All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Matthias Kaehlcke <mka@chromium.org>,
	Ingo Molnar <mingo@kernel.org>,
	Masahiro Yamada <yamada.masahiro@socionext.com>,
	Nick Desaulniers <ndesaulniers@google.com>
Subject: [PATCH 4.9 24/59] x86/build: Specify stack alignment for clang
Date: Wed, 21 Nov 2018 20:06:39 +0100	[thread overview]
Message-ID: <20181121183509.210549454@linuxfoundation.org> (raw)
In-Reply-To: <20181121183508.262873520@linuxfoundation.org>

4.9-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Matthias Kaehlcke <mka@chromium.org>

commit d77698df39a512911586834d303275ea5fda74d0 upstream.

For gcc stack alignment is configured with -mpreferred-stack-boundary=N,
clang has the option -mstack-alignment=N for that purpose. Use the same
alignment as with gcc.

If the alignment is not specified clang assumes an alignment of
16 bytes, as required by the standard ABI. However as mentioned in
d9b0cde91c60 ("x86-64, gcc: Use -mpreferred-stack-boundary=3 if
supported") the standard kernel entry on x86-64 leaves the stack
on an 8-byte boundary, as a consequence clang will keep the stack
misaligned.

Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
Acked-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 arch/x86/Makefile |   26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -11,6 +11,14 @@ else
         KBUILD_DEFCONFIG := $(ARCH)_defconfig
 endif
 
+# For gcc stack alignment is specified with -mpreferred-stack-boundary,
+# clang has the option -mstack-alignment for that purpose.
+ifneq ($(call cc-option, -mpreferred-stack-boundary=4),)
+        cc_stack_align_opt := -mpreferred-stack-boundary
+else ifneq ($(call cc-option, -mstack-alignment=4),)
+        cc_stack_align_opt := -mstack-alignment
+endif
+
 # How to compile the 16-bit code.  Note we always compile for -march=i386;
 # that way we can complain to the user if the CPU is insufficient.
 #
@@ -28,7 +36,7 @@ REALMODE_CFLAGS	:= $(M16_CFLAGS) -g -Os
 
 REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -ffreestanding)
 REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -fno-stack-protector)
-REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -mpreferred-stack-boundary=2)
+REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), $(cc_stack_align_opt)=2)
 export REALMODE_CFLAGS
 
 # BITS is used as extension for files which are available in a 32 bit
@@ -65,8 +73,10 @@ ifeq ($(CONFIG_X86_32),y)
         # with nonstandard options
         KBUILD_CFLAGS += -fno-pic
 
-        # prevent gcc from keeping the stack 16 byte aligned
-        KBUILD_CFLAGS += $(call cc-option,-mpreferred-stack-boundary=2)
+        # Align the stack to the register width instead of using the default
+        # alignment of 16 bytes. This reduces stack usage and the number of
+        # alignment instructions.
+        KBUILD_CFLAGS += $(call cc-option,$(cc_stack_align_opt)=2)
 
         # Disable unit-at-a-time mode on pre-gcc-4.0 compilers, it makes gcc use
         # a lot more stack due to the lack of sharing of stacklots:
@@ -98,8 +108,14 @@ else
         KBUILD_CFLAGS += $(call cc-option,-mno-80387)
         KBUILD_CFLAGS += $(call cc-option,-mno-fp-ret-in-387)
 
