Xen Test Framework
msr.c
Go to the documentation of this file.
1#include "test.h"
2
3/*
4 * Guest MSR_FEATURE_CONTROL is set by Xen hypervisor instead by guest
5 * firmware or hvmloader, so this test checks whether bits in
6 * MSR_FEATURE_CONTROL are set correctly and does not require they are all
7 * zero.
8 */
9static void test_msr_feature_control(void)
10{
12
14 return xtf_failure("Fail: Fault when reading MSR_FEATURE_CONTROL\n");
15
16 if ( !cpu_has_smx && feat.vmxon_inside_smx )
17 xtf_failure("Fail: FEATURE_CONTROL.VMXON_INSIDE_SMX is set but SMX is not supported\n");
18
19 if ( !feat.vmxon_outside_smx )
20 xtf_failure("Fail: FEATURE_CONTROL.VMXON_OUTSIDE_SMX is not set\n");
21
22 /* VMXON should be unusable if LOCK isn't set. */
23 if ( !feat.lock )
24 xtf_failure("Fail: FEATURE_CONTROL.LOCK is not set\n");
25
26 /* Because LOCK is set, the MSR should be read-only. */
28 xtf_failure("Fail: Successfully wrote to MSR_FEATURE_CONTROL\n");
29}
30
31static void test_msr_vmx_basic(void)
32{
33 msr_vmx_basic_t basic;
34
35 if ( rdmsr_safe(MSR_VMX_BASIC, &basic.raw) )
36 return xtf_failure("Fail: Fault when reading MSR_VMX_BASIC\n");
37
38 if ( basic.mbz )
39 xtf_failure("Fail: MSR_VMX_BASIC[31] is not 0\n");
40
41 if ( basic.vmcs_size == 0 )
42 xtf_failure("Fail: VMCS size reported as 0\n");
43 else if ( basic.vmcs_size > 4096 )
44 xtf_failure("Fail: VMCS size (%u) exceeds 4096 limit\n",
45 basic.vmcs_size);
46
47 if ( cpu_has_lm && basic.paddr_32bit )
48 xtf_failure("Fail: Physical address width limited to 32 bits\n");
49
50 if ( !wrmsr_safe(MSR_VMX_BASIC, basic.raw) )
51 xtf_failure("Fail: Successfully wrote to MSR_VMX_BASIC\n");
52}
53
54void test_msr_vmx(void)
55{
56 printk("Test: MSRs\n");
57
60}
61
62/*
63 * Local variables:
64 * mode: C
65 * c-file-style: "BSD"
66 * c-basic-offset: 4
67 * tab-width: 4
68 * indent-tabs-mode: nil
69 * End:
70 */
#define cpu_has_smx
Definition: cpuid.h:79
#define cpu_has_lm
Definition: cpuid.h:88
void printk(const char *fmt,...)
Definition: console.c:134
#define MSR_VMX_BASIC
Definition: msr-index.h:43
#define MSR_FEATURE_CONTROL
Definition: msr-index.h:16
static bool wrmsr_safe(uint32_t idx, uint64_t val)
Wrapper around wrmsr which safely catches #GP[0].
Definition: msr.h:69
static bool rdmsr_safe(uint32_t idx, uint64_t *val)
Wrapper around rdmsr which safely catches #GP[0].
Definition: msr.h:35
void xtf_failure(const char *fmt,...)
Report a test failure.
Definition: report.c:94
static void test_msr_feature_control(void)
Definition: msr.c:9
void test_msr_vmx(void)
Definition: msr.c:54
static void test_msr_vmx_basic(void)
Definition: msr.c:31
bool vmxon_outside_smx
Definition: msr.h:91
uint64_t raw
Definition: msr.h:87
bool vmxon_inside_smx
Definition: msr.h:90
bool mbz
Definition: msr.h:99
uint64_t raw
Definition: msr.h:96
bool paddr_32bit
Definition: msr.h:102
uint32_t vmcs_size
Definition: msr.h:100