1 | /* $Id: VMXInternal.h 103053 2024-01-25 09:16:55Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VMX - Internal header file for the VMX code template.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | #ifndef VMM_INCLUDED_SRC_include_VMXInternal_h
|
---|
29 | #define VMM_INCLUDED_SRC_include_VMXInternal_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | #include "HMVMXCommon.h"
|
---|
35 |
|
---|
36 | #if HC_ARCH_BITS == 32
|
---|
37 | # error "32-bit hosts are no longer supported. Go back to 6.0 or earlier!"
|
---|
38 | #endif
|
---|
39 |
|
---|
40 | /** @def HM_PROFILE_EXIT_DISPATCH
|
---|
41 | * Enables profiling of the VM exit handler dispatching. */
|
---|
42 | #if 0 || defined(DOXYGEN_RUNNING)
|
---|
43 | # define HM_PROFILE_EXIT_DISPATCH
|
---|
44 | #endif
|
---|
45 |
|
---|
46 | RT_C_DECLS_BEGIN
|
---|
47 |
|
---|
48 |
|
---|
49 | /** @defgroup grp_hm_int Internal
|
---|
50 | * @ingroup grp_hm
|
---|
51 | * @internal
|
---|
52 | * @{
|
---|
53 | */
|
---|
54 |
|
---|
55 | /** @addtogroup grp_hm_int_vmx VMX Internal
|
---|
56 | * @{ */
|
---|
57 | /**
|
---|
58 | * VMX per-VCPU transient state.
|
---|
59 | *
|
---|
60 | * A state structure for holding miscellaneous information across
|
---|
61 | * VMX non-root operation and restored after the transition.
|
---|
62 | *
|
---|
63 | * Note: The members are ordered and aligned such that the most
|
---|
64 | * frequently used ones (in the guest execution loop) fall within
|
---|
65 | * the first cache line.
|
---|
66 | */
|
---|
67 | typedef struct VMXTRANSIENT
|
---|
68 | {
|
---|
69 | /** Mask of currently read VMCS fields; HMVMX_READ_XXX. */
|
---|
70 | uint32_t fVmcsFieldsRead;
|
---|
71 | /** The guest's TPR value used for TPR shadowing. */
|
---|
72 | uint8_t u8GuestTpr;
|
---|
73 | uint8_t abAlignment0[3];
|
---|
74 |
|
---|
75 | /** Whether the VM-exit was caused by a page-fault during delivery of an
|
---|
76 | * external interrupt or NMI. */
|
---|
77 | bool fVectoringPF;
|
---|
78 | /** Whether the VM-exit was caused by a page-fault during delivery of a
|
---|
79 | * contributory exception or a page-fault. */
|
---|
80 | bool fVectoringDoublePF;
|
---|
81 | /** Whether the VM-entry failed or not. */
|
---|
82 | bool fVMEntryFailed;
|
---|
83 | /** Whether the TSC_AUX MSR needs to be removed from the auto-load/store MSR
|
---|
84 | * area after VM-exit. */
|
---|
85 | bool fRemoveTscAuxMsr;
|
---|
86 | /** Whether TSC-offsetting and VMX-preemption timer was updated before VM-entry. */
|
---|
87 | bool fUpdatedTscOffsettingAndPreemptTimer;
|
---|
88 | /** Whether we are currently executing a nested-guest. */
|
---|
89 | bool fIsNestedGuest;
|
---|
90 | /** Whether the guest debug state was active at the time of VM-exit. */
|
---|
91 | bool fWasGuestDebugStateActive;
|
---|
92 | /** Whether the hyper debug state was active at the time of VM-exit. */
|
---|
93 | bool fWasHyperDebugStateActive;
|
---|
94 |
|
---|
95 | /** The basic VM-exit reason. */
|
---|
96 | uint32_t uExitReason;
|
---|
97 | /** The VM-exit interruption error code. */
|
---|
98 | uint32_t uExitIntErrorCode;
|
---|
99 |
|
---|
100 | /** The host's rflags/eflags. */
|
---|
101 | RTCCUINTREG fEFlags;
|
---|
102 |
|
---|
103 | /** The VM-exit exit code qualification. */
|
---|
104 | uint64_t uExitQual;
|
---|
105 |
|
---|
106 | /** The VMCS info. object. */
|
---|
107 | PVMXVMCSINFO pVmcsInfo;
|
---|
108 |
|
---|
109 | /** The VM-exit interruption-information field. */
|
---|
110 | uint32_t uExitIntInfo;
|
---|
111 | /** The VM-exit instruction-length field. */
|
---|
112 | uint32_t cbExitInstr;
|
---|
113 |
|
---|
114 | /** The VM-exit instruction-information field. */
|
---|
115 | VMXEXITINSTRINFO ExitInstrInfo;
|
---|
116 | /** IDT-vectoring information field. */
|
---|
117 | uint32_t uIdtVectoringInfo;
|
---|
118 |
|
---|
119 | /** IDT-vectoring error code. */
|
---|
120 | uint32_t uIdtVectoringErrorCode;
|
---|
121 | uint32_t u32Alignment0;
|
---|
122 |
|
---|
123 | /** The Guest-linear address. */
|
---|
124 | uint64_t uGuestLinearAddr;
|
---|
125 |
|
---|
126 | /** The Guest-physical address. */
|
---|
127 | uint64_t uGuestPhysicalAddr;
|
---|
128 |
|
---|
129 | /** The Guest pending-debug exceptions. */
|
---|
130 | uint64_t uGuestPendingDbgXcpts;
|
---|
131 |
|
---|
132 | /** The VM-entry interruption-information field. */
|
---|
133 | uint32_t uEntryIntInfo;
|
---|
134 | /** The VM-entry exception error code field. */
|
---|
135 | uint32_t uEntryXcptErrorCode;
|
---|
136 |
|
---|
137 | /** The VM-entry instruction length field. */
|
---|
138 | uint32_t cbEntryInstr;
|
---|
139 | } VMXTRANSIENT;
|
---|
140 | AssertCompileMemberSize(VMXTRANSIENT, ExitInstrInfo, sizeof(uint32_t));
|
---|
141 | AssertCompileMemberAlignment(VMXTRANSIENT, fVmcsFieldsRead, 8);
|
---|
142 | AssertCompileMemberAlignment(VMXTRANSIENT, fVectoringPF, 8);
|
---|
143 | AssertCompileMemberAlignment(VMXTRANSIENT, uExitReason, 8);
|
---|
144 | AssertCompileMemberAlignment(VMXTRANSIENT, fEFlags, 8);
|
---|
145 | AssertCompileMemberAlignment(VMXTRANSIENT, uExitQual, 8);
|
---|
146 | AssertCompileMemberAlignment(VMXTRANSIENT, pVmcsInfo, 8);
|
---|
147 | AssertCompileMemberAlignment(VMXTRANSIENT, uExitIntInfo, 8);
|
---|
148 | AssertCompileMemberAlignment(VMXTRANSIENT, ExitInstrInfo, 8);
|
---|
149 | AssertCompileMemberAlignment(VMXTRANSIENT, uIdtVectoringErrorCode, 8);
|
---|
150 | AssertCompileMemberAlignment(VMXTRANSIENT, uGuestLinearAddr, 8);
|
---|
151 | AssertCompileMemberAlignment(VMXTRANSIENT, uGuestPhysicalAddr, 8);
|
---|
152 | AssertCompileMemberAlignment(VMXTRANSIENT, uEntryIntInfo, 8);
|
---|
153 | AssertCompileMemberAlignment(VMXTRANSIENT, cbEntryInstr, 8);
|
---|
154 | /** Pointer to VMX transient state. */
|
---|
155 | typedef VMXTRANSIENT *PVMXTRANSIENT;
|
---|
156 | /** Pointer to a const VMX transient state. */
|
---|
157 | typedef const VMXTRANSIENT *PCVMXTRANSIENT;
|
---|
158 |
|
---|
159 |
|
---|
160 | /**
|
---|
161 | * VMX statistics structure.
|
---|
162 | */
|
---|
163 | typedef struct VMXSTATISTICS
|
---|
164 | {
|
---|
165 | /* These two comes because they are accessed from assembly and we don't
|
---|
166 | want to detail all the stats in the assembly version of this structure. */
|
---|
167 | STAMCOUNTER StatVmxWriteHostRip;
|
---|
168 | STAMCOUNTER StatVmxWriteHostRsp;
|
---|
169 | STAMCOUNTER StatVmxVmLaunch;
|
---|
170 | STAMCOUNTER StatVmxVmResume;
|
---|
171 |
|
---|
172 | STAMPROFILEADV StatEntry;
|
---|
173 | STAMPROFILEADV StatPreExit;
|
---|
174 | STAMPROFILEADV StatExitHandling;
|
---|
175 | STAMPROFILEADV StatExitIO;
|
---|
176 | STAMPROFILEADV StatExitMovCRx;
|
---|
177 | STAMPROFILEADV StatExitXcptNmi;
|
---|
178 | STAMPROFILEADV StatExitVmentry;
|
---|
179 | STAMPROFILEADV StatImportGuestState;
|
---|
180 | STAMPROFILEADV StatExportGuestState;
|
---|
181 | STAMPROFILEADV StatLoadGuestFpuState;
|
---|
182 | STAMPROFILEADV StatInGC;
|
---|
183 | STAMPROFILEADV StatPoke;
|
---|
184 | STAMPROFILEADV StatSpinPoke;
|
---|
185 | STAMPROFILEADV StatSpinPokeFailed;
|
---|
186 |
|
---|
187 | STAMCOUNTER StatImportGuestStateFallback;
|
---|
188 | STAMCOUNTER StatReadToTransientFallback;
|
---|
189 |
|
---|
190 | STAMCOUNTER StatInjectInterrupt;
|
---|
191 | STAMCOUNTER StatInjectXcpt;
|
---|
192 | STAMCOUNTER StatInjectReflect;
|
---|
193 | STAMCOUNTER StatInjectConvertDF;
|
---|
194 | STAMCOUNTER StatInjectInterpret;
|
---|
195 | STAMCOUNTER StatInjectReflectNPF;
|
---|
196 |
|
---|
197 | STAMCOUNTER StatExitAll;
|
---|
198 | STAMCOUNTER StatNestedExitAll;
|
---|
199 | STAMCOUNTER StatExitShadowNM;
|
---|
200 | STAMCOUNTER StatExitGuestNM;
|
---|
201 | STAMCOUNTER StatExitShadowPF; /**< Misleading, currently used for MMIO \#PFs as well. */
|
---|
202 | STAMCOUNTER StatExitShadowPFEM;
|
---|
203 | STAMCOUNTER StatExitGuestPF;
|
---|
204 | STAMCOUNTER StatExitGuestUD;
|
---|
205 | STAMCOUNTER StatExitGuestSS;
|
---|
206 | STAMCOUNTER StatExitGuestNP;
|
---|
207 | STAMCOUNTER StatExitGuestTS;
|
---|
208 | STAMCOUNTER StatExitGuestOF;
|
---|
209 | STAMCOUNTER StatExitGuestGP;
|
---|
210 | STAMCOUNTER StatExitGuestDE;
|
---|
211 | STAMCOUNTER StatExitGuestDF;
|
---|
212 | STAMCOUNTER StatExitGuestBR;
|
---|
213 | STAMCOUNTER StatExitGuestAC;
|
---|
214 | STAMCOUNTER StatExitGuestACSplitLock;
|
---|
215 | STAMCOUNTER StatExitGuestDB;
|
---|
216 | STAMCOUNTER StatExitGuestMF;
|
---|
217 | STAMCOUNTER StatExitGuestBP;
|
---|
218 | STAMCOUNTER StatExitGuestXF;
|
---|
219 | STAMCOUNTER StatExitGuestXcpUnk;
|
---|
220 | STAMCOUNTER StatExitDRxWrite;
|
---|
221 | STAMCOUNTER StatExitDRxRead;
|
---|
222 | STAMCOUNTER StatExitCR0Read;
|
---|
223 | STAMCOUNTER StatExitCR2Read;
|
---|
224 | STAMCOUNTER StatExitCR3Read;
|
---|
225 | STAMCOUNTER StatExitCR4Read;
|
---|
226 | STAMCOUNTER StatExitCR8Read;
|
---|
227 | STAMCOUNTER StatExitCR0Write;
|
---|
228 | STAMCOUNTER StatExitCR2Write;
|
---|
229 | STAMCOUNTER StatExitCR3Write;
|
---|
230 | STAMCOUNTER StatExitCR4Write;
|
---|
231 | STAMCOUNTER StatExitCR8Write;
|
---|
232 | STAMCOUNTER StatExitRdmsr;
|
---|
233 | STAMCOUNTER StatExitWrmsr;
|
---|
234 | STAMCOUNTER StatExitClts;
|
---|
235 | STAMCOUNTER StatExitXdtrAccess;
|
---|
236 | STAMCOUNTER StatExitLmsw;
|
---|
237 | STAMCOUNTER StatExitIOWrite;
|
---|
238 | STAMCOUNTER StatExitIORead;
|
---|
239 | STAMCOUNTER StatExitIOStringWrite;
|
---|
240 | STAMCOUNTER StatExitIOStringRead;
|
---|
241 | STAMCOUNTER StatExitIntWindow;
|
---|
242 | STAMCOUNTER StatExitExtInt;
|
---|
243 | STAMCOUNTER StatExitHostNmiInGC;
|
---|
244 | STAMCOUNTER StatExitHostNmiInGCIpi;
|
---|
245 | STAMCOUNTER StatExitPreemptTimer;
|
---|
246 | STAMCOUNTER StatExitTprBelowThreshold;
|
---|
247 | STAMCOUNTER StatExitTaskSwitch;
|
---|
248 | STAMCOUNTER StatExitApicAccess;
|
---|
249 | STAMCOUNTER StatExitReasonNpf;
|
---|
250 |
|
---|
251 | STAMCOUNTER StatNestedExitReasonNpf;
|
---|
252 | STAMCOUNTER StatNestedExitACSplitLock;
|
---|
253 |
|
---|
254 | STAMCOUNTER StatFlushPage;
|
---|
255 | STAMCOUNTER StatFlushPageManual;
|
---|
256 | STAMCOUNTER StatFlushPhysPageManual;
|
---|
257 | STAMCOUNTER StatFlushTlb;
|
---|
258 | STAMCOUNTER StatFlushTlbNstGst;
|
---|
259 | STAMCOUNTER StatFlushTlbManual;
|
---|
260 | STAMCOUNTER StatFlushTlbWorldSwitch;
|
---|
261 | STAMCOUNTER StatNoFlushTlbWorldSwitch;
|
---|
262 | STAMCOUNTER StatFlushEntire;
|
---|
263 | STAMCOUNTER StatFlushAsid;
|
---|
264 | STAMCOUNTER StatFlushNestedPaging;
|
---|
265 | STAMCOUNTER StatFlushTlbInvlpgVirt;
|
---|
266 | STAMCOUNTER StatFlushTlbInvlpgPhys;
|
---|
267 | STAMCOUNTER StatTlbShootdown;
|
---|
268 | STAMCOUNTER StatTlbShootdownFlush;
|
---|
269 |
|
---|
270 | STAMCOUNTER StatSwitchPendingHostIrq;
|
---|
271 | STAMCOUNTER StatSwitchTprMaskedIrq;
|
---|
272 | STAMCOUNTER StatSwitchGuestIrq;
|
---|
273 | STAMCOUNTER StatSwitchHmToR3FF;
|
---|
274 | STAMCOUNTER StatSwitchVmReq;
|
---|
275 | STAMCOUNTER StatSwitchPgmPoolFlush;
|
---|
276 | STAMCOUNTER StatSwitchDma;
|
---|
277 | STAMCOUNTER StatSwitchExitToR3;
|
---|
278 | STAMCOUNTER StatSwitchLongJmpToR3;
|
---|
279 | STAMCOUNTER StatSwitchMaxResumeLoops;
|
---|
280 | STAMCOUNTER StatSwitchHltToR3;
|
---|
281 | STAMCOUNTER StatSwitchApicAccessToR3;
|
---|
282 | STAMCOUNTER StatSwitchPreempt;
|
---|
283 | STAMCOUNTER StatSwitchNstGstVmexit;
|
---|
284 |
|
---|
285 | STAMCOUNTER StatTscParavirt;
|
---|
286 | STAMCOUNTER StatTscOffset;
|
---|
287 | STAMCOUNTER StatTscIntercept;
|
---|
288 |
|
---|
289 | STAMCOUNTER StatDRxArmed;
|
---|
290 | STAMCOUNTER StatDRxContextSwitch;
|
---|
291 | STAMCOUNTER StatDRxIoCheck;
|
---|
292 |
|
---|
293 | STAMCOUNTER StatExportMinimal;
|
---|
294 | STAMCOUNTER StatExportFull;
|
---|
295 | STAMCOUNTER StatLoadGuestFpu;
|
---|
296 | STAMCOUNTER StatExportHostState;
|
---|
297 |
|
---|
298 | STAMCOUNTER StatVmxCheckBadRmSelBase;
|
---|
299 | STAMCOUNTER StatVmxCheckBadRmSelLimit;
|
---|
300 | STAMCOUNTER StatVmxCheckBadRmSelAttr;
|
---|
301 | STAMCOUNTER StatVmxCheckBadV86SelBase;
|
---|
302 | STAMCOUNTER StatVmxCheckBadV86SelLimit;
|
---|
303 | STAMCOUNTER StatVmxCheckBadV86SelAttr;
|
---|
304 | STAMCOUNTER StatVmxCheckRmOk;
|
---|
305 | STAMCOUNTER StatVmxCheckBadSel;
|
---|
306 | STAMCOUNTER StatVmxCheckBadRpl;
|
---|
307 | STAMCOUNTER StatVmxCheckPmOk;
|
---|
308 |
|
---|
309 | STAMCOUNTER StatVmxPreemptionRecalcingDeadline;
|
---|
310 | STAMCOUNTER StatVmxPreemptionRecalcingDeadlineExpired;
|
---|
311 | STAMCOUNTER StatVmxPreemptionReusingDeadline;
|
---|
312 | STAMCOUNTER StatVmxPreemptionReusingDeadlineExpired;
|
---|
313 |
|
---|
314 | #ifdef VBOX_WITH_STATISTICS
|
---|
315 | STAMCOUNTER aStatExitReason[MAX_EXITREASON_STAT];
|
---|
316 | STAMCOUNTER aStatNestedExitReason[MAX_EXITREASON_STAT];
|
---|
317 | STAMCOUNTER aStatInjectedIrqs[256];
|
---|
318 | STAMCOUNTER aStatInjectedXcpts[X86_XCPT_LAST + 1];
|
---|
319 | #endif
|
---|
320 | #ifdef HM_PROFILE_EXIT_DISPATCH
|
---|
321 | STAMPROFILEADV StatExitDispatch;
|
---|
322 | #endif
|
---|
323 | } VMXSTATISTICS;
|
---|
324 | /** Pointer to the VMX statistics. */
|
---|
325 | typedef VMXSTATISTICS *PVMXSTATISTICS;
|
---|
326 | /** Pointer to a const VMX statistics structure. */
|
---|
327 | typedef const VMXSTATISTICS *PCVMXSTATISTICS;
|
---|
328 |
|
---|
329 | /** @} */
|
---|
330 |
|
---|
331 | /** @} */
|
---|
332 |
|
---|
333 | RT_C_DECLS_END
|
---|
334 |
|
---|
335 | #endif /* !VMM_INCLUDED_SRC_include_VMXInternal_h */
|
---|
336 |
|
---|