VirtualBox

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

Last change on this file since 72466 was 72462, checked in by vboxsync, 7 years ago

EM,IEM,HM: Consolidated VMMHypercallsDisable/VMMHypercallsEnable into EMSetHypercallInstructionsEnabled and made the information available thru EMAreHypercallInstructionsEnabled(). Adjusted the vmmcall implementation so it works without HM. bugref:9044

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 45.7 KB
Line 
1/* $Id: HMInternal.h 72462 2018-06-06 14:24:04Z vboxsync $ */
2/** @file
3 * HM - Internal header file.
4 */
5
6/*
7 * Copyright (C) 2006-2017 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 ___HMInternal_h
19#define ___HMInternal_h
20
21#include <VBox/cdefs.h>
22#include <VBox/types.h>
23#include <VBox/vmm/em.h>
24#include <VBox/vmm/stam.h>
25#include <VBox/dis.h>
26#include <VBox/vmm/hm.h>
27#include <VBox/vmm/hm_vmx.h>
28#include <VBox/vmm/hm_svm.h>
29#include <VBox/vmm/pgm.h>
30#include <VBox/vmm/cpum.h>
31#include <VBox/vmm/trpm.h>
32#include <iprt/memobj.h>
33#include <iprt/cpuset.h>
34#include <iprt/mp.h>
35#include <iprt/avl.h>
36#include <iprt/string.h>
37
38#if defined(RT_OS_DARWIN) && HC_ARCH_BITS == 32
39# error "32-bit darwin is no longer supported. Go back to 4.3 or earlier!"
40#endif
41
42#if HC_ARCH_BITS == 64 || defined(VBOX_WITH_64_BITS_GUESTS)
43/* Enable 64 bits guest support. */
44# define VBOX_ENABLE_64_BITS_GUESTS
45#endif
46
47#if HC_ARCH_BITS == 32 && defined(VBOX_ENABLE_64_BITS_GUESTS)
48# define VMX_USE_CACHED_VMCS_ACCESSES
49#endif
50
51/** @def HM_PROFILE_EXIT_DISPATCH
52 * Enables profiling of the VM exit handler dispatching. */
53#if 0 || defined(DOXYGEN_RUNNING)
54# define HM_PROFILE_EXIT_DISPATCH
55#endif
56
57RT_C_DECLS_BEGIN
58
59
60/** @defgroup grp_hm_int Internal
61 * @ingroup grp_hm
62 * @internal
63 * @{
64 */
65
66/** @def HMCPU_CF_CLEAR
67 * Clears a HM-context flag.
68 *
69 * @param pVCpu The cross context virtual CPU structure.
70 * @param fFlag The flag to clear.
71 */
72#define HMCPU_CF_CLEAR(pVCpu, fFlag) (ASMAtomicUoAndU32(&(pVCpu)->hm.s.fContextUseFlags, ~(fFlag)))
73
74/** @def HMCPU_CF_SET
75 * Sets a HM-context flag.
76 *
77 * @param pVCpu The cross context virtual CPU structure.
78 * @param fFlag The flag to set.
79 */
80#define HMCPU_CF_SET(pVCpu, fFlag) (ASMAtomicUoOrU32(&(pVCpu)->hm.s.fContextUseFlags, (fFlag)))
81
82/** @def HMCPU_CF_IS_SET
83 * Checks if all the flags in the specified HM-context set is pending.
84 *
85 * @param pVCpu The cross context virtual CPU structure.
86 * @param fFlag The flag to check.
87 */
88#define HMCPU_CF_IS_SET(pVCpu, fFlag) ((ASMAtomicUoReadU32(&(pVCpu)->hm.s.fContextUseFlags) & (fFlag)) == (fFlag))
89
90/** @def HMCPU_CF_IS_PENDING
91 * Checks if one or more of the flags in the specified HM-context set is
92 * pending.
93 *
94 * @param pVCpu The cross context virtual CPU structure.
95 * @param fFlags The flags to check for.
96 */
97#define HMCPU_CF_IS_PENDING(pVCpu, fFlags) RT_BOOL(ASMAtomicUoReadU32(&(pVCpu)->hm.s.fContextUseFlags) & (fFlags))
98
99/** @def HMCPU_CF_IS_PENDING_ONLY
100 * Checks if -only- one or more of the specified HM-context flags is pending.
101 *
102 * @param pVCpu The cross context virtual CPU structure.
103 * @param fFlags The flags to check for.
104 */
105#define HMCPU_CF_IS_PENDING_ONLY(pVCpu, fFlags) !RT_BOOL(ASMAtomicUoReadU32(&(pVCpu)->hm.s.fContextUseFlags) & ~(fFlags))
106
107/** @def HMCPU_CF_IS_SET_ONLY
108 * Checks if -only- all the flags in the specified HM-context set is pending.
109 *
110 * @param pVCpu The cross context virtual CPU structure.
111 * @param fFlags The flags to check for.
112 */
113#define HMCPU_CF_IS_SET_ONLY(pVCpu, fFlags) (ASMAtomicUoReadU32(&(pVCpu)->hm.s.fContextUseFlags) == (fFlags))
114
115/** @def HMCPU_CF_RESET_TO
116 * Resets the HM-context flags to the specified value.
117 *
118 * @param pVCpu The cross context virtual CPU structure.
119 * @param fFlags The new value.
120 */
121#define HMCPU_CF_RESET_TO(pVCpu, fFlags) (ASMAtomicUoWriteU32(&(pVCpu)->hm.s.fContextUseFlags, (fFlags)))
122
123/** @def HMCPU_CF_VALUE
124 * Returns the current HM-context flags value.
125 *
126 * @param pVCpu The cross context virtual CPU structure.
127 */
128#define HMCPU_CF_VALUE(pVCpu) (ASMAtomicUoReadU32(&(pVCpu)->hm.s.fContextUseFlags))
129
130
131/** Resets/initializes the VM-exit/\#VMEXIT history array. */
132#define HMCPU_EXIT_HISTORY_RESET(pVCpu) (memset(&(pVCpu)->hm.s.auExitHistory, 0xff, sizeof((pVCpu)->hm.s.auExitHistory)))
133
134/** Updates the VM-exit/\#VMEXIT history array. */
135#define HMCPU_EXIT_HISTORY_ADD(pVCpu, a_ExitReason) \
136 do { \
137 AssertMsg((pVCpu)->hm.s.idxExitHistoryFree < RT_ELEMENTS((pVCpu)->hm.s.auExitHistory), ("%u\n", (pVCpu)->hm.s.idxExitHistoryFree)); \
138 (pVCpu)->hm.s.auExitHistory[(pVCpu)->hm.s.idxExitHistoryFree++] = (uint16_t)(a_ExitReason); \
139 if ((pVCpu)->hm.s.idxExitHistoryFree == RT_ELEMENTS((pVCpu)->hm.s.auExitHistory)) \
140 (pVCpu)->hm.s.idxExitHistoryFree = 0; \
141 (pVCpu)->hm.s.auExitHistory[(pVCpu)->hm.s.idxExitHistoryFree] = UINT16_MAX; \
142 } while (0)
143
144/** Maximum number of exit reason statistics counters. */
145#define MAX_EXITREASON_STAT 0x100
146#define MASK_EXITREASON_STAT 0xff
147#define MASK_INJECT_IRQ_STAT 0xff
148
149/** @name HM changed flags.
150 * These flags are used to keep track of which important registers that have
151 * been changed since last they were reset.
152 *
153 * Flags marked "shared" are used for registers that are common to both the host
154 * and guest (i.e. without dedicated VMCS/VMCB fields for guest bits).
155 *
156 * @{
157 */
158#define HM_CHANGED_GUEST_CR0 RT_BIT(0) /* Shared */
159#define HM_CHANGED_GUEST_CR3 RT_BIT(1)
160#define HM_CHANGED_GUEST_CR4 RT_BIT(2)
161#define HM_CHANGED_GUEST_GDTR RT_BIT(3)
162#define HM_CHANGED_GUEST_IDTR RT_BIT(4)
163#define HM_CHANGED_GUEST_LDTR RT_BIT(5)
164#define HM_CHANGED_GUEST_TR RT_BIT(6)
165#define HM_CHANGED_GUEST_SEGMENT_REGS RT_BIT(7)
166#define HM_CHANGED_GUEST_DEBUG RT_BIT(8) /* Shared */
167#define HM_CHANGED_GUEST_RIP RT_BIT(9)
168#define HM_CHANGED_GUEST_RSP RT_BIT(10)
169#define HM_CHANGED_GUEST_RFLAGS RT_BIT(11)
170#define HM_CHANGED_GUEST_CR2 RT_BIT(12)
171#define HM_CHANGED_GUEST_SYSENTER_CS_MSR RT_BIT(13)
172#define HM_CHANGED_GUEST_SYSENTER_EIP_MSR RT_BIT(14)
173#define HM_CHANGED_GUEST_SYSENTER_ESP_MSR RT_BIT(15)
174#define HM_CHANGED_GUEST_EFER_MSR RT_BIT(16)
175#define HM_CHANGED_GUEST_APIC_STATE RT_BIT(17)
176#define HM_CHANGED_GUEST_HWVIRT RT_BIT(18)
177/* Logically common VMM state. */
178#define HM_CHANGED_VMM_GUEST_XCPT_INTERCEPTS RT_BIT(19)
179#define HM_CHANGED_VMM_GUEST_LAZY_MSRS RT_BIT(20)
180/* VT-x specific state. */
181#define HM_CHANGED_VMX_GUEST_AUTO_MSRS RT_BIT(21)
182#define HM_CHANGED_VMX_GUEST_ACTIVITY_STATE RT_BIT(22)
183#define HM_CHANGED_VMX_ENTRY_CTLS RT_BIT(23)
184#define HM_CHANGED_VMX_EXIT_CTLS RT_BIT(24)
185/* AMD-V specific state. */
186#define HM_CHANGED_SVM_RESERVED1 RT_BIT(21)
187#define HM_CHANGED_SVM_RESERVED2 RT_BIT(22)
188#define HM_CHANGED_SVM_RESERVED3 RT_BIT(23)
189#define HM_CHANGED_SVM_RESERVED4 RT_BIT(24)
190
191#define HM_CHANGED_ALL_GUEST ( HM_CHANGED_GUEST_CR0 \
192 | HM_CHANGED_GUEST_CR3 \
193 | HM_CHANGED_GUEST_CR4 \
194 | HM_CHANGED_GUEST_GDTR \
195 | HM_CHANGED_GUEST_IDTR \
196 | HM_CHANGED_GUEST_LDTR \
197 | HM_CHANGED_GUEST_TR \
198 | HM_CHANGED_GUEST_SEGMENT_REGS \
199 | HM_CHANGED_GUEST_DEBUG \
200 | HM_CHANGED_GUEST_RIP \
201 | HM_CHANGED_GUEST_RSP \
202 | HM_CHANGED_GUEST_RFLAGS \
203 | HM_CHANGED_GUEST_CR2 \
204 | HM_CHANGED_GUEST_SYSENTER_CS_MSR \
205 | HM_CHANGED_GUEST_SYSENTER_EIP_MSR \
206 | HM_CHANGED_GUEST_SYSENTER_ESP_MSR \
207 | HM_CHANGED_GUEST_EFER_MSR \
208 | HM_CHANGED_GUEST_APIC_STATE \
209 | HM_CHANGED_GUEST_HWVIRT \
210 | HM_CHANGED_VMM_GUEST_XCPT_INTERCEPTS \
211 | HM_CHANGED_VMM_GUEST_LAZY_MSRS \
212 | HM_CHANGED_VMX_GUEST_AUTO_MSRS \
213 | HM_CHANGED_VMX_GUEST_ACTIVITY_STATE \
214 | HM_CHANGED_VMX_ENTRY_CTLS \
215 | HM_CHANGED_VMX_EXIT_CTLS)
216
217#define HM_CHANGED_HOST_CONTEXT RT_BIT(25)
218
219/* Bits shared between host and guest. */
220#define HM_CHANGED_HOST_GUEST_SHARED_STATE ( HM_CHANGED_GUEST_CR0 \
221 | HM_CHANGED_GUEST_DEBUG \
222 | HM_CHANGED_VMM_GUEST_LAZY_MSRS)
223/** @} */
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() \
239 RTTHREADPREEMPTSTATE PreemptStateInternal = RTTHREADPREEMPTSTATE_INITIALIZER; \
240 Assert(!RTThreadPreemptIsEnabled(NIL_RTTHREAD) || VMMR0ThreadCtxHookIsEnabled(pVCpu)); \
241 RTThreadPreemptDisable(&PreemptStateInternal)
242#else
243# define HM_DISABLE_PREEMPT() \
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 * Global per-cpu information. (host)
264 */
265typedef struct HMGLOBALCPUINFO
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 volatile bool 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 * contigous 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} HMGLOBALCPUINFO;
307/** Pointer to the per-cpu global information. */
308typedef HMGLOBALCPUINFO *PHMGLOBALCPUINFO;
309
310typedef enum
311{
312 HMPENDINGIO_INVALID = 0,
313 HMPENDINGIO_PORT_READ,
314 /* not implemented: HMPENDINGIO_STRING_READ, */
315 /* not implemented: HMPENDINGIO_STRING_WRITE, */
316 /** The usual 32-bit paranoia. */
317 HMPENDINGIO_32BIT_HACK = 0x7fffffff
318} HMPENDINGIO;
319
320
321typedef enum
322{
323 HMTPRINSTR_INVALID,
324 HMTPRINSTR_READ,
325 HMTPRINSTR_READ_SHR4,
326 HMTPRINSTR_WRITE_REG,
327 HMTPRINSTR_WRITE_IMM,
328 HMTPRINSTR_JUMP_REPLACEMENT,
329 /** The usual 32-bit paranoia. */
330 HMTPRINSTR_32BIT_HACK = 0x7fffffff
331} HMTPRINSTR;
332
333typedef struct
334{
335 /** The key is the address of patched instruction. (32 bits GC ptr) */
336 AVLOU32NODECORE Core;
337 /** Original opcode. */
338 uint8_t aOpcode[16];
339 /** Instruction size. */
340 uint32_t cbOp;
341 /** Replacement opcode. */
342 uint8_t aNewOpcode[16];
343 /** Replacement instruction size. */
344 uint32_t cbNewOp;
345 /** Instruction type. */
346 HMTPRINSTR enmType;
347 /** Source operand. */
348 uint32_t uSrcOperand;
349 /** Destination operand. */
350 uint32_t uDstOperand;
351 /** Number of times the instruction caused a fault. */
352 uint32_t cFaults;
353 /** Patch address of the jump replacement. */
354 RTGCPTR32 pJumpTarget;
355} HMTPRPATCH;
356/** Pointer to HMTPRPATCH. */
357typedef HMTPRPATCH *PHMTPRPATCH;
358/** Pointer to a const HMTPRPATCH. */
359typedef const HMTPRPATCH *PCHMTPRPATCH;
360
361
362/**
363 * Makes a HMEXITSTAT::uKey value from a program counter and an exit code.
364 *
365 * @returns 64-bit key
366 * @param a_uPC The RIP + CS.BASE value of the exit.
367 * @param a_uExit The exit code.
368 * @todo Add CPL?
369 */
370#define HMEXITSTAT_MAKE_KEY(a_uPC, a_uExit) (((a_uPC) & UINT64_C(0x0000ffffffffffff)) | (uint64_t)(a_uExit) << 48)
371
372typedef struct HMEXITINFO
373{
374 /** See HMEXITSTAT_MAKE_KEY(). */
375 uint64_t uKey;
376 /** Number of recent hits (depreciates with time). */
377 uint32_t volatile cHits;
378 /** The age + lock. */
379 uint16_t volatile uAge;
380 /** Action or action table index. */
381 uint16_t iAction;
382} HMEXITINFO;
383AssertCompileSize(HMEXITINFO, 16); /* Lots of these guys, so don't add any unnecessary stuff! */
384
385typedef struct HMEXITHISTORY
386{
387 /** The exit timestamp. */
388 uint64_t uTscExit;
389 /** The index of the corresponding HMEXITINFO entry.
390 * UINT32_MAX if none (too many collisions, race, whatever). */
391 uint32_t iExitInfo;
392 /** Figure out later, needed for padding now. */
393 uint32_t uSomeClueOrSomething;
394} HMEXITHISTORY;
395
396/**
397 * Switcher function, HC to the special 64-bit RC.
398 *
399 * @param pVM The cross context VM structure.
400 * @param offCpumVCpu Offset from pVM->cpum to pVM->aCpus[idCpu].cpum.
401 * @returns Return code indicating the action to take.
402 */
403typedef DECLCALLBACK(int) FNHMSWITCHERHC(PVM pVM, uint32_t offCpumVCpu);
404/** Pointer to switcher function. */
405typedef FNHMSWITCHERHC *PFNHMSWITCHERHC;
406
407/**
408 * HM VM Instance data.
409 * Changes to this must checked against the padding of the hm union in VM!
410 */
411typedef struct HM
412{
413 /** Set when we've initialized VMX or SVM. */
414 bool fInitialized;
415 /** Set if nested paging is enabled. */
416 bool fNestedPaging;
417 /** Set if nested paging is allowed. */
418 bool fAllowNestedPaging;
419 /** Set if large pages are enabled (requires nested paging). */
420 bool fLargePages;
421 /** Set if we can support 64-bit guests or not. */
422 bool fAllow64BitGuests;
423 /** Set when TPR patching is allowed. */
424 bool fTprPatchingAllowed;
425 /** Set when we initialize VT-x or AMD-V once for all CPUs. */
426 bool fGlobalInit;
427 /** Set when TPR patching is active. */
428 bool fTPRPatchingActive;
429 /** Set when the debug facility has breakpoints/events enabled that requires
430 * us to use the debug execution loop in ring-0. */
431 bool fUseDebugLoop;
432 /** Set if hardware APIC virtualization is enabled. */
433 bool fVirtApicRegs;
434 /** Set if posted interrupt processing is enabled. */
435 bool fPostedIntrs;
436 /** Set if indirect branch prediction barrier on VM exit. */
437 bool fIbpbOnVmExit;
438 /** Set if indirect branch prediction barrier on VM entry. */
439 bool fIbpbOnVmEntry;
440 /** Set if host manages speculation control settings. */
441 bool fSpecCtrlByHost;
442 /** Explicit padding. */
443 bool afPadding[2];
444
445 /** Maximum ASID allowed. */
446 uint32_t uMaxAsid;
447 /** The maximum number of resumes loops allowed in ring-0 (safety precaution).
448 * This number is set much higher when RTThreadPreemptIsPending is reliable. */
449 uint32_t cMaxResumeLoops;
450
451 /** Host kernel flags that HM might need to know (SUPKERNELFEATURES_XXX). */
452 uint32_t fHostKernelFeatures;
453
454 /** Size of the guest patch memory block. */
455 uint32_t cbGuestPatchMem;
456 /** Guest allocated memory for patching purposes. */
457 RTGCPTR pGuestPatchMem;
458 /** Current free pointer inside the patch block. */
459 RTGCPTR pFreeGuestPatchMem;
460
461#if HC_ARCH_BITS == 32 && defined(VBOX_ENABLE_64_BITS_GUESTS)
462 /** 32 to 64 bits switcher entrypoint. */
463 R0PTRTYPE(PFNHMSWITCHERHC) pfnHost32ToGuest64R0;
464 RTR0PTR pvR0Alignment0;
465#endif
466
467 struct
468 {
469 /** Set by the ring-0 side of HM to indicate VMX is supported by the
470 * CPU. */
471 bool fSupported;
472 /** Set when we've enabled VMX. */
473 bool fEnabled;
474 /** Set if VPID is supported. */
475 bool fVpid;
476 /** Set if VT-x VPID is allowed. */
477 bool fAllowVpid;
478 /** Set if unrestricted guest execution is in use (real and protected mode without paging). */
479 bool fUnrestrictedGuest;
480 /** Set if unrestricted guest execution is allowed to be used. */
481 bool fAllowUnrestricted;
482 /** Whether we're using the preemption timer or not. */
483 bool fUsePreemptTimer;
484 /** The shift mask employed by the VMX-Preemption timer. */
485 uint8_t cPreemptTimerShift;
486
487 /** Virtual address of the TSS page used for real mode emulation. */
488 R3PTRTYPE(PVBOXTSS) pRealModeTSS;
489 /** Virtual address of the identity page table used for real mode and protected mode without paging emulation in EPT mode. */
490 R3PTRTYPE(PX86PD) pNonPagingModeEPTPageTable;
491
492 /** Physical address of the APIC-access page. */
493 RTHCPHYS HCPhysApicAccess;
494 /** R0 memory object for the APIC-access page. */
495 RTR0MEMOBJ hMemObjApicAccess;
496 /** Virtual address of the APIC-access page. */
497 R0PTRTYPE(uint8_t *) pbApicAccess;
498
499#ifdef VBOX_WITH_CRASHDUMP_MAGIC
500 RTHCPHYS HCPhysScratch;
501 RTR0MEMOBJ hMemObjScratch;
502 R0PTRTYPE(uint8_t *) pbScratch;
503#endif
504
505 /** Internal Id of which flush-handler to use for tagged-TLB entries. */
506 uint32_t uFlushTaggedTlb;
507
508 /** Pause-loop exiting (PLE) gap in ticks. */
509 uint32_t cPleGapTicks;
510 /** Pause-loop exiting (PLE) window in ticks. */
511 uint32_t cPleWindowTicks;
512 uint32_t u32Alignment0;
513
514 /** Host CR4 value (set by ring-0 VMX init) */
515 uint64_t u64HostCr4;
516 /** Host SMM monitor control (set by ring-0 VMX init) */
517 uint64_t u64HostSmmMonitorCtl;
518 /** Host EFER value (set by ring-0 VMX init) */
519 uint64_t u64HostEfer;
520 /** Whether the CPU supports VMCS fields for swapping EFER. */
521 bool fSupportsVmcsEfer;
522 uint8_t u8Alignment2[7];
523
524 /** VMX MSR values. */
525 VMXMSRS Msrs;
526
527 /** Flush types for invept & invvpid; they depend on capabilities. */
528 VMXFLUSHEPT enmFlushEpt;
529 VMXFLUSHVPID enmFlushVpid;
530
531 /** Host-physical address for a failing VMXON instruction. */
532 RTHCPHYS HCPhysVmxEnableError;
533 } vmx;
534
535 struct
536 {
537 /** Set by the ring-0 side of HM to indicate SVM is supported by the
538 * CPU. */
539 bool fSupported;
540 /** Set when we've enabled SVM. */
541 bool fEnabled;
542 /** Set if erratum 170 affects the AMD cpu. */
543 bool fAlwaysFlushTLB;
544 /** Set when the hack to ignore VERR_SVM_IN_USE is active. */
545 bool fIgnoreInUseError;
546 /** Whether to use virtualized VMSAVE/VMLOAD feature. */
547 bool fVirtVmsaveVmload;
548 /** Whether to use virtual GIF feature. */
549 bool fVGif;
550 uint8_t u8Alignment0[2];
551
552 /** Physical address of the IO bitmap (12kb). */
553 RTHCPHYS HCPhysIOBitmap;
554 /** R0 memory object for the IO bitmap (12kb). */
555 RTR0MEMOBJ hMemObjIOBitmap;
556 /** Virtual address of the IO bitmap. */
557 R0PTRTYPE(void *) pvIOBitmap;
558
559 /* HWCR MSR (for diagnostics) */
560 uint64_t u64MsrHwcr;
561
562 /** SVM revision. */
563 uint32_t u32Rev;
564 /** SVM feature bits from cpuid 0x8000000a */
565 uint32_t u32Features;
566
567 /** Pause filter counter. */
568 uint16_t cPauseFilter;
569 /** Pause filter treshold in ticks. */
570 uint16_t cPauseFilterThresholdTicks;
571 uint32_t u32Alignment0;
572 } svm;
573
574 /**
575 * AVL tree with all patches (active or disabled) sorted by guest instruction
576 * address.
577 */
578 AVLOU32TREE PatchTree;
579 uint32_t cPatches;
580 HMTPRPATCH aPatches[64];
581
582 struct
583 {
584 uint32_t u32AMDFeatureECX;
585 uint32_t u32AMDFeatureEDX;
586 } cpuid;
587
588 /** Saved error from detection */
589 int32_t lLastError;
590
591 /** HMR0Init was run */
592 bool fHMR0Init;
593 bool u8Alignment1[3];
594
595 STAMCOUNTER StatTprPatchSuccess;
596 STAMCOUNTER StatTprPatchFailure;
597 STAMCOUNTER StatTprReplaceSuccessCr8;
598 STAMCOUNTER StatTprReplaceSuccessVmc;
599 STAMCOUNTER StatTprReplaceFailure;
600} HM;
601/** Pointer to HM VM instance data. */
602typedef HM *PHM;
603
604AssertCompileMemberAlignment(HM, StatTprPatchSuccess, 8);
605
606/* Maximum number of cached entries. */
607#define VMCSCACHE_MAX_ENTRY 128
608
609/**
610 * Structure for storing read and write VMCS actions.
611 */
612typedef struct VMCSCACHE
613{
614#ifdef VBOX_WITH_CRASHDUMP_MAGIC
615 /* Magic marker for searching in crash dumps. */
616 uint8_t aMagic[16];
617 uint64_t uMagic;
618 uint64_t u64TimeEntry;
619 uint64_t u64TimeSwitch;
620 uint64_t cResume;
621 uint64_t interPD;
622 uint64_t pSwitcher;
623 uint32_t uPos;
624 uint32_t idCpu;
625#endif
626 /* CR2 is saved here for EPT syncing. */
627 uint64_t cr2;
628 struct
629 {
630 uint32_t cValidEntries;
631 uint32_t uAlignment;
632 uint32_t aField[VMCSCACHE_MAX_ENTRY];
633 uint64_t aFieldVal[VMCSCACHE_MAX_ENTRY];
634 } Write;
635 struct
636 {
637 uint32_t cValidEntries;
638 uint32_t uAlignment;
639 uint32_t aField[VMCSCACHE_MAX_ENTRY];
640 uint64_t aFieldVal[VMCSCACHE_MAX_ENTRY];
641 } Read;
642#ifdef VBOX_STRICT
643 struct
644 {
645 RTHCPHYS HCPhysCpuPage;
646 RTHCPHYS HCPhysVmcs;
647 RTGCPTR pCache;
648 RTGCPTR pCtx;
649 } TestIn;
650 struct
651 {
652 RTHCPHYS HCPhysVmcs;
653 RTGCPTR pCache;
654 RTGCPTR pCtx;
655 uint64_t eflags;
656 uint64_t cr8;
657 } TestOut;
658 struct
659 {
660 uint64_t param1;
661 uint64_t param2;
662 uint64_t param3;
663 uint64_t param4;
664 } ScratchPad;
665#endif
666} VMCSCACHE;
667/** Pointer to VMCSCACHE. */
668typedef VMCSCACHE *PVMCSCACHE;
669AssertCompileSizeAlignment(VMCSCACHE, 8);
670
671/**
672 * VMX StartVM function.
673 *
674 * @returns VBox status code (no informational stuff).
675 * @param fResume Whether to use VMRESUME (true) or VMLAUNCH (false).
676 * @param pCtx The CPU register context.
677 * @param pCache The VMCS cache.
678 * @param pVM Pointer to the cross context VM structure.
679 * @param pVCpu Pointer to the cross context per-CPU structure.
680 */
681typedef DECLCALLBACK(int) FNHMVMXSTARTVM(RTHCUINT fResume, PCPUMCTX pCtx, PVMCSCACHE pCache, PVM pVM, PVMCPU pVCpu);
682/** Pointer to a VMX StartVM function. */
683typedef R0PTRTYPE(FNHMVMXSTARTVM *) PFNHMVMXSTARTVM;
684
685/** SVM VMRun function. */
686typedef DECLCALLBACK(int) FNHMSVMVMRUN(RTHCPHYS pVmcbHostPhys, RTHCPHYS pVmcbPhys, PCPUMCTX pCtx, PVM pVM, PVMCPU pVCpu);
687/** Pointer to a SVM VMRun function. */
688typedef R0PTRTYPE(FNHMSVMVMRUN *) PFNHMSVMVMRUN;
689
690/**
691 * HM VMCPU Instance data.
692 *
693 * Note! If you change members of this struct, make sure to check if the
694 * assembly counterpart in HMInternal.mac needs to be updated as well.
695 */
696typedef struct HMCPU
697{
698 /** Set if we need to flush the TLB during the world switch. */
699 bool fForceTLBFlush;
700 /** Set when we're using VT-x or AMD-V at that moment. */
701 bool fActive;
702 /** Set when the TLB has been checked until we return from the world switch. */
703 volatile bool fCheckedTLBFlush;
704 /** Whether we've completed the inner HM leave function. */
705 bool fLeaveDone;
706 /** Whether we're using the hyper DR7 or guest DR7. */
707 bool fUsingHyperDR7;
708 /** Whether to preload the guest-FPU state to avoid \#NM VM-exit overhead. */
709 bool fPreloadGuestFpu;
710 /** Set if XCR0 needs to be loaded and saved when entering and exiting guest
711 * code execution. */
712 bool fLoadSaveGuestXcr0;
713
714 /** Whether we should use the debug loop because of single stepping or special
715 * debug breakpoints / events are armed. */
716 bool fUseDebugLoop;
717 /** Whether we are currently executing in the debug loop.
718 * Mainly for assertions. */
719 bool fUsingDebugLoop;
720 /** Set if we using the debug loop and wish to intercept RDTSC. */
721 bool fDebugWantRdTscExit;
722 /** Whether we're executing a single instruction. */
723 bool fSingleInstruction;
724 /** Set if we need to clear the trap flag because of single stepping. */
725 bool fClearTrapFlag;
726
727 /** Whether \#UD needs to be intercepted (required by certain GIM providers). */
728 bool fGIMTrapXcptUD;
729 uint8_t u8Alignment0[3];
730
731 /** World switch exit counter. */
732 volatile uint32_t cWorldSwitchExits;
733 /** HM_CHANGED_* flags. */
734 volatile uint32_t fContextUseFlags;
735 /** Id of the last cpu we were executing code on (NIL_RTCPUID for the first
736 * time). */
737 RTCPUID idLastCpu;
738 /** TLB flush count. */
739 uint32_t cTlbFlushes;
740 /** Current ASID in use by the VM. */
741 uint32_t uCurrentAsid;
742 /** An additional error code used for some gurus. */
743 uint32_t u32HMError;
744 /** Host's TSC_AUX MSR (used when RDTSCP doesn't cause VM-exits). */
745 uint64_t u64HostTscAux;
746
747 struct
748 {
749 /** Ring 0 handlers for VT-x. */
750 PFNHMVMXSTARTVM pfnStartVM;
751#if HC_ARCH_BITS == 32
752 uint32_t u32Alignment0;
753#endif
754 /** Current VMX_VMCS32_CTRL_PIN_EXEC. */
755 uint32_t u32PinCtls;
756 /** Current VMX_VMCS32_CTRL_PROC_EXEC. */
757 uint32_t u32ProcCtls;
758 /** Current VMX_VMCS32_CTRL_PROC_EXEC2. */
759 uint32_t u32ProcCtls2;
760 /** Current VMX_VMCS32_CTRL_EXIT. */
761 uint32_t u32ExitCtls;
762 /** Current VMX_VMCS32_CTRL_ENTRY. */
763 uint32_t u32EntryCtls;
764
765 /** Current CR0 mask. */
766 uint32_t u32CR0Mask;
767 /** Current CR4 mask. */
768 uint32_t u32CR4Mask;
769 /** Current exception bitmap. */
770 uint32_t u32XcptBitmap;
771 /** The updated-guest-state mask. */
772 volatile uint32_t fUpdatedGuestState;
773 uint32_t u32Alignment1;
774
775 /** Physical address of the VM control structure (VMCS). */
776 RTHCPHYS HCPhysVmcs;
777 /** R0 memory object for the VM control structure (VMCS). */
778 RTR0MEMOBJ hMemObjVmcs;
779 /** Virtual address of the VM control structure (VMCS). */
780 R0PTRTYPE(void *) pvVmcs;
781
782 /** Physical address of the virtual APIC page for TPR caching. */
783 RTHCPHYS HCPhysVirtApic;
784 /** Padding. */
785 R0PTRTYPE(void *) pvAlignment0;
786 /** Virtual address of the virtual APIC page for TPR caching. */
787 R0PTRTYPE(uint8_t *) pbVirtApic;
788
789 /** Physical address of the MSR bitmap. */
790 RTHCPHYS HCPhysMsrBitmap;
791 /** R0 memory object for the MSR bitmap. */
792 RTR0MEMOBJ hMemObjMsrBitmap;
793 /** Virtual address of the MSR bitmap. */
794 R0PTRTYPE(void *) pvMsrBitmap;
795
796 /** Physical address of the VM-entry MSR-load and VM-exit MSR-store area (used
797 * for guest MSRs). */
798 RTHCPHYS HCPhysGuestMsr;
799 /** R0 memory object of the VM-entry MSR-load and VM-exit MSR-store area
800 * (used for guest MSRs). */
801 RTR0MEMOBJ hMemObjGuestMsr;
802 /** Virtual address of the VM-entry MSR-load and VM-exit MSR-store area (used
803 * for guest MSRs). */
804 R0PTRTYPE(void *) pvGuestMsr;
805
806 /** Physical address of the VM-exit MSR-load area (used for host MSRs). */
807 RTHCPHYS HCPhysHostMsr;
808 /** R0 memory object for the VM-exit MSR-load area (used for host MSRs). */
809 RTR0MEMOBJ hMemObjHostMsr;
810 /** Virtual address of the VM-exit MSR-load area (used for host MSRs). */
811 R0PTRTYPE(void *) pvHostMsr;
812
813 /** Current EPTP. */
814 RTHCPHYS HCPhysEPTP;
815
816 /** Number of guest/host MSR pairs in the auto-load/store area. */
817 uint32_t cMsrs;
818 /** Whether the host MSR values are up-to-date in the auto-load/store area. */
819 bool fUpdatedHostMsrs;
820 uint8_t u8Alignment0[3];
821
822 /** Host LSTAR MSR value to restore lazily while leaving VT-x. */
823 uint64_t u64HostLStarMsr;
824 /** Host STAR MSR value to restore lazily while leaving VT-x. */
825 uint64_t u64HostStarMsr;
826 /** Host SF_MASK MSR value to restore lazily while leaving VT-x. */
827 uint64_t u64HostSFMaskMsr;
828 /** Host KernelGS-Base MSR value to restore lazily while leaving VT-x. */
829 uint64_t u64HostKernelGSBaseMsr;
830 /** A mask of which MSRs have been swapped and need restoration. */
831 uint32_t fLazyMsrs;
832 uint32_t u32Alignment2;
833
834 /** The cached APIC-base MSR used for identifying when to map the HC physical APIC-access page. */
835 uint64_t u64MsrApicBase;
836 /** Last use TSC offset value. (cached) */
837 uint64_t u64TSCOffset;
838
839 /** VMCS cache. */
840 VMCSCACHE VMCSCache;
841
842 /** Real-mode emulation state. */
843 struct
844 {
845 X86DESCATTR AttrCS;
846 X86DESCATTR AttrDS;
847 X86DESCATTR AttrES;
848 X86DESCATTR AttrFS;
849 X86DESCATTR AttrGS;
850 X86DESCATTR AttrSS;
851 X86EFLAGS Eflags;
852 uint32_t fRealOnV86Active;
853 } RealMode;
854
855 /** VT-x error-reporting (mainly for ring-3 propagation). */
856 struct
857 {
858 uint64_t u64VMCSPhys;
859 uint32_t u32VMCSRevision;
860 uint32_t u32InstrError;
861 uint32_t u32ExitReason;
862 RTCPUID idEnteredCpu;
863 RTCPUID idCurrentCpu;
864 uint32_t u32Alignment0;
865 } LastError;
866
867 /** Current state of the VMCS. */
868 uint32_t uVmcsState;
869 /** Which host-state bits to restore before being preempted. */
870 uint32_t fRestoreHostFlags;
871 /** The host-state restoration structure. */
872 VMXRESTOREHOST RestoreHost;
873
874 /** Set if guest was executing in real mode (extra checks). */
875 bool fWasInRealMode;
876 /** Set if guest switched to 64-bit mode on a 32-bit host. */
877 bool fSwitchedTo64on32;
878
879 uint8_t u8Alignment1[6];
880 } vmx;
881
882 struct
883 {
884 /** Ring 0 handlers for VT-x. */
885 PFNHMSVMVMRUN pfnVMRun;
886#if HC_ARCH_BITS == 32
887 uint32_t u32Alignment0;
888#endif
889
890 /** Physical address of the host VMCB which holds additional host-state. */
891 RTHCPHYS HCPhysVmcbHost;
892 /** R0 memory object for the host VMCB which holds additional host-state. */
893 RTR0MEMOBJ hMemObjVmcbHost;
894 /** Padding. */
895 R0PTRTYPE(void *) pvPadding;
896
897 /** Physical address of the guest VMCB. */
898 RTHCPHYS HCPhysVmcb;
899 /** R0 memory object for the guest VMCB. */
900 RTR0MEMOBJ hMemObjVmcb;
901 /** Pointer to the guest VMCB. */
902 R0PTRTYPE(PSVMVMCB) pVmcb;
903
904 /** Physical address of the MSR bitmap (8 KB). */
905 RTHCPHYS HCPhysMsrBitmap;
906 /** R0 memory object for the MSR bitmap (8 KB). */
907 RTR0MEMOBJ hMemObjMsrBitmap;
908 /** Pointer to the MSR bitmap. */
909 R0PTRTYPE(void *) pvMsrBitmap;
910
911 /** Whether VTPR with V_INTR_MASKING set is in effect, indicating
912 * we should check if the VTPR changed on every VM-exit. */
913 bool fSyncVTpr;
914 uint8_t u8Alignment0[7];
915
916 /** Cache of the nested-guest's VMCB fields that we modify in order to run the
917 * nested-guest using AMD-V. This will be restored on \#VMEXIT. */
918 SVMNESTEDVMCBCACHE NstGstVmcbCache;
919 } svm;
920
921 /** Event injection state. */
922 struct
923 {
924 uint32_t fPending;
925 uint32_t u32ErrCode;
926 uint32_t cbInstr;
927 uint32_t u32Padding; /**< Explicit alignment padding. */
928 uint64_t u64IntInfo;
929 RTGCUINTPTR GCPtrFaultAddress;
930 } Event;
931
932 /** IO Block emulation state. */
933 struct
934 {
935 bool fEnabled;
936 uint8_t u8Align[7];
937
938 /** RIP at the start of the io code we wish to emulate in the recompiler. */
939 RTGCPTR GCPtrFunctionEip;
940
941 uint64_t cr0;
942 } EmulateIoBlock;
943
944 /* */
945 struct
946 {
947 /** Pending IO operation type. */
948 HMPENDINGIO enmType;
949 uint32_t u32Alignment0;
950 RTGCPTR GCPtrRip;
951 RTGCPTR GCPtrRipNext;
952 union
953 {
954 struct
955 {
956 uint32_t uPort;
957 uint32_t uAndVal;
958 uint32_t cbSize;
959 } Port;
960 uint64_t aRaw[2];
961 } s;
962 } PendingIO;
963
964 /** The PAE PDPEs used with Nested Paging (only valid when
965 * VMCPU_FF_HM_UPDATE_PAE_PDPES is set). */
966 X86PDPE aPdpes[4];
967
968 /** Current shadow paging mode. */
969 PGMMODE enmShadowMode;
970
971 /** The CPU ID of the CPU currently owning the VMCS. Set in
972 * HMR0Enter and cleared in HMR0Leave. */
973 RTCPUID idEnteredCpu;
974
975 /** VT-x/AMD-V VM-exit/\#VMXEXIT history, circular array. */
976 uint16_t auExitHistory[31];
977 /** The index of the next free slot in the history array. */
978 uint16_t idxExitHistoryFree;
979
980 /** For saving stack space, the disassembler state is allocated here instead of
981 * on the stack. */
982 DISCPUSTATE DisState;
983
984 STAMPROFILEADV StatEntry;
985 STAMPROFILEADV StatExit1;
986 STAMPROFILEADV StatExit2;
987 STAMPROFILEADV StatExitIO;
988 STAMPROFILEADV StatExitMovCRx;
989 STAMPROFILEADV StatExitXcptNmi;
990 STAMPROFILEADV StatLoadGuestState;
991 STAMPROFILEADV StatLoadGuestFpuState;
992 STAMPROFILEADV StatInGC;
993
994#if HC_ARCH_BITS == 32 && defined(VBOX_ENABLE_64_BITS_GUESTS)
995 STAMPROFILEADV StatWorldSwitch3264;
996#endif
997 STAMPROFILEADV StatPoke;
998 STAMPROFILEADV StatSpinPoke;
999 STAMPROFILEADV StatSpinPokeFailed;
1000
1001 STAMCOUNTER StatInjectInterrupt;
1002 STAMCOUNTER StatInjectXcpt;
1003 STAMCOUNTER StatInjectPendingReflect;
1004 STAMCOUNTER StatInjectPendingInterpret;
1005
1006 STAMCOUNTER StatExitAll;
1007 STAMCOUNTER StatExitShadowNM;
1008 STAMCOUNTER StatExitGuestNM;
1009 STAMCOUNTER StatExitShadowPF; /**< Misleading, currently used for MMIO \#PFs as well. */
1010 STAMCOUNTER StatExitShadowPFEM;
1011 STAMCOUNTER StatExitGuestPF;
1012 STAMCOUNTER StatExitGuestUD;
1013 STAMCOUNTER StatExitGuestSS;
1014 STAMCOUNTER StatExitGuestNP;
1015 STAMCOUNTER StatExitGuestTS;
1016 STAMCOUNTER StatExitGuestGP;
1017 STAMCOUNTER StatExitGuestDE;
1018 STAMCOUNTER StatExitGuestDB;
1019 STAMCOUNTER StatExitGuestMF;
1020 STAMCOUNTER StatExitGuestBP;
1021 STAMCOUNTER StatExitGuestXF;
1022 STAMCOUNTER StatExitGuestXcpUnk;
1023 STAMCOUNTER StatExitInvlpg;
1024 STAMCOUNTER StatExitInvd;
1025 STAMCOUNTER StatExitWbinvd;
1026 STAMCOUNTER StatExitPause;
1027 STAMCOUNTER StatExitCpuid;
1028 STAMCOUNTER StatExitRdtsc;
1029 STAMCOUNTER StatExitRdtscp;
1030 STAMCOUNTER StatExitRdpmc;
1031 STAMCOUNTER StatExitVmcall;
1032 STAMCOUNTER StatExitRdrand;
1033 STAMCOUNTER StatExitCli;
1034 STAMCOUNTER StatExitSti;
1035 STAMCOUNTER StatExitPushf;
1036 STAMCOUNTER StatExitPopf;
1037 STAMCOUNTER StatExitIret;
1038 STAMCOUNTER StatExitInt;
1039 STAMCOUNTER StatExitCRxWrite[16];
1040 STAMCOUNTER StatExitCRxRead[16];
1041 STAMCOUNTER StatExitDRxWrite;
1042 STAMCOUNTER StatExitDRxRead;
1043 STAMCOUNTER StatExitRdmsr;
1044 STAMCOUNTER StatExitWrmsr;
1045 STAMCOUNTER StatExitClts;
1046 STAMCOUNTER StatExitXdtrAccess;
1047 STAMCOUNTER StatExitHlt;
1048 STAMCOUNTER StatExitMwait;
1049 STAMCOUNTER StatExitMonitor;
1050 STAMCOUNTER StatExitLmsw;
1051 STAMCOUNTER StatExitIOWrite;
1052 STAMCOUNTER StatExitIORead;
1053 STAMCOUNTER StatExitIOStringWrite;
1054 STAMCOUNTER StatExitIOStringRead;
1055 STAMCOUNTER StatExitIntWindow;
1056 STAMCOUNTER StatExitExtInt;
1057 STAMCOUNTER StatExitHostNmiInGC;
1058 STAMCOUNTER StatExitPreemptTimer;
1059 STAMCOUNTER StatExitTprBelowThreshold;
1060 STAMCOUNTER StatExitTaskSwitch;
1061 STAMCOUNTER StatExitMtf;
1062 STAMCOUNTER StatExitApicAccess;
1063 STAMCOUNTER StatPendingHostIrq;
1064
1065 STAMCOUNTER StatFlushPage;
1066 STAMCOUNTER StatFlushPageManual;
1067 STAMCOUNTER StatFlushPhysPageManual;
1068 STAMCOUNTER StatFlushTlb;
1069 STAMCOUNTER StatFlushTlbManual;
1070 STAMCOUNTER StatFlushTlbWorldSwitch;
1071 STAMCOUNTER StatNoFlushTlbWorldSwitch;
1072 STAMCOUNTER StatFlushEntire;
1073 STAMCOUNTER StatFlushAsid;
1074 STAMCOUNTER StatFlushNestedPaging;
1075 STAMCOUNTER StatFlushTlbInvlpgVirt;
1076 STAMCOUNTER StatFlushTlbInvlpgPhys;
1077 STAMCOUNTER StatTlbShootdown;
1078 STAMCOUNTER StatTlbShootdownFlush;
1079
1080 STAMCOUNTER StatSwitchTprMaskedIrq;
1081 STAMCOUNTER StatSwitchGuestIrq;
1082 STAMCOUNTER StatSwitchHmToR3FF;
1083 STAMCOUNTER StatSwitchExitToR3;
1084 STAMCOUNTER StatSwitchLongJmpToR3;
1085 STAMCOUNTER StatSwitchMaxResumeLoops;
1086 STAMCOUNTER StatSwitchHltToR3;
1087 STAMCOUNTER StatSwitchApicAccessToR3;
1088 STAMCOUNTER StatSwitchPreempt;
1089 STAMCOUNTER StatSwitchPreemptSaveHostState;
1090
1091 STAMCOUNTER StatTscParavirt;
1092 STAMCOUNTER StatTscOffset;
1093 STAMCOUNTER StatTscIntercept;
1094
1095 STAMCOUNTER StatExitReasonNpf;
1096 STAMCOUNTER StatDRxArmed;
1097 STAMCOUNTER StatDRxContextSwitch;
1098 STAMCOUNTER StatDRxIoCheck;
1099
1100 STAMCOUNTER StatLoadMinimal;
1101 STAMCOUNTER StatLoadFull;
1102 STAMCOUNTER StatLoadGuestFpu;
1103
1104 STAMCOUNTER StatVmxCheckBadRmSelBase;
1105 STAMCOUNTER StatVmxCheckBadRmSelLimit;
1106 STAMCOUNTER StatVmxCheckRmOk;
1107
1108 STAMCOUNTER StatVmxCheckBadSel;
1109 STAMCOUNTER StatVmxCheckBadRpl;
1110 STAMCOUNTER StatVmxCheckBadLdt;
1111 STAMCOUNTER StatVmxCheckBadTr;
1112 STAMCOUNTER StatVmxCheckPmOk;
1113
1114 STAMCOUNTER StatNestedExitReasonNpf;
1115
1116#if HC_ARCH_BITS == 32 && defined(VBOX_ENABLE_64_BITS_GUESTS)
1117 STAMCOUNTER StatFpu64SwitchBack;
1118 STAMCOUNTER StatDebug64SwitchBack;
1119#endif
1120
1121#ifdef VBOX_WITH_STATISTICS
1122 R3PTRTYPE(PSTAMCOUNTER) paStatExitReason;
1123 R0PTRTYPE(PSTAMCOUNTER) paStatExitReasonR0;
1124 R3PTRTYPE(PSTAMCOUNTER) paStatInjectedIrqs;
1125 R0PTRTYPE(PSTAMCOUNTER) paStatInjectedIrqsR0;
1126 R3PTRTYPE(PSTAMCOUNTER) paStatNestedExitReason;
1127 R0PTRTYPE(PSTAMCOUNTER) paStatNestedExitReasonR0;
1128#endif
1129#ifdef HM_PROFILE_EXIT_DISPATCH
1130 STAMPROFILEADV StatExitDispatch;
1131#endif
1132} HMCPU;
1133/** Pointer to HM VMCPU instance data. */
1134typedef HMCPU *PHMCPU;
1135AssertCompileMemberAlignment(HMCPU, vmx, 8);
1136AssertCompileMemberAlignment(HMCPU, svm, 8);
1137AssertCompileMemberAlignment(HMCPU, Event, 8);
1138
1139#ifdef IN_RING0
1140VMMR0_INT_DECL(PHMGLOBALCPUINFO) hmR0GetCurrentCpu(void);
1141
1142# ifdef VBOX_STRICT
1143VMMR0_INT_DECL(void) hmR0DumpRegs(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
1144VMMR0_INT_DECL(void) hmR0DumpDescriptor(PCX86DESCHC pDesc, RTSEL Sel, const char *pszMsg);
1145# else
1146# define hmR0DumpRegs(a, b ,c) do { } while (0)
1147# define hmR0DumpDescriptor(a, b, c) do { } while (0)
1148# endif /* VBOX_STRICT */
1149
1150# ifdef VBOX_WITH_KERNEL_USING_XMM
1151DECLASM(int) hmR0VMXStartVMWrapXMM(RTHCUINT fResume, PCPUMCTX pCtx, PVMCSCACHE pCache, PVM pVM, PVMCPU pVCpu, PFNHMVMXSTARTVM pfnStartVM);
1152DECLASM(int) hmR0SVMRunWrapXMM(RTHCPHYS pVmcbHostPhys, RTHCPHYS pVmcbPhys, PCPUMCTX pCtx, PVM pVM, PVMCPU pVCpu, PFNHMSVMVMRUN pfnVMRun);
1153# endif
1154
1155#endif /* IN_RING0 */
1156
1157int hmSvmEmulateMovTpr(PVMCPU pVCpu, PCPUMCTX pCtx);
1158
1159/** @} */
1160
1161RT_C_DECLS_END
1162
1163#endif
1164
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