From: Haozhong Zhang Date: Fri, 16 Dec 2016 13:43:34 +0000 (+0800) Subject: vvmx: test whether MSR_FEATURE_CONTROL is set correctly X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=ac6151c03b14df45c2852bf52f6905e407ecd901;p=people%2Fandrewcoop%2Fxen-test-framework.git vvmx: test whether MSR_FEATURE_CONTROL is set correctly Guest MSR_FEATURE_CONTROL is set by Xen hypervisor instead by guest firmware or hvmloader, so this test instead checks whether bits in MSR_FEATURE_CONTROL are set correctly, rather than requiring they are all zeroed. Signed-off-by: Haozhong Zhang Rebase and cleanup. Signed-off-by: Andrew Cooper --- diff --git a/arch/x86/include/arch/msr-index.h b/arch/x86/include/arch/msr-index.h index cc5f5a4..9ac7970 100644 --- a/arch/x86/include/arch/msr-index.h +++ b/arch/x86/include/arch/msr-index.h @@ -8,6 +8,8 @@ #define MSR_APICBASE_EXTD (_AC(1, L) << 10) #define MSR_APICBASE_ENABLE (_AC(1, L) << 11) +#define MSR_FEATURE_CONTROL 0x0000003a + #define MSR_PMC(n) (0x000000c1 + (n)) #define MSR_INTEL_PLATFORM_INFO 0x000000ce @@ -61,6 +63,19 @@ #define MSR_GS_BASE 0xc0000101 #define MSR_SHADOW_GS_BASE 0xc0000102 +#ifndef __ASSEMBLY__ +#include + +typedef union msr_feature_control { + uint64_t raw; + struct { + bool lock:1, + vmxon_inside_smx:1, + vmxon_outside_smx:1; + }; +} msr_feature_control_t; + +#endif /* !__ASSEMBLY__ */ #endif /* XFT_X86_MSR_INDEX_H */ /* diff --git a/tests/vvmx/Makefile b/tests/vvmx/Makefile index eaa12d1..82b895e 100644 --- a/tests/vvmx/Makefile +++ b/tests/vvmx/Makefile @@ -6,6 +6,6 @@ TEST-ENVS := $(HVM_ENVIRONMENTS) TEST-EXTRA-CFG := extra.cfg.in -obj-perenv += main.o +obj-perenv += main.o msr.o include $(ROOT)/build/gen.mk diff --git a/tests/vvmx/main.c b/tests/vvmx/main.c index 1e9edd6..6c02cfc 100644 --- a/tests/vvmx/main.c +++ b/tests/vvmx/main.c @@ -8,9 +8,9 @@ * * @see tests/vvmx/main.c */ -#include +#include "test.h" -const char test_title[] = "Test vvmx"; +const char test_title[] = "Nested VT-x testing"; void test_main(void) { @@ -20,6 +20,8 @@ void test_main(void) if ( !vendor_is_intel ) xtf_warning("Warning: VT-x found on non-Intel processor\n"); + test_msr_vmx(); + xtf_success(NULL); } diff --git a/tests/vvmx/msr.c b/tests/vvmx/msr.c new file mode 100644 index 0000000..231612f --- /dev/null +++ b/tests/vvmx/msr.c @@ -0,0 +1,46 @@ +#include "test.h" + +/* + * Guest MSR_FEATURE_CONTROL is set by Xen hypervisor instead by guest + * firmware or hvmloader, so this test checks whether bits in + * MSR_FEATURE_CONTROL are set correctly and does not require they are all + * zero. + */ +static void test_msr_feature_control(void) +{ + msr_feature_control_t feat; + + if ( rdmsr_safe(MSR_FEATURE_CONTROL, &feat.raw) ) + return xtf_failure("Fail: Fault when reading MSR_FEATURE_CONTROL\n"); + + if ( !cpu_has_smx && feat.vmxon_inside_smx ) + xtf_failure("Fail: FEATURE_CONTROL.VMXON_INSIDE_SMX is set but SMX is not supported\n"); + + if ( !feat.vmxon_outside_smx ) + xtf_failure("Fail: FEATURE_CONTROL.VMXON_OUTSIDE_SMX is not set\n"); + + /* VMXON should be unusable if LOCK isn't set. */ + if ( !feat.lock ) + xtf_failure("Fail: FEATURE_CONTROL.LOCK is not set\n"); + + /* Because LOCK is set, the MSR should be read-only. */ + if ( !wrmsr_safe(MSR_FEATURE_CONTROL, feat.raw) ) + xtf_failure("Fail: Successfully wrote to MSR_FEATURE_CONTROL\n"); +} + +void test_msr_vmx(void) +{ + printk("Test: MSRs\n"); + + test_msr_feature_control(); +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/tests/vvmx/test.h b/tests/vvmx/test.h new file mode 100644 index 0000000..2528df2 --- /dev/null +++ b/tests/vvmx/test.h @@ -0,0 +1,10 @@ +#ifndef VVMX_TEST_H +#define VVMX_TEST_H + +#include + +#include + +void test_msr_vmx(void); + +#endif /* VVMX_TEST_H */