VirtualBox

source: vbox/trunk/src/VBox/VMM/include/VMXInternal.h@ 92354

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

VMM/include: Seperate some things we require both for HM and the NEM/VMX template on darwin into a dedicated header, bugref:10136

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 19.6 KB
Line 
1/* $Id: VMXInternal.h 92354 2021-11-11 10:56:03Z vboxsync $ */
2/** @file
3 * VMX - Internal header file for the VMX code template.
4 */
5
6/*
7 * Copyright (C) 2006-2021 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_VMXInternal_h
19#define VMM_INCLUDED_SRC_include_VMXInternal_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24#include "HMVMXCommon.h"
25
26#if HC_ARCH_BITS == 32
27# error "32-bit hosts are no longer supported. Go back to 6.0 or earlier!"
28#endif
29
30/** @def HM_PROFILE_EXIT_DISPATCH
31 * Enables profiling of the VM exit handler dispatching. */
32#if 0 || defined(DOXYGEN_RUNNING)
33# define HM_PROFILE_EXIT_DISPATCH
34#endif
35
36RT_C_DECLS_BEGIN
37
38
39/** @defgroup grp_hm_int Internal
40 * @ingroup grp_hm
41 * @internal
42 * @{
43 */
44
45/** @addtogroup grp_hm_int_vmx VMX Internal
46 * @{ */
47/**
48 * VMX VMCS information, shared.
49 *
50 * This structure provides information maintained for and during the executing of a
51 * guest (or nested-guest) VMCS (VM control structure) using hardware-assisted VMX.
52 *
53 * Note! The members here are ordered and aligned based on estimated frequency of
54 * usage and grouped to fit within a cache line in hot code paths. Even subtle
55 * changes here have a noticeable effect in the bootsector benchmarks. Modify with
56 * care.
57 */
58typedef struct VMXVMCSINFOSHARED
59{
60 /** @name Real-mode emulation state.
61 * @{ */
62 /** Set if guest was executing in real mode (extra checks). */
63 bool fWasInRealMode;
64 /** Padding. */
65 bool afPadding0[7];
66 struct
67 {
68 X86DESCATTR AttrCS;
69 X86DESCATTR AttrDS;
70 X86DESCATTR AttrES;
71 X86DESCATTR AttrFS;
72 X86DESCATTR AttrGS;
73 X86DESCATTR AttrSS;
74 X86EFLAGS Eflags;
75 bool fRealOnV86Active;
76 bool afPadding1[3];
77 } RealMode;
78 /** @} */
79
80 /** @name LBR MSR data.
81 * @{ */
82 /** List of LastBranch-From-IP MSRs. */
83 uint64_t au64LbrFromIpMsr[32];
84 /** List of LastBranch-To-IP MSRs. */
85 uint64_t au64LbrToIpMsr[32];
86 /** The MSR containing the index to the most recent branch record. */
87 uint64_t u64LbrTosMsr;
88 /** @} */
89} VMXVMCSINFOSHARED;
90/** Pointer to a VMXVMCSINFOSHARED struct. */
91typedef VMXVMCSINFOSHARED *PVMXVMCSINFOSHARED;
92/** Pointer to a const VMXVMCSINFOSHARED struct. */
93typedef const VMXVMCSINFOSHARED *PCVMXVMCSINFOSHARED;
94AssertCompileSizeAlignment(VMXVMCSINFOSHARED, 8);
95
96
97/**
98 * VMX VMCS information, ring-0 only.
99 *
100 * This structure provides information maintained for and during the executing of a
101 * guest (or nested-guest) VMCS (VM control structure) using hardware-assisted VMX.
102 *
103 * Note! The members here are ordered and aligned based on estimated frequency of
104 * usage and grouped to fit within a cache line in hot code paths. Even subtle
105 * changes here have a noticeable effect in the bootsector benchmarks. Modify with
106 * care.
107 */
108typedef struct VMXVMCSINFO
109{
110 /** Pointer to the bits we share with ring-3. */
111 R3R0PTRTYPE(PVMXVMCSINFOSHARED) pShared;
112
113 /** @name Auxiliary information.
114 * @{ */
115 /** Host-physical address of the EPTP. */
116 RTHCPHYS HCPhysEPTP;
117 /** The VMCS launch state, see VMX_V_VMCS_LAUNCH_STATE_XXX. */
118 uint32_t fVmcsState;
119 /** The VMCS launch state of the shadow VMCS, see VMX_V_VMCS_LAUNCH_STATE_XXX. */
120 uint32_t fShadowVmcsState;
121 /** The host CPU for which its state has been exported to this VMCS. */
122 RTCPUID idHostCpuState;
123 /** The host CPU on which we last executed this VMCS. */
124 RTCPUID idHostCpuExec;
125 /** Number of guest MSRs in the VM-entry MSR-load area. */
126 uint32_t cEntryMsrLoad;
127 /** Number of guest MSRs in the VM-exit MSR-store area. */
128 uint32_t cExitMsrStore;
129 /** Number of host MSRs in the VM-exit MSR-load area. */
130 uint32_t cExitMsrLoad;
131 /** @} */
132
133 /** @name Cache of execution related VMCS fields.
134 * @{ */
135 /** Pin-based VM-execution controls. */
136 uint32_t u32PinCtls;
137 /** Processor-based VM-execution controls. */
138 uint32_t u32ProcCtls;
139 /** Secondary processor-based VM-execution controls. */
140 uint32_t u32ProcCtls2;
141 /** Tertiary processor-based VM-execution controls. */
142 uint64_t u64ProcCtls3;
143 /** VM-entry controls. */
144 uint32_t u32EntryCtls;
145 /** VM-exit controls. */
146 uint32_t u32ExitCtls;
147 /** Exception bitmap. */
148 uint32_t u32XcptBitmap;
149 /** Page-fault exception error-code mask. */
150 uint32_t u32XcptPFMask;
151 /** Page-fault exception error-code match. */
152 uint32_t u32XcptPFMatch;
153 /** Padding. */
154 uint32_t u32Alignment0;
155 /** TSC offset. */
156 uint64_t u64TscOffset;
157 /** VMCS link pointer. */
158 uint64_t u64VmcsLinkPtr;
159 /** CR0 guest/host mask. */
160 uint64_t u64Cr0Mask;
161 /** CR4 guest/host mask. */
162 uint64_t u64Cr4Mask;
163#ifdef IN_RING0
164 /** Current VMX_VMCS_HOST_RIP value (only used in HMR0A.asm). */
165 uint64_t uHostRip;
166 /** Current VMX_VMCS_HOST_RSP value (only used in HMR0A.asm). */
167 uint64_t uHostRsp;
168#endif
169 /** @} */
170
171 /** @name Host-virtual address of VMCS and related data structures.
172 * @{ */
173 /** The VMCS. */
174 R3R0PTRTYPE(void *) pvVmcs;
175 /** The shadow VMCS. */
176 R3R0PTRTYPE(void *) pvShadowVmcs;
177 /** The virtual-APIC page. */
178 R3R0PTRTYPE(uint8_t *) pbVirtApic;
179 /** The MSR bitmap. */
180 R3R0PTRTYPE(void *) pvMsrBitmap;
181 /** The VM-entry MSR-load area. */
182 R3R0PTRTYPE(void *) pvGuestMsrLoad;
183 /** The VM-exit MSR-store area. */
184 R3R0PTRTYPE(void *) pvGuestMsrStore;
185 /** The VM-exit MSR-load area. */
186 R3R0PTRTYPE(void *) pvHostMsrLoad;
187 /** @} */
188
189#ifdef IN_RING0
190 /** @name Host-physical address of VMCS and related data structures.
191 * @{ */
192 /** The VMCS. */
193 RTHCPHYS HCPhysVmcs;
194 /** The shadow VMCS. */
195 RTHCPHYS HCPhysShadowVmcs;
196 /** The virtual APIC page. */
197 RTHCPHYS HCPhysVirtApic;
198 /** The MSR bitmap. */
199 RTHCPHYS HCPhysMsrBitmap;
200 /** The VM-entry MSR-load area. */
201 RTHCPHYS HCPhysGuestMsrLoad;
202 /** The VM-exit MSR-store area. */
203 RTHCPHYS HCPhysGuestMsrStore;
204 /** The VM-exit MSR-load area. */
205 RTHCPHYS HCPhysHostMsrLoad;
206 /** @} */
207
208 /** @name R0-memory objects address for VMCS and related data structures.
209 * @{ */
210 /** R0-memory object for VMCS and related data structures. */
211 RTR0MEMOBJ hMemObj;
212 /** @} */
213#endif
214} VMXVMCSINFO;
215/** Pointer to a VMXVMCSINFOR0 struct. */
216typedef VMXVMCSINFO *PVMXVMCSINFO;
217/** Pointer to a const VMXVMCSINFO struct. */
218typedef const VMXVMCSINFO *PCVMXVMCSINFO;
219AssertCompileSizeAlignment(VMXVMCSINFO, 8);
220AssertCompileMemberAlignment(VMXVMCSINFO, u32PinCtls, 4);
221AssertCompileMemberAlignment(VMXVMCSINFO, u64VmcsLinkPtr, 8);
222AssertCompileMemberAlignment(VMXVMCSINFO, pvVmcs, 8);
223AssertCompileMemberAlignment(VMXVMCSINFO, pvShadowVmcs, 8);
224AssertCompileMemberAlignment(VMXVMCSINFO, pbVirtApic, 8);
225AssertCompileMemberAlignment(VMXVMCSINFO, pvMsrBitmap, 8);
226AssertCompileMemberAlignment(VMXVMCSINFO, pvGuestMsrLoad, 8);
227AssertCompileMemberAlignment(VMXVMCSINFO, pvGuestMsrStore, 8);
228AssertCompileMemberAlignment(VMXVMCSINFO, pvHostMsrLoad, 8);
229#ifdef IN_RING0
230AssertCompileMemberAlignment(VMXVMCSINFO, HCPhysVmcs, 8);
231AssertCompileMemberAlignment(VMXVMCSINFO, hMemObj, 8);
232#endif
233
234
235/**
236 * VMX per-VCPU transient state.
237 *
238 * A state structure for holding miscellaneous information across
239 * VMX non-root operation and restored after the transition.
240 *
241 * Note: The members are ordered and aligned such that the most
242 * frequently used ones (in the guest execution loop) fall within
243 * the first cache line.
244 */
245typedef struct VMXTRANSIENT
246{
247 /** Mask of currently read VMCS fields; HMVMX_READ_XXX. */
248 uint32_t fVmcsFieldsRead;
249 /** The guest's TPR value used for TPR shadowing. */
250 uint8_t u8GuestTpr;
251 uint8_t abAlignment0[3];
252
253 /** Whether the VM-exit was caused by a page-fault during delivery of an
254 * external interrupt or NMI. */
255 bool fVectoringPF;
256 /** Whether the VM-exit was caused by a page-fault during delivery of a
257 * contributory exception or a page-fault. */
258 bool fVectoringDoublePF;
259 /** Whether the VM-entry failed or not. */
260 bool fVMEntryFailed;
261 /** Whether the TSC_AUX MSR needs to be removed from the auto-load/store MSR
262 * area after VM-exit. */
263 bool fRemoveTscAuxMsr;
264 /** Whether TSC-offsetting and VMX-preemption timer was updated before VM-entry. */
265 bool fUpdatedTscOffsettingAndPreemptTimer;
266 /** Whether we are currently executing a nested-guest. */
267 bool fIsNestedGuest;
268 /** Whether the guest debug state was active at the time of VM-exit. */
269 bool fWasGuestDebugStateActive;
270 /** Whether the hyper debug state was active at the time of VM-exit. */
271 bool fWasHyperDebugStateActive;
272
273 /** The basic VM-exit reason. */
274 uint32_t uExitReason;
275 /** The VM-exit interruption error code. */
276 uint32_t uExitIntErrorCode;
277
278 /** The host's rflags/eflags. */
279 RTCCUINTREG fEFlags;
280
281 /** The VM-exit exit code qualification. */
282 uint64_t uExitQual;
283
284 /** The VMCS info. object. */
285 PVMXVMCSINFO pVmcsInfo;
286
287 /** The VM-exit interruption-information field. */
288 uint32_t uExitIntInfo;
289 /** The VM-exit instruction-length field. */
290 uint32_t cbExitInstr;
291
292 /** The VM-exit instruction-information field. */
293 VMXEXITINSTRINFO ExitInstrInfo;
294 /** IDT-vectoring information field. */
295 uint32_t uIdtVectoringInfo;
296
297 /** IDT-vectoring error code. */
298 uint32_t uIdtVectoringErrorCode;
299 uint32_t u32Alignment0;
300
301 /** The Guest-linear address. */
302 uint64_t uGuestLinearAddr;
303
304 /** The Guest-physical address. */
305 uint64_t uGuestPhysicalAddr;
306
307 /** The Guest pending-debug exceptions. */
308 uint64_t uGuestPendingDbgXcpts;
309
310 /** The VM-entry interruption-information field. */
311 uint32_t uEntryIntInfo;
312 /** The VM-entry exception error code field. */
313 uint32_t uEntryXcptErrorCode;
314
315 /** The VM-entry instruction length field. */
316 uint32_t cbEntryInstr;
317} VMXTRANSIENT;
318AssertCompileMemberSize(VMXTRANSIENT, ExitInstrInfo, sizeof(uint32_t));
319AssertCompileMemberAlignment(VMXTRANSIENT, fVmcsFieldsRead, 8);
320AssertCompileMemberAlignment(VMXTRANSIENT, fVectoringPF, 8);
321AssertCompileMemberAlignment(VMXTRANSIENT, uExitReason, 8);
322AssertCompileMemberAlignment(VMXTRANSIENT, fEFlags, 8);
323AssertCompileMemberAlignment(VMXTRANSIENT, uExitQual, 8);
324AssertCompileMemberAlignment(VMXTRANSIENT, pVmcsInfo, 8);
325AssertCompileMemberAlignment(VMXTRANSIENT, uExitIntInfo, 8);
326AssertCompileMemberAlignment(VMXTRANSIENT, ExitInstrInfo, 8);
327AssertCompileMemberAlignment(VMXTRANSIENT, uIdtVectoringErrorCode, 8);
328AssertCompileMemberAlignment(VMXTRANSIENT, uGuestLinearAddr, 8);
329AssertCompileMemberAlignment(VMXTRANSIENT, uGuestPhysicalAddr, 8);
330AssertCompileMemberAlignment(VMXTRANSIENT, uEntryIntInfo, 8);
331AssertCompileMemberAlignment(VMXTRANSIENT, cbEntryInstr, 8);
332/** Pointer to VMX transient state. */
333typedef VMXTRANSIENT *PVMXTRANSIENT;
334/** Pointer to a const VMX transient state. */
335typedef const VMXTRANSIENT *PCVMXTRANSIENT;
336
337
338/**
339 * VMX statistics structure.
340 */
341typedef struct VMXSTATISTICS
342{
343 /* These two comes because they are accessed from assembly and we don't
344 want to detail all the stats in the assembly version of this structure. */
345 STAMCOUNTER StatVmxWriteHostRip;
346 STAMCOUNTER StatVmxWriteHostRsp;
347 STAMCOUNTER StatVmxVmLaunch;
348 STAMCOUNTER StatVmxVmResume;
349
350 STAMPROFILEADV StatEntry;
351 STAMPROFILEADV StatPreExit;
352 STAMPROFILEADV StatExitHandling;
353 STAMPROFILEADV StatExitIO;
354 STAMPROFILEADV StatExitMovCRx;
355 STAMPROFILEADV StatExitXcptNmi;
356 STAMPROFILEADV StatExitVmentry;
357 STAMPROFILEADV StatImportGuestState;
358 STAMPROFILEADV StatExportGuestState;
359 STAMPROFILEADV StatLoadGuestFpuState;
360 STAMPROFILEADV StatInGC;
361 STAMPROFILEADV StatPoke;
362 STAMPROFILEADV StatSpinPoke;
363 STAMPROFILEADV StatSpinPokeFailed;
364
365 STAMCOUNTER StatInjectInterrupt;
366 STAMCOUNTER StatInjectXcpt;
367 STAMCOUNTER StatInjectReflect;
368 STAMCOUNTER StatInjectConvertDF;
369 STAMCOUNTER StatInjectInterpret;
370 STAMCOUNTER StatInjectReflectNPF;
371
372 STAMCOUNTER StatExitAll;
373 STAMCOUNTER StatNestedExitAll;
374 STAMCOUNTER StatExitShadowNM;
375 STAMCOUNTER StatExitGuestNM;
376 STAMCOUNTER StatExitShadowPF; /**< Misleading, currently used for MMIO \#PFs as well. */
377 STAMCOUNTER StatExitShadowPFEM;
378 STAMCOUNTER StatExitGuestPF;
379 STAMCOUNTER StatExitGuestUD;
380 STAMCOUNTER StatExitGuestSS;
381 STAMCOUNTER StatExitGuestNP;
382 STAMCOUNTER StatExitGuestTS;
383 STAMCOUNTER StatExitGuestOF;
384 STAMCOUNTER StatExitGuestGP;
385 STAMCOUNTER StatExitGuestDE;
386 STAMCOUNTER StatExitGuestDF;
387 STAMCOUNTER StatExitGuestBR;
388 STAMCOUNTER StatExitGuestAC;
389 STAMCOUNTER StatExitGuestACSplitLock;
390 STAMCOUNTER StatExitGuestDB;
391 STAMCOUNTER StatExitGuestMF;
392 STAMCOUNTER StatExitGuestBP;
393 STAMCOUNTER StatExitGuestXF;
394 STAMCOUNTER StatExitGuestXcpUnk;
395 STAMCOUNTER StatExitDRxWrite;
396 STAMCOUNTER StatExitDRxRead;
397 STAMCOUNTER StatExitCR0Read;
398 STAMCOUNTER StatExitCR2Read;
399 STAMCOUNTER StatExitCR3Read;
400 STAMCOUNTER StatExitCR4Read;
401 STAMCOUNTER StatExitCR8Read;
402 STAMCOUNTER StatExitCR0Write;
403 STAMCOUNTER StatExitCR2Write;
404 STAMCOUNTER StatExitCR3Write;
405 STAMCOUNTER StatExitCR4Write;
406 STAMCOUNTER StatExitCR8Write;
407 STAMCOUNTER StatExitRdmsr;
408 STAMCOUNTER StatExitWrmsr;
409 STAMCOUNTER StatExitClts;
410 STAMCOUNTER StatExitXdtrAccess;
411 STAMCOUNTER StatExitLmsw;
412 STAMCOUNTER StatExitIOWrite;
413 STAMCOUNTER StatExitIORead;
414 STAMCOUNTER StatExitIOStringWrite;
415 STAMCOUNTER StatExitIOStringRead;
416 STAMCOUNTER StatExitIntWindow;
417 STAMCOUNTER StatExitExtInt;
418 STAMCOUNTER StatExitHostNmiInGC;
419 STAMCOUNTER StatExitHostNmiInGCIpi;
420 STAMCOUNTER StatExitPreemptTimer;
421 STAMCOUNTER StatExitTprBelowThreshold;
422 STAMCOUNTER StatExitTaskSwitch;
423 STAMCOUNTER StatExitApicAccess;
424 STAMCOUNTER StatExitReasonNpf;
425
426 STAMCOUNTER StatNestedExitReasonNpf;
427
428 STAMCOUNTER StatFlushPage;
429 STAMCOUNTER StatFlushPageManual;
430 STAMCOUNTER StatFlushPhysPageManual;
431 STAMCOUNTER StatFlushTlb;
432 STAMCOUNTER StatFlushTlbNstGst;
433 STAMCOUNTER StatFlushTlbManual;
434 STAMCOUNTER StatFlushTlbWorldSwitch;
435 STAMCOUNTER StatNoFlushTlbWorldSwitch;
436 STAMCOUNTER StatFlushEntire;
437 STAMCOUNTER StatFlushAsid;
438 STAMCOUNTER StatFlushNestedPaging;
439 STAMCOUNTER StatFlushTlbInvlpgVirt;
440 STAMCOUNTER StatFlushTlbInvlpgPhys;
441 STAMCOUNTER StatTlbShootdown;
442 STAMCOUNTER StatTlbShootdownFlush;
443
444 STAMCOUNTER StatSwitchPendingHostIrq;
445 STAMCOUNTER StatSwitchTprMaskedIrq;
446 STAMCOUNTER StatSwitchGuestIrq;
447 STAMCOUNTER StatSwitchHmToR3FF;
448 STAMCOUNTER StatSwitchVmReq;
449 STAMCOUNTER StatSwitchPgmPoolFlush;
450 STAMCOUNTER StatSwitchDma;
451 STAMCOUNTER StatSwitchExitToR3;
452 STAMCOUNTER StatSwitchLongJmpToR3;
453 STAMCOUNTER StatSwitchMaxResumeLoops;
454 STAMCOUNTER StatSwitchHltToR3;
455 STAMCOUNTER StatSwitchApicAccessToR3;
456 STAMCOUNTER StatSwitchPreempt;
457 STAMCOUNTER StatSwitchNstGstVmexit;
458
459 STAMCOUNTER StatTscParavirt;
460 STAMCOUNTER StatTscOffset;
461 STAMCOUNTER StatTscIntercept;
462
463 STAMCOUNTER StatDRxArmed;
464 STAMCOUNTER StatDRxContextSwitch;
465 STAMCOUNTER StatDRxIoCheck;
466
467 STAMCOUNTER StatExportMinimal;
468 STAMCOUNTER StatExportFull;
469 STAMCOUNTER StatLoadGuestFpu;
470 STAMCOUNTER StatExportHostState;
471
472 STAMCOUNTER StatVmxCheckBadRmSelBase;
473 STAMCOUNTER StatVmxCheckBadRmSelLimit;
474 STAMCOUNTER StatVmxCheckBadRmSelAttr;
475 STAMCOUNTER StatVmxCheckBadV86SelBase;
476 STAMCOUNTER StatVmxCheckBadV86SelLimit;
477 STAMCOUNTER StatVmxCheckBadV86SelAttr;
478 STAMCOUNTER StatVmxCheckRmOk;
479 STAMCOUNTER StatVmxCheckBadSel;
480 STAMCOUNTER StatVmxCheckBadRpl;
481 STAMCOUNTER StatVmxCheckPmOk;
482
483 STAMCOUNTER StatVmxPreemptionRecalcingDeadline;
484 STAMCOUNTER StatVmxPreemptionRecalcingDeadlineExpired;
485 STAMCOUNTER StatVmxPreemptionReusingDeadline;
486 STAMCOUNTER StatVmxPreemptionReusingDeadlineExpired;
487
488#ifdef VBOX_WITH_STATISTICS
489 STAMCOUNTER aStatExitReason[MAX_EXITREASON_STAT];
490 STAMCOUNTER aStatNestedExitReason[MAX_EXITREASON_STAT];
491 STAMCOUNTER aStatInjectedIrqs[256];
492 STAMCOUNTER aStatInjectedXcpts[X86_XCPT_LAST + 1];
493#endif
494#ifdef HM_PROFILE_EXIT_DISPATCH
495 STAMPROFILEADV StatExitDispatch;
496#endif
497} VMXSTATISTICS;
498/** Pointer to the VMX statistics. */
499typedef VMXSTATISTICS *PVMXSTATISTICS;
500/** Pointer to a const VMX statistics structure. */
501typedef const VMXSTATISTICS *PCVMXSTATISTICS;
502
503/** @} */
504
505/** @} */
506
507RT_C_DECLS_END
508
509#endif /* !VMM_INCLUDED_SRC_include_VMXInternal_h */
510
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