VirtualBox

source: vbox/trunk/src/VBox/VMM/include/HMInternal.h@ 79268

Last change on this file since 79268 was 79222, checked in by vboxsync, 6 years ago

HMInternal.h: Nested VMX: bugref:9180 Add fShadowVmcsState for upcoming changes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 52.5 KB
Line 
1/* $Id: HMInternal.h 79222 2019-06-19 05:32:21Z vboxsync $ */
2/** @file
3 * HM - Internal header file.
4 */
5
6/*
7 * Copyright (C) 2006-2019 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef VMM_INCLUDED_SRC_include_HMInternal_h
19#define VMM_INCLUDED_SRC_include_HMInternal_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24#include <VBox/cdefs.h>
25#include <VBox/types.h>
26#include <VBox/vmm/stam.h>
27#include <VBox/dis.h>
28#include <VBox/vmm/hm.h>
29#include <VBox/vmm/hm_vmx.h>
30#include <VBox/vmm/hm_svm.h>
31#include <VBox/vmm/pgm.h>
32#include <VBox/vmm/cpum.h>
33#include <VBox/vmm/trpm.h>
34#include <iprt/memobj.h>
35#include <iprt/cpuset.h>
36#include <iprt/mp.h>
37#include <iprt/avl.h>
38#include <iprt/string.h>
39
40#if HC_ARCH_BITS == 32 && defined(RT_OS_DARWIN)
41# error "32-bit darwin is no longer supported. Go back to 4.3 or earlier!"
42#endif
43
44#if HC_ARCH_BITS == 64 || defined(VBOX_WITH_64_BITS_GUESTS)
45/* Enable 64 bits guest support. */
46# define VBOX_ENABLE_64_BITS_GUESTS
47#endif
48
49#if HC_ARCH_BITS == 32 && defined(VBOX_ENABLE_64_BITS_GUESTS)
50# define VMX_USE_CACHED_VMCS_ACCESSES
51#endif
52
53/** @def HM_PROFILE_EXIT_DISPATCH
54 * Enables profiling of the VM exit handler dispatching. */
55#if 0 || defined(DOXYGEN_RUNNING)
56# define HM_PROFILE_EXIT_DISPATCH
57#endif
58
59RT_C_DECLS_BEGIN
60
61
62/** @defgroup grp_hm_int Internal
63 * @ingroup grp_hm
64 * @internal
65 * @{
66 */
67
68/** @name HM_CHANGED_XXX
69 * HM CPU-context changed flags.
70 *
71 * These flags are used to keep track of which registers and state has been
72 * modified since they were imported back into the guest-CPU context.
73 *
74 * @{
75 */
76#define HM_CHANGED_HOST_CONTEXT UINT64_C(0x0000000000000001)
77#define HM_CHANGED_GUEST_RIP UINT64_C(0x0000000000000004)
78#define HM_CHANGED_GUEST_RFLAGS UINT64_C(0x0000000000000008)
79
80#define HM_CHANGED_GUEST_RAX UINT64_C(0x0000000000000010)
81#define HM_CHANGED_GUEST_RCX UINT64_C(0x0000000000000020)
82#define HM_CHANGED_GUEST_RDX UINT64_C(0x0000000000000040)
83#define HM_CHANGED_GUEST_RBX UINT64_C(0x0000000000000080)
84#define HM_CHANGED_GUEST_RSP UINT64_C(0x0000000000000100)
85#define HM_CHANGED_GUEST_RBP UINT64_C(0x0000000000000200)
86#define HM_CHANGED_GUEST_RSI UINT64_C(0x0000000000000400)
87#define HM_CHANGED_GUEST_RDI UINT64_C(0x0000000000000800)
88#define HM_CHANGED_GUEST_R8_R15 UINT64_C(0x0000000000001000)
89#define HM_CHANGED_GUEST_GPRS_MASK UINT64_C(0x0000000000001ff0)
90
91#define HM_CHANGED_GUEST_ES UINT64_C(0x0000000000002000)
92#define HM_CHANGED_GUEST_CS UINT64_C(0x0000000000004000)
93#define HM_CHANGED_GUEST_SS UINT64_C(0x0000000000008000)
94#define HM_CHANGED_GUEST_DS UINT64_C(0x0000000000010000)
95#define HM_CHANGED_GUEST_FS UINT64_C(0x0000000000020000)
96#define HM_CHANGED_GUEST_GS UINT64_C(0x0000000000040000)
97#define HM_CHANGED_GUEST_SREG_MASK UINT64_C(0x000000000007e000)
98
99#define HM_CHANGED_GUEST_GDTR UINT64_C(0x0000000000080000)
100#define HM_CHANGED_GUEST_IDTR UINT64_C(0x0000000000100000)
101#define HM_CHANGED_GUEST_LDTR UINT64_C(0x0000000000200000)
102#define HM_CHANGED_GUEST_TR UINT64_C(0x0000000000400000)
103#define HM_CHANGED_GUEST_TABLE_MASK UINT64_C(0x0000000000780000)
104
105#define HM_CHANGED_GUEST_CR0 UINT64_C(0x0000000000800000)
106#define HM_CHANGED_GUEST_CR2 UINT64_C(0x0000000001000000)
107#define HM_CHANGED_GUEST_CR3 UINT64_C(0x0000000002000000)
108#define HM_CHANGED_GUEST_CR4 UINT64_C(0x0000000004000000)
109#define HM_CHANGED_GUEST_CR_MASK UINT64_C(0x0000000007800000)
110
111#define HM_CHANGED_GUEST_APIC_TPR UINT64_C(0x0000000008000000)
112#define HM_CHANGED_GUEST_EFER_MSR UINT64_C(0x0000000010000000)
113
114#define HM_CHANGED_GUEST_DR0_DR3 UINT64_C(0x0000000020000000)
115#define HM_CHANGED_GUEST_DR6 UINT64_C(0x0000000040000000)
116#define HM_CHANGED_GUEST_DR7 UINT64_C(0x0000000080000000)
117#define HM_CHANGED_GUEST_DR_MASK UINT64_C(0x00000000e0000000)
118
119#define HM_CHANGED_GUEST_X87 UINT64_C(0x0000000100000000)
120#define HM_CHANGED_GUEST_SSE_AVX UINT64_C(0x0000000200000000)
121#define HM_CHANGED_GUEST_OTHER_XSAVE UINT64_C(0x0000000400000000)
122#define HM_CHANGED_GUEST_XCRx UINT64_C(0x0000000800000000)
123
124#define HM_CHANGED_GUEST_KERNEL_GS_BASE UINT64_C(0x0000001000000000)
125#define HM_CHANGED_GUEST_SYSCALL_MSRS UINT64_C(0x0000002000000000)
126#define HM_CHANGED_GUEST_SYSENTER_CS_MSR UINT64_C(0x0000004000000000)
127#define HM_CHANGED_GUEST_SYSENTER_EIP_MSR UINT64_C(0x0000008000000000)
128#define HM_CHANGED_GUEST_SYSENTER_ESP_MSR UINT64_C(0x0000010000000000)
129#define HM_CHANGED_GUEST_SYSENTER_MSR_MASK UINT64_C(0x000001c000000000)
130#define HM_CHANGED_GUEST_TSC_AUX UINT64_C(0x0000020000000000)
131#define HM_CHANGED_GUEST_OTHER_MSRS UINT64_C(0x0000040000000000)
132#define HM_CHANGED_GUEST_ALL_MSRS ( HM_CHANGED_GUEST_EFER \
133 | HM_CHANGED_GUEST_KERNEL_GS_BASE \
134 | HM_CHANGED_GUEST_SYSCALL_MSRS \
135 | HM_CHANGED_GUEST_SYSENTER_MSR_MASK \
136 | HM_CHANGED_GUEST_TSC_AUX \
137 | HM_CHANGED_GUEST_OTHER_MSRS)
138
139#define HM_CHANGED_GUEST_HWVIRT UINT64_C(0x0000080000000000)
140#define HM_CHANGED_GUEST_MASK UINT64_C(0x00000ffffffffffc)
141
142#define HM_CHANGED_KEEPER_STATE_MASK UINT64_C(0xffff000000000000)
143
144#define HM_CHANGED_VMX_XCPT_INTERCEPTS UINT64_C(0x0001000000000000)
145#define HM_CHANGED_VMX_GUEST_AUTO_MSRS UINT64_C(0x0002000000000000)
146#define HM_CHANGED_VMX_GUEST_LAZY_MSRS UINT64_C(0x0004000000000000)
147#define HM_CHANGED_VMX_ENTRY_EXIT_CTLS UINT64_C(0x0008000000000000)
148#define HM_CHANGED_VMX_MASK UINT64_C(0x000f000000000000)
149#define HM_CHANGED_VMX_HOST_GUEST_SHARED_STATE ( HM_CHANGED_GUEST_DR_MASK \
150 | HM_CHANGED_VMX_GUEST_LAZY_MSRS)
151
152#define HM_CHANGED_SVM_XCPT_INTERCEPTS UINT64_C(0x0001000000000000)
153#define HM_CHANGED_SVM_MASK UINT64_C(0x0001000000000000)
154#define HM_CHANGED_SVM_HOST_GUEST_SHARED_STATE HM_CHANGED_GUEST_DR_MASK
155
156#define HM_CHANGED_ALL_GUEST ( HM_CHANGED_GUEST_MASK \
157 | HM_CHANGED_KEEPER_STATE_MASK)
158
159/** Mask of what state might have changed when IEM raised an exception.
160 * This is a based on IEM_CPUMCTX_EXTRN_XCPT_MASK. */
161#define HM_CHANGED_RAISED_XCPT_MASK ( HM_CHANGED_GUEST_GPRS_MASK \
162 | HM_CHANGED_GUEST_RIP \
163 | HM_CHANGED_GUEST_RFLAGS \
164 | HM_CHANGED_GUEST_SS \
165 | HM_CHANGED_GUEST_CS \
166 | HM_CHANGED_GUEST_CR0 \
167 | HM_CHANGED_GUEST_CR3 \
168 | HM_CHANGED_GUEST_CR4 \
169 | HM_CHANGED_GUEST_APIC_TPR \
170 | HM_CHANGED_GUEST_EFER_MSR \
171 | HM_CHANGED_GUEST_DR7 \
172 | HM_CHANGED_GUEST_CR2 \
173 | HM_CHANGED_GUEST_SREG_MASK \
174 | HM_CHANGED_GUEST_TABLE_MASK)
175
176#ifdef VBOX_WITH_NESTED_HWVIRT_SVM
177/** Mask of what state might have changed when \#VMEXIT is emulated. */
178# define HM_CHANGED_SVM_VMEXIT_MASK ( HM_CHANGED_GUEST_RSP \
179 | HM_CHANGED_GUEST_RAX \
180 | HM_CHANGED_GUEST_RIP \
181 | HM_CHANGED_GUEST_RFLAGS \
182 | HM_CHANGED_GUEST_CS \
183 | HM_CHANGED_GUEST_SS \
184 | HM_CHANGED_GUEST_DS \
185 | HM_CHANGED_GUEST_ES \
186 | HM_CHANGED_GUEST_GDTR \
187 | HM_CHANGED_GUEST_IDTR \
188 | HM_CHANGED_GUEST_CR_MASK \
189 | HM_CHANGED_GUEST_EFER_MSR \
190 | HM_CHANGED_GUEST_DR6 \
191 | HM_CHANGED_GUEST_DR7 \
192 | HM_CHANGED_GUEST_OTHER_MSRS \
193 | HM_CHANGED_GUEST_HWVIRT \
194 | HM_CHANGED_SVM_MASK \
195 | HM_CHANGED_GUEST_APIC_TPR)
196
197/** Mask of what state might have changed when VMRUN is emulated. */
198# define HM_CHANGED_SVM_VMRUN_MASK HM_CHANGED_SVM_VMEXIT_MASK
199#endif
200#ifdef VBOX_WITH_NESTED_HWVIRT_VMX
201/** Mask of what state might have changed when VM-exit is emulated.
202 *
203 * This is currently unused, but keeping it here in case we can get away a bit more
204 * fine-grained state handling.
205 *
206 * @note Update IEM_CPUMCTX_EXTRN_VMX_VMEXIT_MASK when this changes. */
207# define HM_CHANGED_VMX_VMEXIT_MASK ( HM_CHANGED_GUEST_CR0 | HM_CHANGED_GUEST_CR3 | HM_CHANGED_GUEST_CR4 \
208 | HM_CHANGED_GUEST_DR7 | HM_CHANGED_GUEST_DR6 \
209 | HM_CHANGED_GUEST_EFER_MSR \
210 | HM_CHANGED_GUEST_SYSENTER_MSR_MASK \
211 | HM_CHANGED_GUEST_OTHER_MSRS /* for PAT MSR */ \
212 | HM_CHANGED_GUEST_RIP | HM_CHANGED_GUEST_RSP | HM_CHANGED_GUEST_RFLAGS \
213 | HM_CHANGED_GUEST_SREG_MASK \
214 | HM_CHANGED_GUEST_TR \
215 | HM_CHANGED_GUEST_LDTR | HM_CHANGED_GUEST_GDTR | HM_CHANGED_GUEST_IDTR \
216 | HM_CHANGED_GUEST_HWVIRT )
217#endif
218/** @} */
219
220/** Maximum number of exit reason statistics counters. */
221#define MAX_EXITREASON_STAT 0x100
222#define MASK_EXITREASON_STAT 0xff
223#define MASK_INJECT_IRQ_STAT 0xff
224
225/** Size for the EPT identity page table (1024 4 MB pages to cover the entire address space). */
226#define HM_EPT_IDENTITY_PG_TABLE_SIZE PAGE_SIZE
227/** Size of the TSS structure + 2 pages for the IO bitmap + end byte. */
228#define HM_VTX_TSS_SIZE (sizeof(VBOXTSS) + 2 * PAGE_SIZE + 1)
229/** Total guest mapped memory needed. */
230#define HM_VTX_TOTAL_DEVHEAP_MEM (HM_EPT_IDENTITY_PG_TABLE_SIZE + HM_VTX_TSS_SIZE)
231
232
233/** @name Macros for enabling and disabling preemption.
234 * These are really just for hiding the RTTHREADPREEMPTSTATE and asserting that
235 * preemption has already been disabled when there is no context hook.
236 * @{ */
237#ifdef VBOX_STRICT
238# define HM_DISABLE_PREEMPT(a_pVCpu) \
239 RTTHREADPREEMPTSTATE PreemptStateInternal = RTTHREADPREEMPTSTATE_INITIALIZER; \
240 Assert(!RTThreadPreemptIsEnabled(NIL_RTTHREAD) || VMMR0ThreadCtxHookIsEnabled((a_pVCpu))); \
241 RTThreadPreemptDisable(&PreemptStateInternal)
242#else
243# define HM_DISABLE_PREEMPT(a_pVCpu) \
244 RTTHREADPREEMPTSTATE PreemptStateInternal = RTTHREADPREEMPTSTATE_INITIALIZER; \
245 RTThreadPreemptDisable(&PreemptStateInternal)
246#endif /* VBOX_STRICT */
247#define HM_RESTORE_PREEMPT() do { RTThreadPreemptRestore(&PreemptStateInternal); } while(0)
248/** @} */
249
250
251/** @name HM saved state versions.
252 * @{
253 */
254#define HM_SAVED_STATE_VERSION HM_SAVED_STATE_VERSION_SVM_NESTED_HWVIRT
255#define HM_SAVED_STATE_VERSION_SVM_NESTED_HWVIRT 6
256#define HM_SAVED_STATE_VERSION_TPR_PATCHING 5
257#define HM_SAVED_STATE_VERSION_NO_TPR_PATCHING 4
258#define HM_SAVED_STATE_VERSION_2_0_X 3
259/** @} */
260
261
262/**
263 * HM physical (host) CPU information.
264 */
265typedef struct HMPHYSCPU
266{
267 /** The CPU ID. */
268 RTCPUID idCpu;
269 /** The VM_HSAVE_AREA (AMD-V) / VMXON region (Intel) memory backing. */
270 RTR0MEMOBJ hMemObj;
271 /** The physical address of the first page in hMemObj (it's a
272 * physcially contigous allocation if it spans multiple pages). */
273 RTHCPHYS HCPhysMemObj;
274 /** The address of the memory (for pfnEnable). */
275 void *pvMemObj;
276 /** Current ASID (AMD-V) / VPID (Intel). */
277 uint32_t uCurrentAsid;
278 /** TLB flush count. */
279 uint32_t cTlbFlushes;
280 /** Whether to flush each new ASID/VPID before use. */
281 bool fFlushAsidBeforeUse;
282 /** Configured for VT-x or AMD-V. */
283 bool fConfigured;
284 /** Set if the VBOX_HWVIRTEX_IGNORE_SVM_IN_USE hack is active. */
285 bool fIgnoreAMDVInUseError;
286 /** In use by our code. (for power suspend) */
287 bool volatile fInUse;
288#ifdef VBOX_WITH_NESTED_HWVIRT_SVM
289 /** Nested-guest union (put data common to SVM/VMX outside the union). */
290 union
291 {
292 /** Nested-guest SVM data. */
293 struct
294 {
295 /** The active nested-guest MSR permission bitmap memory backing. */
296 RTR0MEMOBJ hNstGstMsrpm;
297 /** The physical address of the first page in hNstGstMsrpm (physcially
298 * contiguous allocation). */
299 RTHCPHYS HCPhysNstGstMsrpm;
300 /** The address of the active nested-guest MSRPM. */
301 void *pvNstGstMsrpm;
302 } svm;
303 /** @todo Nested-VMX. */
304 } n;
305#endif
306} HMPHYSCPU;
307/** Pointer to HMPHYSCPU struct. */
308typedef HMPHYSCPU *PHMPHYSCPU;
309/** Pointer to a const HMPHYSCPU struct. */
310typedef const HMPHYSCPU *PCHMPHYSCPU;
311
312/**
313 * TPR-instruction type.
314 */
315typedef enum
316{
317 HMTPRINSTR_INVALID,
318 HMTPRINSTR_READ,
319 HMTPRINSTR_READ_SHR4,
320 HMTPRINSTR_WRITE_REG,
321 HMTPRINSTR_WRITE_IMM,
322 HMTPRINSTR_JUMP_REPLACEMENT,
323 /** The usual 32-bit paranoia. */
324 HMTPRINSTR_32BIT_HACK = 0x7fffffff
325} HMTPRINSTR;
326
327/**
328 * TPR patch information.
329 */
330typedef struct
331{
332 /** The key is the address of patched instruction. (32 bits GC ptr) */
333 AVLOU32NODECORE Core;
334 /** Original opcode. */
335 uint8_t aOpcode[16];
336 /** Instruction size. */
337 uint32_t cbOp;
338 /** Replacement opcode. */
339 uint8_t aNewOpcode[16];
340 /** Replacement instruction size. */
341 uint32_t cbNewOp;
342 /** Instruction type. */
343 HMTPRINSTR enmType;
344 /** Source operand. */
345 uint32_t uSrcOperand;
346 /** Destination operand. */
347 uint32_t uDstOperand;
348 /** Number of times the instruction caused a fault. */
349 uint32_t cFaults;
350 /** Patch address of the jump replacement. */
351 RTGCPTR32 pJumpTarget;
352} HMTPRPATCH;
353/** Pointer to HMTPRPATCH. */
354typedef HMTPRPATCH *PHMTPRPATCH;
355/** Pointer to a const HMTPRPATCH. */
356typedef const HMTPRPATCH *PCHMTPRPATCH;
357
358
359/**
360 * Makes a HMEXITSTAT::uKey value from a program counter and an exit code.
361 *
362 * @returns 64-bit key
363 * @param a_uPC The RIP + CS.BASE value of the exit.
364 * @param a_uExit The exit code.
365 * @todo Add CPL?
366 */
367#define HMEXITSTAT_MAKE_KEY(a_uPC, a_uExit) (((a_uPC) & UINT64_C(0x0000ffffffffffff)) | (uint64_t)(a_uExit) << 48)
368
369typedef struct HMEXITINFO
370{
371 /** See HMEXITSTAT_MAKE_KEY(). */
372 uint64_t uKey;
373 /** Number of recent hits (depreciates with time). */
374 uint32_t volatile cHits;
375 /** The age + lock. */
376 uint16_t volatile uAge;
377 /** Action or action table index. */
378 uint16_t iAction;
379} HMEXITINFO;
380AssertCompileSize(HMEXITINFO, 16); /* Lots of these guys, so don't add any unnecessary stuff! */
381
382typedef struct HMEXITHISTORY
383{
384 /** The exit timestamp. */
385 uint64_t uTscExit;
386 /** The index of the corresponding HMEXITINFO entry.
387 * UINT32_MAX if none (too many collisions, race, whatever). */
388 uint32_t iExitInfo;
389 /** Figure out later, needed for padding now. */
390 uint32_t uSomeClueOrSomething;
391} HMEXITHISTORY;
392
393/**
394 * Switcher function, HC to the special 64-bit RC.
395 *
396 * @param pVM The cross context VM structure.
397 * @param offCpumVCpu Offset from pVM->cpum to pVM->aCpus[idCpu].cpum.
398 * @returns Return code indicating the action to take.
399 */
400typedef DECLCALLBACK(int) FNHMSWITCHERHC(PVM pVM, uint32_t offCpumVCpu);
401/** Pointer to switcher function. */
402typedef FNHMSWITCHERHC *PFNHMSWITCHERHC;
403
404/** @def HM_UNION_NM
405 * For compilers (like DTrace) that does not grok nameless unions, we have a
406 * little hack to make them palatable.
407 */
408/** @def HM_STRUCT_NM
409 * For compilers (like DTrace) that does not grok nameless structs (it is
410 * non-standard C++), we have a little hack to make them palatable.
411 */
412#ifdef VBOX_FOR_DTRACE_LIB
413# define HM_UNION_NM(a_Nm) a_Nm
414# define HM_STRUCT_NM(a_Nm) a_Nm
415#elif defined(IPRT_WITHOUT_NAMED_UNIONS_AND_STRUCTS)
416# define HM_UNION_NM(a_Nm) a_Nm
417# define HM_STRUCT_NM(a_Nm) a_Nm
418#else
419# define HM_UNION_NM(a_Nm)
420# define HM_STRUCT_NM(a_Nm)
421#endif
422
423/**
424 * HM event.
425 *
426 * VT-x and AMD-V common event injection structure.
427 */
428typedef struct HMEVENT
429{
430 /** Whether the event is pending. */
431 uint32_t fPending;
432 /** The error-code associated with the event. */
433 uint32_t u32ErrCode;
434 /** The length of the instruction in bytes (only relevant for software
435 * interrupts or software exceptions). */
436 uint32_t cbInstr;
437 /** Alignment. */
438 uint32_t u32Padding;
439 /** The encoded event (VM-entry interruption-information for VT-x or EVENTINJ
440 * for SVM). */
441 uint64_t u64IntInfo;
442 /** Guest virtual address if this is a page-fault event. */
443 RTGCUINTPTR GCPtrFaultAddress;
444} HMEVENT;
445/** Pointer to a HMEVENT struct. */
446typedef HMEVENT *PHMEVENT;
447/** Pointer to a const HMEVENT struct. */
448typedef const HMEVENT *PCHMEVENT;
449AssertCompileSizeAlignment(HMEVENT, 8);
450
451/**
452 * HM VM Instance data.
453 * Changes to this must checked against the padding of the hm union in VM!
454 */
455typedef struct HM
456{
457 /** Set when we've initialized VMX or SVM. */
458 bool fInitialized;
459 /** Set if nested paging is enabled. */
460 bool fNestedPaging;
461 /** Set if nested paging is allowed. */
462 bool fAllowNestedPaging;
463 /** Set if large pages are enabled (requires nested paging). */
464 bool fLargePages;
465 /** Set if we can support 64-bit guests or not. */
466 bool fAllow64BitGuests;
467 /** Set when TPR patching is allowed. */
468 bool fTprPatchingAllowed;
469 /** Set when we initialize VT-x or AMD-V once for all CPUs. */
470 bool fGlobalInit;
471 /** Set when TPR patching is active. */
472 bool fTPRPatchingActive;
473 /** Set when the debug facility has breakpoints/events enabled that requires
474 * us to use the debug execution loop in ring-0. */
475 bool fUseDebugLoop;
476 /** Set if hardware APIC virtualization is enabled. */
477 bool fVirtApicRegs;
478 /** Set if posted interrupt processing is enabled. */
479 bool fPostedIntrs;
480 /** Set if indirect branch prediction barrier on VM exit. */
481 bool fIbpbOnVmExit;
482 /** Set if indirect branch prediction barrier on VM entry. */
483 bool fIbpbOnVmEntry;
484 /** Set if level 1 data cache should be flushed on VM entry. */
485 bool fL1dFlushOnVmEntry;
486 /** Set if level 1 data cache should be flushed on EMT scheduling. */
487 bool fL1dFlushOnSched;
488 /** Set if host manages speculation control settings. */
489 bool fSpecCtrlByHost;
490 /** Set if MDS related buffers should be cleared on VM entry. */
491 bool fMdsClearOnVmEntry;
492 /** Set if MDS related buffers should be cleared on EMT scheduling. */
493 bool fMdsClearOnSched;
494 /** Alignment padding. */
495 bool afPaddingMinus1[6];
496
497 /** Maximum ASID allowed. */
498 uint32_t uMaxAsid;
499 /** The maximum number of resumes loops allowed in ring-0 (safety precaution).
500 * This number is set much higher when RTThreadPreemptIsPending is reliable. */
501 uint32_t cMaxResumeLoops;
502
503 /** Host kernel flags that HM might need to know (SUPKERNELFEATURES_XXX). */
504 uint32_t fHostKernelFeatures;
505
506 /** Size of the guest patch memory block. */
507 uint32_t cbGuestPatchMem;
508 /** Guest allocated memory for patching purposes. */
509 RTGCPTR pGuestPatchMem;
510 /** Current free pointer inside the patch block. */
511 RTGCPTR pFreeGuestPatchMem;
512
513#if HC_ARCH_BITS == 32 && defined(VBOX_ENABLE_64_BITS_GUESTS)
514 /** 32 to 64 bits switcher entrypoint. */
515 R0PTRTYPE(PFNHMSWITCHERHC) pfnHost32ToGuest64R0;
516 RTR0PTR pvR0Alignment0;
517#endif
518
519 struct
520 {
521 /** Set by the ring-0 side of HM to indicate VMX is supported by the
522 * CPU. */
523 bool fSupported;
524 /** Set when we've enabled VMX. */
525 bool fEnabled;
526 /** Set if VPID is supported. */
527 bool fVpid;
528 /** Set if VT-x VPID is allowed. */
529 bool fAllowVpid;
530 /** Set if unrestricted guest execution is in use (real and protected mode
531 * without paging). */
532 bool fUnrestrictedGuest;
533 /** Set if unrestricted guest execution is allowed to be used. */
534 bool fAllowUnrestricted;
535 /** Set if the preemption timer is in use or not. */
536 bool fUsePreemptTimer;
537 /** The shift mask employed by the VMX-Preemption timer. */
538 uint8_t cPreemptTimerShift;
539
540 /** Virtual address of the TSS page used for real mode emulation. */
541 R3PTRTYPE(PVBOXTSS) pRealModeTSS;
542 /** Virtual address of the identity page table used for real mode and protected
543 * mode without paging emulation in EPT mode. */
544 R3PTRTYPE(PX86PD) pNonPagingModeEPTPageTable;
545
546 /** Physical address of the APIC-access page. */
547 RTHCPHYS HCPhysApicAccess;
548 /** R0 memory object for the APIC-access page. */
549 RTR0MEMOBJ hMemObjApicAccess;
550 /** Virtual address of the APIC-access page. */
551 R0PTRTYPE(uint8_t *) pbApicAccess;
552
553 /** Physical address of the VMREAD bitmap. */
554 RTHCPHYS HCPhysVmreadBitmap;
555 /** Ring-0 memory object for the VMREAD bitmap. */
556 RTR0MEMOBJ hMemObjVmreadBitmap;
557 /** Pointer to the VMREAD bitmap. */
558 R0PTRTYPE(void *) pvVmreadBitmap;
559
560 /** Physical address of the VMWRITE bitmap. */
561 RTHCPHYS HCPhysVmwriteBitmap;
562 /** Ring-0 memory object for the VMWRITE bitmap. */
563 RTR0MEMOBJ hMemObjVmwriteBitmap;
564 /** Pointer to the VMWRITE bitmap. */
565 R0PTRTYPE(void *) pvVmwriteBitmap;
566
567#ifdef VBOX_WITH_CRASHDUMP_MAGIC
568 /** Physical address of the crash-dump scratch area. */
569 RTHCPHYS HCPhysScratch;
570 /** Ring-0 memory object for the crash-dump scratch area. */
571 RTR0MEMOBJ hMemObjScratch;
572 /** Pointer to the crash-dump scratch bitmap. */
573 R0PTRTYPE(uint8_t *) pbScratch;
574#endif
575
576 /** Tagged-TLB flush type. */
577 VMXTLBFLUSHTYPE enmTlbFlushType;
578 /** Flush type to use for INVEPT. */
579 VMXTLBFLUSHEPT enmTlbFlushEpt;
580 /** Flush type to use for INVVPID. */
581 VMXTLBFLUSHVPID enmTlbFlushVpid;
582
583 /** Pause-loop exiting (PLE) gap in ticks. */
584 uint32_t cPleGapTicks;
585 /** Pause-loop exiting (PLE) window in ticks. */
586 uint32_t cPleWindowTicks;
587 uint32_t u32Alignment0;
588
589 /** Host CR4 value (set by ring-0 VMX init) */
590 uint64_t u64HostCr4;
591 /** Host SMM monitor control (set by ring-0 VMX init) */
592 uint64_t u64HostSmmMonitorCtl;
593 /** Host EFER value (set by ring-0 VMX init) */
594 uint64_t u64HostMsrEfer;
595 /** Whether the CPU supports VMCS fields for swapping EFER. */
596 bool fSupportsVmcsEfer;
597 uint8_t u8Alignment2[7];
598
599 /** VMX MSR values. */
600 VMXMSRS Msrs;
601
602 /** Host-physical address for a failing VMXON instruction. */
603 RTHCPHYS HCPhysVmxEnableError;
604
605 /** Pointer to the shadow VMCS fields array. */
606 R0PTRTYPE(uint32_t *) paShadowVmcsFields;
607 RTR0PTR pvR0Alignment1;
608 /** Number of elements in the shadow VMCS fields array. */
609 uint32_t cShadowVmcsFields;
610 uint32_t u32Alignemnt0;
611 } vmx;
612
613 struct
614 {
615 /** Set by the ring-0 side of HM to indicate SVM is supported by the
616 * CPU. */
617 bool fSupported;
618 /** Set when we've enabled SVM. */
619 bool fEnabled;
620 /** Set if erratum 170 affects the AMD cpu. */
621 bool fAlwaysFlushTLB;
622 /** Set when the hack to ignore VERR_SVM_IN_USE is active. */
623 bool fIgnoreInUseError;
624 /** Whether to use virtualized VMSAVE/VMLOAD feature. */
625 bool fVirtVmsaveVmload;
626 /** Whether to use virtual GIF feature. */
627 bool fVGif;
628 uint8_t u8Alignment0[2];
629
630 /** Physical address of the IO bitmap (12kb). */
631 RTHCPHYS HCPhysIOBitmap;
632 /** R0 memory object for the IO bitmap (12kb). */
633 RTR0MEMOBJ hMemObjIOBitmap;
634 /** Virtual address of the IO bitmap. */
635 R0PTRTYPE(void *) pvIOBitmap;
636
637 /* HWCR MSR (for diagnostics) */
638 uint64_t u64MsrHwcr;
639
640 /** SVM revision. */
641 uint32_t u32Rev;
642 /** SVM feature bits from cpuid 0x8000000a */
643 uint32_t u32Features;
644
645 /** Pause filter counter. */
646 uint16_t cPauseFilter;
647 /** Pause filter treshold in ticks. */
648 uint16_t cPauseFilterThresholdTicks;
649 uint32_t u32Alignment0;
650 } svm;
651
652 /**
653 * AVL tree with all patches (active or disabled) sorted by guest instruction
654 * address.
655 */
656 AVLOU32TREE PatchTree;
657 uint32_t cPatches;
658 HMTPRPATCH aPatches[64];
659
660 /** Last recorded error code during HM ring-0 init. */
661 int32_t rcInit;
662
663 /** HMR0Init was run */
664 bool fHMR0Init;
665 bool u8Alignment1[3];
666
667 STAMCOUNTER StatTprPatchSuccess;
668 STAMCOUNTER StatTprPatchFailure;
669 STAMCOUNTER StatTprReplaceSuccessCr8;
670 STAMCOUNTER StatTprReplaceSuccessVmc;
671 STAMCOUNTER StatTprReplaceFailure;
672} HM;
673/** Pointer to HM VM instance data. */
674typedef HM *PHM;
675
676AssertCompileMemberAlignment(HM, StatTprPatchSuccess, 8);
677
678/* Maximum number of cached entries. */
679#define VMX_VMCS_CACHE_MAX_ENTRY 128
680
681/**
682 * Cache of a VMCS for batch reads or writes.
683 */
684typedef struct VMXVMCSCACHE
685{
686#ifdef VBOX_WITH_CRASHDUMP_MAGIC
687 /* Magic marker for searching in crash dumps. */
688 uint8_t aMagic[16];
689 uint64_t uMagic;
690 uint64_t u64TimeEntry;
691 uint64_t u64TimeSwitch;
692 uint64_t cResume;
693 uint64_t interPD;
694 uint64_t pSwitcher;
695 uint32_t uPos;
696 uint32_t idCpu;
697#endif
698 /* CR2 is saved here for EPT syncing. */
699 uint64_t cr2;
700 struct
701 {
702 uint32_t cValidEntries;
703 uint32_t uAlignment;
704 uint32_t aField[VMX_VMCS_CACHE_MAX_ENTRY];
705 uint64_t aFieldVal[VMX_VMCS_CACHE_MAX_ENTRY];
706 } Write;
707 struct
708 {
709 uint32_t cValidEntries;
710 uint32_t uAlignment;
711 uint32_t aField[VMX_VMCS_CACHE_MAX_ENTRY];
712 uint64_t aFieldVal[VMX_VMCS_CACHE_MAX_ENTRY];
713 } Read;
714#ifdef VBOX_STRICT
715 struct
716 {
717 RTHCPHYS HCPhysCpuPage;
718 RTHCPHYS HCPhysVmcs;
719 RTGCPTR pCache;
720 RTGCPTR pCtx;
721 } TestIn;
722 struct
723 {
724 RTHCPHYS HCPhysVmcs;
725 RTGCPTR pCache;
726 RTGCPTR pCtx;
727 uint64_t eflags;
728 uint64_t cr8;
729 } TestOut;
730 struct
731 {
732 uint64_t param1;
733 uint64_t param2;
734 uint64_t param3;
735 uint64_t param4;
736 } ScratchPad;
737#endif
738} VMXVMCSCACHE;
739/** Pointer to VMXVMCSCACHE. */
740typedef VMXVMCSCACHE *PVMXVMCSCACHE;
741AssertCompileSizeAlignment(VMXVMCSCACHE, 8);
742
743/**
744 * VMX StartVM function.
745 *
746 * @returns VBox status code (no informational stuff).
747 * @param fResume Whether to use VMRESUME (true) or VMLAUNCH (false).
748 * @param pCtx The CPU register context.
749 * @param pVmcsCache The VMCS batch cache.
750 * @param pVM Pointer to the cross context VM structure.
751 * @param pVCpu Pointer to the cross context per-CPU structure.
752 */
753typedef DECLCALLBACK(int) FNHMVMXSTARTVM(RTHCUINT fResume, PCPUMCTX pCtx, PVMXVMCSCACHE pVmcsCache, PVM pVM, PVMCPU pVCpu);
754/** Pointer to a VMX StartVM function. */
755typedef R0PTRTYPE(FNHMVMXSTARTVM *) PFNHMVMXSTARTVM;
756
757/** SVM VMRun function. */
758typedef DECLCALLBACK(int) FNHMSVMVMRUN(RTHCPHYS pVmcbHostPhys, RTHCPHYS pVmcbPhys, PCPUMCTX pCtx, PVM pVM, PVMCPU pVCpu);
759/** Pointer to a SVM VMRun function. */
760typedef R0PTRTYPE(FNHMSVMVMRUN *) PFNHMSVMVMRUN;
761
762/**
763 * VMX VMCS information.
764 *
765 * This structure provides information maintained for and during the executing of a
766 * guest (or nested-guest) VMCS (VM control structure) using hardware-assisted VMX.
767 */
768typedef struct VMXVMCSINFO
769{
770 /** @name VMLAUNCH/VMRESUME information.
771 * @{ */
772 /** Ring-0 pointer to the hardware-assisted VMX execution function. */
773 PFNHMVMXSTARTVM pfnStartVM;
774#if HC_ARCH_BITS == 32
775 uint32_t u32Alignment0;
776#endif
777 /** @} */
778
779 /** @name VMCS and related data structures.
780 * @{ */
781 /** Host-physical address of the VMCS. */
782 RTHCPHYS HCPhysVmcs;
783 /** R0 memory object for the VMCS. */
784 RTR0MEMOBJ hMemObjVmcs;
785 /** Host-virtual address of the VMCS. */
786 R0PTRTYPE(void *) pvVmcs;
787
788 /** Host-physical address of the shadow VMCS. */
789 RTHCPHYS HCPhysShadowVmcs;
790 /** R0 memory object for the shadow VMCS. */
791 RTR0MEMOBJ hMemObjShadowVmcs;
792 /** Host-virtual address of the shadow VMCS. */
793 R0PTRTYPE(void *) pvShadowVmcs;
794
795 /** Host-physical address of the virtual APIC page. */
796 RTHCPHYS HCPhysVirtApic;
797 /** Alignment. */
798 R0PTRTYPE(void *) pvAlignment0;
799 /** Host-virtual address of the virtual-APIC page. */
800 R0PTRTYPE(uint8_t *) pbVirtApic;
801
802 /** Host-physical address of the MSR bitmap. */
803 RTHCPHYS HCPhysMsrBitmap;
804 /** R0 memory object for the MSR bitmap. */
805 RTR0MEMOBJ hMemObjMsrBitmap;
806 /** Host-virtual address of the MSR bitmap. */
807 R0PTRTYPE(void *) pvMsrBitmap;
808
809 /** Host-physical address of the VM-entry MSR-load area. */
810 RTHCPHYS HCPhysGuestMsrLoad;
811 /** R0 memory object of the VM-entry MSR-load area. */
812 RTR0MEMOBJ hMemObjGuestMsrLoad;
813 /** Host-virtual address of the VM-entry MSR-load area. */
814 R0PTRTYPE(void *) pvGuestMsrLoad;
815
816 /** Host-physical address of the VM-exit MSR-store area. */
817 RTHCPHYS HCPhysGuestMsrStore;
818 /** R0 memory object of the VM-exit MSR-store area. */
819 RTR0MEMOBJ hMemObjGuestMsrStore;
820 /** Host-virtual address of the VM-exit MSR-store area. */
821 R0PTRTYPE(void *) pvGuestMsrStore;
822
823 /** Host-physical address of the VM-exit MSR-load area. */
824 RTHCPHYS HCPhysHostMsrLoad;
825 /** R0 memory object for the VM-exit MSR-load area. */
826 RTR0MEMOBJ hMemObjHostMsrLoad;
827 /** Host-virtual address of the VM-exit MSR-load area. */
828 R0PTRTYPE(void *) pvHostMsrLoad;
829
830 /** Host-physical address of the EPTP. */
831 RTHCPHYS HCPhysEPTP;
832 /** Number of guest MSRs in the VM-entry MSR-load area. */
833 uint32_t cEntryMsrLoad;
834 /** Number of guest MSRs in the VM-exit MSR-store area. */
835 uint32_t cExitMsrStore;
836 /** Number of host MSRs in the VM-exit MSR-load area. */
837 uint32_t cExitMsrLoad;
838 /** Padding. */
839 uint32_t u32Padding0;
840 /** @} */
841
842 /** @name Auxiliary information.
843 * @{ */
844 /** The VMCS launch state, see VMX_V_VMCS_LAUNCH_STATE_XXX. */
845 uint32_t fVmcsState;
846 /** The VMCS launch state of the shadow VMCS, see VMX_V_VMCS_LAUNCH_STATE_XXX. */
847 uint32_t fShadowVmcsState;
848 /** Set if guest was executing in real mode (extra checks). */
849 bool fWasInRealMode;
850 /** Set if the guest switched to 64-bit mode on a 32-bit host. */
851 bool fSwitchedTo64on32;
852 /** Padding. */
853 bool afPadding0[6];
854 /** @} */
855
856 /** @name Cache of execution related VMCS fields.
857 * @{ */
858 /** Pin-based VM-execution controls. */
859 uint32_t u32PinCtls;
860 /** Processor-based VM-execution controls. */
861 uint32_t u32ProcCtls;
862 /** Secondary processor-based VM-execution controls. */
863 uint32_t u32ProcCtls2;
864 /** VM-entry controls. */
865 uint32_t u32EntryCtls;
866 /** VM-exit controls. */
867 uint32_t u32ExitCtls;
868 /** Exception bitmap. */
869 uint32_t u32XcptBitmap;
870 /** CR0 guest/host mask. */
871 uint64_t u64Cr0Mask;
872 /** CR4 guest/host mask. */
873 uint64_t u64Cr4Mask;
874 /** Page-fault exception error-code mask. */
875 uint32_t u32XcptPFMask;
876 /** Page-fault exception error-code match. */
877 uint32_t u32XcptPFMatch;
878 /** TSC offset. */
879 uint64_t u64TscOffset;
880 /** VMCS link pointer. */
881 uint64_t u64VmcsLinkPtr;
882 /** @} */
883
884 /** @name Real-mode emulation state.
885 * @{ */
886 struct
887 {
888 X86DESCATTR AttrCS;
889 X86DESCATTR AttrDS;
890 X86DESCATTR AttrES;
891 X86DESCATTR AttrFS;
892 X86DESCATTR AttrGS;
893 X86DESCATTR AttrSS;
894 X86EFLAGS Eflags;
895 bool fRealOnV86Active;
896 bool afPadding1[3];
897 } RealMode;
898 /** @} */
899
900 /** Padding. */
901 uint64_t au64Padding[2];
902} VMXVMCSINFO;
903/** Pointer to a VMXVMCSINFO struct. */
904typedef VMXVMCSINFO *PVMXVMCSINFO;
905/** Pointer to a const VMXVMCSINFO struct. */
906typedef const VMXVMCSINFO *PCVMXVMCSINFO;
907AssertCompileSizeAlignment(VMXVMCSINFO, 8);
908AssertCompileMemberAlignment(VMXVMCSINFO, fVmcsState, 8);
909AssertCompileMemberAlignment(VMXVMCSINFO, u32PinCtls, 8);
910AssertCompileMemberAlignment(VMXVMCSINFO, u64VmcsLinkPtr, 8);
911
912/**
913 * HM VMCPU Instance data.
914 *
915 * Note! If you change members of this struct, make sure to check if the
916 * assembly counterpart in HMInternal.mac needs to be updated as well.
917 */
918typedef struct HMCPU
919{
920 /** Set when the TLB has been checked until we return from the world switch. */
921 bool volatile fCheckedTLBFlush;
922 /** Set if we need to flush the TLB during the world switch. */
923 bool fForceTLBFlush;
924 /** Set when we're using VT-x or AMD-V at that moment. */
925 bool fActive;
926 /** Whether we've completed the inner HM leave function. */
927 bool fLeaveDone;
928 /** Whether we're using the hyper DR7 or guest DR7. */
929 bool fUsingHyperDR7;
930 /** Set if XCR0 needs to be saved/restored when entering/exiting guest code
931 * execution. */
932 bool fLoadSaveGuestXcr0;
933
934 /** Whether we should use the debug loop because of single stepping or special
935 * debug breakpoints / events are armed. */
936 bool fUseDebugLoop;
937 /** Whether we are currently executing in the debug loop.
938 * Mainly for assertions. */
939 bool fUsingDebugLoop;
940 /** Set if we using the debug loop and wish to intercept RDTSC. */
941 bool fDebugWantRdTscExit;
942 /** Whether we're executing a single instruction. */
943 bool fSingleInstruction;
944 /** Set if we need to clear the trap flag because of single stepping. */
945 bool fClearTrapFlag;
946
947 /** Whether \#UD needs to be intercepted (required by certain GIM providers). */
948 bool fGIMTrapXcptUD;
949 /** Whether \#GP needs to be intercept for mesa driver workaround. */
950 bool fTrapXcptGpForLovelyMesaDrv;
951 uint8_t u8Alignment0[3];
952
953 /** World switch exit counter. */
954 uint32_t volatile cWorldSwitchExits;
955 /** The last CPU we were executing code on (NIL_RTCPUID for the first time). */
956 RTCPUID idLastCpu;
957 /** TLB flush count. */
958 uint32_t cTlbFlushes;
959 /** Current ASID in use by the VM. */
960 uint32_t uCurrentAsid;
961 /** An additional error code used for some gurus. */
962 uint32_t u32HMError;
963 /** The last exit-to-ring-3 reason. */
964 int32_t rcLastExitToR3;
965 /** CPU-context changed flags (see HM_CHANGED_xxx). */
966 uint64_t fCtxChanged;
967 /** Host's TSC_AUX MSR (used when RDTSCP doesn't cause VM-exits). */
968 uint64_t u64HostTscAux; /** @todo r=ramshankar: Can be removed and put in SVMTRANSIENT instead! */
969
970 union /* no tag! */
971 {
972 /** VT-x data. */
973 struct
974 {
975 /** @name Guest information.
976 * @{ */
977 /** Guest VMCS information. */
978 VMXVMCSINFO VmcsInfo;
979 /** Nested-guest VMCS information. */
980 VMXVMCSINFO VmcsInfoNstGst;
981 /** Whether the nested-guest VMCS was the last current VMCS. */
982 bool fSwitchedToNstGstVmcs;
983 /** Whether the static guest VMCS controls has been merged with the
984 * nested-guest VMCS controls. */
985 bool fMergedNstGstCtls;
986 /** Alignment. */
987 bool afAlignment0[6];
988 /** Cached guest APIC-base MSR for identifying when to map the APIC-access page. */
989 uint64_t u64GstMsrApicBase;
990 /** VMCS cache for batched vmread/vmwrites. */
991 VMXVMCSCACHE VmcsCache;
992 /** @} */
993
994 /** @name Host information.
995 * @{ */
996 /** Host LSTAR MSR to restore lazily while leaving VT-x. */
997 uint64_t u64HostMsrLStar;
998 /** Host STAR MSR to restore lazily while leaving VT-x. */
999 uint64_t u64HostMsrStar;
1000 /** Host SF_MASK MSR to restore lazily while leaving VT-x. */
1001 uint64_t u64HostMsrSfMask;
1002 /** Host KernelGS-Base MSR to restore lazily while leaving VT-x. */
1003 uint64_t u64HostMsrKernelGsBase;
1004 /** The mask of lazy MSRs swap/restore state, see VMX_LAZY_MSRS_XXX. */
1005 uint32_t fLazyMsrs;
1006 /** Whether the host MSR values are up-to-date in the auto-load/store MSR area. */
1007 bool fUpdatedHostAutoMsrs;
1008 /** Alignment. */
1009 uint8_t au8Alignment0[3];
1010 /** Which host-state bits to restore before being preempted. */
1011 uint32_t fRestoreHostFlags;
1012 /** Alignment. */
1013 uint32_t u32Alignment0;
1014 /** The host-state restoration structure. */
1015 VMXRESTOREHOST RestoreHost;
1016 /** @} */
1017
1018 /** @name Error reporting and diagnostics.
1019 * @{ */
1020 /** VT-x error-reporting (mainly for ring-3 propagation). */
1021 struct
1022 {
1023 RTHCPHYS HCPhysCurrentVmcs;
1024 uint32_t u32VmcsRev;
1025 uint32_t u32InstrError;
1026 uint32_t u32ExitReason;
1027 uint32_t u32Alignment0;
1028 RTCPUID idEnteredCpu;
1029 RTCPUID idCurrentCpu;
1030 } LastError;
1031 /** @} */
1032 } vmx;
1033
1034 /** SVM data. */
1035 struct
1036 {
1037 /** Ring 0 handlers for VT-x. */
1038 PFNHMSVMVMRUN pfnVMRun;
1039#if HC_ARCH_BITS == 32
1040 uint32_t u32Alignment0;
1041#endif
1042
1043 /** Physical address of the host VMCB which holds additional host-state. */
1044 RTHCPHYS HCPhysVmcbHost;
1045 /** R0 memory object for the host VMCB which holds additional host-state. */
1046 RTR0MEMOBJ hMemObjVmcbHost;
1047 /** Padding. */
1048 R0PTRTYPE(void *) pvPadding;
1049
1050 /** Physical address of the guest VMCB. */
1051 RTHCPHYS HCPhysVmcb;
1052 /** R0 memory object for the guest VMCB. */
1053 RTR0MEMOBJ hMemObjVmcb;
1054 /** Pointer to the guest VMCB. */
1055 R0PTRTYPE(PSVMVMCB) pVmcb;
1056
1057 /** Physical address of the MSR bitmap (8 KB). */
1058 RTHCPHYS HCPhysMsrBitmap;
1059 /** R0 memory object for the MSR bitmap (8 KB). */
1060 RTR0MEMOBJ hMemObjMsrBitmap;
1061 /** Pointer to the MSR bitmap. */
1062 R0PTRTYPE(void *) pvMsrBitmap;
1063
1064 /** Whether VTPR with V_INTR_MASKING set is in effect, indicating
1065 * we should check if the VTPR changed on every VM-exit. */
1066 bool fSyncVTpr;
1067 uint8_t au8Alignment0[7];
1068
1069 /** Cache of the nested-guest's VMCB fields that we modify in order to run the
1070 * nested-guest using AMD-V. This will be restored on \#VMEXIT. */
1071 SVMNESTEDVMCBCACHE NstGstVmcbCache;
1072 } svm;
1073 } HM_UNION_NM(u);
1074
1075 /** Event injection state. */
1076 HMEVENT Event;
1077
1078 /** The PAE PDPEs used with Nested Paging (only valid when
1079 * VMCPU_FF_HM_UPDATE_PAE_PDPES is set). */
1080 X86PDPE aPdpes[4];
1081
1082 /** Current shadow paging mode for updating CR4. */
1083 PGMMODE enmShadowMode;
1084
1085 /** The CPU ID of the CPU currently owning the VMCS. Set in
1086 * HMR0Enter and cleared in HMR0Leave. */
1087 RTCPUID idEnteredCpu;
1088
1089 /** For saving stack space, the disassembler state is allocated here instead of
1090 * on the stack. */
1091 DISCPUSTATE DisState;
1092
1093 STAMPROFILEADV StatEntry;
1094 STAMPROFILEADV StatPreExit;
1095 STAMPROFILEADV StatExitHandling;
1096 STAMPROFILEADV StatExitIO;
1097 STAMPROFILEADV StatExitMovCRx;
1098 STAMPROFILEADV StatExitXcptNmi;
1099 STAMPROFILEADV StatImportGuestState;
1100 STAMPROFILEADV StatExportGuestState;
1101 STAMPROFILEADV StatLoadGuestFpuState;
1102 STAMPROFILEADV StatInGC;
1103#if HC_ARCH_BITS == 32 && defined(VBOX_ENABLE_64_BITS_GUESTS)
1104 STAMPROFILEADV StatWorldSwitch3264;
1105#endif
1106 STAMPROFILEADV StatPoke;
1107 STAMPROFILEADV StatSpinPoke;
1108 STAMPROFILEADV StatSpinPokeFailed;
1109
1110 STAMCOUNTER StatInjectInterrupt;
1111 STAMCOUNTER StatInjectXcpt;
1112 STAMCOUNTER StatInjectPendingReflect;
1113 STAMCOUNTER StatInjectPendingInterpret;
1114
1115 STAMCOUNTER StatExitAll;
1116 STAMCOUNTER StatExitShadowNM;
1117 STAMCOUNTER StatExitGuestNM;
1118 STAMCOUNTER StatExitShadowPF; /**< Misleading, currently used for MMIO \#PFs as well. */
1119 STAMCOUNTER StatExitShadowPFEM;
1120 STAMCOUNTER StatExitGuestPF;
1121 STAMCOUNTER StatExitGuestUD;
1122 STAMCOUNTER StatExitGuestSS;
1123 STAMCOUNTER StatExitGuestNP;
1124 STAMCOUNTER StatExitGuestTS;
1125 STAMCOUNTER StatExitGuestGP;
1126 STAMCOUNTER StatExitGuestDE;
1127 STAMCOUNTER StatExitGuestDB;
1128 STAMCOUNTER StatExitGuestMF;
1129 STAMCOUNTER StatExitGuestBP;
1130 STAMCOUNTER StatExitGuestXF;
1131 STAMCOUNTER StatExitGuestXcpUnk;
1132 STAMCOUNTER StatExitDRxWrite;
1133 STAMCOUNTER StatExitDRxRead;
1134 STAMCOUNTER StatExitCR0Read;
1135 STAMCOUNTER StatExitCR2Read;
1136 STAMCOUNTER StatExitCR3Read;
1137 STAMCOUNTER StatExitCR4Read;
1138 STAMCOUNTER StatExitCR8Read;
1139 STAMCOUNTER StatExitCR0Write;
1140 STAMCOUNTER StatExitCR2Write;
1141 STAMCOUNTER StatExitCR3Write;
1142 STAMCOUNTER StatExitCR4Write;
1143 STAMCOUNTER StatExitCR8Write;
1144 STAMCOUNTER StatExitRdmsr;
1145 STAMCOUNTER StatExitWrmsr;
1146 STAMCOUNTER StatExitClts;
1147 STAMCOUNTER StatExitXdtrAccess;
1148 STAMCOUNTER StatExitLmsw;
1149 STAMCOUNTER StatExitIOWrite;
1150 STAMCOUNTER StatExitIORead;
1151 STAMCOUNTER StatExitIOStringWrite;
1152 STAMCOUNTER StatExitIOStringRead;
1153 STAMCOUNTER StatExitIntWindow;
1154 STAMCOUNTER StatExitExtInt;
1155 STAMCOUNTER StatExitHostNmiInGC;
1156 STAMCOUNTER StatExitPreemptTimer;
1157 STAMCOUNTER StatExitTprBelowThreshold;
1158 STAMCOUNTER StatExitTaskSwitch;
1159 STAMCOUNTER StatExitApicAccess;
1160 STAMCOUNTER StatExitReasonNpf;
1161
1162 STAMCOUNTER StatNestedExitReasonNpf;
1163
1164 STAMCOUNTER StatFlushPage;
1165 STAMCOUNTER StatFlushPageManual;
1166 STAMCOUNTER StatFlushPhysPageManual;
1167 STAMCOUNTER StatFlushTlb;
1168 STAMCOUNTER StatFlushTlbManual;
1169 STAMCOUNTER StatFlushTlbWorldSwitch;
1170 STAMCOUNTER StatNoFlushTlbWorldSwitch;
1171 STAMCOUNTER StatFlushEntire;
1172 STAMCOUNTER StatFlushAsid;
1173 STAMCOUNTER StatFlushNestedPaging;
1174 STAMCOUNTER StatFlushTlbInvlpgVirt;
1175 STAMCOUNTER StatFlushTlbInvlpgPhys;
1176 STAMCOUNTER StatTlbShootdown;
1177 STAMCOUNTER StatTlbShootdownFlush;
1178
1179 STAMCOUNTER StatSwitchPendingHostIrq;
1180 STAMCOUNTER StatSwitchTprMaskedIrq;
1181 STAMCOUNTER StatSwitchGuestIrq;
1182 STAMCOUNTER StatSwitchHmToR3FF;
1183 STAMCOUNTER StatSwitchExitToR3;
1184 STAMCOUNTER StatSwitchLongJmpToR3;
1185 STAMCOUNTER StatSwitchMaxResumeLoops;
1186 STAMCOUNTER StatSwitchHltToR3;
1187 STAMCOUNTER StatSwitchApicAccessToR3;
1188 STAMCOUNTER StatSwitchPreempt;
1189 STAMCOUNTER StatSwitchPreemptExportHostState;
1190
1191 STAMCOUNTER StatTscParavirt;
1192 STAMCOUNTER StatTscOffset;
1193 STAMCOUNTER StatTscIntercept;
1194
1195 STAMCOUNTER StatDRxArmed;
1196 STAMCOUNTER StatDRxContextSwitch;
1197 STAMCOUNTER StatDRxIoCheck;
1198
1199 STAMCOUNTER StatExportMinimal;
1200 STAMCOUNTER StatExportFull;
1201 STAMCOUNTER StatLoadGuestFpu;
1202
1203 STAMCOUNTER StatVmxCheckBadRmSelBase;
1204 STAMCOUNTER StatVmxCheckBadRmSelLimit;
1205 STAMCOUNTER StatVmxCheckBadRmSelAttr;
1206 STAMCOUNTER StatVmxCheckBadV86SelBase;
1207 STAMCOUNTER StatVmxCheckBadV86SelLimit;
1208 STAMCOUNTER StatVmxCheckBadV86SelAttr;
1209 STAMCOUNTER StatVmxCheckRmOk;
1210 STAMCOUNTER StatVmxCheckBadSel;
1211 STAMCOUNTER StatVmxCheckBadRpl;
1212 STAMCOUNTER StatVmxCheckPmOk;
1213
1214#if HC_ARCH_BITS == 32 && defined(VBOX_ENABLE_64_BITS_GUESTS)
1215 STAMCOUNTER StatFpu64SwitchBack;
1216 STAMCOUNTER StatDebug64SwitchBack;
1217#endif
1218#ifdef VBOX_WITH_STATISTICS
1219 R3PTRTYPE(PSTAMCOUNTER) paStatExitReason;
1220 R0PTRTYPE(PSTAMCOUNTER) paStatExitReasonR0;
1221 R3PTRTYPE(PSTAMCOUNTER) paStatInjectedIrqs;
1222 R0PTRTYPE(PSTAMCOUNTER) paStatInjectedIrqsR0;
1223 R3PTRTYPE(PSTAMCOUNTER) paStatNestedExitReason;
1224 R0PTRTYPE(PSTAMCOUNTER) paStatNestedExitReasonR0;
1225#endif
1226#ifdef HM_PROFILE_EXIT_DISPATCH
1227 STAMPROFILEADV StatExitDispatch;
1228#endif
1229} HMCPU;
1230/** Pointer to HM VMCPU instance data. */
1231typedef HMCPU *PHMCPU;
1232AssertCompileMemberAlignment(HMCPU, cWorldSwitchExits, 4);
1233AssertCompileMemberAlignment(HMCPU, fCtxChanged, 8);
1234AssertCompileMemberAlignment(HMCPU, HM_UNION_NM(u.) vmx, 8);
1235AssertCompileMemberAlignment(HMCPU, HM_UNION_NM(u.) svm, 8);
1236AssertCompileMemberAlignment(HMCPU, Event, 8);
1237
1238#ifdef IN_RING0
1239VMMR0_INT_DECL(PHMPHYSCPU) hmR0GetCurrentCpu(void);
1240VMMR0_INT_DECL(int) hmR0EnterCpu(PVMCPU pVCpu);
1241
1242# ifdef VBOX_STRICT
1243VMMR0_INT_DECL(void) hmR0DumpRegs(PVMCPU pVCpu);
1244VMMR0_INT_DECL(void) hmR0DumpDescriptor(PCX86DESCHC pDesc, RTSEL Sel, const char *pszMsg);
1245# endif
1246
1247# ifdef VBOX_WITH_KERNEL_USING_XMM
1248DECLASM(int) hmR0VMXStartVMWrapXMM(RTHCUINT fResume, PCPUMCTX pCtx, PVMXVMCSCACHE pVmcsCache, PVM pVM,
1249 PVMCPU pVCpu, PFNHMVMXSTARTVM pfnStartVM);
1250DECLASM(int) hmR0SVMRunWrapXMM(RTHCPHYS pVmcbHostPhys, RTHCPHYS pVmcbPhys, PCPUMCTX pCtx, PVM pVM, PVMCPU pVCpu,
1251 PFNHMSVMVMRUN pfnVMRun);
1252# endif
1253DECLASM(void) hmR0MdsClear(void);
1254#endif /* IN_RING0 */
1255
1256VMM_INT_DECL(int) hmEmulateSvmMovTpr(PVMCPU pVCpu);
1257
1258VMM_INT_DECL(PVMXVMCSINFO) hmGetVmxActiveVmcsInfo(PVMCPU pVCpu);
1259
1260/** @} */
1261
1262RT_C_DECLS_END
1263
1264#endif /* !VMM_INCLUDED_SRC_include_HMInternal_h */
1265
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette