VirtualBox

source: vbox/trunk/src/VBox/VMM/include/HMVMXCommon.h@ 94155

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

HMVMXCommon.h: Doxygen.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 19.4 KB
Line 
1/* $Id: HMVMXCommon.h 93968 2022-02-28 10:11:52Z vboxsync $ */
2/** @file
3 * HM/VMX - Internal header file for sharing common bits between the
4 * VMX template code (which is also used with NEM on darwin) and HM.
5 */
6
7/*
8 * Copyright (C) 2006-2022 Oracle Corporation
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 */
18
19#ifndef VMM_INCLUDED_SRC_include_HMVMXCommon_h
20#define VMM_INCLUDED_SRC_include_HMVMXCommon_h
21#ifndef RT_WITHOUT_PRAGMA_ONCE
22# pragma once
23#endif
24
25#include <VBox/cdefs.h>
26#include <VBox/types.h>
27
28RT_C_DECLS_BEGIN
29
30
31/** @defgroup grp_hm_int Internal
32 * @ingroup grp_hm
33 * @internal
34 * @{
35 */
36
37/** @name HM_CHANGED_XXX
38 * HM CPU-context changed flags.
39 *
40 * These flags are used to keep track of which registers and state has been
41 * modified since they were imported back into the guest-CPU context.
42 *
43 * @{
44 */
45#define HM_CHANGED_HOST_CONTEXT UINT64_C(0x0000000000000001)
46#define HM_CHANGED_GUEST_RIP UINT64_C(0x0000000000000004)
47#define HM_CHANGED_GUEST_RFLAGS UINT64_C(0x0000000000000008)
48
49#define HM_CHANGED_GUEST_RAX UINT64_C(0x0000000000000010)
50#define HM_CHANGED_GUEST_RCX UINT64_C(0x0000000000000020)
51#define HM_CHANGED_GUEST_RDX UINT64_C(0x0000000000000040)
52#define HM_CHANGED_GUEST_RBX UINT64_C(0x0000000000000080)
53#define HM_CHANGED_GUEST_RSP UINT64_C(0x0000000000000100)
54#define HM_CHANGED_GUEST_RBP UINT64_C(0x0000000000000200)
55#define HM_CHANGED_GUEST_RSI UINT64_C(0x0000000000000400)
56#define HM_CHANGED_GUEST_RDI UINT64_C(0x0000000000000800)
57#define HM_CHANGED_GUEST_R8_R15 UINT64_C(0x0000000000001000)
58#define HM_CHANGED_GUEST_GPRS_MASK UINT64_C(0x0000000000001ff0)
59
60#define HM_CHANGED_GUEST_ES UINT64_C(0x0000000000002000)
61#define HM_CHANGED_GUEST_CS UINT64_C(0x0000000000004000)
62#define HM_CHANGED_GUEST_SS UINT64_C(0x0000000000008000)
63#define HM_CHANGED_GUEST_DS UINT64_C(0x0000000000010000)
64#define HM_CHANGED_GUEST_FS UINT64_C(0x0000000000020000)
65#define HM_CHANGED_GUEST_GS UINT64_C(0x0000000000040000)
66#define HM_CHANGED_GUEST_SREG_MASK UINT64_C(0x000000000007e000)
67
68#define HM_CHANGED_GUEST_GDTR UINT64_C(0x0000000000080000)
69#define HM_CHANGED_GUEST_IDTR UINT64_C(0x0000000000100000)
70#define HM_CHANGED_GUEST_LDTR UINT64_C(0x0000000000200000)
71#define HM_CHANGED_GUEST_TR UINT64_C(0x0000000000400000)
72#define HM_CHANGED_GUEST_TABLE_MASK UINT64_C(0x0000000000780000)
73
74#define HM_CHANGED_GUEST_CR0 UINT64_C(0x0000000000800000)
75#define HM_CHANGED_GUEST_CR2 UINT64_C(0x0000000001000000)
76#define HM_CHANGED_GUEST_CR3 UINT64_C(0x0000000002000000)
77#define HM_CHANGED_GUEST_CR4 UINT64_C(0x0000000004000000)
78#define HM_CHANGED_GUEST_CR_MASK UINT64_C(0x0000000007800000)
79
80#define HM_CHANGED_GUEST_APIC_TPR UINT64_C(0x0000000008000000)
81#define HM_CHANGED_GUEST_EFER_MSR UINT64_C(0x0000000010000000)
82
83#define HM_CHANGED_GUEST_DR0_DR3 UINT64_C(0x0000000020000000)
84#define HM_CHANGED_GUEST_DR6 UINT64_C(0x0000000040000000)
85#define HM_CHANGED_GUEST_DR7 UINT64_C(0x0000000080000000)
86#define HM_CHANGED_GUEST_DR_MASK UINT64_C(0x00000000e0000000)
87
88#define HM_CHANGED_GUEST_X87 UINT64_C(0x0000000100000000)
89#define HM_CHANGED_GUEST_SSE_AVX UINT64_C(0x0000000200000000)
90#define HM_CHANGED_GUEST_OTHER_XSAVE UINT64_C(0x0000000400000000)
91#define HM_CHANGED_GUEST_XCRx UINT64_C(0x0000000800000000)
92
93#define HM_CHANGED_GUEST_KERNEL_GS_BASE UINT64_C(0x0000001000000000)
94#define HM_CHANGED_GUEST_SYSCALL_MSRS UINT64_C(0x0000002000000000)
95#define HM_CHANGED_GUEST_SYSENTER_CS_MSR UINT64_C(0x0000004000000000)
96#define HM_CHANGED_GUEST_SYSENTER_EIP_MSR UINT64_C(0x0000008000000000)
97#define HM_CHANGED_GUEST_SYSENTER_ESP_MSR UINT64_C(0x0000010000000000)
98#define HM_CHANGED_GUEST_SYSENTER_MSR_MASK UINT64_C(0x000001c000000000)
99#define HM_CHANGED_GUEST_TSC_AUX UINT64_C(0x0000020000000000)
100#define HM_CHANGED_GUEST_OTHER_MSRS UINT64_C(0x0000040000000000)
101#define HM_CHANGED_GUEST_ALL_MSRS ( HM_CHANGED_GUEST_EFER \
102 | HM_CHANGED_GUEST_KERNEL_GS_BASE \
103 | HM_CHANGED_GUEST_SYSCALL_MSRS \
104 | HM_CHANGED_GUEST_SYSENTER_MSR_MASK \
105 | HM_CHANGED_GUEST_TSC_AUX \
106 | HM_CHANGED_GUEST_OTHER_MSRS)
107
108#define HM_CHANGED_GUEST_HWVIRT UINT64_C(0x0000080000000000)
109#define HM_CHANGED_GUEST_MASK UINT64_C(0x00000ffffffffffc)
110
111#define HM_CHANGED_KEEPER_STATE_MASK UINT64_C(0xffff000000000000)
112
113#define HM_CHANGED_VMX_XCPT_INTERCEPTS UINT64_C(0x0001000000000000)
114#define HM_CHANGED_VMX_GUEST_AUTO_MSRS UINT64_C(0x0002000000000000)
115#define HM_CHANGED_VMX_GUEST_LAZY_MSRS UINT64_C(0x0004000000000000)
116#define HM_CHANGED_VMX_ENTRY_EXIT_CTLS UINT64_C(0x0008000000000000)
117#define HM_CHANGED_VMX_MASK UINT64_C(0x000f000000000000)
118#define HM_CHANGED_VMX_HOST_GUEST_SHARED_STATE ( HM_CHANGED_GUEST_DR_MASK \
119 | HM_CHANGED_VMX_GUEST_LAZY_MSRS)
120
121#define HM_CHANGED_SVM_XCPT_INTERCEPTS UINT64_C(0x0001000000000000)
122#define HM_CHANGED_SVM_MASK UINT64_C(0x0001000000000000)
123#define HM_CHANGED_SVM_HOST_GUEST_SHARED_STATE HM_CHANGED_GUEST_DR_MASK
124
125#define HM_CHANGED_ALL_GUEST ( HM_CHANGED_GUEST_MASK \
126 | HM_CHANGED_KEEPER_STATE_MASK)
127
128/** Mask of what state might have changed when IEM raised an exception.
129 * This is a based on IEM_CPUMCTX_EXTRN_XCPT_MASK. */
130#define HM_CHANGED_RAISED_XCPT_MASK ( HM_CHANGED_GUEST_GPRS_MASK \
131 | HM_CHANGED_GUEST_RIP \
132 | HM_CHANGED_GUEST_RFLAGS \
133 | HM_CHANGED_GUEST_SS \
134 | HM_CHANGED_GUEST_CS \
135 | HM_CHANGED_GUEST_CR0 \
136 | HM_CHANGED_GUEST_CR3 \
137 | HM_CHANGED_GUEST_CR4 \
138 | HM_CHANGED_GUEST_APIC_TPR \
139 | HM_CHANGED_GUEST_EFER_MSR \
140 | HM_CHANGED_GUEST_DR7 \
141 | HM_CHANGED_GUEST_CR2 \
142 | HM_CHANGED_GUEST_SREG_MASK \
143 | HM_CHANGED_GUEST_TABLE_MASK)
144
145#ifdef VBOX_WITH_NESTED_HWVIRT_SVM
146/** Mask of what state might have changed when \#VMEXIT is emulated. */
147# define HM_CHANGED_SVM_VMEXIT_MASK ( HM_CHANGED_GUEST_RSP \
148 | HM_CHANGED_GUEST_RAX \
149 | HM_CHANGED_GUEST_RIP \
150 | HM_CHANGED_GUEST_RFLAGS \
151 | HM_CHANGED_GUEST_CS \
152 | HM_CHANGED_GUEST_SS \
153 | HM_CHANGED_GUEST_DS \
154 | HM_CHANGED_GUEST_ES \
155 | HM_CHANGED_GUEST_GDTR \
156 | HM_CHANGED_GUEST_IDTR \
157 | HM_CHANGED_GUEST_CR_MASK \
158 | HM_CHANGED_GUEST_EFER_MSR \
159 | HM_CHANGED_GUEST_DR6 \
160 | HM_CHANGED_GUEST_DR7 \
161 | HM_CHANGED_GUEST_OTHER_MSRS \
162 | HM_CHANGED_GUEST_HWVIRT \
163 | HM_CHANGED_SVM_MASK \
164 | HM_CHANGED_GUEST_APIC_TPR)
165
166/** Mask of what state might have changed when VMRUN is emulated. */
167# define HM_CHANGED_SVM_VMRUN_MASK HM_CHANGED_SVM_VMEXIT_MASK
168#endif
169#ifdef VBOX_WITH_NESTED_HWVIRT_VMX
170/** Mask of what state might have changed when VM-exit is emulated.
171 *
172 * This is currently unused, but keeping it here in case we can get away a bit more
173 * fine-grained state handling.
174 *
175 * @note Update IEM_CPUMCTX_EXTRN_VMX_VMEXIT_MASK when this changes. */
176# define HM_CHANGED_VMX_VMEXIT_MASK ( HM_CHANGED_GUEST_CR0 | HM_CHANGED_GUEST_CR3 | HM_CHANGED_GUEST_CR4 \
177 | HM_CHANGED_GUEST_DR7 | HM_CHANGED_GUEST_DR6 \
178 | HM_CHANGED_GUEST_EFER_MSR \
179 | HM_CHANGED_GUEST_SYSENTER_MSR_MASK \
180 | HM_CHANGED_GUEST_OTHER_MSRS /* for PAT MSR */ \
181 | HM_CHANGED_GUEST_RIP | HM_CHANGED_GUEST_RSP | HM_CHANGED_GUEST_RFLAGS \
182 | HM_CHANGED_GUEST_SREG_MASK \
183 | HM_CHANGED_GUEST_TR \
184 | HM_CHANGED_GUEST_LDTR | HM_CHANGED_GUEST_GDTR | HM_CHANGED_GUEST_IDTR \
185 | HM_CHANGED_GUEST_HWVIRT )
186#endif
187/** @} */
188
189
190/** Maximum number of exit reason statistics counters. */
191#define MAX_EXITREASON_STAT 0x100
192#define MASK_EXITREASON_STAT 0xff
193#define MASK_INJECT_IRQ_STAT 0xff
194
195
196/**
197 * HM event.
198 *
199 * VT-x and AMD-V common event injection structure.
200 */
201typedef struct HMEVENT
202{
203 /** Whether the event is pending. */
204 uint32_t fPending;
205 /** The error-code associated with the event. */
206 uint32_t u32ErrCode;
207 /** The length of the instruction in bytes (only relevant for software
208 * interrupts or software exceptions). */
209 uint32_t cbInstr;
210 /** Alignment. */
211 uint32_t u32Padding;
212 /** The encoded event (VM-entry interruption-information for VT-x or EVENTINJ
213 * for SVM). */
214 uint64_t u64IntInfo;
215 /** Guest virtual address if this is a page-fault event. */
216 RTGCUINTPTR GCPtrFaultAddress;
217} HMEVENT;
218/** Pointer to a HMEVENT struct. */
219typedef HMEVENT *PHMEVENT;
220/** Pointer to a const HMEVENT struct. */
221typedef const HMEVENT *PCHMEVENT;
222AssertCompileSizeAlignment(HMEVENT, 8);
223
224
225/**
226 * VMX VMCS information, shared.
227 *
228 * This structure provides information maintained for and during the executing of a
229 * guest (or nested-guest) VMCS (VM control structure) using hardware-assisted VMX.
230 *
231 * Note! The members here are ordered and aligned based on estimated frequency of
232 * usage and grouped to fit within a cache line in hot code paths. Even subtle
233 * changes here have a noticeable effect in the bootsector benchmarks. Modify with
234 * care.
235 */
236typedef struct VMXVMCSINFOSHARED
237{
238 /** @name Real-mode emulation state.
239 * @{ */
240 /** Set if guest was executing in real mode (extra checks). */
241 bool fWasInRealMode;
242 /** Padding. */
243 bool afPadding0[7];
244 struct
245 {
246 X86DESCATTR AttrCS;
247 X86DESCATTR AttrDS;
248 X86DESCATTR AttrES;
249 X86DESCATTR AttrFS;
250 X86DESCATTR AttrGS;
251 X86DESCATTR AttrSS;
252 X86EFLAGS Eflags;
253 bool fRealOnV86Active;
254 bool afPadding1[3];
255 } RealMode;
256 /** @} */
257
258 /** @name LBR MSR data.
259 * @{ */
260 /** List of LastBranch-From-IP MSRs. */
261 uint64_t au64LbrFromIpMsr[32];
262 /** List of LastBranch-To-IP MSRs. */
263 uint64_t au64LbrToIpMsr[32];
264 /** List of LastBranch-Info MSRs. */
265 uint64_t au64LbrInfoMsr[32];
266 /** The MSR containing the index to the most recent branch record. */
267 uint64_t u64LbrTosMsr;
268 /** The MSR containing the last event record from IP value. */
269 uint64_t u64LerFromIpMsr;
270 /** The MSR containing the last event record to IP value. */
271 uint64_t u64LerToIpMsr;
272 /** @} */
273} VMXVMCSINFOSHARED;
274/** Pointer to a VMXVMCSINFOSHARED struct. */
275typedef VMXVMCSINFOSHARED *PVMXVMCSINFOSHARED;
276/** Pointer to a const VMXVMCSINFOSHARED struct. */
277typedef const VMXVMCSINFOSHARED *PCVMXVMCSINFOSHARED;
278AssertCompileSizeAlignment(VMXVMCSINFOSHARED, 8);
279
280
281/**
282 * VMX VMCS information, ring-0 only.
283 *
284 * This structure provides information maintained for and during the executing of a
285 * guest (or nested-guest) VMCS (VM control structure) using hardware-assisted VMX.
286 *
287 * Note! The members here are ordered and aligned based on estimated frequency of
288 * usage and grouped to fit within a cache line in hot code paths. Even subtle
289 * changes here have a noticeable effect in the bootsector benchmarks. Modify with
290 * care.
291 */
292typedef struct VMXVMCSINFO
293{
294 /** Pointer to the bits we share with ring-3. */
295 R3R0PTRTYPE(PVMXVMCSINFOSHARED) pShared;
296
297 /** @name Auxiliary information.
298 * @{ */
299 /** Host-physical address of the EPTP. */
300 RTHCPHYS HCPhysEPTP;
301 /** The VMCS launch state, see VMX_V_VMCS_LAUNCH_STATE_XXX. */
302 uint32_t fVmcsState;
303 /** The VMCS launch state of the shadow VMCS, see VMX_V_VMCS_LAUNCH_STATE_XXX. */
304 uint32_t fShadowVmcsState;
305 /** The host CPU for which its state has been exported to this VMCS. */
306 RTCPUID idHostCpuState;
307 /** The host CPU on which we last executed this VMCS. */
308 RTCPUID idHostCpuExec;
309 /** Number of guest MSRs in the VM-entry MSR-load area. */
310 uint32_t cEntryMsrLoad;
311 /** Number of guest MSRs in the VM-exit MSR-store area. */
312 uint32_t cExitMsrStore;
313 /** Number of host MSRs in the VM-exit MSR-load area. */
314 uint32_t cExitMsrLoad;
315 /** @} */
316
317 /** @name Cache of execution related VMCS fields.
318 * @{ */
319 /** Pin-based VM-execution controls. */
320 uint32_t u32PinCtls;
321 /** Processor-based VM-execution controls. */
322 uint32_t u32ProcCtls;
323 /** Secondary processor-based VM-execution controls. */
324 uint32_t u32ProcCtls2;
325 /** Tertiary processor-based VM-execution controls. */
326 uint64_t u64ProcCtls3;
327 /** VM-entry controls. */
328 uint32_t u32EntryCtls;
329 /** VM-exit controls. */
330 uint32_t u32ExitCtls;
331 /** Exception bitmap. */
332 uint32_t u32XcptBitmap;
333 /** Page-fault exception error-code mask. */
334 uint32_t u32XcptPFMask;
335 /** Page-fault exception error-code match. */
336 uint32_t u32XcptPFMatch;
337 /** Padding. */
338 uint32_t u32Alignment0;
339 /** TSC offset. */
340 uint64_t u64TscOffset;
341 /** VMCS link pointer. */
342 uint64_t u64VmcsLinkPtr;
343 /** CR0 guest/host mask. */
344 uint64_t u64Cr0Mask;
345 /** CR4 guest/host mask. */
346 uint64_t u64Cr4Mask;
347#ifndef IN_NEM_DARWIN
348 /** Current VMX_VMCS_HOST_RIP value (only used in HMR0A.asm). */
349 uint64_t uHostRip;
350 /** Current VMX_VMCS_HOST_RSP value (only used in HMR0A.asm). */
351 uint64_t uHostRsp;
352#endif
353 /** @} */
354
355 /** @name Host-virtual address of VMCS and related data structures.
356 * @{ */
357 /** The VMCS. */
358 R3R0PTRTYPE(void *) pvVmcs;
359 /** The shadow VMCS. */
360 R3R0PTRTYPE(void *) pvShadowVmcs;
361 /** The virtual-APIC page. */
362 R3R0PTRTYPE(uint8_t *) pbVirtApic;
363 /** The MSR bitmap. */
364 R3R0PTRTYPE(void *) pvMsrBitmap;
365 /** The VM-entry MSR-load area. */
366 R3R0PTRTYPE(void *) pvGuestMsrLoad;
367 /** The VM-exit MSR-store area. */
368 R3R0PTRTYPE(void *) pvGuestMsrStore;
369 /** The VM-exit MSR-load area. */
370 R3R0PTRTYPE(void *) pvHostMsrLoad;
371 /** @} */
372
373#ifndef IN_NEM_DARWIN
374 /** @name Host-physical address of VMCS and related data structures.
375 * @{ */
376 /** The VMCS. */
377 RTHCPHYS HCPhysVmcs;
378 /** The shadow VMCS. */
379 RTHCPHYS HCPhysShadowVmcs;
380 /** The virtual APIC page. */
381 RTHCPHYS HCPhysVirtApic;
382 /** The MSR bitmap. */
383 RTHCPHYS HCPhysMsrBitmap;
384 /** The VM-entry MSR-load area. */
385 RTHCPHYS HCPhysGuestMsrLoad;
386 /** The VM-exit MSR-store area. */
387 RTHCPHYS HCPhysGuestMsrStore;
388 /** The VM-exit MSR-load area. */
389 RTHCPHYS HCPhysHostMsrLoad;
390 /** @} */
391
392 /** @name R0-memory objects address for VMCS and related data structures.
393 * @{ */
394 /** R0-memory object for VMCS and related data structures. */
395 RTR0MEMOBJ hMemObj;
396 /** @} */
397#endif
398} VMXVMCSINFO;
399/** Pointer to a VMXVMCSINFOR0 struct. */
400typedef VMXVMCSINFO *PVMXVMCSINFO;
401/** Pointer to a const VMXVMCSINFO struct. */
402typedef const VMXVMCSINFO *PCVMXVMCSINFO;
403AssertCompileSizeAlignment(VMXVMCSINFO, 8);
404AssertCompileMemberAlignment(VMXVMCSINFO, u32PinCtls, 4);
405AssertCompileMemberAlignment(VMXVMCSINFO, u64VmcsLinkPtr, 8);
406AssertCompileMemberAlignment(VMXVMCSINFO, pvVmcs, 8);
407AssertCompileMemberAlignment(VMXVMCSINFO, pvShadowVmcs, 8);
408AssertCompileMemberAlignment(VMXVMCSINFO, pbVirtApic, 8);
409AssertCompileMemberAlignment(VMXVMCSINFO, pvMsrBitmap, 8);
410AssertCompileMemberAlignment(VMXVMCSINFO, pvGuestMsrLoad, 8);
411AssertCompileMemberAlignment(VMXVMCSINFO, pvGuestMsrStore, 8);
412AssertCompileMemberAlignment(VMXVMCSINFO, pvHostMsrLoad, 8);
413#ifndef IN_NEM_DARWIN
414AssertCompileMemberAlignment(VMXVMCSINFO, HCPhysVmcs, 8);
415AssertCompileMemberAlignment(VMXVMCSINFO, hMemObj, 8);
416#endif
417
418/** @} */
419
420RT_C_DECLS_END
421
422#endif /* !VMM_INCLUDED_SRC_include_HMVMXCommon_h */
423
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