VirtualBox

source: vbox/trunk/src/VBox/Devices/VMMDev/VMMDevState.h@ 90447

Last change on this file since 90447 was 90266, checked in by vboxsync, 3 years ago

VMMDev: More heap usage statistics. bugref:9379

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 18.4 KB
Line 
1/* $Id: VMMDevState.h 90266 2021-07-20 20:38:59Z vboxsync $ */
2/** @file
3 * VMMDev - Guest <-> VMM/Host communication device, internal header.
4 */
5
6/*
7 * Copyright (C) 2006-2020 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 VBOX_INCLUDED_SRC_VMMDev_VMMDevState_h
19#define VBOX_INCLUDED_SRC_VMMDev_VMMDevState_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24#include <VBoxVideo.h> /* For VBVA definitions. */
25#include <VBox/VMMDev.h>
26#include <VBox/vmm/pdmdev.h>
27#include <VBox/vmm/pdmifs.h>
28#ifndef VBOX_WITHOUT_TESTING_FEATURES
29# include <iprt/test.h>
30# include <VBox/VMMDevTesting.h>
31#endif
32
33#include <iprt/list.h>
34#include <iprt/memcache.h>
35
36
37#define VMMDEV_WITH_ALT_TIMESYNC
38
39/** Request locking structure (HGCM optimization). */
40typedef struct VMMDEVREQLOCK
41{
42 void *pvReq;
43 PGMPAGEMAPLOCK Lock;
44} VMMDEVREQLOCK;
45/** Pointer to a request lock structure. */
46typedef VMMDEVREQLOCK *PVMMDEVREQLOCK;
47
48typedef struct DISPLAYCHANGEREQUEST
49{
50 bool fPending;
51 bool afAlignment[3];
52 VMMDevDisplayDef displayChangeRequest;
53 VMMDevDisplayDef lastReadDisplayChangeRequest;
54} DISPLAYCHANGEREQUEST;
55
56typedef struct DISPLAYCHANGEDATA
57{
58 /* Which monitor is being reported to the guest. */
59 int32_t iCurrentMonitor;
60
61 /** true if the guest responded to VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST at least once */
62 bool fGuestSentChangeEventAck;
63 bool afAlignment[3];
64
65 DISPLAYCHANGEREQUEST aRequests[VBOX_VIDEO_MAX_SCREENS];
66} DISPLAYCHANGEDATA;
67
68
69/**
70 * Credentials for automatic guest logon and host configured logon (?).
71 *
72 * This is not stored in the same block as the instance data in order to make it
73 * harder to access.
74 */
75typedef struct VMMDEVCREDS
76{
77 /** credentials for guest logon purposes */
78 struct
79 {
80 char szUserName[VMMDEV_CREDENTIALS_SZ_SIZE];
81 char szPassword[VMMDEV_CREDENTIALS_SZ_SIZE];
82 char szDomain[VMMDEV_CREDENTIALS_SZ_SIZE];
83 bool fAllowInteractiveLogon;
84 } Logon;
85
86 /** credentials for verification by guest */
87 struct
88 {
89 char szUserName[VMMDEV_CREDENTIALS_SZ_SIZE];
90 char szPassword[VMMDEV_CREDENTIALS_SZ_SIZE];
91 char szDomain[VMMDEV_CREDENTIALS_SZ_SIZE];
92 } Judge;
93} VMMDEVCREDS;
94
95
96/**
97 * Facility status entry.
98 */
99typedef struct VMMDEVFACILITYSTATUSENTRY
100{
101 /** The facility (may contain values other than the defined ones). */
102 VBoxGuestFacilityType enmFacility;
103 /** The status (may contain values other than the defined ones). */
104 VBoxGuestFacilityStatus enmStatus;
105 /** Whether this entry is fixed and cannot be reused when inactive. */
106 bool fFixed;
107 /** Explicit alignment padding / reserved for future use. MBZ. */
108 bool afPadding[3];
109 /** The facility flags (yet to be defined). */
110 uint32_t fFlags;
111 /** Last update timestamp. */
112 RTTIMESPEC TimeSpecTS;
113} VMMDEVFACILITYSTATUSENTRY;
114/** Pointer to a facility status entry. */
115typedef VMMDEVFACILITYSTATUSENTRY *PVMMDEVFACILITYSTATUSENTRY;
116
117
118/**
119 * State structure for the VMM device.
120 */
121typedef struct VMMDEV
122{
123 /** The critical section for this device.
124 * @remarks We use this rather than the default one, it's simpler with all
125 * the driver interfaces where we have to waste time digging out the
126 * PDMDEVINS structure. */
127 PDMCRITSECT CritSect;
128
129 /** mouse capabilities of host and guest */
130 uint32_t fMouseCapabilities;
131 /** @name Absolute mouse position in pixels
132 * @{ */
133 int32_t xMouseAbs;
134 int32_t yMouseAbs;
135 /** @} */
136 /** Does the guest currently want the host pointer to be shown? */
137 uint32_t fHostCursorRequested;
138
139 /** message buffer for backdoor logging. */
140 char szMsg[512];
141 /** message buffer index. */
142 uint32_t offMsg;
143 /** Alignment padding. */
144 uint32_t u32Alignment2;
145
146 /** Statistics counter for slow IRQ ACK. */
147 STAMCOUNTER StatSlowIrqAck;
148 /** Statistics counter for fast IRQ ACK - R3. */
149 STAMCOUNTER StatFastIrqAckR3;
150 /** Statistics counter for fast IRQ ACK - R0 / RC. */
151 STAMCOUNTER StatFastIrqAckRZ;
152 /** Current host side event flags - VMMDEV_EVENT_XXX. */
153 uint32_t fHostEventFlags;
154 /** Mask of events guest is interested in - VMMDEV_EVENT_XXX.
155 * @note The HGCM events are enabled automatically by the VMMDev device when
156 * guest issues HGCM commands. */
157 uint32_t fGuestFilterMask;
158 /** Delayed mask of guest events - VMMDEV_EVENT_XXX. */
159 uint32_t fNewGuestFilterMask;
160 /** Flag whether fNewGuestFilterMask is valid */
161 bool fNewGuestFilterMaskValid;
162 /** Alignment padding. */
163 bool afAlignment3[3];
164
165 /** Information reported by guest via VMMDevReportGuestInfo generic request.
166 * Until this information is reported the VMMDev refuses any other requests.
167 */
168 VBoxGuestInfo guestInfo;
169 /** Information report \#2, chewed a little. */
170 struct
171 {
172 uint32_t uFullVersion; /**< non-zero if info is present. */
173 uint32_t uRevision;
174 uint32_t fFeatures;
175 char szName[128];
176 } guestInfo2;
177
178 /** Array of guest facility statuses. */
179 VMMDEVFACILITYSTATUSENTRY aFacilityStatuses[32];
180 /** The number of valid entries in the facility status array. */
181 uint32_t cFacilityStatuses;
182
183 /** Information reported by guest via VMMDevReportGuestCapabilities - VMMDEV_GUEST_SUPPORTS_XXX. */
184 uint32_t fGuestCaps;
185
186 /** "Additions are Ok" indicator, set to true after processing VMMDevReportGuestInfo,
187 * if additions version is compatible. This flag is here to avoid repeated comparing
188 * of the version in guestInfo.
189 */
190 uint32_t fu32AdditionsOk;
191
192 /** Video acceleration status set by guest. */
193 uint32_t u32VideoAccelEnabled;
194
195 DISPLAYCHANGEDATA displayChangeData;
196
197 /** memory balloon change request */
198 uint32_t cMbMemoryBalloon;
199 /** The last balloon size queried by the guest additions. */
200 uint32_t cMbMemoryBalloonLast;
201
202 /** guest ram size */
203 uint64_t cbGuestRAM;
204
205 /** unique session id; the id will be different after each start, reset or restore of the VM. */
206 uint64_t idSession;
207
208 /** Statistics interval in seconds. */
209 uint32_t cSecsStatInterval;
210 /** The statistics interval last returned to the guest. */
211 uint32_t cSecsLastStatInterval;
212
213 /** Whether seamless is enabled or not. */
214 bool fSeamlessEnabled;
215 /** The last fSeamlessEnabled state returned to the guest. */
216 bool fLastSeamlessEnabled;
217 bool afAlignment5[1];
218
219 bool fVRDPEnabled;
220 uint32_t uVRDPExperienceLevel;
221
222#ifdef VMMDEV_WITH_ALT_TIMESYNC
223 uint64_t msLatchedHostTime;
224 bool fTimesyncBackdoorLo;
225 bool afAlignment6[1];
226#else
227 bool afAlignment6[2];
228#endif
229
230 /** Set if guest should be allowed to trigger state save and power off. */
231 bool fAllowGuestToSaveState;
232 /** Set if GetHostTime should fail.
233 * Loaded from the GetHostTimeDisabled configuration value. */
234 bool fGetHostTimeDisabled;
235 /** Set if backdoor logging should be disabled (output will be ignored then) */
236 bool fBackdoorLogDisabled;
237 /** Don't clear credentials */
238 bool fKeepCredentials;
239 /** Heap enabled. */
240 bool fHeapEnabled;
241
242 /** Guest Core Dumping enabled. */
243 bool fGuestCoreDumpEnabled;
244 /** Guest Core Dump location. */
245 char szGuestCoreDumpDir[RTPATH_MAX];
246 /** Number of additional cores to keep around. */
247 uint32_t cGuestCoreDumps;
248
249 /** FLag whether CPU hotplug events are monitored */
250 bool fCpuHotPlugEventsEnabled;
251 /** Alignment padding. */
252 bool afPadding8[3];
253 /** CPU hotplug event */
254 VMMDevCpuEventType enmCpuHotPlugEvent;
255 /** Core id of the CPU to change */
256 uint32_t idCpuCore;
257 /** Package id of the CPU to change */
258 uint32_t idCpuPackage;
259
260 uint32_t StatMemBalloonChunks;
261
262 /** Set if testing is enabled. */
263 bool fTestingEnabled;
264 /** Set if testing the MMIO testing range is enabled. */
265 bool fTestingMMIO;
266 /** Alignment padding. */
267 bool afPadding9[HC_ARCH_BITS == 32 ? 2 : 6];
268#ifndef VBOX_WITHOUT_TESTING_FEATURES
269 /** The high timestamp value. */
270 uint32_t u32TestingHighTimestamp;
271 /** The current testing command (VMMDEV_TESTING_CMD_XXX). */
272 uint32_t u32TestingCmd;
273 /** The testing data offset (command specific). */
274 uint32_t offTestingData;
275 /** For buffering the what comes in over the testing data port. */
276 union
277 {
278 char padding[1024];
279
280 /** VMMDEV_TESTING_CMD_INIT, VMMDEV_TESTING_CMD_SUB_NEW,
281 * VMMDEV_TESTING_CMD_FAILED. */
282 struct
283 {
284 char sz[1024];
285 } String, Init, SubNew, Failed;
286
287 /** VMMDEV_TESTING_CMD_TERM, VMMDEV_TESTING_CMD_SUB_DONE. */
288 struct
289 {
290 uint32_t c;
291 } Error, Term, SubDone;
292
293 /** VMMDEV_TESTING_CMD_VALUE. */
294 struct
295 {
296 RTUINT64U u64Value;
297 uint32_t u32Unit;
298 char szName[1024 - 8 - 4];
299 } Value;
300
301 /** The read back register (VMMDEV_TESTING_MMIO_OFF_READBACK,
302 * VMMDEV_TESTING_MMIO_OFF_READBACK_R3). */
303 uint8_t abReadBack[VMMDEV_TESTING_READBACK_SIZE];
304 } TestingData;
305
306 /** Handle for the I/O ports used by the testing component. */
307 IOMIOPORTHANDLE hIoPortTesting;
308 /** Handle for the MMIO region used by the testing component. */
309 IOMMMIOHANDLE hMmioTesting;
310#endif /* !VBOX_WITHOUT_TESTING_FEATURES */
311
312 /** @name Heartbeat
313 * @{ */
314 /** Timestamp of the last heartbeat from guest in nanosec. */
315 uint64_t volatile nsLastHeartbeatTS;
316 /** Indicates whether we missed HB from guest on last check. */
317 bool volatile fFlatlined;
318 /** Indicates whether heartbeat check is active. */
319 bool volatile fHeartbeatActive;
320 /** Alignment padding. */
321 bool afAlignment8[6];
322 /** Guest heartbeat interval in nanoseconds.
323 * This is the interval the guest is told to produce heartbeats at. */
324 uint64_t cNsHeartbeatInterval;
325 /** The amount of time without a heartbeat (nanoseconds) before we
326 * conclude the guest is doing a Dixie Flatline (Neuromancer) impression. */
327 uint64_t cNsHeartbeatTimeout;
328 /** Timer for signalling a flatlined guest. */
329 TMTIMERHANDLE hFlatlinedTimer;
330 /** @} */
331
332 /** Handle for the backdoor logging I/O port. */
333 IOMIOPORTHANDLE hIoPortBackdoorLog;
334 /** Handle for the alternative timesync I/O port. */
335 IOMIOPORTHANDLE hIoPortAltTimesync;
336 /** Handle for the VMM request I/O port (PCI region \#0). */
337 IOMIOPORTHANDLE hIoPortReq;
338 /** Handle for the fast VMM request I/O port (PCI region \#0). */
339 IOMIOPORTHANDLE hIoPortFast;
340 /** Handle for the VMMDev RAM (PCI region \#1). */
341 PGMMMIO2HANDLE hMmio2VMMDevRAM;
342 /** Handle for the VMMDev Heap (PCI region \#2). */
343 PGMMMIO2HANDLE hMmio2Heap;
344} VMMDEV;
345/** Pointer to the shared VMM device state. */
346typedef VMMDEV *PVMMDEV;
347AssertCompileMemberAlignment(VMMDEV, CritSect, 8);
348AssertCompileMemberAlignment(VMMDEV, StatSlowIrqAck, 8);
349AssertCompileMemberAlignment(VMMDEV, cbGuestRAM, 8);
350AssertCompileMemberAlignment(VMMDEV, enmCpuHotPlugEvent, 4);
351AssertCompileMemberAlignment(VMMDEV, aFacilityStatuses, 8);
352#ifndef VBOX_WITHOUT_TESTING_FEATURES
353AssertCompileMemberAlignment(VMMDEV, TestingData.Value.u64Value, 8);
354#endif
355
356
357/** @name VMMDev/HGCM accounting categories (indexes into VMMDEVR3::aHgcmAcc)
358 * @{ */
359/** Legacy, VMMDEV_REQUESTOR_USR_NOT_GIVEN, VMMDEV_REQUESTOR_USR_DRV,
360 * VMMDEV_REQUESTOR_USR_DRV_OTHER. */
361#define VMMDEV_HGCM_CATEGORY_KERNEL 0
362/** VMMDEV_REQUESTOR_USR_ROOT, VMMDEV_REQUESTOR_USR_SYSTEM */
363#define VMMDEV_HGCM_CATEGORY_ROOT 1
364/** VMMDEV_REQUESTOR_USR_RESERVED1, VMMDEV_REQUESTOR_USR_USER,
365 * VMMDEV_REQUESTOR_USR_GUEST */
366#define VMMDEV_HGCM_CATEGORY_USER 2
367/** Array size. */
368#define VMMDEV_HGCM_CATEGORY_MAX 3
369/** @} */
370
371/**
372 * State structure for the VMM device, ring-3 edition.
373 */
374typedef struct VMMDEVR3
375{
376 /** LUN\#0 + Status: VMMDev port base interface. */
377 PDMIBASE IBase;
378 /** LUN\#0: VMMDev port interface. */
379 PDMIVMMDEVPORT IPort;
380#ifdef VBOX_WITH_HGCM
381 /** LUN\#0: HGCM port interface. */
382 PDMIHGCMPORT IHGCMPort;
383 /** HGCM connector interface */
384 R3PTRTYPE(PPDMIHGCMCONNECTOR) pHGCMDrv;
385#endif
386 /** Pointer to base interface of the driver. */
387 R3PTRTYPE(PPDMIBASE) pDrvBase;
388 /** VMMDev connector interface */
389 R3PTRTYPE(PPDMIVMMDEVCONNECTOR) pDrv;
390 /** Pointer to the device instance.
391 * @note Only for interface methods to get their bearings. */
392 PPDMDEVINSR3 pDevIns;
393
394 /** R3 pointer to VMMDev RAM area */
395 R3PTRTYPE(VMMDevMemory *) pVMMDevRAMR3;
396
397 /** R3 pointer to VMMDev Heap RAM area. */
398 R3PTRTYPE(VMMDevMemory *) pVMMDevHeapR3;
399
400 /** Pointer to the credentials. */
401 R3PTRTYPE(VMMDEVCREDS *) pCredentials;
402 /** Set if pCredentials is using the RTMemSafer allocator, clear if heap. */
403 bool fSaferCredentials;
404 bool afAlignment[7];
405
406#ifdef VBOX_WITH_HGCM
407 /** Critical section to protect the list. */
408 RTCRITSECT critsectHGCMCmdList;
409 /** List of pending HGCM requests (VBOXHGCMCMD). */
410 RTLISTANCHORR3 listHGCMCmd;
411 /** Whether the HGCM events are already automatically enabled. */
412 uint32_t u32HGCMEnabled;
413 /** Saved state version of restored commands. */
414 uint32_t uSavedStateVersion;
415 RTMEMCACHE hHgcmCmdCache;
416 /** Accounting by for each requestor VMMDEV_REQUESTOR_USR_XXX group.
417 * Legacy requests ends up with VMMDEV_REQUESTOR_USR_NOT_GIVEN */
418 struct
419 {
420 /** The configured heap budget. */
421 uint64_t cbHeapBudgetConfig;
422 /** The currently available heap budget. */
423 uint64_t cbHeapBudget;
424 /** Message stats. */
425 STAMPROFILE StateMsgHeapUsage;
426 /** Budget overruns. */
427 STAMCOUNTER StatBudgetOverruns;
428 } aHgcmAcc[VMMDEV_HGCM_CATEGORY_MAX];
429 STAMPROFILE StatHgcmCmdArrival;
430 STAMPROFILE StatHgcmCmdCompletion;
431 STAMPROFILE StatHgcmCmdTotal;
432 STAMCOUNTER StatHgcmLargeCmdAllocs;
433 STAMCOUNTER StatHgcmFailedPageListLocking;
434#endif /* VBOX_WITH_HGCM */
435 STAMCOUNTER StatReqBufAllocs;
436 /** Per CPU request 4K sized buffers, allocated as needed. */
437 R3PTRTYPE(VMMDevRequestHeader *) apReqBufs[VMM_MAX_CPU_COUNT];
438
439 /** Status LUN: Shared folders LED */
440 struct
441 {
442 /** The LED. */
443 PDMLED Led;
444 /** The LED ports. */
445 PDMILEDPORTS ILeds;
446 /** Partner of ILeds. */
447 R3PTRTYPE(PPDMILEDCONNECTORS) pLedsConnector;
448 } SharedFolders;
449
450#ifndef VBOX_WITHOUT_TESTING_FEATURES
451 /** The XML output file name (can be a named pipe, doesn't matter to us). */
452 R3PTRTYPE(char *) pszTestingXmlOutput;
453 /** Testing instance for dealing with the output. */
454 RTTEST hTestingTest;
455#endif
456} VMMDEVR3;
457/** Pointer to the ring-3 VMM device state. */
458typedef VMMDEVR3 *PVMMDEVR3;
459
460
461/**
462 * State structure for the VMM device, ring-0 edition.
463 */
464typedef struct VMMDEVR0
465{
466 /** R0 pointer to VMMDev RAM area - first page only, could be NULL! */
467 R0PTRTYPE(VMMDevMemory *) pVMMDevRAMR0;
468} VMMDEVR0;
469/** Pointer to the ring-0 VMM device state. */
470typedef VMMDEVR0 *PVMMDEVR0;
471
472
473/**
474 * State structure for the VMM device, raw-mode edition.
475 */
476typedef struct VMMDEVRC
477{
478 /** R0 pointer to VMMDev RAM area - first page only, could be NULL! */
479 RCPTRTYPE(VMMDevMemory *) pVMMDevRAMRC;
480} VMMDEVRC;
481/** Pointer to the raw-mode VMM device state. */
482typedef VMMDEVRC *PVMMDEVRC;
483
484
485/** @typedef VMMDEVCC
486 * The VMMDEV device data for the current context. */
487typedef CTX_SUFF(VMMDEV) VMMDEVCC;
488/** @typedef PVMMDEVCC
489 * Pointer to the VMMDEV device for the current context. */
490typedef CTX_SUFF(PVMMDEV) PVMMDEVCC;
491
492
493void VMMDevNotifyGuest(PPDMDEVINS pDevIns, PVMMDEV pThis, PVMMDEVCC pThisCC, uint32_t fAddEvents);
494void VMMDevCtlSetGuestFilterMask(PPDMDEVINS pDevIns, PVMMDEV pThis, PVMMDEVCC pThisCC, uint32_t fOrMask, uint32_t fNotMask);
495
496
497/** The saved state version. */
498#define VMMDEV_SAVED_STATE_VERSION VMMDEV_SAVED_STATE_VERSION_HGCM_PARAMS
499/** Updated HGCM commands. */
500#define VMMDEV_SAVED_STATE_VERSION_HGCM_PARAMS 17
501/** The saved state version with heartbeat state. */
502#define VMMDEV_SAVED_STATE_VERSION_HEARTBEAT 16
503/** The saved state version without heartbeat state. */
504#define VMMDEV_SAVED_STATE_VERSION_NO_HEARTBEAT 15
505/** The saved state version which is missing the guest facility statuses. */
506#define VMMDEV_SAVED_STATE_VERSION_MISSING_FACILITY_STATUSES 14
507/** The saved state version which is missing the guestInfo2 bits. */
508#define VMMDEV_SAVED_STATE_VERSION_MISSING_GUEST_INFO_2 13
509/** The saved state version used by VirtualBox 3.0.
510 * This doesn't have the config part. */
511#define VMMDEV_SAVED_STATE_VERSION_VBOX_30 11
512
513#endif /* !VBOX_INCLUDED_SRC_VMMDev_VMMDevState_h */
514
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