VirtualBox

source: vbox/trunk/src/VBox/VMM/HWACCMInternal.h@ 23011

Last change on this file since 23011 was 22429, checked in by vboxsync, 15 years ago

VMM,x86.h/mac: Be more careful with X86DESCHC.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 32.3 KB
Line 
1/* $Id: HWACCMInternal.h 22429 2009-08-25 11:54:39Z vboxsync $ */
2/** @file
3 * HWACCM - Internal header file.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22#ifndef ___HWACCMInternal_h
23#define ___HWACCMInternal_h
24
25#include <VBox/cdefs.h>
26#include <VBox/types.h>
27#include <VBox/em.h>
28#include <VBox/stam.h>
29#include <VBox/dis.h>
30#include <VBox/hwaccm.h>
31#include <VBox/pgm.h>
32#include <VBox/cpum.h>
33#include <iprt/memobj.h>
34#include <iprt/cpuset.h>
35#include <iprt/mp.h>
36#include <iprt/avl.h>
37
38#if HC_ARCH_BITS == 64 || defined(VBOX_WITH_HYBRID_32BIT_KERNEL) || defined (VBOX_WITH_64_BITS_GUESTS)
39/* Enable 64 bits guest support. */
40# define VBOX_ENABLE_64_BITS_GUESTS
41#endif
42
43#define VMX_USE_CACHED_VMCS_ACCESSES
44#define HWACCM_VMX_EMULATE_REALMODE
45#define HWACCM_VTX_WITH_EPT
46#define HWACCM_VTX_WITH_VPID
47
48
49#if 0
50/* Seeing somewhat random behaviour on my Nehalem system with auto-save of guest MSRs;
51 * for some strange reason the CPU doesn't save the MSRs during the VM-exit.
52 * Clearly visible with a dual VCPU configured OpenSolaris 200906 live cd VM.
53 *
54 * Note: change the assembly files when enabling this! (remove the manual auto load/save)
55 */
56#define VBOX_WITH_AUTO_MSR_LOAD_RESTORE
57#endif
58
59RT_C_DECLS_BEGIN
60
61
62/** @defgroup grp_hwaccm_int Internal
63 * @ingroup grp_hwaccm
64 * @internal
65 * @{
66 */
67
68
69/** Maximum number of exit reason statistics counters. */
70#define MAX_EXITREASON_STAT 0x100
71#define MASK_EXITREASON_STAT 0xff
72#define MASK_INJECT_IRQ_STAT 0xff
73
74/** @name Changed flags
75 * These flags are used to keep track of which important registers that
76 * have been changed since last they were reset.
77 * @{
78 */
79#define HWACCM_CHANGED_GUEST_FPU RT_BIT(0)
80#define HWACCM_CHANGED_GUEST_CR0 RT_BIT(1)
81#define HWACCM_CHANGED_GUEST_CR3 RT_BIT(2)
82#define HWACCM_CHANGED_GUEST_CR4 RT_BIT(3)
83#define HWACCM_CHANGED_GUEST_GDTR RT_BIT(4)
84#define HWACCM_CHANGED_GUEST_IDTR RT_BIT(5)
85#define HWACCM_CHANGED_GUEST_LDTR RT_BIT(6)
86#define HWACCM_CHANGED_GUEST_TR RT_BIT(7)
87#define HWACCM_CHANGED_GUEST_SYSENTER_MSR RT_BIT(8)
88#define HWACCM_CHANGED_GUEST_SEGMENT_REGS RT_BIT(9)
89#define HWACCM_CHANGED_GUEST_DEBUG RT_BIT(10)
90#define HWACCM_CHANGED_HOST_CONTEXT RT_BIT(11)
91
92#define HWACCM_CHANGED_ALL ( HWACCM_CHANGED_GUEST_SEGMENT_REGS \
93 | HWACCM_CHANGED_GUEST_CR0 \
94 | HWACCM_CHANGED_GUEST_CR3 \
95 | HWACCM_CHANGED_GUEST_CR4 \
96 | HWACCM_CHANGED_GUEST_GDTR \
97 | HWACCM_CHANGED_GUEST_IDTR \
98 | HWACCM_CHANGED_GUEST_LDTR \
99 | HWACCM_CHANGED_GUEST_TR \
100 | HWACCM_CHANGED_GUEST_SYSENTER_MSR \
101 | HWACCM_CHANGED_GUEST_FPU \
102 | HWACCM_CHANGED_GUEST_DEBUG \
103 | HWACCM_CHANGED_HOST_CONTEXT)
104
105#define HWACCM_CHANGED_ALL_GUEST ( HWACCM_CHANGED_GUEST_SEGMENT_REGS \
106 | HWACCM_CHANGED_GUEST_CR0 \
107 | HWACCM_CHANGED_GUEST_CR3 \
108 | HWACCM_CHANGED_GUEST_CR4 \
109 | HWACCM_CHANGED_GUEST_GDTR \
110 | HWACCM_CHANGED_GUEST_IDTR \
111 | HWACCM_CHANGED_GUEST_LDTR \
112 | HWACCM_CHANGED_GUEST_TR \
113 | HWACCM_CHANGED_GUEST_SYSENTER_MSR \
114 | HWACCM_CHANGED_GUEST_DEBUG \
115 | HWACCM_CHANGED_GUEST_FPU)
116
117/** @} */
118
119/** @name Intercepted traps
120 * Traps that need to be intercepted so we can correctly dispatch them to the guest if required.
121 * Currently #NM and #PF only
122 */
123#ifdef VBOX_STRICT
124#define HWACCM_VMX_TRAP_MASK RT_BIT(X86_XCPT_DE) | RT_BIT(X86_XCPT_NM) | RT_BIT(X86_XCPT_PF) | RT_BIT(X86_XCPT_UD) | RT_BIT(X86_XCPT_NP) | RT_BIT(X86_XCPT_SS) | RT_BIT(X86_XCPT_GP) | RT_BIT(X86_XCPT_MF)
125#define HWACCM_SVM_TRAP_MASK HWACCM_VMX_TRAP_MASK
126#else
127#define HWACCM_VMX_TRAP_MASK RT_BIT(X86_XCPT_NM) | RT_BIT(X86_XCPT_PF)
128#define HWACCM_SVM_TRAP_MASK RT_BIT(X86_XCPT_NM) | RT_BIT(X86_XCPT_PF)
129#endif
130/* All exceptions have to be intercept in emulated real-mode (minues NM & PF as they are always intercepted. */
131#define HWACCM_VMX_TRAP_MASK_REALMODE RT_BIT(X86_XCPT_DE) | RT_BIT(X86_XCPT_DB) | RT_BIT(X86_XCPT_NMI) | RT_BIT(X86_XCPT_BP) | RT_BIT(X86_XCPT_OF) | RT_BIT(X86_XCPT_BR) | RT_BIT(X86_XCPT_UD) | RT_BIT(X86_XCPT_DF) | RT_BIT(X86_XCPT_CO_SEG_OVERRUN) | RT_BIT(X86_XCPT_TS) | RT_BIT(X86_XCPT_NP) | RT_BIT(X86_XCPT_SS) | RT_BIT(X86_XCPT_GP) | RT_BIT(X86_XCPT_MF) | RT_BIT(X86_XCPT_AC) | RT_BIT(X86_XCPT_MC) | RT_BIT(X86_XCPT_XF)
132/** @} */
133
134
135/** Maximum number of page flushes we are willing to remember before considering a full TLB flush. */
136#define HWACCM_MAX_TLB_SHOOTDOWN_PAGES 8
137
138/** Size for the EPT identity page table (1024 4 MB pages to cover the entire address space). */
139#define HWACCM_EPT_IDENTITY_PG_TABLE_SIZE PAGE_SIZE
140/** Size of the TSS structure + 2 pages for the IO bitmap + end byte. */
141#define HWACCM_VTX_TSS_SIZE (sizeof(VBOXTSS) + 2*PAGE_SIZE + 1)
142/** Total guest mapped memory needed. */
143#define HWACCM_VTX_TOTAL_DEVHEAP_MEM (HWACCM_EPT_IDENTITY_PG_TABLE_SIZE + HWACCM_VTX_TSS_SIZE)
144
145/* Enable for TPR guest patching. */
146#define VBOX_HWACCM_WITH_GUEST_PATCHING
147
148/** HWACCM SSM version
149 */
150#ifdef VBOX_HWACCM_WITH_GUEST_PATCHING
151#define HWACCM_SSM_VERSION 5
152#define HWACCM_SSM_VERSION_NO_PATCHING 4
153#else
154#define HWACCM_SSM_VERSION 4
155#define HWACCM_SSM_VERSION_NO_PATCHING 4
156#endif
157#define HWACCM_SSM_VERSION_2_0_X 3
158
159/* Per-cpu information. (host) */
160typedef struct
161{
162 RTCPUID idCpu;
163
164 RTR0MEMOBJ pMemObj;
165 /* Current ASID (AMD-V)/VPID (Intel) */
166 uint32_t uCurrentASID;
167 /* TLB flush count */
168 uint32_t cTLBFlushes;
169
170 /* Set the first time a cpu is used to make sure we start with a clean TLB. */
171 bool fFlushTLB;
172
173 /** Configured for VT-x or AMD-V. */
174 bool fConfigured;
175
176 /** In use by our code. (for power suspend) */
177 volatile bool fInUse;
178} HWACCM_CPUINFO;
179typedef HWACCM_CPUINFO *PHWACCM_CPUINFO;
180
181/* VT-x capability qword. */
182typedef union
183{
184 struct
185 {
186 uint32_t disallowed0;
187 uint32_t allowed1;
188 } n;
189 uint64_t u;
190} VMX_CAPABILITY;
191
192typedef enum
193{
194 HWACCMPENDINGIO_INVALID = 0,
195 HWACCMPENDINGIO_PORT_READ,
196 HWACCMPENDINGIO_PORT_WRITE,
197 HWACCMPENDINGIO_STRING_READ,
198 HWACCMPENDINGIO_STRING_WRITE,
199 /** The usual 32-bit paranoia. */
200 HWACCMPENDINGIO_32BIT_HACK = 0x7fffffff
201} HWACCMPENDINGIO;
202
203
204typedef enum
205{
206 HWACCMTPRINSTR_INVALID,
207 HWACCMTPRINSTR_READ,
208 HWACCMTPRINSTR_READ_SHR4,
209 HWACCMTPRINSTR_WRITE_REG,
210 HWACCMTPRINSTR_WRITE_IMM,
211 HWACCMTPRINSTR_JUMP_REPLACEMENT,
212 /** The usual 32-bit paranoia. */
213 HWACCMTPRINSTR_32BIT_HACK = 0x7fffffff
214} HWACCMTPRINSTR;
215
216typedef struct
217{
218 /** The key is the address of patched instruction. (32 bits GC ptr) */
219 AVLOU32NODECORE Core;
220 /** Original opcode. */
221 uint8_t aOpcode[16];
222 /** Instruction size. */
223 uint32_t cbOp;
224 /** Replacement opcode. */
225 uint8_t aNewOpcode[16];
226 /** Replacement instruction size. */
227 uint32_t cbNewOp;
228 /** Instruction type. */
229 HWACCMTPRINSTR enmType;
230 /** Source operand. */
231 uint32_t uSrcOperand;
232 /** Destination operand. */
233 uint32_t uDstOperand;
234 /** Number of times the instruction caused a fault. */
235 uint32_t cFaults;
236 /** Patch address of the jump replacement. */
237 RTGCPTR32 pJumpTarget;
238} HWACCMTPRPATCH;
239/** Pointer to HWACCMTPRPATCH. */
240typedef HWACCMTPRPATCH *PHWACCMTPRPATCH;
241
242/**
243 * Switcher function, HC to RC.
244 *
245 * @param pVM The VM handle.
246 * @returns Return code indicating the action to take.
247 */
248typedef DECLASMTYPE(int) FNHWACCMSWITCHERHC(PVM pVM);
249/** Pointer to switcher function. */
250typedef FNHWACCMSWITCHERHC *PFNHWACCMSWITCHERHC;
251
252/**
253 * HWACCM VM Instance data.
254 * Changes to this must checked against the padding of the cfgm union in VM!
255 */
256typedef struct HWACCM
257{
258 /** Set when we've initialized VMX or SVM. */
259 bool fInitialized;
260
261 /** Set when hardware acceleration is allowed. */
262 bool fAllowed;
263
264 /** Set if nested paging is enabled. */
265 bool fNestedPaging;
266
267 /** Set if nested paging is allowed. */
268 bool fAllowNestedPaging;
269
270 /** Set if we can support 64-bit guests or not. */
271 bool fAllow64BitGuests;
272
273 /** Set if an IO-APIC is configured for this VM. */
274 bool fHasIoApic;
275
276 /** Set when TPR patching is allowed. */
277 bool fTRPPatchingAllowed;
278
279 /** Explicit alignment padding to make 32-bit gcc align u64RegisterMask
280 * naturally. */
281 bool padding[1];
282
283 /** And mask for copying register contents. */
284 uint64_t u64RegisterMask;
285
286 /** Maximum ASID allowed. */
287 RTUINT uMaxASID;
288
289 /** The maximum number of resumes loops allowed in ring-0 (safety precaution).
290 * This number is set much higher when RTThreadPreemptIsPending is reliable. */
291 uint32_t cMaxResumeLoops;
292
293 /** Guest allocated memory for patching purposes. */
294 RTGCPTR pGuestPatchMem;
295 /** Current free pointer inside the patch block. */
296 RTGCPTR pFreeGuestPatchMem;
297 /** Size of the guest patch memory block. */
298 uint32_t cbGuestPatchMem;
299 uint32_t uPadding1;
300
301#if HC_ARCH_BITS == 32 && defined(VBOX_ENABLE_64_BITS_GUESTS) && !defined(VBOX_WITH_HYBRID_32BIT_KERNEL)
302 /** 32 to 64 bits switcher entrypoint. */
303 R0PTRTYPE(PFNHWACCMSWITCHERHC) pfnHost32ToGuest64R0;
304
305 /* AMD-V 64 bits vmrun handler */
306 RTRCPTR pfnSVMGCVMRun64;
307
308 /* VT-x 64 bits vmlaunch handler */
309 RTRCPTR pfnVMXGCStartVM64;
310
311 /* RC handler to setup the 64 bits FPU state. */
312 RTRCPTR pfnSaveGuestFPU64;
313
314 /* RC handler to setup the 64 bits debug state. */
315 RTRCPTR pfnSaveGuestDebug64;
316
317 /* Test handler */
318 RTRCPTR pfnTest64;
319
320 RTRCPTR uAlignment[2];
321/*#elif defined(VBOX_WITH_HYBRID_32BIT_KERNEL)
322 uint32_t u32Alignment[1]; */
323#endif
324
325 struct
326 {
327 /** Set by the ring-0 driver to indicate VMX is supported by the CPU. */
328 bool fSupported;
329
330 /** Set when we've enabled VMX. */
331 bool fEnabled;
332
333 /** Set if VPID is supported. */
334 bool fVPID;
335
336 /** Set if VT-x VPID is allowed. */
337 bool fAllowVPID;
338
339 /** Virtual address of the TSS page used for real mode emulation. */
340 R3PTRTYPE(PVBOXTSS) pRealModeTSS;
341
342 /** Virtual address of the identity page table used for real mode and protected mode without paging emulation in EPT mode. */
343 R3PTRTYPE(PX86PD) pNonPagingModeEPTPageTable;
344
345 /** R0 memory object for the APIC physical page (serves for filtering accesses). */
346 RTR0MEMOBJ pMemObjAPIC;
347 /** Physical address of the APIC physical page (serves for filtering accesses). */
348 RTHCPHYS pAPICPhys;
349 /** Virtual address of the APIC physical page (serves for filtering accesses). */
350 R0PTRTYPE(uint8_t *) pAPIC;
351
352 /** R0 memory object for the MSR entry load page (guest MSRs). */
353 RTR0MEMOBJ pMemObjMSREntryLoad;
354 /** Physical address of the MSR entry load page (guest MSRs). */
355 RTHCPHYS pMSREntryLoadPhys;
356 /** Virtual address of the MSR entry load page (guest MSRs). */
357 R0PTRTYPE(uint8_t *) pMSREntryLoad;
358
359#ifdef VBOX_WITH_CRASHDUMP_MAGIC
360 RTR0MEMOBJ pMemObjScratch;
361 RTHCPHYS pScratchPhys;
362 R0PTRTYPE(uint8_t *) pScratch;
363#endif
364 /** R0 memory object for the MSR exit store page (guest MSRs). */
365 RTR0MEMOBJ pMemObjMSRExitStore;
366 /** Physical address of the MSR exit store page (guest MSRs). */
367 RTHCPHYS pMSRExitStorePhys;
368 /** Virtual address of the MSR exit store page (guest MSRs). */
369 R0PTRTYPE(uint8_t *) pMSRExitStore;
370
371 /** R0 memory object for the MSR exit load page (host MSRs). */
372 RTR0MEMOBJ pMemObjMSRExitLoad;
373 /** Physical address of the MSR exit load page (host MSRs). */
374 RTHCPHYS pMSRExitLoadPhys;
375 /** Virtual address of the MSR exit load page (host MSRs). */
376 R0PTRTYPE(uint8_t *) pMSRExitLoad;
377
378 /** Ring 0 handlers for VT-x. */
379 DECLR0CALLBACKMEMBER(void, pfnSetupTaggedTLB, (PVM pVM, PVMCPU pVCpu));
380
381 /** Host CR4 value (set by ring-0 VMX init) */
382 uint64_t hostCR4;
383
384 /** VMX MSR values */
385 struct
386 {
387 uint64_t feature_ctrl;
388 uint64_t vmx_basic_info;
389 VMX_CAPABILITY vmx_pin_ctls;
390 VMX_CAPABILITY vmx_proc_ctls;
391 VMX_CAPABILITY vmx_proc_ctls2;
392 VMX_CAPABILITY vmx_exit;
393 VMX_CAPABILITY vmx_entry;
394 uint64_t vmx_misc;
395 uint64_t vmx_cr0_fixed0;
396 uint64_t vmx_cr0_fixed1;
397 uint64_t vmx_cr4_fixed0;
398 uint64_t vmx_cr4_fixed1;
399 uint64_t vmx_vmcs_enum;
400 uint64_t vmx_eptcaps;
401 } msr;
402
403 /** Flush types for invept & invvpid; they depend on capabilities. */
404 VMX_FLUSH enmFlushPage;
405 VMX_FLUSH enmFlushContext;
406 } vmx;
407
408 struct
409 {
410 /** Set by the ring-0 driver to indicate SVM is supported by the CPU. */
411 bool fSupported;
412 /** Set when we've enabled SVM. */
413 bool fEnabled;
414 /** Set if erratum 170 affects the AMD cpu. */
415 bool fAlwaysFlushTLB;
416 /** Set when TPR patching is active. */
417 bool fTPRPatchingActive;
418
419 /** R0 memory object for the IO bitmap (12kb). */
420 RTR0MEMOBJ pMemObjIOBitmap;
421 /** Physical address of the IO bitmap (12kb). */
422 RTHCPHYS pIOBitmapPhys;
423 /** Virtual address of the IO bitmap. */
424 R0PTRTYPE(void *) pIOBitmap;
425
426 /** SVM revision. */
427 uint32_t u32Rev;
428
429 /** SVM feature bits from cpuid 0x8000000a */
430 uint32_t u32Features;
431
432 /**
433 * AVL tree with all patches (active or disabled) sorted by guest instruction address
434 */
435 AVLOU32TREE PatchTree;
436 uint32_t cPatches;
437 HWACCMTPRPATCH aPatches[64];
438 } svm;
439
440 struct
441 {
442 uint32_t u32AMDFeatureECX;
443 uint32_t u32AMDFeatureEDX;
444 } cpuid;
445
446 /** Saved error from detection */
447 int32_t lLastError;
448
449 /** HWACCMR0Init was run */
450 bool fHWACCMR0Init;
451 bool u8Alignment[7];
452
453 STAMCOUNTER StatTPRPatchSuccess;
454 STAMCOUNTER StatTPRPatchFailure;
455 STAMCOUNTER StatTPRReplaceSuccess;
456 STAMCOUNTER StatTPRReplaceFailure;
457} HWACCM;
458/** Pointer to HWACCM VM instance data. */
459typedef HWACCM *PHWACCM;
460
461/* Maximum number of cached entries. */
462#define VMCSCACHE_MAX_ENTRY 128
463
464/* Structure for storing read and write VMCS actions. */
465typedef struct VMCSCACHE
466{
467#ifdef VBOX_WITH_CRASHDUMP_MAGIC
468 /* Magic marker for searching in crash dumps. */
469 uint8_t aMagic[16];
470 uint64_t uMagic;
471 uint64_t u64TimeEntry;
472 uint64_t u64TimeSwitch;
473 uint64_t cResume;
474 uint64_t interPD;
475 uint64_t pSwitcher;
476 uint32_t uPos;
477 uint32_t idCpu;
478#endif
479 /* CR2 is saved here for EPT syncing. */
480 uint64_t cr2;
481 struct
482 {
483 uint32_t cValidEntries;
484 uint32_t uAlignment;
485 uint32_t aField[VMCSCACHE_MAX_ENTRY];
486 uint64_t aFieldVal[VMCSCACHE_MAX_ENTRY];
487 } Write;
488 struct
489 {
490 uint32_t cValidEntries;
491 uint32_t uAlignment;
492 uint32_t aField[VMCSCACHE_MAX_ENTRY];
493 uint64_t aFieldVal[VMCSCACHE_MAX_ENTRY];
494 } Read;
495#ifdef DEBUG
496 struct
497 {
498 RTHCPHYS pPageCpuPhys;
499 RTHCPHYS pVMCSPhys;
500 RTGCPTR pCache;
501 RTGCPTR pCtx;
502 } TestIn;
503 struct
504 {
505 RTHCPHYS pVMCSPhys;
506 RTGCPTR pCache;
507 RTGCPTR pCtx;
508 uint64_t eflags;
509 uint64_t cr8;
510 } TestOut;
511 struct
512 {
513 uint64_t param1;
514 uint64_t param2;
515 uint64_t param3;
516 uint64_t param4;
517 } ScratchPad;
518#endif
519} VMCSCACHE;
520/** Pointer to VMCSCACHE. */
521typedef VMCSCACHE *PVMCSCACHE;
522
523/** VMX StartVM function. */
524typedef DECLCALLBACK(int) FNHWACCMVMXSTARTVM(RTHCUINT fResume, PCPUMCTX pCtx, PVMCSCACHE pCache, PVM pVM, PVMCPU pVCpu);
525/** Pointer to a VMX StartVM function. */
526typedef R0PTRTYPE(FNHWACCMVMXSTARTVM *) PFNHWACCMVMXSTARTVM;
527
528/** SVM VMRun function. */
529typedef DECLCALLBACK(int) FNHWACCMSVMVMRUN(RTHCPHYS pVMCBHostPhys, RTHCPHYS pVMCBPhys, PCPUMCTX pCtx, PVM pVM, PVMCPU pVCpu);
530/** Pointer to a SVM VMRun function. */
531typedef R0PTRTYPE(FNHWACCMSVMVMRUN *) PFNHWACCMSVMVMRUN;
532
533/**
534 * HWACCM VMCPU Instance data.
535 */
536typedef struct HWACCMCPU
537{
538 /** Old style FPU reporting trap mask override performed (optimization) */
539 bool fFPUOldStyleOverride;
540
541 /** Set if we don't have to flush the TLB on VM entry. */
542 bool fResumeVM;
543
544 /** Set if we need to flush the TLB during the world switch. */
545 bool fForceTLBFlush;
546
547 /** Set when we're using VT-x or AMD-V at that moment. */
548 bool fActive;
549
550 /** HWACCM_CHANGED_* flags. */
551 RTUINT fContextUseFlags;
552
553 /* Id of the last cpu we were executing code on (NIL_RTCPUID for the first time) */
554 RTCPUID idLastCpu;
555
556 /* TLB flush count */
557 RTUINT cTLBFlushes;
558
559 /* Current ASID in use by the VM */
560 RTUINT uCurrentASID;
561
562 struct
563 {
564 /** Physical address of the VM control structure (VMCS). */
565 RTHCPHYS pVMCSPhys;
566 /** R0 memory object for the VM control structure (VMCS). */
567 RTR0MEMOBJ pMemObjVMCS;
568 /** Virtual address of the VM control structure (VMCS). */
569 R0PTRTYPE(void *) pVMCS;
570
571 /** Ring 0 handlers for VT-x. */
572 PFNHWACCMVMXSTARTVM pfnStartVM;
573
574 /** Current VMX_VMCS_CTRL_PROC_EXEC_CONTROLS. */
575 uint64_t proc_ctls;
576
577 /** Current VMX_VMCS_CTRL_PROC_EXEC2_CONTROLS. */
578 uint64_t proc_ctls2;
579
580 /** Physical address of the virtual APIC page for TPR caching. */
581 RTHCPHYS pVAPICPhys;
582 /** R0 memory object for the virtual APIC page for TPR caching. */
583 RTR0MEMOBJ pMemObjVAPIC;
584 /** Virtual address of the virtual APIC page for TPR caching. */
585 R0PTRTYPE(uint8_t *) pVAPIC;
586
587 /** Current CR0 mask. */
588 uint64_t cr0_mask;
589 /** Current CR4 mask. */
590 uint64_t cr4_mask;
591
592 /** Current EPTP. */
593 RTHCPHYS GCPhysEPTP;
594
595 /** Physical address of the MSR bitmap (1 page). */
596 RTHCPHYS pMSRBitmapPhys;
597 /** R0 memory object for the MSR bitmap (1 page). */
598 RTR0MEMOBJ pMemObjMSRBitmap;
599 /** Virtual address of the MSR bitmap (1 page). */
600 R0PTRTYPE(uint8_t *) pMSRBitmap;
601
602#ifdef VBOX_WITH_AUTO_MSR_LOAD_RESTORE
603 /** Physical address of the guest MSR load area (1 page). */
604 RTHCPHYS pGuestMSRPhys;
605 /** R0 memory object for the guest MSR load area (1 page). */
606 RTR0MEMOBJ pMemObjGuestMSR;
607 /** Virtual address of the guest MSR load area (1 page). */
608 R0PTRTYPE(uint8_t *) pGuestMSR;
609
610 /** Physical address of the MSR load area (1 page). */
611 RTHCPHYS pHostMSRPhys;
612 /** R0 memory object for the MSR load area (1 page). */
613 RTR0MEMOBJ pMemObjHostMSR;
614 /** Virtual address of the MSR load area (1 page). */
615 R0PTRTYPE(uint8_t *) pHostMSR;
616#endif /* VBOX_WITH_AUTO_MSR_LOAD_RESTORE */
617
618 /* Number of automatically loaded/restored MSRs. */
619 uint32_t cCachedMSRs;
620 uint32_t uAlignement;
621
622 /* Last use TSC offset value. (cached) */
623 uint64_t u64TSCOffset;
624
625 /** VMCS cache. */
626 VMCSCACHE VMCSCache;
627
628 /** Real-mode emulation state. */
629 struct
630 {
631 X86EFLAGS eflags;
632 uint32_t fValid;
633 } RealMode;
634
635 struct
636 {
637 uint64_t u64VMCSPhys;
638 uint32_t ulVMCSRevision;
639 uint32_t ulInstrError;
640 uint32_t ulExitReason;
641 RTCPUID idEnteredCpu;
642 RTCPUID idCurrentCpu;
643 uint32_t padding;
644 } lasterror;
645
646 /** The last seen guest paging mode (by VT-x). */
647 PGMMODE enmLastSeenGuestMode;
648 /** Current guest paging mode (as seen by HWACCMR3PagingModeChanged). */
649 PGMMODE enmCurrGuestMode;
650 /** Previous guest paging mode (as seen by HWACCMR3PagingModeChanged). */
651 PGMMODE enmPrevGuestMode;
652 } vmx;
653
654 struct
655 {
656 /** R0 memory object for the host VM control block (VMCB). */
657 RTR0MEMOBJ pMemObjVMCBHost;
658 /** Physical address of the host VM control block (VMCB). */
659 RTHCPHYS pVMCBHostPhys;
660 /** Virtual address of the host VM control block (VMCB). */
661 R0PTRTYPE(void *) pVMCBHost;
662
663 /** R0 memory object for the VM control block (VMCB). */
664 RTR0MEMOBJ pMemObjVMCB;
665 /** Physical address of the VM control block (VMCB). */
666 RTHCPHYS pVMCBPhys;
667 /** Virtual address of the VM control block (VMCB). */
668 R0PTRTYPE(void *) pVMCB;
669
670 /** Ring 0 handlers for VT-x. */
671 PFNHWACCMSVMVMRUN pfnVMRun;
672
673 /** R0 memory object for the MSR bitmap (8kb). */
674 RTR0MEMOBJ pMemObjMSRBitmap;
675 /** Physical address of the MSR bitmap (8kb). */
676 RTHCPHYS pMSRBitmapPhys;
677 /** Virtual address of the MSR bitmap. */
678 R0PTRTYPE(void *) pMSRBitmap;
679 } svm;
680
681 /** Event injection state. */
682 struct
683 {
684 uint32_t fPending;
685 uint32_t errCode;
686 uint64_t intInfo;
687 } Event;
688
689 /** IO Block emulation state. */
690 struct
691 {
692 bool fEnabled;
693 uint8_t u8Align[7];
694
695 /** RIP at the start of the io code we wish to emulate in the recompiler. */
696 RTGCPTR GCPtrFunctionEip;
697
698 uint64_t cr0;
699 } EmulateIoBlock;
700
701 struct
702 {
703 /* Pending IO operation type. */
704 HWACCMPENDINGIO enmType;
705 uint32_t uPadding;
706 RTGCPTR GCPtrRip;
707 RTGCPTR GCPtrRipNext;
708 union
709 {
710 struct
711 {
712 unsigned uPort;
713 unsigned uAndVal;
714 unsigned cbSize;
715 } Port;
716 uint64_t aRaw[2];
717 } s;
718 } PendingIO;
719
720 /** Currenty shadow paging mode. */
721 PGMMODE enmShadowMode;
722
723 /** The CPU ID of the CPU currently owning the VMCS. Set in
724 * HWACCMR0Enter and cleared in HWACCMR0Leave. */
725 RTCPUID idEnteredCpu;
726
727 /** To keep track of pending TLB shootdown pages. (SMP guest only) */
728 struct
729 {
730 RTGCPTR aPages[HWACCM_MAX_TLB_SHOOTDOWN_PAGES];
731 unsigned cPages;
732 } TlbShootdown;
733
734 /** For saving stack space, the disassembler state is allocated here instead of
735 * on the stack.
736 * @note The DISCPUSTATE structure is not R3/R0/RZ clean! */
737 union
738 {
739 /** The disassembler scratch space. */
740 DISCPUSTATE DisState;
741 /** Padding. */
742 uint8_t abDisStatePadding[DISCPUSTATE_PADDING_SIZE];
743 };
744
745 RTUINT padding2[1];
746
747 STAMPROFILEADV StatEntry;
748 STAMPROFILEADV StatExit1;
749 STAMPROFILEADV StatExit2;
750#if 1 /* temporary for tracking down darwin issues. */
751 STAMPROFILEADV StatExit2Sub1;
752 STAMPROFILEADV StatExit2Sub2;
753 STAMPROFILEADV StatExit2Sub3;
754#endif
755 STAMPROFILEADV StatInGC;
756
757#if HC_ARCH_BITS == 32 && defined(VBOX_ENABLE_64_BITS_GUESTS) && !defined(VBOX_WITH_HYBRID_32BIT_KERNEL)
758 STAMPROFILEADV StatWorldSwitch3264;
759#endif
760
761 STAMCOUNTER StatIntInject;
762
763 STAMCOUNTER StatExitShadowNM;
764 STAMCOUNTER StatExitGuestNM;
765 STAMCOUNTER StatExitShadowPF;
766 STAMCOUNTER StatExitGuestPF;
767 STAMCOUNTER StatExitGuestUD;
768 STAMCOUNTER StatExitGuestSS;
769 STAMCOUNTER StatExitGuestNP;
770 STAMCOUNTER StatExitGuestGP;
771 STAMCOUNTER StatExitGuestDE;
772 STAMCOUNTER StatExitGuestDB;
773 STAMCOUNTER StatExitGuestMF;
774 STAMCOUNTER StatExitInvpg;
775 STAMCOUNTER StatExitInvd;
776 STAMCOUNTER StatExitCpuid;
777 STAMCOUNTER StatExitRdtsc;
778 STAMCOUNTER StatExitRdpmc;
779 STAMCOUNTER StatExitCli;
780 STAMCOUNTER StatExitSti;
781 STAMCOUNTER StatExitPushf;
782 STAMCOUNTER StatExitPopf;
783 STAMCOUNTER StatExitIret;
784 STAMCOUNTER StatExitInt;
785 STAMCOUNTER StatExitCRxWrite[16];
786 STAMCOUNTER StatExitCRxRead[16];
787 STAMCOUNTER StatExitDRxWrite;
788 STAMCOUNTER StatExitDRxRead;
789 STAMCOUNTER StatExitRdmsr;
790 STAMCOUNTER StatExitWrmsr;
791 STAMCOUNTER StatExitCLTS;
792 STAMCOUNTER StatExitHlt;
793 STAMCOUNTER StatExitMwait;
794 STAMCOUNTER StatExitLMSW;
795 STAMCOUNTER StatExitIOWrite;
796 STAMCOUNTER StatExitIORead;
797 STAMCOUNTER StatExitIOStringWrite;
798 STAMCOUNTER StatExitIOStringRead;
799 STAMCOUNTER StatExitIrqWindow;
800 STAMCOUNTER StatExitMaxResume;
801 STAMCOUNTER StatExitPreemptPending;
802 STAMCOUNTER StatIntReinject;
803 STAMCOUNTER StatPendingHostIrq;
804
805 STAMCOUNTER StatFlushPageManual;
806 STAMCOUNTER StatFlushPhysPageManual;
807 STAMCOUNTER StatFlushTLBManual;
808 STAMCOUNTER StatFlushPageInvlpg;
809 STAMCOUNTER StatFlushTLBWorldSwitch;
810 STAMCOUNTER StatNoFlushTLBWorldSwitch;
811 STAMCOUNTER StatFlushTLBCRxChange;
812 STAMCOUNTER StatFlushASID;
813 STAMCOUNTER StatFlushTLBInvlpga;
814 STAMCOUNTER StatTlbShootdown;
815 STAMCOUNTER StatTlbShootdownFlush;
816
817 STAMCOUNTER StatSwitchGuestIrq;
818 STAMCOUNTER StatSwitchToR3;
819
820 STAMCOUNTER StatTSCOffset;
821 STAMCOUNTER StatTSCIntercept;
822 STAMCOUNTER StatTSCInterceptOverFlow;
823
824 STAMCOUNTER StatExitReasonNPF;
825 STAMCOUNTER StatDRxArmed;
826 STAMCOUNTER StatDRxContextSwitch;
827 STAMCOUNTER StatDRxIOCheck;
828
829
830#ifdef VBOX_WITH_STATISTICS
831 R3PTRTYPE(PSTAMCOUNTER) paStatExitReason;
832 R0PTRTYPE(PSTAMCOUNTER) paStatExitReasonR0;
833 R3PTRTYPE(PSTAMCOUNTER) paStatInjectedIrqs;
834 R0PTRTYPE(PSTAMCOUNTER) paStatInjectedIrqsR0;
835#endif
836} HWACCMCPU;
837/** Pointer to HWACCM VM instance data. */
838typedef HWACCMCPU *PHWACCMCPU;
839
840
841#ifdef IN_RING0
842
843VMMR0DECL(PHWACCM_CPUINFO) HWACCMR0GetCurrentCpu();
844VMMR0DECL(PHWACCM_CPUINFO) HWACCMR0GetCurrentCpuEx(RTCPUID idCpu);
845
846
847#ifdef VBOX_STRICT
848VMMR0DECL(void) HWACCMDumpRegs(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
849VMMR0DECL(void) HWACCMR0DumpDescriptor(PCX86DESCHC pDesc, RTSEL Sel, const char *pszMsg);
850#else
851# define HWACCMDumpRegs(a, b ,c) do { } while (0)
852# define HWACCMR0DumpDescriptor(a, b, c) do { } while (0)
853#endif
854
855/* Dummy callback handlers. */
856VMMR0DECL(int) HWACCMR0DummyEnter(PVM pVM, PVMCPU pVCpu, PHWACCM_CPUINFO pCpu);
857VMMR0DECL(int) HWACCMR0DummyLeave(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
858VMMR0DECL(int) HWACCMR0DummyEnableCpu(PHWACCM_CPUINFO pCpu, PVM pVM, void *pvPageCpu, RTHCPHYS pPageCpuPhys);
859VMMR0DECL(int) HWACCMR0DummyDisableCpu(PHWACCM_CPUINFO pCpu, void *pvPageCpu, RTHCPHYS pPageCpuPhys);
860VMMR0DECL(int) HWACCMR0DummyInitVM(PVM pVM);
861VMMR0DECL(int) HWACCMR0DummyTermVM(PVM pVM);
862VMMR0DECL(int) HWACCMR0DummySetupVM(PVM pVM);
863VMMR0DECL(int) HWACCMR0DummyRunGuestCode(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
864VMMR0DECL(int) HWACCMR0DummySaveHostState(PVM pVM, PVMCPU pVCpu);
865VMMR0DECL(int) HWACCMR0DummyLoadGuestState(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
866
867# ifdef VBOX_WITH_KERNEL_USING_XMM
868DECLASM(int) hwaccmR0VMXStartVMWrapXMM(RTHCUINT fResume, PCPUMCTX pCtx, PVMCSCACHE pCache, PVM pVM, PVMCPU pVCpu, PFNHWACCMVMXSTARTVM pfnStartVM);
869DECLASM(int) hwaccmR0SVMRunWrapXMM(RTHCPHYS pVMCBHostPhys, RTHCPHYS pVMCBPhys, PCPUMCTX pCtx, PVM pVM, PVMCPU pVCpu, PFNHWACCMSVMVMRUN pfnVMRun);
870# endif
871
872# ifdef VBOX_WITH_HYBRID_32BIT_KERNEL
873/**
874 * Gets 64-bit GDTR and IDTR on darwin.
875 * @param pGdtr Where to store the 64-bit GDTR.
876 * @param pIdtr Where to store the 64-bit IDTR.
877 */
878DECLASM(void) hwaccmR0Get64bitGDTRandIDTR(PX86XDTR64 pGdtr, PX86XDTR64 pIdtr);
879
880/**
881 * Gets 64-bit CR3 on darwin.
882 * @returns CR3
883 */
884DECLASM(uint64_t) hwaccmR0Get64bitCR3(void);
885# endif
886
887#endif /* IN_RING0 */
888
889/** @} */
890
891RT_C_DECLS_END
892
893#endif
894
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