All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/build: Use cc-option to validate stack alignment parameter
@ 2017-08-17 18:20 Matthias Kaehlcke
  2017-08-21  7:53 ` Ingo Molnar
  2017-08-21  9:20 ` [tip:x86/build] " tip-bot for Matthias Kaehlcke
  0 siblings, 2 replies; 3+ messages in thread
From: Matthias Kaehlcke @ 2017-08-17 18:20 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, H . Peter Anvin, Masahiro Yamada
  Cc: x86, linux-kernel, dianders, Michael Davidson, Greg Hackmann,
	Nick Desaulniers, Stephen Hines, Kees Cook, Arnd Bergmann,
	Bernhard.Rosenkranzer, Matthias Kaehlcke

With 8f91869766c0 ("x86/build: Fix stack alignment for CLang") cc-option
is only used to determine the name of the stack alignment option supported
by the compiler, but not to verify that the actual parameter <option>=N is
valid in combination with the other CFLAGS. This causes problems with older
gcc versions which only support stack alignment on a boundary of 16 bytes
or higher.

Also use (__)cc_option to add the stack alignment option to CFLAGS to
make sure only valid options are added.

Fixes: 8f91869766c0 ("x86/build: Fix stack alignment for CLang")
Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
---
 arch/x86/Makefile | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 65ed359eb904..9231bbfae670 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -38,7 +38,7 @@ REALMODE_CFLAGS	:= $(M16_CFLAGS) -g -Os -D__KERNEL__ \
 
 REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -ffreestanding)
 REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -fno-stack-protector)
-REALMODE_CFLAGS += $(cc_stack_align4)
+REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), $(cc_stack_align4))
 export REALMODE_CFLAGS
 
 # BITS is used as extension for files which are available in a 32 bit
@@ -78,7 +78,7 @@ ifeq ($(CONFIG_X86_32),y)
         # 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 += $(cc_stack_align4)
+        KBUILD_CFLAGS += $(call cc-option,$(cc_stack_align4))
 
         # 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:
@@ -117,7 +117,7 @@ else
         # 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 += $(cc_stack_align8)
+        KBUILD_CFLAGS += $(call cc-option,$(cc_stack_align8))
 
 	# Use -mskip-rax-setup if supported.
 	KBUILD_CFLAGS += $(call cc-option,-mskip-rax-setup)
-- 
2.14.1.480.gb18f417b89-goog

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] x86/build: Use cc-option to validate stack alignment parameter
  2017-08-17 18:20 [PATCH] x86/build: Use cc-option to validate stack alignment parameter Matthias Kaehlcke
@ 2017-08-21  7:53 ` Ingo Molnar
  2017-08-21  9:20 ` [tip:x86/build] " tip-bot for Matthias Kaehlcke
  1 sibling, 0 replies; 3+ messages in thread
From: Ingo Molnar @ 2017-08-21  7:53 UTC (permalink / raw)
  To: Matthias Kaehlcke
  Cc: Thomas Gleixner, Ingo Molnar, H . Peter Anvin, Masahiro Yamada,
	x86, linux-kernel, dianders, Michael Davidson, Greg Hackmann,
	Nick Desaulniers, Stephen Hines, Kees Cook, Arnd Bergmann,
	Bernhard.Rosenkranzer


* Matthias Kaehlcke <mka@chromium.org> wrote:

> With 8f91869766c0 ("x86/build: Fix stack alignment for CLang") cc-option
> is only used to determine the name of the stack alignment option supported
> by the compiler, but not to verify that the actual parameter <option>=N is
> valid in combination with the other CFLAGS. This causes problems with older
> gcc versions which only support stack alignment on a boundary of 16 bytes
> or higher.
> 
> Also use (__)cc_option to add the stack alignment option to CFLAGS to
> make sure only valid options are added.
> 
> Fixes: 8f91869766c0 ("x86/build: Fix stack alignment for CLang")
> Signed-off-by: Matthias Kaehlcke <mka@chromium.org>

I've added the kbuild-bot Reported-by tag to document (and credit) how this bug 
was found.

Thanks,

	Ingo

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tip:x86/build] x86/build: Use cc-option to validate stack alignment parameter
  2017-08-17 18:20 [PATCH] x86/build: Use cc-option to validate stack alignment parameter Matthias Kaehlcke
  2017-08-21  7:53 ` Ingo Molnar
@ 2017-08-21  9:20 ` tip-bot for Matthias Kaehlcke
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Matthias Kaehlcke @ 2017-08-21  9:20 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: mka, hpa, keescook, ndesaulniers, ghackmann, torvalds,
	yamada.masahiro, srhines, arnd, tglx, mingo, linux-kernel,
	peterz, md, fengguang.wu

Commit-ID:  9e8730b178a2472fca3123e909d6e69cc8127778
Gitweb:     http://git.kernel.org/tip/9e8730b178a2472fca3123e909d6e69cc8127778
Author:     Matthias Kaehlcke <mka@chromium.org>
AuthorDate: Thu, 17 Aug 2017 11:20:47 -0700
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Mon, 21 Aug 2017 09:53:15 +0200

x86/build: Use cc-option to validate stack alignment parameter

With the following commit:

  8f91869766c0 ("x86/build: Fix stack alignment for CLang")

cc-option is only used to determine the name of the stack alignment option
supported by the compiler, but not to verify that the actual parameter
<option>=N is valid in combination with the other CFLAGS.

This causes problems (as reported by the kbuild robot) with older GCC versions
which only support stack alignment on a boundary of 16 bytes or higher.

Also use (__)cc_option to add the stack alignment option to CFLAGS to
make sure only valid options are added.

Reported-by: kbuild test robot <fengguang.wu@intel.com>
Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Bernhard.Rosenkranzer@linaro.org
Cc: Greg Hackmann <ghackmann@google.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Michael Davidson <md@google.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephen Hines <srhines@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: dianders@chromium.org
Fixes: 8f91869766c0 ("x86/build: Fix stack alignment for CLang")
Link: http://lkml.kernel.org/r/20170817182047.176752-1-mka@chromium.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/Makefile | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 48f3ae7..6276572 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -38,7 +38,7 @@ REALMODE_CFLAGS	:= $(M16_CFLAGS) -g -Os -D__KERNEL__ \
 
 REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -ffreestanding)
 REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -fno-stack-protector)
-REALMODE_CFLAGS += $(cc_stack_align4)
+REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), $(cc_stack_align4))
 export REALMODE_CFLAGS
 
 # BITS is used as extension for files which are available in a 32 bit
@@ -78,7 +78,7 @@ ifeq ($(CONFIG_X86_32),y)
         # 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 += $(cc_stack_align4)
+        KBUILD_CFLAGS += $(call cc-option,$(cc_stack_align4))
 
         # 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:
@@ -117,7 +117,7 @@ else
         # 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 += $(cc_stack_align8)
+        KBUILD_CFLAGS += $(call cc-option,$(cc_stack_align8))
 
 	# Use -mskip-rax-setup if supported.
 	KBUILD_CFLAGS += $(call cc-option,-mskip-rax-setup)

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-08-21  9:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-17 18:20 [PATCH] x86/build: Use cc-option to validate stack alignment parameter Matthias Kaehlcke
2017-08-21  7:53 ` Ingo Molnar
2017-08-21  9:20 ` [tip:x86/build] " tip-bot for Matthias Kaehlcke

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.