Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752339AbbDDKKP (ORCPT ); Sat, 4 Apr 2015 06:10:15 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:18403 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752026AbbDDKKO (ORCPT ); Sat, 4 Apr 2015 06:10:14 -0400 Date: Sat, 4 Apr 2015 12:11:55 +0200 From: Quentin Casasnovas To: Borislav Petkov Cc: Quentin Casasnovas , X86 ML , LKML , "H. Peter Anvin" , Ingo Molnar , Thomas Gleixner , Oleg Nesterov , Andy Lutomirski Subject: Re: [PATCH] x86/xsave: Robustify and merge macros Message-ID: <20150404101155.GB5922@chrystal.uk.oracle.com> References: <20150403141426.GE14902@chrystal.uk.oracle.com> <20150403152324.GG3418@pd.tnic> <20150403154055.GF14902@chrystal.uk.oracle.com> <20150403170625.GJ3418@pd.tnic> <20150403173306.GG14902@chrystal.uk.oracle.com> <20150403174824.GL3418@pd.tnic> <20150403204217.GH14902@chrystal.uk.oracle.com> <20150404073454.GA21152@pd.tnic> <20150404083611.GA5922@chrystal.uk.oracle.com> <20150404092536.GB21152@pd.tnic> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150404092536.GB21152@pd.tnic> User-Agent: Mutt/1.5.22 (2013-10-16) X-Source-IP: aserv0021.oracle.com [141.146.126.233] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2544 Lines: 67 On Sat, Apr 04, 2015 at 11:25:36AM +0200, Borislav Petkov wrote: > On Sat, Apr 04, 2015 at 10:36:11AM +0200, Quentin Casasnovas wrote: > > Since all of these are compile time constants, could we not use the safe > > variant on that same page? Not that I'm too worried about the signed right > > shift but heh that would be portable and should not impact performance > > anyway, so no added value in using the optimized version is there? > > Seems to work with the experimental diff below. I need to do > > -(-(x < y)) > > with the last term though as we're working with s32s. > > --- > diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h > index 44a1fc5439d3..2cb6da2716bf 100644 > --- a/arch/x86/include/asm/alternative-asm.h > +++ b/arch/x86/include/asm/alternative-asm.h > @@ -53,14 +53,14 @@ > * Shamelessly stolen and adapted from: > * http://graphics.stanford.edu/~seander/bithacks.html#IntegerMinOrMax > */ > -#define alt_max_short(a,b) (((a) - (((a) - (b)) & (((a) - (b)) >> 15))) & 0xffff) > +#define alt_max_short(a, b) ((a) ^ (((a) ^ (b)) & -(-((a) < (b))))) > So I'm not claiming I've spent the time to fully understand this macro but it looks like it's doing the right thing on my dummy tests: http://pastebin.com/DDhtZQgX Did you also change it in the alternative.h file BTW? > .macro ALTERNATIVE_2 oldinstr, newinstr1, feature1, newinstr2, feature2 > 140: > \oldinstr > 141: > - .skip -((alt_max_short(new_len1, new_len2) - old_len) > 0) * \ > - (alt_max_short(new_len1, new_len2) - old_len),0x90 > + .skip -((alt_max_short(new_len1, new_len2) - (old_len)) > 0) * \ > + (alt_max_short(new_len1, new_len2) - (old_len)),0x90 > 142: Good catch for the missing parenthesis! > > > > Looks good to me and I find it much easier to understand here :) > > > > Cool. Please give it more critical staring as we're under time pressure > here. > So I _think_ it's OK but it would be re-assuring if somebody else could have a look as well just in case.. :) Do you have a cleaned up version of the patch you're planning to apply on top of tip/master instead of just snippets? This way we can hammer it with different calls to ALTERNATIVE_2 and alternative_2 to check it's good? I'll have to leave soonish though.. Quentin -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/