VirtualBox

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

Last change on this file since 22026 was 22016, checked in by vboxsync, 15 years ago

MSR bitmap must be per-VCPU

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