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
26 MSR_IA32_VMX_PROCBASED_CTLS3 = 0x492
31 self.f = open('/dev/cpu/0/msr', 'rb', 0)
33 self.f = open('/dev/msr0', 'rb', 0)
34 def read(self, index, default = None):
38 return struct.unpack('Q', self.f.read(8))[0]
42 class Control(object):
43 def __init__(self, name, bits, cap_msr, true_cap_msr = None):
46 self.cap_msr = cap_msr
47 self.true_cap_msr = true_cap_msr
51 return (val & 0xffffffff, val >> 32)
54 mb1, cb1 = self.read2(self.cap_msr)
57 tmb1, tcb1 = self.read2(self.true_cap_msr)
58 for bit in sorted(self.bits.keys()):
59 zero = not (mb1 & (1 << bit))
60 one = cb1 & (1 << bit)
61 true_zero = not (tmb1 & (1 << bit))
62 true_one = tcb1 & (1 << bit)
64 if (self.true_cap_msr and true_zero and true_one
65 and one and not zero):
67 elif zero and not one:
69 elif one and not zero:
73 print(' %-40s %s' % (self.bits[bit], s))
75 # All 64 bits in the tertiary controls MSR are allowed-1
76 class Allowed1Control(Control):
83 def __init__(self, name, bits, msr):
89 value = msr().read(self.msr, 0)
90 print(' Hex: 0x%x' % (value))
92 if type(key) is tuple:
96 for bits in sorted(self.bits.keys(), key = first_bit):
97 if type(bits) is tuple:
103 return { True: 'yes', False: 'no' }[x]
104 v = (value >> lo) & ((1 << (hi - lo + 1)) - 1)
105 print(' %-40s %s' % (self.bits[bits], fmt(v)))
109 name = 'Basic VMX Information',
112 (32,44): 'VMCS size',
113 48: 'VMCS restricted to 32 bit addresses',
114 49: 'Dual-monitor support',
115 (50, 53): 'VMCS memory type',
116 54: 'INS/OUTS instruction information',
117 55: 'IA32_VMX_TRUE_*_CTLS support',
118 56: 'Skip checks on event error code',
120 msr = MSR_IA32_VMX_BASIC,
123 name = 'pin-based controls',
125 0: 'External interrupt exiting',
128 6: 'Activate VMX-preemption timer',
129 7: 'Process posted interrupts',
131 cap_msr = MSR_IA32_VMX_PINBASED_CTLS,
132 true_cap_msr = MSR_IA32_VMX_TRUE_PINBASED_CTLS,
136 name = 'primary processor-based controls',
138 2: 'Interrupt window exiting',
139 3: 'Use TSC offsetting',
145 15: 'CR3-load exiting',
146 16: 'CR3-store exiting',
147 17: 'Activate tertiary controls',
148 19: 'CR8-load exiting',
149 20: 'CR8-store exiting',
150 21: 'Use TPR shadow',
151 22: 'NMI-window exiting',
152 23: 'MOV-DR exiting',
153 24: 'Unconditional I/O exiting',
154 25: 'Use I/O bitmaps',
155 27: 'Monitor trap flag',
156 28: 'Use MSR bitmaps',
157 29: 'MONITOR exiting',
159 31: 'Activate secondary control',
161 cap_msr = MSR_IA32_VMX_PROCBASED_CTLS,
162 true_cap_msr = MSR_IA32_VMX_TRUE_PROCBASED_CTLS,
166 name = 'secondary processor-based controls',
168 0: 'Virtualize APIC accesses',
170 2: 'Descriptor-table exiting',
172 4: 'Virtualize x2APIC mode',
175 7: 'Unrestricted guest',
176 8: 'APIC register emulation',
177 9: 'Virtual interrupt delivery',
178 10: 'PAUSE-loop exiting',
179 11: 'RDRAND exiting',
180 12: 'Enable INVPCID',
181 13: 'Enable VM functions',
182 14: 'VMCS shadowing',
183 15: 'Enable ENCLS exiting',
184 16: 'RDSEED exiting',
186 18: 'EPT-violation #VE',
187 19: 'Conceal non-root operation from PT',
188 20: 'Enable XSAVES/XRSTORS',
189 22: 'Mode-based execute control (XS/XU)',
190 23: 'Sub-page write permissions',
191 24: 'GPA translation for PT',
193 26: 'User wait and pause',
196 cap_msr = MSR_IA32_VMX_PROCBASED_CTLS2,
200 name = 'tertiary processor-based controls',
202 4: 'Enable IPI virtualization'
204 cap_msr = MSR_IA32_VMX_PROCBASED_CTLS3,
208 name = 'VM-Exit controls',
210 2: 'Save debug controls',
211 9: 'Host address-space size',
212 12: 'Load IA32_PERF_GLOBAL_CTRL',
213 15: 'Acknowledge interrupt on exit',
216 20: 'Save IA32_EFER',
217 21: 'Load IA32_EFER',
218 22: 'Save VMX-preemption timer value',
219 23: 'Clear IA32_BNDCFGS',
220 24: 'Conceal VM exits from PT',
221 25: 'Clear IA32_RTIT_CTL',
223 cap_msr = MSR_IA32_VMX_EXIT_CTLS,
224 true_cap_msr = MSR_IA32_VMX_TRUE_EXIT_CTLS,
228 name = 'VM-Entry controls',
230 2: 'Load debug controls',
231 9: 'IA-32e mode guest',
233 11: 'Deactivate dual-monitor treatment',
234 13: 'Load IA32_PERF_GLOBAL_CTRL',
236 15: 'Load IA32_EFER',
237 16: 'Load IA32_BNDCFGS',
238 17: 'Conceal VM entries from PT',
239 18: 'Load IA32_RTIT_CTL',
241 cap_msr = MSR_IA32_VMX_ENTRY_CTLS,
242 true_cap_msr = MSR_IA32_VMX_TRUE_ENTRY_CTLS,
246 name = 'Miscellaneous data',
248 (0,4): 'VMX-preemption timer scale (log2)',
249 5: 'Store EFER.LMA into IA-32e mode guest control',
250 6: 'HLT activity state',
251 7: 'Shutdown activity state',
252 8: 'Wait-for-SIPI activity state',
253 14: 'PT in VMX operation',
254 15: 'IA32_SMBASE support',
255 (16,24): 'Number of CR3-target values',
256 (25,27): 'MSR-load/store count recommendation',
257 28: 'IA32_SMM_MONITOR_CTL[2] can be set to 1',
258 29: 'VMWRITE to VM-exit information fields',
259 30: 'Inject event with insn length=0',
260 (32,63): 'MSEG revision identifier',
262 msr = MSR_IA32_VMX_MISC_CTLS,
266 name = 'VPID and EPT capabilities',
268 0: 'Execute-only EPT translations',
269 6: 'Page-walk length 4',
270 7: 'Page-walk length 5',
271 8: 'Paging-structure memory type UC',
272 14: 'Paging-structure memory type WB',
275 20: 'INVEPT supported',
276 21: 'EPT accessed and dirty flags',
277 22: 'Advanced VM-exit information for EPT violations',
278 25: 'Single-context INVEPT',
279 26: 'All-context INVEPT',
280 32: 'INVVPID supported',
281 40: 'Individual-address INVVPID',
282 41: 'Single-context INVVPID',
283 42: 'All-context INVVPID',
284 43: 'Single-context-retaining-globals INVVPID',
286 msr = MSR_IA32_VMX_EPT_VPID_CAP,
289 name = 'VM Functions',
293 msr = MSR_IA32_VMX_VMFUNC,
297 if __name__ == '__main__':