1 | /* $Id: HWACCM.cpp 16136 2009-01-21 13:17:41Z 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 | * Global Variables *
|
---|
52 | *******************************************************************************/
|
---|
53 | #ifdef VBOX_WITH_STATISTICS
|
---|
54 | # define EXIT_REASON(def, val, str) #def " - " #val " - " str
|
---|
55 | # define EXIT_REASON_NIL() NULL
|
---|
56 | /** Exit reason descriptions for VT-x, used to describe statistics. */
|
---|
57 | static const char * const g_apszVTxExitReasons[MAX_EXITREASON_STAT] =
|
---|
58 | {
|
---|
59 | EXIT_REASON(VMX_EXIT_EXCEPTION , 0, "Exception or non-maskable interrupt (NMI)."),
|
---|
60 | EXIT_REASON(VMX_EXIT_EXTERNAL_IRQ , 1, "External interrupt."),
|
---|
61 | EXIT_REASON(VMX_EXIT_TRIPLE_FAULT , 2, "Triple fault."),
|
---|
62 | EXIT_REASON(VMX_EXIT_INIT_SIGNAL , 3, "INIT signal."),
|
---|
63 | EXIT_REASON(VMX_EXIT_SIPI , 4, "Start-up IPI (SIPI)."),
|
---|
64 | EXIT_REASON(VMX_EXIT_IO_SMI_IRQ , 5, "I/O system-management interrupt (SMI)."),
|
---|
65 | EXIT_REASON(VMX_EXIT_SMI_IRQ , 6, "Other SMI."),
|
---|
66 | EXIT_REASON(VMX_EXIT_IRQ_WINDOW , 7, "Interrupt window."),
|
---|
67 | EXIT_REASON_NIL(),
|
---|
68 | EXIT_REASON(VMX_EXIT_TASK_SWITCH , 9, "Task switch."),
|
---|
69 | EXIT_REASON(VMX_EXIT_CPUID , 10, "Guest software attempted to execute CPUID."),
|
---|
70 | EXIT_REASON_NIL(),
|
---|
71 | EXIT_REASON(VMX_EXIT_HLT , 12, "Guest software attempted to execute HLT."),
|
---|
72 | EXIT_REASON(VMX_EXIT_INVD , 13, "Guest software attempted to execute INVD."),
|
---|
73 | EXIT_REASON(VMX_EXIT_INVPG , 14, "Guest software attempted to execute INVPG."),
|
---|
74 | EXIT_REASON(VMX_EXIT_RDPMC , 15, "Guest software attempted to execute RDPMC."),
|
---|
75 | EXIT_REASON(VMX_EXIT_RDTSC , 16, "Guest software attempted to execute RDTSC."),
|
---|
76 | EXIT_REASON(VMX_EXIT_RSM , 17, "Guest software attempted to execute RSM in SMM."),
|
---|
77 | EXIT_REASON(VMX_EXIT_VMCALL , 18, "Guest software executed VMCALL."),
|
---|
78 | EXIT_REASON(VMX_EXIT_VMCLEAR , 19, "Guest software executed VMCLEAR."),
|
---|
79 | EXIT_REASON(VMX_EXIT_VMLAUNCH , 20, "Guest software executed VMLAUNCH."),
|
---|
80 | EXIT_REASON(VMX_EXIT_VMPTRLD , 21, "Guest software executed VMPTRLD."),
|
---|
81 | EXIT_REASON(VMX_EXIT_VMPTRST , 22, "Guest software executed VMPTRST."),
|
---|
82 | EXIT_REASON(VMX_EXIT_VMREAD , 23, "Guest software executed VMREAD."),
|
---|
83 | EXIT_REASON(VMX_EXIT_VMRESUME , 24, "Guest software executed VMRESUME."),
|
---|
84 | EXIT_REASON(VMX_EXIT_VMWRITE , 25, "Guest software executed VMWRITE."),
|
---|
85 | EXIT_REASON(VMX_EXIT_VMXOFF , 26, "Guest software executed VMXOFF."),
|
---|
86 | EXIT_REASON(VMX_EXIT_VMXON , 27, "Guest software executed VMXON."),
|
---|
87 | EXIT_REASON(VMX_EXIT_CRX_MOVE , 28, "Control-register accesses."),
|
---|
88 | EXIT_REASON(VMX_EXIT_DRX_MOVE , 29, "Debug-register accesses."),
|
---|
89 | EXIT_REASON(VMX_EXIT_PORT_IO , 30, "I/O instruction."),
|
---|
90 | EXIT_REASON(VMX_EXIT_RDMSR , 31, "RDMSR. Guest software attempted to execute RDMSR."),
|
---|
91 | EXIT_REASON(VMX_EXIT_WRMSR , 32, "WRMSR. Guest software attempted to execute WRMSR."),
|
---|
92 | EXIT_REASON(VMX_EXIT_ERR_INVALID_GUEST_STATE, 33, "VM-entry failure due to invalid guest state."),
|
---|
93 | EXIT_REASON(VMX_EXIT_ERR_MSR_LOAD , 34, "VM-entry failure due to MSR loading."),
|
---|
94 | EXIT_REASON_NIL(),
|
---|
95 | EXIT_REASON(VMX_EXIT_MWAIT , 36, "Guest software executed MWAIT."),
|
---|
96 | EXIT_REASON_NIL(),
|
---|
97 | EXIT_REASON_NIL(),
|
---|
98 | EXIT_REASON(VMX_EXIT_MONITOR , 39, "Guest software attempted to execute MONITOR."),
|
---|
99 | EXIT_REASON(VMX_EXIT_PAUSE , 40, "Guest software attempted to execute PAUSE."),
|
---|
100 | EXIT_REASON(VMX_EXIT_ERR_MACHINE_CHECK , 41, "VM-entry failure due to machine-check."),
|
---|
101 | EXIT_REASON_NIL(),
|
---|
102 | EXIT_REASON(VMX_EXIT_TPR , 43, "TPR below threshold. Guest software executed MOV to CR8."),
|
---|
103 | EXIT_REASON(VMX_EXIT_APIC_ACCESS , 44, "APIC access. Guest software attempted to access memory at a physical address on the APIC-access page."),
|
---|
104 | EXIT_REASON_NIL(),
|
---|
105 | EXIT_REASON(VMX_EXIT_XDTR_ACCESS , 46, "Access to GDTR or IDTR. Guest software attempted to execute LGDT, LIDT, SGDT, or SIDT."),
|
---|
106 | EXIT_REASON(VMX_EXIT_TR_ACCESS , 47, "Access to LDTR or TR. Guest software attempted to execute LLDT, LTR, SLDT, or STR."),
|
---|
107 | EXIT_REASON(VMX_EXIT_EPT_VIOLATION , 48, "EPT violation. An attempt to access memory with a guest-physical address was disallowed by the configuration of the EPT paging structures."),
|
---|
108 | EXIT_REASON(VMX_EXIT_EPT_MISCONFIG , 49, "EPT misconfiguration. An attempt to access memory with a guest-physical address encountered a misconfigured EPT paging-structure entry."),
|
---|
109 | EXIT_REASON(VMX_EXIT_INVEPT , 50, "INVEPT. Guest software attempted to execute INVEPT."),
|
---|
110 | EXIT_REASON_NIL(),
|
---|
111 | EXIT_REASON(VMX_EXIT_PREEMPTION_TIMER , 52, "VMX-preemption timer expired. The preemption timer counted down to zero."),
|
---|
112 | EXIT_REASON(VMX_EXIT_INVVPID , 53, "INVVPID. Guest software attempted to execute INVVPID."),
|
---|
113 | EXIT_REASON(VMX_EXIT_WBINVD , 54, "WBINVD. Guest software attempted to execute WBINVD."),
|
---|
114 | EXIT_REASON(VMX_EXIT_XSETBV , 55, "XSETBV. Guest software attempted to execute XSETBV."),
|
---|
115 | EXIT_REASON_NIL()
|
---|
116 | };
|
---|
117 | /** Exit reason descriptions for AMD-V, used to describe statistics. */
|
---|
118 | static const char * const g_apszAmdVExitReasons[MAX_EXITREASON_STAT] =
|
---|
119 | {
|
---|
120 | /** @todo fill in these. */
|
---|
121 | EXIT_REASON_NIL()
|
---|
122 | };
|
---|
123 | # undef EXIT_REASON
|
---|
124 | # undef EXIT_REASON_NIL
|
---|
125 | #endif /* VBOX_WITH_STATISTICS */
|
---|
126 |
|
---|
127 | /*******************************************************************************
|
---|
128 | * Internal Functions *
|
---|
129 | *******************************************************************************/
|
---|
130 | static DECLCALLBACK(int) hwaccmR3Save(PVM pVM, PSSMHANDLE pSSM);
|
---|
131 | static DECLCALLBACK(int) hwaccmR3Load(PVM pVM, PSSMHANDLE pSSM, uint32_t u32Version);
|
---|
132 |
|
---|
133 |
|
---|
134 | /**
|
---|
135 | * Initializes the HWACCM.
|
---|
136 | *
|
---|
137 | * @returns VBox status code.
|
---|
138 | * @param pVM The VM to operate on.
|
---|
139 | */
|
---|
140 | VMMR3DECL(int) HWACCMR3Init(PVM pVM)
|
---|
141 | {
|
---|
142 | LogFlow(("HWACCMR3Init\n"));
|
---|
143 |
|
---|
144 | /*
|
---|
145 | * Assert alignment and sizes.
|
---|
146 | */
|
---|
147 | AssertRelease(!(RT_OFFSETOF(VM, hwaccm.s) & 31));
|
---|
148 | AssertRelease(sizeof(pVM->hwaccm.s) <= sizeof(pVM->hwaccm.padding));
|
---|
149 |
|
---|
150 | /* Some structure checks. */
|
---|
151 | AssertReleaseMsg(RT_OFFSETOF(SVM_VMCB, u8Reserved3) == 0xC0, ("u8Reserved3 offset = %x\n", RT_OFFSETOF(SVM_VMCB, u8Reserved3)));
|
---|
152 | AssertReleaseMsg(RT_OFFSETOF(SVM_VMCB, ctrl.EventInject) == 0xA8, ("ctrl.EventInject offset = %x\n", RT_OFFSETOF(SVM_VMCB, ctrl.EventInject)));
|
---|
153 | AssertReleaseMsg(RT_OFFSETOF(SVM_VMCB, ctrl.ExitIntInfo) == 0x88, ("ctrl.ExitIntInfo offset = %x\n", RT_OFFSETOF(SVM_VMCB, ctrl.ExitIntInfo)));
|
---|
154 | AssertReleaseMsg(RT_OFFSETOF(SVM_VMCB, ctrl.TLBCtrl) == 0x58, ("ctrl.TLBCtrl offset = %x\n", RT_OFFSETOF(SVM_VMCB, ctrl.TLBCtrl)));
|
---|
155 |
|
---|
156 | AssertReleaseMsg(RT_OFFSETOF(SVM_VMCB, guest) == 0x400, ("guest offset = %x\n", RT_OFFSETOF(SVM_VMCB, guest)));
|
---|
157 | AssertReleaseMsg(RT_OFFSETOF(SVM_VMCB, guest.u8Reserved4) == 0x4A0, ("guest.u8Reserved4 offset = %x\n", RT_OFFSETOF(SVM_VMCB, guest.u8Reserved4)));
|
---|
158 | AssertReleaseMsg(RT_OFFSETOF(SVM_VMCB, guest.u8Reserved6) == 0x4D8, ("guest.u8Reserved6 offset = %x\n", RT_OFFSETOF(SVM_VMCB, guest.u8Reserved6)));
|
---|
159 | AssertReleaseMsg(RT_OFFSETOF(SVM_VMCB, guest.u8Reserved7) == 0x580, ("guest.u8Reserved7 offset = %x\n", RT_OFFSETOF(SVM_VMCB, guest.u8Reserved7)));
|
---|
160 | AssertReleaseMsg(RT_OFFSETOF(SVM_VMCB, guest.u8Reserved9) == 0x648, ("guest.u8Reserved9 offset = %x\n", RT_OFFSETOF(SVM_VMCB, guest.u8Reserved9)));
|
---|
161 | AssertReleaseMsg(RT_OFFSETOF(SVM_VMCB, u8Reserved10) == 0x698, ("u8Reserved3 offset = %x\n", RT_OFFSETOF(SVM_VMCB, u8Reserved10)));
|
---|
162 | AssertReleaseMsg(sizeof(SVM_VMCB) == 0x1000, ("SVM_VMCB size = %x\n", sizeof(SVM_VMCB)));
|
---|
163 |
|
---|
164 |
|
---|
165 | /*
|
---|
166 | * Register the saved state data unit.
|
---|
167 | */
|
---|
168 | int rc = SSMR3RegisterInternal(pVM, "HWACCM", 0, HWACCM_SSM_VERSION, sizeof(HWACCM),
|
---|
169 | NULL, hwaccmR3Save, NULL,
|
---|
170 | NULL, hwaccmR3Load, NULL);
|
---|
171 | if (RT_FAILURE(rc))
|
---|
172 | return rc;
|
---|
173 |
|
---|
174 | /* Misc initialisation. */
|
---|
175 | pVM->hwaccm.s.vmx.fSupported = false;
|
---|
176 | pVM->hwaccm.s.svm.fSupported = false;
|
---|
177 | pVM->hwaccm.s.vmx.fEnabled = false;
|
---|
178 | pVM->hwaccm.s.svm.fEnabled = false;
|
---|
179 |
|
---|
180 | pVM->hwaccm.s.fActive = false;
|
---|
181 | pVM->hwaccm.s.fNestedPaging = false;
|
---|
182 |
|
---|
183 | /* Disabled by default. */
|
---|
184 | pVM->fHWACCMEnabled = false;
|
---|
185 |
|
---|
186 | /*
|
---|
187 | * Check CFGM options.
|
---|
188 | */
|
---|
189 | PCFGMNODE pRoot = CFGMR3GetRoot(pVM);
|
---|
190 | PCFGMNODE pHWVirtExt = CFGMR3GetChild(pRoot, "HWVirtExt/");
|
---|
191 | /* Nested paging: disabled by default. */
|
---|
192 | rc = CFGMR3QueryBoolDef(pRoot, "EnableNestedPaging", &pVM->hwaccm.s.fAllowNestedPaging, false);
|
---|
193 | AssertRC(rc);
|
---|
194 |
|
---|
195 | /* VT-x VPID: disabled by default. */
|
---|
196 | rc = CFGMR3QueryBoolDef(pRoot, "EnableVPID", &pVM->hwaccm.s.vmx.fAllowVPID, false);
|
---|
197 | AssertRC(rc);
|
---|
198 |
|
---|
199 | /* HWACCM support must be explicitely enabled in the configuration file. */
|
---|
200 | rc = CFGMR3QueryBoolDef(pHWVirtExt, "Enabled", &pVM->hwaccm.s.fAllowed, false);
|
---|
201 | AssertRC(rc);
|
---|
202 |
|
---|
203 | #ifdef RT_OS_DARWIN
|
---|
204 | if (VMMIsHwVirtExtForced(pVM) != pVM->hwaccm.s.fAllowed)
|
---|
205 | #else
|
---|
206 | if (VMMIsHwVirtExtForced(pVM) && !pVM->hwaccm.s.fAllowed)
|
---|
207 | #endif
|
---|
208 | {
|
---|
209 | AssertLogRelMsgFailed(("VMMIsHwVirtExtForced=%RTbool fAllowed=%RTbool\n",
|
---|
210 | VMMIsHwVirtExtForced(pVM), pVM->hwaccm.s.fAllowed));
|
---|
211 | return VERR_HWACCM_CONFIG_MISMATCH;
|
---|
212 | }
|
---|
213 |
|
---|
214 | if (VMMIsHwVirtExtForced(pVM))
|
---|
215 | pVM->fHWACCMEnabled = true;
|
---|
216 |
|
---|
217 | #if HC_ARCH_BITS == 32
|
---|
218 | /* 64-bit mode is configurable and it depends on both the kernel mode and VT-x.
|
---|
219 | * (To use the default, don't set 64bitEnabled in CFGM.) */
|
---|
220 | rc = CFGMR3QueryBoolDef(pHWVirtExt, "64bitEnabled", &pVM->hwaccm.s.fAllow64BitGuests, false);
|
---|
221 | AssertLogRelRCReturn(rc, rc);
|
---|
222 | if (pVM->hwaccm.s.fAllow64BitGuests)
|
---|
223 | {
|
---|
224 | # ifdef RT_OS_DARWIN
|
---|
225 | if (!VMMIsHwVirtExtForced(pVM))
|
---|
226 | # else
|
---|
227 | if (!pVM->hwaccm.s.fAllowed)
|
---|
228 | # endif
|
---|
229 | return VM_SET_ERROR(pVM, VERR_INVALID_PARAMETER, "64-bit guest support was requested without also enabling VT-x.");
|
---|
230 | }
|
---|
231 | #else
|
---|
232 | /* On 64-bit hosts 64-bit guest support is enabled by default, but allow this to be overridden
|
---|
233 | * via VBoxInternal/HWVirtExt/64bitEnabled=0. (ConsoleImpl2.cpp doesn't set this to false for 64-bit.) */
|
---|
234 | rc = CFGMR3QueryBoolDef(pHWVirtExt, "64bitEnabled", &pVM->hwaccm.s.fAllow64BitGuests, true);
|
---|
235 | AssertLogRelRCReturn(rc, rc);
|
---|
236 | #endif
|
---|
237 |
|
---|
238 | return VINF_SUCCESS;
|
---|
239 | }
|
---|
240 |
|
---|
241 | /**
|
---|
242 | * Initializes the per-VCPU HWACCM.
|
---|
243 | *
|
---|
244 | * @returns VBox status code.
|
---|
245 | * @param pVM The VM to operate on.
|
---|
246 | */
|
---|
247 | VMMR3DECL(int) HWACCMR3InitCPU(PVM pVM)
|
---|
248 | {
|
---|
249 | LogFlow(("HWACCMR3InitCPU\n"));
|
---|
250 |
|
---|
251 | #ifdef VBOX_WITH_STATISTICS
|
---|
252 | /*
|
---|
253 | * Statistics.
|
---|
254 | */
|
---|
255 | for (unsigned i=0;i<pVM->cCPUs;i++)
|
---|
256 | {
|
---|
257 | PVMCPU pVCpu = &pVM->aCpus[i];
|
---|
258 | int rc;
|
---|
259 |
|
---|
260 | rc = STAMR3RegisterF(pVM, &pVCpu->hwaccm.s.StatEntry, STAMTYPE_PROFILE, STAMVISIBILITY_USED, STAMUNIT_TICKS_PER_CALL, "Profiling of VMXR0RunGuestCode entry",
|
---|
261 | "/PROF/HWACCM/CPU%d/SwitchToGC", i);
|
---|
262 | AssertRC(rc);
|
---|
263 | rc = STAMR3RegisterF(pVM, &pVCpu->hwaccm.s.StatExit1, STAMTYPE_PROFILE, STAMVISIBILITY_USED, STAMUNIT_TICKS_PER_CALL, "Profiling of VMXR0RunGuestCode exit part 1",
|
---|
264 | "/PROF/HWACCM/CPU%d/SwitchFromGC_1", i);
|
---|
265 | AssertRC(rc);
|
---|
266 | rc = STAMR3RegisterF(pVM, &pVCpu->hwaccm.s.StatExit2, STAMTYPE_PROFILE, STAMVISIBILITY_USED, STAMUNIT_TICKS_PER_CALL, "Profiling of VMXR0RunGuestCode exit part 2",
|
---|
267 | "/PROF/HWACCM/CPU%d/SwitchFromGC_2", i);
|
---|
268 | AssertRC(rc);
|
---|
269 | # if 1 /* temporary for tracking down darwin holdup. */
|
---|
270 | rc = STAMR3RegisterF(pVM, &pVCpu->hwaccm.s.StatExit2Sub1, STAMTYPE_PROFILE, STAMVISIBILITY_USED, STAMUNIT_TICKS_PER_CALL, "Temporary - I/O",
|
---|
271 | "/PROF/HWACCM/CPU%d/SwitchFromGC_2/Sub1", i);
|
---|
272 | AssertRC(rc);
|
---|
273 | rc = STAMR3RegisterF(pVM, &pVCpu->hwaccm.s.StatExit2Sub2, STAMTYPE_PROFILE, STAMVISIBILITY_USED, STAMUNIT_TICKS_PER_CALL, "Temporary - CRx RWs",
|
---|
274 | "/PROF/HWACCM/CPU%d/SwitchFromGC_2/Sub2", i);
|
---|
275 | AssertRC(rc);
|
---|
276 | rc = STAMR3RegisterF(pVM, &pVCpu->hwaccm.s.StatExit2Sub3, STAMTYPE_PROFILE, STAMVISIBILITY_USED, STAMUNIT_TICKS_PER_CALL, "Temporary - Exceptions",
|
---|
277 | "/PROF/HWACCM/CPU%d/SwitchFromGC_2/Sub3", i);
|
---|
278 | AssertRC(rc);
|
---|
279 | # endif
|
---|
280 | rc = STAMR3RegisterF(pVM, &pVCpu->hwaccm.s.StatInGC, STAMTYPE_PROFILE, STAMVISIBILITY_USED, STAMUNIT_TICKS_PER_CALL, "Profiling of vmlaunch",
|
---|
281 | "/PROF/HWACCM/CPU%d/InGC", i);
|
---|
282 | AssertRC(rc);
|
---|
283 |
|
---|
284 | # if HC_ARCH_BITS == 32 && defined(VBOX_ENABLE_64_BITS_GUESTS) && !defined(VBOX_WITH_HYBRID_32BIT_KERNEL)
|
---|
285 | rc = STAMR3RegisterF(pVM, &pVCpu->hwaccm.s.StatWorldSwitch3264, STAMTYPE_PROFILE, STAMVISIBILITY_USED, STAMUNIT_TICKS_PER_CALL, "Profiling of the 32/64 switcher",
|
---|
286 | "/PROF/HWACCM/CPU%d/Switcher3264", i);
|
---|
287 | AssertRC(rc);
|
---|
288 | # endif
|
---|
289 |
|
---|
290 | # define HWACCM_REG_COUNTER(a, b) \
|
---|
291 | rc = STAMR3RegisterF(pVM, a, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, "Profiling of vmlaunch", b, i); \
|
---|
292 | AssertRC(rc);
|
---|
293 |
|
---|
294 | HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitShadowNM, "/HWACCM/CPU%d/Exit/Trap/Shw/#NM");
|
---|
295 | HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitGuestNM, "/HWACCM/CPU%d/Exit/Trap/Gst/#NM");
|
---|
296 | HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitShadowPF, "/HWACCM/CPU%d/Exit/Trap/Shw/#PF");
|
---|
297 | HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitGuestPF, "/HWACCM/CPU%d/Exit/Trap/Gst/#PF");
|
---|
298 | HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitGuestUD, "/HWACCM/CPU%d/Exit/Trap/Gst/#UD");
|
---|
299 | HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitGuestSS, "/HWACCM/CPU%d/Exit/Trap/Gst/#SS");
|
---|
300 | HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitGuestNP, "/HWACCM/CPU%d/Exit/Trap/Gst/#NP");
|
---|
301 | HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitGuestGP, "/HWACCM/CPU%d/Exit/Trap/Gst/#GP");
|
---|
302 | HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitGuestMF, "/HWACCM/CPU%d/Exit/Trap/Gst/#MF");
|
---|
303 | HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitGuestDE, "/HWACCM/CPU%d/Exit/Trap/Gst/#DE");
|
---|
304 | HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitGuestDB, "/HWACCM/CPU%d/Exit/Trap/Gst/#DB");
|
---|
305 | HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitInvpg, "/HWACCM/CPU%d/Exit/Instr/Invlpg");
|
---|
306 | HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitInvd, "/HWACCM/CPU%d/Exit/Instr/Invd");
|
---|
307 | HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitCpuid, "/HWACCM/CPU%d/Exit/Instr/Cpuid");
|
---|
308 | HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitRdtsc, "/HWACCM/CPU%d/Exit/Instr/Rdtsc");
|
---|
309 | HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitDRxWrite, "/HWACCM/CPU%d/Exit/Instr/DR/Write");
|
---|
310 | HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitDRxRead, "/HWACCM/CPU%d/Exit/Instr/DR/Read");
|
---|
311 | HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitCLTS, "/HWACCM/CPU%d/Exit/Instr/CLTS");
|
---|
312 | HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitLMSW, "/HWACCM/CPU%d/Exit/Instr/LMSW");
|
---|
313 | HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitIOWrite, "/HWACCM/CPU%d/Exit/IO/Write");
|
---|
314 | HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitIORead, "/HWACCM/CPU%d/Exit/IO/Read");
|
---|
315 | HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitIOStringWrite, "/HWACCM/CPU%d/Exit/IO/WriteString");
|
---|
316 | HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitIOStringRead, "/HWACCM/CPU%d/Exit/IO/ReadString");
|
---|
317 | HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitIrqWindow, "/HWACCM/CPU%d/Exit/IrqWindow");
|
---|
318 | HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatExitMaxResume, "/HWACCM/CPU%d/Exit/MaxResume");
|
---|
319 |
|
---|
320 | HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatSwitchGuestIrq, "/HWACCM/CPU%d/Switch/IrqPending");
|
---|
321 | HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatSwitchToR3, "/HWACCM/CPU%d/Switch/ToR3");
|
---|
322 |
|
---|
323 | HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatIntInject, "/HWACCM/CPU%d/Irq/Inject");
|
---|
324 | HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatIntReinject, "/HWACCM/CPU%d/Irq/Reinject");
|
---|
325 | HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatPendingHostIrq, "/HWACCM/CPU%d/Irq/PendingOnHost");
|
---|
326 |
|
---|
327 | HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatFlushPageManual, "/HWACCM/CPU%d/Flush/Page/Virt");
|
---|
328 | HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatFlushPhysPageManual, "/HWACCM/CPU%d/Flush/Page/Phys");
|
---|
329 | HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatFlushTLBManual, "/HWACCM/CPU%d/Flush/TLB/Manual");
|
---|
330 | HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatFlushTLBCRxChange, "/HWACCM/CPU%d/Flush/TLB/CRx");
|
---|
331 | HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatFlushPageInvlpg, "/HWACCM/CPU%d/Flush/Page/Invlpg");
|
---|
332 | HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatFlushTLBWorldSwitch, "/HWACCM/CPU%d/Flush/TLB/Switch");
|
---|
333 | HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatNoFlushTLBWorldSwitch, "/HWACCM/CPU%d/Flush/TLB/Skipped");
|
---|
334 | HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatFlushASID, "/HWACCM/CPU%d/Flush/TLB/ASID");
|
---|
335 | HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatFlushTLBInvlpga, "/HWACCM/CPU%d/Flush/TLB/PhysInvl");
|
---|
336 |
|
---|
337 | HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatTSCOffset, "/HWACCM/CPU%d/TSC/Offset");
|
---|
338 | HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatTSCIntercept, "/HWACCM/CPU%d/TSC/Intercept");
|
---|
339 |
|
---|
340 | HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatDRxArmed, "/HWACCM/CPU%d/Debug/Armed");
|
---|
341 | HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatDRxContextSwitch, "/HWACCM/CPU%d/Debug/ContextSwitch");
|
---|
342 | HWACCM_REG_COUNTER(&pVCpu->hwaccm.s.StatDRxIOCheck, "/HWACCM/CPU%d/Debug/IOCheck");
|
---|
343 |
|
---|
344 | for (unsigned j=0;j<RT_ELEMENTS(pVCpu->hwaccm.s.StatExitCRxWrite);j++)
|
---|
345 | {
|
---|
346 | rc = STAMR3RegisterF(pVM, &pVCpu->hwaccm.s.StatExitCRxWrite[j], STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_OCCURENCES, "Profiling of CRx writes",
|
---|
347 | "/HWACCM/CPU%d/Exit/Instr/CR/Write/%x", i, j);
|
---|
348 | AssertRC(rc);
|
---|
349 | rc = STAMR3RegisterF(pVM, &pVCpu->hwaccm.s.StatExitCRxRead[j], STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_OCCURENCES, "Profiling of CRx reads",
|
---|
350 | "/HWACCM/CPU%d/Exit/Instr/CR/Read/%x", i, j);
|
---|
351 | AssertRC(rc);
|
---|
352 | }
|
---|
353 |
|
---|
354 | #undef HWACCM_REG_COUNTER
|
---|
355 |
|
---|
356 | pVCpu->hwaccm.s.paStatExitReason = NULL;
|
---|
357 |
|
---|
358 | rc = MMHyperAlloc(pVM, MAX_EXITREASON_STAT*sizeof(*pVCpu->hwaccm.s.paStatExitReason), 0, MM_TAG_HWACCM, (void **)&pVCpu->hwaccm.s.paStatExitReason);
|
---|
359 | AssertRC(rc);
|
---|
360 | if (RT_SUCCESS(rc))
|
---|
361 | {
|
---|
362 | const char * const *papszDesc = ASMIsIntelCpu() ? &g_apszVTxExitReasons[0] : &g_apszAmdVExitReasons[0];
|
---|
363 | for (int j=0;j<MAX_EXITREASON_STAT;j++)
|
---|
364 | {
|
---|
365 | rc = STAMR3RegisterF(pVM, &pVCpu->hwaccm.s.paStatExitReason[j], STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_OCCURENCES,
|
---|
366 | papszDesc[j] ? papszDesc[j] : "Exit reason",
|
---|
367 | "/HWACCM/CPU%d/Exit/Reason/%02x", i, j);
|
---|
368 | AssertRC(rc);
|
---|
369 | }
|
---|
370 | rc = STAMR3RegisterF(pVM, &pVCpu->hwaccm.s.StatExitReasonNPF, STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_OCCURENCES, "Nested page fault", "/HWACCM/CPU%d/Exit/Reason/#NPF", i);
|
---|
371 | AssertRC(rc);
|
---|
372 | }
|
---|
373 | pVCpu->hwaccm.s.paStatExitReasonR0 = MMHyperR3ToR0(pVM, pVCpu->hwaccm.s.paStatExitReason);
|
---|
374 | # ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
|
---|
375 | Assert(pVCpu->hwaccm.s.paStatExitReasonR0 != NIL_RTR0PTR || !VMMIsHwVirtExtForced(pVM));
|
---|
376 | # else
|
---|
377 | Assert(pVCpu->hwaccm.s.paStatExitReasonR0 != NIL_RTR0PTR);
|
---|
378 | # endif
|
---|
379 | }
|
---|
380 | #endif /* VBOX_WITH_STATISTICS */
|
---|
381 |
|
---|
382 | #ifdef VBOX_WITH_CRASHDUMP_MAGIC
|
---|
383 | /* Magic marker for searching in crash dumps. */
|
---|
384 | for (unsigned i=0;i<pVM->cCPUs;i++)
|
---|
385 | {
|
---|
386 | PVMCPU pVCpu = &pVM->aCpus[i];
|
---|
387 |
|
---|
388 | PVMCSCACHE pCache = &pVCpu->hwaccm.s.vmx.VMCSCache;
|
---|
389 | strcpy((char *)pCache->aMagic, "VMCSCACHE Magic");
|
---|
390 | pCache->uMagic = UINT64_C(0xDEADBEEFDEADBEEF);
|
---|
391 | }
|
---|
392 | #endif
|
---|
393 | return VINF_SUCCESS;
|
---|
394 | }
|
---|
395 |
|
---|
396 | /**
|
---|
397 | * Turns off normal raw mode features
|
---|
398 | *
|
---|
399 | * @param pVM The VM to operate on.
|
---|
400 | */
|
---|
401 | static void hwaccmR3DisableRawMode(PVM pVM)
|
---|
402 | {
|
---|
403 | /* Disable PATM & CSAM. */
|
---|
404 | PATMR3AllowPatching(pVM, false);
|
---|
405 | CSAMDisableScanning(pVM);
|
---|
406 |
|
---|
407 | /* Turn off IDT/LDT/GDT and TSS monitoring and sycing. */
|
---|
408 | SELMR3DisableMonitoring(pVM);
|
---|
409 | TRPMR3DisableMonitoring(pVM);
|
---|
410 |
|
---|
411 | /* The hidden selector registers are now valid. */
|
---|
412 | CPUMSetHiddenSelRegsValid(pVM, true);
|
---|
413 |
|
---|
414 | /* Disable the switcher code (safety precaution). */
|
---|
415 | VMMR3DisableSwitcher(pVM);
|
---|
416 |
|
---|
417 | /* Disable mapping of the hypervisor into the shadow page table. */
|
---|
418 | PGMR3ChangeShwPDMappings(pVM, false);
|
---|
419 |
|
---|
420 | /* Disable the switcher */
|
---|
421 | VMMR3DisableSwitcher(pVM);
|
---|
422 |
|
---|
423 | if (pVM->hwaccm.s.fNestedPaging)
|
---|
424 | {
|
---|
425 | /* Reinit the paging mode to force the new shadow mode. */
|
---|
426 | PGMR3ChangeMode(pVM, PGMMODE_REAL);
|
---|
427 | }
|
---|
428 | }
|
---|
429 |
|
---|
430 | /**
|
---|
431 | * Initialize VT-x or AMD-V.
|
---|
432 | *
|
---|
433 | * @returns VBox status code.
|
---|
434 | * @param pVM The VM handle.
|
---|
435 | */
|
---|
436 | VMMR3DECL(int) HWACCMR3InitFinalizeR0(PVM pVM)
|
---|
437 | {
|
---|
438 | int rc;
|
---|
439 |
|
---|
440 | if ( !pVM->hwaccm.s.vmx.fSupported
|
---|
441 | && !pVM->hwaccm.s.svm.fSupported)
|
---|
442 | {
|
---|
443 | LogRel(("HWACCM: No VMX or SVM CPU extension found. Reason %Rrc\n", pVM->hwaccm.s.lLastError));
|
---|
444 | LogRel(("HWACCM: VMX MSR_IA32_FEATURE_CONTROL=%RX64\n", pVM->hwaccm.s.vmx.msr.feature_ctrl));
|
---|
445 | #ifdef RT_OS_DARWIN
|
---|
446 | if (VMMIsHwVirtExtForced(pVM))
|
---|
447 | return VM_SET_ERROR(pVM, VERR_VMX_NO_VMX, "VT-x is not available.");
|
---|
448 | #endif
|
---|
449 | return VINF_SUCCESS;
|
---|
450 | }
|
---|
451 |
|
---|
452 | /*
|
---|
453 | * 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
|
---|
454 | * because it turns off paging, which is not allowed in VMX root mode.
|
---|
455 | *
|
---|
456 | * 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.
|
---|
457 | * There's no such problem with AMD-V. (@todo)
|
---|
458 | *
|
---|
459 | */
|
---|
460 | /* If we enabled or disabled hwaccm mode, then it can't be changed until all the VMs are shutdown. */
|
---|
461 | rc = SUPCallVMMR0Ex(pVM->pVMR0, VMMR0_DO_HWACC_ENABLE, (pVM->hwaccm.s.fAllowed) ? HWACCMSTATE_ENABLED : HWACCMSTATE_DISABLED, NULL);
|
---|
462 | if (RT_FAILURE(rc))
|
---|
463 | {
|
---|
464 | LogRel(("HWACCMR3InitFinalize: SUPCallVMMR0Ex VMMR0_DO_HWACC_ENABLE failed with %Rrc\n", rc));
|
---|
465 | LogRel(("HWACCMR3InitFinalize: disallowed %s of HWACCM\n", pVM->hwaccm.s.fAllowed ? "enabling" : "disabling"));
|
---|
466 |
|
---|
467 | #ifdef RT_OS_DARWIN
|
---|
468 | /*
|
---|
469 | * This is 100% fatal if we didn't prepare for a HwVirtExt setup because of
|
---|
470 | * missing ring-0 allocations. For VMs that require HwVirtExt it doesn't normally
|
---|
471 | * make sense to try run them in software mode, so fail that too.
|
---|
472 | */
|
---|
473 | if (VMMIsHwVirtExtForced(pVM))
|
---|
474 | VM_SET_ERROR(pVM, rc, "An active VM already uses software virtualization. It is not allowed to "
|
---|
475 | "simultaneously use VT-x.");
|
---|
476 | else
|
---|
477 | VM_SET_ERROR(pVM, rc, "An active VM already uses Intel VT-x hardware acceleration. It is not "
|
---|
478 | "allowed to simultaneously use software virtualization.");
|
---|
479 | return rc;
|
---|
480 |
|
---|
481 | #else /* !RT_OS_DARWIN */
|
---|
482 |
|
---|
483 | /* Invert the selection */
|
---|
484 | pVM->hwaccm.s.fAllowed ^= 1;
|
---|
485 | if (pVM->hwaccm.s.fAllowed)
|
---|
486 | {
|
---|
487 | if (pVM->hwaccm.s.vmx.fSupported)
|
---|
488 | VM_SET_ERROR(pVM, rc, "An active VM already uses Intel VT-x hardware acceleration. It is not allowed "
|
---|
489 | "to simultaneously use software virtualization.\n");
|
---|
490 | else
|
---|
491 | VM_SET_ERROR(pVM, rc, "An active VM already uses AMD-V hardware acceleration. It is not allowed to "
|
---|
492 | "simultaneously use software virtualization.\n");
|
---|
493 | }
|
---|
494 | else
|
---|
495 | VM_SET_ERROR(pVM, rc, "An active VM already uses software virtualization. It is not allowed to simultaneously "
|
---|
496 | "use VT-x or AMD-V.\n");
|
---|
497 | return rc;
|
---|
498 | #endif /* !RT_OS_DARWIN */
|
---|
499 | }
|
---|
500 |
|
---|
501 | if (pVM->hwaccm.s.fAllowed == false)
|
---|
502 | return VINF_SUCCESS; /* disabled */
|
---|
503 |
|
---|
504 | Assert(!pVM->fHWACCMEnabled || VMMIsHwVirtExtForced(pVM));
|
---|
505 |
|
---|
506 | if (pVM->hwaccm.s.vmx.fSupported)
|
---|
507 | {
|
---|
508 | Log(("pVM->hwaccm.s.vmx.fSupported = %d\n", pVM->hwaccm.s.vmx.fSupported));
|
---|
509 |
|
---|
510 | if ( pVM->hwaccm.s.fInitialized == false
|
---|
511 | && pVM->hwaccm.s.vmx.msr.feature_ctrl != 0)
|
---|
512 | {
|
---|
513 | uint64_t val;
|
---|
514 | RTGCPHYS GCPhys = 0;
|
---|
515 |
|
---|
516 | LogRel(("HWACCM: Host CR4=%08X\n", pVM->hwaccm.s.vmx.hostCR4));
|
---|
517 | LogRel(("HWACCM: MSR_IA32_FEATURE_CONTROL = %RX64\n", pVM->hwaccm.s.vmx.msr.feature_ctrl));
|
---|
518 | LogRel(("HWACCM: MSR_IA32_VMX_BASIC_INFO = %RX64\n", pVM->hwaccm.s.vmx.msr.vmx_basic_info));
|
---|
519 | LogRel(("HWACCM: VMCS id = %x\n", MSR_IA32_VMX_BASIC_INFO_VMCS_ID(pVM->hwaccm.s.vmx.msr.vmx_basic_info)));
|
---|
520 | LogRel(("HWACCM: VMCS size = %x\n", MSR_IA32_VMX_BASIC_INFO_VMCS_SIZE(pVM->hwaccm.s.vmx.msr.vmx_basic_info)));
|
---|
521 | 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"));
|
---|
522 | LogRel(("HWACCM: VMCS memory type = %x\n", MSR_IA32_VMX_BASIC_INFO_VMCS_MEM_TYPE(pVM->hwaccm.s.vmx.msr.vmx_basic_info)));
|
---|
523 | LogRel(("HWACCM: Dual monitor treatment = %d\n", MSR_IA32_VMX_BASIC_INFO_VMCS_DUAL_MON(pVM->hwaccm.s.vmx.msr.vmx_basic_info)));
|
---|
524 |
|
---|
525 | LogRel(("HWACCM: MSR_IA32_VMX_PINBASED_CTLS = %RX64\n", pVM->hwaccm.s.vmx.msr.vmx_pin_ctls.u));
|
---|
526 | val = pVM->hwaccm.s.vmx.msr.vmx_pin_ctls.n.allowed1;
|
---|
527 | if (val & VMX_VMCS_CTRL_PIN_EXEC_CONTROLS_EXT_INT_EXIT)
|
---|
528 | LogRel(("HWACCM: VMX_VMCS_CTRL_PIN_EXEC_CONTROLS_EXT_INT_EXIT\n"));
|
---|
529 | if (val & VMX_VMCS_CTRL_PIN_EXEC_CONTROLS_NMI_EXIT)
|
---|
530 | LogRel(("HWACCM: VMX_VMCS_CTRL_PIN_EXEC_CONTROLS_NMI_EXIT\n"));
|
---|
531 | if (val & VMX_VMCS_CTRL_PIN_EXEC_CONTROLS_VIRTUAL_NMI)
|
---|
532 | LogRel(("HWACCM: VMX_VMCS_CTRL_PIN_EXEC_CONTROLS_VIRTUAL_NMI\n"));
|
---|
533 | if (val & VMX_VMCS_CTRL_PIN_EXEC_CONTROLS_PREEMPT_TIMER)
|
---|
534 | LogRel(("HWACCM: VMX_VMCS_CTRL_PIN_EXEC_CONTROLS_PREEMPT_TIMER\n"));
|
---|
535 | val = pVM->hwaccm.s.vmx.msr.vmx_pin_ctls.n.disallowed0;
|
---|
536 | if (val & VMX_VMCS_CTRL_PIN_EXEC_CONTROLS_EXT_INT_EXIT)
|
---|
537 | LogRel(("HWACCM: VMX_VMCS_CTRL_PIN_EXEC_CONTROLS_EXT_INT_EXIT *must* be set\n"));
|
---|
538 | if (val & VMX_VMCS_CTRL_PIN_EXEC_CONTROLS_NMI_EXIT)
|
---|
539 | LogRel(("HWACCM: VMX_VMCS_CTRL_PIN_EXEC_CONTROLS_NMI_EXIT *must* be set\n"));
|
---|
540 | if (val & VMX_VMCS_CTRL_PIN_EXEC_CONTROLS_VIRTUAL_NMI)
|
---|
541 | LogRel(("HWACCM: VMX_VMCS_CTRL_PIN_EXEC_CONTROLS_VIRTUAL_NMI *must* be set\n"));
|
---|
542 | if (val & VMX_VMCS_CTRL_PIN_EXEC_CONTROLS_PREEMPT_TIMER)
|
---|
543 | LogRel(("HWACCM: VMX_VMCS_CTRL_PIN_EXEC_CONTROLS_PREEMPT_TIMER *must* be set\n"));
|
---|
544 |
|
---|
545 | LogRel(("HWACCM: MSR_IA32_VMX_PROCBASED_CTLS = %RX64\n", pVM->hwaccm.s.vmx.msr.vmx_proc_ctls.u));
|
---|
546 | val = pVM->hwaccm.s.vmx.msr.vmx_proc_ctls.n.allowed1;
|
---|
547 | if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_IRQ_WINDOW_EXIT)
|
---|
548 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_IRQ_WINDOW_EXIT\n"));
|
---|
549 | if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_TSC_OFFSET)
|
---|
550 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_TSC_OFFSET\n"));
|
---|
551 | if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_HLT_EXIT)
|
---|
552 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_HLT_EXIT\n"));
|
---|
553 | if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_INVLPG_EXIT)
|
---|
554 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_INVLPG_EXIT\n"));
|
---|
555 | if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_MWAIT_EXIT)
|
---|
556 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_MWAIT_EXIT\n"));
|
---|
557 | if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_RDPMC_EXIT)
|
---|
558 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_RDPMC_EXIT\n"));
|
---|
559 | if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_RDTSC_EXIT)
|
---|
560 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_RDTSC_EXIT\n"));
|
---|
561 | if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_CR3_LOAD_EXIT)
|
---|
562 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_CR3_LOAD_EXIT\n"));
|
---|
563 | if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_CR3_STORE_EXIT)
|
---|
564 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_CR3_STORE_EXIT\n"));
|
---|
565 | if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_CR8_LOAD_EXIT)
|
---|
566 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_CR8_LOAD_EXIT\n"));
|
---|
567 | if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_CR8_STORE_EXIT)
|
---|
568 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_CR8_STORE_EXIT\n"));
|
---|
569 | if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_USE_TPR_SHADOW)
|
---|
570 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_USE_TPR_SHADOW\n"));
|
---|
571 | if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_NMI_WINDOW_EXIT)
|
---|
572 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_NMI_WINDOW_EXIT\n"));
|
---|
573 | if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_MOV_DR_EXIT)
|
---|
574 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_MOV_DR_EXIT\n"));
|
---|
575 | if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_UNCOND_IO_EXIT)
|
---|
576 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_UNCOND_IO_EXIT\n"));
|
---|
577 | if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_USE_IO_BITMAPS)
|
---|
578 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_USE_IO_BITMAPS\n"));
|
---|
579 | if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_MONITOR_TRAP_FLAG)
|
---|
580 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_MONITOR_TRAP_FLAG\n"));
|
---|
581 | if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_USE_MSR_BITMAPS)
|
---|
582 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_USE_MSR_BITMAPS\n"));
|
---|
583 | if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_MONITOR_EXIT)
|
---|
584 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_MONITOR_EXIT\n"));
|
---|
585 | if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_PAUSE_EXIT)
|
---|
586 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_PAUSE_EXIT\n"));
|
---|
587 | if (val & VMX_VMCS_CTRL_PROC_EXEC_USE_SECONDARY_EXEC_CTRL)
|
---|
588 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_USE_SECONDARY_EXEC_CTRL\n"));
|
---|
589 |
|
---|
590 | val = pVM->hwaccm.s.vmx.msr.vmx_proc_ctls.n.disallowed0;
|
---|
591 | if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_IRQ_WINDOW_EXIT)
|
---|
592 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_IRQ_WINDOW_EXIT *must* be set\n"));
|
---|
593 | if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_TSC_OFFSET)
|
---|
594 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_TSC_OFFSET *must* be set\n"));
|
---|
595 | if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_HLT_EXIT)
|
---|
596 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_HLT_EXIT *must* be set\n"));
|
---|
597 | if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_INVLPG_EXIT)
|
---|
598 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_INVLPG_EXIT *must* be set\n"));
|
---|
599 | if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_MWAIT_EXIT)
|
---|
600 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_MWAIT_EXIT *must* be set\n"));
|
---|
601 | if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_RDPMC_EXIT)
|
---|
602 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_RDPMC_EXIT *must* be set\n"));
|
---|
603 | if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_RDTSC_EXIT)
|
---|
604 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_RDTSC_EXIT *must* be set\n"));
|
---|
605 | if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_CR3_LOAD_EXIT)
|
---|
606 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_CR3_LOAD_EXIT *must* be set\n"));
|
---|
607 | if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_CR3_STORE_EXIT)
|
---|
608 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_CR3_STORE_EXIT *must* be set\n"));
|
---|
609 | if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_CR8_LOAD_EXIT)
|
---|
610 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_CR8_LOAD_EXIT *must* be set\n"));
|
---|
611 | if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_CR8_STORE_EXIT)
|
---|
612 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_CR8_STORE_EXIT *must* be set\n"));
|
---|
613 | if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_USE_TPR_SHADOW)
|
---|
614 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_USE_TPR_SHADOW *must* be set\n"));
|
---|
615 | if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_NMI_WINDOW_EXIT)
|
---|
616 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_NMI_WINDOW_EXIT *must* be set\n"));
|
---|
617 | if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_MOV_DR_EXIT)
|
---|
618 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_MOV_DR_EXIT *must* be set\n"));
|
---|
619 | if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_UNCOND_IO_EXIT)
|
---|
620 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_UNCOND_IO_EXIT *must* be set\n"));
|
---|
621 | if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_USE_IO_BITMAPS)
|
---|
622 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_USE_IO_BITMAPS *must* be set\n"));
|
---|
623 | if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_MONITOR_TRAP_FLAG)
|
---|
624 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_MONITOR_TRAP_FLAG *must* be set\n"));
|
---|
625 | if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_USE_MSR_BITMAPS)
|
---|
626 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_USE_MSR_BITMAPS *must* be set\n"));
|
---|
627 | if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_MONITOR_EXIT)
|
---|
628 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_MONITOR_EXIT *must* be set\n"));
|
---|
629 | if (val & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_PAUSE_EXIT)
|
---|
630 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_PAUSE_EXIT *must* be set\n"));
|
---|
631 | if (val & VMX_VMCS_CTRL_PROC_EXEC_USE_SECONDARY_EXEC_CTRL)
|
---|
632 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC_USE_SECONDARY_EXEC_CTRL *must* be set\n"));
|
---|
633 |
|
---|
634 | if (pVM->hwaccm.s.vmx.msr.vmx_proc_ctls.n.allowed1 & VMX_VMCS_CTRL_PROC_EXEC_USE_SECONDARY_EXEC_CTRL)
|
---|
635 | {
|
---|
636 | LogRel(("HWACCM: MSR_IA32_VMX_PROCBASED_CTLS2 = %RX64\n", pVM->hwaccm.s.vmx.msr.vmx_proc_ctls2.u));
|
---|
637 | val = pVM->hwaccm.s.vmx.msr.vmx_proc_ctls2.n.allowed1;
|
---|
638 | if (val & VMX_VMCS_CTRL_PROC_EXEC2_VIRT_APIC)
|
---|
639 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC2_VIRT_APIC\n"));
|
---|
640 | if (val & VMX_VMCS_CTRL_PROC_EXEC2_EPT)
|
---|
641 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC2_EPT\n"));
|
---|
642 | if (val & VMX_VMCS_CTRL_PROC_EXEC2_DESCRIPTOR_INSTR_EXIT)
|
---|
643 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC2_DESCRIPTOR_INSTR_EXIT\n"));
|
---|
644 | if (val & VMX_VMCS_CTRL_PROC_EXEC2_X2APIC)
|
---|
645 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC2_X2APIC\n"));
|
---|
646 | if (val & VMX_VMCS_CTRL_PROC_EXEC2_VPID)
|
---|
647 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC2_VPID\n"));
|
---|
648 | if (val & VMX_VMCS_CTRL_PROC_EXEC2_WBINVD_EXIT)
|
---|
649 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC2_WBINVD_EXIT\n"));
|
---|
650 |
|
---|
651 | val = pVM->hwaccm.s.vmx.msr.vmx_proc_ctls2.n.disallowed0;
|
---|
652 | if (val & VMX_VMCS_CTRL_PROC_EXEC2_VIRT_APIC)
|
---|
653 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC2_VIRT_APIC *must* be set\n"));
|
---|
654 | if (val & VMX_VMCS_CTRL_PROC_EXEC2_DESCRIPTOR_INSTR_EXIT)
|
---|
655 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC2_DESCRIPTOR_INSTR_EXIT *must* be set\n"));
|
---|
656 | if (val & VMX_VMCS_CTRL_PROC_EXEC2_X2APIC)
|
---|
657 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC2_X2APIC *must* be set\n"));
|
---|
658 | if (val & VMX_VMCS_CTRL_PROC_EXEC2_EPT)
|
---|
659 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC2_EPT *must* be set\n"));
|
---|
660 | if (val & VMX_VMCS_CTRL_PROC_EXEC2_VPID)
|
---|
661 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC2_VPID *must* be set\n"));
|
---|
662 | if (val & VMX_VMCS_CTRL_PROC_EXEC2_WBINVD_EXIT)
|
---|
663 | LogRel(("HWACCM: VMX_VMCS_CTRL_PROC_EXEC2_WBINVD_EXIT *must* be set\n"));
|
---|
664 | }
|
---|
665 |
|
---|
666 | LogRel(("HWACCM: MSR_IA32_VMX_ENTRY_CTLS = %RX64\n", pVM->hwaccm.s.vmx.msr.vmx_entry.u));
|
---|
667 | val = pVM->hwaccm.s.vmx.msr.vmx_entry.n.allowed1;
|
---|
668 | if (val & VMX_VMCS_CTRL_ENTRY_CONTROLS_LOAD_DEBUG)
|
---|
669 | LogRel(("HWACCM: VMX_VMCS_CTRL_ENTRY_CONTROLS_LOAD_DEBUG\n"));
|
---|
670 | if (val & VMX_VMCS_CTRL_ENTRY_CONTROLS_IA64_MODE)
|
---|
671 | LogRel(("HWACCM: VMX_VMCS_CTRL_ENTRY_CONTROLS_IA64_MODE\n"));
|
---|
672 | if (val & VMX_VMCS_CTRL_ENTRY_CONTROLS_ENTRY_SMM)
|
---|
673 | LogRel(("HWACCM: VMX_VMCS_CTRL_ENTRY_CONTROLS_ENTRY_SMM\n"));
|
---|
674 | if (val & VMX_VMCS_CTRL_ENTRY_CONTROLS_DEACTIVATE_DUALMON)
|
---|
675 | LogRel(("HWACCM: VMX_VMCS_CTRL_ENTRY_CONTROLS_DEACTIVATE_DUALMON\n"));
|
---|
676 | if (val & VMX_VMCS_CTRL_ENTRY_CONTROLS_LOAD_GUEST_PERF_MSR)
|
---|
677 | LogRel(("HWACCM: VMX_VMCS_CTRL_ENTRY_CONTROLS_LOAD_GUEST_PERF_MSR\n"));
|
---|
678 | if (val & VMX_VMCS_CTRL_ENTRY_CONTROLS_LOAD_GUEST_PAT_MSR)
|
---|
679 | LogRel(("HWACCM: VMX_VMCS_CTRL_ENTRY_CONTROLS_LOAD_GUEST_PAT_MSR\n"));
|
---|
680 | if (val & VMX_VMCS_CTRL_ENTRY_CONTROLS_LOAD_GUEST_EFER_MSR)
|
---|
681 | LogRel(("HWACCM: VMX_VMCS_CTRL_ENTRY_CONTROLS_LOAD_GUEST_EFER_MSR\n"));
|
---|
682 | val = pVM->hwaccm.s.vmx.msr.vmx_entry.n.disallowed0;
|
---|
683 | if (val & VMX_VMCS_CTRL_ENTRY_CONTROLS_LOAD_DEBUG)
|
---|
684 | LogRel(("HWACCM: VMX_VMCS_CTRL_ENTRY_CONTROLS_LOAD_DEBUG *must* be set\n"));
|
---|
685 | if (val & VMX_VMCS_CTRL_ENTRY_CONTROLS_IA64_MODE)
|
---|
686 | LogRel(("HWACCM: VMX_VMCS_CTRL_ENTRY_CONTROLS_IA64_MODE *must* be set\n"));
|
---|
687 | if (val & VMX_VMCS_CTRL_ENTRY_CONTROLS_ENTRY_SMM)
|
---|
688 | LogRel(("HWACCM: VMX_VMCS_CTRL_ENTRY_CONTROLS_ENTRY_SMM *must* be set\n"));
|
---|
689 | if (val & VMX_VMCS_CTRL_ENTRY_CONTROLS_DEACTIVATE_DUALMON)
|
---|
690 | LogRel(("HWACCM: VMX_VMCS_CTRL_ENTRY_CONTROLS_DEACTIVATE_DUALMON *must* be set\n"));
|
---|
691 | if (val & VMX_VMCS_CTRL_ENTRY_CONTROLS_LOAD_GUEST_PERF_MSR)
|
---|
692 | LogRel(("HWACCM: VMX_VMCS_CTRL_ENTRY_CONTROLS_LOAD_GUEST_PERF_MSR *must* be set\n"));
|
---|
693 | if (val & VMX_VMCS_CTRL_ENTRY_CONTROLS_LOAD_GUEST_PAT_MSR)
|
---|
694 | LogRel(("HWACCM: VMX_VMCS_CTRL_ENTRY_CONTROLS_LOAD_GUEST_PAT_MSR *must* be set\n"));
|
---|
695 | if (val & VMX_VMCS_CTRL_ENTRY_CONTROLS_LOAD_GUEST_EFER_MSR)
|
---|
696 | LogRel(("HWACCM: VMX_VMCS_CTRL_ENTRY_CONTROLS_LOAD_GUEST_EFER_MSR *must* be set\n"));
|
---|
697 |
|
---|
698 | LogRel(("HWACCM: MSR_IA32_VMX_EXIT_CTLS = %RX64\n", pVM->hwaccm.s.vmx.msr.vmx_exit.u));
|
---|
699 | val = pVM->hwaccm.s.vmx.msr.vmx_exit.n.allowed1;
|
---|
700 | if (val & VMX_VMCS_CTRL_EXIT_CONTROLS_SAVE_DEBUG)
|
---|
701 | LogRel(("HWACCM: VMX_VMCS_CTRL_EXIT_CONTROLS_SAVE_DEBUG\n"));
|
---|
702 | if (val & VMX_VMCS_CTRL_EXIT_CONTROLS_HOST_AMD64)
|
---|
703 | LogRel(("HWACCM: VMX_VMCS_CTRL_EXIT_CONTROLS_HOST_AMD64\n"));
|
---|
704 | if (val & VMX_VMCS_CTRL_EXIT_CONTROLS_ACK_EXTERNAL_IRQ)
|
---|
705 | LogRel(("HWACCM: VMX_VMCS_CTRL_EXIT_CONTROLS_ACK_EXTERNAL_IRQ\n"));
|
---|
706 | if (val & VMX_VMCS_CTRL_EXIT_CONTROLS_SAVE_GUEST_PAT_MSR)
|
---|
707 | LogRel(("HWACCM: VMX_VMCS_CTRL_EXIT_CONTROLS_SAVE_GUEST_PAT_MSR\n"));
|
---|
708 | if (val & VMX_VMCS_CTRL_EXIT_CONTROLS_LOAD_HOST_PAT_MSR)
|
---|
709 | LogRel(("HWACCM: VMX_VMCS_CTRL_EXIT_CONTROLS_LOAD_HOST_PAT_MSR\n"));
|
---|
710 | if (val & VMX_VMCS_CTRL_EXIT_CONTROLS_SAVE_GUEST_EFER_MSR)
|
---|
711 | LogRel(("HWACCM: VMX_VMCS_CTRL_EXIT_CONTROLS_SAVE_GUEST_EFER_MSR\n"));
|
---|
712 | if (val & VMX_VMCS_CTRL_EXIT_CONTROLS_LOAD_HOST_EFER_MSR)
|
---|
713 | LogRel(("HWACCM: VMX_VMCS_CTRL_EXIT_CONTROLS_LOAD_HOST_EFER_MSR\n"));
|
---|
714 | if (val & VMX_VMCS_CTRL_EXIT_CONTROLS_SAVE_VMX_PREEMPT_TIMER)
|
---|
715 | LogRel(("HWACCM: VMX_VMCS_CTRL_EXIT_CONTROLS_SAVE_VMX_PREEMPT_TIMER\n"));
|
---|
716 | val = pVM->hwaccm.s.vmx.msr.vmx_exit.n.disallowed0;
|
---|
717 | if (val & VMX_VMCS_CTRL_EXIT_CONTROLS_SAVE_DEBUG)
|
---|
718 | LogRel(("HWACCM: VMX_VMCS_CTRL_EXIT_CONTROLS_SAVE_DEBUG *must* be set\n"));
|
---|
719 | if (val & VMX_VMCS_CTRL_EXIT_CONTROLS_HOST_AMD64)
|
---|
720 | LogRel(("HWACCM: VMX_VMCS_CTRL_EXIT_CONTROLS_HOST_AMD64 *must* be set\n"));
|
---|
721 | if (val & VMX_VMCS_CTRL_EXIT_CONTROLS_ACK_EXTERNAL_IRQ)
|
---|
722 | LogRel(("HWACCM: VMX_VMCS_CTRL_EXIT_CONTROLS_ACK_EXTERNAL_IRQ *must* be set\n"));
|
---|
723 | if (val & VMX_VMCS_CTRL_EXIT_CONTROLS_SAVE_GUEST_PAT_MSR)
|
---|
724 | LogRel(("HWACCM: VMX_VMCS_CTRL_EXIT_CONTROLS_SAVE_GUEST_PAT_MSR *must* be set\n"));
|
---|
725 | if (val & VMX_VMCS_CTRL_EXIT_CONTROLS_LOAD_HOST_PAT_MSR)
|
---|
726 | LogRel(("HWACCM: VMX_VMCS_CTRL_EXIT_CONTROLS_LOAD_HOST_PAT_MSR *must* be set\n"));
|
---|
727 | if (val & VMX_VMCS_CTRL_EXIT_CONTROLS_SAVE_GUEST_EFER_MSR)
|
---|
728 | LogRel(("HWACCM: VMX_VMCS_CTRL_EXIT_CONTROLS_SAVE_GUEST_EFER_MSR *must* be set\n"));
|
---|
729 | if (val & VMX_VMCS_CTRL_EXIT_CONTROLS_LOAD_HOST_EFER_MSR)
|
---|
730 | LogRel(("HWACCM: VMX_VMCS_CTRL_EXIT_CONTROLS_LOAD_HOST_EFER_MSR *must* be set\n"));
|
---|
731 | if (val & VMX_VMCS_CTRL_EXIT_CONTROLS_SAVE_VMX_PREEMPT_TIMER)
|
---|
732 | LogRel(("HWACCM: VMX_VMCS_CTRL_EXIT_CONTROLS_SAVE_VMX_PREEMPT_TIMER *must* be set\n"));
|
---|
733 |
|
---|
734 | if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps)
|
---|
735 | {
|
---|
736 | LogRel(("HWACCM: MSR_IA32_VMX_EPT_VPID_CAPS = %RX64\n", pVM->hwaccm.s.vmx.msr.vmx_eptcaps));
|
---|
737 |
|
---|
738 | if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_RWX_X_ONLY)
|
---|
739 | LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_RWX_X_ONLY\n"));
|
---|
740 | if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_RWX_W_ONLY)
|
---|
741 | LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_RWX_W_ONLY\n"));
|
---|
742 | if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_RWX_WX_ONLY)
|
---|
743 | LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_RWX_WX_ONLY\n"));
|
---|
744 | if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_GAW_21_BITS)
|
---|
745 | LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_GAW_21_BITS\n"));
|
---|
746 | if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_GAW_30_BITS)
|
---|
747 | LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_GAW_30_BITS\n"));
|
---|
748 | if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_GAW_39_BITS)
|
---|
749 | LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_GAW_39_BITS\n"));
|
---|
750 | if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_GAW_48_BITS)
|
---|
751 | LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_GAW_48_BITS\n"));
|
---|
752 | if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_GAW_57_BITS)
|
---|
753 | LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_GAW_57_BITS\n"));
|
---|
754 | if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_EMT_UC)
|
---|
755 | LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_EMT_UC\n"));
|
---|
756 | if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_EMT_WC)
|
---|
757 | LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_EMT_WC\n"));
|
---|
758 | if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_EMT_WT)
|
---|
759 | LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_EMT_WT\n"));
|
---|
760 | if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_EMT_WP)
|
---|
761 | LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_EMT_WP\n"));
|
---|
762 | if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_EMT_WB)
|
---|
763 | LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_EMT_WB\n"));
|
---|
764 | if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_SP_21_BITS)
|
---|
765 | LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_SP_21_BITS\n"));
|
---|
766 | if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_SP_30_BITS)
|
---|
767 | LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_SP_30_BITS\n"));
|
---|
768 | if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_SP_39_BITS)
|
---|
769 | LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_SP_39_BITS\n"));
|
---|
770 | if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_SP_48_BITS)
|
---|
771 | LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_SP_48_BITS\n"));
|
---|
772 | if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_INVEPT)
|
---|
773 | LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_INVEPT\n"));
|
---|
774 | if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_INVEPT_CAPS_INDIV)
|
---|
775 | LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_INVEPT_CAPS_INDIV\n"));
|
---|
776 | if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_INVEPT_CAPS_CONTEXT)
|
---|
777 | LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_INVEPT_CAPS_CONTEXT\n"));
|
---|
778 | if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_INVEPT_CAPS_ALL)
|
---|
779 | LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_INVEPT_CAPS_ALL\n"));
|
---|
780 | if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_INVVPID)
|
---|
781 | LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_INVVPID\n"));
|
---|
782 | if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_INVVPID_CAPS_INDIV)
|
---|
783 | LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_INVVPID_CAPS_INDIV\n"));
|
---|
784 | if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_INVVPID_CAPS_CONTEXT)
|
---|
785 | LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_INVVPID_CAPS_CONTEXT\n"));
|
---|
786 | if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_INVVPID_CAPS_ALL)
|
---|
787 | LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_INVVPID_CAPS_ALL\n"));
|
---|
788 | if (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_INVVPID_CAPS_CONTEXT_GLOBAL)
|
---|
789 | LogRel(("HWACCM: MSR_IA32_VMX_EPT_CAPS_INVVPID_CAPS_CONTEXT_GLOBAL\n"));
|
---|
790 | }
|
---|
791 |
|
---|
792 | LogRel(("HWACCM: MSR_IA32_VMX_MISC = %RX64\n", pVM->hwaccm.s.vmx.msr.vmx_misc));
|
---|
793 | LogRel(("HWACCM: MSR_IA32_VMX_MISC_PREEMPT_TSC_BIT %x\n", MSR_IA32_VMX_MISC_PREEMPT_TSC_BIT(pVM->hwaccm.s.vmx.msr.vmx_misc)));
|
---|
794 | LogRel(("HWACCM: MSR_IA32_VMX_MISC_ACTIVITY_STATES %x\n", MSR_IA32_VMX_MISC_ACTIVITY_STATES(pVM->hwaccm.s.vmx.msr.vmx_misc)));
|
---|
795 | LogRel(("HWACCM: MSR_IA32_VMX_MISC_CR3_TARGET %x\n", MSR_IA32_VMX_MISC_CR3_TARGET(pVM->hwaccm.s.vmx.msr.vmx_misc)));
|
---|
796 | LogRel(("HWACCM: MSR_IA32_VMX_MISC_MAX_MSR %x\n", MSR_IA32_VMX_MISC_MAX_MSR(pVM->hwaccm.s.vmx.msr.vmx_misc)));
|
---|
797 | LogRel(("HWACCM: MSR_IA32_VMX_MISC_MSEG_ID %x\n", MSR_IA32_VMX_MISC_MSEG_ID(pVM->hwaccm.s.vmx.msr.vmx_misc)));
|
---|
798 |
|
---|
799 | LogRel(("HWACCM: MSR_IA32_VMX_CR0_FIXED0 = %RX64\n", pVM->hwaccm.s.vmx.msr.vmx_cr0_fixed0));
|
---|
800 | LogRel(("HWACCM: MSR_IA32_VMX_CR0_FIXED1 = %RX64\n", pVM->hwaccm.s.vmx.msr.vmx_cr0_fixed1));
|
---|
801 | LogRel(("HWACCM: MSR_IA32_VMX_CR4_FIXED0 = %RX64\n", pVM->hwaccm.s.vmx.msr.vmx_cr4_fixed0));
|
---|
802 | LogRel(("HWACCM: MSR_IA32_VMX_CR4_FIXED1 = %RX64\n", pVM->hwaccm.s.vmx.msr.vmx_cr4_fixed1));
|
---|
803 | LogRel(("HWACCM: MSR_IA32_VMX_VMCS_ENUM = %RX64\n", pVM->hwaccm.s.vmx.msr.vmx_vmcs_enum));
|
---|
804 |
|
---|
805 | LogRel(("HWACCM: TPR shadow physaddr = %RHp\n", pVM->hwaccm.s.vmx.pAPICPhys));
|
---|
806 | LogRel(("HWACCM: MSR bitmap physaddr = %RHp\n", pVM->hwaccm.s.vmx.pMSRBitmapPhys));
|
---|
807 |
|
---|
808 | for (unsigned i=0;i<pVM->cCPUs;i++)
|
---|
809 | LogRel(("HWACCM: VMCS physaddr VCPU%d = %RHp\n", i, pVM->aCpus[i].hwaccm.s.vmx.pVMCSPhys));
|
---|
810 |
|
---|
811 | #ifdef HWACCM_VTX_WITH_EPT
|
---|
812 | if (pVM->hwaccm.s.vmx.msr.vmx_proc_ctls2.n.allowed1 & VMX_VMCS_CTRL_PROC_EXEC2_EPT)
|
---|
813 | pVM->hwaccm.s.fNestedPaging = pVM->hwaccm.s.fAllowNestedPaging;
|
---|
814 | #endif /* HWACCM_VTX_WITH_EPT */
|
---|
815 | #ifdef HWACCM_VTX_WITH_VPID
|
---|
816 | if ( (pVM->hwaccm.s.vmx.msr.vmx_proc_ctls2.n.allowed1 & VMX_VMCS_CTRL_PROC_EXEC2_VPID)
|
---|
817 | && !pVM->hwaccm.s.fNestedPaging) /* VPID and EPT are mutually exclusive. */
|
---|
818 | pVM->hwaccm.s.vmx.fVPID = pVM->hwaccm.s.vmx.fAllowVPID;
|
---|
819 | #endif /* HWACCM_VTX_WITH_VPID */
|
---|
820 |
|
---|
821 | /* Only try once. */
|
---|
822 | pVM->hwaccm.s.fInitialized = true;
|
---|
823 |
|
---|
824 | /* Allocate three pages for the TSS we need for real mode emulation. (2 page for the IO bitmap) */
|
---|
825 | #if 1
|
---|
826 | rc = PDMR3VMMDevHeapAlloc(pVM, HWACCM_VTX_TOTAL_DEVHEAP_MEM, (RTR3PTR *)&pVM->hwaccm.s.vmx.pRealModeTSS);
|
---|
827 | #else
|
---|
828 | rc = VERR_NO_MEMORY; /* simulation of no VMMDev Heap. */
|
---|
829 | #endif
|
---|
830 | if (RT_SUCCESS(rc))
|
---|
831 | {
|
---|
832 | /* The I/O bitmap starts right after the virtual interrupt redirection bitmap. */
|
---|
833 | ASMMemZero32(pVM->hwaccm.s.vmx.pRealModeTSS, sizeof(*pVM->hwaccm.s.vmx.pRealModeTSS));
|
---|
834 | pVM->hwaccm.s.vmx.pRealModeTSS->offIoBitmap = sizeof(*pVM->hwaccm.s.vmx.pRealModeTSS);
|
---|
835 | /* Bit set to 0 means redirection enabled. */
|
---|
836 | memset(pVM->hwaccm.s.vmx.pRealModeTSS->IntRedirBitmap, 0x0, sizeof(pVM->hwaccm.s.vmx.pRealModeTSS->IntRedirBitmap));
|
---|
837 | /* Allow all port IO, so the VT-x IO intercepts do their job. */
|
---|
838 | memset(pVM->hwaccm.s.vmx.pRealModeTSS + 1, 0, PAGE_SIZE*2);
|
---|
839 | *((unsigned char *)pVM->hwaccm.s.vmx.pRealModeTSS + HWACCM_VTX_TSS_SIZE - 2) = 0xff;
|
---|
840 |
|
---|
841 | /* Construct a 1024 element page directory with 4 MB pages for the identity mapped page table used in
|
---|
842 | * real and protected mode without paging with EPT.
|
---|
843 | */
|
---|
844 | pVM->hwaccm.s.vmx.pNonPagingModeEPTPageTable = (PX86PD)((char *)pVM->hwaccm.s.vmx.pRealModeTSS + PAGE_SIZE * 3);
|
---|
845 | for (unsigned i=0;i<X86_PG_ENTRIES;i++)
|
---|
846 | {
|
---|
847 | pVM->hwaccm.s.vmx.pNonPagingModeEPTPageTable->a[i].u = _4M * i;
|
---|
848 | 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;
|
---|
849 | }
|
---|
850 |
|
---|
851 | /* We convert it here every time as pci regions could be reconfigured. */
|
---|
852 | rc = PDMVMMDevHeapR3ToGCPhys(pVM, pVM->hwaccm.s.vmx.pRealModeTSS, &GCPhys);
|
---|
853 | AssertRC(rc);
|
---|
854 | LogRel(("HWACCM: Real Mode TSS guest physaddr = %RGp\n", GCPhys));
|
---|
855 |
|
---|
856 | rc = PDMVMMDevHeapR3ToGCPhys(pVM, pVM->hwaccm.s.vmx.pNonPagingModeEPTPageTable, &GCPhys);
|
---|
857 | AssertRC(rc);
|
---|
858 | LogRel(("HWACCM: Non-Paging Mode EPT CR3 = %RGp\n", GCPhys));
|
---|
859 | }
|
---|
860 | else
|
---|
861 | {
|
---|
862 | LogRel(("HWACCM: No real mode VT-x support (PDMR3VMMDevHeapAlloc returned %Rrc)\n", rc));
|
---|
863 | pVM->hwaccm.s.vmx.pRealModeTSS = NULL;
|
---|
864 | pVM->hwaccm.s.vmx.pNonPagingModeEPTPageTable = NULL;
|
---|
865 | }
|
---|
866 |
|
---|
867 | rc = SUPCallVMMR0Ex(pVM->pVMR0, VMMR0_DO_HWACC_SETUP_VM, 0, NULL);
|
---|
868 | AssertRC(rc);
|
---|
869 | if (rc == VINF_SUCCESS)
|
---|
870 | {
|
---|
871 | pVM->fHWACCMEnabled = true;
|
---|
872 | pVM->hwaccm.s.vmx.fEnabled = true;
|
---|
873 | hwaccmR3DisableRawMode(pVM);
|
---|
874 |
|
---|
875 | CPUMSetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_SEP);
|
---|
876 | #ifdef VBOX_ENABLE_64_BITS_GUESTS
|
---|
877 | if (pVM->hwaccm.s.fAllow64BitGuests)
|
---|
878 | {
|
---|
879 | CPUMSetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_PAE);
|
---|
880 | CPUMSetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_LONG_MODE);
|
---|
881 | CPUMSetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_SYSCALL); /* 64 bits only on Intel CPUs */
|
---|
882 | CPUMSetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_LAHF);
|
---|
883 | CPUMSetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_NXE);
|
---|
884 | }
|
---|
885 | LogRel((pVM->hwaccm.s.fAllow64BitGuests
|
---|
886 | ? "HWACCM: 32-bit and 64-bit guest supported.\n"
|
---|
887 | : "HWACCM: 32-bit guest supported.\n"));
|
---|
888 | #else
|
---|
889 | LogRel(("HWACCM: 32-bit guest supported.\n"));
|
---|
890 | #endif
|
---|
891 | LogRel(("HWACCM: VMX enabled!\n"));
|
---|
892 | if (pVM->hwaccm.s.fNestedPaging)
|
---|
893 | {
|
---|
894 | LogRel(("HWACCM: Enabled nested paging\n"));
|
---|
895 | LogRel(("HWACCM: EPT root page = %RHp\n", PGMGetEPTCR3(pVM)));
|
---|
896 | }
|
---|
897 | if (pVM->hwaccm.s.vmx.fVPID)
|
---|
898 | LogRel(("HWACCM: Enabled VPID\n"));
|
---|
899 |
|
---|
900 | if ( pVM->hwaccm.s.fNestedPaging
|
---|
901 | || pVM->hwaccm.s.vmx.fVPID)
|
---|
902 | {
|
---|
903 | LogRel(("HWACCM: enmFlushPage %d\n", pVM->hwaccm.s.vmx.enmFlushPage));
|
---|
904 | LogRel(("HWACCM: enmFlushContext %d\n", pVM->hwaccm.s.vmx.enmFlushContext));
|
---|
905 | }
|
---|
906 | }
|
---|
907 | else
|
---|
908 | {
|
---|
909 | LogRel(("HWACCM: VMX setup failed with rc=%Rrc!\n", rc));
|
---|
910 | LogRel(("HWACCM: Last instruction error %x\n", pVM->aCpus[0].hwaccm.s.vmx.lasterror.ulInstrError));
|
---|
911 | pVM->fHWACCMEnabled = false;
|
---|
912 | }
|
---|
913 | }
|
---|
914 | }
|
---|
915 | else
|
---|
916 | if (pVM->hwaccm.s.svm.fSupported)
|
---|
917 | {
|
---|
918 | Log(("pVM->hwaccm.s.svm.fSupported = %d\n", pVM->hwaccm.s.svm.fSupported));
|
---|
919 |
|
---|
920 | if (pVM->hwaccm.s.fInitialized == false)
|
---|
921 | {
|
---|
922 | /* Erratum 170 which requires a forced TLB flush for each world switch:
|
---|
923 | * See http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/33610.pdf
|
---|
924 | *
|
---|
925 | * All BH-G1/2 and DH-G1/2 models include a fix:
|
---|
926 | * Athlon X2: 0x6b 1/2
|
---|
927 | * 0x68 1/2
|
---|
928 | * Athlon 64: 0x7f 1
|
---|
929 | * 0x6f 2
|
---|
930 | * Sempron: 0x7f 1/2
|
---|
931 | * 0x6f 2
|
---|
932 | * 0x6c 2
|
---|
933 | * 0x7c 2
|
---|
934 | * Turion 64: 0x68 2
|
---|
935 | *
|
---|
936 | */
|
---|
937 | uint32_t u32Dummy;
|
---|
938 | uint32_t u32Version, u32Family, u32Model, u32Stepping, u32BaseFamily;
|
---|
939 | ASMCpuId(1, &u32Version, &u32Dummy, &u32Dummy, &u32Dummy);
|
---|
940 | u32BaseFamily= (u32Version >> 8) & 0xf;
|
---|
941 | u32Family = u32BaseFamily + (u32BaseFamily == 0xf ? ((u32Version >> 20) & 0x7f) : 0);
|
---|
942 | u32Model = ((u32Version >> 4) & 0xf);
|
---|
943 | u32Model = u32Model | ((u32BaseFamily == 0xf ? (u32Version >> 16) & 0x0f : 0) << 4);
|
---|
944 | u32Stepping = u32Version & 0xf;
|
---|
945 | if ( u32Family == 0xf
|
---|
946 | && !((u32Model == 0x68 || u32Model == 0x6b || u32Model == 0x7f) && u32Stepping >= 1)
|
---|
947 | && !((u32Model == 0x6f || u32Model == 0x6c || u32Model == 0x7c) && u32Stepping >= 2))
|
---|
948 | {
|
---|
949 | LogRel(("HWACMM: AMD cpu with erratum 170 family %x model %x stepping %x\n", u32Family, u32Model, u32Stepping));
|
---|
950 | }
|
---|
951 |
|
---|
952 | LogRel(("HWACMM: cpuid 0x80000001.u32AMDFeatureECX = %RX32\n", pVM->hwaccm.s.cpuid.u32AMDFeatureECX));
|
---|
953 | LogRel(("HWACMM: cpuid 0x80000001.u32AMDFeatureEDX = %RX32\n", pVM->hwaccm.s.cpuid.u32AMDFeatureEDX));
|
---|
954 | LogRel(("HWACCM: SVM revision = %X\n", pVM->hwaccm.s.svm.u32Rev));
|
---|
955 | LogRel(("HWACCM: SVM max ASID = %d\n", pVM->hwaccm.s.uMaxASID));
|
---|
956 | LogRel(("HWACCM: SVM features = %X\n", pVM->hwaccm.s.svm.u32Features));
|
---|
957 |
|
---|
958 | if (pVM->hwaccm.s.svm.u32Features & AMD_CPUID_SVM_FEATURE_EDX_NESTED_PAGING)
|
---|
959 | LogRel(("HWACCM: AMD_CPUID_SVM_FEATURE_EDX_NESTED_PAGING\n"));
|
---|
960 | if (pVM->hwaccm.s.svm.u32Features & AMD_CPUID_SVM_FEATURE_EDX_LBR_VIRT)
|
---|
961 | LogRel(("HWACCM: AMD_CPUID_SVM_FEATURE_EDX_LBR_VIRT\n"));
|
---|
962 | if (pVM->hwaccm.s.svm.u32Features & AMD_CPUID_SVM_FEATURE_EDX_SVM_LOCK)
|
---|
963 | LogRel(("HWACCM: AMD_CPUID_SVM_FEATURE_EDX_SVM_LOCK\n"));
|
---|
964 | if (pVM->hwaccm.s.svm.u32Features & AMD_CPUID_SVM_FEATURE_EDX_NRIP_SAVE)
|
---|
965 | LogRel(("HWACCM: AMD_CPUID_SVM_FEATURE_EDX_NRIP_SAVE\n"));
|
---|
966 | if (pVM->hwaccm.s.svm.u32Features & AMD_CPUID_SVM_FEATURE_EDX_SSE_3_5_DISABLE)
|
---|
967 | LogRel(("HWACCM: AMD_CPUID_SVM_FEATURE_EDX_SSE_3_5_DISABLE\n"));
|
---|
968 |
|
---|
969 | /* Only try once. */
|
---|
970 | pVM->hwaccm.s.fInitialized = true;
|
---|
971 |
|
---|
972 | if (pVM->hwaccm.s.svm.u32Features & AMD_CPUID_SVM_FEATURE_EDX_NESTED_PAGING)
|
---|
973 | pVM->hwaccm.s.fNestedPaging = pVM->hwaccm.s.fAllowNestedPaging;
|
---|
974 |
|
---|
975 | rc = SUPCallVMMR0Ex(pVM->pVMR0, VMMR0_DO_HWACC_SETUP_VM, 0, NULL);
|
---|
976 | AssertRC(rc);
|
---|
977 | if (rc == VINF_SUCCESS)
|
---|
978 | {
|
---|
979 | pVM->fHWACCMEnabled = true;
|
---|
980 | pVM->hwaccm.s.svm.fEnabled = true;
|
---|
981 |
|
---|
982 | if (pVM->hwaccm.s.fNestedPaging)
|
---|
983 | LogRel(("HWACCM: Enabled nested paging\n"));
|
---|
984 |
|
---|
985 | hwaccmR3DisableRawMode(pVM);
|
---|
986 | CPUMSetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_SEP);
|
---|
987 | CPUMSetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_SYSCALL);
|
---|
988 | CPUMSetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_RDTSCP);
|
---|
989 | #ifdef VBOX_ENABLE_64_BITS_GUESTS
|
---|
990 | if (pVM->hwaccm.s.fAllow64BitGuests)
|
---|
991 | {
|
---|
992 | CPUMSetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_PAE);
|
---|
993 | CPUMSetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_LONG_MODE);
|
---|
994 | CPUMSetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_NXE);
|
---|
995 | CPUMSetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_LAHF);
|
---|
996 | }
|
---|
997 | #endif
|
---|
998 | LogRel((pVM->hwaccm.s.fAllow64BitGuests
|
---|
999 | ? "HWACCM: 32-bit and 64-bit guest supported.\n"
|
---|
1000 | : "HWACCM: 32-bit guest supported.\n"));
|
---|
1001 | }
|
---|
1002 | else
|
---|
1003 | {
|
---|
1004 | pVM->fHWACCMEnabled = false;
|
---|
1005 | }
|
---|
1006 | }
|
---|
1007 | }
|
---|
1008 | return VINF_SUCCESS;
|
---|
1009 | }
|
---|
1010 |
|
---|
1011 | /**
|
---|
1012 | * Applies relocations to data and code managed by this
|
---|
1013 | * component. This function will be called at init and
|
---|
1014 | * whenever the VMM need to relocate it self inside the GC.
|
---|
1015 | *
|
---|
1016 | * @param pVM The VM.
|
---|
1017 | */
|
---|
1018 | VMMR3DECL(void) HWACCMR3Relocate(PVM pVM)
|
---|
1019 | {
|
---|
1020 | Log(("HWACCMR3Relocate to %RGv\n", MMHyperGetArea(pVM, 0)));
|
---|
1021 |
|
---|
1022 | /* Fetch the current paging mode during the relocate callback during state loading. */
|
---|
1023 | if (VMR3GetState(pVM) == VMSTATE_LOADING)
|
---|
1024 | {
|
---|
1025 | for (unsigned i=0;i<pVM->cCPUs;i++)
|
---|
1026 | {
|
---|
1027 | PVMCPU pVCpu = &pVM->aCpus[i];
|
---|
1028 | /* @todo SMP */
|
---|
1029 | pVCpu->hwaccm.s.enmShadowMode = PGMGetShadowMode(pVM);
|
---|
1030 | pVCpu->hwaccm.s.vmx.enmLastSeenGuestMode = PGMGetGuestMode(pVM);
|
---|
1031 | }
|
---|
1032 | }
|
---|
1033 | #if HC_ARCH_BITS == 32 && defined(VBOX_ENABLE_64_BITS_GUESTS) && !defined(VBOX_WITH_HYBRID_32BIT_KERNEL)
|
---|
1034 | if (pVM->fHWACCMEnabled)
|
---|
1035 | {
|
---|
1036 | int rc;
|
---|
1037 |
|
---|
1038 | switch(PGMGetHostMode(pVM))
|
---|
1039 | {
|
---|
1040 | case PGMMODE_32_BIT:
|
---|
1041 | pVM->hwaccm.s.pfnHost32ToGuest64R0 = VMMR3GetHostToGuestSwitcher(pVM, VMMSWITCHER_32_TO_AMD64);
|
---|
1042 | break;
|
---|
1043 |
|
---|
1044 | case PGMMODE_PAE:
|
---|
1045 | case PGMMODE_PAE_NX:
|
---|
1046 | pVM->hwaccm.s.pfnHost32ToGuest64R0 = VMMR3GetHostToGuestSwitcher(pVM, VMMSWITCHER_PAE_TO_AMD64);
|
---|
1047 | break;
|
---|
1048 |
|
---|
1049 | default:
|
---|
1050 | AssertFailed();
|
---|
1051 | break;
|
---|
1052 | }
|
---|
1053 | rc = PDMR3LdrGetSymbolRC(pVM, NULL, "VMXGCStartVM64", &pVM->hwaccm.s.pfnVMXGCStartVM64);
|
---|
1054 | AssertReleaseMsgRC(rc, ("VMXGCStartVM64 -> rc=%Rrc\n", rc));
|
---|
1055 |
|
---|
1056 | rc = PDMR3LdrGetSymbolRC(pVM, NULL, "SVMGCVMRun64", &pVM->hwaccm.s.pfnSVMGCVMRun64);
|
---|
1057 | AssertReleaseMsgRC(rc, ("SVMGCVMRun64 -> rc=%Rrc\n", rc));
|
---|
1058 |
|
---|
1059 | rc = PDMR3LdrGetSymbolRC(pVM, NULL, "HWACCMSaveGuestFPU64", &pVM->hwaccm.s.pfnSaveGuestFPU64);
|
---|
1060 | AssertReleaseMsgRC(rc, ("HWACCMSetupFPU64 -> rc=%Rrc\n", rc));
|
---|
1061 |
|
---|
1062 | rc = PDMR3LdrGetSymbolRC(pVM, NULL, "HWACCMSaveGuestDebug64", &pVM->hwaccm.s.pfnSaveGuestDebug64);
|
---|
1063 | AssertReleaseMsgRC(rc, ("HWACCMSetupDebug64 -> rc=%Rrc\n", rc));
|
---|
1064 |
|
---|
1065 | # ifdef DEBUG
|
---|
1066 | rc = PDMR3LdrGetSymbolRC(pVM, NULL, "HWACCMTestSwitcher64", &pVM->hwaccm.s.pfnTest64);
|
---|
1067 | AssertReleaseMsgRC(rc, ("HWACCMTestSwitcher64 -> rc=%Rrc\n", rc));
|
---|
1068 | # endif
|
---|
1069 | }
|
---|
1070 | #endif
|
---|
1071 | return;
|
---|
1072 | }
|
---|
1073 |
|
---|
1074 | /**
|
---|
1075 | * Checks hardware accelerated raw mode is allowed.
|
---|
1076 | *
|
---|
1077 | * @returns boolean
|
---|
1078 | * @param pVM The VM to operate on.
|
---|
1079 | */
|
---|
1080 | VMMR3DECL(bool) HWACCMR3IsAllowed(PVM pVM)
|
---|
1081 | {
|
---|
1082 | return pVM->hwaccm.s.fAllowed;
|
---|
1083 | }
|
---|
1084 |
|
---|
1085 | /**
|
---|
1086 | * Notification callback which is called whenever there is a chance that a CR3
|
---|
1087 | * value might have changed.
|
---|
1088 | *
|
---|
1089 | * This is called by PGM.
|
---|
1090 | *
|
---|
1091 | * @param pVM The VM to operate on.
|
---|
1092 | * @param enmShadowMode New shadow paging mode.
|
---|
1093 | * @param enmGuestMode New guest paging mode.
|
---|
1094 | */
|
---|
1095 | VMMR3DECL(void) HWACCMR3PagingModeChanged(PVM pVM, PGMMODE enmShadowMode, PGMMODE enmGuestMode)
|
---|
1096 | {
|
---|
1097 | /* Ignore page mode changes during state loading. */
|
---|
1098 | if (VMR3GetState(pVM) == VMSTATE_LOADING)
|
---|
1099 | return;
|
---|
1100 |
|
---|
1101 | PVMCPU pVCpu = VMMGetCpu(pVM);
|
---|
1102 | pVCpu->hwaccm.s.enmShadowMode = enmShadowMode;
|
---|
1103 |
|
---|
1104 | if ( pVM->hwaccm.s.vmx.fEnabled
|
---|
1105 | && pVM->fHWACCMEnabled)
|
---|
1106 | {
|
---|
1107 | if ( pVCpu->hwaccm.s.vmx.enmLastSeenGuestMode == PGMMODE_REAL
|
---|
1108 | && enmGuestMode >= PGMMODE_PROTECTED)
|
---|
1109 | {
|
---|
1110 | PCPUMCTX pCtx;
|
---|
1111 |
|
---|
1112 | pCtx = CPUMQueryGuestCtxPtr(pVM);
|
---|
1113 |
|
---|
1114 | /* After a real mode switch to protected mode we must force
|
---|
1115 | * CPL to 0. Our real mode emulation had to set it to 3.
|
---|
1116 | */
|
---|
1117 | pCtx->ssHid.Attr.n.u2Dpl = 0;
|
---|
1118 | }
|
---|
1119 | }
|
---|
1120 |
|
---|
1121 | if (pVCpu->hwaccm.s.vmx.enmCurrGuestMode != enmGuestMode)
|
---|
1122 | {
|
---|
1123 | /* Keep track of paging mode changes. */
|
---|
1124 | pVCpu->hwaccm.s.vmx.enmPrevGuestMode = pVCpu->hwaccm.s.vmx.enmCurrGuestMode;
|
---|
1125 | pVCpu->hwaccm.s.vmx.enmCurrGuestMode = enmGuestMode;
|
---|
1126 |
|
---|
1127 | /* Did we miss a change, because all code was executed in the recompiler? */
|
---|
1128 | if (pVCpu->hwaccm.s.vmx.enmLastSeenGuestMode == enmGuestMode)
|
---|
1129 | {
|
---|
1130 | Log(("HWACCMR3PagingModeChanged missed %s->%s transition (prev %s)\n", PGMGetModeName(pVCpu->hwaccm.s.vmx.enmPrevGuestMode), PGMGetModeName(pVCpu->hwaccm.s.vmx.enmCurrGuestMode), PGMGetModeName(pVCpu->hwaccm.s.vmx.enmLastSeenGuestMode)));
|
---|
1131 | pVCpu->hwaccm.s.vmx.enmLastSeenGuestMode = pVCpu->hwaccm.s.vmx.enmPrevGuestMode;
|
---|
1132 | }
|
---|
1133 | }
|
---|
1134 |
|
---|
1135 | /* Reset the contents of the read cache. */
|
---|
1136 | PVMCSCACHE pCache = &pVCpu->hwaccm.s.vmx.VMCSCache;
|
---|
1137 | for (unsigned j=0;j<pCache->Read.cValidEntries;j++)
|
---|
1138 | pCache->Read.aFieldVal[j] = 0;
|
---|
1139 | }
|
---|
1140 |
|
---|
1141 | /**
|
---|
1142 | * Terminates the HWACCM.
|
---|
1143 | *
|
---|
1144 | * Termination means cleaning up and freeing all resources,
|
---|
1145 | * the VM it self is at this point powered off or suspended.
|
---|
1146 | *
|
---|
1147 | * @returns VBox status code.
|
---|
1148 | * @param pVM The VM to operate on.
|
---|
1149 | */
|
---|
1150 | VMMR3DECL(int) HWACCMR3Term(PVM pVM)
|
---|
1151 | {
|
---|
1152 | if (pVM->hwaccm.s.vmx.pRealModeTSS)
|
---|
1153 | {
|
---|
1154 | PDMR3VMMDevHeapFree(pVM, pVM->hwaccm.s.vmx.pRealModeTSS);
|
---|
1155 | pVM->hwaccm.s.vmx.pRealModeTSS = 0;
|
---|
1156 | }
|
---|
1157 | HWACCMR3TermCPU(pVM);
|
---|
1158 | return 0;
|
---|
1159 | }
|
---|
1160 |
|
---|
1161 | /**
|
---|
1162 | * Terminates the per-VCPU HWACCM.
|
---|
1163 | *
|
---|
1164 | * Termination means cleaning up and freeing all resources,
|
---|
1165 | * the VM it self is at this point powered off or suspended.
|
---|
1166 | *
|
---|
1167 | * @returns VBox status code.
|
---|
1168 | * @param pVM The VM to operate on.
|
---|
1169 | */
|
---|
1170 | VMMR3DECL(int) HWACCMR3TermCPU(PVM pVM)
|
---|
1171 | {
|
---|
1172 | for (unsigned i=0;i<pVM->cCPUs;i++)
|
---|
1173 | {
|
---|
1174 | PVMCPU pVCpu = &pVM->aCpus[i];
|
---|
1175 |
|
---|
1176 | if (pVCpu->hwaccm.s.paStatExitReason)
|
---|
1177 | {
|
---|
1178 | MMHyperFree(pVM, pVCpu->hwaccm.s.paStatExitReason);
|
---|
1179 | pVCpu->hwaccm.s.paStatExitReason = NULL;
|
---|
1180 | pVCpu->hwaccm.s.paStatExitReasonR0 = NIL_RTR0PTR;
|
---|
1181 | }
|
---|
1182 | #ifdef VBOX_WITH_CRASHDUMP_MAGIC
|
---|
1183 | memset(pVCpu->hwaccm.s.vmx.VMCSCache.aMagic, 0, sizeof(pVCpu->hwaccm.s.vmx.VMCSCache.aMagic));
|
---|
1184 | pVCpu->hwaccm.s.vmx.VMCSCache.uMagic = 0;
|
---|
1185 | pVCpu->hwaccm.s.vmx.VMCSCache.uPos = 0xffffffff;
|
---|
1186 | #endif
|
---|
1187 | }
|
---|
1188 | return 0;
|
---|
1189 | }
|
---|
1190 |
|
---|
1191 | /**
|
---|
1192 | * The VM is being reset.
|
---|
1193 | *
|
---|
1194 | * For the HWACCM component this means that any GDT/LDT/TSS monitors
|
---|
1195 | * needs to be removed.
|
---|
1196 | *
|
---|
1197 | * @param pVM VM handle.
|
---|
1198 | */
|
---|
1199 | VMMR3DECL(void) HWACCMR3Reset(PVM pVM)
|
---|
1200 | {
|
---|
1201 | LogFlow(("HWACCMR3Reset:\n"));
|
---|
1202 |
|
---|
1203 | if (pVM->fHWACCMEnabled)
|
---|
1204 | hwaccmR3DisableRawMode(pVM);
|
---|
1205 |
|
---|
1206 | for (unsigned i=0;i<pVM->cCPUs;i++)
|
---|
1207 | {
|
---|
1208 | PVMCPU pVCpu = &pVM->aCpus[i];
|
---|
1209 |
|
---|
1210 | /* On first entry we'll sync everything. */
|
---|
1211 | pVCpu->hwaccm.s.fContextUseFlags = HWACCM_CHANGED_ALL;
|
---|
1212 |
|
---|
1213 | pVCpu->hwaccm.s.vmx.cr0_mask = 0;
|
---|
1214 | pVCpu->hwaccm.s.vmx.cr4_mask = 0;
|
---|
1215 |
|
---|
1216 | pVCpu->hwaccm.s.Event.fPending = false;
|
---|
1217 |
|
---|
1218 | /* Reset state information for real-mode emulation in VT-x. */
|
---|
1219 | pVCpu->hwaccm.s.vmx.enmLastSeenGuestMode = PGMMODE_REAL;
|
---|
1220 | pVCpu->hwaccm.s.vmx.enmPrevGuestMode = PGMMODE_REAL;
|
---|
1221 | pVCpu->hwaccm.s.vmx.enmCurrGuestMode = PGMMODE_REAL;
|
---|
1222 |
|
---|
1223 | /* Reset the contents of the read cache. */
|
---|
1224 | PVMCSCACHE pCache = &pVCpu->hwaccm.s.vmx.VMCSCache;
|
---|
1225 | for (unsigned j=0;j<pCache->Read.cValidEntries;j++)
|
---|
1226 | pCache->Read.aFieldVal[j] = 0;
|
---|
1227 |
|
---|
1228 | #ifdef VBOX_WITH_CRASHDUMP_MAGIC
|
---|
1229 | /* Magic marker for searching in crash dumps. */
|
---|
1230 | strcpy((char *)pCache->aMagic, "VMCSCACHE Magic");
|
---|
1231 | pCache->uMagic = UINT64_C(0xDEADBEEFDEADBEEF);
|
---|
1232 | #endif
|
---|
1233 | }
|
---|
1234 | }
|
---|
1235 |
|
---|
1236 | /**
|
---|
1237 | * Checks if we can currently use hardware accelerated raw mode.
|
---|
1238 | *
|
---|
1239 | * @returns boolean
|
---|
1240 | * @param pVM The VM to operate on.
|
---|
1241 | * @param pCtx Partial VM execution context
|
---|
1242 | */
|
---|
1243 | VMMR3DECL(bool) HWACCMR3CanExecuteGuest(PVM pVM, PCPUMCTX pCtx)
|
---|
1244 | {
|
---|
1245 | Assert(pVM->fHWACCMEnabled);
|
---|
1246 |
|
---|
1247 | /* AMD SVM supports real & protected mode with or without paging. */
|
---|
1248 | if (pVM->hwaccm.s.svm.fEnabled)
|
---|
1249 | {
|
---|
1250 | pVM->hwaccm.s.fActive = true;
|
---|
1251 | return true;
|
---|
1252 | }
|
---|
1253 |
|
---|
1254 | pVM->hwaccm.s.fActive = false;
|
---|
1255 |
|
---|
1256 | /* Note! The context supplied by REM is partial. If we add more checks here, be sure to verify that REM provides this info! */
|
---|
1257 | #ifdef HWACCM_VMX_EMULATE_REALMODE
|
---|
1258 | if (pVM->hwaccm.s.vmx.pRealModeTSS)
|
---|
1259 | {
|
---|
1260 | if (CPUMIsGuestInRealModeEx(pCtx))
|
---|
1261 | {
|
---|
1262 | /* VT-x will not allow high selector bases in v86 mode; fall back to the recompiler in that case.
|
---|
1263 | * The base must also be equal to (sel << 4).
|
---|
1264 | */
|
---|
1265 | if ( ( pCtx->cs != (pCtx->csHid.u64Base >> 4)
|
---|
1266 | && pCtx->csHid.u64Base != 0xffff0000 /* we can deal with the BIOS code as it's also mapped into the lower region. */)
|
---|
1267 | || pCtx->ds != (pCtx->dsHid.u64Base >> 4)
|
---|
1268 | || pCtx->es != (pCtx->esHid.u64Base >> 4)
|
---|
1269 | || pCtx->fs != (pCtx->fsHid.u64Base >> 4)
|
---|
1270 | || pCtx->gs != (pCtx->gsHid.u64Base >> 4)
|
---|
1271 | || pCtx->ss != (pCtx->ssHid.u64Base >> 4))
|
---|
1272 | {
|
---|
1273 | return false;
|
---|
1274 | }
|
---|
1275 | }
|
---|
1276 | else
|
---|
1277 | {
|
---|
1278 | PGMMODE enmGuestMode = PGMGetGuestMode(pVM);
|
---|
1279 | /* Verify the requirements for executing code in protected mode. VT-x can't handle the CPU state right after a switch
|
---|
1280 | * from real to protected mode. (all sorts of RPL & DPL assumptions)
|
---|
1281 | */
|
---|
1282 | PVMCPU pVCpu = VMMGetCpu(pVM);
|
---|
1283 |
|
---|
1284 | if ( pVCpu->hwaccm.s.vmx.enmLastSeenGuestMode == PGMMODE_REAL
|
---|
1285 | && enmGuestMode >= PGMMODE_PROTECTED)
|
---|
1286 | {
|
---|
1287 | if ( (pCtx->cs & X86_SEL_RPL)
|
---|
1288 | || (pCtx->ds & X86_SEL_RPL)
|
---|
1289 | || (pCtx->es & X86_SEL_RPL)
|
---|
1290 | || (pCtx->fs & X86_SEL_RPL)
|
---|
1291 | || (pCtx->gs & X86_SEL_RPL)
|
---|
1292 | || (pCtx->ss & X86_SEL_RPL))
|
---|
1293 | {
|
---|
1294 | return false;
|
---|
1295 | }
|
---|
1296 | }
|
---|
1297 | }
|
---|
1298 | }
|
---|
1299 | else
|
---|
1300 | #endif /* HWACCM_VMX_EMULATE_REALMODE */
|
---|
1301 | {
|
---|
1302 | if (!CPUMIsGuestInLongModeEx(pCtx))
|
---|
1303 | {
|
---|
1304 | /** @todo This should (probably) be set on every excursion to the REM,
|
---|
1305 | * however it's too risky right now. So, only apply it when we go
|
---|
1306 | * back to REM for real mode execution. (The XP hack below doesn't
|
---|
1307 | * work reliably without this.)
|
---|
1308 | * Update: Implemented in EM.cpp, see #ifdef EM_NOTIFY_HWACCM. */
|
---|
1309 | pVM->aCpus[0].hwaccm.s.fContextUseFlags |= HWACCM_CHANGED_ALL_GUEST;
|
---|
1310 |
|
---|
1311 | /* Too early for VT-x; Solaris guests will fail with a guru meditation otherwise; same for XP. */
|
---|
1312 | if (pCtx->idtr.pIdt == 0 || pCtx->idtr.cbIdt == 0 || pCtx->tr == 0)
|
---|
1313 | return false;
|
---|
1314 |
|
---|
1315 | /* The guest is about to complete the switch to protected mode. Wait a bit longer. */
|
---|
1316 | /* Windows XP; switch to protected mode; all selectors are marked not present in the
|
---|
1317 | * hidden registers (possible recompiler bug; see load_seg_vm) */
|
---|
1318 | if (pCtx->csHid.Attr.n.u1Present == 0)
|
---|
1319 | return false;
|
---|
1320 | if (pCtx->ssHid.Attr.n.u1Present == 0)
|
---|
1321 | return false;
|
---|
1322 |
|
---|
1323 | /* Windows XP: possible same as above, but new recompiler requires new heuristics?
|
---|
1324 | VT-x doesn't seem to like something about the guest state and this stuff avoids it. */
|
---|
1325 | /** @todo This check is actually wrong, it doesn't take the direction of the
|
---|
1326 | * stack segment into account. But, it does the job for now. */
|
---|
1327 | if (pCtx->rsp >= pCtx->ssHid.u32Limit)
|
---|
1328 | return false;
|
---|
1329 | #if 0
|
---|
1330 | if ( pCtx->cs >= pCtx->gdtr.cbGdt
|
---|
1331 | || pCtx->ss >= pCtx->gdtr.cbGdt
|
---|
1332 | || pCtx->ds >= pCtx->gdtr.cbGdt
|
---|
1333 | || pCtx->es >= pCtx->gdtr.cbGdt
|
---|
1334 | || pCtx->fs >= pCtx->gdtr.cbGdt
|
---|
1335 | || pCtx->gs >= pCtx->gdtr.cbGdt)
|
---|
1336 | return false;
|
---|
1337 | #endif
|
---|
1338 | }
|
---|
1339 | }
|
---|
1340 |
|
---|
1341 | if (pVM->hwaccm.s.vmx.fEnabled)
|
---|
1342 | {
|
---|
1343 | uint32_t mask;
|
---|
1344 |
|
---|
1345 | /* if bit N is set in cr0_fixed0, then it must be set in the guest's cr0. */
|
---|
1346 | mask = (uint32_t)pVM->hwaccm.s.vmx.msr.vmx_cr0_fixed0;
|
---|
1347 | /* Note: We ignore the NE bit here on purpose; see vmmr0\hwaccmr0.cpp for details. */
|
---|
1348 | mask &= ~X86_CR0_NE;
|
---|
1349 |
|
---|
1350 | #ifdef HWACCM_VMX_EMULATE_REALMODE
|
---|
1351 | if (pVM->hwaccm.s.vmx.pRealModeTSS)
|
---|
1352 | {
|
---|
1353 | /* Note: We ignore the PE & PG bits here on purpose; we emulate real and protected mode without paging. */
|
---|
1354 | mask &= ~(X86_CR0_PG|X86_CR0_PE);
|
---|
1355 | }
|
---|
1356 | else
|
---|
1357 | #endif
|
---|
1358 | {
|
---|
1359 | /* We support protected mode without paging using identity mapping. */
|
---|
1360 | mask &= ~X86_CR0_PG;
|
---|
1361 | }
|
---|
1362 | if ((pCtx->cr0 & mask) != mask)
|
---|
1363 | return false;
|
---|
1364 |
|
---|
1365 | /* if bit N is cleared in cr0_fixed1, then it must be zero in the guest's cr0. */
|
---|
1366 | mask = (uint32_t)~pVM->hwaccm.s.vmx.msr.vmx_cr0_fixed1;
|
---|
1367 | if ((pCtx->cr0 & mask) != 0)
|
---|
1368 | return false;
|
---|
1369 |
|
---|
1370 | /* if bit N is set in cr4_fixed0, then it must be set in the guest's cr4. */
|
---|
1371 | mask = (uint32_t)pVM->hwaccm.s.vmx.msr.vmx_cr4_fixed0;
|
---|
1372 | mask &= ~X86_CR4_VMXE;
|
---|
1373 | if ((pCtx->cr4 & mask) != mask)
|
---|
1374 | return false;
|
---|
1375 |
|
---|
1376 | /* if bit N is cleared in cr4_fixed1, then it must be zero in the guest's cr4. */
|
---|
1377 | mask = (uint32_t)~pVM->hwaccm.s.vmx.msr.vmx_cr4_fixed1;
|
---|
1378 | if ((pCtx->cr4 & mask) != 0)
|
---|
1379 | return false;
|
---|
1380 |
|
---|
1381 | pVM->hwaccm.s.fActive = true;
|
---|
1382 | return true;
|
---|
1383 | }
|
---|
1384 |
|
---|
1385 | return false;
|
---|
1386 | }
|
---|
1387 |
|
---|
1388 | /**
|
---|
1389 | * Notifcation from EM about a rescheduling into hardware assisted execution
|
---|
1390 | * mode.
|
---|
1391 | *
|
---|
1392 | * @param pVCpu Pointer to the current virtual cpu structure.
|
---|
1393 | */
|
---|
1394 | VMMR3DECL(void) HWACCMR3NotifyScheduled(PVMCPU pVCpu)
|
---|
1395 | {
|
---|
1396 | pVCpu->hwaccm.s.fContextUseFlags |= HWACCM_CHANGED_ALL_GUEST;
|
---|
1397 | }
|
---|
1398 |
|
---|
1399 | /**
|
---|
1400 | * Notifcation from EM about returning from instruction emulation (REM / EM).
|
---|
1401 | *
|
---|
1402 | * @param pVCpu Pointer to the current virtual cpu structure.
|
---|
1403 | */
|
---|
1404 | VMMR3DECL(void) HWACCMR3NotifyEmulated(PVMCPU pVCpu)
|
---|
1405 | {
|
---|
1406 | pVCpu->hwaccm.s.fContextUseFlags |= HWACCM_CHANGED_ALL_GUEST;
|
---|
1407 | }
|
---|
1408 |
|
---|
1409 | /**
|
---|
1410 | * Checks if we are currently using hardware accelerated raw mode.
|
---|
1411 | *
|
---|
1412 | * @returns boolean
|
---|
1413 | * @param pVM The VM to operate on.
|
---|
1414 | */
|
---|
1415 | VMMR3DECL(bool) HWACCMR3IsActive(PVM pVM)
|
---|
1416 | {
|
---|
1417 | return pVM->hwaccm.s.fActive;
|
---|
1418 | }
|
---|
1419 |
|
---|
1420 | /**
|
---|
1421 | * Checks if we are currently using nested paging.
|
---|
1422 | *
|
---|
1423 | * @returns boolean
|
---|
1424 | * @param pVM The VM to operate on.
|
---|
1425 | */
|
---|
1426 | VMMR3DECL(bool) HWACCMR3IsNestedPagingActive(PVM pVM)
|
---|
1427 | {
|
---|
1428 | return pVM->hwaccm.s.fNestedPaging;
|
---|
1429 | }
|
---|
1430 |
|
---|
1431 | /**
|
---|
1432 | * Checks if we are currently using VPID in VT-x mode.
|
---|
1433 | *
|
---|
1434 | * @returns boolean
|
---|
1435 | * @param pVM The VM to operate on.
|
---|
1436 | */
|
---|
1437 | VMMR3DECL(bool) HWACCMR3IsVPIDActive(PVM pVM)
|
---|
1438 | {
|
---|
1439 | return pVM->hwaccm.s.vmx.fVPID;
|
---|
1440 | }
|
---|
1441 |
|
---|
1442 |
|
---|
1443 | /**
|
---|
1444 | * Checks if internal events are pending. In that case we are not allowed to dispatch interrupts.
|
---|
1445 | *
|
---|
1446 | * @returns boolean
|
---|
1447 | * @param pVM The VM to operate on.
|
---|
1448 | */
|
---|
1449 | VMMR3DECL(bool) HWACCMR3IsEventPending(PVM pVM)
|
---|
1450 | {
|
---|
1451 | /* @todo SMP */
|
---|
1452 | return HWACCMIsEnabled(pVM) && pVM->aCpus[0].hwaccm.s.Event.fPending;
|
---|
1453 | }
|
---|
1454 |
|
---|
1455 |
|
---|
1456 | /**
|
---|
1457 | * Inject an NMI into a running VM
|
---|
1458 | *
|
---|
1459 | * @returns boolean
|
---|
1460 | * @param pVM The VM to operate on.
|
---|
1461 | */
|
---|
1462 | VMMR3DECL(int) HWACCMR3InjectNMI(PVM pVM)
|
---|
1463 | {
|
---|
1464 | pVM->hwaccm.s.fInjectNMI = true;
|
---|
1465 | return VINF_SUCCESS;
|
---|
1466 | }
|
---|
1467 |
|
---|
1468 | /**
|
---|
1469 | * Check fatal VT-x/AMD-V error and produce some meaningful
|
---|
1470 | * log release message.
|
---|
1471 | *
|
---|
1472 | * @param pVM The VM to operate on.
|
---|
1473 | * @param iStatusCode VBox status code
|
---|
1474 | */
|
---|
1475 | VMMR3DECL(void) HWACCMR3CheckError(PVM pVM, int iStatusCode)
|
---|
1476 | {
|
---|
1477 | for (unsigned i=0;i<pVM->cCPUs;i++)
|
---|
1478 | {
|
---|
1479 | switch(iStatusCode)
|
---|
1480 | {
|
---|
1481 | case VERR_VMX_INVALID_VMCS_FIELD:
|
---|
1482 | break;
|
---|
1483 |
|
---|
1484 | case VERR_VMX_INVALID_VMCS_PTR:
|
---|
1485 | 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));
|
---|
1486 | LogRel(("VERR_VMX_INVALID_VMCS_PTR: CPU%d Current VMCS version %x\n", i, pVM->aCpus[i].hwaccm.s.vmx.lasterror.ulVMCSRevision));
|
---|
1487 | LogRel(("VERR_VMX_INVALID_VMCS_PTR: CPU%d Entered Cpu %d\n", i, pVM->aCpus[i].hwaccm.s.vmx.lasterror.idEnteredCpu));
|
---|
1488 | LogRel(("VERR_VMX_INVALID_VMCS_PTR: CPU%d Current Cpu %d\n", i, pVM->aCpus[i].hwaccm.s.vmx.lasterror.idCurrentCpu));
|
---|
1489 | break;
|
---|
1490 |
|
---|
1491 | case VERR_VMX_UNABLE_TO_START_VM:
|
---|
1492 | LogRel(("VERR_VMX_UNABLE_TO_START_VM: CPU%d instruction error %x\n", i, pVM->aCpus[i].hwaccm.s.vmx.lasterror.ulInstrError));
|
---|
1493 | LogRel(("VERR_VMX_UNABLE_TO_START_VM: CPU%d exit reason %x\n", i, pVM->aCpus[i].hwaccm.s.vmx.lasterror.ulExitReason));
|
---|
1494 | #if 0 /* @todo dump the current control fields to the release log */
|
---|
1495 | if (pVM->aCpus[i].hwaccm.s.vmx.lasterror.ulInstrError == VMX_ERROR_VMENTRY_INVALID_CONTROL_FIELDS)
|
---|
1496 | {
|
---|
1497 |
|
---|
1498 | }
|
---|
1499 | #endif
|
---|
1500 | break;
|
---|
1501 |
|
---|
1502 | case VERR_VMX_UNABLE_TO_RESUME_VM:
|
---|
1503 | LogRel(("VERR_VMX_UNABLE_TO_RESUME_VM: CPU%d instruction error %x\n", i, pVM->aCpus[i].hwaccm.s.vmx.lasterror.ulInstrError));
|
---|
1504 | LogRel(("VERR_VMX_UNABLE_TO_RESUME_VM: CPU%d exit reason %x\n", i, pVM->aCpus[i].hwaccm.s.vmx.lasterror.ulExitReason));
|
---|
1505 | break;
|
---|
1506 |
|
---|
1507 | case VERR_VMX_INVALID_VMXON_PTR:
|
---|
1508 | break;
|
---|
1509 | }
|
---|
1510 | }
|
---|
1511 | }
|
---|
1512 |
|
---|
1513 | /**
|
---|
1514 | * Execute state save operation.
|
---|
1515 | *
|
---|
1516 | * @returns VBox status code.
|
---|
1517 | * @param pVM VM Handle.
|
---|
1518 | * @param pSSM SSM operation handle.
|
---|
1519 | */
|
---|
1520 | static DECLCALLBACK(int) hwaccmR3Save(PVM pVM, PSSMHANDLE pSSM)
|
---|
1521 | {
|
---|
1522 | int rc;
|
---|
1523 |
|
---|
1524 | Log(("hwaccmR3Save:\n"));
|
---|
1525 |
|
---|
1526 | for (unsigned i=0;i<pVM->cCPUs;i++)
|
---|
1527 | {
|
---|
1528 | /*
|
---|
1529 | * Save the basic bits - fortunately all the other things can be resynced on load.
|
---|
1530 | */
|
---|
1531 | rc = SSMR3PutU32(pSSM, pVM->aCpus[i].hwaccm.s.Event.fPending);
|
---|
1532 | AssertRCReturn(rc, rc);
|
---|
1533 | rc = SSMR3PutU32(pSSM, pVM->aCpus[i].hwaccm.s.Event.errCode);
|
---|
1534 | AssertRCReturn(rc, rc);
|
---|
1535 | rc = SSMR3PutU64(pSSM, pVM->aCpus[i].hwaccm.s.Event.intInfo);
|
---|
1536 | AssertRCReturn(rc, rc);
|
---|
1537 |
|
---|
1538 | rc = SSMR3PutU32(pSSM, pVM->aCpus[i].hwaccm.s.vmx.enmLastSeenGuestMode);
|
---|
1539 | AssertRCReturn(rc, rc);
|
---|
1540 | rc = SSMR3PutU32(pSSM, pVM->aCpus[i].hwaccm.s.vmx.enmCurrGuestMode);
|
---|
1541 | AssertRCReturn(rc, rc);
|
---|
1542 | rc = SSMR3PutU32(pSSM, pVM->aCpus[i].hwaccm.s.vmx.enmPrevGuestMode);
|
---|
1543 | AssertRCReturn(rc, rc);
|
---|
1544 | }
|
---|
1545 |
|
---|
1546 | return VINF_SUCCESS;
|
---|
1547 | }
|
---|
1548 |
|
---|
1549 | /**
|
---|
1550 | * Execute state load operation.
|
---|
1551 | *
|
---|
1552 | * @returns VBox status code.
|
---|
1553 | * @param pVM VM Handle.
|
---|
1554 | * @param pSSM SSM operation handle.
|
---|
1555 | * @param u32Version Data layout version.
|
---|
1556 | */
|
---|
1557 | static DECLCALLBACK(int) hwaccmR3Load(PVM pVM, PSSMHANDLE pSSM, uint32_t u32Version)
|
---|
1558 | {
|
---|
1559 | int rc;
|
---|
1560 |
|
---|
1561 | Log(("hwaccmR3Load:\n"));
|
---|
1562 |
|
---|
1563 | /*
|
---|
1564 | * Validate version.
|
---|
1565 | */
|
---|
1566 | if ( u32Version != HWACCM_SSM_VERSION
|
---|
1567 | && u32Version != HWACCM_SSM_VERSION_2_0_X)
|
---|
1568 | {
|
---|
1569 | AssertMsgFailed(("hwaccmR3Load: Invalid version u32Version=%d!\n", u32Version));
|
---|
1570 | return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
|
---|
1571 | }
|
---|
1572 | for (unsigned i=0;i<pVM->cCPUs;i++)
|
---|
1573 | {
|
---|
1574 | rc = SSMR3GetU32(pSSM, &pVM->aCpus[i].hwaccm.s.Event.fPending);
|
---|
1575 | AssertRCReturn(rc, rc);
|
---|
1576 | rc = SSMR3GetU32(pSSM, &pVM->aCpus[i].hwaccm.s.Event.errCode);
|
---|
1577 | AssertRCReturn(rc, rc);
|
---|
1578 | rc = SSMR3GetU64(pSSM, &pVM->aCpus[i].hwaccm.s.Event.intInfo);
|
---|
1579 | AssertRCReturn(rc, rc);
|
---|
1580 |
|
---|
1581 | if (u32Version >= HWACCM_SSM_VERSION)
|
---|
1582 | {
|
---|
1583 | uint32_t val;
|
---|
1584 |
|
---|
1585 | rc = SSMR3GetU32(pSSM, &val);
|
---|
1586 | AssertRCReturn(rc, rc);
|
---|
1587 | pVM->aCpus[i].hwaccm.s.vmx.enmLastSeenGuestMode = (PGMMODE)val;
|
---|
1588 |
|
---|
1589 | rc = SSMR3GetU32(pSSM, &val);
|
---|
1590 | AssertRCReturn(rc, rc);
|
---|
1591 | pVM->aCpus[i].hwaccm.s.vmx.enmCurrGuestMode = (PGMMODE)val;
|
---|
1592 |
|
---|
1593 | rc = SSMR3GetU32(pSSM, &val);
|
---|
1594 | AssertRCReturn(rc, rc);
|
---|
1595 | pVM->aCpus[i].hwaccm.s.vmx.enmPrevGuestMode = (PGMMODE)val;
|
---|
1596 | }
|
---|
1597 | }
|
---|
1598 | return VINF_SUCCESS;
|
---|
1599 | }
|
---|
1600 |
|
---|