PGMAllPool.cpp revision 2c080f6fc6ab70995d6390eeaa199d590c1a34d5
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * PGM Shadow Page Pool.
3f1e0eea71cabeb90529e546f16eb7aee513fde9vboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * available from http://www.virtualbox.org. This file is free software;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * you can redistribute it and/or modify it under the terms of the GNU
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * General Public License (GPL) as published by the Free Software
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * additional information or have any questions.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync/*******************************************************************************
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync* Header Files *
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync*******************************************************************************/
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync/*******************************************************************************
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync* Internal Functions *
590bfe12ce22cd3716448fbb9f4dc51664bfe5e2vboxsync*******************************************************************************/
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncDECLINLINE(unsigned) pgmPoolTrackGetShadowEntrySize(PGMPOOLKIND enmKind);
afed5ab737f4aacfae3fe73776f40e989190a7cavboxsyncDECLINLINE(unsigned) pgmPoolTrackGetGuestEntrySize(PGMPOOLKIND enmKind);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic void pgmPoolTrackDeref(PPGMPOOL pPool, PPGMPOOLPAGE pPage);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic void pgmPoolTracDerefGCPhysHint(PPGMPOOL pPool, PPGMPOOLPAGE pPage, RTHCPHYS HCPhys, RTGCPHYS GCPhysHint);
0174432b2b1a760b89840ba696f7ba51def65dddvboxsyncstatic int pgmPoolTrackAddUser(PPGMPOOL pPool, PPGMPOOLPAGE pPage, uint16_t iUser, uint32_t iUserTable);
614cbe11a7e5588dc8d369e223174b1441a09359vboxsyncstatic void pgmPoolMonitorModifiedRemove(PPGMPOOL pPool, PPGMPOOLPAGE pPage);
7666082b743c5e146a8cee6cc794ff4bc3fd0ffdvboxsyncDECLEXPORT(int) pgmPoolAccessHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPHYS GCPhysFault, void *pvUser);
7666082b743c5e146a8cee6cc794ff4bc3fd0ffdvboxsyncstatic const char *pgmPoolPoolKindToStr(uint8_t enmKind);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Checks if the specified page pool kind is for a 4MB or 2MB guest page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns true if it's the shadow of a 4MB or 2MB guest page, otherwise false.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param enmKind The page kind.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncDECLINLINE(bool) pgmPoolIsBigPage(PGMPOOLKIND enmKind)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return true;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return false;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync#if defined(IN_RC) || defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Maps a pool page into the current context.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns Pointer to the mapping.
f351fab06d1e1507b72f5c574df71193061fd393vboxsync * @param pPGM Pointer to the PGM instance data.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The page to map.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncvoid *pgmPoolMapPageFallback(PPGM pPGM, PPGMPOOLPAGE pPage)
a11c569636fa6838bd423f4631a9660a5a84204bvboxsync /* general pages are take care of by the inlined part, it
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync only ends up here in case of failure. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertReleaseReturn(pPage->idx < PGMPOOL_IDX_FIRST, NULL);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync/** @todo make sure HCPhys is valid for *all* indexes. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* special pages. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertReleaseMsgFailed(("Invalid index %d\n", pPage->idx));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync# else /* VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0 */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertReleaseMsgFailed(("PGMPOOL_IDX_PAE_PD is not usable in VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0 context\n"));
e08de24d4792d31b7f2aac29db5cb8840d940009vboxsync AssertReleaseMsgFailed(("Invalid index %d\n", pPage->idx));
69deddbc68802f1cf1c3a404a9f816b8accb3385vboxsync AssertMsg(HCPhys && HCPhys != NIL_RTHCPHYS && !(PAGE_OFFSET_MASK & HCPhys), ("%RHp\n", HCPhys));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync# endif /* VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0 */
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync#endif /* IN_RC || VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0 */
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync * Determin the size of a write instruction.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns number of bytes written.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pDis The disassembler state.
3ecd8008b81f02a04220705ae0033142af363280vboxsyncstatic unsigned pgmPoolDisasWriteSize(PDISCPUSTATE pDis)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * This is very crude and possibly wrong for some opcodes,
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * but since it's not really supposed to be called we can
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * probably live with that.
b74ca013e5f201a2dd371e6c438433ceac12af30vboxsync * Flushes a chain of pages sharing the same access monitor.
22e281e75ed636601178296c6daebda8f1d17c59vboxsync * @returns VBox status code suitable for scheduling.
b74ca013e5f201a2dd371e6c438433ceac12af30vboxsync * @param pPool The pool.
b74ca013e5f201a2dd371e6c438433ceac12af30vboxsync * @param pPage A page in the chain.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncint pgmPoolMonitorChainFlush(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
82e90599291da476b2de7c8db33cfb0f2cbac774vboxsync LogFlow(("pgmPoolMonitorChainFlush: Flush page %RGp type=%d\n", pPage->GCPhys, pPage->enmKind));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Find the list head.
b74ca013e5f201a2dd371e6c438433ceac12af30vboxsync * Iterate the list flushing each shadow page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if (rc2 == VERR_PGM_POOL_CLEARED && rc == VINF_SUCCESS)
9984bae4ef25be8afd95d184308adcfef6e2ec0dvboxsync * Wrapper for getting the current context pointer to the entry being modified.
e50404712a2b5234c42bdf9740bddab5729ba188vboxsync * @returns Pointer to the current context mapping of the entry.
b978e5849454446957177fd47ee98609ab0457a6vboxsync * @param pPool The pool.
57399ab65e2825c324fb9dcb4642d4ae2c232509vboxsync * @param pvFault The fault virtual address.
533ffcb943c4af2c5fe6385d816d0ba3eda9383bvboxsync * @param GCPhysFault The fault physical address.
57399ab65e2825c324fb9dcb4642d4ae2c232509vboxsync * @param cbEntry The entry size.
1843553dbdf4e46417158b4c6348c503adf10740vboxsyncDECLINLINE(const void *) pgmPoolMonitorGCPtr2CCPtr(PPGMPOOL pPool, RTHCPTR pvFault, RTGCPHYS GCPhysFault, const unsigned cbEntry)
22e281e75ed636601178296c6daebda8f1d17c59vboxsyncDECLINLINE(const void *) pgmPoolMonitorGCPtr2CCPtr(PPGMPOOL pPool, RTGCPTR pvFault, RTGCPHYS GCPhysFault, const unsigned cbEntry)
1843553dbdf4e46417158b4c6348c503adf10740vboxsync return (const void *)((RTGCUINTPTR)pvFault & ~(RTGCUINTPTR)(cbEntry - 1));
1843553dbdf4e46417158b4c6348c503adf10740vboxsync int rc = PGMDynMapGCPageOff(pPool->pVMR0, GCPhysFault & ~(RTGCPHYS)(cbEntry - 1), &pvRet);
6ae4b1c72625a8e5c369effea7f018b578d733c4vboxsync int rc = pgmRamGCPhys2HCPtr(&pPool->pVMR0->pgm.s, GCPhysFault & ~(RTGCPHYS)(cbEntry - 1), &pvRet);
9e4166cf5ed4940f506bc718ea6c89bf7ed252c8vboxsync return (RTHCPTR)((uintptr_t)pvFault & ~(RTHCUINTPTR)(cbEntry - 1));
22e281e75ed636601178296c6daebda8f1d17c59vboxsync * Process shadow entries before they are changed by the guest.
1843553dbdf4e46417158b4c6348c503adf10740vboxsync * For PT entries we will clear them. For PD entries, we'll simply check
806d0b554daa555364af5f87bc96eccbe760db7avboxsync * for mapping conflicts and set the SyncCR3 FF if found.
1843553dbdf4e46417158b4c6348c503adf10740vboxsync * @param pPool The pool.
13ba5527caaa9b8c4fee29f22e374fa67c4c6f72vboxsync * @param pPage The head page.
1843553dbdf4e46417158b4c6348c503adf10740vboxsync * @param GCPhysFault The guest physical fault address.
1843553dbdf4e46417158b4c6348c503adf10740vboxsync * @param uAddress In R0 and GC this is the guest context fault address (flat).
1843553dbdf4e46417158b4c6348c503adf10740vboxsync * In R3 this is the host context 'fault' address.
22e281e75ed636601178296c6daebda8f1d17c59vboxsync * @param pCpu The disassembler state for figuring out the write size.
1843553dbdf4e46417158b4c6348c503adf10740vboxsync * This need not be specified if the caller knows we won't do cross entry accesses.
6ae4b1c72625a8e5c369effea7f018b578d733c4vboxsyncvoid pgmPoolMonitorChainChanging(PPGMPOOL pPool, PPGMPOOLPAGE pPage, RTGCPHYS GCPhysFault, RTHCPTR pvAddress, PDISCPUSTATE pCpu)
ebbb1f6c7e8bae363a4efda4b35b58c8467d24bcvboxsyncvoid pgmPoolMonitorChainChanging(PPGMPOOL pPool, PPGMPOOLPAGE pPage, RTGCPHYS GCPhysFault, RTGCPTR pvAddress, PDISCPUSTATE pCpu)
533ffcb943c4af2c5fe6385d816d0ba3eda9383bvboxsync const unsigned off = GCPhysFault & PAGE_OFFSET_MASK;
533ffcb943c4af2c5fe6385d816d0ba3eda9383bvboxsync const unsigned cbWrite = (pCpu) ? pgmPoolDisasWriteSize(pCpu) : 0;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolMonitorChainChanging: %RGv phys=%RGp kind=%d cbWrite=%d\n", pvAddress, GCPhysFault, pPage->enmKind, cbWrite));
0e77737b0ba913683e614db11463b31ca67aacbevboxsync uShw.pv = PGMPOOL_PAGE_2_PTR(pPool->CTX_SUFF(pVM), pPage);
22e281e75ed636601178296c6daebda8f1d17c59vboxsync PCX86PTE pGstPte = (PCX86PTE)pgmPoolMonitorGCPtr2CCPtr(pPool, pvAddress, GCPhysFault, sizeof(*pGstPte));
e9a217d585085a6a6d129d27ca0d96a1b8e6d0eevboxsync Log4(("pgmPoolMonitorChainChanging 32_32: deref %016RX64 GCPhys %08RX32\n", uShw.pPT->a[iShw].u & X86_PTE_PAE_PG_MASK, pGstPte->u & X86_PTE_PG_MASK));
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync /* page/2 sized */
82e90599291da476b2de7c8db33cfb0f2cbac774vboxsync uShw.pv = PGMPOOL_PAGE_2_PTR(pPool->CTX_SUFF(pVM), pPage);
2d53f6e472561965d363674e17f48d3bdffc24d3vboxsync const unsigned iShw = (off / sizeof(X86PTE)) & (X86_PG_PAE_ENTRIES - 1);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PCX86PTE pGstPte = (PCX86PTE)pgmPoolMonitorGCPtr2CCPtr(pPool, pvAddress, GCPhysFault, sizeof(*pGstPte));
3080f6c0871099df43a4e91b31894d9c2b1369a8vboxsync Log4(("pgmPoolMonitorChainChanging pae_32: deref %016RX64 GCPhys %08RX32\n", uShw.pPT->a[iShw].u & X86_PTE_PAE_PG_MASK, pGstPte->u & X86_PTE_PG_MASK));
806d0b554daa555364af5f87bc96eccbe760db7avboxsync uShw.pv = PGMPOOL_PAGE_2_PTR(pPool->CTX_SUFF(pVM), pPage);
806d0b554daa555364af5f87bc96eccbe760db7avboxsync LogFlow(("pgmPoolMonitorChainChanging PAE for 32 bits: iGst=%x idx = %d page idx=%d\n", iGst, iShwPdpt, pPage->enmKind - PGMPOOLKIND_PAE_PD0_FOR_32BIT_PD));
806d0b554daa555364af5f87bc96eccbe760db7avboxsync if (iShwPdpt == pPage->enmKind - PGMPOOLKIND_PAE_PD0_FOR_32BIT_PD)
806d0b554daa555364af5f87bc96eccbe760db7avboxsync for (unsigned i=0;i<2;i++)
806d0b554daa555364af5f87bc96eccbe760db7avboxsync if ((uShw.pPDPae->a[iShw + i].u & (PGM_PDFLAGS_MAPPING | X86_PDE_P)) == (PGM_PDFLAGS_MAPPING | X86_PDE_P))
806d0b554daa555364af5f87bc96eccbe760db7avboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTX_SUFF(pVM)->pgm.s));
806d0b554daa555364af5f87bc96eccbe760db7avboxsync VM_FF_SET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3);
d98e61ba075ed7d0b567a5d884bc85d643fe3de7vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShwPdpt=%#x iShw=%#x!\n", iShwPdpt, iShw+i));
806d0b554daa555364af5f87bc96eccbe760db7avboxsync LogFlow(("pgmPoolMonitorChainChanging: pae pd iShw=%#x: %RX64 -> freeing it!\n", iShw+i, uShw.pPDPae->a[iShw+i].u));
806d0b554daa555364af5f87bc96eccbe760db7avboxsync /* paranoia / a bit assumptive. */
806d0b554daa555364af5f87bc96eccbe760db7avboxsync if ((uShw.pPDPae->a[iShw2].u & (PGM_PDFLAGS_MAPPING | X86_PDE_P)) == (PGM_PDFLAGS_MAPPING | X86_PDE_P))
806d0b554daa555364af5f87bc96eccbe760db7avboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTX_SUFF(pVM)->pgm.s));
22e281e75ed636601178296c6daebda8f1d17c59vboxsync VM_FF_SET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3);
806d0b554daa555364af5f87bc96eccbe760db7avboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShwPdpt=%#x iShw2=%#x!\n", iShwPdpt, iShw2));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolMonitorChainChanging: pae pd iShw=%#x: %RX64 -> freeing it!\n", iShw2, uShw.pPDPae->a[iShw2].u));
79b24ef0ab7cd4a03a3571b3954c52ab8b573137vboxsync uShw.pv = PGMPOOL_PAGE_2_PTR(pPool->CTX_SUFF(pVM), pPage);
79b24ef0ab7cd4a03a3571b3954c52ab8b573137vboxsync PCX86PTEPAE pGstPte = (PCX86PTEPAE)pgmPoolMonitorGCPtr2CCPtr(pPool, pvAddress, GCPhysFault, sizeof(*pGstPte));
79b24ef0ab7cd4a03a3571b3954c52ab8b573137vboxsync Log4(("pgmPoolMonitorChainChanging pae: deref %016RX64 GCPhys %016RX64\n", uShw.pPTPae->a[iShw].u & X86_PTE_PAE_PG_MASK, pGstPte->u & X86_PTE_PAE_PG_MASK));
3cac8f8c6923a3a89ecfccda5e89ad75f48658e0vboxsync /* paranoia / a bit assumptive. */
1157941288c9533575a655c660af55d13da31eefvboxsync const unsigned iShw2 = (off + cbWrite - 1) / sizeof(X86PTEPAE);
5e797edc29f96c8367de4fbf5874171c24a89ba7vboxsync AssertReturnVoid(iShw2 < RT_ELEMENTS(uShw.pPTPae->a));
5e797edc29f96c8367de4fbf5874171c24a89ba7vboxsync PCX86PTEPAE pGstPte = (PCX86PTEPAE)pgmPoolMonitorGCPtr2CCPtr(pPool, pvAddress, GCPhysFault, sizeof(*pGstPte));
22e281e75ed636601178296c6daebda8f1d17c59vboxsync Log4(("pgmPoolMonitorChainChanging pae: deref %016RX64 GCPhys %016RX64\n", uShw.pPTPae->a[iShw2].u & X86_PTE_PAE_PG_MASK, pGstPte->u & X86_PTE_PAE_PG_MASK));
22e281e75ed636601178296c6daebda8f1d17c59vboxsync uShw.pv = PGMPOOL_PAGE_2_PTR(pPool->CTX_SUFF(pVM), pPage);
e0b9d3c357adf9b7d05f55540e86f22943fc4b23vboxsync const unsigned iShw = off / sizeof(X86PTE); // ASSUMING 32-bit guest paging!
e149c362e69e5f0bbd82da11fd8163b2d29c3a72vboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTX_SUFF(pVM)->pgm.s));
79b24ef0ab7cd4a03a3571b3954c52ab8b573137vboxsync VM_FF_SET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3);
13ba5527caaa9b8c4fee29f22e374fa67c4c6f72vboxsync STAM_COUNTER_INC(&(pPool->CTX_SUFF(pVM)->pgm.s.StatRZGuestCR3WriteConflict));
13ba5527caaa9b8c4fee29f22e374fa67c4c6f72vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw=%#x!\n", iShw));
7bae75e0b207aa4d4cad2a951271ad1a0e8ab9fdvboxsync LogFlow(("pgmPoolMonitorChainChanging: 32 bit pd iShw=%#x: %RX64 -> freeing it!\n", iShw, uShw.pPD->a[iShw].u));
f9147fe1eaa4e35287f8f39282c7f92f0d7de0b7vboxsync /* paranoia / a bit assumptive. */
7082d29724f6c3788977a51591b0379fd3acbf72vboxsync const unsigned iShw2 = (off + cbWrite - 1) / sizeof(X86PTE);
e4ea543752422f1139923e3e506c625b0a1827c5vboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTX_SUFF(pVM)->pgm.s));
f9147fe1eaa4e35287f8f39282c7f92f0d7de0b7vboxsync STAM_COUNTER_INC(&(pPool->CTX_SUFF(pVM)->pgm.s.StatRZGuestCR3WriteConflict));
13ba5527caaa9b8c4fee29f22e374fa67c4c6f72vboxsync VM_FF_SET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3);
f827fea1108b8f8a1a5f63318f6ec3cf4a9e7010vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw2=%#x!\n", iShw2));
f9147fe1eaa4e35287f8f39282c7f92f0d7de0b7vboxsync LogFlow(("pgmPoolMonitorChainChanging: 32 bit pd iShw=%#x: %RX64 -> freeing it!\n", iShw2, uShw.pPD->a[iShw2].u));
6f0193f5a9287559d34a75f438c2682d8fb08038vboxsync#if 0 /* useful when running PGMAssertCR3(), a bit too troublesome for general use (TLBs). */
6f0193f5a9287559d34a75f438c2682d8fb08038vboxsync && !VM_FF_ISSET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3))
f9147fe1eaa4e35287f8f39282c7f92f0d7de0b7vboxsync LogFlow(("pgmPoolMonitorChainChanging: iShw=%#x: %RX32 -> freeing it!\n", iShw, uShw.pPD->a[iShw].u));
9e4166cf5ed4940f506bc718ea6c89bf7ed252c8vboxsync# ifdef IN_RC /* TLB load - we're pushing things a bit... */
6f0193f5a9287559d34a75f438c2682d8fb08038vboxsync pgmPoolFree(pPool->CTX_SUFF(pVM), uShw.pPD->a[iShw].u & X86_PDE_PG_MASK, pPage->idx, iShw);
6f0193f5a9287559d34a75f438c2682d8fb08038vboxsync unsigned iGst = off / sizeof(X86PDE); // ASSUMING 32-bit guest paging!
6f0193f5a9287559d34a75f438c2682d8fb08038vboxsync Assert(pPage2->idx == PGMPOOL_IDX_PAE_PD_0 + iShwPdpt);
13ba5527caaa9b8c4fee29f22e374fa67c4c6f72vboxsync uShw.pv = PGMPOOL_PAGE_2_PTR(pPool->CTX_SUFF(pVM), pPage2);
6f0193f5a9287559d34a75f438c2682d8fb08038vboxsync if ((uShw.pPDPae->a[iShw].u & (PGM_PDFLAGS_MAPPING | X86_PDE_P)) == (PGM_PDFLAGS_MAPPING | X86_PDE_P))
6f0193f5a9287559d34a75f438c2682d8fb08038vboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTX_SUFF(pVM)->pgm.s));
6f0193f5a9287559d34a75f438c2682d8fb08038vboxsync VM_FF_SET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3);
6f0193f5a9287559d34a75f438c2682d8fb08038vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShwPdpt=%#x iShw=%#x!\n", iShwPdpt, iShw));
6f0193f5a9287559d34a75f438c2682d8fb08038vboxsync /* paranoia / a bit assumptive. */
f9147fe1eaa4e35287f8f39282c7f92f0d7de0b7vboxsync if ( iShw2 < RT_ELEMENTS(uShw.pPDPae->a) /** @todo was completely wrong, it's better now after #1865 but still wrong from cross PD. */
7e960d3a0a8a3a84d7aba2cca45d72b1c31cc97bvboxsync && (uShw.pPDPae->a[iShw2].u & (PGM_PDFLAGS_MAPPING | X86_PDE_P)) == (PGM_PDFLAGS_MAPPING | X86_PDE_P))
65b61798a61dd4c32cce448db1dac70bba8d5cf5vboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTX_SUFF(pVM)->pgm.s));
b978e5849454446957177fd47ee98609ab0457a6vboxsync VM_FF_SET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3);
9984bae4ef25be8afd95d184308adcfef6e2ec0dvboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShwPdpt=%#x iShw2=%#x!\n", iShwPdpt, iShw2));
13ba5527caaa9b8c4fee29f22e374fa67c4c6f72vboxsync#if 0 /* useful when running PGMAssertCR3(), a bit too troublesome for general use (TLBs). */
13ba5527caaa9b8c4fee29f22e374fa67c4c6f72vboxsync && !VM_FF_ISSET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3))
13ba5527caaa9b8c4fee29f22e374fa67c4c6f72vboxsync LogFlow(("pgmPoolMonitorChainChanging: iShwPdpt=%#x iShw=%#x: %RX64 -> freeing it!\n", iShwPdpt, iShw, uShw.pPDPae->a[iShw].u));
13ba5527caaa9b8c4fee29f22e374fa67c4c6f72vboxsync# ifdef IN_RC /* TLB load - we're pushing things a bit... */
65b61798a61dd4c32cce448db1dac70bba8d5cf5vboxsync pgmPoolFree(pPool->CTX_SUFF(pVM), uShw.pPDPae->a[iShw].u & X86_PDE_PAE_PG_MASK, pPage->idx, iShw + iShwPdpt * X86_PG_PAE_ENTRIES);
65b61798a61dd4c32cce448db1dac70bba8d5cf5vboxsync# endif /* !VBOX_WITH_PGMPOOL_PAGING_ONLY */
65b61798a61dd4c32cce448db1dac70bba8d5cf5vboxsync uShw.pv = PGMPOOL_PAGE_2_PTR(pPool->CTX_SUFF(pVM), pPage);
65b61798a61dd4c32cce448db1dac70bba8d5cf5vboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTX_SUFF(pVM)->pgm.s));
6ae4b1c72625a8e5c369effea7f018b578d733c4vboxsync VM_FF_SET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3);
65b61798a61dd4c32cce448db1dac70bba8d5cf5vboxsync STAM_COUNTER_INC(&(pPool->CTX_SUFF(pVM)->pgm.s.StatRZGuestCR3WriteConflict));
65b61798a61dd4c32cce448db1dac70bba8d5cf5vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw=%#x!\n", iShw));
46df4404c8dbbf3672e7aae8cd0b2770356e5b73vboxsync * Causes trouble when the guest uses a PDE to refer to the whole page table level
b978e5849454446957177fd47ee98609ab0457a6vboxsync * structure. (Invalidate here; faults later on when it tries to change the page
3cac8f8c6923a3a89ecfccda5e89ad75f48658e0vboxsync * table entries -> recheck; probably only applies to the RC case.)
ce2d2eef2525963979102e63c2419d1c69d767ccvboxsync LogFlow(("pgmPoolMonitorChainChanging: pae pd iShw=%#x: %RX64 -> freeing it!\n", iShw, uShw.pPDPae->a[iShw].u));
9e4166cf5ed4940f506bc718ea6c89bf7ed252c8vboxsync /* Note: hardcoded PAE implementation dependency */
9e4166cf5ed4940f506bc718ea6c89bf7ed252c8vboxsync (pPage->enmKind == PGMPOOLKIND_PAE_PD_FOR_PAE_PD) ? PGMPOOL_IDX_PAE_PD : pPage->idx,
ce2d2eef2525963979102e63c2419d1c69d767ccvboxsync (pPage->enmKind == PGMPOOLKIND_PAE_PD_FOR_PAE_PD) ? iShw + (pPage->idx - PGMPOOL_IDX_PAE_PD_0) * X86_PG_PAE_ENTRIES : iShw);
ce2d2eef2525963979102e63c2419d1c69d767ccvboxsync /* paranoia / a bit assumptive. */
46df4404c8dbbf3672e7aae8cd0b2770356e5b73vboxsync const unsigned iShw2 = (off + cbWrite - 1) / sizeof(X86PDEPAE);
5db1d52ffbcaa46c3d944c6c2d9c552306817d9avboxsync AssertReturnVoid(iShw2 < RT_ELEMENTS(uShw.pPDPae->a));
585f64d6f624f9e683321dabeb21b0eb2e6aa473vboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTX_SUFF(pVM)->pgm.s));
585f64d6f624f9e683321dabeb21b0eb2e6aa473vboxsync VM_FF_SET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3);
9984bae4ef25be8afd95d184308adcfef6e2ec0dvboxsync STAM_COUNTER_INC(&(pPool->CTX_SUFF(pVM)->pgm.s.StatRZGuestCR3WriteConflict));
ce2d2eef2525963979102e63c2419d1c69d767ccvboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw2=%#x!\n", iShw2));
ce2d2eef2525963979102e63c2419d1c69d767ccvboxsync LogFlow(("pgmPoolMonitorChainChanging: pae pd iShw2=%#x: %RX64 -> freeing it!\n", iShw2, uShw.pPDPae->a[iShw2].u));
ce2d2eef2525963979102e63c2419d1c69d767ccvboxsync /* Note: hardcoded PAE implementation dependency */
585f64d6f624f9e683321dabeb21b0eb2e6aa473vboxsync (pPage->enmKind == PGMPOOLKIND_PAE_PD_FOR_PAE_PD) ? PGMPOOL_IDX_PAE_PD : pPage->idx,
ce2d2eef2525963979102e63c2419d1c69d767ccvboxsync (pPage->enmKind == PGMPOOLKIND_PAE_PD_FOR_PAE_PD) ? iShw2 + (pPage->idx - PGMPOOL_IDX_PAE_PD_0) * X86_PG_PAE_ENTRIES : iShw2);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Hopefully this doesn't happen very often:
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * - touching unused parts of the page
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * - messing with the bits of pd pointers without changing the physical address
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* PDPT roots are not page aligned; 32 byte only! */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync const unsigned offPdpt = GCPhysFault - pPage->GCPhys;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync uShw.pv = PGMPOOL_PAGE_2_PTR(pPool->CTX_SUFF(pVM), pPage);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if (iShw < X86_PG_PAE_PDPE_ENTRIES) /* don't use RT_ELEMENTS(uShw.pPDPT->a), because that's for long mode only */
3cbb4f9a6a320e58ed398ef7aaa004cc8727abc5vboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTX_SUFF(pVM)->pgm.s));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_COUNTER_INC(&(pPool->CTX_SUFF(pVM)->pgm.s.StatRZGuestCR3WriteConflict));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync VM_FF_SET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw=%#x!\n", iShw));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolMonitorChainChanging: pae pdpt iShw=%#x: %RX64 -> freeing it!\n", iShw, uShw.pPDPT->a[iShw].u));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* paranoia / a bit assumptive. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync const unsigned iShw2 = (offPdpt + cbWrite - 1) / sizeof(X86PDPE);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTX_SUFF(pVM)->pgm.s));
e9a217d585085a6a6d129d27ca0d96a1b8e6d0eevboxsync STAM_COUNTER_INC(&(pPool->CTX_SUFF(pVM)->pgm.s.StatRZGuestCR3WriteConflict));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync VM_FF_SET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw2=%#x!\n", iShw2));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolMonitorChainChanging: pae pdpt iShw=%#x: %RX64 -> freeing it!\n", iShw2, uShw.pPDPT->a[iShw2].u));
e17bd6c32a8dd64f2d42838f9028216465e2caf0vboxsync uShw.pv = PGMPOOL_PAGE_2_PTR(pPool->CTX_SUFF(pVM), pPage);
5ace91141404400247438502a84a418fba00c8cfvboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTX_SUFF(pVM)->pgm.s));
5ace91141404400247438502a84a418fba00c8cfvboxsync VM_FF_SET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3);
5ace91141404400247438502a84a418fba00c8cfvboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw=%#x!\n", iShw));
49748bb305bd71f672cd083af208f4bb08c5d6abvboxsync LogFlow(("pgmPoolMonitorChainChanging: pae pd iShw=%#x: %RX64 -> freeing it!\n", iShw, uShw.pPDPae->a[iShw].u));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* paranoia / a bit assumptive. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync const unsigned iShw2 = (off + cbWrite - 1) / sizeof(X86PDEPAE);
b9ca93dd1ad44cb8b27679dc5624be2f7b7f7af5vboxsync AssertReturnVoid(iShw2 < RT_ELEMENTS(uShw.pPDPae->a));
b9ca93dd1ad44cb8b27679dc5624be2f7b7f7af5vboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTX_SUFF(pVM)->pgm.s));
7c3417bbf525c03163d54d151a277a981d5d61b6vboxsync VM_FF_SET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3);
e9a217d585085a6a6d129d27ca0d96a1b8e6d0eevboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw2=%#x!\n", iShw2));
3cbb4f9a6a320e58ed398ef7aaa004cc8727abc5vboxsync LogFlow(("pgmPoolMonitorChainChanging: pae pd iShw2=%#x: %RX64 -> freeing it!\n", iShw2, uShw.pPDPae->a[iShw2].u));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Hopefully this doesn't happen very often:
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * - messing with the bits of pd pointers without changing the physical address
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync if (!VM_FF_ISSET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3))
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync uShw.pv = PGMPOOL_PAGE_2_PTR(pPool->CTX_SUFF(pVM), pPage);
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync LogFlow(("pgmPoolMonitorChainChanging: pdpt iShw=%#x: %RX64 -> freeing it!\n", iShw, uShw.pPDPT->a[iShw].u));
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync pgmPoolFree(pPool->CTX_SUFF(pVM), uShw.pPDPT->a[iShw].u & X86_PDPE_PG_MASK, pPage->idx, iShw);
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync /* paranoia / a bit assumptive. */
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync const unsigned iShw2 = (off + cbWrite - 1) / sizeof(X86PDPE);
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync LogFlow(("pgmPoolMonitorChainChanging: pdpt iShw2=%#x: %RX64 -> freeing it!\n", iShw2, uShw.pPDPT->a[iShw2].u));
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync pgmPoolFree(pPool->CTX_SUFF(pVM), uShw.pPDPT->a[iShw2].u & X86_PDPE_PG_MASK, pPage->idx, iShw2);
f351fab06d1e1507b72f5c574df71193061fd393vboxsync * Hopefully this doesn't happen very often:
f351fab06d1e1507b72f5c574df71193061fd393vboxsync * - messing with the bits of pd pointers without changing the physical address
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync if (!VM_FF_ISSET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3))
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync uShw.pv = PGMPOOL_PAGE_2_PTR(pPool->CTX_SUFF(pVM), pPage);
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync LogFlow(("pgmPoolMonitorChainChanging: pml4 iShw=%#x: %RX64 -> freeing it!\n", iShw, uShw.pPML4->a[iShw].u));
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync pgmPoolFree(pPool->CTX_SUFF(pVM), uShw.pPML4->a[iShw].u & X86_PML4E_PG_MASK, pPage->idx, iShw);
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync /* paranoia / a bit assumptive. */
f351fab06d1e1507b72f5c574df71193061fd393vboxsync const unsigned iShw2 = (off + cbWrite - 1) / sizeof(X86PML4E);
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync LogFlow(("pgmPoolMonitorChainChanging: pml4 iShw2=%#x: %RX64 -> freeing it!\n", iShw2, uShw.pPML4->a[iShw2].u));
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync pgmPoolFree(pPool->CTX_SUFF(pVM), uShw.pPML4->a[iShw2].u & X86_PML4E_PG_MASK, pPage->idx, iShw2);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync#endif /* IN_RING0 */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertFatalMsgFailed(("enmKind=%d\n", pPage->enmKind));
5ace91141404400247438502a84a418fba00c8cfvboxsync * Checks if a access could be a fork operation in progress.
09e2f92b8f54aa362088e216007b53ecdb42e283vboxsync * Meaning, that the guest is setuping up the parent process for Copy-On-Write.
5ace91141404400247438502a84a418fba00c8cfvboxsync * @returns true if it's likly that we're forking, otherwise false.
3123bb2477edc752585e4bbd8e4cfedaf87997d1vboxsync * @param pPool The pool.
247b55faa8d054157f2481e68caca36f4dc9542cvboxsync * @param pCpu The disassembled instruction.
247b55faa8d054157f2481e68caca36f4dc9542cvboxsync * @param offFault The access offset.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncDECLINLINE(bool) pgmPoolMonitorIsForking(PPGMPOOL pPool, PDISCPUSTATE pCpu, unsigned offFault)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * i386 linux is using btr to clear X86_PTE_RW.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * The functions involved are (2.6.16 source inspection):
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * clear_bit
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * ptep_set_wrprotect
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * copy_one_pte
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * copy_pte_range
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * copy_pmd_range
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * copy_pud_range
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * copy_page_range
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * copy_process
0975ae0a0fb615c945150c48e4a73187c1f4f84dvboxsync /** @todo Validate that the bit index is X86_PTE_RW. */
7e960d3a0a8a3a84d7aba2cca45d72b1c31cc97bvboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,Fork));
d07ea3c3faead54c0de83ab93f2b03dedfb819e2vboxsync return true;
09e2f92b8f54aa362088e216007b53ecdb42e283vboxsync return false;
09e2f92b8f54aa362088e216007b53ecdb42e283vboxsync * Determine whether the page is likely to have been reused.
3cbb4f9a6a320e58ed398ef7aaa004cc8727abc5vboxsync * @returns true if we consider the page as being reused for a different purpose.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns false if we consider it to still be a paging page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM VM Handle.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The page in question.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pRegFrame Trap register frame.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pCpu The disassembly info for the faulting instruction.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pvFault The fault address.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @remark The REP prefix check is left to the caller because of STOSD/W.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncDECLINLINE(bool) pgmPoolMonitorIsReused(PVM pVM, PPGMPOOLPAGE pPage, PCPUMCTXCORE pRegFrame, PDISCPUSTATE pCpu, RTGCPTR pvFault)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /** @todo could make this general, faulting close to rsp should be safe reuse heuristic. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Fault caused by stack writes while trying to inject an interrupt event. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log(("pgmPoolMonitorIsReused: reused %RGv for interrupt stack (rsp=%RGv).\n", pvFault, pRegFrame->rsp));
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync return true;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* call implies the actual push of the return address faulted */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return true;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return true;
9984bae4ef25be8afd95d184308adcfef6e2ec0dvboxsync return true;
0975ae0a0fb615c945150c48e4a73187c1f4f84dvboxsync return true;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return true;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return true;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync case OP_MOVNTDQ: /* solaris - hwblkclr & hwblkpagecopy */
1a25adaca81841abf5e6cdfed02eaff64941357dvboxsync return true;
5b6e2c9a765c3c72295acc15791af8a700746956vboxsync return true;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return false;
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync return true;
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync //if (pPage->fCR3Mix)
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync // return false;
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync return false;
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync * Flushes the page being accessed.
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync * @returns VBox status code suitable for scheduling.
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync * @param pVM The VM handle.
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync * @param pPool The pool.
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync * @param pPage The pool page (head).
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync * @param pCpu The disassembly of the write instruction.
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync * @param pRegFrame The trap register frame.
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync * @param GCPhysFault The fault address as guest physical address.
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync * @param pvFault The fault address.
1fb9c510656583ba12872e082125263a58d9bc6bvboxsyncstatic int pgmPoolAccessHandlerFlush(PVM pVM, PPGMPOOL pPool, PPGMPOOLPAGE pPage, PDISCPUSTATE pCpu,
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, RTGCPTR pvFault)
f351fab06d1e1507b72f5c574df71193061fd393vboxsync * First, do the flushing.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Emulate the instruction (xp/w2k problem, requires pc/cr2/sp detection).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync int rc2 = EMInterpretInstructionCPU(pVM, pCpu, pRegFrame, pvFault, &cbWritten);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if (PATMIsPatchGCAddr(pVM, (RTRCPTR)pRegFrame->eip))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolAccessHandlerPTWorker: Interpretation failed for patch code %04x:%RGv, ignoring.\n",
50df3da42ff6589b0ecc4f50f2288811bc370186vboxsync STAM_COUNTER_INC(&pPool->StatMonitorRZIntrFailPatch2);
b1c3cdef473df2fbc621d5da81acc82dbfb8a11avboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,EmulateInstr));
6778b34cb96bef0fef23ebc461eb6a429d2907c5vboxsync /* See use in pgmPoolAccessHandlerSimple(). */
6778b34cb96bef0fef23ebc461eb6a429d2907c5vboxsync LogFlow(("pgmPoolAccessHandlerPT: returns %Rrc (flushed)\n", rc));
614cbe11a7e5588dc8d369e223174b1441a09359vboxsync * Handles the STOSD write accesses.
614cbe11a7e5588dc8d369e223174b1441a09359vboxsync * @returns VBox status code suitable for scheduling.
614cbe11a7e5588dc8d369e223174b1441a09359vboxsync * @param pVM The VM handle.
32f9be50b34dbbdfceec5c81c0594d6a1d66d990vboxsync * @param pPool The pool.
614cbe11a7e5588dc8d369e223174b1441a09359vboxsync * @param pPage The pool page (head).
614cbe11a7e5588dc8d369e223174b1441a09359vboxsync * @param pCpu The disassembly of the write instruction.
9984bae4ef25be8afd95d184308adcfef6e2ec0dvboxsync * @param pRegFrame The trap register frame.
614cbe11a7e5588dc8d369e223174b1441a09359vboxsync * @param GCPhysFault The fault address as guest physical address.
614cbe11a7e5588dc8d369e223174b1441a09359vboxsync * @param pvFault The fault address.
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsyncDECLINLINE(int) pgmPoolAccessHandlerSTOSD(PVM pVM, PPGMPOOL pPool, PPGMPOOLPAGE pPage, PDISCPUSTATE pCpu,
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, RTGCPTR pvFault)
d4b98dbce4cf7b3694b62d62a47553d399718dccvboxsync * Increment the modification counter and insert it into the list
d4b98dbce4cf7b3694b62d62a47553d399718dccvboxsync * of modified pages the first time.
b6d0062d24490dd07b4a424e5809b3b2bc910c5avboxsync * Execute REP STOSD.
b6d0062d24490dd07b4a424e5809b3b2bc910c5avboxsync * This ASSUMES that we're not invoked by Trap0e on in a out-of-sync
d4b98dbce4cf7b3694b62d62a47553d399718dccvboxsync * write situation, meaning that it's safe to write here.
b978e5849454446957177fd47ee98609ab0457a6vboxsync uint32_t iPrevSubset = PGMDynMapPushAutoSubset(pVCpu);
b978e5849454446957177fd47ee98609ab0457a6vboxsync pgmPoolMonitorChainChanging(pPool, pPage, GCPhysFault, (RTGCPTR)pu32, NULL);
5ace91141404400247438502a84a418fba00c8cfvboxsync pgmPoolMonitorChainChanging(pPool, pPage, GCPhysFault, (RTGCPTR)pu32, NULL);
5ace91141404400247438502a84a418fba00c8cfvboxsync PGMPhysSimpleWriteGCPhys(pVM, GCPhysFault, &pRegFrame->eax, 4);
5ace91141404400247438502a84a418fba00c8cfvboxsync /* See use in pgmPoolAccessHandlerSimple(). */
5ace91141404400247438502a84a418fba00c8cfvboxsync * Handles the simple write accesses.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * @returns VBox status code suitable for scheduling.
5ace91141404400247438502a84a418fba00c8cfvboxsync * @param pVM The VM handle.
5ace91141404400247438502a84a418fba00c8cfvboxsync * @param pPool The pool.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * @param pPage The pool page (head).
d94da006d266643454eaeeb7e54c7c4a06bff515vboxsync * @param pCpu The disassembly of the write instruction.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * @param pRegFrame The trap register frame.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param GCPhysFault The fault address as guest physical address.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pvFault The fault address.
0f5d1b2abd9e82c7ee46f1327287c44856604bcbvboxsyncDECLINLINE(int) pgmPoolAccessHandlerSimple(PVM pVM, PPGMPOOL pPool, PPGMPOOLPAGE pPage, PDISCPUSTATE pCpu,
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, RTGCPTR pvFault)
20a793635760c71752932fde640ba328cab84348vboxsync * Increment the modification counter and insert it into the list
5ace91141404400247438502a84a418fba00c8cfvboxsync * of modified pages the first time.
3cbb4f9a6a320e58ed398ef7aaa004cc8727abc5vboxsync * Clear all the pages. ASSUMES that pvFault is readable.
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync uint32_t iPrevSubset = PGMDynMapPushAutoSubset(pVCpu);
e17f587595bd5d3a7be56a892e3fd3a0ef83d268vboxsync pgmPoolMonitorChainChanging(pPool, pPage, GCPhysFault, pvFault, pCpu);
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync pgmPoolMonitorChainChanging(pPool, pPage, GCPhysFault, pvFault, pCpu);
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync * Interpret the instruction.
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync int rc = EMInterpretInstructionCPU(pVM, pCpu, pRegFrame, pvFault, &cb);
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync LogFlow(("pgmPoolAccessHandlerPTWorker: Interpretation failed for %04x:%RGv - opcode=%d\n",
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync pRegFrame->cs, (RTGCPTR)pRegFrame->rip, pCpu->pCurInstr->opcode));
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,EmulateInstr));
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync * Quick hack, with logging enabled we're getting stale
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync * code TLBs but no data TLB for EIP and crash in EMInterpretDisasOne.
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync * Flushing here is BAD and expensive, I think EMInterpretDisasOne will
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync * have to be fixed to support this. But that'll have to wait till next week.
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync * An alternative is to keep track of the changed PTEs together with the
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync * GCPhys from the guest PT. This may proove expensive though.
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync * At the moment, it's VITAL that it's done AFTER the instruction interpreting
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * because we need the stale TLBs in some cases (XP boot). This MUST be fixed properly!
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolAccessHandlerSimple: returns %Rrc cb=%d\n", rc, cb));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * \#PF Handler callback for PT write accesses.
09e2f92b8f54aa362088e216007b53ecdb42e283vboxsync * @returns VBox status code (appropriate for GC return).
09e2f92b8f54aa362088e216007b53ecdb42e283vboxsync * @param pVM VM Handle.
28c928d1100d3b6a6d3506224cae25ad04732f73vboxsync * @param uErrorCode CPU Error code.
09e2f92b8f54aa362088e216007b53ecdb42e283vboxsync * @param pRegFrame Trap register frame.
09e2f92b8f54aa362088e216007b53ecdb42e283vboxsync * NULL on DMA and other non CPU access.
09e2f92b8f54aa362088e216007b53ecdb42e283vboxsync * @param pvFault The fault address (cr2).
09e2f92b8f54aa362088e216007b53ecdb42e283vboxsync * @param GCPhysFault The GC physical address corresponding to pvFault.
09e2f92b8f54aa362088e216007b53ecdb42e283vboxsync * @param pvUser User argument.
09e2f92b8f54aa362088e216007b53ecdb42e283vboxsyncDECLEXPORT(int) pgmPoolAccessHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPHYS GCPhysFault, void *pvUser)
09e2f92b8f54aa362088e216007b53ecdb42e283vboxsync STAM_PROFILE_START(&pVM->pgm.s.CTX_SUFF(pPool)->CTX_SUFF_Z(StatMonitor), a);
28c928d1100d3b6a6d3506224cae25ad04732f73vboxsync LogFlow(("pgmPoolAccessHandler: pvFault=%RGv pPage=%p:{.idx=%d} GCPhysFault=%RGp\n", pvFault, pPage, pPage->idx, GCPhysFault));
5ace91141404400247438502a84a418fba00c8cfvboxsync * We should ALWAYS have the list head as user parameter. This
09e2f92b8f54aa362088e216007b53ecdb42e283vboxsync * is because we use that page to record the changes.
09e2f92b8f54aa362088e216007b53ecdb42e283vboxsync * Disassemble the faulting instruction.
09e2f92b8f54aa362088e216007b53ecdb42e283vboxsync int rc = EMInterpretDisasOne(pVM, pRegFrame, &Cpu, NULL);
09e2f92b8f54aa362088e216007b53ecdb42e283vboxsync * Check if it's worth dealing with.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync bool fReused = false;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if ( ( pPage->cModifications < 48 /** @todo #define */ /** @todo need to check that it's not mapping EIP. */ /** @todo adjust this! */
08bc90fc2848c80bf8270bedc883745b8398e186vboxsync && !(fReused = pgmPoolMonitorIsReused(pVM, pPage, pRegFrame, &Cpu, pvFault))
3cbb4f9a6a320e58ed398ef7aaa004cc8727abc5vboxsync && !pgmPoolMonitorIsForking(pPool, &Cpu, GCPhysFault & PAGE_OFFSET_MASK))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Simple instructions, no REP prefix.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync rc = pgmPoolAccessHandlerSimple(pVM, pPool, pPage, &Cpu, pRegFrame, GCPhysFault, pvFault);
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync STAM_PROFILE_STOP_EX(&pVM->pgm.s.CTX_SUFF(pPool)->CTX_SUFF_Z(StatMonitor), &pPool->CTX_MID_Z(StatMonitor,Handled), a);
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync * Windows is frequently doing small memset() operations (netio test 4k+).
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync * We have to deal with these or we'll kill the cache and performance.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync && pRegFrame->ecx * 4 <= PAGE_SIZE - ((uintptr_t)pvFault & PAGE_OFFSET_MASK)
74735ec6edd6640eebac8885fbb2dadc86b89cf5vboxsync && (pRegFrame->eax == 0 || pRegFrame->eax == 0x80) /* the two values observed. */
74735ec6edd6640eebac8885fbb2dadc86b89cf5vboxsync rc = pgmPoolAccessHandlerSTOSD(pVM, pPool, pPage, &Cpu, pRegFrame, GCPhysFault, pvFault);
74735ec6edd6640eebac8885fbb2dadc86b89cf5vboxsync STAM_PROFILE_STOP_EX(&pVM->pgm.s.CTX_SUFF(pPool)->CTX_SUFF_Z(StatMonitor), &pPool->CTX_MID_Z(StatMonitor,RepStosd), a);
74735ec6edd6640eebac8885fbb2dadc86b89cf5vboxsync /* REP prefix, don't bother. */
74735ec6edd6640eebac8885fbb2dadc86b89cf5vboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,RepPrefix));
0f5b937bdc21496925500f3ce418794a5a9a1351vboxsync Log4(("pgmPoolAccessHandler: eax=%#x ecx=%#x edi=%#x esi=%#x rip=%RGv opcode=%d prefix=%#x\n",
74735ec6edd6640eebac8885fbb2dadc86b89cf5vboxsync pRegFrame->eax, pRegFrame->ecx, pRegFrame->edi, pRegFrame->esi, (RTGCPTR)pRegFrame->rip, Cpu.pCurInstr->opcode, Cpu.prefix));
74735ec6edd6640eebac8885fbb2dadc86b89cf5vboxsync * Not worth it, so flush it.
74735ec6edd6640eebac8885fbb2dadc86b89cf5vboxsync * If we considered it to be reused, don't to back to ring-3
74735ec6edd6640eebac8885fbb2dadc86b89cf5vboxsync * to emulate failed instructions since we usually cannot
74735ec6edd6640eebac8885fbb2dadc86b89cf5vboxsync * interpret then. This may be a bit risky, in which case
74735ec6edd6640eebac8885fbb2dadc86b89cf5vboxsync * the reuse detection must be fixed.
74735ec6edd6640eebac8885fbb2dadc86b89cf5vboxsync rc = pgmPoolAccessHandlerFlush(pVM, pPool, pPage, &Cpu, pRegFrame, GCPhysFault, pvFault);
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync STAM_PROFILE_STOP_EX(&pVM->pgm.s.CTX_SUFF(pPool)->CTX_SUFF_Z(StatMonitor), &pPool->CTX_MID_Z(StatMonitor,FlushPage), a);
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync# endif /* !IN_RING3 */
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync#endif /* PGMPOOL_WITH_MONITORING */
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync * Inserts a page into the GCPhys hash table.
e17f587595bd5d3a7be56a892e3fd3a0ef83d268vboxsync * @param pPool The pool.
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync * @param pPage The page.
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsyncDECLINLINE(void) pgmPoolHashInsert(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync Log3(("pgmPoolHashInsert: %RGp\n", pPage->GCPhys));
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync Assert(pPage->GCPhys != NIL_RTGCPHYS); Assert(pPage->iNext == NIL_PGMPOOL_IDX);
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync * Removes a page from the GCPhys hash table.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync * @param pPage The page.
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsyncDECLINLINE(void) pgmPoolHashRemove(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync Log3(("pgmPoolHashRemove: %RGp\n", pPage->GCPhys));
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync AssertReleaseMsgFailed(("GCPhys=%RGp idx=%#x\n", pPage->GCPhys, pPage->idx));
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync * Frees up one cache page.
016bd61cdd14201a24f289559b0cc333d8c94748vboxsync * @returns VBox status code.
016bd61cdd14201a24f289559b0cc333d8c94748vboxsync * @retval VINF_SUCCESS on success.
016bd61cdd14201a24f289559b0cc333d8c94748vboxsync * @retval VERR_PGM_POOL_CLEARED if the deregistration of a physical handler will cause a light weight pool flush.
016bd61cdd14201a24f289559b0cc333d8c94748vboxsync * @param pPool The pool.
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync * @param iUser The user index.
4584ef6026a823006bea5acbeb13dc4efe50da69vboxsyncstatic int pgmPoolCacheFreeOne(PPGMPOOL pPool, uint16_t iUser)
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync Assert(pPool->iAgeHead != pPool->iAgeTail); /* We shouldn't be here if there < 2 cached entries! */
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync * Select one page from the tail of the age list.
a46e399d5426a79f6f7e18d0ba85c505280e9386vboxsync/* This is the alternative to the SyncCR3 pgmPoolCacheUsed calls.
a46e399d5426a79f6f7e18d0ba85c505280e9386vboxsync if (pPool->aPages[iToFree].iUserHead != NIL_PGMPOOL_USER_INDEX)
13b9db9ae2c12b6c4e00eda5c79772d57a0d29e1vboxsync uint16_t i = pPool->aPages[iToFree].iAgePrev;
13b9db9ae2c12b6c4e00eda5c79772d57a0d29e1vboxsync for (unsigned j = 0; j < 10 && i != NIL_PGMPOOL_USER_INDEX; j++, i = pPool->aPages[i].iAgePrev)
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync if (pPool->aPages[iToFree].iUserHead == NIL_PGMPOOL_USER_INDEX)
13b9db9ae2c12b6c4e00eda5c79772d57a0d29e1vboxsync iToFree = i;
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync * Reject any attempts at flushing the currently active shadow CR3 mapping
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync if (PGMGetHyperCR3(pPool->CTX_SUFF(pVM)) == pPage->Core.Key)
13b9db9ae2c12b6c4e00eda5c79772d57a0d29e1vboxsync /* Refresh the cr3 mapping by putting it at the head of the age list. */
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync LogFlow(("pgmPoolCacheFreeOne refuse CR3 mapping\n"));
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * Checks if a kind mismatch is really a page being reused
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * or if it's just normal remappings.
01cc79d6798a7ad8b8041ddb2b67fc8b37bf0b37vboxsync * @returns true if reused and the cached page (enmKind1) should be flushed
01cc79d6798a7ad8b8041ddb2b67fc8b37bf0b37vboxsync * @returns false if not reused.
01cc79d6798a7ad8b8041ddb2b67fc8b37bf0b37vboxsync * @param enmKind1 The kind of the cached page.
01cc79d6798a7ad8b8041ddb2b67fc8b37bf0b37vboxsync * @param enmKind2 The kind of the requested page.
01cc79d6798a7ad8b8041ddb2b67fc8b37bf0b37vboxsyncstatic bool pgmPoolCacheReusedByKind(PGMPOOLKIND enmKind1, PGMPOOLKIND enmKind2)
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * Never reuse them. There is no remapping in non-paging mode.
01cc79d6798a7ad8b8041ddb2b67fc8b37bf0b37vboxsync case PGMPOOLKIND_PAE_PDPT_FOR_32BIT: /* never reuse them for other types */
01cc79d6798a7ad8b8041ddb2b67fc8b37bf0b37vboxsync return false;
01cc79d6798a7ad8b8041ddb2b67fc8b37bf0b37vboxsync return true;
01cc79d6798a7ad8b8041ddb2b67fc8b37bf0b37vboxsync * It's perfectly fine to reuse these, except for PAE and non-paging stuff.
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync return true;
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync return false;
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * It's perfectly fine to reuse these, except for PAE and non-paging stuff.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync return true;
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync return false;
1171e4fb031146163c9a5a66bd9cbf3f2a5acdb6vboxsync * These cannot be flushed, and it's common to reuse the PDs as PTs.
1171e4fb031146163c9a5a66bd9cbf3f2a5acdb6vboxsync return false;
1171e4fb031146163c9a5a66bd9cbf3f2a5acdb6vboxsync * Attempts to satisfy a pgmPoolAlloc request from the cache.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * @returns VBox status code.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * @retval VINF_PGM_CACHED_PAGE on success.
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync * @retval VERR_FILE_NOT_FOUND if not found.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * @param pPool The pool.
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync * @param GCPhys The GC physical address of the page we're gonna shadow.
01cc79d6798a7ad8b8041ddb2b67fc8b37bf0b37vboxsync * @param enmKind The kind of mapping.
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync * @param iUser The shadow page pool index of the user table.
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync * @param iUserTable The index into the user table (shadowed).
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync * @param ppPage Where to store the pointer to the page.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsyncstatic int pgmPoolCacheAlloc(PPGMPOOL pPool, RTGCPHYS GCPhys, PGMPOOLKIND enmKind, uint16_t iUser, uint32_t iUserTable, PPPGMPOOLPAGE ppPage)
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * Look up the GCPhys in the hash.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync Log3(("pgmPoolCacheAlloc: %RGp kind %s iUser=%d iUserTable=%x SLOT=%d\n", GCPhys, pgmPoolPoolKindToStr(enmKind), iUser, iUserTable, i));
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync Log3(("pgmPoolCacheAlloc: slot %d found page %RGp\n", i, pPage->GCPhys));
9b726ba798aabd1a27863e6f5cfeef1393bd198dvboxsync int rc = pgmPoolTrackAddUser(pPool, pPage, iUser, iUserTable);
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * The kind is different. In some cases we should now flush the page
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync * as it has been reused, but in most cases this is normal remapping
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * of PDs as PT or big pages using the GCPhys field in a slightly
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * different way than the other kinds.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync if (pgmPoolCacheReusedByKind((PGMPOOLKIND)pPage->enmKind, enmKind))
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync pgmPoolFlushPage(pPool, pPage); /* ASSUMES that VERR_PGM_POOL_CLEARED will be returned by pgmPoolTracInsert. */
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync } while (i != NIL_PGMPOOL_IDX);
3ecd8008b81f02a04220705ae0033142af363280vboxsync Log3(("pgmPoolCacheAlloc: Missed GCPhys=%RGp enmKind=%s\n", GCPhys, pgmPoolPoolKindToStr(enmKind)));
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * Inserts a page into the cache.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * @param pPool The pool.
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync * @param pPage The cached page.
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync * @param fCanBeCached Set if the page is fit for caching from the caller's point of view.
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsyncstatic void pgmPoolCacheInsert(PPGMPOOL pPool, PPGMPOOLPAGE pPage, bool fCanBeCached)
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * Insert into the GCPhys hash if the page is fit for that.
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync Log3(("pgmPoolCacheInsert: Caching %p:{.Core=%RHp, .idx=%d, .enmKind=%s, GCPhys=%RGp}\n",
2cd06fc737773d015b5268b9e4dfba5997915957vboxsync pPage, pPage->Core.Key, pPage->idx, pgmPoolPoolKindToStr(pPage->enmKind), pPage->GCPhys));
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync Log3(("pgmPoolCacheInsert: Not caching %p:{.Core=%RHp, .idx=%d, .enmKind=%s, GCPhys=%RGp}\n",
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync pPage, pPage->Core.Key, pPage->idx, pgmPoolPoolKindToStr(pPage->enmKind), pPage->GCPhys));
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * Insert at the head of the age list.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync pPool->aPages[pPool->iAgeHead].iAgePrev = pPage->idx;
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * Flushes a cached page.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * @param pPool The pool.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * @param pPage The cached page.
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsyncstatic void pgmPoolCacheFlushPage(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
d41220dff1068effe66bb6a11f444811ba58de40vboxsync Log3(("pgmPoolCacheFlushPage: %RGp\n", pPage->GCPhys));
d41220dff1068effe66bb6a11f444811ba58de40vboxsync * Remove the page from the hash.
d184d98f6e75700295aaa08ff14d0478dd6cc94avboxsync * Remove it from the age list.
d41220dff1068effe66bb6a11f444811ba58de40vboxsync pPool->aPages[pPage->iAgeNext].iAgePrev = pPage->iAgePrev;
90466ec66c4fa6a8cd62f01fbf141b51189d33cbvboxsync pPool->aPages[pPage->iAgePrev].iAgeNext = pPage->iAgeNext;
d41220dff1068effe66bb6a11f444811ba58de40vboxsync#endif /* PGMPOOL_WITH_CACHE */
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * Looks for pages sharing the monitor.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * @returns Pointer to the head page.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * @returns NULL if not found.
01cc79d6798a7ad8b8041ddb2b67fc8b37bf0b37vboxsync * @param pPool The Pool
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * @param pNewPage The page which is going to be monitored.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsyncstatic PPGMPOOLPAGE pgmPoolMonitorGetPageByGCPhys(PPGMPOOL pPool, PPGMPOOLPAGE pNewPage)
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * Look up the GCPhys in the hash.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync RTGCPHYS GCPhys = pNewPage->GCPhys & ~(RTGCPHYS)(PAGE_SIZE - 1);
dea1368099e5337861dd52906d4c683c447a33c4vboxsync /* find the head */
dea1368099e5337861dd52906d4c683c447a33c4vboxsync /* ignore, no monitoring. */
dea1368099e5337861dd52906d4c683c447a33c4vboxsync AssertFatalMsgFailed(("enmKind=%d idx=%d\n", pPage->enmKind, pPage->idx));
dea1368099e5337861dd52906d4c683c447a33c4vboxsync } while (i != NIL_PGMPOOL_IDX);
dea1368099e5337861dd52906d4c683c447a33c4vboxsync * Enabled write monitoring of a guest page.
dea1368099e5337861dd52906d4c683c447a33c4vboxsync * @returns VBox status code.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * @retval VINF_SUCCESS on success.
3cac8f8c6923a3a89ecfccda5e89ad75f48658e0vboxsync * @retval VERR_PGM_POOL_CLEARED if the registration of the physical handler will cause a light weight pool flush.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The cached page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic int pgmPoolMonitorInsert(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolMonitorInsert %RGp\n", pPage->GCPhys & ~(RTGCPHYS)(PAGE_SIZE - 1)));
b1c3cdef473df2fbc621d5da81acc82dbfb8a11avboxsync * Filter out the relevant kinds.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Nothing to monitor here. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Nothing to monitor here. */
6b022885f2cb6a55167609edecd89570cd80001dvboxsync AssertFatalMsgFailed(("This can't happen! enmKind=%d\n", pPage->enmKind));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Install handler.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPGMPOOLPAGE pPageHead = pgmPoolMonitorGetPageByGCPhys(pPool, pPage);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Assert(pPageHead != pPage); Assert(pPageHead->iMonitoredNext != pPage->idx);
1ce20e84ae29a712029d1e213740388d7e158d5cvboxsync pPool->aPages[pPageHead->iMonitoredNext].iMonitoredPrev = pPage->idx;
1ce20e84ae29a712029d1e213740388d7e158d5cvboxsync Assert(pPage->iMonitoredNext == NIL_PGMPOOL_IDX); Assert(pPage->iMonitoredPrev == NIL_PGMPOOL_IDX);
1ce20e84ae29a712029d1e213740388d7e158d5cvboxsync const RTGCPHYS GCPhysPage = pPage->GCPhys & ~(RTGCPHYS)(PAGE_SIZE - 1);
1ce20e84ae29a712029d1e213740388d7e158d5cvboxsync rc = PGMHandlerPhysicalRegisterEx(pVM, PGMPHYSHANDLERTYPE_PHYSICAL_WRITE,
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPool->pfnAccessHandlerR3, MMHyperCCToR3(pVM, pPage),
1ce20e84ae29a712029d1e213740388d7e158d5cvboxsync pPool->pfnAccessHandlerR0, MMHyperCCToR0(pVM, pPage),
1ce20e84ae29a712029d1e213740388d7e158d5cvboxsync pPool->pfnAccessHandlerRC, MMHyperCCToRC(pVM, pPage),
8b03ab0bcd5c238021bc8a43d887dd9d0870c0f5vboxsync /** @todo we should probably deal with out-of-memory conditions here, but for now increasing
1ce20e84ae29a712029d1e213740388d7e158d5cvboxsync * the heap size should suffice. */
1ce20e84ae29a712029d1e213740388d7e158d5cvboxsync if (pVM->pgm.s.fSyncFlags & PGM_SYNC_CLEAR_PGM_POOL)
1ce20e84ae29a712029d1e213740388d7e158d5cvboxsync * Disables write monitoring of a guest page.
c995102a21cae5b5ffeedadbfaddcc105809e196vboxsync * @returns VBox status code.
c995102a21cae5b5ffeedadbfaddcc105809e196vboxsync * @retval VINF_SUCCESS on success.
c995102a21cae5b5ffeedadbfaddcc105809e196vboxsync * @retval VERR_PGM_POOL_CLEARED if the deregistration of the physical handler will cause a light weight pool flush.
3b5afcead60894f1a362df77eaeff7b7cdaee7a9vboxsync * @param pPool The pool.
3b5afcead60894f1a362df77eaeff7b7cdaee7a9vboxsync * @param pPage The cached page.
3b5afcead60894f1a362df77eaeff7b7cdaee7a9vboxsyncstatic int pgmPoolMonitorFlush(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Filter out the relevant kinds.
00599f6d39cc25ca39845c2433cd75de7b9f6971vboxsync /* Nothing to monitor here. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertFatalMsgFailed(("This can't happen! enmKind=%d\n", pPage->enmKind));
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync * Remove the page from the monitored list or uninstall it if last.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPGMPOOLPAGE pNewHead = &pPool->aPages[pPage->iMonitoredNext];
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = PGMHandlerPhysicalChangeCallbacks(pVM, pPage->GCPhys & ~(RTGCPHYS)(PAGE_SIZE - 1),
10e1bc06b2908a0af56d92ffdbadd25b36a5ef61vboxsync pPool->pfnAccessHandlerR3, MMHyperCCToR3(pVM, pNewHead),
8f7bc6ad2b7bbcb4b3b96248cd2478e45f2e3b88vboxsync pPool->pfnAccessHandlerR0, MMHyperCCToR0(pVM, pNewHead),
5db1d52ffbcaa46c3d944c6c2d9c552306817d9avboxsync pPool->pfnAccessHandlerRC, MMHyperCCToRC(pVM, pNewHead),
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPool->aPages[pPage->iMonitoredPrev].iMonitoredNext = pPage->iMonitoredNext;
00599f6d39cc25ca39845c2433cd75de7b9f6971vboxsync pPool->aPages[pPage->iMonitoredNext].iMonitoredPrev = pPage->iMonitoredPrev;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = PGMHandlerPhysicalDeregister(pVM, pPage->GCPhys & ~(RTGCPHYS)(PAGE_SIZE - 1));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if (pVM->pgm.s.fSyncFlags & PGM_SYNC_CLEAR_PGM_POOL)
ec588a4ac8429a8b6c744544818b3ce3b2c75690vboxsync * Remove it from the list of modified pages (if in it).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Set or clear the fCR3Mix attribute in a chain of monitored pages.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The Pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage A page in the chain.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param fCR3Mix The new fCR3Mix value.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic void pgmPoolMonitorChainChangeCR3Mix(PPGMPOOL pPool, PPGMPOOLPAGE pPage, bool fCR3Mix)
abe73d9ccf5dd90fb1e3726792c56f2556a3d702vboxsync /* current */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* before */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* after */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Installs or modifies monitoring of a CR3 page (special).
74991d7531692858fd22acf371a7ee941567977cvboxsync * We're pretending the CR3 page is shadowed by the pool so we can use the
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * generic mechanisms in detecting chained monitoring. (This also gives us a
57399ab65e2825c324fb9dcb4642d4ae2c232509vboxsync * tast of what code changes are required to really pool CR3 shadow pages.)
3a21cbe769e7500039a2d17c794a911f7acb2dadvboxsync * @returns VBox status code.
3a21cbe769e7500039a2d17c794a911f7acb2dadvboxsync * @param pPool The pool.
3a21cbe769e7500039a2d17c794a911f7acb2dadvboxsync * @param idxRoot The CR3 (root) page index.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param GCPhysCR3 The (new) CR3 value.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncint pgmPoolMonitorMonitorCR3(PPGMPOOL pPool, uint16_t idxRoot, RTGCPHYS GCPhysCR3)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Assert(idxRoot != NIL_PGMPOOL_IDX && idxRoot < PGMPOOL_IDX_FIRST);
6863baa4d9788245537c986d9caf02fb1893d2c6vboxsync LogFlow(("pgmPoolMonitorMonitorCR3: idxRoot=%d pPage=%p:{.GCPhys=%RGp, .fMonitored=%d} GCPhysCR3=%RGp\n",
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync idxRoot, pPage, pPage->GCPhys, pPage->fMonitored, GCPhysCR3));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * The unlikely case where it already matches.
74991d7531692858fd22acf371a7ee941567977cvboxsync * Flush the current monitoring and remove it from the hash.
74991d7531692858fd22acf371a7ee941567977cvboxsync pgmPoolMonitorChainChangeCR3Mix(pPool, pPage, false);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Monitor the page at the new location and insert it into the hash.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolMonitorChainChangeCR3Mix(pPool, pPage, true);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Removes the monitoring of a CR3 page (special).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param idxRoot The CR3 (root) page index.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncint pgmPoolMonitorUnmonitorCR3(PPGMPOOL pPool, uint16_t idxRoot)
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync Assert(idxRoot != NIL_PGMPOOL_IDX && idxRoot < PGMPOOL_IDX_FIRST);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolMonitorUnmonitorCR3: idxRoot=%d pPage=%p:{.GCPhys=%RGp, .fMonitored=%d}\n",
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync idxRoot, pPage, pPage->GCPhys, pPage->fMonitored));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolMonitorChainChangeCR3Mix(pPool, pPage, false);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync# endif /* PGMPOOL_WITH_MIXED_PT_CR3 */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Inserts the page into the list of modified pages.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncvoid pgmPoolMonitorModifiedInsert(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log3(("pgmPoolMonitorModifiedInsert: idx=%d\n", pPage->idx));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync ("Next=%d Prev=%d idx=%d cModifications=%d Head=%d cModifiedPages=%d\n",
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPage->iModifiedNext, pPage->iModifiedPrev, pPage->idx, pPage->cModifications,
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPool->aPages[pPool->iModifiedHead].iModifiedPrev = pPage->idx;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if (pPool->cModifiedPages > pPool->cModifiedPagesHigh)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Removes the page from the list of modified pages and resets the
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * moficiation counter.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The page which is believed to be in the list of modified pages.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic void pgmPoolMonitorModifiedRemove(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
3cac8f8c6923a3a89ecfccda5e89ad75f48658e0vboxsync Log3(("pgmPoolMonitorModifiedRemove: idx=%d cModifications=%d\n", pPage->idx, pPage->cModifications));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPool->aPages[pPage->iModifiedNext].iModifiedPrev = NIL_PGMPOOL_IDX;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPool->aPages[pPage->iModifiedPrev].iModifiedNext = pPage->iModifiedNext;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPool->aPages[pPage->iModifiedNext].iModifiedPrev = pPage->iModifiedPrev;
00599f6d39cc25ca39845c2433cd75de7b9f6971vboxsync * Zaps the list of modified pages, resetting their modification counters in the process.
00599f6d39cc25ca39845c2433cd75de7b9f6971vboxsync * @param pVM The VM handle.
3080f6c0871099df43a4e91b31894d9c2b1369a8vboxsync LogFlow(("pgmPoolMonitorModifiedClearAll: cModifiedPages=%d\n", pPool->cModifiedPages));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertMsg(cPages == pPool->cModifiedPages, ("%d != %d\n", cPages, pPool->cModifiedPages));
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync * Clear all shadow pages and clear all modification counters.
ec588a4ac8429a8b6c744544818b3ce3b2c75690vboxsync * @param pVM The VM handle.
75fca099c974cbbd48f132af1378c60232614760vboxsync * @remark Should only be used when monitoring is available, thus placed in
75fca099c974cbbd48f132af1378c60232614760vboxsync * the PGMPOOL_WITH_MONITORING #ifdef.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolClearAll: cUsedPages=%d\n", pPool->cUsedPages));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Iterate all the pages until we've encountered all that in use.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * This is simple but not quite optimal solution.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync unsigned cModifiedPages = 0; NOREF(cModifiedPages);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * We only care about shadow page tables.
315f443a509c31db47b8f5cb94d26e54c3d5c497vboxsync void *pvShw = PGMPOOL_PAGE_2_PTR(pPool->CTX_SUFF(pVM), pPage);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* fall thru */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Assert(!pPage->cModifications || ++cModifiedPages);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Assert(pPage->iModifiedNext == NIL_PGMPOOL_IDX || pPage->cModifications);
9b45880674da6f82ca27cc28b0272de3dd3cc7dfvboxsync Assert(pPage->iModifiedPrev == NIL_PGMPOOL_IDX || pPage->cModifications);
57f41f24b7a290eba73c63449f44017d7917561dvboxsync /* swipe the special pages too. */
a3db4ff1e0aa7f94c9176ef16264df572eec0aebvboxsync for (iPage = PGMPOOL_IDX_FIRST_SPECIAL; iPage < PGMPOOL_IDX_FIRST; iPage++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Assert(!pPage->cModifications || ++cModifiedPages);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Assert(pPage->iModifiedNext == NIL_PGMPOOL_IDX || pPage->cModifications);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Assert(pPage->iModifiedPrev == NIL_PGMPOOL_IDX || pPage->cModifications);
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync AssertMsg(cModifiedPages == pPool->cModifiedPages, ("%d != %d\n", cModifiedPages, pPool->cModifiedPages));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Clear all the GCPhys links and rebuild the phys ext free list.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (PPGMRAMRANGE pRam = pPool->CTX_SUFF(pVM)->pgm.s.CTX_SUFF(pRamRanges);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync while (iPage-- > 0)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pRam->aPages[iPage].HCPhys &= MM_RAM_FLAGS_NO_REFS_MASK; /** @todo PAGE FLAGS */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPGMPOOLPHYSEXT paPhysExts = pPool->CTX_SUFF(paPhysExts);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned i = 0; i < cMaxPhysExts; i++)
32e2c6f724d4daf2665f2ffa5cbc2333073d42cfvboxsync paPhysExts[cMaxPhysExts - 1].iNext = NIL_PGMPOOL_PHYSEXT_INDEX;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync#endif /* IN_RING3 */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Handle SyncCR3 pool tasks
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VINF_SUCCESS if successfully added.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VINF_PGM_SYNC_CR3 is it needs to be deferred to ring 3 (GC only)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM The VM handle.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @remark Should only be used when monitoring is available, thus placed in
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * the PGMPOOL_WITH_MONITORING #ifdef.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * When monitoring shadowed pages, we reset the modification counters on CR3 sync.
a27fbcbb29ffc2196c2ebd0f2dad92f40c7ec65dvboxsync * Occasionally we will have to clear all the shadow page tables because we wanted
a27fbcbb29ffc2196c2ebd0f2dad92f40c7ec65dvboxsync * to monitor a page which was mapped by too many shadowed page tables. This operation
10e1bc06b2908a0af56d92ffdbadd25b36a5ef61vboxsync * sometimes refered to as a 'lightweight flush'.
5db1d52ffbcaa46c3d944c6c2d9c552306817d9avboxsync if (!(pVM->pgm.s.fSyncFlags & PGM_SYNC_CLEAR_PGM_POOL))
00599f6d39cc25ca39845c2433cd75de7b9f6971vboxsync# ifdef IN_RING3 /* Don't flush in ring-0 or raw mode, it's taking too long. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync# else /* !IN_RING3 */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("SyncCR3: PGM_SYNC_CLEAR_PGM_POOL is set -> VINF_PGM_SYNC_CR3\n"));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync VM_FF_SET(pVM, VM_FF_PGM_SYNC_CR3); /** @todo no need to do global sync, right? */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync# endif /* !IN_RING3 */
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync#endif /* PGMPOOL_WITH_MONITORING */
75fca099c974cbbd48f132af1378c60232614760vboxsync * Frees up at least one user entry.
75fca099c974cbbd48f132af1378c60232614760vboxsync * @returns VBox status code.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VINF_SUCCESS if successfully added.
09881e82498fc49063e06a8896e4e16d3cffeda8vboxsync * @retval VERR_PGM_POOL_FLUSHED if the pool was flushed.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param iUser The user index.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic int pgmPoolTrackFreeOneUser(PPGMPOOL pPool, uint16_t iUser)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Just free cached pages in a braindead fashion.
6b022885f2cb6a55167609edecd89570cd80001dvboxsync /** @todo walk the age list backwards and free the first with usage. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync } while (pPool->iUserFreeHead == NIL_PGMPOOL_USER_INDEX);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Lazy approach.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* @todo incompatible with long mode paging (cr3 root will be flushed) */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Inserts a page into the cache.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * This will create user node for the page, insert it into the GCPhys
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * hash, and insert it into the age list.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VINF_SUCCESS if successfully added.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VERR_PGM_POOL_FLUSHED if the pool was flushed.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VERR_PGM_POOL_CLEARED if the deregistration of the physical handler will cause a light weight pool flush.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The cached page.
d6b5539478863f176bfffefc1ada2b9489cfa092vboxsync * @param GCPhys The GC physical address of the page we're gonna shadow.
32e2c6f724d4daf2665f2ffa5cbc2333073d42cfvboxsync * @param iUser The user index.
d6b5539478863f176bfffefc1ada2b9489cfa092vboxsync * @param iUserTable The user table index.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncDECLINLINE(int) pgmPoolTrackInsert(PPGMPOOL pPool, PPGMPOOLPAGE pPage, RTGCPHYS GCPhys, uint16_t iUser, uint32_t iUserTable)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolTrackInsert GCPhys=%RGp iUser %x iUserTable %x\n", GCPhys, iUser, iUserTable));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Check that the entry doesn't already exists.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertMsg(paUsers[i].iUser != iUser || paUsers[i].iUserTable != iUserTable, ("%x %x vs new %x %x\n", paUsers[i].iUser, paUsers[i].iUserTable, iUser, iUserTable));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Find free a user node.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Unlink the user node from the free list,
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * initialize and insert it into the user list.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Insert into cache and enable monitoring of the guest page if enabled.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Until we implement caching of all levels, including the CR3 one, we'll
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * have to make sure we don't try monitor & cache any recursive reuse of
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * a monitored CR3 page. Because all windows versions are doing this we'll
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * have to be able to do combined access monitoring, CR3 + PT and
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * PD + PT (guest PAE).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * We're now cooperating with the CR3 monitor if an uncachable page is found.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync#if defined(PGMPOOL_WITH_MONITORING) || defined(PGMPOOL_WITH_CACHE)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync const bool fCanBeMonitored = true;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync bool fCanBeMonitored = pPool->CTX_SUFF(pVM)->pgm.s.GCPhysGstCR3Monitored == NIL_RTGCPHYS
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync || (GCPhys & X86_PTE_PAE_PG_MASK) != (pPool->CTX_SUFF(pVM)->pgm.s.GCPhysGstCR3Monitored & X86_PTE_PAE_PG_MASK)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolCacheInsert(pPool, pPage, fCanBeMonitored); /* This can be expanded. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* 'Failed' - free the usage, and keep it in the cache (if enabled). */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync#endif /* PGMPOOL_WITH_MONITORING */
01cc79d6798a7ad8b8041ddb2b67fc8b37bf0b37vboxsync# ifdef PGMPOOL_WITH_CACHE /* (only used when the cache is enabled.) */
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * Adds a user reference to a page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * This will move the page to the head of the
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VINF_SUCCESS if successfully added.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VERR_PGM_POOL_FLUSHED if the pool was flushed.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The cached page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param iUser The user index.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param iUserTable The user table.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic int pgmPoolTrackAddUser(PPGMPOOL pPool, PPGMPOOLPAGE pPage, uint16_t iUser, uint32_t iUserTable)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log3(("pgmPoolTrackAddUser GCPhys = %RGp iUser %x iUserTable %x\n", pPage->GCPhys, iUser, iUserTable));
5dda7f07dab8a954e6c4cf2378b15f921e60d9aavboxsync * Check that the entry doesn't already exists.
5dda7f07dab8a954e6c4cf2378b15f921e60d9aavboxsync AssertMsg(paUsers[i].iUser != iUser || paUsers[i].iUserTable != iUserTable, ("%x %x vs new %x %x\n", paUsers[i].iUser, paUsers[i].iUserTable, iUser, iUserTable));
5dda7f07dab8a954e6c4cf2378b15f921e60d9aavboxsync * Allocate a user node.
9c2450ffd7e8a08cc596a2e4cc4d4e4dc9b382cfvboxsync * Initialize the user node and insert it.
52694110156cee1511e430c9ae800de121a20050vboxsync * Tell the cache to update its replacement stats for this page.
016950bb1b289514e67d9e473538d22a50c0e408vboxsync# endif /* PGMPOOL_WITH_CACHE */
016950bb1b289514e67d9e473538d22a50c0e408vboxsync * Frees a user record associated with a page.
5dda7f07dab8a954e6c4cf2378b15f921e60d9aavboxsync * This does not clear the entry in the user table, it simply replaces the
5dda7f07dab8a954e6c4cf2378b15f921e60d9aavboxsync * user record to the chain of free records.
3cac8f8c6923a3a89ecfccda5e89ad75f48658e0vboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param HCPhys The HC physical address of the shadow page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param iUser The shadow page pool index of the user table.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param iUserTable The index into the user table (shadowed).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic void pgmPoolTrackFreeUser(PPGMPOOL pPool, PPGMPOOLPAGE pPage, uint16_t iUser, uint32_t iUserTable)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Unlink and free the specified user entry.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log3(("pgmPoolTrackFreeUser %RGp %x %x\n", pPage->GCPhys, iUser, iUserTable));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Special: For PAE and 32-bit paging, there is usually no more than one user. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* General: Linear search. */
2c080f6fc6ab70995d6390eeaa199d590c1a34d5vboxsync /* Fatal: didn't find it */
8a132edc1577cbe2a19cd778c1b2bea6ae5e8515vboxsync AssertFatalMsgFailed(("Didn't find the user entry! iUser=%#x iUserTable=%#x GCPhys=%RGp\n",
32f98f3d0fb00168315b4ece1f0808df4cd88248vboxsync * Gets the entry size of a shadow table.
32f98f3d0fb00168315b4ece1f0808df4cd88248vboxsync * @param enmKind The kind of page.
32f98f3d0fb00168315b4ece1f0808df4cd88248vboxsync * @returns The size of the entry in bytes. That is, 4 or 8.
32f98f3d0fb00168315b4ece1f0808df4cd88248vboxsync * @returns If the kind is not for a table, an assertion is raised and 0 is
32f98f3d0fb00168315b4ece1f0808df4cd88248vboxsync * returned.
32f98f3d0fb00168315b4ece1f0808df4cd88248vboxsyncDECLINLINE(unsigned) pgmPoolTrackGetShadowEntrySize(PGMPOOLKIND enmKind)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Gets the entry size of a guest table.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param enmKind The kind of page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns The size of the entry in bytes. That is, 0, 4 or 8.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns If the kind is not for a table, an assertion is raised and 0 is
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * returned.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncDECLINLINE(unsigned) pgmPoolTrackGetGuestEntrySize(PGMPOOLKIND enmKind)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /** @todo can we return 0? (nobody is calling this...) */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Scans one shadow page table for mappings of a physical page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM The VM handle.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPhysPage The guest page in question.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param iShw The shadow page table.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param cRefs The number of references made in that PT.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic void pgmPoolTrackFlushGCPhysPTInt(PVM pVM, PCPGMPAGE pPhysPage, uint16_t iShw, uint16_t cRefs)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolTrackFlushGCPhysPT: HCPhys=%RHp iShw=%d cRefs=%d\n", pPhysPage->HCPhys, iShw, cRefs));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Assert sanity.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertFatalMsg(iShw < pPool->cCurPages && iShw != NIL_PGMPOOL_IDX, ("iShw=%d\n", iShw));
6b022885f2cb6a55167609edecd89570cd80001dvboxsync * Then, clear the actual mappings to the page in the shadow PT.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync const uint32_t u32 = PGM_PAGE_GET_HCPHYS(pPhysPage) | X86_PTE_P;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PX86PT pPT = (PX86PT)PGMPOOL_PAGE_2_PTR(pVM, pPage);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pPT->a); i++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if ((pPT->a[i].u & (X86_PTE_PG_MASK | X86_PTE_P)) == u32)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log4(("pgmPoolTrackFlushGCPhysPTs: i=%d pte=%RX32 cRefs=%#x\n", i, pPT->a[i], cRefs));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPT->a[i].u = 0;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync RTLogPrintf("cRefs=%d iFirstPresent=%d cPresent=%d\n", cRefs, pPage->iFirstPresent, pPage->cPresent);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if ((pPT->a[i].u & (X86_PTE_PG_MASK | X86_PTE_P)) == u32)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPT->a[i].u = 0;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertFatalMsgFailed(("cRefs=%d iFirstPresent=%d cPresent=%d\n", cRefs, pPage->iFirstPresent, pPage->cPresent));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync const uint64_t u64 = PGM_PAGE_GET_HCPHYS(pPhysPage) | X86_PTE_P;
b1c3cdef473df2fbc621d5da81acc82dbfb8a11avboxsync PX86PTPAE pPT = (PX86PTPAE)PGMPOOL_PAGE_2_PTR(pVM, pPage);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pPT->a); i++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if ((pPT->a[i].u & (X86_PTE_PAE_PG_MASK | X86_PTE_P)) == u64)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log4(("pgmPoolTrackFlushGCPhysPTs: i=%d pte=%RX64 cRefs=%#x\n", i, pPT->a[i], cRefs));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPT->a[i].u = 0;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync RTLogPrintf("cRefs=%d iFirstPresent=%d cPresent=%d\n", cRefs, pPage->iFirstPresent, pPage->cPresent);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if ((pPT->a[i].u & (X86_PTE_PAE_PG_MASK | X86_PTE_P)) == u64)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPT->a[i].u = 0;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertFatalMsgFailed(("cRefs=%d iFirstPresent=%d cPresent=%d u64=%RX64\n", cRefs, pPage->iFirstPresent, pPage->cPresent, u64));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync const uint64_t u64 = PGM_PAGE_GET_HCPHYS(pPhysPage) | X86_PTE_P;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PEPTPT pPT = (PEPTPT)PGMPOOL_PAGE_2_PTR(pVM, pPage);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pPT->a); i++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if ((pPT->a[i].u & (EPT_PTE_PG_MASK | X86_PTE_P)) == u64)
00599f6d39cc25ca39845c2433cd75de7b9f6971vboxsync Log4(("pgmPoolTrackFlushGCPhysPTs: i=%d pte=%RX64 cRefs=%#x\n", i, pPT->a[i], cRefs));
00599f6d39cc25ca39845c2433cd75de7b9f6971vboxsync pPT->a[i].u = 0;
5db1d52ffbcaa46c3d944c6c2d9c552306817d9avboxsync RTLogPrintf("cRefs=%d iFirstPresent=%d cPresent=%d\n", cRefs, pPage->iFirstPresent, pPage->cPresent);
ec588a4ac8429a8b6c744544818b3ce3b2c75690vboxsync if ((pPT->a[i].u & (EPT_PTE_PG_MASK | X86_PTE_P)) == u64)
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync pPT->a[i].u = 0;
75fca099c974cbbd48f132af1378c60232614760vboxsync AssertFatalMsgFailed(("cRefs=%d iFirstPresent=%d cPresent=%d\n", cRefs, pPage->iFirstPresent, pPage->cPresent));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertFatalMsgFailed(("enmKind=%d iShw=%d\n", pPage->enmKind, iShw));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Scans one shadow page table for mappings of a physical page.
19b725c530eb49600728765de7ed451cbe290740vboxsync * @param pVM The VM handle.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPhysPage The guest page in question.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param iShw The shadow page table.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param cRefs The number of references made in that PT.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncvoid pgmPoolTrackFlushGCPhysPT(PVM pVM, PPGMPAGE pPhysPage, uint16_t iShw, uint16_t cRefs)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPGMPOOL pPool = pVM->pgm.s.CTX_SUFF(pPool); NOREF(pPool);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolTrackFlushGCPhysPT: HCPhys=%RHp iShw=%d cRefs=%d\n", pPhysPage->HCPhys, iShw, cRefs));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_PROFILE_START(&pPool->StatTrackFlushGCPhysPT, f);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolTrackFlushGCPhysPTInt(pVM, pPhysPage, iShw, cRefs);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPhysPage->HCPhys &= MM_RAM_FLAGS_NO_REFS_MASK; /** @todo PAGE FLAGS */
3080f6c0871099df43a4e91b31894d9c2b1369a8vboxsync STAM_PROFILE_STOP(&pPool->StatTrackFlushGCPhysPT, f);
00599f6d39cc25ca39845c2433cd75de7b9f6971vboxsync * Flushes a list of shadow page tables mapping the same physical page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM The VM handle.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPhysPage The guest page in question.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param iPhysExt The physical cross reference extent list to flush.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncvoid pgmPoolTrackFlushGCPhysPTs(PVM pVM, PPGMPAGE pPhysPage, uint16_t iPhysExt)
5db1d52ffbcaa46c3d944c6c2d9c552306817d9avboxsync STAM_PROFILE_START(&pPool->StatTrackFlushGCPhysPTs, f);
3080f6c0871099df43a4e91b31894d9c2b1369a8vboxsync LogFlow(("pgmPoolTrackFlushGCPhysPTs: HCPhys=%RHp iPhysExt\n", pPhysPage->HCPhys, iPhysExt));
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync for (unsigned i = 0; i < RT_ELEMENTS(pPhysExt->aidx); i++)
75fca099c974cbbd48f132af1378c60232614760vboxsync pgmPoolTrackFlushGCPhysPTInt(pVM, pPhysPage, pPhysExt->aidx[i], 1);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* insert the list into the free list and clear the ram range entry. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPhysPage->HCPhys &= MM_RAM_FLAGS_NO_REFS_MASK; /** @todo PAGE FLAGS */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_PROFILE_STOP(&pPool->StatTrackFlushGCPhysPTs, f);
020916e230faa4a37bace3a8480f54fac94ea173vboxsync#endif /* PGMPOOL_WITH_GCPHYS_TRACKING */
aaeb2e2f6ed5b164f1dec9a16a7adeb84f64cf31vboxsync * Scans all shadow page tables for mappings of a physical page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * This may be slow, but it's most likely more efficient than cleaning
5007ad5d2bce84d88ee339a94e0aa7b91c699194vboxsync * out the entire page pool / cache.
020916e230faa4a37bace3a8480f54fac94ea173vboxsync * @returns VBox status code.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VINF_SUCCESS if all references has been successfully cleared.
020916e230faa4a37bace3a8480f54fac94ea173vboxsync * @retval VINF_PGM_GCPHYS_ALIASED if we're better off with a CR3 sync and
50df3da42ff6589b0ecc4f50f2288811bc370186vboxsync * a page pool cleaning.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM The VM handle.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPhysPage The guest page in question.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncint pgmPoolTrackFlushGCPhysPTsSlow(PVM pVM, PPGMPAGE pPhysPage)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_PROFILE_START(&pPool->StatTrackFlushGCPhysPTsSlow, s);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolTrackFlushGCPhysPTsSlow: cUsedPages=%d cPresent=%d HCPhys=%RHp\n",
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPool->cUsedPages, pPool->cPresent, pPhysPage->HCPhys));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * There is a limit to what makes sense.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolTrackFlushGCPhysPTsSlow: giving up... (cPresent=%d)\n", pPool->cPresent));
aaeb2e2f6ed5b164f1dec9a16a7adeb84f64cf31vboxsync STAM_PROFILE_STOP(&pPool->StatTrackFlushGCPhysPTsSlow, s);
b978e5849454446957177fd47ee98609ab0457a6vboxsync * Iterate all the pages until we've encountered all that in use.
b978e5849454446957177fd47ee98609ab0457a6vboxsync * This is simple but not quite optimal solution.
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync const uint64_t u64 = PGM_PAGE_GET_HCPHYS(pPhysPage) | X86_PTE_P;
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync * We only care about shadow page tables.
b978e5849454446957177fd47ee98609ab0457a6vboxsync PX86PT pPT = (PX86PT)PGMPOOL_PAGE_2_PTR(pVM, pPage);
b978e5849454446957177fd47ee98609ab0457a6vboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pPT->a); i++)
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync if ((pPT->a[i].u & (X86_PTE_PG_MASK | X86_PTE_P)) == u32)
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync //Log4(("pgmPoolTrackFlushGCPhysPTsSlow: idx=%d i=%d pte=%RX32\n", iPage, i, pPT->a[i]));
020916e230faa4a37bace3a8480f54fac94ea173vboxsync pPT->a[i].u = 0;
5007ad5d2bce84d88ee339a94e0aa7b91c699194vboxsync PX86PTPAE pPT = (PX86PTPAE)PGMPOOL_PAGE_2_PTR(pVM, pPage);
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pPT->a); i++)
467e62e1aa999ec951e820d74498ef79dd1bedbdvboxsync if ((pPT->a[i].u & (X86_PTE_PAE_PG_MASK | X86_PTE_P)) == u64)
020916e230faa4a37bace3a8480f54fac94ea173vboxsync //Log4(("pgmPoolTrackFlushGCPhysPTsSlow: idx=%d i=%d pte=%RX64\n", iPage, i, pPT->a[i]));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPT->a[i].u = 0;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPhysPage->HCPhys &= MM_RAM_FLAGS_NO_REFS_MASK; /** @todo PAGE FLAGS */
9c425bdea5f0991df62922b1584b805a86f2f898vboxsync STAM_PROFILE_STOP(&pPool->StatTrackFlushGCPhysPTsSlow, s);
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync * Clears the user entry in a user table.
b978e5849454446957177fd47ee98609ab0457a6vboxsync * This is used to remove all references to a page when flushing it.
b978e5849454446957177fd47ee98609ab0457a6vboxsyncstatic void pgmPoolTrackClearPageUser(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PCPGMPOOLUSER pUser)
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync * Map the user page.
b978e5849454446957177fd47ee98609ab0457a6vboxsync PPGMPOOLPAGE pUserPage = &pPool->aPages[pUser->iUser];
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync#if defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0) && !defined(VBOX_WITH_PGMPOOL_PAGING_ONLY)
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync /* Must translate the fake 2048 entry PD to a 512 PD one since the R0 mapping is not linear. */
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync pUserPage = &pPool->aPages[PGMPOOL_IDX_PAE_PD_0 + iPdpt];
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync Assert(pUserPage->enmKind == PGMPOOLKIND_PAE_PD_FOR_PAE_PD);
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync u.pau64 = (uint64_t *)PGMPOOL_PAGE_2_PTR(pPool->CTX_SUFF(pVM), pUserPage);
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync /* Safety precaution in case we change the paging for other modes too in the future. */
020916e230faa4a37bace3a8480f54fac94ea173vboxsync Assert(PGMGetHyperCR3(pPool->CTX_SUFF(pVM)) != pPage->Core.Key);
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync * Some sanity checks.
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync Assert(!(u.pau32[iUserTable] & PGM_PDFLAGS_MAPPING));
467e62e1aa999ec951e820d74498ef79dd1bedbdvboxsync# if !defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0) && !defined(VBOX_WITH_PGMPOOL_PAGING_ONLY)
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync Assert(iUserTable < 2048 && pUser->iUser == PGMPOOL_IDX_PAE_PD);
020916e230faa4a37bace3a8480f54fac94ea173vboxsync AssertMsg(!(u.pau64[iUserTable] & PGM_PDFLAGS_MAPPING), ("%llx %d\n", u.pau64[iUserTable], iUserTable));
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync Assert(!(u.pau64[iUserTable] & PGM_PLXFLAGS_PERMANENT));
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync Assert(!(u.pau64[iUserTable] & PGM_PDFLAGS_MAPPING));
5007ad5d2bce84d88ee339a94e0aa7b91c699194vboxsync Assert(!(u.pau64[iUserTable] & PGM_PLXFLAGS_PERMANENT));
5007ad5d2bce84d88ee339a94e0aa7b91c699194vboxsync Assert(!(u.pau64[iUserTable] & PGM_PLXFLAGS_PERMANENT));
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync /* GCPhys >> PAGE_SHIFT is the index here */
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync AssertMsgFailed(("enmKind=%d\n", pUserPage->enmKind));
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync#endif /* VBOX_STRICT */
020916e230faa4a37bace3a8480f54fac94ea173vboxsync * Clear the entry in the user page.
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync /* 32-bit entries */
020916e230faa4a37bace3a8480f54fac94ea173vboxsync /* 64-bit entries */
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync# if !defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0) && !defined(VBOX_WITH_PGMPOOL_PAGING_ONLY)
7a6e9389a4252b9dc6fca1344e5ddbd1838849d5vboxsync AssertFatalMsgFailed(("enmKind=%d iUser=%#x iUserTable=%#x\n", pUserPage->enmKind, pUser->iUser, pUser->iUserTable));
b978e5849454446957177fd47ee98609ab0457a6vboxsync * Clears all users of a page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic void pgmPoolTrackClearPageUsers(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Free all the user records.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolTrackClearPageUsers %RGp\n", pPage->GCPhys));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Clear enter in user table. */
b978e5849454446957177fd47ee98609ab0457a6vboxsync pgmPoolTrackClearPageUser(pPool, pPage, &paUsers[i]);
9424be2edf0232241bc75178b401464d4de76cadvboxsync /* Free it. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Next. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Allocates a new physical cross reference extent.
020916e230faa4a37bace3a8480f54fac94ea173vboxsync * @returns Pointer to the allocated extent on success. NULL if we're out of them.
b978e5849454446957177fd47ee98609ab0457a6vboxsync * @param pVM The VM handle.
5007ad5d2bce84d88ee339a94e0aa7b91c699194vboxsync * @param piPhysExt Where to store the phys ext index.
5007ad5d2bce84d88ee339a94e0aa7b91c699194vboxsyncPPGMPOOLPHYSEXT pgmPoolTrackPhysExtAlloc(PVM pVM, uint16_t *piPhysExt)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_COUNTER_INC(&pPool->StamTrackPhysExtAllocFailures);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPGMPOOLPHYSEXT pPhysExt = &pPool->CTX_SUFF(paPhysExts)[iPhysExt];
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Frees a physical cross reference extent.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM The VM handle.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param iPhysExt The extent to free.
11c599b71a8c202a506b8623af57432c3d415ddavboxsyncvoid pgmPoolTrackPhysExtFree(PVM pVM, uint16_t iPhysExt)
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync PPGMPOOLPHYSEXT pPhysExt = &pPool->CTX_SUFF(paPhysExts)[iPhysExt];
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync for (unsigned i = 0; i < RT_ELEMENTS(pPhysExt->aidx); i++)
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync * Frees a physical cross reference extent.
b978e5849454446957177fd47ee98609ab0457a6vboxsync * @param pVM The VM handle.
11c599b71a8c202a506b8623af57432c3d415ddavboxsync * @param iPhysExt The extent to free.
11c599b71a8c202a506b8623af57432c3d415ddavboxsyncvoid pgmPoolTrackPhysExtFreeList(PVM pVM, uint16_t iPhysExt)
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync for (unsigned i = 0; i < RT_ELEMENTS(pPhysExt->aidx); i++)
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync * Insert a reference into a list of physical cross reference extents.
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync * @returns The new ram range flags (top 16-bits).
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync * @param pVM The VM handle.
b301c2ed80b2ae5201801c30b37618a158fcc14evboxsync * @param iPhysExt The physical extent index of the list head.
b301c2ed80b2ae5201801c30b37618a158fcc14evboxsync * @param iShwPT The shadow page table index.
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsyncstatic uint16_t pgmPoolTrackPhysExtInsert(PVM pVM, uint16_t iPhysExt, uint16_t iShwPT)
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync PPGMPOOLPHYSEXT paPhysExts = pPool->CTX_SUFF(paPhysExts);
b301c2ed80b2ae5201801c30b37618a158fcc14evboxsync /* special common case. */
b301c2ed80b2ae5201801c30b37618a158fcc14evboxsync if (paPhysExts[iPhysExt].aidx[2] == NIL_PGMPOOL_IDX)
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync STAM_COUNTER_INC(&pVM->pgm.s.StatTrackAliasedMany);
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync LogFlow(("pgmPoolTrackPhysExtAddref: %d:{,,%d}\n", iPhysExt, iShwPT));
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync return iPhysExt | (MM_RAM_FLAGS_CREFS_PHYSEXT << (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT));
11c599b71a8c202a506b8623af57432c3d415ddavboxsync /* general treatment. */
11c599b71a8c202a506b8623af57432c3d415ddavboxsync for (unsigned i = 0; i < RT_ELEMENTS(paPhysExts[iPhysExt].aidx); i++)
11c599b71a8c202a506b8623af57432c3d415ddavboxsync if (paPhysExts[iPhysExt].aidx[i] == NIL_PGMPOOL_IDX)
11c599b71a8c202a506b8623af57432c3d415ddavboxsync STAM_COUNTER_INC(&pVM->pgm.s.StatTrackAliasedMany);
11c599b71a8c202a506b8623af57432c3d415ddavboxsync LogFlow(("pgmPoolTrackPhysExtAddref: %d:{%d} i=%d cMax=%d\n", iPhysExt, iShwPT, i, cMax));
11c599b71a8c202a506b8623af57432c3d415ddavboxsync return iPhysExtStart | (MM_RAM_FLAGS_CREFS_PHYSEXT << (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT));
11c599b71a8c202a506b8623af57432c3d415ddavboxsync LogFlow(("pgmPoolTrackPhysExtAddref: overflow (1) iShwPT=%d\n", iShwPT));
11c599b71a8c202a506b8623af57432c3d415ddavboxsync return MM_RAM_FLAGS_IDX_OVERFLOWED | (MM_RAM_FLAGS_CREFS_PHYSEXT << (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT));
11c599b71a8c202a506b8623af57432c3d415ddavboxsync /* add another extent to the list. */
b978e5849454446957177fd47ee98609ab0457a6vboxsync PPGMPOOLPHYSEXT pNew = pgmPoolTrackPhysExtAlloc(pVM, &iPhysExt);
11c599b71a8c202a506b8623af57432c3d415ddavboxsync return MM_RAM_FLAGS_IDX_OVERFLOWED | (MM_RAM_FLAGS_CREFS_PHYSEXT << (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT));
fbf5c218f8bc15f0d765fef4b81e745f4db71b7avboxsync LogFlow(("pgmPoolTrackPhysExtAddref: added new extent %d:{%d}->%d\n", iPhysExt, iShwPT, iPhysExtStart));
9984bae4ef25be8afd95d184308adcfef6e2ec0dvboxsync return iPhysExt | (MM_RAM_FLAGS_CREFS_PHYSEXT << (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT));
965a56f05878cf7c9634998e98d0bed41ebf21dbvboxsync * Add a reference to guest physical page where extents are in use.
d6b5539478863f176bfffefc1ada2b9489cfa092vboxsync * @returns The new ram range flags (top 16-bits).
965a56f05878cf7c9634998e98d0bed41ebf21dbvboxsync * @param pVM The VM handle.
965a56f05878cf7c9634998e98d0bed41ebf21dbvboxsync * @param u16 The ram range flags (top 16-bits).
d7f733dd34ab7755807d85016b7c2ab3d1a362d4vboxsync * @param iShwPT The shadow page table index.
11c599b71a8c202a506b8623af57432c3d415ddavboxsyncuint16_t pgmPoolTrackPhysExtAddref(PVM pVM, uint16_t u16, uint16_t iShwPT)
11c599b71a8c202a506b8623af57432c3d415ddavboxsync if ((u16 >> (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT)) != MM_RAM_FLAGS_CREFS_PHYSEXT)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Convert to extent list.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Assert((u16 >> (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT)) == 1);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPGMPOOLPHYSEXT pPhysExt = pgmPoolTrackPhysExtAlloc(pVM, &iPhysExt);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolTrackPhysExtAddref: new extent: %d:{%d, %d}\n", iPhysExt, u16 & MM_RAM_FLAGS_IDX_MASK, iShwPT));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync u16 = iPhysExt | (MM_RAM_FLAGS_CREFS_PHYSEXT << (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT));
50df3da42ff6589b0ecc4f50f2288811bc370186vboxsync u16 = MM_RAM_FLAGS_IDX_OVERFLOWED | (MM_RAM_FLAGS_CREFS_PHYSEXT << (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT));
bee80f3f77b15c166b7debd080a70e5231ba6751vboxsync else if (u16 != (MM_RAM_FLAGS_IDX_OVERFLOWED | (MM_RAM_FLAGS_CREFS_PHYSEXT << (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT))))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Insert into the extent list.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync u16 = pgmPoolTrackPhysExtInsert(pVM, u16 & MM_RAM_FLAGS_IDX_MASK, iShwPT);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_COUNTER_INC(&pVM->pgm.s.StatTrackAliasedLots);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Clear references to guest physical memory.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The page.
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync * @param pPhysPage Pointer to the aPages entry in the ram range.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncvoid pgmPoolTrackPhysExtDerefGCPhys(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PPGMPAGE pPhysPage)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync const unsigned cRefs = pPhysPage->HCPhys >> MM_RAM_FLAGS_CREFS_SHIFT; /** @todo PAGE FLAGS */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertFatalMsg(cRefs == MM_RAM_FLAGS_CREFS_PHYSEXT, ("cRefs=%d HCPhys=%RHp pPage=%p:{.idx=%d}\n", cRefs, pPhysPage->HCPhys, pPage, pPage->idx));
ea04f885ccd9a758072e975806b1275d9afaac06vboxsync uint16_t iPhysExt = (pPhysPage->HCPhys >> MM_RAM_FLAGS_IDX_SHIFT) & MM_RAM_FLAGS_IDX_MASK;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPGMPOOLPHYSEXT paPhysExts = pPool->CTX_SUFF(paPhysExts);
9c425bdea5f0991df62922b1584b805a86f2f898vboxsync * Look for the shadow page and check if it's all freed.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned i = 0; i < RT_ELEMENTS(paPhysExts[iPhysExt].aidx); i++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (i = 0; i < RT_ELEMENTS(paPhysExts[iPhysExt].aidx); i++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if (paPhysExts[iPhysExt].aidx[i] != NIL_PGMPOOL_IDX)
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync LogFlow(("pgmPoolTrackPhysExtDerefGCPhys: HCPhys=%RX64 idx=%d\n", pPhysPage->HCPhys, pPage->idx));
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync /* we can free the node. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync const uint16_t iPhysExtNext = paPhysExts[iPhysExt].iNext;
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync /* lonely node */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolTrackPhysExtDerefGCPhys: HCPhys=%RX64 idx=%d lonely\n", pPhysPage->HCPhys, pPage->idx));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPhysPage->HCPhys &= MM_RAM_FLAGS_NO_REFS_MASK; /** @todo PAGE FLAGS */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync else if (iPhysExtPrev == NIL_PGMPOOL_PHYSEXT_INDEX)
9c425bdea5f0991df62922b1584b805a86f2f898vboxsync LogFlow(("pgmPoolTrackPhysExtDerefGCPhys: HCPhys=%RX64 idx=%d head\n", pPhysPage->HCPhys, pPage->idx));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPhysPage->HCPhys = (pPhysPage->HCPhys & MM_RAM_FLAGS_NO_REFS_MASK) /** @todo PAGE FLAGS */
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync | ((uint64_t)MM_RAM_FLAGS_CREFS_PHYSEXT << MM_RAM_FLAGS_CREFS_SHIFT)
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync | ((uint64_t)iPhysExtNext << MM_RAM_FLAGS_IDX_SHIFT);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* in list */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolTrackPhysExtDerefGCPhys: HCPhys=%RX64 idx=%d\n", pPhysPage->HCPhys, pPage->idx));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertFatalMsgFailed(("not-found! cRefs=%d HCPhys=%RHp pPage=%p:{.idx=%d}\n", cRefs, pPhysPage->HCPhys, pPage, pPage->idx));
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync else /* nothing to do */
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync LogFlow(("pgmPoolTrackPhysExtDerefGCPhys: HCPhys=%RX64\n", pPhysPage->HCPhys));
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync * Clear references to guest physical memory.
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync * This is the same as pgmPoolTracDerefGCPhys except that the guest physical address
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync * is assumed to be correct, so the linear search can be skipped and we can assert
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync * at an earlier point.
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync * @param pPool The pool.
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync * @param pPage The page.
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync * @param HCPhys The host physical address corresponding to the guest page.
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync * @param GCPhys The guest physical address corresponding to HCPhys.
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsyncstatic void pgmPoolTracDerefGCPhys(PPGMPOOL pPool, PPGMPOOLPAGE pPage, RTHCPHYS HCPhys, RTGCPHYS GCPhys)
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync * Walk range list.
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync PPGMRAMRANGE pRam = pPool->CTX_SUFF(pVM)->pgm.s.CTX_SUFF(pRamRanges);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* does it match? */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncRTHCPHYS HCPhysPage = PGM_PAGE_GET_HCPHYS(&pRam->aPages[iPage]);
55a158b986cee4c4ebe1a650e8727e1c6905e32evboxsyncLog(("pgmPoolTracDerefGCPhys %RHp vs %RHp\n", HCPhysPage, HCPhys));
55a158b986cee4c4ebe1a650e8727e1c6905e32evboxsync if (PGM_PAGE_GET_HCPHYS(&pRam->aPages[iPage]) == HCPhys)
55a158b986cee4c4ebe1a650e8727e1c6905e32evboxsync pgmTrackDerefGCPhys(pPool, pPage, &pRam->aPages[iPage]);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertFatalMsgFailed(("HCPhys=%RHp GCPhys=%RGp\n", HCPhys, GCPhys));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Clear references to guest physical memory.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param HCPhys The host physical address corresponding to the guest page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param GCPhysHint The guest physical address which may corresponding to HCPhys.
da936e0446fb2b56b813d5d938f1dfc6e4bf8b13vboxsyncstatic void pgmPoolTracDerefGCPhysHint(PPGMPOOL pPool, PPGMPOOLPAGE pPage, RTHCPHYS HCPhys, RTGCPHYS GCPhysHint)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Walk range list.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPGMRAMRANGE pRam = pPool->CTX_SUFF(pVM)->pgm.s.CTX_SUFF(pRamRanges);
6b022885f2cb6a55167609edecd89570cd80001dvboxsync /* does it match? */
e37007b39ddadf2af401414550b69c6c466f1633vboxsync if (PGM_PAGE_GET_HCPHYS(&pRam->aPages[iPage]) == HCPhys)
f8b934f4817639cddebe4d3c2ae25d39a91fe448vboxsync pgmTrackDerefGCPhys(pPool, pPage, &pRam->aPages[iPage]);
ac4d756407655dded93d992085e6cf2f7c45f592vboxsync * Damn, the hint didn't work. We'll have to do an expensive linear search.
9f1e0743f565b1975bb4efd7311b30cfa0d3e384vboxsync STAM_COUNTER_INC(&pPool->StatTrackLinearRamSearches);
3080f6c0871099df43a4e91b31894d9c2b1369a8vboxsync pRam = pPool->CTX_SUFF(pVM)->pgm.s.CTX_SUFF(pRamRanges);
da936e0446fb2b56b813d5d938f1dfc6e4bf8b13vboxsync while (iPage-- > 0)
00599f6d39cc25ca39845c2433cd75de7b9f6971vboxsync if (PGM_PAGE_GET_HCPHYS(&pRam->aPages[iPage]) == HCPhys)
00599f6d39cc25ca39845c2433cd75de7b9f6971vboxsync Log4(("pgmPoolTracDerefGCPhysHint: Linear HCPhys=%RHp GCPhysHint=%RGp GCPhysReal=%RGp\n",
00599f6d39cc25ca39845c2433cd75de7b9f6971vboxsync HCPhys, GCPhysHint, pRam->GCPhys + (iPage << PAGE_SHIFT)));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmTrackDerefGCPhys(pPool, pPage, &pRam->aPages[iPage]);
4cad44a5f7cfa7db8d5fb255a1df3b3cd1687853vboxsync AssertFatalMsgFailed(("HCPhys=%RHp GCPhysHint=%RGp\n", HCPhys, GCPhysHint));
5db1d52ffbcaa46c3d944c6c2d9c552306817d9avboxsync * Clear references to guest physical memory in a 32-bit / 32-bit page table.
585f64d6f624f9e683321dabeb21b0eb2e6aa473vboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The page.
54fe68d807196dc565de24055996e634ee40ee92vboxsync * @param pShwPT The shadow page table (mapping of the page).
54fe68d807196dc565de24055996e634ee40ee92vboxsync * @param pGstPT The guest page table.
54fe68d807196dc565de24055996e634ee40ee92vboxsyncDECLINLINE(void) pgmPoolTrackDerefPT32Bit32Bit(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PT pShwPT, PCX86PT pGstPT)
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pShwPT->a); i++)
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync Log4(("pgmPoolTrackDerefPT32Bit32Bit: i=%d pte=%RX32 hint=%RX32\n",
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync i, pShwPT->a[i].u & X86_PTE_PG_MASK, pGstPT->a[i].u & X86_PTE_PG_MASK));
ec588a4ac8429a8b6c744544818b3ce3b2c75690vboxsync pgmPoolTracDerefGCPhysHint(pPool, pPage, pShwPT->a[i].u & X86_PTE_PG_MASK, pGstPT->a[i].u & X86_PTE_PG_MASK);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Clear references to guest physical memory in a PAE / 32-bit page table.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pShwPT The shadow page table (mapping of the page).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pGstPT The guest page table (just a half one).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncDECLINLINE(void) pgmPoolTrackDerefPTPae32Bit(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PTPAE pShwPT, PCX86PT pGstPT)
ac4d756407655dded93d992085e6cf2f7c45f592vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pShwPT->a); i++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log4(("pgmPoolTrackDerefPTPae32Bit: i=%d pte=%RX32 hint=%RX32\n",
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync i, pShwPT->a[i].u & X86_PTE_PAE_PG_MASK, pGstPT->a[i].u & X86_PTE_PG_MASK));
00599f6d39cc25ca39845c2433cd75de7b9f6971vboxsync pgmPoolTracDerefGCPhysHint(pPool, pPage, pShwPT->a[i].u & X86_PTE_PAE_PG_MASK, pGstPT->a[i].u & X86_PTE_PG_MASK);
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync * Clear references to guest physical memory in a PAE / PAE page table.
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync * @param pPool The pool.
e751d1e1e4ae424d4846a23da32f663d14960796vboxsync * @param pPage The page.
e751d1e1e4ae424d4846a23da32f663d14960796vboxsync * @param pShwPT The shadow page table (mapping of the page).
e751d1e1e4ae424d4846a23da32f663d14960796vboxsync * @param pGstPT The guest page table.
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsyncDECLINLINE(void) pgmPoolTrackDerefPTPaePae(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PTPAE pShwPT, PCX86PTPAE pGstPT)
2b88b28162a49c6fa769c03d56767a9806d4f456vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pShwPT->a); i++)
5db1d52ffbcaa46c3d944c6c2d9c552306817d9avboxsync Log4(("pgmPoolTrackDerefPTPaePae: i=%d pte=%RX32 hint=%RX32\n",
54fe68d807196dc565de24055996e634ee40ee92vboxsync i, pShwPT->a[i].u & X86_PTE_PAE_PG_MASK, pGstPT->a[i].u & X86_PTE_PAE_PG_MASK));
54fe68d807196dc565de24055996e634ee40ee92vboxsync pgmPoolTracDerefGCPhysHint(pPool, pPage, pShwPT->a[i].u & X86_PTE_PAE_PG_MASK, pGstPT->a[i].u & X86_PTE_PAE_PG_MASK);
26741664c62f393bf6d97d6b873b3dae6356c96evboxsync * Clear references to guest physical memory in a 32-bit / 4MB page table.
5be6801527b2bb09f4b481e28d771f366961cdacvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pShwPT The shadow page table (mapping of the page).
9984bae4ef25be8afd95d184308adcfef6e2ec0dvboxsyncDECLINLINE(void) pgmPoolTrackDerefPT32Bit4MB(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PT pShwPT)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned i = 0; i < RT_ELEMENTS(pShwPT->a); i++, GCPhys += PAGE_SIZE)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log4(("pgmPoolTrackDerefPT32Bit4MB: i=%d pte=%RX32 GCPhys=%RGp\n",
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolTracDerefGCPhys(pPool, pPage, pShwPT->a[i].u & X86_PTE_PG_MASK, GCPhys);
6b022885f2cb6a55167609edecd89570cd80001dvboxsync * Clear references to guest physical memory in a PAE / 2/4MB page table.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pShwPT The shadow page table (mapping of the page).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncDECLINLINE(void) pgmPoolTrackDerefPTPaeBig(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PTPAE pShwPT)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned i = 0; i < RT_ELEMENTS(pShwPT->a); i++, GCPhys += PAGE_SIZE)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log4(("pgmPoolTrackDerefPTPaeBig: i=%d pte=%RX64 hint=%RGp\n",
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolTracDerefGCPhys(pPool, pPage, pShwPT->a[i].u & X86_PTE_PAE_PG_MASK, GCPhys);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync#endif /* PGMPOOL_WITH_GCPHYS_TRACKING */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Clear references to shadowed pages in a 32 bits page directory.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pShwPD The shadow page directory (mapping of the page).
0138777a0eae9d74905d86f792f1f1c497dab65evboxsyncDECLINLINE(void) pgmPoolTrackDerefPD(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PD pShwPD)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned i = 0; i < RT_ELEMENTS(pShwPD->a); i++)
6b022885f2cb6a55167609edecd89570cd80001dvboxsync PPGMPOOLPAGE pSubPage = (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, pShwPD->a[i].u & X86_PDE_PG_MASK);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolTrackFreeUser(pPool, pSubPage, pPage->idx, i);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertFatalMsgFailed(("%x\n", pShwPD->a[i].u & X86_PDE_PG_MASK));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /** @todo 64-bit guests: have to ensure that we're not exhausting the dynamic mappings! */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Clear references to shadowed pages in a PAE (legacy or 64 bits) page directory.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The page.
0138777a0eae9d74905d86f792f1f1c497dab65evboxsync * @param pShwPD The shadow page directory (mapping of the page).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncDECLINLINE(void) pgmPoolTrackDerefPDPae(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PDPAE pShwPD)
e4ea543752422f1139923e3e506c625b0a1827c5vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pShwPD->a); i++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPGMPOOLPAGE pSubPage = (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, pShwPD->a[i].u & X86_PDE_PAE_PG_MASK);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolTrackFreeUser(pPool, pSubPage, pPage->idx, i);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertFatalMsgFailed(("%RX64\n", pShwPD->a[i].u & X86_PDE_PAE_PG_MASK));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /** @todo 64-bit guests: have to ensure that we're not exhausting the dynamic mappings! */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Clear references to shadowed pages in a 64-bit page directory pointer table.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pShwPDPT The shadow page directory pointer table (mapping of the page).
6b022885f2cb6a55167609edecd89570cd80001dvboxsyncDECLINLINE(void) pgmPoolTrackDerefPDPT64Bit(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PDPT pShwPDPT)
5007ad5d2bce84d88ee339a94e0aa7b91c699194vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pShwPDPT->a); i++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPGMPOOLPAGE pSubPage = (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, pShwPDPT->a[i].u & X86_PDPE_PG_MASK);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolTrackFreeUser(pPool, pSubPage, pPage->idx, i);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertFatalMsgFailed(("%RX64\n", pShwPDPT->a[i].u & X86_PDPE_PG_MASK));
3cac8f8c6923a3a89ecfccda5e89ad75f48658e0vboxsync /** @todo 64-bit guests: have to ensure that we're not exhausting the dynamic mappings! */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Clear references to shadowed pages in a 64-bit level 4 page table.
5007ad5d2bce84d88ee339a94e0aa7b91c699194vboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pShwPML4 The shadow page directory pointer table (mapping of the page).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncDECLINLINE(void) pgmPoolTrackDerefPML464Bit(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PML4 pShwPML4)
50df3da42ff6589b0ecc4f50f2288811bc370186vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pShwPML4->a); i++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPGMPOOLPAGE pSubPage = (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, pShwPML4->a[i].u & X86_PDPE_PG_MASK);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolTrackFreeUser(pPool, pSubPage, pPage->idx, i);
1986f56777969a25707ab214f8dd070804be666cvboxsync AssertFatalMsgFailed(("%RX64\n", pShwPML4->a[i].u & X86_PML4E_PG_MASK));
5007ad5d2bce84d88ee339a94e0aa7b91c699194vboxsync /** @todo 64-bit guests: have to ensure that we're not exhausting the dynamic mappings! */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Clear references to shadowed pages in an EPT page table.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
e4ea543752422f1139923e3e506c625b0a1827c5vboxsync * @param pPage The page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pShwPML4 The shadow page directory pointer table (mapping of the page).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncDECLINLINE(void) pgmPoolTrackDerefPTEPT(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PEPTPT pShwPT)
5007ad5d2bce84d88ee339a94e0aa7b91c699194vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pShwPT->a); i++, GCPhys += PAGE_SIZE)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log4(("pgmPoolTrackDerefPTEPT: i=%d pte=%RX64 GCPhys=%RX64\n",
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync i, pShwPT->a[i].u & EPT_PTE_PG_MASK, pPage->GCPhys));
1986f56777969a25707ab214f8dd070804be666cvboxsync pgmPoolTracDerefGCPhys(pPool, pPage, pShwPT->a[i].u & EPT_PTE_PG_MASK, GCPhys);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Clear references to shadowed pages in an EPT page directory.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pShwPD The shadow page directory (mapping of the page).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncDECLINLINE(void) pgmPoolTrackDerefPDEPT(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PEPTPD pShwPD)
65ff326ac3915638f5c4e79c2c3e836aeeeb86devboxsync for (unsigned i = 0; i < RT_ELEMENTS(pShwPD->a); i++)
22343c7425791036f2c645cdf5316907527659b9vboxsync PPGMPOOLPAGE pSubPage = (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, pShwPD->a[i].u & EPT_PDE_PG_MASK);
65ff326ac3915638f5c4e79c2c3e836aeeeb86devboxsync pgmPoolTrackFreeUser(pPool, pSubPage, pPage->idx, i);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertFatalMsgFailed(("%RX64\n", pShwPD->a[i].u & EPT_PDE_PG_MASK));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /** @todo 64-bit guests: have to ensure that we're not exhausting the dynamic mappings! */
5007ad5d2bce84d88ee339a94e0aa7b91c699194vboxsync * Clear references to shadowed pages in an EPT page directory pointer table.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
5007ad5d2bce84d88ee339a94e0aa7b91c699194vboxsync * @param pPage The page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pShwPDPT The shadow page directory pointer table (mapping of the page).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncDECLINLINE(void) pgmPoolTrackDerefPDPTEPT(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PEPTPDPT pShwPDPT)
65ff326ac3915638f5c4e79c2c3e836aeeeb86devboxsync for (unsigned i = 0; i < RT_ELEMENTS(pShwPDPT->a); i++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPGMPOOLPAGE pSubPage = (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, pShwPDPT->a[i].u & EPT_PDPTE_PG_MASK);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolTrackFreeUser(pPool, pSubPage, pPage->idx, i);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertFatalMsgFailed(("%RX64\n", pShwPDPT->a[i].u & EPT_PDPTE_PG_MASK));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /** @todo 64-bit guests: have to ensure that we're not exhausting the dynamic mappings! */
65ff326ac3915638f5c4e79c2c3e836aeeeb86devboxsync * Clears all references made by this page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * This includes other shadow pages and GC physical addresses.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
ba15b5303eb3e9ebd10e3d357f51335399f9d28dvboxsync * @param pPage The page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic void pgmPoolTrackDeref(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
5007ad5d2bce84d88ee339a94e0aa7b91c699194vboxsync * Map the shadow page and take action according to the page kind.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync void *pvShw = PGMPOOL_PAGE_2_PTR(pPool->CTX_SUFF(pVM), pPage);
020916e230faa4a37bace3a8480f54fac94ea173vboxsync STAM_PROFILE_START(&pPool->StatTrackDerefGCPhys, g);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync int rc = PGM_GCPHYS_2_PTR(pPool->CTX_SUFF(pVM), pPage->GCPhys, &pvGst); AssertReleaseRC(rc);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolTrackDerefPT32Bit32Bit(pPool, pPage, (PX86PT)pvShw, (PCX86PT)pvGst);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_PROFILE_STOP(&pPool->StatTrackDerefGCPhys, g);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_PROFILE_START(&pPool->StatTrackDerefGCPhys, g);
bee80f3f77b15c166b7debd080a70e5231ba6751vboxsync int rc = PGM_GCPHYS_2_PTR_EX(pPool->CTX_SUFF(pVM), pPage->GCPhys, &pvGst); AssertReleaseRC(rc);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolTrackDerefPTPae32Bit(pPool, pPage, (PX86PTPAE)pvShw, (PCX86PT)pvGst);
65ff326ac3915638f5c4e79c2c3e836aeeeb86devboxsync STAM_PROFILE_STOP(&pPool->StatTrackDerefGCPhys, g);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_PROFILE_START(&pPool->StatTrackDerefGCPhys, g);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync int rc = PGM_GCPHYS_2_PTR(pPool->CTX_SUFF(pVM), pPage->GCPhys, &pvGst); AssertReleaseRC(rc);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolTrackDerefPTPaePae(pPool, pPage, (PX86PTPAE)pvShw, (PCX86PTPAE)pvGst);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_PROFILE_STOP(&pPool->StatTrackDerefGCPhys, g);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync case PGMPOOLKIND_32BIT_PT_FOR_PHYS: /* treat it like a 4 MB page */
82e90599291da476b2de7c8db33cfb0f2cbac774vboxsync STAM_PROFILE_START(&pPool->StatTrackDerefGCPhys, g);
82e90599291da476b2de7c8db33cfb0f2cbac774vboxsync pgmPoolTrackDerefPT32Bit4MB(pPool, pPage, (PX86PT)pvShw);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_PROFILE_STOP(&pPool->StatTrackDerefGCPhys, g);
e4ea543752422f1139923e3e506c625b0a1827c5vboxsync case PGMPOOLKIND_PAE_PT_FOR_PHYS: /* treat it like a 2 MB page */
d7f733dd34ab7755807d85016b7c2ab3d1a362d4vboxsync STAM_PROFILE_START(&pPool->StatTrackDerefGCPhys, g);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolTrackDerefPTPaeBig(pPool, pPage, (PX86PTPAE)pvShw);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_PROFILE_STOP(&pPool->StatTrackDerefGCPhys, g);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync#else /* !PGMPOOL_WITH_GCPHYS_TRACKING */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync#endif /* !PGMPOOL_WITH_GCPHYS_TRACKING */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolTrackDerefPDPae(pPool, pPage, (PX86PDPAE)pvShw);
bee80f3f77b15c166b7debd080a70e5231ba6751vboxsync pgmPoolTrackDerefPDPT64Bit(pPool, pPage, (PX86PDPT)pvShw);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolTrackDerefPML464Bit(pPool, pPage, (PX86PML4)pvShw);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolTrackDerefPTEPT(pPool, pPage, (PEPTPT)pvShw);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolTrackDerefPDEPT(pPool, pPage, (PEPTPD)pvShw);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolTrackDerefPDPTEPT(pPool, pPage, (PEPTPDPT)pvShw);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertFatalMsgFailed(("enmKind=%d\n", pPage->enmKind));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* paranoia, clear the shadow page. Remove this laser (i.e. let Alloc and ClearAll do it). */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync#endif /* PGMPOOL_WITH_USER_TRACKING */
3cac8f8c6923a3a89ecfccda5e89ad75f48658e0vboxsync * Flushes all the special root pages as part of a pgmPoolFlushAllInt operation.
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync * @param pPool The pool.
aaeb2e2f6ed5b164f1dec9a16a7adeb84f64cf31vboxsyncstatic void pgmPoolFlushAllSpecialRoots(PPGMPOOL pPool)
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync /* Start a subset so we won't run out of mapping space. */
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync uint32_t iPrevSubset = PGMDynMapPushAutoSubset(pVCpu);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * These special pages are all mapped into the indexes 1..PGMPOOL_IDX_FIRST.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Get the page address.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Mark stuff not present.
fa7355597d7eba5b4ca8a23056ebe1b8fb306fdbvboxsync u.pau64 = (uint64_t *)PGMPOOL_PAGE_2_PTR(pPool->CTX_SUFF(pVM), pPage);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned iPage = 0; iPage < X86_PG_ENTRIES; iPage++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if ((u.pau32[iPage] & (PGM_PDFLAGS_MAPPING | X86_PDE_P)) == X86_PDE_P)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync u.pau64 = (uint64_t *)PGMPOOL_PAGE_2_PTR(pPool->CTX_SUFF(pVM), pPage);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned iPage = 0; iPage < X86_PG_PAE_ENTRIES; iPage++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if ((u.pau64[iPage] & (PGM_PDFLAGS_MAPPING | X86_PDE_P)) == X86_PDE_P)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Not root of shadowed pages currently, ignore it. */
82e90599291da476b2de7c8db33cfb0f2cbac774vboxsync u.pau64 = (uint64_t *)PGMPOOL_PAGE_2_PTR(pPool->CTX_SUFF(pVM), pPage);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Paranoia (to be removed), flag a global CR3 sync.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync VM_FF_SET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Pop the subset. */
aaeb2e2f6ed5b164f1dec9a16a7adeb84f64cf31vboxsync * Flushes the entire cache.
b1c3cdef473df2fbc621d5da81acc82dbfb8a11avboxsync * It will assert a global CR3 flush (FF) and assumes the caller is aware of this
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * and execute this CR3 flush.
53163a75972769c720ae0b51a007ce4de6408778vboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * If there are no pages in the pool, there is nothing to do.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Nuke the free list and reinsert all pages into it.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned i = pPool->cCurPages - 1; i >= PGMPOOL_IDX_FIRST; i--)
e4ea543752422f1139923e3e506c625b0a1827c5vboxsync Assert(pPage->Core.Key == MMPage2Phys(pPool->pVMR3, pPage->pvPageR3));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPage->fZeroed = false; /* This could probably be optimized, but better safe than sorry. */
eab582ddaaa130fc769ad00b09b81b3966817d3fvboxsync pPool->aPages[pPool->cCurPages - 1].iNext = NIL_PGMPOOL_IDX;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Zap and reinitialize the user records.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned i = 0; i < cMaxUsers; i++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync paUsers[cMaxUsers - 1].iNext = NIL_PGMPOOL_USER_INDEX;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Clear all the GCPhys links and rebuild the phys ext free list.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (PPGMRAMRANGE pRam = pPool->CTX_SUFF(pVM)->pgm.s.CTX_SUFF(pRamRanges);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync while (iPage-- > 0)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pRam->aPages[iPage].HCPhys &= MM_RAM_FLAGS_NO_REFS_MASK; /** @todo PAGE FLAGS */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPGMPOOLPHYSEXT paPhysExts = pPool->CTX_SUFF(paPhysExts);
eab582ddaaa130fc769ad00b09b81b3966817d3fvboxsync for (unsigned i = 0; i < cMaxPhysExts; i++)
eab582ddaaa130fc769ad00b09b81b3966817d3fvboxsync paPhysExts[cMaxPhysExts - 1].iNext = NIL_PGMPOOL_PHYSEXT_INDEX;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Just zap the modified list.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Clear the GCPhys hash and the age list.
eab582ddaaa130fc769ad00b09b81b3966817d3fvboxsync for (unsigned i = 0; i < RT_ELEMENTS(pPool->aiHash); i++)
eab582ddaaa130fc769ad00b09b81b3966817d3fvboxsync * Flush all the special root pages.
eab582ddaaa130fc769ad00b09b81b3966817d3fvboxsync * Reinsert active pages into the hash and ensure monitoring chains are correct.
eab582ddaaa130fc769ad00b09b81b3966817d3fvboxsync for (unsigned i = PGMPOOL_IDX_FIRST_SPECIAL; i < PGMPOOL_IDX_FIRST; i++)
eab582ddaaa130fc769ad00b09b81b3966817d3fvboxsync /* ASSUMES that we're not sharing with any of the other special pages (safe for now). */
eab582ddaaa130fc769ad00b09b81b3966817d3fvboxsync int rc = PGMHandlerPhysicalChangeCallbacks(pVM, pPage->GCPhys & ~(RTGCPHYS)(PAGE_SIZE - 1),
eab582ddaaa130fc769ad00b09b81b3966817d3fvboxsync pPool->pfnAccessHandlerR3, MMHyperCCToR3(pVM, pPage),
82e90599291da476b2de7c8db33cfb0f2cbac774vboxsync pPool->pfnAccessHandlerR0, MMHyperCCToR0(pVM, pPage),
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync pPool->pfnAccessHandlerRC, MMHyperCCToRC(pVM, pPage),
9f1e0743f565b1975bb4efd7311b30cfa0d3e384vboxsync Assert(pPage->iUserHead == NIL_PGMPOOL_USER_INDEX); /* for now */
9f1e0743f565b1975bb4efd7311b30cfa0d3e384vboxsync * Finally, assert the FF.
9f1e0743f565b1975bb4efd7311b30cfa0d3e384vboxsync VM_FF_SET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3);
9f1e0743f565b1975bb4efd7311b30cfa0d3e384vboxsync * Flushes a pool page.
9f1e0743f565b1975bb4efd7311b30cfa0d3e384vboxsync * This moves the page to the free list after removing all user references to it.
9f1e0743f565b1975bb4efd7311b30cfa0d3e384vboxsync * In GC this will cause a CR3 reload if the page is traced back to an active root page.
10e1bc06b2908a0af56d92ffdbadd25b36a5ef61vboxsync * @returns VBox status code.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VINF_SUCCESS on success.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VERR_PGM_POOL_CLEARED if the deregistration of the physical handler will cause a light weight pool flush.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param HCPhys The HC physical address of the shadow page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncint pgmPoolFlushPage(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
9f1e0743f565b1975bb4efd7311b30cfa0d3e384vboxsync LogFlow(("pgmPoolFlushPage: pPage=%p:{.Key=%RHp, .idx=%d, .enmKind=%s, .GCPhys=%RGp}\n",
9f1e0743f565b1975bb4efd7311b30cfa0d3e384vboxsync pPage, pPage->Core.Key, pPage->idx, pgmPoolPoolKindToStr(pPage->enmKind), pPage->GCPhys));
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync * Quietly reject any attempts at flushing any of the special root pages.
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync Log(("pgmPoolFlushPage: special root page, rejected. enmKind=%s idx=%d\n", pgmPoolPoolKindToStr(pPage->enmKind), pPage->idx));
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync * Quietly reject any attempts at flushing the currently active shadow CR3 mapping
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync if (PGMGetHyperCR3(pPool->CTX_SUFF(pVM)) == pPage->Core.Key)
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync AssertMsg( pPage->enmKind == PGMPOOLKIND_64BIT_PML4
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync || pPage->enmKind == PGMPOOLKIND_PAE_PDPT_FOR_32BIT
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync ("Can't free the shadow CR3! (%RHp vs %RHp kind=%d\n", PGMGetHyperCR3(pPool->CTX_SUFF(pVM)), pPage->Core.Key, pPage->enmKind));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertMsg(pPage->enmKind == PGMPOOLKIND_64BIT_PML4,
ef4275be1971a6d17d45121d075a4f41659fa6c9vboxsync ("Can't free the shadow CR3! (%RHp vs %RHp kind=%d\n", PGMGetHyperCR3(pPool->CTX_SUFF(pVM)), pPage->Core.Key, pPage->enmKind));
ef4275be1971a6d17d45121d075a4f41659fa6c9vboxsync Log(("pgmPoolFlushPage: current active shadow CR3, rejected. enmKind=%s idx=%d\n", pgmPoolPoolKindToStr(pPage->enmKind), pPage->idx));
ef4275be1971a6d17d45121d075a4f41659fa6c9vboxsync /* Start a subset so we won't run out of mapping space. */
ef4275be1971a6d17d45121d075a4f41659fa6c9vboxsync uint32_t iPrevSubset = PGMDynMapPushAutoSubset(pVCpu);
ef4275be1971a6d17d45121d075a4f41659fa6c9vboxsync * Mark the page as being in need of a ASMMemZeroPage().
ef4275be1971a6d17d45121d075a4f41659fa6c9vboxsync * Clear the page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Flush it from the cache.
8f7bc6ad2b7bbcb4b3b96248cd2478e45f2e3b88vboxsync#endif /* PGMPOOL_WITH_CACHE */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Heavy stuff done. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Deregistering the monitoring.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Free the page.
40f47bc231ff6c86a7ddc3295eed7010e889e78avboxsync * Frees a usage of a pool page.
40f47bc231ff6c86a7ddc3295eed7010e889e78avboxsync * The caller is responsible to updating the user table so that it no longer
40f47bc231ff6c86a7ddc3295eed7010e889e78avboxsync * references the shadow page.
40f47bc231ff6c86a7ddc3295eed7010e889e78avboxsync * @param pPool The pool.
40f47bc231ff6c86a7ddc3295eed7010e889e78avboxsync * @param HCPhys The HC physical address of the shadow page.
40f47bc231ff6c86a7ddc3295eed7010e889e78avboxsync * @param iUser The shadow page pool index of the user table.
40f47bc231ff6c86a7ddc3295eed7010e889e78avboxsync * @param iUserTable The index into the user table (shadowed).
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsyncvoid pgmPoolFreeByPage(PPGMPOOL pPool, PPGMPOOLPAGE pPage, uint16_t iUser, uint32_t iUserTable)
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync LogFlow(("pgmPoolFreeByPage: pPage=%p:{.Key=%RHp, .idx=%d, enmKind=%s} iUser=%#x iUserTable=%#x\n",
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync pPage, pPage->Core.Key, pPage->idx, pgmPoolPoolKindToStr(pPage->enmKind), iUser, iUserTable));
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync pgmPoolTrackFreeUser(pPool, pPage, iUser, iUserTable);
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync pgmPoolFlushPage(pPool, pPage); /* ASSUMES that VERR_PGM_POOL_CLEARED can be ignored here. */
82e90599291da476b2de7c8db33cfb0f2cbac774vboxsync * Makes one or more free page free.
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync * @returns VBox status code.
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync * @retval VINF_SUCCESS on success.
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync * @retval VERR_PGM_POOL_FLUSHED if the pool was flushed.
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync * @param pPool The pool.
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync * @param iUser The user of the page.
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsyncstatic int pgmPoolMakeMoreFreePages(PPGMPOOL pPool, uint16_t iUser)
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync LogFlow(("pgmPoolMakeMoreFreePages: iUser=%#x\n", iUser));
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync * If the pool isn't full grown yet, expand it.
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync int rc = CTXALLMID(VMM, CallHost)(pPool->CTX_SUFF(pVM), VMMCALLHOST_PGM_POOL_GROW, 0);
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync * Free one cached page.
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync * Flush the pool.
3cac8f8c6923a3a89ecfccda5e89ad75f48658e0vboxsync * If we have tracking enabled, it should be possible to come up with
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * a cheap replacement strategy...
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* @todo incompatible with long mode paging (cr3 root will be flushed) */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Allocates a page from the pool.
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync * This page may actually be a cached page and not in need of any processing
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync * on the callers part.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VINF_SUCCESS if a NEW page was allocated.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VINF_PGM_CACHED_PAGE if a CACHED page was returned.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VERR_PGM_POOL_FLUSHED if the pool was flushed.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM The VM handle.
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync * @param GCPhys The GC physical address of the page we're gonna shadow.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * For 4MB and 2MB PD entries, it's the first address the
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync * shadow PT is covering.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param enmKind The kind of mapping.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param iUser The shadow page pool index of the user table.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param iUserTable The index into the user table (shadowed).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param ppPage Where to store the pointer to the page. NULL is stored here on failure.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncint pgmPoolAlloc(PVM pVM, RTGCPHYS GCPhys, PGMPOOLKIND enmKind, uint16_t iUser, uint32_t iUserTable, PPPGMPOOLPAGE ppPage)
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync LogFlow(("pgmPoolAlloc: GCPhys=%RGp enmKind=%s iUser=%#x iUserTable=%#x\n", GCPhys, pgmPoolPoolKindToStr(enmKind), iUser, iUserTable));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /** @todo CSAM/PGMPrefetchPage messes up here during CSAMR3CheckGates
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * (TRPMR3SyncIDT) because of FF priority. Try fix that?
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Assert(!(pVM->pgm.s.fSyncFlags & PGM_SYNC_CLEAR_PGM_POOL)); */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync int rc2 = pgmPoolCacheAlloc(pPool, GCPhys, enmKind, iUser, iUserTable, ppPage);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolAlloc: cached returns %Rrc *ppPage=%p:{.Key=%RHp, .idx=%d}\n", rc2, *ppPage, (*ppPage)->Core.Key, (*ppPage)->idx));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Allocate a new one.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log(("pgmPoolMakeMoreFreePages failed with %Rrc -> return VERR_PGM_POOL_FLUSHED\n", rc));
00599f6d39cc25ca39845c2433cd75de7b9f6971vboxsync AssertReleaseReturn(iNew != NIL_PGMPOOL_IDX, VERR_INTERNAL_ERROR);
10e1bc06b2908a0af56d92ffdbadd25b36a5ef61vboxsync /* unlink the free head */
9f1e0743f565b1975bb4efd7311b30cfa0d3e384vboxsync * Initialize it.
9f1e0743f565b1975bb4efd7311b30cfa0d3e384vboxsync pPool->cUsedPages++; /* physical handler registration / pgmPoolTrackFlushGCPhysPTsSlow requirement. */
9f1e0743f565b1975bb4efd7311b30cfa0d3e384vboxsync pPage->fSeenNonGlobal = false; /* Set this to 'true' to disable this feature. */
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync * Insert into the tracking and cache. If this fails, free the page.
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync int rc3 = pgmPoolTrackInsert(pPool, pPage, GCPhys, iUser, iUserTable);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log(("pgmPoolAlloc: returns %Rrc (Insert)\n", rc3));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log(("pgmPoolTrackInsert failed with %Rrc -> return VERR_PGM_POOL_FLUSHED\n", rc3));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync#endif /* PGMPOOL_WITH_USER_TRACKING */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Commit the allocation, clear the page and return.
b15ec73af09a8129b8a9ebfcc185ea11c3dd7c63vboxsync LogFlow(("pgmPoolAlloc: returns %Rrc *ppPage=%p:{.Key=%RHp, .idx=%d, .fCached=%RTbool, .fMonitored=%RTbool}\n",
41b8e304f190c3d901bcfee5e73c11bc2c42ce13vboxsync rc, pPage, pPage->Core.Key, pPage->idx, pPage->fCached, pPage->fMonitored));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Frees a usage of a pool page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM The VM handle.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param HCPhys The HC physical address of the shadow page.
750d4d0506a38b2e80c997075d40aad474e675fbvboxsync * @param iUser The shadow page pool index of the user table.
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync * @param iUserTable The index into the user table (shadowed).
1b7f3a92e42fb9cabf96cf31c20481da466edf76vboxsyncvoid pgmPoolFree(PVM pVM, RTHCPHYS HCPhys, uint16_t iUser, uint32_t iUserTable)
41b8e304f190c3d901bcfee5e73c11bc2c42ce13vboxsync LogFlow(("pgmPoolFree: HCPhys=%RHp iUser=%#x iUserTable=%#x\n", HCPhys, iUser, iUserTable));
1b7f3a92e42fb9cabf96cf31c20481da466edf76vboxsync pgmPoolFreeByPage(pPool, pgmPoolGetPage(pPool, HCPhys), iUser, iUserTable);
0aeb5f500280603a51364071670efeb2617f771cvboxsync * Gets a in-use page in the pool by it's physical address.
0aeb5f500280603a51364071670efeb2617f771cvboxsync * @returns Pointer to the page.
2d6f33c6a171136b87841159dee425ad4e237934vboxsync * @param pVM The VM handle.
6c849982f467f6a3b6c2e01f8f7109391715c29cvboxsync * @param HCPhys The HC physical address of the shadow page.
7e2fce486e7e2e45eb61d78ee206ba42ed89e016vboxsync * @remark This function will NEVER return NULL. It will assert if HCPhys is invalid.
7e2fce486e7e2e45eb61d78ee206ba42ed89e016vboxsyncPPGMPOOLPAGE pgmPoolGetPageByHCPhys(PVM pVM, RTHCPHYS HCPhys)
41b8e304f190c3d901bcfee5e73c11bc2c42ce13vboxsync /** @todo profile this! */
41b8e304f190c3d901bcfee5e73c11bc2c42ce13vboxsync PPGMPOOLPAGE pPage = pgmPoolGetPage(pPool, HCPhys);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log3(("pgmPoolGetPageByHCPhys: HCPhys=%RHp -> %p:{.idx=%d .GCPhys=%RGp .enmKind=%s}\n",
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync HCPhys, pPage, pPage->idx, pPage->GCPhys, pgmPoolPoolKindToStr(pPage->enmKind)));
50e0e1bb8996934b3f38c117a456f825052bfb0cvboxsync * Flushes the entire cache.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * It will assert a global CR3 flush (FF) and assumes the caller is aware of this
9e3d5133d0d1dfaf4721e714ffe066464d622ce7vboxsync * and execute this CR3 flush.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
b15ec73af09a8129b8a9ebfcc185ea11c3dd7c63vboxsyncstatic const char *pgmPoolPoolKindToStr(uint8_t enmKind)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return "PGMPOOLKIND_INVALID";
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return "PGMPOOLKIND_FREE";
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return "PGMPOOLKIND_32BIT_PT_FOR_PHYS";
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return "PGMPOOLKIND_32BIT_PT_FOR_32BIT_PT";
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return "PGMPOOLKIND_32BIT_PT_FOR_32BIT_4MB";
fbf5c218f8bc15f0d765fef4b81e745f4db71b7avboxsync return "PGMPOOLKIND_PAE_PT_FOR_PHYS";
9984bae4ef25be8afd95d184308adcfef6e2ec0dvboxsync return "PGMPOOLKIND_PAE_PT_FOR_32BIT_PT";
50e0e1bb8996934b3f38c117a456f825052bfb0cvboxsync return "PGMPOOLKIND_PAE_PT_FOR_32BIT_4MB";
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return "PGMPOOLKIND_PAE_PT_FOR_PAE_PT";
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return "PGMPOOLKIND_PAE_PT_FOR_PAE_2MB";
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return "PGMPOOLKIND_32BIT_PD";
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return "PGMPOOLKIND_32BIT_PD_PHYS";
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return "PGMPOOLKIND_PAE_PD0_FOR_32BIT_PD";
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return "PGMPOOLKIND_PAE_PD1_FOR_32BIT_PD";
74991d7531692858fd22acf371a7ee941567977cvboxsync return "PGMPOOLKIND_PAE_PD2_FOR_32BIT_PD";
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return "PGMPOOLKIND_PAE_PD3_FOR_32BIT_PD";
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return "PGMPOOLKIND_PAE_PD_FOR_PAE_PD";
b15ec73af09a8129b8a9ebfcc185ea11c3dd7c63vboxsync return "PGMPOOLKIND_PAE_PD_PHYS";
b15ec73af09a8129b8a9ebfcc185ea11c3dd7c63vboxsync return "PGMPOOLKIND_PAE_PDPT_FOR_32BIT";
e5ce4bb707bf5c17c2bfa42306210e915ca29fa2vboxsync return "PGMPOOLKIND_PAE_PDPT";
b15ec73af09a8129b8a9ebfcc185ea11c3dd7c63vboxsync return "PGMPOOLKIND_PAE_PDPT_PHYS";
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return "PGMPOOLKIND_64BIT_PDPT_FOR_64BIT_PDPT";
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return "PGMPOOLKIND_64BIT_PDPT_FOR_PHYS";
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return "PGMPOOLKIND_64BIT_PD_FOR_64BIT_PD";
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return "PGMPOOLKIND_64BIT_PD_FOR_PHYS";
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return "PGMPOOLKIND_64BIT_PML4";
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return "PGMPOOLKIND_EPT_PDPT_FOR_PHYS";
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return "PGMPOOLKIND_EPT_PD_FOR_PHYS";
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return "PGMPOOLKIND_EPT_PT_FOR_PHYS";
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return "PGMPOOLKIND_ROOT_32BIT_PD";
41b8e304f190c3d901bcfee5e73c11bc2c42ce13vboxsync return "PGMPOOLKIND_ROOT_PAE_PD";
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync return "PGMPOOLKIND_ROOT_PDPT";
41b8e304f190c3d901bcfee5e73c11bc2c42ce13vboxsync return "PGMPOOLKIND_ROOT_NESTED";
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return "Unknown kind!";