PGMAllPool.cpp revision 3dafd1633a0838d51a02c30dc1451b822a3892bd
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync/* $Id$ */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/** @file
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * PGM Shadow Page Pool.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/*
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync * Copyright (C) 2006-2010 Oracle Corporation
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * available from http://www.virtualbox.org. This file is free software;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * you can redistribute it and/or modify it under the terms of the GNU
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * General Public License (GPL) as published by the Free Software
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/*******************************************************************************
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync* Header Files *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync*******************************************************************************/
d200be7337d4aad2bec2961a885e856f7866d4f6vboxsync#define LOG_GROUP LOG_GROUP_PGM_POOL
2624f7a939f765d1975a82f3072c272f7fa3548dvboxsync#include <VBox/pgm.h>
d200be7337d4aad2bec2961a885e856f7866d4f6vboxsync#include <VBox/mm.h>
d200be7337d4aad2bec2961a885e856f7866d4f6vboxsync#include <VBox/em.h>
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync#include <VBox/cpum.h>
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync#ifdef IN_RC
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync# include <VBox/patm.h>
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#endif
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#include "../PGMInternal.h"
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#include <VBox/vm.h>
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#include "../PGMInline.h"
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#include <VBox/disopcode.h>
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#include <VBox/hwacc_vmx.h>
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#include <VBox/log.h>
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#include <VBox/err.h>
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#include <iprt/asm.h>
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#include <iprt/asm-amd64-x86.h>
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#include <iprt/string.h>
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/*******************************************************************************
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync* Internal Functions *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync*******************************************************************************/
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncRT_C_DECLS_BEGIN
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncstatic void pgmPoolFlushAllInt(PPGMPOOL pPool);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncDECLINLINE(unsigned) pgmPoolTrackGetShadowEntrySize(PGMPOOLKIND enmKind);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncDECLINLINE(unsigned) pgmPoolTrackGetGuestEntrySize(PGMPOOLKIND enmKind);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncstatic void pgmPoolTrackDeref(PPGMPOOL pPool, PPGMPOOLPAGE pPage);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncstatic int pgmPoolTrackAddUser(PPGMPOOL pPool, PPGMPOOLPAGE pPage, uint16_t iUser, uint32_t iUserTable);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncstatic void pgmPoolMonitorModifiedRemove(PPGMPOOL pPool, PPGMPOOLPAGE pPage);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#ifndef IN_RING3
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsyncDECLEXPORT(int) pgmPoolAccessHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPHYS GCPhysFault, void *pvUser);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#endif
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync#ifdef LOG_ENABLED
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsyncstatic const char *pgmPoolPoolKindToStr(uint8_t enmKind);
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync#endif
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync#if defined(VBOX_STRICT) && defined(PGMPOOL_WITH_OPTIMIZED_DIRTY_PT)
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsyncstatic void pgmPoolTrackCheckPTPaePae(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PPGMSHWPTPAE pShwPT, PCX86PTPAE pGstPT);
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync#endif
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsyncint pgmPoolTrackFlushGCPhysPTsSlow(PVM pVM, PPGMPAGE pPhysPage);
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsyncPPGMPOOLPHYSEXT pgmPoolTrackPhysExtAlloc(PVM pVM, uint16_t *piPhysExt);
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsyncvoid pgmPoolTrackPhysExtFree(PVM pVM, uint16_t iPhysExt);
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsyncvoid pgmPoolTrackPhysExtFreeList(PVM pVM, uint16_t iPhysExt);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncRT_C_DECLS_END
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Checks if the specified page pool kind is for a 4MB or 2MB guest page.
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync *
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync * @returns true if it's the shadow of a 4MB or 2MB guest page, otherwise false.
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync * @param enmKind The page kind.
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync */
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsyncDECLINLINE(bool) pgmPoolIsBigPage(PGMPOOLKIND enmKind)
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync{
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync switch (enmKind)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_4MB:
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_4MB:
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_2MB:
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync return true;
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync default:
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync return false;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
d200be7337d4aad2bec2961a885e856f7866d4f6vboxsync}
d200be7337d4aad2bec2961a885e856f7866d4f6vboxsync
d200be7337d4aad2bec2961a885e856f7866d4f6vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Flushes a chain of pages sharing the same access monitor.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @returns VBox status code suitable for scheduling.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPool The pool.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPage A page in the chain.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @todo VBOXSTRICTRC
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsyncint pgmPoolMonitorChainFlush(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync{
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync LogFlow(("pgmPoolMonitorChainFlush: Flush page %RGp type=%d\n", pPage->GCPhys, pPage->enmKind));
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync /*
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync * Find the list head.
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync */
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync uint16_t idx = pPage->idx;
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync if (pPage->iMonitoredPrev != NIL_PGMPOOL_IDX)
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync {
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync while (pPage->iMonitoredPrev != NIL_PGMPOOL_IDX)
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync {
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync idx = pPage->iMonitoredPrev;
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync Assert(idx != pPage->idx);
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync pPage = &pPool->aPages[idx];
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync }
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync }
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync /*
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync * Iterate the list flushing each shadow page.
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync */
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync int rc = VINF_SUCCESS;
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync for (;;)
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync {
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync idx = pPage->iMonitoredNext;
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync Assert(idx != pPage->idx);
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync if (pPage->idx >= PGMPOOL_IDX_FIRST)
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync {
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync int rc2 = pgmPoolFlushPage(pPool, pPage);
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync AssertRC(rc2);
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync }
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync /* next */
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync if (idx == NIL_PGMPOOL_IDX)
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync break;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync pPage = &pPool->aPages[idx];
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync }
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync return rc;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync/**
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync * Wrapper for getting the current context pointer to the entry being modified.
e94ff1af89bf631c68367d4e291ddbb491b5e5c0vboxsync *
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync * @returns VBox status code suitable for scheduling.
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync * @param pVM VM Handle.
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync * @param pvDst Destination address
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pvSrc Source guest virtual address.
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync * @param GCPhysSrc The source guest physical address.
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync * @param cb Size of data to read
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync */
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsyncDECLINLINE(int) pgmPoolPhysSimpleReadGCPhys(PVM pVM, void *pvDst, CTXTYPE(RTGCPTR, RTHCPTR, RTGCPTR) pvSrc, RTGCPHYS GCPhysSrc, size_t cb)
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#if defined(IN_RING3)
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync memcpy(pvDst, (RTHCPTR)((uintptr_t)pvSrc & ~(RTHCUINTPTR)(cb - 1)), cb);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return VINF_SUCCESS;
e94ff1af89bf631c68367d4e291ddbb491b5e5c0vboxsync#else
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* @todo in RC we could attempt to use the virtual address, although this can cause many faults (PAE Windows XP guest). */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return PGMPhysSimpleReadGCPhys(pVM, pvDst, GCPhysSrc & ~(RTGCPHYS)(cb - 1), cb);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#endif
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Process shadow entries before they are changed by the guest.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * For PT entries we will clear them. For PD entries, we'll simply check
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * for mapping conflicts and set the SyncCR3 FF if found.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pVCpu VMCPU handle
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync * @param pPool The pool.
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync * @param pPage The head page.
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync * @param GCPhysFault The guest physical fault address.
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync * @param uAddress In R0 and GC this is the guest context fault address (flat).
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync * In R3 this is the host context 'fault' address.
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync * @param cbWrite Write size; might be zero if the caller knows we're not crossing entry boundaries
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync */
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsyncvoid pgmPoolMonitorChainChanging(PVMCPU pVCpu, PPGMPOOL pPool, PPGMPOOLPAGE pPage, RTGCPHYS GCPhysFault, CTXTYPE(RTGCPTR, RTHCPTR, RTGCPTR) pvAddress, unsigned cbWrite)
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync{
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync AssertMsg(pPage->iMonitoredPrev == NIL_PGMPOOL_IDX, ("%u (idx=%u)\n", pPage->iMonitoredPrev, pPage->idx));
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync const unsigned off = GCPhysFault & PAGE_OFFSET_MASK;
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync PVM pVM = pPool->CTX_SUFF(pVM);
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync LogFlow(("pgmPoolMonitorChainChanging: %RGv phys=%RGp cbWrite=%d\n", (RTGCPTR)(CTXTYPE(RTGCPTR, uintptr_t, RTGCPTR))pvAddress, GCPhysFault, cbWrite));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync for (;;)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync union
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync {
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync void *pv;
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync PX86PT pPT;
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync PPGMSHWPTPAE pPTPae;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PX86PD pPD;
e12084fc5287a5fa65e3a28bbeb05af29c22dad7vboxsync PX86PDPAE pPDPae;
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync PX86PDPT pPDPT;
e12084fc5287a5fa65e3a28bbeb05af29c22dad7vboxsync PX86PML4 pPML4;
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync } uShw;
e12084fc5287a5fa65e3a28bbeb05af29c22dad7vboxsync
e12084fc5287a5fa65e3a28bbeb05af29c22dad7vboxsync LogFlow(("pgmPoolMonitorChainChanging: page idx=%d phys=%RGp (next=%d) kind=%s\n", pPage->idx, pPage->GCPhys, pPage->iMonitoredNext, pgmPoolPoolKindToStr(pPage->enmKind), cbWrite));
e12084fc5287a5fa65e3a28bbeb05af29c22dad7vboxsync
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync uShw.pv = NULL;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync switch (pPage->enmKind)
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_PT:
290f895ae2ac655ba90c8904a0e2687d8aa0837dvboxsync {
290f895ae2ac655ba90c8904a0e2687d8aa0837dvboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,FaultPT));
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync uShw.pv = PGMPOOL_PAGE_2_PTR(pVM, pPage);
e12084fc5287a5fa65e3a28bbeb05af29c22dad7vboxsync const unsigned iShw = off / sizeof(X86PTE);
290f895ae2ac655ba90c8904a0e2687d8aa0837dvboxsync LogFlow(("PGMPOOLKIND_32BIT_PT_FOR_32BIT_PT iShw=%x\n", iShw));
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync if (uShw.pPT->a[iShw].n.u1Present)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync X86PTE GstPte;
e12084fc5287a5fa65e3a28bbeb05af29c22dad7vboxsync
e12084fc5287a5fa65e3a28bbeb05af29c22dad7vboxsync int rc = pgmPoolPhysSimpleReadGCPhys(pVM, &GstPte, pvAddress, GCPhysFault, sizeof(GstPte));
e12084fc5287a5fa65e3a28bbeb05af29c22dad7vboxsync AssertRC(rc);
e12084fc5287a5fa65e3a28bbeb05af29c22dad7vboxsync Log4(("pgmPoolMonitorChainChanging 32_32: deref %016RX64 GCPhys %08RX32\n", uShw.pPT->a[iShw].u & X86_PTE_PAE_PG_MASK, GstPte.u & X86_PTE_PG_MASK));
e12084fc5287a5fa65e3a28bbeb05af29c22dad7vboxsync pgmPoolTracDerefGCPhysHint(pPool, pPage,
e12084fc5287a5fa65e3a28bbeb05af29c22dad7vboxsync uShw.pPT->a[iShw].u & X86_PTE_PAE_PG_MASK,
e12084fc5287a5fa65e3a28bbeb05af29c22dad7vboxsync GstPte.u & X86_PTE_PG_MASK,
e12084fc5287a5fa65e3a28bbeb05af29c22dad7vboxsync iShw);
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync ASMAtomicWriteU32(&uShw.pPT->a[iShw].u, 0);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
290f895ae2ac655ba90c8904a0e2687d8aa0837dvboxsync }
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync /* page/2 sized */
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_PT:
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync {
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,FaultPT));
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync uShw.pv = PGMPOOL_PAGE_2_PTR(pVM, pPage);
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync if (!((off ^ pPage->GCPhys) & (PAGE_SIZE / 2)))
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync {
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync const unsigned iShw = (off / sizeof(X86PTE)) & (X86_PG_PAE_ENTRIES - 1);
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync LogFlow(("PGMPOOLKIND_PAE_PT_FOR_32BIT_PT iShw=%x\n", iShw));
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync if (PGMSHWPTEPAE_IS_P(uShw.pPTPae->a[iShw]))
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync {
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync X86PTE GstPte;
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync int rc = pgmPoolPhysSimpleReadGCPhys(pVM, &GstPte, pvAddress, GCPhysFault, sizeof(GstPte));
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync AssertRC(rc);
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync Log4(("pgmPoolMonitorChainChanging pae_32: deref %016RX64 GCPhys %08RX32\n", uShw.pPT->a[iShw].u & X86_PTE_PAE_PG_MASK, GstPte.u & X86_PTE_PG_MASK));
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync pgmPoolTracDerefGCPhysHint(pPool, pPage,
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync PGMSHWPTEPAE_GET_HCPHYS(uShw.pPTPae->a[iShw]),
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync GstPte.u & X86_PTE_PG_MASK,
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync iShw);
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync PGMSHWPTEPAE_ATOMIC_SET(uShw.pPTPae->a[iShw], 0);
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync }
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync }
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync break;
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync }
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync case PGMPOOLKIND_PAE_PD0_FOR_32BIT_PD:
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync case PGMPOOLKIND_PAE_PD1_FOR_32BIT_PD:
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync case PGMPOOLKIND_PAE_PD2_FOR_32BIT_PD:
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync case PGMPOOLKIND_PAE_PD3_FOR_32BIT_PD:
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync {
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync unsigned iGst = off / sizeof(X86PDE);
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync unsigned iShwPdpt = iGst / 256;
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync unsigned iShw = (iGst % 256) * 2;
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync uShw.pv = PGMPOOL_PAGE_2_PTR(pVM, pPage);
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync LogFlow(("pgmPoolMonitorChainChanging PAE for 32 bits: iGst=%x iShw=%x idx = %d page idx=%d\n", iGst, iShw, iShwPdpt, pPage->enmKind - PGMPOOLKIND_PAE_PD0_FOR_32BIT_PD));
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,FaultPD));
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync if (iShwPdpt == pPage->enmKind - (unsigned)PGMPOOLKIND_PAE_PD0_FOR_32BIT_PD)
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync {
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync for (unsigned i = 0; i < 2; i++)
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync {
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync# ifndef IN_RING0
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync if ((uShw.pPDPae->a[iShw + i].u & (PGM_PDFLAGS_MAPPING | X86_PDE_P)) == (PGM_PDFLAGS_MAPPING | X86_PDE_P))
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync {
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync Assert(pgmMapAreMappingsEnabled(&pVM->pgm.s));
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync VMCPU_FF_SET(pVCpu, VMCPU_FF_PGM_SYNC_CR3);
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShwPdpt=%#x iShw=%#x!\n", iShwPdpt, iShw+i));
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync break;
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync }
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync else
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync# endif /* !IN_RING0 */
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync if (uShw.pPDPae->a[iShw+i].n.u1Present)
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync {
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync LogFlow(("pgmPoolMonitorChainChanging: pae pd iShw=%#x: %RX64 -> freeing it!\n", iShw+i, uShw.pPDPae->a[iShw+i].u));
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync pgmPoolFree(pVM,
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync uShw.pPDPae->a[iShw+i].u & X86_PDE_PAE_PG_MASK,
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync pPage->idx,
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync iShw + i);
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync ASMAtomicWriteU64(&uShw.pPDPae->a[iShw+i].u, 0);
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync }
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync /* paranoia / a bit assumptive. */
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync if ( (off & 3)
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync && (off & 3) + cbWrite > 4)
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync {
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync const unsigned iShw2 = iShw + 2 + i;
290f895ae2ac655ba90c8904a0e2687d8aa0837dvboxsync if (iShw2 < RT_ELEMENTS(uShw.pPDPae->a))
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync {
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync# ifndef IN_RING0
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync if ((uShw.pPDPae->a[iShw2].u & (PGM_PDFLAGS_MAPPING | X86_PDE_P)) == (PGM_PDFLAGS_MAPPING | X86_PDE_P))
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync {
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync Assert(pgmMapAreMappingsEnabled(&pVM->pgm.s));
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync VMCPU_FF_SET(pVCpu, VMCPU_FF_PGM_SYNC_CR3);
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShwPdpt=%#x iShw2=%#x!\n", iShwPdpt, iShw2));
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync break;
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync }
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync else
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync# endif /* !IN_RING0 */
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync if (uShw.pPDPae->a[iShw2].n.u1Present)
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync {
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync LogFlow(("pgmPoolMonitorChainChanging: pae pd iShw=%#x: %RX64 -> freeing it!\n", iShw2, uShw.pPDPae->a[iShw2].u));
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync pgmPoolFree(pVM,
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync uShw.pPDPae->a[iShw2].u & X86_PDE_PAE_PG_MASK,
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync pPage->idx,
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync iShw2);
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync ASMAtomicWriteU64(&uShw.pPDPae->a[iShw2].u, 0);
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync }
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync }
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync }
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync }
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync }
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync break;
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync }
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_PT:
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync {
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync uShw.pv = PGMPOOL_PAGE_2_PTR(pVM, pPage);
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync const unsigned iShw = off / sizeof(X86PTEPAE);
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,FaultPT));
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync if (PGMSHWPTEPAE_IS_P(uShw.pPTPae->a[iShw]))
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync {
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync X86PTEPAE GstPte;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync int rc = pgmPoolPhysSimpleReadGCPhys(pVM, &GstPte, pvAddress, GCPhysFault, sizeof(GstPte));
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync AssertRC(rc);
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync Log4(("pgmPoolMonitorChainChanging pae: deref %016RX64 GCPhys %016RX64\n", PGMSHWPTEPAE_GET_HCPHYS(uShw.pPTPae->a[iShw]), GstPte.u & X86_PTE_PAE_PG_MASK));
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync pgmPoolTracDerefGCPhysHint(pPool, pPage,
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync PGMSHWPTEPAE_GET_HCPHYS(uShw.pPTPae->a[iShw]),
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync GstPte.u & X86_PTE_PAE_PG_MASK,
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync iShw);
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync PGMSHWPTEPAE_ATOMIC_SET(uShw.pPTPae->a[iShw], 0);
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync }
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync /* paranoia / a bit assumptive. */
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync if ( (off & 7)
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync && (off & 7) + cbWrite > sizeof(X86PTEPAE))
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync {
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync const unsigned iShw2 = (off + cbWrite - 1) / sizeof(X86PTEPAE);
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync AssertBreak(iShw2 < RT_ELEMENTS(uShw.pPTPae->a));
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync if (PGMSHWPTEPAE_IS_P(uShw.pPTPae->a[iShw2]))
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync {
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync X86PTEPAE GstPte;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync# ifdef IN_RING3
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync int rc = pgmPoolPhysSimpleReadGCPhys(pVM, &GstPte, (RTHCPTR)((RTHCUINTPTR)pvAddress + sizeof(GstPte)), GCPhysFault + sizeof(GstPte), sizeof(GstPte));
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync# else
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync int rc = pgmPoolPhysSimpleReadGCPhys(pVM, &GstPte, pvAddress + sizeof(GstPte), GCPhysFault + sizeof(GstPte), sizeof(GstPte));
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync# endif
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync AssertRC(rc);
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync Log4(("pgmPoolMonitorChainChanging pae: deref %016RX64 GCPhys %016RX64\n", PGMSHWPTEPAE_GET_HCPHYS(uShw.pPTPae->a[iShw2]), GstPte.u & X86_PTE_PAE_PG_MASK));
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync pgmPoolTracDerefGCPhysHint(pPool, pPage,
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync PGMSHWPTEPAE_GET_HCPHYS(uShw.pPTPae->a[iShw2]),
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync GstPte.u & X86_PTE_PAE_PG_MASK,
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync iShw2);
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync PGMSHWPTEPAE_ATOMIC_SET(uShw.pPTPae->a[iShw2], 0);
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync }
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync }
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync break;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync }
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_32BIT_PD:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync {
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync uShw.pv = PGMPOOL_PAGE_2_PTR(pVM, pPage);
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync const unsigned iShw = off / sizeof(X86PTE); // ASSUMING 32-bit guest paging!
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync LogFlow(("pgmPoolMonitorChainChanging: PGMPOOLKIND_32BIT_PD %x\n", iShw));
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,FaultPD));
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync# ifndef IN_RING0
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync if (uShw.pPD->a[iShw].u & PGM_PDFLAGS_MAPPING)
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync {
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync Assert(pgmMapAreMappingsEnabled(&pVM->pgm.s));
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync VMCPU_FF_SET(pVCpu, VMCPU_FF_PGM_SYNC_CR3);
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync STAM_COUNTER_INC(&(pVCpu->pgm.s.CTX_SUFF(pStats)->StatRZGuestCR3WriteConflict));
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw=%#x!\n", iShw));
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync break;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync }
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync# endif /* !IN_RING0 */
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync# ifndef IN_RING0
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync else
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync# endif /* !IN_RING0 */
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync {
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync if (uShw.pPD->a[iShw].n.u1Present)
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync {
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync LogFlow(("pgmPoolMonitorChainChanging: 32 bit pd iShw=%#x: %RX64 -> freeing it!\n", iShw, uShw.pPD->a[iShw].u));
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync pgmPoolFree(pVM,
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync uShw.pPD->a[iShw].u & X86_PDE_PAE_PG_MASK,
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync pPage->idx,
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync iShw);
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync ASMAtomicWriteU32(&uShw.pPD->a[iShw].u, 0);
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync }
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync }
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync /* paranoia / a bit assumptive. */
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync if ( (off & 3)
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync && (off & 3) + cbWrite > sizeof(X86PTE))
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync {
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync const unsigned iShw2 = (off + cbWrite - 1) / sizeof(X86PTE);
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync if ( iShw2 != iShw
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync && iShw2 < RT_ELEMENTS(uShw.pPD->a))
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync {
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync# ifndef IN_RING0
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync if (uShw.pPD->a[iShw2].u & PGM_PDFLAGS_MAPPING)
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync {
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync Assert(pgmMapAreMappingsEnabled(&pVM->pgm.s));
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync STAM_COUNTER_INC(&(pVCpu->pgm.s.CTX_SUFF(pStats)->StatRZGuestCR3WriteConflict));
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync VMCPU_FF_SET(pVCpu, VMCPU_FF_PGM_SYNC_CR3);
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw2=%#x!\n", iShw2));
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync break;
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync# endif /* !IN_RING0 */
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync# ifndef IN_RING0
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync else
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync# endif /* !IN_RING0 */
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync {
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync if (uShw.pPD->a[iShw2].n.u1Present)
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync {
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync LogFlow(("pgmPoolMonitorChainChanging: 32 bit pd iShw=%#x: %RX64 -> freeing it!\n", iShw2, uShw.pPD->a[iShw2].u));
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync pgmPoolFree(pVM,
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync uShw.pPD->a[iShw2].u & X86_PDE_PAE_PG_MASK,
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync pPage->idx,
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync iShw2);
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync ASMAtomicWriteU32(&uShw.pPD->a[iShw2].u, 0);
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync }
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync }
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync }
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync }
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync#if 0 /* useful when running PGMAssertCR3(), a bit too troublesome for general use (TLBs). */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if ( uShw.pPD->a[iShw].n.u1Present
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync && !VMCPU_FF_ISSET(pVCpu, VMCPU_FF_PGM_SYNC_CR3))
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync LogFlow(("pgmPoolMonitorChainChanging: iShw=%#x: %RX32 -> freeing it!\n", iShw, uShw.pPD->a[iShw].u));
b9473064e26edc9a65150b4206ea1e52f3ca600avboxsync# ifdef IN_RC /* TLB load - we're pushing things a bit... */
b9473064e26edc9a65150b4206ea1e52f3ca600avboxsync ASMProbeReadByte(pvAddress);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync# endif
b9473064e26edc9a65150b4206ea1e52f3ca600avboxsync pgmPoolFree(pVM, uShw.pPD->a[iShw].u & X86_PDE_PG_MASK, pPage->idx, iShw);
b9473064e26edc9a65150b4206ea1e52f3ca600avboxsync ASMAtomicWriteU32(&uShw.pPD->a[iShw].u, 0);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync }
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync#endif
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync break;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync }
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync case PGMPOOLKIND_PAE_PD_FOR_PAE_PD:
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync {
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync uShw.pv = PGMPOOL_PAGE_2_PTR(pVM, pPage);
b9473064e26edc9a65150b4206ea1e52f3ca600avboxsync const unsigned iShw = off / sizeof(X86PDEPAE);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,FaultPD));
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync#ifndef IN_RING0
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync if (uShw.pPDPae->a[iShw].u & PGM_PDFLAGS_MAPPING)
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync {
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync Assert(pgmMapAreMappingsEnabled(&pVM->pgm.s));
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync VMCPU_FF_SET(pVCpu, VMCPU_FF_PGM_SYNC_CR3);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync STAM_COUNTER_INC(&(pVCpu->pgm.s.CTX_SUFF(pStats)->StatRZGuestCR3WriteConflict));
b9473064e26edc9a65150b4206ea1e52f3ca600avboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw=%#x!\n", iShw));
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync break;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync }
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync#endif /* !IN_RING0 */
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync /*
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * Causes trouble when the guest uses a PDE to refer to the whole page table level
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync * structure. (Invalidate here; faults later on when it tries to change the page
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync * table entries -> recheck; probably only applies to the RC case.)
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync */
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync# ifndef IN_RING0
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync else
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync# endif /* !IN_RING0 */
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync {
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync if (uShw.pPDPae->a[iShw].n.u1Present)
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync {
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync LogFlow(("pgmPoolMonitorChainChanging: pae pd iShw=%#x: %RX64 -> freeing it!\n", iShw, uShw.pPDPae->a[iShw].u));
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync pgmPoolFree(pVM,
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync uShw.pPDPae->a[iShw].u & X86_PDE_PAE_PG_MASK,
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync pPage->idx,
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync iShw);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync ASMAtomicWriteU64(&uShw.pPDPae->a[iShw].u, 0);
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync }
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync }
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync /* paranoia / a bit assumptive. */
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync if ( (off & 7)
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync && (off & 7) + cbWrite > sizeof(X86PDEPAE))
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync const unsigned iShw2 = (off + cbWrite - 1) / sizeof(X86PDEPAE);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertBreak(iShw2 < RT_ELEMENTS(uShw.pPDPae->a));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#ifndef IN_RING0
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if ( iShw2 != iShw
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync && uShw.pPDPae->a[iShw2].u & PGM_PDFLAGS_MAPPING)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(pgmMapAreMappingsEnabled(&pVM->pgm.s));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync VMCPU_FF_SET(pVCpu, VMCPU_FF_PGM_SYNC_CR3);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_COUNTER_INC(&(pVCpu->pgm.s.CTX_SUFF(pStats)->StatRZGuestCR3WriteConflict));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw2=%#x!\n", iShw2));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#endif /* !IN_RING0 */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync# ifndef IN_RING0
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync else
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync# endif /* !IN_RING0 */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (uShw.pPDPae->a[iShw2].n.u1Present)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync LogFlow(("pgmPoolMonitorChainChanging: pae pd iShw2=%#x: %RX64 -> freeing it!\n", iShw2, uShw.pPDPae->a[iShw2].u));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolFree(pVM,
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync uShw.pPDPae->a[iShw2].u & X86_PDE_PAE_PG_MASK,
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->idx,
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync iShw2);
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync ASMAtomicWriteU64(&uShw.pPDPae->a[iShw2].u, 0);
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync }
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync case PGMPOOLKIND_PAE_PDPT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,FaultPDPT));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Hopefully this doesn't happen very often:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * - touching unused parts of the page
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * - messing with the bits of pd pointers without changing the physical address
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* PDPT roots are not page aligned; 32 byte only! */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync const unsigned offPdpt = GCPhysFault - pPage->GCPhys;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync uShw.pv = PGMPOOL_PAGE_2_PTR(pVM, pPage);
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync const unsigned iShw = offPdpt / sizeof(X86PDPE);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (iShw < X86_PG_PAE_PDPE_ENTRIES) /* don't use RT_ELEMENTS(uShw.pPDPT->a), because that's for long mode only */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync# ifndef IN_RING0
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (uShw.pPDPT->a[iShw].u & PGM_PLXFLAGS_MAPPING)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(pgmMapAreMappingsEnabled(&pVM->pgm.s));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_COUNTER_INC(&(pVCpu->pgm.s.CTX_SUFF(pStats)->StatRZGuestCR3WriteConflict));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync VMCPU_FF_SET(pVCpu, VMCPU_FF_PGM_SYNC_CR3);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected pdpt conflict at iShw=%#x!\n", iShw));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync# endif /* !IN_RING0 */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync# ifndef IN_RING0
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync else
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync# endif /* !IN_RING0 */
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync if (uShw.pPDPT->a[iShw].n.u1Present)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync LogFlow(("pgmPoolMonitorChainChanging: pae pdpt iShw=%#x: %RX64 -> freeing it!\n", iShw, uShw.pPDPT->a[iShw].u));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolFree(pVM,
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync uShw.pPDPT->a[iShw].u & X86_PDPE_PG_MASK,
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->idx,
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync iShw);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync ASMAtomicWriteU64(&uShw.pPDPT->a[iShw].u, 0);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* paranoia / a bit assumptive. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if ( (offPdpt & 7)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync && (offPdpt & 7) + cbWrite > sizeof(X86PDPE))
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync const unsigned iShw2 = (offPdpt + cbWrite - 1) / sizeof(X86PDPE);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if ( iShw2 != iShw
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync && iShw2 < X86_PG_PAE_PDPE_ENTRIES)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync# ifndef IN_RING0
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (uShw.pPDPT->a[iShw2].u & PGM_PLXFLAGS_MAPPING)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(pgmMapAreMappingsEnabled(&pVM->pgm.s));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_COUNTER_INC(&(pVCpu->pgm.s.CTX_SUFF(pStats)->StatRZGuestCR3WriteConflict));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync VMCPU_FF_SET(pVCpu, VMCPU_FF_PGM_SYNC_CR3);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw2=%#x!\n", iShw2));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync# endif /* !IN_RING0 */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync# ifndef IN_RING0
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync else
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync# endif /* !IN_RING0 */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (uShw.pPDPT->a[iShw2].n.u1Present)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync LogFlow(("pgmPoolMonitorChainChanging: pae pdpt iShw=%#x: %RX64 -> freeing it!\n", iShw2, uShw.pPDPT->a[iShw2].u));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolFree(pVM,
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync uShw.pPDPT->a[iShw2].u & X86_PDPE_PG_MASK,
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->idx,
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync iShw2);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync ASMAtomicWriteU64(&uShw.pPDPT->a[iShw2].u, 0);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#ifndef IN_RC
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PD_FOR_64BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,FaultPD));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync uShw.pv = PGMPOOL_PAGE_2_PTR(pVM, pPage);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync const unsigned iShw = off / sizeof(X86PDEPAE);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(!(uShw.pPDPae->a[iShw].u & PGM_PDFLAGS_MAPPING));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (uShw.pPDPae->a[iShw].n.u1Present)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync LogFlow(("pgmPoolMonitorChainChanging: pae pd iShw=%#x: %RX64 -> freeing it!\n", iShw, uShw.pPDPae->a[iShw].u));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolFree(pVM,
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync uShw.pPDPae->a[iShw].u & X86_PDE_PAE_PG_MASK,
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->idx,
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync iShw);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync ASMAtomicWriteU64(&uShw.pPDPae->a[iShw].u, 0);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* paranoia / a bit assumptive. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if ( (off & 7)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync && (off & 7) + cbWrite > sizeof(X86PDEPAE))
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync const unsigned iShw2 = (off + cbWrite - 1) / sizeof(X86PDEPAE);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertBreak(iShw2 < RT_ELEMENTS(uShw.pPDPae->a));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(!(uShw.pPDPae->a[iShw2].u & PGM_PDFLAGS_MAPPING));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (uShw.pPDPae->a[iShw2].n.u1Present)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync LogFlow(("pgmPoolMonitorChainChanging: pae pd iShw2=%#x: %RX64 -> freeing it!\n", iShw2, uShw.pPDPae->a[iShw2].u));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolFree(pVM,
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync uShw.pPDPae->a[iShw2].u & X86_PDE_PAE_PG_MASK,
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->idx,
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync iShw2);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync ASMAtomicWriteU64(&uShw.pPDPae->a[iShw2].u, 0);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_64BIT_PDPT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,FaultPDPT));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Hopefully this doesn't happen very often:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * - messing with the bits of pd pointers without changing the physical address
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync uShw.pv = PGMPOOL_PAGE_2_PTR(pVM, pPage);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync const unsigned iShw = off / sizeof(X86PDPE);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (uShw.pPDPT->a[iShw].n.u1Present)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync LogFlow(("pgmPoolMonitorChainChanging: pdpt iShw=%#x: %RX64 -> freeing it!\n", iShw, uShw.pPDPT->a[iShw].u));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolFree(pVM, uShw.pPDPT->a[iShw].u & X86_PDPE_PG_MASK, pPage->idx, iShw);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync ASMAtomicWriteU64(&uShw.pPDPT->a[iShw].u, 0);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* paranoia / a bit assumptive. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if ( (off & 7)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync && (off & 7) + cbWrite > sizeof(X86PDPE))
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync const unsigned iShw2 = (off + cbWrite - 1) / sizeof(X86PDPE);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (uShw.pPDPT->a[iShw2].n.u1Present)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync LogFlow(("pgmPoolMonitorChainChanging: pdpt iShw2=%#x: %RX64 -> freeing it!\n", iShw2, uShw.pPDPT->a[iShw2].u));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolFree(pVM, uShw.pPDPT->a[iShw2].u & X86_PDPE_PG_MASK, pPage->idx, iShw2);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync ASMAtomicWriteU64(&uShw.pPDPT->a[iShw2].u, 0);
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PML4:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,FaultPML4));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Hopefully this doesn't happen very often:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * - messing with the bits of pd pointers without changing the physical address
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync uShw.pv = PGMPOOL_PAGE_2_PTR(pVM, pPage);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync const unsigned iShw = off / sizeof(X86PDPE);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (uShw.pPML4->a[iShw].n.u1Present)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync LogFlow(("pgmPoolMonitorChainChanging: pml4 iShw=%#x: %RX64 -> freeing it!\n", iShw, uShw.pPML4->a[iShw].u));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolFree(pVM, uShw.pPML4->a[iShw].u & X86_PML4E_PG_MASK, pPage->idx, iShw);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync ASMAtomicWriteU64(&uShw.pPML4->a[iShw].u, 0);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* paranoia / a bit assumptive. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if ( (off & 7)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync && (off & 7) + cbWrite > sizeof(X86PDPE))
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync const unsigned iShw2 = (off + cbWrite - 1) / sizeof(X86PML4E);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (uShw.pPML4->a[iShw2].n.u1Present)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync LogFlow(("pgmPoolMonitorChainChanging: pml4 iShw2=%#x: %RX64 -> freeing it!\n", iShw2, uShw.pPML4->a[iShw2].u));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolFree(pVM, uShw.pPML4->a[iShw2].u & X86_PML4E_PG_MASK, pPage->idx, iShw2);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync ASMAtomicWriteU64(&uShw.pPML4->a[iShw2].u, 0);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#endif /* IN_RING0 */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync default:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertFatalMsgFailed(("enmKind=%d\n", pPage->enmKind));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PGM_DYNMAP_UNUSED_HINT_VM(pVM, uShw.pv);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* next */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pPage->iMonitoredNext == NIL_PGMPOOL_IDX)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage = &pPool->aPages[pPage->iMonitoredNext];
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync# ifndef IN_RING3
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Checks if a access could be a fork operation in progress.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Meaning, that the guest is setting up the parent process for Copy-On-Write.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @returns true if it's likly that we're forking, otherwise false.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPool The pool.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pDis The disassembled instruction.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param offFault The access offset.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncDECLINLINE(bool) pgmPoolMonitorIsForking(PPGMPOOL pPool, PDISCPUSTATE pDis, unsigned offFault)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * i386 linux is using btr to clear X86_PTE_RW.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * The functions involved are (2.6.16 source inspection):
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * clear_bit
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * ptep_set_wrprotect
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * copy_one_pte
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * copy_pte_range
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * copy_pmd_range
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * copy_pud_range
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * copy_page_range
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * dup_mmap
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * dup_mm
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * copy_mm
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * copy_process
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * do_fork
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if ( pDis->pCurInstr->opcode == OP_BTR
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync && !(offFault & 4)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /** @todo Validate that the bit index is X86_PTE_RW. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync )
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,Fork));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return true;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return false;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Determine whether the page is likely to have been reused.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @returns true if we consider the page as being reused for a different purpose.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @returns false if we consider it to still be a paging page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pVM VM Handle.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pVCpu VMCPU Handle.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pRegFrame Trap register frame.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pDis The disassembly info for the faulting instruction.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pvFault The fault address.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @remark The REP prefix check is left to the caller because of STOSD/W.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncDECLINLINE(bool) pgmPoolMonitorIsReused(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame, PDISCPUSTATE pDis, RTGCPTR pvFault)
7c19e11502220292d5270519296442234c2493cdvboxsync{
7c19e11502220292d5270519296442234c2493cdvboxsync#ifndef IN_RC
7c19e11502220292d5270519296442234c2493cdvboxsync /** @todo could make this general, faulting close to rsp should be a safe reuse heuristic. */
7c19e11502220292d5270519296442234c2493cdvboxsync if ( HWACCMHasPendingIrq(pVM)
7c19e11502220292d5270519296442234c2493cdvboxsync && (pRegFrame->rsp - pvFault) < 32)
7c19e11502220292d5270519296442234c2493cdvboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* Fault caused by stack writes while trying to inject an interrupt event. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log(("pgmPoolMonitorIsReused: reused %RGv for interrupt stack (rsp=%RGv).\n", pvFault, pRegFrame->rsp));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return true;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#else
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync NOREF(pVM); NOREF(pvFault);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#endif
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync LogFlow(("Reused instr %RGv %d at %RGv param1.flags=%x param1.reg=%d\n", pRegFrame->rip, pDis->pCurInstr->opcode, pvFault, pDis->param1.flags, pDis->param1.base.reg_gen));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* Non-supervisor mode write means it's used for something else. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (CPUMGetGuestCPL(pVCpu, pRegFrame) != 0)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return true;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync switch (pDis->pCurInstr->opcode)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* call implies the actual push of the return address faulted */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case OP_CALL:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log4(("pgmPoolMonitorIsReused: CALL\n"));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return true;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case OP_PUSH:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log4(("pgmPoolMonitorIsReused: PUSH\n"));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return true;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case OP_PUSHF:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log4(("pgmPoolMonitorIsReused: PUSHF\n"));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return true;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case OP_PUSHA:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log4(("pgmPoolMonitorIsReused: PUSHA\n"));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return true;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case OP_FXSAVE:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log4(("pgmPoolMonitorIsReused: FXSAVE\n"));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return true;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case OP_MOVNTI: /* solaris - block_zero_no_xmm */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log4(("pgmPoolMonitorIsReused: MOVNTI\n"));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return true;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case OP_MOVNTDQ: /* solaris - hwblkclr & hwblkpagecopy */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log4(("pgmPoolMonitorIsReused: MOVNTDQ\n"));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return true;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case OP_MOVSWD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case OP_STOSWD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if ( pDis->prefix == (PREFIX_REP|PREFIX_REX)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync && pRegFrame->rcx >= 0x40
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync )
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(pDis->mode == CPUMODE_64BIT);
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log(("pgmPoolMonitorIsReused: OP_STOSQ\n"));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return true;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return false;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if ( ( (pDis->param1.flags & USE_REG_GEN32)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync || (pDis->param1.flags & USE_REG_GEN64))
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync && (pDis->param1.base.reg_gen == USE_REG_ESP))
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log4(("pgmPoolMonitorIsReused: ESP\n"));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return true;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return false;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync * Flushes the page being accessed.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync * @returns VBox status code suitable for scheduling.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pVM The VM handle.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pVCpu The VMCPU handle.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPool The pool.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPage The pool page (head).
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pDis The disassembly of the write instruction.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pRegFrame The trap register frame.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param GCPhysFault The fault address as guest physical address.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pvFault The fault address.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @todo VBOXSTRICTRC
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncstatic int pgmPoolAccessHandlerFlush(PVM pVM, PVMCPU pVCpu, PPGMPOOL pPool, PPGMPOOLPAGE pPage, PDISCPUSTATE pDis,
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, RTGCPTR pvFault)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * First, do the flushing.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync int rc = pgmPoolMonitorChainFlush(pPool, pPage);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Emulate the instruction (xp/w2k problem, requires pc/cr2/sp detection).
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Must do this in raw mode (!); XP boot will fail otherwise.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync uint32_t cbWritten;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync VBOXSTRICTRC rc2 = EMInterpretInstructionCPU(pVM, pVCpu, pDis, pRegFrame, pvFault, EMCODETYPE_ALL, &cbWritten);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (RT_SUCCESS(rc2))
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pRegFrame->rip += pDis->opsize;
0ffa3979e9b800f5931dd30c51ec3c0aadc3a1f1vboxsync AssertMsg(rc2 == VINF_SUCCESS, ("%Rrc\n", VBOXSTRICTRC_VAL(rc2))); /* ASSUMES no complicated stuff here. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync else if (rc2 == VERR_EM_INTERPRETER)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync#ifdef IN_RC
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync if (PATMIsPatchGCAddr(pVM, pRegFrame->eip))
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync {
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync LogFlow(("pgmPoolAccessHandlerPTWorker: Interpretation failed for patch code %04x:%RGv, ignoring.\n",
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync pRegFrame->cs, (RTGCPTR)pRegFrame->eip));
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync rc = VINF_SUCCESS;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync STAM_COUNTER_INC(&pPool->StatMonitorRZIntrFailPatch2);
7c19e11502220292d5270519296442234c2493cdvboxsync }
7c19e11502220292d5270519296442234c2493cdvboxsync else
7c19e11502220292d5270519296442234c2493cdvboxsync#endif
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync {
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync rc = VINF_EM_RAW_EMULATE_INSTR;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,EmulateInstr));
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync }
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync }
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync else
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync rc = VBOXSTRICTRC_VAL(rc2);
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync LogFlow(("pgmPoolAccessHandlerPT: returns %Rrc (flushed)\n", rc));
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync return rc;
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync}
7c19e11502220292d5270519296442234c2493cdvboxsync
7c19e11502220292d5270519296442234c2493cdvboxsync/**
7c19e11502220292d5270519296442234c2493cdvboxsync * Handles the STOSD write accesses.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @returns VBox status code suitable for scheduling.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pVM The VM handle.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPool The pool.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPage The pool page (head).
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pDis The disassembly of the write instruction.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pRegFrame The trap register frame.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param GCPhysFault The fault address as guest physical address.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pvFault The fault address.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncDECLINLINE(int) pgmPoolAccessHandlerSTOSD(PVM pVM, PPGMPOOL pPool, PPGMPOOLPAGE pPage, PDISCPUSTATE pDis,
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, RTGCPTR pvFault)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync unsigned uIncrement = pDis->param1.size;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(pDis->mode == CPUMODE_32BIT || pDis->mode == CPUMODE_64BIT);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(pRegFrame->rcx <= 0x20);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#ifdef VBOX_STRICT
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pDis->opmode == CPUMODE_32BIT)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(uIncrement == 4);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync else
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(uIncrement == 8);
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync#endif
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
0ffa3979e9b800f5931dd30c51ec3c0aadc3a1f1vboxsync Log3(("pgmPoolAccessHandlerSTOSD\n"));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Increment the modification counter and insert it into the list
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * of modified pages the first time.
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync */
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync if (!pPage->cModifications++)
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync pgmPoolMonitorModifiedInsert(pPool, pPage);
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync /*
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync * Execute REP STOSD.
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync *
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync * This ASSUMES that we're not invoked by Trap0e on in a out-of-sync
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync * write situation, meaning that it's safe to write here.
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync */
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync PVMCPU pVCpu = VMMGetCpu(pPool->CTX_SUFF(pVM));
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync RTGCUINTPTR pu32 = (RTGCUINTPTR)pvFault;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync while (pRegFrame->rcx)
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync {
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync#if defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0) || defined(IN_RC)
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync uint32_t iPrevSubset = PGMRZDynMapPushAutoSubset(pVCpu);
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync pgmPoolMonitorChainChanging(pVCpu, pPool, pPage, GCPhysFault, (RTGCPTR)pu32, uIncrement);
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync PGMRZDynMapPopAutoSubset(pVCpu, iPrevSubset);
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync#else
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync pgmPoolMonitorChainChanging(pVCpu, pPool, pPage, GCPhysFault, (RTGCPTR)pu32, uIncrement);
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync#endif
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync#ifdef IN_RC
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync *(uint32_t *)(uintptr_t)pu32 = pRegFrame->eax;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync#else
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync PGMPhysSimpleWriteGCPhys(pVM, GCPhysFault, &pRegFrame->rax, uIncrement);
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync#endif
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync pu32 += uIncrement;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync GCPhysFault += uIncrement;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pRegFrame->rdi += uIncrement;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pRegFrame->rcx--;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pRegFrame->rip += pDis->opsize;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync LogFlow(("pgmPoolAccessHandlerSTOSD: returns\n"));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return VINF_SUCCESS;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Handles the simple write accesses.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @returns VBox status code suitable for scheduling.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pVM The VM handle.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pVCpu The VMCPU handle.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPool The pool.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPage The pool page (head).
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync * @param pDis The disassembly of the write instruction.
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync * @param pRegFrame The trap register frame.
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync * @param GCPhysFault The fault address as guest physical address.
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync * @param pvFault The fault address.
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync * @param pfReused Reused state (out)
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncDECLINLINE(int) pgmPoolAccessHandlerSimple(PVM pVM, PVMCPU pVCpu, PPGMPOOL pPool, PPGMPOOLPAGE pPage, PDISCPUSTATE pDis,
f067ea84f385c1b66e9b1f3c6faf7cacb0eb194cvboxsync PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, RTGCPTR pvFault, bool *pfReused)
f067ea84f385c1b66e9b1f3c6faf7cacb0eb194cvboxsync{
f067ea84f385c1b66e9b1f3c6faf7cacb0eb194cvboxsync Log3(("pgmPoolAccessHandlerSimple\n"));
f067ea84f385c1b66e9b1f3c6faf7cacb0eb194cvboxsync /*
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync * Increment the modification counter and insert it into the list
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync * of modified pages the first time.
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync */
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync if (!pPage->cModifications++)
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync pgmPoolMonitorModifiedInsert(pPool, pPage);
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync * Clear all the pages. ASSUMES that pvFault is readable.
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync */
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync#if defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0) || defined(IN_RC)
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync uint32_t iPrevSubset = PGMRZDynMapPushAutoSubset(pVCpu);
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync pgmPoolMonitorChainChanging(pVCpu, pPool, pPage, GCPhysFault, pvFault, DISGetParamSize(pDis, &pDis->param1));
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync PGMRZDynMapPopAutoSubset(pVCpu, iPrevSubset);
e819feefdc34d50781a3c95edecda1072e8575d0vboxsync#else
e819feefdc34d50781a3c95edecda1072e8575d0vboxsync pgmPoolMonitorChainChanging(pVCpu, pPool, pPage, GCPhysFault, pvFault, DISGetParamSize(pDis, &pDis->param1));
e819feefdc34d50781a3c95edecda1072e8575d0vboxsync#endif
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync /*
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync * Interpret the instruction.
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync */
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync uint32_t cb;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync VBOXSTRICTRC rc = EMInterpretInstructionCPU(pVM, pVCpu, pDis, pRegFrame, pvFault, EMCODETYPE_ALL, &cb);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync if (RT_SUCCESS(rc))
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync {
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync pRegFrame->rip += pDis->opsize;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync AssertMsg(rc == VINF_SUCCESS, ("%Rrc\n", VBOXSTRICTRC_VAL(rc))); /* ASSUMES no complicated stuff here. */
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync }
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync else if (rc == VERR_EM_INTERPRETER)
e819feefdc34d50781a3c95edecda1072e8575d0vboxsync {
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync LogFlow(("pgmPoolAccessHandlerPTWorker: Interpretation failed for %04x:%RGv - opcode=%d\n",
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync pRegFrame->cs, (RTGCPTR)pRegFrame->rip, pDis->pCurInstr->opcode));
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync rc = VINF_EM_RAW_EMULATE_INSTR;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,EmulateInstr));
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync }
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync#if 0 /* experimental code */
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync if (rc == VINF_SUCCESS)
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync {
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync switch (pPage->enmKind)
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync {
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_PT:
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync {
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync X86PTEPAE GstPte;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync int rc = pgmPoolPhysSimpleReadGCPhys(pVM, &GstPte, pvFault, GCPhysFault, sizeof(GstPte));
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync AssertRC(rc);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync /* Check the new value written by the guest. If present and with a bogus physical address, then
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * it's fairly safe to assume the guest is reusing the PT.
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync */
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync if (GstPte.n.u1Present)
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync {
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync RTHCPHYS HCPhys = -1;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync int rc = PGMPhysGCPhys2HCPhys(pVM, GstPte.u & X86_PTE_PAE_PG_MASK, &HCPhys);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync if (rc != VINF_SUCCESS)
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync {
e819feefdc34d50781a3c95edecda1072e8575d0vboxsync *pfReused = true;
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync STAM_COUNTER_INC(&pPool->StatForceFlushReused);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync }
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync }
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync break;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync }
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync }
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync }
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync#endif
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync LogFlow(("pgmPoolAccessHandlerSimple: returns %Rrc cb=%d\n", VBOXSTRICTRC_VAL(rc), cb));
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync return VBOXSTRICTRC_VAL(rc);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync}
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync/**
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * \#PF Handler callback for PT write accesses.
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync *
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * @returns VBox status code (appropriate for GC return).
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * @param pVM VM Handle.
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * @param uErrorCode CPU Error code.
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * @param pRegFrame Trap register frame.
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * NULL on DMA and other non CPU access.
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * @param pvFault The fault address (cr2).
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * @param GCPhysFault The GC physical address corresponding to pvFault.
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * @param pvUser User argument.
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync */
07557d07616212d7ba6e7ab3059e85cb14633775vboxsyncDECLEXPORT(int) pgmPoolAccessHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPHYS GCPhysFault, void *pvUser)
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync{
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync STAM_PROFILE_START(&pVM->pgm.s.CTX_SUFF(pPool)->CTX_SUFF_Z(StatMonitor), a);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync PPGMPOOL pPool = pVM->pgm.s.CTX_SUFF(pPool);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync PPGMPOOLPAGE pPage = (PPGMPOOLPAGE)pvUser;
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync PVMCPU pVCpu = VMMGetCpu(pVM);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync unsigned cMaxModifications;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync bool fForcedFlush = false;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync LogFlow(("pgmPoolAccessHandler: pvFault=%RGv pPage=%p:{.idx=%d} GCPhysFault=%RGp\n", pvFault, pPage, pPage->idx, GCPhysFault));
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync pgmLock(pVM);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync if (PHYS_PAGE_ADDRESS(GCPhysFault) != PHYS_PAGE_ADDRESS(pPage->GCPhys))
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync {
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync /* Pool page changed while we were waiting for the lock; ignore. */
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync Log(("CPU%d: pgmPoolAccessHandler pgm pool page for %RGp changed (to %RGp) while waiting!\n", pVCpu->idCpu, PHYS_PAGE_ADDRESS(GCPhysFault), PHYS_PAGE_ADDRESS(pPage->GCPhys)));
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync STAM_PROFILE_STOP_EX(&pVM->pgm.s.CTX_SUFF(pPool)->CTX_SUFF_Z(StatMonitor), &pPool->CTX_MID_Z(StatMonitor,Handled), a);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync pgmUnlock(pVM);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync return VINF_SUCCESS;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync }
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync#ifdef PGMPOOL_WITH_OPTIMIZED_DIRTY_PT
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync if (pPage->fDirty)
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync {
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync Assert(VMCPU_FF_ISSET(pVCpu, VMCPU_FF_TLB_FLUSH));
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync pgmUnlock(pVM);
e819feefdc34d50781a3c95edecda1072e8575d0vboxsync return VINF_SUCCESS; /* SMP guest case where we were blocking on the pgm lock while the same page was being marked dirty. */
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync }
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync#endif
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync#if 0 /* test code defined(VBOX_STRICT) && defined(PGMPOOL_WITH_OPTIMIZED_DIRTY_PT) */
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync if (pPage->enmKind == PGMPOOLKIND_PAE_PT_FOR_PAE_PT)
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync {
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync void *pvShw = PGMPOOL_PAGE_2_PTR(pPool->CTX_SUFF(pVM), pPage);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync void *pvGst;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync int rc = PGM_GCPHYS_2_PTR(pPool->CTX_SUFF(pVM), pPage->GCPhys, &pvGst); AssertReleaseRC(rc);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync pgmPoolTrackCheckPTPaePae(pPool, pPage, (PPGMSHWPTPAE)pvShw, (PCX86PTPAE)pvGst);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync PGM_DYNMAP_UNUSED_HINT_VM(pVM, pvGst);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync PGM_DYNMAP_UNUSED_HINT_VM(pVM, pvShw);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync }
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync#endif
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync /*
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * Disassemble the faulting instruction.
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync */
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync PDISCPUSTATE pDis = &pVCpu->pgm.s.DisState;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync int rc = EMInterpretDisasOne(pVM, pVCpu, pRegFrame, pDis, NULL);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync if (RT_UNLIKELY(rc != VINF_SUCCESS))
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync {
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync AssertMsg(rc == VERR_PAGE_NOT_PRESENT || rc == VERR_PAGE_TABLE_NOT_PRESENT, ("Unexpected rc %d\n", rc));
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync pgmUnlock(pVM);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync return rc;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync }
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync Assert(pPage->enmKind != PGMPOOLKIND_FREE);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync /*
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * We should ALWAYS have the list head as user parameter. This
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * is because we use that page to record the changes.
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync */
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync Assert(pPage->iMonitoredPrev == NIL_PGMPOOL_IDX);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync#ifdef IN_RING0
e819feefdc34d50781a3c95edecda1072e8575d0vboxsync /* Maximum nr of modifications depends on the page type. */
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync if ( pPage->enmKind == PGMPOOLKIND_PAE_PT_FOR_PAE_PT
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync || pPage->enmKind == PGMPOOLKIND_PAE_PT_FOR_32BIT_PT)
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync cMaxModifications = 4;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync else
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync cMaxModifications = 24;
e819feefdc34d50781a3c95edecda1072e8575d0vboxsync#else
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync cMaxModifications = 48;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync#endif
e819feefdc34d50781a3c95edecda1072e8575d0vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync /*
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * Incremental page table updates should weigh more than random ones.
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * (Only applies when started from offset 0)
e819feefdc34d50781a3c95edecda1072e8575d0vboxsync */
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync pVCpu->pgm.s.cPoolAccessHandler++;
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync if ( pPage->pvLastAccessHandlerRip >= pRegFrame->rip - 0x40 /* observed loops in Windows 7 x64 */
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync && pPage->pvLastAccessHandlerRip < pRegFrame->rip + 0x40
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync && pvFault == (pPage->pvLastAccessHandlerFault + pDis->param1.size)
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync && pVCpu->pgm.s.cPoolAccessHandler == (pPage->cLastAccessHandlerCount + 1))
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync {
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync Log(("Possible page reuse cMods=%d -> %d (locked=%d type=%s)\n", pPage->cModifications, pPage->cModifications * 2, pgmPoolIsPageLocked(&pVM->pgm.s, pPage), pgmPoolPoolKindToStr(pPage->enmKind)));
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync Assert(pPage->cModifications < 32000);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync pPage->cModifications = pPage->cModifications * 2;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync pPage->pvLastAccessHandlerFault = pvFault;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync pPage->cLastAccessHandlerCount = pVCpu->pgm.s.cPoolAccessHandler;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync if (pPage->cModifications >= cMaxModifications)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
e819feefdc34d50781a3c95edecda1072e8575d0vboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,FlushReinit));
815647972e1e2746466be1ea725e702459693cd5vboxsync fForcedFlush = true;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync }
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync }
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync if (pPage->cModifications >= cMaxModifications)
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync Log(("Mod overflow %RGv cMods=%d (locked=%d type=%s)\n", pvFault, pPage->cModifications, pgmPoolIsPageLocked(&pVM->pgm.s, pPage), pgmPoolPoolKindToStr(pPage->enmKind)));
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync /*
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * Check if it's worth dealing with.
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync */
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync bool fReused = false;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync bool fNotReusedNotForking = false;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync if ( ( pPage->cModifications < cMaxModifications /** @todo #define */ /** @todo need to check that it's not mapping EIP. */ /** @todo adjust this! */
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync || pgmPoolIsPageLocked(&pVM->pgm.s, pPage)
815647972e1e2746466be1ea725e702459693cd5vboxsync )
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync && !(fReused = pgmPoolMonitorIsReused(pVM, pVCpu, pRegFrame, pDis, pvFault))
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync && !pgmPoolMonitorIsForking(pPool, pDis, GCPhysFault & PAGE_OFFSET_MASK))
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync {
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync /*
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * Simple instructions, no REP prefix.
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync */
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync if (!(pDis->prefix & (PREFIX_REP | PREFIX_REPNE)))
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync {
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync rc = pgmPoolAccessHandlerSimple(pVM, pVCpu, pPool, pPage, pDis, pRegFrame, GCPhysFault, pvFault, &fReused);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync if (fReused)
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync goto flushPage;
815647972e1e2746466be1ea725e702459693cd5vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync /* A mov instruction to change the first page table entry will be remembered so we can detect
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * full page table changes early on. This will reduce the amount of unnecessary traps we'll take.
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync */
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync if ( rc == VINF_SUCCESS
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync && !pPage->cLocked /* only applies to unlocked pages as we can't free locked ones (e.g. cr3 root). */
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync && pDis->pCurInstr->opcode == OP_MOV
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync && (pvFault & PAGE_OFFSET_MASK) == 0)
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync {
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync pPage->pvLastAccessHandlerFault = pvFault;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync pPage->cLastAccessHandlerCount = pVCpu->pgm.s.cPoolAccessHandler;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync pPage->pvLastAccessHandlerRip = pRegFrame->rip;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync /* Make sure we don't kick out a page too quickly. */
815647972e1e2746466be1ea725e702459693cd5vboxsync if (pPage->cModifications > 8)
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync pPage->cModifications = 2;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync }
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync else
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync if (pPage->pvLastAccessHandlerFault == pvFault)
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync {
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync /* ignore the 2nd write to this page table entry. */
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync pPage->cLastAccessHandlerCount = pVCpu->pgm.s.cPoolAccessHandler;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync }
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync else
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync {
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync pPage->pvLastAccessHandlerFault = 0;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync pPage->pvLastAccessHandlerRip = 0;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync }
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync STAM_PROFILE_STOP_EX(&pVM->pgm.s.CTX_SUFF(pPool)->CTX_SUFF_Z(StatMonitor), &pPool->CTX_MID_Z(StatMonitor,Handled), a);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync pgmUnlock(pVM);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync return rc;
815647972e1e2746466be1ea725e702459693cd5vboxsync }
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync /*
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * Windows is frequently doing small memset() operations (netio test 4k+).
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * We have to deal with these or we'll kill the cache and performance.
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync */
815647972e1e2746466be1ea725e702459693cd5vboxsync if ( pDis->pCurInstr->opcode == OP_STOSWD
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync && !pRegFrame->eflags.Bits.u1DF
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync && pDis->opmode == pDis->mode
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync && pDis->addrmode == pDis->mode)
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync {
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync bool fValidStosd = false;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync if ( pDis->mode == CPUMODE_32BIT
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync && pDis->prefix == PREFIX_REP
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync && pRegFrame->ecx <= 0x20
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync && pRegFrame->ecx * 4 <= PAGE_SIZE - ((uintptr_t)pvFault & PAGE_OFFSET_MASK)
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync && !((uintptr_t)pvFault & 3)
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync && (pRegFrame->eax == 0 || pRegFrame->eax == 0x80) /* the two values observed. */
815647972e1e2746466be1ea725e702459693cd5vboxsync )
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync {
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync fValidStosd = true;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync pRegFrame->rcx &= 0xffffffff; /* paranoia */
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync }
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync else
815647972e1e2746466be1ea725e702459693cd5vboxsync if ( pDis->mode == CPUMODE_64BIT
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync && pDis->prefix == (PREFIX_REP | PREFIX_REX)
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync && pRegFrame->rcx <= 0x20
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync && pRegFrame->rcx * 8 <= PAGE_SIZE - ((uintptr_t)pvFault & PAGE_OFFSET_MASK)
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync && !((uintptr_t)pvFault & 7)
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync && (pRegFrame->rax == 0 || pRegFrame->rax == 0x80) /* the two values observed. */
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync )
815647972e1e2746466be1ea725e702459693cd5vboxsync {
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync fValidStosd = true;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync }
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync if (fValidStosd)
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync {
815647972e1e2746466be1ea725e702459693cd5vboxsync rc = pgmPoolAccessHandlerSTOSD(pVM, pPool, pPage, pDis, pRegFrame, GCPhysFault, pvFault);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync STAM_PROFILE_STOP_EX(&pVM->pgm.s.CTX_SUFF(pPool)->CTX_SUFF_Z(StatMonitor), &pPool->CTX_MID_Z(StatMonitor,RepStosd), a);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync pgmUnlock(pVM);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync return rc;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync }
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync }
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync /* REP prefix, don't bother. */
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,RepPrefix));
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync Log4(("pgmPoolAccessHandler: eax=%#x ecx=%#x edi=%#x esi=%#x rip=%RGv opcode=%d prefix=%#x\n",
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync pRegFrame->eax, pRegFrame->ecx, pRegFrame->edi, pRegFrame->esi, (RTGCPTR)pRegFrame->rip, pDis->pCurInstr->opcode, pDis->prefix));
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync fNotReusedNotForking = true;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync }
815647972e1e2746466be1ea725e702459693cd5vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync#if defined(PGMPOOL_WITH_OPTIMIZED_DIRTY_PT) && defined(IN_RING0)
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync /* E.g. Windows 7 x64 initializes page tables and touches some pages in the table during the process. This
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * leads to pgm pool trashing and an excessive amount of write faults due to page monitoring.
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync */
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync if ( pPage->cModifications >= cMaxModifications
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync && !fForcedFlush
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync && (pPage->enmKind == PGMPOOLKIND_PAE_PT_FOR_PAE_PT || pPage->enmKind == PGMPOOLKIND_PAE_PT_FOR_32BIT_PT)
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync && ( fNotReusedNotForking
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync || ( !pgmPoolMonitorIsReused(pVM, pVCpu, pRegFrame, pDis, pvFault)
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync && !pgmPoolMonitorIsForking(pPool, pDis, GCPhysFault & PAGE_OFFSET_MASK))
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync )
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync )
815647972e1e2746466be1ea725e702459693cd5vboxsync {
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync Assert(!pgmPoolIsPageLocked(&pVM->pgm.s, pPage));
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync Assert(pPage->fDirty == false);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync /* Flush any monitored duplicates as we will disable write protection. */
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync if ( pPage->iMonitoredNext != NIL_PGMPOOL_IDX
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync || pPage->iMonitoredPrev != NIL_PGMPOOL_IDX)
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync {
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync PPGMPOOLPAGE pPageHead = pPage;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync /* Find the monitor head. */
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync while (pPageHead->iMonitoredPrev != NIL_PGMPOOL_IDX)
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync pPageHead = &pPool->aPages[pPageHead->iMonitoredPrev];
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync while (pPageHead)
815647972e1e2746466be1ea725e702459693cd5vboxsync {
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync unsigned idxNext = pPageHead->iMonitoredNext;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync if (pPageHead != pPage)
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync {
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync STAM_COUNTER_INC(&pPool->StatDirtyPageDupFlush);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync Log(("Flush duplicate page idx=%d GCPhys=%RGp type=%s\n", pPageHead->idx, pPageHead->GCPhys, pgmPoolPoolKindToStr(pPageHead->enmKind)));
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync int rc2 = pgmPoolFlushPage(pPool, pPageHead);
e819feefdc34d50781a3c95edecda1072e8575d0vboxsync AssertRC(rc2);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync if (idxNext == NIL_PGMPOOL_IDX)
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync break;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync pPageHead = &pPool->aPages[idxNext];
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync }
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync }
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync /* The flushing above might fail for locked pages, so double check. */
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync if ( pPage->iMonitoredNext == NIL_PGMPOOL_IDX
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync && pPage->iMonitoredPrev == NIL_PGMPOOL_IDX)
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync {
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync pgmPoolAddDirtyPage(pVM, pPool, pPage);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync /* Temporarily allow write access to the page table again. */
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync rc = PGMHandlerPhysicalPageTempOff(pVM, pPage->GCPhys & PAGE_BASE_GC_MASK, pPage->GCPhys & PAGE_BASE_GC_MASK);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync if (rc == VINF_SUCCESS)
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync {
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync rc = PGMShwMakePageWritable(pVCpu, pvFault, PGM_MK_PG_IS_WRITE_FAULT);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync AssertMsg(rc == VINF_SUCCESS
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync /* In the SMP case the page table might be removed while we wait for the PGM lock in the trap handler. */
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync || rc == VERR_PAGE_TABLE_NOT_PRESENT
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync || rc == VERR_PAGE_NOT_PRESENT,
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync ("PGMShwModifyPage -> GCPtr=%RGv rc=%d\n", pvFault, rc));
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync pPage->pvDirtyFault = pvFault;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync STAM_PROFILE_STOP(&pVM->pgm.s.CTX_SUFF(pPool)->CTX_SUFF_Z(StatMonitor), a);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmUnlock(pVM);
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync return rc;
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync }
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#endif /* PGMPOOL_WITH_OPTIMIZED_DIRTY_PT */
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,FlushModOverflow));
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsyncflushPage:
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync /*
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync * Not worth it, so flush it.
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync *
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * If we considered it to be reused, don't go back to ring-3
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync * to emulate failed instructions since we usually cannot
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * interpret then. This may be a bit risky, in which case
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * the reuse detection must be fixed.
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync */
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync rc = pgmPoolAccessHandlerFlush(pVM, pVCpu, pPool, pPage, pDis, pRegFrame, GCPhysFault, pvFault);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync if ( rc == VINF_EM_RAW_EMULATE_INSTR
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync && fReused)
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync {
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync /* Make sure that the current instruction still has shadow page backing, otherwise we'll end up in a loop. */
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync if (PGMShwGetPage(pVCpu, pRegFrame->rip, NULL, NULL) == VINF_SUCCESS)
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync rc = VINF_SUCCESS; /* safe to restart the instruction. */
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync }
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync STAM_PROFILE_STOP_EX(&pVM->pgm.s.CTX_SUFF(pPool)->CTX_SUFF_Z(StatMonitor), &pPool->CTX_MID_Z(StatMonitor,FlushPage), a);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync pgmUnlock(pVM);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync return rc;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync}
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync# endif /* !IN_RING3 */
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync# ifdef PGMPOOL_WITH_OPTIMIZED_DIRTY_PT
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync# ifdef VBOX_STRICT
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync/**
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * Check references to guest physical memory in a PAE / PAE page table.
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync *
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * @param pPool The pool.
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * @param pPage The page.
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * @param pShwPT The shadow page table (mapping of the page).
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * @param pGstPT The guest page table.
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync */
07557d07616212d7ba6e7ab3059e85cb14633775vboxsyncstatic void pgmPoolTrackCheckPTPaePae(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PPGMSHWPTPAE pShwPT, PCX86PTPAE pGstPT)
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync{
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync unsigned cErrors = 0;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync int LastRc = -1; /* initialized to shut up gcc */
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync unsigned LastPTE = ~0U; /* initialized to shut up gcc */
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync RTHCPHYS LastHCPhys = NIL_RTHCPHYS; /* initialized to shut up gcc */
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync PVM pVM = pPool->CTX_SUFF(pVM);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync#ifdef VBOX_STRICT
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync for (unsigned i = 0; i < RT_MIN(RT_ELEMENTS(pShwPT->a), pPage->iFirstPresent); i++)
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync AssertMsg(!PGMSHWPTEPAE_IS_P(pShwPT->a[i]), ("Unexpected PTE: idx=%d %RX64 (first=%d)\n", i, PGMSHWPTEPAE_GET_LOG(pShwPT->a[i]), pPage->iFirstPresent));
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync#endif
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pShwPT->a); i++)
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync {
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync if (PGMSHWPTEPAE_IS_P(pShwPT->a[i]))
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync {
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync RTHCPHYS HCPhys = NIL_RTHCPHYS;
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync int rc = PGMPhysGCPhys2HCPhys(pVM, pGstPT->a[i].u & X86_PTE_PAE_PG_MASK, &HCPhys);
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync if ( rc != VINF_SUCCESS
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync || PGMSHWPTEPAE_GET_HCPHYS(pShwPT->a[i]) != HCPhys)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log(("rc=%d idx=%d guest %RX64 shw=%RX64 vs %RHp\n", rc, i, pGstPT->a[i].u, PGMSHWPTEPAE_GET_LOG(pShwPT->a[i]), HCPhys));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync LastPTE = i;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync LastRc = rc;
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync LastHCPhys = HCPhys;
bf8889d6b20936475381d2ed2b80b06eaf2a03d1vboxsync cErrors++;
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync RTHCPHYS HCPhysPT = NIL_RTHCPHYS;
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync rc = PGMPhysGCPhys2HCPhys(pVM, pPage->GCPhys, &HCPhysPT);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertRC(rc);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync for (unsigned iPage = 0; iPage < pPool->cCurPages; iPage++)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMPOOLPAGE pTempPage = &pPool->aPages[iPage];
bf8889d6b20936475381d2ed2b80b06eaf2a03d1vboxsync
bf8889d6b20936475381d2ed2b80b06eaf2a03d1vboxsync if (pTempPage->enmKind == PGMPOOLKIND_PAE_PT_FOR_PAE_PT)
bf8889d6b20936475381d2ed2b80b06eaf2a03d1vboxsync {
bf8889d6b20936475381d2ed2b80b06eaf2a03d1vboxsync PPGMSHWPTPAE pShwPT2 = (PPGMSHWPTPAE)PGMPOOL_PAGE_2_PTR(pVM, pTempPage);
bf8889d6b20936475381d2ed2b80b06eaf2a03d1vboxsync
bf8889d6b20936475381d2ed2b80b06eaf2a03d1vboxsync for (unsigned j = 0; j < RT_ELEMENTS(pShwPT->a); j++)
bf8889d6b20936475381d2ed2b80b06eaf2a03d1vboxsync {
bf8889d6b20936475381d2ed2b80b06eaf2a03d1vboxsync if ( PGMSHWPTEPAE_IS_P_RW(pShwPT2->a[j])
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync && PGMSHWPTEPAE_GET_HCPHYS(pShwPT2->a[j]) == HCPhysPT)
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync {
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync Log(("GCPhys=%RGp idx=%d %RX64 vs %RX64\n", pTempPage->GCPhys, j, PGMSHWPTEPAE_GET_LOG(pShwPT->a[j]), PGMSHWPTEPAE_GET_LOG(pShwPT2->a[j])));
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync }
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync }
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync PGM_DYNMAP_UNUSED_HINT_VM(pVM, pShwPT2);
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync }
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync }
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync }
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync }
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertMsg(!cErrors, ("cErrors=%d: last rc=%d idx=%d guest %RX64 shw=%RX64 vs %RHp\n", cErrors, LastRc, LastPTE, pGstPT->a[LastPTE].u, PGMSHWPTEPAE_GET_LOG(pShwPT->a[LastPTE]), LastHCPhys));
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync}
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync/**
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync * Check references to guest physical memory in a PAE / 32-bit page table.
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync *
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync * @param pPool The pool.
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync * @param pPage The page.
ad2e12b64b9ccbde05d913515deced851c446b3evboxsync * @param pShwPT The shadow page table (mapping of the page).
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pGstPT The guest page table.
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync */
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsyncstatic void pgmPoolTrackCheckPTPae32Bit(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PPGMSHWPTPAE pShwPT, PCX86PT pGstPT)
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync{
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync unsigned cErrors = 0;
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync int LastRc = -1; /* initialized to shut up gcc */
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync unsigned LastPTE = ~0U; /* initialized to shut up gcc */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync RTHCPHYS LastHCPhys = NIL_RTHCPHYS; /* initialized to shut up gcc */
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync PVM pVM = pPool->CTX_SUFF(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#ifdef VBOX_STRICT
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync for (unsigned i = 0; i < RT_MIN(RT_ELEMENTS(pShwPT->a), pPage->iFirstPresent); i++)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertMsg(!PGMSHWPTEPAE_IS_P(pShwPT->a[i]), ("Unexpected PTE: idx=%d %RX64 (first=%d)\n", i, PGMSHWPTEPAE_GET_LOG(pShwPT->a[i]), pPage->iFirstPresent));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#endif
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pShwPT->a); i++)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (PGMSHWPTEPAE_IS_P(pShwPT->a[i]))
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync {
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync RTHCPHYS HCPhys = NIL_RTHCPHYS;
7c19e11502220292d5270519296442234c2493cdvboxsync int rc = PGMPhysGCPhys2HCPhys(pVM, pGstPT->a[i].u & X86_PTE_PG_MASK, &HCPhys);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if ( rc != VINF_SUCCESS
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync || PGMSHWPTEPAE_GET_HCPHYS(pShwPT->a[i]) != HCPhys)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log(("rc=%d idx=%d guest %x shw=%RX64 vs %RHp\n", rc, i, pGstPT->a[i].u, PGMSHWPTEPAE_GET_LOG(pShwPT->a[i]), HCPhys));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync LastPTE = i;
7c19e11502220292d5270519296442234c2493cdvboxsync LastRc = rc;
7c19e11502220292d5270519296442234c2493cdvboxsync LastHCPhys = HCPhys;
7c19e11502220292d5270519296442234c2493cdvboxsync cErrors++;
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync RTHCPHYS HCPhysPT = NIL_RTHCPHYS;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync rc = PGMPhysGCPhys2HCPhys(pVM, pPage->GCPhys, &HCPhysPT);
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync AssertRC(rc);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync for (unsigned iPage = 0; iPage < pPool->cCurPages; iPage++)
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync {
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync PPGMPOOLPAGE pTempPage = &pPool->aPages[iPage];
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync if (pTempPage->enmKind == PGMPOOLKIND_PAE_PT_FOR_32BIT_PT)
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync {
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync PPGMSHWPTPAE pShwPT2 = (PPGMSHWPTPAE)PGMPOOL_PAGE_2_PTR(pVM, pTempPage);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync for (unsigned j = 0; j < RT_ELEMENTS(pShwPT->a); j++)
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync {
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync if ( PGMSHWPTEPAE_IS_P_RW(pShwPT2->a[j])
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync && PGMSHWPTEPAE_GET_HCPHYS(pShwPT2->a[j]) == HCPhysPT)
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log(("GCPhys=%RGp idx=%d %RX64 vs %RX64\n", pTempPage->GCPhys, j, PGMSHWPTEPAE_GET_LOG(pShwPT->a[j]), PGMSHWPTEPAE_GET_LOG(pShwPT2->a[j])));
7c19e11502220292d5270519296442234c2493cdvboxsync }
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync }
7c19e11502220292d5270519296442234c2493cdvboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync PGM_DYNMAP_UNUSED_HINT_VM(pVM, pShwPT2);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync }
7c19e11502220292d5270519296442234c2493cdvboxsync }
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync }
7c19e11502220292d5270519296442234c2493cdvboxsync }
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync }
7c19e11502220292d5270519296442234c2493cdvboxsync AssertMsg(!cErrors, ("cErrors=%d: last rc=%d idx=%d guest %x shw=%RX64 vs %RHp\n", cErrors, LastRc, LastPTE, pGstPT->a[LastPTE].u, PGMSHWPTEPAE_GET_LOG(pShwPT->a[LastPTE]), LastHCPhys));
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync}
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
7c19e11502220292d5270519296442234c2493cdvboxsync# endif /* VBOX_STRICT */
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync/**
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * Clear references to guest physical memory in a PAE / PAE page table.
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync *
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * @returns nr of changed PTEs
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * @param pPool The pool.
7c19e11502220292d5270519296442234c2493cdvboxsync * @param pPage The page.
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * @param pShwPT The shadow page table (mapping of the page).
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * @param pGstPT The guest page table.
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * @param pOldGstPT The old cached guest page table.
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * @param fAllowRemoval Bail out as soon as we encounter an invalid PTE
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * @param pfFlush Flush reused page table (out)
7c19e11502220292d5270519296442234c2493cdvboxsync */
7c19e11502220292d5270519296442234c2493cdvboxsyncDECLINLINE(unsigned) pgmPoolTrackFlushPTPaePae(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PPGMSHWPTPAE pShwPT, PCX86PTPAE pGstPT,
7c19e11502220292d5270519296442234c2493cdvboxsync PCX86PTPAE pOldGstPT, bool fAllowRemoval, bool *pfFlush)
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync{
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync unsigned cChanged = 0;
7c19e11502220292d5270519296442234c2493cdvboxsync
7c19e11502220292d5270519296442234c2493cdvboxsync#ifdef VBOX_STRICT
7c19e11502220292d5270519296442234c2493cdvboxsync for (unsigned i = 0; i < RT_MIN(RT_ELEMENTS(pShwPT->a), pPage->iFirstPresent); i++)
d200be7337d4aad2bec2961a885e856f7866d4f6vboxsync AssertMsg(!PGMSHWPTEPAE_IS_P(pShwPT->a[i]), ("Unexpected PTE: idx=%d %RX64 (first=%d)\n", i, PGMSHWPTEPAE_GET_LOG(pShwPT->a[i]), pPage->iFirstPresent));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#endif
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *pfFlush = false;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pShwPT->a); i++)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* Check the new value written by the guest. If present and with a bogus physical address, then
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * it's fairly safe to assume the guest is reusing the PT.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if ( fAllowRemoval
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync && pGstPT->a[i].n.u1Present)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (!PGMPhysIsGCPhysValid(pPool->CTX_SUFF(pVM), pGstPT->a[i].u & X86_PTE_PAE_PG_MASK))
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *pfFlush = true;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return ++cChanged;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (PGMSHWPTEPAE_IS_P(pShwPT->a[i]))
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* If the old cached PTE is identical, then there's no need to flush the shadow copy. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if ((pGstPT->a[i].u & X86_PTE_PAE_PG_MASK) == (pOldGstPT->a[i].u & X86_PTE_PAE_PG_MASK))
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#ifdef VBOX_STRICT
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync RTHCPHYS HCPhys = NIL_RTGCPHYS;
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync int rc = PGMPhysGCPhys2HCPhys(pPool->CTX_SUFF(pVM), pGstPT->a[i].u & X86_PTE_PAE_PG_MASK, &HCPhys);
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync AssertMsg(rc == VINF_SUCCESS && PGMSHWPTEPAE_GET_HCPHYS(pShwPT->a[i]) == HCPhys, ("rc=%d guest %RX64 old %RX64 shw=%RX64 vs %RHp\n", rc, pGstPT->a[i].u, pOldGstPT->a[i].u, PGMSHWPTEPAE_GET_LOG(pShwPT->a[i]), HCPhys));
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync#endif
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync uint64_t uHostAttr = PGMSHWPTEPAE_GET_U(pShwPT->a[i]) & (X86_PTE_P | X86_PTE_US | X86_PTE_A | X86_PTE_D | X86_PTE_G | X86_PTE_PAE_NX);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync bool fHostRW = !!(PGMSHWPTEPAE_GET_U(pShwPT->a[i]) & X86_PTE_RW);
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync uint64_t uGuestAttr = pGstPT->a[i].u & (X86_PTE_P | X86_PTE_US | X86_PTE_A | X86_PTE_D | X86_PTE_G | X86_PTE_PAE_NX);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync bool fGuestRW = !!(pGstPT->a[i].u & X86_PTE_RW);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if ( uHostAttr == uGuestAttr
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync && fHostRW <= fGuestRW)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync continue;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync cChanged++;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* Something was changed, so flush it. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log4(("pgmPoolTrackDerefPTPaePae: i=%d pte=%RX64 hint=%RX64\n",
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync i, PGMSHWPTEPAE_GET_HCPHYS(pShwPT->a[i]), pOldGstPT->a[i].u & X86_PTE_PAE_PG_MASK));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolTracDerefGCPhysHint(pPool, pPage, PGMSHWPTEPAE_GET_HCPHYS(pShwPT->a[i]), pOldGstPT->a[i].u & X86_PTE_PAE_PG_MASK, i);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PGMSHWPTEPAE_ATOMIC_SET(pShwPT->a[i], 0);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return cChanged;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Clear references to guest physical memory in a PAE / PAE page table.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @returns nr of changed PTEs
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPool The pool.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPage The page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pShwPT The shadow page table (mapping of the page).
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pGstPT The guest page table.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pOldGstPT The old cached guest page table.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param fAllowRemoval Bail out as soon as we encounter an invalid PTE
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pfFlush Flush reused page table (out)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncDECLINLINE(unsigned) pgmPoolTrackFlushPTPae32Bit(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PPGMSHWPTPAE pShwPT, PCX86PT pGstPT,
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync PCX86PT pOldGstPT, bool fAllowRemoval, bool *pfFlush)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync unsigned cChanged = 0;
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#ifdef VBOX_STRICT
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync for (unsigned i = 0; i < RT_MIN(RT_ELEMENTS(pShwPT->a), pPage->iFirstPresent); i++)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertMsg(!PGMSHWPTEPAE_IS_P(pShwPT->a[i]), ("Unexpected PTE: idx=%d %RX64 (first=%d)\n", i, PGMSHWPTEPAE_GET_LOG(pShwPT->a[i]), pPage->iFirstPresent));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#endif
815647972e1e2746466be1ea725e702459693cd5vboxsync *pfFlush = false;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pShwPT->a); i++)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* Check the new value written by the guest. If present and with a bogus physical address, then
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * it's fairly safe to assume the guest is reusing the PT.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if ( fAllowRemoval
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync && pGstPT->a[i].n.u1Present)
815647972e1e2746466be1ea725e702459693cd5vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (!PGMPhysIsGCPhysValid(pPool->CTX_SUFF(pVM), pGstPT->a[i].u & X86_PTE_PG_MASK))
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *pfFlush = true;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return ++cChanged;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (PGMSHWPTEPAE_IS_P(pShwPT->a[i]))
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync {
e819feefdc34d50781a3c95edecda1072e8575d0vboxsync /* If the old cached PTE is identical, then there's no need to flush the shadow copy. */
d200be7337d4aad2bec2961a885e856f7866d4f6vboxsync if ((pGstPT->a[i].u & X86_PTE_PG_MASK) == (pOldGstPT->a[i].u & X86_PTE_PG_MASK))
e819feefdc34d50781a3c95edecda1072e8575d0vboxsync {
d200be7337d4aad2bec2961a885e856f7866d4f6vboxsync#ifdef VBOX_STRICT
e819feefdc34d50781a3c95edecda1072e8575d0vboxsync RTHCPHYS HCPhys = NIL_RTGCPHYS;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync int rc = PGMPhysGCPhys2HCPhys(pPool->CTX_SUFF(pVM), pGstPT->a[i].u & X86_PTE_PG_MASK, &HCPhys);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync AssertMsg(rc == VINF_SUCCESS && PGMSHWPTEPAE_GET_HCPHYS(pShwPT->a[i]) == HCPhys, ("rc=%d guest %x old %x shw=%RX64 vs %RHp\n", rc, pGstPT->a[i].u, pOldGstPT->a[i].u, PGMSHWPTEPAE_GET_LOG(pShwPT->a[i]), HCPhys));
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync#endif
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync uint64_t uHostAttr = PGMSHWPTEPAE_GET_U(pShwPT->a[i]) & (X86_PTE_P | X86_PTE_US | X86_PTE_A | X86_PTE_D | X86_PTE_G);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync bool fHostRW = !!(PGMSHWPTEPAE_GET_U(pShwPT->a[i]) & X86_PTE_RW);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync uint64_t uGuestAttr = pGstPT->a[i].u & (X86_PTE_P | X86_PTE_US | X86_PTE_A | X86_PTE_D | X86_PTE_G);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync bool fGuestRW = !!(pGstPT->a[i].u & X86_PTE_RW);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync if ( uHostAttr == uGuestAttr
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync && fHostRW <= fGuestRW)
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync continue;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync }
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync cChanged++;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync /* Something was changed, so flush it. */
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync Log4(("pgmPoolTrackDerefPTPaePae: i=%d pte=%RX64 hint=%x\n",
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync i, PGMSHWPTEPAE_GET_HCPHYS(pShwPT->a[i]), pOldGstPT->a[i].u & X86_PTE_PG_MASK));
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync pgmPoolTracDerefGCPhysHint(pPool, pPage, PGMSHWPTEPAE_GET_HCPHYS(pShwPT->a[i]), pOldGstPT->a[i].u & X86_PTE_PG_MASK, i);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync PGMSHWPTEPAE_ATOMIC_SET(pShwPT->a[i], 0);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync }
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync }
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync return cChanged;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync}
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync/**
ed62637a580e2dd556fce500bb7a108210800c4avboxsync * Flush a dirty page
ed62637a580e2dd556fce500bb7a108210800c4avboxsync *
ed62637a580e2dd556fce500bb7a108210800c4avboxsync * @param pVM VM Handle.
ed62637a580e2dd556fce500bb7a108210800c4avboxsync * @param pPool The pool.
ed62637a580e2dd556fce500bb7a108210800c4avboxsync * @param idxSlot Dirty array slot index
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync * @param fAllowRemoval Allow a reused page table to be removed
ed62637a580e2dd556fce500bb7a108210800c4avboxsync */
07557d07616212d7ba6e7ab3059e85cb14633775vboxsyncstatic void pgmPoolFlushDirtyPage(PVM pVM, PPGMPOOL pPool, unsigned idxSlot, bool fAllowRemoval = false)
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync{
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync PPGMPOOLPAGE pPage;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync unsigned idxPage;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(idxSlot < RT_ELEMENTS(pPool->aDirtyPages));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pPool->aDirtyPages[idxSlot].uIdx == NIL_PGMPOOL_IDX)
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync return;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync idxPage = pPool->aDirtyPages[idxSlot].uIdx;
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync AssertRelease(idxPage != NIL_PGMPOOL_IDX);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync pPage = &pPool->aPages[idxPage];
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync Assert(pPage->idx == idxPage);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync Assert(pPage->iMonitoredNext == NIL_PGMPOOL_IDX && pPage->iMonitoredPrev == NIL_PGMPOOL_IDX);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync AssertMsg(pPage->fDirty, ("Page %RGp (slot=%d) not marked dirty!", pPage->GCPhys, idxSlot));
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync Log(("Flush dirty page %RGp cMods=%d\n", pPage->GCPhys, pPage->cModifications));
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync#if defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0) || defined(IN_RC)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PVMCPU pVCpu = VMMGetCpu(pVM);
d200be7337d4aad2bec2961a885e856f7866d4f6vboxsync uint32_t iPrevSubset = PGMRZDynMapPushAutoSubset(pVCpu);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#endif
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* First write protect the page again to catch all write accesses. (before checking for changes -> SMP) */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync int rc = PGMHandlerPhysicalReset(pVM, pPage->GCPhys & PAGE_BASE_GC_MASK);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(rc == VINF_SUCCESS);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->fDirty = false;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#ifdef VBOX_STRICT
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync uint64_t fFlags = 0;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync RTHCPHYS HCPhys;
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync rc = PGMShwGetPage(VMMGetCpu(pVM), pPage->pvDirtyFault, &fFlags, &HCPhys);
d200be7337d4aad2bec2961a885e856f7866d4f6vboxsync AssertMsg( ( rc == VINF_SUCCESS
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync && (!(fFlags & X86_PTE_RW) || HCPhys != pPage->Core.Key))
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* In the SMP case the page table might be removed while we wait for the PGM lock in the trap handler. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync || rc == VERR_PAGE_TABLE_NOT_PRESENT
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync || rc == VERR_PAGE_NOT_PRESENT,
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync ("PGMShwGetPage -> GCPtr=%RGv rc=%d flags=%RX64\n", pPage->pvDirtyFault, rc, fFlags));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#endif
d200be7337d4aad2bec2961a885e856f7866d4f6vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync /* Flush those PTEs that have changed. */
d200be7337d4aad2bec2961a885e856f7866d4f6vboxsync STAM_PROFILE_START(&pPool->StatTrackDeref,a);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync void *pvShw = PGMPOOL_PAGE_2_PTR(pVM, pPage);
e819feefdc34d50781a3c95edecda1072e8575d0vboxsync void *pvGst;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync rc = PGM_GCPHYS_2_PTR_EX(pVM, pPage->GCPhys, &pvGst); AssertReleaseRC(rc);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync bool fFlush;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync unsigned cChanges;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pPage->enmKind == PGMPOOLKIND_PAE_PT_FOR_PAE_PT)
d200be7337d4aad2bec2961a885e856f7866d4f6vboxsync cChanges = pgmPoolTrackFlushPTPaePae(pPool, pPage, (PPGMSHWPTPAE)pvShw, (PCX86PTPAE)pvGst,
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync (PCX86PTPAE)&pPool->aDirtyPages[idxSlot].aPage[0], fAllowRemoval, &fFlush);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync else
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync cChanges = pgmPoolTrackFlushPTPae32Bit(pPool, pPage, (PPGMSHWPTPAE)pvShw, (PCX86PT)pvGst,
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync (PCX86PT)&pPool->aDirtyPages[idxSlot].aPage[0], fAllowRemoval, &fFlush);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PGM_DYNMAP_UNUSED_HINT_VM(pVM, pvGst);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PGM_DYNMAP_UNUSED_HINT_VM(pVM, pvShw);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_PROFILE_STOP(&pPool->StatTrackDeref,a);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* Note: we might want to consider keeping the dirty page active in case there were many changes. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* This page is likely to be modified again, so reduce the nr of modifications just a bit here. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(pPage->cModifications);
815647972e1e2746466be1ea725e702459693cd5vboxsync if (cChanges < 4)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->cModifications = 1; /* must use > 0 here */
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync else
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->cModifications = RT_MAX(1, pPage->cModifications / 2);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_COUNTER_INC(&pPool->StatResetDirtyPages);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pPool->cDirtyPages == RT_ELEMENTS(pPool->aDirtyPages))
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->idxFreeDirtyPage = idxSlot;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->cDirtyPages--;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->aDirtyPages[idxSlot].uIdx = NIL_PGMPOOL_IDX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(pPool->cDirtyPages <= RT_ELEMENTS(pPool->aDirtyPages));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (fFlush)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(fAllowRemoval);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log(("Flush reused page table!\n"));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolFlushPage(pPool, pPage);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_COUNTER_INC(&pPool->StatForceFlushReused);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync else
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log(("Removed dirty page %RGp cMods=%d cChanges=%d\n", pPage->GCPhys, pPage->cModifications, cChanges));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#if defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0) || defined(IN_RC)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PGMRZDynMapPopAutoSubset(pVCpu, iPrevSubset);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#endif
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync# ifndef IN_RING3
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Add a new dirty page
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pVM VM Handle.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPool The pool.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPage The page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncvoid pgmPoolAddDirtyPage(PVM pVM, PPGMPOOL pPool, PPGMPOOLPAGE pPage)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync unsigned idxFree;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(PGMIsLocked(pVM));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertCompile(RT_ELEMENTS(pPool->aDirtyPages) == 8 || RT_ELEMENTS(pPool->aDirtyPages) == 16);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(!pPage->fDirty);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync idxFree = pPool->idxFreeDirtyPage;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(idxFree < RT_ELEMENTS(pPool->aDirtyPages));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(pPage->iMonitoredNext == NIL_PGMPOOL_IDX && pPage->iMonitoredPrev == NIL_PGMPOOL_IDX);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pPool->cDirtyPages >= RT_ELEMENTS(pPool->aDirtyPages))
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_COUNTER_INC(&pPool->StatDirtyPageOverFlowFlush);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolFlushDirtyPage(pVM, pPool, idxFree, true /* allow removal of reused page tables*/);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(pPool->cDirtyPages < RT_ELEMENTS(pPool->aDirtyPages));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertMsg(pPool->aDirtyPages[idxFree].uIdx == NIL_PGMPOOL_IDX, ("idxFree=%d cDirtyPages=%d\n", idxFree, pPool->cDirtyPages));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log(("Add dirty page %RGp (slot=%d)\n", pPage->GCPhys, idxFree));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Make a copy of the guest page table as we require valid GCPhys addresses
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * when removing references to physical pages.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * (The HCPhys linear lookup is *extremely* expensive!)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync void *pvGst;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync int rc = PGM_GCPHYS_2_PTR_EX(pVM, pPage->GCPhys, &pvGst); AssertReleaseRC(rc);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync memcpy(&pPool->aDirtyPages[idxFree].aPage[0], pvGst, (pPage->enmKind == PGMPOOLKIND_PAE_PT_FOR_PAE_PT) ? PAGE_SIZE : PAGE_SIZE/2);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#ifdef VBOX_STRICT
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync void *pvShw = PGMPOOL_PAGE_2_PTR(pVM, pPage);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pPage->enmKind == PGMPOOLKIND_PAE_PT_FOR_PAE_PT)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolTrackCheckPTPaePae(pPool, pPage, (PPGMSHWPTPAE)pvShw, (PCX86PTPAE)pvGst);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync else
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolTrackCheckPTPae32Bit(pPool, pPage, (PPGMSHWPTPAE)pvShw, (PCX86PT)pvGst);
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync PGM_DYNMAP_UNUSED_HINT_VM(pVM, pvShw);
7c19e11502220292d5270519296442234c2493cdvboxsync#endif
7c19e11502220292d5270519296442234c2493cdvboxsync PGM_DYNMAP_UNUSED_HINT_VM(pVM, pvGst);
7c19e11502220292d5270519296442234c2493cdvboxsync
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync STAM_COUNTER_INC(&pPool->StatDirtyPage);
7c19e11502220292d5270519296442234c2493cdvboxsync pPage->fDirty = true;
7c19e11502220292d5270519296442234c2493cdvboxsync pPage->idxDirty = idxFree;
7c19e11502220292d5270519296442234c2493cdvboxsync pPool->aDirtyPages[idxFree].uIdx = pPage->idx;
7c19e11502220292d5270519296442234c2493cdvboxsync pPool->cDirtyPages++;
7c19e11502220292d5270519296442234c2493cdvboxsync
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync pPool->idxFreeDirtyPage = (pPool->idxFreeDirtyPage + 1) & (RT_ELEMENTS(pPool->aDirtyPages) - 1);
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync if ( pPool->cDirtyPages < RT_ELEMENTS(pPool->aDirtyPages)
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync && pPool->aDirtyPages[pPool->idxFreeDirtyPage].uIdx != NIL_PGMPOOL_IDX)
7c19e11502220292d5270519296442234c2493cdvboxsync {
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync unsigned i;
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync for (i = 1; i < RT_ELEMENTS(pPool->aDirtyPages); i++)
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync idxFree = (pPool->idxFreeDirtyPage + i) & (RT_ELEMENTS(pPool->aDirtyPages) - 1);
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync if (pPool->aDirtyPages[idxFree].uIdx == NIL_PGMPOOL_IDX)
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync {
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync pPool->idxFreeDirtyPage = idxFree;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(i != RT_ELEMENTS(pPool->aDirtyPages));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
7c19e11502220292d5270519296442234c2493cdvboxsync Assert(pPool->cDirtyPages == RT_ELEMENTS(pPool->aDirtyPages) || pPool->aDirtyPages[pPool->idxFreeDirtyPage].uIdx == NIL_PGMPOOL_IDX);
7c19e11502220292d5270519296442234c2493cdvboxsync return;
7c19e11502220292d5270519296442234c2493cdvboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync# endif /* !IN_RING3 */
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Check if the specified page is dirty (not write monitored)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @return dirty or not
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pVM VM Handle.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param GCPhys Guest physical address
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncbool pgmPoolIsDirtyPage(PVM pVM, RTGCPHYS GCPhys)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMPOOL pPool = pVM->pgm.s.CTX_SUFF(pPool);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(PGMIsLocked(pVM));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (!pPool->cDirtyPages)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return false;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync GCPhys = GCPhys & ~(RTGCPHYS)PAGE_OFFSET_MASK;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pPool->aDirtyPages); i++)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pPool->aDirtyPages[i].uIdx != NIL_PGMPOOL_IDX)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMPOOLPAGE pPage;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync unsigned idxPage = pPool->aDirtyPages[i].uIdx;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage = &pPool->aPages[idxPage];
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pPage->GCPhys == GCPhys)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return true;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return false;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Reset all dirty pages by reinstating page monitoring.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pVM VM Handle.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncvoid pgmPoolResetDirtyPages(PVM pVM)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMPOOL pPool = pVM->pgm.s.CTX_SUFF(pPool);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(PGMIsLocked(pVM));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(pPool->cDirtyPages <= RT_ELEMENTS(pPool->aDirtyPages));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (!pPool->cDirtyPages)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return;
0ffa3979e9b800f5931dd30c51ec3c0aadc3a1f1vboxsync
0ffa3979e9b800f5931dd30c51ec3c0aadc3a1f1vboxsync Log(("pgmPoolResetDirtyPages\n"));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pPool->aDirtyPages); i++)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolFlushDirtyPage(pVM, pPool, i, true /* allow removal of reused page tables*/);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->idxFreeDirtyPage = 0;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if ( pPool->cDirtyPages != RT_ELEMENTS(pPool->aDirtyPages)
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync && pPool->aDirtyPages[pPool->idxFreeDirtyPage].uIdx != NIL_PGMPOOL_IDX)
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync unsigned i;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync for (i = 1; i < RT_ELEMENTS(pPool->aDirtyPages); i++)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pPool->aDirtyPages[i].uIdx == NIL_PGMPOOL_IDX)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->idxFreeDirtyPage = i;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
7c19e11502220292d5270519296442234c2493cdvboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertMsg(i != RT_ELEMENTS(pPool->aDirtyPages), ("cDirtyPages %d", pPool->cDirtyPages));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(pPool->aDirtyPages[pPool->idxFreeDirtyPage].uIdx == NIL_PGMPOOL_IDX || pPool->cDirtyPages == RT_ELEMENTS(pPool->aDirtyPages));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Invalidate the PT entry for the specified page
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pVM VM Handle.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param GCPtrPage Guest page to invalidate
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncvoid pgmPoolResetDirtyPage(PVM pVM, RTGCPTR GCPtrPage)
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMPOOL pPool = pVM->pgm.s.CTX_SUFF(pPool);
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync Assert(PGMIsLocked(pVM));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(pPool->cDirtyPages <= RT_ELEMENTS(pPool->aDirtyPages));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (!pPool->cDirtyPages)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log(("pgmPoolResetDirtyPage %RGv\n", GCPtrPage));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pPool->aDirtyPages); i++)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync }
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync}
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync/**
7c19e11502220292d5270519296442234c2493cdvboxsync * Reset all dirty pages by reinstating page monitoring.
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync *
7c19e11502220292d5270519296442234c2493cdvboxsync * @param pVM VM Handle.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param GCPhysPT Physical address of the page table
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncvoid pgmPoolInvalidateDirtyPage(PVM pVM, RTGCPHYS GCPhysPT)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMPOOL pPool = pVM->pgm.s.CTX_SUFF(pPool);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(PGMIsLocked(pVM));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(pPool->cDirtyPages <= RT_ELEMENTS(pPool->aDirtyPages));
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync unsigned idxDirtyPage = RT_ELEMENTS(pPool->aDirtyPages);
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync if (!pPool->cDirtyPages)
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync return;
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync GCPhysPT = GCPhysPT & ~(RTGCPHYS)PAGE_OFFSET_MASK;
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pPool->aDirtyPages); i++)
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync {
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync if (pPool->aDirtyPages[i].uIdx != NIL_PGMPOOL_IDX)
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync {
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync unsigned idxPage = pPool->aDirtyPages[i].uIdx;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMPOOLPAGE pPage = &pPool->aPages[idxPage];
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pPage->GCPhys == GCPhysPT)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync idxDirtyPage = i;
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (idxDirtyPage != RT_ELEMENTS(pPool->aDirtyPages))
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolFlushDirtyPage(pVM, pPool, idxDirtyPage, true /* allow removal of reused page tables*/);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if ( pPool->cDirtyPages != RT_ELEMENTS(pPool->aDirtyPages)
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync && pPool->aDirtyPages[pPool->idxFreeDirtyPage].uIdx != NIL_PGMPOOL_IDX)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync unsigned i;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync for (i = 0; i < RT_ELEMENTS(pPool->aDirtyPages); i++)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pPool->aDirtyPages[i].uIdx == NIL_PGMPOOL_IDX)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->idxFreeDirtyPage = i;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertMsg(i != RT_ELEMENTS(pPool->aDirtyPages), ("cDirtyPages %d", pPool->cDirtyPages));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync# endif /* PGMPOOL_WITH_OPTIMIZED_DIRTY_PT */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Inserts a page into the GCPhys hash table.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPool The pool.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPage The page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncDECLINLINE(void) pgmPoolHashInsert(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log3(("pgmPoolHashInsert: %RGp\n", pPage->GCPhys));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(pPage->GCPhys != NIL_RTGCPHYS); Assert(pPage->iNext == NIL_PGMPOOL_IDX);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync uint16_t iHash = PGMPOOL_HASH(pPage->GCPhys);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->iNext = pPool->aiHash[iHash];
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->aiHash[iHash] = pPage->idx;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Removes a page from the GCPhys hash table.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPool The pool.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPage The page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncDECLINLINE(void) pgmPoolHashRemove(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log3(("pgmPoolHashRemove: %RGp\n", pPage->GCPhys));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync uint16_t iHash = PGMPOOL_HASH(pPage->GCPhys);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pPool->aiHash[iHash] == pPage->idx)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->aiHash[iHash] = pPage->iNext;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync else
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync uint16_t iPrev = pPool->aiHash[iHash];
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync for (;;)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync const int16_t i = pPool->aPages[iPrev].iNext;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (i == pPage->idx)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->aPages[iPrev].iNext = pPage->iNext;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (i == NIL_PGMPOOL_IDX)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertReleaseMsgFailed(("GCPhys=%RGp idx=%d\n", pPage->GCPhys, pPage->idx));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync iPrev = i;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->iNext = NIL_PGMPOOL_IDX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Frees up one cache page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @returns VBox status code.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @retval VINF_SUCCESS on success.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPool The pool.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param iUser The user index.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncstatic int pgmPoolCacheFreeOne(PPGMPOOL pPool, uint16_t iUser)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#ifndef IN_RC
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync const PVM pVM = pPool->CTX_SUFF(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#endif
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(pPool->iAgeHead != pPool->iAgeTail); /* We shouldn't be here if there < 2 cached entries! */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_COUNTER_INC(&pPool->StatCacheFreeUpOne);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Select one page from the tail of the age list.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMPOOLPAGE pPage;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync for (unsigned iLoop = 0; ; iLoop++)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync uint16_t iToFree = pPool->iAgeTail;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (iToFree == iUser)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync iToFree = pPool->aPages[iToFree].iAgePrev;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/* This is the alternative to the SyncCR3 pgmPoolCacheUsed calls.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pPool->aPages[iToFree].iUserHead != NIL_PGMPOOL_USER_INDEX)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync uint16_t i = pPool->aPages[iToFree].iAgePrev;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync for (unsigned j = 0; j < 10 && i != NIL_PGMPOOL_USER_INDEX; j++, i = pPool->aPages[i].iAgePrev)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pPool->aPages[iToFree].iUserHead == NIL_PGMPOOL_USER_INDEX)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync continue;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync iToFree = i;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync*/
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(iToFree != iUser);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertRelease(iToFree != NIL_PGMPOOL_IDX);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage = &pPool->aPages[iToFree];
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync /*
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync * Reject any attempts at flushing the currently active shadow CR3 mapping.
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync * Call pgmPoolCacheUsed to move the page to the head of the age list.
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync */
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync if (!pgmPoolIsPageLocked(&pPool->CTX_SUFF(pVM)->pgm.s, pPage))
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync LogFlow(("pgmPoolCacheFreeOne: refuse CR3 mapping\n"));
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync pgmPoolCacheUsed(pPool, pPage);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertLogRelReturn(iLoop < 8192, VERR_INTERNAL_ERROR);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Found a usable page, flush it and return.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync int rc = pgmPoolFlushPage(pPool, pPage);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* This flush was initiated by us and not the guest, so explicitly flush the TLB. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* todo: find out why this is necessary; pgmPoolFlushPage should trigger a flush if one is really needed. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (rc == VINF_SUCCESS)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PGM_INVL_ALL_VCPU_TLBS(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return rc;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync * Checks if a kind mismatch is really a page being reused
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * or if it's just normal remappings.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @returns true if reused and the cached page (enmKind1) should be flushed
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @returns false if not reused.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param enmKind1 The kind of the cached page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param enmKind2 The kind of the requested page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncstatic bool pgmPoolCacheReusedByKind(PGMPOOLKIND enmKind1, PGMPOOLKIND enmKind2)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync switch (enmKind1)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Never reuse them. There is no remapping in non-paging mode.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_32BIT_PT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_32BIT_PD_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PDPT_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PD_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_EPT_PT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_EPT_PD_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_EPT_PDPT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PDPT_FOR_32BIT: /* never reuse them for other types */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return false;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * It's perfectly fine to reuse these, except for PAE and non-paging stuff.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_4MB:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_4MB:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_PT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_PT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD0_FOR_32BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD1_FOR_32BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD2_FOR_32BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD3_FOR_32BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_32BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PDPT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync switch (enmKind2)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD_FOR_PAE_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_PT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PD_FOR_64BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_64BIT_PDPT:
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync case PGMPOOLKIND_64BIT_PML4:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_2MB:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_32BIT_PT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PD_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_EPT_PDPT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_EPT_PD_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_EPT_PT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return true;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync default:
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync return false;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * It's perfectly fine to reuse these, except for PAE and non-paging stuff.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync case PGMPOOLKIND_PAE_PD_FOR_PAE_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_PT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PD_FOR_64BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_64BIT_PDPT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PML4:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_2MB:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync switch (enmKind2)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_4MB:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_4MB:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_PT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_PT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD0_FOR_32BIT_PD:
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync case PGMPOOLKIND_PAE_PD1_FOR_32BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD2_FOR_32BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD3_FOR_32BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_32BIT_PT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PD_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_EPT_PDPT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_EPT_PD_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_EPT_PT_FOR_PHYS:
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync return true;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync default:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return false;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * These cannot be flushed, and it's common to reuse the PDs as PTs.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_ROOT_NESTED:
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync return false;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync default:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertFatalMsgFailed(("enmKind1=%d\n", enmKind1));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Attempts to satisfy a pgmPoolAlloc request from the cache.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @returns VBox status code.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @retval VINF_PGM_CACHED_PAGE on success.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @retval VERR_FILE_NOT_FOUND if not found.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPool The pool.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param GCPhys The GC physical address of the page we're gonna shadow.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param enmKind The kind of mapping.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param enmAccess Access type for the mapping (only relevant for big pages)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param iUser The shadow page pool index of the user table.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param iUserTable The index into the user table (shadowed).
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param ppPage Where to store the pointer to the page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncstatic int pgmPoolCacheAlloc(PPGMPOOL pPool, RTGCPHYS GCPhys, PGMPOOLKIND enmKind, PGMPOOLACCESS enmAccess, uint16_t iUser, uint32_t iUserTable, PPPGMPOOLPAGE ppPage)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#ifndef IN_RC
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync const PVM pVM = pPool->CTX_SUFF(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#endif
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Look up the GCPhys in the hash.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync unsigned i = pPool->aiHash[PGMPOOL_HASH(GCPhys)];
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log3(("pgmPoolCacheAlloc: %RGp kind %s iUser=%d iUserTable=%x SLOT=%d\n", GCPhys, pgmPoolPoolKindToStr(enmKind), iUser, iUserTable, i));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (i != NIL_PGMPOOL_IDX)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync do
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMPOOLPAGE pPage = &pPool->aPages[i];
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log4(("pgmPoolCacheAlloc: slot %d found page %RGp\n", i, pPage->GCPhys));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pPage->GCPhys == GCPhys)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if ( (PGMPOOLKIND)pPage->enmKind == enmKind
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync && (PGMPOOLACCESS)pPage->enmAccess == enmAccess)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* Put it at the start of the use list to make sure pgmPoolTrackAddUser
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * doesn't flush it in case there are no more free use records.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolCacheUsed(pPool, pPage);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync int rc = pgmPoolTrackAddUser(pPool, pPage, iUser, iUserTable);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (RT_SUCCESS(rc))
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert((PGMPOOLKIND)pPage->enmKind == enmKind);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *ppPage = pPage;
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync if (pPage->cModifications)
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync pPage->cModifications = 1; /* reset counter (can't use 0, or else it will be reinserted in the modified list) */
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync STAM_COUNTER_INC(&pPool->StatCacheHits);
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync return VINF_PGM_CACHED_PAGE;
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync }
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync return rc;
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync }
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync if ((PGMPOOLKIND)pPage->enmKind != enmKind)
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync {
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync /*
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync * The kind is different. In some cases we should now flush the page
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync * as it has been reused, but in most cases this is normal remapping
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync * of PDs as PT or big pages using the GCPhys field in a slightly
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync * different way than the other kinds.
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync */
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync if (pgmPoolCacheReusedByKind((PGMPOOLKIND)pPage->enmKind, enmKind))
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync {
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync STAM_COUNTER_INC(&pPool->StatCacheKindMismatches);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolFlushPage(pPool, pPage);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* next */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync i = pPage->iNext;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync } while (i != NIL_PGMPOOL_IDX);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log3(("pgmPoolCacheAlloc: Missed GCPhys=%RGp enmKind=%s\n", GCPhys, pgmPoolPoolKindToStr(enmKind)));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_COUNTER_INC(&pPool->StatCacheMisses);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return VERR_FILE_NOT_FOUND;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Inserts a page into the cache.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPool The pool.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPage The cached page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param fCanBeCached Set if the page is fit for caching from the caller's point of view.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncstatic void pgmPoolCacheInsert(PPGMPOOL pPool, PPGMPOOLPAGE pPage, bool fCanBeCached)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Insert into the GCPhys hash if the page is fit for that.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(!pPage->fCached);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (fCanBeCached)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->fCached = true;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolHashInsert(pPool, pPage);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log3(("pgmPoolCacheInsert: Caching %p:{.Core=%RHp, .idx=%d, .enmKind=%s, GCPhys=%RGp}\n",
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage, pPage->Core.Key, pPage->idx, pgmPoolPoolKindToStr(pPage->enmKind), pPage->GCPhys));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_COUNTER_INC(&pPool->StatCacheCacheable);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync else
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log3(("pgmPoolCacheInsert: Not caching %p:{.Core=%RHp, .idx=%d, .enmKind=%s, GCPhys=%RGp}\n",
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage, pPage->Core.Key, pPage->idx, pgmPoolPoolKindToStr(pPage->enmKind), pPage->GCPhys));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_COUNTER_INC(&pPool->StatCacheUncacheable);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Insert at the head of the age list.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->iAgePrev = NIL_PGMPOOL_IDX;
22e8ba5dcc23ec1e6715802fb7ac56b449d1c857vboxsync pPage->iAgeNext = pPool->iAgeHead;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pPool->iAgeHead != NIL_PGMPOOL_IDX)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->aPages[pPool->iAgeHead].iAgePrev = pPage->idx;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync else
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->iAgeTail = pPage->idx;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->iAgeHead = pPage->idx;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Flushes a cached page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPool The pool.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPage The cached page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncstatic void pgmPoolCacheFlushPage(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log3(("pgmPoolCacheFlushPage: %RGp\n", pPage->GCPhys));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync * Remove the page from the hash.
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync */
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync if (pPage->fCached)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->fCached = false;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolHashRemove(pPool, pPage);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync else
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync Assert(pPage->iNext == NIL_PGMPOOL_IDX);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Remove it from the age list.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync if (pPage->iAgeNext != NIL_PGMPOOL_IDX)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->aPages[pPage->iAgeNext].iAgePrev = pPage->iAgePrev;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync else
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->iAgeTail = pPage->iAgePrev;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pPage->iAgePrev != NIL_PGMPOOL_IDX)
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync pPool->aPages[pPage->iAgePrev].iAgeNext = pPage->iAgeNext;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync else
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->iAgeHead = pPage->iAgeNext;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->iAgeNext = NIL_PGMPOOL_IDX;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync pPage->iAgePrev = NIL_PGMPOOL_IDX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Looks for pages sharing the monitor.
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @returns Pointer to the head page.
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync * @returns NULL if not found.
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync * @param pPool The Pool
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync * @param pNewPage The page which is going to be monitored.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsyncstatic PPGMPOOLPAGE pgmPoolMonitorGetPageByGCPhys(PPGMPOOL pPool, PPGMPOOLPAGE pNewPage)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync /*
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync * Look up the GCPhys in the hash.
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync */
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync RTGCPHYS GCPhys = pNewPage->GCPhys & ~(RTGCPHYS)PAGE_OFFSET_MASK;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync unsigned i = pPool->aiHash[PGMPOOL_HASH(GCPhys)];
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (i == NIL_PGMPOOL_IDX)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return NULL;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync do
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMPOOLPAGE pPage = &pPool->aPages[i];
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if ( pPage->GCPhys - GCPhys < PAGE_SIZE
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync && pPage != pNewPage)
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync {
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync switch (pPage->enmKind)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_PT:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_PT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_PT:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_PAE_PD0_FOR_32BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD1_FOR_32BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD2_FOR_32BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD3_FOR_32BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD_FOR_PAE_PD:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_64BIT_PD_FOR_64BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_64BIT_PDPT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PML4:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_32BIT_PD:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_PAE_PDPT:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* find the head */
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync while (pPage->iMonitoredPrev != NIL_PGMPOOL_IDX)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(pPage->iMonitoredPrev != pPage->idx);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage = &pPool->aPages[pPage->iMonitoredPrev];
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return pPage;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* ignore, no monitoring. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_4MB:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_2MB:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_4MB:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_32BIT_PT_FOR_PHYS:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_PAE_PT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PD_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_EPT_PDPT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_EPT_PD_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_EPT_PT_FOR_PHYS:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_ROOT_NESTED:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PDPT_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_32BIT_PD_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PDPT_FOR_32BIT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync default:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertFatalMsgFailed(("enmKind=%d idx=%d\n", pPage->enmKind, pPage->idx));
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync /* next */
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync i = pPage->iNext;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync } while (i != NIL_PGMPOOL_IDX);
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync return NULL;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Enabled write monitoring of a guest page.
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @returns VBox status code.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @retval VINF_SUCCESS on success.
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync * @param pPool The pool.
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync * @param pPage The cached page.
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync */
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsyncstatic int pgmPoolMonitorInsert(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync LogFlow(("pgmPoolMonitorInsert %RGp\n", pPage->GCPhys & ~(RTGCPHYS)PAGE_OFFSET_MASK));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Filter out the relevant kinds.
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync switch (pPage->enmKind)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_PT:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_PT:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_PAE_PD_FOR_PAE_PD:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_PT:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_64BIT_PD_FOR_64BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_64BIT_PDPT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PML4:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_PAE_PD0_FOR_32BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD1_FOR_32BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD2_FOR_32BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD3_FOR_32BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_32BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PDPT:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_4MB:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_4MB:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_2MB:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_32BIT_PT_FOR_PHYS:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_PAE_PT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PD_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_EPT_PDPT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_EPT_PD_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_EPT_PT_FOR_PHYS:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_ROOT_NESTED:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* Nothing to monitor here. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return VINF_SUCCESS;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_32BIT_PD_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PDPT_PHYS:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_PAE_PD_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PDPT_FOR_32BIT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* Nothing to monitor here. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return VINF_SUCCESS;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync default:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertFatalMsgFailed(("This can't happen! enmKind=%d\n", pPage->enmKind));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Install handler.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync int rc;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMPOOLPAGE pPageHead = pgmPoolMonitorGetPageByGCPhys(pPool, pPage);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pPageHead)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(pPageHead != pPage); Assert(pPageHead->iMonitoredNext != pPage->idx);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(pPageHead->iMonitoredPrev != pPage->idx);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#ifdef PGMPOOL_WITH_OPTIMIZED_DIRTY_PT
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pPageHead->fDirty)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolFlushDirtyPage(pPool->CTX_SUFF(pVM), pPool, pPageHead->idxDirty, false /* do not remove */);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#endif
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->iMonitoredPrev = pPageHead->idx;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->iMonitoredNext = pPageHead->iMonitoredNext;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pPageHead->iMonitoredNext != NIL_PGMPOOL_IDX)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->aPages[pPageHead->iMonitoredNext].iMonitoredPrev = pPage->idx;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPageHead->iMonitoredNext = pPage->idx;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync rc = VINF_SUCCESS;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync else
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync Assert(pPage->iMonitoredNext == NIL_PGMPOOL_IDX); Assert(pPage->iMonitoredPrev == NIL_PGMPOOL_IDX);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PVM pVM = pPool->CTX_SUFF(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync const RTGCPHYS GCPhysPage = pPage->GCPhys & ~(RTGCPHYS)PAGE_OFFSET_MASK;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync rc = PGMHandlerPhysicalRegisterEx(pVM, PGMPHYSHANDLERTYPE_PHYSICAL_WRITE,
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync GCPhysPage, GCPhysPage + PAGE_OFFSET_MASK,
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync pPool->pfnAccessHandlerR3, MMHyperCCToR3(pVM, pPage),
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync pPool->pfnAccessHandlerR0, MMHyperCCToR0(pVM, pPage),
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync pPool->pfnAccessHandlerRC, MMHyperCCToRC(pVM, pPage),
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync pPool->pszAccessHandler);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /** @todo we should probably deal with out-of-memory conditions here, but for now increasing
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * the heap size should suffice. */
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync AssertFatalMsgRC(rc, ("PGMHandlerPhysicalRegisterEx %RGp failed with %Rrc\n", GCPhysPage, rc));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PVMCPU pVCpu = VMMGetCpu(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertFatalMsg(!(pVCpu->pgm.s.fSyncFlags & PGM_SYNC_CLEAR_PGM_POOL) || VMCPU_FF_ISSET(pVCpu, VMCPU_FF_PGM_SYNC_CR3), ("fSyncFlags=%x syncff=%d\n", pVCpu->pgm.s.fSyncFlags, VMCPU_FF_ISSET(pVCpu, VMCPU_FF_PGM_SYNC_CR3)));
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->fMonitored = true;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return rc;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync}
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync * Disables write monitoring of a guest page.
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync *
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync * @returns VBox status code.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @retval VINF_SUCCESS on success.
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync * @param pPool The pool.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPage The cached page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncstatic int pgmPoolMonitorFlush(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Filter out the relevant kinds.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync switch (pPage->enmKind)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_PT:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_PT:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_PAE_PD_FOR_PAE_PD:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_PT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PD_FOR_64BIT_PD:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_64BIT_PDPT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PML4:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_32BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PDPT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD0_FOR_32BIT_PD:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_PAE_PD1_FOR_32BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD2_FOR_32BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD3_FOR_32BIT_PD:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_4MB:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_4MB:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_2MB:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_32BIT_PT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PT_FOR_PHYS:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PD_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_EPT_PDPT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_EPT_PD_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_EPT_PT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_ROOT_NESTED:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PDPT_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_32BIT_PD_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* Nothing to monitor here. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(!pPage->fMonitored);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return VINF_SUCCESS;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync default:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertFatalMsgFailed(("This can't happen! enmKind=%d\n", pPage->enmKind));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(pPage->fMonitored);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Remove the page from the monitored list or uninstall it if last.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync const PVM pVM = pPool->CTX_SUFF(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync int rc;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if ( pPage->iMonitoredNext != NIL_PGMPOOL_IDX
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync || pPage->iMonitoredPrev != NIL_PGMPOOL_IDX)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pPage->iMonitoredPrev == NIL_PGMPOOL_IDX)
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMPOOLPAGE pNewHead = &pPool->aPages[pPage->iMonitoredNext];
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync pNewHead->iMonitoredPrev = NIL_PGMPOOL_IDX;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync rc = PGMHandlerPhysicalChangeCallbacks(pVM, pPage->GCPhys & ~(RTGCPHYS)PAGE_OFFSET_MASK,
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync pPool->pfnAccessHandlerR3, MMHyperCCToR3(pVM, pNewHead),
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync pPool->pfnAccessHandlerR0, MMHyperCCToR0(pVM, pNewHead),
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->pfnAccessHandlerRC, MMHyperCCToRC(pVM, pNewHead),
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->pszAccessHandler);
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync AssertFatalRCSuccess(rc);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->iMonitoredNext = NIL_PGMPOOL_IDX;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync }
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync else
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync pPool->aPages[pPage->iMonitoredPrev].iMonitoredNext = pPage->iMonitoredNext;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync if (pPage->iMonitoredNext != NIL_PGMPOOL_IDX)
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync {
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync pPool->aPages[pPage->iMonitoredNext].iMonitoredPrev = pPage->iMonitoredPrev;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->iMonitoredNext = NIL_PGMPOOL_IDX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->iMonitoredPrev = NIL_PGMPOOL_IDX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync rc = VINF_SUCCESS;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync else
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync rc = PGMHandlerPhysicalDeregister(pVM, pPage->GCPhys & ~(RTGCPHYS)PAGE_OFFSET_MASK);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertFatalRC(rc);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PVMCPU pVCpu = VMMGetCpu(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertFatalMsg(!(pVCpu->pgm.s.fSyncFlags & PGM_SYNC_CLEAR_PGM_POOL) || VMCPU_FF_ISSET(pVCpu, VMCPU_FF_PGM_SYNC_CR3),
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync ("%#x %#x\n", pVCpu->pgm.s.fSyncFlags, pVM->fGlobalForcedActions));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->fMonitored = false;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Remove it from the list of modified pages (if in it).
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolMonitorModifiedRemove(pPool, pPage);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return rc;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Inserts the page into the list of modified pages.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPool The pool.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPage The page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncvoid pgmPoolMonitorModifiedInsert(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log3(("pgmPoolMonitorModifiedInsert: idx=%d\n", pPage->idx));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertMsg( pPage->iModifiedNext == NIL_PGMPOOL_IDX
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync && pPage->iModifiedPrev == NIL_PGMPOOL_IDX
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync && pPool->iModifiedHead != pPage->idx,
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync ("Next=%d Prev=%d idx=%d cModifications=%d Head=%d cModifiedPages=%d\n",
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->iModifiedNext, pPage->iModifiedPrev, pPage->idx, pPage->cModifications,
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->iModifiedHead, pPool->cModifiedPages));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->iModifiedNext = pPool->iModifiedHead;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pPool->iModifiedHead != NIL_PGMPOOL_IDX)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->aPages[pPool->iModifiedHead].iModifiedPrev = pPage->idx;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->iModifiedHead = pPage->idx;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->cModifiedPages++;
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync#ifdef VBOX_WITH_STATISTICS
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync if (pPool->cModifiedPages > pPool->cModifiedPagesHigh)
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync pPool->cModifiedPagesHigh = pPool->cModifiedPages;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#endif
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync * Removes the page from the list of modified pages and resets the
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * moficiation counter.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPool The pool.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPage The page which is believed to be in the list of modified pages.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncstatic void pgmPoolMonitorModifiedRemove(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log3(("pgmPoolMonitorModifiedRemove: idx=%d cModifications=%d\n", pPage->idx, pPage->cModifications));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pPool->iModifiedHead == pPage->idx)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
0ffa3979e9b800f5931dd30c51ec3c0aadc3a1f1vboxsync Assert(pPage->iModifiedPrev == NIL_PGMPOOL_IDX);
0ffa3979e9b800f5931dd30c51ec3c0aadc3a1f1vboxsync pPool->iModifiedHead = pPage->iModifiedNext;
0ffa3979e9b800f5931dd30c51ec3c0aadc3a1f1vboxsync if (pPage->iModifiedNext != NIL_PGMPOOL_IDX)
9b37cfa6efe394762d21f3710df8fa46b2758880vboxsync {
0ffa3979e9b800f5931dd30c51ec3c0aadc3a1f1vboxsync pPool->aPages[pPage->iModifiedNext].iModifiedPrev = NIL_PGMPOOL_IDX;
0ffa3979e9b800f5931dd30c51ec3c0aadc3a1f1vboxsync pPage->iModifiedNext = NIL_PGMPOOL_IDX;
0ffa3979e9b800f5931dd30c51ec3c0aadc3a1f1vboxsync }
0ffa3979e9b800f5931dd30c51ec3c0aadc3a1f1vboxsync pPool->cModifiedPages--;
0ffa3979e9b800f5931dd30c51ec3c0aadc3a1f1vboxsync }
0ffa3979e9b800f5931dd30c51ec3c0aadc3a1f1vboxsync else if (pPage->iModifiedPrev != NIL_PGMPOOL_IDX)
0ffa3979e9b800f5931dd30c51ec3c0aadc3a1f1vboxsync {
0ffa3979e9b800f5931dd30c51ec3c0aadc3a1f1vboxsync pPool->aPages[pPage->iModifiedPrev].iModifiedNext = pPage->iModifiedNext;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pPage->iModifiedNext != NIL_PGMPOOL_IDX)
0ffa3979e9b800f5931dd30c51ec3c0aadc3a1f1vboxsync {
0ffa3979e9b800f5931dd30c51ec3c0aadc3a1f1vboxsync pPool->aPages[pPage->iModifiedNext].iModifiedPrev = pPage->iModifiedPrev;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->iModifiedNext = NIL_PGMPOOL_IDX;
0ffa3979e9b800f5931dd30c51ec3c0aadc3a1f1vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->iModifiedPrev = NIL_PGMPOOL_IDX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->cModifiedPages--;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync else
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync Assert(pPage->iModifiedPrev == NIL_PGMPOOL_IDX);
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync pPage->cModifications = 0;
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Zaps the list of modified pages, resetting their modification counters in the process.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pVM The VM handle.
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncstatic void pgmPoolMonitorModifiedClearAll(PVM pVM)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmLock(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMPOOL pPool = pVM->pgm.s.CTX_SUFF(pPool);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync LogFlow(("pgmPoolMonitorModifiedClearAll: cModifiedPages=%d\n", pPool->cModifiedPages));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync unsigned cPages = 0; NOREF(cPages);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#ifdef PGMPOOL_WITH_OPTIMIZED_DIRTY_PT
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolResetDirtyPages(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#endif
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync uint16_t idx = pPool->iModifiedHead;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->iModifiedHead = NIL_PGMPOOL_IDX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync while (idx != NIL_PGMPOOL_IDX)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMPOOLPAGE pPage = &pPool->aPages[idx];
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync idx = pPage->iModifiedNext;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->iModifiedNext = NIL_PGMPOOL_IDX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->iModifiedPrev = NIL_PGMPOOL_IDX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->cModifications = 0;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(++cPages);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertMsg(cPages == pPool->cModifiedPages, ("%d != %d\n", cPages, pPool->cModifiedPages));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->cModifiedPages = 0;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmUnlock(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Handle SyncCR3 pool tasks
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @returns VBox status code.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @retval VINF_SUCCESS if successfully added.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @retval VINF_PGM_SYNC_CR3 is it needs to be deferred to ring 3 (GC only)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pVCpu The VMCPU handle.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @remark Should only be used when monitoring is available, thus placed in
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * the PGMPOOL_WITH_MONITORING #ifdef.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncint pgmPoolSyncCR3(PVMCPU pVCpu)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PVM pVM = pVCpu->CTX_SUFF(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync LogFlow(("pgmPoolSyncCR3 fSyncFlags=%x\n", pVCpu->pgm.s.fSyncFlags));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * When monitoring shadowed pages, we reset the modification counters on CR3 sync.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Occasionally we will have to clear all the shadow page tables because we wanted
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * to monitor a page which was mapped by too many shadowed page tables. This operation
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * sometimes refered to as a 'lightweight flush'.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync# ifdef IN_RING3 /* Don't flush in ring-0 or raw mode, it's taking too long. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pVCpu->pgm.s.fSyncFlags & PGM_SYNC_CLEAR_PGM_POOL)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmR3PoolClearAll(pVM, false /*fFlushRemTlb*/);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync# else /* !IN_RING3 */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pVCpu->pgm.s.fSyncFlags & PGM_SYNC_CLEAR_PGM_POOL)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log(("SyncCR3: PGM_SYNC_CLEAR_PGM_POOL is set -> VINF_PGM_SYNC_CR3\n"));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync VMCPU_FF_SET(pVCpu, VMCPU_FF_PGM_SYNC_CR3); /** @todo no need to do global sync, right? */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* Make sure all other VCPUs return to ring 3. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pVM->cCpus > 1)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync VM_FF_SET(pVM, VM_FF_PGM_POOL_FLUSH_PENDING);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PGM_INVL_ALL_VCPU_TLBS(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return VINF_PGM_SYNC_CR3;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync# endif /* !IN_RING3 */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync else
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolMonitorModifiedClearAll(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* pgmPoolMonitorModifiedClearAll can cause a pgm pool flush (dirty page clearing), so make sure we handle this! */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pVCpu->pgm.s.fSyncFlags & PGM_SYNC_CLEAR_PGM_POOL)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log(("pgmPoolMonitorModifiedClearAll caused a pgm flush -> call pgmPoolSyncCR3 again!\n"));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return pgmPoolSyncCR3(pVCpu);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return VINF_SUCCESS;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Frees up at least one user entry.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @returns VBox status code.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @retval VINF_SUCCESS if successfully added.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @retval VERR_PGM_POOL_FLUSHED if the pool was flushed.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPool The pool.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param iUser The user index.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncstatic int pgmPoolTrackFreeOneUser(PPGMPOOL pPool, uint16_t iUser)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_COUNTER_INC(&pPool->StatTrackFreeUpOneUser);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Just free cached pages in a braindead fashion.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /** @todo walk the age list backwards and free the first with usage. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync int rc = VINF_SUCCESS;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync do
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync int rc2 = pgmPoolCacheFreeOne(pPool, iUser);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (RT_FAILURE(rc2) && rc == VINF_SUCCESS)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync rc = rc2;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync } while (pPool->iUserFreeHead == NIL_PGMPOOL_USER_INDEX);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return rc;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Inserts a page into the cache.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * This will create user node for the page, insert it into the GCPhys
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * hash, and insert it into the age list.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @returns VBox status code.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @retval VINF_SUCCESS if successfully added.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @retval VERR_PGM_POOL_FLUSHED if the pool was flushed.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPool The pool.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPage The cached page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param GCPhys The GC physical address of the page we're gonna shadow.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param iUser The user index.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param iUserTable The user table index.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsyncDECLINLINE(int) pgmPoolTrackInsert(PPGMPOOL pPool, PPGMPOOLPAGE pPage, RTGCPHYS GCPhys, uint16_t iUser, uint32_t iUserTable)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync int rc = VINF_SUCCESS;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMPOOLUSER paUsers = pPool->CTX_SUFF(paUsers);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync LogFlow(("pgmPoolTrackInsert GCPhys=%RGp iUser=%d iUserTable=%x\n", GCPhys, iUser, iUserTable));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#ifdef VBOX_STRICT
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Check that the entry doesn't already exists.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pPage->iUserHead != NIL_PGMPOOL_USER_INDEX)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync uint16_t i = pPage->iUserHead;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync do
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(i < pPool->cMaxUsers);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertMsg(paUsers[i].iUser != iUser || paUsers[i].iUserTable != iUserTable, ("%x %x vs new %x %x\n", paUsers[i].iUser, paUsers[i].iUserTable, iUser, iUserTable));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync i = paUsers[i].iNext;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync } while (i != NIL_PGMPOOL_USER_INDEX);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#endif
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Find free a user node.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
0ffa3979e9b800f5931dd30c51ec3c0aadc3a1f1vboxsync uint16_t i = pPool->iUserFreeHead;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (i == NIL_PGMPOOL_USER_INDEX)
0ffa3979e9b800f5931dd30c51ec3c0aadc3a1f1vboxsync {
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync rc = pgmPoolTrackFreeOneUser(pPool, iUser);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (RT_FAILURE(rc))
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return rc;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync i = pPool->iUserFreeHead;
c69ef54ce54c2282a61c82986d2fd748d930719bvboxsync }
c69ef54ce54c2282a61c82986d2fd748d930719bvboxsync
c69ef54ce54c2282a61c82986d2fd748d930719bvboxsync /*
c69ef54ce54c2282a61c82986d2fd748d930719bvboxsync * Unlink the user node from the free list,
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync * initialize and insert it into the user list.
c69ef54ce54c2282a61c82986d2fd748d930719bvboxsync */
c69ef54ce54c2282a61c82986d2fd748d930719bvboxsync pPool->iUserFreeHead = paUsers[i].iNext;
c69ef54ce54c2282a61c82986d2fd748d930719bvboxsync paUsers[i].iNext = NIL_PGMPOOL_USER_INDEX;
c69ef54ce54c2282a61c82986d2fd748d930719bvboxsync paUsers[i].iUser = iUser;
c69ef54ce54c2282a61c82986d2fd748d930719bvboxsync paUsers[i].iUserTable = iUserTable;
c69ef54ce54c2282a61c82986d2fd748d930719bvboxsync pPage->iUserHead = i;
c69ef54ce54c2282a61c82986d2fd748d930719bvboxsync
c69ef54ce54c2282a61c82986d2fd748d930719bvboxsync /*
c69ef54ce54c2282a61c82986d2fd748d930719bvboxsync * Insert into cache and enable monitoring of the guest page if enabled.
c69ef54ce54c2282a61c82986d2fd748d930719bvboxsync *
c69ef54ce54c2282a61c82986d2fd748d930719bvboxsync * Until we implement caching of all levels, including the CR3 one, we'll
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync * have to make sure we don't try monitor & cache any recursive reuse of
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync * a monitored CR3 page. Because all windows versions are doing this we'll
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync * have to be able to do combined access monitoring, CR3 + PT and
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync * PD + PT (guest PAE).
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Update:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * We're now cooperating with the CR3 monitor if an uncachable page is found.
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync const bool fCanBeMonitored = true;
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync pgmPoolCacheInsert(pPool, pPage, fCanBeMonitored); /* This can be expanded. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (fCanBeMonitored)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync rc = pgmPoolMonitorInsert(pPool, pPage);
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync AssertRC(rc);
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return rc;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync * Adds a user reference to a page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * This will move the page to the head of the
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @returns VBox status code.
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync * @retval VINF_SUCCESS if successfully added.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @retval VERR_PGM_POOL_FLUSHED if the pool was flushed.
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync * @param pPool The pool.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPage The cached page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param iUser The user index.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param iUserTable The user table.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncstatic int pgmPoolTrackAddUser(PPGMPOOL pPool, PPGMPOOLPAGE pPage, uint16_t iUser, uint32_t iUserTable)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMPOOLUSER paUsers = pPool->CTX_SUFF(paUsers);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log3(("pgmPoolTrackAddUser GCPhys = %RGp iUser %x iUserTable %x\n", pPage->GCPhys, iUser, iUserTable));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync# ifdef VBOX_STRICT
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Check that the entry doesn't already exists. We only allow multiple
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * users of top-level paging structures (SHW_POOL_ROOT_IDX).
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pPage->iUserHead != NIL_PGMPOOL_USER_INDEX)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync uint16_t i = pPage->iUserHead;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync do
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(i < pPool->cMaxUsers);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertMsg(iUser != PGMPOOL_IDX_PD || iUser != PGMPOOL_IDX_PDPT || iUser != PGMPOOL_IDX_NESTED_ROOT || iUser != PGMPOOL_IDX_AMD64_CR3 ||
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync paUsers[i].iUser != iUser || paUsers[i].iUserTable != iUserTable, ("%x %x vs new %x %x\n", paUsers[i].iUser, paUsers[i].iUserTable, iUser, iUserTable));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync i = paUsers[i].iNext;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync } while (i != NIL_PGMPOOL_USER_INDEX);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync# endif
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Allocate a user node.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync uint16_t i = pPool->iUserFreeHead;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (i == NIL_PGMPOOL_USER_INDEX)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync int rc = pgmPoolTrackFreeOneUser(pPool, iUser);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (RT_FAILURE(rc))
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return rc;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync i = pPool->iUserFreeHead;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->iUserFreeHead = paUsers[i].iNext;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Initialize the user node and insert it.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync paUsers[i].iNext = pPage->iUserHead;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync paUsers[i].iUser = iUser;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync paUsers[i].iUserTable = iUserTable;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->iUserHead = i;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync# ifdef PGMPOOL_WITH_OPTIMIZED_DIRTY_PT
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pPage->fDirty)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolFlushDirtyPage(pPool->CTX_SUFF(pVM), pPool, pPage->idxDirty, false /* do not remove */);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync# endif
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Tell the cache to update its replacement stats for this page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolCacheUsed(pPool, pPage);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return VINF_SUCCESS;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Frees a user record associated with a page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * This does not clear the entry in the user table, it simply replaces the
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * user record to the chain of free records.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPool The pool.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param HCPhys The HC physical address of the shadow page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param iUser The shadow page pool index of the user table.
0ffa3979e9b800f5931dd30c51ec3c0aadc3a1f1vboxsync * @param iUserTable The index into the user table (shadowed).
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
0ffa3979e9b800f5931dd30c51ec3c0aadc3a1f1vboxsyncstatic void pgmPoolTrackFreeUser(PPGMPOOL pPool, PPGMPOOLPAGE pPage, uint16_t iUser, uint32_t iUserTable)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Unlink and free the specified user entry.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMPOOLUSER paUsers = pPool->CTX_SUFF(paUsers);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log3(("pgmPoolTrackFreeUser %RGp %x %x\n", pPage->GCPhys, iUser, iUserTable));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* Special: For PAE and 32-bit paging, there is usually no more than one user. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync uint16_t i = pPage->iUserHead;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if ( i != NIL_PGMPOOL_USER_INDEX
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync && paUsers[i].iUser == iUser
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync && paUsers[i].iUserTable == iUserTable)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->iUserHead = paUsers[i].iNext;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync paUsers[i].iUser = NIL_PGMPOOL_IDX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync paUsers[i].iNext = pPool->iUserFreeHead;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->iUserFreeHead = i;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* General: Linear search. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync uint16_t iPrev = NIL_PGMPOOL_USER_INDEX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync while (i != NIL_PGMPOOL_USER_INDEX)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync if ( paUsers[i].iUser == iUser
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync && paUsers[i].iUserTable == iUserTable)
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync {
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync if (iPrev != NIL_PGMPOOL_USER_INDEX)
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync paUsers[iPrev].iNext = paUsers[i].iNext;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync else
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync pPage->iUserHead = paUsers[i].iNext;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync paUsers[i].iUser = NIL_PGMPOOL_IDX;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync paUsers[i].iNext = pPool->iUserFreeHead;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync pPool->iUserFreeHead = i;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync return;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync }
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync iPrev = i;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync i = paUsers[i].iNext;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync }
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync /* Fatal: didn't find it */
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync AssertFatalMsgFailed(("Didn't find the user entry! iUser=%d iUserTable=%#x GCPhys=%RGp\n",
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync iUser, iUserTable, pPage->GCPhys));
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync}
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync/**
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync * Gets the entry size of a shadow table.
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync *
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync * @param enmKind The kind of page.
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync *
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync * @returns The size of the entry in bytes. That is, 4 or 8.
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync * @returns If the kind is not for a table, an assertion is raised and 0 is
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync * returned.
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync */
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsyncDECLINLINE(unsigned) pgmPoolTrackGetShadowEntrySize(PGMPOOLKIND enmKind)
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync{
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync switch (enmKind)
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync {
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_PT:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_32BIT_PT_FOR_PHYS:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_4MB:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_32BIT_PD:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_32BIT_PD_PHYS:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync return 4;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_PAE_PT_FOR_PHYS:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_PT:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_4MB:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_PT:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_2MB:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_PAE_PD0_FOR_32BIT_PD:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_PAE_PD1_FOR_32BIT_PD:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_PAE_PD2_FOR_32BIT_PD:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_PAE_PD3_FOR_32BIT_PD:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_PAE_PD_FOR_PAE_PD:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_64BIT_PD_FOR_64BIT_PD:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_64BIT_PDPT:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_64BIT_PML4:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_PAE_PDPT:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_ROOT_NESTED:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_PHYS:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_64BIT_PD_FOR_PHYS:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_EPT_PDPT_FOR_PHYS:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_EPT_PD_FOR_PHYS:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_EPT_PT_FOR_PHYS:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_PAE_PD_PHYS:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_PAE_PDPT_PHYS:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync return 8;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync default:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync AssertFatalMsgFailed(("enmKind=%d\n", enmKind));
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync }
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync}
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync/**
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync * Gets the entry size of a guest table.
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync *
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync * @param enmKind The kind of page.
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync *
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync * @returns The size of the entry in bytes. That is, 0, 4 or 8.
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync * @returns If the kind is not for a table, an assertion is raised and 0 is
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync * returned.
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync */
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsyncDECLINLINE(unsigned) pgmPoolTrackGetGuestEntrySize(PGMPOOLKIND enmKind)
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync{
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync switch (enmKind)
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync {
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_PT:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_4MB:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_32BIT_PD:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_PT:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_4MB:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_PAE_PD0_FOR_32BIT_PD:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_PAE_PD1_FOR_32BIT_PD:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_PAE_PD2_FOR_32BIT_PD:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_PAE_PD3_FOR_32BIT_PD:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync return 4;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_PT:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_2MB:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_PAE_PD_FOR_PAE_PD:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_64BIT_PD_FOR_64BIT_PD:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_64BIT_PDPT:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_64BIT_PML4:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_PAE_PDPT:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync return 8;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_32BIT_PT_FOR_PHYS:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_PAE_PT_FOR_PHYS:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_PHYS:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_64BIT_PD_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_EPT_PDPT_FOR_PHYS:
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync case PGMPOOLKIND_EPT_PD_FOR_PHYS:
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync case PGMPOOLKIND_EPT_PT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_ROOT_NESTED:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD_PHYS:
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync case PGMPOOLKIND_PAE_PDPT_PHYS:
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync case PGMPOOLKIND_32BIT_PD_PHYS:
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync /** @todo can we return 0? (nobody is calling this...) */
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync AssertFailed();
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync return 0;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync default:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertFatalMsgFailed(("enmKind=%d\n", enmKind));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Checks one shadow page table entry for a mapping of a physical page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @returns true / false indicating removal of all relevant PTEs
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
2baa3306795480a7d51024e33733db7bcd14e7bavboxsync * @param pVM The VM handle.
2baa3306795480a7d51024e33733db7bcd14e7bavboxsync * @param pPhysPage The guest page in question.
2baa3306795480a7d51024e33733db7bcd14e7bavboxsync * @param fFlushPTEs Flush PTEs or allow them to be updated (e.g. in case of an RW bit change)
2baa3306795480a7d51024e33733db7bcd14e7bavboxsync * @param iShw The shadow page table.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param iPte Page table entry or NIL_PGMPOOL_PHYSEXT_IDX_PTE if unknown
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncstatic bool pgmPoolTrackFlushGCPhysPTInt(PVM pVM, PCPGMPAGE pPhysPage, bool fFlushPTEs, uint16_t iShw, uint16_t iPte)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync LogFlow(("pgmPoolTrackFlushGCPhysPTInt: pPhysPage=%RHp iShw=%d iPte=%d\n", PGM_PAGE_GET_HCPHYS(pPhysPage), iShw, iPte));
2baa3306795480a7d51024e33733db7bcd14e7bavboxsync PPGMPOOL pPool = pVM->pgm.s.CTX_SUFF(pPool);
2baa3306795480a7d51024e33733db7bcd14e7bavboxsync bool fRet = false;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
2baa3306795480a7d51024e33733db7bcd14e7bavboxsync /*
2baa3306795480a7d51024e33733db7bcd14e7bavboxsync * Assert sanity.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync Assert(iPte != NIL_PGMPOOL_PHYSEXT_IDX_PTE);
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync AssertFatalMsg(iShw < pPool->cCurPages && iShw != NIL_PGMPOOL_IDX, ("iShw=%d\n", iShw));
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync PPGMPOOLPAGE pPage = &pPool->aPages[iShw];
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync /*
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync * Then, clear the actual mappings to the page in the shadow PT.
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync */
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync switch (pPage->enmKind)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_PT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_4MB:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_32BIT_PT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync const uint32_t u32 = PGM_PAGE_GET_HCPHYS(pPhysPage) | X86_PTE_P;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PX86PT pPT = (PX86PT)PGMPOOL_PAGE_2_PTR(pVM, pPage);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync uint32_t u32AndMask = 0;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync uint32_t u32OrMask = 0;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
e12084fc5287a5fa65e3a28bbeb05af29c22dad7vboxsync if (!fFlushPTEs)
8177818e385db2d90f58710d17aa5f66e074f2f6vboxsync {
8177818e385db2d90f58710d17aa5f66e074f2f6vboxsync switch (PGM_PAGE_GET_HNDL_PHYS_STATE(pPhysPage))
8177818e385db2d90f58710d17aa5f66e074f2f6vboxsync {
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync case PGM_PAGE_HNDL_PHYS_STATE_NONE: /** No handler installed. */
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync case PGM_PAGE_HNDL_PHYS_STATE_DISABLED: /** Monitoring is temporarily disabled. */
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync u32OrMask = X86_PTE_RW;
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync u32AndMask = UINT32_MAX;
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync fRet = true;
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync STAM_COUNTER_INC(&pPool->StatTrackFlushEntryKeep);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync
2baa3306795480a7d51024e33733db7bcd14e7bavboxsync case PGM_PAGE_HNDL_PHYS_STATE_WRITE: /** Write access is monitored. */
e12084fc5287a5fa65e3a28bbeb05af29c22dad7vboxsync u32OrMask = 0;
e12084fc5287a5fa65e3a28bbeb05af29c22dad7vboxsync u32AndMask = ~X86_PTE_RW;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync fRet = true;
2baa3306795480a7d51024e33733db7bcd14e7bavboxsync STAM_COUNTER_INC(&pPool->StatTrackFlushEntryKeep);
2baa3306795480a7d51024e33733db7bcd14e7bavboxsync break;
2baa3306795480a7d51024e33733db7bcd14e7bavboxsync default:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* (shouldn't be here, will assert below) */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_COUNTER_INC(&pPool->StatTrackFlushEntry);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync }
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync else
290f895ae2ac655ba90c8904a0e2687d8aa0837dvboxsync STAM_COUNTER_INC(&pPool->StatTrackFlushEntry);
e12084fc5287a5fa65e3a28bbeb05af29c22dad7vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* Update the counter if we're removing references. */
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync if (!u32AndMask)
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync {
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync Assert(pPage->cPresent );
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync Assert(pPool->cPresent);
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync pPage->cPresent--;
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync pPool->cPresent--;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if ((pPT->a[iPte].u & (X86_PTE_PG_MASK | X86_PTE_P)) == u32)
e12084fc5287a5fa65e3a28bbeb05af29c22dad7vboxsync {
e12084fc5287a5fa65e3a28bbeb05af29c22dad7vboxsync X86PTE Pte;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log4(("pgmPoolTrackFlushGCPhysPTs: i=%d pte=%RX32\n", iPte, pPT->a[iPte]));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Pte.u = (pPT->a[iPte].u & u32AndMask) | u32OrMask;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (Pte.u & PGM_PTFLAGS_TRACK_DIRTY)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Pte.n.u1Write = 0; /* need to disallow writes when dirty bit tracking is still active. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync ASMAtomicWriteU32(&pPT->a[iPte].u, Pte.u);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PGM_DYNMAP_UNUSED_HINT_VM(pVM, pPT);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return fRet;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#ifdef LOG_ENABLED
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log(("iFirstPresent=%d cPresent=%d\n", pPage->iFirstPresent, pPage->cPresent));
0ffa3979e9b800f5931dd30c51ec3c0aadc3a1f1vboxsync for (unsigned i = 0, cFound = 0; i < RT_ELEMENTS(pPT->a); i++)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if ((pPT->a[i].u & (X86_PTE_PG_MASK | X86_PTE_P)) == u32)
0ffa3979e9b800f5931dd30c51ec3c0aadc3a1f1vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log(("i=%d cFound=%d\n", i, ++cFound));
0ffa3979e9b800f5931dd30c51ec3c0aadc3a1f1vboxsync }
0ffa3979e9b800f5931dd30c51ec3c0aadc3a1f1vboxsync#endif
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertFatalMsgFailed(("iFirstPresent=%d cPresent=%d u32=%RX32 poolkind=%x\n", pPage->iFirstPresent, pPage->cPresent, u32, pPage->enmKind));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PGM_DYNMAP_UNUSED_HINT_VM(pVM, pPT);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync }
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_PT:
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_4MB:
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_PT:
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_2MB:
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync case PGMPOOLKIND_PAE_PT_FOR_PHYS:
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync case PGMPOOLKIND_EPT_PT_FOR_PHYS: /* physical mask the same as PAE; RW bit as well; be careful! */
290f895ae2ac655ba90c8904a0e2687d8aa0837dvboxsync {
4c2dae8889e41182eef3162d516fa7ef73b6f536vboxsync const uint64_t u64 = PGM_PAGE_GET_HCPHYS(pPhysPage) | X86_PTE_P;
4c2dae8889e41182eef3162d516fa7ef73b6f536vboxsync PPGMSHWPTPAE pPT = (PPGMSHWPTPAE)PGMPOOL_PAGE_2_PTR(pVM, pPage);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync uint64_t u64OrMask = 0;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync uint64_t u64AndMask = 0;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (!fFlushPTEs)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync switch (PGM_PAGE_GET_HNDL_PHYS_STATE(pPhysPage))
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync case PGM_PAGE_HNDL_PHYS_STATE_NONE: /* No handler installed. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGM_PAGE_HNDL_PHYS_STATE_DISABLED: /* Monitoring is temporarily disabled. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync u64OrMask = X86_PTE_RW;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync u64AndMask = UINT64_MAX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync fRet = true;
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync STAM_COUNTER_INC(&pPool->StatTrackFlushEntryKeep);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGM_PAGE_HNDL_PHYS_STATE_WRITE: /* Write access is monitored. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync u64OrMask = 0;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync u64AndMask = ~(uint64_t)X86_PTE_RW;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync fRet = true;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_COUNTER_INC(&pPool->StatTrackFlushEntryKeep);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync default:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* (shouldn't be here, will assert below) */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_COUNTER_INC(&pPool->StatTrackFlushEntry);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync else
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_COUNTER_INC(&pPool->StatTrackFlushEntry);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* Update the counter if we're removing references. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (!u64AndMask)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(pPage->cPresent);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(pPool->cPresent);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->cPresent--;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->cPresent--;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
e12084fc5287a5fa65e3a28bbeb05af29c22dad7vboxsync
e12084fc5287a5fa65e3a28bbeb05af29c22dad7vboxsync if ((PGMSHWPTEPAE_GET_U(pPT->a[iPte]) & (X86_PTE_PAE_PG_MASK | X86_PTE_P | X86_PTE_PAE_MBZ_MASK_NX)) == u64)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
e12084fc5287a5fa65e3a28bbeb05af29c22dad7vboxsync X86PTEPAE Pte;
e12084fc5287a5fa65e3a28bbeb05af29c22dad7vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log4(("pgmPoolTrackFlushGCPhysPTs: i=%d pte=%RX64\n", iPte, PGMSHWPTEPAE_GET_LOG(pPT->a[iPte])));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Pte.u = (PGMSHWPTEPAE_GET_U(pPT->a[iPte]) & u64AndMask) | u64OrMask;
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync if (Pte.u & PGM_PTFLAGS_TRACK_DIRTY)
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync Pte.n.u1Write = 0; /* need to disallow writes when dirty bit tracking is still active. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PGMSHWPTEPAE_ATOMIC_SET(pPT->a[iPte], Pte.u);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PGM_DYNMAP_UNUSED_HINT_VM(pVM, pPT);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return fRet;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#ifdef LOG_ENABLED
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log(("iFirstPresent=%d cPresent=%d\n", pPage->iFirstPresent, pPage->cPresent));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log(("Found %RX64 expected %RX64\n", PGMSHWPTEPAE_GET_U(pPT->a[iPte]) & (X86_PTE_PAE_PG_MASK | X86_PTE_P | X86_PTE_PAE_MBZ_MASK_NX), u64));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync for (unsigned i = 0, cFound = 0; i < RT_ELEMENTS(pPT->a); i++)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if ((PGMSHWPTEPAE_GET_U(pPT->a[i]) & (X86_PTE_PAE_PG_MASK | X86_PTE_P | X86_PTE_PAE_MBZ_MASK_NX)) == u64)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log(("i=%d cFound=%d\n", i, ++cFound));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#endif
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertFatalMsgFailed(("iFirstPresent=%d cPresent=%d u64=%RX64 poolkind=%x iPte=%d PT=%RX64\n", pPage->iFirstPresent, pPage->cPresent, u64, pPage->enmKind, iPte, PGMSHWPTEPAE_GET_LOG(pPT->a[iPte])));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PGM_DYNMAP_UNUSED_HINT_VM(pVM, pPT);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#ifdef PGM_WITH_LARGE_PAGES
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* Large page case only. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_EPT_PD_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(pVM->pgm.s.fNestedPaging);
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync const uint64_t u64 = PGM_PAGE_GET_HCPHYS(pPhysPage) | X86_PDE4M_P | X86_PDE4M_PS;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PEPTPD pPD = (PEPTPD)PGMPOOL_PAGE_2_PTR(pVM, pPage);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if ((pPD->a[iPte].u & (EPT_PDE2M_PG_MASK | X86_PDE4M_P | X86_PDE4M_PS)) == u64)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log4(("pgmPoolTrackFlushGCPhysPTs: i=%d pde=%RX64\n", iPte, pPD->a[iPte]));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_COUNTER_INC(&pPool->StatTrackFlushEntry);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPD->a[iPte].u = 0;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PGM_DYNMAP_UNUSED_HINT_VM(pVM, pPD);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* Update the counter as we're removing references. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(pPage->cPresent);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(pPool->cPresent);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->cPresent--;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync pPool->cPresent--;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync return fRet;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync }
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync# ifdef LOG_ENABLED
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync Log(("iFirstPresent=%d cPresent=%d\n", pPage->iFirstPresent, pPage->cPresent));
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync for (unsigned i = 0, cFound = 0; i < RT_ELEMENTS(pPD->a); i++)
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync if ((pPD->a[i].u & (EPT_PDE2M_PG_MASK | X86_PDE4M_P | X86_PDE4M_PS)) == u64)
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync Log(("i=%d cFound=%d\n", i, ++cFound));
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync# endif
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync AssertFatalMsgFailed(("iFirstPresent=%d cPresent=%d\n", pPage->iFirstPresent, pPage->cPresent));
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync PGM_DYNMAP_UNUSED_HINT_VM(pVM, pPD);
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync break;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync }
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync /* AMD-V nested paging */ /** @todo merge with EPT as we only check the parts that are identical. */
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync case PGMPOOLKIND_PAE_PD_PHYS:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync {
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync Assert(pVM->pgm.s.fNestedPaging);
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync const uint64_t u64 = PGM_PAGE_GET_HCPHYS(pPhysPage) | X86_PDE4M_P | X86_PDE4M_PS;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync PX86PD pPD = (PX86PD)PGMPOOL_PAGE_2_PTR(pVM, pPage);
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync if ((pPD->a[iPte].u & (X86_PDE2M_PAE_PG_MASK | X86_PDE4M_P | X86_PDE4M_PS)) == u64)
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync {
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync Log4(("pgmPoolTrackFlushGCPhysPTs: i=%d pde=%RX64\n", iPte, pPD->a[iPte]));
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync STAM_COUNTER_INC(&pPool->StatTrackFlushEntry);
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync pPD->a[iPte].u = 0;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync PGM_DYNMAP_UNUSED_HINT_VM(pVM, pPD);
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync /* Update the counter as we're removing references. */
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync Assert(pPage->cPresent);
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync Assert(pPool->cPresent);
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync pPage->cPresent--;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync pPool->cPresent--;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync return fRet;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync }
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync# ifdef LOG_ENABLED
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync Log(("iFirstPresent=%d cPresent=%d\n", pPage->iFirstPresent, pPage->cPresent));
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync for (unsigned i = 0, cFound = 0; i < RT_ELEMENTS(pPD->a); i++)
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync if ((pPD->a[i].u & (X86_PDE2M_PAE_PG_MASK | X86_PDE4M_P | X86_PDE4M_PS)) == u64)
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync Log(("i=%d cFound=%d\n", i, ++cFound));
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync# endif
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync AssertFatalMsgFailed(("iFirstPresent=%d cPresent=%d\n", pPage->iFirstPresent, pPage->cPresent));
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync PGM_DYNMAP_UNUSED_HINT_VM(pVM, pPD);
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync break;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync }
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync#endif /* PGM_WITH_LARGE_PAGES */
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync default:
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync AssertFatalMsgFailed(("enmKind=%d iShw=%d\n", pPage->enmKind, iShw));
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync }
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync return fRet;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync}
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync/**
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync * Scans one shadow page table for mappings of a physical page.
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync *
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync * @param pVM The VM handle.
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync * @param pPhysPage The guest page in question.
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync * @param fFlushPTEs Flush PTEs or allow them to be updated (e.g. in case of an RW bit change)
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync * @param iShw The shadow page table.
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync */
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsyncstatic void pgmPoolTrackFlushGCPhysPT(PVM pVM, PPGMPAGE pPhysPage, bool fFlushPTEs, uint16_t iShw)
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync{
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync PPGMPOOL pPool = pVM->pgm.s.CTX_SUFF(pPool); NOREF(pPool);
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync /* We should only come here with when there's only one reference to this physical page. */
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync Assert(PGMPOOL_TD_GET_CREFS(PGM_PAGE_GET_TRACKING(pPhysPage)) == 1);
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync Log2(("pgmPoolTrackFlushGCPhysPT: pPhysPage=%RHp iShw=%d\n", PGM_PAGE_GET_HCPHYS(pPhysPage), iShw));
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync STAM_PROFILE_START(&pPool->StatTrackFlushGCPhysPT, f);
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync bool fKeptPTEs = pgmPoolTrackFlushGCPhysPTInt(pVM, pPhysPage, fFlushPTEs, iShw, PGM_PAGE_GET_PTE_INDEX(pPhysPage));
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync if (!fKeptPTEs)
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync PGM_PAGE_SET_TRACKING(pPhysPage, 0);
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync STAM_PROFILE_STOP(&pPool->StatTrackFlushGCPhysPT, f);
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync}
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync/**
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync * Flushes a list of shadow page tables mapping the same physical page.
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync *
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync * @param pVM The VM handle.
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync * @param pPhysPage The guest page in question.
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync * @param fFlushPTEs Flush PTEs or allow them to be updated (e.g. in case of an RW bit change)
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync * @param iPhysExt The physical cross reference extent list to flush.
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync */
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsyncstatic void pgmPoolTrackFlushGCPhysPTs(PVM pVM, PPGMPAGE pPhysPage, bool fFlushPTEs, uint16_t iPhysExt)
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync{
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync Assert(PGMIsLockOwner(pVM));
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync PPGMPOOL pPool = pVM->pgm.s.CTX_SUFF(pPool);
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync bool fKeepList = false;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync STAM_PROFILE_START(&pPool->StatTrackFlushGCPhysPTs, f);
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync Log2(("pgmPoolTrackFlushGCPhysPTs: pPhysPage=%RHp iPhysExt\n", PGM_PAGE_GET_HCPHYS(pPhysPage), iPhysExt));
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync const uint16_t iPhysExtStart = iPhysExt;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync PPGMPOOLPHYSEXT pPhysExt;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync do
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync {
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync Assert(iPhysExt < pPool->cMaxPhysExts);
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync pPhysExt = &pPool->CTX_SUFF(paPhysExts)[iPhysExt];
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pPhysExt->aidx); i++)
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync {
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync if (pPhysExt->aidx[i] != NIL_PGMPOOL_IDX)
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync {
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync bool fKeptPTEs = pgmPoolTrackFlushGCPhysPTInt(pVM, pPhysPage, fFlushPTEs, pPhysExt->aidx[i], pPhysExt->apte[i]);
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync if (!fKeptPTEs)
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync {
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync pPhysExt->aidx[i] = NIL_PGMPOOL_IDX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPhysExt->apte[i] = NIL_PGMPOOL_PHYSEXT_IDX_PTE;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync else
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync fKeepList = true;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* next */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync iPhysExt = pPhysExt->iNext;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync } while (iPhysExt != NIL_PGMPOOL_PHYSEXT_INDEX);
0ffa3979e9b800f5931dd30c51ec3c0aadc3a1f1vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (!fKeepList)
0ffa3979e9b800f5931dd30c51ec3c0aadc3a1f1vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* insert the list into the free list and clear the ram range entry. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPhysExt->iNext = pPool->iPhysExtFreeHead;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->iPhysExtFreeHead = iPhysExtStart;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* Invalidate the tracking data. */
d200be7337d4aad2bec2961a885e856f7866d4f6vboxsync PGM_PAGE_SET_TRACKING(pPhysPage, 0);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
d200be7337d4aad2bec2961a885e856f7866d4f6vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_PROFILE_STOP(&pPool->StatTrackFlushGCPhysPTs, f);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Flushes all shadow page table mappings of the given guest page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * This is typically called when the host page backing the guest one has been
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * replaced or when the page protection was changed due to a guest access
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * caught by the monitoring.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @returns VBox status code.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @retval VINF_SUCCESS if all references has been successfully cleared.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @retval VINF_PGM_SYNC_CR3 if we're better off with a CR3 sync and a page
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * pool cleaning. FF and sync flags are set.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pVM The VM handle.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param GCPhysPage GC physical address of the page in question
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPhysPage The guest page in question.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param fFlushPTEs Flush PTEs or allow them to be updated (e.g. in case of an RW bit change)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pfFlushTLBs This is set to @a true if the shadow TLBs should be
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * flushed, it is NOT touched if this isn't necessary.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * The caller MUST initialized this to @a false.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncint pgmPoolTrackUpdateGCPhys(PVM pVM, RTGCPHYS GCPhysPage, PPGMPAGE pPhysPage, bool fFlushPTEs, bool *pfFlushTLBs)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PVMCPU pVCpu = VMMGetCpu(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmLock(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync int rc = VINF_SUCCESS;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#ifdef PGM_WITH_LARGE_PAGES
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* Is this page part of a large page? */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (PGM_PAGE_GET_PDE_TYPE(pPhysPage) == PGM_PAGE_PDE_TYPE_PDE)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMPAGE pPhysBase;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync RTGCPHYS GCPhysBase = GCPhysPage & X86_PDE2M_PAE_PG_MASK;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync GCPhysPage &= X86_PDE_PAE_PG_MASK;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* Fetch the large page base. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (GCPhysBase != GCPhysPage)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPhysBase = pgmPhysGetPage(&pVM->pgm.s, GCPhysBase);
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync AssertFatal(pPhysBase);
c049162517778158b3507c0389358a7342622b99vboxsync }
c049162517778158b3507c0389358a7342622b99vboxsync else
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPhysBase = pPhysPage;
c049162517778158b3507c0389358a7342622b99vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log(("pgmPoolTrackUpdateGCPhys: update large page PDE for %RGp (%RGp)\n", GCPhysBase, GCPhysPage));
c049162517778158b3507c0389358a7342622b99vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (PGM_PAGE_GET_PDE_TYPE(pPhysBase) == PGM_PAGE_PDE_TYPE_PDE)
c049162517778158b3507c0389358a7342622b99vboxsync {
c049162517778158b3507c0389358a7342622b99vboxsync /* Mark the large page as disabled as we need to break it up to change a single page in the 2 MB range. */
c049162517778158b3507c0389358a7342622b99vboxsync PGM_PAGE_SET_PDE_TYPE(pPhysBase, PGM_PAGE_PDE_TYPE_PDE_DISABLED);
c049162517778158b3507c0389358a7342622b99vboxsync
c049162517778158b3507c0389358a7342622b99vboxsync /* Update the base as that *only* that one has a reference and there's only one PDE to clear. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync rc = pgmPoolTrackUpdateGCPhys(pVM, GCPhysBase, pPhysBase, fFlushPTEs, pfFlushTLBs);
c6ade8a5a12fad69394e7223b7ea170bd729f0f4vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *pfFlushTLBs = true;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmUnlock(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return rc;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#else
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync NOREF(GCPhysPage);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#endif /* PGM_WITH_LARGE_PAGES */
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync const uint16_t u16 = PGM_PAGE_GET_TRACKING(pPhysPage);
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync if (u16)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * The zero page is currently screwing up the tracking and we'll
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync * have to flush the whole shebang. Unless VBOX_WITH_NEW_LAZY_PAGE_ALLOC
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * is defined, zero pages won't normally be mapped. Some kind of solution
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync * will be needed for this problem of course, but it will have to wait...
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if ( PGM_PAGE_IS_ZERO(pPhysPage)
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync || PGM_PAGE_IS_BALLOONED(pPhysPage))
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync rc = VINF_PGM_GCPHYS_ALIASED;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync else
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync# if defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0) || defined(IN_RC) /** @todo we can drop this now. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* Start a subset here because pgmPoolTrackFlushGCPhysPTsSlow and
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolTrackFlushGCPhysPTs will/may kill the pool otherwise. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync uint32_t iPrevSubset = PGMRZDynMapPushAutoSubset(pVCpu);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync# endif
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (PGMPOOL_TD_GET_CREFS(u16) != PGMPOOL_TD_CREFS_PHYSEXT)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(PGMPOOL_TD_GET_CREFS(u16) == 1);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolTrackFlushGCPhysPT(pVM,
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPhysPage,
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync fFlushPTEs,
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PGMPOOL_TD_GET_IDX(u16));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync else if (u16 != PGMPOOL_TD_MAKE(PGMPOOL_TD_CREFS_PHYSEXT, PGMPOOL_TD_IDX_OVERFLOWED))
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolTrackFlushGCPhysPTs(pVM, pPhysPage, fFlushPTEs, PGMPOOL_TD_GET_IDX(u16));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync else
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync rc = pgmPoolTrackFlushGCPhysPTsSlow(pVM, pPhysPage);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *pfFlushTLBs = true;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync# if defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0) || defined(IN_RC)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PGMRZDynMapPopAutoSubset(pVCpu, iPrevSubset);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync# endif
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (rc == VINF_PGM_GCPHYS_ALIASED)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pVCpu->pgm.s.fSyncFlags |= PGM_SYNC_CLEAR_PGM_POOL;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync VMCPU_FF_SET(pVCpu, VMCPU_FF_PGM_SYNC_CR3);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync rc = VINF_PGM_SYNC_CR3;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmUnlock(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return rc;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Scans all shadow page tables for mappings of a physical page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * This may be slow, but it's most likely more efficient than cleaning
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * out the entire page pool / cache.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @returns VBox status code.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @retval VINF_SUCCESS if all references has been successfully cleared.
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync * @retval VINF_PGM_GCPHYS_ALIASED if we're better off with a CR3 sync and
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * a page pool cleaning.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pVM The VM handle.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPhysPage The guest page in question.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncint pgmPoolTrackFlushGCPhysPTsSlow(PVM pVM, PPGMPAGE pPhysPage)
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync{
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync PPGMPOOL pPool = pVM->pgm.s.CTX_SUFF(pPool);
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync STAM_PROFILE_START(&pPool->StatTrackFlushGCPhysPTsSlow, s);
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync LogFlow(("pgmPoolTrackFlushGCPhysPTsSlow: cUsedPages=%d cPresent=%d pPhysPage=%R[pgmpage]\n",
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->cUsedPages, pPool->cPresent, pPhysPage));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync /*
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync * There is a limit to what makes sense.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if ( pPool->cPresent > 1024
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync && pVM->cCpus == 1)
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync {
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync LogFlow(("pgmPoolTrackFlushGCPhysPTsSlow: giving up... (cPresent=%d)\n", pPool->cPresent));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_PROFILE_STOP(&pPool->StatTrackFlushGCPhysPTsSlow, s);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return VINF_PGM_GCPHYS_ALIASED;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
2ddffe5c4ec41abd5bb836588c9a1b0788b9be5dvboxsync * Iterate all the pages until we've encountered all that in use.
2ddffe5c4ec41abd5bb836588c9a1b0788b9be5dvboxsync * This is simple but not quite optimal solution.
2ddffe5c4ec41abd5bb836588c9a1b0788b9be5dvboxsync */
2ddffe5c4ec41abd5bb836588c9a1b0788b9be5dvboxsync const uint64_t u64 = PGM_PAGE_GET_HCPHYS(pPhysPage) | X86_PTE_P; /** @todo drop X86_PTE_P here as we always test if present separately, anyway. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync const uint32_t u32 = u64; /** @todo move into the 32BIT_PT_xx case */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync unsigned cLeft = pPool->cUsedPages;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync unsigned iPage = pPool->cCurPages;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync while (--iPage >= PGMPOOL_IDX_FIRST)
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync {
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync PPGMPOOLPAGE pPage = &pPool->aPages[iPage];
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync if ( pPage->GCPhys != NIL_RTGCPHYS
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync && pPage->cPresent)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync switch (pPage->enmKind)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * We only care about shadow page tables.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_PT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_4MB:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_32BIT_PT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync unsigned cPresent = pPage->cPresent;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PX86PT pPT = (PX86PT)PGMPOOL_PAGE_2_PTR(pVM, pPage);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pPT->a); i++)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pPT->a[i].n.u1Present)
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if ((pPT->a[i].u & (X86_PTE_PG_MASK | X86_PTE_P)) == u32)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync //Log4(("pgmPoolTrackFlushGCPhysPTsSlow: idx=%d i=%d pte=%RX32\n", iPage, i, pPT->a[i]));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPT->a[i].u = 0;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* Update the counter as we're removing references. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(pPage->cPresent);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(pPool->cPresent);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->cPresent--;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->cPresent--;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (!--cPresent)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PGM_DYNMAP_UNUSED_HINT_VM(pVM, pPT);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_PT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_4MB:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_PT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_2MB:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync unsigned cPresent = pPage->cPresent;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMSHWPTPAE pPT = (PPGMSHWPTPAE)PGMPOOL_PAGE_2_PTR(pVM, pPage);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pPT->a); i++)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (PGMSHWPTEPAE_IS_P(pPT->a[i]))
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync if ((PGMSHWPTEPAE_GET_U(pPT->a[i]) & (X86_PTE_PAE_PG_MASK | X86_PTE_P)) == u64)
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync //Log4(("pgmPoolTrackFlushGCPhysPTsSlow: idx=%d i=%d pte=%RX64\n", iPage, i, pPT->a[i]));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PGMSHWPTEPAE_SET(pPT->a[i], 0); /// @todo why not atomic?
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* Update the counter as we're removing references. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(pPage->cPresent);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(pPool->cPresent);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->cPresent--;
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync pPool->cPresent--;
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (!--cPresent)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PGM_DYNMAP_UNUSED_HINT_VM(pVM, pPT);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#ifndef IN_RC
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_EPT_PT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync unsigned cPresent = pPage->cPresent;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PEPTPT pPT = (PEPTPT)PGMPOOL_PAGE_2_PTR(pVM, pPage);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pPT->a); i++)
c6ade8a5a12fad69394e7223b7ea170bd729f0f4vboxsync if (pPT->a[i].n.u1Present)
e94ff1af89bf631c68367d4e291ddbb491b5e5c0vboxsync {
e94ff1af89bf631c68367d4e291ddbb491b5e5c0vboxsync if ((pPT->a[i].u & (EPT_PTE_PG_MASK | X86_PTE_P)) == u64)
e94ff1af89bf631c68367d4e291ddbb491b5e5c0vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync //Log4(("pgmPoolTrackFlushGCPhysPTsSlow: idx=%d i=%d pte=%RX64\n", iPage, i, pPT->a[i]));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPT->a[i].u = 0;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* Update the counter as we're removing references. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(pPage->cPresent);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(pPool->cPresent);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->cPresent--;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->cPresent--;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (!--cPresent)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync PGM_DYNMAP_UNUSED_HINT_VM(pVM, pPT);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync }
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync#endif
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync }
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync if (!--cLeft)
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync break;
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync }
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync }
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync PGM_PAGE_SET_TRACKING(pPhysPage, 0);
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync STAM_PROFILE_STOP(&pPool->StatTrackFlushGCPhysPTsSlow, s);
66536cda1b721606f6f5aa25ee8454737c5031cavboxsync
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync /*
66536cda1b721606f6f5aa25ee8454737c5031cavboxsync * There is a limit to what makes sense. The above search is very expensive, so force a pgm pool flush.
66536cda1b721606f6f5aa25ee8454737c5031cavboxsync */
66536cda1b721606f6f5aa25ee8454737c5031cavboxsync if (pPool->cPresent > 1024)
66536cda1b721606f6f5aa25ee8454737c5031cavboxsync {
66536cda1b721606f6f5aa25ee8454737c5031cavboxsync LogFlow(("pgmPoolTrackFlushGCPhysPTsSlow: giving up... (cPresent=%d)\n", pPool->cPresent));
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync return VINF_PGM_GCPHYS_ALIASED;
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync }
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync return VINF_SUCCESS;
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync}
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync/**
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync * Clears the user entry in a user table.
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync *
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync * This is used to remove all references to a page when flushing it.
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync */
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsyncstatic void pgmPoolTrackClearPageUser(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PCPGMPOOLUSER pUser)
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync{
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync Assert(pUser->iUser != NIL_PGMPOOL_IDX);
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync Assert(pUser->iUser < pPool->cCurPages);
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync uint32_t iUserTable = pUser->iUserTable;
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync /*
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync * Map the user page.
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync */
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync PPGMPOOLPAGE pUserPage = &pPool->aPages[pUser->iUser];
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync union
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync {
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync uint64_t *pau64;
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync uint32_t *pau32;
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync } u;
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync u.pau64 = (uint64_t *)PGMPOOL_PAGE_2_PTR(pPool->CTX_SUFF(pVM), pUserPage);
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync LogFlow(("pgmPoolTrackClearPageUser: clear %x in %s (%RGp) (flushing %s)\n", iUserTable, pgmPoolPoolKindToStr(pUserPage->enmKind), pUserPage->Core.Key, pgmPoolPoolKindToStr(pPage->enmKind)));
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync /* Safety precaution in case we change the paging for other modes too in the future. */
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync Assert(!pgmPoolIsPageLocked(&pPool->CTX_SUFF(pVM)->pgm.s, pPage));
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync#ifdef VBOX_STRICT
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Some sanity checks.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync switch (pUserPage->enmKind)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_32BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_32BIT_PD_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(iUserTable < X86_PG_ENTRIES);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PDPT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PDPT_FOR_32BIT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PDPT_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(iUserTable < 4);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(!(u.pau64[iUserTable] & PGM_PLXFLAGS_PERMANENT));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD0_FOR_32BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD1_FOR_32BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD2_FOR_32BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD3_FOR_32BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD_FOR_PAE_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(iUserTable < X86_PG_PAE_ENTRIES);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PD_FOR_64BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(iUserTable < X86_PG_PAE_ENTRIES);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(!(u.pau64[iUserTable] & PGM_PDFLAGS_MAPPING));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_64BIT_PDPT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(iUserTable < X86_PG_PAE_ENTRIES);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(!(u.pau64[iUserTable] & PGM_PLXFLAGS_PERMANENT));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PML4:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(!(u.pau64[iUserTable] & PGM_PLXFLAGS_PERMANENT));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* GCPhys >> PAGE_SHIFT is the index here */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PD_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(iUserTable < X86_PG_PAE_ENTRIES);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_EPT_PDPT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_EPT_PD_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(iUserTable < X86_PG_PAE_ENTRIES);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_ROOT_NESTED:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(iUserTable < X86_PG_PAE_ENTRIES);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync default:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertMsgFailed(("enmKind=%d\n", pUserPage->enmKind));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#endif /* VBOX_STRICT */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Clear the entry in the user page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync switch (pUserPage->enmKind)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* 32-bit entries */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_32BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_32BIT_PD_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync ASMAtomicWriteU32(&u.pau32[iUserTable], 0);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* 64-bit entries */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD0_FOR_32BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD1_FOR_32BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD2_FOR_32BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD3_FOR_32BIT_PD:
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync case PGMPOOLKIND_PAE_PD_FOR_PAE_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#ifdef IN_RC
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * In 32 bits PAE mode we *must* invalidate the TLB when changing a
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * PDPT entry; the CPU fetches them only during cr3 load, so any
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * non-present PDPT will continue to cause page faults.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync ASMReloadCR3();
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* no break */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#endif
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PDPT_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PD_FOR_64BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_64BIT_PDPT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PML4:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PD_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PDPT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PDPT_FOR_32BIT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_ROOT_NESTED:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_EPT_PDPT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_EPT_PD_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync ASMAtomicWriteU64(&u.pau64[iUserTable], 0);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync default:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertFatalMsgFailed(("enmKind=%d iUser=%d iUserTable=%#x\n", pUserPage->enmKind, pUser->iUser, pUser->iUserTable));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PGM_DYNMAP_UNUSED_HINT_VM(pPool->CTX_SUFF(pVM), u.pau64);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
0ffa3979e9b800f5931dd30c51ec3c0aadc3a1f1vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Clears all users of a page.
0ffa3979e9b800f5931dd30c51ec3c0aadc3a1f1vboxsync */
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsyncstatic void pgmPoolTrackClearPageUsers(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Free all the user records.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync LogFlow(("pgmPoolTrackClearPageUsers %RGp\n", pPage->GCPhys));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMPOOLUSER paUsers = pPool->CTX_SUFF(paUsers);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync uint16_t i = pPage->iUserHead;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync while (i != NIL_PGMPOOL_USER_INDEX)
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync {
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync /* Clear enter in user table. */
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync pgmPoolTrackClearPageUser(pPool, pPage, &paUsers[i]);
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync /* Free it. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync const uint16_t iNext = paUsers[i].iNext;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync paUsers[i].iUser = NIL_PGMPOOL_IDX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync paUsers[i].iNext = pPool->iUserFreeHead;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->iUserFreeHead = i;
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* Next. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync i = iNext;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->iUserHead = NIL_PGMPOOL_USER_INDEX;
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Allocates a new physical cross reference extent.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @returns Pointer to the allocated extent on success. NULL if we're out of them.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pVM The VM handle.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param piPhysExt Where to store the phys ext index.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncPPGMPOOLPHYSEXT pgmPoolTrackPhysExtAlloc(PVM pVM, uint16_t *piPhysExt)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(PGMIsLockOwner(pVM));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMPOOL pPool = pVM->pgm.s.CTX_SUFF(pPool);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync uint16_t iPhysExt = pPool->iPhysExtFreeHead;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (iPhysExt == NIL_PGMPOOL_PHYSEXT_INDEX)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_COUNTER_INC(&pPool->StamTrackPhysExtAllocFailures);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return NULL;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMPOOLPHYSEXT pPhysExt = &pPool->CTX_SUFF(paPhysExts)[iPhysExt];
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->iPhysExtFreeHead = pPhysExt->iNext;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPhysExt->iNext = NIL_PGMPOOL_PHYSEXT_INDEX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *piPhysExt = iPhysExt;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return pPhysExt;
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Frees a physical cross reference extent.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pVM The VM handle.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param iPhysExt The extent to free.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncvoid pgmPoolTrackPhysExtFree(PVM pVM, uint16_t iPhysExt)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(PGMIsLockOwner(pVM));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMPOOL pPool = pVM->pgm.s.CTX_SUFF(pPool);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(iPhysExt < pPool->cMaxPhysExts);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMPOOLPHYSEXT pPhysExt = &pPool->CTX_SUFF(paPhysExts)[iPhysExt];
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pPhysExt->aidx); i++)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync pPhysExt->aidx[i] = NIL_PGMPOOL_IDX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPhysExt->apte[i] = NIL_PGMPOOL_PHYSEXT_IDX_PTE;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPhysExt->iNext = pPool->iPhysExtFreeHead;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->iPhysExtFreeHead = iPhysExt;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Frees a physical cross reference extent.
0ffa3979e9b800f5931dd30c51ec3c0aadc3a1f1vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pVM The VM handle.
0ffa3979e9b800f5931dd30c51ec3c0aadc3a1f1vboxsync * @param iPhysExt The extent to free.
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncvoid pgmPoolTrackPhysExtFreeList(PVM pVM, uint16_t iPhysExt)
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(PGMIsLockOwner(pVM));
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync PPGMPOOL pPool = pVM->pgm.s.CTX_SUFF(pPool);
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync const uint16_t iPhysExtStart = iPhysExt;
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync PPGMPOOLPHYSEXT pPhysExt;
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync do
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync {
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync Assert(iPhysExt < pPool->cMaxPhysExts);
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync pPhysExt = &pPool->CTX_SUFF(paPhysExts)[iPhysExt];
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pPhysExt->aidx); i++)
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPhysExt->aidx[i] = NIL_PGMPOOL_IDX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPhysExt->apte[i] = NIL_PGMPOOL_PHYSEXT_IDX_PTE;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* next */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync iPhysExt = pPhysExt->iNext;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync } while (iPhysExt != NIL_PGMPOOL_PHYSEXT_INDEX);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPhysExt->iNext = pPool->iPhysExtFreeHead;
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync pPool->iPhysExtFreeHead = iPhysExtStart;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync * Insert a reference into a list of physical cross reference extents.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync * @returns The new tracking data for PGMPAGE.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pVM The VM handle.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param iPhysExt The physical extent index of the list head.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param iShwPT The shadow page table index.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param iPte Page table entry
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncstatic uint16_t pgmPoolTrackPhysExtInsert(PVM pVM, uint16_t iPhysExt, uint16_t iShwPT, uint16_t iPte)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(PGMIsLockOwner(pVM));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMPOOL pPool = pVM->pgm.s.CTX_SUFF(pPool);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMPOOLPHYSEXT paPhysExts = pPool->CTX_SUFF(paPhysExts);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Special common cases.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (paPhysExts[iPhysExt].aidx[1] == NIL_PGMPOOL_IDX)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync paPhysExts[iPhysExt].aidx[1] = iShwPT;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync paPhysExts[iPhysExt].apte[1] = iPte;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_COUNTER_INC(&pVM->pgm.s.CTX_SUFF(pStats)->StatTrackAliasedMany);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync LogFlow(("pgmPoolTrackPhysExtInsert: %d:{,%d pte %d,}\n", iPhysExt, iShwPT, iPte));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return PGMPOOL_TD_MAKE(PGMPOOL_TD_CREFS_PHYSEXT, iPhysExt);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (paPhysExts[iPhysExt].aidx[2] == NIL_PGMPOOL_IDX)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync paPhysExts[iPhysExt].aidx[2] = iShwPT;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync paPhysExts[iPhysExt].apte[2] = iPte;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_COUNTER_INC(&pVM->pgm.s.CTX_SUFF(pStats)->StatTrackAliasedMany);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync LogFlow(("pgmPoolTrackPhysExtInsert: %d:{,,%d pte %d}\n", iPhysExt, iShwPT, iPte));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return PGMPOOL_TD_MAKE(PGMPOOL_TD_CREFS_PHYSEXT, iPhysExt);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertCompile(RT_ELEMENTS(paPhysExts[iPhysExt].aidx) == 3);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * General treatment.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync const uint16_t iPhysExtStart = iPhysExt;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync unsigned cMax = 15;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync for (;;)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(iPhysExt < pPool->cMaxPhysExts);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync for (unsigned i = 0; i < RT_ELEMENTS(paPhysExts[iPhysExt].aidx); i++)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (paPhysExts[iPhysExt].aidx[i] == NIL_PGMPOOL_IDX)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync paPhysExts[iPhysExt].aidx[i] = iShwPT;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync paPhysExts[iPhysExt].apte[i] = iPte;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_COUNTER_INC(&pVM->pgm.s.CTX_SUFF(pStats)->StatTrackAliasedMany);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync LogFlow(("pgmPoolTrackPhysExtInsert: %d:{%d pte %d} i=%d cMax=%d\n", iPhysExt, iShwPT, iPte, i, cMax));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return PGMPOOL_TD_MAKE(PGMPOOL_TD_CREFS_PHYSEXT, iPhysExtStart);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (!--cMax)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_COUNTER_INC(&pVM->pgm.s.CTX_SUFF(pStats)->StatTrackOverflows);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolTrackPhysExtFreeList(pVM, iPhysExtStart);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync LogFlow(("pgmPoolTrackPhysExtInsert: overflow (1) iShwPT=%d\n", iShwPT));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return PGMPOOL_TD_MAKE(PGMPOOL_TD_CREFS_PHYSEXT, PGMPOOL_TD_IDX_OVERFLOWED);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* advance */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync iPhysExt = paPhysExts[iPhysExt].iNext;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (iPhysExt == NIL_PGMPOOL_PHYSEXT_INDEX)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Add another extent to the list.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMPOOLPHYSEXT pNew = pgmPoolTrackPhysExtAlloc(pVM, &iPhysExt);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (!pNew)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_COUNTER_INC(&pVM->pgm.s.CTX_SUFF(pStats)->StatTrackNoExtentsLeft);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolTrackPhysExtFreeList(pVM, iPhysExtStart);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync LogFlow(("pgmPoolTrackPhysExtInsert: pgmPoolTrackPhysExtAlloc failed iShwPT=%d\n", iShwPT));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return PGMPOOL_TD_MAKE(PGMPOOL_TD_CREFS_PHYSEXT, PGMPOOL_TD_IDX_OVERFLOWED);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pNew->iNext = iPhysExtStart;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pNew->aidx[0] = iShwPT;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pNew->apte[0] = iPte;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync LogFlow(("pgmPoolTrackPhysExtInsert: added new extent %d:{%d pte %d}->%d\n", iPhysExt, iShwPT, iPte, iPhysExtStart));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return PGMPOOL_TD_MAKE(PGMPOOL_TD_CREFS_PHYSEXT, iPhysExt);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Add a reference to guest physical page where extents are in use.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @returns The new tracking data for PGMPAGE.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pVM The VM handle.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPhysPage Pointer to the aPages entry in the ram range.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param u16 The ram range flags (top 16-bits).
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param iShwPT The shadow page table index.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param iPte Page table entry
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncuint16_t pgmPoolTrackPhysExtAddref(PVM pVM, PPGMPAGE pPhysPage, uint16_t u16, uint16_t iShwPT, uint16_t iPte)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmLock(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (PGMPOOL_TD_GET_CREFS(u16) != PGMPOOL_TD_CREFS_PHYSEXT)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Convert to extent list.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(PGMPOOL_TD_GET_CREFS(u16) == 1);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync uint16_t iPhysExt;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMPOOLPHYSEXT pPhysExt = pgmPoolTrackPhysExtAlloc(pVM, &iPhysExt);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pPhysExt)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync LogFlow(("pgmPoolTrackPhysExtAddref: new extent: %d:{%d, %d}\n", iPhysExt, PGMPOOL_TD_GET_IDX(u16), iShwPT));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_COUNTER_INC(&pVM->pgm.s.CTX_SUFF(pStats)->StatTrackAliased);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPhysExt->aidx[0] = PGMPOOL_TD_GET_IDX(u16);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPhysExt->apte[0] = PGM_PAGE_GET_PTE_INDEX(pPhysPage);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPhysExt->aidx[1] = iShwPT;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPhysExt->apte[1] = iPte;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync u16 = PGMPOOL_TD_MAKE(PGMPOOL_TD_CREFS_PHYSEXT, iPhysExt);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync else
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync u16 = PGMPOOL_TD_MAKE(PGMPOOL_TD_CREFS_PHYSEXT, PGMPOOL_TD_IDX_OVERFLOWED);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync else if (u16 != PGMPOOL_TD_MAKE(PGMPOOL_TD_CREFS_PHYSEXT, PGMPOOL_TD_IDX_OVERFLOWED))
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Insert into the extent list.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync u16 = pgmPoolTrackPhysExtInsert(pVM, PGMPOOL_TD_GET_IDX(u16), iShwPT, iPte);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync else
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_COUNTER_INC(&pVM->pgm.s.CTX_SUFF(pStats)->StatTrackAliasedLots);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmUnlock(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return u16;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Clear references to guest physical memory.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPool The pool.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPage The page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPhysPage Pointer to the aPages entry in the ram range.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param iPte Shadow PTE index
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncvoid pgmPoolTrackPhysExtDerefGCPhys(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PPGMPAGE pPhysPage, uint16_t iPte)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync const unsigned cRefs = PGM_PAGE_GET_TD_CREFS(pPhysPage);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertFatalMsg(cRefs == PGMPOOL_TD_CREFS_PHYSEXT, ("cRefs=%d pPhysPage=%R[pgmpage] pPage=%p:{.idx=%d}\n", cRefs, pPhysPage, pPage, pPage->idx));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync uint16_t iPhysExt = PGM_PAGE_GET_TD_IDX(pPhysPage);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (iPhysExt != PGMPOOL_TD_IDX_OVERFLOWED)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PVM pVM = pPool->CTX_SUFF(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmLock(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync uint16_t iPhysExtPrev = NIL_PGMPOOL_PHYSEXT_INDEX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMPOOLPHYSEXT paPhysExts = pPool->CTX_SUFF(paPhysExts);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync do
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(iPhysExt < pPool->cMaxPhysExts);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Look for the shadow page and check if it's all freed.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync for (unsigned i = 0; i < RT_ELEMENTS(paPhysExts[iPhysExt].aidx); i++)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if ( paPhysExts[iPhysExt].aidx[i] == pPage->idx
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync && paPhysExts[iPhysExt].apte[i] == iPte)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync paPhysExts[iPhysExt].aidx[i] = NIL_PGMPOOL_IDX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync paPhysExts[iPhysExt].apte[i] = NIL_PGMPOOL_PHYSEXT_IDX_PTE;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync for (i = 0; i < RT_ELEMENTS(paPhysExts[iPhysExt].aidx); i++)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (paPhysExts[iPhysExt].aidx[i] != NIL_PGMPOOL_IDX)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log2(("pgmPoolTrackPhysExtDerefGCPhys: pPhysPage=%R[pgmpage] idx=%d\n", pPhysPage, pPage->idx));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmUnlock(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* we can free the node. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync const uint16_t iPhysExtNext = paPhysExts[iPhysExt].iNext;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if ( iPhysExtPrev == NIL_PGMPOOL_PHYSEXT_INDEX
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync && iPhysExtNext == NIL_PGMPOOL_PHYSEXT_INDEX)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* lonely node */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolTrackPhysExtFree(pVM, iPhysExt);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log2(("pgmPoolTrackPhysExtDerefGCPhys: pPhysPage=%R[pgmpage] idx=%d lonely\n", pPhysPage, pPage->idx));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PGM_PAGE_SET_TRACKING(pPhysPage, 0);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync else if (iPhysExtPrev == NIL_PGMPOOL_PHYSEXT_INDEX)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* head */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log2(("pgmPoolTrackPhysExtDerefGCPhys: pPhysPage=%R[pgmpage] idx=%d head\n", pPhysPage, pPage->idx));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PGM_PAGE_SET_TRACKING(pPhysPage, PGMPOOL_TD_MAKE(PGMPOOL_TD_CREFS_PHYSEXT, iPhysExtNext));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolTrackPhysExtFree(pVM, iPhysExt);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync else
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* in list */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log2(("pgmPoolTrackPhysExtDerefGCPhys: pPhysPage=%R[pgmpage] idx=%d in list\n", pPhysPage, pPage->idx));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync paPhysExts[iPhysExtPrev].iNext = iPhysExtNext;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolTrackPhysExtFree(pVM, iPhysExt);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync iPhysExt = iPhysExtNext;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmUnlock(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* next */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync iPhysExtPrev = iPhysExt;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync iPhysExt = paPhysExts[iPhysExt].iNext;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync } while (iPhysExt != NIL_PGMPOOL_PHYSEXT_INDEX);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmUnlock(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertFatalMsgFailed(("not-found! cRefs=%d pPhysPage=%R[pgmpage] pPage=%p:{.idx=%d}\n", cRefs, pPhysPage, pPage, pPage->idx));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync else /* nothing to do */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log2(("pgmPoolTrackPhysExtDerefGCPhys: pPhysPage=%R[pgmpage]\n", pPhysPage));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Clear references to guest physical memory.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * This is the same as pgmPoolTracDerefGCPhys except that the guest physical address
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * is assumed to be correct, so the linear search can be skipped and we can assert
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * at an earlier point.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPool The pool.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPage The page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param HCPhys The host physical address corresponding to the guest page.
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync * @param GCPhys The guest physical address corresponding to HCPhys.
e94ff1af89bf631c68367d4e291ddbb491b5e5c0vboxsync * @param iPte Shadow PTE index
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncstatic void pgmPoolTracDerefGCPhys(PPGMPOOL pPool, PPGMPOOLPAGE pPage, RTHCPHYS HCPhys, RTGCPHYS GCPhys, uint16_t iPte)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Walk range list.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMRAMRANGE pRam = pPool->CTX_SUFF(pVM)->pgm.s.CTX_SUFF(pRamRanges);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync while (pRam)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync RTGCPHYS off = GCPhys - pRam->GCPhys;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (off < pRam->cb)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* does it match? */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync const unsigned iPage = off >> PAGE_SHIFT;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(PGM_PAGE_GET_HCPHYS(&pRam->aPages[iPage]));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#ifdef LOG_ENABLED
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync RTHCPHYS HCPhysPage = PGM_PAGE_GET_HCPHYS(&pRam->aPages[iPage]);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log2(("pgmPoolTracDerefGCPhys %RHp vs %RHp\n", HCPhysPage, HCPhys));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#endif
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (PGM_PAGE_GET_HCPHYS(&pRam->aPages[iPage]) == HCPhys)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(pPage->cPresent);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(pPool->cPresent);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->cPresent--;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->cPresent--;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmTrackDerefGCPhys(pPool, pPage, &pRam->aPages[iPage], iPte);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertFatalMsgFailed(("HCPhys=%RHp GCPhys=%RGp; found page index %x HCPhys=%RHp\n", HCPhys, GCPhys, iPage, PGM_PAGE_GET_HCPHYS(&pRam->aPages[iPage])));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pRam = pRam->CTX_SUFF(pNext);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertFatalMsgFailed(("HCPhys=%RHp GCPhys=%RGp\n", HCPhys, GCPhys));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Clear references to guest physical memory.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPool The pool.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPage The page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param HCPhys The host physical address corresponding to the guest page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param GCPhysHint The guest physical address which may corresponding to HCPhys.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param iPte Shadow pte index
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncvoid pgmPoolTracDerefGCPhysHint(PPGMPOOL pPool, PPGMPOOLPAGE pPage, RTHCPHYS HCPhys, RTGCPHYS GCPhysHint, uint16_t iPte)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync RTHCPHYS HCPhysExpected = 0xDEADBEEFDEADBEEFULL;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync Log4(("pgmPoolTracDerefGCPhysHint %RHp %RGp\n", HCPhys, GCPhysHint));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Walk range list.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMRAMRANGE pRam = pPool->CTX_SUFF(pVM)->pgm.s.CTX_SUFF(pRamRanges);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync while (pRam)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync RTGCPHYS off = GCPhysHint - pRam->GCPhys;
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync if (off < pRam->cb)
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync {
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync /* does it match? */
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync const unsigned iPage = off >> PAGE_SHIFT;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(PGM_PAGE_GET_HCPHYS(&pRam->aPages[iPage]));
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync if (PGM_PAGE_GET_HCPHYS(&pRam->aPages[iPage]) == HCPhys)
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync {
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync Assert(pPage->cPresent);
7c19e11502220292d5270519296442234c2493cdvboxsync Assert(pPool->cPresent);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->cPresent--;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->cPresent--;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmTrackDerefGCPhys(pPool, pPage, &pRam->aPages[iPage], iPte);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync HCPhysExpected = PGM_PAGE_GET_HCPHYS(&pRam->aPages[iPage]);
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pRam = pRam->CTX_SUFF(pNext);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync /*
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync * Damn, the hint didn't work. We'll have to do an expensive linear search.
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync */
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync STAM_COUNTER_INC(&pPool->StatTrackLinearRamSearches);
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync pRam = pPool->CTX_SUFF(pVM)->pgm.s.CTX_SUFF(pRamRanges);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync while (pRam)
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync {
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync unsigned iPage = pRam->cb >> PAGE_SHIFT;
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync while (iPage-- > 0)
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync {
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync if (PGM_PAGE_GET_HCPHYS(&pRam->aPages[iPage]) == HCPhys)
9b37cfa6efe394762d21f3710df8fa46b2758880vboxsync {
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync Log4(("pgmPoolTracDerefGCPhysHint: Linear HCPhys=%RHp GCPhysHint=%RGp GCPhysReal=%RGp\n",
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync HCPhys, GCPhysHint, pRam->GCPhys + (iPage << PAGE_SHIFT)));
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync Assert(pPage->cPresent);
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync Assert(pPool->cPresent);
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync pPage->cPresent--;
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync pPool->cPresent--;
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync pgmTrackDerefGCPhys(pPool, pPage, &pRam->aPages[iPage], iPte);
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync return;
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync }
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync }
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync pRam = pRam->CTX_SUFF(pNext);
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync }
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync AssertFatalMsgFailed(("HCPhys=%RHp GCPhysHint=%RGp (Expected HCPhys with hint = %RHp)\n", HCPhys, GCPhysHint, HCPhysExpected));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync/**
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync * Clear references to guest physical memory in a 32-bit / 32-bit page table.
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync *
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync * @param pPool The pool.
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync * @param pPage The page.
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync * @param pShwPT The shadow page table (mapping of the page).
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync * @param pGstPT The guest page table.
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync */
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsyncDECLINLINE(void) pgmPoolTrackDerefPT32Bit32Bit(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PT pShwPT, PCX86PT pGstPT)
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync{
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pShwPT->a); i++)
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync {
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync Assert(!(pShwPT->a[i].u & RT_BIT_32(10)));
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync if (pShwPT->a[i].n.u1Present)
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync {
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync Log4(("pgmPoolTrackDerefPT32Bit32Bit: i=%d pte=%RX32 hint=%RX32\n",
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync i, pShwPT->a[i].u & X86_PTE_PG_MASK, pGstPT->a[i].u & X86_PTE_PG_MASK));
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync pgmPoolTracDerefGCPhysHint(pPool, pPage, pShwPT->a[i].u & X86_PTE_PG_MASK, pGstPT->a[i].u & X86_PTE_PG_MASK, i);
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync if (!pPage->cPresent)
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync break;
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync }
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync }
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync}
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync/**
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync * Clear references to guest physical memory in a PAE / 32-bit page table.
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync *
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync * @param pPool The pool.
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync * @param pPage The page.
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync * @param pShwPT The shadow page table (mapping of the page).
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync * @param pGstPT The guest page table (just a half one).
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync */
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsyncDECLINLINE(void) pgmPoolTrackDerefPTPae32Bit(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PPGMSHWPTPAE pShwPT, PCX86PT pGstPT)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pShwPT->a); i++)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert( (PGMSHWPTEPAE_GET_U(pShwPT->a[i]) & UINT64_C(0x7ff0000000000400)) == 0
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync || (PGMSHWPTEPAE_GET_U(pShwPT->a[i]) & UINT64_C(0x7ff0000000000400)) == UINT64_C(0x7ff0000000000000));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (PGMSHWPTEPAE_IS_P(pShwPT->a[i]))
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log4(("pgmPoolTrackDerefPTPae32Bit: i=%d pte=%RX64 hint=%RX32\n",
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync i, PGMSHWPTEPAE_GET_HCPHYS(pShwPT->a[i]), pGstPT->a[i].u & X86_PTE_PG_MASK));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolTracDerefGCPhysHint(pPool, pPage, PGMSHWPTEPAE_GET_HCPHYS(pShwPT->a[i]), pGstPT->a[i].u & X86_PTE_PG_MASK, i);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (!pPage->cPresent)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Clear references to guest physical memory in a PAE / PAE page table.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPool The pool.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPage The page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pShwPT The shadow page table (mapping of the page).
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pGstPT The guest page table.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncDECLINLINE(void) pgmPoolTrackDerefPTPaePae(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PPGMSHWPTPAE pShwPT, PCX86PTPAE pGstPT)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pShwPT->a); i++)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert( (PGMSHWPTEPAE_GET_U(pShwPT->a[i]) & UINT64_C(0x7ff0000000000400)) == 0
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync || (PGMSHWPTEPAE_GET_U(pShwPT->a[i]) & UINT64_C(0x7ff0000000000400)) == UINT64_C(0x7ff0000000000000));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (PGMSHWPTEPAE_IS_P(pShwPT->a[i]))
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log4(("pgmPoolTrackDerefPTPaePae: i=%d pte=%RX32 hint=%RX32\n",
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync i, PGMSHWPTEPAE_GET_HCPHYS(pShwPT->a[i]), pGstPT->a[i].u & X86_PTE_PAE_PG_MASK));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolTracDerefGCPhysHint(pPool, pPage, PGMSHWPTEPAE_GET_HCPHYS(pShwPT->a[i]), pGstPT->a[i].u & X86_PTE_PAE_PG_MASK, i);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (!pPage->cPresent)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Clear references to guest physical memory in a 32-bit / 4MB page table.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPool The pool.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPage The page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pShwPT The shadow page table (mapping of the page).
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsyncDECLINLINE(void) pgmPoolTrackDerefPT32Bit4MB(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PT pShwPT)
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync RTGCPHYS GCPhys = pPage->GCPhys + PAGE_SIZE * pPage->iFirstPresent;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pShwPT->a); i++, GCPhys += PAGE_SIZE)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(!(pShwPT->a[i].u & RT_BIT_32(10)));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pShwPT->a[i].n.u1Present)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log4(("pgmPoolTrackDerefPT32Bit4MB: i=%d pte=%RX32 GCPhys=%RGp\n",
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync i, pShwPT->a[i].u & X86_PTE_PG_MASK, GCPhys));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolTracDerefGCPhys(pPool, pPage, pShwPT->a[i].u & X86_PTE_PG_MASK, GCPhys, i);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (!pPage->cPresent)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Clear references to guest physical memory in a PAE / 2/4MB page table.
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPool The pool.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPage The page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pShwPT The shadow page table (mapping of the page).
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncDECLINLINE(void) pgmPoolTrackDerefPTPaeBig(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PPGMSHWPTPAE pShwPT)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync RTGCPHYS GCPhys = pPage->GCPhys + PAGE_SIZE * pPage->iFirstPresent;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pShwPT->a); i++, GCPhys += PAGE_SIZE)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert( (PGMSHWPTEPAE_GET_U(pShwPT->a[i]) & UINT64_C(0x7ff0000000000400)) == 0
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync || (PGMSHWPTEPAE_GET_U(pShwPT->a[i]) & UINT64_C(0x7ff0000000000400)) == UINT64_C(0x7ff0000000000000));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (PGMSHWPTEPAE_IS_P(pShwPT->a[i]))
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log4(("pgmPoolTrackDerefPTPaeBig: i=%d pte=%RX64 hint=%RGp\n",
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync i, PGMSHWPTEPAE_GET_HCPHYS(pShwPT->a[i]), GCPhys));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolTracDerefGCPhys(pPool, pPage, PGMSHWPTEPAE_GET_HCPHYS(pShwPT->a[i]), GCPhys, i);
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync if (!pPage->cPresent)
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync}
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync
7c19e11502220292d5270519296442234c2493cdvboxsync
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync/**
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync * Clear references to shadowed pages in an EPT page table.
e94ff1af89bf631c68367d4e291ddbb491b5e5c0vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPool The pool.
e94ff1af89bf631c68367d4e291ddbb491b5e5c0vboxsync * @param pPage The page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pShwPML4 The shadow page directory pointer table (mapping of the page).
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncDECLINLINE(void) pgmPoolTrackDerefPTEPT(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PEPTPT pShwPT)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync RTGCPHYS GCPhys = pPage->GCPhys + PAGE_SIZE * pPage->iFirstPresent;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync for (unsigned i = pPage->iFirstPresent; i < RT_ELEMENTS(pShwPT->a); i++, GCPhys += PAGE_SIZE)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert((pShwPT->a[i].u & UINT64_C(0xfff0000000000f80)) == 0);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pShwPT->a[i].n.u1Present)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log4(("pgmPoolTrackDerefPTEPT: i=%d pte=%RX64 GCPhys=%RX64\n",
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync i, pShwPT->a[i].u & EPT_PTE_PG_MASK, pPage->GCPhys));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolTracDerefGCPhys(pPool, pPage, pShwPT->a[i].u & EPT_PTE_PG_MASK, GCPhys, i);
e94ff1af89bf631c68367d4e291ddbb491b5e5c0vboxsync if (!pPage->cPresent)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Clear references to shadowed pages in a 32 bits page directory.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPool The pool.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPage The page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pShwPD The shadow page directory (mapping of the page).
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncDECLINLINE(void) pgmPoolTrackDerefPD(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PD pShwPD)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pShwPD->a); i++)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(!(pShwPD->a[i].u & RT_BIT_32(9)));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if ( pShwPD->a[i].n.u1Present
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync && !(pShwPD->a[i].u & PGM_PDFLAGS_MAPPING)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync )
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMPOOLPAGE pSubPage = (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, pShwPD->a[i].u & X86_PDE_PG_MASK);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pSubPage)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolTrackFreeUser(pPool, pSubPage, pPage->idx, i);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync else
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertFatalMsgFailed(("%x\n", pShwPD->a[i].u & X86_PDE_PG_MASK));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Clear references to shadowed pages in a PAE (legacy or 64 bits) page directory.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPool The pool.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPage The page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pShwPD The shadow page directory (mapping of the page).
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncDECLINLINE(void) pgmPoolTrackDerefPDPae(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PDPAE pShwPD)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pShwPD->a); i++)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert((pShwPD->a[i].u & (X86_PDE_PAE_MBZ_MASK_NX | UINT64_C(0x7ff0000000000200))) == 0);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if ( pShwPD->a[i].n.u1Present
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync && !(pShwPD->a[i].u & PGM_PDFLAGS_MAPPING))
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#ifdef PGM_WITH_LARGE_PAGES
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pShwPD->a[i].b.u1Size)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log4(("pgmPoolTrackDerefPDPae: i=%d pde=%RX64 GCPhys=%RX64\n",
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync i, pShwPD->a[i].u & X86_PDE2M_PAE_PG_MASK, pPage->GCPhys));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolTracDerefGCPhys(pPool, pPage, pShwPD->a[i].u & X86_PDE2M_PAE_PG_MASK, pPage->GCPhys + i * 2 * _1M /* pPage->GCPhys = base address of the memory described by the PD */, i);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync else
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#endif
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMPOOLPAGE pSubPage = (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, pShwPD->a[i].u & X86_PDE_PAE_PG_MASK);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pSubPage)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolTrackFreeUser(pPool, pSubPage, pPage->idx, i);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync else
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertFatalMsgFailed(("%RX64\n", pShwPD->a[i].u & X86_PDE_PAE_PG_MASK));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /** @todo 64-bit guests: have to ensure that we're not exhausting the dynamic mappings! */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Clear references to shadowed pages in a PAE page directory pointer table.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPool The pool.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPage The page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pShwPDPT The shadow page directory pointer table (mapping of the page).
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncDECLINLINE(void) pgmPoolTrackDerefPDPTPae(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PDPT pShwPDPT)
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync{
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync for (unsigned i = 0; i < X86_PG_PAE_PDPE_ENTRIES; i++)
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync {
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync Assert((pShwPDPT->a[i].u & (X86_PDPE_PAE_MBZ_MASK | UINT64_C(0x7ff0000000000200))) == 0);
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync if ( pShwPDPT->a[i].n.u1Present
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync && !(pShwPDPT->a[i].u & PGM_PLXFLAGS_MAPPING)
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync )
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync {
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync PPGMPOOLPAGE pSubPage = (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, pShwPDPT->a[i].u & X86_PDPE_PG_MASK);
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync if (pSubPage)
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync pgmPoolTrackFreeUser(pPool, pSubPage, pPage->idx, i);
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync else
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync AssertFatalMsgFailed(("%RX64\n", pShwPDPT->a[i].u & X86_PDPE_PG_MASK));
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Clear references to shadowed pages in a 64-bit page directory pointer table.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPool The pool.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPage The page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pShwPDPT The shadow page directory pointer table (mapping of the page).
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncDECLINLINE(void) pgmPoolTrackDerefPDPT64Bit(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PDPT pShwPDPT)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pShwPDPT->a); i++)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync Assert((pShwPDPT->a[i].u & (X86_PDPE_LM_MBZ_MASK_NX | UINT64_C(0x7ff0000000000200))) == 0);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pShwPDPT->a[i].n.u1Present)
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMPOOLPAGE pSubPage = (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, pShwPDPT->a[i].u & X86_PDPE_PG_MASK);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pSubPage)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolTrackFreeUser(pPool, pSubPage, pPage->idx, i);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync else
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertFatalMsgFailed(("%RX64\n", pShwPDPT->a[i].u & X86_PDPE_PG_MASK));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /** @todo 64-bit guests: have to ensure that we're not exhausting the dynamic mappings! */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Clear references to shadowed pages in a 64-bit level 4 page table.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPool The pool.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPage The page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pShwPML4 The shadow page directory pointer table (mapping of the page).
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncDECLINLINE(void) pgmPoolTrackDerefPML464Bit(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PML4 pShwPML4)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pShwPML4->a); i++)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert((pShwPML4->a[i].u & (X86_PML4E_MBZ_MASK_NX | UINT64_C(0x7ff0000000000200))) == 0);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pShwPML4->a[i].n.u1Present)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMPOOLPAGE pSubPage = (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, pShwPML4->a[i].u & X86_PDPE_PG_MASK);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pSubPage)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolTrackFreeUser(pPool, pSubPage, pPage->idx, i);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync else
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertFatalMsgFailed(("%RX64\n", pShwPML4->a[i].u & X86_PML4E_PG_MASK));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /** @todo 64-bit guests: have to ensure that we're not exhausting the dynamic mappings! */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync/**
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync * Clear references to shadowed pages in an EPT page directory.
0ffa3979e9b800f5931dd30c51ec3c0aadc3a1f1vboxsync *
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync * @param pPool The pool.
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync * @param pPage The page.
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync * @param pShwPD The shadow page directory (mapping of the page).
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync */
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsyncDECLINLINE(void) pgmPoolTrackDerefPDEPT(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PEPTPD pShwPD)
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync{
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pShwPD->a); i++)
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync {
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync Assert((pShwPD->a[i].u & UINT64_C(0xfff0000000000f80)) == 0);
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync if (pShwPD->a[i].n.u1Present)
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync {
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync#ifdef PGM_WITH_LARGE_PAGES
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync if (pShwPD->a[i].b.u1Size)
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync {
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync Log4(("pgmPoolTrackDerefPDEPT: i=%d pde=%RX64 GCPhys=%RX64\n",
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync i, pShwPD->a[i].u & X86_PDE2M_PAE_PG_MASK, pPage->GCPhys));
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync pgmPoolTracDerefGCPhys(pPool, pPage, pShwPD->a[i].u & X86_PDE2M_PAE_PG_MASK, pPage->GCPhys + i * 2 * _1M /* pPage->GCPhys = base address of the memory described by the PD */, i);
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync }
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync else
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync#endif
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync {
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync PPGMPOOLPAGE pSubPage = (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, pShwPD->a[i].u & EPT_PDE_PG_MASK);
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync if (pSubPage)
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync pgmPoolTrackFreeUser(pPool, pSubPage, pPage->idx, i);
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync else
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync AssertFatalMsgFailed(("%RX64\n", pShwPD->a[i].u & EPT_PDE_PG_MASK));
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync }
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync /** @todo 64-bit guests: have to ensure that we're not exhausting the dynamic mappings! */
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync }
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync }
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync}
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync/**
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync * Clear references to shadowed pages in an EPT page directory pointer table.
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync *
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync * @param pPool The pool.
cf16cbc1c9fba42198dfb26f17a38902284dca48vboxsync * @param pPage The page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pShwPDPT The shadow page directory pointer table (mapping of the page).
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncDECLINLINE(void) pgmPoolTrackDerefPDPTEPT(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PEPTPDPT pShwPDPT)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pShwPDPT->a); i++)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert((pShwPDPT->a[i].u & UINT64_C(0xfff0000000000f80)) == 0);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pShwPDPT->a[i].n.u1Present)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMPOOLPAGE pSubPage = (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, pShwPDPT->a[i].u & EPT_PDPTE_PG_MASK);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pSubPage)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolTrackFreeUser(pPool, pSubPage, pPage->idx, i);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync else
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertFatalMsgFailed(("%RX64\n", pShwPDPT->a[i].u & EPT_PDPTE_PG_MASK));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /** @todo 64-bit guests: have to ensure that we're not exhausting the dynamic mappings! */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
d200be7337d4aad2bec2961a885e856f7866d4f6vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Clears all references made by this page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * This includes other shadow pages and GC physical addresses.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPool The pool.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPage The page.
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncstatic void pgmPoolTrackDeref(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Map the shadow page and take action according to the page kind.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PVM pVM = pPool->CTX_SUFF(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync void *pvShw = PGMPOOL_PAGE_2_PTR(pVM, pPage);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync switch (pPage->enmKind)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_PT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_PROFILE_START(&pPool->StatTrackDerefGCPhys, g);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync void *pvGst;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync int rc = PGM_GCPHYS_2_PTR(pVM, pPage->GCPhys, &pvGst); AssertReleaseRC(rc);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolTrackDerefPT32Bit32Bit(pPool, pPage, (PX86PT)pvShw, (PCX86PT)pvGst);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PGM_DYNMAP_UNUSED_HINT_VM(pVM, pvGst);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_PROFILE_STOP(&pPool->StatTrackDerefGCPhys, g);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_PT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_PROFILE_START(&pPool->StatTrackDerefGCPhys, g);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync void *pvGst;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync int rc = PGM_GCPHYS_2_PTR_EX(pVM, pPage->GCPhys, &pvGst); AssertReleaseRC(rc);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolTrackDerefPTPae32Bit(pPool, pPage, (PPGMSHWPTPAE)pvShw, (PCX86PT)pvGst);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PGM_DYNMAP_UNUSED_HINT_VM(pVM, pvGst);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_PROFILE_STOP(&pPool->StatTrackDerefGCPhys, g);
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_PT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_PROFILE_START(&pPool->StatTrackDerefGCPhys, g);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync void *pvGst;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync int rc = PGM_GCPHYS_2_PTR(pVM, pPage->GCPhys, &pvGst); AssertReleaseRC(rc);
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync pgmPoolTrackDerefPTPaePae(pPool, pPage, (PPGMSHWPTPAE)pvShw, (PCX86PTPAE)pvGst);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PGM_DYNMAP_UNUSED_HINT_VM(pVM, pvGst);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_PROFILE_STOP(&pPool->StatTrackDerefGCPhys, g);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_32BIT_PT_FOR_PHYS: /* treat it like a 4 MB page */
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_4MB:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync STAM_PROFILE_START(&pPool->StatTrackDerefGCPhys, g);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolTrackDerefPT32Bit4MB(pPool, pPage, (PX86PT)pvShw);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_PROFILE_STOP(&pPool->StatTrackDerefGCPhys, g);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PT_FOR_PHYS: /* treat it like a 2 MB page */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_2MB:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_4MB:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_PROFILE_START(&pPool->StatTrackDerefGCPhys, g);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolTrackDerefPTPaeBig(pPool, pPage, (PPGMSHWPTPAE)pvShw);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_PROFILE_STOP(&pPool->StatTrackDerefGCPhys, g);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD0_FOR_32BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD1_FOR_32BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD2_FOR_32BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD3_FOR_32BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD_FOR_PAE_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD_PHYS:
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync case PGMPOOLKIND_64BIT_PD_FOR_64BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PD_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolTrackDerefPDPae(pPool, pPage, (PX86PDPAE)pvShw);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync case PGMPOOLKIND_32BIT_PD_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_32BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolTrackDerefPD(pPool, pPage, (PX86PD)pvShw);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PDPT_FOR_32BIT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PDPT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PDPT_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolTrackDerefPDPTPae(pPool, pPage, (PX86PDPT)pvShw);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_64BIT_PDPT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolTrackDerefPDPT64Bit(pPool, pPage, (PX86PDPT)pvShw);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PML4:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolTrackDerefPML464Bit(pPool, pPage, (PX86PML4)pvShw);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_EPT_PT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolTrackDerefPTEPT(pPool, pPage, (PEPTPT)pvShw);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_EPT_PD_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolTrackDerefPDEPT(pPool, pPage, (PEPTPD)pvShw);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_EPT_PDPT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolTrackDerefPDPTEPT(pPool, pPage, (PEPTPDPT)pvShw);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync default:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertFatalMsgFailed(("enmKind=%d\n", pPage->enmKind));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* paranoia, clear the shadow page. Remove this laser (i.e. let Alloc and ClearAll do it). */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_PROFILE_START(&pPool->StatZeroPage, z);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync ASMMemZeroPage(pvShw);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_PROFILE_STOP(&pPool->StatZeroPage, z);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->fZeroed = true;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(!pPage->cPresent);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PGM_DYNMAP_UNUSED_HINT_VM(pVM, pvShw);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Flushes a pool page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * This moves the page to the free list after removing all user references to it.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @returns VBox status code.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @retval VINF_SUCCESS on success.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPool The pool.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param HCPhys The HC physical address of the shadow page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param fFlush Flush the TLBS when required (should only be false in very specific use cases!!)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncint pgmPoolFlushPage(PPGMPOOL pPool, PPGMPOOLPAGE pPage, bool fFlush)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PVM pVM = pPool->CTX_SUFF(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync bool fFlushRequired = false;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync int rc = VINF_SUCCESS;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_PROFILE_START(&pPool->StatFlushPage, f);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync LogFlow(("pgmPoolFlushPage: pPage=%p:{.Key=%RHp, .idx=%d, .enmKind=%s, .GCPhys=%RGp}\n",
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage, pPage->Core.Key, pPage->idx, pgmPoolPoolKindToStr(pPage->enmKind), pPage->GCPhys));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Quietly reject any attempts at flushing any of the special root pages.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pPage->idx < PGMPOOL_IDX_FIRST)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertFailed(); /* can no longer happen */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log(("pgmPoolFlushPage: special root page, rejected. enmKind=%s idx=%d\n", pgmPoolPoolKindToStr(pPage->enmKind), pPage->idx));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return VINF_SUCCESS;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmLock(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Quietly reject any attempts at flushing the currently active shadow CR3 mapping
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pgmPoolIsPageLocked(&pVM->pgm.s, pPage))
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertMsg( pPage->enmKind == PGMPOOLKIND_64BIT_PML4
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync || pPage->enmKind == PGMPOOLKIND_PAE_PDPT
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync || pPage->enmKind == PGMPOOLKIND_PAE_PDPT_FOR_32BIT
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync || pPage->enmKind == PGMPOOLKIND_32BIT_PD
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync || pPage->enmKind == PGMPOOLKIND_PAE_PD_FOR_PAE_PD
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync || pPage->enmKind == PGMPOOLKIND_PAE_PD0_FOR_32BIT_PD
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync || pPage->enmKind == PGMPOOLKIND_PAE_PD1_FOR_32BIT_PD
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync || pPage->enmKind == PGMPOOLKIND_PAE_PD2_FOR_32BIT_PD
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync || pPage->enmKind == PGMPOOLKIND_PAE_PD3_FOR_32BIT_PD
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync || pPage->enmKind == PGMPOOLKIND_ROOT_NESTED,
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync ("Can't free the shadow CR3! (%RHp vs %RHp kind=%d\n", PGMGetHyperCR3(VMMGetCpu(pVM)), pPage->Core.Key, pPage->enmKind));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log(("pgmPoolFlushPage: current active shadow CR3, rejected. enmKind=%s idx=%d\n", pgmPoolPoolKindToStr(pPage->enmKind), pPage->idx));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmUnlock(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return VINF_SUCCESS;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#if defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0) || defined(IN_RC)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* Start a subset so we won't run out of mapping space. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PVMCPU pVCpu = VMMGetCpu(pVM);
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync uint32_t iPrevSubset = PGMRZDynMapPushAutoSubset(pVCpu);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#endif
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Mark the page as being in need of an ASMMemZeroPage().
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->fZeroed = false;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#ifdef PGMPOOL_WITH_OPTIMIZED_DIRTY_PT
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pPage->fDirty)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolFlushDirtyPage(pVM, pPool, pPage->idxDirty, false /* do not remove */);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#endif
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* If there are any users of this table, then we *must* issue a tlb flush on all VCPUs. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pPage->iUserHead != NIL_PGMPOOL_USER_INDEX)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync fFlushRequired = true;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Clear the page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolTrackClearPageUsers(pPool, pPage);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_PROFILE_START(&pPool->StatTrackDeref,a);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolTrackDeref(pPool, pPage);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_PROFILE_STOP(&pPool->StatTrackDeref,a);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Flush it from the cache.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolCacheFlushPage(pPool, pPage);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#if defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0) || defined(IN_RC)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* Heavy stuff done. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PGMRZDynMapPopAutoSubset(pVCpu, iPrevSubset);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#endif
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Deregistering the monitoring.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pPage->fMonitored)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync rc = pgmPoolMonitorFlush(pPool, pPage);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Free the page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(pPage->iNext == NIL_PGMPOOL_IDX);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->iNext = pPool->iFreeHead;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->iFreeHead = pPage->idx;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->enmKind = PGMPOOLKIND_FREE;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->enmAccess = PGMPOOLACCESS_DONTCARE;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->GCPhys = NIL_RTGCPHYS;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->fReusedFlushPending = false;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->cUsedPages--;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* Flush the TLBs of all VCPUs if required. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if ( fFlushRequired
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync && fFlush)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PGM_INVL_ALL_VCPU_TLBS(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmUnlock(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_PROFILE_STOP(&pPool->StatFlushPage, f);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return rc;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Frees a usage of a pool page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * The caller is responsible to updating the user table so that it no longer
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * references the shadow page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPool The pool.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param HCPhys The HC physical address of the shadow page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param iUser The shadow page pool index of the user table.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param iUserTable The index into the user table (shadowed).
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncvoid pgmPoolFreeByPage(PPGMPOOL pPool, PPGMPOOLPAGE pPage, uint16_t iUser, uint32_t iUserTable)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PVM pVM = pPool->CTX_SUFF(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_PROFILE_START(&pPool->StatFree, a);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync LogFlow(("pgmPoolFreeByPage: pPage=%p:{.Key=%RHp, .idx=%d, enmKind=%s} iUser=%d iUserTable=%#x\n",
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage, pPage->Core.Key, pPage->idx, pgmPoolPoolKindToStr(pPage->enmKind), iUser, iUserTable));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(pPage->idx >= PGMPOOL_IDX_FIRST);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmLock(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolTrackFreeUser(pPool, pPage, iUser, iUserTable);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (!pPage->fCached)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolFlushPage(pPool, pPage);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmUnlock(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_PROFILE_STOP(&pPool->StatFree, a);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Makes one or more free page free.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @returns VBox status code.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @retval VINF_SUCCESS on success.
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync * @retval VERR_PGM_POOL_FLUSHED if the pool was flushed.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPool The pool.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param enmKind Page table kind
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param iUser The user of the page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncstatic int pgmPoolMakeMoreFreePages(PPGMPOOL pPool, PGMPOOLKIND enmKind, uint16_t iUser)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PVM pVM = pPool->CTX_SUFF(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync LogFlow(("pgmPoolMakeMoreFreePages: iUser=%d\n", iUser));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * If the pool isn't full grown yet, expand it.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if ( pPool->cCurPages < pPool->cMaxPages
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#if defined(IN_RC)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* Hack alert: we can't deal with jumps to ring 3 when called from MapCR3 and allocating pages for PAE PDs. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync && enmKind != PGMPOOLKIND_PAE_PD_FOR_PAE_PD
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync && (enmKind < PGMPOOLKIND_PAE_PD0_FOR_32BIT_PD || enmKind > PGMPOOLKIND_PAE_PD3_FOR_32BIT_PD)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#endif
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync )
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_PROFILE_ADV_SUSPEND(&pPool->StatAlloc, a);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#ifdef IN_RING3
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync int rc = PGMR3PoolGrow(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#else
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync int rc = VMMRZCallRing3NoCpu(pVM, VMMCALLRING3_PGM_POOL_GROW, 0);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#endif
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (RT_FAILURE(rc))
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return rc;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_PROFILE_ADV_RESUME(&pPool->StatAlloc, a);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pPool->iFreeHead != NIL_PGMPOOL_IDX)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return VINF_SUCCESS;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Free one cached page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return pgmPoolCacheFreeOne(pPool, iUser);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Allocates a page from the pool.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * This page may actually be a cached page and not in need of any processing
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * on the callers part.
aec6fc9d2efe16d4e250b2ebaf8dbfbd49f8eaa6vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @returns VBox status code.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @retval VINF_SUCCESS if a NEW page was allocated.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @retval VINF_PGM_CACHED_PAGE if a CACHED page was returned.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @retval VERR_PGM_POOL_FLUSHED if the pool was flushed.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pVM The VM handle.
d200be7337d4aad2bec2961a885e856f7866d4f6vboxsync * @param GCPhys The GC physical address of the page we're gonna shadow.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * For 4MB and 2MB PD entries, it's the first address the
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * shadow PT is covering.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param enmKind The kind of mapping.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param enmAccess Access type for the mapping (only relevant for big pages)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param iUser The shadow page pool index of the user table.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param iUserTable The index into the user table (shadowed).
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync * @param fLockPage Lock the page
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param ppPage Where to store the pointer to the page. NULL is stored here on failure.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncint pgmPoolAllocEx(PVM pVM, RTGCPHYS GCPhys, PGMPOOLKIND enmKind, PGMPOOLACCESS enmAccess, uint16_t iUser, uint32_t iUserTable,
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync bool fLockPage, PPPGMPOOLPAGE ppPage)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMPOOL pPool = pVM->pgm.s.CTX_SUFF(pPool);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_PROFILE_ADV_START(&pPool->StatAlloc, a);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync LogFlow(("pgmPoolAllocEx: GCPhys=%RGp enmKind=%s iUser=%d iUserTable=%#x\n", GCPhys, pgmPoolPoolKindToStr(enmKind), iUser, iUserTable));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *ppPage = NULL;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /** @todo CSAM/PGMPrefetchPage messes up here during CSAMR3CheckGates
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * (TRPMR3SyncIDT) because of FF priority. Try fix that?
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Assert(!(pVM->pgm.s.fGlobalSyncFlags & PGM_SYNC_CLEAR_PGM_POOL)); */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmLock(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pPool->fCacheEnabled)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync int rc2 = pgmPoolCacheAlloc(pPool, GCPhys, enmKind, enmAccess, iUser, iUserTable, ppPage);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (RT_SUCCESS(rc2))
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (fLockPage)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolLockPage(pPool, *ppPage);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmUnlock(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_PROFILE_ADV_STOP(&pPool->StatAlloc, a);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync LogFlow(("pgmPoolAllocEx: cached returns %Rrc *ppPage=%p:{.Key=%RHp, .idx=%d}\n", rc2, *ppPage, (*ppPage)->Core.Key, (*ppPage)->idx));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return rc2;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Allocate a new one.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync int rc = VINF_SUCCESS;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync uint16_t iNew = pPool->iFreeHead;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (iNew == NIL_PGMPOOL_IDX)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync rc = pgmPoolMakeMoreFreePages(pPool, enmKind, iUser);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (RT_FAILURE(rc))
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmUnlock(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log(("pgmPoolAllocEx: returns %Rrc (Free)\n", rc));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_PROFILE_ADV_STOP(&pPool->StatAlloc, a);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return rc;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync iNew = pPool->iFreeHead;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertReleaseReturn(iNew != NIL_PGMPOOL_IDX, VERR_INTERNAL_ERROR);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* unlink the free head */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMPOOLPAGE pPage = &pPool->aPages[iNew];
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->iFreeHead = pPage->iNext;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->iNext = NIL_PGMPOOL_IDX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Initialize it.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->cUsedPages++; /* physical handler registration / pgmPoolTrackFlushGCPhysPTsSlow requirement. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->enmKind = enmKind;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->enmAccess = enmAccess;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->GCPhys = GCPhys;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->fSeenNonGlobal = false; /* Set this to 'true' to disable this feature. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->fMonitored = false;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->fCached = false;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#ifdef PGMPOOL_WITH_OPTIMIZED_DIRTY_PT
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->fDirty = false;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#endif
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->fReusedFlushPending = false;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->cModifications = 0;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->iModifiedNext = NIL_PGMPOOL_IDX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->iModifiedPrev = NIL_PGMPOOL_IDX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->cLocked = 0;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->cPresent = 0;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->iFirstPresent = NIL_PGMPOOL_PRESENT_INDEX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->pvLastAccessHandlerFault = 0;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->cLastAccessHandlerCount = 0;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->pvLastAccessHandlerRip = 0;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Insert into the tracking and cache. If this fails, free the page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync int rc3 = pgmPoolTrackInsert(pPool, pPage, GCPhys, iUser, iUserTable);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (RT_FAILURE(rc3))
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->cUsedPages--;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->enmKind = PGMPOOLKIND_FREE;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->enmAccess = PGMPOOLACCESS_DONTCARE;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->GCPhys = NIL_RTGCPHYS;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->iNext = pPool->iFreeHead;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->iFreeHead = pPage->idx;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmUnlock(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_PROFILE_ADV_STOP(&pPool->StatAlloc, a);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log(("pgmPoolAllocEx: returns %Rrc (Insert)\n", rc3));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return rc3;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Commit the allocation, clear the page and return.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#ifdef VBOX_WITH_STATISTICS
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pPool->cUsedPages > pPool->cUsedPagesHigh)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->cUsedPagesHigh = pPool->cUsedPages;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#endif
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (!pPage->fZeroed)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_PROFILE_START(&pPool->StatZeroPage, z);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync void *pv = PGMPOOL_PAGE_2_PTR(pVM, pPage);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync ASMMemZeroPage(pv);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_PROFILE_STOP(&pPool->StatZeroPage, z);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *ppPage = pPage;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (fLockPage)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolLockPage(pPool, pPage);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmUnlock(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync LogFlow(("pgmPoolAllocEx: returns %Rrc *ppPage=%p:{.Key=%RHp, .idx=%d, .fCached=%RTbool, .fMonitored=%RTbool}\n",
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync rc, pPage, pPage->Core.Key, pPage->idx, pPage->fCached, pPage->fMonitored));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_PROFILE_ADV_STOP(&pPool->StatAlloc, a);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return rc;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Frees a usage of a pool page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pVM The VM handle.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param HCPhys The HC physical address of the shadow page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param iUser The shadow page pool index of the user table.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param iUserTable The index into the user table (shadowed).
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncvoid pgmPoolFree(PVM pVM, RTHCPHYS HCPhys, uint16_t iUser, uint32_t iUserTable)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync LogFlow(("pgmPoolFree: HCPhys=%RHp iUser=%d iUserTable=%#x\n", HCPhys, iUser, iUserTable));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMPOOL pPool = pVM->pgm.s.CTX_SUFF(pPool);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolFreeByPage(pPool, pgmPoolGetPage(pPool, HCPhys), iUser, iUserTable);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Internal worker for finding a 'in-use' shadow page give by it's physical address.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @returns Pointer to the shadow page structure.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPool The pool.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param HCPhys The HC physical address of the shadow page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncPPGMPOOLPAGE pgmPoolGetPage(PPGMPOOL pPool, RTHCPHYS HCPhys)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PVM pVM = pPool->CTX_SUFF(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(PGMIsLockOwner(pVM));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Look up the page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMPOOLPAGE pPage = (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, HCPhys & X86_PTE_PAE_PG_MASK);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertFatalMsg(pPage && pPage->enmKind != PGMPOOLKIND_FREE, ("HCPhys=%RHp pPage=%p idx=%d\n", HCPhys, pPage, (pPage) ? pPage->idx : 0));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return pPage;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Internal worker for finding a page for debugging purposes, no assertions.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @returns Pointer to the shadow page structure. NULL on if not found.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPool The pool.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param HCPhys The HC physical address of the shadow page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncPPGMPOOLPAGE pgmPoolQueryPageForDbg(PPGMPOOL pPool, RTHCPHYS HCPhys)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PVM pVM = pPool->CTX_SUFF(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(PGMIsLockOwner(pVM));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, HCPhys & X86_PTE_PAE_PG_MASK);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#ifdef IN_RING3 /* currently only used in ring 3; save some space in the R0 & GC modules (left it here as we might need it elsewhere later on) */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Flush the specified page if present
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pVM The VM handle.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param GCPhys Guest physical address of the page to flush
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncvoid pgmPoolFlushPageByGCPhys(PVM pVM, RTGCPHYS GCPhys)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMPOOL pPool = pVM->pgm.s.CTX_SUFF(pPool);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync VM_ASSERT_EMT(pVM);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Look up the GCPhys in the hash.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync GCPhys = GCPhys & ~(RTGCPHYS)PAGE_OFFSET_MASK;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync unsigned i = pPool->aiHash[PGMPOOL_HASH(GCPhys)];
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (i == NIL_PGMPOOL_IDX)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync do
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMPOOLPAGE pPage = &pPool->aPages[i];
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pPage->GCPhys - GCPhys < PAGE_SIZE)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync switch (pPage->enmKind)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_PT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_PT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_PT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD0_FOR_32BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD1_FOR_32BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD2_FOR_32BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD3_FOR_32BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD_FOR_PAE_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PD_FOR_64BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_64BIT_PDPT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PML4:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_32BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PDPT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Log(("PGMPoolFlushPage: found pgm pool pages for %RGp\n", GCPhys));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#ifdef PGMPOOL_WITH_OPTIMIZED_DIRTY_PT
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pPage->fDirty)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_COUNTER_INC(&pPool->StatForceFlushDirtyPage);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync else
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#endif
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_COUNTER_INC(&pPool->StatForceFlushPage);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(!pgmPoolIsPageLocked(&pVM->pgm.s, pPage));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolMonitorChainFlush(pPool, pPage);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* ignore, no monitoring. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_4MB:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_2MB:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_4MB:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_32BIT_PT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PD_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_EPT_PDPT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_EPT_PD_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_EPT_PT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_ROOT_NESTED:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PDPT_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_32BIT_PD_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PDPT_FOR_32BIT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync break;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync default:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertFatalMsgFailed(("enmKind=%d idx=%d\n", pPage->enmKind, pPage->idx));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* next */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync i = pPage->iNext;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync } while (i != NIL_PGMPOOL_IDX);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#endif /* IN_RING3 */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#ifdef IN_RING3
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Reset CPU on hot plugging.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pVM The VM handle.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pVCpu The virtual CPU.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncvoid pgmR3PoolResetUnpluggedCpu(PVM pVM, PVMCPU pVCpu)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmR3ExitShadowModeBeforePoolFlush(pVM, pVCpu);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmR3ReEnterShadowModeAfterPoolFlush(pVM, pVCpu);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync VMCPU_FF_SET(pVCpu, VMCPU_FF_PGM_SYNC_CR3);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync VMCPU_FF_SET(pVCpu, VMCPU_FF_TLB_FLUSH);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/**
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Flushes the entire cache.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * It will assert a global CR3 flush (FF) and assumes the caller is aware of
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * this and execute this CR3 flush.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * @param pPool The pool.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncvoid pgmR3PoolReset(PVM pVM)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMPOOL pPool = pVM->pgm.s.CTX_SUFF(pPool);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(PGMIsLockOwner(pVM));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_PROFILE_START(&pPool->StatR3Reset, a);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync LogFlow(("pgmR3PoolReset:\n"));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * If there are no pages in the pool, there is nothing to do.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pPool->cCurPages <= PGMPOOL_IDX_FIRST)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_PROFILE_STOP(&pPool->StatR3Reset, a);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Exit the shadow mode since we're going to clear everything,
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * including the root page.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync for (VMCPUID i = 0; i < pVM->cCpus; i++)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PVMCPU pVCpu = &pVM->aCpus[i];
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmR3ExitShadowModeBeforePoolFlush(pVM, pVCpu);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Nuke the free list and reinsert all pages into it.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync for (unsigned i = pPool->cCurPages - 1; i >= PGMPOOL_IDX_FIRST; i--)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMPOOLPAGE pPage = &pPool->aPages[i];
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(pPage->Core.Key == MMPage2Phys(pVM, pPage->pvPageR3));
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pPage->fMonitored)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolMonitorFlush(pPool, pPage);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->iModifiedNext = NIL_PGMPOOL_IDX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->iModifiedPrev = NIL_PGMPOOL_IDX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->iMonitoredNext = NIL_PGMPOOL_IDX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->iMonitoredPrev = NIL_PGMPOOL_IDX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->cModifications = 0;
2b114c590cf5a19f8047cd7bde9c7e5ae00aa22bvboxsync pPage->GCPhys = NIL_RTGCPHYS;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->enmKind = PGMPOOLKIND_FREE;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->enmAccess = PGMPOOLACCESS_DONTCARE;
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync Assert(pPage->idx == i);
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync pPage->iNext = i + 1;
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync pPage->fZeroed = false; /* This could probably be optimized, but better safe than sorry. */
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync pPage->fSeenNonGlobal = false;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->fMonitored = false;
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync#ifdef PGMPOOL_WITH_OPTIMIZED_DIRTY_PT
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync pPage->fDirty = false;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#endif
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->fCached = false;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->fReusedFlushPending = false;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->iUserHead = NIL_PGMPOOL_USER_INDEX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->iAgeNext = NIL_PGMPOOL_IDX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->iAgePrev = NIL_PGMPOOL_IDX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->cLocked = 0;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->aPages[pPool->cCurPages - 1].iNext = NIL_PGMPOOL_IDX;
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync pPool->iFreeHead = PGMPOOL_IDX_FIRST;
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync pPool->cUsedPages = 0;
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync * Zap and reinitialize the user records.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->cPresent = 0;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->iUserFreeHead = 0;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMPOOLUSER paUsers = pPool->CTX_SUFF(paUsers);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync const unsigned cMaxUsers = pPool->cMaxUsers;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync for (unsigned i = 0; i < cMaxUsers; i++)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync paUsers[i].iNext = i + 1;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync paUsers[i].iUser = NIL_PGMPOOL_IDX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync paUsers[i].iUserTable = 0xfffffffe;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync paUsers[cMaxUsers - 1].iNext = NIL_PGMPOOL_USER_INDEX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Clear all the GCPhys links and rebuild the phys ext free list.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync for (PPGMRAMRANGE pRam = pVM->pgm.s.CTX_SUFF(pRamRanges);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pRam;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pRam = pRam->CTX_SUFF(pNext))
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync unsigned iPage = pRam->cb >> PAGE_SHIFT;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync while (iPage-- > 0)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PGM_PAGE_SET_TRACKING(&pRam->aPages[iPage], 0);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->iPhysExtFreeHead = 0;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMPOOLPHYSEXT paPhysExts = pPool->CTX_SUFF(paPhysExts);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync const unsigned cMaxPhysExts = pPool->cMaxPhysExts;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync for (unsigned i = 0; i < cMaxPhysExts; i++)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync paPhysExts[i].iNext = i + 1;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync paPhysExts[i].aidx[0] = NIL_PGMPOOL_IDX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync paPhysExts[i].apte[0] = NIL_PGMPOOL_PHYSEXT_IDX_PTE;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync paPhysExts[i].aidx[1] = NIL_PGMPOOL_IDX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync paPhysExts[i].apte[1] = NIL_PGMPOOL_PHYSEXT_IDX_PTE;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync paPhysExts[i].aidx[2] = NIL_PGMPOOL_IDX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync paPhysExts[i].apte[2] = NIL_PGMPOOL_PHYSEXT_IDX_PTE;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync paPhysExts[cMaxPhysExts - 1].iNext = NIL_PGMPOOL_PHYSEXT_INDEX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Just zap the modified list.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->cModifiedPages = 0;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->iModifiedHead = NIL_PGMPOOL_IDX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Clear the GCPhys hash and the age list.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pPool->aiHash); i++)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->aiHash[i] = NIL_PGMPOOL_IDX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->iAgeHead = NIL_PGMPOOL_IDX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->iAgeTail = NIL_PGMPOOL_IDX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#ifdef PGMPOOL_WITH_OPTIMIZED_DIRTY_PT
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* Clear all dirty pages. */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->idxFreeDirtyPage = 0;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->cDirtyPages = 0;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pPool->aDirtyPages); i++)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->aDirtyPages[i].uIdx = NIL_PGMPOOL_IDX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#endif
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Reinsert active pages into the hash and ensure monitoring chains are correct.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync for (unsigned i = PGMPOOL_IDX_FIRST_SPECIAL; i < PGMPOOL_IDX_FIRST; i++)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPGMPOOLPAGE pPage = &pPool->aPages[i];
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->iNext = NIL_PGMPOOL_IDX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->iModifiedNext = NIL_PGMPOOL_IDX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->iModifiedPrev = NIL_PGMPOOL_IDX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->cModifications = 0;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /* ASSUMES that we're not sharing with any of the other special pages (safe for now). */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->iMonitoredNext = NIL_PGMPOOL_IDX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPage->iMonitoredPrev = NIL_PGMPOOL_IDX;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (pPage->fMonitored)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync int rc = PGMHandlerPhysicalChangeCallbacks(pVM, pPage->GCPhys & ~(RTGCPHYS)PAGE_OFFSET_MASK,
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->pfnAccessHandlerR3, MMHyperCCToR3(pVM, pPage),
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->pfnAccessHandlerR0, MMHyperCCToR0(pVM, pPage),
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->pfnAccessHandlerRC, MMHyperCCToRC(pVM, pPage),
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pPool->pszAccessHandler);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync AssertFatalRCSuccess(rc);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmPoolHashInsert(pPool, pPage);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(pPage->iUserHead == NIL_PGMPOOL_USER_INDEX); /* for now */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(pPage->iAgeNext == NIL_PGMPOOL_IDX);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync Assert(pPage->iAgePrev == NIL_PGMPOOL_IDX);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync for (VMCPUID i = 0; i < pVM->cCpus; i++)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync /*
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Re-enter the shadowing mode and assert Sync CR3 FF.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PVMCPU pVCpu = &pVM->aCpus[i];
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pgmR3ReEnterShadowModeAfterPoolFlush(pVM, pVCpu);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync VMCPU_FF_SET(pVCpu, VMCPU_FF_PGM_SYNC_CR3);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync VMCPU_FF_SET(pVCpu, VMCPU_FF_TLB_FLUSH);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync STAM_PROFILE_STOP(&pPool->StatR3Reset, a);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#endif /* IN_RING3 */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#ifdef LOG_ENABLED
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncstatic const char *pgmPoolPoolKindToStr(uint8_t enmKind)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync switch(enmKind)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync {
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_INVALID:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return "PGMPOOLKIND_INVALID";
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_FREE:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return "PGMPOOLKIND_FREE";
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_32BIT_PT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return "PGMPOOLKIND_32BIT_PT_FOR_PHYS";
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_PT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return "PGMPOOLKIND_32BIT_PT_FOR_32BIT_PT";
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_32BIT_PT_FOR_32BIT_4MB:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return "PGMPOOLKIND_32BIT_PT_FOR_32BIT_4MB";
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return "PGMPOOLKIND_PAE_PT_FOR_PHYS";
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_PT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return "PGMPOOLKIND_PAE_PT_FOR_32BIT_PT";
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PT_FOR_32BIT_4MB:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return "PGMPOOLKIND_PAE_PT_FOR_32BIT_4MB";
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_PT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return "PGMPOOLKIND_PAE_PT_FOR_PAE_PT";
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PT_FOR_PAE_2MB:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return "PGMPOOLKIND_PAE_PT_FOR_PAE_2MB";
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_32BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return "PGMPOOLKIND_32BIT_PD";
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_32BIT_PD_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return "PGMPOOLKIND_32BIT_PD_PHYS";
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD0_FOR_32BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return "PGMPOOLKIND_PAE_PD0_FOR_32BIT_PD";
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD1_FOR_32BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return "PGMPOOLKIND_PAE_PD1_FOR_32BIT_PD";
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD2_FOR_32BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return "PGMPOOLKIND_PAE_PD2_FOR_32BIT_PD";
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD3_FOR_32BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return "PGMPOOLKIND_PAE_PD3_FOR_32BIT_PD";
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD_FOR_PAE_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return "PGMPOOLKIND_PAE_PD_FOR_PAE_PD";
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PD_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return "PGMPOOLKIND_PAE_PD_PHYS";
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PDPT_FOR_32BIT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return "PGMPOOLKIND_PAE_PDPT_FOR_32BIT";
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PDPT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return "PGMPOOLKIND_PAE_PDPT";
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_PAE_PDPT_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return "PGMPOOLKIND_PAE_PDPT_PHYS";
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_64BIT_PDPT:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return "PGMPOOLKIND_64BIT_PDPT_FOR_64BIT_PDPT";
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PDPT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return "PGMPOOLKIND_64BIT_PDPT_FOR_PHYS";
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PD_FOR_64BIT_PD:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return "PGMPOOLKIND_64BIT_PD_FOR_64BIT_PD";
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PD_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return "PGMPOOLKIND_64BIT_PD_FOR_PHYS";
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_64BIT_PML4:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return "PGMPOOLKIND_64BIT_PML4";
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_EPT_PDPT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return "PGMPOOLKIND_EPT_PDPT_FOR_PHYS";
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_EPT_PD_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return "PGMPOOLKIND_EPT_PD_FOR_PHYS";
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_EPT_PT_FOR_PHYS:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return "PGMPOOLKIND_EPT_PT_FOR_PHYS";
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync case PGMPOOLKIND_ROOT_NESTED:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return "PGMPOOLKIND_ROOT_NESTED";
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return "Unknown kind!";
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#endif /* LOG_ENABLED*/
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync