]> xenbits.xensource.com Git - people/andrewcoop/xen-test-framework.git/commitdiff
vvmx: Test vmxon with mismatched VMCS revision ID
authorHaozhong Zhang <haozhong.zhang@intel.com>
Fri, 16 Dec 2016 13:43:42 +0000 (21:43 +0800)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 30 Jun 2017 09:21:43 +0000 (10:21 +0100)
VMfailInvalid is expected in this test.

Signed-off-by: Haozhong Zhang <haozhong.zhang@intel.com>
Rebase and cleanup.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
tests/vvmx/main.c
tests/vvmx/test.h
tests/vvmx/util.c
tests/vvmx/vmxon.c

index 5c635d0e130a67ecc9cacf5f37793b049b636ccc..9e213374680f928977b83bcada1c332766f21516 100644 (file)
@@ -21,6 +21,12 @@ void test_main(void)
         xtf_warning("Warning: VT-x found on non-Intel processor\n");
 
     test_msr_vmx();
+
+    if ( xtf_status_reported() )
+        return; /* No point continuing if the basic MSRs aren't working. */
+
+    vmx_collect_data();
+
     test_vmxon();
 
     xtf_success(NULL);
index 472d79623dffacb8a313c53912e56322fa7308d9..ef8239a16ac11384ad8bfb6f9f96834b784f7fb7 100644 (file)
  */
 void check(const char *func, exinfo_t got, exinfo_t exp);
 
+extern uint32_t vmcs_revid; /**< Hardware VMCS Revision ID. */
+
+/**
+ * Collect real information about the VT-x environment, for use by test.
+ */
+void vmx_collect_data(void);
+
+/* Clear a VMCS, and set a specific revision id. */
+static inline void clear_vmcs(void *_vmcs, uint32_t rev)
+{
+    uint32_t *vmcs = _vmcs;
+
+    memset(vmcs, 0, PAGE_SIZE);
+    vmcs[0] = rev;
+}
+
 /* VMX instruction stubs, wrapped to return exinfo_t information. */
 exinfo_t stub_vmxon(uint64_t paddr);
 exinfo_t stub_vmxon_user(uint64_t paddr);
index 4290a998d6890579c9aa62bb09f9c34abc5b07fe..c86ed432ca2eaf3d838318bb0cc3daa52bc05352 100644 (file)
@@ -52,6 +52,15 @@ void check(const char *func, exinfo_t got, exinfo_t exp)
                 func, exp, expstr, got, gotstr);
 }
 
+uint32_t vmcs_revid;
+
+void vmx_collect_data(void)
+{
+    msr_vmx_basic_t basic = { rdmsr(MSR_VMX_BASIC) };
+
+    vmcs_revid = basic.vmcs_rev_id;
+}
+
 /*
  * Read the VM Instruction Error code from the VMCS.  It is the callers
  * responsibility to ensure that the VMCS is valid in context.
index fcd0869f1f7b4577c79d1f091ddf7fb36eed6e28..4fe68e26367f5023728826646d8c615fc3fc4168 100644 (file)
@@ -71,6 +71,19 @@ static void test_vmxon_unaligned_paddr(void)
     check(__func__, ex, VMERR_INVALID);
 }
 
+/**
+ * vmxon with VMCS revision ID mismatched with MSR_IA32_VMX_BASIC
+ *
+ * Expect: VMfailInvalid
+ */
+static void test_vmxon_mismatched_revid(void)
+{
+    clear_vmcs(vmxon_region_unused, vmcs_revid ^ 2);
+    exinfo_t ex = stub_vmxon(_u(vmxon_region_unused));
+
+    check(__func__, ex, VMERR_INVALID);
+}
+
 void test_vmxon(void)
 {
     unsigned long cr4 = read_cr4();
@@ -88,6 +101,7 @@ void test_vmxon(void)
     test_vmxon_in_user();
     test_vmxon_overly_wide_paddr();
     test_vmxon_unaligned_paddr();
+    test_vmxon_mismatched_revid();
 }
 
 /*