VirtualBox

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

Last change on this file since 97441 was 97069, checked in by vboxsync, 2 years ago

VMM/HMVMXR0: Working on streamlining CPU state importing from the VMCS. This does cause quite some code bloat (release linux from 93950 to 132120 text bytes), but it is hopefully worth it. This should also provide some basis for addressing the @todo in nemR3DarwinHandleExitCommon (NEM/darwin) where the code imports the entire state for every exit.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 12.8 KB
Line 
1/* $Id: VMXInternal.h 97069 2022-10-10 15:03:10Z 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
46RT_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 */
67typedef 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;
140AssertCompileMemberSize(VMXTRANSIENT, ExitInstrInfo, sizeof(uint32_t));
141AssertCompileMemberAlignment(VMXTRANSIENT, fVmcsFieldsRead, 8);
142AssertCompileMemberAlignment(VMXTRANSIENT, fVectoringPF, 8);
143AssertCompileMemberAlignment(VMXTRANSIENT, uExitReason, 8);
144AssertCompileMemberAlignment(VMXTRANSIENT, fEFlags, 8);
145AssertCompileMemberAlignment(VMXTRANSIENT, uExitQual, 8);
146AssertCompileMemberAlignment(VMXTRANSIENT, pVmcsInfo, 8);
147AssertCompileMemberAlignment(VMXTRANSIENT, uExitIntInfo, 8);
148AssertCompileMemberAlignment(VMXTRANSIENT, ExitInstrInfo, 8);
149AssertCompileMemberAlignment(VMXTRANSIENT, uIdtVectoringErrorCode, 8);
150AssertCompileMemberAlignment(VMXTRANSIENT, uGuestLinearAddr, 8);
151AssertCompileMemberAlignment(VMXTRANSIENT, uGuestPhysicalAddr, 8);
152AssertCompileMemberAlignment(VMXTRANSIENT, uEntryIntInfo, 8);
153AssertCompileMemberAlignment(VMXTRANSIENT, cbEntryInstr, 8);
154/** Pointer to VMX transient state. */
155typedef VMXTRANSIENT *PVMXTRANSIENT;
156/** Pointer to a const VMX transient state. */
157typedef const VMXTRANSIENT *PCVMXTRANSIENT;
158
159
160/**
161 * VMX statistics structure.
162 */
163typedef 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
253 STAMCOUNTER StatFlushPage;
254 STAMCOUNTER StatFlushPageManual;
255 STAMCOUNTER StatFlushPhysPageManual;
256 STAMCOUNTER StatFlushTlb;
257 STAMCOUNTER StatFlushTlbNstGst;
258 STAMCOUNTER StatFlushTlbManual;
259 STAMCOUNTER StatFlushTlbWorldSwitch;
260 STAMCOUNTER StatNoFlushTlbWorldSwitch;
261 STAMCOUNTER StatFlushEntire;
262 STAMCOUNTER StatFlushAsid;
263 STAMCOUNTER StatFlushNestedPaging;
264 STAMCOUNTER StatFlushTlbInvlpgVirt;
265 STAMCOUNTER StatFlushTlbInvlpgPhys;
266 STAMCOUNTER StatTlbShootdown;
267 STAMCOUNTER StatTlbShootdownFlush;
268
269 STAMCOUNTER StatSwitchPendingHostIrq;
270 STAMCOUNTER StatSwitchTprMaskedIrq;
271 STAMCOUNTER StatSwitchGuestIrq;
272 STAMCOUNTER StatSwitchHmToR3FF;
273 STAMCOUNTER StatSwitchVmReq;
274 STAMCOUNTER StatSwitchPgmPoolFlush;
275 STAMCOUNTER StatSwitchDma;
276 STAMCOUNTER StatSwitchExitToR3;
277 STAMCOUNTER StatSwitchLongJmpToR3;
278 STAMCOUNTER StatSwitchMaxResumeLoops;
279 STAMCOUNTER StatSwitchHltToR3;
280 STAMCOUNTER StatSwitchApicAccessToR3;
281 STAMCOUNTER StatSwitchPreempt;
282 STAMCOUNTER StatSwitchNstGstVmexit;
283
284 STAMCOUNTER StatTscParavirt;
285 STAMCOUNTER StatTscOffset;
286 STAMCOUNTER StatTscIntercept;
287
288 STAMCOUNTER StatDRxArmed;
289 STAMCOUNTER StatDRxContextSwitch;
290 STAMCOUNTER StatDRxIoCheck;
291
292 STAMCOUNTER StatExportMinimal;
293 STAMCOUNTER StatExportFull;
294 STAMCOUNTER StatLoadGuestFpu;
295 STAMCOUNTER StatExportHostState;
296
297 STAMCOUNTER StatVmxCheckBadRmSelBase;
298 STAMCOUNTER StatVmxCheckBadRmSelLimit;
299 STAMCOUNTER StatVmxCheckBadRmSelAttr;
300 STAMCOUNTER StatVmxCheckBadV86SelBase;
301 STAMCOUNTER StatVmxCheckBadV86SelLimit;
302 STAMCOUNTER StatVmxCheckBadV86SelAttr;
303 STAMCOUNTER StatVmxCheckRmOk;
304 STAMCOUNTER StatVmxCheckBadSel;
305 STAMCOUNTER StatVmxCheckBadRpl;
306 STAMCOUNTER StatVmxCheckPmOk;
307
308 STAMCOUNTER StatVmxPreemptionRecalcingDeadline;
309 STAMCOUNTER StatVmxPreemptionRecalcingDeadlineExpired;
310 STAMCOUNTER StatVmxPreemptionReusingDeadline;
311 STAMCOUNTER StatVmxPreemptionReusingDeadlineExpired;
312
313#ifdef VBOX_WITH_STATISTICS
314 STAMCOUNTER aStatExitReason[MAX_EXITREASON_STAT];
315 STAMCOUNTER aStatNestedExitReason[MAX_EXITREASON_STAT];
316 STAMCOUNTER aStatInjectedIrqs[256];
317 STAMCOUNTER aStatInjectedXcpts[X86_XCPT_LAST + 1];
318#endif
319#ifdef HM_PROFILE_EXIT_DISPATCH
320 STAMPROFILEADV StatExitDispatch;
321#endif
322} VMXSTATISTICS;
323/** Pointer to the VMX statistics. */
324typedef VMXSTATISTICS *PVMXSTATISTICS;
325/** Pointer to a const VMX statistics structure. */
326typedef const VMXSTATISTICS *PCVMXSTATISTICS;
327
328/** @} */
329
330/** @} */
331
332RT_C_DECLS_END
333
334#endif /* !VMM_INCLUDED_SRC_include_VMXInternal_h */
335
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