VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMR3/CPUM.cpp@ 97150

Last change on this file since 97150 was 97150, checked in by vboxsync, 2 years ago

VMM/CPUM: Nested VMX: bugref:10092 We access the virtual-APIC page directly from guest's memory. Removed it from CPUMCTX.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 243.1 KB
Line 
1/* $Id: CPUM.cpp 97150 2022-10-14 07:12:10Z vboxsync $ */
2/** @file
3 * CPUM - CPU Monitor / Manager.
4 */
5
6/*
7 * Copyright (C) 2006-2022 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28/** @page pg_cpum CPUM - CPU Monitor / Manager
29 *
30 * The CPU Monitor / Manager keeps track of all the CPU registers. It is
31 * also responsible for lazy FPU handling and some of the context loading
32 * in raw mode.
33 *
34 * There are three CPU contexts, the most important one is the guest one (GC).
35 * When running in raw-mode (RC) there is a special hyper context for the VMM
36 * part that floats around inside the guest address space. When running in
37 * raw-mode, CPUM also maintains a host context for saving and restoring
38 * registers across world switches. This latter is done in cooperation with the
39 * world switcher (@see pg_vmm).
40 *
41 * @see grp_cpum
42 *
43 * @section sec_cpum_fpu FPU / SSE / AVX / ++ state.
44 *
45 * TODO: proper write up, currently just some notes.
46 *
47 * The ring-0 FPU handling per OS:
48 *
49 * - 64-bit Windows uses XMM registers in the kernel as part of the calling
50 * convention (Visual C++ doesn't seem to have a way to disable
51 * generating such code either), so CR0.TS/EM are always zero from what I
52 * can tell. We are also forced to always load/save the guest XMM0-XMM15
53 * registers when entering/leaving guest context. Interrupt handlers
54 * using FPU/SSE will offically have call save and restore functions
55 * exported by the kernel, if the really really have to use the state.
56 *
57 * - 32-bit windows does lazy FPU handling, I think, probably including
58 * lazying saving. The Windows Internals book states that it's a bad
59 * idea to use the FPU in kernel space. However, it looks like it will
60 * restore the FPU state of the current thread in case of a kernel \#NM.
61 * Interrupt handlers should be same as for 64-bit.
62 *
63 * - Darwin allows taking \#NM in kernel space, restoring current thread's
64 * state if I read the code correctly. It saves the FPU state of the
65 * outgoing thread, and uses CR0.TS to lazily load the state of the
66 * incoming one. No idea yet how the FPU is treated by interrupt
67 * handlers, i.e. whether they are allowed to disable the state or
68 * something.
69 *
70 * - Linux also allows \#NM in kernel space (don't know since when), and
71 * uses CR0.TS for lazy loading. Saves outgoing thread's state, lazy
72 * loads the incoming unless configured to agressivly load it. Interrupt
73 * handlers can ask whether they're allowed to use the FPU, and may
74 * freely trash the state if Linux thinks it has saved the thread's state
75 * already. This is a problem.
76 *
77 * - Solaris will, from what I can tell, panic if it gets an \#NM in kernel
78 * context. When switching threads, the kernel will save the state of
79 * the outgoing thread and lazy load the incoming one using CR0.TS.
80 * There are a few routines in seeblk.s which uses the SSE unit in ring-0
81 * to do stuff, HAT are among the users. The routines there will
82 * manually clear CR0.TS and save the XMM registers they use only if
83 * CR0.TS was zero upon entry. They will skip it when not, because as
84 * mentioned above, the FPU state is saved when switching away from a
85 * thread and CR0.TS set to 1, so when CR0.TS is 1 there is nothing to
86 * preserve. This is a problem if we restore CR0.TS to 1 after loading
87 * the guest state.
88 *
89 * - FreeBSD - no idea yet.
90 *
91 * - OS/2 does not allow \#NMs in kernel space IIRC. Does lazy loading,
92 * possibly also lazy saving. Interrupts must preserve the CR0.TS+EM &
93 * FPU states.
94 *
95 * Up to r107425 (2016-05-24) we would only temporarily modify CR0.TS/EM while
96 * saving and restoring the host and guest states. The motivation for this
97 * change is that we want to be able to emulate SSE instruction in ring-0 (IEM).
98 *
99 * Starting with that change, we will leave CR0.TS=EM=0 after saving the host
100 * state and only restore it once we've restore the host FPU state. This has the
101 * accidental side effect of triggering Solaris to preserve XMM registers in
102 * sseblk.s. When CR0 was changed by saving the FPU state, CPUM must now inform
103 * the VT-x (HMVMX) code about it as it caches the CR0 value in the VMCS.
104 *
105 *
106 * @section sec_cpum_logging Logging Level Assignments.
107 *
108 * Following log level assignments:
109 * - Log6 is used for FPU state management.
110 * - Log7 is used for FPU state actualization.
111 *
112 */
113
114
115/*********************************************************************************************************************************
116* Header Files *
117*********************************************************************************************************************************/
118#define LOG_GROUP LOG_GROUP_CPUM
119#define CPUM_WITH_NONCONST_HOST_FEATURES
120#include <VBox/vmm/cpum.h>
121#include <VBox/vmm/cpumdis.h>
122#include <VBox/vmm/cpumctx-v1_6.h>
123#include <VBox/vmm/pgm.h>
124#include <VBox/vmm/apic.h>
125#include <VBox/vmm/mm.h>
126#include <VBox/vmm/em.h>
127#include <VBox/vmm/iem.h>
128#include <VBox/vmm/selm.h>
129#include <VBox/vmm/dbgf.h>
130#include <VBox/vmm/hm.h>
131#include <VBox/vmm/hmvmxinline.h>
132#include <VBox/vmm/ssm.h>
133#include "CPUMInternal.h"
134#include <VBox/vmm/vm.h>
135
136#include <VBox/param.h>
137#include <VBox/dis.h>
138#include <VBox/err.h>
139#include <VBox/log.h>
140#if defined(RT_ARCH_X86) || defined(RT_ARCH_AMD64)
141# include <iprt/asm-amd64-x86.h>
142#endif
143#include <iprt/assert.h>
144#include <iprt/cpuset.h>
145#include <iprt/mem.h>
146#include <iprt/mp.h>
147#include <iprt/string.h>
148
149
150/*********************************************************************************************************************************
151* Defined Constants And Macros *
152*********************************************************************************************************************************/
153/**
154 * This was used in the saved state up to the early life of version 14.
155 *
156 * It indicates that we may have some out-of-sync hidden segement registers.
157 * It is only relevant for raw-mode.
158 */
159#define CPUM_CHANGED_HIDDEN_SEL_REGS_INVALID RT_BIT(12)
160
161
162/*********************************************************************************************************************************
163* Structures and Typedefs *
164*********************************************************************************************************************************/
165
166/**
167 * What kind of cpu info dump to perform.
168 */
169typedef enum CPUMDUMPTYPE
170{
171 CPUMDUMPTYPE_TERSE,
172 CPUMDUMPTYPE_DEFAULT,
173 CPUMDUMPTYPE_VERBOSE
174} CPUMDUMPTYPE;
175/** Pointer to a cpu info dump type. */
176typedef CPUMDUMPTYPE *PCPUMDUMPTYPE;
177
178
179/*********************************************************************************************************************************
180* Internal Functions *
181*********************************************************************************************************************************/
182static DECLCALLBACK(int) cpumR3LiveExec(PVM pVM, PSSMHANDLE pSSM, uint32_t uPass);
183static DECLCALLBACK(int) cpumR3SaveExec(PVM pVM, PSSMHANDLE pSSM);
184static DECLCALLBACK(int) cpumR3LoadPrep(PVM pVM, PSSMHANDLE pSSM);
185static DECLCALLBACK(int) cpumR3LoadExec(PVM pVM, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass);
186static DECLCALLBACK(int) cpumR3LoadDone(PVM pVM, PSSMHANDLE pSSM);
187static DECLCALLBACK(void) cpumR3InfoAll(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs);
188static DECLCALLBACK(void) cpumR3InfoGuest(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs);
189static DECLCALLBACK(void) cpumR3InfoGuestHwvirt(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs);
190static DECLCALLBACK(void) cpumR3InfoGuestInstr(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs);
191static DECLCALLBACK(void) cpumR3InfoHyper(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs);
192static DECLCALLBACK(void) cpumR3InfoHost(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs);
193
194
195/*********************************************************************************************************************************
196* Global Variables *
197*********************************************************************************************************************************/
198#if defined(RT_ARCH_X86) || defined(RT_ARCH_AMD64)
199/** Host CPU features. */
200DECL_HIDDEN_DATA(CPUHOSTFEATURES) g_CpumHostFeatures;
201#endif
202
203/** Saved state field descriptors for CPUMCTX. */
204static const SSMFIELD g_aCpumCtxFields[] =
205{
206 SSMFIELD_ENTRY( CPUMCTX, rdi),
207 SSMFIELD_ENTRY( CPUMCTX, rsi),
208 SSMFIELD_ENTRY( CPUMCTX, rbp),
209 SSMFIELD_ENTRY( CPUMCTX, rax),
210 SSMFIELD_ENTRY( CPUMCTX, rbx),
211 SSMFIELD_ENTRY( CPUMCTX, rdx),
212 SSMFIELD_ENTRY( CPUMCTX, rcx),
213 SSMFIELD_ENTRY( CPUMCTX, rsp),
214 SSMFIELD_ENTRY( CPUMCTX, rflags),
215 SSMFIELD_ENTRY( CPUMCTX, rip),
216 SSMFIELD_ENTRY( CPUMCTX, r8),
217 SSMFIELD_ENTRY( CPUMCTX, r9),
218 SSMFIELD_ENTRY( CPUMCTX, r10),
219 SSMFIELD_ENTRY( CPUMCTX, r11),
220 SSMFIELD_ENTRY( CPUMCTX, r12),
221 SSMFIELD_ENTRY( CPUMCTX, r13),
222 SSMFIELD_ENTRY( CPUMCTX, r14),
223 SSMFIELD_ENTRY( CPUMCTX, r15),
224 SSMFIELD_ENTRY( CPUMCTX, es.Sel),
225 SSMFIELD_ENTRY( CPUMCTX, es.ValidSel),
226 SSMFIELD_ENTRY( CPUMCTX, es.fFlags),
227 SSMFIELD_ENTRY( CPUMCTX, es.u64Base),
228 SSMFIELD_ENTRY( CPUMCTX, es.u32Limit),
229 SSMFIELD_ENTRY( CPUMCTX, es.Attr),
230 SSMFIELD_ENTRY( CPUMCTX, cs.Sel),
231 SSMFIELD_ENTRY( CPUMCTX, cs.ValidSel),
232 SSMFIELD_ENTRY( CPUMCTX, cs.fFlags),
233 SSMFIELD_ENTRY( CPUMCTX, cs.u64Base),
234 SSMFIELD_ENTRY( CPUMCTX, cs.u32Limit),
235 SSMFIELD_ENTRY( CPUMCTX, cs.Attr),
236 SSMFIELD_ENTRY( CPUMCTX, ss.Sel),
237 SSMFIELD_ENTRY( CPUMCTX, ss.ValidSel),
238 SSMFIELD_ENTRY( CPUMCTX, ss.fFlags),
239 SSMFIELD_ENTRY( CPUMCTX, ss.u64Base),
240 SSMFIELD_ENTRY( CPUMCTX, ss.u32Limit),
241 SSMFIELD_ENTRY( CPUMCTX, ss.Attr),
242 SSMFIELD_ENTRY( CPUMCTX, ds.Sel),
243 SSMFIELD_ENTRY( CPUMCTX, ds.ValidSel),
244 SSMFIELD_ENTRY( CPUMCTX, ds.fFlags),
245 SSMFIELD_ENTRY( CPUMCTX, ds.u64Base),
246 SSMFIELD_ENTRY( CPUMCTX, ds.u32Limit),
247 SSMFIELD_ENTRY( CPUMCTX, ds.Attr),
248 SSMFIELD_ENTRY( CPUMCTX, fs.Sel),
249 SSMFIELD_ENTRY( CPUMCTX, fs.ValidSel),
250 SSMFIELD_ENTRY( CPUMCTX, fs.fFlags),
251 SSMFIELD_ENTRY( CPUMCTX, fs.u64Base),
252 SSMFIELD_ENTRY( CPUMCTX, fs.u32Limit),
253 SSMFIELD_ENTRY( CPUMCTX, fs.Attr),
254 SSMFIELD_ENTRY( CPUMCTX, gs.Sel),
255 SSMFIELD_ENTRY( CPUMCTX, gs.ValidSel),
256 SSMFIELD_ENTRY( CPUMCTX, gs.fFlags),
257 SSMFIELD_ENTRY( CPUMCTX, gs.u64Base),
258 SSMFIELD_ENTRY( CPUMCTX, gs.u32Limit),
259 SSMFIELD_ENTRY( CPUMCTX, gs.Attr),
260 SSMFIELD_ENTRY( CPUMCTX, cr0),
261 SSMFIELD_ENTRY( CPUMCTX, cr2),
262 SSMFIELD_ENTRY( CPUMCTX, cr3),
263 SSMFIELD_ENTRY( CPUMCTX, cr4),
264 SSMFIELD_ENTRY( CPUMCTX, dr[0]),
265 SSMFIELD_ENTRY( CPUMCTX, dr[1]),
266 SSMFIELD_ENTRY( CPUMCTX, dr[2]),
267 SSMFIELD_ENTRY( CPUMCTX, dr[3]),
268 SSMFIELD_ENTRY( CPUMCTX, dr[6]),
269 SSMFIELD_ENTRY( CPUMCTX, dr[7]),
270 SSMFIELD_ENTRY( CPUMCTX, gdtr.cbGdt),
271 SSMFIELD_ENTRY( CPUMCTX, gdtr.pGdt),
272 SSMFIELD_ENTRY( CPUMCTX, idtr.cbIdt),
273 SSMFIELD_ENTRY( CPUMCTX, idtr.pIdt),
274 SSMFIELD_ENTRY( CPUMCTX, SysEnter.cs),
275 SSMFIELD_ENTRY( CPUMCTX, SysEnter.eip),
276 SSMFIELD_ENTRY( CPUMCTX, SysEnter.esp),
277 SSMFIELD_ENTRY( CPUMCTX, msrEFER),
278 SSMFIELD_ENTRY( CPUMCTX, msrSTAR),
279 SSMFIELD_ENTRY( CPUMCTX, msrPAT),
280 SSMFIELD_ENTRY( CPUMCTX, msrLSTAR),
281 SSMFIELD_ENTRY( CPUMCTX, msrCSTAR),
282 SSMFIELD_ENTRY( CPUMCTX, msrSFMASK),
283 SSMFIELD_ENTRY( CPUMCTX, msrKERNELGSBASE),
284 SSMFIELD_ENTRY( CPUMCTX, ldtr.Sel),
285 SSMFIELD_ENTRY( CPUMCTX, ldtr.ValidSel),
286 SSMFIELD_ENTRY( CPUMCTX, ldtr.fFlags),
287 SSMFIELD_ENTRY( CPUMCTX, ldtr.u64Base),
288 SSMFIELD_ENTRY( CPUMCTX, ldtr.u32Limit),
289 SSMFIELD_ENTRY( CPUMCTX, ldtr.Attr),
290 SSMFIELD_ENTRY( CPUMCTX, tr.Sel),
291 SSMFIELD_ENTRY( CPUMCTX, tr.ValidSel),
292 SSMFIELD_ENTRY( CPUMCTX, tr.fFlags),
293 SSMFIELD_ENTRY( CPUMCTX, tr.u64Base),
294 SSMFIELD_ENTRY( CPUMCTX, tr.u32Limit),
295 SSMFIELD_ENTRY( CPUMCTX, tr.Attr),
296 SSMFIELD_ENTRY_VER( CPUMCTX, aXcr[0], CPUM_SAVED_STATE_VERSION_XSAVE),
297 SSMFIELD_ENTRY_VER( CPUMCTX, aXcr[1], CPUM_SAVED_STATE_VERSION_XSAVE),
298 SSMFIELD_ENTRY_VER( CPUMCTX, fXStateMask, CPUM_SAVED_STATE_VERSION_XSAVE),
299 SSMFIELD_ENTRY_TERM()
300};
301
302/** Saved state field descriptors for SVM nested hardware-virtualization
303 * Host State. */
304static const SSMFIELD g_aSvmHwvirtHostState[] =
305{
306 SSMFIELD_ENTRY( SVMHOSTSTATE, uEferMsr),
307 SSMFIELD_ENTRY( SVMHOSTSTATE, uCr0),
308 SSMFIELD_ENTRY( SVMHOSTSTATE, uCr4),
309 SSMFIELD_ENTRY( SVMHOSTSTATE, uCr3),
310 SSMFIELD_ENTRY( SVMHOSTSTATE, uRip),
311 SSMFIELD_ENTRY( SVMHOSTSTATE, uRsp),
312 SSMFIELD_ENTRY( SVMHOSTSTATE, uRax),
313 SSMFIELD_ENTRY( SVMHOSTSTATE, rflags),
314 SSMFIELD_ENTRY( SVMHOSTSTATE, es.Sel),
315 SSMFIELD_ENTRY( SVMHOSTSTATE, es.ValidSel),
316 SSMFIELD_ENTRY( SVMHOSTSTATE, es.fFlags),
317 SSMFIELD_ENTRY( SVMHOSTSTATE, es.u64Base),
318 SSMFIELD_ENTRY( SVMHOSTSTATE, es.u32Limit),
319 SSMFIELD_ENTRY( SVMHOSTSTATE, es.Attr),
320 SSMFIELD_ENTRY( SVMHOSTSTATE, cs.Sel),
321 SSMFIELD_ENTRY( SVMHOSTSTATE, cs.ValidSel),
322 SSMFIELD_ENTRY( SVMHOSTSTATE, cs.fFlags),
323 SSMFIELD_ENTRY( SVMHOSTSTATE, cs.u64Base),
324 SSMFIELD_ENTRY( SVMHOSTSTATE, cs.u32Limit),
325 SSMFIELD_ENTRY( SVMHOSTSTATE, cs.Attr),
326 SSMFIELD_ENTRY( SVMHOSTSTATE, ss.Sel),
327 SSMFIELD_ENTRY( SVMHOSTSTATE, ss.ValidSel),
328 SSMFIELD_ENTRY( SVMHOSTSTATE, ss.fFlags),
329 SSMFIELD_ENTRY( SVMHOSTSTATE, ss.u64Base),
330 SSMFIELD_ENTRY( SVMHOSTSTATE, ss.u32Limit),
331 SSMFIELD_ENTRY( SVMHOSTSTATE, ss.Attr),
332 SSMFIELD_ENTRY( SVMHOSTSTATE, ds.Sel),
333 SSMFIELD_ENTRY( SVMHOSTSTATE, ds.ValidSel),
334 SSMFIELD_ENTRY( SVMHOSTSTATE, ds.fFlags),
335 SSMFIELD_ENTRY( SVMHOSTSTATE, ds.u64Base),
336 SSMFIELD_ENTRY( SVMHOSTSTATE, ds.u32Limit),
337 SSMFIELD_ENTRY( SVMHOSTSTATE, ds.Attr),
338 SSMFIELD_ENTRY( SVMHOSTSTATE, gdtr.cbGdt),
339 SSMFIELD_ENTRY( SVMHOSTSTATE, gdtr.pGdt),
340 SSMFIELD_ENTRY( SVMHOSTSTATE, idtr.cbIdt),
341 SSMFIELD_ENTRY( SVMHOSTSTATE, idtr.pIdt),
342 SSMFIELD_ENTRY_IGNORE(SVMHOSTSTATE, abPadding),
343 SSMFIELD_ENTRY_TERM()
344};
345
346/** Saved state field descriptors for VMX nested hardware-virtualization
347 * VMCS. */
348static const SSMFIELD g_aVmxHwvirtVmcs[] =
349{
350 SSMFIELD_ENTRY( VMXVVMCS, u32VmcsRevId),
351 SSMFIELD_ENTRY( VMXVVMCS, enmVmxAbort),
352 SSMFIELD_ENTRY( VMXVVMCS, fVmcsState),
353 SSMFIELD_ENTRY_IGNORE(VMXVVMCS, au8Padding0),
354 SSMFIELD_ENTRY_IGNORE(VMXVVMCS, au32Reserved0),
355
356 SSMFIELD_ENTRY_IGNORE(VMXVVMCS, u16Reserved0),
357
358 SSMFIELD_ENTRY( VMXVVMCS, u32RoVmInstrError),
359 SSMFIELD_ENTRY( VMXVVMCS, u32RoExitReason),
360 SSMFIELD_ENTRY( VMXVVMCS, u32RoExitIntInfo),
361 SSMFIELD_ENTRY( VMXVVMCS, u32RoExitIntErrCode),
362 SSMFIELD_ENTRY( VMXVVMCS, u32RoIdtVectoringInfo),
363 SSMFIELD_ENTRY( VMXVVMCS, u32RoIdtVectoringErrCode),
364 SSMFIELD_ENTRY( VMXVVMCS, u32RoExitInstrLen),
365 SSMFIELD_ENTRY( VMXVVMCS, u32RoExitInstrInfo),
366 SSMFIELD_ENTRY_IGNORE(VMXVVMCS, au32RoReserved2),
367
368 SSMFIELD_ENTRY( VMXVVMCS, u64RoGuestPhysAddr),
369 SSMFIELD_ENTRY_IGNORE(VMXVVMCS, au64Reserved1),
370
371 SSMFIELD_ENTRY( VMXVVMCS, u64RoExitQual),
372 SSMFIELD_ENTRY( VMXVVMCS, u64RoIoRcx),
373 SSMFIELD_ENTRY( VMXVVMCS, u64RoIoRsi),
374 SSMFIELD_ENTRY( VMXVVMCS, u64RoIoRdi),
375 SSMFIELD_ENTRY( VMXVVMCS, u64RoIoRip),
376 SSMFIELD_ENTRY( VMXVVMCS, u64RoGuestLinearAddr),
377 SSMFIELD_ENTRY_IGNORE(VMXVVMCS, au64Reserved5),
378
379 SSMFIELD_ENTRY( VMXVVMCS, u16Vpid),
380 SSMFIELD_ENTRY( VMXVVMCS, u16PostIntNotifyVector),
381 SSMFIELD_ENTRY( VMXVVMCS, u16EptpIndex),
382 SSMFIELD_ENTRY_IGNORE(VMXVVMCS, au16Reserved0),
383
384 SSMFIELD_ENTRY( VMXVVMCS, u32PinCtls),
385 SSMFIELD_ENTRY( VMXVVMCS, u32ProcCtls),
386 SSMFIELD_ENTRY( VMXVVMCS, u32XcptBitmap),
387 SSMFIELD_ENTRY( VMXVVMCS, u32XcptPFMask),
388 SSMFIELD_ENTRY( VMXVVMCS, u32XcptPFMatch),
389 SSMFIELD_ENTRY( VMXVVMCS, u32Cr3TargetCount),
390 SSMFIELD_ENTRY( VMXVVMCS, u32ExitCtls),
391 SSMFIELD_ENTRY( VMXVVMCS, u32ExitMsrStoreCount),
392 SSMFIELD_ENTRY( VMXVVMCS, u32ExitMsrLoadCount),
393 SSMFIELD_ENTRY( VMXVVMCS, u32EntryCtls),
394 SSMFIELD_ENTRY( VMXVVMCS, u32EntryMsrLoadCount),
395 SSMFIELD_ENTRY( VMXVVMCS, u32EntryIntInfo),
396 SSMFIELD_ENTRY( VMXVVMCS, u32EntryXcptErrCode),
397 SSMFIELD_ENTRY( VMXVVMCS, u32EntryInstrLen),
398 SSMFIELD_ENTRY( VMXVVMCS, u32TprThreshold),
399 SSMFIELD_ENTRY( VMXVVMCS, u32ProcCtls2),
400 SSMFIELD_ENTRY( VMXVVMCS, u32PleGap),
401 SSMFIELD_ENTRY( VMXVVMCS, u32PleWindow),
402 SSMFIELD_ENTRY_IGNORE(VMXVVMCS, au32Reserved1),
403
404 SSMFIELD_ENTRY( VMXVVMCS, u64AddrIoBitmapA),
405 SSMFIELD_ENTRY( VMXVVMCS, u64AddrIoBitmapB),
406 SSMFIELD_ENTRY( VMXVVMCS, u64AddrMsrBitmap),
407 SSMFIELD_ENTRY( VMXVVMCS, u64AddrExitMsrStore),
408 SSMFIELD_ENTRY( VMXVVMCS, u64AddrExitMsrLoad),
409 SSMFIELD_ENTRY( VMXVVMCS, u64AddrEntryMsrLoad),
410 SSMFIELD_ENTRY( VMXVVMCS, u64ExecVmcsPtr),
411 SSMFIELD_ENTRY( VMXVVMCS, u64AddrPml),
412 SSMFIELD_ENTRY( VMXVVMCS, u64TscOffset),
413 SSMFIELD_ENTRY( VMXVVMCS, u64AddrVirtApic),
414 SSMFIELD_ENTRY( VMXVVMCS, u64AddrApicAccess),
415 SSMFIELD_ENTRY( VMXVVMCS, u64AddrPostedIntDesc),
416 SSMFIELD_ENTRY( VMXVVMCS, u64VmFuncCtls),
417 SSMFIELD_ENTRY( VMXVVMCS, u64EptPtr),
418 SSMFIELD_ENTRY( VMXVVMCS, u64EoiExitBitmap0),
419 SSMFIELD_ENTRY( VMXVVMCS, u64EoiExitBitmap1),
420 SSMFIELD_ENTRY( VMXVVMCS, u64EoiExitBitmap2),
421 SSMFIELD_ENTRY( VMXVVMCS, u64EoiExitBitmap3),
422 SSMFIELD_ENTRY( VMXVVMCS, u64AddrEptpList),
423 SSMFIELD_ENTRY( VMXVVMCS, u64AddrVmreadBitmap),
424 SSMFIELD_ENTRY( VMXVVMCS, u64AddrVmwriteBitmap),
425 SSMFIELD_ENTRY( VMXVVMCS, u64AddrXcptVeInfo),
426 SSMFIELD_ENTRY( VMXVVMCS, u64XssExitBitmap),
427 SSMFIELD_ENTRY( VMXVVMCS, u64EnclsExitBitmap),
428 SSMFIELD_ENTRY( VMXVVMCS, u64SppTablePtr),
429 SSMFIELD_ENTRY( VMXVVMCS, u64TscMultiplier),
430 SSMFIELD_ENTRY_VER( VMXVVMCS, u64ProcCtls3, CPUM_SAVED_STATE_VERSION_HWVIRT_VMX_2),
431 SSMFIELD_ENTRY_VER( VMXVVMCS, u64EnclvExitBitmap, CPUM_SAVED_STATE_VERSION_HWVIRT_VMX_2),
432 SSMFIELD_ENTRY_IGNORE(VMXVVMCS, au64Reserved0),
433
434 SSMFIELD_ENTRY( VMXVVMCS, u64Cr0Mask),
435 SSMFIELD_ENTRY( VMXVVMCS, u64Cr4Mask),
436 SSMFIELD_ENTRY( VMXVVMCS, u64Cr0ReadShadow),
437 SSMFIELD_ENTRY( VMXVVMCS, u64Cr4ReadShadow),
438 SSMFIELD_ENTRY( VMXVVMCS, u64Cr3Target0),
439 SSMFIELD_ENTRY( VMXVVMCS, u64Cr3Target1),
440 SSMFIELD_ENTRY( VMXVVMCS, u64Cr3Target2),
441 SSMFIELD_ENTRY( VMXVVMCS, u64Cr3Target3),
442 SSMFIELD_ENTRY_IGNORE(VMXVVMCS, au64Reserved4),
443
444 SSMFIELD_ENTRY( VMXVVMCS, HostEs),
445 SSMFIELD_ENTRY( VMXVVMCS, HostCs),
446 SSMFIELD_ENTRY( VMXVVMCS, HostSs),
447 SSMFIELD_ENTRY( VMXVVMCS, HostDs),
448 SSMFIELD_ENTRY( VMXVVMCS, HostFs),
449 SSMFIELD_ENTRY( VMXVVMCS, HostGs),
450 SSMFIELD_ENTRY( VMXVVMCS, HostTr),
451 SSMFIELD_ENTRY_IGNORE(VMXVVMCS, au16Reserved2),
452
453 SSMFIELD_ENTRY( VMXVVMCS, u32HostSysenterCs),
454 SSMFIELD_ENTRY_IGNORE(VMXVVMCS, au32Reserved4),
455
456 SSMFIELD_ENTRY( VMXVVMCS, u64HostPatMsr),
457 SSMFIELD_ENTRY( VMXVVMCS, u64HostEferMsr),
458 SSMFIELD_ENTRY( VMXVVMCS, u64HostPerfGlobalCtlMsr),
459 SSMFIELD_ENTRY_VER( VMXVVMCS, u64HostPkrsMsr, CPUM_SAVED_STATE_VERSION_HWVIRT_VMX_2),
460 SSMFIELD_ENTRY_IGNORE(VMXVVMCS, au64Reserved3),
461
462 SSMFIELD_ENTRY( VMXVVMCS, u64HostCr0),
463 SSMFIELD_ENTRY( VMXVVMCS, u64HostCr3),
464 SSMFIELD_ENTRY( VMXVVMCS, u64HostCr4),
465 SSMFIELD_ENTRY( VMXVVMCS, u64HostFsBase),
466 SSMFIELD_ENTRY( VMXVVMCS, u64HostGsBase),
467 SSMFIELD_ENTRY( VMXVVMCS, u64HostTrBase),
468 SSMFIELD_ENTRY( VMXVVMCS, u64HostGdtrBase),
469 SSMFIELD_ENTRY( VMXVVMCS, u64HostIdtrBase),
470 SSMFIELD_ENTRY( VMXVVMCS, u64HostSysenterEsp),
471 SSMFIELD_ENTRY( VMXVVMCS, u64HostSysenterEip),
472 SSMFIELD_ENTRY( VMXVVMCS, u64HostRsp),
473 SSMFIELD_ENTRY( VMXVVMCS, u64HostRip),
474 SSMFIELD_ENTRY_VER( VMXVVMCS, u64HostSCetMsr, CPUM_SAVED_STATE_VERSION_HWVIRT_VMX_2),
475 SSMFIELD_ENTRY_VER( VMXVVMCS, u64HostSsp, CPUM_SAVED_STATE_VERSION_HWVIRT_VMX_2),
476 SSMFIELD_ENTRY_VER( VMXVVMCS, u64HostIntrSspTableAddrMsr, CPUM_SAVED_STATE_VERSION_HWVIRT_VMX_2),
477 SSMFIELD_ENTRY_IGNORE(VMXVVMCS, au64Reserved7),
478
479 SSMFIELD_ENTRY( VMXVVMCS, GuestEs),
480 SSMFIELD_ENTRY( VMXVVMCS, GuestCs),
481 SSMFIELD_ENTRY( VMXVVMCS, GuestSs),
482 SSMFIELD_ENTRY( VMXVVMCS, GuestDs),
483 SSMFIELD_ENTRY( VMXVVMCS, GuestFs),
484 SSMFIELD_ENTRY( VMXVVMCS, GuestGs),
485 SSMFIELD_ENTRY( VMXVVMCS, GuestLdtr),
486 SSMFIELD_ENTRY( VMXVVMCS, GuestTr),
487 SSMFIELD_ENTRY( VMXVVMCS, u16GuestIntStatus),
488 SSMFIELD_ENTRY( VMXVVMCS, u16PmlIndex),
489 SSMFIELD_ENTRY_IGNORE(VMXVVMCS, au16Reserved1),
490
491 SSMFIELD_ENTRY( VMXVVMCS, u32GuestEsLimit),
492 SSMFIELD_ENTRY( VMXVVMCS, u32GuestCsLimit),
493 SSMFIELD_ENTRY( VMXVVMCS, u32GuestSsLimit),
494 SSMFIELD_ENTRY( VMXVVMCS, u32GuestDsLimit),
495 SSMFIELD_ENTRY( VMXVVMCS, u32GuestFsLimit),
496 SSMFIELD_ENTRY( VMXVVMCS, u32GuestGsLimit),
497 SSMFIELD_ENTRY( VMXVVMCS, u32GuestLdtrLimit),
498 SSMFIELD_ENTRY( VMXVVMCS, u32GuestTrLimit),
499 SSMFIELD_ENTRY( VMXVVMCS, u32GuestGdtrLimit),
500 SSMFIELD_ENTRY( VMXVVMCS, u32GuestIdtrLimit),
501 SSMFIELD_ENTRY( VMXVVMCS, u32GuestEsAttr),
502 SSMFIELD_ENTRY( VMXVVMCS, u32GuestCsAttr),
503 SSMFIELD_ENTRY( VMXVVMCS, u32GuestSsAttr),
504 SSMFIELD_ENTRY( VMXVVMCS, u32GuestDsAttr),
505 SSMFIELD_ENTRY( VMXVVMCS, u32GuestFsAttr),
506 SSMFIELD_ENTRY( VMXVVMCS, u32GuestGsAttr),
507 SSMFIELD_ENTRY( VMXVVMCS, u32GuestLdtrAttr),
508 SSMFIELD_ENTRY( VMXVVMCS, u32GuestTrAttr),
509 SSMFIELD_ENTRY( VMXVVMCS, u32GuestIntrState),
510 SSMFIELD_ENTRY( VMXVVMCS, u32GuestActivityState),
511 SSMFIELD_ENTRY( VMXVVMCS, u32GuestSmBase),
512 SSMFIELD_ENTRY( VMXVVMCS, u32GuestSysenterCS),
513 SSMFIELD_ENTRY( VMXVVMCS, u32PreemptTimer),
514 SSMFIELD_ENTRY_IGNORE(VMXVVMCS, au32Reserved3),
515
516 SSMFIELD_ENTRY( VMXVVMCS, u64VmcsLinkPtr),
517 SSMFIELD_ENTRY( VMXVVMCS, u64GuestDebugCtlMsr),
518 SSMFIELD_ENTRY( VMXVVMCS, u64GuestPatMsr),
519 SSMFIELD_ENTRY( VMXVVMCS, u64GuestEferMsr),
520 SSMFIELD_ENTRY( VMXVVMCS, u64GuestPerfGlobalCtlMsr),
521 SSMFIELD_ENTRY( VMXVVMCS, u64GuestPdpte0),
522 SSMFIELD_ENTRY( VMXVVMCS, u64GuestPdpte1),
523 SSMFIELD_ENTRY( VMXVVMCS, u64GuestPdpte2),
524 SSMFIELD_ENTRY( VMXVVMCS, u64GuestPdpte3),
525 SSMFIELD_ENTRY( VMXVVMCS, u64GuestBndcfgsMsr),
526 SSMFIELD_ENTRY( VMXVVMCS, u64GuestRtitCtlMsr),
527 SSMFIELD_ENTRY_VER( VMXVVMCS, u64GuestPkrsMsr, CPUM_SAVED_STATE_VERSION_HWVIRT_VMX_2),
528 SSMFIELD_ENTRY_IGNORE(VMXVVMCS, au64Reserved2),
529
530 SSMFIELD_ENTRY( VMXVVMCS, u64GuestCr0),
531 SSMFIELD_ENTRY( VMXVVMCS, u64GuestCr3),
532 SSMFIELD_ENTRY( VMXVVMCS, u64GuestCr4),
533 SSMFIELD_ENTRY( VMXVVMCS, u64GuestEsBase),
534 SSMFIELD_ENTRY( VMXVVMCS, u64GuestCsBase),
535 SSMFIELD_ENTRY( VMXVVMCS, u64GuestSsBase),
536 SSMFIELD_ENTRY( VMXVVMCS, u64GuestDsBase),
537 SSMFIELD_ENTRY( VMXVVMCS, u64GuestFsBase),
538 SSMFIELD_ENTRY( VMXVVMCS, u64GuestGsBase),
539 SSMFIELD_ENTRY( VMXVVMCS, u64GuestLdtrBase),
540 SSMFIELD_ENTRY( VMXVVMCS, u64GuestTrBase),
541 SSMFIELD_ENTRY( VMXVVMCS, u64GuestGdtrBase),
542 SSMFIELD_ENTRY( VMXVVMCS, u64GuestIdtrBase),
543 SSMFIELD_ENTRY( VMXVVMCS, u64GuestDr7),
544 SSMFIELD_ENTRY( VMXVVMCS, u64GuestRsp),
545 SSMFIELD_ENTRY( VMXVVMCS, u64GuestRip),
546 SSMFIELD_ENTRY( VMXVVMCS, u64GuestRFlags),
547 SSMFIELD_ENTRY( VMXVVMCS, u64GuestPendingDbgXcpts),
548 SSMFIELD_ENTRY( VMXVVMCS, u64GuestSysenterEsp),
549 SSMFIELD_ENTRY( VMXVVMCS, u64GuestSysenterEip),
550 SSMFIELD_ENTRY_VER( VMXVVMCS, u64GuestSCetMsr, CPUM_SAVED_STATE_VERSION_HWVIRT_VMX_2),
551 SSMFIELD_ENTRY_VER( VMXVVMCS, u64GuestSsp, CPUM_SAVED_STATE_VERSION_HWVIRT_VMX_2),
552 SSMFIELD_ENTRY_VER( VMXVVMCS, u64GuestIntrSspTableAddrMsr, CPUM_SAVED_STATE_VERSION_HWVIRT_VMX_2),
553 SSMFIELD_ENTRY_IGNORE(VMXVVMCS, au64Reserved6),
554
555 SSMFIELD_ENTRY_TERM()
556};
557
558/** Saved state field descriptors for CPUMCTX. */
559static const SSMFIELD g_aCpumX87Fields[] =
560{
561 SSMFIELD_ENTRY( X86FXSTATE, FCW),
562 SSMFIELD_ENTRY( X86FXSTATE, FSW),
563 SSMFIELD_ENTRY( X86FXSTATE, FTW),
564 SSMFIELD_ENTRY( X86FXSTATE, FOP),
565 SSMFIELD_ENTRY( X86FXSTATE, FPUIP),
566 SSMFIELD_ENTRY( X86FXSTATE, CS),
567 SSMFIELD_ENTRY( X86FXSTATE, Rsrvd1),
568 SSMFIELD_ENTRY( X86FXSTATE, FPUDP),
569 SSMFIELD_ENTRY( X86FXSTATE, DS),
570 SSMFIELD_ENTRY( X86FXSTATE, Rsrvd2),
571 SSMFIELD_ENTRY( X86FXSTATE, MXCSR),
572 SSMFIELD_ENTRY( X86FXSTATE, MXCSR_MASK),
573 SSMFIELD_ENTRY( X86FXSTATE, aRegs[0]),
574 SSMFIELD_ENTRY( X86FXSTATE, aRegs[1]),
575 SSMFIELD_ENTRY( X86FXSTATE, aRegs[2]),
576 SSMFIELD_ENTRY( X86FXSTATE, aRegs[3]),
577 SSMFIELD_ENTRY( X86FXSTATE, aRegs[4]),
578 SSMFIELD_ENTRY( X86FXSTATE, aRegs[5]),
579 SSMFIELD_ENTRY( X86FXSTATE, aRegs[6]),
580 SSMFIELD_ENTRY( X86FXSTATE, aRegs[7]),
581 SSMFIELD_ENTRY( X86FXSTATE, aXMM[0]),
582 SSMFIELD_ENTRY( X86FXSTATE, aXMM[1]),
583 SSMFIELD_ENTRY( X86FXSTATE, aXMM[2]),
584 SSMFIELD_ENTRY( X86FXSTATE, aXMM[3]),
585 SSMFIELD_ENTRY( X86FXSTATE, aXMM[4]),
586 SSMFIELD_ENTRY( X86FXSTATE, aXMM[5]),
587 SSMFIELD_ENTRY( X86FXSTATE, aXMM[6]),
588 SSMFIELD_ENTRY( X86FXSTATE, aXMM[7]),
589 SSMFIELD_ENTRY( X86FXSTATE, aXMM[8]),
590 SSMFIELD_ENTRY( X86FXSTATE, aXMM[9]),
591 SSMFIELD_ENTRY( X86FXSTATE, aXMM[10]),
592 SSMFIELD_ENTRY( X86FXSTATE, aXMM[11]),
593 SSMFIELD_ENTRY( X86FXSTATE, aXMM[12]),
594 SSMFIELD_ENTRY( X86FXSTATE, aXMM[13]),
595 SSMFIELD_ENTRY( X86FXSTATE, aXMM[14]),
596 SSMFIELD_ENTRY( X86FXSTATE, aXMM[15]),
597 SSMFIELD_ENTRY_VER( X86FXSTATE, au32RsrvdForSoftware[0], CPUM_SAVED_STATE_VERSION_XSAVE), /* 32-bit/64-bit hack */
598 SSMFIELD_ENTRY_TERM()
599};
600
601/** Saved state field descriptors for X86XSAVEHDR. */
602static const SSMFIELD g_aCpumXSaveHdrFields[] =
603{
604 SSMFIELD_ENTRY( X86XSAVEHDR, bmXState),
605 SSMFIELD_ENTRY_TERM()
606};
607
608/** Saved state field descriptors for X86XSAVEYMMHI. */
609static const SSMFIELD g_aCpumYmmHiFields[] =
610{
611 SSMFIELD_ENTRY( X86XSAVEYMMHI, aYmmHi[0]),
612 SSMFIELD_ENTRY( X86XSAVEYMMHI, aYmmHi[1]),
613 SSMFIELD_ENTRY( X86XSAVEYMMHI, aYmmHi[2]),
614 SSMFIELD_ENTRY( X86XSAVEYMMHI, aYmmHi[3]),
615 SSMFIELD_ENTRY( X86XSAVEYMMHI, aYmmHi[4]),
616 SSMFIELD_ENTRY( X86XSAVEYMMHI, aYmmHi[5]),
617 SSMFIELD_ENTRY( X86XSAVEYMMHI, aYmmHi[6]),
618 SSMFIELD_ENTRY( X86XSAVEYMMHI, aYmmHi[7]),
619 SSMFIELD_ENTRY( X86XSAVEYMMHI, aYmmHi[8]),
620 SSMFIELD_ENTRY( X86XSAVEYMMHI, aYmmHi[9]),
621 SSMFIELD_ENTRY( X86XSAVEYMMHI, aYmmHi[10]),
622 SSMFIELD_ENTRY( X86XSAVEYMMHI, aYmmHi[11]),
623 SSMFIELD_ENTRY( X86XSAVEYMMHI, aYmmHi[12]),
624 SSMFIELD_ENTRY( X86XSAVEYMMHI, aYmmHi[13]),
625 SSMFIELD_ENTRY( X86XSAVEYMMHI, aYmmHi[14]),
626 SSMFIELD_ENTRY( X86XSAVEYMMHI, aYmmHi[15]),
627 SSMFIELD_ENTRY_TERM()
628};
629
630/** Saved state field descriptors for X86XSAVEBNDREGS. */
631static const SSMFIELD g_aCpumBndRegsFields[] =
632{
633 SSMFIELD_ENTRY( X86XSAVEBNDREGS, aRegs[0]),
634 SSMFIELD_ENTRY( X86XSAVEBNDREGS, aRegs[1]),
635 SSMFIELD_ENTRY( X86XSAVEBNDREGS, aRegs[2]),
636 SSMFIELD_ENTRY( X86XSAVEBNDREGS, aRegs[3]),
637 SSMFIELD_ENTRY_TERM()
638};
639
640/** Saved state field descriptors for X86XSAVEBNDCFG. */
641static const SSMFIELD g_aCpumBndCfgFields[] =
642{
643 SSMFIELD_ENTRY( X86XSAVEBNDCFG, fConfig),
644 SSMFIELD_ENTRY( X86XSAVEBNDCFG, fStatus),
645 SSMFIELD_ENTRY_TERM()
646};
647
648#if 0 /** @todo */
649/** Saved state field descriptors for X86XSAVEOPMASK. */
650static const SSMFIELD g_aCpumOpmaskFields[] =
651{
652 SSMFIELD_ENTRY( X86XSAVEOPMASK, aKRegs[0]),
653 SSMFIELD_ENTRY( X86XSAVEOPMASK, aKRegs[1]),
654 SSMFIELD_ENTRY( X86XSAVEOPMASK, aKRegs[2]),
655 SSMFIELD_ENTRY( X86XSAVEOPMASK, aKRegs[3]),
656 SSMFIELD_ENTRY( X86XSAVEOPMASK, aKRegs[4]),
657 SSMFIELD_ENTRY( X86XSAVEOPMASK, aKRegs[5]),
658 SSMFIELD_ENTRY( X86XSAVEOPMASK, aKRegs[6]),
659 SSMFIELD_ENTRY( X86XSAVEOPMASK, aKRegs[7]),
660 SSMFIELD_ENTRY_TERM()
661};
662#endif
663
664/** Saved state field descriptors for X86XSAVEZMMHI256. */
665static const SSMFIELD g_aCpumZmmHi256Fields[] =
666{
667 SSMFIELD_ENTRY( X86XSAVEZMMHI256, aHi256Regs[0]),
668 SSMFIELD_ENTRY( X86XSAVEZMMHI256, aHi256Regs[1]),
669 SSMFIELD_ENTRY( X86XSAVEZMMHI256, aHi256Regs[2]),
670 SSMFIELD_ENTRY( X86XSAVEZMMHI256, aHi256Regs[3]),
671 SSMFIELD_ENTRY( X86XSAVEZMMHI256, aHi256Regs[4]),
672 SSMFIELD_ENTRY( X86XSAVEZMMHI256, aHi256Regs[5]),
673 SSMFIELD_ENTRY( X86XSAVEZMMHI256, aHi256Regs[6]),
674 SSMFIELD_ENTRY( X86XSAVEZMMHI256, aHi256Regs[7]),
675 SSMFIELD_ENTRY( X86XSAVEZMMHI256, aHi256Regs[8]),
676 SSMFIELD_ENTRY( X86XSAVEZMMHI256, aHi256Regs[9]),
677 SSMFIELD_ENTRY( X86XSAVEZMMHI256, aHi256Regs[10]),
678 SSMFIELD_ENTRY( X86XSAVEZMMHI256, aHi256Regs[11]),
679 SSMFIELD_ENTRY( X86XSAVEZMMHI256, aHi256Regs[12]),
680 SSMFIELD_ENTRY( X86XSAVEZMMHI256, aHi256Regs[13]),
681 SSMFIELD_ENTRY( X86XSAVEZMMHI256, aHi256Regs[14]),
682 SSMFIELD_ENTRY( X86XSAVEZMMHI256, aHi256Regs[15]),
683 SSMFIELD_ENTRY_TERM()
684};
685
686/** Saved state field descriptors for X86XSAVEZMM16HI. */
687static const SSMFIELD g_aCpumZmm16HiFields[] =
688{
689 SSMFIELD_ENTRY( X86XSAVEZMM16HI, aRegs[0]),
690 SSMFIELD_ENTRY( X86XSAVEZMM16HI, aRegs[1]),
691 SSMFIELD_ENTRY( X86XSAVEZMM16HI, aRegs[2]),
692 SSMFIELD_ENTRY( X86XSAVEZMM16HI, aRegs[3]),
693 SSMFIELD_ENTRY( X86XSAVEZMM16HI, aRegs[4]),
694 SSMFIELD_ENTRY( X86XSAVEZMM16HI, aRegs[5]),
695 SSMFIELD_ENTRY( X86XSAVEZMM16HI, aRegs[6]),
696 SSMFIELD_ENTRY( X86XSAVEZMM16HI, aRegs[7]),
697 SSMFIELD_ENTRY( X86XSAVEZMM16HI, aRegs[8]),
698 SSMFIELD_ENTRY( X86XSAVEZMM16HI, aRegs[9]),
699 SSMFIELD_ENTRY( X86XSAVEZMM16HI, aRegs[10]),
700 SSMFIELD_ENTRY( X86XSAVEZMM16HI, aRegs[11]),
701 SSMFIELD_ENTRY( X86XSAVEZMM16HI, aRegs[12]),
702 SSMFIELD_ENTRY( X86XSAVEZMM16HI, aRegs[13]),
703 SSMFIELD_ENTRY( X86XSAVEZMM16HI, aRegs[14]),
704 SSMFIELD_ENTRY( X86XSAVEZMM16HI, aRegs[15]),
705 SSMFIELD_ENTRY_TERM()
706};
707
708
709
710/** Saved state field descriptors for CPUMCTX in V4.1 before the hidden selector
711 * registeres changed. */
712static const SSMFIELD g_aCpumX87FieldsMem[] =
713{
714 SSMFIELD_ENTRY( X86FXSTATE, FCW),
715 SSMFIELD_ENTRY( X86FXSTATE, FSW),
716 SSMFIELD_ENTRY( X86FXSTATE, FTW),
717 SSMFIELD_ENTRY( X86FXSTATE, FOP),
718 SSMFIELD_ENTRY( X86FXSTATE, FPUIP),
719 SSMFIELD_ENTRY( X86FXSTATE, CS),
720 SSMFIELD_ENTRY( X86FXSTATE, Rsrvd1),
721 SSMFIELD_ENTRY( X86FXSTATE, FPUDP),
722 SSMFIELD_ENTRY( X86FXSTATE, DS),
723 SSMFIELD_ENTRY( X86FXSTATE, Rsrvd2),
724 SSMFIELD_ENTRY( X86FXSTATE, MXCSR),
725 SSMFIELD_ENTRY( X86FXSTATE, MXCSR_MASK),
726 SSMFIELD_ENTRY( X86FXSTATE, aRegs[0]),
727 SSMFIELD_ENTRY( X86FXSTATE, aRegs[1]),
728 SSMFIELD_ENTRY( X86FXSTATE, aRegs[2]),
729 SSMFIELD_ENTRY( X86FXSTATE, aRegs[3]),
730 SSMFIELD_ENTRY( X86FXSTATE, aRegs[4]),
731 SSMFIELD_ENTRY( X86FXSTATE, aRegs[5]),
732 SSMFIELD_ENTRY( X86FXSTATE, aRegs[6]),
733 SSMFIELD_ENTRY( X86FXSTATE, aRegs[7]),
734 SSMFIELD_ENTRY( X86FXSTATE, aXMM[0]),
735 SSMFIELD_ENTRY( X86FXSTATE, aXMM[1]),
736 SSMFIELD_ENTRY( X86FXSTATE, aXMM[2]),
737 SSMFIELD_ENTRY( X86FXSTATE, aXMM[3]),
738 SSMFIELD_ENTRY( X86FXSTATE, aXMM[4]),
739 SSMFIELD_ENTRY( X86FXSTATE, aXMM[5]),
740 SSMFIELD_ENTRY( X86FXSTATE, aXMM[6]),
741 SSMFIELD_ENTRY( X86FXSTATE, aXMM[7]),
742 SSMFIELD_ENTRY( X86FXSTATE, aXMM[8]),
743 SSMFIELD_ENTRY( X86FXSTATE, aXMM[9]),
744 SSMFIELD_ENTRY( X86FXSTATE, aXMM[10]),
745 SSMFIELD_ENTRY( X86FXSTATE, aXMM[11]),
746 SSMFIELD_ENTRY( X86FXSTATE, aXMM[12]),
747 SSMFIELD_ENTRY( X86FXSTATE, aXMM[13]),
748 SSMFIELD_ENTRY( X86FXSTATE, aXMM[14]),
749 SSMFIELD_ENTRY( X86FXSTATE, aXMM[15]),
750 SSMFIELD_ENTRY_IGNORE( X86FXSTATE, au32RsrvdRest),
751 SSMFIELD_ENTRY_IGNORE( X86FXSTATE, au32RsrvdForSoftware),
752};
753
754/** Saved state field descriptors for CPUMCTX in V4.1 before the hidden selector
755 * registeres changed. */
756static const SSMFIELD g_aCpumCtxFieldsMem[] =
757{
758 SSMFIELD_ENTRY( CPUMCTX, rdi),
759 SSMFIELD_ENTRY( CPUMCTX, rsi),
760 SSMFIELD_ENTRY( CPUMCTX, rbp),
761 SSMFIELD_ENTRY( CPUMCTX, rax),
762 SSMFIELD_ENTRY( CPUMCTX, rbx),
763 SSMFIELD_ENTRY( CPUMCTX, rdx),
764 SSMFIELD_ENTRY( CPUMCTX, rcx),
765 SSMFIELD_ENTRY( CPUMCTX, rsp),
766 SSMFIELD_ENTRY_OLD( lss_esp, sizeof(uint32_t)),
767 SSMFIELD_ENTRY( CPUMCTX, ss.Sel),
768 SSMFIELD_ENTRY_OLD( ssPadding, sizeof(uint16_t)),
769 SSMFIELD_ENTRY( CPUMCTX, gs.Sel),
770 SSMFIELD_ENTRY_OLD( gsPadding, sizeof(uint16_t)),
771 SSMFIELD_ENTRY( CPUMCTX, fs.Sel),
772 SSMFIELD_ENTRY_OLD( fsPadding, sizeof(uint16_t)),
773 SSMFIELD_ENTRY( CPUMCTX, es.Sel),
774 SSMFIELD_ENTRY_OLD( esPadding, sizeof(uint16_t)),
775 SSMFIELD_ENTRY( CPUMCTX, ds.Sel),
776 SSMFIELD_ENTRY_OLD( dsPadding, sizeof(uint16_t)),
777 SSMFIELD_ENTRY( CPUMCTX, cs.Sel),
778 SSMFIELD_ENTRY_OLD( csPadding, sizeof(uint16_t)*3),
779 SSMFIELD_ENTRY( CPUMCTX, rflags),
780 SSMFIELD_ENTRY( CPUMCTX, rip),
781 SSMFIELD_ENTRY( CPUMCTX, r8),
782 SSMFIELD_ENTRY( CPUMCTX, r9),
783 SSMFIELD_ENTRY( CPUMCTX, r10),
784 SSMFIELD_ENTRY( CPUMCTX, r11),
785 SSMFIELD_ENTRY( CPUMCTX, r12),
786 SSMFIELD_ENTRY( CPUMCTX, r13),
787 SSMFIELD_ENTRY( CPUMCTX, r14),
788 SSMFIELD_ENTRY( CPUMCTX, r15),
789 SSMFIELD_ENTRY( CPUMCTX, es.u64Base),
790 SSMFIELD_ENTRY( CPUMCTX, es.u32Limit),
791 SSMFIELD_ENTRY( CPUMCTX, es.Attr),
792 SSMFIELD_ENTRY( CPUMCTX, cs.u64Base),
793 SSMFIELD_ENTRY( CPUMCTX, cs.u32Limit),
794 SSMFIELD_ENTRY( CPUMCTX, cs.Attr),
795 SSMFIELD_ENTRY( CPUMCTX, ss.u64Base),
796 SSMFIELD_ENTRY( CPUMCTX, ss.u32Limit),
797 SSMFIELD_ENTRY( CPUMCTX, ss.Attr),
798 SSMFIELD_ENTRY( CPUMCTX, ds.u64Base),
799 SSMFIELD_ENTRY( CPUMCTX, ds.u32Limit),
800 SSMFIELD_ENTRY( CPUMCTX, ds.Attr),
801 SSMFIELD_ENTRY( CPUMCTX, fs.u64Base),
802 SSMFIELD_ENTRY( CPUMCTX, fs.u32Limit),
803 SSMFIELD_ENTRY( CPUMCTX, fs.Attr),
804 SSMFIELD_ENTRY( CPUMCTX, gs.u64Base),
805 SSMFIELD_ENTRY( CPUMCTX, gs.u32Limit),
806 SSMFIELD_ENTRY( CPUMCTX, gs.Attr),
807 SSMFIELD_ENTRY( CPUMCTX, cr0),
808 SSMFIELD_ENTRY( CPUMCTX, cr2),
809 SSMFIELD_ENTRY( CPUMCTX, cr3),
810 SSMFIELD_ENTRY( CPUMCTX, cr4),
811 SSMFIELD_ENTRY( CPUMCTX, dr[0]),
812 SSMFIELD_ENTRY( CPUMCTX, dr[1]),
813 SSMFIELD_ENTRY( CPUMCTX, dr[2]),
814 SSMFIELD_ENTRY( CPUMCTX, dr[3]),
815 SSMFIELD_ENTRY_OLD( dr[4], sizeof(uint64_t)),
816 SSMFIELD_ENTRY_OLD( dr[5], sizeof(uint64_t)),
817 SSMFIELD_ENTRY( CPUMCTX, dr[6]),
818 SSMFIELD_ENTRY( CPUMCTX, dr[7]),
819 SSMFIELD_ENTRY( CPUMCTX, gdtr.cbGdt),
820 SSMFIELD_ENTRY( CPUMCTX, gdtr.pGdt),
821 SSMFIELD_ENTRY_OLD( gdtrPadding, sizeof(uint16_t)),
822 SSMFIELD_ENTRY( CPUMCTX, idtr.cbIdt),
823 SSMFIELD_ENTRY( CPUMCTX, idtr.pIdt),
824 SSMFIELD_ENTRY_OLD( idtrPadding, sizeof(uint16_t)),
825 SSMFIELD_ENTRY( CPUMCTX, ldtr.Sel),
826 SSMFIELD_ENTRY_OLD( ldtrPadding, sizeof(uint16_t)),
827 SSMFIELD_ENTRY( CPUMCTX, tr.Sel),
828 SSMFIELD_ENTRY_OLD( trPadding, sizeof(uint16_t)),
829 SSMFIELD_ENTRY( CPUMCTX, SysEnter.cs),
830 SSMFIELD_ENTRY( CPUMCTX, SysEnter.eip),
831 SSMFIELD_ENTRY( CPUMCTX, SysEnter.esp),
832 SSMFIELD_ENTRY( CPUMCTX, msrEFER),
833 SSMFIELD_ENTRY( CPUMCTX, msrSTAR),
834 SSMFIELD_ENTRY( CPUMCTX, msrPAT),
835 SSMFIELD_ENTRY( CPUMCTX, msrLSTAR),
836 SSMFIELD_ENTRY( CPUMCTX, msrCSTAR),
837 SSMFIELD_ENTRY( CPUMCTX, msrSFMASK),
838 SSMFIELD_ENTRY( CPUMCTX, msrKERNELGSBASE),
839 SSMFIELD_ENTRY( CPUMCTX, ldtr.u64Base),
840 SSMFIELD_ENTRY( CPUMCTX, ldtr.u32Limit),
841 SSMFIELD_ENTRY( CPUMCTX, ldtr.Attr),
842 SSMFIELD_ENTRY( CPUMCTX, tr.u64Base),
843 SSMFIELD_ENTRY( CPUMCTX, tr.u32Limit),
844 SSMFIELD_ENTRY( CPUMCTX, tr.Attr),
845 SSMFIELD_ENTRY_TERM()
846};
847
848/** Saved state field descriptors for CPUMCTX_VER1_6. */
849static const SSMFIELD g_aCpumX87FieldsV16[] =
850{
851 SSMFIELD_ENTRY( X86FXSTATE, FCW),
852 SSMFIELD_ENTRY( X86FXSTATE, FSW),
853 SSMFIELD_ENTRY( X86FXSTATE, FTW),
854 SSMFIELD_ENTRY( X86FXSTATE, FOP),
855 SSMFIELD_ENTRY( X86FXSTATE, FPUIP),
856 SSMFIELD_ENTRY( X86FXSTATE, CS),
857 SSMFIELD_ENTRY( X86FXSTATE, Rsrvd1),
858 SSMFIELD_ENTRY( X86FXSTATE, FPUDP),
859 SSMFIELD_ENTRY( X86FXSTATE, DS),
860 SSMFIELD_ENTRY( X86FXSTATE, Rsrvd2),
861 SSMFIELD_ENTRY( X86FXSTATE, MXCSR),
862 SSMFIELD_ENTRY( X86FXSTATE, MXCSR_MASK),
863 SSMFIELD_ENTRY( X86FXSTATE, aRegs[0]),
864 SSMFIELD_ENTRY( X86FXSTATE, aRegs[1]),
865 SSMFIELD_ENTRY( X86FXSTATE, aRegs[2]),
866 SSMFIELD_ENTRY( X86FXSTATE, aRegs[3]),
867 SSMFIELD_ENTRY( X86FXSTATE, aRegs[4]),
868 SSMFIELD_ENTRY( X86FXSTATE, aRegs[5]),
869 SSMFIELD_ENTRY( X86FXSTATE, aRegs[6]),
870 SSMFIELD_ENTRY( X86FXSTATE, aRegs[7]),
871 SSMFIELD_ENTRY( X86FXSTATE, aXMM[0]),
872 SSMFIELD_ENTRY( X86FXSTATE, aXMM[1]),
873 SSMFIELD_ENTRY( X86FXSTATE, aXMM[2]),
874 SSMFIELD_ENTRY( X86FXSTATE, aXMM[3]),
875 SSMFIELD_ENTRY( X86FXSTATE, aXMM[4]),
876 SSMFIELD_ENTRY( X86FXSTATE, aXMM[5]),
877 SSMFIELD_ENTRY( X86FXSTATE, aXMM[6]),
878 SSMFIELD_ENTRY( X86FXSTATE, aXMM[7]),
879 SSMFIELD_ENTRY( X86FXSTATE, aXMM[8]),
880 SSMFIELD_ENTRY( X86FXSTATE, aXMM[9]),
881 SSMFIELD_ENTRY( X86FXSTATE, aXMM[10]),
882 SSMFIELD_ENTRY( X86FXSTATE, aXMM[11]),
883 SSMFIELD_ENTRY( X86FXSTATE, aXMM[12]),
884 SSMFIELD_ENTRY( X86FXSTATE, aXMM[13]),
885 SSMFIELD_ENTRY( X86FXSTATE, aXMM[14]),
886 SSMFIELD_ENTRY( X86FXSTATE, aXMM[15]),
887 SSMFIELD_ENTRY_IGNORE( X86FXSTATE, au32RsrvdRest),
888 SSMFIELD_ENTRY_IGNORE( X86FXSTATE, au32RsrvdForSoftware),
889 SSMFIELD_ENTRY_TERM()
890};
891
892/** Saved state field descriptors for CPUMCTX_VER1_6. */
893static const SSMFIELD g_aCpumCtxFieldsV16[] =
894{
895 SSMFIELD_ENTRY( CPUMCTX, rdi),
896 SSMFIELD_ENTRY( CPUMCTX, rsi),
897 SSMFIELD_ENTRY( CPUMCTX, rbp),
898 SSMFIELD_ENTRY( CPUMCTX, rax),
899 SSMFIELD_ENTRY( CPUMCTX, rbx),
900 SSMFIELD_ENTRY( CPUMCTX, rdx),
901 SSMFIELD_ENTRY( CPUMCTX, rcx),
902 SSMFIELD_ENTRY_U32_ZX_U64( CPUMCTX, rsp),
903 SSMFIELD_ENTRY( CPUMCTX, ss.Sel),
904 SSMFIELD_ENTRY_OLD( ssPadding, sizeof(uint16_t)),
905 SSMFIELD_ENTRY_OLD( CPUMCTX, sizeof(uint64_t) /*rsp_notused*/),
906 SSMFIELD_ENTRY( CPUMCTX, gs.Sel),
907 SSMFIELD_ENTRY_OLD( gsPadding, sizeof(uint16_t)),
908 SSMFIELD_ENTRY( CPUMCTX, fs.Sel),
909 SSMFIELD_ENTRY_OLD( fsPadding, sizeof(uint16_t)),
910 SSMFIELD_ENTRY( CPUMCTX, es.Sel),
911 SSMFIELD_ENTRY_OLD( esPadding, sizeof(uint16_t)),
912 SSMFIELD_ENTRY( CPUMCTX, ds.Sel),
913 SSMFIELD_ENTRY_OLD( dsPadding, sizeof(uint16_t)),
914 SSMFIELD_ENTRY( CPUMCTX, cs.Sel),
915 SSMFIELD_ENTRY_OLD( csPadding, sizeof(uint16_t)*3),
916 SSMFIELD_ENTRY( CPUMCTX, rflags),
917 SSMFIELD_ENTRY( CPUMCTX, rip),
918 SSMFIELD_ENTRY( CPUMCTX, r8),
919 SSMFIELD_ENTRY( CPUMCTX, r9),
920 SSMFIELD_ENTRY( CPUMCTX, r10),
921 SSMFIELD_ENTRY( CPUMCTX, r11),
922 SSMFIELD_ENTRY( CPUMCTX, r12),
923 SSMFIELD_ENTRY( CPUMCTX, r13),
924 SSMFIELD_ENTRY( CPUMCTX, r14),
925 SSMFIELD_ENTRY( CPUMCTX, r15),
926 SSMFIELD_ENTRY_U32_ZX_U64( CPUMCTX, es.u64Base),
927 SSMFIELD_ENTRY( CPUMCTX, es.u32Limit),
928 SSMFIELD_ENTRY( CPUMCTX, es.Attr),
929 SSMFIELD_ENTRY_U32_ZX_U64( CPUMCTX, cs.u64Base),
930 SSMFIELD_ENTRY( CPUMCTX, cs.u32Limit),
931 SSMFIELD_ENTRY( CPUMCTX, cs.Attr),
932 SSMFIELD_ENTRY_U32_ZX_U64( CPUMCTX, ss.u64Base),
933 SSMFIELD_ENTRY( CPUMCTX, ss.u32Limit),
934 SSMFIELD_ENTRY( CPUMCTX, ss.Attr),
935 SSMFIELD_ENTRY_U32_ZX_U64( CPUMCTX, ds.u64Base),
936 SSMFIELD_ENTRY( CPUMCTX, ds.u32Limit),
937 SSMFIELD_ENTRY( CPUMCTX, ds.Attr),
938 SSMFIELD_ENTRY_U32_ZX_U64( CPUMCTX, fs.u64Base),
939 SSMFIELD_ENTRY( CPUMCTX, fs.u32Limit),
940 SSMFIELD_ENTRY( CPUMCTX, fs.Attr),
941 SSMFIELD_ENTRY_U32_ZX_U64( CPUMCTX, gs.u64Base),
942 SSMFIELD_ENTRY( CPUMCTX, gs.u32Limit),
943 SSMFIELD_ENTRY( CPUMCTX, gs.Attr),
944 SSMFIELD_ENTRY( CPUMCTX, cr0),
945 SSMFIELD_ENTRY( CPUMCTX, cr2),
946 SSMFIELD_ENTRY( CPUMCTX, cr3),
947 SSMFIELD_ENTRY( CPUMCTX, cr4),
948 SSMFIELD_ENTRY_OLD( cr8, sizeof(uint64_t)),
949 SSMFIELD_ENTRY( CPUMCTX, dr[0]),
950 SSMFIELD_ENTRY( CPUMCTX, dr[1]),
951 SSMFIELD_ENTRY( CPUMCTX, dr[2]),
952 SSMFIELD_ENTRY( CPUMCTX, dr[3]),
953 SSMFIELD_ENTRY_OLD( dr[4], sizeof(uint64_t)),
954 SSMFIELD_ENTRY_OLD( dr[5], sizeof(uint64_t)),
955 SSMFIELD_ENTRY( CPUMCTX, dr[6]),
956 SSMFIELD_ENTRY( CPUMCTX, dr[7]),
957 SSMFIELD_ENTRY( CPUMCTX, gdtr.cbGdt),
958 SSMFIELD_ENTRY_U32_ZX_U64( CPUMCTX, gdtr.pGdt),
959 SSMFIELD_ENTRY_OLD( gdtrPadding, sizeof(uint16_t)),
960 SSMFIELD_ENTRY_OLD( gdtrPadding64, sizeof(uint64_t)),
961 SSMFIELD_ENTRY( CPUMCTX, idtr.cbIdt),
962 SSMFIELD_ENTRY_U32_ZX_U64( CPUMCTX, idtr.pIdt),
963 SSMFIELD_ENTRY_OLD( idtrPadding, sizeof(uint16_t)),
964 SSMFIELD_ENTRY_OLD( idtrPadding64, sizeof(uint64_t)),
965 SSMFIELD_ENTRY( CPUMCTX, ldtr.Sel),
966 SSMFIELD_ENTRY_OLD( ldtrPadding, sizeof(uint16_t)),
967 SSMFIELD_ENTRY( CPUMCTX, tr.Sel),
968 SSMFIELD_ENTRY_OLD( trPadding, sizeof(uint16_t)),
969 SSMFIELD_ENTRY( CPUMCTX, SysEnter.cs),
970 SSMFIELD_ENTRY( CPUMCTX, SysEnter.eip),
971 SSMFIELD_ENTRY( CPUMCTX, SysEnter.esp),
972 SSMFIELD_ENTRY( CPUMCTX, msrEFER),
973 SSMFIELD_ENTRY( CPUMCTX, msrSTAR),
974 SSMFIELD_ENTRY( CPUMCTX, msrPAT),
975 SSMFIELD_ENTRY( CPUMCTX, msrLSTAR),
976 SSMFIELD_ENTRY( CPUMCTX, msrCSTAR),
977 SSMFIELD_ENTRY( CPUMCTX, msrSFMASK),
978 SSMFIELD_ENTRY_OLD( msrFSBASE, sizeof(uint64_t)),
979 SSMFIELD_ENTRY_OLD( msrGSBASE, sizeof(uint64_t)),
980 SSMFIELD_ENTRY( CPUMCTX, msrKERNELGSBASE),
981 SSMFIELD_ENTRY_U32_ZX_U64( CPUMCTX, ldtr.u64Base),
982 SSMFIELD_ENTRY( CPUMCTX, ldtr.u32Limit),
983 SSMFIELD_ENTRY( CPUMCTX, ldtr.Attr),
984 SSMFIELD_ENTRY_U32_ZX_U64( CPUMCTX, tr.u64Base),
985 SSMFIELD_ENTRY( CPUMCTX, tr.u32Limit),
986 SSMFIELD_ENTRY( CPUMCTX, tr.Attr),
987 SSMFIELD_ENTRY_OLD( padding, sizeof(uint32_t)*2),
988 SSMFIELD_ENTRY_TERM()
989};
990
991
992#if defined(RT_ARCH_X86) || defined(RT_ARCH_AMD64)
993/**
994 * Checks for partial/leaky FXSAVE/FXRSTOR handling on AMD CPUs.
995 *
996 * AMD K7, K8 and newer AMD CPUs do not save/restore the x87 error pointers
997 * (last instruction pointer, last data pointer, last opcode) except when the ES
998 * bit (Exception Summary) in x87 FSW (FPU Status Word) is set. Thus if we don't
999 * clear these registers there is potential, local FPU leakage from a process
1000 * using the FPU to another.
1001 *
1002 * See AMD Instruction Reference for FXSAVE, FXRSTOR.
1003 *
1004 * @param pVM The cross context VM structure.
1005 */
1006static void cpumR3CheckLeakyFpu(PVM pVM)
1007{
1008 uint32_t u32CpuVersion = ASMCpuId_EAX(1);
1009 uint32_t const u32Family = u32CpuVersion >> 8;
1010 if ( u32Family >= 6 /* K7 and higher */
1011 && (ASMIsAmdCpu() || ASMIsHygonCpu()) )
1012 {
1013 uint32_t cExt = ASMCpuId_EAX(0x80000000);
1014 if (RTX86IsValidExtRange(cExt))
1015 {
1016 uint32_t fExtFeaturesEDX = ASMCpuId_EDX(0x80000001);
1017 if (fExtFeaturesEDX & X86_CPUID_AMD_FEATURE_EDX_FFXSR)
1018 {
1019 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
1020 {
1021 PVMCPU pVCpu = pVM->apCpusR3[idCpu];
1022 pVCpu->cpum.s.fUseFlags |= CPUM_USE_FFXSR_LEAKY;
1023 }
1024 Log(("CPUM: Host CPU has leaky fxsave/fxrstor behaviour\n"));
1025 }
1026 }
1027 }
1028}
1029#endif
1030
1031
1032/**
1033 * Initialize the SVM hardware virtualization state.
1034 *
1035 * @param pVM The cross context VM structure.
1036 */
1037static void cpumR3InitSvmHwVirtState(PVM pVM)
1038{
1039 LogRel(("CPUM: AMD-V nested-guest init\n"));
1040 for (VMCPUID i = 0; i < pVM->cCpus; i++)
1041 {
1042 PVMCPU pVCpu = pVM->apCpusR3[i];
1043 PCPUMCTX pCtx = &pVCpu->cpum.s.Guest;
1044
1045 /* Initialize that SVM hardware virtualization is available. */
1046 pCtx->hwvirt.enmHwvirt = CPUMHWVIRT_SVM;
1047
1048 AssertCompile(sizeof(pCtx->hwvirt.svm.Vmcb) == SVM_VMCB_PAGES * X86_PAGE_SIZE);
1049 AssertCompile(sizeof(pCtx->hwvirt.svm.abMsrBitmap) == SVM_MSRPM_PAGES * X86_PAGE_SIZE);
1050 AssertCompile(sizeof(pCtx->hwvirt.svm.abIoBitmap) == SVM_IOPM_PAGES * X86_PAGE_SIZE);
1051
1052 /* Initialize non-zero values. */
1053 pCtx->hwvirt.svm.GCPhysVmcb = NIL_RTGCPHYS;
1054 }
1055}
1056
1057
1058/**
1059 * Resets per-VCPU SVM hardware virtualization state.
1060 *
1061 * @param pVCpu The cross context virtual CPU structure.
1062 */
1063DECLINLINE(void) cpumR3ResetSvmHwVirtState(PVMCPU pVCpu)
1064{
1065 PCPUMCTX pCtx = &pVCpu->cpum.s.Guest;
1066 Assert(pCtx->hwvirt.enmHwvirt == CPUMHWVIRT_SVM);
1067
1068 RT_ZERO(pCtx->hwvirt.svm.Vmcb);
1069 RT_ZERO(pCtx->hwvirt.svm.HostState);
1070 RT_ZERO(pCtx->hwvirt.svm.abMsrBitmap);
1071 RT_ZERO(pCtx->hwvirt.svm.abIoBitmap);
1072
1073 pCtx->hwvirt.svm.uMsrHSavePa = 0;
1074 pCtx->hwvirt.svm.uPrevPauseTick = 0;
1075 pCtx->hwvirt.svm.GCPhysVmcb = NIL_RTGCPHYS;
1076 pCtx->hwvirt.svm.cPauseFilter = 0;
1077 pCtx->hwvirt.svm.cPauseFilterThreshold = 0;
1078 pCtx->hwvirt.svm.fInterceptEvents = false;
1079}
1080
1081
1082/**
1083 * Initializes the VMX hardware virtualization state.
1084 *
1085 * @param pVM The cross context VM structure.
1086 */
1087static void cpumR3InitVmxHwVirtState(PVM pVM)
1088{
1089 LogRel(("CPUM: VT-x nested-guest init\n"));
1090 for (VMCPUID i = 0; i < pVM->cCpus; i++)
1091 {
1092 PVMCPU pVCpu = pVM->apCpusR3[i];
1093 PCPUMCTX pCtx = &pVCpu->cpum.s.Guest;
1094
1095 /* Initialize that VMX hardware virtualization is available. */
1096 pCtx->hwvirt.enmHwvirt = CPUMHWVIRT_VMX;
1097
1098 AssertCompile(sizeof(pCtx->hwvirt.vmx.Vmcs) == VMX_V_VMCS_PAGES * X86_PAGE_SIZE);
1099 AssertCompile(sizeof(pCtx->hwvirt.vmx.Vmcs) == VMX_V_VMCS_SIZE);
1100 AssertCompile(sizeof(pCtx->hwvirt.vmx.ShadowVmcs) == VMX_V_SHADOW_VMCS_PAGES * X86_PAGE_SIZE);
1101 AssertCompile(sizeof(pCtx->hwvirt.vmx.ShadowVmcs) == VMX_V_SHADOW_VMCS_SIZE);
1102 AssertCompile(sizeof(pCtx->hwvirt.vmx.abVmreadBitmap) == VMX_V_VMREAD_VMWRITE_BITMAP_PAGES * X86_PAGE_SIZE);
1103 AssertCompile(sizeof(pCtx->hwvirt.vmx.abVmreadBitmap) == VMX_V_VMREAD_VMWRITE_BITMAP_SIZE);
1104 AssertCompile(sizeof(pCtx->hwvirt.vmx.abVmwriteBitmap) == VMX_V_VMREAD_VMWRITE_BITMAP_PAGES * X86_PAGE_SIZE);
1105 AssertCompile(sizeof(pCtx->hwvirt.vmx.abVmwriteBitmap) == VMX_V_VMREAD_VMWRITE_BITMAP_SIZE);
1106 AssertCompile(sizeof(pCtx->hwvirt.vmx.aEntryMsrLoadArea) == VMX_V_AUTOMSR_AREA_PAGES * X86_PAGE_SIZE);
1107 AssertCompile(sizeof(pCtx->hwvirt.vmx.aEntryMsrLoadArea) == VMX_V_AUTOMSR_AREA_SIZE);
1108 AssertCompile(sizeof(pCtx->hwvirt.vmx.aExitMsrStoreArea) == VMX_V_AUTOMSR_AREA_PAGES * X86_PAGE_SIZE);
1109 AssertCompile(sizeof(pCtx->hwvirt.vmx.aExitMsrStoreArea) == VMX_V_AUTOMSR_AREA_SIZE);
1110 AssertCompile(sizeof(pCtx->hwvirt.vmx.aExitMsrLoadArea) == VMX_V_AUTOMSR_AREA_PAGES * X86_PAGE_SIZE);
1111 AssertCompile(sizeof(pCtx->hwvirt.vmx.aExitMsrLoadArea) == VMX_V_AUTOMSR_AREA_SIZE);
1112 AssertCompile(sizeof(pCtx->hwvirt.vmx.abMsrBitmap) == VMX_V_MSR_BITMAP_PAGES * X86_PAGE_SIZE);
1113 AssertCompile(sizeof(pCtx->hwvirt.vmx.abMsrBitmap) == VMX_V_MSR_BITMAP_SIZE);
1114 AssertCompile(sizeof(pCtx->hwvirt.vmx.abIoBitmap) == (VMX_V_IO_BITMAP_A_PAGES + VMX_V_IO_BITMAP_B_PAGES) * X86_PAGE_SIZE);
1115 AssertCompile(sizeof(pCtx->hwvirt.vmx.abIoBitmap) == VMX_V_IO_BITMAP_A_SIZE + VMX_V_IO_BITMAP_B_SIZE);
1116
1117 /* Initialize non-zero values. */
1118 pCtx->hwvirt.vmx.GCPhysVmxon = NIL_RTGCPHYS;
1119 pCtx->hwvirt.vmx.GCPhysShadowVmcs = NIL_RTGCPHYS;
1120 pCtx->hwvirt.vmx.GCPhysVmcs = NIL_RTGCPHYS;
1121 }
1122}
1123
1124
1125/**
1126 * Resets per-VCPU VMX hardware virtualization state.
1127 *
1128 * @param pVCpu The cross context virtual CPU structure.
1129 */
1130DECLINLINE(void) cpumR3ResetVmxHwVirtState(PVMCPU pVCpu)
1131{
1132 PCPUMCTX pCtx = &pVCpu->cpum.s.Guest;
1133 Assert(pCtx->hwvirt.enmHwvirt == CPUMHWVIRT_VMX);
1134
1135 RT_ZERO(pCtx->hwvirt.vmx.Vmcs);
1136 RT_ZERO(pCtx->hwvirt.vmx.ShadowVmcs);
1137 RT_ZERO(pCtx->hwvirt.vmx.abVmreadBitmap);
1138 RT_ZERO(pCtx->hwvirt.vmx.abVmwriteBitmap);
1139 RT_ZERO(pCtx->hwvirt.vmx.aEntryMsrLoadArea);
1140 RT_ZERO(pCtx->hwvirt.vmx.aExitMsrStoreArea);
1141 RT_ZERO(pCtx->hwvirt.vmx.aExitMsrLoadArea);
1142 RT_ZERO(pCtx->hwvirt.vmx.abMsrBitmap);
1143 RT_ZERO(pCtx->hwvirt.vmx.abIoBitmap);
1144
1145 pCtx->hwvirt.vmx.GCPhysVmxon = NIL_RTGCPHYS;
1146 pCtx->hwvirt.vmx.GCPhysShadowVmcs = NIL_RTGCPHYS;
1147 pCtx->hwvirt.vmx.GCPhysVmcs = NIL_RTGCPHYS;
1148 pCtx->hwvirt.vmx.fInVmxRootMode = false;
1149 pCtx->hwvirt.vmx.fInVmxNonRootMode = false;
1150 /* Don't reset diagnostics here. */
1151
1152 pCtx->hwvirt.vmx.fInterceptEvents = false;
1153 pCtx->hwvirt.vmx.fNmiUnblockingIret = false;
1154 pCtx->hwvirt.vmx.uFirstPauseLoopTick = 0;
1155 pCtx->hwvirt.vmx.uPrevPauseTick = 0;
1156 pCtx->hwvirt.vmx.uEntryTick = 0;
1157 pCtx->hwvirt.vmx.offVirtApicWrite = 0;
1158 pCtx->hwvirt.vmx.fVirtNmiBlocking = false;
1159
1160 /* Stop any VMX-preemption timer. */
1161 CPUMStopGuestVmxPremptTimer(pVCpu);
1162
1163 /* Clear all nested-guest FFs. */
1164 VMCPU_FF_CLEAR_MASK(pVCpu, VMCPU_FF_VMX_ALL_MASK);
1165}
1166
1167
1168/**
1169 * Displays the host and guest VMX features.
1170 *
1171 * @param pVM The cross context VM structure.
1172 * @param pHlp The info helper functions.
1173 * @param pszArgs "terse", "default" or "verbose".
1174 */
1175DECLCALLBACK(void) cpumR3InfoVmxFeatures(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs)
1176{
1177 RT_NOREF(pszArgs);
1178 PCCPUMFEATURES pHostFeatures = &pVM->cpum.s.HostFeatures;
1179 PCCPUMFEATURES pGuestFeatures = &pVM->cpum.s.GuestFeatures;
1180 if ( pHostFeatures->enmCpuVendor == CPUMCPUVENDOR_INTEL
1181 || pHostFeatures->enmCpuVendor == CPUMCPUVENDOR_VIA
1182 || pHostFeatures->enmCpuVendor == CPUMCPUVENDOR_SHANGHAI)
1183 {
1184#define VMXFEATDUMP(a_szDesc, a_Var) \
1185 pHlp->pfnPrintf(pHlp, " %s = %u (%u)\n", a_szDesc, pGuestFeatures->a_Var, pHostFeatures->a_Var)
1186
1187 pHlp->pfnPrintf(pHlp, "Nested hardware virtualization - VMX features\n");
1188 pHlp->pfnPrintf(pHlp, " Mnemonic - Description = guest (host)\n");
1189 VMXFEATDUMP("VMX - Virtual-Machine Extensions ", fVmx);
1190 /* Basic. */
1191 VMXFEATDUMP("InsOutInfo - INS/OUTS instruction info. ", fVmxInsOutInfo);
1192
1193 /* Pin-based controls. */
1194 VMXFEATDUMP("ExtIntExit - External interrupt exiting ", fVmxExtIntExit);
1195 VMXFEATDUMP("NmiExit - NMI exiting ", fVmxNmiExit);
1196 VMXFEATDUMP("VirtNmi - Virtual NMIs ", fVmxVirtNmi);
1197 VMXFEATDUMP("PreemptTimer - VMX preemption timer ", fVmxPreemptTimer);
1198 VMXFEATDUMP("PostedInt - Posted interrupts ", fVmxPostedInt);
1199
1200 /* Processor-based controls. */
1201 VMXFEATDUMP("IntWindowExit - Interrupt-window exiting ", fVmxIntWindowExit);
1202 VMXFEATDUMP("TscOffsetting - TSC offsetting ", fVmxTscOffsetting);
1203 VMXFEATDUMP("HltExit - HLT exiting ", fVmxHltExit);
1204 VMXFEATDUMP("InvlpgExit - INVLPG exiting ", fVmxInvlpgExit);
1205 VMXFEATDUMP("MwaitExit - MWAIT exiting ", fVmxMwaitExit);
1206 VMXFEATDUMP("RdpmcExit - RDPMC exiting ", fVmxRdpmcExit);
1207 VMXFEATDUMP("RdtscExit - RDTSC exiting ", fVmxRdtscExit);
1208 VMXFEATDUMP("Cr3LoadExit - CR3-load exiting ", fVmxCr3LoadExit);
1209 VMXFEATDUMP("Cr3StoreExit - CR3-store exiting ", fVmxCr3StoreExit);
1210 VMXFEATDUMP("TertiaryExecCtls - Activate tertiary controls ", fVmxTertiaryExecCtls);
1211 VMXFEATDUMP("Cr8LoadExit - CR8-load exiting ", fVmxCr8LoadExit);
1212 VMXFEATDUMP("Cr8StoreExit - CR8-store exiting ", fVmxCr8StoreExit);
1213 VMXFEATDUMP("UseTprShadow - Use TPR shadow ", fVmxUseTprShadow);
1214 VMXFEATDUMP("NmiWindowExit - NMI-window exiting ", fVmxNmiWindowExit);
1215 VMXFEATDUMP("MovDRxExit - Mov-DR exiting ", fVmxMovDRxExit);
1216 VMXFEATDUMP("UncondIoExit - Unconditional I/O exiting ", fVmxUncondIoExit);
1217 VMXFEATDUMP("UseIoBitmaps - Use I/O bitmaps ", fVmxUseIoBitmaps);
1218 VMXFEATDUMP("MonitorTrapFlag - Monitor Trap Flag ", fVmxMonitorTrapFlag);
1219 VMXFEATDUMP("UseMsrBitmaps - MSR bitmaps ", fVmxUseMsrBitmaps);
1220 VMXFEATDUMP("MonitorExit - MONITOR exiting ", fVmxMonitorExit);
1221 VMXFEATDUMP("PauseExit - PAUSE exiting ", fVmxPauseExit);
1222 VMXFEATDUMP("SecondaryExecCtl - Activate secondary controls ", fVmxSecondaryExecCtls);
1223
1224 /* Secondary processor-based controls. */
1225 VMXFEATDUMP("VirtApic - Virtualize-APIC accesses ", fVmxVirtApicAccess);
1226 VMXFEATDUMP("Ept - Extended Page Tables ", fVmxEpt);
1227 VMXFEATDUMP("DescTableExit - Descriptor-table exiting ", fVmxDescTableExit);
1228 VMXFEATDUMP("Rdtscp - Enable RDTSCP ", fVmxRdtscp);
1229 VMXFEATDUMP("VirtX2ApicMode - Virtualize-x2APIC mode ", fVmxVirtX2ApicMode);
1230 VMXFEATDUMP("Vpid - Enable VPID ", fVmxVpid);
1231 VMXFEATDUMP("WbinvdExit - WBINVD exiting ", fVmxWbinvdExit);
1232 VMXFEATDUMP("UnrestrictedGuest - Unrestricted guest ", fVmxUnrestrictedGuest);
1233 VMXFEATDUMP("ApicRegVirt - APIC-register virtualization ", fVmxApicRegVirt);
1234 VMXFEATDUMP("VirtIntDelivery - Virtual-interrupt delivery ", fVmxVirtIntDelivery);
1235 VMXFEATDUMP("PauseLoopExit - PAUSE-loop exiting ", fVmxPauseLoopExit);
1236 VMXFEATDUMP("RdrandExit - RDRAND exiting ", fVmxRdrandExit);
1237 VMXFEATDUMP("Invpcid - Enable INVPCID ", fVmxInvpcid);
1238 VMXFEATDUMP("VmFuncs - Enable VM Functions ", fVmxVmFunc);
1239 VMXFEATDUMP("VmcsShadowing - VMCS shadowing ", fVmxVmcsShadowing);
1240 VMXFEATDUMP("RdseedExiting - RDSEED exiting ", fVmxRdseedExit);
1241 VMXFEATDUMP("PML - Page-Modification Log (PML) ", fVmxPml);
1242 VMXFEATDUMP("EptVe - EPT violations can cause #VE ", fVmxEptXcptVe);
1243 VMXFEATDUMP("ConcealVmxFromPt - Conceal VMX from Processor Trace ", fVmxConcealVmxFromPt);
1244 VMXFEATDUMP("XsavesXRstors - Enable XSAVES/XRSTORS ", fVmxXsavesXrstors);
1245 VMXFEATDUMP("ModeBasedExecuteEpt - Mode-based execute permissions ", fVmxModeBasedExecuteEpt);
1246 VMXFEATDUMP("SppEpt - Sub-page page write permissions for EPT ", fVmxSppEpt);
1247 VMXFEATDUMP("PtEpt - Processor Trace address' translatable by EPT ", fVmxPtEpt);
1248 VMXFEATDUMP("UseTscScaling - Use TSC scaling ", fVmxUseTscScaling);
1249 VMXFEATDUMP("UserWaitPause - Enable TPAUSE, UMONITOR and UMWAIT ", fVmxUserWaitPause);
1250 VMXFEATDUMP("EnclvExit - ENCLV exiting ", fVmxEnclvExit);
1251
1252 /* Tertiary processor-based controls. */
1253 VMXFEATDUMP("LoadIwKeyExit - LOADIWKEY exiting ", fVmxLoadIwKeyExit);
1254
1255 /* VM-entry controls. */
1256 VMXFEATDUMP("EntryLoadDebugCtls - Load debug controls on VM-entry ", fVmxEntryLoadDebugCtls);
1257 VMXFEATDUMP("Ia32eModeGuest - IA-32e mode guest ", fVmxIa32eModeGuest);
1258 VMXFEATDUMP("EntryLoadEferMsr - Load IA32_EFER MSR on VM-entry ", fVmxEntryLoadEferMsr);
1259 VMXFEATDUMP("EntryLoadPatMsr - Load IA32_PAT MSR on VM-entry ", fVmxEntryLoadPatMsr);
1260
1261 /* VM-exit controls. */
1262 VMXFEATDUMP("ExitSaveDebugCtls - Save debug controls on VM-exit ", fVmxExitSaveDebugCtls);
1263 VMXFEATDUMP("HostAddrSpaceSize - Host address-space size ", fVmxHostAddrSpaceSize);
1264 VMXFEATDUMP("ExitAckExtInt - Acknowledge interrupt on VM-exit ", fVmxExitAckExtInt);
1265 VMXFEATDUMP("ExitSavePatMsr - Save IA32_PAT MSR on VM-exit ", fVmxExitSavePatMsr);
1266 VMXFEATDUMP("ExitLoadPatMsr - Load IA32_PAT MSR on VM-exit ", fVmxExitLoadPatMsr);
1267 VMXFEATDUMP("ExitSaveEferMsr - Save IA32_EFER MSR on VM-exit ", fVmxExitSaveEferMsr);
1268 VMXFEATDUMP("ExitLoadEferMsr - Load IA32_EFER MSR on VM-exit ", fVmxExitLoadEferMsr);
1269 VMXFEATDUMP("SavePreemptTimer - Save VMX-preemption timer ", fVmxSavePreemptTimer);
1270
1271 /* Miscellaneous data. */
1272 VMXFEATDUMP("ExitSaveEferLma - Save IA32_EFER.LMA on VM-exit ", fVmxExitSaveEferLma);
1273 VMXFEATDUMP("IntelPt - Intel PT (Processor Trace) in VMX operation ", fVmxPt);
1274 VMXFEATDUMP("VmwriteAll - VMWRITE to any supported VMCS field ", fVmxVmwriteAll);
1275 VMXFEATDUMP("EntryInjectSoftInt - Inject softint. with 0-len instr. ", fVmxEntryInjectSoftInt);
1276#undef VMXFEATDUMP
1277 }
1278 else
1279 pHlp->pfnPrintf(pHlp, "No VMX features present - requires an Intel or compatible CPU.\n");
1280}
1281
1282
1283/**
1284 * Checks whether nested-guest execution using hardware-assisted VMX (e.g, using HM
1285 * or NEM) is allowed.
1286 *
1287 * @returns @c true if hardware-assisted nested-guest execution is allowed, @c false
1288 * otherwise.
1289 * @param pVM The cross context VM structure.
1290 */
1291static bool cpumR3IsHwAssistNstGstExecAllowed(PVM pVM)
1292{
1293 AssertMsg(pVM->bMainExecutionEngine != VM_EXEC_ENGINE_NOT_SET, ("Calling this function too early!\n"));
1294#ifndef VBOX_WITH_NESTED_HWVIRT_ONLY_IN_IEM
1295 if ( pVM->bMainExecutionEngine == VM_EXEC_ENGINE_HW_VIRT
1296 || pVM->bMainExecutionEngine == VM_EXEC_ENGINE_NATIVE_API)
1297 return true;
1298#else
1299 NOREF(pVM);
1300#endif
1301 return false;
1302}
1303
1304
1305/**
1306 * Initializes the VMX guest MSRs from guest CPU features based on the host MSRs.
1307 *
1308 * @param pVM The cross context VM structure.
1309 * @param pHostVmxMsrs The host VMX MSRs. Pass NULL when fully emulating VMX
1310 * and no hardware-assisted nested-guest execution is
1311 * possible for this VM.
1312 * @param pGuestFeatures The guest features to use (only VMX features are
1313 * accessed).
1314 * @param pGuestVmxMsrs Where to store the initialized guest VMX MSRs.
1315 *
1316 * @remarks This function ASSUMES the VMX guest-features are already exploded!
1317 */
1318static void cpumR3InitVmxGuestMsrs(PVM pVM, PCVMXMSRS pHostVmxMsrs, PCCPUMFEATURES pGuestFeatures, PVMXMSRS pGuestVmxMsrs)
1319{
1320 bool const fIsNstGstHwExecAllowed = cpumR3IsHwAssistNstGstExecAllowed(pVM);
1321
1322 Assert(!fIsNstGstHwExecAllowed || pHostVmxMsrs);
1323 Assert(pGuestFeatures->fVmx);
1324
1325 /* Basic information. */
1326 uint8_t const fTrueVmxMsrs = 1;
1327 {
1328 uint64_t const u64Basic = RT_BF_MAKE(VMX_BF_BASIC_VMCS_ID, VMX_V_VMCS_REVISION_ID )
1329 | RT_BF_MAKE(VMX_BF_BASIC_VMCS_SIZE, VMX_V_VMCS_SIZE )
1330 | RT_BF_MAKE(VMX_BF_BASIC_PHYSADDR_WIDTH, !pGuestFeatures->fLongMode )
1331 | RT_BF_MAKE(VMX_BF_BASIC_DUAL_MON, 0 )
1332 | RT_BF_MAKE(VMX_BF_BASIC_VMCS_MEM_TYPE, VMX_BASIC_MEM_TYPE_WB )
1333 | RT_BF_MAKE(VMX_BF_BASIC_VMCS_INS_OUTS, pGuestFeatures->fVmxInsOutInfo)
1334 | RT_BF_MAKE(VMX_BF_BASIC_TRUE_CTLS, fTrueVmxMsrs );
1335 pGuestVmxMsrs->u64Basic = u64Basic;
1336 }
1337
1338 /* Pin-based VM-execution controls. */
1339 {
1340 uint32_t const fFeatures = (pGuestFeatures->fVmxExtIntExit << VMX_BF_PIN_CTLS_EXT_INT_EXIT_SHIFT )
1341 | (pGuestFeatures->fVmxNmiExit << VMX_BF_PIN_CTLS_NMI_EXIT_SHIFT )
1342 | (pGuestFeatures->fVmxVirtNmi << VMX_BF_PIN_CTLS_VIRT_NMI_SHIFT )
1343 | (pGuestFeatures->fVmxPreemptTimer << VMX_BF_PIN_CTLS_PREEMPT_TIMER_SHIFT)
1344 | (pGuestFeatures->fVmxPostedInt << VMX_BF_PIN_CTLS_POSTED_INT_SHIFT );
1345 uint32_t const fAllowed0 = VMX_PIN_CTLS_DEFAULT1;
1346 uint32_t const fAllowed1 = fFeatures | VMX_PIN_CTLS_DEFAULT1;
1347 AssertMsg((fAllowed0 & fAllowed1) == fAllowed0, ("fAllowed0=%#RX32 fAllowed1=%#RX32 fFeatures=%#RX32\n",
1348 fAllowed0, fAllowed1, fFeatures));
1349 pGuestVmxMsrs->PinCtls.u = RT_MAKE_U64(fAllowed0, fAllowed1);
1350
1351 /* True pin-based VM-execution controls. */
1352 if (fTrueVmxMsrs)
1353 {
1354 /* VMX_PIN_CTLS_DEFAULT1 contains MB1 reserved bits and must be reserved MB1 in true pin-based controls as well. */
1355 pGuestVmxMsrs->TruePinCtls.u = pGuestVmxMsrs->PinCtls.u;
1356 }
1357 }
1358
1359 /* Processor-based VM-execution controls. */
1360 {
1361 uint32_t const fFeatures = (pGuestFeatures->fVmxIntWindowExit << VMX_BF_PROC_CTLS_INT_WINDOW_EXIT_SHIFT )
1362 | (pGuestFeatures->fVmxTscOffsetting << VMX_BF_PROC_CTLS_USE_TSC_OFFSETTING_SHIFT)
1363 | (pGuestFeatures->fVmxHltExit << VMX_BF_PROC_CTLS_HLT_EXIT_SHIFT )
1364 | (pGuestFeatures->fVmxInvlpgExit << VMX_BF_PROC_CTLS_INVLPG_EXIT_SHIFT )
1365 | (pGuestFeatures->fVmxMwaitExit << VMX_BF_PROC_CTLS_MWAIT_EXIT_SHIFT )
1366 | (pGuestFeatures->fVmxRdpmcExit << VMX_BF_PROC_CTLS_RDPMC_EXIT_SHIFT )
1367 | (pGuestFeatures->fVmxRdtscExit << VMX_BF_PROC_CTLS_RDTSC_EXIT_SHIFT )
1368 | (pGuestFeatures->fVmxCr3LoadExit << VMX_BF_PROC_CTLS_CR3_LOAD_EXIT_SHIFT )
1369 | (pGuestFeatures->fVmxCr3StoreExit << VMX_BF_PROC_CTLS_CR3_STORE_EXIT_SHIFT )
1370 | (pGuestFeatures->fVmxTertiaryExecCtls << VMX_BF_PROC_CTLS_USE_TERTIARY_CTLS_SHIFT )
1371 | (pGuestFeatures->fVmxCr8LoadExit << VMX_BF_PROC_CTLS_CR8_LOAD_EXIT_SHIFT )
1372 | (pGuestFeatures->fVmxCr8StoreExit << VMX_BF_PROC_CTLS_CR8_STORE_EXIT_SHIFT )
1373 | (pGuestFeatures->fVmxUseTprShadow << VMX_BF_PROC_CTLS_USE_TPR_SHADOW_SHIFT )
1374 | (pGuestFeatures->fVmxNmiWindowExit << VMX_BF_PROC_CTLS_NMI_WINDOW_EXIT_SHIFT )
1375 | (pGuestFeatures->fVmxMovDRxExit << VMX_BF_PROC_CTLS_MOV_DR_EXIT_SHIFT )
1376 | (pGuestFeatures->fVmxUncondIoExit << VMX_BF_PROC_CTLS_UNCOND_IO_EXIT_SHIFT )
1377 | (pGuestFeatures->fVmxUseIoBitmaps << VMX_BF_PROC_CTLS_USE_IO_BITMAPS_SHIFT )
1378 | (pGuestFeatures->fVmxMonitorTrapFlag << VMX_BF_PROC_CTLS_MONITOR_TRAP_FLAG_SHIFT )
1379 | (pGuestFeatures->fVmxUseMsrBitmaps << VMX_BF_PROC_CTLS_USE_MSR_BITMAPS_SHIFT )
1380 | (pGuestFeatures->fVmxMonitorExit << VMX_BF_PROC_CTLS_MONITOR_EXIT_SHIFT )
1381 | (pGuestFeatures->fVmxPauseExit << VMX_BF_PROC_CTLS_PAUSE_EXIT_SHIFT )
1382 | (pGuestFeatures->fVmxSecondaryExecCtls << VMX_BF_PROC_CTLS_USE_SECONDARY_CTLS_SHIFT);
1383 uint32_t const fAllowed0 = VMX_PROC_CTLS_DEFAULT1;
1384 uint32_t const fAllowed1 = fFeatures | VMX_PROC_CTLS_DEFAULT1;
1385 AssertMsg((fAllowed0 & fAllowed1) == fAllowed0, ("fAllowed0=%#RX32 fAllowed1=%#RX32 fFeatures=%#RX32\n", fAllowed0,
1386 fAllowed1, fFeatures));
1387 pGuestVmxMsrs->ProcCtls.u = RT_MAKE_U64(fAllowed0, fAllowed1);
1388
1389 /* True processor-based VM-execution controls. */
1390 if (fTrueVmxMsrs)
1391 {
1392 /* VMX_PROC_CTLS_DEFAULT1 contains MB1 reserved bits but the following are not really reserved. */
1393 uint32_t const fTrueAllowed0 = VMX_PROC_CTLS_DEFAULT1 & ~( VMX_BF_PROC_CTLS_CR3_LOAD_EXIT_MASK
1394 | VMX_BF_PROC_CTLS_CR3_STORE_EXIT_MASK);
1395 uint32_t const fTrueAllowed1 = fFeatures | fTrueAllowed0;
1396 pGuestVmxMsrs->TrueProcCtls.u = RT_MAKE_U64(fTrueAllowed0, fTrueAllowed1);
1397 }
1398 }
1399
1400 /* Secondary processor-based VM-execution controls. */
1401 if (pGuestFeatures->fVmxSecondaryExecCtls)
1402 {
1403 uint32_t const fFeatures = (pGuestFeatures->fVmxVirtApicAccess << VMX_BF_PROC_CTLS2_VIRT_APIC_ACCESS_SHIFT )
1404 | (pGuestFeatures->fVmxEpt << VMX_BF_PROC_CTLS2_EPT_SHIFT )
1405 | (pGuestFeatures->fVmxDescTableExit << VMX_BF_PROC_CTLS2_DESC_TABLE_EXIT_SHIFT )
1406 | (pGuestFeatures->fVmxRdtscp << VMX_BF_PROC_CTLS2_RDTSCP_SHIFT )
1407 | (pGuestFeatures->fVmxVirtX2ApicMode << VMX_BF_PROC_CTLS2_VIRT_X2APIC_MODE_SHIFT )
1408 | (pGuestFeatures->fVmxVpid << VMX_BF_PROC_CTLS2_VPID_SHIFT )
1409 | (pGuestFeatures->fVmxWbinvdExit << VMX_BF_PROC_CTLS2_WBINVD_EXIT_SHIFT )
1410 | (pGuestFeatures->fVmxUnrestrictedGuest << VMX_BF_PROC_CTLS2_UNRESTRICTED_GUEST_SHIFT )
1411 | (pGuestFeatures->fVmxApicRegVirt << VMX_BF_PROC_CTLS2_APIC_REG_VIRT_SHIFT )
1412 | (pGuestFeatures->fVmxVirtIntDelivery << VMX_BF_PROC_CTLS2_VIRT_INT_DELIVERY_SHIFT )
1413 | (pGuestFeatures->fVmxPauseLoopExit << VMX_BF_PROC_CTLS2_PAUSE_LOOP_EXIT_SHIFT )
1414 | (pGuestFeatures->fVmxRdrandExit << VMX_BF_PROC_CTLS2_RDRAND_EXIT_SHIFT )
1415 | (pGuestFeatures->fVmxInvpcid << VMX_BF_PROC_CTLS2_INVPCID_SHIFT )
1416 | (pGuestFeatures->fVmxVmFunc << VMX_BF_PROC_CTLS2_VMFUNC_SHIFT )
1417 | (pGuestFeatures->fVmxVmcsShadowing << VMX_BF_PROC_CTLS2_VMCS_SHADOWING_SHIFT )
1418 | (pGuestFeatures->fVmxRdseedExit << VMX_BF_PROC_CTLS2_RDSEED_EXIT_SHIFT )
1419 | (pGuestFeatures->fVmxPml << VMX_BF_PROC_CTLS2_PML_SHIFT )
1420 | (pGuestFeatures->fVmxEptXcptVe << VMX_BF_PROC_CTLS2_EPT_VE_SHIFT )
1421 | (pGuestFeatures->fVmxConcealVmxFromPt << VMX_BF_PROC_CTLS2_CONCEAL_VMX_FROM_PT_SHIFT)
1422 | (pGuestFeatures->fVmxXsavesXrstors << VMX_BF_PROC_CTLS2_XSAVES_XRSTORS_SHIFT )
1423 | (pGuestFeatures->fVmxModeBasedExecuteEpt << VMX_BF_PROC_CTLS2_MODE_BASED_EPT_PERM_SHIFT)
1424 | (pGuestFeatures->fVmxSppEpt << VMX_BF_PROC_CTLS2_SPP_EPT_SHIFT )
1425 | (pGuestFeatures->fVmxPtEpt << VMX_BF_PROC_CTLS2_PT_EPT_SHIFT )
1426 | (pGuestFeatures->fVmxUseTscScaling << VMX_BF_PROC_CTLS2_TSC_SCALING_SHIFT )
1427 | (pGuestFeatures->fVmxUserWaitPause << VMX_BF_PROC_CTLS2_USER_WAIT_PAUSE_SHIFT )
1428 | (pGuestFeatures->fVmxEnclvExit << VMX_BF_PROC_CTLS2_ENCLV_EXIT_SHIFT );
1429 uint32_t const fAllowed0 = 0;
1430 uint32_t const fAllowed1 = fFeatures;
1431 pGuestVmxMsrs->ProcCtls2.u = RT_MAKE_U64(fAllowed0, fAllowed1);
1432 }
1433
1434 /* Tertiary processor-based VM-execution controls. */
1435 if (pGuestFeatures->fVmxTertiaryExecCtls)
1436 {
1437 pGuestVmxMsrs->u64ProcCtls3 = (pGuestFeatures->fVmxLoadIwKeyExit << VMX_BF_PROC_CTLS3_LOADIWKEY_EXIT_SHIFT);
1438 }
1439
1440 /* VM-exit controls. */
1441 {
1442 uint32_t const fFeatures = (pGuestFeatures->fVmxExitSaveDebugCtls << VMX_BF_EXIT_CTLS_SAVE_DEBUG_SHIFT )
1443 | (pGuestFeatures->fVmxHostAddrSpaceSize << VMX_BF_EXIT_CTLS_HOST_ADDR_SPACE_SIZE_SHIFT)
1444 | (pGuestFeatures->fVmxExitAckExtInt << VMX_BF_EXIT_CTLS_ACK_EXT_INT_SHIFT )
1445 | (pGuestFeatures->fVmxExitSavePatMsr << VMX_BF_EXIT_CTLS_SAVE_PAT_MSR_SHIFT )
1446 | (pGuestFeatures->fVmxExitLoadPatMsr << VMX_BF_EXIT_CTLS_LOAD_PAT_MSR_SHIFT )
1447 | (pGuestFeatures->fVmxExitSaveEferMsr << VMX_BF_EXIT_CTLS_SAVE_EFER_MSR_SHIFT )
1448 | (pGuestFeatures->fVmxExitLoadEferMsr << VMX_BF_EXIT_CTLS_LOAD_EFER_MSR_SHIFT )
1449 | (pGuestFeatures->fVmxSavePreemptTimer << VMX_BF_EXIT_CTLS_SAVE_PREEMPT_TIMER_SHIFT );
1450 /* Set the default1 class bits. See Intel spec. A.4 "VM-exit Controls". */
1451 uint32_t const fAllowed0 = VMX_EXIT_CTLS_DEFAULT1;
1452 uint32_t const fAllowed1 = fFeatures | VMX_EXIT_CTLS_DEFAULT1;
1453 AssertMsg((fAllowed0 & fAllowed1) == fAllowed0, ("fAllowed0=%#RX32 fAllowed1=%#RX32 fFeatures=%#RX32\n", fAllowed0,
1454 fAllowed1, fFeatures));
1455 pGuestVmxMsrs->ExitCtls.u = RT_MAKE_U64(fAllowed0, fAllowed1);
1456
1457 /* True VM-exit controls. */
1458 if (fTrueVmxMsrs)
1459 {
1460 /* VMX_EXIT_CTLS_DEFAULT1 contains MB1 reserved bits but the following are not really reserved */
1461 uint32_t const fTrueAllowed0 = VMX_EXIT_CTLS_DEFAULT1 & ~VMX_BF_EXIT_CTLS_SAVE_DEBUG_MASK;
1462 uint32_t const fTrueAllowed1 = fFeatures | fTrueAllowed0;
1463 pGuestVmxMsrs->TrueExitCtls.u = RT_MAKE_U64(fTrueAllowed0, fTrueAllowed1);
1464 }
1465 }
1466
1467 /* VM-entry controls. */
1468 {
1469 uint32_t const fFeatures = (pGuestFeatures->fVmxEntryLoadDebugCtls << VMX_BF_ENTRY_CTLS_LOAD_DEBUG_SHIFT )
1470 | (pGuestFeatures->fVmxIa32eModeGuest << VMX_BF_ENTRY_CTLS_IA32E_MODE_GUEST_SHIFT)
1471 | (pGuestFeatures->fVmxEntryLoadEferMsr << VMX_BF_ENTRY_CTLS_LOAD_EFER_MSR_SHIFT )
1472 | (pGuestFeatures->fVmxEntryLoadPatMsr << VMX_BF_ENTRY_CTLS_LOAD_PAT_MSR_SHIFT );
1473 uint32_t const fAllowed0 = VMX_ENTRY_CTLS_DEFAULT1;
1474 uint32_t const fAllowed1 = fFeatures | VMX_ENTRY_CTLS_DEFAULT1;
1475 AssertMsg((fAllowed0 & fAllowed1) == fAllowed0, ("fAllowed0=%#RX32 fAllowed0=%#RX32 fFeatures=%#RX32\n", fAllowed0,
1476 fAllowed1, fFeatures));
1477 pGuestVmxMsrs->EntryCtls.u = RT_MAKE_U64(fAllowed0, fAllowed1);
1478
1479 /* True VM-entry controls. */
1480 if (fTrueVmxMsrs)
1481 {
1482 /* VMX_ENTRY_CTLS_DEFAULT1 contains MB1 reserved bits but the following are not really reserved */
1483 uint32_t const fTrueAllowed0 = VMX_ENTRY_CTLS_DEFAULT1 & ~( VMX_BF_ENTRY_CTLS_LOAD_DEBUG_MASK
1484 | VMX_BF_ENTRY_CTLS_IA32E_MODE_GUEST_MASK
1485 | VMX_BF_ENTRY_CTLS_ENTRY_SMM_MASK
1486 | VMX_BF_ENTRY_CTLS_DEACTIVATE_DUAL_MON_MASK);
1487 uint32_t const fTrueAllowed1 = fFeatures | fTrueAllowed0;
1488 pGuestVmxMsrs->TrueEntryCtls.u = RT_MAKE_U64(fTrueAllowed0, fTrueAllowed1);
1489 }
1490 }
1491
1492 /* Miscellaneous data. */
1493 {
1494 uint64_t const uHostMsr = fIsNstGstHwExecAllowed ? pHostVmxMsrs->u64Misc : 0;
1495
1496 uint8_t const cMaxMsrs = RT_MIN(RT_BF_GET(uHostMsr, VMX_BF_MISC_MAX_MSRS), VMX_V_AUTOMSR_COUNT_MAX);
1497 uint8_t const fActivityState = RT_BF_GET(uHostMsr, VMX_BF_MISC_ACTIVITY_STATES) & VMX_V_GUEST_ACTIVITY_STATE_MASK;
1498 pGuestVmxMsrs->u64Misc = RT_BF_MAKE(VMX_BF_MISC_PREEMPT_TIMER_TSC, VMX_V_PREEMPT_TIMER_SHIFT )
1499 | RT_BF_MAKE(VMX_BF_MISC_EXIT_SAVE_EFER_LMA, pGuestFeatures->fVmxExitSaveEferLma )
1500 | RT_BF_MAKE(VMX_BF_MISC_ACTIVITY_STATES, fActivityState )
1501 | RT_BF_MAKE(VMX_BF_MISC_INTEL_PT, pGuestFeatures->fVmxPt )
1502 | RT_BF_MAKE(VMX_BF_MISC_SMM_READ_SMBASE_MSR, 0 )
1503 | RT_BF_MAKE(VMX_BF_MISC_CR3_TARGET, VMX_V_CR3_TARGET_COUNT )
1504 | RT_BF_MAKE(VMX_BF_MISC_MAX_MSRS, cMaxMsrs )
1505 | RT_BF_MAKE(VMX_BF_MISC_VMXOFF_BLOCK_SMI, 0 )
1506 | RT_BF_MAKE(VMX_BF_MISC_VMWRITE_ALL, pGuestFeatures->fVmxVmwriteAll )
1507 | RT_BF_MAKE(VMX_BF_MISC_ENTRY_INJECT_SOFT_INT, pGuestFeatures->fVmxEntryInjectSoftInt)
1508 | RT_BF_MAKE(VMX_BF_MISC_MSEG_ID, VMX_V_MSEG_REV_ID );
1509 }
1510
1511 /* CR0 Fixed-0 (we report this fixed value regardless of whether UX is supported as it does on real hardware). */
1512 pGuestVmxMsrs->u64Cr0Fixed0 = VMX_V_CR0_FIXED0;
1513
1514 /* CR0 Fixed-1. */
1515 {
1516 /*
1517 * All CPUs I've looked at so far report CR0 fixed-1 bits as 0xffffffff.
1518 * This is different from CR4 fixed-1 bits which are reported as per the
1519 * CPU features and/or micro-architecture/generation. Why? Ask Intel.
1520 */
1521 uint64_t const uHostMsr = fIsNstGstHwExecAllowed ? pHostVmxMsrs->u64Cr0Fixed1 : VMX_V_CR0_FIXED1;
1522 pGuestVmxMsrs->u64Cr0Fixed1 = uHostMsr | pGuestVmxMsrs->u64Cr0Fixed0; /* Make sure the CR0 MB1 bits are not clear. */
1523 }
1524
1525 /* CR4 Fixed-0. */
1526 pGuestVmxMsrs->u64Cr4Fixed0 = VMX_V_CR4_FIXED0;
1527
1528 /* CR4 Fixed-1. */
1529 {
1530 uint64_t const uHostMsr = fIsNstGstHwExecAllowed ? pHostVmxMsrs->u64Cr4Fixed1 : CPUMGetGuestCR4ValidMask(pVM);
1531 pGuestVmxMsrs->u64Cr4Fixed1 = uHostMsr | pGuestVmxMsrs->u64Cr4Fixed0; /* Make sure the CR4 MB1 bits are not clear. */
1532 }
1533
1534 /* VMCS Enumeration. */
1535 pGuestVmxMsrs->u64VmcsEnum = VMX_V_VMCS_MAX_INDEX << VMX_BF_VMCS_ENUM_HIGHEST_IDX_SHIFT;
1536
1537 /* VPID and EPT Capabilities. */
1538 if (pGuestFeatures->fVmxEpt)
1539 {
1540 /*
1541 * INVVPID instruction always causes a VM-exit unconditionally, so we are free to fake
1542 * and emulate any INVVPID flush type. However, it only makes sense to expose the types
1543 * when INVVPID instruction is supported just to be more compatible with guest
1544 * hypervisors that may make assumptions by only looking at this MSR even though they
1545 * are technically supposed to refer to VMX_PROC_CTLS2_VPID first.
1546 *
1547 * See Intel spec. 25.1.2 "Instructions That Cause VM Exits Unconditionally".
1548 * See Intel spec. 30.3 "VMX Instructions".
1549 */
1550 uint64_t const uHostMsr = fIsNstGstHwExecAllowed ? pHostVmxMsrs->u64EptVpidCaps : UINT64_MAX;
1551 uint8_t const fVpid = pGuestFeatures->fVmxVpid;
1552
1553 uint8_t const fExecOnly = RT_BF_GET(uHostMsr, VMX_BF_EPT_VPID_CAP_EXEC_ONLY);
1554 uint8_t const fPml4 = RT_BF_GET(uHostMsr, VMX_BF_EPT_VPID_CAP_PAGE_WALK_LENGTH_4);
1555 uint8_t const fMemTypeUc = RT_BF_GET(uHostMsr, VMX_BF_EPT_VPID_CAP_MEMTYPE_UC);
1556 uint8_t const fMemTypeWb = RT_BF_GET(uHostMsr, VMX_BF_EPT_VPID_CAP_MEMTYPE_WB);
1557 uint8_t const f2MPage = RT_BF_GET(uHostMsr, VMX_BF_EPT_VPID_CAP_PDE_2M);
1558 uint8_t const fInvept = RT_BF_GET(uHostMsr, VMX_BF_EPT_VPID_CAP_INVEPT);
1559 /** @todo Nested VMX: Support accessed/dirty bits, see @bugref{10092#c25}. */
1560 /* uint8_t const fAccessDirty = RT_BF_GET(uHostMsr, VMX_BF_EPT_VPID_CAP_ACCESS_DIRTY); */
1561 uint8_t const fEptSingle = RT_BF_GET(uHostMsr, VMX_BF_EPT_VPID_CAP_INVEPT_SINGLE_CTX);
1562 uint8_t const fEptAll = RT_BF_GET(uHostMsr, VMX_BF_EPT_VPID_CAP_INVEPT_ALL_CTX);
1563 uint8_t const fVpidIndiv = RT_BF_GET(uHostMsr, VMX_BF_EPT_VPID_CAP_INVVPID_INDIV_ADDR);
1564 uint8_t const fVpidSingle = RT_BF_GET(uHostMsr, VMX_BF_EPT_VPID_CAP_INVVPID_SINGLE_CTX);
1565 uint8_t const fVpidAll = RT_BF_GET(uHostMsr, VMX_BF_EPT_VPID_CAP_INVVPID_ALL_CTX);
1566 uint8_t const fVpidSingleGlobal = RT_BF_GET(uHostMsr, VMX_BF_EPT_VPID_CAP_INVVPID_SINGLE_CTX_RETAIN_GLOBALS);
1567 pGuestVmxMsrs->u64EptVpidCaps = RT_BF_MAKE(VMX_BF_EPT_VPID_CAP_EXEC_ONLY, fExecOnly)
1568 | RT_BF_MAKE(VMX_BF_EPT_VPID_CAP_PAGE_WALK_LENGTH_4, fPml4)
1569 | RT_BF_MAKE(VMX_BF_EPT_VPID_CAP_MEMTYPE_UC, fMemTypeUc)
1570 | RT_BF_MAKE(VMX_BF_EPT_VPID_CAP_MEMTYPE_WB, fMemTypeWb)
1571 | RT_BF_MAKE(VMX_BF_EPT_VPID_CAP_PDE_2M, f2MPage)
1572 //| RT_BF_MAKE(VMX_BF_EPT_VPID_CAP_PDPTE_1G, 0)
1573 | RT_BF_MAKE(VMX_BF_EPT_VPID_CAP_INVEPT, fInvept)
1574 //| RT_BF_MAKE(VMX_BF_EPT_VPID_CAP_ACCESS_DIRTY, 0)
1575 //| RT_BF_MAKE(VMX_BF_EPT_VPID_CAP_ADVEXITINFO_EPT_VIOLATION, 0)
1576 //| RT_BF_MAKE(VMX_BF_EPT_VPID_CAP_SUPER_SHW_STACK, 0)
1577 | RT_BF_MAKE(VMX_BF_EPT_VPID_CAP_INVEPT_SINGLE_CTX, fEptSingle)
1578 | RT_BF_MAKE(VMX_BF_EPT_VPID_CAP_INVEPT_ALL_CTX, fEptAll)
1579 | RT_BF_MAKE(VMX_BF_EPT_VPID_CAP_INVVPID, fVpid)
1580 | RT_BF_MAKE(VMX_BF_EPT_VPID_CAP_INVVPID_INDIV_ADDR, fVpid & fVpidIndiv)
1581 | RT_BF_MAKE(VMX_BF_EPT_VPID_CAP_INVVPID_SINGLE_CTX, fVpid & fVpidSingle)
1582 | RT_BF_MAKE(VMX_BF_EPT_VPID_CAP_INVVPID_ALL_CTX, fVpid & fVpidAll)
1583 | RT_BF_MAKE(VMX_BF_EPT_VPID_CAP_INVVPID_SINGLE_CTX_RETAIN_GLOBALS, fVpid & fVpidSingleGlobal);
1584 }
1585
1586 /* VM Functions. */
1587 if (pGuestFeatures->fVmxVmFunc)
1588 pGuestVmxMsrs->u64VmFunc = RT_BF_MAKE(VMX_BF_VMFUNC_EPTP_SWITCHING, 1);
1589}
1590
1591
1592/**
1593 * Checks whether the given guest CPU VMX features are compatible with the provided
1594 * base features.
1595 *
1596 * @returns @c true if compatible, @c false otherwise.
1597 * @param pVM The cross context VM structure.
1598 * @param pBase The base VMX CPU features.
1599 * @param pGst The guest VMX CPU features.
1600 *
1601 * @remarks Only VMX feature bits are examined.
1602 */
1603static bool cpumR3AreVmxCpuFeaturesCompatible(PVM pVM, PCCPUMFEATURES pBase, PCCPUMFEATURES pGst)
1604{
1605 if (!cpumR3IsHwAssistNstGstExecAllowed(pVM))
1606 return false;
1607
1608#define CPUM_VMX_FEAT_SHIFT(a_pFeat, a_FeatName, a_cShift) ((uint64_t)(a_pFeat->a_FeatName) << (a_cShift))
1609#define CPUM_VMX_MAKE_FEATURES_1(a_pFeat) ( CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxInsOutInfo , 0) \
1610 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxExtIntExit , 1) \
1611 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxNmiExit , 2) \
1612 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxVirtNmi , 3) \
1613 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxPreemptTimer , 4) \
1614 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxPostedInt , 5) \
1615 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxIntWindowExit , 6) \
1616 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxTscOffsetting , 7) \
1617 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxHltExit , 8) \
1618 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxInvlpgExit , 9) \
1619 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxMwaitExit , 10) \
1620 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxRdpmcExit , 12) \
1621 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxRdtscExit , 13) \
1622 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxCr3LoadExit , 14) \
1623 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxCr3StoreExit , 15) \
1624 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxTertiaryExecCtls , 16) \
1625 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxCr8LoadExit , 17) \
1626 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxCr8StoreExit , 18) \
1627 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxUseTprShadow , 19) \
1628 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxNmiWindowExit , 20) \
1629 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxMovDRxExit , 21) \
1630 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxUncondIoExit , 22) \
1631 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxUseIoBitmaps , 23) \
1632 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxMonitorTrapFlag , 24) \
1633 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxUseMsrBitmaps , 25) \
1634 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxMonitorExit , 26) \
1635 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxPauseExit , 27) \
1636 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxSecondaryExecCtls , 28) \
1637 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxVirtApicAccess , 29) \
1638 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxEpt , 30) \
1639 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxDescTableExit , 31) \
1640 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxRdtscp , 32) \
1641 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxVirtX2ApicMode , 33) \
1642 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxVpid , 34) \
1643 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxWbinvdExit , 35) \
1644 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxUnrestrictedGuest , 36) \
1645 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxApicRegVirt , 37) \
1646 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxVirtIntDelivery , 38) \
1647 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxPauseLoopExit , 39) \
1648 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxRdrandExit , 40) \
1649 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxInvpcid , 41) \
1650 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxVmFunc , 42) \
1651 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxVmcsShadowing , 43) \
1652 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxRdseedExit , 44) \
1653 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxPml , 45) \
1654 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxEptXcptVe , 46) \
1655 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxConcealVmxFromPt , 47) \
1656 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxXsavesXrstors , 48) \
1657 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxModeBasedExecuteEpt, 49) \
1658 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxSppEpt , 50) \
1659 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxPtEpt , 51) \
1660 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxUseTscScaling , 52) \
1661 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxUserWaitPause , 53) \
1662 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxEnclvExit , 54) \
1663 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxLoadIwKeyExit , 55) \
1664 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxEntryLoadDebugCtls , 56) \
1665 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxIa32eModeGuest , 57) \
1666 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxEntryLoadEferMsr , 58) \
1667 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxEntryLoadPatMsr , 59) \
1668 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxExitSaveDebugCtls , 60) \
1669 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxHostAddrSpaceSize , 61) \
1670 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxExitAckExtInt , 62) \
1671 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxExitSavePatMsr , 63))
1672
1673#define CPUM_VMX_MAKE_FEATURES_2(a_pFeat) ( CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxExitLoadPatMsr , 0) \
1674 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxExitSaveEferMsr , 1) \
1675 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxExitLoadEferMsr , 2) \
1676 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxSavePreemptTimer , 3) \
1677 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxExitSaveEferLma , 4) \
1678 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxPt , 5) \
1679 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxVmwriteAll , 6) \
1680 | CPUM_VMX_FEAT_SHIFT(a_pFeat, fVmxEntryInjectSoftInt , 7))
1681
1682 /* Check first set of feature bits. */
1683 {
1684 uint64_t const fBase = CPUM_VMX_MAKE_FEATURES_1(pBase);
1685 uint64_t const fGst = CPUM_VMX_MAKE_FEATURES_1(pGst);
1686 if ((fBase | fGst) != fBase)
1687 {
1688 uint64_t const fDiff = fBase ^ fGst;
1689 LogRel(("CPUM: VMX features (1) now exposed to the guest are incompatible with those from the saved state. fBase=%#RX64 fGst=%#RX64 fDiff=%#RX64\n",
1690 fBase, fGst, fDiff));
1691 return false;
1692 }
1693 }
1694
1695 /* Check second set of feature bits. */
1696 {
1697 uint64_t const fBase = CPUM_VMX_MAKE_FEATURES_2(pBase);
1698 uint64_t const fGst = CPUM_VMX_MAKE_FEATURES_2(pGst);
1699 if ((fBase | fGst) != fBase)
1700 {
1701 uint64_t const fDiff = fBase ^ fGst;
1702 LogRel(("CPUM: VMX features (2) now exposed to the guest are incompatible with those from the saved state. fBase=%#RX64 fGst=%#RX64 fDiff=%#RX64\n",
1703 fBase, fGst, fDiff));
1704 return false;
1705 }
1706 }
1707#undef CPUM_VMX_FEAT_SHIFT
1708#undef CPUM_VMX_MAKE_FEATURES_1
1709#undef CPUM_VMX_MAKE_FEATURES_2
1710
1711 return true;
1712}
1713
1714
1715/**
1716 * Initializes VMX guest features and MSRs.
1717 *
1718 * @param pVM The cross context VM structure.
1719 * @param pHostVmxMsrs The host VMX MSRs. Pass NULL when fully emulating VMX
1720 * and no hardware-assisted nested-guest execution is
1721 * possible for this VM.
1722 * @param pGuestVmxMsrs Where to store the initialized guest VMX MSRs.
1723 */
1724void cpumR3InitVmxGuestFeaturesAndMsrs(PVM pVM, PCVMXMSRS pHostVmxMsrs, PVMXMSRS pGuestVmxMsrs)
1725{
1726 Assert(pVM);
1727 Assert(pGuestVmxMsrs);
1728
1729 /*
1730 * While it would be nice to check this earlier while initializing
1731 * fNestedVmxEpt but we would not have enumearted host features then, so do
1732 * it at least now.
1733 */
1734 /** @todo r=bird: Why don't we just ditch the fNestedVmxEpt and
1735 * fNestedVmxUnrestrictedGuest state members and read the CFGM stuff
1736 * here? Neither of them have any purpose beyond keeping the two value
1737 * read in cpumR3CpuIdReadConfig for use here. They aren't even
1738 * necessarily correct after the feature merging has taken place. */
1739 if (pVM->cpum.s.fNestedVmxEpt)
1740 {
1741 const char *pszWhy = NULL;
1742 if (!VM_IS_HM_ENABLED(pVM) && !VM_IS_EXEC_ENGINE_IEM(pVM))
1743 pszWhy = "execution engine is neither HM nor IEM";
1744 else if (VM_IS_HM_ENABLED(pVM) && !HMIsNestedPagingActive(pVM))
1745 pszWhy = "nested paging is not enabled for the VM or it is not supported by the host";
1746 else if (VM_IS_HM_ENABLED(pVM) && !pVM->cpum.s.HostFeatures.fNoExecute)
1747 pszWhy = "NX is not available on the host";
1748 if (pszWhy)
1749 {
1750 LogRel(("CPUM: Warning! EPT not exposed to the guest because %s.\n", pszWhy));
1751 pVM->cpum.s.fNestedVmxEpt = false;
1752 }
1753 }
1754 if ( pVM->cpum.s.fNestedVmxUnrestrictedGuest
1755 && !pVM->cpum.s.fNestedVmxEpt)
1756 {
1757 LogRel(("CPUM: Warning! Can't expose \"Unrestricted Guest\" to the guest when EPT is not exposed!\n"));
1758 pVM->cpum.s.fNestedVmxUnrestrictedGuest = false;
1759 }
1760
1761 /*
1762 * Initialize the set of VMX features we emulate.
1763 *
1764 * Note! Some bits might be reported as 1 always if they fall under the
1765 * default1 class bits (e.g. fVmxEntryLoadDebugCtls), see @bugref{9180#c5}.
1766 */
1767 CPUMFEATURES EmuFeat;
1768 RT_ZERO(EmuFeat);
1769 EmuFeat.fVmx = 1;
1770 EmuFeat.fVmxInsOutInfo = 1;
1771 EmuFeat.fVmxExtIntExit = 1;
1772 EmuFeat.fVmxNmiExit = 1;
1773 EmuFeat.fVmxVirtNmi = 1;
1774 EmuFeat.fVmxPreemptTimer = pVM->cpum.s.fNestedVmxPreemptTimer;
1775 EmuFeat.fVmxPostedInt = 0;
1776 EmuFeat.fVmxIntWindowExit = 1;
1777 EmuFeat.fVmxTscOffsetting = 1;
1778 EmuFeat.fVmxHltExit = 1;
1779 EmuFeat.fVmxInvlpgExit = 1;
1780 EmuFeat.fVmxMwaitExit = 1;
1781 EmuFeat.fVmxRdpmcExit = 1;
1782 EmuFeat.fVmxRdtscExit = 1;
1783 EmuFeat.fVmxCr3LoadExit = 1;
1784 EmuFeat.fVmxCr3StoreExit = 1;
1785 EmuFeat.fVmxTertiaryExecCtls = 0;
1786 EmuFeat.fVmxCr8LoadExit = 1;
1787 EmuFeat.fVmxCr8StoreExit = 1;
1788 EmuFeat.fVmxUseTprShadow = 1;
1789 EmuFeat.fVmxNmiWindowExit = 0;
1790 EmuFeat.fVmxMovDRxExit = 1;
1791 EmuFeat.fVmxUncondIoExit = 1;
1792 EmuFeat.fVmxUseIoBitmaps = 1;
1793 EmuFeat.fVmxMonitorTrapFlag = 0;
1794 EmuFeat.fVmxUseMsrBitmaps = 1;
1795 EmuFeat.fVmxMonitorExit = 1;
1796 EmuFeat.fVmxPauseExit = 1;
1797 EmuFeat.fVmxSecondaryExecCtls = 1;
1798 EmuFeat.fVmxVirtApicAccess = 1;
1799 EmuFeat.fVmxEpt = pVM->cpum.s.fNestedVmxEpt;
1800 EmuFeat.fVmxDescTableExit = 1;
1801 EmuFeat.fVmxRdtscp = 1;
1802 EmuFeat.fVmxVirtX2ApicMode = 0;
1803 EmuFeat.fVmxVpid = 0; /** @todo Consider enabling this when EPT works. */
1804 EmuFeat.fVmxWbinvdExit = 1;
1805 EmuFeat.fVmxUnrestrictedGuest = pVM->cpum.s.fNestedVmxUnrestrictedGuest;
1806 EmuFeat.fVmxApicRegVirt = 0;
1807 EmuFeat.fVmxVirtIntDelivery = 0;
1808 EmuFeat.fVmxPauseLoopExit = 0;
1809 EmuFeat.fVmxRdrandExit = 0;
1810 EmuFeat.fVmxInvpcid = 1;
1811 EmuFeat.fVmxVmFunc = 0;
1812 EmuFeat.fVmxVmcsShadowing = 0;
1813 EmuFeat.fVmxRdseedExit = 0;
1814 EmuFeat.fVmxPml = 0;
1815 EmuFeat.fVmxEptXcptVe = 0;
1816 EmuFeat.fVmxConcealVmxFromPt = 0;
1817 EmuFeat.fVmxXsavesXrstors = 0;
1818 EmuFeat.fVmxModeBasedExecuteEpt = 0;
1819 EmuFeat.fVmxSppEpt = 0;
1820 EmuFeat.fVmxPtEpt = 0;
1821 EmuFeat.fVmxUseTscScaling = 0;
1822 EmuFeat.fVmxUserWaitPause = 0;
1823 EmuFeat.fVmxEnclvExit = 0;
1824 EmuFeat.fVmxLoadIwKeyExit = 0;
1825 EmuFeat.fVmxEntryLoadDebugCtls = 1;
1826 EmuFeat.fVmxIa32eModeGuest = 1;
1827 EmuFeat.fVmxEntryLoadEferMsr = 1;
1828 EmuFeat.fVmxEntryLoadPatMsr = 0;
1829 EmuFeat.fVmxExitSaveDebugCtls = 1;
1830 EmuFeat.fVmxHostAddrSpaceSize = 1;
1831 EmuFeat.fVmxExitAckExtInt = 1;
1832 EmuFeat.fVmxExitSavePatMsr = 0;
1833 EmuFeat.fVmxExitLoadPatMsr = 0;
1834 EmuFeat.fVmxExitSaveEferMsr = 1;
1835 EmuFeat.fVmxExitLoadEferMsr = 1;
1836 EmuFeat.fVmxSavePreemptTimer = 0; /* Cannot be enabled if VMX-preemption timer is disabled. */
1837 EmuFeat.fVmxExitSaveEferLma = 1; /* Cannot be disabled if unrestricted guest is enabled. */
1838 EmuFeat.fVmxPt = 0;
1839 EmuFeat.fVmxVmwriteAll = 0; /** @todo NSTVMX: enable this when nested VMCS shadowing is enabled. */
1840 EmuFeat.fVmxEntryInjectSoftInt = 1;
1841
1842 /*
1843 * Merge guest features.
1844 *
1845 * When hardware-assisted VMX may be used, any feature we emulate must also be supported
1846 * by the hardware, hence we merge our emulated features with the host features below.
1847 */
1848 PCCPUMFEATURES pBaseFeat = cpumR3IsHwAssistNstGstExecAllowed(pVM) ? &pVM->cpum.s.HostFeatures : &EmuFeat;
1849 PCPUMFEATURES pGuestFeat = &pVM->cpum.s.GuestFeatures;
1850 Assert(pBaseFeat->fVmx);
1851 pGuestFeat->fVmxInsOutInfo = (pBaseFeat->fVmxInsOutInfo & EmuFeat.fVmxInsOutInfo );
1852 pGuestFeat->fVmxExtIntExit = (pBaseFeat->fVmxExtIntExit & EmuFeat.fVmxExtIntExit );
1853 pGuestFeat->fVmxNmiExit = (pBaseFeat->fVmxNmiExit & EmuFeat.fVmxNmiExit );
1854 pGuestFeat->fVmxVirtNmi = (pBaseFeat->fVmxVirtNmi & EmuFeat.fVmxVirtNmi );
1855 pGuestFeat->fVmxPreemptTimer = (pBaseFeat->fVmxPreemptTimer & EmuFeat.fVmxPreemptTimer );
1856 pGuestFeat->fVmxPostedInt = (pBaseFeat->fVmxPostedInt & EmuFeat.fVmxPostedInt );
1857 pGuestFeat->fVmxIntWindowExit = (pBaseFeat->fVmxIntWindowExit & EmuFeat.fVmxIntWindowExit );
1858 pGuestFeat->fVmxTscOffsetting = (pBaseFeat->fVmxTscOffsetting & EmuFeat.fVmxTscOffsetting );
1859 pGuestFeat->fVmxHltExit = (pBaseFeat->fVmxHltExit & EmuFeat.fVmxHltExit );
1860 pGuestFeat->fVmxInvlpgExit = (pBaseFeat->fVmxInvlpgExit & EmuFeat.fVmxInvlpgExit );
1861 pGuestFeat->fVmxMwaitExit = (pBaseFeat->fVmxMwaitExit & EmuFeat.fVmxMwaitExit );
1862 pGuestFeat->fVmxRdpmcExit = (pBaseFeat->fVmxRdpmcExit & EmuFeat.fVmxRdpmcExit );
1863 pGuestFeat->fVmxRdtscExit = (pBaseFeat->fVmxRdtscExit & EmuFeat.fVmxRdtscExit );
1864 pGuestFeat->fVmxCr3LoadExit = (pBaseFeat->fVmxCr3LoadExit & EmuFeat.fVmxCr3LoadExit );
1865 pGuestFeat->fVmxCr3StoreExit = (pBaseFeat->fVmxCr3StoreExit & EmuFeat.fVmxCr3StoreExit );
1866 pGuestFeat->fVmxTertiaryExecCtls = (pBaseFeat->fVmxTertiaryExecCtls & EmuFeat.fVmxTertiaryExecCtls );
1867 pGuestFeat->fVmxCr8LoadExit = (pBaseFeat->fVmxCr8LoadExit & EmuFeat.fVmxCr8LoadExit );
1868 pGuestFeat->fVmxCr8StoreExit = (pBaseFeat->fVmxCr8StoreExit & EmuFeat.fVmxCr8StoreExit );
1869 pGuestFeat->fVmxUseTprShadow = (pBaseFeat->fVmxUseTprShadow & EmuFeat.fVmxUseTprShadow );
1870 pGuestFeat->fVmxNmiWindowExit = (pBaseFeat->fVmxNmiWindowExit & EmuFeat.fVmxNmiWindowExit );
1871 pGuestFeat->fVmxMovDRxExit = (pBaseFeat->fVmxMovDRxExit & EmuFeat.fVmxMovDRxExit );
1872 pGuestFeat->fVmxUncondIoExit = (pBaseFeat->fVmxUncondIoExit & EmuFeat.fVmxUncondIoExit );
1873 pGuestFeat->fVmxUseIoBitmaps = (pBaseFeat->fVmxUseIoBitmaps & EmuFeat.fVmxUseIoBitmaps );
1874 pGuestFeat->fVmxMonitorTrapFlag = (pBaseFeat->fVmxMonitorTrapFlag & EmuFeat.fVmxMonitorTrapFlag );
1875 pGuestFeat->fVmxUseMsrBitmaps = (pBaseFeat->fVmxUseMsrBitmaps & EmuFeat.fVmxUseMsrBitmaps );
1876 pGuestFeat->fVmxMonitorExit = (pBaseFeat->fVmxMonitorExit & EmuFeat.fVmxMonitorExit );
1877 pGuestFeat->fVmxPauseExit = (pBaseFeat->fVmxPauseExit & EmuFeat.fVmxPauseExit );
1878 pGuestFeat->fVmxSecondaryExecCtls = (pBaseFeat->fVmxSecondaryExecCtls & EmuFeat.fVmxSecondaryExecCtls );
1879 pGuestFeat->fVmxVirtApicAccess = (pBaseFeat->fVmxVirtApicAccess & EmuFeat.fVmxVirtApicAccess );
1880 pGuestFeat->fVmxEpt = (pBaseFeat->fVmxEpt & EmuFeat.fVmxEpt );
1881 pGuestFeat->fVmxDescTableExit = (pBaseFeat->fVmxDescTableExit & EmuFeat.fVmxDescTableExit );
1882 pGuestFeat->fVmxRdtscp = (pBaseFeat->fVmxRdtscp & EmuFeat.fVmxRdtscp );
1883 pGuestFeat->fVmxVirtX2ApicMode = (pBaseFeat->fVmxVirtX2ApicMode & EmuFeat.fVmxVirtX2ApicMode );
1884 pGuestFeat->fVmxVpid = (pBaseFeat->fVmxVpid & EmuFeat.fVmxVpid );
1885 pGuestFeat->fVmxWbinvdExit = (pBaseFeat->fVmxWbinvdExit & EmuFeat.fVmxWbinvdExit );
1886 pGuestFeat->fVmxUnrestrictedGuest = (pBaseFeat->fVmxUnrestrictedGuest & EmuFeat.fVmxUnrestrictedGuest );
1887 pGuestFeat->fVmxApicRegVirt = (pBaseFeat->fVmxApicRegVirt & EmuFeat.fVmxApicRegVirt );
1888 pGuestFeat->fVmxVirtIntDelivery = (pBaseFeat->fVmxVirtIntDelivery & EmuFeat.fVmxVirtIntDelivery );
1889 pGuestFeat->fVmxPauseLoopExit = (pBaseFeat->fVmxPauseLoopExit & EmuFeat.fVmxPauseLoopExit );
1890 pGuestFeat->fVmxRdrandExit = (pBaseFeat->fVmxRdrandExit & EmuFeat.fVmxRdrandExit );
1891 pGuestFeat->fVmxInvpcid = (pBaseFeat->fVmxInvpcid & EmuFeat.fVmxInvpcid );
1892 pGuestFeat->fVmxVmFunc = (pBaseFeat->fVmxVmFunc & EmuFeat.fVmxVmFunc );
1893 pGuestFeat->fVmxVmcsShadowing = (pBaseFeat->fVmxVmcsShadowing & EmuFeat.fVmxVmcsShadowing );
1894 pGuestFeat->fVmxRdseedExit = (pBaseFeat->fVmxRdseedExit & EmuFeat.fVmxRdseedExit );
1895 pGuestFeat->fVmxPml = (pBaseFeat->fVmxPml & EmuFeat.fVmxPml );
1896 pGuestFeat->fVmxEptXcptVe = (pBaseFeat->fVmxEptXcptVe & EmuFeat.fVmxEptXcptVe );
1897 pGuestFeat->fVmxConcealVmxFromPt = (pBaseFeat->fVmxConcealVmxFromPt & EmuFeat.fVmxConcealVmxFromPt );
1898 pGuestFeat->fVmxXsavesXrstors = (pBaseFeat->fVmxXsavesXrstors & EmuFeat.fVmxXsavesXrstors );
1899 pGuestFeat->fVmxModeBasedExecuteEpt = (pBaseFeat->fVmxModeBasedExecuteEpt & EmuFeat.fVmxModeBasedExecuteEpt );
1900 pGuestFeat->fVmxSppEpt = (pBaseFeat->fVmxSppEpt & EmuFeat.fVmxSppEpt );
1901 pGuestFeat->fVmxPtEpt = (pBaseFeat->fVmxPtEpt & EmuFeat.fVmxPtEpt );
1902 pGuestFeat->fVmxUseTscScaling = (pBaseFeat->fVmxUseTscScaling & EmuFeat.fVmxUseTscScaling );
1903 pGuestFeat->fVmxUserWaitPause = (pBaseFeat->fVmxUserWaitPause & EmuFeat.fVmxUserWaitPause );
1904 pGuestFeat->fVmxEnclvExit = (pBaseFeat->fVmxEnclvExit & EmuFeat.fVmxEnclvExit );
1905 pGuestFeat->fVmxLoadIwKeyExit = (pBaseFeat->fVmxLoadIwKeyExit & EmuFeat.fVmxLoadIwKeyExit );
1906 pGuestFeat->fVmxEntryLoadDebugCtls = (pBaseFeat->fVmxEntryLoadDebugCtls & EmuFeat.fVmxEntryLoadDebugCtls );
1907 pGuestFeat->fVmxIa32eModeGuest = (pBaseFeat->fVmxIa32eModeGuest & EmuFeat.fVmxIa32eModeGuest );
1908 pGuestFeat->fVmxEntryLoadEferMsr = (pBaseFeat->fVmxEntryLoadEferMsr & EmuFeat.fVmxEntryLoadEferMsr );
1909 pGuestFeat->fVmxEntryLoadPatMsr = (pBaseFeat->fVmxEntryLoadPatMsr & EmuFeat.fVmxEntryLoadPatMsr );
1910 pGuestFeat->fVmxExitSaveDebugCtls = (pBaseFeat->fVmxExitSaveDebugCtls & EmuFeat.fVmxExitSaveDebugCtls );
1911 pGuestFeat->fVmxHostAddrSpaceSize = (pBaseFeat->fVmxHostAddrSpaceSize & EmuFeat.fVmxHostAddrSpaceSize );
1912 pGuestFeat->fVmxExitAckExtInt = (pBaseFeat->fVmxExitAckExtInt & EmuFeat.fVmxExitAckExtInt );
1913 pGuestFeat->fVmxExitSavePatMsr = (pBaseFeat->fVmxExitSavePatMsr & EmuFeat.fVmxExitSavePatMsr );
1914 pGuestFeat->fVmxExitLoadPatMsr = (pBaseFeat->fVmxExitLoadPatMsr & EmuFeat.fVmxExitLoadPatMsr );
1915 pGuestFeat->fVmxExitSaveEferMsr = (pBaseFeat->fVmxExitSaveEferMsr & EmuFeat.fVmxExitSaveEferMsr );
1916 pGuestFeat->fVmxExitLoadEferMsr = (pBaseFeat->fVmxExitLoadEferMsr & EmuFeat.fVmxExitLoadEferMsr );
1917 pGuestFeat->fVmxSavePreemptTimer = (pBaseFeat->fVmxSavePreemptTimer & EmuFeat.fVmxSavePreemptTimer );
1918 pGuestFeat->fVmxExitSaveEferLma = (pBaseFeat->fVmxExitSaveEferLma & EmuFeat.fVmxExitSaveEferLma );
1919 pGuestFeat->fVmxPt = (pBaseFeat->fVmxPt & EmuFeat.fVmxPt );
1920 pGuestFeat->fVmxVmwriteAll = (pBaseFeat->fVmxVmwriteAll & EmuFeat.fVmxVmwriteAll );
1921 pGuestFeat->fVmxEntryInjectSoftInt = (pBaseFeat->fVmxEntryInjectSoftInt & EmuFeat.fVmxEntryInjectSoftInt );
1922
1923#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
1924 /* Don't expose VMX preemption timer if host is subject to VMX-preemption timer erratum. */
1925 if ( pGuestFeat->fVmxPreemptTimer
1926 && HMIsSubjectToVmxPreemptTimerErratum())
1927 {
1928 LogRel(("CPUM: Warning! VMX-preemption timer not exposed to guest due to host CPU erratum.\n"));
1929 pGuestFeat->fVmxPreemptTimer = 0;
1930 pGuestFeat->fVmxSavePreemptTimer = 0;
1931 }
1932#endif
1933
1934 /* Sanity checking. */
1935 if (!pGuestFeat->fVmxSecondaryExecCtls)
1936 {
1937 Assert(!pGuestFeat->fVmxVirtApicAccess);
1938 Assert(!pGuestFeat->fVmxEpt);
1939 Assert(!pGuestFeat->fVmxDescTableExit);
1940 Assert(!pGuestFeat->fVmxRdtscp);
1941 Assert(!pGuestFeat->fVmxVirtX2ApicMode);
1942 Assert(!pGuestFeat->fVmxVpid);
1943 Assert(!pGuestFeat->fVmxWbinvdExit);
1944 Assert(!pGuestFeat->fVmxUnrestrictedGuest);
1945 Assert(!pGuestFeat->fVmxApicRegVirt);
1946 Assert(!pGuestFeat->fVmxVirtIntDelivery);
1947 Assert(!pGuestFeat->fVmxPauseLoopExit);
1948 Assert(!pGuestFeat->fVmxRdrandExit);
1949 Assert(!pGuestFeat->fVmxInvpcid);
1950 Assert(!pGuestFeat->fVmxVmFunc);
1951 Assert(!pGuestFeat->fVmxVmcsShadowing);
1952 Assert(!pGuestFeat->fVmxRdseedExit);
1953 Assert(!pGuestFeat->fVmxPml);
1954 Assert(!pGuestFeat->fVmxEptXcptVe);
1955 Assert(!pGuestFeat->fVmxConcealVmxFromPt);
1956 Assert(!pGuestFeat->fVmxXsavesXrstors);
1957 Assert(!pGuestFeat->fVmxModeBasedExecuteEpt);
1958 Assert(!pGuestFeat->fVmxSppEpt);
1959 Assert(!pGuestFeat->fVmxPtEpt);
1960 Assert(!pGuestFeat->fVmxUseTscScaling);
1961 Assert(!pGuestFeat->fVmxUserWaitPause);
1962 Assert(!pGuestFeat->fVmxEnclvExit);
1963 }
1964 else if (pGuestFeat->fVmxUnrestrictedGuest)
1965 {
1966 /* See footnote in Intel spec. 27.2 "Recording VM-Exit Information And Updating VM-entry Control Fields". */
1967 Assert(pGuestFeat->fVmxExitSaveEferLma);
1968 /* Unrestricted guest execution requires EPT. See Intel spec. 25.2.1.1 "VM-Execution Control Fields". */
1969 Assert(pGuestFeat->fVmxEpt);
1970 }
1971
1972 if (!pGuestFeat->fVmxTertiaryExecCtls)
1973 Assert(!pGuestFeat->fVmxLoadIwKeyExit);
1974
1975 /*
1976 * Finally initialize the VMX guest MSRs.
1977 */
1978 cpumR3InitVmxGuestMsrs(pVM, pHostVmxMsrs, pGuestFeat, pGuestVmxMsrs);
1979}
1980
1981
1982/**
1983 * Gets the host hardware-virtualization MSRs.
1984 *
1985 * @returns VBox status code.
1986 * @param pMsrs Where to store the MSRs.
1987 */
1988static int cpumR3GetHostHwvirtMsrs(PCPUMMSRS pMsrs)
1989{
1990 Assert(pMsrs);
1991
1992 uint32_t fCaps = 0;
1993 int rc = SUPR3QueryVTCaps(&fCaps);
1994 if (RT_SUCCESS(rc))
1995 {
1996 if (fCaps & (SUPVTCAPS_VT_X | SUPVTCAPS_AMD_V))
1997 {
1998 SUPHWVIRTMSRS HwvirtMsrs;
1999 rc = SUPR3GetHwvirtMsrs(&HwvirtMsrs, false /* fForceRequery */);
2000 if (RT_SUCCESS(rc))
2001 {
2002 if (fCaps & SUPVTCAPS_VT_X)
2003 HMGetVmxMsrsFromHwvirtMsrs(&HwvirtMsrs, &pMsrs->hwvirt.vmx);
2004 else
2005 HMGetSvmMsrsFromHwvirtMsrs(&HwvirtMsrs, &pMsrs->hwvirt.svm);
2006 return VINF_SUCCESS;
2007 }
2008
2009 LogRel(("CPUM: Querying hardware-virtualization MSRs failed. rc=%Rrc\n", rc));
2010 return rc;
2011 }
2012
2013 LogRel(("CPUM: Querying hardware-virtualization capability succeeded but did not find VT-x or AMD-V\n"));
2014 return VERR_INTERNAL_ERROR_5;
2015 }
2016 LogRel(("CPUM: No hardware-virtualization capability detected\n"));
2017 return VINF_SUCCESS;
2018}
2019
2020
2021/**
2022 * @callback_method_impl{FNTMTIMERINT,
2023 * Callback that fires when the nested VMX-preemption timer expired.}
2024 */
2025static DECLCALLBACK(void) cpumR3VmxPreemptTimerCallback(PVM pVM, TMTIMERHANDLE hTimer, void *pvUser)
2026{
2027 RT_NOREF(pVM, hTimer);
2028 PVMCPU pVCpu = (PVMCPUR3)pvUser;
2029 AssertPtr(pVCpu);
2030 VMCPU_FF_SET(pVCpu, VMCPU_FF_VMX_PREEMPT_TIMER);
2031}
2032
2033
2034/**
2035 * Initializes the CPUM.
2036 *
2037 * @returns VBox status code.
2038 * @param pVM The cross context VM structure.
2039 */
2040VMMR3DECL(int) CPUMR3Init(PVM pVM)
2041{
2042 LogFlow(("CPUMR3Init\n"));
2043
2044 /*
2045 * Assert alignment, sizes and tables.
2046 */
2047 AssertCompileMemberAlignment(VM, cpum.s, 32);
2048 AssertCompile(sizeof(pVM->cpum.s) <= sizeof(pVM->cpum.padding));
2049 AssertCompileSizeAlignment(CPUMCTX, 64);
2050 AssertCompileSizeAlignment(CPUMCTXMSRS, 64);
2051 AssertCompileSizeAlignment(CPUMHOSTCTX, 64);
2052 AssertCompileMemberAlignment(VM, cpum, 64);
2053 AssertCompileMemberAlignment(VMCPU, cpum.s, 64);
2054#ifdef VBOX_STRICT
2055 int rc2 = cpumR3MsrStrictInitChecks();
2056 AssertRCReturn(rc2, rc2);
2057#endif
2058
2059 /*
2060 * Gather info about the host CPU.
2061 */
2062#if defined(RT_ARCH_X86) || defined(RT_ARCH_AMD64)
2063 if (!ASMHasCpuId())
2064 {
2065 LogRel(("The CPU doesn't support CPUID!\n"));
2066 return VERR_UNSUPPORTED_CPU;
2067 }
2068
2069 pVM->cpum.s.fHostMxCsrMask = CPUMR3DeterminHostMxCsrMask();
2070#endif
2071
2072 CPUMMSRS HostMsrs;
2073 RT_ZERO(HostMsrs);
2074 int rc = cpumR3GetHostHwvirtMsrs(&HostMsrs);
2075 AssertLogRelRCReturn(rc, rc);
2076
2077#if defined(RT_ARCH_X86) || defined(RT_ARCH_AMD64)
2078 /* Use the host features detected by CPUMR0ModuleInit if available. */
2079 if (pVM->cpum.s.HostFeatures.enmCpuVendor != CPUMCPUVENDOR_INVALID)
2080 g_CpumHostFeatures.s = pVM->cpum.s.HostFeatures;
2081 else
2082 {
2083 PCPUMCPUIDLEAF paLeaves;
2084 uint32_t cLeaves;
2085 rc = CPUMCpuIdCollectLeavesX86(&paLeaves, &cLeaves);
2086 AssertLogRelRCReturn(rc, rc);
2087
2088 rc = cpumCpuIdExplodeFeaturesX86(paLeaves, cLeaves, &HostMsrs, &g_CpumHostFeatures.s);
2089 RTMemFree(paLeaves);
2090 AssertLogRelRCReturn(rc, rc);
2091 }
2092 pVM->cpum.s.HostFeatures = g_CpumHostFeatures.s;
2093 pVM->cpum.s.GuestFeatures.enmCpuVendor = pVM->cpum.s.HostFeatures.enmCpuVendor;
2094#endif
2095
2096 /*
2097 * Check that the CPU supports the minimum features we require.
2098 */
2099#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
2100 if (!pVM->cpum.s.HostFeatures.fFxSaveRstor)
2101 return VMSetError(pVM, VERR_UNSUPPORTED_CPU, RT_SRC_POS, "Host CPU does not support the FXSAVE/FXRSTOR instruction.");
2102 if (!pVM->cpum.s.HostFeatures.fMmx)
2103 return VMSetError(pVM, VERR_UNSUPPORTED_CPU, RT_SRC_POS, "Host CPU does not support MMX.");
2104 if (!pVM->cpum.s.HostFeatures.fTsc)
2105 return VMSetError(pVM, VERR_UNSUPPORTED_CPU, RT_SRC_POS, "Host CPU does not support RDTSC.");
2106#endif
2107
2108 /*
2109 * Setup the CR4 AND and OR masks used in the raw-mode switcher.
2110 */
2111 pVM->cpum.s.CR4.AndMask = X86_CR4_OSXMMEEXCPT | X86_CR4_PVI | X86_CR4_VME;
2112 pVM->cpum.s.CR4.OrMask = X86_CR4_OSFXSR;
2113
2114 /*
2115 * Figure out which XSAVE/XRSTOR features are available on the host.
2116 */
2117 uint64_t fXcr0Host = 0;
2118 uint64_t fXStateHostMask = 0;
2119#if defined(RT_ARCH_X86) || defined(RT_ARCH_AMD64)
2120 if ( pVM->cpum.s.HostFeatures.fXSaveRstor
2121 && pVM->cpum.s.HostFeatures.fOpSysXSaveRstor)
2122 {
2123 fXStateHostMask = fXcr0Host = ASMGetXcr0();
2124 fXStateHostMask &= XSAVE_C_X87 | XSAVE_C_SSE | XSAVE_C_YMM | XSAVE_C_OPMASK | XSAVE_C_ZMM_HI256 | XSAVE_C_ZMM_16HI;
2125 AssertLogRelMsgStmt((fXStateHostMask & (XSAVE_C_X87 | XSAVE_C_SSE)) == (XSAVE_C_X87 | XSAVE_C_SSE),
2126 ("%#llx\n", fXStateHostMask), fXStateHostMask = 0);
2127 }
2128#endif
2129 pVM->cpum.s.fXStateHostMask = fXStateHostMask;
2130 LogRel(("CPUM: fXStateHostMask=%#llx; initial: %#llx; host XCR0=%#llx\n",
2131 pVM->cpum.s.fXStateHostMask, fXStateHostMask, fXcr0Host));
2132
2133 /*
2134 * Initialize the host XSAVE/XRSTOR mask.
2135 */
2136#if defined(RT_ARCH_X86) || defined(RT_ARCH_AMD64)
2137 uint32_t cbMaxXState = pVM->cpum.s.HostFeatures.cbMaxExtendedState;
2138 cbMaxXState = RT_ALIGN(cbMaxXState, 128);
2139 AssertLogRelReturn( pVM->cpum.s.HostFeatures.cbMaxExtendedState >= sizeof(X86FXSTATE)
2140 && pVM->cpum.s.HostFeatures.cbMaxExtendedState <= sizeof(pVM->apCpusR3[0]->cpum.s.Host.XState)
2141 && pVM->cpum.s.HostFeatures.cbMaxExtendedState <= sizeof(pVM->apCpusR3[0]->cpum.s.Guest.XState)
2142 , VERR_CPUM_IPE_2);
2143#endif
2144
2145 for (VMCPUID i = 0; i < pVM->cCpus; i++)
2146 {
2147 PVMCPU pVCpu = pVM->apCpusR3[i];
2148
2149 pVCpu->cpum.s.Host.fXStateMask = fXStateHostMask;
2150 pVCpu->cpum.s.hNestedVmxPreemptTimer = NIL_TMTIMERHANDLE;
2151 }
2152
2153 /*
2154 * Register saved state data item.
2155 */
2156 rc = SSMR3RegisterInternal(pVM, "cpum", 1, CPUM_SAVED_STATE_VERSION, sizeof(CPUM),
2157 NULL, cpumR3LiveExec, NULL,
2158 NULL, cpumR3SaveExec, NULL,
2159 cpumR3LoadPrep, cpumR3LoadExec, cpumR3LoadDone);
2160 if (RT_FAILURE(rc))
2161 return rc;
2162
2163 /*
2164 * Register info handlers and registers with the debugger facility.
2165 */
2166 DBGFR3InfoRegisterInternalEx(pVM, "cpum", "Displays the all the cpu states.",
2167 &cpumR3InfoAll, DBGFINFO_FLAGS_ALL_EMTS);
2168 DBGFR3InfoRegisterInternalEx(pVM, "cpumguest", "Displays the guest cpu state.",
2169 &cpumR3InfoGuest, DBGFINFO_FLAGS_ALL_EMTS);
2170 DBGFR3InfoRegisterInternalEx(pVM, "cpumguesthwvirt", "Displays the guest hwvirt. cpu state.",
2171 &cpumR3InfoGuestHwvirt, DBGFINFO_FLAGS_ALL_EMTS);
2172 DBGFR3InfoRegisterInternalEx(pVM, "cpumhyper", "Displays the hypervisor cpu state.",
2173 &cpumR3InfoHyper, DBGFINFO_FLAGS_ALL_EMTS);
2174 DBGFR3InfoRegisterInternalEx(pVM, "cpumhost", "Displays the host cpu state.",
2175 &cpumR3InfoHost, DBGFINFO_FLAGS_ALL_EMTS);
2176 DBGFR3InfoRegisterInternalEx(pVM, "cpumguestinstr", "Displays the current guest instruction.",
2177 &cpumR3InfoGuestInstr, DBGFINFO_FLAGS_ALL_EMTS);
2178 DBGFR3InfoRegisterInternal( pVM, "cpuid", "Displays the guest cpuid leaves.",
2179 &cpumR3CpuIdInfo);
2180 DBGFR3InfoRegisterInternal( pVM, "cpumvmxfeat", "Displays the host and guest VMX hwvirt. features.",
2181 &cpumR3InfoVmxFeatures);
2182
2183 rc = cpumR3DbgInit(pVM);
2184 if (RT_FAILURE(rc))
2185 return rc;
2186
2187#if defined(RT_ARCH_X86) || defined(RT_ARCH_AMD64)
2188 /*
2189 * Check if we need to workaround partial/leaky FPU handling.
2190 */
2191 cpumR3CheckLeakyFpu(pVM);
2192#endif
2193
2194 /*
2195 * Initialize the Guest CPUID and MSR states.
2196 */
2197 rc = cpumR3InitCpuIdAndMsrs(pVM, &HostMsrs);
2198 if (RT_FAILURE(rc))
2199 return rc;
2200
2201 /*
2202 * Init the VMX/SVM state.
2203 *
2204 * This must be done after initializing CPUID/MSR features as we access the
2205 * the VMX/SVM guest features below.
2206 *
2207 * In the case of nested VT-x, we also need to create the per-VCPU
2208 * VMX preemption timers.
2209 */
2210 if (pVM->cpum.s.GuestFeatures.fVmx)
2211 cpumR3InitVmxHwVirtState(pVM);
2212 else if (pVM->cpum.s.GuestFeatures.fSvm)
2213 cpumR3InitSvmHwVirtState(pVM);
2214 else
2215 Assert(pVM->apCpusR3[0]->cpum.s.Guest.hwvirt.enmHwvirt == CPUMHWVIRT_NONE);
2216
2217 CPUMR3Reset(pVM);
2218 return VINF_SUCCESS;
2219}
2220
2221
2222/**
2223 * Applies relocations to data and code managed by this
2224 * component. This function will be called at init and
2225 * whenever the VMM need to relocate it self inside the GC.
2226 *
2227 * The CPUM will update the addresses used by the switcher.
2228 *
2229 * @param pVM The cross context VM structure.
2230 */
2231VMMR3DECL(void) CPUMR3Relocate(PVM pVM)
2232{
2233 RT_NOREF(pVM);
2234}
2235
2236
2237/**
2238 * Terminates the CPUM.
2239 *
2240 * Termination means cleaning up and freeing all resources,
2241 * the VM it self is at this point powered off or suspended.
2242 *
2243 * @returns VBox status code.
2244 * @param pVM The cross context VM structure.
2245 */
2246VMMR3DECL(int) CPUMR3Term(PVM pVM)
2247{
2248#ifdef VBOX_WITH_CRASHDUMP_MAGIC
2249 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
2250 {
2251 PVMCPU pVCpu = pVM->apCpusR3[idCpu];
2252 memset(pVCpu->cpum.s.aMagic, 0, sizeof(pVCpu->cpum.s.aMagic));
2253 pVCpu->cpum.s.uMagic = 0;
2254 pvCpu->cpum.s.Guest.dr[5] = 0;
2255 }
2256#endif
2257
2258 if (pVM->cpum.s.GuestFeatures.fVmx)
2259 {
2260 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
2261 {
2262 PVMCPU pVCpu = pVM->apCpusR3[idCpu];
2263 if (pVCpu->cpum.s.hNestedVmxPreemptTimer != NIL_TMTIMERHANDLE)
2264 {
2265 int rc = TMR3TimerDestroy(pVM, pVCpu->cpum.s.hNestedVmxPreemptTimer); AssertRC(rc);
2266 pVCpu->cpum.s.hNestedVmxPreemptTimer = NIL_TMTIMERHANDLE;
2267 }
2268 }
2269 }
2270 return VINF_SUCCESS;
2271}
2272
2273
2274/**
2275 * Resets a virtual CPU.
2276 *
2277 * Used by CPUMR3Reset and CPU hot plugging.
2278 *
2279 * @param pVM The cross context VM structure.
2280 * @param pVCpu The cross context virtual CPU structure of the CPU that is
2281 * being reset. This may differ from the current EMT.
2282 */
2283VMMR3DECL(void) CPUMR3ResetCpu(PVM pVM, PVMCPU pVCpu)
2284{
2285 /** @todo anything different for VCPU > 0? */
2286 PCPUMCTX pCtx = &pVCpu->cpum.s.Guest;
2287
2288 /*
2289 * Initialize everything to ZERO first.
2290 */
2291 uint32_t fUseFlags = pVCpu->cpum.s.fUseFlags & ~CPUM_USED_FPU_SINCE_REM;
2292
2293 RT_BZERO(pCtx, RT_UOFFSETOF(CPUMCTX, aoffXState));
2294
2295 pVCpu->cpum.s.fUseFlags = fUseFlags;
2296
2297 pCtx->cr0 = X86_CR0_CD | X86_CR0_NW | X86_CR0_ET; //0x60000010
2298 pCtx->eip = 0x0000fff0;
2299 pCtx->edx = 0x00000600; /* P6 processor */
2300 pCtx->eflags.Bits.u1Reserved0 = 1;
2301
2302 pCtx->cs.Sel = 0xf000;
2303 pCtx->cs.ValidSel = 0xf000;
2304 pCtx->cs.fFlags = CPUMSELREG_FLAGS_VALID;
2305 pCtx->cs.u64Base = UINT64_C(0xffff0000);
2306 pCtx->cs.u32Limit = 0x0000ffff;
2307 pCtx->cs.Attr.n.u1DescType = 1; /* code/data segment */
2308 pCtx->cs.Attr.n.u1Present = 1;
2309 pCtx->cs.Attr.n.u4Type = X86_SEL_TYPE_ER_ACC;
2310
2311 pCtx->ds.fFlags = CPUMSELREG_FLAGS_VALID;
2312 pCtx->ds.u32Limit = 0x0000ffff;
2313 pCtx->ds.Attr.n.u1DescType = 1; /* code/data segment */
2314 pCtx->ds.Attr.n.u1Present = 1;
2315 pCtx->ds.Attr.n.u4Type = X86_SEL_TYPE_RW_ACC;
2316
2317 pCtx->es.fFlags = CPUMSELREG_FLAGS_VALID;
2318 pCtx->es.u32Limit = 0x0000ffff;
2319 pCtx->es.Attr.n.u1DescType = 1; /* code/data segment */
2320 pCtx->es.Attr.n.u1Present = 1;
2321 pCtx->es.Attr.n.u4Type = X86_SEL_TYPE_RW_ACC;
2322
2323 pCtx->fs.fFlags = CPUMSELREG_FLAGS_VALID;
2324 pCtx->fs.u32Limit = 0x0000ffff;
2325 pCtx->fs.Attr.n.u1DescType = 1; /* code/data segment */
2326 pCtx->fs.Attr.n.u1Present = 1;
2327 pCtx->fs.Attr.n.u4Type = X86_SEL_TYPE_RW_ACC;
2328
2329 pCtx->gs.fFlags = CPUMSELREG_FLAGS_VALID;
2330 pCtx->gs.u32Limit = 0x0000ffff;
2331 pCtx->gs.Attr.n.u1DescType = 1; /* code/data segment */
2332 pCtx->gs.Attr.n.u1Present = 1;
2333 pCtx->gs.Attr.n.u4Type = X86_SEL_TYPE_RW_ACC;
2334
2335 pCtx->ss.fFlags = CPUMSELREG_FLAGS_VALID;
2336 pCtx->ss.u32Limit = 0x0000ffff;
2337 pCtx->ss.Attr.n.u1Present = 1;
2338 pCtx->ss.Attr.n.u1DescType = 1; /* code/data segment */
2339 pCtx->ss.Attr.n.u4Type = X86_SEL_TYPE_RW_ACC;
2340
2341 pCtx->idtr.cbIdt = 0xffff;
2342 pCtx->gdtr.cbGdt = 0xffff;
2343
2344 pCtx->ldtr.fFlags = CPUMSELREG_FLAGS_VALID;
2345 pCtx->ldtr.u32Limit = 0xffff;
2346 pCtx->ldtr.Attr.n.u1Present = 1;
2347 pCtx->ldtr.Attr.n.u4Type = X86_SEL_TYPE_SYS_LDT;
2348
2349 pCtx->tr.fFlags = CPUMSELREG_FLAGS_VALID;
2350 pCtx->tr.u32Limit = 0xffff;
2351 pCtx->tr.Attr.n.u1Present = 1;
2352 pCtx->tr.Attr.n.u4Type = X86_SEL_TYPE_SYS_386_TSS_BUSY; /* Deduction, not properly documented by Intel. */
2353
2354 pCtx->dr[6] = X86_DR6_INIT_VAL;
2355 pCtx->dr[7] = X86_DR7_INIT_VAL;
2356
2357 PX86FXSTATE pFpuCtx = &pCtx->XState.x87;
2358 pFpuCtx->FTW = 0x00; /* All empty (abbridged tag reg edition). */
2359 pFpuCtx->FCW = 0x37f;
2360
2361 /* Intel 64 and IA-32 Architectures Software Developer's Manual Volume 3A, Table 8-1.
2362 IA-32 Processor States Following Power-up, Reset, or INIT */
2363 pFpuCtx->MXCSR = 0x1F80;
2364 pFpuCtx->MXCSR_MASK = pVM->cpum.s.GuestInfo.fMxCsrMask; /** @todo check if REM messes this up... */
2365
2366 pCtx->aXcr[0] = XSAVE_C_X87;
2367 if (pVM->cpum.s.HostFeatures.cbMaxExtendedState >= RT_UOFFSETOF(X86XSAVEAREA, Hdr))
2368 {
2369 /* The entire FXSAVE state needs loading when we switch to XSAVE/XRSTOR
2370 as we don't know what happened before. (Bother optimize later?) */
2371 pCtx->XState.Hdr.bmXState = XSAVE_C_X87 | XSAVE_C_SSE;
2372 }
2373
2374 /*
2375 * MSRs.
2376 */
2377 /* Init PAT MSR */
2378 pCtx->msrPAT = MSR_IA32_CR_PAT_INIT_VAL;
2379
2380 /* EFER MBZ; see AMD64 Architecture Programmer's Manual Volume 2: Table 14-1. Initial Processor State.
2381 * The Intel docs don't mention it. */
2382 Assert(!pCtx->msrEFER);
2383
2384 /* IA32_MISC_ENABLE - not entirely sure what the init/reset state really
2385 is supposed to be here, just trying provide useful/sensible values. */
2386 PCPUMMSRRANGE pRange = cpumLookupMsrRange(pVM, MSR_IA32_MISC_ENABLE);
2387 if (pRange)
2388 {
2389 pVCpu->cpum.s.GuestMsrs.msr.MiscEnable = MSR_IA32_MISC_ENABLE_BTS_UNAVAIL
2390 | MSR_IA32_MISC_ENABLE_PEBS_UNAVAIL
2391 | (pVM->cpum.s.GuestFeatures.fMonitorMWait ? MSR_IA32_MISC_ENABLE_MONITOR : 0)
2392 | MSR_IA32_MISC_ENABLE_FAST_STRINGS;
2393 pRange->fWrIgnMask |= MSR_IA32_MISC_ENABLE_BTS_UNAVAIL
2394 | MSR_IA32_MISC_ENABLE_PEBS_UNAVAIL;
2395 pRange->fWrGpMask &= ~pVCpu->cpum.s.GuestMsrs.msr.MiscEnable;
2396 }
2397
2398 /** @todo Wire IA32_MISC_ENABLE bit 22 to our NT 4 CPUID trick. */
2399
2400 /** @todo r=ramshankar: Currently broken for SMP as TMCpuTickSet() expects to be
2401 * called from each EMT while we're getting called by CPUMR3Reset()
2402 * iteratively on the same thread. Fix later. */
2403#if 0 /** @todo r=bird: This we will do in TM, not here. */
2404 /* TSC must be 0. Intel spec. Table 9-1. "IA-32 Processor States Following Power-up, Reset, or INIT." */
2405 CPUMSetGuestMsr(pVCpu, MSR_IA32_TSC, 0);
2406#endif
2407
2408
2409 /* C-state control. Guesses. */
2410 pVCpu->cpum.s.GuestMsrs.msr.PkgCStateCfgCtrl = 1 /*C1*/ | RT_BIT_32(25) | RT_BIT_32(26) | RT_BIT_32(27) | RT_BIT_32(28);
2411 /* For Nehalem+ and Atoms, the 0xE2 MSR (MSR_PKG_CST_CONFIG_CONTROL) is documented. For Core 2,
2412 * it's undocumented but exists as MSR_PMG_CST_CONFIG_CONTROL and has similar but not identical
2413 * functionality. The default value must be different due to incompatible write mask.
2414 */
2415 if (CPUMMICROARCH_IS_INTEL_CORE2(pVM->cpum.s.GuestFeatures.enmMicroarch))
2416 pVCpu->cpum.s.GuestMsrs.msr.PkgCStateCfgCtrl = 0x202a01; /* From Mac Pro Harpertown, unlocked. */
2417 else if (pVM->cpum.s.GuestFeatures.enmMicroarch == kCpumMicroarch_Intel_Core_Yonah)
2418 pVCpu->cpum.s.GuestMsrs.msr.PkgCStateCfgCtrl = 0x26740c; /* From MacBookPro1,1. */
2419
2420 /*
2421 * Hardware virtualization state.
2422 */
2423 CPUMSetGuestGif(pCtx, true);
2424 Assert(!pVM->cpum.s.GuestFeatures.fVmx || !pVM->cpum.s.GuestFeatures.fSvm); /* Paranoia. */
2425 if (pVM->cpum.s.GuestFeatures.fVmx)
2426 cpumR3ResetVmxHwVirtState(pVCpu);
2427 else if (pVM->cpum.s.GuestFeatures.fSvm)
2428 cpumR3ResetSvmHwVirtState(pVCpu);
2429}
2430
2431
2432/**
2433 * Resets the CPU.
2434 *
2435 * @returns VINF_SUCCESS.
2436 * @param pVM The cross context VM structure.
2437 */
2438VMMR3DECL(void) CPUMR3Reset(PVM pVM)
2439{
2440 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
2441 {
2442 PVMCPU pVCpu = pVM->apCpusR3[idCpu];
2443 CPUMR3ResetCpu(pVM, pVCpu);
2444
2445#ifdef VBOX_WITH_CRASHDUMP_MAGIC
2446
2447 /* Magic marker for searching in crash dumps. */
2448 strcpy((char *)pVCpu->.cpum.s.aMagic, "CPUMCPU Magic");
2449 pVCpu->cpum.s.uMagic = UINT64_C(0xDEADBEEFDEADBEEF);
2450 pVCpu->cpum.s.Guest->dr[5] = UINT64_C(0xDEADBEEFDEADBEEF);
2451#endif
2452 }
2453}
2454
2455
2456
2457
2458/**
2459 * Pass 0 live exec callback.
2460 *
2461 * @returns VINF_SSM_DONT_CALL_AGAIN.
2462 * @param pVM The cross context VM structure.
2463 * @param pSSM The saved state handle.
2464 * @param uPass The pass (0).
2465 */
2466static DECLCALLBACK(int) cpumR3LiveExec(PVM pVM, PSSMHANDLE pSSM, uint32_t uPass)
2467{
2468 AssertReturn(uPass == 0, VERR_SSM_UNEXPECTED_PASS);
2469 cpumR3SaveCpuId(pVM, pSSM);
2470 return VINF_SSM_DONT_CALL_AGAIN;
2471}
2472
2473
2474/**
2475 * Execute state save operation.
2476 *
2477 * @returns VBox status code.
2478 * @param pVM The cross context VM structure.
2479 * @param pSSM SSM operation handle.
2480 */
2481static DECLCALLBACK(int) cpumR3SaveExec(PVM pVM, PSSMHANDLE pSSM)
2482{
2483 /*
2484 * Save.
2485 */
2486 SSMR3PutU32(pSSM, pVM->cCpus);
2487 SSMR3PutU32(pSSM, sizeof(pVM->apCpusR3[0]->cpum.s.GuestMsrs.msr));
2488 CPUMCTX DummyHyperCtx;
2489 RT_ZERO(DummyHyperCtx);
2490 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
2491 {
2492 PVMCPU pVCpu = pVM->apCpusR3[idCpu];
2493
2494 SSMR3PutStructEx(pSSM, &DummyHyperCtx, sizeof(DummyHyperCtx), 0, g_aCpumCtxFields, NULL);
2495
2496 PCPUMCTX pGstCtx = &pVCpu->cpum.s.Guest;
2497 SSMR3PutStructEx(pSSM, pGstCtx, sizeof(*pGstCtx), 0, g_aCpumCtxFields, NULL);
2498 SSMR3PutStructEx(pSSM, &pGstCtx->XState.x87, sizeof(pGstCtx->XState.x87), 0, g_aCpumX87Fields, NULL);
2499 if (pGstCtx->fXStateMask != 0)
2500 SSMR3PutStructEx(pSSM, &pGstCtx->XState.Hdr, sizeof(pGstCtx->XState.Hdr), 0, g_aCpumXSaveHdrFields, NULL);
2501 if (pGstCtx->fXStateMask & XSAVE_C_YMM)
2502 {
2503 PCX86XSAVEYMMHI pYmmHiCtx = CPUMCTX_XSAVE_C_PTR(pGstCtx, XSAVE_C_YMM_BIT, PCX86XSAVEYMMHI);
2504 SSMR3PutStructEx(pSSM, pYmmHiCtx, sizeof(*pYmmHiCtx), SSMSTRUCT_FLAGS_FULL_STRUCT, g_aCpumYmmHiFields, NULL);
2505 }
2506 if (pGstCtx->fXStateMask & XSAVE_C_BNDREGS)
2507 {
2508 PCX86XSAVEBNDREGS pBndRegs = CPUMCTX_XSAVE_C_PTR(pGstCtx, XSAVE_C_BNDREGS_BIT, PCX86XSAVEBNDREGS);
2509 SSMR3PutStructEx(pSSM, pBndRegs, sizeof(*pBndRegs), SSMSTRUCT_FLAGS_FULL_STRUCT, g_aCpumBndRegsFields, NULL);
2510 }
2511 if (pGstCtx->fXStateMask & XSAVE_C_BNDCSR)
2512 {
2513 PCX86XSAVEBNDCFG pBndCfg = CPUMCTX_XSAVE_C_PTR(pGstCtx, XSAVE_C_BNDCSR_BIT, PCX86XSAVEBNDCFG);
2514 SSMR3PutStructEx(pSSM, pBndCfg, sizeof(*pBndCfg), SSMSTRUCT_FLAGS_FULL_STRUCT, g_aCpumBndCfgFields, NULL);
2515 }
2516 if (pGstCtx->fXStateMask & XSAVE_C_ZMM_HI256)
2517 {
2518 PCX86XSAVEZMMHI256 pZmmHi256 = CPUMCTX_XSAVE_C_PTR(pGstCtx, XSAVE_C_ZMM_HI256_BIT, PCX86XSAVEZMMHI256);
2519 SSMR3PutStructEx(pSSM, pZmmHi256, sizeof(*pZmmHi256), SSMSTRUCT_FLAGS_FULL_STRUCT, g_aCpumZmmHi256Fields, NULL);
2520 }
2521 if (pGstCtx->fXStateMask & XSAVE_C_ZMM_16HI)
2522 {
2523 PCX86XSAVEZMM16HI pZmm16Hi = CPUMCTX_XSAVE_C_PTR(pGstCtx, XSAVE_C_ZMM_16HI_BIT, PCX86XSAVEZMM16HI);
2524 SSMR3PutStructEx(pSSM, pZmm16Hi, sizeof(*pZmm16Hi), SSMSTRUCT_FLAGS_FULL_STRUCT, g_aCpumZmm16HiFields, NULL);
2525 }
2526 SSMR3PutU64(pSSM, pGstCtx->aPaePdpes[0].u);
2527 SSMR3PutU64(pSSM, pGstCtx->aPaePdpes[1].u);
2528 SSMR3PutU64(pSSM, pGstCtx->aPaePdpes[2].u);
2529 SSMR3PutU64(pSSM, pGstCtx->aPaePdpes[3].u);
2530 if (pVM->cpum.s.GuestFeatures.fSvm)
2531 {
2532 SSMR3PutU64(pSSM, pGstCtx->hwvirt.svm.uMsrHSavePa);
2533 SSMR3PutGCPhys(pSSM, pGstCtx->hwvirt.svm.GCPhysVmcb);
2534 SSMR3PutU64(pSSM, pGstCtx->hwvirt.svm.uPrevPauseTick);
2535 SSMR3PutU16(pSSM, pGstCtx->hwvirt.svm.cPauseFilter);
2536 SSMR3PutU16(pSSM, pGstCtx->hwvirt.svm.cPauseFilterThreshold);
2537 SSMR3PutBool(pSSM, pGstCtx->hwvirt.svm.fInterceptEvents);
2538 SSMR3PutStructEx(pSSM, &pGstCtx->hwvirt.svm.HostState, sizeof(pGstCtx->hwvirt.svm.HostState), 0 /* fFlags */,
2539 g_aSvmHwvirtHostState, NULL /* pvUser */);
2540 SSMR3PutMem(pSSM, &pGstCtx->hwvirt.svm.Vmcb, sizeof(pGstCtx->hwvirt.svm.Vmcb));
2541 SSMR3PutMem(pSSM, &pGstCtx->hwvirt.svm.abMsrBitmap[0], sizeof(pGstCtx->hwvirt.svm.abMsrBitmap));
2542 SSMR3PutMem(pSSM, &pGstCtx->hwvirt.svm.abIoBitmap[0], sizeof(pGstCtx->hwvirt.svm.abIoBitmap));
2543 SSMR3PutU32(pSSM, pGstCtx->hwvirt.fLocalForcedActions);
2544 SSMR3PutBool(pSSM, pGstCtx->hwvirt.fGif);
2545 }
2546 if (pVM->cpum.s.GuestFeatures.fVmx)
2547 {
2548 SSMR3PutGCPhys(pSSM, pGstCtx->hwvirt.vmx.GCPhysVmxon);
2549 SSMR3PutGCPhys(pSSM, pGstCtx->hwvirt.vmx.GCPhysVmcs);
2550 SSMR3PutGCPhys(pSSM, pGstCtx->hwvirt.vmx.GCPhysShadowVmcs);
2551 SSMR3PutBool(pSSM, pGstCtx->hwvirt.vmx.fInVmxRootMode);
2552 SSMR3PutBool(pSSM, pGstCtx->hwvirt.vmx.fInVmxNonRootMode);
2553 SSMR3PutBool(pSSM, pGstCtx->hwvirt.vmx.fInterceptEvents);
2554 SSMR3PutBool(pSSM, pGstCtx->hwvirt.vmx.fNmiUnblockingIret);
2555 SSMR3PutStructEx(pSSM, &pGstCtx->hwvirt.vmx.Vmcs, sizeof(pGstCtx->hwvirt.vmx.Vmcs), 0, g_aVmxHwvirtVmcs, NULL);
2556 SSMR3PutStructEx(pSSM, &pGstCtx->hwvirt.vmx.ShadowVmcs, sizeof(pGstCtx->hwvirt.vmx.ShadowVmcs),
2557 0, g_aVmxHwvirtVmcs, NULL);
2558 SSMR3PutMem(pSSM, &pGstCtx->hwvirt.vmx.abVmreadBitmap[0], sizeof(pGstCtx->hwvirt.vmx.abVmreadBitmap));
2559 SSMR3PutMem(pSSM, &pGstCtx->hwvirt.vmx.abVmwriteBitmap[0], sizeof(pGstCtx->hwvirt.vmx.abVmwriteBitmap));
2560 SSMR3PutMem(pSSM, &pGstCtx->hwvirt.vmx.aEntryMsrLoadArea[0], sizeof(pGstCtx->hwvirt.vmx.aEntryMsrLoadArea));
2561 SSMR3PutMem(pSSM, &pGstCtx->hwvirt.vmx.aExitMsrStoreArea[0], sizeof(pGstCtx->hwvirt.vmx.aExitMsrStoreArea));
2562 SSMR3PutMem(pSSM, &pGstCtx->hwvirt.vmx.aExitMsrLoadArea[0], sizeof(pGstCtx->hwvirt.vmx.aExitMsrLoadArea));
2563 SSMR3PutMem(pSSM, &pGstCtx->hwvirt.vmx.abMsrBitmap[0], sizeof(pGstCtx->hwvirt.vmx.abMsrBitmap));
2564 SSMR3PutMem(pSSM, &pGstCtx->hwvirt.vmx.abIoBitmap[0], sizeof(pGstCtx->hwvirt.vmx.abIoBitmap));
2565 SSMR3PutU64(pSSM, pGstCtx->hwvirt.vmx.uFirstPauseLoopTick);
2566 SSMR3PutU64(pSSM, pGstCtx->hwvirt.vmx.uPrevPauseTick);
2567 SSMR3PutU64(pSSM, pGstCtx->hwvirt.vmx.uEntryTick);
2568 SSMR3PutU16(pSSM, pGstCtx->hwvirt.vmx.offVirtApicWrite);
2569 SSMR3PutBool(pSSM, pGstCtx->hwvirt.vmx.fVirtNmiBlocking);
2570 SSMR3PutU64(pSSM, MSR_IA32_FEATURE_CONTROL_LOCK | MSR_IA32_FEATURE_CONTROL_VMXON); /* Deprecated since 2021/09/22. Value kept backwards compatibile with 6.1.26. */
2571 SSMR3PutU64(pSSM, pGstCtx->hwvirt.vmx.Msrs.u64Basic);
2572 SSMR3PutU64(pSSM, pGstCtx->hwvirt.vmx.Msrs.PinCtls.u);
2573 SSMR3PutU64(pSSM, pGstCtx->hwvirt.vmx.Msrs.ProcCtls.u);
2574 SSMR3PutU64(pSSM, pGstCtx->hwvirt.vmx.Msrs.ProcCtls2.u);
2575 SSMR3PutU64(pSSM, pGstCtx->hwvirt.vmx.Msrs.ExitCtls.u);
2576 SSMR3PutU64(pSSM, pGstCtx->hwvirt.vmx.Msrs.EntryCtls.u);
2577 SSMR3PutU64(pSSM, pGstCtx->hwvirt.vmx.Msrs.TruePinCtls.u);
2578 SSMR3PutU64(pSSM, pGstCtx->hwvirt.vmx.Msrs.TrueProcCtls.u);
2579 SSMR3PutU64(pSSM, pGstCtx->hwvirt.vmx.Msrs.TrueEntryCtls.u);
2580 SSMR3PutU64(pSSM, pGstCtx->hwvirt.vmx.Msrs.TrueExitCtls.u);
2581 SSMR3PutU64(pSSM, pGstCtx->hwvirt.vmx.Msrs.u64Misc);
2582 SSMR3PutU64(pSSM, pGstCtx->hwvirt.vmx.Msrs.u64Cr0Fixed0);
2583 SSMR3PutU64(pSSM, pGstCtx->hwvirt.vmx.Msrs.u64Cr0Fixed1);
2584 SSMR3PutU64(pSSM, pGstCtx->hwvirt.vmx.Msrs.u64Cr4Fixed0);
2585 SSMR3PutU64(pSSM, pGstCtx->hwvirt.vmx.Msrs.u64Cr4Fixed1);
2586 SSMR3PutU64(pSSM, pGstCtx->hwvirt.vmx.Msrs.u64VmcsEnum);
2587 SSMR3PutU64(pSSM, pGstCtx->hwvirt.vmx.Msrs.u64VmFunc);
2588 SSMR3PutU64(pSSM, pGstCtx->hwvirt.vmx.Msrs.u64EptVpidCaps);
2589 SSMR3PutU64(pSSM, pGstCtx->hwvirt.vmx.Msrs.u64ProcCtls3);
2590 }
2591 SSMR3PutU32(pSSM, pVCpu->cpum.s.fUseFlags);
2592 SSMR3PutU32(pSSM, pVCpu->cpum.s.fChanged);
2593 AssertCompileSizeAlignment(pVCpu->cpum.s.GuestMsrs.msr, sizeof(uint64_t));
2594 SSMR3PutMem(pSSM, &pVCpu->cpum.s.GuestMsrs, sizeof(pVCpu->cpum.s.GuestMsrs.msr));
2595 }
2596
2597 cpumR3SaveCpuId(pVM, pSSM);
2598 return VINF_SUCCESS;
2599}
2600
2601
2602/**
2603 * @callback_method_impl{FNSSMINTLOADPREP}
2604 */
2605static DECLCALLBACK(int) cpumR3LoadPrep(PVM pVM, PSSMHANDLE pSSM)
2606{
2607 NOREF(pSSM);
2608 pVM->cpum.s.fPendingRestore = true;
2609 return VINF_SUCCESS;
2610}
2611
2612
2613/**
2614 * @callback_method_impl{FNSSMINTLOADEXEC}
2615 */
2616static DECLCALLBACK(int) cpumR3LoadExec(PVM pVM, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
2617{
2618 int rc; /* Only for AssertRCReturn use. */
2619
2620 /*
2621 * Validate version.
2622 */
2623 if ( uVersion != CPUM_SAVED_STATE_VERSION_PAE_PDPES
2624 && uVersion != CPUM_SAVED_STATE_VERSION_HWVIRT_VMX_2
2625 && uVersion != CPUM_SAVED_STATE_VERSION_HWVIRT_VMX
2626 && uVersion != CPUM_SAVED_STATE_VERSION_HWVIRT_SVM
2627 && uVersion != CPUM_SAVED_STATE_VERSION_XSAVE
2628 && uVersion != CPUM_SAVED_STATE_VERSION_GOOD_CPUID_COUNT
2629 && uVersion != CPUM_SAVED_STATE_VERSION_BAD_CPUID_COUNT
2630 && uVersion != CPUM_SAVED_STATE_VERSION_PUT_STRUCT
2631 && uVersion != CPUM_SAVED_STATE_VERSION_MEM
2632 && uVersion != CPUM_SAVED_STATE_VERSION_NO_MSR_SIZE
2633 && uVersion != CPUM_SAVED_STATE_VERSION_VER3_2
2634 && uVersion != CPUM_SAVED_STATE_VERSION_VER3_0
2635 && uVersion != CPUM_SAVED_STATE_VERSION_VER2_1_NOMSR
2636 && uVersion != CPUM_SAVED_STATE_VERSION_VER2_0
2637 && uVersion != CPUM_SAVED_STATE_VERSION_VER1_6)
2638 {
2639 AssertMsgFailed(("cpumR3LoadExec: Invalid version uVersion=%d!\n", uVersion));
2640 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
2641 }
2642
2643 if (uPass == SSM_PASS_FINAL)
2644 {
2645 /*
2646 * Set the size of RTGCPTR for SSMR3GetGCPtr. (Only necessary for
2647 * really old SSM file versions.)
2648 */
2649 if (uVersion == CPUM_SAVED_STATE_VERSION_VER1_6)
2650 SSMR3HandleSetGCPtrSize(pSSM, sizeof(RTGCPTR32));
2651 else if (uVersion <= CPUM_SAVED_STATE_VERSION_VER3_0)
2652 SSMR3HandleSetGCPtrSize(pSSM, sizeof(RTGCPTR));
2653
2654 /*
2655 * Figure x86 and ctx field definitions to use for older states.
2656 */
2657 uint32_t const fLoad = uVersion > CPUM_SAVED_STATE_VERSION_MEM ? 0 : SSMSTRUCT_FLAGS_MEM_BAND_AID_RELAXED;
2658 PCSSMFIELD paCpumCtx1Fields = g_aCpumX87Fields;
2659 PCSSMFIELD paCpumCtx2Fields = g_aCpumCtxFields;
2660 if (uVersion == CPUM_SAVED_STATE_VERSION_VER1_6)
2661 {
2662 paCpumCtx1Fields = g_aCpumX87FieldsV16;
2663 paCpumCtx2Fields = g_aCpumCtxFieldsV16;
2664 }
2665 else if (uVersion <= CPUM_SAVED_STATE_VERSION_MEM)
2666 {
2667 paCpumCtx1Fields = g_aCpumX87FieldsMem;
2668 paCpumCtx2Fields = g_aCpumCtxFieldsMem;
2669 }
2670
2671 /*
2672 * The hyper state used to preceed the CPU count. Starting with
2673 * XSAVE it was moved down till after we've got the count.
2674 */
2675 CPUMCTX HyperCtxIgnored;
2676 if (uVersion < CPUM_SAVED_STATE_VERSION_XSAVE)
2677 {
2678 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
2679 {
2680 X86FXSTATE Ign;
2681 SSMR3GetStructEx(pSSM, &Ign, sizeof(Ign), fLoad | SSMSTRUCT_FLAGS_NO_TAIL_MARKER, paCpumCtx1Fields, NULL);
2682 SSMR3GetStructEx(pSSM, &HyperCtxIgnored, sizeof(HyperCtxIgnored),
2683 fLoad | SSMSTRUCT_FLAGS_NO_LEAD_MARKER, paCpumCtx2Fields, NULL);
2684 }
2685 }
2686
2687 if (uVersion >= CPUM_SAVED_STATE_VERSION_VER2_1_NOMSR)
2688 {
2689 uint32_t cCpus;
2690 rc = SSMR3GetU32(pSSM, &cCpus); AssertRCReturn(rc, rc);
2691 AssertLogRelMsgReturn(cCpus == pVM->cCpus, ("Mismatching CPU counts: saved: %u; configured: %u \n", cCpus, pVM->cCpus),
2692 VERR_SSM_UNEXPECTED_DATA);
2693 }
2694 AssertLogRelMsgReturn( uVersion > CPUM_SAVED_STATE_VERSION_VER2_0
2695 || pVM->cCpus == 1,
2696 ("cCpus=%u\n", pVM->cCpus),
2697 VERR_SSM_UNEXPECTED_DATA);
2698
2699 uint32_t cbMsrs = 0;
2700 if (uVersion > CPUM_SAVED_STATE_VERSION_NO_MSR_SIZE)
2701 {
2702 rc = SSMR3GetU32(pSSM, &cbMsrs); AssertRCReturn(rc, rc);
2703 AssertLogRelMsgReturn(RT_ALIGN(cbMsrs, sizeof(uint64_t)) == cbMsrs, ("Size of MSRs is misaligned: %#x\n", cbMsrs),
2704 VERR_SSM_UNEXPECTED_DATA);
2705 AssertLogRelMsgReturn(cbMsrs <= sizeof(CPUMCTXMSRS) && cbMsrs > 0, ("Size of MSRs is out of range: %#x\n", cbMsrs),
2706 VERR_SSM_UNEXPECTED_DATA);
2707 }
2708
2709 /*
2710 * Do the per-CPU restoring.
2711 */
2712 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
2713 {
2714 PVMCPU pVCpu = pVM->apCpusR3[idCpu];
2715 PCPUMCTX pGstCtx = &pVCpu->cpum.s.Guest;
2716
2717 if (uVersion >= CPUM_SAVED_STATE_VERSION_XSAVE)
2718 {
2719 /*
2720 * The XSAVE saved state layout moved the hyper state down here.
2721 */
2722 rc = SSMR3GetStructEx(pSSM, &HyperCtxIgnored, sizeof(HyperCtxIgnored), 0, g_aCpumCtxFields, NULL);
2723 AssertRCReturn(rc, rc);
2724
2725 /*
2726 * Start by restoring the CPUMCTX structure and the X86FXSAVE bits of the extended state.
2727 */
2728 rc = SSMR3GetStructEx(pSSM, pGstCtx, sizeof(*pGstCtx), 0, g_aCpumCtxFields, NULL);
2729 rc = SSMR3GetStructEx(pSSM, &pGstCtx->XState.x87, sizeof(pGstCtx->XState.x87), 0, g_aCpumX87Fields, NULL);
2730 AssertRCReturn(rc, rc);
2731
2732 /* Check that the xsave/xrstor mask is valid (invalid results in #GP). */
2733 if (pGstCtx->fXStateMask != 0)
2734 {
2735 AssertLogRelMsgReturn(!(pGstCtx->fXStateMask & ~pVM->cpum.s.fXStateGuestMask),
2736 ("fXStateMask=%#RX64 fXStateGuestMask=%#RX64\n",
2737 pGstCtx->fXStateMask, pVM->cpum.s.fXStateGuestMask),
2738 VERR_CPUM_INCOMPATIBLE_XSAVE_COMP_MASK);
2739 AssertLogRelMsgReturn(pGstCtx->fXStateMask & XSAVE_C_X87,
2740 ("fXStateMask=%#RX64\n", pGstCtx->fXStateMask), VERR_CPUM_INVALID_XSAVE_COMP_MASK);
2741 AssertLogRelMsgReturn((pGstCtx->fXStateMask & (XSAVE_C_SSE | XSAVE_C_YMM)) != XSAVE_C_YMM,
2742 ("fXStateMask=%#RX64\n", pGstCtx->fXStateMask), VERR_CPUM_INVALID_XSAVE_COMP_MASK);
2743 AssertLogRelMsgReturn( (pGstCtx->fXStateMask & (XSAVE_C_OPMASK | XSAVE_C_ZMM_HI256 | XSAVE_C_ZMM_16HI)) == 0
2744 || (pGstCtx->fXStateMask & (XSAVE_C_SSE | XSAVE_C_YMM | XSAVE_C_OPMASK | XSAVE_C_ZMM_HI256 | XSAVE_C_ZMM_16HI))
2745 == (XSAVE_C_SSE | XSAVE_C_YMM | XSAVE_C_OPMASK | XSAVE_C_ZMM_HI256 | XSAVE_C_ZMM_16HI),
2746 ("fXStateMask=%#RX64\n", pGstCtx->fXStateMask), VERR_CPUM_INVALID_XSAVE_COMP_MASK);
2747 }
2748
2749 /* Check that the XCR0 mask is valid (invalid results in #GP). */
2750 AssertLogRelMsgReturn(pGstCtx->aXcr[0] & XSAVE_C_X87, ("xcr0=%#RX64\n", pGstCtx->aXcr[0]), VERR_CPUM_INVALID_XCR0);
2751 if (pGstCtx->aXcr[0] != XSAVE_C_X87)
2752 {
2753 AssertLogRelMsgReturn(!(pGstCtx->aXcr[0] & ~(pGstCtx->fXStateMask | XSAVE_C_X87)),
2754 ("xcr0=%#RX64 fXStateMask=%#RX64\n", pGstCtx->aXcr[0], pGstCtx->fXStateMask),
2755 VERR_CPUM_INVALID_XCR0);
2756 AssertLogRelMsgReturn(pGstCtx->aXcr[0] & XSAVE_C_X87,
2757 ("xcr0=%#RX64\n", pGstCtx->aXcr[0]), VERR_CPUM_INVALID_XSAVE_COMP_MASK);
2758 AssertLogRelMsgReturn((pGstCtx->aXcr[0] & (XSAVE_C_SSE | XSAVE_C_YMM)) != XSAVE_C_YMM,
2759 ("xcr0=%#RX64\n", pGstCtx->aXcr[0]), VERR_CPUM_INVALID_XSAVE_COMP_MASK);
2760 AssertLogRelMsgReturn( (pGstCtx->aXcr[0] & (XSAVE_C_OPMASK | XSAVE_C_ZMM_HI256 | XSAVE_C_ZMM_16HI)) == 0
2761 || (pGstCtx->aXcr[0] & (XSAVE_C_SSE | XSAVE_C_YMM | XSAVE_C_OPMASK | XSAVE_C_ZMM_HI256 | XSAVE_C_ZMM_16HI))
2762 == (XSAVE_C_SSE | XSAVE_C_YMM | XSAVE_C_OPMASK | XSAVE_C_ZMM_HI256 | XSAVE_C_ZMM_16HI),
2763 ("xcr0=%#RX64\n", pGstCtx->aXcr[0]), VERR_CPUM_INVALID_XSAVE_COMP_MASK);
2764 }
2765
2766 /* Check that the XCR1 is zero, as we don't implement it yet. */
2767 AssertLogRelMsgReturn(!pGstCtx->aXcr[1], ("xcr1=%#RX64\n", pGstCtx->aXcr[1]), VERR_SSM_DATA_UNIT_FORMAT_CHANGED);
2768
2769 /*
2770 * Restore the individual extended state components we support.
2771 */
2772 if (pGstCtx->fXStateMask != 0)
2773 {
2774 rc = SSMR3GetStructEx(pSSM, &pGstCtx->XState.Hdr, sizeof(pGstCtx->XState.Hdr),
2775 0, g_aCpumXSaveHdrFields, NULL);
2776 AssertRCReturn(rc, rc);
2777 AssertLogRelMsgReturn(!(pGstCtx->XState.Hdr.bmXState & ~pGstCtx->fXStateMask),
2778 ("bmXState=%#RX64 fXStateMask=%#RX64\n",
2779 pGstCtx->XState.Hdr.bmXState, pGstCtx->fXStateMask),
2780 VERR_CPUM_INVALID_XSAVE_HDR);
2781 }
2782 if (pGstCtx->fXStateMask & XSAVE_C_YMM)
2783 {
2784 PX86XSAVEYMMHI pYmmHiCtx = CPUMCTX_XSAVE_C_PTR(pGstCtx, XSAVE_C_YMM_BIT, PX86XSAVEYMMHI);
2785 SSMR3GetStructEx(pSSM, pYmmHiCtx, sizeof(*pYmmHiCtx), SSMSTRUCT_FLAGS_FULL_STRUCT, g_aCpumYmmHiFields, NULL);
2786 }
2787 if (pGstCtx->fXStateMask & XSAVE_C_BNDREGS)
2788 {
2789 PX86XSAVEBNDREGS pBndRegs = CPUMCTX_XSAVE_C_PTR(pGstCtx, XSAVE_C_BNDREGS_BIT, PX86XSAVEBNDREGS);
2790 SSMR3GetStructEx(pSSM, pBndRegs, sizeof(*pBndRegs), SSMSTRUCT_FLAGS_FULL_STRUCT, g_aCpumBndRegsFields, NULL);
2791 }
2792 if (pGstCtx->fXStateMask & XSAVE_C_BNDCSR)
2793 {
2794 PX86XSAVEBNDCFG pBndCfg = CPUMCTX_XSAVE_C_PTR(pGstCtx, XSAVE_C_BNDCSR_BIT, PX86XSAVEBNDCFG);
2795 SSMR3GetStructEx(pSSM, pBndCfg, sizeof(*pBndCfg), SSMSTRUCT_FLAGS_FULL_STRUCT, g_aCpumBndCfgFields, NULL);
2796 }
2797 if (pGstCtx->fXStateMask & XSAVE_C_ZMM_HI256)
2798 {
2799 PX86XSAVEZMMHI256 pZmmHi256 = CPUMCTX_XSAVE_C_PTR(pGstCtx, XSAVE_C_ZMM_HI256_BIT, PX86XSAVEZMMHI256);
2800 SSMR3GetStructEx(pSSM, pZmmHi256, sizeof(*pZmmHi256), SSMSTRUCT_FLAGS_FULL_STRUCT, g_aCpumZmmHi256Fields, NULL);
2801 }
2802 if (pGstCtx->fXStateMask & XSAVE_C_ZMM_16HI)
2803 {
2804 PX86XSAVEZMM16HI pZmm16Hi = CPUMCTX_XSAVE_C_PTR(pGstCtx, XSAVE_C_ZMM_16HI_BIT, PX86XSAVEZMM16HI);
2805 SSMR3GetStructEx(pSSM, pZmm16Hi, sizeof(*pZmm16Hi), SSMSTRUCT_FLAGS_FULL_STRUCT, g_aCpumZmm16HiFields, NULL);
2806 }
2807 if (uVersion >= CPUM_SAVED_STATE_VERSION_PAE_PDPES)
2808 {
2809 SSMR3GetU64(pSSM, &pGstCtx->aPaePdpes[0].u);
2810 SSMR3GetU64(pSSM, &pGstCtx->aPaePdpes[1].u);
2811 SSMR3GetU64(pSSM, &pGstCtx->aPaePdpes[2].u);
2812 SSMR3GetU64(pSSM, &pGstCtx->aPaePdpes[3].u);
2813 }
2814 if (uVersion >= CPUM_SAVED_STATE_VERSION_HWVIRT_SVM)
2815 {
2816 if (pVM->cpum.s.GuestFeatures.fSvm)
2817 {
2818 SSMR3GetU64(pSSM, &pGstCtx->hwvirt.svm.uMsrHSavePa);
2819 SSMR3GetGCPhys(pSSM, &pGstCtx->hwvirt.svm.GCPhysVmcb);
2820 SSMR3GetU64(pSSM, &pGstCtx->hwvirt.svm.uPrevPauseTick);
2821 SSMR3GetU16(pSSM, &pGstCtx->hwvirt.svm.cPauseFilter);
2822 SSMR3GetU16(pSSM, &pGstCtx->hwvirt.svm.cPauseFilterThreshold);
2823 SSMR3GetBool(pSSM, &pGstCtx->hwvirt.svm.fInterceptEvents);
2824 SSMR3GetStructEx(pSSM, &pGstCtx->hwvirt.svm.HostState, sizeof(pGstCtx->hwvirt.svm.HostState),
2825 0 /* fFlags */, g_aSvmHwvirtHostState, NULL /* pvUser */);
2826 SSMR3GetMem(pSSM, &pGstCtx->hwvirt.svm.Vmcb, sizeof(pGstCtx->hwvirt.svm.Vmcb));
2827 SSMR3GetMem(pSSM, &pGstCtx->hwvirt.svm.abMsrBitmap[0], sizeof(pGstCtx->hwvirt.svm.abMsrBitmap));
2828 SSMR3GetMem(pSSM, &pGstCtx->hwvirt.svm.abIoBitmap[0], sizeof(pGstCtx->hwvirt.svm.abIoBitmap));
2829 SSMR3GetU32(pSSM, &pGstCtx->hwvirt.fLocalForcedActions);
2830 SSMR3GetBool(pSSM, &pGstCtx->hwvirt.fGif);
2831 }
2832 }
2833 if (uVersion >= CPUM_SAVED_STATE_VERSION_HWVIRT_VMX)
2834 {
2835 if (pVM->cpum.s.GuestFeatures.fVmx)
2836 {
2837 SSMR3GetGCPhys(pSSM, &pGstCtx->hwvirt.vmx.GCPhysVmxon);
2838 SSMR3GetGCPhys(pSSM, &pGstCtx->hwvirt.vmx.GCPhysVmcs);
2839 SSMR3GetGCPhys(pSSM, &pGstCtx->hwvirt.vmx.GCPhysShadowVmcs);
2840 SSMR3GetBool(pSSM, &pGstCtx->hwvirt.vmx.fInVmxRootMode);
2841 SSMR3GetBool(pSSM, &pGstCtx->hwvirt.vmx.fInVmxNonRootMode);
2842 SSMR3GetBool(pSSM, &pGstCtx->hwvirt.vmx.fInterceptEvents);
2843 SSMR3GetBool(pSSM, &pGstCtx->hwvirt.vmx.fNmiUnblockingIret);
2844 SSMR3GetStructEx(pSSM, &pGstCtx->hwvirt.vmx.Vmcs, sizeof(pGstCtx->hwvirt.vmx.Vmcs),
2845 0, g_aVmxHwvirtVmcs, NULL);
2846 SSMR3GetStructEx(pSSM, &pGstCtx->hwvirt.vmx.ShadowVmcs, sizeof(pGstCtx->hwvirt.vmx.ShadowVmcs),
2847 0, g_aVmxHwvirtVmcs, NULL);
2848 SSMR3GetMem(pSSM, &pGstCtx->hwvirt.vmx.abVmreadBitmap[0], sizeof(pGstCtx->hwvirt.vmx.abVmreadBitmap));
2849 SSMR3GetMem(pSSM, &pGstCtx->hwvirt.vmx.abVmwriteBitmap[0], sizeof(pGstCtx->hwvirt.vmx.abVmwriteBitmap));
2850 SSMR3GetMem(pSSM, &pGstCtx->hwvirt.vmx.aEntryMsrLoadArea[0], sizeof(pGstCtx->hwvirt.vmx.aEntryMsrLoadArea));
2851 SSMR3GetMem(pSSM, &pGstCtx->hwvirt.vmx.aExitMsrStoreArea[0], sizeof(pGstCtx->hwvirt.vmx.aExitMsrStoreArea));
2852 SSMR3GetMem(pSSM, &pGstCtx->hwvirt.vmx.aExitMsrLoadArea[0], sizeof(pGstCtx->hwvirt.vmx.aExitMsrLoadArea));
2853 SSMR3GetMem(pSSM, &pGstCtx->hwvirt.vmx.abMsrBitmap[0], sizeof(pGstCtx->hwvirt.vmx.abMsrBitmap));
2854 SSMR3GetMem(pSSM, &pGstCtx->hwvirt.vmx.abIoBitmap[0], sizeof(pGstCtx->hwvirt.vmx.abIoBitmap));
2855 SSMR3GetU64(pSSM, &pGstCtx->hwvirt.vmx.uFirstPauseLoopTick);
2856 SSMR3GetU64(pSSM, &pGstCtx->hwvirt.vmx.uPrevPauseTick);
2857 SSMR3GetU64(pSSM, &pGstCtx->hwvirt.vmx.uEntryTick);
2858 SSMR3GetU16(pSSM, &pGstCtx->hwvirt.vmx.offVirtApicWrite);
2859 SSMR3GetBool(pSSM, &pGstCtx->hwvirt.vmx.fVirtNmiBlocking);
2860 SSMR3Skip(pSSM, sizeof(uint64_t)); /* Unused - used to be IA32_FEATURE_CONTROL, see @bugref{10106}. */
2861 SSMR3GetU64(pSSM, &pGstCtx->hwvirt.vmx.Msrs.u64Basic);
2862 SSMR3GetU64(pSSM, &pGstCtx->hwvirt.vmx.Msrs.PinCtls.u);
2863 SSMR3GetU64(pSSM, &pGstCtx->hwvirt.vmx.Msrs.ProcCtls.u);
2864 SSMR3GetU64(pSSM, &pGstCtx->hwvirt.vmx.Msrs.ProcCtls2.u);
2865 SSMR3GetU64(pSSM, &pGstCtx->hwvirt.vmx.Msrs.ExitCtls.u);
2866 SSMR3GetU64(pSSM, &pGstCtx->hwvirt.vmx.Msrs.EntryCtls.u);
2867 SSMR3GetU64(pSSM, &pGstCtx->hwvirt.vmx.Msrs.TruePinCtls.u);
2868 SSMR3GetU64(pSSM, &pGstCtx->hwvirt.vmx.Msrs.TrueProcCtls.u);
2869 SSMR3GetU64(pSSM, &pGstCtx->hwvirt.vmx.Msrs.TrueEntryCtls.u);
2870 SSMR3GetU64(pSSM, &pGstCtx->hwvirt.vmx.Msrs.TrueExitCtls.u);
2871 SSMR3GetU64(pSSM, &pGstCtx->hwvirt.vmx.Msrs.u64Misc);
2872 SSMR3GetU64(pSSM, &pGstCtx->hwvirt.vmx.Msrs.u64Cr0Fixed0);
2873 SSMR3GetU64(pSSM, &pGstCtx->hwvirt.vmx.Msrs.u64Cr0Fixed1);
2874 SSMR3GetU64(pSSM, &pGstCtx->hwvirt.vmx.Msrs.u64Cr4Fixed0);
2875 SSMR3GetU64(pSSM, &pGstCtx->hwvirt.vmx.Msrs.u64Cr4Fixed1);
2876 SSMR3GetU64(pSSM, &pGstCtx->hwvirt.vmx.Msrs.u64VmcsEnum);
2877 SSMR3GetU64(pSSM, &pGstCtx->hwvirt.vmx.Msrs.u64VmFunc);
2878 SSMR3GetU64(pSSM, &pGstCtx->hwvirt.vmx.Msrs.u64EptVpidCaps);
2879 if (uVersion >= CPUM_SAVED_STATE_VERSION_HWVIRT_VMX_2)
2880 SSMR3GetU64(pSSM, &pGstCtx->hwvirt.vmx.Msrs.u64ProcCtls3);
2881 }
2882 }
2883 }
2884 else
2885 {
2886 /*
2887 * Pre XSAVE saved state.
2888 */
2889 SSMR3GetStructEx(pSSM, &pGstCtx->XState.x87, sizeof(pGstCtx->XState.x87),
2890 fLoad | SSMSTRUCT_FLAGS_NO_TAIL_MARKER, paCpumCtx1Fields, NULL);
2891 SSMR3GetStructEx(pSSM, pGstCtx, sizeof(*pGstCtx), fLoad | SSMSTRUCT_FLAGS_NO_LEAD_MARKER, paCpumCtx2Fields, NULL);
2892 }
2893
2894 /*
2895 * Restore a couple of flags and the MSRs.
2896 */
2897 uint32_t fIgnoredUsedFlags = 0;
2898 rc = SSMR3GetU32(pSSM, &fIgnoredUsedFlags); /* we're recalc the two relevant flags after loading state. */
2899 AssertRCReturn(rc, rc);
2900 SSMR3GetU32(pSSM, &pVCpu->cpum.s.fChanged);
2901
2902 rc = VINF_SUCCESS;
2903 if (uVersion > CPUM_SAVED_STATE_VERSION_NO_MSR_SIZE)
2904 rc = SSMR3GetMem(pSSM, &pVCpu->cpum.s.GuestMsrs.au64[0], cbMsrs);
2905 else if (uVersion >= CPUM_SAVED_STATE_VERSION_VER3_0)
2906 {
2907 SSMR3GetMem(pSSM, &pVCpu->cpum.s.GuestMsrs.au64[0], 2 * sizeof(uint64_t)); /* Restore two MSRs. */
2908 rc = SSMR3Skip(pSSM, 62 * sizeof(uint64_t));
2909 }
2910 AssertRCReturn(rc, rc);
2911
2912 /* REM and other may have cleared must-be-one fields in DR6 and
2913 DR7, fix these. */
2914 pGstCtx->dr[6] &= ~(X86_DR6_RAZ_MASK | X86_DR6_MBZ_MASK);
2915 pGstCtx->dr[6] |= X86_DR6_RA1_MASK;
2916 pGstCtx->dr[7] &= ~(X86_DR7_RAZ_MASK | X86_DR7_MBZ_MASK);
2917 pGstCtx->dr[7] |= X86_DR7_RA1_MASK;
2918 }
2919
2920 /* Older states does not have the internal selector register flags
2921 and valid selector value. Supply those. */
2922 if (uVersion <= CPUM_SAVED_STATE_VERSION_MEM)
2923 {
2924 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
2925 {
2926 PVMCPU pVCpu = pVM->apCpusR3[idCpu];
2927 bool const fValid = true /*!VM_IS_RAW_MODE_ENABLED(pVM)*/
2928 || ( uVersion > CPUM_SAVED_STATE_VERSION_VER3_2
2929 && !(pVCpu->cpum.s.fChanged & CPUM_CHANGED_HIDDEN_SEL_REGS_INVALID));
2930 PCPUMSELREG paSelReg = CPUMCTX_FIRST_SREG(&pVCpu->cpum.s.Guest);
2931 if (fValid)
2932 {
2933 for (uint32_t iSelReg = 0; iSelReg < X86_SREG_COUNT; iSelReg++)
2934 {
2935 paSelReg[iSelReg].fFlags = CPUMSELREG_FLAGS_VALID;
2936 paSelReg[iSelReg].ValidSel = paSelReg[iSelReg].Sel;
2937 }
2938
2939 pVCpu->cpum.s.Guest.ldtr.fFlags = CPUMSELREG_FLAGS_VALID;
2940 pVCpu->cpum.s.Guest.ldtr.ValidSel = pVCpu->cpum.s.Guest.ldtr.Sel;
2941 }
2942 else
2943 {
2944 for (uint32_t iSelReg = 0; iSelReg < X86_SREG_COUNT; iSelReg++)
2945 {
2946 paSelReg[iSelReg].fFlags = 0;
2947 paSelReg[iSelReg].ValidSel = 0;
2948 }
2949
2950 /* This might not be 104% correct, but I think it's close
2951 enough for all practical purposes... (REM always loaded
2952 LDTR registers.) */
2953 pVCpu->cpum.s.Guest.ldtr.fFlags = CPUMSELREG_FLAGS_VALID;
2954 pVCpu->cpum.s.Guest.ldtr.ValidSel = pVCpu->cpum.s.Guest.ldtr.Sel;
2955 }
2956 pVCpu->cpum.s.Guest.tr.fFlags = CPUMSELREG_FLAGS_VALID;
2957 pVCpu->cpum.s.Guest.tr.ValidSel = pVCpu->cpum.s.Guest.tr.Sel;
2958 }
2959 }
2960
2961 /* Clear CPUM_CHANGED_HIDDEN_SEL_REGS_INVALID. */
2962 if ( uVersion > CPUM_SAVED_STATE_VERSION_VER3_2
2963 && uVersion <= CPUM_SAVED_STATE_VERSION_MEM)
2964 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
2965 {
2966 PVMCPU pVCpu = pVM->apCpusR3[idCpu];
2967 pVCpu->cpum.s.fChanged &= CPUM_CHANGED_HIDDEN_SEL_REGS_INVALID;
2968 }
2969
2970 /*
2971 * A quick sanity check.
2972 */
2973 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
2974 {
2975 PVMCPU pVCpu = pVM->apCpusR3[idCpu];
2976 AssertLogRelReturn(!(pVCpu->cpum.s.Guest.es.fFlags & ~CPUMSELREG_FLAGS_VALID_MASK), VERR_SSM_UNEXPECTED_DATA);
2977 AssertLogRelReturn(!(pVCpu->cpum.s.Guest.cs.fFlags & ~CPUMSELREG_FLAGS_VALID_MASK), VERR_SSM_UNEXPECTED_DATA);
2978 AssertLogRelReturn(!(pVCpu->cpum.s.Guest.ss.fFlags & ~CPUMSELREG_FLAGS_VALID_MASK), VERR_SSM_UNEXPECTED_DATA);
2979 AssertLogRelReturn(!(pVCpu->cpum.s.Guest.ds.fFlags & ~CPUMSELREG_FLAGS_VALID_MASK), VERR_SSM_UNEXPECTED_DATA);
2980 AssertLogRelReturn(!(pVCpu->cpum.s.Guest.fs.fFlags & ~CPUMSELREG_FLAGS_VALID_MASK), VERR_SSM_UNEXPECTED_DATA);
2981 AssertLogRelReturn(!(pVCpu->cpum.s.Guest.gs.fFlags & ~CPUMSELREG_FLAGS_VALID_MASK), VERR_SSM_UNEXPECTED_DATA);
2982 }
2983 }
2984
2985 pVM->cpum.s.fPendingRestore = false;
2986
2987 /*
2988 * Guest CPUIDs (and VMX MSR features).
2989 */
2990 if (uVersion >= CPUM_SAVED_STATE_VERSION_VER3_2)
2991 {
2992 CPUMMSRS GuestMsrs;
2993 RT_ZERO(GuestMsrs);
2994
2995 CPUMFEATURES BaseFeatures;
2996 bool const fVmxGstFeat = pVM->cpum.s.GuestFeatures.fVmx;
2997 if (fVmxGstFeat)
2998 {
2999 /*
3000 * At this point the MSRs in the guest CPU-context are loaded with the guest VMX MSRs from the saved state.
3001 * However the VMX sub-features have not been exploded yet. So cache the base (host derived) VMX features
3002 * here so we can compare them for compatibility after exploding guest features.
3003 */
3004 BaseFeatures = pVM->cpum.s.GuestFeatures;
3005
3006 /* Use the VMX MSR features from the saved state while exploding guest features. */
3007 GuestMsrs.hwvirt.vmx = pVM->apCpusR3[0]->cpum.s.Guest.hwvirt.vmx.Msrs;
3008 }
3009
3010 /* Load CPUID and explode guest features. */
3011 rc = cpumR3LoadCpuId(pVM, pSSM, uVersion, &GuestMsrs);
3012 if (fVmxGstFeat)
3013 {
3014 /*
3015 * Check if the exploded VMX features from the saved state are compatible with the host-derived features
3016 * we cached earlier (above). The is required if we use hardware-assisted nested-guest execution with
3017 * VMX features presented to the guest.
3018 */
3019 bool const fIsCompat = cpumR3AreVmxCpuFeaturesCompatible(pVM, &BaseFeatures, &pVM->cpum.s.GuestFeatures);
3020 if (!fIsCompat)
3021 return VERR_CPUM_INVALID_HWVIRT_FEAT_COMBO;
3022 }
3023 return rc;
3024 }
3025 return cpumR3LoadCpuIdPre32(pVM, pSSM, uVersion);
3026}
3027
3028
3029/**
3030 * @callback_method_impl{FNSSMINTLOADDONE}
3031 */
3032static DECLCALLBACK(int) cpumR3LoadDone(PVM pVM, PSSMHANDLE pSSM)
3033{
3034 if (RT_FAILURE(SSMR3HandleGetStatus(pSSM)))
3035 return VINF_SUCCESS;
3036
3037 /* just check this since we can. */ /** @todo Add a SSM unit flag for indicating that it's mandatory during a restore. */
3038 if (pVM->cpum.s.fPendingRestore)
3039 {
3040 LogRel(("CPUM: Missing state!\n"));
3041 return VERR_INTERNAL_ERROR_2;
3042 }
3043
3044 bool const fSupportsLongMode = VMR3IsLongModeAllowed(pVM);
3045 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
3046 {
3047 PVMCPU pVCpu = pVM->apCpusR3[idCpu];
3048
3049 /* Notify PGM of the NXE states in case they've changed. */
3050 PGMNotifyNxeChanged(pVCpu, RT_BOOL(pVCpu->cpum.s.Guest.msrEFER & MSR_K6_EFER_NXE));
3051
3052 /* During init. this is done in CPUMR3InitCompleted(). */
3053 if (fSupportsLongMode)
3054 pVCpu->cpum.s.fUseFlags |= CPUM_USE_SUPPORTS_LONGMODE;
3055
3056 /* Recalc the CPUM_USE_DEBUG_REGS_HYPER value. */
3057 CPUMRecalcHyperDRx(pVCpu, UINT8_MAX);
3058 }
3059 return VINF_SUCCESS;
3060}
3061
3062
3063/**
3064 * Checks if the CPUM state restore is still pending.
3065 *
3066 * @returns true / false.
3067 * @param pVM The cross context VM structure.
3068 */
3069VMMDECL(bool) CPUMR3IsStateRestorePending(PVM pVM)
3070{
3071 return pVM->cpum.s.fPendingRestore;
3072}
3073
3074
3075/**
3076 * Formats the EFLAGS value into mnemonics.
3077 *
3078 * @param pszEFlags Where to write the mnemonics. (Assumes sufficient buffer space.)
3079 * @param efl The EFLAGS value.
3080 */
3081static void cpumR3InfoFormatFlags(char *pszEFlags, uint32_t efl)
3082{
3083 /*
3084 * Format the flags.
3085 */
3086 static const struct
3087 {
3088 const char *pszSet; const char *pszClear; uint32_t fFlag;
3089 } s_aFlags[] =
3090 {
3091 { "vip",NULL, X86_EFL_VIP },
3092 { "vif",NULL, X86_EFL_VIF },
3093 { "ac", NULL, X86_EFL_AC },
3094 { "vm", NULL, X86_EFL_VM },
3095 { "rf", NULL, X86_EFL_RF },
3096 { "nt", NULL, X86_EFL_NT },
3097 { "ov", "nv", X86_EFL_OF },
3098 { "dn", "up", X86_EFL_DF },
3099 { "ei", "di", X86_EFL_IF },
3100 { "tf", NULL, X86_EFL_TF },
3101 { "nt", "pl", X86_EFL_SF },
3102 { "nz", "zr", X86_EFL_ZF },
3103 { "ac", "na", X86_EFL_AF },
3104 { "po", "pe", X86_EFL_PF },
3105 { "cy", "nc", X86_EFL_CF },
3106 };
3107 char *psz = pszEFlags;
3108 for (unsigned i = 0; i < RT_ELEMENTS(s_aFlags); i++)
3109 {
3110 const char *pszAdd = s_aFlags[i].fFlag & efl ? s_aFlags[i].pszSet : s_aFlags[i].pszClear;
3111 if (pszAdd)
3112 {
3113 strcpy(psz, pszAdd);
3114 psz += strlen(pszAdd);
3115 *psz++ = ' ';
3116 }
3117 }
3118 psz[-1] = '\0';
3119}
3120
3121
3122/**
3123 * Formats a full register dump.
3124 *
3125 * @param pVM The cross context VM structure.
3126 * @param pCtx The context to format.
3127 * @param pCtxCore The context core to format.
3128 * @param pHlp Output functions.
3129 * @param enmType The dump type.
3130 * @param pszPrefix Register name prefix.
3131 */
3132static void cpumR3InfoOne(PVM pVM, PCPUMCTX pCtx, PCCPUMCTXCORE pCtxCore, PCDBGFINFOHLP pHlp, CPUMDUMPTYPE enmType,
3133 const char *pszPrefix)
3134{
3135 NOREF(pVM);
3136
3137 /*
3138 * Format the EFLAGS.
3139 */
3140 uint32_t efl = pCtxCore->eflags.u32;
3141 char szEFlags[80];
3142 cpumR3InfoFormatFlags(&szEFlags[0], efl);
3143
3144 /*
3145 * Format the registers.
3146 */
3147 switch (enmType)
3148 {
3149 case CPUMDUMPTYPE_TERSE:
3150 if (CPUMIsGuestIn64BitCodeEx(pCtx))
3151 pHlp->pfnPrintf(pHlp,
3152 "%srax=%016RX64 %srbx=%016RX64 %srcx=%016RX64 %srdx=%016RX64\n"
3153 "%srsi=%016RX64 %srdi=%016RX64 %sr8 =%016RX64 %sr9 =%016RX64\n"
3154 "%sr10=%016RX64 %sr11=%016RX64 %sr12=%016RX64 %sr13=%016RX64\n"
3155 "%sr14=%016RX64 %sr15=%016RX64\n"
3156 "%srip=%016RX64 %srsp=%016RX64 %srbp=%016RX64 %siopl=%d %*s\n"
3157 "%scs=%04x %sss=%04x %sds=%04x %ses=%04x %sfs=%04x %sgs=%04x %seflags=%08x\n",
3158 pszPrefix, pCtxCore->rax, pszPrefix, pCtxCore->rbx, pszPrefix, pCtxCore->rcx, pszPrefix, pCtxCore->rdx, pszPrefix, pCtxCore->rsi, pszPrefix, pCtxCore->rdi,
3159 pszPrefix, pCtxCore->r8, pszPrefix, pCtxCore->r9, pszPrefix, pCtxCore->r10, pszPrefix, pCtxCore->r11, pszPrefix, pCtxCore->r12, pszPrefix, pCtxCore->r13,
3160 pszPrefix, pCtxCore->r14, pszPrefix, pCtxCore->r15,
3161 pszPrefix, pCtxCore->rip, pszPrefix, pCtxCore->rsp, pszPrefix, pCtxCore->rbp, pszPrefix, X86_EFL_GET_IOPL(efl), *pszPrefix ? 33 : 31, szEFlags,
3162 pszPrefix, pCtxCore->cs.Sel, pszPrefix, pCtxCore->ss.Sel, pszPrefix, pCtxCore->ds.Sel, pszPrefix, pCtxCore->es.Sel,
3163 pszPrefix, pCtxCore->fs.Sel, pszPrefix, pCtxCore->gs.Sel, pszPrefix, efl);
3164 else
3165 pHlp->pfnPrintf(pHlp,
3166 "%seax=%08x %sebx=%08x %secx=%08x %sedx=%08x %sesi=%08x %sedi=%08x\n"
3167 "%seip=%08x %sesp=%08x %sebp=%08x %siopl=%d %*s\n"
3168 "%scs=%04x %sss=%04x %sds=%04x %ses=%04x %sfs=%04x %sgs=%04x %seflags=%08x\n",
3169 pszPrefix, pCtxCore->eax, pszPrefix, pCtxCore->ebx, pszPrefix, pCtxCore->ecx, pszPrefix, pCtxCore->edx, pszPrefix, pCtxCore->esi, pszPrefix, pCtxCore->edi,
3170 pszPrefix, pCtxCore->eip, pszPrefix, pCtxCore->esp, pszPrefix, pCtxCore->ebp, pszPrefix, X86_EFL_GET_IOPL(efl), *pszPrefix ? 33 : 31, szEFlags,
3171 pszPrefix, pCtxCore->cs.Sel, pszPrefix, pCtxCore->ss.Sel, pszPrefix, pCtxCore->ds.Sel, pszPrefix, pCtxCore->es.Sel,
3172 pszPrefix, pCtxCore->fs.Sel, pszPrefix, pCtxCore->gs.Sel, pszPrefix, efl);
3173 break;
3174
3175 case CPUMDUMPTYPE_DEFAULT:
3176 if (CPUMIsGuestIn64BitCodeEx(pCtx))
3177 pHlp->pfnPrintf(pHlp,
3178 "%srax=%016RX64 %srbx=%016RX64 %srcx=%016RX64 %srdx=%016RX64\n"
3179 "%srsi=%016RX64 %srdi=%016RX64 %sr8 =%016RX64 %sr9 =%016RX64\n"
3180 "%sr10=%016RX64 %sr11=%016RX64 %sr12=%016RX64 %sr13=%016RX64\n"
3181 "%sr14=%016RX64 %sr15=%016RX64\n"
3182 "%srip=%016RX64 %srsp=%016RX64 %srbp=%016RX64 %siopl=%d %*s\n"
3183 "%scs=%04x %sss=%04x %sds=%04x %ses=%04x %sfs=%04x %sgs=%04x %str=%04x %seflags=%08x\n"
3184 "%scr0=%08RX64 %scr2=%08RX64 %scr3=%08RX64 %scr4=%08RX64 %sgdtr=%016RX64:%04x %sldtr=%04x\n"
3185 ,
3186 pszPrefix, pCtxCore->rax, pszPrefix, pCtxCore->rbx, pszPrefix, pCtxCore->rcx, pszPrefix, pCtxCore->rdx, pszPrefix, pCtxCore->rsi, pszPrefix, pCtxCore->rdi,
3187 pszPrefix, pCtxCore->r8, pszPrefix, pCtxCore->r9, pszPrefix, pCtxCore->r10, pszPrefix, pCtxCore->r11, pszPrefix, pCtxCore->r12, pszPrefix, pCtxCore->r13,
3188 pszPrefix, pCtxCore->r14, pszPrefix, pCtxCore->r15,
3189 pszPrefix, pCtxCore->rip, pszPrefix, pCtxCore->rsp, pszPrefix, pCtxCore->rbp, pszPrefix, X86_EFL_GET_IOPL(efl), *pszPrefix ? 33 : 31, szEFlags,
3190 pszPrefix, pCtxCore->cs.Sel, pszPrefix, pCtxCore->ss.Sel, pszPrefix, pCtxCore->ds.Sel, pszPrefix, pCtxCore->es.Sel,
3191 pszPrefix, pCtxCore->fs.Sel, pszPrefix, pCtxCore->gs.Sel, pszPrefix, pCtx->tr.Sel, pszPrefix, efl,
3192 pszPrefix, pCtx->cr0, pszPrefix, pCtx->cr2, pszPrefix, pCtx->cr3, pszPrefix, pCtx->cr4,
3193 pszPrefix, pCtx->gdtr.pGdt, pCtx->gdtr.cbGdt, pszPrefix, pCtx->ldtr.Sel);
3194 else
3195 pHlp->pfnPrintf(pHlp,
3196 "%seax=%08x %sebx=%08x %secx=%08x %sedx=%08x %sesi=%08x %sedi=%08x\n"
3197 "%seip=%08x %sesp=%08x %sebp=%08x %siopl=%d %*s\n"
3198 "%scs=%04x %sss=%04x %sds=%04x %ses=%04x %sfs=%04x %sgs=%04x %str=%04x %seflags=%08x\n"
3199 "%scr0=%08RX64 %scr2=%08RX64 %scr3=%08RX64 %scr4=%08RX64 %sgdtr=%08RX64:%04x %sldtr=%04x\n"
3200 ,
3201 pszPrefix, pCtxCore->eax, pszPrefix, pCtxCore->ebx, pszPrefix, pCtxCore->ecx, pszPrefix, pCtxCore->edx, pszPrefix, pCtxCore->esi, pszPrefix, pCtxCore->edi,
3202 pszPrefix, pCtxCore->eip, pszPrefix, pCtxCore->esp, pszPrefix, pCtxCore->ebp, pszPrefix, X86_EFL_GET_IOPL(efl), *pszPrefix ? 33 : 31, szEFlags,
3203 pszPrefix, pCtxCore->cs.Sel, pszPrefix, pCtxCore->ss.Sel, pszPrefix, pCtxCore->ds.Sel, pszPrefix, pCtxCore->es.Sel,
3204 pszPrefix, pCtxCore->fs.Sel, pszPrefix, pCtxCore->gs.Sel, pszPrefix, pCtx->tr.Sel, pszPrefix, efl,
3205 pszPrefix, pCtx->cr0, pszPrefix, pCtx->cr2, pszPrefix, pCtx->cr3, pszPrefix, pCtx->cr4,
3206 pszPrefix, pCtx->gdtr.pGdt, pCtx->gdtr.cbGdt, pszPrefix, pCtx->ldtr.Sel);
3207 break;
3208
3209 case CPUMDUMPTYPE_VERBOSE:
3210 if (CPUMIsGuestIn64BitCodeEx(pCtx))
3211 pHlp->pfnPrintf(pHlp,
3212 "%srax=%016RX64 %srbx=%016RX64 %srcx=%016RX64 %srdx=%016RX64\n"
3213 "%srsi=%016RX64 %srdi=%016RX64 %sr8 =%016RX64 %sr9 =%016RX64\n"
3214 "%sr10=%016RX64 %sr11=%016RX64 %sr12=%016RX64 %sr13=%016RX64\n"
3215 "%sr14=%016RX64 %sr15=%016RX64\n"
3216 "%srip=%016RX64 %srsp=%016RX64 %srbp=%016RX64 %siopl=%d %*s\n"
3217 "%scs={%04x base=%016RX64 limit=%08x flags=%08x}\n"
3218 "%sds={%04x base=%016RX64 limit=%08x flags=%08x}\n"
3219 "%ses={%04x base=%016RX64 limit=%08x flags=%08x}\n"
3220 "%sfs={%04x base=%016RX64 limit=%08x flags=%08x}\n"
3221 "%sgs={%04x base=%016RX64 limit=%08x flags=%08x}\n"
3222 "%sss={%04x base=%016RX64 limit=%08x flags=%08x}\n"
3223 "%scr0=%016RX64 %scr2=%016RX64 %scr3=%016RX64 %scr4=%016RX64\n"
3224 "%sdr0=%016RX64 %sdr1=%016RX64 %sdr2=%016RX64 %sdr3=%016RX64\n"
3225 "%sdr4=%016RX64 %sdr5=%016RX64 %sdr6=%016RX64 %sdr7=%016RX64\n"
3226 "%sgdtr=%016RX64:%04x %sidtr=%016RX64:%04x %seflags=%08x\n"
3227 "%sldtr={%04x base=%08RX64 limit=%08x flags=%08x}\n"
3228 "%str ={%04x base=%08RX64 limit=%08x flags=%08x}\n"
3229 "%sSysEnter={cs=%04llx eip=%016RX64 esp=%016RX64}\n"
3230 ,
3231 pszPrefix, pCtxCore->rax, pszPrefix, pCtxCore->rbx, pszPrefix, pCtxCore->rcx, pszPrefix, pCtxCore->rdx, pszPrefix, pCtxCore->rsi, pszPrefix, pCtxCore->rdi,
3232 pszPrefix, pCtxCore->r8, pszPrefix, pCtxCore->r9, pszPrefix, pCtxCore->r10, pszPrefix, pCtxCore->r11, pszPrefix, pCtxCore->r12, pszPrefix, pCtxCore->r13,
3233 pszPrefix, pCtxCore->r14, pszPrefix, pCtxCore->r15,
3234 pszPrefix, pCtxCore->rip, pszPrefix, pCtxCore->rsp, pszPrefix, pCtxCore->rbp, pszPrefix, X86_EFL_GET_IOPL(efl), *pszPrefix ? 33 : 31, szEFlags,
3235 pszPrefix, pCtxCore->cs.Sel, pCtx->cs.u64Base, pCtx->cs.u32Limit, pCtx->cs.Attr.u,
3236 pszPrefix, pCtxCore->ds.Sel, pCtx->ds.u64Base, pCtx->ds.u32Limit, pCtx->ds.Attr.u,
3237 pszPrefix, pCtxCore->es.Sel, pCtx->es.u64Base, pCtx->es.u32Limit, pCtx->es.Attr.u,
3238 pszPrefix, pCtxCore->fs.Sel, pCtx->fs.u64Base, pCtx->fs.u32Limit, pCtx->fs.Attr.u,
3239 pszPrefix, pCtxCore->gs.Sel, pCtx->gs.u64Base, pCtx->gs.u32Limit, pCtx->gs.Attr.u,
3240 pszPrefix, pCtxCore->ss.Sel, pCtx->ss.u64Base, pCtx->ss.u32Limit, pCtx->ss.Attr.u,
3241 pszPrefix, pCtx->cr0, pszPrefix, pCtx->cr2, pszPrefix, pCtx->cr3, pszPrefix, pCtx->cr4,
3242 pszPrefix, pCtx->dr[0], pszPrefix, pCtx->dr[1], pszPrefix, pCtx->dr[2], pszPrefix, pCtx->dr[3],
3243 pszPrefix, pCtx->dr[4], pszPrefix, pCtx->dr[5], pszPrefix, pCtx->dr[6], pszPrefix, pCtx->dr[7],
3244 pszPrefix, pCtx->gdtr.pGdt, pCtx->gdtr.cbGdt, pszPrefix, pCtx->idtr.pIdt, pCtx->idtr.cbIdt, pszPrefix, efl,
3245 pszPrefix, pCtx->ldtr.Sel, pCtx->ldtr.u64Base, pCtx->ldtr.u32Limit, pCtx->ldtr.Attr.u,
3246 pszPrefix, pCtx->tr.Sel, pCtx->tr.u64Base, pCtx->tr.u32Limit, pCtx->tr.Attr.u,
3247 pszPrefix, pCtx->SysEnter.cs, pCtx->SysEnter.eip, pCtx->SysEnter.esp);
3248 else
3249 pHlp->pfnPrintf(pHlp,
3250 "%seax=%08x %sebx=%08x %secx=%08x %sedx=%08x %sesi=%08x %sedi=%08x\n"
3251 "%seip=%08x %sesp=%08x %sebp=%08x %siopl=%d %*s\n"
3252 "%scs={%04x base=%016RX64 limit=%08x flags=%08x} %sdr0=%08RX64 %sdr1=%08RX64\n"
3253 "%sds={%04x base=%016RX64 limit=%08x flags=%08x} %sdr2=%08RX64 %sdr3=%08RX64\n"
3254 "%ses={%04x base=%016RX64 limit=%08x flags=%08x} %sdr4=%08RX64 %sdr5=%08RX64\n"
3255 "%sfs={%04x base=%016RX64 limit=%08x flags=%08x} %sdr6=%08RX64 %sdr7=%08RX64\n"
3256 "%sgs={%04x base=%016RX64 limit=%08x flags=%08x} %scr0=%08RX64 %scr2=%08RX64\n"
3257 "%sss={%04x base=%016RX64 limit=%08x flags=%08x} %scr3=%08RX64 %scr4=%08RX64\n"
3258 "%sgdtr=%016RX64:%04x %sidtr=%016RX64:%04x %seflags=%08x\n"
3259 "%sldtr={%04x base=%08RX64 limit=%08x flags=%08x}\n"
3260 "%str ={%04x base=%08RX64 limit=%08x flags=%08x}\n"
3261 "%sSysEnter={cs=%04llx eip=%08llx esp=%08llx}\n"
3262 ,
3263 pszPrefix, pCtxCore->eax, pszPrefix, pCtxCore->ebx, pszPrefix, pCtxCore->ecx, pszPrefix, pCtxCore->edx, pszPrefix, pCtxCore->esi, pszPrefix, pCtxCore->edi,
3264 pszPrefix, pCtxCore->eip, pszPrefix, pCtxCore->esp, pszPrefix, pCtxCore->ebp, pszPrefix, X86_EFL_GET_IOPL(efl), *pszPrefix ? 33 : 31, szEFlags,
3265 pszPrefix, pCtxCore->cs.Sel, pCtx->cs.u64Base, pCtx->cs.u32Limit, pCtx->cs.Attr.u, pszPrefix, pCtx->dr[0], pszPrefix, pCtx->dr[1],
3266 pszPrefix, pCtxCore->ds.Sel, pCtx->ds.u64Base, pCtx->ds.u32Limit, pCtx->ds.Attr.u, pszPrefix, pCtx->dr[2], pszPrefix, pCtx->dr[3],
3267 pszPrefix, pCtxCore->es.Sel, pCtx->es.u64Base, pCtx->es.u32Limit, pCtx->es.Attr.u, pszPrefix, pCtx->dr[4], pszPrefix, pCtx->dr[5],
3268 pszPrefix, pCtxCore->fs.Sel, pCtx->fs.u64Base, pCtx->fs.u32Limit, pCtx->fs.Attr.u, pszPrefix, pCtx->dr[6], pszPrefix, pCtx->dr[7],
3269 pszPrefix, pCtxCore->gs.Sel, pCtx->gs.u64Base, pCtx->gs.u32Limit, pCtx->gs.Attr.u, pszPrefix, pCtx->cr0, pszPrefix, pCtx->cr2,
3270 pszPrefix, pCtxCore->ss.Sel, pCtx->ss.u64Base, pCtx->ss.u32Limit, pCtx->ss.Attr.u, pszPrefix, pCtx->cr3, pszPrefix, pCtx->cr4,
3271 pszPrefix, pCtx->gdtr.pGdt, pCtx->gdtr.cbGdt, pszPrefix, pCtx->idtr.pIdt, pCtx->idtr.cbIdt, pszPrefix, efl,
3272 pszPrefix, pCtx->ldtr.Sel, pCtx->ldtr.u64Base, pCtx->ldtr.u32Limit, pCtx->ldtr.Attr.u,
3273 pszPrefix, pCtx->tr.Sel, pCtx->tr.u64Base, pCtx->tr.u32Limit, pCtx->tr.Attr.u,
3274 pszPrefix, pCtx->SysEnter.cs, pCtx->SysEnter.eip, pCtx->SysEnter.esp);
3275
3276 pHlp->pfnPrintf(pHlp, "%sxcr=%016RX64 %sxcr1=%016RX64 %sxss=%016RX64 (fXStateMask=%016RX64)\n",
3277 pszPrefix, pCtx->aXcr[0], pszPrefix, pCtx->aXcr[1],
3278 pszPrefix, UINT64_C(0) /** @todo XSS */, pCtx->fXStateMask);
3279 {
3280 PX86FXSTATE pFpuCtx = &pCtx->XState.x87;
3281 pHlp->pfnPrintf(pHlp,
3282 "%sFCW=%04x %sFSW=%04x %sFTW=%04x %sFOP=%04x %sMXCSR=%08x %sMXCSR_MASK=%08x\n"
3283 "%sFPUIP=%08x %sCS=%04x %sRsrvd1=%04x %sFPUDP=%08x %sDS=%04x %sRsvrd2=%04x\n"
3284 ,
3285 pszPrefix, pFpuCtx->FCW, pszPrefix, pFpuCtx->FSW, pszPrefix, pFpuCtx->FTW, pszPrefix, pFpuCtx->FOP,
3286 pszPrefix, pFpuCtx->MXCSR, pszPrefix, pFpuCtx->MXCSR_MASK,
3287 pszPrefix, pFpuCtx->FPUIP, pszPrefix, pFpuCtx->CS, pszPrefix, pFpuCtx->Rsrvd1,
3288 pszPrefix, pFpuCtx->FPUDP, pszPrefix, pFpuCtx->DS, pszPrefix, pFpuCtx->Rsrvd2
3289 );
3290 /*
3291 * The FSAVE style memory image contains ST(0)-ST(7) at increasing addresses,
3292 * not (FP)R0-7 as Intel SDM suggests.
3293 */
3294 unsigned iShift = (pFpuCtx->FSW >> 11) & 7;
3295 for (unsigned iST = 0; iST < RT_ELEMENTS(pFpuCtx->aRegs); iST++)
3296 {
3297 unsigned iFPR = (iST + iShift) % RT_ELEMENTS(pFpuCtx->aRegs);
3298 unsigned uTag = (pFpuCtx->FTW >> (2 * iFPR)) & 3;
3299 char chSign = pFpuCtx->aRegs[iST].au16[4] & 0x8000 ? '-' : '+';
3300 unsigned iInteger = (unsigned)(pFpuCtx->aRegs[iST].au64[0] >> 63);
3301 uint64_t u64Fraction = pFpuCtx->aRegs[iST].au64[0] & UINT64_C(0x7fffffffffffffff);
3302 int iExponent = pFpuCtx->aRegs[iST].au16[4] & 0x7fff;
3303 iExponent -= 16383; /* subtract bias */
3304 /** @todo This isn't entirenly correct and needs more work! */
3305 pHlp->pfnPrintf(pHlp,
3306 "%sST(%u)=%sFPR%u={%04RX16'%08RX32'%08RX32} t%d %c%u.%022llu * 2 ^ %d (*)",
3307 pszPrefix, iST, pszPrefix, iFPR,
3308 pFpuCtx->aRegs[iST].au16[4], pFpuCtx->aRegs[iST].au32[1], pFpuCtx->aRegs[iST].au32[0],
3309 uTag, chSign, iInteger, u64Fraction, iExponent);
3310 if (pFpuCtx->aRegs[iST].au16[5] || pFpuCtx->aRegs[iST].au16[6] || pFpuCtx->aRegs[iST].au16[7])
3311 pHlp->pfnPrintf(pHlp, " res={%04RX16,%04RX16,%04RX16}\n",
3312 pFpuCtx->aRegs[iST].au16[5], pFpuCtx->aRegs[iST].au16[6], pFpuCtx->aRegs[iST].au16[7]);
3313 else
3314 pHlp->pfnPrintf(pHlp, "\n");
3315 }
3316
3317 /* XMM/YMM/ZMM registers. */
3318 if (pCtx->fXStateMask & XSAVE_C_YMM)
3319 {
3320 PCX86XSAVEYMMHI pYmmHiCtx = CPUMCTX_XSAVE_C_PTR(pCtx, XSAVE_C_YMM_BIT, PCX86XSAVEYMMHI);
3321 if (!(pCtx->fXStateMask & XSAVE_C_ZMM_HI256))
3322 for (unsigned i = 0; i < RT_ELEMENTS(pFpuCtx->aXMM); i++)
3323 pHlp->pfnPrintf(pHlp, "%sYMM%u%s=%08RX32'%08RX32'%08RX32'%08RX32'%08RX32'%08RX32'%08RX32'%08RX32\n",
3324 pszPrefix, i, i < 10 ? " " : "",
3325 pYmmHiCtx->aYmmHi[i].au32[3],
3326 pYmmHiCtx->aYmmHi[i].au32[2],
3327 pYmmHiCtx->aYmmHi[i].au32[1],
3328 pYmmHiCtx->aYmmHi[i].au32[0],
3329 pFpuCtx->aXMM[i].au32[3],
3330 pFpuCtx->aXMM[i].au32[2],
3331 pFpuCtx->aXMM[i].au32[1],
3332 pFpuCtx->aXMM[i].au32[0]);
3333 else
3334 {
3335 PCX86XSAVEZMMHI256 pZmmHi256 = CPUMCTX_XSAVE_C_PTR(pCtx, XSAVE_C_ZMM_HI256_BIT, PCX86XSAVEZMMHI256);
3336 for (unsigned i = 0; i < RT_ELEMENTS(pFpuCtx->aXMM); i++)
3337 pHlp->pfnPrintf(pHlp,
3338 "%sZMM%u%s=%08RX32'%08RX32'%08RX32'%08RX32'%08RX32'%08RX32'%08RX32'%08RX32''%08RX32'%08RX32'%08RX32'%08RX32'%08RX32'%08RX32'%08RX32'%08RX32\n",
3339 pszPrefix, i, i < 10 ? " " : "",
3340 pZmmHi256->aHi256Regs[i].au32[7],
3341 pZmmHi256->aHi256Regs[i].au32[6],
3342 pZmmHi256->aHi256Regs[i].au32[5],
3343 pZmmHi256->aHi256Regs[i].au32[4],
3344 pZmmHi256->aHi256Regs[i].au32[3],
3345 pZmmHi256->aHi256Regs[i].au32[2],
3346 pZmmHi256->aHi256Regs[i].au32[1],
3347 pZmmHi256->aHi256Regs[i].au32[0],
3348 pYmmHiCtx->aYmmHi[i].au32[3],
3349 pYmmHiCtx->aYmmHi[i].au32[2],
3350 pYmmHiCtx->aYmmHi[i].au32[1],
3351 pYmmHiCtx->aYmmHi[i].au32[0],
3352 pFpuCtx->aXMM[i].au32[3],
3353 pFpuCtx->aXMM[i].au32[2],
3354 pFpuCtx->aXMM[i].au32[1],
3355 pFpuCtx->aXMM[i].au32[0]);
3356
3357 PCX86XSAVEZMM16HI pZmm16Hi = CPUMCTX_XSAVE_C_PTR(pCtx, XSAVE_C_ZMM_16HI_BIT, PCX86XSAVEZMM16HI);
3358 for (unsigned i = 0; i < RT_ELEMENTS(pZmm16Hi->aRegs); i++)
3359 pHlp->pfnPrintf(pHlp,
3360 "%sZMM%u=%08RX32'%08RX32'%08RX32'%08RX32'%08RX32'%08RX32'%08RX32'%08RX32''%08RX32'%08RX32'%08RX32'%08RX32'%08RX32'%08RX32'%08RX32'%08RX32\n",
3361 pszPrefix, i + 16,
3362 pZmm16Hi->aRegs[i].au32[15],
3363 pZmm16Hi->aRegs[i].au32[14],
3364 pZmm16Hi->aRegs[i].au32[13],
3365 pZmm16Hi->aRegs[i].au32[12],
3366 pZmm16Hi->aRegs[i].au32[11],
3367 pZmm16Hi->aRegs[i].au32[10],
3368 pZmm16Hi->aRegs[i].au32[9],
3369 pZmm16Hi->aRegs[i].au32[8],
3370 pZmm16Hi->aRegs[i].au32[7],
3371 pZmm16Hi->aRegs[i].au32[6],
3372 pZmm16Hi->aRegs[i].au32[5],
3373 pZmm16Hi->aRegs[i].au32[4],
3374 pZmm16Hi->aRegs[i].au32[3],
3375 pZmm16Hi->aRegs[i].au32[2],
3376 pZmm16Hi->aRegs[i].au32[1],
3377 pZmm16Hi->aRegs[i].au32[0]);
3378 }
3379 }
3380 else
3381 for (unsigned i = 0; i < RT_ELEMENTS(pFpuCtx->aXMM); i++)
3382 pHlp->pfnPrintf(pHlp,
3383 i & 1
3384 ? "%sXMM%u%s=%08RX32'%08RX32'%08RX32'%08RX32\n"
3385 : "%sXMM%u%s=%08RX32'%08RX32'%08RX32'%08RX32 ",
3386 pszPrefix, i, i < 10 ? " " : "",
3387 pFpuCtx->aXMM[i].au32[3],
3388 pFpuCtx->aXMM[i].au32[2],
3389 pFpuCtx->aXMM[i].au32[1],
3390 pFpuCtx->aXMM[i].au32[0]);
3391
3392 if (pCtx->fXStateMask & XSAVE_C_OPMASK)
3393 {
3394 PCX86XSAVEOPMASK pOpMask = CPUMCTX_XSAVE_C_PTR(pCtx, XSAVE_C_OPMASK_BIT, PCX86XSAVEOPMASK);
3395 for (unsigned i = 0; i < RT_ELEMENTS(pOpMask->aKRegs); i += 4)
3396 pHlp->pfnPrintf(pHlp, "%sK%u=%016RX64 %sK%u=%016RX64 %sK%u=%016RX64 %sK%u=%016RX64\n",
3397 pszPrefix, i + 0, pOpMask->aKRegs[i + 0],
3398 pszPrefix, i + 1, pOpMask->aKRegs[i + 1],
3399 pszPrefix, i + 2, pOpMask->aKRegs[i + 2],
3400 pszPrefix, i + 3, pOpMask->aKRegs[i + 3]);
3401 }
3402
3403 if (pCtx->fXStateMask & XSAVE_C_BNDREGS)
3404 {
3405 PCX86XSAVEBNDREGS pBndRegs = CPUMCTX_XSAVE_C_PTR(pCtx, XSAVE_C_BNDREGS_BIT, PCX86XSAVEBNDREGS);
3406 for (unsigned i = 0; i < RT_ELEMENTS(pBndRegs->aRegs); i += 2)
3407 pHlp->pfnPrintf(pHlp, "%sBNDREG%u=%016RX64/%016RX64 %sBNDREG%u=%016RX64/%016RX64\n",
3408 pszPrefix, i, pBndRegs->aRegs[i].uLowerBound, pBndRegs->aRegs[i].uUpperBound,
3409 pszPrefix, i + 1, pBndRegs->aRegs[i + 1].uLowerBound, pBndRegs->aRegs[i + 1].uUpperBound);
3410 }
3411
3412 if (pCtx->fXStateMask & XSAVE_C_BNDCSR)
3413 {
3414 PCX86XSAVEBNDCFG pBndCfg = CPUMCTX_XSAVE_C_PTR(pCtx, XSAVE_C_BNDCSR_BIT, PCX86XSAVEBNDCFG);
3415 pHlp->pfnPrintf(pHlp, "%sBNDCFG.CONFIG=%016RX64 %sBNDCFG.STATUS=%016RX64\n",
3416 pszPrefix, pBndCfg->fConfig, pszPrefix, pBndCfg->fStatus);
3417 }
3418
3419 for (unsigned i = 0; i < RT_ELEMENTS(pFpuCtx->au32RsrvdRest); i++)
3420 if (pFpuCtx->au32RsrvdRest[i])
3421 pHlp->pfnPrintf(pHlp, "%sRsrvdRest[%u]=%RX32 (offset=%#x)\n",
3422 pszPrefix, i, pFpuCtx->au32RsrvdRest[i], RT_UOFFSETOF_DYN(X86FXSTATE, au32RsrvdRest[i]) );
3423 }
3424
3425 pHlp->pfnPrintf(pHlp,
3426 "%sEFER =%016RX64\n"
3427 "%sPAT =%016RX64\n"
3428 "%sSTAR =%016RX64\n"
3429 "%sCSTAR =%016RX64\n"
3430 "%sLSTAR =%016RX64\n"
3431 "%sSFMASK =%016RX64\n"
3432 "%sKERNELGSBASE =%016RX64\n",
3433 pszPrefix, pCtx->msrEFER,
3434 pszPrefix, pCtx->msrPAT,
3435 pszPrefix, pCtx->msrSTAR,
3436 pszPrefix, pCtx->msrCSTAR,
3437 pszPrefix, pCtx->msrLSTAR,
3438 pszPrefix, pCtx->msrSFMASK,
3439 pszPrefix, pCtx->msrKERNELGSBASE);
3440
3441 if (CPUMIsGuestInPAEModeEx(pCtx))
3442 for (unsigned i = 0; i < RT_ELEMENTS(pCtx->aPaePdpes); i++)
3443 pHlp->pfnPrintf(pHlp, "%sPAE PDPTE %u =%016RX64\n", pszPrefix, i, pCtx->aPaePdpes[i]);
3444 break;
3445 }
3446}
3447
3448
3449/**
3450 * Display all cpu states and any other cpum info.
3451 *
3452 * @param pVM The cross context VM structure.
3453 * @param pHlp The info helper functions.
3454 * @param pszArgs Arguments, ignored.
3455 */
3456static DECLCALLBACK(void) cpumR3InfoAll(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs)
3457{
3458 cpumR3InfoGuest(pVM, pHlp, pszArgs);
3459 cpumR3InfoGuestInstr(pVM, pHlp, pszArgs);
3460 cpumR3InfoGuestHwvirt(pVM, pHlp, pszArgs);
3461 cpumR3InfoHyper(pVM, pHlp, pszArgs);
3462 cpumR3InfoHost(pVM, pHlp, pszArgs);
3463}
3464
3465
3466/**
3467 * Parses the info argument.
3468 *
3469 * The argument starts with 'verbose', 'terse' or 'default' and then
3470 * continues with the comment string.
3471 *
3472 * @param pszArgs The pointer to the argument string.
3473 * @param penmType Where to store the dump type request.
3474 * @param ppszComment Where to store the pointer to the comment string.
3475 */
3476static void cpumR3InfoParseArg(const char *pszArgs, CPUMDUMPTYPE *penmType, const char **ppszComment)
3477{
3478 if (!pszArgs)
3479 {
3480 *penmType = CPUMDUMPTYPE_DEFAULT;
3481 *ppszComment = "";
3482 }
3483 else
3484 {
3485 if (!strncmp(pszArgs, RT_STR_TUPLE("verbose")))
3486 {
3487 pszArgs += 7;
3488 *penmType = CPUMDUMPTYPE_VERBOSE;
3489 }
3490 else if (!strncmp(pszArgs, RT_STR_TUPLE("terse")))
3491 {
3492 pszArgs += 5;
3493 *penmType = CPUMDUMPTYPE_TERSE;
3494 }
3495 else if (!strncmp(pszArgs, RT_STR_TUPLE("default")))
3496 {
3497 pszArgs += 7;
3498 *penmType = CPUMDUMPTYPE_DEFAULT;
3499 }
3500 else
3501 *penmType = CPUMDUMPTYPE_DEFAULT;
3502 *ppszComment = RTStrStripL(pszArgs);
3503 }
3504}
3505
3506
3507/**
3508 * Display the guest cpu state.
3509 *
3510 * @param pVM The cross context VM structure.
3511 * @param pHlp The info helper functions.
3512 * @param pszArgs Arguments.
3513 */
3514static DECLCALLBACK(void) cpumR3InfoGuest(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs)
3515{
3516 CPUMDUMPTYPE enmType;
3517 const char *pszComment;
3518 cpumR3InfoParseArg(pszArgs, &enmType, &pszComment);
3519
3520 PVMCPU pVCpu = VMMGetCpu(pVM);
3521 if (!pVCpu)
3522 pVCpu = pVM->apCpusR3[0];
3523
3524 pHlp->pfnPrintf(pHlp, "Guest CPUM (VCPU %d) state: %s\n", pVCpu->idCpu, pszComment);
3525
3526 PCPUMCTX pCtx = &pVCpu->cpum.s.Guest;
3527 cpumR3InfoOne(pVM, pCtx, CPUMCTX2CORE(pCtx), pHlp, enmType, "");
3528}
3529
3530
3531/**
3532 * Displays an SVM VMCB control area.
3533 *
3534 * @param pHlp The info helper functions.
3535 * @param pVmcbCtrl Pointer to a SVM VMCB controls area.
3536 * @param pszPrefix Caller specified string prefix.
3537 */
3538static void cpumR3InfoSvmVmcbCtrl(PCDBGFINFOHLP pHlp, PCSVMVMCBCTRL pVmcbCtrl, const char *pszPrefix)
3539{
3540 AssertReturnVoid(pHlp);
3541 AssertReturnVoid(pVmcbCtrl);
3542
3543 pHlp->pfnPrintf(pHlp, "%sCRX-read intercepts = %#RX16\n", pszPrefix, pVmcbCtrl->u16InterceptRdCRx);
3544 pHlp->pfnPrintf(pHlp, "%sCRX-write intercepts = %#RX16\n", pszPrefix, pVmcbCtrl->u16InterceptWrCRx);
3545 pHlp->pfnPrintf(pHlp, "%sDRX-read intercepts = %#RX16\n", pszPrefix, pVmcbCtrl->u16InterceptRdDRx);
3546 pHlp->pfnPrintf(pHlp, "%sDRX-write intercepts = %#RX16\n", pszPrefix, pVmcbCtrl->u16InterceptWrDRx);
3547 pHlp->pfnPrintf(pHlp, "%sException intercepts = %#RX32\n", pszPrefix, pVmcbCtrl->u32InterceptXcpt);
3548 pHlp->pfnPrintf(pHlp, "%sControl intercepts = %#RX64\n", pszPrefix, pVmcbCtrl->u64InterceptCtrl);
3549 pHlp->pfnPrintf(pHlp, "%sPause-filter threshold = %#RX16\n", pszPrefix, pVmcbCtrl->u16PauseFilterThreshold);
3550 pHlp->pfnPrintf(pHlp, "%sPause-filter count = %#RX16\n", pszPrefix, pVmcbCtrl->u16PauseFilterCount);
3551 pHlp->pfnPrintf(pHlp, "%sIOPM bitmap physaddr = %#RX64\n", pszPrefix, pVmcbCtrl->u64IOPMPhysAddr);
3552 pHlp->pfnPrintf(pHlp, "%sMSRPM bitmap physaddr = %#RX64\n", pszPrefix, pVmcbCtrl->u64MSRPMPhysAddr);
3553 pHlp->pfnPrintf(pHlp, "%sTSC offset = %#RX64\n", pszPrefix, pVmcbCtrl->u64TSCOffset);
3554 pHlp->pfnPrintf(pHlp, "%sTLB Control\n", pszPrefix);
3555 pHlp->pfnPrintf(pHlp, " %sASID = %#RX32\n", pszPrefix, pVmcbCtrl->TLBCtrl.n.u32ASID);
3556 pHlp->pfnPrintf(pHlp, " %sTLB-flush type = %u\n", pszPrefix, pVmcbCtrl->TLBCtrl.n.u8TLBFlush);
3557 pHlp->pfnPrintf(pHlp, "%sInterrupt Control\n", pszPrefix);
3558 pHlp->pfnPrintf(pHlp, " %sVTPR = %#RX8 (%u)\n", pszPrefix, pVmcbCtrl->IntCtrl.n.u8VTPR, pVmcbCtrl->IntCtrl.n.u8VTPR);
3559 pHlp->pfnPrintf(pHlp, " %sVIRQ (Pending) = %RTbool\n", pszPrefix, pVmcbCtrl->IntCtrl.n.u1VIrqPending);
3560 pHlp->pfnPrintf(pHlp, " %sVINTR vector = %#RX8\n", pszPrefix, pVmcbCtrl->IntCtrl.n.u8VIntrVector);
3561 pHlp->pfnPrintf(pHlp, " %sVGIF = %u\n", pszPrefix, pVmcbCtrl->IntCtrl.n.u1VGif);
3562 pHlp->pfnPrintf(pHlp, " %sVINTR priority = %#RX8\n", pszPrefix, pVmcbCtrl->IntCtrl.n.u4VIntrPrio);
3563 pHlp->pfnPrintf(pHlp, " %sIgnore TPR = %RTbool\n", pszPrefix, pVmcbCtrl->IntCtrl.n.u1IgnoreTPR);
3564 pHlp->pfnPrintf(pHlp, " %sVINTR masking = %RTbool\n", pszPrefix, pVmcbCtrl->IntCtrl.n.u1VIntrMasking);
3565 pHlp->pfnPrintf(pHlp, " %sVGIF enable = %RTbool\n", pszPrefix, pVmcbCtrl->IntCtrl.n.u1VGifEnable);
3566 pHlp->pfnPrintf(pHlp, " %sAVIC enable = %RTbool\n", pszPrefix, pVmcbCtrl->IntCtrl.n.u1AvicEnable);
3567 pHlp->pfnPrintf(pHlp, "%sInterrupt Shadow\n", pszPrefix);
3568 pHlp->pfnPrintf(pHlp, " %sInterrupt shadow = %RTbool\n", pszPrefix, pVmcbCtrl->IntShadow.n.u1IntShadow);
3569 pHlp->pfnPrintf(pHlp, " %sGuest-interrupt Mask = %RTbool\n", pszPrefix, pVmcbCtrl->IntShadow.n.u1GuestIntMask);
3570 pHlp->pfnPrintf(pHlp, "%sExit Code = %#RX64\n", pszPrefix, pVmcbCtrl->u64ExitCode);
3571 pHlp->pfnPrintf(pHlp, "%sEXITINFO1 = %#RX64\n", pszPrefix, pVmcbCtrl->u64ExitInfo1);
3572 pHlp->pfnPrintf(pHlp, "%sEXITINFO2 = %#RX64\n", pszPrefix, pVmcbCtrl->u64ExitInfo2);
3573 pHlp->pfnPrintf(pHlp, "%sExit Interrupt Info\n", pszPrefix);
3574 pHlp->pfnPrintf(pHlp, " %sValid = %RTbool\n", pszPrefix, pVmcbCtrl->ExitIntInfo.n.u1Valid);
3575 pHlp->pfnPrintf(pHlp, " %sVector = %#RX8 (%u)\n", pszPrefix, pVmcbCtrl->ExitIntInfo.n.u8Vector, pVmcbCtrl->ExitIntInfo.n.u8Vector);
3576 pHlp->pfnPrintf(pHlp, " %sType = %u\n", pszPrefix, pVmcbCtrl->ExitIntInfo.n.u3Type);
3577 pHlp->pfnPrintf(pHlp, " %sError-code valid = %RTbool\n", pszPrefix, pVmcbCtrl->ExitIntInfo.n.u1ErrorCodeValid);
3578 pHlp->pfnPrintf(pHlp, " %sError-code = %#RX32\n", pszPrefix, pVmcbCtrl->ExitIntInfo.n.u32ErrorCode);
3579 pHlp->pfnPrintf(pHlp, "%sNested paging and SEV\n", pszPrefix);
3580 pHlp->pfnPrintf(pHlp, " %sNested paging = %RTbool\n", pszPrefix, pVmcbCtrl->NestedPagingCtrl.n.u1NestedPaging);
3581 pHlp->pfnPrintf(pHlp, " %sSEV (Secure Encrypted VM) = %RTbool\n", pszPrefix, pVmcbCtrl->NestedPagingCtrl.n.u1Sev);
3582 pHlp->pfnPrintf(pHlp, " %sSEV-ES (Encrypted State) = %RTbool\n", pszPrefix, pVmcbCtrl->NestedPagingCtrl.n.u1SevEs);
3583 pHlp->pfnPrintf(pHlp, "%sEvent Inject\n", pszPrefix);
3584 pHlp->pfnPrintf(pHlp, " %sValid = %RTbool\n", pszPrefix, pVmcbCtrl->EventInject.n.u1Valid);
3585 pHlp->pfnPrintf(pHlp, " %sVector = %#RX32 (%u)\n", pszPrefix, pVmcbCtrl->EventInject.n.u8Vector, pVmcbCtrl->EventInject.n.u8Vector);
3586 pHlp->pfnPrintf(pHlp, " %sType = %u\n", pszPrefix, pVmcbCtrl->EventInject.n.u3Type);
3587 pHlp->pfnPrintf(pHlp, " %sError-code valid = %RTbool\n", pszPrefix, pVmcbCtrl->EventInject.n.u1ErrorCodeValid);
3588 pHlp->pfnPrintf(pHlp, " %sError-code = %#RX32\n", pszPrefix, pVmcbCtrl->EventInject.n.u32ErrorCode);
3589 pHlp->pfnPrintf(pHlp, "%sNested-paging CR3 = %#RX64\n", pszPrefix, pVmcbCtrl->u64NestedPagingCR3);
3590 pHlp->pfnPrintf(pHlp, "%sLBR Virtualization\n", pszPrefix);
3591 pHlp->pfnPrintf(pHlp, " %sLBR virt = %RTbool\n", pszPrefix, pVmcbCtrl->LbrVirt.n.u1LbrVirt);
3592 pHlp->pfnPrintf(pHlp, " %sVirt. VMSAVE/VMLOAD = %RTbool\n", pszPrefix, pVmcbCtrl->LbrVirt.n.u1VirtVmsaveVmload);
3593 pHlp->pfnPrintf(pHlp, "%sVMCB Clean Bits = %#RX32\n", pszPrefix, pVmcbCtrl->u32VmcbCleanBits);
3594 pHlp->pfnPrintf(pHlp, "%sNext-RIP = %#RX64\n", pszPrefix, pVmcbCtrl->u64NextRIP);
3595 pHlp->pfnPrintf(pHlp, "%sInstruction bytes fetched = %u\n", pszPrefix, pVmcbCtrl->cbInstrFetched);
3596 pHlp->pfnPrintf(pHlp, "%sInstruction bytes = %.*Rhxs\n", pszPrefix, sizeof(pVmcbCtrl->abInstr), pVmcbCtrl->abInstr);
3597 pHlp->pfnPrintf(pHlp, "%sAVIC\n", pszPrefix);
3598 pHlp->pfnPrintf(pHlp, " %sBar addr = %#RX64\n", pszPrefix, pVmcbCtrl->AvicBar.n.u40Addr);
3599 pHlp->pfnPrintf(pHlp, " %sBacking page addr = %#RX64\n", pszPrefix, pVmcbCtrl->AvicBackingPagePtr.n.u40Addr);
3600 pHlp->pfnPrintf(pHlp, " %sLogical table addr = %#RX64\n", pszPrefix, pVmcbCtrl->AvicLogicalTablePtr.n.u40Addr);
3601 pHlp->pfnPrintf(pHlp, " %sPhysical table addr = %#RX64\n", pszPrefix, pVmcbCtrl->AvicPhysicalTablePtr.n.u40Addr);
3602 pHlp->pfnPrintf(pHlp, " %sLast guest core Id = %u\n", pszPrefix, pVmcbCtrl->AvicPhysicalTablePtr.n.u8LastGuestCoreId);
3603}
3604
3605
3606/**
3607 * Helper for dumping the SVM VMCB selector registers.
3608 *
3609 * @param pHlp The info helper functions.
3610 * @param pSel Pointer to the SVM selector register.
3611 * @param pszName Name of the selector.
3612 * @param pszPrefix Caller specified string prefix.
3613 */
3614DECLINLINE(void) cpumR3InfoSvmVmcbSelReg(PCDBGFINFOHLP pHlp, PCSVMSELREG pSel, const char *pszName, const char *pszPrefix)
3615{
3616 /* The string width of 4 used below is to handle 'LDTR'. Change later if longer register names are used. */
3617 pHlp->pfnPrintf(pHlp, "%s%-4s = {%04x base=%016RX64 limit=%08x flags=%04x}\n", pszPrefix,
3618 pszName, pSel->u16Sel, pSel->u64Base, pSel->u32Limit, pSel->u16Attr);
3619}
3620
3621
3622/**
3623 * Helper for dumping the SVM VMCB GDTR/IDTR registers.
3624 *
3625 * @param pHlp The info helper functions.
3626 * @param pXdtr Pointer to the descriptor table register.
3627 * @param pszName Name of the descriptor table register.
3628 * @param pszPrefix Caller specified string prefix.
3629 */
3630DECLINLINE(void) cpumR3InfoSvmVmcbXdtr(PCDBGFINFOHLP pHlp, PCSVMXDTR pXdtr, const char *pszName, const char *pszPrefix)
3631{
3632 /* The string width of 4 used below is to cover 'GDTR', 'IDTR'. Change later if longer register names are used. */
3633 pHlp->pfnPrintf(pHlp, "%s%-4s = %016RX64:%04x\n", pszPrefix, pszName, pXdtr->u64Base, pXdtr->u32Limit);
3634}
3635
3636
3637/**
3638 * Displays an SVM VMCB state-save area.
3639 *
3640 * @param pHlp The info helper functions.
3641 * @param pVmcbStateSave Pointer to a SVM VMCB controls area.
3642 * @param pszPrefix Caller specified string prefix.
3643 */
3644static void cpumR3InfoSvmVmcbStateSave(PCDBGFINFOHLP pHlp, PCSVMVMCBSTATESAVE pVmcbStateSave, const char *pszPrefix)
3645{
3646 AssertReturnVoid(pHlp);
3647 AssertReturnVoid(pVmcbStateSave);
3648
3649 char szEFlags[80];
3650 cpumR3InfoFormatFlags(&szEFlags[0], pVmcbStateSave->u64RFlags);
3651
3652 cpumR3InfoSvmVmcbSelReg(pHlp, &pVmcbStateSave->CS, "CS", pszPrefix);
3653 cpumR3InfoSvmVmcbSelReg(pHlp, &pVmcbStateSave->SS, "SS", pszPrefix);
3654 cpumR3InfoSvmVmcbSelReg(pHlp, &pVmcbStateSave->ES, "ES", pszPrefix);
3655 cpumR3InfoSvmVmcbSelReg(pHlp, &pVmcbStateSave->DS, "DS", pszPrefix);
3656 cpumR3InfoSvmVmcbSelReg(pHlp, &pVmcbStateSave->FS, "FS", pszPrefix);
3657 cpumR3InfoSvmVmcbSelReg(pHlp, &pVmcbStateSave->GS, "GS", pszPrefix);
3658 cpumR3InfoSvmVmcbSelReg(pHlp, &pVmcbStateSave->LDTR, "LDTR", pszPrefix);
3659 cpumR3InfoSvmVmcbSelReg(pHlp, &pVmcbStateSave->TR, "TR", pszPrefix);
3660 cpumR3InfoSvmVmcbXdtr(pHlp, &pVmcbStateSave->GDTR, "GDTR", pszPrefix);
3661 cpumR3InfoSvmVmcbXdtr(pHlp, &pVmcbStateSave->IDTR, "IDTR", pszPrefix);
3662 pHlp->pfnPrintf(pHlp, "%sCPL = %u\n", pszPrefix, pVmcbStateSave->u8CPL);
3663 pHlp->pfnPrintf(pHlp, "%sEFER = %#RX64\n", pszPrefix, pVmcbStateSave->u64EFER);
3664 pHlp->pfnPrintf(pHlp, "%sCR4 = %#RX64\n", pszPrefix, pVmcbStateSave->u64CR4);
3665 pHlp->pfnPrintf(pHlp, "%sCR3 = %#RX64\n", pszPrefix, pVmcbStateSave->u64CR3);
3666 pHlp->pfnPrintf(pHlp, "%sCR0 = %#RX64\n", pszPrefix, pVmcbStateSave->u64CR0);
3667 pHlp->pfnPrintf(pHlp, "%sDR7 = %#RX64\n", pszPrefix, pVmcbStateSave->u64DR7);
3668 pHlp->pfnPrintf(pHlp, "%sDR6 = %#RX64\n", pszPrefix, pVmcbStateSave->u64DR6);
3669 pHlp->pfnPrintf(pHlp, "%sRFLAGS = %#RX64 %31s\n", pszPrefix, pVmcbStateSave->u64RFlags, szEFlags);
3670 pHlp->pfnPrintf(pHlp, "%sRIP = %#RX64\n", pszPrefix, pVmcbStateSave->u64RIP);
3671 pHlp->pfnPrintf(pHlp, "%sRSP = %#RX64\n", pszPrefix, pVmcbStateSave->u64RSP);
3672 pHlp->pfnPrintf(pHlp, "%sRAX = %#RX64\n", pszPrefix, pVmcbStateSave->u64RAX);
3673 pHlp->pfnPrintf(pHlp, "%sSTAR = %#RX64\n", pszPrefix, pVmcbStateSave->u64STAR);
3674 pHlp->pfnPrintf(pHlp, "%sLSTAR = %#RX64\n", pszPrefix, pVmcbStateSave->u64LSTAR);
3675 pHlp->pfnPrintf(pHlp, "%sCSTAR = %#RX64\n", pszPrefix, pVmcbStateSave->u64CSTAR);
3676 pHlp->pfnPrintf(pHlp, "%sSFMASK = %#RX64\n", pszPrefix, pVmcbStateSave->u64SFMASK);
3677 pHlp->pfnPrintf(pHlp, "%sKERNELGSBASE = %#RX64\n", pszPrefix, pVmcbStateSave->u64KernelGSBase);
3678 pHlp->pfnPrintf(pHlp, "%sSysEnter CS = %#RX64\n", pszPrefix, pVmcbStateSave->u64SysEnterCS);
3679 pHlp->pfnPrintf(pHlp, "%sSysEnter EIP = %#RX64\n", pszPrefix, pVmcbStateSave->u64SysEnterEIP);
3680 pHlp->pfnPrintf(pHlp, "%sSysEnter ESP = %#RX64\n", pszPrefix, pVmcbStateSave->u64SysEnterESP);
3681 pHlp->pfnPrintf(pHlp, "%sCR2 = %#RX64\n", pszPrefix, pVmcbStateSave->u64CR2);
3682 pHlp->pfnPrintf(pHlp, "%sPAT = %#RX64\n", pszPrefix, pVmcbStateSave->u64PAT);
3683 pHlp->pfnPrintf(pHlp, "%sDBGCTL = %#RX64\n", pszPrefix, pVmcbStateSave->u64DBGCTL);
3684 pHlp->pfnPrintf(pHlp, "%sBR_FROM = %#RX64\n", pszPrefix, pVmcbStateSave->u64BR_FROM);
3685 pHlp->pfnPrintf(pHlp, "%sBR_TO = %#RX64\n", pszPrefix, pVmcbStateSave->u64BR_TO);
3686 pHlp->pfnPrintf(pHlp, "%sLASTXCPT_FROM = %#RX64\n", pszPrefix, pVmcbStateSave->u64LASTEXCPFROM);
3687 pHlp->pfnPrintf(pHlp, "%sLASTXCPT_TO = %#RX64\n", pszPrefix, pVmcbStateSave->u64LASTEXCPTO);
3688}
3689
3690
3691/**
3692 * Displays a virtual-VMCS.
3693 *
3694 * @param pVCpu The cross context virtual CPU structure.
3695 * @param pHlp The info helper functions.
3696 * @param pVmcs Pointer to a virtual VMCS.
3697 * @param pszPrefix Caller specified string prefix.
3698 */
3699static void cpumR3InfoVmxVmcs(PVMCPU pVCpu, PCDBGFINFOHLP pHlp, PCVMXVVMCS pVmcs, const char *pszPrefix)
3700{
3701 AssertReturnVoid(pHlp);
3702 AssertReturnVoid(pVmcs);
3703
3704 /* The string width of -4 used in the macros below to cover 'LDTR', 'GDTR', 'IDTR. */
3705#define CPUMVMX_DUMP_HOST_XDTR(a_pHlp, a_pVmcs, a_Seg, a_SegName, a_pszPrefix) \
3706 do { \
3707 (a_pHlp)->pfnPrintf((a_pHlp), " %s%-4s = {base=%016RX64}\n", \
3708 (a_pszPrefix), (a_SegName), (a_pVmcs)->u64Host##a_Seg##Base.u); \
3709 } while (0)
3710
3711#define CPUMVMX_DUMP_HOST_FS_GS_TR(a_pHlp, a_pVmcs, a_Seg, a_SegName, a_pszPrefix) \
3712 do { \
3713 (a_pHlp)->pfnPrintf((a_pHlp), " %s%-4s = {%04x base=%016RX64}\n", \
3714 (a_pszPrefix), (a_SegName), (a_pVmcs)->Host##a_Seg, (a_pVmcs)->u64Host##a_Seg##Base.u); \
3715 } while (0)
3716
3717#define CPUMVMX_DUMP_GUEST_SEGREG(a_pHlp, a_pVmcs, a_Seg, a_SegName, a_pszPrefix) \
3718 do { \
3719 (a_pHlp)->pfnPrintf((a_pHlp), " %s%-4s = {%04x base=%016RX64 limit=%08x flags=%04x}\n", \
3720 (a_pszPrefix), (a_SegName), (a_pVmcs)->Guest##a_Seg, (a_pVmcs)->u64Guest##a_Seg##Base.u, \
3721 (a_pVmcs)->u32Guest##a_Seg##Limit, (a_pVmcs)->u32Guest##a_Seg##Attr); \
3722 } while (0)
3723
3724#define CPUMVMX_DUMP_GUEST_XDTR(a_pHlp, a_pVmcs, a_Seg, a_SegName, a_pszPrefix) \
3725 do { \
3726 (a_pHlp)->pfnPrintf((a_pHlp), " %s%-4s = {base=%016RX64 limit=%08x}\n", \
3727 (a_pszPrefix), (a_SegName), (a_pVmcs)->u64Guest##a_Seg##Base.u, (a_pVmcs)->u32Guest##a_Seg##Limit); \
3728 } while (0)
3729
3730 /* Header. */
3731 {
3732 pHlp->pfnPrintf(pHlp, "%sHeader:\n", pszPrefix);
3733 pHlp->pfnPrintf(pHlp, " %sVMCS revision id = %#RX32\n", pszPrefix, pVmcs->u32VmcsRevId);
3734 pHlp->pfnPrintf(pHlp, " %sVMX-abort id = %#RX32 (%s)\n", pszPrefix, pVmcs->enmVmxAbort, VMXGetAbortDesc(pVmcs->enmVmxAbort));
3735 pHlp->pfnPrintf(pHlp, " %sVMCS state = %#x (%s)\n", pszPrefix, pVmcs->fVmcsState, VMXGetVmcsStateDesc(pVmcs->fVmcsState));
3736 }
3737
3738 /* Control fields. */
3739 {
3740 /* 16-bit. */
3741 pHlp->pfnPrintf(pHlp, "%sControl:\n", pszPrefix);
3742 pHlp->pfnPrintf(pHlp, " %sVPID = %#RX16\n", pszPrefix, pVmcs->u16Vpid);
3743 pHlp->pfnPrintf(pHlp, " %sPosted intr notify vector = %#RX16\n", pszPrefix, pVmcs->u16PostIntNotifyVector);
3744 pHlp->pfnPrintf(pHlp, " %sEPTP index = %#RX16\n", pszPrefix, pVmcs->u16EptpIndex);
3745
3746 /* 32-bit. */
3747 pHlp->pfnPrintf(pHlp, " %sPin ctls = %#RX32\n", pszPrefix, pVmcs->u32PinCtls);
3748 pHlp->pfnPrintf(pHlp, " %sProcessor ctls = %#RX32\n", pszPrefix, pVmcs->u32ProcCtls);
3749 pHlp->pfnPrintf(pHlp, " %sSecondary processor ctls = %#RX32\n", pszPrefix, pVmcs->u32ProcCtls2);
3750 pHlp->pfnPrintf(pHlp, " %sVM-exit ctls = %#RX32\n", pszPrefix, pVmcs->u32ExitCtls);
3751 pHlp->pfnPrintf(pHlp, " %sVM-entry ctls = %#RX32\n", pszPrefix, pVmcs->u32EntryCtls);
3752 pHlp->pfnPrintf(pHlp, " %sException bitmap = %#RX32\n", pszPrefix, pVmcs->u32XcptBitmap);
3753 pHlp->pfnPrintf(pHlp, " %sPage-fault mask = %#RX32\n", pszPrefix, pVmcs->u32XcptPFMask);
3754 pHlp->pfnPrintf(pHlp, " %sPage-fault match = %#RX32\n", pszPrefix, pVmcs->u32XcptPFMatch);
3755 pHlp->pfnPrintf(pHlp, " %sCR3-target count = %RU32\n", pszPrefix, pVmcs->u32Cr3TargetCount);
3756 pHlp->pfnPrintf(pHlp, " %sVM-exit MSR store count = %RU32\n", pszPrefix, pVmcs->u32ExitMsrStoreCount);
3757 pHlp->pfnPrintf(pHlp, " %sVM-exit MSR load count = %RU32\n", pszPrefix, pVmcs->u32ExitMsrLoadCount);
3758 pHlp->pfnPrintf(pHlp, " %sVM-entry MSR load count = %RU32\n", pszPrefix, pVmcs->u32EntryMsrLoadCount);
3759 pHlp->pfnPrintf(pHlp, " %sVM-entry interruption info = %#RX32\n", pszPrefix, pVmcs->u32EntryIntInfo);
3760 {
3761 uint32_t const fInfo = pVmcs->u32EntryIntInfo;
3762 uint8_t const uType = VMX_ENTRY_INT_INFO_TYPE(fInfo);
3763 pHlp->pfnPrintf(pHlp, " %sValid = %RTbool\n", pszPrefix, VMX_ENTRY_INT_INFO_IS_VALID(fInfo));
3764 pHlp->pfnPrintf(pHlp, " %sType = %#x (%s)\n", pszPrefix, uType, VMXGetEntryIntInfoTypeDesc(uType));
3765 pHlp->pfnPrintf(pHlp, " %sVector = %#x\n", pszPrefix, VMX_ENTRY_INT_INFO_VECTOR(fInfo));
3766 pHlp->pfnPrintf(pHlp, " %sNMI-unblocking-IRET = %RTbool\n", pszPrefix, VMX_ENTRY_INT_INFO_IS_NMI_UNBLOCK_IRET(fInfo));
3767 pHlp->pfnPrintf(pHlp, " %sError-code valid = %RTbool\n", pszPrefix, VMX_ENTRY_INT_INFO_IS_ERROR_CODE_VALID(fInfo));
3768 }
3769 pHlp->pfnPrintf(pHlp, " %sVM-entry xcpt error-code = %#RX32\n", pszPrefix, pVmcs->u32EntryXcptErrCode);
3770 pHlp->pfnPrintf(pHlp, " %sVM-entry instr length = %u byte(s)\n", pszPrefix, pVmcs->u32EntryInstrLen);
3771 pHlp->pfnPrintf(pHlp, " %sTPR threshold = %#RX32\n", pszPrefix, pVmcs->u32TprThreshold);
3772 pHlp->pfnPrintf(pHlp, " %sPLE gap = %#RX32\n", pszPrefix, pVmcs->u32PleGap);
3773 pHlp->pfnPrintf(pHlp, " %sPLE window = %#RX32\n", pszPrefix, pVmcs->u32PleWindow);
3774
3775 /* 64-bit. */
3776 pHlp->pfnPrintf(pHlp, " %sIO-bitmap A addr = %#RX64\n", pszPrefix, pVmcs->u64AddrIoBitmapA.u);
3777 pHlp->pfnPrintf(pHlp, " %sIO-bitmap B addr = %#RX64\n", pszPrefix, pVmcs->u64AddrIoBitmapB.u);
3778 pHlp->pfnPrintf(pHlp, " %sMSR-bitmap addr = %#RX64\n", pszPrefix, pVmcs->u64AddrMsrBitmap.u);
3779 pHlp->pfnPrintf(pHlp, " %sVM-exit MSR store addr = %#RX64\n", pszPrefix, pVmcs->u64AddrExitMsrStore.u);
3780 pHlp->pfnPrintf(pHlp, " %sVM-exit MSR load addr = %#RX64\n", pszPrefix, pVmcs->u64AddrExitMsrLoad.u);
3781 pHlp->pfnPrintf(pHlp, " %sVM-entry MSR load addr = %#RX64\n", pszPrefix, pVmcs->u64AddrEntryMsrLoad.u);
3782 pHlp->pfnPrintf(pHlp, " %sExecutive VMCS ptr = %#RX64\n", pszPrefix, pVmcs->u64ExecVmcsPtr.u);
3783 pHlp->pfnPrintf(pHlp, " %sPML addr = %#RX64\n", pszPrefix, pVmcs->u64AddrPml.u);
3784 pHlp->pfnPrintf(pHlp, " %sTSC offset = %#RX64\n", pszPrefix, pVmcs->u64TscOffset.u);
3785 pHlp->pfnPrintf(pHlp, " %sVirtual-APIC addr = %#RX64\n", pszPrefix, pVmcs->u64AddrVirtApic.u);
3786 pHlp->pfnPrintf(pHlp, " %sAPIC-access addr = %#RX64\n", pszPrefix, pVmcs->u64AddrApicAccess.u);
3787 pHlp->pfnPrintf(pHlp, " %sPosted-intr desc addr = %#RX64\n", pszPrefix, pVmcs->u64AddrPostedIntDesc.u);
3788 pHlp->pfnPrintf(pHlp, " %sVM-functions control = %#RX64\n", pszPrefix, pVmcs->u64VmFuncCtls.u);
3789 pHlp->pfnPrintf(pHlp, " %sEPTP ptr = %#RX64\n", pszPrefix, pVmcs->u64EptPtr.u);
3790 pHlp->pfnPrintf(pHlp, " %sEOI-exit bitmap 0 = %#RX64\n", pszPrefix, pVmcs->u64EoiExitBitmap0.u);
3791 pHlp->pfnPrintf(pHlp, " %sEOI-exit bitmap 1 = %#RX64\n", pszPrefix, pVmcs->u64EoiExitBitmap1.u);
3792 pHlp->pfnPrintf(pHlp, " %sEOI-exit bitmap 2 = %#RX64\n", pszPrefix, pVmcs->u64EoiExitBitmap2.u);
3793 pHlp->pfnPrintf(pHlp, " %sEOI-exit bitmap 3 = %#RX64\n", pszPrefix, pVmcs->u64EoiExitBitmap3.u);
3794 pHlp->pfnPrintf(pHlp, " %sEPTP-list addr = %#RX64\n", pszPrefix, pVmcs->u64AddrEptpList.u);
3795 pHlp->pfnPrintf(pHlp, " %sVMREAD-bitmap addr = %#RX64\n", pszPrefix, pVmcs->u64AddrVmreadBitmap.u);
3796 pHlp->pfnPrintf(pHlp, " %sVMWRITE-bitmap addr = %#RX64\n", pszPrefix, pVmcs->u64AddrVmwriteBitmap.u);
3797 pHlp->pfnPrintf(pHlp, " %sVirt-Xcpt info addr = %#RX64\n", pszPrefix, pVmcs->u64AddrXcptVeInfo.u);
3798 pHlp->pfnPrintf(pHlp, " %sXSS-exiting bitmap = %#RX64\n", pszPrefix, pVmcs->u64XssExitBitmap.u);
3799 pHlp->pfnPrintf(pHlp, " %sENCLS-exiting bitmap = %#RX64\n", pszPrefix, pVmcs->u64EnclsExitBitmap.u);
3800 pHlp->pfnPrintf(pHlp, " %sSPP-table ptr = %#RX64\n", pszPrefix, pVmcs->u64SppTablePtr.u);
3801 pHlp->pfnPrintf(pHlp, " %sTSC multiplier = %#RX64\n", pszPrefix, pVmcs->u64TscMultiplier.u);
3802 pHlp->pfnPrintf(pHlp, " %sTertiary processor ctls = %#RX64\n", pszPrefix, pVmcs->u64ProcCtls3.u);
3803 pHlp->pfnPrintf(pHlp, " %sENCLV-exiting bitmap = %#RX64\n", pszPrefix, pVmcs->u64EnclvExitBitmap.u);
3804
3805 /* Natural width. */
3806 pHlp->pfnPrintf(pHlp, " %sCR0 guest/host mask = %#RX64\n", pszPrefix, pVmcs->u64Cr0Mask.u);
3807 pHlp->pfnPrintf(pHlp, " %sCR4 guest/host mask = %#RX64\n", pszPrefix, pVmcs->u64Cr4Mask.u);
3808 pHlp->pfnPrintf(pHlp, " %sCR0 read shadow = %#RX64\n", pszPrefix, pVmcs->u64Cr0ReadShadow.u);
3809 pHlp->pfnPrintf(pHlp, " %sCR4 read shadow = %#RX64\n", pszPrefix, pVmcs->u64Cr4ReadShadow.u);
3810 pHlp->pfnPrintf(pHlp, " %sCR3-target 0 = %#RX64\n", pszPrefix, pVmcs->u64Cr3Target0.u);
3811 pHlp->pfnPrintf(pHlp, " %sCR3-target 1 = %#RX64\n", pszPrefix, pVmcs->u64Cr3Target1.u);
3812 pHlp->pfnPrintf(pHlp, " %sCR3-target 2 = %#RX64\n", pszPrefix, pVmcs->u64Cr3Target2.u);
3813 pHlp->pfnPrintf(pHlp, " %sCR3-target 3 = %#RX64\n", pszPrefix, pVmcs->u64Cr3Target3.u);
3814 }
3815
3816 /* Guest state. */
3817 {
3818 char szEFlags[80];
3819 cpumR3InfoFormatFlags(&szEFlags[0], pVmcs->u64GuestRFlags.u);
3820 pHlp->pfnPrintf(pHlp, "%sGuest state:\n", pszPrefix);
3821
3822 /* 16-bit. */
3823 CPUMVMX_DUMP_GUEST_SEGREG(pHlp, pVmcs, Cs, "CS", pszPrefix);
3824 CPUMVMX_DUMP_GUEST_SEGREG(pHlp, pVmcs, Ss, "SS", pszPrefix);
3825 CPUMVMX_DUMP_GUEST_SEGREG(pHlp, pVmcs, Es, "ES", pszPrefix);
3826 CPUMVMX_DUMP_GUEST_SEGREG(pHlp, pVmcs, Ds, "DS", pszPrefix);
3827 CPUMVMX_DUMP_GUEST_SEGREG(pHlp, pVmcs, Fs, "FS", pszPrefix);
3828 CPUMVMX_DUMP_GUEST_SEGREG(pHlp, pVmcs, Gs, "GS", pszPrefix);
3829 CPUMVMX_DUMP_GUEST_SEGREG(pHlp, pVmcs, Ldtr, "LDTR", pszPrefix);
3830 CPUMVMX_DUMP_GUEST_SEGREG(pHlp, pVmcs, Tr, "TR", pszPrefix);
3831 CPUMVMX_DUMP_GUEST_XDTR(pHlp, pVmcs, Gdtr, "GDTR", pszPrefix);
3832 CPUMVMX_DUMP_GUEST_XDTR(pHlp, pVmcs, Idtr, "IDTR", pszPrefix);
3833 pHlp->pfnPrintf(pHlp, " %sInterrupt status = %#RX16\n", pszPrefix, pVmcs->u16GuestIntStatus);
3834 pHlp->pfnPrintf(pHlp, " %sPML index = %#RX16\n", pszPrefix, pVmcs->u16PmlIndex);
3835
3836 /* 32-bit. */
3837 pHlp->pfnPrintf(pHlp, " %sInterruptibility state = %#RX32\n", pszPrefix, pVmcs->u32GuestIntrState);
3838 pHlp->pfnPrintf(pHlp, " %sActivity state = %#RX32\n", pszPrefix, pVmcs->u32GuestActivityState);
3839 pHlp->pfnPrintf(pHlp, " %sSMBASE = %#RX32\n", pszPrefix, pVmcs->u32GuestSmBase);
3840 pHlp->pfnPrintf(pHlp, " %sSysEnter CS = %#RX32\n", pszPrefix, pVmcs->u32GuestSysenterCS);
3841 pHlp->pfnPrintf(pHlp, " %sVMX-preemption timer value = %#RX32\n", pszPrefix, pVmcs->u32PreemptTimer);
3842
3843 /* 64-bit. */
3844 pHlp->pfnPrintf(pHlp, " %sVMCS link ptr = %#RX64\n", pszPrefix, pVmcs->u64VmcsLinkPtr.u);
3845 pHlp->pfnPrintf(pHlp, " %sDBGCTL = %#RX64\n", pszPrefix, pVmcs->u64GuestDebugCtlMsr.u);
3846 pHlp->pfnPrintf(pHlp, " %sPAT = %#RX64\n", pszPrefix, pVmcs->u64GuestPatMsr.u);
3847 pHlp->pfnPrintf(pHlp, " %sEFER = %#RX64\n", pszPrefix, pVmcs->u64GuestEferMsr.u);
3848 pHlp->pfnPrintf(pHlp, " %sPERFGLOBALCTRL = %#RX64\n", pszPrefix, pVmcs->u64GuestPerfGlobalCtlMsr.u);
3849 pHlp->pfnPrintf(pHlp, " %sPDPTE 0 = %#RX64\n", pszPrefix, pVmcs->u64GuestPdpte0.u);
3850 pHlp->pfnPrintf(pHlp, " %sPDPTE 1 = %#RX64\n", pszPrefix, pVmcs->u64GuestPdpte1.u);
3851 pHlp->pfnPrintf(pHlp, " %sPDPTE 2 = %#RX64\n", pszPrefix, pVmcs->u64GuestPdpte2.u);
3852 pHlp->pfnPrintf(pHlp, " %sPDPTE 3 = %#RX64\n", pszPrefix, pVmcs->u64GuestPdpte3.u);
3853 pHlp->pfnPrintf(pHlp, " %sBNDCFGS = %#RX64\n", pszPrefix, pVmcs->u64GuestBndcfgsMsr.u);
3854 pHlp->pfnPrintf(pHlp, " %sRTIT_CTL = %#RX64\n", pszPrefix, pVmcs->u64GuestRtitCtlMsr.u);
3855 pHlp->pfnPrintf(pHlp, " %sPKRS = %#RX64\n", pszPrefix, pVmcs->u64GuestPkrsMsr.u);
3856
3857 /* Natural width. */
3858 pHlp->pfnPrintf(pHlp, " %sCR0 = %#RX64\n", pszPrefix, pVmcs->u64GuestCr0.u);
3859 pHlp->pfnPrintf(pHlp, " %sCR3 = %#RX64\n", pszPrefix, pVmcs->u64GuestCr3.u);
3860 pHlp->pfnPrintf(pHlp, " %sCR4 = %#RX64\n", pszPrefix, pVmcs->u64GuestCr4.u);
3861 pHlp->pfnPrintf(pHlp, " %sDR7 = %#RX64\n", pszPrefix, pVmcs->u64GuestDr7.u);
3862 pHlp->pfnPrintf(pHlp, " %sRSP = %#RX64\n", pszPrefix, pVmcs->u64GuestRsp.u);
3863 pHlp->pfnPrintf(pHlp, " %sRIP = %#RX64\n", pszPrefix, pVmcs->u64GuestRip.u);
3864 pHlp->pfnPrintf(pHlp, " %sRFLAGS = %#RX64 %31s\n",pszPrefix, pVmcs->u64GuestRFlags.u, szEFlags);
3865 pHlp->pfnPrintf(pHlp, " %sPending debug xcpts = %#RX64\n", pszPrefix, pVmcs->u64GuestPendingDbgXcpts.u);
3866 pHlp->pfnPrintf(pHlp, " %sSysEnter ESP = %#RX64\n", pszPrefix, pVmcs->u64GuestSysenterEsp.u);
3867 pHlp->pfnPrintf(pHlp, " %sSysEnter EIP = %#RX64\n", pszPrefix, pVmcs->u64GuestSysenterEip.u);
3868 pHlp->pfnPrintf(pHlp, " %sS_CET = %#RX64\n", pszPrefix, pVmcs->u64GuestSCetMsr.u);
3869 pHlp->pfnPrintf(pHlp, " %sSSP = %#RX64\n", pszPrefix, pVmcs->u64GuestSsp.u);
3870 pHlp->pfnPrintf(pHlp, " %sINTERRUPT_SSP_TABLE_ADDR = %#RX64\n", pszPrefix, pVmcs->u64GuestIntrSspTableAddrMsr.u);
3871 }
3872
3873 /* Host state. */
3874 {
3875 pHlp->pfnPrintf(pHlp, "%sHost state:\n", pszPrefix);
3876
3877 /* 16-bit. */
3878 pHlp->pfnPrintf(pHlp, " %sCS = %#RX16\n", pszPrefix, pVmcs->HostCs);
3879 pHlp->pfnPrintf(pHlp, " %sSS = %#RX16\n", pszPrefix, pVmcs->HostSs);
3880 pHlp->pfnPrintf(pHlp, " %sDS = %#RX16\n", pszPrefix, pVmcs->HostDs);
3881 pHlp->pfnPrintf(pHlp, " %sES = %#RX16\n", pszPrefix, pVmcs->HostEs);
3882 CPUMVMX_DUMP_HOST_FS_GS_TR(pHlp, pVmcs, Fs, "FS", pszPrefix);
3883 CPUMVMX_DUMP_HOST_FS_GS_TR(pHlp, pVmcs, Gs, "GS", pszPrefix);
3884 CPUMVMX_DUMP_HOST_FS_GS_TR(pHlp, pVmcs, Tr, "TR", pszPrefix);
3885 CPUMVMX_DUMP_HOST_XDTR(pHlp, pVmcs, Gdtr, "GDTR", pszPrefix);
3886 CPUMVMX_DUMP_HOST_XDTR(pHlp, pVmcs, Idtr, "IDTR", pszPrefix);
3887
3888 /* 32-bit. */
3889 pHlp->pfnPrintf(pHlp, " %sSysEnter CS = %#RX32\n", pszPrefix, pVmcs->u32HostSysenterCs);
3890
3891 /* 64-bit. */
3892 pHlp->pfnPrintf(pHlp, " %sEFER = %#RX64\n", pszPrefix, pVmcs->u64HostEferMsr.u);
3893 pHlp->pfnPrintf(pHlp, " %sPAT = %#RX64\n", pszPrefix, pVmcs->u64HostPatMsr.u);
3894 pHlp->pfnPrintf(pHlp, " %sPERFGLOBALCTRL = %#RX64\n", pszPrefix, pVmcs->u64HostPerfGlobalCtlMsr.u);
3895 pHlp->pfnPrintf(pHlp, " %sPKRS = %#RX64\n", pszPrefix, pVmcs->u64HostPkrsMsr.u);
3896
3897 /* Natural width. */
3898 pHlp->pfnPrintf(pHlp, " %sCR0 = %#RX64\n", pszPrefix, pVmcs->u64HostCr0.u);
3899 pHlp->pfnPrintf(pHlp, " %sCR3 = %#RX64\n", pszPrefix, pVmcs->u64HostCr3.u);
3900 pHlp->pfnPrintf(pHlp, " %sCR4 = %#RX64\n", pszPrefix, pVmcs->u64HostCr4.u);
3901 pHlp->pfnPrintf(pHlp, " %sSysEnter ESP = %#RX64\n", pszPrefix, pVmcs->u64HostSysenterEsp.u);
3902 pHlp->pfnPrintf(pHlp, " %sSysEnter EIP = %#RX64\n", pszPrefix, pVmcs->u64HostSysenterEip.u);
3903 pHlp->pfnPrintf(pHlp, " %sRSP = %#RX64\n", pszPrefix, pVmcs->u64HostRsp.u);
3904 pHlp->pfnPrintf(pHlp, " %sRIP = %#RX64\n", pszPrefix, pVmcs->u64HostRip.u);
3905 pHlp->pfnPrintf(pHlp, " %sS_CET = %#RX64\n", pszPrefix, pVmcs->u64HostSCetMsr.u);
3906 pHlp->pfnPrintf(pHlp, " %sSSP = %#RX64\n", pszPrefix, pVmcs->u64HostSsp.u);
3907 pHlp->pfnPrintf(pHlp, " %sINTERRUPT_SSP_TABLE_ADDR = %#RX64\n", pszPrefix, pVmcs->u64HostIntrSspTableAddrMsr.u);
3908
3909 }
3910
3911 /* Read-only fields. */
3912 {
3913 pHlp->pfnPrintf(pHlp, "%sRead-only data fields:\n", pszPrefix);
3914
3915 /* 16-bit (none currently). */
3916
3917 /* 32-bit. */
3918 pHlp->pfnPrintf(pHlp, " %sExit reason = %u (%s)\n", pszPrefix, pVmcs->u32RoExitReason, HMGetVmxExitName(pVmcs->u32RoExitReason));
3919 pHlp->pfnPrintf(pHlp, " %sExit qualification = %#RX64\n", pszPrefix, pVmcs->u64RoExitQual.u);
3920 pHlp->pfnPrintf(pHlp, " %sVM-instruction error = %#RX32\n", pszPrefix, pVmcs->u32RoVmInstrError);
3921 pHlp->pfnPrintf(pHlp, " %sVM-exit intr info = %#RX32\n", pszPrefix, pVmcs->u32RoExitIntInfo);
3922 {
3923 uint32_t const fInfo = pVmcs->u32RoExitIntInfo;
3924 uint8_t const uType = VMX_EXIT_INT_INFO_TYPE(fInfo);
3925 pHlp->pfnPrintf(pHlp, " %sValid = %RTbool\n", pszPrefix, VMX_EXIT_INT_INFO_IS_VALID(fInfo));
3926 pHlp->pfnPrintf(pHlp, " %sType = %#x (%s)\n", pszPrefix, uType, VMXGetExitIntInfoTypeDesc(uType));
3927 pHlp->pfnPrintf(pHlp, " %sVector = %#x\n", pszPrefix, VMX_EXIT_INT_INFO_VECTOR(fInfo));
3928 pHlp->pfnPrintf(pHlp, " %sNMI-unblocking-IRET = %RTbool\n", pszPrefix, VMX_EXIT_INT_INFO_IS_NMI_UNBLOCK_IRET(fInfo));
3929 pHlp->pfnPrintf(pHlp, " %sError-code valid = %RTbool\n", pszPrefix, VMX_EXIT_INT_INFO_IS_ERROR_CODE_VALID(fInfo));
3930 }
3931 pHlp->pfnPrintf(pHlp, " %sVM-exit intr error-code = %#RX32\n", pszPrefix, pVmcs->u32RoExitIntErrCode);
3932 pHlp->pfnPrintf(pHlp, " %sIDT-vectoring info = %#RX32\n", pszPrefix, pVmcs->u32RoIdtVectoringInfo);
3933 {
3934 uint32_t const fInfo = pVmcs->u32RoIdtVectoringInfo;
3935 uint8_t const uType = VMX_IDT_VECTORING_INFO_TYPE(fInfo);
3936 pHlp->pfnPrintf(pHlp, " %sValid = %RTbool\n", pszPrefix, VMX_IDT_VECTORING_INFO_IS_VALID(fInfo));
3937 pHlp->pfnPrintf(pHlp, " %sType = %#x (%s)\n", pszPrefix, uType, VMXGetIdtVectoringInfoTypeDesc(uType));
3938 pHlp->pfnPrintf(pHlp, " %sVector = %#x\n", pszPrefix, VMX_IDT_VECTORING_INFO_VECTOR(fInfo));
3939 pHlp->pfnPrintf(pHlp, " %sError-code valid = %RTbool\n", pszPrefix, VMX_IDT_VECTORING_INFO_IS_ERROR_CODE_VALID(fInfo));
3940 }
3941 pHlp->pfnPrintf(pHlp, " %sIDT-vectoring error-code = %#RX32\n", pszPrefix, pVmcs->u32RoIdtVectoringErrCode);
3942 pHlp->pfnPrintf(pHlp, " %sVM-exit instruction length = %u byte(s)\n", pszPrefix, pVmcs->u32RoExitInstrLen);
3943 pHlp->pfnPrintf(pHlp, " %sVM-exit instruction info = %#RX64\n", pszPrefix, pVmcs->u32RoExitInstrInfo);
3944
3945 /* 64-bit. */
3946 pHlp->pfnPrintf(pHlp, " %sGuest-physical addr = %#RX64\n", pszPrefix, pVmcs->u64RoGuestPhysAddr.u);
3947
3948 /* Natural width. */
3949 pHlp->pfnPrintf(pHlp, " %sI/O RCX = %#RX64\n", pszPrefix, pVmcs->u64RoIoRcx.u);
3950 pHlp->pfnPrintf(pHlp, " %sI/O RSI = %#RX64\n", pszPrefix, pVmcs->u64RoIoRsi.u);
3951 pHlp->pfnPrintf(pHlp, " %sI/O RDI = %#RX64\n", pszPrefix, pVmcs->u64RoIoRdi.u);
3952 pHlp->pfnPrintf(pHlp, " %sI/O RIP = %#RX64\n", pszPrefix, pVmcs->u64RoIoRip.u);
3953 pHlp->pfnPrintf(pHlp, " %sGuest-linear addr = %#RX64\n", pszPrefix, pVmcs->u64RoGuestLinearAddr.u);
3954 }
3955
3956#ifdef DEBUG_ramshankar
3957 if (pVmcs->u32ProcCtls & VMX_PROC_CTLS_USE_TPR_SHADOW)
3958 {
3959 void *pvPage = RTMemTmpAllocZ(VMX_V_VIRT_APIC_SIZE);
3960 Assert(pvPage);
3961 RTGCPHYS const GCPhysVirtApic = pVmcs->u64AddrVirtApic.u;
3962 int rc = PGMPhysSimpleReadGCPhys(pVCpu->CTX_SUFF(pVM), pvPage, GCPhysVirtApic, VMX_V_VIRT_APIC_SIZE);
3963 if (RT_SUCCESS(rc))
3964 {
3965 pHlp->pfnPrintf(pHlp, " %sVirtual-APIC page\n", pszPrefix);
3966 pHlp->pfnPrintf(pHlp, "%.*Rhxs\n", VMX_V_VIRT_APIC_SIZE, pvPage);
3967 pHlp->pfnPrintf(pHlp, "\n");
3968 }
3969 RTMemTmpFree(pvPage);
3970 }
3971#else
3972 NOREF(pVCpu);
3973#endif
3974
3975#undef CPUMVMX_DUMP_HOST_XDTR
3976#undef CPUMVMX_DUMP_HOST_FS_GS_TR
3977#undef CPUMVMX_DUMP_GUEST_SEGREG
3978#undef CPUMVMX_DUMP_GUEST_XDTR
3979}
3980
3981
3982/**
3983 * Display the guest's hardware-virtualization cpu state.
3984 *
3985 * @param pVM The cross context VM structure.
3986 * @param pHlp The info helper functions.
3987 * @param pszArgs Arguments, ignored.
3988 */
3989static DECLCALLBACK(void) cpumR3InfoGuestHwvirt(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs)
3990{
3991 RT_NOREF(pszArgs);
3992
3993 PVMCPU pVCpu = VMMGetCpu(pVM);
3994 if (!pVCpu)
3995 pVCpu = pVM->apCpusR3[0];
3996
3997 PCCPUMCTX pCtx = &pVCpu->cpum.s.Guest;
3998 bool const fSvm = pVM->cpum.s.GuestFeatures.fSvm;
3999 bool const fVmx = pVM->cpum.s.GuestFeatures.fVmx;
4000
4001 pHlp->pfnPrintf(pHlp, "VCPU[%u] hardware virtualization state:\n", pVCpu->idCpu);
4002 pHlp->pfnPrintf(pHlp, "fLocalForcedActions = %#RX32\n", pCtx->hwvirt.fLocalForcedActions);
4003 pHlp->pfnPrintf(pHlp, "In nested-guest hwvirt mode = %RTbool\n", CPUMIsGuestInNestedHwvirtMode(pCtx));
4004
4005 if (fSvm)
4006 {
4007 pHlp->pfnPrintf(pHlp, "SVM hwvirt state:\n");
4008 pHlp->pfnPrintf(pHlp, " fGif = %RTbool\n", pCtx->hwvirt.fGif);
4009
4010 char szEFlags[80];
4011 cpumR3InfoFormatFlags(&szEFlags[0], pCtx->hwvirt.svm.HostState.rflags.u);
4012 pHlp->pfnPrintf(pHlp, " uMsrHSavePa = %#RX64\n", pCtx->hwvirt.svm.uMsrHSavePa);
4013 pHlp->pfnPrintf(pHlp, " GCPhysVmcb = %#RGp\n", pCtx->hwvirt.svm.GCPhysVmcb);
4014 pHlp->pfnPrintf(pHlp, " VmcbCtrl:\n");
4015 cpumR3InfoSvmVmcbCtrl(pHlp, &pCtx->hwvirt.svm.Vmcb.ctrl, " " /* pszPrefix */);
4016 pHlp->pfnPrintf(pHlp, " VmcbStateSave:\n");
4017 cpumR3InfoSvmVmcbStateSave(pHlp, &pCtx->hwvirt.svm.Vmcb.guest, " " /* pszPrefix */);
4018 pHlp->pfnPrintf(pHlp, " HostState:\n");
4019 pHlp->pfnPrintf(pHlp, " uEferMsr = %#RX64\n", pCtx->hwvirt.svm.HostState.uEferMsr);
4020 pHlp->pfnPrintf(pHlp, " uCr0 = %#RX64\n", pCtx->hwvirt.svm.HostState.uCr0);
4021 pHlp->pfnPrintf(pHlp, " uCr4 = %#RX64\n", pCtx->hwvirt.svm.HostState.uCr4);
4022 pHlp->pfnPrintf(pHlp, " uCr3 = %#RX64\n", pCtx->hwvirt.svm.HostState.uCr3);
4023 pHlp->pfnPrintf(pHlp, " uRip = %#RX64\n", pCtx->hwvirt.svm.HostState.uRip);
4024 pHlp->pfnPrintf(pHlp, " uRsp = %#RX64\n", pCtx->hwvirt.svm.HostState.uRsp);
4025 pHlp->pfnPrintf(pHlp, " uRax = %#RX64\n", pCtx->hwvirt.svm.HostState.uRax);
4026 pHlp->pfnPrintf(pHlp, " rflags = %#RX64 %31s\n", pCtx->hwvirt.svm.HostState.rflags.u64, szEFlags);
4027 PCCPUMSELREG pSelEs = &pCtx->hwvirt.svm.HostState.es;
4028 pHlp->pfnPrintf(pHlp, " es = {%04x base=%016RX64 limit=%08x flags=%08x}\n",
4029 pSelEs->Sel, pSelEs->u64Base, pSelEs->u32Limit, pSelEs->Attr.u);
4030 PCCPUMSELREG pSelCs = &pCtx->hwvirt.svm.HostState.cs;
4031 pHlp->pfnPrintf(pHlp, " cs = {%04x base=%016RX64 limit=%08x flags=%08x}\n",
4032 pSelCs->Sel, pSelCs->u64Base, pSelCs->u32Limit, pSelCs->Attr.u);
4033 PCCPUMSELREG pSelSs = &pCtx->hwvirt.svm.HostState.ss;
4034 pHlp->pfnPrintf(pHlp, " ss = {%04x base=%016RX64 limit=%08x flags=%08x}\n",
4035 pSelSs->Sel, pSelSs->u64Base, pSelSs->u32Limit, pSelSs->Attr.u);
4036 PCCPUMSELREG pSelDs = &pCtx->hwvirt.svm.HostState.ds;
4037 pHlp->pfnPrintf(pHlp, " ds = {%04x base=%016RX64 limit=%08x flags=%08x}\n",
4038 pSelDs->Sel, pSelDs->u64Base, pSelDs->u32Limit, pSelDs->Attr.u);
4039 pHlp->pfnPrintf(pHlp, " gdtr = %016RX64:%04x\n", pCtx->hwvirt.svm.HostState.gdtr.pGdt,
4040 pCtx->hwvirt.svm.HostState.gdtr.cbGdt);
4041 pHlp->pfnPrintf(pHlp, " idtr = %016RX64:%04x\n", pCtx->hwvirt.svm.HostState.idtr.pIdt,
4042 pCtx->hwvirt.svm.HostState.idtr.cbIdt);
4043 pHlp->pfnPrintf(pHlp, " cPauseFilter = %RU16\n", pCtx->hwvirt.svm.cPauseFilter);
4044 pHlp->pfnPrintf(pHlp, " cPauseFilterThreshold = %RU32\n", pCtx->hwvirt.svm.cPauseFilterThreshold);
4045 pHlp->pfnPrintf(pHlp, " fInterceptEvents = %u\n", pCtx->hwvirt.svm.fInterceptEvents);
4046 }
4047 else if (fVmx)
4048 {
4049 pHlp->pfnPrintf(pHlp, "VMX hwvirt state:\n");
4050 pHlp->pfnPrintf(pHlp, " GCPhysVmxon = %#RGp\n", pCtx->hwvirt.vmx.GCPhysVmxon);
4051 pHlp->pfnPrintf(pHlp, " GCPhysVmcs = %#RGp\n", pCtx->hwvirt.vmx.GCPhysVmcs);
4052 pHlp->pfnPrintf(pHlp, " GCPhysShadowVmcs = %#RGp\n", pCtx->hwvirt.vmx.GCPhysShadowVmcs);
4053 pHlp->pfnPrintf(pHlp, " enmDiag = %u (%s)\n", pCtx->hwvirt.vmx.enmDiag, HMGetVmxDiagDesc(pCtx->hwvirt.vmx.enmDiag));
4054 pHlp->pfnPrintf(pHlp, " uDiagAux = %#RX64\n", pCtx->hwvirt.vmx.uDiagAux);
4055 pHlp->pfnPrintf(pHlp, " enmAbort = %u (%s)\n", pCtx->hwvirt.vmx.enmAbort, VMXGetAbortDesc(pCtx->hwvirt.vmx.enmAbort));
4056 pHlp->pfnPrintf(pHlp, " uAbortAux = %u (%#x)\n", pCtx->hwvirt.vmx.uAbortAux, pCtx->hwvirt.vmx.uAbortAux);
4057 pHlp->pfnPrintf(pHlp, " fInVmxRootMode = %RTbool\n", pCtx->hwvirt.vmx.fInVmxRootMode);
4058 pHlp->pfnPrintf(pHlp, " fInVmxNonRootMode = %RTbool\n", pCtx->hwvirt.vmx.fInVmxNonRootMode);
4059 pHlp->pfnPrintf(pHlp, " fInterceptEvents = %RTbool\n", pCtx->hwvirt.vmx.fInterceptEvents);
4060 pHlp->pfnPrintf(pHlp, " fNmiUnblockingIret = %RTbool\n", pCtx->hwvirt.vmx.fNmiUnblockingIret);
4061 pHlp->pfnPrintf(pHlp, " uFirstPauseLoopTick = %RX64\n", pCtx->hwvirt.vmx.uFirstPauseLoopTick);
4062 pHlp->pfnPrintf(pHlp, " uPrevPauseTick = %RX64\n", pCtx->hwvirt.vmx.uPrevPauseTick);
4063 pHlp->pfnPrintf(pHlp, " uEntryTick = %RX64\n", pCtx->hwvirt.vmx.uEntryTick);
4064 pHlp->pfnPrintf(pHlp, " offVirtApicWrite = %#RX16\n", pCtx->hwvirt.vmx.offVirtApicWrite);
4065 pHlp->pfnPrintf(pHlp, " fVirtNmiBlocking = %RTbool\n", pCtx->hwvirt.vmx.fVirtNmiBlocking);
4066 pHlp->pfnPrintf(pHlp, " VMCS cache:\n");
4067 cpumR3InfoVmxVmcs(pVCpu, pHlp, &pCtx->hwvirt.vmx.Vmcs, " " /* pszPrefix */);
4068 }
4069 else
4070 pHlp->pfnPrintf(pHlp, "Hwvirt state disabled.\n");
4071
4072#undef CPUMHWVIRTDUMP_NONE
4073#undef CPUMHWVIRTDUMP_COMMON
4074#undef CPUMHWVIRTDUMP_SVM
4075#undef CPUMHWVIRTDUMP_VMX
4076#undef CPUMHWVIRTDUMP_LAST
4077#undef CPUMHWVIRTDUMP_ALL
4078}
4079
4080/**
4081 * Display the current guest instruction
4082 *
4083 * @param pVM The cross context VM structure.
4084 * @param pHlp The info helper functions.
4085 * @param pszArgs Arguments, ignored.
4086 */
4087static DECLCALLBACK(void) cpumR3InfoGuestInstr(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs)
4088{
4089 NOREF(pszArgs);
4090
4091 PVMCPU pVCpu = VMMGetCpu(pVM);
4092 if (!pVCpu)
4093 pVCpu = pVM->apCpusR3[0];
4094
4095 char szInstruction[256];
4096 szInstruction[0] = '\0';
4097 DBGFR3DisasInstrCurrent(pVCpu, szInstruction, sizeof(szInstruction));
4098 pHlp->pfnPrintf(pHlp, "\nCPUM%u: %s\n\n", pVCpu->idCpu, szInstruction);
4099}
4100
4101
4102/**
4103 * Display the hypervisor cpu state.
4104 *
4105 * @param pVM The cross context VM structure.
4106 * @param pHlp The info helper functions.
4107 * @param pszArgs Arguments, ignored.
4108 */
4109static DECLCALLBACK(void) cpumR3InfoHyper(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs)
4110{
4111 PVMCPU pVCpu = VMMGetCpu(pVM);
4112 if (!pVCpu)
4113 pVCpu = pVM->apCpusR3[0];
4114
4115 CPUMDUMPTYPE enmType;
4116 const char *pszComment;
4117 cpumR3InfoParseArg(pszArgs, &enmType, &pszComment);
4118 pHlp->pfnPrintf(pHlp, "Hypervisor CPUM state: %s\n", pszComment);
4119
4120 pHlp->pfnPrintf(pHlp,
4121 ".dr0=%016RX64 .dr1=%016RX64 .dr2=%016RX64 .dr3=%016RX64\n"
4122 ".dr4=%016RX64 .dr5=%016RX64 .dr6=%016RX64 .dr7=%016RX64\n",
4123 pVCpu->cpum.s.Hyper.dr[0], pVCpu->cpum.s.Hyper.dr[1], pVCpu->cpum.s.Hyper.dr[2], pVCpu->cpum.s.Hyper.dr[3],
4124 pVCpu->cpum.s.Hyper.dr[4], pVCpu->cpum.s.Hyper.dr[5], pVCpu->cpum.s.Hyper.dr[6], pVCpu->cpum.s.Hyper.dr[7]);
4125 pHlp->pfnPrintf(pHlp, "CR4OrMask=%#x CR4AndMask=%#x\n", pVM->cpum.s.CR4.OrMask, pVM->cpum.s.CR4.AndMask);
4126}
4127
4128
4129/**
4130 * Display the host cpu state.
4131 *
4132 * @param pVM The cross context VM structure.
4133 * @param pHlp The info helper functions.
4134 * @param pszArgs Arguments, ignored.
4135 */
4136static DECLCALLBACK(void) cpumR3InfoHost(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs)
4137{
4138 CPUMDUMPTYPE enmType;
4139 const char *pszComment;
4140 cpumR3InfoParseArg(pszArgs, &enmType, &pszComment);
4141 pHlp->pfnPrintf(pHlp, "Host CPUM state: %s\n", pszComment);
4142
4143 PVMCPU pVCpu = VMMGetCpu(pVM);
4144 if (!pVCpu)
4145 pVCpu = pVM->apCpusR3[0];
4146 PCPUMHOSTCTX pCtx = &pVCpu->cpum.s.Host;
4147
4148 /*
4149 * Format the EFLAGS.
4150 */
4151 uint64_t efl = pCtx->rflags;
4152 char szEFlags[80];
4153 cpumR3InfoFormatFlags(&szEFlags[0], efl);
4154
4155 /*
4156 * Format the registers.
4157 */
4158 pHlp->pfnPrintf(pHlp,
4159 "rax=xxxxxxxxxxxxxxxx rbx=%016RX64 rcx=xxxxxxxxxxxxxxxx\n"
4160 "rdx=xxxxxxxxxxxxxxxx rsi=%016RX64 rdi=%016RX64\n"
4161 "rip=xxxxxxxxxxxxxxxx rsp=%016RX64 rbp=%016RX64\n"
4162 " r8=xxxxxxxxxxxxxxxx r9=xxxxxxxxxxxxxxxx r10=%016RX64\n"
4163 "r11=%016RX64 r12=%016RX64 r13=%016RX64\n"
4164 "r14=%016RX64 r15=%016RX64\n"
4165 "iopl=%d %31s\n"
4166 "cs=%04x ds=%04x es=%04x fs=%04x gs=%04x eflags=%08RX64\n"
4167 "cr0=%016RX64 cr2=xxxxxxxxxxxxxxxx cr3=%016RX64\n"
4168 "cr4=%016RX64 ldtr=%04x tr=%04x\n"
4169 "dr[0]=%016RX64 dr[1]=%016RX64 dr[2]=%016RX64\n"
4170 "dr[3]=%016RX64 dr[6]=%016RX64 dr[7]=%016RX64\n"
4171 "gdtr=%016RX64:%04x idtr=%016RX64:%04x\n"
4172 "SysEnter={cs=%04x eip=%08x esp=%08x}\n"
4173 "FSbase=%016RX64 GSbase=%016RX64 efer=%08RX64\n"
4174 ,
4175 /*pCtx->rax,*/ pCtx->rbx, /*pCtx->rcx,
4176 pCtx->rdx,*/ pCtx->rsi, pCtx->rdi,
4177 /*pCtx->rip,*/ pCtx->rsp, pCtx->rbp,
4178 /*pCtx->r8, pCtx->r9,*/ pCtx->r10,
4179 pCtx->r11, pCtx->r12, pCtx->r13,
4180 pCtx->r14, pCtx->r15,
4181 X86_EFL_GET_IOPL(efl), szEFlags,
4182 pCtx->cs, pCtx->ds, pCtx->es, pCtx->fs, pCtx->gs, efl,
4183 pCtx->cr0, /*pCtx->cr2,*/ pCtx->cr3,
4184 pCtx->cr4, pCtx->ldtr, pCtx->tr,
4185 pCtx->dr0, pCtx->dr1, pCtx->dr2,
4186 pCtx->dr3, pCtx->dr6, pCtx->dr7,
4187 pCtx->gdtr.uAddr, pCtx->gdtr.cb, pCtx->idtr.uAddr, pCtx->idtr.cb,
4188 pCtx->SysEnter.cs, pCtx->SysEnter.eip, pCtx->SysEnter.esp,
4189 pCtx->FSbase, pCtx->GSbase, pCtx->efer);
4190}
4191
4192/**
4193 * Structure used when disassembling and instructions in DBGF.
4194 * This is used so the reader function can get the stuff it needs.
4195 */
4196typedef struct CPUMDISASSTATE
4197{
4198 /** Pointer to the CPU structure. */
4199 PDISCPUSTATE pCpu;
4200 /** Pointer to the VM. */
4201 PVM pVM;
4202 /** Pointer to the VMCPU. */
4203 PVMCPU pVCpu;
4204 /** Pointer to the first byte in the segment. */
4205 RTGCUINTPTR GCPtrSegBase;
4206 /** Pointer to the byte after the end of the segment. (might have wrapped!) */
4207 RTGCUINTPTR GCPtrSegEnd;
4208 /** The size of the segment minus 1. */
4209 RTGCUINTPTR cbSegLimit;
4210 /** Pointer to the current page - R3 Ptr. */
4211 void const *pvPageR3;
4212 /** Pointer to the current page - GC Ptr. */
4213 RTGCPTR pvPageGC;
4214 /** The lock information that PGMPhysReleasePageMappingLock needs. */
4215 PGMPAGEMAPLOCK PageMapLock;
4216 /** Whether the PageMapLock is valid or not. */
4217 bool fLocked;
4218 /** 64 bits mode or not. */
4219 bool f64Bits;
4220} CPUMDISASSTATE, *PCPUMDISASSTATE;
4221
4222
4223/**
4224 * @callback_method_impl{FNDISREADBYTES}
4225 */
4226static DECLCALLBACK(int) cpumR3DisasInstrRead(PDISCPUSTATE pDis, uint8_t offInstr, uint8_t cbMinRead, uint8_t cbMaxRead)
4227{
4228 PCPUMDISASSTATE pState = (PCPUMDISASSTATE)pDis->pvUser;
4229 for (;;)
4230 {
4231 RTGCUINTPTR GCPtr = pDis->uInstrAddr + offInstr + pState->GCPtrSegBase;
4232
4233 /*
4234 * Need to update the page translation?
4235 */
4236 if ( !pState->pvPageR3
4237 || (GCPtr >> GUEST_PAGE_SHIFT) != (pState->pvPageGC >> GUEST_PAGE_SHIFT))
4238 {
4239 /* translate the address */
4240 pState->pvPageGC = GCPtr & ~(RTGCPTR)GUEST_PAGE_OFFSET_MASK;
4241
4242 /* Release mapping lock previously acquired. */
4243 if (pState->fLocked)
4244 PGMPhysReleasePageMappingLock(pState->pVM, &pState->PageMapLock);
4245 int rc = PGMPhysGCPtr2CCPtrReadOnly(pState->pVCpu, pState->pvPageGC, &pState->pvPageR3, &pState->PageMapLock);
4246 if (RT_SUCCESS(rc))
4247 pState->fLocked = true;
4248 else
4249 {
4250 pState->fLocked = false;
4251 pState->pvPageR3 = NULL;
4252 return rc;
4253 }
4254 }
4255
4256 /*
4257 * Check the segment limit.
4258 */
4259 if (!pState->f64Bits && pDis->uInstrAddr + offInstr > pState->cbSegLimit)
4260 return VERR_OUT_OF_SELECTOR_BOUNDS;
4261
4262 /*
4263 * Calc how much we can read.
4264 */
4265 uint32_t cb = GUEST_PAGE_SIZE - (GCPtr & GUEST_PAGE_OFFSET_MASK);
4266 if (!pState->f64Bits)
4267 {
4268 RTGCUINTPTR cbSeg = pState->GCPtrSegEnd - GCPtr;
4269 if (cb > cbSeg && cbSeg)
4270 cb = cbSeg;
4271 }
4272 if (cb > cbMaxRead)
4273 cb = cbMaxRead;
4274
4275 /*
4276 * Read and advance or exit.
4277 */
4278 memcpy(&pDis->abInstr[offInstr], (uint8_t *)pState->pvPageR3 + (GCPtr & GUEST_PAGE_OFFSET_MASK), cb);
4279 offInstr += (uint8_t)cb;
4280 if (cb >= cbMinRead)
4281 {
4282 pDis->cbCachedInstr = offInstr;
4283 return VINF_SUCCESS;
4284 }
4285 cbMinRead -= (uint8_t)cb;
4286 cbMaxRead -= (uint8_t)cb;
4287 }
4288}
4289
4290
4291/**
4292 * Disassemble an instruction and return the information in the provided structure.
4293 *
4294 * @returns VBox status code.
4295 * @param pVM The cross context VM structure.
4296 * @param pVCpu The cross context virtual CPU structure.
4297 * @param pCtx Pointer to the guest CPU context.
4298 * @param GCPtrPC Program counter (relative to CS) to disassemble from.
4299 * @param pCpu Disassembly state.
4300 * @param pszPrefix String prefix for logging (debug only).
4301 *
4302 */
4303VMMR3DECL(int) CPUMR3DisasmInstrCPU(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx, RTGCPTR GCPtrPC, PDISCPUSTATE pCpu,
4304 const char *pszPrefix)
4305{
4306 CPUMDISASSTATE State;
4307 int rc;
4308
4309 const PGMMODE enmMode = PGMGetGuestMode(pVCpu);
4310 State.pCpu = pCpu;
4311 State.pvPageGC = 0;
4312 State.pvPageR3 = NULL;
4313 State.pVM = pVM;
4314 State.pVCpu = pVCpu;
4315 State.fLocked = false;
4316 State.f64Bits = false;
4317
4318 /*
4319 * Get selector information.
4320 */
4321 DISCPUMODE enmDisCpuMode;
4322 if ( (pCtx->cr0 & X86_CR0_PE)
4323 && pCtx->eflags.Bits.u1VM == 0)
4324 {
4325 if (!CPUMSELREG_ARE_HIDDEN_PARTS_VALID(pVCpu, &pCtx->cs))
4326 return VERR_CPUM_HIDDEN_CS_LOAD_ERROR;
4327 State.f64Bits = enmMode >= PGMMODE_AMD64 && pCtx->cs.Attr.n.u1Long;
4328 State.GCPtrSegBase = pCtx->cs.u64Base;
4329 State.GCPtrSegEnd = pCtx->cs.u32Limit + 1 + (RTGCUINTPTR)pCtx->cs.u64Base;
4330 State.cbSegLimit = pCtx->cs.u32Limit;
4331 enmDisCpuMode = (State.f64Bits)
4332 ? DISCPUMODE_64BIT
4333 : pCtx->cs.Attr.n.u1DefBig
4334 ? DISCPUMODE_32BIT
4335 : DISCPUMODE_16BIT;
4336 }
4337 else
4338 {
4339 /* real or V86 mode */
4340 enmDisCpuMode = DISCPUMODE_16BIT;
4341 State.GCPtrSegBase = pCtx->cs.Sel * 16;
4342 State.GCPtrSegEnd = 0xFFFFFFFF;
4343 State.cbSegLimit = 0xFFFFFFFF;
4344 }
4345
4346 /*
4347 * Disassemble the instruction.
4348 */
4349 uint32_t cbInstr;
4350#ifndef LOG_ENABLED
4351 RT_NOREF_PV(pszPrefix);
4352 rc = DISInstrWithReader(GCPtrPC, enmDisCpuMode, cpumR3DisasInstrRead, &State, pCpu, &cbInstr);
4353 if (RT_SUCCESS(rc))
4354 {
4355#else
4356 char szOutput[160];
4357 rc = DISInstrToStrWithReader(GCPtrPC, enmDisCpuMode, cpumR3DisasInstrRead, &State,
4358 pCpu, &cbInstr, szOutput, sizeof(szOutput));
4359 if (RT_SUCCESS(rc))
4360 {
4361 /* log it */
4362 if (pszPrefix)
4363 Log(("%s-CPU%d: %s", pszPrefix, pVCpu->idCpu, szOutput));
4364 else
4365 Log(("%s", szOutput));
4366#endif
4367 rc = VINF_SUCCESS;
4368 }
4369 else
4370 Log(("CPUMR3DisasmInstrCPU: DISInstr failed for %04X:%RGv rc=%Rrc\n", pCtx->cs.Sel, GCPtrPC, rc));
4371
4372 /* Release mapping lock acquired in cpumR3DisasInstrRead. */
4373 if (State.fLocked)
4374 PGMPhysReleasePageMappingLock(pVM, &State.PageMapLock);
4375
4376 return rc;
4377}
4378
4379
4380
4381/**
4382 * API for controlling a few of the CPU features found in CR4.
4383 *
4384 * Currently only X86_CR4_TSD is accepted as input.
4385 *
4386 * @returns VBox status code.
4387 *
4388 * @param pVM The cross context VM structure.
4389 * @param fOr The CR4 OR mask.
4390 * @param fAnd The CR4 AND mask.
4391 */
4392VMMR3DECL(int) CPUMR3SetCR4Feature(PVM pVM, RTHCUINTREG fOr, RTHCUINTREG fAnd)
4393{
4394 AssertMsgReturn(!(fOr & ~(X86_CR4_TSD)), ("%#x\n", fOr), VERR_INVALID_PARAMETER);
4395 AssertMsgReturn((fAnd & ~(X86_CR4_TSD)) == ~(X86_CR4_TSD), ("%#x\n", fAnd), VERR_INVALID_PARAMETER);
4396
4397 pVM->cpum.s.CR4.OrMask &= fAnd;
4398 pVM->cpum.s.CR4.OrMask |= fOr;
4399
4400 return VINF_SUCCESS;
4401}
4402
4403
4404/**
4405 * Called when the ring-3 init phase completes.
4406 *
4407 * @returns VBox status code.
4408 * @param pVM The cross context VM structure.
4409 * @param enmWhat Which init phase.
4410 */
4411VMMR3DECL(int) CPUMR3InitCompleted(PVM pVM, VMINITCOMPLETED enmWhat)
4412{
4413 switch (enmWhat)
4414 {
4415 case VMINITCOMPLETED_RING3:
4416 {
4417 /*
4418 * Figure out if the guest uses 32-bit or 64-bit FPU state at runtime for 64-bit capable VMs.
4419 * Only applicable/used on 64-bit hosts, refer CPUMR0A.asm. See @bugref{7138}.
4420 */
4421 bool const fSupportsLongMode = VMR3IsLongModeAllowed(pVM);
4422 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
4423 {
4424 PVMCPU pVCpu = pVM->apCpusR3[idCpu];
4425
4426 /* While loading a saved-state we fix it up in, cpumR3LoadDone(). */
4427 if (fSupportsLongMode)
4428 pVCpu->cpum.s.fUseFlags |= CPUM_USE_SUPPORTS_LONGMODE;
4429 }
4430
4431 /* Register statistic counters for MSRs. */
4432 cpumR3MsrRegStats(pVM);
4433
4434 /* There shouldn't be any more calls to CPUMR3SetGuestCpuIdFeature and
4435 CPUMR3ClearGuestCpuIdFeature now, so do some final CPUID polishing (NX). */
4436 cpumR3CpuIdRing3InitDone(pVM);
4437
4438 /* Create VMX-preemption timer for nested guests if required. Must be
4439 done here as CPUM is initialized before TM. */
4440 if (pVM->cpum.s.GuestFeatures.fVmx)
4441 {
4442 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
4443 {
4444 PVMCPU pVCpu = pVM->apCpusR3[idCpu];
4445 char szName[32];
4446 RTStrPrintf(szName, sizeof(szName), "Nested VMX-preemption %u", idCpu);
4447 int rc = TMR3TimerCreate(pVM, TMCLOCK_VIRTUAL_SYNC, cpumR3VmxPreemptTimerCallback, pVCpu,
4448 TMTIMER_FLAGS_RING0, szName, &pVCpu->cpum.s.hNestedVmxPreemptTimer);
4449 AssertLogRelRCReturn(rc, rc);
4450 }
4451 }
4452 break;
4453 }
4454
4455 default:
4456 break;
4457 }
4458 return VINF_SUCCESS;
4459}
4460
4461
4462/**
4463 * Called when the ring-0 init phases completed.
4464 *
4465 * @param pVM The cross context VM structure.
4466 */
4467VMMR3DECL(void) CPUMR3LogCpuIdAndMsrFeatures(PVM pVM)
4468{
4469 /*
4470 * Enable log buffering as we're going to log a lot of lines.
4471 */
4472 bool const fOldBuffered = RTLogRelSetBuffering(true /*fBuffered*/);
4473
4474 /*
4475 * Log the cpuid.
4476 */
4477 RTCPUSET OnlineSet;
4478 LogRel(("CPUM: Logical host processors: %u present, %u max, %u online, online mask: %016RX64\n",
4479 (unsigned)RTMpGetPresentCount(), (unsigned)RTMpGetCount(), (unsigned)RTMpGetOnlineCount(),
4480 RTCpuSetToU64(RTMpGetOnlineSet(&OnlineSet)) ));
4481 RTCPUID cCores = RTMpGetCoreCount();
4482 if (cCores)
4483 LogRel(("CPUM: Physical host cores: %u\n", (unsigned)cCores));
4484 LogRel(("************************* CPUID dump ************************\n"));
4485 DBGFR3Info(pVM->pUVM, "cpuid", "verbose", DBGFR3InfoLogRelHlp());
4486 LogRel(("\n"));
4487 DBGFR3_INFO_LOG_SAFE(pVM, "cpuid", "verbose"); /* macro */
4488 LogRel(("******************** End of CPUID dump **********************\n"));
4489
4490 /*
4491 * Log VT-x extended features.
4492 *
4493 * SVM features are currently all covered under CPUID so there is nothing
4494 * to do here for SVM.
4495 */
4496 if (pVM->cpum.s.HostFeatures.fVmx)
4497 {
4498 LogRel(("*********************** VT-x features ***********************\n"));
4499 DBGFR3Info(pVM->pUVM, "cpumvmxfeat", "default", DBGFR3InfoLogRelHlp());
4500 LogRel(("\n"));
4501 LogRel(("******************* End of VT-x features ********************\n"));
4502 }
4503
4504 /*
4505 * Restore the log buffering state to what it was previously.
4506 */
4507 RTLogRelSetBuffering(fOldBuffered);
4508}
4509
4510
4511/**
4512 * Marks the guest debug state as active.
4513 *
4514 * @returns nothing.
4515 * @param pVCpu The cross context virtual CPU structure.
4516 *
4517 * @note This is used solely by NEM (hence the name) to set the correct flags here
4518 * without loading the host's DRx registers, which is not possible from ring-3 anyway.
4519 * The specific NEM backends have to make sure to load the correct values.
4520 */
4521VMMR3_INT_DECL(void) CPUMR3NemActivateGuestDebugState(PVMCPUCC pVCpu)
4522{
4523 ASMAtomicAndU32(&pVCpu->cpum.s.fUseFlags, ~CPUM_USED_DEBUG_REGS_HYPER);
4524 ASMAtomicOrU32(&pVCpu->cpum.s.fUseFlags, CPUM_USED_DEBUG_REGS_GUEST);
4525}
4526
4527
4528/**
4529 * Marks the hyper debug state as active.
4530 *
4531 * @returns nothing.
4532 * @param pVCpu The cross context virtual CPU structure.
4533 *
4534 * @note This is used solely by NEM (hence the name) to set the correct flags here
4535 * without loading the host's DRx registers, which is not possible from ring-3 anyway.
4536 * The specific NEM backends have to make sure to load the correct values.
4537 */
4538VMMR3_INT_DECL(void) CPUMR3NemActivateHyperDebugState(PVMCPUCC pVCpu)
4539{
4540 /*
4541 * Make sure the hypervisor values are up to date.
4542 */
4543 CPUMRecalcHyperDRx(pVCpu, UINT8_MAX /* no loading, please */);
4544
4545 ASMAtomicAndU32(&pVCpu->cpum.s.fUseFlags, ~CPUM_USED_DEBUG_REGS_GUEST);
4546 ASMAtomicOrU32(&pVCpu->cpum.s.fUseFlags, CPUM_USED_DEBUG_REGS_HYPER);
4547}
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