VirtualBox

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

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

VMMDev: Do proper heap usage accounting for HGCM requests. bugref:9379

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 17.9 KB
Line 
1/* $Id: VMMDevState.h 90264 2021-07-20 19:37:24Z 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/**
358 * State structure for the VMM device, ring-3 edition.
359 */
360typedef struct VMMDEVR3
361{
362 /** LUN\#0 + Status: VMMDev port base interface. */
363 PDMIBASE IBase;
364 /** LUN\#0: VMMDev port interface. */
365 PDMIVMMDEVPORT IPort;
366#ifdef VBOX_WITH_HGCM
367 /** LUN\#0: HGCM port interface. */
368 PDMIHGCMPORT IHGCMPort;
369 /** HGCM connector interface */
370 R3PTRTYPE(PPDMIHGCMCONNECTOR) pHGCMDrv;
371#endif
372 /** Pointer to base interface of the driver. */
373 R3PTRTYPE(PPDMIBASE) pDrvBase;
374 /** VMMDev connector interface */
375 R3PTRTYPE(PPDMIVMMDEVCONNECTOR) pDrv;
376 /** Pointer to the device instance.
377 * @note Only for interface methods to get their bearings. */
378 PPDMDEVINSR3 pDevIns;
379
380 /** R3 pointer to VMMDev RAM area */
381 R3PTRTYPE(VMMDevMemory *) pVMMDevRAMR3;
382
383 /** R3 pointer to VMMDev Heap RAM area. */
384 R3PTRTYPE(VMMDevMemory *) pVMMDevHeapR3;
385
386 /** Pointer to the credentials. */
387 R3PTRTYPE(VMMDEVCREDS *) pCredentials;
388 /** Set if pCredentials is using the RTMemSafer allocator, clear if heap. */
389 bool fSaferCredentials;
390 bool afAlignment[7];
391
392#ifdef VBOX_WITH_HGCM
393 /** Critical section to protect the list. */
394 RTCRITSECT critsectHGCMCmdList;
395 /** List of pending HGCM requests (VBOXHGCMCMD). */
396 RTLISTANCHORR3 listHGCMCmd;
397 /** Whether the HGCM events are already automatically enabled. */
398 uint32_t u32HGCMEnabled;
399 /** Saved state version of restored commands. */
400 uint32_t uSavedStateVersion;
401 RTMEMCACHE hHgcmCmdCache;
402 /** Accounting by for each requestor VMMDEV_REQUESTOR_USR_XXX group.
403 * Legacy requests ends up with VMMDEV_REQUESTOR_USR_NOT_GIVEN */
404 struct
405 {
406 /** The configured heap budget. */
407 uint64_t cbHeapBudgetConfig;
408 /** The currently available heap budget. */
409 uint64_t cbHeapBudget;
410 /** Total sum of all heap usage. */
411 STAMCOUNTER cbHeapTotal;
412 /** Total number of message. */
413 STAMCOUNTER cTotalMessages;
414 } aHgcmAcc[VMMDEV_REQUESTOR_USR_MASK + 1];
415 STAMPROFILE StatHgcmCmdArrival;
416 STAMPROFILE StatHgcmCmdCompletion;
417 STAMPROFILE StatHgcmCmdTotal;
418 STAMCOUNTER StatHgcmLargeCmdAllocs;
419 STAMCOUNTER StatHgcmFailedPageListLocking;
420#endif /* VBOX_WITH_HGCM */
421 STAMCOUNTER StatReqBufAllocs;
422 /** Per CPU request 4K sized buffers, allocated as needed. */
423 R3PTRTYPE(VMMDevRequestHeader *) apReqBufs[VMM_MAX_CPU_COUNT];
424
425 /** Status LUN: Shared folders LED */
426 struct
427 {
428 /** The LED. */
429 PDMLED Led;
430 /** The LED ports. */
431 PDMILEDPORTS ILeds;
432 /** Partner of ILeds. */
433 R3PTRTYPE(PPDMILEDCONNECTORS) pLedsConnector;
434 } SharedFolders;
435
436#ifndef VBOX_WITHOUT_TESTING_FEATURES
437 /** The XML output file name (can be a named pipe, doesn't matter to us). */
438 R3PTRTYPE(char *) pszTestingXmlOutput;
439 /** Testing instance for dealing with the output. */
440 RTTEST hTestingTest;
441#endif
442} VMMDEVR3;
443/** Pointer to the ring-3 VMM device state. */
444typedef VMMDEVR3 *PVMMDEVR3;
445
446
447/**
448 * State structure for the VMM device, ring-0 edition.
449 */
450typedef struct VMMDEVR0
451{
452 /** R0 pointer to VMMDev RAM area - first page only, could be NULL! */
453 R0PTRTYPE(VMMDevMemory *) pVMMDevRAMR0;
454} VMMDEVR0;
455/** Pointer to the ring-0 VMM device state. */
456typedef VMMDEVR0 *PVMMDEVR0;
457
458
459/**
460 * State structure for the VMM device, raw-mode edition.
461 */
462typedef struct VMMDEVRC
463{
464 /** R0 pointer to VMMDev RAM area - first page only, could be NULL! */
465 RCPTRTYPE(VMMDevMemory *) pVMMDevRAMRC;
466} VMMDEVRC;
467/** Pointer to the raw-mode VMM device state. */
468typedef VMMDEVRC *PVMMDEVRC;
469
470
471/** @typedef VMMDEVCC
472 * The VMMDEV device data for the current context. */
473typedef CTX_SUFF(VMMDEV) VMMDEVCC;
474/** @typedef PVMMDEVCC
475 * Pointer to the VMMDEV device for the current context. */
476typedef CTX_SUFF(PVMMDEV) PVMMDEVCC;
477
478
479void VMMDevNotifyGuest(PPDMDEVINS pDevIns, PVMMDEV pThis, PVMMDEVCC pThisCC, uint32_t fAddEvents);
480void VMMDevCtlSetGuestFilterMask(PPDMDEVINS pDevIns, PVMMDEV pThis, PVMMDEVCC pThisCC, uint32_t fOrMask, uint32_t fNotMask);
481
482
483/** The saved state version. */
484#define VMMDEV_SAVED_STATE_VERSION VMMDEV_SAVED_STATE_VERSION_HGCM_PARAMS
485/** Updated HGCM commands. */
486#define VMMDEV_SAVED_STATE_VERSION_HGCM_PARAMS 17
487/** The saved state version with heartbeat state. */
488#define VMMDEV_SAVED_STATE_VERSION_HEARTBEAT 16
489/** The saved state version without heartbeat state. */
490#define VMMDEV_SAVED_STATE_VERSION_NO_HEARTBEAT 15
491/** The saved state version which is missing the guest facility statuses. */
492#define VMMDEV_SAVED_STATE_VERSION_MISSING_FACILITY_STATUSES 14
493/** The saved state version which is missing the guestInfo2 bits. */
494#define VMMDEV_SAVED_STATE_VERSION_MISSING_GUEST_INFO_2 13
495/** The saved state version used by VirtualBox 3.0.
496 * This doesn't have the config part. */
497#define VMMDEV_SAVED_STATE_VERSION_VBOX_30 11
498
499#endif /* !VBOX_INCLUDED_SRC_VMMDev_VMMDevState_h */
500
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