xref: /illumos-kvm-cmd/kvm/scripts/vmxcap (revision 68396ea9)
1#!/usr/bin/python
2
3MSR_IA32_VMX_BASIC = 0x480
4MSR_IA32_VMX_PINBASED_CTLS = 0x481
5MSR_IA32_VMX_PROCBASED_CTLS = 0x482
6MSR_IA32_VMX_EXIT_CTLS = 0x483
7MSR_IA32_VMX_ENTRY_CTLS = 0x484
8MSR_IA32_VMX_MISC_CTLS = 0x485
9MSR_IA32_VMX_PROCBASED_CTLS2 = 0x48B
10MSR_IA32_VMX_EPT_VPID_CAP = 0x48C
11MSR_IA32_VMX_TRUE_PINBASED_CTLS = 0x48D
12MSR_IA32_VMX_TRUE_PROCBASED_CTLS = 0x48E
13MSR_IA32_VMX_TRUE_EXIT_CTLS = 0x48F
14MSR_IA32_VMX_TRUE_ENTRY_CTLS = 0x490
15
16class msr(object):
17    def __init__(self):
18        try:
19            self.f = file('/dev/cpu/0/msr')
20        except:
21            self.f = file('/dev/msr0')
22    def read(self, index, default = None):
23        import struct
24        self.f.seek(index)
25        try:
26            return struct.unpack('Q', self.f.read(8))[0]
27        except:
28            return default
29
30class Control(object):
31    def __init__(self, name, bits, cap_msr, true_cap_msr = None):
32        self.name = name
33        self.bits = bits
34        self.cap_msr = cap_msr
35        self.true_cap_msr = true_cap_msr
36    def read2(self, nr):
37        m = msr()
38        val = m.read(nr, 0)
39        return (val & 0xffffffff, val >> 32)
40    def show(self):
41        print self.name
42        mbz, mb1 = self.read2(self.cap_msr)
43        tmbz, tmb1 = 0, 0
44        if self.true_cap_msr:
45            tmbz, tmb1 = self.read2(self.true_cap_msr)
46        for bit in sorted(self.bits.keys()):
47            zero = not (mbz & (1 << bit))
48            one = mb1 & (1 << bit)
49            true_zero = not (tmbz & (1 << bit))
50            true_one = tmb1 & (1 << bit)
51            s= '?'
52            if (self.true_cap_msr and true_zero and true_one
53                and one and not zero):
54                s = 'default'
55            elif zero and not one:
56                s = 'no'
57            elif one and not zero:
58                s = 'forced'
59            elif one and zero:
60                s = 'yes'
61            print '  %-40s %s' % (self.bits[bit], s)
62
63class Misc(object):
64    def __init__(self, name, bits, msr):
65        self.name = name
66        self.bits = bits
67        self.msr = msr
68    def show(self):
69        print self.name
70        value = msr().read(self.msr, 0)
71        def first_bit(key):
72            if type(key) is tuple:
73                return key[0]
74            else:
75                return key
76        for bits in sorted(self.bits.keys(), key = first_bit):
77            if type(bits) is tuple:
78                lo, hi = bits
79                fmt = int
80            else:
81                lo = hi = bits
82                def fmt(x):
83                    return { True: 'yes', False: 'no' }[x]
84            v = (value >> lo) & ((1 << (hi - lo + 1)) - 1)
85            print '  %-40s %s' % (self.bits[bits], fmt(v))
86
87controls = [
88    Control(
89        name = 'pin-based controls',
90        bits = {
91            0: 'External interrupt exiting',
92            3: 'NMI exiting',
93            5: 'Virtual NMIs',
94            6: 'Activate VMX-preemption timer',
95            },
96        cap_msr = MSR_IA32_VMX_PINBASED_CTLS,
97        true_cap_msr = MSR_IA32_VMX_TRUE_PINBASED_CTLS,
98        ),
99
100    Control(
101        name = 'primary processor-based controls',
102        bits = {
103            2: 'Interrupt window exiting',
104            3: 'Use TSC offsetting',
105            7: 'HLT exiting',
106            9: 'INVLPG exiting',
107            10: 'MWAIT exiting',
108            11: 'RDPMC exiting',
109            12: 'RDTSC exiting',
110            15: 'CR3-load exiting',
111            16: 'CR3-store exiting',
112            19: 'CR8-load exiting',
113            20: 'CR8-store exiting',
114            21: 'Use TPR shadow',
115            22: 'NMI-window exiting',
116            23: 'MOV-DR exiting',
117            24: 'Unconditional I/O exiting',
118            25: 'Use I/O bitmaps',
119            27: 'Monitor trap flag',
120            28: 'Use MSR bitmaps',
121            29: 'MONITOR exiting',
122            30: 'PAUSE exiting',
123            31: 'Activate secondary control',
124            },
125        cap_msr = MSR_IA32_VMX_PROCBASED_CTLS,
126        true_cap_msr = MSR_IA32_VMX_TRUE_PROCBASED_CTLS,
127        ),
128
129    Control(
130        name = 'secondary processor-based controls',
131        bits = {
132            0: 'Virtualize APIC accesses',
133            1: 'Enable EPT',
134            2: 'Descriptor-table exiting',
135            4: 'Virtualize x2APIC mode',
136            5: 'Enable VPID',
137            6: 'WBINVD exiting',
138            7: 'Unrestricted guest',
139            10: 'PAUSE-loop exiting',
140            },
141        cap_msr = MSR_IA32_VMX_PROCBASED_CTLS2,
142        ),
143
144    Control(
145        name = 'VM-Exit controls',
146        bits = {
147            2: 'Save debug controls',
148            9: 'Host address-space size',
149            12: 'Load IA32_PERF_GLOBAL_CTRL',
150            15: 'Acknowledge interrupt on exit',
151            18: 'Save IA32_PAT',
152            19: 'Load IA32_PAT',
153            20: 'Save IA32_EFER',
154            21: 'Load IA32_EFER',
155            22: 'Save VMX-preemption timer value',
156            },
157        cap_msr = MSR_IA32_VMX_EXIT_CTLS,
158        true_cap_msr = MSR_IA32_VMX_TRUE_EXIT_CTLS,
159        ),
160
161    Control(
162        name = 'VM-Entry controls',
163        bits = {
164            2: 'Load debug controls',
165            9: 'IA-64 mode guest',
166            10: 'Entry to SMM',
167            11: 'Deactivate dual-monitor treatment',
168            13: 'Load IA32_PERF_GLOBAL_CTRL',
169            14: 'Load IA32_PAT',
170            15: 'Load IA32_EFER',
171            },
172        cap_msr = MSR_IA32_VMX_ENTRY_CTLS,
173        true_cap_msr = MSR_IA32_VMX_TRUE_ENTRY_CTLS,
174        ),
175
176    Misc(
177        name = 'Miscellaneous data',
178        bits = {
179            (0,4): 'VMX-preemption timer scale (log2)',
180            5: 'Store EFER.LMA into IA-32e mode guest control',
181            6: 'HLT activity state',
182            7: 'Shutdown activity state',
183            8: 'Wait-for-SIPI activity state',
184            (16,24): 'Number of CR3-target values',
185            (25,27): 'MSR-load/store count recommenation',
186            (32,62): 'MSEG revision identifier',
187            },
188        msr = MSR_IA32_VMX_MISC_CTLS,
189        ),
190
191    Misc(
192        name = 'VPID and EPT capabilities',
193        bits = {
194            0: 'Execute-only EPT translations',
195            6: 'Page-walk length 4',
196            8: 'Paging-structure memory type UC',
197            14: 'Paging-structure memory type WB',
198            16: '2MB EPT pages',
199            17: '1GB EPT pages',
200            20: 'INVEPT supported',
201            25: 'Single-context INVEPT',
202            26: 'All-context INVEPT',
203            32: 'INVVPID supported',
204            40: 'Individual-address INVVPID',
205            41: 'Single-context INVVPID',
206            42: 'All-context INVVPID',
207            43: 'Single-context-retaining-globals INVVPID',
208            },
209        msr = MSR_IA32_VMX_EPT_VPID_CAP,
210        ),
211    ]
212
213for c in controls:
214    c.show()
215
216
217