VirtualBox

source: vbox/trunk/include/VBox/vmm/hm_vmx.h@ 73286

Last change on this file since 73286 was 73286, checked in by vboxsync, 7 years ago

VMM: hex digits nits.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 107.1 KB
Line 
1/** @file
2 * HM - VMX Structures and Definitions. (VMM)
3 */
4
5/*
6 * Copyright (C) 2006-2017 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef ___VBox_vmm_vmx_h
27#define ___VBox_vmm_vmx_h
28
29#include <VBox/types.h>
30#include <VBox/err.h>
31#include <iprt/x86.h>
32#include <iprt/assert.h>
33
34/* In Visual C++ versions prior to 2012, the vmx intrinsics are only available
35 when targeting AMD64. */
36#if RT_INLINE_ASM_USES_INTRIN >= 16 && defined(RT_ARCH_AMD64)
37# pragma warning(push)
38# pragma warning(disable:4668) /* Several incorrect __cplusplus uses. */
39# pragma warning(disable:4255) /* Incorrect __slwpcb prototype. */
40# include <intrin.h>
41# pragma warning(pop)
42/* We always want them as intrinsics, no functions. */
43# pragma intrinsic(__vmx_on)
44# pragma intrinsic(__vmx_off)
45# pragma intrinsic(__vmx_vmclear)
46# pragma intrinsic(__vmx_vmptrld)
47# pragma intrinsic(__vmx_vmread)
48# pragma intrinsic(__vmx_vmwrite)
49# define VMX_USE_MSC_INTRINSICS 1
50#else
51# define VMX_USE_MSC_INTRINSICS 0
52#endif
53
54
55/** @defgroup grp_hm_vmx VMX Types and Definitions
56 * @ingroup grp_hm
57 * @{
58 */
59
60/** @name Host-state restoration flags.
61 * @note If you change these values don't forget to update the assembly
62 * defines as well!
63 * @{
64 */
65#define VMX_RESTORE_HOST_SEL_DS RT_BIT(0)
66#define VMX_RESTORE_HOST_SEL_ES RT_BIT(1)
67#define VMX_RESTORE_HOST_SEL_FS RT_BIT(2)
68#define VMX_RESTORE_HOST_SEL_GS RT_BIT(3)
69#define VMX_RESTORE_HOST_SEL_TR RT_BIT(4)
70#define VMX_RESTORE_HOST_GDTR RT_BIT(5)
71#define VMX_RESTORE_HOST_IDTR RT_BIT(6)
72#define VMX_RESTORE_HOST_GDT_READ_ONLY RT_BIT(7)
73#define VMX_RESTORE_HOST_REQUIRED RT_BIT(8)
74#define VMX_RESTORE_HOST_GDT_NEED_WRITABLE RT_BIT(9)
75/** @} */
76
77/**
78 * Host-state restoration structure.
79 * This holds host-state fields that require manual restoration.
80 * Assembly version found in hm_vmx.mac (should be automatically verified).
81 */
82typedef struct VMXRESTOREHOST
83{
84 RTSEL uHostSelDS; /* 0x00 */
85 RTSEL uHostSelES; /* 0x02 */
86 RTSEL uHostSelFS; /* 0x04 */
87 RTSEL uHostSelGS; /* 0x06 */
88 RTSEL uHostSelTR; /* 0x08 */
89 uint8_t abPadding0[4];
90 X86XDTR64 HostGdtr; /**< 0x0e - should be aligned by it's 64-bit member. */
91 uint8_t abPadding1[6];
92 X86XDTR64 HostGdtrRw; /**< 0x1e - should be aligned by it's 64-bit member. */
93 uint8_t abPadding2[6];
94 X86XDTR64 HostIdtr; /**< 0x2e - should be aligned by it's 64-bit member. */
95 uint64_t uHostFSBase; /* 0x38 */
96 uint64_t uHostGSBase; /* 0x40 */
97} VMXRESTOREHOST;
98/** Pointer to VMXRESTOREHOST. */
99typedef VMXRESTOREHOST *PVMXRESTOREHOST;
100AssertCompileSize(X86XDTR64, 10);
101AssertCompileMemberOffset(VMXRESTOREHOST, HostGdtr.uAddr, 16);
102AssertCompileMemberOffset(VMXRESTOREHOST, HostGdtrRw.uAddr, 32);
103AssertCompileMemberOffset(VMXRESTOREHOST, HostIdtr.uAddr, 48);
104AssertCompileMemberOffset(VMXRESTOREHOST, uHostFSBase, 56);
105AssertCompileSize(VMXRESTOREHOST, 72);
106AssertCompileSizeAlignment(VMXRESTOREHOST, 8);
107
108/** @name Host-state MSR lazy-restoration flags.
109 * @{
110 */
111/** The host MSRs have been saved. */
112#define VMX_LAZY_MSRS_SAVED_HOST RT_BIT(0)
113/** The guest MSRs are loaded and in effect. */
114#define VMX_LAZY_MSRS_LOADED_GUEST RT_BIT(1)
115/** @} */
116
117/** @name VMX HM-error codes for VERR_HM_UNSUPPORTED_CPU_FEATURE_COMBO.
118 * UFC = Unsupported Feature Combination.
119 * @{
120 */
121/** Unsupported pin-based VM-execution controls combo. */
122#define VMX_UFC_CTRL_PIN_EXEC 1
123/** Unsupported processor-based VM-execution controls combo. */
124#define VMX_UFC_CTRL_PROC_EXEC 2
125/** Unsupported move debug register VM-exit combo. */
126#define VMX_UFC_CTRL_PROC_MOV_DRX_EXIT 3
127/** Unsupported VM-entry controls combo. */
128#define VMX_UFC_CTRL_ENTRY 4
129/** Unsupported VM-exit controls combo. */
130#define VMX_UFC_CTRL_EXIT 5
131/** MSR storage capacity of the VMCS autoload/store area is not sufficient
132 * for storing host MSRs. */
133#define VMX_UFC_INSUFFICIENT_HOST_MSR_STORAGE 6
134/** MSR storage capacity of the VMCS autoload/store area is not sufficient
135 * for storing guest MSRs. */
136#define VMX_UFC_INSUFFICIENT_GUEST_MSR_STORAGE 7
137/** Invalid VMCS size. */
138#define VMX_UFC_INVALID_VMCS_SIZE 8
139/** Unsupported secondary processor-based VM-execution controls combo. */
140#define VMX_UFC_CTRL_PROC_EXEC2 9
141/** Invalid unrestricted-guest execution controls combo. */
142#define VMX_UFC_INVALID_UX_COMBO 10
143/** EPT flush type not supported. */
144#define VMX_UFC_EPT_FLUSH_TYPE_UNSUPPORTED 11
145/** EPT paging structure memory type is not write-back. */
146#define VMX_UFC_EPT_MEM_TYPE_NOT_WB 12
147/** EPT requires INVEPT instr. support but it's not available. */
148#define VMX_UFC_EPT_INVEPT_UNAVAILABLE 13
149/** EPT requires page-walk length of 4. */
150#define VMX_UFC_EPT_PAGE_WALK_LENGTH_UNSUPPORTED 14
151/** @} */
152
153/** @name VMX HM-error codes for VERR_VMX_VMCS_FIELD_CACHE_INVALID.
154 * VCI = VMCS-field Cache Invalid.
155 * @{
156 */
157/** Cache of VM-entry controls invalid. */
158#define VMX_VCI_CTRL_ENTRY 300
159/** Cache of VM-exit controls invalid. */
160#define VMX_VCI_CTRL_EXIT 301
161/** Cache of pin-based VM-execution controls invalid. */
162#define VMX_VCI_CTRL_PIN_EXEC 302
163/** Cache of processor-based VM-execution controls invalid. */
164#define VMX_VCI_CTRL_PROC_EXEC 303
165/** Cache of secondary processor-based VM-execution controls invalid. */
166#define VMX_VCI_CTRL_PROC_EXEC2 304
167/** Cache of exception bitmap invalid. */
168#define VMX_VCI_CTRL_XCPT_BITMAP 305
169/** Cache of TSC offset invalid. */
170#define VMX_VCI_CTRL_TSC_OFFSET 306
171/** @} */
172
173/** @name VMX HM-error codes for VERR_VMX_INVALID_GUEST_STATE.
174 * IGS = Invalid Guest State.
175 * @{
176 */
177/** An error occurred while checking invalid-guest-state. */
178#define VMX_IGS_ERROR 500
179/** The invalid guest-state checks did not find any reason why. */
180#define VMX_IGS_REASON_NOT_FOUND 501
181/** CR0 fixed1 bits invalid. */
182#define VMX_IGS_CR0_FIXED1 502
183/** CR0 fixed0 bits invalid. */
184#define VMX_IGS_CR0_FIXED0 503
185/** CR0.PE and CR0.PE invalid VT-x/host combination. */
186#define VMX_IGS_CR0_PG_PE_COMBO 504
187/** CR4 fixed1 bits invalid. */
188#define VMX_IGS_CR4_FIXED1 505
189/** CR4 fixed0 bits invalid. */
190#define VMX_IGS_CR4_FIXED0 506
191/** Reserved bits in VMCS' DEBUGCTL MSR field not set to 0 when
192 * VMX_VMCS_CTRL_ENTRY_LOAD_DEBUG is used. */
193#define VMX_IGS_DEBUGCTL_MSR_RESERVED 507
194/** CR0.PG not set for long-mode when not using unrestricted guest. */
195#define VMX_IGS_CR0_PG_LONGMODE 508
196/** CR4.PAE not set for long-mode guest when not using unrestricted guest. */
197#define VMX_IGS_CR4_PAE_LONGMODE 509
198/** CR4.PCIDE set for 32-bit guest. */
199#define VMX_IGS_CR4_PCIDE 510
200/** VMCS' DR7 reserved bits not set to 0. */
201#define VMX_IGS_DR7_RESERVED 511
202/** VMCS' PERF_GLOBAL MSR reserved bits not set to 0. */
203#define VMX_IGS_PERF_GLOBAL_MSR_RESERVED 512
204/** VMCS' EFER MSR reserved bits not set to 0. */
205#define VMX_IGS_EFER_MSR_RESERVED 513
206/** VMCS' EFER MSR.LMA does not match the IA32e mode guest control. */
207#define VMX_IGS_EFER_LMA_GUEST_MODE_MISMATCH 514
208/** VMCS' EFER MSR.LMA does not match EFER.LME of the guest when using paging
209 * without unrestricted guest. */
210#define VMX_IGS_EFER_LMA_LME_MISMATCH 515
211/** CS.Attr.P bit invalid. */
212#define VMX_IGS_CS_ATTR_P_INVALID 516
213/** CS.Attr reserved bits not set to 0. */
214#define VMX_IGS_CS_ATTR_RESERVED 517
215/** CS.Attr.G bit invalid. */
216#define VMX_IGS_CS_ATTR_G_INVALID 518
217/** CS is unusable. */
218#define VMX_IGS_CS_ATTR_UNUSABLE 519
219/** CS and SS DPL unequal. */
220#define VMX_IGS_CS_SS_ATTR_DPL_UNEQUAL 520
221/** CS and SS DPL mismatch. */
222#define VMX_IGS_CS_SS_ATTR_DPL_MISMATCH 521
223/** CS Attr.Type invalid. */
224#define VMX_IGS_CS_ATTR_TYPE_INVALID 522
225/** CS and SS RPL unequal. */
226#define VMX_IGS_SS_CS_RPL_UNEQUAL 523
227/** SS.Attr.DPL and SS RPL unequal. */
228#define VMX_IGS_SS_ATTR_DPL_RPL_UNEQUAL 524
229/** SS.Attr.DPL invalid for segment type. */
230#define VMX_IGS_SS_ATTR_DPL_INVALID 525
231/** SS.Attr.Type invalid. */
232#define VMX_IGS_SS_ATTR_TYPE_INVALID 526
233/** SS.Attr.P bit invalid. */
234#define VMX_IGS_SS_ATTR_P_INVALID 527
235/** SS.Attr reserved bits not set to 0. */
236#define VMX_IGS_SS_ATTR_RESERVED 528
237/** SS.Attr.G bit invalid. */
238#define VMX_IGS_SS_ATTR_G_INVALID 529
239/** DS.Attr.A bit invalid. */
240#define VMX_IGS_DS_ATTR_A_INVALID 530
241/** DS.Attr.P bit invalid. */
242#define VMX_IGS_DS_ATTR_P_INVALID 531
243/** DS.Attr.DPL and DS RPL unequal. */
244#define VMX_IGS_DS_ATTR_DPL_RPL_UNEQUAL 532
245/** DS.Attr reserved bits not set to 0. */
246#define VMX_IGS_DS_ATTR_RESERVED 533
247/** DS.Attr.G bit invalid. */
248#define VMX_IGS_DS_ATTR_G_INVALID 534
249/** DS.Attr.Type invalid. */
250#define VMX_IGS_DS_ATTR_TYPE_INVALID 535
251/** ES.Attr.A bit invalid. */
252#define VMX_IGS_ES_ATTR_A_INVALID 536
253/** ES.Attr.P bit invalid. */
254#define VMX_IGS_ES_ATTR_P_INVALID 537
255/** ES.Attr.DPL and DS RPL unequal. */
256#define VMX_IGS_ES_ATTR_DPL_RPL_UNEQUAL 538
257/** ES.Attr reserved bits not set to 0. */
258#define VMX_IGS_ES_ATTR_RESERVED 539
259/** ES.Attr.G bit invalid. */
260#define VMX_IGS_ES_ATTR_G_INVALID 540
261/** ES.Attr.Type invalid. */
262#define VMX_IGS_ES_ATTR_TYPE_INVALID 541
263/** FS.Attr.A bit invalid. */
264#define VMX_IGS_FS_ATTR_A_INVALID 542
265/** FS.Attr.P bit invalid. */
266#define VMX_IGS_FS_ATTR_P_INVALID 543
267/** FS.Attr.DPL and DS RPL unequal. */
268#define VMX_IGS_FS_ATTR_DPL_RPL_UNEQUAL 544
269/** FS.Attr reserved bits not set to 0. */
270#define VMX_IGS_FS_ATTR_RESERVED 545
271/** FS.Attr.G bit invalid. */
272#define VMX_IGS_FS_ATTR_G_INVALID 546
273/** FS.Attr.Type invalid. */
274#define VMX_IGS_FS_ATTR_TYPE_INVALID 547
275/** GS.Attr.A bit invalid. */
276#define VMX_IGS_GS_ATTR_A_INVALID 548
277/** GS.Attr.P bit invalid. */
278#define VMX_IGS_GS_ATTR_P_INVALID 549
279/** GS.Attr.DPL and DS RPL unequal. */
280#define VMX_IGS_GS_ATTR_DPL_RPL_UNEQUAL 550
281/** GS.Attr reserved bits not set to 0. */
282#define VMX_IGS_GS_ATTR_RESERVED 551
283/** GS.Attr.G bit invalid. */
284#define VMX_IGS_GS_ATTR_G_INVALID 552
285/** GS.Attr.Type invalid. */
286#define VMX_IGS_GS_ATTR_TYPE_INVALID 553
287/** V86 mode CS.Base invalid. */
288#define VMX_IGS_V86_CS_BASE_INVALID 554
289/** V86 mode CS.Limit invalid. */
290#define VMX_IGS_V86_CS_LIMIT_INVALID 555
291/** V86 mode CS.Attr invalid. */
292#define VMX_IGS_V86_CS_ATTR_INVALID 556
293/** V86 mode SS.Base invalid. */
294#define VMX_IGS_V86_SS_BASE_INVALID 557
295/** V86 mode SS.Limit invalid. */
296#define VMX_IGS_V86_SS_LIMIT_INVALID 558
297/** V86 mode SS.Attr invalid. */
298#define VMX_IGS_V86_SS_ATTR_INVALID 559
299/** V86 mode DS.Base invalid. */
300#define VMX_IGS_V86_DS_BASE_INVALID 560
301/** V86 mode DS.Limit invalid. */
302#define VMX_IGS_V86_DS_LIMIT_INVALID 561
303/** V86 mode DS.Attr invalid. */
304#define VMX_IGS_V86_DS_ATTR_INVALID 562
305/** V86 mode ES.Base invalid. */
306#define VMX_IGS_V86_ES_BASE_INVALID 563
307/** V86 mode ES.Limit invalid. */
308#define VMX_IGS_V86_ES_LIMIT_INVALID 564
309/** V86 mode ES.Attr invalid. */
310#define VMX_IGS_V86_ES_ATTR_INVALID 565
311/** V86 mode FS.Base invalid. */
312#define VMX_IGS_V86_FS_BASE_INVALID 566
313/** V86 mode FS.Limit invalid. */
314#define VMX_IGS_V86_FS_LIMIT_INVALID 567
315/** V86 mode FS.Attr invalid. */
316#define VMX_IGS_V86_FS_ATTR_INVALID 568
317/** V86 mode GS.Base invalid. */
318#define VMX_IGS_V86_GS_BASE_INVALID 569
319/** V86 mode GS.Limit invalid. */
320#define VMX_IGS_V86_GS_LIMIT_INVALID 570
321/** V86 mode GS.Attr invalid. */
322#define VMX_IGS_V86_GS_ATTR_INVALID 571
323/** Longmode CS.Base invalid. */
324#define VMX_IGS_LONGMODE_CS_BASE_INVALID 572
325/** Longmode SS.Base invalid. */
326#define VMX_IGS_LONGMODE_SS_BASE_INVALID 573
327/** Longmode DS.Base invalid. */
328#define VMX_IGS_LONGMODE_DS_BASE_INVALID 574
329/** Longmode ES.Base invalid. */
330#define VMX_IGS_LONGMODE_ES_BASE_INVALID 575
331/** SYSENTER ESP is not canonical. */
332#define VMX_IGS_SYSENTER_ESP_NOT_CANONICAL 576
333/** SYSENTER EIP is not canonical. */
334#define VMX_IGS_SYSENTER_EIP_NOT_CANONICAL 577
335/** PAT MSR invalid. */
336#define VMX_IGS_PAT_MSR_INVALID 578
337/** PAT MSR reserved bits not set to 0. */
338#define VMX_IGS_PAT_MSR_RESERVED 579
339/** GDTR.Base is not canonical. */
340#define VMX_IGS_GDTR_BASE_NOT_CANONICAL 580
341/** IDTR.Base is not canonical. */
342#define VMX_IGS_IDTR_BASE_NOT_CANONICAL 581
343/** GDTR.Limit invalid. */
344#define VMX_IGS_GDTR_LIMIT_INVALID 582
345/** IDTR.Limit invalid. */
346#define VMX_IGS_IDTR_LIMIT_INVALID 583
347/** Longmode RIP is invalid. */
348#define VMX_IGS_LONGMODE_RIP_INVALID 584
349/** RFLAGS reserved bits not set to 0. */
350#define VMX_IGS_RFLAGS_RESERVED 585
351/** RFLAGS RA1 reserved bits not set to 1. */
352#define VMX_IGS_RFLAGS_RESERVED1 586
353/** RFLAGS.VM (V86 mode) invalid. */
354#define VMX_IGS_RFLAGS_VM_INVALID 587
355/** RFLAGS.IF invalid. */
356#define VMX_IGS_RFLAGS_IF_INVALID 588
357/** Activity state invalid. */
358#define VMX_IGS_ACTIVITY_STATE_INVALID 589
359/** Activity state HLT invalid when SS.Attr.DPL is not zero. */
360#define VMX_IGS_ACTIVITY_STATE_HLT_INVALID 590
361/** Activity state ACTIVE invalid when block-by-STI or MOV SS. */
362#define VMX_IGS_ACTIVITY_STATE_ACTIVE_INVALID 591
363/** Activity state SIPI WAIT invalid. */
364#define VMX_IGS_ACTIVITY_STATE_SIPI_WAIT_INVALID 592
365/** Interruptibility state reserved bits not set to 0. */
366#define VMX_IGS_INTERRUPTIBILITY_STATE_RESERVED 593
367/** Interruptibility state cannot be block-by-STI -and- MOV SS. */
368#define VMX_IGS_INTERRUPTIBILITY_STATE_STI_MOVSS_INVALID 594
369/** Interruptibility state block-by-STI invalid for EFLAGS. */
370#define VMX_IGS_INTERRUPTIBILITY_STATE_STI_EFL_INVALID 595
371/** Interruptibility state invalid while trying to deliver external
372 * interrupt. */
373#define VMX_IGS_INTERRUPTIBILITY_STATE_EXT_INT_INVALID 596
374/** Interruptibility state block-by-MOVSS invalid while trying to deliver an
375 * NMI. */
376#define VMX_IGS_INTERRUPTIBILITY_STATE_MOVSS_INVALID 597
377/** Interruptibility state block-by-SMI invalid when CPU is not in SMM. */
378#define VMX_IGS_INTERRUPTIBILITY_STATE_SMI_INVALID 598
379/** Interruptibility state block-by-SMI invalid when trying to enter SMM. */
380#define VMX_IGS_INTERRUPTIBILITY_STATE_SMI_SMM_INVALID 599
381/** Interruptibility state block-by-STI (maybe) invalid when trying to
382 * deliver an NMI. */
383#define VMX_IGS_INTERRUPTIBILITY_STATE_STI_INVALID 600
384/** Interruptibility state block-by-NMI invalid when virtual-NMIs control is
385 * active. */
386#define VMX_IGS_INTERRUPTIBILITY_STATE_NMI_INVALID 601
387/** Pending debug exceptions reserved bits not set to 0. */
388#define VMX_IGS_PENDING_DEBUG_RESERVED 602
389/** Longmode pending debug exceptions reserved bits not set to 0. */
390#define VMX_IGS_LONGMODE_PENDING_DEBUG_RESERVED 603
391/** Pending debug exceptions.BS bit is not set when it should be. */
392#define VMX_IGS_PENDING_DEBUG_XCPT_BS_NOT_SET 604
393/** Pending debug exceptions.BS bit is not clear when it should be. */
394#define VMX_IGS_PENDING_DEBUG_XCPT_BS_NOT_CLEAR 605
395/** VMCS link pointer reserved bits not set to 0. */
396#define VMX_IGS_VMCS_LINK_PTR_RESERVED 606
397/** TR cannot index into LDT, TI bit MBZ. */
398#define VMX_IGS_TR_TI_INVALID 607
399/** LDTR cannot index into LDT. TI bit MBZ. */
400#define VMX_IGS_LDTR_TI_INVALID 608
401/** TR.Base is not canonical. */
402#define VMX_IGS_TR_BASE_NOT_CANONICAL 609
403/** FS.Base is not canonical. */
404#define VMX_IGS_FS_BASE_NOT_CANONICAL 610
405/** GS.Base is not canonical. */
406#define VMX_IGS_GS_BASE_NOT_CANONICAL 611
407/** LDTR.Base is not canonical. */
408#define VMX_IGS_LDTR_BASE_NOT_CANONICAL 612
409/** TR is unusable. */
410#define VMX_IGS_TR_ATTR_UNUSABLE 613
411/** TR.Attr.S bit invalid. */
412#define VMX_IGS_TR_ATTR_S_INVALID 614
413/** TR is not present. */
414#define VMX_IGS_TR_ATTR_P_INVALID 615
415/** TR.Attr reserved bits not set to 0. */
416#define VMX_IGS_TR_ATTR_RESERVED 616
417/** TR.Attr.G bit invalid. */
418#define VMX_IGS_TR_ATTR_G_INVALID 617
419/** Longmode TR.Attr.Type invalid. */
420#define VMX_IGS_LONGMODE_TR_ATTR_TYPE_INVALID 618
421/** TR.Attr.Type invalid. */
422#define VMX_IGS_TR_ATTR_TYPE_INVALID 619
423/** CS.Attr.S invalid. */
424#define VMX_IGS_CS_ATTR_S_INVALID 620
425/** CS.Attr.DPL invalid. */
426#define VMX_IGS_CS_ATTR_DPL_INVALID 621
427/** PAE PDPTE reserved bits not set to 0. */
428#define VMX_IGS_PAE_PDPTE_RESERVED 623
429/** @} */
430
431/** @name VMX VMCS-Read cache indices.
432 * @{
433 */
434#define VMX_VMCS_GUEST_ES_BASE_CACHE_IDX 0
435#define VMX_VMCS_GUEST_CS_BASE_CACHE_IDX 1
436#define VMX_VMCS_GUEST_SS_BASE_CACHE_IDX 2
437#define VMX_VMCS_GUEST_DS_BASE_CACHE_IDX 3
438#define VMX_VMCS_GUEST_FS_BASE_CACHE_IDX 4
439#define VMX_VMCS_GUEST_GS_BASE_CACHE_IDX 5
440#define VMX_VMCS_GUEST_LDTR_BASE_CACHE_IDX 6
441#define VMX_VMCS_GUEST_TR_BASE_CACHE_IDX 7
442#define VMX_VMCS_GUEST_GDTR_BASE_CACHE_IDX 8
443#define VMX_VMCS_GUEST_IDTR_BASE_CACHE_IDX 9
444#define VMX_VMCS_GUEST_RSP_CACHE_IDX 10
445#define VMX_VMCS_GUEST_RIP_CACHE_IDX 11
446#define VMX_VMCS_GUEST_SYSENTER_ESP_CACHE_IDX 12
447#define VMX_VMCS_GUEST_SYSENTER_EIP_CACHE_IDX 13
448#define VMX_VMCS_RO_EXIT_QUALIFICATION_CACHE_IDX 14
449#define VMX_VMCS_MAX_CACHE_IDX (VMX_VMCS_RO_EXIT_QUALIFICATION_CACHE_IDX + 1)
450#define VMX_VMCS_GUEST_CR3_CACHE_IDX 15
451#define VMX_VMCS_MAX_NESTED_PAGING_CACHE_IDX (VMX_VMCS_GUEST_CR3_CACHE_IDX + 1)
452/** @} */
453
454/** @name VMX EPT paging structures
455 * @{
456 */
457
458/**
459 * Number of page table entries in the EPT. (PDPTE/PDE/PTE)
460 */
461#define EPT_PG_ENTRIES X86_PG_PAE_ENTRIES
462
463/**
464 * EPT Page Directory Pointer Entry. Bit view.
465 * @todo uint64_t isn't safe for bitfields (gcc pedantic warnings, and IIRC,
466 * this did cause trouble with one compiler/version).
467 */
468typedef struct EPTPML4EBITS
469{
470 /** Present bit. */
471 uint64_t u1Present : 1;
472 /** Writable bit. */
473 uint64_t u1Write : 1;
474 /** Executable bit. */
475 uint64_t u1Execute : 1;
476 /** Reserved (must be 0). */
477 uint64_t u5Reserved : 5;
478 /** Available for software. */
479 uint64_t u4Available : 4;
480 /** Physical address of the next level (PD). Restricted by maximum physical address width of the cpu. */
481 uint64_t u40PhysAddr : 40;
482 /** Available for software. */
483 uint64_t u12Available : 12;
484} EPTPML4EBITS;
485AssertCompileSize(EPTPML4EBITS, 8);
486
487/** Bits 12-51 - - EPT - Physical Page number of the next level. */
488#define EPT_PML4E_PG_MASK X86_PML4E_PG_MASK
489/** The page shift to get the PML4 index. */
490#define EPT_PML4_SHIFT X86_PML4_SHIFT
491/** The PML4 index mask (apply to a shifted page address). */
492#define EPT_PML4_MASK X86_PML4_MASK
493
494/**
495 * EPT PML4E.
496 */
497typedef union EPTPML4E
498{
499 /** Normal view. */
500 EPTPML4EBITS n;
501 /** Unsigned integer view. */
502 X86PGPAEUINT u;
503 /** 64 bit unsigned integer view. */
504 uint64_t au64[1];
505 /** 32 bit unsigned integer view. */
506 uint32_t au32[2];
507} EPTPML4E;
508AssertCompileSize(EPTPML4E, 8);
509/** Pointer to a PML4 table entry. */
510typedef EPTPML4E *PEPTPML4E;
511/** Pointer to a const PML4 table entry. */
512typedef const EPTPML4E *PCEPTPML4E;
513
514/**
515 * EPT PML4 Table.
516 */
517typedef struct EPTPML4
518{
519 EPTPML4E a[EPT_PG_ENTRIES];
520} EPTPML4;
521AssertCompileSize(EPTPML4, 0x1000);
522/** Pointer to an EPT PML4 Table. */
523typedef EPTPML4 *PEPTPML4;
524/** Pointer to a const EPT PML4 Table. */
525typedef const EPTPML4 *PCEPTPML4;
526
527/**
528 * EPT Page Directory Pointer Entry. Bit view.
529 */
530typedef struct EPTPDPTEBITS
531{
532 /** Present bit. */
533 uint64_t u1Present : 1;
534 /** Writable bit. */
535 uint64_t u1Write : 1;
536 /** Executable bit. */
537 uint64_t u1Execute : 1;
538 /** Reserved (must be 0). */
539 uint64_t u5Reserved : 5;
540 /** Available for software. */
541 uint64_t u4Available : 4;
542 /** Physical address of the next level (PD). Restricted by maximum physical address width of the cpu. */
543 uint64_t u40PhysAddr : 40;
544 /** Available for software. */
545 uint64_t u12Available : 12;
546} EPTPDPTEBITS;
547AssertCompileSize(EPTPDPTEBITS, 8);
548
549/** Bits 12-51 - - EPT - Physical Page number of the next level. */
550#define EPT_PDPTE_PG_MASK X86_PDPE_PG_MASK
551/** The page shift to get the PDPT index. */
552#define EPT_PDPT_SHIFT X86_PDPT_SHIFT
553/** The PDPT index mask (apply to a shifted page address). */
554#define EPT_PDPT_MASK X86_PDPT_MASK_AMD64
555
556/**
557 * EPT Page Directory Pointer.
558 */
559typedef union EPTPDPTE
560{
561 /** Normal view. */
562 EPTPDPTEBITS n;
563 /** Unsigned integer view. */
564 X86PGPAEUINT u;
565 /** 64 bit unsigned integer view. */
566 uint64_t au64[1];
567 /** 32 bit unsigned integer view. */
568 uint32_t au32[2];
569} EPTPDPTE;
570AssertCompileSize(EPTPDPTE, 8);
571/** Pointer to an EPT Page Directory Pointer Entry. */
572typedef EPTPDPTE *PEPTPDPTE;
573/** Pointer to a const EPT Page Directory Pointer Entry. */
574typedef const EPTPDPTE *PCEPTPDPTE;
575
576/**
577 * EPT Page Directory Pointer Table.
578 */
579typedef struct EPTPDPT
580{
581 EPTPDPTE a[EPT_PG_ENTRIES];
582} EPTPDPT;
583AssertCompileSize(EPTPDPT, 0x1000);
584/** Pointer to an EPT Page Directory Pointer Table. */
585typedef EPTPDPT *PEPTPDPT;
586/** Pointer to a const EPT Page Directory Pointer Table. */
587typedef const EPTPDPT *PCEPTPDPT;
588
589/**
590 * EPT Page Directory Table Entry. Bit view.
591 */
592typedef struct EPTPDEBITS
593{
594 /** Present bit. */
595 uint64_t u1Present : 1;
596 /** Writable bit. */
597 uint64_t u1Write : 1;
598 /** Executable bit. */
599 uint64_t u1Execute : 1;
600 /** Reserved (must be 0). */
601 uint64_t u4Reserved : 4;
602 /** Big page (must be 0 here). */
603 uint64_t u1Size : 1;
604 /** Available for software. */
605 uint64_t u4Available : 4;
606 /** Physical address of page table. Restricted by maximum physical address width of the cpu. */
607 uint64_t u40PhysAddr : 40;
608 /** Available for software. */
609 uint64_t u12Available : 12;
610} EPTPDEBITS;
611AssertCompileSize(EPTPDEBITS, 8);
612
613/** Bits 12-51 - - EPT - Physical Page number of the next level. */
614#define EPT_PDE_PG_MASK X86_PDE_PAE_PG_MASK
615/** The page shift to get the PD index. */
616#define EPT_PD_SHIFT X86_PD_PAE_SHIFT
617/** The PD index mask (apply to a shifted page address). */
618#define EPT_PD_MASK X86_PD_PAE_MASK
619
620/**
621 * EPT 2MB Page Directory Table Entry. Bit view.
622 */
623typedef struct EPTPDE2MBITS
624{
625 /** Present bit. */
626 uint64_t u1Present : 1;
627 /** Writable bit. */
628 uint64_t u1Write : 1;
629 /** Executable bit. */
630 uint64_t u1Execute : 1;
631 /** EPT Table Memory Type. MBZ for non-leaf nodes. */
632 uint64_t u3EMT : 3;
633 /** Ignore PAT memory type */
634 uint64_t u1IgnorePAT : 1;
635 /** Big page (must be 1 here). */
636 uint64_t u1Size : 1;
637 /** Available for software. */
638 uint64_t u4Available : 4;
639 /** Reserved (must be 0). */
640 uint64_t u9Reserved : 9;
641 /** Physical address of the 2MB page. Restricted by maximum physical address width of the cpu. */
642 uint64_t u31PhysAddr : 31;
643 /** Available for software. */
644 uint64_t u12Available : 12;
645} EPTPDE2MBITS;
646AssertCompileSize(EPTPDE2MBITS, 8);
647
648/** Bits 21-51 - - EPT - Physical Page number of the next level. */
649#define EPT_PDE2M_PG_MASK X86_PDE2M_PAE_PG_MASK
650
651/**
652 * EPT Page Directory Table Entry.
653 */
654typedef union EPTPDE
655{
656 /** Normal view. */
657 EPTPDEBITS n;
658 /** 2MB view (big). */
659 EPTPDE2MBITS b;
660 /** Unsigned integer view. */
661 X86PGPAEUINT u;
662 /** 64 bit unsigned integer view. */
663 uint64_t au64[1];
664 /** 32 bit unsigned integer view. */
665 uint32_t au32[2];
666} EPTPDE;
667AssertCompileSize(EPTPDE, 8);
668/** Pointer to an EPT Page Directory Table Entry. */
669typedef EPTPDE *PEPTPDE;
670/** Pointer to a const EPT Page Directory Table Entry. */
671typedef const EPTPDE *PCEPTPDE;
672
673/**
674 * EPT Page Directory Table.
675 */
676typedef struct EPTPD
677{
678 EPTPDE a[EPT_PG_ENTRIES];
679} EPTPD;
680AssertCompileSize(EPTPD, 0x1000);
681/** Pointer to an EPT Page Directory Table. */
682typedef EPTPD *PEPTPD;
683/** Pointer to a const EPT Page Directory Table. */
684typedef const EPTPD *PCEPTPD;
685
686/**
687 * EPT Page Table Entry. Bit view.
688 */
689typedef struct EPTPTEBITS
690{
691 /** 0 - Present bit.
692 * @remarks This is a convenience "misnomer". The bit actually indicates read access
693 * and the CPU will consider an entry with any of the first three bits set
694 * as present. Since all our valid entries will have this bit set, it can
695 * be used as a present indicator and allow some code sharing. */
696 uint64_t u1Present : 1;
697 /** 1 - Writable bit. */
698 uint64_t u1Write : 1;
699 /** 2 - Executable bit. */
700 uint64_t u1Execute : 1;
701 /** 5:3 - EPT Memory Type. MBZ for non-leaf nodes. */
702 uint64_t u3EMT : 3;
703 /** 6 - Ignore PAT memory type */
704 uint64_t u1IgnorePAT : 1;
705 /** 11:7 - Available for software. */
706 uint64_t u5Available : 5;
707 /** 51:12 - Physical address of page. Restricted by maximum physical
708 * address width of the cpu. */
709 uint64_t u40PhysAddr : 40;
710 /** 63:52 - Available for software. */
711 uint64_t u12Available : 12;
712} EPTPTEBITS;
713AssertCompileSize(EPTPTEBITS, 8);
714
715/** Bits 12-51 - - EPT - Physical Page number of the next level. */
716#define EPT_PTE_PG_MASK X86_PTE_PAE_PG_MASK
717/** The page shift to get the EPT PTE index. */
718#define EPT_PT_SHIFT X86_PT_PAE_SHIFT
719/** The EPT PT index mask (apply to a shifted page address). */
720#define EPT_PT_MASK X86_PT_PAE_MASK
721
722/**
723 * EPT Page Table Entry.
724 */
725typedef union EPTPTE
726{
727 /** Normal view. */
728 EPTPTEBITS n;
729 /** Unsigned integer view. */
730 X86PGPAEUINT u;
731 /** 64 bit unsigned integer view. */
732 uint64_t au64[1];
733 /** 32 bit unsigned integer view. */
734 uint32_t au32[2];
735} EPTPTE;
736AssertCompileSize(EPTPTE, 8);
737/** Pointer to an EPT Page Directory Table Entry. */
738typedef EPTPTE *PEPTPTE;
739/** Pointer to a const EPT Page Directory Table Entry. */
740typedef const EPTPTE *PCEPTPTE;
741
742/**
743 * EPT Page Table.
744 */
745typedef struct EPTPT
746{
747 EPTPTE a[EPT_PG_ENTRIES];
748} EPTPT;
749AssertCompileSize(EPTPT, 0x1000);
750/** Pointer to an extended page table. */
751typedef EPTPT *PEPTPT;
752/** Pointer to a const extended table. */
753typedef const EPTPT *PCEPTPT;
754
755/** @} */
756
757/**
758 * VMX VPID flush types.
759 * @note Valid enum members are in accordance to the VT-x spec.
760 */
761typedef enum
762{
763 /** Invalidate a specific page. */
764 VMXTLBFLUSHVPID_INDIV_ADDR = 0,
765 /** Invalidate one context (specific VPID). */
766 VMXTLBFLUSHVPID_SINGLE_CONTEXT = 1,
767 /** Invalidate all contexts (all VPIDs). */
768 VMXTLBFLUSHVPID_ALL_CONTEXTS = 2,
769 /** Invalidate a single VPID context retaining global mappings. */
770 VMXTLBFLUSHVPID_SINGLE_CONTEXT_RETAIN_GLOBALS = 3,
771 /** Unsupported by VirtualBox. */
772 VMXTLBFLUSHVPID_NOT_SUPPORTED = 0xbad0,
773 /** Unsupported by CPU. */
774 VMXTLBFLUSHVPID_NONE = 0xbad1
775} VMXTLBFLUSHVPID;
776AssertCompileSize(VMXTLBFLUSHVPID, 4);
777
778/**
779 * VMX EPT flush types.
780 * @note Valid enums values are in accordance to the VT-x spec.
781 */
782typedef enum
783{
784 /** Invalidate one context (specific EPT). */
785 VMXTLBFLUSHEPT_SINGLE_CONTEXT = 1,
786 /* Invalidate all contexts (all EPTs) */
787 VMXTLBFLUSHEPT_ALL_CONTEXTS = 2,
788 /** Unsupported by VirtualBox. */
789 VMXTLBFLUSHEPT_NOT_SUPPORTED = 0xbad0,
790 /** Unsupported by CPU. */
791 VMXTLBFLUSHEPT_NONE = 0xbad1
792} VMXTLBFLUSHEPT;
793AssertCompileSize(VMXTLBFLUSHEPT, 4);
794
795/**
796 * VMX Posted Interrupt Descriptor.
797 * In accordance to the VT-x spec.
798 */
799typedef struct VMXPOSTEDINTRDESC
800{
801 uint32_t aVectorBitmap[8];
802 uint32_t fOutstandingNotification : 1;
803 uint32_t uReserved0 : 31;
804 uint8_t au8Reserved0[28];
805} VMXPOSTEDINTRDESC;
806AssertCompileMemberSize(VMXPOSTEDINTRDESC, aVectorBitmap, 32);
807AssertCompileSize(VMXPOSTEDINTRDESC, 64);
808/** Pointer to a posted interrupt descriptor. */
809typedef VMXPOSTEDINTRDESC *PVMXPOSTEDINTRDESC;
810/** Pointer to a const posted interrupt descriptor. */
811typedef const VMXPOSTEDINTRDESC *PCVMXPOSTEDINTRDESC;
812
813/**
814 * VMX MSR autoload/store element.
815 * In accordance to the VT-x spec.
816 */
817typedef struct VMXAUTOMSR
818{
819 /** The MSR Id. */
820 uint32_t u32Msr;
821 /** Reserved (MBZ). */
822 uint32_t u32Reserved;
823 /** The MSR value. */
824 uint64_t u64Value;
825} VMXAUTOMSR;
826AssertCompileSize(VMXAUTOMSR, 16);
827/** Pointer to an MSR load/store element. */
828typedef VMXAUTOMSR *PVMXAUTOMSR;
829/** Pointer to a const MSR load/store element. */
830typedef const VMXAUTOMSR *PCVMXAUTOMSR;
831
832/**
833 * VMX-capability qword.
834 */
835typedef union
836{
837 struct
838 {
839 /** Bits set here -must- be set in the corresponding VM-execution controls. */
840 uint32_t disallowed0;
841 /** Bits cleared here -must- be cleared in the corresponding VM-execution
842 * controls. */
843 uint32_t allowed1;
844 } n;
845 uint64_t u;
846} VMXCAPABILITY;
847AssertCompileSize(VMXCAPABILITY, 8);
848
849/**
850 * VMX tagged-TLB flush types.
851 */
852typedef enum
853{
854 VMXTLBFLUSHTYPE_EPT,
855 VMXTLBFLUSHTYPE_VPID,
856 VMXTLBFLUSHTYPE_EPT_VPID,
857 VMXTLBFLUSHTYPE_NONE
858} VMXTLBFLUSHTYPE;
859/** Pointer to a VMXTLBFLUSHTYPE enum. */
860typedef VMXTLBFLUSHTYPE *PVMXTLBFLUSHTYPE;
861/** Pointer to a const VMXTLBFLUSHTYPE enum. */
862typedef const VMXTLBFLUSHTYPE *PCVMXTLBFLUSHTYPE;
863
864/**
865 * VMX MSRs.
866 */
867typedef struct VMXMSRS
868{
869 uint64_t u64FeatureCtrl;
870 uint64_t u64BasicInfo;
871 VMXCAPABILITY VmxPinCtls;
872 VMXCAPABILITY VmxProcCtls;
873 VMXCAPABILITY VmxProcCtls2;
874 VMXCAPABILITY VmxExit;
875 VMXCAPABILITY VmxEntry;
876 uint64_t u64Misc;
877 uint64_t u64Cr0Fixed0;
878 uint64_t u64Cr0Fixed1;
879 uint64_t u64Cr4Fixed0;
880 uint64_t u64Cr4Fixed1;
881 uint64_t u64VmcsEnum;
882 uint64_t u64Vmfunc;
883 uint64_t u64EptVpidCaps;
884} VMXMSRS;
885AssertCompileSizeAlignment(VMXMSRS, 8);
886/** Pointer to a VMXMSRS struct. */
887typedef VMXMSRS *PVMXMSRS;
888
889/** @name VMX Basic Exit Reasons.
890 * @{
891 */
892/** -1 Invalid exit code */
893#define VMX_EXIT_INVALID (-1)
894/** 0 Exception or non-maskable interrupt (NMI). */
895#define VMX_EXIT_XCPT_OR_NMI 0
896/** 1 External interrupt. */
897#define VMX_EXIT_EXT_INT 1
898/** 2 Triple fault. */
899#define VMX_EXIT_TRIPLE_FAULT 2
900/** 3 INIT signal. */
901#define VMX_EXIT_INIT_SIGNAL 3
902/** 4 Start-up IPI (SIPI). */
903#define VMX_EXIT_SIPI 4
904/** 5 I/O system-management interrupt (SMI). */
905#define VMX_EXIT_IO_SMI 5
906/** 6 Other SMI. */
907#define VMX_EXIT_SMI 6
908/** 7 Interrupt window exiting. */
909#define VMX_EXIT_INT_WINDOW 7
910/** 8 NMI window exiting. */
911#define VMX_EXIT_NMI_WINDOW 8
912/** 9 Task switch. */
913#define VMX_EXIT_TASK_SWITCH 9
914/** 10 Guest software attempted to execute CPUID. */
915#define VMX_EXIT_CPUID 10
916/** 11 Guest software attempted to execute GETSEC. */
917#define VMX_EXIT_GETSEC 11
918/** 12 Guest software attempted to execute HLT. */
919#define VMX_EXIT_HLT 12
920/** 13 Guest software attempted to execute INVD. */
921#define VMX_EXIT_INVD 13
922/** 14 Guest software attempted to execute INVLPG. */
923#define VMX_EXIT_INVLPG 14
924/** 15 Guest software attempted to execute RDPMC. */
925#define VMX_EXIT_RDPMC 15
926/** 16 Guest software attempted to execute RDTSC. */
927#define VMX_EXIT_RDTSC 16
928/** 17 Guest software attempted to execute RSM in SMM. */
929#define VMX_EXIT_RSM 17
930/** 18 Guest software executed VMCALL. */
931#define VMX_EXIT_VMCALL 18
932/** 19 Guest software executed VMCLEAR. */
933#define VMX_EXIT_VMCLEAR 19
934/** 20 Guest software executed VMLAUNCH. */
935#define VMX_EXIT_VMLAUNCH 20
936/** 21 Guest software executed VMPTRLD. */
937#define VMX_EXIT_VMPTRLD 21
938/** 22 Guest software executed VMPTRST. */
939#define VMX_EXIT_VMPTRST 22
940/** 23 Guest software executed VMREAD. */
941#define VMX_EXIT_VMREAD 23
942/** 24 Guest software executed VMRESUME. */
943#define VMX_EXIT_VMRESUME 24
944/** 25 Guest software executed VMWRITE. */
945#define VMX_EXIT_VMWRITE 25
946/** 26 Guest software executed VMXOFF. */
947#define VMX_EXIT_VMXOFF 26
948/** 27 Guest software executed VMXON. */
949#define VMX_EXIT_VMXON 27
950/** 28 Control-register accesses. */
951#define VMX_EXIT_MOV_CRX 28
952/** 29 Debug-register accesses. */
953#define VMX_EXIT_MOV_DRX 29
954/** 30 I/O instruction. */
955#define VMX_EXIT_IO_INSTR 30
956/** 31 RDMSR. Guest software attempted to execute RDMSR. */
957#define VMX_EXIT_RDMSR 31
958/** 32 WRMSR. Guest software attempted to execute WRMSR. */
959#define VMX_EXIT_WRMSR 32
960/** 33 VM-entry failure due to invalid guest state. */
961#define VMX_EXIT_ERR_INVALID_GUEST_STATE 33
962/** 34 VM-entry failure due to MSR loading. */
963#define VMX_EXIT_ERR_MSR_LOAD 34
964/** 36 Guest software executed MWAIT. */
965#define VMX_EXIT_MWAIT 36
966/** 37 VM-exit due to monitor trap flag. */
967#define VMX_EXIT_MTF 37
968/** 39 Guest software attempted to execute MONITOR. */
969#define VMX_EXIT_MONITOR 39
970/** 40 Guest software attempted to execute PAUSE. */
971#define VMX_EXIT_PAUSE 40
972/** 41 VM-entry failure due to machine-check. */
973#define VMX_EXIT_ERR_MACHINE_CHECK 41
974/** 43 TPR below threshold. Guest software executed MOV to CR8. */
975#define VMX_EXIT_TPR_BELOW_THRESHOLD 43
976/** 44 APIC access. Guest software attempted to access memory at a physical
977 * address on the APIC-access page. */
978#define VMX_EXIT_APIC_ACCESS 44
979/** 45 Virtualized EOI. EOI virtualization was performed for a virtual
980 * interrupt whose vector indexed a bit set in the EOI-exit bitmap. */
981#define VMX_EXIT_VIRTUALIZED_EOI 45
982/** 46 Access to GDTR or IDTR. Guest software attempted to execute LGDT, LIDT,
983 * SGDT, or SIDT. */
984#define VMX_EXIT_XDTR_ACCESS 46
985/** 47 Access to LDTR or TR. Guest software attempted to execute LLDT, LTR,
986 * SLDT, or STR. */
987#define VMX_EXIT_TR_ACCESS 47
988/** 48 EPT violation. An attempt to access memory with a guest-physical address
989 * was disallowed by the configuration of the EPT paging structures. */
990#define VMX_EXIT_EPT_VIOLATION 48
991/** 49 EPT misconfiguration. An attempt to access memory with a guest-physical
992 * address encountered a misconfigured EPT paging-structure entry. */
993#define VMX_EXIT_EPT_MISCONFIG 49
994/** 50 INVEPT. Guest software attempted to execute INVEPT. */
995#define VMX_EXIT_INVEPT 50
996/** 51 RDTSCP. Guest software attempted to execute RDTSCP. */
997#define VMX_EXIT_RDTSCP 51
998/** 52 VMX-preemption timer expired. The preemption timer counted down to zero. */
999#define VMX_EXIT_PREEMPT_TIMER 52
1000/** 53 INVVPID. Guest software attempted to execute INVVPID. */
1001#define VMX_EXIT_INVVPID 53
1002/** 54 WBINVD. Guest software attempted to execute WBINVD. */
1003#define VMX_EXIT_WBINVD 54
1004/** 55 XSETBV. Guest software attempted to execute XSETBV. */
1005#define VMX_EXIT_XSETBV 55
1006/** 56 APIC write. Guest completed write to virtual-APIC. */
1007#define VMX_EXIT_APIC_WRITE 56
1008/** 57 RDRAND. Guest software attempted to execute RDRAND. */
1009#define VMX_EXIT_RDRAND 57
1010/** 58 INVPCID. Guest software attempted to execute INVPCID. */
1011#define VMX_EXIT_INVPCID 58
1012/** 59 VMFUNC. Guest software attempted to execute VMFUNC. */
1013#define VMX_EXIT_VMFUNC 59
1014/** 60 ENCLS. Guest software attempted to execute ENCLS. */
1015#define VMX_EXIT_ENCLS 60
1016/** 61 - RDSEED - Guest software attempted to executed RDSEED and exiting was
1017 * enabled. */
1018#define VMX_EXIT_RDSEED 61
1019/** 62 - Page-modification log full. */
1020#define VMX_EXIT_PML_FULL 62
1021/** 63 - XSAVES - Guest software attempted to executed XSAVES and exiting was
1022 * enabled (XSAVES/XRSTORS was enabled too, of course). */
1023#define VMX_EXIT_XSAVES 63
1024/** 63 - XRSTORS - Guest software attempted to executed XRSTORS and exiting
1025 * was enabled (XSAVES/XRSTORS was enabled too, of course). */
1026#define VMX_EXIT_XRSTORS 64
1027/** The maximum exit value (inclusive). */
1028#define VMX_EXIT_MAX (VMX_EXIT_XRSTORS)
1029/** @} */
1030
1031
1032/** @name VM Instruction Errors
1033 * @{
1034 */
1035/** VMCALL executed in VMX root operation. */
1036#define VMX_ERROR_VMCALL 1
1037/** VMCLEAR with invalid physical address. */
1038#define VMX_ERROR_VMCLEAR_INVALID_PHYS_ADDR 2
1039/** VMCLEAR with VMXON pointer. */
1040#define VMX_ERROR_VMCLEAR_INVALID_VMXON_PTR 3
1041/** VMLAUNCH with non-clear VMCS. */
1042#define VMX_ERROR_VMLAUCH_NON_CLEAR_VMCS 4
1043/** VMRESUME with non-launched VMCS. */
1044#define VMX_ERROR_VMRESUME_NON_LAUNCHED_VMCS 5
1045/** VMRESUME with a corrupted VMCS (indicates corruption of the current VMCS). */
1046#define VMX_ERROR_VMRESUME_CORRUPTED_VMCS 6
1047/** VM-entry with invalid control field(s). */
1048#define VMX_ERROR_VMENTRY_INVALID_CONTROL_FIELDS 7
1049/** VM-entry with invalid host-state field(s). */
1050#define VMX_ERROR_VMENTRY_INVALID_HOST_STATE 8
1051/** VMPTRLD with invalid physical address. */
1052#define VMX_ERROR_VMPTRLD_INVALID_PHYS_ADDR 9
1053/** VMPTRLD with VMXON pointer. */
1054#define VMX_ERROR_VMPTRLD_VMXON_PTR 10
1055/** VMPTRLD with incorrect VMCS revision identifier. */
1056#define VMX_ERROR_VMPTRLD_WRONG_VMCS_REVISION 11
1057/** VMREAD/VMWRITE from/to unsupported VMCS component. */
1058#define VMX_ERROR_VMREAD_INVALID_COMPONENT 12
1059#define VMX_ERROR_VMWRITE_INVALID_COMPONENT VMX_ERROR_VMREAD_INVALID_COMPONENT
1060/** VMWRITE to read-only VMCS component. */
1061#define VMX_ERROR_VMWRITE_READONLY_COMPONENT 13
1062/** VMXON executed in VMX root operation. */
1063#define VMX_ERROR_VMXON_IN_VMX_ROOT_OP 15
1064/** VM-entry with invalid executive-VMCS pointer. */
1065#define VMX_ERROR_VMENTRY_INVALID_VMCS_EXEC_PTR 16
1066/** VM-entry with non-launched executive VMCS. */
1067#define VMX_ERROR_VMENTRY_NON_LAUNCHED_EXEC_VMCS 17
1068/** VM-entry with executive-VMCS pointer not VMXON pointer. */
1069#define VMX_ERROR_VMENTRY_EXEC_VMCS_PTR 18
1070/** VMCALL with non-clear VMCS. */
1071#define VMX_ERROR_VMCALL_NON_CLEAR_VMCS 19
1072/** VMCALL with invalid VM-exit control fields. */
1073#define VMX_ERROR_VMCALL_INVALID_VMEXIT_FIELDS 20
1074/** VMCALL with incorrect MSEG revision identifier. */
1075#define VMX_ERROR_VMCALL_INVALID_MSEG_REVISION 22
1076/** VMXOFF under dual-monitor treatment of SMIs and SMM. */
1077#define VMX_ERROR_VMXOFF_DUAL_MONITOR 23
1078/** VMCALL with invalid SMM-monitor features. */
1079#define VMX_ERROR_VMCALL_INVALID_SMM_MONITOR 24
1080/** VM-entry with invalid VM-execution control fields in executive VMCS. */
1081#define VMX_ERROR_VMENTRY_INVALID_VM_EXEC_CTRL 25
1082/** VM-entry with events blocked by MOV SS. */
1083#define VMX_ERROR_VMENTRY_MOV_SS 26
1084/** Invalid operand to INVEPT/INVVPID. */
1085#define VMX_ERROR_INVEPTVPID_INVALID_OPERAND 28
1086/** @} */
1087
1088
1089/** @name VMX MSRs - Basic VMX information.
1090 * @{
1091 */
1092/** VMCS revision identifier used by the processor. */
1093#define MSR_IA32_VMX_BASIC_VMCS_ID(a) ((a) & 0x7fffffff)
1094/** Shift to get the VMCS size. */
1095#define MSR_IA32_VMX_BASIC_VMCS_SIZE_SHIFT 32
1096/** VMCS size in bytes. */
1097#define MSR_IA32_VMX_BASIC_VMCS_SIZE(a) (((a) >> 32) & 0x1fff)
1098/** Shift to get the width of physical addresses and associated memory regions. */
1099#define MSR_IA32_VMX_BASIC_VMCS_PHYS_WIDTH_SHIFT 48
1100/** Width of physical addresses used for the VMCS and associated memory regions. */
1101#define MSR_IA32_VMX_BASIC_VMCS_PHYS_WIDTH(a) (((a) >> 48) & 1)
1102/** Shift to get the dual-monitor treatment of SMI and SMM. */
1103#define MSR_IA32_VMX_BASIC_DUAL_MON_SHIFT 49
1104/** Dual-monitor treatment of SMI and SMM supported. */
1105#define MSR_IA32_VMX_BASIC_DUAL_MON(a) (((a) >> 49) & 1)
1106/** Shift to get the memory type that must be used for the VMCS and associated
1107 * memory regions. */
1108#define MSR_IA32_VMX_BASIC_VMCS_MEM_TYPE_SHIFT 50
1109/** Memory type that must be used for the VMCS and associated memory regions. */
1110#define MSR_IA32_VMX_BASIC_VMCS_MEM_TYPE(a) (((a) >> 50) & 0xf)
1111/** Shift to get the additional VM-exit information for INS/OUTS. */
1112#define MSR_IA32_VMX_BASIC_VMCS_INS_OUTS_SHIFT 54
1113/** Additional VM-exit information for INS/OUTS. */
1114#define MSR_IA32_VMX_BASIC_VMCS_INS_OUTS(a) (((a) >> 54) & 1)
1115/** Shift to get the VMCS true controls. */
1116#define MSR_IA32_VMX_BASIC_TRUE_CONTROLS_SHIFT 55
1117/** Whether default 1 bits in control MSRs (pin/proc/exit/entry) may be
1118 * cleared to 0 and that 'true' control MSRs are supported. */
1119#define MSR_IA32_VMX_BASIC_TRUE_CONTROLS(a) (((a) >> 55) & 1)
1120/** @} */
1121
1122
1123/** @name VMX MSRs - Misc VMX info.
1124 * @{
1125 */
1126/** Relationship between the preemption timer and tsc; count down every time bit
1127 * x of the tsc changes. */
1128#define MSR_IA32_VMX_MISC_PREEMPT_TSC_BIT(a) ((a) & 0x1f)
1129/** Whether VM-exit stores EFER.LMA into the "IA32e mode guest" field. */
1130#define MSR_IA32_VMX_MISC_STORE_EFERLMA_VMEXIT(a) (((a) >> 5) & 1)
1131/** Activity states supported by the implementation. */
1132#define MSR_IA32_VMX_MISC_ACTIVITY_STATES(a) (((a) >> 6) & 0x7)
1133/** Number of CR3 target values supported by the processor. (0-256) */
1134#define MSR_IA32_VMX_MISC_CR3_TARGET(a) (((a) >> 16) & 0x1ff)
1135/** Maximum number of MSRs in the VMCS. (N+1)*512. */
1136#define MSR_IA32_VMX_MISC_MAX_MSR(a) (((((a) >> 25) & 0x7) + 1) * 512)
1137/** Whether RDMSR can be used to read IA32_SMBASE_MSR in SMM. */
1138#define MSR_IA32_VMX_MISC_RDMSR_SMBASE_MSR_SMM(a) (((a) >> 15) & 1)
1139/** Whether bit 2 of IA32_SMM_MONITOR_CTL can be set to 1. */
1140#define MSR_IA32_VMX_MISC_SMM_MONITOR_CTL_B2(a) (((a) >> 28) & 1)
1141/** Whether VMWRITE can be used to write VM-exit information fields. */
1142#define MSR_IA32_VMX_MISC_VMWRITE_VMEXIT_INFO(a) (((a) >> 29) & 1)
1143/** MSEG revision identifier used by the processor. */
1144#define MSR_IA32_VMX_MISC_MSEG_ID(a) ((a) >> 32)
1145/** @} */
1146
1147
1148/** @name VMX MSRs - VMCS enumeration field info
1149 * @{
1150 */
1151/** Highest field index. */
1152#define MSR_IA32_VMX_VMCS_ENUM_HIGHEST_INDEX(a) (((a) >> 1) & 0x1ff)
1153/** @} */
1154
1155
1156/** @name MSR_IA32_VMX_EPT_VPID_CAPS; EPT capabilities MSR
1157 * @{
1158 */
1159#define MSR_IA32_VMX_EPT_VPID_CAP_RWX_X_ONLY RT_BIT_64(0)
1160#define MSR_IA32_VMX_EPT_VPID_CAP_PAGE_WALK_LENGTH_4 RT_BIT_64(6)
1161#define MSR_IA32_VMX_EPT_VPID_CAP_EMT_UC RT_BIT_64(8)
1162#define MSR_IA32_VMX_EPT_VPID_CAP_EMT_WB RT_BIT_64(14)
1163#define MSR_IA32_VMX_EPT_VPID_CAP_PDE_2M RT_BIT_64(16)
1164#define MSR_IA32_VMX_EPT_VPID_CAP_PDPTE_1G RT_BIT_64(17)
1165#define MSR_IA32_VMX_EPT_VPID_CAP_INVEPT RT_BIT_64(20)
1166#define MSR_IA32_VMX_EPT_VPID_CAP_EPT_ACCESS_DIRTY RT_BIT_64(21)
1167#define MSR_IA32_VMX_EPT_VPID_CAP_INVEPT_SINGLE_CONTEXT RT_BIT_64(25)
1168#define MSR_IA32_VMX_EPT_VPID_CAP_INVEPT_ALL_CONTEXTS RT_BIT_64(26)
1169#define MSR_IA32_VMX_EPT_VPID_CAP_INVVPID RT_BIT_64(32)
1170#define MSR_IA32_VMX_EPT_VPID_CAP_INVVPID_INDIV_ADDR RT_BIT_64(40)
1171#define MSR_IA32_VMX_EPT_VPID_CAP_INVVPID_SINGLE_CONTEXT RT_BIT_64(41)
1172#define MSR_IA32_VMX_EPT_VPID_CAP_INVVPID_ALL_CONTEXTS RT_BIT_64(42)
1173#define MSR_IA32_VMX_EPT_VPID_CAP_INVVPID_SINGLE_CONTEXT_RETAIN_GLOBALS RT_BIT_64(43)
1174/** @} */
1175
1176/** @name Extended Page Table Pointer (EPTP)
1177 * @{
1178 */
1179/** Uncachable EPT paging structure memory type. */
1180#define VMX_EPT_MEMTYPE_UC 0
1181/** Write-back EPT paging structure memory type. */
1182#define VMX_EPT_MEMTYPE_WB 6
1183/** Shift value to get the EPT page walk length (bits 5-3) */
1184#define VMX_EPT_PAGE_WALK_LENGTH_SHIFT 3
1185/** Mask value to get the EPT page walk length (bits 5-3) */
1186#define VMX_EPT_PAGE_WALK_LENGTH_MASK 7
1187/** Default EPT page-walk length (1 less than the actual EPT page-walk
1188 * length) */
1189#define VMX_EPT_PAGE_WALK_LENGTH_DEFAULT 3
1190/** @} */
1191
1192
1193/** @name VMCS field encoding: 16-bit guest fields.
1194 * @{
1195 */
1196#define VMX_VMCS16_VPID 0x000
1197#define VMX_VMCS16_POSTED_INTR_NOTIFY_VECTOR 0x002
1198#define VMX_VMCS16_EPTP_INDEX 0x004
1199#define VMX_VMCS16_GUEST_ES_SEL 0x800
1200#define VMX_VMCS16_GUEST_CS_SEL 0x802
1201#define VMX_VMCS16_GUEST_SS_SEL 0x804
1202#define VMX_VMCS16_GUEST_DS_SEL 0x806
1203#define VMX_VMCS16_GUEST_FS_SEL 0x808
1204#define VMX_VMCS16_GUEST_GS_SEL 0x80a
1205#define VMX_VMCS16_GUEST_LDTR_SEL 0x80c
1206#define VMX_VMCS16_GUEST_TR_SEL 0x80e
1207#define VMX_VMCS16_GUEST_INTR_STATUS 0x810
1208/** @} */
1209
1210/** @name VMCS field encoding: 16-bits host fields.
1211 * @{
1212 */
1213#define VMX_VMCS16_HOST_ES_SEL 0xc00
1214#define VMX_VMCS16_HOST_CS_SEL 0xc02
1215#define VMX_VMCS16_HOST_SS_SEL 0xc04
1216#define VMX_VMCS16_HOST_DS_SEL 0xc06
1217#define VMX_VMCS16_HOST_FS_SEL 0xc08
1218#define VMX_VMCS16_HOST_GS_SEL 0xc0a
1219#define VMX_VMCS16_HOST_TR_SEL 0xc0c
1220/** @} */
1221
1222/** @name VMCS field encoding: 64-bit host fields.
1223 * @{
1224 */
1225#define VMX_VMCS64_HOST_PAT_FULL 0x2c00
1226#define VMX_VMCS64_HOST_PAT_HIGH 0x2c01
1227#define VMX_VMCS64_HOST_EFER_FULL 0x2c02
1228#define VMX_VMCS64_HOST_EFER_HIGH 0x2c03
1229#define VMX_VMCS64_HOST_PERF_GLOBAL_CTRL_FULL 0x2c04 /**< MSR IA32_PERF_GLOBAL_CTRL */
1230#define VMX_VMCS64_HOST_PERF_GLOBAL_CTRL_HIGH 0x2c05 /**< MSR IA32_PERF_GLOBAL_CTRL */
1231/** @} */
1232
1233
1234/** @name VMCS field encoding: 64-bit control fields.
1235 * @{
1236 */
1237#define VMX_VMCS64_CTRL_IO_BITMAP_A_FULL 0x2000
1238#define VMX_VMCS64_CTRL_IO_BITMAP_A_HIGH 0x2001
1239#define VMX_VMCS64_CTRL_IO_BITMAP_B_FULL 0x2002
1240#define VMX_VMCS64_CTRL_IO_BITMAP_B_HIGH 0x2003
1241#define VMX_VMCS64_CTRL_MSR_BITMAP_FULL 0x2004
1242#define VMX_VMCS64_CTRL_MSR_BITMAP_HIGH 0x2005
1243#define VMX_VMCS64_CTRL_EXIT_MSR_STORE_FULL 0x2006
1244#define VMX_VMCS64_CTRL_EXIT_MSR_STORE_HIGH 0x2007
1245#define VMX_VMCS64_CTRL_EXIT_MSR_LOAD_FULL 0x2008
1246#define VMX_VMCS64_CTRL_EXIT_MSR_LOAD_HIGH 0x2009
1247#define VMX_VMCS64_CTRL_ENTRY_MSR_LOAD_FULL 0x200a
1248#define VMX_VMCS64_CTRL_ENTRY_MSR_LOAD_HIGH 0x200b
1249#define VMX_VMCS64_CTRL_EXEC_VMCS_PTR_FULL 0x200c
1250#define VMX_VMCS64_CTRL_EXEC_VMCS_PTR_HIGH 0x200d
1251#define VMX_VMCS64_CTRL_TSC_OFFSET_FULL 0x2010
1252#define VMX_VMCS64_CTRL_TSC_OFFSET_HIGH 0x2011
1253#define VMX_VMCS64_CTRL_VAPIC_PAGEADDR_FULL 0x2012
1254#define VMX_VMCS64_CTRL_VAPIC_PAGEADDR_HIGH 0x2013
1255#define VMX_VMCS64_CTRL_APIC_ACCESSADDR_FULL 0x2014
1256#define VMX_VMCS64_CTRL_APIC_ACCESSADDR_HIGH 0x2015
1257#define VMX_VMCS64_CTRL_POSTED_INTR_DESC_FULL 0x2016
1258#define VMX_VMCS64_CTRL_POSTED_INTR_DESC_HIGH 0x2017
1259#define VMX_VMCS64_CTRL_VMFUNC_CTRLS_FULL 0x2018
1260#define VMX_VMCS64_CTRL_VMFUNC_CTRLS_HIGH 0x2019
1261#define VMX_VMCS64_CTRL_EPTP_FULL 0x201a
1262#define VMX_VMCS64_CTRL_EPTP_HIGH 0x201b
1263#define VMX_VMCS64_CTRL_EOI_BITMAP_0_FULL 0x201c
1264#define VMX_VMCS64_CTRL_EOI_BITMAP_0_HIGH 0x201d
1265#define VMX_VMCS64_CTRL_EOI_BITMAP_1_FULL 0x201e
1266#define VMX_VMCS64_CTRL_EOI_BITMAP_1_HIGH 0x201f
1267#define VMX_VMCS64_CTRL_EOI_BITMAP_2_FULL 0x2020
1268#define VMX_VMCS64_CTRL_EOI_BITMAP_2_HIGH 0x2021
1269#define VMX_VMCS64_CTRL_EOI_BITMAP_3_FULL 0x2022
1270#define VMX_VMCS64_CTRL_EOI_BITMAP_3_HIGH 0x2023
1271#define VMX_VMCS64_CTRL_EPTP_LIST_FULL 0x2024
1272#define VMX_VMCS64_CTRL_EPTP_LIST_HIGH 0x2025
1273#define VMX_VMCS64_CTRL_VMREAD_BITMAP_FULL 0x2026
1274#define VMX_VMCS64_CTRL_VMREAD_BITMAP_HIGH 0x2027
1275#define VMX_VMCS64_CTRL_VMWRITE_BITMAP_FULL 0x2028
1276#define VMX_VMCS64_CTRL_VMWRITE_BITMAP_HIGH 0x2029
1277#define VMX_VMCS64_CTRL_VIRTXCPT_INFO_ADDR_FULL 0x202a
1278#define VMX_VMCS64_CTRL_VIRTXCPT_INFO_ADDR_HIGH 0x202b
1279#define VMX_VMCS64_CTRL_XSS_EXITING_BITMAP_FULL 0x202c
1280#define VMX_VMCS64_CTRL_XSS_EXITING_BITMAP_HIGH 0x202d
1281#define VMX_VMCS64_CTRL_TSC_MULTIPLIER_FULL 0x2032
1282#define VMX_VMCS64_CTRL_TSC_MULTIPLIER_HIGH 0x2033
1283#define VMX_VMCS64_EXIT_GUEST_PHYS_ADDR_FULL 0x2400
1284#define VMX_VMCS64_EXIT_GUEST_PHYS_ADDR_HIGH 0x2401
1285/** @} */
1286
1287
1288/** @name VMCS field encoding: 64-bit guest fields.
1289 * @{
1290 */
1291#define VMX_VMCS64_GUEST_VMCS_LINK_PTR_FULL 0x2800
1292#define VMX_VMCS64_GUEST_VMCS_LINK_PTR_HIGH 0x2801
1293#define VMX_VMCS64_GUEST_DEBUGCTL_FULL 0x2802 /**< MSR IA32_DEBUGCTL */
1294#define VMX_VMCS64_GUEST_DEBUGCTL_HIGH 0x2803 /**< MSR IA32_DEBUGCTL */
1295#define VMX_VMCS64_GUEST_PAT_FULL 0x2804
1296#define VMX_VMCS64_GUEST_PAT_HIGH 0x2805
1297#define VMX_VMCS64_GUEST_EFER_FULL 0x2806
1298#define VMX_VMCS64_GUEST_EFER_HIGH 0x2807
1299#define VMX_VMCS64_GUEST_PERF_GLOBAL_CTRL_FULL 0x2808 /**< MSR IA32_PERF_GLOBAL_CTRL */
1300#define VMX_VMCS64_GUEST_PERF_GLOBAL_CTRL_HIGH 0x2809 /**< MSR IA32_PERF_GLOBAL_CTRL */
1301#define VMX_VMCS64_GUEST_PDPTE0_FULL 0x280a
1302#define VMX_VMCS64_GUEST_PDPTE0_HIGH 0x280b
1303#define VMX_VMCS64_GUEST_PDPTE1_FULL 0x280c
1304#define VMX_VMCS64_GUEST_PDPTE1_HIGH 0x280d
1305#define VMX_VMCS64_GUEST_PDPTE2_FULL 0x280e
1306#define VMX_VMCS64_GUEST_PDPTE2_HIGH 0x280f
1307#define VMX_VMCS64_GUEST_PDPTE3_FULL 0x2810
1308#define VMX_VMCS64_GUEST_PDPTE3_HIGH 0x2811
1309/** @} */
1310
1311
1312/** @name VMCS field encoding: 32-bit control fields.
1313 * @{
1314 */
1315#define VMX_VMCS32_CTRL_PIN_EXEC 0x4000
1316#define VMX_VMCS32_CTRL_PROC_EXEC 0x4002
1317#define VMX_VMCS32_CTRL_EXCEPTION_BITMAP 0x4004
1318#define VMX_VMCS32_CTRL_PAGEFAULT_ERROR_MASK 0x4006
1319#define VMX_VMCS32_CTRL_PAGEFAULT_ERROR_MATCH 0x4008
1320#define VMX_VMCS32_CTRL_CR3_TARGET_COUNT 0x400a
1321#define VMX_VMCS32_CTRL_EXIT 0x400c
1322#define VMX_VMCS32_CTRL_EXIT_MSR_STORE_COUNT 0x400e
1323#define VMX_VMCS32_CTRL_EXIT_MSR_LOAD_COUNT 0x4010
1324#define VMX_VMCS32_CTRL_ENTRY 0x4012
1325#define VMX_VMCS32_CTRL_ENTRY_MSR_LOAD_COUNT 0x4014
1326#define VMX_VMCS32_CTRL_ENTRY_INTERRUPTION_INFO 0x4016
1327#define VMX_VMCS32_CTRL_ENTRY_EXCEPTION_ERRCODE 0x4018
1328#define VMX_VMCS32_CTRL_ENTRY_INSTR_LENGTH 0x401a
1329#define VMX_VMCS32_CTRL_TPR_THRESHOLD 0x401c
1330#define VMX_VMCS32_CTRL_PROC_EXEC2 0x401e
1331#define VMX_VMCS32_CTRL_PLE_GAP 0x4020
1332#define VMX_VMCS32_CTRL_PLE_WINDOW 0x4022
1333/** @} */
1334
1335
1336/** @name VMX_VMCS_CTRL_PIN_EXEC
1337 * @{
1338 */
1339/** External interrupts cause VM-exits if set; otherwise dispatched through the
1340 * guest's IDT. */
1341#define VMX_VMCS_CTRL_PIN_EXEC_EXT_INT_EXIT RT_BIT(0)
1342/** Non-maskable interrupts cause VM-exits if set; otherwise dispatched through
1343 * the guest's IDT. */
1344#define VMX_VMCS_CTRL_PIN_EXEC_NMI_EXIT RT_BIT(3)
1345/** Virtual NMIs. */
1346#define VMX_VMCS_CTRL_PIN_EXEC_VIRTUAL_NMI RT_BIT(5)
1347/** Activate VMX preemption timer. */
1348#define VMX_VMCS_CTRL_PIN_EXEC_PREEMPT_TIMER RT_BIT(6)
1349/** Process interrupts with the posted-interrupt notification vector. */
1350#define VMX_VMCS_CTRL_PIN_EXEC_POSTED_INTR RT_BIT(7)
1351/* All other bits are reserved and must be set according to MSR IA32_VMX_PROCBASED_CTLS. */
1352/** @} */
1353
1354
1355/** @name VMX_VMCS_CTRL_PROC_EXEC
1356 * @{
1357 */
1358/** VM-exit as soon as RFLAGS.IF=1 and no blocking is active. */
1359#define VMX_VMCS_CTRL_PROC_EXEC_INT_WINDOW_EXIT RT_BIT(2)
1360/** Use timestamp counter offset. */
1361#define VMX_VMCS_CTRL_PROC_EXEC_USE_TSC_OFFSETTING RT_BIT(3)
1362/** VM-exit when executing the HLT instruction. */
1363#define VMX_VMCS_CTRL_PROC_EXEC_HLT_EXIT RT_BIT(7)
1364/** VM-exit when executing the INVLPG instruction. */
1365#define VMX_VMCS_CTRL_PROC_EXEC_INVLPG_EXIT RT_BIT(9)
1366/** VM-exit when executing the MWAIT instruction. */
1367#define VMX_VMCS_CTRL_PROC_EXEC_MWAIT_EXIT RT_BIT(10)
1368/** VM-exit when executing the RDPMC instruction. */
1369#define VMX_VMCS_CTRL_PROC_EXEC_RDPMC_EXIT RT_BIT(11)
1370/** VM-exit when executing the RDTSC/RDTSCP instruction. */
1371#define VMX_VMCS_CTRL_PROC_EXEC_RDTSC_EXIT RT_BIT(12)
1372/** VM-exit when executing the MOV to CR3 instruction. (forced to 1 on the
1373 * 'first' VT-x capable CPUs; this actually includes the newest Nehalem CPUs) */
1374#define VMX_VMCS_CTRL_PROC_EXEC_CR3_LOAD_EXIT RT_BIT(15)
1375/** VM-exit when executing the MOV from CR3 instruction. (forced to 1 on the
1376 * 'first' VT-x capable CPUs; this actually includes the newest Nehalem CPUs) */
1377#define VMX_VMCS_CTRL_PROC_EXEC_CR3_STORE_EXIT RT_BIT(16)
1378/** VM-exit on CR8 loads. */
1379#define VMX_VMCS_CTRL_PROC_EXEC_CR8_LOAD_EXIT RT_BIT(19)
1380/** VM-exit on CR8 stores. */
1381#define VMX_VMCS_CTRL_PROC_EXEC_CR8_STORE_EXIT RT_BIT(20)
1382/** Use TPR shadow. */
1383#define VMX_VMCS_CTRL_PROC_EXEC_USE_TPR_SHADOW RT_BIT(21)
1384/** VM-exit when virtual NMI blocking is disabled. */
1385#define VMX_VMCS_CTRL_PROC_EXEC_NMI_WINDOW_EXIT RT_BIT(22)
1386/** VM-exit when executing a MOV DRx instruction. */
1387#define VMX_VMCS_CTRL_PROC_EXEC_MOV_DR_EXIT RT_BIT(23)
1388/** VM-exit when executing IO instructions. */
1389#define VMX_VMCS_CTRL_PROC_EXEC_UNCOND_IO_EXIT RT_BIT(24)
1390/** Use IO bitmaps. */
1391#define VMX_VMCS_CTRL_PROC_EXEC_USE_IO_BITMAPS RT_BIT(25)
1392/** Monitor trap flag. */
1393#define VMX_VMCS_CTRL_PROC_EXEC_MONITOR_TRAP_FLAG RT_BIT(27)
1394/** Use MSR bitmaps. */
1395#define VMX_VMCS_CTRL_PROC_EXEC_USE_MSR_BITMAPS RT_BIT(28)
1396/** VM-exit when executing the MONITOR instruction. */
1397#define VMX_VMCS_CTRL_PROC_EXEC_MONITOR_EXIT RT_BIT(29)
1398/** VM-exit when executing the PAUSE instruction. */
1399#define VMX_VMCS_CTRL_PROC_EXEC_PAUSE_EXIT RT_BIT(30)
1400/** Whether the secondary processor based VM-execution controls are used. */
1401#define VMX_VMCS_CTRL_PROC_EXEC_USE_SECONDARY_EXEC_CTRL RT_BIT(31)
1402/** @} */
1403
1404
1405/** @name VMX_VMCS_CTRL_PROC_EXEC2
1406 * @{
1407 */
1408/** Virtualize APIC access. */
1409#define VMX_VMCS_CTRL_PROC_EXEC2_VIRT_APIC RT_BIT(0)
1410/** EPT supported/enabled. */
1411#define VMX_VMCS_CTRL_PROC_EXEC2_EPT RT_BIT(1)
1412/** Descriptor table instructions cause VM-exits. */
1413#define VMX_VMCS_CTRL_PROC_EXEC2_DESCRIPTOR_TABLE_EXIT RT_BIT(2)
1414/** RDTSCP supported/enabled. */
1415#define VMX_VMCS_CTRL_PROC_EXEC2_RDTSCP RT_BIT(3)
1416/** Virtualize x2APIC mode. */
1417#define VMX_VMCS_CTRL_PROC_EXEC2_VIRT_X2APIC RT_BIT(4)
1418/** VPID supported/enabled. */
1419#define VMX_VMCS_CTRL_PROC_EXEC2_VPID RT_BIT(5)
1420/** VM-exit when executing the WBINVD instruction. */
1421#define VMX_VMCS_CTRL_PROC_EXEC2_WBINVD_EXIT RT_BIT(6)
1422/** Unrestricted guest execution. */
1423#define VMX_VMCS_CTRL_PROC_EXEC2_UNRESTRICTED_GUEST RT_BIT(7)
1424/** APIC register virtualization. */
1425#define VMX_VMCS_CTRL_PROC_EXEC2_APIC_REG_VIRT RT_BIT(8)
1426/** Virtual-interrupt delivery. */
1427#define VMX_VMCS_CTRL_PROC_EXEC2_VIRT_INTR_DELIVERY RT_BIT(9)
1428/** A specified number of pause loops cause a VM-exit. */
1429#define VMX_VMCS_CTRL_PROC_EXEC2_PAUSE_LOOP_EXIT RT_BIT(10)
1430/** VM-exit when executing RDRAND instructions. */
1431#define VMX_VMCS_CTRL_PROC_EXEC2_RDRAND_EXIT RT_BIT(11)
1432/** Enables INVPCID instructions. */
1433#define VMX_VMCS_CTRL_PROC_EXEC2_INVPCID RT_BIT(12)
1434/** Enables VMFUNC instructions. */
1435#define VMX_VMCS_CTRL_PROC_EXEC2_VMFUNC RT_BIT(13)
1436/** Enables VMCS shadowing. */
1437#define VMX_VMCS_CTRL_PROC_EXEC2_VMCS_SHADOWING RT_BIT(14)
1438/** Enables ENCLS VM-exits. */
1439#define VMX_VMCS_CTRL_PROC_EXEC2_ENCLS_EXIT RT_BIT(15)
1440/** VM-exit when executing RDSEED. */
1441#define VMX_VMCS_CTRL_PROC_EXEC2_RDSEED_EXIT RT_BIT(16)
1442/** Enables page-modification logging. */
1443#define VMX_VMCS_CTRL_PROC_EXEC2_PML RT_BIT(17)
1444/** Controls whether EPT-violations may cause \#VE instead of exits. */
1445#define VMX_VMCS_CTRL_PROC_EXEC2_EPT_VE RT_BIT(18)
1446/** Conceal VMX non-root operation from Intel processor trace (PT). */
1447#define VMX_VMCS_CTRL_PROC_EXEC2_CONCEAL_FROM_PT RT_BIT(19)
1448/** Enables XSAVES/XRSTORS instructions. */
1449#define VMX_VMCS_CTRL_PROC_EXEC2_XSAVES_XRSTORS RT_BIT(20)
1450/** Use TSC scaling. */
1451#define VMX_VMCS_CTRL_PROC_EXEC2_TSC_SCALING RT_BIT(25)
1452/** @} */
1453
1454
1455/** @name VMX_VMCS_CTRL_ENTRY
1456 * @{
1457 */
1458/** Load guest debug controls (dr7 & IA32_DEBUGCTL_MSR) (forced to 1 on the
1459 * 'first' VT-x capable CPUs; this actually includes the newest Nehalem CPUs) */
1460#define VMX_VMCS_CTRL_ENTRY_LOAD_DEBUG RT_BIT(2)
1461/** 64 bits guest mode. Must be 0 for CPUs that don't support AMD64. */
1462#define VMX_VMCS_CTRL_ENTRY_IA32E_MODE_GUEST RT_BIT(9)
1463/** In SMM mode after VM-entry. */
1464#define VMX_VMCS_CTRL_ENTRY_ENTRY_SMM RT_BIT(10)
1465/** Disable dual treatment of SMI and SMM; must be zero for VM-entry outside of SMM. */
1466#define VMX_VMCS_CTRL_ENTRY_DEACTIVATE_DUALMON RT_BIT(11)
1467/** Whether the guest IA32_PERF_GLOBAL_CTRL MSR is loaded on VM-entry. */
1468#define VMX_VMCS_CTRL_ENTRY_LOAD_GUEST_PERF_MSR RT_BIT(13)
1469/** Whether the guest IA32_PAT MSR is loaded on VM-entry. */
1470#define VMX_VMCS_CTRL_ENTRY_LOAD_GUEST_PAT_MSR RT_BIT(14)
1471/** Whether the guest IA32_EFER MSR is loaded on VM-entry. */
1472#define VMX_VMCS_CTRL_ENTRY_LOAD_GUEST_EFER_MSR RT_BIT(15)
1473/** @} */
1474
1475
1476/** @name VMX_VMCS_CTRL_EXIT
1477 * @{
1478 */
1479/** Save guest debug controls (dr7 & IA32_DEBUGCTL_MSR) (forced to 1 on the
1480 * 'first' VT-x capable CPUs; this actually includes the newest Nehalem CPUs) */
1481#define VMX_VMCS_CTRL_EXIT_SAVE_DEBUG RT_BIT(2)
1482/** Return to long mode after a VM-exit. */
1483#define VMX_VMCS_CTRL_EXIT_HOST_ADDR_SPACE_SIZE RT_BIT(9)
1484/** Whether the IA32_PERF_GLOBAL_CTRL MSR is loaded on VM-exit. */
1485#define VMX_VMCS_CTRL_EXIT_LOAD_PERF_MSR RT_BIT(12)
1486/** Acknowledge external interrupts with the irq controller if one caused a VM-exit. */
1487#define VMX_VMCS_CTRL_EXIT_ACK_EXT_INT RT_BIT(15)
1488/** Whether the guest IA32_PAT MSR is saved on VM-exit. */
1489#define VMX_VMCS_CTRL_EXIT_SAVE_GUEST_PAT_MSR RT_BIT(18)
1490/** Whether the host IA32_PAT MSR is loaded on VM-exit. */
1491#define VMX_VMCS_CTRL_EXIT_LOAD_HOST_PAT_MSR RT_BIT(19)
1492/** Whether the guest IA32_EFER MSR is saved on VM-exit. */
1493#define VMX_VMCS_CTRL_EXIT_SAVE_GUEST_EFER_MSR RT_BIT(20)
1494/** Whether the host IA32_EFER MSR is loaded on VM-exit. */
1495#define VMX_VMCS_CTRL_EXIT_LOAD_HOST_EFER_MSR RT_BIT(21)
1496/** Whether the value of the VMX preemption timer is saved on every VM-exit. */
1497#define VMX_VMCS_CTRL_EXIT_SAVE_VMX_PREEMPT_TIMER RT_BIT(22)
1498/** @} */
1499
1500
1501/** @name VMX_VMCS_CTRL_VMFUNC
1502 * @{
1503 */
1504/** EPTP-switching function changes the value of the EPTP to one chosen from the EPTP list. */
1505#define VMX_VMCS_CTRL_VMFUNC_EPTP_SWITCHING RT_BIT_64(0)
1506/** @} */
1507
1508
1509/** @name VMCS field encoding: 32-bits read-only fields.
1510 * @{
1511 */
1512#define VMX_VMCS32_RO_VM_INSTR_ERROR 0x4400
1513#define VMX_VMCS32_RO_EXIT_REASON 0x4402
1514#define VMX_VMCS32_RO_EXIT_INTERRUPTION_INFO 0x4404
1515#define VMX_VMCS32_RO_EXIT_INTERRUPTION_ERROR_CODE 0x4406
1516#define VMX_VMCS32_RO_IDT_VECTORING_INFO 0x4408
1517#define VMX_VMCS32_RO_IDT_VECTORING_ERROR_CODE 0x440a
1518#define VMX_VMCS32_RO_EXIT_INSTR_LENGTH 0x440c
1519#define VMX_VMCS32_RO_EXIT_INSTR_INFO 0x440e
1520/** @} */
1521
1522
1523/** @name VMX_VMCS32_RO_EXIT_REASON
1524 * @{
1525 */
1526#define VMX_EXIT_REASON_BASIC(a) ((a) & 0xffff)
1527/** @} */
1528
1529
1530/** @name VMX_VMCS32_CTRL_ENTRY_INTERRUPTION_INFO
1531 * @{
1532 */
1533#define VMX_ENTRY_INTERRUPTION_INFO_IS_VALID(a) (((a) >> 31) & 1)
1534#define VMX_ENTRY_INTERRUPTION_INFO_TYPE_SHIFT 8
1535#define VMX_ENTRY_INTERRUPTION_INFO_TYPE(a) ((a >> VMX_ENTRY_INTERRUPTION_INFO_TYPE_SHIFT) & 7)
1536/** @} */
1537
1538
1539/** @name VMX_VMCS32_RO_EXIT_INTERRUPTION_INFO
1540 * @{
1541 */
1542#define VMX_EXIT_INTERRUPTION_INFO_VECTOR(a) ((a) & 0xff)
1543#define VMX_EXIT_INTERRUPTION_INFO_TYPE_SHIFT 8
1544#define VMX_EXIT_INTERRUPTION_INFO_TYPE(a) (((a) >> VMX_EXIT_INTERRUPTION_INFO_TYPE_SHIFT) & 7)
1545#define VMX_EXIT_INTERRUPTION_INFO_ERROR_CODE_VALID RT_BIT(11)
1546#define VMX_EXIT_INTERRUPTION_INFO_IS_ERROR_CODE_VALID(a) RT_BOOL((a) & VMX_EXIT_INTERRUPTION_INFO_ERROR_CODE_VALID)
1547#define VMX_EXIT_INTERRUPTION_INFO_IS_NMI_UNBLOCK_IRET(a) (((a) >> 12) & 1)
1548#define VMX_EXIT_INTERRUPTION_INFO_VALID RT_BIT(31)
1549#define VMX_EXIT_INTERRUPTION_INFO_IS_VALID(a) (((a) >> 31) & 1)
1550/** Construct an irq event injection value from the exit interruption info value
1551 * (same except that bit 12 is reserved). */
1552#define VMX_VMCS_CTRL_ENTRY_IRQ_INFO_FROM_EXIT_INT_INFO(a) ((a) & ~RT_BIT(12))
1553/** @} */
1554
1555
1556/** @name VMX_VMCS_RO_EXIT_INTERRUPTION_INFO_TYPE
1557 * @{
1558 */
1559#define VMX_EXIT_INTERRUPTION_INFO_TYPE_EXT_INT 0
1560#define VMX_EXIT_INTERRUPTION_INFO_TYPE_NMI 2
1561#define VMX_EXIT_INTERRUPTION_INFO_TYPE_HW_XCPT 3
1562#define VMX_EXIT_INTERRUPTION_INFO_TYPE_SW_INT 4
1563#define VMX_EXIT_INTERRUPTION_INFO_TYPE_PRIV_SW_XCPT 5
1564#define VMX_EXIT_INTERRUPTION_INFO_TYPE_SW_XCPT 6
1565/** @} */
1566
1567
1568/** @name VMX_VMCS32_RO_IDT_VECTORING_INFO
1569 * @{
1570 */
1571#define VMX_IDT_VECTORING_INFO_VECTOR(a) ((a) & 0xff)
1572#define VMX_IDT_VECTORING_INFO_TYPE_SHIFT 8
1573#define VMX_IDT_VECTORING_INFO_TYPE(a) (((a) >> VMX_IDT_VECTORING_INFO_TYPE_SHIFT) & 7)
1574#define VMX_IDT_VECTORING_INFO_ERROR_CODE_VALID RT_BIT(11)
1575#define VMX_IDT_VECTORING_INFO_IS_ERROR_CODE_VALID(a) (((a) >> 11) & 1)
1576#define VMX_IDT_VECTORING_INFO_VALID(a) ((a) & RT_BIT(31))
1577#define VMX_ENTRY_INT_INFO_FROM_EXIT_IDT_INFO(a) ((a) & ~RT_BIT(12))
1578/** @} */
1579
1580
1581/** @name VMX_VMCS_RO_IDT_VECTORING_INFO_TYPE
1582 * @{
1583 */
1584#define VMX_IDT_VECTORING_INFO_TYPE_EXT_INT 0
1585#define VMX_IDT_VECTORING_INFO_TYPE_NMI 2
1586#define VMX_IDT_VECTORING_INFO_TYPE_HW_XCPT 3
1587#define VMX_IDT_VECTORING_INFO_TYPE_SW_INT 4
1588#define VMX_IDT_VECTORING_INFO_TYPE_PRIV_SW_XCPT 5
1589#define VMX_IDT_VECTORING_INFO_TYPE_SW_XCPT 6
1590/** @} */
1591
1592
1593/** @name VMCS field encoding: 32-bit guest-state fields.
1594 * @{
1595 */
1596#define VMX_VMCS32_GUEST_ES_LIMIT 0x4800
1597#define VMX_VMCS32_GUEST_CS_LIMIT 0x4802
1598#define VMX_VMCS32_GUEST_SS_LIMIT 0x4804
1599#define VMX_VMCS32_GUEST_DS_LIMIT 0x4806
1600#define VMX_VMCS32_GUEST_FS_LIMIT 0x4808
1601#define VMX_VMCS32_GUEST_GS_LIMIT 0x480a
1602#define VMX_VMCS32_GUEST_LDTR_LIMIT 0x480c
1603#define VMX_VMCS32_GUEST_TR_LIMIT 0x480e
1604#define VMX_VMCS32_GUEST_GDTR_LIMIT 0x4810
1605#define VMX_VMCS32_GUEST_IDTR_LIMIT 0x4812
1606#define VMX_VMCS32_GUEST_ES_ACCESS_RIGHTS 0x4814
1607#define VMX_VMCS32_GUEST_CS_ACCESS_RIGHTS 0x4816
1608#define VMX_VMCS32_GUEST_SS_ACCESS_RIGHTS 0x4818
1609#define VMX_VMCS32_GUEST_DS_ACCESS_RIGHTS 0x481a
1610#define VMX_VMCS32_GUEST_FS_ACCESS_RIGHTS 0x481c
1611#define VMX_VMCS32_GUEST_GS_ACCESS_RIGHTS 0x481e
1612#define VMX_VMCS32_GUEST_LDTR_ACCESS_RIGHTS 0x4820
1613#define VMX_VMCS32_GUEST_TR_ACCESS_RIGHTS 0x4822
1614#define VMX_VMCS32_GUEST_INTERRUPTIBILITY_STATE 0x4824
1615#define VMX_VMCS32_GUEST_ACTIVITY_STATE 0x4826
1616#define VMX_VMCS32_GUEST_SYSENTER_CS 0x482a /**< MSR IA32_SYSENTER_CS */
1617#define VMX_VMCS32_GUEST_PREEMPT_TIMER_VALUE 0x482e
1618/** @} */
1619
1620
1621/** @name VMX_VMCS_GUEST_ACTIVITY_STATE
1622 * @{
1623 */
1624/** The logical processor is active. */
1625#define VMX_VMCS_GUEST_ACTIVITY_ACTIVE 0x0
1626/** The logical processor is inactive, because executed a HLT instruction. */
1627#define VMX_VMCS_GUEST_ACTIVITY_HLT 0x1
1628/** The logical processor is inactive, because of a triple fault or other serious error. */
1629#define VMX_VMCS_GUEST_ACTIVITY_SHUTDOWN 0x2
1630/** The logical processor is inactive, because it's waiting for a startup-IPI */
1631#define VMX_VMCS_GUEST_ACTIVITY_SIPI_WAIT 0x3
1632/** @} */
1633
1634
1635/** @name VMX_VMCS_GUEST_INTERRUPTIBILITY_STATE
1636 * @{
1637 */
1638#define VMX_VMCS_GUEST_INTERRUPTIBILITY_STATE_BLOCK_STI RT_BIT(0)
1639#define VMX_VMCS_GUEST_INTERRUPTIBILITY_STATE_BLOCK_MOVSS RT_BIT(1)
1640#define VMX_VMCS_GUEST_INTERRUPTIBILITY_STATE_BLOCK_SMI RT_BIT(2)
1641#define VMX_VMCS_GUEST_INTERRUPTIBILITY_STATE_BLOCK_NMI RT_BIT(3)
1642/** @} */
1643
1644
1645/** @name VMCS field encoding: 32-bit host-state fields.
1646 * @{
1647 */
1648#define VMX_VMCS32_HOST_SYSENTER_CS 0x4C00
1649/** @} */
1650
1651
1652/** @name Natural width control fields
1653 * @{
1654 */
1655#define VMX_VMCS_CTRL_CR0_MASK 0x6000
1656#define VMX_VMCS_CTRL_CR4_MASK 0x6002
1657#define VMX_VMCS_CTRL_CR0_READ_SHADOW 0x6004
1658#define VMX_VMCS_CTRL_CR4_READ_SHADOW 0x6006
1659#define VMX_VMCS_CTRL_CR3_TARGET_VAL0 0x6008
1660#define VMX_VMCS_CTRL_CR3_TARGET_VAL1 0x600a
1661#define VMX_VMCS_CTRL_CR3_TARGET_VAL2 0x600c
1662#define VMX_VMCS_CTRL_CR3_TARGET_VAL31 0x600e
1663/** @} */
1664
1665
1666/** @name Natural width read-only data fields
1667 * @{
1668 */
1669#define VMX_VMCS_RO_EXIT_QUALIFICATION 0x6400
1670#define VMX_VMCS_RO_IO_RCX 0x6402
1671#define VMX_VMCS_RO_IO_RSX 0x6404
1672#define VMX_VMCS_RO_IO_RDI 0x6406
1673#define VMX_VMCS_RO_IO_RIP 0x6408
1674#define VMX_VMCS_RO_EXIT_GUEST_LINEAR_ADDR 0x640a
1675/** @} */
1676
1677
1678/** @name VMX_VMCS_RO_EXIT_QUALIFICATION
1679 * @{
1680 */
1681/** 0-2: Debug register number */
1682#define VMX_EXIT_QUAL_DRX_REGISTER(a) ((a) & 7)
1683/** 3: Reserved; cleared to 0. */
1684#define VMX_EXIT_QUAL_DRX_RES1(a) (((a) >> 3) & 1)
1685/** 4: Direction of move (0 = write, 1 = read) */
1686#define VMX_EXIT_QUAL_DRX_DIRECTION(a) (((a) >> 4) & 1)
1687/** 5-7: Reserved; cleared to 0. */
1688#define VMX_EXIT_QUAL_DRX_RES2(a) (((a) >> 5) & 7)
1689/** 8-11: General purpose register number. */
1690#define VMX_EXIT_QUAL_DRX_GENREG(a) (((a) >> 8) & 0xf)
1691/** Rest: reserved. */
1692/** @} */
1693
1694
1695/** @name VMX_EXIT_QUAL_DRX_DIRECTION values
1696 * @{
1697 */
1698#define VMX_EXIT_QUAL_DRX_DIRECTION_WRITE 0
1699#define VMX_EXIT_QUAL_DRX_DIRECTION_READ 1
1700/** @} */
1701
1702
1703/** @name CRx accesses
1704 * @{
1705 */
1706/** 0-3: Control register number (0 for CLTS & LMSW) */
1707#define VMX_EXIT_QUAL_CRX_REGISTER(a) ((a) & 0xf)
1708/** 4-5: Access type. */
1709#define VMX_EXIT_QUAL_CRX_ACCESS(a) (((a) >> 4) & 3)
1710/** 6: LMSW operand type */
1711#define VMX_EXIT_QUAL_CRX_LMSW_OP(a) (((a) >> 6) & 1)
1712/** 7: Reserved; cleared to 0. */
1713#define VMX_EXIT_QUAL_CRX_RES1(a) (((a) >> 7) & 1)
1714/** 8-11: General purpose register number (0 for CLTS & LMSW). */
1715#define VMX_EXIT_QUAL_CRX_GENREG(a) (((a) >> 8) & 0xf)
1716/** 12-15: Reserved; cleared to 0. */
1717#define VMX_EXIT_QUAL_CRX_RES2(a) (((a) >> 12) & 0xf)
1718/** 16-31: LMSW source data (else 0). */
1719#define VMX_EXIT_QUAL_CRX_LMSW_DATA(a) (((a) >> 16) & 0xffff)
1720/* Rest: reserved. */
1721/** @} */
1722
1723
1724/** @name VMX_EXIT_QUAL_CRX_ACCESS
1725 * @{
1726 */
1727#define VMX_EXIT_QUAL_CRX_ACCESS_WRITE 0
1728#define VMX_EXIT_QUAL_CRX_ACCESS_READ 1
1729#define VMX_EXIT_QUAL_CRX_ACCESS_CLTS 2
1730#define VMX_EXIT_QUAL_CRX_ACCESS_LMSW 3
1731/** @} */
1732
1733
1734/** @name VMX_EXIT_QUAL_TASK_SWITCH
1735 * @{
1736 */
1737#define VMX_EXIT_QUAL_TASK_SWITCH_SELECTOR(a) ((a) & 0xffff)
1738#define VMX_EXIT_QUAL_TASK_SWITCH_TYPE(a) (((a) >> 30) & 0x3)
1739/** Task switch caused by a call instruction. */
1740#define VMX_EXIT_QUAL_TASK_SWITCH_TYPE_CALL 0
1741/** Task switch caused by an iret instruction. */
1742#define VMX_EXIT_QUAL_TASK_SWITCH_TYPE_IRET 1
1743/** Task switch caused by a jmp instruction. */
1744#define VMX_EXIT_QUAL_TASK_SWITCH_TYPE_JMP 2
1745/** Task switch caused by an interrupt gate. */
1746#define VMX_EXIT_QUAL_TASK_SWITCH_TYPE_IDT 3
1747/** @} */
1748
1749
1750/** @name VMX_EXIT_EPT_VIOLATION
1751 * @{
1752 */
1753/** Set if the violation was caused by a data read. */
1754#define VMX_EXIT_QUAL_EPT_DATA_READ RT_BIT(0)
1755/** Set if the violation was caused by a data write. */
1756#define VMX_EXIT_QUAL_EPT_DATA_WRITE RT_BIT(1)
1757/** Set if the violation was caused by an instruction fetch. */
1758#define VMX_EXIT_QUAL_EPT_INSTR_FETCH RT_BIT(2)
1759/** AND of the present bit of all EPT structures. */
1760#define VMX_EXIT_QUAL_EPT_ENTRY_PRESENT RT_BIT(3)
1761/** AND of the write bit of all EPT structures. */
1762#define VMX_EXIT_QUAL_EPT_ENTRY_WRITE RT_BIT(4)
1763/** AND of the execute bit of all EPT structures. */
1764#define VMX_EXIT_QUAL_EPT_ENTRY_EXECUTE RT_BIT(5)
1765/** Set if the guest linear address field contains the faulting address. */
1766#define VMX_EXIT_QUAL_EPT_GUEST_ADDR_VALID RT_BIT(7)
1767/** If bit 7 is one: (reserved otherwise)
1768 * 1 - violation due to physical address access.
1769 * 0 - violation caused by page walk or access/dirty bit updates
1770 */
1771#define VMX_EXIT_QUAL_EPT_TRANSLATED_ACCESS RT_BIT(8)
1772/** @} */
1773
1774
1775/** @name VMX_EXIT_PORT_IO
1776 * @{
1777 */
1778/** 0-2: IO operation width. */
1779#define VMX_EXIT_QUAL_IO_WIDTH(a) ((a) & 7)
1780/** 3: IO operation direction. */
1781#define VMX_EXIT_QUAL_IO_DIRECTION(a) (((a) >> 3) & 1)
1782/** 4: String IO operation (INS / OUTS). */
1783#define VMX_EXIT_QUAL_IO_IS_STRING(a) RT_BOOL((a) & RT_BIT_64(4))
1784/** 5: Repeated IO operation. */
1785#define VMX_EXIT_QUAL_IO_IS_REP(a) RT_BOOL((a) & RT_BIT_64(5))
1786/** 6: Operand encoding. */
1787#define VMX_EXIT_QUAL_IO_ENCODING(a) (((a) >> 6) & 1)
1788/** 16-31: IO Port (0-0xffff). */
1789#define VMX_EXIT_QUAL_IO_PORT(a) (((a) >> 16) & 0xffff)
1790/* Rest reserved. */
1791/** @} */
1792
1793
1794/** @name VMX_EXIT_QUAL_IO_DIRECTION
1795 * @{
1796 */
1797#define VMX_EXIT_QUAL_IO_DIRECTION_OUT 0
1798#define VMX_EXIT_QUAL_IO_DIRECTION_IN 1
1799/** @} */
1800
1801
1802/** @name VMX_EXIT_QUAL_IO_ENCODING
1803 * @{
1804 */
1805#define VMX_EXIT_QUAL_IO_ENCODING_DX 0
1806#define VMX_EXIT_QUAL_IO_ENCODING_IMM 1
1807/** @} */
1808
1809
1810/** @name VMX_EXIT_APIC_ACCESS
1811 * @{
1812 */
1813/** 0-11: If the APIC-access VM-exit is due to a linear access, the offset of
1814 * access within the APIC page. */
1815#define VMX_EXIT_QUAL_APIC_ACCESS_OFFSET(a) ((a) & 0xfff)
1816/** 12-15: Access type. */
1817#define VMX_EXIT_QUAL_APIC_ACCESS_TYPE(a) (((a) & 0xf000) >> 12)
1818/* Rest reserved. */
1819/** @} */
1820
1821
1822/** @name VMX_EXIT_QUAL_APIC_ACCESS_TYPE return values
1823 * @{
1824 */
1825/** Linear read access. */
1826#define VMX_APIC_ACCESS_TYPE_LINEAR_READ 0
1827/** Linear write access. */
1828#define VMX_APIC_ACCESS_TYPE_LINEAR_WRITE 1
1829/** Linear instruction fetch access. */
1830#define VMX_APIC_ACCESS_TYPE_LINEAR_INSTR_FETCH 2
1831/** Linear read/write access during event delivery. */
1832#define VMX_APIC_ACCESS_TYPE_LINEAR_EVENT_DELIVERY 3
1833/** Physical read/write access during event delivery. */
1834#define VMX_APIC_ACCESS_TYPE_PHYSICAL_EVENT_DELIVERY 10
1835/** Physical access for an instruction fetch or during instruction execution. */
1836#define VMX_APIC_ACCESS_TYPE_PHYSICAL_INSTR 15
1837/** @} */
1838
1839
1840/** @name VMX_XDTR_INSINFO_XXX - VMX_EXIT_XDTR_ACCESS instruction information
1841 * Found in VMX_VMCS32_RO_EXIT_INSTR_INFO.
1842 * @{
1843 */
1844/** Address calculation scaling field (powers of two). */
1845#define VMX_XDTR_INSINFO_SCALE_SHIFT 0
1846#define VMX_XDTR_INSINFO_SCALE_MASK UINT32_C(0x00000003)
1847/** Bits 2 thru 6 are undefined. */
1848#define VMX_XDTR_INSINFO_UNDEF_2_6_SHIFT 2
1849#define VMX_XDTR_INSINFO_UNDEF_2_6_MASK UINT32_C(0x0000007c)
1850/** Address size, only 0(=16), 1(=32) and 2(=64) are defined.
1851 * @remarks anyone's guess why this is a 3 bit field... */
1852#define VMX_XDTR_INSINFO_ADDR_SIZE_SHIFT 7
1853#define VMX_XDTR_INSINFO_ADDR_SIZE_MASK UINT32_C(0x00000380)
1854/** Bit 10 is defined as zero. */
1855#define VMX_XDTR_INSINFO_ZERO_10_SHIFT 10
1856#define VMX_XDTR_INSINFO_ZERO_10_MASK UINT32_C(0x00000400)
1857/** Operand size, either (1=)32-bit or (0=)16-bit, but get this, it's undefined
1858 * for exits from 64-bit code as the operand size there is fixed. */
1859#define VMX_XDTR_INSINFO_OP_SIZE_SHIFT 11
1860#define VMX_XDTR_INSINFO_OP_SIZE_MASK UINT32_C(0x00000800)
1861/** Bits 12 thru 14 are undefined. */
1862#define VMX_XDTR_INSINFO_UNDEF_12_14_SHIFT 12
1863#define VMX_XDTR_INSINFO_UNDEF_12_14_MASK UINT32_C(0x00007000)
1864/** Applicable segment register (X86_SREG_XXX values). */
1865#define VMX_XDTR_INSINFO_SREG_SHIFT 15
1866#define VMX_XDTR_INSINFO_SREG_MASK UINT32_C(0x00038000)
1867/** Index register (X86_GREG_XXX values). Undefined if HAS_INDEX_REG is clear. */
1868#define VMX_XDTR_INSINFO_INDEX_REG_SHIFT 18
1869#define VMX_XDTR_INSINFO_INDEX_REG_MASK UINT32_C(0x003c0000)
1870/** Is VMX_XDTR_INSINFO_INDEX_REG_XXX valid (=1) or not (=0). */
1871#define VMX_XDTR_INSINFO_HAS_INDEX_REG_SHIFT 22
1872#define VMX_XDTR_INSINFO_HAS_INDEX_REG_MASK UINT32_C(0x00400000)
1873/** Base register (X86_GREG_XXX values). Undefined if HAS_BASE_REG is clear. */
1874#define VMX_XDTR_INSINFO_BASE_REG_SHIFT 23
1875#define VMX_XDTR_INSINFO_BASE_REG_MASK UINT32_C(0x07800000)
1876/** Is VMX_XDTR_INSINFO_BASE_REG_XXX valid (=1) or not (=0). */
1877#define VMX_XDTR_INSINFO_HAS_BASE_REG_SHIFT 27
1878#define VMX_XDTR_INSINFO_HAS_BASE_REG_MASK UINT32_C(0x08000000)
1879/** The instruction identity (VMX_XDTR_INSINFO_II_XXX values) */
1880#define VMX_XDTR_INSINFO_INSTR_ID_SHIFT 28
1881#define VMX_XDTR_INSINFO_INSTR_ID_MASK UINT32_C(0x30000000)
1882#define VMX_XDTR_INSINFO_II_SGDT 0 /**< Instruction ID: SGDT */
1883#define VMX_XDTR_INSINFO_II_SIDT 1 /**< Instruction ID: SIDT */
1884#define VMX_XDTR_INSINFO_II_LGDT 2 /**< Instruction ID: LGDT */
1885#define VMX_XDTR_INSINFO_II_LIDT 3 /**< Instruction ID: LIDT */
1886/** Bits 30 & 31 are undefined. */
1887#define VMX_XDTR_INSINFO_UNDEF_30_31_SHIFT 30
1888#define VMX_XDTR_INSINFO_UNDEF_30_31_MASK UINT32_C(0xc0000000)
1889RT_BF_ASSERT_COMPILE_CHECKS(VMX_XDTR_INSINFO_, UINT32_C(0), UINT32_MAX,
1890 (SCALE, UNDEF_2_6, ADDR_SIZE, ZERO_10, OP_SIZE, UNDEF_12_14, SREG, INDEX_REG, HAS_INDEX_REG,
1891 BASE_REG, HAS_BASE_REG, INSTR_ID, UNDEF_30_31));
1892/** @} */
1893
1894
1895/** @name VMX_YYTR_INSINFO_XXX - VMX_EXIT_TR_ACCESS instruction information
1896 * Found in VMX_VMCS32_RO_EXIT_INSTR_INFO.
1897 * This is similar to VMX_XDTR_INSINFO_XXX.
1898 * @{
1899 */
1900/** Address calculation scaling field (powers of two). */
1901#define VMX_YYTR_INSINFO_SCALE_SHIFT 0
1902#define VMX_YYTR_INSINFO_SCALE_MASK UINT32_C(0x00000003)
1903/** Bit 2 is undefined. */
1904#define VMX_YYTR_INSINFO_UNDEF_2_SHIFT 2
1905#define VMX_YYTR_INSINFO_UNDEF_2_MASK UINT32_C(0x00000004)
1906/** Register operand 1. Undefined if VMX_YYTR_INSINFO_HAS_REG1 is clear. */
1907#define VMX_YYTR_INSINFO_REG1_SHIFT 3
1908#define VMX_YYTR_INSINFO_REG1_MASK UINT32_C(0x00000078)
1909/** Address size, only 0(=16), 1(=32) and 2(=64) are defined.
1910 * @remarks anyone's guess why this is a 3 bit field... */
1911#define VMX_YYTR_INSINFO_ADDR_SIZE_SHIFT 7
1912#define VMX_YYTR_INSINFO_ADDR_SIZE_MASK UINT32_C(0x00000380)
1913/** Is VMX_YYTR_INSINFO_REG1_XXX valid (=1) or not (=0). */
1914#define VMX_YYTR_INSINFO_HAS_REG1_SHIFT 10
1915#define VMX_YYTR_INSINFO_HAS_REG1_MASK UINT32_C(0x00000400)
1916/** Bits 11 thru 14 are undefined. */
1917#define VMX_YYTR_INSINFO_UNDEF_11_14_SHIFT 11
1918#define VMX_YYTR_INSINFO_UNDEF_11_14_MASK UINT32_C(0x00007800)
1919/** Applicable segment register (X86_SREG_XXX values). */
1920#define VMX_YYTR_INSINFO_SREG_SHIFT 15
1921#define VMX_YYTR_INSINFO_SREG_MASK UINT32_C(0x00038000)
1922/** Index register (X86_GREG_XXX values). Undefined if HAS_INDEX_REG is clear. */
1923#define VMX_YYTR_INSINFO_INDEX_REG_SHIFT 18
1924#define VMX_YYTR_INSINFO_INDEX_REG_MASK UINT32_C(0x003c0000)
1925/** Is VMX_YYTR_INSINFO_INDEX_REG_XXX valid (=1) or not (=0). */
1926#define VMX_YYTR_INSINFO_HAS_INDEX_REG_SHIFT 22
1927#define VMX_YYTR_INSINFO_HAS_INDEX_REG_MASK UINT32_C(0x00400000)
1928/** Base register (X86_GREG_XXX values). Undefined if HAS_BASE_REG is clear. */
1929#define VMX_YYTR_INSINFO_BASE_REG_SHIFT 23
1930#define VMX_YYTR_INSINFO_BASE_REG_MASK UINT32_C(0x07800000)
1931/** Is VMX_YYTR_INSINFO_BASE_REG_XXX valid (=1) or not (=0). */
1932#define VMX_YYTR_INSINFO_HAS_BASE_REG_SHIFT 27
1933#define VMX_YYTR_INSINFO_HAS_BASE_REG_MASK UINT32_C(0x08000000)
1934/** The instruction identity (VMX_YYTR_INSINFO_II_XXX values) */
1935#define VMX_YYTR_INSINFO_INSTR_ID_SHIFT 28
1936#define VMX_YYTR_INSINFO_INSTR_ID_MASK UINT32_C(0x30000000)
1937#define VMX_YYTR_INSINFO_II_SLDT 0 /**< Instruction ID: SLDT */
1938#define VMX_YYTR_INSINFO_II_STR 1 /**< Instruction ID: STR */
1939#define VMX_YYTR_INSINFO_II_LLDT 2 /**< Instruction ID: LLDT */
1940#define VMX_YYTR_INSINFO_II_LTR 3 /**< Instruction ID: LTR */
1941/** Bits 30 & 31 are undefined. */
1942#define VMX_YYTR_INSINFO_UNDEF_30_31_SHIFT 30
1943#define VMX_YYTR_INSINFO_UNDEF_30_31_MASK UINT32_C(0xc0000000)
1944RT_BF_ASSERT_COMPILE_CHECKS(VMX_YYTR_INSINFO_, UINT32_C(0), UINT32_MAX,
1945 (SCALE, UNDEF_2, REG1, ADDR_SIZE, HAS_REG1, UNDEF_11_14, SREG, INDEX_REG, HAS_INDEX_REG,
1946 BASE_REG, HAS_BASE_REG, INSTR_ID, UNDEF_30_31));
1947/** @} */
1948
1949
1950/** @name VMCS field encoding: Natural width guest-state fields.
1951 * @{
1952 */
1953#define VMX_VMCS_GUEST_CR0 0x6800
1954#define VMX_VMCS_GUEST_CR3 0x6802
1955#define VMX_VMCS_GUEST_CR4 0x6804
1956#define VMX_VMCS_GUEST_ES_BASE 0x6806
1957#define VMX_VMCS_GUEST_CS_BASE 0x6808
1958#define VMX_VMCS_GUEST_SS_BASE 0x680a
1959#define VMX_VMCS_GUEST_DS_BASE 0x680c
1960#define VMX_VMCS_GUEST_FS_BASE 0x680e
1961#define VMX_VMCS_GUEST_GS_BASE 0x6810
1962#define VMX_VMCS_GUEST_LDTR_BASE 0x6812
1963#define VMX_VMCS_GUEST_TR_BASE 0x6814
1964#define VMX_VMCS_GUEST_GDTR_BASE 0x6816
1965#define VMX_VMCS_GUEST_IDTR_BASE 0x6818
1966#define VMX_VMCS_GUEST_DR7 0x681a
1967#define VMX_VMCS_GUEST_RSP 0x681c
1968#define VMX_VMCS_GUEST_RIP 0x681e
1969#define VMX_VMCS_GUEST_RFLAGS 0x6820
1970#define VMX_VMCS_GUEST_PENDING_DEBUG_EXCEPTIONS 0x6822
1971#define VMX_VMCS_GUEST_SYSENTER_ESP 0x6824 /**< MSR IA32_SYSENTER_ESP */
1972#define VMX_VMCS_GUEST_SYSENTER_EIP 0x6826 /**< MSR IA32_SYSENTER_EIP */
1973/** @} */
1974
1975
1976/** @name VMX_VMCS_GUEST_DEBUG_EXCEPTIONS
1977 * Bits 4-11, 13 and 15-63 are reserved.
1978 * @{
1979 */
1980/** Hardware breakpoint 0 was met. */
1981#define VMX_VMCS_GUEST_DEBUG_EXCEPTIONS_B0 RT_BIT(0)
1982/** Hardware breakpoint 1 was met. */
1983#define VMX_VMCS_GUEST_DEBUG_EXCEPTIONS_B1 RT_BIT(1)
1984/** Hardware breakpoint 2 was met. */
1985#define VMX_VMCS_GUEST_DEBUG_EXCEPTIONS_B2 RT_BIT(2)
1986/** Hardware breakpoint 3 was met. */
1987#define VMX_VMCS_GUEST_DEBUG_EXCEPTIONS_B3 RT_BIT(3)
1988/** At least one data or IO breakpoint was hit. */
1989#define VMX_VMCS_GUEST_DEBUG_EXCEPTIONS_BREAKPOINT_ENABLED RT_BIT(12)
1990/** A debug exception would have been triggered by single-step execution mode. */
1991#define VMX_VMCS_GUEST_DEBUG_EXCEPTIONS_BS RT_BIT(14)
1992/** @} */
1993
1994
1995/** @name VMCS field encoding: Natural width host-state fields.
1996 * @{
1997 */
1998#define VMX_VMCS_HOST_CR0 0x6c00
1999#define VMX_VMCS_HOST_CR3 0x6c02
2000#define VMX_VMCS_HOST_CR4 0x6c04
2001#define VMX_VMCS_HOST_FS_BASE 0x6c06
2002#define VMX_VMCS_HOST_GS_BASE 0x6c08
2003#define VMX_VMCS_HOST_TR_BASE 0x6c0a
2004#define VMX_VMCS_HOST_GDTR_BASE 0x6c0c
2005#define VMX_VMCS_HOST_IDTR_BASE 0x6c0e
2006#define VMX_VMCS_HOST_SYSENTER_ESP 0x6c10
2007#define VMX_VMCS_HOST_SYSENTER_EIP 0x6c12
2008#define VMX_VMCS_HOST_RSP 0x6c14
2009#define VMX_VMCS_HOST_RIP 0x6c16
2010/** @} */
2011
2012
2013/** VMCS revision identifier used for emulating VMX (bit 31 MBZ). Bump this
2014 * arbitarily chosen identifier if incompatible changes to the layout of our VMCS
2015 * structure is done. */
2016#define VMX_VMCS_REVISION_ID UINT32_C(0x1d000001)
2017AssertCompile(!(VMX_VMCS_REVISION_ID & RT_BIT(31)));
2018/** VMCS (and related regions) memory type - Uncacheable. */
2019#define VMX_VMCS_MEM_TYPE_UC 0
2020/** VMCS (and related regions) memory type - Write back. */
2021#define VMX_VMCS_MEM_TYPE_WB 6
2022
2023
2024/** @defgroup grp_hm_vmx_asm VMX Assembly Helpers
2025 * @{
2026 */
2027
2028/**
2029 * Restores some host-state fields that need not be done on every VM-exit.
2030 *
2031 * @returns VBox status code.
2032 * @param fRestoreHostFlags Flags of which host registers needs to be
2033 * restored.
2034 * @param pRestoreHost Pointer to the host-restore structure.
2035 */
2036DECLASM(int) VMXRestoreHostState(uint32_t fRestoreHostFlags, PVMXRESTOREHOST pRestoreHost);
2037
2038
2039/**
2040 * Dispatches an NMI to the host.
2041 */
2042DECLASM(int) VMXDispatchHostNmi(void);
2043
2044
2045/**
2046 * Executes VMXON.
2047 *
2048 * @returns VBox status code.
2049 * @param HCPhysVmxOn Physical address of VMXON structure.
2050 */
2051#if ((RT_INLINE_ASM_EXTERNAL || !defined(RT_ARCH_X86)) && !VMX_USE_MSC_INTRINSICS)
2052DECLASM(int) VMXEnable(RTHCPHYS HCPhysVmxOn);
2053#else
2054DECLINLINE(int) VMXEnable(RTHCPHYS HCPhysVmxOn)
2055{
2056# if RT_INLINE_ASM_GNU_STYLE
2057 int rc = VINF_SUCCESS;
2058 __asm__ __volatile__ (
2059 "push %3 \n\t"
2060 "push %2 \n\t"
2061 ".byte 0xf3, 0x0f, 0xc7, 0x34, 0x24 # VMXON [esp] \n\t"
2062 "ja 2f \n\t"
2063 "je 1f \n\t"
2064 "movl $" RT_XSTR(VERR_VMX_INVALID_VMXON_PTR)", %0 \n\t"
2065 "jmp 2f \n\t"
2066 "1: \n\t"
2067 "movl $" RT_XSTR(VERR_VMX_VMXON_FAILED)", %0 \n\t"
2068 "2: \n\t"
2069 "add $8, %%esp \n\t"
2070 :"=rm"(rc)
2071 :"0"(VINF_SUCCESS),
2072 "ir"((uint32_t)HCPhysVmxOn), /* don't allow direct memory reference here, */
2073 "ir"((uint32_t)(HCPhysVmxOn >> 32)) /* this would not work with -fomit-frame-pointer */
2074 :"memory"
2075 );
2076 return rc;
2077
2078# elif VMX_USE_MSC_INTRINSICS
2079 unsigned char rcMsc = __vmx_on(&HCPhysVmxOn);
2080 if (RT_LIKELY(rcMsc == 0))
2081 return VINF_SUCCESS;
2082 return rcMsc == 2 ? VERR_VMX_INVALID_VMXON_PTR : VERR_VMX_VMXON_FAILED;
2083
2084# else
2085 int rc = VINF_SUCCESS;
2086 __asm
2087 {
2088 push dword ptr [HCPhysVmxOn + 4]
2089 push dword ptr [HCPhysVmxOn]
2090 _emit 0xf3
2091 _emit 0x0f
2092 _emit 0xc7
2093 _emit 0x34
2094 _emit 0x24 /* VMXON [esp] */
2095 jnc vmxon_good
2096 mov dword ptr [rc], VERR_VMX_INVALID_VMXON_PTR
2097 jmp the_end
2098
2099vmxon_good:
2100 jnz the_end
2101 mov dword ptr [rc], VERR_VMX_VMXON_FAILED
2102the_end:
2103 add esp, 8
2104 }
2105 return rc;
2106# endif
2107}
2108#endif
2109
2110
2111/**
2112 * Executes VMXOFF.
2113 */
2114#if ((RT_INLINE_ASM_EXTERNAL || !defined(RT_ARCH_X86)) && !VMX_USE_MSC_INTRINSICS)
2115DECLASM(void) VMXDisable(void);
2116#else
2117DECLINLINE(void) VMXDisable(void)
2118{
2119# if RT_INLINE_ASM_GNU_STYLE
2120 __asm__ __volatile__ (
2121 ".byte 0x0f, 0x01, 0xc4 # VMXOFF \n\t"
2122 );
2123
2124# elif VMX_USE_MSC_INTRINSICS
2125 __vmx_off();
2126
2127# else
2128 __asm
2129 {
2130 _emit 0x0f
2131 _emit 0x01
2132 _emit 0xc4 /* VMXOFF */
2133 }
2134# endif
2135}
2136#endif
2137
2138
2139/**
2140 * Executes VMCLEAR.
2141 *
2142 * @returns VBox status code.
2143 * @param HCPhysVmcs Physical address of VM control structure.
2144 */
2145#if ((RT_INLINE_ASM_EXTERNAL || !defined(RT_ARCH_X86)) && !VMX_USE_MSC_INTRINSICS)
2146DECLASM(int) VMXClearVmcs(RTHCPHYS HCPhysVmcs);
2147#else
2148DECLINLINE(int) VMXClearVmcs(RTHCPHYS HCPhysVmcs)
2149{
2150# if RT_INLINE_ASM_GNU_STYLE
2151 int rc = VINF_SUCCESS;
2152 __asm__ __volatile__ (
2153 "push %3 \n\t"
2154 "push %2 \n\t"
2155 ".byte 0x66, 0x0f, 0xc7, 0x34, 0x24 # VMCLEAR [esp] \n\t"
2156 "jnc 1f \n\t"
2157 "movl $" RT_XSTR(VERR_VMX_INVALID_VMCS_PTR)", %0 \n\t"
2158 "1: \n\t"
2159 "add $8, %%esp \n\t"
2160 :"=rm"(rc)
2161 :"0"(VINF_SUCCESS),
2162 "ir"((uint32_t)HCPhysVmcs), /* don't allow direct memory reference here, */
2163 "ir"((uint32_t)(HCPhysVmcs >> 32)) /* this would not work with -fomit-frame-pointer */
2164 :"memory"
2165 );
2166 return rc;
2167
2168# elif VMX_USE_MSC_INTRINSICS
2169 unsigned char rcMsc = __vmx_vmclear(&HCPhysVmcs);
2170 if (RT_LIKELY(rcMsc == 0))
2171 return VINF_SUCCESS;
2172 return VERR_VMX_INVALID_VMCS_PTR;
2173
2174# else
2175 int rc = VINF_SUCCESS;
2176 __asm
2177 {
2178 push dword ptr [HCPhysVmcs + 4]
2179 push dword ptr [HCPhysVmcs]
2180 _emit 0x66
2181 _emit 0x0f
2182 _emit 0xc7
2183 _emit 0x34
2184 _emit 0x24 /* VMCLEAR [esp] */
2185 jnc success
2186 mov dword ptr [rc], VERR_VMX_INVALID_VMCS_PTR
2187success:
2188 add esp, 8
2189 }
2190 return rc;
2191# endif
2192}
2193#endif
2194
2195
2196/**
2197 * Executes VMPTRLD.
2198 *
2199 * @returns VBox status code.
2200 * @param HCPhysVmcs Physical address of VMCS structure.
2201 */
2202#if ((RT_INLINE_ASM_EXTERNAL || !defined(RT_ARCH_X86)) && !VMX_USE_MSC_INTRINSICS)
2203DECLASM(int) VMXActivateVmcs(RTHCPHYS HCPhysVmcs);
2204#else
2205DECLINLINE(int) VMXActivateVmcs(RTHCPHYS HCPhysVmcs)
2206{
2207# if RT_INLINE_ASM_GNU_STYLE
2208 int rc = VINF_SUCCESS;
2209 __asm__ __volatile__ (
2210 "push %3 \n\t"
2211 "push %2 \n\t"
2212 ".byte 0x0f, 0xc7, 0x34, 0x24 # VMPTRLD [esp] \n\t"
2213 "jnc 1f \n\t"
2214 "movl $" RT_XSTR(VERR_VMX_INVALID_VMCS_PTR)", %0 \n\t"
2215 "1: \n\t"
2216 "add $8, %%esp \n\t"
2217 :"=rm"(rc)
2218 :"0"(VINF_SUCCESS),
2219 "ir"((uint32_t)HCPhysVmcs), /* don't allow direct memory reference here, */
2220 "ir"((uint32_t)(HCPhysVmcs >> 32)) /* this will not work with -fomit-frame-pointer */
2221 );
2222 return rc;
2223
2224# elif VMX_USE_MSC_INTRINSICS
2225 unsigned char rcMsc = __vmx_vmptrld(&HCPhysVmcs);
2226 if (RT_LIKELY(rcMsc == 0))
2227 return VINF_SUCCESS;
2228 return VERR_VMX_INVALID_VMCS_PTR;
2229
2230# else
2231 int rc = VINF_SUCCESS;
2232 __asm
2233 {
2234 push dword ptr [HCPhysVmcs + 4]
2235 push dword ptr [HCPhysVmcs]
2236 _emit 0x0f
2237 _emit 0xc7
2238 _emit 0x34
2239 _emit 0x24 /* VMPTRLD [esp] */
2240 jnc success
2241 mov dword ptr [rc], VERR_VMX_INVALID_VMCS_PTR
2242
2243success:
2244 add esp, 8
2245 }
2246 return rc;
2247# endif
2248}
2249#endif
2250
2251
2252/**
2253 * Executes VMPTRST.
2254 *
2255 * @returns VBox status code.
2256 * @param pHCPhysVmcs Where to store the physical address of the current
2257 * VMCS.
2258 */
2259DECLASM(int) VMXGetActivatedVmcs(RTHCPHYS *pHCPhysVmcs);
2260
2261
2262/**
2263 * Executes VMWRITE.
2264 *
2265 * @returns VBox status code.
2266 * @retval VINF_SUCCESS.
2267 * @retval VERR_VMX_INVALID_VMCS_PTR.
2268 * @retval VERR_VMX_INVALID_VMCS_FIELD.
2269 *
2270 * @param idxField VMCS index.
2271 * @param u32Val 32-bit value.
2272 *
2273 * @remarks The values of the two status codes can be OR'ed together, the result
2274 * will be VERR_VMX_INVALID_VMCS_PTR.
2275 */
2276#if ((RT_INLINE_ASM_EXTERNAL || !defined(RT_ARCH_X86)) && !VMX_USE_MSC_INTRINSICS)
2277DECLASM(int) VMXWriteVmcs32(uint32_t idxField, uint32_t u32Val);
2278#else
2279DECLINLINE(int) VMXWriteVmcs32(uint32_t idxField, uint32_t u32Val)
2280{
2281# if RT_INLINE_ASM_GNU_STYLE
2282 int rc = VINF_SUCCESS;
2283 __asm__ __volatile__ (
2284 ".byte 0x0f, 0x79, 0xc2 # VMWRITE eax, edx \n\t"
2285 "ja 2f \n\t"
2286 "je 1f \n\t"
2287 "movl $" RT_XSTR(VERR_VMX_INVALID_VMCS_PTR)", %0 \n\t"
2288 "jmp 2f \n\t"
2289 "1: \n\t"
2290 "movl $" RT_XSTR(VERR_VMX_INVALID_VMCS_FIELD)", %0 \n\t"
2291 "2: \n\t"
2292 :"=rm"(rc)
2293 :"0"(VINF_SUCCESS),
2294 "a"(idxField),
2295 "d"(u32Val)
2296 );
2297 return rc;
2298
2299# elif VMX_USE_MSC_INTRINSICS
2300 unsigned char rcMsc = __vmx_vmwrite(idxField, u32Val);
2301 if (RT_LIKELY(rcMsc == 0))
2302 return VINF_SUCCESS;
2303 return rcMsc == 2 ? VERR_VMX_INVALID_VMCS_PTR : VERR_VMX_INVALID_VMCS_FIELD;
2304
2305#else
2306 int rc = VINF_SUCCESS;
2307 __asm
2308 {
2309 push dword ptr [u32Val]
2310 mov eax, [idxField]
2311 _emit 0x0f
2312 _emit 0x79
2313 _emit 0x04
2314 _emit 0x24 /* VMWRITE eax, [esp] */
2315 jnc valid_vmcs
2316 mov dword ptr [rc], VERR_VMX_INVALID_VMCS_PTR
2317 jmp the_end
2318
2319valid_vmcs:
2320 jnz the_end
2321 mov dword ptr [rc], VERR_VMX_INVALID_VMCS_FIELD
2322the_end:
2323 add esp, 4
2324 }
2325 return rc;
2326# endif
2327}
2328#endif
2329
2330/**
2331 * Executes VMWRITE.
2332 *
2333 * @returns VBox status code.
2334 * @retval VINF_SUCCESS.
2335 * @retval VERR_VMX_INVALID_VMCS_PTR.
2336 * @retval VERR_VMX_INVALID_VMCS_FIELD.
2337 *
2338 * @param idxField VMCS index.
2339 * @param u64Val 16, 32 or 64-bit value.
2340 *
2341 * @remarks The values of the two status codes can be OR'ed together, the result
2342 * will be VERR_VMX_INVALID_VMCS_PTR.
2343 */
2344#if !defined(RT_ARCH_X86)
2345# if !VMX_USE_MSC_INTRINSICS || ARCH_BITS != 64
2346DECLASM(int) VMXWriteVmcs64(uint32_t idxField, uint64_t u64Val);
2347# else /* VMX_USE_MSC_INTRINSICS */
2348DECLINLINE(int) VMXWriteVmcs64(uint32_t idxField, uint64_t u64Val)
2349{
2350 unsigned char rcMsc = __vmx_vmwrite(idxField, u64Val);
2351 if (RT_LIKELY(rcMsc == 0))
2352 return VINF_SUCCESS;
2353 return rcMsc == 2 ? VERR_VMX_INVALID_VMCS_PTR : VERR_VMX_INVALID_VMCS_FIELD;
2354}
2355# endif /* VMX_USE_MSC_INTRINSICS */
2356#else
2357# define VMXWriteVmcs64(idxField, u64Val) VMXWriteVmcs64Ex(pVCpu, idxField, u64Val) /** @todo dead ugly, picking up pVCpu like this */
2358VMMR0DECL(int) VMXWriteVmcs64Ex(PVMCPU pVCpu, uint32_t idxField, uint64_t u64Val);
2359#endif
2360
2361#if ARCH_BITS == 32
2362# define VMXWriteVmcsHstN VMXWriteVmcs32
2363# define VMXWriteVmcsGstN(idxField, u64Val) VMXWriteVmcs64Ex(pVCpu, idxField, u64Val)
2364#else /* ARCH_BITS == 64 */
2365# define VMXWriteVmcsHstN VMXWriteVmcs64
2366# define VMXWriteVmcsGstN VMXWriteVmcs64
2367#endif
2368
2369
2370/**
2371 * Invalidate a page using INVEPT.
2372 *
2373 * @returns VBox status code.
2374 * @param enmFlush Type of flush.
2375 * @param pDescriptor Pointer to the descriptor.
2376 */
2377DECLASM(int) VMXR0InvEPT(VMXTLBFLUSHEPT enmFlush, uint64_t *pDescriptor);
2378
2379
2380/**
2381 * Invalidate a page using INVVPID.
2382 *
2383 * @returns VBox status code.
2384 * @param enmFlush Type of flush.
2385 * @param pDescriptor Pointer to the descriptor.
2386 */
2387DECLASM(int) VMXR0InvVPID(VMXTLBFLUSHVPID enmFlush, uint64_t *pDescriptor);
2388
2389
2390/**
2391 * Executes VMREAD.
2392 *
2393 * @returns VBox status code.
2394 * @retval VINF_SUCCESS.
2395 * @retval VERR_VMX_INVALID_VMCS_PTR.
2396 * @retval VERR_VMX_INVALID_VMCS_FIELD.
2397 *
2398 * @param idxField VMCS index.
2399 * @param pData Where to store VM field value.
2400 *
2401 * @remarks The values of the two status codes can be OR'ed together, the result
2402 * will be VERR_VMX_INVALID_VMCS_PTR.
2403 */
2404#if ((RT_INLINE_ASM_EXTERNAL || !defined(RT_ARCH_X86)) && !VMX_USE_MSC_INTRINSICS)
2405DECLASM(int) VMXReadVmcs32(uint32_t idxField, uint32_t *pData);
2406#else
2407DECLINLINE(int) VMXReadVmcs32(uint32_t idxField, uint32_t *pData)
2408{
2409# if RT_INLINE_ASM_GNU_STYLE
2410 int rc = VINF_SUCCESS;
2411 __asm__ __volatile__ (
2412 "movl $" RT_XSTR(VINF_SUCCESS)", %0 \n\t"
2413 ".byte 0x0f, 0x78, 0xc2 # VMREAD eax, edx \n\t"
2414 "ja 2f \n\t"
2415 "je 1f \n\t"
2416 "movl $" RT_XSTR(VERR_VMX_INVALID_VMCS_PTR)", %0 \n\t"
2417 "jmp 2f \n\t"
2418 "1: \n\t"
2419 "movl $" RT_XSTR(VERR_VMX_INVALID_VMCS_FIELD)", %0 \n\t"
2420 "2: \n\t"
2421 :"=&r"(rc),
2422 "=d"(*pData)
2423 :"a"(idxField),
2424 "d"(0)
2425 );
2426 return rc;
2427
2428# elif VMX_USE_MSC_INTRINSICS
2429 unsigned char rcMsc;
2430# if ARCH_BITS == 32
2431 rcMsc = __vmx_vmread(idxField, pData);
2432# else
2433 uint64_t u64Tmp;
2434 rcMsc = __vmx_vmread(idxField, &u64Tmp);
2435 *pData = (uint32_t)u64Tmp;
2436# endif
2437 if (RT_LIKELY(rcMsc == 0))
2438 return VINF_SUCCESS;
2439 return rcMsc == 2 ? VERR_VMX_INVALID_VMCS_PTR : VERR_VMX_INVALID_VMCS_FIELD;
2440
2441#else
2442 int rc = VINF_SUCCESS;
2443 __asm
2444 {
2445 sub esp, 4
2446 mov dword ptr [esp], 0
2447 mov eax, [idxField]
2448 _emit 0x0f
2449 _emit 0x78
2450 _emit 0x04
2451 _emit 0x24 /* VMREAD eax, [esp] */
2452 mov edx, pData
2453 pop dword ptr [edx]
2454 jnc valid_vmcs
2455 mov dword ptr [rc], VERR_VMX_INVALID_VMCS_PTR
2456 jmp the_end
2457
2458valid_vmcs:
2459 jnz the_end
2460 mov dword ptr [rc], VERR_VMX_INVALID_VMCS_FIELD
2461the_end:
2462 }
2463 return rc;
2464# endif
2465}
2466#endif
2467
2468/**
2469 * Executes VMREAD.
2470 *
2471 * @returns VBox status code.
2472 * @retval VINF_SUCCESS.
2473 * @retval VERR_VMX_INVALID_VMCS_PTR.
2474 * @retval VERR_VMX_INVALID_VMCS_FIELD.
2475 *
2476 * @param idxField VMCS index.
2477 * @param pData Where to store VM field value.
2478 *
2479 * @remarks The values of the two status codes can be OR'ed together, the result
2480 * will be VERR_VMX_INVALID_VMCS_PTR.
2481 */
2482#if (!defined(RT_ARCH_X86) && !VMX_USE_MSC_INTRINSICS)
2483DECLASM(int) VMXReadVmcs64(uint32_t idxField, uint64_t *pData);
2484#else
2485DECLINLINE(int) VMXReadVmcs64(uint32_t idxField, uint64_t *pData)
2486{
2487# if VMX_USE_MSC_INTRINSICS
2488 unsigned char rcMsc;
2489# if ARCH_BITS == 32
2490 size_t uLow;
2491 size_t uHigh;
2492 rcMsc = __vmx_vmread(idxField, &uLow);
2493 rcMsc |= __vmx_vmread(idxField + 1, &uHigh);
2494 *pData = RT_MAKE_U64(uLow, uHigh);
2495# else
2496 rcMsc = __vmx_vmread(idxField, pData);
2497# endif
2498 if (RT_LIKELY(rcMsc == 0))
2499 return VINF_SUCCESS;
2500 return rcMsc == 2 ? VERR_VMX_INVALID_VMCS_PTR : VERR_VMX_INVALID_VMCS_FIELD;
2501
2502# elif ARCH_BITS == 32
2503 int rc;
2504 uint32_t val_hi, val;
2505 rc = VMXReadVmcs32(idxField, &val);
2506 rc |= VMXReadVmcs32(idxField + 1, &val_hi);
2507 AssertRC(rc);
2508 *pData = RT_MAKE_U64(val, val_hi);
2509 return rc;
2510
2511# else
2512# error "Shouldn't be here..."
2513# endif
2514}
2515#endif
2516
2517
2518/**
2519 * Gets the last instruction error value from the current VMCS.
2520 *
2521 * @returns VBox status code.
2522 */
2523DECLINLINE(uint32_t) VMXGetLastError(void)
2524{
2525#if ARCH_BITS == 64
2526 uint64_t uLastError = 0;
2527 int rc = VMXReadVmcs64(VMX_VMCS32_RO_VM_INSTR_ERROR, &uLastError);
2528 AssertRC(rc);
2529 return (uint32_t)uLastError;
2530
2531#else /* 32-bit host: */
2532 uint32_t uLastError = 0;
2533 int rc = VMXReadVmcs32(VMX_VMCS32_RO_VM_INSTR_ERROR, &uLastError);
2534 AssertRC(rc);
2535 return uLastError;
2536#endif
2537}
2538
2539/** @} */
2540
2541/** @} */
2542
2543#endif
2544
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