]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
x86/percpu: Use __force to cast from __percpu address space
authorUros Bizjak <ubizjak@gmail.com>
Tue, 2 Apr 2024 17:50:38 +0000 (19:50 +0200)
committerIngo Molnar <mingo@kernel.org>
Wed, 3 Apr 2024 06:59:15 +0000 (08:59 +0200)
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: 9a462b9eafa6 ("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
Closes: https://lore.kernel.org/lkml/CAFGhKbzev7W4aHwhFPWwMZQEHenVgZUj7=aunFieVqZg3mt14A@mail.gmail.com/
arch/x86/include/asm/percpu.h

index 1f6404e0c428309c9c983c98694055fcfeb8fd64..20696df5d5678bc73e3042dd7449df822465146d 100644 (file)
@@ -77,7 +77,7 @@
 #define arch_raw_cpu_ptr(_ptr)                                 \
 ({                                                             \
        unsigned long tcp_ptr__ = __raw_my_cpu_offset;          \
-       tcp_ptr__ += (unsigned long)(_ptr);                     \
+       tcp_ptr__ += (__force unsigned long)(_ptr);             \
        (typeof(*(_ptr)) __kernel __force *)tcp_ptr__;          \
 })
 #else
@@ -96,8 +96,8 @@
 #endif /* CONFIG_SMP */
 
 #define __my_cpu_type(var)     typeof(var) __percpu_seg_override
-#define __my_cpu_ptr(ptr)      (__my_cpu_type(*ptr) *)(uintptr_t)(ptr)
-#define __my_cpu_var(var)      (*__my_cpu_ptr(&var))
+#define __my_cpu_ptr(ptr)      (__my_cpu_type(*ptr)*)(__force uintptr_t)(ptr)
+#define __my_cpu_var(var)      (*__my_cpu_ptr(&(var)))
 #define __percpu_arg(x)                __percpu_prefix "%" #x
 #define __force_percpu_arg(x)  __force_percpu_prefix "%" #x