All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86: Fix location of '-plugin-opt=' flags
@ 2021-05-18 19:01 Nathan Chancellor
  2021-05-18 20:24 ` Nick Desaulniers
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Nathan Chancellor @ 2021-05-18 19:01 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, x86, Kees Cook,
	Sami Tolvanen, Nick Desaulniers
  Cc: H. Peter Anvin, linux-kernel, clang-built-linux,
	Nathan Chancellor, stable, Anthony Ruhier

Commit b33fff07e3e3 ("x86, build: allow LTO to be selected") added a
couple of '-plugin-opt=' flags to KBUILD_LDFLAGS because the code model
and stack alignment are not stored in LLVM bitcode. However, these flags
were added to KBUILD_LDFLAGS prior to the emulation flag assignment,
which uses ':=', so they were overwritten and never added to $(LD)
invocations. The absence of these flags caused misalignment issues in
the AMDGPU driver when compiling with CONFIG_LTO_CLANG, resulting in
general protection faults.

Shuffle the assignment below the initial one so that the flags are
properly passed along and all of the linker flags stay together.

At the same time, avoid any future issues with clobbering flags by
changing the emulation flag assignment to '+=' since KBUILD_LDFLAGS is
already defined with ':=' in the main Makefile before being exported for
modification here as a result of commit ce99d0bf312d ("kbuild: clear
LDFLAGS in the top Makefile").

Cc: stable@vger.kernel.org
Fixes: b33fff07e3e3 ("x86, build: allow LTO to be selected")
Link: https://github.com/ClangBuiltLinux/linux/issues/1374
Reported-by: Anthony Ruhier <aruhier@mailbox.org>
Tested-by: Anthony Ruhier <aruhier@mailbox.org>
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
 arch/x86/Makefile | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index c77c5d8a7b3e..307529417021 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -178,11 +178,6 @@ ifeq ($(ACCUMULATE_OUTGOING_ARGS), 1)
 	KBUILD_CFLAGS += $(call cc-option,-maccumulate-outgoing-args,)
 endif
 
-ifdef CONFIG_LTO_CLANG
-KBUILD_LDFLAGS	+= -plugin-opt=-code-model=kernel \
-		   -plugin-opt=-stack-alignment=$(if $(CONFIG_X86_32),4,8)
-endif
-
 # Workaround for a gcc prelease that unfortunately was shipped in a suse release
 KBUILD_CFLAGS += -Wno-sign-compare
 #
@@ -202,7 +197,12 @@ ifdef CONFIG_RETPOLINE
   endif
 endif
 
-KBUILD_LDFLAGS := -m elf_$(UTS_MACHINE)
+KBUILD_LDFLAGS += -m elf_$(UTS_MACHINE)
+
+ifdef CONFIG_LTO_CLANG
+KBUILD_LDFLAGS	+= -plugin-opt=-code-model=kernel \
+		   -plugin-opt=-stack-alignment=$(if $(CONFIG_X86_32),4,8)
+endif
 
 ifdef CONFIG_X86_NEED_RELOCS
 LDFLAGS_vmlinux := --emit-relocs --discard-none

base-commit: d07f6ca923ea0927a1024dfccafc5b53b61cfecc
-- 
2.32.0.rc0


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

* Re: [PATCH] x86: Fix location of '-plugin-opt=' flags
  2021-05-18 19:01 [PATCH] x86: Fix location of '-plugin-opt=' flags Nathan Chancellor
@ 2021-05-18 20:24 ` Nick Desaulniers
  2021-05-19 11:23 ` [tip: x86/urgent] x86/build: " tip-bot2 for Nathan Chancellor
  2021-05-21 17:59 ` [PATCH] x86: " Kees Cook
  2 siblings, 0 replies; 6+ messages in thread
From: Nick Desaulniers @ 2021-05-18 20:24 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	Kees Cook, Sami Tolvanen, H. Peter Anvin, LKML,
	clang-built-linux, # 3.4.x, Anthony Ruhier

