xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Haozhong Zhang <haozhong.zhang@intel.com>
To: xen-devel@lists.xenproject.org
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
	Haozhong Zhang <haozhong.zhang@intel.com>
Subject: [XTF PATCH 02/16] vvmx: test whether MSR_IA32_FEATURE_CONTROL is set correctly
Date: Fri, 16 Dec 2016 21:43:34 +0800	[thread overview]
Message-ID: <20161216134348.16236-3-haozhong.zhang@intel.com> (raw)
In-Reply-To: <20161216134348.16236-1-haozhong.zhang@intel.com>

Guest MSR_IA32_FEATURE_CONTROL is set by Xen hypervisor instead by
guest firmware or hvmloader, so this test instead checks whether bits
in MSR_IA32_FEATURE_CONTROL are set correctly, rather than requiring
they are all zeroed.

Signed-off-by: Haozhong Zhang <haozhong.zhang@intel.com>
---
 include/arch/x86/msr-index.h |  5 ++++
 tests/vvmx/Makefile          |  2 +-
 tests/vvmx/main.c            |  4 +++
 tests/vvmx/msr.c             | 67 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 77 insertions(+), 1 deletion(-)
 create mode 100644 tests/vvmx/msr.c

diff --git a/include/arch/x86/msr-index.h b/include/arch/x86/msr-index.h
index d479239..f9867d5 100644
--- a/include/arch/x86/msr-index.h
+++ b/include/arch/x86/msr-index.h
@@ -3,6 +3,11 @@
 
 #include <xtf/numbers.h>
 
+#define MSR_IA32_FEATURE_CONTROL        0x0000003a
+#define IA32_FEATURE_CONTROL_LOCK                     0x0001
+#define IA32_FEATURE_CONTROL_ENABLE_VMXON_INSIDE_SMX  0x0002
+#define IA32_FEATURE_CONTROL_ENABLE_VMXON_OUTSIDE_SMX 0x0004
+
 #define MSR_INTEL_PLATFORM_INFO         0x000000ce
 #define _MSR_PLATFORM_INFO_CPUID_FAULTING       31
 #define MSR_PLATFORM_INFO_CPUID_FAULTING        (1ULL << _MSR_PLATFORM_INFO_CPUID_FAULTING)
diff --git a/tests/vvmx/Makefile b/tests/vvmx/Makefile
index 80a6629..54769fa 100644
--- a/tests/vvmx/Makefile
+++ b/tests/vvmx/Makefile
@@ -6,6 +6,6 @@ TEST-ENVS := hvm64
 
 TEST-EXTRA-CFG := extra.cfg.in
 
-obj-perenv += main.o cpuid.o
+obj-perenv += main.o cpuid.o msr.o
 
 include $(ROOT)/build/gen.mk
diff --git a/tests/vvmx/main.c b/tests/vvmx/main.c
index 8506b7b..bd36f10 100644
--- a/tests/vvmx/main.c
+++ b/tests/vvmx/main.c
@@ -14,6 +14,7 @@
 const char test_title[] = "Test vvmx";
 
 extern bool test_cpuid_vmx_feat(void);
