From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Cooper Subject: Re: [PATCH v6 04/10] x86: Add support for STAC/CLAC instructions Date: Wed, 7 May 2014 10:36:18 +0100 Message-ID: <5369FE92.2040602@citrix.com> References: <1399450782-14735-1-git-send-email-feng.wu@intel.com> <1399450782-14735-5-git-send-email-feng.wu@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1399450782-14735-5-git-send-email-feng.wu@intel.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Feng Wu Cc: kevin.tian@intel.com, ian.campbell@citrix.com, eddie.dong@intel.com, xen-devel@lists.xen.org, JBeulich@suse.com, jun.nakajima@intel.com List-Id: xen-devel@lists.xenproject.org On 07/05/14 09:19, Feng Wu wrote: > 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 Reviewed-by: Andrew Cooper > --- > 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 c4b2bb2..0302836 100644 > --- a/xen/include/asm-x86/asm_defns.h > +++ b/xen/include/asm-x86/asm_defns.h > @@ -8,6 +8,8 @@ > #endif > #include > #include > +#include > +#include > > #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