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