-	# Use -mpreferred-stack-boundary=3 if supported.
-	KBUILD_CFLAGS += $(call cc-option,-mpreferred-stack-boundary=3)
+        # By default gcc and clang use a stack alignment of 16 bytes for x86.
+        # However the standard kernel entry on x86-64 leaves the stack on an
+        # 8-byte boundary. If the compiler isn't informed about the actual
+        # alignment it will generate extra alignment instructions for the
+        # default alignment which keep the stack *mis*aligned.
+        # Furthermore an alignment to the register width reduces stack usage
+        # and the number of alignment instructions.
+        KBUILD_CFLAGS += $(call cc-option,$(cc_stack_align_opt)=3)
 
 	# Use -mskip-rax-setup if supported.
 	KBUILD_CFLAGS += $(call cc-option,-mskip-rax-setup)



  parent reply	other threads:[~2018-11-21 19:10 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-21 19:06 [PATCH 4.9 00/59] 4.9.139-stable review Greg Kroah-Hartman
2018-11-21 19:06 ` [PATCH 4.9 01/59] flow_dissector: do not dissect l4 ports for fragments Greg Kroah-Hartman
2018-11-21 19:06 ` [PATCH 4.9 02/59] ibmvnic: fix accelerated VLAN handling Greg Kroah-Hartman
2018-11-21 19:06 ` [PATCH 4.9 03/59] ip_tunnel: dont force DF when MTU is locked Greg Kroah-Hartman
2018-11-21 19:06 ` [PATCH 4.9 04/59] net-gro: reset skb->pkt_type in napi_reuse_skb() Greg Kroah-Hartman
2018-11-21 19:06 ` [PATCH 4.9 05/59] sctp: not allow to set asoc prsctp_enable by sockopt Greg Kroah-Hartman
2018-11-21 19:06 ` [PATCH 4.9 06/59] tg3: Add PHY reset for 5717/5719/5720 in change ring and flow control paths Greg Kroah-Hartman
2018-11-21 19:06 ` [PATCH 4.9 07/59] usbnet: smsc95xx: disable carrier check while suspending Greg Kroah-Hartman
2018-11-21 19:06 ` [PATCH 4.9 08/59] inet: frags: better deal with smp races Greg Kroah-Hartman
2018-11-21 19:06 ` [PATCH 4.9 09/59] ipv6: Fix PMTU updates for UDP/raw sockets in presence of VRF Greg Kroah-Hartman
2018-11-21 19:06 ` [PATCH 4.9 10/59] kbuild: Add better clang cross build support Greg Kroah-Hartman
2018-11-21 19:06 ` [PATCH 4.9 11/59] kbuild: clang: add -no-integrated-as to KBUILD_[AC]FLAGS Greg Kroah-Hartman
2018-11-21 19:06 ` [PATCH 4.9 12/59] kbuild: Consolidate header generation from ASM offset information Greg Kroah-Hartman
2018-11-21 19:06 ` [PATCH 4.9 13/59] kbuild: consolidate redundant sed script ASM offset generation Greg Kroah-Hartman
2018-11-21 19:06 ` [PATCH 4.9 14/59] kbuild: fix asm-offset generation to work with clang Greg Kroah-Hartman
2018-11-21 19:06 ` [PATCH 4.9 15/59] kbuild: drop -Wno-unknown-warning-option from clang options Greg Kroah-Hartman
2018-11-21 19:06 ` [PATCH 4.9 16/59] kbuild, LLVMLinux: Add -Werror to cc-option to support clang Greg Kroah-Hartman
2018-11-21 19:06 ` [PATCH 4.9 17/59] kbuild: use -Oz instead of -Os when using clang Greg Kroah-Hartman
2018-11-21 19:06 ` [PATCH 4.9 18/59] kbuild: Add support to generate LLVM assembly files Greg Kroah-Hartman
2018-11-21 19:06 ` [PATCH 4.9 19/59] modules: mark __inittest/__exittest as __maybe_unused Greg Kroah-Hartman
2018-11-21 19:06 ` [PATCH 4.9 20/59] x86/kbuild: Use cc-option to enable -falign-{jumps/loops} Greg Kroah-Hartman
2018-11-21 19:06 ` [PATCH 4.9 21/59] crypto, x86: aesni - fix token pasting for clang Greg Kroah-Hartman
2018-11-21 19:06 ` [PATCH 4.9 22/59] kbuild: Add __cc-option macro Greg Kroah-Hartman
2018-11-21 19:06 ` [PATCH 4.9 23/59] x86/build: Use __cc-option for boot code compiler options Greg Kroah-Hartman
2018-11-21 19:06 ` Greg Kroah-Hartman [this message]
2018-11-21 19:06 ` [PATCH 4.9 25/59] kbuild: clang: Disable address-of-packed-member warning Greg Kroah-Hartman
2018-11-21 19:06 ` [PATCH 4.9 26/59] crypto: arm64/sha - avoid non-standard inline asm tricks Greg Kroah-Hartman
2018-11-21 19:06 ` [PATCH 4.9 27/59] x86/boot: #undef memcpy() et al in string.c Greg Kroah-Hartman
2018-11-21 19:06 ` [PATCH 4.9 28/59] efi/libstub/arm64: Use hidden attribute for struct screen_info reference Greg Kroah-Hartman
2018-11-21 19:06 ` [PATCH 4.9 29/59] efi/libstub/arm64: Force hidden visibility for section markers Greg Kroah-Hartman
2018-11-21 19:06 ` [PATCH 4.9 30/59] efi/libstub: Preserve .debug sections after absolute relocation check Greg Kroah-Hartman
2018-11-21 19:06 ` [PATCH 4.9 31/59] efi/libstub/arm64: Set -fpie when building the EFI stub Greg Kroah-Hartman
2018-11-21 19:06 ` [PATCH 4.9 32/59] x86/build: Fix stack alignment for CLang Greg Kroah-Hartman
2018-11-21 19:06 ` [PATCH 4.9 33/59] x86/build: Use cc-option to validate stack alignment parameter Greg Kroah-Hartman
2018-11-21 19:06 ` [PATCH 4.9 34/59] Kbuild: use -fshort-wchar globally Greg Kroah-Hartman
2018-11-21 19:06 ` [PATCH 4.9 35/59] arm64: uaccess: suppress spurious clang warning Greg Kroah-Hartman
2018-11-21 19:06 ` [PATCH 4.9 36/59] ARM: add more CPU part numbers for Cortex and Brahma B15 CPUs Greg Kroah-Hartman
2018-11-21 19:06 ` [PATCH 4.9 37/59] ARM: bugs: prepare processor bug infrastructure Greg Kroah-Hartman
2018-11-21 19:06 ` [PATCH 4.9 38/59] ARM: bugs: hook processor bug checking into SMP and suspend paths Greg Kroah-Hartman
2018-11-21 19:06 ` [PATCH 4.9 39/59] ARM: bugs: add support for per-processor bug checking Greg Kroah-Hartman
2018-11-21 19:06 ` [PATCH 4.9 40/59] ARM: spectre: add Kconfig symbol for CPUs vulnerable to Spectre Greg Kroah-Hartman
2018-11-21 19:06 ` [PATCH 4.9 41/59] ARM: spectre-v2: harden branch predictor on context switches Greg Kroah-Hartman
2018-11-21 19:06 ` [PATCH 4.9 42/59] ARM: spectre-v2: add Cortex A8 and A15 validation of the IBE bit Greg Kroah-Hartman
2018-11-21 19:06 ` [PATCH 4.9 43/59] ARM: spectre-v2: harden user aborts in kernel space Greg Kroah-Hartman
2018-11-21 19:06 ` [PATCH 4.9 44/59] ARM: spectre-v2: add firmware based hardening Greg Kroah-Hartman
2018-11-21 19:07 ` [PATCH 4.9 45/59] ARM: spectre-v2: warn about incorrect context switching functions Greg Kroah-Hartman
2018-11-21 19:07 ` [PATCH 4.9 46/59] ARM: KVM: invalidate BTB on guest exit for Cortex-A12/A17 Greg Kroah-Hartman
2018-11-21 19:07 ` [PATCH 4.9 47/59] ARM: KVM: invalidate icache on guest exit for Cortex-A15 Greg Kroah-Hartman
2018-11-21 19:07 ` [PATCH 4.9 48/59] ARM: spectre-v2: KVM: invalidate icache on guest exit for Brahma B15 Greg Kroah-Hartman
2018-11-21 19:07 ` [PATCH 4.9 49/59] ARM: KVM: Add SMCCC_ARCH_WORKAROUND_1 fast handling Greg Kroah-Hartman
2018-11-21 19:07 ` [PATCH 4.9 50/59] ARM: KVM: report support for SMCCC_ARCH_WORKAROUND_1 Greg Kroah-Hartman
2018-11-21 19:07 ` [PATCH 4.9 51/59] ARM: spectre-v1: add speculation barrier (csdb) macros Greg Kroah-Hartman
2018-11-21 19:07 ` [PATCH 4.9 52/59] ARM: spectre-v1: add array_index_mask_nospec() implementation Greg Kroah-Hartman
2018-11-21 19:07 ` [PATCH 4.9 53/59] ARM: spectre-v1: fix syscall entry Greg Kroah-Hartman
2018-11-21 19:07 ` [PATCH 4.9 54/59] ARM: signal: copy registers using __copy_from_user() Greg Kroah-Hartman
2018-11-21 19:07 ` [PATCH 4.9 55/59] ARM: vfp: use __copy_from_user() when restoring VFP state Greg Kroah-Hartman
2018-11-21 19:07 ` [PATCH 4.9 56/59] ARM: oabi-compat: copy semops using __copy_from_user() Greg Kroah-Hartman
2018-11-21 19:07 ` [PATCH 4.9 57/59] ARM: use __inttype() in get_user() Greg Kroah-Hartman
2018-11-21 19:07 ` [PATCH 4.9 58/59] ARM: spectre-v1: use get_user() for __get_user() Greg Kroah-Hartman
2018-11-21 19:07 ` [PATCH 4.9 59/59] ARM: spectre-v1: mitigate user accesses Greg Kroah-Hartman
2018-11-22  4:58 ` [PATCH 4.9 00/59] 4.9.139-stable review kernelci.org bot
2018-11-22 16:33 ` Guenter Roeck
2018-11-22 18:07   ` Murilo Fossa Vicentini
2018-11-22 19:49     ` Guenter Roeck
2018-11-22 20:16       ` Murilo Fossa Vicentini
2018-11-23  7:15       ` Greg Kroah-Hartman
2018-11-23  7:16 ` Naresh Kamboju
2018-11-23  7:28   ` Greg Kroah-Hartman
2018-11-23  9:57 ` Jon Hunter
2018-11-23  9:57   ` Jon Hunter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181121183509.210549454@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=mka@chromium.org \
    --cc=ndesaulniers@google.com \
    --cc=stable@vger.kernel.org \
    --cc=yamada.masahiro@socionext.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.