VirtualBox

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

最後變更 在這個檔案從37323是 37323,由 vboxsync 提交於 14 年 前

build fix and some prefix cleanup.

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette