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>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
	Wei Liu <wei.liu2@citrix.com>, Jan Beulich <jbeulich@suse.com>
Subject: [PATCH v2 06/12] x86emul: use msr definitions in msr-index.h
Date: Tue, 31 Jan 2017 11:08:03 +0000	[thread overview]
Message-ID: <20170131110809.30001-7-wei.liu2@citrix.com> (raw)
In-Reply-To: <20170131110809.30001-1-wei.liu2@citrix.com>

Change the names used in code according to numeric values. Remove the
now unused macros in x86_emualte.c and fix indentation. This in turns
requires including msr-index.h  and removing duplicates in userspace
x86_emulate.c in userspace harness program.

No functional change.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
Cc: Jan Beulich <jbeulich@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
---
 tools/tests/x86_emulator/x86_emulate.c |  3 ---
 tools/tests/x86_emulator/x86_emulate.h |  1 +
 xen/arch/x86/x86_emulate/x86_emulate.c | 43 ++++++++++++----------------------
 3 files changed, 16 insertions(+), 31 deletions(-)

diff --git a/tools/tests/x86_emulator/x86_emulate.c b/tools/tests/x86_emulator/x86_emulate.c
index 615326259b..cda0fd8ee1 100644
--- a/tools/tests/x86_emulator/x86_emulate.c
+++ b/tools/tests/x86_emulator/x86_emulate.c
@@ -2,9 +2,6 @@
 
 #include <sys/mman.h>
 
-#define EFER_SCE       (1 << 0)
-#define EFER_LMA       (1 << 10)
-
 #define cpu_has_amd_erratum(nr) 0
 #define mark_regs_dirty(r) ((void)(r))
 #define cpu_has_mpx false
diff --git a/tools/tests/x86_emulator/x86_emulate.h b/tools/tests/x86_emulator/x86_emulate.h
index 0046514220..b64c09968f 100644
--- a/tools/tests/x86_emulator/x86_emulate.h
+++ b/tools/tests/x86_emulator/x86_emulate.h
@@ -8,6 +8,7 @@
 
 #include "../../../xen/include/asm-x86/x86-defns.h"
 #include "../../../xen/include/asm-x86/x86-vendors.h"
+#include "../../../xen/include/asm-x86/msr-index.h"
 
 #define BUG() abort()
 #define ASSERT assert
