Changeset 93620 in vbox for trunk/src/VBox
- Timestamp:
- Feb 6, 2022 9:43:00 AM (3 years ago)
- Location:
- trunk/src/VBox/VMM
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/VMMAll/MMAll.cpp
r93592 r93620 304 304 305 305 /** 306 * Converts a ring-0 host context address in the Hypervisor memory region to a ring-3 host context address.307 *308 * @returns ring-3 host context address.309 * @param pVM The cross context VM structure.310 * @param R0Ptr The ring-0 host context address.311 * You'll be damned if this is not in the HMA! :-)312 * @thread The Emulation Thread.313 */314 VMMDECL(RTR3PTR) MMHyperR0ToR3(PVM pVM, RTR0PTR R0Ptr)315 {316 uint32_t off;317 PMMLOOKUPHYPER pLookup = mmHyperLookupR0(pVM, R0Ptr, &off);318 if (pLookup)319 return mmHyperLookupCalcR3(pLookup, off);320 return NIL_RTR3PTR;321 }322 323 324 /**325 306 * Converts a ring-3 host context address in the Hypervisor memory region to a ring-0 host context address. 326 307 * … … 362 343 #endif 363 344 364 365 /**366 * Converts a raw-mode context address in the Hypervisor memory region to a ring-3 context address.367 *368 * @returns ring-3 host context address.369 * @param pVM The cross context VM structure.370 * @param RCPtr The raw-mode context address.371 * You'll be damned if this is not in the HMA! :-)372 * @thread The Emulation Thread.373 */374 VMMDECL(RTR3PTR) MMHyperRCToR3(PVM pVM, RTRCPTR RCPtr)375 {376 uint32_t off;377 PMMLOOKUPHYPER pLookup = mmHyperLookupRC(pVM, RCPtr, &off);378 if (pLookup)379 return mmHyperLookupCalcR3(pLookup, off);380 return NIL_RTR3PTR;381 }382 383 384 /**385 * Converts a raw-mode context address in the Hypervisor memory region to a ring-0 host context address.386 *387 * @returns ring-0 host context address.388 * @param pVM The cross context VM structure.389 * @param RCPtr The raw-mode context address.390 * You'll be damned if this is not in the HMA! :-)391 * @thread The Emulation Thread.392 */393 VMMDECL(RTR0PTR) MMHyperRCToR0(PVM pVM, RTRCPTR RCPtr)394 {395 uint32_t off;396 PMMLOOKUPHYPER pLookup = mmHyperLookupRC(pVM, RCPtr, &off);397 if (pLookup)398 return mmHyperLookupCalcR0(pVM, pLookup, off);399 return NIL_RTR0PTR;400 }401 402 403 /**404 * Converts a raw-mode context address in the Hypervisor memory region to a current context address.405 *406 * @returns current context address.407 * @param pVM The cross context VM structure.408 * @param RCPtr The raw-mode host context address.409 * You'll be damned if this is not in the HMA! :-)410 * @thread The Emulation Thread.411 */412 VMMDECL(void *) MMHyperRCToCC(PVM pVM, RTRCPTR RCPtr)413 {414 uint32_t off;415 PMMLOOKUPHYPER pLookup = mmHyperLookupRC(pVM, RCPtr, &off);416 if (pLookup)417 return mmHyperLookupCalcCC(pVM, pLookup, off);418 return NULL;419 }420 421 422 #ifndef IN_RING3423 /**424 * Converts a current context address in the Hypervisor memory region to a ring-3 host context address.425 *426 * @returns ring-3 host context address.427 * @param pVM The cross context VM structure.428 * @param pv The current context address.429 * You'll be damned if this is not in the HMA! :-)430 * @thread The Emulation Thread.431 */432 VMMDECL(RTR3PTR) MMHyperCCToR3(PVM pVM, void *pv)433 {434 uint32_t off;435 PMMLOOKUPHYPER pLookup = mmHyperLookupCC(pVM, pv, &off);436 if (pLookup)437 return mmHyperLookupCalcR3(pLookup, off);438 return NIL_RTR3PTR;439 }440 #endif441 345 442 346 #ifndef IN_RING0 -
trunk/src/VBox/VMM/VMMAll/TMAll.cpp
r93115 r93620 131 131 if (pTimer->enmType == TMTIMERTYPE_DEV) 132 132 { 133 RTCCUINTREG fSavedFlags = ASMAddFlags(X86_EFL_AC); /** @todo fix ring-3 pointer use */134 PPDMDEVINSR0 pDevInsR0= ((struct PDMDEVINSR3 *)pTimer->u.Dev.pDevIns)->pDevInsR0RemoveMe; /* !ring-3 read! */133 RTCCUINTREG fSavedFlags = ASMAddFlags(X86_EFL_AC); /** @todo fix ring-3 pointer use */ 134 PPDMDEVINSR0 pDevInsR0 = ((struct PDMDEVINSR3 *)pTimer->u.Dev.pDevIns)->pDevInsR0RemoveMe; /* !ring-3 read! */ 135 135 ASMSetFlags(fSavedFlags); 136 136 struct PDMDEVINSR3 *pDevInsR3 = pDevInsR0->pDevInsForR3R0; -
trunk/src/VBox/VMM/VMMR3/MMHyper.cpp
r93597 r93620 43 43 static int mmR3HyperHeapMap(PVM pVM, PMMHYPERHEAP pHeap, PRTGCPTR ppHeapGC); 44 44 static DECLCALLBACK(void) mmR3HyperInfoHma(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs); 45 static int MMR3HyperReserveFence(PVM pVM);46 45 static int MMR3HyperMapPages(PVM pVM, void *pvR3, RTR0PTR pvR0, size_t cHostPages, PCSUPPAGE paPages, 47 46 const char *pszDesc, PRTGCPTR pGCPtr); … … 144 143 if (RT_SUCCESS(rc)) 145 144 { 146 /*147 * Make a small head fence to fend of accidental sequential access.148 */149 MMR3HyperReserveFence(pVM);150 151 145 /* 152 146 * Map the VM structure into the hypervisor space. … … 184 178 pVM->apCpusR3[i]->pVMRC = pVM->pVMRC; 185 179 186 /* Reserve a page for fencing. */187 MMR3HyperReserveFence(pVM);188 189 180 /* 190 181 * Map the heap into the hypervisor space. … … 322 313 323 314 return rc; 324 }325 326 327 /**328 * Reserves an electric fence page.329 *330 * @returns VBox status code.331 * @param pVM The cross context VM structure.332 */333 static int MMR3HyperReserveFence(PVM pVM)334 {335 RT_NOREF(pVM);336 return VINF_SUCCESS;337 315 } 338 316 … … 491 469 pHeap->pVMRC = pVM->pVMRC; 492 470 pHeap->pbHeapRC = *ppHeapGC + MMYPERHEAP_HDR_SIZE; 493 /* Reserve a page for fencing. */494 MMR3HyperReserveFence(pVM);495 471 496 472 /* We won't need these any more. */ … … 498 474 pHeap->paPages = NULL; 499 475 } 500 return rc;501 }502 503 504 /**505 * Allocates memory in the Hypervisor (GC VMM) area which never will506 * be freed and doesn't have any offset based relation to other heap blocks.507 *508 * The latter means that two blocks allocated by this API will not have the509 * same relative position to each other in GC and HC. In short, never use510 * this API for allocating nodes for an offset based AVL tree!511 *512 * The returned memory is of course zeroed.513 *514 * @returns VBox status code.515 * @param pVM The cross context VM structure.516 * @param cb Number of bytes to allocate.517 * @param uAlignment Required memory alignment in bytes.518 * Values are 0,8,16,32 and GUEST_PAGE_SIZE.519 * 0 -> default alignment, i.e. 8 bytes.520 * @param enmTag The statistics tag.521 * @param ppv Where to store the address to the allocated522 * memory.523 * @remark This is assumed not to be used at times when serialization is required.524 */525 VMMR3DECL(int) MMR3HyperAllocOnceNoRel(PVM pVM, size_t cb, unsigned uAlignment, MMTAG enmTag, void **ppv)526 {527 return MMR3HyperAllocOnceNoRelEx(pVM, cb, uAlignment, enmTag, 0/*fFlags*/, ppv);528 }529 530 531 /**532 * Allocates memory in the Hypervisor (GC VMM) area which never will533 * be freed and doesn't have any offset based relation to other heap blocks.534 *535 * The latter means that two blocks allocated by this API will not have the536 * same relative position to each other in GC and HC. In short, never use537 * this API for allocating nodes for an offset based AVL tree!538 *539 * The returned memory is of course zeroed.540 *541 * @returns VBox status code.542 * @param pVM The cross context VM structure.543 * @param cb Number of bytes to allocate.544 * @param uAlignment Required memory alignment in bytes.545 * Values are 0,8,16,32 and GUEST_PAGE_SIZE.546 * 0 -> default alignment, i.e. 8 bytes.547 * @param enmTag The statistics tag.548 * @param fFlags Flags, see MMHYPER_AONR_FLAGS_KERNEL_MAPPING.549 * @param ppv Where to store the address to the allocated memory.550 * @remark This is assumed not to be used at times when serialization is required.551 */552 VMMR3DECL(int) MMR3HyperAllocOnceNoRelEx(PVM pVM, size_t cb, unsigned uAlignment, MMTAG enmTag, uint32_t fFlags, void **ppv)553 {554 AssertMsg(cb >= 8, ("Hey! Do you really mean to allocate less than 8 bytes?! cb=%d\n", cb));555 Assert(!(fFlags & ~(MMHYPER_AONR_FLAGS_KERNEL_MAPPING)));556 557 /*558 * Choose between allocating a new chunk of HMA memory559 * and the heap. We will only do BIG allocations from HMA and560 * only at creation time.561 */562 if ( ( cb < _64K563 && ( uAlignment != GUEST_PAGE_SIZE564 || cb < 48*_1K)565 && !(fFlags & MMHYPER_AONR_FLAGS_KERNEL_MAPPING)566 )567 || VMR3GetState(pVM) != VMSTATE_CREATING568 )569 {570 Assert(!(fFlags & MMHYPER_AONR_FLAGS_KERNEL_MAPPING));571 int rc = MMHyperAlloc(pVM, cb, uAlignment, enmTag, ppv);572 if ( rc != VERR_MM_HYPER_NO_MEMORY573 || cb <= 8*_1K)574 {575 Log2(("MMR3HyperAllocOnceNoRel: cb=%#zx uAlignment=%#x returns %Rrc and *ppv=%p\n",576 cb, uAlignment, rc, *ppv));577 return rc;578 }579 }580 581 /*582 * Validate alignment.583 */584 switch (uAlignment)585 {586 case 0:587 case 8:588 case 16:589 case 32:590 case GUEST_PAGE_SIZE:591 break;592 default:593 AssertMsgFailed(("Invalid alignment %u\n", uAlignment));594 return VERR_INVALID_PARAMETER;595 }596 597 /*598 * Allocate the pages and map them into HMA space.599 */600 uint32_t const cbAligned = RT_ALIGN_32(cb, RT_MAX(GUEST_PAGE_SIZE, HOST_PAGE_SIZE));601 AssertReturn(cbAligned >= cb, VERR_INVALID_PARAMETER);602 uint32_t const cHostPages = cbAligned >> HOST_PAGE_SHIFT;603 PSUPPAGE paPages = (PSUPPAGE)RTMemTmpAlloc(cHostPages * sizeof(paPages[0]));604 if (!paPages)605 return VERR_NO_TMP_MEMORY;606 void *pvPages;607 RTR0PTR pvR0 = NIL_RTR0PTR;608 int rc = SUPR3PageAllocEx(cHostPages,609 0 /*fFlags*/,610 &pvPages,611 &pvR0,612 paPages);613 if (RT_SUCCESS(rc))614 {615 Assert(pvR0 != NIL_RTR0PTR || SUPR3IsDriverless());616 memset(pvPages, 0, cbAligned);617 618 RTGCPTR GCPtr;619 rc = MMR3HyperMapPages(pVM,620 pvPages,621 pvR0,622 cHostPages,623 paPages,624 MMR3HeapAPrintf(pVM, MM_TAG_MM, "alloc once (%s)", mmGetTagName(enmTag)),625 &GCPtr);626 /* not needed anymore */627 RTMemTmpFree(paPages);628 if (RT_SUCCESS(rc))629 {630 *ppv = pvPages;631 Log2(("MMR3HyperAllocOnceNoRel: cbAligned=%#x uAlignment=%#x returns VINF_SUCCESS and *ppv=%p\n",632 cbAligned, uAlignment, *ppv));633 MMR3HyperReserveFence(pVM);634 return rc;635 }636 AssertMsgFailed(("Failed to allocate %zd bytes! %Rrc\n", cbAligned, rc));637 SUPR3PageFreeEx(pvPages, cHostPages);638 639 640 /*641 * HACK ALERT! Try allocate it off the heap so that we don't freak642 * out during vga/vmmdev mmio2 allocation with certain ram sizes.643 */644 /** @todo make a proper fix for this so we will never end up in this kind of situation! */645 Log(("MMR3HyperAllocOnceNoRel: MMR3HyperMapHCRam failed with rc=%Rrc, try MMHyperAlloc(,%#x,,) instead\n", rc, cb));646 int rc2 = MMHyperAlloc(pVM, cb, uAlignment, enmTag, ppv);647 if (RT_SUCCESS(rc2))648 {649 Log2(("MMR3HyperAllocOnceNoRel: cb=%#x uAlignment=%#x returns %Rrc and *ppv=%p\n",650 cb, uAlignment, rc, *ppv));651 return rc;652 }653 }654 else655 AssertMsgFailed(("Failed to allocate %zd bytes! %Rrc\n", cbAligned, rc));656 657 if (rc == VERR_NO_MEMORY)658 rc = VERR_MM_HYPER_NO_MEMORY;659 LogRel(("MMR3HyperAllocOnceNoRel: cb=%#zx uAlignment=%#x returns %Rrc\n", cb, uAlignment, rc));660 476 return rc; 661 477 }
Note:
See TracChangeset
for help on using the changeset viewer.