VirtualBox

source: vbox/trunk/src/VBox/VMM/HWACCM.cpp@ 14899

Last change on this file since 14899 was 14899, checked in by vboxsync, 16 years ago

Wrote testcase for the new switcher.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 61.7 KB
Line 
1/* $Id: HWACCM.cpp 14899 2008-12-02 12:39:34Z vboxsync $ */
2/** @file
3 * HWACCM - Intel/AMD VM Hardware Support Manager
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/*******************************************************************************
23* Header Files *
24*******************************************************************************/
25#define LOG_GROUP LOG_GROUP_HWACCM
26#include <VBox/cpum.h>
27#include <VBox/stam.h>
28#include <VBox/mm.h>
29#include <VBox/pdm.h>
30#include <VBox/pgm.h>
31#include <VBox/trpm.h>
32#include <VBox/dbgf.h>
33#include <VBox/patm.h>
34#include <VBox/csam.h>
35#include <VBox/selm.h>
36#include <VBox/rem.h>
37#include <VBox/hwacc_vmx.h>
38#include <VBox/hwacc_svm.h>
39#include "HWACCMInternal.h"
40#include <VBox/vm.h>
41#include <VBox/err.h>
42#include <VBox/param.h>
43
44#include <iprt/assert.h>
45#include <VBox/log.h>
46#include <iprt/asm.h>
47#include <iprt/string.h>
48#include <iprt/thread.h>
49
50/*******************************************************************************
51* Internal Functions *
52*******************************************************************************/
53static DECLCALLBACK(int) hwaccmR3Save(PVM pVM, PSSMHANDLE pSSM);
54static DECLCALLBACK(int) hwaccmR3Load(PVM pVM, PSSMHANDLE pSSM, uint32_t u32Version);
55
56
57/**
58 * Initializes the HWACCM.
59 *
60 * @returns VBox status code.
61 * @param pVM The VM to operate on.
62 */
63VMMR3DECL(int) HWACCMR3Init(PVM pVM)
64{
65 LogFlow(("HWACCMR3Init\n"));
66
67 /*
68 * Assert alignment and sizes.
69 */
70 AssertRelease(!(RT_OFFSETOF(VM, hwaccm.s) & 31));
71 AssertRelease(sizeof(pVM->hwaccm.s) <= sizeof(pVM->hwaccm.padding));
72
73 /* Some structure checks. */
74 AssertReleaseMsg(RT_OFFSETOF(SVM_VMCB, u8Reserved3) == 0xC0, ("u8Reserved3 offset = %x\n", RT_OFFSETOF(SVM_VMCB, u8Reserved3)));
75 AssertReleaseMsg(RT_OFFSETOF(SVM_VMCB, ctrl.EventInject) == 0xA8, ("ctrl.EventInject offset = %x\n", RT_OFFSETOF(SVM_VMCB, ctrl.EventInject)));
76 AssertReleaseMsg(RT_OFFSETOF(SVM_VMCB, ctrl.ExitIntInfo) == 0x88, ("ctrl.ExitIntInfo offset = %x\n", RT_OFFSETOF(SVM_VMCB, ctrl.ExitIntInfo)));
77 AssertReleaseMsg(RT_OFFSETOF(SVM_VMCB, ctrl.TLBCtrl) == 0x58, ("ctrl.TLBCtrl offset = %x\n", RT_OFFSETOF(SVM_VMCB, ctrl.TLBCtrl)));
78
79 AssertReleaseMsg(RT_OFFSETOF(SVM_VMCB, guest) == 0x400, ("guest offset = %x\n", RT_OFFSETOF(SVM_VMCB, guest)));
80 AssertReleaseMsg(RT_OFFSETOF(SVM_VMCB, guest.u8Reserved4) == 0x4A0, ("guest.u8Reserved4 offset = %x\n", RT_OFFSETOF(SVM_VMCB, guest.u8Reserved4)));
81 AssertReleaseMsg(RT_OFFSETOF(SVM_VMCB, guest.u8Reserved6) == 0x4D8, ("guest.u8Reserved6 offset = %x\n", RT_OFFSETOF(SVM_VMCB, guest.u8Reserved6)));
82 AssertReleaseMsg(RT_OFFSETOF(SVM_VMCB, guest.u8Reserved7) == 0x580, ("guest.u8Reserved7 offset = %x\n", RT_OFFSETOF(SVM_VMCB, guest.u8Reserved7)));
83 AssertReleaseMsg(RT_OFFSETOF(SVM_VMCB, guest.u8Reserved9) == 0x648, ("guest.u8Reserved9 offset = %x\n", RT_OFFSETOF(SVM_VMCB, guest.u8Reserved9)));
84 AssertReleaseMsg(RT_OFFSETOF(SVM_VMCB, u8Reserved10) == 0x698, ("u8Reserved3 offset = %x\n", RT_OFFSETOF(SVM_VMCB, u8Reserved10)));
85 AssertReleaseMsg(sizeof(SVM_VMCB) == 0x1000, ("SVM_VMCB size = %x\n", sizeof(SVM_VMCB)));
86
87
88 /*
89 * Register the saved state data unit.
90 */
91 int rc = SSMR3RegisterInternal(pVM, "HWACCM", 0, HWACCM_SSM_VERSION, sizeof(HWACCM),
92 NULL, hwaccmR3Save, NULL,
93 NULL, hwaccmR3Load, NULL);
94 if (RT_FAILURE(rc))
95 return rc;
96
97 /* Misc initialisation. */
98 pVM->hwaccm.s.vmx.fSupported = false;
99 pVM->hwaccm.s.svm.fSupported = false;
100 pVM->hwaccm.s.vmx.fEnabled = false;
101 pVM->hwaccm.s.svm.fEnabled = false;
102
103 pVM->hwaccm.s.fActive = false;
104 pVM->hwaccm.s.fNestedPaging = false;
105
106 /* Disabled by default. */
107 pVM->fHWACCMEnabled = false;
108
109 /*
110 * Check CFGM options.
111 */
112 /* Nested paging: disabled by default. */
113 rc = CFGMR3QueryBoolDef(CFGMR3GetRoot(pVM), "EnableNestedPaging", &pVM->hwaccm.s.fAllowNestedPaging, false);
114 AssertRC(rc);
115
116 /* VT-x VPID: disabled by default. */
117 rc = CFGMR3QueryBoolDef(CFGMR3GetRoot(pVM), "EnableVPID", &pVM->hwaccm.s.vmx.fAllowVPID, false);
118 AssertRC(rc);
119
120 /* HWACCM support must be explicitely enabled in the configuration file. */
121 rc = CFGMR3QueryBoolDef(CFGMR3GetChild(CFGMR3GetRoot(pVM), "HWVirtExt/"), "Enabled", &pVM->hwaccm.s.fAllowed, false);
122 AssertRC(rc);
123
124#ifdef RT_OS_DARWIN
125 if (VMMIsHwVirtExtForced(pVM) != pVM->hwaccm.s.fAllowed)
126#else
127 if (VMMIsHwVirtExtForced(pVM) && !pVM->hwaccm.s.fAllowed)
128#endif
129 {
130 AssertLogRelMsgFailed(("VMMIsHwVirtExtForced=%RTbool fAllowed=%RTbool\n",
131 VMMIsHwVirtExtForced(pVM), pVM->hwaccm.s.fAllowed));
132 return VERR_HWACCM_CONFIG_MISMATCH;
133 }
134
135 if (VMMIsHwVirtExtForced(pVM))
136 pVM->fHWACCMEnabled = true;
137
138 return VINF_SUCCESS;
139}
140
141/**
142 * Initializes the per-VCPU HWACCM.
143 *
144 * @returns VBox status code.
145 * @param pVM The VM to operate on.
146 */
147VMMR3DECL(int) HWACCMR3InitCPU(PVM pVM)
148{
149 LogFlow(("HWACCMR3InitCPU\n"));
150
151#ifdef VBOX_WITH_STATISTICS
152 /*
153 * Statistics.
154 */
155 for (unsigned i=0;i<pVM->cCPUs;i++)
156 {
157 PVMCPU pVCpu = &pVM->aCpus[i];
158 int rc;
159
160 rc = STAMR3RegisterF(pVM, &pVCpu->hwaccm.s.StatEntry, STAMTYPE_PROFILE, STAMVISIBILITY_USED, STAMUNIT_TICKS_PER_CALL, "Profiling of VMXR0RunGuestCode entry",
161 "/PROF/HWACCM/CPU%d/SwitchToGC", i);
162 AssertRC(rc);
163 rc = STAMR3RegisterF(pVM, &pVCpu->hwaccm.s.StatExit, STAMTYPE_PROFILE, STAMVISIBILITY_USED, STAMUNIT_TICKS_PER_CALL, "Profiling of VMXR0RunGuestCode exit",
164 "/PROF/HWACCM/CPU%d/SwitchFromGC", i);
165 AssertRC(rc);
166 rc = STAMR3RegisterF(pVM, &pVCpu->hwaccm.s.StatInGC, STAMTYPE_PROFILE, STAMVISIBILITY_USED, STAMUNIT_TICKS_PER_CALL, "Profiling of vmlaunch",
167 "/PROF/HWACCM/CPU%d/InGC", i);
168 AssertRC(rc);
169
170#define HWACCM_REG_COUNTER(a, b) \
171 rc = STAMR3RegisterF(pVM, a, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, "Profiling of vmlaunch", b, i); \
172 AssertRC(rc);
173
174 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitShadowNM, "/HWACCM/CPU%d/Exit/Trap/Shw/#NM");
175 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitGuestNM, "/HWACCM/CPU%d/Exit/Trap/Gst/#NM");
176 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitShadowPF, "/HWACCM/CPU%d/Exit/Trap/Shw/#PF");
177 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitGuestPF, "/HWACCM/CPU%d/Exit/Trap/Gst/#PF");
178 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitGuestUD, "/HWACCM/CPU%d/Exit/Trap/Gst/#UD");
179 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitGuestSS, "/HWACCM/CPU%d/Exit/Trap/Gst/#SS");
180 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitGuestNP, "/HWACCM/CPU%d/Exit/Trap/Gst/#NP");
181 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitGuestGP, "/HWACCM/CPU%d/Exit/Trap/Gst/#GP");
182 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitGuestMF, "/HWACCM/CPU%d/Exit/Trap/Gst/#MF");
183 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitGuestDE, "/HWACCM/CPU%d/Exit/Trap/Gst/#DE");
184 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitGuestDB, "/HWACCM/CPU%d/Exit/Trap/Gst/#DB");
185 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitInvpg, "/HWACCM/CPU%d/Exit/Instr/Invlpg");
186 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitInvd, "/HWACCM/CPU%d/Exit/Instr/Invd");
187 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitCpuid, "/HWACCM/CPU%d/Exit/Instr/Cpuid");
188 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitRdtsc, "/HWACCM/CPU%d/Exit/Instr/Rdtsc");
189 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitCRxWrite, "/HWACCM/CPU%d/Exit/Instr/CR/Write");
190 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitCRxRead, "/HWACCM/CPU%d/Exit/Instr/CR/Read");
191 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitDRxWrite, "/HWACCM/CPU%d/Exit/Instr/DR/Write");
192 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitDRxRead, "/HWACCM/CPU%d/Exit/Instr/DR/Read");
193 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitCLTS, "/HWACCM/CPU%d/Exit/Instr/CLTS");
194 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitLMSW, "/HWACCM/CPU%d/Exit/Instr/LMSW");
195 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitIOWrite, "/HWACCM/CPU%d/Exit/IO/Write");
196 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitIORead, "/HWACCM/CPU%d/Exit/IO/Read");
197 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitIOStringWrite, "/HWACCM/CPU%d/Exit/IO/WriteString");
198 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitIOStringRead, "/HWACCM/CPU%d/Exit/IO/ReadString");
199 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitIrqWindow, "/HWACCM/CPU%d/Exit/IrqWindow");
200 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitMaxResume, "/HWACCM/CPU%d/Exit/MaxResume");
201
202 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatSwitchGuestIrq, "/HWACCM/CPU%d/Switch/IrqPending");
203 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatSwitchToR3, "/HWACCM/CPU%d/Switch/ToR3");
204
205 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatIntInject, "/HWACCM/CPU%d/Irq/Inject");
206 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatIntReinject, "/HWACCM/CPU%d/Irq/Reinject");
207 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatPendingHostIrq, "/HWACCM/CPU%d/Irq/PendingOnHost");
208
209 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatFlushPageManual, "/HWACCM/CPU%d/Flush/Page/Virt");
210 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatFlushPhysPageManual, "/HWACCM/CPU%d/Flush/Page/Phys");
211 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatFlushTLBManual, "/HWACCM/CPU%d/Flush/TLB/Manual");
212 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatFlushTLBCRxChange, "/HWACCM/CPU%d/Flush/TLB/CRx");
213 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatFlushPageInvlpg, "/HWACCM/CPU%d/Flush/Page/Invlpg");
214 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatFlushTLBWorldSwitch, "/HWACCM/CPU%d/Flush/TLB/Switch");
215 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatNoFlushTLBWorldSwitch, "/HWACCM/CPU%d/Flush/TLB/Skipped");
216 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatFlushASID, "/HWACCM/CPU%d/Flush/TLB/ASID");
217 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatFlushTLBInvlpga, "/HWACCM/CPU%d/Flush/TLB/PhysInvl");
218
219 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatTSCOffset, "/HWACCM/CPU%d/TSC/Offset");
220 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatTSCIntercept, "/HWACCM/CPU%d/TSC/Intercept");
221
222 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatDRxArmed, "/HWACCM/CPU%d/Debug/Armed");
223 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatDRxContextSwitch, "/HWACCM/CPU%d/Debug/ContextSwitch");
224 HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatDRxIOCheck, "/HWACCM/CPU%d/Debug/IOCheck");
225
226#undef HWACCM_REG_COUNTER
227
228 pVCpu->hwaccm.s.paStatExitReason = NULL;
229
230 rc = MMHyperAlloc(pVM, MAX_EXITREASON_STAT*sizeof(*pVCpu->hwaccm.s.paStatExitReason), 0, MM_TAG_HWACCM, (void **)&pVCpu->hwaccm.s.paStatExitReason);
231 AssertRC(rc);
232 if (RT_SUCCESS(rc))
233 {
234 for (int j=0;j<MAX_EXITREASON_STAT;j++)
235 {
236 rc = STAMR3RegisterF(pVM, &pVCpu->hwaccm.s.paStatExitReason[j], STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_OCCURENCES, "Exit reason",
237 "/HWACCM/CPU%d/Exit/Reason/%02x", i, j);
238 AssertRC(rc);
239 }
240 rc = STAMR3RegisterF(pVM, &pVCpu->hwaccm.s.StatExitReasonNPF, STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_OCCURENCES, "Exit reason", "/HWACCM/CPU%d/Exit/Reason/#NPF", i);
241 AssertRC(rc);
242 }
243 pVCpu->hwaccm.s.paStatExitReasonR0 = MMHyperR3ToR0(pVM, pVCpu->hwaccm.s.paStatExitReason);
244 Assert(pVCpu->hwaccm.s.paStatExitReasonR0);
245 }
246#endif /* VBOX_WITH_STATISTICS */
247 return VINF_SUCCESS;
248}
249
250/**
251 * Turns off normal raw mode features
252 *
253 * @param pVM The VM to operate on.
254 */
255static void hwaccmR3DisableRawMode(PVM pVM)
256{
257 /* Disable PATM & CSAM. */
258 PATMR3AllowPatching(pVM, false);
259 CSAMDisableScanning(pVM);
260
261 /* Turn off IDT/LDT/GDT and TSS monitoring and sycing. */
262 SELMR3DisableMonitoring(pVM);
263 TRPMR3DisableMonitoring(pVM);
264
265 /* The hidden selector registers are now valid. */
266 CPUMSetHiddenSelRegsValid(pVM, true);
267
268 /* Disable the switcher code (safety precaution). */
269 VMMR3DisableSwitcher(pVM);
270
271 /* Disable mapping of the hypervisor into the shadow page table. */
272 PGMR3ChangeShwPDMappings(pVM, false);
273
274 /* Disable the switcher */
275 VMMR3DisableSwitcher(pVM);
276
277 if (pVM->hwaccm.s.fNestedPaging)
278 {
279 /* Reinit the paging mode to force the new shadow mode. */
280 PGMR3ChangeMode(pVM, PGMMODE_REAL);
281 }
282}
283
284/**
285 * Initialize VT-x or AMD-V.
286 *
287 * @returns VBox status code.
288 * @param pVM The VM handle.
289 */
290VMMR3DECL(int) HWACCMR3InitFinalizeR0(PVM pVM)
291{
292 int rc;
293
294 if ( !pVM->hwaccm.s.vmx.fSupported
295 && !pVM->hwaccm.s.svm.fSupported)
296 {
297 LogRel(("HWACCM: No VMX or SVM CPU extension found. Reason %Rrc\n", pVM->hwaccm.s.lLastError));
298 LogRel(("HWACCM: VMX MSR_IA32_FEATURE_CONTROL=%RX64\n", pVM->hwaccm.s.vmx.msr.feature_ctrl));
299 return VINF_SUCCESS;
300 }
301
302 /*
303 * Note that we have a global setting for VT-x/AMD-V usage. VMX root mode changes the way the CPU operates. Our 64 bits switcher will trap
304 * because it turns off paging, which is not allowed in VMX root mode.
305 *
306 * To simplify matters we'll just force all running VMs to either use raw or VT-x mode. No mixing allowed in the VT-x case.
307 * There's no such problem with AMD-V. (@todo)
308 *
309 */
310 /* If we enabled or disabled hwaccm mode, then it can't be changed until all the VMs are shutdown. */
311 rc = SUPCallVMMR0Ex(pVM->pVMR0, VMMR0_DO_HWACC_ENABLE, (pVM->hwaccm.s.fAllowed) ? HWACCMSTATE_ENABLED : HWACCMSTATE_DISABLED, NULL);
312 if (RT_FAILURE(rc))
313 {
314 LogRel(("HWACCMR3InitFinalize: SUPCallVMMR0Ex VMMR0_DO_HWACC_ENABLE failed with %Rrc\n", rc));
315 LogRel(("HWACCMR3InitFinalize: disallowed %s of HWACCM\n", pVM->hwaccm.s.fAllowed ? "enabling" : "disabling"));
316
317#ifdef RT_OS_DARWIN
318 /*
319 * This is 100% fatal if we didn't prepare for a HwVirtExt setup because of
320 * missing ring-0 allocations. For VMs that require HwVirtExt it doesn't normally
321 * make sense to try run them in software mode, so fail that too.
322 */
323 if (VMMIsHwVirtExtForced(pVM))
324 VM_SET_ERROR(pVM, rc, "An active VM already uses software virtualization. It is not allowed to "
325 "simultaneously use VT-x.\n");
326 else
327 VM_SET_ERROR(pVM, rc, "An active VM already uses Intel VT-x hardware acceleration. It is not "
328 "allowed to simultaneously use software virtualization.\n");
329 return rc;
330
331#else /* !RT_OS_DARWIN */
332
333 /* Invert the selection */
334 pVM->hwaccm.s.fAllowed ^= 1;
335 if (pVM->hwaccm.s.fAllowed)
336 {
337 if (pVM->hwaccm.s.vmx.fSupported)
338 VM_SET_ERROR(pVM, rc, "An active VM already uses Intel VT-x hardware acceleration. It is not allowed "
339 "to simultaneously use software virtualization.\n");
340 else
341 VM_SET_ERROR(pVM, rc, "An active VM already uses AMD-V hardware acceleration. It is not allowed to "
342 "simultaneously use software virtualization.\n");
343 }
344 else
345 VM_SET_ERROR(pVM, rc, "An active VM already uses software virtualization. It is not allowed to simultaneously "
346 "use VT-x or AMD-V.\n");
347 return rc;
348#endif /* !RT_OS_DARWIN */
349 }
350
351 if (pVM->hwaccm.s.fAllowed == false)
352 return VINF_SUCCESS; /* disabled */
353
354 Assert(!pVM->fHWACCMEnabled || VMMIsHwVirtExtForced(pVM));
355
356 if (pVM->hwaccm.s.vmx.fSupported)
357 {
358 Log(("pVM->hwaccm.s.vmx.fSupported = %d\n", pVM->hwaccm.s.vmx.fSupported));
359
360 if ( pVM->hwaccm.s.fInitialized == false
361 && pVM->hwaccm.s.vmx.msr.feature_ctrl != 0)
362 {
363 uint64_t val;
364 RTGCPHYS GCPhys = 0;
365
366 LogRel(("HWACCM: Host CR4=%08X\n", pVM->hwaccm.s.vmx.hostCR4));
367 LogRel(("HWACCM: MSR_IA32_FEATURE_CONTROL = %RX64\n", pVM->hwaccm.s.vmx.msr.feature_ctrl));
368 LogRel(("HWACCM: MSR_IA32_VMX_BASIC_INFO = %RX64\n", pVM->hwaccm.s.vmx.msr.vmx_basic_info));
369 LogRel(("HWACCM: VMCS id = %x\n", MSR_IA32_VMX_BASIC_INFO_VMCS_ID(pVM->hwaccm.s.vmx.msr.vmx_basic_info)));
370 LogRel(("HWACCM: VMCS size = %x\n", MSR_IA32_VMX_BASIC_INFO_VMCS_SIZE(pVM->hwaccm.s.vmx.msr.vmx_basic_info)));
371 LogRel(("HWACCM: VMCS physical address limit = %s\n", MSR_IA32_VMX_BASIC_INFO_VMCS_PHYS_WIDTH(pVM->hwaccm.s.vmx.msr.vmx_basic_info) ? "< 4 GB" : "None"));
372 LogRel(("HWACCM: VMCS memory type = %x\n", MSR_IA32_VMX_BASIC_INFO_VMCS_MEM_TYPE(pVM->hwaccm.s.vmx.msr.vmx_basic_info)));
373 LogRel(("HWACCM: Dual monitor treatment = %d\n", MSR_IA32_VMX_BASIC_INFO_VMCS_DUAL_MON(pVM->hwaccm.s.vmx.msr.vmx_basic_info)));
374
375 LogRel(("HWACCM: MSR_IA32_VMX_PINBASED_CTLS = %RX64\n", pVM->hwaccm.s.vmx.msr.vmx_pin_ctls.u));
376 val = pVM->hwaccm.s.vmx.msr.vmx_pin_ctls.n.allowed1;
377 if (val & VMX_VMCS_CTRL_PIN_EXEC_CONTROLS_EXT_INT_EXIT)
378 LogRel(("HWACCM: VMX_VMCS_CTRL_PIN_EXEC_CONTROLS_EXT_INT_EXIT\n"));
379 if (val & VMX_VMCS_CTRL_PIN_EXEC_CONTROLS_NMI_EXIT)
380 LogRel(("HWACCM: VMX_VMCS_CTRL_PIN_EXEC_CONTROLS_NMI_EXIT\n"));
381 val = pVM->hwaccm.s.vmx.msr.vmx_pin_ctls.n.disallowed0;
382 if (val & VMX_VMCS_CTRL_PIN_EXEC_CONTROLS_EXT_INT_EXIT)
383 LogRel(("HWACCM: VMX_VMCS_CTRL_PIN_EXEC_CONTROLS_EXT_INT_EXIT *must* be set\n"));
384 if (val & VMX_VMCS_CTRL_PIN_EXEC_CONTROLS_NMI_EXIT)
385 LogRel(("HWACCM: VMX_VMCS_CTRL_PIN_EXEC_CONTROLS_NMI_EXIT *must* be set\n"));
386
387 LogRel(("HWACCM: MSR_IA32_VMX_PROCBASED_CTLS = %RX64\n", pVM->hwaccm.s.vmx.msr.vmx_proc_ctls.u));
388 val = pVM->hwaccm.s.vmx.msr.vmx_proc_ctls.n.allowed1;
389 if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_IRQ_WINDOW_EXIT)
390 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_IRQ_WINDOW_EXIT\n"));
391 if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_TSC_OFFSET)
392 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_TSC_OFFSET\n"));
393 if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_HLT_EXIT)
394 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_HLT_EXIT\n"));
395 if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_INVLPG_EXIT)
396 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_INVLPG_EXIT\n"));
397 if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_MWAIT_EXIT)
398 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_MWAIT_EXIT\n"));
399 if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_RDPMC_EXIT)
400 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_RDPMC_EXIT\n"));
401 if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_RDTSC_EXIT)
402 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_RDTSC_EXIT\n"));
403 if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_CR3_LOAD_EXIT)
404 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_CR3_LOAD_EXIT\n"));
405 if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_CR3_STORE_EXIT)
406 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_CR3_STORE_EXIT\n"));
407 if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_CR8_LOAD_EXIT)
408 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_CR8_LOAD_EXIT\n"));
409 if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_CR8_STORE_EXIT)
410 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_CR8_STORE_EXIT\n"));
411 if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_USE_TPR_SHADOW)
412 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_USE_TPR_SHADOW\n"));
413 if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_MOV_DR_EXIT)
414 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_MOV_DR_EXIT\n"));
415 if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_UNCOND_IO_EXIT)
416 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_UNCOND_IO_EXIT\n"));
417 if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_USE_IO_BITMAPS)
418 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_USE_IO_BITMAPS\n"));
419 if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_MONITOR_TRAP_FLAG)
420 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_MONITOR_TRAP_FLAG\n"));
421 if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_USE_MSR_BITMAPS)
422 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_USE_MSR_BITMAPS\n"));
423 if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_MONITOR_EXIT)
424 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_MONITOR_EXIT\n"));
425 if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_PAUSE_EXIT)
426 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_PAUSE_EXIT\n"));
427 if (val & VMX_VMCS_CTRL_PROC_EXEC_USE_SECONDARY_EXEC_CTRL)
428 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_USE_SECONDARY_EXEC_CTRL\n"));
429
430 val = pVM->hwaccm.s.vmx.msr.vmx_proc_ctls.n.disallowed0;
431 if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_IRQ_WINDOW_EXIT)
432 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_IRQ_WINDOW_EXIT *must* be set\n"));
433 if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_TSC_OFFSET)
434 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_TSC_OFFSET *must* be set\n"));
435 if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_HLT_EXIT)
436 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_HLT_EXIT *must* be set\n"));
437 if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_INVLPG_EXIT)
438 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_INVLPG_EXIT *must* be set\n"));
439 if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_MWAIT_EXIT)
440 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_MWAIT_EXIT *must* be set\n"));
441 if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_RDPMC_EXIT)
442 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_RDPMC_EXIT *must* be set\n"));
443 if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_RDTSC_EXIT)
444 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_RDTSC_EXIT *must* be set\n"));
445 if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_CR3_LOAD_EXIT)
446 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_CR3_LOAD_EXIT *must* be set\n"));
447 if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_CR3_STORE_EXIT)
448 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_CR3_STORE_EXIT *must* be set\n"));
449 if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_CR8_LOAD_EXIT)
450 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_CR8_LOAD_EXIT *must* be set\n"));
451 if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_CR8_STORE_EXIT)
452 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_CR8_STORE_EXIT *must* be set\n"));
453 if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_USE_TPR_SHADOW)
454 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_USE_TPR_SHADOW *must* be set\n"));
455 if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_MOV_DR_EXIT)
456 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_MOV_DR_EXIT *must* be set\n"));
457 if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_UNCOND_IO_EXIT)
458 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_UNCOND_IO_EXIT *must* be set\n"));
459 if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_USE_IO_BITMAPS)
460 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_USE_IO_BITMAPS *must* be set\n"));
461 if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_MONITOR_TRAP_FLAG)
462 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_MONITOR_TRAP_FLAG *must* be set\n"));
463 if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_USE_MSR_BITMAPS)
464 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_USE_MSR_BITMAPS *must* be set\n"));
465 if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_MONITOR_EXIT)
466 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_MONITOR_EXIT *must* be set\n"));
467 if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_PAUSE_EXIT)
468 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_PAUSE_EXIT *must* be set\n"));
469 if (val & VMX_VMCS_CTRL_PROC_EXEC_USE_SECONDARY_EXEC_CTRL)
470 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_USE_SECONDARY_EXEC_CTRL *must* be set\n"));
471
472 if (pVM->hwaccm.s.vmx.msr.vmx_proc_ctls.n.allowed1 & VMX_VMCS_CTRL_PROC_EXEC_USE_SECONDARY_EXEC_CTRL)
473 {
474 LogRel(("HWACCM: MSR_IA32_VMX_PROCBASED_CTLS2 = %RX64\n", pVM->hwaccm.s.vmx.msr.vmx_proc_ctls2.u));
475 val = pVM->hwaccm.s.vmx.msr.vmx_proc_ctls2.n.allowed1;
476 if (val & VMX_VMCS_CTRL_PROC_EXEC2_VIRT_APIC)
477 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC2_VIRT_APIC\n"));
478 if (val & VMX_VMCS_CTRL_PROC_EXEC2_EPT)
479 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC2_EPT\n"));
480 if (val & VMX_VMCS_CTRL_PROC_EXEC2_VPID)
481 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC2_VPID\n"));
482 if (val & VMX_VMCS_CTRL_PROC_EXEC2_WBINVD_EXIT)
483 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC2_WBINVD_EXIT\n"));
484
485 val = pVM->hwaccm.s.vmx.msr.vmx_proc_ctls2.n.disallowed0;
486 if (val & VMX_VMCS_CTRL_PROC_EXEC2_VIRT_APIC)
487 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC2_VIRT_APIC *must* be set\n"));
488 if (val & VMX_VMCS_CTRL_PROC_EXEC2_EPT)
489 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC2_EPT *must* be set\n"));
490 if (val & VMX_VMCS_CTRL_PROC_EXEC2_VPID)
491 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC2_VPID *must* be set\n"));
492 if (val & VMX_VMCS_CTRL_PROC_EXEC2_WBINVD_EXIT)
493 LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC2_WBINVD_EXIT *must* be set\n"));
494 }
495
496 LogRel(("HWACCM: MSR_IA32_VMX_ENTRY_CTLS = %RX64\n", pVM->hwaccm.s.vmx.msr.vmx_entry.u));
497 val = pVM->hwaccm.s.vmx.msr.vmx_entry.n.allowed1;
498 if (val & VMX_VMCS_CTRL_ENTRY_CONTROLS_LOAD_DEBUG)
499 LogRel(("HWACCM: VMX_VMCS_CTRL_ENTRY_CONTROLS_LOAD_DEBUG\n"));
500 if (val & VMX_VMCS_CTRL_ENTRY_CONTROLS_IA64_MODE)
501 LogRel(("HWACCM: VMX_VMCS_CTRL_ENTRY_CONTROLS_IA64_MODE\n"));
502 if (val & VMX_VMCS_CTRL_ENTRY_CONTROLS_ENTRY_SMM)
503 LogRel(("HWACCM: VMX_VMCS_CTRL_ENTRY_CONTROLS_ENTRY_SMM\n"));
504 if (val & VMX_VMCS_CTRL_ENTRY_CONTROLS_DEACTIVATE_DUALMON)
505 LogRel(("HWACCM: VMX_VMCS_CTRL_ENTRY_CONTROLS_DEACTIVATE_DUALMON\n"));
506 if (val & VMX_VMCS_CTRL_ENTRY_CONTROLS_LOAD_GUEST_PERF_MSR)
507 LogRel(("HWACCM: VMX_VMCS_CTRL_ENTRY_CONTROLS_LOAD_GUEST_PERF_MSR\n"));
508 if (val & VMX_VMCS_CTRL_ENTRY_CONTROLS_LOAD_GUEST_PAT_MSR)
509 LogRel(("HWACCM: VMX_VMCS_CTRL_ENTRY_CONTROLS_LOAD_GUEST_PAT_MSR\n"));
510 if (val & VMX_VMCS_CTRL_ENTRY_CONTROLS_LOAD_GUEST_EFER_MSR)
511 LogRel(("HWACCM: VMX_VMCS_CTRL_ENTRY_CONTROLS_LOAD_GUEST_EFER_MSR\n"));
512 val = pVM->hwaccm.s.vmx.msr.vmx_entry.n.disallowed0;
513 if (val & VMX_VMCS_CTRL_ENTRY_CONTROLS_LOAD_DEBUG)
514 LogRel(("HWACCM: VMX_VMCS_CTRL_ENTRY_CONTROLS_LOAD_DEBUG *must* be set\n"));
515 if (val & VMX_VMCS_CTRL_ENTRY_CONTROLS_IA64_MODE)
516 LogRel(("HWACCM: VMX_VMCS_CTRL_ENTRY_CONTROLS_IA64_MODE *must* be set\n"));
517 if (val & VMX_VMCS_CTRL_ENTRY_CONTROLS_ENTRY_SMM)
518 LogRel(("HWACCM: VMX_VMCS_CTRL_ENTRY_CONTROLS_ENTRY_SMM *must* be set\n"));
519 if (val & VMX_VMCS_CTRL_ENTRY_CONTROLS_DEACTIVATE_DUALMON)
520 LogRel(("HWACCM: VMX_VMCS_CTRL_ENTRY_CONTROLS_DEACTIVATE_DUALMON *must* be set\n"));
521 if (val & VMX_VMCS_CTRL_ENTRY_CONTROLS_LOAD_GUEST_PERF_MSR)
522 LogRel(("HWACCM: VMX_VMCS_CTRL_ENTRY_CONTROLS_LOAD_GUEST_PERF_MSR *must* be set\n"));
523 if (val & VMX_VMCS_CTRL_ENTRY_CONTROLS_LOAD_GUEST_PAT_MSR)
524 LogRel(("HWACCM: VMX_VMCS_CTRL_ENTRY_CONTROLS_LOAD_GUEST_PAT_MSR *must* be set\n"));
525 if (val & VMX_VMCS_CTRL_ENTRY_CONTROLS_LOAD_GUEST_EFER_MSR)
526 LogRel(("HWACCM: VMX_VMCS_CTRL_ENTRY_CONTROLS_LOAD_GUEST_EFER_MSR *must* be set\n"));
527
528 LogRel(("HWACCM: MSR_IA32_VMX_EXIT_CTLS = %RX64\n", pVM->hwaccm.s.vmx.msr.vmx_exit.u));
529 val = pVM->hwaccm.s.vmx.msr.vmx_exit.n.allowed1;
530 if (val & VMX_VMCS_CTRL_EXIT_CONTROLS_SAVE_DEBUG)
531 LogRel(("HWACCM: VMX_VMCS_CTRL_EXIT_CONTROLS_SAVE_DEBUG\n"));
532 if (val & VMX_VMCS_CTRL_EXIT_CONTROLS_HOST_AMD64)
533 LogRel(("HWACCM: VMX_VMCS_CTRL_EXIT_CONTROLS_HOST_AMD64\n"));
534 if (val & VMX_VMCS_CTRL_EXIT_CONTROLS_ACK_EXTERNAL_IRQ)
535 LogRel(("HWACCM: VMX_VMCS_CTRL_EXIT_CONTROLS_ACK_EXTERNAL_IRQ\n"));
536 if (val & VMX_VMCS_CTRL_EXIT_CONTROLS_SAVE_GUEST_PAT_MSR)
537 LogRel(("HWACCM: VMX_VMCS_CTRL_EXIT_CONTROLS_SAVE_GUEST_PAT_MSR\n"));
538 if (val & VMX_VMCS_CTRL_EXIT_CONTROLS_LOAD_HOST_PAT_MSR)
539 LogRel(("HWACCM: VMX_VMCS_CTRL_EXIT_CONTROLS_LOAD_HOST_PAT_MSR\n"));
540 if (val & VMX_VMCS_CTRL_EXIT_CONTROLS_SAVE_GUEST_EFER_MSR)
541 LogRel(("HWACCM: VMX_VMCS_CTRL_EXIT_CONTROLS_SAVE_GUEST_EFER_MSR\n"));
542 if (val & VMX_VMCS_CTRL_EXIT_CONTROLS_LOAD_HOST_EFER_MSR)
543 LogRel(("HWACCM: VMX_VMCS_CTRL_EXIT_CONTROLS_LOAD_HOST_EFER_MSR\n"));
544 if (val & VMX_VMCS_CTRL_EXIT_CONTROLS_SAVE_VMX_PREEMPT_TIMER)
545 LogRel(("HWACCM: VMX_VMCS_CTRL_EXIT_CONTROLS_SAVE_VMX_PREEMPT_TIMER\n"));
546 val = pVM->hwaccm.s.vmx.msr.vmx_exit.n.disallowed0;
547 if (val & VMX_VMCS_CTRL_EXIT_CONTROLS_SAVE_DEBUG)
548 LogRel(("HWACCM: VMX_VMCS_CTRL_EXIT_CONTROLS_SAVE_DEBUG *must* be set\n"));
549 if (val & VMX_VMCS_CTRL_EXIT_CONTROLS_HOST_AMD64)
550 LogRel(("HWACCM: VMX_VMCS_CTRL_EXIT_CONTROLS_HOST_AMD64 *must* be set\n"));
551 if (val & VMX_VMCS_CTRL_EXIT_CONTROLS_ACK_EXTERNAL_IRQ)
552 LogRel(("HWACCM: VMX_VMCS_CTRL_EXIT_CONTROLS_ACK_EXTERNAL_IRQ *must* be set\n"));
553 if (val & VMX_VMCS_CTRL_EXIT_CONTROLS_SAVE_GUEST_PAT_MSR)
554 LogRel(("HWACCM: VMX_VMCS_CTRL_EXIT_CONTROLS_SAVE_GUEST_PAT_MSR *must* be set\n"));
555 if (val & VMX_VMCS_CTRL_EXIT_CONTROLS_LOAD_HOST_PAT_MSR)
556 LogRel(("HWACCM: VMX_VMCS_CTRL_EXIT_CONTROLS_LOAD_HOST_PAT_MSR *must* be set\n"));
557 if (val & VMX_VMCS_CTRL_EXIT_CONTROLS_SAVE_GUEST_EFER_MSR)
558 LogRel(("HWACCM: VMX_VMCS_CTRL_EXIT_CONTROLS_SAVE_GUEST_EFER_MSR *must* be set\n"));
559 if (val & VMX_VMCS_CTRL_EXIT_CONTROLS_LOAD_HOST_EFER_MSR)
560 LogRel(("HWACCM: VMX_VMCS_CTRL_EXIT_CONTROLS_LOAD_HOST_EFER_MSR *must* be set\n"));
561 if (val & VMX_VMCS_CTRL_EXIT_CONTROLS_SAVE_VMX_PREEMPT_TIMER)
562 LogRel(("HWACCM: VMX_VMCS_CTRL_EXIT_CONTROLS_SAVE_VMX_PREEMPT_TIMER *must* be set\n"));
563
564 if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps)
565 {
566 LogRel(("HWACCM: MSR_IA32_VMX_EPT_VPID_CAPS = %RX64\n", pVM->hwaccm.s.vmx.msr.vmx_eptcaps));
567
568 if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_RWX_X_ONLY)
569 LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_RWX_X_ONLY\n"));
570 if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_RWX_W_ONLY)
571 LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_RWX_W_ONLY\n"));
572 if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_RWX_WX_ONLY)
573 LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_RWX_WX_ONLY\n"));
574 if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_GAW_21_BITS)
575 LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_GAW_21_BITS\n"));
576 if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_GAW_30_BITS)
577 LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_GAW_30_BITS\n"));
578 if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_GAW_39_BITS)
579 LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_GAW_39_BITS\n"));
580 if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_GAW_48_BITS)
581 LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_GAW_48_BITS\n"));
582 if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_GAW_57_BITS)
583 LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_GAW_57_BITS\n"));
584 if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_EMT_UC)
585 LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_EMT_UC\n"));
586 if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_EMT_WC)
587 LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_EMT_WC\n"));
588 if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_EMT_WT)
589 LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_EMT_WT\n"));
590 if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_EMT_WP)
591 LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_EMT_WP\n"));
592 if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_EMT_WB)
593 LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_EMT_WB\n"));
594 if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_SP_21_BITS)
595 LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_SP_21_BITS\n"));
596 if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_SP_30_BITS)
597 LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_SP_30_BITS\n"));
598 if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_SP_39_BITS)
599 LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_SP_39_BITS\n"));
600 if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_SP_48_BITS)
601 LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_SP_48_BITS\n"));
602 if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_INVEPT)
603 LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_INVEPT\n"));
604 if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_INVEPT_CAPS_INDIV)
605 LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_INVEPT_CAPS_INDIV\n"));
606 if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_INVEPT_CAPS_CONTEXT)
607 LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_INVEPT_CAPS_CONTEXT\n"));
608 if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_INVEPT_CAPS_ALL)
609 LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_INVEPT_CAPS_ALL\n"));
610 if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_INVVPID)
611 LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_INVVPID\n"));
612 if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_INVVPID_CAPS_INDIV)
613 LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_INVVPID_CAPS_INDIV\n"));
614 if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_INVVPID_CAPS_CONTEXT)
615 LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_INVVPID_CAPS_CONTEXT\n"));
616 if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_INVVPID_CAPS_ALL)
617 LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_INVVPID_CAPS_ALL\n"));
618 if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_INVVPID_CAPS_CONTEXT_GLOBAL)
619 LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_INVVPID_CAPS_CONTEXT_GLOBAL\n"));
620 }
621
622 LogRel(("HWACCM: MSR_IA32_VMX_MISC = %RX64\n", pVM->hwaccm.s.vmx.msr.vmx_misc));
623 LogRel(("HWACCM: MSR_IA32_VMX_MISC_ACTIVITY_STATES %x\n", MSR_IA32_VMX_MISC_ACTIVITY_STATES(pVM->hwaccm.s.vmx.msr.vmx_misc)));
624 LogRel(("HWACCM: MSR_IA32_VMX_MISC_CR3_TARGET %x\n", MSR_IA32_VMX_MISC_CR3_TARGET(pVM->hwaccm.s.vmx.msr.vmx_misc)));
625 LogRel(("HWACCM: MSR_IA32_VMX_MISC_MAX_MSR %x\n", MSR_IA32_VMX_MISC_MAX_MSR(pVM->hwaccm.s.vmx.msr.vmx_misc)));
626 LogRel(("HWACCM: MSR_IA32_VMX_MISC_MSEG_ID %x\n", MSR_IA32_VMX_MISC_MSEG_ID(pVM->hwaccm.s.vmx.msr.vmx_misc)));
627
628 LogRel(("HWACCM: MSR_IA32_VMX_CR0_FIXED0 = %RX64\n", pVM->hwaccm.s.vmx.msr.vmx_cr0_fixed0));
629 LogRel(("HWACCM: MSR_IA32_VMX_CR0_FIXED1 = %RX64\n", pVM->hwaccm.s.vmx.msr.vmx_cr0_fixed1));
630 LogRel(("HWACCM: MSR_IA32_VMX_CR4_FIXED0 = %RX64\n", pVM->hwaccm.s.vmx.msr.vmx_cr4_fixed0));
631 LogRel(("HWACCM: MSR_IA32_VMX_CR4_FIXED1 = %RX64\n", pVM->hwaccm.s.vmx.msr.vmx_cr4_fixed1));
632 LogRel(("HWACCM: MSR_IA32_VMX_VMCS_ENUM = %RX64\n", pVM->hwaccm.s.vmx.msr.vmx_vmcs_enum));
633
634 LogRel(("HWACCM: TPR shadow physaddr = %RHp\n", pVM->hwaccm.s.vmx.pAPICPhys));
635 LogRel(("HWACCM: MSR bitmap physaddr = %RHp\n", pVM->hwaccm.s.vmx.pMSRBitmapPhys));
636
637 for (unsigned i=0;i<pVM->cCPUs;i++)
638 LogRel(("HWACCM: VMCS physaddr VCPU%d = %RHp\n", i, pVM->aCpus[i].hwaccm.s.vmx.pVMCSPhys));
639
640#ifdef HWACCM_VTX_WITH_EPT
641 if (pVM->hwaccm.s.vmx.msr.vmx_proc_ctls2.n.allowed1 & VMX_VMCS_CTRL_PROC_EXEC2_EPT)
642 pVM->hwaccm.s.fNestedPaging = pVM->hwaccm.s.fAllowNestedPaging;
643#endif /* HWACCM_VTX_WITH_EPT */
644#ifdef HWACCM_VTX_WITH_VPID
645 if ( (pVM->hwaccm.s.vmx.msr.vmx_proc_ctls2.n.allowed1 & VMX_VMCS_CTRL_PROC_EXEC2_VPID)
646 && !pVM->hwaccm.s.fNestedPaging) /* VPID and EPT are mutually exclusive. */
647 pVM->hwaccm.s.vmx.fVPID = pVM->hwaccm.s.vmx.fAllowVPID;
648#endif /* HWACCM_VTX_WITH_VPID */
649
650 /* Only try once. */
651 pVM->hwaccm.s.fInitialized = true;
652
653 /* Allocate three pages for the TSS we need for real mode emulation. (2 page for the IO bitmap) */
654 rc = PDMR3VMMDevHeapAlloc(pVM, HWACCM_VTX_TOTAL_DEVHEAP_MEM, (RTR3PTR *)&pVM->hwaccm.s.vmx.pRealModeTSS);
655 AssertRC(rc);
656 if (RT_FAILURE(rc))
657 return rc;
658
659 /* The I/O bitmap starts right after the virtual interrupt redirection bitmap. */
660 ASMMemZero32(pVM->hwaccm.s.vmx.pRealModeTSS, sizeof(*pVM->hwaccm.s.vmx.pRealModeTSS));
661 pVM->hwaccm.s.vmx.pRealModeTSS->offIoBitmap = sizeof(*pVM->hwaccm.s.vmx.pRealModeTSS);
662 /* Bit set to 0 means redirection enabled. */
663 memset(pVM->hwaccm.s.vmx.pRealModeTSS->IntRedirBitmap, 0x0, sizeof(pVM->hwaccm.s.vmx.pRealModeTSS->IntRedirBitmap));
664 /* Allow all port IO, so the VT-x IO intercepts do their job. */
665 memset(pVM->hwaccm.s.vmx.pRealModeTSS + 1, 0, PAGE_SIZE*2);
666 *((unsigned char *)pVM->hwaccm.s.vmx.pRealModeTSS + HWACCM_VTX_TSS_SIZE - 2) = 0xff;
667
668 /* Construct a 1024 element page directory with 4 MB pages for the identity mapped page table used in
669 * real and protected mode without paging with EPT.
670 */
671 pVM->hwaccm.s.vmx.pNonPagingModeEPTPageTable = (PX86PD)((char *)pVM->hwaccm.s.vmx.pRealModeTSS + PAGE_SIZE * 3);
672 for (unsigned i=0;i<X86_PG_ENTRIES;i++)
673 {
674 pVM->hwaccm.s.vmx.pNonPagingModeEPTPageTable->a[i].u = _4M * i;
675 pVM->hwaccm.s.vmx.pNonPagingModeEPTPageTable->a[i].u |= X86_PDE4M_P | X86_PDE4M_RW | X86_PDE4M_US | X86_PDE4M_A | X86_PDE4M_D | X86_PDE4M_PS | X86_PDE4M_G;
676 }
677
678 /* We convert it here every time as pci regions could be reconfigured. */
679 rc = PDMVMMDevHeapR3ToGCPhys(pVM, pVM->hwaccm.s.vmx.pRealModeTSS, &GCPhys);
680 AssertRC(rc);
681 LogRel(("HWACCM: Real Mode TSS guest physaddr = %RGp\n", GCPhys));
682
683 rc = PDMVMMDevHeapR3ToGCPhys(pVM, pVM->hwaccm.s.vmx.pNonPagingModeEPTPageTable, &GCPhys);
684 AssertRC(rc);
685 LogRel(("HWACCM: Non-Paging Mode EPT CR3 = %RGp\n", GCPhys));
686
687 rc = SUPCallVMMR0Ex(pVM->pVMR0, VMMR0_DO_HWACC_SETUP_VM, 0, NULL);
688 AssertRC(rc);
689 if (rc == VINF_SUCCESS)
690 {
691 pVM->fHWACCMEnabled = true;
692 pVM->hwaccm.s.vmx.fEnabled = true;
693 hwaccmR3DisableRawMode(pVM);
694
695 CPUMSetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_SEP);
696#ifdef VBOX_ENABLE_64_BITS_GUESTS
697 CPUMSetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_PAE);
698 CPUMSetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_LONG_MODE);
699 CPUMSetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_SYSCALL); /* 64 bits only on Intel CPUs */
700 CPUMSetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_LAHF);
701 CPUMSetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_NXE);
702#endif
703 LogRel(("HWACCM: VMX enabled!\n"));
704 if (pVM->hwaccm.s.fNestedPaging)
705 {
706 LogRel(("HWACCM: Enabled nested paging\n"));
707 LogRel(("HWACCM: EPT root page = %RHp\n", PGMGetEPTCR3(pVM)));
708 }
709 if (pVM->hwaccm.s.vmx.fVPID)
710 LogRel(("HWACCM: Enabled VPID\n"));
711
712 if ( pVM->hwaccm.s.fNestedPaging
713 || pVM->hwaccm.s.vmx.fVPID)
714 {
715 LogRel(("HWACCM: enmFlushPage %d\n", pVM->hwaccm.s.vmx.enmFlushPage));
716 LogRel(("HWACCM: enmFlushContext %d\n", pVM->hwaccm.s.vmx.enmFlushContext));
717 }
718 }
719 else
720 {
721 LogRel(("HWACCM: VMX setup failed with rc=%Rrc!\n", rc));
722 LogRel(("HWACCM: Last instruction error %x\n", pVM->aCpus[0].hwaccm.s.vmx.lasterror.ulInstrError));
723 pVM->fHWACCMEnabled = false;
724 }
725 }
726 }
727 else
728 if (pVM->hwaccm.s.svm.fSupported)
729 {
730 Log(("pVM->hwaccm.s.svm.fSupported = %d\n", pVM->hwaccm.s.svm.fSupported));
731
732 if (pVM->hwaccm.s.fInitialized == false)
733 {
734 /* Erratum 170 which requires a forced TLB flush for each world switch:
735 * See http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/33610.pdf
736 *
737 * All BH-G1/2 and DH-G1/2 models include a fix:
738 * Athlon X2: 0x6b 1/2
739 * 0x68 1/2
740 * Athlon 64: 0x7f 1
741 * 0x6f 2
742 * Sempron: 0x7f 1/2
743 * 0x6f 2
744 * 0x6c 2
745 * 0x7c 2
746 * Turion 64: 0x68 2
747 *
748 */
749 uint32_t u32Dummy;
750 uint32_t u32Version, u32Family, u32Model, u32Stepping, u32BaseFamily;
751 ASMCpuId(1, &u32Version, &u32Dummy, &u32Dummy, &u32Dummy);
752 u32BaseFamily= (u32Version >> 8) & 0xf;
753 u32Family = u32BaseFamily + (u32BaseFamily == 0xf ? ((u32Version >> 20) & 0x7f) : 0);
754 u32Model = ((u32Version >> 4) & 0xf);
755 u32Model = u32Model | ((u32BaseFamily == 0xf ? (u32Version >> 16) & 0x0f : 0) << 4);
756 u32Stepping = u32Version & 0xf;
757 if ( u32Family == 0xf
758 && !((u32Model == 0x68 || u32Model == 0x6b || u32Model == 0x7f) && u32Stepping >= 1)
759 && !((u32Model == 0x6f || u32Model == 0x6c || u32Model == 0x7c) && u32Stepping >= 2))
760 {
761 LogRel(("HWACMM: AMD cpu with erratum 170 family %x model %x stepping %x\n", u32Family, u32Model, u32Stepping));
762 }
763
764 LogRel(("HWACMM: cpuid 0x80000001.u32AMDFeatureECX = %RX32\n", pVM->hwaccm.s.cpuid.u32AMDFeatureECX));
765 LogRel(("HWACMM: cpuid 0x80000001.u32AMDFeatureEDX = %RX32\n", pVM->hwaccm.s.cpuid.u32AMDFeatureEDX));
766 LogRel(("HWACCM: SVM revision = %X\n", pVM->hwaccm.s.svm.u32Rev));
767 LogRel(("HWACCM: SVM max ASID = %d\n", pVM->hwaccm.s.uMaxASID));
768 LogRel(("HWACCM: SVM features = %X\n", pVM->hwaccm.s.svm.u32Features));
769
770 if (pVM->hwaccm.s.svm.u32Features & AMD_CPUID_SVM_FEATURE_EDX_NESTED_PAGING)
771 LogRel(("HWACCM: AMD_CPUID_SVM_FEATURE_EDX_NESTED_PAGING\n"));
772 if (pVM->hwaccm.s.svm.u32Features & AMD_CPUID_SVM_FEATURE_EDX_LBR_VIRT)
773 LogRel(("HWACCM: AMD_CPUID_SVM_FEATURE_EDX_LBR_VIRT\n"));
774 if (pVM->hwaccm.s.svm.u32Features & AMD_CPUID_SVM_FEATURE_EDX_SVM_LOCK)
775 LogRel(("HWACCM: AMD_CPUID_SVM_FEATURE_EDX_SVM_LOCK\n"));
776 if (pVM->hwaccm.s.svm.u32Features & AMD_CPUID_SVM_FEATURE_EDX_NRIP_SAVE)
777 LogRel(("HWACCM: AMD_CPUID_SVM_FEATURE_EDX_NRIP_SAVE\n"));
778 if (pVM->hwaccm.s.svm.u32Features & AMD_CPUID_SVM_FEATURE_EDX_SSE_3_5_DISABLE)
779 LogRel(("HWACCM: AMD_CPUID_SVM_FEATURE_EDX_SSE_3_5_DISABLE\n"));
780
781 /* Only try once. */
782 pVM->hwaccm.s.fInitialized = true;
783
784 if (pVM->hwaccm.s.svm.u32Features & AMD_CPUID_SVM_FEATURE_EDX_NESTED_PAGING)
785 pVM->hwaccm.s.fNestedPaging = pVM->hwaccm.s.fAllowNestedPaging;
786
787 rc = SUPCallVMMR0Ex(pVM->pVMR0, VMMR0_DO_HWACC_SETUP_VM, 0, NULL);
788 AssertRC(rc);
789 if (rc == VINF_SUCCESS)
790 {
791 pVM->fHWACCMEnabled = true;
792 pVM->hwaccm.s.svm.fEnabled = true;
793
794 if (pVM->hwaccm.s.fNestedPaging)
795 LogRel(("HWACCM: Enabled nested paging\n"));
796
797 hwaccmR3DisableRawMode(pVM);
798 CPUMSetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_SEP);
799 CPUMSetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_SYSCALL);
800 CPUMSetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_RDTSCP);
801#ifdef VBOX_ENABLE_64_BITS_GUESTS
802 CPUMSetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_PAE);
803 CPUMSetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_LONG_MODE);
804 CPUMSetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_NXE);
805 CPUMSetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_LAHF);
806#endif
807 }
808 else
809 {
810 pVM->fHWACCMEnabled = false;
811 }
812 }
813 }
814
815#if HC_ARCH_BITS == 32 && defined(VBOX_ENABLE_64_BITS_GUESTS)
816 if (pVM->fHWACCMEnabled)
817 {
818 switch(PGMGetHostMode(pVM))
819 {
820 case PGMMODE_32_BIT:
821 pVM->hwaccm.s.pfnHost32ToGuest64R0 = VMMR3GetHostToGuestSwitcher(pVM, VMMSWITCHER_32_TO_AMD64);
822 break;
823
824 case PGMMODE_PAE:
825 case PGMMODE_PAE_NX:
826 pVM->hwaccm.s.pfnHost32ToGuest64R0 = VMMR3GetHostToGuestSwitcher(pVM, VMMSWITCHER_PAE_TO_AMD64);
827 break;
828
829 default:
830 AssertFailed();
831 break;
832 }
833
834 rc = PDMR3LdrGetSymbolRC(pVM, NULL, "VMXGCStartVM64", &pVM->hwaccm.s.pfnVMXGCStartVM64);
835 AssertMsgRCReturn(rc, ("VMXGCStartVM64 -> rc=%Rrc\n", rc), rc);
836
837 rc = PDMR3LdrGetSymbolRC(pVM, NULL, "SVMGCVMRun64", &pVM->hwaccm.s.pfnSVMGCVMRun64);
838 AssertMsgRCReturn(rc, ("SVMGCVMRun64 -> rc=%Rrc\n", rc), rc);
839
840 rc = PDMR3LdrGetSymbolRC(pVM, NULL, "HWACCMSaveGuestFPU64", &pVM->hwaccm.s.pfnSaveGuestFPU64);
841 AssertMsgRCReturn(rc, ("HWACCMSetupFPU64 -> rc=%Rrc\n", rc), rc);
842
843 rc = PDMR3LdrGetSymbolRC(pVM, NULL, "HWACCMSaveGuestDebug64", &pVM->hwaccm.s.pfnSaveGuestDebug64);
844 AssertMsgRCReturn(rc, ("HWACCMSetupDebug64 -> rc=%Rrc\n", rc), rc);
845
846#ifdef DEBUG
847 rc = PDMR3LdrGetSymbolRC(pVM, NULL, "HWACCMTestSwitcher64", &pVM->hwaccm.s.pfnTest64);
848 AssertMsgRCReturn(rc, ("HWACCMTestSwitcher64 -> rc=%Rrc\n", rc), rc);
849#endif
850 }
851#endif
852 return VINF_SUCCESS;
853}
854
855/**
856 * Applies relocations to data and code managed by this
857 * component. This function will be called at init and
858 * whenever the VMM need to relocate it self inside the GC.
859 *
860 * @param pVM The VM.
861 */
862VMMR3DECL(void) HWACCMR3Relocate(PVM pVM)
863{
864 Log(("HWACCMR3Relocate to %RGv\n", MMHyperGetArea(pVM, 0)));
865
866 /* Fetch the current paging mode during the relocate callback during state loading. */
867 if (VMR3GetState(pVM) == VMSTATE_LOADING)
868 {
869 for (unsigned i=0;i<pVM->cCPUs;i++)
870 {
871 PVMCPU pVCpu = &pVM->aCpus[i];
872 /* @todo SMP */
873 pVCpu->hwaccm.s.enmShadowMode = PGMGetShadowMode(pVM);
874 pVCpu->hwaccm.s.vmx.enmCurrGuestMode = PGMGetGuestMode(pVM);
875 }
876 }
877
878 return;
879}
880
881/**
882 * Checks hardware accelerated raw mode is allowed.
883 *
884 * @returns boolean
885 * @param pVM The VM to operate on.
886 */
887VMMR3DECL(bool) HWACCMR3IsAllowed(PVM pVM)
888{
889 return pVM->hwaccm.s.fAllowed;
890}
891
892/**
893 * Notification callback which is called whenever there is a chance that a CR3
894 * value might have changed.
895 *
896 * This is called by PGM.
897 *
898 * @param pVM The VM to operate on.
899 * @param enmShadowMode New shadow paging mode.
900 * @param enmGuestMode New guest paging mode.
901 */
902VMMR3DECL(void) HWACCMR3PagingModeChanged(PVM pVM, PGMMODE enmShadowMode, PGMMODE enmGuestMode)
903{
904 /* Ignore page mode changes during state loading. */
905 if (VMR3GetState(pVM) == VMSTATE_LOADING)
906 return;
907
908 PVMCPU pVCpu = VMMGetCpu(pVM);
909 pVCpu->hwaccm.s.enmShadowMode = enmShadowMode;
910
911 if ( pVM->hwaccm.s.vmx.fEnabled
912 && pVM->fHWACCMEnabled)
913 {
914 if ( pVCpu->hwaccm.s.vmx.enmCurrGuestMode == PGMMODE_REAL
915 && enmGuestMode >= PGMMODE_PROTECTED)
916 {
917 PCPUMCTX pCtx;
918
919 pCtx = CPUMQueryGuestCtxPtr(pVM);
920
921 /* After a real mode switch to protected mode we must force
922 * CPL to 0. Our real mode emulation had to set it to 3.
923 */
924 pCtx->ssHid.Attr.n.u2Dpl = 0;
925 }
926 }
927}
928
929/**
930 * Terminates the HWACCM.
931 *
932 * Termination means cleaning up and freeing all resources,
933 * the VM it self is at this point powered off or suspended.
934 *
935 * @returns VBox status code.
936 * @param pVM The VM to operate on.
937 */
938VMMR3DECL(int) HWACCMR3Term(PVM pVM)
939{
940 if (pVM->hwaccm.s.vmx.pRealModeTSS)
941 {
942 PDMR3VMMDevHeapFree(pVM, pVM->hwaccm.s.vmx.pRealModeTSS);
943 pVM->hwaccm.s.vmx.pRealModeTSS = 0;
944 }
945 return 0;
946}
947
948/**
949 * Terminates the per-VCPU HWACCM.
950 *
951 * Termination means cleaning up and freeing all resources,
952 * the VM it self is at this point powered off or suspended.
953 *
954 * @returns VBox status code.
955 * @param pVM The VM to operate on.
956 */
957VMMR3DECL(int) HWACCMR3TermCPU(PVM pVM)
958{
959 for (unsigned i=0;i<pVM->cCPUs;i++)
960 {
961 PVMCPU pVCpu = &pVM->aCpus[i];
962
963 if (pVCpu->hwaccm.s.paStatExitReason)
964 {
965 MMHyperFree(pVM, pVCpu->hwaccm.s.paStatExitReason);
966 pVCpu->hwaccm.s.paStatExitReason = NULL;
967 pVCpu->hwaccm.s.paStatExitReasonR0 = NIL_RTR0PTR;
968 }
969 }
970 return 0;
971}
972
973/**
974 * The VM is being reset.
975 *
976 * For the HWACCM component this means that any GDT/LDT/TSS monitors
977 * needs to be removed.
978 *
979 * @param pVM VM handle.
980 */
981VMMR3DECL(void) HWACCMR3Reset(PVM pVM)
982{
983 LogFlow(("HWACCMR3Reset:\n"));
984
985 if (pVM->fHWACCMEnabled)
986 hwaccmR3DisableRawMode(pVM);
987
988 for (unsigned i=0;i<pVM->cCPUs;i++)
989 {
990 PVMCPU pVCpu = &pVM->aCpus[i];
991
992 /* On first entry we'll sync everything. */
993 pVCpu->hwaccm.s.fContextUseFlags = HWACCM_CHANGED_ALL;
994
995 pVCpu->hwaccm.s.vmx.cr0_mask = 0;
996 pVCpu->hwaccm.s.vmx.cr4_mask = 0;
997
998 pVCpu->hwaccm.s.Event.fPending = false;
999
1000 /* Reset state information for real-mode emulation in VT-x. */
1001 pVCpu->hwaccm.s.vmx.enmCurrGuestMode = PGMMODE_REAL;
1002 }
1003}
1004
1005/**
1006 * Checks if we can currently use hardware accelerated raw mode.
1007 *
1008 * @returns boolean
1009 * @param pVM The VM to operate on.
1010 * @param pCtx Partial VM execution context
1011 */
1012VMMR3DECL(bool) HWACCMR3CanExecuteGuest(PVM pVM, PCPUMCTX pCtx)
1013{
1014 Assert(pVM->fHWACCMEnabled);
1015
1016 /* AMD SVM supports real & protected mode with or without paging. */
1017 if (pVM->hwaccm.s.svm.fEnabled)
1018 {
1019 pVM->hwaccm.s.fActive = true;
1020 return true;
1021 }
1022
1023 pVM->hwaccm.s.fActive = false;
1024
1025 /* Note! The context supplied by REM is partial. If we add more checks here, be sure to verify that REM provides this info! */
1026#ifdef HWACCM_VMX_EMULATE_REALMODE
1027 if (CPUMIsGuestInRealModeEx(pCtx))
1028 {
1029 /* VT-x will not allow high selector bases in v86 mode; fall back to the recompiler in that case.
1030 * The base must also be equal to (sel << 4).
1031 */
1032 if ( ( pCtx->cs != (pCtx->csHid.u64Base >> 4)
1033 && pCtx->csHid.u64Base != 0xffff0000 /* we can deal with the BIOS code as it's also mapped into the lower region. */)
1034 || pCtx->ds != (pCtx->dsHid.u64Base >> 4)
1035 || pCtx->es != (pCtx->esHid.u64Base >> 4)
1036 || pCtx->fs != (pCtx->fsHid.u64Base >> 4)
1037 || pCtx->gs != (pCtx->gsHid.u64Base >> 4)
1038 || pCtx->ss != (pCtx->ssHid.u64Base >> 4))
1039 return false;
1040 }
1041 else
1042 {
1043 PGMMODE enmGuestMode = PGMGetGuestMode(pVM);
1044 /* Verify the requirements for executing code in protected mode. VT-x can't handle the CPU state right after a switch
1045 * from real to protected mode. (all sorts of RPL & DPL assumptions)
1046 */
1047 PVMCPU pVCpu = VMMGetCpu(pVM);
1048
1049 if ( pVCpu->hwaccm.s.vmx.enmCurrGuestMode == PGMMODE_REAL
1050 && enmGuestMode >= PGMMODE_PROTECTED)
1051 {
1052 if ( (pCtx->cs & X86_SEL_RPL)
1053 || (pCtx->ds & X86_SEL_RPL)
1054 || (pCtx->es & X86_SEL_RPL)
1055 || (pCtx->fs & X86_SEL_RPL)
1056 || (pCtx->gs & X86_SEL_RPL)
1057 || (pCtx->ss & X86_SEL_RPL))
1058 {
1059 return false;
1060 }
1061 }
1062 }
1063#else
1064 if (!CPUMIsGuestInLongModeEx(pCtx))
1065 {
1066 /* Too early for VT-x; Solaris guests will fail with a guru meditation otherwise; same for XP. */
1067 if (pCtx->idtr.pIdt == 0 || pCtx->idtr.cbIdt == 0 || pCtx->tr == 0)
1068 return false;
1069
1070 /* The guest is about to complete the switch to protected mode. Wait a bit longer. */
1071 /* Windows XP; switch to protected mode; all selectors are marked not present in the
1072 * hidden registers (possible recompiler bug; see load_seg_vm) */
1073 if (pCtx->csHid.Attr.n.u1Present == 0)
1074 return false;
1075 if (pCtx->ssHid.Attr.n.u1Present == 0)
1076 return false;
1077 }
1078#endif
1079
1080 if (pVM->hwaccm.s.vmx.fEnabled)
1081 {
1082 uint32_t mask;
1083
1084 /* if bit N is set in cr0_fixed0, then it must be set in the guest's cr0. */
1085 mask = (uint32_t)pVM->hwaccm.s.vmx.msr.vmx_cr0_fixed0;
1086 /* Note: We ignore the NE bit here on purpose; see vmmr0\hwaccmr0.cpp for details. */
1087 mask &= ~X86_CR0_NE;
1088
1089#ifdef HWACCM_VMX_EMULATE_REALMODE
1090 /* Note: We ignore the PE & PG bits here on purpose; we emulate real and protected mode without paging. */
1091 mask &= ~(X86_CR0_PG|X86_CR0_PE);
1092#else
1093 /* We support protected mode without paging using identity mapping. */
1094 mask &= ~X86_CR0_PG;
1095#endif
1096 if ((pCtx->cr0 & mask) != mask)
1097 return false;
1098
1099 /* if bit N is cleared in cr0_fixed1, then it must be zero in the guest's cr0. */
1100 mask = (uint32_t)~pVM->hwaccm.s.vmx.msr.vmx_cr0_fixed1;
1101 if ((pCtx->cr0 & mask) != 0)
1102 return false;
1103
1104 /* if bit N is set in cr4_fixed0, then it must be set in the guest's cr4. */
1105 mask = (uint32_t)pVM->hwaccm.s.vmx.msr.vmx_cr4_fixed0;
1106 mask &= ~X86_CR4_VMXE;
1107 if ((pCtx->cr4 & mask) != mask)
1108 return false;
1109
1110 /* if bit N is cleared in cr4_fixed1, then it must be zero in the guest's cr4. */
1111 mask = (uint32_t)~pVM->hwaccm.s.vmx.msr.vmx_cr4_fixed1;
1112 if ((pCtx->cr4 & mask) != 0)
1113 return false;
1114
1115 pVM->hwaccm.s.fActive = true;
1116 return true;
1117 }
1118
1119 return false;
1120}
1121
1122/**
1123 * Checks if we are currently using hardware accelerated raw mode.
1124 *
1125 * @returns boolean
1126 * @param pVM The VM to operate on.
1127 */
1128VMMR3DECL(bool) HWACCMR3IsActive(PVM pVM)
1129{
1130 return pVM->hwaccm.s.fActive;
1131}
1132
1133/**
1134 * Checks if we are currently using nested paging.
1135 *
1136 * @returns boolean
1137 * @param pVM The VM to operate on.
1138 */
1139VMMR3DECL(bool) HWACCMR3IsNestedPagingActive(PVM pVM)
1140{
1141 return pVM->hwaccm.s.fNestedPaging;
1142}
1143
1144/**
1145 * Checks if we are currently using VPID in VT-x mode.
1146 *
1147 * @returns boolean
1148 * @param pVM The VM to operate on.
1149 */
1150VMMR3DECL(bool) HWACCMR3IsVPIDActive(PVM pVM)
1151{
1152 return pVM->hwaccm.s.vmx.fVPID;
1153}
1154
1155
1156/**
1157 * Checks if internal events are pending. In that case we are not allowed to dispatch interrupts.
1158 *
1159 * @returns boolean
1160 * @param pVM The VM to operate on.
1161 */
1162VMMR3DECL(bool) HWACCMR3IsEventPending(PVM pVM)
1163{
1164 /* @todo SMP */
1165 return HWACCMIsEnabled(pVM) && pVM->aCpus[0].hwaccm.s.Event.fPending;
1166}
1167
1168
1169/**
1170 * Inject an NMI into a running VM
1171 *
1172 * @returns boolean
1173 * @param pVM The VM to operate on.
1174 */
1175VMMR3DECL(int) HWACCMR3InjectNMI(PVM pVM)
1176{
1177 pVM->hwaccm.s.fInjectNMI = true;
1178 return VINF_SUCCESS;
1179}
1180
1181/**
1182 * Check fatal VT-x/AMD-V error and produce some meaningful
1183 * log release message.
1184 *
1185 * @param pVM The VM to operate on.
1186 * @param iStatusCode VBox status code
1187 */
1188VMMR3DECL(void) HWACCMR3CheckError(PVM pVM, int iStatusCode)
1189{
1190 for (unsigned i=0;i<pVM->cCPUs;i++)
1191 {
1192 switch(iStatusCode)
1193 {
1194 case VERR_VMX_INVALID_VMCS_FIELD:
1195 break;
1196
1197 case VERR_VMX_INVALID_VMCS_PTR:
1198 LogRel(("VERR_VMX_INVALID_VMCS_PTR: CPU%d Current pointer %RGp vs %RGp\n", i, pVM->aCpus[i].hwaccm.s.vmx.lasterror.u64VMCSPhys, pVM->aCpus[i].hwaccm.s.vmx.pVMCSPhys));
1199 LogRel(("VERR_VMX_INVALID_VMCS_PTR: CPU%d Current VMCS version %x\n", i, pVM->aCpus[i].hwaccm.s.vmx.lasterror.ulVMCSRevision));
1200 LogRel(("VERR_VMX_INVALID_VMCS_PTR: CPU%d Entered Cpu %d\n", i, pVM->aCpus[i].hwaccm.s.vmx.lasterror.idEnteredCpu));
1201 LogRel(("VERR_VMX_INVALID_VMCS_PTR: CPU%d Current Cpu %d\n", i, pVM->aCpus[i].hwaccm.s.vmx.lasterror.idCurrentCpu));
1202 break;
1203
1204 case VERR_VMX_UNABLE_TO_START_VM:
1205 LogRel(("VERR_VMX_UNABLE_TO_START_VM: CPU%d instruction error %x\n", i, pVM->aCpus[i].hwaccm.s.vmx.lasterror.ulInstrError));
1206 LogRel(("VERR_VMX_UNABLE_TO_START_VM: CPU%d exit reason %x\n", i, pVM->aCpus[i].hwaccm.s.vmx.lasterror.ulExitReason));
1207#if 0 /* @todo dump the current control fields to the release log */
1208 if (pVM->aCpus[i].hwaccm.s.vmx.lasterror.ulInstrError == VMX_ERROR_VMENTRY_INVALID_CONTROL_FIELDS)
1209 {
1210
1211 }
1212#endif
1213 break;
1214
1215 case VERR_VMX_UNABLE_TO_RESUME_VM:
1216 LogRel(("VERR_VMX_UNABLE_TO_RESUME_VM: CPU%d instruction error %x\n", i, pVM->aCpus[i].hwaccm.s.vmx.lasterror.ulInstrError));
1217 LogRel(("VERR_VMX_UNABLE_TO_RESUME_VM: CPU%d exit reason %x\n", i, pVM->aCpus[i].hwaccm.s.vmx.lasterror.ulExitReason));
1218 break;
1219
1220 case VERR_VMX_INVALID_VMXON_PTR:
1221 break;
1222 }
1223 }
1224}
1225
1226/**
1227 * Execute state save operation.
1228 *
1229 * @returns VBox status code.
1230 * @param pVM VM Handle.
1231 * @param pSSM SSM operation handle.
1232 */
1233static DECLCALLBACK(int) hwaccmR3Save(PVM pVM, PSSMHANDLE pSSM)
1234{
1235 int rc;
1236
1237 Log(("hwaccmR3Save:\n"));
1238
1239 for (unsigned i=0;i<pVM->cCPUs;i++)
1240 {
1241 /*
1242 * Save the basic bits - fortunately all the other things can be resynced on load.
1243 */
1244 rc = SSMR3PutU32(pSSM, pVM->aCpus[i].hwaccm.s.Event.fPending);
1245 AssertRCReturn(rc, rc);
1246 rc = SSMR3PutU32(pSSM, pVM->aCpus[i].hwaccm.s.Event.errCode);
1247 AssertRCReturn(rc, rc);
1248 rc = SSMR3PutU64(pSSM, pVM->aCpus[i].hwaccm.s.Event.intInfo);
1249 AssertRCReturn(rc, rc);
1250 }
1251
1252 return VINF_SUCCESS;
1253}
1254
1255/**
1256 * Execute state load operation.
1257 *
1258 * @returns VBox status code.
1259 * @param pVM VM Handle.
1260 * @param pSSM SSM operation handle.
1261 * @param u32Version Data layout version.
1262 */
1263static DECLCALLBACK(int) hwaccmR3Load(PVM pVM, PSSMHANDLE pSSM, uint32_t u32Version)
1264{
1265 int rc;
1266
1267 Log(("hwaccmR3Load:\n"));
1268
1269 /*
1270 * Validate version.
1271 */
1272 if (u32Version != HWACCM_SSM_VERSION)
1273 {
1274 AssertMsgFailed(("hwaccmR3Load: Invalid version u32Version=%d!\n", u32Version));
1275 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
1276 }
1277 for (unsigned i=0;i<pVM->cCPUs;i++)
1278 {
1279 rc = SSMR3GetU32(pSSM, &pVM->aCpus[i].hwaccm.s.Event.fPending);
1280 AssertRCReturn(rc, rc);
1281 rc = SSMR3GetU32(pSSM, &pVM->aCpus[i].hwaccm.s.Event.errCode);
1282 AssertRCReturn(rc, rc);
1283 rc = SSMR3GetU64(pSSM, &pVM->aCpus[i].hwaccm.s.Event.intInfo);
1284 AssertRCReturn(rc, rc);
1285 }
1286 return VINF_SUCCESS;
1287}
1288
1289
1290
1291
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