VirtualBox

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

Last change on this file since 23454 was 23387, checked in by vboxsync, 15 years ago

32-bit Linux build fix

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 32.8 KB
Line 
1/* $Id: HWACCMInternal.h 23387 2009-09-28 14:35:51Z 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 /** Set when the TLB has been checked until we return from the world switch. */
551 volatile uint8_t fCheckedTLBFlush;
552 uint8_t bAlignment[3];
553
554 /** HWACCM_CHANGED_* flags. */
555 RTUINT fContextUseFlags;
556
557 /** Id of the last cpu we were executing code on (NIL_RTCPUID for the first time) */
558 RTCPUID idLastCpu;
559
560 /** TLB flush count */
561 RTUINT cTLBFlushes;
562
563 /** Current ASID in use by the VM */
564 RTUINT uCurrentASID;
565
566 /** World switch exit counter. */
567 volatile uint32_t cWorldSwitchExit;
568 uint32_t u32Alignment;
569
570 struct
571 {
572 /** Physical address of the VM control structure (VMCS). */
573 RTHCPHYS pVMCSPhys;
574 /** R0 memory object for the VM control structure (VMCS). */
575 RTR0MEMOBJ pMemObjVMCS;
576 /** Virtual address of the VM control structure (VMCS). */
577 R0PTRTYPE(void *) pVMCS;
578
579 /** Ring 0 handlers for VT-x. */
580 PFNHWACCMVMXSTARTVM pfnStartVM;
581
582#if HC_ARCH_BITS == 32
583 uint32_t u32Alignment;
584#endif
585
586 /** Current VMX_VMCS_CTRL_PROC_EXEC_CONTROLS. */
587 uint64_t proc_ctls;
588
589 /** Current VMX_VMCS_CTRL_PROC_EXEC2_CONTROLS. */
590 uint64_t proc_ctls2;
591
592 /** Physical address of the virtual APIC page for TPR caching. */
593 RTHCPHYS pVAPICPhys;
594 /** R0 memory object for the virtual APIC page for TPR caching. */
595 RTR0MEMOBJ pMemObjVAPIC;
596 /** Virtual address of the virtual APIC page for TPR caching. */
597 R0PTRTYPE(uint8_t *) pVAPIC;
598
599 /** Current CR0 mask. */
600 uint64_t cr0_mask;
601 /** Current CR4 mask. */
602 uint64_t cr4_mask;
603
604 /** Current EPTP. */
605 RTHCPHYS GCPhysEPTP;
606
607 /** Physical address of the MSR bitmap (1 page). */
608 RTHCPHYS pMSRBitmapPhys;
609 /** R0 memory object for the MSR bitmap (1 page). */
610 RTR0MEMOBJ pMemObjMSRBitmap;
611 /** Virtual address of the MSR bitmap (1 page). */
612 R0PTRTYPE(uint8_t *) pMSRBitmap;
613
614#ifdef VBOX_WITH_AUTO_MSR_LOAD_RESTORE
615 /** Physical address of the guest MSR load area (1 page). */
616 RTHCPHYS pGuestMSRPhys;
617 /** R0 memory object for the guest MSR load area (1 page). */
618 RTR0MEMOBJ pMemObjGuestMSR;
619 /** Virtual address of the guest MSR load area (1 page). */
620 R0PTRTYPE(uint8_t *) pGuestMSR;
621
622 /** Physical address of the MSR load area (1 page). */
623 RTHCPHYS pHostMSRPhys;
624 /** R0 memory object for the MSR load area (1 page). */
625 RTR0MEMOBJ pMemObjHostMSR;
626 /** Virtual address of the MSR load area (1 page). */
627 R0PTRTYPE(uint8_t *) pHostMSR;
628#endif /* VBOX_WITH_AUTO_MSR_LOAD_RESTORE */
629
630 /* Number of automatically loaded/restored MSRs. */
631 uint32_t cCachedMSRs;
632 uint32_t uAlignement;
633
634 /* Last use TSC offset value. (cached) */
635 uint64_t u64TSCOffset;
636
637 /** VMCS cache. */
638 VMCSCACHE VMCSCache;
639
640 /** Real-mode emulation state. */
641 struct
642 {
643 X86EFLAGS eflags;
644 uint32_t fValid;
645 } RealMode;
646
647 struct
648 {
649 uint64_t u64VMCSPhys;
650 uint32_t ulVMCSRevision;
651 uint32_t ulInstrError;
652 uint32_t ulExitReason;
653 RTCPUID idEnteredCpu;
654 RTCPUID idCurrentCpu;
655 uint32_t padding;
656 } lasterror;
657
658 /** The last seen guest paging mode (by VT-x). */
659 PGMMODE enmLastSeenGuestMode;
660 /** Current guest paging mode (as seen by HWACCMR3PagingModeChanged). */
661 PGMMODE enmCurrGuestMode;
662 /** Previous guest paging mode (as seen by HWACCMR3PagingModeChanged). */
663 PGMMODE enmPrevGuestMode;
664 } vmx;
665
666 struct
667 {
668 /** R0 memory object for the host VM control block (VMCB). */
669 RTR0MEMOBJ pMemObjVMCBHost;
670 /** Physical address of the host VM control block (VMCB). */
671 RTHCPHYS pVMCBHostPhys;
672 /** Virtual address of the host VM control block (VMCB). */
673 R0PTRTYPE(void *) pVMCBHost;
674
675 /** R0 memory object for the VM control block (VMCB). */
676 RTR0MEMOBJ pMemObjVMCB;
677 /** Physical address of the VM control block (VMCB). */
678 RTHCPHYS pVMCBPhys;
679 /** Virtual address of the VM control block (VMCB). */
680 R0PTRTYPE(void *) pVMCB;
681
682 /** Ring 0 handlers for VT-x. */
683 PFNHWACCMSVMVMRUN pfnVMRun;
684
685 /** R0 memory object for the MSR bitmap (8kb). */
686 RTR0MEMOBJ pMemObjMSRBitmap;
687 /** Physical address of the MSR bitmap (8kb). */
688 RTHCPHYS pMSRBitmapPhys;
689 /** Virtual address of the MSR bitmap. */
690 R0PTRTYPE(void *) pMSRBitmap;
691 } svm;
692
693 /** Event injection state. */
694 struct
695 {
696 uint32_t fPending;
697 uint32_t errCode;
698 uint64_t intInfo;
699 } Event;
700
701 /** IO Block emulation state. */
702 struct
703 {
704 bool fEnabled;
705 uint8_t u8Align[7];
706
707 /** RIP at the start of the io code we wish to emulate in the recompiler. */
708 RTGCPTR GCPtrFunctionEip;
709
710 uint64_t cr0;
711 } EmulateIoBlock;
712
713 struct
714 {
715 /* Pending IO operation type. */
716 HWACCMPENDINGIO enmType;
717 uint32_t uPadding;
718 RTGCPTR GCPtrRip;
719 RTGCPTR GCPtrRipNext;
720 union
721 {
722 struct
723 {
724 unsigned uPort;
725 unsigned uAndVal;
726 unsigned cbSize;
727 } Port;
728 uint64_t aRaw[2];
729 } s;
730 } PendingIO;
731
732 /** Currenty shadow paging mode. */
733 PGMMODE enmShadowMode;
734
735 /** The CPU ID of the CPU currently owning the VMCS. Set in
736 * HWACCMR0Enter and cleared in HWACCMR0Leave. */
737 RTCPUID idEnteredCpu;
738
739 /** To keep track of pending TLB shootdown pages. (SMP guest only) */
740 struct
741 {
742 RTGCPTR aPages[HWACCM_MAX_TLB_SHOOTDOWN_PAGES];
743 unsigned cPages;
744 } TlbShootdown;
745
746 /** For saving stack space, the disassembler state is allocated here instead of
747 * on the stack.
748 * @note The DISCPUSTATE structure is not R3/R0/RZ clean! */
749 union
750 {
751 /** The disassembler scratch space. */
752 DISCPUSTATE DisState;
753 /** Padding. */
754 uint8_t abDisStatePadding[DISCPUSTATE_PADDING_SIZE];
755 };
756
757 RTUINT padding2[1];
758
759 STAMPROFILEADV StatEntry;
760 STAMPROFILEADV StatExit1;
761 STAMPROFILEADV StatExit2;
762#if 1 /* temporary for tracking down darwin issues. */
763 STAMPROFILEADV StatExit2Sub1;
764 STAMPROFILEADV StatExit2Sub2;
765 STAMPROFILEADV StatExit2Sub3;
766#endif
767 STAMPROFILEADV StatInGC;
768
769#if HC_ARCH_BITS == 32 && defined(VBOX_ENABLE_64_BITS_GUESTS) && !defined(VBOX_WITH_HYBRID_32BIT_KERNEL)
770 STAMPROFILEADV StatWorldSwitch3264;
771#endif
772 STAMPROFILEADV StatSpinPoke;
773 STAMPROFILEADV StatSpinPokeFailed;
774
775 STAMCOUNTER StatIntInject;
776
777 STAMCOUNTER StatExitShadowNM;
778 STAMCOUNTER StatExitGuestNM;
779 STAMCOUNTER StatExitShadowPF;
780 STAMCOUNTER StatExitGuestPF;
781 STAMCOUNTER StatExitGuestUD;
782 STAMCOUNTER StatExitGuestSS;
783 STAMCOUNTER StatExitGuestNP;
784 STAMCOUNTER StatExitGuestGP;
785 STAMCOUNTER StatExitGuestDE;
786 STAMCOUNTER StatExitGuestDB;
787 STAMCOUNTER StatExitGuestMF;
788 STAMCOUNTER StatExitInvpg;
789 STAMCOUNTER StatExitInvd;
790 STAMCOUNTER StatExitCpuid;
791 STAMCOUNTER StatExitRdtsc;
792 STAMCOUNTER StatExitRdpmc;
793 STAMCOUNTER StatExitCli;
794 STAMCOUNTER StatExitSti;
795 STAMCOUNTER StatExitPushf;
796 STAMCOUNTER StatExitPopf;
797 STAMCOUNTER StatExitIret;
798 STAMCOUNTER StatExitInt;
799 STAMCOUNTER StatExitCRxWrite[16];
800 STAMCOUNTER StatExitCRxRead[16];
801 STAMCOUNTER StatExitDRxWrite;
802 STAMCOUNTER StatExitDRxRead;
803 STAMCOUNTER StatExitRdmsr;
804 STAMCOUNTER StatExitWrmsr;
805 STAMCOUNTER StatExitCLTS;
806 STAMCOUNTER StatExitHlt;
807 STAMCOUNTER StatExitMwait;
808 STAMCOUNTER StatExitLMSW;
809 STAMCOUNTER StatExitIOWrite;
810 STAMCOUNTER StatExitIORead;
811 STAMCOUNTER StatExitIOStringWrite;
812 STAMCOUNTER StatExitIOStringRead;
813 STAMCOUNTER StatExitIrqWindow;
814 STAMCOUNTER StatExitMaxResume;
815 STAMCOUNTER StatExitPreemptPending;
816 STAMCOUNTER StatIntReinject;
817 STAMCOUNTER StatPendingHostIrq;
818
819 STAMCOUNTER StatFlushPageManual;
820 STAMCOUNTER StatFlushPhysPageManual;
821 STAMCOUNTER StatFlushTLBManual;
822 STAMCOUNTER StatFlushPageInvlpg;
823 STAMCOUNTER StatFlushTLBWorldSwitch;
824 STAMCOUNTER StatNoFlushTLBWorldSwitch;
825 STAMCOUNTER StatFlushTLBCRxChange;
826 STAMCOUNTER StatFlushASID;
827 STAMCOUNTER StatFlushTLBInvlpga;
828 STAMCOUNTER StatTlbShootdown;
829 STAMCOUNTER StatTlbShootdownFlush;
830
831 STAMCOUNTER StatSwitchGuestIrq;
832 STAMCOUNTER StatSwitchToR3;
833
834 STAMCOUNTER StatTSCOffset;
835 STAMCOUNTER StatTSCIntercept;
836 STAMCOUNTER StatTSCInterceptOverFlow;
837
838 STAMCOUNTER StatExitReasonNPF;
839 STAMCOUNTER StatDRxArmed;
840 STAMCOUNTER StatDRxContextSwitch;
841 STAMCOUNTER StatDRxIOCheck;
842
843
844#ifdef VBOX_WITH_STATISTICS
845 R3PTRTYPE(PSTAMCOUNTER) paStatExitReason;
846 R0PTRTYPE(PSTAMCOUNTER) paStatExitReasonR0;
847 R3PTRTYPE(PSTAMCOUNTER) paStatInjectedIrqs;
848 R0PTRTYPE(PSTAMCOUNTER) paStatInjectedIrqsR0;
849#endif
850} HWACCMCPU;
851/** Pointer to HWACCM VM instance data. */
852typedef HWACCMCPU *PHWACCMCPU;
853
854
855#ifdef IN_RING0
856
857VMMR0DECL(PHWACCM_CPUINFO) HWACCMR0GetCurrentCpu();
858VMMR0DECL(PHWACCM_CPUINFO) HWACCMR0GetCurrentCpuEx(RTCPUID idCpu);
859
860
861#ifdef VBOX_STRICT
862VMMR0DECL(void) HWACCMDumpRegs(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
863VMMR0DECL(void) HWACCMR0DumpDescriptor(PCX86DESCHC pDesc, RTSEL Sel, const char *pszMsg);
864#else
865# define HWACCMDumpRegs(a, b ,c) do { } while (0)
866# define HWACCMR0DumpDescriptor(a, b, c) do { } while (0)
867#endif
868
869/* Dummy callback handlers. */
870VMMR0DECL(int) HWACCMR0DummyEnter(PVM pVM, PVMCPU pVCpu, PHWACCM_CPUINFO pCpu);
871VMMR0DECL(int) HWACCMR0DummyLeave(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
872VMMR0DECL(int) HWACCMR0DummyEnableCpu(PHWACCM_CPUINFO pCpu, PVM pVM, void *pvPageCpu, RTHCPHYS pPageCpuPhys);
873VMMR0DECL(int) HWACCMR0DummyDisableCpu(PHWACCM_CPUINFO pCpu, void *pvPageCpu, RTHCPHYS pPageCpuPhys);
874VMMR0DECL(int) HWACCMR0DummyInitVM(PVM pVM);
875VMMR0DECL(int) HWACCMR0DummyTermVM(PVM pVM);
876VMMR0DECL(int) HWACCMR0DummySetupVM(PVM pVM);
877VMMR0DECL(int) HWACCMR0DummyRunGuestCode(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
878VMMR0DECL(int) HWACCMR0DummySaveHostState(PVM pVM, PVMCPU pVCpu);
879VMMR0DECL(int) HWACCMR0DummyLoadGuestState(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
880
881# ifdef VBOX_WITH_KERNEL_USING_XMM
882DECLASM(int) hwaccmR0VMXStartVMWrapXMM(RTHCUINT fResume, PCPUMCTX pCtx, PVMCSCACHE pCache, PVM pVM, PVMCPU pVCpu, PFNHWACCMVMXSTARTVM pfnStartVM);
883DECLASM(int) hwaccmR0SVMRunWrapXMM(RTHCPHYS pVMCBHostPhys, RTHCPHYS pVMCBPhys, PCPUMCTX pCtx, PVM pVM, PVMCPU pVCpu, PFNHWACCMSVMVMRUN pfnVMRun);
884# endif
885
886# ifdef VBOX_WITH_HYBRID_32BIT_KERNEL
887/**
888 * Gets 64-bit GDTR and IDTR on darwin.
889 * @param pGdtr Where to store the 64-bit GDTR.
890 * @param pIdtr Where to store the 64-bit IDTR.
891 */
892DECLASM(void) hwaccmR0Get64bitGDTRandIDTR(PX86XDTR64 pGdtr, PX86XDTR64 pIdtr);
893
894/**
895 * Gets 64-bit CR3 on darwin.
896 * @returns CR3
897 */
898DECLASM(uint64_t) hwaccmR0Get64bitCR3(void);
899# endif
900
901#endif /* IN_RING0 */
902
903/** @} */
904
905RT_C_DECLS_END
906
907#endif
908
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