From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Cooper Subject: Re: [PATCH 3/3] x86: Use alternative mechanism to define CLAC/STAC Date: Mon, 26 May 2014 16:49:33 +0100 Message-ID: <5383628D.4000907@citrix.com> References: <1401089273-16425-1-git-send-email-feng.wu@intel.com> <1401089273-16425-4-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: <1401089273-16425-4-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 , xen-devel@lists.xen.org Cc: keir.xen@gmail.com, JBeulich@suse.com List-Id: xen-devel@lists.xenproject.org On 26/05/2014 08:27, Feng Wu wrote: > This patch use alternative mechanism to define CLAC/STAC. > > Signed-off-by: Feng Wu > --- > xen/include/asm-x86/asm_defns.h | 36 +++++++++++++++++++++++------------- > 1 file changed, 23 insertions(+), 13 deletions(-) > > diff --git a/xen/include/asm-x86/asm_defns.h b/xen/include/asm-x86/asm_defns.h > index 87a462f..92024cc 100644 > --- a/xen/include/asm-x86/asm_defns.h > +++ b/xen/include/asm-x86/asm_defns.h > @@ -10,6 +10,8 @@ > #include > #include > #include > +#include > +#include alternatives should include nops, to avoid needing a double include everywhere alternative() is used. > > #ifndef __ASSEMBLY__ > void ret_from_intr(void); > @@ -166,26 +168,34 @@ void ret_from_intr(void); > #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) > +#define ASM_CLAC \ > + 661: ASM_NOP3; \ > + .pushsection .altinstr_replacement, "ax"; \ The altinstr_replacement section doesn't need to be executable. The data inside it is copied out into the .text section. > + 662: __ASM_CLAC; \ > + .popsection; \ > + .pushsection .altinstructions, "a"; \ > + altinstruction_entry 661b, 662b, X86_FEATURE_SMAP, 3, 3; \ > + .popsection these 661s and 662s alias magic numbers in the alternatives core code, which could lead to subtle issues. Surely there is a better way than having to choose magic numbers which don't collide with anything else in the source. ~Andrew > + > +#define ASM_STAC \ > + 661: ASM_NOP3; \ > + .pushsection .altinstr_replacement, "ax"; \ > + 662: __ASM_STAC; \ > + .popsection; \ > + .pushsection .altinstructions, "a"; \ > + altinstruction_entry 661b, 662b, X86_FEATURE_SMAP, 3, 3; \ > + .popsection > #else > static inline void clac(void) > { > - if ( boot_cpu_has(X86_FEATURE_SMAP) ) > - asm volatile (__stringify(__ASM_CLAC) : : : "memory"); > + /* Note: a barrier is implicit in alternative() */ > + alternative(ASM_NOP3, __stringify(__ASM_CLAC), X86_FEATURE_SMAP); > } > > static inline void stac(void) > { > - if ( boot_cpu_has(X86_FEATURE_SMAP) ) > - asm volatile (__stringify(__ASM_STAC) : : : "memory"); > + /* Note: a barrier is implicit in alternative() */ > + alternative(ASM_NOP3, __stringify(__ASM_STAC), X86_FEATURE_SMAP); > } > #endif >