1 | /* $Id: PGMInternal.h 23372 2009-09-28 12:46:22Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * PGM - Internal header file.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
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 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
18 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
19 | * additional information or have any questions.
|
---|
20 | */
|
---|
21 |
|
---|
22 | #ifndef ___PGMInternal_h
|
---|
23 | #define ___PGMInternal_h
|
---|
24 |
|
---|
25 | #include <VBox/cdefs.h>
|
---|
26 | #include <VBox/types.h>
|
---|
27 | #include <VBox/err.h>
|
---|
28 | #include <VBox/stam.h>
|
---|
29 | #include <VBox/param.h>
|
---|
30 | #include <VBox/vmm.h>
|
---|
31 | #include <VBox/mm.h>
|
---|
32 | #include <VBox/pdmcritsect.h>
|
---|
33 | #include <VBox/pdmapi.h>
|
---|
34 | #include <VBox/dis.h>
|
---|
35 | #include <VBox/dbgf.h>
|
---|
36 | #include <VBox/log.h>
|
---|
37 | #include <VBox/gmm.h>
|
---|
38 | #include <VBox/hwaccm.h>
|
---|
39 | #include <iprt/asm.h>
|
---|
40 | #include <iprt/assert.h>
|
---|
41 | #include <iprt/avl.h>
|
---|
42 | #include <iprt/critsect.h>
|
---|
43 |
|
---|
44 |
|
---|
45 |
|
---|
46 | /** @defgroup grp_pgm_int Internals
|
---|
47 | * @ingroup grp_pgm
|
---|
48 | * @internal
|
---|
49 | * @{
|
---|
50 | */
|
---|
51 |
|
---|
52 |
|
---|
53 | /** @name PGM Compile Time Config
|
---|
54 | * @{
|
---|
55 | */
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * Solve page is out of sync issues inside Guest Context (in PGMGC.cpp).
|
---|
59 | * Comment it if it will break something.
|
---|
60 | */
|
---|
61 | #define PGM_OUT_OF_SYNC_IN_GC
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * Check and skip global PDEs for non-global flushes
|
---|
65 | */
|
---|
66 | #define PGM_SKIP_GLOBAL_PAGEDIRS_ON_NONGLOBAL_FLUSH
|
---|
67 |
|
---|
68 | /**
|
---|
69 | * Optimization for PAE page tables that are modified often
|
---|
70 | */
|
---|
71 | #if 0 /* disabled again while debugging */
|
---|
72 | #ifndef IN_RC
|
---|
73 | # define PGMPOOL_WITH_OPTIMIZED_DIRTY_PT
|
---|
74 | #endif
|
---|
75 | #endif
|
---|
76 |
|
---|
77 | /**
|
---|
78 | * Sync N pages instead of a whole page table
|
---|
79 | */
|
---|
80 | #define PGM_SYNC_N_PAGES
|
---|
81 |
|
---|
82 | /**
|
---|
83 | * Number of pages to sync during a page fault
|
---|
84 | *
|
---|
85 | * When PGMPOOL_WITH_GCPHYS_TRACKING is enabled using high values here
|
---|
86 | * causes a lot of unnecessary extents and also is slower than taking more \#PFs.
|
---|
87 | *
|
---|
88 | * Note that \#PFs are much more expensive in the VT-x/AMD-V case due to
|
---|
89 | * world switch overhead, so let's sync more.
|
---|
90 | */
|
---|
91 | # ifdef IN_RING0
|
---|
92 | /* Chose 32 based on the compile test in #4219; 64 shows worse stats.
|
---|
93 | * 32 again shows better results than 16; slightly more overhead in the \#PF handler,
|
---|
94 | * but ~5% fewer faults.
|
---|
95 | */
|
---|
96 | # define PGM_SYNC_NR_PAGES 32
|
---|
97 | #else
|
---|
98 | # define PGM_SYNC_NR_PAGES 8
|
---|
99 | #endif
|
---|
100 |
|
---|
101 | /**
|
---|
102 | * Number of PGMPhysRead/Write cache entries (must be <= sizeof(uint64_t))
|
---|
103 | */
|
---|
104 | #define PGM_MAX_PHYSCACHE_ENTRIES 64
|
---|
105 | #define PGM_MAX_PHYSCACHE_ENTRIES_MASK (PGM_MAX_PHYSCACHE_ENTRIES-1)
|
---|
106 |
|
---|
107 | /** @def PGMPOOL_WITH_CACHE
|
---|
108 | * Enable agressive caching using the page pool.
|
---|
109 | *
|
---|
110 | * This requires PGMPOOL_WITH_USER_TRACKING and PGMPOOL_WITH_MONITORING.
|
---|
111 | */
|
---|
112 | #define PGMPOOL_WITH_CACHE
|
---|
113 |
|
---|
114 | /** @def PGMPOOL_WITH_MIXED_PT_CR3
|
---|
115 | * When defined, we'll deal with 'uncachable' pages.
|
---|
116 | */
|
---|
117 | #ifdef PGMPOOL_WITH_CACHE
|
---|
118 | # define PGMPOOL_WITH_MIXED_PT_CR3
|
---|
119 | #endif
|
---|
120 |
|
---|
121 | /** @def PGMPOOL_WITH_MONITORING
|
---|
122 | * Monitor the guest pages which are shadowed.
|
---|
123 | * When this is enabled, PGMPOOL_WITH_CACHE or PGMPOOL_WITH_GCPHYS_TRACKING must
|
---|
124 | * be enabled as well.
|
---|
125 | * @remark doesn't really work without caching now. (Mixed PT/CR3 change.)
|
---|
126 | */
|
---|
127 | #ifdef PGMPOOL_WITH_CACHE
|
---|
128 | # define PGMPOOL_WITH_MONITORING
|
---|
129 | #endif
|
---|
130 |
|
---|
131 | /** @def PGMPOOL_WITH_GCPHYS_TRACKING
|
---|
132 | * Tracking the of shadow pages mapping guest physical pages.
|
---|
133 | *
|
---|
134 | * This is very expensive, the current cache prototype is trying to figure out
|
---|
135 | * whether it will be acceptable with an agressive caching policy.
|
---|
136 | */
|
---|
137 | #if defined(PGMPOOL_WITH_CACHE) || defined(PGMPOOL_WITH_MONITORING)
|
---|
138 | # define PGMPOOL_WITH_GCPHYS_TRACKING
|
---|
139 | #endif
|
---|
140 |
|
---|
141 | /** @def PGMPOOL_WITH_USER_TRACKING
|
---|
142 | * Tracking users of shadow pages. This is required for the linking of shadow page
|
---|
143 | * tables and physical guest addresses.
|
---|
144 | */
|
---|
145 | #if defined(PGMPOOL_WITH_GCPHYS_TRACKING) || defined(PGMPOOL_WITH_CACHE) || defined(PGMPOOL_WITH_MONITORING)
|
---|
146 | # define PGMPOOL_WITH_USER_TRACKING
|
---|
147 | #endif
|
---|
148 |
|
---|
149 | /** @def PGMPOOL_CFG_MAX_GROW
|
---|
150 | * The maximum number of pages to add to the pool in one go.
|
---|
151 | */
|
---|
152 | #define PGMPOOL_CFG_MAX_GROW (_256K >> PAGE_SHIFT)
|
---|
153 |
|
---|
154 | /** @def VBOX_STRICT_PGM_HANDLER_VIRTUAL
|
---|
155 | * Enables some extra assertions for virtual handlers (mainly phys2virt related).
|
---|
156 | */
|
---|
157 | #ifdef VBOX_STRICT
|
---|
158 | # define VBOX_STRICT_PGM_HANDLER_VIRTUAL
|
---|
159 | #endif
|
---|
160 |
|
---|
161 | /** @def VBOX_WITH_NEW_LAZY_PAGE_ALLOC
|
---|
162 | * Enables the experimental lazy page allocation code. */
|
---|
163 | /*# define VBOX_WITH_NEW_LAZY_PAGE_ALLOC */
|
---|
164 |
|
---|
165 | /** @} */
|
---|
166 |
|
---|
167 |
|
---|
168 | /** @name PDPT and PML4 flags.
|
---|
169 | * These are placed in the three bits available for system programs in
|
---|
170 | * the PDPT and PML4 entries.
|
---|
171 | * @{ */
|
---|
172 | /** The entry is a permanent one and it's must always be present.
|
---|
173 | * Never free such an entry. */
|
---|
174 | #define PGM_PLXFLAGS_PERMANENT RT_BIT_64(10)
|
---|
175 | /** Mapping (hypervisor allocated pagetable). */
|
---|
176 | #define PGM_PLXFLAGS_MAPPING RT_BIT_64(11)
|
---|
177 | /** @} */
|
---|
178 |
|
---|
179 | /** @name Page directory flags.
|
---|
180 | * These are placed in the three bits available for system programs in
|
---|
181 | * the page directory entries.
|
---|
182 | * @{ */
|
---|
183 | /** Mapping (hypervisor allocated pagetable). */
|
---|
184 | #define PGM_PDFLAGS_MAPPING RT_BIT_64(10)
|
---|
185 | /** Made read-only to facilitate dirty bit tracking. */
|
---|
186 | #define PGM_PDFLAGS_TRACK_DIRTY RT_BIT_64(11)
|
---|
187 | /** @} */
|
---|
188 |
|
---|
189 | /** @name Page flags.
|
---|
190 | * These are placed in the three bits available for system programs in
|
---|
191 | * the page entries.
|
---|
192 | * @{ */
|
---|
193 | /** Made read-only to facilitate dirty bit tracking. */
|
---|
194 | #define PGM_PTFLAGS_TRACK_DIRTY RT_BIT_64(9)
|
---|
195 |
|
---|
196 | #ifndef PGM_PTFLAGS_CSAM_VALIDATED
|
---|
197 | /** Scanned and approved by CSAM (tm).
|
---|
198 | * NOTE: Must be identical to the one defined in CSAMInternal.h!!
|
---|
199 | * @todo Move PGM_PTFLAGS_* and PGM_PDFLAGS_* to VBox/pgm.h. */
|
---|
200 | #define PGM_PTFLAGS_CSAM_VALIDATED RT_BIT_64(11)
|
---|
201 | #endif
|
---|
202 |
|
---|
203 | /** @} */
|
---|
204 |
|
---|
205 | /** @name Defines used to indicate the shadow and guest paging in the templates.
|
---|
206 | * @{ */
|
---|
207 | #define PGM_TYPE_REAL 1
|
---|
208 | #define PGM_TYPE_PROT 2
|
---|
209 | #define PGM_TYPE_32BIT 3
|
---|
210 | #define PGM_TYPE_PAE 4
|
---|
211 | #define PGM_TYPE_AMD64 5
|
---|
212 | #define PGM_TYPE_NESTED 6
|
---|
213 | #define PGM_TYPE_EPT 7
|
---|
214 | #define PGM_TYPE_MAX PGM_TYPE_EPT
|
---|
215 | /** @} */
|
---|
216 |
|
---|
217 | /** Macro for checking if the guest is using paging.
|
---|
218 | * @param uGstType PGM_TYPE_*
|
---|
219 | * @param uShwType PGM_TYPE_*
|
---|
220 | * @remark ASSUMES certain order of the PGM_TYPE_* values.
|
---|
221 | */
|
---|
222 | #define PGM_WITH_PAGING(uGstType, uShwType) \
|
---|
223 | ( (uGstType) >= PGM_TYPE_32BIT \
|
---|
224 | && (uShwType) != PGM_TYPE_NESTED \
|
---|
225 | && (uShwType) != PGM_TYPE_EPT)
|
---|
226 |
|
---|
227 | /** Macro for checking if the guest supports the NX bit.
|
---|
228 | * @param uGstType PGM_TYPE_*
|
---|
229 | * @param uShwType PGM_TYPE_*
|
---|
230 | * @remark ASSUMES certain order of the PGM_TYPE_* values.
|
---|
231 | */
|
---|
232 | #define PGM_WITH_NX(uGstType, uShwType) \
|
---|
233 | ( (uGstType) >= PGM_TYPE_PAE \
|
---|
234 | && (uShwType) != PGM_TYPE_NESTED \
|
---|
235 | && (uShwType) != PGM_TYPE_EPT)
|
---|
236 |
|
---|
237 |
|
---|
238 | /** @def PGM_HCPHYS_2_PTR
|
---|
239 | * Maps a HC physical page pool address to a virtual address.
|
---|
240 | *
|
---|
241 | * @returns VBox status code.
|
---|
242 | * @param pVM The VM handle.
|
---|
243 | * @param HCPhys The HC physical address to map to a virtual one.
|
---|
244 | * @param ppv Where to store the virtual address. No need to cast this.
|
---|
245 | *
|
---|
246 | * @remark In GC this uses PGMGCDynMapHCPage(), so it will consume of the
|
---|
247 | * small page window employeed by that function. Be careful.
|
---|
248 | * @remark There is no need to assert on the result.
|
---|
249 | */
|
---|
250 | #ifdef IN_RC
|
---|
251 | # define PGM_HCPHYS_2_PTR(pVM, HCPhys, ppv) \
|
---|
252 | PGMDynMapHCPage(pVM, HCPhys, (void **)(ppv))
|
---|
253 | #elif defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0)
|
---|
254 | # define PGM_HCPHYS_2_PTR(pVM, HCPhys, ppv) \
|
---|
255 | pgmR0DynMapHCPageInlined(&(pVM)->pgm.s, HCPhys, (void **)(ppv))
|
---|
256 | #else
|
---|
257 | # define PGM_HCPHYS_2_PTR(pVM, HCPhys, ppv) \
|
---|
258 | MMPagePhys2PageEx(pVM, HCPhys, (void **)(ppv))
|
---|
259 | #endif
|
---|
260 |
|
---|
261 | /** @def PGM_HCPHYS_2_PTR_BY_PGM
|
---|
262 | * Maps a HC physical page pool address to a virtual address.
|
---|
263 | *
|
---|
264 | * @returns VBox status code.
|
---|
265 | * @param pPGM The PGM instance data.
|
---|
266 | * @param HCPhys The HC physical address to map to a virtual one.
|
---|
267 | * @param ppv Where to store the virtual address. No need to cast this.
|
---|
268 | *
|
---|
269 | * @remark In GC this uses PGMGCDynMapHCPage(), so it will consume of the
|
---|
270 | * small page window employeed by that function. Be careful.
|
---|
271 | * @remark There is no need to assert on the result.
|
---|
272 | */
|
---|
273 | #ifdef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
|
---|
274 | # define PGM_HCPHYS_2_PTR_BY_PGM(pPGM, HCPhys, ppv) \
|
---|
275 | pgmR0DynMapHCPageInlined(pPGM, HCPhys, (void **)(ppv))
|
---|
276 | #else
|
---|
277 | # define PGM_HCPHYS_2_PTR_BY_PGM(pPGM, HCPhys, ppv) \
|
---|
278 | PGM_HCPHYS_2_PTR(PGM2VM(pPGM), HCPhys, (void **)(ppv))
|
---|
279 | #endif
|
---|
280 |
|
---|
281 | /** @def PGM_GCPHYS_2_PTR
|
---|
282 | * Maps a GC physical page address to a virtual address.
|
---|
283 | *
|
---|
284 | * @returns VBox status code.
|
---|
285 | * @param pVM The VM handle.
|
---|
286 | * @param GCPhys The GC physical address to map to a virtual one.
|
---|
287 | * @param ppv Where to store the virtual address. No need to cast this.
|
---|
288 | *
|
---|
289 | * @remark In GC this uses PGMGCDynMapGCPage(), so it will consume of the
|
---|
290 | * small page window employeed by that function. Be careful.
|
---|
291 | * @remark There is no need to assert on the result.
|
---|
292 | */
|
---|
293 | #ifdef IN_RC
|
---|
294 | # define PGM_GCPHYS_2_PTR(pVM, GCPhys, ppv) \
|
---|
295 | PGMDynMapGCPage(pVM, GCPhys, (void **)(ppv))
|
---|
296 | #elif defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0)
|
---|
297 | # define PGM_GCPHYS_2_PTR(pVM, GCPhys, ppv) \
|
---|
298 | pgmR0DynMapGCPageInlined(&(pVM)->pgm.s, GCPhys, (void **)(ppv))
|
---|
299 | #else
|
---|
300 | # define PGM_GCPHYS_2_PTR(pVM, GCPhys, ppv) \
|
---|
301 | PGMPhysGCPhys2R3Ptr(pVM, GCPhys, 1 /* one page only */, (PRTR3PTR)(ppv)) /** @todo this isn't asserting, use PGMRamGCPhys2HCPtr! */
|
---|
302 | #endif
|
---|
303 |
|
---|
304 | /** @def PGM_GCPHYS_2_PTR_BY_PGMCPU
|
---|
305 | * Maps a GC physical page address to a virtual address.
|
---|
306 | *
|
---|
307 | * @returns VBox status code.
|
---|
308 | * @param pPGM Pointer to the PGM instance data.
|
---|
309 | * @param GCPhys The GC physical address to map to a virtual one.
|
---|
310 | * @param ppv Where to store the virtual address. No need to cast this.
|
---|
311 | *
|
---|
312 | * @remark In GC this uses PGMGCDynMapGCPage(), so it will consume of the
|
---|
313 | * small page window employeed by that function. Be careful.
|
---|
314 | * @remark There is no need to assert on the result.
|
---|
315 | */
|
---|
316 | #ifdef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
|
---|
317 | # define PGM_GCPHYS_2_PTR_BY_PGMCPU(pPGM, GCPhys, ppv) \
|
---|
318 | pgmR0DynMapGCPageInlined(PGMCPU2PGM(pPGM), GCPhys, (void **)(ppv))
|
---|
319 | #else
|
---|
320 | # define PGM_GCPHYS_2_PTR_BY_PGMCPU(pPGM, GCPhys, ppv) \
|
---|
321 | PGM_GCPHYS_2_PTR(PGMCPU2VM(pPGM), GCPhys, ppv)
|
---|
322 | #endif
|
---|
323 |
|
---|
324 | /** @def PGM_GCPHYS_2_PTR_EX
|
---|
325 | * Maps a unaligned GC physical page address to a virtual address.
|
---|
326 | *
|
---|
327 | * @returns VBox status code.
|
---|
328 | * @param pVM The VM handle.
|
---|
329 | * @param GCPhys The GC physical address to map to a virtual one.
|
---|
330 | * @param ppv Where to store the virtual address. No need to cast this.
|
---|
331 | *
|
---|
332 | * @remark In GC this uses PGMGCDynMapGCPage(), so it will consume of the
|
---|
333 | * small page window employeed by that function. Be careful.
|
---|
334 | * @remark There is no need to assert on the result.
|
---|
335 | */
|
---|
336 | #if defined(IN_RC) || defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0)
|
---|
337 | # define PGM_GCPHYS_2_PTR_EX(pVM, GCPhys, ppv) \
|
---|
338 | PGMDynMapGCPageOff(pVM, GCPhys, (void **)(ppv))
|
---|
339 | #else
|
---|
340 | # define PGM_GCPHYS_2_PTR_EX(pVM, GCPhys, ppv) \
|
---|
341 | PGMPhysGCPhys2R3Ptr(pVM, GCPhys, 1 /* one page only */, (PRTR3PTR)(ppv)) /** @todo this isn't asserting, use PGMRamGCPhys2HCPtr! */
|
---|
342 | #endif
|
---|
343 |
|
---|
344 | /** @def PGM_INVL_PG
|
---|
345 | * Invalidates a page.
|
---|
346 | *
|
---|
347 | * @param pVCpu The VMCPU handle.
|
---|
348 | * @param GCVirt The virtual address of the page to invalidate.
|
---|
349 | */
|
---|
350 | #ifdef IN_RC
|
---|
351 | # define PGM_INVL_PG(pVCpu, GCVirt) ASMInvalidatePage((void *)(GCVirt))
|
---|
352 | #elif defined(IN_RING0)
|
---|
353 | # define PGM_INVL_PG(pVCpu, GCVirt) HWACCMInvalidatePage(pVCpu, (RTGCPTR)(GCVirt))
|
---|
354 | #else
|
---|
355 | # define PGM_INVL_PG(pVCpu, GCVirt) HWACCMInvalidatePage(pVCpu, (RTGCPTR)(GCVirt))
|
---|
356 | #endif
|
---|
357 |
|
---|
358 | /** @def PGM_INVL_PG_ALL_VCPU
|
---|
359 | * Invalidates a page on all VCPUs
|
---|
360 | *
|
---|
361 | * @param pVM The VM handle.
|
---|
362 | * @param GCVirt The virtual address of the page to invalidate.
|
---|
363 | */
|
---|
364 | #ifdef IN_RC
|
---|
365 | # define PGM_INVL_PG_ALL_VCPU(pVM, GCVirt) ASMInvalidatePage((void *)(GCVirt))
|
---|
366 | #elif defined(IN_RING0)
|
---|
367 | # define PGM_INVL_PG_ALL_VCPU(pVM, GCVirt) HWACCMInvalidatePageOnAllVCpus(pVM, (RTGCPTR)(GCVirt))
|
---|
368 | #else
|
---|
369 | # define PGM_INVL_PG_ALL_VCPU(pVM, GCVirt) HWACCMInvalidatePageOnAllVCpus(pVM, (RTGCPTR)(GCVirt))
|
---|
370 | #endif
|
---|
371 |
|
---|
372 | /** @def PGM_INVL_BIG_PG
|
---|
373 | * Invalidates a 4MB page directory entry.
|
---|
374 | *
|
---|
375 | * @param pVCpu The VMCPU handle.
|
---|
376 | * @param GCVirt The virtual address within the page directory to invalidate.
|
---|
377 | */
|
---|
378 | #ifdef IN_RC
|
---|
379 | # define PGM_INVL_BIG_PG(pVCpu, GCVirt) ASMReloadCR3()
|
---|
380 | #elif defined(IN_RING0)
|
---|
381 | # define PGM_INVL_BIG_PG(pVCpu, GCVirt) HWACCMFlushTLB(pVCpu)
|
---|
382 | #else
|
---|
383 | # define PGM_INVL_BIG_PG(pVCpu, GCVirt) HWACCMFlushTLB(pVCpu)
|
---|
384 | #endif
|
---|
385 |
|
---|
386 | /** @def PGM_INVL_VCPU_TLBS()
|
---|
387 | * Invalidates the TLBs of the specified VCPU
|
---|
388 | *
|
---|
389 | * @param pVCpu The VMCPU handle.
|
---|
390 | */
|
---|
391 | #ifdef IN_RC
|
---|
392 | # define PGM_INVL_VCPU_TLBS(pVCpu) ASMReloadCR3()
|
---|
393 | #elif defined(IN_RING0)
|
---|
394 | # define PGM_INVL_VCPU_TLBS(pVCpu) HWACCMFlushTLB(pVCpu)
|
---|
395 | #else
|
---|
396 | # define PGM_INVL_VCPU_TLBS(pVCpu) HWACCMFlushTLB(pVCpu)
|
---|
397 | #endif
|
---|
398 |
|
---|
399 | /** @def PGM_INVL_ALL_VCPU_TLBS()
|
---|
400 | * Invalidates the TLBs of all VCPUs
|
---|
401 | *
|
---|
402 | * @param pVM The VM handle.
|
---|
403 | */
|
---|
404 | #ifdef IN_RC
|
---|
405 | # define PGM_INVL_ALL_VCPU_TLBS(pVM) ASMReloadCR3()
|
---|
406 | #elif defined(IN_RING0)
|
---|
407 | # define PGM_INVL_ALL_VCPU_TLBS(pVM) HWACCMFlushTLBOnAllVCpus(pVM)
|
---|
408 | #else
|
---|
409 | # define PGM_INVL_ALL_VCPU_TLBS(pVM) HWACCMFlushTLBOnAllVCpus(pVM)
|
---|
410 | #endif
|
---|
411 |
|
---|
412 | /** Size of the GCPtrConflict array in PGMMAPPING.
|
---|
413 | * @remarks Must be a power of two. */
|
---|
414 | #define PGMMAPPING_CONFLICT_MAX 8
|
---|
415 |
|
---|
416 | /**
|
---|
417 | * Structure for tracking GC Mappings.
|
---|
418 | *
|
---|
419 | * This structure is used by linked list in both GC and HC.
|
---|
420 | */
|
---|
421 | typedef struct PGMMAPPING
|
---|
422 | {
|
---|
423 | /** Pointer to next entry. */
|
---|
424 | R3PTRTYPE(struct PGMMAPPING *) pNextR3;
|
---|
425 | /** Pointer to next entry. */
|
---|
426 | R0PTRTYPE(struct PGMMAPPING *) pNextR0;
|
---|
427 | /** Pointer to next entry. */
|
---|
428 | RCPTRTYPE(struct PGMMAPPING *) pNextRC;
|
---|
429 | /** Indicate whether this entry is finalized. */
|
---|
430 | bool fFinalized;
|
---|
431 | /** Start Virtual address. */
|
---|
432 | RTGCPTR GCPtr;
|
---|
433 | /** Last Virtual address (inclusive). */
|
---|
434 | RTGCPTR GCPtrLast;
|
---|
435 | /** Range size (bytes). */
|
---|
436 | RTGCPTR cb;
|
---|
437 | /** Pointer to relocation callback function. */
|
---|
438 | R3PTRTYPE(PFNPGMRELOCATE) pfnRelocate;
|
---|
439 | /** User argument to the callback. */
|
---|
440 | R3PTRTYPE(void *) pvUser;
|
---|
441 | /** Mapping description / name. For easing debugging. */
|
---|
442 | R3PTRTYPE(const char *) pszDesc;
|
---|
443 | /** Last 8 addresses that caused conflicts. */
|
---|
444 | RTGCPTR aGCPtrConflicts[PGMMAPPING_CONFLICT_MAX];
|
---|
445 | /** Number of conflicts for this hypervisor mapping. */
|
---|
446 | uint32_t cConflicts;
|
---|
447 | /** Number of page tables. */
|
---|
448 | uint32_t cPTs;
|
---|
449 |
|
---|
450 | /** Array of page table mapping data. Each entry
|
---|
451 | * describes one page table. The array can be longer
|
---|
452 | * than the declared length.
|
---|
453 | */
|
---|
454 | struct
|
---|
455 | {
|
---|
456 | /** The HC physical address of the page table. */
|
---|
457 | RTHCPHYS HCPhysPT;
|
---|
458 | /** The HC physical address of the first PAE page table. */
|
---|
459 | RTHCPHYS HCPhysPaePT0;
|
---|
460 | /** The HC physical address of the second PAE page table. */
|
---|
461 | RTHCPHYS HCPhysPaePT1;
|
---|
462 | /** The HC virtual address of the 32-bit page table. */
|
---|
463 | R3PTRTYPE(PX86PT) pPTR3;
|
---|
464 | /** The HC virtual address of the two PAE page table. (i.e 1024 entries instead of 512) */
|
---|
465 | R3PTRTYPE(PX86PTPAE) paPaePTsR3;
|
---|
466 | /** The RC virtual address of the 32-bit page table. */
|
---|
467 | RCPTRTYPE(PX86PT) pPTRC;
|
---|
468 | /** The RC virtual address of the two PAE page table. */
|
---|
469 | RCPTRTYPE(PX86PTPAE) paPaePTsRC;
|
---|
470 | /** The R0 virtual address of the 32-bit page table. */
|
---|
471 | R0PTRTYPE(PX86PT) pPTR0;
|
---|
472 | /** The R0 virtual address of the two PAE page table. */
|
---|
473 | R0PTRTYPE(PX86PTPAE) paPaePTsR0;
|
---|
474 | } aPTs[1];
|
---|
475 | } PGMMAPPING;
|
---|
476 | /** Pointer to structure for tracking GC Mappings. */
|
---|
477 | typedef struct PGMMAPPING *PPGMMAPPING;
|
---|
478 |
|
---|
479 |
|
---|
480 | /**
|
---|
481 | * Physical page access handler structure.
|
---|
482 | *
|
---|
483 | * This is used to keep track of physical address ranges
|
---|
484 | * which are being monitored in some kind of way.
|
---|
485 | */
|
---|
486 | typedef struct PGMPHYSHANDLER
|
---|
487 | {
|
---|
488 | AVLROGCPHYSNODECORE Core;
|
---|
489 | /** Access type. */
|
---|
490 | PGMPHYSHANDLERTYPE enmType;
|
---|
491 | /** Number of pages to update. */
|
---|
492 | uint32_t cPages;
|
---|
493 | /** Pointer to R3 callback function. */
|
---|
494 | R3PTRTYPE(PFNPGMR3PHYSHANDLER) pfnHandlerR3;
|
---|
495 | /** User argument for R3 handlers. */
|
---|
496 | R3PTRTYPE(void *) pvUserR3;
|
---|
497 | /** Pointer to R0 callback function. */
|
---|
498 | R0PTRTYPE(PFNPGMR0PHYSHANDLER) pfnHandlerR0;
|
---|
499 | /** User argument for R0 handlers. */
|
---|
500 | R0PTRTYPE(void *) pvUserR0;
|
---|
501 | /** Pointer to RC callback function. */
|
---|
502 | RCPTRTYPE(PFNPGMRCPHYSHANDLER) pfnHandlerRC;
|
---|
503 | /** User argument for RC handlers. */
|
---|
504 | RCPTRTYPE(void *) pvUserRC;
|
---|
505 | /** Description / Name. For easing debugging. */
|
---|
506 | R3PTRTYPE(const char *) pszDesc;
|
---|
507 | #ifdef VBOX_WITH_STATISTICS
|
---|
508 | /** Profiling of this handler. */
|
---|
509 | STAMPROFILE Stat;
|
---|
510 | #endif
|
---|
511 | } PGMPHYSHANDLER;
|
---|
512 | /** Pointer to a physical page access handler structure. */
|
---|
513 | typedef PGMPHYSHANDLER *PPGMPHYSHANDLER;
|
---|
514 |
|
---|
515 |
|
---|
516 | /**
|
---|
517 | * Cache node for the physical addresses covered by a virtual handler.
|
---|
518 | */
|
---|
519 | typedef struct PGMPHYS2VIRTHANDLER
|
---|
520 | {
|
---|
521 | /** Core node for the tree based on physical ranges. */
|
---|
522 | AVLROGCPHYSNODECORE Core;
|
---|
523 | /** Offset from this struct to the PGMVIRTHANDLER structure. */
|
---|
524 | int32_t offVirtHandler;
|
---|
525 | /** Offset of the next alias relative to this one.
|
---|
526 | * Bit 0 is used for indicating whether we're in the tree.
|
---|
527 | * Bit 1 is used for indicating that we're the head node.
|
---|
528 | */
|
---|
529 | int32_t offNextAlias;
|
---|
530 | } PGMPHYS2VIRTHANDLER;
|
---|
531 | /** Pointer to a phys to virtual handler structure. */
|
---|
532 | typedef PGMPHYS2VIRTHANDLER *PPGMPHYS2VIRTHANDLER;
|
---|
533 |
|
---|
534 | /** The bit in PGMPHYS2VIRTHANDLER::offNextAlias used to indicate that the
|
---|
535 | * node is in the tree. */
|
---|
536 | #define PGMPHYS2VIRTHANDLER_IN_TREE RT_BIT(0)
|
---|
537 | /** The bit in PGMPHYS2VIRTHANDLER::offNextAlias used to indicate that the
|
---|
538 | * node is in the head of an alias chain.
|
---|
539 | * The PGMPHYS2VIRTHANDLER_IN_TREE is always set if this bit is set. */
|
---|
540 | #define PGMPHYS2VIRTHANDLER_IS_HEAD RT_BIT(1)
|
---|
541 | /** The mask to apply to PGMPHYS2VIRTHANDLER::offNextAlias to get the offset. */
|
---|
542 | #define PGMPHYS2VIRTHANDLER_OFF_MASK (~(int32_t)3)
|
---|
543 |
|
---|
544 |
|
---|
545 | /**
|
---|
546 | * Virtual page access handler structure.
|
---|
547 | *
|
---|
548 | * This is used to keep track of virtual address ranges
|
---|
549 | * which are being monitored in some kind of way.
|
---|
550 | */
|
---|
551 | typedef struct PGMVIRTHANDLER
|
---|
552 | {
|
---|
553 | /** Core node for the tree based on virtual ranges. */
|
---|
554 | AVLROGCPTRNODECORE Core;
|
---|
555 | /** Size of the range (in bytes). */
|
---|
556 | RTGCPTR cb;
|
---|
557 | /** Number of cache pages. */
|
---|
558 | uint32_t cPages;
|
---|
559 | /** Access type. */
|
---|
560 | PGMVIRTHANDLERTYPE enmType;
|
---|
561 | /** Pointer to the RC callback function. */
|
---|
562 | RCPTRTYPE(PFNPGMRCVIRTHANDLER) pfnHandlerRC;
|
---|
563 | #if HC_ARCH_BITS == 64
|
---|
564 | RTRCPTR padding;
|
---|
565 | #endif
|
---|
566 | /** Pointer to the R3 callback function for invalidation. */
|
---|
567 | R3PTRTYPE(PFNPGMR3VIRTINVALIDATE) pfnInvalidateR3;
|
---|
568 | /** Pointer to the R3 callback function. */
|
---|
569 | R3PTRTYPE(PFNPGMR3VIRTHANDLER) pfnHandlerR3;
|
---|
570 | /** Description / Name. For easing debugging. */
|
---|
571 | R3PTRTYPE(const char *) pszDesc;
|
---|
572 | #ifdef VBOX_WITH_STATISTICS
|
---|
573 | /** Profiling of this handler. */
|
---|
574 | STAMPROFILE Stat;
|
---|
575 | #endif
|
---|
576 | /** Array of cached physical addresses for the monitored ranged. */
|
---|
577 | PGMPHYS2VIRTHANDLER aPhysToVirt[HC_ARCH_BITS == 32 ? 1 : 2];
|
---|
578 | } PGMVIRTHANDLER;
|
---|
579 | /** Pointer to a virtual page access handler structure. */
|
---|
580 | typedef PGMVIRTHANDLER *PPGMVIRTHANDLER;
|
---|
581 |
|
---|
582 |
|
---|
583 | /**
|
---|
584 | * Page type.
|
---|
585 | *
|
---|
586 | * @remarks This enum has to fit in a 3-bit field (see PGMPAGE::u3Type).
|
---|
587 | * @remarks This is used in the saved state, so changes to it requires bumping
|
---|
588 | * the saved state version.
|
---|
589 | * @todo So, convert to \#defines!
|
---|
590 | */
|
---|
591 | typedef enum PGMPAGETYPE
|
---|
592 | {
|
---|
593 | /** The usual invalid zero entry. */
|
---|
594 | PGMPAGETYPE_INVALID = 0,
|
---|
595 | /** RAM page. (RWX) */
|
---|
596 | PGMPAGETYPE_RAM,
|
---|
597 | /** MMIO2 page. (RWX) */
|
---|
598 | PGMPAGETYPE_MMIO2,
|
---|
599 | /** MMIO2 page aliased over an MMIO page. (RWX)
|
---|
600 | * See PGMHandlerPhysicalPageAlias(). */
|
---|
601 | PGMPAGETYPE_MMIO2_ALIAS_MMIO,
|
---|
602 | /** Shadowed ROM. (RWX) */
|
---|
603 | PGMPAGETYPE_ROM_SHADOW,
|
---|
604 | /** ROM page. (R-X) */
|
---|
605 | PGMPAGETYPE_ROM,
|
---|
606 | /** MMIO page. (---) */
|
---|
607 | PGMPAGETYPE_MMIO,
|
---|
608 | /** End of valid entries. */
|
---|
609 | PGMPAGETYPE_END
|
---|
610 | } PGMPAGETYPE;
|
---|
611 | AssertCompile(PGMPAGETYPE_END <= 7);
|
---|
612 |
|
---|
613 | /** @name Page type predicates.
|
---|
614 | * @{ */
|
---|
615 | #define PGMPAGETYPE_IS_READABLE(type) ( (type) <= PGMPAGETYPE_ROM )
|
---|
616 | #define PGMPAGETYPE_IS_WRITEABLE(type) ( (type) <= PGMPAGETYPE_ROM_SHADOW )
|
---|
617 | #define PGMPAGETYPE_IS_RWX(type) ( (type) <= PGMPAGETYPE_ROM_SHADOW )
|
---|
618 | #define PGMPAGETYPE_IS_ROX(type) ( (type) == PGMPAGETYPE_ROM )
|
---|
619 | #define PGMPAGETYPE_IS_NP(type) ( (type) == PGMPAGETYPE_MMIO )
|
---|
620 | /** @} */
|
---|
621 |
|
---|
622 |
|
---|
623 | /**
|
---|
624 | * A Physical Guest Page tracking structure.
|
---|
625 | *
|
---|
626 | * The format of this structure is complicated because we have to fit a lot
|
---|
627 | * of information into as few bits as possible. The format is also subject
|
---|
628 | * to change (there is one comming up soon). Which means that for we'll be
|
---|
629 | * using PGM_PAGE_GET_*, PGM_PAGE_IS_ and PGM_PAGE_SET_* macros for *all*
|
---|
630 | * accessess to the structure.
|
---|
631 | */
|
---|
632 | typedef struct PGMPAGE
|
---|
633 | {
|
---|
634 | /** The physical address and a whole lot of other stuff. All bits are used! */
|
---|
635 | RTHCPHYS HCPhysX;
|
---|
636 | /** The page state. */
|
---|
637 | uint32_t u2StateX : 2;
|
---|
638 | /** Flag indicating that a write monitored page was written to when set. */
|
---|
639 | uint32_t fWrittenToX : 1;
|
---|
640 | /** For later. */
|
---|
641 | uint32_t fSomethingElse : 1;
|
---|
642 | /** The Page ID.
|
---|
643 | * @todo Merge with HCPhysX once we've liberated HCPhysX of its stuff.
|
---|
644 | * The HCPhysX will then be 100% static. */
|
---|
645 | uint32_t idPageX : 28;
|
---|
646 | /** The page type (PGMPAGETYPE). */
|
---|
647 | uint32_t u3Type : 3;
|
---|
648 | /** The physical handler state (PGM_PAGE_HNDL_PHYS_STATE*) */
|
---|
649 | uint32_t u2HandlerPhysStateX : 2;
|
---|
650 | /** The virtual handler state (PGM_PAGE_HNDL_VIRT_STATE*) */
|
---|
651 | uint32_t u2HandlerVirtStateX : 2;
|
---|
652 | uint32_t u29B : 25;
|
---|
653 | } PGMPAGE;
|
---|
654 | AssertCompileSize(PGMPAGE, 16);
|
---|
655 | /** Pointer to a physical guest page. */
|
---|
656 | typedef PGMPAGE *PPGMPAGE;
|
---|
657 | /** Pointer to a const physical guest page. */
|
---|
658 | typedef const PGMPAGE *PCPGMPAGE;
|
---|
659 | /** Pointer to a physical guest page pointer. */
|
---|
660 | typedef PPGMPAGE *PPPGMPAGE;
|
---|
661 |
|
---|
662 |
|
---|
663 | /**
|
---|
664 | * Clears the page structure.
|
---|
665 | * @param pPage Pointer to the physical guest page tracking structure.
|
---|
666 | */
|
---|
667 | #define PGM_PAGE_CLEAR(pPage) \
|
---|
668 | do { \
|
---|
669 | (pPage)->HCPhysX = 0; \
|
---|
670 | (pPage)->u2StateX = 0; \
|
---|
671 | (pPage)->fWrittenToX = 0; \
|
---|
672 | (pPage)->fSomethingElse = 0; \
|
---|
673 | (pPage)->idPageX = 0; \
|
---|
674 | (pPage)->u3Type = 0; \
|
---|
675 | (pPage)->u29B = 0; \
|
---|
676 | } while (0)
|
---|
677 |
|
---|
678 | /**
|
---|
679 | * Initializes the page structure.
|
---|
680 | * @param pPage Pointer to the physical guest page tracking structure.
|
---|
681 | */
|
---|
682 | #define PGM_PAGE_INIT(pPage, _HCPhys, _idPage, _uType, _uState) \
|
---|
683 | do { \
|
---|
684 | (pPage)->HCPhysX = (_HCPhys); \
|
---|
685 | (pPage)->u2StateX = (_uState); \
|
---|
686 | (pPage)->fWrittenToX = 0; \
|
---|
687 | (pPage)->fSomethingElse = 0; \
|
---|
688 | (pPage)->idPageX = (_idPage); \
|
---|
689 | /*(pPage)->u3Type = (_uType); - later */ \
|
---|
690 | PGM_PAGE_SET_TYPE(pPage, _uType); \
|
---|
691 | (pPage)->u29B = 0; \
|
---|
692 | } while (0)
|
---|
693 |
|
---|
694 | /**
|
---|
695 | * Initializes the page structure of a ZERO page.
|
---|
696 | * @param pPage Pointer to the physical guest page tracking structure.
|
---|
697 | */
|
---|
698 | #define PGM_PAGE_INIT_ZERO(pPage, pVM, _uType) \
|
---|
699 | PGM_PAGE_INIT(pPage, (pVM)->pgm.s.HCPhysZeroPg, NIL_GMM_PAGEID, (_uType), PGM_PAGE_STATE_ZERO)
|
---|
700 | /** Temporary hack. Replaced by PGM_PAGE_INIT_ZERO once the old code is kicked out. */
|
---|
701 | # define PGM_PAGE_INIT_ZERO_REAL(pPage, pVM, _uType) \
|
---|
702 | PGM_PAGE_INIT(pPage, (pVM)->pgm.s.HCPhysZeroPg, NIL_GMM_PAGEID, (_uType), PGM_PAGE_STATE_ZERO)
|
---|
703 |
|
---|
704 |
|
---|
705 | /** @name The Page state, PGMPAGE::u2StateX.
|
---|
706 | * @{ */
|
---|
707 | /** The zero page.
|
---|
708 | * This is a per-VM page that's never ever mapped writable. */
|
---|
709 | #define PGM_PAGE_STATE_ZERO 0
|
---|
710 | /** A allocated page.
|
---|
711 | * This is a per-VM page allocated from the page pool (or wherever
|
---|
712 | * we get MMIO2 pages from if the type is MMIO2).
|
---|
713 | */
|
---|
714 | #define PGM_PAGE_STATE_ALLOCATED 1
|
---|
715 | /** A allocated page that's being monitored for writes.
|
---|
716 | * The shadow page table mappings are read-only. When a write occurs, the
|
---|
717 | * fWrittenTo member is set, the page remapped as read-write and the state
|
---|
718 | * moved back to allocated. */
|
---|
719 | #define PGM_PAGE_STATE_WRITE_MONITORED 2
|
---|
720 | /** The page is shared, aka. copy-on-write.
|
---|
721 | * This is a page that's shared with other VMs. */
|
---|
722 | #define PGM_PAGE_STATE_SHARED 3
|
---|
723 | /** @} */
|
---|
724 |
|
---|
725 |
|
---|
726 | /**
|
---|
727 | * Gets the page state.
|
---|
728 | * @returns page state (PGM_PAGE_STATE_*).
|
---|
729 | * @param pPage Pointer to the physical guest page tracking structure.
|
---|
730 | */
|
---|
731 | #define PGM_PAGE_GET_STATE(pPage) ( (pPage)->u2StateX )
|
---|
732 |
|
---|
733 | /**
|
---|
734 | * Sets the page state.
|
---|
735 | * @param pPage Pointer to the physical guest page tracking structure.
|
---|
736 | * @param _uState The new page state.
|
---|
737 | */
|
---|
738 | #define PGM_PAGE_SET_STATE(pPage, _uState) \
|
---|
739 | do { (pPage)->u2StateX = (_uState); } while (0)
|
---|
740 |
|
---|
741 |
|
---|
742 | /**
|
---|
743 | * Gets the host physical address of the guest page.
|
---|
744 | * @returns host physical address (RTHCPHYS).
|
---|
745 | * @param pPage Pointer to the physical guest page tracking structure.
|
---|
746 | */
|
---|
747 | #define PGM_PAGE_GET_HCPHYS(pPage) ( (pPage)->HCPhysX & UINT64_C(0x0000fffffffff000) )
|
---|
748 |
|
---|
749 | /**
|
---|
750 | * Sets the host physical address of the guest page.
|
---|
751 | * @param pPage Pointer to the physical guest page tracking structure.
|
---|
752 | * @param _HCPhys The new host physical address.
|
---|
753 | */
|
---|
754 | #define PGM_PAGE_SET_HCPHYS(pPage, _HCPhys) \
|
---|
755 | do { (pPage)->HCPhysX = (((pPage)->HCPhysX) & UINT64_C(0xffff000000000fff)) \
|
---|
756 | | ((_HCPhys) & UINT64_C(0x0000fffffffff000)); } while (0)
|
---|
757 |
|
---|
758 | /**
|
---|
759 | * Get the Page ID.
|
---|
760 | * @returns The Page ID; NIL_GMM_PAGEID if it's a ZERO page.
|
---|
761 | * @param pPage Pointer to the physical guest page tracking structure.
|
---|
762 | */
|
---|
763 | #define PGM_PAGE_GET_PAGEID(pPage) ( (pPage)->idPageX )
|
---|
764 | /* later:
|
---|
765 | #define PGM_PAGE_GET_PAGEID(pPage) ( ((uint32_t)(pPage)->HCPhysX >> (48 - 12))
|
---|
766 | | ((uint32_t)(pPage)->HCPhysX & 0xfff) )
|
---|
767 | */
|
---|
768 | /**
|
---|
769 | * Sets the Page ID.
|
---|
770 | * @param pPage Pointer to the physical guest page tracking structure.
|
---|
771 | */
|
---|
772 | #define PGM_PAGE_SET_PAGEID(pPage, _idPage) do { (pPage)->idPageX = (_idPage); } while (0)
|
---|
773 | /* later:
|
---|
774 | #define PGM_PAGE_SET_PAGEID(pPage, _idPage) do { (pPage)->HCPhysX = (((pPage)->HCPhysX) & UINT64_C(0x0000fffffffff000)) \
|
---|
775 | | ((_idPage) & 0xfff) \
|
---|
776 | | (((_idPage) & 0x0ffff000) << (48-12)); } while (0)
|
---|
777 | */
|
---|
778 |
|
---|
779 | /**
|
---|
780 | * Get the Chunk ID.
|
---|
781 | * @returns The Chunk ID; NIL_GMM_CHUNKID if it's a ZERO page.
|
---|
782 | * @param pPage Pointer to the physical guest page tracking structure.
|
---|
783 | */
|
---|
784 | #define PGM_PAGE_GET_CHUNKID(pPage) ( (pPage)->idPageX >> GMM_CHUNKID_SHIFT )
|
---|
785 | /* later:
|
---|
786 | #if GMM_CHUNKID_SHIFT == 12
|
---|
787 | # define PGM_PAGE_GET_CHUNKID(pPage) ( (uint32_t)((pPage)->HCPhysX >> 48) )
|
---|
788 | #elif GMM_CHUNKID_SHIFT > 12
|
---|
789 | # define PGM_PAGE_GET_CHUNKID(pPage) ( (uint32_t)((pPage)->HCPhysX >> (48 + (GMM_CHUNKID_SHIFT - 12)) )
|
---|
790 | #elif GMM_CHUNKID_SHIFT < 12
|
---|
791 | # define PGM_PAGE_GET_CHUNKID(pPage) ( ( (uint32_t)((pPage)->HCPhysX >> 48) << (12 - GMM_CHUNKID_SHIFT) ) \
|
---|
792 | | ( (uint32_t)((pPage)->HCPhysX & 0xfff) >> GMM_CHUNKID_SHIFT ) )
|
---|
793 | #else
|
---|
794 | # error "GMM_CHUNKID_SHIFT isn't defined or something."
|
---|
795 | #endif
|
---|
796 | */
|
---|
797 |
|
---|
798 | /**
|
---|
799 | * Get the index of the page within the allocaiton chunk.
|
---|
800 | * @returns The page index.
|
---|
801 | * @param pPage Pointer to the physical guest page tracking structure.
|
---|
802 | */
|
---|
803 | #define PGM_PAGE_GET_PAGE_IN_CHUNK(pPage) ( (pPage)->idPageX & GMM_PAGEID_IDX_MASK )
|
---|
804 | /* later:
|
---|
805 | #if GMM_CHUNKID_SHIFT <= 12
|
---|
806 | # define PGM_PAGE_GET_PAGE_IN_CHUNK(pPage) ( (uint32_t)((pPage)->HCPhysX & GMM_PAGEID_IDX_MASK) )
|
---|
807 | #else
|
---|
808 | # define PGM_PAGE_GET_PAGE_IN_CHUNK(pPage) ( (uint32_t)((pPage)->HCPhysX & 0xfff) \
|
---|
809 | | ( (uint32_t)((pPage)->HCPhysX >> 48) & (RT_BIT_32(GMM_CHUNKID_SHIFT - 12) - 1) ) )
|
---|
810 | #endif
|
---|
811 | */
|
---|
812 |
|
---|
813 |
|
---|
814 | /**
|
---|
815 | * Gets the page type.
|
---|
816 | * @returns The page type.
|
---|
817 | * @param pPage Pointer to the physical guest page tracking structure.
|
---|
818 | */
|
---|
819 | #define PGM_PAGE_GET_TYPE(pPage) (pPage)->u3Type
|
---|
820 |
|
---|
821 | /**
|
---|
822 | * Sets the page type.
|
---|
823 | * @param pPage Pointer to the physical guest page tracking structure.
|
---|
824 | * @param _enmType The new page type (PGMPAGETYPE).
|
---|
825 | */
|
---|
826 | #define PGM_PAGE_SET_TYPE(pPage, _enmType) \
|
---|
827 | do { (pPage)->u3Type = (_enmType); } while (0)
|
---|
828 |
|
---|
829 | /**
|
---|
830 | * Checks if the page is marked for MMIO.
|
---|
831 | * @returns true/false.
|
---|
832 | * @param pPage Pointer to the physical guest page tracking structure.
|
---|
833 | */
|
---|
834 | #define PGM_PAGE_IS_MMIO(pPage) ( (pPage)->u3Type == PGMPAGETYPE_MMIO )
|
---|
835 |
|
---|
836 | /**
|
---|
837 | * Checks if the page is backed by the ZERO page.
|
---|
838 | * @returns true/false.
|
---|
839 | * @param pPage Pointer to the physical guest page tracking structure.
|
---|
840 | */
|
---|
841 | #define PGM_PAGE_IS_ZERO(pPage) ( (pPage)->u2StateX == PGM_PAGE_STATE_ZERO )
|
---|
842 |
|
---|
843 | /**
|
---|
844 | * Checks if the page is backed by a SHARED page.
|
---|
845 | * @returns true/false.
|
---|
846 | * @param pPage Pointer to the physical guest page tracking structure.
|
---|
847 | */
|
---|
848 | #define PGM_PAGE_IS_SHARED(pPage) ( (pPage)->u2StateX == PGM_PAGE_STATE_SHARED )
|
---|
849 |
|
---|
850 |
|
---|
851 | /**
|
---|
852 | * Marks the paget as written to (for GMM change monitoring).
|
---|
853 | * @param pPage Pointer to the physical guest page tracking structure.
|
---|
854 | */
|
---|
855 | #define PGM_PAGE_SET_WRITTEN_TO(pPage) do { (pPage)->fWrittenToX = 1; } while (0)
|
---|
856 |
|
---|
857 | /**
|
---|
858 | * Clears the written-to indicator.
|
---|
859 | * @param pPage Pointer to the physical guest page tracking structure.
|
---|
860 | */
|
---|
861 | #define PGM_PAGE_CLEAR_WRITTEN_TO(pPage) do { (pPage)->fWrittenToX = 0; } while (0)
|
---|
862 |
|
---|
863 | /**
|
---|
864 | * Checks if the page was marked as written-to.
|
---|
865 | * @returns true/false.
|
---|
866 | * @param pPage Pointer to the physical guest page tracking structure.
|
---|
867 | */
|
---|
868 | #define PGM_PAGE_IS_WRITTEN_TO(pPage) ( (pPage)->fWrittenToX )
|
---|
869 |
|
---|
870 |
|
---|
871 | /** @name Physical Access Handler State values (PGMPAGE::u2HandlerPhysStateX).
|
---|
872 | *
|
---|
873 | * @remarks The values are assigned in order of priority, so we can calculate
|
---|
874 | * the correct state for a page with different handlers installed.
|
---|
875 | * @{ */
|
---|
876 | /** No handler installed. */
|
---|
877 | #define PGM_PAGE_HNDL_PHYS_STATE_NONE 0
|
---|
878 | /** Monitoring is temporarily disabled. */
|
---|
879 | #define PGM_PAGE_HNDL_PHYS_STATE_DISABLED 1
|
---|
880 | /** Write access is monitored. */
|
---|
881 | #define PGM_PAGE_HNDL_PHYS_STATE_WRITE 2
|
---|
882 | /** All access is monitored. */
|
---|
883 | #define PGM_PAGE_HNDL_PHYS_STATE_ALL 3
|
---|
884 | /** @} */
|
---|
885 |
|
---|
886 | /**
|
---|
887 | * Gets the physical access handler state of a page.
|
---|
888 | * @returns PGM_PAGE_HNDL_PHYS_STATE_* value.
|
---|
889 | * @param pPage Pointer to the physical guest page tracking structure.
|
---|
890 | */
|
---|
891 | #define PGM_PAGE_GET_HNDL_PHYS_STATE(pPage) ( (pPage)->u2HandlerPhysStateX )
|
---|
892 |
|
---|
893 | /**
|
---|
894 | * Sets the physical access handler state of a page.
|
---|
895 | * @param pPage Pointer to the physical guest page tracking structure.
|
---|
896 | * @param _uState The new state value.
|
---|
897 | */
|
---|
898 | #define PGM_PAGE_SET_HNDL_PHYS_STATE(pPage, _uState) \
|
---|
899 | do { (pPage)->u2HandlerPhysStateX = (_uState); } while (0)
|
---|
900 |
|
---|
901 | /**
|
---|
902 | * Checks if the page has any physical access handlers, including temporariliy disabled ones.
|
---|
903 | * @returns true/false
|
---|
904 | * @param pPage Pointer to the physical guest page tracking structure.
|
---|
905 | */
|
---|
906 | #define PGM_PAGE_HAS_ANY_PHYSICAL_HANDLERS(pPage) ( (pPage)->u2HandlerPhysStateX != PGM_PAGE_HNDL_PHYS_STATE_NONE )
|
---|
907 |
|
---|
908 | /**
|
---|
909 | * Checks if the page has any active physical access handlers.
|
---|
910 | * @returns true/false
|
---|
911 | * @param pPage Pointer to the physical guest page tracking structure.
|
---|
912 | */
|
---|
913 | #define PGM_PAGE_HAS_ACTIVE_PHYSICAL_HANDLERS(pPage) ( (pPage)->u2HandlerPhysStateX >= PGM_PAGE_HNDL_PHYS_STATE_WRITE )
|
---|
914 |
|
---|
915 |
|
---|
916 | /** @name Virtual Access Handler State values (PGMPAGE::u2HandlerVirtStateX).
|
---|
917 | *
|
---|
918 | * @remarks The values are assigned in order of priority, so we can calculate
|
---|
919 | * the correct state for a page with different handlers installed.
|
---|
920 | * @{ */
|
---|
921 | /** No handler installed. */
|
---|
922 | #define PGM_PAGE_HNDL_VIRT_STATE_NONE 0
|
---|
923 | /* 1 is reserved so the lineup is identical with the physical ones. */
|
---|
924 | /** Write access is monitored. */
|
---|
925 | #define PGM_PAGE_HNDL_VIRT_STATE_WRITE 2
|
---|
926 | /** All access is monitored. */
|
---|
927 | #define PGM_PAGE_HNDL_VIRT_STATE_ALL 3
|
---|
928 | /** @} */
|
---|
929 |
|
---|
930 | /**
|
---|
931 | * Gets the virtual access handler state of a page.
|
---|
932 | * @returns PGM_PAGE_HNDL_VIRT_STATE_* value.
|
---|
933 | * @param pPage Pointer to the physical guest page tracking structure.
|
---|
934 | */
|
---|
935 | #define PGM_PAGE_GET_HNDL_VIRT_STATE(pPage) ( (pPage)->u2HandlerVirtStateX )
|
---|
936 |
|
---|
937 | /**
|
---|
938 | * Sets the virtual access handler state of a page.
|
---|
939 | * @param pPage Pointer to the physical guest page tracking structure.
|
---|
940 | * @param _uState The new state value.
|
---|
941 | */
|
---|
942 | #define PGM_PAGE_SET_HNDL_VIRT_STATE(pPage, _uState) \
|
---|
943 | do { (pPage)->u2HandlerVirtStateX = (_uState); } while (0)
|
---|
944 |
|
---|
945 | /**
|
---|
946 | * Checks if the page has any virtual access handlers.
|
---|
947 | * @returns true/false
|
---|
948 | * @param pPage Pointer to the physical guest page tracking structure.
|
---|
949 | */
|
---|
950 | #define PGM_PAGE_HAS_ANY_VIRTUAL_HANDLERS(pPage) ( (pPage)->u2HandlerVirtStateX != PGM_PAGE_HNDL_VIRT_STATE_NONE )
|
---|
951 |
|
---|
952 | /**
|
---|
953 | * Same as PGM_PAGE_HAS_ANY_VIRTUAL_HANDLERS - can't disable pages in
|
---|
954 | * virtual handlers.
|
---|
955 | * @returns true/false
|
---|
956 | * @param pPage Pointer to the physical guest page tracking structure.
|
---|
957 | */
|
---|
958 | #define PGM_PAGE_HAS_ACTIVE_VIRTUAL_HANDLERS(pPage) PGM_PAGE_HAS_ANY_VIRTUAL_HANDLERS(pPage)
|
---|
959 |
|
---|
960 |
|
---|
961 |
|
---|
962 | /**
|
---|
963 | * Checks if the page has any access handlers, including temporarily disabled ones.
|
---|
964 | * @returns true/false
|
---|
965 | * @param pPage Pointer to the physical guest page tracking structure.
|
---|
966 | */
|
---|
967 | #define PGM_PAGE_HAS_ANY_HANDLERS(pPage) \
|
---|
968 | ( (pPage)->u2HandlerPhysStateX != PGM_PAGE_HNDL_PHYS_STATE_NONE \
|
---|
969 | || (pPage)->u2HandlerVirtStateX != PGM_PAGE_HNDL_VIRT_STATE_NONE )
|
---|
970 |
|
---|
971 | /**
|
---|
972 | * Checks if the page has any active access handlers.
|
---|
973 | * @returns true/false
|
---|
974 | * @param pPage Pointer to the physical guest page tracking structure.
|
---|
975 | */
|
---|
976 | #define PGM_PAGE_HAS_ACTIVE_HANDLERS(pPage) \
|
---|
977 | ( (pPage)->u2HandlerPhysStateX >= PGM_PAGE_HNDL_PHYS_STATE_WRITE \
|
---|
978 | || (pPage)->u2HandlerVirtStateX >= PGM_PAGE_HNDL_VIRT_STATE_WRITE )
|
---|
979 |
|
---|
980 | /**
|
---|
981 | * Checks if the page has any active access handlers catching all accesses.
|
---|
982 | * @returns true/false
|
---|
983 | * @param pPage Pointer to the physical guest page tracking structure.
|
---|
984 | */
|
---|
985 | #define PGM_PAGE_HAS_ACTIVE_ALL_HANDLERS(pPage) \
|
---|
986 | ( (pPage)->u2HandlerPhysStateX == PGM_PAGE_HNDL_PHYS_STATE_ALL \
|
---|
987 | || (pPage)->u2HandlerVirtStateX == PGM_PAGE_HNDL_VIRT_STATE_ALL )
|
---|
988 |
|
---|
989 |
|
---|
990 |
|
---|
991 |
|
---|
992 | /** @def PGM_PAGE_GET_TRACKING
|
---|
993 | * Gets the packed shadow page pool tracking data associated with a guest page.
|
---|
994 | * @returns uint16_t containing the data.
|
---|
995 | * @param pPage Pointer to the physical guest page tracking structure.
|
---|
996 | */
|
---|
997 | #define PGM_PAGE_GET_TRACKING(pPage) \
|
---|
998 | ( *((uint16_t *)&(pPage)->HCPhysX + 3) )
|
---|
999 |
|
---|
1000 | /** @def PGM_PAGE_SET_TRACKING
|
---|
1001 | * Sets the packed shadow page pool tracking data associated with a guest page.
|
---|
1002 | * @param pPage Pointer to the physical guest page tracking structure.
|
---|
1003 | * @param u16TrackingData The tracking data to store.
|
---|
1004 | */
|
---|
1005 | #define PGM_PAGE_SET_TRACKING(pPage, u16TrackingData) \
|
---|
1006 | do { *((uint16_t *)&(pPage)->HCPhysX + 3) = (u16TrackingData); } while (0)
|
---|
1007 |
|
---|
1008 | /** @def PGM_PAGE_GET_TD_CREFS
|
---|
1009 | * Gets the @a cRefs tracking data member.
|
---|
1010 | * @returns cRefs.
|
---|
1011 | * @param pPage Pointer to the physical guest page tracking structure.
|
---|
1012 | */
|
---|
1013 | #define PGM_PAGE_GET_TD_CREFS(pPage) \
|
---|
1014 | ((PGM_PAGE_GET_TRACKING(pPage) >> PGMPOOL_TD_CREFS_SHIFT) & PGMPOOL_TD_CREFS_MASK)
|
---|
1015 |
|
---|
1016 | #define PGM_PAGE_GET_TD_IDX(pPage) \
|
---|
1017 | ((PGM_PAGE_GET_TRACKING(pPage) >> PGMPOOL_TD_IDX_SHIFT) & PGMPOOL_TD_IDX_MASK)
|
---|
1018 |
|
---|
1019 | /**
|
---|
1020 | * Per page live save tracking data.
|
---|
1021 | */
|
---|
1022 | typedef struct PGMLIVESAVEPAGE
|
---|
1023 | {
|
---|
1024 | /** The pass number where this page was last saved. */
|
---|
1025 | uint32_t uPassSaved;
|
---|
1026 | /** Number of times it has been dirtied. */
|
---|
1027 | uint32_t cDirtied : 24;
|
---|
1028 | /** Whether it is currently dirty. */
|
---|
1029 | uint32_t fDirty : 1;
|
---|
1030 | /** Is or has been a MMIO/MMIO2 and is not worth saving. */
|
---|
1031 | uint32_t fMmio : 1;
|
---|
1032 | /** Was a ZERO page last time around. */
|
---|
1033 | uint32_t fZero : 1;
|
---|
1034 | /** Bits reserved for future use. */
|
---|
1035 | uint32_t u5Reserved : 5;
|
---|
1036 | } PGMLIVESAVEPAGE;
|
---|
1037 | AssertCompileSize(PGMLIVESAVEPAGE, 8);
|
---|
1038 | /** Pointer to the per page live save tracking data. */
|
---|
1039 | typedef PGMLIVESAVEPAGE *PPGMLIVESAVEPAGE;
|
---|
1040 |
|
---|
1041 |
|
---|
1042 | /**
|
---|
1043 | * Ram range for GC Phys to HC Phys conversion.
|
---|
1044 | *
|
---|
1045 | * Can be used for HC Virt to GC Phys and HC Virt to HC Phys
|
---|
1046 | * conversions too, but we'll let MM handle that for now.
|
---|
1047 | *
|
---|
1048 | * This structure is used by linked lists in both GC and HC.
|
---|
1049 | */
|
---|
1050 | typedef struct PGMRAMRANGE
|
---|
1051 | {
|
---|
1052 | /** Start of the range. Page aligned. */
|
---|
1053 | RTGCPHYS GCPhys;
|
---|
1054 | /** Size of the range. (Page aligned of course). */
|
---|
1055 | RTGCPHYS cb;
|
---|
1056 | /** Pointer to the next RAM range - for R3. */
|
---|
1057 | R3PTRTYPE(struct PGMRAMRANGE *) pNextR3;
|
---|
1058 | /** Pointer to the next RAM range - for R0. */
|
---|
1059 | R0PTRTYPE(struct PGMRAMRANGE *) pNextR0;
|
---|
1060 | /** Pointer to the next RAM range - for RC. */
|
---|
1061 | RCPTRTYPE(struct PGMRAMRANGE *) pNextRC;
|
---|
1062 | /** PGM_RAM_RANGE_FLAGS_* flags. */
|
---|
1063 | uint32_t fFlags;
|
---|
1064 | /** Last address in the range (inclusive). Page aligned (-1). */
|
---|
1065 | RTGCPHYS GCPhysLast;
|
---|
1066 | /** Start of the HC mapping of the range. This is only used for MMIO2. */
|
---|
1067 | R3PTRTYPE(void *) pvR3;
|
---|
1068 | /** Live save per page tracking data. */
|
---|
1069 | R3PTRTYPE(PPGMLIVESAVEPAGE) paLSPages;
|
---|
1070 | /** The range description. */
|
---|
1071 | R3PTRTYPE(const char *) pszDesc;
|
---|
1072 | /** Pointer to self - R0 pointer. */
|
---|
1073 | R0PTRTYPE(struct PGMRAMRANGE *) pSelfR0;
|
---|
1074 | /** Pointer to self - RC pointer. */
|
---|
1075 | RCPTRTYPE(struct PGMRAMRANGE *) pSelfRC;
|
---|
1076 | /** Padding to make aPage aligned on sizeof(PGMPAGE). */
|
---|
1077 | uint32_t au32Alignment2[HC_ARCH_BITS == 32 ? 1 : 3];
|
---|
1078 | /** Array of physical guest page tracking structures. */
|
---|
1079 | PGMPAGE aPages[1];
|
---|
1080 | } PGMRAMRANGE;
|
---|
1081 | /** Pointer to Ram range for GC Phys to HC Phys conversion. */
|
---|
1082 | typedef PGMRAMRANGE *PPGMRAMRANGE;
|
---|
1083 |
|
---|
1084 | /** @name PGMRAMRANGE::fFlags
|
---|
1085 | * @{ */
|
---|
1086 | /** The RAM range is floating around as an independent guest mapping. */
|
---|
1087 | #define PGM_RAM_RANGE_FLAGS_FLOATING RT_BIT(20)
|
---|
1088 | /** Ad hoc RAM range for an ROM mapping. */
|
---|
1089 | #define PGM_RAM_RANGE_FLAGS_AD_HOC_ROM RT_BIT(21)
|
---|
1090 | /** Ad hoc RAM range for an MMIO mapping. */
|
---|
1091 | #define PGM_RAM_RANGE_FLAGS_AD_HOC_MMIO RT_BIT(22)
|
---|
1092 | /** Ad hoc RAM range for an MMIO2 mapping. */
|
---|
1093 | #define PGM_RAM_RANGE_FLAGS_AD_HOC_MMIO2 RT_BIT(23)
|
---|
1094 | /** @} */
|
---|
1095 |
|
---|
1096 | /** Tests if a RAM range is an ad hoc one or not.
|
---|
1097 | * @returns true/false.
|
---|
1098 | * @param pRam The RAM range.
|
---|
1099 | */
|
---|
1100 | #define PGM_RAM_RANGE_IS_AD_HOC(pRam) \
|
---|
1101 | (!!( (pRam)->fFlags & (PGM_RAM_RANGE_FLAGS_AD_HOC_ROM | PGM_RAM_RANGE_FLAGS_AD_HOC_MMIO | PGM_RAM_RANGE_FLAGS_AD_HOC_MMIO2) ) )
|
---|
1102 |
|
---|
1103 |
|
---|
1104 | /**
|
---|
1105 | * Per page tracking structure for ROM image.
|
---|
1106 | *
|
---|
1107 | * A ROM image may have a shadow page, in which case we may have
|
---|
1108 | * two pages backing it. This structure contains the PGMPAGE for
|
---|
1109 | * both while PGMRAMRANGE have a copy of the active one. It is
|
---|
1110 | * important that these aren't out of sync in any regard other
|
---|
1111 | * than page pool tracking data.
|
---|
1112 | */
|
---|
1113 | typedef struct PGMROMPAGE
|
---|
1114 | {
|
---|
1115 | /** The page structure for the virgin ROM page. */
|
---|
1116 | PGMPAGE Virgin;
|
---|
1117 | /** The page structure for the shadow RAM page. */
|
---|
1118 | PGMPAGE Shadow;
|
---|
1119 | /** The current protection setting. */
|
---|
1120 | PGMROMPROT enmProt;
|
---|
1121 | /** Pad the structure size to a multiple of 8. */
|
---|
1122 | uint32_t u32Padding;
|
---|
1123 | } PGMROMPAGE;
|
---|
1124 | /** Pointer to a ROM page tracking structure. */
|
---|
1125 | typedef PGMROMPAGE *PPGMROMPAGE;
|
---|
1126 |
|
---|
1127 |
|
---|
1128 | /**
|
---|
1129 | * A registered ROM image.
|
---|
1130 | *
|
---|
1131 | * This is needed to keep track of ROM image since they generally
|
---|
1132 | * intrude into a PGMRAMRANGE. It also keeps track of additional
|
---|
1133 | * info like the two page sets (read-only virgin and read-write shadow),
|
---|
1134 | * the current state of each page.
|
---|
1135 | *
|
---|
1136 | * Because access handlers cannot easily be executed in a different
|
---|
1137 | * context, the ROM ranges needs to be accessible and in all contexts.
|
---|
1138 | */
|
---|
1139 | typedef struct PGMROMRANGE
|
---|
1140 | {
|
---|
1141 | /** Pointer to the next range - R3. */
|
---|
1142 | R3PTRTYPE(struct PGMROMRANGE *) pNextR3;
|
---|
1143 | /** Pointer to the next range - R0. */
|
---|
1144 | R0PTRTYPE(struct PGMROMRANGE *) pNextR0;
|
---|
1145 | /** Pointer to the next range - RC. */
|
---|
1146 | RCPTRTYPE(struct PGMROMRANGE *) pNextRC;
|
---|
1147 | /** Pointer alignment */
|
---|
1148 | RTRCPTR GCPtrAlignment;
|
---|
1149 | /** Address of the range. */
|
---|
1150 | RTGCPHYS GCPhys;
|
---|
1151 | /** Address of the last byte in the range. */
|
---|
1152 | RTGCPHYS GCPhysLast;
|
---|
1153 | /** Size of the range. */
|
---|
1154 | RTGCPHYS cb;
|
---|
1155 | /** The flags (PGMPHYS_ROM_FLAG_*). */
|
---|
1156 | uint32_t fFlags;
|
---|
1157 | /** Alignment padding ensuring that aPages is sizeof(PGMROMPAGE) aligned. */
|
---|
1158 | uint32_t au32Alignemnt[HC_ARCH_BITS == 32 ? 7 : 3];
|
---|
1159 | /** Pointer to the original bits when PGMPHYS_ROM_FLAGS_PERMANENT_BINARY was specified.
|
---|
1160 | * This is used for strictness checks. */
|
---|
1161 | R3PTRTYPE(const void *) pvOriginal;
|
---|
1162 | /** The ROM description. */
|
---|
1163 | R3PTRTYPE(const char *) pszDesc;
|
---|
1164 | /** The per page tracking structures. */
|
---|
1165 | PGMROMPAGE aPages[1];
|
---|
1166 | } PGMROMRANGE;
|
---|
1167 | /** Pointer to a ROM range. */
|
---|
1168 | typedef PGMROMRANGE *PPGMROMRANGE;
|
---|
1169 |
|
---|
1170 |
|
---|
1171 | /**
|
---|
1172 | * A registered MMIO2 (= Device RAM) range.
|
---|
1173 | *
|
---|
1174 | * There are a few reason why we need to keep track of these
|
---|
1175 | * registrations. One of them is the deregistration & cleanup
|
---|
1176 | * stuff, while another is that the PGMRAMRANGE associated with
|
---|
1177 | * such a region may have to be removed from the ram range list.
|
---|
1178 | *
|
---|
1179 | * Overlapping with a RAM range has to be 100% or none at all. The
|
---|
1180 | * pages in the existing RAM range must not be ROM nor MMIO. A guru
|
---|
1181 | * meditation will be raised if a partial overlap or an overlap of
|
---|
1182 | * ROM pages is encountered. On an overlap we will free all the
|
---|
1183 | * existing RAM pages and put in the ram range pages instead.
|
---|
1184 | */
|
---|
1185 | typedef struct PGMMMIO2RANGE
|
---|
1186 | {
|
---|
1187 | /** The owner of the range. (a device) */
|
---|
1188 | PPDMDEVINSR3 pDevInsR3;
|
---|
1189 | /** Pointer to the ring-3 mapping of the allocation. */
|
---|
1190 | RTR3PTR pvR3;
|
---|
1191 | /** Pointer to the next range - R3. */
|
---|
1192 | R3PTRTYPE(struct PGMMMIO2RANGE *) pNextR3;
|
---|
1193 | /** Whether it's mapped or not. */
|
---|
1194 | bool fMapped;
|
---|
1195 | /** Whether it's overlapping or not. */
|
---|
1196 | bool fOverlapping;
|
---|
1197 | /** The PCI region number.
|
---|
1198 | * @remarks This ASSUMES that nobody will ever really need to have multiple
|
---|
1199 | * PCI devices with matching MMIO region numbers on a single device. */
|
---|
1200 | uint8_t iRegion;
|
---|
1201 | /** Alignment padding for putting the ram range on a PGMPAGE alignment boundrary. */
|
---|
1202 | uint8_t abAlignemnt[HC_ARCH_BITS == 32 ? 1 : 5];
|
---|
1203 | /** The associated RAM range. */
|
---|
1204 | PGMRAMRANGE RamRange;
|
---|
1205 | } PGMMMIO2RANGE;
|
---|
1206 | /** Pointer to a MMIO2 range. */
|
---|
1207 | typedef PGMMMIO2RANGE *PPGMMMIO2RANGE;
|
---|
1208 |
|
---|
1209 |
|
---|
1210 |
|
---|
1211 |
|
---|
1212 | /**
|
---|
1213 | * PGMPhysRead/Write cache entry
|
---|
1214 | */
|
---|
1215 | typedef struct PGMPHYSCACHEENTRY
|
---|
1216 | {
|
---|
1217 | /** R3 pointer to physical page. */
|
---|
1218 | R3PTRTYPE(uint8_t *) pbR3;
|
---|
1219 | /** GC Physical address for cache entry */
|
---|
1220 | RTGCPHYS GCPhys;
|
---|
1221 | #if HC_ARCH_BITS == 64 && GC_ARCH_BITS == 32
|
---|
1222 | RTGCPHYS u32Padding0; /**< alignment padding. */
|
---|
1223 | #endif
|
---|
1224 | } PGMPHYSCACHEENTRY;
|
---|
1225 |
|
---|
1226 | /**
|
---|
1227 | * PGMPhysRead/Write cache to reduce REM memory access overhead
|
---|
1228 | */
|
---|
1229 | typedef struct PGMPHYSCACHE
|
---|
1230 | {
|
---|
1231 | /** Bitmap of valid cache entries */
|
---|
1232 | uint64_t aEntries;
|
---|
1233 | /** Cache entries */
|
---|
1234 | PGMPHYSCACHEENTRY Entry[PGM_MAX_PHYSCACHE_ENTRIES];
|
---|
1235 | } PGMPHYSCACHE;
|
---|
1236 |
|
---|
1237 |
|
---|
1238 | /** Pointer to an allocation chunk ring-3 mapping. */
|
---|
1239 | typedef struct PGMCHUNKR3MAP *PPGMCHUNKR3MAP;
|
---|
1240 | /** Pointer to an allocation chunk ring-3 mapping pointer. */
|
---|
1241 | typedef PPGMCHUNKR3MAP *PPPGMCHUNKR3MAP;
|
---|
1242 |
|
---|
1243 | /**
|
---|
1244 | * Ring-3 tracking structore for an allocation chunk ring-3 mapping.
|
---|
1245 | *
|
---|
1246 | * The primary tree (Core) uses the chunk id as key.
|
---|
1247 | * The secondary tree (AgeCore) is used for ageing and uses ageing sequence number as key.
|
---|
1248 | */
|
---|
1249 | typedef struct PGMCHUNKR3MAP
|
---|
1250 | {
|
---|
1251 | /** The key is the chunk id. */
|
---|
1252 | AVLU32NODECORE Core;
|
---|
1253 | /** The key is the ageing sequence number. */
|
---|
1254 | AVLLU32NODECORE AgeCore;
|
---|
1255 | /** The current age thingy. */
|
---|
1256 | uint32_t iAge;
|
---|
1257 | /** The current reference count. */
|
---|
1258 | uint32_t volatile cRefs;
|
---|
1259 | /** The current permanent reference count. */
|
---|
1260 | uint32_t volatile cPermRefs;
|
---|
1261 | /** The mapping address. */
|
---|
1262 | void *pv;
|
---|
1263 | } PGMCHUNKR3MAP;
|
---|
1264 |
|
---|
1265 | /**
|
---|
1266 | * Allocation chunk ring-3 mapping TLB entry.
|
---|
1267 | */
|
---|
1268 | typedef struct PGMCHUNKR3MAPTLBE
|
---|
1269 | {
|
---|
1270 | /** The chunk id. */
|
---|
1271 | uint32_t volatile idChunk;
|
---|
1272 | #if HC_ARCH_BITS == 64
|
---|
1273 | uint32_t u32Padding; /**< alignment padding. */
|
---|
1274 | #endif
|
---|
1275 | /** The chunk map. */
|
---|
1276 | #ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
|
---|
1277 | R3PTRTYPE(PPGMCHUNKR3MAP) volatile pChunk;
|
---|
1278 | #else
|
---|
1279 | R3R0PTRTYPE(PPGMCHUNKR3MAP) volatile pChunk;
|
---|
1280 | #endif
|
---|
1281 | } PGMCHUNKR3MAPTLBE;
|
---|
1282 | /** Pointer to the an allocation chunk ring-3 mapping TLB entry. */
|
---|
1283 | typedef PGMCHUNKR3MAPTLBE *PPGMCHUNKR3MAPTLBE;
|
---|
1284 |
|
---|
1285 | /** The number of TLB entries in PGMCHUNKR3MAPTLB.
|
---|
1286 | * @remark Must be a power of two value. */
|
---|
1287 | #define PGM_CHUNKR3MAPTLB_ENTRIES 32
|
---|
1288 |
|
---|
1289 | /**
|
---|
1290 | * Allocation chunk ring-3 mapping TLB.
|
---|
1291 | *
|
---|
1292 | * @remarks We use a TLB to speed up lookups by avoiding walking the AVL.
|
---|
1293 | * At first glance this might look kinda odd since AVL trees are
|
---|
1294 | * supposed to give the most optimial lookup times of all trees
|
---|
1295 | * due to their balancing. However, take a tree with 1023 nodes
|
---|
1296 | * in it, that's 10 levels, meaning that most searches has to go
|
---|
1297 | * down 9 levels before they find what they want. This isn't fast
|
---|
1298 | * compared to a TLB hit. There is the factor of cache misses,
|
---|
1299 | * and of course the problem with trees and branch prediction.
|
---|
1300 | * This is why we use TLBs in front of most of the trees.
|
---|
1301 | *
|
---|
1302 | * @todo Generalize this TLB + AVL stuff, shouldn't be all that
|
---|
1303 | * difficult when we switch to the new inlined AVL trees (from kStuff).
|
---|
1304 | */
|
---|
1305 | typedef struct PGMCHUNKR3MAPTLB
|
---|
1306 | {
|
---|
1307 | /** The TLB entries. */
|
---|
1308 | PGMCHUNKR3MAPTLBE aEntries[PGM_CHUNKR3MAPTLB_ENTRIES];
|
---|
1309 | } PGMCHUNKR3MAPTLB;
|
---|
1310 |
|
---|
1311 | /**
|
---|
1312 | * Calculates the index of a guest page in the Ring-3 Chunk TLB.
|
---|
1313 | * @returns Chunk TLB index.
|
---|
1314 | * @param idChunk The Chunk ID.
|
---|
1315 | */
|
---|
1316 | #define PGM_CHUNKR3MAPTLB_IDX(idChunk) ( (idChunk) & (PGM_CHUNKR3MAPTLB_ENTRIES - 1) )
|
---|
1317 |
|
---|
1318 |
|
---|
1319 | /**
|
---|
1320 | * Ring-3 guest page mapping TLB entry.
|
---|
1321 | * @remarks used in ring-0 as well at the moment.
|
---|
1322 | */
|
---|
1323 | typedef struct PGMPAGER3MAPTLBE
|
---|
1324 | {
|
---|
1325 | /** Address of the page. */
|
---|
1326 | RTGCPHYS volatile GCPhys;
|
---|
1327 | /** The guest page. */
|
---|
1328 | #ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
|
---|
1329 | R3PTRTYPE(PPGMPAGE) volatile pPage;
|
---|
1330 | #else
|
---|
1331 | R3R0PTRTYPE(PPGMPAGE) volatile pPage;
|
---|
1332 | #endif
|
---|
1333 | /** Pointer to the page mapping tracking structure, PGMCHUNKR3MAP. */
|
---|
1334 | #ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
|
---|
1335 | R3PTRTYPE(PPGMCHUNKR3MAP) volatile pMap;
|
---|
1336 | #else
|
---|
1337 | R3R0PTRTYPE(PPGMCHUNKR3MAP) volatile pMap;
|
---|
1338 | #endif
|
---|
1339 | /** The address */
|
---|
1340 | #ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
|
---|
1341 | R3PTRTYPE(void *) volatile pv;
|
---|
1342 | #else
|
---|
1343 | R3R0PTRTYPE(void *) volatile pv;
|
---|
1344 | #endif
|
---|
1345 | #if HC_ARCH_BITS == 32
|
---|
1346 | uint32_t u32Padding; /**< alignment padding. */
|
---|
1347 | #endif
|
---|
1348 | } PGMPAGER3MAPTLBE;
|
---|
1349 | /** Pointer to an entry in the HC physical TLB. */
|
---|
1350 | typedef PGMPAGER3MAPTLBE *PPGMPAGER3MAPTLBE;
|
---|
1351 |
|
---|
1352 |
|
---|
1353 | /** The number of entries in the ring-3 guest page mapping TLB.
|
---|
1354 | * @remarks The value must be a power of two. */
|
---|
1355 | #define PGM_PAGER3MAPTLB_ENTRIES 64
|
---|
1356 |
|
---|
1357 | /**
|
---|
1358 | * Ring-3 guest page mapping TLB.
|
---|
1359 | * @remarks used in ring-0 as well at the moment.
|
---|
1360 | */
|
---|
1361 | typedef struct PGMPAGER3MAPTLB
|
---|
1362 | {
|
---|
1363 | /** The TLB entries. */
|
---|
1364 | PGMPAGER3MAPTLBE aEntries[PGM_PAGER3MAPTLB_ENTRIES];
|
---|
1365 | } PGMPAGER3MAPTLB;
|
---|
1366 | /** Pointer to the ring-3 guest page mapping TLB. */
|
---|
1367 | typedef PGMPAGER3MAPTLB *PPGMPAGER3MAPTLB;
|
---|
1368 |
|
---|
1369 | /**
|
---|
1370 | * Calculates the index of the TLB entry for the specified guest page.
|
---|
1371 | * @returns Physical TLB index.
|
---|
1372 | * @param GCPhys The guest physical address.
|
---|
1373 | */
|
---|
1374 | #define PGM_PAGER3MAPTLB_IDX(GCPhys) ( ((GCPhys) >> PAGE_SHIFT) & (PGM_PAGER3MAPTLB_ENTRIES - 1) )
|
---|
1375 |
|
---|
1376 |
|
---|
1377 | /**
|
---|
1378 | * Mapping cache usage set entry.
|
---|
1379 | *
|
---|
1380 | * @remarks 16-bit ints was choosen as the set is not expected to be used beyond
|
---|
1381 | * the dynamic ring-0 and (to some extent) raw-mode context mapping
|
---|
1382 | * cache. If it's extended to include ring-3, well, then something will
|
---|
1383 | * have be changed here...
|
---|
1384 | */
|
---|
1385 | typedef struct PGMMAPSETENTRY
|
---|
1386 | {
|
---|
1387 | /** The mapping cache index. */
|
---|
1388 | uint16_t iPage;
|
---|
1389 | /** The number of references.
|
---|
1390 | * The max is UINT16_MAX - 1. */
|
---|
1391 | uint16_t cRefs;
|
---|
1392 | #if HC_ARCH_BITS == 64
|
---|
1393 | uint32_t alignment;
|
---|
1394 | #endif
|
---|
1395 | /** Pointer to the page. */
|
---|
1396 | RTR0PTR pvPage;
|
---|
1397 | /** The physical address for this entry. */
|
---|
1398 | RTHCPHYS HCPhys;
|
---|
1399 | } PGMMAPSETENTRY;
|
---|
1400 | /** Pointer to a mapping cache usage set entry. */
|
---|
1401 | typedef PGMMAPSETENTRY *PPGMMAPSETENTRY;
|
---|
1402 |
|
---|
1403 | /**
|
---|
1404 | * Mapping cache usage set.
|
---|
1405 | *
|
---|
1406 | * This is used in ring-0 and the raw-mode context to track dynamic mappings
|
---|
1407 | * done during exits / traps. The set is
|
---|
1408 | */
|
---|
1409 | typedef struct PGMMAPSET
|
---|
1410 | {
|
---|
1411 | /** The number of occupied entries.
|
---|
1412 | * This is PGMMAPSET_CLOSED if the set is closed and we're not supposed to do
|
---|
1413 | * dynamic mappings. */
|
---|
1414 | uint32_t cEntries;
|
---|
1415 | /** The start of the current subset.
|
---|
1416 | * This is UINT32_MAX if no subset is currently open. */
|
---|
1417 | uint32_t iSubset;
|
---|
1418 | /** The index of the current CPU, only valid if the set is open. */
|
---|
1419 | int32_t iCpu;
|
---|
1420 | #if HC_ARCH_BITS == 64
|
---|
1421 | uint32_t alignment;
|
---|
1422 | #endif
|
---|
1423 | /** The entries. */
|
---|
1424 | PGMMAPSETENTRY aEntries[64];
|
---|
1425 | /** HCPhys -> iEntry fast lookup table.
|
---|
1426 | * Use PGMMAPSET_HASH for hashing.
|
---|
1427 | * The entries may or may not be valid, check against cEntries. */
|
---|
1428 | uint8_t aiHashTable[128];
|
---|
1429 | } PGMMAPSET;
|
---|
1430 | /** Pointer to the mapping cache set. */
|
---|
1431 | typedef PGMMAPSET *PPGMMAPSET;
|
---|
1432 |
|
---|
1433 | /** PGMMAPSET::cEntries value for a closed set. */
|
---|
1434 | #define PGMMAPSET_CLOSED UINT32_C(0xdeadc0fe)
|
---|
1435 |
|
---|
1436 | /** Hash function for aiHashTable. */
|
---|
1437 | #define PGMMAPSET_HASH(HCPhys) (((HCPhys) >> PAGE_SHIFT) & 127)
|
---|
1438 |
|
---|
1439 | /** The max fill size (strict builds). */
|
---|
1440 | #define PGMMAPSET_MAX_FILL (64U * 80U / 100U)
|
---|
1441 |
|
---|
1442 |
|
---|
1443 | /** @name Context neutrual page mapper TLB.
|
---|
1444 | *
|
---|
1445 | * Hoping to avoid some code and bug duplication parts of the GCxxx->CCPtr
|
---|
1446 | * code is writting in a kind of context neutrual way. Time will show whether
|
---|
1447 | * this actually makes sense or not...
|
---|
1448 | *
|
---|
1449 | * @todo this needs to be reconsidered and dropped/redone since the ring-0
|
---|
1450 | * context ends up using a global mapping cache on some platforms
|
---|
1451 | * (darwin).
|
---|
1452 | *
|
---|
1453 | * @{ */
|
---|
1454 | /** @typedef PPGMPAGEMAPTLB
|
---|
1455 | * The page mapper TLB pointer type for the current context. */
|
---|
1456 | /** @typedef PPGMPAGEMAPTLB
|
---|
1457 | * The page mapper TLB entry pointer type for the current context. */
|
---|
1458 | /** @typedef PPGMPAGEMAPTLB
|
---|
1459 | * The page mapper TLB entry pointer pointer type for the current context. */
|
---|
1460 | /** @def PGM_PAGEMAPTLB_ENTRIES
|
---|
1461 | * The number of TLB entries in the page mapper TLB for the current context. */
|
---|
1462 | /** @def PGM_PAGEMAPTLB_IDX
|
---|
1463 | * Calculate the TLB index for a guest physical address.
|
---|
1464 | * @returns The TLB index.
|
---|
1465 | * @param GCPhys The guest physical address. */
|
---|
1466 | /** @typedef PPGMPAGEMAP
|
---|
1467 | * Pointer to a page mapper unit for current context. */
|
---|
1468 | /** @typedef PPPGMPAGEMAP
|
---|
1469 | * Pointer to a page mapper unit pointer for current context. */
|
---|
1470 | #ifdef IN_RC
|
---|
1471 | // typedef PPGMPAGEGCMAPTLB PPGMPAGEMAPTLB;
|
---|
1472 | // typedef PPGMPAGEGCMAPTLBE PPGMPAGEMAPTLBE;
|
---|
1473 | // typedef PPGMPAGEGCMAPTLBE *PPPGMPAGEMAPTLBE;
|
---|
1474 | # define PGM_PAGEMAPTLB_ENTRIES PGM_PAGEGCMAPTLB_ENTRIES
|
---|
1475 | # define PGM_PAGEMAPTLB_IDX(GCPhys) PGM_PAGEGCMAPTLB_IDX(GCPhys)
|
---|
1476 | typedef void * PPGMPAGEMAP;
|
---|
1477 | typedef void ** PPPGMPAGEMAP;
|
---|
1478 | //#elif IN_RING0
|
---|
1479 | // typedef PPGMPAGER0MAPTLB PPGMPAGEMAPTLB;
|
---|
1480 | // typedef PPGMPAGER0MAPTLBE PPGMPAGEMAPTLBE;
|
---|
1481 | // typedef PPGMPAGER0MAPTLBE *PPPGMPAGEMAPTLBE;
|
---|
1482 | //# define PGM_PAGEMAPTLB_ENTRIES PGM_PAGER0MAPTLB_ENTRIES
|
---|
1483 | //# define PGM_PAGEMAPTLB_IDX(GCPhys) PGM_PAGER0MAPTLB_IDX(GCPhys)
|
---|
1484 | // typedef PPGMCHUNKR0MAP PPGMPAGEMAP;
|
---|
1485 | // typedef PPPGMCHUNKR0MAP PPPGMPAGEMAP;
|
---|
1486 | #else
|
---|
1487 | typedef PPGMPAGER3MAPTLB PPGMPAGEMAPTLB;
|
---|
1488 | typedef PPGMPAGER3MAPTLBE PPGMPAGEMAPTLBE;
|
---|
1489 | typedef PPGMPAGER3MAPTLBE *PPPGMPAGEMAPTLBE;
|
---|
1490 | # define PGM_PAGEMAPTLB_ENTRIES PGM_PAGER3MAPTLB_ENTRIES
|
---|
1491 | # define PGM_PAGEMAPTLB_IDX(GCPhys) PGM_PAGER3MAPTLB_IDX(GCPhys)
|
---|
1492 | typedef PPGMCHUNKR3MAP PPGMPAGEMAP;
|
---|
1493 | typedef PPPGMCHUNKR3MAP PPPGMPAGEMAP;
|
---|
1494 | #endif
|
---|
1495 | /** @} */
|
---|
1496 |
|
---|
1497 |
|
---|
1498 | /** @name PGM Pool Indexes.
|
---|
1499 | * Aka. the unique shadow page identifier.
|
---|
1500 | * @{ */
|
---|
1501 | /** NIL page pool IDX. */
|
---|
1502 | #define NIL_PGMPOOL_IDX 0
|
---|
1503 | /** The first normal index. */
|
---|
1504 | #define PGMPOOL_IDX_FIRST_SPECIAL 1
|
---|
1505 | /** Page directory (32-bit root). */
|
---|
1506 | #define PGMPOOL_IDX_PD 1
|
---|
1507 | /** Page Directory Pointer Table (PAE root). */
|
---|
1508 | #define PGMPOOL_IDX_PDPT 2
|
---|
1509 | /** AMD64 CR3 level index.*/
|
---|
1510 | #define PGMPOOL_IDX_AMD64_CR3 3
|
---|
1511 | /** Nested paging root.*/
|
---|
1512 | #define PGMPOOL_IDX_NESTED_ROOT 4
|
---|
1513 | /** The first normal index. */
|
---|
1514 | #define PGMPOOL_IDX_FIRST 5
|
---|
1515 | /** The last valid index. (inclusive, 14 bits) */
|
---|
1516 | #define PGMPOOL_IDX_LAST 0x3fff
|
---|
1517 | /** @} */
|
---|
1518 |
|
---|
1519 | /** The NIL index for the parent chain. */
|
---|
1520 | #define NIL_PGMPOOL_USER_INDEX ((uint16_t)0xffff)
|
---|
1521 | #define NIL_PGMPOOL_PRESENT_INDEX ((uint16_t)0xffff)
|
---|
1522 |
|
---|
1523 | /**
|
---|
1524 | * Node in the chain linking a shadowed page to it's parent (user).
|
---|
1525 | */
|
---|
1526 | #pragma pack(1)
|
---|
1527 | typedef struct PGMPOOLUSER
|
---|
1528 | {
|
---|
1529 | /** The index to the next item in the chain. NIL_PGMPOOL_USER_INDEX is no next. */
|
---|
1530 | uint16_t iNext;
|
---|
1531 | /** The user page index. */
|
---|
1532 | uint16_t iUser;
|
---|
1533 | /** Index into the user table. */
|
---|
1534 | uint32_t iUserTable;
|
---|
1535 | } PGMPOOLUSER, *PPGMPOOLUSER;
|
---|
1536 | typedef const PGMPOOLUSER *PCPGMPOOLUSER;
|
---|
1537 | #pragma pack()
|
---|
1538 |
|
---|
1539 |
|
---|
1540 | /** The NIL index for the phys ext chain. */
|
---|
1541 | #define NIL_PGMPOOL_PHYSEXT_INDEX ((uint16_t)0xffff)
|
---|
1542 |
|
---|
1543 | /**
|
---|
1544 | * Node in the chain of physical cross reference extents.
|
---|
1545 | * @todo Calling this an 'extent' is not quite right, find a better name.
|
---|
1546 | */
|
---|
1547 | #pragma pack(1)
|
---|
1548 | typedef struct PGMPOOLPHYSEXT
|
---|
1549 | {
|
---|
1550 | /** The index to the next item in the chain. NIL_PGMPOOL_PHYSEXT_INDEX is no next. */
|
---|
1551 | uint16_t iNext;
|
---|
1552 | /** The user page index. */
|
---|
1553 | uint16_t aidx[3];
|
---|
1554 | } PGMPOOLPHYSEXT, *PPGMPOOLPHYSEXT;
|
---|
1555 | typedef const PGMPOOLPHYSEXT *PCPGMPOOLPHYSEXT;
|
---|
1556 | #pragma pack()
|
---|
1557 |
|
---|
1558 |
|
---|
1559 | /**
|
---|
1560 | * The kind of page that's being shadowed.
|
---|
1561 | */
|
---|
1562 | typedef enum PGMPOOLKIND
|
---|
1563 | {
|
---|
1564 | /** The virtual invalid 0 entry. */
|
---|
1565 | PGMPOOLKIND_INVALID = 0,
|
---|
1566 | /** The entry is free (=unused). */
|
---|
1567 | PGMPOOLKIND_FREE,
|
---|
1568 |
|
---|
1569 | /** Shw: 32-bit page table; Gst: no paging */
|
---|
1570 | PGMPOOLKIND_32BIT_PT_FOR_PHYS,
|
---|
1571 | /** Shw: 32-bit page table; Gst: 32-bit page table. */
|
---|
1572 | PGMPOOLKIND_32BIT_PT_FOR_32BIT_PT,
|
---|
1573 | /** Shw: 32-bit page table; Gst: 4MB page. */
|
---|
1574 | PGMPOOLKIND_32BIT_PT_FOR_32BIT_4MB,
|
---|
1575 | /** Shw: PAE page table; Gst: no paging */
|
---|
1576 | PGMPOOLKIND_PAE_PT_FOR_PHYS,
|
---|
1577 | /** Shw: PAE page table; Gst: 32-bit page table. */
|
---|
1578 | PGMPOOLKIND_PAE_PT_FOR_32BIT_PT,
|
---|
1579 | /** Shw: PAE page table; Gst: Half of a 4MB page. */
|
---|
1580 | PGMPOOLKIND_PAE_PT_FOR_32BIT_4MB,
|
---|
1581 | /** Shw: PAE page table; Gst: PAE page table. */
|
---|
1582 | PGMPOOLKIND_PAE_PT_FOR_PAE_PT,
|
---|
1583 | /** Shw: PAE page table; Gst: 2MB page. */
|
---|
1584 | PGMPOOLKIND_PAE_PT_FOR_PAE_2MB,
|
---|
1585 |
|
---|
1586 | /** Shw: 32-bit page directory. Gst: 32-bit page directory. */
|
---|
1587 | PGMPOOLKIND_32BIT_PD,
|
---|
1588 | /** Shw: 32-bit page directory. Gst: no paging. */
|
---|
1589 | PGMPOOLKIND_32BIT_PD_PHYS,
|
---|
1590 | /** Shw: PAE page directory 0; Gst: 32-bit page directory. */
|
---|
1591 | PGMPOOLKIND_PAE_PD0_FOR_32BIT_PD,
|
---|
1592 | /** Shw: PAE page directory 1; Gst: 32-bit page directory. */
|
---|
1593 | PGMPOOLKIND_PAE_PD1_FOR_32BIT_PD,
|
---|
1594 | /** Shw: PAE page directory 2; Gst: 32-bit page directory. */
|
---|
1595 | PGMPOOLKIND_PAE_PD2_FOR_32BIT_PD,
|
---|
1596 | /** Shw: PAE page directory 3; Gst: 32-bit page directory. */
|
---|
1597 | PGMPOOLKIND_PAE_PD3_FOR_32BIT_PD,
|
---|
1598 | /** Shw: PAE page directory; Gst: PAE page directory. */
|
---|
1599 | PGMPOOLKIND_PAE_PD_FOR_PAE_PD,
|
---|
1600 | /** Shw: PAE page directory; Gst: no paging. */
|
---|
1601 | PGMPOOLKIND_PAE_PD_PHYS,
|
---|
1602 |
|
---|
1603 | /** Shw: PAE page directory pointer table (legacy, 4 entries); Gst 32 bits paging. */
|
---|
1604 | PGMPOOLKIND_PAE_PDPT_FOR_32BIT,
|
---|
1605 | /** Shw: PAE page directory pointer table (legacy, 4 entries); Gst PAE PDPT. */
|
---|
1606 | PGMPOOLKIND_PAE_PDPT,
|
---|
1607 | /** Shw: PAE page directory pointer table (legacy, 4 entries); Gst: no paging. */
|
---|
1608 | PGMPOOLKIND_PAE_PDPT_PHYS,
|
---|
1609 |
|
---|
1610 | /** Shw: 64-bit page directory pointer table; Gst: 64-bit page directory pointer table. */
|
---|
1611 | PGMPOOLKIND_64BIT_PDPT_FOR_64BIT_PDPT,
|
---|
1612 | /** Shw: 64-bit page directory pointer table; Gst: no paging */
|
---|
1613 | PGMPOOLKIND_64BIT_PDPT_FOR_PHYS,
|
---|
1614 | /** Shw: 64-bit page directory table; Gst: 64-bit page directory table. */
|
---|
1615 | PGMPOOLKIND_64BIT_PD_FOR_64BIT_PD,
|
---|
1616 | /** Shw: 64-bit page directory table; Gst: no paging */
|
---|
1617 | PGMPOOLKIND_64BIT_PD_FOR_PHYS, /* 22 */
|
---|
1618 |
|
---|
1619 | /** Shw: 64-bit PML4; Gst: 64-bit PML4. */
|
---|
1620 | PGMPOOLKIND_64BIT_PML4,
|
---|
1621 |
|
---|
1622 | /** Shw: EPT page directory pointer table; Gst: no paging */
|
---|
1623 | PGMPOOLKIND_EPT_PDPT_FOR_PHYS,
|
---|
1624 | /** Shw: EPT page directory table; Gst: no paging */
|
---|
1625 | PGMPOOLKIND_EPT_PD_FOR_PHYS,
|
---|
1626 | /** Shw: EPT page table; Gst: no paging */
|
---|
1627 | PGMPOOLKIND_EPT_PT_FOR_PHYS,
|
---|
1628 |
|
---|
1629 | /** Shw: Root Nested paging table. */
|
---|
1630 | PGMPOOLKIND_ROOT_NESTED,
|
---|
1631 |
|
---|
1632 | /** The last valid entry. */
|
---|
1633 | PGMPOOLKIND_LAST = PGMPOOLKIND_ROOT_NESTED
|
---|
1634 | } PGMPOOLKIND;
|
---|
1635 |
|
---|
1636 | /**
|
---|
1637 | * The access attributes of the page; only applies to big pages.
|
---|
1638 | */
|
---|
1639 | typedef enum
|
---|
1640 | {
|
---|
1641 | PGMPOOLACCESS_DONTCARE = 0,
|
---|
1642 | PGMPOOLACCESS_USER_RW,
|
---|
1643 | PGMPOOLACCESS_USER_R,
|
---|
1644 | PGMPOOLACCESS_USER_RW_NX,
|
---|
1645 | PGMPOOLACCESS_USER_R_NX,
|
---|
1646 | PGMPOOLACCESS_SUPERVISOR_RW,
|
---|
1647 | PGMPOOLACCESS_SUPERVISOR_R,
|
---|
1648 | PGMPOOLACCESS_SUPERVISOR_RW_NX,
|
---|
1649 | PGMPOOLACCESS_SUPERVISOR_R_NX
|
---|
1650 | } PGMPOOLACCESS;
|
---|
1651 |
|
---|
1652 | /**
|
---|
1653 | * The tracking data for a page in the pool.
|
---|
1654 | */
|
---|
1655 | typedef struct PGMPOOLPAGE
|
---|
1656 | {
|
---|
1657 | /** AVL node code with the (R3) physical address of this page. */
|
---|
1658 | AVLOHCPHYSNODECORE Core;
|
---|
1659 | /** Pointer to the R3 mapping of the page. */
|
---|
1660 | #ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
|
---|
1661 | R3PTRTYPE(void *) pvPageR3;
|
---|
1662 | #else
|
---|
1663 | R3R0PTRTYPE(void *) pvPageR3;
|
---|
1664 | #endif
|
---|
1665 | /** The guest physical address. */
|
---|
1666 | #if HC_ARCH_BITS == 32 && GC_ARCH_BITS == 64
|
---|
1667 | uint32_t Alignment0;
|
---|
1668 | #endif
|
---|
1669 | RTGCPHYS GCPhys;
|
---|
1670 |
|
---|
1671 | /** Access handler statistics to determine whether the guest is (re)initializing a page table. */
|
---|
1672 | RTGCPTR pvLastAccessHandlerRip;
|
---|
1673 | RTGCPTR pvLastAccessHandlerFault;
|
---|
1674 | uint64_t cLastAccessHandlerCount;
|
---|
1675 |
|
---|
1676 | /** The kind of page we're shadowing. (This is really a PGMPOOLKIND enum.) */
|
---|
1677 | uint8_t enmKind;
|
---|
1678 | /** The subkind of page we're shadowing. (This is really a PGMPOOLACCESS enum.) */
|
---|
1679 | uint8_t enmAccess;
|
---|
1680 | /** The index of this page. */
|
---|
1681 | uint16_t idx;
|
---|
1682 | /** The next entry in the list this page currently resides in.
|
---|
1683 | * It's either in the free list or in the GCPhys hash. */
|
---|
1684 | uint16_t iNext;
|
---|
1685 | #ifdef PGMPOOL_WITH_USER_TRACKING
|
---|
1686 | /** Head of the user chain. NIL_PGMPOOL_USER_INDEX if not currently in use. */
|
---|
1687 | uint16_t iUserHead;
|
---|
1688 | /** The number of present entries. */
|
---|
1689 | uint16_t cPresent;
|
---|
1690 | /** The first entry in the table which is present. */
|
---|
1691 | uint16_t iFirstPresent;
|
---|
1692 | #endif
|
---|
1693 | #ifdef PGMPOOL_WITH_MONITORING
|
---|
1694 | /** The number of modifications to the monitored page. */
|
---|
1695 | uint16_t cModifications;
|
---|
1696 | /** The next modified page. NIL_PGMPOOL_IDX if tail. */
|
---|
1697 | uint16_t iModifiedNext;
|
---|
1698 | /** The previous modified page. NIL_PGMPOOL_IDX if head. */
|
---|
1699 | uint16_t iModifiedPrev;
|
---|
1700 | /** The next page sharing access handler. NIL_PGMPOOL_IDX if tail. */
|
---|
1701 | uint16_t iMonitoredNext;
|
---|
1702 | /** The previous page sharing access handler. NIL_PGMPOOL_IDX if head. */
|
---|
1703 | uint16_t iMonitoredPrev;
|
---|
1704 | #endif
|
---|
1705 | #ifdef PGMPOOL_WITH_CACHE
|
---|
1706 | /** The next page in the age list. */
|
---|
1707 | uint16_t iAgeNext;
|
---|
1708 | /** The previous page in the age list. */
|
---|
1709 | uint16_t iAgePrev;
|
---|
1710 | #endif /* PGMPOOL_WITH_CACHE */
|
---|
1711 | /** Used to indicate that the page is zeroed. */
|
---|
1712 | bool fZeroed;
|
---|
1713 | /** Used to indicate that a PT has non-global entries. */
|
---|
1714 | bool fSeenNonGlobal;
|
---|
1715 | /** Used to indicate that we're monitoring writes to the guest page. */
|
---|
1716 | bool fMonitored;
|
---|
1717 | /** Used to indicate that the page is in the cache (e.g. in the GCPhys hash).
|
---|
1718 | * (All pages are in the age list.) */
|
---|
1719 | bool fCached;
|
---|
1720 | /** This is used by the R3 access handlers when invoked by an async thread.
|
---|
1721 | * It's a hack required because of REMR3NotifyHandlerPhysicalDeregister. */
|
---|
1722 | bool volatile fReusedFlushPending;
|
---|
1723 | /** Used to mark the page as dirty (write monitoring if temporarily off. */
|
---|
1724 | bool fDirty;
|
---|
1725 |
|
---|
1726 | /** Used to indicate that this page can't be flushed. Important for cr3 root pages or shadow pae pd pages). */
|
---|
1727 | uint32_t cLocked;
|
---|
1728 | uint32_t idxDirty;
|
---|
1729 | RTGCPTR pvDirtyFault;
|
---|
1730 | } PGMPOOLPAGE, *PPGMPOOLPAGE, **PPPGMPOOLPAGE;
|
---|
1731 | /** Pointer to a const pool page. */
|
---|
1732 | typedef PGMPOOLPAGE const *PCPGMPOOLPAGE;
|
---|
1733 |
|
---|
1734 |
|
---|
1735 | #ifdef PGMPOOL_WITH_CACHE
|
---|
1736 | /** The hash table size. */
|
---|
1737 | # define PGMPOOL_HASH_SIZE 0x40
|
---|
1738 | /** The hash function. */
|
---|
1739 | # define PGMPOOL_HASH(GCPhys) ( ((GCPhys) >> PAGE_SHIFT) & (PGMPOOL_HASH_SIZE - 1) )
|
---|
1740 | #endif
|
---|
1741 |
|
---|
1742 |
|
---|
1743 | /**
|
---|
1744 | * The shadow page pool instance data.
|
---|
1745 | *
|
---|
1746 | * It's all one big allocation made at init time, except for the
|
---|
1747 | * pages that is. The user nodes follows immediatly after the
|
---|
1748 | * page structures.
|
---|
1749 | */
|
---|
1750 | typedef struct PGMPOOL
|
---|
1751 | {
|
---|
1752 | /** The VM handle - R3 Ptr. */
|
---|
1753 | PVMR3 pVMR3;
|
---|
1754 | /** The VM handle - R0 Ptr. */
|
---|
1755 | PVMR0 pVMR0;
|
---|
1756 | /** The VM handle - RC Ptr. */
|
---|
1757 | PVMRC pVMRC;
|
---|
1758 | /** The max pool size. This includes the special IDs. */
|
---|
1759 | uint16_t cMaxPages;
|
---|
1760 | /** The current pool size. */
|
---|
1761 | uint16_t cCurPages;
|
---|
1762 | /** The head of the free page list. */
|
---|
1763 | uint16_t iFreeHead;
|
---|
1764 | /* Padding. */
|
---|
1765 | uint16_t u16Padding;
|
---|
1766 | #ifdef PGMPOOL_WITH_USER_TRACKING
|
---|
1767 | /** Head of the chain of free user nodes. */
|
---|
1768 | uint16_t iUserFreeHead;
|
---|
1769 | /** The number of user nodes we've allocated. */
|
---|
1770 | uint16_t cMaxUsers;
|
---|
1771 | /** The number of present page table entries in the entire pool. */
|
---|
1772 | uint32_t cPresent;
|
---|
1773 | /** Pointer to the array of user nodes - RC pointer. */
|
---|
1774 | RCPTRTYPE(PPGMPOOLUSER) paUsersRC;
|
---|
1775 | /** Pointer to the array of user nodes - R3 pointer. */
|
---|
1776 | R3PTRTYPE(PPGMPOOLUSER) paUsersR3;
|
---|
1777 | /** Pointer to the array of user nodes - R0 pointer. */
|
---|
1778 | R0PTRTYPE(PPGMPOOLUSER) paUsersR0;
|
---|
1779 | #endif /* PGMPOOL_WITH_USER_TRACKING */
|
---|
1780 | #ifdef PGMPOOL_WITH_GCPHYS_TRACKING
|
---|
1781 | /** Head of the chain of free phys ext nodes. */
|
---|
1782 | uint16_t iPhysExtFreeHead;
|
---|
1783 | /** The number of user nodes we've allocated. */
|
---|
1784 | uint16_t cMaxPhysExts;
|
---|
1785 | /** Pointer to the array of physical xref extent - RC pointer. */
|
---|
1786 | RCPTRTYPE(PPGMPOOLPHYSEXT) paPhysExtsRC;
|
---|
1787 | /** Pointer to the array of physical xref extent nodes - R3 pointer. */
|
---|
1788 | R3PTRTYPE(PPGMPOOLPHYSEXT) paPhysExtsR3;
|
---|
1789 | /** Pointer to the array of physical xref extent nodes - R0 pointer. */
|
---|
1790 | R0PTRTYPE(PPGMPOOLPHYSEXT) paPhysExtsR0;
|
---|
1791 | #endif /* PGMPOOL_WITH_GCPHYS_TRACKING */
|
---|
1792 | #ifdef PGMPOOL_WITH_CACHE
|
---|
1793 | /** Hash table for GCPhys addresses. */
|
---|
1794 | uint16_t aiHash[PGMPOOL_HASH_SIZE];
|
---|
1795 | /** The head of the age list. */
|
---|
1796 | uint16_t iAgeHead;
|
---|
1797 | /** The tail of the age list. */
|
---|
1798 | uint16_t iAgeTail;
|
---|
1799 | /** Set if the cache is enabled. */
|
---|
1800 | bool fCacheEnabled;
|
---|
1801 | /** Alignment padding. */
|
---|
1802 | bool afPadding1[3];
|
---|
1803 | #endif /* PGMPOOL_WITH_CACHE */
|
---|
1804 | #ifdef PGMPOOL_WITH_MONITORING
|
---|
1805 | /** Head of the list of modified pages. */
|
---|
1806 | uint16_t iModifiedHead;
|
---|
1807 | /** The current number of modified pages. */
|
---|
1808 | uint16_t cModifiedPages;
|
---|
1809 | /** Access handler, RC. */
|
---|
1810 | RCPTRTYPE(PFNPGMRCPHYSHANDLER) pfnAccessHandlerRC;
|
---|
1811 | /** Access handler, R0. */
|
---|
1812 | R0PTRTYPE(PFNPGMR0PHYSHANDLER) pfnAccessHandlerR0;
|
---|
1813 | /** Access handler, R3. */
|
---|
1814 | R3PTRTYPE(PFNPGMR3PHYSHANDLER) pfnAccessHandlerR3;
|
---|
1815 | /** The access handler description (R3 ptr). */
|
---|
1816 | R3PTRTYPE(const char *) pszAccessHandler;
|
---|
1817 | # if HC_ARCH_BITS == 32
|
---|
1818 | /** Alignment padding. */
|
---|
1819 | uint32_t u32Padding2;
|
---|
1820 | # endif
|
---|
1821 | /* Next available slot. */
|
---|
1822 | uint32_t idxFreeDirtyPage;
|
---|
1823 | /* Number of active dirty pages. */
|
---|
1824 | uint32_t cDirtyPages;
|
---|
1825 | /* Array of current dirty pgm pool page indices. */
|
---|
1826 | uint16_t aIdxDirtyPages[16];
|
---|
1827 | uint64_t aDirtyPages[16][512];
|
---|
1828 | #endif /* PGMPOOL_WITH_MONITORING */
|
---|
1829 | /** The number of pages currently in use. */
|
---|
1830 | uint16_t cUsedPages;
|
---|
1831 | #ifdef VBOX_WITH_STATISTICS
|
---|
1832 | /** The high water mark for cUsedPages. */
|
---|
1833 | uint16_t cUsedPagesHigh;
|
---|
1834 | uint32_t Alignment1; /**< Align the next member on a 64-bit boundrary. */
|
---|
1835 | /** Profiling pgmPoolAlloc(). */
|
---|
1836 | STAMPROFILEADV StatAlloc;
|
---|
1837 | /** Profiling pgmR3PoolClearDoIt(). */
|
---|
1838 | STAMPROFILE StatClearAll;
|
---|
1839 | /** Profiling pgmR3PoolReset(). */
|
---|
1840 | STAMPROFILE StatR3Reset;
|
---|
1841 | /** Profiling pgmPoolFlushPage(). */
|
---|
1842 | STAMPROFILE StatFlushPage;
|
---|
1843 | /** Profiling pgmPoolFree(). */
|
---|
1844 | STAMPROFILE StatFree;
|
---|
1845 | /** Counting explicit flushes by PGMPoolFlushPage(). */
|
---|
1846 | STAMCOUNTER StatForceFlushPage;
|
---|
1847 | /** Counting explicit flushes of dirty pages by PGMPoolFlushPage(). */
|
---|
1848 | STAMCOUNTER StatForceFlushDirtyPage;
|
---|
1849 | /** Counting flushes for reused pages. */
|
---|
1850 | STAMCOUNTER StatForceFlushReused;
|
---|
1851 | /** Profiling time spent zeroing pages. */
|
---|
1852 | STAMPROFILE StatZeroPage;
|
---|
1853 | # ifdef PGMPOOL_WITH_USER_TRACKING
|
---|
1854 | /** Profiling of pgmPoolTrackDeref. */
|
---|
1855 | STAMPROFILE StatTrackDeref;
|
---|
1856 | /** Profiling pgmTrackFlushGCPhysPT. */
|
---|
1857 | STAMPROFILE StatTrackFlushGCPhysPT;
|
---|
1858 | /** Profiling pgmTrackFlushGCPhysPTs. */
|
---|
1859 | STAMPROFILE StatTrackFlushGCPhysPTs;
|
---|
1860 | /** Profiling pgmTrackFlushGCPhysPTsSlow. */
|
---|
1861 | STAMPROFILE StatTrackFlushGCPhysPTsSlow;
|
---|
1862 | /** Number of times we've been out of user records. */
|
---|
1863 | STAMCOUNTER StatTrackFreeUpOneUser;
|
---|
1864 | /** Nr of flushed entries. */
|
---|
1865 | STAMCOUNTER StatTrackFlushEntry;
|
---|
1866 | /** Nr of updated entries. */
|
---|
1867 | STAMCOUNTER StatTrackFlushEntryKeep;
|
---|
1868 | # endif
|
---|
1869 | # ifdef PGMPOOL_WITH_GCPHYS_TRACKING
|
---|
1870 | /** Profiling deref activity related tracking GC physical pages. */
|
---|
1871 | STAMPROFILE StatTrackDerefGCPhys;
|
---|
1872 | /** Number of linear searches for a HCPhys in the ram ranges. */
|
---|
1873 | STAMCOUNTER StatTrackLinearRamSearches;
|
---|
1874 | /** The number of failing pgmPoolTrackPhysExtAlloc calls. */
|
---|
1875 | STAMCOUNTER StamTrackPhysExtAllocFailures;
|
---|
1876 | # endif
|
---|
1877 | # ifdef PGMPOOL_WITH_MONITORING
|
---|
1878 | /** Profiling the RC/R0 access handler. */
|
---|
1879 | STAMPROFILE StatMonitorRZ;
|
---|
1880 | /** Times we've failed interpreting the instruction. */
|
---|
1881 | STAMCOUNTER StatMonitorRZEmulateInstr;
|
---|
1882 | /** Profiling the pgmPoolFlushPage calls made from the RC/R0 access handler. */
|
---|
1883 | STAMPROFILE StatMonitorRZFlushPage;
|
---|
1884 | /* Times we've detected a page table reinit. */
|
---|
1885 | STAMCOUNTER StatMonitorRZFlushReinit;
|
---|
1886 | /** Counting flushes for pages that are modified too often. */
|
---|
1887 | STAMCOUNTER StatMonitorRZFlushModOverflow;
|
---|
1888 | /** Times we've detected fork(). */
|
---|
1889 | STAMCOUNTER StatMonitorRZFork;
|
---|
1890 | /** Profiling the RC/R0 access we've handled (except REP STOSD). */
|
---|
1891 | STAMPROFILE StatMonitorRZHandled;
|
---|
1892 | /** Times we've failed interpreting a patch code instruction. */
|
---|
1893 | STAMCOUNTER StatMonitorRZIntrFailPatch1;
|
---|
1894 | /** Times we've failed interpreting a patch code instruction during flushing. */
|
---|
1895 | STAMCOUNTER StatMonitorRZIntrFailPatch2;
|
---|
1896 | /** The number of times we've seen rep prefixes we can't handle. */
|
---|
1897 | STAMCOUNTER StatMonitorRZRepPrefix;
|
---|
1898 | /** Profiling the REP STOSD cases we've handled. */
|
---|
1899 | STAMPROFILE StatMonitorRZRepStosd;
|
---|
1900 | /** Nr of handled PT faults. */
|
---|
1901 | STAMCOUNTER StatMonitorRZFaultPT;
|
---|
1902 | /** Nr of handled PD faults. */
|
---|
1903 | STAMCOUNTER StatMonitorRZFaultPD;
|
---|
1904 | /** Nr of handled PDPT faults. */
|
---|
1905 | STAMCOUNTER StatMonitorRZFaultPDPT;
|
---|
1906 | /** Nr of handled PML4 faults. */
|
---|
1907 | STAMCOUNTER StatMonitorRZFaultPML4;
|
---|
1908 |
|
---|
1909 | /** Profiling the R3 access handler. */
|
---|
1910 | STAMPROFILE StatMonitorR3;
|
---|
1911 | /** Times we've failed interpreting the instruction. */
|
---|
1912 | STAMCOUNTER StatMonitorR3EmulateInstr;
|
---|
1913 | /** Profiling the pgmPoolFlushPage calls made from the R3 access handler. */
|
---|
1914 | STAMPROFILE StatMonitorR3FlushPage;
|
---|
1915 | /* Times we've detected a page table reinit. */
|
---|
1916 | STAMCOUNTER StatMonitorR3FlushReinit;
|
---|
1917 | /** Counting flushes for pages that are modified too often. */
|
---|
1918 | STAMCOUNTER StatMonitorR3FlushModOverflow;
|
---|
1919 | /** Times we've detected fork(). */
|
---|
1920 | STAMCOUNTER StatMonitorR3Fork;
|
---|
1921 | /** Profiling the R3 access we've handled (except REP STOSD). */
|
---|
1922 | STAMPROFILE StatMonitorR3Handled;
|
---|
1923 | /** The number of times we've seen rep prefixes we can't handle. */
|
---|
1924 | STAMCOUNTER StatMonitorR3RepPrefix;
|
---|
1925 | /** Profiling the REP STOSD cases we've handled. */
|
---|
1926 | STAMPROFILE StatMonitorR3RepStosd;
|
---|
1927 | /** Nr of handled PT faults. */
|
---|
1928 | STAMCOUNTER StatMonitorR3FaultPT;
|
---|
1929 | /** Nr of handled PD faults. */
|
---|
1930 | STAMCOUNTER StatMonitorR3FaultPD;
|
---|
1931 | /** Nr of handled PDPT faults. */
|
---|
1932 | STAMCOUNTER StatMonitorR3FaultPDPT;
|
---|
1933 | /** Nr of handled PML4 faults. */
|
---|
1934 | STAMCOUNTER StatMonitorR3FaultPML4;
|
---|
1935 | /** The number of times we're called in an async thread an need to flush. */
|
---|
1936 | STAMCOUNTER StatMonitorR3Async;
|
---|
1937 | /** Times we've called pgmPoolResetDirtyPages (and there were dirty page). */
|
---|
1938 | STAMCOUNTER StatResetDirtyPages;
|
---|
1939 | /** Times we've called pgmPoolAddDirtyPage. */
|
---|
1940 | STAMCOUNTER StatDirtyPage;
|
---|
1941 | /** Times we've had to flush duplicates for dirty page management. */
|
---|
1942 | STAMCOUNTER StatDirtyPageDupFlush;
|
---|
1943 | /** Times we've had to flush because of overflow. */
|
---|
1944 | STAMCOUNTER StatDirtyPageOverFlowFlush;
|
---|
1945 |
|
---|
1946 | /** The high wather mark for cModifiedPages. */
|
---|
1947 | uint16_t cModifiedPagesHigh;
|
---|
1948 | uint16_t Alignment2[3]; /**< Align the next member on a 64-bit boundrary. */
|
---|
1949 | # endif
|
---|
1950 | # ifdef PGMPOOL_WITH_CACHE
|
---|
1951 | /** The number of cache hits. */
|
---|
1952 | STAMCOUNTER StatCacheHits;
|
---|
1953 | /** The number of cache misses. */
|
---|
1954 | STAMCOUNTER StatCacheMisses;
|
---|
1955 | /** The number of times we've got a conflict of 'kind' in the cache. */
|
---|
1956 | STAMCOUNTER StatCacheKindMismatches;
|
---|
1957 | /** Number of times we've been out of pages. */
|
---|
1958 | STAMCOUNTER StatCacheFreeUpOne;
|
---|
1959 | /** The number of cacheable allocations. */
|
---|
1960 | STAMCOUNTER StatCacheCacheable;
|
---|
1961 | /** The number of uncacheable allocations. */
|
---|
1962 | STAMCOUNTER StatCacheUncacheable;
|
---|
1963 | # endif
|
---|
1964 | #else
|
---|
1965 | uint32_t Alignment3; /**< Align the next member on a 64-bit boundrary. */
|
---|
1966 | #endif
|
---|
1967 | /** The AVL tree for looking up a page by its HC physical address. */
|
---|
1968 | AVLOHCPHYSTREE HCPhysTree;
|
---|
1969 | uint32_t Alignment4; /**< Align the next member on a 64-bit boundrary. */
|
---|
1970 | /** Array of pages. (cMaxPages in length)
|
---|
1971 | * The Id is the index into thist array.
|
---|
1972 | */
|
---|
1973 | PGMPOOLPAGE aPages[PGMPOOL_IDX_FIRST];
|
---|
1974 | } PGMPOOL, *PPGMPOOL, **PPPGMPOOL;
|
---|
1975 | #ifdef PGMPOOL_WITH_MONITORING
|
---|
1976 | AssertCompileMemberAlignment(PGMPOOL, iModifiedHead, 8);
|
---|
1977 | AssertCompileMemberAlignment(PGMPOOL, aDirtyPages, 8);
|
---|
1978 | #endif
|
---|
1979 | AssertCompileMemberAlignment(PGMPOOL, cUsedPages, 8);
|
---|
1980 | #ifdef VBOX_WITH_STATISTICS
|
---|
1981 | AssertCompileMemberAlignment(PGMPOOL, StatAlloc, 8);
|
---|
1982 | #endif
|
---|
1983 | AssertCompileMemberAlignment(PGMPOOL, aPages, 8);
|
---|
1984 |
|
---|
1985 |
|
---|
1986 | /** @def PGMPOOL_PAGE_2_PTR
|
---|
1987 | * Maps a pool page pool into the current context.
|
---|
1988 | *
|
---|
1989 | * @returns VBox status code.
|
---|
1990 | * @param pVM The VM handle.
|
---|
1991 | * @param pPage The pool page.
|
---|
1992 | *
|
---|
1993 | * @remark In RC this uses PGMGCDynMapHCPage(), so it will consume of the
|
---|
1994 | * small page window employeed by that function. Be careful.
|
---|
1995 | * @remark There is no need to assert on the result.
|
---|
1996 | */
|
---|
1997 | #if defined(IN_RC)
|
---|
1998 | # define PGMPOOL_PAGE_2_PTR(pVM, pPage) pgmPoolMapPageInlined(&(pVM)->pgm.s, (pPage))
|
---|
1999 | #elif defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0)
|
---|
2000 | # define PGMPOOL_PAGE_2_PTR(pVM, pPage) pgmPoolMapPageInlined(&(pVM)->pgm.s, (pPage))
|
---|
2001 | #elif defined(VBOX_STRICT)
|
---|
2002 | # define PGMPOOL_PAGE_2_PTR(pVM, pPage) pgmPoolMapPageStrict(pPage)
|
---|
2003 | DECLINLINE(void *) pgmPoolMapPageStrict(PPGMPOOLPAGE pPage)
|
---|
2004 | {
|
---|
2005 | Assert(pPage && pPage->pvPageR3);
|
---|
2006 | return pPage->pvPageR3;
|
---|
2007 | }
|
---|
2008 | #else
|
---|
2009 | # define PGMPOOL_PAGE_2_PTR(pVM, pPage) ((pPage)->pvPageR3)
|
---|
2010 | #endif
|
---|
2011 |
|
---|
2012 | /** @def PGMPOOL_PAGE_2_PTR_BY_PGM
|
---|
2013 | * Maps a pool page pool into the current context.
|
---|
2014 | *
|
---|
2015 | * @returns VBox status code.
|
---|
2016 | * @param pPGM Pointer to the PGM instance data.
|
---|
2017 | * @param pPage The pool page.
|
---|
2018 | *
|
---|
2019 | * @remark In RC this uses PGMGCDynMapHCPage(), so it will consume of the
|
---|
2020 | * small page window employeed by that function. Be careful.
|
---|
2021 | * @remark There is no need to assert on the result.
|
---|
2022 | */
|
---|
2023 | #if defined(IN_RC)
|
---|
2024 | # define PGMPOOL_PAGE_2_PTR_BY_PGM(pPGM, pPage) pgmPoolMapPageInlined(pPGM, (pPage))
|
---|
2025 | #elif defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0)
|
---|
2026 | # define PGMPOOL_PAGE_2_PTR_BY_PGM(pPGM, pPage) pgmPoolMapPageInlined(pPGM, (pPage))
|
---|
2027 | #else
|
---|
2028 | # define PGMPOOL_PAGE_2_PTR_BY_PGM(pPGM, pPage) PGMPOOL_PAGE_2_PTR(PGM2VM(pPGM), pPage)
|
---|
2029 | #endif
|
---|
2030 |
|
---|
2031 | /** @def PGMPOOL_PAGE_2_PTR_BY_PGMCPU
|
---|
2032 | * Maps a pool page pool into the current context.
|
---|
2033 | *
|
---|
2034 | * @returns VBox status code.
|
---|
2035 | * @param pPGM Pointer to the PGMCPU instance data.
|
---|
2036 | * @param pPage The pool page.
|
---|
2037 | *
|
---|
2038 | * @remark In RC this uses PGMGCDynMapHCPage(), so it will consume of the
|
---|
2039 | * small page window employeed by that function. Be careful.
|
---|
2040 | * @remark There is no need to assert on the result.
|
---|
2041 | */
|
---|
2042 | #if defined(IN_RC)
|
---|
2043 | # define PGMPOOL_PAGE_2_PTR_BY_PGMCPU(pPGM, pPage) pgmPoolMapPageInlined(PGMCPU2PGM(pPGM), (pPage))
|
---|
2044 | #elif defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0)
|
---|
2045 | # define PGMPOOL_PAGE_2_PTR_BY_PGMCPU(pPGM, pPage) pgmPoolMapPageInlined(PGMCPU2PGM(pPGM), (pPage))
|
---|
2046 | #else
|
---|
2047 | # define PGMPOOL_PAGE_2_PTR_BY_PGMCPU(pPGM, pPage) PGMPOOL_PAGE_2_PTR(PGMCPU2VM(pPGM), pPage)
|
---|
2048 | #endif
|
---|
2049 |
|
---|
2050 |
|
---|
2051 | /** @name Per guest page tracking data.
|
---|
2052 | * This is currently as a 16-bit word in the PGMPAGE structure, the idea though
|
---|
2053 | * is to use more bits for it and split it up later on. But for now we'll play
|
---|
2054 | * safe and change as little as possible.
|
---|
2055 | *
|
---|
2056 | * The 16-bit word has two parts:
|
---|
2057 | *
|
---|
2058 | * The first 14-bit forms the @a idx field. It is either the index of a page in
|
---|
2059 | * the shadow page pool, or and index into the extent list.
|
---|
2060 | *
|
---|
2061 | * The 2 topmost bits makes up the @a cRefs field, which counts the number of
|
---|
2062 | * shadow page pool references to the page. If cRefs equals
|
---|
2063 | * PGMPOOL_CREFS_PHYSEXT, then the @a idx field is an indext into the extent
|
---|
2064 | * (misnomer) table and not the shadow page pool.
|
---|
2065 | *
|
---|
2066 | * See PGM_PAGE_GET_TRACKING and PGM_PAGE_SET_TRACKING for how to get and set
|
---|
2067 | * the 16-bit word.
|
---|
2068 | *
|
---|
2069 | * @{ */
|
---|
2070 | /** The shift count for getting to the cRefs part. */
|
---|
2071 | #define PGMPOOL_TD_CREFS_SHIFT 14
|
---|
2072 | /** The mask applied after shifting the tracking data down by
|
---|
2073 | * PGMPOOL_TD_CREFS_SHIFT. */
|
---|
2074 | #define PGMPOOL_TD_CREFS_MASK 0x3
|
---|
2075 | /** The cRef value used to indiciate that the idx is the head of a
|
---|
2076 | * physical cross reference list. */
|
---|
2077 | #define PGMPOOL_TD_CREFS_PHYSEXT PGMPOOL_TD_CREFS_MASK
|
---|
2078 | /** The shift used to get idx. */
|
---|
2079 | #define PGMPOOL_TD_IDX_SHIFT 0
|
---|
2080 | /** The mask applied to the idx after shifting down by PGMPOOL_TD_IDX_SHIFT. */
|
---|
2081 | #define PGMPOOL_TD_IDX_MASK 0x3fff
|
---|
2082 | /** The idx value when we're out of of PGMPOOLPHYSEXT entries or/and there are
|
---|
2083 | * simply too many mappings of this page. */
|
---|
2084 | #define PGMPOOL_TD_IDX_OVERFLOWED PGMPOOL_TD_IDX_MASK
|
---|
2085 |
|
---|
2086 | /** @def PGMPOOL_TD_MAKE
|
---|
2087 | * Makes a 16-bit tracking data word.
|
---|
2088 | *
|
---|
2089 | * @returns tracking data.
|
---|
2090 | * @param cRefs The @a cRefs field. Must be within bounds!
|
---|
2091 | * @param idx The @a idx field. Must also be within bounds! */
|
---|
2092 | #define PGMPOOL_TD_MAKE(cRefs, idx) ( ((cRefs) << PGMPOOL_TD_CREFS_SHIFT) | (idx) )
|
---|
2093 |
|
---|
2094 | /** @def PGMPOOL_TD_GET_CREFS
|
---|
2095 | * Get the @a cRefs field from a tracking data word.
|
---|
2096 | *
|
---|
2097 | * @returns The @a cRefs field
|
---|
2098 | * @param u16 The tracking data word. */
|
---|
2099 | #define PGMPOOL_TD_GET_CREFS(u16) ( ((u16) >> PGMPOOL_TD_CREFS_SHIFT) & PGMPOOL_TD_CREFS_MASK )
|
---|
2100 |
|
---|
2101 | /** @def PGMPOOL_TD_GET_IDX
|
---|
2102 | * Get the @a idx field from a tracking data word.
|
---|
2103 | *
|
---|
2104 | * @returns The @a idx field
|
---|
2105 | * @param u16 The tracking data word. */
|
---|
2106 | #define PGMPOOL_TD_GET_IDX(u16) ( ((u16) >> PGMPOOL_TD_IDX_SHIFT) & PGMPOOL_TD_IDX_MASK )
|
---|
2107 | /** @} */
|
---|
2108 |
|
---|
2109 |
|
---|
2110 | /**
|
---|
2111 | * Trees are using self relative offsets as pointers.
|
---|
2112 | * So, all its data, including the root pointer, must be in the heap for HC and GC
|
---|
2113 | * to have the same layout.
|
---|
2114 | */
|
---|
2115 | typedef struct PGMTREES
|
---|
2116 | {
|
---|
2117 | /** Physical access handlers (AVL range+offsetptr tree). */
|
---|
2118 | AVLROGCPHYSTREE PhysHandlers;
|
---|
2119 | /** Virtual access handlers (AVL range + GC ptr tree). */
|
---|
2120 | AVLROGCPTRTREE VirtHandlers;
|
---|
2121 | /** Virtual access handlers (Phys range AVL range + offsetptr tree). */
|
---|
2122 | AVLROGCPHYSTREE PhysToVirtHandlers;
|
---|
2123 | /** Virtual access handlers for the hypervisor (AVL range + GC ptr tree). */
|
---|
2124 | AVLROGCPTRTREE HyperVirtHandlers;
|
---|
2125 | } PGMTREES;
|
---|
2126 | /** Pointer to PGM trees. */
|
---|
2127 | typedef PGMTREES *PPGMTREES;
|
---|
2128 |
|
---|
2129 |
|
---|
2130 | /** @name Paging mode macros
|
---|
2131 | * @{ */
|
---|
2132 | #ifdef IN_RC
|
---|
2133 | # define PGM_CTX(a,b) a##RC##b
|
---|
2134 | # define PGM_CTX_STR(a,b) a "GC" b
|
---|
2135 | # define PGM_CTX_DECL(type) VMMRCDECL(type)
|
---|
2136 | #else
|
---|
2137 | # ifdef IN_RING3
|
---|
2138 | # define PGM_CTX(a,b) a##R3##b
|
---|
2139 | # define PGM_CTX_STR(a,b) a "R3" b
|
---|
2140 | # define PGM_CTX_DECL(type) DECLCALLBACK(type)
|
---|
2141 | # else
|
---|
2142 | # define PGM_CTX(a,b) a##R0##b
|
---|
2143 | # define PGM_CTX_STR(a,b) a "R0" b
|
---|
2144 | # define PGM_CTX_DECL(type) VMMDECL(type)
|
---|
2145 | # endif
|
---|
2146 | #endif
|
---|
2147 |
|
---|
2148 | #define PGM_GST_NAME_REAL(name) PGM_CTX(pgm,GstReal##name)
|
---|
2149 | #define PGM_GST_NAME_RC_REAL_STR(name) "pgmRCGstReal" #name
|
---|
2150 | #define PGM_GST_NAME_R0_REAL_STR(name) "pgmR0GstReal" #name
|
---|
2151 | #define PGM_GST_NAME_PROT(name) PGM_CTX(pgm,GstProt##name)
|
---|
2152 | #define PGM_GST_NAME_RC_PROT_STR(name) "pgmRCGstProt" #name
|
---|
2153 | #define PGM_GST_NAME_R0_PROT_STR(name) "pgmR0GstProt" #name
|
---|
2154 | #define PGM_GST_NAME_32BIT(name) PGM_CTX(pgm,Gst32Bit##name)
|
---|
2155 | #define PGM_GST_NAME_RC_32BIT_STR(name) "pgmRCGst32Bit" #name
|
---|
2156 | #define PGM_GST_NAME_R0_32BIT_STR(name) "pgmR0Gst32Bit" #name
|
---|
2157 | #define PGM_GST_NAME_PAE(name) PGM_CTX(pgm,GstPAE##name)
|
---|
2158 | #define PGM_GST_NAME_RC_PAE_STR(name) "pgmRCGstPAE" #name
|
---|
2159 | #define PGM_GST_NAME_R0_PAE_STR(name) "pgmR0GstPAE" #name
|
---|
2160 | #define PGM_GST_NAME_AMD64(name) PGM_CTX(pgm,GstAMD64##name)
|
---|
2161 | #define PGM_GST_NAME_RC_AMD64_STR(name) "pgmRCGstAMD64" #name
|
---|
2162 | #define PGM_GST_NAME_R0_AMD64_STR(name) "pgmR0GstAMD64" #name
|
---|
2163 | #define PGM_GST_PFN(name, pVCpu) ((pVCpu)->pgm.s.PGM_CTX(pfn,Gst##name))
|
---|
2164 | #define PGM_GST_DECL(type, name) PGM_CTX_DECL(type) PGM_GST_NAME(name)
|
---|
2165 |
|
---|
2166 | #define PGM_SHW_NAME_32BIT(name) PGM_CTX(pgm,Shw32Bit##name)
|
---|
2167 | #define PGM_SHW_NAME_RC_32BIT_STR(name) "pgmRCShw32Bit" #name
|
---|
2168 | #define PGM_SHW_NAME_R0_32BIT_STR(name) "pgmR0Shw32Bit" #name
|
---|
2169 | #define PGM_SHW_NAME_PAE(name) PGM_CTX(pgm,ShwPAE##name)
|
---|
2170 | #define PGM_SHW_NAME_RC_PAE_STR(name) "pgmRCShwPAE" #name
|
---|
2171 | #define PGM_SHW_NAME_R0_PAE_STR(name) "pgmR0ShwPAE" #name
|
---|
2172 | #define PGM_SHW_NAME_AMD64(name) PGM_CTX(pgm,ShwAMD64##name)
|
---|
2173 | #define PGM_SHW_NAME_RC_AMD64_STR(name) "pgmRCShwAMD64" #name
|
---|
2174 | #define PGM_SHW_NAME_R0_AMD64_STR(name) "pgmR0ShwAMD64" #name
|
---|
2175 | #define PGM_SHW_NAME_NESTED(name) PGM_CTX(pgm,ShwNested##name)
|
---|
2176 | #define PGM_SHW_NAME_RC_NESTED_STR(name) "pgmRCShwNested" #name
|
---|
2177 | #define PGM_SHW_NAME_R0_NESTED_STR(name) "pgmR0ShwNested" #name
|
---|
2178 | #define PGM_SHW_NAME_EPT(name) PGM_CTX(pgm,ShwEPT##name)
|
---|
2179 | #define PGM_SHW_NAME_RC_EPT_STR(name) "pgmRCShwEPT" #name
|
---|
2180 | #define PGM_SHW_NAME_R0_EPT_STR(name) "pgmR0ShwEPT" #name
|
---|
2181 | #define PGM_SHW_DECL(type, name) PGM_CTX_DECL(type) PGM_SHW_NAME(name)
|
---|
2182 | #define PGM_SHW_PFN(name, pVCpu) ((pVCpu)->pgm.s.PGM_CTX(pfn,Shw##name))
|
---|
2183 |
|
---|
2184 | /* Shw_Gst */
|
---|
2185 | #define PGM_BTH_NAME_32BIT_REAL(name) PGM_CTX(pgm,Bth32BitReal##name)
|
---|
2186 | #define PGM_BTH_NAME_32BIT_PROT(name) PGM_CTX(pgm,Bth32BitProt##name)
|
---|
2187 | #define PGM_BTH_NAME_32BIT_32BIT(name) PGM_CTX(pgm,Bth32Bit32Bit##name)
|
---|
2188 | #define PGM_BTH_NAME_PAE_REAL(name) PGM_CTX(pgm,BthPAEReal##name)
|
---|
2189 | #define PGM_BTH_NAME_PAE_PROT(name) PGM_CTX(pgm,BthPAEProt##name)
|
---|
2190 | #define PGM_BTH_NAME_PAE_32BIT(name) PGM_CTX(pgm,BthPAE32Bit##name)
|
---|
2191 | #define PGM_BTH_NAME_PAE_PAE(name) PGM_CTX(pgm,BthPAEPAE##name)
|
---|
2192 | #define PGM_BTH_NAME_AMD64_PROT(name) PGM_CTX(pgm,BthAMD64Prot##name)
|
---|
2193 | #define PGM_BTH_NAME_AMD64_AMD64(name) PGM_CTX(pgm,BthAMD64AMD64##name)
|
---|
2194 | #define PGM_BTH_NAME_NESTED_REAL(name) PGM_CTX(pgm,BthNestedReal##name)
|
---|
2195 | #define PGM_BTH_NAME_NESTED_PROT(name) PGM_CTX(pgm,BthNestedProt##name)
|
---|
2196 | #define PGM_BTH_NAME_NESTED_32BIT(name) PGM_CTX(pgm,BthNested32Bit##name)
|
---|
2197 | #define PGM_BTH_NAME_NESTED_PAE(name) PGM_CTX(pgm,BthNestedPAE##name)
|
---|
2198 | #define PGM_BTH_NAME_NESTED_AMD64(name) PGM_CTX(pgm,BthNestedAMD64##name)
|
---|
2199 | #define PGM_BTH_NAME_EPT_REAL(name) PGM_CTX(pgm,BthEPTReal##name)
|
---|
2200 | #define PGM_BTH_NAME_EPT_PROT(name) PGM_CTX(pgm,BthEPTProt##name)
|
---|
2201 | #define PGM_BTH_NAME_EPT_32BIT(name) PGM_CTX(pgm,BthEPT32Bit##name)
|
---|
2202 | #define PGM_BTH_NAME_EPT_PAE(name) PGM_CTX(pgm,BthEPTPAE##name)
|
---|
2203 | #define PGM_BTH_NAME_EPT_AMD64(name) PGM_CTX(pgm,BthEPTAMD64##name)
|
---|
2204 |
|
---|
2205 | #define PGM_BTH_NAME_RC_32BIT_REAL_STR(name) "pgmRCBth32BitReal" #name
|
---|
2206 | #define PGM_BTH_NAME_RC_32BIT_PROT_STR(name) "pgmRCBth32BitProt" #name
|
---|
2207 | #define PGM_BTH_NAME_RC_32BIT_32BIT_STR(name) "pgmRCBth32Bit32Bit" #name
|
---|
2208 | #define PGM_BTH_NAME_RC_PAE_REAL_STR(name) "pgmRCBthPAEReal" #name
|
---|
2209 | #define PGM_BTH_NAME_RC_PAE_PROT_STR(name) "pgmRCBthPAEProt" #name
|
---|
2210 | #define PGM_BTH_NAME_RC_PAE_32BIT_STR(name) "pgmRCBthPAE32Bit" #name
|
---|
2211 | #define PGM_BTH_NAME_RC_PAE_PAE_STR(name) "pgmRCBthPAEPAE" #name
|
---|
2212 | #define PGM_BTH_NAME_RC_AMD64_AMD64_STR(name) "pgmRCBthAMD64AMD64" #name
|
---|
2213 | #define PGM_BTH_NAME_RC_NESTED_REAL_STR(name) "pgmRCBthNestedReal" #name
|
---|
2214 | #define PGM_BTH_NAME_RC_NESTED_PROT_STR(name) "pgmRCBthNestedProt" #name
|
---|
2215 | #define PGM_BTH_NAME_RC_NESTED_32BIT_STR(name) "pgmRCBthNested32Bit" #name
|
---|
2216 | #define PGM_BTH_NAME_RC_NESTED_PAE_STR(name) "pgmRCBthNestedPAE" #name
|
---|
2217 | #define PGM_BTH_NAME_RC_NESTED_AMD64_STR(name) "pgmRCBthNestedAMD64" #name
|
---|
2218 | #define PGM_BTH_NAME_RC_EPT_REAL_STR(name) "pgmRCBthEPTReal" #name
|
---|
2219 | #define PGM_BTH_NAME_RC_EPT_PROT_STR(name) "pgmRCBthEPTProt" #name
|
---|
2220 | #define PGM_BTH_NAME_RC_EPT_32BIT_STR(name) "pgmRCBthEPT32Bit" #name
|
---|
2221 | #define PGM_BTH_NAME_RC_EPT_PAE_STR(name) "pgmRCBthEPTPAE" #name
|
---|
2222 | #define PGM_BTH_NAME_RC_EPT_AMD64_STR(name) "pgmRCBthEPTAMD64" #name
|
---|
2223 | #define PGM_BTH_NAME_R0_32BIT_REAL_STR(name) "pgmR0Bth32BitReal" #name
|
---|
2224 | #define PGM_BTH_NAME_R0_32BIT_PROT_STR(name) "pgmR0Bth32BitProt" #name
|
---|
2225 | #define PGM_BTH_NAME_R0_32BIT_32BIT_STR(name) "pgmR0Bth32Bit32Bit" #name
|
---|
2226 | #define PGM_BTH_NAME_R0_PAE_REAL_STR(name) "pgmR0BthPAEReal" #name
|
---|
2227 | #define PGM_BTH_NAME_R0_PAE_PROT_STR(name) "pgmR0BthPAEProt" #name
|
---|
2228 | #define PGM_BTH_NAME_R0_PAE_32BIT_STR(name) "pgmR0BthPAE32Bit" #name
|
---|
2229 | #define PGM_BTH_NAME_R0_PAE_PAE_STR(name) "pgmR0BthPAEPAE" #name
|
---|
2230 | #define PGM_BTH_NAME_R0_AMD64_PROT_STR(name) "pgmR0BthAMD64Prot" #name
|
---|
2231 | #define PGM_BTH_NAME_R0_AMD64_AMD64_STR(name) "pgmR0BthAMD64AMD64" #name
|
---|
2232 | #define PGM_BTH_NAME_R0_NESTED_REAL_STR(name) "pgmR0BthNestedReal" #name
|
---|
2233 | #define PGM_BTH_NAME_R0_NESTED_PROT_STR(name) "pgmR0BthNestedProt" #name
|
---|
2234 | #define PGM_BTH_NAME_R0_NESTED_32BIT_STR(name) "pgmR0BthNested32Bit" #name
|
---|
2235 | #define PGM_BTH_NAME_R0_NESTED_PAE_STR(name) "pgmR0BthNestedPAE" #name
|
---|
2236 | #define PGM_BTH_NAME_R0_NESTED_AMD64_STR(name) "pgmR0BthNestedAMD64" #name
|
---|
2237 | #define PGM_BTH_NAME_R0_EPT_REAL_STR(name) "pgmR0BthEPTReal" #name
|
---|
2238 | #define PGM_BTH_NAME_R0_EPT_PROT_STR(name) "pgmR0BthEPTProt" #name
|
---|
2239 | #define PGM_BTH_NAME_R0_EPT_32BIT_STR(name) "pgmR0BthEPT32Bit" #name
|
---|
2240 | #define PGM_BTH_NAME_R0_EPT_PAE_STR(name) "pgmR0BthEPTPAE" #name
|
---|
2241 | #define PGM_BTH_NAME_R0_EPT_AMD64_STR(name) "pgmR0BthEPTAMD64" #name
|
---|
2242 |
|
---|
2243 | #define PGM_BTH_DECL(type, name) PGM_CTX_DECL(type) PGM_BTH_NAME(name)
|
---|
2244 | #define PGM_BTH_PFN(name, pVCpu) ((pVCpu)->pgm.s.PGM_CTX(pfn,Bth##name))
|
---|
2245 | /** @} */
|
---|
2246 |
|
---|
2247 | /**
|
---|
2248 | * Data for each paging mode.
|
---|
2249 | */
|
---|
2250 | typedef struct PGMMODEDATA
|
---|
2251 | {
|
---|
2252 | /** The guest mode type. */
|
---|
2253 | uint32_t uGstType;
|
---|
2254 | /** The shadow mode type. */
|
---|
2255 | uint32_t uShwType;
|
---|
2256 |
|
---|
2257 | /** @name Function pointers for Shadow paging.
|
---|
2258 | * @{
|
---|
2259 | */
|
---|
2260 | DECLR3CALLBACKMEMBER(int, pfnR3ShwRelocate,(PVMCPU pVCpu, RTGCPTR offDelta));
|
---|
2261 | DECLR3CALLBACKMEMBER(int, pfnR3ShwExit,(PVMCPU pVCpu));
|
---|
2262 | DECLR3CALLBACKMEMBER(int, pfnR3ShwGetPage,(PVMCPU pVCpu, RTGCPTR GCPtr, uint64_t *pfFlags, PRTHCPHYS pHCPhys));
|
---|
2263 | DECLR3CALLBACKMEMBER(int, pfnR3ShwModifyPage,(PVMCPU pVCpu, RTGCPTR GCPtr, size_t cbPages, uint64_t fFlags, uint64_t fMask));
|
---|
2264 |
|
---|
2265 | DECLRCCALLBACKMEMBER(int, pfnRCShwGetPage,(PVMCPU pVCpu, RTGCPTR GCPtr, uint64_t *pfFlags, PRTHCPHYS pHCPhys));
|
---|
2266 | DECLRCCALLBACKMEMBER(int, pfnRCShwModifyPage,(PVMCPU pVCpu, RTGCPTR GCPtr, size_t cbPages, uint64_t fFlags, uint64_t fMask));
|
---|
2267 |
|
---|
2268 | DECLR0CALLBACKMEMBER(int, pfnR0ShwGetPage,(PVMCPU pVCpu, RTGCPTR GCPtr, uint64_t *pfFlags, PRTHCPHYS pHCPhys));
|
---|
2269 | DECLR0CALLBACKMEMBER(int, pfnR0ShwModifyPage,(PVMCPU pVCpu, RTGCPTR GCPtr, size_t cbPages, uint64_t fFlags, uint64_t fMask));
|
---|
2270 | /** @} */
|
---|
2271 |
|
---|
2272 | /** @name Function pointers for Guest paging.
|
---|
2273 | * @{
|
---|
2274 | */
|
---|
2275 | DECLR3CALLBACKMEMBER(int, pfnR3GstRelocate,(PVMCPU pVCpu, RTGCPTR offDelta));
|
---|
2276 | DECLR3CALLBACKMEMBER(int, pfnR3GstExit,(PVMCPU pVCpu));
|
---|
2277 | DECLR3CALLBACKMEMBER(int, pfnR3GstGetPage,(PVMCPU pVCpu, RTGCPTR GCPtr, uint64_t *pfFlags, PRTGCPHYS pGCPhys));
|
---|
2278 | DECLR3CALLBACKMEMBER(int, pfnR3GstModifyPage,(PVMCPU pVCpu, RTGCPTR GCPtr, size_t cbPages, uint64_t fFlags, uint64_t fMask));
|
---|
2279 | DECLR3CALLBACKMEMBER(int, pfnR3GstGetPDE,(PVMCPU pVCpu, RTGCPTR GCPtr, PX86PDEPAE pPde));
|
---|
2280 | DECLRCCALLBACKMEMBER(int, pfnRCGstGetPage,(PVMCPU pVCpu, RTGCPTR GCPtr, uint64_t *pfFlags, PRTGCPHYS pGCPhys));
|
---|
2281 | DECLRCCALLBACKMEMBER(int, pfnRCGstModifyPage,(PVMCPU pVCpu, RTGCPTR GCPtr, size_t cbPages, uint64_t fFlags, uint64_t fMask));
|
---|
2282 | DECLRCCALLBACKMEMBER(int, pfnRCGstGetPDE,(PVMCPU pVCpu, RTGCPTR GCPtr, PX86PDEPAE pPde));
|
---|
2283 | DECLR0CALLBACKMEMBER(int, pfnR0GstGetPage,(PVMCPU pVCpu, RTGCPTR GCPtr, uint64_t *pfFlags, PRTGCPHYS pGCPhys));
|
---|
2284 | DECLR0CALLBACKMEMBER(int, pfnR0GstModifyPage,(PVMCPU pVCpu, RTGCPTR GCPtr, size_t cbPages, uint64_t fFlags, uint64_t fMask));
|
---|
2285 | DECLR0CALLBACKMEMBER(int, pfnR0GstGetPDE,(PVMCPU pVCpu, RTGCPTR GCPtr, PX86PDEPAE pPde));
|
---|
2286 | /** @} */
|
---|
2287 |
|
---|
2288 | /** @name Function pointers for Both Shadow and Guest paging.
|
---|
2289 | * @{
|
---|
2290 | */
|
---|
2291 | DECLR3CALLBACKMEMBER(int, pfnR3BthRelocate,(PVMCPU pVCpu, RTGCPTR offDelta));
|
---|
2292 | /* no pfnR3BthTrap0eHandler */
|
---|
2293 | DECLR3CALLBACKMEMBER(int, pfnR3BthInvalidatePage,(PVMCPU pVCpu, RTGCPTR GCPtrPage));
|
---|
2294 | DECLR3CALLBACKMEMBER(int, pfnR3BthSyncCR3,(PVMCPU pVCpu, uint64_t cr0, uint64_t cr3, uint64_t cr4, bool fGlobal));
|
---|
2295 | DECLR3CALLBACKMEMBER(int, pfnR3BthSyncPage,(PVMCPU pVCpu, X86PDE PdeSrc, RTGCPTR GCPtrPage, unsigned cPages, unsigned uError));
|
---|
2296 | DECLR3CALLBACKMEMBER(int, pfnR3BthPrefetchPage,(PVMCPU pVCpu, RTGCPTR GCPtrPage));
|
---|
2297 | DECLR3CALLBACKMEMBER(int, pfnR3BthVerifyAccessSyncPage,(PVMCPU pVCpu, RTGCPTR GCPtrPage, unsigned fFlags, unsigned uError));
|
---|
2298 | #ifdef VBOX_STRICT
|
---|
2299 | DECLR3CALLBACKMEMBER(unsigned, pfnR3BthAssertCR3,(PVMCPU pVCpu, uint64_t cr3, uint64_t cr4, RTGCPTR GCPtr, RTGCPTR cb));
|
---|
2300 | #endif
|
---|
2301 | DECLR3CALLBACKMEMBER(int, pfnR3BthMapCR3,(PVMCPU pVCpu, RTGCPHYS GCPhysCR3));
|
---|
2302 | DECLR3CALLBACKMEMBER(int, pfnR3BthUnmapCR3,(PVMCPU pVCpu));
|
---|
2303 |
|
---|
2304 | DECLRCCALLBACKMEMBER(int, pfnRCBthTrap0eHandler,(PVMCPU pVCpu, RTGCUINT uErr, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault));
|
---|
2305 | DECLRCCALLBACKMEMBER(int, pfnRCBthInvalidatePage,(PVMCPU pVCpu, RTGCPTR GCPtrPage));
|
---|
2306 | DECLRCCALLBACKMEMBER(int, pfnRCBthSyncCR3,(PVMCPU pVCpu, uint64_t cr0, uint64_t cr3, uint64_t cr4, bool fGlobal));
|
---|
2307 | DECLRCCALLBACKMEMBER(int, pfnRCBthSyncPage,(PVMCPU pVCpu, X86PDE PdeSrc, RTGCPTR GCPtrPage, unsigned cPages, unsigned uError));
|
---|
2308 | DECLRCCALLBACKMEMBER(int, pfnRCBthPrefetchPage,(PVMCPU pVCpu, RTGCPTR GCPtrPage));
|
---|
2309 | DECLRCCALLBACKMEMBER(int, pfnRCBthVerifyAccessSyncPage,(PVMCPU pVCpu, RTGCPTR GCPtrPage, unsigned fFlags, unsigned uError));
|
---|
2310 | #ifdef VBOX_STRICT
|
---|
2311 | DECLRCCALLBACKMEMBER(unsigned, pfnRCBthAssertCR3,(PVMCPU pVCpu, uint64_t cr3, uint64_t cr4, RTGCPTR GCPtr, RTGCPTR cb));
|
---|
2312 | #endif
|
---|
2313 | DECLRCCALLBACKMEMBER(int, pfnRCBthMapCR3,(PVMCPU pVCpu, RTGCPHYS GCPhysCR3));
|
---|
2314 | DECLRCCALLBACKMEMBER(int, pfnRCBthUnmapCR3,(PVMCPU pVCpu));
|
---|
2315 |
|
---|
2316 | DECLR0CALLBACKMEMBER(int, pfnR0BthTrap0eHandler,(PVMCPU pVCpu, RTGCUINT uErr, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault));
|
---|
2317 | DECLR0CALLBACKMEMBER(int, pfnR0BthInvalidatePage,(PVMCPU pVCpu, RTGCPTR GCPtrPage));
|
---|
2318 | DECLR0CALLBACKMEMBER(int, pfnR0BthSyncCR3,(PVMCPU pVCpu, uint64_t cr0, uint64_t cr3, uint64_t cr4, bool fGlobal));
|
---|
2319 | DECLR0CALLBACKMEMBER(int, pfnR0BthSyncPage,(PVMCPU pVCpu, X86PDE PdeSrc, RTGCPTR GCPtrPage, unsigned cPages, unsigned uError));
|
---|
2320 | DECLR0CALLBACKMEMBER(int, pfnR0BthPrefetchPage,(PVMCPU pVCpu, RTGCPTR GCPtrPage));
|
---|
2321 | DECLR0CALLBACKMEMBER(int, pfnR0BthVerifyAccessSyncPage,(PVMCPU pVCpu, RTGCPTR GCPtrPage, unsigned fFlags, unsigned uError));
|
---|
2322 | #ifdef VBOX_STRICT
|
---|
2323 | DECLR0CALLBACKMEMBER(unsigned, pfnR0BthAssertCR3,(PVMCPU pVCpu, uint64_t cr3, uint64_t cr4, RTGCPTR GCPtr, RTGCPTR cb));
|
---|
2324 | #endif
|
---|
2325 | DECLR0CALLBACKMEMBER(int, pfnR0BthMapCR3,(PVMCPU pVCpu, RTGCPHYS GCPhysCR3));
|
---|
2326 | DECLR0CALLBACKMEMBER(int, pfnR0BthUnmapCR3,(PVMCPU pVCpu));
|
---|
2327 | /** @} */
|
---|
2328 | } PGMMODEDATA, *PPGMMODEDATA;
|
---|
2329 |
|
---|
2330 |
|
---|
2331 |
|
---|
2332 | /**
|
---|
2333 | * Converts a PGM pointer into a VM pointer.
|
---|
2334 | * @returns Pointer to the VM structure the PGM is part of.
|
---|
2335 | * @param pPGM Pointer to PGM instance data.
|
---|
2336 | */
|
---|
2337 | #define PGM2VM(pPGM) ( (PVM)((char*)pPGM - pPGM->offVM) )
|
---|
2338 |
|
---|
2339 | /**
|
---|
2340 | * PGM Data (part of VM)
|
---|
2341 | */
|
---|
2342 | typedef struct PGM
|
---|
2343 | {
|
---|
2344 | /** Offset to the VM structure. */
|
---|
2345 | RTINT offVM;
|
---|
2346 | /** Offset of the PGMCPU structure relative to VMCPU. */
|
---|
2347 | RTINT offVCpuPGM;
|
---|
2348 |
|
---|
2349 | /** @cfgm{RamPreAlloc, boolean, false}
|
---|
2350 | * Indicates whether the base RAM should all be allocated before starting
|
---|
2351 | * the VM (default), or if it should be allocated when first written to.
|
---|
2352 | */
|
---|
2353 | bool fRamPreAlloc;
|
---|
2354 | /** Indicates whether write monitoring is currently in use.
|
---|
2355 | * This is used to prevent conflicts between live saving and page sharing
|
---|
2356 | * detection. */
|
---|
2357 | bool fPhysWriteMonitoringEngaged;
|
---|
2358 | /** Alignment padding. */
|
---|
2359 | bool afAlignment0[2];
|
---|
2360 |
|
---|
2361 | /*
|
---|
2362 | * This will be redefined at least two more times before we're done, I'm sure.
|
---|
2363 | * The current code is only to get on with the coding.
|
---|
2364 | * - 2004-06-10: initial version, bird.
|
---|
2365 | * - 2004-07-02: 1st time, bird.
|
---|
2366 | * - 2004-10-18: 2nd time, bird.
|
---|
2367 | * - 2005-07-xx: 3rd time, bird.
|
---|
2368 | */
|
---|
2369 |
|
---|
2370 | /** The host paging mode. (This is what SUPLib reports.) */
|
---|
2371 | SUPPAGINGMODE enmHostMode;
|
---|
2372 |
|
---|
2373 | /** Pointer to the page table entries for the dynamic page mapping area - GCPtr. */
|
---|
2374 | RCPTRTYPE(PX86PTE) paDynPageMap32BitPTEsGC;
|
---|
2375 | /** Pointer to the page table entries for the dynamic page mapping area - GCPtr. */
|
---|
2376 | RCPTRTYPE(PX86PTEPAE) paDynPageMapPaePTEsGC;
|
---|
2377 |
|
---|
2378 | /** 4 MB page mask; 32 or 36 bits depending on PSE-36 (identical for all VCPUs) */
|
---|
2379 | RTGCPHYS GCPhys4MBPSEMask;
|
---|
2380 |
|
---|
2381 | /** Pointer to the list of RAM ranges (Phys GC -> Phys HC conversion) - for R3.
|
---|
2382 | * This is sorted by physical address and contains no overlapping ranges. */
|
---|
2383 | R3PTRTYPE(PPGMRAMRANGE) pRamRangesR3;
|
---|
2384 | /** R0 pointer corresponding to PGM::pRamRangesR3. */
|
---|
2385 | R0PTRTYPE(PPGMRAMRANGE) pRamRangesR0;
|
---|
2386 | /** RC pointer corresponding to PGM::pRamRangesR3. */
|
---|
2387 | RCPTRTYPE(PPGMRAMRANGE) pRamRangesRC;
|
---|
2388 | /** Generation ID for the RAM ranges. This member is incremented everytime a RAM
|
---|
2389 | * range is linked or unlinked. */
|
---|
2390 | uint32_t volatile idRamRangesGen;
|
---|
2391 |
|
---|
2392 | /** Pointer to the list of ROM ranges - for R3.
|
---|
2393 | * This is sorted by physical address and contains no overlapping ranges. */
|
---|
2394 | R3PTRTYPE(PPGMROMRANGE) pRomRangesR3;
|
---|
2395 | /** R0 pointer corresponding to PGM::pRomRangesR3. */
|
---|
2396 | R0PTRTYPE(PPGMROMRANGE) pRomRangesR0;
|
---|
2397 | /** RC pointer corresponding to PGM::pRomRangesR3. */
|
---|
2398 | RCPTRTYPE(PPGMROMRANGE) pRomRangesRC;
|
---|
2399 | #if HC_ARCH_BITS == 64
|
---|
2400 | /** Alignment padding. */
|
---|
2401 | RTRCPTR GCPtrPadding2;
|
---|
2402 | #endif
|
---|
2403 |
|
---|
2404 | /** Pointer to the list of MMIO2 ranges - for R3.
|
---|
2405 | * Registration order. */
|
---|
2406 | R3PTRTYPE(PPGMMMIO2RANGE) pMmio2RangesR3;
|
---|
2407 |
|
---|
2408 | /** PGM offset based trees - R3 Ptr. */
|
---|
2409 | R3PTRTYPE(PPGMTREES) pTreesR3;
|
---|
2410 | /** PGM offset based trees - R0 Ptr. */
|
---|
2411 | R0PTRTYPE(PPGMTREES) pTreesR0;
|
---|
2412 | /** PGM offset based trees - RC Ptr. */
|
---|
2413 | RCPTRTYPE(PPGMTREES) pTreesRC;
|
---|
2414 |
|
---|
2415 | /** Linked list of GC mappings - for RC.
|
---|
2416 | * The list is sorted ascending on address.
|
---|
2417 | */
|
---|
2418 | RCPTRTYPE(PPGMMAPPING) pMappingsRC;
|
---|
2419 | /** Linked list of GC mappings - for HC.
|
---|
2420 | * The list is sorted ascending on address.
|
---|
2421 | */
|
---|
2422 | R3PTRTYPE(PPGMMAPPING) pMappingsR3;
|
---|
2423 | /** Linked list of GC mappings - for R0.
|
---|
2424 | * The list is sorted ascending on address.
|
---|
2425 | */
|
---|
2426 | R0PTRTYPE(PPGMMAPPING) pMappingsR0;
|
---|
2427 |
|
---|
2428 | /** Pointer to the 5 page CR3 content mapping.
|
---|
2429 | * The first page is always the CR3 (in some form) while the 4 other pages
|
---|
2430 | * are used of the PDs in PAE mode. */
|
---|
2431 | RTGCPTR GCPtrCR3Mapping;
|
---|
2432 | #if HC_ARCH_BITS == 64 && GC_ARCH_BITS == 32
|
---|
2433 | uint32_t u32Alignment1;
|
---|
2434 | #endif
|
---|
2435 |
|
---|
2436 | /** Indicates that PGMR3FinalizeMappings has been called and that further
|
---|
2437 | * PGMR3MapIntermediate calls will be rejected. */
|
---|
2438 | bool fFinalizedMappings;
|
---|
2439 | /** If set no conflict checks are required. (boolean) */
|
---|
2440 | bool fMappingsFixed;
|
---|
2441 | /** If set, then no mappings are put into the shadow page table. (boolean) */
|
---|
2442 | bool fDisableMappings;
|
---|
2443 | /** Size of fixed mapping */
|
---|
2444 | uint32_t cbMappingFixed;
|
---|
2445 | /** Base address (GC) of fixed mapping */
|
---|
2446 | RTGCPTR GCPtrMappingFixed;
|
---|
2447 | /** The address of the previous RAM range mapping. */
|
---|
2448 | RTGCPTR GCPtrPrevRamRangeMapping;
|
---|
2449 |
|
---|
2450 | /** @name Intermediate Context
|
---|
2451 | * @{ */
|
---|
2452 | /** Pointer to the intermediate page directory - Normal. */
|
---|
2453 | R3PTRTYPE(PX86PD) pInterPD;
|
---|
2454 | /** Pointer to the intermedate page tables - Normal.
|
---|
2455 | * There are two page tables, one for the identity mapping and one for
|
---|
2456 | * the host context mapping (of the core code). */
|
---|
2457 | R3PTRTYPE(PX86PT) apInterPTs[2];
|
---|
2458 | /** Pointer to the intermedate page tables - PAE. */
|
---|
2459 | R3PTRTYPE(PX86PTPAE) apInterPaePTs[2];
|
---|
2460 | /** Pointer to the intermedate page directory - PAE. */
|
---|
2461 | R3PTRTYPE(PX86PDPAE) apInterPaePDs[4];
|
---|
2462 | /** Pointer to the intermedate page directory - PAE. */
|
---|
2463 | R3PTRTYPE(PX86PDPT) pInterPaePDPT;
|
---|
2464 | /** Pointer to the intermedate page-map level 4 - AMD64. */
|
---|
2465 | R3PTRTYPE(PX86PML4) pInterPaePML4;
|
---|
2466 | /** Pointer to the intermedate page directory - AMD64. */
|
---|
2467 | R3PTRTYPE(PX86PDPT) pInterPaePDPT64;
|
---|
2468 | /** The Physical Address (HC) of the intermediate Page Directory - Normal. */
|
---|
2469 | RTHCPHYS HCPhysInterPD;
|
---|
2470 | /** The Physical Address (HC) of the intermediate Page Directory Pointer Table - PAE. */
|
---|
2471 | RTHCPHYS HCPhysInterPaePDPT;
|
---|
2472 | /** The Physical Address (HC) of the intermediate Page Map Level 4 table - AMD64. */
|
---|
2473 | RTHCPHYS HCPhysInterPaePML4;
|
---|
2474 | /** @} */
|
---|
2475 |
|
---|
2476 | /** Base address of the dynamic page mapping area.
|
---|
2477 | * The array is MM_HYPER_DYNAMIC_SIZE bytes big.
|
---|
2478 | */
|
---|
2479 | RCPTRTYPE(uint8_t *) pbDynPageMapBaseGC;
|
---|
2480 | /** The index of the last entry used in the dynamic page mapping area. */
|
---|
2481 | RTUINT iDynPageMapLast;
|
---|
2482 | /** Cache containing the last entries in the dynamic page mapping area.
|
---|
2483 | * The cache size is covering half of the mapping area. */
|
---|
2484 | RTHCPHYS aHCPhysDynPageMapCache[MM_HYPER_DYNAMIC_SIZE >> (PAGE_SHIFT + 1)];
|
---|
2485 | /** Keep a lock counter for the full (!) mapping area. */
|
---|
2486 | uint32_t aLockedDynPageMapCache[MM_HYPER_DYNAMIC_SIZE >> (PAGE_SHIFT)];
|
---|
2487 |
|
---|
2488 | /** The address of the ring-0 mapping cache if we're making use of it. */
|
---|
2489 | RTR0PTR pvR0DynMapUsed;
|
---|
2490 | #if HC_ARCH_BITS == 32
|
---|
2491 | /** Alignment padding that makes the next member start on a 8 byte boundrary. */
|
---|
2492 | uint32_t u32Alignment2;
|
---|
2493 | #endif
|
---|
2494 |
|
---|
2495 | /** PGM critical section.
|
---|
2496 | * This protects the physical & virtual access handlers, ram ranges,
|
---|
2497 | * and the page flag updating (some of it anyway).
|
---|
2498 | */
|
---|
2499 | PDMCRITSECT CritSect;
|
---|
2500 |
|
---|
2501 | /** Pointer to SHW+GST mode data (function pointers).
|
---|
2502 | * The index into this table is made up from */
|
---|
2503 | R3PTRTYPE(PPGMMODEDATA) paModeData;
|
---|
2504 |
|
---|
2505 | /** Shadow Page Pool - R3 Ptr. */
|
---|
2506 | R3PTRTYPE(PPGMPOOL) pPoolR3;
|
---|
2507 | /** Shadow Page Pool - R0 Ptr. */
|
---|
2508 | R0PTRTYPE(PPGMPOOL) pPoolR0;
|
---|
2509 | /** Shadow Page Pool - RC Ptr. */
|
---|
2510 | RCPTRTYPE(PPGMPOOL) pPoolRC;
|
---|
2511 |
|
---|
2512 | /** We're not in a state which permits writes to guest memory.
|
---|
2513 | * (Only used in strict builds.) */
|
---|
2514 | bool fNoMorePhysWrites;
|
---|
2515 | /** Alignment padding that makes the next member start on a 8 byte boundrary. */
|
---|
2516 | bool afAlignment3[HC_ARCH_BITS == 32 ? 7: 3];
|
---|
2517 |
|
---|
2518 | /**
|
---|
2519 | * Data associated with managing the ring-3 mappings of the allocation chunks.
|
---|
2520 | */
|
---|
2521 | struct
|
---|
2522 | {
|
---|
2523 | /** The chunk tree, ordered by chunk id. */
|
---|
2524 | #ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
|
---|
2525 | R3PTRTYPE(PAVLU32NODECORE) pTree;
|
---|
2526 | #else
|
---|
2527 | R3R0PTRTYPE(PAVLU32NODECORE) pTree;
|
---|
2528 | #endif
|
---|
2529 | /** The chunk age tree, ordered by ageing sequence number. */
|
---|
2530 | R3PTRTYPE(PAVLLU32NODECORE) pAgeTree;
|
---|
2531 | /** The chunk mapping TLB. */
|
---|
2532 | PGMCHUNKR3MAPTLB Tlb;
|
---|
2533 | /** The number of mapped chunks. */
|
---|
2534 | uint32_t c;
|
---|
2535 | /** The maximum number of mapped chunks.
|
---|
2536 | * @cfgm PGM/MaxRing3Chunks */
|
---|
2537 | uint32_t cMax;
|
---|
2538 | /** The current time. */
|
---|
2539 | uint32_t iNow;
|
---|
2540 | /** Number of pgmR3PhysChunkFindUnmapCandidate calls left to the next ageing. */
|
---|
2541 | uint32_t AgeingCountdown;
|
---|
2542 | } ChunkR3Map;
|
---|
2543 |
|
---|
2544 | /**
|
---|
2545 | * The page mapping TLB for ring-3 and (for the time being) ring-0.
|
---|
2546 | */
|
---|
2547 | PGMPAGER3MAPTLB PhysTlbHC;
|
---|
2548 |
|
---|
2549 | /** @name The zero page.
|
---|
2550 | * @{ */
|
---|
2551 | /** The host physical address of the zero page. */
|
---|
2552 | RTHCPHYS HCPhysZeroPg;
|
---|
2553 | /** The ring-3 mapping of the zero page. */
|
---|
2554 | RTR3PTR pvZeroPgR3;
|
---|
2555 | /** The ring-0 mapping of the zero page. */
|
---|
2556 | RTR0PTR pvZeroPgR0;
|
---|
2557 | /** The GC mapping of the zero page. */
|
---|
2558 | RTGCPTR pvZeroPgRC;
|
---|
2559 | #if GC_ARCH_BITS != 32
|
---|
2560 | uint32_t u32ZeroAlignment; /**< Alignment padding. */
|
---|
2561 | #endif
|
---|
2562 | /** @}*/
|
---|
2563 |
|
---|
2564 | /** The number of handy pages. */
|
---|
2565 | uint32_t cHandyPages;
|
---|
2566 | /**
|
---|
2567 | * Array of handy pages.
|
---|
2568 | *
|
---|
2569 | * This array is used in a two way communication between pgmPhysAllocPage
|
---|
2570 | * and GMMR0AllocateHandyPages, with PGMR3PhysAllocateHandyPages serving as
|
---|
2571 | * an intermediary.
|
---|
2572 | *
|
---|
2573 | * The size of this array is important, see pgmPhysEnsureHandyPage for details.
|
---|
2574 | * (The current size of 32 pages, means 128 KB of handy memory.)
|
---|
2575 | */
|
---|
2576 | GMMPAGEDESC aHandyPages[PGM_HANDY_PAGES];
|
---|
2577 |
|
---|
2578 | /**
|
---|
2579 | * Live save data.
|
---|
2580 | */
|
---|
2581 | struct
|
---|
2582 | {
|
---|
2583 | /** The number of ready pages. */
|
---|
2584 | uint32_t cReadyPages;
|
---|
2585 | /** The number of dirty pages. */
|
---|
2586 | uint32_t cDirtyPages;
|
---|
2587 | /** The number of MMIO and MMIO2 pages. */
|
---|
2588 | uint32_t cMmioPages;
|
---|
2589 | uint32_t u32;
|
---|
2590 | } LiveSave;
|
---|
2591 |
|
---|
2592 | /** @name Error injection.
|
---|
2593 | * @{ */
|
---|
2594 | /** Inject handy page allocation errors pretending we're completely out of
|
---|
2595 | * memory. */
|
---|
2596 | bool volatile fErrInjHandyPages;
|
---|
2597 | /** Padding. */
|
---|
2598 | bool afReserved[7];
|
---|
2599 | /** @} */
|
---|
2600 |
|
---|
2601 | /** @name Release Statistics
|
---|
2602 | * @{ */
|
---|
2603 | uint32_t cAllPages; /**< The total number of pages. (Should be Private + Shared + Zero.) */
|
---|
2604 | uint32_t cPrivatePages; /**< The number of private pages. */
|
---|
2605 | uint32_t cSharedPages; /**< The number of shared pages. */
|
---|
2606 | uint32_t cZeroPages; /**< The number of zero backed pages. */
|
---|
2607 |
|
---|
2608 | /** The number of times we were forced to change the hypervisor region location. */
|
---|
2609 | STAMCOUNTER cRelocations;
|
---|
2610 | /** @} */
|
---|
2611 |
|
---|
2612 | #ifdef VBOX_WITH_STATISTICS /** @todo move this chunk to the heap. */
|
---|
2613 | /* R3 only: */
|
---|
2614 | STAMCOUNTER StatR3DetectedConflicts; /**< R3: Number of times PGMR3MapHasConflicts() detected a conflict. */
|
---|
2615 | STAMPROFILE StatR3ResolveConflict; /**< R3: pgmR3SyncPTResolveConflict() profiling (includes the entire relocation). */
|
---|
2616 |
|
---|
2617 | STAMCOUNTER StatRZChunkR3MapTlbHits; /**< RC/R0: Ring-3/0 chunk mapper TLB hits. */
|
---|
2618 | STAMCOUNTER StatRZChunkR3MapTlbMisses; /**< RC/R0: Ring-3/0 chunk mapper TLB misses. */
|
---|
2619 | STAMCOUNTER StatRZPageMapTlbHits; /**< RC/R0: Ring-3/0 page mapper TLB hits. */
|
---|
2620 | STAMCOUNTER StatRZPageMapTlbMisses; /**< RC/R0: Ring-3/0 page mapper TLB misses. */
|
---|
2621 | STAMCOUNTER StatR3ChunkR3MapTlbHits; /**< R3: Ring-3/0 chunk mapper TLB hits. */
|
---|
2622 | STAMCOUNTER StatR3ChunkR3MapTlbMisses; /**< R3: Ring-3/0 chunk mapper TLB misses. */
|
---|
2623 | STAMCOUNTER StatR3PageMapTlbHits; /**< R3: Ring-3/0 page mapper TLB hits. */
|
---|
2624 | STAMCOUNTER StatR3PageMapTlbMisses; /**< R3: Ring-3/0 page mapper TLB misses. */
|
---|
2625 | STAMPROFILE StatRZSyncCR3HandlerVirtualReset; /**< RC/R0: Profiling of the virtual handler resets. */
|
---|
2626 | STAMPROFILE StatRZSyncCR3HandlerVirtualUpdate; /**< RC/R0: Profiling of the virtual handler updates. */
|
---|
2627 | STAMPROFILE StatR3SyncCR3HandlerVirtualReset; /**< R3: Profiling of the virtual handler resets. */
|
---|
2628 | STAMPROFILE StatR3SyncCR3HandlerVirtualUpdate; /**< R3: Profiling of the virtual handler updates. */
|
---|
2629 | STAMCOUNTER StatR3PhysHandlerReset; /**< R3: The number of times PGMHandlerPhysicalReset is called. */
|
---|
2630 | STAMCOUNTER StatRZPhysHandlerReset; /**< RC/R0: The number of times PGMHandlerPhysicalReset is called. */
|
---|
2631 | STAMPROFILE StatRZVirtHandlerSearchByPhys; /**< RC/R0: Profiling of pgmHandlerVirtualFindByPhysAddr. */
|
---|
2632 | STAMPROFILE StatR3VirtHandlerSearchByPhys; /**< R3: Profiling of pgmHandlerVirtualFindByPhysAddr. */
|
---|
2633 | STAMCOUNTER StatRZPageReplaceShared; /**< RC/R0: Times a shared page has been replaced by a private one. */
|
---|
2634 | STAMCOUNTER StatRZPageReplaceZero; /**< RC/R0: Times the zero page has been replaced by a private one. */
|
---|
2635 | /// @todo STAMCOUNTER StatRZPageHandyAllocs; /**< RC/R0: The number of times we've executed GMMR3AllocateHandyPages. */
|
---|
2636 | STAMCOUNTER StatR3PageReplaceShared; /**< R3: Times a shared page has been replaced by a private one. */
|
---|
2637 | STAMCOUNTER StatR3PageReplaceZero; /**< R3: Times the zero page has been replaced by a private one. */
|
---|
2638 | /// @todo STAMCOUNTER StatR3PageHandyAllocs; /**< R3: The number of times we've executed GMMR3AllocateHandyPages. */
|
---|
2639 |
|
---|
2640 | /* RC only: */
|
---|
2641 | STAMCOUNTER StatRCDynMapCacheMisses; /**< RC: The number of dynamic page mapping cache misses */
|
---|
2642 | STAMCOUNTER StatRCDynMapCacheHits; /**< RC: The number of dynamic page mapping cache hits */
|
---|
2643 | STAMCOUNTER StatRCInvlPgConflict; /**< RC: Number of times PGMInvalidatePage() detected a mapping conflict. */
|
---|
2644 | STAMCOUNTER StatRCInvlPgSyncMonCR3; /**< RC: Number of times PGMInvalidatePage() ran into PGM_SYNC_MONITOR_CR3. */
|
---|
2645 |
|
---|
2646 | STAMCOUNTER StatRZPhysRead;
|
---|
2647 | STAMCOUNTER StatRZPhysReadBytes;
|
---|
2648 | STAMCOUNTER StatRZPhysWrite;
|
---|
2649 | STAMCOUNTER StatRZPhysWriteBytes;
|
---|
2650 | STAMCOUNTER StatR3PhysRead;
|
---|
2651 | STAMCOUNTER StatR3PhysReadBytes;
|
---|
2652 | STAMCOUNTER StatR3PhysWrite;
|
---|
2653 | STAMCOUNTER StatR3PhysWriteBytes;
|
---|
2654 | STAMCOUNTER StatRCPhysRead;
|
---|
2655 | STAMCOUNTER StatRCPhysReadBytes;
|
---|
2656 | STAMCOUNTER StatRCPhysWrite;
|
---|
2657 | STAMCOUNTER StatRCPhysWriteBytes;
|
---|
2658 |
|
---|
2659 | STAMCOUNTER StatRZPhysSimpleRead;
|
---|
2660 | STAMCOUNTER StatRZPhysSimpleReadBytes;
|
---|
2661 | STAMCOUNTER StatRZPhysSimpleWrite;
|
---|
2662 | STAMCOUNTER StatRZPhysSimpleWriteBytes;
|
---|
2663 | STAMCOUNTER StatR3PhysSimpleRead;
|
---|
2664 | STAMCOUNTER StatR3PhysSimpleReadBytes;
|
---|
2665 | STAMCOUNTER StatR3PhysSimpleWrite;
|
---|
2666 | STAMCOUNTER StatR3PhysSimpleWriteBytes;
|
---|
2667 | STAMCOUNTER StatRCPhysSimpleRead;
|
---|
2668 | STAMCOUNTER StatRCPhysSimpleReadBytes;
|
---|
2669 | STAMCOUNTER StatRCPhysSimpleWrite;
|
---|
2670 | STAMCOUNTER StatRCPhysSimpleWriteBytes;
|
---|
2671 |
|
---|
2672 | # ifdef PGMPOOL_WITH_GCPHYS_TRACKING
|
---|
2673 | STAMCOUNTER StatTrackVirgin; /**< The number of first time shadowings. */
|
---|
2674 | STAMCOUNTER StatTrackAliased; /**< The number of times switching to cRef2, i.e. the page is being shadowed by two PTs. */
|
---|
2675 | STAMCOUNTER StatTrackAliasedMany; /**< The number of times we're tracking using cRef2. */
|
---|
2676 | STAMCOUNTER StatTrackAliasedLots; /**< The number of times we're hitting pages which has overflowed cRef2. */
|
---|
2677 | STAMCOUNTER StatTrackOverflows; /**< The number of times the extent list grows to long. */
|
---|
2678 | STAMPROFILE StatTrackDeref; /**< Profiling of SyncPageWorkerTrackDeref (expensive). */
|
---|
2679 | # endif
|
---|
2680 | #endif
|
---|
2681 | } PGM;
|
---|
2682 | #ifndef IN_TSTVMSTRUCTGC /* HACK */
|
---|
2683 | AssertCompileMemberAlignment(PGM, paDynPageMap32BitPTEsGC, 8);
|
---|
2684 | AssertCompileMemberAlignment(PGM, GCPtrMappingFixed, sizeof(RTGCPTR));
|
---|
2685 | AssertCompileMemberAlignment(PGM, HCPhysInterPD, 8);
|
---|
2686 | AssertCompileMemberAlignment(PGM, aHCPhysDynPageMapCache, 8);
|
---|
2687 | AssertCompileMemberAlignment(PGM, CritSect, 8);
|
---|
2688 | AssertCompileMemberAlignment(PGM, ChunkR3Map, 8);
|
---|
2689 | AssertCompileMemberAlignment(PGM, PhysTlbHC, 8);
|
---|
2690 | AssertCompileMemberAlignment(PGM, HCPhysZeroPg, 8);
|
---|
2691 | AssertCompileMemberAlignment(PGM, aHandyPages, 8);
|
---|
2692 | AssertCompileMemberAlignment(PGM, cRelocations, 8);
|
---|
2693 | #endif /* !IN_TSTVMSTRUCTGC */
|
---|
2694 | /** Pointer to the PGM instance data. */
|
---|
2695 | typedef PGM *PPGM;
|
---|
2696 |
|
---|
2697 |
|
---|
2698 | /**
|
---|
2699 | * Converts a PGMCPU pointer into a VM pointer.
|
---|
2700 | * @returns Pointer to the VM structure the PGM is part of.
|
---|
2701 | * @param pPGM Pointer to PGMCPU instance data.
|
---|
2702 | */
|
---|
2703 | #define PGMCPU2VM(pPGM) ( (PVM)((char*)pPGM - pPGM->offVM) )
|
---|
2704 |
|
---|
2705 | /**
|
---|
2706 | * Converts a PGMCPU pointer into a PGM pointer.
|
---|
2707 | * @returns Pointer to the VM structure the PGM is part of.
|
---|
2708 | * @param pPGM Pointer to PGMCPU instance data.
|
---|
2709 | */
|
---|
2710 | #define PGMCPU2PGM(pPGMCpu) ( (PPGM)((char*)pPGMCpu - pPGMCpu->offPGM) )
|
---|
2711 |
|
---|
2712 | /**
|
---|
2713 | * PGMCPU Data (part of VMCPU).
|
---|
2714 | */
|
---|
2715 | typedef struct PGMCPU
|
---|
2716 | {
|
---|
2717 | /** Offset to the VM structure. */
|
---|
2718 | RTINT offVM;
|
---|
2719 | /** Offset to the VMCPU structure. */
|
---|
2720 | RTINT offVCpu;
|
---|
2721 | /** Offset of the PGM structure relative to VMCPU. */
|
---|
2722 | RTINT offPGM;
|
---|
2723 | RTINT uPadding0; /**< structure size alignment. */
|
---|
2724 |
|
---|
2725 | #ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
|
---|
2726 | /** Automatically tracked physical memory mapping set.
|
---|
2727 | * Ring-0 and strict raw-mode builds. */
|
---|
2728 | PGMMAPSET AutoSet;
|
---|
2729 | #endif
|
---|
2730 |
|
---|
2731 | /** A20 gate mask.
|
---|
2732 | * Our current approach to A20 emulation is to let REM do it and don't bother
|
---|
2733 | * anywhere else. The interesting Guests will be operating with it enabled anyway.
|
---|
2734 | * But whould need arrise, we'll subject physical addresses to this mask. */
|
---|
2735 | RTGCPHYS GCPhysA20Mask;
|
---|
2736 | /** A20 gate state - boolean! */
|
---|
2737 | bool fA20Enabled;
|
---|
2738 |
|
---|
2739 | /** What needs syncing (PGM_SYNC_*).
|
---|
2740 | * This is used to queue operations for PGMSyncCR3, PGMInvalidatePage,
|
---|
2741 | * PGMFlushTLB, and PGMR3Load. */
|
---|
2742 | RTUINT fSyncFlags;
|
---|
2743 |
|
---|
2744 | /** The shadow paging mode. */
|
---|
2745 | PGMMODE enmShadowMode;
|
---|
2746 | /** The guest paging mode. */
|
---|
2747 | PGMMODE enmGuestMode;
|
---|
2748 |
|
---|
2749 | /** The current physical address representing in the guest CR3 register. */
|
---|
2750 | RTGCPHYS GCPhysCR3;
|
---|
2751 |
|
---|
2752 | /** @name 32-bit Guest Paging.
|
---|
2753 | * @{ */
|
---|
2754 | /** The guest's page directory, R3 pointer. */
|
---|
2755 | R3PTRTYPE(PX86PD) pGst32BitPdR3;
|
---|
2756 | #ifndef VBOX_WITH_2X_4GB_ADDR_SPACE
|
---|
2757 | /** The guest's page directory, R0 pointer. */
|
---|
2758 | R0PTRTYPE(PX86PD) pGst32BitPdR0;
|
---|
2759 | #endif
|
---|
2760 | /** The guest's page directory, static RC mapping. */
|
---|
2761 | RCPTRTYPE(PX86PD) pGst32BitPdRC;
|
---|
2762 | /** @} */
|
---|
2763 |
|
---|
2764 | /** @name PAE Guest Paging.
|
---|
2765 | * @{ */
|
---|
2766 | /** The guest's page directory pointer table, static RC mapping. */
|
---|
2767 | RCPTRTYPE(PX86PDPT) pGstPaePdptRC;
|
---|
2768 | /** The guest's page directory pointer table, R3 pointer. */
|
---|
2769 | R3PTRTYPE(PX86PDPT) pGstPaePdptR3;
|
---|
2770 | #ifndef VBOX_WITH_2X_4GB_ADDR_SPACE
|
---|
2771 | /** The guest's page directory pointer table, R0 pointer. */
|
---|
2772 | R0PTRTYPE(PX86PDPT) pGstPaePdptR0;
|
---|
2773 | #endif
|
---|
2774 |
|
---|
2775 | /** The guest's page directories, R3 pointers.
|
---|
2776 | * These are individual pointers and don't have to be adjecent.
|
---|
2777 | * These don't have to be up-to-date - use pgmGstGetPaePD() to access them. */
|
---|
2778 | R3PTRTYPE(PX86PDPAE) apGstPaePDsR3[4];
|
---|
2779 | /** The guest's page directories, R0 pointers.
|
---|
2780 | * Same restrictions as apGstPaePDsR3. */
|
---|
2781 | #ifndef VBOX_WITH_2X_4GB_ADDR_SPACE
|
---|
2782 | R0PTRTYPE(PX86PDPAE) apGstPaePDsR0[4];
|
---|
2783 | #endif
|
---|
2784 | /** The guest's page directories, static GC mapping.
|
---|
2785 | * Unlike the R3/R0 array the first entry can be accessed as a 2048 entry PD.
|
---|
2786 | * These don't have to be up-to-date - use pgmGstGetPaePD() to access them. */
|
---|
2787 | RCPTRTYPE(PX86PDPAE) apGstPaePDsRC[4];
|
---|
2788 | /** The physical addresses of the guest page directories (PAE) pointed to by apGstPagePDsHC/GC. */
|
---|
2789 | RTGCPHYS aGCPhysGstPaePDs[4];
|
---|
2790 | /** The physical addresses of the monitored guest page directories (PAE). */
|
---|
2791 | RTGCPHYS aGCPhysGstPaePDsMonitored[4];
|
---|
2792 | /** @} */
|
---|
2793 |
|
---|
2794 | /** @name AMD64 Guest Paging.
|
---|
2795 | * @{ */
|
---|
2796 | /** The guest's page directory pointer table, R3 pointer. */
|
---|
2797 | R3PTRTYPE(PX86PML4) pGstAmd64Pml4R3;
|
---|
2798 | #ifndef VBOX_WITH_2X_4GB_ADDR_SPACE
|
---|
2799 | /** The guest's page directory pointer table, R0 pointer. */
|
---|
2800 | R0PTRTYPE(PX86PML4) pGstAmd64Pml4R0;
|
---|
2801 | #endif
|
---|
2802 | /** @} */
|
---|
2803 |
|
---|
2804 | /** Pointer to the page of the current active CR3 - R3 Ptr. */
|
---|
2805 | R3PTRTYPE(PPGMPOOLPAGE) pShwPageCR3R3;
|
---|
2806 | /** Pointer to the page of the current active CR3 - R0 Ptr. */
|
---|
2807 | R0PTRTYPE(PPGMPOOLPAGE) pShwPageCR3R0;
|
---|
2808 | /** Pointer to the page of the current active CR3 - RC Ptr. */
|
---|
2809 | RCPTRTYPE(PPGMPOOLPAGE) pShwPageCR3RC;
|
---|
2810 | /* The shadow page pool index of the user table as specified during allocation; useful for freeing root pages */
|
---|
2811 | uint32_t iShwUser;
|
---|
2812 | /* The index into the user table (shadowed) as specified during allocation; useful for freeing root pages. */
|
---|
2813 | uint32_t iShwUserTable;
|
---|
2814 | # if HC_ARCH_BITS == 64
|
---|
2815 | RTRCPTR alignment6; /**< structure size alignment. */
|
---|
2816 | # endif
|
---|
2817 | /** @} */
|
---|
2818 |
|
---|
2819 | /** @name Function pointers for Shadow paging.
|
---|
2820 | * @{
|
---|
2821 | */
|
---|
2822 | DECLR3CALLBACKMEMBER(int, pfnR3ShwRelocate,(PVMCPU pVCpu, RTGCPTR offDelta));
|
---|
2823 | DECLR3CALLBACKMEMBER(int, pfnR3ShwExit,(PVMCPU pVCpu));
|
---|
2824 | DECLR3CALLBACKMEMBER(int, pfnR3ShwGetPage,(PVMCPU pVCpu, RTGCPTR GCPtr, uint64_t *pfFlags, PRTHCPHYS pHCPhys));
|
---|
2825 | DECLR3CALLBACKMEMBER(int, pfnR3ShwModifyPage,(PVMCPU pVCpu, RTGCPTR GCPtr, size_t cbPages, uint64_t fFlags, uint64_t fMask));
|
---|
2826 |
|
---|
2827 | DECLRCCALLBACKMEMBER(int, pfnRCShwGetPage,(PVMCPU pVCpu, RTGCPTR GCPtr, uint64_t *pfFlags, PRTHCPHYS pHCPhys));
|
---|
2828 | DECLRCCALLBACKMEMBER(int, pfnRCShwModifyPage,(PVMCPU pVCpu, RTGCPTR GCPtr, size_t cbPages, uint64_t fFlags, uint64_t fMask));
|
---|
2829 |
|
---|
2830 | DECLR0CALLBACKMEMBER(int, pfnR0ShwGetPage,(PVMCPU pVCpu, RTGCPTR GCPtr, uint64_t *pfFlags, PRTHCPHYS pHCPhys));
|
---|
2831 | DECLR0CALLBACKMEMBER(int, pfnR0ShwModifyPage,(PVMCPU pVCpu, RTGCPTR GCPtr, size_t cbPages, uint64_t fFlags, uint64_t fMask));
|
---|
2832 |
|
---|
2833 | /** @} */
|
---|
2834 |
|
---|
2835 | /** @name Function pointers for Guest paging.
|
---|
2836 | * @{
|
---|
2837 | */
|
---|
2838 | DECLR3CALLBACKMEMBER(int, pfnR3GstRelocate,(PVMCPU pVCpu, RTGCPTR offDelta));
|
---|
2839 | DECLR3CALLBACKMEMBER(int, pfnR3GstExit,(PVMCPU pVCpu));
|
---|
2840 | DECLR3CALLBACKMEMBER(int, pfnR3GstGetPage,(PVMCPU pVCpu, RTGCPTR GCPtr, uint64_t *pfFlags, PRTGCPHYS pGCPhys));
|
---|
2841 | DECLR3CALLBACKMEMBER(int, pfnR3GstModifyPage,(PVMCPU pVCpu, RTGCPTR GCPtr, size_t cbPages, uint64_t fFlags, uint64_t fMask));
|
---|
2842 | DECLR3CALLBACKMEMBER(int, pfnR3GstGetPDE,(PVMCPU pVCpu, RTGCPTR GCPtr, PX86PDEPAE pPde));
|
---|
2843 | DECLRCCALLBACKMEMBER(int, pfnRCGstGetPage,(PVMCPU pVCpu, RTGCPTR GCPtr, uint64_t *pfFlags, PRTGCPHYS pGCPhys));
|
---|
2844 | DECLRCCALLBACKMEMBER(int, pfnRCGstModifyPage,(PVMCPU pVCpu, RTGCPTR GCPtr, size_t cbPages, uint64_t fFlags, uint64_t fMask));
|
---|
2845 | DECLRCCALLBACKMEMBER(int, pfnRCGstGetPDE,(PVMCPU pVCpu, RTGCPTR GCPtr, PX86PDEPAE pPde));
|
---|
2846 | #if HC_ARCH_BITS == 64
|
---|
2847 | RTRCPTR alignment3; /**< structure size alignment. */
|
---|
2848 | #endif
|
---|
2849 |
|
---|
2850 | DECLR0CALLBACKMEMBER(int, pfnR0GstGetPage,(PVMCPU pVCpu, RTGCPTR GCPtr, uint64_t *pfFlags, PRTGCPHYS pGCPhys));
|
---|
2851 | DECLR0CALLBACKMEMBER(int, pfnR0GstModifyPage,(PVMCPU pVCpu, RTGCPTR GCPtr, size_t cbPages, uint64_t fFlags, uint64_t fMask));
|
---|
2852 | DECLR0CALLBACKMEMBER(int, pfnR0GstGetPDE,(PVMCPU pVCpu, RTGCPTR GCPtr, PX86PDEPAE pPde));
|
---|
2853 | /** @} */
|
---|
2854 |
|
---|
2855 | /** @name Function pointers for Both Shadow and Guest paging.
|
---|
2856 | * @{
|
---|
2857 | */
|
---|
2858 | DECLR3CALLBACKMEMBER(int, pfnR3BthRelocate,(PVMCPU pVCpu, RTGCPTR offDelta));
|
---|
2859 | /* no pfnR3BthTrap0eHandler */
|
---|
2860 | DECLR3CALLBACKMEMBER(int, pfnR3BthInvalidatePage,(PVMCPU pVCpu, RTGCPTR GCPtrPage));
|
---|
2861 | DECLR3CALLBACKMEMBER(int, pfnR3BthSyncCR3,(PVMCPU pVCpu, uint64_t cr0, uint64_t cr3, uint64_t cr4, bool fGlobal));
|
---|
2862 | DECLR3CALLBACKMEMBER(int, pfnR3BthSyncPage,(PVMCPU pVCpu, X86PDE PdeSrc, RTGCPTR GCPtrPage, unsigned cPages, unsigned uError));
|
---|
2863 | DECLR3CALLBACKMEMBER(int, pfnR3BthPrefetchPage,(PVMCPU pVCpu, RTGCPTR GCPtrPage));
|
---|
2864 | DECLR3CALLBACKMEMBER(int, pfnR3BthVerifyAccessSyncPage,(PVMCPU pVCpu, RTGCPTR GCPtrPage, unsigned fFlags, unsigned uError));
|
---|
2865 | DECLR3CALLBACKMEMBER(unsigned, pfnR3BthAssertCR3,(PVMCPU pVCpu, uint64_t cr3, uint64_t cr4, RTGCPTR GCPtr, RTGCPTR cb));
|
---|
2866 | DECLR3CALLBACKMEMBER(int, pfnR3BthMapCR3,(PVMCPU pVCpu, RTGCPHYS GCPhysCR3));
|
---|
2867 | DECLR3CALLBACKMEMBER(int, pfnR3BthUnmapCR3,(PVMCPU pVCpu));
|
---|
2868 |
|
---|
2869 | DECLR0CALLBACKMEMBER(int, pfnR0BthTrap0eHandler,(PVMCPU pVCpu, RTGCUINT uErr, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault));
|
---|
2870 | DECLR0CALLBACKMEMBER(int, pfnR0BthInvalidatePage,(PVMCPU pVCpu, RTGCPTR GCPtrPage));
|
---|
2871 | DECLR0CALLBACKMEMBER(int, pfnR0BthSyncCR3,(PVMCPU pVCpu, uint64_t cr0, uint64_t cr3, uint64_t cr4, bool fGlobal));
|
---|
2872 | DECLR0CALLBACKMEMBER(int, pfnR0BthSyncPage,(PVMCPU pVCpu, X86PDE PdeSrc, RTGCPTR GCPtrPage, unsigned cPages, unsigned uError));
|
---|
2873 | DECLR0CALLBACKMEMBER(int, pfnR0BthPrefetchPage,(PVMCPU pVCpu, RTGCPTR GCPtrPage));
|
---|
2874 | DECLR0CALLBACKMEMBER(int, pfnR0BthVerifyAccessSyncPage,(PVMCPU pVCpu, RTGCPTR GCPtrPage, unsigned fFlags, unsigned uError));
|
---|
2875 | DECLR0CALLBACKMEMBER(unsigned, pfnR0BthAssertCR3,(PVMCPU pVCpu, uint64_t cr3, uint64_t cr4, RTGCPTR GCPtr, RTGCPTR cb));
|
---|
2876 | DECLR0CALLBACKMEMBER(int, pfnR0BthMapCR3,(PVMCPU pVCpu, RTGCPHYS GCPhysCR3));
|
---|
2877 | DECLR0CALLBACKMEMBER(int, pfnR0BthUnmapCR3,(PVMCPU pVCpu));
|
---|
2878 |
|
---|
2879 | DECLRCCALLBACKMEMBER(int, pfnRCBthTrap0eHandler,(PVMCPU pVCpu, RTGCUINT uErr, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault));
|
---|
2880 | DECLRCCALLBACKMEMBER(int, pfnRCBthInvalidatePage,(PVMCPU pVCpu, RTGCPTR GCPtrPage));
|
---|
2881 | DECLRCCALLBACKMEMBER(int, pfnRCBthSyncCR3,(PVMCPU pVCpu, uint64_t cr0, uint64_t cr3, uint64_t cr4, bool fGlobal));
|
---|
2882 | DECLRCCALLBACKMEMBER(int, pfnRCBthSyncPage,(PVMCPU pVCpu, X86PDE PdeSrc, RTGCPTR GCPtrPage, unsigned cPages, unsigned uError));
|
---|
2883 | DECLRCCALLBACKMEMBER(int, pfnRCBthPrefetchPage,(PVMCPU pVCpu, RTGCPTR GCPtrPage));
|
---|
2884 | DECLRCCALLBACKMEMBER(int, pfnRCBthVerifyAccessSyncPage,(PVMCPU pVCpu, RTGCPTR GCPtrPage, unsigned fFlags, unsigned uError));
|
---|
2885 | DECLRCCALLBACKMEMBER(unsigned, pfnRCBthAssertCR3,(PVMCPU pVCpu, uint64_t cr3, uint64_t cr4, RTGCPTR GCPtr, RTGCPTR cb));
|
---|
2886 | DECLRCCALLBACKMEMBER(int, pfnRCBthMapCR3,(PVMCPU pVCpu, RTGCPHYS GCPhysCR3));
|
---|
2887 | DECLRCCALLBACKMEMBER(int, pfnRCBthUnmapCR3,(PVMCPU pVCpu));
|
---|
2888 | RTRCPTR alignment2; /**< structure size alignment. */
|
---|
2889 | /** @} */
|
---|
2890 |
|
---|
2891 | /** For saving stack space, the disassembler state is allocated here instead of
|
---|
2892 | * on the stack.
|
---|
2893 | * @note The DISCPUSTATE structure is not R3/R0/RZ clean! */
|
---|
2894 | union
|
---|
2895 | {
|
---|
2896 | /** The disassembler scratch space. */
|
---|
2897 | DISCPUSTATE DisState;
|
---|
2898 | /** Padding. */
|
---|
2899 | uint8_t abDisStatePadding[DISCPUSTATE_PADDING_SIZE];
|
---|
2900 | };
|
---|
2901 |
|
---|
2902 | /* Count the number of pgm pool access handler calls. */
|
---|
2903 | uint64_t cPoolAccessHandler;
|
---|
2904 |
|
---|
2905 | /** @name Release Statistics
|
---|
2906 | * @{ */
|
---|
2907 | /** The number of times the guest has switched mode since last reset or statistics reset. */
|
---|
2908 | STAMCOUNTER cGuestModeChanges;
|
---|
2909 | /** @} */
|
---|
2910 |
|
---|
2911 | #ifdef VBOX_WITH_STATISTICS /** @todo move this chunk to the heap. */
|
---|
2912 | /** @name Statistics
|
---|
2913 | * @{ */
|
---|
2914 | /** RC: Which statistic this \#PF should be attributed to. */
|
---|
2915 | RCPTRTYPE(PSTAMPROFILE) pStatTrap0eAttributionRC;
|
---|
2916 | RTRCPTR padding0;
|
---|
2917 | /** R0: Which statistic this \#PF should be attributed to. */
|
---|
2918 | R0PTRTYPE(PSTAMPROFILE) pStatTrap0eAttributionR0;
|
---|
2919 | RTR0PTR padding1;
|
---|
2920 |
|
---|
2921 | /* Common */
|
---|
2922 | STAMCOUNTER StatSyncPtPD[X86_PG_ENTRIES]; /**< SyncPT - PD distribution. */
|
---|
2923 | STAMCOUNTER StatSyncPagePD[X86_PG_ENTRIES]; /**< SyncPage - PD distribution. */
|
---|
2924 |
|
---|
2925 | /* R0 only: */
|
---|
2926 | STAMCOUNTER StatR0DynMapMigrateInvlPg; /**< R0: invlpg in PGMDynMapMigrateAutoSet. */
|
---|
2927 | STAMPROFILE StatR0DynMapGCPageInl; /**< R0: Calls to pgmR0DynMapGCPageInlined. */
|
---|
2928 | STAMCOUNTER StatR0DynMapGCPageInlHits; /**< R0: Hash table lookup hits. */
|
---|
2929 | STAMCOUNTER StatR0DynMapGCPageInlMisses; /**< R0: Misses that falls back to code common with PGMDynMapHCPage. */
|
---|
2930 | STAMCOUNTER StatR0DynMapGCPageInlRamHits; /**< R0: 1st ram range hits. */
|
---|
2931 | STAMCOUNTER StatR0DynMapGCPageInlRamMisses; /**< R0: 1st ram range misses, takes slow path. */
|
---|
2932 | STAMPROFILE StatR0DynMapHCPageInl; /**< R0: Calls to pgmR0DynMapHCPageInlined. */
|
---|
2933 | STAMCOUNTER StatR0DynMapHCPageInlHits; /**< R0: Hash table lookup hits. */
|
---|
2934 | STAMCOUNTER StatR0DynMapHCPageInlMisses; /**< R0: Misses that falls back to code common with PGMDynMapHCPage. */
|
---|
2935 | STAMPROFILE StatR0DynMapHCPage; /**< R0: Calls to PGMDynMapHCPage. */
|
---|
2936 | STAMCOUNTER StatR0DynMapSetOptimize; /**< R0: Calls to pgmDynMapOptimizeAutoSet. */
|
---|
2937 | STAMCOUNTER StatR0DynMapSetSearchFlushes; /**< R0: Set search restorting to subset flushes. */
|
---|
2938 | STAMCOUNTER StatR0DynMapSetSearchHits; /**< R0: Set search hits. */
|
---|
2939 | STAMCOUNTER StatR0DynMapSetSearchMisses; /**< R0: Set search misses. */
|
---|
2940 | STAMCOUNTER StatR0DynMapPage; /**< R0: Calls to pgmR0DynMapPage. */
|
---|
2941 | STAMCOUNTER StatR0DynMapPageHits0; /**< R0: Hits at iPage+0. */
|
---|
2942 | STAMCOUNTER StatR0DynMapPageHits1; /**< R0: Hits at iPage+1. */
|
---|
2943 | STAMCOUNTER StatR0DynMapPageHits2; /**< R0: Hits at iPage+2. */
|
---|
2944 | STAMCOUNTER StatR0DynMapPageInvlPg; /**< R0: invlpg. */
|
---|
2945 | STAMCOUNTER StatR0DynMapPageSlow; /**< R0: Calls to pgmR0DynMapPageSlow. */
|
---|
2946 | STAMCOUNTER StatR0DynMapPageSlowLoopHits; /**< R0: Hits in the pgmR0DynMapPageSlow search loop. */
|
---|
2947 | STAMCOUNTER StatR0DynMapPageSlowLoopMisses; /**< R0: Misses in the pgmR0DynMapPageSlow search loop. */
|
---|
2948 | //STAMCOUNTER StatR0DynMapPageSlowLostHits; /**< R0: Lost hits. */
|
---|
2949 | STAMCOUNTER StatR0DynMapSubsets; /**< R0: Times PGMDynMapPushAutoSubset was called. */
|
---|
2950 | STAMCOUNTER StatR0DynMapPopFlushes; /**< R0: Times PGMDynMapPopAutoSubset flushes the subset. */
|
---|
2951 | STAMCOUNTER aStatR0DynMapSetSize[11]; /**< R0: Set size distribution. */
|
---|
2952 |
|
---|
2953 | /* RZ only: */
|
---|
2954 | STAMPROFILE StatRZTrap0e; /**< RC/R0: PGMTrap0eHandler() profiling. */
|
---|
2955 | STAMPROFILE StatRZTrap0eTimeCheckPageFault;
|
---|
2956 | STAMPROFILE StatRZTrap0eTimeSyncPT;
|
---|
2957 | STAMPROFILE StatRZTrap0eTimeMapping;
|
---|
2958 | STAMPROFILE StatRZTrap0eTimeOutOfSync;
|
---|
2959 | STAMPROFILE StatRZTrap0eTimeHandlers;
|
---|
2960 | STAMPROFILE StatRZTrap0eTime2CSAM; /**< RC/R0: Profiling of the Trap0eHandler body when the cause is CSAM. */
|
---|
2961 | STAMPROFILE StatRZTrap0eTime2DirtyAndAccessed; /**< RC/R0: Profiling of the Trap0eHandler body when the cause is dirty and/or accessed bit emulation. */
|
---|
2962 | STAMPROFILE StatRZTrap0eTime2GuestTrap; /**< RC/R0: Profiling of the Trap0eHandler body when the cause is a guest trap. */
|
---|
2963 | STAMPROFILE StatRZTrap0eTime2HndPhys; /**< RC/R0: Profiling of the Trap0eHandler body when the cause is a physical handler. */
|
---|
2964 | STAMPROFILE StatRZTrap0eTime2HndVirt; /**< RC/R0: Profiling of the Trap0eHandler body when the cause is a virtual handler. */
|
---|
2965 | STAMPROFILE StatRZTrap0eTime2HndUnhandled; /**< RC/R0: Profiling of the Trap0eHandler body when the cause is access outside the monitored areas of a monitored page. */
|
---|
2966 | STAMPROFILE StatRZTrap0eTime2Misc; /**< RC/R0: Profiling of the Trap0eHandler body when the cause is not known. */
|
---|
2967 | STAMPROFILE StatRZTrap0eTime2OutOfSync; /**< RC/R0: Profiling of the Trap0eHandler body when the cause is an out-of-sync page. */
|
---|
2968 | STAMPROFILE StatRZTrap0eTime2OutOfSyncHndPhys; /**< RC/R0: Profiling of the Trap0eHandler body when the cause is an out-of-sync physical handler page. */
|
---|
2969 | STAMPROFILE StatRZTrap0eTime2OutOfSyncHndVirt; /**< RC/R0: Profiling of the Trap0eHandler body when the cause is an out-of-sync virtual handler page. */
|
---|
2970 | STAMPROFILE StatRZTrap0eTime2OutOfSyncHndObs; /**< RC/R0: Profiling of the Trap0eHandler body when the cause is an obsolete handler page. */
|
---|
2971 | STAMPROFILE StatRZTrap0eTime2SyncPT; /**< RC/R0: Profiling of the Trap0eHandler body when the cause is lazy syncing of a PT. */
|
---|
2972 | STAMCOUNTER StatRZTrap0eConflicts; /**< RC/R0: The number of times \#PF was caused by an undetected conflict. */
|
---|
2973 | STAMCOUNTER StatRZTrap0eHandlersMapping; /**< RC/R0: Number of traps due to access handlers in mappings. */
|
---|
2974 | STAMCOUNTER StatRZTrap0eHandlersOutOfSync; /**< RC/R0: Number of out-of-sync handled pages. */
|
---|
2975 | STAMCOUNTER StatRZTrap0eHandlersPhysical; /**< RC/R0: Number of traps due to physical access handlers. */
|
---|
2976 | STAMCOUNTER StatRZTrap0eHandlersVirtual; /**< RC/R0: Number of traps due to virtual access handlers. */
|
---|
2977 | STAMCOUNTER StatRZTrap0eHandlersVirtualByPhys; /**< RC/R0: Number of traps due to virtual access handlers found by physical address. */
|
---|
2978 | STAMCOUNTER StatRZTrap0eHandlersVirtualUnmarked;/**< RC/R0: Number of traps due to virtual access handlers found by virtual address (without proper physical flags). */
|
---|
2979 | STAMCOUNTER StatRZTrap0eHandlersUnhandled; /**< RC/R0: Number of traps due to access outside range of monitored page(s). */
|
---|
2980 | STAMCOUNTER StatRZTrap0eHandlersInvalid; /**< RC/R0: Number of traps due to access to invalid physical memory. */
|
---|
2981 | STAMCOUNTER StatRZTrap0eUSNotPresentRead; /**< RC/R0: #PF err kind */
|
---|
2982 | STAMCOUNTER StatRZTrap0eUSNotPresentWrite; /**< RC/R0: #PF err kind */
|
---|
2983 | STAMCOUNTER StatRZTrap0eUSWrite; /**< RC/R0: #PF err kind */
|
---|
2984 | STAMCOUNTER StatRZTrap0eUSReserved; /**< RC/R0: #PF err kind */
|
---|
2985 | STAMCOUNTER StatRZTrap0eUSNXE; /**< RC/R0: #PF err kind */
|
---|
2986 | STAMCOUNTER StatRZTrap0eUSRead; /**< RC/R0: #PF err kind */
|
---|
2987 | STAMCOUNTER StatRZTrap0eSVNotPresentRead; /**< RC/R0: #PF err kind */
|
---|
2988 | STAMCOUNTER StatRZTrap0eSVNotPresentWrite; /**< RC/R0: #PF err kind */
|
---|
2989 | STAMCOUNTER StatRZTrap0eSVWrite; /**< RC/R0: #PF err kind */
|
---|
2990 | STAMCOUNTER StatRZTrap0eSVReserved; /**< RC/R0: #PF err kind */
|
---|
2991 | STAMCOUNTER StatRZTrap0eSNXE; /**< RC/R0: #PF err kind */
|
---|
2992 | STAMCOUNTER StatRZTrap0eGuestPF; /**< RC/R0: Real guest #PFs. */
|
---|
2993 | STAMCOUNTER StatRZTrap0eGuestPFUnh; /**< RC/R0: Real guest #PF ending up at the end of the #PF code. */
|
---|
2994 | STAMCOUNTER StatRZTrap0eGuestPFMapping; /**< RC/R0: Real guest #PF to HMA or other mapping. */
|
---|
2995 | STAMCOUNTER StatRZTrap0eWPEmulInRZ; /**< RC/R0: WP=0 virtualization trap, handled. */
|
---|
2996 | STAMCOUNTER StatRZTrap0eWPEmulToR3; /**< RC/R0: WP=0 virtualization trap, chickened out. */
|
---|
2997 | STAMCOUNTER StatRZTrap0ePD[X86_PG_ENTRIES]; /**< RC/R0: PD distribution of the #PFs. */
|
---|
2998 | STAMCOUNTER StatRZGuestCR3WriteHandled; /**< RC/R0: The number of times WriteHandlerCR3() was successfully called. */
|
---|
2999 | STAMCOUNTER StatRZGuestCR3WriteUnhandled; /**< RC/R0: The number of times WriteHandlerCR3() was called and we had to fall back to the recompiler. */
|
---|
3000 | STAMCOUNTER StatRZGuestCR3WriteConflict; /**< RC/R0: The number of times WriteHandlerCR3() was called and a conflict was detected. */
|
---|
3001 | STAMCOUNTER StatRZGuestROMWriteHandled; /**< RC/R0: The number of times pgmPhysRomWriteHandler() was successfully called. */
|
---|
3002 | STAMCOUNTER StatRZGuestROMWriteUnhandled; /**< RC/R0: The number of times pgmPhysRomWriteHandler() was called and we had to fall back to the recompiler */
|
---|
3003 |
|
---|
3004 | /* HC - R3 and (maybe) R0: */
|
---|
3005 |
|
---|
3006 | /* RZ & R3: */
|
---|
3007 | STAMPROFILE StatRZSyncCR3; /**< RC/R0: PGMSyncCR3() profiling. */
|
---|
3008 | STAMPROFILE StatRZSyncCR3Handlers; /**< RC/R0: Profiling of the PGMSyncCR3() update handler section. */
|
---|
3009 | STAMCOUNTER StatRZSyncCR3Global; /**< RC/R0: The number of global CR3 syncs. */
|
---|
3010 | STAMCOUNTER StatRZSyncCR3NotGlobal; /**< RC/R0: The number of non-global CR3 syncs. */
|
---|
3011 | STAMCOUNTER StatRZSyncCR3DstCacheHit; /**< RC/R0: The number of times we got some kind of cache hit on a page table. */
|
---|
3012 | STAMCOUNTER StatRZSyncCR3DstFreed; /**< RC/R0: The number of times we've had to free a shadow entry. */
|
---|
3013 | STAMCOUNTER StatRZSyncCR3DstFreedSrcNP; /**< RC/R0: The number of times we've had to free a shadow entry for which the source entry was not present. */
|
---|
3014 | STAMCOUNTER StatRZSyncCR3DstNotPresent; /**< RC/R0: The number of times we've encountered a not present shadow entry for a present guest entry. */
|
---|
3015 | STAMCOUNTER StatRZSyncCR3DstSkippedGlobalPD; /**< RC/R0: The number of times a global page directory wasn't flushed. */
|
---|
3016 | STAMCOUNTER StatRZSyncCR3DstSkippedGlobalPT; /**< RC/R0: The number of times a page table with only global entries wasn't flushed. */
|
---|
3017 | STAMPROFILE StatRZSyncPT; /**< RC/R0: PGMSyncPT() profiling. */
|
---|
3018 | STAMCOUNTER StatRZSyncPTFailed; /**< RC/R0: The number of times PGMSyncPT() failed. */
|
---|
3019 | STAMCOUNTER StatRZSyncPT4K; /**< RC/R0: Number of 4KB syncs. */
|
---|
3020 | STAMCOUNTER StatRZSyncPT4M; /**< RC/R0: Number of 4MB syncs. */
|
---|
3021 | STAMCOUNTER StatRZSyncPagePDNAs; /**< RC/R0: The number of time we've marked a PD not present from SyncPage to virtualize the accessed bit. */
|
---|
3022 | STAMCOUNTER StatRZSyncPagePDOutOfSync; /**< RC/R0: The number of time we've encountered an out-of-sync PD in SyncPage. */
|
---|
3023 | STAMCOUNTER StatRZAccessedPage; /**< RC/R0: The number of pages marked not present for accessed bit emulation. */
|
---|
3024 | STAMPROFILE StatRZDirtyBitTracking; /**< RC/R0: Profiling the dirty bit tracking in CheckPageFault().. */
|
---|
3025 | STAMCOUNTER StatRZDirtyPage; /**< RC/R0: The number of pages marked read-only for dirty bit tracking. */
|
---|
3026 | STAMCOUNTER StatRZDirtyPageBig; /**< RC/R0: The number of pages marked read-only for dirty bit tracking. */
|
---|
3027 | STAMCOUNTER StatRZDirtyPageSkipped; /**< RC/R0: The number of pages already dirty or readonly. */
|
---|
3028 | STAMCOUNTER StatRZDirtyPageTrap; /**< RC/R0: The number of traps generated for dirty bit tracking. */
|
---|
3029 | STAMCOUNTER StatRZDirtyPageStale; /**< RC/R0: The number of traps generated for dirty bit tracking. (stale tlb entries) */
|
---|
3030 | STAMCOUNTER StatRZDirtyTrackRealPF; /**< RC/R0: The number of real pages faults during dirty bit tracking. */
|
---|
3031 | STAMCOUNTER StatRZDirtiedPage; /**< RC/R0: The number of pages marked dirty because of write accesses. */
|
---|
3032 | STAMCOUNTER StatRZPageAlreadyDirty; /**< RC/R0: The number of pages already marked dirty because of write accesses. */
|
---|
3033 | STAMPROFILE StatRZInvalidatePage; /**< RC/R0: PGMInvalidatePage() profiling. */
|
---|
3034 | STAMCOUNTER StatRZInvalidatePage4KBPages; /**< RC/R0: The number of times PGMInvalidatePage() was called for a 4KB page. */
|
---|
3035 | STAMCOUNTER StatRZInvalidatePage4MBPages; /**< RC/R0: The number of times PGMInvalidatePage() was called for a 4MB page. */
|
---|
3036 | STAMCOUNTER StatRZInvalidatePage4MBPagesSkip; /**< RC/R0: The number of times PGMInvalidatePage() skipped a 4MB page. */
|
---|
3037 | STAMCOUNTER StatRZInvalidatePagePDMappings; /**< RC/R0: The number of times PGMInvalidatePage() was called for a page directory containing mappings (no conflict). */
|
---|
3038 | STAMCOUNTER StatRZInvalidatePagePDNAs; /**< RC/R0: The number of times PGMInvalidatePage() was called for a not accessed page directory. */
|
---|
3039 | STAMCOUNTER StatRZInvalidatePagePDNPs; /**< RC/R0: The number of times PGMInvalidatePage() was called for a not present page directory. */
|
---|
3040 | STAMCOUNTER StatRZInvalidatePagePDOutOfSync; /**< RC/R0: The number of times PGMInvalidatePage() was called for an out of sync page directory. */
|
---|
3041 | STAMCOUNTER StatRZInvalidatePageSkipped; /**< RC/R0: The number of times PGMInvalidatePage() was skipped due to not present shw or pending pending SyncCR3. */
|
---|
3042 | STAMCOUNTER StatRZPageOutOfSyncUser; /**< RC/R0: The number of times user page is out of sync was detected in #PF or VerifyAccessSyncPage. */
|
---|
3043 | STAMCOUNTER StatRZPageOutOfSyncSupervisor; /**< RC/R0: The number of times supervisor page is out of sync was detected in in #PF or VerifyAccessSyncPage. */
|
---|
3044 | STAMCOUNTER StatRZPageOutOfSyncUserWrite; /**< RC/R0: The number of times user page is out of sync was detected in #PF. */
|
---|
3045 | STAMCOUNTER StatRZPageOutOfSyncSupervisorWrite; /**< RC/R0: The number of times supervisor page is out of sync was detected in in #PF. */
|
---|
3046 | STAMPROFILE StatRZPrefetch; /**< RC/R0: PGMPrefetchPage. */
|
---|
3047 | STAMPROFILE StatRZFlushTLB; /**< RC/R0: Profiling of the PGMFlushTLB() body. */
|
---|
3048 | STAMCOUNTER StatRZFlushTLBNewCR3; /**< RC/R0: The number of times PGMFlushTLB was called with a new CR3, non-global. (switch) */
|
---|
3049 | STAMCOUNTER StatRZFlushTLBNewCR3Global; /**< RC/R0: The number of times PGMFlushTLB was called with a new CR3, global. (switch) */
|
---|
3050 | STAMCOUNTER StatRZFlushTLBSameCR3; /**< RC/R0: The number of times PGMFlushTLB was called with the same CR3, non-global. (flush) */
|
---|
3051 | STAMCOUNTER StatRZFlushTLBSameCR3Global; /**< RC/R0: The number of times PGMFlushTLB was called with the same CR3, global. (flush) */
|
---|
3052 | STAMPROFILE StatRZGstModifyPage; /**< RC/R0: Profiling of the PGMGstModifyPage() body */
|
---|
3053 |
|
---|
3054 | STAMPROFILE StatR3SyncCR3; /**< R3: PGMSyncCR3() profiling. */
|
---|
3055 | STAMPROFILE StatR3SyncCR3Handlers; /**< R3: Profiling of the PGMSyncCR3() update handler section. */
|
---|
3056 | STAMCOUNTER StatR3SyncCR3Global; /**< R3: The number of global CR3 syncs. */
|
---|
3057 | STAMCOUNTER StatR3SyncCR3NotGlobal; /**< R3: The number of non-global CR3 syncs. */
|
---|
3058 | STAMCOUNTER StatR3SyncCR3DstFreed; /**< R3: The number of times we've had to free a shadow entry. */
|
---|
3059 | STAMCOUNTER StatR3SyncCR3DstFreedSrcNP; /**< R3: The number of times we've had to free a shadow entry for which the source entry was not present. */
|
---|
3060 | STAMCOUNTER StatR3SyncCR3DstNotPresent; /**< R3: The number of times we've encountered a not present shadow entry for a present guest entry. */
|
---|
3061 | STAMCOUNTER StatR3SyncCR3DstSkippedGlobalPD; /**< R3: The number of times a global page directory wasn't flushed. */
|
---|
3062 | STAMCOUNTER StatR3SyncCR3DstSkippedGlobalPT; /**< R3: The number of times a page table with only global entries wasn't flushed. */
|
---|
3063 | STAMCOUNTER StatR3SyncCR3DstCacheHit; /**< R3: The number of times we got some kind of cache hit on a page table. */
|
---|
3064 | STAMPROFILE StatR3SyncPT; /**< R3: PGMSyncPT() profiling. */
|
---|
3065 | STAMCOUNTER StatR3SyncPTFailed; /**< R3: The number of times PGMSyncPT() failed. */
|
---|
3066 | STAMCOUNTER StatR3SyncPT4K; /**< R3: Number of 4KB syncs. */
|
---|
3067 | STAMCOUNTER StatR3SyncPT4M; /**< R3: Number of 4MB syncs. */
|
---|
3068 | STAMCOUNTER StatR3SyncPagePDNAs; /**< R3: The number of time we've marked a PD not present from SyncPage to virtualize the accessed bit. */
|
---|
3069 | STAMCOUNTER StatR3SyncPagePDOutOfSync; /**< R3: The number of time we've encountered an out-of-sync PD in SyncPage. */
|
---|
3070 | STAMCOUNTER StatR3AccessedPage; /**< R3: The number of pages marked not present for accessed bit emulation. */
|
---|
3071 | STAMPROFILE StatR3DirtyBitTracking; /**< R3: Profiling the dirty bit tracking in CheckPageFault(). */
|
---|
3072 | STAMCOUNTER StatR3DirtyPage; /**< R3: The number of pages marked read-only for dirty bit tracking. */
|
---|
3073 | STAMCOUNTER StatR3DirtyPageBig; /**< R3: The number of pages marked read-only for dirty bit tracking. */
|
---|
3074 | STAMCOUNTER StatR3DirtyPageSkipped; /**< R3: The number of pages already dirty or readonly. */
|
---|
3075 | STAMCOUNTER StatR3DirtyPageTrap; /**< R3: The number of traps generated for dirty bit tracking. */
|
---|
3076 | STAMCOUNTER StatR3DirtyTrackRealPF; /**< R3: The number of real pages faults during dirty bit tracking. */
|
---|
3077 | STAMCOUNTER StatR3DirtiedPage; /**< R3: The number of pages marked dirty because of write accesses. */
|
---|
3078 | STAMCOUNTER StatR3PageAlreadyDirty; /**< R3: The number of pages already marked dirty because of write accesses. */
|
---|
3079 | STAMPROFILE StatR3InvalidatePage; /**< R3: PGMInvalidatePage() profiling. */
|
---|
3080 | STAMCOUNTER StatR3InvalidatePage4KBPages; /**< R3: The number of times PGMInvalidatePage() was called for a 4KB page. */
|
---|
3081 | STAMCOUNTER StatR3InvalidatePage4MBPages; /**< R3: The number of times PGMInvalidatePage() was called for a 4MB page. */
|
---|
3082 | STAMCOUNTER StatR3InvalidatePage4MBPagesSkip; /**< R3: The number of times PGMInvalidatePage() skipped a 4MB page. */
|
---|
3083 | STAMCOUNTER StatR3InvalidatePagePDNAs; /**< R3: The number of times PGMInvalidatePage() was called for a not accessed page directory. */
|
---|
3084 | STAMCOUNTER StatR3InvalidatePagePDNPs; /**< R3: The number of times PGMInvalidatePage() was called for a not present page directory. */
|
---|
3085 | STAMCOUNTER StatR3InvalidatePagePDMappings; /**< R3: The number of times PGMInvalidatePage() was called for a page directory containing mappings (no conflict). */
|
---|
3086 | STAMCOUNTER StatR3InvalidatePagePDOutOfSync; /**< R3: The number of times PGMInvalidatePage() was called for an out of sync page directory. */
|
---|
3087 | STAMCOUNTER StatR3InvalidatePageSkipped; /**< R3: The number of times PGMInvalidatePage() was skipped due to not present shw or pending pending SyncCR3. */
|
---|
3088 | STAMCOUNTER StatR3PageOutOfSyncUser; /**< R3: The number of times user page is out of sync was detected in #PF or VerifyAccessSyncPage. */
|
---|
3089 | STAMCOUNTER StatR3PageOutOfSyncSupervisor; /**< R3: The number of times supervisor page is out of sync was detected in in #PF or VerifyAccessSyncPage. */
|
---|
3090 | STAMCOUNTER StatR3PageOutOfSyncUserWrite; /**< R3: The number of times user page is out of sync was detected in #PF. */
|
---|
3091 | STAMCOUNTER StatR3PageOutOfSyncSupervisorWrite; /**< R3: The number of times supervisor page is out of sync was detected in in #PF. */
|
---|
3092 | STAMPROFILE StatR3Prefetch; /**< R3: PGMPrefetchPage. */
|
---|
3093 | STAMPROFILE StatR3FlushTLB; /**< R3: Profiling of the PGMFlushTLB() body. */
|
---|
3094 | STAMCOUNTER StatR3FlushTLBNewCR3; /**< R3: The number of times PGMFlushTLB was called with a new CR3, non-global. (switch) */
|
---|
3095 | STAMCOUNTER StatR3FlushTLBNewCR3Global; /**< R3: The number of times PGMFlushTLB was called with a new CR3, global. (switch) */
|
---|
3096 | STAMCOUNTER StatR3FlushTLBSameCR3; /**< R3: The number of times PGMFlushTLB was called with the same CR3, non-global. (flush) */
|
---|
3097 | STAMCOUNTER StatR3FlushTLBSameCR3Global; /**< R3: The number of times PGMFlushTLB was called with the same CR3, global. (flush) */
|
---|
3098 | STAMPROFILE StatR3GstModifyPage; /**< R3: Profiling of the PGMGstModifyPage() body */
|
---|
3099 | /** @} */
|
---|
3100 | #endif /* VBOX_WITH_STATISTICS */
|
---|
3101 | } PGMCPU;
|
---|
3102 | /** Pointer to the per-cpu PGM data. */
|
---|
3103 | typedef PGMCPU *PPGMCPU;
|
---|
3104 |
|
---|
3105 |
|
---|
3106 | /** @name PGM::fSyncFlags Flags
|
---|
3107 | * @{
|
---|
3108 | */
|
---|
3109 | /** Updates the virtual access handler state bit in PGMPAGE. */
|
---|
3110 | #define PGM_SYNC_UPDATE_PAGE_BIT_VIRTUAL RT_BIT(0)
|
---|
3111 | /** Always sync CR3. */
|
---|
3112 | #define PGM_SYNC_ALWAYS RT_BIT(1)
|
---|
3113 | /** Check monitoring on next CR3 (re)load and invalidate page.
|
---|
3114 | * @todo This is obsolete now. Remove after 2.2.0 is branched off. */
|
---|
3115 | #define PGM_SYNC_MONITOR_CR3 RT_BIT(2)
|
---|
3116 | /** Check guest mapping in SyncCR3. */
|
---|
3117 | #define PGM_SYNC_MAP_CR3 RT_BIT(3)
|
---|
3118 | /** Clear the page pool (a light weight flush). */
|
---|
3119 | #define PGM_SYNC_CLEAR_PGM_POOL_BIT 8
|
---|
3120 | #define PGM_SYNC_CLEAR_PGM_POOL RT_BIT(PGM_SYNC_CLEAR_PGM_POOL_BIT)
|
---|
3121 | /** @} */
|
---|
3122 |
|
---|
3123 |
|
---|
3124 | RT_C_DECLS_BEGIN
|
---|
3125 |
|
---|
3126 | int pgmLock(PVM pVM);
|
---|
3127 | void pgmUnlock(PVM pVM);
|
---|
3128 |
|
---|
3129 | int pgmR3SyncPTResolveConflict(PVM pVM, PPGMMAPPING pMapping, PX86PD pPDSrc, RTGCPTR GCPtrOldMapping);
|
---|
3130 | int pgmR3SyncPTResolveConflictPAE(PVM pVM, PPGMMAPPING pMapping, RTGCPTR GCPtrOldMapping);
|
---|
3131 | PPGMMAPPING pgmGetMapping(PVM pVM, RTGCPTR GCPtr);
|
---|
3132 | void pgmR3MapRelocate(PVM pVM, PPGMMAPPING pMapping, RTGCPTR GCPtrOldMapping, RTGCPTR GCPtrNewMapping);
|
---|
3133 | DECLCALLBACK(void) pgmR3MapInfo(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs);
|
---|
3134 |
|
---|
3135 | void pgmR3HandlerPhysicalUpdateAll(PVM pVM);
|
---|
3136 | bool pgmHandlerPhysicalIsAll(PVM pVM, RTGCPHYS GCPhys);
|
---|
3137 | void pgmHandlerPhysicalResetAliasedPage(PVM pVM, PPGMPAGE pPage, RTGCPHYS GCPhysPage);
|
---|
3138 | int pgmHandlerVirtualFindByPhysAddr(PVM pVM, RTGCPHYS GCPhys, PPGMVIRTHANDLER *ppVirt, unsigned *piPage);
|
---|
3139 | DECLCALLBACK(int) pgmHandlerVirtualResetOne(PAVLROGCPTRNODECORE pNode, void *pvUser);
|
---|
3140 | #if defined(VBOX_STRICT) || defined(LOG_ENABLED)
|
---|
3141 | void pgmHandlerVirtualDumpPhysPages(PVM pVM);
|
---|
3142 | #else
|
---|
3143 | # define pgmHandlerVirtualDumpPhysPages(a) do { } while (0)
|
---|
3144 | #endif
|
---|
3145 | DECLCALLBACK(void) pgmR3InfoHandlers(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs);
|
---|
3146 | int pgmR3InitSavedState(PVM pVM, uint64_t cbRam);
|
---|
3147 |
|
---|
3148 | int pgmPhysAllocPage(PVM pVM, PPGMPAGE pPage, RTGCPHYS GCPhys);
|
---|
3149 | int pgmPhysPageLoadIntoTlb(PPGM pPGM, RTGCPHYS GCPhys);
|
---|
3150 | int pgmPhysPageLoadIntoTlbWithPage(PPGM pPGM, PPGMPAGE pPage, RTGCPHYS GCPhys);
|
---|
3151 | int pgmPhysPageMakeWritable(PVM pVM, PPGMPAGE pPage, RTGCPHYS GCPhys);
|
---|
3152 | int pgmPhysPageMakeWritableUnlocked(PVM pVM, PPGMPAGE pPage, RTGCPHYS GCPhys);
|
---|
3153 | int pgmPhysPageMap(PVM pVM, PPGMPAGE pPage, RTGCPHYS GCPhys, PPPGMPAGEMAP ppMap, void **ppv);
|
---|
3154 | int pgmPhysPageMapByPageID(PVM pVM, uint32_t idPage, RTHCPHYS HCPhys, void **ppv);
|
---|
3155 | int pgmPhysGCPhys2CCPtrInternal(PVM pVM, PPGMPAGE pPage, RTGCPHYS GCPhys, void **ppv);
|
---|
3156 | int pgmPhysGCPhys2CCPtrInternalReadOnly(PVM pVM, PPGMPAGE pPage, RTGCPHYS GCPhys, const void **ppv);
|
---|
3157 | VMMDECL(int) pgmPhysRomWriteHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPHYS GCPhysFault, void *pvUser);
|
---|
3158 | #ifdef IN_RING3
|
---|
3159 | void pgmR3PhysRelinkRamRanges(PVM pVM);
|
---|
3160 | int pgmR3PhysRamPreAllocate(PVM pVM);
|
---|
3161 | int pgmR3PhysRamReset(PVM pVM);
|
---|
3162 | int pgmR3PhysRomReset(PVM pVM);
|
---|
3163 | int pgmR3PhysChunkMap(PVM pVM, uint32_t idChunk, PPPGMCHUNKR3MAP ppChunk);
|
---|
3164 |
|
---|
3165 | int pgmR3PoolInit(PVM pVM);
|
---|
3166 | void pgmR3PoolRelocate(PVM pVM);
|
---|
3167 | void pgmR3PoolReset(PVM pVM);
|
---|
3168 | void pgmR3PoolClearAll(PVM pVM);
|
---|
3169 |
|
---|
3170 | #endif /* IN_RING3 */
|
---|
3171 | #ifdef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
|
---|
3172 | int pgmR0DynMapHCPageCommon(PVM pVM, PPGMMAPSET pSet, RTHCPHYS HCPhys, void **ppv);
|
---|
3173 | #endif
|
---|
3174 | int pgmPoolAllocEx(PVM pVM, RTGCPHYS GCPhys, PGMPOOLKIND enmKind, PGMPOOLACCESS enmAccess, uint16_t iUser, uint32_t iUserTable, PPPGMPOOLPAGE ppPage, bool fLockPage = false);
|
---|
3175 |
|
---|
3176 | DECLINLINE(int) pgmPoolAlloc(PVM pVM, RTGCPHYS GCPhys, PGMPOOLKIND enmKind, uint16_t iUser, uint32_t iUserTable, PPPGMPOOLPAGE ppPage, bool fLockPage = false)
|
---|
3177 | {
|
---|
3178 | return pgmPoolAllocEx(pVM, GCPhys, enmKind, PGMPOOLACCESS_DONTCARE, iUser, iUserTable, ppPage, fLockPage);
|
---|
3179 | }
|
---|
3180 |
|
---|
3181 | void pgmPoolFree(PVM pVM, RTHCPHYS HCPhys, uint16_t iUser, uint32_t iUserTable);
|
---|
3182 | void pgmPoolFreeByPage(PPGMPOOL pPool, PPGMPOOLPAGE pPage, uint16_t iUser, uint32_t iUserTable);
|
---|
3183 | int pgmPoolFlushPage(PPGMPOOL pPool, PPGMPOOLPAGE pPage);
|
---|
3184 | void pgmPoolFlushPageByGCPhys(PVM pVM, RTGCPHYS GCPhys);
|
---|
3185 | PPGMPOOLPAGE pgmPoolGetPage(PPGMPOOL pPool, RTHCPHYS HCPhys);
|
---|
3186 | int pgmPoolSyncCR3(PVMCPU pVCpu);
|
---|
3187 | bool pgmPoolIsDirtyPage(PVM pVM, RTGCPHYS GCPhys);
|
---|
3188 | int pgmPoolTrackUpdateGCPhys(PVM pVM, PPGMPAGE pPhysPage, bool fFlushPTEs, bool *pfFlushTLBs);
|
---|
3189 | DECLINLINE(int) pgmPoolTrackFlushGCPhys(PVM pVM, PPGMPAGE pPhysPage, bool *pfFlushTLBs)
|
---|
3190 | {
|
---|
3191 | return pgmPoolTrackUpdateGCPhys(pVM, pPhysPage, true /* flush PTEs */, pfFlushTLBs);
|
---|
3192 | }
|
---|
3193 |
|
---|
3194 | uint16_t pgmPoolTrackPhysExtAddref(PVM pVM, uint16_t u16, uint16_t iShwPT);
|
---|
3195 | void pgmPoolTrackPhysExtDerefGCPhys(PPGMPOOL pPool, PPGMPOOLPAGE pPoolPage, PPGMPAGE pPhysPage);
|
---|
3196 | void pgmPoolTracDerefGCPhysHint(PPGMPOOL pPool, PPGMPOOLPAGE pPage, RTHCPHYS HCPhys, RTGCPHYS GCPhysHint);
|
---|
3197 | #ifdef PGMPOOL_WITH_MONITORING
|
---|
3198 | void pgmPoolMonitorChainChanging(PVMCPU pVCpu, PPGMPOOL pPool, PPGMPOOLPAGE pPage, RTGCPHYS GCPhysFault, CTXTYPE(RTGCPTR, RTHCPTR, RTGCPTR) pvAddress, PDISCPUSTATE pCpu);
|
---|
3199 | int pgmPoolMonitorChainFlush(PPGMPOOL pPool, PPGMPOOLPAGE pPage);
|
---|
3200 | void pgmPoolMonitorModifiedInsert(PPGMPOOL pPool, PPGMPOOLPAGE pPage);
|
---|
3201 | #endif
|
---|
3202 |
|
---|
3203 | void pgmPoolAddDirtyPage(PVM pVM, PPGMPOOL pPool, PPGMPOOLPAGE pPage);
|
---|
3204 | void pgmPoolResetDirtyPages(PVM pVM);
|
---|
3205 |
|
---|
3206 | int pgmR3ExitShadowModeBeforePoolFlush(PVM pVM, PVMCPU pVCpu);
|
---|
3207 | int pgmR3ReEnterShadowModeAfterPoolFlush(PVM pVM, PVMCPU pVCpu);
|
---|
3208 |
|
---|
3209 | void pgmMapSetShadowPDEs(PVM pVM, PPGMMAPPING pMap, unsigned iNewPDE);
|
---|
3210 | void pgmMapClearShadowPDEs(PVM pVM, PPGMPOOLPAGE pShwPageCR3, PPGMMAPPING pMap, unsigned iOldPDE, bool fDeactivateCR3);
|
---|
3211 | int pgmMapActivateCR3(PVM pVM, PPGMPOOLPAGE pShwPageCR3);
|
---|
3212 | int pgmMapDeactivateCR3(PVM pVM, PPGMPOOLPAGE pShwPageCR3);
|
---|
3213 |
|
---|
3214 | int pgmShwSyncPaePDPtr(PVMCPU pVCpu, RTGCPTR GCPtr, PX86PDPE pGstPdpe, PX86PDPAE *ppPD);
|
---|
3215 | #ifndef IN_RC
|
---|
3216 | int pgmShwSyncLongModePDPtr(PVMCPU pVCpu, RTGCPTR64 GCPtr, PX86PML4E pGstPml4e, PX86PDPE pGstPdpe, PX86PDPAE *ppPD);
|
---|
3217 | #endif
|
---|
3218 | int pgmShwGetEPTPDPtr(PVMCPU pVCpu, RTGCPTR64 GCPtr, PEPTPDPT *ppPdpt, PEPTPD *ppPD);
|
---|
3219 |
|
---|
3220 | PX86PD pgmGstLazyMap32BitPD(PPGMCPU pPGM);
|
---|
3221 | PX86PDPT pgmGstLazyMapPaePDPT(PPGMCPU pPGM);
|
---|
3222 | PX86PDPAE pgmGstLazyMapPaePD(PPGMCPU pPGM, uint32_t iPdpt);
|
---|
3223 | PX86PML4 pgmGstLazyMapPml4(PPGMCPU pPGM);
|
---|
3224 |
|
---|
3225 | RT_C_DECLS_END
|
---|
3226 |
|
---|
3227 |
|
---|
3228 | /**
|
---|
3229 | * Gets the PGMRAMRANGE structure for a guest page.
|
---|
3230 | *
|
---|
3231 | * @returns Pointer to the RAM range on success.
|
---|
3232 | * @returns NULL on a VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS condition.
|
---|
3233 | *
|
---|
3234 | * @param pPGM PGM handle.
|
---|
3235 | * @param GCPhys The GC physical address.
|
---|
3236 | */
|
---|
3237 | DECLINLINE(PPGMRAMRANGE) pgmPhysGetRange(PPGM pPGM, RTGCPHYS GCPhys)
|
---|
3238 | {
|
---|
3239 | /*
|
---|
3240 | * Optimize for the first range.
|
---|
3241 | */
|
---|
3242 | PPGMRAMRANGE pRam = pPGM->CTX_SUFF(pRamRanges);
|
---|
3243 | RTGCPHYS off = GCPhys - pRam->GCPhys;
|
---|
3244 | if (RT_UNLIKELY(off >= pRam->cb))
|
---|
3245 | {
|
---|
3246 | do
|
---|
3247 | {
|
---|
3248 | pRam = pRam->CTX_SUFF(pNext);
|
---|
3249 | if (RT_UNLIKELY(!pRam))
|
---|
3250 | break;
|
---|
3251 | off = GCPhys - pRam->GCPhys;
|
---|
3252 | } while (off >= pRam->cb);
|
---|
3253 | }
|
---|
3254 | return pRam;
|
---|
3255 | }
|
---|
3256 |
|
---|
3257 |
|
---|
3258 | /**
|
---|
3259 | * Gets the PGMPAGE structure for a guest page.
|
---|
3260 | *
|
---|
3261 | * @returns Pointer to the page on success.
|
---|
3262 | * @returns NULL on a VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS condition.
|
---|
3263 | *
|
---|
3264 | * @param pPGM PGM handle.
|
---|
3265 | * @param GCPhys The GC physical address.
|
---|
3266 | */
|
---|
3267 | DECLINLINE(PPGMPAGE) pgmPhysGetPage(PPGM pPGM, RTGCPHYS GCPhys)
|
---|
3268 | {
|
---|
3269 | /*
|
---|
3270 | * Optimize for the first range.
|
---|
3271 | */
|
---|
3272 | PPGMRAMRANGE pRam = pPGM->CTX_SUFF(pRamRanges);
|
---|
3273 | RTGCPHYS off = GCPhys - pRam->GCPhys;
|
---|
3274 | if (RT_UNLIKELY(off >= pRam->cb))
|
---|
3275 | {
|
---|
3276 | do
|
---|
3277 | {
|
---|
3278 | pRam = pRam->CTX_SUFF(pNext);
|
---|
3279 | if (RT_UNLIKELY(!pRam))
|
---|
3280 | return NULL;
|
---|
3281 | off = GCPhys - pRam->GCPhys;
|
---|
3282 | } while (off >= pRam->cb);
|
---|
3283 | }
|
---|
3284 | return &pRam->aPages[off >> PAGE_SHIFT];
|
---|
3285 | }
|
---|
3286 |
|
---|
3287 |
|
---|
3288 | /**
|
---|
3289 | * Gets the PGMPAGE structure for a guest page.
|
---|
3290 | *
|
---|
3291 | * Old Phys code: Will make sure the page is present.
|
---|
3292 | *
|
---|
3293 | * @returns VBox status code.
|
---|
3294 | * @retval VINF_SUCCESS and a valid *ppPage on success.
|
---|
3295 | * @retval VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS if the address isn't valid.
|
---|
3296 | *
|
---|
3297 | * @param pPGM PGM handle.
|
---|
3298 | * @param GCPhys The GC physical address.
|
---|
3299 | * @param ppPage Where to store the page pointer on success.
|
---|
3300 | */
|
---|
3301 | DECLINLINE(int) pgmPhysGetPageEx(PPGM pPGM, RTGCPHYS GCPhys, PPPGMPAGE ppPage)
|
---|
3302 | {
|
---|
3303 | /*
|
---|
3304 | * Optimize for the first range.
|
---|
3305 | */
|
---|
3306 | PPGMRAMRANGE pRam = pPGM->CTX_SUFF(pRamRanges);
|
---|
3307 | RTGCPHYS off = GCPhys - pRam->GCPhys;
|
---|
3308 | if (RT_UNLIKELY(off >= pRam->cb))
|
---|
3309 | {
|
---|
3310 | do
|
---|
3311 | {
|
---|
3312 | pRam = pRam->CTX_SUFF(pNext);
|
---|
3313 | if (RT_UNLIKELY(!pRam))
|
---|
3314 | {
|
---|
3315 | *ppPage = NULL; /* avoid incorrect and very annoying GCC warnings */
|
---|
3316 | return VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS;
|
---|
3317 | }
|
---|
3318 | off = GCPhys - pRam->GCPhys;
|
---|
3319 | } while (off >= pRam->cb);
|
---|
3320 | }
|
---|
3321 | *ppPage = &pRam->aPages[off >> PAGE_SHIFT];
|
---|
3322 | return VINF_SUCCESS;
|
---|
3323 | }
|
---|
3324 |
|
---|
3325 |
|
---|
3326 |
|
---|
3327 |
|
---|
3328 | /**
|
---|
3329 | * Gets the PGMPAGE structure for a guest page.
|
---|
3330 | *
|
---|
3331 | * Old Phys code: Will make sure the page is present.
|
---|
3332 | *
|
---|
3333 | * @returns VBox status code.
|
---|
3334 | * @retval VINF_SUCCESS and a valid *ppPage on success.
|
---|
3335 | * @retval VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS if the address isn't valid.
|
---|
3336 | *
|
---|
3337 | * @param pPGM PGM handle.
|
---|
3338 | * @param GCPhys The GC physical address.
|
---|
3339 | * @param ppPage Where to store the page pointer on success.
|
---|
3340 | * @param ppRamHint Where to read and store the ram list hint.
|
---|
3341 | * The caller initializes this to NULL before the call.
|
---|
3342 | */
|
---|
3343 | DECLINLINE(int) pgmPhysGetPageWithHintEx(PPGM pPGM, RTGCPHYS GCPhys, PPPGMPAGE ppPage, PPGMRAMRANGE *ppRamHint)
|
---|
3344 | {
|
---|
3345 | RTGCPHYS off;
|
---|
3346 | PPGMRAMRANGE pRam = *ppRamHint;
|
---|
3347 | if ( !pRam
|
---|
3348 | || RT_UNLIKELY((off = GCPhys - pRam->GCPhys) >= pRam->cb))
|
---|
3349 | {
|
---|
3350 | pRam = pPGM->CTX_SUFF(pRamRanges);
|
---|
3351 | off = GCPhys - pRam->GCPhys;
|
---|
3352 | if (RT_UNLIKELY(off >= pRam->cb))
|
---|
3353 | {
|
---|
3354 | do
|
---|
3355 | {
|
---|
3356 | pRam = pRam->CTX_SUFF(pNext);
|
---|
3357 | if (RT_UNLIKELY(!pRam))
|
---|
3358 | {
|
---|
3359 | *ppPage = NULL; /* Kill the incorrect and extremely annoying GCC warnings. */
|
---|
3360 | return VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS;
|
---|
3361 | }
|
---|
3362 | off = GCPhys - pRam->GCPhys;
|
---|
3363 | } while (off >= pRam->cb);
|
---|
3364 | }
|
---|
3365 | *ppRamHint = pRam;
|
---|
3366 | }
|
---|
3367 | *ppPage = &pRam->aPages[off >> PAGE_SHIFT];
|
---|
3368 | return VINF_SUCCESS;
|
---|
3369 | }
|
---|
3370 |
|
---|
3371 |
|
---|
3372 | /**
|
---|
3373 | * Gets the PGMPAGE structure for a guest page together with the PGMRAMRANGE.
|
---|
3374 | *
|
---|
3375 | * @returns Pointer to the page on success.
|
---|
3376 | * @returns NULL on a VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS condition.
|
---|
3377 | *
|
---|
3378 | * @param pPGM PGM handle.
|
---|
3379 | * @param GCPhys The GC physical address.
|
---|
3380 | * @param ppRam Where to store the pointer to the PGMRAMRANGE.
|
---|
3381 | */
|
---|
3382 | DECLINLINE(PPGMPAGE) pgmPhysGetPageAndRange(PPGM pPGM, RTGCPHYS GCPhys, PPGMRAMRANGE *ppRam)
|
---|
3383 | {
|
---|
3384 | /*
|
---|
3385 | * Optimize for the first range.
|
---|
3386 | */
|
---|
3387 | PPGMRAMRANGE pRam = pPGM->CTX_SUFF(pRamRanges);
|
---|
3388 | RTGCPHYS off = GCPhys - pRam->GCPhys;
|
---|
3389 | if (RT_UNLIKELY(off >= pRam->cb))
|
---|
3390 | {
|
---|
3391 | do
|
---|
3392 | {
|
---|
3393 | pRam = pRam->CTX_SUFF(pNext);
|
---|
3394 | if (RT_UNLIKELY(!pRam))
|
---|
3395 | return NULL;
|
---|
3396 | off = GCPhys - pRam->GCPhys;
|
---|
3397 | } while (off >= pRam->cb);
|
---|
3398 | }
|
---|
3399 | *ppRam = pRam;
|
---|
3400 | return &pRam->aPages[off >> PAGE_SHIFT];
|
---|
3401 | }
|
---|
3402 |
|
---|
3403 |
|
---|
3404 | /**
|
---|
3405 | * Gets the PGMPAGE structure for a guest page together with the PGMRAMRANGE.
|
---|
3406 | *
|
---|
3407 | * @returns Pointer to the page on success.
|
---|
3408 | * @returns NULL on a VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS condition.
|
---|
3409 | *
|
---|
3410 | * @param pPGM PGM handle.
|
---|
3411 | * @param GCPhys The GC physical address.
|
---|
3412 | * @param ppPage Where to store the pointer to the PGMPAGE structure.
|
---|
3413 | * @param ppRam Where to store the pointer to the PGMRAMRANGE structure.
|
---|
3414 | */
|
---|
3415 | DECLINLINE(int) pgmPhysGetPageAndRangeEx(PPGM pPGM, RTGCPHYS GCPhys, PPPGMPAGE ppPage, PPGMRAMRANGE *ppRam)
|
---|
3416 | {
|
---|
3417 | /*
|
---|
3418 | * Optimize for the first range.
|
---|
3419 | */
|
---|
3420 | PPGMRAMRANGE pRam = pPGM->CTX_SUFF(pRamRanges);
|
---|
3421 | RTGCPHYS off = GCPhys - pRam->GCPhys;
|
---|
3422 | if (RT_UNLIKELY(off >= pRam->cb))
|
---|
3423 | {
|
---|
3424 | do
|
---|
3425 | {
|
---|
3426 | pRam = pRam->CTX_SUFF(pNext);
|
---|
3427 | if (RT_UNLIKELY(!pRam))
|
---|
3428 | {
|
---|
3429 | *ppRam = NULL; /* Shut up silly GCC warnings. */
|
---|
3430 | *ppPage = NULL; /* ditto */
|
---|
3431 | return VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS;
|
---|
3432 | }
|
---|
3433 | off = GCPhys - pRam->GCPhys;
|
---|
3434 | } while (off >= pRam->cb);
|
---|
3435 | }
|
---|
3436 | *ppRam = pRam;
|
---|
3437 | *ppPage = &pRam->aPages[off >> PAGE_SHIFT];
|
---|
3438 | return VINF_SUCCESS;
|
---|
3439 | }
|
---|
3440 |
|
---|
3441 |
|
---|
3442 | /**
|
---|
3443 | * Convert GC Phys to HC Phys.
|
---|
3444 | *
|
---|
3445 | * @returns VBox status.
|
---|
3446 | * @param pPGM PGM handle.
|
---|
3447 | * @param GCPhys The GC physical address.
|
---|
3448 | * @param pHCPhys Where to store the corresponding HC physical address.
|
---|
3449 | *
|
---|
3450 | * @deprecated Doesn't deal with zero, shared or write monitored pages.
|
---|
3451 | * Avoid when writing new code!
|
---|
3452 | */
|
---|
3453 | DECLINLINE(int) pgmRamGCPhys2HCPhys(PPGM pPGM, RTGCPHYS GCPhys, PRTHCPHYS pHCPhys)
|
---|
3454 | {
|
---|
3455 | PPGMPAGE pPage;
|
---|
3456 | int rc = pgmPhysGetPageEx(pPGM, GCPhys, &pPage);
|
---|
3457 | if (RT_FAILURE(rc))
|
---|
3458 | return rc;
|
---|
3459 | *pHCPhys = PGM_PAGE_GET_HCPHYS(pPage) | (GCPhys & PAGE_OFFSET_MASK);
|
---|
3460 | return VINF_SUCCESS;
|
---|
3461 | }
|
---|
3462 |
|
---|
3463 | #ifdef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
|
---|
3464 |
|
---|
3465 | /**
|
---|
3466 | * Inlined version of the ring-0 version of PGMDynMapHCPage that
|
---|
3467 | * optimizes access to pages already in the set.
|
---|
3468 | *
|
---|
3469 | * @returns VINF_SUCCESS. Will bail out to ring-3 on failure.
|
---|
3470 | * @param pPGM Pointer to the PVM instance data.
|
---|
3471 | * @param HCPhys The physical address of the page.
|
---|
3472 | * @param ppv Where to store the mapping address.
|
---|
3473 | */
|
---|
3474 | DECLINLINE(int) pgmR0DynMapHCPageInlined(PPGM pPGM, RTHCPHYS HCPhys, void **ppv)
|
---|
3475 | {
|
---|
3476 | PVM pVM = PGM2VM(pPGM);
|
---|
3477 | PPGMCPU pPGMCPU = (PPGMCPU)((uint8_t *)VMMGetCpu(pVM) + pPGM->offVCpuPGM); /* very pretty ;-) */
|
---|
3478 | PPGMMAPSET pSet = &pPGMCPU->AutoSet;
|
---|
3479 |
|
---|
3480 | STAM_PROFILE_START(&pPGMCPU->StatR0DynMapHCPageInl, a);
|
---|
3481 | Assert(!(HCPhys & PAGE_OFFSET_MASK));
|
---|
3482 | Assert(pSet->cEntries <= RT_ELEMENTS(pSet->aEntries));
|
---|
3483 |
|
---|
3484 | unsigned iHash = PGMMAPSET_HASH(HCPhys);
|
---|
3485 | unsigned iEntry = pSet->aiHashTable[iHash];
|
---|
3486 | if ( iEntry < pSet->cEntries
|
---|
3487 | && pSet->aEntries[iEntry].HCPhys == HCPhys)
|
---|
3488 | {
|
---|
3489 | *ppv = pSet->aEntries[iEntry].pvPage;
|
---|
3490 | STAM_COUNTER_INC(&pPGMCPU->StatR0DynMapHCPageInlHits);
|
---|
3491 | }
|
---|
3492 | else
|
---|
3493 | {
|
---|
3494 | STAM_COUNTER_INC(&pPGMCPU->StatR0DynMapHCPageInlMisses);
|
---|
3495 | pgmR0DynMapHCPageCommon(pVM, pSet, HCPhys, ppv);
|
---|
3496 | }
|
---|
3497 |
|
---|
3498 | STAM_PROFILE_STOP(&pPGMCPU->StatR0DynMapHCPageInl, a);
|
---|
3499 | return VINF_SUCCESS;
|
---|
3500 | }
|
---|
3501 |
|
---|
3502 |
|
---|
3503 | /**
|
---|
3504 | * Inlined version of the ring-0 version of PGMDynMapGCPage that optimizes
|
---|
3505 | * access to pages already in the set.
|
---|
3506 | *
|
---|
3507 | * @returns See PGMDynMapGCPage.
|
---|
3508 | * @param pPGM Pointer to the PVM instance data.
|
---|
3509 | * @param HCPhys The physical address of the page.
|
---|
3510 | * @param ppv Where to store the mapping address.
|
---|
3511 | */
|
---|
3512 | DECLINLINE(int) pgmR0DynMapGCPageInlined(PPGM pPGM, RTGCPHYS GCPhys, void **ppv)
|
---|
3513 | {
|
---|
3514 | PVM pVM = PGM2VM(pPGM);
|
---|
3515 | PPGMCPU pPGMCPU = (PPGMCPU)((uint8_t *)VMMGetCpu(pVM) + pPGM->offVCpuPGM); /* very pretty ;-) */
|
---|
3516 |
|
---|
3517 | STAM_PROFILE_START(&pPGMCPU->StatR0DynMapGCPageInl, a);
|
---|
3518 | AssertMsg(!(GCPhys & PAGE_OFFSET_MASK), ("%RGp\n", GCPhys));
|
---|
3519 |
|
---|
3520 | /*
|
---|
3521 | * Get the ram range.
|
---|
3522 | */
|
---|
3523 | PPGMRAMRANGE pRam = pPGM->CTX_SUFF(pRamRanges);
|
---|
3524 | RTGCPHYS off = GCPhys - pRam->GCPhys;
|
---|
3525 | if (RT_UNLIKELY(off >= pRam->cb
|
---|
3526 | /** @todo || page state stuff */))
|
---|
3527 | {
|
---|
3528 | /* This case is not counted into StatR0DynMapGCPageInl. */
|
---|
3529 | STAM_COUNTER_INC(&pPGMCPU->StatR0DynMapGCPageInlRamMisses);
|
---|
3530 | return PGMDynMapGCPage(pVM, GCPhys, ppv);
|
---|
3531 | }
|
---|
3532 |
|
---|
3533 | RTHCPHYS HCPhys = PGM_PAGE_GET_HCPHYS(&pRam->aPages[off >> PAGE_SHIFT]);
|
---|
3534 | STAM_COUNTER_INC(&pPGMCPU->StatR0DynMapGCPageInlRamHits);
|
---|
3535 |
|
---|
3536 | /*
|
---|
3537 | * pgmR0DynMapHCPageInlined with out stats.
|
---|
3538 | */
|
---|
3539 | PPGMMAPSET pSet = &pPGMCPU->AutoSet;
|
---|
3540 | Assert(!(HCPhys & PAGE_OFFSET_MASK));
|
---|
3541 | Assert(pSet->cEntries <= RT_ELEMENTS(pSet->aEntries));
|
---|
3542 |
|
---|
3543 | unsigned iHash = PGMMAPSET_HASH(HCPhys);
|
---|
3544 | unsigned iEntry = pSet->aiHashTable[iHash];
|
---|
3545 | if ( iEntry < pSet->cEntries
|
---|
3546 | && pSet->aEntries[iEntry].HCPhys == HCPhys)
|
---|
3547 | {
|
---|
3548 | *ppv = pSet->aEntries[iEntry].pvPage;
|
---|
3549 | STAM_COUNTER_INC(&pPGMCPU->StatR0DynMapGCPageInlHits);
|
---|
3550 | }
|
---|
3551 | else
|
---|
3552 | {
|
---|
3553 | STAM_COUNTER_INC(&pPGMCPU->StatR0DynMapGCPageInlMisses);
|
---|
3554 | pgmR0DynMapHCPageCommon(pVM, pSet, HCPhys, ppv);
|
---|
3555 | }
|
---|
3556 |
|
---|
3557 | STAM_PROFILE_STOP(&pPGMCPU->StatR0DynMapGCPageInl, a);
|
---|
3558 | return VINF_SUCCESS;
|
---|
3559 | }
|
---|
3560 |
|
---|
3561 |
|
---|
3562 | /**
|
---|
3563 | * Inlined version of the ring-0 version of PGMDynMapGCPageOff that optimizes
|
---|
3564 | * access to pages already in the set.
|
---|
3565 | *
|
---|
3566 | * @returns See PGMDynMapGCPage.
|
---|
3567 | * @param pPGM Pointer to the PVM instance data.
|
---|
3568 | * @param HCPhys The physical address of the page.
|
---|
3569 | * @param ppv Where to store the mapping address.
|
---|
3570 | */
|
---|
3571 | DECLINLINE(int) pgmR0DynMapGCPageOffInlined(PPGM pPGM, RTGCPHYS GCPhys, void **ppv)
|
---|
3572 | {
|
---|
3573 | PVM pVM = PGM2VM(pPGM);
|
---|
3574 | PPGMCPU pPGMCPU = (PPGMCPU)((uint8_t *)VMMGetCpu(pVM) + pPGM->offVCpuPGM); /* very pretty ;-) */
|
---|
3575 |
|
---|
3576 | STAM_PROFILE_START(&pPGMCPU->StatR0DynMapGCPageInl, a);
|
---|
3577 |
|
---|
3578 | /*
|
---|
3579 | * Get the ram range.
|
---|
3580 | */
|
---|
3581 | PPGMRAMRANGE pRam = pPGM->CTX_SUFF(pRamRanges);
|
---|
3582 | RTGCPHYS off = GCPhys - pRam->GCPhys;
|
---|
3583 | if (RT_UNLIKELY(off >= pRam->cb
|
---|
3584 | /** @todo || page state stuff */))
|
---|
3585 | {
|
---|
3586 | /* This case is not counted into StatR0DynMapGCPageInl. */
|
---|
3587 | STAM_COUNTER_INC(&pPGMCPU->StatR0DynMapGCPageInlRamMisses);
|
---|
3588 | return PGMDynMapGCPageOff(pVM, GCPhys, ppv);
|
---|
3589 | }
|
---|
3590 |
|
---|
3591 | RTHCPHYS HCPhys = PGM_PAGE_GET_HCPHYS(&pRam->aPages[off >> PAGE_SHIFT]);
|
---|
3592 | STAM_COUNTER_INC(&pPGMCPU->StatR0DynMapGCPageInlRamHits);
|
---|
3593 |
|
---|
3594 | /*
|
---|
3595 | * pgmR0DynMapHCPageInlined with out stats.
|
---|
3596 | */
|
---|
3597 | PPGMMAPSET pSet = &pPGMCPU->AutoSet;
|
---|
3598 | Assert(!(HCPhys & PAGE_OFFSET_MASK));
|
---|
3599 | Assert(pSet->cEntries <= RT_ELEMENTS(pSet->aEntries));
|
---|
3600 |
|
---|
3601 | unsigned iHash = PGMMAPSET_HASH(HCPhys);
|
---|
3602 | unsigned iEntry = pSet->aiHashTable[iHash];
|
---|
3603 | if ( iEntry < pSet->cEntries
|
---|
3604 | && pSet->aEntries[iEntry].HCPhys == HCPhys)
|
---|
3605 | {
|
---|
3606 | *ppv = (void *)((uintptr_t)pSet->aEntries[iEntry].pvPage | (PAGE_OFFSET_MASK & (uintptr_t)GCPhys));
|
---|
3607 | STAM_COUNTER_INC(&pPGMCPU->StatR0DynMapGCPageInlHits);
|
---|
3608 | }
|
---|
3609 | else
|
---|
3610 | {
|
---|
3611 | STAM_COUNTER_INC(&pPGMCPU->StatR0DynMapGCPageInlMisses);
|
---|
3612 | pgmR0DynMapHCPageCommon(pVM, pSet, HCPhys, ppv);
|
---|
3613 | *ppv = (void *)((uintptr_t)*ppv | (PAGE_OFFSET_MASK & (uintptr_t)GCPhys));
|
---|
3614 | }
|
---|
3615 |
|
---|
3616 | STAM_PROFILE_STOP(&pPGMCPU->StatR0DynMapGCPageInl, a);
|
---|
3617 | return VINF_SUCCESS;
|
---|
3618 | }
|
---|
3619 |
|
---|
3620 | #endif /* VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0 */
|
---|
3621 | #if defined(IN_RC) || defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0)
|
---|
3622 |
|
---|
3623 | /**
|
---|
3624 | * Maps the page into current context (RC and maybe R0).
|
---|
3625 | *
|
---|
3626 | * @returns pointer to the mapping.
|
---|
3627 | * @param pVM Pointer to the PGM instance data.
|
---|
3628 | * @param pPage The page.
|
---|
3629 | */
|
---|
3630 | DECLINLINE(void *) pgmPoolMapPageInlined(PPGM pPGM, PPGMPOOLPAGE pPage)
|
---|
3631 | {
|
---|
3632 | if (pPage->idx >= PGMPOOL_IDX_FIRST)
|
---|
3633 | {
|
---|
3634 | Assert(pPage->idx < pPGM->CTX_SUFF(pPool)->cCurPages);
|
---|
3635 | void *pv;
|
---|
3636 | # ifdef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
|
---|
3637 | pgmR0DynMapHCPageInlined(pPGM, pPage->Core.Key, &pv);
|
---|
3638 | # else
|
---|
3639 | PGMDynMapHCPage(PGM2VM(pPGM), pPage->Core.Key, &pv);
|
---|
3640 | # endif
|
---|
3641 | return pv;
|
---|
3642 | }
|
---|
3643 | AssertFatalMsgFailed(("pgmPoolMapPageInlined invalid page index %x\n", pPage->idx));
|
---|
3644 | }
|
---|
3645 |
|
---|
3646 | /**
|
---|
3647 | * Temporarily maps one host page specified by HC physical address, returning
|
---|
3648 | * pointer within the page.
|
---|
3649 | *
|
---|
3650 | * Be WARNED that the dynamic page mapping area is small, 8 pages, thus the space is
|
---|
3651 | * reused after 8 mappings (or perhaps a few more if you score with the cache).
|
---|
3652 | *
|
---|
3653 | * @returns The address corresponding to HCPhys.
|
---|
3654 | * @param pPGM Pointer to the PVM instance data.
|
---|
3655 | * @param HCPhys HC Physical address of the page.
|
---|
3656 | */
|
---|
3657 | DECLINLINE(void *) pgmDynMapHCPageOff(PPGM pPGM, RTHCPHYS HCPhys)
|
---|
3658 | {
|
---|
3659 | void *pv;
|
---|
3660 | # ifdef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
|
---|
3661 | pgmR0DynMapHCPageInlined(pPGM, HCPhys & ~(RTHCPHYS)PAGE_OFFSET_MASK, &pv);
|
---|
3662 | # else
|
---|
3663 | PGMDynMapHCPage(PGM2VM(pPGM), HCPhys & ~(RTHCPHYS)PAGE_OFFSET_MASK, &pv);
|
---|
3664 | # endif
|
---|
3665 | pv = (void *)((uintptr_t)pv | ((uintptr_t)HCPhys & PAGE_OFFSET_MASK));
|
---|
3666 | return pv;
|
---|
3667 | }
|
---|
3668 |
|
---|
3669 | #endif /* VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0 || IN_RC */
|
---|
3670 | #ifndef IN_RC
|
---|
3671 |
|
---|
3672 | /**
|
---|
3673 | * Queries the Physical TLB entry for a physical guest page,
|
---|
3674 | * attempting to load the TLB entry if necessary.
|
---|
3675 | *
|
---|
3676 | * @returns VBox status code.
|
---|
3677 | * @retval VINF_SUCCESS on success
|
---|
3678 | * @retval VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS if it's not a valid physical address.
|
---|
3679 | *
|
---|
3680 | * @param pPGM The PGM instance handle.
|
---|
3681 | * @param GCPhys The address of the guest page.
|
---|
3682 | * @param ppTlbe Where to store the pointer to the TLB entry.
|
---|
3683 | */
|
---|
3684 | DECLINLINE(int) pgmPhysPageQueryTlbe(PPGM pPGM, RTGCPHYS GCPhys, PPPGMPAGEMAPTLBE ppTlbe)
|
---|
3685 | {
|
---|
3686 | int rc;
|
---|
3687 | PPGMPAGEMAPTLBE pTlbe = &pPGM->CTXSUFF(PhysTlb).aEntries[PGM_PAGEMAPTLB_IDX(GCPhys)];
|
---|
3688 | if (pTlbe->GCPhys == (GCPhys & X86_PTE_PAE_PG_MASK))
|
---|
3689 | {
|
---|
3690 | STAM_COUNTER_INC(&pPGM->CTX_MID_Z(Stat,PageMapTlbHits));
|
---|
3691 | rc = VINF_SUCCESS;
|
---|
3692 | }
|
---|
3693 | else
|
---|
3694 | rc = pgmPhysPageLoadIntoTlb(pPGM, GCPhys);
|
---|
3695 | *ppTlbe = pTlbe;
|
---|
3696 | return rc;
|
---|
3697 | }
|
---|
3698 |
|
---|
3699 |
|
---|
3700 | /**
|
---|
3701 | * Queries the Physical TLB entry for a physical guest page,
|
---|
3702 | * attempting to load the TLB entry if necessary.
|
---|
3703 | *
|
---|
3704 | * @returns VBox status code.
|
---|
3705 | * @retval VINF_SUCCESS on success
|
---|
3706 | * @retval VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS if it's not a valid physical address.
|
---|
3707 | *
|
---|
3708 | * @param pPGM The PGM instance handle.
|
---|
3709 | * @param pPage Pointer to the PGMPAGE structure corresponding to
|
---|
3710 | * GCPhys.
|
---|
3711 | * @param GCPhys The address of the guest page.
|
---|
3712 | * @param ppTlbe Where to store the pointer to the TLB entry.
|
---|
3713 | */
|
---|
3714 | DECLINLINE(int) pgmPhysPageQueryTlbeWithPage(PPGM pPGM, PPGMPAGE pPage, RTGCPHYS GCPhys, PPPGMPAGEMAPTLBE ppTlbe)
|
---|
3715 | {
|
---|
3716 | int rc;
|
---|
3717 | PPGMPAGEMAPTLBE pTlbe = &pPGM->CTXSUFF(PhysTlb).aEntries[PGM_PAGEMAPTLB_IDX(GCPhys)];
|
---|
3718 | if (pTlbe->GCPhys == (GCPhys & X86_PTE_PAE_PG_MASK))
|
---|
3719 | {
|
---|
3720 | STAM_COUNTER_INC(&pPGM->CTX_MID_Z(Stat,PageMapTlbHits));
|
---|
3721 | rc = VINF_SUCCESS;
|
---|
3722 | }
|
---|
3723 | else
|
---|
3724 | rc = pgmPhysPageLoadIntoTlbWithPage(pPGM, pPage, GCPhys);
|
---|
3725 | *ppTlbe = pTlbe;
|
---|
3726 | return rc;
|
---|
3727 | }
|
---|
3728 |
|
---|
3729 | #endif /* !IN_RC */
|
---|
3730 |
|
---|
3731 | /**
|
---|
3732 | * Calculated the guest physical address of the large (4 MB) page in 32 bits paging mode.
|
---|
3733 | * Takes PSE-36 into account.
|
---|
3734 | *
|
---|
3735 | * @returns guest physical address
|
---|
3736 | * @param pPGM Pointer to the PGM instance data.
|
---|
3737 | * @param Pde Guest Pde
|
---|
3738 | */
|
---|
3739 | DECLINLINE(RTGCPHYS) pgmGstGet4MBPhysPage(PPGM pPGM, X86PDE Pde)
|
---|
3740 | {
|
---|
3741 | RTGCPHYS GCPhys = Pde.u & X86_PDE4M_PG_MASK;
|
---|
3742 | GCPhys |= (RTGCPHYS)Pde.b.u8PageNoHigh << 32;
|
---|
3743 |
|
---|
3744 | return GCPhys & pPGM->GCPhys4MBPSEMask;
|
---|
3745 | }
|
---|
3746 |
|
---|
3747 |
|
---|
3748 | /**
|
---|
3749 | * Gets the page directory entry for the specified address (32-bit paging).
|
---|
3750 | *
|
---|
3751 | * @returns The page directory entry in question.
|
---|
3752 | * @param pPGM Pointer to the PGM instance data.
|
---|
3753 | * @param GCPtr The address.
|
---|
3754 | */
|
---|
3755 | DECLINLINE(X86PDE) pgmGstGet32bitPDE(PPGMCPU pPGM, RTGCPTR GCPtr)
|
---|
3756 | {
|
---|
3757 | #ifdef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
|
---|
3758 | PCX86PD pGuestPD = NULL;
|
---|
3759 | int rc = pgmR0DynMapGCPageInlined(PGMCPU2PGM(pPGM), pPGM->GCPhysCR3, (void **)&pGuestPD);
|
---|
3760 | if (RT_FAILURE(rc))
|
---|
3761 | {
|
---|
3762 | X86PDE ZeroPde = {0};
|
---|
3763 | AssertMsgFailedReturn(("%Rrc\n", rc), ZeroPde);
|
---|
3764 | }
|
---|
3765 | #else
|
---|
3766 | PX86PD pGuestPD = pPGM->CTX_SUFF(pGst32BitPd);
|
---|
3767 | # ifdef IN_RING3
|
---|
3768 | if (!pGuestPD)
|
---|
3769 | pGuestPD = pgmGstLazyMap32BitPD(pPGM);
|
---|
3770 | # endif
|
---|
3771 | #endif
|
---|
3772 | return pGuestPD->a[GCPtr >> X86_PD_SHIFT];
|
---|
3773 | }
|
---|
3774 |
|
---|
3775 |
|
---|
3776 | /**
|
---|
3777 | * Gets the address of a specific page directory entry (32-bit paging).
|
---|
3778 | *
|
---|
3779 | * @returns Pointer the page directory entry in question.
|
---|
3780 | * @param pPGM Pointer to the PGM instance data.
|
---|
3781 | * @param GCPtr The address.
|
---|
3782 | */
|
---|
3783 | DECLINLINE(PX86PDE) pgmGstGet32bitPDEPtr(PPGMCPU pPGM, RTGCPTR GCPtr)
|
---|
3784 | {
|
---|
3785 | #ifdef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
|
---|
3786 | PX86PD pGuestPD = NULL;
|
---|
3787 | int rc = pgmR0DynMapGCPageInlined(PGMCPU2PGM(pPGM), pPGM->GCPhysCR3, (void **)&pGuestPD);
|
---|
3788 | AssertRCReturn(rc, NULL);
|
---|
3789 | #else
|
---|
3790 | PX86PD pGuestPD = pPGM->CTX_SUFF(pGst32BitPd);
|
---|
3791 | # ifdef IN_RING3
|
---|
3792 | if (!pGuestPD)
|
---|
3793 | pGuestPD = pgmGstLazyMap32BitPD(pPGM);
|
---|
3794 | # endif
|
---|
3795 | #endif
|
---|
3796 | return &pGuestPD->a[GCPtr >> X86_PD_SHIFT];
|
---|
3797 | }
|
---|
3798 |
|
---|
3799 |
|
---|
3800 | /**
|
---|
3801 | * Gets the address the guest page directory (32-bit paging).
|
---|
3802 | *
|
---|
3803 | * @returns Pointer the page directory entry in question.
|
---|
3804 | * @param pPGM Pointer to the PGM instance data.
|
---|
3805 | */
|
---|
3806 | DECLINLINE(PX86PD) pgmGstGet32bitPDPtr(PPGMCPU pPGM)
|
---|
3807 | {
|
---|
3808 | #ifdef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
|
---|
3809 | PX86PD pGuestPD = NULL;
|
---|
3810 | int rc = pgmR0DynMapGCPageInlined(PGMCPU2PGM(pPGM), pPGM->GCPhysCR3, (void **)&pGuestPD);
|
---|
3811 | AssertRCReturn(rc, NULL);
|
---|
3812 | #else
|
---|
3813 | PX86PD pGuestPD = pPGM->CTX_SUFF(pGst32BitPd);
|
---|
3814 | # ifdef IN_RING3
|
---|
3815 | if (!pGuestPD)
|
---|
3816 | pGuestPD = pgmGstLazyMap32BitPD(pPGM);
|
---|
3817 | # endif
|
---|
3818 | #endif
|
---|
3819 | return pGuestPD;
|
---|
3820 | }
|
---|
3821 |
|
---|
3822 |
|
---|
3823 | /**
|
---|
3824 | * Gets the guest page directory pointer table.
|
---|
3825 | *
|
---|
3826 | * @returns Pointer to the page directory in question.
|
---|
3827 | * @returns NULL if the page directory is not present or on an invalid page.
|
---|
3828 | * @param pPGM Pointer to the PGM instance data.
|
---|
3829 | */
|
---|
3830 | DECLINLINE(PX86PDPT) pgmGstGetPaePDPTPtr(PPGMCPU pPGM)
|
---|
3831 | {
|
---|
3832 | #ifdef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
|
---|
3833 | PX86PDPT pGuestPDPT = NULL;
|
---|
3834 | int rc = pgmR0DynMapGCPageOffInlined(PGMCPU2PGM(pPGM), pPGM->GCPhysCR3, (void **)&pGuestPDPT);
|
---|
3835 | AssertRCReturn(rc, NULL);
|
---|
3836 | #else
|
---|
3837 | PX86PDPT pGuestPDPT = pPGM->CTX_SUFF(pGstPaePdpt);
|
---|
3838 | # ifdef IN_RING3
|
---|
3839 | if (!pGuestPDPT)
|
---|
3840 | pGuestPDPT = pgmGstLazyMapPaePDPT(pPGM);
|
---|
3841 | # endif
|
---|
3842 | #endif
|
---|
3843 | return pGuestPDPT;
|
---|
3844 | }
|
---|
3845 |
|
---|
3846 |
|
---|
3847 | /**
|
---|
3848 | * Gets the guest page directory pointer table entry for the specified address.
|
---|
3849 | *
|
---|
3850 | * @returns Pointer to the page directory in question.
|
---|
3851 | * @returns NULL if the page directory is not present or on an invalid page.
|
---|
3852 | * @param pPGM Pointer to the PGM instance data.
|
---|
3853 | * @param GCPtr The address.
|
---|
3854 | */
|
---|
3855 | DECLINLINE(PX86PDPE) pgmGstGetPaePDPEPtr(PPGMCPU pPGM, RTGCPTR GCPtr)
|
---|
3856 | {
|
---|
3857 | AssertGCPtr32(GCPtr);
|
---|
3858 |
|
---|
3859 | #ifdef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
|
---|
3860 | PX86PDPT pGuestPDPT = 0;
|
---|
3861 | int rc = pgmR0DynMapGCPageOffInlined(PGMCPU2PGM(pPGM), pPGM->GCPhysCR3, (void **)&pGuestPDPT);
|
---|
3862 | AssertRCReturn(rc, 0);
|
---|
3863 | #else
|
---|
3864 | PX86PDPT pGuestPDPT = pPGM->CTX_SUFF(pGstPaePdpt);
|
---|
3865 | # ifdef IN_RING3
|
---|
3866 | if (!pGuestPDPT)
|
---|
3867 | pGuestPDPT = pgmGstLazyMapPaePDPT(pPGM);
|
---|
3868 | # endif
|
---|
3869 | #endif
|
---|
3870 | return &pGuestPDPT->a[(GCPtr >> X86_PDPT_SHIFT) & X86_PDPT_MASK_PAE];
|
---|
3871 | }
|
---|
3872 |
|
---|
3873 |
|
---|
3874 | /**
|
---|
3875 | * Gets the page directory for the specified address.
|
---|
3876 | *
|
---|
3877 | * @returns Pointer to the page directory in question.
|
---|
3878 | * @returns NULL if the page directory is not present or on an invalid page.
|
---|
3879 | * @param pPGM Pointer to the PGM instance data.
|
---|
3880 | * @param GCPtr The address.
|
---|
3881 | */
|
---|
3882 | DECLINLINE(PX86PDPAE) pgmGstGetPaePD(PPGMCPU pPGM, RTGCPTR GCPtr)
|
---|
3883 | {
|
---|
3884 | AssertGCPtr32(GCPtr);
|
---|
3885 |
|
---|
3886 | PX86PDPT pGuestPDPT = pgmGstGetPaePDPTPtr(pPGM);
|
---|
3887 | AssertReturn(pGuestPDPT, NULL);
|
---|
3888 | const unsigned iPdpt = (GCPtr >> X86_PDPT_SHIFT) & X86_PDPT_MASK_PAE;
|
---|
3889 | if (pGuestPDPT->a[iPdpt].n.u1Present)
|
---|
3890 | {
|
---|
3891 | #ifdef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
|
---|
3892 | PX86PDPAE pGuestPD = NULL;
|
---|
3893 | int rc = pgmR0DynMapGCPageInlined(PGMCPU2PGM(pPGM), pGuestPDPT->a[iPdpt].u & X86_PDPE_PG_MASK, (void **)&pGuestPD);
|
---|
3894 | AssertRCReturn(rc, NULL);
|
---|
3895 | #else
|
---|
3896 | PX86PDPAE pGuestPD = pPGM->CTX_SUFF(apGstPaePDs)[iPdpt];
|
---|
3897 | if ( !pGuestPD
|
---|
3898 | || (pGuestPDPT->a[iPdpt].u & X86_PDPE_PG_MASK) != pPGM->aGCPhysGstPaePDs[iPdpt])
|
---|
3899 | pGuestPD = pgmGstLazyMapPaePD(pPGM, iPdpt);
|
---|
3900 | #endif
|
---|
3901 | return pGuestPD;
|
---|
3902 | /* returning NULL is ok if we assume it's just an invalid page of some kind emulated as all 0s. (not quite true) */
|
---|
3903 | }
|
---|
3904 | return NULL;
|
---|
3905 | }
|
---|
3906 |
|
---|
3907 |
|
---|
3908 | /**
|
---|
3909 | * Gets the page directory entry for the specified address.
|
---|
3910 | *
|
---|
3911 | * @returns Pointer to the page directory entry in question.
|
---|
3912 | * @returns NULL if the page directory is not present or on an invalid page.
|
---|
3913 | * @param pPGM Pointer to the PGM instance data.
|
---|
3914 | * @param GCPtr The address.
|
---|
3915 | */
|
---|
3916 | DECLINLINE(PX86PDEPAE) pgmGstGetPaePDEPtr(PPGMCPU pPGM, RTGCPTR GCPtr)
|
---|
3917 | {
|
---|
3918 | AssertGCPtr32(GCPtr);
|
---|
3919 |
|
---|
3920 | PX86PDPT pGuestPDPT = pgmGstGetPaePDPTPtr(pPGM);
|
---|
3921 | AssertReturn(pGuestPDPT, NULL);
|
---|
3922 | const unsigned iPdpt = (GCPtr >> X86_PDPT_SHIFT) & X86_PDPT_MASK_PAE;
|
---|
3923 | if (pGuestPDPT->a[iPdpt].n.u1Present)
|
---|
3924 | {
|
---|
3925 | const unsigned iPD = (GCPtr >> X86_PD_PAE_SHIFT) & X86_PD_PAE_MASK;
|
---|
3926 | #ifdef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
|
---|
3927 | PX86PDPAE pGuestPD = NULL;
|
---|
3928 | int rc = pgmR0DynMapGCPageInlined(PGMCPU2PGM(pPGM), pGuestPDPT->a[iPdpt].u & X86_PDPE_PG_MASK, (void **)&pGuestPD);
|
---|
3929 | AssertRCReturn(rc, NULL);
|
---|
3930 | #else
|
---|
3931 | PX86PDPAE pGuestPD = pPGM->CTX_SUFF(apGstPaePDs)[iPdpt];
|
---|
3932 | if ( !pGuestPD
|
---|
3933 | || (pGuestPDPT->a[iPdpt].u & X86_PDPE_PG_MASK) != pPGM->aGCPhysGstPaePDs[iPdpt])
|
---|
3934 | pGuestPD = pgmGstLazyMapPaePD(pPGM, iPdpt);
|
---|
3935 | #endif
|
---|
3936 | return &pGuestPD->a[iPD];
|
---|
3937 | /* returning NIL_RTGCPHYS is ok if we assume it's just an invalid page or something which we'll emulate as all 0s. (not quite true) */
|
---|
3938 | }
|
---|
3939 | return NULL;
|
---|
3940 | }
|
---|
3941 |
|
---|
3942 |
|
---|
3943 | /**
|
---|
3944 | * Gets the page directory entry for the specified address.
|
---|
3945 | *
|
---|
3946 | * @returns The page directory entry in question.
|
---|
3947 | * @returns A non-present entry if the page directory is not present or on an invalid page.
|
---|
3948 | * @param pPGM Pointer to the PGM instance data.
|
---|
3949 | * @param GCPtr The address.
|
---|
3950 | */
|
---|
3951 | DECLINLINE(X86PDEPAE) pgmGstGetPaePDE(PPGMCPU pPGM, RTGCPTR GCPtr)
|
---|
3952 | {
|
---|
3953 | AssertGCPtr32(GCPtr);
|
---|
3954 | X86PDEPAE ZeroPde = {0};
|
---|
3955 | PX86PDPT pGuestPDPT = pgmGstGetPaePDPTPtr(pPGM);
|
---|
3956 | if (RT_LIKELY(pGuestPDPT))
|
---|
3957 | {
|
---|
3958 | const unsigned iPdpt = (GCPtr >> X86_PDPT_SHIFT) & X86_PDPT_MASK_PAE;
|
---|
3959 | if (pGuestPDPT->a[iPdpt].n.u1Present)
|
---|
3960 | {
|
---|
3961 | const unsigned iPD = (GCPtr >> X86_PD_PAE_SHIFT) & X86_PD_PAE_MASK;
|
---|
3962 | #ifdef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
|
---|
3963 | PX86PDPAE pGuestPD = NULL;
|
---|
3964 | int rc = pgmR0DynMapGCPageInlined(PGMCPU2PGM(pPGM), pGuestPDPT->a[iPdpt].u & X86_PDPE_PG_MASK, (void **)&pGuestPD);
|
---|
3965 | AssertRCReturn(rc, ZeroPde);
|
---|
3966 | #else
|
---|
3967 | PX86PDPAE pGuestPD = pPGM->CTX_SUFF(apGstPaePDs)[iPdpt];
|
---|
3968 | if ( !pGuestPD
|
---|
3969 | || (pGuestPDPT->a[iPdpt].u & X86_PDPE_PG_MASK) != pPGM->aGCPhysGstPaePDs[iPdpt])
|
---|
3970 | pGuestPD = pgmGstLazyMapPaePD(pPGM, iPdpt);
|
---|
3971 | #endif
|
---|
3972 | return pGuestPD->a[iPD];
|
---|
3973 | }
|
---|
3974 | }
|
---|
3975 | return ZeroPde;
|
---|
3976 | }
|
---|
3977 |
|
---|
3978 |
|
---|
3979 | /**
|
---|
3980 | * Gets the page directory pointer table entry for the specified address
|
---|
3981 | * and returns the index into the page directory
|
---|
3982 | *
|
---|
3983 | * @returns Pointer to the page directory in question.
|
---|
3984 | * @returns NULL if the page directory is not present or on an invalid page.
|
---|
3985 | * @param pPGM Pointer to the PGM instance data.
|
---|
3986 | * @param GCPtr The address.
|
---|
3987 | * @param piPD Receives the index into the returned page directory
|
---|
3988 | * @param pPdpe Receives the page directory pointer entry. Optional.
|
---|
3989 | */
|
---|
3990 | DECLINLINE(PX86PDPAE) pgmGstGetPaePDPtr(PPGMCPU pPGM, RTGCPTR GCPtr, unsigned *piPD, PX86PDPE pPdpe)
|
---|
3991 | {
|
---|
3992 | AssertGCPtr32(GCPtr);
|
---|
3993 |
|
---|
3994 | PX86PDPT pGuestPDPT = pgmGstGetPaePDPTPtr(pPGM);
|
---|
3995 | AssertReturn(pGuestPDPT, NULL);
|
---|
3996 | const unsigned iPdpt = (GCPtr >> X86_PDPT_SHIFT) & X86_PDPT_MASK_PAE;
|
---|
3997 | if (pPdpe)
|
---|
3998 | *pPdpe = pGuestPDPT->a[iPdpt];
|
---|
3999 | if (pGuestPDPT->a[iPdpt].n.u1Present)
|
---|
4000 | {
|
---|
4001 | const unsigned iPD = (GCPtr >> X86_PD_PAE_SHIFT) & X86_PD_PAE_MASK;
|
---|
4002 | #ifdef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
|
---|
4003 | PX86PDPAE pGuestPD = NULL;
|
---|
4004 | int rc = pgmR0DynMapGCPageInlined(PGMCPU2PGM(pPGM), pGuestPDPT->a[iPdpt].u & X86_PDPE_PG_MASK, (void **)&pGuestPD);
|
---|
4005 | AssertRCReturn(rc, NULL);
|
---|
4006 | #else
|
---|
4007 | PX86PDPAE pGuestPD = pPGM->CTX_SUFF(apGstPaePDs)[iPdpt];
|
---|
4008 | if ( !pGuestPD
|
---|
4009 | || (pGuestPDPT->a[iPdpt].u & X86_PDPE_PG_MASK) != pPGM->aGCPhysGstPaePDs[iPdpt])
|
---|
4010 | pGuestPD = pgmGstLazyMapPaePD(pPGM, iPdpt);
|
---|
4011 | #endif
|
---|
4012 | *piPD = iPD;
|
---|
4013 | return pGuestPD;
|
---|
4014 | /* returning NIL_RTGCPHYS is ok if we assume it's just an invalid page of some kind emulated as all 0s. */
|
---|
4015 | }
|
---|
4016 | return NULL;
|
---|
4017 | }
|
---|
4018 |
|
---|
4019 | #ifndef IN_RC
|
---|
4020 |
|
---|
4021 | /**
|
---|
4022 | * Gets the page map level-4 pointer for the guest.
|
---|
4023 | *
|
---|
4024 | * @returns Pointer to the PML4 page.
|
---|
4025 | * @param pPGM Pointer to the PGM instance data.
|
---|
4026 | */
|
---|
4027 | DECLINLINE(PX86PML4) pgmGstGetLongModePML4Ptr(PPGMCPU pPGM)
|
---|
4028 | {
|
---|
4029 | #ifdef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
|
---|
4030 | PX86PML4 pGuestPml4;
|
---|
4031 | int rc = pgmR0DynMapGCPageInlined(PGMCPU2PGM(pPGM), pPGM->GCPhysCR3, (void **)&pGuestPml4);
|
---|
4032 | AssertRCReturn(rc, NULL);
|
---|
4033 | #else
|
---|
4034 | PX86PML4 pGuestPml4 = pPGM->CTX_SUFF(pGstAmd64Pml4);
|
---|
4035 | # ifdef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R3
|
---|
4036 | if (!pGuestPml4)
|
---|
4037 | pGuestPml4 = pgmGstLazyMapPml4(pPGM);
|
---|
4038 | # endif
|
---|
4039 | Assert(pGuestPml4);
|
---|
4040 | #endif
|
---|
4041 | return pGuestPml4;
|
---|
4042 | }
|
---|
4043 |
|
---|
4044 |
|
---|
4045 | /**
|
---|
4046 | * Gets the pointer to a page map level-4 entry.
|
---|
4047 | *
|
---|
4048 | * @returns Pointer to the PML4 entry.
|
---|
4049 | * @param pPGM Pointer to the PGM instance data.
|
---|
4050 | * @param iPml4 The index.
|
---|
4051 | */
|
---|
4052 | DECLINLINE(PX86PML4E) pgmGstGetLongModePML4EPtr(PPGMCPU pPGM, unsigned int iPml4)
|
---|
4053 | {
|
---|
4054 | #ifdef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
|
---|
4055 | PX86PML4 pGuestPml4;
|
---|
4056 | int rc = pgmR0DynMapGCPageInlined(PGMCPU2PGM(pPGM), pPGM->GCPhysCR3, (void **)&pGuestPml4);
|
---|
4057 | AssertRCReturn(rc, NULL);
|
---|
4058 | #else
|
---|
4059 | PX86PML4 pGuestPml4 = pPGM->CTX_SUFF(pGstAmd64Pml4);
|
---|
4060 | # ifdef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R3
|
---|
4061 | if (!pGuestPml4)
|
---|
4062 | pGuestPml4 = pgmGstLazyMapPml4(pPGM);
|
---|
4063 | # endif
|
---|
4064 | Assert(pGuestPml4);
|
---|
4065 | #endif
|
---|
4066 | return &pGuestPml4->a[iPml4];
|
---|
4067 | }
|
---|
4068 |
|
---|
4069 |
|
---|
4070 | /**
|
---|
4071 | * Gets a page map level-4 entry.
|
---|
4072 | *
|
---|
4073 | * @returns The PML4 entry.
|
---|
4074 | * @param pPGM Pointer to the PGM instance data.
|
---|
4075 | * @param iPml4 The index.
|
---|
4076 | */
|
---|
4077 | DECLINLINE(X86PML4E) pgmGstGetLongModePML4E(PPGMCPU pPGM, unsigned int iPml4)
|
---|
4078 | {
|
---|
4079 | #ifdef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
|
---|
4080 | PX86PML4 pGuestPml4;
|
---|
4081 | int rc = pgmR0DynMapGCPageInlined(PGMCPU2PGM(pPGM), pPGM->GCPhysCR3, (void **)&pGuestPml4);
|
---|
4082 | if (RT_FAILURE(rc))
|
---|
4083 | {
|
---|
4084 | X86PML4E ZeroPml4e = {0};
|
---|
4085 | AssertMsgFailedReturn(("%Rrc\n", rc), ZeroPml4e);
|
---|
4086 | }
|
---|
4087 | #else
|
---|
4088 | PX86PML4 pGuestPml4 = pPGM->CTX_SUFF(pGstAmd64Pml4);
|
---|
4089 | # ifdef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R3
|
---|
4090 | if (!pGuestPml4)
|
---|
4091 | pGuestPml4 = pgmGstLazyMapPml4(pPGM);
|
---|
4092 | # endif
|
---|
4093 | Assert(pGuestPml4);
|
---|
4094 | #endif
|
---|
4095 | return pGuestPml4->a[iPml4];
|
---|
4096 | }
|
---|
4097 |
|
---|
4098 |
|
---|
4099 | /**
|
---|
4100 | * Gets the page directory pointer entry for the specified address.
|
---|
4101 | *
|
---|
4102 | * @returns Pointer to the page directory pointer entry in question.
|
---|
4103 | * @returns NULL if the page directory is not present or on an invalid page.
|
---|
4104 | * @param pPGM Pointer to the PGM instance data.
|
---|
4105 | * @param GCPtr The address.
|
---|
4106 | * @param ppPml4e Page Map Level-4 Entry (out)
|
---|
4107 | */
|
---|
4108 | DECLINLINE(PX86PDPE) pgmGstGetLongModePDPTPtr(PPGMCPU pPGM, RTGCPTR64 GCPtr, PX86PML4E *ppPml4e)
|
---|
4109 | {
|
---|
4110 | PX86PML4 pGuestPml4 = pgmGstGetLongModePML4Ptr(pPGM);
|
---|
4111 | const unsigned iPml4 = (GCPtr >> X86_PML4_SHIFT) & X86_PML4_MASK;
|
---|
4112 | PCX86PML4E pPml4e = *ppPml4e = &pGuestPml4->a[iPml4];
|
---|
4113 | if (pPml4e->n.u1Present)
|
---|
4114 | {
|
---|
4115 | PX86PDPT pPdpt;
|
---|
4116 | int rc = PGM_GCPHYS_2_PTR_BY_PGMCPU(pPGM, pPml4e->u & X86_PML4E_PG_MASK, &pPdpt);
|
---|
4117 | AssertRCReturn(rc, NULL);
|
---|
4118 |
|
---|
4119 | const unsigned iPdpt = (GCPtr >> X86_PDPT_SHIFT) & X86_PDPT_MASK_AMD64;
|
---|
4120 | return &pPdpt->a[iPdpt];
|
---|
4121 | }
|
---|
4122 | return NULL;
|
---|
4123 | }
|
---|
4124 |
|
---|
4125 |
|
---|
4126 | /**
|
---|
4127 | * Gets the page directory entry for the specified address.
|
---|
4128 | *
|
---|
4129 | * @returns The page directory entry in question.
|
---|
4130 | * @returns A non-present entry if the page directory is not present or on an invalid page.
|
---|
4131 | * @param pPGM Pointer to the PGM instance data.
|
---|
4132 | * @param GCPtr The address.
|
---|
4133 | * @param ppPml4e Page Map Level-4 Entry (out)
|
---|
4134 | * @param pPdpe Page directory pointer table entry (out)
|
---|
4135 | */
|
---|
4136 | DECLINLINE(X86PDEPAE) pgmGstGetLongModePDEEx(PPGMCPU pPGM, RTGCPTR64 GCPtr, PX86PML4E *ppPml4e, PX86PDPE pPdpe)
|
---|
4137 | {
|
---|
4138 | X86PDEPAE ZeroPde = {0};
|
---|
4139 | PX86PML4 pGuestPml4 = pgmGstGetLongModePML4Ptr(pPGM);
|
---|
4140 | const unsigned iPml4 = (GCPtr >> X86_PML4_SHIFT) & X86_PML4_MASK;
|
---|
4141 | PCX86PML4E pPml4e = *ppPml4e = &pGuestPml4->a[iPml4];
|
---|
4142 | if (pPml4e->n.u1Present)
|
---|
4143 | {
|
---|
4144 | PCX86PDPT pPdptTemp;
|
---|
4145 | int rc = PGM_GCPHYS_2_PTR_BY_PGMCPU(pPGM, pPml4e->u & X86_PML4E_PG_MASK, &pPdptTemp);
|
---|
4146 | AssertRCReturn(rc, ZeroPde);
|
---|
4147 |
|
---|
4148 | const unsigned iPdpt = (GCPtr >> X86_PDPT_SHIFT) & X86_PDPT_MASK_AMD64;
|
---|
4149 | *pPdpe = pPdptTemp->a[iPdpt];
|
---|
4150 | if (pPdptTemp->a[iPdpt].n.u1Present)
|
---|
4151 | {
|
---|
4152 | PCX86PDPAE pPD;
|
---|
4153 | rc = PGM_GCPHYS_2_PTR_BY_PGMCPU(pPGM, pPdptTemp->a[iPdpt].u & X86_PDPE_PG_MASK, &pPD);
|
---|
4154 | AssertRCReturn(rc, ZeroPde);
|
---|
4155 |
|
---|
4156 | const unsigned iPD = (GCPtr >> X86_PD_PAE_SHIFT) & X86_PD_PAE_MASK;
|
---|
4157 | return pPD->a[iPD];
|
---|
4158 | }
|
---|
4159 | }
|
---|
4160 |
|
---|
4161 | return ZeroPde;
|
---|
4162 | }
|
---|
4163 |
|
---|
4164 |
|
---|
4165 | /**
|
---|
4166 | * Gets the page directory entry for the specified address.
|
---|
4167 | *
|
---|
4168 | * @returns The page directory entry in question.
|
---|
4169 | * @returns A non-present entry if the page directory is not present or on an invalid page.
|
---|
4170 | * @param pPGM Pointer to the PGM instance data.
|
---|
4171 | * @param GCPtr The address.
|
---|
4172 | */
|
---|
4173 | DECLINLINE(X86PDEPAE) pgmGstGetLongModePDE(PPGMCPU pPGM, RTGCPTR64 GCPtr)
|
---|
4174 | {
|
---|
4175 | X86PDEPAE ZeroPde = {0};
|
---|
4176 | PCX86PML4 pGuestPml4 = pgmGstGetLongModePML4Ptr(pPGM);
|
---|
4177 | const unsigned iPml4 = (GCPtr >> X86_PML4_SHIFT) & X86_PML4_MASK;
|
---|
4178 | if (pGuestPml4->a[iPml4].n.u1Present)
|
---|
4179 | {
|
---|
4180 | PCX86PDPT pPdptTemp;
|
---|
4181 | int rc = PGM_GCPHYS_2_PTR_BY_PGMCPU(pPGM, pGuestPml4->a[iPml4].u & X86_PML4E_PG_MASK, &pPdptTemp);
|
---|
4182 | AssertRCReturn(rc, ZeroPde);
|
---|
4183 |
|
---|
4184 | const unsigned iPdpt = (GCPtr >> X86_PDPT_SHIFT) & X86_PDPT_MASK_AMD64;
|
---|
4185 | if (pPdptTemp->a[iPdpt].n.u1Present)
|
---|
4186 | {
|
---|
4187 | PCX86PDPAE pPD;
|
---|
4188 | rc = PGM_GCPHYS_2_PTR_BY_PGMCPU(pPGM, pPdptTemp->a[iPdpt].u & X86_PDPE_PG_MASK, &pPD);
|
---|
4189 | AssertRCReturn(rc, ZeroPde);
|
---|
4190 |
|
---|
4191 | const unsigned iPD = (GCPtr >> X86_PD_PAE_SHIFT) & X86_PD_PAE_MASK;
|
---|
4192 | return pPD->a[iPD];
|
---|
4193 | }
|
---|
4194 | }
|
---|
4195 | return ZeroPde;
|
---|
4196 | }
|
---|
4197 |
|
---|
4198 |
|
---|
4199 | /**
|
---|
4200 | * Gets the page directory entry for the specified address.
|
---|
4201 | *
|
---|
4202 | * @returns Pointer to the page directory entry in question.
|
---|
4203 | * @returns NULL if the page directory is not present or on an invalid page.
|
---|
4204 | * @param pPGM Pointer to the PGM instance data.
|
---|
4205 | * @param GCPtr The address.
|
---|
4206 | */
|
---|
4207 | DECLINLINE(PX86PDEPAE) pgmGstGetLongModePDEPtr(PPGMCPU pPGM, RTGCPTR64 GCPtr)
|
---|
4208 | {
|
---|
4209 | PCX86PML4 pGuestPml4 = pgmGstGetLongModePML4Ptr(pPGM);
|
---|
4210 | const unsigned iPml4 = (GCPtr >> X86_PML4_SHIFT) & X86_PML4_MASK;
|
---|
4211 | if (pGuestPml4->a[iPml4].n.u1Present)
|
---|
4212 | {
|
---|
4213 | PCX86PDPT pPdptTemp;
|
---|
4214 | int rc = PGM_GCPHYS_2_PTR_BY_PGMCPU(pPGM, pGuestPml4->a[iPml4].u & X86_PML4E_PG_MASK, &pPdptTemp);
|
---|
4215 | AssertRCReturn(rc, NULL);
|
---|
4216 |
|
---|
4217 | const unsigned iPdpt = (GCPtr >> X86_PDPT_SHIFT) & X86_PDPT_MASK_AMD64;
|
---|
4218 | if (pPdptTemp->a[iPdpt].n.u1Present)
|
---|
4219 | {
|
---|
4220 | PX86PDPAE pPD;
|
---|
4221 | rc = PGM_GCPHYS_2_PTR_BY_PGMCPU(pPGM, pPdptTemp->a[iPdpt].u & X86_PDPE_PG_MASK, &pPD);
|
---|
4222 | AssertRCReturn(rc, NULL);
|
---|
4223 |
|
---|
4224 | const unsigned iPD = (GCPtr >> X86_PD_PAE_SHIFT) & X86_PD_PAE_MASK;
|
---|
4225 | return &pPD->a[iPD];
|
---|
4226 | }
|
---|
4227 | }
|
---|
4228 | return NULL;
|
---|
4229 | }
|
---|
4230 |
|
---|
4231 |
|
---|
4232 | /**
|
---|
4233 | * Gets the GUEST page directory pointer for the specified address.
|
---|
4234 | *
|
---|
4235 | * @returns The page directory in question.
|
---|
4236 | * @returns NULL if the page directory is not present or on an invalid page.
|
---|
4237 | * @param pPGM Pointer to the PGM instance data.
|
---|
4238 | * @param GCPtr The address.
|
---|
4239 | * @param ppPml4e Page Map Level-4 Entry (out)
|
---|
4240 | * @param pPdpe Page directory pointer table entry (out)
|
---|
4241 | * @param piPD Receives the index into the returned page directory
|
---|
4242 | */
|
---|
4243 | DECLINLINE(PX86PDPAE) pgmGstGetLongModePDPtr(PPGMCPU pPGM, RTGCPTR64 GCPtr, PX86PML4E *ppPml4e, PX86PDPE pPdpe, unsigned *piPD)
|
---|
4244 | {
|
---|
4245 | PX86PML4 pGuestPml4 = pgmGstGetLongModePML4Ptr(pPGM);
|
---|
4246 | const unsigned iPml4 = (GCPtr >> X86_PML4_SHIFT) & X86_PML4_MASK;
|
---|
4247 | PCX86PML4E pPml4e = *ppPml4e = &pGuestPml4->a[iPml4];
|
---|
4248 | if (pPml4e->n.u1Present)
|
---|
4249 | {
|
---|
4250 | PCX86PDPT pPdptTemp;
|
---|
4251 | int rc = PGM_GCPHYS_2_PTR_BY_PGMCPU(pPGM, pPml4e->u & X86_PML4E_PG_MASK, &pPdptTemp);
|
---|
4252 | AssertRCReturn(rc, NULL);
|
---|
4253 |
|
---|
4254 | const unsigned iPdpt = (GCPtr >> X86_PDPT_SHIFT) & X86_PDPT_MASK_AMD64;
|
---|
4255 | *pPdpe = pPdptTemp->a[iPdpt];
|
---|
4256 | if (pPdptTemp->a[iPdpt].n.u1Present)
|
---|
4257 | {
|
---|
4258 | PX86PDPAE pPD;
|
---|
4259 | rc = PGM_GCPHYS_2_PTR_BY_PGMCPU(pPGM, pPdptTemp->a[iPdpt].u & X86_PDPE_PG_MASK, &pPD);
|
---|
4260 | AssertRCReturn(rc, NULL);
|
---|
4261 |
|
---|
4262 | *piPD = (GCPtr >> X86_PD_PAE_SHIFT) & X86_PD_PAE_MASK;
|
---|
4263 | return pPD;
|
---|
4264 | }
|
---|
4265 | }
|
---|
4266 | return 0;
|
---|
4267 | }
|
---|
4268 |
|
---|
4269 | #endif /* !IN_RC */
|
---|
4270 |
|
---|
4271 | /**
|
---|
4272 | * Gets the shadow page directory, 32-bit.
|
---|
4273 | *
|
---|
4274 | * @returns Pointer to the shadow 32-bit PD.
|
---|
4275 | * @param pPGM Pointer to the PGM instance data.
|
---|
4276 | */
|
---|
4277 | DECLINLINE(PX86PD) pgmShwGet32BitPDPtr(PPGMCPU pPGM)
|
---|
4278 | {
|
---|
4279 | return (PX86PD)PGMPOOL_PAGE_2_PTR_BY_PGMCPU(pPGM, pPGM->CTX_SUFF(pShwPageCR3));
|
---|
4280 | }
|
---|
4281 |
|
---|
4282 |
|
---|
4283 | /**
|
---|
4284 | * Gets the shadow page directory entry for the specified address, 32-bit.
|
---|
4285 | *
|
---|
4286 | * @returns Shadow 32-bit PDE.
|
---|
4287 | * @param pPGM Pointer to the PGM instance data.
|
---|
4288 | * @param GCPtr The address.
|
---|
4289 | */
|
---|
4290 | DECLINLINE(X86PDE) pgmShwGet32BitPDE(PPGMCPU pPGM, RTGCPTR GCPtr)
|
---|
4291 | {
|
---|
4292 | const unsigned iPd = (GCPtr >> X86_PD_SHIFT) & X86_PD_MASK;
|
---|
4293 |
|
---|
4294 | PX86PD pShwPde = pgmShwGet32BitPDPtr(pPGM);
|
---|
4295 | if (!pShwPde)
|
---|
4296 | {
|
---|
4297 | X86PDE ZeroPde = {0};
|
---|
4298 | return ZeroPde;
|
---|
4299 | }
|
---|
4300 | return pShwPde->a[iPd];
|
---|
4301 | }
|
---|
4302 |
|
---|
4303 |
|
---|
4304 | /**
|
---|
4305 | * Gets the pointer to the shadow page directory entry for the specified
|
---|
4306 | * address, 32-bit.
|
---|
4307 | *
|
---|
4308 | * @returns Pointer to the shadow 32-bit PDE.
|
---|
4309 | * @param pPGM Pointer to the PGM instance data.
|
---|
4310 | * @param GCPtr The address.
|
---|
4311 | */
|
---|
4312 | DECLINLINE(PX86PDE) pgmShwGet32BitPDEPtr(PPGMCPU pPGM, RTGCPTR GCPtr)
|
---|
4313 | {
|
---|
4314 | const unsigned iPd = (GCPtr >> X86_PD_SHIFT) & X86_PD_MASK;
|
---|
4315 |
|
---|
4316 | PX86PD pPde = pgmShwGet32BitPDPtr(pPGM);
|
---|
4317 | AssertReturn(pPde, NULL);
|
---|
4318 | return &pPde->a[iPd];
|
---|
4319 | }
|
---|
4320 |
|
---|
4321 |
|
---|
4322 | /**
|
---|
4323 | * Gets the shadow page pointer table, PAE.
|
---|
4324 | *
|
---|
4325 | * @returns Pointer to the shadow PAE PDPT.
|
---|
4326 | * @param pPGM Pointer to the PGM instance data.
|
---|
4327 | */
|
---|
4328 | DECLINLINE(PX86PDPT) pgmShwGetPaePDPTPtr(PPGMCPU pPGM)
|
---|
4329 | {
|
---|
4330 | return (PX86PDPT)PGMPOOL_PAGE_2_PTR_BY_PGMCPU(pPGM, pPGM->CTX_SUFF(pShwPageCR3));
|
---|
4331 | }
|
---|
4332 |
|
---|
4333 |
|
---|
4334 | /**
|
---|
4335 | * Gets the shadow page directory for the specified address, PAE.
|
---|
4336 | *
|
---|
4337 | * @returns Pointer to the shadow PD.
|
---|
4338 | * @param pPGM Pointer to the PGM instance data.
|
---|
4339 | * @param GCPtr The address.
|
---|
4340 | */
|
---|
4341 | DECLINLINE(PX86PDPAE) pgmShwGetPaePDPtr(PPGMCPU pPGM, RTGCPTR GCPtr)
|
---|
4342 | {
|
---|
4343 | const unsigned iPdpt = (GCPtr >> X86_PDPT_SHIFT) & X86_PDPT_MASK_PAE;
|
---|
4344 | PX86PDPT pPdpt = pgmShwGetPaePDPTPtr(pPGM);
|
---|
4345 |
|
---|
4346 | if (!pPdpt->a[iPdpt].n.u1Present)
|
---|
4347 | return NULL;
|
---|
4348 |
|
---|
4349 | /* Fetch the pgm pool shadow descriptor. */
|
---|
4350 | PPGMPOOLPAGE pShwPde = pgmPoolGetPage(PGMCPU2PGM(pPGM)->CTX_SUFF(pPool), pPdpt->a[iPdpt].u & X86_PDPE_PG_MASK);
|
---|
4351 | AssertReturn(pShwPde, NULL);
|
---|
4352 |
|
---|
4353 | return (PX86PDPAE)PGMPOOL_PAGE_2_PTR_BY_PGMCPU(pPGM, pShwPde);
|
---|
4354 | }
|
---|
4355 |
|
---|
4356 |
|
---|
4357 | /**
|
---|
4358 | * Gets the shadow page directory for the specified address, PAE.
|
---|
4359 | *
|
---|
4360 | * @returns Pointer to the shadow PD.
|
---|
4361 | * @param pPGM Pointer to the PGM instance data.
|
---|
4362 | * @param GCPtr The address.
|
---|
4363 | */
|
---|
4364 | DECLINLINE(PX86PDPAE) pgmShwGetPaePDPtr(PPGMCPU pPGM, PX86PDPT pPdpt, RTGCPTR GCPtr)
|
---|
4365 | {
|
---|
4366 | const unsigned iPdpt = (GCPtr >> X86_PDPT_SHIFT) & X86_PDPT_MASK_PAE;
|
---|
4367 |
|
---|
4368 | if (!pPdpt->a[iPdpt].n.u1Present)
|
---|
4369 | return NULL;
|
---|
4370 |
|
---|
4371 | /* Fetch the pgm pool shadow descriptor. */
|
---|
4372 | PPGMPOOLPAGE pShwPde = pgmPoolGetPage(PGMCPU2PGM(pPGM)->CTX_SUFF(pPool), pPdpt->a[iPdpt].u & X86_PDPE_PG_MASK);
|
---|
4373 | AssertReturn(pShwPde, NULL);
|
---|
4374 |
|
---|
4375 | return (PX86PDPAE)PGMPOOL_PAGE_2_PTR_BY_PGMCPU(pPGM, pShwPde);
|
---|
4376 | }
|
---|
4377 |
|
---|
4378 |
|
---|
4379 | /**
|
---|
4380 | * Gets the shadow page directory entry, PAE.
|
---|
4381 | *
|
---|
4382 | * @returns PDE.
|
---|
4383 | * @param pPGM Pointer to the PGM instance data.
|
---|
4384 | * @param GCPtr The address.
|
---|
4385 | */
|
---|
4386 | DECLINLINE(X86PDEPAE) pgmShwGetPaePDE(PPGMCPU pPGM, RTGCPTR GCPtr)
|
---|
4387 | {
|
---|
4388 | const unsigned iPd = (GCPtr >> X86_PD_PAE_SHIFT) & X86_PD_PAE_MASK;
|
---|
4389 |
|
---|
4390 | PX86PDPAE pShwPde = pgmShwGetPaePDPtr(pPGM, GCPtr);
|
---|
4391 | if (!pShwPde)
|
---|
4392 | {
|
---|
4393 | X86PDEPAE ZeroPde = {0};
|
---|
4394 | return ZeroPde;
|
---|
4395 | }
|
---|
4396 | return pShwPde->a[iPd];
|
---|
4397 | }
|
---|
4398 |
|
---|
4399 |
|
---|
4400 | /**
|
---|
4401 | * Gets the pointer to the shadow page directory entry for an address, PAE.
|
---|
4402 | *
|
---|
4403 | * @returns Pointer to the PDE.
|
---|
4404 | * @param pPGM Pointer to the PGM instance data.
|
---|
4405 | * @param GCPtr The address.
|
---|
4406 | */
|
---|
4407 | DECLINLINE(PX86PDEPAE) pgmShwGetPaePDEPtr(PPGMCPU pPGM, RTGCPTR GCPtr)
|
---|
4408 | {
|
---|
4409 | const unsigned iPd = (GCPtr >> X86_PD_PAE_SHIFT) & X86_PD_PAE_MASK;
|
---|
4410 |
|
---|
4411 | PX86PDPAE pPde = pgmShwGetPaePDPtr(pPGM, GCPtr);
|
---|
4412 | AssertReturn(pPde, NULL);
|
---|
4413 | return &pPde->a[iPd];
|
---|
4414 | }
|
---|
4415 |
|
---|
4416 | #ifndef IN_RC
|
---|
4417 |
|
---|
4418 | /**
|
---|
4419 | * Gets the shadow page map level-4 pointer.
|
---|
4420 | *
|
---|
4421 | * @returns Pointer to the shadow PML4.
|
---|
4422 | * @param pPGM Pointer to the PGM instance data.
|
---|
4423 | */
|
---|
4424 | DECLINLINE(PX86PML4) pgmShwGetLongModePML4Ptr(PPGMCPU pPGM)
|
---|
4425 | {
|
---|
4426 | return (PX86PML4)PGMPOOL_PAGE_2_PTR_BY_PGMCPU(pPGM, pPGM->CTX_SUFF(pShwPageCR3));
|
---|
4427 | }
|
---|
4428 |
|
---|
4429 |
|
---|
4430 | /**
|
---|
4431 | * Gets the shadow page map level-4 entry for the specified address.
|
---|
4432 | *
|
---|
4433 | * @returns The entry.
|
---|
4434 | * @param pPGM Pointer to the PGM instance data.
|
---|
4435 | * @param GCPtr The address.
|
---|
4436 | */
|
---|
4437 | DECLINLINE(X86PML4E) pgmShwGetLongModePML4E(PPGMCPU pPGM, RTGCPTR GCPtr)
|
---|
4438 | {
|
---|
4439 | const unsigned iPml4 = ((RTGCUINTPTR64)GCPtr >> X86_PML4_SHIFT) & X86_PML4_MASK;
|
---|
4440 | PX86PML4 pShwPml4 = pgmShwGetLongModePML4Ptr(pPGM);
|
---|
4441 |
|
---|
4442 | if (!pShwPml4)
|
---|
4443 | {
|
---|
4444 | X86PML4E ZeroPml4e = {0};
|
---|
4445 | return ZeroPml4e;
|
---|
4446 | }
|
---|
4447 | return pShwPml4->a[iPml4];
|
---|
4448 | }
|
---|
4449 |
|
---|
4450 |
|
---|
4451 | /**
|
---|
4452 | * Gets the pointer to the specified shadow page map level-4 entry.
|
---|
4453 | *
|
---|
4454 | * @returns The entry.
|
---|
4455 | * @param pPGM Pointer to the PGM instance data.
|
---|
4456 | * @param iPml4 The PML4 index.
|
---|
4457 | */
|
---|
4458 | DECLINLINE(PX86PML4E) pgmShwGetLongModePML4EPtr(PPGMCPU pPGM, unsigned int iPml4)
|
---|
4459 | {
|
---|
4460 | PX86PML4 pShwPml4 = pgmShwGetLongModePML4Ptr(pPGM);
|
---|
4461 | if (!pShwPml4)
|
---|
4462 | return NULL;
|
---|
4463 | return &pShwPml4->a[iPml4];
|
---|
4464 | }
|
---|
4465 |
|
---|
4466 |
|
---|
4467 | /**
|
---|
4468 | * Gets the GUEST page directory pointer for the specified address.
|
---|
4469 | *
|
---|
4470 | * @returns The page directory in question.
|
---|
4471 | * @returns NULL if the page directory is not present or on an invalid page.
|
---|
4472 | * @param pPGM Pointer to the PGM instance data.
|
---|
4473 | * @param GCPtr The address.
|
---|
4474 | * @param piPD Receives the index into the returned page directory
|
---|
4475 | */
|
---|
4476 | DECLINLINE(PX86PDPAE) pgmGstGetLongModePDPtr(PPGMCPU pPGM, RTGCPTR64 GCPtr, unsigned *piPD)
|
---|
4477 | {
|
---|
4478 | PCX86PML4 pGuestPml4 = pgmGstGetLongModePML4Ptr(pPGM);
|
---|
4479 | const unsigned iPml4 = (GCPtr >> X86_PML4_SHIFT) & X86_PML4_MASK;
|
---|
4480 | if (pGuestPml4->a[iPml4].n.u1Present)
|
---|
4481 | {
|
---|
4482 | PCX86PDPT pPdptTemp;
|
---|
4483 | int rc = PGM_GCPHYS_2_PTR_BY_PGMCPU(pPGM, pGuestPml4->a[iPml4].u & X86_PML4E_PG_MASK, &pPdptTemp);
|
---|
4484 | AssertRCReturn(rc, NULL);
|
---|
4485 |
|
---|
4486 | const unsigned iPdpt = (GCPtr >> X86_PDPT_SHIFT) & X86_PDPT_MASK_AMD64;
|
---|
4487 | if (pPdptTemp->a[iPdpt].n.u1Present)
|
---|
4488 | {
|
---|
4489 | PX86PDPAE pPD;
|
---|
4490 | rc = PGM_GCPHYS_2_PTR_BY_PGMCPU(pPGM, pPdptTemp->a[iPdpt].u & X86_PDPE_PG_MASK, &pPD);
|
---|
4491 | AssertRCReturn(rc, NULL);
|
---|
4492 |
|
---|
4493 | *piPD = (GCPtr >> X86_PD_PAE_SHIFT) & X86_PD_PAE_MASK;
|
---|
4494 | return pPD;
|
---|
4495 | }
|
---|
4496 | }
|
---|
4497 | return NULL;
|
---|
4498 | }
|
---|
4499 |
|
---|
4500 | #endif /* !IN_RC */
|
---|
4501 |
|
---|
4502 | /**
|
---|
4503 | * Gets the page state for a physical handler.
|
---|
4504 | *
|
---|
4505 | * @returns The physical handler page state.
|
---|
4506 | * @param pCur The physical handler in question.
|
---|
4507 | */
|
---|
4508 | DECLINLINE(unsigned) pgmHandlerPhysicalCalcState(PPGMPHYSHANDLER pCur)
|
---|
4509 | {
|
---|
4510 | switch (pCur->enmType)
|
---|
4511 | {
|
---|
4512 | case PGMPHYSHANDLERTYPE_PHYSICAL_WRITE:
|
---|
4513 | return PGM_PAGE_HNDL_PHYS_STATE_WRITE;
|
---|
4514 |
|
---|
4515 | case PGMPHYSHANDLERTYPE_MMIO:
|
---|
4516 | case PGMPHYSHANDLERTYPE_PHYSICAL_ALL:
|
---|
4517 | return PGM_PAGE_HNDL_PHYS_STATE_ALL;
|
---|
4518 |
|
---|
4519 | default:
|
---|
4520 | AssertFatalMsgFailed(("Invalid type %d\n", pCur->enmType));
|
---|
4521 | }
|
---|
4522 | }
|
---|
4523 |
|
---|
4524 |
|
---|
4525 | /**
|
---|
4526 | * Gets the page state for a virtual handler.
|
---|
4527 | *
|
---|
4528 | * @returns The virtual handler page state.
|
---|
4529 | * @param pCur The virtual handler in question.
|
---|
4530 | * @remarks This should never be used on a hypervisor access handler.
|
---|
4531 | */
|
---|
4532 | DECLINLINE(unsigned) pgmHandlerVirtualCalcState(PPGMVIRTHANDLER pCur)
|
---|
4533 | {
|
---|
4534 | switch (pCur->enmType)
|
---|
4535 | {
|
---|
4536 | case PGMVIRTHANDLERTYPE_WRITE:
|
---|
4537 | return PGM_PAGE_HNDL_VIRT_STATE_WRITE;
|
---|
4538 | case PGMVIRTHANDLERTYPE_ALL:
|
---|
4539 | return PGM_PAGE_HNDL_VIRT_STATE_ALL;
|
---|
4540 | default:
|
---|
4541 | AssertFatalMsgFailed(("Invalid type %d\n", pCur->enmType));
|
---|
4542 | }
|
---|
4543 | }
|
---|
4544 |
|
---|
4545 |
|
---|
4546 | /**
|
---|
4547 | * Clears one physical page of a virtual handler
|
---|
4548 | *
|
---|
4549 | * @param pPGM Pointer to the PGM instance.
|
---|
4550 | * @param pCur Virtual handler structure
|
---|
4551 | * @param iPage Physical page index
|
---|
4552 | *
|
---|
4553 | * @remark Only used when PGM_SYNC_UPDATE_PAGE_BIT_VIRTUAL is being set, so no
|
---|
4554 | * need to care about other handlers in the same page.
|
---|
4555 | */
|
---|
4556 | DECLINLINE(void) pgmHandlerVirtualClearPage(PPGM pPGM, PPGMVIRTHANDLER pCur, unsigned iPage)
|
---|
4557 | {
|
---|
4558 | const PPGMPHYS2VIRTHANDLER pPhys2Virt = &pCur->aPhysToVirt[iPage];
|
---|
4559 |
|
---|
4560 | /*
|
---|
4561 | * Remove the node from the tree (it's supposed to be in the tree if we get here!).
|
---|
4562 | */
|
---|
4563 | #ifdef VBOX_STRICT_PGM_HANDLER_VIRTUAL
|
---|
4564 | AssertReleaseMsg(pPhys2Virt->offNextAlias & PGMPHYS2VIRTHANDLER_IN_TREE,
|
---|
4565 | ("pPhys2Virt=%p:{.Core.Key=%RGp, .Core.KeyLast=%RGp, .offVirtHandler=%#RX32, .offNextAlias=%#RX32}\n",
|
---|
4566 | pPhys2Virt, pPhys2Virt->Core.Key, pPhys2Virt->Core.KeyLast, pPhys2Virt->offVirtHandler, pPhys2Virt->offNextAlias));
|
---|
4567 | #endif
|
---|
4568 | if (pPhys2Virt->offNextAlias & PGMPHYS2VIRTHANDLER_IS_HEAD)
|
---|
4569 | {
|
---|
4570 | /* We're the head of the alias chain. */
|
---|
4571 | PPGMPHYS2VIRTHANDLER pRemove = (PPGMPHYS2VIRTHANDLER)RTAvlroGCPhysRemove(&pPGM->CTX_SUFF(pTrees)->PhysToVirtHandlers, pPhys2Virt->Core.Key); NOREF(pRemove);
|
---|
4572 | #ifdef VBOX_STRICT_PGM_HANDLER_VIRTUAL
|
---|
4573 | AssertReleaseMsg(pRemove != NULL,
|
---|
4574 | ("pPhys2Virt=%p:{.Core.Key=%RGp, .Core.KeyLast=%RGp, .offVirtHandler=%#RX32, .offNextAlias=%#RX32}\n",
|
---|
4575 | pPhys2Virt, pPhys2Virt->Core.Key, pPhys2Virt->Core.KeyLast, pPhys2Virt->offVirtHandler, pPhys2Virt->offNextAlias));
|
---|
4576 | AssertReleaseMsg(pRemove == pPhys2Virt,
|
---|
4577 | ("wanted: pPhys2Virt=%p:{.Core.Key=%RGp, .Core.KeyLast=%RGp, .offVirtHandler=%#RX32, .offNextAlias=%#RX32}\n"
|
---|
4578 | " got: pRemove=%p:{.Core.Key=%RGp, .Core.KeyLast=%RGp, .offVirtHandler=%#RX32, .offNextAlias=%#RX32}\n",
|
---|
4579 | pPhys2Virt, pPhys2Virt->Core.Key, pPhys2Virt->Core.KeyLast, pPhys2Virt->offVirtHandler, pPhys2Virt->offNextAlias,
|
---|
4580 | pRemove, pRemove->Core.Key, pRemove->Core.KeyLast, pRemove->offVirtHandler, pRemove->offNextAlias));
|
---|
4581 | #endif
|
---|
4582 | if (pPhys2Virt->offNextAlias & PGMPHYS2VIRTHANDLER_OFF_MASK)
|
---|
4583 | {
|
---|
4584 | /* Insert the next list in the alias chain into the tree. */
|
---|
4585 | PPGMPHYS2VIRTHANDLER pNext = (PPGMPHYS2VIRTHANDLER)((intptr_t)pPhys2Virt + (pPhys2Virt->offNextAlias & PGMPHYS2VIRTHANDLER_OFF_MASK));
|
---|
4586 | #ifdef VBOX_STRICT_PGM_HANDLER_VIRTUAL
|
---|
4587 | AssertReleaseMsg(pNext->offNextAlias & PGMPHYS2VIRTHANDLER_IN_TREE,
|
---|
4588 | ("pNext=%p:{.Core.Key=%RGp, .Core.KeyLast=%RGp, .offVirtHandler=%#RX32, .offNextAlias=%#RX32}\n",
|
---|
4589 | pNext, pNext->Core.Key, pNext->Core.KeyLast, pNext->offVirtHandler, pNext->offNextAlias));
|
---|
4590 | #endif
|
---|
4591 | pNext->offNextAlias |= PGMPHYS2VIRTHANDLER_IS_HEAD;
|
---|
4592 | bool fRc = RTAvlroGCPhysInsert(&pPGM->CTX_SUFF(pTrees)->PhysToVirtHandlers, &pNext->Core);
|
---|
4593 | AssertRelease(fRc);
|
---|
4594 | }
|
---|
4595 | }
|
---|
4596 | else
|
---|
4597 | {
|
---|
4598 | /* Locate the previous node in the alias chain. */
|
---|
4599 | PPGMPHYS2VIRTHANDLER pPrev = (PPGMPHYS2VIRTHANDLER)RTAvlroGCPhysGet(&pPGM->CTX_SUFF(pTrees)->PhysToVirtHandlers, pPhys2Virt->Core.Key);
|
---|
4600 | #ifdef VBOX_STRICT_PGM_HANDLER_VIRTUAL
|
---|
4601 | AssertReleaseMsg(pPrev != pPhys2Virt,
|
---|
4602 | ("pPhys2Virt=%p:{.Core.Key=%RGp, .Core.KeyLast=%RGp, .offVirtHandler=%#RX32, .offNextAlias=%#RX32} pPrev=%p\n",
|
---|
4603 | pPhys2Virt, pPhys2Virt->Core.Key, pPhys2Virt->Core.KeyLast, pPhys2Virt->offVirtHandler, pPhys2Virt->offNextAlias, pPrev));
|
---|
4604 | #endif
|
---|
4605 | for (;;)
|
---|
4606 | {
|
---|
4607 | PPGMPHYS2VIRTHANDLER pNext = (PPGMPHYS2VIRTHANDLER)((intptr_t)pPrev + (pPrev->offNextAlias & PGMPHYS2VIRTHANDLER_OFF_MASK));
|
---|
4608 | if (pNext == pPhys2Virt)
|
---|
4609 | {
|
---|
4610 | /* unlink. */
|
---|
4611 | LogFlow(("pgmHandlerVirtualClearPage: removed %p:{.offNextAlias=%#RX32} from alias chain. prev %p:{.offNextAlias=%#RX32} [%RGp-%RGp]\n",
|
---|
4612 | pPhys2Virt, pPhys2Virt->offNextAlias, pPrev, pPrev->offNextAlias, pPhys2Virt->Core.Key, pPhys2Virt->Core.KeyLast));
|
---|
4613 | if (!(pPhys2Virt->offNextAlias & PGMPHYS2VIRTHANDLER_OFF_MASK))
|
---|
4614 | pPrev->offNextAlias &= ~PGMPHYS2VIRTHANDLER_OFF_MASK;
|
---|
4615 | else
|
---|
4616 | {
|
---|
4617 | PPGMPHYS2VIRTHANDLER pNewNext = (PPGMPHYS2VIRTHANDLER)((intptr_t)pPhys2Virt + (pPhys2Virt->offNextAlias & PGMPHYS2VIRTHANDLER_OFF_MASK));
|
---|
4618 | pPrev->offNextAlias = ((intptr_t)pNewNext - (intptr_t)pPrev)
|
---|
4619 | | (pPrev->offNextAlias & ~PGMPHYS2VIRTHANDLER_OFF_MASK);
|
---|
4620 | }
|
---|
4621 | break;
|
---|
4622 | }
|
---|
4623 |
|
---|
4624 | /* next */
|
---|
4625 | if (pNext == pPrev)
|
---|
4626 | {
|
---|
4627 | #ifdef VBOX_STRICT_PGM_HANDLER_VIRTUAL
|
---|
4628 | AssertReleaseMsg(pNext != pPrev,
|
---|
4629 | ("pPhys2Virt=%p:{.Core.Key=%RGp, .Core.KeyLast=%RGp, .offVirtHandler=%#RX32, .offNextAlias=%#RX32} pPrev=%p\n",
|
---|
4630 | pPhys2Virt, pPhys2Virt->Core.Key, pPhys2Virt->Core.KeyLast, pPhys2Virt->offVirtHandler, pPhys2Virt->offNextAlias, pPrev));
|
---|
4631 | #endif
|
---|
4632 | break;
|
---|
4633 | }
|
---|
4634 | pPrev = pNext;
|
---|
4635 | }
|
---|
4636 | }
|
---|
4637 | Log2(("PHYS2VIRT: Removing %RGp-%RGp %#RX32 %s\n",
|
---|
4638 | pPhys2Virt->Core.Key, pPhys2Virt->Core.KeyLast, pPhys2Virt->offNextAlias, R3STRING(pCur->pszDesc)));
|
---|
4639 | pPhys2Virt->offNextAlias = 0;
|
---|
4640 | pPhys2Virt->Core.KeyLast = NIL_RTGCPHYS; /* require reinsert */
|
---|
4641 |
|
---|
4642 | /*
|
---|
4643 | * Clear the ram flags for this page.
|
---|
4644 | */
|
---|
4645 | PPGMPAGE pPage = pgmPhysGetPage(pPGM, pPhys2Virt->Core.Key);
|
---|
4646 | AssertReturnVoid(pPage);
|
---|
4647 | PGM_PAGE_SET_HNDL_VIRT_STATE(pPage, PGM_PAGE_HNDL_VIRT_STATE_NONE);
|
---|
4648 | }
|
---|
4649 |
|
---|
4650 |
|
---|
4651 | /**
|
---|
4652 | * Internal worker for finding a 'in-use' shadow page give by it's physical address.
|
---|
4653 | *
|
---|
4654 | * @returns Pointer to the shadow page structure.
|
---|
4655 | * @param pPool The pool.
|
---|
4656 | * @param idx The pool page index.
|
---|
4657 | */
|
---|
4658 | DECLINLINE(PPGMPOOLPAGE) pgmPoolGetPageByIdx(PPGMPOOL pPool, unsigned idx)
|
---|
4659 | {
|
---|
4660 | AssertFatalMsg(idx >= PGMPOOL_IDX_FIRST && idx < pPool->cCurPages, ("idx=%d\n", idx));
|
---|
4661 | return &pPool->aPages[idx];
|
---|
4662 | }
|
---|
4663 |
|
---|
4664 |
|
---|
4665 | #ifdef PGMPOOL_WITH_GCPHYS_TRACKING
|
---|
4666 | /**
|
---|
4667 | * Clear references to guest physical memory.
|
---|
4668 | *
|
---|
4669 | * @param pPool The pool.
|
---|
4670 | * @param pPoolPage The pool page.
|
---|
4671 | * @param pPhysPage The physical guest page tracking structure.
|
---|
4672 | */
|
---|
4673 | DECLINLINE(void) pgmTrackDerefGCPhys(PPGMPOOL pPool, PPGMPOOLPAGE pPoolPage, PPGMPAGE pPhysPage)
|
---|
4674 | {
|
---|
4675 | /*
|
---|
4676 | * Just deal with the simple case here.
|
---|
4677 | */
|
---|
4678 | # ifdef LOG_ENABLED
|
---|
4679 | const unsigned uOrg = PGM_PAGE_GET_TRACKING(pPhysPage);
|
---|
4680 | # endif
|
---|
4681 | const unsigned cRefs = PGM_PAGE_GET_TD_CREFS(pPhysPage);
|
---|
4682 | if (cRefs == 1)
|
---|
4683 | {
|
---|
4684 | Assert(pPoolPage->idx == PGM_PAGE_GET_TD_IDX(pPhysPage));
|
---|
4685 | PGM_PAGE_SET_TRACKING(pPhysPage, 0);
|
---|
4686 | }
|
---|
4687 | else
|
---|
4688 | pgmPoolTrackPhysExtDerefGCPhys(pPool, pPoolPage, pPhysPage);
|
---|
4689 | Log2(("pgmTrackDerefGCPhys: %x -> %x pPhysPage=%R[pgmpage]\n", uOrg, PGM_PAGE_GET_TRACKING(pPhysPage), pPhysPage ));
|
---|
4690 | }
|
---|
4691 | #endif /* PGMPOOL_WITH_GCPHYS_TRACKING */
|
---|
4692 |
|
---|
4693 |
|
---|
4694 | #ifdef PGMPOOL_WITH_CACHE
|
---|
4695 | /**
|
---|
4696 | * Moves the page to the head of the age list.
|
---|
4697 | *
|
---|
4698 | * This is done when the cached page is used in one way or another.
|
---|
4699 | *
|
---|
4700 | * @param pPool The pool.
|
---|
4701 | * @param pPage The cached page.
|
---|
4702 | */
|
---|
4703 | DECLINLINE(void) pgmPoolCacheUsed(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
|
---|
4704 | {
|
---|
4705 | PVM pVM = pPool->CTX_SUFF(pVM);
|
---|
4706 | pgmLock(pVM);
|
---|
4707 |
|
---|
4708 | /*
|
---|
4709 | * Move to the head of the age list.
|
---|
4710 | */
|
---|
4711 | if (pPage->iAgePrev != NIL_PGMPOOL_IDX)
|
---|
4712 | {
|
---|
4713 | /* unlink */
|
---|
4714 | pPool->aPages[pPage->iAgePrev].iAgeNext = pPage->iAgeNext;
|
---|
4715 | if (pPage->iAgeNext != NIL_PGMPOOL_IDX)
|
---|
4716 | pPool->aPages[pPage->iAgeNext].iAgePrev = pPage->iAgePrev;
|
---|
4717 | else
|
---|
4718 | pPool->iAgeTail = pPage->iAgePrev;
|
---|
4719 |
|
---|
4720 | /* insert at head */
|
---|
4721 | pPage->iAgePrev = NIL_PGMPOOL_IDX;
|
---|
4722 | pPage->iAgeNext = pPool->iAgeHead;
|
---|
4723 | Assert(pPage->iAgeNext != NIL_PGMPOOL_IDX); /* we would've already been head then */
|
---|
4724 | pPool->iAgeHead = pPage->idx;
|
---|
4725 | pPool->aPages[pPage->iAgeNext].iAgePrev = pPage->idx;
|
---|
4726 | }
|
---|
4727 | pgmUnlock(pVM);
|
---|
4728 | }
|
---|
4729 | #endif /* PGMPOOL_WITH_CACHE */
|
---|
4730 |
|
---|
4731 | /**
|
---|
4732 | * Locks a page to prevent flushing (important for cr3 root pages or shadow pae pd pages).
|
---|
4733 | *
|
---|
4734 | * @param pVM VM Handle.
|
---|
4735 | * @param pPage PGM pool page
|
---|
4736 | */
|
---|
4737 | DECLINLINE(void) pgmPoolLockPage(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
|
---|
4738 | {
|
---|
4739 | Assert(PGMIsLockOwner(pPool->CTX_SUFF(pVM)));
|
---|
4740 | ASMAtomicIncU32(&pPage->cLocked);
|
---|
4741 | }
|
---|
4742 |
|
---|
4743 |
|
---|
4744 | /**
|
---|
4745 | * Unlocks a page to allow flushing again
|
---|
4746 | *
|
---|
4747 | * @param pVM VM Handle.
|
---|
4748 | * @param pPage PGM pool page
|
---|
4749 | */
|
---|
4750 | DECLINLINE(void) pgmPoolUnlockPage(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
|
---|
4751 | {
|
---|
4752 | Assert(PGMIsLockOwner(pPool->CTX_SUFF(pVM)));
|
---|
4753 | Assert(pPage->cLocked);
|
---|
4754 | ASMAtomicDecU32(&pPage->cLocked);
|
---|
4755 | }
|
---|
4756 |
|
---|
4757 |
|
---|
4758 | /**
|
---|
4759 | * Checks if the page is locked (e.g. the active CR3 or one of the four PDs of a PAE PDPT)
|
---|
4760 | *
|
---|
4761 | * @returns VBox status code.
|
---|
4762 | * @param pPage PGM pool page
|
---|
4763 | */
|
---|
4764 | DECLINLINE(bool) pgmPoolIsPageLocked(PPGM pPGM, PPGMPOOLPAGE pPage)
|
---|
4765 | {
|
---|
4766 | if (pPage->cLocked)
|
---|
4767 | {
|
---|
4768 | LogFlow(("pgmPoolIsPageLocked found root page %d\n", pPage->enmKind));
|
---|
4769 | if (pPage->cModifications)
|
---|
4770 | pPage->cModifications = 1; /* reset counter (can't use 0, or else it will be reinserted in the modified list) */
|
---|
4771 | return true;
|
---|
4772 | }
|
---|
4773 | return false;
|
---|
4774 | }
|
---|
4775 |
|
---|
4776 | /**
|
---|
4777 | * Tells if mappings are to be put into the shadow page table or not
|
---|
4778 | *
|
---|
4779 | * @returns boolean result
|
---|
4780 | * @param pVM VM handle.
|
---|
4781 | */
|
---|
4782 | DECLINLINE(bool) pgmMapAreMappingsEnabled(PPGM pPGM)
|
---|
4783 | {
|
---|
4784 | #ifdef IN_RING0
|
---|
4785 | /* There are no mappings in VT-x and AMD-V mode. */
|
---|
4786 | Assert(pPGM->fDisableMappings);
|
---|
4787 | return false;
|
---|
4788 | #else
|
---|
4789 | return !pPGM->fDisableMappings;
|
---|
4790 | #endif
|
---|
4791 | }
|
---|
4792 |
|
---|
4793 | /** @} */
|
---|
4794 |
|
---|
4795 | #endif
|
---|
4796 |
|
---|
4797 |
|
---|