[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [XTF PATCH 07/16] vvmx: test vmxon in CPL=3 and out of VMX operation



Fault #GP(0) is expected in this test.

Signed-off-by: Haozhong Zhang <haozhong.zhang@xxxxxxxxx>
---
 tests/vvmx/main.c  |  2 ++
 tests/vvmx/vmxon.c | 31 +++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/tests/vvmx/main.c b/tests/vvmx/main.c
index cec9057..c1852fd 100644
--- a/tests/vvmx/main.c
+++ b/tests/vvmx/main.c
@@ -13,6 +13,8 @@
 
 const char test_title[] = "Test vvmx";
 
+bool test_wants_user_mappings = true;
+
 extern bool test_cpuid_vmx_feat(void);
 extern bool test_msr_vmx(void);
 extern bool test_vmxon(void);
diff --git a/tests/vvmx/vmxon.c b/tests/vvmx/vmxon.c
index 31f074c..ca33b3c 100644
--- a/tests/vvmx/vmxon.c
+++ b/tests/vvmx/vmxon.c
@@ -28,11 +28,42 @@ static bool test_vmxon_novmxe(void)
                               VMXERR_FAULT, EXINFO_SYM(UD, 0), 0);
 }
 
+static unsigned long vmxon_in_user(void)
+{
+    exinfo_t fault;
+    unsigned long ret = vmxon((uint64_t)vmxon_region, &fault);
+
+    return (ret << 32) | fault;
+}
+
+/**
+ * vmxon in CPL=3 and out of VMX operation
+ *
+ * Expect: #GP(0)
+ */
+static bool test_vmxon_in_user(void)
+{
+    clear_vmcs(vmxon_region, get_vmcs_revid());
+
+    unsigned long ret = exec_user(vmxon_in_user);
+    uint8_t err = (ret >> 32) & 0xff;
+    exinfo_t fault = ret & 0xFFFFFFFF;
+
+    return handle_vmxinsn_err(__func__, err, fault,
+                              VMXERR_FAULT, EXINFO_SYM(GP, 0), 0);
+}
+
 bool test_vmxon(void)
 {
     if ( !test_vmxon_novmxe() )
         return false;
 
+    unsigned long cr4 = read_cr4();
+    write_cr4(cr4 | X86_CR4_VMXE);
+
+    if ( !test_vmxon_in_user() )
+        return false;
+
     return true;
 }
 
-- 
2.10.1


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.