xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Wei Liu <wei.liu2@citrix.com>
To: Xen-devel <xen-devel@lists.xenproject.org>, yu.c.zhang@linux.intel.com
Cc: andrew.cooper3@citrix.com, Wei Liu <wei.liu2@citrix.com>,
	Jan Beulich <JBeulich@suse.com>
Subject: [DO NOT APPLY PATCH XTF 2/2] Add UMIP test
Date: Thu, 2 Mar 2017 08:42:32 +0000	[thread overview]
Message-ID: <20170302084232.13339-3-wei.liu2@citrix.com> (raw)
In-Reply-To: <20170302084232.13339-1-wei.liu2@citrix.com>

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
 tests/umip/Makefile |   9 +++++
 tests/umip/main.c   | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 111 insertions(+)
 create mode 100644 tests/umip/Makefile
 create mode 100644 tests/umip/main.c

diff --git a/tests/umip/Makefile b/tests/umip/Makefile
new file mode 100644
index 0000000..a74016c
--- /dev/null
+++ b/tests/umip/Makefile
@@ -0,0 +1,9 @@
+include $(ROOT)/build/common.mk
+
+NAME      := umip
+CATEGORY  := functional
+TEST-ENVS := hvm32
+
+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 0000000..ca74085
--- /dev/null
+++ b/tests/umip/main.c
@@ -0,0 +1,102 @@
+/**
+ * @file tests/umip/main.c
+ * @ref test-umip
+ *
+ * @page test-umip UMIP
+ *
+ * Test if UMIP (User-Mode Instruction Prevention) is functional.
+ *
+ * Returns SUCCESS if UMIP is functional, SKIP if UMIP is not
+ * available and FAILURE if UMIP doesn't cause SGDT, SLDT, SIDT, STR
+ * or SMSW to fault.
+ *
+ * @see tests/umip/main.c
+ */
+#include <xtf.h>
+
+#include <arch/x86/processor.h>
+
+#define EX(instr)                                                       \
+    bool seen_ ## instr ## _fault;                                      \
+    bool ex_ ##instr(struct cpu_regs *regs,                             \
+                     const struct extable_entry *ex)                    \
+    {                                                                   \
+        if ( regs->entry_vector == X86_EXC_GP )                         \
+        {                                                               \
+            seen_ ## instr ## _fault = true;                            \
+            regs->ip = ex->fixup;                                       \
+                                                                        \
+            return true;                                                \
+        }                                                               \
+                                                                        \
+        return false;                                                   \
+    }                                                                   \
+
+EX(sgdt)
+EX(sldt)
+EX(sidt)
+EX(str)
+EX(smsw)
+
+#undef EX
+
+void test_main(void)
+{
+    uint8_t buf[1024];
+
+    printk("Test if UMIP is functional\n");
+
+    if ( !cpu_has_umip )
+    {
+        xtf_skip("UMIP is not available\n");
+        return;
+    }
+
+    if ( !xtf_has_fep )
+        xtf_skip("FEP not available, some tests will be skipped\n");
+
+    write_cr4(read_cr4() | X86_CR4_UMIP);
+
+#define TEST(fep,instr)                                         \
+    do {                                                        \
+        seen_ ## instr ## _fault = false;                       \
+        asm volatile ("1: " fep #instr " %0; 2:"                \
+                      _ASM_EXTABLE_HANDLER(1b, 2b, ex_ ##instr) \
+                      : : "m"(buf));                            \
+        if ( !seen_ ## instr ## _fault )                        \
+        {                                                       \
+            xtf_failure(fep #instr " didn't cause fault\n");    \
+            return;                                             \
+        }                                                       \
+        seen_ ## instr ## _fault = false;                       \
+    } while (0)
+
+    TEST(, sgdt);
+    TEST(, sldt);
+    TEST(, sidt);
+    TEST(, str);
+    TEST(, smsw);
+
+    if ( xtf_has_fep )
+    {
+        TEST(_ASM_XEN_FEP, sgdt);
+        TEST(_ASM_XEN_FEP, sldt);
+        TEST(_ASM_XEN_FEP, sidt);
+        TEST(_ASM_XEN_FEP, str);
+        TEST(_ASM_XEN_FEP, smsw);
+    }
+
+#undef TEST
+
+    xtf_success(NULL);
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
-- 
2.11.0


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

  parent reply	other threads:[~2017-03-02  8:42 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-02  2:33 About UMIP unit test Yu Zhang
2017-03-02  8:06 ` Andrew Cooper
2017-03-02  8:42 ` [DO NOT APPLY PATCH XTF 0/2] UMIP test case Wei Liu
2017-03-02  8:42   ` [DO NOT APPLY PATCH XTF 1/2] x86: add UMIP feature bit Wei Liu
2017-03-02  8:42   ` Wei Liu [this message]
2017-03-02  9:05   ` [DO NOT APPLY PATCH XTF 0/2] UMIP test case Andrew Cooper
2017-03-02 10:53     ` Wei Liu
2017-03-02 12:30     ` Yu Zhang
2017-03-02 12:39       ` 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=20170302084232.13339-3-wei.liu2@citrix.com \
    --to=wei.liu2@citrix.com \
    --cc=JBeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=xen-devel@lists.xenproject.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).