VirtualBox

source: vbox/trunk/src/VBox/VMM/include/MMInternal.h@ 79846

Last change on this file since 79846 was 76585, checked in by vboxsync, 6 years ago

*: scm --fix-header-guard-endif

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 27.1 KB
Line 
1/* $Id: MMInternal.h 76585 2019-01-01 06:31:29Z vboxsync $ */
2/** @file
3 * MM - Internal header file.
4 */
5
6/*
7 * Copyright (C) 2006-2019 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef VMM_INCLUDED_SRC_include_MMInternal_h
19#define VMM_INCLUDED_SRC_include_MMInternal_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24#include <VBox/cdefs.h>
25#include <VBox/types.h>
26#include <VBox/sup.h>
27#include <VBox/vmm/stam.h>
28#include <VBox/vmm/pdmcritsect.h>
29#include <iprt/assert.h>
30#include <iprt/avl.h>
31#include <iprt/critsect.h>
32
33
34
35/** @defgroup grp_mm_int Internals
36 * @ingroup grp_mm
37 * @internal
38 * @{
39 */
40
41
42/** @name MMR3Heap - VM Ring-3 Heap Internals
43 * @{
44 */
45
46/** @def MMR3HEAP_SIZE_ALIGNMENT
47 * The allocation size alignment of the MMR3Heap.
48 */
49#define MMR3HEAP_SIZE_ALIGNMENT 16
50
51/** @def MMR3HEAP_WITH_STATISTICS
52 * Enable MMR3Heap statistics.
53 */
54#if !defined(MMR3HEAP_WITH_STATISTICS) && defined(VBOX_WITH_STATISTICS)
55# define MMR3HEAP_WITH_STATISTICS
56#endif
57
58/**
59 * Heap statistics record.
60 * There is one global and one per allocation tag.
61 */
62typedef struct MMHEAPSTAT
63{
64 /** Core avl node, key is the tag. */
65 AVLULNODECORE Core;
66 /** Pointer to the heap the memory belongs to. */
67 struct MMHEAP *pHeap;
68#ifdef MMR3HEAP_WITH_STATISTICS
69 /** Number of bytes currently allocated. */
70 size_t cbCurAllocated;
71 /** Number of allocation. */
72 uint64_t cAllocations;
73 /** Number of reallocations. */
74 uint64_t cReallocations;
75 /** Number of frees. */
76 uint64_t cFrees;
77 /** Failures. */
78 uint64_t cFailures;
79 /** Number of bytes allocated (sum). */
80 uint64_t cbAllocated;
81 /** Number of bytes freed. */
82 uint64_t cbFreed;
83#endif
84} MMHEAPSTAT;
85#if defined(MMR3HEAP_WITH_STATISTICS) && defined(IN_RING3)
86AssertCompileMemberAlignment(MMHEAPSTAT, cAllocations, 8);
87AssertCompileSizeAlignment(MMHEAPSTAT, 8);
88#endif
89/** Pointer to heap statistics record. */
90typedef MMHEAPSTAT *PMMHEAPSTAT;
91
92
93
94
95/**
96 * Additional heap block header for relating allocations to the VM.
97 */
98typedef struct MMHEAPHDR
99{
100 /** Pointer to the next record. */
101 struct MMHEAPHDR *pNext;
102 /** Pointer to the previous record. */
103 struct MMHEAPHDR *pPrev;
104 /** Pointer to the heap statistics record.
105 * (Where the a PVM can be found.) */
106 PMMHEAPSTAT pStat;
107 /** Size of the allocation (including this header). */
108 size_t cbSize;
109} MMHEAPHDR;
110/** Pointer to MM heap header. */
111typedef MMHEAPHDR *PMMHEAPHDR;
112
113
114/** MM Heap structure. */
115typedef struct MMHEAP
116{
117 /** Lock protecting the heap. */
118 RTCRITSECT Lock;
119 /** Heap block list head. */
120 PMMHEAPHDR pHead;
121 /** Heap block list tail. */
122 PMMHEAPHDR pTail;
123 /** Heap per tag statistics tree. */
124 PAVLULNODECORE pStatTree;
125 /** The VM handle. */
126 PUVM pUVM;
127 /** Heap global statistics. */
128 MMHEAPSTAT Stat;
129} MMHEAP;
130/** Pointer to MM Heap structure. */
131typedef MMHEAP *PMMHEAP;
132
133/** @} */
134
135
136/** @name MMUkHeap - VM User-kernel Heap Internals
137 * @{
138 */
139
140/** @def MMUKHEAP_SIZE_ALIGNMENT
141 * The allocation size alignment of the MMR3UkHeap.
142 */
143#define MMUKHEAP_SIZE_ALIGNMENT 16
144
145/** @def MMUKHEAP_WITH_STATISTICS
146 * Enable MMUkHeap statistics.
147 */
148#if !defined(MMUKHEAP_WITH_STATISTICS) && defined(VBOX_WITH_STATISTICS)
149# define MMUKHEAP_WITH_STATISTICS
150#endif
151
152
153/**
154 * Heap statistics record.
155 * There is one global and one per allocation tag.
156 */
157typedef struct MMUKHEAPSTAT
158{
159 /** Core avl node, key is the tag. */
160 AVLULNODECORE Core;
161 /** Number of allocation. */
162 uint64_t cAllocations;
163 /** Number of reallocations. */
164 uint64_t cReallocations;
165 /** Number of frees. */
166 uint64_t cFrees;
167 /** Failures. */
168 uint64_t cFailures;
169 /** Number of bytes allocated (sum). */
170 uint64_t cbAllocated;
171 /** Number of bytes freed. */
172 uint64_t cbFreed;
173 /** Number of bytes currently allocated. */
174 size_t cbCurAllocated;
175} MMUKHEAPSTAT;
176#ifdef IN_RING3
177AssertCompileMemberAlignment(MMUKHEAPSTAT, cAllocations, 8);
178#endif
179/** Pointer to heap statistics record. */
180typedef MMUKHEAPSTAT *PMMUKHEAPSTAT;
181
182/**
183 * Sub heap tracking record.
184 */
185typedef struct MMUKHEAPSUB
186{
187 /** Pointer to the next sub-heap. */
188 struct MMUKHEAPSUB *pNext;
189 /** The base address of the sub-heap. */
190 void *pv;
191 /** The size of the sub-heap. */
192 size_t cb;
193 /** The handle of the simple block pointer. */
194 RTHEAPSIMPLE hSimple;
195 /** The ring-0 address corresponding to MMUKHEAPSUB::pv. */
196 RTR0PTR pvR0;
197} MMUKHEAPSUB;
198/** Pointer to a sub-heap tracking record. */
199typedef MMUKHEAPSUB *PMMUKHEAPSUB;
200
201
202/** MM User-kernel Heap structure. */
203typedef struct MMUKHEAP
204{
205 /** Lock protecting the heap. */
206 RTCRITSECT Lock;
207 /** Head of the sub-heap LIFO. */
208 PMMUKHEAPSUB pSubHeapHead;
209 /** Heap per tag statistics tree. */
210 PAVLULNODECORE pStatTree;
211 /** The VM handle. */
212 PUVM pUVM;
213#if HC_ARCH_BITS == 32
214 /** Aligning the statistics on an 8 byte boundary (for uint64_t and STAM). */
215 void *pvAlignment;
216#endif
217 /** Heap global statistics. */
218 MMUKHEAPSTAT Stat;
219} MMUKHEAP;
220#ifdef IN_RING3
221AssertCompileMemberAlignment(MMUKHEAP, Stat, 8);
222#endif
223/** Pointer to MM Heap structure. */
224typedef MMUKHEAP *PMMUKHEAP;
225
226/** @} */
227
228
229
230/** @name Hypervisor Heap Internals
231 * @{
232 */
233
234/** @def MMHYPER_HEAP_FREE_DELAY
235 * If defined, it indicates the number of frees that should be delayed.
236 */
237#if defined(DOXYGEN_RUNNING)
238# define MMHYPER_HEAP_FREE_DELAY 64
239#endif
240
241/** @def MMHYPER_HEAP_FREE_POISON
242 * If defined, it indicates that freed memory should be poisoned
243 * with the value it has.
244 */
245#if defined(VBOX_STRICT) || defined(DOXYGEN_RUNNING)
246# define MMHYPER_HEAP_FREE_POISON 0xcb
247#endif
248
249/** @def MMHYPER_HEAP_STRICT
250 * Enables a bunch of assertions in the heap code. */
251#if defined(VBOX_STRICT) || defined(DOXYGEN_RUNNING)
252# define MMHYPER_HEAP_STRICT 1
253# if 0 || defined(DOXYGEN_RUNNING)
254/** @def MMHYPER_HEAP_STRICT_FENCE
255 * Enables tail fence. */
256# define MMHYPER_HEAP_STRICT_FENCE
257/** @def MMHYPER_HEAP_STRICT_FENCE_SIZE
258 * The fence size in bytes. */
259# define MMHYPER_HEAP_STRICT_FENCE_SIZE 256
260/** @def MMHYPER_HEAP_STRICT_FENCE_U32
261 * The fence filler. */
262# define MMHYPER_HEAP_STRICT_FENCE_U32 UINT32_C(0xdeadbeef)
263# endif
264#endif
265
266/**
267 * Hypervisor heap statistics record.
268 * There is one global and one per allocation tag.
269 */
270typedef struct MMHYPERSTAT
271{
272 /** Core avl node, key is the tag.
273 * @todo The type is wrong! Get your lazy a$$ over and create that offsetted uint32_t version we need here! */
274 AVLOGCPHYSNODECORE Core;
275 /** Aligning the 64-bit fields on a 64-bit line. */
276 uint32_t u32Padding0;
277 /** Indicator for whether these statistics are registered with STAM or not. */
278 bool fRegistered;
279 /** Number of allocation. */
280 uint64_t cAllocations;
281 /** Number of frees. */
282 uint64_t cFrees;
283 /** Failures. */
284 uint64_t cFailures;
285 /** Number of bytes allocated (sum). */
286 uint64_t cbAllocated;
287 /** Number of bytes freed (sum). */
288 uint64_t cbFreed;
289 /** Number of bytes currently allocated. */
290 uint32_t cbCurAllocated;
291 /** Max number of bytes allocated. */
292 uint32_t cbMaxAllocated;
293} MMHYPERSTAT;
294AssertCompileMemberAlignment(MMHYPERSTAT, cAllocations, 8);
295/** Pointer to hypervisor heap statistics record. */
296typedef MMHYPERSTAT *PMMHYPERSTAT;
297
298/**
299 * Hypervisor heap chunk.
300 */
301typedef struct MMHYPERCHUNK
302{
303 /** Previous block in the list of all blocks.
304 * This is relative to the start of the heap. */
305 uint32_t offNext;
306 /** Offset to the previous block relative to this one. */
307 int32_t offPrev;
308 /** The statistics record this allocation belongs to (self relative). */
309 int32_t offStat;
310 /** Offset to the heap block (self relative). */
311 int32_t offHeap;
312} MMHYPERCHUNK;
313/** Pointer to a hypervisor heap chunk. */
314typedef MMHYPERCHUNK *PMMHYPERCHUNK;
315
316
317/**
318 * Hypervisor heap chunk.
319 */
320typedef struct MMHYPERCHUNKFREE
321{
322 /** Main list. */
323 MMHYPERCHUNK core;
324 /** Offset of the next chunk in the list of free nodes. */
325 uint32_t offNext;
326 /** Offset of the previous chunk in the list of free nodes. */
327 int32_t offPrev;
328 /** Size of the block. */
329 uint32_t cb;
330} MMHYPERCHUNKFREE;
331/** Pointer to a free hypervisor heap chunk. */
332typedef MMHYPERCHUNKFREE *PMMHYPERCHUNKFREE;
333
334
335/**
336 * The hypervisor heap.
337 */
338typedef struct MMHYPERHEAP
339{
340 /** The typical magic (MMHYPERHEAP_MAGIC). */
341 uint32_t u32Magic;
342 /** The heap size. (This structure is not included!) */
343 uint32_t cbHeap;
344 /** Lock protecting the heap. */
345 PDMCRITSECT Lock;
346 /** The HC ring-3 address of the heap. */
347 R3PTRTYPE(uint8_t *) pbHeapR3;
348 /** The HC ring-3 address of the shared VM structure. */
349 PVMR3 pVMR3;
350 /** The HC ring-0 address of the heap. */
351 R0PTRTYPE(uint8_t *) pbHeapR0;
352 /** The HC ring-0 address of the shared VM structure. */
353 PVMR0 pVMR0;
354 /** The RC address of the heap. */
355 RCPTRTYPE(uint8_t *) pbHeapRC;
356 /** The RC address of the shared VM structure. */
357 PVMRC pVMRC;
358 /** The amount of free memory in the heap. */
359 uint32_t cbFree;
360 /** Offset of the first free chunk in the heap.
361 * The offset is relative to the start of the heap. */
362 uint32_t offFreeHead;
363 /** Offset of the last free chunk in the heap.
364 * The offset is relative to the start of the heap. */
365 uint32_t offFreeTail;
366 /** Offset of the first page aligned block in the heap.
367 * The offset is equal to cbHeap initially. */
368 uint32_t offPageAligned;
369 /** Tree of hypervisor heap statistics. */
370 AVLOGCPHYSTREE HyperHeapStatTree;
371#ifdef MMHYPER_HEAP_FREE_DELAY
372 /** Where to insert the next free. */
373 uint32_t iDelayedFree;
374 /** Array of delayed frees. Circular. Offsets relative to this structure. */
375 struct
376 {
377 /** The free caller address. */
378 RTUINTPTR uCaller;
379 /** The offset of the freed chunk. */
380 uint32_t offChunk;
381 } aDelayedFrees[MMHYPER_HEAP_FREE_DELAY];
382#else
383 /** Padding the structure to a 64-bit aligned size. */
384 uint32_t u32Padding0;
385#endif
386 /** The heap physical pages. */
387 R3PTRTYPE(PSUPPAGE) paPages;
388#if HC_ARCH_BITS == 32
389 /** Padding the structure to a 64-bit aligned size. */
390 uint32_t u32Padding1;
391#endif
392} MMHYPERHEAP;
393/** Pointer to the hypervisor heap. */
394typedef MMHYPERHEAP *PMMHYPERHEAP;
395
396/** Magic value for MMHYPERHEAP. (C. S. Lewis) */
397#define MMHYPERHEAP_MAGIC UINT32_C(0x18981129)
398
399
400/**
401 * Hypervisor heap minimum alignment (16 bytes).
402 */
403#define MMHYPER_HEAP_ALIGN_MIN 16
404
405/**
406 * The aligned size of the MMHYPERHEAP structure.
407 */
408#define MMYPERHEAP_HDR_SIZE RT_ALIGN_Z(sizeof(MMHYPERHEAP), MMHYPER_HEAP_ALIGN_MIN * 4)
409
410/** @name Hypervisor heap chunk flags.
411 * The flags are put in the first bits of the MMHYPERCHUNK::offPrev member.
412 * These bits aren't used anyway because of the chunk minimal alignment (16 bytes).
413 * @{ */
414/** The chunk is free. (The code ASSUMES this is 0!) */
415#define MMHYPERCHUNK_FLAGS_FREE 0x0
416/** The chunk is in use. */
417#define MMHYPERCHUNK_FLAGS_USED 0x1
418/** The type mask. */
419#define MMHYPERCHUNK_FLAGS_TYPE_MASK 0x1
420/** The flag mask */
421#define MMHYPERCHUNK_FLAGS_MASK 0x1
422
423/** Checks if the chunk is free. */
424#define MMHYPERCHUNK_ISFREE(pChunk) ( (((pChunk)->offPrev) & MMHYPERCHUNK_FLAGS_TYPE_MASK) == MMHYPERCHUNK_FLAGS_FREE )
425/** Checks if the chunk is used. */
426#define MMHYPERCHUNK_ISUSED(pChunk) ( (((pChunk)->offPrev) & MMHYPERCHUNK_FLAGS_TYPE_MASK) == MMHYPERCHUNK_FLAGS_USED )
427/** Toggles FREE/USED flag of a chunk. */
428#define MMHYPERCHUNK_SET_TYPE(pChunk, type) do { (pChunk)->offPrev = ((pChunk)->offPrev & ~MMHYPERCHUNK_FLAGS_TYPE_MASK) | ((type) & MMHYPERCHUNK_FLAGS_TYPE_MASK); } while (0)
429
430/** Gets the prev offset without the flags. */
431#define MMHYPERCHUNK_GET_OFFPREV(pChunk) ((int32_t)((pChunk)->offPrev & ~MMHYPERCHUNK_FLAGS_MASK))
432/** Sets the prev offset without changing the flags. */
433#define MMHYPERCHUNK_SET_OFFPREV(pChunk, off) do { (pChunk)->offPrev = (off) | ((pChunk)->offPrev & MMHYPERCHUNK_FLAGS_MASK); } while (0)
434#if 0
435/** Clears one or more flags. */
436#define MMHYPERCHUNK_FLAGS_OP_CLEAR(pChunk, fFlags) do { ((pChunk)->offPrev) &= ~((fFlags) & MMHYPERCHUNK_FLAGS_MASK); } while (0)
437/** Sets one or more flags. */
438#define MMHYPERCHUNK_FLAGS_OP_SET(pChunk, fFlags) do { ((pChunk)->offPrev) |= ((fFlags) & MMHYPERCHUNK_FLAGS_MASK); } while (0)
439/** Checks if one is set. */
440#define MMHYPERCHUNK_FLAGS_OP_ISSET(pChunk, fFlag) (!!(((pChunk)->offPrev) & ((fFlag) & MMHYPERCHUNK_FLAGS_MASK)))
441#endif
442/** @} */
443
444/** @} */
445
446
447/** @name Page Pool Internals
448 * @{
449 */
450
451/**
452 * Page sub pool
453 *
454 * About the allocation of this structure. To keep the number of heap blocks,
455 * the number of heap calls, and fragmentation low we allocate all the data
456 * related to a MMPAGESUBPOOL node in one chunk. That means that after the
457 * bitmap (which is of variable size) comes the SUPPAGE records and then
458 * follows the lookup tree nodes. (The heap in question is the hyper heap.)
459 */
460typedef struct MMPAGESUBPOOL
461{
462 /** Pointer to next sub pool. */
463#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
464 R3PTRTYPE(struct MMPAGESUBPOOL *) pNext;
465#else
466 R3R0PTRTYPE(struct MMPAGESUBPOOL *) pNext;
467#endif
468 /** Pointer to next sub pool in the free chain.
469 * This is NULL if we're not in the free chain or at the end of it. */
470#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
471 R3PTRTYPE(struct MMPAGESUBPOOL *) pNextFree;
472#else
473 R3R0PTRTYPE(struct MMPAGESUBPOOL *) pNextFree;
474#endif
475 /** Pointer to array of lock ranges.
476 * This is allocated together with the MMPAGESUBPOOL and thus needs no freeing.
477 * It follows immediately after the bitmap.
478 * The reserved field is a pointer to this structure.
479 */
480#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
481 R3PTRTYPE(PSUPPAGE) paPhysPages;
482#else
483 R3R0PTRTYPE(PSUPPAGE) paPhysPages;
484#endif
485 /** Pointer to the first page. */
486#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
487 R3PTRTYPE(void *) pvPages;
488#else
489 R3R0PTRTYPE(void *) pvPages;
490#endif
491 /** Size of the subpool. */
492 uint32_t cPages;
493 /** Number of free pages. */
494 uint32_t cPagesFree;
495 /** The allocation bitmap.
496 * This may extend beyond the end of the defined array size.
497 */
498 uint32_t auBitmap[1];
499 /* ... SUPPAGE aRanges[1]; */
500} MMPAGESUBPOOL;
501/** Pointer to page sub pool. */
502typedef MMPAGESUBPOOL *PMMPAGESUBPOOL;
503
504/**
505 * Page pool.
506 */
507typedef struct MMPAGEPOOL
508{
509 /** List of subpools. */
510#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
511 R3PTRTYPE(PMMPAGESUBPOOL) pHead;
512#else
513 R3R0PTRTYPE(PMMPAGESUBPOOL) pHead;
514#endif
515 /** Head of subpools with free pages. */
516#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
517 R3PTRTYPE(PMMPAGESUBPOOL) pHeadFree;
518#else
519 R3R0PTRTYPE(PMMPAGESUBPOOL) pHeadFree;
520#endif
521 /** AVLPV tree for looking up HC virtual addresses.
522 * The tree contains MMLOOKUPVIRTPP records.
523 */
524#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
525 R3PTRTYPE(PAVLPVNODECORE) pLookupVirt;
526#else
527 R3R0PTRTYPE(PAVLPVNODECORE) pLookupVirt;
528#endif
529 /** Tree for looking up HC physical addresses.
530 * The tree contains MMLOOKUPPHYSHC records.
531 */
532#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
533 R3PTRTYPE(AVLHCPHYSTREE) pLookupPhys;
534#else
535 R3R0PTRTYPE(AVLHCPHYSTREE) pLookupPhys;
536#endif
537 /** Pointer to the VM this pool belongs. */
538#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
539 PVMR3 pVM;
540#else
541 R3R0PTRTYPE(PVM) pVM;
542#endif
543 /** Flag indicating the allocation method.
544 * Set: SUPR3LowAlloc().
545 * Clear: SUPR3PageAllocEx(). */
546 bool fLow;
547 /** Number of subpools. */
548 uint32_t cSubPools;
549 /** Number of pages in pool. */
550 uint32_t cPages;
551#ifdef VBOX_WITH_STATISTICS
552 /** Number of free pages in pool. */
553 uint32_t cFreePages;
554# if HC_ARCH_BITS == 32
555 /** Aligning the statistics on an 8 byte boundary. */
556 uint32_t u32Alignment;
557# endif
558 /** Number of alloc calls. */
559 STAMCOUNTER cAllocCalls;
560 /** Number of free calls. */
561 STAMCOUNTER cFreeCalls;
562 /** Number of to phys conversions. */
563 STAMCOUNTER cToPhysCalls;
564 /** Number of to virtual conversions. */
565 STAMCOUNTER cToVirtCalls;
566 /** Number of real errors. */
567 STAMCOUNTER cErrors;
568#endif
569} MMPAGEPOOL;
570#ifndef IN_RC
571AssertCompileMemberAlignment(MMPAGEPOOL, cSubPools, 4);
572# ifdef VBOX_WITH_STATISTICS
573AssertCompileMemberAlignment(MMPAGEPOOL, cAllocCalls, 8);
574# endif
575#endif
576/** Pointer to page pool. */
577typedef MMPAGEPOOL *PMMPAGEPOOL;
578
579/**
580 * Lookup record for HC virtual memory in the page pool.
581 */
582typedef struct MMPPLOOKUPHCPTR
583{
584 /** The key is virtual address. */
585 AVLPVNODECORE Core;
586 /** Pointer to subpool if lookup record for a pool. */
587 struct MMPAGESUBPOOL *pSubPool;
588} MMPPLOOKUPHCPTR;
589/** Pointer to virtual memory lookup record. */
590typedef MMPPLOOKUPHCPTR *PMMPPLOOKUPHCPTR;
591
592/**
593 * Lookup record for HC physical memory.
594 */
595typedef struct MMPPLOOKUPHCPHYS
596{
597 /** The key is physical address. */
598 AVLHCPHYSNODECORE Core;
599 /** Pointer to SUPPAGE record for this physical address. */
600 PSUPPAGE pPhysPage;
601} MMPPLOOKUPHCPHYS;
602/** Pointer to physical memory lookup record. */
603typedef MMPPLOOKUPHCPHYS *PMMPPLOOKUPHCPHYS;
604
605/** @} */
606
607
608/**
609 * Hypervisor memory mapping type.
610 */
611typedef enum MMLOOKUPHYPERTYPE
612{
613 /** Invalid record. This is used for record which are incomplete. */
614 MMLOOKUPHYPERTYPE_INVALID = 0,
615 /** Mapping of locked memory. */
616 MMLOOKUPHYPERTYPE_LOCKED,
617 /** Mapping of contiguous HC physical memory. */
618 MMLOOKUPHYPERTYPE_HCPHYS,
619 /** Mapping of contiguous GC physical memory. */
620 MMLOOKUPHYPERTYPE_GCPHYS,
621 /** Mapping of MMIO2 memory. */
622 MMLOOKUPHYPERTYPE_MMIO2,
623 /** Dynamic mapping area (MMR3HyperReserve).
624 * A conversion will require to check what's in the page table for the pages. */
625 MMLOOKUPHYPERTYPE_DYNAMIC
626} MMLOOKUPHYPERTYPE;
627
628/**
629 * Lookup record for the hypervisor memory area.
630 */
631typedef struct MMLOOKUPHYPER
632{
633 /** Byte offset from the start of this record to the next.
634 * If the value is NIL_OFFSET the chain is terminated. */
635 int32_t offNext;
636 /** Offset into the hypervisor memory area. */
637 uint32_t off;
638 /** Size of this part. */
639 uint32_t cb;
640 /** Locking type. */
641 MMLOOKUPHYPERTYPE enmType;
642 /** Type specific data */
643 union
644 {
645 /** Locked memory. */
646 struct
647 {
648 /** Host context ring-3 pointer. */
649 R3PTRTYPE(void *) pvR3;
650 /** Host context ring-0 pointer. Optional. */
651 RTR0PTR pvR0;
652 /** Pointer to an array containing the physical address of each page. */
653 R3PTRTYPE(PRTHCPHYS) paHCPhysPages;
654 } Locked;
655
656 /** Contiguous physical memory. */
657 struct
658 {
659 /** Host context ring-3 pointer. */
660 R3PTRTYPE(void *) pvR3;
661 /** Host context ring-0 pointer. Optional. */
662 RTR0PTR pvR0;
663 /** HC physical address corresponding to pvR3/pvR0. */
664 RTHCPHYS HCPhys;
665 } HCPhys;
666
667 /** Contiguous guest physical memory. */
668 struct
669 {
670 /** The memory address (Guest Context). */
671 RTGCPHYS GCPhys;
672 } GCPhys;
673
674 /** MMIO2 memory. */
675 struct
676 {
677 /** The device instance owning the MMIO2 region. */
678 PPDMDEVINSR3 pDevIns;
679 /** The sub-device number. */
680 uint32_t iSubDev;
681 /** The region number. */
682 uint32_t iRegion;
683#if HC_ARCH_BITS == 32
684 /** Alignment padding. */
685 uint32_t uPadding;
686#endif
687 /** The offset into the MMIO2 region. */
688 RTGCPHYS off;
689 } MMIO2;
690 } u;
691 /** Description. */
692 R3PTRTYPE(const char *) pszDesc;
693} MMLOOKUPHYPER;
694/** Pointer to a hypervisor memory lookup record. */
695typedef MMLOOKUPHYPER *PMMLOOKUPHYPER;
696
697
698/**
699 * Converts a MM pointer into a VM pointer.
700 * @returns Pointer to the VM structure the MM is part of.
701 * @param pMM Pointer to MM instance data.
702 */
703#define MM2VM(pMM) ( (PVM)((uint8_t *)pMM - pMM->offVM) )
704
705
706/**
707 * MM Data (part of VM)
708 */
709typedef struct MM
710{
711 /** Offset to the VM structure.
712 * See MM2VM(). */
713 RTINT offVM;
714
715 /** Set if MMR3InitPaging has been called. */
716 bool fDoneMMR3InitPaging;
717 /** Set if PGM has been initialized and we can safely call PGMR3Map(). */
718 bool fPGMInitialized;
719#if GC_ARCH_BITS == 64 || HC_ARCH_BITS == 64
720 uint32_t u32Padding1; /**< alignment padding. */
721#endif
722
723 /** Lookup list for the Hypervisor Memory Area.
724 * The offset is relative to the start of the heap.
725 * Use pHyperHeapR3, pHyperHeapR0 or pHypeRHeapRC to calculate the address.
726 */
727 RTUINT offLookupHyper;
728
729 /** The offset of the next static mapping in the Hypervisor Memory Area. */
730 RTUINT offHyperNextStatic;
731 /** The size of the HMA.
732 * Starts at 12MB and will be fixed late in the init process. */
733 RTUINT cbHyperArea;
734
735 /** Guest address of the Hypervisor Memory Area.
736 * @remarks It's still a bit open whether this should be change to RTRCPTR or
737 * remain a RTGCPTR. */
738 RTGCPTR pvHyperAreaGC;
739
740 /** The hypervisor heap (GC Ptr). */
741 RCPTRTYPE(PMMHYPERHEAP) pHyperHeapRC;
742#if HC_ARCH_BITS == 64 && GC_ARCH_BITS == 64
743 uint32_t u32Padding2;
744#endif
745
746 /** The hypervisor heap (R0 Ptr). */
747 R0PTRTYPE(PMMHYPERHEAP) pHyperHeapR0;
748#ifndef VBOX_WITH_2X_4GB_ADDR_SPACE
749 /** Page pool - R0 Ptr. */
750 R0PTRTYPE(PMMPAGEPOOL) pPagePoolR0;
751 /** Page pool pages in low memory R0 Ptr. */
752 R0PTRTYPE(PMMPAGEPOOL) pPagePoolLowR0;
753#endif /* !VBOX_WITH_2X_4GB_ADDR_SPACE */
754
755 /** The hypervisor heap (R3 Ptr). */
756 R3PTRTYPE(PMMHYPERHEAP) pHyperHeapR3;
757 /** Page pool - R3 Ptr. */
758 R3PTRTYPE(PMMPAGEPOOL) pPagePoolR3;
759 /** Page pool pages in low memory R3 Ptr. */
760 R3PTRTYPE(PMMPAGEPOOL) pPagePoolLowR3;
761
762 /** Pointer to the dummy page.
763 * The dummy page is a paranoia thingy used for instance for pure MMIO RAM ranges
764 * to make sure any bugs will not harm whatever the system stores in the first
765 * physical page. */
766 R3PTRTYPE(void *) pvDummyPage;
767 /** Physical address of the dummy page. */
768 RTHCPHYS HCPhysDummyPage;
769
770 /** Size of the base RAM in bytes. (The CFGM RamSize value.) */
771 uint64_t cbRamBase;
772 /** Number of bytes of RAM above 4GB, starting at address 4GB. */
773 uint64_t cbRamAbove4GB;
774 /** Size of the below 4GB RAM hole. */
775 uint32_t cbRamHole;
776 /** Number of bytes of RAM below 4GB, starting at address 0. */
777 uint32_t cbRamBelow4GB;
778 /** The number of base RAM pages that PGM has reserved (GMM).
779 * @remarks Shadow ROMs will be counted twice (RAM+ROM), so it won't be 1:1 with
780 * what the guest sees. */
781 uint64_t cBasePages;
782 /** The number of handy pages that PGM has reserved (GMM).
783 * These are kept out of cBasePages and thus out of the saved state. */
784 uint32_t cHandyPages;
785 /** The number of shadow pages PGM has reserved (GMM). */
786 uint32_t cShadowPages;
787 /** The number of fixed pages we've reserved (GMM). */
788 uint32_t cFixedPages;
789 /** Padding. */
790 uint32_t u32Padding0;
791} MM;
792/** Pointer to MM Data (part of VM). */
793typedef MM *PMM;
794
795
796/**
797 * MM data kept in the UVM.
798 */
799typedef struct MMUSERPERVM
800{
801 /** Pointer to the MM R3 Heap. */
802 R3PTRTYPE(PMMHEAP) pHeap;
803 /** Pointer to the MM Uk Heap. */
804 R3PTRTYPE(PMMUKHEAP) pUkHeap;
805} MMUSERPERVM;
806/** Pointer to the MM data kept in the UVM. */
807typedef MMUSERPERVM *PMMUSERPERVM;
808
809
810RT_C_DECLS_BEGIN
811
812
813int mmR3UpdateReservation(PVM pVM);
814
815int mmR3PagePoolInit(PVM pVM);
816void mmR3PagePoolTerm(PVM pVM);
817
818int mmR3HeapCreateU(PUVM pUVM, PMMHEAP *ppHeap);
819void mmR3HeapDestroy(PMMHEAP pHeap);
820
821void mmR3UkHeapDestroy(PMMUKHEAP pHeap);
822int mmR3UkHeapCreateU(PUVM pUVM, PMMUKHEAP *ppHeap);
823
824
825int mmR3HyperInit(PVM pVM);
826int mmR3HyperTerm(PVM pVM);
827int mmR3HyperInitPaging(PVM pVM);
828
829const char *mmGetTagName(MMTAG enmTag);
830
831/**
832 * Converts a pool address to a physical address.
833 * The specified allocation type must match with the address.
834 *
835 * @returns Physical address.
836 * @returns NIL_RTHCPHYS if not found or eType is not matching.
837 * @param pPool Pointer to the page pool.
838 * @param pv The address to convert.
839 * @thread The Emulation Thread.
840 */
841RTHCPHYS mmPagePoolPtr2Phys(PMMPAGEPOOL pPool, void *pv);
842
843/**
844 * Converts a pool physical address to a linear address.
845 * The specified allocation type must match with the address.
846 *
847 * @returns Physical address.
848 * @returns NULL if not found or eType is not matching.
849 * @param pPool Pointer to the page pool.
850 * @param HCPhys The address to convert.
851 * @thread The Emulation Thread.
852 */
853void *mmPagePoolPhys2Ptr(PMMPAGEPOOL pPool, RTHCPHYS HCPhys);
854
855RT_C_DECLS_END
856
857/** @} */
858
859#endif /* !VMM_INCLUDED_SRC_include_MMInternal_h */
860
Note: See TracBrowser for help on using the repository browser.

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