All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Boqun Feng (Intel)" <boqun.feng@gmail.com>
To: xen-devel@lists.xen.org
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
	"Boqun Feng (Intel)" <boqun.feng@gmail.com>,
	yu.c.zhang@linux.intel.com, Jan Beulich <jbeulich@suse.com>
Subject: [PATCH XTF] Functional: Add a UMIP test
Date: Thu, 20 Jul 2017 13:29:21 +0800	[thread overview]
Message-ID: <20170720052921.31586-2-boqun.feng@gmail.com> (raw)
In-Reply-To: <20170720052921.31586-1-boqun.feng@gmail.com>

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@gmail.com>
---
 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@lists.xen.org
https://lists.xen.org/xen-devel

  reply	other threads:[~2017-07-20  5:29 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-20  5:29 [PATCH] x86/cpufeatures: Expose UMIP to HVM guest Boqun Feng (Intel)
2017-07-20  5:29 ` Boqun Feng (Intel) [this message]
2017-07-20  9:38   ` [PATCH XTF] Functional: Add a UMIP test Andrew Cooper
2017-07-21  1:42     ` Boqun Feng
2017-07-21 16:36       ` Andrew Cooper
2017-08-10 10:31 ` [PATCH] x86/cpufeatures: Expose UMIP to HVM guest Jan Beulich
2017-08-14  5:08 ` [PATCH XTF v2] Functional: Add a UMIP test Boqun Feng (Intel)
2017-08-14 10:35   ` Andrew Cooper
2017-08-14 12:43     ` Boqun Feng
2017-08-14 12:48       ` Andrew Cooper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170720052921.31586-2-boqun.feng@gmail.com \
    --to=boqun.feng@gmail.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=xen-devel@lists.xen.org \
    --cc=yu.c.zhang@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.