PGMAllPool.cpp revision 248c616a220b4b7d67dee7b3d1dfb7b9ad09a107
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * PGM Shadow Page Pool.
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * Copyright (C) 2006-2007 Oracle Corporation
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/*******************************************************************************
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync* Header Files *
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync*******************************************************************************/
b74ca013e5f201a2dd371e6c438433ceac12af30vboxsync/*******************************************************************************
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync* Internal Functions *
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync*******************************************************************************/
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncDECLINLINE(unsigned) pgmPoolTrackGetShadowEntrySize(PGMPOOLKIND enmKind);
590bfe12ce22cd3716448fbb9f4dc51664bfe5e2vboxsyncDECLINLINE(unsigned) pgmPoolTrackGetGuestEntrySize(PGMPOOLKIND enmKind);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic void pgmPoolTrackDeref(PPGMPOOL pPool, PPGMPOOLPAGE pPage);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic int pgmPoolTrackAddUser(PPGMPOOL pPool, PPGMPOOLPAGE pPage, uint16_t iUser, uint32_t iUserTable);
223cf005b18af2c21352a70693ebaf0582f68ebcvboxsyncstatic void pgmPoolMonitorModifiedRemove(PPGMPOOL pPool, PPGMPOOLPAGE pPage);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncDECLEXPORT(int) pgmPoolAccessHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPHYS GCPhysFault, void *pvUser);
afed5ab737f4aacfae3fe73776f40e989190a7cavboxsyncstatic const char *pgmPoolPoolKindToStr(uint8_t enmKind);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync#if defined(VBOX_STRICT) && defined(PGMPOOL_WITH_OPTIMIZED_DIRTY_PT)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic void pgmPoolTrackCheckPTPaePae(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PTPAE pShwPT, PCX86PTPAE pGstPT);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncint pgmPoolTrackFlushGCPhysPTsSlow(PVM pVM, PPGMPAGE pPhysPage);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncPPGMPOOLPHYSEXT pgmPoolTrackPhysExtAlloc(PVM pVM, uint16_t *piPhysExt);
0174432b2b1a760b89840ba696f7ba51def65dddvboxsyncvoid pgmPoolTrackPhysExtFree(PVM pVM, uint16_t iPhysExt);
2daaccf68be3773aee600c5c3e48bcf5401418a6vboxsyncvoid pgmPoolTrackPhysExtFreeList(PVM pVM, uint16_t iPhysExt);
7666082b743c5e146a8cee6cc794ff4bc3fd0ffdvboxsync * Checks if the specified page pool kind is for a 4MB or 2MB guest page.
7666082b743c5e146a8cee6cc794ff4bc3fd0ffdvboxsync * @returns true if it's the shadow of a 4MB or 2MB guest page, otherwise false.
7666082b743c5e146a8cee6cc794ff4bc3fd0ffdvboxsync * @param enmKind The page kind.
590bfe12ce22cd3716448fbb9f4dc51664bfe5e2vboxsyncDECLINLINE(bool) pgmPoolIsBigPage(PGMPOOLKIND enmKind)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return true;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return false;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync/** @def PGMPOOL_PAGE_2_LOCKED_PTR
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Maps a pool page pool into the current context and lock it (RC only).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM The VM handle.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The pool page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @remark In RC this uses PGMGCDynMapHCPage(), so it will consume of the
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * small page window employeed by that function. Be careful.
22e281e75ed636601178296c6daebda8f1d17c59vboxsync * @remark There is no need to assert on the result.
22e281e75ed636601178296c6daebda8f1d17c59vboxsyncDECLINLINE(void *) PGMPOOL_PAGE_2_LOCKED_PTR(PVM pVM, PPGMPOOLPAGE pPage)
22e281e75ed636601178296c6daebda8f1d17c59vboxsync void *pv = pgmPoolMapPageInlined(&pVM->pgm.s, pPage);
22e281e75ed636601178296c6daebda8f1d17c59vboxsync /* Make sure the dynamic mapping will not be reused. */
22e281e75ed636601178296c6daebda8f1d17c59vboxsync# define PGMPOOL_PAGE_2_LOCKED_PTR(pVM, pPage) PGMPOOL_PAGE_2_PTR(pVM, pPage)
22e281e75ed636601178296c6daebda8f1d17c59vboxsync/** @def PGMPOOL_UNLOCK_PTR
22e281e75ed636601178296c6daebda8f1d17c59vboxsync * Unlock a previously locked dynamic caching (RC only).
22e281e75ed636601178296c6daebda8f1d17c59vboxsync * @returns VBox status code.
22e281e75ed636601178296c6daebda8f1d17c59vboxsync * @param pVM The VM handle.
22e281e75ed636601178296c6daebda8f1d17c59vboxsync * @param pPage The pool page.
22e281e75ed636601178296c6daebda8f1d17c59vboxsync * @remark In RC this uses PGMGCDynMapHCPage(), so it will consume of the
22e281e75ed636601178296c6daebda8f1d17c59vboxsync * small page window employeed by that function. Be careful.
22e281e75ed636601178296c6daebda8f1d17c59vboxsync * @remark There is no need to assert on the result.
22e281e75ed636601178296c6daebda8f1d17c59vboxsyncDECLINLINE(void) PGMPOOL_UNLOCK_PTR(PVM pVM, void *pvPage)
22e281e75ed636601178296c6daebda8f1d17c59vboxsync# define PGMPOOL_UNLOCK_PTR(pVM, pPage) do {} while (0)
22e281e75ed636601178296c6daebda8f1d17c59vboxsync * Flushes a chain of pages sharing the same access monitor.
22e281e75ed636601178296c6daebda8f1d17c59vboxsync * @returns VBox status code suitable for scheduling.
22e281e75ed636601178296c6daebda8f1d17c59vboxsync * @param pPool The pool.
c17f5c90f2cb60b38ecabebce128724c6ff2d036vboxsync * @param pPage A page in the chain.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncint pgmPoolMonitorChainFlush(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolMonitorChainFlush: Flush page %RGp type=%d\n", pPage->GCPhys, pPage->enmKind));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Find the list head.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Iterate the list flushing each shadow page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * 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.
3ecf9412133496b2aeb090cfd33a286404ec59fbvboxsync * @param pvDst Destination address
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pvSrc Source guest virtual address.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param GCPhysSrc The source guest physical address.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param cb Size of data to read
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncDECLINLINE(int) pgmPoolPhysSimpleReadGCPhys(PVM pVM, void *pvDst, CTXTYPE(RTGCPTR, RTHCPTR, RTGCPTR) pvSrc, RTGCPHYS GCPhysSrc, size_t cb)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync memcpy(pvDst, (RTHCPTR)((uintptr_t)pvSrc & ~(RTHCUINTPTR)(cb - 1)), cb);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* @todo in RC we could attempt to use the virtual address, although this can cause many faults (PAE Windows XP guest). */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return PGMPhysSimpleReadGCPhys(pVM, pvDst, GCPhysSrc & ~(RTGCPHYS)(cb - 1), cb);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Process shadow entries before they are changed by the guest.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * For PT entries we will clear them. For PD entries, we'll simply check
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * for mapping conflicts and set the SyncCR3 FF if found.
aaeb2e2f6ed5b164f1dec9a16a7adeb84f64cf31vboxsync * @param pVCpu VMCPU handle
223cf005b18af2c21352a70693ebaf0582f68ebcvboxsync * @param pPool The pool.
b74ca013e5f201a2dd371e6c438433ceac12af30vboxsync * @param pPage The head page.
b74ca013e5f201a2dd371e6c438433ceac12af30vboxsync * @param GCPhysFault The guest physical fault address.
b74ca013e5f201a2dd371e6c438433ceac12af30vboxsync * @param uAddress In R0 and GC this is the guest context fault address (flat).
b74ca013e5f201a2dd371e6c438433ceac12af30vboxsync * In R3 this is the host context 'fault' address.
b74ca013e5f201a2dd371e6c438433ceac12af30vboxsync * @param cbWrite Write size; might be zero if the caller knows we're not crossing entry boundaries
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncvoid pgmPoolMonitorChainChanging(PVMCPU pVCpu, PPGMPOOL pPool, PPGMPOOLPAGE pPage, RTGCPHYS GCPhysFault, CTXTYPE(RTGCPTR, RTHCPTR, RTGCPTR) pvAddress, unsigned cbWrite)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertMsg(pPage->iMonitoredPrev == NIL_PGMPOOL_IDX, ("%#x (idx=%#x)\n", pPage->iMonitoredPrev, pPage->idx));
576d4214137bce409cdcf01e8df4a0bca5e0b2d1vboxsync const unsigned off = GCPhysFault & PAGE_OFFSET_MASK;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolMonitorChainChanging: %RGv phys=%RGp cbWrite=%d\n", (RTGCPTR)(CTXTYPE(RTGCPTR, uintptr_t, RTGCPTR))pvAddress, GCPhysFault, cbWrite));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolMonitorChainChanging: page idx=%d phys=%RGp (next=%d) kind=%s\n", pPage->idx, pPage->GCPhys, pPage->iMonitoredNext, pgmPoolPoolKindToStr(pPage->enmKind), cbWrite));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,FaultPT));
3cbb4f9a6a320e58ed398ef7aaa004cc8727abc5vboxsync LogFlow(("PGMPOOLKIND_32BIT_PT_FOR_32BIT_PT iShw=%x\n", iShw));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync int rc = pgmPoolPhysSimpleReadGCPhys(pVM, &GstPte, pvAddress, GCPhysFault, sizeof(GstPte));
576d4214137bce409cdcf01e8df4a0bca5e0b2d1vboxsync 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));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* page/2 sized */
22e281e75ed636601178296c6daebda8f1d17c59vboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,FaultPT));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync const unsigned iShw = (off / sizeof(X86PTE)) & (X86_PG_PAE_ENTRIES - 1);
b978e5849454446957177fd47ee98609ab0457a6vboxsync LogFlow(("PGMPOOLKIND_PAE_PT_FOR_32BIT_PT iShw=%x\n", iShw));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync int rc = pgmPoolPhysSimpleReadGCPhys(pVM, &GstPte, pvAddress, GCPhysFault, sizeof(GstPte));
b74ca013e5f201a2dd371e6c438433ceac12af30vboxsync 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));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolMonitorChainChanging PAE for 32 bits: iGst=%x iShw=%x idx = %d page idx=%d\n", iGst, iShw, iShwPdpt, pPage->enmKind - PGMPOOLKIND_PAE_PD0_FOR_32BIT_PD));
247b55faa8d054157f2481e68caca36f4dc9542cvboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,FaultPD));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if (iShwPdpt == pPage->enmKind - (unsigned)PGMPOOLKIND_PAE_PD0_FOR_32BIT_PD)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned i = 0; i < 2; i++)
b74ca013e5f201a2dd371e6c438433ceac12af30vboxsync if ((uShw.pPDPae->a[iShw + i].u & (PGM_PDFLAGS_MAPPING | X86_PDE_P)) == (PGM_PDFLAGS_MAPPING | X86_PDE_P))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShwPdpt=%#x iShw=%#x!\n", iShwPdpt, iShw+i));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync# endif /* !IN_RING0 */
533ffcb943c4af2c5fe6385d816d0ba3eda9383bvboxsync LogFlow(("pgmPoolMonitorChainChanging: pae pd iShw=%#x: %RX64 -> freeing it!\n", iShw+i, uShw.pPDPae->a[iShw+i].u));
533ffcb943c4af2c5fe6385d816d0ba3eda9383bvboxsync /* paranoia / a bit assumptive. */
57399ab65e2825c324fb9dcb4642d4ae2c232509vboxsync if ((uShw.pPDPae->a[iShw2].u & (PGM_PDFLAGS_MAPPING | X86_PDE_P)) == (PGM_PDFLAGS_MAPPING | X86_PDE_P))
1843553dbdf4e46417158b4c6348c503adf10740vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShwPdpt=%#x iShw2=%#x!\n", iShwPdpt, iShw2));
806d0b554daa555364af5f87bc96eccbe760db7avboxsync# endif /* !IN_RING0 */
13ba5527caaa9b8c4fee29f22e374fa67c4c6f72vboxsync LogFlow(("pgmPoolMonitorChainChanging: pae pd iShw=%#x: %RX64 -> freeing it!\n", iShw2, uShw.pPDPae->a[iShw2].u));
ebbb1f6c7e8bae363a4efda4b35b58c8467d24bcvboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,FaultPT));
22e281e75ed636601178296c6daebda8f1d17c59vboxsync int rc = pgmPoolPhysSimpleReadGCPhys(pVM, &GstPte, pvAddress, GCPhysFault, sizeof(GstPte));
806d0b554daa555364af5f87bc96eccbe760db7avboxsync 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));
1843553dbdf4e46417158b4c6348c503adf10740vboxsync /* paranoia / a bit assumptive. */
1843553dbdf4e46417158b4c6348c503adf10740vboxsync const unsigned iShw2 = (off + cbWrite - 1) / sizeof(X86PTEPAE);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync int rc = pgmPoolPhysSimpleReadGCPhys(pVM, &GstPte, (RTHCPTR)((RTHCUINTPTR)pvAddress + sizeof(GstPte)), GCPhysFault + sizeof(GstPte), sizeof(GstPte));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync int rc = pgmPoolPhysSimpleReadGCPhys(pVM, &GstPte, pvAddress + sizeof(GstPte), GCPhysFault + sizeof(GstPte), sizeof(GstPte));
b978e5849454446957177fd47ee98609ab0457a6vboxsync 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));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync const unsigned iShw = off / sizeof(X86PTE); // ASSUMING 32-bit guest paging!
0e77737b0ba913683e614db11463b31ca67aacbevboxsync LogFlow(("pgmPoolMonitorChainChanging: PGMPOOLKIND_32BIT_PD %x\n", iShw));
3cbb4f9a6a320e58ed398ef7aaa004cc8727abc5vboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,FaultPD));
e9a217d585085a6a6d129d27ca0d96a1b8e6d0eevboxsync STAM_COUNTER_INC(&(pVCpu->pgm.s.StatRZGuestCR3WriteConflict));
2d53f6e472561965d363674e17f48d3bdffc24d3vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw=%#x!\n", iShw));
b74ca013e5f201a2dd371e6c438433ceac12af30vboxsync# endif /* !IN_RING0 */
b74ca013e5f201a2dd371e6c438433ceac12af30vboxsync# endif /* !IN_RING0 */
b74ca013e5f201a2dd371e6c438433ceac12af30vboxsync LogFlow(("pgmPoolMonitorChainChanging: 32 bit pd iShw=%#x: %RX64 -> freeing it!\n", iShw, uShw.pPD->a[iShw].u));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* paranoia / a bit assumptive. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync const unsigned iShw2 = (off + cbWrite - 1) / sizeof(X86PTE);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_COUNTER_INC(&(pVCpu->pgm.s.StatRZGuestCR3WriteConflict));
e0b9d3c357adf9b7d05f55540e86f22943fc4b23vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw2=%#x!\n", iShw2));
806d0b554daa555364af5f87bc96eccbe760db7avboxsync# endif /* !IN_RING0 */
13ba5527caaa9b8c4fee29f22e374fa67c4c6f72vboxsync# endif /* !IN_RING0 */
806d0b554daa555364af5f87bc96eccbe760db7avboxsync LogFlow(("pgmPoolMonitorChainChanging: 32 bit pd iShw=%#x: %RX64 -> freeing it!\n", iShw2, uShw.pPD->a[iShw2].u));
d98e61ba075ed7d0b567a5d884bc85d643fe3de7vboxsync#if 0 /* useful when running PGMAssertCR3(), a bit too troublesome for general use (TLBs). */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolMonitorChainChanging: iShw=%#x: %RX32 -> freeing it!\n", iShw, uShw.pPD->a[iShw].u));
e08de24d4792d31b7f2aac29db5cb8840d940009vboxsync# ifdef IN_RC /* TLB load - we're pushing things a bit... */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolFree(pVM, uShw.pPD->a[iShw].u & X86_PDE_PG_MASK, pPage->idx, iShw);
13ba5527caaa9b8c4fee29f22e374fa67c4c6f72vboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,FaultPD));
806d0b554daa555364af5f87bc96eccbe760db7avboxsync STAM_COUNTER_INC(&(pVCpu->pgm.s.StatRZGuestCR3WriteConflict));
22e281e75ed636601178296c6daebda8f1d17c59vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw=%#x!\n", iShw));
806d0b554daa555364af5f87bc96eccbe760db7avboxsync#endif /* !IN_RING0 */
806d0b554daa555364af5f87bc96eccbe760db7avboxsync * Causes trouble when the guest uses a PDE to refer to the whole page table level
806d0b554daa555364af5f87bc96eccbe760db7avboxsync * structure. (Invalidate here; faults later on when it tries to change the page
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * table entries -> recheck; probably only applies to the RC case.)
e0b9d3c357adf9b7d05f55540e86f22943fc4b23vboxsync# endif /* !IN_RING0 */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolMonitorChainChanging: pae pd iShw=%#x: %RX64 -> freeing it!\n", iShw, uShw.pPDPae->a[iShw].u));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* paranoia / a bit assumptive. */
3dde2f85d4cf477621a3128887a2c08a8bca7c01vboxsync const unsigned iShw2 = (off + cbWrite - 1) / sizeof(X86PDEPAE);
806d0b554daa555364af5f87bc96eccbe760db7avboxsync STAM_COUNTER_INC(&(pVCpu->pgm.s.StatRZGuestCR3WriteConflict));
79b24ef0ab7cd4a03a3571b3954c52ab8b573137vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw2=%#x!\n", iShw2));
3cac8f8c6923a3a89ecfccda5e89ad75f48658e0vboxsync#endif /* !IN_RING0 */
03319aeaef07ef63a404237f2cb56199131f4a03vboxsync# endif /* !IN_RING0 */
1157941288c9533575a655c660af55d13da31eefvboxsync LogFlow(("pgmPoolMonitorChainChanging: pae pd iShw2=%#x: %RX64 -> freeing it!\n", iShw2, uShw.pPDPae->a[iShw2].u));
3cbb4f9a6a320e58ed398ef7aaa004cc8727abc5vboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,FaultPDPT));
e08de24d4792d31b7f2aac29db5cb8840d940009vboxsync * Hopefully this doesn't happen very often:
79b24ef0ab7cd4a03a3571b3954c52ab8b573137vboxsync * - touching unused parts of the page
e08de24d4792d31b7f2aac29db5cb8840d940009vboxsync * - messing with the bits of pd pointers without changing the physical address
5e797edc29f96c8367de4fbf5874171c24a89ba7vboxsync /* PDPT roots are not page aligned; 32 byte only! */
13ba5527caaa9b8c4fee29f22e374fa67c4c6f72vboxsync const unsigned offPdpt = GCPhysFault - pPage->GCPhys;
22e281e75ed636601178296c6daebda8f1d17c59vboxsync if (iShw < X86_PG_PAE_PDPE_ENTRIES) /* don't use RT_ELEMENTS(uShw.pPDPT->a), because that's for long mode only */
13ba5527caaa9b8c4fee29f22e374fa67c4c6f72vboxsync STAM_COUNTER_INC(&(pVCpu->pgm.s.StatRZGuestCR3WriteConflict));
57399ab65e2825c324fb9dcb4642d4ae2c232509vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected pdpt conflict at iShw=%#x!\n", iShw));
3dde2f85d4cf477621a3128887a2c08a8bca7c01vboxsync# endif /* !IN_RING0 */
8e8844a522f5d335f177a0313b03067d79cce201vboxsync# endif /* !IN_RING0 */
6ae4b1c72625a8e5c369effea7f018b578d733c4vboxsync LogFlow(("pgmPoolMonitorChainChanging: pae pdpt iShw=%#x: %RX64 -> freeing it!\n", iShw, uShw.pPDPT->a[iShw].u));
b978e5849454446957177fd47ee98609ab0457a6vboxsync /* paranoia / a bit assumptive. */
7082d29724f6c3788977a51591b0379fd3acbf72vboxsync const unsigned iShw2 = (offPdpt + cbWrite - 1) / sizeof(X86PDPE);
f9147fe1eaa4e35287f8f39282c7f92f0d7de0b7vboxsync STAM_COUNTER_INC(&(pVCpu->pgm.s.StatRZGuestCR3WriteConflict));
f827fea1108b8f8a1a5f63318f6ec3cf4a9e7010vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw2=%#x!\n", iShw2));
42c1972c22e09797b4b24afbd0ec114ed076c37cvboxsync# endif /* !IN_RING0 */
806d0b554daa555364af5f87bc96eccbe760db7avboxsync# endif /* !IN_RING0 */
13ba5527caaa9b8c4fee29f22e374fa67c4c6f72vboxsync LogFlow(("pgmPoolMonitorChainChanging: pae pdpt iShw=%#x: %RX64 -> freeing it!\n", iShw2, uShw.pPDPT->a[iShw2].u));
6f0193f5a9287559d34a75f438c2682d8fb08038vboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,FaultPD));
f9147fe1eaa4e35287f8f39282c7f92f0d7de0b7vboxsync Assert(!(uShw.pPDPae->a[iShw].u & PGM_PDFLAGS_MAPPING));
13ba5527caaa9b8c4fee29f22e374fa67c4c6f72vboxsync LogFlow(("pgmPoolMonitorChainChanging: pae pd iShw=%#x: %RX64 -> freeing it!\n", iShw, uShw.pPDPae->a[iShw].u));
e149c362e69e5f0bbd82da11fd8163b2d29c3a72vboxsync /* paranoia / a bit assumptive. */
6f0193f5a9287559d34a75f438c2682d8fb08038vboxsync const unsigned iShw2 = (off + cbWrite - 1) / sizeof(X86PDEPAE);
6f0193f5a9287559d34a75f438c2682d8fb08038vboxsync Assert(!(uShw.pPDPae->a[iShw2].u & PGM_PDFLAGS_MAPPING));
6f0193f5a9287559d34a75f438c2682d8fb08038vboxsync LogFlow(("pgmPoolMonitorChainChanging: pae pd iShw2=%#x: %RX64 -> freeing it!\n", iShw2, uShw.pPDPae->a[iShw2].u));
65b61798a61dd4c32cce448db1dac70bba8d5cf5vboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,FaultPDPT));
22e281e75ed636601178296c6daebda8f1d17c59vboxsync * Hopefully this doesn't happen very often:
65b61798a61dd4c32cce448db1dac70bba8d5cf5vboxsync * - messing with the bits of pd pointers without changing the physical address
13ba5527caaa9b8c4fee29f22e374fa67c4c6f72vboxsync LogFlow(("pgmPoolMonitorChainChanging: pdpt iShw=%#x: %RX64 -> freeing it!\n", iShw, uShw.pPDPT->a[iShw].u));
13ba5527caaa9b8c4fee29f22e374fa67c4c6f72vboxsync pgmPoolFree(pVM, uShw.pPDPT->a[iShw].u & X86_PDPE_PG_MASK, pPage->idx, iShw);
65b61798a61dd4c32cce448db1dac70bba8d5cf5vboxsync /* paranoia / a bit assumptive. */
e08de24d4792d31b7f2aac29db5cb8840d940009vboxsync const unsigned iShw2 = (off + cbWrite - 1) / sizeof(X86PDPE);
22e281e75ed636601178296c6daebda8f1d17c59vboxsync LogFlow(("pgmPoolMonitorChainChanging: pdpt iShw2=%#x: %RX64 -> freeing it!\n", iShw2, uShw.pPDPT->a[iShw2].u));
65b61798a61dd4c32cce448db1dac70bba8d5cf5vboxsync pgmPoolFree(pVM, uShw.pPDPT->a[iShw2].u & X86_PDPE_PG_MASK, pPage->idx, iShw2);
6ae4b1c72625a8e5c369effea7f018b578d733c4vboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,FaultPML4));
65b61798a61dd4c32cce448db1dac70bba8d5cf5vboxsync * Hopefully this doesn't happen very often:
65b61798a61dd4c32cce448db1dac70bba8d5cf5vboxsync * - messing with the bits of pd pointers without changing the physical address
3cac8f8c6923a3a89ecfccda5e89ad75f48658e0vboxsync LogFlow(("pgmPoolMonitorChainChanging: pml4 iShw=%#x: %RX64 -> freeing it!\n", iShw, uShw.pPML4->a[iShw].u));
3cac8f8c6923a3a89ecfccda5e89ad75f48658e0vboxsync pgmPoolFree(pVM, uShw.pPML4->a[iShw].u & X86_PML4E_PG_MASK, pPage->idx, iShw);
e0b9d3c357adf9b7d05f55540e86f22943fc4b23vboxsync /* paranoia / a bit assumptive. */
3dde2f85d4cf477621a3128887a2c08a8bca7c01vboxsync const unsigned iShw2 = (off + cbWrite - 1) / sizeof(X86PML4E);
22e281e75ed636601178296c6daebda8f1d17c59vboxsync LogFlow(("pgmPoolMonitorChainChanging: pml4 iShw2=%#x: %RX64 -> freeing it!\n", iShw2, uShw.pPML4->a[iShw2].u));
6ae4b1c72625a8e5c369effea7f018b578d733c4vboxsync pgmPoolFree(pVM, uShw.pPML4->a[iShw2].u & X86_PML4E_PG_MASK, pPage->idx, iShw2);
3dde2f85d4cf477621a3128887a2c08a8bca7c01vboxsync#endif /* IN_RING0 */
3dde2f85d4cf477621a3128887a2c08a8bca7c01vboxsync AssertFatalMsgFailed(("enmKind=%d\n", pPage->enmKind));
3cac8f8c6923a3a89ecfccda5e89ad75f48658e0vboxsync * Checks if a access could be a fork operation in progress.
585f64d6f624f9e683321dabeb21b0eb2e6aa473vboxsync * Meaning, that the guest is setting up the parent process for Copy-On-Write.
e0b9d3c357adf9b7d05f55540e86f22943fc4b23vboxsync * @returns true if it's likly that we're forking, otherwise false.
585f64d6f624f9e683321dabeb21b0eb2e6aa473vboxsync * @param pPool The pool.
22e281e75ed636601178296c6daebda8f1d17c59vboxsync * @param pDis The disassembled instruction.
585f64d6f624f9e683321dabeb21b0eb2e6aa473vboxsync * @param offFault The access offset.
585f64d6f624f9e683321dabeb21b0eb2e6aa473vboxsyncDECLINLINE(bool) pgmPoolMonitorIsForking(PPGMPOOL pPool, PDISCPUSTATE pDis, unsigned offFault)
6ae4b1c72625a8e5c369effea7f018b578d733c4vboxsync * i386 linux is using btr to clear X86_PTE_RW.
585f64d6f624f9e683321dabeb21b0eb2e6aa473vboxsync * The functions involved are (2.6.16 source inspection):
585f64d6f624f9e683321dabeb21b0eb2e6aa473vboxsync * clear_bit
3cbb4f9a6a320e58ed398ef7aaa004cc8727abc5vboxsync * ptep_set_wrprotect
585f64d6f624f9e683321dabeb21b0eb2e6aa473vboxsync * copy_one_pte
e08de24d4792d31b7f2aac29db5cb8840d940009vboxsync * copy_pte_range
585f64d6f624f9e683321dabeb21b0eb2e6aa473vboxsync * copy_pmd_range
e08de24d4792d31b7f2aac29db5cb8840d940009vboxsync * copy_pud_range
585f64d6f624f9e683321dabeb21b0eb2e6aa473vboxsync * copy_page_range
6ae4b1c72625a8e5c369effea7f018b578d733c4vboxsync * copy_process
585f64d6f624f9e683321dabeb21b0eb2e6aa473vboxsync /** @todo Validate that the bit index is X86_PTE_RW. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,Fork));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return true;
22e281e75ed636601178296c6daebda8f1d17c59vboxsync return false;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Determine whether the page is likely to have been reused.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns true if we consider the page as being reused for a different purpose.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns false if we consider it to still be a paging page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM VM Handle.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVCpu VMCPU Handle.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pRegFrame Trap register frame.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pDis The disassembly info for the faulting instruction.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * @param pvFault The fault address.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @remark The REP prefix check is left to the caller because of STOSD/W.
3cbb4f9a6a320e58ed398ef7aaa004cc8727abc5vboxsyncDECLINLINE(bool) pgmPoolMonitorIsReused(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame, PDISCPUSTATE pDis, RTGCPTR pvFault)
3cbb4f9a6a320e58ed398ef7aaa004cc8727abc5vboxsync /** @todo could make this general, faulting close to rsp should be a 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;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("Reused instr %RGv %d at %RGv param1.flags=%x param1.reg=%d\n", pRegFrame->rip, pDis->pCurInstr->opcode, pvFault, pDis->param1.flags, pDis->param1.base.reg_gen));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Non-supervisor mode write means it's used for something else. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return true;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* call implies the actual push of the return address faulted */
5b6e2c9a765c3c72295acc15791af8a700746956vboxsync return true;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return true;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return true;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return true;
e17bd6c32a8dd64f2d42838f9028216465e2caf0vboxsync return true;
3cbb4f9a6a320e58ed398ef7aaa004cc8727abc5vboxsync return true;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync case OP_MOVNTDQ: /* solaris - hwblkclr & hwblkpagecopy */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return true;
08bc90fc2848c80bf8270bedc883745b8398e186vboxsync return true;
e17bd6c32a8dd64f2d42838f9028216465e2caf0vboxsync return false;
5ace91141404400247438502a84a418fba00c8cfvboxsync return true;
5ace91141404400247438502a84a418fba00c8cfvboxsync return false;
49748bb305bd71f672cd083af208f4bb08c5d6abvboxsync * Flushes the page being accessed.
49748bb305bd71f672cd083af208f4bb08c5d6abvboxsync * @returns VBox status code suitable for scheduling.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM The VM handle.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVCpu The VMCPU handle.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The pool page (head).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pDis 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, PVMCPU pVCpu, PPGMPOOL pPool, PPGMPOOLPAGE pPage, PDISCPUSTATE pDis,
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, RTGCPTR pvFault)
b9ca93dd1ad44cb8b27679dc5624be2f7b7f7af5vboxsync * First, do the flushing.
7c3417bbf525c03163d54d151a277a981d5d61b6vboxsync * Emulate the instruction (xp/w2k problem, requires pc/cr2/sp detection). Must do this in raw mode (!); XP boot will fail otherwise
8b984478b755f4d3091b977d9beac9fb7434279fvboxsync int rc2 = EMInterpretInstructionCPUEx(pVM, pVCpu, pDis, pRegFrame, pvFault, &cbWritten, EMCODETYPE_ALL);
e9a217d585085a6a6d129d27ca0d96a1b8e6d0eevboxsync LogFlow(("pgmPoolAccessHandlerPTWorker: Interpretation failed for patch code %04x:%RGv, ignoring.\n",
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync STAM_COUNTER_INC(&pPool->StatMonitorRZIntrFailPatch2);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,EmulateInstr));
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync LogFlow(("pgmPoolAccessHandlerPT: returns %Rrc (flushed)\n", rc));
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync * Handles the STOSD write accesses.
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync * @returns VBox status code suitable for scheduling.
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync * @param pVM The VM handle.
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync * @param pPool The pool.
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync * @param pPage The pool page (head).
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync * @param pDis The disassembly of the write instruction.
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync * @param pRegFrame The trap register frame.
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync * @param GCPhysFault The fault address as guest physical address.
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync * @param pvFault The fault address.
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsyncDECLINLINE(int) pgmPoolAccessHandlerSTOSD(PVM pVM, PPGMPOOL pPool, PPGMPOOLPAGE pPage, PDISCPUSTATE pDis,
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, RTGCPTR pvFault)
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync Assert(pDis->mode == CPUMODE_32BIT || pDis->mode == CPUMODE_64BIT);
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync * Increment the modification counter and insert it into the list
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync * of modified pages the first time.
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync * Execute REP STOSD.
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync * This ASSUMES that we're not invoked by Trap0e on in a out-of-sync
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync * write situation, meaning that it's safe to write here.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync uint32_t iPrevSubset = PGMDynMapPushAutoSubset(pVCpu);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolMonitorChainChanging(pVCpu, pPool, pPage, GCPhysFault, (RTGCPTR)pu32, uIncrement);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolMonitorChainChanging(pVCpu, pPool, pPage, GCPhysFault, (RTGCPTR)pu32, uIncrement);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PGMPhysSimpleWriteGCPhys(pVM, GCPhysFault, &pRegFrame->rax, uIncrement);
09e2f92b8f54aa362088e216007b53ecdb42e283vboxsync * Handles the simple write accesses.
5ace91141404400247438502a84a418fba00c8cfvboxsync * @returns VBox status code suitable for scheduling.
3123bb2477edc752585e4bbd8e4cfedaf87997d1vboxsync * @param pVM The VM handle.
247b55faa8d054157f2481e68caca36f4dc9542cvboxsync * @param pVCpu The VMCPU handle.
247b55faa8d054157f2481e68caca36f4dc9542cvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The pool page (head).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pDis 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.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pfReused Reused state (out)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncDECLINLINE(int) pgmPoolAccessHandlerSimple(PVM pVM, PVMCPU pVCpu, PPGMPOOL pPool, PPGMPOOLPAGE pPage, PDISCPUSTATE pDis,
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, RTGCPTR pvFault, bool *pfReused)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Increment the modification counter and insert it into the list
0975ae0a0fb615c945150c48e4a73187c1f4f84dvboxsync * of modified pages the first time.
42c1972c22e09797b4b24afbd0ec114ed076c37cvboxsync * Clear all the pages. ASSUMES that pvFault is readable.
42c1972c22e09797b4b24afbd0ec114ed076c37cvboxsync uint32_t iPrevSubset = PGMDynMapPushAutoSubset(pVCpu);
0975ae0a0fb615c945150c48e4a73187c1f4f84dvboxsync pgmPoolMonitorChainChanging(pVCpu, pPool, pPage, GCPhysFault, pvFault, DISGetParamSize(pDis, &pDis->param1));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolMonitorChainChanging(pVCpu, pPool, pPage, GCPhysFault, pvFault, DISGetParamSize(pDis, &pDis->param1));
09e2f92b8f54aa362088e216007b53ecdb42e283vboxsync * Interpret the instruction.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync int rc = EMInterpretInstructionCPUEx(pVM, pVCpu, pDis, pRegFrame, pvFault, &cb, EMCODETYPE_ALL);
688b55d5387d8b7c508d30141fe1a96eadecb988vboxsync LogFlow(("pgmPoolAccessHandlerPTWorker: Interpretation failed for %04x:%RGv - opcode=%d\n",
5cf54b3ffeb7ee90685dcaec329ef71a729f5947vboxsync pRegFrame->cs, (RTGCPTR)pRegFrame->rip, pDis->pCurInstr->opcode));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,EmulateInstr));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync#if 0 /* experimental code */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync int rc = pgmPoolPhysSimpleReadGCPhys(pVM, &GstPte, pvFault, GCPhysFault, sizeof(GstPte));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Check the new value written by the guest. If present and with a bogus physical address, then
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * it's fairly safe to assume the guest is reusing the PT.
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync int rc = PGMPhysGCPhys2HCPhys(pVM, GstPte.u & X86_PTE_PAE_PG_MASK, &HCPhys);
0975ae0a0fb615c945150c48e4a73187c1f4f84dvboxsync LogFlow(("pgmPoolAccessHandlerSimple: returns %Rrc cb=%d\n", rc, cb));
3cbb4f9a6a320e58ed398ef7aaa004cc8727abc5vboxsync * \#PF Handler callback for PT write accesses.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code (appropriate for GC return).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM VM Handle.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param uErrorCode CPU Error code.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pRegFrame Trap register frame.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * NULL on DMA and other non CPU access.
3cbb4f9a6a320e58ed398ef7aaa004cc8727abc5vboxsync * @param pvFault The fault address (cr2).
1a25adaca81841abf5e6cdfed02eaff64941357dvboxsync * @param GCPhysFault The GC physical address corresponding to pvFault.
3cbb4f9a6a320e58ed398ef7aaa004cc8727abc5vboxsync * @param pvUser User argument.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncDECLEXPORT(int) pgmPoolAccessHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPHYS GCPhysFault, void *pvUser)
3cbb4f9a6a320e58ed398ef7aaa004cc8727abc5vboxsync STAM_PROFILE_START(&pVM->pgm.s.CTX_SUFF(pPool)->CTX_SUFF_Z(StatMonitor), a);
036d626c5d4722da925dc8292f9248a5e09b4588vboxsync bool fForcedFlush = false;
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync LogFlow(("pgmPoolAccessHandler: pvFault=%RGv pPage=%p:{.idx=%d} GCPhysFault=%RGp\n", pvFault, pPage, pPage->idx, GCPhysFault));
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync if (PHYS_PAGE_ADDRESS(GCPhysFault) != PHYS_PAGE_ADDRESS(pPage->GCPhys))
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync /* Pool page changed while we were waiting for the lock; ignore. */
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync Log(("CPU%d: pgmPoolAccessHandler pgm pool page for %RGp changed (to %RGp) while waiting!\n", pVCpu->idCpu, PHYS_PAGE_ADDRESS(GCPhysFault), PHYS_PAGE_ADDRESS(pPage->GCPhys)));
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync STAM_PROFILE_STOP_EX(&pVM->pgm.s.CTX_SUFF(pPool)->CTX_SUFF_Z(StatMonitor), &pPool->CTX_MID_Z(StatMonitor,Handled), a);
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync return VINF_SUCCESS; /* SMP guest case where we were blocking on the pgm lock while the same page was being marked dirty. */
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync#if 0 /* test code defined(VBOX_STRICT) && defined(PGMPOOL_WITH_OPTIMIZED_DIRTY_PT) */
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync if (pPage->enmKind == PGMPOOLKIND_PAE_PT_FOR_PAE_PT)
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync void *pvShw = PGMPOOL_PAGE_2_LOCKED_PTR(pPool->CTX_SUFF(pVM), pPage);
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync int rc = PGM_GCPHYS_2_PTR(pPool->CTX_SUFF(pVM), pPage->GCPhys, &pvGst); AssertReleaseRC(rc);
036d626c5d4722da925dc8292f9248a5e09b4588vboxsync pgmPoolTrackCheckPTPaePae(pPool, pPage, (PX86PTPAE)pvShw, (PCX86PTPAE)pvGst);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Disassemble the faulting instruction.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync int rc = EMInterpretDisasOne(pVM, pVCpu, pRegFrame, pDis, NULL);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertMsg(rc == VERR_PAGE_NOT_PRESENT || rc == VERR_PAGE_TABLE_NOT_PRESENT, ("Unexpected rc %d\n", rc));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * We should ALWAYS have the list head as user parameter. This
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * is because we use that page to record the changes.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Maximum nr of modifications depends on the page type. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if (pPage->enmKind == PGMPOOLKIND_PAE_PT_FOR_PAE_PT)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Incremental page table updates should weigh more than random ones.
5b6e2c9a765c3c72295acc15791af8a700746956vboxsync * (Only applies when started from offset 0)
42c1972c22e09797b4b24afbd0ec114ed076c37cvboxsync if ( pPage->pvLastAccessHandlerRip >= pRegFrame->rip - 0x40 /* observed loops in Windows 7 x64 */
5ace91141404400247438502a84a418fba00c8cfvboxsync && pPage->pvLastAccessHandlerRip < pRegFrame->rip + 0x40
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync && pvFault == (pPage->pvLastAccessHandlerFault + pDis->param1.size)
42c1972c22e09797b4b24afbd0ec114ed076c37cvboxsync && pVCpu->pgm.s.cPoolAccessHandler == (pPage->cLastAccessHandlerCount + 1))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log(("Possible page reuse cMods=%d -> %d (locked=%d type=%s)\n", pPage->cModifications, pPage->cModifications * 2, pgmPoolIsPageLocked(&pVM->pgm.s, pPage), pgmPoolPoolKindToStr(pPage->enmKind)));
6778b34cb96bef0fef23ebc461eb6a429d2907c5vboxsync pPage->cLastAccessHandlerCount = pVCpu->pgm.s.cPoolAccessHandler;
6778b34cb96bef0fef23ebc461eb6a429d2907c5vboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,FlushReinit));
614cbe11a7e5588dc8d369e223174b1441a09359vboxsync Log(("Mod overflow %RGv cMods=%d (locked=%d type=%s)\n", pvFault, pPage->cModifications, pgmPoolIsPageLocked(&pVM->pgm.s, pPage), pgmPoolPoolKindToStr(pPage->enmKind)));
614cbe11a7e5588dc8d369e223174b1441a09359vboxsync * Check if it's worth dealing with.
614cbe11a7e5588dc8d369e223174b1441a09359vboxsync bool fReused = false;
614cbe11a7e5588dc8d369e223174b1441a09359vboxsync if ( ( pPage->cModifications < cMaxModifications /** @todo #define */ /** @todo need to check that it's not mapping EIP. */ /** @todo adjust this! */
614cbe11a7e5588dc8d369e223174b1441a09359vboxsync && !(fReused = pgmPoolMonitorIsReused(pVM, pVCpu, pRegFrame, pDis, pvFault))
614cbe11a7e5588dc8d369e223174b1441a09359vboxsync && !pgmPoolMonitorIsForking(pPool, pDis, GCPhysFault & PAGE_OFFSET_MASK))
b5b12033c1f7eaf82b038f06e2b9e464b9ddd8d2vboxsync * Simple instructions, no REP prefix.
d4b98dbce4cf7b3694b62d62a47553d399718dccvboxsync rc = pgmPoolAccessHandlerSimple(pVM, pVCpu, pPool, pPage, pDis, pRegFrame, GCPhysFault, pvFault, &fReused);
97b2abd2828499b2f4c2d5721952c9570ced1ebcvboxsync /* A mov instruction to change the first page table entry will be remembered so we can detect
97b2abd2828499b2f4c2d5721952c9570ced1ebcvboxsync * full page table changes early on. This will reduce the amount of unnecessary traps we'll take.
fd69ca9bd8b533bfa9ade45c1c2ff3116854e84avboxsync && !pPage->cLocked /* only applies to unlocked pages as we can't free locked ones (e.g. cr3 root). */
b978e5849454446957177fd47ee98609ab0457a6vboxsync pPage->cLastAccessHandlerCount = pVCpu->pgm.s.cPoolAccessHandler;
b978e5849454446957177fd47ee98609ab0457a6vboxsync /* Make sure we don't kick out a page too quickly. */
5ace91141404400247438502a84a418fba00c8cfvboxsync /* ignore the 2nd write to this page table entry. */
5ace91141404400247438502a84a418fba00c8cfvboxsync pPage->cLastAccessHandlerCount = pVCpu->pgm.s.cPoolAccessHandler;
5ace91141404400247438502a84a418fba00c8cfvboxsync STAM_PROFILE_STOP_EX(&pVM->pgm.s.CTX_SUFF(pPool)->CTX_SUFF_Z(StatMonitor), &pPool->CTX_MID_Z(StatMonitor,Handled), a);
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * Windows is frequently doing small memset() operations (netio test 4k+).
5ace91141404400247438502a84a418fba00c8cfvboxsync * We have to deal with these or we'll kill the cache and performance.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync bool fValidStosd = false;
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync && pRegFrame->ecx * 4 <= PAGE_SIZE - ((uintptr_t)pvFault & PAGE_OFFSET_MASK)
f8b934f4817639cddebe4d3c2ae25d39a91fe448vboxsync && (pRegFrame->eax == 0 || pRegFrame->eax == 0x80) /* the two values observed. */
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync && pRegFrame->rcx * 8 <= PAGE_SIZE - ((uintptr_t)pvFault & PAGE_OFFSET_MASK)
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync && (pRegFrame->rax == 0 || pRegFrame->rax == 0x80) /* the two values observed. */
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync rc = pgmPoolAccessHandlerSTOSD(pVM, pPool, pPage, pDis, pRegFrame, GCPhysFault, pvFault);
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync STAM_PROFILE_STOP_EX(&pVM->pgm.s.CTX_SUFF(pPool)->CTX_SUFF_Z(StatMonitor), &pPool->CTX_MID_Z(StatMonitor,RepStosd), a);
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync /* REP prefix, don't bother. */
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,RepPrefix));
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync Log4(("pgmPoolAccessHandler: eax=%#x ecx=%#x edi=%#x esi=%#x rip=%RGv opcode=%d prefix=%#x\n",
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync pRegFrame->eax, pRegFrame->ecx, pRegFrame->edi, pRegFrame->esi, (RTGCPTR)pRegFrame->rip, pDis->pCurInstr->opcode, pDis->prefix));
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync#if defined(PGMPOOL_WITH_OPTIMIZED_DIRTY_PT) && defined(IN_RING0)
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync /* E.g. Windows 7 x64 initializes page tables and touches some pages in the table during the process. This
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync * leads to pgm pool trashing and an excessive amount of write faults due to page monitoring.
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync || ( !pgmPoolMonitorIsReused(pVM, pVCpu, pRegFrame, pDis, pvFault)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync && !pgmPoolMonitorIsForking(pPool, pDis, GCPhysFault & PAGE_OFFSET_MASK))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Flush any monitored duplicates as we will disable write protection. */
09e2f92b8f54aa362088e216007b53ecdb42e283vboxsync /* Find the monitor head. */
28c928d1100d3b6a6d3506224cae25ad04732f73vboxsync while (pPageHead->iMonitoredPrev != NIL_PGMPOOL_IDX)
09e2f92b8f54aa362088e216007b53ecdb42e283vboxsync pPageHead = &pPool->aPages[pPageHead->iMonitoredPrev];
09e2f92b8f54aa362088e216007b53ecdb42e283vboxsync Log(("Flush duplicate page idx=%d GCPhys=%RGp type=%s\n", pPageHead->idx, pPageHead->GCPhys, pgmPoolPoolKindToStr(pPageHead->enmKind)));
09e2f92b8f54aa362088e216007b53ecdb42e283vboxsync /* The flushing above might fail for locked pages, so double check. */
09e2f92b8f54aa362088e216007b53ecdb42e283vboxsync /* Temporarily allow write access to the page table again. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = PGMHandlerPhysicalPageTempOff(pVM, pPage->GCPhys, pPage->GCPhys);
5b6e2c9a765c3c72295acc15791af8a700746956vboxsync rc = PGMShwModifyPage(pVCpu, pvFault, 1, X86_PTE_RW, ~(uint64_t)X86_PTE_RW);
3cbb4f9a6a320e58ed398ef7aaa004cc8727abc5vboxsync /* In the SMP case the page table might be removed while we wait for the PGM lock in the trap handler. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync ("PGMShwModifyPage -> GCPtr=%RGv rc=%d\n", pvFault, rc));
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync STAM_PROFILE_STOP(&pVM->pgm.s.CTX_SUFF(pPool)->CTX_SUFF_Z(StatMonitor), a);
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync#endif /* PGMPOOL_WITH_OPTIMIZED_DIRTY_PT */
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,FlushModOverflow));
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * Not worth it, so flush it.
74735ec6edd6640eebac8885fbb2dadc86b89cf5vboxsync * If we considered it to be reused, don't go back to ring-3
74735ec6edd6640eebac8885fbb2dadc86b89cf5vboxsync * to emulate failed instructions since we usually cannot
74735ec6edd6640eebac8885fbb2dadc86b89cf5vboxsync * interpret then. This may be a bit risky, in which case
74735ec6edd6640eebac8885fbb2dadc86b89cf5vboxsync * the reuse detection must be fixed.
74735ec6edd6640eebac8885fbb2dadc86b89cf5vboxsync rc = pgmPoolAccessHandlerFlush(pVM, pVCpu, pPool, pPage, pDis, pRegFrame, GCPhysFault, pvFault);
74735ec6edd6640eebac8885fbb2dadc86b89cf5vboxsync /* Make sure that the current instruction still has shadow page backing, otherwise we'll end up in a loop. */
74735ec6edd6640eebac8885fbb2dadc86b89cf5vboxsync if (PGMShwGetPage(pVCpu, pRegFrame->rip, NULL, NULL) == VINF_SUCCESS)
74735ec6edd6640eebac8885fbb2dadc86b89cf5vboxsync rc = VINF_SUCCESS; /* safe to restart the instruction. */
74735ec6edd6640eebac8885fbb2dadc86b89cf5vboxsync STAM_PROFILE_STOP_EX(&pVM->pgm.s.CTX_SUFF(pPool)->CTX_SUFF_Z(StatMonitor), &pPool->CTX_MID_Z(StatMonitor,FlushPage), a);
74735ec6edd6640eebac8885fbb2dadc86b89cf5vboxsync# endif /* !IN_RING3 */
74735ec6edd6640eebac8885fbb2dadc86b89cf5vboxsync * Check references to guest physical memory in a PAE / PAE page table.
74735ec6edd6640eebac8885fbb2dadc86b89cf5vboxsync * @param pPool The pool.
74735ec6edd6640eebac8885fbb2dadc86b89cf5vboxsync * @param pPage The page.
74735ec6edd6640eebac8885fbb2dadc86b89cf5vboxsync * @param pShwPT The shadow page table (mapping of the page).
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync * @param pGstPT The guest page table.
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsyncstatic void pgmPoolTrackCheckPTPaePae(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PTPAE pShwPT, PCX86PTPAE pGstPT)
1171e4fb031146163c9a5a66bd9cbf3f2a5acdb6vboxsync unsigned cErrors = 0;
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync unsigned LastPTE = ~0U; /* initialized to shut up gcc */
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync RTHCPHYS LastHCPhys = NIL_RTHCPHYS; /* initialized to shut up gcc */
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync for (unsigned i = 0; i < RT_MIN(RT_ELEMENTS(pShwPT->a), pPage->iFirstPresent); i++)
e17f587595bd5d3a7be56a892e3fd3a0ef83d268vboxsync AssertMsg(!pShwPT->a[i].n.u1Present, ("Unexpected PTE: idx=%d %RX64 (first=%d)\n", i, pShwPT->a[i].u, pPage->iFirstPresent));
e17f587595bd5d3a7be56a892e3fd3a0ef83d268vboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pShwPT->a); i++)
e17f587595bd5d3a7be56a892e3fd3a0ef83d268vboxsync int rc = PGMPhysGCPhys2HCPhys(pPool->CTX_SUFF(pVM), pGstPT->a[i].u & X86_PTE_PAE_PG_MASK, &HCPhys);
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync || (pShwPT->a[i].u & X86_PTE_PAE_PG_MASK) != HCPhys)
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync Log(("rc=%d idx=%d guest %RX64 shw=%RX64 vs %RHp\n", rc, i, pGstPT->a[i].u, pShwPT->a[i].u, HCPhys));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = PGMPhysGCPhys2HCPhys(pPool->CTX_SUFF(pVM), pPage->GCPhys, &HCPhysPT);
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync for (unsigned iPage = 0; iPage < pPool->cCurPages; iPage++)
e17f587595bd5d3a7be56a892e3fd3a0ef83d268vboxsync if (pTempPage->enmKind == PGMPOOLKIND_PAE_PT_FOR_PAE_PT)
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync PX86PTPAE pShwPT2 = (PX86PTPAE)PGMPOOL_PAGE_2_LOCKED_PTR(pPool->CTX_SUFF(pVM), pTempPage);
5b6e2c9a765c3c72295acc15791af8a700746956vboxsync for (unsigned j = 0; j < RT_ELEMENTS(pShwPT->a); j++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync && ((pShwPT2->a[j].u & X86_PTE_PAE_PG_MASK) == HCPhysPT))
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync Log(("GCPhys=%RGp idx=%d %RX64 vs %RX64\n", pTempPage->GCPhys, j, pShwPT->a[j].u, pShwPT2->a[j].u));
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync AssertMsg(!cErrors, ("cErrors=%d: last rc=%d idx=%d guest %RX64 shw=%RX64 vs %RHp\n", cErrors, LastRc, LastPTE, pGstPT->a[LastPTE].u, pShwPT->a[LastPTE].u, LastHCPhys));
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync# endif /* VBOX_STRICT */
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync * Clear references to guest physical memory in a PAE / PAE page table.
a46e399d5426a79f6f7e18d0ba85c505280e9386vboxsync * @returns nr of changed PTEs
a46e399d5426a79f6f7e18d0ba85c505280e9386vboxsync * @param pPool The pool.
a46e399d5426a79f6f7e18d0ba85c505280e9386vboxsync * @param pPage The page.
a46e399d5426a79f6f7e18d0ba85c505280e9386vboxsync * @param pShwPT The shadow page table (mapping of the page).
4584ef6026a823006bea5acbeb13dc4efe50da69vboxsync * @param pGstPT The guest page table.
9bebc668ed1ad5c93d92ff98fee1cd7dca55f6d5vboxsync * @param pOldGstPT The old cached guest page table.
9bebc668ed1ad5c93d92ff98fee1cd7dca55f6d5vboxsync * @param fAllowRemoval Bail out as soon as we encounter an invalid PTE
4584ef6026a823006bea5acbeb13dc4efe50da69vboxsync * @param pfFlush Flush reused page table (out)
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsyncDECLINLINE(unsigned) pgmPoolTrackFlushPTPaePae(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PTPAE pShwPT, PCX86PTPAE pGstPT, PCX86PTPAE pOldGstPT, bool fAllowRemoval, bool *pfFlush)
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync unsigned cChanged = 0;
e17f587595bd5d3a7be56a892e3fd3a0ef83d268vboxsync for (unsigned i = 0; i < RT_MIN(RT_ELEMENTS(pShwPT->a), pPage->iFirstPresent); i++)
13b9db9ae2c12b6c4e00eda5c79772d57a0d29e1vboxsync AssertMsg(!pShwPT->a[i].n.u1Present, ("Unexpected PTE: idx=%d %RX64 (first=%d)\n", i, pShwPT->a[i].u, pPage->iFirstPresent));
a46e399d5426a79f6f7e18d0ba85c505280e9386vboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pShwPT->a); i++)
a46e399d5426a79f6f7e18d0ba85c505280e9386vboxsync /* Check the new value written by the guest. If present and with a bogus physical address, then
13b9db9ae2c12b6c4e00eda5c79772d57a0d29e1vboxsync * it's fairly safe to assume the guest is reusing the PT.
13b9db9ae2c12b6c4e00eda5c79772d57a0d29e1vboxsync if (!PGMPhysIsGCPhysValid(pPool->CTX_SUFF(pVM), pGstPT->a[i].u & X86_PTE_PAE_PG_MASK))
13b9db9ae2c12b6c4e00eda5c79772d57a0d29e1vboxsync /* If the old cached PTE is identical, then there's no need to flush the shadow copy. */
13b9db9ae2c12b6c4e00eda5c79772d57a0d29e1vboxsync if ((pGstPT->a[i].u & X86_PTE_PAE_PG_MASK) == (pOldGstPT->a[i].u & X86_PTE_PAE_PG_MASK))
13b9db9ae2c12b6c4e00eda5c79772d57a0d29e1vboxsync int rc = PGMPhysGCPhys2HCPhys(pPool->CTX_SUFF(pVM), pGstPT->a[i].u & X86_PTE_PAE_PG_MASK, &HCPhys);
13b9db9ae2c12b6c4e00eda5c79772d57a0d29e1vboxsync AssertMsg(rc == VINF_SUCCESS && (pShwPT->a[i].u & X86_PTE_PAE_PG_MASK) == HCPhys, ("rc=%d guest %RX64 old %RX64 shw=%RX64 vs %RHp\n", rc, pGstPT->a[i].u, pOldGstPT->a[i].u, pShwPT->a[i].u, HCPhys));
13b9db9ae2c12b6c4e00eda5c79772d57a0d29e1vboxsync uint64_t uHostAttr = pShwPT->a[i].u & (X86_PTE_P | X86_PTE_US | X86_PTE_A | X86_PTE_D | X86_PTE_G | X86_PTE_PAE_NX);
13b9db9ae2c12b6c4e00eda5c79772d57a0d29e1vboxsync uint64_t uGuestAttr = pGstPT->a[i].u & (X86_PTE_P | X86_PTE_US | X86_PTE_A | X86_PTE_D | X86_PTE_G | X86_PTE_PAE_NX);
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync /* Something was changed, so flush it. */
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync Log4(("pgmPoolTrackDerefPTPaePae: i=%d pte=%RX64 hint=%RX64\n",
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync i, pShwPT->a[i].u & X86_PTE_PAE_PG_MASK, pOldGstPT->a[i].u & X86_PTE_PAE_PG_MASK));
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync pgmPoolTracDerefGCPhysHint(pPool, pPage, pShwPT->a[i].u & X86_PTE_PAE_PG_MASK, pOldGstPT->a[i].u & X86_PTE_PAE_PG_MASK, i);
01cc79d6798a7ad8b8041ddb2b67fc8b37bf0b37vboxsync * Flush a dirty page
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * @param pVM VM Handle.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * @param pPool The pool.
4584ef6026a823006bea5acbeb13dc4efe50da69vboxsync * @param idxSlot Dirty array slot index
9bebc668ed1ad5c93d92ff98fee1cd7dca55f6d5vboxsync * @param fAllowRemoval Allow a reused page table to be removed
4584ef6026a823006bea5acbeb13dc4efe50da69vboxsyncstatic void pgmPoolFlushDirtyPage(PVM pVM, PPGMPOOL pPool, unsigned idxSlot, bool fAllowRemoval = false)
01cc79d6798a7ad8b8041ddb2b67fc8b37bf0b37vboxsync Assert(idxSlot < RT_ELEMENTS(pPool->aIdxDirtyPages));
01cc79d6798a7ad8b8041ddb2b67fc8b37bf0b37vboxsync if (pPool->aIdxDirtyPages[idxSlot] == NIL_PGMPOOL_IDX)
01cc79d6798a7ad8b8041ddb2b67fc8b37bf0b37vboxsync Assert(pPage->iMonitoredNext == NIL_PGMPOOL_IDX && pPage->iMonitoredPrev == NIL_PGMPOOL_IDX);
01cc79d6798a7ad8b8041ddb2b67fc8b37bf0b37vboxsync AssertMsg(pPage->fDirty, ("Page %RGp (slot=%d) not marked dirty!", pPage->GCPhys, idxSlot));
01cc79d6798a7ad8b8041ddb2b67fc8b37bf0b37vboxsync Log(("Flush dirty page %RGp cMods=%d\n", pPage->GCPhys, pPage->cModifications));
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync /* First write protect the page again to catch all write accesses. (before checking for changes -> SMP) */
1171e4fb031146163c9a5a66bd9cbf3f2a5acdb6vboxsync int rc = PGMHandlerPhysicalReset(pVM, pPage->GCPhys);
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync uint32_t iPrevSubset = PGMDynMapPushAutoSubset(VMMGetCpu(pVM));
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync rc = PGMShwGetPage(VMMGetCpu(pVM), pPage->pvDirtyFault, &fFlags, &HCPhys);
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync && (!(fFlags & X86_PTE_RW) || HCPhys != pPage->Core.Key))
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync /* In the SMP case the page table might be removed while we wait for the PGM lock in the trap handler. */
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync ("PGMShwGetPage -> GCPtr=%RGv rc=%d flags=%RX64\n", pPage->pvDirtyFault, rc, fFlags));
c39952b427f31961ee5281dcdd492ad847ca74bbvboxsync /* Flush those PTEs that have changed. */
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync void *pvShw = PGMPOOL_PAGE_2_LOCKED_PTR(pPool->CTX_SUFF(pVM), pPage);
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync rc = PGM_GCPHYS_2_PTR(pPool->CTX_SUFF(pVM), pPage->GCPhys, &pvGst); AssertReleaseRC(rc);
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync unsigned cChanges = pgmPoolTrackFlushPTPaePae(pPool, pPage, (PX86PTPAE)pvShw, (PCX86PTPAE)pvGst, (PCX86PTPAE)&pPool->aDirtyPages[idxSlot][0], fAllowRemoval, &fFlush);
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync /** Note: we might want to consider keeping the dirty page active in case there were many changes. */
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync /* This page is likely to be modified again, so reduce the nr of modifications just a bit here. */
01cc79d6798a7ad8b8041ddb2b67fc8b37bf0b37vboxsync pPage->cModifications = RT_MAX(1, pPage->cModifications / 2);
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync if (pPool->cDirtyPages == RT_ELEMENTS(pPool->aIdxDirtyPages))
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync Assert(pPool->cDirtyPages <= RT_ELEMENTS(pPool->aIdxDirtyPages));
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync Log(("Removed dirty page %RGp cMods=%d cChanges=%d\n", pPage->GCPhys, pPage->cModifications, cChanges));
1171e4fb031146163c9a5a66bd9cbf3f2a5acdb6vboxsync PGMDynMapPopAutoSubset(VMMGetCpu(pVM), iPrevSubset);
1171e4fb031146163c9a5a66bd9cbf3f2a5acdb6vboxsync * Add a new dirty page
1171e4fb031146163c9a5a66bd9cbf3f2a5acdb6vboxsync * @param pVM VM Handle.
1171e4fb031146163c9a5a66bd9cbf3f2a5acdb6vboxsync * @param pPool The pool.
1171e4fb031146163c9a5a66bd9cbf3f2a5acdb6vboxsync * @param pPage The page.
1171e4fb031146163c9a5a66bd9cbf3f2a5acdb6vboxsyncvoid pgmPoolAddDirtyPage(PVM pVM, PPGMPOOL pPool, PPGMPOOLPAGE pPage)
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync AssertCompile(RT_ELEMENTS(pPool->aIdxDirtyPages) == 8 || RT_ELEMENTS(pPool->aIdxDirtyPages) == 16);
01cc79d6798a7ad8b8041ddb2b67fc8b37bf0b37vboxsync Assert(idxFree < RT_ELEMENTS(pPool->aIdxDirtyPages));
1171e4fb031146163c9a5a66bd9cbf3f2a5acdb6vboxsync Assert(pPage->iMonitoredNext == NIL_PGMPOOL_IDX && pPage->iMonitoredPrev == NIL_PGMPOOL_IDX);
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync if (pPool->cDirtyPages >= RT_ELEMENTS(pPool->aIdxDirtyPages))
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync STAM_COUNTER_INC(&pPool->StatDirtyPageOverFlowFlush);
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync pgmPoolFlushDirtyPage(pVM, pPool, idxFree, true /* allow removal of reused page tables*/);
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync Assert(pPool->cDirtyPages < RT_ELEMENTS(pPool->aIdxDirtyPages));
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync AssertMsg(pPool->aIdxDirtyPages[idxFree] == NIL_PGMPOOL_IDX, ("idxFree=%d cDirtyPages=%d\n", idxFree, pPool->cDirtyPages));
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync Log(("Add dirty page %RGp (slot=%d)\n", pPage->GCPhys, idxFree));
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync /* Make a copy of the guest page table as we require valid GCPhys addresses when removing
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * references to physical pages. (the HCPhys linear lookup is *extremely* expensive!)
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync void *pvShw = PGMPOOL_PAGE_2_LOCKED_PTR(pPool->CTX_SUFF(pVM), pPage);
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync int rc = PGM_GCPHYS_2_PTR(pPool->CTX_SUFF(pVM), pPage->GCPhys, &pvGst); AssertReleaseRC(rc);
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync memcpy(&pPool->aDirtyPages[idxFree][0], pvGst, PAGE_SIZE);
9b726ba798aabd1a27863e6f5cfeef1393bd198dvboxsync pgmPoolTrackCheckPTPaePae(pPool, pPage, (PX86PTPAE)pvShw, (PCX86PTPAE)pvGst);
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync pPool->idxFreeDirtyPage = (pPool->idxFreeDirtyPage + 1) & (RT_ELEMENTS(pPool->aIdxDirtyPages) - 1);
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync if ( pPool->cDirtyPages < RT_ELEMENTS(pPool->aIdxDirtyPages)
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync && pPool->aIdxDirtyPages[pPool->idxFreeDirtyPage] != NIL_PGMPOOL_IDX)
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync unsigned i;
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync for (i = 1; i < RT_ELEMENTS(pPool->aIdxDirtyPages); i++)
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync idxFree = (pPool->idxFreeDirtyPage + i) & (RT_ELEMENTS(pPool->aIdxDirtyPages) - 1);
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync if (pPool->aIdxDirtyPages[idxFree] == NIL_PGMPOOL_IDX)
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync Assert(pPool->cDirtyPages == RT_ELEMENTS(pPool->aIdxDirtyPages) || pPool->aIdxDirtyPages[pPool->idxFreeDirtyPage] == NIL_PGMPOOL_IDX);
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync# endif /* !IN_RING3 */
e8f172f2032e21b4be9a8f3df20e8ef689c6a6favboxsync * Check if the specified page is dirty (not write monitored)
e8f172f2032e21b4be9a8f3df20e8ef689c6a6favboxsync * @return dirty or not
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * @param pVM VM Handle.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * @param GCPhys Guest physical address
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync return false;
2cd06fc737773d015b5268b9e4dfba5997915957vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pPool->aIdxDirtyPages); i++)
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync return true;
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync return false;
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * Reset all dirty pages by reinstating page monitoring.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * @param pVM VM Handle.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync Assert(pPool->cDirtyPages <= RT_ELEMENTS(pPool->aIdxDirtyPages));
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pPool->aIdxDirtyPages); i++)
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync pgmPoolFlushDirtyPage(pVM, pPool, i, true /* allow removal of reused page tables*/);
d41220dff1068effe66bb6a11f444811ba58de40vboxsync if ( pPool->cDirtyPages != RT_ELEMENTS(pPool->aIdxDirtyPages)
d41220dff1068effe66bb6a11f444811ba58de40vboxsync && pPool->aIdxDirtyPages[pPool->idxFreeDirtyPage] != NIL_PGMPOOL_IDX)
d41220dff1068effe66bb6a11f444811ba58de40vboxsync unsigned i;
d41220dff1068effe66bb6a11f444811ba58de40vboxsync for (i = 1; i < RT_ELEMENTS(pPool->aIdxDirtyPages); i++)
d184d98f6e75700295aaa08ff14d0478dd6cc94avboxsync AssertMsg(i != RT_ELEMENTS(pPool->aIdxDirtyPages), ("cDirtyPages %d", pPool->cDirtyPages));
d41220dff1068effe66bb6a11f444811ba58de40vboxsync Assert(pPool->aIdxDirtyPages[pPool->idxFreeDirtyPage] == NIL_PGMPOOL_IDX || pPool->cDirtyPages == RT_ELEMENTS(pPool->aIdxDirtyPages));
d41220dff1068effe66bb6a11f444811ba58de40vboxsync * Reset all dirty pages by reinstating page monitoring.
d41220dff1068effe66bb6a11f444811ba58de40vboxsync * @param pVM VM Handle.
d41220dff1068effe66bb6a11f444811ba58de40vboxsync * @param GCPhysPT Physical address of the page table
d41220dff1068effe66bb6a11f444811ba58de40vboxsyncvoid pgmPoolInvalidateDirtyPage(PVM pVM, RTGCPHYS GCPhysPT)
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync Assert(pPool->cDirtyPages <= RT_ELEMENTS(pPool->aIdxDirtyPages));
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync unsigned idxDirtyPage = RT_ELEMENTS(pPool->aIdxDirtyPages);
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync for (unsigned i = 0; i < RT_ELEMENTS(pPool->aIdxDirtyPages); i++)
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync if (idxDirtyPage != RT_ELEMENTS(pPool->aIdxDirtyPages))
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync pgmPoolFlushDirtyPage(pVM, pPool, idxDirtyPage, true /* allow removal of reused page tables*/);
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync if ( pPool->cDirtyPages != RT_ELEMENTS(pPool->aIdxDirtyPages)
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync && pPool->aIdxDirtyPages[pPool->idxFreeDirtyPage] != NIL_PGMPOOL_IDX)
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync unsigned i;
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync for (i = 0; i < RT_ELEMENTS(pPool->aIdxDirtyPages); i++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertMsg(i != RT_ELEMENTS(pPool->aIdxDirtyPages), ("cDirtyPages %d", pPool->cDirtyPages));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync# endif /* PGMPOOL_WITH_OPTIMIZED_DIRTY_PT */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Inserts a page into the GCPhys hash table.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncDECLINLINE(void) pgmPoolHashInsert(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync 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.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncDECLINLINE(void) pgmPoolHashRemove(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log3(("pgmPoolHashRemove: %RGp\n", pPage->GCPhys));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertReleaseMsgFailed(("GCPhys=%RGp idx=%#x\n", pPage->GCPhys, pPage->idx));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Frees up one cache page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VINF_SUCCESS on success.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param iUser The user index.
6b022885f2cb6a55167609edecd89570cd80001dvboxsyncstatic int pgmPoolCacheFreeOne(PPGMPOOL pPool, uint16_t iUser)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Assert(pPool->iAgeHead != pPool->iAgeTail); /* We shouldn't be here if there < 2 cached entries! */
1ce20e84ae29a712029d1e213740388d7e158d5cvboxsync * Select one page from the tail of the age list.
1ce20e84ae29a712029d1e213740388d7e158d5cvboxsync/* This is the alternative to the SyncCR3 pgmPoolCacheUsed calls.
1ce20e84ae29a712029d1e213740388d7e158d5cvboxsync if (pPool->aPages[iToFree].iUserHead != NIL_PGMPOOL_USER_INDEX)
1ce20e84ae29a712029d1e213740388d7e158d5cvboxsync uint16_t i = pPool->aPages[iToFree].iAgePrev;
1ce20e84ae29a712029d1e213740388d7e158d5cvboxsync for (unsigned j = 0; j < 10 && i != NIL_PGMPOOL_USER_INDEX; j++, i = pPool->aPages[i].iAgePrev)
1ce20e84ae29a712029d1e213740388d7e158d5cvboxsync if (pPool->aPages[iToFree].iUserHead == NIL_PGMPOOL_USER_INDEX)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync iToFree = i;
1ce20e84ae29a712029d1e213740388d7e158d5cvboxsync * Reject any attempts at flushing the currently active shadow CR3 mapping.
1ce20e84ae29a712029d1e213740388d7e158d5cvboxsync * Call pgmPoolCacheUsed to move the page to the head of the age list.
8b03ab0bcd5c238021bc8a43d887dd9d0870c0f5vboxsync if (!pgmPoolIsPageLocked(&pPool->CTX_SUFF(pVM)->pgm.s, pPage))
8b03ab0bcd5c238021bc8a43d887dd9d0870c0f5vboxsync LogFlow(("pgmPoolCacheFreeOne: refuse CR3 mapping\n"));
1ce20e84ae29a712029d1e213740388d7e158d5cvboxsync AssertLogRelReturn(iLoop < 8192, VERR_INTERNAL_ERROR);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Found a usable page, flush it and return.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* This flush was initiated by us and not the guest, so explicitly flush the TLB. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* todo: find out why this is necessary; pgmPoolFlushPage should trigger a flush if one is really needed. */
223cf005b18af2c21352a70693ebaf0582f68ebcvboxsync * Checks if a kind mismatch is really a page being reused
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * or if it's just normal remappings.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns true if reused and the cached page (enmKind1) should be flushed
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns false if not reused.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param enmKind1 The kind of the cached page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param enmKind2 The kind of the requested page.
e85d76a7e5a047db3cdc8576ff5f412c7b73bbabvboxsyncstatic bool pgmPoolCacheReusedByKind(PGMPOOLKIND enmKind1, PGMPOOLKIND enmKind2)
9b45880674da6f82ca27cc28b0272de3dd3cc7dfvboxsync * Never reuse them. There is no remapping in non-paging mode.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync case PGMPOOLKIND_PAE_PDPT_FOR_32BIT: /* never reuse them for other types */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return false;
00599f6d39cc25ca39845c2433cd75de7b9f6971vboxsync * It's perfectly fine to reuse these, except for PAE and non-paging stuff.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return true;
10e1bc06b2908a0af56d92ffdbadd25b36a5ef61vboxsync return false;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * It's perfectly fine to reuse these, except for PAE and non-paging stuff.
ec588a4ac8429a8b6c744544818b3ce3b2c75690vboxsync return true;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return false;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * These cannot be flushed, and it's common to reuse the PDs as PTs.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return false;
abe73d9ccf5dd90fb1e3726792c56f2556a3d702vboxsync * Attempts to satisfy a pgmPoolAlloc request from the cache.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VINF_PGM_CACHED_PAGE on success.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VERR_FILE_NOT_FOUND if not found.
74991d7531692858fd22acf371a7ee941567977cvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param GCPhys The GC physical address of the page we're gonna shadow.
7e960d3a0a8a3a84d7aba2cca45d72b1c31cc97bvboxsync * @param enmKind The kind of mapping.
6b022885f2cb6a55167609edecd89570cd80001dvboxsync * @param enmAccess Access type for the mapping (only relevant for big pages)
b45d66c0e496e2fd861479202f3d43aad592bd14vboxsync * @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.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic int pgmPoolCacheAlloc(PPGMPOOL pPool, RTGCPHYS GCPhys, PGMPOOLKIND enmKind, PGMPOOLACCESS enmAccess, uint16_t iUser, uint32_t iUserTable, PPPGMPOOLPAGE ppPage)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Look up the GCPhys in the hash.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log3(("pgmPoolCacheAlloc: %RGp kind %s iUser=%x iUserTable=%x SLOT=%d\n", GCPhys, pgmPoolPoolKindToStr(enmKind), iUser, iUserTable, i));
3a21cbe769e7500039a2d17c794a911f7acb2dadvboxsync Log4(("pgmPoolCacheAlloc: slot %d found page %RGp\n", i, pPage->GCPhys));
3a21cbe769e7500039a2d17c794a911f7acb2dadvboxsync /* Put it at the start of the use list to make sure pgmPoolTrackAddUser
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * doesn't flush it in case there are no more free use records.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync int rc = pgmPoolTrackAddUser(pPool, pPage, iUser, iUserTable);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPage->cModifications = 1; /* reset counter (can't use 0, or else it will be reinserted in the modified list) */
74991d7531692858fd22acf371a7ee941567977cvboxsync * The kind is different. In some cases we should now flush the page
74991d7531692858fd22acf371a7ee941567977cvboxsync * as it has been reused, but in most cases this is normal remapping
74991d7531692858fd22acf371a7ee941567977cvboxsync * of PDs as PT or big pages using the GCPhys field in a slightly
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * different way than the other kinds.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if (pgmPoolCacheReusedByKind((PGMPOOLKIND)pPage->enmKind, enmKind))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync } while (i != NIL_PGMPOOL_IDX);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log3(("pgmPoolCacheAlloc: Missed GCPhys=%RGp enmKind=%s\n", GCPhys, pgmPoolPoolKindToStr(enmKind)));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Inserts a page into the cache.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The cached page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param fCanBeCached Set if the page is fit for caching from the caller's point of view.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic void pgmPoolCacheInsert(PPGMPOOL pPool, PPGMPOOLPAGE pPage, bool fCanBeCached)
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync * Insert into the GCPhys hash if the page is fit for that.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log3(("pgmPoolCacheInsert: Caching %p:{.Core=%RHp, .idx=%d, .enmKind=%s, GCPhys=%RGp}\n",
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPage, pPage->Core.Key, pPage->idx, pgmPoolPoolKindToStr(pPage->enmKind), pPage->GCPhys));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log3(("pgmPoolCacheInsert: Not caching %p:{.Core=%RHp, .idx=%d, .enmKind=%s, GCPhys=%RGp}\n",
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPage, pPage->Core.Key, pPage->idx, pgmPoolPoolKindToStr(pPage->enmKind), pPage->GCPhys));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Insert at the head of the age list.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPool->aPages[pPool->iAgeHead].iAgePrev = pPage->idx;
c33db29e7b41467a35675031f5f5233839909083vboxsync * Flushes a cached page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The cached page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic void pgmPoolCacheFlushPage(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log3(("pgmPoolCacheFlushPage: %RGp\n", pPage->GCPhys));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Remove the page from the hash.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Remove it from the age list.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPool->aPages[pPage->iAgeNext].iAgePrev = pPage->iAgePrev;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPool->aPages[pPage->iAgePrev].iAgeNext = pPage->iAgeNext;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Looks for pages sharing the monitor.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns Pointer to the head page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns NULL if not found.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The Pool
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pNewPage The page which is going to be monitored.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic PPGMPOOLPAGE pgmPoolMonitorGetPageByGCPhys(PPGMPOOL pPool, PPGMPOOLPAGE pNewPage)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Look up the GCPhys in the hash.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync RTGCPHYS GCPhys = pNewPage->GCPhys & ~(RTGCPHYS)(PAGE_SIZE - 1);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* find the head */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* ignore, no monitoring. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertFatalMsgFailed(("enmKind=%d idx=%d\n", pPage->enmKind, pPage->idx));
3cac8f8c6923a3a89ecfccda5e89ad75f48658e0vboxsync } 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 * @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.
75fca099c974cbbd48f132af1378c60232614760vboxsync /* Nothing to monitor here. */
e16fc293d8bdb6174849b7b4c6f7d9ef5f03ea83vboxsync /* Nothing to monitor here. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertFatalMsgFailed(("This can't happen! enmKind=%d\n", pPage->enmKind));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Install handler.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPGMPOOLPAGE pPageHead = pgmPoolMonitorGetPageByGCPhys(pPool, pPage);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Assert(pPageHead != pPage); Assert(pPageHead->iMonitoredNext != pPage->idx);
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync pgmPoolFlushDirtyPage(pPool->CTX_SUFF(pVM), pPool, pPageHead->idxDirty, false /* do not remove */);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPool->aPages[pPageHead->iMonitoredNext].iMonitoredPrev = pPage->idx;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Assert(pPage->iMonitoredNext == NIL_PGMPOOL_IDX); Assert(pPage->iMonitoredPrev == NIL_PGMPOOL_IDX);
6b022885f2cb6a55167609edecd89570cd80001dvboxsync const RTGCPHYS GCPhysPage = pPage->GCPhys & ~(RTGCPHYS)(PAGE_SIZE - 1);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = PGMHandlerPhysicalRegisterEx(pVM, PGMPHYSHANDLERTYPE_PHYSICAL_WRITE,
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPool->pfnAccessHandlerR3, MMHyperCCToR3(pVM, pPage),
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPool->pfnAccessHandlerR0, MMHyperCCToR0(pVM, pPage),
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPool->pfnAccessHandlerRC, MMHyperCCToRC(pVM, pPage),
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /** @todo we should probably deal with out-of-memory conditions here, but for now increasing
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * the heap size should suffice. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertFatalMsgRC(rc, ("PGMHandlerPhysicalRegisterEx %RGp failed with %Rrc\n", GCPhysPage, rc));
d6b5539478863f176bfffefc1ada2b9489cfa092vboxsync AssertFatalMsg(!(pVCpu->pgm.s.fSyncFlags & PGM_SYNC_CLEAR_PGM_POOL) || VMCPU_FF_ISSET(pVCpu, VMCPU_FF_PGM_SYNC_CR3), ("fSyncFlags=%x syncff=%d\n", pVCpu->pgm.s.fSyncFlags, VMCPU_FF_ISSET(pVCpu, VMCPU_FF_PGM_SYNC_CR3)));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Disables write monitoring of a guest page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VINF_SUCCESS on success.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The cached page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic int pgmPoolMonitorFlush(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Filter out the relevant kinds.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Nothing to monitor here. */
00599f6d39cc25ca39845c2433cd75de7b9f6971vboxsync 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];
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = PGMHandlerPhysicalChangeCallbacks(pVM, pPage->GCPhys & ~(RTGCPHYS)(PAGE_SIZE - 1),
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPool->pfnAccessHandlerR3, MMHyperCCToR3(pVM, pNewHead),
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPool->pfnAccessHandlerR0, MMHyperCCToR0(pVM, pNewHead),
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync 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));
d6b5539478863f176bfffefc1ada2b9489cfa092vboxsync AssertFatalMsg(!(pVCpu->pgm.s.fSyncFlags & PGM_SYNC_CLEAR_PGM_POOL) || VMCPU_FF_ISSET(pVCpu, VMCPU_FF_PGM_SYNC_CR3),
d6b5539478863f176bfffefc1ada2b9489cfa092vboxsync ("%#x %#x\n", pVCpu->pgm.s.fSyncFlags, pVM->fGlobalForcedActions));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Remove it from the list of modified pages (if in it).
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));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertMsg(cPages == pPool->cModifiedPages, ("%d != %d\n", cPages, pPool->cModifiedPages));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Handle SyncCR3 pool tasks
06de36c1229f14000638fa27993b13c9133e85f5vboxsync * @returns VBox status code.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VINF_SUCCESS if successfully added.
bc8991845b5bd7e98758795748d3d76408756793vboxsync * @retval VINF_PGM_SYNC_CR3 is it needs to be deferred to ring 3 (GC only)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVCpu The VMCPU handle.
1bd0025f8e699b37641beaddb205c61394ef7defvboxsync * @remark Should only be used when monitoring is available, thus placed in
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * the PGMPOOL_WITH_MONITORING #ifdef.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * When monitoring shadowed pages, we reset the modification counters on CR3 sync.
50df3da42ff6589b0ecc4f50f2288811bc370186vboxsync * Occasionally we will have to clear all the shadow page tables because we wanted
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * to monitor a page which was mapped by too many shadowed page tables. This operation
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * sometimes refered to as a 'lightweight flush'.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync# ifdef IN_RING3 /* Don't flush in ring-0 or raw mode, it's taking too long. */
0138777a0eae9d74905d86f792f1f1c497dab65evboxsync if (pVCpu->pgm.s.fSyncFlags & PGM_SYNC_CLEAR_PGM_POOL)
4584ef6026a823006bea5acbeb13dc4efe50da69vboxsync# else /* !IN_RING3 */
01cc79d6798a7ad8b8041ddb2b67fc8b37bf0b37vboxsync if (pVCpu->pgm.s.fSyncFlags & PGM_SYNC_CLEAR_PGM_POOL)
4584ef6026a823006bea5acbeb13dc4efe50da69vboxsync Log(("SyncCR3: PGM_SYNC_CLEAR_PGM_POOL is set -> VINF_PGM_SYNC_CR3\n"));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync VMCPU_FF_SET(pVCpu, VMCPU_FF_PGM_SYNC_CR3); /** @todo no need to do global sync, right? */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Make sure all other VCPUs return to ring 3. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync# endif /* !IN_RING3 */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* pgmPoolMonitorModifiedClearAll can cause a pgm pool flush (dirty page clearing), so make sure we handle this! */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if (pVCpu->pgm.s.fSyncFlags & PGM_SYNC_CLEAR_PGM_POOL)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log(("pgmPoolMonitorModifiedClearAll caused a pgm flush -> call pgmPoolSyncCR3 again!\n"));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Frees up at least one user entry.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code.
6b022885f2cb6a55167609edecd89570cd80001dvboxsync * @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)
de32f2abcb21ab5b46566f51b08d8f0b2094080avboxsync * Just free cached pages in a braindead fashion.
de32f2abcb21ab5b46566f51b08d8f0b2094080avboxsync /** @todo walk the age list backwards and free the first with usage. */
94e740c29aa13add24f941924e763ed5ed2abfa3vboxsync } while (pPool->iUserFreeHead == NIL_PGMPOOL_USER_INDEX);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Inserts a page into the cache.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * This will create user node for the page, insert it into the GCPhys
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * hash, and insert it into the age list.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VINF_SUCCESS if successfully added.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VERR_PGM_POOL_FLUSHED if the pool was flushed.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @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.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * Insert into cache and enable monitoring of the guest page if enabled.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * Until we implement caching of all levels, including the CR3 one, we'll
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * have to make sure we don't try monitor & cache any recursive reuse of
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * a monitored CR3 page. Because all windows versions are doing this we'll
d6b5539478863f176bfffefc1ada2b9489cfa092vboxsync * have to be able to do combined access monitoring, CR3 + PT and
e17f587595bd5d3a7be56a892e3fd3a0ef83d268vboxsync * PD + PT (guest PAE).
d6b5539478863f176bfffefc1ada2b9489cfa092vboxsync * We're now cooperating with the CR3 monitor if an uncachable page is found.
d6b5539478863f176bfffefc1ada2b9489cfa092vboxsync const bool fCanBeMonitored = true;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolCacheInsert(pPool, pPage, fCanBeMonitored); /* This can be expanded. */
5dda7f07dab8a954e6c4cf2378b15f921e60d9aavboxsync * Adds a user reference to a page.
5dda7f07dab8a954e6c4cf2378b15f921e60d9aavboxsync * This will move the page to the head of the
d6b5539478863f176bfffefc1ada2b9489cfa092vboxsync * @returns VBox status code.
5dda7f07dab8a954e6c4cf2378b15f921e60d9aavboxsync * @retval VINF_SUCCESS if successfully added.
5dda7f07dab8a954e6c4cf2378b15f921e60d9aavboxsync * @retval VERR_PGM_POOL_FLUSHED if the pool was flushed.
5dda7f07dab8a954e6c4cf2378b15f921e60d9aavboxsync * @param pPool The pool.
d6b5539478863f176bfffefc1ada2b9489cfa092vboxsync * @param pPage The cached page.
5dda7f07dab8a954e6c4cf2378b15f921e60d9aavboxsync * @param iUser The user index.
d6b5539478863f176bfffefc1ada2b9489cfa092vboxsync * @param iUserTable The user table.
52694110156cee1511e430c9ae800de121a20050vboxsyncstatic 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));
d6b5539478863f176bfffefc1ada2b9489cfa092vboxsync * Check that the entry doesn't already exists. We only allow multiple users of top-level paging structures (SHW_POOL_ROOT_IDX).
d6b5539478863f176bfffefc1ada2b9489cfa092vboxsync AssertMsg(iUser != PGMPOOL_IDX_PD || iUser != PGMPOOL_IDX_PDPT || iUser != PGMPOOL_IDX_NESTED_ROOT || iUser != PGMPOOL_IDX_AMD64_CR3 ||
d6b5539478863f176bfffefc1ada2b9489cfa092vboxsync 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.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Initialize the user node and insert it.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolFlushDirtyPage(pPool->CTX_SUFF(pVM), pPool, pPage->idxDirty, false /* do not remove */);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Tell the cache to update its replacement stats for this page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Frees a user record associated with a page.
750d4d0506a38b2e80c997075d40aad474e675fbvboxsync * This does not clear the entry in the user table, it simply replaces the
c657bea826c7455c93bd45eaebab63a4c7742c42vboxsync * 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).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic void pgmPoolTrackFreeUser(PPGMPOOL pPool, PPGMPOOLPAGE pPage, uint16_t iUser, uint32_t iUserTable)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Unlink and free the specified user entry.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log3(("pgmPoolTrackFreeUser %RGp %x %x\n", pPage->GCPhys, iUser, iUserTable));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Special: For PAE and 32-bit paging, there is usually no more than one user. */
32f98f3d0fb00168315b4ece1f0808df4cd88248vboxsync /* General: Linear search. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Fatal: didn't find it */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertFatalMsgFailed(("Didn't find the user entry! iUser=%#x iUserTable=%#x GCPhys=%RGp\n",
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Gets the entry size of a shadow table.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param enmKind The kind of page.
32f98f3d0fb00168315b4ece1f0808df4cd88248vboxsync * @returns The size of the entry in bytes. That is, 4 or 8.
32f98f3d0fb00168315b4ece1f0808df4cd88248vboxsync * @returns If the kind is not for a table, an assertion is raised and 0 is
32f98f3d0fb00168315b4ece1f0808df4cd88248vboxsync * returned.
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...) */
491e761460097c61edb725a77477cecb2774da45vboxsync * Scans one shadow page table for mappings of a physical page.
491e761460097c61edb725a77477cecb2774da45vboxsync * @returns true/false indicating removal of all relevant PTEs
491e761460097c61edb725a77477cecb2774da45vboxsync * @param pVM The VM handle.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPhysPage The guest page in question.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param fFlushPTEs Flush PTEs or allow them to be updated (e.g. in case of an RW bit change)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param iShw The shadow page table.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param iPte Page table entry or NIL_PGMPOOL_PHYSEXT_IDX_PTE if unknown
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param cRefs The number of references made in that PT.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic bool pgmPoolTrackFlushGCPhysPTInt(PVM pVM, PCPGMPAGE pPhysPage, bool fFlushPTEs, uint16_t iShw, uint16_t iPte, uint16_t cRefs)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolTrackFlushGCPhysPT: pPhysPage=%RHp iShw=%d iPte=%d cRefs=%d\n", PGM_PAGE_GET_HCPHYS(pPhysPage), iShw, iPte, cRefs));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync bool bRet = false;
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.
2f1b3d7474489e653b75edf9492132a0f56aab4dvboxsync const uint32_t u32 = PGM_PAGE_GET_HCPHYS(pPhysPage) | X86_PTE_P;
ab1239d8445aa1fd4afddb7d0c8b90bbdc742010vboxsync PX86PT pPT = (PX86PT)PGMPOOL_PAGE_2_PTR(pVM, pPage);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync case PGM_PAGE_HNDL_PHYS_STATE_NONE: /** No handler installed. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync case PGM_PAGE_HNDL_PHYS_STATE_DISABLED: /** Monitoring is temporarily disabled. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync case PGM_PAGE_HNDL_PHYS_STATE_WRITE: /** Write access is monitored. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Update the counter if we're removing references. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if ((pPT->a[iPte].u & (X86_PTE_PG_MASK | X86_PTE_P)) == u32)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log4(("pgmPoolTrackFlushGCPhysPTs: i=%d pte=%RX32 cRefs=%#x\n", iPte, pPT->a[iPte], cRefs));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Pte.n.u1Write = 0; /* need to disallow writes when dirty bit tracking is still active. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log(("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 AssertFatalMsgFailed(("cRefs=%d iFirstPresent=%d cPresent=%d u32=%RX32 poolkind=%x\n", cRefs, pPage->iFirstPresent, pPage->cPresent, u32, pPage->enmKind));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync case PGMPOOLKIND_EPT_PT_FOR_PHYS: /* physical mask the same as PAE; RW bit as well; be careful! */
8f7bc6ad2b7bbcb4b3b96248cd2478e45f2e3b88vboxsync const uint64_t u64 = PGM_PAGE_GET_HCPHYS(pPhysPage) | X86_PTE_P;
5db1d52ffbcaa46c3d944c6c2d9c552306817d9avboxsync PX86PTPAE pPT = (PX86PTPAE)PGMPOOL_PAGE_2_PTR(pVM, pPage);
75fca099c974cbbd48f132af1378c60232614760vboxsync case PGM_PAGE_HNDL_PHYS_STATE_NONE: /** No handler installed. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync case PGM_PAGE_HNDL_PHYS_STATE_DISABLED: /** Monitoring is temporarily disabled. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync case PGM_PAGE_HNDL_PHYS_STATE_WRITE: /** Write access is monitored. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Update the counter if we're removing references. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if ((pPT->a[iPte].u & (X86_PTE_PAE_PG_MASK | X86_PTE_P)) == u64)
10e1bc06b2908a0af56d92ffdbadd25b36a5ef61vboxsync Log4(("pgmPoolTrackFlushGCPhysPTs: i=%d pte=%RX64 cRefs=%#x\n", iPte, pPT->a[iPte], cRefs));
3080f6c0871099df43a4e91b31894d9c2b1369a8vboxsync Pte.n.u1Write = 0; /* need to disallow writes when dirty bit tracking is still active. */
9b45880674da6f82ca27cc28b0272de3dd3cc7dfvboxsync Log(("cRefs=%d iFirstPresent=%d cPresent=%d\n", cRefs, pPage->iFirstPresent, pPage->cPresent));
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync Log(("Found %RX64 expected %RX64\n", pPT->a[iPte].u & (X86_PTE_PAE_PG_MASK | X86_PTE_P), u64));
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync if ((pPT->a[i].u & (X86_PTE_PAE_PG_MASK | X86_PTE_P)) == u64)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertFatalMsgFailed(("cRefs=%d iFirstPresent=%d cPresent=%d u64=%RX64 poolkind=%x\n", cRefs, pPage->iFirstPresent, pPage->cPresent, u64, pPage->enmKind));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Large page case only. */
3cac8f8c6923a3a89ecfccda5e89ad75f48658e0vboxsync const uint64_t u64 = PGM_PAGE_GET_HCPHYS(pPhysPage) | X86_PDE4M_P | X86_PDE4M_PS;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PEPTPD pPD = (PEPTPD)PGMPOOL_PAGE_2_PTR(pVM, pPage);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if ((pPD->a[iPte].u & (EPT_PDE2M_PG_MASK | X86_PDE4M_P | X86_PDE4M_PS)) == u64)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log4(("pgmPoolTrackFlushGCPhysPTs: i=%d pde=%RX64 cRefs=%#x\n", iPte, pPD->a[iPte], cRefs));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Update the counter as we're removing references. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log(("cRefs=%d iFirstPresent=%d cPresent=%d\n", cRefs, pPage->iFirstPresent, pPage->cPresent));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if ((pPD->a[i].u & (EPT_PDE2M_PG_MASK | X86_PDE4M_P | X86_PDE4M_PS)) == u64)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertFatalMsgFailed(("cRefs=%d iFirstPresent=%d cPresent=%d\n", cRefs, pPage->iFirstPresent, pPage->cPresent));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* AMD-V nested paging - @todo merge with EPT as we only check the parts that are identical. */
aaeb2e2f6ed5b164f1dec9a16a7adeb84f64cf31vboxsync const uint64_t u64 = PGM_PAGE_GET_HCPHYS(pPhysPage) | X86_PDE4M_P | X86_PDE4M_PS;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PX86PD pPD = (PX86PD)PGMPOOL_PAGE_2_PTR(pVM, pPage);
b978e5849454446957177fd47ee98609ab0457a6vboxsync if ((pPD->a[iPte].u & (X86_PDE2M_PAE_PG_MASK | X86_PDE4M_P | X86_PDE4M_PS)) == u64)
b978e5849454446957177fd47ee98609ab0457a6vboxsync Log4(("pgmPoolTrackFlushGCPhysPTs: i=%d pde=%RX64 cRefs=%#x\n", iPte, pPD->a[iPte], cRefs));
b978e5849454446957177fd47ee98609ab0457a6vboxsync /* Update the counter as we're removing references. */
b978e5849454446957177fd47ee98609ab0457a6vboxsync Log(("cRefs=%d iFirstPresent=%d cPresent=%d\n", cRefs, pPage->iFirstPresent, pPage->cPresent));
b978e5849454446957177fd47ee98609ab0457a6vboxsync if ((pPD->a[i].u & (X86_PDE2M_PAE_PG_MASK | X86_PDE4M_P | X86_PDE4M_PS)) == u64)
b978e5849454446957177fd47ee98609ab0457a6vboxsync AssertFatalMsgFailed(("cRefs=%d iFirstPresent=%d cPresent=%d\n", cRefs, pPage->iFirstPresent, pPage->cPresent));
b978e5849454446957177fd47ee98609ab0457a6vboxsync#endif /* PGM_WITH_LARGE_PAGES */
b978e5849454446957177fd47ee98609ab0457a6vboxsync AssertFatalMsgFailed(("enmKind=%d iShw=%d\n", pPage->enmKind, iShw));
b978e5849454446957177fd47ee98609ab0457a6vboxsync * Scans one shadow page table for mappings of a physical page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM The VM handle.
b978e5849454446957177fd47ee98609ab0457a6vboxsync * @param pPhysPage The guest page in question.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param fFlushPTEs Flush PTEs or allow them to be updated (e.g. in case of an RW bit change)
467e62e1aa999ec951e820d74498ef79dd1bedbdvboxsync * @param iShw The shadow page table.
a53545030cc899212e9ac2a67971902c9fc26e99vboxsync * @param cRefs The number of references made in that PT.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic void pgmPoolTrackFlushGCPhysPT(PVM pVM, PPGMPAGE pPhysPage, bool fFlushPTEs, uint16_t iShw, uint16_t cRefs)
a53545030cc899212e9ac2a67971902c9fc26e99vboxsync PPGMPOOL pPool = pVM->pgm.s.CTX_SUFF(pPool); NOREF(pPool);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* We should only come here with when there's only one reference to this physical page. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Assert(PGMPOOL_TD_GET_CREFS(PGM_PAGE_GET_TRACKING(pPhysPage)) == 1);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log2(("pgmPoolTrackFlushGCPhysPT: pPhysPage=%RHp iShw=%d cRefs=%d\n", PGM_PAGE_GET_HCPHYS(pPhysPage), iShw, cRefs));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_PROFILE_START(&pPool->StatTrackFlushGCPhysPT, f);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync bool fKeptPTEs = pgmPoolTrackFlushGCPhysPTInt(pVM, pPhysPage, fFlushPTEs, iShw, PGM_PAGE_GET_PTE_INDEX(pPhysPage), cRefs);
9c425bdea5f0991df62922b1584b805a86f2f898vboxsync STAM_PROFILE_STOP(&pPool->StatTrackFlushGCPhysPT, f);
b978e5849454446957177fd47ee98609ab0457a6vboxsync * Flushes a list of shadow page tables mapping the same physical page.
b978e5849454446957177fd47ee98609ab0457a6vboxsync * @param pVM The VM handle.
b978e5849454446957177fd47ee98609ab0457a6vboxsync * @param pPhysPage The guest page in question.
b978e5849454446957177fd47ee98609ab0457a6vboxsync * @param fFlushPTEs Flush PTEs or allow them to be updated (e.g. in case of an RW bit change)
b978e5849454446957177fd47ee98609ab0457a6vboxsync * @param iPhysExt The physical cross reference extent list to flush.
b978e5849454446957177fd47ee98609ab0457a6vboxsyncstatic void pgmPoolTrackFlushGCPhysPTs(PVM pVM, PPGMPAGE pPhysPage, bool fFlushPTEs, uint16_t iPhysExt)
b978e5849454446957177fd47ee98609ab0457a6vboxsync bool fKeepList = false;
b978e5849454446957177fd47ee98609ab0457a6vboxsync STAM_PROFILE_START(&pPool->StatTrackFlushGCPhysPTs, f);
b978e5849454446957177fd47ee98609ab0457a6vboxsync Log2(("pgmPoolTrackFlushGCPhysPTs: pPhysPage=%RHp iPhysExt\n", PGM_PAGE_GET_HCPHYS(pPhysPage), iPhysExt));
b978e5849454446957177fd47ee98609ab0457a6vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pPhysExt->aidx); i++)
b978e5849454446957177fd47ee98609ab0457a6vboxsync bool fKeptPTEs = pgmPoolTrackFlushGCPhysPTInt(pVM, pPhysPage, fFlushPTEs, pPhysExt->aidx[i], pPhysExt->apte[i], 1);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* insert the list into the free list and clear the ram range entry. */
8c9d2065ca6efecd5661174e382314868c0d4b94vboxsync /* Invalidate the tracking data. */
8c9d2065ca6efecd5661174e382314868c0d4b94vboxsync STAM_PROFILE_STOP(&pPool->StatTrackFlushGCPhysPTs, f);
8c9d2065ca6efecd5661174e382314868c0d4b94vboxsync * Flushes all shadow page table mappings of the given guest page.
8c9d2065ca6efecd5661174e382314868c0d4b94vboxsync * This is typically called when the host page backing the guest one has been
8c9d2065ca6efecd5661174e382314868c0d4b94vboxsync * replaced or when the page protection was changed due to an access handler.
b978e5849454446957177fd47ee98609ab0457a6vboxsync * @returns VBox status code.
8c9d2065ca6efecd5661174e382314868c0d4b94vboxsync * @retval VINF_SUCCESS if all references has been successfully cleared.
8c9d2065ca6efecd5661174e382314868c0d4b94vboxsync * @retval VINF_PGM_SYNC_CR3 if we're better off with a CR3 sync and a page
8c9d2065ca6efecd5661174e382314868c0d4b94vboxsync * pool cleaning. FF and sync flags are set.
8c9d2065ca6efecd5661174e382314868c0d4b94vboxsync * @param pVM The VM handle.
467e62e1aa999ec951e820d74498ef79dd1bedbdvboxsync * @param GCPhysPage GC physical address of the page in question
a53545030cc899212e9ac2a67971902c9fc26e99vboxsync * @param pPhysPage The guest page in question.
8c9d2065ca6efecd5661174e382314868c0d4b94vboxsync * @param fFlushPTEs Flush PTEs or allow them to be updated (e.g. in case of an RW bit change)
8c9d2065ca6efecd5661174e382314868c0d4b94vboxsync * @param pfFlushTLBs This is set to @a true if the shadow TLBs should be
8c9d2065ca6efecd5661174e382314868c0d4b94vboxsync * flushed, it is NOT touched if this isn't necessary.
a53545030cc899212e9ac2a67971902c9fc26e99vboxsync * The caller MUST initialized this to @a false.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncint pgmPoolTrackUpdateGCPhys(PVM pVM, RTGCPHYS GCPhysPage, PPGMPAGE pPhysPage, bool fFlushPTEs, bool *pfFlushTLBs)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Is this page part of a large page? */
b978e5849454446957177fd47ee98609ab0457a6vboxsync if (PGM_PAGE_GET_PDE_TYPE(pPhysPage) == PGM_PAGE_PDE_TYPE_PDE)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync RTGCPHYS GCPhysBase = GCPhysPage & X86_PDE2M_PAE_PG_MASK;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Fetch the large page base. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPhysBase = pgmPhysGetPage(&pVM->pgm.s, GCPhysBase);
b978e5849454446957177fd47ee98609ab0457a6vboxsync Log(("pgmPoolTrackUpdateGCPhys: update large page PDE for %RGp (%RGp)\n", GCPhysBase, GCPhysPage));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if (PGM_PAGE_GET_PDE_TYPE(pPhysBase) == PGM_PAGE_PDE_TYPE_PDE)
b978e5849454446957177fd47ee98609ab0457a6vboxsync /* Mark the large page as disabled as we need to break it up to change a single page in the 2 MB range. */
b978e5849454446957177fd47ee98609ab0457a6vboxsync PGM_PAGE_SET_PDE_TYPE(pPhysBase, PGM_PAGE_PDE_TYPE_PDE_DISABLED);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Update the base as that *only* that one has a reference and there's only one PDE to clear. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = pgmPoolTrackUpdateGCPhys(pVM, GCPhysBase, pPhysBase, fFlushPTEs, pfFlushTLBs);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync#endif /* PGM_WITH_LARGE_PAGES */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync const uint16_t u16 = PGM_PAGE_GET_TRACKING(pPhysPage);
b978e5849454446957177fd47ee98609ab0457a6vboxsync * The zero page is currently screwing up the tracking and we'll
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * have to flush the whole shebang. Unless VBOX_WITH_NEW_LAZY_PAGE_ALLOC
7696b635f26eb0a48aaddab6cc39da44e81fbdaevboxsync * is defined, zero pages won't normally be mapped. Some kind of solution
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * will be needed for this problem of course, but it will have to wait...
b978e5849454446957177fd47ee98609ab0457a6vboxsync /* Start a subset here because pgmPoolTrackFlushGCPhysPTsSlow and
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolTrackFlushGCPhysPTs will/may kill the pool otherwise. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync uint32_t iPrevSubset = PGMDynMapPushAutoSubset(pVCpu);
b978e5849454446957177fd47ee98609ab0457a6vboxsync if (PGMPOOL_TD_GET_CREFS(u16) != PGMPOOL_TD_CREFS_PHYSEXT)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync else if (u16 != PGMPOOL_TD_MAKE(PGMPOOL_TD_CREFS_PHYSEXT, PGMPOOL_TD_IDX_OVERFLOWED))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolTrackFlushGCPhysPTs(pVM, pPhysPage, fFlushPTEs, PGMPOOL_TD_GET_IDX(u16));
b978e5849454446957177fd47ee98609ab0457a6vboxsync rc = pgmPoolTrackFlushGCPhysPTsSlow(pVM, pPhysPage);
3cac8f8c6923a3a89ecfccda5e89ad75f48658e0vboxsync pVCpu->pgm.s.fSyncFlags |= PGM_SYNC_CLEAR_PGM_POOL;
965a56f05878cf7c9634998e98d0bed41ebf21dbvboxsync * Scans all shadow page tables for mappings of a physical page.
11c599b71a8c202a506b8623af57432c3d415ddavboxsync * This may be slow, but it's most likely more efficient than cleaning
11c599b71a8c202a506b8623af57432c3d415ddavboxsync * out the entire page pool / cache.
b978e5849454446957177fd47ee98609ab0457a6vboxsync * @returns VBox status code.
11c599b71a8c202a506b8623af57432c3d415ddavboxsync * @retval VINF_SUCCESS if all references has been successfully cleared.
11c599b71a8c202a506b8623af57432c3d415ddavboxsync * @retval VINF_PGM_GCPHYS_ALIASED if we're better off with a CR3 sync and
11c599b71a8c202a506b8623af57432c3d415ddavboxsync * a page pool cleaning.
b978e5849454446957177fd47ee98609ab0457a6vboxsync * @param pVM The VM handle.
11c599b71a8c202a506b8623af57432c3d415ddavboxsync * @param pPhysPage The guest page in question.
d7f733dd34ab7755807d85016b7c2ab3d1a362d4vboxsyncint pgmPoolTrackFlushGCPhysPTsSlow(PVM pVM, PPGMPAGE pPhysPage)
11c599b71a8c202a506b8623af57432c3d415ddavboxsync STAM_PROFILE_START(&pPool->StatTrackFlushGCPhysPTsSlow, s);
11c599b71a8c202a506b8623af57432c3d415ddavboxsync LogFlow(("pgmPoolTrackFlushGCPhysPTsSlow: cUsedPages=%d cPresent=%d pPhysPage=%R[pgmpage]\n",
11c599b71a8c202a506b8623af57432c3d415ddavboxsync * There is a limit to what makes sense.
11c599b71a8c202a506b8623af57432c3d415ddavboxsync LogFlow(("pgmPoolTrackFlushGCPhysPTsSlow: giving up... (cPresent=%d)\n", pPool->cPresent));
11c599b71a8c202a506b8623af57432c3d415ddavboxsync STAM_PROFILE_STOP(&pPool->StatTrackFlushGCPhysPTsSlow, s);
11c599b71a8c202a506b8623af57432c3d415ddavboxsync * Iterate all the pages until we've encountered all that in use.
11c599b71a8c202a506b8623af57432c3d415ddavboxsync * This is simple but not quite optimal solution.
11c599b71a8c202a506b8623af57432c3d415ddavboxsync const uint64_t u64 = PGM_PAGE_GET_HCPHYS(pPhysPage) | X86_PTE_P;
11c599b71a8c202a506b8623af57432c3d415ddavboxsync * We only care about shadow page tables.
11c599b71a8c202a506b8623af57432c3d415ddavboxsync PX86PT pPT = (PX86PT)PGMPOOL_PAGE_2_PTR(pVM, pPage);
11c599b71a8c202a506b8623af57432c3d415ddavboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pPT->a); i++)
3241f1be564f7351b07ce8a807673fa77a7847bcvboxsync if ((pPT->a[i].u & (X86_PTE_PG_MASK | X86_PTE_P)) == u32)
11c599b71a8c202a506b8623af57432c3d415ddavboxsync //Log4(("pgmPoolTrackFlushGCPhysPTsSlow: idx=%d i=%d pte=%RX32\n", iPage, i, pPT->a[i]));
11c599b71a8c202a506b8623af57432c3d415ddavboxsync pPT->a[i].u = 0;
11c599b71a8c202a506b8623af57432c3d415ddavboxsync /* Update the counter as we're removing references. */
11c599b71a8c202a506b8623af57432c3d415ddavboxsync PX86PTPAE pPT = (PX86PTPAE)PGMPOOL_PAGE_2_PTR(pVM, pPage);
11c599b71a8c202a506b8623af57432c3d415ddavboxsync 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(("pgmPoolTrackFlushGCPhysPTsSlow: idx=%d i=%d pte=%RX64\n", iPage, i, pPT->a[i]));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPT->a[i].u = 0;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Update the counter as we're removing references. */
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(("pgmPoolTrackFlushGCPhysPTsSlow: idx=%d i=%d pte=%RX64\n", iPage, i, pPT->a[i]));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPT->a[i].u = 0;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Update the counter as we're removing references. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_PROFILE_STOP(&pPool->StatTrackFlushGCPhysPTsSlow, s);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Clears the user entry in a user table.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * This is used to remove all references to a page when flushing it.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic void pgmPoolTrackClearPageUser(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PCPGMPOOLUSER pUser)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Map the user page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPGMPOOLPAGE pUserPage = &pPool->aPages[pUser->iUser];
9c425bdea5f0991df62922b1584b805a86f2f898vboxsync u.pau64 = (uint64_t *)PGMPOOL_PAGE_2_PTR(pPool->CTX_SUFF(pVM), pUserPage);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolTrackClearPageUser: clear %x in %s (%RGp) (flushing %s)\n", iUserTable, pgmPoolPoolKindToStr(pUserPage->enmKind), pUserPage->Core.Key, pgmPoolPoolKindToStr(pPage->enmKind)));
e4ea543752422f1139923e3e506c625b0a1827c5vboxsync /* Safety precaution in case we change the paging for other modes too in the future. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Assert(!pgmPoolIsPageLocked(&pPool->CTX_SUFF(pVM)->pgm.s, pPage));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Some sanity checks.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync 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 */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertMsgFailed(("enmKind=%d\n", pUserPage->enmKind));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync#endif /* VBOX_STRICT */
9f1e0743f565b1975bb4efd7311b30cfa0d3e384vboxsync * Clear the entry in the user page.
2b88b28162a49c6fa769c03d56767a9806d4f456vboxsync /* 32-bit entries */
00599f6d39cc25ca39845c2433cd75de7b9f6971vboxsync /* 64-bit entries */
da936e0446fb2b56b813d5d938f1dfc6e4bf8b13vboxsync /* 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
da936e0446fb2b56b813d5d938f1dfc6e4bf8b13vboxsync * non-present PDPT will continue to cause page faults.
da936e0446fb2b56b813d5d938f1dfc6e4bf8b13vboxsync /* no break */
da936e0446fb2b56b813d5d938f1dfc6e4bf8b13vboxsync AssertFatalMsgFailed(("enmKind=%d iUser=%#x iUserTable=%#x\n", pUserPage->enmKind, pUser->iUser, pUser->iUserTable));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Clears all users of a page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic void pgmPoolTrackClearPageUsers(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Free all the user records.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolTrackClearPageUsers %RGp\n", pPage->GCPhys));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Clear enter in user table. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolTrackClearPageUser(pPool, pPage, &paUsers[i]);
00599f6d39cc25ca39845c2433cd75de7b9f6971vboxsync /* Free it. */
e751d1e1e4ae424d4846a23da32f663d14960796vboxsync /* Next. */
8f7bc6ad2b7bbcb4b3b96248cd2478e45f2e3b88vboxsync * Allocates a new physical cross reference extent.
54fe68d807196dc565de24055996e634ee40ee92vboxsync * @returns Pointer to the allocated extent on success. NULL if we're out of them.
54fe68d807196dc565de24055996e634ee40ee92vboxsync * @param pVM The VM handle.
3080f6c0871099df43a4e91b31894d9c2b1369a8vboxsync * @param piPhysExt Where to store the phys ext index.
ec588a4ac8429a8b6c744544818b3ce3b2c75690vboxsyncPPGMPOOLPHYSEXT pgmPoolTrackPhysExtAlloc(PVM pVM, uint16_t *piPhysExt)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_COUNTER_INC(&pPool->StamTrackPhysExtAllocFailures);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPGMPOOLPHYSEXT pPhysExt = &pPool->CTX_SUFF(paPhysExts)[iPhysExt];
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Frees a physical cross reference extent.
907da3b41f191bef4c8eb94accb9d16fcbe77019vboxsync * @param pVM The VM handle.
6b022885f2cb6a55167609edecd89570cd80001dvboxsync * @param iPhysExt The extent to free.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncvoid pgmPoolTrackPhysExtFree(PVM pVM, uint16_t iPhysExt)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPGMPOOLPHYSEXT pPhysExt = &pPool->CTX_SUFF(paPhysExts)[iPhysExt];
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned i = 0; i < RT_ELEMENTS(pPhysExt->aidx); i++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Frees a physical cross reference extent.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM The VM handle.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param iPhysExt The extent to free.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncvoid pgmPoolTrackPhysExtFreeList(PVM pVM, uint16_t iPhysExt)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned i = 0; i < RT_ELEMENTS(pPhysExt->aidx); i++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Insert a reference into a list of physical cross reference extents.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns The new tracking data for PGMPAGE.
50df3da42ff6589b0ecc4f50f2288811bc370186vboxsync * @param pVM The VM handle.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param iPhysExt The physical extent index of the list head.
6b022885f2cb6a55167609edecd89570cd80001dvboxsync * @param iShwPT The shadow page table index.
e4ea543752422f1139923e3e506c625b0a1827c5vboxsync * @param iPte Page table entry
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic uint16_t pgmPoolTrackPhysExtInsert(PVM pVM, uint16_t iPhysExt, uint16_t iShwPT, uint16_t iPte)
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);
0138777a0eae9d74905d86f792f1f1c497dab65evboxsync LogFlow(("pgmPoolTrackPhysExtInsert: %d:{,,%d pte %d}\n", iPhysExt, iShwPT, iPte));
50df3da42ff6589b0ecc4f50f2288811bc370186vboxsync return PGMPOOL_TD_MAKE(PGMPOOL_TD_CREFS_PHYSEXT, iPhysExt);
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(("pgmPoolTrackPhysExtInsert: %d:{%d pte %d} i=%d cMax=%d\n", iPhysExt, iShwPT, iPte, i, cMax));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return PGMPOOL_TD_MAKE(PGMPOOL_TD_CREFS_PHYSEXT, iPhysExtStart);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolTrackPhysExtInsert: overflow (1) iShwPT=%d\n", iShwPT));
65ff326ac3915638f5c4e79c2c3e836aeeeb86devboxsync return PGMPOOL_TD_MAKE(PGMPOOL_TD_CREFS_PHYSEXT, PGMPOOL_TD_IDX_OVERFLOWED);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* add another extent to the list. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPGMPOOLPHYSEXT pNew = pgmPoolTrackPhysExtAlloc(pVM, &iPhysExt);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_COUNTER_INC(&pVM->pgm.s.StatTrackNoExtentsLeft);
50df3da42ff6589b0ecc4f50f2288811bc370186vboxsync LogFlow(("pgmPoolTrackPhysExtInsert: pgmPoolTrackPhysExtAlloc failed iShwPT=%d\n", iShwPT));
6b022885f2cb6a55167609edecd89570cd80001dvboxsync return PGMPOOL_TD_MAKE(PGMPOOL_TD_CREFS_PHYSEXT, PGMPOOL_TD_IDX_OVERFLOWED);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolTrackPhysExtInsert: added new extent %d:{%d pte %d}->%d\n", iPhysExt, iShwPT, iPte, iPhysExtStart));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return PGMPOOL_TD_MAKE(PGMPOOL_TD_CREFS_PHYSEXT, iPhysExt);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Add a reference to guest physical page where extents are in use.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns The new tracking data for PGMPAGE.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM The VM handle.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPhysPage Pointer to the aPages entry in the ram range.
e4ea543752422f1139923e3e506c625b0a1827c5vboxsync * @param u16 The ram range flags (top 16-bits).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param iShwPT The shadow page table index.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param iPte Page table entry
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncuint16_t pgmPoolTrackPhysExtAddref(PVM pVM, PPGMPAGE pPhysPage, uint16_t u16, uint16_t iShwPT, uint16_t iPte)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if (PGMPOOL_TD_GET_CREFS(u16) != PGMPOOL_TD_CREFS_PHYSEXT)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Convert to extent list.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPGMPOOLPHYSEXT pPhysExt = pgmPoolTrackPhysExtAlloc(pVM, &iPhysExt);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolTrackPhysExtAddref: new extent: %d:{%d, %d}\n", iPhysExt, PGMPOOL_TD_GET_IDX(u16), iShwPT));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPhysExt->apte[0] = PGM_PAGE_GET_PTE_INDEX(pPhysPage);
96fb9e5765400c1ad6e462d0a25680e2312dd54cvboxsync u16 = PGMPOOL_TD_MAKE(PGMPOOL_TD_CREFS_PHYSEXT, iPhysExt);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync u16 = PGMPOOL_TD_MAKE(PGMPOOL_TD_CREFS_PHYSEXT, PGMPOOL_TD_IDX_OVERFLOWED);
96fb9e5765400c1ad6e462d0a25680e2312dd54cvboxsync else if (u16 != PGMPOOL_TD_MAKE(PGMPOOL_TD_CREFS_PHYSEXT, PGMPOOL_TD_IDX_OVERFLOWED))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Insert into the extent list.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync u16 = pgmPoolTrackPhysExtInsert(pVM, PGMPOOL_TD_GET_IDX(u16), iShwPT, iPte);
65ff326ac3915638f5c4e79c2c3e836aeeeb86devboxsync STAM_COUNTER_INC(&pVM->pgm.s.StatTrackAliasedLots);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Clear references to guest physical memory.
d7f733dd34ab7755807d85016b7c2ab3d1a362d4vboxsync * @param pPool The pool.
65ff326ac3915638f5c4e79c2c3e836aeeeb86devboxsync * @param pPage The page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPhysPage Pointer to the aPages entry in the ram range.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param iPte Shadow PTE index
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncvoid pgmPoolTrackPhysExtDerefGCPhys(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PPGMPAGE pPhysPage, uint16_t iPte)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync const unsigned cRefs = PGM_PAGE_GET_TD_CREFS(pPhysPage);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertFatalMsg(cRefs == PGMPOOL_TD_CREFS_PHYSEXT, ("cRefs=%d pPhysPage=%R[pgmpage] pPage=%p:{.idx=%d}\n", cRefs, pPhysPage, pPage, pPage->idx));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync uint16_t iPhysExt = PGM_PAGE_GET_TD_IDX(pPhysPage);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPGMPOOLPHYSEXT paPhysExts = pPool->CTX_SUFF(paPhysExts);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Look for the shadow page and check if it's all freed.
65ff326ac3915638f5c4e79c2c3e836aeeeb86devboxsync for (unsigned i = 0; i < RT_ELEMENTS(paPhysExts[iPhysExt].aidx); i++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync paPhysExts[iPhysExt].apte[i] = NIL_PGMPOOL_PHYSEXT_IDX_PTE;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (i = 0; i < RT_ELEMENTS(paPhysExts[iPhysExt].aidx); i++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if (paPhysExts[iPhysExt].aidx[i] != NIL_PGMPOOL_IDX)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log2(("pgmPoolTrackPhysExtDerefGCPhys: pPhysPage=%R[pgmpage] idx=%d\n", pPhysPage, pPage->idx));
aaeb2e2f6ed5b164f1dec9a16a7adeb84f64cf31vboxsync /* we can free the node. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync const uint16_t iPhysExtNext = paPhysExts[iPhysExt].iNext;
65ff326ac3915638f5c4e79c2c3e836aeeeb86devboxsync /* lonely node */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log2(("pgmPoolTrackPhysExtDerefGCPhys: pPhysPage=%R[pgmpage] idx=%d lonely\n", pPhysPage, pPage->idx));
d7f733dd34ab7755807d85016b7c2ab3d1a362d4vboxsync else if (iPhysExtPrev == NIL_PGMPOOL_PHYSEXT_INDEX)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log2(("pgmPoolTrackPhysExtDerefGCPhys: pPhysPage=%R[pgmpage] idx=%d head\n", pPhysPage, pPage->idx));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PGM_PAGE_SET_TRACKING(pPhysPage, PGMPOOL_TD_MAKE(PGMPOOL_TD_CREFS_PHYSEXT, iPhysExtNext));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* in list */
e4ea543752422f1139923e3e506c625b0a1827c5vboxsync Log2(("pgmPoolTrackPhysExtDerefGCPhys: pPhysPage=%R[pgmpage] idx=%d in list\n", pPhysPage, pPage->idx));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertFatalMsgFailed(("not-found! cRefs=%d pPhysPage=%R[pgmpage] pPage=%p:{.idx=%d}\n", cRefs, pPhysPage, pPage, pPage->idx));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync else /* nothing to do */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log2(("pgmPoolTrackPhysExtDerefGCPhys: pPhysPage=%R[pgmpage]\n", pPhysPage));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Clear references to guest physical memory.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * This is the same as pgmPoolTracDerefGCPhys except that the guest physical address
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * is assumed to be correct, so the linear search can be skipped and we can assert
bee80f3f77b15c166b7debd080a70e5231ba6751vboxsync * at an earlier point.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param HCPhys The host physical address corresponding to the guest page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param GCPhys The guest physical address corresponding to HCPhys.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param iPte Shadow PTE index
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic void pgmPoolTracDerefGCPhys(PPGMPOOL pPool, PPGMPOOLPAGE pPage, RTHCPHYS HCPhys, RTGCPHYS GCPhys, uint16_t iPte)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Walk range list.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPGMRAMRANGE pRam = pPool->CTX_SUFF(pVM)->pgm.s.CTX_SUFF(pRamRanges);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* does it match? */
bee80f3f77b15c166b7debd080a70e5231ba6751vboxsync RTHCPHYS HCPhysPage = PGM_PAGE_GET_HCPHYS(&pRam->aPages[iPage]);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log2(("pgmPoolTracDerefGCPhys %RHp vs %RHp\n", HCPhysPage, HCPhys));
bee80f3f77b15c166b7debd080a70e5231ba6751vboxsync if (PGM_PAGE_GET_HCPHYS(&pRam->aPages[iPage]) == HCPhys)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmTrackDerefGCPhys(pPool, pPage, &pRam->aPages[iPage], iPte);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertFatalMsgFailed(("HCPhys=%RHp GCPhys=%RGp\n", HCPhys, GCPhys));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Clear references to guest physical memory.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
6b022885f2cb6a55167609edecd89570cd80001dvboxsync * @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.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param iPte Shadow pte index
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncvoid pgmPoolTracDerefGCPhysHint(PPGMPOOL pPool, PPGMPOOLPAGE pPage, RTHCPHYS HCPhys, RTGCPHYS GCPhysHint, uint16_t iPte)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log4(("pgmPoolTracDerefGCPhysHint %RHp %RGp\n", HCPhys, GCPhysHint));
fe49486f3c0fc3c327138e9a8f9ea9911d7c0d64vboxsync * Walk range list.
3cac8f8c6923a3a89ecfccda5e89ad75f48658e0vboxsync PPGMRAMRANGE pRam = pPool->CTX_SUFF(pVM)->pgm.s.CTX_SUFF(pRamRanges);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* does it match? */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if (PGM_PAGE_GET_HCPHYS(&pRam->aPages[iPage]) == HCPhys)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmTrackDerefGCPhys(pPool, pPage, &pRam->aPages[iPage], iPte);
fa7355597d7eba5b4ca8a23056ebe1b8fb306fdbvboxsync * 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);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync 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], iPte);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertFatalMsgFailed(("HCPhys=%RHp GCPhysHint=%RGp\n", HCPhys, GCPhysHint));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Clear references to guest physical memory in a 32-bit / 32-bit page table.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pShwPT The shadow page table (mapping of the page).
aaeb2e2f6ed5b164f1dec9a16a7adeb84f64cf31vboxsync * @param pGstPT The guest page table.
b1c3cdef473df2fbc621d5da81acc82dbfb8a11avboxsyncDECLINLINE(void) pgmPoolTrackDerefPT32Bit32Bit(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PT pShwPT, PCX86PT pGstPT)
aaeb2e2f6ed5b164f1dec9a16a7adeb84f64cf31vboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pShwPT->a); i++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log4(("pgmPoolTrackDerefPT32Bit32Bit: i=%d pte=%RX32 hint=%RX32\n",
6f516ad9911d9037a18778742caa955fe362f8ffvboxsync 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, i);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Clear references to guest physical memory in a PAE / 32-bit page table.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pShwPT The shadow page table (mapping of the page).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pGstPT The guest page table (just a half one).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncDECLINLINE(void) pgmPoolTrackDerefPTPae32Bit(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PTPAE pShwPT, PCX86PT pGstPT)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pShwPT->a); i++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log4(("pgmPoolTrackDerefPTPae32Bit: i=%d pte=%RX64 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, i);
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)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned i = pPage->iFirstPresent; 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));
eab582ddaaa130fc769ad00b09b81b3966817d3fvboxsync pgmPoolTracDerefGCPhysHint(pPool, pPage, pShwPT->a[i].u & X86_PTE_PAE_PG_MASK, pGstPT->a[i].u & X86_PTE_PAE_PG_MASK, i);
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)
eab582ddaaa130fc769ad00b09b81b3966817d3fvboxsync RTGCPHYS GCPhys = pPage->GCPhys + PAGE_SIZE * pPage->iFirstPresent;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pShwPT->a); i++, GCPhys += PAGE_SIZE)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log4(("pgmPoolTrackDerefPT32Bit4MB: i=%d pte=%RX32 GCPhys=%RGp\n",
eab582ddaaa130fc769ad00b09b81b3966817d3fvboxsync pgmPoolTracDerefGCPhys(pPool, pPage, pShwPT->a[i].u & X86_PTE_PG_MASK, GCPhys, i);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * 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)
eab582ddaaa130fc769ad00b09b81b3966817d3fvboxsync RTGCPHYS GCPhys = pPage->GCPhys + PAGE_SIZE * pPage->iFirstPresent;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pShwPT->a); i++, GCPhys += PAGE_SIZE)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log4(("pgmPoolTrackDerefPTPaeBig: i=%d pte=%RX64 hint=%RGp\n",
eab582ddaaa130fc769ad00b09b81b3966817d3fvboxsync pgmPoolTracDerefGCPhys(pPool, pPage, pShwPT->a[i].u & X86_PTE_PAE_PG_MASK, GCPhys, i);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Clear references to shadowed pages in an EPT 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) pgmPoolTrackDerefPTEPT(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PEPTPT pShwPT)
eab582ddaaa130fc769ad00b09b81b3966817d3fvboxsync RTGCPHYS GCPhys = pPage->GCPhys + PAGE_SIZE * pPage->iFirstPresent;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pShwPT->a); i++, GCPhys += PAGE_SIZE)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log4(("pgmPoolTrackDerefPTEPT: i=%d pte=%RX64 GCPhys=%RX64\n",
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync i, pShwPT->a[i].u & EPT_PTE_PG_MASK, pPage->GCPhys));
eab582ddaaa130fc769ad00b09b81b3966817d3fvboxsync pgmPoolTracDerefGCPhys(pPool, pPage, pShwPT->a[i].u & EPT_PTE_PG_MASK, GCPhys, i);
eab582ddaaa130fc769ad00b09b81b3966817d3fvboxsync * Clear references to shadowed pages in a 32 bits page directory.
eab582ddaaa130fc769ad00b09b81b3966817d3fvboxsync * @param pPool The pool.
eab582ddaaa130fc769ad00b09b81b3966817d3fvboxsync * @param pPage The page.
eab582ddaaa130fc769ad00b09b81b3966817d3fvboxsync * @param pShwPD The shadow page directory (mapping of the page).
eab582ddaaa130fc769ad00b09b81b3966817d3fvboxsyncDECLINLINE(void) pgmPoolTrackDerefPD(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PD pShwPD)
eab582ddaaa130fc769ad00b09b81b3966817d3fvboxsync for (unsigned i = 0; i < RT_ELEMENTS(pShwPD->a); i++)
eab582ddaaa130fc769ad00b09b81b3966817d3fvboxsync PPGMPOOLPAGE pSubPage = (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, pShwPD->a[i].u & X86_PDE_PG_MASK);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolTrackFreeUser(pPool, pSubPage, pPage->idx, i);
3cac8f8c6923a3a89ecfccda5e89ad75f48658e0vboxsync AssertFatalMsgFailed(("%x\n", pShwPD->a[i].u & X86_PDE_PG_MASK));
9f1e0743f565b1975bb4efd7311b30cfa0d3e384vboxsync * Clear references to shadowed pages in a PAE (legacy or 64 bits) page directory.
9f1e0743f565b1975bb4efd7311b30cfa0d3e384vboxsync * @param pPool The pool.
9f1e0743f565b1975bb4efd7311b30cfa0d3e384vboxsync * @param pPage The page.
9f1e0743f565b1975bb4efd7311b30cfa0d3e384vboxsync * @param pShwPD The shadow page directory (mapping of the page).
9f1e0743f565b1975bb4efd7311b30cfa0d3e384vboxsyncDECLINLINE(void) pgmPoolTrackDerefPDPae(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PDPAE pShwPD)
9f1e0743f565b1975bb4efd7311b30cfa0d3e384vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pShwPD->a); i++)
9f1e0743f565b1975bb4efd7311b30cfa0d3e384vboxsync Log4(("pgmPoolTrackDerefPDPae: i=%d pde=%RX64 GCPhys=%RX64\n",
9f1e0743f565b1975bb4efd7311b30cfa0d3e384vboxsync i, pShwPD->a[i].u & X86_PDE2M_PAE_PG_MASK, pPage->GCPhys));
9f1e0743f565b1975bb4efd7311b30cfa0d3e384vboxsync pgmPoolTracDerefGCPhys(pPool, pPage, pShwPD->a[i].u & X86_PDE2M_PAE_PG_MASK, pPage->GCPhys /* == base of 2 MB page */, 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 PAE page directory pointer table.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pShwPDPT The shadow page directory pointer table (mapping of the page).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncDECLINLINE(void) pgmPoolTrackDerefPDPTPae(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PDPT pShwPDPT)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned i = 0; i < X86_PG_PAE_PDPE_ENTRIES; i++)
ef4275be1971a6d17d45121d075a4f41659fa6c9vboxsync PPGMPOOLPAGE pSubPage = (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, pShwPDPT->a[i].u & X86_PDPE_PG_MASK);
ef4275be1971a6d17d45121d075a4f41659fa6c9vboxsync pgmPoolTrackFreeUser(pPool, pSubPage, pPage->idx, i);
ef4275be1971a6d17d45121d075a4f41659fa6c9vboxsync AssertFatalMsgFailed(("%RX64\n", pShwPDPT->a[i].u & X86_PDPE_PG_MASK));
ef4275be1971a6d17d45121d075a4f41659fa6c9vboxsync * Clear references to shadowed pages in a 64-bit page directory pointer table.
ef4275be1971a6d17d45121d075a4f41659fa6c9vboxsync * @param pPool The pool.
ef4275be1971a6d17d45121d075a4f41659fa6c9vboxsync * @param pPage The page.
ef4275be1971a6d17d45121d075a4f41659fa6c9vboxsync * @param pShwPDPT The shadow page directory pointer table (mapping of the page).
ef4275be1971a6d17d45121d075a4f41659fa6c9vboxsyncDECLINLINE(void) pgmPoolTrackDerefPDPT64Bit(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PDPT pShwPDPT)
ef4275be1971a6d17d45121d075a4f41659fa6c9vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pShwPDPT->a); i++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Assert(!(pShwPDPT->a[i].u & PGM_PLXFLAGS_MAPPING));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPGMPOOLPAGE pSubPage = (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, pShwPDPT->a[i].u & X86_PDPE_PG_MASK);
8f7bc6ad2b7bbcb4b3b96248cd2478e45f2e3b88vboxsync pgmPoolTrackFreeUser(pPool, pSubPage, pPage->idx, i);
8f7bc6ad2b7bbcb4b3b96248cd2478e45f2e3b88vboxsync 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.
8f7bc6ad2b7bbcb4b3b96248cd2478e45f2e3b88vboxsync * @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++)
40f47bc231ff6c86a7ddc3295eed7010e889e78avboxsync PPGMPOOLPAGE pSubPage = (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, pShwPML4->a[i].u & X86_PDPE_PG_MASK);
40f47bc231ff6c86a7ddc3295eed7010e889e78avboxsync pgmPoolTrackFreeUser(pPool, pSubPage, pPage->idx, i);
40f47bc231ff6c86a7ddc3295eed7010e889e78avboxsync AssertFatalMsgFailed(("%RX64\n", pShwPML4->a[i].u & X86_PML4E_PG_MASK));
40f47bc231ff6c86a7ddc3295eed7010e889e78avboxsync /** @todo 64-bit guests: have to ensure that we're not exhausting the dynamic mappings! */
40f47bc231ff6c86a7ddc3295eed7010e889e78avboxsync * Clear references to shadowed pages in an EPT page directory.
40f47bc231ff6c86a7ddc3295eed7010e889e78avboxsync * @param pPool The pool.
40f47bc231ff6c86a7ddc3295eed7010e889e78avboxsync * @param pPage The page.
40f47bc231ff6c86a7ddc3295eed7010e889e78avboxsync * @param pShwPD The shadow page directory (mapping of the page).
40f47bc231ff6c86a7ddc3295eed7010e889e78avboxsyncDECLINLINE(void) pgmPoolTrackDerefPDEPT(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PEPTPD pShwPD)
40f47bc231ff6c86a7ddc3295eed7010e889e78avboxsync for (unsigned i = 0; i < RT_ELEMENTS(pShwPD->a); i++)
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync Log4(("pgmPoolTrackDerefPDEPT: i=%d pde=%RX64 GCPhys=%RX64\n",
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync i, pShwPD->a[i].u & X86_PDE2M_PAE_PG_MASK, pPage->GCPhys));
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync pgmPoolTracDerefGCPhys(pPool, pPage, pShwPD->a[i].u & X86_PDE2M_PAE_PG_MASK, pPage->GCPhys /* == base of 2 MB page */, i);
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync PPGMPOOLPAGE pSubPage = (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, pShwPD->a[i].u & EPT_PDE_PG_MASK);
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync pgmPoolTrackFreeUser(pPool, pSubPage, pPage->idx, i);
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync AssertFatalMsgFailed(("%RX64\n", pShwPD->a[i].u & EPT_PDE_PG_MASK));
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync /** @todo 64-bit guests: have to ensure that we're not exhausting the dynamic mappings! */
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync * Clear references to shadowed pages in an EPT page directory pointer table.
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync * @param pPool The pool.
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync * @param pPage The page.
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync * @param pShwPDPT The shadow page directory pointer table (mapping of the page).
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsyncDECLINLINE(void) pgmPoolTrackDerefPDPTEPT(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PEPTPDPT pShwPDPT)
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync for (unsigned i = 0; i < RT_ELEMENTS(pShwPDPT->a); i++)
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync PPGMPOOLPAGE pSubPage = (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, pShwPDPT->a[i].u & EPT_PDPTE_PG_MASK);
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync pgmPoolTrackFreeUser(pPool, pSubPage, pPage->idx, i);
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync AssertFatalMsgFailed(("%RX64\n", pShwPDPT->a[i].u & EPT_PDPTE_PG_MASK));
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync /** @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.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic void pgmPoolTrackDeref(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Map the shadow page and take action according to the page kind.
22e281e75ed636601178296c6daebda8f1d17c59vboxsync void *pvShw = PGMPOOL_PAGE_2_LOCKED_PTR(pPool->CTX_SUFF(pVM), pPage);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_PROFILE_START(&pPool->StatTrackDerefGCPhys, g);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync int rc = PGM_GCPHYS_2_PTR(pPool->CTX_SUFF(pVM), pPage->GCPhys, &pvGst); AssertReleaseRC(rc);
6b022885f2cb6a55167609edecd89570cd80001dvboxsync pgmPoolTrackDerefPT32Bit32Bit(pPool, pPage, (PX86PT)pvShw, (PCX86PT)pvGst);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync 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);
6b022885f2cb6a55167609edecd89570cd80001dvboxsync pgmPoolTrackDerefPTPae32Bit(pPool, pPage, (PX86PTPAE)pvShw, (PCX86PT)pvGst);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_PROFILE_STOP(&pPool->StatTrackDerefGCPhys, g);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_PROFILE_START(&pPool->StatTrackDerefGCPhys, g);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync int rc = PGM_GCPHYS_2_PTR(pPool->CTX_SUFF(pVM), pPage->GCPhys, &pvGst); AssertReleaseRC(rc);
6b022885f2cb6a55167609edecd89570cd80001dvboxsync pgmPoolTrackDerefPTPaePae(pPool, pPage, (PX86PTPAE)pvShw, (PCX86PTPAE)pvGst);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_PROFILE_STOP(&pPool->StatTrackDerefGCPhys, g);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync case PGMPOOLKIND_32BIT_PT_FOR_PHYS: /* treat it like a 4 MB page */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_PROFILE_START(&pPool->StatTrackDerefGCPhys, g);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolTrackDerefPT32Bit4MB(pPool, pPage, (PX86PT)pvShw);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync 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);
9c425bdea5f0991df62922b1584b805a86f2f898vboxsync pgmPoolTrackDerefPDPae(pPool, pPage, (PX86PDPAE)pvShw);
10e1bc06b2908a0af56d92ffdbadd25b36a5ef61vboxsync pgmPoolTrackDerefPDPTPae(pPool, pPage, (PX86PDPT)pvShw);
14f2d81f7090ba5b7261e7c67a7f65c796d037f1vboxsync pgmPoolTrackDerefPDPT64Bit(pPool, pPage, (PX86PDPT)pvShw);
9f1e0743f565b1975bb4efd7311b30cfa0d3e384vboxsync pgmPoolTrackDerefPML464Bit(pPool, pPage, (PX86PML4)pvShw);
ef4275be1971a6d17d45121d075a4f41659fa6c9vboxsync pgmPoolTrackDerefPTEPT(pPool, pPage, (PEPTPT)pvShw);
8f7bc6ad2b7bbcb4b3b96248cd2478e45f2e3b88vboxsync pgmPoolTrackDerefPDEPT(pPool, pPage, (PEPTPD)pvShw);
5db1d52ffbcaa46c3d944c6c2d9c552306817d9avboxsync pgmPoolTrackDerefPDPTEPT(pPool, pPage, (PEPTPDPT)pvShw);
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync AssertFatalMsgFailed(("enmKind=%d\n", pPage->enmKind));
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync /* paranoia, clear the shadow page. Remove this laser (i.e. let Alloc and ClearAll do it). */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Flushes a pool page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * This moves the page to the free list after removing all user references to it.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VINF_SUCCESS on success.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param HCPhys The HC physical address of the shadow page.
22e281e75ed636601178296c6daebda8f1d17c59vboxsync * @param fFlush Flush the TLBS when required (should only be false in very specific use cases!!)
3cac8f8c6923a3a89ecfccda5e89ad75f48658e0vboxsyncint pgmPoolFlushPage(PPGMPOOL pPool, PPGMPOOLPAGE pPage, bool fFlush)
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.
3241f1be564f7351b07ce8a807673fa77a7847bcvboxsync Log(("pgmPoolFlushPage: special root page, rejected. enmKind=%s idx=%d\n", pgmPoolPoolKindToStr(pPage->enmKind), pPage->idx));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Quietly reject any attempts at flushing the currently active shadow CR3 mapping
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync AssertMsg( pPage->enmKind == PGMPOOLKIND_64BIT_PML4
1b7f3a92e42fb9cabf96cf31c20481da466edf76vboxsync || pPage->enmKind == PGMPOOLKIND_PAE_PDPT_FOR_32BIT
41b8e304f190c3d901bcfee5e73c11bc2c42ce13vboxsync || pPage->enmKind == PGMPOOLKIND_PAE_PD0_FOR_32BIT_PD
1b7f3a92e42fb9cabf96cf31c20481da466edf76vboxsync || pPage->enmKind == PGMPOOLKIND_PAE_PD1_FOR_32BIT_PD
1b7f3a92e42fb9cabf96cf31c20481da466edf76vboxsync || pPage->enmKind == PGMPOOLKIND_PAE_PD2_FOR_32BIT_PD
1b7f3a92e42fb9cabf96cf31c20481da466edf76vboxsync || pPage->enmKind == PGMPOOLKIND_PAE_PD3_FOR_32BIT_PD,
41b8e304f190c3d901bcfee5e73c11bc2c42ce13vboxsync ("Can't free the shadow CR3! (%RHp vs %RHp kind=%d\n", PGMGetHyperCR3(VMMGetCpu(pVM)), pPage->Core.Key, pPage->enmKind));
7e2fce486e7e2e45eb61d78ee206ba42ed89e016vboxsync Log(("pgmPoolFlushPage: current active shadow CR3, rejected. enmKind=%s idx=%d\n", pgmPoolPoolKindToStr(pPage->enmKind), pPage->idx));
7e2fce486e7e2e45eb61d78ee206ba42ed89e016vboxsync /* Start a subset so we won't run out of mapping space. */
7e2fce486e7e2e45eb61d78ee206ba42ed89e016vboxsync uint32_t iPrevSubset = PGMDynMapPushAutoSubset(pVCpu);
41b8e304f190c3d901bcfee5e73c11bc2c42ce13vboxsync * Mark the page as being in need of an ASMMemZeroPage().
41b8e304f190c3d901bcfee5e73c11bc2c42ce13vboxsync pgmPoolFlushDirtyPage(pVM, pPool, pPage->idxDirty, false /* do not remove */);
50e0e1bb8996934b3f38c117a456f825052bfb0cvboxsync /* If there are any users of this table, then we *must* issue a tlb flush on all VCPUs. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Clear the page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Flush it from the cache.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Heavy stuff done. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Deregistering the monitoring.
50e0e1bb8996934b3f38c117a456f825052bfb0cvboxsync * Free the page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Flush the TLBs of all VCPUs if required. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Frees a usage of a pool page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * 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)
afed5ab737f4aacfae3fe73776f40e989190a7cavboxsync 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));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolTrackFreeUser(pPool, pPage, iUser, iUserTable);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Makes one or more free page free.
750d4d0506a38b2e80c997075d40aad474e675fbvboxsync * @returns VBox status code.
41b8e304f190c3d901bcfee5e73c11bc2c42ce13vboxsync * @retval VINF_SUCCESS on success.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VERR_PGM_POOL_FLUSHED if the pool was flushed.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param enmKind Page table kind
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param iUser The user of the page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic int pgmPoolMakeMoreFreePages(PPGMPOOL pPool, PGMPOOLKIND enmKind, uint16_t iUser)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolMakeMoreFreePages: iUser=%#x\n", iUser));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * If the pool isn't full grown yet, expand it.
2885e130ed9e2da2cb7c2cced97ca1b5779d6e71vboxsync /* Hack alert: we can't deal with jumps to ring 3 when called from MapCR3 and allocating pages for PAE PDs. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync && (enmKind < PGMPOOLKIND_PAE_PD0_FOR_32BIT_PD || enmKind > PGMPOOLKIND_PAE_PD3_FOR_32BIT_PD)
5e0e35e65847aae0955835d5c4b4e76143e580c1vboxsync int rc = VMMRZCallRing3NoCpu(pVM, VMMCALLRING3_PGM_POOL_GROW, 0);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Free one cached page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Allocates a page from the pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * This page may actually be a cached page and not in need of any processing
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * on the callers part.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VINF_SUCCESS if a NEW page was allocated.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VINF_PGM_CACHED_PAGE if a CACHED page was returned.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VERR_PGM_POOL_FLUSHED if the pool was flushed.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM The VM handle.
26824086a3f6b36cd911058f1d9b4c0b944706fbvboxsync * @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.
750d4d0506a38b2e80c997075d40aad474e675fbvboxsync * @param enmAccess Access type for the mapping (only relevant for big pages)
750d4d0506a38b2e80c997075d40aad474e675fbvboxsync * @param iUser The shadow page pool index of the user table.
c657bea826c7455c93bd45eaebab63a4c7742c42vboxsync * @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.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param fLockPage Lock the page
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncint pgmPoolAllocEx(PVM pVM, RTGCPHYS GCPhys, PGMPOOLKIND enmKind, PGMPOOLACCESS enmAccess, uint16_t iUser, uint32_t iUserTable, PPPGMPOOLPAGE ppPage, bool fLockPage)
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?
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Assert(!(pVM->pgm.s.fGlobalSyncFlags & PGM_SYNC_CLEAR_PGM_POOL)); */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync int rc2 = pgmPoolCacheAlloc(pPool, GCPhys, enmKind, enmAccess, iUser, iUserTable, ppPage);
cb06e3f411d6ced5515682cddfbfa8ec463c6ff3vboxsync LogFlow(("pgmPoolAlloc: cached returns %Rrc *ppPage=%p:{.Key=%RHp, .idx=%d}\n", rc2, *ppPage, (*ppPage)->Core.Key, (*ppPage)->idx));
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync * Allocate a new one.
50cd04a47a3d04b52dbafe28921bff3d4c387841vboxsync rc = pgmPoolMakeMoreFreePages(pPool, enmKind, iUser);
cb06e3f411d6ced5515682cddfbfa8ec463c6ff3vboxsync AssertReleaseReturn(iNew != NIL_PGMPOOL_IDX, VERR_INTERNAL_ERROR);
8da94e4d6813b682cdb38eb9b151ada72d91b40evboxsync /* unlink the free head */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Initialize it.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPool->cUsedPages++; /* physical handler registration / pgmPoolTrackFlushGCPhysPTsSlow requirement. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync 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));
6ee326f4243bcf103c001da26f5d914360b6d312vboxsync * Commit the allocation, clear the page and return.
74991d7531692858fd22acf371a7ee941567977cvboxsync LogFlow(("pgmPoolAlloc: returns %Rrc *ppPage=%p:{.Key=%RHp, .idx=%d, .fCached=%RTbool, .fMonitored=%RTbool}\n",
74991d7531692858fd22acf371a7ee941567977cvboxsync rc, pPage, pPage->Core.Key, pPage->idx, pPage->fCached, pPage->fMonitored));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Frees a usage of a pool page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM The VM handle.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param HCPhys The HC physical address of the shadow page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param iUser The shadow page pool index of the user table.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param iUserTable The index into the user table (shadowed).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncvoid pgmPoolFree(PVM pVM, RTHCPHYS HCPhys, uint16_t iUser, uint32_t iUserTable)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolFree: HCPhys=%RHp iUser=%#x iUserTable=%#x\n", HCPhys, iUser, iUserTable));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolFreeByPage(pPool, pgmPoolGetPage(pPool, HCPhys), iUser, iUserTable);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Internal worker for finding a 'in-use' shadow page give by it's physical address.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns Pointer to the shadow page structure.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
cb06e3f411d6ced5515682cddfbfa8ec463c6ff3vboxsync * @param HCPhys The HC physical address of the shadow page.
50cd04a47a3d04b52dbafe28921bff3d4c387841vboxsyncPPGMPOOLPAGE pgmPoolGetPage(PPGMPOOL pPool, RTHCPHYS HCPhys)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Look up the page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPGMPOOLPAGE pPage = (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, HCPhys & X86_PTE_PAE_PG_MASK);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertFatalMsg(pPage && pPage->enmKind != PGMPOOLKIND_FREE, ("HCPhys=%RHp pPage=%p idx=%d\n", HCPhys, pPage, (pPage) ? pPage->idx : 0));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync#ifdef IN_RING3 /* currently only used in ring 3; save some space in the R0 & GC modules (left it here as we might need it elsewhere later on) */
50df3da42ff6589b0ecc4f50f2288811bc370186vboxsync * Flush the specified page if present
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM The VM handle.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param GCPhys Guest physical address of the page to flush
a4eb337e9a5a6a72bcfe50134dc42732f5ee65c0vboxsyncvoid pgmPoolFlushPageByGCPhys(PVM pVM, RTGCPHYS GCPhys)
a4eb337e9a5a6a72bcfe50134dc42732f5ee65c0vboxsync * Look up the GCPhys in the hash.
8729218d00f8b764686a331b45a1b6de0d0e293evboxsync Log(("PGMPoolFlushPage: found pgm pool pages for %RGp\n", GCPhys));
13b9db9ae2c12b6c4e00eda5c79772d57a0d29e1vboxsync /* ignore, no monitoring. */
13b9db9ae2c12b6c4e00eda5c79772d57a0d29e1vboxsync AssertFatalMsgFailed(("enmKind=%d idx=%d\n", pPage->enmKind, pPage->idx));
18928869a28716fc7ccd4255ba7d282cda027affvboxsync } while (i != NIL_PGMPOOL_IDX);
13b9db9ae2c12b6c4e00eda5c79772d57a0d29e1vboxsync#endif /* IN_RING3 */
13b9db9ae2c12b6c4e00eda5c79772d57a0d29e1vboxsync * Reset CPU on hot plugging.
13b9db9ae2c12b6c4e00eda5c79772d57a0d29e1vboxsync * @param pVM The VM handle.
13b9db9ae2c12b6c4e00eda5c79772d57a0d29e1vboxsync * @param pVCpu The virtual CPU.
13b9db9ae2c12b6c4e00eda5c79772d57a0d29e1vboxsyncvoid pgmR3PoolResetUnpluggedCpu(PVM pVM, PVMCPU pVCpu)
13b9db9ae2c12b6c4e00eda5c79772d57a0d29e1vboxsync * Flushes the entire cache.
13b9db9ae2c12b6c4e00eda5c79772d57a0d29e1vboxsync * It will assert a global CR3 flush (FF) and assumes the caller is aware of
13b9db9ae2c12b6c4e00eda5c79772d57a0d29e1vboxsync * this and execute this CR3 flush.
13b9db9ae2c12b6c4e00eda5c79772d57a0d29e1vboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * If there are no pages in the pool, there is nothing to do.
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync * Exit the shadow mode since we're going to clear everything,
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync * including the root page.
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync * Nuke the free list and reinsert all pages into it.
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync for (unsigned i = pPool->cCurPages - 1; i >= PGMPOOL_IDX_FIRST; i--)
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync Assert(pPage->Core.Key == MMPage2Phys(pVM, pPage->pvPageR3));
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync pPage->fZeroed = false; /* This could probably be optimized, but better safe than sorry. */
74991d7531692858fd22acf371a7ee941567977cvboxsync pPool->aPages[pPool->cCurPages - 1].iNext = NIL_PGMPOOL_IDX;
74991d7531692858fd22acf371a7ee941567977cvboxsync * Zap and reinitialize the user records.
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync for (unsigned i = 0; i < cMaxUsers; i++)
74991d7531692858fd22acf371a7ee941567977cvboxsync paUsers[cMaxUsers - 1].iNext = NIL_PGMPOOL_USER_INDEX;
74991d7531692858fd22acf371a7ee941567977cvboxsync * Clear all the GCPhys links and rebuild the phys ext free list.
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync for (PPGMRAMRANGE pRam = pVM->pgm.s.CTX_SUFF(pRamRanges);
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync while (iPage-- > 0)
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync PPGMPOOLPHYSEXT paPhysExts = pPool->CTX_SUFF(paPhysExts);
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync for (unsigned i = 0; i < cMaxPhysExts; i++)
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync paPhysExts[i].apte[0] = NIL_PGMPOOL_PHYSEXT_IDX_PTE;
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync paPhysExts[i].apte[1] = NIL_PGMPOOL_PHYSEXT_IDX_PTE;
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync paPhysExts[i].apte[2] = NIL_PGMPOOL_PHYSEXT_IDX_PTE;
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync paPhysExts[cMaxPhysExts - 1].iNext = NIL_PGMPOOL_PHYSEXT_INDEX;
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync * Just zap the modified list.
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync * Clear the GCPhys hash and the age list.
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pPool->aiHash); i++)
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync /* Clear all dirty pages. */
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pPool->aIdxDirtyPages); i++)
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync * Reinsert active pages into the hash and ensure monitoring chains are correct.
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync for (unsigned i = PGMPOOL_IDX_FIRST_SPECIAL; i < PGMPOOL_IDX_FIRST; i++)
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync /* ASSUMES that we're not sharing with any of the other special pages (safe for now). */
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync int rc = PGMHandlerPhysicalChangeCallbacks(pVM, pPage->GCPhys & ~(RTGCPHYS)(PAGE_SIZE - 1),
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync pPool->pfnAccessHandlerR3, MMHyperCCToR3(pVM, pPage),
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync pPool->pfnAccessHandlerR0, MMHyperCCToR0(pVM, pPage),
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync pPool->pfnAccessHandlerRC, MMHyperCCToRC(pVM, pPage),
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync Assert(pPage->iUserHead == NIL_PGMPOOL_USER_INDEX); /* for now */
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync * Re-enter the shadowing mode and assert Sync CR3 FF.
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync#endif /* IN_RING3 */
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsyncstatic const char *pgmPoolPoolKindToStr(uint8_t enmKind)
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync return "PGMPOOLKIND_INVALID";
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync return "PGMPOOLKIND_FREE";
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync return "PGMPOOLKIND_32BIT_PT_FOR_PHYS";
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync return "PGMPOOLKIND_32BIT_PT_FOR_32BIT_PT";
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync return "PGMPOOLKIND_32BIT_PT_FOR_32BIT_4MB";
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync return "PGMPOOLKIND_PAE_PT_FOR_PHYS";
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync return "PGMPOOLKIND_PAE_PT_FOR_32BIT_PT";
e17f587595bd5d3a7be56a892e3fd3a0ef83d268vboxsync return "PGMPOOLKIND_PAE_PT_FOR_32BIT_4MB";
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync return "PGMPOOLKIND_PAE_PT_FOR_PAE_PT";
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync return "PGMPOOLKIND_PAE_PT_FOR_PAE_2MB";
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync return "PGMPOOLKIND_32BIT_PD";
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync return "PGMPOOLKIND_32BIT_PD_PHYS";
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync return "PGMPOOLKIND_PAE_PD0_FOR_32BIT_PD";
d410f63700f660eab1bbf8d6e107b6b7373fee72vboxsync return "PGMPOOLKIND_PAE_PD1_FOR_32BIT_PD";
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync return "PGMPOOLKIND_PAE_PD2_FOR_32BIT_PD";
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync return "PGMPOOLKIND_PAE_PD3_FOR_32BIT_PD";
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync return "PGMPOOLKIND_PAE_PD_FOR_PAE_PD";
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync return "PGMPOOLKIND_PAE_PD_PHYS";
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync return "PGMPOOLKIND_PAE_PDPT_FOR_32BIT";
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync return "PGMPOOLKIND_PAE_PDPT";
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync return "PGMPOOLKIND_PAE_PDPT_PHYS";
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync return "PGMPOOLKIND_64BIT_PDPT_FOR_64BIT_PDPT";
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync return "PGMPOOLKIND_64BIT_PDPT_FOR_PHYS";
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync return "PGMPOOLKIND_64BIT_PD_FOR_64BIT_PD";
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync return "PGMPOOLKIND_64BIT_PD_FOR_PHYS";
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync return "PGMPOOLKIND_64BIT_PML4";
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync return "PGMPOOLKIND_EPT_PDPT_FOR_PHYS";
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync return "PGMPOOLKIND_EPT_PD_FOR_PHYS";
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync return "PGMPOOLKIND_EPT_PT_FOR_PHYS";
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync return "PGMPOOLKIND_ROOT_NESTED";
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync return "Unknown kind!";
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync#endif /* LOG_ENABLED*/