]>
Commit | Line | Data |
---|---|---|
5f6caa4f JK |
1 | #!/usr/bin/python |
2 | # | |
3 | # tool for querying VMX capabilities | |
4 | # | |
5 | # Copyright 2009-2010 Red Hat, Inc. | |
6 | # | |
7 | # Authors: | |
8 | # Avi Kivity <[email protected]> | |
9 | # | |
10 | # This work is licensed under the terms of the GNU GPL, version 2. See | |
11 | # the COPYING file in the top-level directory. | |
12 | ||
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 | |
287d55c6 | 25 | MSR_IA32_VMX_VMFUNC = 0x491 |
5f6caa4f JK |
26 | |
27 | class msr(object): | |
28 | def __init__(self): | |
29 | try: | |
f505a4d7 | 30 | self.f = open('/dev/cpu/0/msr', 'r', 0) |
5f6caa4f | 31 | except: |
f505a4d7 | 32 | self.f = open('/dev/msr0', 'r', 0) |
5f6caa4f JK |
33 | def read(self, index, default = None): |
34 | import struct | |
35 | self.f.seek(index) | |
36 | try: | |
37 | return struct.unpack('Q', self.f.read(8))[0] | |
38 | except: | |
39 | return default | |
40 | ||
41 | class Control(object): | |
42 | def __init__(self, name, bits, cap_msr, true_cap_msr = None): | |
43 | self.name = name | |
44 | self.bits = bits | |
45 | self.cap_msr = cap_msr | |
46 | self.true_cap_msr = true_cap_msr | |
47 | def read2(self, nr): | |
48 | m = msr() | |
49 | val = m.read(nr, 0) | |
50 | return (val & 0xffffffff, val >> 32) | |
51 | def show(self): | |
52 | print self.name | |
53 | mbz, mb1 = self.read2(self.cap_msr) | |
54 | tmbz, tmb1 = 0, 0 | |
55 | if self.true_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) | |
62 | s= '?' | |
63 | if (self.true_cap_msr and true_zero and true_one | |
64 | and one and not zero): | |
65 | s = 'default' | |
66 | elif zero and not one: | |
67 | s = 'no' | |
68 | elif one and not zero: | |
69 | s = 'forced' | |
70 | elif one and zero: | |
71 | s = 'yes' | |
72 | print ' %-40s %s' % (self.bits[bit], s) | |
73 | ||
74 | class Misc(object): | |
75 | def __init__(self, name, bits, msr): | |
76 | self.name = name | |
77 | self.bits = bits | |
78 | self.msr = msr | |
79 | def show(self): | |
80 | print self.name | |
81 | value = msr().read(self.msr, 0) | |
82 | def first_bit(key): | |
83 | if type(key) is tuple: | |
84 | return key[0] | |
85 | else: | |
86 | return key | |
87 | for bits in sorted(self.bits.keys(), key = first_bit): | |
88 | if type(bits) is tuple: | |
89 | lo, hi = bits | |
90 | fmt = int | |
91 | else: | |
92 | lo = hi = bits | |
93 | def fmt(x): | |
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)) | |
97 | ||
98 | controls = [ | |
ea4ee283 JK |
99 | Misc( |
100 | name = 'Basic VMX Information', | |
101 | bits = { | |
c5d1e2cc | 102 | (0, 30): 'Revision', |
ea4ee283 JK |
103 | (32,44): 'VMCS size', |
104 | 48: 'VMCS restricted to 32 bit addresses', | |
105 | 49: 'Dual-monitor support', | |
106 | (50, 53): 'VMCS memory type', | |
107 | 54: 'INS/OUTS instruction information', | |
108 | 55: 'IA32_VMX_TRUE_*_CTLS support', | |
109 | }, | |
110 | msr = MSR_IA32_VMX_BASIC, | |
111 | ), | |
5f6caa4f JK |
112 | Control( |
113 | name = 'pin-based controls', | |
114 | bits = { | |
115 | 0: 'External interrupt exiting', | |
116 | 3: 'NMI exiting', | |
117 | 5: 'Virtual NMIs', | |
118 | 6: 'Activate VMX-preemption timer', | |
ea4ee283 | 119 | 7: 'Process posted interrupts', |
5f6caa4f JK |
120 | }, |
121 | cap_msr = MSR_IA32_VMX_PINBASED_CTLS, | |
122 | true_cap_msr = MSR_IA32_VMX_TRUE_PINBASED_CTLS, | |
123 | ), | |
124 | ||
125 | Control( | |
126 | name = 'primary processor-based controls', | |
127 | bits = { | |
128 | 2: 'Interrupt window exiting', | |
129 | 3: 'Use TSC offsetting', | |
130 | 7: 'HLT exiting', | |
131 | 9: 'INVLPG exiting', | |
132 | 10: 'MWAIT exiting', | |
133 | 11: 'RDPMC exiting', | |
134 | 12: 'RDTSC exiting', | |
135 | 15: 'CR3-load exiting', | |
136 | 16: 'CR3-store exiting', | |
137 | 19: 'CR8-load exiting', | |
138 | 20: 'CR8-store exiting', | |
139 | 21: 'Use TPR shadow', | |
140 | 22: 'NMI-window exiting', | |
141 | 23: 'MOV-DR exiting', | |
142 | 24: 'Unconditional I/O exiting', | |
143 | 25: 'Use I/O bitmaps', | |
144 | 27: 'Monitor trap flag', | |
145 | 28: 'Use MSR bitmaps', | |
146 | 29: 'MONITOR exiting', | |
147 | 30: 'PAUSE exiting', | |
148 | 31: 'Activate secondary control', | |
149 | }, | |
150 | cap_msr = MSR_IA32_VMX_PROCBASED_CTLS, | |
151 | true_cap_msr = MSR_IA32_VMX_TRUE_PROCBASED_CTLS, | |
152 | ), | |
153 | ||
154 | Control( | |
155 | name = 'secondary processor-based controls', | |
156 | bits = { | |
157 | 0: 'Virtualize APIC accesses', | |
158 | 1: 'Enable EPT', | |
159 | 2: 'Descriptor-table exiting', | |
614413f7 | 160 | 3: 'Enable RDTSCP', |
5f6caa4f JK |
161 | 4: 'Virtualize x2APIC mode', |
162 | 5: 'Enable VPID', | |
163 | 6: 'WBINVD exiting', | |
164 | 7: 'Unrestricted guest', | |
614413f7 | 165 | 8: 'APIC register emulation', |
f9e90c79 | 166 | 9: 'Virtual interrupt delivery', |
5f6caa4f | 167 | 10: 'PAUSE-loop exiting', |
287d55c6 AK |
168 | 11: 'RDRAND exiting', |
169 | 12: 'Enable INVPCID', | |
170 | 13: 'Enable VM functions', | |
007e986f | 171 | 14: 'VMCS shadowing', |
c5d1e2cc AKR |
172 | 16: 'RDSEED exiting', |
173 | 18: 'EPT-violation #VE', | |
174 | 20: 'Enable XSAVES/XRSTORS', | |
5f6caa4f JK |
175 | }, |
176 | cap_msr = MSR_IA32_VMX_PROCBASED_CTLS2, | |
177 | ), | |
178 | ||
179 | Control( | |
180 | name = 'VM-Exit controls', | |
181 | bits = { | |
182 | 2: 'Save debug controls', | |
183 | 9: 'Host address-space size', | |
184 | 12: 'Load IA32_PERF_GLOBAL_CTRL', | |
185 | 15: 'Acknowledge interrupt on exit', | |
186 | 18: 'Save IA32_PAT', | |
187 | 19: 'Load IA32_PAT', | |
188 | 20: 'Save IA32_EFER', | |
189 | 21: 'Load IA32_EFER', | |
190 | 22: 'Save VMX-preemption timer value', | |
191 | }, | |
192 | cap_msr = MSR_IA32_VMX_EXIT_CTLS, | |
193 | true_cap_msr = MSR_IA32_VMX_TRUE_EXIT_CTLS, | |
194 | ), | |
195 | ||
196 | Control( | |
197 | name = 'VM-Entry controls', | |
198 | bits = { | |
199 | 2: 'Load debug controls', | |
c5d1e2cc | 200 | 9: 'IA-32e mode guest', |
5f6caa4f JK |
201 | 10: 'Entry to SMM', |
202 | 11: 'Deactivate dual-monitor treatment', | |
203 | 13: 'Load IA32_PERF_GLOBAL_CTRL', | |
204 | 14: 'Load IA32_PAT', | |
205 | 15: 'Load IA32_EFER', | |
206 | }, | |
207 | cap_msr = MSR_IA32_VMX_ENTRY_CTLS, | |
208 | true_cap_msr = MSR_IA32_VMX_TRUE_ENTRY_CTLS, | |
209 | ), | |
210 | ||
211 | Misc( | |
212 | name = 'Miscellaneous data', | |
213 | bits = { | |
214 | (0,4): 'VMX-preemption timer scale (log2)', | |
215 | 5: 'Store EFER.LMA into IA-32e mode guest control', | |
216 | 6: 'HLT activity state', | |
217 | 7: 'Shutdown activity state', | |
218 | 8: 'Wait-for-SIPI activity state', | |
007e986f | 219 | 15: 'IA32_SMBASE support', |
5f6caa4f | 220 | (16,24): 'Number of CR3-target values', |
c5d1e2cc | 221 | (25,27): 'MSR-load/store count recommendation', |
287d55c6 | 222 | 28: 'IA32_SMM_MONITOR_CTL[2] can be set to 1', |
007e986f JK |
223 | 29: 'VMWRITE to VM-exit information fields', |
224 | (32,63): 'MSEG revision identifier', | |
5f6caa4f JK |
225 | }, |
226 | msr = MSR_IA32_VMX_MISC_CTLS, | |
227 | ), | |
228 | ||
229 | Misc( | |
230 | name = 'VPID and EPT capabilities', | |
231 | bits = { | |
232 | 0: 'Execute-only EPT translations', | |
233 | 6: 'Page-walk length 4', | |
234 | 8: 'Paging-structure memory type UC', | |
235 | 14: 'Paging-structure memory type WB', | |
236 | 16: '2MB EPT pages', | |
237 | 17: '1GB EPT pages', | |
238 | 20: 'INVEPT supported', | |
287d55c6 | 239 | 21: 'EPT accessed and dirty flags', |
5f6caa4f JK |
240 | 25: 'Single-context INVEPT', |
241 | 26: 'All-context INVEPT', | |
242 | 32: 'INVVPID supported', | |
243 | 40: 'Individual-address INVVPID', | |
244 | 41: 'Single-context INVVPID', | |
245 | 42: 'All-context INVVPID', | |
246 | 43: 'Single-context-retaining-globals INVVPID', | |
247 | }, | |
248 | msr = MSR_IA32_VMX_EPT_VPID_CAP, | |
249 | ), | |
287d55c6 AK |
250 | Misc( |
251 | name = 'VM Functions', | |
252 | bits = { | |
253 | 0: 'EPTP Switching', | |
254 | }, | |
255 | msr = MSR_IA32_VMX_VMFUNC, | |
256 | ), | |
5f6caa4f JK |
257 | ] |
258 | ||
259 | for c in controls: | |
260 | c.show() |