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

[Xen-devel] [PATCH XTF] Functional: Add a UMIP test



Add a "umip" test for the User-Model Instruction Prevention. The test
simply tries to run sgdt/sidt/sldt/str/smsw in guest user-mode with
CR4_UMIP = 1.

Signed-off-by: Boqun Feng (Intel) <boqun.feng@xxxxxxxxx>
---
 docs/all-tests.dox  |   2 +
 tests/umip/Makefile |   9 ++++
 tests/umip/main.c   | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 131 insertions(+)
 create mode 100644 tests/umip/Makefile
 create mode 100644 tests/umip/main.c

diff --git a/docs/all-tests.dox b/docs/all-tests.dox
index 01a7a572f472..ec5328b50189 100644
--- a/docs/all-tests.dox
+++ b/docs/all-tests.dox
@@ -109,4 +109,6 @@ guest breakout.
 @section index-in-development In Development
 
 @subpage test-vvmx - Nested VT-x tests.
+
+@subpage test-umip - User-Mode Instruction Prevention
 */
diff --git a/tests/umip/Makefile b/tests/umip/Makefile
new file mode 100644
index 000000000000..0248c8b247a0
--- /dev/null
+++ b/tests/umip/Makefile
@@ -0,0 +1,9 @@
+include $(ROOT)/build/common.mk
+
+NAME      := umip
+CATEGORY  := functional
+TEST-ENVS := hvm32 hvm64
+
+obj-perenv += main.o
+
+include $(ROOT)/build/gen.mk
diff --git a/tests/umip/main.c b/tests/umip/main.c
new file mode 100644
index 000000000000..27b7d44f4b98
--- /dev/null
+++ b/tests/umip/main.c
@@ -0,0 +1,120 @@
+/**
+ * @file tests/umip/main.c
+ * @ref test-umip
+ *
+ * @page test-umip umip
+ *
+ * @todo Docs for test-umip
+ *
+ * @see tests/umip/main.c
+ */
+#include <xtf.h>
+#include <arch/processor.h>
+
+const char test_title[] = "User-Mode Instruction Prevention Test";
+bool test_wants_user_mapping = true;
+
+unsigned long umip_sgdt(void)
+{
+    unsigned long fault = 0;
+    unsigned long tmp;
+
+    asm volatile("1: sgdt %[tmp]; 2:"
+                 _ASM_EXTABLE_HANDLER(1b,2b, ex_record_fault_edi)
+                : "+D" (fault), [tmp] "=m" (tmp)
+                :);
+
+    return fault;
+}
+
+unsigned long umip_sldt(void)
+{
+    unsigned long fault = 0;
+    unsigned long tmp;
+
+    asm volatile("1: sldt %[tmp]; 2:"
+                 _ASM_EXTABLE_HANDLER(1b,2b, ex_record_fault_edi)
+                : "+D" (fault), [tmp] "=m" (tmp)
+                :);
+
+    return fault;
+}
+
+unsigned long umip_sidt(void)
+{
+    unsigned long fault = 0;
+    unsigned long tmp;
+
+    asm volatile("1: sidt %[tmp]; 2:"
+                 _ASM_EXTABLE_HANDLER(1b,2b, ex_record_fault_edi)
+                : "+D" (fault), [tmp] "=m" (tmp)
+                :);
+
+    return fault;
+}
+
+unsigned long umip_str(void)
+{
+    unsigned long fault = 0;
+    unsigned long tmp;
+
+    asm volatile("1: str %[tmp]; 2:"
+                 _ASM_EXTABLE_HANDLER(1b,2b, ex_record_fault_edi)
+                : "+D" (fault), [tmp] "=m" (tmp)
+                :);
+
+    return fault;
+}
+
+unsigned long umip_smsw(void)
+{
+    unsigned long fault = 0;
+    unsigned long tmp;
+
+    asm volatile("1: smsw %[tmp]; 2:"
+                 _ASM_EXTABLE_HANDLER(1b,2b, ex_record_fault_edi)
+                : "+D" (fault), [tmp] "=m" (tmp)
+                :);
+
+    return fault;
+}
+
+void test_main(void)
+{
+    unsigned long exp;
+    unsigned long cr4 = read_cr4();
+
+    if ( !cpu_has_umip )
+        xtf_failure("Fail: UMIP is not supported\n");
+
+    write_cr4(cr4 | X86_CR4_UMIP);
+
+    exp = EXINFO_SYM(GP, 0);
+
+    if ( exec_user(umip_sgdt) != exp )
+        xtf_failure("Fail: sgdt didn't trigger #GP\n");
+
+    if ( exec_user(umip_sldt) != exp )
+        xtf_failure("Fail: sldt didn't trigger #GP\n");
+
+    if ( exec_user(umip_sidt) != exp )
+        xtf_failure("Fail: sidt didn't trigger #GP\n");
+
+    if ( exec_user(umip_str) != exp )
+        xtf_failure("Fail: str didn't trigger #GP\n");
+
+    if ( exec_user(umip_smsw) != exp )
+        xtf_failure("Fail: smsw didn't trigger #GP\n");
+
+    xtf_success(NULL);
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
-- 
2.13.2


_______________________________________________
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®.