]> xenbits.xensource.com Git - people/andrewcoop/xen-test-framework.git/commitdiff
vvmx: test whether MSR_FEATURE_CONTROL is set correctly
authorHaozhong Zhang <haozhong.zhang@intel.com>
Fri, 16 Dec 2016 13:43:34 +0000 (21:43 +0800)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Wed, 28 Jun 2017 14:29:14 +0000 (15:29 +0100)
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 <haozhong.zhang@intel.com>
Rebase and cleanup.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
arch/x86/include/arch/msr-index.h
tests/vvmx/Makefile
tests/vvmx/main.c
tests/vvmx/msr.c [new file with mode: 0644]
tests/vvmx/test.h [new file with mode: 0644]

index cc5f5a4f34f4473cc9e0b177af742b0cb05e3fca..9ac797017b9c9617ed3dd87467e74a13bc61c964 100644 (file)
@@ -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
 #define MSR_GS_BASE                     0xc0000101
 #define MSR_SHADOW_GS_BASE              0xc0000102
 
+#ifndef __ASSEMBLY__
+#include <xtf/types.h>
+
+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 */
 
 /*
index eaa12d1421b032c7013372a481a63197e7592606..82b895e900b78b7698f2d9cea029646c2ba7cd1a 100644 (file)
@@ -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
index 1e9edd698b5ff24ffa925e115991198cdfe7b770..6c02cfc09f430169662e44890b8450968c5e8295 100644 (file)
@@ -8,9 +8,9 @@
  *
  * @see tests/vvmx/main.c
  */
-#include <xtf.h>
+#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 (file)
index 0000000..231612f
--- /dev/null
@@ -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 (file)
index 0000000..2528df2
--- /dev/null
@@ -0,0 +1,10 @@
+#ifndef VVMX_TEST_H
+#define VVMX_TEST_H
+
+#include <xtf.h>
+
+#include <arch/msr-index.h>
+
+void test_msr_vmx(void);
+
+#endif /* VVMX_TEST_H */