VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMR0/PGMR0SharedPage.cpp@ 39909

Last change on this file since 39909 was 39909, checked in by vboxsync, 13 years ago

too long lines.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 6.2 KB
Line 
1/* $Id: PGMR0SharedPage.cpp 39909 2012-01-30 15:32:01Z vboxsync $ */
2/** @file
3 * PGM - Page Manager and Monitor, Page Sharing, Ring-0.
4 */
5
6/*
7 * Copyright (C) 2010 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18/*******************************************************************************
19* Header Files *
20*******************************************************************************/
21#define LOG_GROUP LOG_GROUP_PGM_SHARED
22#include <VBox/vmm/pgm.h>
23#include <VBox/vmm/gmm.h>
24#include "PGMInternal.h"
25#include <VBox/vmm/vm.h>
26#include "PGMInline.h"
27#include <VBox/log.h>
28#include <VBox/err.h>
29#include <iprt/assert.h>
30#include <iprt/mem.h>
31
32
33#ifdef VBOX_WITH_PAGE_SHARING
34/**
35 * Check a registered module for shared page changes
36 *
37 * @returns The following VBox status codes.
38 *
39 * @param pVM The VM handle.
40 * @param pGVM Pointer to the GVM instance data.
41 * @param idCpu VCPU id
42 * @param pModule Module description
43 * @param cRegions Number of regions
44 * @param pRegions Region array
45 */
46VMMR0DECL(int) PGMR0SharedModuleCheck(PVM pVM, PGVM pGVM, VMCPUID idCpu, PGMMSHAREDMODULE pModule,
47 uint32_t cRegions, PGMMSHAREDREGIONDESC pRegions)
48{
49 int rc = VINF_SUCCESS;
50 GMMSHAREDPAGEDESC PageDesc;
51 bool fFlushTLBs = false;
52 PVMCPU pVCpu = &pVM->aCpus[idCpu];
53
54 Log(("PGMR0SharedModuleCheck: check %s %s base=%RGv size=%x\n", pModule->szName, pModule->szVersion, pModule->Core.Key, pModule->cbModule));
55
56 PGM_LOCK_ASSERT_OWNER(pVM); /* This cannot fail as we grab the lock in pgmR3SharedModuleRegRendezvous before calling into ring-0. */
57
58 /* Check every region of the shared module. */
59 for (unsigned idxRegion = 0; idxRegion < cRegions; idxRegion++)
60 {
61 Assert((pRegions[idxRegion].cbRegion & 0xfff) == 0);
62 Assert((pRegions[idxRegion].GCRegionAddr & 0xfff) == 0);
63
64 RTGCPTR GCRegion = pRegions[idxRegion].GCRegionAddr;
65 unsigned cbRegion = pRegions[idxRegion].cbRegion & ~0xfff;
66 unsigned idxPage = 0;
67
68 while (cbRegion)
69 {
70 RTGCPHYS GCPhys;
71 uint64_t fFlags;
72
73 /** @todo inefficient to fetch each guest page like this... */
74 rc = PGMGstGetPage(pVCpu, GCRegion, &fFlags, &GCPhys);
75 if ( rc == VINF_SUCCESS
76 && !(fFlags & X86_PTE_RW)) /* important as we make assumptions about this below! */
77 {
78 PPGMPAGE pPage = pgmPhysGetPage(pVM, GCPhys);
79 Assert(!pPage || !PGM_PAGE_IS_BALLOONED(pPage));
80 if ( pPage
81 && PGM_PAGE_GET_STATE(pPage) == PGM_PAGE_STATE_ALLOCATED)
82 {
83 PageDesc.uHCPhysPageId = PGM_PAGE_GET_PAGEID(pPage);
84 PageDesc.HCPhys = PGM_PAGE_GET_HCPHYS(pPage);
85 PageDesc.GCPhys = GCPhys;
86
87 rc = GMMR0SharedModuleCheckPage(pGVM, pModule, idxRegion, idxPage, &PageDesc);
88 if (rc == VINF_SUCCESS)
89 {
90 /* Any change for this page? */
91 if (PageDesc.uHCPhysPageId != NIL_GMM_PAGEID)
92 {
93 Assert(PGM_PAGE_GET_STATE(pPage) == PGM_PAGE_STATE_ALLOCATED);
94
95 Log(("PGMR0SharedModuleCheck: shared page gc virt=%RGv phys %RGp host %RHp->%RHp\n", pRegions[idxRegion].GCRegionAddr + idxPage * PAGE_SIZE, PageDesc.GCPhys, PGM_PAGE_GET_HCPHYS(pPage), PageDesc.HCPhys));
96 if (PageDesc.HCPhys != PGM_PAGE_GET_HCPHYS(pPage))
97 {
98 bool fFlush = false;
99
100 /* Page was replaced by an existing shared version of it; clear all references first. */
101 rc = pgmPoolTrackUpdateGCPhys(pVM, PageDesc.GCPhys, pPage, true /* clear the entries */, &fFlush);
102 Assert(rc == VINF_SUCCESS || (VMCPU_FF_ISSET(pVCpu, VMCPU_FF_PGM_SYNC_CR3) && (pVCpu->pgm.s.fSyncFlags & PGM_SYNC_CLEAR_PGM_POOL)));
103 if (rc == VINF_SUCCESS)
104 fFlushTLBs |= fFlush;
105
106 /* Update the physical address and page id now. */
107 PGM_PAGE_SET_HCPHYS(pVM, pPage, PageDesc.HCPhys);
108 PGM_PAGE_SET_PAGEID(pVM, pPage, PageDesc.uHCPhysPageId);
109
110 /* Invalidate page map TLB entry for this page too. */
111 pgmPhysInvalidatePageMapTLBEntry(pVM, PageDesc.GCPhys);
112 pVM->pgm.s.cReusedSharedPages++;
113 }
114 /* else nothing changed (== this page is now a shared page), so no need to flush anything. */
115
116 pVM->pgm.s.cSharedPages++;
117 pVM->pgm.s.cPrivatePages--;
118 PGM_PAGE_SET_STATE(pVM, pPage, PGM_PAGE_STATE_SHARED);
119 }
120 }
121 else
122 break;
123 }
124 }
125 else
126 {
127 Assert( rc == VINF_SUCCESS
128 || rc == VERR_PAGE_NOT_PRESENT
129 || rc == VERR_PAGE_MAP_LEVEL4_NOT_PRESENT
130 || rc == VERR_PAGE_DIRECTORY_PTR_NOT_PRESENT
131 || rc == VERR_PAGE_TABLE_NOT_PRESENT);
132 rc = VINF_SUCCESS; /* ignore error */
133 }
134
135 idxPage++;
136 GCRegion += PAGE_SIZE;
137 cbRegion -= PAGE_SIZE;
138 }
139 }
140
141 if (fFlushTLBs)
142 PGM_INVL_ALL_VCPU_TLBS(pVM);
143
144 return rc;
145}
146#endif /* VBOX_WITH_PAGE_SHARING */
147
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette