Skip to content

Commit 7a4b16f

Browse files
ubizjakgregkh
authored andcommitted
x86/percpu: Use __force to cast from __percpu address space
commit a55c1fd upstream. Fix Sparse warning when casting from __percpu address space by using __force in the cast. x86 named address spaces are not considered to be subspaces of the generic (flat) address space, so explicit casts are required to convert pointers between these address spaces and the generic address space (the application should cast to uintptr_t and apply the segment base offset). The cast to uintptr_t removes __percpu address space tag and Sparse reports: warning: cast removes address space '__percpu' of expression Use __force to inform Sparse that the cast is intentional. Fixes: 9a462b9 ("x86/percpu: Use compiler segment prefix qualifier") Reported-by: Charlemagne Lasse <charlemagnelasse@gmail.com> 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/20240402175058.52649-1-ubizjak@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Closes: https://lore.kernel.org/lkml/CAFGhKbzev7W4aHwhFPWwMZQEHenVgZUj7=aunFieVqZg3mt14A@mail.gmail.com/
1 parent b3687a2 commit 7a4b16f

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

arch/x86/include/asm/percpu.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
unsigned long tcp_ptr__; \
7171
tcp_ptr__ = __raw_cpu_read(, this_cpu_off); \
7272
\
73-
tcp_ptr__ += (unsigned long)(ptr); \
73+
tcp_ptr__ += (__force unsigned long)(ptr); \
7474
(typeof(*(ptr)) __kernel __force *)tcp_ptr__; \
7575
})
7676
#else /* CONFIG_USE_X86_SEG_SUPPORT */
@@ -102,8 +102,8 @@
102102
#endif /* CONFIG_SMP */
103103

104104
#define __my_cpu_type(var) typeof(var) __percpu_seg_override
105-
#define __my_cpu_ptr(ptr) (__my_cpu_type(*ptr) *)(uintptr_t)(ptr)
106-
#define __my_cpu_var(var) (*__my_cpu_ptr(&var))
105+
#define __my_cpu_ptr(ptr) (__my_cpu_type(*ptr)*)(__force uintptr_t)(ptr)
106+
#define __my_cpu_var(var) (*__my_cpu_ptr(&(var)))
107107
#define __percpu_arg(x) __percpu_prefix "%" #x
108108
#define __force_percpu_arg(x) __force_percpu_prefix "%" #x
109109

0 commit comments

Comments
 (0)