+extern bool test_msr_vmx(void);
 
 void test_main(void)
 {
@@ -26,6 +27,9 @@ void test_main(void)
     if ( !test_cpuid_vmx_feat() )
         goto fail;
 
+    if ( !test_msr_vmx() )
+        goto fail;
+
     xtf_success(NULL);
     return;
 
diff --git a/tests/vvmx/msr.c b/tests/vvmx/msr.c
new file mode 100644
index 0000000..100491d
--- /dev/null
+++ b/tests/vvmx/msr.c
@@ -0,0 +1,67 @@
+#include <xtf.h>
+
+#include <arch/x86/msr-index.h>
+
+/*
+ * NB. Guest MSR_IA32_FEATURE_CONTROL is set by Xen hypervisor instead
+ * by guest firmware or hvmloader, so this test checks whether bits in
+ * MSR_IA32_FEATURE_CONTROL are set correctly and does not require they
+ * are all zero.
+ *
+ * TODO: If the behavior in above NB is changed in future, remember to
+ * adjust this test.
+ */
+static bool test_msr_feature_control(void)
+{
+    bool passed = true;
+    uint32_t cpuid_feat_ecx = cpuid_ecx(1);
+    uint64_t msr_feat_ctrl;
+
+    if ( rdmsr_safe(MSR_IA32_FEATURE_CONTROL, &msr_feat_ctrl) )
+    {
+        xtf_failure("Fail: fault when rdmsr MSR_IA32_FEATURE_CONTROL\n");
+        passed = false;
+        goto out;
+    }
+
+    if ( (msr_feat_ctrl & IA32_FEATURE_CONTROL_ENABLE_VMXON_INSIDE_SMX) &&
+         !(cpuid_feat_ecx & X86_FEATURE_SMX) )
+    {
+        xtf_failure("Fail: MSR_IA32_FEATURE_CONTROL[1] is set "
+                    "but SMX is not supported\n");
+        passed = false;
+    }
+
+    if ( !(msr_feat_ctrl & IA32_FEATURE_CONTROL_ENABLE_VMXON_OUTSIDE_SMX) )
+    {
+        xtf_failure("Fail: MSR_IA32_FEATURE_CONTROL[2] is not set\n");
+        passed = false;
+    }
+
+    if ( !(msr_feat_ctrl & IA32_FEATURE_CONTROL_LOCK) )
+    {
+        xtf_failure("Fail: MSR_IA32_FEATURE_CONTROL[0] is not set\n");
+        passed = false;
+    }
+
+out:
+    return passed;
+}
+
+bool test_msr_vmx(void)
+{
+    if ( !test_msr_feature_control() )
+        return false;
+
+    return true;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
-- 
2.10.1


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

  parent reply	other threads:[~2016-12-16 13:44 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-16 13:43 [XTF PATCH 00/16] Add test cases for nested vmxon Haozhong Zhang
2016-12-16 13:43 ` [XTF PATCH 01/16] vvmx: test whether VMX feature is present in CPUID Haozhong Zhang
2016-12-16 14:40   ` Andrew Cooper
2016-12-19  1:51     ` Haozhong Zhang
2016-12-16 13:43 ` Haozhong Zhang [this message]
2016-12-16 16:17   ` [XTF PATCH 02/16] vvmx: test whether MSR_IA32_FEATURE_CONTROL is set correctly Andrew Cooper
2016-12-19  2:20     ` Haozhong Zhang
2016-12-19 15:29       ` Andrew Cooper
2016-12-16 13:43 ` [XTF PATCH 03/16] vvmx: test whether MSR_IA32_VMX_BASIC " Haozhong Zhang
2016-12-16 17:19   ` Andrew Cooper
2016-12-19  2:44     ` Haozhong Zhang
2016-12-19 15:41       ` Andrew Cooper
2016-12-20  2:45         ` Haozhong Zhang
2016-12-16 13:43 ` [XTF PATCH 04/16] vvmx: add C wrappers of vmxon/vmread/vmptrld Haozhong Zhang
2016-12-16 19:03   ` [licensing] was: " Andrew Cooper
2016-12-19  3:20     ` Haozhong Zhang
2016-12-19 14:41       ` Lars Kurth
2016-12-19 15:51         ` Ian Jackson
2016-12-19 15:58       ` Andrew Cooper
2016-12-19 15:20     ` Roger Pau Monné
2016-12-19 15:24       ` Andrew Cooper
2016-12-16 19:47   ` Andrew Cooper
2016-12-19  3:00     ` Haozhong Zhang
2016-12-16 13:43 ` [XTF PATCH 05/16] vvmx: add a general error handler for VMX instructions Haozhong Zhang
2016-12-16 20:16   ` Andrew Cooper
2016-12-19  3:24     ` Haozhong Zhang
2016-12-16 13:43 ` [XTF PATCH 06/16] vvmx: test vmxon with CR4.VMXE cleared Haozhong Zhang
2016-12-16 20:25   ` Andrew Cooper
2016-12-19  3:26     ` Haozhong Zhang
2016-12-16 13:43 ` [XTF PATCH 07/16] vvmx: test vmxon in CPL=3 and out of VMX operation Haozhong Zhang
2016-12-16 20:33   ` Andrew Cooper
2016-12-19  3:35     ` Haozhong Zhang
2016-12-19 16:02       ` Andrew Cooper
2016-12-19 16:02       ` Andrew Cooper
2016-12-16 13:43 ` [XTF PATCH 08/16] vvmx: test vmxon with invalidly wide VMXON region address Haozhong Zhang
2016-12-16 20:40   ` Andrew Cooper
2016-12-19  3:36     ` Haozhong Zhang
2016-12-16 13:43 ` [XTF PATCH 09/16] vvmx: test vmxon with unaligned " Haozhong Zhang
2016-12-16 13:43 ` [XTF PATCH 10/16] vvmx: test vmxon with mismatched VMCS revision ID Haozhong Zhang
2016-12-16 13:43 ` [XTF PATCH 11/16] vvmx: test vmxon with bit 31 of VMCS revision ID set Haozhong Zhang
2016-12-16 13:43 ` [XTF PATCH 12/16] vvmx: test the correct vmxon Haozhong Zhang
2016-12-16 13:43 ` [XTF PATCH 13/16] vvmx: test vmxon in VMX root w/ CPL = 0 and w/o current VMCS Haozhong Zhang
2016-12-16 13:43 ` [XTF PATCH 14/16] vvmx: test vmxon in VMX root w/ CPL = 3 " Haozhong Zhang
2016-12-16 20:59   ` Andrew Cooper
2016-12-19  3:46     ` Haozhong Zhang
2016-12-19 16:07       ` Andrew Cooper
2016-12-20  2:50         ` Haozhong Zhang
2016-12-16 13:43 ` [XTF PATCH 15/16] vvmx: test vmxon in VMX root w/ CPL = 0 and w/ " Haozhong Zhang
2016-12-16 13:43 ` [XTF PATCH 16/16] vvmx: test vmxon in VMX root w/ CPL = 3 " Haozhong Zhang
2016-12-16 14:12 ` [XTF PATCH 00/16] Add test cases for nested vmxon Andrew Cooper
2016-12-19  1:44   ` Haozhong Zhang
2016-12-19 16:18     ` Andrew Cooper
2016-12-16 21:26 ` Andrew Cooper
2016-12-19  5:31   ` Haozhong Zhang
2016-12-19 16:34     ` Andrew Cooper
2016-12-20  2:32       ` Haozhong Zhang

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=20161216134348.16236-3-haozhong.zhang@intel.com \
    --to=haozhong.zhang@intel.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /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).