PGMAllPool.cpp revision 2b88b28162a49c6fa769c03d56767a9806d4f456
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * PGM Shadow Page Pool.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * available from http://www.virtualbox.org. This file is free software;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * you can redistribute it and/or modify it under the terms of the GNU
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * General Public License (GPL) as published by the Free Software
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * additional information or have any questions.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/*******************************************************************************
7b9f0c34e9ea328981c99e97054bdf8684d9d620vboxsync* Header Files *
9e7e0b61d29309a0ed7af9472c8d6d865f9e8a2dvboxsync*******************************************************************************/
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync/*******************************************************************************
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync* Internal Functions *
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync*******************************************************************************/
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsyncDECLINLINE(unsigned) pgmPoolTrackGetShadowEntrySize(PGMPOOLKIND enmKind);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsyncDECLINLINE(unsigned) pgmPoolTrackGetGuestEntrySize(PGMPOOLKIND enmKind);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsyncstatic void pgmPoolTrackDeref(PPGMPOOL pPool, PPGMPOOLPAGE pPage);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsyncstatic void pgmPoolTracDerefGCPhysHint(PPGMPOOL pPool, PPGMPOOLPAGE pPage, RTHCPHYS HCPhys, RTGCPHYS GCPhysHint);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsyncstatic int pgmPoolTrackAddUser(PPGMPOOL pPool, PPGMPOOLPAGE pPage, uint16_t iUser, uint32_t iUserTable);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsyncstatic void pgmPoolMonitorModifiedRemove(PPGMPOOL pPool, PPGMPOOLPAGE pPage);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsyncDECLEXPORT(int) pgmPoolAccessHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPHYS GCPhysFault, void *pvUser);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * Checks if the specified page pool kind is for a 4MB or 2MB guest page.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * @returns true if it's the shadow of a 4MB or 2MB guest page, otherwise false.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * @param enmKind The page kind.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsyncDECLINLINE(bool) pgmPoolIsBigPage(PGMPOOLKIND enmKind)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync return true;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync return false;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync#if defined(IN_RC) || defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0)
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync * Maps a pool page into the current context.
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync * @returns Pointer to the mapping.
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync * @param pPGM Pointer to the PGM instance data.
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync * @param pPage The page to map.
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsyncvoid *pgmPoolMapPageFallback(PPGM pPGM, PPGMPOOLPAGE pPage)
e38a1f5933935fe8db152ea06dac5aa1be27d870vboxsync /* general pages are take care of by the inlined part, it
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync only ends up here in case of failure. */
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync AssertReleaseReturn(pPage->idx < PGMPOOL_IDX_FIRST, NULL);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync/** @todo make sure HCPhys is valid for *all* indexes. */
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync /* special pages. */
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync AssertReleaseMsgFailed(("Invalid index %d\n", pPage->idx));
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync# else /* VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0 */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync AssertReleaseMsgFailed(("PGMPOOL_IDX_PAE_PD is not usable in VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0 context\n"));
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync AssertReleaseMsgFailed(("Invalid index %d\n", pPage->idx));
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync AssertMsg(HCPhys && HCPhys != NIL_RTHCPHYS && !(PAGE_OFFSET_MASK & HCPhys), ("%RHp\n", HCPhys));
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync# endif /* VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0 */
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync#endif /* IN_RC || VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0 */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * Determin the size of a write instruction.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * @returns number of bytes written.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * @param pDis The disassembler state.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsyncstatic unsigned pgmPoolDisasWriteSize(PDISCPUSTATE pDis)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * This is very crude and possibly wrong for some opcodes,
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * but since it's not really supposed to be called we can
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * probably live with that.
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync * Flushes a chain of pages sharing the same access monitor.
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * @returns VBox status code suitable for scheduling.
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * @param pPool The pool.
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync * @param pPage A page in the chain.
cd5df721f068659172f3bf95de8fedeb465f057dvboxsyncint pgmPoolMonitorChainFlush(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync LogFlow(("pgmPoolMonitorChainFlush: Flush page %RGp type=%d\n", pPage->GCPhys, pPage->enmKind));
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync * Find the list head.
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync * Iterate the list flushing each shadow page.
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync if (rc2 == VERR_PGM_POOL_CLEARED && rc == VINF_SUCCESS)
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync * Wrapper for getting the current context pointer to the entry being modified.
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync * @returns Pointer to the current context mapping of the entry.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * @param pPool The pool.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * @param pvFault The fault virtual address.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * @param GCPhysFault The fault physical address.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * @param cbEntry The entry size.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsyncDECLINLINE(const void *) pgmPoolMonitorGCPtr2CCPtr(PPGMPOOL pPool, RTHCPTR pvFault, RTGCPHYS GCPhysFault, const unsigned cbEntry)
cd5df721f068659172f3bf95de8fedeb465f057dvboxsyncDECLINLINE(const void *) pgmPoolMonitorGCPtr2CCPtr(PPGMPOOL pPool, RTGCPTR pvFault, RTGCPHYS GCPhysFault, const unsigned cbEntry)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync return (const void *)((RTGCUINTPTR)pvFault & ~(RTGCUINTPTR)(cbEntry - 1));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync int rc = PGMDynMapGCPageOff(pPool->pVMR0, GCPhysFault & ~(RTGCPHYS)(cbEntry - 1), &pvRet);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync int rc = pgmRamGCPhys2HCPtr(&pPool->pVMR0->pgm.s, GCPhysFault & ~(RTGCPHYS)(cbEntry - 1), &pvRet);
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync return (RTHCPTR)((uintptr_t)pvFault & ~(RTHCUINTPTR)(cbEntry - 1));
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync * Process shadow entries before they are changed by the guest.
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync * For PT entries we will clear them. For PD entries, we'll simply check
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync * for mapping conflicts and set the SyncCR3 FF if found.
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync * @param pPool The pool.
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync * @param pPage The head page.
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync * @param GCPhysFault The guest physical fault address.
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync * @param uAddress In R0 and GC this is the guest context fault address (flat).
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync * In R3 this is the host context 'fault' address.
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync * @param pCpu The disassembler state for figuring out the write size.
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync * This need not be specified if the caller knows we won't do cross entry accesses.
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsyncvoid pgmPoolMonitorChainChanging(PPGMPOOL pPool, PPGMPOOLPAGE pPage, RTGCPHYS GCPhysFault, RTHCPTR pvAddress, PDISCPUSTATE pCpu)
f044158ee9eb7045a43f2c4ef2fbc07cb11329aevboxsyncvoid pgmPoolMonitorChainChanging(PPGMPOOL pPool, PPGMPOOLPAGE pPage, RTGCPHYS GCPhysFault, RTGCPTR pvAddress, PDISCPUSTATE pCpu)
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync const unsigned off = GCPhysFault & PAGE_OFFSET_MASK;
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync const unsigned cbWrite = (pCpu) ? pgmPoolDisasWriteSize(pCpu) : 0;
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync LogFlow(("pgmPoolMonitorChainChanging: %RGv phys=%RGp kind=%d cbWrite=%d\n", pvAddress, GCPhysFault, pPage->enmKind, cbWrite));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync uShw.pv = PGMPOOL_PAGE_2_PTR(pPool->CTX_SUFF(pVM), pPage);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync PCX86PTE pGstPte = (PCX86PTE)pgmPoolMonitorGCPtr2CCPtr(pPool, pvAddress, GCPhysFault, sizeof(*pGstPte));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync 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));
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync /* page/2 sized */
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync uShw.pv = PGMPOOL_PAGE_2_PTR(pPool->CTX_SUFF(pVM), pPage);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync const unsigned iShw = (off / sizeof(X86PTE)) & (X86_PG_PAE_ENTRIES - 1);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync PCX86PTE pGstPte = (PCX86PTE)pgmPoolMonitorGCPtr2CCPtr(pPool, pvAddress, GCPhysFault, sizeof(*pGstPte));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync 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));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync uShw.pv = PGMPOOL_PAGE_2_PTR(pPool->CTX_SUFF(pVM), pPage);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync PCX86PTEPAE pGstPte = (PCX86PTEPAE)pgmPoolMonitorGCPtr2CCPtr(pPool, pvAddress, GCPhysFault, sizeof(*pGstPte));
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsync 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));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* paranoia / a bit assumptive. */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync const unsigned iShw2 = (off + cbWrite - 1) / sizeof(X86PTEPAE);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync AssertReturnVoid(iShw2 < RT_ELEMENTS(uShw.pPTPae->a));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync PCX86PTEPAE pGstPte = (PCX86PTEPAE)pgmPoolMonitorGCPtr2CCPtr(pPool, pvAddress, GCPhysFault, sizeof(*pGstPte));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync 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));
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync uShw.pv = PGMPOOL_PAGE_2_PTR(pPool->CTX_SUFF(pVM), pPage);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync const unsigned iShw = off / sizeof(X86PTE); // ASSUMING 32-bit guest paging!
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTX_SUFF(pVM)->pgm.s));
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync VM_FF_SET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync STAM_COUNTER_INC(&(pPool->CTX_SUFF(pVM)->pgm.s.StatRZGuestCR3WriteConflict));
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw=%#x!\n", iShw));
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync /* paranoia / a bit assumptive. */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync const unsigned iShw2 = (off + cbWrite - 1) / sizeof(X86PTE);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTX_SUFF(pVM)->pgm.s));
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync STAM_COUNTER_INC(&(pPool->CTX_SUFF(pVM)->pgm.s.StatRZGuestCR3WriteConflict));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync VM_FF_SET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw2=%#x!\n", iShw2));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#if 0 /* useful when running PGMAssertCR3(), a bit too troublesome for general use (TLBs). */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync && !VM_FF_ISSET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3))
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync LogFlow(("pgmPoolMonitorChainChanging: iShw=%#x: %RX32 -> freeing it!\n", iShw, uShw.pPD->a[iShw].u));
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync# ifdef IN_RC /* TLB load - we're pushing things a bit... */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pgmPoolFree(pPool->CTX_SUFF(pVM), uShw.pPD->a[iShw].u & X86_PDE_PG_MASK, pPage->idx, iShw);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync unsigned iGst = off / sizeof(X86PDE); // ASSUMING 32-bit guest paging!
7e8ef90d3160234df0f254131b87af4243d79476vboxsync Assert(pPage2->idx == PGMPOOL_IDX_PAE_PD_0 + iShwPdpt);
7e8ef90d3160234df0f254131b87af4243d79476vboxsync uShw.pv = PGMPOOL_PAGE_2_PTR(pPool->CTX_SUFF(pVM), pPage2);
7e8ef90d3160234df0f254131b87af4243d79476vboxsync if ((uShw.pPDPae->a[iShw].u & (PGM_PDFLAGS_MAPPING | X86_PDE_P)) == (PGM_PDFLAGS_MAPPING | X86_PDE_P))
7e8ef90d3160234df0f254131b87af4243d79476vboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTX_SUFF(pVM)->pgm.s));
7e8ef90d3160234df0f254131b87af4243d79476vboxsync VM_FF_SET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3);
7e8ef90d3160234df0f254131b87af4243d79476vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShwPdpt=%#x iShw=%#x!\n", iShwPdpt, iShw));
7e8ef90d3160234df0f254131b87af4243d79476vboxsync /* paranoia / a bit assumptive. */
7e8ef90d3160234df0f254131b87af4243d79476vboxsync if ( iShw2 < RT_ELEMENTS(uShw.pPDPae->a) /** @todo was completely wrong, it's better now after #1865 but still wrong from cross PD. */
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync && (uShw.pPDPae->a[iShw2].u & (PGM_PDFLAGS_MAPPING | X86_PDE_P)) == (PGM_PDFLAGS_MAPPING | X86_PDE_P))
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTX_SUFF(pVM)->pgm.s));
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync VM_FF_SET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3);
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShwPdpt=%#x iShw2=%#x!\n", iShwPdpt, iShw2));
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync#if 0 /* useful when running PGMAssertCR3(), a bit too troublesome for general use (TLBs). */
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync && !VM_FF_ISSET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3))
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync LogFlow(("pgmPoolMonitorChainChanging: iShwPdpt=%#x iShw=%#x: %RX64 -> freeing it!\n", iShwPdpt, iShw, uShw.pPDPae->a[iShw].u));
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync# ifdef IN_RC /* TLB load - we're pushing things a bit... */
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync pgmPoolFree(pPool->CTX_SUFF(pVM), uShw.pPDPae->a[iShw].u & X86_PDE_PAE_PG_MASK, pPage->idx, iShw + iShwPdpt * X86_PG_PAE_ENTRIES);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync# endif /* !VBOX_WITH_PGMPOOL_PAGING_ONLY */
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync uShw.pv = PGMPOOL_PAGE_2_PTR(pPool->CTX_SUFF(pVM), pPage);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTX_SUFF(pVM)->pgm.s));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync VM_FF_SET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync STAM_COUNTER_INC(&(pPool->CTX_SUFF(pVM)->pgm.s.StatRZGuestCR3WriteConflict));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw=%#x!\n", iShw));
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync#ifdef PGMPOOL_INVALIDATE_UPPER_SHADOW_TABLE_ENTRIES
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * Causes trouble when the guest uses a PDE to refer to the whole page table level
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync * structure. (Invalidate here; faults later on when it tries to change the page
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * table entries -> recheck; probably only applies to the RC case.)
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlow(("pgmPoolMonitorChainChanging: pae pd iShw=%#x: %RX64 -> freeing it!\n", iShw, uShw.pPDPae->a[iShw].u));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* Note: hardcoded PAE implementation dependency */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync (pPage->enmKind == PGMPOOLKIND_PAE_PD_FOR_PAE_PD) ? PGMPOOL_IDX_PAE_PD : pPage->idx,
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync (pPage->enmKind == PGMPOOLKIND_PAE_PD_FOR_PAE_PD) ? iShw + (pPage->idx - PGMPOOL_IDX_PAE_PD_0) * X86_PG_PAE_ENTRIES : iShw);
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync /* paranoia / a bit assumptive. */
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync const unsigned iShw2 = (off + cbWrite - 1) / sizeof(X86PDEPAE);
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync AssertReturnVoid(iShw2 < RT_ELEMENTS(uShw.pPDPae->a));
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTX_SUFF(pVM)->pgm.s));
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync VM_FF_SET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3);
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync STAM_COUNTER_INC(&(pPool->CTX_SUFF(pVM)->pgm.s.StatRZGuestCR3WriteConflict));
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw2=%#x!\n", iShw2));
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync#ifdef PGMPOOL_INVALIDATE_UPPER_SHADOW_TABLE_ENTRIES
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync LogFlow(("pgmPoolMonitorChainChanging: pae pd iShw2=%#x: %RX64 -> freeing it!\n", iShw2, uShw.pPDPae->a[iShw2].u));
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync /* Note: hardcoded PAE implementation dependency */
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync (pPage->enmKind == PGMPOOLKIND_PAE_PD_FOR_PAE_PD) ? PGMPOOL_IDX_PAE_PD : pPage->idx,
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync (pPage->enmKind == PGMPOOLKIND_PAE_PD_FOR_PAE_PD) ? iShw2 + (pPage->idx - PGMPOOL_IDX_PAE_PD_0) * X86_PG_PAE_ENTRIES : iShw2);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Hopefully this doesn't happen very often:
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * - touching unused parts of the page
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * - messing with the bits of pd pointers without changing the physical address
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync uShw.pv = PGMPOOL_PAGE_2_PTR(pPool->CTX_SUFF(pVM), pPage);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (iShw < X86_PG_PAE_PDPE_ENTRIES) /* don't use RT_ELEMENTS(uShw.pPDPT->a), because that's for long mode only */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTX_SUFF(pVM)->pgm.s));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync STAM_COUNTER_INC(&(pPool->CTX_SUFF(pVM)->pgm.s.StatRZGuestCR3WriteConflict));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync VM_FF_SET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3);
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw=%#x!\n", iShw));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* paranoia / a bit assumptive. */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync const unsigned iShw2 = (off + cbWrite - 1) / sizeof(X86PDPE);
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTX_SUFF(pVM)->pgm.s));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync STAM_COUNTER_INC(&(pPool->CTX_SUFF(pVM)->pgm.s.StatRZGuestCR3WriteConflict));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync VM_FF_SET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw2=%#x!\n", iShw2));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Assert(pPage->enmKind == PGMPOOLKIND_64BIT_PD_FOR_64BIT_PD);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync uShw.pv = PGMPOOL_PAGE_2_PTR(pPool->CTX_SUFF(pVM), pPage);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTX_SUFF(pVM)->pgm.s));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync VM_FF_SET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw=%#x!\n", iShw));
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync LogFlow(("pgmPoolMonitorChainChanging: pae pd iShw=%#x: %RX64 -> freeing it!\n", iShw, uShw.pPDPae->a[iShw].u));
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync /* paranoia / a bit assumptive. */
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync const unsigned iShw2 = (off + cbWrite - 1) / sizeof(X86PDEPAE);
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync AssertReturnVoid(iShw2 < RT_ELEMENTS(uShw.pPDPae->a));
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTX_SUFF(pVM)->pgm.s));
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync VM_FF_SET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw2=%#x!\n", iShw2));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync LogFlow(("pgmPoolMonitorChainChanging: pae pd iShw2=%#x: %RX64 -> freeing it!\n", iShw2, uShw.pPDPae->a[iShw2].u));
c193ae401647c574d0ef52af57c32cf5d7c44966vboxsync * Hopefully this doesn't happen very often:
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync * - messing with the bits of pd pointers without changing the physical address
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync if (!VM_FF_ISSET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3))
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync uShw.pv = PGMPOOL_PAGE_2_PTR(pPool->CTX_SUFF(pVM), pPage);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync LogFlow(("pgmPoolMonitorChainChanging: pdpt iShw=%#x: %RX64 -> freeing it!\n", iShw, uShw.pPDPT->a[iShw].u));
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync pgmPoolFree(pPool->CTX_SUFF(pVM), uShw.pPDPT->a[iShw].u & X86_PDPE_PG_MASK, pPage->idx, iShw);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /* paranoia / a bit assumptive. */
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync const unsigned iShw2 = (off + cbWrite - 1) / sizeof(X86PDPE);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync LogFlow(("pgmPoolMonitorChainChanging: pdpt iShw2=%#x: %RX64 -> freeing it!\n", iShw2, uShw.pPDPT->a[iShw2].u));
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync pgmPoolFree(pPool->CTX_SUFF(pVM), uShw.pPDPT->a[iShw2].u & X86_PDPE_PG_MASK, pPage->idx, iShw2);
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync * Hopefully this doesn't happen very often:
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync * - messing with the bits of pd pointers without changing the physical address
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync if (!VM_FF_ISSET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3))
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync uShw.pv = PGMPOOL_PAGE_2_PTR(pPool->CTX_SUFF(pVM), pPage);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync LogFlow(("pgmPoolMonitorChainChanging: pml4 iShw=%#x: %RX64 -> freeing it!\n", iShw, uShw.pPML4->a[iShw].u));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync pgmPoolFree(pPool->CTX_SUFF(pVM), uShw.pPML4->a[iShw].u & X86_PML4E_PG_MASK, pPage->idx, iShw);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* paranoia / a bit assumptive. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync const unsigned iShw2 = (off + cbWrite - 1) / sizeof(X86PML4E);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync LogFlow(("pgmPoolMonitorChainChanging: pml4 iShw2=%#x: %RX64 -> freeing it!\n", iShw2, uShw.pPML4->a[iShw2].u));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync pgmPoolFree(pPool->CTX_SUFF(pVM), uShw.pPML4->a[iShw2].u & X86_PML4E_PG_MASK, pPage->idx, iShw2);
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync#endif /* IN_RING0 */
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync AssertFatalMsgFailed(("enmKind=%d\n", pPage->enmKind));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * Checks if a access could be a fork operation in progress.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * Meaning, that the guest is setuping up the parent process for Copy-On-Write.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * @returns true if it's likly that we're forking, otherwise false.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * @param pPool The pool.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * @param pCpu The disassembled instruction.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * @param offFault The access offset.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsyncDECLINLINE(bool) pgmPoolMonitorIsForking(PPGMPOOL pPool, PDISCPUSTATE pCpu, unsigned offFault)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * i386 linux is using btr to clear X86_PTE_RW.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * The functions involved are (2.6.16 source inspection):
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * clear_bit
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * ptep_set_wrprotect
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * copy_one_pte
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * copy_pte_range
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * copy_pmd_range
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * copy_pud_range
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * copy_page_range
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * copy_process
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /** @todo Validate that the bit index is X86_PTE_RW. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,Fork));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return true;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return false;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * Determine whether the page is likely to have been reused.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * @returns true if we consider the page as being reused for a different purpose.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * @returns false if we consider it to still be a paging page.
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync * @param pVM VM Handle.
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync * @param pPage The page in question.
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync * @param pRegFrame Trap register frame.
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync * @param pCpu The disassembly info for the faulting instruction.
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync * @param pvFault The fault address.
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync * @remark The REP prefix check is left to the caller because of STOSD/W.
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsyncDECLINLINE(bool) pgmPoolMonitorIsReused(PVM pVM, PPGMPOOLPAGE pPage, PCPUMCTXCORE pRegFrame, PDISCPUSTATE pCpu, RTGCPTR pvFault)
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync /** @todo could make this general, faulting close to rsp should be safe reuse heuristic. */
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync /* Fault caused by stack writes while trying to inject an interrupt event. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync Log(("pgmPoolMonitorIsReused: reused %RGv for interrupt stack (rsp=%RGv).\n", pvFault, pRegFrame->rsp));
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync return true;
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync /* call implies the actual push of the return address faulted */
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync return true;
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync return true;
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync return true;
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync return true;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return true;
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync return true;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync case OP_MOVNTDQ: /* solaris - hwblkclr & hwblkpagecopy */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return true;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return true;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return false;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return true;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync //if (pPage->fCR3Mix)
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync // return false;
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync return false;
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync * Flushes the page being accessed.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * @returns VBox status code suitable for scheduling.
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync * @param pVM The VM handle.
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync * @param pPool The pool.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * @param pPage The pool page (head).
81dfa298981df637a707b142ebd03cb7d3385097vboxsync * @param pCpu The disassembly of the write instruction.
ca3db470494a8b6eaec69ea37468a5cda65e2da8vboxsync * @param pRegFrame The trap register frame.
81dfa298981df637a707b142ebd03cb7d3385097vboxsync * @param GCPhysFault The fault address as guest physical address.
81dfa298981df637a707b142ebd03cb7d3385097vboxsync * @param pvFault The fault address.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsyncstatic int pgmPoolAccessHandlerFlush(PVM pVM, PPGMPOOL pPool, PPGMPOOLPAGE pPage, PDISCPUSTATE pCpu,
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, RTGCPTR pvFault)
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * First, do the flushing.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * Emulate the instruction (xp/w2k problem, requires pc/cr2/sp detection).
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync int rc2 = EMInterpretInstructionCPU(pVM, pCpu, pRegFrame, pvFault, &cbWritten);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (PATMIsPatchGCAddr(pVM, (RTRCPTR)pRegFrame->eip))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync LogFlow(("pgmPoolAccessHandlerPTWorker: Interpretation failed for patch code %04x:%RGv, ignoring.\n",
81dfa298981df637a707b142ebd03cb7d3385097vboxsync STAM_COUNTER_INC(&pPool->StatMonitorRZIntrFailPatch2);
dea3e7faa80f4aab41e08945b9308fd2e3ffe7fcvboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,EmulateInstr));
81dfa298981df637a707b142ebd03cb7d3385097vboxsync /* See use in pgmPoolAccessHandlerSimple(). */
81dfa298981df637a707b142ebd03cb7d3385097vboxsync LogFlow(("pgmPoolAccessHandlerPT: returns %Rrc (flushed)\n", rc));
81dfa298981df637a707b142ebd03cb7d3385097vboxsync * Handles the STOSD write accesses.
81dfa298981df637a707b142ebd03cb7d3385097vboxsync * @returns VBox status code suitable for scheduling.
81dfa298981df637a707b142ebd03cb7d3385097vboxsync * @param pVM The VM handle.
81dfa298981df637a707b142ebd03cb7d3385097vboxsync * @param pPool The pool.
81dfa298981df637a707b142ebd03cb7d3385097vboxsync * @param pPage The pool page (head).
81dfa298981df637a707b142ebd03cb7d3385097vboxsync * @param pCpu The disassembly of the write instruction.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * @param pRegFrame The trap register frame.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * @param GCPhysFault The fault address as guest physical address.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * @param pvFault The fault address.
ca3db470494a8b6eaec69ea37468a5cda65e2da8vboxsyncDECLINLINE(int) pgmPoolAccessHandlerSTOSD(PVM pVM, PPGMPOOL pPool, PPGMPOOLPAGE pPage, PDISCPUSTATE pCpu,
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, RTGCPTR pvFault)
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync * Increment the modification counter and insert it into the list
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync * of modified pages the first time.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * Execute REP STOSD.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * This ASSUMES that we're not invoked by Trap0e on in a out-of-sync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * write situation, meaning that it's safe to write here.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync uint32_t iPrevSubset = PGMDynMapPushAutoSubset(pVCpu);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync pgmPoolMonitorChainChanging(pPool, pPage, GCPhysFault, (RTGCPTR)pu32, NULL);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync pgmPoolMonitorChainChanging(pPool, pPage, GCPhysFault, (RTGCPTR)pu32, NULL);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync PGMPhysSimpleWriteGCPhys(pVM, GCPhysFault, &pRegFrame->eax, 4);
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync /* See use in pgmPoolAccessHandlerSimple(). */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * Handles the simple write accesses.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * @returns VBox status code suitable for scheduling.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * @param pVM The VM handle.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * @param pPool The pool.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * @param pPage The pool page (head).
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * @param pCpu The disassembly of the write instruction.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * @param pRegFrame The trap register frame.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * @param GCPhysFault The fault address as guest physical address.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * @param pvFault The fault address.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsyncDECLINLINE(int) pgmPoolAccessHandlerSimple(PVM pVM, PPGMPOOL pPool, PPGMPOOLPAGE pPage, PDISCPUSTATE pCpu,
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, RTGCPTR pvFault)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * Increment the modification counter and insert it into the list
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * of modified pages the first time.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * Clear all the pages. ASSUMES that pvFault is readable.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync uint32_t iPrevSubset = PGMDynMapPushAutoSubset(pVCpu);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync pgmPoolMonitorChainChanging(pPool, pPage, GCPhysFault, pvFault, pCpu);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync pgmPoolMonitorChainChanging(pPool, pPage, GCPhysFault, pvFault, pCpu);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * Interpret the instruction.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync int rc = EMInterpretInstructionCPU(pVM, pCpu, pRegFrame, pvFault, &cb);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync LogFlow(("pgmPoolAccessHandlerPTWorker: Interpretation failed for %04x:%RGv - opcode=%d\n",
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync pRegFrame->cs, (RTGCPTR)pRegFrame->rip, pCpu->pCurInstr->opcode));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,EmulateInstr));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * Quick hack, with logging enabled we're getting stale
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * code TLBs but no data TLB for EIP and crash in EMInterpretDisasOne.
56484ba959c372f0196716100568e02412b0dbd5vboxsync * Flushing here is BAD and expensive, I think EMInterpretDisasOne will
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * have to be fixed to support this. But that'll have to wait till next week.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * An alternative is to keep track of the changed PTEs together with the
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * GCPhys from the guest PT. This may proove expensive though.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * At the moment, it's VITAL that it's done AFTER the instruction interpreting
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * because we need the stale TLBs in some cases (XP boot). This MUST be fixed properly!
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync LogFlow(("pgmPoolAccessHandlerSimple: returns %Rrc cb=%d\n", rc, cb));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * \#PF Handler callback for PT write accesses.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * @returns VBox status code (appropriate for GC return).
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * @param pVM VM Handle.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * @param uErrorCode CPU Error code.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * @param pRegFrame Trap register frame.
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync * NULL on DMA and other non CPU access.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * @param pvFault The fault address (cr2).
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * @param GCPhysFault The GC physical address corresponding to pvFault.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * @param pvUser User argument.
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsyncDECLEXPORT(int) pgmPoolAccessHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPHYS GCPhysFault, void *pvUser)
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync STAM_PROFILE_START(&pVM->pgm.s.CTX_SUFF(pPool)->CTX_SUFF_Z(StatMonitor), a);
56484ba959c372f0196716100568e02412b0dbd5vboxsync LogFlow(("pgmPoolAccessHandler: pvFault=%RGv pPage=%p:{.idx=%d} GCPhysFault=%RGp\n", pvFault, pPage, pPage->idx, GCPhysFault));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * We should ALWAYS have the list head as user parameter. This
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * is because we use that page to record the changes.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * Disassemble the faulting instruction.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync int rc = EMInterpretDisasOne(pVM, pRegFrame, &Cpu, NULL);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * Check if it's worth dealing with.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync bool fReused = false;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync if ( ( pPage->cModifications < 48 /** @todo #define */ /** @todo need to check that it's not mapping EIP. */ /** @todo adjust this! */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync && !(fReused = pgmPoolMonitorIsReused(pVM, pPage, pRegFrame, &Cpu, pvFault))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync && !pgmPoolMonitorIsForking(pPool, &Cpu, GCPhysFault & PAGE_OFFSET_MASK))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * Simple instructions, no REP prefix.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync rc = pgmPoolAccessHandlerSimple(pVM, pPool, pPage, &Cpu, pRegFrame, GCPhysFault, pvFault);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync STAM_PROFILE_STOP_EX(&pVM->pgm.s.CTX_SUFF(pPool)->CTX_SUFF_Z(StatMonitor), &pPool->CTX_MID_Z(StatMonitor,Handled), a);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * Windows is frequently doing small memset() operations (netio test 4k+).
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * We have to deal with these or we'll kill the cache and performance.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync && pRegFrame->ecx * 4 <= PAGE_SIZE - ((uintptr_t)pvFault & PAGE_OFFSET_MASK)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync && (pRegFrame->eax == 0 || pRegFrame->eax == 0x80) /* the two values observed. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync rc = pgmPoolAccessHandlerSTOSD(pVM, pPool, pPage, &Cpu, pRegFrame, GCPhysFault, pvFault);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync STAM_PROFILE_STOP_EX(&pVM->pgm.s.CTX_SUFF(pPool)->CTX_SUFF_Z(StatMonitor), &pPool->CTX_MID_Z(StatMonitor,RepStosd), a);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* REP prefix, don't bother. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,RepPrefix));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync Log4(("pgmPoolAccessHandler: eax=%#x ecx=%#x edi=%#x esi=%#x rip=%RGv opcode=%d prefix=%#x\n",
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync pRegFrame->eax, pRegFrame->ecx, pRegFrame->edi, pRegFrame->esi, (RTGCPTR)pRegFrame->rip, Cpu.pCurInstr->opcode, Cpu.prefix));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * Not worth it, so flush it.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * If we considered it to be reused, don't to back to ring-3
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * to emulate failed instructions since we usually cannot
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * interpret then. This may be a bit risky, in which case
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * the reuse detection must be fixed.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync rc = pgmPoolAccessHandlerFlush(pVM, pPool, pPage, &Cpu, pRegFrame, GCPhysFault, pvFault);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync STAM_PROFILE_STOP_EX(&pVM->pgm.s.CTX_SUFF(pPool)->CTX_SUFF_Z(StatMonitor), &pPool->CTX_MID_Z(StatMonitor,FlushPage), a);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync# endif /* !IN_RING3 */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync#endif /* PGMPOOL_WITH_MONITORING */
cc1ef2ef9bbc6a0ff964928d61b7298e5bfcce5fvboxsync * Inserts a page into the GCPhys hash table.
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync * @param pPool The pool.
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync * @param pPage The page.
687794577e2e35c3cae67e692a7f2130d1262a82vboxsyncDECLINLINE(void) pgmPoolHashInsert(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
4fc4c719ffba45eb4136c34ad713ef9b21f69e3bvboxsync Log3(("pgmPoolHashInsert: %RGp\n", pPage->GCPhys));
4fc4c719ffba45eb4136c34ad713ef9b21f69e3bvboxsync Assert(pPage->GCPhys != NIL_RTGCPHYS); Assert(pPage->iNext == NIL_PGMPOOL_IDX);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * Removes a page from the GCPhys hash table.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * @param pPool The pool.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * @param pPage The page.
f044158ee9eb7045a43f2c4ef2fbc07cb11329aevboxsyncDECLINLINE(void) pgmPoolHashRemove(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync Log3(("pgmPoolHashRemove: %RGp\n", pPage->GCPhys));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync AssertReleaseMsgFailed(("GCPhys=%RGp idx=%#x\n", pPage->GCPhys, pPage->idx));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * Frees up one cache page.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * @returns VBox status code.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * @retval VINF_SUCCESS on success.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * @retval VERR_PGM_POOL_CLEARED if the deregistration of a physical handler will cause a light weight pool flush.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * @param pPool The pool.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * @param iUser The user index.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsyncstatic int pgmPoolCacheFreeOne(PPGMPOOL pPool, uint16_t iUser)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync Assert(pPool->iAgeHead != pPool->iAgeTail); /* We shouldn't be here if there < 2 cached entries! */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * Select one page from the tail of the age list.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync/* This is the alternative to the SyncCR3 pgmPoolCacheUsed calls.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync if (pPool->aPages[iToFree].iUserHead != NIL_PGMPOOL_USER_INDEX)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync uint16_t i = pPool->aPages[iToFree].iAgePrev;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync for (unsigned j = 0; j < 10 && i != NIL_PGMPOOL_USER_INDEX; j++, i = pPool->aPages[i].iAgePrev)
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync if (pPool->aPages[iToFree].iUserHead == NIL_PGMPOOL_USER_INDEX)
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync iToFree = i;
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync * Reject any attempts at flushing the currently active shadow CR3 mapping
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync if (PGMGetHyperCR3(pPool->CTX_SUFF(pVM)) == pPage->Core.Key)
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync /* Refresh the cr3 mapping by putting it at the head of the age list. */
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync * Checks if a kind mismatch is really a page being reused
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync * or if it's just normal remappings.
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync * @returns true if reused and the cached page (enmKind1) should be flushed
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync * @returns false if not reused.
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync * @param enmKind1 The kind of the cached page.
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync * @param enmKind2 The kind of the requested page.
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsyncstatic bool pgmPoolCacheReusedByKind(PGMPOOLKIND enmKind1, PGMPOOLKIND enmKind2)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * Never reuse them. There is no remapping in non-paging mode.
004d74842597dacc4009803171296dfcf9398c69vboxsync return false;
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync return true;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * It's perfectly fine to reuse these, except for PAE and non-paging stuff.
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync return true;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync return false;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * It's perfectly fine to reuse these, except for PAE and non-paging stuff.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync return true;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync return false;
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync * These cannot be flushed, and it's common to reuse the PDs as PTs.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync return false;
81096b0da0061583a511da27088643aa949a1ec9vboxsync * Attempts to satisfy a pgmPoolAlloc request from the cache.
d8e12fa5dd1c35282b98cb165e42b6b395cf971bvboxsync * @returns VBox status code.
81096b0da0061583a511da27088643aa949a1ec9vboxsync * @retval VINF_PGM_CACHED_PAGE on success.
81096b0da0061583a511da27088643aa949a1ec9vboxsync * @retval VERR_FILE_NOT_FOUND if not found.
81096b0da0061583a511da27088643aa949a1ec9vboxsync * @param pPool The pool.
81096b0da0061583a511da27088643aa949a1ec9vboxsync * @param GCPhys The GC physical address of the page we're gonna shadow.
5366e994777f9d9391cf809dc77610f57270d75dvboxsync * @param enmKind The kind of mapping.
56484ba959c372f0196716100568e02412b0dbd5vboxsync * @param iUser The shadow page pool index of the user table.
81096b0da0061583a511da27088643aa949a1ec9vboxsync * @param iUserTable The index into the user table (shadowed).
15c6c4ce0082362b8b81e15c3605f2d3aca69a21vboxsync * @param ppPage Where to store the pointer to the page.
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsyncstatic int pgmPoolCacheAlloc(PPGMPOOL pPool, RTGCPHYS GCPhys, PGMPOOLKIND enmKind, uint16_t iUser, uint32_t iUserTable, PPPGMPOOLPAGE ppPage)
81096b0da0061583a511da27088643aa949a1ec9vboxsync * Look up the GCPhys in the hash.
81096b0da0061583a511da27088643aa949a1ec9vboxsync Log3(("pgmPoolCacheAlloc: %RGp kind %d iUser=%d iUserTable=%x SLOT=%d\n", GCPhys, enmKind, iUser, iUserTable, i));
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync Log3(("pgmPoolCacheAlloc: slot %d found page %RGp\n", i, pPage->GCPhys));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync int rc = pgmPoolTrackAddUser(pPool, pPage, iUser, iUserTable);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * The kind is different. In some cases we should now flush the page
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * as it has been reused, but in most cases this is normal remapping
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync * of PDs as PT or big pages using the GCPhys field in a slightly
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync * different way than the other kinds.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync if (pgmPoolCacheReusedByKind((PGMPOOLKIND)pPage->enmKind, enmKind))
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync pgmPoolFlushPage(pPool, pPage); /* ASSUMES that VERR_PGM_POOL_CLEARED will be returned by pgmPoolTracInsert. */
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync } while (i != NIL_PGMPOOL_IDX);
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync Log3(("pgmPoolCacheAlloc: Missed GCPhys=%RGp enmKind=%d\n", GCPhys, enmKind));
3ff8aa7d3c74cfbe8da5f77b8ea6c748cc79213avboxsync * Inserts a page into the cache.
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync * @param pPool The pool.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * @param pPage The cached page.
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync * @param fCanBeCached Set if the page is fit for caching from the caller's point of view.
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsyncstatic void pgmPoolCacheInsert(PPGMPOOL pPool, PPGMPOOLPAGE pPage, bool fCanBeCached)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * Insert into the GCPhys hash if the page is fit for that.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync Log3(("pgmPoolCacheInsert: Caching %p:{.Core=%RHp, .idx=%d, .enmKind=%d, GCPhys=%RGp}\n",
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync pPage, pPage->Core.Key, pPage->idx, pPage->enmKind, pPage->GCPhys));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync Log3(("pgmPoolCacheInsert: Not caching %p:{.Core=%RHp, .idx=%d, .enmKind=%d, GCPhys=%RGp}\n",
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync pPage, pPage->Core.Key, pPage->idx, pPage->enmKind, pPage->GCPhys));
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync * Insert at the head of the age list.
e94bac0e97b56692161549c95d72512b1eaa78ccvboxsync pPool->aPages[pPool->iAgeHead].iAgePrev = pPage->idx;
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync * Flushes a cached page.
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync * @param pPool The pool.
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync * @param pPage The cached page.
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsyncstatic void pgmPoolCacheFlushPage(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync Log3(("pgmPoolCacheFlushPage: %RGp\n", pPage->GCPhys));
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * Remove the page from the hash.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * Remove it from the age list.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync pPool->aPages[pPage->iAgeNext].iAgePrev = pPage->iAgePrev;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync pPool->aPages[pPage->iAgePrev].iAgeNext = pPage->iAgeNext;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync#endif /* PGMPOOL_WITH_CACHE */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * Looks for pages sharing the monitor.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * @returns Pointer to the head page.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * @returns NULL if not found.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * @param pPool The Pool
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * @param pNewPage The page which is going to be monitored.
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsyncstatic PPGMPOOLPAGE pgmPoolMonitorGetPageByGCPhys(PPGMPOOL pPool, PPGMPOOLPAGE pNewPage)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * Look up the GCPhys in the hash.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync RTGCPHYS GCPhys = pNewPage->GCPhys & ~(RTGCPHYS)(PAGE_SIZE - 1);
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync /* find the head */
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync /* ignore, no monitoring. */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync AssertFatalMsgFailed(("enmKind=%d idx=%d\n", pPage->enmKind, pPage->idx));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync } while (i != NIL_PGMPOOL_IDX);
16793803f63339106d16a55bc5b55ba9070b44e0vboxsync * Enabled write monitoring of a guest page.
16793803f63339106d16a55bc5b55ba9070b44e0vboxsync * @returns VBox status code.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * @retval VINF_SUCCESS on success.
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * @retval VERR_PGM_POOL_CLEARED if the registration of the physical handler will cause a light weight pool flush.
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * @param pPool The pool.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * @param pPage The cached page.
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsyncstatic int pgmPoolMonitorInsert(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync LogFlow(("pgmPoolMonitorInsert %RGp\n", pPage->GCPhys & ~(RTGCPHYS)(PAGE_SIZE - 1)));
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * Filter out the relevant kinds.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync /* Nothing to monitor here. */
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync /* Nothing to monitor here. */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync AssertFatalMsgFailed(("This can't happen! enmKind=%d\n", pPage->enmKind));
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * Install handler.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync PPGMPOOLPAGE pPageHead = pgmPoolMonitorGetPageByGCPhys(pPool, pPage);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync Assert(pPageHead != pPage); Assert(pPageHead->iMonitoredNext != pPage->idx);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync pPool->aPages[pPageHead->iMonitoredNext].iMonitoredPrev = pPage->idx;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync Assert(pPage->iMonitoredNext == NIL_PGMPOOL_IDX); Assert(pPage->iMonitoredPrev == NIL_PGMPOOL_IDX);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync const RTGCPHYS GCPhysPage = pPage->GCPhys & ~(RTGCPHYS)(PAGE_SIZE - 1);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync rc = PGMHandlerPhysicalRegisterEx(pVM, PGMPHYSHANDLERTYPE_PHYSICAL_WRITE,
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync pPool->pfnAccessHandlerR3, MMHyperCCToR3(pVM, pPage),
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync pPool->pfnAccessHandlerR0, MMHyperCCToR0(pVM, pPage),
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync pPool->pfnAccessHandlerRC, MMHyperCCToRC(pVM, pPage),
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync /** @todo we should probably deal with out-of-memory conditions here, but for now increasing
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync * the heap size should suffice. */
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync if (pVM->pgm.s.fSyncFlags & PGM_SYNC_CLEAR_PGM_POOL)
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync * Disables write monitoring of a guest page.
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync * @returns VBox status code.
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync * @retval VINF_SUCCESS on success.
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync * @retval VERR_PGM_POOL_CLEARED if the deregistration of the physical handler will cause a light weight pool flush.
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync * @param pPool The pool.
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync * @param pPage The cached page.
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsyncstatic int pgmPoolMonitorFlush(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync * Filter out the relevant kinds.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync /* Nothing to monitor here. */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync AssertFatalMsgFailed(("This can't happen! enmKind=%d\n", pPage->enmKind));
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * Remove the page from the monitored list or uninstall it if last.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync PPGMPOOLPAGE pNewHead = &pPool->aPages[pPage->iMonitoredNext];
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync rc = PGMHandlerPhysicalChangeCallbacks(pVM, pPage->GCPhys & ~(RTGCPHYS)(PAGE_SIZE - 1),
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync pPool->pfnAccessHandlerR3, MMHyperCCToR3(pVM, pNewHead),
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync pPool->pfnAccessHandlerR0, MMHyperCCToR0(pVM, pNewHead),
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync pPool->pfnAccessHandlerRC, MMHyperCCToRC(pVM, pNewHead),
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync pPool->aPages[pPage->iMonitoredPrev].iMonitoredNext = pPage->iMonitoredNext;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync pPool->aPages[pPage->iMonitoredNext].iMonitoredPrev = pPage->iMonitoredPrev;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync rc = PGMHandlerPhysicalDeregister(pVM, pPage->GCPhys & ~(RTGCPHYS)(PAGE_SIZE - 1));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (pVM->pgm.s.fSyncFlags & PGM_SYNC_CLEAR_PGM_POOL)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * Remove it from the list of modified pages (if in it).
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * Set or clear the fCR3Mix attribute in a chain of monitored pages.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * @param pPool The Pool.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * @param pPage A page in the chain.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * @param fCR3Mix The new fCR3Mix value.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsyncstatic void pgmPoolMonitorChainChangeCR3Mix(PPGMPOOL pPool, PPGMPOOLPAGE pPage, bool fCR3Mix)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* current */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* before */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* after */
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * Installs or modifies monitoring of a CR3 page (special).
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync * We're pretending the CR3 page is shadowed by the pool so we can use the
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync * generic mechanisms in detecting chained monitoring. (This also gives us a
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync * tast of what code changes are required to really pool CR3 shadow pages.)
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync * @returns VBox status code.
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync * @param pPool The pool.
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * @param idxRoot The CR3 (root) page index.
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync * @param GCPhysCR3 The (new) CR3 value.
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsyncint pgmPoolMonitorMonitorCR3(PPGMPOOL pPool, uint16_t idxRoot, RTGCPHYS GCPhysCR3)
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync Assert(idxRoot != NIL_PGMPOOL_IDX && idxRoot < PGMPOOL_IDX_FIRST);
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync LogFlow(("pgmPoolMonitorMonitorCR3: idxRoot=%d pPage=%p:{.GCPhys=%RGp, .fMonitored=%d} GCPhysCR3=%RGp\n",
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync idxRoot, pPage, pPage->GCPhys, pPage->fMonitored, GCPhysCR3));
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync * The unlikely case where it already matches.
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync * Flush the current monitoring and remove it from the hash.
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync pgmPoolMonitorChainChangeCR3Mix(pPool, pPage, false);
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync * Monitor the page at the new location and insert it into the hash.
5366e994777f9d9391cf809dc77610f57270d75dvboxsync pgmPoolMonitorChainChangeCR3Mix(pPool, pPage, true);
5366e994777f9d9391cf809dc77610f57270d75dvboxsync * Removes the monitoring of a CR3 page (special).
5366e994777f9d9391cf809dc77610f57270d75dvboxsync * @returns VBox status code.
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync * @param pPool The pool.
cc1ef2ef9bbc6a0ff964928d61b7298e5bfcce5fvboxsync * @param idxRoot The CR3 (root) page index.
5366e994777f9d9391cf809dc77610f57270d75dvboxsyncint pgmPoolMonitorUnmonitorCR3(PPGMPOOL pPool, uint16_t idxRoot)
5366e994777f9d9391cf809dc77610f57270d75dvboxsync Assert(idxRoot != NIL_PGMPOOL_IDX && idxRoot < PGMPOOL_IDX_FIRST);
5366e994777f9d9391cf809dc77610f57270d75dvboxsync LogFlow(("pgmPoolMonitorUnmonitorCR3: idxRoot=%d pPage=%p:{.GCPhys=%RGp, .fMonitored=%d}\n",
5366e994777f9d9391cf809dc77610f57270d75dvboxsync idxRoot, pPage, pPage->GCPhys, pPage->fMonitored));
5366e994777f9d9391cf809dc77610f57270d75dvboxsync pgmPoolMonitorChainChangeCR3Mix(pPool, pPage, false);
7e8ef90d3160234df0f254131b87af4243d79476vboxsync# endif /* PGMPOOL_WITH_MIXED_PT_CR3 */
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync * Inserts the page into the list of modified pages.
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync * @param pPool The pool.
e2489bd9ef063ae006feaebc3318ffa4143f6e16vboxsync * @param pPage The page.
e2489bd9ef063ae006feaebc3318ffa4143f6e16vboxsyncvoid pgmPoolMonitorModifiedInsert(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
e2489bd9ef063ae006feaebc3318ffa4143f6e16vboxsync Log3(("pgmPoolMonitorModifiedInsert: idx=%d\n", pPage->idx));
e2489bd9ef063ae006feaebc3318ffa4143f6e16vboxsync ("Next=%d Prev=%d idx=%d cModifications=%d Head=%d cModifiedPages=%d\n",
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync pPage->iModifiedNext, pPage->iModifiedPrev, pPage->idx, pPage->cModifications,
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync pPool->aPages[pPool->iModifiedHead].iModifiedPrev = pPage->idx;
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync if (pPool->cModifiedPages > pPool->cModifiedPagesHigh)
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync * Removes the page from the list of modified pages and resets the
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync * moficiation counter.
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync * @param pPool The pool.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * @param pPage The page which is believed to be in the list of modified pages.
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsyncstatic void pgmPoolMonitorModifiedRemove(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync Log3(("pgmPoolMonitorModifiedRemove: idx=%d cModifications=%d\n", pPage->idx, pPage->cModifications));
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync pPool->aPages[pPage->iModifiedNext].iModifiedPrev = NIL_PGMPOOL_IDX;
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync pPool->aPages[pPage->iModifiedPrev].iModifiedNext = pPage->iModifiedNext;
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync pPool->aPages[pPage->iModifiedNext].iModifiedPrev = pPage->iModifiedPrev;
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync * Zaps the list of modified pages, resetting their modification counters in the process.
56484ba959c372f0196716100568e02412b0dbd5vboxsync * @param pVM The VM handle.
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync LogFlow(("pgmPoolMonitorModifiedClearAll: cModifiedPages=%d\n", pPool->cModifiedPages));
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync AssertMsg(cPages == pPool->cModifiedPages, ("%d != %d\n", cPages, pPool->cModifiedPages));
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync * Clear all shadow pages and clear all modification counters.
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync * @param pVM The VM handle.
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync * @remark Should only be used when monitoring is available, thus placed in
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync * the PGMPOOL_WITH_MONITORING #ifdef.
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync LogFlow(("pgmPoolClearAll: cUsedPages=%d\n", pPool->cUsedPages));
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync * Iterate all the pages until we've encountered all that in use.
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync * This is simple but not quite optimal solution.
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync unsigned cModifiedPages = 0; NOREF(cModifiedPages);
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync * We only care about shadow page tables.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync void *pvShw = PGMPOOL_PAGE_2_PTR(pPool->CTX_SUFF(pVM), pPage);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /* fall thru */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync Assert(!pPage->cModifications || ++cModifiedPages);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync Assert(pPage->iModifiedNext == NIL_PGMPOOL_IDX || pPage->cModifications);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync Assert(pPage->iModifiedPrev == NIL_PGMPOOL_IDX || pPage->cModifications);
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync /* swipe the special pages too. */
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync for (iPage = PGMPOOL_IDX_FIRST_SPECIAL; iPage < PGMPOOL_IDX_FIRST; iPage++)
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync Assert(!pPage->cModifications || ++cModifiedPages);
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync Assert(pPage->iModifiedNext == NIL_PGMPOOL_IDX || pPage->cModifications);
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync Assert(pPage->iModifiedPrev == NIL_PGMPOOL_IDX || pPage->cModifications);
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync AssertMsg(cModifiedPages == pPool->cModifiedPages, ("%d != %d\n", cModifiedPages, pPool->cModifiedPages));
9e7e0b61d29309a0ed7af9472c8d6d865f9e8a2dvboxsync * Clear all the GCPhys links and rebuild the phys ext free list.
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync for (PPGMRAMRANGE pRam = pPool->CTX_SUFF(pVM)->pgm.s.CTX_SUFF(pRamRanges);
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync while (iPage-- > 0)
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync pRam->aPages[iPage].HCPhys &= MM_RAM_FLAGS_NO_REFS_MASK; /** @todo PAGE FLAGS */
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync PPGMPOOLPHYSEXT paPhysExts = pPool->CTX_SUFF(paPhysExts);
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync for (unsigned i = 0; i < cMaxPhysExts; i++)
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync paPhysExts[cMaxPhysExts - 1].iNext = NIL_PGMPOOL_PHYSEXT_INDEX;
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync#endif /* IN_RING3 */
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync * Handle SyncCR3 pool tasks
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync * @returns VBox status code.
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync * @retval VINF_SUCCESS if successfully added.
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync * @retval VINF_PGM_SYNC_CR3 is it needs to be deferred to ring 3 (GC only)
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync * @param pVM The VM handle.
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync * @remark Should only be used when monitoring is available, thus placed in
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync * the PGMPOOL_WITH_MONITORING #ifdef.
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync * When monitoring shadowed pages, we reset the modification counters on CR3 sync.
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync * Occasionally we will have to clear all the shadow page tables because we wanted
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync * to monitor a page which was mapped by too many shadowed page tables. This operation
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync * sometimes refered to as a 'lightweight flush'.
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync if (!(pVM->pgm.s.fSyncFlags & PGM_SYNC_CLEAR_PGM_POOL))
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync# ifdef IN_RING3 /* Don't flush in ring-0 or raw mode, it's taking too long. */
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync# else /* !IN_RING3 */
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync LogFlow(("SyncCR3: PGM_SYNC_CLEAR_PGM_POOL is set -> VINF_PGM_SYNC_CR3\n"));
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync VM_FF_SET(pVM, VM_FF_PGM_SYNC_CR3); /** @todo no need to do global sync, right? */
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync# endif /* !IN_RING3 */
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync#endif /* PGMPOOL_WITH_MONITORING */
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * Frees up at least one user entry.
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync * @returns VBox status code.
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync * @retval VINF_SUCCESS if successfully added.
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync * @retval VERR_PGM_POOL_FLUSHED if the pool was flushed.
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync * @param pPool The pool.
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync * @param iUser The user index.
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsyncstatic int pgmPoolTrackFreeOneUser(PPGMPOOL pPool, uint16_t iUser)
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync * Just free cached pages in a braindead fashion.
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync /** @todo walk the age list backwards and free the first with usage. */
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync } while (pPool->iUserFreeHead == NIL_PGMPOOL_USER_INDEX);
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync * Lazy approach.
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync /* @todo incompatible with long mode paging (cr3 root will be flushed) */
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * Inserts a page into the cache.
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * This will create user node for the page, insert it into the GCPhys
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * hash, and insert it into the age list.
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * @returns VBox status code.
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync * @retval VINF_SUCCESS if successfully added.
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * @retval VERR_PGM_POOL_FLUSHED if the pool was flushed.
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * @retval VERR_PGM_POOL_CLEARED if the deregistration of the physical handler will cause a light weight pool flush.
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * @param pPool The pool.
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * @param pPage The cached page.
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * @param GCPhys The GC physical address of the page we're gonna shadow.
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * @param iUser The user index.
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * @param iUserTable The user table index.
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsyncDECLINLINE(int) pgmPoolTrackInsert(PPGMPOOL pPool, PPGMPOOLPAGE pPage, RTGCPHYS GCPhys, uint16_t iUser, uint32_t iUserTable)
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync LogFlow(("pgmPoolTrackInsert iUser %d iUserTable %d\n", iUser, iUserTable));
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync * Find free a user node.
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * Unlink the user node from the free list,
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * initialize and insert it into the user list.
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * Insert into cache and enable monitoring of the guest page if enabled.
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * Until we implement caching of all levels, including the CR3 one, we'll
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * have to make sure we don't try monitor & cache any recursive reuse of
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * a monitored CR3 page. Because all windows versions are doing this we'll
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * have to be able to do combined access monitoring, CR3 + PT and
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * PD + PT (guest PAE).
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * We're now cooperating with the CR3 monitor if an uncachable page is found.
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync#if defined(PGMPOOL_WITH_MONITORING) || defined(PGMPOOL_WITH_CACHE)
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync const bool fCanBeMonitored = true;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync bool fCanBeMonitored = pPool->CTX_SUFF(pVM)->pgm.s.GCPhysGstCR3Monitored == NIL_RTGCPHYS
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync || (GCPhys & X86_PTE_PAE_PG_MASK) != (pPool->CTX_SUFF(pVM)->pgm.s.GCPhysGstCR3Monitored & X86_PTE_PAE_PG_MASK)
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync pgmPoolCacheInsert(pPool, pPage, fCanBeMonitored); /* This can be expanded. */
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync /* 'Failed' - free the usage, and keep it in the cache (if enabled). */
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync#endif /* PGMPOOL_WITH_MONITORING */
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync# ifdef PGMPOOL_WITH_CACHE /* (only used when the cache is enabled.) */
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * Adds a user reference to a page.
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * This will
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * This will move the page to the head of the
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * @returns VBox status code.
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * @retval VINF_SUCCESS if successfully added.
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync * @retval VERR_PGM_POOL_FLUSHED if the pool was flushed.
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * @param pPool The pool.
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * @param pPage The cached page.
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync * @param iUser The user index.
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync * @param iUserTable The user table.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsyncstatic int pgmPoolTrackAddUser(PPGMPOOL pPool, PPGMPOOLPAGE pPage, uint16_t iUser, uint32_t iUserTable)
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync LogFlow(("pgmPoolTrackAddUser iUser %d iUserTable %d\n", iUser, iUserTable));
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync * Check that the entry doesn't already exists.
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync AssertMsg(paUsers[i].iUser != iUser || paUsers[i].iUserTable != iUserTable, ("%x %x vs new %x %x\n", paUsers[i].iUser, paUsers[i].iUserTable, iUser, iUserTable));
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * Allocate a user node.
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * Initialize the user node and insert it.
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * Tell the cache to update its replacement stats for this page.
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync# endif /* PGMPOOL_WITH_CACHE */
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * Frees a user record associated with a page.
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * This does not clear the entry in the user table, it simply replaces the
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * user record to the chain of free records.
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync * @param pPool The pool.
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * @param HCPhys The HC physical address of the shadow page.
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync * @param iUser The shadow page pool index of the user table.
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * @param iUserTable The index into the user table (shadowed).
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsyncstatic void pgmPoolTrackFreeUser(PPGMPOOL pPool, PPGMPOOLPAGE pPage, uint16_t iUser, uint32_t iUserTable)
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync * Unlink and free the specified user entry.
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync /* Special: For PAE and 32-bit paging, there is usually no more than one user. */
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync /* General: Linear search. */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* Fatal: didn't find it */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AssertFatalMsgFailed(("Didn't find the user entry! iUser=%#x iUserTable=%#x GCPhys=%RGp\n",
d8e12fa5dd1c35282b98cb165e42b6b395cf971bvboxsync * Gets the entry size of a shadow table.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * @param enmKind The kind of page.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * @returns The size of the entry in bytes. That is, 4 or 8.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * @returns If the kind is not for a table, an assertion is raised and 0 is
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * returned.
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsyncDECLINLINE(unsigned) pgmPoolTrackGetShadowEntrySize(PGMPOOLKIND enmKind)
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync * Gets the entry size of a guest table.
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync * @param enmKind The kind of page.
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync * @returns The size of the entry in bytes. That is, 0, 4 or 8.
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync * @returns If the kind is not for a table, an assertion is raised and 0 is
c99b597540585068d22dde4c9f74730305f24097vboxsync * returned.
c99b597540585068d22dde4c9f74730305f24097vboxsyncDECLINLINE(unsigned) pgmPoolTrackGetGuestEntrySize(PGMPOOLKIND enmKind)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /** @todo can we return 0? (nobody is calling this...) */
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync * Scans one shadow page table for mappings of a physical page.
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync * @param pVM The VM handle.
c99b597540585068d22dde4c9f74730305f24097vboxsync * @param pPhysPage The guest page in question.
c99b597540585068d22dde4c9f74730305f24097vboxsync * @param iShw The shadow page table.
c99b597540585068d22dde4c9f74730305f24097vboxsync * @param cRefs The number of references made in that PT.
c99b597540585068d22dde4c9f74730305f24097vboxsyncstatic void pgmPoolTrackFlushGCPhysPTInt(PVM pVM, PCPGMPAGE pPhysPage, uint16_t iShw, uint16_t cRefs)
c99b597540585068d22dde4c9f74730305f24097vboxsync LogFlow(("pgmPoolTrackFlushGCPhysPT: HCPhys=%RHp iShw=%d cRefs=%d\n", pPhysPage->HCPhys, iShw, cRefs));
c99b597540585068d22dde4c9f74730305f24097vboxsync * Assert sanity.
c99b597540585068d22dde4c9f74730305f24097vboxsync AssertFatalMsg(iShw < pPool->cCurPages && iShw != NIL_PGMPOOL_IDX, ("iShw=%d\n", iShw));
c99b597540585068d22dde4c9f74730305f24097vboxsync * Then, clear the actual mappings to the page in the shadow PT.
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync const uint32_t u32 = PGM_PAGE_GET_HCPHYS(pPhysPage) | X86_PTE_P;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync PX86PT pPT = (PX86PT)PGMPOOL_PAGE_2_PTR(pVM, pPage);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pPT->a); i++)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if ((pPT->a[i].u & (X86_PTE_PG_MASK | X86_PTE_P)) == u32)
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync Log4(("pgmPoolTrackFlushGCPhysPTs: i=%d pte=%RX32 cRefs=%#x\n", i, pPT->a[i], cRefs));
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync pPT->a[i].u = 0;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync RTLogPrintf("cRefs=%d iFirstPresent=%d cPresent=%d\n", cRefs, pPage->iFirstPresent, pPage->cPresent);
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync if ((pPT->a[i].u & (X86_PTE_PG_MASK | X86_PTE_P)) == u32)
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync pPT->a[i].u = 0;
5366e994777f9d9391cf809dc77610f57270d75dvboxsync AssertFatalMsgFailed(("cRefs=%d iFirstPresent=%d cPresent=%d\n", cRefs, pPage->iFirstPresent, pPage->cPresent));
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync const uint64_t u64 = PGM_PAGE_GET_HCPHYS(pPhysPage) | X86_PTE_P;
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync PX86PTPAE pPT = (PX86PTPAE)PGMPOOL_PAGE_2_PTR(pVM, pPage);
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pPT->a); i++)
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync if ((pPT->a[i].u & (X86_PTE_PAE_PG_MASK | X86_PTE_P)) == u64)
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync Log4(("pgmPoolTrackFlushGCPhysPTs: i=%d pte=%RX64 cRefs=%#x\n", i, pPT->a[i], cRefs));
e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5vboxsync pPT->a[i].u = 0;
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync RTLogPrintf("cRefs=%d iFirstPresent=%d cPresent=%d\n", cRefs, pPage->iFirstPresent, pPage->cPresent);
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync if ((pPT->a[i].u & (X86_PTE_PAE_PG_MASK | X86_PTE_P)) == u64)
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync pPT->a[i].u = 0;
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync AssertFatalMsgFailed(("cRefs=%d iFirstPresent=%d cPresent=%d u64=%RX64\n", cRefs, pPage->iFirstPresent, pPage->cPresent, u64));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync const uint64_t u64 = PGM_PAGE_GET_HCPHYS(pPhysPage) | X86_PTE_P;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync PEPTPT pPT = (PEPTPT)PGMPOOL_PAGE_2_PTR(pVM, pPage);
3641904508e6a0671c21a083a2ed03ebad8d976cvboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pPT->a); i++)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if ((pPT->a[i].u & (EPT_PTE_PG_MASK | X86_PTE_P)) == u64)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Log4(("pgmPoolTrackFlushGCPhysPTs: i=%d pte=%RX64 cRefs=%#x\n", i, pPT->a[i], cRefs));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pPT->a[i].u = 0;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync RTLogPrintf("cRefs=%d iFirstPresent=%d cPresent=%d\n", cRefs, pPage->iFirstPresent, pPage->cPresent);
36f3c24e4ad9c6b813767db1faeabbe7e2ecc057vboxsync if ((pPT->a[i].u & (EPT_PTE_PG_MASK | X86_PTE_P)) == u64)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pPT->a[i].u = 0;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync AssertFatalMsgFailed(("cRefs=%d iFirstPresent=%d cPresent=%d\n", cRefs, pPage->iFirstPresent, pPage->cPresent));
36f3c24e4ad9c6b813767db1faeabbe7e2ecc057vboxsync AssertFatalMsgFailed(("enmKind=%d iShw=%d\n", pPage->enmKind, iShw));
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * Scans one shadow page table for mappings of a physical page.
dea3e7faa80f4aab41e08945b9308fd2e3ffe7fcvboxsync * @param pVM The VM handle.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * @param pPhysPage The guest page in question.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * @param iShw The shadow page table.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * @param cRefs The number of references made in that PT.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsyncvoid pgmPoolTrackFlushGCPhysPT(PVM pVM, PPGMPAGE pPhysPage, uint16_t iShw, uint16_t cRefs)
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync PPGMPOOL pPool = pVM->pgm.s.CTX_SUFF(pPool); NOREF(pPool);
36f3c24e4ad9c6b813767db1faeabbe7e2ecc057vboxsync LogFlow(("pgmPoolTrackFlushGCPhysPT: HCPhys=%RHp iShw=%d cRefs=%d\n", pPhysPage->HCPhys, iShw, cRefs));
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync STAM_PROFILE_START(&pPool->StatTrackFlushGCPhysPT, f);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync pgmPoolTrackFlushGCPhysPTInt(pVM, pPhysPage, iShw, cRefs);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pPhysPage->HCPhys &= MM_RAM_FLAGS_NO_REFS_MASK; /** @todo PAGE FLAGS */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync STAM_PROFILE_STOP(&pPool->StatTrackFlushGCPhysPT, f);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Flushes a list of shadow page tables mapping the same physical page.
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync * @param pVM The VM handle.
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync * @param pPhysPage The guest page in question.
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync * @param iPhysExt The physical cross reference extent list to flush.
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsyncvoid pgmPoolTrackFlushGCPhysPTs(PVM pVM, PPGMPAGE pPhysPage, uint16_t iPhysExt)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync STAM_PROFILE_START(&pPool->StatTrackFlushGCPhysPTs, f);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync LogFlow(("pgmPoolTrackFlushGCPhysPTs: HCPhys=%RHp iPhysExt\n", pPhysPage->HCPhys, iPhysExt));
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pPhysExt->aidx); i++)
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync pgmPoolTrackFlushGCPhysPTInt(pVM, pPhysPage, pPhysExt->aidx[i], 1);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync /* insert the list into the free list and clear the ram range entry. */
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync pPhysPage->HCPhys &= MM_RAM_FLAGS_NO_REFS_MASK; /** @todo PAGE FLAGS */
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync STAM_PROFILE_STOP(&pPool->StatTrackFlushGCPhysPTs, f);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* PGMPOOL_WITH_GCPHYS_TRACKING */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Scans all shadow page tables for mappings of a physical page.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * This may be slow, but it's most likely more efficient than cleaning
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync * out the entire page pool / cache.
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync * @returns VBox status code.
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync * @retval VINF_SUCCESS if all references has been successfully cleared.
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync * @retval VINF_PGM_GCPHYS_ALIASED if we're better off with a CR3 sync and
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * a page pool cleaning.
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync * @param pVM The VM handle.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * @param pPhysPage The guest page in question.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncint pgmPoolTrackFlushGCPhysPTsSlow(PVM pVM, PPGMPAGE pPhysPage)
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync STAM_PROFILE_START(&pPool->StatTrackFlushGCPhysPTsSlow, s);
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync LogFlow(("pgmPoolTrackFlushGCPhysPTsSlow: cUsedPages=%d cPresent=%d HCPhys=%RHp\n",
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync pPool->cUsedPages, pPool->cPresent, pPhysPage->HCPhys));
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync * There is a limit to what makes sense.
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync LogFlow(("pgmPoolTrackFlushGCPhysPTsSlow: giving up... (cPresent=%d)\n", pPool->cPresent));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync STAM_PROFILE_STOP(&pPool->StatTrackFlushGCPhysPTsSlow, s);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * Iterate all the pages until we've encountered all that in use.
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync * This is simple but not quite optimal solution.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync const uint64_t u64 = PGM_PAGE_GET_HCPHYS(pPhysPage) | X86_PTE_P;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * We only care about shadow page tables.
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync PX86PT pPT = (PX86PT)PGMPOOL_PAGE_2_PTR(pVM, pPage);
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pPT->a); i++)
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync if ((pPT->a[i].u & (X86_PTE_PG_MASK | X86_PTE_P)) == u32)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync //Log4(("pgmPoolTrackFlushGCPhysPTsSlow: idx=%d i=%d pte=%RX32\n", iPage, i, pPT->a[i]));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pPT->a[i].u = 0;
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync PX86PTPAE pPT = (PX86PTPAE)PGMPOOL_PAGE_2_PTR(pVM, pPage);
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pPT->a); i++)
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync if ((pPT->a[i].u & (X86_PTE_PAE_PG_MASK | X86_PTE_P)) == u64)
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync //Log4(("pgmPoolTrackFlushGCPhysPTsSlow: idx=%d i=%d pte=%RX64\n", iPage, i, pPT->a[i]));
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync pPT->a[i].u = 0;
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync pPhysPage->HCPhys &= MM_RAM_FLAGS_NO_REFS_MASK; /** @todo PAGE FLAGS */
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync STAM_PROFILE_STOP(&pPool->StatTrackFlushGCPhysPTsSlow, s);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * Clears the user entry in a user table.
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync * This is used to remove all references to a page when flushing it.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsyncstatic void pgmPoolTrackClearPageUser(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PCPGMPOOLUSER pUser)
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync * Map the user page.
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync PPGMPOOLPAGE pUserPage = &pPool->aPages[pUser->iUser];
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* Must translate the fake 2048 entry PD to a 512 PD one since the R0 mapping is not linear. */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pUserPage = &pPool->aPages[PGMPOOL_IDX_PAE_PD_0 + iPdpt];
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Assert(pUserPage->enmKind == PGMPOOLKIND_PAE_PD_FOR_PAE_PD);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync u.pau64 = (uint64_t *)PGMPOOL_PAGE_2_PTR(pPool->CTX_SUFF(pVM), pUserPage);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* Safety precaution in case we change the paging for other modes too in the future. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync Assert(PGMGetHyperCR3(pPool->CTX_SUFF(pVM)) != pPage->Core.Key);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * Some sanity checks.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync Assert(!(u.pau32[iUserTable] & PGM_PDFLAGS_MAPPING));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync# if !defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0) && !defined(VBOX_WITH_PGMPOOL_PAGING_ONLY)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync Assert(iUserTable < 2048 && pUser->iUser == PGMPOOL_IDX_PAE_PD);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync AssertMsg(!(u.pau64[iUserTable] & PGM_PDFLAGS_MAPPING), ("%llx %d\n", u.pau64[iUserTable], iUserTable));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Assert(!(u.pau64[iUserTable] & PGM_PLXFLAGS_PERMANENT));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Assert(!(u.pau64[iUserTable] & PGM_PDFLAGS_MAPPING));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync Assert(!(u.pau64[iUserTable] & PGM_PLXFLAGS_PERMANENT));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync Assert(!(u.pau64[iUserTable] & PGM_PLXFLAGS_PERMANENT));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* GCPhys >> PAGE_SHIFT is the index here */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync AssertMsgFailed(("enmKind=%d\n", pUserPage->enmKind));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync#endif /* VBOX_STRICT */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * Clear the entry in the user page.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* 32-bit entries */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* 64-bit entries */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync# if !defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0) && !defined(VBOX_WITH_PGMPOOL_PAGING_ONLY)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AssertFatalMsgFailed(("enmKind=%d iUser=%#x iUserTable=%#x\n", pUserPage->enmKind, pUser->iUser, pUser->iUserTable));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * Clears all users of a page.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsyncstatic void pgmPoolTrackClearPageUsers(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * Free all the user records.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* Clear enter in user table. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync pgmPoolTrackClearPageUser(pPool, pPage, &paUsers[i]);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* Free it. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* Next. */
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsync * Allocates a new physical cross reference extent.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * @returns Pointer to the allocated extent on success. NULL if we're out of them.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * @param pVM The VM handle.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * @param piPhysExt Where to store the phys ext index.
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsyncPPGMPOOLPHYSEXT pgmPoolTrackPhysExtAlloc(PVM pVM, uint16_t *piPhysExt)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync STAM_COUNTER_INC(&pPool->StamTrackPhysExtAllocFailures);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync PPGMPOOLPHYSEXT pPhysExt = &pPool->CTX_SUFF(paPhysExts)[iPhysExt];
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync * Frees a physical cross reference extent.
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync * @param pVM The VM handle.
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync * @param iPhysExt The extent to free.
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsyncvoid pgmPoolTrackPhysExtFree(PVM pVM, uint16_t iPhysExt)
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync PPGMPOOLPHYSEXT pPhysExt = &pPool->CTX_SUFF(paPhysExts)[iPhysExt];
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync for (unsigned i = 0; i < RT_ELEMENTS(pPhysExt->aidx); i++)
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync * Frees a physical cross reference extent.
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync * @param pVM The VM handle.
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync * @param iPhysExt The extent to free.
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsyncvoid pgmPoolTrackPhysExtFreeList(PVM pVM, uint16_t iPhysExt)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pPhysExt->aidx); i++)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Insert a reference into a list of physical cross reference extents.
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync * @returns The new ram range flags (top 16-bits).
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync * @param pVM The VM handle.
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync * @param iPhysExt The physical extent index of the list head.
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync * @param iShwPT The shadow page table index.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncstatic uint16_t pgmPoolTrackPhysExtInsert(PVM pVM, uint16_t iPhysExt, uint16_t iShwPT)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync PPGMPOOLPHYSEXT paPhysExts = pPool->CTX_SUFF(paPhysExts);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* special common case. */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (paPhysExts[iPhysExt].aidx[2] == NIL_PGMPOOL_IDX)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync STAM_COUNTER_INC(&pVM->pgm.s.StatTrackAliasedMany);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync LogFlow(("pgmPoolTrackPhysExtAddref: %d:{,,%d}\n", iPhysExt, iShwPT));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync return iPhysExt | (MM_RAM_FLAGS_CREFS_PHYSEXT << (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT));
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync /* general treatment. */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync for (unsigned i = 0; i < RT_ELEMENTS(paPhysExts[iPhysExt].aidx); i++)
92e624e40b06b4dc6d0a8222e1de33bd3e879a63vboxsync if (paPhysExts[iPhysExt].aidx[i] == NIL_PGMPOOL_IDX)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync STAM_COUNTER_INC(&pVM->pgm.s.StatTrackAliasedMany);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync LogFlow(("pgmPoolTrackPhysExtAddref: %d:{%d} i=%d cMax=%d\n", iPhysExt, iShwPT, i, cMax));
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync return iPhysExtStart | (MM_RAM_FLAGS_CREFS_PHYSEXT << (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync LogFlow(("pgmPoolTrackPhysExtAddref: overflow (1) iShwPT=%d\n", iShwPT));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync return MM_RAM_FLAGS_IDX_OVERFLOWED | (MM_RAM_FLAGS_CREFS_PHYSEXT << (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* add another extent to the list. */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync PPGMPOOLPHYSEXT pNew = pgmPoolTrackPhysExtAlloc(pVM, &iPhysExt);
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync return MM_RAM_FLAGS_IDX_OVERFLOWED | (MM_RAM_FLAGS_CREFS_PHYSEXT << (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync LogFlow(("pgmPoolTrackPhysExtAddref: added new extent %d:{%d}->%d\n", iPhysExt, iShwPT, iPhysExtStart));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync return iPhysExt | (MM_RAM_FLAGS_CREFS_PHYSEXT << (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT));
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * Add a reference to guest physical page where extents are in use.
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync * @returns The new ram range flags (top 16-bits).
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * @param pVM The VM handle.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * @param u16 The ram range flags (top 16-bits).
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * @param iShwPT The shadow page table index.
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsyncuint16_t pgmPoolTrackPhysExtAddref(PVM pVM, uint16_t u16, uint16_t iShwPT)
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync if ((u16 >> (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT)) != MM_RAM_FLAGS_CREFS_PHYSEXT)
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * Convert to extent list.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync Assert((u16 >> (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT)) == 1);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync PPGMPOOLPHYSEXT pPhysExt = pgmPoolTrackPhysExtAlloc(pVM, &iPhysExt);
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync LogFlow(("pgmPoolTrackPhysExtAddref: new extent: %d:{%d, %d}\n", iPhysExt, u16 & MM_RAM_FLAGS_IDX_MASK, iShwPT));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync u16 = iPhysExt | (MM_RAM_FLAGS_CREFS_PHYSEXT << (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT));
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync u16 = MM_RAM_FLAGS_IDX_OVERFLOWED | (MM_RAM_FLAGS_CREFS_PHYSEXT << (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT));
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync else if (u16 != (MM_RAM_FLAGS_IDX_OVERFLOWED | (MM_RAM_FLAGS_CREFS_PHYSEXT << (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT))))
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync * Insert into the extent list.
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync u16 = pgmPoolTrackPhysExtInsert(pVM, u16 & MM_RAM_FLAGS_IDX_MASK, iShwPT);
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync STAM_COUNTER_INC(&pVM->pgm.s.StatTrackAliasedLots);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * Clear references to guest physical memory.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * @param pPool The pool.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * @param pPage The page.
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync * @param pPhysPage Pointer to the aPages entry in the ram range.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsyncvoid pgmPoolTrackPhysExtDerefGCPhys(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PPGMPAGE pPhysPage)
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync const unsigned cRefs = pPhysPage->HCPhys >> MM_RAM_FLAGS_CREFS_SHIFT; /** @todo PAGE FLAGS */
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync AssertFatalMsg(cRefs == MM_RAM_FLAGS_CREFS_PHYSEXT, ("cRefs=%d HCPhys=%RHp pPage=%p:{.idx=%d}\n", cRefs, pPhysPage->HCPhys, pPage, pPage->idx));
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync uint16_t iPhysExt = (pPhysPage->HCPhys >> MM_RAM_FLAGS_IDX_SHIFT) & MM_RAM_FLAGS_IDX_MASK;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync PPGMPOOLPHYSEXT paPhysExts = pPool->CTX_SUFF(paPhysExts);
81096b0da0061583a511da27088643aa949a1ec9vboxsync * Look for the shadow page and check if it's all freed.
81096b0da0061583a511da27088643aa949a1ec9vboxsync for (unsigned i = 0; i < RT_ELEMENTS(paPhysExts[iPhysExt].aidx); i++)
81096b0da0061583a511da27088643aa949a1ec9vboxsync for (i = 0; i < RT_ELEMENTS(paPhysExts[iPhysExt].aidx); i++)
81096b0da0061583a511da27088643aa949a1ec9vboxsync if (paPhysExts[iPhysExt].aidx[i] != NIL_PGMPOOL_IDX)
81096b0da0061583a511da27088643aa949a1ec9vboxsync LogFlow(("pgmPoolTrackPhysExtDerefGCPhys: HCPhys=%RX64 idx=%d\n", pPhysPage->HCPhys, pPage->idx));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* we can free the node. */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync const uint16_t iPhysExtNext = paPhysExts[iPhysExt].iNext;
5366e994777f9d9391cf809dc77610f57270d75dvboxsync /* lonely node */
5366e994777f9d9391cf809dc77610f57270d75dvboxsync LogFlow(("pgmPoolTrackPhysExtDerefGCPhys: HCPhys=%RX64 idx=%d lonely\n", pPhysPage->HCPhys, pPage->idx));
5366e994777f9d9391cf809dc77610f57270d75dvboxsync pPhysPage->HCPhys &= MM_RAM_FLAGS_NO_REFS_MASK; /** @todo PAGE FLAGS */
81096b0da0061583a511da27088643aa949a1ec9vboxsync else if (iPhysExtPrev == NIL_PGMPOOL_PHYSEXT_INDEX)
5366e994777f9d9391cf809dc77610f57270d75dvboxsync LogFlow(("pgmPoolTrackPhysExtDerefGCPhys: HCPhys=%RX64 idx=%d head\n", pPhysPage->HCPhys, pPage->idx));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pPhysPage->HCPhys = (pPhysPage->HCPhys & MM_RAM_FLAGS_NO_REFS_MASK) /** @todo PAGE FLAGS */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync | ((uint64_t)MM_RAM_FLAGS_CREFS_PHYSEXT << MM_RAM_FLAGS_CREFS_SHIFT)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync | ((uint64_t)iPhysExtNext << MM_RAM_FLAGS_IDX_SHIFT);
5366e994777f9d9391cf809dc77610f57270d75dvboxsync /* in list */
5366e994777f9d9391cf809dc77610f57270d75dvboxsync LogFlow(("pgmPoolTrackPhysExtDerefGCPhys: HCPhys=%RX64 idx=%d\n", pPhysPage->HCPhys, pPage->idx));
81096b0da0061583a511da27088643aa949a1ec9vboxsync AssertFatalMsgFailed(("not-found! cRefs=%d HCPhys=%RHp pPage=%p:{.idx=%d}\n", cRefs, pPhysPage->HCPhys, pPage, pPage->idx));
81096b0da0061583a511da27088643aa949a1ec9vboxsync else /* nothing to do */
81096b0da0061583a511da27088643aa949a1ec9vboxsync LogFlow(("pgmPoolTrackPhysExtDerefGCPhys: HCPhys=%RX64\n", pPhysPage->HCPhys));
5366e994777f9d9391cf809dc77610f57270d75dvboxsync * Clear references to guest physical memory.
5366e994777f9d9391cf809dc77610f57270d75dvboxsync * This is the same as pgmPoolTracDerefGCPhys except that the guest physical address
5366e994777f9d9391cf809dc77610f57270d75dvboxsync * is assumed to be correct, so the linear search can be skipped and we can assert
5366e994777f9d9391cf809dc77610f57270d75dvboxsync * at an earlier point.
5366e994777f9d9391cf809dc77610f57270d75dvboxsync * @param pPool The pool.
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync * @param pPage The page.
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync * @param HCPhys The host physical address corresponding to the guest page.
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync * @param GCPhys The guest physical address corresponding to HCPhys.
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsyncstatic void pgmPoolTracDerefGCPhys(PPGMPOOL pPool, PPGMPOOLPAGE pPage, RTHCPHYS HCPhys, RTGCPHYS GCPhys)
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * Walk range list.
5366e994777f9d9391cf809dc77610f57270d75dvboxsync PPGMRAMRANGE pRam = pPool->CTX_SUFF(pVM)->pgm.s.CTX_SUFF(pRamRanges);
5366e994777f9d9391cf809dc77610f57270d75dvboxsync /* does it match? */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncRTHCPHYS HCPhysPage = PGM_PAGE_GET_HCPHYS(&pRam->aPages[iPage]);
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsyncLog(("pgmPoolTracDerefGCPhys %RHp vs %RHp\n", HCPhysPage, HCPhys));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (PGM_PAGE_GET_HCPHYS(&pRam->aPages[iPage]) == HCPhys)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pgmTrackDerefGCPhys(pPool, pPage, &pRam->aPages[iPage]);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AssertFatalMsgFailed(("HCPhys=%RHp GCPhys=%RGp\n", HCPhys, GCPhys));
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * Clear references to guest physical memory.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * @param pPool The pool.
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync * @param pPage The page.
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync * @param HCPhys The host physical address corresponding to the guest page.
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync * @param GCPhysHint The guest physical address which may corresponding to HCPhys.
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsyncstatic void pgmPoolTracDerefGCPhysHint(PPGMPOOL pPool, PPGMPOOLPAGE pPage, RTHCPHYS HCPhys, RTGCPHYS GCPhysHint)
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * Walk range list.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync PPGMRAMRANGE pRam = pPool->CTX_SUFF(pVM)->pgm.s.CTX_SUFF(pRamRanges);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync /* does it match? */
dea3e7faa80f4aab41e08945b9308fd2e3ffe7fcvboxsync if (PGM_PAGE_GET_HCPHYS(&pRam->aPages[iPage]) == HCPhys)
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync pgmTrackDerefGCPhys(pPool, pPage, &pRam->aPages[iPage]);
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync * Damn, the hint didn't work. We'll have to do an expensive linear search.
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync STAM_COUNTER_INC(&pPool->StatTrackLinearRamSearches);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pRam = pPool->CTX_SUFF(pVM)->pgm.s.CTX_SUFF(pRamRanges);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync while (iPage-- > 0)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (PGM_PAGE_GET_HCPHYS(&pRam->aPages[iPage]) == HCPhys)
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync Log4(("pgmPoolTracDerefGCPhysHint: Linear HCPhys=%RHp GCPhysHint=%RGp GCPhysReal=%RGp\n",
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync HCPhys, GCPhysHint, pRam->GCPhys + (iPage << PAGE_SHIFT)));
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync pgmTrackDerefGCPhys(pPool, pPage, &pRam->aPages[iPage]);
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync AssertFatalMsgFailed(("HCPhys=%RHp GCPhysHint=%RGp\n", HCPhys, GCPhysHint));
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync * Clear references to guest physical memory in a 32-bit / 32-bit page table.
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync * @param pPool The pool.
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync * @param pPage The page.
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync * @param pShwPT The shadow page table (mapping of the page).
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * @param pGstPT The guest page table.
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsyncDECLINLINE(void) pgmPoolTrackDerefPT32Bit32Bit(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PT pShwPT, PCX86PT pGstPT)
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pShwPT->a); i++)
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync Log4(("pgmPoolTrackDerefPT32Bit32Bit: i=%d pte=%RX32 hint=%RX32\n",
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync i, pShwPT->a[i].u & X86_PTE_PG_MASK, pGstPT->a[i].u & X86_PTE_PG_MASK));
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync pgmPoolTracDerefGCPhysHint(pPool, pPage, pShwPT->a[i].u & X86_PTE_PG_MASK, pGstPT->a[i].u & X86_PTE_PG_MASK);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Clear references to guest physical memory in a PAE / 32-bit page table.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * @param pPool The pool.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * @param pPage The page.
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync * @param pShwPT The shadow page table (mapping of the page).
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync * @param pGstPT The guest page table (just a half one).
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsyncDECLINLINE(void) pgmPoolTrackDerefPTPae32Bit(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PTPAE pShwPT, PCX86PT pGstPT)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pShwPT->a); i++)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Log4(("pgmPoolTrackDerefPTPae32Bit: i=%d pte=%RX32 hint=%RX32\n",
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync i, pShwPT->a[i].u & X86_PTE_PAE_PG_MASK, pGstPT->a[i].u & X86_PTE_PG_MASK));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pgmPoolTracDerefGCPhysHint(pPool, pPage, pShwPT->a[i].u & X86_PTE_PAE_PG_MASK, pGstPT->a[i].u & X86_PTE_PG_MASK);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * Clear references to guest physical memory in a PAE / PAE page table.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * @param pPool The pool.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * @param pPage The page.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * @param pShwPT The shadow page table (mapping of the page).
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * @param pGstPT The guest page table.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsyncDECLINLINE(void) pgmPoolTrackDerefPTPaePae(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PTPAE pShwPT, PCX86PTPAE pGstPT)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pShwPT->a); i++)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync Log4(("pgmPoolTrackDerefPTPaePae: i=%d pte=%RX32 hint=%RX32\n",
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync i, pShwPT->a[i].u & X86_PTE_PAE_PG_MASK, pGstPT->a[i].u & X86_PTE_PAE_PG_MASK));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync pgmPoolTracDerefGCPhysHint(pPool, pPage, pShwPT->a[i].u & X86_PTE_PAE_PG_MASK, pGstPT->a[i].u & X86_PTE_PAE_PG_MASK);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * Clear references to guest physical memory in a 32-bit / 4MB page table.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * @param pPool The pool.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * @param pPage The page.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * @param pShwPT The shadow page table (mapping of the page).
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsyncDECLINLINE(void) pgmPoolTrackDerefPT32Bit4MB(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PT pShwPT)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pShwPT->a); i++, GCPhys += PAGE_SIZE)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Log4(("pgmPoolTrackDerefPT32Bit4MB: i=%d pte=%RX32 GCPhys=%RGp\n",
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pgmPoolTracDerefGCPhys(pPool, pPage, pShwPT->a[i].u & X86_PTE_PG_MASK, GCPhys);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Clear references to guest physical memory in a PAE / 2/4MB page table.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * @param pPool The pool.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * @param pPage The page.
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync * @param pShwPT The shadow page table (mapping of the page).
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncDECLINLINE(void) pgmPoolTrackDerefPTPaeBig(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PTPAE pShwPT)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pShwPT->a); i++, GCPhys += PAGE_SIZE)
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync Log4(("pgmPoolTrackDerefPTPaeBig: i=%d pte=%RX64 hint=%RGp\n",
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync pgmPoolTracDerefGCPhys(pPool, pPage, pShwPT->a[i].u & X86_PTE_PAE_PG_MASK, GCPhys);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* PGMPOOL_WITH_GCPHYS_TRACKING */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Clear references to shadowed pages in a 32 bits page directory.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * @param pPool The pool.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * @param pPage The page.
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync * @param pShwPD The shadow page directory (mapping of the page).
687794577e2e35c3cae67e692a7f2130d1262a82vboxsyncDECLINLINE(void) pgmPoolTrackDerefPD(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PD pShwPD)
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pShwPD->a); i++)
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync PPGMPOOLPAGE pSubPage = (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, pShwPD->a[i].u & X86_PDE_PG_MASK);
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync pgmPoolTrackFreeUser(pPool, pSubPage, pPage->idx, i);
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync AssertFatalMsgFailed(("%x\n", pShwPD->a[i].u & X86_PDE_PG_MASK));
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync /** @todo 64-bit guests: have to ensure that we're not exhausting the dynamic mappings! */
45655563f818c5d5bbf4b3d14aa48cbd92a871f1vboxsync * Clear references to shadowed pages in a PAE (legacy or 64 bits) page directory.
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync * @param pPool The pool.
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync * @param pPage The page.
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync * @param pShwPD The shadow page directory (mapping of the page).
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsyncDECLINLINE(void) pgmPoolTrackDerefPDPae(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PDPAE pShwPD)
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pShwPD->a); i++)
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync PPGMPOOLPAGE pSubPage = (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, pShwPD->a[i].u & X86_PDE_PAE_PG_MASK);
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync pgmPoolTrackFreeUser(pPool, pSubPage, pPage->idx, i);
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync AssertFatalMsgFailed(("%RX64\n", pShwPD->a[i].u & X86_PDE_PAE_PG_MASK));
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync /** @todo 64-bit guests: have to ensure that we're not exhausting the dynamic mappings! */
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync * Clear references to shadowed pages in a 64-bit page directory pointer table.
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync * @param pPool The pool.
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync * @param pPage The page.
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync * @param pShwPDPT The shadow page directory pointer table (mapping of the page).
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsyncDECLINLINE(void) pgmPoolTrackDerefPDPT64Bit(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PDPT pShwPDPT)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync for (unsigned i = 0; i < RT_ELEMENTS(pShwPDPT->a); i++)
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync PPGMPOOLPAGE pSubPage = (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, pShwPDPT->a[i].u & X86_PDPE_PG_MASK);
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync pgmPoolTrackFreeUser(pPool, pSubPage, pPage->idx, i);
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync AssertFatalMsgFailed(("%RX64\n", pShwPDPT->a[i].u & X86_PDPE_PG_MASK));
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync /** @todo 64-bit guests: have to ensure that we're not exhausting the dynamic mappings! */
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync * Clear references to shadowed pages in a 64-bit level 4 page table.
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync * @param pPool The pool.
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync * @param pPage The page.
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * @param pShwPML4 The shadow page directory pointer table (mapping of the page).
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsyncDECLINLINE(void) pgmPoolTrackDerefPML464Bit(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PML4 pShwPML4)
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync for (unsigned i = 0; i < RT_ELEMENTS(pShwPML4->a); i++)
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync PPGMPOOLPAGE pSubPage = (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, pShwPML4->a[i].u & X86_PDPE_PG_MASK);
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync pgmPoolTrackFreeUser(pPool, pSubPage, pPage->idx, i);
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync AssertFatalMsgFailed(("%RX64\n", pShwPML4->a[i].u & X86_PML4E_PG_MASK));
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync /** @todo 64-bit guests: have to ensure that we're not exhausting the dynamic mappings! */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Clear references to shadowed pages in an EPT page table.
56484ba959c372f0196716100568e02412b0dbd5vboxsync * @param pPool The pool.
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync * @param pPage The page.
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync * @param pShwPML4 The shadow page directory pointer table (mapping of the page).
687794577e2e35c3cae67e692a7f2130d1262a82vboxsyncDECLINLINE(void) pgmPoolTrackDerefPTEPT(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PEPTPT pShwPT)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pShwPT->a); i++, GCPhys += PAGE_SIZE)
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync Log4(("pgmPoolTrackDerefPTEPT: i=%d pte=%RX64 GCPhys=%RX64\n",
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync i, pShwPT->a[i].u & EPT_PTE_PG_MASK, pPage->GCPhys));
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync pgmPoolTracDerefGCPhys(pPool, pPage, pShwPT->a[i].u & EPT_PTE_PG_MASK, GCPhys);
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync * Clear references to shadowed pages in an EPT page directory.
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync * @param pPool The pool.
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync * @param pPage The page.
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync * @param pShwPD The shadow page directory (mapping of the page).
687794577e2e35c3cae67e692a7f2130d1262a82vboxsyncDECLINLINE(void) pgmPoolTrackDerefPDEPT(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PEPTPD pShwPD)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pShwPD->a); i++)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync PPGMPOOLPAGE pSubPage = (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, pShwPD->a[i].u & EPT_PDE_PG_MASK);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pgmPoolTrackFreeUser(pPool, pSubPage, pPage->idx, i);
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync AssertFatalMsgFailed(("%RX64\n", pShwPD->a[i].u & EPT_PDE_PG_MASK));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /** @todo 64-bit guests: have to ensure that we're not exhausting the dynamic mappings! */
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync * Clear references to shadowed pages in an EPT page directory pointer table.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * @param pPool The pool.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * @param pPage The page.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * @param pShwPDPT The shadow page directory pointer table (mapping of the page).
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsyncDECLINLINE(void) pgmPoolTrackDerefPDPTEPT(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PEPTPDPT pShwPDPT)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pShwPDPT->a); i++)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync PPGMPOOLPAGE pSubPage = (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, pShwPDPT->a[i].u & EPT_PDPTE_PG_MASK);
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsync pgmPoolTrackFreeUser(pPool, pSubPage, pPage->idx, i);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AssertFatalMsgFailed(("%RX64\n", pShwPDPT->a[i].u & EPT_PDPTE_PG_MASK));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /** @todo 64-bit guests: have to ensure that we're not exhausting the dynamic mappings! */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Clears all references made by this page.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * This includes other shadow pages and GC physical addresses.
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync * @param pPool The pool.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * @param pPage The page.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncstatic void pgmPoolTrackDeref(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync * Map the shadow page and take action according to the page kind.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync void *pvShw = PGMPOOL_PAGE_2_PTR(pPool->CTX_SUFF(pVM), pPage);
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync STAM_PROFILE_START(&pPool->StatTrackDerefGCPhys, g);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync int rc = PGM_GCPHYS_2_PTR(pPool->CTX_SUFF(pVM), pPage->GCPhys, &pvGst); AssertReleaseRC(rc);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pgmPoolTrackDerefPT32Bit32Bit(pPool, pPage, (PX86PT)pvShw, (PCX86PT)pvGst);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync STAM_PROFILE_STOP(&pPool->StatTrackDerefGCPhys, g);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync STAM_PROFILE_START(&pPool->StatTrackDerefGCPhys, g);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync int rc = PGM_GCPHYS_2_PTR_EX(pPool->CTX_SUFF(pVM), pPage->GCPhys, &pvGst); AssertReleaseRC(rc);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pgmPoolTrackDerefPTPae32Bit(pPool, pPage, (PX86PTPAE)pvShw, (PCX86PT)pvGst);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync STAM_PROFILE_STOP(&pPool->StatTrackDerefGCPhys, g);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync STAM_PROFILE_START(&pPool->StatTrackDerefGCPhys, g);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync int rc = PGM_GCPHYS_2_PTR(pPool->CTX_SUFF(pVM), pPage->GCPhys, &pvGst); AssertReleaseRC(rc);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync pgmPoolTrackDerefPTPaePae(pPool, pPage, (PX86PTPAE)pvShw, (PCX86PTPAE)pvGst);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync STAM_PROFILE_STOP(&pPool->StatTrackDerefGCPhys, g);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync case PGMPOOLKIND_32BIT_PT_FOR_PHYS: /* treat it like a 4 MB page */
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync STAM_PROFILE_START(&pPool->StatTrackDerefGCPhys, g);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync pgmPoolTrackDerefPT32Bit4MB(pPool, pPage, (PX86PT)pvShw);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync STAM_PROFILE_STOP(&pPool->StatTrackDerefGCPhys, g);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync case PGMPOOLKIND_PAE_PT_FOR_PHYS: /* treat it like a 2 MB page */
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync STAM_PROFILE_START(&pPool->StatTrackDerefGCPhys, g);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync pgmPoolTrackDerefPTPaeBig(pPool, pPage, (PX86PTPAE)pvShw);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync STAM_PROFILE_STOP(&pPool->StatTrackDerefGCPhys, g);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync#else /* !PGMPOOL_WITH_GCPHYS_TRACKING */
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync#endif /* !PGMPOOL_WITH_GCPHYS_TRACKING */
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync pgmPoolTrackDerefPDPae(pPool, pPage, (PX86PDPAE)pvShw);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync pgmPoolTrackDerefPDPT64Bit(pPool, pPage, (PX86PDPT)pvShw);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync pgmPoolTrackDerefPML464Bit(pPool, pPage, (PX86PML4)pvShw);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync pgmPoolTrackDerefPTEPT(pPool, pPage, (PEPTPT)pvShw);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync pgmPoolTrackDerefPDEPT(pPool, pPage, (PEPTPD)pvShw);
#ifndef VBOX_WITH_PGMPOOL_PAGING_ONLY
case PGMPOOLKIND_ROOT_PDPT:
case PGMPOOLKIND_ROOT_NESTED:
#ifdef IN_RING3
#ifdef PGMPOOL_WITH_MONITORING
#ifdef PGMPOOL_WITH_USER_TRACKING
#ifdef PGMPOOL_WITH_CACHE
#ifdef PGMPOOL_WITH_USER_TRACKING
for (unsigned i = 0; i < cMaxUsers; i++)
#ifdef PGMPOOL_WITH_GCPHYS_TRACKING
pRam;
while (iPage-- > 0)
for (unsigned i = 0; i < cMaxPhysExts; i++)
#ifdef PGMPOOL_WITH_MONITORING
#ifdef PGMPOOL_WITH_CACHE
#ifdef PGMPOOL_WITH_MONITORING
# ifdef PGMPOOL_WITH_CACHE
#ifdef PGMPOOL_WITH_USER_TRACKING
#ifdef PGMPOOL_WITH_CACHE
* @retval VERR_PGM_POOL_CLEARED if the deregistration of the physical handler will cause a light weight pool flush.
Log(("pgmPoolFlushPage: special root page, rejected. enmKind=%d idx=%d\n", pPage->enmKind, pPage->idx));
return VINF_SUCCESS;
("Can't free the shadow CR3! (%RHp vs %RHp kind=%d\n", PGMGetHyperCR3(pPool->CTX_SUFF(pVM)), pPage->Core.Key, pPage->enmKind));
Log(("pgmPoolFlushPage: current active shadow CR3, rejected. enmKind=%d idx=%d\n", pPage->enmKind, pPage->idx));
return VINF_SUCCESS;
#ifdef PGMPOOL_WITH_USER_TRACKING
#ifdef PGMPOOL_WITH_CACHE
#ifdef PGMPOOL_WITH_MONITORING
return rc;
#ifdef PGMPOOL_WITH_USER_TRACKING
#ifdef PGMPOOL_WITH_CACHE
#ifdef IN_RING3
return rc;
return VINF_SUCCESS;
#ifdef PGMPOOL_WITH_CACHE
return VERR_PGM_POOL_FLUSHED;
int pgmPoolAlloc(PVM pVM, RTGCPHYS GCPhys, PGMPOOLKIND enmKind, uint16_t iUser, uint32_t iUserTable, PPPGMPOOLPAGE ppPage)
LogFlow(("pgmPoolAlloc: GCPhys=%RGp enmKind=%d iUser=%#x iUserTable=%#x\n", GCPhys, enmKind, iUser, iUserTable));
/** @todo CSAM/PGMPrefetchPage messes up here during CSAMR3CheckGates
* Assert(!(pVM->pgm.s.fSyncFlags & PGM_SYNC_CLEAR_PGM_POOL)); */
#ifdef PGMPOOL_WITH_CACHE
LogFlow(("pgmPoolAlloc: cached returns %Rrc *ppPage=%p:{.Key=%RHp, .idx=%d}\n", rc2, *ppPage, (*ppPage)->Core.Key, (*ppPage)->idx));
return rc2;
return rc;
pPool->cUsedPages++; /* physical handler registration / pgmPoolTrackFlushGCPhysPTsSlow requirement. */
#ifdef PGMPOOL_WITH_MONITORING
#ifdef PGMPOOL_WITH_USER_TRACKING
return rc3;
#ifdef VBOX_WITH_STATISTICS
LogFlow(("pgmPoolAlloc: returns %Rrc *ppPage=%p:{.Key=%RHp, .idx=%d, .fCached=%RTbool, .fMonitored=%RTbool}\n",
return rc;
return pPage;