VirtualBox

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

Last change on this file since 80333 was 80333, checked in by vboxsync, 5 years ago

VMM: Eliminating the VBOX_BUGREF_9217_PART_I preprocessor macro. bugref:9217

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 7.5 KB
Line 
1/* $Id: PGMR0SharedPage.cpp 80333 2019-08-16 20:28:38Z vboxsync $ */
2/** @file
3 * PGM - Page Manager and Monitor, Page Sharing, Ring-0.
4 */
5
6/*
7 * Copyright (C) 2010-2019 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/*********************************************************************************************************************************
20* Header Files *
21*********************************************************************************************************************************/
22#define LOG_GROUP LOG_GROUP_PGM_SHARED
23#include <VBox/vmm/pgm.h>
24#include <VBox/vmm/gmm.h>
25#include "PGMInternal.h"
26#include <VBox/vmm/vmcc.h>
27#include <VBox/vmm/gvm.h>
28#include "PGMInline.h"
29#include <VBox/log.h>
30#include <VBox/err.h>
31#include <iprt/assert.h>
32#include <iprt/mem.h>
33
34
35#ifdef VBOX_WITH_PAGE_SHARING
36/**
37 * Check a registered module for shared page changes.
38 *
39 * The PGM lock shall be taken prior to calling this method.
40 *
41 * @returns The following VBox status codes.
42 *
43 * @param pVM The cross context VM structure.
44 * @param pGVM Pointer to the GVM instance data.
45 * @param idCpu The ID of the calling virtual CPU.
46 * @param pModule Global module description.
47 * @param paRegionsGCPtrs Array parallel to pModules->aRegions with the
48 * addresses of the regions in the calling
49 * process.
50 */
51VMMR0DECL(int) PGMR0SharedModuleCheck(PVMCC pVM, PGVM pGVM, VMCPUID idCpu, PGMMSHAREDMODULE pModule, PCRTGCPTR64 paRegionsGCPtrs)
52{
53#ifdef VBOX_BUGREF_9217
54 PVMCPUCC pVCpu = &pGVM->aCpus[idCpu];
55#else
56 PVMCPUCC pVCpu = VMCC_GET_CPU(pVM, idCpu);
57#endif
58 int rc = VINF_SUCCESS;
59 bool fFlushTLBs = false;
60 bool fFlushRemTLBs = false;
61 GMMSHAREDPAGEDESC PageDesc;
62
63 Log(("PGMR0SharedModuleCheck: check %s %s base=%RGv size=%x\n", pModule->szName, pModule->szVersion, pModule->Core.Key, pModule->cbModule));
64
65 PGM_LOCK_ASSERT_OWNER(pVM); /* This cannot fail as we grab the lock in pgmR3SharedModuleRegRendezvous before calling into ring-0. */
66
67 /*
68 * Check every region of the shared module.
69 */
70 for (uint32_t idxRegion = 0; idxRegion < pModule->cRegions; idxRegion++)
71 {
72 RTGCPTR GCPtrPage = paRegionsGCPtrs[idxRegion] & ~(RTGCPTR)PAGE_OFFSET_MASK;
73 uint32_t cbLeft = pModule->aRegions[idxRegion].cb; Assert(!(cbLeft & PAGE_OFFSET_MASK));
74 uint32_t idxPage = 0;
75
76 while (cbLeft)
77 {
78 /** @todo inefficient to fetch each guest page like this... */
79 RTGCPHYS GCPhys;
80 uint64_t fFlags;
81 rc = PGMGstGetPage(pVCpu, GCPtrPage, &fFlags, &GCPhys);
82 if ( rc == VINF_SUCCESS
83 && !(fFlags & X86_PTE_RW)) /* important as we make assumptions about this below! */
84 {
85 PPGMPAGE pPage = pgmPhysGetPage(pVM, GCPhys);
86 Assert(!pPage || !PGM_PAGE_IS_BALLOONED(pPage));
87 if ( pPage
88 && PGM_PAGE_GET_STATE(pPage) == PGM_PAGE_STATE_ALLOCATED
89 && PGM_PAGE_GET_READ_LOCKS(pPage) == 0
90 && PGM_PAGE_GET_WRITE_LOCKS(pPage) == 0 )
91 {
92 PageDesc.idPage = PGM_PAGE_GET_PAGEID(pPage);
93 PageDesc.HCPhys = PGM_PAGE_GET_HCPHYS(pPage);
94 PageDesc.GCPhys = GCPhys;
95
96 rc = GMMR0SharedModuleCheckPage(pGVM, pModule, idxRegion, idxPage, &PageDesc);
97 if (RT_FAILURE(rc))
98 break;
99
100 /*
101 * Any change for this page?
102 */
103 if (PageDesc.idPage != NIL_GMM_PAGEID)
104 {
105 Assert(PGM_PAGE_GET_STATE(pPage) == PGM_PAGE_STATE_ALLOCATED);
106
107 Log(("PGMR0SharedModuleCheck: shared page gst virt=%RGv phys=%RGp host %RHp->%RHp\n",
108 GCPtrPage, PageDesc.GCPhys, PGM_PAGE_GET_HCPHYS(pPage), PageDesc.HCPhys));
109
110 /* Page was either replaced by an existing shared
111 version of it or converted into a read-only shared
112 page, so, clear all references. */
113 bool fFlush = false;
114 rc = pgmPoolTrackUpdateGCPhys(pVM, PageDesc.GCPhys, pPage, true /* clear the entries */, &fFlush);
115 Assert( rc == VINF_SUCCESS
116 || ( VMCPU_FF_IS_SET(pVCpu, VMCPU_FF_PGM_SYNC_CR3)
117 && (pVCpu->pgm.s.fSyncFlags & PGM_SYNC_CLEAR_PGM_POOL)));
118 if (rc == VINF_SUCCESS)
119 fFlushTLBs |= fFlush;
120 fFlushRemTLBs = true;
121
122 if (PageDesc.HCPhys != PGM_PAGE_GET_HCPHYS(pPage))
123 {
124 /* Update the physical address and page id now. */
125 PGM_PAGE_SET_HCPHYS(pVM, pPage, PageDesc.HCPhys);
126 PGM_PAGE_SET_PAGEID(pVM, pPage, PageDesc.idPage);
127
128 /* Invalidate page map TLB entry for this page too. */
129 pgmPhysInvalidatePageMapTLBEntry(pVM, PageDesc.GCPhys);
130 pVM->pgm.s.cReusedSharedPages++;
131 }
132 /* else: nothing changed (== this page is now a shared
133 page), so no need to flush anything. */
134
135 pVM->pgm.s.cSharedPages++;
136 pVM->pgm.s.cPrivatePages--;
137 PGM_PAGE_SET_STATE(pVM, pPage, PGM_PAGE_STATE_SHARED);
138
139# ifdef VBOX_STRICT /* check sum hack */
140 pPage->s.u2Unused0 = PageDesc.u32StrictChecksum & 3;
141 //pPage->s.u2Unused1 = (PageDesc.u32StrictChecksum >> 8) & 3;
142# endif
143 }
144 }
145 }
146 else
147 {
148 Assert( rc == VINF_SUCCESS
149 || rc == VERR_PAGE_NOT_PRESENT
150 || rc == VERR_PAGE_MAP_LEVEL4_NOT_PRESENT
151 || rc == VERR_PAGE_DIRECTORY_PTR_NOT_PRESENT
152 || rc == VERR_PAGE_TABLE_NOT_PRESENT);
153 rc = VINF_SUCCESS; /* ignore error */
154 }
155
156 idxPage++;
157 GCPtrPage += PAGE_SIZE;
158 cbLeft -= PAGE_SIZE;
159 }
160 }
161
162 /*
163 * Do TLB flushing if necessary.
164 */
165 if (fFlushTLBs)
166 PGM_INVL_ALL_VCPU_TLBS(pVM);
167
168 if (fFlushRemTLBs)
169#ifdef VBOX_BUGREF_9217
170 for (VMCPUID idCurCpu = 0; idCurCpu < pGVM->cCpus; idCurCpu++)
171 CPUMSetChangedFlags(&pGVM->aCpus[idCurCpu], CPUM_CHANGED_GLOBAL_TLB_FLUSH);
172#else
173 for (VMCPUID idCurCpu = 0; idCurCpu < pVM->cCpus; idCurCpu++)
174 CPUMSetChangedFlags(VMCC_GET_CPU(pVM, idCurCpu), CPUM_CHANGED_GLOBAL_TLB_FLUSH);
175#endif
176
177 return rc;
178}
179#endif /* VBOX_WITH_PAGE_SHARING */
180
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