VirtualBox

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

Last change on this file since 79141 was 79123, checked in by vboxsync, 6 years ago

VMM/HM: Nested VMX: bugref:9180 Comment for upcoming changes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 50.8 KB
Line 
1/* $Id: HMInternal.h 79123 2019-06-13 10:43:33Z 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 without paging). */
531 bool fUnrestrictedGuest;
532 /** Set if unrestricted guest execution is allowed to be used. */
533 bool fAllowUnrestricted;
534 /** Set if the preemption timer is in use or not. */
535 bool fUsePreemptTimer;
536 /** The shift mask employed by the VMX-Preemption timer. */
537 uint8_t cPreemptTimerShift;
538
539 /** Virtual address of the TSS page used for real mode emulation. */
540 R3PTRTYPE(PVBOXTSS) pRealModeTSS;
541 /** Virtual address of the identity page table used for real mode and protected mode without paging emulation in EPT mode. */
542 R3PTRTYPE(PX86PD) pNonPagingModeEPTPageTable;
543
544 /** Physical address of the APIC-access page. */
545 RTHCPHYS HCPhysApicAccess;
546 /** R0 memory object for the APIC-access page. */
547 RTR0MEMOBJ hMemObjApicAccess;
548 /** Virtual address of the APIC-access page. */
549 R0PTRTYPE(uint8_t *) pbApicAccess;
550
551#ifdef VBOX_WITH_CRASHDUMP_MAGIC
552 RTHCPHYS HCPhysScratch;
553 RTR0MEMOBJ hMemObjScratch;
554 R0PTRTYPE(uint8_t *) pbScratch;
555#endif
556
557 /** Tagged-TLB flush type. */
558 VMXTLBFLUSHTYPE enmTlbFlushType;
559 /** Flush type to use for INVEPT. */
560 VMXTLBFLUSHEPT enmTlbFlushEpt;
561 /** Flush type to use for INVVPID. */
562 VMXTLBFLUSHVPID enmTlbFlushVpid;
563
564 /** Pause-loop exiting (PLE) gap in ticks. */
565 uint32_t cPleGapTicks;
566 /** Pause-loop exiting (PLE) window in ticks. */
567 uint32_t cPleWindowTicks;
568 uint32_t u32Alignment0;
569
570 /** Host CR4 value (set by ring-0 VMX init) */
571 uint64_t u64HostCr4;
572 /** Host SMM monitor control (set by ring-0 VMX init) */
573 uint64_t u64HostSmmMonitorCtl;
574 /** Host EFER value (set by ring-0 VMX init) */
575 uint64_t u64HostMsrEfer;
576 /** Whether the CPU supports VMCS fields for swapping EFER. */
577 bool fSupportsVmcsEfer;
578 uint8_t u8Alignment2[7];
579
580 /** VMX MSR values. */
581 VMXMSRS Msrs;
582
583 /** Host-physical address for a failing VMXON instruction. */
584 RTHCPHYS HCPhysVmxEnableError;
585 } vmx;
586
587 struct
588 {
589 /** Set by the ring-0 side of HM to indicate SVM is supported by the
590 * CPU. */
591 bool fSupported;
592 /** Set when we've enabled SVM. */
593 bool fEnabled;
594 /** Set if erratum 170 affects the AMD cpu. */
595 bool fAlwaysFlushTLB;
596 /** Set when the hack to ignore VERR_SVM_IN_USE is active. */
597 bool fIgnoreInUseError;
598 /** Whether to use virtualized VMSAVE/VMLOAD feature. */
599 bool fVirtVmsaveVmload;
600 /** Whether to use virtual GIF feature. */
601 bool fVGif;
602 uint8_t u8Alignment0[2];
603
604 /** Physical address of the IO bitmap (12kb). */
605 RTHCPHYS HCPhysIOBitmap;
606 /** R0 memory object for the IO bitmap (12kb). */
607 RTR0MEMOBJ hMemObjIOBitmap;
608 /** Virtual address of the IO bitmap. */
609 R0PTRTYPE(void *) pvIOBitmap;
610
611 /* HWCR MSR (for diagnostics) */
612 uint64_t u64MsrHwcr;
613
614 /** SVM revision. */
615 uint32_t u32Rev;
616 /** SVM feature bits from cpuid 0x8000000a */
617 uint32_t u32Features;
618
619 /** Pause filter counter. */
620 uint16_t cPauseFilter;
621 /** Pause filter treshold in ticks. */
622 uint16_t cPauseFilterThresholdTicks;
623 uint32_t u32Alignment0;
624 } svm;
625
626 /**
627 * AVL tree with all patches (active or disabled) sorted by guest instruction
628 * address.
629 */
630 AVLOU32TREE PatchTree;
631 uint32_t cPatches;
632 HMTPRPATCH aPatches[64];
633
634 /** Last recorded error code during HM ring-0 init. */
635 int32_t rcInit;
636
637 /** HMR0Init was run */
638 bool fHMR0Init;
639 bool u8Alignment1[3];
640
641 STAMCOUNTER StatTprPatchSuccess;
642 STAMCOUNTER StatTprPatchFailure;
643 STAMCOUNTER StatTprReplaceSuccessCr8;
644 STAMCOUNTER StatTprReplaceSuccessVmc;
645 STAMCOUNTER StatTprReplaceFailure;
646} HM;
647/** Pointer to HM VM instance data. */
648typedef HM *PHM;
649
650AssertCompileMemberAlignment(HM, StatTprPatchSuccess, 8);
651
652/* Maximum number of cached entries. */
653#define VMX_VMCS_CACHE_MAX_ENTRY 128
654
655/**
656 * Cache of a VMCS for batch reads or writes.
657 */
658typedef struct VMXVMCSCACHE
659{
660#ifdef VBOX_WITH_CRASHDUMP_MAGIC
661 /* Magic marker for searching in crash dumps. */
662 uint8_t aMagic[16];
663 uint64_t uMagic;
664 uint64_t u64TimeEntry;
665 uint64_t u64TimeSwitch;
666 uint64_t cResume;
667 uint64_t interPD;
668 uint64_t pSwitcher;
669 uint32_t uPos;
670 uint32_t idCpu;
671#endif
672 /* CR2 is saved here for EPT syncing. */
673 uint64_t cr2;
674 struct
675 {
676 uint32_t cValidEntries;
677 uint32_t uAlignment;
678 uint32_t aField[VMX_VMCS_CACHE_MAX_ENTRY];
679 uint64_t aFieldVal[VMX_VMCS_CACHE_MAX_ENTRY];
680 } Write;
681 struct
682 {
683 uint32_t cValidEntries;
684 uint32_t uAlignment;
685 uint32_t aField[VMX_VMCS_CACHE_MAX_ENTRY];
686 uint64_t aFieldVal[VMX_VMCS_CACHE_MAX_ENTRY];
687 } Read;
688#ifdef VBOX_STRICT
689 struct
690 {
691 RTHCPHYS HCPhysCpuPage;
692 RTHCPHYS HCPhysVmcs;
693 RTGCPTR pCache;
694 RTGCPTR pCtx;
695 } TestIn;
696 struct
697 {
698 RTHCPHYS HCPhysVmcs;
699 RTGCPTR pCache;
700 RTGCPTR pCtx;
701 uint64_t eflags;
702 uint64_t cr8;
703 } TestOut;
704 struct
705 {
706 uint64_t param1;
707 uint64_t param2;
708 uint64_t param3;
709 uint64_t param4;
710 } ScratchPad;
711#endif
712} VMXVMCSCACHE;
713/** Pointer to VMXVMCSCACHE. */
714typedef VMXVMCSCACHE *PVMXVMCSCACHE;
715AssertCompileSizeAlignment(VMXVMCSCACHE, 8);
716
717/**
718 * VMX StartVM function.
719 *
720 * @returns VBox status code (no informational stuff).
721 * @param fResume Whether to use VMRESUME (true) or VMLAUNCH (false).
722 * @param pCtx The CPU register context.
723 * @param pVmcsCache The VMCS batch cache.
724 * @param pVM Pointer to the cross context VM structure.
725 * @param pVCpu Pointer to the cross context per-CPU structure.
726 */
727typedef DECLCALLBACK(int) FNHMVMXSTARTVM(RTHCUINT fResume, PCPUMCTX pCtx, PVMXVMCSCACHE pVmcsCache, PVM pVM, PVMCPU pVCpu);
728/** Pointer to a VMX StartVM function. */
729typedef R0PTRTYPE(FNHMVMXSTARTVM *) PFNHMVMXSTARTVM;
730
731/** SVM VMRun function. */
732typedef DECLCALLBACK(int) FNHMSVMVMRUN(RTHCPHYS pVmcbHostPhys, RTHCPHYS pVmcbPhys, PCPUMCTX pCtx, PVM pVM, PVMCPU pVCpu);
733/** Pointer to a SVM VMRun function. */
734typedef R0PTRTYPE(FNHMSVMVMRUN *) PFNHMSVMVMRUN;
735
736/**
737 * VMX VMCS information.
738 *
739 * This structure provides information maintained for and during the executing of a
740 * guest (or nested-guest) VMCS (VM control structure) using hardware-assisted VMX.
741 */
742typedef struct VMXVMCSINFO
743{
744 /** @name VMLAUNCH/VMRESUME information.
745 * @{ */
746 /** Ring-0 pointer to the hardware-assisted VMX execution function. */
747 PFNHMVMXSTARTVM pfnStartVM;
748#if HC_ARCH_BITS == 32
749 uint32_t u32Alignment0;
750#endif
751 /** @} */
752
753 /** @name VMCS and related data structures.
754 * @{ */
755 /** Host-physical address of the VMCS. */
756 RTHCPHYS HCPhysVmcs;
757 /** R0 memory object for the VMCS. */
758 RTR0MEMOBJ hMemObjVmcs;
759 /** Host-virtual address of the VMCS. */
760 R0PTRTYPE(void *) pvVmcs;
761
762 /** Host-physical address of the virtual APIC page. */
763 RTHCPHYS HCPhysVirtApic;
764 /** Alignment. */
765 R0PTRTYPE(void *) pvAlignment0;
766 /** Host-virtual address of the virtual-APIC page. */
767 R0PTRTYPE(uint8_t *) pbVirtApic;
768
769 /** Host-physical address of the MSR bitmap. */
770 RTHCPHYS HCPhysMsrBitmap;
771 /** R0 memory object for the MSR bitmap. */
772 RTR0MEMOBJ hMemObjMsrBitmap;
773 /** Host-virtual address of the MSR bitmap. */
774 R0PTRTYPE(void *) pvMsrBitmap;
775
776 /** Host-physical address of the VM-entry MSR-load area. */
777 RTHCPHYS HCPhysGuestMsrLoad;
778 /** R0 memory object of the VM-entry MSR-load area. */
779 RTR0MEMOBJ hMemObjGuestMsrLoad;
780 /** Host-virtual address of the VM-entry MSR-load area. */
781 R0PTRTYPE(void *) pvGuestMsrLoad;
782
783 /** Host-physical address of the VM-exit MSR-store area. */
784 RTHCPHYS HCPhysGuestMsrStore;
785 /** R0 memory object of the VM-exit MSR-store area. */
786 RTR0MEMOBJ hMemObjGuestMsrStore;
787 /** Host-virtual address of the VM-exit MSR-store area. */
788 R0PTRTYPE(void *) pvGuestMsrStore;
789
790 /** Host-physical address of the VM-exit MSR-load area. */
791 RTHCPHYS HCPhysHostMsrLoad;
792 /** R0 memory object for the VM-exit MSR-load area. */
793 RTR0MEMOBJ hMemObjHostMsrLoad;
794 /** Host-virtual address of the VM-exit MSR-load area. */
795 R0PTRTYPE(void *) pvHostMsrLoad;
796
797 /** Host-physical address of the EPTP. */
798 RTHCPHYS HCPhysEPTP;
799 /** Number of guest MSRs in the VM-entry MSR-load area. */
800 uint32_t cEntryMsrLoad;
801 /** Number of guest MSRs in the VM-exit MSR-store area. */
802 uint32_t cExitMsrStore;
803 /** Number of host MSRs in the VM-exit MSR-load area. */
804 uint32_t cExitMsrLoad;
805 /** Padding. */
806 uint32_t u32Padding0;
807 /** @} */
808
809 /** @name Auxiliary information.
810 * @{ */
811 /** The VMCS launch state, see VMX_V_VMCS_LAUNCH_STATE_XXX. */
812 uint32_t fVmcsState;
813 /** Set if guest was executing in real mode (extra checks). */
814 bool fWasInRealMode;
815 /** Set if the guest switched to 64-bit mode on a 32-bit host. */
816 bool fSwitchedTo64on32;
817 /** Padding. */
818 bool afPadding0[2];
819 /** @} */
820
821 /** @name Cache of execution related VMCS fields.
822 * @{ */
823 /** Pin-based VM-execution controls. */
824 uint32_t u32PinCtls;
825 /** Processor-based VM-execution controls. */
826 uint32_t u32ProcCtls;
827 /** Secondary processor-based VM-execution controls. */
828 uint32_t u32ProcCtls2;
829 /** VM-entry controls. */
830 uint32_t u32EntryCtls;
831 /** VM-exit controls. */
832 uint32_t u32ExitCtls;
833 /** Exception bitmap. */
834 uint32_t u32XcptBitmap;
835 /** CR0 guest/host mask. */
836 uint64_t u64Cr0Mask;
837 /** CR4 guest/host mask. */
838 uint64_t u64Cr4Mask;
839 /** Page-fault exception error-code mask. */
840 uint32_t u32XcptPFMask;
841 /** Page-fault exception error-code match. */
842 uint32_t u32XcptPFMatch;
843 /** TSC offset. */
844 uint64_t u64TscOffset;
845 /** VMCS link pointer. */
846 uint64_t u64VmcsLinkPtr;
847 /** @} */
848
849 /** @name Real-mode emulation state.
850 * @{ */
851 struct
852 {
853 X86DESCATTR AttrCS;
854 X86DESCATTR AttrDS;
855 X86DESCATTR AttrES;
856 X86DESCATTR AttrFS;
857 X86DESCATTR AttrGS;
858 X86DESCATTR AttrSS;
859 X86EFLAGS Eflags;
860 bool fRealOnV86Active;
861 bool afPadding1[3];
862 } RealMode;
863 /** @} */
864
865 /** Padding. */
866 uint64_t au64Padding[2];
867} VMXVMCSINFO;
868/** Pointer to a VMXVMCSINFO struct. */
869typedef VMXVMCSINFO *PVMXVMCSINFO;
870/** Pointer to a const VMXVMCSINFO struct. */
871typedef const VMXVMCSINFO *PCVMXVMCSINFO;
872AssertCompileSizeAlignment(VMXVMCSINFO, 8);
873AssertCompileMemberAlignment(VMXVMCSINFO, fVmcsState, 8);
874AssertCompileMemberAlignment(VMXVMCSINFO, u32PinCtls, 8);
875AssertCompileMemberAlignment(VMXVMCSINFO, u64VmcsLinkPtr, 8);
876
877/**
878 * HM VMCPU Instance data.
879 *
880 * Note! If you change members of this struct, make sure to check if the
881 * assembly counterpart in HMInternal.mac needs to be updated as well.
882 */
883typedef struct HMCPU
884{
885 /** Set when the TLB has been checked until we return from the world switch. */
886 bool volatile fCheckedTLBFlush;
887 /** Set if we need to flush the TLB during the world switch. */
888 bool fForceTLBFlush;
889 /** Set when we're using VT-x or AMD-V at that moment. */
890 bool fActive;
891 /** Whether we've completed the inner HM leave function. */
892 bool fLeaveDone;
893 /** Whether we're using the hyper DR7 or guest DR7. */
894 bool fUsingHyperDR7;
895 /** Set if XCR0 needs to be saved/restored when entering/exiting guest code
896 * execution. */
897 bool fLoadSaveGuestXcr0;
898
899 /** Whether we should use the debug loop because of single stepping or special
900 * debug breakpoints / events are armed. */
901 bool fUseDebugLoop;
902 /** Whether we are currently executing in the debug loop.
903 * Mainly for assertions. */
904 bool fUsingDebugLoop;
905 /** Set if we using the debug loop and wish to intercept RDTSC. */
906 bool fDebugWantRdTscExit;
907 /** Whether we're executing a single instruction. */
908 bool fSingleInstruction;
909 /** Set if we need to clear the trap flag because of single stepping. */
910 bool fClearTrapFlag;
911
912 /** Whether \#UD needs to be intercepted (required by certain GIM providers). */
913 bool fGIMTrapXcptUD;
914 /** Whether \#GP needs to be intercept for mesa driver workaround. */
915 bool fTrapXcptGpForLovelyMesaDrv;
916 uint8_t u8Alignment0[3];
917
918 /** World switch exit counter. */
919 uint32_t volatile cWorldSwitchExits;
920 /** The last CPU we were executing code on (NIL_RTCPUID for the first time). */
921 RTCPUID idLastCpu;
922 /** TLB flush count. */
923 uint32_t cTlbFlushes;
924 /** Current ASID in use by the VM. */
925 uint32_t uCurrentAsid;
926 /** An additional error code used for some gurus. */
927 uint32_t u32HMError;
928 /** The last exit-to-ring-3 reason. */
929 int32_t rcLastExitToR3;
930 /** CPU-context changed flags (see HM_CHANGED_xxx). */
931 uint64_t fCtxChanged;
932 /** Host's TSC_AUX MSR (used when RDTSCP doesn't cause VM-exits). */
933 uint64_t u64HostTscAux; /** @todo r=ramshankar: Can be removed and put in SVMTRANSIENT instead! */
934
935 union /* no tag! */
936 {
937 /** VT-x data. */
938 struct
939 {
940 /** @name Guest information.
941 * @{ */
942 /** Guest VMCS information. */
943 VMXVMCSINFO VmcsInfo;
944 /** Nested-guest VMCS information. */
945 VMXVMCSINFO VmcsInfoNstGst;
946 /** Whether the nested-guest VMCS was the last current VMCS. */
947 bool fSwitchedToNstGstVmcs;
948 /** Whether the static guest VMCS controls has been merged with the
949 * nested-guest VMCS controls. */
950 bool fMergedNstGstCtls;
951 /** Alignment. */
952 bool afAlignment0[6];
953 /** Cached guest APIC-base MSR for identifying when to map the APIC-access page. */
954 uint64_t u64GstMsrApicBase;
955 /** VMCS cache for batched vmread/vmwrites. */
956 VMXVMCSCACHE VmcsCache;
957 /** @} */
958
959 /** @name Host information.
960 * @{ */
961 /** Host LSTAR MSR to restore lazily while leaving VT-x. */
962 uint64_t u64HostMsrLStar;
963 /** Host STAR MSR to restore lazily while leaving VT-x. */
964 uint64_t u64HostMsrStar;
965 /** Host SF_MASK MSR to restore lazily while leaving VT-x. */
966 uint64_t u64HostMsrSfMask;
967 /** Host KernelGS-Base MSR to restore lazily while leaving VT-x. */
968 uint64_t u64HostMsrKernelGsBase;
969 /** The mask of lazy MSRs swap/restore state, see VMX_LAZY_MSRS_XXX. */
970 uint32_t fLazyMsrs;
971 /** Whether the host MSR values are up-to-date in the auto-load/store MSR area. */
972 bool fUpdatedHostAutoMsrs;
973 /** Alignment. */
974 uint8_t au8Alignment0[3];
975 /** Which host-state bits to restore before being preempted. */
976 uint32_t fRestoreHostFlags;
977 /** Alignment. */
978 uint32_t u32Alignment0;
979 /** The host-state restoration structure. */
980 VMXRESTOREHOST RestoreHost;
981 /** @} */
982
983 /** @name Error reporting and diagnostics.
984 * @{ */
985 /** VT-x error-reporting (mainly for ring-3 propagation). */
986 struct
987 {
988 RTHCPHYS HCPhysCurrentVmcs;
989 uint32_t u32VmcsRev;
990 uint32_t u32InstrError;
991 uint32_t u32ExitReason;
992 uint32_t u32Alignment0;
993 RTCPUID idEnteredCpu;
994 RTCPUID idCurrentCpu;
995 } LastError;
996 /** @} */
997 } vmx;
998
999 /** SVM data. */
1000 struct
1001 {
1002 /** Ring 0 handlers for VT-x. */
1003 PFNHMSVMVMRUN pfnVMRun;
1004#if HC_ARCH_BITS == 32
1005 uint32_t u32Alignment0;
1006#endif
1007
1008 /** Physical address of the host VMCB which holds additional host-state. */
1009 RTHCPHYS HCPhysVmcbHost;
1010 /** R0 memory object for the host VMCB which holds additional host-state. */
1011 RTR0MEMOBJ hMemObjVmcbHost;
1012 /** Padding. */
1013 R0PTRTYPE(void *) pvPadding;
1014
1015 /** Physical address of the guest VMCB. */
1016 RTHCPHYS HCPhysVmcb;
1017 /** R0 memory object for the guest VMCB. */
1018 RTR0MEMOBJ hMemObjVmcb;
1019 /** Pointer to the guest VMCB. */
1020 R0PTRTYPE(PSVMVMCB) pVmcb;
1021
1022 /** Physical address of the MSR bitmap (8 KB). */
1023 RTHCPHYS HCPhysMsrBitmap;
1024 /** R0 memory object for the MSR bitmap (8 KB). */
1025 RTR0MEMOBJ hMemObjMsrBitmap;
1026 /** Pointer to the MSR bitmap. */
1027 R0PTRTYPE(void *) pvMsrBitmap;
1028
1029 /** Whether VTPR with V_INTR_MASKING set is in effect, indicating
1030 * we should check if the VTPR changed on every VM-exit. */
1031 bool fSyncVTpr;
1032 uint8_t au8Alignment0[7];
1033
1034 /** Cache of the nested-guest's VMCB fields that we modify in order to run the
1035 * nested-guest using AMD-V. This will be restored on \#VMEXIT. */
1036 SVMNESTEDVMCBCACHE NstGstVmcbCache;
1037 } svm;
1038 } HM_UNION_NM(u);
1039
1040 /** Event injection state. */
1041 HMEVENT Event;
1042
1043 /** The PAE PDPEs used with Nested Paging (only valid when
1044 * VMCPU_FF_HM_UPDATE_PAE_PDPES is set). */
1045 X86PDPE aPdpes[4];
1046
1047 /** Current shadow paging mode for updating CR4. */
1048 PGMMODE enmShadowMode;
1049
1050 /** The CPU ID of the CPU currently owning the VMCS. Set in
1051 * HMR0Enter and cleared in HMR0Leave. */
1052 RTCPUID idEnteredCpu;
1053
1054 /** For saving stack space, the disassembler state is allocated here instead of
1055 * on the stack. */
1056 DISCPUSTATE DisState;
1057
1058 STAMPROFILEADV StatEntry;
1059 STAMPROFILEADV StatPreExit;
1060 STAMPROFILEADV StatExitHandling;
1061 STAMPROFILEADV StatExitIO;
1062 STAMPROFILEADV StatExitMovCRx;
1063 STAMPROFILEADV StatExitXcptNmi;
1064 STAMPROFILEADV StatImportGuestState;
1065 STAMPROFILEADV StatExportGuestState;
1066 STAMPROFILEADV StatLoadGuestFpuState;
1067 STAMPROFILEADV StatInGC;
1068#if HC_ARCH_BITS == 32 && defined(VBOX_ENABLE_64_BITS_GUESTS)
1069 STAMPROFILEADV StatWorldSwitch3264;
1070#endif
1071 STAMPROFILEADV StatPoke;
1072 STAMPROFILEADV StatSpinPoke;
1073 STAMPROFILEADV StatSpinPokeFailed;
1074
1075 STAMCOUNTER StatInjectInterrupt;
1076 STAMCOUNTER StatInjectXcpt;
1077 STAMCOUNTER StatInjectPendingReflect;
1078 STAMCOUNTER StatInjectPendingInterpret;
1079
1080 STAMCOUNTER StatExitAll;
1081 STAMCOUNTER StatExitShadowNM;
1082 STAMCOUNTER StatExitGuestNM;
1083 STAMCOUNTER StatExitShadowPF; /**< Misleading, currently used for MMIO \#PFs as well. */
1084 STAMCOUNTER StatExitShadowPFEM;
1085 STAMCOUNTER StatExitGuestPF;
1086 STAMCOUNTER StatExitGuestUD;
1087 STAMCOUNTER StatExitGuestSS;
1088 STAMCOUNTER StatExitGuestNP;
1089 STAMCOUNTER StatExitGuestTS;
1090 STAMCOUNTER StatExitGuestGP;
1091 STAMCOUNTER StatExitGuestDE;
1092 STAMCOUNTER StatExitGuestDB;
1093 STAMCOUNTER StatExitGuestMF;
1094 STAMCOUNTER StatExitGuestBP;
1095 STAMCOUNTER StatExitGuestXF;
1096 STAMCOUNTER StatExitGuestXcpUnk;
1097 STAMCOUNTER StatExitDRxWrite;
1098 STAMCOUNTER StatExitDRxRead;
1099 STAMCOUNTER StatExitCR0Read;
1100 STAMCOUNTER StatExitCR2Read;
1101 STAMCOUNTER StatExitCR3Read;
1102 STAMCOUNTER StatExitCR4Read;
1103 STAMCOUNTER StatExitCR8Read;
1104 STAMCOUNTER StatExitCR0Write;
1105 STAMCOUNTER StatExitCR2Write;
1106 STAMCOUNTER StatExitCR3Write;
1107 STAMCOUNTER StatExitCR4Write;
1108 STAMCOUNTER StatExitCR8Write;
1109 STAMCOUNTER StatExitRdmsr;
1110 STAMCOUNTER StatExitWrmsr;
1111 STAMCOUNTER StatExitClts;
1112 STAMCOUNTER StatExitXdtrAccess;
1113 STAMCOUNTER StatExitLmsw;
1114 STAMCOUNTER StatExitIOWrite;
1115 STAMCOUNTER StatExitIORead;
1116 STAMCOUNTER StatExitIOStringWrite;
1117 STAMCOUNTER StatExitIOStringRead;
1118 STAMCOUNTER StatExitIntWindow;
1119 STAMCOUNTER StatExitExtInt;
1120 STAMCOUNTER StatExitHostNmiInGC;
1121 STAMCOUNTER StatExitPreemptTimer;
1122 STAMCOUNTER StatExitTprBelowThreshold;
1123 STAMCOUNTER StatExitTaskSwitch;
1124 STAMCOUNTER StatExitApicAccess;
1125 STAMCOUNTER StatExitReasonNpf;
1126
1127 STAMCOUNTER StatNestedExitReasonNpf;
1128
1129 STAMCOUNTER StatFlushPage;
1130 STAMCOUNTER StatFlushPageManual;
1131 STAMCOUNTER StatFlushPhysPageManual;
1132 STAMCOUNTER StatFlushTlb;
1133 STAMCOUNTER StatFlushTlbManual;
1134 STAMCOUNTER StatFlushTlbWorldSwitch;
1135 STAMCOUNTER StatNoFlushTlbWorldSwitch;
1136 STAMCOUNTER StatFlushEntire;
1137 STAMCOUNTER StatFlushAsid;
1138 STAMCOUNTER StatFlushNestedPaging;
1139 STAMCOUNTER StatFlushTlbInvlpgVirt;
1140 STAMCOUNTER StatFlushTlbInvlpgPhys;
1141 STAMCOUNTER StatTlbShootdown;
1142 STAMCOUNTER StatTlbShootdownFlush;
1143
1144 STAMCOUNTER StatSwitchPendingHostIrq;
1145 STAMCOUNTER StatSwitchTprMaskedIrq;
1146 STAMCOUNTER StatSwitchGuestIrq;
1147 STAMCOUNTER StatSwitchHmToR3FF;
1148 STAMCOUNTER StatSwitchExitToR3;
1149 STAMCOUNTER StatSwitchLongJmpToR3;
1150 STAMCOUNTER StatSwitchMaxResumeLoops;
1151 STAMCOUNTER StatSwitchHltToR3;
1152 STAMCOUNTER StatSwitchApicAccessToR3;
1153 STAMCOUNTER StatSwitchPreempt;
1154 STAMCOUNTER StatSwitchPreemptExportHostState;
1155
1156 STAMCOUNTER StatTscParavirt;
1157 STAMCOUNTER StatTscOffset;
1158 STAMCOUNTER StatTscIntercept;
1159
1160 STAMCOUNTER StatDRxArmed;
1161 STAMCOUNTER StatDRxContextSwitch;
1162 STAMCOUNTER StatDRxIoCheck;
1163
1164 STAMCOUNTER StatExportMinimal;
1165 STAMCOUNTER StatExportFull;
1166 STAMCOUNTER StatLoadGuestFpu;
1167
1168 STAMCOUNTER StatVmxCheckBadRmSelBase;
1169 STAMCOUNTER StatVmxCheckBadRmSelLimit;
1170 STAMCOUNTER StatVmxCheckBadRmSelAttr;
1171 STAMCOUNTER StatVmxCheckBadV86SelBase;
1172 STAMCOUNTER StatVmxCheckBadV86SelLimit;
1173 STAMCOUNTER StatVmxCheckBadV86SelAttr;
1174 STAMCOUNTER StatVmxCheckRmOk;
1175 STAMCOUNTER StatVmxCheckBadSel;
1176 STAMCOUNTER StatVmxCheckBadRpl;
1177 STAMCOUNTER StatVmxCheckPmOk;
1178
1179#if HC_ARCH_BITS == 32 && defined(VBOX_ENABLE_64_BITS_GUESTS)
1180 STAMCOUNTER StatFpu64SwitchBack;
1181 STAMCOUNTER StatDebug64SwitchBack;
1182#endif
1183#ifdef VBOX_WITH_STATISTICS
1184 R3PTRTYPE(PSTAMCOUNTER) paStatExitReason;
1185 R0PTRTYPE(PSTAMCOUNTER) paStatExitReasonR0;
1186 R3PTRTYPE(PSTAMCOUNTER) paStatInjectedIrqs;
1187 R0PTRTYPE(PSTAMCOUNTER) paStatInjectedIrqsR0;
1188 R3PTRTYPE(PSTAMCOUNTER) paStatNestedExitReason;
1189 R0PTRTYPE(PSTAMCOUNTER) paStatNestedExitReasonR0;
1190#endif
1191#ifdef HM_PROFILE_EXIT_DISPATCH
1192 STAMPROFILEADV StatExitDispatch;
1193#endif
1194} HMCPU;
1195/** Pointer to HM VMCPU instance data. */
1196typedef HMCPU *PHMCPU;
1197AssertCompileMemberAlignment(HMCPU, cWorldSwitchExits, 4);
1198AssertCompileMemberAlignment(HMCPU, fCtxChanged, 8);
1199AssertCompileMemberAlignment(HMCPU, HM_UNION_NM(u.) vmx, 8);
1200AssertCompileMemberAlignment(HMCPU, HM_UNION_NM(u.) svm, 8);
1201AssertCompileMemberAlignment(HMCPU, Event, 8);
1202
1203#ifdef IN_RING0
1204VMMR0_INT_DECL(PHMPHYSCPU) hmR0GetCurrentCpu(void);
1205VMMR0_INT_DECL(int) hmR0EnterCpu(PVMCPU pVCpu);
1206
1207# ifdef VBOX_STRICT
1208VMMR0_INT_DECL(void) hmR0DumpRegs(PVMCPU pVCpu);
1209VMMR0_INT_DECL(void) hmR0DumpDescriptor(PCX86DESCHC pDesc, RTSEL Sel, const char *pszMsg);
1210# endif
1211
1212# ifdef VBOX_WITH_KERNEL_USING_XMM
1213DECLASM(int) hmR0VMXStartVMWrapXMM(RTHCUINT fResume, PCPUMCTX pCtx, PVMXVMCSCACHE pVmcsCache, PVM pVM,
1214 PVMCPU pVCpu, PFNHMVMXSTARTVM pfnStartVM);
1215DECLASM(int) hmR0SVMRunWrapXMM(RTHCPHYS pVmcbHostPhys, RTHCPHYS pVmcbPhys, PCPUMCTX pCtx, PVM pVM, PVMCPU pVCpu,
1216 PFNHMSVMVMRUN pfnVMRun);
1217# endif
1218DECLASM(void) hmR0MdsClear(void);
1219#endif /* IN_RING0 */
1220
1221VMM_INT_DECL(int) hmEmulateSvmMovTpr(PVMCPU pVCpu);
1222
1223VMM_INT_DECL(PVMXVMCSINFO) hmGetVmxActiveVmcsInfo(PVMCPU pVCpu);
1224
1225/** @} */
1226
1227RT_C_DECLS_END
1228
1229#endif /* !VMM_INCLUDED_SRC_include_HMInternal_h */
1230
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