VirtualBox

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

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

VMM/include/HMVMXCommon.h: Use IN_NEM_DARWIN instead of IN_RING0 so tstStructVMSize doesn't fail to compile, bugref:10136

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 18.7 KB
Line 
1/* $Id: HMVMXCommon.h 92363 2021-11-11 11:25:18Z 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-2021 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
225typedef struct VMXVMCSINFOSHARED
226{
227 /** @name Real-mode emulation state.
228 * @{ */
229 /** Set if guest was executing in real mode (extra checks). */
230 bool fWasInRealMode;
231 /** Padding. */
232 bool afPadding0[7];
233 struct
234 {
235 X86DESCATTR AttrCS;
236 X86DESCATTR AttrDS;
237 X86DESCATTR AttrES;
238 X86DESCATTR AttrFS;
239 X86DESCATTR AttrGS;
240 X86DESCATTR AttrSS;
241 X86EFLAGS Eflags;
242 bool fRealOnV86Active;
243 bool afPadding1[3];
244 } RealMode;
245 /** @} */
246
247 /** @name LBR MSR data.
248 * @{ */
249 /** List of LastBranch-From-IP MSRs. */
250 uint64_t au64LbrFromIpMsr[32];
251 /** List of LastBranch-To-IP MSRs. */
252 uint64_t au64LbrToIpMsr[32];
253 /** The MSR containing the index to the most recent branch record. */
254 uint64_t u64LbrTosMsr;
255 /** @} */
256} VMXVMCSINFOSHARED;
257/** Pointer to a VMXVMCSINFOSHARED struct. */
258typedef VMXVMCSINFOSHARED *PVMXVMCSINFOSHARED;
259/** Pointer to a const VMXVMCSINFOSHARED struct. */
260typedef const VMXVMCSINFOSHARED *PCVMXVMCSINFOSHARED;
261AssertCompileSizeAlignment(VMXVMCSINFOSHARED, 8);
262
263
264/**
265 * VMX VMCS information, ring-0 only.
266 *
267 * This structure provides information maintained for and during the executing of a
268 * guest (or nested-guest) VMCS (VM control structure) using hardware-assisted VMX.
269 *
270 * Note! The members here are ordered and aligned based on estimated frequency of
271 * usage and grouped to fit within a cache line in hot code paths. Even subtle
272 * changes here have a noticeable effect in the bootsector benchmarks. Modify with
273 * care.
274 */
275typedef struct VMXVMCSINFO
276{
277 /** Pointer to the bits we share with ring-3. */
278 R3R0PTRTYPE(PVMXVMCSINFOSHARED) pShared;
279
280 /** @name Auxiliary information.
281 * @{ */
282 /** Host-physical address of the EPTP. */
283 RTHCPHYS HCPhysEPTP;
284 /** The VMCS launch state, see VMX_V_VMCS_LAUNCH_STATE_XXX. */
285 uint32_t fVmcsState;
286 /** The VMCS launch state of the shadow VMCS, see VMX_V_VMCS_LAUNCH_STATE_XXX. */
287 uint32_t fShadowVmcsState;
288 /** The host CPU for which its state has been exported to this VMCS. */
289 RTCPUID idHostCpuState;
290 /** The host CPU on which we last executed this VMCS. */
291 RTCPUID idHostCpuExec;
292 /** Number of guest MSRs in the VM-entry MSR-load area. */
293 uint32_t cEntryMsrLoad;
294 /** Number of guest MSRs in the VM-exit MSR-store area. */
295 uint32_t cExitMsrStore;
296 /** Number of host MSRs in the VM-exit MSR-load area. */
297 uint32_t cExitMsrLoad;
298 /** @} */
299
300 /** @name Cache of execution related VMCS fields.
301 * @{ */
302 /** Pin-based VM-execution controls. */
303 uint32_t u32PinCtls;
304 /** Processor-based VM-execution controls. */
305 uint32_t u32ProcCtls;
306 /** Secondary processor-based VM-execution controls. */
307 uint32_t u32ProcCtls2;
308 /** Tertiary processor-based VM-execution controls. */
309 uint64_t u64ProcCtls3;
310 /** VM-entry controls. */
311 uint32_t u32EntryCtls;
312 /** VM-exit controls. */
313 uint32_t u32ExitCtls;
314 /** Exception bitmap. */
315 uint32_t u32XcptBitmap;
316 /** Page-fault exception error-code mask. */
317 uint32_t u32XcptPFMask;
318 /** Page-fault exception error-code match. */
319 uint32_t u32XcptPFMatch;
320 /** Padding. */
321 uint32_t u32Alignment0;
322 /** TSC offset. */
323 uint64_t u64TscOffset;
324 /** VMCS link pointer. */
325 uint64_t u64VmcsLinkPtr;
326 /** CR0 guest/host mask. */
327 uint64_t u64Cr0Mask;
328 /** CR4 guest/host mask. */
329 uint64_t u64Cr4Mask;
330#ifndef IN_NEM_DARWIN
331 /** Current VMX_VMCS_HOST_RIP value (only used in HMR0A.asm). */
332 uint64_t uHostRip;
333 /** Current VMX_VMCS_HOST_RSP value (only used in HMR0A.asm). */
334 uint64_t uHostRsp;
335#endif
336 /** @} */
337
338 /** @name Host-virtual address of VMCS and related data structures.
339 * @{ */
340 /** The VMCS. */
341 R3R0PTRTYPE(void *) pvVmcs;
342 /** The shadow VMCS. */
343 R3R0PTRTYPE(void *) pvShadowVmcs;
344 /** The virtual-APIC page. */
345 R3R0PTRTYPE(uint8_t *) pbVirtApic;
346 /** The MSR bitmap. */
347 R3R0PTRTYPE(void *) pvMsrBitmap;
348 /** The VM-entry MSR-load area. */
349 R3R0PTRTYPE(void *) pvGuestMsrLoad;
350 /** The VM-exit MSR-store area. */
351 R3R0PTRTYPE(void *) pvGuestMsrStore;
352 /** The VM-exit MSR-load area. */
353 R3R0PTRTYPE(void *) pvHostMsrLoad;
354 /** @} */
355
356#ifndef IN_NEM_DARWIN
357 /** @name Host-physical address of VMCS and related data structures.
358 * @{ */
359 /** The VMCS. */
360 RTHCPHYS HCPhysVmcs;
361 /** The shadow VMCS. */
362 RTHCPHYS HCPhysShadowVmcs;
363 /** The virtual APIC page. */
364 RTHCPHYS HCPhysVirtApic;
365 /** The MSR bitmap. */
366 RTHCPHYS HCPhysMsrBitmap;
367 /** The VM-entry MSR-load area. */
368 RTHCPHYS HCPhysGuestMsrLoad;
369 /** The VM-exit MSR-store area. */
370 RTHCPHYS HCPhysGuestMsrStore;
371 /** The VM-exit MSR-load area. */
372 RTHCPHYS HCPhysHostMsrLoad;
373 /** @} */
374
375 /** @name R0-memory objects address for VMCS and related data structures.
376 * @{ */
377 /** R0-memory object for VMCS and related data structures. */
378 RTR0MEMOBJ hMemObj;
379 /** @} */
380#endif
381} VMXVMCSINFO;
382/** Pointer to a VMXVMCSINFOR0 struct. */
383typedef VMXVMCSINFO *PVMXVMCSINFO;
384/** Pointer to a const VMXVMCSINFO struct. */
385typedef const VMXVMCSINFO *PCVMXVMCSINFO;
386AssertCompileSizeAlignment(VMXVMCSINFO, 8);
387AssertCompileMemberAlignment(VMXVMCSINFO, u32PinCtls, 4);
388AssertCompileMemberAlignment(VMXVMCSINFO, u64VmcsLinkPtr, 8);
389AssertCompileMemberAlignment(VMXVMCSINFO, pvVmcs, 8);
390AssertCompileMemberAlignment(VMXVMCSINFO, pvShadowVmcs, 8);
391AssertCompileMemberAlignment(VMXVMCSINFO, pbVirtApic, 8);
392AssertCompileMemberAlignment(VMXVMCSINFO, pvMsrBitmap, 8);
393AssertCompileMemberAlignment(VMXVMCSINFO, pvGuestMsrLoad, 8);
394AssertCompileMemberAlignment(VMXVMCSINFO, pvGuestMsrStore, 8);
395AssertCompileMemberAlignment(VMXVMCSINFO, pvHostMsrLoad, 8);
396#ifndef IN_NEM_DARWIN
397AssertCompileMemberAlignment(VMXVMCSINFO, HCPhysVmcs, 8);
398AssertCompileMemberAlignment(VMXVMCSINFO, hMemObj, 8);
399#endif
400
401/** @} */
402
403/** @} */
404
405RT_C_DECLS_END
406
407#endif /* !VMM_INCLUDED_SRC_include_HMVMXCommon_h */
408
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