PGMR0SharedPage.cpp revision 652d85a9390f54d4c6eca560340bf67ac1f85c9d
/* $Id$ */
/** @file
* PGM - Page Manager and Monitor, Ring-0.
*/
/*
* Copyright (C) 2007 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_PGM_SHARED
#include "../PGMInternal.h"
#include "../PGMInline.h"
#ifdef VBOX_WITH_PAGE_SHARING
/**
* Check a registered module for shared page changes
*
* @returns The following VBox status codes.
*
* @param pVM The VM handle.
* @param pGVM Pointer to the GVM instance data.
* @param idCpu VCPU id
* @param pModule Module description
* @param cRegions Number of regions
* @param pRegions Region array
*/
VMMR0DECL(int) PGMR0SharedModuleCheck(PVM pVM, PGVM pGVM, VMCPUID idCpu, PGMMSHAREDMODULE pModule, uint32_t cRegions, PGMMSHAREDREGIONDESC pRegions)
{
int rc = VINF_SUCCESS;
uint32_t cbPreviousRegion = 0;
bool fFlushTLBs = false;
Log(("PGMR0SharedModuleCheck: check %s %s base=%RGv size=%x\n", pModule->szName, pModule->szVersion, pModule->Core.Key, pModule->cbModule));
/* Check every region of the shared module. */
{
unsigned idxPage = 0;
bool fValidChanges = false;
if (cbPreviousRegion < cbRegion)
{
if (paPageDesc)
if (!paPageDesc)
{
AssertFailed();
rc = VERR_NO_MEMORY;
goto end;
}
}
while (cbRegion)
{
/** todo: inefficient to fetch each guest page like this... */
if ( rc == VINF_SUCCESS
{
if ( pPage
{
fValidChanges = true;
}
else
}
else
idxPage++;
}
if (fValidChanges)
{
if (RT_FAILURE(rc))
break;
for (unsigned i = 0; i < idxPage; i++)
{
/* Any change for this page? */
{
/** todo: maybe cache these to prevent the nth lookup. */
if (!pPage)
{
/* Should never happen. */
AssertFailed();
goto end;
}
Log(("PGMR0SharedModuleCheck: shared page gc virt=%RGv phys %RGp host %RHp->%RHp\n", pRegions[idxRegion].GCRegionAddr + i * PAGE_SIZE, paPageDesc[i].GCPhys, PGM_PAGE_GET_HCPHYS(pPage), paPageDesc[i].HCPhys));
{
bool fFlush = false;
/* Page was replaced by an existing shared version of it; clear all references first. */
rc = pgmPoolTrackUpdateGCPhys(pVM, paPageDesc[i].GCPhys, pPage, true /* clear the entries */, &fFlush);
if (RT_FAILURE(rc))
{
goto end;
}
Assert(rc == VINF_SUCCESS || (VMCPU_FF_ISSET(pVCpu, VMCPU_FF_PGM_SYNC_CR3) && (pVCpu->pgm.s.fSyncFlags & PGM_SYNC_CLEAR_PGM_POOL)));
if (rc == VINF_SUCCESS)
fFlushTLBs |= fFlush;
/* Update the physical address and page id now. */
/* Invalidate page map TLB entry for this page too. */
}
/* else nothing changed (== this page is now a shared page), so no need to flush anything. */
}
}
}
else
}
end:
if (fFlushTLBs)
if (paPageDesc)
return rc;
}
#endif