Skip to contentSkip to conversation

x86/speculation: Use DECLARE_PER_CPU for x86_spec_ctrl_current

PATCH Applied Nathan Chancellor 7 participants 13 messages Jul 13, 2022 – Jul 15, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 x86/speculation: Use DECLARE_PER_CPU for x86_spec_ctrl_current

Clang warns:

arch/x86/kernel/cpu/bugs.c:58:21: error: section attribute is specified on redeclared variable [-Werror,-Wsection]

  DEFINE_PER_CPU(u64, x86_spec_ctrl_current);
                      ^
  arch/x86/include/asm/nospec-branch.h:283:12: note: previous declaration is here
  extern u64 x86_spec_ctrl_current;
             ^

1 error generated.

The declaration should be using DECLARE_PER_CPU instead so all attributes stay in sync.

Fixes fc02735b14ff ("KVM: VMX: Prevent guest RSB poisoning attacks with eIBRS")

---

v1 -> v2: https://lore.kernel.org/[email protected]/

* Use asm/percpu.h instead of linux/percpu.h to avoid static call include errors.

 arch/x86/include/asm/nospec-branch.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/include/asm/nospec-branch.h +2 -1
index bb05ed4f46bd..10a3bfc1eb23 100644
@@ -11,6 +11,7 @@
 #include <asm/cpufeatures.h>
 #include <asm/msr-index.h>
 #include <asm/unwind_hints.h>
+#include <asm/percpu.h>
 
 #define RETPOLINE_THUNK_SIZE	32
 
@@ -280,7 +281,7 @@ static inline void indirect_branch_prediction_barrier(void)
 
 /* The Intel SPEC CTRL MSR base value cache */
 extern u64 x86_spec_ctrl_base;
-extern u64 x86_spec_ctrl_current;
+DECLARE_PER_CPU(u64, x86_spec_ctrl_current);
 extern void write_spec_ctrl_current(u64 val, bool force);
 extern u64 spec_ctrl_current(void);
 

base-commit: 72a8e05d4f66b5af7854df4490e3135168694b6b

Signature · 1 line
2.37.1
Reviewed-by Tested-by on v2 1/1
#1 lore raw
Quoted 11 lines · Nathan Chancellor

Clang warns:

arch/x86/kernel/cpu/bugs.c:58:21: error: section attribute is specified on redeclared variable [-Werror,-Wsection]

  DEFINE_PER_CPU(u64, x86_spec_ctrl_current);
                      ^
  arch/x86/include/asm/nospec-branch.h:283:12: note: previous declaration is here
  extern u64 x86_spec_ctrl_current;
             ^

1 error generated.

Quoted 7 lines

The declaration should be using DECLARE_PER_CPU instead so all attributes stay in sync.

Fixes fc02735b14ff ("KVM: VMX: Prevent guest RSB poisoning attacks with eIBRS")

Thanks for the patch!

Quoted 37 lines

---

v1 -> v2: https://lore.kernel.org/[email protected]/

* Use asm/percpu.h instead of linux/percpu.h to avoid static call include errors.

 arch/x86/include/asm/nospec-branch.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/include/asm/nospec-branch.h +2 -1
index bb05ed4f46bd..10a3bfc1eb23 100644
@@ -11,6 +11,7 @@
 #include <asm/cpufeatures.h>
 #include <asm/msr-index.h>
 #include <asm/unwind_hints.h>
+#include <asm/percpu.h>
 
 #define RETPOLINE_THUNK_SIZE   32
 
@@ -280,7 +281,7 @@ static inline void indirect_branch_prediction_barrier(void)
 
 /* The Intel SPEC CTRL MSR base value cache */
 extern u64 x86_spec_ctrl_base;
-extern u64 x86_spec_ctrl_current;
+DECLARE_PER_CPU(u64, x86_spec_ctrl_current);
 extern void write_spec_ctrl_current(u64 val, bool force);
 extern u64 spec_ctrl_current(void);
 

