1 | /* $Id: VMXInternal.h 96407 2022-08-22 17:43:14Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VMX - Internal header file for the VMX code template.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2022 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 StatInjectInterrupt;
|
---|
188 | STAMCOUNTER StatInjectXcpt;
|
---|
189 | STAMCOUNTER StatInjectReflect;
|
---|
190 | STAMCOUNTER StatInjectConvertDF;
|
---|
191 | STAMCOUNTER StatInjectInterpret;
|
---|
192 | STAMCOUNTER StatInjectReflectNPF;
|
---|
193 |
|
---|
194 | STAMCOUNTER StatExitAll;
|
---|
195 | STAMCOUNTER StatNestedExitAll;
|
---|
196 | STAMCOUNTER StatExitShadowNM;
|
---|
197 | STAMCOUNTER StatExitGuestNM;
|
---|
198 | STAMCOUNTER StatExitShadowPF; /**< Misleading, currently used for MMIO \#PFs as well. */
|
---|
199 | STAMCOUNTER StatExitShadowPFEM;
|
---|
200 | STAMCOUNTER StatExitGuestPF;
|
---|
201 | STAMCOUNTER StatExitGuestUD;
|
---|
202 | STAMCOUNTER StatExitGuestSS;
|
---|
203 | STAMCOUNTER StatExitGuestNP;
|
---|
204 | STAMCOUNTER StatExitGuestTS;
|
---|
205 | STAMCOUNTER StatExitGuestOF;
|
---|
206 | STAMCOUNTER StatExitGuestGP;
|
---|
207 | STAMCOUNTER StatExitGuestDE;
|
---|
208 | STAMCOUNTER StatExitGuestDF;
|
---|
209 | STAMCOUNTER StatExitGuestBR;
|
---|
210 | STAMCOUNTER StatExitGuestAC;
|
---|
211 | STAMCOUNTER StatExitGuestACSplitLock;
|
---|
212 | STAMCOUNTER StatExitGuestDB;
|
---|
213 | STAMCOUNTER StatExitGuestMF;
|
---|
214 | STAMCOUNTER StatExitGuestBP;
|
---|
215 | STAMCOUNTER StatExitGuestXF;
|
---|
216 | STAMCOUNTER StatExitGuestXcpUnk;
|
---|
217 | STAMCOUNTER StatExitDRxWrite;
|
---|
218 | STAMCOUNTER StatExitDRxRead;
|
---|
219 | STAMCOUNTER StatExitCR0Read;
|
---|
220 | STAMCOUNTER StatExitCR2Read;
|
---|
221 | STAMCOUNTER StatExitCR3Read;
|
---|
222 | STAMCOUNTER StatExitCR4Read;
|
---|
223 | STAMCOUNTER StatExitCR8Read;
|
---|
224 | STAMCOUNTER StatExitCR0Write;
|
---|
225 | STAMCOUNTER StatExitCR2Write;
|
---|
226 | STAMCOUNTER StatExitCR3Write;
|
---|
227 | STAMCOUNTER StatExitCR4Write;
|
---|
228 | STAMCOUNTER StatExitCR8Write;
|
---|
229 | STAMCOUNTER StatExitRdmsr;
|
---|
230 | STAMCOUNTER StatExitWrmsr;
|
---|
231 | STAMCOUNTER StatExitClts;
|
---|
232 | STAMCOUNTER StatExitXdtrAccess;
|
---|
233 | STAMCOUNTER StatExitLmsw;
|
---|
234 | STAMCOUNTER StatExitIOWrite;
|
---|
235 | STAMCOUNTER StatExitIORead;
|
---|
236 | STAMCOUNTER StatExitIOStringWrite;
|
---|
237 | STAMCOUNTER StatExitIOStringRead;
|
---|
238 | STAMCOUNTER StatExitIntWindow;
|
---|
239 | STAMCOUNTER StatExitExtInt;
|
---|
240 | STAMCOUNTER StatExitHostNmiInGC;
|
---|
241 | STAMCOUNTER StatExitHostNmiInGCIpi;
|
---|
242 | STAMCOUNTER StatExitPreemptTimer;
|
---|
243 | STAMCOUNTER StatExitTprBelowThreshold;
|
---|
244 | STAMCOUNTER StatExitTaskSwitch;
|
---|
245 | STAMCOUNTER StatExitApicAccess;
|
---|
246 | STAMCOUNTER StatExitReasonNpf;
|
---|
247 |
|
---|
248 | STAMCOUNTER StatNestedExitReasonNpf;
|
---|
249 |
|
---|
250 | STAMCOUNTER StatFlushPage;
|
---|
251 | STAMCOUNTER StatFlushPageManual;
|
---|
252 | STAMCOUNTER StatFlushPhysPageManual;
|
---|
253 | STAMCOUNTER StatFlushTlb;
|
---|
254 | STAMCOUNTER StatFlushTlbNstGst;
|
---|
255 | STAMCOUNTER StatFlushTlbManual;
|
---|
256 | STAMCOUNTER StatFlushTlbWorldSwitch;
|
---|
257 | STAMCOUNTER StatNoFlushTlbWorldSwitch;
|
---|
258 | STAMCOUNTER StatFlushEntire;
|
---|
259 | STAMCOUNTER StatFlushAsid;
|
---|
260 | STAMCOUNTER StatFlushNestedPaging;
|
---|
261 | STAMCOUNTER StatFlushTlbInvlpgVirt;
|
---|
262 | STAMCOUNTER StatFlushTlbInvlpgPhys;
|
---|
263 | STAMCOUNTER StatTlbShootdown;
|
---|
264 | STAMCOUNTER StatTlbShootdownFlush;
|
---|
265 |
|
---|
266 | STAMCOUNTER StatSwitchPendingHostIrq;
|
---|
267 | STAMCOUNTER StatSwitchTprMaskedIrq;
|
---|
268 | STAMCOUNTER StatSwitchGuestIrq;
|
---|
269 | STAMCOUNTER StatSwitchHmToR3FF;
|
---|
270 | STAMCOUNTER StatSwitchVmReq;
|
---|
271 | STAMCOUNTER StatSwitchPgmPoolFlush;
|
---|
272 | STAMCOUNTER StatSwitchDma;
|
---|
273 | STAMCOUNTER StatSwitchExitToR3;
|
---|
274 | STAMCOUNTER StatSwitchLongJmpToR3;
|
---|
275 | STAMCOUNTER StatSwitchMaxResumeLoops;
|
---|
276 | STAMCOUNTER StatSwitchHltToR3;
|
---|
277 | STAMCOUNTER StatSwitchApicAccessToR3;
|
---|
278 | STAMCOUNTER StatSwitchPreempt;
|
---|
279 | STAMCOUNTER StatSwitchNstGstVmexit;
|
---|
280 |
|
---|
281 | STAMCOUNTER StatTscParavirt;
|
---|
282 | STAMCOUNTER StatTscOffset;
|
---|
283 | STAMCOUNTER StatTscIntercept;
|
---|
284 |
|
---|
285 | STAMCOUNTER StatDRxArmed;
|
---|
286 | STAMCOUNTER StatDRxContextSwitch;
|
---|
287 | STAMCOUNTER StatDRxIoCheck;
|
---|
288 |
|
---|
289 | STAMCOUNTER StatExportMinimal;
|
---|
290 | STAMCOUNTER StatExportFull;
|
---|
291 | STAMCOUNTER StatLoadGuestFpu;
|
---|
292 | STAMCOUNTER StatExportHostState;
|
---|
293 |
|
---|
294 | STAMCOUNTER StatVmxCheckBadRmSelBase;
|
---|
295 | STAMCOUNTER StatVmxCheckBadRmSelLimit;
|
---|
296 | STAMCOUNTER StatVmxCheckBadRmSelAttr;
|
---|
297 | STAMCOUNTER StatVmxCheckBadV86SelBase;
|
---|
298 | STAMCOUNTER StatVmxCheckBadV86SelLimit;
|
---|
299 | STAMCOUNTER StatVmxCheckBadV86SelAttr;
|
---|
300 | STAMCOUNTER StatVmxCheckRmOk;
|
---|
301 | STAMCOUNTER StatVmxCheckBadSel;
|
---|
302 | STAMCOUNTER StatVmxCheckBadRpl;
|
---|
303 | STAMCOUNTER StatVmxCheckPmOk;
|
---|
304 |
|
---|
305 | STAMCOUNTER StatVmxPreemptionRecalcingDeadline;
|
---|
306 | STAMCOUNTER StatVmxPreemptionRecalcingDeadlineExpired;
|
---|
307 | STAMCOUNTER StatVmxPreemptionReusingDeadline;
|
---|
308 | STAMCOUNTER StatVmxPreemptionReusingDeadlineExpired;
|
---|
309 |
|
---|
310 | #ifdef VBOX_WITH_STATISTICS
|
---|
311 | STAMCOUNTER aStatExitReason[MAX_EXITREASON_STAT];
|
---|
312 | STAMCOUNTER aStatNestedExitReason[MAX_EXITREASON_STAT];
|
---|
313 | STAMCOUNTER aStatInjectedIrqs[256];
|
---|
314 | STAMCOUNTER aStatInjectedXcpts[X86_XCPT_LAST + 1];
|
---|
315 | #endif
|
---|
316 | #ifdef HM_PROFILE_EXIT_DISPATCH
|
---|
317 | STAMPROFILEADV StatExitDispatch;
|
---|
318 | #endif
|
---|
319 | } VMXSTATISTICS;
|
---|
320 | /** Pointer to the VMX statistics. */
|
---|
321 | typedef VMXSTATISTICS *PVMXSTATISTICS;
|
---|
322 | /** Pointer to a const VMX statistics structure. */
|
---|
323 | typedef const VMXSTATISTICS *PCVMXSTATISTICS;
|
---|
324 |
|
---|
325 | /** @} */
|
---|
326 |
|
---|
327 | /** @} */
|
---|
328 |
|
---|
329 | RT_C_DECLS_END
|
---|
330 |
|
---|
331 | #endif /* !VMM_INCLUDED_SRC_include_VMXInternal_h */
|
---|
332 |
|
---|