Subject: [PATCH v4 0/6] Enable strict percpu address space checks

From: Uros Bizjak <[email-masked]>
Date: Mon, 27 Jan 2025 17:05:04 +0100

Enable strict percpu address space checks via x86 named address space
qualifiers. Percpu variables are declared in __seg_gs/__seg_fs named
AS and kept named AS qualified until they are dereferenced via percpu
accessor. This approach enables various compiler checks for
cross-namespace variable assignments.

Please note that current version of sparse doesn't know anything about
__typeof_unqual__() operator. Avoid the usage of __typeof_unqual__()
when sparse checking is active to prevent sparse errors with unknowing
keyword. The proposed patch by Dan Carpenter to implement
__typeof_unqual__() handling in sparse is located at:

https://lore.kernel.org/lkml/[email-masked]/

v2: - Add comment to remove test for __CHECKER__ once sparse learns
      about __typeof_unqual__.
    - Add Acked-by: tags.
v3: - Rename __per_cpu_qual to __percpu_qual.
    - Add more Acked-by: tags.
v4: - Do not auto-detect compiler support for __typeof_unqual__()

Cc: Thomas Gleixner <[email-masked]>
Cc: Dennis Zhou <[email-masked]>
Cc: Tejun Heo <[email-masked]>
Cc: Christoph Lameter <[email-masked]>
Cc: Linus Torvalds <[email-masked]>
Cc: Andrew Morton <[email-masked]>
Cc: Andy Lutomirski <[email-masked]>
Cc: Ingo Molnar <[email-masked]>
Cc: Nadav Amit <[email-masked]>
Cc: Brian Gerst <[email-masked]>
Cc: Dan Carpenter <[email-masked]>
Cc: H. Peter Anvin <[email-masked]>
Cc: Peter Zijlstra <[email-masked]>

Uros Bizjak (6):
  x86/kgdb: Use IS_ERR_PCPU() macro
  compiler.h: Introduce TYPEOF_UNQUAL() macro
  percpu: Use TYPEOF_UNQUAL() in variable declarations
  percpu: Use TYPEOF_UNQUAL() in *_cpu_ptr() accessors
  percpu: Repurpose __percpu tag as a named address space qualifier
  percpu/x86: Enable strict percpu checks via named AS qualifiers

 arch/x86/include/asm/percpu.h  | 33 +++++++++++++++++++---------
 arch/x86/kernel/kgdb.c         |  2 +-
 fs/bcachefs/util.h             |  2 +-
 include/asm-generic/percpu.h   | 39 ++++++++++++++++++++++------------
 include/linux/compiler-clang.h |  8 +++++++
 include/linux/compiler-gcc.h   |  8 +++++++
 include/linux/compiler.h       | 20 +++++++++++++++++
 include/linux/compiler_types.h |  2 +-
 include/linux/part_stat.h      |  2 +-
 include/linux/percpu-defs.h    |  6 +++---
 include/net/snmp.h             |  5 ++---
 kernel/locking/percpu-rwsem.c  |  2 +-
 net/mpls/internal.h            |  4 ++--
 13 files changed, 97 insertions(+), 36 deletions(-)

-- 
2.42.0