From: Feng Wu <feng.wu@intel.com>
To: xen-devel@lists.xen.org
Cc: kevin.tian@intel.com, Feng Wu <feng.wu@intel.com>,
JBeulich@suse.com, andrew.cooper3@citrix.com,
eddie.dong@intel.com, jun.nakajima@intel.com,
ian.campbell@citrix.com
Subject: [PATCH v9 1/7] x86: Add support for STAC/CLAC instructions
Date: Mon, 12 May 2014 14:27:35 +0800 [thread overview]
Message-ID: <1399876061-28158-2-git-send-email-feng.wu@intel.com> (raw)
In-Reply-To: <1399876061-28158-1-git-send-email-feng.wu@intel.com>
The STAC/CLAC instructions are only available when SMAP feature is
available, but on the other hand they aren't needed if SMAP is not
enabled, or before we start to run userspace, in that case, the
functions and macros do nothing.
Signed-off-by: Feng Wu <feng.wu@intel.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
xen/include/asm-x86/asm_defns.h | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/xen/include/asm-x86/asm_defns.h b/xen/include/asm-x86/asm_defns.h
index db4a778..b75905a 100644
--- a/xen/include/asm-x86/asm_defns.h
+++ b/xen/include/asm-x86/asm_defns.h
@@ -8,6 +8,8 @@
#endif
#include <asm/processor.h>
#include <asm/percpu.h>
+#include <xen/stringify.h>
+#include <asm/cpufeature.h>
#ifndef __ASSEMBLY__
void ret_from_intr(void);
@@ -159,6 +161,34 @@ void ret_from_intr(void);
#endif
+/* "Raw" instruction opcodes */
+#define __ASM_CLAC .byte 0x0f,0x01,0xca
+#define __ASM_STAC .byte 0x0f,0x01,0xcb
+
+#ifdef __ASSEMBLY__
+#define ASM_AC(op) \
+ btl $X86_FEATURE_SMAP & 31, \
+ CPUINFO_FEATURE_OFFSET(X86_FEATURE_SMAP)+boot_cpu_data(%rip); \
+ jnc 881f; \
+ __ASM_##op; \
+881:
+
+#define ASM_STAC ASM_AC(STAC)
+#define ASM_CLAC ASM_AC(CLAC)
+#else
+static inline void clac(void)
+{
+ if ( boot_cpu_has(X86_FEATURE_SMAP) )
+ asm volatile (__stringify(__ASM_CLAC) : : : "memory");
+}
+
+static inline void stac(void)
+{
+ if ( boot_cpu_has(X86_FEATURE_SMAP) )
+ asm volatile (__stringify(__ASM_STAC) : : : "memory");
+}
+#endif
+
#ifdef __ASSEMBLY__
.macro SAVE_ALL
addq $-(UREGS_error_code-UREGS_r15), %rsp
--
1.8.3.1
next prev parent reply other threads:[~2014-05-12 6:27 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-12 6:27 [PATCH v9 0/7] x86: Enable Supervisor Mode Access Prevention (SMAP) Feng Wu
2014-05-12 6:27 ` Feng Wu [this message]
2014-05-12 6:27 ` [PATCH v9 2/7] x86: Clear AC bit in RFLAGS to protect Xen itself by SMAP Feng Wu
2014-05-12 14:04 ` Andrew Cooper
2014-05-12 6:27 ` [PATCH v9 3/7] x86: Temporary disable SMAP to legally access user pages in kernel mode Feng Wu
2014-05-12 6:27 ` [PATCH v9 4/7] VMX: Disable SMAP feature when guest is in non-paging mode Feng Wu
2014-05-12 6:27 ` [PATCH v9 5/7] x86: Enable Supervisor Mode Access Prevention (SMAP) for Xen Feng Wu
2014-05-12 6:27 ` [PATCH v9 6/7] x86/hvm: Add SMAP support to HVM guest Feng Wu
2014-05-12 6:27 ` [PATCH v9 7/7] x86/tools: Expose SMAP to HVM guests Feng Wu
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=1399876061-28158-2-git-send-email-feng.wu@intel.com \
--to=feng.wu@intel.com \
--cc=JBeulich@suse.com \
--cc=andrew.cooper3@citrix.com \
--cc=eddie.dong@intel.com \
--cc=ian.campbell@citrix.com \
--cc=jun.nakajima@intel.com \
--cc=kevin.tian@intel.com \
--cc=xen-devel@lists.xen.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).