VirtualBox

source: vbox/trunk/include/VBox/vmm/gmm.h@ 92745

Last change on this file since 92745 was 92329, checked in by vboxsync, 3 years ago

VMM/GMM,PGM: Optimize zeroing of RAM allocations by not doing it again if the OS already zeroed an allocation. [build fix] bugref:10093

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 30.4 KB
Line 
1/** @file
2 * GMM - The Global Memory Manager.
3 */
4
5/*
6 * Copyright (C) 2007-2020 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef VBOX_INCLUDED_vmm_gmm_h
27#define VBOX_INCLUDED_vmm_gmm_h
28#ifndef RT_WITHOUT_PRAGMA_ONCE
29# pragma once
30#endif
31
32#include <VBox/vmm/gvmm.h>
33#include <VBox/sup.h>
34#include <VBox/param.h>
35#include <VBox/ostypes.h>
36#include <iprt/avl.h>
37
38
39RT_C_DECLS_BEGIN
40
41/** @defgroup grp_gmm GMM - The Global Memory Manager
42 * @ingroup grp_vmm
43 * @{
44 */
45
46/** @def IN_GMM_R0
47 * Used to indicate whether we're inside the same link module as the ring 0
48 * part of the Global Memory Manager or not.
49 */
50#ifdef DOXYGEN_RUNNING
51# define IN_GMM_R0
52#endif
53/** @def GMMR0DECL
54 * Ring 0 GMM export or import declaration.
55 * @param type The return type of the function declaration.
56 */
57#ifdef IN_GMM_R0
58# define GMMR0DECL(type) DECLEXPORT(type) VBOXCALL
59#else
60# define GMMR0DECL(type) DECLIMPORT(type) VBOXCALL
61#endif
62
63/** @def IN_GMM_R3
64 * Used to indicate whether we're inside the same link module as the ring 3
65 * part of the Global Memory Manager or not.
66 */
67#ifdef DOXYGEN_RUNNING
68# define IN_GMM_R3
69#endif
70/** @def GMMR3DECL
71 * Ring 3 GMM export or import declaration.
72 * @param type The return type of the function declaration.
73 */
74#ifdef IN_GMM_R3
75# define GMMR3DECL(type) DECLEXPORT(type) VBOXCALL
76#else
77# define GMMR3DECL(type) DECLIMPORT(type) VBOXCALL
78#endif
79
80
81/** The chunk shift. (2^21 = 2 MB) */
82#define GMM_CHUNK_SHIFT 21
83/** The allocation chunk size. */
84#define GMM_CHUNK_SIZE (1U << GMM_CHUNK_SHIFT)
85/** The allocation chunk size in pages. */
86#define GMM_CHUNK_NUM_PAGES (1U << (GMM_CHUNK_SHIFT - PAGE_SHIFT))
87/** The shift factor for converting a page id into a chunk id. */
88#define GMM_CHUNKID_SHIFT (GMM_CHUNK_SHIFT - PAGE_SHIFT)
89/** The last valid Chunk ID value. */
90#define GMM_CHUNKID_LAST (GMM_PAGEID_LAST >> GMM_CHUNKID_SHIFT)
91/** The last valid Page ID value. */
92#define GMM_PAGEID_LAST UINT32_C(0xfffffff0)
93/** Mask out the page index from the Page ID. */
94#define GMM_PAGEID_IDX_MASK ((1U << GMM_CHUNKID_SHIFT) - 1)
95/** The NIL Chunk ID value. */
96#define NIL_GMM_CHUNKID 0
97/** The NIL Page ID value. */
98#define NIL_GMM_PAGEID 0
99
100#if 0 /* wrong - these are guest page pfns and not page ids! */
101/** Special Page ID used by unassigned pages. */
102#define GMM_PAGEID_UNASSIGNED 0x0fffffffU
103/** Special Page ID used by unsharable pages.
104 * Like MMIO2, shadow and heap. This is for later, obviously. */
105#define GMM_PAGEID_UNSHARABLE 0x0ffffffeU
106/** The end of the valid Page IDs. This is the first special one. */
107#define GMM_PAGEID_END 0x0ffffff0U
108#endif
109
110
111/** @def GMM_GCPHYS_LAST
112 * The last of the valid guest physical address as it applies to GMM pages.
113 *
114 * This must reflect the constraints imposed by the RTGCPHYS type and
115 * the guest page frame number used internally in GMMPAGE.
116 *
117 * @note Note this corresponds to GMM_PAGE_PFN_LAST. */
118#if HC_ARCH_BITS == 64
119# define GMM_GCPHYS_LAST UINT64_C(0x00000fffffff0000) /* 2^44 (16TB) - 0x10000 */
120#else
121# define GMM_GCPHYS_LAST UINT64_C(0x0000000fffff0000) /* 2^36 (64GB) - 0x10000 */
122#endif
123
124/**
125 * Over-commitment policy.
126 */
127typedef enum GMMOCPOLICY
128{
129 /** The usual invalid 0 value. */
130 GMMOCPOLICY_INVALID = 0,
131 /** No over-commitment, fully backed.
132 * The GMM guarantees that it will be able to allocate all of the
133 * guest RAM for a VM with OC policy. */
134 GMMOCPOLICY_NO_OC,
135 /** to-be-determined. */
136 GMMOCPOLICY_TBD,
137 /** The end of the valid policy range. */
138 GMMOCPOLICY_END,
139 /** The usual 32-bit hack. */
140 GMMOCPOLICY_32BIT_HACK = 0x7fffffff
141} GMMOCPOLICY;
142
143/**
144 * VM / Memory priority.
145 */
146typedef enum GMMPRIORITY
147{
148 /** The usual invalid 0 value. */
149 GMMPRIORITY_INVALID = 0,
150 /** High.
151 * When ballooning, ask these VMs last.
152 * When running out of memory, try not to interrupt these VMs. */
153 GMMPRIORITY_HIGH,
154 /** Normal.
155 * When ballooning, don't wait to ask these.
156 * When running out of memory, pause, save and/or kill these VMs. */
157 GMMPRIORITY_NORMAL,
158 /** Low.
159 * When ballooning, maximize these first.
160 * When running out of memory, save or kill these VMs. */
161 GMMPRIORITY_LOW,
162 /** The end of the valid priority range. */
163 GMMPRIORITY_END,
164 /** The custom 32-bit type blowup. */
165 GMMPRIORITY_32BIT_HACK = 0x7fffffff
166} GMMPRIORITY;
167
168
169/**
170 * GMM Memory Accounts.
171 */
172typedef enum GMMACCOUNT
173{
174 /** The customary invalid zero entry. */
175 GMMACCOUNT_INVALID = 0,
176 /** Account with the base allocations. */
177 GMMACCOUNT_BASE,
178 /** Account with the shadow allocations. */
179 GMMACCOUNT_SHADOW,
180 /** Account with the fixed allocations. */
181 GMMACCOUNT_FIXED,
182 /** The end of the valid values. */
183 GMMACCOUNT_END,
184 /** The usual 32-bit value to finish it off. */
185 GMMACCOUNT_32BIT_HACK = 0x7fffffff
186} GMMACCOUNT;
187
188
189/**
190 * Balloon actions.
191 */
192typedef enum
193{
194 /** Invalid zero entry. */
195 GMMBALLOONACTION_INVALID = 0,
196 /** Inflate the balloon. */
197 GMMBALLOONACTION_INFLATE,
198 /** Deflate the balloon. */
199 GMMBALLOONACTION_DEFLATE,
200 /** Puncture the balloon because of VM reset. */
201 GMMBALLOONACTION_RESET,
202 /** End of the valid actions. */
203 GMMBALLOONACTION_END,
204 /** hack forcing the size of the enum to 32-bits. */
205 GMMBALLOONACTION_MAKE_32BIT_HACK = 0x7fffffff
206} GMMBALLOONACTION;
207
208
209/**
210 * A page descriptor for use when freeing pages.
211 * See GMMR0FreePages, GMMR0BalloonedPages.
212 */
213typedef struct GMMFREEPAGEDESC
214{
215 /** The Page ID of the page to be freed. */
216 uint32_t idPage;
217} GMMFREEPAGEDESC;
218/** Pointer to a page descriptor for freeing pages. */
219typedef GMMFREEPAGEDESC *PGMMFREEPAGEDESC;
220
221
222/**
223 * A page descriptor for use when updating and allocating pages.
224 *
225 * This is a bit complicated because we want to do as much as possible
226 * with the same structure.
227 */
228typedef struct GMMPAGEDESC
229{
230 /** The physical address of the page.
231 *
232 * @input GMMR0AllocateHandyPages expects the guest physical address
233 * to update the GMMPAGE structure with. Pass GMM_GCPHYS_UNSHAREABLE
234 * when appropriate and NIL_GMMPAGEDESC_PHYS when the page wasn't used
235 * for any specific guest address.
236 *
237 * GMMR0AllocatePage expects the guest physical address to put in
238 * the GMMPAGE structure for the page it allocates for this entry.
239 * Pass NIL_GMMPAGEDESC_PHYS and GMM_GCPHYS_UNSHAREABLE as above.
240 *
241 * @output The host physical address of the allocated page.
242 * NIL_GMMPAGEDESC_PHYS on allocation failure.
243 *
244 * ASSUMES: sizeof(RTHCPHYS) >= sizeof(RTGCPHYS) and that physical addresses are
245 * limited to 63 or fewer bits (52 by AMD64 arch spec).
246 */
247 RT_GCC_EXTENSION
248 RTHCPHYS HCPhysGCPhys : 63;
249 /** Set if the memory was zeroed. */
250 RT_GCC_EXTENSION
251 RTHCPHYS fZeroed : 1;
252
253 /** The Page ID.
254 *
255 * @input GMMR0AllocateHandyPages expects the Page ID of the page to
256 * update here. NIL_GMM_PAGEID means no page should be updated.
257 *
258 * GMMR0AllocatePages requires this to be initialized to
259 * NIL_GMM_PAGEID currently.
260 *
261 * @output The ID of the page, NIL_GMM_PAGEID if the allocation failed.
262 */
263 uint32_t idPage;
264
265 /** The Page ID of the shared page was replaced by this page.
266 *
267 * @input GMMR0AllocateHandyPages expects this to indicate a shared
268 * page that has been replaced by this page and should have its
269 * reference counter decremented and perhaps be freed up. Use
270 * NIL_GMM_PAGEID if no shared page was involved.
271 *
272 * All other APIs expects NIL_GMM_PAGEID here.
273 *
274 * @output All APIs sets this to NIL_GMM_PAGEID.
275 */
276 uint32_t idSharedPage;
277} GMMPAGEDESC;
278AssertCompileSize(GMMPAGEDESC, 16);
279/** Pointer to a page allocation. */
280typedef GMMPAGEDESC *PGMMPAGEDESC;
281
282/** Special NIL value for GMMPAGEDESC::HCPhysGCPhys. */
283#define NIL_GMMPAGEDESC_PHYS UINT64_C(0x7fffffffffffffff)
284
285/** GMMPAGEDESC::HCPhysGCPhys value that indicates that the page is unsharable.
286 * @note This corresponds to GMM_PAGE_PFN_UNSHAREABLE. */
287#if HC_ARCH_BITS == 64
288# define GMM_GCPHYS_UNSHAREABLE UINT64_C(0x00000fffffff1000)
289#else
290# define GMM_GCPHYS_UNSHAREABLE UINT64_C(0x0000000fffff1000)
291#endif
292
293
294/**
295 * The allocation sizes.
296 */
297typedef struct GMMVMSIZES
298{
299 /** The number of pages of base memory.
300 * This is the sum of RAM, ROMs and handy pages. */
301 uint64_t cBasePages;
302 /** The number of pages for the shadow pool. (Can be squeezed for memory.) */
303 uint32_t cShadowPages;
304 /** The number of pages for fixed allocations like MMIO2 and the hyper heap. */
305 uint32_t cFixedPages;
306} GMMVMSIZES;
307/** Pointer to a GMMVMSIZES. */
308typedef GMMVMSIZES *PGMMVMSIZES;
309
310
311/**
312 * GMM VM statistics.
313 */
314typedef struct GMMVMSTATS
315{
316 /** The reservations. */
317 GMMVMSIZES Reserved;
318 /** The actual allocations.
319 * This includes both private and shared page allocations. */
320 GMMVMSIZES Allocated;
321
322 /** The current number of private pages. */
323 uint64_t cPrivatePages;
324 /** The current number of shared pages. */
325 uint64_t cSharedPages;
326 /** The current number of ballooned pages. */
327 uint64_t cBalloonedPages;
328 /** The max number of pages that can be ballooned. */
329 uint64_t cMaxBalloonedPages;
330 /** The number of pages we've currently requested the guest to give us.
331 * This is 0 if no pages currently requested. */
332 uint64_t cReqBalloonedPages;
333 /** The number of pages the guest has given us in response to the request.
334 * This is not reset on request completed and may be used in later decisions. */
335 uint64_t cReqActuallyBalloonedPages;
336 /** The number of pages we've currently requested the guest to take back. */
337 uint64_t cReqDeflatePages;
338 /** The number of shareable module tracked by this VM. */
339 uint32_t cShareableModules;
340
341 /** The current over-commitment policy. */
342 GMMOCPOLICY enmPolicy;
343 /** The VM priority for arbitrating VMs in low and out of memory situation.
344 * Like which VMs to start squeezing first. */
345 GMMPRIORITY enmPriority;
346 /** Whether ballooning is enabled or not. */
347 bool fBallooningEnabled;
348 /** Whether shared paging is enabled or not. */
349 bool fSharedPagingEnabled;
350 /** Whether the VM is allowed to allocate memory or not.
351 * This is used when the reservation update request fails or when the VM has
352 * been told to suspend/save/die in an out-of-memory case. */
353 bool fMayAllocate;
354 /** Explicit alignment. */
355 bool afReserved[1];
356
357
358} GMMVMSTATS;
359
360
361/**
362 * The GMM statistics.
363 */
364typedef struct GMMSTATS
365{
366 /** The maximum number of pages we're allowed to allocate
367 * (GMM::cMaxPages). */
368 uint64_t cMaxPages;
369 /** The number of pages that has been reserved (GMM::cReservedPages). */
370 uint64_t cReservedPages;
371 /** The number of pages that we have over-committed in reservations
372 * (GMM::cOverCommittedPages). */
373 uint64_t cOverCommittedPages;
374 /** The number of actually allocated (committed if you like) pages
375 * (GMM::cAllocatedPages). */
376 uint64_t cAllocatedPages;
377 /** The number of pages that are shared. A subset of cAllocatedPages.
378 * (GMM::cSharedPages) */
379 uint64_t cSharedPages;
380 /** The number of pages that are actually shared between VMs.
381 * (GMM:cDuplicatePages) */
382 uint64_t cDuplicatePages;
383 /** The number of pages that are shared that has been left behind by
384 * VMs not doing proper cleanups (GMM::cLeftBehindSharedPages). */
385 uint64_t cLeftBehindSharedPages;
386 /** The number of current ballooned pages (GMM::cBalloonedPages). */
387 uint64_t cBalloonedPages;
388 /** The number of allocation chunks (GMM::cChunks). */
389 uint32_t cChunks;
390 /** The number of freed chunks ever (GMM::cFreedChunks). */
391 uint32_t cFreedChunks;
392 /** The number of shareable modules (GMM:cShareableModules). */
393 uint64_t cShareableModules;
394 /** The current chunk freeing generation use by the per-VM TLB validation (GMM::idFreeGeneration). */
395 uint64_t idFreeGeneration;
396 /** Space reserved for later. */
397 uint64_t au64Reserved[1];
398
399 /** Statistics for the specified VM. (Zero filled if not requested.) */
400 GMMVMSTATS VMStats;
401} GMMSTATS;
402/** Pointer to the GMM statistics. */
403typedef GMMSTATS *PGMMSTATS;
404/** Const pointer to the GMM statistics. */
405typedef const GMMSTATS *PCGMMSTATS;
406
407
408GMMR0DECL(int) GMMR0Init(void);
409GMMR0DECL(void) GMMR0Term(void);
410GMMR0DECL(int) GMMR0InitPerVMData(PGVM pGVM);
411GMMR0DECL(void) GMMR0CleanupVM(PGVM pGVM);
412GMMR0DECL(int) GMMR0InitialReservation(PGVM pGVM, VMCPUID idCpu, uint64_t cBasePages, uint32_t cShadowPages, uint32_t cFixedPages,
413 GMMOCPOLICY enmPolicy, GMMPRIORITY enmPriority);
414GMMR0DECL(int) GMMR0UpdateReservation(PGVM pGVM, VMCPUID idCpu, uint64_t cBasePages, uint32_t cShadowPages, uint32_t cFixedPages);
415GMMR0DECL(int) GMMR0AllocateHandyPages(PGVM pGVM, VMCPUID idCpu, uint32_t cPagesToUpdate,
416 uint32_t cPagesToAlloc, PGMMPAGEDESC paPages);
417GMMR0DECL(int) GMMR0AllocatePages(PGVM pGVM, VMCPUID idCpu, uint32_t cPages, PGMMPAGEDESC paPages, GMMACCOUNT enmAccount);
418GMMR0DECL(int) GMMR0AllocateLargePage(PGVM pGVM, VMCPUID idCpu, uint32_t cbPage, uint32_t *pIdPage, RTHCPHYS *pHCPhys);
419GMMR0DECL(int) GMMR0FreePages(PGVM pGVM, VMCPUID idCpu, uint32_t cPages, PGMMFREEPAGEDESC paPages, GMMACCOUNT enmAccount);
420GMMR0DECL(int) GMMR0FreeLargePage(PGVM pGVM, VMCPUID idCpu, uint32_t idPage);
421GMMR0DECL(int) GMMR0BalloonedPages(PGVM pGVM, VMCPUID idCpu, GMMBALLOONACTION enmAction, uint32_t cBalloonedPages);
422GMMR0DECL(int) GMMR0MapUnmapChunk(PGVM pGVM, uint32_t idChunkMap, uint32_t idChunkUnmap, PRTR3PTR ppvR3);
423GMMR0DECL(int) GMMR0PageIdToVirt(PGVM pGVM, uint32_t idPage, void **ppv);
424GMMR0DECL(int) GMMR0RegisterSharedModule(PGVM pGVM, VMCPUID idCpu, VBOXOSFAMILY enmGuestOS, char *pszModuleName,
425 char *pszVersion, RTGCPTR GCBaseAddr, uint32_t cbModule, uint32_t cRegions,
426 struct VMMDEVSHAREDREGIONDESC const *paRegions);
427GMMR0DECL(int) GMMR0UnregisterSharedModule(PGVM pGVM, VMCPUID idCpu, char *pszModuleName, char *pszVersion,
428 RTGCPTR GCBaseAddr, uint32_t cbModule);
429GMMR0DECL(int) GMMR0UnregisterAllSharedModules(PGVM pGVM, VMCPUID idCpu);
430GMMR0DECL(int) GMMR0CheckSharedModules(PGVM pGVM, VMCPUID idCpu);
431GMMR0DECL(int) GMMR0ResetSharedModules(PGVM pGVM, VMCPUID idCpu);
432GMMR0DECL(int) GMMR0QueryStatistics(PGMMSTATS pStats, PSUPDRVSESSION pSession);
433GMMR0DECL(int) GMMR0ResetStatistics(PCGMMSTATS pStats, PSUPDRVSESSION pSession);
434
435/**
436 * Request buffer for GMMR0InitialReservationReq / VMMR0_DO_GMM_INITIAL_RESERVATION.
437 * @see GMMR0InitialReservation
438 */
439typedef struct GMMINITIALRESERVATIONREQ
440{
441 /** The header. */
442 SUPVMMR0REQHDR Hdr;
443 uint64_t cBasePages; /**< @see GMMR0InitialReservation */
444 uint32_t cShadowPages; /**< @see GMMR0InitialReservation */
445 uint32_t cFixedPages; /**< @see GMMR0InitialReservation */
446 GMMOCPOLICY enmPolicy; /**< @see GMMR0InitialReservation */
447 GMMPRIORITY enmPriority; /**< @see GMMR0InitialReservation */
448} GMMINITIALRESERVATIONREQ;
449/** Pointer to a GMMR0InitialReservationReq / VMMR0_DO_GMM_INITIAL_RESERVATION request buffer. */
450typedef GMMINITIALRESERVATIONREQ *PGMMINITIALRESERVATIONREQ;
451
452GMMR0DECL(int) GMMR0InitialReservationReq(PGVM pGVM, VMCPUID idCpu, PGMMINITIALRESERVATIONREQ pReq);
453
454
455/**
456 * Request buffer for GMMR0UpdateReservationReq / VMMR0_DO_GMM_UPDATE_RESERVATION.
457 * @see GMMR0UpdateReservation
458 */
459typedef struct GMMUPDATERESERVATIONREQ
460{
461 /** The header. */
462 SUPVMMR0REQHDR Hdr;
463 uint64_t cBasePages; /**< @see GMMR0UpdateReservation */
464 uint32_t cShadowPages; /**< @see GMMR0UpdateReservation */
465 uint32_t cFixedPages; /**< @see GMMR0UpdateReservation */
466} GMMUPDATERESERVATIONREQ;
467/** Pointer to a GMMR0InitialReservationReq / VMMR0_DO_GMM_INITIAL_RESERVATION request buffer. */
468typedef GMMUPDATERESERVATIONREQ *PGMMUPDATERESERVATIONREQ;
469
470GMMR0DECL(int) GMMR0UpdateReservationReq(PGVM pGVM, VMCPUID idCpu, PGMMUPDATERESERVATIONREQ pReq);
471
472
473/**
474 * Request buffer for GMMR0AllocatePagesReq / VMMR0_DO_GMM_ALLOCATE_PAGES.
475 * @see GMMR0AllocatePages.
476 */
477typedef struct GMMALLOCATEPAGESREQ
478{
479 /** The header. */
480 SUPVMMR0REQHDR Hdr;
481 /** The account to charge the allocation to. */
482 GMMACCOUNT enmAccount;
483 /** The number of pages to allocate. */
484 uint32_t cPages;
485 /** Array of page descriptors. */
486 GMMPAGEDESC aPages[1];
487} GMMALLOCATEPAGESREQ;
488/** Pointer to a GMMR0AllocatePagesReq / VMMR0_DO_GMM_ALLOCATE_PAGES request buffer. */
489typedef GMMALLOCATEPAGESREQ *PGMMALLOCATEPAGESREQ;
490
491GMMR0DECL(int) GMMR0AllocatePagesReq(PGVM pGVM, VMCPUID idCpu, PGMMALLOCATEPAGESREQ pReq);
492
493
494/**
495 * Request buffer for GMMR0FreePagesReq / VMMR0_DO_GMM_FREE_PAGES.
496 * @see GMMR0FreePages.
497 */
498typedef struct GMMFREEPAGESREQ
499{
500 /** The header. */
501 SUPVMMR0REQHDR Hdr;
502 /** The account this relates to. */
503 GMMACCOUNT enmAccount;
504 /** The number of pages to free. */
505 uint32_t cPages;
506 /** Array of free page descriptors. */
507 GMMFREEPAGEDESC aPages[1];
508} GMMFREEPAGESREQ;
509/** Pointer to a GMMR0FreePagesReq / VMMR0_DO_GMM_FREE_PAGES request buffer. */
510typedef GMMFREEPAGESREQ *PGMMFREEPAGESREQ;
511
512GMMR0DECL(int) GMMR0FreePagesReq(PGVM pGVM, VMCPUID idCpu, PGMMFREEPAGESREQ pReq);
513
514/**
515 * Request buffer for GMMR0BalloonedPagesReq / VMMR0_DO_GMM_BALLOONED_PAGES.
516 * @see GMMR0BalloonedPages.
517 */
518typedef struct GMMBALLOONEDPAGESREQ
519{
520 /** The header. */
521 SUPVMMR0REQHDR Hdr;
522 /** The number of ballooned pages. */
523 uint32_t cBalloonedPages;
524 /** Inflate or deflate the balloon. */
525 GMMBALLOONACTION enmAction;
526} GMMBALLOONEDPAGESREQ;
527/** Pointer to a GMMR0BalloonedPagesReq / VMMR0_DO_GMM_BALLOONED_PAGES request buffer. */
528typedef GMMBALLOONEDPAGESREQ *PGMMBALLOONEDPAGESREQ;
529
530GMMR0DECL(int) GMMR0BalloonedPagesReq(PGVM pGVM, VMCPUID idCpu, PGMMBALLOONEDPAGESREQ pReq);
531
532
533/**
534 * Request buffer for GMMR0QueryHypervisorMemoryStatsReq / VMMR0_DO_GMM_QUERY_VMM_MEM_STATS.
535 * @see GMMR0QueryHypervisorMemoryStatsReq.
536 */
537typedef struct GMMMEMSTATSREQ
538{
539 /** The header. */
540 SUPVMMR0REQHDR Hdr;
541 /** The number of allocated pages (out). */
542 uint64_t cAllocPages;
543 /** The number of free pages (out). */
544 uint64_t cFreePages;
545 /** The number of ballooned pages (out). */
546 uint64_t cBalloonedPages;
547 /** The number of shared pages (out). */
548 uint64_t cSharedPages;
549 /** Maximum nr of pages (out). */
550 uint64_t cMaxPages;
551} GMMMEMSTATSREQ;
552/** Pointer to a GMMR0QueryHypervisorMemoryStatsReq / VMMR0_DO_GMM_QUERY_HYPERVISOR_MEM_STATS request buffer. */
553typedef GMMMEMSTATSREQ *PGMMMEMSTATSREQ;
554
555GMMR0DECL(int) GMMR0QueryHypervisorMemoryStatsReq(PGMMMEMSTATSREQ pReq);
556GMMR0DECL(int) GMMR0QueryMemoryStatsReq(PGVM pGVM, VMCPUID idCpu, PGMMMEMSTATSREQ pReq);
557
558/**
559 * Request buffer for GMMR0MapUnmapChunkReq / VMMR0_DO_GMM_MAP_UNMAP_CHUNK.
560 * @see GMMR0MapUnmapChunk
561 */
562typedef struct GMMMAPUNMAPCHUNKREQ
563{
564 /** The header. */
565 SUPVMMR0REQHDR Hdr;
566 /** The chunk to map, NIL_GMM_CHUNKID if unmap only. (IN) */
567 uint32_t idChunkMap;
568 /** The chunk to unmap, NIL_GMM_CHUNKID if map only. (IN) */
569 uint32_t idChunkUnmap;
570 /** Where the mapping address is returned. (OUT) */
571 RTR3PTR pvR3;
572} GMMMAPUNMAPCHUNKREQ;
573/** Pointer to a GMMR0MapUnmapChunkReq / VMMR0_DO_GMM_MAP_UNMAP_CHUNK request buffer. */
574typedef GMMMAPUNMAPCHUNKREQ *PGMMMAPUNMAPCHUNKREQ;
575
576GMMR0DECL(int) GMMR0MapUnmapChunkReq(PGVM pGVM, PGMMMAPUNMAPCHUNKREQ pReq);
577
578
579/**
580 * Request buffer for GMMR0FreeLargePageReq / VMMR0_DO_GMM_FREE_LARGE_PAGE.
581 * @see GMMR0FreeLargePage.
582 */
583typedef struct GMMFREELARGEPAGEREQ
584{
585 /** The header. */
586 SUPVMMR0REQHDR Hdr;
587 /** The Page ID. */
588 uint32_t idPage;
589} GMMFREELARGEPAGEREQ;
590/** Pointer to a GMMR0FreePagesReq / VMMR0_DO_GMM_FREE_PAGES request buffer. */
591typedef GMMFREELARGEPAGEREQ *PGMMFREELARGEPAGEREQ;
592
593GMMR0DECL(int) GMMR0FreeLargePageReq(PGVM pGVM, VMCPUID idCpu, PGMMFREELARGEPAGEREQ pReq);
594
595/** Maximum length of the shared module name string, terminator included. */
596#define GMM_SHARED_MODULE_MAX_NAME_STRING 128
597/** Maximum length of the shared module version string, terminator included. */
598#define GMM_SHARED_MODULE_MAX_VERSION_STRING 16
599
600/**
601 * Request buffer for GMMR0RegisterSharedModuleReq / VMMR0_DO_GMM_REGISTER_SHARED_MODULE.
602 * @see GMMR0RegisterSharedModule.
603 */
604typedef struct GMMREGISTERSHAREDMODULEREQ
605{
606 /** The header. */
607 SUPVMMR0REQHDR Hdr;
608 /** Shared module size. */
609 uint32_t cbModule;
610 /** Number of included region descriptors */
611 uint32_t cRegions;
612 /** Base address of the shared module. */
613 RTGCPTR64 GCBaseAddr;
614 /** Guest OS type. */
615 VBOXOSFAMILY enmGuestOS;
616 /** return code. */
617 uint32_t rc;
618 /** Module name */
619 char szName[GMM_SHARED_MODULE_MAX_NAME_STRING];
620 /** Module version */
621 char szVersion[GMM_SHARED_MODULE_MAX_VERSION_STRING];
622 /** Shared region descriptor(s). */
623 VMMDEVSHAREDREGIONDESC aRegions[1];
624} GMMREGISTERSHAREDMODULEREQ;
625/** Pointer to a GMMR0RegisterSharedModuleReq / VMMR0_DO_GMM_REGISTER_SHARED_MODULE request buffer. */
626typedef GMMREGISTERSHAREDMODULEREQ *PGMMREGISTERSHAREDMODULEREQ;
627
628GMMR0DECL(int) GMMR0RegisterSharedModuleReq(PGVM pGVM, VMCPUID idCpu, PGMMREGISTERSHAREDMODULEREQ pReq);
629
630/**
631 * Shared region descriptor
632 */
633typedef struct GMMSHAREDREGIONDESC
634{
635 /** The page offset where the region starts. */
636 uint32_t off;
637 /** Region size - adjusted by the region offset and rounded up to a
638 * page. */
639 uint32_t cb;
640 /** Pointer to physical GMM page ID array. */
641 uint32_t *paidPages;
642} GMMSHAREDREGIONDESC;
643/** Pointer to a GMMSHAREDREGIONDESC. */
644typedef GMMSHAREDREGIONDESC *PGMMSHAREDREGIONDESC;
645
646
647/**
648 * Shared module registration info (global)
649 */
650typedef struct GMMSHAREDMODULE
651{
652 /** Tree node (keyed by a hash of name & version). */
653 AVLLU32NODECORE Core;
654 /** Shared module size. */
655 uint32_t cbModule;
656 /** Number of included region descriptors */
657 uint32_t cRegions;
658 /** Number of users (VMs). */
659 uint32_t cUsers;
660 /** Guest OS family type. */
661 VBOXOSFAMILY enmGuestOS;
662 /** Module name */
663 char szName[GMM_SHARED_MODULE_MAX_NAME_STRING];
664 /** Module version */
665 char szVersion[GMM_SHARED_MODULE_MAX_VERSION_STRING];
666 /** Shared region descriptor(s). */
667 GMMSHAREDREGIONDESC aRegions[1];
668} GMMSHAREDMODULE;
669/** Pointer to a GMMSHAREDMODULE. */
670typedef GMMSHAREDMODULE *PGMMSHAREDMODULE;
671
672/**
673 * Page descriptor for GMMR0SharedModuleCheckRange
674 */
675typedef struct GMMSHAREDPAGEDESC
676{
677 /** HC Physical address (in/out) */
678 RTHCPHYS HCPhys;
679 /** GC Physical address (in) */
680 RTGCPHYS GCPhys;
681 /** GMM page id. (in/out) */
682 uint32_t idPage;
683 /** CRC32 of the page in strict builds (0 if page not available).
684 * In non-strict build this serves as structure alignment. */
685 uint32_t u32StrictChecksum;
686} GMMSHAREDPAGEDESC;
687/** Pointer to a GMMSHAREDPAGEDESC. */
688typedef GMMSHAREDPAGEDESC *PGMMSHAREDPAGEDESC;
689
690GMMR0DECL(int) GMMR0SharedModuleCheckPage(PGVM pGVM, PGMMSHAREDMODULE pModule, uint32_t idxRegion, uint32_t idxPage,
691 PGMMSHAREDPAGEDESC pPageDesc);
692
693/**
694 * Request buffer for GMMR0UnregisterSharedModuleReq / VMMR0_DO_GMM_UNREGISTER_SHARED_MODULE.
695 * @see GMMR0UnregisterSharedModule.
696 */
697typedef struct GMMUNREGISTERSHAREDMODULEREQ
698{
699 /** The header. */
700 SUPVMMR0REQHDR Hdr;
701 /** Shared module size. */
702 uint32_t cbModule;
703 /** Align at 8 byte boundary. */
704 uint32_t u32Alignment;
705 /** Base address of the shared module. */
706 RTGCPTR64 GCBaseAddr;
707 /** Module name */
708 char szName[GMM_SHARED_MODULE_MAX_NAME_STRING];
709 /** Module version */
710 char szVersion[GMM_SHARED_MODULE_MAX_VERSION_STRING];
711} GMMUNREGISTERSHAREDMODULEREQ;
712/** Pointer to a GMMR0UnregisterSharedModuleReq / VMMR0_DO_GMM_UNREGISTER_SHARED_MODULE request buffer. */
713typedef GMMUNREGISTERSHAREDMODULEREQ *PGMMUNREGISTERSHAREDMODULEREQ;
714
715GMMR0DECL(int) GMMR0UnregisterSharedModuleReq(PGVM pGVM, VMCPUID idCpu, PGMMUNREGISTERSHAREDMODULEREQ pReq);
716
717#if defined(VBOX_STRICT) && HC_ARCH_BITS == 64
718/**
719 * Request buffer for GMMR0FindDuplicatePageReq / VMMR0_DO_GMM_FIND_DUPLICATE_PAGE.
720 * @see GMMR0FindDuplicatePage.
721 */
722typedef struct GMMFINDDUPLICATEPAGEREQ
723{
724 /** The header. */
725 SUPVMMR0REQHDR Hdr;
726 /** Page id. */
727 uint32_t idPage;
728 /** Duplicate flag (out) */
729 bool fDuplicate;
730} GMMFINDDUPLICATEPAGEREQ;
731/** Pointer to a GMMR0FindDuplicatePageReq / VMMR0_DO_GMM_FIND_DUPLICATE_PAGE request buffer. */
732typedef GMMFINDDUPLICATEPAGEREQ *PGMMFINDDUPLICATEPAGEREQ;
733
734GMMR0DECL(int) GMMR0FindDuplicatePageReq(PGVM pGVM, PGMMFINDDUPLICATEPAGEREQ pReq);
735#endif /* VBOX_STRICT && HC_ARCH_BITS == 64 */
736
737
738/**
739 * Request buffer for GMMR0QueryStatisticsReq / VMMR0_DO_GMM_QUERY_STATISTICS.
740 * @see GMMR0QueryStatistics.
741 */
742typedef struct GMMQUERYSTATISTICSSREQ
743{
744 /** The header. */
745 SUPVMMR0REQHDR Hdr;
746 /** The support driver session. */
747 PSUPDRVSESSION pSession;
748 /** The statistics. */
749 GMMSTATS Stats;
750} GMMQUERYSTATISTICSSREQ;
751/** Pointer to a GMMR0QueryStatisticsReq / VMMR0_DO_GMM_QUERY_STATISTICS
752 * request buffer. */
753typedef GMMQUERYSTATISTICSSREQ *PGMMQUERYSTATISTICSSREQ;
754
755GMMR0DECL(int) GMMR0QueryStatisticsReq(PGVM pGVM, PGMMQUERYSTATISTICSSREQ pReq);
756
757
758/**
759 * Request buffer for GMMR0ResetStatisticsReq / VMMR0_DO_GMM_RESET_STATISTICS.
760 * @see GMMR0ResetStatistics.
761 */
762typedef struct GMMRESETSTATISTICSSREQ
763{
764 /** The header. */
765 SUPVMMR0REQHDR Hdr;
766 /** The support driver session. */
767 PSUPDRVSESSION pSession;
768 /** The statistics to reset.
769 * Any non-zero entry will be reset (if permitted). */
770 GMMSTATS Stats;
771} GMMRESETSTATISTICSSREQ;
772/** Pointer to a GMMR0ResetStatisticsReq / VMMR0_DO_GMM_RESET_STATISTICS
773 * request buffer. */
774typedef GMMRESETSTATISTICSSREQ *PGMMRESETSTATISTICSSREQ;
775
776GMMR0DECL(int) GMMR0ResetStatisticsReq(PGVM pGVM, PGMMRESETSTATISTICSSREQ pReq);
777
778
779
780#ifdef IN_RING3
781/** @defgroup grp_gmm_r3 The Global Memory Manager Ring-3 API Wrappers
782 * @{
783 */
784GMMR3DECL(int) GMMR3InitialReservation(PVM pVM, uint64_t cBasePages, uint32_t cShadowPages, uint32_t cFixedPages,
785 GMMOCPOLICY enmPolicy, GMMPRIORITY enmPriority);
786GMMR3DECL(int) GMMR3UpdateReservation(PVM pVM, uint64_t cBasePages, uint32_t cShadowPages, uint32_t cFixedPages);
787GMMR3DECL(int) GMMR3AllocatePagesPrepare(PVM pVM, PGMMALLOCATEPAGESREQ *ppReq, uint32_t cPages, GMMACCOUNT enmAccount);
788GMMR3DECL(int) GMMR3AllocatePagesPerform(PVM pVM, PGMMALLOCATEPAGESREQ pReq);
789GMMR3DECL(void) GMMR3AllocatePagesCleanup(PGMMALLOCATEPAGESREQ pReq);
790GMMR3DECL(int) GMMR3FreePagesPrepare(PVM pVM, PGMMFREEPAGESREQ *ppReq, uint32_t cPages, GMMACCOUNT enmAccount);
791GMMR3DECL(void) GMMR3FreePagesRePrep(PVM pVM, PGMMFREEPAGESREQ pReq, uint32_t cPages, GMMACCOUNT enmAccount);
792GMMR3DECL(int) GMMR3FreePagesPerform(PVM pVM, PGMMFREEPAGESREQ pReq, uint32_t cActualPages);
793GMMR3DECL(void) GMMR3FreePagesCleanup(PGMMFREEPAGESREQ pReq);
794GMMR3DECL(void) GMMR3FreeAllocatedPages(PVM pVM, GMMALLOCATEPAGESREQ const *pAllocReq);
795GMMR3DECL(int) GMMR3AllocateLargePage(PVM pVM, uint32_t cbPage);
796GMMR3DECL(int) GMMR3FreeLargePage(PVM pVM, uint32_t idPage);
797GMMR3DECL(int) GMMR3MapUnmapChunk(PVM pVM, uint32_t idChunkMap, uint32_t idChunkUnmap, PRTR3PTR ppvR3);
798GMMR3DECL(int) GMMR3QueryHypervisorMemoryStats(PVM pVM, uint64_t *pcTotalAllocPages, uint64_t *pcTotalFreePages, uint64_t *pcTotalBalloonPages, uint64_t *puTotalBalloonSize);
799GMMR3DECL(int) GMMR3QueryMemoryStats(PVM pVM, uint64_t *pcAllocPages, uint64_t *pcMaxPages, uint64_t *pcBalloonPages);
800GMMR3DECL(int) GMMR3BalloonedPages(PVM pVM, GMMBALLOONACTION enmAction, uint32_t cBalloonedPages);
801GMMR3DECL(int) GMMR3RegisterSharedModule(PVM pVM, PGMMREGISTERSHAREDMODULEREQ pReq);
802GMMR3DECL(int) GMMR3UnregisterSharedModule(PVM pVM, PGMMUNREGISTERSHAREDMODULEREQ pReq);
803GMMR3DECL(int) GMMR3CheckSharedModules(PVM pVM);
804GMMR3DECL(int) GMMR3ResetSharedModules(PVM pVM);
805
806# if defined(VBOX_STRICT) && HC_ARCH_BITS == 64
807GMMR3DECL(bool) GMMR3IsDuplicatePage(PVM pVM, uint32_t idPage);
808# endif
809
810/** @} */
811#endif /* IN_RING3 */
812
813/** @} */
814
815RT_C_DECLS_END
816
817#endif /* !VBOX_INCLUDED_vmm_gmm_h */
818
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