base-commit: 72a8e05d4f66b5af7854df4490e3135168694b6b --
2.37.1

Signature · 2 lines
Thanks,
~Nick Desaulniers
maintainer
#2 lore raw
In reply to Nathan Chancellor
Quoted 32 lines · Nathan Chancellor

Clang warns:

arch/x86/kernel/cpu/bugs.c:58:21: error: section attribute is specified on redeclared variable [-Werror,-Wsection]

  DEFINE_PER_CPU(u64, x86_spec_ctrl_current);
                      ^
  arch/x86/include/asm/nospec-branch.h:283:12: note: previous declaration is here
  extern u64 x86_spec_ctrl_current;
             ^

1 error generated.

The declaration should be using DECLARE_PER_CPU instead so all attributes stay in sync.

Fixes fc02735b14ff ("KVM: VMX: Prevent guest RSB poisoning attacks with eIBRS")

---

v1 -> v2: https://lore.kernel.org/[email protected]/

* Use asm/percpu.h instead of linux/percpu.h to avoid static call include errors.

 arch/x86/include/asm/nospec-branch.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/include/asm/nospec-branch.h +0 -0
index bb05ed4f46bd..10a3bfc1eb23 100644

arch/x86/include/asm/nospec-branch.h line 17

Quoted 7 lines
arch/x86/include/asm/nospec-branch.h +1 -0
@@ -11,6 +11,7 @@
 #include <asm/cpufeatures.h>
 #include <asm/msr-index.h>
 #include <asm/unwind_hints.h>
+#include <asm/percpu.h>
 
 #define RETPOLINE_THUNK_SIZE	32
 

When I tried this earlier today I ran into cyclic headers, you sure this works?

#3 lore raw
Quoted 38 lines · Peter Zijlstra
Quoted 37 lines · Nathan Chancellor

Clang warns:

arch/x86/kernel/cpu/bugs.c:58:21: error: section attribute is specified on redeclared variable [-Werror,-Wsection]

  DEFINE_PER_CPU(u64, x86_spec_ctrl_current);
                      ^
  arch/x86/include/asm/nospec-branch.h:283:12: note: previous declaration is here
  extern u64 x86_spec_ctrl_current;
             ^

1 error generated.

The declaration should be using DECLARE_PER_CPU instead so all attributes stay in sync.

Fixes fc02735b14ff ("KVM: VMX: Prevent guest RSB poisoning attacks with eIBRS")

---

v1 -> v2: https://lore.kernel.org/[email protected]/

* Use asm/percpu.h instead of linux/percpu.h to avoid static call include errors.

 arch/x86/include/asm/nospec-branch.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/include/asm/nospec-branch.h +1 -0
index bb05ed4f46bd..10a3bfc1eb23 100644
@@ -11,6 +11,7 @@
 #include <asm/cpufeatures.h>
 #include <asm/msr-index.h>
 #include <asm/unwind_hints.h>
+#include <asm/percpu.h>
 
Quoted 5 lines

arch/x86/include/asm/nospec-branch.h line 17

Quoted 2 lines
arch/x86/include/asm/nospec-branch.h +0 -0
 #define RETPOLINE_THUNK_SIZE	32
 

When I tried this earlier today I ran into cyclic headers, you sure this works?

Yes, I did my regular set of x86 builds with clang and they all passed.

Cheers,
Nathan

#4 lore raw
In reply to Nathan Chancellor
The following commit has been merged into the x86/urgent branch of tip:

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

Commit-ID:     db866d3352ec85e821e730e191481cba3a2bfa6e
Gitweb:        https://git.kernel.org/tip/db866d3352ec85e821e730e191481cba3a2bfa6e
Author:        Nathan Chancellor <[email protected]>
AuthorDate:    Wed, 13 Jul 2022 08:24:37 -07:00
Committer:     Borislav Petkov <[email protected]>
CommitterDate: Thu, 14 Jul 2022 13:40:21 +02:00

