PGMAllPool.cpp revision 681380880d4131019871e8f22cb3349b757168ca
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * PGM Shadow Page Pool.
3f1e0eea71cabeb90529e546f16eb7aee513fde9vboxsync * Copyright (C) 2006-2010 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.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync/*******************************************************************************
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync* Header Files *
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync*******************************************************************************/
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync/*******************************************************************************
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync* Internal Functions *
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync*******************************************************************************/
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncDECLINLINE(unsigned) pgmPoolTrackGetShadowEntrySize(PGMPOOLKIND enmKind);
223cf005b18af2c21352a70693ebaf0582f68ebcvboxsyncDECLINLINE(unsigned) pgmPoolTrackGetGuestEntrySize(PGMPOOLKIND enmKind);
223cf005b18af2c21352a70693ebaf0582f68ebcvboxsyncstatic void pgmPoolTrackDeref(PPGMPOOL pPool, PPGMPOOLPAGE pPage);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic int pgmPoolTrackAddUser(PPGMPOOL pPool, PPGMPOOLPAGE pPage, uint16_t iUser, uint32_t iUserTable);
afed5ab737f4aacfae3fe73776f40e989190a7cavboxsyncstatic void pgmPoolMonitorModifiedRemove(PPGMPOOL pPool, PPGMPOOLPAGE pPage);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncDECLEXPORT(int) pgmPoolAccessHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPHYS GCPhysFault, void *pvUser);
0174432b2b1a760b89840ba696f7ba51def65dddvboxsyncstatic const char *pgmPoolPoolKindToStr(uint8_t enmKind);
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync#if 0 /*defined(VBOX_STRICT) && defined(PGMPOOL_WITH_OPTIMIZED_DIRTY_PT)*/
614cbe11a7e5588dc8d369e223174b1441a09359vboxsyncstatic void pgmPoolTrackCheckPTPaePae(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PPGMSHWPTPAE pShwPT, PCX86PTPAE pGstPT);
7666082b743c5e146a8cee6cc794ff4bc3fd0ffdvboxsyncint pgmPoolTrackFlushGCPhysPTsSlow(PVM pVM, PPGMPAGE pPhysPage);
7666082b743c5e146a8cee6cc794ff4bc3fd0ffdvboxsyncPPGMPOOLPHYSEXT pgmPoolTrackPhysExtAlloc(PVM pVM, uint16_t *piPhysExt);
7666082b743c5e146a8cee6cc794ff4bc3fd0ffdvboxsyncvoid pgmPoolTrackPhysExtFree(PVM pVM, uint16_t iPhysExt);
7666082b743c5e146a8cee6cc794ff4bc3fd0ffdvboxsyncvoid pgmPoolTrackPhysExtFreeList(PVM pVM, uint16_t iPhysExt);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Checks if the specified page pool kind is for a 4MB or 2MB guest page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns true if it's the shadow of a 4MB or 2MB guest page, otherwise false.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param enmKind The page kind.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncDECLINLINE(bool) pgmPoolIsBigPage(PGMPOOLKIND enmKind)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return true;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return false;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Flushes a chain of pages sharing the same access monitor.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code suitable for scheduling.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage A page in the chain.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @todo VBOXSTRICTRC
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.
223cf005b18af2c21352a70693ebaf0582f68ebcvboxsync * @returns VBox status code suitable for scheduling.
b74ca013e5f201a2dd371e6c438433ceac12af30vboxsync * @param pVM Pointer to the VM.
b74ca013e5f201a2dd371e6c438433ceac12af30vboxsync * @param pvDst Destination address
b74ca013e5f201a2dd371e6c438433ceac12af30vboxsync * @param pvSrc Source guest virtual address.
b74ca013e5f201a2dd371e6c438433ceac12af30vboxsync * @param GCPhysSrc The source guest physical address.
b74ca013e5f201a2dd371e6c438433ceac12af30vboxsync * @param cb Size of data to read
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncDECLINLINE(int) pgmPoolPhysSimpleReadGCPhys(PVM pVM, void *pvDst, CTXTYPE(RTGCPTR, RTHCPTR, RTGCPTR) pvSrc,
b74ca013e5f201a2dd371e6c438433ceac12af30vboxsync memcpy(pvDst, (RTHCPTR)((uintptr_t)pvSrc & ~(RTHCUINTPTR)(cb - 1)), cb);
b74ca013e5f201a2dd371e6c438433ceac12af30vboxsync /* @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.
42c1972c22e09797b4b24afbd0ec114ed076c37cvboxsync * 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.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVCpu Pointer to the VMCPU.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The head page.
9e4166cf5ed4940f506bc718ea6c89bf7ed252c8vboxsync * @param GCPhysFault The guest physical fault address.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param uAddress In R0 and GC this is the guest context fault address (flat).
9e4166cf5ed4940f506bc718ea6c89bf7ed252c8vboxsync * In R3 this is the host context 'fault' address.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param cbWrite Write size; might be zero if the caller knows we're not crossing entry boundaries
e08de24d4792d31b7f2aac29db5cb8840d940009vboxsyncvoid pgmPoolMonitorChainChanging(PVMCPU pVCpu, PPGMPOOL pPool, PPGMPOOLPAGE pPage, RTGCPHYS GCPhysFault,
22e281e75ed636601178296c6daebda8f1d17c59vboxsync CTXTYPE(RTGCPTR, RTHCPTR, RTGCPTR) pvAddress, unsigned cbWrite)
69deddbc68802f1cf1c3a404a9f816b8accb3385vboxsync AssertMsg(pPage->iMonitoredPrev == NIL_PGMPOOL_IDX, ("%u (idx=%u)\n", pPage->iMonitoredPrev, pPage->idx));
3ecd8008b81f02a04220705ae0033142af363280vboxsync 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));
22e281e75ed636601178296c6daebda8f1d17c59vboxsync LogFlow(("PGMPOOLKIND_32BIT_PT_FOR_32BIT_PT iShw=%x\n", iShw));
82e90599291da476b2de7c8db33cfb0f2cbac774vboxsync int rc = pgmPoolPhysSimpleReadGCPhys(pVM, &GstPte, pvAddress, GCPhysFault, sizeof(GstPte));
4b8fcf8e4d11536879a1f6e66279ba0c363a7eaevboxsync 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 */
247b55faa8d054157f2481e68caca36f4dc9542cvboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,FaultPT));
22e281e75ed636601178296c6daebda8f1d17c59vboxsync const unsigned iShw = (off / sizeof(X86PTE)) & (X86_PG_PAE_ENTRIES - 1);
b74ca013e5f201a2dd371e6c438433ceac12af30vboxsync LogFlow(("PGMPOOLKIND_PAE_PT_FOR_32BIT_PT iShw=%x\n", iShw));
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync int rc = pgmPoolPhysSimpleReadGCPhys(pVM, &GstPte, pvAddress, GCPhysFault, sizeof(GstPte));
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync 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));
533ffcb943c4af2c5fe6385d816d0ba3eda9383bvboxsync 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));
13ba5527caaa9b8c4fee29f22e374fa67c4c6f72vboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,FaultPD));
1843553dbdf4e46417158b4c6348c503adf10740vboxsync if (iShwPdpt == pPage->enmKind - (unsigned)PGMPOOLKIND_PAE_PD0_FOR_32BIT_PD)
1999ae03c34840fa4d712fd2e020120b2cb7182avboxsync for (unsigned i = 0; i < 2; i++)
806d0b554daa555364af5f87bc96eccbe760db7avboxsync if ((uShw.pPDPae->a[iShw + i].u & (PGM_PDFLAGS_MAPPING | X86_PDE_P)) == (PGM_PDFLAGS_MAPPING | X86_PDE_P))
1843553dbdf4e46417158b4c6348c503adf10740vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShwPdpt=%#x iShw=%#x!\n", iShwPdpt, iShw+i));
22e281e75ed636601178296c6daebda8f1d17c59vboxsync# endif /* !IN_RING0 */
1843553dbdf4e46417158b4c6348c503adf10740vboxsync LogFlow(("pgmPoolMonitorChainChanging: pae pd iShw=%#x: %RX64 -> freeing it!\n", iShw+i, uShw.pPDPae->a[iShw+i].u));
1843553dbdf4e46417158b4c6348c503adf10740vboxsync /* paranoia / a bit assumptive. */
1843553dbdf4e46417158b4c6348c503adf10740vboxsync if ((uShw.pPDPae->a[iShw2].u & (PGM_PDFLAGS_MAPPING | X86_PDE_P)) == (PGM_PDFLAGS_MAPPING | X86_PDE_P))
13ba5527caaa9b8c4fee29f22e374fa67c4c6f72vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShwPdpt=%#x iShw2=%#x!\n", iShwPdpt, iShw2));
1843553dbdf4e46417158b4c6348c503adf10740vboxsync# endif /* !IN_RING0 */
1843553dbdf4e46417158b4c6348c503adf10740vboxsync LogFlow(("pgmPoolMonitorChainChanging: pae pd iShw=%#x: %RX64 -> freeing it!\n", iShw2, uShw.pPDPae->a[iShw2].u));
b74ca013e5f201a2dd371e6c438433ceac12af30vboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,FaultPT));
b40179b44fea65b72b2f226f62af1ed7bd3c48fcvboxsync int rc = pgmPoolPhysSimpleReadGCPhys(pVM, &GstPte, pvAddress, GCPhysFault, sizeof(GstPte));
b40179b44fea65b72b2f226f62af1ed7bd3c48fcvboxsync Log4(("pgmPoolMonitorChainChanging pae: deref %016RX64 GCPhys %016RX64\n", PGMSHWPTEPAE_GET_HCPHYS(uShw.pPTPae->a[iShw]), GstPte.u & X86_PTE_PAE_PG_MASK));
0e77737b0ba913683e614db11463b31ca67aacbevboxsync /* paranoia / a bit assumptive. */
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync const unsigned iShw2 = (off + cbWrite - 1) / sizeof(X86PTEPAE);
b74ca013e5f201a2dd371e6c438433ceac12af30vboxsync int rc = pgmPoolPhysSimpleReadGCPhys(pVM, &GstPte, (RTHCPTR)((RTHCUINTPTR)pvAddress + sizeof(GstPte)), GCPhysFault + sizeof(GstPte), sizeof(GstPte));
b40179b44fea65b72b2f226f62af1ed7bd3c48fcvboxsync int rc = pgmPoolPhysSimpleReadGCPhys(pVM, &GstPte, pvAddress + sizeof(GstPte), GCPhysFault + sizeof(GstPte), sizeof(GstPte));
b40179b44fea65b72b2f226f62af1ed7bd3c48fcvboxsync Log4(("pgmPoolMonitorChainChanging pae: deref %016RX64 GCPhys %016RX64\n", PGMSHWPTEPAE_GET_HCPHYS(uShw.pPTPae->a[iShw2]), GstPte.u & X86_PTE_PAE_PG_MASK));
b978e5849454446957177fd47ee98609ab0457a6vboxsync const unsigned iShw = off / sizeof(X86PTE); // ASSUMING 32-bit guest paging!
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolMonitorChainChanging: PGMPOOLKIND_32BIT_PD %x\n", iShw));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,FaultPD));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_COUNTER_INC(&(pVCpu->pgm.s.CTX_SUFF(pStats)->StatRZGuestCR3WriteConflict));
13ba5527caaa9b8c4fee29f22e374fa67c4c6f72vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw=%#x!\n", iShw));
13ba5527caaa9b8c4fee29f22e374fa67c4c6f72vboxsync# endif /* !IN_RING0 */
806d0b554daa555364af5f87bc96eccbe760db7avboxsync# endif /* !IN_RING0 */
806d0b554daa555364af5f87bc96eccbe760db7avboxsync 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);
e149c362e69e5f0bbd82da11fd8163b2d29c3a72vboxsync STAM_COUNTER_INC(&(pVCpu->pgm.s.CTX_SUFF(pStats)->StatRZGuestCR3WriteConflict));
13ba5527caaa9b8c4fee29f22e374fa67c4c6f72vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw2=%#x!\n", iShw2));
13ba5527caaa9b8c4fee29f22e374fa67c4c6f72vboxsync# endif /* !IN_RING0 */
806d0b554daa555364af5f87bc96eccbe760db7avboxsync LogFlow(("pgmPoolMonitorChainChanging: 32 bit pd iShw=%#x: %RX64 -> freeing it!\n", iShw2, uShw.pPD->a[iShw2].u));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync#if 0 /* useful when running PGMAssertCR3(), a bit too troublesome for general use (TLBs). */
e0b9d3c357adf9b7d05f55540e86f22943fc4b23vboxsync LogFlow(("pgmPoolMonitorChainChanging: iShw=%#x: %RX32 -> freeing it!\n", iShw, uShw.pPD->a[iShw].u));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync# 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);
9984bae4ef25be8afd95d184308adcfef6e2ec0dvboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,FaultPD));
1999ae03c34840fa4d712fd2e020120b2cb7182avboxsync STAM_COUNTER_INC(&(pVCpu->pgm.s.CTX_SUFF(pStats)->StatRZGuestCR3WriteConflict));
e0b9d3c357adf9b7d05f55540e86f22943fc4b23vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw=%#x!\n", iShw));
806d0b554daa555364af5f87bc96eccbe760db7avboxsync#endif /* !IN_RING0 */
13ba5527caaa9b8c4fee29f22e374fa67c4c6f72vboxsync * Causes trouble when the guest uses a PDE to refer to the whole page table level
3cac8f8c6923a3a89ecfccda5e89ad75f48658e0vboxsync * structure. (Invalidate here; faults later on when it tries to change the page
3cac8f8c6923a3a89ecfccda5e89ad75f48658e0vboxsync * table entries -> recheck; probably only applies to the RC case.)
1157941288c9533575a655c660af55d13da31eefvboxsync# endif /* !IN_RING0 */
5e797edc29f96c8367de4fbf5874171c24a89ba7vboxsync LogFlow(("pgmPoolMonitorChainChanging: pae pd iShw=%#x: %RX64 -> freeing it!\n", iShw, uShw.pPDPae->a[iShw].u));
5e797edc29f96c8367de4fbf5874171c24a89ba7vboxsync /* paranoia / a bit assumptive. */
9e4166cf5ed4940f506bc718ea6c89bf7ed252c8vboxsync const unsigned iShw2 = (off + cbWrite - 1) / sizeof(X86PDEPAE);
1999ae03c34840fa4d712fd2e020120b2cb7182avboxsync STAM_COUNTER_INC(&(pVCpu->pgm.s.CTX_SUFF(pStats)->StatRZGuestCR3WriteConflict));
e0b9d3c357adf9b7d05f55540e86f22943fc4b23vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw2=%#x!\n", iShw2));
e149c362e69e5f0bbd82da11fd8163b2d29c3a72vboxsync#endif /* !IN_RING0 */
13ba5527caaa9b8c4fee29f22e374fa67c4c6f72vboxsync# endif /* !IN_RING0 */
13ba5527caaa9b8c4fee29f22e374fa67c4c6f72vboxsync LogFlow(("pgmPoolMonitorChainChanging: pae pd iShw2=%#x: %RX64 -> freeing it!\n", iShw2, uShw.pPDPae->a[iShw2].u));
3080f6c0871099df43a4e91b31894d9c2b1369a8vboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,FaultPDPT));
b978e5849454446957177fd47ee98609ab0457a6vboxsync * Hopefully this doesn't happen very often:
3cac8f8c6923a3a89ecfccda5e89ad75f48658e0vboxsync * - touching unused parts of the page
3cac8f8c6923a3a89ecfccda5e89ad75f48658e0vboxsync * - messing with the bits of pd pointers without changing the physical address
7082d29724f6c3788977a51591b0379fd3acbf72vboxsync /* PDPT roots are not page aligned; 32 byte only! */
7082d29724f6c3788977a51591b0379fd3acbf72vboxsync const unsigned offPdpt = GCPhysFault - pPage->GCPhys;
9984bae4ef25be8afd95d184308adcfef6e2ec0dvboxsync if (iShw < X86_PG_PAE_PDPE_ENTRIES) /* don't use RT_ELEMENTS(uShw.pPDPT->a), because that's for long mode only */
f9147fe1eaa4e35287f8f39282c7f92f0d7de0b7vboxsync STAM_COUNTER_INC(&(pVCpu->pgm.s.CTX_SUFF(pStats)->StatRZGuestCR3WriteConflict));
1986f56777969a25707ab214f8dd070804be666cvboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected pdpt conflict at iShw=%#x!\n", iShw));
806d0b554daa555364af5f87bc96eccbe760db7avboxsync# endif /* !IN_RING0 */
13ba5527caaa9b8c4fee29f22e374fa67c4c6f72vboxsync# endif /* !IN_RING0 */
6f0193f5a9287559d34a75f438c2682d8fb08038vboxsync LogFlow(("pgmPoolMonitorChainChanging: pae pdpt iShw=%#x: %RX64 -> freeing it!\n", iShw, uShw.pPDPT->a[iShw].u));
6f0193f5a9287559d34a75f438c2682d8fb08038vboxsync /* paranoia / a bit assumptive. */
9e4166cf5ed4940f506bc718ea6c89bf7ed252c8vboxsync const unsigned iShw2 = (offPdpt + cbWrite - 1) / sizeof(X86PDPE);
6f0193f5a9287559d34a75f438c2682d8fb08038vboxsync STAM_COUNTER_INC(&(pVCpu->pgm.s.CTX_SUFF(pStats)->StatRZGuestCR3WriteConflict));
1986f56777969a25707ab214f8dd070804be666cvboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw2=%#x!\n", iShw2));
e149c362e69e5f0bbd82da11fd8163b2d29c3a72vboxsync# endif /* !IN_RING0 */
13ba5527caaa9b8c4fee29f22e374fa67c4c6f72vboxsync# endif /* !IN_RING0 */
6f0193f5a9287559d34a75f438c2682d8fb08038vboxsync LogFlow(("pgmPoolMonitorChainChanging: pae pdpt iShw=%#x: %RX64 -> freeing it!\n", iShw2, uShw.pPDPT->a[iShw2].u));
65b61798a61dd4c32cce448db1dac70bba8d5cf5vboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,FaultPD));
9984bae4ef25be8afd95d184308adcfef6e2ec0dvboxsync 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));
4b8fcf8e4d11536879a1f6e66279ba0c363a7eaevboxsync /* paranoia / a bit assumptive. */
9e4166cf5ed4940f506bc718ea6c89bf7ed252c8vboxsync const unsigned iShw2 = (off + cbWrite - 1) / sizeof(X86PDEPAE);
22e281e75ed636601178296c6daebda8f1d17c59vboxsync Assert(!(uShw.pPDPae->a[iShw2].u & PGM_PDFLAGS_MAPPING));
65b61798a61dd4c32cce448db1dac70bba8d5cf5vboxsync LogFlow(("pgmPoolMonitorChainChanging: pae pd iShw2=%#x: %RX64 -> freeing it!\n", iShw2, uShw.pPDPae->a[iShw2].u));
46df4404c8dbbf3672e7aae8cd0b2770356e5b73vboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,FaultPDPT));
b978e5849454446957177fd47ee98609ab0457a6vboxsync * Hopefully this doesn't happen very often:
3cac8f8c6923a3a89ecfccda5e89ad75f48658e0vboxsync * - messing with the bits of pd pointers without changing the physical address
ce2d2eef2525963979102e63c2419d1c69d767ccvboxsync LogFlow(("pgmPoolMonitorChainChanging: pdpt iShw=%#x: %RX64 -> freeing it!\n", iShw, uShw.pPDPT->a[iShw].u));
46df4404c8dbbf3672e7aae8cd0b2770356e5b73vboxsync pgmPoolFree(pVM, uShw.pPDPT->a[iShw].u & X86_PDPE_PG_MASK, pPage->idx, iShw);
4b8fcf8e4d11536879a1f6e66279ba0c363a7eaevboxsync /* paranoia / a bit assumptive. */
9e4166cf5ed4940f506bc718ea6c89bf7ed252c8vboxsync const unsigned iShw2 = (off + cbWrite - 1) / sizeof(X86PDPE);
ce2d2eef2525963979102e63c2419d1c69d767ccvboxsync LogFlow(("pgmPoolMonitorChainChanging: pdpt iShw2=%#x: %RX64 -> freeing it!\n", iShw2, uShw.pPDPT->a[iShw2].u));
3dde2f85d4cf477621a3128887a2c08a8bca7c01vboxsync pgmPoolFree(pVM, uShw.pPDPT->a[iShw2].u & X86_PDPE_PG_MASK, pPage->idx, iShw2);
5db1d52ffbcaa46c3d944c6c2d9c552306817d9avboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,FaultPML4));
b978e5849454446957177fd47ee98609ab0457a6vboxsync * Hopefully this doesn't happen very often:
3cac8f8c6923a3a89ecfccda5e89ad75f48658e0vboxsync * - messing with the bits of pd pointers without changing the physical address
ce2d2eef2525963979102e63c2419d1c69d767ccvboxsync LogFlow(("pgmPoolMonitorChainChanging: pml4 iShw=%#x: %RX64 -> freeing it!\n", iShw, uShw.pPML4->a[iShw].u));
585f64d6f624f9e683321dabeb21b0eb2e6aa473vboxsync pgmPoolFree(pVM, uShw.pPML4->a[iShw].u & X86_PML4E_PG_MASK, pPage->idx, iShw);
4b8fcf8e4d11536879a1f6e66279ba0c363a7eaevboxsync /* paranoia / a bit assumptive. */
9e4166cf5ed4940f506bc718ea6c89bf7ed252c8vboxsync const unsigned iShw2 = (off + cbWrite - 1) / sizeof(X86PML4E);
ce2d2eef2525963979102e63c2419d1c69d767ccvboxsync LogFlow(("pgmPoolMonitorChainChanging: pml4 iShw2=%#x: %RX64 -> freeing it!\n", iShw2, uShw.pPML4->a[iShw2].u));
585f64d6f624f9e683321dabeb21b0eb2e6aa473vboxsync pgmPoolFree(pVM, uShw.pPML4->a[iShw2].u & X86_PML4E_PG_MASK, pPage->idx, iShw2);
585f64d6f624f9e683321dabeb21b0eb2e6aa473vboxsync#endif /* IN_RING0 */
585f64d6f624f9e683321dabeb21b0eb2e6aa473vboxsync AssertFatalMsgFailed(("enmKind=%d\n", pPage->enmKind));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Checks if a access could be a fork operation in progress.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Meaning, that the guest is setting up the parent process for Copy-On-Write.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns true if it's likely that we're forking, otherwise false.
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pDis The disassembled instruction.
3cbb4f9a6a320e58ed398ef7aaa004cc8727abc5vboxsync * @param offFault The access offset.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncDECLINLINE(bool) pgmPoolMonitorIsForking(PPGMPOOL pPool, PDISCPUSTATE pDis, unsigned offFault)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * i386 linux is using btr to clear X86_PTE_RW.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * The functions involved are (2.6.16 source inspection):
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * clear_bit
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * ptep_set_wrprotect
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * copy_one_pte
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * copy_pte_range
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * copy_pmd_range
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * copy_pud_range
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * copy_page_range
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * copy_process
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /** @todo Validate that the bit index is X86_PTE_RW. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,Fork));
5b6e2c9a765c3c72295acc15791af8a700746956vboxsync return true;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync 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 Pointer to the VM.
e17bd6c32a8dd64f2d42838f9028216465e2caf0vboxsync * @param pVCpu Pointer to the VMCPU.
5ace91141404400247438502a84a418fba00c8cfvboxsync * @param pRegFrame Trap register frame.
e9a217d585085a6a6d129d27ca0d96a1b8e6d0eevboxsync * @param pDis The disassembly info for the faulting instruction.
3cbb4f9a6a320e58ed398ef7aaa004cc8727abc5vboxsync * @param pvFault The fault address.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @remark The REP prefix check is left to the caller because of STOSD/W.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncDECLINLINE(bool) pgmPoolMonitorIsReused(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame, PDISCPUSTATE pDis, RTGCPTR pvFault)
7e960d3a0a8a3a84d7aba2cca45d72b1c31cc97bvboxsync /** @todo could make this general, faulting close to rsp should be a safe reuse heuristic. */
e17bd6c32a8dd64f2d42838f9028216465e2caf0vboxsync /* Fault caused by stack writes while trying to inject an interrupt event. */
e17bd6c32a8dd64f2d42838f9028216465e2caf0vboxsync Log(("pgmPoolMonitorIsReused: reused %RGv for interrupt stack (rsp=%RGv).\n", pvFault, pRegFrame->rsp));
08bc90fc2848c80bf8270bedc883745b8398e186vboxsync return true;
e17bd6c32a8dd64f2d42838f9028216465e2caf0vboxsync LogFlow(("Reused instr %RGv %d at %RGv param1.fUse=%llx param1.reg=%d\n", pRegFrame->rip, pDis->pCurInstr->uOpcode, pvFault, pDis->Param1.fUse, pDis->Param1.Base.idxGenReg));
5ace91141404400247438502a84a418fba00c8cfvboxsync /* Non-supervisor mode write means it's used for something else. */
5ace91141404400247438502a84a418fba00c8cfvboxsync return true;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* call implies the actual push of the return address faulted */
49748bb305bd71f672cd083af208f4bb08c5d6abvboxsync return true;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return true;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return true;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return true;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return true;
b9ca93dd1ad44cb8b27679dc5624be2f7b7f7af5vboxsync return true;
b9ca93dd1ad44cb8b27679dc5624be2f7b7f7af5vboxsync case OP_MOVNTDQ: /* solaris - hwblkclr & hwblkpagecopy */
b9ca93dd1ad44cb8b27679dc5624be2f7b7f7af5vboxsync return true;
e9a217d585085a6a6d129d27ca0d96a1b8e6d0eevboxsync if ( pDis->fPrefix == (DISPREFIX_REP|DISPREFIX_REX)
8b984478b755f4d3091b977d9beac9fb7434279fvboxsync return true;
e9a217d585085a6a6d129d27ca0d96a1b8e6d0eevboxsync return false;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return true;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return false;
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync * Flushes the page being accessed.
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync * @returns VBox status code suitable for scheduling.
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync * @param pVM Pointer to the VM.
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync * @param pVCpu Pointer to the VMCPU.
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.
f351fab06d1e1507b72f5c574df71193061fd393vboxsync * @todo VBOXSTRICTRC
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsyncstatic int pgmPoolAccessHandlerFlush(PVM pVM, PVMCPU pVCpu, PPGMPOOL pPool, PPGMPOOLPAGE pPage, PDISCPUSTATE pDis,
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, RTGCPTR pvFault)
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync * First, do the flushing.
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync * Emulate the instruction (xp/w2k problem, requires pc/cr2/sp detection).
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync * Must do this in raw mode (!); XP boot will fail otherwise.
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync VBOXSTRICTRC rc2 = EMInterpretInstructionDisasState(pVCpu, pDis, pRegFrame, pvFault, EMCODETYPE_ALL);
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync AssertMsg(rc2 == VINF_SUCCESS, ("%Rrc\n", VBOXSTRICTRC_VAL(rc2))); /* ASSUMES no complicated stuff here. */
1f19ba1642702523c0d2684aa2542d051f15275bvboxsync LogFlow(("pgmPoolAccessHandlerPTWorker: Interpretation failed for patch code %04x:%RGv, ignoring.\n",
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync STAM_COUNTER_INC(&pPool->StatMonitorRZIntrFailPatch2);
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,EmulateInstr));
f351fab06d1e1507b72f5c574df71193061fd393vboxsync LogFlow(("pgmPoolAccessHandlerPT: returns %Rrc (flushed)\n", rc));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Handles the STOSD write accesses.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code suitable for scheduling.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM Pointer to the VM.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The pool page (head).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pDis The disassembly of the write instruction.
3cbb4f9a6a320e58ed398ef7aaa004cc8727abc5vboxsync * @param pRegFrame The trap register frame.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param GCPhysFault The fault address as guest physical address.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pvFault The fault address.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncDECLINLINE(int) pgmPoolAccessHandlerSTOSD(PVM pVM, PPGMPOOL pPool, PPGMPOOLPAGE pPage, PDISCPUSTATE pDis,
3cbb4f9a6a320e58ed398ef7aaa004cc8727abc5vboxsync PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, RTGCPTR pvFault)
09e2f92b8f54aa362088e216007b53ecdb42e283vboxsync Assert(pDis->uCpuMode == DISCPUMODE_32BIT || pDis->uCpuMode == DISCPUMODE_64BIT);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Increment the modification counter and insert it into the list
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * of modified pages the first time.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Execute REP STOSD.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * This ASSUMES that we're not invoked by Trap0e on in a out-of-sync
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * write situation, meaning that it's safe to write here.
9984bae4ef25be8afd95d184308adcfef6e2ec0dvboxsync#if defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0) || defined(IN_RC)
9984bae4ef25be8afd95d184308adcfef6e2ec0dvboxsync uint32_t iPrevSubset = PGMRZDynMapPushAutoSubset(pVCpu);
9e4166cf5ed4940f506bc718ea6c89bf7ed252c8vboxsync pgmPoolMonitorChainChanging(pVCpu, pPool, pPage, GCPhysFault, (RTGCPTR)pu32, uIncrement);
9e4166cf5ed4940f506bc718ea6c89bf7ed252c8vboxsync pgmPoolMonitorChainChanging(pVCpu, pPool, pPage, GCPhysFault, (RTGCPTR)pu32, uIncrement);
09e2f92b8f54aa362088e216007b53ecdb42e283vboxsync PGMPhysSimpleWriteGCPhys(pVM, GCPhysFault, &pRegFrame->rax, uIncrement);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Handles the simple write accesses.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code suitable for scheduling.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM Pointer to the VM.
42c1972c22e09797b4b24afbd0ec114ed076c37cvboxsync * @param pVCpu Pointer to the VMCPU.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The pool page (head).
3cbb4f9a6a320e58ed398ef7aaa004cc8727abc5vboxsync * @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.
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync * @param pfReused Reused state (in/out)
3cbb4f9a6a320e58ed398ef7aaa004cc8727abc5vboxsyncDECLINLINE(int) pgmPoolAccessHandlerSimple(PVM pVM, PVMCPU pVCpu, PPGMPOOL pPool, PPGMPOOLPAGE pPage, PDISCPUSTATE pDis,
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, RTGCPTR pvFault, bool *pfReused)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Increment the modification counter and insert it into the list
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * of modified pages the first time.
9984bae4ef25be8afd95d184308adcfef6e2ec0dvboxsync * Clear all the pages. ASSUMES that pvFault is readable.
9e4166cf5ed4940f506bc718ea6c89bf7ed252c8vboxsync#if defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0) || defined(IN_RC)
9984bae4ef25be8afd95d184308adcfef6e2ec0dvboxsync uint32_t iPrevSubset = PGMRZDynMapPushAutoSubset(pVCpu);
0975ae0a0fb615c945150c48e4a73187c1f4f84dvboxsync pgmPoolMonitorChainChanging(pVCpu, pPool, pPage, GCPhysFault, pvFault, DISGetParamSize(pDis, &pDis->Param1));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolMonitorChainChanging(pVCpu, pPool, pPage, GCPhysFault, pvFault, DISGetParamSize(pDis, &pDis->Param1));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Interpret the instruction.
1a25adaca81841abf5e6cdfed02eaff64941357dvboxsync VBOXSTRICTRC rc = EMInterpretInstructionDisasState(pVCpu, pDis, pRegFrame, pvFault, EMCODETYPE_ALL);
3cbb4f9a6a320e58ed398ef7aaa004cc8727abc5vboxsync AssertMsg(rc == VINF_SUCCESS, ("%Rrc\n", VBOXSTRICTRC_VAL(rc))); /* ASSUMES no complicated stuff here. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolAccessHandlerPTWorker: Interpretation failed for %04x:%RGv - opcode=%d\n",
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pRegFrame->cs.Sel, (RTGCPTR)pRegFrame->rip, pDis->pCurInstr->uOpcode));
3cbb4f9a6a320e58ed398ef7aaa004cc8727abc5vboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,EmulateInstr));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync#if 0 /* experimental code */
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync int rc = pgmPoolPhysSimpleReadGCPhys(pVM, &GstPte, pvFault, GCPhysFault, sizeof(GstPte));
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync /* Check the new value written by the guest. If present and with a bogus physical address, then
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync * 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);
036d626c5d4722da925dc8292f9248a5e09b4588vboxsync LogFlow(("pgmPoolAccessHandlerSimple: returns %Rrc\n", VBOXSTRICTRC_VAL(rc)));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * \#PF Handler callback for PT write accesses.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code (appropriate for GC return).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM Pointer to the VM.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param uErrorCode CPU Error code.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pRegFrame Trap register frame.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * NULL on DMA and other non CPU access.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pvFault The fault address (cr2).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param GCPhysFault The GC physical address corresponding to pvFault.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pvUser User argument.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncDECLEXPORT(int) pgmPoolAccessHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault,
5b6e2c9a765c3c72295acc15791af8a700746956vboxsync STAM_PROFILE_START(&pVM->pgm.s.CTX_SUFF(pPool)->CTX_SUFF_Z(StatMonitor), a);
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync bool fForcedFlush = false;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolAccessHandler: pvFault=%RGv pPage=%p:{.idx=%d} GCPhysFault=%RGp\n", pvFault, pPage, pPage->idx, GCPhysFault));
6778b34cb96bef0fef23ebc461eb6a429d2907c5vboxsync if (PHYS_PAGE_ADDRESS(GCPhysFault) != PHYS_PAGE_ADDRESS(pPage->GCPhys))
6778b34cb96bef0fef23ebc461eb6a429d2907c5vboxsync /* Pool page changed while we were waiting for the lock; ignore. */
6778b34cb96bef0fef23ebc461eb6a429d2907c5vboxsync 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)));
6778b34cb96bef0fef23ebc461eb6a429d2907c5vboxsync STAM_PROFILE_STOP_EX(&pVM->pgm.s.CTX_SUFF(pPool)->CTX_SUFF_Z(StatMonitor), &pPool->CTX_MID_Z(StatMonitor,Handled), a);
614cbe11a7e5588dc8d369e223174b1441a09359vboxsync return VINF_SUCCESS; /* SMP guest case where we were blocking on the pgm lock while the same page was being marked dirty. */
614cbe11a7e5588dc8d369e223174b1441a09359vboxsync#if 0 /* test code defined(VBOX_STRICT) && defined(PGMPOOL_WITH_OPTIMIZED_DIRTY_PT) */
614cbe11a7e5588dc8d369e223174b1441a09359vboxsync if (pPage->enmKind == PGMPOOLKIND_PAE_PT_FOR_PAE_PT)
614cbe11a7e5588dc8d369e223174b1441a09359vboxsync void *pvShw = PGMPOOL_PAGE_2_PTR(pPool->CTX_SUFF(pVM), pPage);
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync int rc = PGM_GCPHYS_2_PTR(pPool->CTX_SUFF(pVM), pPage->GCPhys, &pvGst); AssertReleaseRC(rc);
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync pgmPoolTrackCheckPTPaePae(pPool, pPage, (PPGMSHWPTPAE)pvShw, (PCX86PTPAE)pvGst);
d4b98dbce4cf7b3694b62d62a47553d399718dccvboxsync * Disassemble the faulting instruction.
b6d0062d24490dd07b4a424e5809b3b2bc910c5avboxsync int rc = EMInterpretDisasCurrent(pVM, pVCpu, pDis, NULL);
b6d0062d24490dd07b4a424e5809b3b2bc910c5avboxsync AssertMsg(rc == VERR_PAGE_NOT_PRESENT || rc == VERR_PAGE_TABLE_NOT_PRESENT, ("Unexpected rc %d\n", rc));
fd69ca9bd8b533bfa9ade45c1c2ff3116854e84avboxsync * We should ALWAYS have the list head as user parameter. This
fd69ca9bd8b533bfa9ade45c1c2ff3116854e84avboxsync * is because we use that page to record the changes.
e556f4b8a69ebc1a21f128234fd69c854ad8cfdfvboxsync /* Maximum nr of modifications depends on the page type. */
e556f4b8a69ebc1a21f128234fd69c854ad8cfdfvboxsync if ( pPage->enmKind == PGMPOOLKIND_PAE_PT_FOR_PAE_PT
b978e5849454446957177fd47ee98609ab0457a6vboxsync || pPage->enmKind == PGMPOOLKIND_PAE_PT_FOR_32BIT_PT)
5ace91141404400247438502a84a418fba00c8cfvboxsync * Incremental page table updates should weigh more than random ones.
5ace91141404400247438502a84a418fba00c8cfvboxsync * (Only applies when started from offset 0)
5ace91141404400247438502a84a418fba00c8cfvboxsync if ( pPage->GCPtrLastAccessHandlerRip >= pRegFrame->rip - 0x40 /* observed loops in Windows 7 x64 */
5ace91141404400247438502a84a418fba00c8cfvboxsync && pPage->GCPtrLastAccessHandlerRip < pRegFrame->rip + 0x40
5ace91141404400247438502a84a418fba00c8cfvboxsync && pvFault == (pPage->GCPtrLastAccessHandlerFault + pDis->Param1.cb)
5ace91141404400247438502a84a418fba00c8cfvboxsync && pVCpu->pgm.s.cPoolAccessHandler == pPage->cLastAccessHandler + 1)
01c7ae36dfb7eb93bef22d5ec6c1c0572eba3f24vboxsync Log(("Possible page reuse cMods=%d -> %d (locked=%d type=%s)\n", pPage->cModifications, pPage->cModifications * 2, pgmPoolIsPageLocked(pPage), pgmPoolPoolKindToStr(pPage->enmKind)));
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync pPage->cLastAccessHandler = pVCpu->pgm.s.cPoolAccessHandler;
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,FlushReinit));
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync Log(("Mod overflow %RGv cMods=%d (locked=%d type=%s)\n", pvFault, pPage->cModifications, pgmPoolIsPageLocked(pPage), pgmPoolPoolKindToStr(pPage->enmKind)));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Check if it's worth dealing with.
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync bool fReused = false;
1999ae03c34840fa4d712fd2e020120b2cb7182avboxsync if ( ( pPage->cModifications < cMaxModifications /** @todo #define */ /** @todo need to check that it's not mapping EIP. */ /** @todo adjust this! */
3cbb4f9a6a320e58ed398ef7aaa004cc8727abc5vboxsync && !(fReused = pgmPoolMonitorIsReused(pVM, pVCpu, pRegFrame, pDis, pvFault))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync && !pgmPoolMonitorIsForking(pPool, pDis, GCPhysFault & PAGE_OFFSET_MASK))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Simple instructions, no REP prefix.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if (!(pDis->fPrefix & (DISPREFIX_REP | DISPREFIX_REPNE)))
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync rc = pgmPoolAccessHandlerSimple(pVM, pVCpu, pPool, pPage, pDis, pRegFrame, GCPhysFault, pvFault, &fReused);
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync /* A mov instruction to change the first page table entry will be remembered so we can detect
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync * full page table changes early on. This will reduce the amount of unnecessary traps we'll take.
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync && !pPage->cLocked /* only applies to unlocked pages as we can't free locked ones (e.g. cr3 root). */
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync pPage->cLastAccessHandler = pVCpu->pgm.s.cPoolAccessHandler;
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync /* Make sure we don't kick out a page too quickly. */
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync else if (pPage->GCPtrLastAccessHandlerFault == pvFault)
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync /* ignore the 2nd write to this page table entry. */
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync pPage->cLastAccessHandler = pVCpu->pgm.s.cPoolAccessHandler;
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync STAM_PROFILE_STOP_EX(&pVM->pgm.s.CTX_SUFF(pPool)->CTX_SUFF_Z(StatMonitor), &pPool->CTX_MID_Z(StatMonitor,Handled), a);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Windows is frequently doing small memset() operations (netio test 4k+).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * We have to deal with these or we'll kill the cache and performance.
09e2f92b8f54aa362088e216007b53ecdb42e283vboxsync bool fValidStosd = false;
09e2f92b8f54aa362088e216007b53ecdb42e283vboxsync && pRegFrame->ecx * 4 <= PAGE_SIZE - ((uintptr_t)pvFault & PAGE_OFFSET_MASK)
09e2f92b8f54aa362088e216007b53ecdb42e283vboxsync && (pRegFrame->eax == 0 || pRegFrame->eax == 0x80) /* the two values observed. */
28c928d1100d3b6a6d3506224cae25ad04732f73vboxsync && pDis->fPrefix == (DISPREFIX_REP | DISPREFIX_REX)
5ace91141404400247438502a84a418fba00c8cfvboxsync && pRegFrame->rcx * 8 <= PAGE_SIZE - ((uintptr_t)pvFault & PAGE_OFFSET_MASK)
09e2f92b8f54aa362088e216007b53ecdb42e283vboxsync && (pRegFrame->rax == 0 || pRegFrame->rax == 0x80) /* the two values observed. */
09e2f92b8f54aa362088e216007b53ecdb42e283vboxsync rc = pgmPoolAccessHandlerSTOSD(pVM, pPool, pPage, pDis, pRegFrame, GCPhysFault, pvFault);
09e2f92b8f54aa362088e216007b53ecdb42e283vboxsync STAM_PROFILE_STOP_EX(&pVM->pgm.s.CTX_SUFF(pPool)->CTX_SUFF_Z(StatMonitor), &pPool->CTX_MID_Z(StatMonitor,RepStosd), a);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* REP prefix, don't bother. */
5b6e2c9a765c3c72295acc15791af8a700746956vboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,RepPrefix));
08bc90fc2848c80bf8270bedc883745b8398e186vboxsync Log4(("pgmPoolAccessHandler: eax=%#x ecx=%#x edi=%#x esi=%#x rip=%RGv opcode=%d prefix=%#x\n",
3cbb4f9a6a320e58ed398ef7aaa004cc8727abc5vboxsync pRegFrame->eax, pRegFrame->ecx, pRegFrame->edi, pRegFrame->esi, (RTGCPTR)pRegFrame->rip, pDis->pCurInstr->uOpcode, pDis->fPrefix));
b978e5849454446957177fd47ee98609ab0457a6vboxsync#if defined(PGMPOOL_WITH_OPTIMIZED_DIRTY_PT) && defined(IN_RING0)
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync /* E.g. Windows 7 x64 initializes page tables and touches some pages in the table during the process. This
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * leads to pgm pool trashing and an excessive amount of write faults due to page monitoring.
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync && (pPage->enmKind == PGMPOOLKIND_PAE_PT_FOR_PAE_PT || pPage->enmKind == PGMPOOLKIND_PAE_PT_FOR_32BIT_PT)
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync || ( !pgmPoolMonitorIsReused(pVM, pVCpu, pRegFrame, pDis, pvFault)
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync && !pgmPoolMonitorIsForking(pPool, pDis, GCPhysFault & PAGE_OFFSET_MASK))
74735ec6edd6640eebac8885fbb2dadc86b89cf5vboxsync /* Flush any monitored duplicates as we will disable write protection. */
74735ec6edd6640eebac8885fbb2dadc86b89cf5vboxsync /* Find the monitor head. */
74735ec6edd6640eebac8885fbb2dadc86b89cf5vboxsync while (pPageHead->iMonitoredPrev != NIL_PGMPOOL_IDX)
74735ec6edd6640eebac8885fbb2dadc86b89cf5vboxsync pPageHead = &pPool->aPages[pPageHead->iMonitoredPrev];
74735ec6edd6640eebac8885fbb2dadc86b89cf5vboxsync Log(("Flush duplicate page idx=%d GCPhys=%RGp type=%s\n", pPageHead->idx, pPageHead->GCPhys, pgmPoolPoolKindToStr(pPageHead->enmKind)));
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync /* The flushing above might fail for locked pages, so double check. */
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync /* Temporarily allow write access to the page table again. */
daf1af91919d2fe4bac56d58487210f747e4592avboxsync rc = PGMHandlerPhysicalPageTempOff(pVM, pPage->GCPhys & PAGE_BASE_GC_MASK, pPage->GCPhys & PAGE_BASE_GC_MASK);
f3e9d2446012445807621d8dd95afb2c8cad2789vboxsync rc = PGMShwMakePageWritable(pVCpu, pvFault, PGM_MK_PG_IS_WRITE_FAULT);
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync /* In the SMP case the page table might be removed while we wait for the PGM lock in the trap handler. */
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync ("PGMShwModifyPage -> GCPtr=%RGv rc=%d\n", pvFault, rc));
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync STAM_PROFILE_STOP(&pVM->pgm.s.CTX_SUFF(pPool)->CTX_SUFF_Z(StatMonitor), a);
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync#endif /* PGMPOOL_WITH_OPTIMIZED_DIRTY_PT */
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,FlushModOverflow));
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync * Not worth it, so flush it.
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync * If we considered it to be reused, don't go back to ring-3
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync * to emulate failed instructions since we usually cannot
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync * interpret then. This may be a bit risky, in which case
e17f587595bd5d3a7be56a892e3fd3a0ef83d268vboxsync * the reuse detection must be fixed.
21d4a56532f8029ae299f552811a0b86c1909416vboxsync rc = pgmPoolAccessHandlerFlush(pVM, pVCpu, pPool, pPage, pDis, pRegFrame, GCPhysFault, pvFault);
4b808cd07fd33b8a3edd0588dc43615686deb0e3vboxsync /* Make sure that the current instruction still has shadow page backing, otherwise we'll end up in a loop. */
4b808cd07fd33b8a3edd0588dc43615686deb0e3vboxsync if (PGMShwGetPage(pVCpu, pRegFrame->rip, NULL, NULL) == VINF_SUCCESS)
4b808cd07fd33b8a3edd0588dc43615686deb0e3vboxsync rc = VINF_SUCCESS; /* safe to restart the instruction. */
b5b12033c1f7eaf82b038f06e2b9e464b9ddd8d2vboxsync STAM_PROFILE_STOP_EX(&pVM->pgm.s.CTX_SUFF(pPool)->CTX_SUFF_Z(StatMonitor), &pPool->CTX_MID_Z(StatMonitor,FlushPage), a);
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync# endif /* !IN_RING3 */
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync * Check references to guest physical memory in a PAE / PAE page table.
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync * @param pPool The pool.
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync * @param pPage The page.
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync * @param pShwPT The shadow page table (mapping of the page).
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync * @param pGstPT The guest page table.
016bd61cdd14201a24f289559b0cc333d8c94748vboxsyncstatic void pgmPoolTrackCheckPTPaePae(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PPGMSHWPTPAE pShwPT, PCX86PTPAE pGstPT)
016bd61cdd14201a24f289559b0cc333d8c94748vboxsync unsigned cErrors = 0;
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync unsigned LastPTE = ~0U; /* initialized to shut up gcc */
a46e399d5426a79f6f7e18d0ba85c505280e9386vboxsync RTHCPHYS LastHCPhys = NIL_RTHCPHYS; /* initialized to shut up gcc */
4584ef6026a823006bea5acbeb13dc4efe50da69vboxsync for (unsigned i = 0; i < RT_MIN(RT_ELEMENTS(pShwPT->a), pPage->iFirstPresent); i++)
4584ef6026a823006bea5acbeb13dc4efe50da69vboxsync AssertMsg(!PGMSHWPTEPAE_IS_P(pShwPT->a[i]), ("Unexpected PTE: idx=%d %RX64 (first=%d)\n", i, PGMSHWPTEPAE_GET_LOG(pShwPT->a[i]), pPage->iFirstPresent));
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pShwPT->a); i++)
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync int rc = PGMPhysGCPhys2HCPhys(pVM, pGstPT->a[i].u & X86_PTE_PAE_PG_MASK, &HCPhys);
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync || PGMSHWPTEPAE_GET_HCPHYS(pShwPT->a[i]) != HCPhys)
a46e399d5426a79f6f7e18d0ba85c505280e9386vboxsync Log(("rc=%d idx=%d guest %RX64 shw=%RX64 vs %RHp\n", rc, i, pGstPT->a[i].u, PGMSHWPTEPAE_GET_LOG(pShwPT->a[i]), HCPhys));
13b9db9ae2c12b6c4e00eda5c79772d57a0d29e1vboxsync rc = PGMPhysGCPhys2HCPhys(pVM, pPage->GCPhys, &HCPhysPT);
21d4a56532f8029ae299f552811a0b86c1909416vboxsync for (unsigned iPage = 0; iPage < pPool->cCurPages; iPage++)
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync if (pTempPage->enmKind == PGMPOOLKIND_PAE_PT_FOR_PAE_PT)
13b9db9ae2c12b6c4e00eda5c79772d57a0d29e1vboxsync PPGMSHWPTPAE pShwPT2 = (PPGMSHWPTPAE)PGMPOOL_PAGE_2_PTR(pVM, pTempPage);
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync for (unsigned j = 0; j < RT_ELEMENTS(pShwPT->a); j++)
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync && PGMSHWPTEPAE_GET_HCPHYS(pShwPT2->a[j]) == HCPhysPT)
13b9db9ae2c12b6c4e00eda5c79772d57a0d29e1vboxsync Log(("GCPhys=%RGp idx=%d %RX64 vs %RX64\n", pTempPage->GCPhys, j, PGMSHWPTEPAE_GET_LOG(pShwPT->a[j]), PGMSHWPTEPAE_GET_LOG(pShwPT2->a[j])));
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync AssertMsg(!cErrors, ("cErrors=%d: last rc=%d idx=%d guest %RX64 shw=%RX64 vs %RHp\n", cErrors, LastRc, LastPTE, pGstPT->a[LastPTE].u, PGMSHWPTEPAE_GET_LOG(pShwPT->a[LastPTE]), LastHCPhys));
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync * Check references to guest physical memory in a PAE / 32-bit page table.
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync * @param pPool The pool.
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync * @param pPage The page.
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync * @param pShwPT The shadow page table (mapping of the page).
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync * @param pGstPT The guest page table.
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsyncstatic void pgmPoolTrackCheckPTPae32Bit(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PPGMSHWPTPAE pShwPT, PCX86PT pGstPT)
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync unsigned cErrors = 0;
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync unsigned LastPTE = ~0U; /* initialized to shut up gcc */
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync RTHCPHYS LastHCPhys = NIL_RTHCPHYS; /* initialized to shut up gcc */
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync for (unsigned i = 0; i < RT_MIN(RT_ELEMENTS(pShwPT->a), pPage->iFirstPresent); i++)
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync AssertMsg(!PGMSHWPTEPAE_IS_P(pShwPT->a[i]), ("Unexpected PTE: idx=%d %RX64 (first=%d)\n", i, PGMSHWPTEPAE_GET_LOG(pShwPT->a[i]), pPage->iFirstPresent));
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pShwPT->a); i++)
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync int rc = PGMPhysGCPhys2HCPhys(pVM, pGstPT->a[i].u & X86_PTE_PG_MASK, &HCPhys);
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync || PGMSHWPTEPAE_GET_HCPHYS(pShwPT->a[i]) != HCPhys)
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync Log(("rc=%d idx=%d guest %x shw=%RX64 vs %RHp\n", rc, i, pGstPT->a[i].u, PGMSHWPTEPAE_GET_LOG(pShwPT->a[i]), HCPhys));
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync rc = PGMPhysGCPhys2HCPhys(pVM, pPage->GCPhys, &HCPhysPT);
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync for (unsigned iPage = 0; iPage < pPool->cCurPages; iPage++)
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync if (pTempPage->enmKind == PGMPOOLKIND_PAE_PT_FOR_32BIT_PT)
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync PPGMSHWPTPAE pShwPT2 = (PPGMSHWPTPAE)PGMPOOL_PAGE_2_PTR(pVM, pTempPage);
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync for (unsigned j = 0; j < RT_ELEMENTS(pShwPT->a); j++)
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync && PGMSHWPTEPAE_GET_HCPHYS(pShwPT2->a[j]) == HCPhysPT)
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync Log(("GCPhys=%RGp idx=%d %RX64 vs %RX64\n", pTempPage->GCPhys, j, PGMSHWPTEPAE_GET_LOG(pShwPT->a[j]), PGMSHWPTEPAE_GET_LOG(pShwPT2->a[j])));
2cd06fc737773d015b5268b9e4dfba5997915957vboxsync AssertMsg(!cErrors, ("cErrors=%d: last rc=%d idx=%d guest %x shw=%RX64 vs %RHp\n", cErrors, LastRc, LastPTE, pGstPT->a[LastPTE].u, PGMSHWPTEPAE_GET_LOG(pShwPT->a[LastPTE]), LastHCPhys));
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync# endif /* VBOX_STRICT && !IN_RING3 */
01cc79d6798a7ad8b8041ddb2b67fc8b37bf0b37vboxsync * Clear references to guest physical memory in a PAE / PAE page table.
01cc79d6798a7ad8b8041ddb2b67fc8b37bf0b37vboxsync * @returns nr of changed PTEs
01cc79d6798a7ad8b8041ddb2b67fc8b37bf0b37vboxsync * @param pPool The pool.
01cc79d6798a7ad8b8041ddb2b67fc8b37bf0b37vboxsync * @param pPage The page.
01cc79d6798a7ad8b8041ddb2b67fc8b37bf0b37vboxsync * @param pShwPT The shadow page table (mapping of the page).
01cc79d6798a7ad8b8041ddb2b67fc8b37bf0b37vboxsync * @param pGstPT The guest page table.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * @param pOldGstPT The old cached guest page table.
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync * @param fAllowRemoval Bail out as soon as we encounter an invalid PTE
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync * @param pfFlush Flush reused page table (out)
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsyncDECLINLINE(unsigned) pgmPoolTrackFlushPTPaePae(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PPGMSHWPTPAE pShwPT, PCX86PTPAE pGstPT,
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync PCX86PTPAE pOldGstPT, bool fAllowRemoval, bool *pfFlush)
9bebc668ed1ad5c93d92ff98fee1cd7dca55f6d5vboxsync unsigned cChanged = 0;
01cc79d6798a7ad8b8041ddb2b67fc8b37bf0b37vboxsync for (unsigned i = 0; i < RT_MIN(RT_ELEMENTS(pShwPT->a), pPage->iFirstPresent); i++)
01cc79d6798a7ad8b8041ddb2b67fc8b37bf0b37vboxsync AssertMsg(!PGMSHWPTEPAE_IS_P(pShwPT->a[i]), ("Unexpected PTE: idx=%d %RX64 (first=%d)\n", i, PGMSHWPTEPAE_GET_LOG(pShwPT->a[i]), pPage->iFirstPresent));
01cc79d6798a7ad8b8041ddb2b67fc8b37bf0b37vboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pShwPT->a); i++)
01cc79d6798a7ad8b8041ddb2b67fc8b37bf0b37vboxsync /* Check the new value written by the guest. If present and with a bogus physical address, then
01cc79d6798a7ad8b8041ddb2b67fc8b37bf0b37vboxsync * it's fairly safe to assume the guest is reusing the PT.
01cc79d6798a7ad8b8041ddb2b67fc8b37bf0b37vboxsync if (!PGMPhysIsGCPhysValid(pPool->CTX_SUFF(pVM), pGstPT->a[i].u & X86_PTE_PAE_PG_MASK))
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync /* If the old cached PTE is identical, then there's no need to flush the shadow copy. */
69deddbc68802f1cf1c3a404a9f816b8accb3385vboxsync if ((pGstPT->a[i].u & X86_PTE_PAE_PG_MASK) == (pOldGstPT->a[i].u & X86_PTE_PAE_PG_MASK))
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync int rc = PGMPhysGCPhys2HCPhys(pPool->CTX_SUFF(pVM), pGstPT->a[i].u & X86_PTE_PAE_PG_MASK, &HCPhys);
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync AssertMsg(rc == VINF_SUCCESS && PGMSHWPTEPAE_GET_HCPHYS(pShwPT->a[i]) == HCPhys, ("rc=%d guest %RX64 old %RX64 shw=%RX64 vs %RHp\n", rc, pGstPT->a[i].u, pOldGstPT->a[i].u, PGMSHWPTEPAE_GET_LOG(pShwPT->a[i]), HCPhys));
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync uint64_t uHostAttr = PGMSHWPTEPAE_GET_U(pShwPT->a[i]) & (X86_PTE_P | X86_PTE_US | X86_PTE_A | X86_PTE_D | X86_PTE_G | X86_PTE_PAE_NX);
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync bool fHostRW = !!(PGMSHWPTEPAE_GET_U(pShwPT->a[i]) & X86_PTE_RW);
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync 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);
b40179b44fea65b72b2f226f62af1ed7bd3c48fcvboxsync /* Something was changed, so flush it. */
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync Log4(("pgmPoolTrackDerefPTPaePae: i=%d pte=%RX64 hint=%RX64\n",
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync i, PGMSHWPTEPAE_GET_HCPHYS(pShwPT->a[i]), pOldGstPT->a[i].u & X86_PTE_PAE_PG_MASK));
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync pgmPoolTracDerefGCPhysHint(pPool, pPage, PGMSHWPTEPAE_GET_HCPHYS(pShwPT->a[i]), pOldGstPT->a[i].u & X86_PTE_PAE_PG_MASK, i);
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync * Clear references to guest physical memory in a PAE / PAE page table.
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync * @returns nr of changed PTEs
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync * @param pPool The pool.
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync * @param pPage The page.
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync * @param pShwPT The shadow page table (mapping of the page).
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync * @param pGstPT The guest page table.
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync * @param pOldGstPT The old cached guest page table.
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync * @param fAllowRemoval Bail out as soon as we encounter an invalid PTE
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync * @param pfFlush Flush reused page table (out)
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsyncDECLINLINE(unsigned) pgmPoolTrackFlushPTPae32Bit(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PPGMSHWPTPAE pShwPT, PCX86PT pGstPT,
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync PCX86PT pOldGstPT, bool fAllowRemoval, bool *pfFlush)
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync unsigned cChanged = 0;
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync for (unsigned i = 0; i < RT_MIN(RT_ELEMENTS(pShwPT->a), pPage->iFirstPresent); i++)
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync AssertMsg(!PGMSHWPTEPAE_IS_P(pShwPT->a[i]), ("Unexpected PTE: idx=%d %RX64 (first=%d)\n", i, PGMSHWPTEPAE_GET_LOG(pShwPT->a[i]), pPage->iFirstPresent));
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pShwPT->a); i++)
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync /* Check the new value written by the guest. If present and with a bogus physical address, then
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync * it's fairly safe to assume the guest is reusing the PT.
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync if (!PGMPhysIsGCPhysValid(pPool->CTX_SUFF(pVM), pGstPT->a[i].u & X86_PTE_PG_MASK))
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync /* If the old cached PTE is identical, then there's no need to flush the shadow copy. */
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync if ((pGstPT->a[i].u & X86_PTE_PG_MASK) == (pOldGstPT->a[i].u & X86_PTE_PG_MASK))
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync int rc = PGMPhysGCPhys2HCPhys(pPool->CTX_SUFF(pVM), pGstPT->a[i].u & X86_PTE_PG_MASK, &HCPhys);
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync AssertMsg(rc == VINF_SUCCESS && PGMSHWPTEPAE_GET_HCPHYS(pShwPT->a[i]) == HCPhys, ("rc=%d guest %x old %x shw=%RX64 vs %RHp\n", rc, pGstPT->a[i].u, pOldGstPT->a[i].u, PGMSHWPTEPAE_GET_LOG(pShwPT->a[i]), HCPhys));
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync uint64_t uHostAttr = PGMSHWPTEPAE_GET_U(pShwPT->a[i]) & (X86_PTE_P | X86_PTE_US | X86_PTE_A | X86_PTE_D | X86_PTE_G);
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync bool fHostRW = !!(PGMSHWPTEPAE_GET_U(pShwPT->a[i]) & X86_PTE_RW);
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync uint64_t uGuestAttr = pGstPT->a[i].u & (X86_PTE_P | X86_PTE_US | X86_PTE_A | X86_PTE_D | X86_PTE_G);
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync /* Something was changed, so flush it. */
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync Log4(("pgmPoolTrackDerefPTPaePae: i=%d pte=%RX64 hint=%x\n",
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync i, PGMSHWPTEPAE_GET_HCPHYS(pShwPT->a[i]), pOldGstPT->a[i].u & X86_PTE_PG_MASK));
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync pgmPoolTracDerefGCPhysHint(pPool, pPage, PGMSHWPTEPAE_GET_HCPHYS(pShwPT->a[i]), pOldGstPT->a[i].u & X86_PTE_PG_MASK, i);
01cc79d6798a7ad8b8041ddb2b67fc8b37bf0b37vboxsync * Flush a dirty page
01cc79d6798a7ad8b8041ddb2b67fc8b37bf0b37vboxsync * @param pVM Pointer to the VM.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * @param pPool The pool.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * @param idxSlot Dirty array slot index
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * @param fAllowRemoval Allow a reused page table to be removed
ef481e64bafc49f1232767ce12c3fa69a5d5fe50vboxsyncstatic void pgmPoolFlushDirtyPage(PVM pVM, PPGMPOOL pPool, unsigned idxSlot, bool fAllowRemoval = false)
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync if (pPool->aDirtyPages[idxSlot].uIdx == NIL_PGMPOOL_IDX)
9984bae4ef25be8afd95d184308adcfef6e2ec0dvboxsync Assert(pPage->iMonitoredNext == NIL_PGMPOOL_IDX && pPage->iMonitoredPrev == NIL_PGMPOOL_IDX);
9984bae4ef25be8afd95d184308adcfef6e2ec0dvboxsync AssertMsg(pPage->fDirty, ("Page %RGp (slot=%d) not marked dirty!", pPage->GCPhys, idxSlot));
8ddd175fa7cb232e090f3b8934a411c167aadb27vboxsync Log(("Flush dirty page %RGp cMods=%d\n", pPage->GCPhys, pPage->cModifications));
4b02cd4133ae0d8e4732c57274a59358e418349cvboxsync#if defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0) || defined(IN_RC)
4b02cd4133ae0d8e4732c57274a59358e418349cvboxsync uint32_t iPrevSubset = PGMRZDynMapPushAutoSubset(pVCpu);
1171e4fb031146163c9a5a66bd9cbf3f2a5acdb6vboxsync /* First write protect the page again to catch all write accesses. (before checking for changes -> SMP) */
1171e4fb031146163c9a5a66bd9cbf3f2a5acdb6vboxsync int rc = PGMHandlerPhysicalReset(pVM, pPage->GCPhys & PAGE_BASE_GC_MASK);
1171e4fb031146163c9a5a66bd9cbf3f2a5acdb6vboxsync rc = PGMShwGetPage(VMMGetCpu(pVM), pPage->GCPtrDirtyFault, &fFlags, &HCPhys);
1171e4fb031146163c9a5a66bd9cbf3f2a5acdb6vboxsync && (!(fFlags & X86_PTE_RW) || HCPhys != pPage->Core.Key))
1171e4fb031146163c9a5a66bd9cbf3f2a5acdb6vboxsync /* In the SMP case the page table might be removed while we wait for the PGM lock in the trap handler. */
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync ("PGMShwGetPage -> GCPtr=%RGv rc=%d flags=%RX64\n", pPage->GCPtrDirtyFault, rc, fFlags));
01cc79d6798a7ad8b8041ddb2b67fc8b37bf0b37vboxsync /* Flush those PTEs that have changed. */
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync rc = PGM_GCPHYS_2_PTR_EX(pVM, pPage->GCPhys, &pvGst); AssertReleaseRC(rc);
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync if (pPage->enmKind == PGMPOOLKIND_PAE_PT_FOR_PAE_PT)
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync cChanges = pgmPoolTrackFlushPTPaePae(pPool, pPage, (PPGMSHWPTPAE)pvShw, (PCX86PTPAE)pvGst,
4b02cd4133ae0d8e4732c57274a59358e418349cvboxsync (PCX86PTPAE)&pPool->aDirtyPages[idxSlot].aPage[0], fAllowRemoval, &fFlush);
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync cChanges = pgmPoolTrackFlushPTPae32Bit(pPool, pPage, (PPGMSHWPTPAE)pvShw, (PCX86PT)pvGst,
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync (PCX86PT)&pPool->aDirtyPages[idxSlot].aPage[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. */
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync pPage->cModifications = RT_MAX(1, pPage->cModifications / 2);
ef481e64bafc49f1232767ce12c3fa69a5d5fe50vboxsync if (pPool->cDirtyPages == RT_ELEMENTS(pPool->aDirtyPages))
9b726ba798aabd1a27863e6f5cfeef1393bd198dvboxsync pPool->aDirtyPages[idxSlot].uIdx = NIL_PGMPOOL_IDX;
9b726ba798aabd1a27863e6f5cfeef1393bd198dvboxsync Assert(pPool->cDirtyPages <= RT_ELEMENTS(pPool->aDirtyPages));
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync Log(("Removed dirty page %RGp cMods=%d cChanges=%d\n", pPage->GCPhys, pPage->cModifications, cChanges));
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync#if defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0) || defined(IN_RC)
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * Add a new dirty page
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * @param pVM Pointer to the VM.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * @param pPool The pool.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * @param pPage The page.
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsyncvoid pgmPoolAddDirtyPage(PVM pVM, PPGMPOOL pPool, PPGMPOOLPAGE pPage)
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync AssertCompile(RT_ELEMENTS(pPool->aDirtyPages) == 8 || RT_ELEMENTS(pPool->aDirtyPages) == 16);
e8f172f2032e21b4be9a8f3df20e8ef689c6a6favboxsync Assert(pPage->iMonitoredNext == NIL_PGMPOOL_IDX && pPage->iMonitoredPrev == NIL_PGMPOOL_IDX);
ef481e64bafc49f1232767ce12c3fa69a5d5fe50vboxsync if (pPool->cDirtyPages >= RT_ELEMENTS(pPool->aDirtyPages))
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync STAM_COUNTER_INC(&pPool->StatDirtyPageOverFlowFlush);
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync pgmPoolFlushDirtyPage(pVM, pPool, idxFree, true /* allow removal of reused page tables*/);
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync Assert(pPool->cDirtyPages < RT_ELEMENTS(pPool->aDirtyPages));
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync AssertMsg(pPool->aDirtyPages[idxFree].uIdx == NIL_PGMPOOL_IDX, ("idxFree=%d cDirtyPages=%d\n", idxFree, pPool->cDirtyPages));
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync Log(("Add dirty page %RGp (slot=%d)\n", pPage->GCPhys, idxFree));
086e613371e0f6d1efc38fbc199fa20291afcd5evboxsync * Make a copy of the guest page table as we require valid GCPhys addresses
2cd06fc737773d015b5268b9e4dfba5997915957vboxsync * when removing references to physical pages.
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync * (The HCPhys linear lookup is *extremely* expensive!)
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync int rc = PGM_GCPHYS_2_PTR_EX(pVM, pPage->GCPhys, &pvGst); AssertReleaseRC(rc);
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync memcpy(&pPool->aDirtyPages[idxFree].aPage[0], pvGst, (pPage->enmKind == PGMPOOLKIND_PAE_PT_FOR_PAE_PT) ? PAGE_SIZE : PAGE_SIZE/2);
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync if (pPage->enmKind == PGMPOOLKIND_PAE_PT_FOR_PAE_PT)
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync pgmPoolTrackCheckPTPaePae(pPool, pPage, (PPGMSHWPTPAE)pvShw, (PCX86PTPAE)pvGst);
ef481e64bafc49f1232767ce12c3fa69a5d5fe50vboxsync pgmPoolTrackCheckPTPae32Bit(pPool, pPage, (PPGMSHWPTPAE)pvShw, (PCX86PT)pvGst);
ef481e64bafc49f1232767ce12c3fa69a5d5fe50vboxsync pPage->idxDirtyEntry = (uint8_t)idxFree; Assert(pPage->idxDirtyEntry == idxFree);
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync pPool->idxFreeDirtyPage = (pPool->idxFreeDirtyPage + 1) & (RT_ELEMENTS(pPool->aDirtyPages) - 1);
ef481e64bafc49f1232767ce12c3fa69a5d5fe50vboxsync if ( pPool->cDirtyPages < RT_ELEMENTS(pPool->aDirtyPages)
ef481e64bafc49f1232767ce12c3fa69a5d5fe50vboxsync && pPool->aDirtyPages[pPool->idxFreeDirtyPage].uIdx != NIL_PGMPOOL_IDX)
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync unsigned i;
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync for (i = 1; i < RT_ELEMENTS(pPool->aDirtyPages); i++)
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync idxFree = (pPool->idxFreeDirtyPage + i) & (RT_ELEMENTS(pPool->aDirtyPages) - 1);
ef481e64bafc49f1232767ce12c3fa69a5d5fe50vboxsync if (pPool->aDirtyPages[idxFree].uIdx == NIL_PGMPOOL_IDX)
d41220dff1068effe66bb6a11f444811ba58de40vboxsync Assert(pPool->cDirtyPages == RT_ELEMENTS(pPool->aDirtyPages) || pPool->aDirtyPages[pPool->idxFreeDirtyPage].uIdx == NIL_PGMPOOL_IDX);
d41220dff1068effe66bb6a11f444811ba58de40vboxsync# endif /* !IN_RING3 */
d41220dff1068effe66bb6a11f444811ba58de40vboxsync * Check if the specified page is dirty (not write monitored)
b9bd019c26def8e4d617c39121b62d7b8a826e96vboxsync * @return dirty or not
d41220dff1068effe66bb6a11f444811ba58de40vboxsync * @param pVM Pointer to the VM.
d41220dff1068effe66bb6a11f444811ba58de40vboxsync * @param GCPhys Guest physical address
d41220dff1068effe66bb6a11f444811ba58de40vboxsync return false;
d41220dff1068effe66bb6a11f444811ba58de40vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pPool->aDirtyPages); i++)
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync return true;
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync return false;
ef481e64bafc49f1232767ce12c3fa69a5d5fe50vboxsync * Reset all dirty pages by reinstating page monitoring.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * @param pVM Pointer to the VM.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync Assert(pPool->cDirtyPages <= RT_ELEMENTS(pPool->aDirtyPages));
ef481e64bafc49f1232767ce12c3fa69a5d5fe50vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pPool->aDirtyPages); i++)
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync pgmPoolFlushDirtyPage(pVM, pPool, i, true /* allow removal of reused page tables*/);
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync if ( pPool->cDirtyPages != RT_ELEMENTS(pPool->aDirtyPages)
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync && pPool->aDirtyPages[pPool->idxFreeDirtyPage].uIdx != NIL_PGMPOOL_IDX)
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync unsigned i;
ef481e64bafc49f1232767ce12c3fa69a5d5fe50vboxsync for (i = 1; i < RT_ELEMENTS(pPool->aDirtyPages); i++)
ef481e64bafc49f1232767ce12c3fa69a5d5fe50vboxsync AssertMsg(i != RT_ELEMENTS(pPool->aDirtyPages), ("cDirtyPages %d", pPool->cDirtyPages));
ef481e64bafc49f1232767ce12c3fa69a5d5fe50vboxsync Assert(pPool->aDirtyPages[pPool->idxFreeDirtyPage].uIdx == NIL_PGMPOOL_IDX || pPool->cDirtyPages == RT_ELEMENTS(pPool->aDirtyPages));
ef481e64bafc49f1232767ce12c3fa69a5d5fe50vboxsync * Invalidate the PT entry for the specified page
ef481e64bafc49f1232767ce12c3fa69a5d5fe50vboxsync * @param pVM Pointer to the VM.
ef481e64bafc49f1232767ce12c3fa69a5d5fe50vboxsync * @param GCPtrPage Guest page to invalidate
ef481e64bafc49f1232767ce12c3fa69a5d5fe50vboxsyncvoid pgmPoolResetDirtyPage(PVM pVM, RTGCPTR GCPtrPage)
ef481e64bafc49f1232767ce12c3fa69a5d5fe50vboxsync Assert(pPool->cDirtyPages <= RT_ELEMENTS(pPool->aDirtyPages));
dea1368099e5337861dd52906d4c683c447a33c4vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pPool->aDirtyPages); i++)
ef481e64bafc49f1232767ce12c3fa69a5d5fe50vboxsync * Reset all dirty pages by reinstating page monitoring.
dea1368099e5337861dd52906d4c683c447a33c4vboxsync * @param pVM Pointer to the VM.
dea1368099e5337861dd52906d4c683c447a33c4vboxsync * @param GCPhysPT Physical address of the page table
a5c11842b92303b7b5d0086ee5011a969e321b50vboxsyncvoid pgmPoolInvalidateDirtyPage(PVM pVM, RTGCPHYS GCPhysPT)
ef481e64bafc49f1232767ce12c3fa69a5d5fe50vboxsync Assert(pPool->cDirtyPages <= RT_ELEMENTS(pPool->aDirtyPages));
dea1368099e5337861dd52906d4c683c447a33c4vboxsync unsigned idxDirtyPage = RT_ELEMENTS(pPool->aDirtyPages);
dea1368099e5337861dd52906d4c683c447a33c4vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pPool->aDirtyPages); i++)
dea1368099e5337861dd52906d4c683c447a33c4vboxsync if (idxDirtyPage != RT_ELEMENTS(pPool->aDirtyPages))
dea1368099e5337861dd52906d4c683c447a33c4vboxsync pgmPoolFlushDirtyPage(pVM, pPool, idxDirtyPage, true /* allow removal of reused page tables*/);
dea1368099e5337861dd52906d4c683c447a33c4vboxsync if ( pPool->cDirtyPages != RT_ELEMENTS(pPool->aDirtyPages)
dea1368099e5337861dd52906d4c683c447a33c4vboxsync && pPool->aDirtyPages[pPool->idxFreeDirtyPage].uIdx != NIL_PGMPOOL_IDX)
dea1368099e5337861dd52906d4c683c447a33c4vboxsync unsigned i;
dea1368099e5337861dd52906d4c683c447a33c4vboxsync for (i = 0; i < RT_ELEMENTS(pPool->aDirtyPages); i++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertMsg(i != RT_ELEMENTS(pPool->aDirtyPages), ("cDirtyPages %d", pPool->cDirtyPages));
b1c3cdef473df2fbc621d5da81acc82dbfb8a11avboxsync# 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=%d\n", pPage->GCPhys, pPage->idx));
6b022885f2cb6a55167609edecd89570cd80001dvboxsync * 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.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic int pgmPoolCacheFreeOne(PPGMPOOL pPool, uint16_t iUser)
1ce20e84ae29a712029d1e213740388d7e158d5cvboxsync Assert(pPool->iAgeHead != pPool->iAgeTail); /* We shouldn't be here if there < 2 cached entries! */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Select one page from the tail of the age list.
1ce20e84ae29a712029d1e213740388d7e158d5cvboxsync/* This is the alternative to the SyncCR3 pgmPoolCacheUsed calls.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync 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)
8b03ab0bcd5c238021bc8a43d887dd9d0870c0f5vboxsync if (pPool->aPages[iToFree].iUserHead == NIL_PGMPOOL_USER_INDEX)
1ce20e84ae29a712029d1e213740388d7e158d5cvboxsync iToFree = i;
1ce20e84ae29a712029d1e213740388d7e158d5cvboxsync * Reject any attempts at flushing the currently active shadow CR3 mapping.
e17f587595bd5d3a7be56a892e3fd3a0ef83d268vboxsync * Call pgmPoolCacheUsed to move the page to the head of the age list.
3b5afcead60894f1a362df77eaeff7b7cdaee7a9vboxsync LogFlow(("pgmPoolCacheFreeOne: refuse CR3 mapping\n"));
c995102a21cae5b5ffeedadbfaddcc105809e196vboxsync AssertLogRelReturn(iLoop < 8192, VERR_PGM_POOL_TOO_MANY_LOOPS);
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. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * 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.
e85d76a7e5a047db3cdc8576ff5f412c7b73bbabvboxsync * @param enmKind2 The kind of the requested page.
e85d76a7e5a047db3cdc8576ff5f412c7b73bbabvboxsyncstatic bool pgmPoolCacheReusedByKind(PGMPOOLKIND enmKind1, PGMPOOLKIND enmKind2)
e85d76a7e5a047db3cdc8576ff5f412c7b73bbabvboxsync * Never reuse them. There is no remapping in non-paging mode.
00599f6d39cc25ca39845c2433cd75de7b9f6971vboxsync case PGMPOOLKIND_PAE_PDPT_FOR_32BIT: /* never reuse them for other types */
00599f6d39cc25ca39845c2433cd75de7b9f6971vboxsync return false;
8cdd041284cfe47b639146efec02846e20b67a0cvboxsync * It's perfectly fine to reuse these, except for PAE and non-paging stuff.
10e1bc06b2908a0af56d92ffdbadd25b36a5ef61vboxsync return true;
5db1d52ffbcaa46c3d944c6c2d9c552306817d9avboxsync return false;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * It's perfectly fine to reuse these, except for PAE and non-paging stuff.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return true;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return false;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * These cannot be flushed, and it's common to reuse the PDs as PTs.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return false;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Attempts to satisfy a pgmPoolAlloc request from the cache.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code.
74991d7531692858fd22acf371a7ee941567977cvboxsync * @retval VINF_PGM_CACHED_PAGE on success.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VERR_FILE_NOT_FOUND if not found.
7e960d3a0a8a3a84d7aba2cca45d72b1c31cc97bvboxsync * @param pPool The pool.
6b022885f2cb6a55167609edecd89570cd80001dvboxsync * @param GCPhys The GC physical address of the page we're gonna shadow.
b45d66c0e496e2fd861479202f3d43aad592bd14vboxsync * @param enmKind The kind of mapping.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param enmAccess Access type for the mapping (only relevant for big pages)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param fA20Enabled Whether the CPU has the A20 gate enabled.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param iUser The shadow page pool index of the user table.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param iUserTable The index into the user table (shadowed).
1e3cd9c9c95ff352da1331a1789b05fd012c880dvboxsync * @param ppPage Where to store the pointer to the page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic int pgmPoolCacheAlloc(PPGMPOOL pPool, RTGCPHYS GCPhys, PGMPOOLKIND enmKind, PGMPOOLACCESS enmAccess, bool fA20Enabled,
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync uint16_t iUser, uint32_t iUserTable, PPPGMPOOLPAGE ppPage)
fa7355597d7eba5b4ca8a23056ebe1b8fb306fdbvboxsync * Look up the GCPhys in the hash.
74991d7531692858fd22acf371a7ee941567977cvboxsync Log3(("pgmPoolCacheAlloc: %RGp kind %s iUser=%d iUserTable=%x SLOT=%d\n", GCPhys, pgmPoolPoolKindToStr(enmKind), iUser, iUserTable, i));
3a21cbe769e7500039a2d17c794a911f7acb2dadvboxsync Log4(("pgmPoolCacheAlloc: slot %d found page %RGp\n", i, pPage->GCPhys));
6863baa4d9788245537c986d9caf02fb1893d2c6vboxsync /* Put it at the start of the use list to make sure pgmPoolTrackAddUser
6863baa4d9788245537c986d9caf02fb1893d2c6vboxsync * doesn't flush it in case there are no more free use records.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync int rc = pgmPoolTrackAddUser(pPool, pPage, iUser, iUserTable);
74991d7531692858fd22acf371a7ee941567977cvboxsync 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
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * as it has been reused, but in most cases this is normal remapping
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * 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.
0174432b2b1a760b89840ba696f7ba51def65dddvboxsyncstatic void pgmPoolCacheInsert(PPGMPOOL pPool, PPGMPOOLPAGE pPage, bool fCanBeCached)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * 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;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * 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.
a5c11842b92303b7b5d0086ee5011a969e321b50vboxsync * @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_OFFSET_MASK;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* find the head */
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync /* ignore, no monitoring. */
3cac8f8c6923a3a89ecfccda5e89ad75f48658e0vboxsync AssertFatalMsgFailed(("enmKind=%d idx=%d\n", pPage->enmKind, pPage->idx));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync } while (i != NIL_PGMPOOL_IDX);
c33db29e7b41467a35675031f5f5233839909083vboxsync * Enabled 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 pgmPoolMonitorInsert(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
a27fbcbb29ffc2196c2ebd0f2dad92f40c7ec65dvboxsync LogFlow(("pgmPoolMonitorInsert %RGp\n", pPage->GCPhys & ~(RTGCPHYS)PAGE_OFFSET_MASK));
5db1d52ffbcaa46c3d944c6c2d9c552306817d9avboxsync * Filter out the relevant kinds.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Nothing to monitor here. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Nothing to monitor here. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertFatalMsgFailed(("This can't happen! enmKind=%d\n", pPage->enmKind));
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * Install handler.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync PPGMPOOLPAGE pPageHead = pgmPoolMonitorGetPageByGCPhys(pPool, pPage);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Assert(pPageHead != pPage); Assert(pPageHead->iMonitoredNext != pPage->idx);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolFlushDirtyPage(pPool->CTX_SUFF(pVM), pPool, pPageHead->idxDirtyEntry, false /* do not remove */);
a5c11842b92303b7b5d0086ee5011a969e321b50vboxsync pPool->aPages[pPageHead->iMonitoredNext].iMonitoredPrev = pPage->idx;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Assert(pPage->iMonitoredNext == NIL_PGMPOOL_IDX); Assert(pPage->iMonitoredPrev == NIL_PGMPOOL_IDX);
32e2c6f724d4daf2665f2ffa5cbc2333073d42cfvboxsync const RTGCPHYS GCPhysPage = pPage->GCPhys & ~(RTGCPHYS)PAGE_OFFSET_MASK;
32e2c6f724d4daf2665f2ffa5cbc2333073d42cfvboxsync 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));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync 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.
a27fbcbb29ffc2196c2ebd0f2dad92f40c7ec65dvboxsyncstatic int pgmPoolMonitorFlush(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
5db1d52ffbcaa46c3d944c6c2d9c552306817d9avboxsync * Filter out the relevant kinds.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Nothing to monitor here. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertFatalMsgFailed(("This can't happen! enmKind=%d\n", pPage->enmKind));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Remove the page from the monitored list or uninstall it if last.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPGMPOOLPAGE pNewHead = &pPool->aPages[pPage->iMonitoredNext];
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = PGMHandlerPhysicalChangeCallbacks(pVM, pPage->GCPhys & ~(RTGCPHYS)PAGE_OFFSET_MASK,
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_OFFSET_MASK);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertFatalMsg(!(pVCpu->pgm.s.fSyncFlags & PGM_SYNC_CLEAR_PGM_POOL) || VMCPU_FF_ISSET(pVCpu, VMCPU_FF_PGM_SYNC_CR3),
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync ("%#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 * modification 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.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * @param pVM Pointer to the VM.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolMonitorModifiedClearAll: cModifiedPages=%d\n", pPool->cModifiedPages));
5dda7f07dab8a954e6c4cf2378b15f921e60d9aavboxsync AssertMsg(cPages == pPool->cModifiedPages, ("%d != %d\n", cPages, pPool->cModifiedPages));
5dda7f07dab8a954e6c4cf2378b15f921e60d9aavboxsync * Handle SyncCR3 pool tasks
23843d56d4bcd697cc8e0e6c9c01aec7baf6e72cvboxsync * @returns VBox status code.
52694110156cee1511e430c9ae800de121a20050vboxsync * @retval VINF_SUCCESS if successfully added.
5dda7f07dab8a954e6c4cf2378b15f921e60d9aavboxsync * @retval VINF_PGM_SYNC_CR3 is it needs to be deferred to ring 3 (GC only)
5dda7f07dab8a954e6c4cf2378b15f921e60d9aavboxsync * @param pVCpu Pointer to the VMCPU.
5dda7f07dab8a954e6c4cf2378b15f921e60d9aavboxsync * @remark Should only be used when monitoring is available, thus placed in
5dda7f07dab8a954e6c4cf2378b15f921e60d9aavboxsync * the PGMPOOL_WITH_MONITORING #ifdef.
c2fce2002588f0edfbb79bc0cd95354e4343fcc1vboxsync LogFlow(("pgmPoolSyncCR3 fSyncFlags=%x\n", pVCpu->pgm.s.fSyncFlags));
9a99bb9ca6c5bc8ef1977e01e13b05e5cc58319bvboxsync * When monitoring shadowed pages, we reset the modification counters on CR3 sync.
5fdc5337b17150e278798aeafaafde9ee56eba16vboxsync * Occasionally we will have to clear all the shadow page tables because we wanted
d6b5539478863f176bfffefc1ada2b9489cfa092vboxsync * to monitor a page which was mapped by too many shadowed page tables. This operation
9c2450ffd7e8a08cc596a2e4cc4d4e4dc9b382cfvboxsync * sometimes referred to as a 'lightweight flush'.
9c2450ffd7e8a08cc596a2e4cc4d4e4dc9b382cfvboxsync# ifdef IN_RING3 /* Don't flush in ring-0 or raw mode, it's taking too long. */
9c2450ffd7e8a08cc596a2e4cc4d4e4dc9b382cfvboxsync if (pVCpu->pgm.s.fSyncFlags & PGM_SYNC_CLEAR_PGM_POOL)
9c2450ffd7e8a08cc596a2e4cc4d4e4dc9b382cfvboxsync# else /* !IN_RING3 */
9c2450ffd7e8a08cc596a2e4cc4d4e4dc9b382cfvboxsync if (pVCpu->pgm.s.fSyncFlags & PGM_SYNC_CLEAR_PGM_POOL)
5dda7f07dab8a954e6c4cf2378b15f921e60d9aavboxsync Log(("SyncCR3: PGM_SYNC_CLEAR_PGM_POOL is set -> VINF_PGM_SYNC_CR3\n"));
52694110156cee1511e430c9ae800de121a20050vboxsync VMCPU_FF_SET(pVCpu, VMCPU_FF_PGM_SYNC_CR3); /** @todo no need to do global sync, right? */
016950bb1b289514e67d9e473538d22a50c0e408vboxsync /* Make sure all other VCPUs return to ring 3. */
016950bb1b289514e67d9e473538d22a50c0e408vboxsync# endif /* !IN_RING3 */
3cac8f8c6923a3a89ecfccda5e89ad75f48658e0vboxsync /* 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.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VINF_SUCCESS if successfully added.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VERR_PGM_POOL_FLUSHED if the pool was flushed.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param iUser The user index.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic int pgmPoolTrackFreeOneUser(PPGMPOOL pPool, uint16_t iUser)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Just free cached pages in a braindead fashion.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /** @todo walk the age list backwards and free the first with usage. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync } while (pPool->iUserFreeHead == NIL_PGMPOOL_USER_INDEX);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * 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.
32f98f3d0fb00168315b4ece1f0808df4cd88248vboxsync * @retval VERR_PGM_POOL_FLUSHED if the pool was flushed.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
1e3cd9c9c95ff352da1331a1789b05fd012c880dvboxsync * @param pPage The cached page.
8a132edc1577cbe2a19cd778c1b2bea6ae5e8515vboxsync * @param GCPhys The GC physical address of the page we're gonna shadow.
32f98f3d0fb00168315b4ece1f0808df4cd88248vboxsync * @param iUser The user index.
32f98f3d0fb00168315b4ece1f0808df4cd88248vboxsync * @param iUserTable The user table index.
32f98f3d0fb00168315b4ece1f0808df4cd88248vboxsyncDECLINLINE(int) pgmPoolTrackInsert(PPGMPOOL pPool, PPGMPOOLPAGE pPage, RTGCPHYS GCPhys, uint16_t iUser, uint32_t iUserTable)
32f98f3d0fb00168315b4ece1f0808df4cd88248vboxsync LogFlow(("pgmPoolTrackInsert GCPhys=%RGp iUser=%d iUserTable=%x\n", GCPhys, iUser, iUserTable));
32f98f3d0fb00168315b4ece1f0808df4cd88248vboxsync * Check that the entry doesn't already exists.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertMsg(paUsers[i].iUser != iUser || paUsers[i].iUserTable != iUserTable, ("%x %x vs new %x %x\n", paUsers[i].iUser, paUsers[i].iUserTable, iUser, iUserTable));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Find free a user node.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Unlink the user node from the free list,
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * initialize and insert it into the user list.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Insert into cache and enable monitoring of the guest page if enabled.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Until we implement caching of all levels, including the CR3 one, we'll
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * have to make sure we don't try monitor & cache any recursive reuse of
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * a monitored CR3 page. Because all windows versions are doing this we'll
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * have to be able to do combined access monitoring, CR3 + PT and
750d4d0506a38b2e80c997075d40aad474e675fbvboxsync * PD + PT (guest PAE).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * We're now cooperating with the CR3 monitor if an uncachable page is found.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync const bool fCanBeMonitored = true;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolCacheInsert(pPool, pPage, fCanBeMonitored); /* This can be expanded. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Adds a user reference to a page.
afed5ab737f4aacfae3fe73776f40e989190a7cavboxsync * This will move the page to the head of the
6b022885f2cb6a55167609edecd89570cd80001dvboxsync * @returns VBox status code.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VINF_SUCCESS if successfully added.
907da3b41f191bef4c8eb94accb9d16fcbe77019vboxsync * @retval VERR_PGM_POOL_FLUSHED if the pool was flushed.
689e03ca2c98ca6feaab8d9de6e4687a98f14ccbvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The cached page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param iUser The user index.
4b02cd4133ae0d8e4732c57274a59358e418349cvboxsync * @param iUserTable The user table.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic int pgmPoolTrackAddUser(PPGMPOOL pPool, PPGMPOOLPAGE pPage, uint16_t iUser, uint32_t iUserTable)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log3(("pgmPoolTrackAddUser GCPhys = %RGp iUser %x iUserTable %x\n", pPage->GCPhys, iUser, iUserTable));
689e03ca2c98ca6feaab8d9de6e4687a98f14ccbvboxsync * Check that the entry doesn't already exists. We only allow multiple
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * users of top-level paging structures (SHW_POOL_ROOT_IDX).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertMsg(iUser != PGMPOOL_IDX_PD || iUser != PGMPOOL_IDX_PDPT || iUser != PGMPOOL_IDX_NESTED_ROOT || iUser != PGMPOOL_IDX_AMD64_CR3 ||
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync paUsers[i].iUser != iUser || paUsers[i].iUserTable != iUserTable, ("%x %x vs new %x %x\n", paUsers[i].iUser, paUsers[i].iUserTable, iUser, iUserTable));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Allocate a user node.
491e761460097c61edb725a77477cecb2774da45vboxsync * Initialize the user node and insert it.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolFlushDirtyPage(pPool->CTX_SUFF(pVM), pPool, pPage->idxDirtyEntry, false /* do not remove */);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Tell the cache to update its replacement stats for this page.
afed5ab737f4aacfae3fe73776f40e989190a7cavboxsync * Frees a user record associated with a page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * This does not clear the entry in the user table, it simply replaces the
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * user record to the chain of free records.
6b022885f2cb6a55167609edecd89570cd80001dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param HCPhys The HC physical address of the shadow page.
2f1b3d7474489e653b75edf9492132a0f56aab4dvboxsync * @param iUser The shadow page pool index of the user table.
ab1239d8445aa1fd4afddb7d0c8b90bbdc742010vboxsync * @param iUserTable The index into the user table (shadowed).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic void pgmPoolTrackFreeUser(PPGMPOOL pPool, PPGMPOOLPAGE pPage, uint16_t iUser, uint32_t iUserTable)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Unlink and free the specified user entry.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log3(("pgmPoolTrackFreeUser %RGp %x %x\n", pPage->GCPhys, iUser, iUserTable));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Special: For PAE and 32-bit paging, there is usually no more than one user. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* General: Linear search. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Fatal: didn't find it */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertFatalMsgFailed(("Didn't find the user entry! iUser=%d iUserTable=%#x GCPhys=%RGp\n",
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Gets the entry size of a shadow table.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param enmKind The kind of page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns The size of the entry in bytes. That is, 4 or 8.
3080f6c0871099df43a4e91b31894d9c2b1369a8vboxsync * @returns If the kind is not for a table, an assertion is raised and 0 is
75fca099c974cbbd48f132af1378c60232614760vboxsync * returned.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncDECLINLINE(unsigned) pgmPoolTrackGetShadowEntrySize(PGMPOOLKIND enmKind)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Gets the entry size of a guest table.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param enmKind The kind of page.
3080f6c0871099df43a4e91b31894d9c2b1369a8vboxsync * @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.
00599f6d39cc25ca39845c2433cd75de7b9f6971vboxsyncDECLINLINE(unsigned) pgmPoolTrackGetGuestEntrySize(PGMPOOLKIND enmKind)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /** @todo can we return 0? (nobody is calling this...) */
020916e230faa4a37bace3a8480f54fac94ea173vboxsync * Checks one shadow page table entry for a mapping of a physical page.
020916e230faa4a37bace3a8480f54fac94ea173vboxsync * @returns true / false indicating removal of all relevant PTEs
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync * @param pVM Pointer to the VM.
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
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic bool pgmPoolTrackFlushGCPhysPTInt(PVM pVM, PCPGMPAGE pPhysPage, bool fFlushPTEs, uint16_t iShw, uint16_t iPte)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolTrackFlushGCPhysPTInt: pPhysPage=%RHp iShw=%d iPte=%d\n", PGM_PAGE_GET_HCPHYS(pPhysPage), iShw, iPte));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync bool fRet = false;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Assert sanity.
9c425bdea5f0991df62922b1584b805a86f2f898vboxsync AssertFatalMsg(iShw < pPool->cCurPages && iShw != NIL_PGMPOOL_IDX, ("iShw=%d\n", iShw));
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync * Then, clear the actual mappings to the page in the shadow PT.
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync const uint32_t u32 = PGM_PAGE_GET_HCPHYS(pPhysPage) | X86_PTE_P;
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync PX86PT pPT = (PX86PT)PGMPOOL_PAGE_2_PTR(pVM, pPage);
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync case PGM_PAGE_HNDL_PHYS_STATE_NONE: /** No handler installed. */
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync case PGM_PAGE_HNDL_PHYS_STATE_DISABLED: /** Monitoring is temporarily disabled. */
b978e5849454446957177fd47ee98609ab0457a6vboxsync case PGM_PAGE_HNDL_PHYS_STATE_WRITE: /** Write access is monitored. */
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync /* (shouldn't be here, will assert below) */
5007ad5d2bce84d88ee339a94e0aa7b91c699194vboxsync /* Update the counter if we're removing references. */
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync if ((pPT->a[iPte].u & (X86_PTE_PG_MASK | X86_PTE_P)) == u32)
020916e230faa4a37bace3a8480f54fac94ea173vboxsync Log4(("pgmPoolTrackFlushGCPhysPTs: i=%d pte=%RX32\n", iPte, pPT->a[iPte]));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Pte.n.u1Write = 0; /* need to disallow writes when dirty bit tracking is still active. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log(("iFirstPresent=%d cPresent=%d\n", pPage->iFirstPresent, pPage->cPresent));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned i = 0, cFound = 0; i < RT_ELEMENTS(pPT->a); i++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if ((pPT->a[i].u & (X86_PTE_PG_MASK | X86_PTE_P)) == u32)
248c616a220b4b7d67dee7b3d1dfb7b9ad09a107vboxsync AssertFatalMsgFailed(("iFirstPresent=%d cPresent=%d u32=%RX32 poolkind=%x\n", pPage->iFirstPresent, pPage->cPresent, u32, pPage->enmKind));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /*PGM_DYNMAP_UNUSED_HINT_VM(pVM, pPT);*/
b978e5849454446957177fd47ee98609ab0457a6vboxsync case PGMPOOLKIND_EPT_PT_FOR_PHYS: /* physical mask the same as PAE; RW bit as well; be careful! */
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync const uint64_t u64 = PGM_PAGE_GET_HCPHYS(pPhysPage) | X86_PTE_P;
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync PPGMSHWPTPAE pPT = (PPGMSHWPTPAE)PGMPOOL_PAGE_2_PTR(pVM, pPage);
a5c11842b92303b7b5d0086ee5011a969e321b50vboxsync case PGM_PAGE_HNDL_PHYS_STATE_NONE: /* No handler installed. */
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync case PGM_PAGE_HNDL_PHYS_STATE_DISABLED: /* Monitoring is temporarily disabled. */
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync case PGM_PAGE_HNDL_PHYS_STATE_WRITE: /* Write access is monitored. */
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync /* (shouldn't be here, will assert below) */
5007ad5d2bce84d88ee339a94e0aa7b91c699194vboxsync /* Update the counter if we're removing references. */
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync if ((PGMSHWPTEPAE_GET_U(pPT->a[iPte]) & (X86_PTE_PAE_PG_MASK | X86_PTE_P | X86_PTE_PAE_MBZ_MASK_NX)) == u64)
020916e230faa4a37bace3a8480f54fac94ea173vboxsync Log4(("pgmPoolTrackFlushGCPhysPTs: i=%d pte=%RX64\n", iPte, PGMSHWPTEPAE_GET_LOG(pPT->a[iPte])));
b40179b44fea65b72b2f226f62af1ed7bd3c48fcvboxsync Pte.u = (PGMSHWPTEPAE_GET_U(pPT->a[iPte]) & u64AndMask) | u64OrMask;
b40179b44fea65b72b2f226f62af1ed7bd3c48fcvboxsync Pte.n.u1Write = 0; /* need to disallow writes when dirty bit tracking is still active. */
8c9d2065ca6efecd5661174e382314868c0d4b94vboxsync Log(("iFirstPresent=%d cPresent=%d\n", pPage->iFirstPresent, pPage->cPresent));
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync Log(("Found %RX64 expected %RX64\n", PGMSHWPTEPAE_GET_U(pPT->a[iPte]) & (X86_PTE_PAE_PG_MASK | X86_PTE_P | X86_PTE_PAE_MBZ_MASK_NX), u64));
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync for (unsigned i = 0, cFound = 0; i < RT_ELEMENTS(pPT->a); i++)
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync if ((PGMSHWPTEPAE_GET_U(pPT->a[i]) & (X86_PTE_PAE_PG_MASK | X86_PTE_P | X86_PTE_PAE_MBZ_MASK_NX)) == u64)
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync AssertFatalMsgFailed(("iFirstPresent=%d cPresent=%d u64=%RX64 poolkind=%x iPte=%d PT=%RX64\n", pPage->iFirstPresent, pPage->cPresent, u64, pPage->enmKind, iPte, PGMSHWPTEPAE_GET_LOG(pPT->a[iPte])));
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync /*PGM_DYNMAP_UNUSED_HINT_VM(pVM, pPT);*/
020916e230faa4a37bace3a8480f54fac94ea173vboxsync /* Large page case only. */
5007ad5d2bce84d88ee339a94e0aa7b91c699194vboxsync const uint64_t u64 = PGM_PAGE_GET_HCPHYS(pPhysPage) | X86_PDE4M_P | X86_PDE4M_PS;
5007ad5d2bce84d88ee339a94e0aa7b91c699194vboxsync PEPTPD pPD = (PEPTPD)PGMPOOL_PAGE_2_PTR(pVM, pPage);
5007ad5d2bce84d88ee339a94e0aa7b91c699194vboxsync if ((pPD->a[iPte].u & (EPT_PDE2M_PG_MASK | X86_PDE4M_P | X86_PDE4M_PS)) == u64)
5007ad5d2bce84d88ee339a94e0aa7b91c699194vboxsync Log4(("pgmPoolTrackFlushGCPhysPTs: i=%d pde=%RX64\n", iPte, pPD->a[iPte]));
020916e230faa4a37bace3a8480f54fac94ea173vboxsync /* Update the counter as we're removing references. */
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync Log(("iFirstPresent=%d cPresent=%d\n", pPage->iFirstPresent, pPage->cPresent));
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync for (unsigned i = 0, cFound = 0; i < RT_ELEMENTS(pPD->a); i++)
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync if ((pPD->a[i].u & (EPT_PDE2M_PG_MASK | X86_PDE4M_P | X86_PDE4M_PS)) == u64)
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync AssertFatalMsgFailed(("iFirstPresent=%d cPresent=%d\n", pPage->iFirstPresent, pPage->cPresent));
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync /*PGM_DYNMAP_UNUSED_HINT_VM(pVM, pPD);*/
020916e230faa4a37bace3a8480f54fac94ea173vboxsync /* AMD-V nested paging */ /** @todo merge with EPT as we only check the parts that are identical. */
5007ad5d2bce84d88ee339a94e0aa7b91c699194vboxsync const uint64_t u64 = PGM_PAGE_GET_HCPHYS(pPhysPage) | X86_PDE4M_P | X86_PDE4M_PS;
5007ad5d2bce84d88ee339a94e0aa7b91c699194vboxsync PX86PD pPD = (PX86PD)PGMPOOL_PAGE_2_PTR(pVM, pPage);
5007ad5d2bce84d88ee339a94e0aa7b91c699194vboxsync if ((pPD->a[iPte].u & (X86_PDE2M_PAE_PG_MASK | X86_PDE4M_P | X86_PDE4M_PS)) == u64)
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync Log4(("pgmPoolTrackFlushGCPhysPTs: i=%d pde=%RX64\n", iPte, pPD->a[iPte]));
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync /* Update the counter as we're removing references. */
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync Log(("iFirstPresent=%d cPresent=%d\n", pPage->iFirstPresent, pPage->cPresent));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned i = 0, cFound = 0; i < RT_ELEMENTS(pPD->a); i++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if ((pPD->a[i].u & (X86_PDE2M_PAE_PG_MASK | X86_PDE4M_P | X86_PDE4M_PS)) == u64)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertFatalMsgFailed(("iFirstPresent=%d cPresent=%d\n", pPage->iFirstPresent, pPage->cPresent));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /*PGM_DYNMAP_UNUSED_HINT_VM(pVM, pPD);*/
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync#endif /* PGM_WITH_LARGE_PAGES */
aaeb2e2f6ed5b164f1dec9a16a7adeb84f64cf31vboxsync AssertFatalMsgFailed(("enmKind=%d iShw=%d\n", pPage->enmKind, iShw));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* not reached. */
020916e230faa4a37bace3a8480f54fac94ea173vboxsync * Scans one shadow page table for mappings of a physical page.
020916e230faa4a37bace3a8480f54fac94ea173vboxsync * @param pVM Pointer to the VM.
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)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param iShw The shadow page table.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic void pgmPoolTrackFlushGCPhysPT(PVM pVM, PPGMPAGE pPhysPage, bool fFlushPTEs, uint16_t iShw)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync 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);
b978e5849454446957177fd47ee98609ab0457a6vboxsync Log2(("pgmPoolTrackFlushGCPhysPT: pPhysPage=%RHp iShw=%d\n", PGM_PAGE_GET_HCPHYS(pPhysPage), iShw));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_PROFILE_START(&pPool->StatTrackFlushGCPhysPT, f);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync bool fKeptPTEs = pgmPoolTrackFlushGCPhysPTInt(pVM, pPhysPage, fFlushPTEs, iShw, PGM_PAGE_GET_PTE_INDEX(pPhysPage));
9424be2edf0232241bc75178b401464d4de76cadvboxsync STAM_PROFILE_STOP(&pPool->StatTrackFlushGCPhysPT, f);
7696b635f26eb0a48aaddab6cc39da44e81fbdaevboxsync * Flushes a list of shadow page tables mapping the same physical page.
b978e5849454446957177fd47ee98609ab0457a6vboxsync * @param pVM Pointer to the VM.
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 iPhysExt The physical cross reference extent list to flush.
6b022885f2cb6a55167609edecd89570cd80001dvboxsyncstatic void pgmPoolTrackFlushGCPhysPTs(PVM pVM, PPGMPAGE pPhysPage, bool fFlushPTEs, uint16_t iPhysExt)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync bool fKeepList = false;
b978e5849454446957177fd47ee98609ab0457a6vboxsync STAM_PROFILE_START(&pPool->StatTrackFlushGCPhysPTs, f);
5007ad5d2bce84d88ee339a94e0aa7b91c699194vboxsync Log2(("pgmPoolTrackFlushGCPhysPTs: pPhysPage=%RHp iPhysExt\n", PGM_PAGE_GET_HCPHYS(pPhysPage), iPhysExt));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned i = 0; i < RT_ELEMENTS(pPhysExt->aidx); i++)
b978e5849454446957177fd47ee98609ab0457a6vboxsync bool fKeptPTEs = pgmPoolTrackFlushGCPhysPTInt(pVM, pPhysPage, fFlushPTEs, pPhysExt->aidx[i], pPhysExt->apte[i]);
11c599b71a8c202a506b8623af57432c3d415ddavboxsync /* insert the list into the free list and clear the ram range entry. */
11c599b71a8c202a506b8623af57432c3d415ddavboxsync /* Invalidate the tracking data. */
965a56f05878cf7c9634998e98d0bed41ebf21dbvboxsync STAM_PROFILE_STOP(&pPool->StatTrackFlushGCPhysPTs, f);
b978e5849454446957177fd47ee98609ab0457a6vboxsync * Flushes all shadow page table mappings of the given guest page.
11c599b71a8c202a506b8623af57432c3d415ddavboxsync * This is typically called when the host page backing the guest one has been
11c599b71a8c202a506b8623af57432c3d415ddavboxsync * replaced or when the page protection was changed due to a guest access
11c599b71a8c202a506b8623af57432c3d415ddavboxsync * caught by the monitoring.
11c599b71a8c202a506b8623af57432c3d415ddavboxsync * @returns VBox status code.
bbbec97e47d726fe8f4ccf775c971846b3dde7eevboxsync * @retval VINF_SUCCESS if all references has been successfully cleared.
d7f733dd34ab7755807d85016b7c2ab3d1a362d4vboxsync * @retval VINF_PGM_SYNC_CR3 if we're better off with a CR3 sync and a page
11c599b71a8c202a506b8623af57432c3d415ddavboxsync * pool cleaning. FF and sync flags are set.
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync * @param pVM Pointer to the VM.
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync * @param GCPhysPage GC physical address of the page in question
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync * @param pPhysPage The guest page in question.
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync * @param fFlushPTEs Flush PTEs or allow them to be updated (e.g. in case of an RW bit change)
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync * @param pfFlushTLBs This is set to @a true if the shadow TLBs should be
34e34d3656484dde89a9c7b57fcbf7048d2fdb13vboxsync * flushed, it is NOT touched if this isn't necessary.
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync * The caller MUST initialized this to @a false.
7b5d0a97e9f87008f7b31583653d93dccaffe5cevboxsyncint pgmPoolTrackUpdateGCPhys(PVM pVM, RTGCPHYS GCPhysPage, PPGMPAGE pPhysPage, bool fFlushPTEs, bool *pfFlushTLBs)
7b5d0a97e9f87008f7b31583653d93dccaffe5cevboxsync /* Is this page part of a large page? */
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync if (PGM_PAGE_GET_PDE_TYPE(pPhysPage) == PGM_PAGE_PDE_TYPE_PDE)
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync RTGCPHYS GCPhysBase = GCPhysPage & X86_PDE2M_PAE_PG_MASK;
b301c2ed80b2ae5201801c30b37618a158fcc14evboxsync /* Fetch the large page base. */
b301c2ed80b2ae5201801c30b37618a158fcc14evboxsync Log(("pgmPoolTrackUpdateGCPhys: update large page PDE for %RGp (%RGp)\n", GCPhysBase, GCPhysPage));
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync if (PGM_PAGE_GET_PDE_TYPE(pLargePage) == PGM_PAGE_PDE_TYPE_PDE)
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync /* Mark the large page as disabled as we need to break it up to change a single page in the 2 MB range. */
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync PGM_PAGE_SET_PDE_TYPE(pVM, pLargePage, PGM_PAGE_PDE_TYPE_PDE_DISABLED);
11c599b71a8c202a506b8623af57432c3d415ddavboxsync /* Update the base as that *only* that one has a reference and there's only one PDE to clear. */
11c599b71a8c202a506b8623af57432c3d415ddavboxsync rc = pgmPoolTrackUpdateGCPhys(pVM, GCPhysBase, pLargePage, fFlushPTEs, pfFlushTLBs);
11c599b71a8c202a506b8623af57432c3d415ddavboxsync#endif /* PGM_WITH_LARGE_PAGES */
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync const uint16_t u16 = PGM_PAGE_GET_TRACKING(pPhysPage);
11c599b71a8c202a506b8623af57432c3d415ddavboxsync * The zero page is currently screwing up the tracking and we'll
11c599b71a8c202a506b8623af57432c3d415ddavboxsync * have to flush the whole shebang. Unless VBOX_WITH_NEW_LAZY_PAGE_ALLOC
11c599b71a8c202a506b8623af57432c3d415ddavboxsync * is defined, zero pages won't normally be mapped. Some kind of solution
020916e230faa4a37bace3a8480f54fac94ea173vboxsync * will be needed for this problem of course, but it will have to wait...
11c599b71a8c202a506b8623af57432c3d415ddavboxsync# if defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0) || defined(IN_RC) /** @todo we can drop this now. */
b978e5849454446957177fd47ee98609ab0457a6vboxsync /* Start a subset here because pgmPoolTrackFlushGCPhysPTsSlow and
11c599b71a8c202a506b8623af57432c3d415ddavboxsync pgmPoolTrackFlushGCPhysPTs will/may kill the pool otherwise. */
11c599b71a8c202a506b8623af57432c3d415ddavboxsync uint32_t iPrevSubset = PGMRZDynMapPushAutoSubset(pVCpu);
fbf5c218f8bc15f0d765fef4b81e745f4db71b7avboxsync if (PGMPOOL_TD_GET_CREFS(u16) != PGMPOOL_TD_CREFS_PHYSEXT)
d6b5539478863f176bfffefc1ada2b9489cfa092vboxsync else if (u16 != PGMPOOL_TD_MAKE(PGMPOOL_TD_CREFS_PHYSEXT, PGMPOOL_TD_IDX_OVERFLOWED))
bbbec97e47d726fe8f4ccf775c971846b3dde7eevboxsync pgmPoolTrackFlushGCPhysPTs(pVM, pPhysPage, fFlushPTEs, PGMPOOL_TD_GET_IDX(u16));
965a56f05878cf7c9634998e98d0bed41ebf21dbvboxsync rc = pgmPoolTrackFlushGCPhysPTsSlow(pVM, pPhysPage);
11c599b71a8c202a506b8623af57432c3d415ddavboxsync# if defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0) || defined(IN_RC)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pVCpu->pgm.s.fSyncFlags |= PGM_SYNC_CLEAR_PGM_POOL;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Scans all shadow page tables for mappings of a physical page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * This may be slow, but it's most likely more efficient than cleaning
bee80f3f77b15c166b7debd080a70e5231ba6751vboxsync * out the entire page pool / cache.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VINF_SUCCESS if all references has been successfully cleared.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VINF_PGM_GCPHYS_ALIASED if we're better off with a CR3 sync and
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * a page pool cleaning.
55a158b986cee4c4ebe1a650e8727e1c6905e32evboxsync * @param pVM Pointer to the VM.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPhysPage The guest page in question.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncint pgmPoolTrackFlushGCPhysPTsSlow(PVM pVM, PPGMPAGE pPhysPage)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_PROFILE_START(&pPool->StatTrackFlushGCPhysPTsSlow, s);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolTrackFlushGCPhysPTsSlow: cUsedPages=%d cPresent=%d pPhysPage=%R[pgmpage]\n",
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync * There is a limit to what makes sense.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolTrackFlushGCPhysPTsSlow: giving up... (cPresent=%d)\n", pPool->cPresent));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_PROFILE_STOP(&pPool->StatTrackFlushGCPhysPTsSlow, s);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Iterate all the pages until we've encountered all that in use.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * This is simple but not quite optimal solution.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync const uint64_t u64 = PGM_PAGE_GET_HCPHYS(pPhysPage) | X86_PTE_P; /** @todo drop X86_PTE_P here as we always test if present separately, anyway. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync const uint32_t u32 = u64; /** @todo move into the 32BIT_PT_xx case */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * We only care about shadow page tables.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PX86PT pPT = (PX86PT)PGMPOOL_PAGE_2_PTR(pVM, pPage);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pPT->a); i++)
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync if ((pPT->a[i].u & (X86_PTE_PG_MASK | X86_PTE_P)) == u32)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync //Log4(("pgmPoolTrackFlushGCPhysPTsSlow: idx=%d i=%d pte=%RX32\n", iPage, i, pPT->a[i]));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPT->a[i].u = 0;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Update the counter as we're removing references. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPGMSHWPTPAE pPT = (PPGMSHWPTPAE)PGMPOOL_PAGE_2_PTR(pVM, pPage);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pPT->a); i++)
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync if ((PGMSHWPTEPAE_GET_U(pPT->a[i]) & (X86_PTE_PAE_PG_MASK | X86_PTE_P)) == u64)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync //Log4(("pgmPoolTrackFlushGCPhysPTsSlow: idx=%d i=%d pte=%RX64\n", iPage, i, pPT->a[i]));
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync PGMSHWPTEPAE_SET(pPT->a[i], 0); /// @todo why not atomic?
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync /* Update the counter as we're removing references. */
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync PEPTPT pPT = (PEPTPT)PGMPOOL_PAGE_2_PTR(pVM, pPage);
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pPT->a); i++)
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync if ((pPT->a[i].u & (EPT_PTE_PG_MASK | X86_PTE_P)) == u64)
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync //Log4(("pgmPoolTrackFlushGCPhysPTsSlow: idx=%d i=%d pte=%RX64\n", iPage, i, pPT->a[i]));
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync pPT->a[i].u = 0;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Update the counter as we're removing references. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_PROFILE_STOP(&pPool->StatTrackFlushGCPhysPTsSlow, s);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * There is a limit to what makes sense. The above search is very expensive, so force a pgm pool flush.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolTrackFlushGCPhysPTsSlow: giving up... (cPresent=%d)\n", pPool->cPresent));
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)
1b7f3a92e42fb9cabf96cf31c20481da466edf76vboxsync * Map the user page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPGMPOOLPAGE pUserPage = &pPool->aPages[pUser->iUser];
ac4d756407655dded93d992085e6cf2f7c45f592vboxsync u.pau64 = (uint64_t *)PGMPOOL_PAGE_2_PTR(pPool->CTX_SUFF(pVM), pUserPage);
9f1e0743f565b1975bb4efd7311b30cfa0d3e384vboxsync LogFlow(("pgmPoolTrackClearPageUser: clear %x in %s (%RGp) (flushing %s)\n", iUserTable, pgmPoolPoolKindToStr(pUserPage->enmKind), pUserPage->Core.Key, pgmPoolPoolKindToStr(pPage->enmKind)));
2b88b28162a49c6fa769c03d56767a9806d4f456vboxsync /* Safety precaution in case we change the paging for other modes too in the future. */
00599f6d39cc25ca39845c2433cd75de7b9f6971vboxsync * Some sanity checks.
8f7bc6ad2b7bbcb4b3b96248cd2478e45f2e3b88vboxsync Assert(!(u.pau64[iUserTable] & PGM_PLXFLAGS_PERMANENT));
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync Assert(!(u.pau64[iUserTable] & PGM_PDFLAGS_MAPPING));
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync Assert(!(u.pau64[iUserTable] & PGM_PLXFLAGS_PERMANENT));
da936e0446fb2b56b813d5d938f1dfc6e4bf8b13vboxsync Assert(!(u.pau64[iUserTable] & PGM_PLXFLAGS_PERMANENT));
ec588a4ac8429a8b6c744544818b3ce3b2c75690vboxsync /* GCPhys >> PAGE_SHIFT is the index here */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertMsgFailed(("enmKind=%d\n", pUserPage->enmKind));
00599f6d39cc25ca39845c2433cd75de7b9f6971vboxsync#endif /* VBOX_STRICT */
00599f6d39cc25ca39845c2433cd75de7b9f6971vboxsync * Clear the entry in the user page.
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync /* 32-bit entries */
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync /* 64-bit entries */
3080f6c0871099df43a4e91b31894d9c2b1369a8vboxsync * In 32 bits PAE mode we *must* invalidate the TLB when changing a
2b88b28162a49c6fa769c03d56767a9806d4f456vboxsync * PDPT entry; the CPU fetches them only during cr3 load, so any
ec588a4ac8429a8b6c744544818b3ce3b2c75690vboxsync * non-present PDPT will continue to cause page faults.
4b02cd4133ae0d8e4732c57274a59358e418349cvboxsync /* no break */
907da3b41f191bef4c8eb94accb9d16fcbe77019vboxsync AssertFatalMsgFailed(("enmKind=%d iUser=%d iUserTable=%#x\n", pUserPage->enmKind, pUser->iUser, pUser->iUserTable));
6b022885f2cb6a55167609edecd89570cd80001dvboxsync PGM_DYNMAP_UNUSED_HINT_VM(pPool->CTX_SUFF(pVM), u.pau64);
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. */
3cac8f8c6923a3a89ecfccda5e89ad75f48658e0vboxsync pgmPoolTrackClearPageUser(pPool, pPage, &paUsers[i]);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Free it. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Next. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Allocates a new physical cross reference extent.
6b022885f2cb6a55167609edecd89570cd80001dvboxsync * @returns Pointer to the allocated extent on success. NULL if we're out of them.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM Pointer to the VM.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param piPhysExt Where to store the phys ext index.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncPPGMPOOLPHYSEXT pgmPoolTrackPhysExtAlloc(PVM pVM, uint16_t *piPhysExt)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_COUNTER_INC(&pPool->StamTrackPhysExtAllocFailures);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPGMPOOLPHYSEXT pPhysExt = &pPool->CTX_SUFF(paPhysExts)[iPhysExt];
5007ad5d2bce84d88ee339a94e0aa7b91c699194vboxsync * Frees a physical cross reference extent.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM Pointer to the VM.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @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.
e4ea543752422f1139923e3e506c625b0a1827c5vboxsync * @param pVM Pointer to the VM.
5007ad5d2bce84d88ee339a94e0aa7b91c699194vboxsync * @param iPhysExt The extent to free.
5007ad5d2bce84d88ee339a94e0aa7b91c699194vboxsyncvoid pgmPoolTrackPhysExtFreeList(PVM pVM, uint16_t iPhysExt)
3cac8f8c6923a3a89ecfccda5e89ad75f48658e0vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pPhysExt->aidx); i++)
6b022885f2cb6a55167609edecd89570cd80001dvboxsync * Insert a reference into a list of physical cross reference extents.
053eccf0693eaef856866aef1a8b7ee4abf11f1fvboxsync * @returns The new tracking data for PGMPAGE.
053eccf0693eaef856866aef1a8b7ee4abf11f1fvboxsync * @param pVM Pointer to the VM.
053eccf0693eaef856866aef1a8b7ee4abf11f1fvboxsync * @param iPhysExt The physical extent index of the list head.
053eccf0693eaef856866aef1a8b7ee4abf11f1fvboxsync * @param iShwPT The shadow page table index.
053eccf0693eaef856866aef1a8b7ee4abf11f1fvboxsync * @param iPte Page table entry
053eccf0693eaef856866aef1a8b7ee4abf11f1fvboxsyncstatic uint16_t pgmPoolTrackPhysExtInsert(PVM pVM, uint16_t iPhysExt, uint16_t iShwPT, uint16_t iPte)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPGMPOOLPHYSEXT paPhysExts = pPool->CTX_SUFF(paPhysExts);
1986f56777969a25707ab214f8dd070804be666cvboxsync * Special common cases.
65ff326ac3915638f5c4e79c2c3e836aeeeb86devboxsync if (paPhysExts[iPhysExt].aidx[1] == NIL_PGMPOOL_IDX)
053eccf0693eaef856866aef1a8b7ee4abf11f1fvboxsync STAM_COUNTER_INC(&pVM->pgm.s.CTX_SUFF(pStats)->StatTrackAliasedMany);
053eccf0693eaef856866aef1a8b7ee4abf11f1fvboxsync LogFlow(("pgmPoolTrackPhysExtInsert: %d:{,%d pte %d,}\n", iPhysExt, iShwPT, iPte));
053eccf0693eaef856866aef1a8b7ee4abf11f1fvboxsync return PGMPOOL_TD_MAKE(PGMPOOL_TD_CREFS_PHYSEXT, iPhysExt);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if (paPhysExts[iPhysExt].aidx[2] == NIL_PGMPOOL_IDX)
e4ea543752422f1139923e3e506c625b0a1827c5vboxsync STAM_COUNTER_INC(&pVM->pgm.s.CTX_SUFF(pStats)->StatTrackAliasedMany);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolTrackPhysExtInsert: %d:{,,%d pte %d}\n", iPhysExt, iShwPT, iPte));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return PGMPOOL_TD_MAKE(PGMPOOL_TD_CREFS_PHYSEXT, iPhysExt);
5007ad5d2bce84d88ee339a94e0aa7b91c699194vboxsync AssertCompile(RT_ELEMENTS(paPhysExts[iPhysExt].aidx) == 3);
65ff326ac3915638f5c4e79c2c3e836aeeeb86devboxsync * General treatment.
65ff326ac3915638f5c4e79c2c3e836aeeeb86devboxsync for (unsigned i = 0; i < RT_ELEMENTS(paPhysExts[iPhysExt].aidx); i++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if (paPhysExts[iPhysExt].aidx[i] == NIL_PGMPOOL_IDX)
fa88302d5e91b79aeae01c928f33437088a90153vboxsync STAM_COUNTER_INC(&pVM->pgm.s.CTX_SUFF(pStats)->StatTrackAliasedMany);
053eccf0693eaef856866aef1a8b7ee4abf11f1fvboxsync 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);
053eccf0693eaef856866aef1a8b7ee4abf11f1fvboxsync STAM_COUNTER_INC(&pVM->pgm.s.CTX_SUFF(pStats)->StatTrackOverflows);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolTrackPhysExtInsert: overflow (1) iShwPT=%d\n", iShwPT));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return PGMPOOL_TD_MAKE(PGMPOOL_TD_CREFS_PHYSEXT, PGMPOOL_TD_IDX_OVERFLOWED);
96fb9e5765400c1ad6e462d0a25680e2312dd54cvboxsync /* advance */
65ff326ac3915638f5c4e79c2c3e836aeeeb86devboxsync * Add another extent to the list.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPGMPOOLPHYSEXT pNew = pgmPoolTrackPhysExtAlloc(pVM, &iPhysExt);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_COUNTER_INC(&pVM->pgm.s.CTX_SUFF(pStats)->StatTrackNoExtentsLeft);
65ff326ac3915638f5c4e79c2c3e836aeeeb86devboxsync LogFlow(("pgmPoolTrackPhysExtInsert: pgmPoolTrackPhysExtAlloc failed iShwPT=%d\n", iShwPT));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return PGMPOOL_TD_MAKE(PGMPOOL_TD_CREFS_PHYSEXT, PGMPOOL_TD_IDX_OVERFLOWED);
5007ad5d2bce84d88ee339a94e0aa7b91c699194vboxsync 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.
65ff326ac3915638f5c4e79c2c3e836aeeeb86devboxsync * @param pVM Pointer to the VM.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPhysPage Pointer to the aPages entry in the ram range.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param u16 The ram range flags (top 16-bits).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param iShwPT The shadow page table index.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param iPte Page table entry
1986f56777969a25707ab214f8dd070804be666cvboxsyncuint16_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.
ba15b5303eb3e9ebd10e3d357f51335399f9d28dvboxsync PPGMPOOLPHYSEXT pPhysExt = pgmPoolTrackPhysExtAlloc(pVM, &iPhysExt);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolTrackPhysExtAddref: new extent: %d:{%d, %d}\n", iPhysExt, PGMPOOL_TD_GET_IDX(u16), iShwPT));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_COUNTER_INC(&pVM->pgm.s.CTX_SUFF(pStats)->StatTrackAliased);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPhysExt->apte[0] = PGM_PAGE_GET_PTE_INDEX(pPhysPage);
d7f733dd34ab7755807d85016b7c2ab3d1a362d4vboxsync u16 = PGMPOOL_TD_MAKE(PGMPOOL_TD_CREFS_PHYSEXT, iPhysExt);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync u16 = PGMPOOL_TD_MAKE(PGMPOOL_TD_CREFS_PHYSEXT, PGMPOOL_TD_IDX_OVERFLOWED);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync else if (u16 != PGMPOOL_TD_MAKE(PGMPOOL_TD_CREFS_PHYSEXT, PGMPOOL_TD_IDX_OVERFLOWED))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Insert into the extent list.
aaeb2e2f6ed5b164f1dec9a16a7adeb84f64cf31vboxsync u16 = pgmPoolTrackPhysExtInsert(pVM, PGMPOOL_TD_GET_IDX(u16), iShwPT, iPte);
82e90599291da476b2de7c8db33cfb0f2cbac774vboxsync STAM_COUNTER_INC(&pVM->pgm.s.CTX_SUFF(pStats)->StatTrackAliasedLots);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Clear references to guest physical memory.
d7f733dd34ab7755807d85016b7c2ab3d1a362d4vboxsync * @param pPool The pool.
d7f733dd34ab7755807d85016b7c2ab3d1a362d4vboxsync * @param pPage The page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPhysPage Pointer to the aPages entry in the ram range.
6b022885f2cb6a55167609edecd89570cd80001dvboxsync * @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));
e4ea543752422f1139923e3e506c625b0a1827c5vboxsync uint16_t iPhysExt = PGM_PAGE_GET_TD_IDX(pPhysPage);
5007ad5d2bce84d88ee339a94e0aa7b91c699194vboxsync PPGMPOOLPHYSEXT paPhysExts = pPool->CTX_SUFF(paPhysExts);
d7f733dd34ab7755807d85016b7c2ab3d1a362d4vboxsync * Look for the shadow page and check if it's all freed.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned i = 0; i < RT_ELEMENTS(paPhysExts[iPhysExt].aidx); i++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync paPhysExts[iPhysExt].apte[i] = NIL_PGMPOOL_PHYSEXT_IDX_PTE;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (i = 0; i < RT_ELEMENTS(paPhysExts[iPhysExt].aidx); i++)
bee80f3f77b15c166b7debd080a70e5231ba6751vboxsync if (paPhysExts[iPhysExt].aidx[i] != NIL_PGMPOOL_IDX)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log2(("pgmPoolTrackPhysExtDerefGCPhys: pPhysPage=%R[pgmpage] idx=%d\n", pPhysPage, pPage->idx));
65ff326ac3915638f5c4e79c2c3e836aeeeb86devboxsync /* we can free the node. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync const uint16_t iPhysExtNext = paPhysExts[iPhysExt].iNext;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* lonely node */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log2(("pgmPoolTrackPhysExtDerefGCPhys: pPhysPage=%R[pgmpage] idx=%d lonely\n", pPhysPage, pPage->idx));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync 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(pVM, pPhysPage, PGMPOOL_TD_MAKE(PGMPOOL_TD_CREFS_PHYSEXT, iPhysExtNext));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* in list */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync 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 */
82e90599291da476b2de7c8db33cfb0f2cbac774vboxsync Log2(("pgmPoolTrackPhysExtDerefGCPhys: pPhysPage=%R[pgmpage]\n", pPhysPage));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Clear references to guest physical memory.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * This is the same as pgmPoolTracDerefGCPhysHint except that the guest
1999ae03c34840fa4d712fd2e020120b2cb7182avboxsync * physical address is assumed to be correct, so the linear search can be
1999ae03c34840fa4d712fd2e020120b2cb7182avboxsync * skipped and we can assert at an earlier point.
1999ae03c34840fa4d712fd2e020120b2cb7182avboxsync * @param pPool The pool.
3cac8f8c6923a3a89ecfccda5e89ad75f48658e0vboxsync * @param pPage The page.
1999ae03c34840fa4d712fd2e020120b2cb7182avboxsync * @param HCPhys The host physical address corresponding to the guest page.
1999ae03c34840fa4d712fd2e020120b2cb7182avboxsync * @param GCPhys The guest physical address corresponding to HCPhys.
3cac8f8c6923a3a89ecfccda5e89ad75f48658e0vboxsync * @param iPte Shadow PTE index
1999ae03c34840fa4d712fd2e020120b2cb7182avboxsyncstatic void pgmPoolTracDerefGCPhys(PPGMPOOL pPool, PPGMPOOLPAGE pPage, RTHCPHYS HCPhys, RTGCPHYS GCPhys, uint16_t iPte)
1999ae03c34840fa4d712fd2e020120b2cb7182avboxsync * Lookup the page and check if it checks out before derefing it.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync RTHCPHYS HCPhysPage = PGM_PAGE_GET_HCPHYS(pPhysPage);
7d917e684060e8f39effae0a7f819465d6a343d8vboxsync Log2(("pgmPoolTracDerefGCPhys %RHp vs %RHp\n", HCPhysPage, HCPhys));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmTrackDerefGCPhys(pPool, pPage, pPhysPage, iPte);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertFatalMsgFailed(("HCPhys=%RHp GCPhys=%RGp; found page has HCPhys=%RHp\n",
fa7355597d7eba5b4ca8a23056ebe1b8fb306fdbvboxsync AssertFatalMsgFailed(("HCPhys=%RHp GCPhys=%RGp\n", HCPhys, GCPhys));
1999ae03c34840fa4d712fd2e020120b2cb7182avboxsync * Clear references to guest physical memory.
1999ae03c34840fa4d712fd2e020120b2cb7182avboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The page.
1999ae03c34840fa4d712fd2e020120b2cb7182avboxsync * @param HCPhys The host physical address corresponding to the guest page.
1999ae03c34840fa4d712fd2e020120b2cb7182avboxsync * @param GCPhysHint The guest physical address which may corresponding to HCPhys.
1999ae03c34840fa4d712fd2e020120b2cb7182avboxsync * @param iPte Shadow pte index
1999ae03c34840fa4d712fd2e020120b2cb7182avboxsyncvoid pgmPoolTracDerefGCPhysHint(PPGMPOOL pPool, PPGMPOOLPAGE pPage, RTHCPHYS HCPhys, RTGCPHYS GCPhysHint, uint16_t iPte)
1999ae03c34840fa4d712fd2e020120b2cb7182avboxsync Log4(("pgmPoolTracDerefGCPhysHint %RHp %RGp\n", HCPhys, GCPhysHint));
1999ae03c34840fa4d712fd2e020120b2cb7182avboxsync * Try the hint first.
1999ae03c34840fa4d712fd2e020120b2cb7182avboxsync PPGMPAGE pPhysPage = pgmPhysGetPage(pVM, GCPhysHint);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmTrackDerefGCPhys(pPool, pPage, pPhysPage, iPte);
53163a75972769c720ae0b51a007ce4de6408778vboxsync * Damn, the hint didn't work. We'll have to do an expensive linear search.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_COUNTER_INC(&pPool->StatTrackLinearRamSearches);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPGMRAMRANGE pRam = pPool->CTX_SUFF(pVM)->pgm.s.CTX_SUFF(pRamRangesX);
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);
1f8ba3bc3e0f62b02e3dc7440cdd6519e8c64e30vboxsync AssertFatalMsgFailed(("HCPhys=%RHp GCPhysHint=%RGp (Hinted page has HCPhys = %RHp)\n", HCPhys, GCPhysHint, HCPhysHinted));
82e90599291da476b2de7c8db33cfb0f2cbac774vboxsync * Clear references to guest physical memory in a 32-bit / 32-bit page table.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The page.
1f8ba3bc3e0f62b02e3dc7440cdd6519e8c64e30vboxsync * @param pShwPT The shadow page table (mapping of the page).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pGstPT The guest page table.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncDECLINLINE(void) pgmPoolTrackDerefPT32Bit32Bit(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PT pShwPT, PCX86PT pGstPT)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync RTGCPHYS32 const fPgMask = pPage->fA20Enabled ? X86_PTE_PG_MASK : X86_PTE_PG_MASK & ~RT_BIT_32(20);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pShwPT->a); i++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log4(("pgmPoolTrackDerefPT32Bit32Bit: i=%d pte=%RX32 hint=%RX32\n",
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync 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 & fPgMask, i);
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync * Clear references to guest physical memory in a PAE / 32-bit page table.
eab582ddaaa130fc769ad00b09b81b3966817d3fvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The page.
1f8ba3bc3e0f62b02e3dc7440cdd6519e8c64e30vboxsync * @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, PPGMSHWPTPAE pShwPT, PCX86PT pGstPT)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync RTGCPHYS32 const fPgMask = pPage->fA20Enabled ? X86_PTE_PG_MASK : X86_PTE_PG_MASK & ~RT_BIT_32(20);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pShwPT->a); i++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Assert( (PGMSHWPTEPAE_GET_U(pShwPT->a[i]) & UINT64_C(0x7ff0000000000400)) == 0
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync || (PGMSHWPTEPAE_GET_U(pShwPT->a[i]) & UINT64_C(0x7ff0000000000400)) == UINT64_C(0x7ff0000000000000));
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync Log4(("pgmPoolTrackDerefPTPae32Bit: i=%d pte=%RX64 hint=%RX32\n",
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync i, PGMSHWPTEPAE_GET_HCPHYS(pShwPT->a[i]), pGstPT->a[i].u & X86_PTE_PG_MASK));
eab582ddaaa130fc769ad00b09b81b3966817d3fvboxsync pgmPoolTracDerefGCPhysHint(pPool, pPage, PGMSHWPTEPAE_GET_HCPHYS(pShwPT->a[i]), pGstPT->a[i].u & fPgMask, i);
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync * Clear references to guest physical memory in a PAE / PAE page table.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
1f8ba3bc3e0f62b02e3dc7440cdd6519e8c64e30vboxsync * @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, PPGMSHWPTPAE pShwPT, PCX86PTPAE pGstPT)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync RTGCPHYS const fPgMask = pPage->fA20Enabled ? X86_PTE_PAE_PG_MASK : X86_PTE_PAE_PG_MASK & ~RT_BIT_64(20);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pShwPT->a); i++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Assert( (PGMSHWPTEPAE_GET_U(pShwPT->a[i]) & UINT64_C(0x7ff0000000000400)) == 0
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync || (PGMSHWPTEPAE_GET_U(pShwPT->a[i]) & UINT64_C(0x7ff0000000000400)) == UINT64_C(0x7ff0000000000000));
eab582ddaaa130fc769ad00b09b81b3966817d3fvboxsync Log4(("pgmPoolTrackDerefPTPaePae: i=%d pte=%RX32 hint=%RX32\n",
eab582ddaaa130fc769ad00b09b81b3966817d3fvboxsync i, PGMSHWPTEPAE_GET_HCPHYS(pShwPT->a[i]), pGstPT->a[i].u & X86_PTE_PAE_PG_MASK));
1f8ba3bc3e0f62b02e3dc7440cdd6519e8c64e30vboxsync pgmPoolTracDerefGCPhysHint(pPool, pPage, PGMSHWPTEPAE_GET_HCPHYS(pShwPT->a[i]), pGstPT->a[i].u & fPgMask, 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)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync RTGCPHYS const GCPhysA20Mask = pPage->fA20Enabled ? UINT64_MAX : ~RT_BIT_64(20);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync RTGCPHYS GCPhys = pPage->GCPhys + PAGE_SIZE * pPage->iFirstPresent;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pShwPT->a); i++, GCPhys += PAGE_SIZE)
eab582ddaaa130fc769ad00b09b81b3966817d3fvboxsync Log4(("pgmPoolTrackDerefPT32Bit4MB: i=%d pte=%RX32 GCPhys=%RGp\n",
1f8ba3bc3e0f62b02e3dc7440cdd6519e8c64e30vboxsync pgmPoolTracDerefGCPhys(pPool, pPage, pShwPT->a[i].u & X86_PTE_PG_MASK, GCPhys & GCPhysA20Mask, i);
eab582ddaaa130fc769ad00b09b81b3966817d3fvboxsync * Clear references to guest physical memory in a PAE / 2/4MB page table.
eab582ddaaa130fc769ad00b09b81b3966817d3fvboxsync * @param pPool The pool.
eab582ddaaa130fc769ad00b09b81b3966817d3fvboxsync * @param pPage The page.
eab582ddaaa130fc769ad00b09b81b3966817d3fvboxsync * @param pShwPT The shadow page table (mapping of the page).
eab582ddaaa130fc769ad00b09b81b3966817d3fvboxsyncDECLINLINE(void) pgmPoolTrackDerefPTPaeBig(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PPGMSHWPTPAE pShwPT)
eab582ddaaa130fc769ad00b09b81b3966817d3fvboxsync RTGCPHYS const GCPhysA20Mask = pPage->fA20Enabled ? UINT64_MAX : ~RT_BIT_64(20);
eab582ddaaa130fc769ad00b09b81b3966817d3fvboxsync RTGCPHYS GCPhys = pPage->GCPhys + PAGE_SIZE * pPage->iFirstPresent;
eab582ddaaa130fc769ad00b09b81b3966817d3fvboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pShwPT->a); i++, GCPhys += PAGE_SIZE)
eab582ddaaa130fc769ad00b09b81b3966817d3fvboxsync Assert( (PGMSHWPTEPAE_GET_U(pShwPT->a[i]) & UINT64_C(0x7ff0000000000400)) == 0
eab582ddaaa130fc769ad00b09b81b3966817d3fvboxsync || (PGMSHWPTEPAE_GET_U(pShwPT->a[i]) & UINT64_C(0x7ff0000000000400)) == UINT64_C(0x7ff0000000000000));
1f8ba3bc3e0f62b02e3dc7440cdd6519e8c64e30vboxsync Log4(("pgmPoolTrackDerefPTPaeBig: i=%d pte=%RX64 hint=%RGp\n",
1f8ba3bc3e0f62b02e3dc7440cdd6519e8c64e30vboxsync i, PGMSHWPTEPAE_GET_HCPHYS(pShwPT->a[i]), GCPhys));
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync pgmPoolTracDerefGCPhys(pPool, pPage, PGMSHWPTEPAE_GET_HCPHYS(pShwPT->a[i]), GCPhys & GCPhysA20Mask, i);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Clear references to shadowed pages in an EPT page table.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
9f1e0743f565b1975bb4efd7311b30cfa0d3e384vboxsync * @param pPage The page.
9f1e0743f565b1975bb4efd7311b30cfa0d3e384vboxsync * @param pShwPML4 The shadow page directory pointer table (mapping of the page).
9f1e0743f565b1975bb4efd7311b30cfa0d3e384vboxsyncDECLINLINE(void) pgmPoolTrackDerefPTEPT(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PEPTPT pShwPT)
9f1e0743f565b1975bb4efd7311b30cfa0d3e384vboxsync RTGCPHYS const GCPhysA20Mask = pPage->fA20Enabled ? UINT64_MAX : ~RT_BIT_64(20);
9f1e0743f565b1975bb4efd7311b30cfa0d3e384vboxsync RTGCPHYS GCPhys = pPage->GCPhys + PAGE_SIZE * pPage->iFirstPresent;
9f1e0743f565b1975bb4efd7311b30cfa0d3e384vboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pShwPT->a); i++, GCPhys += PAGE_SIZE)
9f1e0743f565b1975bb4efd7311b30cfa0d3e384vboxsync Assert((pShwPT->a[i].u & UINT64_C(0xfff0000000000f80)) == 0);
1f8ba3bc3e0f62b02e3dc7440cdd6519e8c64e30vboxsync Log4(("pgmPoolTrackDerefPTEPT: i=%d pte=%RX64 GCPhys=%RX64\n",
9f1e0743f565b1975bb4efd7311b30cfa0d3e384vboxsync i, pShwPT->a[i].u & EPT_PTE_PG_MASK, pPage->GCPhys));
9f1e0743f565b1975bb4efd7311b30cfa0d3e384vboxsync pgmPoolTracDerefGCPhys(pPool, pPage, pShwPT->a[i].u & EPT_PTE_PG_MASK, GCPhys & GCPhysA20Mask, i);
9f1e0743f565b1975bb4efd7311b30cfa0d3e384vboxsync * Clear references to shadowed pages in a 32 bits page directory.
9f1e0743f565b1975bb4efd7311b30cfa0d3e384vboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The page.
10e1bc06b2908a0af56d92ffdbadd25b36a5ef61vboxsync * @param pShwPD The shadow page directory (mapping of the page).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncDECLINLINE(void) pgmPoolTrackDerefPD(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PD pShwPD)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned i = 0; i < RT_ELEMENTS(pShwPD->a); i++)
1f8ba3bc3e0f62b02e3dc7440cdd6519e8c64e30vboxsync PPGMPOOLPAGE pSubPage = (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, pShwPD->a[i].u & X86_PDE_PG_MASK);
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync pgmPoolTrackFreeUser(pPool, pSubPage, pPage->idx, i);
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync AssertFatalMsgFailed(("%x\n", pShwPD->a[i].u & X86_PDE_PG_MASK));
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync * Clear references to shadowed pages in a PAE (legacy or 64 bits) page directory.
34e34d3656484dde89a9c7b57fcbf7048d2fdb13vboxsync * @param pPool The pool.
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync * @param pPage The page.
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync * @param pShwPD The shadow page directory (mapping of the page).
34e34d3656484dde89a9c7b57fcbf7048d2fdb13vboxsyncDECLINLINE(void) pgmPoolTrackDerefPDPae(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PDPAE pShwPD)
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pShwPD->a); i++)
ef4275be1971a6d17d45121d075a4f41659fa6c9vboxsync Log4(("pgmPoolTrackDerefPDPae: i=%d pde=%RX64 GCPhys=%RX64\n",
ef4275be1971a6d17d45121d075a4f41659fa6c9vboxsync i, pShwPD->a[i].u & X86_PDE2M_PAE_PG_MASK, pPage->GCPhys));
ef4275be1971a6d17d45121d075a4f41659fa6c9vboxsync pgmPoolTracDerefGCPhys(pPool, pPage, pShwPD->a[i].u & X86_PDE2M_PAE_PG_MASK,
ef4275be1971a6d17d45121d075a4f41659fa6c9vboxsync pPage->GCPhys + i * 2 * _1M /* pPage->GCPhys = base address of the memory described by the PD */,
ef4275be1971a6d17d45121d075a4f41659fa6c9vboxsync Assert((pShwPD->a[i].u & (X86_PDE_PAE_MBZ_MASK_NX | UINT64_C(0x7ff0000000000200))) == 0);
ef4275be1971a6d17d45121d075a4f41659fa6c9vboxsync PPGMPOOLPAGE pSubPage = (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, pShwPD->a[i].u & X86_PDE_PAE_PG_MASK);
ef4275be1971a6d17d45121d075a4f41659fa6c9vboxsync pgmPoolTrackFreeUser(pPool, pSubPage, pPage->idx, i);
ef4275be1971a6d17d45121d075a4f41659fa6c9vboxsync AssertFatalMsgFailed(("%RX64\n", pShwPD->a[i].u & X86_PDE_PAE_PG_MASK));
ef4275be1971a6d17d45121d075a4f41659fa6c9vboxsync /** @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++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Assert((pShwPDPT->a[i].u & (X86_PDPE_PAE_MBZ_MASK | UINT64_C(0x7ff0000000000200))) == 0);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPGMPOOLPAGE pSubPage = (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, pShwPDPT->a[i].u & X86_PDPE_PG_MASK);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolTrackFreeUser(pPool, pSubPage, pPage->idx, i);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertFatalMsgFailed(("%RX64\n", pShwPDPT->a[i].u & X86_PDPE_PG_MASK));
40f47bc231ff6c86a7ddc3295eed7010e889e78avboxsync * Clear references to shadowed pages in a 64-bit page directory pointer table.
40f47bc231ff6c86a7ddc3295eed7010e889e78avboxsync * @param pPool The pool.
40f47bc231ff6c86a7ddc3295eed7010e889e78avboxsync * @param pPage The page.
40f47bc231ff6c86a7ddc3295eed7010e889e78avboxsync * @param pShwPDPT The shadow page directory pointer table (mapping of the page).
40f47bc231ff6c86a7ddc3295eed7010e889e78avboxsyncDECLINLINE(void) pgmPoolTrackDerefPDPT64Bit(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PDPT pShwPDPT)
e4ea543752422f1139923e3e506c625b0a1827c5vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pShwPDPT->a); i++)
1f8ba3bc3e0f62b02e3dc7440cdd6519e8c64e30vboxsync Assert((pShwPDPT->a[i].u & (X86_PDPE_LM_MBZ_MASK_NX | UINT64_C(0x7ff0000000000200))) == 0);
9f9a20823b87e89c1b5cb45eb9b5699b29bfefebvboxsync PPGMPOOLPAGE pSubPage = (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, pShwPDPT->a[i].u & X86_PDPE_PG_MASK);
40f47bc231ff6c86a7ddc3295eed7010e889e78avboxsync pgmPoolTrackFreeUser(pPool, pSubPage, pPage->idx, i);
9673b0b804d0b0f801f377c6371600e92071241fvboxsync AssertFatalMsgFailed(("%RX64\n", pShwPDPT->a[i].u & X86_PDPE_PG_MASK));
40f47bc231ff6c86a7ddc3295eed7010e889e78avboxsync /** @todo 64-bit guests: have to ensure that we're not exhausting the dynamic mappings! */
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync * Clear references to shadowed pages in a 64-bit level 4 page table.
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync * @param pPool The pool.
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync * @param pPage The page.
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync * @param pShwPML4 The shadow page directory pointer table (mapping of the page).
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsyncDECLINLINE(void) pgmPoolTrackDerefPML464Bit(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PML4 pShwPML4)
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync for (unsigned i = 0; i < RT_ELEMENTS(pShwPML4->a); i++)
1f8ba3bc3e0f62b02e3dc7440cdd6519e8c64e30vboxsync Assert((pShwPML4->a[i].u & (X86_PML4E_MBZ_MASK_NX | UINT64_C(0x7ff0000000000200))) == 0);
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync PPGMPOOLPAGE pSubPage = (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, pShwPML4->a[i].u & X86_PDPE_PG_MASK);
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync pgmPoolTrackFreeUser(pPool, pSubPage, pPage->idx, i);
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync AssertFatalMsgFailed(("%RX64\n", pShwPML4->a[i].u & X86_PML4E_PG_MASK));
9de4f3c0579ee02fe0b2c0b0daed3e49a951551fvboxsync /** @todo 64-bit guests: have to ensure that we're not exhausting the dynamic mappings! */
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync * Clear references to shadowed pages in an EPT page directory.
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync * @param pPool The pool.
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync * @param pPage The page.
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync * @param pShwPD The shadow page directory (mapping of the page).
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsyncDECLINLINE(void) pgmPoolTrackDerefPDEPT(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PEPTPD pShwPD)
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync for (unsigned i = 0; i < RT_ELEMENTS(pShwPD->a); i++)
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync Assert((pShwPD->a[i].u & UINT64_C(0xfff0000000000f80)) == 0);
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,
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync pPage->GCPhys + i * 2 * _1M /* pPage->GCPhys = base address of the memory described by the PD */,
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! */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Clear references to shadowed pages in an EPT 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) pgmPoolTrackDerefPDPTEPT(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PEPTPDPT pShwPDPT)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned i = 0; i < RT_ELEMENTS(pShwPDPT->a); i++)
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync Assert((pShwPDPT->a[i].u & UINT64_C(0xfff0000000000f80)) == 0);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPGMPOOLPAGE pSubPage = (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, pShwPDPT->a[i].u & EPT_PDPTE_PG_MASK);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolTrackFreeUser(pPool, pSubPage, pPage->idx, i);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertFatalMsgFailed(("%RX64\n", pShwPDPT->a[i].u & EPT_PDPTE_PG_MASK));
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync /** @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.
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync * @param pPool The pool.
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync * @param pPage The page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic void pgmPoolTrackDeref(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Map the shadow page and take action according to the page kind.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_PROFILE_START(&pPool->StatTrackDerefGCPhys, g);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync int rc = PGM_GCPHYS_2_PTR(pVM, pPage->GCPhys, &pvGst); AssertReleaseRC(rc);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolTrackDerefPT32Bit32Bit(pPool, pPage, (PX86PT)pvShw, (PCX86PT)pvGst);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_PROFILE_STOP(&pPool->StatTrackDerefGCPhys, g);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_PROFILE_START(&pPool->StatTrackDerefGCPhys, g);
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync int rc = PGM_GCPHYS_2_PTR_EX(pVM, pPage->GCPhys, &pvGst); AssertReleaseRC(rc);
d86aa8a95e908fa0d5e88ed662ea0a919f17756fvboxsync pgmPoolTrackDerefPTPae32Bit(pPool, pPage, (PPGMSHWPTPAE)pvShw, (PCX86PT)pvGst);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_PROFILE_STOP(&pPool->StatTrackDerefGCPhys, g);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_PROFILE_START(&pPool->StatTrackDerefGCPhys, g);
00599f6d39cc25ca39845c2433cd75de7b9f6971vboxsync int rc = PGM_GCPHYS_2_PTR(pVM, pPage->GCPhys, &pvGst); AssertReleaseRC(rc);
00599f6d39cc25ca39845c2433cd75de7b9f6971vboxsync pgmPoolTrackDerefPTPaePae(pPool, pPage, (PPGMSHWPTPAE)pvShw, (PCX86PTPAE)pvGst);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_PROFILE_STOP(&pPool->StatTrackDerefGCPhys, g);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync case PGMPOOLKIND_32BIT_PT_FOR_PHYS: /* treat it like a 4 MB page */
14f2d81f7090ba5b7261e7c67a7f65c796d037f1vboxsync STAM_PROFILE_START(&pPool->StatTrackDerefGCPhys, g);
9f1e0743f565b1975bb4efd7311b30cfa0d3e384vboxsync pgmPoolTrackDerefPT32Bit4MB(pPool, pPage, (PX86PT)pvShw);
9f1e0743f565b1975bb4efd7311b30cfa0d3e384vboxsync STAM_PROFILE_STOP(&pPool->StatTrackDerefGCPhys, g);
9f1e0743f565b1975bb4efd7311b30cfa0d3e384vboxsync case PGMPOOLKIND_PAE_PT_FOR_PHYS: /* treat it like a 2 MB page */
ef4275be1971a6d17d45121d075a4f41659fa6c9vboxsync STAM_PROFILE_START(&pPool->StatTrackDerefGCPhys, g);
9c425bdea5f0991df62922b1584b805a86f2f898vboxsync pgmPoolTrackDerefPTPaeBig(pPool, pPage, (PPGMSHWPTPAE)pvShw);
8f7bc6ad2b7bbcb4b3b96248cd2478e45f2e3b88vboxsync STAM_PROFILE_STOP(&pPool->StatTrackDerefGCPhys, g);
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync pgmPoolTrackDerefPDPae(pPool, pPage, (PX86PDPAE)pvShw);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolTrackDerefPDPTPae(pPool, pPage, (PX86PDPT)pvShw);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolTrackDerefPDPT64Bit(pPool, pPage, (PX86PDPT)pvShw);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolTrackDerefPML464Bit(pPool, pPage, (PX86PML4)pvShw);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolTrackDerefPTEPT(pPool, pPage, (PEPTPT)pvShw);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolTrackDerefPDEPT(pPool, pPage, (PEPTPD)pvShw);
b15ec73af09a8129b8a9ebfcc185ea11c3dd7c63vboxsync pgmPoolTrackDerefPDPTEPT(pPool, pPage, (PEPTPDPT)pvShw);
41b8e304f190c3d901bcfee5e73c11bc2c42ce13vboxsync AssertFatalMsgFailed(("enmKind=%d\n", pPage->enmKind));
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync /* paranoia, clear the shadow page. Remove this laser (i.e. let Alloc and ClearAll do it). */
1b7f3a92e42fb9cabf96cf31c20481da466edf76vboxsync * Flushes a pool page.
41b8e304f190c3d901bcfee5e73c11bc2c42ce13vboxsync * This moves the page to the free list after removing all user references to it.
1b7f3a92e42fb9cabf96cf31c20481da466edf76vboxsync * @returns VBox status code.
1b7f3a92e42fb9cabf96cf31c20481da466edf76vboxsync * @retval VINF_SUCCESS on success.
1b7f3a92e42fb9cabf96cf31c20481da466edf76vboxsync * @param pPool The pool.
1999ae03c34840fa4d712fd2e020120b2cb7182avboxsync * @param HCPhys The HC physical address of the shadow page.
7e2fce486e7e2e45eb61d78ee206ba42ed89e016vboxsync * @param fFlush Flush the TLBS when required (should only be false in very specific use cases!!)
0aeb5f500280603a51364071670efeb2617f771cvboxsyncint pgmPoolFlushPage(PPGMPOOL pPool, PPGMPOOLPAGE pPage, bool fFlush)
3dafd1633a0838d51a02c30dc1451b822a3892bdvboxsync LogFlow(("pgmPoolFlushPage: pPage=%p:{.Key=%RHp, .idx=%d, .enmKind=%s, .GCPhys=%RGp}\n",
3dafd1633a0838d51a02c30dc1451b822a3892bdvboxsync pPage, pPage->Core.Key, pPage->idx, pgmPoolPoolKindToStr(pPage->enmKind), pPage->GCPhys));
41b8e304f190c3d901bcfee5e73c11bc2c42ce13vboxsync * Quietly reject any attempts at flushing any of the special root pages.
50e0e1bb8996934b3f38c117a456f825052bfb0cvboxsync 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
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync AssertMsg( pPage->enmKind == PGMPOOLKIND_64BIT_PML4
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync || pPage->enmKind == PGMPOOLKIND_PAE_PDPT_FOR_32BIT
b15ec73af09a8129b8a9ebfcc185ea11c3dd7c63vboxsync || pPage->enmKind == PGMPOOLKIND_PAE_PD0_FOR_32BIT_PD
b15ec73af09a8129b8a9ebfcc185ea11c3dd7c63vboxsync || pPage->enmKind == PGMPOOLKIND_PAE_PD1_FOR_32BIT_PD
b15ec73af09a8129b8a9ebfcc185ea11c3dd7c63vboxsync || pPage->enmKind == PGMPOOLKIND_PAE_PD2_FOR_32BIT_PD
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync || pPage->enmKind == PGMPOOLKIND_PAE_PD3_FOR_32BIT_PD
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync ("Can't free the shadow CR3! (%RHp vs %RHp kind=%d\n", PGMGetHyperCR3(VMMGetCpu(pVM)), pPage->Core.Key, pPage->enmKind));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log(("pgmPoolFlushPage: current active shadow CR3, rejected. enmKind=%s idx=%d\n", pgmPoolPoolKindToStr(pPage->enmKind), pPage->idx));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync#if defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0) || defined(IN_RC)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Start a subset so we won't run out of mapping space. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync uint32_t iPrevSubset = PGMRZDynMapPushAutoSubset(pVCpu);
9984bae4ef25be8afd95d184308adcfef6e2ec0dvboxsync * Mark the page as being in need of an ASMMemZeroPage().
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolFlushDirtyPage(pVM, pPool, pPage->idxDirtyEntry, false /* do not remove */);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* If there are any users of this table, then we *must* issue a tlb flush on all VCPUs. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Clear the page.
b15ec73af09a8129b8a9ebfcc185ea11c3dd7c63vboxsync * Flush it from the cache.
e5ce4bb707bf5c17c2bfa42306210e915ca29fa2vboxsync#if defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0) || defined(IN_RC)
b15ec73af09a8129b8a9ebfcc185ea11c3dd7c63vboxsync /* Heavy stuff done. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Deregistering the monitoring.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * 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.
5e0e35e65847aae0955835d5c4b4e76143e580c1vboxsync * @param iUser The shadow page pool index of the user table.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param iUserTable The index into the user table (shadowed).
5e0e35e65847aae0955835d5c4b4e76143e580c1vboxsyncvoid pgmPoolFreeByPage(PPGMPOOL pPool, PPGMPOOLPAGE pPage, uint16_t iUser, uint32_t iUserTable)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolFreeByPage: pPage=%p:{.Key=%RHp, .idx=%d, enmKind=%s} iUser=%d iUserTable=%#x\n",
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPage, pPage->Core.Key, pPage->idx, pgmPoolPoolKindToStr(pPage->enmKind), iUser, iUserTable));
5e0e35e65847aae0955835d5c4b4e76143e580c1vboxsync pgmPoolTrackFreeUser(pPool, pPage, iUser, iUserTable);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Makes one or more free page free.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code.
ebe097ee2ebebb775a1e816af91b4ea67c52b0bdvboxsync * @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=%d\n", iUser));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * If the pool isn't full grown yet, expand it.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* 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)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync int rc = VMMRZCallRing3NoCpu(pVM, VMMCALLRING3_PGM_POOL_GROW, 0);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Free one cached page.
d6b5539478863f176bfffefc1ada2b9489cfa092vboxsync * Allocates a page from the pool.
50cd04a47a3d04b52dbafe28921bff3d4c387841vboxsync * This page may actually be a cached page and not in need of any processing
50cd04a47a3d04b52dbafe28921bff3d4c387841vboxsync * on the callers part.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code.
74991d7531692858fd22acf371a7ee941567977cvboxsync * @retval VINF_SUCCESS if a NEW page was allocated.
1a25adaca81841abf5e6cdfed02eaff64941357dvboxsync * @retval VINF_PGM_CACHED_PAGE if a CACHED page was returned.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VERR_PGM_POOL_FLUSHED if the pool was flushed.
cb06e3f411d6ced5515682cddfbfa8ec463c6ff3vboxsync * @param pVM Pointer to the VM.
50cd04a47a3d04b52dbafe28921bff3d4c387841vboxsync * @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
1e3cd9c9c95ff352da1331a1789b05fd012c880dvboxsync * shadow PT is covering.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param enmKind The kind of mapping.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param enmAccess Access type for the mapping (only relevant for big pages)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param fA20Enabled Whether the A20 gate is enabled or not.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param iUser The shadow page pool index of the user table.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param iUserTable The index into the user table (shadowed).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param fLockPage Lock the page
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param ppPage Where to store the pointer to the page. NULL is stored here on failure.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncint pgmPoolAlloc(PVM pVM, RTGCPHYS GCPhys, PGMPOOLKIND enmKind, PGMPOOLACCESS enmAccess, bool fA20Enabled,
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync uint16_t iUser, uint32_t iUserTable, bool fLockPage, PPPGMPOOLPAGE ppPage)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolAlloc: GCPhys=%RGp enmKind=%s iUser=%d iUserTable=%#x\n", GCPhys, pgmPoolPoolKindToStr(enmKind), iUser, iUserTable));
1e3cd9c9c95ff352da1331a1789b05fd012c880dvboxsync /** @todo CSAM/PGMPrefetchPage messes up here during CSAMR3CheckGates
750d4d0506a38b2e80c997075d40aad474e675fbvboxsync * (TRPMR3SyncIDT) because of FF priority. Try fix that?
750d4d0506a38b2e80c997075d40aad474e675fbvboxsync * Assert(!(pVM->pgm.s.fGlobalSyncFlags & PGM_SYNC_CLEAR_PGM_POOL)); */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync int rc2 = pgmPoolCacheAlloc(pPool, GCPhys, enmKind, enmAccess, fA20Enabled, iUser, iUserTable, ppPage);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolAlloc: cached returns %Rrc *ppPage=%p:{.Key=%RHp, .idx=%d}\n", rc2, *ppPage, (*ppPage)->Core.Key, (*ppPage)->idx));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Allocate a new one.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = pgmPoolMakeMoreFreePages(pPool, enmKind, iUser);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertReleaseReturn(iNew != NIL_PGMPOOL_IDX, VERR_PGM_POOL_IPE);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* unlink the free head */
74991d7531692858fd22acf371a7ee941567977cvboxsync * Initialize it.
74991d7531692858fd22acf371a7ee941567977cvboxsync pPool->cUsedPages++; /* physical handler registration / pgmPoolTrackFlushGCPhysPTsSlow requirement. */
750d4d0506a38b2e80c997075d40aad474e675fbvboxsync pPage->fSeenNonGlobal = false; /* Set this to 'true' to disable this feature. */
cb06e3f411d6ced5515682cddfbfa8ec463c6ff3vboxsync * Insert into the tracking and cache. If this fails, free the page.
50cd04a47a3d04b52dbafe28921bff3d4c387841vboxsync int rc3 = pgmPoolTrackInsert(pPool, pPage, GCPhys, iUser, iUserTable);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log(("pgmPoolAlloc: returns %Rrc (Insert)\n", rc3));
afed5ab737f4aacfae3fe73776f40e989190a7cavboxsync * Commit the allocation, clear the page and return.
f7eda1aa747cd9b2119362a9f06fe32ece025024vboxsync LogFlow(("pgmPoolAlloc: returns %Rrc *ppPage=%p:{.Key=%RHp, .idx=%d, .fCached=%RTbool, .fMonitored=%RTbool}\n",
a4eb337e9a5a6a72bcfe50134dc42732f5ee65c0vboxsync rc, pPage, pPage->Core.Key, pPage->idx, pPage->fCached, pPage->fMonitored));
a4eb337e9a5a6a72bcfe50134dc42732f5ee65c0vboxsync * Frees a usage of a pool page.
1a3ad7148138899b8aa53cc2efeedd5ba48dc6c8vboxsync * @param pVM Pointer to the VM.
1a3ad7148138899b8aa53cc2efeedd5ba48dc6c8vboxsync * @param HCPhys The HC physical address of the shadow page.
1a3ad7148138899b8aa53cc2efeedd5ba48dc6c8vboxsync * @param iUser The shadow page pool index of the user table.
1a3ad7148138899b8aa53cc2efeedd5ba48dc6c8vboxsync * @param iUserTable The index into the user table (shadowed).
1a3ad7148138899b8aa53cc2efeedd5ba48dc6c8vboxsyncvoid pgmPoolFree(PVM pVM, RTHCPHYS HCPhys, uint16_t iUser, uint32_t iUserTable)
1a3ad7148138899b8aa53cc2efeedd5ba48dc6c8vboxsync LogFlow(("pgmPoolFree: HCPhys=%RHp iUser=%d iUserTable=%#x\n", HCPhys, iUser, iUserTable));
1a3ad7148138899b8aa53cc2efeedd5ba48dc6c8vboxsync pgmPoolFreeByPage(pPool, pgmPoolGetPage(pPool, HCPhys), iUser, iUserTable);
1a3ad7148138899b8aa53cc2efeedd5ba48dc6c8vboxsync * Internal worker for finding a 'in-use' shadow page give by it's physical address.
6576e3b6a2702e6fbbe0ca8dd645f8ef3270a935vboxsync * @returns Pointer to the shadow page structure.
13b9db9ae2c12b6c4e00eda5c79772d57a0d29e1vboxsync * @param pPool The pool.
13b9db9ae2c12b6c4e00eda5c79772d57a0d29e1vboxsync * @param HCPhys The HC physical address of the shadow page.
13b9db9ae2c12b6c4e00eda5c79772d57a0d29e1vboxsyncPPGMPOOLPAGE pgmPoolGetPage(PPGMPOOL pPool, RTHCPHYS HCPhys)
13b9db9ae2c12b6c4e00eda5c79772d57a0d29e1vboxsync * Look up the page.
8729218d00f8b764686a331b45a1b6de0d0e293evboxsync PPGMPOOLPAGE pPage = (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, HCPhys & X86_PTE_PAE_PG_MASK);
13b9db9ae2c12b6c4e00eda5c79772d57a0d29e1vboxsync AssertFatalMsg(pPage && pPage->enmKind != PGMPOOLKIND_FREE, ("HCPhys=%RHp pPage=%p idx=%d\n", HCPhys, pPage, (pPage) ? pPage->idx : 0));
13b9db9ae2c12b6c4e00eda5c79772d57a0d29e1vboxsync * Internal worker for finding a page for debugging purposes, no assertions.
13b9db9ae2c12b6c4e00eda5c79772d57a0d29e1vboxsync * @returns Pointer to the shadow page structure. NULL on if not found.
13b9db9ae2c12b6c4e00eda5c79772d57a0d29e1vboxsync * @param pPool The pool.
13b9db9ae2c12b6c4e00eda5c79772d57a0d29e1vboxsync * @param HCPhys The HC physical address of the shadow page.
13b9db9ae2c12b6c4e00eda5c79772d57a0d29e1vboxsyncPPGMPOOLPAGE pgmPoolQueryPageForDbg(PPGMPOOL pPool, RTHCPHYS HCPhys)
13b9db9ae2c12b6c4e00eda5c79772d57a0d29e1vboxsync return (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, HCPhys & X86_PTE_PAE_PG_MASK);
13b9db9ae2c12b6c4e00eda5c79772d57a0d29e1vboxsync#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) */
13b9db9ae2c12b6c4e00eda5c79772d57a0d29e1vboxsync * Flush the specified page if present
13b9db9ae2c12b6c4e00eda5c79772d57a0d29e1vboxsync * @param pVM Pointer to the VM.
13b9db9ae2c12b6c4e00eda5c79772d57a0d29e1vboxsync * @param GCPhys Guest physical address of the page to flush
13b9db9ae2c12b6c4e00eda5c79772d57a0d29e1vboxsyncvoid pgmPoolFlushPageByGCPhys(PVM pVM, RTGCPHYS GCPhys)
18928869a28716fc7ccd4255ba7d282cda027affvboxsync * Look up the GCPhys in the hash.
13b9db9ae2c12b6c4e00eda5c79772d57a0d29e1vboxsync Log(("PGMPoolFlushPage: found pgm pool pages for %RGp\n", GCPhys));
c995102a21cae5b5ffeedadbfaddcc105809e196vboxsync /* ignore, no monitoring. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertFatalMsgFailed(("enmKind=%d idx=%d\n", pPage->enmKind, pPage->idx));
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync } while (i != NIL_PGMPOOL_IDX);
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync#endif /* IN_RING3 */
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync * Reset CPU on hot plugging.
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync * @param pVM Pointer to the VM.
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync * @param pVCpu The virtual CPU.
53317612c337db70bbfc72967860b3a00021e152vboxsyncvoid pgmR3PoolResetUnpluggedCpu(PVM pVM, PVMCPU pVCpu)
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync * Flushes the entire cache.
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync * It will assert a global CR3 flush (FF) and assumes the caller is aware of
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync * this and execute this CR3 flush.
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync * @param pPool The pool.
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync * If there are no pages in the pool, there is nothing to do.
74991d7531692858fd22acf371a7ee941567977cvboxsync * Exit the shadow mode since we're going to clear everything,
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * including the root page.
74991d7531692858fd22acf371a7ee941567977cvboxsync pgmR3ExitShadowModeBeforePoolFlush(&pVM->aCpus[i]);
74991d7531692858fd22acf371a7ee941567977cvboxsync * Nuke the free list and reinsert all pages into it.
74991d7531692858fd22acf371a7ee941567977cvboxsync 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. */
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync pPool->aPages[pPool->cCurPages - 1].iNext = NIL_PGMPOOL_IDX;
5007ad5d2bce84d88ee339a94e0aa7b91c699194vboxsync * Zap and reinitialize the user records.
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync for (unsigned i = 0; i < cMaxUsers; i++)
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync paUsers[cMaxUsers - 1].iNext = NIL_PGMPOOL_USER_INDEX;
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync * Clear all the GCPhys links and rebuild the phys ext free list.
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync for (PPGMRAMRANGE pRam = pVM->pgm.s.CTX_SUFF(pRamRangesX);
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync while (iPage-- > 0)
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync PGM_PAGE_SET_TRACKING(pVM, &pRam->aPages[iPage], 0);
ef481e64bafc49f1232767ce12c3fa69a5d5fe50vboxsync PPGMPOOLPHYSEXT paPhysExts = pPool->CTX_SUFF(paPhysExts);
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync 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->aDirtyPages); i++)
320349a3b3aef9a6f58c58b602ae7c179170b4f4vboxsync * Reinsert active pages into the hash and ensure monitoring chains are correct.
b15ec73af09a8129b8a9ebfcc185ea11c3dd7c63vboxsync for (unsigned i = PGMPOOL_IDX_FIRST_SPECIAL; i < PGMPOOL_IDX_FIRST; i++)
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync /* ASSUMES that we're not sharing with any of the other special pages (safe for now). */
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync int rc = PGMHandlerPhysicalChangeCallbacks(pVM, pPage->GCPhys & ~(RTGCPHYS)PAGE_OFFSET_MASK,
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync pPool->pfnAccessHandlerR3, MMHyperCCToR3(pVM, pPage),
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync pPool->pfnAccessHandlerR0, MMHyperCCToR0(pVM, pPage),
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync pPool->pfnAccessHandlerRC, MMHyperCCToRC(pVM, pPage),
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync Assert(pPage->iUserHead == NIL_PGMPOOL_USER_INDEX); /* for now */
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync * Re-enter the shadowing mode and assert Sync CR3 FF.
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync#endif /* IN_RING3 */
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync * Stringifies a PGMPOOLKIND value.
0174432b2b1a760b89840ba696f7ba51def65dddvboxsyncstatic const char *pgmPoolPoolKindToStr(uint8_t enmKind)
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync return "PGMPOOLKIND_INVALID";
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync return "PGMPOOLKIND_FREE";
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync return "PGMPOOLKIND_32BIT_PT_FOR_PHYS";
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync return "PGMPOOLKIND_32BIT_PT_FOR_32BIT_PT";
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync return "PGMPOOLKIND_32BIT_PT_FOR_32BIT_4MB";
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync return "PGMPOOLKIND_PAE_PT_FOR_PHYS";
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync return "PGMPOOLKIND_PAE_PT_FOR_32BIT_PT";
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync return "PGMPOOLKIND_PAE_PT_FOR_32BIT_4MB";
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync return "PGMPOOLKIND_PAE_PT_FOR_PAE_PT";
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync return "PGMPOOLKIND_PAE_PT_FOR_PAE_2MB";
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync return "PGMPOOLKIND_32BIT_PD";
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync return "PGMPOOLKIND_32BIT_PD_PHYS";
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync return "PGMPOOLKIND_PAE_PD0_FOR_32BIT_PD";
case PGMPOOLKIND_PAE_PD_PHYS:
case PGMPOOLKIND_PAE_PDPT:
case PGMPOOLKIND_64BIT_PML4:
case PGMPOOLKIND_ROOT_NESTED: