PGMAllPool.cpp revision 9ddf48fac91d47ba87a5255bbd0993297bb16084
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * PGM Shadow Page Pool.
3f1e0eea71cabeb90529e546f16eb7aee513fde9vboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * available from http://www.virtualbox.org. This file is free software;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * you can redistribute it and/or modify it under the terms of the GNU
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * General Public License (GPL) as published by the Free Software
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * additional information or have any questions.
43747b1f0bc8302a238fb35e55857a5e9aa1933dvboxsync/*******************************************************************************
43747b1f0bc8302a238fb35e55857a5e9aa1933dvboxsync* Header Files *
43747b1f0bc8302a238fb35e55857a5e9aa1933dvboxsync*******************************************************************************/
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync/*******************************************************************************
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync* Internal Functions *
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync*******************************************************************************/
223cf005b18af2c21352a70693ebaf0582f68ebcvboxsyncDECLINLINE(unsigned) pgmPoolTrackGetShadowEntrySize(PGMPOOLKIND enmKind);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncDECLINLINE(unsigned) pgmPoolTrackGetGuestEntrySize(PGMPOOLKIND enmKind);
afed5ab737f4aacfae3fe73776f40e989190a7cavboxsyncstatic void pgmPoolTrackDeref(PPGMPOOL pPool, PPGMPOOLPAGE pPage);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic void pgmPoolTracDerefGCPhysHint(PPGMPOOL pPool, PPGMPOOLPAGE pPage, RTHCPHYS HCPhys, RTGCPHYS GCPhysHint);
2daaccf68be3773aee600c5c3e48bcf5401418a6vboxsyncstatic int pgmPoolTrackAddUser(PPGMPOOL pPool, PPGMPOOLPAGE pPage, uint16_t iUser, uint32_t iUserTable);
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsyncstatic void pgmPoolMonitorModifiedRemove(PPGMPOOL pPool, PPGMPOOLPAGE pPage);
7666082b743c5e146a8cee6cc794ff4bc3fd0ffdvboxsyncDECLEXPORT(int) pgmPoolAccessHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPHYS GCPhysFault, void *pvUser);
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 * Maps a pool page into the current context.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns Pointer to the mapping.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM The VM handle.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The page to map.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* general pages. */
b1c3cdef473df2fbc621d5da81acc82dbfb8a11avboxsync Assert(pPage->idx < pVM->pgm.s.pPoolGC->cCurPages);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync int rc = PGMGCDynMapHCPage(pVM, pPage->Core.Key, &pv);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* special pages. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertReleaseMsgFailed(("Invalid index %d\n", pPage->idx));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync#endif /* IN_GC */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Determin the size of a write instruction.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns number of bytes written.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pDis The disassembler state.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic unsigned pgmPoolDisasWriteSize(PDISCPUSTATE pDis)
223cf005b18af2c21352a70693ebaf0582f68ebcvboxsync * This is very crude and possibly wrong for some opcodes,
b74ca013e5f201a2dd371e6c438433ceac12af30vboxsync * but since it's not really supposed to be called we can
b74ca013e5f201a2dd371e6c438433ceac12af30vboxsync * probably live with that.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Flushes a chain of pages sharing the same access monitor.
b74ca013e5f201a2dd371e6c438433ceac12af30vboxsync * @returns VBox status code suitable for scheduling.
b74ca013e5f201a2dd371e6c438433ceac12af30vboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage A page in the chain.
b74ca013e5f201a2dd371e6c438433ceac12af30vboxsyncint pgmPoolMonitorChainFlush(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolMonitorChainFlush: Flush page %VGp type=%d\n", pPage->GCPhys, pPage->enmKind));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Find the list head.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Iterate the list flushing each shadow page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if (rc2 == VERR_PGM_POOL_CLEARED && rc == VINF_SUCCESS)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Wrapper for getting the current context pointer to the entry being modified.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns Pointer to the current context mapping of the entry.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
b978e5849454446957177fd47ee98609ab0457a6vboxsync * @param pvFault The fault virtual address.
9984bae4ef25be8afd95d184308adcfef6e2ec0dvboxsync * @param GCPhysFault The fault physical address.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param cbEntry The entry size.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncDECLINLINE(const void *) pgmPoolMonitorGCPtr2CCPtr(PPGMPOOL pPool, RTHCPTR pvFault, RTGCPHYS GCPhysFault, const unsigned cbEntry)
57399ab65e2825c324fb9dcb4642d4ae2c232509vboxsyncDECLINLINE(const void *) pgmPoolMonitorGCPtr2CCPtr(PPGMPOOL pPool, RTGCPTR pvFault, RTGCPHYS GCPhysFault, const unsigned cbEntry)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return (const void *)((RTGCUINTPTR)pvFault & ~(RTGCUINTPTR)(cbEntry - 1));
4b8fcf8e4d11536879a1f6e66279ba0c363a7eaevboxsync int rc = pgmRamGCPhys2HCPtr(&pPool->pVMHC->pgm.s, GCPhysFault & ~(RTGCPHYS)(cbEntry - 1), &pvRet);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return (RTHCPTR)((uintptr_t)pvFault & ~(RTHCUINTPTR)(cbEntry - 1));
247b55faa8d054157f2481e68caca36f4dc9542cvboxsync * Process shadow entries before they are changed by the guest.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * For PT entries we will clear them. For PD entries, we'll simply check
b74ca013e5f201a2dd371e6c438433ceac12af30vboxsync * for mapping conflicts and set the SyncCR3 FF if found.
b74ca013e5f201a2dd371e6c438433ceac12af30vboxsync * @param pPool The pool.
b74ca013e5f201a2dd371e6c438433ceac12af30vboxsync * @param pPage The head page.
b40179b44fea65b72b2f226f62af1ed7bd3c48fcvboxsync * @param GCPhysFault The guest physical fault address.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param uAddress In R0 and GC this is the guest context fault address (flat).
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync * In R3 this is the host context 'fault' address.
82e90599291da476b2de7c8db33cfb0f2cbac774vboxsync * @param pCpu The disassembler state for figuring out the write size.
82e90599291da476b2de7c8db33cfb0f2cbac774vboxsync * This need not be specified if the caller knows we won't do cross entry accesses.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncvoid pgmPoolMonitorChainChanging(PPGMPOOL pPool, PPGMPOOLPAGE pPage, RTGCPHYS GCPhysFault, RTHCPTR pvAddress, PDISCPUSTATE pCpu)
533ffcb943c4af2c5fe6385d816d0ba3eda9383bvboxsyncvoid pgmPoolMonitorChainChanging(PPGMPOOL pPool, PPGMPOOLPAGE pPage, RTGCPHYS GCPhysFault, RTGCPTR pvAddress, PDISCPUSTATE pCpu)
00599f6d39cc25ca39845c2433cd75de7b9f6971vboxsync const unsigned off = GCPhysFault & PAGE_OFFSET_MASK;
533ffcb943c4af2c5fe6385d816d0ba3eda9383bvboxsync LogFlow(("pgmPoolMonitorChainChanging: %VGv phys=%VGp kind=%d\n", pvAddress, GCPhysFault, pPage->enmKind));
1843553dbdf4e46417158b4c6348c503adf10740vboxsync uShw.pv = PGMPOOL_PAGE_2_PTR(pPool->CTXSUFF(pVM), pPage);
1843553dbdf4e46417158b4c6348c503adf10740vboxsync PCX86PTE pGstPte = (PCX86PTE)pgmPoolMonitorGCPtr2CCPtr(pPool, pvAddress, GCPhysFault, sizeof(*pGstPte));
22e281e75ed636601178296c6daebda8f1d17c59vboxsync Log4(("pgmPoolMonitorChainChanging 32_32: deref %VHp GCPhys %VGp\n", uShw.pPT->a[iShw].u & X86_PTE_PAE_PG_MASK, pGstPte->u & X86_PTE_PG_MASK));
533ffcb943c4af2c5fe6385d816d0ba3eda9383bvboxsync /* page/2 sized */
13ba5527caaa9b8c4fee29f22e374fa67c4c6f72vboxsync const unsigned iShw = (off / sizeof(X86PTE)) & (X86_PG_PAE_ENTRIES - 1);
e0b9d3c357adf9b7d05f55540e86f22943fc4b23vboxsync PCX86PTE pGstPte = (PCX86PTE)pgmPoolMonitorGCPtr2CCPtr(pPool, pvAddress, GCPhysFault, sizeof(*pGstPte));
1843553dbdf4e46417158b4c6348c503adf10740vboxsync Log4(("pgmPoolMonitorChainChanging pae_32: deref %VHp GCPhys %VGp\n", uShw.pPT->a[iShw].u & X86_PTE_PAE_PG_MASK, pGstPte->u & X86_PTE_PG_MASK));
533ffcb943c4af2c5fe6385d816d0ba3eda9383bvboxsync PCX86PTEPAE pGstPte = (PCX86PTEPAE)pgmPoolMonitorGCPtr2CCPtr(pPool, pvAddress, GCPhysFault, sizeof(*pGstPte));
533ffcb943c4af2c5fe6385d816d0ba3eda9383bvboxsync Log4(("pgmPoolMonitorChainChanging pae_32: deref %VHp GCPhys %VGp\n", uShw.pPTPae->a[iShw].u & X86_PTE_PAE_PG_MASK, pGstPte->u & X86_PTE_PAE_PG_MASK));
b978e5849454446957177fd47ee98609ab0457a6vboxsync /* paranoia / a bit assumptive. */
b74ca013e5f201a2dd371e6c438433ceac12af30vboxsync && (off & 7) + pgmPoolDisasWriteSize(pCpu) > sizeof(X86PTEPAE))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync const unsigned iShw = off / sizeof(X86PTE); // ASSUMING 32-bit guest paging!
9e4166cf5ed4940f506bc718ea6c89bf7ed252c8vboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTXSUFF(pVM)->pgm.s));
9e4166cf5ed4940f506bc718ea6c89bf7ed252c8vboxsync VM_FF_SET(pPool->CTXSUFF(pVM), VM_FF_PGM_SYNC_CR3);
0e77737b0ba913683e614db11463b31ca67aacbevboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw=%#x!\n", iShw));
22e281e75ed636601178296c6daebda8f1d17c59vboxsync /* paranoia / a bit assumptive. */
b74ca013e5f201a2dd371e6c438433ceac12af30vboxsync const unsigned iShw2 = (off + pgmPoolDisasWriteSize(pCpu) - 1) / sizeof(X86PTE);
b74ca013e5f201a2dd371e6c438433ceac12af30vboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTXSUFF(pVM)->pgm.s));
b40179b44fea65b72b2f226f62af1ed7bd3c48fcvboxsync VM_FF_SET(pPool->CTXSUFF(pVM), VM_FF_PGM_SYNC_CR3);
2d53f6e472561965d363674e17f48d3bdffc24d3vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw2=%#x!\n", iShw2));
82e90599291da476b2de7c8db33cfb0f2cbac774vboxsync#if 0 /* useful when running PGMAssertCR3(), a bit too troublesome for general use (TLBs). */
2d53f6e472561965d363674e17f48d3bdffc24d3vboxsync && !VM_FF_ISSET(pPool->CTXSUFF(pVM), VM_FF_PGM_SYNC_CR3))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolMonitorChainChanging: iShw=%#x: %RX32 -> freeing it!\n", iShw, uShw.pPD->a[iShw].u));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync# ifdef IN_GC /* TLB load - we're pushing things a bit... */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolFree(pPool->CTXSUFF(pVM), uShw.pPD->a[iShw].u & X86_PDE_PG_MASK, pPage->idx, iShw);
22e281e75ed636601178296c6daebda8f1d17c59vboxsync unsigned iShw = (off / sizeof(X86PTE)) * 2; // ASSUMING 32-bit guest paging!
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if ((uShw.pPDPae->a[iShw].u & (PGM_PDFLAGS_MAPPING | X86_PDE_P)) == (PGM_PDFLAGS_MAPPING | X86_PDE_P))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTXSUFF(pVM)->pgm.s));
13ba5527caaa9b8c4fee29f22e374fa67c4c6f72vboxsync VM_FF_SET(pPool->CTXSUFF(pVM), VM_FF_PGM_SYNC_CR3);
13ba5527caaa9b8c4fee29f22e374fa67c4c6f72vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw=%#x!\n", iShw));
13ba5527caaa9b8c4fee29f22e374fa67c4c6f72vboxsync /* paranoia / a bit assumptive. */
806d0b554daa555364af5f87bc96eccbe760db7avboxsync && (uShw.pPDPae->a[iShw2].u & (PGM_PDFLAGS_MAPPING | X86_PDE_P)) == (PGM_PDFLAGS_MAPPING | X86_PDE_P))
4b8fcf8e4d11536879a1f6e66279ba0c363a7eaevboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTXSUFF(pVM)->pgm.s));
806d0b554daa555364af5f87bc96eccbe760db7avboxsync VM_FF_SET(pPool->CTXSUFF(pVM), VM_FF_PGM_SYNC_CR3);
806d0b554daa555364af5f87bc96eccbe760db7avboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw2=%#x!\n", iShw2));
9e4166cf5ed4940f506bc718ea6c89bf7ed252c8vboxsync#if 0 /* useful when running PGMAssertCR3(), a bit too troublesome for general use (TLBs). */
e08de24d4792d31b7f2aac29db5cb8840d940009vboxsync && !VM_FF_ISSET(pPool->CTXSUFF(pVM), VM_FF_PGM_SYNC_CR3))
806d0b554daa555364af5f87bc96eccbe760db7avboxsync LogFlow(("pgmPoolMonitorChainChanging: iShw=%#x: %RX64 -> freeing it!\n", iShw, uShw.pPDPae->a[iShw].u));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync# ifdef IN_GC /* TLB load - we're pushing things a bit... */
806d0b554daa555364af5f87bc96eccbe760db7avboxsync pgmPoolFree(pPool->CTXSUFF(pVM), uShw.pPDPae->a[iShw].u & X86_PDE_PAE_PG_MASK, pPage->idx, iShw);
806d0b554daa555364af5f87bc96eccbe760db7avboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTXSUFF(pVM)->pgm.s));
22e281e75ed636601178296c6daebda8f1d17c59vboxsync VM_FF_SET(pPool->CTXSUFF(pVM), VM_FF_PGM_SYNC_CR3);
34e34d3656484dde89a9c7b57fcbf7048d2fdb13vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw=%#x!\n", iShw));
806d0b554daa555364af5f87bc96eccbe760db7avboxsync#ifdef PGMPOOL_INVALIDATE_UPPER_SHADOW_TABLE_ENTRIES
4b8fcf8e4d11536879a1f6e66279ba0c363a7eaevboxsync /* causes trouble when the guest uses a PDE to refer to the whole page table level structure. (invalidate here; faults later on when it tries
806d0b554daa555364af5f87bc96eccbe760db7avboxsync * to change the page table entries
e0b9d3c357adf9b7d05f55540e86f22943fc4b23vboxsync LogFlow(("pgmPoolMonitorChainChanging: pae pd iShw=%#x: %RX64 -> freeing it!\n", iShw, uShw.pPDPae->a[iShw].u));
7e960d3a0a8a3a84d7aba2cca45d72b1c31cc97bvboxsync /* Note: hardcoded PAE implementation dependency */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync (pPage->enmKind == PGMPOOLKIND_PAE_PD_FOR_PAE_PD) ? PGMPOOL_IDX_PAE_PD : pPage->idx,
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync (pPage->enmKind == PGMPOOLKIND_PAE_PD_FOR_PAE_PD) ? iShw + (pPage->idx - PGMPOOL_IDX_PAE_PD_0) * X86_PG_PAE_ENTRIES : iShw);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* paranoia / a bit assumptive. */
79b24ef0ab7cd4a03a3571b3954c52ab8b573137vboxsync && (off & 7) + pgmPoolDisasWriteSize(pCpu) > sizeof(X86PDEPAE))
9984bae4ef25be8afd95d184308adcfef6e2ec0dvboxsync const unsigned iShw2 = (off + pgmPoolDisasWriteSize(pCpu) - 1) / sizeof(X86PDEPAE);
3dde2f85d4cf477621a3128887a2c08a8bca7c01vboxsync AssertReturnVoid(iShw2 < ELEMENTS(uShw.pPDPae->a));
22e281e75ed636601178296c6daebda8f1d17c59vboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTXSUFF(pVM)->pgm.s));
e0b9d3c357adf9b7d05f55540e86f22943fc4b23vboxsync VM_FF_SET(pPool->CTXSUFF(pVM), VM_FF_PGM_SYNC_CR3);
1986f56777969a25707ab214f8dd070804be666cvboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw2=%#x!\n", iShw2));
806d0b554daa555364af5f87bc96eccbe760db7avboxsync#ifdef PGMPOOL_INVALIDATE_UPPER_SHADOW_TABLE_ENTRIES
3cac8f8c6923a3a89ecfccda5e89ad75f48658e0vboxsync LogFlow(("pgmPoolMonitorChainChanging: pae pd iShw2=%#x: %RX64 -> freeing it!\n", iShw2, uShw.pPDPae->a[iShw2].u));
03319aeaef07ef63a404237f2cb56199131f4a03vboxsync /* Note: hardcoded PAE implementation dependency */
1157941288c9533575a655c660af55d13da31eefvboxsync (pPage->enmKind == PGMPOOLKIND_PAE_PD_FOR_PAE_PD) ? PGMPOOL_IDX_PAE_PD : pPage->idx,
5e797edc29f96c8367de4fbf5874171c24a89ba7vboxsync (pPage->enmKind == PGMPOOLKIND_PAE_PD_FOR_PAE_PD) ? iShw2 + (pPage->idx - PGMPOOL_IDX_PAE_PD_0) * X86_PG_PAE_ENTRIES : iShw2);
4b8fcf8e4d11536879a1f6e66279ba0c363a7eaevboxsync /* Hopefully this doesn't happen very often:
5e797edc29f96c8367de4fbf5874171c24a89ba7vboxsync * - touching unused parts of the page
3dde2f85d4cf477621a3128887a2c08a8bca7c01vboxsync * - messing with the bits of pd pointers without changing the physical address
9e4166cf5ed4940f506bc718ea6c89bf7ed252c8vboxsync if (iShw < X86_PG_PAE_PDPE_ENTRIES) /* don't use ELEMENTS(uShw.pPDPT->a), because that's for long mode only */
5e797edc29f96c8367de4fbf5874171c24a89ba7vboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTXSUFF(pVM)->pgm.s));
13ba5527caaa9b8c4fee29f22e374fa67c4c6f72vboxsync VM_FF_SET(pPool->CTXSUFF(pVM), VM_FF_PGM_SYNC_CR3);
79b24ef0ab7cd4a03a3571b3954c52ab8b573137vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw=%#x!\n", iShw));
79b24ef0ab7cd4a03a3571b3954c52ab8b573137vboxsync /* paranoia / a bit assumptive. */
1986f56777969a25707ab214f8dd070804be666cvboxsync && (off & 7) + pgmPoolDisasWriteSize(pCpu) > sizeof(X86PDPE))
e149c362e69e5f0bbd82da11fd8163b2d29c3a72vboxsync const unsigned iShw2 = (off + pgmPoolDisasWriteSize(pCpu) - 1) / sizeof(X86PDPE);
13ba5527caaa9b8c4fee29f22e374fa67c4c6f72vboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTXSUFF(pVM)->pgm.s));
13ba5527caaa9b8c4fee29f22e374fa67c4c6f72vboxsync VM_FF_SET(pPool->CTXSUFF(pVM), VM_FF_PGM_SYNC_CR3);
3dde2f85d4cf477621a3128887a2c08a8bca7c01vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw2=%#x!\n", iShw2));
79b24ef0ab7cd4a03a3571b3954c52ab8b573137vboxsync /* Hopefully this doesn't happen very often:
79b24ef0ab7cd4a03a3571b3954c52ab8b573137vboxsync * - messing with the bits of pd pointers without changing the physical address
3080f6c0871099df43a4e91b31894d9c2b1369a8vboxsync#ifdef PGMPOOL_INVALIDATE_UPPER_SHADOW_TABLE_ENTRIES
f9147fe1eaa4e35287f8f39282c7f92f0d7de0b7vboxsync if (!VM_FF_ISSET(pPool->CTXSUFF(pVM), VM_FF_PGM_SYNC_CR3))
7082d29724f6c3788977a51591b0379fd3acbf72vboxsync LogFlow(("pgmPoolMonitorChainChanging: pdpt iShw=%#x: %RX64 -> freeing it!\n", iShw, uShw.pPDPT->a[iShw].u));
7082d29724f6c3788977a51591b0379fd3acbf72vboxsync pgmPoolFree(pPool->CTXSUFF(pVM), uShw.pPDPT->a[iShw].u & X86_PDPE_PG_MASK, pPage->idx, iShw);
46b1ac1c3302722f93e787d0f0693965e88f5ceevboxsync /* paranoia / a bit assumptive. */
e4ea543752422f1139923e3e506c625b0a1827c5vboxsync && (off & 7) + pgmPoolDisasWriteSize(pCpu) > sizeof(X86PDPE))
13ba5527caaa9b8c4fee29f22e374fa67c4c6f72vboxsync const unsigned iShw2 = (off + pgmPoolDisasWriteSize(pCpu) - 1) / sizeof(X86PDPE);
22e281e75ed636601178296c6daebda8f1d17c59vboxsync LogFlow(("pgmPoolMonitorChainChanging: pdpt iShw2=%#x: %RX64 -> freeing it!\n", iShw2, uShw.pPDPT->a[iShw2].u));
1986f56777969a25707ab214f8dd070804be666cvboxsync pgmPoolFree(pPool->CTXSUFF(pVM), uShw.pPDPT->a[iShw2].u & X86_PDPE_PG_MASK, pPage->idx, iShw2);
6f0193f5a9287559d34a75f438c2682d8fb08038vboxsync /* Hopefully this doesn't happen very often:
22e281e75ed636601178296c6daebda8f1d17c59vboxsync * - messing with the bits of pd pointers without changing the physical address
6f0193f5a9287559d34a75f438c2682d8fb08038vboxsync#ifdef PGMPOOL_INVALIDATE_UPPER_SHADOW_TABLE_ENTRIES
6f0193f5a9287559d34a75f438c2682d8fb08038vboxsync if (!VM_FF_ISSET(pPool->CTXSUFF(pVM), VM_FF_PGM_SYNC_CR3))
9e4166cf5ed4940f506bc718ea6c89bf7ed252c8vboxsync LogFlow(("pgmPoolMonitorChainChanging: pml4 iShw=%#x: %RX64 -> freeing it!\n", iShw, uShw.pPML4->a[iShw].u));
9e4166cf5ed4940f506bc718ea6c89bf7ed252c8vboxsync pgmPoolFree(pPool->CTXSUFF(pVM), uShw.pPML4->a[iShw].u & X86_PML4E_PG_MASK, pPage->idx, iShw);
f9147fe1eaa4e35287f8f39282c7f92f0d7de0b7vboxsync /* paranoia / a bit assumptive. */
13ba5527caaa9b8c4fee29f22e374fa67c4c6f72vboxsync && (off & 7) + pgmPoolDisasWriteSize(pCpu) > sizeof(X86PDPE))
6f0193f5a9287559d34a75f438c2682d8fb08038vboxsync const unsigned iShw2 = (off + pgmPoolDisasWriteSize(pCpu) - 1) / sizeof(X86PML4E);
e0b9d3c357adf9b7d05f55540e86f22943fc4b23vboxsync LogFlow(("pgmPoolMonitorChainChanging: pml4 iShw2=%#x: %RX64 -> freeing it!\n", iShw2, uShw.pPML4->a[iShw2].u));
6f0193f5a9287559d34a75f438c2682d8fb08038vboxsync pgmPoolFree(pPool->CTXSUFF(pVM), uShw.pPML4->a[iShw2].u & X86_PML4E_PG_MASK, pPage->idx, iShw2);
22e281e75ed636601178296c6daebda8f1d17c59vboxsync AssertFatalMsgFailed(("enmKind=%d\n", pPage->enmKind));
65b61798a61dd4c32cce448db1dac70bba8d5cf5vboxsync * Checks if a access could be a fork operation in progress.
b978e5849454446957177fd47ee98609ab0457a6vboxsync * Meaning, that the guest is setuping up the parent process for Copy-On-Write.
65b61798a61dd4c32cce448db1dac70bba8d5cf5vboxsync * @returns true if it's likly that we're forking, otherwise false.
13ba5527caaa9b8c4fee29f22e374fa67c4c6f72vboxsync * @param pPool The pool.
13ba5527caaa9b8c4fee29f22e374fa67c4c6f72vboxsync * @param pCpu The disassembled instruction.
65b61798a61dd4c32cce448db1dac70bba8d5cf5vboxsync * @param offFault The access offset.
22e281e75ed636601178296c6daebda8f1d17c59vboxsyncDECLINLINE(bool) pgmPoolMonitorIsForking(PPGMPOOL pPool, PDISCPUSTATE pCpu, unsigned offFault)
13ba5527caaa9b8c4fee29f22e374fa67c4c6f72vboxsync * i386 linux is using btr to clear X86_PTE_RW.
4b8fcf8e4d11536879a1f6e66279ba0c363a7eaevboxsync * The functions involved are (2.6.16 source inspection):
65b61798a61dd4c32cce448db1dac70bba8d5cf5vboxsync * clear_bit
65b61798a61dd4c32cce448db1dac70bba8d5cf5vboxsync * ptep_set_wrprotect
9e4166cf5ed4940f506bc718ea6c89bf7ed252c8vboxsync * copy_one_pte
9e4166cf5ed4940f506bc718ea6c89bf7ed252c8vboxsync * copy_pte_range
65b61798a61dd4c32cce448db1dac70bba8d5cf5vboxsync * copy_pmd_range
e08de24d4792d31b7f2aac29db5cb8840d940009vboxsync * copy_pud_range
22e281e75ed636601178296c6daebda8f1d17c59vboxsync * copy_page_range
65b61798a61dd4c32cce448db1dac70bba8d5cf5vboxsync * copy_process
65b61798a61dd4c32cce448db1dac70bba8d5cf5vboxsync /** @todo Validate that the bit index is X86_PTE_RW. */
65b61798a61dd4c32cce448db1dac70bba8d5cf5vboxsync STAM_COUNTER_INC(&pPool->CTXMID(StatMonitor,Fork));
65b61798a61dd4c32cce448db1dac70bba8d5cf5vboxsync return true;
65b61798a61dd4c32cce448db1dac70bba8d5cf5vboxsync return false;
3cac8f8c6923a3a89ecfccda5e89ad75f48658e0vboxsync * Determin whether the page is likely to have been reused.
46df4404c8dbbf3672e7aae8cd0b2770356e5b73vboxsync * @returns true if we consider the page as being reused for a different purpose.
9984bae4ef25be8afd95d184308adcfef6e2ec0dvboxsync * @returns false if we consider it to still be a paging page.
ce2d2eef2525963979102e63c2419d1c69d767ccvboxsync * @param pPage The page in question.
ce2d2eef2525963979102e63c2419d1c69d767ccvboxsync * @param pCpu The disassembly info for the faulting insturction.
46df4404c8dbbf3672e7aae8cd0b2770356e5b73vboxsync * @param pvFault The fault address.
9f9a20823b87e89c1b5cb45eb9b5699b29bfefebvboxsync * @remark The REP prefix check is left to the caller because of STOSD/W.
ce2d2eef2525963979102e63c2419d1c69d767ccvboxsyncDECLINLINE(bool) pgmPoolMonitorIsReused(PPGMPOOLPAGE pPage, PDISCPUSTATE pCpu, RTGCPTR pvFault)
ce2d2eef2525963979102e63c2419d1c69d767ccvboxsync return true;
9f9a20823b87e89c1b5cb45eb9b5699b29bfefebvboxsync return true;
46df4404c8dbbf3672e7aae8cd0b2770356e5b73vboxsync return true;
46df4404c8dbbf3672e7aae8cd0b2770356e5b73vboxsync return true;
b978e5849454446957177fd47ee98609ab0457a6vboxsync return true;
3cac8f8c6923a3a89ecfccda5e89ad75f48658e0vboxsync case OP_MOVNTDQ: /* solaris - hwblkclr & hwblkpagecopy */
585f64d6f624f9e683321dabeb21b0eb2e6aa473vboxsync return true;
ce2d2eef2525963979102e63c2419d1c69d767ccvboxsync return true;
ce2d2eef2525963979102e63c2419d1c69d767ccvboxsync //if (pPage->fCR3Mix)
ce2d2eef2525963979102e63c2419d1c69d767ccvboxsync // return false;
9e4166cf5ed4940f506bc718ea6c89bf7ed252c8vboxsync return false;
585f64d6f624f9e683321dabeb21b0eb2e6aa473vboxsync * Flushes the page being accessed.
9673b0b804d0b0f801f377c6371600e92071241fvboxsync * @returns VBox status code suitable for scheduling.
4b8fcf8e4d11536879a1f6e66279ba0c363a7eaevboxsync * @param pVM The VM handle.
585f64d6f624f9e683321dabeb21b0eb2e6aa473vboxsync * @param pPool The pool.
585f64d6f624f9e683321dabeb21b0eb2e6aa473vboxsync * @param pPage The pool page (head).
585f64d6f624f9e683321dabeb21b0eb2e6aa473vboxsync * @param pCpu The disassembly of the write instruction.
585f64d6f624f9e683321dabeb21b0eb2e6aa473vboxsync * @param pRegFrame The trap register frame.
65b61798a61dd4c32cce448db1dac70bba8d5cf5vboxsync * @param GCPhysFault The fault address as guest physical address.
585f64d6f624f9e683321dabeb21b0eb2e6aa473vboxsync * @param pvFault The fault address.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic int pgmPoolAccessHandlerFlush(PVM pVM, PPGMPOOL pPool, PPGMPOOLPAGE pPage, PDISCPUSTATE pCpu,
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, RTGCPTR pvFault)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * First, do the flushing.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Emulate the instruction (xp/w2k problem, requires pc/cr2/sp detection).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync int rc2 = EMInterpretInstructionCPU(pVM, pCpu, pRegFrame, pvFault, &cbWritten);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if (PATMIsPatchGCAddr(pVM, (RTRCPTR)pRegFrame->eip))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolAccessHandlerPTWorker: Interpretation failed for patch code %04x:%RGv, ignoring.\n",
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_COUNTER_INC(&pPool->StatMonitorGCIntrFailPatch2);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_COUNTER_INC(&pPool->CTXMID(StatMonitor,EmulateInstr));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* See use in pgmPoolAccessHandlerSimple(). */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolAccessHandlerPT: returns %Vrc (flushed)\n", rc));
5b6e2c9a765c3c72295acc15791af8a700746956vboxsync * Handles the STOSD write accesses.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code suitable for scheduling.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM The VM handle.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The pool page (head).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pCpu The disassembly of the write instruction.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pRegFrame The trap register frame.
e9a217d585085a6a6d129d27ca0d96a1b8e6d0eevboxsync * @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 pCpu,
e17bd6c32a8dd64f2d42838f9028216465e2caf0vboxsync PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, RTGCPTR pvFault)
3cbb4f9a6a320e58ed398ef7aaa004cc8727abc5vboxsync * Increment the modification counter and insert it into the list
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * of modified pages the first time.
7e960d3a0a8a3a84d7aba2cca45d72b1c31cc97bvboxsync * Execute REP STOSD.
e17bd6c32a8dd64f2d42838f9028216465e2caf0vboxsync * This ASSUMES that we're not invoked by Trap0e on in a out-of-sync
e17bd6c32a8dd64f2d42838f9028216465e2caf0vboxsync * write situation, meaning that it's safe to write here.
e17bd6c32a8dd64f2d42838f9028216465e2caf0vboxsync pgmPoolMonitorChainChanging(pPool, pPage, GCPhysFault, (RTGCPTR)pu32, NULL);
e17bd6c32a8dd64f2d42838f9028216465e2caf0vboxsync PGMPhysWriteGCPhys(pVM, GCPhysFault, &pRegFrame->eax, 4);
49748bb305bd71f672cd083af208f4bb08c5d6abvboxsync /* See use in pgmPoolAccessHandlerSimple(). */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Handles the simple write accesses.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code suitable for scheduling.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM The VM handle.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The pool page (head).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pCpu The disassembly of the write instruction.
b9ca93dd1ad44cb8b27679dc5624be2f7b7f7af5vboxsync * @param pRegFrame The trap register frame.
b9ca93dd1ad44cb8b27679dc5624be2f7b7f7af5vboxsync * @param GCPhysFault The fault address as guest physical address.
b9ca93dd1ad44cb8b27679dc5624be2f7b7f7af5vboxsync * @param pvFault The fault address.
b9ca93dd1ad44cb8b27679dc5624be2f7b7f7af5vboxsyncDECLINLINE(int) pgmPoolAccessHandlerSimple(PVM pVM, PPGMPOOL pPool, PPGMPOOLPAGE pPage, PDISCPUSTATE pCpu,
b9ca93dd1ad44cb8b27679dc5624be2f7b7f7af5vboxsync PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, RTGCPTR pvFault)
3cbb4f9a6a320e58ed398ef7aaa004cc8727abc5vboxsync * Increment the modification counter and insert it into the list
8b984478b755f4d3091b977d9beac9fb7434279fvboxsync * of modified pages the first time.
e9a217d585085a6a6d129d27ca0d96a1b8e6d0eevboxsync * Clear all the pages. ASSUMES that pvFault is readable.
e9a217d585085a6a6d129d27ca0d96a1b8e6d0eevboxsync pgmPoolMonitorChainChanging(pPool, pPage, GCPhysFault, pvFault, pCpu);
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * Interpret the instruction.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync int rc = EMInterpretInstructionCPU(pVM, pCpu, pRegFrame, pvFault, &cb);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolAccessHandlerPTWorker: Interpretation failed for patch code %04x:%RGv - opcode=%d\n",
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pRegFrame->cs, (RTGCPTR)pRegFrame->rip, pCpu->pCurInstr->opcode));
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync STAM_COUNTER_INC(&pPool->CTXMID(StatMonitor,EmulateInstr));
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync * Quick hack, with logging enabled we're getting stale
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync * code TLBs but no data TLB for EIP and crash in EMInterpretDisasOne.
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync * Flushing here is BAD and expensive, I think EMInterpretDisasOne will
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync * have to be fixed to support this. But that'll have to wait till next week.
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync * An alternative is to keep track of the changed PTEs together with the
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync * GCPhys from the guest PT. This may proove expensive though.
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync * At the moment, it's VITAL that it's done AFTER the instruction interpreting
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync * because we need the stale TLBs in some cases (XP boot). This MUST be fixed properly!
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync LogFlow(("pgmPoolAccessHandlerSimple: returns %Vrc cb=%d\n", rc, cb));
f351fab06d1e1507b72f5c574df71193061fd393vboxsync * \#PF Handler callback for PT write accesses.
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync * @returns VBox status code (appropriate for GC return).
f351fab06d1e1507b72f5c574df71193061fd393vboxsync * @param pVM VM Handle.
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync * @param uErrorCode CPU Error code.
f351fab06d1e1507b72f5c574df71193061fd393vboxsync * @param pRegFrame Trap register frame.
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync * NULL on DMA and other non CPU access.
f351fab06d1e1507b72f5c574df71193061fd393vboxsync * @param pvFault The fault address (cr2).
f351fab06d1e1507b72f5c574df71193061fd393vboxsync * @param GCPhysFault The GC physical address corresponding to pvFault.
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync * @param pvUser User argument.
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsyncDECLEXPORT(int) pgmPoolAccessHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPHYS GCPhysFault, void *pvUser)
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync STAM_PROFILE_START(&pVM->pgm.s.CTXSUFF(pPool)->CTXSUFF(StatMonitor), a);
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync LogFlow(("pgmPoolAccessHandler: pvFault=%VGv pPage=%p:{.idx=%d} GCPhysFault=%VGp\n", pvFault, pPage, pPage->idx, GCPhysFault));
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync * We should ALWAYS have the list head as user parameter. This
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync * is because we use that page to record the changes.
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync * Disassemble the faulting instruction.
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync int rc = EMInterpretDisasOne(pVM, pRegFrame, &Cpu, NULL);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Check if it's worth dealing with.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync bool fReused = false;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if ( ( pPage->cModifications < 48 /** @todo #define */ /** @todo need to check that it's not mapping EIP. */ /** @todo adjust this! */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync && !(fReused = pgmPoolMonitorIsReused(pPage, &Cpu, pvFault))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync && !pgmPoolMonitorIsForking(pPool, &Cpu, GCPhysFault & PAGE_OFFSET_MASK))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Simple instructions, no REP prefix.
3cbb4f9a6a320e58ed398ef7aaa004cc8727abc5vboxsync rc = pgmPoolAccessHandlerSimple(pVM, pPool, pPage, &Cpu, pRegFrame, GCPhysFault, pvFault);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_PROFILE_STOP_EX(&pVM->pgm.s.CTXSUFF(pPool)->CTXSUFF(StatMonitor), &pPool->CTXMID(StatMonitor,Handled), a);
09e2f92b8f54aa362088e216007b53ecdb42e283vboxsync * Windows is frequently doing small memset() operations (netio test 4k+).
09e2f92b8f54aa362088e216007b53ecdb42e283vboxsync * We have to deal with these or we'll kill the cache and performance.
5ace91141404400247438502a84a418fba00c8cfvboxsync && pRegFrame->ecx * 4 <= PAGE_SIZE - ((uintptr_t)pvFault & PAGE_OFFSET_MASK)
3123bb2477edc752585e4bbd8e4cfedaf87997d1vboxsync && (pRegFrame->eax == 0 || pRegFrame->eax == 0x80) /* the two values observed. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = pgmPoolAccessHandlerSTOSD(pVM, pPool, pPage, &Cpu, pRegFrame, GCPhysFault, pvFault);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_PROFILE_STOP_EX(&pVM->pgm.s.CTXSUFF(pPool)->CTXSUFF(StatMonitor), &pPool->CTXMID(StatMonitor,RepStosd), a);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* REP prefix, don't bother. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_COUNTER_INC(&pPool->CTXMID(StatMonitor,RepPrefix));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log4(("pgmPoolAccessHandler: eax=%#x ecx=%#x edi=%#x esi=%#x eip=%VGv opcode=%d prefix=%#x\n",
0975ae0a0fb615c945150c48e4a73187c1f4f84dvboxsync pRegFrame->eax, pRegFrame->ecx, pRegFrame->edi, pRegFrame->esi, pRegFrame->rip, Cpu.pCurInstr->opcode, Cpu.prefix));
9984bae4ef25be8afd95d184308adcfef6e2ec0dvboxsync * Not worth it, so flush it.
9e4166cf5ed4940f506bc718ea6c89bf7ed252c8vboxsync * If we considered it to be reused, don't to back to ring-3
9984bae4ef25be8afd95d184308adcfef6e2ec0dvboxsync * to emulate failed instructions since we usually cannot
0975ae0a0fb615c945150c48e4a73187c1f4f84dvboxsync * interpret then. This may be a bit risky, in which case
9e4166cf5ed4940f506bc718ea6c89bf7ed252c8vboxsync * the reuse detection must be fixed.
7e960d3a0a8a3a84d7aba2cca45d72b1c31cc97bvboxsync rc = pgmPoolAccessHandlerFlush(pVM, pPool, pPage, &Cpu, pRegFrame, GCPhysFault, pvFault);
09e2f92b8f54aa362088e216007b53ecdb42e283vboxsync STAM_PROFILE_STOP_EX(&pVM->pgm.s.CTXSUFF(pPool)->CTXSUFF(StatMonitor), &pPool->CTXMID(StatMonitor,FlushPage), a);
09e2f92b8f54aa362088e216007b53ecdb42e283vboxsync# endif /* !IN_RING3 */
09e2f92b8f54aa362088e216007b53ecdb42e283vboxsync#endif /* PGMPOOL_WITH_MONITORING */
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: %VGp\n", pPage->GCPhys));
42c1972c22e09797b4b24afbd0ec114ed076c37cvboxsync Assert(pPage->GCPhys != NIL_RTGCPHYS); Assert(pPage->iNext == NIL_PGMPOOL_IDX);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Removes a page from the GCPhys hash table.
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncDECLINLINE(void) pgmPoolHashRemove(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log3(("pgmPoolHashRemove: %VGp\n", pPage->GCPhys));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertReleaseMsgFailed(("GCPhys=%VGp idx=%#x\n", pPage->GCPhys, pPage->idx));
3e6d3b0af632bdcd931b5149915c7b8be1a732cdvboxsync * Frees up one cache page.
a11c569636fa6838bd423f4631a9660a5a84204bvboxsync * @returns VBox status code.
5b6e2c9a765c3c72295acc15791af8a700746956vboxsync * @retval VINF_SUCCESS on success.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VERR_PGM_POOL_CLEARED if the deregistration of a physical handler will cause a light weight pool flush.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
036d626c5d4722da925dc8292f9248a5e09b4588vboxsync * @param iUser The user index.
1fb9c510656583ba12872e082125263a58d9bc6bvboxsyncstatic int pgmPoolCacheFreeOne(PPGMPOOL pPool, uint16_t iUser)
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync Assert(pPool->iAgeHead != pPool->iAgeTail); /* We shouldn't be here if there < 2 cached entries! */
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync * Select one page from the tail of the age list.
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync/* This is the alternative to the SyncCR3 pgmPoolCacheUsed calls.
b40179b44fea65b72b2f226f62af1ed7bd3c48fcvboxsync if (pPool->aPages[iToFree].iUserHead != NIL_PGMPOOL_USER_INDEX)
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync uint16_t i = pPool->aPages[iToFree].iAgePrev;
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync for (unsigned j = 0; j < 10 && i != NIL_PGMPOOL_USER_INDEX; j++, i = pPool->aPages[i].iAgePrev)
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync if (pPool->aPages[iToFree].iUserHead == NIL_PGMPOOL_USER_INDEX)
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync iToFree = i;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync int rc = pgmPoolFlushPage(pPool, &pPool->aPages[iToFree]);
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.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param enmKind2 The kind of the requested page.
5b6e2c9a765c3c72295acc15791af8a700746956vboxsyncstatic bool pgmPoolCacheReusedByKind(PGMPOOLKIND enmKind1, PGMPOOLKIND enmKind2)
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * Never reuse them. There is no remapping in non-paging mode.
6778b34cb96bef0fef23ebc461eb6a429d2907c5vboxsync return true;
6778b34cb96bef0fef23ebc461eb6a429d2907c5vboxsync * It's perfectly fine to reuse these, except for PAE and non-paging stuff.
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync return true;
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync return false;
d4b98dbce4cf7b3694b62d62a47553d399718dccvboxsync * It's perfectly fine to reuse these, except for PAE and non-paging stuff.
fd69ca9bd8b533bfa9ade45c1c2ff3116854e84avboxsync return true;
b978e5849454446957177fd47ee98609ab0457a6vboxsync return false;
5ace91141404400247438502a84a418fba00c8cfvboxsync * These cannot be flushed, and it's common to reuse the PDs as PTs.
5ace91141404400247438502a84a418fba00c8cfvboxsync return false;
5ace91141404400247438502a84a418fba00c8cfvboxsync * Attempts to satisfy a pgmPoolAlloc request from the cache.
01c7ae36dfb7eb93bef22d5ec6c1c0572eba3f24vboxsync * @returns VBox status code.
5a12b9772d9cf396a0ba7f54db399817ba7a65bavboxsync * @retval VINF_PGM_CACHED_PAGE on success.
5ace91141404400247438502a84a418fba00c8cfvboxsync * @retval VERR_FILE_NOT_FOUND if not found.
5ace91141404400247438502a84a418fba00c8cfvboxsync * @param pPool The pool.
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync * @param GCPhys The GC physical address of the page we're gonna shadow.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * @param enmKind The kind of mapping.
5ace91141404400247438502a84a418fba00c8cfvboxsync * @param iUser The shadow page pool index of the user table.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * @param iUserTable The index into the user table (shadowed).
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * @param ppPage Where to store the pointer to the page.
5ace91141404400247438502a84a418fba00c8cfvboxsyncstatic int pgmPoolCacheAlloc(PPGMPOOL pPool, RTGCPHYS GCPhys, PGMPOOLKIND enmKind, uint16_t iUser, uint32_t iUserTable, PPPGMPOOLPAGE ppPage)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Look up the GCPhys in the hash.
5ace91141404400247438502a84a418fba00c8cfvboxsync Log3(("pgmPoolCacheAlloc: %VGp kind %d iUser=%d iUserTable=%x SLOT=%d\n", GCPhys, enmKind, iUser, iUserTable, i));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log3(("pgmPoolCacheAlloc: slot %d found page %VGp\n", i, pPage->GCPhys));
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync int rc = pgmPoolTrackAddUser(pPool, pPage, iUser, iUserTable);
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync * The kind is different. In some cases we should now flush the page
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync * as it has been reused, but in most cases this is normal remapping
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync * of PDs as PT or big pages using the GCPhys field in a slightly
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync * different way than the other kinds.
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync if (pgmPoolCacheReusedByKind((PGMPOOLKIND)pPage->enmKind, enmKind))
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync pgmPoolFlushPage(pPool, pPage); /* ASSUMES that VERR_PGM_POOL_CLEARED will be returned by pgmPoolTracInsert. */
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync } while (i != NIL_PGMPOOL_IDX);
1fb9c510656583ba12872e082125263a58d9bc6bvboxsync Log3(("pgmPoolCacheAlloc: Missed GCPhys=%RGp enmKind=%d\n", GCPhys, enmKind));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Inserts a page into the cache.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
3cbb4f9a6a320e58ed398ef7aaa004cc8727abc5vboxsync * @param pPage The cached page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param fCanBeCached Set if the page is fit for caching from the caller's point of view.
09e2f92b8f54aa362088e216007b53ecdb42e283vboxsyncstatic void pgmPoolCacheInsert(PPGMPOOL pPool, PPGMPOOLPAGE pPage, bool fCanBeCached)
09e2f92b8f54aa362088e216007b53ecdb42e283vboxsync * Insert into the GCPhys hash if the page is fit for that.
09e2f92b8f54aa362088e216007b53ecdb42e283vboxsync Log3(("pgmPoolCacheInsert: Caching %p:{.Core=%RHp, .idx=%d, .enmKind=%d, GCPhys=%RGp}\n",
09e2f92b8f54aa362088e216007b53ecdb42e283vboxsync pPage, pPage->Core.Key, pPage->idx, pPage->enmKind, pPage->GCPhys));
09e2f92b8f54aa362088e216007b53ecdb42e283vboxsync Log3(("pgmPoolCacheInsert: Not caching %p:{.Core=%RHp, .idx=%d, .enmKind=%d, GCPhys=%RGp}\n",
28c928d1100d3b6a6d3506224cae25ad04732f73vboxsync pPage, pPage->Core.Key, pPage->idx, pPage->enmKind, pPage->GCPhys));
09e2f92b8f54aa362088e216007b53ecdb42e283vboxsync * Insert at the head of the age list.
09e2f92b8f54aa362088e216007b53ecdb42e283vboxsync pPool->aPages[pPool->iAgeHead].iAgePrev = pPage->idx;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Flushes a cached page.
5b6e2c9a765c3c72295acc15791af8a700746956vboxsync * @param pPool The pool.
08bc90fc2848c80bf8270bedc883745b8398e186vboxsync * @param pPage The cached page.
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsyncstatic void pgmPoolCacheFlushPage(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log3(("pgmPoolCacheFlushPage: %VGp\n", pPage->GCPhys));
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * Remove the page from the hash.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * Remove it from the age list.
74735ec6edd6640eebac8885fbb2dadc86b89cf5vboxsync pPool->aPages[pPage->iAgeNext].iAgePrev = pPage->iAgePrev;
74735ec6edd6640eebac8885fbb2dadc86b89cf5vboxsync pPool->aPages[pPage->iAgePrev].iAgeNext = pPage->iAgeNext;
74735ec6edd6640eebac8885fbb2dadc86b89cf5vboxsync#endif /* PGMPOOL_WITH_CACHE */
74735ec6edd6640eebac8885fbb2dadc86b89cf5vboxsync * Looks for pages sharing the monitor.
74735ec6edd6640eebac8885fbb2dadc86b89cf5vboxsync * @returns Pointer to the head page.
74735ec6edd6640eebac8885fbb2dadc86b89cf5vboxsync * @returns NULL if not found.
74735ec6edd6640eebac8885fbb2dadc86b89cf5vboxsync * @param pPool The Pool
74735ec6edd6640eebac8885fbb2dadc86b89cf5vboxsync * @param pNewPage The page which is going to be monitored.
74735ec6edd6640eebac8885fbb2dadc86b89cf5vboxsyncstatic PPGMPOOLPAGE pgmPoolMonitorGetPageByGCPhys(PPGMPOOL pPool, PPGMPOOLPAGE pNewPage)
74735ec6edd6640eebac8885fbb2dadc86b89cf5vboxsync * Look up the GCPhys in the hash.
74735ec6edd6640eebac8885fbb2dadc86b89cf5vboxsync RTGCPHYS GCPhys = pNewPage->GCPhys & ~(RTGCPHYS)(PAGE_SIZE - 1);
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync /* find the head */
ac6ddb9d00c1da301dfa25b0961dbd58b5f2f6e8vboxsync /* ignore, no monitoring. */
4b808cd07fd33b8a3edd0588dc43615686deb0e3vboxsync AssertFatalMsgFailed(("enmKind=%d idx=%d\n", pPage->enmKind, pPage->idx));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync } while (i != NIL_PGMPOOL_IDX);
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync * Enabled write monitoring of a guest page.
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync * @returns VBox status code.
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync * @retval VINF_SUCCESS on success.
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync * @retval VERR_PGM_POOL_CLEARED if the registration of the physical handler will cause a light weight pool flush.
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync * @param pPool The pool.
2b5a4cf3d77ab62dcbd882115b6d497547b20d29vboxsync * @param pPage The cached page.
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsyncstatic int pgmPoolMonitorInsert(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
016bd61cdd14201a24f289559b0cc333d8c94748vboxsync LogFlow(("pgmPoolMonitorInsert %VGp\n", pPage->GCPhys & ~(RTGCPHYS)(PAGE_SIZE - 1)));
016bd61cdd14201a24f289559b0cc333d8c94748vboxsync * Filter out the relevant kinds.
69deddbc68802f1cf1c3a404a9f816b8accb3385vboxsync /* Nothing to monitor here. */
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync AssertFatalMsgFailed(("This can't happen! enmKind=%d\n", pPage->enmKind));
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync * Install handler.
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync PPGMPOOLPAGE pPageHead = pgmPoolMonitorGetPageByGCPhys(pPool, pPage);
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync Assert(pPageHead != pPage); Assert(pPageHead->iMonitoredNext != pPage->idx);
13b9db9ae2c12b6c4e00eda5c79772d57a0d29e1vboxsync pPool->aPages[pPageHead->iMonitoredNext].iMonitoredPrev = pPage->idx;
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync Assert(pPage->iMonitoredNext == NIL_PGMPOOL_IDX); Assert(pPage->iMonitoredPrev == NIL_PGMPOOL_IDX);
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync const RTGCPHYS GCPhysPage = pPage->GCPhys & ~(RTGCPHYS)(PAGE_SIZE - 1);
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync rc = PGMHandlerPhysicalRegisterEx(pVM, PGMPHYSHANDLERTYPE_PHYSICAL_WRITE,
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync pPool->pfnAccessHandlerR3, MMHyperCCToR3(pVM, pPage),
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync pPool->pfnAccessHandlerR0, MMHyperCCToR0(pVM, pPage),
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync pPool->pfnAccessHandlerGC, MMHyperCCToGC(pVM, pPage),
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync /** @todo we should probably deal with out-of-memory conditions here, but for now increasing
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync * the heap size should suffice. */
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync if (pVM->pgm.s.fSyncFlags & PGM_SYNC_CLEAR_PGM_POOL)
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync * Disables write monitoring of a guest page.
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync * @returns VBox status code.
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync * @retval VINF_SUCCESS on success.
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync * @retval VERR_PGM_POOL_CLEARED if the deregistration of the physical handler will cause a light weight pool flush.
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync * @param pPool The pool.
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync * @param pPage The cached page.
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsyncstatic int pgmPoolMonitorFlush(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync * Filter out the relevant kinds.
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync /* Nothing to monitor here. */
2cd06fc737773d015b5268b9e4dfba5997915957vboxsync AssertFatalMsgFailed(("This can't happen! enmKind=%d\n", pPage->enmKind));
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * Remove the page from the monitored list or uninstall it if last.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync PPGMPOOLPAGE pNewHead = &pPool->aPages[pPage->iMonitoredNext];
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync rc = PGMHandlerPhysicalChangeCallbacks(pVM, pPage->GCPhys & ~(RTGCPHYS)(PAGE_SIZE - 1),
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync pPool->pfnAccessHandlerR3, MMHyperCCToR3(pVM, pNewHead),
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync pPool->pfnAccessHandlerR0, MMHyperCCToR0(pVM, pNewHead),
4584ef6026a823006bea5acbeb13dc4efe50da69vboxsync pPool->pfnAccessHandlerGC, MMHyperCCToGC(pVM, pNewHead),
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync pPool->aPages[pPage->iMonitoredPrev].iMonitoredNext = pPage->iMonitoredNext;
01cc79d6798a7ad8b8041ddb2b67fc8b37bf0b37vboxsync pPool->aPages[pPage->iMonitoredNext].iMonitoredPrev = pPage->iMonitoredPrev;
01cc79d6798a7ad8b8041ddb2b67fc8b37bf0b37vboxsync rc = PGMHandlerPhysicalDeregister(pVM, pPage->GCPhys & ~(RTGCPHYS)(PAGE_SIZE - 1));
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync if (pVM->pgm.s.fSyncFlags & PGM_SYNC_CLEAR_PGM_POOL)
b40179b44fea65b72b2f226f62af1ed7bd3c48fcvboxsync * Remove it from the list of modified pages (if in it).
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * Set or clear the fCR3Mix attribute in a chain of monitored pages.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * @param pPool The Pool.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * @param pPage A page in the chain.
c39952b427f31961ee5281dcdd492ad847ca74bbvboxsync * @param fCR3Mix The new fCR3Mix value.
b40179b44fea65b72b2f226f62af1ed7bd3c48fcvboxsyncstatic void pgmPoolMonitorChainChangeCR3Mix(PPGMPOOL pPool, PPGMPOOLPAGE pPage, bool fCR3Mix)
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync /* current */
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync /* before */
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync /* after */
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync * Installs or modifies monitoring of a CR3 page (special).
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync * We're pretending the CR3 page is shadowed by the pool so we can use the
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync * generic mechanisms in detecting chained monitoring. (This also gives us a
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync * tast of what code changes are required to really pool CR3 shadow pages.)
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync * @returns VBox status code.
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync * @param pPool The pool.
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync * @param idxRoot The CR3 (root) page index.
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync * @param GCPhysCR3 The (new) CR3 value.
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsyncint pgmPoolMonitorMonitorCR3(PPGMPOOL pPool, uint16_t idxRoot, RTGCPHYS GCPhysCR3)
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync Assert(idxRoot != NIL_PGMPOOL_IDX && idxRoot < PGMPOOL_IDX_FIRST);
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync LogFlow(("pgmPoolMonitorMonitorCR3: idxRoot=%d pPage=%p:{.GCPhys=%VGp, .fMonitored=%d} GCPhysCR3=%VGp\n",
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync idxRoot, pPage, pPage->GCPhys, pPage->fMonitored, GCPhysCR3));
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync * The unlikely case where it already matches.
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync * Flush the current monitoring and remove it from the hash.
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync pgmPoolMonitorChainChangeCR3Mix(pPool, pPage, false);
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync * Monitor the page at the new location and insert it into the hash.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync pgmPoolMonitorChainChangeCR3Mix(pPool, pPage, true);
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * Removes the monitoring of a CR3 page (special).
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * @returns VBox status code.
ef481e64bafc49f1232767ce12c3fa69a5d5fe50vboxsync * @param pPool The pool.
ef481e64bafc49f1232767ce12c3fa69a5d5fe50vboxsync * @param idxRoot The CR3 (root) page index.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsyncint pgmPoolMonitorUnmonitorCR3(PPGMPOOL pPool, uint16_t idxRoot)
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync Assert(idxRoot != NIL_PGMPOOL_IDX && idxRoot < PGMPOOL_IDX_FIRST);
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync LogFlow(("pgmPoolMonitorUnmonitorCR3: idxRoot=%d pPage=%p:{.GCPhys=%VGp, .fMonitored=%d}\n",
3ecd8008b81f02a04220705ae0033142af363280vboxsync idxRoot, pPage, pPage->GCPhys, pPage->fMonitored));
9984bae4ef25be8afd95d184308adcfef6e2ec0dvboxsync pgmPoolMonitorChainChangeCR3Mix(pPool, pPage, false);
1171e4fb031146163c9a5a66bd9cbf3f2a5acdb6vboxsync#endif /* PGMPOOL_WITH_MIXED_PT_CR3 */
1171e4fb031146163c9a5a66bd9cbf3f2a5acdb6vboxsync * Inserts the page into the list of modified pages.
1171e4fb031146163c9a5a66bd9cbf3f2a5acdb6vboxsync * @param pPool The pool.
1171e4fb031146163c9a5a66bd9cbf3f2a5acdb6vboxsync * @param pPage The page.
1171e4fb031146163c9a5a66bd9cbf3f2a5acdb6vboxsyncvoid pgmPoolMonitorModifiedInsert(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync Log3(("pgmPoolMonitorModifiedInsert: idx=%d\n", pPage->idx));
89818deb947a6b1a2925292bc9ff21e4e1bb60bbvboxsync ("Next=%d Prev=%d idx=%d cModifications=%d Head=%d cModifiedPages=%d\n",
01cc79d6798a7ad8b8041ddb2b67fc8b37bf0b37vboxsync pPage->iModifiedNext, pPage->iModifiedPrev, pPage->idx, pPage->cModifications,
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync pPool->aPages[pPool->iModifiedHead].iModifiedPrev = pPage->idx;
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync if (pPool->cModifiedPages > pPool->cModifiedPagesHigh)
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * Removes the page from the list of modified pages and resets the
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * moficiation counter.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * @param pPool The pool.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * @param pPage The page which is believed to be in the list of modified pages.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsyncstatic void pgmPoolMonitorModifiedRemove(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync Log3(("pgmPoolMonitorModifiedRemove: idx=%d cModifications=%d\n", pPage->idx, pPage->cModifications));
9b726ba798aabd1a27863e6f5cfeef1393bd198dvboxsync pPool->aPages[pPage->iModifiedNext].iModifiedPrev = NIL_PGMPOOL_IDX;
8ddd175fa7cb232e090f3b8934a411c167aadb27vboxsync pPool->aPages[pPage->iModifiedPrev].iModifiedNext = pPage->iModifiedNext;
8ddd175fa7cb232e090f3b8934a411c167aadb27vboxsync pPool->aPages[pPage->iModifiedNext].iModifiedPrev = pPage->iModifiedPrev;
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * Zaps the list of modified pages, resetting their modification counters in the process.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * @param pVM The VM handle.
ef481e64bafc49f1232767ce12c3fa69a5d5fe50vboxsync LogFlow(("pgmPoolMonitorModifiedClearAll: cModifiedPages=%d\n", pPool->cModifiedPages));
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync AssertMsg(cPages == pPool->cModifiedPages, ("%d != %d\n", cPages, pPool->cModifiedPages));
086e613371e0f6d1efc38fbc199fa20291afcd5evboxsync * Clear all shadow pages and clear all modification counters.
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync * @param pVM The VM handle.
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync * @remark Should only be used when monitoring is available, thus placed in
6c7440ab575cca1aa4d97d96b2d898a0d20c8efcvboxsync * the PGMPOOL_WITH_MONITORING #ifdef.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync LogFlow(("pgmPoolClearAll: cUsedPages=%d\n", pPool->cUsedPages));
ef481e64bafc49f1232767ce12c3fa69a5d5fe50vboxsync * Iterate all the pages until we've encountered all that in use.
ef481e64bafc49f1232767ce12c3fa69a5d5fe50vboxsync * This is simple but not quite optimal solution.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync unsigned cModifiedPages = 0; NOREF(cModifiedPages);
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * We only care about shadow page tables.
d41220dff1068effe66bb6a11f444811ba58de40vboxsync void *pvShw = PGMPOOL_PAGE_2_PTR(pPool->CTXSUFF(pVM), pPage);
d41220dff1068effe66bb6a11f444811ba58de40vboxsync /* fall thru */
ef481e64bafc49f1232767ce12c3fa69a5d5fe50vboxsync Assert(!pPage->cModifications || ++cModifiedPages);
d41220dff1068effe66bb6a11f444811ba58de40vboxsync Assert(pPage->iModifiedNext == NIL_PGMPOOL_IDX || pPage->cModifications);
ef481e64bafc49f1232767ce12c3fa69a5d5fe50vboxsync Assert(pPage->iModifiedPrev == NIL_PGMPOOL_IDX || pPage->cModifications);
d41220dff1068effe66bb6a11f444811ba58de40vboxsync /* swipe the special pages too. */
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync for (iPage = PGMPOOL_IDX_FIRST_SPECIAL; iPage < PGMPOOL_IDX_FIRST; iPage++)
01cc79d6798a7ad8b8041ddb2b67fc8b37bf0b37vboxsync Assert(!pPage->cModifications || ++cModifiedPages);
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync Assert(pPage->iModifiedNext == NIL_PGMPOOL_IDX || pPage->cModifications);
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync Assert(pPage->iModifiedPrev == NIL_PGMPOOL_IDX || pPage->cModifications);
ef481e64bafc49f1232767ce12c3fa69a5d5fe50vboxsync AssertMsg(cModifiedPages == pPool->cModifiedPages, ("%d != %d\n", cModifiedPages, pPool->cModifiedPages));
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync * Clear all the GCPhys links and rebuild the phys ext free list.
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync for (PPGMRAMRANGE pRam = pPool->CTXSUFF(pVM)->pgm.s.CTXALLSUFF(pRamRanges);
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync while (iPage-- > 0)
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync pRam->aPages[iPage].HCPhys &= MM_RAM_FLAGS_NO_REFS_MASK; /** @todo PAGE FLAGS */
ef481e64bafc49f1232767ce12c3fa69a5d5fe50vboxsync PPGMPOOLPHYSEXT paPhysExts = pPool->CTXSUFF(paPhysExts);
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync for (unsigned i = 0; i < cMaxPhysExts; i++)
ef481e64bafc49f1232767ce12c3fa69a5d5fe50vboxsync paPhysExts[cMaxPhysExts - 1].iNext = NIL_PGMPOOL_PHYSEXT_INDEX;
ef481e64bafc49f1232767ce12c3fa69a5d5fe50vboxsync#endif /* PGMPOOL_WITH_MONITORING */
ef481e64bafc49f1232767ce12c3fa69a5d5fe50vboxsync * Frees up at least one user entry.
ef481e64bafc49f1232767ce12c3fa69a5d5fe50vboxsync * @returns VBox status code.
ef481e64bafc49f1232767ce12c3fa69a5d5fe50vboxsync * @retval VINF_SUCCESS if successfully added.
dea1368099e5337861dd52906d4c683c447a33c4vboxsync * @retval VERR_PGM_POOL_FLUSHED if the pool was flushed.
dea1368099e5337861dd52906d4c683c447a33c4vboxsync * @param pPool The pool.
dea1368099e5337861dd52906d4c683c447a33c4vboxsync * @param iUser The user index.
dea1368099e5337861dd52906d4c683c447a33c4vboxsyncstatic int pgmPoolTrackFreeOneUser(PPGMPOOL pPool, uint16_t iUser)
dea1368099e5337861dd52906d4c683c447a33c4vboxsync * Just free cached pages in a braindead fashion.
ef481e64bafc49f1232767ce12c3fa69a5d5fe50vboxsync /** @todo walk the age list backwards and free the first with usage. */
ef481e64bafc49f1232767ce12c3fa69a5d5fe50vboxsync } while (pPool->iUserFreeHead == NIL_PGMPOOL_USER_INDEX);
ef481e64bafc49f1232767ce12c3fa69a5d5fe50vboxsync * Lazy approach.
dea1368099e5337861dd52906d4c683c447a33c4vboxsync * Inserts a page into the cache.
ef481e64bafc49f1232767ce12c3fa69a5d5fe50vboxsync * This will create user node for the page, insert it into the GCPhys
dea1368099e5337861dd52906d4c683c447a33c4vboxsync * hash, and insert it into the age list.
ef481e64bafc49f1232767ce12c3fa69a5d5fe50vboxsync * @returns VBox status code.
ef481e64bafc49f1232767ce12c3fa69a5d5fe50vboxsync * @retval VINF_SUCCESS if successfully added.
dea1368099e5337861dd52906d4c683c447a33c4vboxsync * @retval VERR_PGM_POOL_FLUSHED if the pool was flushed.
dea1368099e5337861dd52906d4c683c447a33c4vboxsync * @retval VERR_PGM_POOL_CLEARED if the deregistration of the physical handler will cause a light weight pool flush.
ef481e64bafc49f1232767ce12c3fa69a5d5fe50vboxsync * @param pPool The pool.
dea1368099e5337861dd52906d4c683c447a33c4vboxsync * @param pPage The cached page.
ef481e64bafc49f1232767ce12c3fa69a5d5fe50vboxsync * @param GCPhys The GC physical address of the page we're gonna shadow.
dea1368099e5337861dd52906d4c683c447a33c4vboxsync * @param iUser The user index.
dea1368099e5337861dd52906d4c683c447a33c4vboxsync * @param iUserTable The user table index.
dea1368099e5337861dd52906d4c683c447a33c4vboxsyncDECLINLINE(int) pgmPoolTrackInsert(PPGMPOOL pPool, PPGMPOOLPAGE pPage, RTGCPHYS GCPhys, uint16_t iUser, uint32_t iUserTable)
dea1368099e5337861dd52906d4c683c447a33c4vboxsync LogFlow(("pgmPoolTrackInsert iUser %d iUserTable %d\n", iUser, iUserTable));
3cac8f8c6923a3a89ecfccda5e89ad75f48658e0vboxsync * 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
b1c3cdef473df2fbc621d5da81acc82dbfb8a11avboxsync * have to make sure we don't try monitor & cache any recursive reuse of
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * a monitored CR3 page. Because all windows versions are doing this we'll
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * have to be able to do combined access monitoring, CR3 + PT and
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * PD + PT (guest PAE).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * We're now cooperating with the CR3 monitor if an uncachable page is found.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync#if defined(PGMPOOL_WITH_MONITORING) || defined(PGMPOOL_WITH_CACHE)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync const bool fCanBeMonitored = true;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync bool fCanBeMonitored = pPool->CTXSUFF(pVM)->pgm.s.GCPhysGstCR3Monitored == NIL_RTGCPHYS
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync || (GCPhys & X86_PTE_PAE_PG_MASK) != (pPool->CTXSUFF(pVM)->pgm.s.GCPhysGstCR3Monitored & X86_PTE_PAE_PG_MASK)
1e3cd9c9c95ff352da1331a1789b05fd012c880dvboxsync pgmPoolCacheInsert(pPool, pPage, fCanBeMonitored); /* This can be expanded. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* 'Failed' - free the usage, and keep it in the cache (if enabled). */
7e960d3a0a8a3a84d7aba2cca45d72b1c31cc97bvboxsync#endif /* PGMPOOL_WITH_MONITORING */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync# ifdef PGMPOOL_WITH_CACHE /* (only used when the cache is enabled.) */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Adds a user reference to a page.
1ce20e84ae29a712029d1e213740388d7e158d5cvboxsync * This will
1ce20e84ae29a712029d1e213740388d7e158d5cvboxsync * This will move the page to the head of the
1ce20e84ae29a712029d1e213740388d7e158d5cvboxsync * @returns VBox status code.
1ce20e84ae29a712029d1e213740388d7e158d5cvboxsync * @retval VINF_SUCCESS if successfully added.
1ce20e84ae29a712029d1e213740388d7e158d5cvboxsync * @retval VERR_PGM_POOL_FLUSHED if the pool was flushed.
1ce20e84ae29a712029d1e213740388d7e158d5cvboxsync * @param pPool The pool.
1ce20e84ae29a712029d1e213740388d7e158d5cvboxsync * @param pPage The cached page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param iUser The user index.
1ce20e84ae29a712029d1e213740388d7e158d5cvboxsync * @param iUserTable The user table.
1ce20e84ae29a712029d1e213740388d7e158d5cvboxsyncstatic int pgmPoolTrackAddUser(PPGMPOOL pPool, PPGMPOOLPAGE pPage, uint16_t iUser, uint32_t iUserTable)
1ce20e84ae29a712029d1e213740388d7e158d5cvboxsync LogFlow(("pgmPoolTrackAddUser iUser %d iUserTable %d\n", iUser, iUserTable));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Check that the entry doesn't already exists.
1ce20e84ae29a712029d1e213740388d7e158d5cvboxsync AssertMsg(paUsers[i].iUser != iUser || paUsers[i].iUserTable != iUserTable, ("%x %x vs new %x %x\n", paUsers[i].iUser, paUsers[i].iUserTable, iUser, iUserTable));
8b03ab0bcd5c238021bc8a43d887dd9d0870c0f5vboxsync * Allocate a user node.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Initialize the user node and insert it.
223cf005b18af2c21352a70693ebaf0582f68ebcvboxsync * Tell the cache to update its replacement stats for this page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync# endif /* PGMPOOL_WITH_CACHE */
e85d76a7e5a047db3cdc8576ff5f412c7b73bbabvboxsync * Frees a user record associated with a page.
9b45880674da6f82ca27cc28b0272de3dd3cc7dfvboxsync * This does not clear the entry in the user table, it simply replaces the
9b45880674da6f82ca27cc28b0272de3dd3cc7dfvboxsync * user record to the chain of free records.
e85d76a7e5a047db3cdc8576ff5f412c7b73bbabvboxsync * @param pPool The pool.
e85d76a7e5a047db3cdc8576ff5f412c7b73bbabvboxsync * @param HCPhys The HC physical address of the shadow page.
b55721e255f55546462b62c2d09259bb7bf8ef90vboxsync * @param iUser The shadow page pool index of the user table.
e85d76a7e5a047db3cdc8576ff5f412c7b73bbabvboxsync * @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.
00599f6d39cc25ca39845c2433cd75de7b9f6971vboxsync /* 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=%#x iUserTable=%#x GCPhys=%VGp\n",
00599f6d39cc25ca39845c2433cd75de7b9f6971vboxsync * Gets the entry size of a shadow table.
00599f6d39cc25ca39845c2433cd75de7b9f6971vboxsync * @param enmKind The kind of page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns The size of the entry in bytes. That is, 4 or 8.
9b45880674da6f82ca27cc28b0272de3dd3cc7dfvboxsync * @returns If the kind is not for a table, an assertion is raised and 0 is
9b45880674da6f82ca27cc28b0272de3dd3cc7dfvboxsync * returned.
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsyncDECLINLINE(unsigned) pgmPoolTrackGetShadowEntrySize(PGMPOOLKIND enmKind)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Gets the entry size of a guest table.
6b022885f2cb6a55167609edecd89570cd80001dvboxsync * @param enmKind The kind of page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns The size of the entry in bytes. That is, 0, 4 or 8.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns If the kind is not for a table, an assertion is raised and 0 is
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * returned.
1e3cd9c9c95ff352da1331a1789b05fd012c880dvboxsyncDECLINLINE(unsigned) pgmPoolTrackGetGuestEntrySize(PGMPOOLKIND enmKind)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /** @todo can we return 0? (nobody is calling this...) */
74991d7531692858fd22acf371a7ee941567977cvboxsync * Scans one shadow page table for mappings of a physical page.
74991d7531692858fd22acf371a7ee941567977cvboxsync * @param pVM The VM handle.
74991d7531692858fd22acf371a7ee941567977cvboxsync * @param pPhysPage The guest page in question.
74991d7531692858fd22acf371a7ee941567977cvboxsync * @param iShw The shadow page table.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param cRefs The number of references made in that PT.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic void pgmPoolTrackFlushGCPhysPTInt(PVM pVM, PCPGMPAGE pPhysPage, uint16_t iShw, uint16_t cRefs)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolTrackFlushGCPhysPT: HCPhys=%RHp iShw=%d cRefs=%d\n", pPhysPage->HCPhys, iShw, cRefs));
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync * Assert sanity.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertFatalMsg(iShw < pPool->cCurPages && iShw != NIL_PGMPOOL_IDX, ("iShw=%d\n", iShw));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Then, clear the actual mappings to the page in the shadow PT.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync const uint32_t u32 = PGM_PAGE_GET_HCPHYS(pPhysPage) | X86_PTE_P;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PX86PT pPT = (PX86PT)PGMPOOL_PAGE_2_PTR(pVM, pPage);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned i = pPage->iFirstPresent; i < ELEMENTS(pPT->a); i++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if ((pPT->a[i].u & (X86_PTE_PG_MASK | X86_PTE_P)) == u32)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log4(("pgmPoolTrackFlushGCPhysPTs: i=%d pte=%RX32 cRefs=%#x\n", i, pPT->a[i], cRefs));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPT->a[i].u = 0;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync#if defined(DEBUG) && !defined(IN_RING0) ///@todo RTLogPrintf is missing in R0.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync RTLogPrintf("cRefs=%d iFirstPresent=%d cPresent=%d\n", cRefs, pPage->iFirstPresent, pPage->cPresent);
0174432b2b1a760b89840ba696f7ba51def65dddvboxsync if ((pPT->a[i].u & (X86_PTE_PG_MASK | X86_PTE_P)) == u32)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPT->a[i].u = 0;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertFatalMsgFailed(("cRefs=%d iFirstPresent=%d cPresent=%d\n", cRefs, pPage->iFirstPresent, pPage->cPresent));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync const uint64_t u64 = PGM_PAGE_GET_HCPHYS(pPhysPage) | X86_PTE_P;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PX86PTPAE pPT = (PX86PTPAE)PGMPOOL_PAGE_2_PTR(pVM, pPage);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned i = pPage->iFirstPresent; i < ELEMENTS(pPT->a); i++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if ((pPT->a[i].u & (X86_PTE_PAE_PG_MASK | X86_PTE_P)) == u64)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log4(("pgmPoolTrackFlushGCPhysPTs: i=%d pte=%RX64 cRefs=%#x\n", i, pPT->a[i], cRefs));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPT->a[i].u = 0;
c33db29e7b41467a35675031f5f5233839909083vboxsync#if defined(DEBUG) && !defined(IN_RING0) ///@todo RTLogPrintf is missing in R0.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync RTLogPrintf("cRefs=%d iFirstPresent=%d cPresent=%d\n", cRefs, pPage->iFirstPresent, pPage->cPresent);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if ((pPT->a[i].u & (X86_PTE_PAE_PG_MASK | X86_PTE_P)) == u64)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPT->a[i].u = 0;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertFatalMsgFailed(("cRefs=%d iFirstPresent=%d cPresent=%d\n", cRefs, pPage->iFirstPresent, pPage->cPresent));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertFatalMsgFailed(("enmKind=%d iShw=%d\n", pPage->enmKind, iShw));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Scans one shadow page table for mappings of a physical page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM The VM handle.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPhysPage The guest page in question.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param iShw The shadow page table.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param cRefs The number of references made in that PT.
3cac8f8c6923a3a89ecfccda5e89ad75f48658e0vboxsyncvoid pgmPoolTrackFlushGCPhysPT(PVM pVM, PPGMPAGE pPhysPage, uint16_t iShw, uint16_t cRefs)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPGMPOOL pPool = pVM->pgm.s.CTXSUFF(pPool); NOREF(pPool);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolTrackFlushGCPhysPT: HCPhys=%RHp iShw=%d cRefs=%d\n", pPhysPage->HCPhys, iShw, cRefs));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_PROFILE_START(&pPool->StatTrackFlushGCPhysPT, f);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolTrackFlushGCPhysPTInt(pVM, pPhysPage, iShw, cRefs);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPhysPage->HCPhys &= MM_RAM_FLAGS_NO_REFS_MASK; /** @todo PAGE FLAGS */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_PROFILE_STOP(&pPool->StatTrackFlushGCPhysPT, f);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Flushes a list of shadow page tables mapping the same physical page.
a5c11842b92303b7b5d0086ee5011a969e321b50vboxsync * @param pVM The VM handle.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPhysPage The guest page in question.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param iPhysExt The physical cross reference extent list to flush.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncvoid pgmPoolTrackFlushGCPhysPTs(PVM pVM, PPGMPAGE pPhysPage, uint16_t iPhysExt)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_PROFILE_START(&pPool->StatTrackFlushGCPhysPTs, f);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolTrackFlushGCPhysPTs: HCPhys=%RHp iPhysExt\n", pPhysPage->HCPhys, iPhysExt));
00599f6d39cc25ca39845c2433cd75de7b9f6971vboxsync for (unsigned i = 0; i < ELEMENTS(pPhysExt->aidx); i++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolTrackFlushGCPhysPTInt(pVM, pPhysPage, pPhysExt->aidx[i], 1);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* insert the list into the free list and clear the ram range entry. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPhysPage->HCPhys &= MM_RAM_FLAGS_NO_REFS_MASK; /** @todo PAGE FLAGS */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_PROFILE_STOP(&pPool->StatTrackFlushGCPhysPTs, f);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync#endif /* PGMPOOL_WITH_GCPHYS_TRACKING */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Scans all shadow page tables for mappings of a physical page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * This may be slow, but it's most likely more efficient than cleaning
9b45880674da6f82ca27cc28b0272de3dd3cc7dfvboxsync * out the entire page pool / cache.
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync * @returns VBox status code.
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync * @retval VINF_SUCCESS if all references has been successfully cleared.
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync * @retval VINF_PGM_GCPHYS_ALIASED if we're better off with a CR3 sync and
ec588a4ac8429a8b6c744544818b3ce3b2c75690vboxsync * a page pool cleaning.
75fca099c974cbbd48f132af1378c60232614760vboxsync * @param pVM The VM handle.
75fca099c974cbbd48f132af1378c60232614760vboxsync * @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 HCPhys=%RHp\n",
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPool->cUsedPages, pPool->cPresent, pPhysPage->HCPhys));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * There is a limit to what makes sense.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolTrackFlushGCPhysPTsSlow: giving up... (cPresent=%d)\n", pPool->cPresent));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_PROFILE_STOP(&pPool->StatTrackFlushGCPhysPTsSlow, s);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Iterate all the pages until we've encountered all that in use.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * This is simple but not quite optimal solution.
a5c11842b92303b7b5d0086ee5011a969e321b50vboxsync const uint64_t u64 = PGM_PAGE_GET_HCPHYS(pPhysPage) | X86_PTE_P;
315f443a509c31db47b8f5cb94d26e54c3d5c497vboxsync * We only care about shadow page tables.
3080f6c0871099df43a4e91b31894d9c2b1369a8vboxsync PX86PT pPT = (PX86PT)PGMPOOL_PAGE_2_PTR(pVM, pPage);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned i = pPage->iFirstPresent; i < ELEMENTS(pPT->a); i++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync 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;
a3db4ff1e0aa7f94c9176ef16264df572eec0aebvboxsync PX86PTPAE pPT = (PX86PTPAE)PGMPOOL_PAGE_2_PTR(pVM, pPage);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned i = pPage->iFirstPresent; i < ELEMENTS(pPT->a); i++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if ((pPT->a[i].u & (X86_PTE_PAE_PG_MASK | X86_PTE_P)) == u64)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync //Log4(("pgmPoolTrackFlushGCPhysPTsSlow: idx=%d i=%d pte=%RX64\n", iPage, i, pPT->a[i]));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPT->a[i].u = 0;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPhysPage->HCPhys &= MM_RAM_FLAGS_NO_REFS_MASK; /** @todo PAGE FLAGS */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_PROFILE_STOP(&pPool->StatTrackFlushGCPhysPTsSlow, s);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Clears the user entry in a user table.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * This is used to remove all references to a page when flushing it.
a5c11842b92303b7b5d0086ee5011a969e321b50vboxsyncstatic void pgmPoolTrackClearPageUser(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PCPGMPOOLUSER pUser)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Map the user page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPGMPOOLPAGE pUserPage = &pPool->aPages[pUser->iUser];
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync u.pau64 = (uint64_t *)PGMPOOL_PAGE_2_PTR(pPool->CTXSUFF(pVM), pUserPage);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Safety precaution in case we change the paging for other modes too in the future. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Assert(PGMGetHyperCR3(CTXSUFF(pPool->pVM)) != pPage->Core.Key);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Some sanity checks.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Assert(!(u.pau32[pUser->iUser] & PGM_PDFLAGS_MAPPING));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Assert(!(u.pau64[pUser->iUser] & PGM_PDFLAGS_MAPPING));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Assert(pUser->iUserTable < 2048 && pUser->iUser == PGMPOOL_IDX_PAE_PD);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Assert(!(u.pau64[pUser->iUserTable] & PGM_PLXFLAGS_PERMANENT));
00599f6d39cc25ca39845c2433cd75de7b9f6971vboxsync Assert(!(u.pau64[pUser->iUser] & PGM_PDFLAGS_MAPPING));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Assert(!(u.pau64[pUser->iUserTable] & PGM_PLXFLAGS_PERMANENT));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Assert(!(u.pau64[pUser->iUserTable] & PGM_PLXFLAGS_PERMANENT));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* GCPhys >> PAGE_SHIFT is the index here */
ec588a4ac8429a8b6c744544818b3ce3b2c75690vboxsync AssertMsgFailed(("enmKind=%d\n", pUserPage->enmKind));
75fca099c974cbbd48f132af1378c60232614760vboxsync#endif /* VBOX_STRICT */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Clear the entry in the user page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* 32-bit entries */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* 64-bit entries */
09d4e754a010196fe0d9d972b6ccc005ecb8b116vboxsync AssertFatalMsgFailed(("enmKind=%d iUser=%#x iUserTable=%#x\n", pUserPage->enmKind, pUser->iUser, pUser->iUserTable));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Clears all users of a page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic void pgmPoolTrackClearPageUsers(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Free all the user records.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Clear enter in user table. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolTrackClearPageUser(pPool, pPage, &paUsers[i]);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Free it. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Next. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Allocates a new physical cross reference extent.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns Pointer to the allocated extent on success. NULL if we're out of them.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM The VM handle.
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->CTXSUFF(paPhysExts)[iPhysExt];
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Frees a physical cross reference extent.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM The VM handle.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param iPhysExt The extent to free.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncvoid pgmPoolTrackPhysExtFree(PVM pVM, uint16_t iPhysExt)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPGMPOOLPHYSEXT pPhysExt = &pPool->CTXSUFF(paPhysExts)[iPhysExt];
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned i = 0; i < ELEMENTS(pPhysExt->aidx); i++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Frees a physical cross reference extent.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM The VM handle.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param iPhysExt The extent to free.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncvoid pgmPoolTrackPhysExtFreeList(PVM pVM, uint16_t iPhysExt)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned i = 0; i < ELEMENTS(pPhysExt->aidx); i++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Insert a reference into a list of physical cross reference extents.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns The new ram range flags (top 16-bits).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM The VM handle.
9a99bb9ca6c5bc8ef1977e01e13b05e5cc58319bvboxsync * @param iPhysExt The physical extent index of the list head.
50df3da42ff6589b0ecc4f50f2288811bc370186vboxsync * @param iShwPT The shadow page table index.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic uint16_t pgmPoolTrackPhysExtInsert(PVM pVM, uint16_t iPhysExt, uint16_t iShwPT)
01cc79d6798a7ad8b8041ddb2b67fc8b37bf0b37vboxsync PPGMPOOLPHYSEXT paPhysExts = pPool->CTXSUFF(paPhysExts);
fdc5224bd8d9a60af82da5809e3d6729c9bc69cbvboxsync /* special common case. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if (paPhysExts[iPhysExt].aidx[2] == NIL_PGMPOOL_IDX)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_COUNTER_INC(&pVM->pgm.s.StatTrackAliasedMany);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolTrackPhysExtAddref: %d:{,,%d}\n", iPhysExt, iShwPT));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return iPhysExt | (MM_RAM_FLAGS_CREFS_PHYSEXT << (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* general treatment. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned i = 0; i < ELEMENTS(paPhysExts[iPhysExt].aidx); i++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if (paPhysExts[iPhysExt].aidx[i] == NIL_PGMPOOL_IDX)
5dda7f07dab8a954e6c4cf2378b15f921e60d9aavboxsync STAM_COUNTER_INC(&pVM->pgm.s.StatTrackAliasedMany);
5dda7f07dab8a954e6c4cf2378b15f921e60d9aavboxsync LogFlow(("pgmPoolTrackPhysExtAddref: %d:{%d} i=%d cMax=%d\n", iPhysExt, iShwPT, i, cMax));
5dda7f07dab8a954e6c4cf2378b15f921e60d9aavboxsync return iPhysExtStart | (MM_RAM_FLAGS_CREFS_PHYSEXT << (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT));
5dda7f07dab8a954e6c4cf2378b15f921e60d9aavboxsync LogFlow(("pgmPoolTrackPhysExtAddref: overflow (1) iShwPT=%d\n", iShwPT));
d6b5539478863f176bfffefc1ada2b9489cfa092vboxsync return MM_RAM_FLAGS_IDX_OVERFLOWED | (MM_RAM_FLAGS_CREFS_PHYSEXT << (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT));
52694110156cee1511e430c9ae800de121a20050vboxsync /* add another extent to the list. */
5dda7f07dab8a954e6c4cf2378b15f921e60d9aavboxsync PPGMPOOLPHYSEXT pNew = pgmPoolTrackPhysExtAlloc(pVM, &iPhysExt);
5dda7f07dab8a954e6c4cf2378b15f921e60d9aavboxsync return MM_RAM_FLAGS_IDX_OVERFLOWED | (MM_RAM_FLAGS_CREFS_PHYSEXT << (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT));
06de36c1229f14000638fa27993b13c9133e85f5vboxsync LogFlow(("pgmPoolTrackPhysExtAddref: added new extent %d:{%d}->%d\n", iPhysExt, iShwPT, iPhysExtStart));
d6b5539478863f176bfffefc1ada2b9489cfa092vboxsync return iPhysExt | (MM_RAM_FLAGS_CREFS_PHYSEXT << (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT));
9c2450ffd7e8a08cc596a2e4cc4d4e4dc9b382cfvboxsync * Add a reference to guest physical page where extents are in use.
9c2450ffd7e8a08cc596a2e4cc4d4e4dc9b382cfvboxsync * @returns The new ram range flags (top 16-bits).
9c2450ffd7e8a08cc596a2e4cc4d4e4dc9b382cfvboxsync * @param pVM The VM handle.
9c2450ffd7e8a08cc596a2e4cc4d4e4dc9b382cfvboxsync * @param u16 The ram range flags (top 16-bits).
5dda7f07dab8a954e6c4cf2378b15f921e60d9aavboxsync * @param iShwPT The shadow page table index.
52694110156cee1511e430c9ae800de121a20050vboxsyncuint16_t pgmPoolTrackPhysExtAddref(PVM pVM, uint16_t u16, uint16_t iShwPT)
016950bb1b289514e67d9e473538d22a50c0e408vboxsync if ((u16 >> (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT)) != MM_RAM_FLAGS_CREFS_PHYSEXT)
016950bb1b289514e67d9e473538d22a50c0e408vboxsync * Convert to extent list.
016950bb1b289514e67d9e473538d22a50c0e408vboxsync Assert((u16 >> (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT)) == 1);
016950bb1b289514e67d9e473538d22a50c0e408vboxsync PPGMPOOLPHYSEXT pPhysExt = pgmPoolTrackPhysExtAlloc(pVM, &iPhysExt);
5dda7f07dab8a954e6c4cf2378b15f921e60d9aavboxsync LogFlow(("pgmPoolTrackPhysExtAddref: new extent: %d:{%d, %d}\n", iPhysExt, u16 & MM_RAM_FLAGS_IDX_MASK, iShwPT));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync u16 = iPhysExt | (MM_RAM_FLAGS_CREFS_PHYSEXT << (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync u16 = MM_RAM_FLAGS_IDX_OVERFLOWED | (MM_RAM_FLAGS_CREFS_PHYSEXT << (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync else if (u16 != (MM_RAM_FLAGS_IDX_OVERFLOWED | (MM_RAM_FLAGS_CREFS_PHYSEXT << (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT))))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Insert into the extent list.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync u16 = pgmPoolTrackPhysExtInsert(pVM, u16 & MM_RAM_FLAGS_IDX_MASK, iShwPT);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_COUNTER_INC(&pVM->pgm.s.StatTrackAliasedLots);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Clear references to guest physical memory.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPhysPage Pointer to the aPages entry in the ram range.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncvoid pgmPoolTrackPhysExtDerefGCPhys(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PPGMPAGE pPhysPage)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync const unsigned cRefs = pPhysPage->HCPhys >> MM_RAM_FLAGS_CREFS_SHIFT; /** @todo PAGE FLAGS */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertFatalMsg(cRefs == MM_RAM_FLAGS_CREFS_PHYSEXT, ("cRefs=%d HCPhys=%RHp pPage=%p:{.idx=%d}\n", cRefs, pPhysPage->HCPhys, pPage, pPage->idx));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync uint16_t iPhysExt = (pPhysPage->HCPhys >> MM_RAM_FLAGS_IDX_SHIFT) & MM_RAM_FLAGS_IDX_MASK;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPGMPOOLPHYSEXT paPhysExts = pPool->CTXSUFF(paPhysExts);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Look for the shadow page and check if it's all freed.
afed5ab737f4aacfae3fe73776f40e989190a7cavboxsync for (unsigned i = 0; i < ELEMENTS(paPhysExts[iPhysExt].aidx); i++)
8a132edc1577cbe2a19cd778c1b2bea6ae5e8515vboxsync for (i = 0; i < ELEMENTS(paPhysExts[iPhysExt].aidx); i++)
32f98f3d0fb00168315b4ece1f0808df4cd88248vboxsync if (paPhysExts[iPhysExt].aidx[i] != NIL_PGMPOOL_IDX)
32f98f3d0fb00168315b4ece1f0808df4cd88248vboxsync LogFlow(("pgmPoolTrackPhysExtDerefGCPhys: HCPhys=%RX64 idx=%d\n", pPhysPage->HCPhys, pPage->idx));
32f98f3d0fb00168315b4ece1f0808df4cd88248vboxsync /* we can free the node. */
32f98f3d0fb00168315b4ece1f0808df4cd88248vboxsync const uint16_t iPhysExtNext = paPhysExts[iPhysExt].iNext;
32f98f3d0fb00168315b4ece1f0808df4cd88248vboxsync /* lonely node */
32f98f3d0fb00168315b4ece1f0808df4cd88248vboxsync LogFlow(("pgmPoolTrackPhysExtDerefGCPhys: HCPhys=%RX64 idx=%d lonely\n", pPhysPage->HCPhys, pPage->idx));
32f98f3d0fb00168315b4ece1f0808df4cd88248vboxsync pPhysPage->HCPhys &= MM_RAM_FLAGS_NO_REFS_MASK; /** @todo PAGE FLAGS */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync else if (iPhysExtPrev == NIL_PGMPOOL_PHYSEXT_INDEX)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolTrackPhysExtDerefGCPhys: HCPhys=%RX64 idx=%d head\n", pPhysPage->HCPhys, pPage->idx));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPhysPage->HCPhys = (pPhysPage->HCPhys & MM_RAM_FLAGS_NO_REFS_MASK) /** @todo PAGE FLAGS */
21d4a56532f8029ae299f552811a0b86c1909416vboxsync | ((uint64_t)MM_RAM_FLAGS_CREFS_PHYSEXT << MM_RAM_FLAGS_CREFS_SHIFT)
1a25adaca81841abf5e6cdfed02eaff64941357dvboxsync | ((uint64_t)iPhysExtNext << MM_RAM_FLAGS_IDX_SHIFT);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* in list */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolTrackPhysExtDerefGCPhys: HCPhys=%RX64 idx=%d\n", pPhysPage->HCPhys, pPage->idx));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertFatalMsgFailed(("not-found! cRefs=%d HCPhys=%RHp pPage=%p:{.idx=%d}\n", cRefs, pPhysPage->HCPhys, pPage, pPage->idx));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync else /* nothing to do */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolTrackPhysExtDerefGCPhys: HCPhys=%RX64\n", pPhysPage->HCPhys));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Clear references to guest physical memory.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * This is the same as pgmPoolTracDerefGCPhys except that the guest physical address
750d4d0506a38b2e80c997075d40aad474e675fbvboxsync * is assumed to be correct, so the linear search can be skipped and we can assert
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * at an earlier point.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param HCPhys The host physical address corresponding to the guest page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param GCPhys The guest physical address corresponding to HCPhys.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic void pgmPoolTracDerefGCPhys(PPGMPOOL pPool, PPGMPOOLPAGE pPage, RTHCPHYS HCPhys, RTGCPHYS GCPhys)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Walk range list.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPGMRAMRANGE pRam = pPool->CTXSUFF(pVM)->pgm.s.CTXALLSUFF(pRamRanges);
afed5ab737f4aacfae3fe73776f40e989190a7cavboxsync /* does it match? */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if (PGM_PAGE_GET_HCPHYS(&pRam->aPages[iPage]) == HCPhys)
689e03ca2c98ca6feaab8d9de6e4687a98f14ccbvboxsync pgmTrackDerefGCPhys(pPool, pPage, &pRam->aPages[iPage]);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertFatalMsgFailed(("HCPhys=%VHp GCPhys=%VGp\n", HCPhys, GCPhys));
689e03ca2c98ca6feaab8d9de6e4687a98f14ccbvboxsync * Clear references to guest physical memory.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param HCPhys The host physical address corresponding to the guest page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param GCPhysHint The guest physical address which may corresponding to HCPhys.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic void pgmPoolTracDerefGCPhysHint(PPGMPOOL pPool, PPGMPOOLPAGE pPage, RTHCPHYS HCPhys, RTGCPHYS GCPhysHint)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Walk range list.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPGMRAMRANGE pRam = pPool->CTXSUFF(pVM)->pgm.s.CTXALLSUFF(pRamRanges);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* does it match? */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if (PGM_PAGE_GET_HCPHYS(&pRam->aPages[iPage]) == HCPhys)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmTrackDerefGCPhys(pPool, pPage, &pRam->aPages[iPage]);
491e761460097c61edb725a77477cecb2774da45vboxsync * Damn, the hint didn't work. We'll have to do an expensive linear search.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAM_COUNTER_INC(&pPool->StatTrackLinearRamSearches);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pRam = pPool->CTXSUFF(pVM)->pgm.s.CTXALLSUFF(pRamRanges);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync while (iPage-- > 0)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if (PGM_PAGE_GET_HCPHYS(&pRam->aPages[iPage]) == HCPhys)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log4(("pgmPoolTracDerefGCPhysHint: Linear HCPhys=%VHp GCPhysHint=%VGp GCPhysReal=%VGp\n",
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync HCPhys, GCPhysHint, pRam->GCPhys + (iPage << PAGE_SHIFT)));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmTrackDerefGCPhys(pPool, pPage, &pRam->aPages[iPage]);
afed5ab737f4aacfae3fe73776f40e989190a7cavboxsync AssertFatalMsgFailed(("HCPhys=%VHp GCPhysHint=%VGp\n", HCPhys, GCPhysHint));
6b022885f2cb6a55167609edecd89570cd80001dvboxsync * Clear references to guest physical memory in a 32-bit / 32-bit page table.
2f1b3d7474489e653b75edf9492132a0f56aab4dvboxsync * @param pPool The pool.
ab1239d8445aa1fd4afddb7d0c8b90bbdc742010vboxsync * @param pPage The page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pShwPT The shadow page table (mapping of the page).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pGstPT The guest page table.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncDECLINLINE(void) pgmPoolTrackDerefPT32Bit32Bit(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PT pShwPT, PCX86PT pGstPT)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned i = pPage->iFirstPresent; i < ELEMENTS(pShwPT->a); i++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log4(("pgmPoolTrackDerefPT32Bit32Bit: i=%d pte=%RX32 hint=%RX32\n",
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync i, pShwPT->a[i].u & X86_PTE_PG_MASK, pGstPT->a[i].u & X86_PTE_PG_MASK));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolTracDerefGCPhysHint(pPool, pPage, pShwPT->a[i].u & X86_PTE_PG_MASK, pGstPT->a[i].u & X86_PTE_PG_MASK);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Clear references to guest physical memory in a PAE / 32-bit page table.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pShwPT The shadow page table (mapping of the page).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pGstPT The guest page table (just a half one).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncDECLINLINE(void) pgmPoolTrackDerefPTPae32Bit(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PTPAE pShwPT, PCX86PT pGstPT)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log4(("pgmPoolTrackDerefPTPae32Bit: i=%d pte=%RX32 hint=%RX32\n",
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync i, pShwPT->a[i].u & X86_PTE_PAE_PG_MASK, pGstPT->a[i].u & X86_PTE_PG_MASK));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolTracDerefGCPhysHint(pPool, pPage, pShwPT->a[i].u & X86_PTE_PAE_PG_MASK, pGstPT->a[i].u & X86_PTE_PG_MASK);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Clear references to guest physical memory in a PAE / PAE page table.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pShwPT The shadow page table (mapping of the page).
19b725c530eb49600728765de7ed451cbe290740vboxsync * @param pGstPT The guest page table.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncDECLINLINE(void) pgmPoolTrackDerefPTPaePae(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PTPAE pShwPT, PCX86PTPAE pGstPT)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log4(("pgmPoolTrackDerefPTPaePae: i=%d pte=%RX32 hint=%RX32\n",
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync i, pShwPT->a[i].u & X86_PTE_PAE_PG_MASK, pGstPT->a[i].u & X86_PTE_PAE_PG_MASK));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolTracDerefGCPhysHint(pPool, pPage, pShwPT->a[i].u & X86_PTE_PAE_PG_MASK, pGstPT->a[i].u & X86_PTE_PAE_PG_MASK);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Clear references to guest physical memory in a 32-bit / 4MB page table.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pShwPT The shadow page table (mapping of the page).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncDECLINLINE(void) pgmPoolTrackDerefPT32Bit4MB(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PT pShwPT)
00599f6d39cc25ca39845c2433cd75de7b9f6971vboxsync for (unsigned i = 0; i < ELEMENTS(pShwPT->a); i++, GCPhys += PAGE_SIZE)
10e1bc06b2908a0af56d92ffdbadd25b36a5ef61vboxsync Log4(("pgmPoolTrackDerefPT32Bit4MB: i=%d pte=%RX32 GCPhys=%RGp\n",
5db1d52ffbcaa46c3d944c6c2d9c552306817d9avboxsync pgmPoolTracDerefGCPhys(pPool, pPage, pShwPT->a[i].u & X86_PTE_PG_MASK, GCPhys);
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync * Clear references to guest physical memory in a PAE / 2/4MB page table.
75fca099c974cbbd48f132af1378c60232614760vboxsync * @param pPool The pool.
75fca099c974cbbd48f132af1378c60232614760vboxsync * @param pPage The page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pShwPT The shadow page table (mapping of the page).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncDECLINLINE(void) pgmPoolTrackDerefPTPaeBig(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PTPAE pShwPT)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned i = 0; i < ELEMENTS(pShwPT->a); i++, GCPhys += PAGE_SIZE)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log4(("pgmPoolTrackDerefPTPae32Bit: i=%d pte=%RX32 hint=%RX32\n",
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolTracDerefGCPhys(pPool, pPage, pShwPT->a[i].u & X86_PTE_PAE_PG_MASK, GCPhys);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync#endif /* PGMPOOL_WITH_GCPHYS_TRACKING */
223cf005b18af2c21352a70693ebaf0582f68ebcvboxsync * Clear references to shadowed pages in a PAE (legacy or 64 bits) page directory.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pShwPD The shadow page directory (mapping of the page).
3080f6c0871099df43a4e91b31894d9c2b1369a8vboxsyncDECLINLINE(void) pgmPoolTrackDerefPDPae(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PDPAE pShwPD)
00599f6d39cc25ca39845c2433cd75de7b9f6971vboxsync PPGMPOOLPAGE pSubPage = (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, pShwPD->a[i].u & X86_PDE_PAE_PG_MASK);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolTrackFreeUser(pPool, pSubPage, pPage->idx, i);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertFatalMsgFailed(("%RX64\n", pShwPD->a[i].u & X86_PDE_PAE_PG_MASK));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /** @todo 64-bit guests: have to ensure that we're not exhausting the dynamic mappings! */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Clear references to shadowed pages in a 64-bit page directory pointer table.
9b45880674da6f82ca27cc28b0272de3dd3cc7dfvboxsync * @param pPool The pool.
9b45880674da6f82ca27cc28b0272de3dd3cc7dfvboxsync * @param pPage The page.
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync * @param pShwPDPT The shadow page directory pointer table (mapping of the page).
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsyncDECLINLINE(void) pgmPoolTrackDerefPDPT64Bit(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PDPT pShwPDPT)
75fca099c974cbbd48f132af1378c60232614760vboxsync for (unsigned i = 0; i < ELEMENTS(pShwPDPT->a); i++)
9b45880674da6f82ca27cc28b0272de3dd3cc7dfvboxsync PPGMPOOLPAGE pSubPage = (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, pShwPDPT->a[i].u & X86_PDPE_PG_MASK);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolTrackFreeUser(pPool, pSubPage, pPage->idx, i);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertFatalMsgFailed(("%RX64\n", pShwPDPT->a[i].u & X86_PDPE_PG_MASK));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /** @todo 64-bit guests: have to ensure that we're not exhausting the dynamic mappings! */
020916e230faa4a37bace3a8480f54fac94ea173vboxsync * Clear references to shadowed pages in a 64-bit level 4 page table.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPage The page.
aaeb2e2f6ed5b164f1dec9a16a7adeb84f64cf31vboxsync * @param pShwPML4 The shadow page directory pointer table (mapping of the page).
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncDECLINLINE(void) pgmPoolTrackDerefPML464Bit(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PML4 pShwPML4)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned i = 0; i < ELEMENTS(pShwPML4->a); i++)
50df3da42ff6589b0ecc4f50f2288811bc370186vboxsync PPGMPOOLPAGE pSubPage = (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, pShwPML4->a[i].u & X86_PDPE_PG_MASK);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pgmPoolTrackFreeUser(pPool, pSubPage, pPage->idx, i);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertFatalMsgFailed(("%RX64\n", pShwPML4->a[i].u & X86_PML4E_PG_MASK));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /** @todo 64-bit guests: have to ensure that we're not exhausting the dynamic mappings! */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Clears all references made by this page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * This includes other shadow pages and GC physical addresses.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
9c425bdea5f0991df62922b1584b805a86f2f898vboxsync * @param pPage The page.
aaeb2e2f6ed5b164f1dec9a16a7adeb84f64cf31vboxsyncstatic void pgmPoolTrackDeref(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync * Map the shadow page and take action according to the page kind.
b978e5849454446957177fd47ee98609ab0457a6vboxsync void *pvShw = PGMPOOL_PAGE_2_PTR(pPool->CTXSUFF(pVM), pPage);
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync STAM_PROFILE_START(&pPool->StatTrackDerefGCPhys, g);
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync int rc = PGM_GCPHYS_2_PTR(pPool->CTXSUFF(pVM), pPage->GCPhys, &pvGst); AssertReleaseRC(rc);
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync pgmPoolTrackDerefPT32Bit32Bit(pPool, pPage, (PX86PT)pvShw, (PCX86PT)pvGst);
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync STAM_PROFILE_STOP(&pPool->StatTrackDerefGCPhys, g);
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync STAM_PROFILE_START(&pPool->StatTrackDerefGCPhys, g);
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync int rc = PGM_GCPHYS_2_PTR_EX(pPool->CTXSUFF(pVM), pPage->GCPhys, &pvGst); AssertReleaseRC(rc);
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync pgmPoolTrackDerefPTPae32Bit(pPool, pPage, (PX86PTPAE)pvShw, (PCX86PT)pvGst);
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync STAM_PROFILE_STOP(&pPool->StatTrackDerefGCPhys, g);
b978e5849454446957177fd47ee98609ab0457a6vboxsync STAM_PROFILE_START(&pPool->StatTrackDerefGCPhys, g);
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync int rc = PGM_GCPHYS_2_PTR(pPool->CTXSUFF(pVM), pPage->GCPhys, &pvGst); AssertReleaseRC(rc);
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync pgmPoolTrackDerefPTPaePae(pPool, pPage, (PX86PTPAE)pvShw, (PCX86PTPAE)pvGst);
020916e230faa4a37bace3a8480f54fac94ea173vboxsync STAM_PROFILE_STOP(&pPool->StatTrackDerefGCPhys, g);
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync case PGMPOOLKIND_32BIT_PT_FOR_PHYS: /* treat it like a 4 MB page */
5007ad5d2bce84d88ee339a94e0aa7b91c699194vboxsync STAM_PROFILE_START(&pPool->StatTrackDerefGCPhys, g);
5007ad5d2bce84d88ee339a94e0aa7b91c699194vboxsync pgmPoolTrackDerefPT32Bit4MB(pPool, pPage, (PX86PT)pvShw);
acba9722fdb2a8ee387985604a89e4507bda0789vboxsync STAM_PROFILE_STOP(&pPool->StatTrackDerefGCPhys, g);
5007ad5d2bce84d88ee339a94e0aa7b91c699194vboxsync case PGMPOOLKIND_PAE_PT_FOR_PHYS: /* treat it like a 4 MB page */
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync STAM_PROFILE_START(&pPool->StatTrackDerefGCPhys, g);
5007ad5d2bce84d88ee339a94e0aa7b91c699194vboxsync pgmPoolTrackDerefPTPaeBig(pPool, pPage, (PX86PTPAE)pvShw);
467e62e1aa999ec951e820d74498ef79dd1bedbdvboxsync STAM_PROFILE_STOP(&pPool->StatTrackDerefGCPhys, g);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync#else /* !PGMPOOL_WITH_GCPHYS_TRACKING */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync#endif /* !PGMPOOL_WITH_GCPHYS_TRACKING */
aaeb2e2f6ed5b164f1dec9a16a7adeb84f64cf31vboxsync pgmPoolTrackDerefPDPae(pPool, pPage, (PX86PDPAE)pvShw);
b978e5849454446957177fd47ee98609ab0457a6vboxsync pgmPoolTrackDerefPDPT64Bit(pPool, pPage, (PX86PDPT)pvShw);
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync pgmPoolTrackDerefPML464Bit(pPool, pPage, (PX86PML4)pvShw);
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync AssertFatalMsgFailed(("enmKind=%d\n", pPage->enmKind));
b978e5849454446957177fd47ee98609ab0457a6vboxsync /* paranoia, clear the shadow page. Remove this laser (i.e. let Alloc and ClearAll do it). */
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync#endif /* PGMPOOL_WITH_USER_TRACKING */
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync * Flushes all the special root pages as part of a pgmPoolFlushAllInt operation.
b978e5849454446957177fd47ee98609ab0457a6vboxsync * @param pPool The pool.
b978e5849454446957177fd47ee98609ab0457a6vboxsyncstatic void pgmPoolFlushAllSpecialRoots(PPGMPOOL pPool)
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync * These special pages are all mapped into the indexes 1..PGMPOOL_IDX_FIRST.
020916e230faa4a37bace3a8480f54fac94ea173vboxsync * Get the page address.
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync u.pau64 = (uint64_t *)PGMPOOL_PAGE_2_PTR(pPool->CTXSUFF(pVM), pPage);
b66e14ead868d803cc49957974c34c4ea47346b4vboxsync * Mark stuff not present.
467e62e1aa999ec951e820d74498ef79dd1bedbdvboxsync for (unsigned iPage = 0; iPage < X86_PG_ENTRIES; iPage++)
020916e230faa4a37bace3a8480f54fac94ea173vboxsync if ((u.pau32[iPage] & (PGM_PDFLAGS_MAPPING | X86_PDE_P)) == X86_PDE_P)
8c9d2065ca6efecd5661174e382314868c0d4b94vboxsync for (unsigned iPage = 0; iPage < X86_PG_PAE_ENTRIES * X86_PG_PAE_PDPE_ENTRIES; iPage++)
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync if ((u.pau64[iPage] & (PGM_PDFLAGS_MAPPING | X86_PDE_P)) == X86_PDE_P)
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync /* Not root of shadowed pages currently, ignore it. */
5007ad5d2bce84d88ee339a94e0aa7b91c699194vboxsync * Paranoia (to be removed), flag a global CR3 sync.
5007ad5d2bce84d88ee339a94e0aa7b91c699194vboxsync VM_FF_SET(pPool->CTXSUFF(pVM), VM_FF_PGM_SYNC_CR3);
5007ad5d2bce84d88ee339a94e0aa7b91c699194vboxsync * Flushes the entire cache.
5007ad5d2bce84d88ee339a94e0aa7b91c699194vboxsync * It will assert a global CR3 flush (FF) and assumes the caller is aware of this
5007ad5d2bce84d88ee339a94e0aa7b91c699194vboxsync * and execute this CR3 flush.
b0065cd95da56e4208839eb0d3963472c688a8d4vboxsync * @param pPool The pool.
020916e230faa4a37bace3a8480f54fac94ea173vboxsync * If there are no pages in the pool, there is nothing to do.
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync * Nuke the free list and reinsert all pages into it.
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync for (unsigned i = pPool->cCurPages - 1; i >= PGMPOOL_IDX_FIRST; i--)
5007ad5d2bce84d88ee339a94e0aa7b91c699194vboxsync Assert(pPage->Core.Key == MMPage2Phys(pPool->pVMHC, pPage->pvPageHC));
020916e230faa4a37bace3a8480f54fac94ea173vboxsync pPage->fZeroed = false; /* This could probably be optimized, but better safe than sorry. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPool->aPages[pPool->cCurPages - 1].iNext = NIL_PGMPOOL_IDX;
b978e5849454446957177fd47ee98609ab0457a6vboxsync * Zap and reinitialize the user records.
b978e5849454446957177fd47ee98609ab0457a6vboxsync for (unsigned i = 0; i < cMaxUsers; i++)
020916e230faa4a37bace3a8480f54fac94ea173vboxsync paUsers[cMaxUsers - 1].iNext = NIL_PGMPOOL_USER_INDEX;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Clear all the GCPhys links and rebuild the phys ext free list.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (PPGMRAMRANGE pRam = pPool->CTXSUFF(pVM)->pgm.s.CTXALLSUFF(pRamRanges);
b978e5849454446957177fd47ee98609ab0457a6vboxsync while (iPage-- > 0)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pRam->aPages[iPage].HCPhys &= MM_RAM_FLAGS_NO_REFS_MASK; /** @todo PAGE FLAGS */
9424be2edf0232241bc75178b401464d4de76cadvboxsync PPGMPOOLPHYSEXT paPhysExts = pPool->CTXSUFF(paPhysExts);
b978e5849454446957177fd47ee98609ab0457a6vboxsync for (unsigned i = 0; i < cMaxPhysExts; i++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync paPhysExts[cMaxPhysExts - 1].iNext = NIL_PGMPOOL_PHYSEXT_INDEX;
b978e5849454446957177fd47ee98609ab0457a6vboxsync * Just zap the modified list.
5007ad5d2bce84d88ee339a94e0aa7b91c699194vboxsync * Clear the GCPhys hash and the age list.
b978e5849454446957177fd47ee98609ab0457a6vboxsync for (unsigned i = 0; i < ELEMENTS(pPool->aiHash); i++)
b978e5849454446957177fd47ee98609ab0457a6vboxsync * Flush all the special root pages.
b978e5849454446957177fd47ee98609ab0457a6vboxsync * Reinsert active pages into the hash and ensure monitoring chains are correct.
b978e5849454446957177fd47ee98609ab0457a6vboxsync for (unsigned i = PGMPOOL_IDX_FIRST_SPECIAL; i < PGMPOOL_IDX_FIRST; i++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* ASSUMES that we're not sharing with any of the other special pages (safe for now). */
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync int rc = PGMHandlerPhysicalChangeCallbacks(pVM, pPage->GCPhys & ~(RTGCPHYS)(PAGE_SIZE - 1),
11c599b71a8c202a506b8623af57432c3d415ddavboxsync pPool->pfnAccessHandlerR3, MMHyperCCToR3(pVM, pPage),
11c599b71a8c202a506b8623af57432c3d415ddavboxsync pPool->pfnAccessHandlerR0, MMHyperCCToR0(pVM, pPage),
11c599b71a8c202a506b8623af57432c3d415ddavboxsync pPool->pfnAccessHandlerGC, MMHyperCCToGC(pVM, pPage),
11c599b71a8c202a506b8623af57432c3d415ddavboxsync Assert(pPage->iUserHead == NIL_PGMPOOL_USER_INDEX); /* for now */
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync * Flushes a pool page.
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync * This moves the page to the free list after removing all user references to it.
34e34d3656484dde89a9c7b57fcbf7048d2fdb13vboxsync * In GC this will cause a CR3 reload if the page is traced back to an active root page.
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync * @returns VBox status code.
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync * @retval VINF_SUCCESS on success.
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync * @retval VERR_PGM_POOL_CLEARED if the deregistration of the physical handler will cause a light weight pool flush.
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync * @param pPool The pool.
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync * @param HCPhys The HC physical address of the shadow page.
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsyncint pgmPoolFlushPage(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync LogFlow(("pgmPoolFlushPage: pPage=%p:{.Key=%VHp, .idx=%d, .enmKind=%d, .GCPhys=%VGp}\n",
b301c2ed80b2ae5201801c30b37618a158fcc14evboxsync pPage, pPage->Core.Key, pPage->idx, pPage->enmKind, pPage->GCPhys));
b301c2ed80b2ae5201801c30b37618a158fcc14evboxsync * Quietly reject any attempts at flushing any of the special root pages.
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync Log(("pgmPoolFlushPage: special root page, rejected. enmKind=%d idx=%d\n", pPage->enmKind, pPage->idx));
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync * Quietly reject any attempts at flushing the currently active shadow CR3 mapping
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync if ( pPage->enmKind == PGMPOOLKIND_64BIT_PML4_FOR_64BIT_PML4
fc4516250f652da12d477446bc5351bcf6c5aaebvboxsync && PGMGetHyperCR3(CTXSUFF(pPool->pVM)) == pPage->Core.Key)
11c599b71a8c202a506b8623af57432c3d415ddavboxsync Log(("pgmPoolFlushPage: current active shadow CR3, rejected. enmKind=%d idx=%d\n", pPage->enmKind, pPage->idx));
11c599b71a8c202a506b8623af57432c3d415ddavboxsync /* Safety precaution in case we change the paging for other modes too in the future. */
11c599b71a8c202a506b8623af57432c3d415ddavboxsync AssertFatal(PGMGetHyperCR3(CTXSUFF(pPool->pVM)) != pPage->Core.Key);
11c599b71a8c202a506b8623af57432c3d415ddavboxsync * Mark the page as being in need of a ASMMemZeroPage().
11c599b71a8c202a506b8623af57432c3d415ddavboxsync * Clear the page.
11c599b71a8c202a506b8623af57432c3d415ddavboxsync * Flush it from the cache.
020916e230faa4a37bace3a8480f54fac94ea173vboxsync#endif /* PGMPOOL_WITH_CACHE */
11c599b71a8c202a506b8623af57432c3d415ddavboxsync * Deregistering the monitoring.
11c599b71a8c202a506b8623af57432c3d415ddavboxsync * Free the page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Frees a usage of a pool page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * The caller is responsible to updating the user table so that it no longer
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * references the shadow page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pPool The pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param HCPhys The HC physical address of the shadow page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param iUser The shadow page pool index of the user table.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param iUserTable The index into the user table (shadowed).
223cf005b18af2c21352a70693ebaf0582f68ebcvboxsyncvoid pgmPoolFreeByPage(PPGMPOOL pPool, PPGMPOOLPAGE pPage, uint16_t iUser, uint32_t iUserTable)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolFreeByPage: pPage=%p:{.Key=%VHp, .idx=%d, enmKind=%d} iUser=%#x iUserTable=%#x\n",
50df3da42ff6589b0ecc4f50f2288811bc370186vboxsync pPage, pPage->Core.Key, pPage->idx, pPage->enmKind, iUser, iUserTable));
bee80f3f77b15c166b7debd080a70e5231ba6751vboxsync pgmPoolTrackFreeUser(pPool, pPage, iUser, iUserTable);
55a158b986cee4c4ebe1a650e8727e1c6905e32evboxsync pgmPoolFlushPage(pPool, pPage); /* ASSUMES that VERR_PGM_POOL_CLEARED can be ignored here. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Makes one or more free page free.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VINF_SUCCESS on success.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VERR_PGM_POOL_FLUSHED if the pool was flushed.
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync * @param pPool The pool.
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync * @param iUser The user of the page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic int pgmPoolMakeMoreFreePages(PPGMPOOL pPool, uint16_t iUser)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolMakeMoreFreePages: iUser=%#x\n", iUser));
ea04f885ccd9a758072e975806b1275d9afaac06vboxsync * If the pool isn't full grown yet, expand it.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync int rc = CTXALLMID(VMM, CallHost)(pPool->CTXSUFF(pVM), VMMCALLHOST_PGM_POOL_GROW, 0);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Free one cached page.
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync * Flush the pool.
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync * If we have tracking enabled, it should be possible to come up with
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * a cheap replacement strategy...
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Allocates a page from the pool.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * This page may actually be a cached page and not in need of any processing
9c425bdea5f0991df62922b1584b805a86f2f898vboxsync * on the callers part.
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync * @returns VBox status code.
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync * @retval VINF_SUCCESS if a NEW page was allocated.
e4ea543752422f1139923e3e506c625b0a1827c5vboxsync * @retval VINF_PGM_CACHED_PAGE if a CACHED page was returned.
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync * @retval VERR_PGM_POOL_FLUSHED if the pool was flushed.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM The VM handle.
b40179b44fea65b72b2f226f62af1ed7bd3c48fcvboxsync * @param GCPhys The GC physical address of the page we're gonna shadow.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * For 4MB and 2MB PD entries, it's the first address the
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * shadow PT is covering.
2634ec5cbf8f1fa0a968cd4664ead6df1fed730dvboxsync * @param enmKind The kind of mapping.
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync * @param iUser The shadow page pool index of the user table.
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync * @param iUserTable The index into the user table (shadowed).
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync * @param ppPage Where to store the pointer to the page. NULL is stored here on failure.
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsyncint pgmPoolAlloc(PVM pVM, RTGCPHYS GCPhys, PGMPOOLKIND enmKind, uint16_t iUser, uint32_t iUserTable, PPPGMPOOLPAGE ppPage)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("pgmPoolAlloc: GCPhys=%VGp enmKind=%d iUser=%#x iUserTable=%#x\n", GCPhys, enmKind, iUser, iUserTable));
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync int rc2 = pgmPoolCacheAlloc(pPool, GCPhys, enmKind, iUser, iUserTable, ppPage);
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync LogFlow(("pgmPoolAlloc: cached returns %Vrc *ppPage=%p:{.Key=%VHp, .idx=%d}\n", rc2, *ppPage, (*ppPage)->Core.Key, (*ppPage)->idx));
c613f29bba8757289a5acf5a5dae7ee21b6b1ad5vboxsync * Allocate a new one.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertReleaseReturn(iNew != NIL_PGMPOOL_IDX, VERR_INTERNAL_ERROR);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* unlink the free head */
55a158b986cee4c4ebe1a650e8727e1c6905e32evboxsync * Initialize it.
55a158b986cee4c4ebe1a650e8727e1c6905e32evboxsync pPool->cUsedPages++; /* physical handler registration / pgmPoolTrackFlushGCPhysPTsSlow requirement. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pPage->fSeenNonGlobal = false; /* Set this to 'true' to disable this feature. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Insert into the tracking and cache. If this fails, free the page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync int rc3 = pgmPoolTrackInsert(pPool, pPage, GCPhys, iUser, iUserTable);
1b7f3a92e42fb9cabf96cf31c20481da466edf76vboxsync Log(("pgmPoolAlloc: returns %Vrc (Insert)\n", rc3));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync#endif /* PGMPOOL_WITH_USER_TRACKING */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Commit the allocation, clear the page and return.
75fca099c974cbbd48f132af1378c60232614760vboxsync LogFlow(("pgmPoolAlloc: returns %Vrc *ppPage=%p:{.Key=%VHp, .idx=%d, .fCached=%RTbool, .fMonitored=%RTbool}\n",
da936e0446fb2b56b813d5d938f1dfc6e4bf8b13vboxsync rc, pPage, pPage->Core.Key, pPage->idx, pPage->fCached, pPage->fMonitored));
da936e0446fb2b56b813d5d938f1dfc6e4bf8b13vboxsync * Frees a usage of a pool page.
4cad44a5f7cfa7db8d5fb255a1df3b3cd1687853vboxsync * @param pVM The VM handle.
5db1d52ffbcaa46c3d944c6c2d9c552306817d9avboxsync * @param HCPhys The HC physical address of the shadow page.
da936e0446fb2b56b813d5d938f1dfc6e4bf8b13vboxsync * @param iUser The shadow page pool index of the user table.
585f64d6f624f9e683321dabeb21b0eb2e6aa473vboxsync * @param iUserTable The index into the user table (shadowed).
54fe68d807196dc565de24055996e634ee40ee92vboxsyncvoid pgmPoolFree(PVM pVM, RTHCPHYS HCPhys, uint16_t iUser, uint32_t iUserTable)
da936e0446fb2b56b813d5d938f1dfc6e4bf8b13vboxsync LogFlow(("pgmPoolFree: HCPhys=%VHp iUser=%#x iUserTable=%#x\n", HCPhys, iUser, iUserTable));
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync pgmPoolFreeByPage(pPool, pgmPoolGetPage(pPool, HCPhys), iUser, iUserTable);
61fa69e2bc9fc9e7490feed1c020273f3ddb238dvboxsync * Gets a in-use page in the pool by it's physical address.
da936e0446fb2b56b813d5d938f1dfc6e4bf8b13vboxsync * @returns Pointer to the page.
ec588a4ac8429a8b6c744544818b3ce3b2c75690vboxsync * @param pVM The VM handle.
ec588a4ac8429a8b6c744544818b3ce3b2c75690vboxsync * @param HCPhys The HC physical address of the shadow page.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @remark This function will NEVER return NULL. It will assert if HCPhys is invalid.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncPPGMPOOLPAGE pgmPoolGetPageByHCPhys(PVM pVM, RTHCPHYS HCPhys)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /** @todo profile this! */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPGMPOOLPAGE pPage = pgmPoolGetPage(pPool, HCPhys);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log3(("pgmPoolGetPageByHCPhys: HCPhys=%VHp -> %p:{.idx=%d .GCPhys=%VGp .enmKind=%d}\n",
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync HCPhys, pPage, pPage->idx, pPage->GCPhys, pPage->enmKind));
4b02cd4133ae0d8e4732c57274a59358e418349cvboxsync * Flushes the entire cache.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * It will assert a global CR3 flush (FF) and assumes the caller is aware of this
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * and execute this CR3 flush.
00599f6d39cc25ca39845c2433cd75de7b9f6971vboxsync * @param pPool The pool.