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