On Tue, May 18, 2021 at 12:01 PM Nathan Chancellor <nathan@kernel.org> wrote:
>
> Commit b33fff07e3e3 ("x86, build: allow LTO to be selected") added a
> couple of '-plugin-opt=' flags to KBUILD_LDFLAGS because the code model
> and stack alignment are not stored in LLVM bitcode. However, these flags
> were added to KBUILD_LDFLAGS prior to the emulation flag assignment,
> which uses ':=', so they were overwritten and never added to $(LD)
> invocations. The absence of these flags caused misalignment issues in
> the AMDGPU driver when compiling with CONFIG_LTO_CLANG, resulting in
> general protection faults.
>
> Shuffle the assignment below the initial one so that the flags are
> properly passed along and all of the linker flags stay together.
>
> At the same time, avoid any future issues with clobbering flags by
> changing the emulation flag assignment to '+=' since KBUILD_LDFLAGS is
> already defined with ':=' in the main Makefile before being exported for
> modification here as a result of commit ce99d0bf312d ("kbuild: clear
> LDFLAGS in the top Makefile").

Thanks for the patch file.  I will need to be more wary of `:=`
operator in kbuild changes in the future.

Ideally, we should encode these two flags in LLVM's IR so that we
don't need to respecify them when restarting optimizations from the
linker during LTO. I've filed
https://github.com/ClangBuiltLinux/linux/issues/1377 to follow up on
that idea.

Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

>
> Cc: stable@vger.kernel.org
> Fixes: b33fff07e3e3 ("x86, build: allow LTO to be selected")
> Link: https://github.com/ClangBuiltLinux/linux/issues/1374
> Reported-by: Anthony Ruhier <aruhier@mailbox.org>
> Tested-by: Anthony Ruhier <aruhier@mailbox.org>
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>
> ---
>  arch/x86/Makefile | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/arch/x86/Makefile b/arch/x86/Makefile
> index c77c5d8a7b3e..307529417021 100644
> --- a/arch/x86/Makefile
> +++ b/arch/x86/Makefile
> @@ -178,11 +178,6 @@ ifeq ($(ACCUMULATE_OUTGOING_ARGS), 1)
>         KBUILD_CFLAGS += $(call cc-option,-maccumulate-outgoing-args,)
>  endif
>
> -ifdef CONFIG_LTO_CLANG
> -KBUILD_LDFLAGS += -plugin-opt=-code-model=kernel \
> -                  -plugin-opt=-stack-alignment=$(if $(CONFIG_X86_32),4,8)
> -endif
> -
>  # Workaround for a gcc prelease that unfortunately was shipped in a suse release
>  KBUILD_CFLAGS += -Wno-sign-compare
>  #
> @@ -202,7 +197,12 @@ ifdef CONFIG_RETPOLINE
>    endif
>  endif
>
> -KBUILD_LDFLAGS := -m elf_$(UTS_MACHINE)
> +KBUILD_LDFLAGS += -m elf_$(UTS_MACHINE)
> +
> +ifdef CONFIG_LTO_CLANG
> +KBUILD_LDFLAGS += -plugin-opt=-code-model=kernel \
> +                  -plugin-opt=-stack-alignment=$(if $(CONFIG_X86_32),4,8)
> +endif
>
>  ifdef CONFIG_X86_NEED_RELOCS
>  LDFLAGS_vmlinux := --emit-relocs --discard-none
>
> base-commit: d07f6ca923ea0927a1024dfccafc5b53b61cfecc
> --
> 2.32.0.rc0
>


-- 
Thanks,
~Nick Desaulniers

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

* [tip: x86/urgent] x86/build: Fix location of '-plugin-opt=' flags
  2021-05-18 19:01 [PATCH] x86: Fix location of '-plugin-opt=' flags Nathan Chancellor
  2021-05-18 20:24 ` Nick Desaulniers
@ 2021-05-19 11:23 ` tip-bot2 for Nathan Chancellor
  2021-05-21 17:59 ` [PATCH] x86: " Kees Cook
  2 siblings, 0 replies; 6+ messages in thread
From: tip-bot2 for Nathan Chancellor @ 2021-05-19 11:23 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Anthony Ruhier, Nathan Chancellor, Ingo Molnar, stable, x86,
	linux-kernel

The following commit has been merged into the x86/urgent branch of tip:

Commit-ID:     0024430e920f2900654ad83cd081cf52e02a3ef5
Gitweb:        https://git.kernel.org/tip/0024430e920f2900654ad83cd081cf52e02a3ef5
Author:        Nathan Chancellor <nathan@kernel.org>
AuthorDate:    Tue, 18 May 2021 12:01:06 -07:00
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Wed, 19 May 2021 13:05:53 +02:00

x86/build: Fix location of '-plugin-opt=' flags

Commit b33fff07e3e3 ("x86, build: allow LTO to be selected") added a
couple of '-plugin-opt=' flags to KBUILD_LDFLAGS because the code model
and stack alignment are not stored in LLVM bitcode.

However, these flags were added to KBUILD_LDFLAGS prior to the
emulation flag assignment, which uses ':=', so they were overwritten
and never added to $(LD) invocations.

The absence of these flags caused misalignment issues in the
AMDGPU driver when compiling with CONFIG_LTO_CLANG, resulting in
general protection faults.

Shuffle the assignment below the initial one so that the flags are
properly passed along and all of the linker flags stay together.

At the same time, avoid any future issues with clobbering flags by
changing the emulation flag assignment to '+=' since KBUILD_LDFLAGS is
already defined with ':=' in the main Makefile before being exported for
modification here as a result of commit:

  ce99d0bf312d ("kbuild: clear LDFLAGS in the top Makefile")

Fixes: b33fff07e3e3 ("x86, build: allow LTO to be selected")
Reported-by: Anthony Ruhier <aruhier@mailbox.org>
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Tested-by: Anthony Ruhier <aruhier@mailbox.org>
Cc: stable@vger.kernel.org
Link: https://github.com/ClangBuiltLinux/linux/issues/1374
Link: https://lore.kernel.org/r/20210518190106.60935-1-nathan@kernel.org
---
 arch/x86/Makefile | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index c77c5d8..3075294 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -178,11 +178,6 @@ ifeq ($(ACCUMULATE_OUTGOING_ARGS), 1)
 	KBUILD_CFLAGS += $(call cc-option,-maccumulate-outgoing-args,)
 endif
 
-ifdef CONFIG_LTO_CLANG
-KBUILD_LDFLAGS	+= -plugin-opt=-code-model=kernel \
-		   -plugin-opt=-stack-alignment=$(if $(CONFIG_X86_32),4,8)
-endif
-
 # Workaround for a gcc prelease that unfortunately was shipped in a suse release
 KBUILD_CFLAGS += -Wno-sign-compare
 #
@@ -202,7 +197,12 @@ ifdef CONFIG_RETPOLINE
   endif
 endif
 
-KBUILD_LDFLAGS := -m elf_$(UTS_MACHINE)
+KBUILD_LDFLAGS += -m elf_$(UTS_MACHINE)
+
+ifdef CONFIG_LTO_CLANG
+KBUILD_LDFLAGS	+= -plugin-opt=-code-model=kernel \
+		   -plugin-opt=-stack-alignment=$(if $(CONFIG_X86_32),4,8)
+endif
 
 ifdef CONFIG_X86_NEED_RELOCS
 LDFLAGS_vmlinux := --emit-relocs --discard-none

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

* Re: [PATCH] x86: Fix location of '-plugin-opt=' flags
  2021-05-18 19:01 [PATCH] x86: Fix location of '-plugin-opt=' flags Nathan Chancellor
  2021-05-18 20:24 ` Nick Desaulniers
  2021-05-19 11:23 ` [tip: x86/urgent] x86/build: " tip-bot2 for Nathan Chancellor
@ 2021-05-21 17:59 ` Kees Cook
  2021-05-21 18:31   ` Nathan Chancellor
  2 siblings, 1 reply; 6+ messages in thread
From: Kees Cook @ 2021-05-21 17:59 UTC (permalink / raw)
  To: x86, Sami Tolvanen, Nick Desaulniers, Nathan Chancellor,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov
  Cc: Kees Cook, clang-built-linux, Anthony Ruhier, linux-kernel,
	stable, H. Peter Anvin

On Tue, 18 May 2021 12:01:06 -0700, Nathan Chancellor wrote:
> Commit b33fff07e3e3 ("x86, build: allow LTO to be selected") added a
> couple of '-plugin-opt=' flags to KBUILD_LDFLAGS because the code model
> and stack alignment are not stored in LLVM bitcode. However, these flags
> were added to KBUILD_LDFLAGS prior to the emulation flag assignment,
> which uses ':=', so they were overwritten and never added to $(LD)
> invocations. The absence of these flags caused misalignment issues in
> the AMDGPU driver when compiling with CONFIG_LTO_CLANG, resulting in
> general protection faults.
> 
> [...]

(I've slightly adjusted the title.)

Applied to for-next/clang/features, thanks!

[1/1] x86: lto: Fix location of '-plugin-opt=' flags
      https://git.kernel.org/kees/c/5d6c8592ee5f

-- 
Kees Cook


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

* Re: [PATCH] x86: Fix location of '-plugin-opt=' flags
  2021-05-21 17:59 ` [PATCH] x86: " Kees Cook
@ 2021-05-21 18:31   ` Nathan Chancellor
  2021-05-21 21:04     ` Kees Cook
  0 siblings, 1 reply; 6+ messages in thread
From: Nathan Chancellor @ 2021-05-21 18:31 UTC (permalink / raw)
  To: Kees Cook
  Cc: x86, Sami Tolvanen, Nick Desaulniers, Thomas Gleixner,
	Ingo Molnar, Borislav Petkov, clang-built-linux, Anthony Ruhier,
	linux-kernel, stable, H. Peter Anvin

On Fri, May 21, 2021 at 10:59:10AM -0700, Kees Cook wrote:
> On Tue, 18 May 2021 12:01:06 -0700, Nathan Chancellor wrote:
> > Commit b33fff07e3e3 ("x86, build: allow LTO to be selected") added a
> > couple of '-plugin-opt=' flags to KBUILD_LDFLAGS because the code model
> > and stack alignment are not stored in LLVM bitcode. However, these flags
> > were added to KBUILD_LDFLAGS prior to the emulation flag assignment,
> > which uses ':=', so they were overwritten and never added to $(LD)
> > invocations. The absence of these flags caused misalignment issues in
> > the AMDGPU driver when compiling with CONFIG_LTO_CLANG, resulting in
> > general protection faults.
> > 
> > [...]
> 
> (I've slightly adjusted the title.)
> 
> Applied to for-next/clang/features, thanks!
> 
> [1/1] x86: lto: Fix location of '-plugin-opt=' flags
>       https://git.kernel.org/kees/c/5d6c8592ee5f
> 

Ingo picked this up in x86/urgent so you should not need to carry it.

https://git.kernel.org/tip/0024430e920f2900654ad83cd081cf52e02a3ef5

Cheers,
Nathan

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

* Re: [PATCH] x86: Fix location of '-plugin-opt=' flags
  2021-05-21 18:31   ` Nathan Chancellor
@ 2021-05-21 21:04     ` Kees Cook
  0 siblings, 0 replies; 6+ messages in thread
From: Kees Cook @ 2021-05-21 21:04 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: x86, Sami Tolvanen, Nick Desaulniers, Thomas Gleixner,
	Ingo Molnar, Borislav Petkov, clang-built-linux, Anthony Ruhier,
	linux-kernel, stable, H. Peter Anvin

On Fri, May 21, 2021 at 11:31:54AM -0700, Nathan Chancellor wrote:
> On Fri, May 21, 2021 at 10:59:10AM -0700, Kees Cook wrote:
> > On Tue, 18 May 2021 12:01:06 -0700, Nathan Chancellor wrote:
> > > Commit b33fff07e3e3 ("x86, build: allow LTO to be selected") added a
> > > couple of '-plugin-opt=' flags to KBUILD_LDFLAGS because the code model
> > > and stack alignment are not stored in LLVM bitcode. However, these flags
> > > were added to KBUILD_LDFLAGS prior to the emulation flag assignment,
> > > which uses ':=', so they were overwritten and never added to $(LD)
> > > invocations. The absence of these flags caused misalignment issues in
> > > the AMDGPU driver when compiling with CONFIG_LTO_CLANG, resulting in
> > > general protection faults.
> > > 
> > > [...]
> > 
> > (I've slightly adjusted the title.)
> > 
> > Applied to for-next/clang/features, thanks!
> > 
> > [1/1] x86: lto: Fix location of '-plugin-opt=' flags
> >       https://git.kernel.org/kees/c/5d6c8592ee5f
> > 
> 
> Ingo picked this up in x86/urgent so you should not need to carry it.
> 
> https://git.kernel.org/tip/0024430e920f2900654ad83cd081cf52e02a3ef5

Ah-ha, thanks! I didn't see a reply on the thread.

-- 
Kees Cook

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

end of thread, other threads:[~2021-05-21 21:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-18 19:01 [PATCH] x86: Fix location of '-plugin-opt=' flags Nathan Chancellor
2021-05-18 20:24 ` Nick Desaulniers
2021-05-19 11:23 ` [tip: x86/urgent] x86/build: " tip-bot2 for Nathan Chancellor
2021-05-21 17:59 ` [PATCH] x86: " Kees Cook
2021-05-21 18:31   ` Nathan Chancellor
2021-05-21 21:04     ` Kees Cook

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.