VirtualBox

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

Last change on this file since 22244 was 22243, checked in by vboxsync, 15 years ago

Apply the same tsc underflow check to AMD-V.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 32.2 KB
Line 
1/* $Id: HWACCMInternal.h 22243 2009-08-13 15:43:06Z 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 /** Explicit alignment padding to make 32-bit gcc align u64RegisterMask
277 * naturally. */
278 bool padding[2];
279
280 /** And mask for copying register contents. */
281 uint64_t u64RegisterMask;
282
283 /** Maximum ASID allowed. */
284 RTUINT uMaxASID;
285
286 /** The maximum number of resumes loops allowed in ring-0 (safety precaution).
287 * This number is set much higher when RTThreadPreemptIsPending is reliable. */
288 uint32_t cMaxResumeLoops;
289
290 /** Guest allocated memory for patching purposes. */
291 RTGCPTR pGuestPatchMem;
292 /** Current free pointer inside the patch block. */
293 RTGCPTR pFreeGuestPatchMem;
294 /** Size of the guest patch memory block. */
295 uint32_t cbGuestPatchMem;
296 uint32_t uPadding1;
297
298#if HC_ARCH_BITS == 32 && defined(VBOX_ENABLE_64_BITS_GUESTS) && !defined(VBOX_WITH_HYBRID_32BIT_KERNEL)
299 /** 32 to 64 bits switcher entrypoint. */
300 R0PTRTYPE(PFNHWACCMSWITCHERHC) pfnHost32ToGuest64R0;
301
302 /* AMD-V 64 bits vmrun handler */
303 RTRCPTR pfnSVMGCVMRun64;
304
305 /* VT-x 64 bits vmlaunch handler */
306 RTRCPTR pfnVMXGCStartVM64;
307
308 /* RC handler to setup the 64 bits FPU state. */
309 RTRCPTR pfnSaveGuestFPU64;
310
311 /* RC handler to setup the 64 bits debug state. */
312 RTRCPTR pfnSaveGuestDebug64;
313
314 /* Test handler */
315 RTRCPTR pfnTest64;
316
317 RTRCPTR uAlignment[2];
318/*#elif defined(VBOX_WITH_HYBRID_32BIT_KERNEL)
319 uint32_t u32Alignment[1]; */
320#endif
321
322 struct
323 {
324 /** Set by the ring-0 driver to indicate VMX is supported by the CPU. */
325 bool fSupported;
326
327 /** Set when we've enabled VMX. */
328 bool fEnabled;
329
330 /** Set if VPID is supported. */
331 bool fVPID;
332
333 /** Set if VT-x VPID is allowed. */
334 bool fAllowVPID;
335
336 /** Virtual address of the TSS page used for real mode emulation. */
337 R3PTRTYPE(PVBOXTSS) pRealModeTSS;
338
339 /** Virtual address of the identity page table used for real mode and protected mode without paging emulation in EPT mode. */
340 R3PTRTYPE(PX86PD) pNonPagingModeEPTPageTable;
341
342 /** R0 memory object for the APIC physical page (serves for filtering accesses). */
343 RTR0MEMOBJ pMemObjAPIC;
344 /** Physical address of the APIC physical page (serves for filtering accesses). */
345 RTHCPHYS pAPICPhys;
346 /** Virtual address of the APIC physical page (serves for filtering accesses). */
347 R0PTRTYPE(uint8_t *) pAPIC;
348
349 /** R0 memory object for the MSR entry load page (guest MSRs). */
350 RTR0MEMOBJ pMemObjMSREntryLoad;
351 /** Physical address of the MSR entry load page (guest MSRs). */
352 RTHCPHYS pMSREntryLoadPhys;
353 /** Virtual address of the MSR entry load page (guest MSRs). */
354 R0PTRTYPE(uint8_t *) pMSREntryLoad;
355
356#ifdef VBOX_WITH_CRASHDUMP_MAGIC
357 RTR0MEMOBJ pMemObjScratch;
358 RTHCPHYS pScratchPhys;
359 R0PTRTYPE(uint8_t *) pScratch;
360#endif
361 /** R0 memory object for the MSR exit store page (guest MSRs). */
362 RTR0MEMOBJ pMemObjMSRExitStore;
363 /** Physical address of the MSR exit store page (guest MSRs). */
364 RTHCPHYS pMSRExitStorePhys;
365 /** Virtual address of the MSR exit store page (guest MSRs). */
366 R0PTRTYPE(uint8_t *) pMSRExitStore;
367
368 /** R0 memory object for the MSR exit load page (host MSRs). */
369 RTR0MEMOBJ pMemObjMSRExitLoad;
370 /** Physical address of the MSR exit load page (host MSRs). */
371 RTHCPHYS pMSRExitLoadPhys;
372 /** Virtual address of the MSR exit load page (host MSRs). */
373 R0PTRTYPE(uint8_t *) pMSRExitLoad;
374
375 /** Ring 0 handlers for VT-x. */
376 DECLR0CALLBACKMEMBER(void, pfnSetupTaggedTLB, (PVM pVM, PVMCPU pVCpu));
377
378 /** Host CR4 value (set by ring-0 VMX init) */
379 uint64_t hostCR4;
380
381 /** VMX MSR values */
382 struct
383 {
384 uint64_t feature_ctrl;
385 uint64_t vmx_basic_info;
386 VMX_CAPABILITY vmx_pin_ctls;
387 VMX_CAPABILITY vmx_proc_ctls;
388 VMX_CAPABILITY vmx_proc_ctls2;
389 VMX_CAPABILITY vmx_exit;
390 VMX_CAPABILITY vmx_entry;
391 uint64_t vmx_misc;
392 uint64_t vmx_cr0_fixed0;
393 uint64_t vmx_cr0_fixed1;
394 uint64_t vmx_cr4_fixed0;
395 uint64_t vmx_cr4_fixed1;
396 uint64_t vmx_vmcs_enum;
397 uint64_t vmx_eptcaps;
398 } msr;
399
400 /** Flush types for invept & invvpid; they depend on capabilities. */
401 VMX_FLUSH enmFlushPage;
402 VMX_FLUSH enmFlushContext;
403 } vmx;
404
405 struct
406 {
407 /** Set by the ring-0 driver to indicate SVM is supported by the CPU. */
408 bool fSupported;
409 /** Set when we've enabled SVM. */
410 bool fEnabled;
411 /** Set if erratum 170 affects the AMD cpu. */
412 bool fAlwaysFlushTLB;
413 /** Set when TPR patching is active. */
414 bool fTPRPatchingActive;
415
416 /** R0 memory object for the IO bitmap (12kb). */
417 RTR0MEMOBJ pMemObjIOBitmap;
418 /** Physical address of the IO bitmap (12kb). */
419 RTHCPHYS pIOBitmapPhys;
420 /** Virtual address of the IO bitmap. */
421 R0PTRTYPE(void *) pIOBitmap;
422
423 /** SVM revision. */
424 uint32_t u32Rev;
425
426 /** SVM feature bits from cpuid 0x8000000a */
427 uint32_t u32Features;
428
429 /**
430 * AVL tree with all patches (active or disabled) sorted by guest instruction address
431 */
432 AVLOU32TREE PatchTree;
433 uint32_t cPatches;
434 HWACCMTPRPATCH aPatches[64];
435 } svm;
436
437 struct
438 {
439 uint32_t u32AMDFeatureECX;
440 uint32_t u32AMDFeatureEDX;
441 } cpuid;
442
443 /** Saved error from detection */
444 int32_t lLastError;
445
446 /** HWACCMR0Init was run */
447 bool fHWACCMR0Init;
448 bool u8Alignment[7];
449
450 STAMCOUNTER StatTPRPatchSuccess;
451 STAMCOUNTER StatTPRPatchFailure;
452 STAMCOUNTER StatTPRReplaceSuccess;
453 STAMCOUNTER StatTPRReplaceFailure;
454} HWACCM;
455/** Pointer to HWACCM VM instance data. */
456typedef HWACCM *PHWACCM;
457
458/* Maximum number of cached entries. */
459#define VMCSCACHE_MAX_ENTRY 128
460
461/* Structure for storing read and write VMCS actions. */
462typedef struct VMCSCACHE
463{
464#ifdef VBOX_WITH_CRASHDUMP_MAGIC
465 /* Magic marker for searching in crash dumps. */
466 uint8_t aMagic[16];
467 uint64_t uMagic;
468 uint64_t u64TimeEntry;
469 uint64_t u64TimeSwitch;
470 uint64_t cResume;
471 uint64_t interPD;
472 uint64_t pSwitcher;
473 uint32_t uPos;
474 uint32_t idCpu;
475#endif
476 /* CR2 is saved here for EPT syncing. */
477 uint64_t cr2;
478 struct
479 {
480 uint32_t cValidEntries;
481 uint32_t uAlignment;
482 uint32_t aField[VMCSCACHE_MAX_ENTRY];
483 uint64_t aFieldVal[VMCSCACHE_MAX_ENTRY];
484 } Write;
485 struct
486 {
487 uint32_t cValidEntries;
488 uint32_t uAlignment;
489 uint32_t aField[VMCSCACHE_MAX_ENTRY];
490 uint64_t aFieldVal[VMCSCACHE_MAX_ENTRY];
491 } Read;
492#ifdef DEBUG
493 struct
494 {
495 RTHCPHYS pPageCpuPhys;
496 RTHCPHYS pVMCSPhys;
497 RTGCPTR pCache;
498 RTGCPTR pCtx;
499 } TestIn;
500 struct
501 {
502 RTHCPHYS pVMCSPhys;
503 RTGCPTR pCache;
504 RTGCPTR pCtx;
505 uint64_t eflags;
506 uint64_t cr8;
507 } TestOut;
508 struct
509 {
510 uint64_t param1;
511 uint64_t param2;
512 uint64_t param3;
513 uint64_t param4;
514 } ScratchPad;
515#endif
516} VMCSCACHE;
517/** Pointer to VMCSCACHE. */
518typedef VMCSCACHE *PVMCSCACHE;
519
520/** VMX StartVM function. */
521typedef DECLCALLBACK(int) FNHWACCMVMXSTARTVM(RTHCUINT fResume, PCPUMCTX pCtx, PVMCSCACHE pCache, PVM pVM, PVMCPU pVCpu);
522/** Pointer to a VMX StartVM function. */
523typedef R0PTRTYPE(FNHWACCMVMXSTARTVM *) PFNHWACCMVMXSTARTVM;
524
525/** SVM VMRun function. */
526typedef DECLCALLBACK(int) FNHWACCMSVMVMRUN(RTHCPHYS pVMCBHostPhys, RTHCPHYS pVMCBPhys, PCPUMCTX pCtx, PVM pVM, PVMCPU pVCpu);
527/** Pointer to a SVM VMRun function. */
528typedef R0PTRTYPE(FNHWACCMSVMVMRUN *) PFNHWACCMSVMVMRUN;
529
530/**
531 * HWACCM VMCPU Instance data.
532 */
533typedef struct HWACCMCPU
534{
535 /** Old style FPU reporting trap mask override performed (optimization) */
536 bool fFPUOldStyleOverride;
537
538 /** Set if we don't have to flush the TLB on VM entry. */
539 bool fResumeVM;
540
541 /** Set if we need to flush the TLB during the world switch. */
542 bool fForceTLBFlush;
543
544 /** Set when we're using VT-x or AMD-V at that moment. */
545 bool fActive;
546
547 /** HWACCM_CHANGED_* flags. */
548 RTUINT fContextUseFlags;
549
550 /* Id of the last cpu we were executing code on (NIL_RTCPUID for the first time) */
551 RTCPUID idLastCpu;
552
553 /* TLB flush count */
554 RTUINT cTLBFlushes;
555
556 /* Current ASID in use by the VM */
557 RTUINT uCurrentASID;
558
559 struct
560 {
561 /** Physical address of the VM control structure (VMCS). */
562 RTHCPHYS pVMCSPhys;
563 /** R0 memory object for the VM control structure (VMCS). */
564 RTR0MEMOBJ pMemObjVMCS;
565 /** Virtual address of the VM control structure (VMCS). */
566 R0PTRTYPE(void *) pVMCS;
567
568 /** Ring 0 handlers for VT-x. */
569 PFNHWACCMVMXSTARTVM pfnStartVM;
570
571 /** Current VMX_VMCS_CTRL_PROC_EXEC_CONTROLS. */
572 uint64_t proc_ctls;
573
574 /** Current VMX_VMCS_CTRL_PROC_EXEC2_CONTROLS. */
575 uint64_t proc_ctls2;
576
577 /** Physical address of the virtual APIC page for TPR caching. */
578 RTHCPHYS pVAPICPhys;
579 /** R0 memory object for the virtual APIC page for TPR caching. */
580 RTR0MEMOBJ pMemObjVAPIC;
581 /** Virtual address of the virtual APIC page for TPR caching. */
582 R0PTRTYPE(uint8_t *) pVAPIC;
583
584 /** Current CR0 mask. */
585 uint64_t cr0_mask;
586 /** Current CR4 mask. */
587 uint64_t cr4_mask;
588
589 /** Current EPTP. */
590 RTHCPHYS GCPhysEPTP;
591
592 /** Physical address of the MSR bitmap (1 page). */
593 RTHCPHYS pMSRBitmapPhys;
594 /** R0 memory object for the MSR bitmap (1 page). */
595 RTR0MEMOBJ pMemObjMSRBitmap;
596 /** Virtual address of the MSR bitmap (1 page). */
597 R0PTRTYPE(uint8_t *) pMSRBitmap;
598
599#ifdef VBOX_WITH_AUTO_MSR_LOAD_RESTORE
600 /** Physical address of the guest MSR load area (1 page). */
601 RTHCPHYS pGuestMSRPhys;
602 /** R0 memory object for the guest MSR load area (1 page). */
603 RTR0MEMOBJ pMemObjGuestMSR;
604 /** Virtual address of the guest MSR load area (1 page). */
605 R0PTRTYPE(uint8_t *) pGuestMSR;
606
607 /** Physical address of the MSR load area (1 page). */
608 RTHCPHYS pHostMSRPhys;
609 /** R0 memory object for the MSR load area (1 page). */
610 RTR0MEMOBJ pMemObjHostMSR;
611 /** Virtual address of the MSR load area (1 page). */
612 R0PTRTYPE(uint8_t *) pHostMSR;
613#endif /* VBOX_WITH_AUTO_MSR_LOAD_RESTORE */
614
615 /* Number of automatically loaded/restored MSRs. */
616 uint32_t cCachedMSRs;
617 uint32_t uAlignement;
618
619 /* Last use TSC offset value. (cached) */
620 uint64_t u64TSCOffset;
621
622 /** VMCS cache. */
623 VMCSCACHE VMCSCache;
624
625 /** Real-mode emulation state. */
626 struct
627 {
628 X86EFLAGS eflags;
629 uint32_t fValid;
630 } RealMode;
631
632 struct
633 {
634 uint64_t u64VMCSPhys;
635 uint32_t ulVMCSRevision;
636 uint32_t ulInstrError;
637 uint32_t ulExitReason;
638 RTCPUID idEnteredCpu;
639 RTCPUID idCurrentCpu;
640 uint32_t padding;
641 } lasterror;
642
643 /** The last seen guest paging mode (by VT-x). */
644 PGMMODE enmLastSeenGuestMode;
645 /** Current guest paging mode (as seen by HWACCMR3PagingModeChanged). */
646 PGMMODE enmCurrGuestMode;
647 /** Previous guest paging mode (as seen by HWACCMR3PagingModeChanged). */
648 PGMMODE enmPrevGuestMode;
649 } vmx;
650
651 struct
652 {
653 /** R0 memory object for the host VM control block (VMCB). */
654 RTR0MEMOBJ pMemObjVMCBHost;
655 /** Physical address of the host VM control block (VMCB). */
656 RTHCPHYS pVMCBHostPhys;
657 /** Virtual address of the host VM control block (VMCB). */
658 R0PTRTYPE(void *) pVMCBHost;
659
660 /** R0 memory object for the VM control block (VMCB). */
661 RTR0MEMOBJ pMemObjVMCB;
662 /** Physical address of the VM control block (VMCB). */
663 RTHCPHYS pVMCBPhys;
664 /** Virtual address of the VM control block (VMCB). */
665 R0PTRTYPE(void *) pVMCB;
666
667 /** Ring 0 handlers for VT-x. */
668 PFNHWACCMSVMVMRUN pfnVMRun;
669
670 /** R0 memory object for the MSR bitmap (8kb). */
671 RTR0MEMOBJ pMemObjMSRBitmap;
672 /** Physical address of the MSR bitmap (8kb). */
673 RTHCPHYS pMSRBitmapPhys;
674 /** Virtual address of the MSR bitmap. */
675 R0PTRTYPE(void *) pMSRBitmap;
676 } svm;
677
678 /** Event injection state. */
679 struct
680 {
681 uint32_t fPending;
682 uint32_t errCode;
683 uint64_t intInfo;
684 } Event;
685
686 /** IO Block emulation state. */
687 struct
688 {
689 bool fEnabled;
690 uint8_t u8Align[7];
691
692 /** RIP at the start of the io code we wish to emulate in the recompiler. */
693 RTGCPTR GCPtrFunctionEip;
694
695 uint64_t cr0;
696 } EmulateIoBlock;
697
698 struct
699 {
700 /* Pending IO operation type. */
701 HWACCMPENDINGIO enmType;
702 uint32_t uPadding;
703 RTGCPTR GCPtrRip;
704 RTGCPTR GCPtrRipNext;
705 union
706 {
707 struct
708 {
709 unsigned uPort;
710 unsigned uAndVal;
711 unsigned cbSize;
712 } Port;
713 uint64_t aRaw[2];
714 } s;
715 } PendingIO;
716
717 /** Currenty shadow paging mode. */
718 PGMMODE enmShadowMode;
719
720 /** The CPU ID of the CPU currently owning the VMCS. Set in
721 * HWACCMR0Enter and cleared in HWACCMR0Leave. */
722 RTCPUID idEnteredCpu;
723
724 /** To keep track of pending TLB shootdown pages. (SMP guest only) */
725 struct
726 {
727 RTGCPTR aPages[HWACCM_MAX_TLB_SHOOTDOWN_PAGES];
728 unsigned cPages;
729 } TlbShootdown;
730
731 /** For saving stack space, the disassembler state is allocated here instead of
732 * on the stack.
733 * @note The DISCPUSTATE structure is not R3/R0/RZ clean! */
734 union
735 {
736 /** The disassembler scratch space. */
737 DISCPUSTATE DisState;
738 /** Padding. */
739 uint8_t abDisStatePadding[DISCPUSTATE_PADDING_SIZE];
740 };
741
742 RTUINT padding2[1];
743
744 STAMPROFILEADV StatEntry;
745 STAMPROFILEADV StatExit1;
746 STAMPROFILEADV StatExit2;
747#if 1 /* temporary for tracking down darwin issues. */
748 STAMPROFILEADV StatExit2Sub1;
749 STAMPROFILEADV StatExit2Sub2;
750 STAMPROFILEADV StatExit2Sub3;
751#endif
752 STAMPROFILEADV StatInGC;
753
754#if HC_ARCH_BITS == 32 && defined(VBOX_ENABLE_64_BITS_GUESTS) && !defined(VBOX_WITH_HYBRID_32BIT_KERNEL)
755 STAMPROFILEADV StatWorldSwitch3264;
756#endif
757
758 STAMCOUNTER StatIntInject;
759
760 STAMCOUNTER StatExitShadowNM;
761 STAMCOUNTER StatExitGuestNM;
762 STAMCOUNTER StatExitShadowPF;
763 STAMCOUNTER StatExitGuestPF;
764 STAMCOUNTER StatExitGuestUD;
765 STAMCOUNTER StatExitGuestSS;
766 STAMCOUNTER StatExitGuestNP;
767 STAMCOUNTER StatExitGuestGP;
768 STAMCOUNTER StatExitGuestDE;
769 STAMCOUNTER StatExitGuestDB;
770 STAMCOUNTER StatExitGuestMF;
771 STAMCOUNTER StatExitInvpg;
772 STAMCOUNTER StatExitInvd;
773 STAMCOUNTER StatExitCpuid;
774 STAMCOUNTER StatExitRdtsc;
775 STAMCOUNTER StatExitRdpmc;
776 STAMCOUNTER StatExitCli;
777 STAMCOUNTER StatExitSti;
778 STAMCOUNTER StatExitPushf;
779 STAMCOUNTER StatExitPopf;
780 STAMCOUNTER StatExitIret;
781 STAMCOUNTER StatExitInt;
782 STAMCOUNTER StatExitCRxWrite[16];
783 STAMCOUNTER StatExitCRxRead[16];
784 STAMCOUNTER StatExitDRxWrite;
785 STAMCOUNTER StatExitDRxRead;
786 STAMCOUNTER StatExitRdmsr;
787 STAMCOUNTER StatExitWrmsr;
788 STAMCOUNTER StatExitCLTS;
789 STAMCOUNTER StatExitHlt;
790 STAMCOUNTER StatExitMwait;
791 STAMCOUNTER StatExitLMSW;
792 STAMCOUNTER StatExitIOWrite;
793 STAMCOUNTER StatExitIORead;
794 STAMCOUNTER StatExitIOStringWrite;
795 STAMCOUNTER StatExitIOStringRead;
796 STAMCOUNTER StatExitIrqWindow;
797 STAMCOUNTER StatExitMaxResume;
798 STAMCOUNTER StatExitPreemptPending;
799 STAMCOUNTER StatIntReinject;
800 STAMCOUNTER StatPendingHostIrq;
801
802 STAMCOUNTER StatFlushPageManual;
803 STAMCOUNTER StatFlushPhysPageManual;
804 STAMCOUNTER StatFlushTLBManual;
805 STAMCOUNTER StatFlushPageInvlpg;
806 STAMCOUNTER StatFlushTLBWorldSwitch;
807 STAMCOUNTER StatNoFlushTLBWorldSwitch;
808 STAMCOUNTER StatFlushTLBCRxChange;
809 STAMCOUNTER StatFlushASID;
810 STAMCOUNTER StatFlushTLBInvlpga;
811 STAMCOUNTER StatTlbShootdown;
812 STAMCOUNTER StatTlbShootdownFlush;
813
814 STAMCOUNTER StatSwitchGuestIrq;
815 STAMCOUNTER StatSwitchToR3;
816
817 STAMCOUNTER StatTSCOffset;
818 STAMCOUNTER StatTSCIntercept;
819 STAMCOUNTER StatTSCInterceptOverFlow;
820
821 STAMCOUNTER StatExitReasonNPF;
822 STAMCOUNTER StatDRxArmed;
823 STAMCOUNTER StatDRxContextSwitch;
824 STAMCOUNTER StatDRxIOCheck;
825
826
827#ifdef VBOX_WITH_STATISTICS
828 R3PTRTYPE(PSTAMCOUNTER) paStatExitReason;
829 R0PTRTYPE(PSTAMCOUNTER) paStatExitReasonR0;
830 R3PTRTYPE(PSTAMCOUNTER) paStatInjectedIrqs;
831 R0PTRTYPE(PSTAMCOUNTER) paStatInjectedIrqsR0;
832#endif
833} HWACCMCPU;
834/** Pointer to HWACCM VM instance data. */
835typedef HWACCMCPU *PHWACCMCPU;
836
837
838#ifdef IN_RING0
839
840VMMR0DECL(PHWACCM_CPUINFO) HWACCMR0GetCurrentCpu();
841VMMR0DECL(PHWACCM_CPUINFO) HWACCMR0GetCurrentCpuEx(RTCPUID idCpu);
842
843
844#ifdef VBOX_STRICT
845VMMR0DECL(void) HWACCMDumpRegs(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
846VMMR0DECL(void) HWACCMR0DumpDescriptor(PX86DESCHC Desc, RTSEL Sel, const char *pszMsg);
847#else
848#define HWACCMDumpRegs(a, b ,c) do { } while (0)
849#define HWACCMR0DumpDescriptor(a, b, c) do { } while (0)
850#endif
851
852/* Dummy callback handlers. */
853VMMR0DECL(int) HWACCMR0DummyEnter(PVM pVM, PVMCPU pVCpu, PHWACCM_CPUINFO pCpu);
854VMMR0DECL(int) HWACCMR0DummyLeave(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
855VMMR0DECL(int) HWACCMR0DummyEnableCpu(PHWACCM_CPUINFO pCpu, PVM pVM, void *pvPageCpu, RTHCPHYS pPageCpuPhys);
856VMMR0DECL(int) HWACCMR0DummyDisableCpu(PHWACCM_CPUINFO pCpu, void *pvPageCpu, RTHCPHYS pPageCpuPhys);
857VMMR0DECL(int) HWACCMR0DummyInitVM(PVM pVM);
858VMMR0DECL(int) HWACCMR0DummyTermVM(PVM pVM);
859VMMR0DECL(int) HWACCMR0DummySetupVM(PVM pVM);
860VMMR0DECL(int) HWACCMR0DummyRunGuestCode(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
861VMMR0DECL(int) HWACCMR0DummySaveHostState(PVM pVM, PVMCPU pVCpu);
862VMMR0DECL(int) HWACCMR0DummyLoadGuestState(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
863
864# ifdef VBOX_WITH_KERNEL_USING_XMM
865DECLASM(int) hwaccmR0VMXStartVMWrapXMM(RTHCUINT fResume, PCPUMCTX pCtx, PVMCSCACHE pCache, PVM pVM, PVMCPU pVCpu, PFNHWACCMVMXSTARTVM pfnStartVM);
866DECLASM(int) hwaccmR0SVMRunWrapXMM(RTHCPHYS pVMCBHostPhys, RTHCPHYS pVMCBPhys, PCPUMCTX pCtx, PVM pVM, PVMCPU pVCpu, PFNHWACCMSVMVMRUN pfnVMRun);
867# endif
868
869# ifdef VBOX_WITH_HYBRID_32BIT_KERNEL
870/**
871 * Gets 64-bit GDTR and IDTR on darwin.
872 * @param pGdtr Where to store the 64-bit GDTR.
873 * @param pIdtr Where to store the 64-bit IDTR.
874 */
875DECLASM(void) hwaccmR0Get64bitGDTRandIDTR(PX86XDTR64 pGdtr, PX86XDTR64 pIdtr);
876
877/**
878 * Gets 64-bit CR3 on darwin.
879 * @returns CR3
880 */
881DECLASM(uint64_t) hwaccmR0Get64bitCR3(void);
882# endif
883
884#endif /* IN_RING0 */
885
886/** @} */
887
888RT_C_DECLS_END
889
890#endif
891
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