Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756152AbbGFNob (ORCPT ); Mon, 6 Jul 2015 09:44:31 -0400 Received: from mail-wi0-f177.google.com ([209.85.212.177]:34282 "EHLO mail-wi0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753816AbbGFNo3 (ORCPT ); Mon, 6 Jul 2015 09:44:29 -0400 Date: Mon, 6 Jul 2015 15:44:24 +0200 From: Ingo Molnar To: Andy Lutomirski Cc: linux-kernel@vger.kernel.org, x86@kernel.org, Linus Torvalds , Jan Kara , Borislav Petkov , Denys Vlasenko Subject: Re: [PATCH] x86: Fix detection of GCC -mpreferred-stack-boundary support Message-ID: <20150706134423.GA8094@gmail.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2680 Lines: 70 * Andy Lutomirski wrote: > As per https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383, GCC only > allows -mpreferred-stack-boundary=3 on x86_64 if -mno-sse is set. > That means that cc-option will not detect > -mpreferred-stack-boundary=3 support, because we test for it before > setting -mno-sse. > > Fix it by reordering the Makefile bits. > > Compile-tested only. This should help avoid code generation issues > such as the one that was worked around in b96fecbfa8c8 ("x86/fpu: > Fix boot crash in the early FPU code"). > > I'm a bit concerned that we could still have problems on older GCC > versions given that our asm code does not respect GCC's idea of the > ABI-required stack alignment. > > Cc: Linus Torvalds > Cc: Jan Kara > Cc: Ingo Molnar > Cc: Borislav Petkov > Signed-off-by: Andy Lutomirski > --- > arch/x86/Makefile | 9 ++++++--- > 1 file changed, 6 insertions(+), 3 deletions(-) > > diff --git a/arch/x86/Makefile b/arch/x86/Makefile > index 118e6debc483..344dd2110b2a 100644 > --- a/arch/x86/Makefile > +++ b/arch/x86/Makefile > @@ -39,6 +39,12 @@ ifdef CONFIG_X86_NEED_RELOCS > LDFLAGS_vmlinux := --emit-relocs > endif > > +# prevent gcc from generating any FP code by mistake > +# This must be before we try -mpreferred-stack-boundary -- see > +# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383 > +KBUILD_CFLAGS += -mno-sse -mno-mmx -mno-sse2 -mno-3dnow > +KBUILD_CFLAGS += $(call cc-option,-mno-avx,) > + So the 'stack boundary' is the RSP that GCC generates before it calls another function from within an existing function, right? So looking at this I question the choice of -mpreferred-stack-boundary=3. Why not do -mpreferred-stack-boundary=2? My reasoning: on modern uarchs there's no penalty for 32-bit misalignment of 64-bit variables, only if they cross 64-byte cache lines, which should be rare with a chance of 1:16. This small penalty (of at most +1 cycle in some circumstances IIRC) should be more than counterbalanced by the compression of the stack by 5% on average. ... using stack-boundary=1 or stack-boundary=0 would probably be counterproductive, as these more exotic misalignments get treated progressively worse by x86 CPUs. ... but I have not measured any of this and even the 5% is just a possibly overoptimistic guess. Thanks, Ingo -- 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/