PGMAllPool.cpp revision f37fdece8b97c04e00923c1ec924706682f89b2b
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/* $Id$ */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/** @file
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * PGM Shadow Page Pool.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/*
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync *
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * available from http://www.virtualbox.org. This file is free software;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * you can redistribute it and/or modify it under the terms of the GNU
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * General Public License (GPL) as published by the Free Software
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync *
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * additional information or have any questions.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync/*******************************************************************************
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync* Header Files *
7b9f0c34e9ea328981c99e97054bdf8684d9d620vboxsync*******************************************************************************/
9e7e0b61d29309a0ed7af9472c8d6d865f9e8a2dvboxsync#define LOG_GROUP LOG_GROUP_PGM_POOL
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#include <VBox/pgm.h>
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#include <VBox/mm.h>
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#include <VBox/em.h>
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync#include <VBox/cpum.h>
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync#ifdef IN_RC
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync# include <VBox/patm.h>
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif
b1cc3e87518139898395f96974ecff9e6bf228fbvboxsync#include "PGMInternal.h"
b1cc3e87518139898395f96974ecff9e6bf228fbvboxsync#include <VBox/vm.h>
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync#include <VBox/disopcode.h>
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync#include <VBox/hwacc_vmx.h>
388b6b190a5407548753b7fde12fa58134ec3563vboxsync
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync#include <VBox/log.h>
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#include <VBox/err.h>
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync#include <iprt/asm.h>
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync/*******************************************************************************
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync* Internal Functions *
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync*******************************************************************************/
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync__BEGIN_DECLS
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsyncstatic void pgmPoolFlushAllInt(PPGMPOOL pPool);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#ifdef PGMPOOL_WITH_USER_TRACKING
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsyncDECLINLINE(unsigned) pgmPoolTrackGetShadowEntrySize(PGMPOOLKIND enmKind);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsyncDECLINLINE(unsigned) pgmPoolTrackGetGuestEntrySize(PGMPOOLKIND enmKind);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsyncstatic void pgmPoolTrackDeref(PPGMPOOL pPool, PPGMPOOLPAGE pPage);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync#endif
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync#ifdef PGMPOOL_WITH_GCPHYS_TRACKING
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsyncstatic void pgmPoolTracDerefGCPhysHint(PPGMPOOL pPool, PPGMPOOLPAGE pPage, RTHCPHYS HCPhys, RTGCPHYS GCPhysHint);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync#endif
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync#ifdef PGMPOOL_WITH_CACHE
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsyncstatic int pgmPoolTrackAddUser(PPGMPOOL pPool, PPGMPOOLPAGE pPage, uint16_t iUser, uint32_t iUserTable);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync#endif
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync#ifdef PGMPOOL_WITH_MONITORING
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsyncstatic void pgmPoolMonitorModifiedRemove(PPGMPOOL pPool, PPGMPOOLPAGE pPage);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync#endif
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync#ifndef IN_RING3
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsyncDECLEXPORT(int) pgmPoolAccessHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPHYS GCPhysFault, void *pvUser);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync#endif
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync__END_DECLS
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync/**
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * Checks if the specified page pool kind is for a 4MB or 2MB guest page.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync *
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * @returns true if it's the shadow of a 4MB or 2MB guest page, otherwise false.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * @param enmKind The page kind.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsyncDECLINLINE(bool) pgmPoolIsBigPage(PGMPOOLKIND enmKind)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync{
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync switch (enmKind)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync {
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_4MB:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_4MB:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_2MB:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync return true;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync default:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync return false;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync }
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync}
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync#if defined(IN_RC) || defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0)
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync/**
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync * Maps a pool page into the current context.
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync *
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync * @returns Pointer to the mapping.
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync * @param pVM The VM handle.
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync * @param pPage The page to map.
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync */
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsyncvoid *pgmPoolMapPage(PVM pVM, PPGMPOOLPAGE pPage)
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync{
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync /* general pages. */
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync if (pPage->idx >= PGMPOOL_IDX_FIRST)
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync {
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync Assert(pPage->idx < pVM->pgm.s.CTX_SUFF(pPool)->cCurPages);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync void *pv;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync int rc = PGMDynMapHCPage(pVM, pPage->Core.Key, &pv);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync AssertReleaseRC(rc);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync return pv;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync }
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync /* special pages. */
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync# ifdef IN_RC
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync switch (pPage->idx)
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync {
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync case PGMPOOL_IDX_PD:
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync return pVM->pgm.s.pShw32BitPdRC;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync case PGMPOOL_IDX_PAE_PD:
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync case PGMPOOL_IDX_PAE_PD_0:
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync return pVM->pgm.s.apShwPaePDsRC[0];
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync case PGMPOOL_IDX_PAE_PD_1:
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync return pVM->pgm.s.apShwPaePDsRC[1];
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync case PGMPOOL_IDX_PAE_PD_2:
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync return pVM->pgm.s.apShwPaePDsRC[2];
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync case PGMPOOL_IDX_PAE_PD_3:
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync return pVM->pgm.s.apShwPaePDsRC[3];
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync case PGMPOOL_IDX_PDPT:
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync return pVM->pgm.s.pShwPaePdptRC;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync default:
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync AssertReleaseMsgFailed(("Invalid index %d\n", pPage->idx));
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync return NULL;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync }
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync# else /* VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0 */
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync RTHCPHYS HCPhys;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync switch (pPage->idx)
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync {
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync case PGMPOOL_IDX_PD:
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync HCPhys = pVM->pgm.s.HCPhysShw32BitPD;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync break;
581f0625e43a928987623d7cf59e1b1ab61ca6c8vboxsync case PGMPOOL_IDX_PAE_PD:
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync case PGMPOOL_IDX_PAE_PD_0:
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync HCPhys = pVM->pgm.s.aHCPhysPaePDs[0];
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync break;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync case PGMPOOL_IDX_PAE_PD_1:
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync HCPhys = pVM->pgm.s.aHCPhysPaePDs[1];
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync break;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync case PGMPOOL_IDX_PAE_PD_2:
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync HCPhys = pVM->pgm.s.aHCPhysPaePDs[2];
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync break;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync case PGMPOOL_IDX_PAE_PD_3:
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync HCPhys = pVM->pgm.s.aHCPhysPaePDs[3];
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync break;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync case PGMPOOL_IDX_PDPT:
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync HCPhys = pVM->pgm.s.HCPhysPaePDPT;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync break;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync default:
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AssertReleaseMsgFailed(("Invalid index %d\n", pPage->idx));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync return NULL;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync void *pv;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync int rc = PGMDynMapHCPage(pVM, pPage->Core.Key, &pv);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AssertReleaseRC(rc);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync return pv;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync# endif /* VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0 */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync}
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync#endif /* IN_RC || VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0 */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync#ifdef PGMPOOL_WITH_MONITORING
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync/**
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * Determin the size of a write instruction.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * @returns number of bytes written.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * @param pDis The disassembler state.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsyncstatic unsigned pgmPoolDisasWriteSize(PDISCPUSTATE pDis)
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /*
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * This is very crude and possibly wrong for some opcodes,
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync * but since it's not really supposed to be called we can
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * probably live with that.
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync */
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync return DISGetParamSize(pDis, &pDis->param1);
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync}
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync/**
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * Flushes a chain of pages sharing the same access monitor.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync *
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * @returns VBox status code suitable for scheduling.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * @param pPool The pool.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * @param pPage A page in the chain.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsyncint pgmPoolMonitorChainFlush(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync{
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync LogFlow(("pgmPoolMonitorChainFlush: Flush page %RGp type=%d\n", pPage->GCPhys, pPage->enmKind));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync /*
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * Find the list head.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync uint16_t idx = pPage->idx;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync if (pPage->iMonitoredPrev != NIL_PGMPOOL_IDX)
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync {
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync while (pPage->iMonitoredPrev != NIL_PGMPOOL_IDX)
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync idx = pPage->iMonitoredPrev;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync Assert(idx != pPage->idx);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync pPage = &pPool->aPages[idx];
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync }
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync }
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync /*
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * Iterate the list flushing each shadow page.
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync */
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync int rc = VINF_SUCCESS;
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync for (;;)
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync {
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync idx = pPage->iMonitoredNext;
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync Assert(idx != pPage->idx);
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync if (pPage->idx >= PGMPOOL_IDX_FIRST)
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync {
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync int rc2 = pgmPoolFlushPage(pPool, pPage);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync if (rc2 == VERR_PGM_POOL_CLEARED && rc == VINF_SUCCESS)
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync rc = VINF_PGM_SYNC_CR3;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync }
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync /* next */
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync if (idx == NIL_PGMPOOL_IDX)
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync break;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync pPage = &pPool->aPages[idx];
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync }
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync return rc;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync}
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync/**
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync * Wrapper for getting the current context pointer to the entry being modified.
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync *
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync * @returns Pointer to the current context mapping of the entry.
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync * @param pPool The pool.
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync * @param pvFault The fault virtual address.
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync * @param GCPhysFault The fault physical address.
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync * @param cbEntry The entry size.
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync */
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync#ifdef IN_RING3
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsyncDECLINLINE(const void *) pgmPoolMonitorGCPtr2CCPtr(PPGMPOOL pPool, RTHCPTR pvFault, RTGCPHYS GCPhysFault, const unsigned cbEntry)
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync#else
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsyncDECLINLINE(const void *) pgmPoolMonitorGCPtr2CCPtr(PPGMPOOL pPool, RTGCPTR pvFault, RTGCPHYS GCPhysFault, const unsigned cbEntry)
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync#endif
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync{
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync#ifdef IN_RC
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync return (const void *)((RTGCUINTPTR)pvFault & ~(RTGCUINTPTR)(cbEntry - 1));
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync#elif defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0)
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync void *pvRet;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync int rc = PGMDynMapGCPageOff(pPool->pVMR0, GCPhysFault & ~(RTGCPHYS)(cbEntry - 1), &pvRet);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync AssertFatalRCSuccess(rc);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync return pvRet;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync#elif defined(IN_RING0)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync void *pvRet;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync int rc = pgmRamGCPhys2HCPtr(&pPool->pVMR0->pgm.s, GCPhysFault & ~(RTGCPHYS)(cbEntry - 1), &pvRet);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync AssertFatalRCSuccess(rc);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync return pvRet;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync#elif defined(IN_RING3)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync return (RTHCPTR)((uintptr_t)pvFault & ~(RTHCUINTPTR)(cbEntry - 1));
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync#else
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync# error "huh?"
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync#endif
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/**
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Process shadow entries before they are changed by the guest.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync *
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * For PT entries we will clear them. For PD entries, we'll simply check
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * for mapping conflicts and set the SyncCR3 FF if found.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync *
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync * @param pPool The pool.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * @param pPage The head page.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * @param GCPhysFault The guest physical fault address.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * @param uAddress In R0 and GC this is the guest context fault address (flat).
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * In R3 this is the host context 'fault' address.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * @param pCpu The disassembler state for figuring out the write size.
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync * This need not be specified if the caller knows we won't do cross entry accesses.
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync */
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync#ifdef IN_RING3
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsyncvoid pgmPoolMonitorChainChanging(PPGMPOOL pPool, PPGMPOOLPAGE pPage, RTGCPHYS GCPhysFault, RTHCPTR pvAddress, PDISCPUSTATE pCpu)
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync#else
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsyncvoid pgmPoolMonitorChainChanging(PPGMPOOL pPool, PPGMPOOLPAGE pPage, RTGCPHYS GCPhysFault, RTGCPTR pvAddress, PDISCPUSTATE pCpu)
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync#endif
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync{
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync Assert(pPage->iMonitoredPrev == NIL_PGMPOOL_IDX);
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync const unsigned off = GCPhysFault & PAGE_OFFSET_MASK;
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync const unsigned cbWrite = (pCpu) ? pgmPoolDisasWriteSize(pCpu) : 0;
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync LogFlow(("pgmPoolMonitorChainChanging: %RGv phys=%RGp kind=%d cbWrite=%d\n", pvAddress, GCPhysFault, pPage->enmKind, cbWrite));
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync for (;;)
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync {
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync union
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync {
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync void *pv;
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync PX86PT pPT;
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync PX86PTPAE pPTPae;
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync PX86PD pPD;
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync PX86PDPAE pPDPae;
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync PX86PDPT pPDPT;
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync PX86PML4 pPML4;
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync } uShw;
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync uShw.pv = PGMPOOL_PAGE_2_PTR(pPool->CTX_SUFF(pVM), pPage);
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync switch (pPage->enmKind)
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync {
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_PT:
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync {
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync const unsigned iShw = off / sizeof(X86PTE);
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync if (uShw.pPT->a[iShw].n.u1Present)
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync {
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync# ifdef PGMPOOL_WITH_GCPHYS_TRACKING
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync PCX86PTE pGstPte = (PCX86PTE)pgmPoolMonitorGCPtr2CCPtr(pPool, pvAddress, GCPhysFault, sizeof(*pGstPte));
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync Log4(("pgmPoolMonitorChainChanging 32_32: deref %016RX64 GCPhys %08RX32\n", uShw.pPT->a[iShw].u & X86_PTE_PAE_PG_MASK, pGstPte->u & X86_PTE_PG_MASK));
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync pgmPoolTracDerefGCPhysHint(pPool, pPage,
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync uShw.pPT->a[iShw].u & X86_PTE_PAE_PG_MASK,
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pGstPte->u & X86_PTE_PG_MASK);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync# endif
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync uShw.pPT->a[iShw].u = 0;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync break;
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* page/2 sized */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_PT:
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (!((off ^ pPage->GCPhys) & (PAGE_SIZE / 2)))
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync {
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync const unsigned iShw = (off / sizeof(X86PTE)) & (X86_PG_PAE_ENTRIES - 1);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (uShw.pPTPae->a[iShw].n.u1Present)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync# ifdef PGMPOOL_WITH_GCPHYS_TRACKING
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync PCX86PTE pGstPte = (PCX86PTE)pgmPoolMonitorGCPtr2CCPtr(pPool, pvAddress, GCPhysFault, sizeof(*pGstPte));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Log4(("pgmPoolMonitorChainChanging pae_32: deref %016RX64 GCPhys %08RX32\n", uShw.pPT->a[iShw].u & X86_PTE_PAE_PG_MASK, pGstPte->u & X86_PTE_PG_MASK));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pgmPoolTracDerefGCPhysHint(pPool, pPage,
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync uShw.pPTPae->a[iShw].u & X86_PTE_PAE_PG_MASK,
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync pGstPte->u & X86_PTE_PG_MASK);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync# endif
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync uShw.pPTPae->a[iShw].u = 0;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync break;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_PT:
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync const unsigned iShw = off / sizeof(X86PTEPAE);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (uShw.pPTPae->a[iShw].n.u1Present)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync# ifdef PGMPOOL_WITH_GCPHYS_TRACKING
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync PCX86PTEPAE pGstPte = (PCX86PTEPAE)pgmPoolMonitorGCPtr2CCPtr(pPool, pvAddress, GCPhysFault, sizeof(*pGstPte));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Log4(("pgmPoolMonitorChainChanging pae: deref %016RX64 GCPhys %016RX64\n", uShw.pPTPae->a[iShw].u & X86_PTE_PAE_PG_MASK, pGstPte->u & X86_PTE_PAE_PG_MASK));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pgmPoolTracDerefGCPhysHint(pPool, pPage,
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync uShw.pPTPae->a[iShw].u & X86_PTE_PAE_PG_MASK,
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pGstPte->u & X86_PTE_PAE_PG_MASK);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync# endif
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync uShw.pPTPae->a[iShw].u = 0;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* paranoia / a bit assumptive. */
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync if ( pCpu
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync && (off & 7)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync && (off & 7) + cbWrite > sizeof(X86PTEPAE))
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync const unsigned iShw2 = (off + cbWrite - 1) / sizeof(X86PTEPAE);
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsync AssertReturnVoid(iShw2 < RT_ELEMENTS(uShw.pPTPae->a));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (uShw.pPTPae->a[iShw2].n.u1Present)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync# ifdef PGMPOOL_WITH_GCPHYS_TRACKING
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync PCX86PTEPAE pGstPte = (PCX86PTEPAE)pgmPoolMonitorGCPtr2CCPtr(pPool, pvAddress, GCPhysFault, sizeof(*pGstPte));
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync Log4(("pgmPoolMonitorChainChanging pae: deref %016RX64 GCPhys %016RX64\n", uShw.pPTPae->a[iShw2].u & X86_PTE_PAE_PG_MASK, pGstPte->u & X86_PTE_PAE_PG_MASK));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pgmPoolTracDerefGCPhysHint(pPool, pPage,
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync uShw.pPTPae->a[iShw2].u & X86_PTE_PAE_PG_MASK,
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pGstPte->u & X86_PTE_PAE_PG_MASK);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync# endif
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync uShw.pPTPae->a[iShw2].u = 0;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync break;
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync case PGMPOOLKIND_ROOT_32BIT_PD:
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync const unsigned iShw = off / sizeof(X86PTE); // ASSUMING 32-bit guest paging!
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (uShw.pPD->a[iShw].u & PGM_PDFLAGS_MAPPING)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTX_SUFF(pVM)->pgm.s));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync VM_FF_SET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw=%#x!\n", iShw));
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync }
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync /* paranoia / a bit assumptive. */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync else if ( pCpu
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync && (off & 3)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync && (off & 3) + cbWrite > sizeof(X86PTE))
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync const unsigned iShw2 = (off + cbWrite - 1) / sizeof(X86PTE);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if ( iShw2 != iShw
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync && iShw2 < RT_ELEMENTS(uShw.pPD->a)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync && uShw.pPD->a[iShw2].u & PGM_PDFLAGS_MAPPING)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync {
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTX_SUFF(pVM)->pgm.s));
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync VM_FF_SET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw2=%#x!\n", iShw2));
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync }
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync }
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync#if 0 /* useful when running PGMAssertCR3(), a bit too troublesome for general use (TLBs). */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync if ( uShw.pPD->a[iShw].n.u1Present
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync && !VM_FF_ISSET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3))
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync {
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync LogFlow(("pgmPoolMonitorChainChanging: iShw=%#x: %RX32 -> freeing it!\n", iShw, uShw.pPD->a[iShw].u));
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync# ifdef IN_RC /* TLB load - we're pushing things a bit... */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync ASMProbeReadByte(pvAddress);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync# endif
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync pgmPoolFree(pPool->CTX_SUFF(pVM), uShw.pPD->a[iShw].u & X86_PDE_PG_MASK, pPage->idx, iShw);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync uShw.pPD->a[iShw].u = 0;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync }
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync#endif
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync break;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync }
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync case PGMPOOLKIND_ROOT_PAE_PD:
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync unsigned iShw = (off / sizeof(X86PTE)) * 2; // ASSUMING 32-bit guest paging!
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync for (unsigned i = 0; i < 2; i++, iShw++)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if ((uShw.pPDPae->a[iShw].u & (PGM_PDFLAGS_MAPPING | X86_PDE_P)) == (PGM_PDFLAGS_MAPPING | X86_PDE_P))
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTX_SUFF(pVM)->pgm.s));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync VM_FF_SET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw=%#x!\n", iShw));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync /* paranoia / a bit assumptive. */
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync else if ( pCpu
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync && (off & 3)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync && (off & 3) + cbWrite > 4)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync const unsigned iShw2 = iShw + 2;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if ( iShw2 < RT_ELEMENTS(uShw.pPDPae->a)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync && (uShw.pPDPae->a[iShw2].u & (PGM_PDFLAGS_MAPPING | X86_PDE_P)) == (PGM_PDFLAGS_MAPPING | X86_PDE_P))
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTX_SUFF(pVM)->pgm.s));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync VM_FF_SET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3);
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw2=%#x!\n", iShw2));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#if 0 /* useful when running PGMAssertCR3(), a bit too troublesome for general use (TLBs). */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if ( uShw.pPDPae->a[iShw].n.u1Present
7e8ef90d3160234df0f254131b87af4243d79476vboxsync && !VM_FF_ISSET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3))
7e8ef90d3160234df0f254131b87af4243d79476vboxsync {
7e8ef90d3160234df0f254131b87af4243d79476vboxsync LogFlow(("pgmPoolMonitorChainChanging: iShw=%#x: %RX64 -> freeing it!\n", iShw, uShw.pPDPae->a[iShw].u));
7e8ef90d3160234df0f254131b87af4243d79476vboxsync# ifdef IN_RC /* TLB load - we're pushing things a bit... */
7e8ef90d3160234df0f254131b87af4243d79476vboxsync ASMProbeReadByte(pvAddress);
7e8ef90d3160234df0f254131b87af4243d79476vboxsync# endif
7e8ef90d3160234df0f254131b87af4243d79476vboxsync pgmPoolFree(pPool->CTX_SUFF(pVM), uShw.pPDPae->a[iShw].u & X86_PDE_PAE_PG_MASK, pPage->idx, iShw);
7e8ef90d3160234df0f254131b87af4243d79476vboxsync uShw.pPDPae->a[iShw].u = 0;
7e8ef90d3160234df0f254131b87af4243d79476vboxsync }
7e8ef90d3160234df0f254131b87af4243d79476vboxsync#endif
7e8ef90d3160234df0f254131b87af4243d79476vboxsync }
7e8ef90d3160234df0f254131b87af4243d79476vboxsync break;
7e8ef90d3160234df0f254131b87af4243d79476vboxsync }
7e8ef90d3160234df0f254131b87af4243d79476vboxsync
7e8ef90d3160234df0f254131b87af4243d79476vboxsync case PGMPOOLKIND_PAE_PD_FOR_PAE_PD:
7e8ef90d3160234df0f254131b87af4243d79476vboxsync {
7e8ef90d3160234df0f254131b87af4243d79476vboxsync const unsigned iShw = off / sizeof(X86PDEPAE);
7e8ef90d3160234df0f254131b87af4243d79476vboxsync if (uShw.pPDPae->a[iShw].u & PGM_PDFLAGS_MAPPING)
7e8ef90d3160234df0f254131b87af4243d79476vboxsync {
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTX_SUFF(pVM)->pgm.s));
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync VM_FF_SET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3);
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw=%#x!\n", iShw));
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync }
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync#ifdef PGMPOOL_INVALIDATE_UPPER_SHADOW_TABLE_ENTRIES
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync /*
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync * Causes trouble when the guest uses a PDE to refer to the whole page table level
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync * structure. (Invalidate here; faults later on when it tries to change the page
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync * table entries -> recheck; probably only applies to the RC case.)
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync */
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync else
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync {
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync if (uShw.pPDPae->a[iShw].n.u1Present)
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync {
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync LogFlow(("pgmPoolMonitorChainChanging: pae pd iShw=%#x: %RX64 -> freeing it!\n", iShw, uShw.pPDPae->a[iShw].u));
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync pgmPoolFree(pPool->CTX_SUFF(pVM),
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync uShw.pPDPae->a[iShw].u & X86_PDE_PAE_PG_MASK,
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync /* Note: hardcoded PAE implementation dependency */
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync (pPage->enmKind == PGMPOOLKIND_PAE_PD_FOR_PAE_PD) ? PGMPOOL_IDX_PAE_PD : pPage->idx,
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync (pPage->enmKind == PGMPOOLKIND_PAE_PD_FOR_PAE_PD) ? iShw + (pPage->idx - PGMPOOL_IDX_PAE_PD_0) * X86_PG_PAE_ENTRIES : iShw);
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync uShw.pPDPae->a[iShw].u = 0;
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* paranoia / a bit assumptive. */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if ( pCpu
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync && (off & 7)
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync && (off & 7) + cbWrite > sizeof(X86PDEPAE))
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync const unsigned iShw2 = (off + cbWrite - 1) / sizeof(X86PDEPAE);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AssertReturnVoid(iShw2 < RT_ELEMENTS(uShw.pPDPae->a));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if ( iShw2 != iShw
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync && uShw.pPDPae->a[iShw2].u & PGM_PDFLAGS_MAPPING)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTX_SUFF(pVM)->pgm.s));
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync VM_FF_SET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw2=%#x!\n", iShw2));
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#ifdef PGMPOOL_INVALIDATE_UPPER_SHADOW_TABLE_ENTRIES
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync else if (uShw.pPDPae->a[iShw2].n.u1Present)
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync {
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlow(("pgmPoolMonitorChainChanging: pae pd iShw2=%#x: %RX64 -> freeing it!\n", iShw2, uShw.pPDPae->a[iShw2].u));
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync pgmPoolFree(pPool->CTX_SUFF(pVM),
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync uShw.pPDPae->a[iShw2].u & X86_PDE_PAE_PG_MASK,
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync /* Note: hardcoded PAE implementation dependency */
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync (pPage->enmKind == PGMPOOLKIND_PAE_PD_FOR_PAE_PD) ? PGMPOOL_IDX_PAE_PD : pPage->idx,
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync (pPage->enmKind == PGMPOOLKIND_PAE_PD_FOR_PAE_PD) ? iShw2 + (pPage->idx - PGMPOOL_IDX_PAE_PD_0) * X86_PG_PAE_ENTRIES : iShw2);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync uShw.pPDPae->a[iShw2].u = 0;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync break;
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync }
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync case PGMPOOLKIND_ROOT_PDPT:
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync {
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync /*
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync * Hopefully this doesn't happen very often:
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync * - touching unused parts of the page
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync * - messing with the bits of pd pointers without changing the physical address
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync */
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync const unsigned iShw = off / sizeof(X86PDPE);
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync if (iShw < X86_PG_PAE_PDPE_ENTRIES) /* don't use RT_ELEMENTS(uShw.pPDPT->a), because that's for long mode only */
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync {
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync if (uShw.pPDPT->a[iShw].u & PGM_PLXFLAGS_MAPPING)
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync {
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTX_SUFF(pVM)->pgm.s));
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync VM_FF_SET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3);
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw=%#x!\n", iShw));
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync }
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync /* paranoia / a bit assumptive. */
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync else if ( pCpu
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync && (off & 7)
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync && (off & 7) + cbWrite > sizeof(X86PDPE))
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync {
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync const unsigned iShw2 = (off + cbWrite - 1) / sizeof(X86PDPE);
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync if ( iShw2 != iShw
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync && iShw2 < X86_PG_PAE_PDPE_ENTRIES
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync && uShw.pPDPT->a[iShw2].u & PGM_PLXFLAGS_MAPPING)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTX_SUFF(pVM)->pgm.s));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync VM_FF_SET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw2=%#x!\n", iShw2));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync }
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync break;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#ifndef IN_RC
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync case PGMPOOLKIND_64BIT_PD_FOR_64BIT_PD:
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Assert(pPage->enmKind == PGMPOOLKIND_64BIT_PD_FOR_64BIT_PD);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync const unsigned iShw = off / sizeof(X86PDEPAE);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (uShw.pPDPae->a[iShw].u & PGM_PDFLAGS_MAPPING)
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTX_SUFF(pVM)->pgm.s));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync VM_FF_SET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw=%#x!\n", iShw));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync else
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (uShw.pPDPae->a[iShw].n.u1Present)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync LogFlow(("pgmPoolMonitorChainChanging: pae pd iShw=%#x: %RX64 -> freeing it!\n", iShw, uShw.pPDPae->a[iShw].u));
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync pgmPoolFree(pPool->CTX_SUFF(pVM),
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync uShw.pPDPae->a[iShw].u & X86_PDE_PAE_PG_MASK,
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pPage->idx,
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync iShw);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync uShw.pPDPae->a[iShw].u = 0;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* paranoia / a bit assumptive. */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if ( pCpu
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync && (off & 7)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync && (off & 7) + cbWrite > sizeof(X86PDEPAE))
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync const unsigned iShw2 = (off + cbWrite - 1) / sizeof(X86PDEPAE);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AssertReturnVoid(iShw2 < RT_ELEMENTS(uShw.pPDPae->a));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if ( iShw2 != iShw
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync && uShw.pPDPae->a[iShw2].u & PGM_PDFLAGS_MAPPING)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTX_SUFF(pVM)->pgm.s));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync VM_FF_SET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw2=%#x!\n", iShw2));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync else
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync if (uShw.pPDPae->a[iShw2].n.u1Present)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync LogFlow(("pgmPoolMonitorChainChanging: pae pd iShw2=%#x: %RX64 -> freeing it!\n", iShw2, uShw.pPDPae->a[iShw2].u));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pgmPoolFree(pPool->CTX_SUFF(pVM),
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync uShw.pPDPae->a[iShw2].u & X86_PDE_PAE_PG_MASK,
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pPage->idx,
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync iShw2);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync uShw.pPDPae->a[iShw2].u = 0;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync break;
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_64BIT_PDPT:
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /*
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * Hopefully this doesn't happen very often:
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * - messing with the bits of pd pointers without changing the physical address
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync */
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync if (!VM_FF_ISSET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3))
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync {
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync const unsigned iShw = off / sizeof(X86PDPE);
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync if (uShw.pPDPT->a[iShw].n.u1Present)
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync {
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync LogFlow(("pgmPoolMonitorChainChanging: pdpt iShw=%#x: %RX64 -> freeing it!\n", iShw, uShw.pPDPT->a[iShw].u));
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync pgmPoolFree(pPool->CTX_SUFF(pVM), uShw.pPDPT->a[iShw].u & X86_PDPE_PG_MASK, pPage->idx, iShw);
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync uShw.pPDPT->a[iShw].u = 0;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync }
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync /* paranoia / a bit assumptive. */
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync if ( pCpu
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync && (off & 7)
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync && (off & 7) + cbWrite > sizeof(X86PDPE))
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync {
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync const unsigned iShw2 = (off + cbWrite - 1) / sizeof(X86PDPE);
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync if (uShw.pPDPT->a[iShw2].n.u1Present)
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync {
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync LogFlow(("pgmPoolMonitorChainChanging: pdpt iShw2=%#x: %RX64 -> freeing it!\n", iShw2, uShw.pPDPT->a[iShw2].u));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync pgmPoolFree(pPool->CTX_SUFF(pVM), uShw.pPDPT->a[iShw2].u & X86_PDPE_PG_MASK, pPage->idx, iShw2);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync uShw.pPDPT->a[iShw2].u = 0;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync }
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync }
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync }
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync break;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync }
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync case PGMPOOLKIND_64BIT_PML4_FOR_64BIT_PML4:
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync {
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /*
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * Hopefully this doesn't happen very often:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * - messing with the bits of pd pointers without changing the physical address
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync if (!VM_FF_ISSET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3))
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync {
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync const unsigned iShw = off / sizeof(X86PDPE);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync if (uShw.pPML4->a[iShw].n.u1Present)
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync {
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync LogFlow(("pgmPoolMonitorChainChanging: pml4 iShw=%#x: %RX64 -> freeing it!\n", iShw, uShw.pPML4->a[iShw].u));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync pgmPoolFree(pPool->CTX_SUFF(pVM), uShw.pPML4->a[iShw].u & X86_PML4E_PG_MASK, pPage->idx, iShw);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync uShw.pPML4->a[iShw].u = 0;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync }
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync /* paranoia / a bit assumptive. */
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync if ( pCpu
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync && (off & 7)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync && (off & 7) + cbWrite > sizeof(X86PDPE))
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync {
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync const unsigned iShw2 = (off + cbWrite - 1) / sizeof(X86PML4E);
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync if (uShw.pPML4->a[iShw2].n.u1Present)
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync {
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync LogFlow(("pgmPoolMonitorChainChanging: pml4 iShw2=%#x: %RX64 -> freeing it!\n", iShw2, uShw.pPML4->a[iShw2].u));
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync pgmPoolFree(pPool->CTX_SUFF(pVM), uShw.pPML4->a[iShw2].u & X86_PML4E_PG_MASK, pPage->idx, iShw2);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync uShw.pPML4->a[iShw2].u = 0;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync }
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync }
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync }
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync break;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync }
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync#endif /* IN_RING0 */
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync default:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync AssertFatalMsgFailed(("enmKind=%d\n", pPage->enmKind));
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync }
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync /* next */
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync if (pPage->iMonitoredNext == NIL_PGMPOOL_IDX)
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync return;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync pPage = &pPool->aPages[pPage->iMonitoredNext];
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync }
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync}
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync# ifndef IN_RING3
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync/**
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * Checks if a access could be a fork operation in progress.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync *
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync * Meaning, that the guest is setuping up the parent process for Copy-On-Write.
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync *
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * @returns true if it's likly that we're forking, otherwise false.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * @param pPool The pool.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * @param pCpu The disassembled instruction.
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync * @param offFault The access offset.
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync */
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsyncDECLINLINE(bool) pgmPoolMonitorIsForking(PPGMPOOL pPool, PDISCPUSTATE pCpu, unsigned offFault)
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync{
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync /*
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync * i386 linux is using btr to clear X86_PTE_RW.
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync * The functions involved are (2.6.16 source inspection):
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync * clear_bit
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync * ptep_set_wrprotect
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync * copy_one_pte
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync * copy_pte_range
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync * copy_pmd_range
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync * copy_pud_range
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync * copy_page_range
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync * dup_mmap
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync * dup_mm
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * copy_mm
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync * copy_process
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync * do_fork
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync */
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync if ( pCpu->pCurInstr->opcode == OP_BTR
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync && !(offFault & 4)
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync /** @todo Validate that the bit index is X86_PTE_RW. */
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync )
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync {
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,Fork));
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync return true;
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync }
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync return false;
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync}
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync/**
5366e994777f9d9391cf809dc77610f57270d75dvboxsync * Determine whether the page is likely to have been reused.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync *
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * @returns true if we consider the page as being reused for a different purpose.
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync * @returns false if we consider it to still be a paging page.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * @param pVM VM Handle.
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync * @param pPage The page in question.
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync * @param pRegFrame Trap register frame.
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync * @param pCpu The disassembly info for the faulting instruction.
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync * @param pvFault The fault address.
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync *
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync * @remark The REP prefix check is left to the caller because of STOSD/W.
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync */
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsyncDECLINLINE(bool) pgmPoolMonitorIsReused(PVM pVM, PPGMPOOLPAGE pPage, PCPUMCTXCORE pRegFrame, PDISCPUSTATE pCpu, RTGCPTR pvFault)
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync{
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync#ifndef IN_RC
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync /** @todo could make this general, faulting close to rsp should be safe reuse heuristic. */
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync if ( HWACCMHasPendingIrq(pVM)
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync && (pRegFrame->rsp - pvFault) < 32)
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync {
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync /* Fault caused by stack writes while trying to inject an interrupt event. */
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync Log(("pgmPoolMonitorIsReused: reused %RGv for interrupt stack (rsp=%RGv).\n", pvFault, pRegFrame->rsp));
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync return true;
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync }
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync#else
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync NOREF(pVM); NOREF(pvFault);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync#endif
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync switch (pCpu->pCurInstr->opcode)
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync {
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync /* call implies the actual push of the return address faulted */
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync case OP_CALL:
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync Log4(("pgmPoolMonitorIsReused: CALL\n"));
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync return true;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync case OP_PUSH:
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync Log4(("pgmPoolMonitorIsReused: PUSH\n"));
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync return true;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync case OP_PUSHF:
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync Log4(("pgmPoolMonitorIsReused: PUSHF\n"));
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync return true;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync case OP_PUSHA:
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync Log4(("pgmPoolMonitorIsReused: PUSHA\n"));
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync return true;
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync case OP_FXSAVE:
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync Log4(("pgmPoolMonitorIsReused: FXSAVE\n"));
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync return true;
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync case OP_MOVNTI: /* solaris - block_zero_no_xmm */
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync Log4(("pgmPoolMonitorIsReused: MOVNTI\n"));
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync return true;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync case OP_MOVNTDQ: /* solaris - hwblkclr & hwblkpagecopy */
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync Log4(("pgmPoolMonitorIsReused: MOVNTDQ\n"));
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync return true;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync case OP_MOVSWD:
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync case OP_STOSWD:
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync if ( pCpu->prefix == (PREFIX_REP|PREFIX_REX)
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync && pRegFrame->rcx >= 0x40
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync )
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync {
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync Assert(pCpu->mode == CPUMODE_64BIT);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync Log(("pgmPoolMonitorIsReused: OP_STOSQ\n"));
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync return true;
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync }
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync return false;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync }
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync if ( (pCpu->param1.flags & USE_REG_GEN32)
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync && (pCpu->param1.base.reg_gen == USE_REG_ESP))
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync {
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync Log4(("pgmPoolMonitorIsReused: ESP\n"));
ca3db470494a8b6eaec69ea37468a5cda65e2da8vboxsync return true;
ca3db470494a8b6eaec69ea37468a5cda65e2da8vboxsync }
ca3db470494a8b6eaec69ea37468a5cda65e2da8vboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync //if (pPage->fCR3Mix)
ca3db470494a8b6eaec69ea37468a5cda65e2da8vboxsync // return false;
ca3db470494a8b6eaec69ea37468a5cda65e2da8vboxsync return false;
ca3db470494a8b6eaec69ea37468a5cda65e2da8vboxsync}
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync
ca3db470494a8b6eaec69ea37468a5cda65e2da8vboxsync
ca3db470494a8b6eaec69ea37468a5cda65e2da8vboxsync/**
ca3db470494a8b6eaec69ea37468a5cda65e2da8vboxsync * Flushes the page being accessed.
ca3db470494a8b6eaec69ea37468a5cda65e2da8vboxsync *
ca3db470494a8b6eaec69ea37468a5cda65e2da8vboxsync * @returns VBox status code suitable for scheduling.
ca3db470494a8b6eaec69ea37468a5cda65e2da8vboxsync * @param pVM The VM handle.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * @param pPool The pool.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * @param pPage The pool page (head).
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * @param pCpu The disassembly of the write instruction.
ca3db470494a8b6eaec69ea37468a5cda65e2da8vboxsync * @param pRegFrame The trap register frame.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * @param GCPhysFault The fault address as guest physical address.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * @param pvFault The fault address.
ca3db470494a8b6eaec69ea37468a5cda65e2da8vboxsync */
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsyncstatic int pgmPoolAccessHandlerFlush(PVM pVM, PPGMPOOL pPool, PPGMPOOLPAGE pPage, PDISCPUSTATE pCpu,
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, RTGCPTR pvFault)
ca3db470494a8b6eaec69ea37468a5cda65e2da8vboxsync{
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync /*
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * First, do the flushing.
ca3db470494a8b6eaec69ea37468a5cda65e2da8vboxsync */
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync int rc = pgmPoolMonitorChainFlush(pPool, pPage);
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /*
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync * Emulate the instruction (xp/w2k problem, requires pc/cr2/sp detection).
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync */
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync uint32_t cbWritten;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync int rc2 = EMInterpretInstructionCPU(pVM, pCpu, pRegFrame, pvFault, &cbWritten);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync if (RT_SUCCESS(rc2))
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync pRegFrame->rip += pCpu->opsize;
ca3db470494a8b6eaec69ea37468a5cda65e2da8vboxsync else if (rc2 == VERR_EM_INTERPRETER)
ca3db470494a8b6eaec69ea37468a5cda65e2da8vboxsync {
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync#ifdef IN_RC
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync if (PATMIsPatchGCAddr(pVM, (RTRCPTR)pRegFrame->eip))
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync {
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync LogFlow(("pgmPoolAccessHandlerPTWorker: Interpretation failed for patch code %04x:%RGv, ignoring.\n",
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync pRegFrame->cs, (RTGCPTR)pRegFrame->eip));
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync rc = VINF_SUCCESS;
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync STAM_COUNTER_INC(&pPool->StatMonitorRZIntrFailPatch2);
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync }
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync else
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync#endif
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync {
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync rc = VINF_EM_RAW_EMULATE_INSTR;
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,EmulateInstr));
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync }
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync }
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync else
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync rc = rc2;
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync /* See use in pgmPoolAccessHandlerSimple(). */
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync PGM_INVL_GUEST_TLBS();
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync LogFlow(("pgmPoolAccessHandlerPT: returns %Rrc (flushed)\n", rc));
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync return rc;
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync}
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync/**
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * Handles the STOSD write accesses.
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync *
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * @returns VBox status code suitable for scheduling.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * @param pVM The VM handle.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * @param pPool The pool.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * @param pPage The pool page (head).
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync * @param pCpu The disassembly of the write instruction.
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync * @param pRegFrame The trap register frame.
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync * @param GCPhysFault The fault address as guest physical address.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * @param pvFault The fault address.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsyncDECLINLINE(int) pgmPoolAccessHandlerSTOSD(PVM pVM, PPGMPOOL pPool, PPGMPOOLPAGE pPage, PDISCPUSTATE pCpu,
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, RTGCPTR pvFault)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync{
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync Assert(pCpu->mode == CPUMODE_32BIT);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /*
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * Increment the modification counter and insert it into the list
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * of modified pages the first time.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync if (!pPage->cModifications++)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync pgmPoolMonitorModifiedInsert(pPool, pPage);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /*
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * Execute REP STOSD.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync *
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * This ASSUMES that we're not invoked by Trap0e on in a out-of-sync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * write situation, meaning that it's safe to write here.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync RTGCUINTPTR pu32 = (RTGCUINTPTR)pvFault;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync while (pRegFrame->ecx)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync {
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync pgmPoolMonitorChainChanging(pPool, pPage, GCPhysFault, (RTGCPTR)pu32, NULL);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync#ifdef IN_RC
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync *(uint32_t *)pu32 = pRegFrame->eax;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync#else
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync PGMPhysSimpleWriteGCPhys(pVM, GCPhysFault, &pRegFrame->eax, 4);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync#endif
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync pu32 += 4;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync GCPhysFault += 4;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync pRegFrame->edi += 4;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync pRegFrame->ecx--;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync }
cc1ef2ef9bbc6a0ff964928d61b7298e5bfcce5fvboxsync pRegFrame->rip += pCpu->opsize;
cc1ef2ef9bbc6a0ff964928d61b7298e5bfcce5fvboxsync
cc1ef2ef9bbc6a0ff964928d61b7298e5bfcce5fvboxsync /* See use in pgmPoolAccessHandlerSimple(). */
cc1ef2ef9bbc6a0ff964928d61b7298e5bfcce5fvboxsync PGM_INVL_GUEST_TLBS();
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync LogFlow(("pgmPoolAccessHandlerSTOSD: returns\n"));
cc1ef2ef9bbc6a0ff964928d61b7298e5bfcce5fvboxsync return VINF_SUCCESS;
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync}
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync/**
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync * Handles the simple write accesses.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync *
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * @returns VBox status code suitable for scheduling.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * @param pVM The VM handle.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * @param pPool The pool.
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync * @param pPage The pool page (head).
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * @param pCpu The disassembly of the write instruction.
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync * @param pRegFrame The trap register frame.
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync * @param GCPhysFault The fault address as guest physical address.
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync * @param pvFault The fault address.
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync */
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsyncDECLINLINE(int) pgmPoolAccessHandlerSimple(PVM pVM, PPGMPOOL pPool, PPGMPOOLPAGE pPage, PDISCPUSTATE pCpu,
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, RTGCPTR pvFault)
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync{
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync /*
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * Increment the modification counter and insert it into the list
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * of modified pages the first time.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync if (!pPage->cModifications++)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync pgmPoolMonitorModifiedInsert(pPool, pPage);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /*
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * Clear all the pages. ASSUMES that pvFault is readable.
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync pgmPoolMonitorChainChanging(pPool, pPage, GCPhysFault, pvFault, pCpu);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /*
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * Interpret the instruction.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync uint32_t cb;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync int rc = EMInterpretInstructionCPU(pVM, pCpu, pRegFrame, pvFault, &cb);
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync if (RT_SUCCESS(rc))
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync pRegFrame->rip += pCpu->opsize;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync else if (rc == VERR_EM_INTERPRETER)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync {
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync LogFlow(("pgmPoolAccessHandlerPTWorker: Interpretation failed for %04x:%RGv - opcode=%d\n",
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync pRegFrame->cs, (RTGCPTR)pRegFrame->rip, pCpu->pCurInstr->opcode));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync rc = VINF_EM_RAW_EMULATE_INSTR;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,EmulateInstr));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync }
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /*
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * Quick hack, with logging enabled we're getting stale
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * code TLBs but no data TLB for EIP and crash in EMInterpretDisasOne.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * Flushing here is BAD and expensive, I think EMInterpretDisasOne will
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * have to be fixed to support this. But that'll have to wait till next week.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync *
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * An alternative is to keep track of the changed PTEs together with the
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * GCPhys from the guest PT. This may proove expensive though.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync *
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * At the moment, it's VITAL that it's done AFTER the instruction interpreting
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * because we need the stale TLBs in some cases (XP boot). This MUST be fixed properly!
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync PGM_INVL_GUEST_TLBS();
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync LogFlow(("pgmPoolAccessHandlerSimple: returns %Rrc cb=%d\n", rc, cb));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync return rc;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync}
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync/**
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * \#PF Handler callback for PT write accesses.
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync *
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync * @returns VBox status code (appropriate for GC return).
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync * @param pVM VM Handle.
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync * @param uErrorCode CPU Error code.
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync * @param pRegFrame Trap register frame.
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync * NULL on DMA and other non CPU access.
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync * @param pvFault The fault address (cr2).
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * @param GCPhysFault The GC physical address corresponding to pvFault.
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync * @param pvUser User argument.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsyncDECLEXPORT(int) pgmPoolAccessHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPHYS GCPhysFault, void *pvUser)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync{
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync STAM_PROFILE_START(&pVM->pgm.s.CTX_SUFF(pPool)->CTX_SUFF_Z(StatMonitor), a);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync PPGMPOOL pPool = pVM->pgm.s.CTX_SUFF(pPool);
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync PPGMPOOLPAGE pPage = (PPGMPOOLPAGE)pvUser;
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync LogFlow(("pgmPoolAccessHandler: pvFault=%RGv pPage=%p:{.idx=%d} GCPhysFault=%RGp\n", pvFault, pPage, pPage->idx, GCPhysFault));
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync
15c6c4ce0082362b8b81e15c3605f2d3aca69a21vboxsync /*
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * We should ALWAYS have the list head as user parameter. This
15c6c4ce0082362b8b81e15c3605f2d3aca69a21vboxsync * is because we use that page to record the changes.
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync */
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync Assert(pPage->iMonitoredPrev == NIL_PGMPOOL_IDX);
15c6c4ce0082362b8b81e15c3605f2d3aca69a21vboxsync
15c6c4ce0082362b8b81e15c3605f2d3aca69a21vboxsync /*
15c6c4ce0082362b8b81e15c3605f2d3aca69a21vboxsync * Disassemble the faulting instruction.
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync */
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync DISCPUSTATE Cpu;
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync int rc = EMInterpretDisasOne(pVM, pRegFrame, &Cpu, NULL);
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync AssertRCReturn(rc, rc);
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync /*
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync * Check if it's worth dealing with.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync */
004d74842597dacc4009803171296dfcf9398c69vboxsync bool fReused = false;
004d74842597dacc4009803171296dfcf9398c69vboxsync if ( ( pPage->cModifications < 48 /** @todo #define */ /** @todo need to check that it's not mapping EIP. */ /** @todo adjust this! */
004d74842597dacc4009803171296dfcf9398c69vboxsync || pPage->fCR3Mix)
004d74842597dacc4009803171296dfcf9398c69vboxsync && !(fReused = pgmPoolMonitorIsReused(pVM, pPage, pRegFrame, &Cpu, pvFault))
004d74842597dacc4009803171296dfcf9398c69vboxsync && !pgmPoolMonitorIsForking(pPool, &Cpu, GCPhysFault & PAGE_OFFSET_MASK))
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync {
004d74842597dacc4009803171296dfcf9398c69vboxsync /*
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * Simple instructions, no REP prefix.
004d74842597dacc4009803171296dfcf9398c69vboxsync */
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync if (!(Cpu.prefix & (PREFIX_REP | PREFIX_REPNE)))
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync {
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync rc = pgmPoolAccessHandlerSimple(pVM, pPool, pPage, &Cpu, pRegFrame, GCPhysFault, pvFault);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync STAM_PROFILE_STOP_EX(&pVM->pgm.s.CTX_SUFF(pPool)->CTX_SUFF_Z(StatMonitor), &pPool->CTX_MID_Z(StatMonitor,Handled), a);
004d74842597dacc4009803171296dfcf9398c69vboxsync return rc;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync }
004d74842597dacc4009803171296dfcf9398c69vboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync /*
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * Windows is frequently doing small memset() operations (netio test 4k+).
004d74842597dacc4009803171296dfcf9398c69vboxsync * We have to deal with these or we'll kill the cache and performance.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync */
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync if ( Cpu.pCurInstr->opcode == OP_STOSWD
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync && CPUMGetGuestCPL(pVM, pRegFrame) == 0
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync && pRegFrame->ecx <= 0x20
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync && pRegFrame->ecx * 4 <= PAGE_SIZE - ((uintptr_t)pvFault & PAGE_OFFSET_MASK)
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync && !((uintptr_t)pvFault & 3)
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync && (pRegFrame->eax == 0 || pRegFrame->eax == 0x80) /* the two values observed. */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync && Cpu.mode == CPUMODE_32BIT
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync && Cpu.opmode == CPUMODE_32BIT
004d74842597dacc4009803171296dfcf9398c69vboxsync && Cpu.addrmode == CPUMODE_32BIT
004d74842597dacc4009803171296dfcf9398c69vboxsync && Cpu.prefix == PREFIX_REP
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync && !pRegFrame->eflags.Bits.u1DF
5366e994777f9d9391cf809dc77610f57270d75dvboxsync )
5366e994777f9d9391cf809dc77610f57270d75dvboxsync {
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync rc = pgmPoolAccessHandlerSTOSD(pVM, pPool, pPage, &Cpu, pRegFrame, GCPhysFault, pvFault);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync STAM_PROFILE_STOP_EX(&pVM->pgm.s.CTX_SUFF(pPool)->CTX_SUFF_Z(StatMonitor), &pPool->CTX_MID_Z(StatMonitor,RepStosd), a);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync return rc;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync }
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /* REP prefix, don't bother. */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,RepPrefix));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync Log4(("pgmPoolAccessHandler: eax=%#x ecx=%#x edi=%#x esi=%#x rip=%RGv opcode=%d prefix=%#x\n",
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync pRegFrame->eax, pRegFrame->ecx, pRegFrame->edi, pRegFrame->esi, (RTGCPTR)pRegFrame->rip, Cpu.pCurInstr->opcode, Cpu.prefix));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync }
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /*
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * Not worth it, so flush it.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync *
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * If we considered it to be reused, don't to back to ring-3
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * to emulate failed instructions since we usually cannot
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * interpret then. This may be a bit risky, in which case
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * the reuse detection must be fixed.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync rc = pgmPoolAccessHandlerFlush(pVM, pPool, pPage, &Cpu, pRegFrame, GCPhysFault, pvFault);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync if (rc == VINF_EM_RAW_EMULATE_INSTR && fReused)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync rc = VINF_SUCCESS;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync STAM_PROFILE_STOP_EX(&pVM->pgm.s.CTX_SUFF(pPool)->CTX_SUFF_Z(StatMonitor), &pPool->CTX_MID_Z(StatMonitor,FlushPage), a);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync return rc;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync}
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync# endif /* !IN_RING3 */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync#endif /* PGMPOOL_WITH_MONITORING */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync#ifdef PGMPOOL_WITH_CACHE
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync/**
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * Inserts a page into the GCPhys hash table.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync *
5366e994777f9d9391cf809dc77610f57270d75dvboxsync * @param pPool The pool.
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync * @param pPage The page.
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync */
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsyncDECLINLINE(void) pgmPoolHashInsert(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync{
5366e994777f9d9391cf809dc77610f57270d75dvboxsync Log3(("pgmPoolHashInsert: %RGp\n", pPage->GCPhys));
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync Assert(pPage->GCPhys != NIL_RTGCPHYS); Assert(pPage->iNext == NIL_PGMPOOL_IDX);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync uint16_t iHash = PGMPOOL_HASH(pPage->GCPhys);
5366e994777f9d9391cf809dc77610f57270d75dvboxsync pPage->iNext = pPool->aiHash[iHash];
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync pPool->aiHash[iHash] = pPage->idx;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync}
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync/**
d8e12fa5dd1c35282b98cb165e42b6b395cf971bvboxsync * Removes a page from the GCPhys hash table.
d8e12fa5dd1c35282b98cb165e42b6b395cf971bvboxsync *
d8e12fa5dd1c35282b98cb165e42b6b395cf971bvboxsync * @param pPool The pool.
d8e12fa5dd1c35282b98cb165e42b6b395cf971bvboxsync * @param pPage The page.
d8e12fa5dd1c35282b98cb165e42b6b395cf971bvboxsync */
d8e12fa5dd1c35282b98cb165e42b6b395cf971bvboxsyncDECLINLINE(void) pgmPoolHashRemove(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
d8e12fa5dd1c35282b98cb165e42b6b395cf971bvboxsync{
d8e12fa5dd1c35282b98cb165e42b6b395cf971bvboxsync Log3(("pgmPoolHashRemove: %RGp\n", pPage->GCPhys));
5366e994777f9d9391cf809dc77610f57270d75dvboxsync uint16_t iHash = PGMPOOL_HASH(pPage->GCPhys);
15c6c4ce0082362b8b81e15c3605f2d3aca69a21vboxsync if (pPool->aiHash[iHash] == pPage->idx)
d8e12fa5dd1c35282b98cb165e42b6b395cf971bvboxsync pPool->aiHash[iHash] = pPage->iNext;
15c6c4ce0082362b8b81e15c3605f2d3aca69a21vboxsync else
15c6c4ce0082362b8b81e15c3605f2d3aca69a21vboxsync {
15c6c4ce0082362b8b81e15c3605f2d3aca69a21vboxsync uint16_t iPrev = pPool->aiHash[iHash];
d8e12fa5dd1c35282b98cb165e42b6b395cf971bvboxsync for (;;)
d8e12fa5dd1c35282b98cb165e42b6b395cf971bvboxsync {
d8e12fa5dd1c35282b98cb165e42b6b395cf971bvboxsync const int16_t i = pPool->aPages[iPrev].iNext;
d8e12fa5dd1c35282b98cb165e42b6b395cf971bvboxsync if (i == pPage->idx)
5366e994777f9d9391cf809dc77610f57270d75dvboxsync {
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync pPool->aPages[iPrev].iNext = pPage->iNext;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync break;
5366e994777f9d9391cf809dc77610f57270d75dvboxsync }
5366e994777f9d9391cf809dc77610f57270d75dvboxsync if (i == NIL_PGMPOOL_IDX)
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync {
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync AssertReleaseMsgFailed(("GCPhys=%RGp idx=%#x\n", pPage->GCPhys, pPage->idx));
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync break;
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync }
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync iPrev = i;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync }
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync }
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync pPage->iNext = NIL_PGMPOOL_IDX;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync}
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync/**
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * Frees up one cache page.
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync *
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync * @returns VBox status code.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * @retval VINF_SUCCESS on success.
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync * @retval VERR_PGM_POOL_CLEARED if the deregistration of a physical handler will cause a light weight pool flush.
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync * @param pPool The pool.
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync * @param iUser The user index.
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync */
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsyncstatic int pgmPoolCacheFreeOne(PPGMPOOL pPool, uint16_t iUser)
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync{
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync#ifndef IN_RC
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync const PVM pVM = pPool->CTX_SUFF(pVM);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync#endif
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync Assert(pPool->iAgeHead != pPool->iAgeTail); /* We shouldn't be here if there < 2 cached entries! */
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync STAM_COUNTER_INC(&pPool->StatCacheFreeUpOne);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync /*
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync * Select one page from the tail of the age list.
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync */
3ff8aa7d3c74cfbe8da5f77b8ea6c748cc79213avboxsync uint16_t iToFree = pPool->iAgeTail;
5366e994777f9d9391cf809dc77610f57270d75dvboxsync if (iToFree == iUser)
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync iToFree = pPool->aPages[iToFree].iAgePrev;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync/* This is the alternative to the SyncCR3 pgmPoolCacheUsed calls.
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync if (pPool->aPages[iToFree].iUserHead != NIL_PGMPOOL_USER_INDEX)
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync {
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync uint16_t i = pPool->aPages[iToFree].iAgePrev;
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync for (unsigned j = 0; j < 10 && i != NIL_PGMPOOL_USER_INDEX; j++, i = pPool->aPages[i].iAgePrev)
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync {
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync if (pPool->aPages[iToFree].iUserHead == NIL_PGMPOOL_USER_INDEX)
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync continue;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync iToFree = i;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync break;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync }
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync }
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync*/
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync Assert(iToFree != iUser);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync AssertRelease(iToFree != NIL_PGMPOOL_IDX);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync PPGMPOOLPAGE pPage = &pPool->aPages[iToFree];
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync /*
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync * Reject any attempts at flushing the currently active shadow CR3 mapping
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync */
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync if (PGMGetHyperCR3(pPool->CTX_SUFF(pVM)) == pPage->Core.Key)
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync {
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /* Refresh the cr3 mapping by putting it at the head of the age list. */
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync pgmPoolCacheUsed(pPool, pPage);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync return pgmPoolCacheFreeOne(pPool, iUser);
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync }
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync int rc = pgmPoolFlushPage(pPool, pPage);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync if (rc == VINF_SUCCESS)
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync PGM_INVL_GUEST_TLBS(); /* see PT handler. */
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync return rc;
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync}
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync/**
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync * Checks if a kind mismatch is really a page being reused
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync * or if it's just normal remappings.
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync *
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync * @returns true if reused and the cached page (enmKind1) should be flushed
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync * @returns false if not reused.
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync * @param enmKind1 The kind of the cached page.
40c1a23e86c79b24a917a43c186b2e54504d12c1vboxsync * @param enmKind2 The kind of the requested page.
40c1a23e86c79b24a917a43c186b2e54504d12c1vboxsync */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsyncstatic bool pgmPoolCacheReusedByKind(PGMPOOLKIND enmKind1, PGMPOOLKIND enmKind2)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync{
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync switch (enmKind1)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync {
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync /*
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * Never reuse them. There is no remapping in non-paging mode.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case PGMPOOLKIND_32BIT_PT_FOR_PHYS:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case PGMPOOLKIND_PAE_PT_FOR_PHYS:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_PHYS:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case PGMPOOLKIND_64BIT_PD_FOR_PHYS:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case PGMPOOLKIND_EPT_PDPT_FOR_PHYS:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case PGMPOOLKIND_EPT_PD_FOR_PHYS:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case PGMPOOLKIND_EPT_PT_FOR_PHYS:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync return true;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync /*
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * It's perfectly fine to reuse these, except for PAE and non-paging stuff.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_4MB:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_4MB:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_PT:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_PT:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case PGMPOOLKIND_PAE_PD_FOR_32BIT_PD:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync switch (enmKind2)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync {
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case PGMPOOLKIND_PAE_PD_FOR_PAE_PD:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_PT:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case PGMPOOLKIND_64BIT_PD_FOR_64BIT_PD:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_64BIT_PDPT:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case PGMPOOLKIND_64BIT_PML4_FOR_64BIT_PML4:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_2MB:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case PGMPOOLKIND_32BIT_PT_FOR_PHYS:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case PGMPOOLKIND_PAE_PT_FOR_PHYS:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_PHYS:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case PGMPOOLKIND_64BIT_PD_FOR_PHYS:
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync case PGMPOOLKIND_EPT_PDPT_FOR_PHYS:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case PGMPOOLKIND_EPT_PD_FOR_PHYS:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case PGMPOOLKIND_EPT_PT_FOR_PHYS:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync return true;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync default:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync return false;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync }
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync /*
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * It's perfectly fine to reuse these, except for PAE and non-paging stuff.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case PGMPOOLKIND_PAE_PD_FOR_PAE_PD:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_PT:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case PGMPOOLKIND_64BIT_PD_FOR_64BIT_PD:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_64BIT_PDPT:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case PGMPOOLKIND_64BIT_PML4_FOR_64BIT_PML4:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_2MB:
40c1a23e86c79b24a917a43c186b2e54504d12c1vboxsync switch (enmKind2)
40c1a23e86c79b24a917a43c186b2e54504d12c1vboxsync {
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_4MB:
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_4MB:
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_PT:
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_PT:
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync case PGMPOOLKIND_PAE_PD_FOR_32BIT_PD:
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync case PGMPOOLKIND_32BIT_PT_FOR_PHYS:
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync case PGMPOOLKIND_PAE_PT_FOR_PHYS:
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_PHYS:
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync case PGMPOOLKIND_64BIT_PD_FOR_PHYS:
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync case PGMPOOLKIND_EPT_PDPT_FOR_PHYS:
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync case PGMPOOLKIND_EPT_PD_FOR_PHYS:
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync case PGMPOOLKIND_EPT_PT_FOR_PHYS:
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync return true;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync default:
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync return false;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync }
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /*
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * These cannot be flushed, and it's common to reuse the PDs as PTs.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync */
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync case PGMPOOLKIND_ROOT_32BIT_PD:
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync case PGMPOOLKIND_ROOT_PAE_PD:
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync case PGMPOOLKIND_ROOT_PDPT:
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync case PGMPOOLKIND_ROOT_NESTED:
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync return false;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync default:
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync AssertFatalMsgFailed(("enmKind1=%d\n", enmKind1));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync }
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync}
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync/**
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * Attempts to satisfy a pgmPoolAlloc request from the cache.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync *
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * @returns VBox status code.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * @retval VINF_PGM_CACHED_PAGE on success.
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * @retval VERR_FILE_NOT_FOUND if not found.
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * @param pPool The pool.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * @param GCPhys The GC physical address of the page we're gonna shadow.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * @param enmKind The kind of mapping.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * @param iUser The shadow page pool index of the user table.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * @param iUserTable The index into the user table (shadowed).
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * @param ppPage Where to store the pointer to the page.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsyncstatic int pgmPoolCacheAlloc(PPGMPOOL pPool, RTGCPHYS GCPhys, PGMPOOLKIND enmKind, uint16_t iUser, uint32_t iUserTable, PPPGMPOOLPAGE ppPage)
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync{
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync#ifndef IN_RC
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync const PVM pVM = pPool->CTX_SUFF(pVM);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync#endif
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync /*
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * Look up the GCPhys in the hash.
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync */
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync unsigned i = pPool->aiHash[PGMPOOL_HASH(GCPhys)];
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync Log3(("pgmPoolCacheAlloc: %RGp kind %d iUser=%d iUserTable=%x SLOT=%d\n", GCPhys, enmKind, iUser, iUserTable, i));
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync if (i != NIL_PGMPOOL_IDX)
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync {
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync do
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync {
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync PPGMPOOLPAGE pPage = &pPool->aPages[i];
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync Log3(("pgmPoolCacheAlloc: slot %d found page %RGp\n", i, pPage->GCPhys));
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync if (pPage->GCPhys == GCPhys)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync {
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync if ((PGMPOOLKIND)pPage->enmKind == enmKind)
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync {
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync int rc = pgmPoolTrackAddUser(pPool, pPage, iUser, iUserTable);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync if (RT_SUCCESS(rc))
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync {
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync *ppPage = pPage;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync STAM_COUNTER_INC(&pPool->StatCacheHits);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync return VINF_PGM_CACHED_PAGE;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync }
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync return rc;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync }
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync /*
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * The kind is different. In some cases we should now flush the page
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * as it has been reused, but in most cases this is normal remapping
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * of PDs as PT or big pages using the GCPhys field in a slightly
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * different way than the other kinds.
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync */
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync if (pgmPoolCacheReusedByKind((PGMPOOLKIND)pPage->enmKind, enmKind))
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync {
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync STAM_COUNTER_INC(&pPool->StatCacheKindMismatches);
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync pgmPoolFlushPage(pPool, pPage); /* ASSUMES that VERR_PGM_POOL_CLEARED will be returned by pgmPoolTracInsert. */
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync PGM_INVL_GUEST_TLBS(); /* see PT handler. */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync break;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync }
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync }
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /* next */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync i = pPage->iNext;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync } while (i != NIL_PGMPOOL_IDX);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync }
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync Log3(("pgmPoolCacheAlloc: Missed GCPhys=%RGp enmKind=%d\n", GCPhys, enmKind));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync STAM_COUNTER_INC(&pPool->StatCacheMisses);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync return VERR_FILE_NOT_FOUND;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync}
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync/**
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync * Inserts a page into the cache.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync *
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * @param pPool The pool.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * @param pPage The cached page.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * @param fCanBeCached Set if the page is fit for caching from the caller's point of view.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsyncstatic void pgmPoolCacheInsert(PPGMPOOL pPool, PPGMPOOLPAGE pPage, bool fCanBeCached)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync{
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /*
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * Insert into the GCPhys hash if the page is fit for that.
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync */
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync Assert(!pPage->fCached);
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync if (fCanBeCached)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync {
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync pPage->fCached = true;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync pgmPoolHashInsert(pPool, pPage);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync Log3(("pgmPoolCacheInsert: Caching %p:{.Core=%RHp, .idx=%d, .enmKind=%d, GCPhys=%RGp}\n",
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync pPage, pPage->Core.Key, pPage->idx, pPage->enmKind, pPage->GCPhys));
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync STAM_COUNTER_INC(&pPool->StatCacheCacheable);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync }
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync else
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync {
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync Log3(("pgmPoolCacheInsert: Not caching %p:{.Core=%RHp, .idx=%d, .enmKind=%d, GCPhys=%RGp}\n",
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync pPage, pPage->Core.Key, pPage->idx, pPage->enmKind, pPage->GCPhys));
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync STAM_COUNTER_INC(&pPool->StatCacheUncacheable);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync }
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync /*
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync * Insert at the head of the age list.
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync */
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync pPage->iAgePrev = NIL_PGMPOOL_IDX;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync pPage->iAgeNext = pPool->iAgeHead;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync if (pPool->iAgeHead != NIL_PGMPOOL_IDX)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync pPool->aPages[pPool->iAgeHead].iAgePrev = pPage->idx;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync else
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync pPool->iAgeTail = pPage->idx;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync pPool->iAgeHead = pPage->idx;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync}
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync/**
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync * Flushes a cached page.
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync *
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync * @param pPool The pool.
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync * @param pPage The cached page.
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync */
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsyncstatic void pgmPoolCacheFlushPage(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync{
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync Log3(("pgmPoolCacheFlushPage: %RGp\n", pPage->GCPhys));
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync /*
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * Remove the page from the hash.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync */
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync if (pPage->fCached)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync {
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync pPage->fCached = false;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync pgmPoolHashRemove(pPool, pPage);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync }
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync else
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync Assert(pPage->iNext == NIL_PGMPOOL_IDX);
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync /*
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * Remove it from the age list.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync if (pPage->iAgeNext != NIL_PGMPOOL_IDX)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync pPool->aPages[pPage->iAgeNext].iAgePrev = pPage->iAgePrev;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync else
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync pPool->iAgeTail = pPage->iAgePrev;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync if (pPage->iAgePrev != NIL_PGMPOOL_IDX)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync pPool->aPages[pPage->iAgePrev].iAgeNext = pPage->iAgeNext;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync else
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync pPool->iAgeHead = pPage->iAgeNext;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync pPage->iAgeNext = NIL_PGMPOOL_IDX;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync pPage->iAgePrev = NIL_PGMPOOL_IDX;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync}
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync#endif /* PGMPOOL_WITH_CACHE */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync#ifdef PGMPOOL_WITH_MONITORING
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync/**
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * Looks for pages sharing the monitor.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync *
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * @returns Pointer to the head page.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * @returns NULL if not found.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * @param pPool The Pool
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * @param pNewPage The page which is going to be monitored.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsyncstatic PPGMPOOLPAGE pgmPoolMonitorGetPageByGCPhys(PPGMPOOL pPool, PPGMPOOLPAGE pNewPage)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync{
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync#ifdef PGMPOOL_WITH_CACHE
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync /*
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * Look up the GCPhys in the hash.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync RTGCPHYS GCPhys = pNewPage->GCPhys & ~(RTGCPHYS)(PAGE_SIZE - 1);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync unsigned i = pPool->aiHash[PGMPOOL_HASH(GCPhys)];
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync if (i == NIL_PGMPOOL_IDX)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync return NULL;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync do
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync {
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync PPGMPOOLPAGE pPage = &pPool->aPages[i];
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync if ( pPage->GCPhys - GCPhys < PAGE_SIZE
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync && pPage != pNewPage)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync {
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync switch (pPage->enmKind)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync {
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_PT:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_PT:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_PT:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case PGMPOOLKIND_PAE_PD_FOR_32BIT_PD:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case PGMPOOLKIND_PAE_PD_FOR_PAE_PD:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case PGMPOOLKIND_64BIT_PD_FOR_64BIT_PD:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_64BIT_PDPT:
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync case PGMPOOLKIND_64BIT_PML4_FOR_64BIT_PML4:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case PGMPOOLKIND_ROOT_32BIT_PD:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case PGMPOOLKIND_ROOT_PAE_PD:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case PGMPOOLKIND_ROOT_PDPT:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync {
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync /* find the head */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync while (pPage->iMonitoredPrev != NIL_PGMPOOL_IDX)
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync {
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync Assert(pPage->iMonitoredPrev != pPage->idx);
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync pPage = &pPool->aPages[pPage->iMonitoredPrev];
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync }
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync return pPage;
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync }
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync /* ignore, no monitoring. */
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_4MB:
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_2MB:
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_4MB:
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync case PGMPOOLKIND_32BIT_PT_FOR_PHYS:
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync case PGMPOOLKIND_PAE_PT_FOR_PHYS:
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_PHYS:
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync case PGMPOOLKIND_64BIT_PD_FOR_PHYS:
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync case PGMPOOLKIND_EPT_PDPT_FOR_PHYS:
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync case PGMPOOLKIND_EPT_PD_FOR_PHYS:
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync case PGMPOOLKIND_EPT_PT_FOR_PHYS:
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync case PGMPOOLKIND_ROOT_NESTED:
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync break;
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync default:
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync AssertFatalMsgFailed(("enmKind=%d idx=%d\n", pPage->enmKind, pPage->idx));
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync }
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync }
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync /* next */
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync i = pPage->iNext;
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync } while (i != NIL_PGMPOOL_IDX);
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync#endif
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync return NULL;
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync}
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync/**
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync * Enabled write monitoring of a guest page.
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync *
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync * @returns VBox status code.
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync * @retval VINF_SUCCESS on success.
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * @retval VERR_PGM_POOL_CLEARED if the registration of the physical handler will cause a light weight pool flush.
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * @param pPool The pool.
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync * @param pPage The cached page.
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync */
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsyncstatic int pgmPoolMonitorInsert(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync{
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync LogFlow(("pgmPoolMonitorInsert %RGp\n", pPage->GCPhys & ~(RTGCPHYS)(PAGE_SIZE - 1)));
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync /*
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync * Filter out the relevant kinds.
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync */
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync switch (pPage->enmKind)
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync {
5366e994777f9d9391cf809dc77610f57270d75dvboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_PT:
5366e994777f9d9391cf809dc77610f57270d75dvboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_PT:
5366e994777f9d9391cf809dc77610f57270d75dvboxsync case PGMPOOLKIND_PAE_PD_FOR_PAE_PD:
5366e994777f9d9391cf809dc77610f57270d75dvboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_PT:
5366e994777f9d9391cf809dc77610f57270d75dvboxsync case PGMPOOLKIND_64BIT_PD_FOR_64BIT_PD:
5366e994777f9d9391cf809dc77610f57270d75dvboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_64BIT_PDPT:
5366e994777f9d9391cf809dc77610f57270d75dvboxsync case PGMPOOLKIND_64BIT_PML4_FOR_64BIT_PML4:
5366e994777f9d9391cf809dc77610f57270d75dvboxsync case PGMPOOLKIND_ROOT_PDPT:
5366e994777f9d9391cf809dc77610f57270d75dvboxsync break;
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync
cc1ef2ef9bbc6a0ff964928d61b7298e5bfcce5fvboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_4MB:
cc1ef2ef9bbc6a0ff964928d61b7298e5bfcce5fvboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_4MB:
5366e994777f9d9391cf809dc77610f57270d75dvboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_2MB:
5366e994777f9d9391cf809dc77610f57270d75dvboxsync case PGMPOOLKIND_32BIT_PT_FOR_PHYS:
5366e994777f9d9391cf809dc77610f57270d75dvboxsync case PGMPOOLKIND_PAE_PT_FOR_PHYS:
5366e994777f9d9391cf809dc77610f57270d75dvboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_PHYS:
5366e994777f9d9391cf809dc77610f57270d75dvboxsync case PGMPOOLKIND_64BIT_PD_FOR_PHYS:
5366e994777f9d9391cf809dc77610f57270d75dvboxsync case PGMPOOLKIND_EPT_PDPT_FOR_PHYS:
5366e994777f9d9391cf809dc77610f57270d75dvboxsync case PGMPOOLKIND_EPT_PD_FOR_PHYS:
5366e994777f9d9391cf809dc77610f57270d75dvboxsync case PGMPOOLKIND_EPT_PT_FOR_PHYS:
5366e994777f9d9391cf809dc77610f57270d75dvboxsync case PGMPOOLKIND_ROOT_NESTED:
5366e994777f9d9391cf809dc77610f57270d75dvboxsync /* Nothing to monitor here. */
5366e994777f9d9391cf809dc77610f57270d75dvboxsync return VINF_SUCCESS;
5366e994777f9d9391cf809dc77610f57270d75dvboxsync
5366e994777f9d9391cf809dc77610f57270d75dvboxsync case PGMPOOLKIND_ROOT_32BIT_PD:
cc1ef2ef9bbc6a0ff964928d61b7298e5bfcce5fvboxsync case PGMPOOLKIND_ROOT_PAE_PD:
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync#ifdef PGMPOOL_WITH_MIXED_PT_CR3
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync break;
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync#endif
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync case PGMPOOLKIND_PAE_PD_FOR_32BIT_PD:
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync default:
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync AssertFatalMsgFailed(("This can't happen! enmKind=%d\n", pPage->enmKind));
7e8ef90d3160234df0f254131b87af4243d79476vboxsync }
7e8ef90d3160234df0f254131b87af4243d79476vboxsync
7e8ef90d3160234df0f254131b87af4243d79476vboxsync /*
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync * Install handler.
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync */
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync int rc;
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync PPGMPOOLPAGE pPageHead = pgmPoolMonitorGetPageByGCPhys(pPool, pPage);
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync if (pPageHead)
e2489bd9ef063ae006feaebc3318ffa4143f6e16vboxsync {
e2489bd9ef063ae006feaebc3318ffa4143f6e16vboxsync Assert(pPageHead != pPage); Assert(pPageHead->iMonitoredNext != pPage->idx);
e2489bd9ef063ae006feaebc3318ffa4143f6e16vboxsync Assert(pPageHead->iMonitoredPrev != pPage->idx);
e2489bd9ef063ae006feaebc3318ffa4143f6e16vboxsync pPage->iMonitoredPrev = pPageHead->idx;
e2489bd9ef063ae006feaebc3318ffa4143f6e16vboxsync pPage->iMonitoredNext = pPageHead->iMonitoredNext;
e2489bd9ef063ae006feaebc3318ffa4143f6e16vboxsync if (pPageHead->iMonitoredNext != NIL_PGMPOOL_IDX)
e2489bd9ef063ae006feaebc3318ffa4143f6e16vboxsync pPool->aPages[pPageHead->iMonitoredNext].iMonitoredPrev = pPage->idx;
e2489bd9ef063ae006feaebc3318ffa4143f6e16vboxsync pPageHead->iMonitoredNext = pPage->idx;
e2489bd9ef063ae006feaebc3318ffa4143f6e16vboxsync rc = VINF_SUCCESS;
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync }
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync else
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync {
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync Assert(pPage->iMonitoredNext == NIL_PGMPOOL_IDX); Assert(pPage->iMonitoredPrev == NIL_PGMPOOL_IDX);
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync PVM pVM = pPool->CTX_SUFF(pVM);
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync const RTGCPHYS GCPhysPage = pPage->GCPhys & ~(RTGCPHYS)(PAGE_SIZE - 1);
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync rc = PGMHandlerPhysicalRegisterEx(pVM, PGMPHYSHANDLERTYPE_PHYSICAL_WRITE,
cc1ef2ef9bbc6a0ff964928d61b7298e5bfcce5fvboxsync GCPhysPage, GCPhysPage + (PAGE_SIZE - 1),
cc1ef2ef9bbc6a0ff964928d61b7298e5bfcce5fvboxsync pPool->pfnAccessHandlerR3, MMHyperCCToR3(pVM, pPage),
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync pPool->pfnAccessHandlerR0, MMHyperCCToR0(pVM, pPage),
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync pPool->pfnAccessHandlerRC, MMHyperCCToRC(pVM, pPage),
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync pPool->pszAccessHandler);
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync /** @todo we should probably deal with out-of-memory conditions here, but for now increasing
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync * the heap size should suffice. */
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync AssertFatalRC(rc);
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync if (pVM->pgm.s.fSyncFlags & PGM_SYNC_CLEAR_PGM_POOL)
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync rc = VERR_PGM_POOL_CLEARED;
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync }
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync pPage->fMonitored = true;
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync return rc;
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync}
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync/**
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync * Disables write monitoring of a guest page.
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync *
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync * @returns VBox status code.
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync * @retval VINF_SUCCESS on success.
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync * @retval VERR_PGM_POOL_CLEARED if the deregistration of the physical handler will cause a light weight pool flush.
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync * @param pPool The pool.
6b9d50a0f466bd5a61458ed53925480ab28a3c17vboxsync * @param pPage The cached page.
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsyncstatic int pgmPoolMonitorFlush(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync{
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync /*
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync * Filter out the relevant kinds.
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync */
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync switch (pPage->enmKind)
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync {
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_PT:
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_PT:
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync case PGMPOOLKIND_PAE_PD_FOR_PAE_PD:
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_PT:
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync case PGMPOOLKIND_64BIT_PD_FOR_64BIT_PD:
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_64BIT_PDPT:
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync case PGMPOOLKIND_64BIT_PML4_FOR_64BIT_PML4:
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync case PGMPOOLKIND_ROOT_PDPT:
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync break;
cc1ef2ef9bbc6a0ff964928d61b7298e5bfcce5fvboxsync
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_4MB:
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_4MB:
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_2MB:
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync case PGMPOOLKIND_32BIT_PT_FOR_PHYS:
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync case PGMPOOLKIND_PAE_PT_FOR_PHYS:
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_PHYS:
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync case PGMPOOLKIND_64BIT_PD_FOR_PHYS:
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync case PGMPOOLKIND_EPT_PDPT_FOR_PHYS:
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync case PGMPOOLKIND_EPT_PD_FOR_PHYS:
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync case PGMPOOLKIND_EPT_PT_FOR_PHYS:
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync case PGMPOOLKIND_ROOT_NESTED:
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync /* Nothing to monitor here. */
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync return VINF_SUCCESS;
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync
ccbdc11833996cb9f3be7868f1ebaefcacafb94dvboxsync case PGMPOOLKIND_ROOT_32BIT_PD:
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync case PGMPOOLKIND_ROOT_PAE_PD:
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync#ifdef PGMPOOL_WITH_MIXED_PT_CR3
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync break;
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync#endif
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync case PGMPOOLKIND_PAE_PD_FOR_32BIT_PD:
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync default:
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync AssertFatalMsgFailed(("This can't happen! enmKind=%d\n", pPage->enmKind));
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync }
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync /*
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync * Remove the page from the monitored list or uninstall it if last.
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync */
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync const PVM pVM = pPool->CTX_SUFF(pVM);
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync int rc;
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync if ( pPage->iMonitoredNext != NIL_PGMPOOL_IDX
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync || pPage->iMonitoredPrev != NIL_PGMPOOL_IDX)
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync {
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync if (pPage->iMonitoredPrev == NIL_PGMPOOL_IDX)
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync {
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync PPGMPOOLPAGE pNewHead = &pPool->aPages[pPage->iMonitoredNext];
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync pNewHead->iMonitoredPrev = NIL_PGMPOOL_IDX;
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync pNewHead->fCR3Mix = pPage->fCR3Mix;
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync rc = PGMHandlerPhysicalChangeCallbacks(pVM, pPage->GCPhys & ~(RTGCPHYS)(PAGE_SIZE - 1),
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync pPool->pfnAccessHandlerR3, MMHyperCCToR3(pVM, pNewHead),
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync pPool->pfnAccessHandlerR0, MMHyperCCToR0(pVM, pNewHead),
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync pPool->pfnAccessHandlerRC, MMHyperCCToRC(pVM, pNewHead),
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync pPool->pszAccessHandler);
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync AssertFatalRCSuccess(rc);
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync pPage->iMonitoredNext = NIL_PGMPOOL_IDX;
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync }
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync else
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync {
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync pPool->aPages[pPage->iMonitoredPrev].iMonitoredNext = pPage->iMonitoredNext;
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync if (pPage->iMonitoredNext != NIL_PGMPOOL_IDX)
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync {
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync pPool->aPages[pPage->iMonitoredNext].iMonitoredPrev = pPage->iMonitoredPrev;
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync pPage->iMonitoredNext = NIL_PGMPOOL_IDX;
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync }
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync pPage->iMonitoredPrev = NIL_PGMPOOL_IDX;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync rc = VINF_SUCCESS;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync }
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync }
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync else
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync {
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync rc = PGMHandlerPhysicalDeregister(pVM, pPage->GCPhys & ~(RTGCPHYS)(PAGE_SIZE - 1));
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync AssertFatalRC(rc);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync if (pVM->pgm.s.fSyncFlags & PGM_SYNC_CLEAR_PGM_POOL)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync rc = VERR_PGM_POOL_CLEARED;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync }
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync pPage->fMonitored = false;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /*
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * Remove it from the list of modified pages (if in it).
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync pgmPoolMonitorModifiedRemove(pPool, pPage);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync return rc;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync}
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync# ifdef PGMPOOL_WITH_MIXED_PT_CR3
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync/**
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * Set or clear the fCR3Mix attribute in a chain of monitored pages.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync *
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * @param pPool The Pool.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * @param pPage A page in the chain.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * @param fCR3Mix The new fCR3Mix value.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsyncstatic void pgmPoolMonitorChainChangeCR3Mix(PPGMPOOL pPool, PPGMPOOLPAGE pPage, bool fCR3Mix)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync{
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync /* current */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync pPage->fCR3Mix = fCR3Mix;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync /* before */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync int16_t idx = pPage->iMonitoredPrev;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync while (idx != NIL_PGMPOOL_IDX)
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync {
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync pPool->aPages[idx].fCR3Mix = fCR3Mix;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync idx = pPool->aPages[idx].iMonitoredPrev;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync }
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync /* after */
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync idx = pPage->iMonitoredNext;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync while (idx != NIL_PGMPOOL_IDX)
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync {
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync pPool->aPages[idx].fCR3Mix = fCR3Mix;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync idx = pPool->aPages[idx].iMonitoredNext;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync }
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync}
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync/**
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * Installs or modifies monitoring of a CR3 page (special).
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync *
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * We're pretending the CR3 page is shadowed by the pool so we can use the
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * generic mechanisms in detecting chained monitoring. (This also gives us a
9e7e0b61d29309a0ed7af9472c8d6d865f9e8a2dvboxsync * tast of what code changes are required to really pool CR3 shadow pages.)
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync *
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * @returns VBox status code.
9e7e0b61d29309a0ed7af9472c8d6d865f9e8a2dvboxsync * @param pPool The pool.
9e7e0b61d29309a0ed7af9472c8d6d865f9e8a2dvboxsync * @param idxRoot The CR3 (root) page index.
9e7e0b61d29309a0ed7af9472c8d6d865f9e8a2dvboxsync * @param GCPhysCR3 The (new) CR3 value.
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync */
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsyncint pgmPoolMonitorMonitorCR3(PPGMPOOL pPool, uint16_t idxRoot, RTGCPHYS GCPhysCR3)
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync{
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync Assert(idxRoot != NIL_PGMPOOL_IDX && idxRoot < PGMPOOL_IDX_FIRST);
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync PPGMPOOLPAGE pPage = &pPool->aPages[idxRoot];
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync LogFlow(("pgmPoolMonitorMonitorCR3: idxRoot=%d pPage=%p:{.GCPhys=%RGp, .fMonitored=%d} GCPhysCR3=%RGp\n",
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync idxRoot, pPage, pPage->GCPhys, pPage->fMonitored, GCPhysCR3));
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync /*
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * The unlikely case where it already matches.
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync */
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync if (pPage->GCPhys == GCPhysCR3)
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync {
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync Assert(pPage->fMonitored);
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync return VINF_SUCCESS;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync }
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync /*
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * Flush the current monitoring and remove it from the hash.
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync */
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync int rc = VINF_SUCCESS;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync if (pPage->fMonitored)
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync {
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync pgmPoolMonitorChainChangeCR3Mix(pPool, pPage, false);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync rc = pgmPoolMonitorFlush(pPool, pPage);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync if (rc == VERR_PGM_POOL_CLEARED)
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync rc = VINF_SUCCESS;
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync else
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync AssertFatalRC(rc);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync pgmPoolHashRemove(pPool, pPage);
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync }
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync /*
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync * Monitor the page at the new location and insert it into the hash.
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync */
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync pPage->GCPhys = GCPhysCR3;
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync int rc2 = pgmPoolMonitorInsert(pPool, pPage);
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync if (rc2 != VERR_PGM_POOL_CLEARED)
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync {
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync AssertFatalRC(rc2);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync if (rc2 != VINF_SUCCESS && rc == VINF_SUCCESS)
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync rc = rc2;
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync }
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync pgmPoolHashInsert(pPool, pPage);
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync pgmPoolMonitorChainChangeCR3Mix(pPool, pPage, true);
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync return rc;
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync}
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync/**
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync * Removes the monitoring of a CR3 page (special).
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync *
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync * @returns VBox status code.
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync * @param pPool The pool.
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync * @param idxRoot The CR3 (root) page index.
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync */
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsyncint pgmPoolMonitorUnmonitorCR3(PPGMPOOL pPool, uint16_t idxRoot)
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync{
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync Assert(idxRoot != NIL_PGMPOOL_IDX && idxRoot < PGMPOOL_IDX_FIRST);
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync PPGMPOOLPAGE pPage = &pPool->aPages[idxRoot];
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync LogFlow(("pgmPoolMonitorUnmonitorCR3: idxRoot=%d pPage=%p:{.GCPhys=%RGp, .fMonitored=%d}\n",
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync idxRoot, pPage, pPage->GCPhys, pPage->fMonitored));
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync if (!pPage->fMonitored)
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync return VINF_SUCCESS;
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync pgmPoolMonitorChainChangeCR3Mix(pPool, pPage, false);
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync int rc = pgmPoolMonitorFlush(pPool, pPage);
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync if (rc != VERR_PGM_POOL_CLEARED)
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync AssertFatalRC(rc);
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync else
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync rc = VINF_SUCCESS;
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync pgmPoolHashRemove(pPool, pPage);
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync Assert(!pPage->fMonitored);
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync pPage->GCPhys = NIL_RTGCPHYS;
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync return rc;
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync}
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync# endif /* PGMPOOL_WITH_MIXED_PT_CR3 */
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync/**
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * Inserts the page into the list of modified pages.
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync *
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync * @param pPool The pool.
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync * @param pPage The page.
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync */
cd5df721f068659172f3bf95de8fedeb465f057dvboxsyncvoid pgmPoolMonitorModifiedInsert(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync{
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync Log3(("pgmPoolMonitorModifiedInsert: idx=%d\n", pPage->idx));
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync AssertMsg( pPage->iModifiedNext == NIL_PGMPOOL_IDX
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync && pPage->iModifiedPrev == NIL_PGMPOOL_IDX
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync && pPool->iModifiedHead != pPage->idx,
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync ("Next=%d Prev=%d idx=%d cModifications=%d Head=%d cModifiedPages=%d\n",
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync pPage->iModifiedNext, pPage->iModifiedPrev, pPage->idx, pPage->cModifications,
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync pPool->iModifiedHead, pPool->cModifiedPages));
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync pPage->iModifiedNext = pPool->iModifiedHead;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync if (pPool->iModifiedHead != NIL_PGMPOOL_IDX)
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync pPool->aPages[pPool->iModifiedHead].iModifiedPrev = pPage->idx;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync pPool->iModifiedHead = pPage->idx;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync pPool->cModifiedPages++;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync#ifdef VBOX_WITH_STATISTICS
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync if (pPool->cModifiedPages > pPool->cModifiedPagesHigh)
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync pPool->cModifiedPagesHigh = pPool->cModifiedPages;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync#endif
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync}
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync/**
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * Removes the page from the list of modified pages and resets the
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * moficiation counter.
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync *
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * @param pPool The pool.
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * @param pPage The page which is believed to be in the list of modified pages.
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync */
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsyncstatic void pgmPoolMonitorModifiedRemove(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync{
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync Log3(("pgmPoolMonitorModifiedRemove: idx=%d cModifications=%d\n", pPage->idx, pPage->cModifications));
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync if (pPool->iModifiedHead == pPage->idx)
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync {
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync Assert(pPage->iModifiedPrev == NIL_PGMPOOL_IDX);
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync pPool->iModifiedHead = pPage->iModifiedNext;
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync if (pPage->iModifiedNext != NIL_PGMPOOL_IDX)
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync {
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync pPool->aPages[pPage->iModifiedNext].iModifiedPrev = NIL_PGMPOOL_IDX;
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync pPage->iModifiedNext = NIL_PGMPOOL_IDX;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync }
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync pPool->cModifiedPages--;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync }
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync else if (pPage->iModifiedPrev != NIL_PGMPOOL_IDX)
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync {
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync pPool->aPages[pPage->iModifiedPrev].iModifiedNext = pPage->iModifiedNext;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync if (pPage->iModifiedNext != NIL_PGMPOOL_IDX)
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync {
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync pPool->aPages[pPage->iModifiedNext].iModifiedPrev = pPage->iModifiedPrev;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync pPage->iModifiedNext = NIL_PGMPOOL_IDX;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync }
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync pPage->iModifiedPrev = NIL_PGMPOOL_IDX;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync pPool->cModifiedPages--;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync }
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync else
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync Assert(pPage->iModifiedPrev == NIL_PGMPOOL_IDX);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync pPage->cModifications = 0;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync}
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync/**
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * Zaps the list of modified pages, resetting their modification counters in the process.
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync *
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * @param pVM The VM handle.
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync */
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsyncvoid pgmPoolMonitorModifiedClearAll(PVM pVM)
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync{
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync PPGMPOOL pPool = pVM->pgm.s.CTX_SUFF(pPool);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync LogFlow(("pgmPoolMonitorModifiedClearAll: cModifiedPages=%d\n", pPool->cModifiedPages));
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync unsigned cPages = 0; NOREF(cPages);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync uint16_t idx = pPool->iModifiedHead;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync pPool->iModifiedHead = NIL_PGMPOOL_IDX;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync while (idx != NIL_PGMPOOL_IDX)
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync {
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync PPGMPOOLPAGE pPage = &pPool->aPages[idx];
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync idx = pPage->iModifiedNext;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync pPage->iModifiedNext = NIL_PGMPOOL_IDX;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync pPage->iModifiedPrev = NIL_PGMPOOL_IDX;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync pPage->cModifications = 0;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync Assert(++cPages);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync }
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync AssertMsg(cPages == pPool->cModifiedPages, ("%d != %d\n", cPages, pPool->cModifiedPages));
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync pPool->cModifiedPages = 0;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync}
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync/**
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * Clear all shadow pages and clear all modification counters.
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync *
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * @param pVM The VM handle.
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * @remark Should only be used when monitoring is available, thus placed in
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * the PGMPOOL_WITH_MONITORING #ifdef.
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync */
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsyncvoid pgmPoolClearAll(PVM pVM)
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync{
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync PPGMPOOL pPool = pVM->pgm.s.CTX_SUFF(pPool);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync STAM_PROFILE_START(&pPool->StatClearAll, c);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync LogFlow(("pgmPoolClearAll: cUsedPages=%d\n", pPool->cUsedPages));
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync /*
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * Iterate all the pages until we've encountered all that in use.
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * This is simple but not quite optimal solution.
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync */
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync unsigned cModifiedPages = 0; NOREF(cModifiedPages);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync unsigned cLeft = pPool->cUsedPages;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync unsigned iPage = pPool->cCurPages;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync while (--iPage >= PGMPOOL_IDX_FIRST)
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync {
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync PPGMPOOLPAGE pPage = &pPool->aPages[iPage];
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync if (pPage->GCPhys != NIL_RTGCPHYS)
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync {
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync switch (pPage->enmKind)
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync {
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync /*
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * We only care about shadow page tables.
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync */
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_PT:
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_4MB:
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_PT:
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_4MB:
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_PT:
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_2MB:
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync case PGMPOOLKIND_32BIT_PT_FOR_PHYS:
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync case PGMPOOLKIND_PAE_PT_FOR_PHYS:
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync {
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync#ifdef PGMPOOL_WITH_USER_TRACKING
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync if (pPage->cPresent)
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync#endif
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync {
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync void *pvShw = PGMPOOL_PAGE_2_PTR(pPool->CTX_SUFF(pVM), pPage);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync STAM_PROFILE_START(&pPool->StatZeroPage, z);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync ASMMemZeroPage(pvShw);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync STAM_PROFILE_STOP(&pPool->StatZeroPage, z);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync#ifdef PGMPOOL_WITH_USER_TRACKING
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync pPage->cPresent = 0;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync pPage->iFirstPresent = ~0;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync#endif
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync }
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync }
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync /* fall thru */
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync default:
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync Assert(!pPage->cModifications || ++cModifiedPages);
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync Assert(pPage->iModifiedNext == NIL_PGMPOOL_IDX || pPage->cModifications);
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync Assert(pPage->iModifiedPrev == NIL_PGMPOOL_IDX || pPage->cModifications);
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync pPage->iModifiedNext = NIL_PGMPOOL_IDX;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync pPage->iModifiedPrev = NIL_PGMPOOL_IDX;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync pPage->cModifications = 0;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync break;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync }
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync if (!--cLeft)
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync break;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync }
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync }
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync /* swipe the special pages too. */
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync for (iPage = PGMPOOL_IDX_FIRST_SPECIAL; iPage < PGMPOOL_IDX_FIRST; iPage++)
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync {
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync PPGMPOOLPAGE pPage = &pPool->aPages[iPage];
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync if (pPage->GCPhys != NIL_RTGCPHYS)
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync {
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync Assert(!pPage->cModifications || ++cModifiedPages);
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync Assert(pPage->iModifiedNext == NIL_PGMPOOL_IDX || pPage->cModifications);
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync Assert(pPage->iModifiedPrev == NIL_PGMPOOL_IDX || pPage->cModifications);
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync pPage->iModifiedNext = NIL_PGMPOOL_IDX;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync pPage->iModifiedPrev = NIL_PGMPOOL_IDX;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync pPage->cModifications = 0;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync }
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync }
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync#ifndef DEBUG_michael
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync AssertMsg(cModifiedPages == pPool->cModifiedPages, ("%d != %d\n", cModifiedPages, pPool->cModifiedPages));
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync#endif
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync pPool->iModifiedHead = NIL_PGMPOOL_IDX;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync pPool->cModifiedPages = 0;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync#ifdef PGMPOOL_WITH_GCPHYS_TRACKING
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync /*
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * Clear all the GCPhys links and rebuild the phys ext free list.
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync */
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync for (PPGMRAMRANGE pRam = pPool->CTX_SUFF(pVM)->pgm.s.CTX_SUFF(pRamRanges);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync pRam;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync pRam = pRam->CTX_SUFF(pNext))
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync {
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync unsigned iPage = pRam->cb >> PAGE_SHIFT;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync while (iPage-- > 0)
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync pRam->aPages[iPage].HCPhys &= MM_RAM_FLAGS_NO_REFS_MASK; /** @todo PAGE FLAGS */
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync }
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync pPool->iPhysExtFreeHead = 0;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync PPGMPOOLPHYSEXT paPhysExts = pPool->CTX_SUFF(paPhysExts);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync const unsigned cMaxPhysExts = pPool->cMaxPhysExts;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync for (unsigned i = 0; i < cMaxPhysExts; i++)
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync {
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync paPhysExts[i].iNext = i + 1;
9e7e0b61d29309a0ed7af9472c8d6d865f9e8a2dvboxsync paPhysExts[i].aidx[0] = NIL_PGMPOOL_IDX;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync paPhysExts[i].aidx[1] = NIL_PGMPOOL_IDX;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync paPhysExts[i].aidx[2] = NIL_PGMPOOL_IDX;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync }
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync paPhysExts[cMaxPhysExts - 1].iNext = NIL_PGMPOOL_PHYSEXT_INDEX;
9e7e0b61d29309a0ed7af9472c8d6d865f9e8a2dvboxsync#endif
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync pPool->cPresent = 0;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync STAM_PROFILE_STOP(&pPool->StatClearAll, c);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync}
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync/**
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync * Handle SyncCR3 pool tasks
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync *
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * @returns VBox status code.
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * @retval VINF_SUCCESS if successfully added.
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * @retval VINF_PGM_SYNC_CR3 is it needs to be deferred to ring 3 (GC only)
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * @param pVM The VM handle.
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * @remark Should only be used when monitoring is available, thus placed in
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * the PGMPOOL_WITH_MONITORING #ifdef.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncint pgmPoolSyncCR3(PVM pVM)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /*
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * When monitoring shadowed pages, we reset the modification counters on CR3 sync.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Occasionally we will have to clear all the shadow page tables because we wanted
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * to monitor a page which was mapped by too many shadowed page tables. This operation
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync * sometimes refered to as a 'lightweight flush'.
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync */
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync if (!(pVM->pgm.s.fSyncFlags & PGM_SYNC_CLEAR_PGM_POOL))
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync pgmPoolMonitorModifiedClearAll(pVM);
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync else
d8e12fa5dd1c35282b98cb165e42b6b395cf971bvboxsync {
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync# ifndef IN_RC
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync pVM->pgm.s.fSyncFlags &= ~PGM_SYNC_CLEAR_PGM_POOL;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync pgmPoolClearAll(pVM);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync# else
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync LogFlow(("SyncCR3: PGM_SYNC_CLEAR_PGM_POOL is set -> VINF_PGM_SYNC_CR3\n"));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync VM_FF_SET(pVM, VM_FF_PGM_SYNC_CR3); /** @todo no need to do global sync, right? */
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync return VINF_PGM_SYNC_CR3;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync# endif
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync }
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync return VINF_SUCCESS;
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync}
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync#endif /* PGMPOOL_WITH_MONITORING */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync#ifdef PGMPOOL_WITH_USER_TRACKING
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
d8e12fa5dd1c35282b98cb165e42b6b395cf971bvboxsync/**
d8e12fa5dd1c35282b98cb165e42b6b395cf971bvboxsync * Frees up at least one user entry.
d8e12fa5dd1c35282b98cb165e42b6b395cf971bvboxsync *
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * @returns VBox status code.
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * @retval VINF_SUCCESS if successfully added.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * @retval VERR_PGM_POOL_FLUSHED if the pool was flushed.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * @param pPool The pool.
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync * @param iUser The user index.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncstatic int pgmPoolTrackFreeOneUser(PPGMPOOL pPool, uint16_t iUser)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync STAM_COUNTER_INC(&pPool->StatTrackFreeUpOneUser);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#ifdef PGMPOOL_WITH_CACHE
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /*
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Just free cached pages in a braindead fashion.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync */
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync /** @todo walk the age list backwards and free the first with usage. */
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync int rc = VINF_SUCCESS;
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync do
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync {
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync int rc2 = pgmPoolCacheFreeOne(pPool, iUser);
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync if (RT_FAILURE(rc2) && rc == VINF_SUCCESS)
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync rc = rc2;
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync } while (pPool->iUserFreeHead == NIL_PGMPOOL_USER_INDEX);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync return rc;
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync#else
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync /*
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Lazy approach.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* @todo incompatible with long mode paging (cr3 root will be flushed) */
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync Assert(!CPUMIsGuestInLongMode(pVM));
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync pgmPoolFlushAllInt(pPool);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync return VERR_PGM_POOL_FLUSHED;
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync#endif
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync}
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync/**
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync * Inserts a page into the cache.
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync *
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync * This will create user node for the page, insert it into the GCPhys
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync * hash, and insert it into the age list.
c99b597540585068d22dde4c9f74730305f24097vboxsync *
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync * @returns VBox status code.
c99b597540585068d22dde4c9f74730305f24097vboxsync * @retval VINF_SUCCESS if successfully added.
c99b597540585068d22dde4c9f74730305f24097vboxsync * @retval VERR_PGM_POOL_FLUSHED if the pool was flushed.
c99b597540585068d22dde4c9f74730305f24097vboxsync * @retval VERR_PGM_POOL_CLEARED if the deregistration of the physical handler will cause a light weight pool flush.
c99b597540585068d22dde4c9f74730305f24097vboxsync * @param pPool The pool.
c99b597540585068d22dde4c9f74730305f24097vboxsync * @param pPage The cached page.
c99b597540585068d22dde4c9f74730305f24097vboxsync * @param GCPhys The GC physical address of the page we're gonna shadow.
c99b597540585068d22dde4c9f74730305f24097vboxsync * @param iUser The user index.
c99b597540585068d22dde4c9f74730305f24097vboxsync * @param iUserTable The user table index.
c99b597540585068d22dde4c9f74730305f24097vboxsync */
c99b597540585068d22dde4c9f74730305f24097vboxsyncDECLINLINE(int) pgmPoolTrackInsert(PPGMPOOL pPool, PPGMPOOLPAGE pPage, RTGCPHYS GCPhys, uint16_t iUser, uint32_t iUserTable)
c99b597540585068d22dde4c9f74730305f24097vboxsync{
c99b597540585068d22dde4c9f74730305f24097vboxsync int rc = VINF_SUCCESS;
c99b597540585068d22dde4c9f74730305f24097vboxsync PPGMPOOLUSER pUser = pPool->CTX_SUFF(paUsers);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync
c99b597540585068d22dde4c9f74730305f24097vboxsync LogFlow(("pgmPoolTrackInsert iUser %d iUserTable %d\n", iUser, iUserTable));
c99b597540585068d22dde4c9f74730305f24097vboxsync
c99b597540585068d22dde4c9f74730305f24097vboxsync /*
c99b597540585068d22dde4c9f74730305f24097vboxsync * Find free a user node.
c99b597540585068d22dde4c9f74730305f24097vboxsync */
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync uint16_t i = pPool->iUserFreeHead;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (i == NIL_PGMPOOL_USER_INDEX)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync int rc = pgmPoolTrackFreeOneUser(pPool, iUser);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync if (RT_FAILURE(rc))
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync return rc;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync i = pPool->iUserFreeHead;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync /*
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync * Unlink the user node from the free list,
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync * initialize and insert it into the user list.
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync */
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync pPool->iUserFreeHead = pUser[i].iNext;
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync pUser[i].iNext = NIL_PGMPOOL_USER_INDEX;
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync pUser[i].iUser = iUser;
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync pUser[i].iUserTable = iUserTable;
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync pPage->iUserHead = i;
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync /*
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Insert into cache and enable monitoring of the guest page if enabled.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync *
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Until we implement caching of all levels, including the CR3 one, we'll
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync * have to make sure we don't try monitor & cache any recursive reuse of
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync * a monitored CR3 page. Because all windows versions are doing this we'll
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync * have to be able to do combined access monitoring, CR3 + PT and
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync * PD + PT (guest PAE).
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync *
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync * Update:
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync * We're now cooperating with the CR3 monitor if an uncachable page is found.
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync */
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync#if defined(PGMPOOL_WITH_MONITORING) || defined(PGMPOOL_WITH_CACHE)
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync# ifdef PGMPOOL_WITH_MIXED_PT_CR3
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync const bool fCanBeMonitored = true;
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync# else
c99b597540585068d22dde4c9f74730305f24097vboxsync bool fCanBeMonitored = pPool->CTX_SUFF(pVM)->pgm.s.GCPhysGstCR3Monitored == NIL_RTGCPHYS
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync || (GCPhys & X86_PTE_PAE_PG_MASK) != (pPool->CTX_SUFF(pVM)->pgm.s.GCPhysGstCR3Monitored & X86_PTE_PAE_PG_MASK)
c99b597540585068d22dde4c9f74730305f24097vboxsync || pgmPoolIsBigPage((PGMPOOLKIND)pPage->enmKind);
c99b597540585068d22dde4c9f74730305f24097vboxsync# endif
c99b597540585068d22dde4c9f74730305f24097vboxsync# ifdef PGMPOOL_WITH_CACHE
02651f98b4320e70a300ba1ebe95270096ebfd4dvboxsync pgmPoolCacheInsert(pPool, pPage, fCanBeMonitored); /* This can be expanded. */
c99b597540585068d22dde4c9f74730305f24097vboxsync# endif
c99b597540585068d22dde4c9f74730305f24097vboxsync if (fCanBeMonitored)
c99b597540585068d22dde4c9f74730305f24097vboxsync {
c99b597540585068d22dde4c9f74730305f24097vboxsync# ifdef PGMPOOL_WITH_MONITORING
c99b597540585068d22dde4c9f74730305f24097vboxsync rc = pgmPoolMonitorInsert(pPool, pPage);
c99b597540585068d22dde4c9f74730305f24097vboxsync if (rc == VERR_PGM_POOL_CLEARED)
c99b597540585068d22dde4c9f74730305f24097vboxsync {
c99b597540585068d22dde4c9f74730305f24097vboxsync /* 'Failed' - free the usage, and keep it in the cache (if enabled). */
c99b597540585068d22dde4c9f74730305f24097vboxsync# ifndef PGMPOOL_WITH_CACHE
c99b597540585068d22dde4c9f74730305f24097vboxsync pgmPoolMonitorFlush(pPool, pPage);
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync rc = VERR_PGM_POOL_FLUSHED;
c99b597540585068d22dde4c9f74730305f24097vboxsync# endif
c99b597540585068d22dde4c9f74730305f24097vboxsync pPage->iUserHead = NIL_PGMPOOL_USER_INDEX;
c99b597540585068d22dde4c9f74730305f24097vboxsync pUser[i].iNext = pPool->iUserFreeHead;
c99b597540585068d22dde4c9f74730305f24097vboxsync pUser[i].iUser = NIL_PGMPOOL_IDX;
c99b597540585068d22dde4c9f74730305f24097vboxsync pPool->iUserFreeHead = i;
c99b597540585068d22dde4c9f74730305f24097vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync# endif
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif /* PGMPOOL_WITH_MONITORING */
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync return rc;
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync# ifdef PGMPOOL_WITH_CACHE /* (only used when the cache is enabled.) */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/**
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync * Adds a user reference to a page.
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync *
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync * This will
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync * This will move the page to the head of the
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync *
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * @returns VBox status code.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * @retval VINF_SUCCESS if successfully added.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * @retval VERR_PGM_POOL_FLUSHED if the pool was flushed.
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync * @param pPool The pool.
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync * @param pPage The cached page.
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync * @param iUser The user index.
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync * @param iUserTable The user table.
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync */
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsyncstatic int pgmPoolTrackAddUser(PPGMPOOL pPool, PPGMPOOLPAGE pPage, uint16_t iUser, uint32_t iUserTable)
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync{
5366e994777f9d9391cf809dc77610f57270d75dvboxsync PPGMPOOLUSER paUsers = pPool->CTX_SUFF(paUsers);
5366e994777f9d9391cf809dc77610f57270d75dvboxsync
5366e994777f9d9391cf809dc77610f57270d75dvboxsync LogFlow(("pgmPoolTrackAddUser iUser %d iUserTable %d\n", iUser, iUserTable));
5366e994777f9d9391cf809dc77610f57270d75dvboxsync# ifdef VBOX_STRICT
5366e994777f9d9391cf809dc77610f57270d75dvboxsync /*
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync * Check that the entry doesn't already exists.
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync */
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync if (pPage->iUserHead != NIL_PGMPOOL_USER_INDEX)
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync {
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync uint16_t i = pPage->iUserHead;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync do
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync {
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync Assert(i < pPool->cMaxUsers);
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync AssertMsg(paUsers[i].iUser != iUser || paUsers[i].iUserTable != iUserTable, ("%x %x vs new %x %x\n", paUsers[i].iUser, paUsers[i].iUserTable, iUser, iUserTable));
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync i = paUsers[i].iNext;
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync } while (i != NIL_PGMPOOL_USER_INDEX);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync }
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync# endif
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync /*
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync * Allocate a user node.
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync */
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync uint16_t i = pPool->iUserFreeHead;
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync if (i == NIL_PGMPOOL_USER_INDEX)
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync {
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync int rc = pgmPoolTrackFreeOneUser(pPool, iUser);
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync if (RT_FAILURE(rc))
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync return rc;
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync i = pPool->iUserFreeHead;
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync }
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync pPool->iUserFreeHead = paUsers[i].iNext;
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync /*
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync * Initialize the user node and insert it.
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync */
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync paUsers[i].iNext = pPage->iUserHead;
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync paUsers[i].iUser = iUser;
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync paUsers[i].iUserTable = iUserTable;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pPage->iUserHead = i;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync# ifdef PGMPOOL_WITH_CACHE
3641904508e6a0671c21a083a2ed03ebad8d976cvboxsync /*
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Tell the cache to update its replacement stats for this page.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pgmPoolCacheUsed(pPool, pPage);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync# endif
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync return VINF_SUCCESS;
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync}
36f3c24e4ad9c6b813767db1faeabbe7e2ecc057vboxsync# endif /* PGMPOOL_WITH_CACHE */
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync/**
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * Frees a user record associated with a page.
36f3c24e4ad9c6b813767db1faeabbe7e2ecc057vboxsync *
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * This does not clear the entry in the user table, it simply replaces the
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * user record to the chain of free records.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync *
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * @param pPool The pool.
36f3c24e4ad9c6b813767db1faeabbe7e2ecc057vboxsync * @param HCPhys The HC physical address of the shadow page.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * @param iUser The shadow page pool index of the user table.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * @param iUserTable The index into the user table (shadowed).
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync */
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsyncstatic void pgmPoolTrackFreeUser(PPGMPOOL pPool, PPGMPOOLPAGE pPage, uint16_t iUser, uint32_t iUserTable)
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync{
36f3c24e4ad9c6b813767db1faeabbe7e2ecc057vboxsync /*
ca3db470494a8b6eaec69ea37468a5cda65e2da8vboxsync * Unlink and free the specified user entry.
36f3c24e4ad9c6b813767db1faeabbe7e2ecc057vboxsync */
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync PPGMPOOLUSER paUsers = pPool->CTX_SUFF(paUsers);
36f3c24e4ad9c6b813767db1faeabbe7e2ecc057vboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync /* Special: For PAE and 32-bit paging, there is usually no more than one user. */
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync uint16_t i = pPage->iUserHead;
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync if ( i != NIL_PGMPOOL_USER_INDEX
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync && paUsers[i].iUser == iUser
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync && paUsers[i].iUserTable == iUserTable)
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync {
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync pPage->iUserHead = paUsers[i].iNext;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync paUsers[i].iUser = NIL_PGMPOOL_IDX;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync paUsers[i].iNext = pPool->iUserFreeHead;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync pPool->iUserFreeHead = i;
36f3c24e4ad9c6b813767db1faeabbe7e2ecc057vboxsync return;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync }
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* General: Linear search. */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync uint16_t iPrev = NIL_PGMPOOL_USER_INDEX;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync while (i != NIL_PGMPOOL_USER_INDEX)
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if ( paUsers[i].iUser == iUser
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync && paUsers[i].iUserTable == iUserTable)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (iPrev != NIL_PGMPOOL_USER_INDEX)
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync paUsers[iPrev].iNext = paUsers[i].iNext;
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync else
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync pPage->iUserHead = paUsers[i].iNext;
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync paUsers[i].iUser = NIL_PGMPOOL_IDX;
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync paUsers[i].iNext = pPool->iUserFreeHead;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pPool->iUserFreeHead = i;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync return;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync iPrev = i;
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync i = paUsers[i].iNext;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync }
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync /* Fatal: didn't find it */
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync AssertFatalMsgFailed(("Didn't find the user entry! iUser=%#x iUserTable=%#x GCPhys=%RGp\n",
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync iUser, iUserTable, pPage->GCPhys));
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync}
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync/**
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync * Gets the entry size of a shadow table.
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync *
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * @param enmKind The kind of page.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync *
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync * @returns The size of the entry in bytes. That is, 4 or 8.
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync * @returns If the kind is not for a table, an assertion is raised and 0 is
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * returned.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync */
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsyncDECLINLINE(unsigned) pgmPoolTrackGetShadowEntrySize(PGMPOOLKIND enmKind)
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync{
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync switch (enmKind)
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync {
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_PT:
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync case PGMPOOLKIND_32BIT_PT_FOR_PHYS:
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_4MB:
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync case PGMPOOLKIND_ROOT_32BIT_PD:
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync return 4;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync case PGMPOOLKIND_PAE_PT_FOR_PHYS:
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_PT:
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_4MB:
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_PT:
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_2MB:
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync case PGMPOOLKIND_PAE_PD_FOR_32BIT_PD:
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync case PGMPOOLKIND_PAE_PD_FOR_PAE_PD:
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync case PGMPOOLKIND_64BIT_PD_FOR_64BIT_PD:
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_64BIT_PDPT:
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync case PGMPOOLKIND_64BIT_PML4_FOR_64BIT_PML4:
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync case PGMPOOLKIND_ROOT_PAE_PD:
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync case PGMPOOLKIND_ROOT_PDPT:
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync case PGMPOOLKIND_ROOT_NESTED:
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_PHYS:
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync case PGMPOOLKIND_64BIT_PD_FOR_PHYS:
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync case PGMPOOLKIND_EPT_PDPT_FOR_PHYS:
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync case PGMPOOLKIND_EPT_PD_FOR_PHYS:
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync case PGMPOOLKIND_EPT_PT_FOR_PHYS:
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync return 8;
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync default:
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync AssertFatalMsgFailed(("enmKind=%d\n", enmKind));
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync }
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync}
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync/**
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync * Gets the entry size of a guest table.
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync *
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync * @param enmKind The kind of page.
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync *
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * @returns The size of the entry in bytes. That is, 0, 4 or 8.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * @returns If the kind is not for a table, an assertion is raised and 0 is
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync * returned.
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync */
8bc8d66f188d5357155b8340e2d489573be2b607vboxsyncDECLINLINE(unsigned) pgmPoolTrackGetGuestEntrySize(PGMPOOLKIND enmKind)
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync{
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync switch (enmKind)
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync {
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_PT:
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_4MB:
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync case PGMPOOLKIND_ROOT_32BIT_PD:
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_PT:
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_4MB:
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync case PGMPOOLKIND_PAE_PD_FOR_32BIT_PD:
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync return 4;
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_PT:
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_2MB:
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync case PGMPOOLKIND_PAE_PD_FOR_PAE_PD:
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync case PGMPOOLKIND_64BIT_PD_FOR_64BIT_PD:
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_64BIT_PDPT:
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync case PGMPOOLKIND_64BIT_PML4_FOR_64BIT_PML4:
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync case PGMPOOLKIND_ROOT_PAE_PD:
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync case PGMPOOLKIND_ROOT_PDPT:
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync return 8;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync case PGMPOOLKIND_32BIT_PT_FOR_PHYS:
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync case PGMPOOLKIND_PAE_PT_FOR_PHYS:
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_PHYS:
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync case PGMPOOLKIND_64BIT_PD_FOR_PHYS:
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync case PGMPOOLKIND_EPT_PDPT_FOR_PHYS:
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync case PGMPOOLKIND_EPT_PD_FOR_PHYS:
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync case PGMPOOLKIND_EPT_PT_FOR_PHYS:
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync case PGMPOOLKIND_ROOT_NESTED:
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /** @todo can we return 0? (nobody is calling this...) */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AssertFailed();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync return 0;
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync default:
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync AssertFatalMsgFailed(("enmKind=%d\n", enmKind));
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync }
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync}
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync#ifdef PGMPOOL_WITH_GCPHYS_TRACKING
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync/**
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync * Scans one shadow page table for mappings of a physical page.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync *
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync * @param pVM The VM handle.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * @param pPhysPage The guest page in question.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * @param iShw The shadow page table.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * @param cRefs The number of references made in that PT.
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync */
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsyncstatic void pgmPoolTrackFlushGCPhysPTInt(PVM pVM, PCPGMPAGE pPhysPage, uint16_t iShw, uint16_t cRefs)
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync{
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync LogFlow(("pgmPoolTrackFlushGCPhysPT: HCPhys=%RHp iShw=%d cRefs=%d\n", pPhysPage->HCPhys, iShw, cRefs));
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync PPGMPOOL pPool = pVM->pgm.s.CTX_SUFF(pPool);
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync /*
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync * Assert sanity.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync */
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync Assert(cRefs == 1);
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync AssertFatalMsg(iShw < pPool->cCurPages && iShw != NIL_PGMPOOL_IDX, ("iShw=%d\n", iShw));
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync PPGMPOOLPAGE pPage = &pPool->aPages[iShw];
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync /*
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync * Then, clear the actual mappings to the page in the shadow PT.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync */
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync switch (pPage->enmKind)
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync {
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_PT:
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_4MB:
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync case PGMPOOLKIND_32BIT_PT_FOR_PHYS:
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync {
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync const uint32_t u32 = PGM_PAGE_GET_HCPHYS(pPhysPage) | X86_PTE_P;
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync PX86PT pPT = (PX86PT)PGMPOOL_PAGE_2_PTR(pVM, pPage);
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pPT->a); i++)
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync if ((pPT->a[i].u & (X86_PTE_PG_MASK | X86_PTE_P)) == u32)
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Log4(("pgmPoolTrackFlushGCPhysPTs: i=%d pte=%RX32 cRefs=%#x\n", i, pPT->a[i], cRefs));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pPT->a[i].u = 0;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync cRefs--;
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync if (!cRefs)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync return;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#if defined(DEBUG) && !defined(IN_RING0) ///@todo RTLogPrintf is missing in R0.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync RTLogPrintf("cRefs=%d iFirstPresent=%d cPresent=%d\n", cRefs, pPage->iFirstPresent, pPage->cPresent);
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync for (unsigned i = 0; i < RT_ELEMENTS(pPT->a); i++)
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync if ((pPT->a[i].u & (X86_PTE_PG_MASK | X86_PTE_P)) == u32)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync RTLogPrintf("i=%d cRefs=%d\n", i, cRefs--);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pPT->a[i].u = 0;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AssertFatalMsgFailed(("cRefs=%d iFirstPresent=%d cPresent=%d\n", cRefs, pPage->iFirstPresent, pPage->cPresent));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync break;
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_PT:
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_4MB:
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_PT:
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_2MB:
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync case PGMPOOLKIND_PAE_PT_FOR_PHYS:
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync const uint64_t u64 = PGM_PAGE_GET_HCPHYS(pPhysPage) | X86_PTE_P;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync PX86PTPAE pPT = (PX86PTPAE)PGMPOOL_PAGE_2_PTR(pVM, pPage);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pPT->a); i++)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if ((pPT->a[i].u & (X86_PTE_PAE_PG_MASK | X86_PTE_P)) == u64)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Log4(("pgmPoolTrackFlushGCPhysPTs: i=%d pte=%RX64 cRefs=%#x\n", i, pPT->a[i], cRefs));
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsync pPT->a[i].u = 0;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync cRefs--;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (!cRefs)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync return;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync#if defined(DEBUG) && !defined(IN_RING0) ///@todo RTLogPrintf is missing in R0.
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync RTLogPrintf("cRefs=%d iFirstPresent=%d cPresent=%d\n", cRefs, pPage->iFirstPresent, pPage->cPresent);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pPT->a); i++)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if ((pPT->a[i].u & (X86_PTE_PAE_PG_MASK | X86_PTE_P)) == u64)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync RTLogPrintf("i=%d cRefs=%d\n", i, cRefs--);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pPT->a[i].u = 0;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsync AssertFatalMsgFailed(("cRefs=%d iFirstPresent=%d cPresent=%d\n", cRefs, pPage->iFirstPresent, pPage->cPresent));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync break;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync case PGMPOOLKIND_EPT_PT_FOR_PHYS:
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync {
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync const uint64_t u64 = PGM_PAGE_GET_HCPHYS(pPhysPage) | X86_PTE_P;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync PEPTPT pPT = (PEPTPT)PGMPOOL_PAGE_2_PTR(pVM, pPage);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pPT->a); i++)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if ((pPT->a[i].u & (EPT_PTE_PG_MASK | X86_PTE_P)) == u64)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Log4(("pgmPoolTrackFlushGCPhysPTs: i=%d pte=%RX64 cRefs=%#x\n", i, pPT->a[i], cRefs));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pPT->a[i].u = 0;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync cRefs--;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (!cRefs)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync return;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#if defined(DEBUG) && !defined(IN_RING0) ///@todo RTLogPrintf is missing in R0.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync RTLogPrintf("cRefs=%d iFirstPresent=%d cPresent=%d\n", cRefs, pPage->iFirstPresent, pPage->cPresent);
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync for (unsigned i = 0; i < RT_ELEMENTS(pPT->a); i++)
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync if ((pPT->a[i].u & (EPT_PTE_PG_MASK | X86_PTE_P)) == u64)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync RTLogPrintf("i=%d cRefs=%d\n", i, cRefs--);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pPT->a[i].u = 0;
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync }
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync#endif
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync AssertFatalMsgFailed(("cRefs=%d iFirstPresent=%d cPresent=%d\n", cRefs, pPage->iFirstPresent, pPage->cPresent));
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync break;
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync }
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync default:
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync AssertFatalMsgFailed(("enmKind=%d iShw=%d\n", pPage->enmKind, iShw));
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync }
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync}
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync/**
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync * Scans one shadow page table for mappings of a physical page.
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync *
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync * @param pVM The VM handle.
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync * @param pPhysPage The guest page in question.
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync * @param iShw The shadow page table.
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync * @param cRefs The number of references made in that PT.
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync */
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsyncvoid pgmPoolTrackFlushGCPhysPT(PVM pVM, PPGMPAGE pPhysPage, uint16_t iShw, uint16_t cRefs)
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync{
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync PPGMPOOL pPool = pVM->pgm.s.CTX_SUFF(pPool); NOREF(pPool);
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlow(("pgmPoolTrackFlushGCPhysPT: HCPhys=%RHp iShw=%d cRefs=%d\n", pPhysPage->HCPhys, iShw, cRefs));
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync STAM_PROFILE_START(&pPool->StatTrackFlushGCPhysPT, f);
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync pgmPoolTrackFlushGCPhysPTInt(pVM, pPhysPage, iShw, cRefs);
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync pPhysPage->HCPhys &= MM_RAM_FLAGS_NO_REFS_MASK; /** @todo PAGE FLAGS */
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync STAM_PROFILE_STOP(&pPool->StatTrackFlushGCPhysPT, f);
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync}
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/**
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Flushes a list of shadow page tables mapping the same physical page.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync *
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsync * @param pVM The VM handle.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * @param pPhysPage The guest page in question.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * @param iPhysExt The physical cross reference extent list to flush.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncvoid pgmPoolTrackFlushGCPhysPTs(PVM pVM, PPGMPAGE pPhysPage, uint16_t iPhysExt)
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync{
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync PPGMPOOL pPool = pVM->pgm.s.CTX_SUFF(pPool);
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync STAM_PROFILE_START(&pPool->StatTrackFlushGCPhysPTs, f);
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlow(("pgmPoolTrackFlushGCPhysPTs: HCPhys=%RHp iPhysExt\n", pPhysPage->HCPhys, iPhysExt));
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync const uint16_t iPhysExtStart = iPhysExt;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync PPGMPOOLPHYSEXT pPhysExt;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync do
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync {
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync Assert(iPhysExt < pPool->cMaxPhysExts);
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync pPhysExt = &pPool->CTX_SUFF(paPhysExts)[iPhysExt];
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pPhysExt->aidx); i++)
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync if (pPhysExt->aidx[i] != NIL_PGMPOOL_IDX)
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync {
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync pgmPoolTrackFlushGCPhysPTInt(pVM, pPhysPage, pPhysExt->aidx[i], 1);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pPhysExt->aidx[i] = NIL_PGMPOOL_IDX;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync /* next */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync iPhysExt = pPhysExt->iNext;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync } while (iPhysExt != NIL_PGMPOOL_PHYSEXT_INDEX);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* insert the list into the free list and clear the ram range entry. */
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync pPhysExt->iNext = pPool->iPhysExtFreeHead;
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync pPool->iPhysExtFreeHead = iPhysExtStart;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pPhysPage->HCPhys &= MM_RAM_FLAGS_NO_REFS_MASK; /** @todo PAGE FLAGS */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync STAM_PROFILE_STOP(&pPool->StatTrackFlushGCPhysPTs, f);
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync}
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync#endif /* PGMPOOL_WITH_GCPHYS_TRACKING */
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync/**
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync * Scans all shadow page tables for mappings of a physical page.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync *
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * This may be slow, but it's most likely more efficient than cleaning
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * out the entire page pool / cache.
92e624e40b06b4dc6d0a8222e1de33bd3e879a63vboxsync *
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * @returns VBox status code.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * @retval VINF_SUCCESS if all references has been successfully cleared.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * @retval VINF_PGM_GCPHYS_ALIASED if we're better off with a CR3 sync and
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * a page pool cleaning.
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync *
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync * @param pVM The VM handle.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * @param pPhysPage The guest page in question.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncint pgmPoolTrackFlushGCPhysPTsSlow(PVM pVM, PPGMPAGE pPhysPage)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync PPGMPOOL pPool = pVM->pgm.s.CTX_SUFF(pPool);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync STAM_PROFILE_START(&pPool->StatTrackFlushGCPhysPTsSlow, s);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync LogFlow(("pgmPoolTrackFlushGCPhysPTsSlow: cUsedPages=%d cPresent=%d HCPhys=%RHp\n",
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync pPool->cUsedPages, pPool->cPresent, pPhysPage->HCPhys));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#if 1
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /*
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * There is a limit to what makes sense.
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync */
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync if (pPool->cPresent > 1024)
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync {
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync LogFlow(("pgmPoolTrackFlushGCPhysPTsSlow: giving up... (cPresent=%d)\n", pPool->cPresent));
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync STAM_PROFILE_STOP(&pPool->StatTrackFlushGCPhysPTsSlow, s);
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync return VINF_PGM_GCPHYS_ALIASED;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync /*
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * Iterate all the pages until we've encountered all that in use.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * This is simple but not quite optimal solution.
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync */
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync const uint64_t u64 = PGM_PAGE_GET_HCPHYS(pPhysPage) | X86_PTE_P;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync const uint32_t u32 = u64;
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync unsigned cLeft = pPool->cUsedPages;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync unsigned iPage = pPool->cCurPages;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync while (--iPage >= PGMPOOL_IDX_FIRST)
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync {
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync PPGMPOOLPAGE pPage = &pPool->aPages[iPage];
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync if (pPage->GCPhys != NIL_RTGCPHYS)
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync {
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync switch (pPage->enmKind)
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync {
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync /*
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * We only care about shadow page tables.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync */
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_PT:
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_4MB:
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync case PGMPOOLKIND_32BIT_PT_FOR_PHYS:
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync {
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync unsigned cPresent = pPage->cPresent;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync PX86PT pPT = (PX86PT)PGMPOOL_PAGE_2_PTR(pVM, pPage);
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pPT->a); i++)
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync if (pPT->a[i].n.u1Present)
58c0567dee3cc3ebe62dec1e27f8e35bac4ddeb0vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if ((pPT->a[i].u & (X86_PTE_PG_MASK | X86_PTE_P)) == u32)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync //Log4(("pgmPoolTrackFlushGCPhysPTsSlow: idx=%d i=%d pte=%RX32\n", iPage, i, pPT->a[i]));
36f3c24e4ad9c6b813767db1faeabbe7e2ecc057vboxsync pPT->a[i].u = 0;
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync }
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync if (!--cPresent)
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync break;
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync }
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync break;
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync }
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_PT:
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_4MB:
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_PT:
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_2MB:
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync case PGMPOOLKIND_PAE_PT_FOR_PHYS:
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync {
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync unsigned cPresent = pPage->cPresent;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync PX86PTPAE pPT = (PX86PTPAE)PGMPOOL_PAGE_2_PTR(pVM, pPage);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pPT->a); i++)
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync if (pPT->a[i].n.u1Present)
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync {
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync if ((pPT->a[i].u & (X86_PTE_PAE_PG_MASK | X86_PTE_P)) == u64)
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync {
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync //Log4(("pgmPoolTrackFlushGCPhysPTsSlow: idx=%d i=%d pte=%RX64\n", iPage, i, pPT->a[i]));
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync pPT->a[i].u = 0;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync }
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync if (!--cPresent)
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync break;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync }
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync break;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync }
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync }
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync if (!--cLeft)
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync break;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync }
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync }
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync
9e17ca2e9d797e845e3284141dd4086a4b817ae5vboxsync pPhysPage->HCPhys &= MM_RAM_FLAGS_NO_REFS_MASK; /** @todo PAGE FLAGS */
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsync STAM_PROFILE_STOP(&pPool->StatTrackFlushGCPhysPTsSlow, s);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync return VINF_SUCCESS;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync/**
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync * Clears the user entry in a user table.
5366e994777f9d9391cf809dc77610f57270d75dvboxsync *
5366e994777f9d9391cf809dc77610f57270d75dvboxsync * This is used to remove all references to a page when flushing it.
5366e994777f9d9391cf809dc77610f57270d75dvboxsync */
5366e994777f9d9391cf809dc77610f57270d75dvboxsyncstatic void pgmPoolTrackClearPageUser(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PCPGMPOOLUSER pUser)
5366e994777f9d9391cf809dc77610f57270d75dvboxsync{
5366e994777f9d9391cf809dc77610f57270d75dvboxsync Assert(pUser->iUser != NIL_PGMPOOL_IDX);
5366e994777f9d9391cf809dc77610f57270d75dvboxsync Assert(pUser->iUser < pPool->cCurPages);
5366e994777f9d9391cf809dc77610f57270d75dvboxsync
5366e994777f9d9391cf809dc77610f57270d75dvboxsync /*
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Map the user page.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync PPGMPOOLPAGE pUserPage = &pPool->aPages[pUser->iUser];
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync union
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync {
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync uint64_t *pau64;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync uint32_t *pau32;
5366e994777f9d9391cf809dc77610f57270d75dvboxsync } u;
5366e994777f9d9391cf809dc77610f57270d75dvboxsync u.pau64 = (uint64_t *)PGMPOOL_PAGE_2_PTR(pPool->CTX_SUFF(pVM), pUserPage);
5366e994777f9d9391cf809dc77610f57270d75dvboxsync
5366e994777f9d9391cf809dc77610f57270d75dvboxsync /* Safety precaution in case we change the paging for other modes too in the future. */
5366e994777f9d9391cf809dc77610f57270d75dvboxsync Assert(PGMGetHyperCR3(pPool->CTX_SUFF(pVM)) != pPage->Core.Key);
5366e994777f9d9391cf809dc77610f57270d75dvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync#ifdef VBOX_STRICT
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /*
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * Some sanity checks.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync switch (pUserPage->enmKind)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync {
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync case PGMPOOLKIND_ROOT_32BIT_PD:
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync Assert(pUser->iUserTable < X86_PG_ENTRIES);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync Assert(!(u.pau32[pUser->iUserTable] & PGM_PDFLAGS_MAPPING));
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync break;
5366e994777f9d9391cf809dc77610f57270d75dvboxsync case PGMPOOLKIND_ROOT_PAE_PD:
5366e994777f9d9391cf809dc77610f57270d75dvboxsync Assert(pUser->iUserTable < 2048 && pUser->iUser == PGMPOOL_IDX_PAE_PD);
5366e994777f9d9391cf809dc77610f57270d75dvboxsync Assert(!(u.pau64[pUser->iUserTable] & PGM_PDFLAGS_MAPPING));
5366e994777f9d9391cf809dc77610f57270d75dvboxsync break;
5366e994777f9d9391cf809dc77610f57270d75dvboxsync case PGMPOOLKIND_ROOT_PDPT:
5366e994777f9d9391cf809dc77610f57270d75dvboxsync Assert(pUser->iUserTable < 4);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync Assert(!(u.pau64[pUser->iUserTable] & PGM_PLXFLAGS_PERMANENT));
5366e994777f9d9391cf809dc77610f57270d75dvboxsync break;
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync case PGMPOOLKIND_PAE_PD_FOR_32BIT_PD:
d8e12fa5dd1c35282b98cb165e42b6b395cf971bvboxsync case PGMPOOLKIND_PAE_PD_FOR_PAE_PD:
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync Assert(pUser->iUserTable < X86_PG_PAE_ENTRIES);
5366e994777f9d9391cf809dc77610f57270d75dvboxsync break;
5366e994777f9d9391cf809dc77610f57270d75dvboxsync case PGMPOOLKIND_64BIT_PD_FOR_64BIT_PD:
d8e12fa5dd1c35282b98cb165e42b6b395cf971bvboxsync Assert(pUser->iUserTable < X86_PG_PAE_ENTRIES);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync Assert(!(u.pau64[pUser->iUserTable] & PGM_PDFLAGS_MAPPING));
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync break;
5366e994777f9d9391cf809dc77610f57270d75dvboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_64BIT_PDPT:
5366e994777f9d9391cf809dc77610f57270d75dvboxsync Assert(pUser->iUserTable < X86_PG_PAE_ENTRIES);
5366e994777f9d9391cf809dc77610f57270d75dvboxsync Assert(!(u.pau64[pUser->iUserTable] & PGM_PLXFLAGS_PERMANENT));
5366e994777f9d9391cf809dc77610f57270d75dvboxsync break;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync case PGMPOOLKIND_64BIT_PML4_FOR_64BIT_PML4:
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Assert(!(u.pau64[pUser->iUserTable] & PGM_PLXFLAGS_PERMANENT));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* GCPhys >> PAGE_SHIFT is the index here */
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync break;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_PHYS:
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync case PGMPOOLKIND_64BIT_PD_FOR_PHYS:
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Assert(pUser->iUserTable < X86_PG_PAE_ENTRIES);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync break;
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync case PGMPOOLKIND_EPT_PDPT_FOR_PHYS:
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync case PGMPOOLKIND_EPT_PD_FOR_PHYS:
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync Assert(pUser->iUserTable < X86_PG_PAE_ENTRIES);
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync break;
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync case PGMPOOLKIND_ROOT_NESTED:
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Assert(pUser->iUserTable < X86_PG_PAE_ENTRIES);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync break;
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync default:
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync AssertMsgFailed(("enmKind=%d\n", pUserPage->enmKind));
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync break;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync }
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync#endif /* VBOX_STRICT */
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync /*
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * Clear the entry in the user page.
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync */
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync switch (pUserPage->enmKind)
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync {
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync /* 32-bit entries */
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync case PGMPOOLKIND_ROOT_32BIT_PD:
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync u.pau32[pUser->iUserTable] = 0;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync break;
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync /* 64-bit entries */
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync case PGMPOOLKIND_PAE_PD_FOR_32BIT_PD:
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync case PGMPOOLKIND_PAE_PD_FOR_PAE_PD:
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync case PGMPOOLKIND_64BIT_PD_FOR_64BIT_PD:
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_64BIT_PDPT:
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync case PGMPOOLKIND_64BIT_PML4_FOR_64BIT_PML4:
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_PHYS:
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync case PGMPOOLKIND_64BIT_PD_FOR_PHYS:
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync case PGMPOOLKIND_ROOT_PAE_PD:
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync case PGMPOOLKIND_ROOT_PDPT:
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync case PGMPOOLKIND_ROOT_NESTED:
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync case PGMPOOLKIND_EPT_PDPT_FOR_PHYS:
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync case PGMPOOLKIND_EPT_PD_FOR_PHYS:
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync u.pau64[pUser->iUserTable] = 0;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync break;
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync default:
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync AssertFatalMsgFailed(("enmKind=%d iUser=%#x iUserTable=%#x\n", pUserPage->enmKind, pUser->iUser, pUser->iUserTable));
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync }
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/**
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync * Clears all users of a page.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncstatic void pgmPoolTrackClearPageUsers(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /*
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync * Free all the user records.
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync */
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync PPGMPOOLUSER paUsers = pPool->CTX_SUFF(paUsers);
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync uint16_t i = pPage->iUserHead;
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync while (i != NIL_PGMPOOL_USER_INDEX)
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* Clear enter in user table. */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pgmPoolTrackClearPageUser(pPool, pPage, &paUsers[i]);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync /* Free it. */
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync const uint16_t iNext = paUsers[i].iNext;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync paUsers[i].iUser = NIL_PGMPOOL_IDX;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync paUsers[i].iNext = pPool->iUserFreeHead;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync pPool->iUserFreeHead = i;
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync /* Next. */
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync i = iNext;
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync }
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync pPage->iUserHead = NIL_PGMPOOL_USER_INDEX;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync}
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync#ifdef PGMPOOL_WITH_GCPHYS_TRACKING
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync/**
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync * Allocates a new physical cross reference extent.
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync *
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * @returns Pointer to the allocated extent on success. NULL if we're out of them.
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync * @param pVM The VM handle.
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync * @param piPhysExt Where to store the phys ext index.
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync */
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsyncPPGMPOOLPHYSEXT pgmPoolTrackPhysExtAlloc(PVM pVM, uint16_t *piPhysExt)
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync PPGMPOOL pPool = pVM->pgm.s.CTX_SUFF(pPool);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync uint16_t iPhysExt = pPool->iPhysExtFreeHead;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (iPhysExt == NIL_PGMPOOL_PHYSEXT_INDEX)
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync STAM_COUNTER_INC(&pPool->StamTrackPhysExtAllocFailures);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync return NULL;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync PPGMPOOLPHYSEXT pPhysExt = &pPool->CTX_SUFF(paPhysExts)[iPhysExt];
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync pPool->iPhysExtFreeHead = pPhysExt->iNext;
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync pPhysExt->iNext = NIL_PGMPOOL_PHYSEXT_INDEX;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync *piPhysExt = iPhysExt;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync return pPhysExt;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/**
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Frees a physical cross reference extent.
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsync *
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * @param pVM The VM handle.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * @param iPhysExt The extent to free.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncvoid pgmPoolTrackPhysExtFree(PVM pVM, uint16_t iPhysExt)
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync{
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync PPGMPOOL pPool = pVM->pgm.s.CTX_SUFF(pPool);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Assert(iPhysExt < pPool->cMaxPhysExts);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync PPGMPOOLPHYSEXT pPhysExt = &pPool->CTX_SUFF(paPhysExts)[iPhysExt];
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pPhysExt->aidx); i++)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pPhysExt->aidx[i] = NIL_PGMPOOL_IDX;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pPhysExt->iNext = pPool->iPhysExtFreeHead;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pPool->iPhysExtFreeHead = iPhysExt;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/**
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Frees a physical cross reference extent.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync *
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * @param pVM The VM handle.
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync * @param iPhysExt The extent to free.
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync */
cd5df721f068659172f3bf95de8fedeb465f057dvboxsyncvoid pgmPoolTrackPhysExtFreeList(PVM pVM, uint16_t iPhysExt)
45655563f818c5d5bbf4b3d14aa48cbd92a871f1vboxsync{
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync PPGMPOOL pPool = pVM->pgm.s.CTX_SUFF(pPool);
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync const uint16_t iPhysExtStart = iPhysExt;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync PPGMPOOLPHYSEXT pPhysExt;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync do
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync {
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsync Assert(iPhysExt < pPool->cMaxPhysExts);
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsync pPhysExt = &pPool->CTX_SUFF(paPhysExts)[iPhysExt];
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync for (unsigned i = 0; i < RT_ELEMENTS(pPhysExt->aidx); i++)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pPhysExt->aidx[i] = NIL_PGMPOOL_IDX;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* next */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync iPhysExt = pPhysExt->iNext;
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync } while (iPhysExt != NIL_PGMPOOL_PHYSEXT_INDEX);
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync pPhysExt->iNext = pPool->iPhysExtFreeHead;
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync pPool->iPhysExtFreeHead = iPhysExtStart;
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync}
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/**
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Insert a reference into a list of physical cross reference extents.
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync *
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * @returns The new ram range flags (top 16-bits).
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync *
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * @param pVM The VM handle.
5366e994777f9d9391cf809dc77610f57270d75dvboxsync * @param iPhysExt The physical extent index of the list head.
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync * @param iShwPT The shadow page table index.
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync *
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync */
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsyncstatic uint16_t pgmPoolTrackPhysExtInsert(PVM pVM, uint16_t iPhysExt, uint16_t iShwPT)
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync{
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync PPGMPOOL pPool = pVM->pgm.s.CTX_SUFF(pPool);
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync PPGMPOOLPHYSEXT paPhysExts = pPool->CTX_SUFF(paPhysExts);
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync
45655563f818c5d5bbf4b3d14aa48cbd92a871f1vboxsync /* special common case. */
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync if (paPhysExts[iPhysExt].aidx[2] == NIL_PGMPOOL_IDX)
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync {
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync paPhysExts[iPhysExt].aidx[2] = iShwPT;
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync STAM_COUNTER_INC(&pVM->pgm.s.StatTrackAliasedMany);
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync LogFlow(("pgmPoolTrackPhysExtAddref: %d:{,,%d}\n", iPhysExt, iShwPT));
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync return iPhysExt | (MM_RAM_FLAGS_CREFS_PHYSEXT << (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT));
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync }
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync /* general treatment. */
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync const uint16_t iPhysExtStart = iPhysExt;
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync unsigned cMax = 15;
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync for (;;)
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync {
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync Assert(iPhysExt < pPool->cMaxPhysExts);
cc1ef2ef9bbc6a0ff964928d61b7298e5bfcce5fvboxsync for (unsigned i = 0; i < RT_ELEMENTS(paPhysExts[iPhysExt].aidx); i++)
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync if (paPhysExts[iPhysExt].aidx[i] == NIL_PGMPOOL_IDX)
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync {
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync paPhysExts[iPhysExt].aidx[i] = iShwPT;
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync STAM_COUNTER_INC(&pVM->pgm.s.StatTrackAliasedMany);
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync LogFlow(("pgmPoolTrackPhysExtAddref: %d:{%d} i=%d cMax=%d\n", iPhysExt, iShwPT, i, cMax));
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync return iPhysExtStart | (MM_RAM_FLAGS_CREFS_PHYSEXT << (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT));
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync }
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync if (!--cMax)
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync {
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync STAM_COUNTER_INC(&pVM->pgm.s.StatTrackOverflows);
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync pgmPoolTrackPhysExtFreeList(pVM, iPhysExtStart);
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync LogFlow(("pgmPoolTrackPhysExtAddref: overflow (1) iShwPT=%d\n", iShwPT));
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync return MM_RAM_FLAGS_IDX_OVERFLOWED | (MM_RAM_FLAGS_CREFS_PHYSEXT << (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT));
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync }
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync }
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync /* add another extent to the list. */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync PPGMPOOLPHYSEXT pNew = pgmPoolTrackPhysExtAlloc(pVM, &iPhysExt);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync if (!pNew)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync {
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync STAM_COUNTER_INC(&pVM->pgm.s.StatTrackOverflows);
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync pgmPoolTrackPhysExtFreeList(pVM, iPhysExtStart);
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync return MM_RAM_FLAGS_IDX_OVERFLOWED | (MM_RAM_FLAGS_CREFS_PHYSEXT << (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT));
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync }
45655563f818c5d5bbf4b3d14aa48cbd92a871f1vboxsync pNew->iNext = iPhysExtStart;
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync pNew->aidx[0] = iShwPT;
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync LogFlow(("pgmPoolTrackPhysExtAddref: added new extent %d:{%d}->%d\n", iPhysExt, iShwPT, iPhysExtStart));
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync return iPhysExt | (MM_RAM_FLAGS_CREFS_PHYSEXT << (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT));
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync}
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync/**
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync * Add a reference to guest physical page where extents are in use.
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync *
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync * @returns The new ram range flags (top 16-bits).
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync *
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync * @param pVM The VM handle.
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync * @param u16 The ram range flags (top 16-bits).
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync * @param iShwPT The shadow page table index.
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync */
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsyncuint16_t pgmPoolTrackPhysExtAddref(PVM pVM, uint16_t u16, uint16_t iShwPT)
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync{
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync if ((u16 >> (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT)) != MM_RAM_FLAGS_CREFS_PHYSEXT)
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync {
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync /*
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync * Convert to extent list.
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync */
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync Assert((u16 >> (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT)) == 1);
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync uint16_t iPhysExt;
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync PPGMPOOLPHYSEXT pPhysExt = pgmPoolTrackPhysExtAlloc(pVM, &iPhysExt);
cc1ef2ef9bbc6a0ff964928d61b7298e5bfcce5fvboxsync if (pPhysExt)
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync {
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync LogFlow(("pgmPoolTrackPhysExtAddref: new extent: %d:{%d, %d}\n", iPhysExt, u16 & MM_RAM_FLAGS_IDX_MASK, iShwPT));
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync STAM_COUNTER_INC(&pVM->pgm.s.StatTrackAliased);
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync pPhysExt->aidx[0] = u16 & MM_RAM_FLAGS_IDX_MASK;
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync pPhysExt->aidx[1] = iShwPT;
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync u16 = iPhysExt | (MM_RAM_FLAGS_CREFS_PHYSEXT << (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT));
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync else
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync u16 = MM_RAM_FLAGS_IDX_OVERFLOWED | (MM_RAM_FLAGS_CREFS_PHYSEXT << (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync else if (u16 != (MM_RAM_FLAGS_IDX_OVERFLOWED | (MM_RAM_FLAGS_CREFS_PHYSEXT << (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT))))
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /*
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Insert into the extent list.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync */
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync u16 = pgmPoolTrackPhysExtInsert(pVM, u16 & MM_RAM_FLAGS_IDX_MASK, iShwPT);
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync }
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync else
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync STAM_COUNTER_INC(&pVM->pgm.s.StatTrackAliasedLots);
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync return u16;
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/**
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync * Clear references to guest physical memory.
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync *
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync * @param pPool The pool.
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync * @param pPage The page.
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync * @param pPhysPage Pointer to the aPages entry in the ram range.
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync */
687794577e2e35c3cae67e692a7f2130d1262a82vboxsyncvoid pgmPoolTrackPhysExtDerefGCPhys(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PPGMPAGE pPhysPage)
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync{
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync const unsigned cRefs = pPhysPage->HCPhys >> MM_RAM_FLAGS_CREFS_SHIFT; /** @todo PAGE FLAGS */
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync AssertFatalMsg(cRefs == MM_RAM_FLAGS_CREFS_PHYSEXT, ("cRefs=%d HCPhys=%RHp pPage=%p:{.idx=%d}\n", cRefs, pPhysPage->HCPhys, pPage, pPage->idx));
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync uint16_t iPhysExt = (pPhysPage->HCPhys >> MM_RAM_FLAGS_IDX_SHIFT) & MM_RAM_FLAGS_IDX_MASK;
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync if (iPhysExt != MM_RAM_FLAGS_IDX_OVERFLOWED)
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync {
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync uint16_t iPhysExtPrev = NIL_PGMPOOL_PHYSEXT_INDEX;
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync PPGMPOOLPHYSEXT paPhysExts = pPool->CTX_SUFF(paPhysExts);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync do
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Assert(iPhysExt < pPool->cMaxPhysExts);
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /*
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Look for the shadow page and check if it's all freed.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync for (unsigned i = 0; i < RT_ELEMENTS(paPhysExts[iPhysExt].aidx); i++)
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync {
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync if (paPhysExts[iPhysExt].aidx[i] == pPage->idx)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync paPhysExts[iPhysExt].aidx[i] = NIL_PGMPOOL_IDX;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync for (i = 0; i < RT_ELEMENTS(paPhysExts[iPhysExt].aidx); i++)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (paPhysExts[iPhysExt].aidx[i] != NIL_PGMPOOL_IDX)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync LogFlow(("pgmPoolTrackPhysExtDerefGCPhys: HCPhys=%RX64 idx=%d\n", pPhysPage->HCPhys, pPage->idx));
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync return;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* we can free the node. */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync PVM pVM = pPool->CTX_SUFF(pVM);
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync const uint16_t iPhysExtNext = paPhysExts[iPhysExt].iNext;
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync if ( iPhysExtPrev == NIL_PGMPOOL_PHYSEXT_INDEX
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync && iPhysExtNext == NIL_PGMPOOL_PHYSEXT_INDEX)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* lonely node */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pgmPoolTrackPhysExtFree(pVM, iPhysExt);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync LogFlow(("pgmPoolTrackPhysExtDerefGCPhys: HCPhys=%RX64 idx=%d lonely\n", pPhysPage->HCPhys, pPage->idx));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pPhysPage->HCPhys &= MM_RAM_FLAGS_NO_REFS_MASK; /** @todo PAGE FLAGS */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsync else if (iPhysExtPrev == NIL_PGMPOOL_PHYSEXT_INDEX)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* head */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync LogFlow(("pgmPoolTrackPhysExtDerefGCPhys: HCPhys=%RX64 idx=%d head\n", pPhysPage->HCPhys, pPage->idx));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pPhysPage->HCPhys = (pPhysPage->HCPhys & MM_RAM_FLAGS_NO_REFS_MASK) /** @todo PAGE FLAGS */
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync | ((uint64_t)MM_RAM_FLAGS_CREFS_PHYSEXT << MM_RAM_FLAGS_CREFS_SHIFT)
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync | ((uint64_t)iPhysExtNext << MM_RAM_FLAGS_IDX_SHIFT);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pgmPoolTrackPhysExtFree(pVM, iPhysExt);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync else
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* in list */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync LogFlow(("pgmPoolTrackPhysExtDerefGCPhys: HCPhys=%RX64 idx=%d\n", pPhysPage->HCPhys, pPage->idx));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync paPhysExts[iPhysExtPrev].iNext = iPhysExtNext;
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync pgmPoolTrackPhysExtFree(pVM, iPhysExt);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync iPhysExt = iPhysExtNext;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync return;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync }
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* next */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync iPhysExtPrev = iPhysExt;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync iPhysExt = paPhysExts[iPhysExt].iNext;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync } while (iPhysExt != NIL_PGMPOOL_PHYSEXT_INDEX);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AssertFatalMsgFailed(("not-found! cRefs=%d HCPhys=%RHp pPage=%p:{.idx=%d}\n", cRefs, pPhysPage->HCPhys, pPage, pPage->idx));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync else /* nothing to do */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync LogFlow(("pgmPoolTrackPhysExtDerefGCPhys: HCPhys=%RX64\n", pPhysPage->HCPhys));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync/**
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync * Clear references to guest physical memory.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync *
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * This is the same as pgmPoolTracDerefGCPhys except that the guest physical address
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * is assumed to be correct, so the linear search can be skipped and we can assert
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * at an earlier point.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync *
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * @param pPool The pool.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * @param pPage The page.
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * @param HCPhys The host physical address corresponding to the guest page.
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * @param GCPhys The guest physical address corresponding to HCPhys.
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync */
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsyncstatic void pgmPoolTracDerefGCPhys(PPGMPOOL pPool, PPGMPOOLPAGE pPage, RTHCPHYS HCPhys, RTGCPHYS GCPhys)
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync{
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync /*
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * Walk range list.
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync */
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync PPGMRAMRANGE pRam = pPool->CTX_SUFF(pVM)->pgm.s.CTX_SUFF(pRamRanges);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync while (pRam)
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync {
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync RTGCPHYS off = GCPhys - pRam->GCPhys;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync if (off < pRam->cb)
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync {
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync /* does it match? */
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync const unsigned iPage = off >> PAGE_SHIFT;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync Assert(PGM_PAGE_GET_HCPHYS(&pRam->aPages[iPage]));
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync#ifdef LOG_ENABLED
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsyncRTHCPHYS HCPhysPage = PGM_PAGE_GET_HCPHYS(&pRam->aPages[iPage]);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsyncLog(("pgmPoolTracDerefGCPhys %RHp vs %RHp\n", HCPhysPage, HCPhys));
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync#endif
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync if (PGM_PAGE_GET_HCPHYS(&pRam->aPages[iPage]) == HCPhys)
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync {
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync pgmTrackDerefGCPhys(pPool, pPage, &pRam->aPages[iPage]);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync return;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync }
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync break;
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync }
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync pRam = pRam->CTX_SUFF(pNext);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync }
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync AssertFatalMsgFailed(("HCPhys=%RHp GCPhys=%RGp\n", HCPhys, GCPhys));
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync}
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync/**
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * Clear references to guest physical memory.
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync *
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * @param pPool The pool.
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * @param pPage The page.
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * @param HCPhys The host physical address corresponding to the guest page.
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * @param GCPhysHint The guest physical address which may corresponding to HCPhys.
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync */
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsyncstatic void pgmPoolTracDerefGCPhysHint(PPGMPOOL pPool, PPGMPOOLPAGE pPage, RTHCPHYS HCPhys, RTGCPHYS GCPhysHint)
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync{
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync /*
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * Walk range list.
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync */
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync PPGMRAMRANGE pRam = pPool->CTX_SUFF(pVM)->pgm.s.CTX_SUFF(pRamRanges);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync while (pRam)
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync {
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync RTGCPHYS off = GCPhysHint - pRam->GCPhys;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync if (off < pRam->cb)
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync {
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync /* does it match? */
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync const unsigned iPage = off >> PAGE_SHIFT;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync Assert(PGM_PAGE_GET_HCPHYS(&pRam->aPages[iPage]));
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync if (PGM_PAGE_GET_HCPHYS(&pRam->aPages[iPage]) == HCPhys)
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync {
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync pgmTrackDerefGCPhys(pPool, pPage, &pRam->aPages[iPage]);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync return;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync }
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync break;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync }
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync pRam = pRam->CTX_SUFF(pNext);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync }
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync /*
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync * Damn, the hint didn't work. We'll have to do an expensive linear search.
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync */
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync STAM_COUNTER_INC(&pPool->StatTrackLinearRamSearches);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync pRam = pPool->CTX_SUFF(pVM)->pgm.s.CTX_SUFF(pRamRanges);
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync while (pRam)
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync {
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync unsigned iPage = pRam->cb >> PAGE_SHIFT;
9bff17fe6983cfda2ddd98f1979841bcb48e78e7vboxsync while (iPage-- > 0)
{
if (PGM_PAGE_GET_HCPHYS(&pRam->aPages[iPage]) == HCPhys)
{
Log4(("pgmPoolTracDerefGCPhysHint: Linear HCPhys=%RHp GCPhysHint=%RGp GCPhysReal=%RGp\n",
HCPhys, GCPhysHint, pRam->GCPhys + (iPage << PAGE_SHIFT)));
pgmTrackDerefGCPhys(pPool, pPage, &pRam->aPages[iPage]);
return;
}
}
pRam = pRam->CTX_SUFF(pNext);
}
AssertFatalMsgFailed(("HCPhys=%RHp GCPhysHint=%RGp\n", HCPhys, GCPhysHint));
}
/**
* Clear references to guest physical memory in a 32-bit / 32-bit page table.
*
* @param pPool The pool.
* @param pPage The page.
* @param pShwPT The shadow page table (mapping of the page).
* @param pGstPT The guest page table.
*/
DECLINLINE(void) pgmPoolTrackDerefPT32Bit32Bit(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PT pShwPT, PCX86PT pGstPT)
{
for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pShwPT->a); i++)
if (pShwPT->a[i].n.u1Present)
{
Log4(("pgmPoolTrackDerefPT32Bit32Bit: i=%d pte=%RX32 hint=%RX32\n",
i, pShwPT->a[i].u & X86_PTE_PG_MASK, pGstPT->a[i].u & X86_PTE_PG_MASK));
pgmPoolTracDerefGCPhysHint(pPool, pPage, pShwPT->a[i].u & X86_PTE_PG_MASK, pGstPT->a[i].u & X86_PTE_PG_MASK);
if (!--pPage->cPresent)
break;
}
}
/**
* Clear references to guest physical memory in a PAE / 32-bit page table.
*
* @param pPool The pool.
* @param pPage The page.
* @param pShwPT The shadow page table (mapping of the page).
* @param pGstPT The guest page table (just a half one).
*/
DECLINLINE(void) pgmPoolTrackDerefPTPae32Bit(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PTPAE pShwPT, PCX86PT pGstPT)
{
for (unsigned i = 0; i < RT_ELEMENTS(pShwPT->a); i++)
if (pShwPT->a[i].n.u1Present)
{
Log4(("pgmPoolTrackDerefPTPae32Bit: i=%d pte=%RX32 hint=%RX32\n",
i, pShwPT->a[i].u & X86_PTE_PAE_PG_MASK, pGstPT->a[i].u & X86_PTE_PG_MASK));
pgmPoolTracDerefGCPhysHint(pPool, pPage, pShwPT->a[i].u & X86_PTE_PAE_PG_MASK, pGstPT->a[i].u & X86_PTE_PG_MASK);
}
}
/**
* Clear references to guest physical memory in a PAE / PAE page table.
*
* @param pPool The pool.
* @param pPage The page.
* @param pShwPT The shadow page table (mapping of the page).
* @param pGstPT The guest page table.
*/
DECLINLINE(void) pgmPoolTrackDerefPTPaePae(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PTPAE pShwPT, PCX86PTPAE pGstPT)
{
for (unsigned i = 0; i < RT_ELEMENTS(pShwPT->a); i++)
if (pShwPT->a[i].n.u1Present)
{
Log4(("pgmPoolTrackDerefPTPaePae: i=%d pte=%RX32 hint=%RX32\n",
i, pShwPT->a[i].u & X86_PTE_PAE_PG_MASK, pGstPT->a[i].u & X86_PTE_PAE_PG_MASK));
pgmPoolTracDerefGCPhysHint(pPool, pPage, pShwPT->a[i].u & X86_PTE_PAE_PG_MASK, pGstPT->a[i].u & X86_PTE_PAE_PG_MASK);
}
}
/**
* Clear references to guest physical memory in a 32-bit / 4MB page table.
*
* @param pPool The pool.
* @param pPage The page.
* @param pShwPT The shadow page table (mapping of the page).
*/
DECLINLINE(void) pgmPoolTrackDerefPT32Bit4MB(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PT pShwPT)
{
RTGCPHYS GCPhys = pPage->GCPhys;
for (unsigned i = 0; i < RT_ELEMENTS(pShwPT->a); i++, GCPhys += PAGE_SIZE)
if (pShwPT->a[i].n.u1Present)
{
Log4(("pgmPoolTrackDerefPT32Bit4MB: i=%d pte=%RX32 GCPhys=%RGp\n",
i, pShwPT->a[i].u & X86_PTE_PG_MASK, GCPhys));
pgmPoolTracDerefGCPhys(pPool, pPage, pShwPT->a[i].u & X86_PTE_PG_MASK, GCPhys);
}
}
/**
* Clear references to guest physical memory in a PAE / 2/4MB page table.
*
* @param pPool The pool.
* @param pPage The page.
* @param pShwPT The shadow page table (mapping of the page).
*/
DECLINLINE(void) pgmPoolTrackDerefPTPaeBig(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PTPAE pShwPT)
{
RTGCPHYS GCPhys = pPage->GCPhys;
for (unsigned i = 0; i < RT_ELEMENTS(pShwPT->a); i++, GCPhys += PAGE_SIZE)
if (pShwPT->a[i].n.u1Present)
{
Log4(("pgmPoolTrackDerefPTPaeBig: i=%d pte=%RX64 hint=%RGp\n",
i, pShwPT->a[i].u & X86_PTE_PAE_PG_MASK, GCPhys));
pgmPoolTracDerefGCPhys(pPool, pPage, pShwPT->a[i].u & X86_PTE_PAE_PG_MASK, GCPhys);
}
}
#endif /* PGMPOOL_WITH_GCPHYS_TRACKING */
/**
* Clear references to shadowed pages in a PAE (legacy or 64 bits) page directory.
*
* @param pPool The pool.
* @param pPage The page.
* @param pShwPD The shadow page directory (mapping of the page).
*/
DECLINLINE(void) pgmPoolTrackDerefPDPae(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PDPAE pShwPD)
{
for (unsigned i = 0; i < RT_ELEMENTS(pShwPD->a); i++)
{
if (pShwPD->a[i].n.u1Present)
{
PPGMPOOLPAGE pSubPage = (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, pShwPD->a[i].u & X86_PDE_PAE_PG_MASK);
if (pSubPage)
pgmPoolTrackFreeUser(pPool, pSubPage, pPage->idx, i);
else
AssertFatalMsgFailed(("%RX64\n", pShwPD->a[i].u & X86_PDE_PAE_PG_MASK));
/** @todo 64-bit guests: have to ensure that we're not exhausting the dynamic mappings! */
}
}
}
/**
* Clear references to shadowed pages in a 64-bit page directory pointer table.
*
* @param pPool The pool.
* @param pPage The page.
* @param pShwPDPT The shadow page directory pointer table (mapping of the page).
*/
DECLINLINE(void) pgmPoolTrackDerefPDPT64Bit(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PDPT pShwPDPT)
{
for (unsigned i = 0; i < RT_ELEMENTS(pShwPDPT->a); i++)
{
if (pShwPDPT->a[i].n.u1Present)
{
PPGMPOOLPAGE pSubPage = (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, pShwPDPT->a[i].u & X86_PDPE_PG_MASK);
if (pSubPage)
pgmPoolTrackFreeUser(pPool, pSubPage, pPage->idx, i);
else
AssertFatalMsgFailed(("%RX64\n", pShwPDPT->a[i].u & X86_PDPE_PG_MASK));
/** @todo 64-bit guests: have to ensure that we're not exhausting the dynamic mappings! */
}
}
}
/**
* Clear references to shadowed pages in a 64-bit level 4 page table.
*
* @param pPool The pool.
* @param pPage The page.
* @param pShwPML4 The shadow page directory pointer table (mapping of the page).
*/
DECLINLINE(void) pgmPoolTrackDerefPML464Bit(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PML4 pShwPML4)
{
for (unsigned i = 0; i < RT_ELEMENTS(pShwPML4->a); i++)
{
if (pShwPML4->a[i].n.u1Present)
{
PPGMPOOLPAGE pSubPage = (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, pShwPML4->a[i].u & X86_PDPE_PG_MASK);
if (pSubPage)
pgmPoolTrackFreeUser(pPool, pSubPage, pPage->idx, i);
else
AssertFatalMsgFailed(("%RX64\n", pShwPML4->a[i].u & X86_PML4E_PG_MASK));
/** @todo 64-bit guests: have to ensure that we're not exhausting the dynamic mappings! */
}
}
}
/**
* Clear references to shadowed pages in an EPT page table.
*
* @param pPool The pool.
* @param pPage The page.
* @param pShwPML4 The shadow page directory pointer table (mapping of the page).
*/
DECLINLINE(void) pgmPoolTrackDerefPTEPT(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PEPTPT pShwPT)
{
RTGCPHYS GCPhys = pPage->GCPhys;
for (unsigned i = 0; i < RT_ELEMENTS(pShwPT->a); i++, GCPhys += PAGE_SIZE)
if (pShwPT->a[i].n.u1Present)
{
Log4(("pgmPoolTrackDerefPTEPT: i=%d pte=%RX64 GCPhys=%RX64\n",
i, pShwPT->a[i].u & EPT_PTE_PG_MASK, pPage->GCPhys));
pgmPoolTracDerefGCPhys(pPool, pPage, pShwPT->a[i].u & EPT_PTE_PG_MASK, GCPhys);
}
}
/**
* Clear references to shadowed pages in an EPT page directory.
*
* @param pPool The pool.
* @param pPage The page.
* @param pShwPD The shadow page directory (mapping of the page).
*/
DECLINLINE(void) pgmPoolTrackDerefPDEPT(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PEPTPD pShwPD)
{
for (unsigned i = 0; i < RT_ELEMENTS(pShwPD->a); i++)
{
if (pShwPD->a[i].n.u1Present)
{
PPGMPOOLPAGE pSubPage = (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, pShwPD->a[i].u & EPT_PDE_PG_MASK);
if (pSubPage)
pgmPoolTrackFreeUser(pPool, pSubPage, pPage->idx, i);
else
AssertFatalMsgFailed(("%RX64\n", pShwPD->a[i].u & EPT_PDE_PG_MASK));
/** @todo 64-bit guests: have to ensure that we're not exhausting the dynamic mappings! */
}
}
}
/**
* Clear references to shadowed pages in an EPT page directory pointer table.
*
* @param pPool The pool.
* @param pPage The page.
* @param pShwPDPT The shadow page directory pointer table (mapping of the page).
*/
DECLINLINE(void) pgmPoolTrackDerefPDPTEPT(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PEPTPDPT pShwPDPT)
{
for (unsigned i = 0; i < RT_ELEMENTS(pShwPDPT->a); i++)
{
if (pShwPDPT->a[i].n.u1Present)
{
PPGMPOOLPAGE pSubPage = (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, pShwPDPT->a[i].u & EPT_PDPTE_PG_MASK);
if (pSubPage)
pgmPoolTrackFreeUser(pPool, pSubPage, pPage->idx, i);
else
AssertFatalMsgFailed(("%RX64\n", pShwPDPT->a[i].u & EPT_PDPTE_PG_MASK));
/** @todo 64-bit guests: have to ensure that we're not exhausting the dynamic mappings! */
}
}
}
/**
* Clears all references made by this page.
*
* This includes other shadow pages and GC physical addresses.
*
* @param pPool The pool.
* @param pPage The page.
*/
static void pgmPoolTrackDeref(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
{
/*
* Map the shadow page and take action according to the page kind.
*/
void *pvShw = PGMPOOL_PAGE_2_PTR(pPool->CTX_SUFF(pVM), pPage);
switch (pPage->enmKind)
{
#ifdef PGMPOOL_WITH_GCPHYS_TRACKING
case PGMPOOLKIND_32BIT_PT_FOR_32BIT_PT:
{
STAM_PROFILE_START(&pPool->StatTrackDerefGCPhys, g);
void *pvGst;
int rc = PGM_GCPHYS_2_PTR(pPool->CTX_SUFF(pVM), pPage->GCPhys, &pvGst); AssertReleaseRC(rc);
pgmPoolTrackDerefPT32Bit32Bit(pPool, pPage, (PX86PT)pvShw, (PCX86PT)pvGst);
STAM_PROFILE_STOP(&pPool->StatTrackDerefGCPhys, g);
break;
}
case PGMPOOLKIND_PAE_PT_FOR_32BIT_PT:
{
STAM_PROFILE_START(&pPool->StatTrackDerefGCPhys, g);
void *pvGst;
int rc = PGM_GCPHYS_2_PTR_EX(pPool->CTX_SUFF(pVM), pPage->GCPhys, &pvGst); AssertReleaseRC(rc);
pgmPoolTrackDerefPTPae32Bit(pPool, pPage, (PX86PTPAE)pvShw, (PCX86PT)pvGst);
STAM_PROFILE_STOP(&pPool->StatTrackDerefGCPhys, g);
break;
}
case PGMPOOLKIND_PAE_PT_FOR_PAE_PT:
{
STAM_PROFILE_START(&pPool->StatTrackDerefGCPhys, g);
void *pvGst;
int rc = PGM_GCPHYS_2_PTR(pPool->CTX_SUFF(pVM), pPage->GCPhys, &pvGst); AssertReleaseRC(rc);
pgmPoolTrackDerefPTPaePae(pPool, pPage, (PX86PTPAE)pvShw, (PCX86PTPAE)pvGst);
STAM_PROFILE_STOP(&pPool->StatTrackDerefGCPhys, g);
break;
}
case PGMPOOLKIND_32BIT_PT_FOR_PHYS: /* treat it like a 4 MB page */
case PGMPOOLKIND_32BIT_PT_FOR_32BIT_4MB:
{
STAM_PROFILE_START(&pPool->StatTrackDerefGCPhys, g);
pgmPoolTrackDerefPT32Bit4MB(pPool, pPage, (PX86PT)pvShw);
STAM_PROFILE_STOP(&pPool->StatTrackDerefGCPhys, g);
break;
}
case PGMPOOLKIND_PAE_PT_FOR_PHYS: /* treat it like a 2 MB page */
case PGMPOOLKIND_PAE_PT_FOR_PAE_2MB:
case PGMPOOLKIND_PAE_PT_FOR_32BIT_4MB:
{
STAM_PROFILE_START(&pPool->StatTrackDerefGCPhys, g);
pgmPoolTrackDerefPTPaeBig(pPool, pPage, (PX86PTPAE)pvShw);
STAM_PROFILE_STOP(&pPool->StatTrackDerefGCPhys, g);
break;
}
#else /* !PGMPOOL_WITH_GCPHYS_TRACKING */
case PGMPOOLKIND_32BIT_PT_FOR_32BIT_PT:
case PGMPOOLKIND_PAE_PT_FOR_32BIT_PT:
case PGMPOOLKIND_PAE_PT_FOR_PAE_PT:
case PGMPOOLKIND_32BIT_PT_FOR_32BIT_4MB:
case PGMPOOLKIND_PAE_PT_FOR_PAE_2MB:
case PGMPOOLKIND_PAE_PT_FOR_32BIT_4MB:
case PGMPOOLKIND_32BIT_PT_FOR_PHYS:
case PGMPOOLKIND_PAE_PT_FOR_PHYS:
break;
#endif /* !PGMPOOL_WITH_GCPHYS_TRACKING */
case PGMPOOLKIND_PAE_PD_FOR_32BIT_PD:
case PGMPOOLKIND_PAE_PD_FOR_PAE_PD:
case PGMPOOLKIND_64BIT_PD_FOR_64BIT_PD:
case PGMPOOLKIND_64BIT_PD_FOR_PHYS:
pgmPoolTrackDerefPDPae(pPool, pPage, (PX86PDPAE)pvShw);
break;
case PGMPOOLKIND_64BIT_PDPT_FOR_PHYS:
case PGMPOOLKIND_64BIT_PDPT_FOR_64BIT_PDPT:
pgmPoolTrackDerefPDPT64Bit(pPool, pPage, (PX86PDPT)pvShw);
break;
case PGMPOOLKIND_64BIT_PML4_FOR_64BIT_PML4:
pgmPoolTrackDerefPML464Bit(pPool, pPage, (PX86PML4)pvShw);
break;
case PGMPOOLKIND_EPT_PT_FOR_PHYS:
pgmPoolTrackDerefPTEPT(pPool, pPage, (PEPTPT)pvShw);
break;
case PGMPOOLKIND_EPT_PD_FOR_PHYS:
pgmPoolTrackDerefPDEPT(pPool, pPage, (PEPTPD)pvShw);
break;
case PGMPOOLKIND_EPT_PDPT_FOR_PHYS:
pgmPoolTrackDerefPDPTEPT(pPool, pPage, (PEPTPDPT)pvShw);
break;
default:
AssertFatalMsgFailed(("enmKind=%d\n", pPage->enmKind));
}
/* paranoia, clear the shadow page. Remove this laser (i.e. let Alloc and ClearAll do it). */
STAM_PROFILE_START(&pPool->StatZeroPage, z);
ASMMemZeroPage(pvShw);
STAM_PROFILE_STOP(&pPool->StatZeroPage, z);
pPage->fZeroed = true;
}
#endif /* PGMPOOL_WITH_USER_TRACKING */
/**
* Flushes all the special root pages as part of a pgmPoolFlushAllInt operation.
*
* @param pPool The pool.
*/
static void pgmPoolFlushAllSpecialRoots(PPGMPOOL pPool)
{
/*
* These special pages are all mapped into the indexes 1..PGMPOOL_IDX_FIRST.
*/
Assert(NIL_PGMPOOL_IDX == 0);
for (unsigned i = 1; i < PGMPOOL_IDX_FIRST; i++)
{
/*
* Get the page address.
*/
PPGMPOOLPAGE pPage = &pPool->aPages[i];
union
{
uint64_t *pau64;
uint32_t *pau32;
} u;
u.pau64 = (uint64_t *)PGMPOOL_PAGE_2_PTR(pPool->CTX_SUFF(pVM), pPage);
/*
* Mark stuff not present.
*/
switch (pPage->enmKind)
{
case PGMPOOLKIND_ROOT_32BIT_PD:
for (unsigned iPage = 0; iPage < X86_PG_ENTRIES; iPage++)
if ((u.pau32[iPage] & (PGM_PDFLAGS_MAPPING | X86_PDE_P)) == X86_PDE_P)
u.pau32[iPage] = 0;
break;
case PGMPOOLKIND_ROOT_PAE_PD:
for (unsigned iPage = 0; iPage < X86_PG_PAE_ENTRIES * X86_PG_PAE_PDPE_ENTRIES; iPage++)
if ((u.pau64[iPage] & (PGM_PDFLAGS_MAPPING | X86_PDE_P)) == X86_PDE_P)
u.pau64[iPage] = 0;
break;
case PGMPOOLKIND_ROOT_PDPT:
/* Not root of shadowed pages currently, ignore it. */
break;
case PGMPOOLKIND_ROOT_NESTED:
ASMMemZero32(u.pau64, PAGE_SIZE);
break;
}
}
/*
* Paranoia (to be removed), flag a global CR3 sync.
*/
VM_FF_SET(pPool->CTX_SUFF(pVM), VM_FF_PGM_SYNC_CR3);
}
/**
* Flushes the entire cache.
*
* It will assert a global CR3 flush (FF) and assumes the caller is aware of this
* and execute this CR3 flush.
*
* @param pPool The pool.
*/
static void pgmPoolFlushAllInt(PPGMPOOL pPool)
{
STAM_PROFILE_START(&pPool->StatFlushAllInt, a);
LogFlow(("pgmPoolFlushAllInt:\n"));
/*
* If there are no pages in the pool, there is nothing to do.
*/
if (pPool->cCurPages <= PGMPOOL_IDX_FIRST)
{
STAM_PROFILE_STOP(&pPool->StatFlushAllInt, a);
return;
}
/*
* Nuke the free list and reinsert all pages into it.
*/
for (unsigned i = pPool->cCurPages - 1; i >= PGMPOOL_IDX_FIRST; i--)
{
PPGMPOOLPAGE pPage = &pPool->aPages[i];
#ifdef IN_RING3
Assert(pPage->Core.Key == MMPage2Phys(pPool->pVMR3, pPage->pvPageR3));
#endif
#ifdef PGMPOOL_WITH_MONITORING
if (pPage->fMonitored)
pgmPoolMonitorFlush(pPool, pPage);
pPage->iModifiedNext = NIL_PGMPOOL_IDX;
pPage->iModifiedPrev = NIL_PGMPOOL_IDX;
pPage->iMonitoredNext = NIL_PGMPOOL_IDX;
pPage->iMonitoredPrev = NIL_PGMPOOL_IDX;
pPage->cModifications = 0;
#endif
pPage->GCPhys = NIL_RTGCPHYS;
pPage->enmKind = PGMPOOLKIND_FREE;
Assert(pPage->idx == i);
pPage->iNext = i + 1;
pPage->fZeroed = false; /* This could probably be optimized, but better safe than sorry. */
pPage->fSeenNonGlobal = false;
pPage->fMonitored= false;
pPage->fCached = false;
pPage->fReusedFlushPending = false;
pPage->fCR3Mix = false;
#ifdef PGMPOOL_WITH_USER_TRACKING
pPage->iUserHead = NIL_PGMPOOL_USER_INDEX;
#endif
#ifdef PGMPOOL_WITH_CACHE
pPage->iAgeNext = NIL_PGMPOOL_IDX;
pPage->iAgePrev = NIL_PGMPOOL_IDX;
#endif
}
pPool->aPages[pPool->cCurPages - 1].iNext = NIL_PGMPOOL_IDX;
pPool->iFreeHead = PGMPOOL_IDX_FIRST;
pPool->cUsedPages = 0;
#ifdef PGMPOOL_WITH_USER_TRACKING
/*
* Zap and reinitialize the user records.
*/
pPool->cPresent = 0;
pPool->iUserFreeHead = 0;
PPGMPOOLUSER paUsers = pPool->CTX_SUFF(paUsers);
const unsigned cMaxUsers = pPool->cMaxUsers;
for (unsigned i = 0; i < cMaxUsers; i++)
{
paUsers[i].iNext = i + 1;
paUsers[i].iUser = NIL_PGMPOOL_IDX;
paUsers[i].iUserTable = 0xfffffffe;
}
paUsers[cMaxUsers - 1].iNext = NIL_PGMPOOL_USER_INDEX;
#endif
#ifdef PGMPOOL_WITH_GCPHYS_TRACKING
/*
* Clear all the GCPhys links and rebuild the phys ext free list.
*/
for (PPGMRAMRANGE pRam = pPool->CTX_SUFF(pVM)->pgm.s.CTX_SUFF(pRamRanges);
pRam;
pRam = pRam->CTX_SUFF(pNext))
{
unsigned iPage = pRam->cb >> PAGE_SHIFT;
while (iPage-- > 0)
pRam->aPages[iPage].HCPhys &= MM_RAM_FLAGS_NO_REFS_MASK; /** @todo PAGE FLAGS */
}
pPool->iPhysExtFreeHead = 0;
PPGMPOOLPHYSEXT paPhysExts = pPool->CTX_SUFF(paPhysExts);
const unsigned cMaxPhysExts = pPool->cMaxPhysExts;
for (unsigned i = 0; i < cMaxPhysExts; i++)
{
paPhysExts[i].iNext = i + 1;
paPhysExts[i].aidx[0] = NIL_PGMPOOL_IDX;
paPhysExts[i].aidx[1] = NIL_PGMPOOL_IDX;
paPhysExts[i].aidx[2] = NIL_PGMPOOL_IDX;
}
paPhysExts[cMaxPhysExts - 1].iNext = NIL_PGMPOOL_PHYSEXT_INDEX;
#endif
#ifdef PGMPOOL_WITH_MONITORING
/*
* Just zap the modified list.
*/
pPool->cModifiedPages = 0;
pPool->iModifiedHead = NIL_PGMPOOL_IDX;
#endif
#ifdef PGMPOOL_WITH_CACHE
/*
* Clear the GCPhys hash and the age list.
*/
for (unsigned i = 0; i < RT_ELEMENTS(pPool->aiHash); i++)
pPool->aiHash[i] = NIL_PGMPOOL_IDX;
pPool->iAgeHead = NIL_PGMPOOL_IDX;
pPool->iAgeTail = NIL_PGMPOOL_IDX;
#endif
/*
* Flush all the special root pages.
* Reinsert active pages into the hash and ensure monitoring chains are correct.
*/
pgmPoolFlushAllSpecialRoots(pPool);
for (unsigned i = PGMPOOL_IDX_FIRST_SPECIAL; i < PGMPOOL_IDX_FIRST; i++)
{
PPGMPOOLPAGE pPage = &pPool->aPages[i];
pPage->iNext = NIL_PGMPOOL_IDX;
#ifdef PGMPOOL_WITH_MONITORING
pPage->iModifiedNext = NIL_PGMPOOL_IDX;
pPage->iModifiedPrev = NIL_PGMPOOL_IDX;
pPage->cModifications = 0;
/* ASSUMES that we're not sharing with any of the other special pages (safe for now). */
pPage->iMonitoredNext = NIL_PGMPOOL_IDX;
pPage->iMonitoredPrev = NIL_PGMPOOL_IDX;
if (pPage->fMonitored)
{
PVM pVM = pPool->CTX_SUFF(pVM);
int rc = PGMHandlerPhysicalChangeCallbacks(pVM, pPage->GCPhys & ~(RTGCPHYS)(PAGE_SIZE - 1),
pPool->pfnAccessHandlerR3, MMHyperCCToR3(pVM, pPage),
pPool->pfnAccessHandlerR0, MMHyperCCToR0(pVM, pPage),
pPool->pfnAccessHandlerRC, MMHyperCCToRC(pVM, pPage),
pPool->pszAccessHandler);
AssertFatalRCSuccess(rc);
# ifdef PGMPOOL_WITH_CACHE
pgmPoolHashInsert(pPool, pPage);
# endif
}
#endif
#ifdef PGMPOOL_WITH_USER_TRACKING
Assert(pPage->iUserHead == NIL_PGMPOOL_USER_INDEX); /* for now */
#endif
#ifdef PGMPOOL_WITH_CACHE
Assert(pPage->iAgeNext == NIL_PGMPOOL_IDX);
Assert(pPage->iAgePrev == NIL_PGMPOOL_IDX);
#endif
}
STAM_PROFILE_STOP(&pPool->StatFlushAllInt, a);
}
/**
* Flushes a pool page.
*
* This moves the page to the free list after removing all user references to it.
* In GC this will cause a CR3 reload if the page is traced back to an active root page.
*
* @returns VBox status code.
* @retval VINF_SUCCESS on success.
* @retval VERR_PGM_POOL_CLEARED if the deregistration of the physical handler will cause a light weight pool flush.
* @param pPool The pool.
* @param HCPhys The HC physical address of the shadow page.
*/
int pgmPoolFlushPage(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
{
int rc = VINF_SUCCESS;
STAM_PROFILE_START(&pPool->StatFlushPage, f);
LogFlow(("pgmPoolFlushPage: pPage=%p:{.Key=%RHp, .idx=%d, .enmKind=%d, .GCPhys=%RGp}\n",
pPage, pPage->Core.Key, pPage->idx, pPage->enmKind, pPage->GCPhys));
/*
* Quietly reject any attempts at flushing any of the special root pages.
*/
if (pPage->idx < PGMPOOL_IDX_FIRST)
{
Log(("pgmPoolFlushPage: special root page, rejected. enmKind=%d idx=%d\n", pPage->enmKind, pPage->idx));
return VINF_SUCCESS;
}
/*
* Quietly reject any attempts at flushing the currently active shadow CR3 mapping
*/
if (PGMGetHyperCR3(pPool->CTX_SUFF(pVM)) == pPage->Core.Key)
{
AssertMsg(pPage->enmKind == PGMPOOLKIND_64BIT_PML4_FOR_64BIT_PML4,
("Can't free the shadow CR3! (%RHp vs %RHp kind=%d\n", PGMGetHyperCR3(pPool->CTX_SUFF(pVM)), pPage->Core.Key, pPage->enmKind));
Log(("pgmPoolFlushPage: current active shadow CR3, rejected. enmKind=%d idx=%d\n", pPage->enmKind, pPage->idx));
return VINF_SUCCESS;
}
/*
* Mark the page as being in need of a ASMMemZeroPage().
*/
pPage->fZeroed = false;
#ifdef PGMPOOL_WITH_USER_TRACKING
/*
* Clear the page.
*/
pgmPoolTrackClearPageUsers(pPool, pPage);
STAM_PROFILE_START(&pPool->StatTrackDeref,a);
pgmPoolTrackDeref(pPool, pPage);
STAM_PROFILE_STOP(&pPool->StatTrackDeref,a);
#endif
#ifdef PGMPOOL_WITH_CACHE
/*
* Flush it from the cache.
*/
pgmPoolCacheFlushPage(pPool, pPage);
#endif /* PGMPOOL_WITH_CACHE */
#ifdef PGMPOOL_WITH_MONITORING
/*
* Deregistering the monitoring.
*/
if (pPage->fMonitored)
rc = pgmPoolMonitorFlush(pPool, pPage);
#endif
/*
* Free the page.
*/
Assert(pPage->iNext == NIL_PGMPOOL_IDX);
pPage->iNext = pPool->iFreeHead;
pPool->iFreeHead = pPage->idx;
pPage->enmKind = PGMPOOLKIND_FREE;
pPage->GCPhys = NIL_RTGCPHYS;
pPage->fReusedFlushPending = false;
pPool->cUsedPages--;
STAM_PROFILE_STOP(&pPool->StatFlushPage, f);
return rc;
}
/**
* Frees a usage of a pool page.
*
* The caller is responsible to updating the user table so that it no longer
* references the shadow page.
*
* @param pPool The pool.
* @param HCPhys The HC physical address of the shadow page.
* @param iUser The shadow page pool index of the user table.
* @param iUserTable The index into the user table (shadowed).
*/
void pgmPoolFreeByPage(PPGMPOOL pPool, PPGMPOOLPAGE pPage, uint16_t iUser, uint32_t iUserTable)
{
STAM_PROFILE_START(&pPool->StatFree, a);
LogFlow(("pgmPoolFreeByPage: pPage=%p:{.Key=%RHp, .idx=%d, enmKind=%d} iUser=%#x iUserTable=%#x\n",
pPage, pPage->Core.Key, pPage->idx, pPage->enmKind, iUser, iUserTable));
Assert(pPage->idx >= PGMPOOL_IDX_FIRST);
#ifdef PGMPOOL_WITH_USER_TRACKING
pgmPoolTrackFreeUser(pPool, pPage, iUser, iUserTable);
#endif
#ifdef PGMPOOL_WITH_CACHE
if (!pPage->fCached)
#endif
pgmPoolFlushPage(pPool, pPage); /* ASSUMES that VERR_PGM_POOL_CLEARED can be ignored here. */
STAM_PROFILE_STOP(&pPool->StatFree, a);
}
/**
* Makes one or more free page free.
*
* @returns VBox status code.
* @retval VINF_SUCCESS on success.
* @retval VERR_PGM_POOL_FLUSHED if the pool was flushed.
*
* @param pPool The pool.
* @param iUser The user of the page.
*/
static int pgmPoolMakeMoreFreePages(PPGMPOOL pPool, uint16_t iUser)
{
LogFlow(("pgmPoolMakeMoreFreePages: iUser=%#x\n", iUser));
/*
* If the pool isn't full grown yet, expand it.
*/
if (pPool->cCurPages < pPool->cMaxPages)
{
STAM_PROFILE_ADV_SUSPEND(&pPool->StatAlloc, a);
#ifdef IN_RING3
int rc = PGMR3PoolGrow(pPool->pVMR3);
#else
int rc = CTXALLMID(VMM, CallHost)(pPool->CTX_SUFF(pVM), VMMCALLHOST_PGM_POOL_GROW, 0);
#endif
if (RT_FAILURE(rc))
return rc;
STAM_PROFILE_ADV_RESUME(&pPool->StatAlloc, a);
if (pPool->iFreeHead != NIL_PGMPOOL_IDX)
return VINF_SUCCESS;
}
#ifdef PGMPOOL_WITH_CACHE
/*
* Free one cached page.
*/
return pgmPoolCacheFreeOne(pPool, iUser);
#else
/*
* Flush the pool.
* If we have tracking enabled, it should be possible to come up with
* a cheap replacement strategy...
*/
/* @todo incompatible with long mode paging (cr3 root will be flushed) */
Assert(!CPUMIsGuestInLongMode(pVM));
pgmPoolFlushAllInt(pPool);
return VERR_PGM_POOL_FLUSHED;
#endif
}
/**
* Allocates a page from the pool.
*
* This page may actually be a cached page and not in need of any processing
* on the callers part.
*
* @returns VBox status code.
* @retval VINF_SUCCESS if a NEW page was allocated.
* @retval VINF_PGM_CACHED_PAGE if a CACHED page was returned.
* @retval VERR_PGM_POOL_FLUSHED if the pool was flushed.
* @param pVM The VM handle.
* @param GCPhys The GC physical address of the page we're gonna shadow.
* For 4MB and 2MB PD entries, it's the first address the
* shadow PT is covering.
* @param enmKind The kind of mapping.
* @param iUser The shadow page pool index of the user table.
* @param iUserTable The index into the user table (shadowed).
* @param ppPage Where to store the pointer to the page. NULL is stored here on failure.
*/
int pgmPoolAlloc(PVM pVM, RTGCPHYS GCPhys, PGMPOOLKIND enmKind, uint16_t iUser, uint32_t iUserTable, PPPGMPOOLPAGE ppPage)
{
PPGMPOOL pPool = pVM->pgm.s.CTX_SUFF(pPool);
STAM_PROFILE_ADV_START(&pPool->StatAlloc, a);
LogFlow(("pgmPoolAlloc: GCPhys=%RGp enmKind=%d iUser=%#x iUserTable=%#x\n", GCPhys, enmKind, iUser, iUserTable));
*ppPage = NULL;
#ifdef PGMPOOL_WITH_CACHE
if (pPool->fCacheEnabled)
{
int rc2 = pgmPoolCacheAlloc(pPool, GCPhys, enmKind, iUser, iUserTable, ppPage);
if (RT_SUCCESS(rc2))
{
STAM_PROFILE_ADV_STOP(&pPool->StatAlloc, a);
LogFlow(("pgmPoolAlloc: cached returns %Rrc *ppPage=%p:{.Key=%RHp, .idx=%d}\n", rc2, *ppPage, (*ppPage)->Core.Key, (*ppPage)->idx));
return rc2;
}
}
#endif
/*
* Allocate a new one.
*/
int rc = VINF_SUCCESS;
uint16_t iNew = pPool->iFreeHead;
if (iNew == NIL_PGMPOOL_IDX)
{
rc = pgmPoolMakeMoreFreePages(pPool, iUser);
if (RT_FAILURE(rc))
{
if (rc != VERR_PGM_POOL_CLEARED)
{
Log(("pgmPoolAlloc: returns %Rrc (Free)\n", rc));
STAM_PROFILE_ADV_STOP(&pPool->StatAlloc, a);
return rc;
}
Log(("pgmPoolMakeMoreFreePages failed with %Rrc -> return VERR_PGM_POOL_FLUSHED\n", rc));
rc = VERR_PGM_POOL_FLUSHED;
}
iNew = pPool->iFreeHead;
AssertReleaseReturn(iNew != NIL_PGMPOOL_IDX, VERR_INTERNAL_ERROR);
}
/* unlink the free head */
PPGMPOOLPAGE pPage = &pPool->aPages[iNew];
pPool->iFreeHead = pPage->iNext;
pPage->iNext = NIL_PGMPOOL_IDX;
/*
* Initialize it.
*/
pPool->cUsedPages++; /* physical handler registration / pgmPoolTrackFlushGCPhysPTsSlow requirement. */
pPage->enmKind = enmKind;
pPage->GCPhys = GCPhys;
pPage->fSeenNonGlobal = false; /* Set this to 'true' to disable this feature. */
pPage->fMonitored = false;
pPage->fCached = false;
pPage->fReusedFlushPending = false;
pPage->fCR3Mix = false;
#ifdef PGMPOOL_WITH_MONITORING
pPage->cModifications = 0;
pPage->iModifiedNext = NIL_PGMPOOL_IDX;
pPage->iModifiedPrev = NIL_PGMPOOL_IDX;
#endif
#ifdef PGMPOOL_WITH_USER_TRACKING
pPage->cPresent = 0;
pPage->iFirstPresent = ~0;
/*
* Insert into the tracking and cache. If this fails, free the page.
*/
int rc3 = pgmPoolTrackInsert(pPool, pPage, GCPhys, iUser, iUserTable);
if (RT_FAILURE(rc3))
{
if (rc3 != VERR_PGM_POOL_CLEARED)
{
pPool->cUsedPages--;
pPage->enmKind = PGMPOOLKIND_FREE;
pPage->GCPhys = NIL_RTGCPHYS;
pPage->iNext = pPool->iFreeHead;
pPool->iFreeHead = pPage->idx;
STAM_PROFILE_ADV_STOP(&pPool->StatAlloc, a);
Log(("pgmPoolAlloc: returns %Rrc (Insert)\n", rc3));
return rc3;
}
Log(("pgmPoolTrackInsert failed with %Rrc -> return VERR_PGM_POOL_FLUSHED\n", rc3));
rc = VERR_PGM_POOL_FLUSHED;
}
#endif /* PGMPOOL_WITH_USER_TRACKING */
/*
* Commit the allocation, clear the page and return.
*/
#ifdef VBOX_WITH_STATISTICS
if (pPool->cUsedPages > pPool->cUsedPagesHigh)
pPool->cUsedPagesHigh = pPool->cUsedPages;
#endif
if (!pPage->fZeroed)
{
STAM_PROFILE_START(&pPool->StatZeroPage, z);
void *pv = PGMPOOL_PAGE_2_PTR(pVM, pPage);
ASMMemZeroPage(pv);
STAM_PROFILE_STOP(&pPool->StatZeroPage, z);
}
*ppPage = pPage;
LogFlow(("pgmPoolAlloc: returns %Rrc *ppPage=%p:{.Key=%RHp, .idx=%d, .fCached=%RTbool, .fMonitored=%RTbool}\n",
rc, pPage, pPage->Core.Key, pPage->idx, pPage->fCached, pPage->fMonitored));
STAM_PROFILE_ADV_STOP(&pPool->StatAlloc, a);
return rc;
}
/**
* Frees a usage of a pool page.
*
* @param pVM The VM handle.
* @param HCPhys The HC physical address of the shadow page.
* @param iUser The shadow page pool index of the user table.
* @param iUserTable The index into the user table (shadowed).
*/
void pgmPoolFree(PVM pVM, RTHCPHYS HCPhys, uint16_t iUser, uint32_t iUserTable)
{
LogFlow(("pgmPoolFree: HCPhys=%RHp iUser=%#x iUserTable=%#x\n", HCPhys, iUser, iUserTable));
PPGMPOOL pPool = pVM->pgm.s.CTX_SUFF(pPool);
pgmPoolFreeByPage(pPool, pgmPoolGetPage(pPool, HCPhys), iUser, iUserTable);
}
/**
* Gets a in-use page in the pool by it's physical address.
*
* @returns Pointer to the page.
* @param pVM The VM handle.
* @param HCPhys The HC physical address of the shadow page.
* @remark This function will NEVER return NULL. It will assert if HCPhys is invalid.
*/
PPGMPOOLPAGE pgmPoolGetPageByHCPhys(PVM pVM, RTHCPHYS HCPhys)
{
/** @todo profile this! */
PPGMPOOL pPool = pVM->pgm.s.CTX_SUFF(pPool);
PPGMPOOLPAGE pPage = pgmPoolGetPage(pPool, HCPhys);
Log3(("pgmPoolGetPageByHCPhys: HCPhys=%RHp -> %p:{.idx=%d .GCPhys=%RGp .enmKind=%d}\n",
HCPhys, pPage, pPage->idx, pPage->GCPhys, pPage->enmKind));
return pPage;
}
/**
* Flushes the entire cache.
*
* It will assert a global CR3 flush (FF) and assumes the caller is aware of this
* and execute this CR3 flush.
*
* @param pPool The pool.
*/
void pgmPoolFlushAll(PVM pVM)
{
LogFlow(("pgmPoolFlushAll:\n"));
pgmPoolFlushAllInt(pVM->pgm.s.CTX_SUFF(pPool));
}