PGMR0SharedPage.cpp revision 272945f61415b46e17e1ece4c0424d7949c2638b
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync/* $Id: PGMR0.cpp 61539 2010-05-12 15:11:09Z sandervl $ */
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync * PGM - Page Manager and Monitor, Ring-0.
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * Copyright (C) 2007 Oracle Corporation
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync * available from http://www.virtualbox.org. This file is free software;
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync * you can redistribute it and/or modify it under the terms of the GNU
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * General Public License (GPL) as published by the Free Software
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync/*******************************************************************************
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync* Header Files *
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync*******************************************************************************/
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync * Check a registered module for shared page changes
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync * @returns The following VBox status codes.
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync * @param pVM The VM handle.
134a71c1528b56afe4db843ab63ec5a5b849535bvboxsync * @param idCpu VCPU id
134a71c1528b56afe4db843ab63ec5a5b849535bvboxsync * @param pModule Module description
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync * @param pGVM Pointer to the GVM instance data.
134a71c1528b56afe4db843ab63ec5a5b849535bvboxsyncVMMR0DECL(int) PGMR0SharedModuleCheckRegion(PVM pVM, VMCPUID idCpu, PGMMSHAREDMODULE pModule, PGVM pGVM)
6420f75ffc86ab6494eb5e95418f0c95e71e8068vboxsync bool fFlushTLBs = false;
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync Log(("PGMR0SharedModuleCheck: check %s %s base=%RGv size=%x\n", pModule->szName, pModule->szVersion, pModule->Core.Key, pModule->cbModule));
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync /* Check every region of the shared module. */
6420f75ffc86ab6494eb5e95418f0c95e71e8068vboxsync for (unsigned idxModule = 0; idxModule < pModule->cRegions; idxModule++)
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync Assert((pModule->aRegions[idxModule].cbRegion & 0xfff) == 0);
9ad5e3912962c3dbccc1afc4e7d62890fe906814vboxsync Assert((pModule->aRegions[idxModule].GCRegionAddr & 0xfff) == 0);
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync RTGCPTR GCRegion = pModule->aRegions[idxModule].GCRegionAddr;
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync unsigned cbRegion = pModule->aRegions[idxModule].cbRegion & ~0xfff;
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync unsigned idxPage = 0;
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync paPageDesc = (PGMMSHAREDPAGEDESC)RTMemAlloc((cbRegion >> PAGE_SHIFT) * sizeof(*paPageDesc));
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync rc = PGMGstGetPage(pVCpu, GCRegion, &fFlags, &GCPhys);
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync && !(fFlags & X86_PTE_RW)) /* important as we make assumptions about this below! */
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync PPGMPAGE pPage = pgmPhysGetPage(&pVM->pgm.s, GCPhys);
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync paPageDesc[idxPage].uHCPhysPageId = PGM_PAGE_GET_PAGEID(pPage);
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync paPageDesc[idxPage].HCPhys = PGM_PAGE_GET_HCPHYS(pPage);
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync paPageDesc[idxPage].uHCPhysPageId = NIL_GMM_PAGEID;
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync paPageDesc[idxPage].uHCPhysPageId = NIL_GMM_PAGEID;
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync rc = GMMR0SharedModuleCheckRange(pGVM, pModule, idxModule, idxPage, paPageDesc);
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync for (unsigned i = 0; i < idxPage; i++)
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync /* Any change for this page? */
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync /** todo: maybe cache these to prevent the nth lookup. */
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync PPGMPAGE pPage = pgmPhysGetPage(&pVM->pgm.s, paPageDesc[i].GCPhys);
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync /* Should never happen. */
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync Log(("PGMR0SharedModuleCheck: shared page gc virt=%RGv phys %RGp host %RHp->%RHp\n", pModule->aRegions[idxModule].GCRegionAddr + i * PAGE_SIZE, paPageDesc[i].GCPhys, PGM_PAGE_GET_HCPHYS(pPage), paPageDesc[i].HCPhys));
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync if (paPageDesc[i].HCPhys != PGM_PAGE_GET_HCPHYS(pPage))
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync bool fFlush = false;
50fdc90dae026b2086f85b0f028aa63dd6bbe14evboxsync /* Page was replaced by an existing shared version of it; clear all references first. */
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync rc = pgmPoolTrackUpdateGCPhys(pVM, paPageDesc[i].GCPhys, pPage, true /* clear the entries */, &fFlush);
50fdc90dae026b2086f85b0f028aa63dd6bbe14evboxsync Assert(rc == VINF_SUCCESS || (VMCPU_FF_ISSET(pVCpu, VMCPU_FF_PGM_SYNC_CR3) && (pVCpu->pgm.s.fSyncFlags & PGM_SYNC_CLEAR_PGM_POOL)));
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync /* Update the physical address and page id now. */
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync PGM_PAGE_SET_PAGEID(pPage, paPageDesc[i].uHCPhysPageId);
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync /* Invalidate page map TLB entry for this page too. */
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync PGMPhysInvalidatePageMapTLBEntry(pVM, paPageDesc[i].GCPhys);
6f516ad9911d9037a18778742caa955fe362f8ffvboxsync /* else nothing changed (== this page is now a shared page), so no need to flush anything. */