public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/srso: fix build breakage for LD=ld.lld
@ 2023-08-09 16:40 Nick Desaulniers
  2023-08-10  9:11 ` [tip: x86/bugs] x86/srso: Fix build breakage with the LLVM linker tip-bot2 for Nick Desaulniers
  2023-08-12 14:17 ` [PATCH] x86/srso: fix build breakage for LD=ld.lld Fangrui Song
  0 siblings, 2 replies; 7+ messages in thread
From: Nick Desaulniers @ 2023-08-09 16:40 UTC (permalink / raw)
  To: Borislav Petkov, x86
  Cc: Thomas Gleixner, Ingo Molnar, Dave Hansen, H. Peter Anvin,
	Nathan Chancellor, Tom Rix, linux-kernel, llvm,
	Greg Kroah-Hartman, Sasha Levin, Peter Zijlstra, Andrew Cooper,
	Daniel Kolesa, Naresh Kamboju, Sven Volkinsfeld, Nick Desaulniers

The assertion added to verify the difference in bits set of the
addresses of srso_untrain_ret_alias and srso_safe_ret_alias would fail
to link in LLVM's ld.lld linker with the following error:

  ld.lld: error: ./arch/x86/kernel/vmlinux.lds:210: at least one side of
  the expression must be absolute
  ld.lld: error: ./arch/x86/kernel/vmlinux.lds:211: at least one side of
  the expression must be absolute

Use ABSOLUTE to evaluate the expression referring to at least one of the
symbols so that LLD can evaluate the linker script.

Also, add linker version info to the comment about xor being unsupported
in either ld.bfd or ld.lld until somewhat recently.

Fixes: fb3bd914b3ec ("x86/srso: Add a Speculative RAS Overflow mitigation")
Link: https://github.com/ClangBuiltLinux/linux/issues/1907
Reported-by: Nathan Chancellor <nathan@kernel.org>
Reported-by: Daniel Kolesa <daniel@octaforge.org>
Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org>
Closes: https://lore.kernel.org/llvm/CA+G9fYsdUeNu-gwbs0+T6XHi4hYYk=Y9725-wFhZ7gJMspLDRA@mail.gmail.com/
Suggested-by: Sven Volkinsfeld <thyrc@gmx.net>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
---
Note that CONFIG_LTO_CLANG is still broken due to GDS mitigations. Will
work on a separate fix for that.  Sending this for now to unmuck the
builds.
---
 arch/x86/kernel/vmlinux.lds.S | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
index e76813230192..ef06211bae4c 100644
--- a/arch/x86/kernel/vmlinux.lds.S
+++ b/arch/x86/kernel/vmlinux.lds.S
@@ -529,11 +529,17 @@ INIT_PER_CPU(irq_stack_backing_store);
 
 #ifdef CONFIG_CPU_SRSO
 /*
- * GNU ld cannot do XOR so do: (A | B) - (A & B) in order to compute the XOR
+ * GNU ld cannot do XOR until 2.41.
+ * https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=f6f78318fca803c4907fb8d7f6ded8295f1947b1
+ *
+ * LLVM lld cannot do XOR until lld-17.
+ * https://github.com/llvm/llvm-project/commit/fae96104d4378166cbe5c875ef8ed808a356f3fb
+ *
+ * Instead do: (A | B) - (A & B) in order to compute the XOR
  * of the two function addresses:
  */
