VirtualBox

source: vbox/trunk/src/VBox/VMM/include/PGMInline.h@ 62489

Last change on this file since 62489 was 62478, checked in by vboxsync, 8 years ago

(C) 2016

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 50.5 KB
Line 
1/* $Id: PGMInline.h 62478 2016-07-22 18:29:06Z vboxsync $ */
2/** @file
3 * PGM - Inlined functions.
4 */
5
6/*
7 * Copyright (C) 2006-2016 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#ifndef ___PGMInline_h
19#define ___PGMInline_h
20
21#include <VBox/cdefs.h>
22#include <VBox/types.h>
23#include <VBox/err.h>
24#include <VBox/vmm/stam.h>
25#include <VBox/param.h>
26#include <VBox/vmm/vmm.h>
27#include <VBox/vmm/mm.h>
28#include <VBox/vmm/pdmcritsect.h>
29#include <VBox/vmm/pdmapi.h>
30#include <VBox/dis.h>
31#include <VBox/vmm/dbgf.h>
32#include <VBox/log.h>
33#include <VBox/vmm/gmm.h>
34#include <VBox/vmm/hm.h>
35#include <iprt/asm.h>
36#include <iprt/assert.h>
37#include <iprt/avl.h>
38#include <iprt/critsect.h>
39#include <iprt/sha.h>
40
41
42
43/** @addtogroup grp_pgm_int Internals
44 * @internal
45 * @{
46 */
47
48/**
49 * Gets the PGMRAMRANGE structure for a guest page.
50 *
51 * @returns Pointer to the RAM range on success.
52 * @returns NULL on a VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS condition.
53 *
54 * @param pVM The cross context VM structure.
55 * @param GCPhys The GC physical address.
56 */
57DECLINLINE(PPGMRAMRANGE) pgmPhysGetRange(PVM pVM, RTGCPHYS GCPhys)
58{
59 PPGMRAMRANGE pRam = pVM->pgm.s.CTX_SUFF(apRamRangesTlb)[PGM_RAMRANGE_TLB_IDX(GCPhys)];
60 if (!pRam || GCPhys - pRam->GCPhys >= pRam->cb)
61 pRam = pgmPhysGetRangeSlow(pVM, GCPhys);
62 STAM_COUNTER_INC(&pVM->pgm.s.CTX_SUFF(pStats)->CTX_MID_Z(Stat,RamRangeTlbHits));
63 return pRam;
64}
65
66
67/**
68 * Gets the PGMRAMRANGE structure for a guest page, if unassigned get the ram
69 * range above it.
70 *
71 * @returns Pointer to the RAM range on success.
72 * @returns NULL if the address is located after the last range.
73 *
74 * @param pVM The cross context VM structure.
75 * @param GCPhys The GC physical address.
76 */
77DECLINLINE(PPGMRAMRANGE) pgmPhysGetRangeAtOrAbove(PVM pVM, RTGCPHYS GCPhys)
78{
79 PPGMRAMRANGE pRam = pVM->pgm.s.CTX_SUFF(apRamRangesTlb)[PGM_RAMRANGE_TLB_IDX(GCPhys)];
80 if ( !pRam
81 || (GCPhys - pRam->GCPhys) >= pRam->cb)
82 return pgmPhysGetRangeAtOrAboveSlow(pVM, GCPhys);
83 STAM_COUNTER_INC(&pVM->pgm.s.CTX_SUFF(pStats)->CTX_MID_Z(Stat,RamRangeTlbHits));
84 return pRam;
85}
86
87
88/**
89 * Gets the PGMPAGE structure for a guest page.
90 *
91 * @returns Pointer to the page on success.
92 * @returns NULL on a VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS condition.
93 *
94 * @param pVM The cross context VM structure.
95 * @param GCPhys The GC physical address.
96 */
97DECLINLINE(PPGMPAGE) pgmPhysGetPage(PVM pVM, RTGCPHYS GCPhys)
98{
99 PPGMRAMRANGE pRam = pVM->pgm.s.CTX_SUFF(apRamRangesTlb)[PGM_RAMRANGE_TLB_IDX(GCPhys)];
100 RTGCPHYS off;
101 if ( !pRam
102 || (off = GCPhys - pRam->GCPhys) >= pRam->cb)
103 return pgmPhysGetPageSlow(pVM, GCPhys);
104 STAM_COUNTER_INC(&pVM->pgm.s.CTX_SUFF(pStats)->CTX_MID_Z(Stat,RamRangeTlbHits));
105 return &pRam->aPages[off >> PAGE_SHIFT];
106}
107
108
109/**
110 * Gets the PGMPAGE structure for a guest page.
111 *
112 * Old Phys code: Will make sure the page is present.
113 *
114 * @returns VBox status code.
115 * @retval VINF_SUCCESS and a valid *ppPage on success.
116 * @retval VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS if the address isn't valid.
117 *
118 * @param pVM The cross context VM structure.
119 * @param GCPhys The GC physical address.
120 * @param ppPage Where to store the page pointer on success.
121 */
122DECLINLINE(int) pgmPhysGetPageEx(PVM pVM, RTGCPHYS GCPhys, PPPGMPAGE ppPage)
123{
124 PPGMRAMRANGE pRam = pVM->pgm.s.CTX_SUFF(apRamRangesTlb)[PGM_RAMRANGE_TLB_IDX(GCPhys)];
125 RTGCPHYS off;
126 if ( !pRam
127 || (off = GCPhys - pRam->GCPhys) >= pRam->cb)
128 return pgmPhysGetPageExSlow(pVM, GCPhys, ppPage);
129 *ppPage = &pRam->aPages[(GCPhys - pRam->GCPhys) >> PAGE_SHIFT];
130 STAM_COUNTER_INC(&pVM->pgm.s.CTX_SUFF(pStats)->CTX_MID_Z(Stat,RamRangeTlbHits));
131 return VINF_SUCCESS;
132}
133
134
135/**
136 * Gets the PGMPAGE structure for a guest page.
137 *
138 * Old Phys code: Will make sure the page is present.
139 *
140 * @returns VBox status code.
141 * @retval VINF_SUCCESS and a valid *ppPage on success.
142 * @retval VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS if the address isn't valid.
143 *
144 * @param pVM The cross context VM structure.
145 * @param GCPhys The GC physical address.
146 * @param ppPage Where to store the page pointer on success.
147 * @param ppRamHint Where to read and store the ram list hint.
148 * The caller initializes this to NULL before the call.
149 */
150DECLINLINE(int) pgmPhysGetPageWithHintEx(PVM pVM, RTGCPHYS GCPhys, PPPGMPAGE ppPage, PPGMRAMRANGE *ppRamHint)
151{
152 RTGCPHYS off;
153 PPGMRAMRANGE pRam = *ppRamHint;
154 if ( !pRam
155 || RT_UNLIKELY((off = GCPhys - pRam->GCPhys) >= pRam->cb))
156 {
157 pRam = pVM->pgm.s.CTX_SUFF(apRamRangesTlb)[PGM_RAMRANGE_TLB_IDX(GCPhys)];
158 if ( !pRam
159 || (off = GCPhys - pRam->GCPhys) >= pRam->cb)
160 return pgmPhysGetPageAndRangeExSlow(pVM, GCPhys, ppPage, ppRamHint);
161
162 STAM_COUNTER_INC(&pVM->pgm.s.CTX_SUFF(pStats)->CTX_MID_Z(Stat,RamRangeTlbHits));
163 *ppRamHint = pRam;
164 }
165 *ppPage = &pRam->aPages[off >> PAGE_SHIFT];
166 return VINF_SUCCESS;
167}
168
169
170/**
171 * Gets the PGMPAGE structure for a guest page together with the PGMRAMRANGE.
172 *
173 * @returns Pointer to the page on success.
174 * @returns NULL on a VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS condition.
175 *
176 * @param pVM The cross context VM structure.
177 * @param GCPhys The GC physical address.
178 * @param ppPage Where to store the pointer to the PGMPAGE structure.
179 * @param ppRam Where to store the pointer to the PGMRAMRANGE structure.
180 */
181DECLINLINE(int) pgmPhysGetPageAndRangeEx(PVM pVM, RTGCPHYS GCPhys, PPPGMPAGE ppPage, PPGMRAMRANGE *ppRam)
182{
183 PPGMRAMRANGE pRam = pVM->pgm.s.CTX_SUFF(apRamRangesTlb)[PGM_RAMRANGE_TLB_IDX(GCPhys)];
184 RTGCPHYS off;
185 if ( !pRam
186 || (off = GCPhys - pRam->GCPhys) >= pRam->cb)
187 return pgmPhysGetPageAndRangeExSlow(pVM, GCPhys, ppPage, ppRam);
188
189 STAM_COUNTER_INC(&pVM->pgm.s.CTX_SUFF(pStats)->CTX_MID_Z(Stat,RamRangeTlbHits));
190 *ppRam = pRam;
191 *ppPage = &pRam->aPages[off >> PAGE_SHIFT];
192 return VINF_SUCCESS;
193}
194
195
196/**
197 * Convert GC Phys to HC Phys.
198 *
199 * @returns VBox status code.
200 * @param pVM The cross context VM structure.
201 * @param GCPhys The GC physical address.
202 * @param pHCPhys Where to store the corresponding HC physical address.
203 *
204 * @deprecated Doesn't deal with zero, shared or write monitored pages.
205 * Avoid when writing new code!
206 */
207DECLINLINE(int) pgmRamGCPhys2HCPhys(PVM pVM, RTGCPHYS GCPhys, PRTHCPHYS pHCPhys)
208{
209 PPGMPAGE pPage;
210 int rc = pgmPhysGetPageEx(pVM, GCPhys, &pPage);
211 if (RT_FAILURE(rc))
212 return rc;
213 *pHCPhys = PGM_PAGE_GET_HCPHYS(pPage) | (GCPhys & PAGE_OFFSET_MASK);
214 return VINF_SUCCESS;
215}
216
217#if defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0) || defined(IN_RC)
218
219/**
220 * Inlined version of the ring-0 version of the host page mapping code
221 * that optimizes access to pages already in the set.
222 *
223 * @returns VINF_SUCCESS. Will bail out to ring-3 on failure.
224 * @param pVCpu The cross context virtual CPU structure.
225 * @param HCPhys The physical address of the page.
226 * @param ppv Where to store the mapping address.
227 * @param SRC_POS The source location of the caller.
228 */
229DECLINLINE(int) pgmRZDynMapHCPageInlined(PVMCPU pVCpu, RTHCPHYS HCPhys, void **ppv RTLOG_COMMA_SRC_POS_DECL)
230{
231 PPGMMAPSET pSet = &pVCpu->pgm.s.AutoSet;
232
233 STAM_PROFILE_START(&pVCpu->pgm.s.CTX_SUFF(pStats)->StatRZDynMapHCPageInl, a);
234 Assert(!(HCPhys & PAGE_OFFSET_MASK));
235 Assert(pSet->cEntries <= RT_ELEMENTS(pSet->aEntries));
236
237 unsigned iHash = PGMMAPSET_HASH(HCPhys);
238 unsigned iEntry = pSet->aiHashTable[iHash];
239 if ( iEntry < pSet->cEntries
240 && pSet->aEntries[iEntry].HCPhys == HCPhys
241 && pSet->aEntries[iEntry].cInlinedRefs < UINT16_MAX - 1)
242 {
243 pSet->aEntries[iEntry].cInlinedRefs++;
244 *ppv = pSet->aEntries[iEntry].pvPage;
245 STAM_COUNTER_INC(&pVCpu->pgm.s.CTX_SUFF(pStats)->StatRZDynMapHCPageInlHits);
246 }
247 else
248 {
249 STAM_COUNTER_INC(&pVCpu->pgm.s.CTX_SUFF(pStats)->StatRZDynMapHCPageInlMisses);
250 pgmRZDynMapHCPageCommon(pSet, HCPhys, ppv RTLOG_COMMA_SRC_POS_ARGS);
251 }
252
253 STAM_PROFILE_STOP(&pVCpu->pgm.s.CTX_SUFF(pStats)->StatRZDynMapHCPageInl, a);
254 return VINF_SUCCESS;
255}
256
257
258/**
259 * Inlined version of the guest page mapping code that optimizes access to pages
260 * already in the set.
261 *
262 * @returns VBox status code, see pgmRZDynMapGCPageCommon for details.
263 * @param pVM The cross context VM structure.
264 * @param pVCpu The cross context virtual CPU structure.
265 * @param GCPhys The guest physical address of the page.
266 * @param ppv Where to store the mapping address.
267 * @param SRC_POS The source location of the caller.
268 */
269DECLINLINE(int) pgmRZDynMapGCPageV2Inlined(PVM pVM, PVMCPU pVCpu, RTGCPHYS GCPhys, void **ppv RTLOG_COMMA_SRC_POS_DECL)
270{
271 STAM_PROFILE_START(&pVCpu->pgm.s.CTX_SUFF(pStats)->StatRZDynMapGCPageInl, a);
272 AssertMsg(!(GCPhys & PAGE_OFFSET_MASK), ("%RGp\n", GCPhys));
273
274 /*
275 * Get the ram range.
276 */
277 PPGMRAMRANGE pRam = pVM->pgm.s.CTX_SUFF(apRamRangesTlb)[PGM_RAMRANGE_TLB_IDX(GCPhys)];
278 RTGCPHYS off;
279 if ( !pRam
280 || (off = GCPhys - pRam->GCPhys) >= pRam->cb
281 /** @todo || page state stuff */
282 )
283 {
284 /* This case is not counted into StatRZDynMapGCPageInl. */
285 STAM_COUNTER_INC(&pVCpu->pgm.s.CTX_SUFF(pStats)->StatRZDynMapGCPageInlRamMisses);
286 return pgmRZDynMapGCPageCommon(pVM, pVCpu, GCPhys, ppv RTLOG_COMMA_SRC_POS_ARGS);
287 }
288
289 RTHCPHYS HCPhys = PGM_PAGE_GET_HCPHYS(&pRam->aPages[off >> PAGE_SHIFT]);
290 STAM_COUNTER_INC(&pVCpu->pgm.s.CTX_SUFF(pStats)->StatRZDynMapGCPageInlRamHits);
291
292 /*
293 * pgmRZDynMapHCPageInlined with out stats.
294 */
295 PPGMMAPSET pSet = &pVCpu->pgm.s.AutoSet;
296 Assert(!(HCPhys & PAGE_OFFSET_MASK));
297 Assert(pSet->cEntries <= RT_ELEMENTS(pSet->aEntries));
298
299 unsigned iHash = PGMMAPSET_HASH(HCPhys);
300 unsigned iEntry = pSet->aiHashTable[iHash];
301 if ( iEntry < pSet->cEntries
302 && pSet->aEntries[iEntry].HCPhys == HCPhys
303 && pSet->aEntries[iEntry].cInlinedRefs < UINT16_MAX - 1)
304 {
305 pSet->aEntries[iEntry].cInlinedRefs++;
306 *ppv = pSet->aEntries[iEntry].pvPage;
307 STAM_COUNTER_INC(&pVCpu->pgm.s.CTX_SUFF(pStats)->StatRZDynMapGCPageInlHits);
308 }
309 else
310 {
311 STAM_COUNTER_INC(&pVCpu->pgm.s.CTX_SUFF(pStats)->StatRZDynMapGCPageInlMisses);
312 pgmRZDynMapHCPageCommon(pSet, HCPhys, ppv RTLOG_COMMA_SRC_POS_ARGS);
313 }
314
315 STAM_PROFILE_STOP(&pVCpu->pgm.s.CTX_SUFF(pStats)->StatRZDynMapGCPageInl, a);
316 return VINF_SUCCESS;
317}
318
319
320/**
321 * Inlined version of the ring-0 version of guest page mapping that optimizes
322 * access to pages already in the set.
323 *
324 * @returns VBox status code, see pgmRZDynMapGCPageCommon for details.
325 * @param pVCpu The cross context virtual CPU structure.
326 * @param GCPhys The guest physical address of the page.
327 * @param ppv Where to store the mapping address.
328 * @param SRC_POS The source location of the caller.
329 */
330DECLINLINE(int) pgmRZDynMapGCPageInlined(PVMCPU pVCpu, RTGCPHYS GCPhys, void **ppv RTLOG_COMMA_SRC_POS_DECL)
331{
332 return pgmRZDynMapGCPageV2Inlined(pVCpu->CTX_SUFF(pVM), pVCpu, GCPhys, ppv RTLOG_COMMA_SRC_POS_ARGS);
333}
334
335
336/**
337 * Inlined version of the ring-0 version of the guest byte mapping code
338 * that optimizes access to pages already in the set.
339 *
340 * @returns VBox status code, see pgmRZDynMapGCPageCommon for details.
341 * @param pVCpu The cross context virtual CPU structure.
342 * @param GCPhys The guest physical address of the page.
343 * @param ppv Where to store the mapping address. The offset is
344 * preserved.
345 * @param SRC_POS The source location of the caller.
346 */
347DECLINLINE(int) pgmRZDynMapGCPageOffInlined(PVMCPU pVCpu, RTGCPHYS GCPhys, void **ppv RTLOG_COMMA_SRC_POS_DECL)
348{
349 STAM_PROFILE_START(&pVCpu->pgm.s.StatRZDynMapGCPageInl, a);
350
351 /*
352 * Get the ram range.
353 */
354 PVM pVM = pVCpu->CTX_SUFF(pVM);
355 PPGMRAMRANGE pRam = pVM->pgm.s.CTX_SUFF(apRamRangesTlb)[PGM_RAMRANGE_TLB_IDX(GCPhys)];
356 RTGCPHYS off;
357 if ( !pRam
358 || (off = GCPhys - pRam->GCPhys) >= pRam->cb
359 /** @todo || page state stuff */
360 )
361 {
362 /* This case is not counted into StatRZDynMapGCPageInl. */
363 STAM_COUNTER_INC(&pVCpu->pgm.s.CTX_SUFF(pStats)->StatRZDynMapGCPageInlRamMisses);
364 return pgmRZDynMapGCPageCommon(pVM, pVCpu, GCPhys, ppv RTLOG_COMMA_SRC_POS_ARGS);
365 }
366
367 RTHCPHYS HCPhys = PGM_PAGE_GET_HCPHYS(&pRam->aPages[off >> PAGE_SHIFT]);
368 STAM_COUNTER_INC(&pVCpu->pgm.s.CTX_SUFF(pStats)->StatRZDynMapGCPageInlRamHits);
369
370 /*
371 * pgmRZDynMapHCPageInlined with out stats.
372 */
373 PPGMMAPSET pSet = &pVCpu->pgm.s.AutoSet;
374 Assert(!(HCPhys & PAGE_OFFSET_MASK));
375 Assert(pSet->cEntries <= RT_ELEMENTS(pSet->aEntries));
376
377 unsigned iHash = PGMMAPSET_HASH(HCPhys);
378 unsigned iEntry = pSet->aiHashTable[iHash];
379 if ( iEntry < pSet->cEntries
380 && pSet->aEntries[iEntry].HCPhys == HCPhys
381 && pSet->aEntries[iEntry].cInlinedRefs < UINT16_MAX - 1)
382 {
383 STAM_COUNTER_INC(&pVCpu->pgm.s.CTX_SUFF(pStats)->StatRZDynMapGCPageInlHits);
384 pSet->aEntries[iEntry].cInlinedRefs++;
385 *ppv = (void *)((uintptr_t)pSet->aEntries[iEntry].pvPage | (PAGE_OFFSET_MASK & (uintptr_t)GCPhys));
386 }
387 else
388 {
389 STAM_COUNTER_INC(&pVCpu->pgm.s.CTX_SUFF(pStats)->StatRZDynMapGCPageInlMisses);
390 pgmRZDynMapHCPageCommon(pSet, HCPhys, ppv RTLOG_COMMA_SRC_POS_ARGS);
391 *ppv = (void *)((uintptr_t)*ppv | (PAGE_OFFSET_MASK & (uintptr_t)GCPhys));
392 }
393
394 STAM_PROFILE_STOP(&pVCpu->pgm.s.CTX_SUFF(pStats)->StatRZDynMapGCPageInl, a);
395 return VINF_SUCCESS;
396}
397
398#endif /* VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0 */
399#if defined(IN_RC) || defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0)
400
401/**
402 * Maps the page into current context (RC and maybe R0).
403 *
404 * @returns pointer to the mapping.
405 * @param pVM The cross context VM structure.
406 * @param pPage The page.
407 * @param SRC_POS The source location of the caller.
408 */
409DECLINLINE(void *) pgmPoolMapPageInlined(PVM pVM, PPGMPOOLPAGE pPage RTLOG_COMMA_SRC_POS_DECL)
410{
411 if (pPage->idx >= PGMPOOL_IDX_FIRST)
412 {
413 Assert(pPage->idx < pVM->pgm.s.CTX_SUFF(pPool)->cCurPages);
414 void *pv;
415 pgmRZDynMapHCPageInlined(VMMGetCpu(pVM), pPage->Core.Key, &pv RTLOG_COMMA_SRC_POS_ARGS);
416 return pv;
417 }
418 AssertFatalMsgFailed(("pgmPoolMapPageInlined invalid page index %x\n", pPage->idx));
419}
420
421
422/**
423 * Maps the page into current context (RC and maybe R0).
424 *
425 * @returns pointer to the mapping.
426 * @param pVM The cross context VM structure.
427 * @param pVCpu The cross context virtual CPU structure.
428 * @param pPage The page.
429 * @param SRC_POS The source location of the caller.
430 */
431DECLINLINE(void *) pgmPoolMapPageV2Inlined(PVM pVM, PVMCPU pVCpu, PPGMPOOLPAGE pPage RTLOG_COMMA_SRC_POS_DECL)
432{
433 if (pPage->idx >= PGMPOOL_IDX_FIRST)
434 {
435 Assert(pPage->idx < pVM->pgm.s.CTX_SUFF(pPool)->cCurPages);
436 void *pv;
437 Assert(pVCpu == VMMGetCpu(pVM));
438 pgmRZDynMapHCPageInlined(pVCpu, pPage->Core.Key, &pv RTLOG_COMMA_SRC_POS_ARGS);
439 return pv;
440 }
441 AssertFatalMsgFailed(("pgmPoolMapPageV2Inlined invalid page index %x\n", pPage->idx));
442}
443
444#endif /* VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0 || IN_RC */
445#ifndef IN_RC
446
447/**
448 * Queries the Physical TLB entry for a physical guest page,
449 * attempting to load the TLB entry if necessary.
450 *
451 * @returns VBox status code.
452 * @retval VINF_SUCCESS on success
453 * @retval VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS if it's not a valid physical address.
454 *
455 * @param pVM The cross context VM structure.
456 * @param GCPhys The address of the guest page.
457 * @param ppTlbe Where to store the pointer to the TLB entry.
458 */
459DECLINLINE(int) pgmPhysPageQueryTlbe(PVM pVM, RTGCPHYS GCPhys, PPPGMPAGEMAPTLBE ppTlbe)
460{
461 int rc;
462 PPGMPAGEMAPTLBE pTlbe = &pVM->pgm.s.CTXSUFF(PhysTlb).aEntries[PGM_PAGEMAPTLB_IDX(GCPhys)];
463 if (pTlbe->GCPhys == (GCPhys & X86_PTE_PAE_PG_MASK))
464 {
465 STAM_COUNTER_INC(&pVM->pgm.s.CTX_SUFF(pStats)->CTX_MID_Z(Stat,PageMapTlbHits));
466 rc = VINF_SUCCESS;
467 }
468 else
469 rc = pgmPhysPageLoadIntoTlb(pVM, GCPhys);
470 *ppTlbe = pTlbe;
471 return rc;
472}
473
474
475/**
476 * Queries the Physical TLB entry for a physical guest page,
477 * attempting to load the TLB entry if necessary.
478 *
479 * @returns VBox status code.
480 * @retval VINF_SUCCESS on success
481 * @retval VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS if it's not a valid physical address.
482 *
483 * @param pVM The cross context VM structure.
484 * @param pPage Pointer to the PGMPAGE structure corresponding to
485 * GCPhys.
486 * @param GCPhys The address of the guest page.
487 * @param ppTlbe Where to store the pointer to the TLB entry.
488 */
489DECLINLINE(int) pgmPhysPageQueryTlbeWithPage(PVM pVM, PPGMPAGE pPage, RTGCPHYS GCPhys, PPPGMPAGEMAPTLBE ppTlbe)
490{
491 int rc;
492 PPGMPAGEMAPTLBE pTlbe = &pVM->pgm.s.CTXSUFF(PhysTlb).aEntries[PGM_PAGEMAPTLB_IDX(GCPhys)];
493 if (pTlbe->GCPhys == (GCPhys & X86_PTE_PAE_PG_MASK))
494 {
495 STAM_COUNTER_INC(&pVM->pgm.s.CTX_SUFF(pStats)->CTX_MID_Z(Stat,PageMapTlbHits));
496 rc = VINF_SUCCESS;
497# if 0 //def VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
498# ifdef IN_RING3
499 if (pTlbe->pv == (void *)pVM->pgm.s.pvZeroPgR0)
500# else
501 if (pTlbe->pv == (void *)pVM->pgm.s.pvZeroPgR3)
502# endif
503 pTlbe->pv = pVM->pgm.s.CTX_SUFF(pvZeroPg);
504# endif
505 AssertPtr(pTlbe->pv);
506# ifndef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
507 Assert(!pTlbe->pMap || RT_VALID_PTR(pTlbe->pMap->pv));
508# endif
509 }
510 else
511 rc = pgmPhysPageLoadIntoTlbWithPage(pVM, pPage, GCPhys);
512 *ppTlbe = pTlbe;
513 return rc;
514}
515
516#endif /* !IN_RC */
517
518/**
519 * Enables write monitoring for an allocated page.
520 *
521 * The caller is responsible for updating the shadow page tables.
522 *
523 * @param pVM The cross context VM structure.
524 * @param pPage The page to write monitor.
525 * @param GCPhysPage The address of the page.
526 */
527DECLINLINE(void) pgmPhysPageWriteMonitor(PVM pVM, PPGMPAGE pPage, RTGCPHYS GCPhysPage)
528{
529 Assert(PGM_PAGE_GET_STATE(pPage) == PGM_PAGE_STATE_ALLOCATED);
530 PGM_LOCK_ASSERT_OWNER(pVM);
531
532 PGM_PAGE_SET_STATE(pVM, pPage, PGM_PAGE_STATE_WRITE_MONITORED);
533 pVM->pgm.s.cMonitoredPages++;
534
535 /* Large pages must disabled. */
536 if (PGM_PAGE_GET_PDE_TYPE(pPage) == PGM_PAGE_PDE_TYPE_PDE)
537 {
538 PPGMPAGE pFirstPage = pgmPhysGetPage(pVM, GCPhysPage & X86_PDE2M_PAE_PG_MASK);
539 AssertFatal(pFirstPage);
540 if (PGM_PAGE_GET_PDE_TYPE(pFirstPage) == PGM_PAGE_PDE_TYPE_PDE)
541 {
542 PGM_PAGE_SET_PDE_TYPE(pVM, pFirstPage, PGM_PAGE_PDE_TYPE_PDE_DISABLED);
543 pVM->pgm.s.cLargePagesDisabled++;
544 }
545 else
546 Assert(PGM_PAGE_GET_PDE_TYPE(pFirstPage) == PGM_PAGE_PDE_TYPE_PDE_DISABLED);
547 }
548}
549
550
551/**
552 * Checks if the no-execute (NX) feature is active (EFER.NXE=1).
553 *
554 * Only used when the guest is in PAE or long mode. This is inlined so that we
555 * can perform consistency checks in debug builds.
556 *
557 * @returns true if it is, false if it isn't.
558 * @param pVCpu The cross context virtual CPU structure.
559 */
560DECL_FORCE_INLINE(bool) pgmGstIsNoExecuteActive(PVMCPU pVCpu)
561{
562 Assert(pVCpu->pgm.s.fNoExecuteEnabled == CPUMIsGuestNXEnabled(pVCpu));
563 Assert(CPUMIsGuestInPAEMode(pVCpu) || CPUMIsGuestInLongMode(pVCpu));
564 return pVCpu->pgm.s.fNoExecuteEnabled;
565}
566
567
568/**
569 * Checks if the page size extension (PSE) is currently enabled (CR4.PSE=1).
570 *
571 * Only used when the guest is in paged 32-bit mode. This is inlined so that
572 * we can perform consistency checks in debug builds.
573 *
574 * @returns true if it is, false if it isn't.
575 * @param pVCpu The cross context virtual CPU structure.
576 */
577DECL_FORCE_INLINE(bool) pgmGst32BitIsPageSizeExtActive(PVMCPU pVCpu)
578{
579 Assert(pVCpu->pgm.s.fGst32BitPageSizeExtension == CPUMIsGuestPageSizeExtEnabled(pVCpu));
580 Assert(!CPUMIsGuestInPAEMode(pVCpu));
581 Assert(!CPUMIsGuestInLongMode(pVCpu));
582 return pVCpu->pgm.s.fGst32BitPageSizeExtension;
583}
584
585
586/**
587 * Calculated the guest physical address of the large (4 MB) page in 32 bits paging mode.
588 * Takes PSE-36 into account.
589 *
590 * @returns guest physical address
591 * @param pVM The cross context VM structure.
592 * @param Pde Guest Pde
593 */
594DECLINLINE(RTGCPHYS) pgmGstGet4MBPhysPage(PVM pVM, X86PDE Pde)
595{
596 RTGCPHYS GCPhys = Pde.u & X86_PDE4M_PG_MASK;
597 GCPhys |= (RTGCPHYS)Pde.b.u8PageNoHigh << 32;
598
599 return GCPhys & pVM->pgm.s.GCPhys4MBPSEMask;
600}
601
602
603/**
604 * Gets the address the guest page directory (32-bit paging).
605 *
606 * @returns VBox status code.
607 * @param pVCpu The cross context virtual CPU structure.
608 * @param ppPd Where to return the mapping. This is always set.
609 */
610DECLINLINE(int) pgmGstGet32bitPDPtrEx(PVMCPU pVCpu, PX86PD *ppPd)
611{
612#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
613 int rc = pgmRZDynMapGCPageInlined(pVCpu, pVCpu->pgm.s.GCPhysCR3, (void **)ppPd RTLOG_COMMA_SRC_POS);
614 if (RT_FAILURE(rc))
615 {
616 *ppPd = NULL;
617 return rc;
618 }
619#else
620 *ppPd = pVCpu->pgm.s.CTX_SUFF(pGst32BitPd);
621 if (RT_UNLIKELY(!*ppPd))
622 return pgmGstLazyMap32BitPD(pVCpu, ppPd);
623#endif
624 return VINF_SUCCESS;
625}
626
627
628/**
629 * Gets the address the guest page directory (32-bit paging).
630 *
631 * @returns Pointer to the page directory entry in question.
632 * @param pVCpu The cross context virtual CPU structure.
633 */
634DECLINLINE(PX86PD) pgmGstGet32bitPDPtr(PVMCPU pVCpu)
635{
636#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
637 PX86PD pGuestPD = NULL;
638 int rc = pgmRZDynMapGCPageInlined(pVCpu, pVCpu->pgm.s.GCPhysCR3, (void **)&pGuestPD RTLOG_COMMA_SRC_POS);
639 if (RT_FAILURE(rc))
640 {
641 AssertMsg(rc == VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS, ("%Rrc\n", rc));
642 return NULL;
643 }
644#else
645 PX86PD pGuestPD = pVCpu->pgm.s.CTX_SUFF(pGst32BitPd);
646 if (RT_UNLIKELY(!pGuestPD))
647 {
648 int rc = pgmGstLazyMap32BitPD(pVCpu, &pGuestPD);
649 if (RT_FAILURE(rc))
650 return NULL;
651 }
652#endif
653 return pGuestPD;
654}
655
656
657/**
658 * Gets the guest page directory pointer table.
659 *
660 * @returns VBox status code.
661 * @param pVCpu The cross context virtual CPU structure.
662 * @param ppPdpt Where to return the mapping. This is always set.
663 */
664DECLINLINE(int) pgmGstGetPaePDPTPtrEx(PVMCPU pVCpu, PX86PDPT *ppPdpt)
665{
666#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
667 int rc = pgmRZDynMapGCPageOffInlined(pVCpu, pVCpu->pgm.s.GCPhysCR3, (void **)ppPdpt RTLOG_COMMA_SRC_POS);
668 if (RT_FAILURE(rc))
669 {
670 *ppPdpt = NULL;
671 return rc;
672 }
673#else
674 *ppPdpt = pVCpu->pgm.s.CTX_SUFF(pGstPaePdpt);
675 if (RT_UNLIKELY(!*ppPdpt))
676 return pgmGstLazyMapPaePDPT(pVCpu, ppPdpt);
677#endif
678 return VINF_SUCCESS;
679}
680
681
682/**
683 * Gets the guest page directory pointer table.
684 *
685 * @returns Pointer to the page directory in question.
686 * @returns NULL if the page directory is not present or on an invalid page.
687 * @param pVCpu The cross context virtual CPU structure.
688 */
689DECLINLINE(PX86PDPT) pgmGstGetPaePDPTPtr(PVMCPU pVCpu)
690{
691 PX86PDPT pGuestPdpt;
692 int rc = pgmGstGetPaePDPTPtrEx(pVCpu, &pGuestPdpt);
693 AssertMsg(RT_SUCCESS(rc) || rc == VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS, ("%Rrc\n", rc)); NOREF(rc);
694 return pGuestPdpt;
695}
696
697
698/**
699 * Gets the guest page directory pointer table entry for the specified address.
700 *
701 * @returns Pointer to the page directory in question.
702 * @returns NULL if the page directory is not present or on an invalid page.
703 * @param pVCpu The cross context virtual CPU structure.
704 * @param GCPtr The address.
705 */
706DECLINLINE(PX86PDPE) pgmGstGetPaePDPEPtr(PVMCPU pVCpu, RTGCPTR GCPtr)
707{
708 AssertGCPtr32(GCPtr);
709
710#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
711 PX86PDPT pGuestPDPT = NULL;
712 int rc = pgmRZDynMapGCPageOffInlined(pVCpu, pVCpu->pgm.s.GCPhysCR3, (void **)&pGuestPDPT RTLOG_COMMA_SRC_POS);
713 AssertRCReturn(rc, NULL);
714#else
715 PX86PDPT pGuestPDPT = pVCpu->pgm.s.CTX_SUFF(pGstPaePdpt);
716 if (RT_UNLIKELY(!pGuestPDPT))
717 {
718 int rc = pgmGstLazyMapPaePDPT(pVCpu, &pGuestPDPT);
719 if (RT_FAILURE(rc))
720 return NULL;
721 }
722#endif
723 return &pGuestPDPT->a[(GCPtr >> X86_PDPT_SHIFT) & X86_PDPT_MASK_PAE];
724}
725
726
727/**
728 * Gets the page directory entry for the specified address.
729 *
730 * @returns The page directory entry in question.
731 * @returns A non-present entry if the page directory is not present or on an invalid page.
732 * @param pVCpu The cross context virtual CPU structure of the calling EMT.
733 * @param GCPtr The address.
734 */
735DECLINLINE(X86PDEPAE) pgmGstGetPaePDE(PVMCPU pVCpu, RTGCPTR GCPtr)
736{
737 AssertGCPtr32(GCPtr);
738 PX86PDPT pGuestPDPT = pgmGstGetPaePDPTPtr(pVCpu);
739 if (RT_LIKELY(pGuestPDPT))
740 {
741 const unsigned iPdpt = (GCPtr >> X86_PDPT_SHIFT) & X86_PDPT_MASK_PAE;
742 if ( pGuestPDPT->a[iPdpt].n.u1Present
743 && !(pGuestPDPT->a[iPdpt].u & pVCpu->pgm.s.fGstPaeMbzPdpeMask) )
744 {
745 const unsigned iPD = (GCPtr >> X86_PD_PAE_SHIFT) & X86_PD_PAE_MASK;
746#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
747 PX86PDPAE pGuestPD = NULL;
748 int rc = pgmRZDynMapGCPageInlined(pVCpu,
749 pGuestPDPT->a[iPdpt].u & X86_PDPE_PG_MASK,
750 (void **)&pGuestPD
751 RTLOG_COMMA_SRC_POS);
752 if (RT_SUCCESS(rc))
753 return pGuestPD->a[iPD];
754 AssertMsg(rc == VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS, ("%Rrc\n", rc));
755#else
756 PX86PDPAE pGuestPD = pVCpu->pgm.s.CTX_SUFF(apGstPaePDs)[iPdpt];
757 if ( !pGuestPD
758 || (pGuestPDPT->a[iPdpt].u & X86_PDPE_PG_MASK) != pVCpu->pgm.s.aGCPhysGstPaePDs[iPdpt])
759 pgmGstLazyMapPaePD(pVCpu, iPdpt, &pGuestPD);
760 if (pGuestPD)
761 return pGuestPD->a[iPD];
762#endif
763 }
764 }
765
766 X86PDEPAE ZeroPde = {0};
767 return ZeroPde;
768}
769
770
771/**
772 * Gets the page directory pointer table entry for the specified address
773 * and returns the index into the page directory
774 *
775 * @returns Pointer to the page directory in question.
776 * @returns NULL if the page directory is not present or on an invalid page.
777 * @param pVCpu The cross context virtual CPU structure.
778 * @param GCPtr The address.
779 * @param piPD Receives the index into the returned page directory
780 * @param pPdpe Receives the page directory pointer entry. Optional.
781 */
782DECLINLINE(PX86PDPAE) pgmGstGetPaePDPtr(PVMCPU pVCpu, RTGCPTR GCPtr, unsigned *piPD, PX86PDPE pPdpe)
783{
784 AssertGCPtr32(GCPtr);
785
786 /* The PDPE. */
787 PX86PDPT pGuestPDPT = pgmGstGetPaePDPTPtr(pVCpu);
788 if (RT_UNLIKELY(!pGuestPDPT))
789 return NULL;
790 const unsigned iPdpt = (GCPtr >> X86_PDPT_SHIFT) & X86_PDPT_MASK_PAE;
791 if (pPdpe)
792 *pPdpe = pGuestPDPT->a[iPdpt];
793 if (!pGuestPDPT->a[iPdpt].n.u1Present)
794 return NULL;
795 if (RT_UNLIKELY(pVCpu->pgm.s.fGstPaeMbzPdpeMask & pGuestPDPT->a[iPdpt].u))
796 return NULL;
797
798 /* The PDE. */
799#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
800 PX86PDPAE pGuestPD = NULL;
801 int rc = pgmRZDynMapGCPageInlined(pVCpu,
802 pGuestPDPT->a[iPdpt].u & X86_PDPE_PG_MASK,
803 (void **)&pGuestPD
804 RTLOG_COMMA_SRC_POS);
805 if (RT_FAILURE(rc))
806 {
807 AssertMsg(rc == VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS, ("%Rrc\n", rc));
808 return NULL;
809 }
810#else
811 PX86PDPAE pGuestPD = pVCpu->pgm.s.CTX_SUFF(apGstPaePDs)[iPdpt];
812 if ( !pGuestPD
813 || (pGuestPDPT->a[iPdpt].u & X86_PDPE_PG_MASK) != pVCpu->pgm.s.aGCPhysGstPaePDs[iPdpt])
814 pgmGstLazyMapPaePD(pVCpu, iPdpt, &pGuestPD);
815#endif
816
817 *piPD = (GCPtr >> X86_PD_PAE_SHIFT) & X86_PD_PAE_MASK;
818 return pGuestPD;
819}
820
821#ifndef IN_RC
822
823/**
824 * Gets the page map level-4 pointer for the guest.
825 *
826 * @returns VBox status code.
827 * @param pVCpu The cross context virtual CPU structure.
828 * @param ppPml4 Where to return the mapping. Always set.
829 */
830DECLINLINE(int) pgmGstGetLongModePML4PtrEx(PVMCPU pVCpu, PX86PML4 *ppPml4)
831{
832#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
833 int rc = pgmRZDynMapGCPageInlined(pVCpu, pVCpu->pgm.s.GCPhysCR3, (void **)ppPml4 RTLOG_COMMA_SRC_POS);
834 if (RT_FAILURE(rc))
835 {
836 *ppPml4 = NULL;
837 return rc;
838 }
839#else
840 *ppPml4 = pVCpu->pgm.s.CTX_SUFF(pGstAmd64Pml4);
841 if (RT_UNLIKELY(!*ppPml4))
842 return pgmGstLazyMapPml4(pVCpu, ppPml4);
843#endif
844 return VINF_SUCCESS;
845}
846
847
848/**
849 * Gets the page map level-4 pointer for the guest.
850 *
851 * @returns Pointer to the PML4 page.
852 * @param pVCpu The cross context virtual CPU structure.
853 */
854DECLINLINE(PX86PML4) pgmGstGetLongModePML4Ptr(PVMCPU pVCpu)
855{
856 PX86PML4 pGuestPml4;
857 int rc = pgmGstGetLongModePML4PtrEx(pVCpu, &pGuestPml4);
858 AssertMsg(RT_SUCCESS(rc) || rc == VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS, ("%Rrc\n", rc)); NOREF(rc);
859 return pGuestPml4;
860}
861
862
863/**
864 * Gets the pointer to a page map level-4 entry.
865 *
866 * @returns Pointer to the PML4 entry.
867 * @param pVCpu The cross context virtual CPU structure.
868 * @param iPml4 The index.
869 * @remarks Only used by AssertCR3.
870 */
871DECLINLINE(PX86PML4E) pgmGstGetLongModePML4EPtr(PVMCPU pVCpu, unsigned int iPml4)
872{
873#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
874 PX86PML4 pGuestPml4;
875 int rc = pgmRZDynMapGCPageInlined(pVCpu, pVCpu->pgm.s.GCPhysCR3, (void **)&pGuestPml4 RTLOG_COMMA_SRC_POS);
876 AssertRCReturn(rc, NULL);
877#else
878 PX86PML4 pGuestPml4 = pVCpu->pgm.s.CTX_SUFF(pGstAmd64Pml4);
879 if (RT_UNLIKELY(!pGuestPml4))
880 {
881 int rc = pgmGstLazyMapPml4(pVCpu, &pGuestPml4);
882 AssertRCReturn(rc, NULL);
883 }
884#endif
885 return &pGuestPml4->a[iPml4];
886}
887
888
889/**
890 * Gets the page directory entry for the specified address.
891 *
892 * @returns The page directory entry in question.
893 * @returns A non-present entry if the page directory is not present or on an invalid page.
894 * @param pVCpu The cross context virtual CPU structure.
895 * @param GCPtr The address.
896 */
897DECLINLINE(X86PDEPAE) pgmGstGetLongModePDE(PVMCPU pVCpu, RTGCPTR64 GCPtr)
898{
899 /*
900 * Note! To keep things simple, ASSUME invalid physical addresses will
901 * cause X86_TRAP_PF_RSVD. This isn't a problem until we start
902 * supporting 52-bit wide physical guest addresses.
903 */
904 PCX86PML4 pGuestPml4 = pgmGstGetLongModePML4Ptr(pVCpu);
905 const unsigned iPml4 = (GCPtr >> X86_PML4_SHIFT) & X86_PML4_MASK;
906 if ( RT_LIKELY(pGuestPml4)
907 && pGuestPml4->a[iPml4].n.u1Present
908 && !(pGuestPml4->a[iPml4].u & pVCpu->pgm.s.fGstAmd64MbzPml4eMask) )
909 {
910 PCX86PDPT pPdptTemp;
911 int rc = PGM_GCPHYS_2_PTR_BY_VMCPU(pVCpu, pGuestPml4->a[iPml4].u & X86_PML4E_PG_MASK, &pPdptTemp);
912 if (RT_SUCCESS(rc))
913 {
914 const unsigned iPdpt = (GCPtr >> X86_PDPT_SHIFT) & X86_PDPT_MASK_AMD64;
915 if ( pPdptTemp->a[iPdpt].n.u1Present
916 && !(pPdptTemp->a[iPdpt].u & pVCpu->pgm.s.fGstAmd64MbzPdpeMask) )
917 {
918 PCX86PDPAE pPD;
919 rc = PGM_GCPHYS_2_PTR_BY_VMCPU(pVCpu, pPdptTemp->a[iPdpt].u & X86_PDPE_PG_MASK, &pPD);
920 if (RT_SUCCESS(rc))
921 {
922 const unsigned iPD = (GCPtr >> X86_PD_PAE_SHIFT) & X86_PD_PAE_MASK;
923 return pPD->a[iPD];
924 }
925 }
926 }
927 AssertMsg(RT_SUCCESS(rc) || rc == VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS, ("%Rrc\n", rc));
928 }
929
930 X86PDEPAE ZeroPde = {0};
931 return ZeroPde;
932}
933
934
935/**
936 * Gets the GUEST page directory pointer for the specified address.
937 *
938 * @returns The page directory in question.
939 * @returns NULL if the page directory is not present or on an invalid page.
940 * @param pVCpu The cross context virtual CPU structure.
941 * @param GCPtr The address.
942 * @param ppPml4e Page Map Level-4 Entry (out)
943 * @param pPdpe Page directory pointer table entry (out)
944 * @param piPD Receives the index into the returned page directory
945 */
946DECLINLINE(PX86PDPAE) pgmGstGetLongModePDPtr(PVMCPU pVCpu, RTGCPTR64 GCPtr, PX86PML4E *ppPml4e, PX86PDPE pPdpe, unsigned *piPD)
947{
948 /* The PMLE4. */
949 PX86PML4 pGuestPml4 = pgmGstGetLongModePML4Ptr(pVCpu);
950 if (RT_UNLIKELY(!pGuestPml4))
951 return NULL;
952 const unsigned iPml4 = (GCPtr >> X86_PML4_SHIFT) & X86_PML4_MASK;
953 PCX86PML4E pPml4e = *ppPml4e = &pGuestPml4->a[iPml4];
954 if (!pPml4e->n.u1Present)
955 return NULL;
956 if (RT_UNLIKELY(pPml4e->u & pVCpu->pgm.s.fGstAmd64MbzPml4eMask))
957 return NULL;
958
959 /* The PDPE. */
960 PCX86PDPT pPdptTemp;
961 int rc = PGM_GCPHYS_2_PTR_BY_VMCPU(pVCpu, pPml4e->u & X86_PML4E_PG_MASK, &pPdptTemp);
962 if (RT_FAILURE(rc))
963 {
964 AssertMsg(rc == VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS, ("%Rrc\n", rc));
965 return NULL;
966 }
967 const unsigned iPdpt = (GCPtr >> X86_PDPT_SHIFT) & X86_PDPT_MASK_AMD64;
968 *pPdpe = pPdptTemp->a[iPdpt];
969 if (!pPdpe->n.u1Present)
970 return NULL;
971 if (RT_UNLIKELY(pPdpe->u & pVCpu->pgm.s.fGstAmd64MbzPdpeMask))
972 return NULL;
973
974 /* The PDE. */
975 PX86PDPAE pPD;
976 rc = PGM_GCPHYS_2_PTR_BY_VMCPU(pVCpu, pPdptTemp->a[iPdpt].u & X86_PDPE_PG_MASK, &pPD);
977 if (RT_FAILURE(rc))
978 {
979 AssertMsg(rc == VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS, ("%Rrc\n", rc));
980 return NULL;
981 }
982
983 *piPD = (GCPtr >> X86_PD_PAE_SHIFT) & X86_PD_PAE_MASK;
984 return pPD;
985}
986
987#endif /* !IN_RC */
988
989/**
990 * Gets the shadow page directory, 32-bit.
991 *
992 * @returns Pointer to the shadow 32-bit PD.
993 * @param pVCpu The cross context virtual CPU structure.
994 */
995DECLINLINE(PX86PD) pgmShwGet32BitPDPtr(PVMCPU pVCpu)
996{
997 return (PX86PD)PGMPOOL_PAGE_2_PTR_V2(pVCpu->CTX_SUFF(pVM), pVCpu, pVCpu->pgm.s.CTX_SUFF(pShwPageCR3));
998}
999
1000
1001/**
1002 * Gets the shadow page directory entry for the specified address, 32-bit.
1003 *
1004 * @returns Shadow 32-bit PDE.
1005 * @param pVCpu The cross context virtual CPU structure.
1006 * @param GCPtr The address.
1007 */
1008DECLINLINE(X86PDE) pgmShwGet32BitPDE(PVMCPU pVCpu, RTGCPTR GCPtr)
1009{
1010 const unsigned iPd = (GCPtr >> X86_PD_SHIFT) & X86_PD_MASK;
1011
1012 PX86PD pShwPde = pgmShwGet32BitPDPtr(pVCpu);
1013 if (!pShwPde)
1014 {
1015 X86PDE ZeroPde = {0};
1016 return ZeroPde;
1017 }
1018 return pShwPde->a[iPd];
1019}
1020
1021
1022/**
1023 * Gets the pointer to the shadow page directory entry for the specified
1024 * address, 32-bit.
1025 *
1026 * @returns Pointer to the shadow 32-bit PDE.
1027 * @param pVCpu The cross context virtual CPU structure.
1028 * @param GCPtr The address.
1029 */
1030DECLINLINE(PX86PDE) pgmShwGet32BitPDEPtr(PVMCPU pVCpu, RTGCPTR GCPtr)
1031{
1032 const unsigned iPd = (GCPtr >> X86_PD_SHIFT) & X86_PD_MASK;
1033
1034 PX86PD pPde = pgmShwGet32BitPDPtr(pVCpu);
1035 AssertReturn(pPde, NULL);
1036 return &pPde->a[iPd];
1037}
1038
1039
1040/**
1041 * Gets the shadow page pointer table, PAE.
1042 *
1043 * @returns Pointer to the shadow PAE PDPT.
1044 * @param pVCpu The cross context virtual CPU structure.
1045 */
1046DECLINLINE(PX86PDPT) pgmShwGetPaePDPTPtr(PVMCPU pVCpu)
1047{
1048 return (PX86PDPT)PGMPOOL_PAGE_2_PTR_V2(pVCpu->CTX_SUFF(pVM), pVCpu, pVCpu->pgm.s.CTX_SUFF(pShwPageCR3));
1049}
1050
1051
1052/**
1053 * Gets the shadow page directory for the specified address, PAE.
1054 *
1055 * @returns Pointer to the shadow PD.
1056 * @param pVCpu The cross context virtual CPU structure.
1057 * @param GCPtr The address.
1058 */
1059DECLINLINE(PX86PDPAE) pgmShwGetPaePDPtr(PVMCPU pVCpu, RTGCPTR GCPtr)
1060{
1061 const unsigned iPdpt = (GCPtr >> X86_PDPT_SHIFT) & X86_PDPT_MASK_PAE;
1062 PX86PDPT pPdpt = pgmShwGetPaePDPTPtr(pVCpu);
1063
1064 if (!pPdpt->a[iPdpt].n.u1Present)
1065 return NULL;
1066
1067 /* Fetch the pgm pool shadow descriptor. */
1068 PVM pVM = pVCpu->CTX_SUFF(pVM);
1069 PPGMPOOLPAGE pShwPde = pgmPoolGetPage(pVM->pgm.s.CTX_SUFF(pPool), pPdpt->a[iPdpt].u & X86_PDPE_PG_MASK);
1070 AssertReturn(pShwPde, NULL);
1071
1072 return (PX86PDPAE)PGMPOOL_PAGE_2_PTR_V2(pVM, pVCpu, pShwPde);
1073}
1074
1075
1076/**
1077 * Gets the shadow page directory for the specified address, PAE.
1078 *
1079 * @returns Pointer to the shadow PD.
1080 * @param pVCpu The cross context virtual CPU structure.
1081 * @param pPdpt Pointer to the page directory pointer table.
1082 * @param GCPtr The address.
1083 */
1084DECLINLINE(PX86PDPAE) pgmShwGetPaePDPtr(PVMCPU pVCpu, PX86PDPT pPdpt, RTGCPTR GCPtr)
1085{
1086 const unsigned iPdpt = (GCPtr >> X86_PDPT_SHIFT) & X86_PDPT_MASK_PAE;
1087
1088 if (!pPdpt->a[iPdpt].n.u1Present)
1089 return NULL;
1090
1091 /* Fetch the pgm pool shadow descriptor. */
1092 PVM pVM = pVCpu->CTX_SUFF(pVM);
1093 PPGMPOOLPAGE pShwPde = pgmPoolGetPage(pVM->pgm.s.CTX_SUFF(pPool), pPdpt->a[iPdpt].u & X86_PDPE_PG_MASK);
1094 AssertReturn(pShwPde, NULL);
1095
1096 return (PX86PDPAE)PGMPOOL_PAGE_2_PTR_V2(pVM, pVCpu, pShwPde);
1097}
1098
1099
1100/**
1101 * Gets the shadow page directory entry, PAE.
1102 *
1103 * @returns PDE.
1104 * @param pVCpu The cross context virtual CPU structure.
1105 * @param GCPtr The address.
1106 */
1107DECLINLINE(X86PDEPAE) pgmShwGetPaePDE(PVMCPU pVCpu, RTGCPTR GCPtr)
1108{
1109 const unsigned iPd = (GCPtr >> X86_PD_PAE_SHIFT) & X86_PD_PAE_MASK;
1110
1111 PX86PDPAE pShwPde = pgmShwGetPaePDPtr(pVCpu, GCPtr);
1112 if (!pShwPde)
1113 {
1114 X86PDEPAE ZeroPde = {0};
1115 return ZeroPde;
1116 }
1117 return pShwPde->a[iPd];
1118}
1119
1120
1121/**
1122 * Gets the pointer to the shadow page directory entry for an address, PAE.
1123 *
1124 * @returns Pointer to the PDE.
1125 * @param pVCpu The cross context virtual CPU structure.
1126 * @param GCPtr The address.
1127 * @remarks Only used by AssertCR3.
1128 */
1129DECLINLINE(PX86PDEPAE) pgmShwGetPaePDEPtr(PVMCPU pVCpu, RTGCPTR GCPtr)
1130{
1131 const unsigned iPd = (GCPtr >> X86_PD_PAE_SHIFT) & X86_PD_PAE_MASK;
1132
1133 PX86PDPAE pPde = pgmShwGetPaePDPtr(pVCpu, GCPtr);
1134 AssertReturn(pPde, NULL);
1135 return &pPde->a[iPd];
1136}
1137
1138#ifndef IN_RC
1139
1140/**
1141 * Gets the shadow page map level-4 pointer.
1142 *
1143 * @returns Pointer to the shadow PML4.
1144 * @param pVCpu The cross context virtual CPU structure.
1145 */
1146DECLINLINE(PX86PML4) pgmShwGetLongModePML4Ptr(PVMCPU pVCpu)
1147{
1148 return (PX86PML4)PGMPOOL_PAGE_2_PTR_V2(pVCpu->CTX_SUFF(pVM), pVCpu, pVCpu->pgm.s.CTX_SUFF(pShwPageCR3));
1149}
1150
1151
1152/**
1153 * Gets the shadow page map level-4 entry for the specified address.
1154 *
1155 * @returns The entry.
1156 * @param pVCpu The cross context virtual CPU structure.
1157 * @param GCPtr The address.
1158 */
1159DECLINLINE(X86PML4E) pgmShwGetLongModePML4E(PVMCPU pVCpu, RTGCPTR GCPtr)
1160{
1161 const unsigned iPml4 = ((RTGCUINTPTR64)GCPtr >> X86_PML4_SHIFT) & X86_PML4_MASK;
1162 PX86PML4 pShwPml4 = pgmShwGetLongModePML4Ptr(pVCpu);
1163
1164 if (!pShwPml4)
1165 {
1166 X86PML4E ZeroPml4e = {0};
1167 return ZeroPml4e;
1168 }
1169 return pShwPml4->a[iPml4];
1170}
1171
1172
1173/**
1174 * Gets the pointer to the specified shadow page map level-4 entry.
1175 *
1176 * @returns The entry.
1177 * @param pVCpu The cross context virtual CPU structure.
1178 * @param iPml4 The PML4 index.
1179 */
1180DECLINLINE(PX86PML4E) pgmShwGetLongModePML4EPtr(PVMCPU pVCpu, unsigned int iPml4)
1181{
1182 PX86PML4 pShwPml4 = pgmShwGetLongModePML4Ptr(pVCpu);
1183 if (!pShwPml4)
1184 return NULL;
1185 return &pShwPml4->a[iPml4];
1186}
1187
1188#endif /* !IN_RC */
1189
1190/**
1191 * Cached physical handler lookup.
1192 *
1193 * @returns Physical handler covering @a GCPhys.
1194 * @param pVM The cross context VM structure.
1195 * @param GCPhys The lookup address.
1196 */
1197DECLINLINE(PPGMPHYSHANDLER) pgmHandlerPhysicalLookup(PVM pVM, RTGCPHYS GCPhys)
1198{
1199 PPGMPHYSHANDLER pHandler = pVM->pgm.s.CTX_SUFF(pLastPhysHandler);
1200 if ( pHandler
1201 && GCPhys >= pHandler->Core.Key
1202 && GCPhys < pHandler->Core.KeyLast)
1203 {
1204 STAM_COUNTER_INC(&pVM->pgm.s.CTX_SUFF(pStats)->CTX_MID_Z(Stat,PhysHandlerLookupHits));
1205 return pHandler;
1206 }
1207
1208 STAM_COUNTER_INC(&pVM->pgm.s.CTX_SUFF(pStats)->CTX_MID_Z(Stat,PhysHandlerLookupMisses));
1209 pHandler = (PPGMPHYSHANDLER)RTAvlroGCPhysRangeGet(&pVM->pgm.s.CTX_SUFF(pTrees)->PhysHandlers, GCPhys);
1210 if (pHandler)
1211 pVM->pgm.s.CTX_SUFF(pLastPhysHandler) = pHandler;
1212 return pHandler;
1213}
1214
1215
1216#ifdef VBOX_WITH_RAW_MODE
1217/**
1218 * Clears one physical page of a virtual handler.
1219 *
1220 * @param pVM The cross context VM structure.
1221 * @param pCur Virtual handler structure.
1222 * @param iPage Physical page index.
1223 *
1224 * @remark Only used when PGM_SYNC_UPDATE_PAGE_BIT_VIRTUAL is being set, so no
1225 * need to care about other handlers in the same page.
1226 */
1227DECLINLINE(void) pgmHandlerVirtualClearPage(PVM pVM, PPGMVIRTHANDLER pCur, unsigned iPage)
1228{
1229 const PPGMPHYS2VIRTHANDLER pPhys2Virt = &pCur->aPhysToVirt[iPage];
1230
1231 /*
1232 * Remove the node from the tree (it's supposed to be in the tree if we get here!).
1233 */
1234# ifdef VBOX_STRICT_PGM_HANDLER_VIRTUAL
1235 AssertReleaseMsg(pPhys2Virt->offNextAlias & PGMPHYS2VIRTHANDLER_IN_TREE,
1236 ("pPhys2Virt=%p:{.Core.Key=%RGp, .Core.KeyLast=%RGp, .offVirtHandler=%#RX32, .offNextAlias=%#RX32}\n",
1237 pPhys2Virt, pPhys2Virt->Core.Key, pPhys2Virt->Core.KeyLast, pPhys2Virt->offVirtHandler, pPhys2Virt->offNextAlias));
1238# endif
1239 if (pPhys2Virt->offNextAlias & PGMPHYS2VIRTHANDLER_IS_HEAD)
1240 {
1241 /* We're the head of the alias chain. */
1242 PPGMPHYS2VIRTHANDLER pRemove = (PPGMPHYS2VIRTHANDLER)RTAvlroGCPhysRemove(&pVM->pgm.s.CTX_SUFF(pTrees)->PhysToVirtHandlers, pPhys2Virt->Core.Key); NOREF(pRemove);
1243# ifdef VBOX_STRICT_PGM_HANDLER_VIRTUAL
1244 AssertReleaseMsg(pRemove != NULL,
1245 ("pPhys2Virt=%p:{.Core.Key=%RGp, .Core.KeyLast=%RGp, .offVirtHandler=%#RX32, .offNextAlias=%#RX32}\n",
1246 pPhys2Virt, pPhys2Virt->Core.Key, pPhys2Virt->Core.KeyLast, pPhys2Virt->offVirtHandler, pPhys2Virt->offNextAlias));
1247 AssertReleaseMsg(pRemove == pPhys2Virt,
1248 ("wanted: pPhys2Virt=%p:{.Core.Key=%RGp, .Core.KeyLast=%RGp, .offVirtHandler=%#RX32, .offNextAlias=%#RX32}\n"
1249 " got: pRemove=%p:{.Core.Key=%RGp, .Core.KeyLast=%RGp, .offVirtHandler=%#RX32, .offNextAlias=%#RX32}\n",
1250 pPhys2Virt, pPhys2Virt->Core.Key, pPhys2Virt->Core.KeyLast, pPhys2Virt->offVirtHandler, pPhys2Virt->offNextAlias,
1251 pRemove, pRemove->Core.Key, pRemove->Core.KeyLast, pRemove->offVirtHandler, pRemove->offNextAlias));
1252# endif
1253 if (pPhys2Virt->offNextAlias & PGMPHYS2VIRTHANDLER_OFF_MASK)
1254 {
1255 /* Insert the next list in the alias chain into the tree. */
1256 PPGMPHYS2VIRTHANDLER pNext = (PPGMPHYS2VIRTHANDLER)((intptr_t)pPhys2Virt + (pPhys2Virt->offNextAlias & PGMPHYS2VIRTHANDLER_OFF_MASK));
1257# ifdef VBOX_STRICT_PGM_HANDLER_VIRTUAL
1258 AssertReleaseMsg(pNext->offNextAlias & PGMPHYS2VIRTHANDLER_IN_TREE,
1259 ("pNext=%p:{.Core.Key=%RGp, .Core.KeyLast=%RGp, .offVirtHandler=%#RX32, .offNextAlias=%#RX32}\n",
1260 pNext, pNext->Core.Key, pNext->Core.KeyLast, pNext->offVirtHandler, pNext->offNextAlias));
1261# endif
1262 pNext->offNextAlias |= PGMPHYS2VIRTHANDLER_IS_HEAD;
1263 bool fRc = RTAvlroGCPhysInsert(&pVM->pgm.s.CTX_SUFF(pTrees)->PhysToVirtHandlers, &pNext->Core);
1264 AssertRelease(fRc);
1265 }
1266 }
1267 else
1268 {
1269 /* Locate the previous node in the alias chain. */
1270 PPGMPHYS2VIRTHANDLER pPrev = (PPGMPHYS2VIRTHANDLER)RTAvlroGCPhysGet(&pVM->pgm.s.CTX_SUFF(pTrees)->PhysToVirtHandlers, pPhys2Virt->Core.Key);
1271# ifdef VBOX_STRICT_PGM_HANDLER_VIRTUAL
1272 AssertReleaseMsg(pPrev != pPhys2Virt,
1273 ("pPhys2Virt=%p:{.Core.Key=%RGp, .Core.KeyLast=%RGp, .offVirtHandler=%#RX32, .offNextAlias=%#RX32} pPrev=%p\n",
1274 pPhys2Virt, pPhys2Virt->Core.Key, pPhys2Virt->Core.KeyLast, pPhys2Virt->offVirtHandler, pPhys2Virt->offNextAlias, pPrev));
1275# endif
1276 for (;;)
1277 {
1278 PPGMPHYS2VIRTHANDLER pNext = (PPGMPHYS2VIRTHANDLER)((intptr_t)pPrev + (pPrev->offNextAlias & PGMPHYS2VIRTHANDLER_OFF_MASK));
1279 if (pNext == pPhys2Virt)
1280 {
1281 /* unlink. */
1282 LogFlow(("pgmHandlerVirtualClearPage: removed %p:{.offNextAlias=%#RX32} from alias chain. prev %p:{.offNextAlias=%#RX32} [%RGp-%RGp]\n",
1283 pPhys2Virt, pPhys2Virt->offNextAlias, pPrev, pPrev->offNextAlias, pPhys2Virt->Core.Key, pPhys2Virt->Core.KeyLast));
1284 if (!(pPhys2Virt->offNextAlias & PGMPHYS2VIRTHANDLER_OFF_MASK))
1285 pPrev->offNextAlias &= ~PGMPHYS2VIRTHANDLER_OFF_MASK;
1286 else
1287 {
1288 PPGMPHYS2VIRTHANDLER pNewNext = (PPGMPHYS2VIRTHANDLER)((intptr_t)pPhys2Virt + (pPhys2Virt->offNextAlias & PGMPHYS2VIRTHANDLER_OFF_MASK));
1289 pPrev->offNextAlias = ((intptr_t)pNewNext - (intptr_t)pPrev)
1290 | (pPrev->offNextAlias & ~PGMPHYS2VIRTHANDLER_OFF_MASK);
1291 }
1292 break;
1293 }
1294
1295 /* next */
1296 if (pNext == pPrev)
1297 {
1298# ifdef VBOX_STRICT_PGM_HANDLER_VIRTUAL
1299 AssertReleaseMsg(pNext != pPrev,
1300 ("pPhys2Virt=%p:{.Core.Key=%RGp, .Core.KeyLast=%RGp, .offVirtHandler=%#RX32, .offNextAlias=%#RX32} pPrev=%p\n",
1301 pPhys2Virt, pPhys2Virt->Core.Key, pPhys2Virt->Core.KeyLast, pPhys2Virt->offVirtHandler, pPhys2Virt->offNextAlias, pPrev));
1302# endif
1303 break;
1304 }
1305 pPrev = pNext;
1306 }
1307 }
1308 Log2(("PHYS2VIRT: Removing %RGp-%RGp %#RX32 %s\n",
1309 pPhys2Virt->Core.Key, pPhys2Virt->Core.KeyLast, pPhys2Virt->offNextAlias, R3STRING(pCur->pszDesc)));
1310 pPhys2Virt->offNextAlias = 0;
1311 pPhys2Virt->Core.KeyLast = NIL_RTGCPHYS; /* require reinsert */
1312
1313 /*
1314 * Clear the ram flags for this page.
1315 */
1316 PPGMPAGE pPage = pgmPhysGetPage(pVM, pPhys2Virt->Core.Key);
1317 AssertReturnVoid(pPage);
1318 PGM_PAGE_SET_HNDL_VIRT_STATE(pPage, PGM_PAGE_HNDL_VIRT_STATE_NONE);
1319}
1320#endif /* VBOX_WITH_RAW_MODE */
1321
1322
1323/**
1324 * Internal worker for finding a 'in-use' shadow page give by it's physical address.
1325 *
1326 * @returns Pointer to the shadow page structure.
1327 * @param pPool The pool.
1328 * @param idx The pool page index.
1329 */
1330DECLINLINE(PPGMPOOLPAGE) pgmPoolGetPageByIdx(PPGMPOOL pPool, unsigned idx)
1331{
1332 AssertFatalMsg(idx >= PGMPOOL_IDX_FIRST && idx < pPool->cCurPages, ("idx=%d\n", idx));
1333 return &pPool->aPages[idx];
1334}
1335
1336
1337/**
1338 * Clear references to guest physical memory.
1339 *
1340 * @param pPool The pool.
1341 * @param pPoolPage The pool page.
1342 * @param pPhysPage The physical guest page tracking structure.
1343 * @param iPte Shadow PTE index
1344 */
1345DECLINLINE(void) pgmTrackDerefGCPhys(PPGMPOOL pPool, PPGMPOOLPAGE pPoolPage, PPGMPAGE pPhysPage, uint16_t iPte)
1346{
1347 /*
1348 * Just deal with the simple case here.
1349 */
1350# ifdef VBOX_STRICT
1351 PVM pVM = pPool->CTX_SUFF(pVM); NOREF(pVM);
1352# endif
1353# ifdef LOG_ENABLED
1354 const unsigned uOrg = PGM_PAGE_GET_TRACKING(pPhysPage);
1355# endif
1356 const unsigned cRefs = PGM_PAGE_GET_TD_CREFS(pPhysPage);
1357 if (cRefs == 1)
1358 {
1359 Assert(pPoolPage->idx == PGM_PAGE_GET_TD_IDX(pPhysPage));
1360 Assert(iPte == PGM_PAGE_GET_PTE_INDEX(pPhysPage));
1361 /* Invalidate the tracking data. */
1362 PGM_PAGE_SET_TRACKING(pVM, pPhysPage, 0);
1363 }
1364 else
1365 pgmPoolTrackPhysExtDerefGCPhys(pPool, pPoolPage, pPhysPage, iPte);
1366 Log2(("pgmTrackDerefGCPhys: %x -> %x pPhysPage=%R[pgmpage]\n", uOrg, PGM_PAGE_GET_TRACKING(pPhysPage), pPhysPage ));
1367}
1368
1369
1370/**
1371 * Moves the page to the head of the age list.
1372 *
1373 * This is done when the cached page is used in one way or another.
1374 *
1375 * @param pPool The pool.
1376 * @param pPage The cached page.
1377 */
1378DECLINLINE(void) pgmPoolCacheUsed(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
1379{
1380 PGM_LOCK_ASSERT_OWNER(pPool->CTX_SUFF(pVM));
1381
1382 /*
1383 * Move to the head of the age list.
1384 */
1385 if (pPage->iAgePrev != NIL_PGMPOOL_IDX)
1386 {
1387 /* unlink */
1388 pPool->aPages[pPage->iAgePrev].iAgeNext = pPage->iAgeNext;
1389 if (pPage->iAgeNext != NIL_PGMPOOL_IDX)
1390 pPool->aPages[pPage->iAgeNext].iAgePrev = pPage->iAgePrev;
1391 else
1392 pPool->iAgeTail = pPage->iAgePrev;
1393
1394 /* insert at head */
1395 pPage->iAgePrev = NIL_PGMPOOL_IDX;
1396 pPage->iAgeNext = pPool->iAgeHead;
1397 Assert(pPage->iAgeNext != NIL_PGMPOOL_IDX); /* we would've already been head then */
1398 pPool->iAgeHead = pPage->idx;
1399 pPool->aPages[pPage->iAgeNext].iAgePrev = pPage->idx;
1400 }
1401}
1402
1403
1404/**
1405 * Locks a page to prevent flushing (important for cr3 root pages or shadow pae pd pages).
1406 *
1407 * @param pPool The pool.
1408 * @param pPage PGM pool page
1409 */
1410DECLINLINE(void) pgmPoolLockPage(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
1411{
1412 PGM_LOCK_ASSERT_OWNER(pPool->CTX_SUFF(pVM)); NOREF(pPool);
1413 ASMAtomicIncU32(&pPage->cLocked);
1414}
1415
1416
1417/**
1418 * Unlocks a page to allow flushing again
1419 *
1420 * @param pPool The pool.
1421 * @param pPage PGM pool page
1422 */
1423DECLINLINE(void) pgmPoolUnlockPage(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
1424{
1425 PGM_LOCK_ASSERT_OWNER(pPool->CTX_SUFF(pVM)); NOREF(pPool);
1426 Assert(pPage->cLocked);
1427 ASMAtomicDecU32(&pPage->cLocked);
1428}
1429
1430
1431/**
1432 * Checks if the page is locked (e.g. the active CR3 or one of the four PDs of a PAE PDPT)
1433 *
1434 * @returns VBox status code.
1435 * @param pPage PGM pool page
1436 */
1437DECLINLINE(bool) pgmPoolIsPageLocked(PPGMPOOLPAGE pPage)
1438{
1439 if (pPage->cLocked)
1440 {
1441 LogFlow(("pgmPoolIsPageLocked found root page %d\n", pPage->enmKind));
1442 if (pPage->cModifications)
1443 pPage->cModifications = 1; /* reset counter (can't use 0, or else it will be reinserted in the modified list) */
1444 return true;
1445 }
1446 return false;
1447}
1448
1449
1450/**
1451 * Tells if mappings are to be put into the shadow page table or not.
1452 *
1453 * @returns boolean result
1454 * @param pVM The cross context VM structure.
1455 */
1456DECL_FORCE_INLINE(bool) pgmMapAreMappingsEnabled(PVM pVM)
1457{
1458#ifdef PGM_WITHOUT_MAPPINGS
1459 /* There are no mappings in VT-x and AMD-V mode. */
1460 Assert(HMIsEnabled(pVM)); NOREF(pVM);
1461 return false;
1462#else
1463 Assert(pVM->cCpus == 1 || HMIsEnabled(pVM));
1464 return !HMIsEnabled(pVM);
1465#endif
1466}
1467
1468
1469/**
1470 * Checks if the mappings are floating and enabled.
1471 *
1472 * @returns true / false.
1473 * @param pVM The cross context VM structure.
1474 */
1475DECL_FORCE_INLINE(bool) pgmMapAreMappingsFloating(PVM pVM)
1476{
1477#ifdef PGM_WITHOUT_MAPPINGS
1478 /* There are no mappings in VT-x and AMD-V mode. */
1479 Assert(HMIsEnabled(pVM)); NOREF(pVM);
1480 return false;
1481#else
1482 return !pVM->pgm.s.fMappingsFixed
1483 && pgmMapAreMappingsEnabled(pVM);
1484#endif
1485}
1486
1487/** @} */
1488
1489#endif
1490
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