VirtualBox

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

Last change on this file since 8984 was 8943, checked in by vboxsync, 17 years ago

AMD-V: flush TLB when the flush count for the cpu has changed
AMD-V: Some preparational work for nested paging.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 13.5 KB
Line 
1/* $Id: HWACCMInternal.h 8943 2008-05-20 09:15:53Z 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 <iprt/memobj.h>
33#include <iprt/cpuset.h>
34#include <iprt/mp.h>
35
36__BEGIN_DECLS
37
38
39/** @defgroup grp_hwaccm_int Internal
40 * @ingroup grp_hwaccm
41 * @internal
42 * @{
43 */
44
45
46/**
47 * Converts a HWACCM pointer into a VM pointer.
48 * @returns Pointer to the VM structure the EM is part of.
49 * @param pHWACCM Pointer to HWACCM instance data.
50 */
51#define HWACCM2VM(pHWACCM) ( (PVM)((char*)pHWACCM - pHWACCM->offVM) )
52
53/** Maximum number of exit reason statistics counters. */
54#define MAX_EXITREASON_STAT 0x100
55#define MASK_EXITREASON_STAT 0xff
56
57/** @name Changed flags
58 * These flags are used to keep track of which important registers that
59 * have been changed since last they were reset.
60 * @{
61 */
62#define HWACCM_CHANGED_GUEST_FPU RT_BIT(0)
63#define HWACCM_CHANGED_GUEST_CR0 RT_BIT(1)
64#define HWACCM_CHANGED_GUEST_CR3 RT_BIT(2)
65#define HWACCM_CHANGED_GUEST_CR4 RT_BIT(3)
66#define HWACCM_CHANGED_GUEST_GDTR RT_BIT(4)
67#define HWACCM_CHANGED_GUEST_IDTR RT_BIT(5)
68#define HWACCM_CHANGED_GUEST_LDTR RT_BIT(6)
69#define HWACCM_CHANGED_GUEST_TR RT_BIT(7)
70#define HWACCM_CHANGED_GUEST_SYSENTER_MSR RT_BIT(8)
71#define HWACCM_CHANGED_GUEST_SEGMENT_REGS RT_BIT(9)
72#define HWACCM_CHANGED_GUEST_DEBUG RT_BIT(10)
73#define HWACCM_CHANGED_HOST_CONTEXT RT_BIT(11)
74
75#define HWACCM_CHANGED_ALL ( HWACCM_CHANGED_GUEST_SEGMENT_REGS \
76 | HWACCM_CHANGED_GUEST_CR0 \
77 | HWACCM_CHANGED_GUEST_CR3 \
78 | HWACCM_CHANGED_GUEST_CR4 \
79 | HWACCM_CHANGED_GUEST_GDTR \
80 | HWACCM_CHANGED_GUEST_IDTR \
81 | HWACCM_CHANGED_GUEST_LDTR \
82 | HWACCM_CHANGED_GUEST_TR \
83 | HWACCM_CHANGED_GUEST_SYSENTER_MSR \
84 | HWACCM_CHANGED_GUEST_FPU \
85 | HWACCM_CHANGED_GUEST_DEBUG \
86 | HWACCM_CHANGED_HOST_CONTEXT)
87
88#define HWACCM_CHANGED_ALL_GUEST ( HWACCM_CHANGED_GUEST_SEGMENT_REGS \
89 | HWACCM_CHANGED_GUEST_CR0 \
90 | HWACCM_CHANGED_GUEST_CR3 \
91 | HWACCM_CHANGED_GUEST_CR4 \
92 | HWACCM_CHANGED_GUEST_GDTR \
93 | HWACCM_CHANGED_GUEST_IDTR \
94 | HWACCM_CHANGED_GUEST_LDTR \
95 | HWACCM_CHANGED_GUEST_TR \
96 | HWACCM_CHANGED_GUEST_SYSENTER_MSR \
97 | HWACCM_CHANGED_GUEST_DEBUG \
98 | HWACCM_CHANGED_GUEST_FPU)
99
100/** @} */
101
102/** @name Intercepted traps
103 * Traps that need to be intercepted so we can correctly dispatch them to the guest if required.
104 * Currently #NM and #PF only
105 */
106#ifdef VBOX_STRICT
107#define HWACCM_VMX_TRAP_MASK RT_BIT(0) | RT_BIT(7) | RT_BIT(14) | RT_BIT(6) | RT_BIT(11) | RT_BIT(12) | RT_BIT(13) | RT_BIT(16)
108#define HWACCM_SVM_TRAP_MASK HWACCM_VMX_TRAP_MASK
109#else
110#define HWACCM_VMX_TRAP_MASK RT_BIT(7) | RT_BIT(14)
111#define HWACCM_SVM_TRAP_MASK HWACCM_VMX_TRAP_MASK
112#endif
113/** @} */
114
115
116/** Maxium resume loops allowed in ring 0 (safety precaution) */
117#define HWACCM_MAX_RESUME_LOOPS 1024
118
119/** HWACCM SSM version
120 */
121#define HWACCM_SSM_VERSION 3
122
123/**
124 * HWACCM VM Instance data.
125 * Changes to this must checked against the padding of the cfgm union in VM!
126 */
127typedef struct HWACCM
128{
129 /** Offset to the VM structure.
130 * See HWACCM2VM(). */
131 RTUINT offVM;
132
133 /** Set when we've initialized VMX or SVM. */
134 bool fInitialized;
135 /** Set when we're using VMX/SVN at that moment. */
136 bool fActive;
137
138 /** Set when hardware acceleration is allowed. */
139 bool fAllowed;
140
141 /** HWACCM_CHANGED_* flags. */
142 uint32_t fContextUseFlags;
143
144 /** Old style FPU reporting trap mask override performed (optimization) */
145 uint32_t fFPUOldStyleOverride;
146
147 struct
148 {
149 /** Set by the ring-0 driver to indicate VMX is supported by the CPU. */
150 bool fSupported;
151
152 /** Set when we've enabled VMX. */
153 bool fEnabled;
154
155 /** Set if we can use VMXResume to execute guest code. */
156 bool fResumeVM;
157
158 /** R0 memory object for the VM control structure (VMCS). */
159 RTR0MEMOBJ pMemObjVMCS;
160 /** Physical address of the VM control structure (VMCS). */
161 RTHCPHYS pVMCSPhys;
162 /** Virtual address of the VM control structure (VMCS). */
163 R0PTRTYPE(void *) pVMCS;
164
165 /** R0 memory object for the TSS page used for real mode emulation. */
166 RTR0MEMOBJ pMemObjRealModeTSS;
167 /** Physical address of the TSS page used for real mode emulation. */
168 RTHCPHYS pRealModeTSSPhys;
169 /** Virtual address of the TSS page used for real mode emulation. */
170 R0PTRTYPE(PVBOXTSS) pRealModeTSS;
171
172 /** Host CR4 value (set by ring-0 VMX init) */
173 uint64_t hostCR4;
174
175 /** Current VMX_VMCS_CTRL_PROC_EXEC_CONTROLS. */
176 uint64_t proc_ctls;
177
178 /** Current CR0 mask. */
179 uint64_t cr0_mask;
180 /** Current CR4 mask. */
181 uint64_t cr4_mask;
182
183 /** VMX MSR values */
184 struct
185 {
186 uint64_t feature_ctrl;
187 uint64_t vmx_basic_info;
188 uint64_t vmx_pin_ctls;
189 uint64_t vmx_proc_ctls;
190 uint64_t vmx_exit;
191 uint64_t vmx_entry;
192 uint64_t vmx_misc;
193 uint64_t vmx_cr0_fixed0;
194 uint64_t vmx_cr0_fixed1;
195 uint64_t vmx_cr4_fixed0;
196 uint64_t vmx_cr4_fixed1;
197 uint64_t vmx_vmcs_enum;
198 } msr;
199
200 /* Last instruction error */
201 uint32_t ulLastInstrError;
202 } vmx;
203
204 struct
205 {
206 /** Set by the ring-0 driver to indicate SVM is supported by the CPU. */
207 bool fSupported;
208 /** Set when we've enabled SVM. */
209 bool fEnabled;
210 /** Set if we don't have to flush the TLB on VM entry. */
211 bool fResumeVM;
212 /** Set if erratum 170 affects the AMD cpu. */
213 bool fAlwaysFlushTLB;
214 /** Set if we need to flush the TLB during the world switch. */
215 bool fForceTLBFlush;
216 /** Set if nested paging is enabled. */
217 bool fNestedPaging;
218
219 /* Id of the last cpu we were executing code on (NIL_RTCPUID for the first time) */
220 RTCPUID idLastCpu;
221
222 /* TLB flush count */
223 uint32_t cTLBFlushes;
224
225 /** R0 memory object for the VM control block (VMCB). */
226 RTR0MEMOBJ pMemObjVMCB;
227 /** Physical address of the VM control block (VMCB). */
228 RTHCPHYS pVMCBPhys;
229 /** Virtual address of the VM control block (VMCB). */
230 R0PTRTYPE(void *) pVMCB;
231
232 /** R0 memory object for the host VM control block (VMCB). */
233 RTR0MEMOBJ pMemObjVMCBHost;
234 /** Physical address of the host VM control block (VMCB). */
235 RTHCPHYS pVMCBHostPhys;
236 /** Virtual address of the host VM control block (VMCB). */
237 R0PTRTYPE(void *) pVMCBHost;
238
239 /** R0 memory object for the IO bitmap (12kb). */
240 RTR0MEMOBJ pMemObjIOBitmap;
241 /** Physical address of the IO bitmap (12kb). */
242 RTHCPHYS pIOBitmapPhys;
243 /** Virtual address of the IO bitmap. */
244 R0PTRTYPE(void *) pIOBitmap;
245
246 /** R0 memory object for the MSR bitmap (8kb). */
247 RTR0MEMOBJ pMemObjMSRBitmap;
248 /** Physical address of the MSR bitmap (8kb). */
249 RTHCPHYS pMSRBitmapPhys;
250 /** Virtual address of the MSR bitmap. */
251 R0PTRTYPE(void *) pMSRBitmap;
252
253 /** SVM revision. */
254 uint32_t u32Rev;
255
256 /** Maximum ASID allowed. */
257 uint32_t u32MaxASID;
258
259 /** SVM feature bits from cpuid 0x8000000a */
260 uint32_t u32Features;
261 } svm;
262
263 struct
264 {
265 uint32_t u32AMDFeatureECX;
266 uint32_t u32AMDFeatureEDX;
267 } cpuid;
268
269 /* Event injection state. */
270 struct
271 {
272 uint32_t fPending;
273 uint32_t errCode;
274 uint64_t intInfo;
275 } Event;
276
277 /** Saved error from detection */
278 int32_t lLastError;
279
280 /** HWACCMR0Init was run */
281 bool fHWACCMR0Init;
282
283 /** Currenty shadow paging mode. */
284 PGMMODE enmShadowMode;
285
286 STAMPROFILEADV StatEntry;
287 STAMPROFILEADV StatExit;
288 STAMPROFILEADV StatInGC;
289
290 STAMCOUNTER StatIntInject;
291
292 STAMCOUNTER StatExitShadowNM;
293 STAMCOUNTER StatExitGuestNM;
294 STAMCOUNTER StatExitShadowPF;
295 STAMCOUNTER StatExitGuestPF;
296 STAMCOUNTER StatExitGuestUD;
297 STAMCOUNTER StatExitGuestSS;
298 STAMCOUNTER StatExitGuestNP;
299 STAMCOUNTER StatExitGuestGP;
300 STAMCOUNTER StatExitGuestDE;
301 STAMCOUNTER StatExitGuestMF;
302 STAMCOUNTER StatExitInvpg;
303 STAMCOUNTER StatExitInvd;
304 STAMCOUNTER StatExitCpuid;
305 STAMCOUNTER StatExitRdtsc;
306 STAMCOUNTER StatExitCRxWrite;
307 STAMCOUNTER StatExitCRxRead;
308 STAMCOUNTER StatExitDRxWrite;
309 STAMCOUNTER StatExitDRxRead;
310 STAMCOUNTER StatExitCLTS;
311 STAMCOUNTER StatExitLMSW;
312 STAMCOUNTER StatExitIOWrite;
313 STAMCOUNTER StatExitIORead;
314 STAMCOUNTER StatExitIOStringWrite;
315 STAMCOUNTER StatExitIOStringRead;
316 STAMCOUNTER StatExitIrqWindow;
317 STAMCOUNTER StatExitMaxResume;
318 STAMCOUNTER StatIntReinject;
319 STAMCOUNTER StatPendingHostIrq;
320
321 STAMCOUNTER StatFlushPageManual;
322 STAMCOUNTER StatFlushTLBManual;
323 STAMCOUNTER StatFlushPageInvlpg;
324 STAMCOUNTER StatFlushTLBWorldSwitch;
325 STAMCOUNTER StatNoFlushTLBWorldSwitch;
326 STAMCOUNTER StatFlushTLBCRxChange;
327 STAMCOUNTER StatFlushASID;
328
329 STAMCOUNTER StatSwitchGuestIrq;
330 STAMCOUNTER StatSwitchToR3;
331
332 R3PTRTYPE(PSTAMCOUNTER) pStatExitReason;
333 R0PTRTYPE(PSTAMCOUNTER) pStatExitReasonR0;
334} HWACCM;
335/** Pointer to HWACCM VM instance data. */
336typedef HWACCM *PHWACCM;
337
338typedef struct
339{
340 RTCPUID idCpu;
341
342 RTR0MEMOBJ pMemObj;
343 /* Current ASID (AMD-V only) */
344 uint32_t uCurrentASID;
345 /* TLB flush count */
346 uint32_t cTLBFlushes;
347
348 bool fVMXConfigured;
349 bool fSVMConfigured;
350} HWACCM_CPUINFO;
351typedef HWACCM_CPUINFO *PHWACCM_CPUINFO;
352
353#ifdef IN_RING0
354
355#ifdef VBOX_STRICT
356HWACCMR0DECL(void) HWACCMDumpRegs(PCPUMCTX pCtx);
357HWACCMR0DECL(void) HWACCMR0DumpDescriptor(PX86DESCHC Desc, RTSEL Sel, const char *pszMsg);
358#else
359#define HWACCMDumpRegs(a) do { } while (0)
360#define HWACCMR0DumpDescriptor(a, b, c) do { } while (0)
361#endif
362
363#endif
364
365/** @} */
366
367__END_DECLS
368
369#endif
370
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