Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

percpu: use TYPEOF_UNQUAL() in *_cpu_ptr() accessors

Use TYPEOF_UNQUAL() macro to declare the return type of *_cpu_ptr()
accessors in the generic named address space to avoid access to data from
pointer to non-enclosed address space type of errors.

Link: https://lkml.kernel.org/r/20250127160709.80604-5-ubizjak@gmail.com
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Acked-by: Nadav Amit <nadav.amit@gmail.com>
Acked-by: Christoph Lameter <cl@linux.com>
Cc: Dennis Zhou <dennis@kernel.org>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Kent Overstreet <kent.overstreet@linux.dev>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: Waiman Long <longman@redhat.com>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Uros Bizjak and committed by
Andrew Morton
6a39fe05 8a3c3923

+7 -3
+6 -2
arch/x86/include/asm/percpu.h
··· 73 73 unsigned long tcp_ptr__ = raw_cpu_read_long(this_cpu_off); \ 74 74 \ 75 75 tcp_ptr__ += (__force unsigned long)(_ptr); \ 76 - (typeof(*(_ptr)) __kernel __force *)tcp_ptr__; \ 76 + (TYPEOF_UNQUAL(*(_ptr)) __force __kernel *)tcp_ptr__; \ 77 77 }) 78 78 #else 79 - #define arch_raw_cpu_ptr(_ptr) ({ BUILD_BUG(); (typeof(_ptr))0; }) 79 + #define arch_raw_cpu_ptr(_ptr) \ 80 + ({ \ 81 + BUILD_BUG(); \ 82 + (TYPEOF_UNQUAL(*(_ptr)) __force __kernel *)0; \ 83 + }) 80 84 #endif 81 85 82 86 #define PER_CPU_VAR(var) %__percpu_seg:(var)__percpu_rel
+1 -1
include/linux/percpu-defs.h
··· 221 221 } while (0) 222 222 223 223 #define PERCPU_PTR(__p) \ 224 - (typeof(*(__p)) __force __kernel *)((__force unsigned long)(__p)) 224 + (TYPEOF_UNQUAL(*(__p)) __force __kernel *)((__force unsigned long)(__p)) 225 225 226 226 #ifdef CONFIG_SMP 227 227