x86/speculation: Use DECLARE_PER_CPU for x86_spec_ctrl_current

Clang warns:

arch/x86/kernel/cpu/bugs.c:58:21: error: section attribute is specified on redeclared variable [-Werror,-Wsection]

  DEFINE_PER_CPU(u64, x86_spec_ctrl_current);
                      ^
  arch/x86/include/asm/nospec-branch.h:283:12: note: previous declaration is here
  extern u64 x86_spec_ctrl_current;
             ^

1 error generated.

The declaration should be using DECLARE_PER_CPU instead so all attributes stay in sync.

---
 arch/x86/include/asm/nospec-branch.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/include/asm/nospec-branch.h +2 -1
index bb05ed4..10a3bfc 100644
@@ -11,6 +11,7 @@
 #include <asm/cpufeatures.h>
 #include <asm/msr-index.h>
 #include <asm/unwind_hints.h>
+#include <asm/percpu.h>
 
 #define RETPOLINE_THUNK_SIZE	32
 
@@ -280,7 +281,7 @@ static inline void indirect_branch_prediction_barrier(void)
 
 /* The Intel SPEC CTRL MSR base value cache */
 extern u64 x86_spec_ctrl_base;
-extern u64 x86_spec_ctrl_current;
+DECLARE_PER_CPU(u64, x86_spec_ctrl_current);
 extern void write_spec_ctrl_current(u64 val, bool force);
 extern u64 spec_ctrl_current(void);
 
#5 lore raw
In reply to Nathan Chancellor
Quoted 10 lines · On Wed, 13 Jul 2022 08:24:37 -0700 Nathan Chancellor wrote:

Clang warns:

arch/x86/kernel/cpu/bugs.c:58:21: error: section attribute is specified on redeclared variable [-Werror,-Wsection]

  DEFINE_PER_CPU(u64, x86_spec_ctrl_current);
                      ^
  arch/x86/include/asm/nospec-branch.h:283:12: note: previous declaration is here
  extern u64 x86_spec_ctrl_current;
             ^

1 error generated.

Quoted 7 lines

The declaration should be using DECLARE_PER_CPU instead so all attributes stay in sync.

Fixes fc02735b14ff ("KVM: VMX: Prevent guest RSB poisoning attacks with eIBRS")

Hi, sorry to bother, any idea on the ETA for this fix getting into Linus's tree? I'm trying to figure out if we should wait with forwarding the networking trees or this will take a while.

#6 lore raw
Quoted 4 lines · Jakub Kicinski

Hi, sorry to bother, any idea on the ETA for this fix getting into Linus's tree? I'm trying to figure out if we should wait with forwarding the networking trees or this will take a while.

Well, I have that patch by now in my own clang tree, but was holding it off just because I was expecting a few other fixes for the fallout.

But if this particular one causes problems for maintainers, I can easily just take it right away just cherry-pick it from my own test-tree to my "main" tree.

Linus

#7 lore raw
Quoted 4 lines · Linus Torvalds

But if this particular one causes problems for maintainers, I can easily just take it right away just cherry-pick it from my own test-tree to my "main" tree.

Oh, and as I did that cherry-pick, I suddenly remembered that I think PeterZ had a slightly different version of it - the one I picked up is Nathan's "v2".

PeterZ, do you have preferences? I've waited this long, I might as well wait a bit more before I push out whatever version people prefer.

Linus

maintainer
#8 lore raw
Quoted 7 lines · Linus Torvalds
Quoted 4 lines · Linus Torvalds

But if this particular one causes problems for maintainers, I can easily just take it right away just cherry-pick it from my own test-tree to my "main" tree.

Quoted 6 lines

Oh, and as I did that cherry-pick, I suddenly remembered that I think PeterZ had a slightly different version of it - the one I picked up is Nathan's "v2".

PeterZ, do you have preferences? I've waited this long, I might as well wait a bit more before I push out whatever version people prefer.

Nathan's is much nicer; I got bit by header hell and punted.

#9 lore raw
In reply to Linus Torvalds
Quoted 11 lines · On Thu, 14 Jul 2022 14:51:52 -0700 Linus Torvalds wrote:
Quoted 3 lines · Jakub Kicinski

Hi, sorry to bother, any idea on the ETA for this fix getting into Linus's tree? I'm trying to figure out if we should wait with forwarding the networking trees or this will take a while.

Well, I have that patch by now in my own clang tree, but was holding it off just because I was expecting a few other fixes for the fallout.

But if this particular one causes problems for maintainers, I can easily just take it right away just cherry-pick it from my own test-tree to my "main" tree.

I have clang 13, let me double check this fix is enough for the build to complete without disabling WERROR. If it's not a hassle it'd certainly make my life easier if the fix gotten applied now...

#10 lore raw
Quoted 3 lines · Jakub Kicinski

I have clang 13, let me double check this fix is enough for the build to complete without disabling WERROR.

I have clang 14 locally, and it builds fine with that (and doesn't build without it).

I actually normally build the kernel with both gcc and clang. My "upstream" kernel I build with gcc, and then I have my "private random collection of patches" kernel that I build with clang and that are just rebased on top of the kernel-of-the-day.

This is all entirely for historical reasons - part of my "private random collection of patches" used to be the "asm goto with outputs", which had clang support first.

But then the reason I never even noticed the build breakage with the retbleed patches until much too late was that those I just had as a third fork off my upstream kernel, so despite me usually building with clang too, that only got attention from gcc.

So it's really just a microcosm version of the exact same bigger issue we always have with those embargoed hw security patches: they end up missing out on all the usual test environments.

Anyway, I cherry-picked Nathan's patch from my clang tree and pushed it out as commit db886979683a ("x86/speculation: Use DECLARE_PER_CPU for x86_spec_ctrl_current").

Linus

#11 lore raw
Quoted 6 lines · On Thu, 14 Jul 2022 15:14:53 -0700 Linus Torvalds wrote:
Quoted 2 lines · Jakub Kicinski

I have clang 13, let me double check this fix is enough for the build to complete without disabling WERROR.

I have clang 14 locally, and it builds fine with that (and doesn't build without it).

FWIW I can confirm - builds with clang 13 as well.

Quoted 14 lines

I actually normally build the kernel with both gcc and clang. My "upstream" kernel I build with gcc, and then I have my "private random collection of patches" kernel that I build with clang and that are just rebased on top of the kernel-of-the-day.

This is all entirely for historical reasons - part of my "private random collection of patches" used to be the "asm goto with outputs", which had clang support first.

But then the reason I never even noticed the build breakage with the retbleed patches until much too late was that those I just had as a third fork off my upstream kernel, so despite me usually building with clang too, that only got attention from gcc.

Quoted 7 lines

So it's really just a microcosm version of the exact same bigger issue we always have with those embargoed hw security patches: they end up missing out on all the usual test environments.

Anyway, I cherry-picked Nathan's patch from my clang tree and pushed it out as commit db886979683a ("x86/speculation: Use DECLARE_PER_CPU for x86_spec_ctrl_current").

Awesome, thanks!

#12 lore raw
In reply to Linus Torvalds
Quoted 3 lines · Linus Torvalds

Anyway, I cherry-picked Nathan's patch from my clang tree and pushed it out as commit db886979683a ("x86/speculation: Use DECLARE_PER_CPU for x86_spec_ctrl_current").

... and I've zapped it from my lineup.

Thx.

Signature · 6 lines
Regards/Gruss,
    Boris.

SUSE Software Solutions Germany GmbH
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Martje Boudien Moerman
(HRB 36809, AG Nürnberg)