3 # tool for querying VMX capabilities
5 # Copyright 2009-2010 Red Hat, Inc.
8 # Avi Kivity <avi@redhat.com>
10 # This work is licensed under the terms of the GNU GPL, version 2. See
11 # the COPYING file in the top-level directory.
13 MSR_IA32_VMX_BASIC
= 0x480
14 MSR_IA32_VMX_PINBASED_CTLS
= 0x481
15 MSR_IA32_VMX_PROCBASED_CTLS
= 0x482
16 MSR_IA32_VMX_EXIT_CTLS
= 0x483
17 MSR_IA32_VMX_ENTRY_CTLS
= 0x484
18 MSR_IA32_VMX_MISC_CTLS
= 0x485
19 MSR_IA32_VMX_PROCBASED_CTLS2
= 0x48B
20 MSR_IA32_VMX_EPT_VPID_CAP
= 0x48C
21 MSR_IA32_VMX_TRUE_PINBASED_CTLS
= 0x48D
22 MSR_IA32_VMX_TRUE_PROCBASED_CTLS
= 0x48E
23 MSR_IA32_VMX_TRUE_EXIT_CTLS
= 0x48F
24 MSR_IA32_VMX_TRUE_ENTRY_CTLS
= 0x490
25 MSR_IA32_VMX_VMFUNC
= 0x491
30 self
.f
= file('/dev/cpu/0/msr')
32 self
.f
= file('/dev/msr0')
33 def read(self
, index
, default
= None):
37 return struct
.unpack('Q', self
.f
.read(8))[0]
41 class Control(object):
42 def __init__(self
, name
, bits
, cap_msr
, true_cap_msr
= None):
45 self
.cap_msr
= cap_msr
46 self
.true_cap_msr
= true_cap_msr
50 return (val
& 0xffffffff, val
>> 32)
53 mbz
, mb1
= self
.read2(self
.cap_msr
)
56 tmbz
, tmb1
= self
.read2(self
.true_cap_msr
)
57 for bit
in sorted(self
.bits
.keys()):
58 zero
= not (mbz
& (1 << bit
))
59 one
= mb1
& (1 << bit
)
60 true_zero
= not (tmbz
& (1 << bit
))
61 true_one
= tmb1
& (1 << bit
)
63 if (self
.true_cap_msr
and true_zero
and true_one
64 and one
and not zero
):
66 elif zero
and not one
:
68 elif one
and not zero
:
72 print ' %-40s %s' % (self
.bits
[bit
], s
)
75 def __init__(self
, name
, bits
, msr
):
81 value
= msr().read(self
.msr
, 0)
83 if type(key
) is tuple:
87 for bits
in sorted(self
.bits
.keys(), key
= first_bit
):
88 if type(bits
) is tuple:
94 return { True: 'yes', False: 'no' }[x
]
95 v
= (value
>> lo
) & ((1 << (hi
- lo
+ 1)) - 1)
96 print ' %-40s %s' % (self
.bits
[bits
], fmt(v
))
100 name
= 'pin-based controls',
102 0: 'External interrupt exiting',
105 6: 'Activate VMX-preemption timer',
107 cap_msr
= MSR_IA32_VMX_PINBASED_CTLS
,
108 true_cap_msr
= MSR_IA32_VMX_TRUE_PINBASED_CTLS
,
112 name
= 'primary processor-based controls',
114 2: 'Interrupt window exiting',
115 3: 'Use TSC offsetting',
121 15: 'CR3-load exiting',
122 16: 'CR3-store exiting',
123 19: 'CR8-load exiting',
124 20: 'CR8-store exiting',
125 21: 'Use TPR shadow',
126 22: 'NMI-window exiting',
127 23: 'MOV-DR exiting',
128 24: 'Unconditional I/O exiting',
129 25: 'Use I/O bitmaps',
130 27: 'Monitor trap flag',
131 28: 'Use MSR bitmaps',
132 29: 'MONITOR exiting',
134 31: 'Activate secondary control',
136 cap_msr
= MSR_IA32_VMX_PROCBASED_CTLS
,
137 true_cap_msr
= MSR_IA32_VMX_TRUE_PROCBASED_CTLS
,
141 name
= 'secondary processor-based controls',
143 0: 'Virtualize APIC accesses',
145 2: 'Descriptor-table exiting',
146 4: 'Virtualize x2APIC mode',
149 7: 'Unrestricted guest',
150 10: 'PAUSE-loop exiting',
151 11: 'RDRAND exiting',
152 12: 'Enable INVPCID',
153 13: 'Enable VM functions',
155 cap_msr
= MSR_IA32_VMX_PROCBASED_CTLS2
,
159 name
= 'VM-Exit controls',
161 2: 'Save debug controls',
162 9: 'Host address-space size',
163 12: 'Load IA32_PERF_GLOBAL_CTRL',
164 15: 'Acknowledge interrupt on exit',
167 20: 'Save IA32_EFER',
168 21: 'Load IA32_EFER',
169 22: 'Save VMX-preemption timer value',
171 cap_msr
= MSR_IA32_VMX_EXIT_CTLS
,
172 true_cap_msr
= MSR_IA32_VMX_TRUE_EXIT_CTLS
,
176 name
= 'VM-Entry controls',
178 2: 'Load debug controls',
179 9: 'IA-64 mode guest',
181 11: 'Deactivate dual-monitor treatment',
182 13: 'Load IA32_PERF_GLOBAL_CTRL',
184 15: 'Load IA32_EFER',
186 cap_msr
= MSR_IA32_VMX_ENTRY_CTLS
,
187 true_cap_msr
= MSR_IA32_VMX_TRUE_ENTRY_CTLS
,
191 name
= 'Miscellaneous data',
193 (0,4): 'VMX-preemption timer scale (log2)',
194 5: 'Store EFER.LMA into IA-32e mode guest control',
195 6: 'HLT activity state',
196 7: 'Shutdown activity state',
197 8: 'Wait-for-SIPI activity state',
198 (16,24): 'Number of CR3-target values',
199 (25,27): 'MSR-load/store count recommenation',
200 28: 'IA32_SMM_MONITOR_CTL[2] can be set to 1',
201 (32,62): 'MSEG revision identifier',
203 msr
= MSR_IA32_VMX_MISC_CTLS
,
207 name
= 'VPID and EPT capabilities',
209 0: 'Execute-only EPT translations',
210 6: 'Page-walk length 4',
211 8: 'Paging-structure memory type UC',
212 14: 'Paging-structure memory type WB',
215 20: 'INVEPT supported',
216 21: 'EPT accessed and dirty flags',
217 25: 'Single-context INVEPT',
218 26: 'All-context INVEPT',
219 32: 'INVVPID supported',
220 40: 'Individual-address INVVPID',
221 41: 'Single-context INVVPID',
222 42: 'All-context INVVPID',
223 43: 'Single-context-retaining-globals INVVPID',
225 msr
= MSR_IA32_VMX_EPT_VPID_CAP
,
228 name
= 'VM Functions',
232 msr
= MSR_IA32_VMX_VMFUNC
,