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