Skip to content

Commit 0e37036

Browse files
ubizjakIngo Molnar
authored andcommitted
x86/percpu: Fix "const_pcpu_hot" version generation failure
Version generation for "const_pcpu_hot" symbol failed because genksyms doesn't know the __seg_gs keyword. Effectively revert commit 4604c05 ("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
1 parent fc50065 commit 0e37036

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

arch/x86/include/asm/current.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@ static_assert(sizeof(struct pcpu_hot) == 64);
3737
DECLARE_PER_CPU_ALIGNED(struct pcpu_hot, pcpu_hot);
3838

3939
/* const-qualified alias to pcpu_hot, aliased by linker. */
40-
extern const struct pcpu_hot __percpu_seg_override const_pcpu_hot;
40+
DECLARE_PER_CPU_ALIGNED(const struct pcpu_hot __percpu_seg_override,
41+
const_pcpu_hot);
4142

4243
static __always_inline struct task_struct *get_current(void)
4344
{
4445
if (IS_ENABLED(CONFIG_USE_X86_SEG_SUPPORT))
45-
return const_pcpu_hot.current_task;
46+
return this_cpu_read_const(const_pcpu_hot.current_task);
4647

4748
return this_cpu_read_stable(pcpu_hot.current_task);
4849
}

arch/x86/include/asm/percpu.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#else /* ...!ASSEMBLY */
3030

31+
#include <linux/build_bug.h>
3132
#include <linux/kernel.h>
3233
#include <linux/stringify.h>
3334

@@ -462,6 +463,7 @@ do { \
462463
#define this_cpu_write_8(pcp, val) __raw_cpu_write(volatile, pcp, val)
463464
#endif
464465

466+
#define this_cpu_read_const(pcp) __raw_cpu_read(, pcp)
465467
#else /* CONFIG_USE_X86_SEG_SUPPORT */
466468

467469
#define raw_cpu_read_1(pcp) percpu_from_op(1, , "mov", pcp)
@@ -486,6 +488,11 @@ do { \
486488
#define this_cpu_write_8(pcp, val) percpu_to_op(8, volatile, "mov", (pcp), val)
487489
#endif
488490

491+
/*
492+
* The generic per-cpu infrastrucutre is not suitable for
493+
* reading const-qualified variables.
494+
*/
495+
#define this_cpu_read_const(pcp) ({ BUILD_BUG(); (typeof(pcp))0; })
489496
#endif /* CONFIG_USE_X86_SEG_SUPPORT */
490497

491498
#define raw_cpu_add_1(pcp, val) percpu_add_op(1, , (pcp), val)

arch/x86/include/asm/processor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ static __always_inline unsigned long current_top_of_stack(void)
519519
* entry trampoline.
520520
*/
521521
if (IS_ENABLED(CONFIG_USE_X86_SEG_SUPPORT))
522-
return const_pcpu_hot.top_of_stack;
522+
return this_cpu_read_const(const_pcpu_hot.top_of_stack);
523523

524524
return this_cpu_read_stable(pcpu_hot.top_of_stack);
525525
}

0 commit comments

Comments
 (0)