x86/percpu: Fix "const_pcpu_hot" version generation failure
authorUros Bizjak <ubizjak@gmail.com>
Mon, 4 Dec 2023 21:02:29 +0000 (22:02 +0100)
committerIngo Molnar <mingo@kernel.org>
Mon, 11 Dec 2023 10:47:14 +0000 (11:47 +0100)
Version generation for "const_pcpu_hot" symbol failed because genksyms
doesn't know the __seg_gs keyword. Effectively revert commit 4604c052b84d
("x86/percpu: Declare const_pcpu_hot as extern const variable") and
use this_cpu_read_const() instead to avoid "sparse: dereference of
noderef expression" warning when reading const_pcpu_hot.

Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/r/20231204210320.114429-1-ubizjak@gmail.com
arch/x86/include/asm/current.h
arch/x86/include/asm/percpu.h
arch/x86/include/asm/processor.h

index 9fbd7cb2dc86644c5b3b0358bc1ba8bb7ad08869..c8c5674d69f644432ab5eec30a7d1115789e76ac 100644 (file)
@@ -37,12 +37,13 @@ static_assert(sizeof(struct pcpu_hot) == 64);
 DECLARE_PER_CPU_ALIGNED(struct pcpu_hot, pcpu_hot);
 
 /* const-qualified alias to pcpu_hot, aliased by linker. */
-extern const struct pcpu_hot __percpu_seg_override const_pcpu_hot;
+DECLARE_PER_CPU_ALIGNED(const struct pcpu_hot __percpu_seg_override,
+                       const_pcpu_hot);
 
 static __always_inline struct task_struct *get_current(void)
 {
        if (IS_ENABLED(CONFIG_USE_X86_SEG_SUPPORT))
-               return const_pcpu_hot.current_task;
+               return this_cpu_read_const(const_pcpu_hot.current_task);
 
        return this_cpu_read_stable(pcpu_hot.current_task);
 }
index 0f12b2004b9420d8d140a76d9829d0c0e24fc41a..3859abad19ec909712c83eb0c96a5896412be99a 100644 (file)
@@ -28,6 +28,7 @@
 
 #else /* ...!ASSEMBLY */
 
+#include <linux/build_bug.h>
 #include <linux/kernel.h>
 #include <linux/stringify.h>
 
@@ -462,6 +463,7 @@ do {                                                                        \
 #define this_cpu_write_8(pcp, val)     __raw_cpu_write(volatile, pcp, val)
 #endif
 
+#define this_cpu_read_const(pcp)       __raw_cpu_read(, pcp)
 #else /* CONFIG_USE_X86_SEG_SUPPORT */
 
 #define raw_cpu_read_1(pcp)            percpu_from_op(1, , "mov", pcp)
@@ -486,6 +488,11 @@ do {                                                                       \
 #define this_cpu_write_8(pcp, val)     percpu_to_op(8, volatile, "mov", (pcp), val)
 #endif
 
+/*
+ * The generic per-cpu infrastrucutre is not suitable for
+ * reading const-qualified variables.
+ */
+#define this_cpu_read_const(pcp)       ({ BUILD_BUG(); (typeof(pcp))0; })
 #endif /* CONFIG_USE_X86_SEG_SUPPORT */
 
 #define raw_cpu_add_1(pcp, val)                percpu_add_op(1, , (pcp), val)
index f20e87632669079c561dc9b6b11cae6128afdad9..a94a857152c44506feb4d54b831182e9f6b37655 100644 (file)
@@ -519,7 +519,7 @@ static __always_inline unsigned long current_top_of_stack(void)
         *  entry trampoline.
         */
        if (IS_ENABLED(CONFIG_USE_X86_SEG_SUPPORT))
-               return const_pcpu_hot.top_of_stack;
+               return this_cpu_read_const(const_pcpu_hot.top_of_stack);
 
        return this_cpu_read_stable(pcpu_hot.top_of_stack);
 }