-. = ASSERT(((srso_untrain_ret_alias | srso_safe_ret_alias) -
-		(srso_untrain_ret_alias & srso_safe_ret_alias)) == ((1 << 2) | (1 << 8) | (1 << 14) | (1 << 20)),
+. = ASSERT(((ABSOLUTE(srso_untrain_ret_alias) | srso_safe_ret_alias) -
+		(ABSOLUTE(srso_untrain_ret_alias) & srso_safe_ret_alias)) == ((1 << 2) | (1 << 8) | (1 << 14) | (1 << 20)),
 		"SRSO function pair won't alias");
 #endif
 

---
base-commit: 13b9372068660fe4f7023f43081067376582ef3c
change-id: 20230809-gds-8b0456a18548

Best regards,
-- 
Nick Desaulniers <ndesaulniers@google.com>


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

* [tip: x86/bugs] x86/srso: Fix build breakage with the LLVM linker
  2023-08-09 16:40 [PATCH] x86/srso: fix build breakage for LD=ld.lld Nick Desaulniers
@ 2023-08-10  9:11 ` tip-bot2 for Nick Desaulniers
  2023-08-10 23:25   ` Jakub Kicinski
  2023-08-12 14:17 ` [PATCH] x86/srso: fix build breakage for LD=ld.lld Fangrui Song
  1 sibling, 1 reply; 7+ messages in thread
From: tip-bot2 for Nick Desaulniers @ 2023-08-10  9:11 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Nathan Chancellor, Daniel Kolesa, Naresh Kamboju,
	Sven Volkinsfeld, Nick Desaulniers, Borislav Petkov (AMD), x86,
	linux-kernel

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

Commit-ID:     cbe8ded48b939b9d55d2c5589ab56caa7b530709
Gitweb:        https://git.kernel.org/tip/cbe8ded48b939b9d55d2c5589ab56caa7b530709
Author:        Nick Desaulniers <ndesaulniers@google.com>
AuthorDate:    Wed, 09 Aug 2023 09:40:26 -07:00
Committer:     Borislav Petkov (AMD) <bp@alien8.de>
CommitterDate: Thu, 10 Aug 2023 11:03:12 +02:00

x86/srso: Fix build breakage with the LLVM linker

The assertion added to verify the difference in bits set of the
addresses of srso_untrain_ret_alias() and srso_safe_ret_alias() would fail
to link in LLVM's ld.lld linker with the following error:

  ld.lld: error: ./arch/x86/kernel/vmlinux.lds:210: at least one side of
  the expression must be absolute
  ld.lld: error: ./arch/x86/kernel/vmlinux.lds:211: at least one side of
  the expression must be absolute

Use ABSOLUTE to evaluate the expression referring to at least one of the
symbols so that LLD can evaluate the linker script.

Also, add linker version info to the comment about XOR being unsupported
in either ld.bfd or ld.lld until somewhat recently.

Fixes: fb3bd914b3ec ("x86/srso: Add a Speculative RAS Overflow mitigation")
Closes: https://lore.kernel.org/llvm/CA+G9fYsdUeNu-gwbs0+T6XHi4hYYk=Y9725-wFhZ7gJMspLDRA@mail.gmail.com/
Reported-by: Nathan Chancellor <nathan@kernel.org>
Reported-by: Daniel Kolesa <daniel@octaforge.org>
Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org>
Suggested-by: Sven Volkinsfeld <thyrc@gmx.net>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Link: https://github.com/ClangBuiltLinux/linux/issues/1907
Link: https://lore.kernel.org/r/20230809-gds-v1-1-eaac90b0cbcc@google.com
---
 arch/x86/kernel/vmlinux.lds.S | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
index e768132..ef06211 100644
--- a/arch/x86/kernel/vmlinux.lds.S
+++ b/arch/x86/kernel/vmlinux.lds.S
@@ -529,11 +529,17 @@ INIT_PER_CPU(irq_stack_backing_store);
 
 #ifdef CONFIG_CPU_SRSO
 /*
- * GNU ld cannot do XOR so do: (A | B) - (A & B) in order to compute the XOR
+ * GNU ld cannot do XOR until 2.41.
+ * https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=f6f78318fca803c4907fb8d7f6ded8295f1947b1
+ *
+ * LLVM lld cannot do XOR until lld-17.
+ * https://github.com/llvm/llvm-project/commit/fae96104d4378166cbe5c875ef8ed808a356f3fb
+ *
+ * Instead do: (A | B) - (A & B) in order to compute the XOR
  * of the two function addresses:
  */
-. = ASSERT(((srso_untrain_ret_alias | srso_safe_ret_alias) -
-		(srso_untrain_ret_alias & srso_safe_ret_alias)) == ((1 << 2) | (1 << 8) | (1 << 14) | (1 << 20)),
+. = ASSERT(((ABSOLUTE(srso_untrain_ret_alias) | srso_safe_ret_alias) -
+		(ABSOLUTE(srso_untrain_ret_alias) & srso_safe_ret_alias)) == ((1 << 2) | (1 << 8) | (1 << 14) | (1 << 20)),
 		"SRSO function pair won't alias");
 #endif
 

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

* Re: [tip: x86/bugs] x86/srso: Fix build breakage with the LLVM linker
  2023-08-10  9:11 ` [tip: x86/bugs] x86/srso: Fix build breakage with the LLVM linker tip-bot2 for Nick Desaulniers
@ 2023-08-10 23:25   ` Jakub Kicinski
  2023-08-11  0:28     ` Jakub Kicinski
  0 siblings, 1 reply; 7+ messages in thread
From: Jakub Kicinski @ 2023-08-10 23:25 UTC (permalink / raw)
  To: tip-bot2 for Nick Desaulniers, Borislav Petkov (AMD)
  Cc: linux-kernel, linux-tip-commits, Nathan Chancellor, Daniel Kolesa,
	Naresh Kamboju, Sven Volkinsfeld, Nick Desaulniers, x86,
	netdev@vger.kernel.org, torvalds

On Thu, 10 Aug 2023 09:11:48 -0000 tip-bot2 for Nick Desaulniers wrote:
> The following commit has been merged into the x86/bugs branch of tip:

Hi folks, is there an ETA on this getting to Linus?
The breakage has propagated to the networking trees, if the fix reaches
Linus soon we'll just hold off on applying stuff and fast forward again.

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

* Re: [tip: x86/bugs] x86/srso: Fix build breakage with the LLVM linker
  2023-08-10 23:25   ` Jakub Kicinski
@ 2023-08-11  0:28     ` Jakub Kicinski
  2023-08-11  0:37       ` Linus Torvalds
  0 siblings, 1 reply; 7+ messages in thread
From: Jakub Kicinski @ 2023-08-11  0:28 UTC (permalink / raw)
  To: Borislav Petkov (AMD)
  Cc: linux-kernel, linux-tip-commits, Nathan Chancellor, Daniel Kolesa,
	Naresh Kamboju, Sven Volkinsfeld, Nick Desaulniers, x86,
	netdev@vger.kernel.org, torvalds, Martin KaFai Lau

On Thu, 10 Aug 2023 16:25:24 -0700 Jakub Kicinski wrote:
> On Thu, 10 Aug 2023 09:11:48 -0000 tip-bot2 for Nick Desaulniers wrote:
> > The following commit has been merged into the x86/bugs branch of tip:  
> 
> Hi folks, is there an ETA on this getting to Linus?
> The breakage has propagated to the networking trees, if the fix reaches
> Linus soon we'll just hold off on applying stuff and fast forward again.

Are the commit IDs stable on x86/bugs? 
Would it be rude if we pulled that in?

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

* Re: [tip: x86/bugs] x86/srso: Fix build breakage with the LLVM linker
  2023-08-11  0:28     ` Jakub Kicinski
@ 2023-08-11  0:37       ` Linus Torvalds
  2023-08-11  9:02         ` Borislav Petkov
  0 siblings, 1 reply; 7+ messages in thread
From: Linus Torvalds @ 2023-08-11  0:37 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: Borislav Petkov (AMD), linux-kernel, linux-tip-commits,
	Nathan Chancellor, Daniel Kolesa, Naresh Kamboju,
	Sven Volkinsfeld, Nick Desaulniers, x86, netdev@vger.kernel.org,
	Martin KaFai Lau

On Thu, 10 Aug 2023 at 17:29, Jakub Kicinski <kuba@kernel.org> wrote:
>
> Are the commit IDs stable on x86/bugs?

I think normally yes.

> Would it be rude if we pulled that in?

If this is holding stuff up, you have a pretty good excuse. It
shouldn't be the normal workflow, but hey, it's not a normal problem.

As I mentioned elsewhere, I hate the embargoed stuff, and every single
time it happens I expect fallout from the fact that we couldn't use
the usual bots for build and boot testing.

All our processes are geared towards open development, and I think
that's exactly how they *should* be.

But then that means that they fail horribly for the embargoes.

Anyway, go ahead and just pull in the fixes if this holds up your
normal workflow.

And if we end up with duplicates due to rebases (or worse yet, merge
issues due to rebases with other changes), it is what it is. Can't
blame you.

              Linus

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

* Re: [tip: x86/bugs] x86/srso: Fix build breakage with the LLVM linker
  2023-08-11  0:37       ` Linus Torvalds
@ 2023-08-11  9:02         ` Borislav Petkov
  0 siblings, 0 replies; 7+ messages in thread
From: Borislav Petkov @ 2023-08-11  9:02 UTC (permalink / raw)
  To: Linus Torvalds
  Cc: Jakub Kicinski, linux-kernel, linux-tip-commits,
	Nathan Chancellor, Daniel Kolesa, Naresh Kamboju,
	Sven Volkinsfeld, Nick Desaulniers, x86, netdev@vger.kernel.org,
	Martin KaFai Lau

On Thu, Aug 10, 2023 at 05:37:46PM -0700, Linus Torvalds wrote:
> If this is holding stuff up, you have a pretty good excuse. It
> shouldn't be the normal workflow, but hey, it's not a normal problem.
> 
> As I mentioned elsewhere, I hate the embargoed stuff, and every single
> time it happens I expect fallout from the fact that we couldn't use
> the usual bots for build and boot testing.

Yah, and this time ain't no different.

I was thinking of sending it to you now but Jakub pulled already. So
I'll send it to you on Sunday.

Thx.

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

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

* Re: [PATCH] x86/srso: fix build breakage for LD=ld.lld
  2023-08-09 16:40 [PATCH] x86/srso: fix build breakage for LD=ld.lld Nick Desaulniers
  2023-08-10  9:11 ` [tip: x86/bugs] x86/srso: Fix build breakage with the LLVM linker tip-bot2 for Nick Desaulniers
@ 2023-08-12 14:17 ` Fangrui Song
  1 sibling, 0 replies; 7+ messages in thread
From: Fangrui Song @ 2023-08-12 14:17 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: Borislav Petkov, x86, Thomas Gleixner, Ingo Molnar, Dave Hansen,
	H. Peter Anvin, Nathan Chancellor, Tom Rix, linux-kernel, llvm,
	Greg Kroah-Hartman, Sasha Levin, Peter Zijlstra, Andrew Cooper,
	Daniel Kolesa, Naresh Kamboju, Sven Volkinsfeld

On Wed, Aug 9, 2023 at 12:40 PM Nick Desaulniers
<ndesaulniers@google.com> wrote:
>
> The assertion added to verify the difference in bits set of the
> addresses of srso_untrain_ret_alias and srso_safe_ret_alias would fail
> to link in LLVM's ld.lld linker with the following error:
>
>   ld.lld: error: ./arch/x86/kernel/vmlinux.lds:210: at least one side of
>   the expression must be absolute
>   ld.lld: error: ./arch/x86/kernel/vmlinux.lds:211: at least one side of
>   the expression must be absolute
>
> Use ABSOLUTE to evaluate the expression referring to at least one of the
> symbols so that LLD can evaluate the linker script.
>
> Also, add linker version info to the comment about xor being unsupported
> in either ld.bfd or ld.lld until somewhat recently.
>
> Fixes: fb3bd914b3ec ("x86/srso: Add a Speculative RAS Overflow mitigation")
> Link: https://github.com/ClangBuiltLinux/linux/issues/1907
> Reported-by: Nathan Chancellor <nathan@kernel.org>
> Reported-by: Daniel Kolesa <daniel@octaforge.org>
> Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org>
> Closes: https://lore.kernel.org/llvm/CA+G9fYsdUeNu-gwbs0+T6XHi4hYYk=Y9725-wFhZ7gJMspLDRA@mail.gmail.com/
> Suggested-by: Sven Volkinsfeld <thyrc@gmx.net>
> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
> ---
> Note that CONFIG_LTO_CLANG is still broken due to GDS mitigations. Will
> work on a separate fix for that.  Sending this for now to unmuck the
> builds.
> ---
>  arch/x86/kernel/vmlinux.lds.S | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
> index e76813230192..ef06211bae4c 100644
> --- a/arch/x86/kernel/vmlinux.lds.S
> +++ b/arch/x86/kernel/vmlinux.lds.S
> @@ -529,11 +529,17 @@ INIT_PER_CPU(irq_stack_backing_store);
>
>  #ifdef CONFIG_CPU_SRSO
>  /*
> - * GNU ld cannot do XOR so do: (A | B) - (A & B) in order to compute the XOR
> + * GNU ld cannot do XOR until 2.41.
> + * https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=f6f78318fca803c4907fb8d7f6ded8295f1947b1
> + *
> + * LLVM lld cannot do XOR until lld-17.
> + * https://github.com/llvm/llvm-project/commit/fae96104d4378166cbe5c875ef8ed808a356f3fb
> + *
> + * Instead do: (A | B) - (A & B) in order to compute the XOR
>   * of the two function addresses:
>   */
> -. = ASSERT(((srso_untrain_ret_alias | srso_safe_ret_alias) -
> -               (srso_untrain_ret_alias & srso_safe_ret_alias)) == ((1 << 2) | (1 << 8) | (1 << 14) | (1 << 20)),
> +. = ASSERT(((ABSOLUTE(srso_untrain_ret_alias) | srso_safe_ret_alias) -
> +               (ABSOLUTE(srso_untrain_ret_alias) & srso_safe_ret_alias)) == ((1 << 2) | (1 << 8) | (1 << 14) | (1 << 20)),
>                 "SRSO function pair won't alias");
>  #endif
>
>
> ---
> base-commit: 13b9372068660fe4f7023f43081067376582ef3c
> change-id: 20230809-gds-8b0456a18548
>
> Best regards,
> --
> Nick Desaulniers <ndesaulniers@google.com>
>
>

LGTM as a maintainer of lld/ELF and the author of the ^ ^= feature:)

Expressions in linker scripts are hard and GNU ld has quite a few
rules https://sourceware.org/binutils/docs/ld/Expression-Section.html
. I suspect the rule " Expressions appearing inside an output section
definition treat absolute symbols as numbers." is involved.

In any case, the semantics of the bitwise AND/OR results of two
addresses is unclear.
ld.lld reports "at least one side of the expression must be absolute",
which seems to right thing.

Reviewed-by: Fangrui Song <maskray@google.com>


-- 
宋方睿

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

end of thread, other threads:[~2023-08-12 14:17 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-09 16:40 [PATCH] x86/srso: fix build breakage for LD=ld.lld Nick Desaulniers
2023-08-10  9:11 ` [tip: x86/bugs] x86/srso: Fix build breakage with the LLVM linker tip-bot2 for Nick Desaulniers
2023-08-10 23:25   ` Jakub Kicinski
2023-08-11  0:28     ` Jakub Kicinski
2023-08-11  0:37       ` Linus Torvalds
2023-08-11  9:02         ` Borislav Petkov
2023-08-12 14:17 ` [PATCH] x86/srso: fix build breakage for LD=ld.lld Fangrui Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox