Skip to contentSkip to conversation

x86/speculation: Use DECLARE_PER_CPU for x86_spec_ctrl_current

PATCH Superseded Nathan Chancellor 1 participant 2 messages Jul 13, 2022

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 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")
---
 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..99a29c83adf8 100644
@@ -6,6 +6,7 @@
 #include <linux/static_key.h>
 #include <linux/objtool.h>
 #include <linux/linkage.h>
+#include <linux/percpu.h>
 
 #include <asm/alternative.h>
 #include <asm/cpufeatures.h>
@@ -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
#1 lore raw
Quoted 26 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")
---
 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..99a29c83adf8 100644

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

Quoted 4 lines
arch/x86/include/asm/nospec-branch.h +1 -0
@@ -6,6 +6,7 @@
 #include <linux/static_key.h>
 #include <linux/objtool.h>
 #include <linux/linkage.h>
+#include <linux/percpu.h>

Argh, forgot to amend... v2 incoming.

Quoted 16 lines
arch/x86/include/asm/nospec-branch.h +1 -1
 #include <asm/alternative.h>
 #include <asm/cpufeatures.h>
@@ -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