From: "Jan Beulich" Subject: Re: [PATCH v8 2/7] x86: Clear AC bit in RFLAGS to protect Xen itself by SMAP Date: Fri, 09 May 2014 11:29:08 +0100 Message-ID: <536CCA140200007800010DE5@mail.emea.novell.com> References: <1399613682-5411-1-git-send-email-feng.wu@intel.com> <1399613682-5411-3-git-send-email-feng.wu@intel.com> <536CBCC00200007800010D2A@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <536CBCC00200007800010D2A@mail.emea.novell.com> Content-Disposition: inline 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 , Jan Beulich Cc: kevin.tian@intel.com, ian.campbell@citrix.com, andrew.cooper3@citrix.com, eddie.dong@intel.com, xen-devel@lists.xen.org, jun.nakajima@intel.com List-Id: xen-devel@lists.xenproject.org >>> On 09.05.14 at 11:32, wrote: >>>> On 09.05.14 at 07:34, wrote: >> --- a/xen/include/asm-x86/asm_defns.h >> +++ b/xen/include/asm-x86/asm_defns.h >> @@ -190,7 +190,12 @@ static inline void stac(void) >> #endif >> >> #ifdef __ASSEMBLY__ >> -.macro SAVE_ALL >> +.macro SAVE_ALL op=0 >> +.if \op == CLAC >> + ASM_CLAC >> +.elseif \op == STAC >> + ASM_STAC >> +.endif > > If this really works with all assembler versions we support, that's of > course fine; I wouldn't have thought this is being accepted by gas. Just tried it out - it sort of works, but leverages what as far as I know is undefined behavior: It ends up inserting undefined symbols CLAC and STAC into the symbol table, which the linker is free to error out on. So instead of (just giving the example I experimented with) .macro m1 a=0 .if \a == A .byte 1 .elseif \a == B .byte -1 .else .byte 0 .endif .endm please use .macro m2 a .ifeqs "\a", "A" .byte 2 .exitm .endif .ifeqs "\a", "B" .byte -2 .exitm .endif .ifnb \a .err .endif .endm (except of course you can't use .exitm directly in SAVE_ALL, i.e. you either need to use nested if/else constructs or a second helper macro. Yet another option would be to simply use the concatenation ASM_\a if \a is non-empty, but that would require ASM_STAC and ASM_CLAC to become assembler equates or some such rather than C preprocessor symbols. Jan