VirtualBox

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

Last change on this file since 45094 was 45094, checked in by vboxsync, 12 years ago

Build fix, try 2.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 35.1 KB
Line 
1/* $Id: HMInternal.h 45094 2013-03-19 17:51:30Z vboxsync $ */
2/** @file
3 * HM - Internal header file.
4 */
5
6/*
7 * Copyright (C) 2006-2013 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/pgm.h>
29#include <VBox/vmm/cpum.h>
30#include <iprt/memobj.h>
31#include <iprt/cpuset.h>
32#include <iprt/mp.h>
33#include <iprt/avl.h>
34
35#if HC_ARCH_BITS == 64 || defined(VBOX_WITH_HYBRID_32BIT_KERNEL) || defined (VBOX_WITH_64_BITS_GUESTS)
36/* Enable 64 bits guest support. */
37# define VBOX_ENABLE_64_BITS_GUESTS
38#endif
39
40#ifdef VBOX_WITH_OLD_VTX_CODE
41# define VMX_USE_CACHED_VMCS_ACCESSES
42#elif HC_ARCH_BITS == 32 && !defined(VBOX_WITH_HYBRID_32BIT_KERNEL)
43# define VMX_USE_CACHED_VMCS_ACCESSES
44#endif
45
46#define HM_VMX_EMULATE_REALMODE
47
48/* The MSR auto load/store does not work for KERNEL_GS_BASE MSR, thus we
49 * handle this MSR manually. See @bugref{6208}. This is clearly visible while
50 * booting Solaris 11 (11.1 b19) VMs with 2 Cpus.
51 *
52 * Note: don't forget to update the assembly files while modifying this!
53 */
54# define VBOX_WITH_AUTO_MSR_LOAD_RESTORE
55
56RT_C_DECLS_BEGIN
57
58
59/** @defgroup grp_hm_int Internal
60 * @ingroup grp_hm
61 * @internal
62 * @{
63 */
64
65
66/** Maximum number of exit reason statistics counters. */
67#define MAX_EXITREASON_STAT 0x100
68#define MASK_EXITREASON_STAT 0xff
69#define MASK_INJECT_IRQ_STAT 0xff
70
71/** @name Changed flags
72 * These flags are used to keep track of which important registers that
73 * have been changed since last they were reset.
74 * @{
75 */
76#ifdef VBOX_WITH_OLD_VTX_CODE
77# define HM_CHANGED_GUEST_FPU RT_BIT(0)
78# define HM_CHANGED_GUEST_CR0 RT_BIT(1)
79# define HM_CHANGED_GUEST_CR3 RT_BIT(2)
80# define HM_CHANGED_GUEST_CR4 RT_BIT(3)
81# define HM_CHANGED_GUEST_GDTR RT_BIT(4)
82# define HM_CHANGED_GUEST_IDTR RT_BIT(5)
83# define HM_CHANGED_GUEST_LDTR RT_BIT(6)
84# define HM_CHANGED_GUEST_TR RT_BIT(7)
85# define HM_CHANGED_GUEST_MSR RT_BIT(8)
86# define HM_CHANGED_GUEST_SEGMENT_REGS RT_BIT(9)
87# define HM_CHANGED_GUEST_DEBUG RT_BIT(10)
88# define HM_CHANGED_HOST_CONTEXT RT_BIT(11)
89# define HM_CHANGED_ALL_GUEST ( HM_CHANGED_GUEST_SEGMENT_REGS \
90 | HM_CHANGED_GUEST_CR0 \
91 | HM_CHANGED_GUEST_CR3 \
92 | HM_CHANGED_GUEST_CR4 \
93 | HM_CHANGED_GUEST_GDTR \
94 | HM_CHANGED_GUEST_IDTR \
95 | HM_CHANGED_GUEST_LDTR \
96 | HM_CHANGED_GUEST_TR \
97 | HM_CHANGED_GUEST_MSR \
98 | HM_CHANGED_GUEST_DEBUG \
99 | HM_CHANGED_GUEST_FPU)
100#else
101# define HM_CHANGED_GUEST_RIP RT_BIT(0)
102# define HM_CHANGED_GUEST_RSP RT_BIT(1)
103# define HM_CHANGED_GUEST_RFLAGS RT_BIT(2)
104# define HM_CHANGED_GUEST_FPU RT_BIT(3)
105# define HM_CHANGED_GUEST_CR0 RT_BIT(4)
106# define HM_CHANGED_GUEST_CR2 RT_BIT(5)
107# define HM_CHANGED_GUEST_CR3 RT_BIT(6)
108# define HM_CHANGED_GUEST_CR4 RT_BIT(7)
109# define HM_CHANGED_GUEST_GDTR RT_BIT(8)
110# define HM_CHANGED_GUEST_IDTR RT_BIT(9)
111# define HM_CHANGED_GUEST_LDTR RT_BIT(10)
112# define HM_CHANGED_GUEST_TR RT_BIT(11)
113# define HM_CHANGED_GUEST_SEGMENT_REGS RT_BIT(12)
114# define HM_CHANGED_GUEST_DEBUG RT_BIT(13)
115# define HM_CHANGED_GUEST_FS_BASE_MSR RT_BIT(14)
116# define HM_CHANGED_GUEST_GS_BASE_MSR RT_BIT(15)
117# define HM_CHANGED_GUEST_SYSENTER_CS_MSR RT_BIT(16)
118# define HM_CHANGED_GUEST_SYSENTER_EIP_MSR RT_BIT(17)
119# define HM_CHANGED_GUEST_SYSENTER_ESP_MSR RT_BIT(18)
120# define HM_CHANGED_GUEST_INTR_STATE RT_BIT(19)
121# define HM_CHANGED_VMX_GUEST_AUTO_MSRS RT_BIT(20)
122# define HM_CHANGED_VMX_GUEST_ACTIVITY_STATE RT_BIT(21)
123# define HM_CHANGED_VMX_GUEST_APIC_STATE RT_BIT(22)
124# define HM_CHANGED_VMX_ENTRY_CTLS RT_BIT(23)
125# define HM_CHANGED_VMX_EXIT_CTLS RT_BIT(24)
126
127# define HM_CHANGED_HOST_CONTEXT RT_BIT(25)
128
129# define HM_CHANGED_ALL_GUEST ( HM_CHANGED_GUEST_RIP \
130 | HM_CHANGED_GUEST_RSP \
131 | HM_CHANGED_GUEST_RFLAGS \
132 | HM_CHANGED_GUEST_FPU \
133 | HM_CHANGED_GUEST_CR0 \
134 | HM_CHANGED_GUEST_CR2 \
135 | HM_CHANGED_GUEST_CR3 \
136 | HM_CHANGED_GUEST_CR4 \
137 | HM_CHANGED_GUEST_GDTR \
138 | HM_CHANGED_GUEST_IDTR \
139 | HM_CHANGED_GUEST_LDTR \
140 | HM_CHANGED_GUEST_TR \
141 | HM_CHANGED_GUEST_SEGMENT_REGS \
142 | HM_CHANGED_GUEST_DEBUG \
143 | HM_CHANGED_GUEST_FS_BASE_MSR \
144 | HM_CHANGED_GUEST_GS_BASE_MSR \
145 | HM_CHANGED_GUEST_SYSENTER_CS_MSR \
146 | HM_CHANGED_GUEST_SYSENTER_EIP_MSR \
147 | HM_CHANGED_GUEST_SYSENTER_ESP_MSR \
148 | HM_CHANGED_GUEST_INTR_STATE \
149 | HM_CHANGED_VMX_GUEST_AUTO_MSRS \
150 | HM_CHANGED_VMX_GUEST_ACTIVITY_STATE \
151 | HM_CHANGED_VMX_GUEST_APIC_STATE \
152 | HM_CHANGED_VMX_ENTRY_CTLS \
153 | HM_CHANGED_VMX_EXIT_CTLS)
154#endif
155
156#define HM_CHANGED_ALL (HM_CHANGED_ALL_GUEST | HM_CHANGED_HOST_CONTEXT)
157/** @} */
158
159/** Maximum number of page flushes we are willing to remember before considering a full TLB flush. */
160#define HM_MAX_TLB_SHOOTDOWN_PAGES 8
161
162/** Size for the EPT identity page table (1024 4 MB pages to cover the entire address space). */
163#define HM_EPT_IDENTITY_PG_TABLE_SIZE PAGE_SIZE
164/** Size of the TSS structure + 2 pages for the IO bitmap + end byte. */
165#define HM_VTX_TSS_SIZE (sizeof(VBOXTSS) + 2 * PAGE_SIZE + 1)
166/** Total guest mapped memory needed. */
167#define HM_VTX_TOTAL_DEVHEAP_MEM (HM_EPT_IDENTITY_PG_TABLE_SIZE + HM_VTX_TSS_SIZE)
168
169/** Enable for TPR guest patching. */
170#define VBOX_HM_WITH_GUEST_PATCHING
171
172/** HM SSM version
173 */
174#ifdef VBOX_HM_WITH_GUEST_PATCHING
175# define HM_SSM_VERSION 5
176# define HM_SSM_VERSION_NO_PATCHING 4
177#else
178# define HM_SSM_VERSION 4
179# define HM_SSM_VERSION_NO_PATCHING 4
180#endif
181#define HM_SSM_VERSION_2_0_X 3
182
183/**
184 * Global per-cpu information. (host)
185 */
186typedef struct HMGLOBLCPUINFO
187{
188 /** The CPU ID. */
189 RTCPUID idCpu;
190 /** The memory object */
191 RTR0MEMOBJ hMemObj;
192 /** Current ASID (AMD-V) / VPID (Intel). */
193 uint32_t uCurrentAsid;
194 /** TLB flush count. */
195 uint32_t cTlbFlushes;
196 /** Whether to flush each new ASID/VPID before use. */
197 bool fFlushAsidBeforeUse;
198 /** Configured for VT-x or AMD-V. */
199 bool fConfigured;
200 /** Set if the VBOX_HWVIRTEX_IGNORE_SVM_IN_USE hack is active. */
201 bool fIgnoreAMDVInUseError;
202 /** In use by our code. (for power suspend) */
203 volatile bool fInUse;
204} HMGLOBLCPUINFO;
205/** Pointer to the per-cpu global information. */
206typedef HMGLOBLCPUINFO *PHMGLOBLCPUINFO;
207
208typedef enum
209{
210 HMPENDINGIO_INVALID = 0,
211 HMPENDINGIO_PORT_READ,
212 HMPENDINGIO_PORT_WRITE,
213 HMPENDINGIO_STRING_READ,
214 HMPENDINGIO_STRING_WRITE,
215 /** The usual 32-bit paranoia. */
216 HMPENDINGIO_32BIT_HACK = 0x7fffffff
217} HMPENDINGIO;
218
219
220typedef enum
221{
222 HMTPRINSTR_INVALID,
223 HMTPRINSTR_READ,
224 HMTPRINSTR_READ_SHR4,
225 HMTPRINSTR_WRITE_REG,
226 HMTPRINSTR_WRITE_IMM,
227 HMTPRINSTR_JUMP_REPLACEMENT,
228 /** The usual 32-bit paranoia. */
229 HMTPRINSTR_32BIT_HACK = 0x7fffffff
230} HMTPRINSTR;
231
232typedef struct
233{
234 /** The key is the address of patched instruction. (32 bits GC ptr) */
235 AVLOU32NODECORE Core;
236 /** Original opcode. */
237 uint8_t aOpcode[16];
238 /** Instruction size. */
239 uint32_t cbOp;
240 /** Replacement opcode. */
241 uint8_t aNewOpcode[16];
242 /** Replacement instruction size. */
243 uint32_t cbNewOp;
244 /** Instruction type. */
245 HMTPRINSTR enmType;
246 /** Source operand. */
247 uint32_t uSrcOperand;
248 /** Destination operand. */
249 uint32_t uDstOperand;
250 /** Number of times the instruction caused a fault. */
251 uint32_t cFaults;
252 /** Patch address of the jump replacement. */
253 RTGCPTR32 pJumpTarget;
254} HMTPRPATCH;
255/** Pointer to HMTPRPATCH. */
256typedef HMTPRPATCH *PHMTPRPATCH;
257
258/**
259 * Switcher function, HC to RC.
260 *
261 * @param pVM Pointer to the VM.
262 * @param uOffsetVMCPU VMCPU offset from pVM
263 * @returns Return code indicating the action to take.
264 */
265typedef DECLCALLBACK (int) FNHMSWITCHERHC(PVM pVM, uint32_t uOffsetVMCPU);
266/** Pointer to switcher function. */
267typedef FNHMSWITCHERHC *PFNHMSWITCHERHC;
268
269/**
270 * HM VM Instance data.
271 * Changes to this must checked against the padding of the hm union in VM!
272 */
273typedef struct HM
274{
275 /** Set when we've initialized VMX or SVM. */
276 bool fInitialized;
277
278 /** Set when hardware acceleration is allowed. */
279 bool fAllowed;
280
281 /** Set if nested paging is enabled. */
282 bool fNestedPaging;
283
284 /** Set if nested paging is allowed. */
285 bool fAllowNestedPaging;
286
287 /** Set if large pages are enabled (requires nested paging). */
288 bool fLargePages;
289
290 /** Set if we can support 64-bit guests or not. */
291 bool fAllow64BitGuests;
292
293 /** Set if an IO-APIC is configured for this VM. */
294 bool fHasIoApic;
295
296 /** Set when TPR patching is allowed. */
297 bool fTRPPatchingAllowed;
298
299 /** Set when we initialize VT-x or AMD-V once for all CPUs. */
300 bool fGlobalInit;
301
302 /** Set when TPR patching is active. */
303 bool fTPRPatchingActive;
304 bool u8Alignment[6];
305
306 /** And mask for copying register contents. */
307 uint64_t u64RegisterMask;
308
309 /** Maximum ASID allowed. */
310 uint32_t uMaxAsid;
311
312 /** The maximum number of resumes loops allowed in ring-0 (safety precaution).
313 * This number is set much higher when RTThreadPreemptIsPending is reliable. */
314 uint32_t cMaxResumeLoops;
315
316 /** Guest allocated memory for patching purposes. */
317 RTGCPTR pGuestPatchMem;
318 /** Current free pointer inside the patch block. */
319 RTGCPTR pFreeGuestPatchMem;
320 /** Size of the guest patch memory block. */
321 uint32_t cbGuestPatchMem;
322 uint32_t uPadding1;
323
324#if HC_ARCH_BITS == 32 && defined(VBOX_ENABLE_64_BITS_GUESTS) && !defined(VBOX_WITH_HYBRID_32BIT_KERNEL)
325 /** 32 to 64 bits switcher entrypoint. */
326 R0PTRTYPE(PFNHMSWITCHERHC) pfnHost32ToGuest64R0;
327
328 /* AMD-V 64 bits vmrun handler */
329 RTRCPTR pfnSVMGCVMRun64;
330
331 /* VT-x 64 bits vmlaunch handler */
332 RTRCPTR pfnVMXGCStartVM64;
333
334 /* RC handler to setup the 64 bits FPU state. */
335 RTRCPTR pfnSaveGuestFPU64;
336
337 /* RC handler to setup the 64 bits debug state. */
338 RTRCPTR pfnSaveGuestDebug64;
339
340 /* Test handler */
341 RTRCPTR pfnTest64;
342
343 RTRCPTR uAlignment[2];
344/*#elif defined(VBOX_WITH_HYBRID_32BIT_KERNEL)
345 uint32_t u32Alignment[1]; */
346#endif
347
348 struct
349 {
350 /** Set by the ring-0 side of HM to indicate VMX is supported by the
351 * CPU. */
352 bool fSupported;
353
354 /** Set when we've enabled VMX. */
355 bool fEnabled;
356
357 /** Set if VPID is supported. */
358 bool fVpid;
359
360 /** Set if VT-x VPID is allowed. */
361 bool fAllowVpid;
362
363 /** Set if unrestricted guest execution is allowed (real and protected mode without paging). */
364 bool fUnrestrictedGuest;
365
366 /** Whether we're using the preemption timer or not. */
367 bool fUsePreemptTimer;
368 /** The shift mask employed by the VMX-Preemption timer. */
369 uint8_t cPreemptTimerShift;
370
371 bool uAlignment[1];
372
373 /** Virtual address of the TSS page used for real mode emulation. */
374 R3PTRTYPE(PVBOXTSS) pRealModeTSS;
375
376 /** Virtual address of the identity page table used for real mode and protected mode without paging emulation in EPT mode. */
377 R3PTRTYPE(PX86PD) pNonPagingModeEPTPageTable;
378
379 /** R0 memory object for the APIC-access page. */
380 RTR0MEMOBJ hMemObjApicAccess;
381 /** Physical address of the APIC-access page. */
382 RTHCPHYS HCPhysApicAccess;
383 /** Virtual address of the APIC-access page. */
384 R0PTRTYPE(uint8_t *) pbApicAccess;
385
386#ifdef VBOX_WITH_CRASHDUMP_MAGIC
387 RTR0MEMOBJ hMemObjScratch;
388 RTHCPHYS HCPhysScratch;
389 R0PTRTYPE(uint8_t *) pbScratch;
390#endif
391 /** Ring 0 handlers for VT-x. */
392 DECLR0CALLBACKMEMBER(void, pfnFlushTaggedTlb, (PVM pVM, PVMCPU pVCpu));
393
394#if HC_ARCH_BITS == 32 && defined(VBOX_ENABLE_64_BITS_GUESTS)
395 uint32_t u32Alignment;
396#endif
397 /** Host CR4 value (set by ring-0 VMX init) */
398 uint64_t hostCR4;
399
400 /** Host EFER value (set by ring-0 VMX init) */
401 uint64_t hostEFER;
402
403 /** VMX MSR values */
404 struct
405 {
406 uint64_t feature_ctrl;
407 uint64_t vmx_basic_info;
408 VMX_CAPABILITY vmx_pin_ctls;
409 VMX_CAPABILITY vmx_proc_ctls;
410 VMX_CAPABILITY vmx_proc_ctls2;
411 VMX_CAPABILITY vmx_exit;
412 VMX_CAPABILITY vmx_entry;
413 uint64_t vmx_misc;
414 uint64_t vmx_cr0_fixed0;
415 uint64_t vmx_cr0_fixed1;
416 uint64_t vmx_cr4_fixed0;
417 uint64_t vmx_cr4_fixed1;
418 uint64_t vmx_vmcs_enum;
419 uint64_t vmx_ept_vpid_caps;
420 } msr;
421
422 /** Flush types for invept & invvpid; they depend on capabilities. */
423 VMX_FLUSH_EPT enmFlushEpt;
424 VMX_FLUSH_VPID enmFlushVpid;
425 } vmx;
426
427 struct
428 {
429 /** Set by the ring-0 side of HM to indicate SVM is supported by the
430 * CPU. */
431 bool fSupported;
432 /** Set when we've enabled SVM. */
433 bool fEnabled;
434 /** Set if erratum 170 affects the AMD cpu. */
435 bool fAlwaysFlushTLB;
436 /** Set when the hack to ignore VERR_SVM_IN_USE is active. */
437 bool fIgnoreInUseError;
438
439 /** R0 memory object for the IO bitmap (12kb). */
440 RTR0MEMOBJ hMemObjIOBitmap;
441 /** Physical address of the IO bitmap (12kb). */
442 RTHCPHYS HCPhysIOBitmap;
443 /** Virtual address of the IO bitmap. */
444 R0PTRTYPE(void *) pvIOBitmap;
445
446 /* HWCR MSR (for diagnostics) */
447 uint64_t msrHwcr;
448
449 /** SVM revision. */
450 uint32_t u32Rev;
451
452 /** SVM feature bits from cpuid 0x8000000a */
453 uint32_t u32Features;
454 } svm;
455
456 /**
457 * AVL tree with all patches (active or disabled) sorted by guest instruction address
458 */
459 AVLOU32TREE PatchTree;
460 uint32_t cPatches;
461 HMTPRPATCH aPatches[64];
462
463 struct
464 {
465 uint32_t u32AMDFeatureECX;
466 uint32_t u32AMDFeatureEDX;
467 } cpuid;
468
469 /** Saved error from detection */
470 int32_t lLastError;
471
472 /** HMR0Init was run */
473 bool fHMR0Init;
474 bool u8Alignment1[7];
475
476 STAMCOUNTER StatTprPatchSuccess;
477 STAMCOUNTER StatTprPatchFailure;
478 STAMCOUNTER StatTprReplaceSuccess;
479 STAMCOUNTER StatTprReplaceFailure;
480} HM;
481/** Pointer to HM VM instance data. */
482typedef HM *PHM;
483
484/* Maximum number of cached entries. */
485#define VMCSCACHE_MAX_ENTRY 128
486
487/* Structure for storing read and write VMCS actions. */
488typedef struct VMCSCACHE
489{
490#ifdef VBOX_WITH_CRASHDUMP_MAGIC
491 /* Magic marker for searching in crash dumps. */
492 uint8_t aMagic[16];
493 uint64_t uMagic;
494 uint64_t u64TimeEntry;
495 uint64_t u64TimeSwitch;
496 uint64_t cResume;
497 uint64_t interPD;
498 uint64_t pSwitcher;
499 uint32_t uPos;
500 uint32_t idCpu;
501#endif
502 /* CR2 is saved here for EPT syncing. */
503 uint64_t cr2;
504 struct
505 {
506 uint32_t cValidEntries;
507 uint32_t uAlignment;
508 uint32_t aField[VMCSCACHE_MAX_ENTRY];
509 uint64_t aFieldVal[VMCSCACHE_MAX_ENTRY];
510 } Write;
511 struct
512 {
513 uint32_t cValidEntries;
514 uint32_t uAlignment;
515 uint32_t aField[VMCSCACHE_MAX_ENTRY];
516 uint64_t aFieldVal[VMCSCACHE_MAX_ENTRY];
517 } Read;
518#ifdef DEBUG
519 struct
520 {
521 RTHCPHYS HCPhysCpuPage;
522 RTHCPHYS HCPhysVmcs;
523 RTGCPTR pCache;
524 RTGCPTR pCtx;
525 } TestIn;
526 struct
527 {
528 RTHCPHYS HCPhysVmcs;
529 RTGCPTR pCache;
530 RTGCPTR pCtx;
531 uint64_t eflags;
532 uint64_t cr8;
533 } TestOut;
534 struct
535 {
536 uint64_t param1;
537 uint64_t param2;
538 uint64_t param3;
539 uint64_t param4;
540 } ScratchPad;
541#endif
542} VMCSCACHE;
543/** Pointer to VMCSCACHE. */
544typedef VMCSCACHE *PVMCSCACHE;
545
546/** VMX StartVM function. */
547typedef DECLCALLBACK(int) FNHMVMXSTARTVM(RTHCUINT fResume, PCPUMCTX pCtx, PVMCSCACHE pCache, PVM pVM, PVMCPU pVCpu);
548/** Pointer to a VMX StartVM function. */
549typedef R0PTRTYPE(FNHMVMXSTARTVM *) PFNHMVMXSTARTVM;
550
551/** SVM VMRun function. */
552typedef DECLCALLBACK(int) FNHMSVMVMRUN(RTHCPHYS pVMCBHostPhys, RTHCPHYS pVMCBPhys, PCPUMCTX pCtx, PVM pVM, PVMCPU pVCpu);
553/** Pointer to a SVM VMRun function. */
554typedef R0PTRTYPE(FNHMSVMVMRUN *) PFNHMSVMVMRUN;
555
556/**
557 * HM VMCPU Instance data.
558 */
559typedef struct HMCPU
560{
561 /** Old style FPU reporting trap mask override performed (optimization) */
562 bool fFPUOldStyleOverride;
563 /** Set if we don't have to flush the TLB on VM entry. */
564 bool fResumeVM;
565 /** Set if we need to flush the TLB during the world switch. */
566 bool fForceTLBFlush;
567 /** Set when we're using VT-x or AMD-V at that moment. */
568 bool fActive;
569 /** Set when the TLB has been checked until we return from the world switch. */
570 volatile bool fCheckedTLBFlush;
571 uint8_t u8Alignment[3];
572
573 /** World switch exit counter. */
574 volatile uint32_t cWorldSwitchExits;
575 /** HM_CHANGED_* flags. */
576 uint32_t fContextUseFlags;
577 /** Id of the last cpu we were executing code on (NIL_RTCPUID for the first time) */
578 RTCPUID idLastCpu;
579 /** TLB flush count */
580 uint32_t cTlbFlushes;
581 /** Current ASID in use by the VM */
582 uint32_t uCurrentAsid;
583 uint32_t u32Alignment;
584
585 /* Host's TSC_AUX MSR (used when RDTSCP doesn't cause VM-exits). */
586 uint64_t u64HostTscAux;
587
588 struct
589 {
590 /** Physical address of the VM control structure (VMCS). */
591 RTHCPHYS HCPhysVmcs;
592 /** R0 memory object for the VM control structure (VMCS). */
593 RTR0MEMOBJ hMemObjVmcs;
594 /** Virtual address of the VM control structure (VMCS). */
595 R0PTRTYPE(void *) pvVmcs;
596 /** Ring 0 handlers for VT-x. */
597 PFNHMVMXSTARTVM pfnStartVM;
598#if HC_ARCH_BITS == 32
599 uint32_t u32Alignment1;
600#endif
601
602 /** Current VMX_VMCS32_CTRL_PIN_EXEC_CONTROLS. */
603 uint32_t u32PinCtls;
604 /** Current VMX_VMCS32_CTRL_PROC_EXEC_CONTROLS. */
605 uint32_t u32ProcCtls;
606 /** Current VMX_VMCS32_CTRL_PROC_EXEC2_CONTROLS. */
607 uint32_t u32ProcCtls2;
608 /** Current VMX_VMCS32_CTRL_EXIT_CONTROLS. */
609 uint32_t u32ExitCtls;
610 /** Current VMX_VMCS32_CTRL_ENTRY_CONTROLS. */
611 uint32_t u32EntryCtls;
612 /** Physical address of the virtual APIC page for TPR caching. */
613 RTHCPHYS HCPhysVirtApic;
614 /** R0 memory object for the virtual APIC page for TPR caching. */
615 RTR0MEMOBJ hMemObjVirtApic;
616 /** Virtual address of the virtual APIC page for TPR caching. */
617 R0PTRTYPE(uint8_t *) pbVirtApic;
618
619 /** Current CR0 mask. */
620 uint64_t cr0_mask;
621 /** Current CR4 mask. */
622 uint64_t cr4_mask;
623 /** Current exception bitmap. */
624 uint32_t u32XcptBitmap;
625 /** The updated-guest-state mask. */
626 uint32_t fUpdatedGuestState;
627 /** Current EPTP. */
628 RTHCPHYS GCPhysEPTP;
629
630 /** Physical address of the MSR bitmap. */
631 RTHCPHYS HCPhysMsrBitmap;
632 /** R0 memory object for the MSR bitmap. */
633 RTR0MEMOBJ hMemObjMsrBitmap;
634 /** Virtual address of the MSR bitmap. */
635 R0PTRTYPE(void *) pvMsrBitmap;
636
637#ifdef VBOX_WITH_AUTO_MSR_LOAD_RESTORE
638 /** Physical address of the VM-entry MSR-load and VM-exit MSR-store area (used
639 * for guest MSRs). */
640 RTHCPHYS HCPhysGuestMsr;
641 /** R0 memory object of the VM-entry MSR-load and VM-exit MSR-store area
642 * (used for guest MSRs). */
643 RTR0MEMOBJ hMemObjGuestMsr;
644 /** Virtual address of the VM-entry MSR-load and VM-exit MSR-store area (used
645 * for guest MSRs). */
646 R0PTRTYPE(void *) pvGuestMsr;
647
648 /** Physical address of the VM-exit MSR-load area (used for host MSRs). */
649 RTHCPHYS HCPhysHostMsr;
650 /** R0 memory object for the VM-exit MSR-load area (used for host MSRs). */
651 RTR0MEMOBJ hMemObjHostMsr;
652 /** Virtual address of the VM-exit MSR-load area (used for host MSRs). */
653 R0PTRTYPE(void *) pvHostMsr;
654
655 /* Number of automatically loaded/restored guest MSRs during the world switch. */
656 uint32_t cGuestMsrs;
657 uint32_t uAlignment;
658#endif /* VBOX_WITH_AUTO_MSR_LOAD_RESTORE */
659
660 /* The cached APIC-base MSR used for identifying when to map the HC physical APIC-access page. */
661 uint64_t u64MsrApicBase;
662 /* Last use TSC offset value. (cached) */
663 uint64_t u64TSCOffset;
664 /** VMCS cache. */
665 VMCSCACHE VMCSCache;
666
667 /** Real-mode emulation state. */
668 struct
669 {
670 X86DESCATTR uAttrCS;
671 X86DESCATTR uAttrDS;
672 X86DESCATTR uAttrES;
673 X86DESCATTR uAttrFS;
674 X86DESCATTR uAttrGS;
675 X86DESCATTR uAttrSS;
676 X86EFLAGS eflags;
677 uint32_t fRealOnV86Active;
678 } RealMode;
679
680 struct
681 {
682 uint64_t u64VMCSPhys;
683 uint32_t u32VMCSRevision;
684 uint32_t u32InstrError;
685 uint32_t u32ExitReason;
686 RTCPUID idEnteredCpu;
687 RTCPUID idCurrentCpu;
688 uint32_t padding;
689 } lasterror;
690
691 /** The last seen guest paging mode (by VT-x). */
692 PGMMODE enmLastSeenGuestMode;
693 /** Current guest paging mode (as seen by HMR3PagingModeChanged). */
694 PGMMODE enmCurrGuestMode;
695 /** Previous guest paging mode (as seen by HMR3PagingModeChanged). */
696 PGMMODE enmPrevGuestMode;
697 } vmx;
698
699 struct
700 {
701 /** R0 memory object for the host VM control block (VMCB). */
702 RTR0MEMOBJ hMemObjVMCBHost;
703 /** Physical address of the host VM control block (VMCB). */
704 RTHCPHYS HCPhysVMCBHost;
705 /** Virtual address of the host VM control block (VMCB). */
706 R0PTRTYPE(void *) pvVMCBHost;
707
708 /** R0 memory object for the VM control block (VMCB). */
709 RTR0MEMOBJ hMemObjVMCB;
710 /** Physical address of the VM control block (VMCB). */
711 RTHCPHYS HCPhysVMCB;
712 /** Virtual address of the VM control block (VMCB). */
713 R0PTRTYPE(void *) pvVMCB;
714
715 /** Ring 0 handlers for VT-x. */
716 PFNHMSVMVMRUN pfnVMRun;
717
718 /** R0 memory object for the MSR bitmap (8kb). */
719 RTR0MEMOBJ hMemObjMsrBitmap;
720 /** Physical address of the MSR bitmap (8kb). */
721 RTHCPHYS HCPhysMsrBitmap;
722 /** Virtual address of the MSR bitmap. */
723 R0PTRTYPE(void *) pvMsrBitmap;
724 } svm;
725
726 /** Event injection state. */
727 struct
728 {
729 uint32_t fPending;
730 uint32_t u32ErrCode;
731 uint64_t u64IntrInfo;
732 } Event;
733
734 /** IO Block emulation state. */
735 struct
736 {
737 bool fEnabled;
738 uint8_t u8Align[7];
739
740 /** RIP at the start of the io code we wish to emulate in the recompiler. */
741 RTGCPTR GCPtrFunctionEip;
742
743 uint64_t cr0;
744 } EmulateIoBlock;
745
746 struct
747 {
748 /* Pending IO operation type. */
749 HMPENDINGIO enmType;
750 uint32_t uPadding;
751 RTGCPTR GCPtrRip;
752 RTGCPTR GCPtrRipNext;
753 union
754 {
755 struct
756 {
757 unsigned uPort;
758 unsigned uAndVal;
759 unsigned cbSize;
760 } Port;
761 uint64_t aRaw[2];
762 } s;
763 } PendingIO;
764
765 /** The PAE PDPEs used with Nested Paging (only valid when
766 * VMCPU_FF_HM_UPDATE_PAE_PDPES is set). */
767 X86PDPE aPdpes[4];
768
769 /** Current shadow paging mode. */
770 PGMMODE enmShadowMode;
771
772 /** The CPU ID of the CPU currently owning the VMCS. Set in
773 * HMR0Enter and cleared in HMR0Leave. */
774 RTCPUID idEnteredCpu;
775
776 /** To keep track of pending TLB shootdown pages. (SMP guest only) */
777 struct
778 {
779 RTGCPTR aPages[HM_MAX_TLB_SHOOTDOWN_PAGES];
780 unsigned cPages;
781 } TlbShootdown;
782
783 /** For saving stack space, the disassembler state is allocated here instead of
784 * on the stack. */
785 DISCPUSTATE DisState;
786
787 uint32_t padding2[1];
788
789 STAMPROFILEADV StatEntry;
790 STAMPROFILEADV StatExit1;
791 STAMPROFILEADV StatExit2;
792#if 1 /* temporary for tracking down darwin issues. */
793 STAMPROFILEADV StatExit2Sub1;
794 STAMPROFILEADV StatExit2Sub2;
795 STAMPROFILEADV StatExit2Sub3;
796#endif
797 STAMPROFILEADV StatInGC;
798
799#if HC_ARCH_BITS == 32 && defined(VBOX_ENABLE_64_BITS_GUESTS) && !defined(VBOX_WITH_HYBRID_32BIT_KERNEL)
800 STAMPROFILEADV StatWorldSwitch3264;
801#endif
802 STAMPROFILEADV StatPoke;
803 STAMPROFILEADV StatSpinPoke;
804 STAMPROFILEADV StatSpinPokeFailed;
805
806 STAMCOUNTER StatIntInject;
807
808 STAMCOUNTER StatExitShadowNM;
809 STAMCOUNTER StatExitGuestNM;
810 STAMCOUNTER StatExitShadowPF; /* Misleading, currently used for MMIO #PFs as well. */
811 STAMCOUNTER StatExitShadowPFEM;
812 STAMCOUNTER StatExitGuestPF;
813 STAMCOUNTER StatExitGuestUD;
814 STAMCOUNTER StatExitGuestSS;
815 STAMCOUNTER StatExitGuestNP;
816 STAMCOUNTER StatExitGuestGP;
817 STAMCOUNTER StatExitGuestDE;
818 STAMCOUNTER StatExitGuestDB;
819 STAMCOUNTER StatExitGuestMF;
820 STAMCOUNTER StatExitGuestBP;
821 STAMCOUNTER StatExitGuestXF;
822 STAMCOUNTER StatExitGuestXcpUnk;
823 STAMCOUNTER StatExitInvlpg;
824 STAMCOUNTER StatExitInvd;
825 STAMCOUNTER StatExitWbinvd;
826 STAMCOUNTER StatExitPause;
827 STAMCOUNTER StatExitCpuid;
828 STAMCOUNTER StatExitRdtsc;
829 STAMCOUNTER StatExitRdtscp;
830 STAMCOUNTER StatExitRdpmc;
831 STAMCOUNTER StatExitRdrand;
832 STAMCOUNTER StatExitCli;
833 STAMCOUNTER StatExitSti;
834 STAMCOUNTER StatExitPushf;
835 STAMCOUNTER StatExitPopf;
836 STAMCOUNTER StatExitIret;
837 STAMCOUNTER StatExitInt;
838 STAMCOUNTER StatExitCRxWrite[16];
839 STAMCOUNTER StatExitCRxRead[16];
840 STAMCOUNTER StatExitDRxWrite;
841 STAMCOUNTER StatExitDRxRead;
842 STAMCOUNTER StatExitRdmsr;
843 STAMCOUNTER StatExitWrmsr;
844 STAMCOUNTER StatExitClts;
845 STAMCOUNTER StatExitXdtrAccess;
846 STAMCOUNTER StatExitHlt;
847 STAMCOUNTER StatExitMwait;
848 STAMCOUNTER StatExitMonitor;
849 STAMCOUNTER StatExitLmsw;
850 STAMCOUNTER StatExitIOWrite;
851 STAMCOUNTER StatExitIORead;
852 STAMCOUNTER StatExitIOStringWrite;
853 STAMCOUNTER StatExitIOStringRead;
854 STAMCOUNTER StatExitIntWindow;
855 STAMCOUNTER StatExitMaxResume;
856 STAMCOUNTER StatExitPreemptPending;
857 STAMCOUNTER StatExitPreemptTimer;
858 STAMCOUNTER StatExitTprBelowThreshold;
859 STAMCOUNTER StatExitTaskSwitch;
860 STAMCOUNTER StatExitMtf;
861 STAMCOUNTER StatExitApicAccess;
862 STAMCOUNTER StatIntReinject;
863 STAMCOUNTER StatPendingHostIrq;
864
865 STAMCOUNTER StatFlushPage;
866 STAMCOUNTER StatFlushPageManual;
867 STAMCOUNTER StatFlushPhysPageManual;
868 STAMCOUNTER StatFlushTlb;
869 STAMCOUNTER StatFlushTlbManual;
870 STAMCOUNTER StatFlushPageInvlpg;
871 STAMCOUNTER StatFlushTlbWorldSwitch;
872 STAMCOUNTER StatNoFlushTlbWorldSwitch;
873 STAMCOUNTER StatFlushTlbCRxChange;
874 STAMCOUNTER StatFlushAsid;
875 STAMCOUNTER StatFlushNestedPaging;
876 STAMCOUNTER StatFlushTlbInvlpga;
877 STAMCOUNTER StatTlbShootdown;
878 STAMCOUNTER StatTlbShootdownFlush;
879
880 STAMCOUNTER StatSwitchGuestIrq;
881 STAMCOUNTER StatSwitchToR3;
882
883 STAMCOUNTER StatTscOffset;
884 STAMCOUNTER StatTscIntercept;
885 STAMCOUNTER StatTscInterceptOverFlow;
886
887 STAMCOUNTER StatExitReasonNpf;
888 STAMCOUNTER StatDRxArmed;
889 STAMCOUNTER StatDRxContextSwitch;
890 STAMCOUNTER StatDRxIoCheck;
891
892 STAMCOUNTER StatLoadMinimal;
893 STAMCOUNTER StatLoadFull;
894
895#if HC_ARCH_BITS == 32 && defined(VBOX_ENABLE_64_BITS_GUESTS) && !defined(VBOX_WITH_HYBRID_32BIT_KERNEL)
896 STAMCOUNTER StatFpu64SwitchBack;
897 STAMCOUNTER StatDebug64SwitchBack;
898#endif
899
900#ifdef VBOX_WITH_STATISTICS
901 R3PTRTYPE(PSTAMCOUNTER) paStatExitReason;
902 R0PTRTYPE(PSTAMCOUNTER) paStatExitReasonR0;
903 R3PTRTYPE(PSTAMCOUNTER) paStatInjectedIrqs;
904 R0PTRTYPE(PSTAMCOUNTER) paStatInjectedIrqsR0;
905#endif
906} HMCPU;
907/** Pointer to HM VM instance data. */
908typedef HMCPU *PHMCPU;
909
910
911#ifdef IN_RING0
912
913VMMR0DECL(PHMGLOBLCPUINFO) HMR0GetCurrentCpu(void);
914VMMR0DECL(PHMGLOBLCPUINFO) HMR0GetCurrentCpuEx(RTCPUID idCpu);
915
916
917#ifdef VBOX_STRICT
918VMMR0DECL(void) HMDumpRegs(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
919VMMR0DECL(void) HMR0DumpDescriptor(PCX86DESCHC pDesc, RTSEL Sel, const char *pszMsg);
920#else
921# define HMDumpRegs(a, b ,c) do { } while (0)
922# define HMR0DumpDescriptor(a, b, c) do { } while (0)
923#endif
924
925# ifdef VBOX_WITH_KERNEL_USING_XMM
926DECLASM(int) hmR0VMXStartVMWrapXMM(RTHCUINT fResume, PCPUMCTX pCtx, PVMCSCACHE pCache, PVM pVM, PVMCPU pVCpu, PFNHMVMXSTARTVM pfnStartVM);
927DECLASM(int) hmR0SVMRunWrapXMM(RTHCPHYS pVMCBHostPhys, RTHCPHYS pVMCBPhys, PCPUMCTX pCtx, PVM pVM, PVMCPU pVCpu, PFNHMSVMVMRUN pfnVMRun);
928# endif
929
930# ifdef VBOX_WITH_HYBRID_32BIT_KERNEL
931/**
932 * Gets 64-bit GDTR and IDTR on darwin.
933 * @param pGdtr Where to store the 64-bit GDTR.
934 * @param pIdtr Where to store the 64-bit IDTR.
935 */
936DECLASM(void) hmR0Get64bitGdtrAndIdtr(PX86XDTR64 pGdtr, PX86XDTR64 pIdtr);
937
938/**
939 * Gets 64-bit CR3 on darwin.
940 * @returns CR3
941 */
942DECLASM(uint64_t) hmR0Get64bitCR3(void);
943# endif
944
945#endif /* IN_RING0 */
946
947/** @} */
948
949RT_C_DECLS_END
950
951#endif
952
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