diff --git a/xen/arch/x86/x86_emulate/x86_emulate.c b/xen/arch/x86/x86_emulate/x86_emulate.c
index 1d2d019cc7..695e450141 100644
--- a/xen/arch/x86/x86_emulate/x86_emulate.c
+++ b/xen/arch/x86/x86_emulate/x86_emulate.c
@@ -415,23 +415,6 @@ typedef union {
 # define ASM_FLAG_OUT(yes, no) no
 #endif
 
-/* MSRs. */
-#define MSR_TSC          0x00000010
-#define MSR_SYSENTER_CS  0x00000174
-#define MSR_SYSENTER_ESP 0x00000175
-#define MSR_SYSENTER_EIP 0x00000176
-#define MSR_DEBUGCTL     0x000001d9
-#define DEBUGCTL_BTF     (1 << 1)
-#define MSR_BNDCFGS      0x00000d90
-#define BNDCFG_ENABLE    (1 << 0)
-#define BNDCFG_PRESERVE  (1 << 1)
-#define MSR_EFER         0xc0000080
-#define MSR_STAR         0xc0000081
-#define MSR_LSTAR        0xc0000082
-#define MSR_CSTAR        0xc0000083
-#define MSR_FMASK        0xc0000084
-#define MSR_TSC_AUX      0xc0000103
-
 /* Control register flags. */
 #define CR0_PE    (1<<0)
 #define CR0_MP    (1<<1)
@@ -1731,8 +1714,8 @@ static bool is_branch_step(struct x86_emulate_ctxt *ctxt,
     uint64_t debugctl;
 
     return ops->read_msr &&
-           ops->read_msr(MSR_DEBUGCTL, &debugctl, ctxt) == X86EMUL_OKAY &&
-           (debugctl & DEBUGCTL_BTF);
+           ops->read_msr(MSR_IA32_DEBUGCTLMSR, &debugctl, ctxt) == X86EMUL_OKAY &&
+           (debugctl & IA32_DEBUGCTLMSR_BTF);
 }
 
 static bool umip_active(struct x86_emulate_ctxt *ctxt,
@@ -1894,9 +1877,9 @@ static void adjust_bnd(struct x86_emulate_ctxt *ctxt,
     if ( !mode_ring0() )
         bndcfg = read_bndcfgu();
     else if ( !ops->read_msr ||
-              ops->read_msr(MSR_BNDCFGS, &bndcfg, ctxt) != X86EMUL_OKAY )
+              ops->read_msr(MSR_IA32_BNDCFGS, &bndcfg, ctxt) != X86EMUL_OKAY )
         return;
-    if ( (bndcfg & BNDCFG_ENABLE) && !(bndcfg & BNDCFG_PRESERVE) )
+    if ( (bndcfg & IA32_BNDCFGS_ENABLE) && !(bndcfg & IA32_BNDCFGS_PRESERVE) )
     {
         /*
          * Using BNDMK or any other MPX instruction here is pointless, as
@@ -4983,7 +4966,7 @@ x86_emulate(
                 goto done;
             _regs.rip = msr_content;
 
-            if ( (rc = ops->read_msr(MSR_FMASK, &msr_content, ctxt)) != 0 )
+            if ( (rc = ops->read_msr(MSR_SYSCALL_MASK, &msr_content, ctxt)) != 0 )
                 goto done;
             _regs._eflags &= ~(msr_content | X86_EFLAGS_RF);
         }
@@ -5009,7 +4992,7 @@ x86_emulate(
          * As the #DB is raised after the CPL change and before the OS can
          * switch stack, it is a large risk for privilege escalation.
          *
-         * 64bit kernels should mask X86_EFLAGS_TF in MSR_FMASK to avoid any
+         * 64bit kernels should mask X86_EFLAGS_TF in MSR_SYSCALL_MASK to avoid any
          * vulnerability.  Running the #DB handler on an IST stack is also a
          * mitigation.
          *
@@ -5207,7 +5190,7 @@ x86_emulate(
             generate_exception_if(cr4 & CR4_TSD, EXC_GP, 0);
         }
         fail_if(ops->read_msr == NULL);
-        if ( (rc = ops->read_msr(MSR_TSC, &val, ctxt)) != 0 )
+        if ( (rc = ops->read_msr(MSR_IA32_TSC, &val, ctxt)) != 0 )
             goto done;
         _regs.r(dx) = val >> 32;
         _regs.r(ax) = (uint32_t)val;
@@ -5240,7 +5223,8 @@ x86_emulate(
         generate_exception_if(!in_protmode(ctxt, ops), EXC_GP, 0);
 
         fail_if(ops->read_msr == NULL);
-        if ( (rc = ops->read_msr(MSR_SYSENTER_CS, &msr_content, ctxt)) != 0 )
+        if ( (rc = ops->read_msr(MSR_IA32_SYSENTER_CS, &msr_content, ctxt))
+             != 0 )
             goto done;
 
         generate_exception_if(!(msr_content & 0xfffc), EXC_GP, 0);
@@ -5266,11 +5250,13 @@ x86_emulate(
              (rc = ops->write_segment(x86_seg_ss, &sreg, ctxt)) != 0 )
             goto done;
 
-        if ( (rc = ops->read_msr(MSR_SYSENTER_EIP, &msr_content, ctxt)) != 0 )
+        if ( (rc = ops->read_msr(MSR_IA32_SYSENTER_EIP, &msr_content, ctxt))
+             != 0 )
             goto done;
         _regs.r(ip) = lm ? msr_content : (uint32_t)msr_content;
 
-        if ( (rc = ops->read_msr(MSR_SYSENTER_ESP, &msr_content, ctxt)) != 0 )
+        if ( (rc = ops->read_msr(MSR_IA32_SYSENTER_ESP, &msr_content, ctxt))
+             != 0 )
             goto done;
         _regs.r(sp) = lm ? msr_content : (uint32_t)msr_content;
 
@@ -5287,7 +5273,8 @@ x86_emulate(
         generate_exception_if(!in_protmode(ctxt, ops), EXC_GP, 0);
 
         fail_if(ops->read_msr == NULL);
-        if ( (rc = ops->read_msr(MSR_SYSENTER_CS, &msr_content, ctxt)) != 0 )
+        if ( (rc = ops->read_msr(MSR_IA32_SYSENTER_CS, &msr_content, ctxt))
+             != 0 )
             goto done;
 
         generate_exception_if(!(msr_content & 0xfffc), EXC_GP, 0);
-- 
2.11.0


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

  parent reply	other threads:[~2017-01-31 11:08 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-31 11:07 [PATCH v2 00/12] fuzz: update x86emul fuzzer Wei Liu
2017-01-31 11:07 ` [PATCH v2 01/12] fuzz: don't buffer stdout in afl stubs Wei Liu
2017-01-31 12:44   ` Jan Beulich
2017-01-31 11:07 ` [PATCH v2 02/12] x86: extract macros to x86-defns.h Wei Liu
2017-01-31 12:45   ` Jan Beulich
2017-01-31 13:28     ` Wei Liu
2017-01-31 11:08 ` [PATCH v2 03/12] x86: extract vendor numeric id to x86-vendors.h Wei Liu
2017-01-31 12:48   ` Jan Beulich
2017-01-31 11:08 ` [PATCH v2 04/12] x86emul/test: use x86-vendors.h Wei Liu
2017-01-31 12:50   ` Jan Beulich
2017-01-31 14:36     ` Wei Liu
2017-01-31 15:16       ` Jan Beulich
2017-01-31 15:16         ` Wei Liu
2017-01-31 11:08 ` [PATCH v2 05/12] x86emul: use eflags definitions in x86-defns.h Wei Liu
2017-01-31 12:56   ` Jan Beulich
2017-01-31 14:55     ` Wei Liu
2017-01-31 15:16       ` Jan Beulich
2017-01-31 11:08 ` Wei Liu [this message]
2017-01-31 12:59   ` [PATCH v2 06/12] x86emul: use msr definitions in msr-index.h Jan Beulich
2017-01-31 11:08 ` [PATCH v2 07/12] x86: add UMIP CR4 bit Wei Liu
2017-01-31 13:00   ` Jan Beulich
2017-01-31 11:08 ` [PATCH v2 08/12] x86emul: use CR definitions in x86-defns.h Wei Liu
2017-01-31 13:01   ` Jan Beulich
2017-01-31 11:08 ` [PATCH v2 09/12] x86emul: use TRAP " Wei Liu
2017-01-31 11:26   ` Andrew Cooper
2017-01-31 11:08 ` [PATCH v2 10/12] fuzz/x86emul: update fuzzer Wei Liu
2017-01-31 13:33   ` Jan Beulich
2017-01-31 15:51     ` Wei Liu
2017-01-31 15:57       ` Andrew Cooper
2017-01-31 16:01         ` George Dunlap
2017-01-31 16:05         ` Jan Beulich
2017-01-31 16:02       ` Jan Beulich
2017-01-31 17:37         ` Wei Liu
2017-01-31 11:08 ` [PATCH v2 11/12] fuzz/x86emul: print out minimal input size Wei Liu
2017-01-31 13:33   ` Jan Beulich
2017-01-31 11:08 ` [PATCH v2 12/12] fuzz: update README.afl example Wei Liu
2017-01-31 13:34   ` Jan Beulich

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=20170131110809.30001-7-wei.liu2@citrix.com \
    --to=wei.liu2@citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=jbeulich@suse.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).