Skip to contentSkip to conversation

x86/percpu: Make CONFIG_USE_X86_SEG_SUPPORT work with sparse

PATCH Applied Thomas Gleixner 3 participants 3 messages Jan 18

Subsystems (2)
lore
Share & tools
lore

Thomas Gleixner

author maintainer
#0 lore raw

PATCH 1/1 x86/percpu: Make CONFIG_USE_X86_SEG_SUPPORT work with sparse

Now that sparse builds enforce the usage of typeof_unqual() the casts in __raw_cpu_read/write() cause sparse to emit tons of false postive warnings:

warning: cast removes address space '__percpu' of expression

Address this by annotating the casts with __force.

---
 arch/x86/include/asm/percpu.h |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
arch/x86/include/asm/percpu.h +4 -4
@@ -137,12 +137,12 @@
 
 #define __raw_cpu_read(size, qual, pcp)					\
 ({									\
-	*(qual __my_cpu_type(pcp) *)__my_cpu_ptr(&(pcp));		\
+	*(qual __my_cpu_type(pcp) * __force)__my_cpu_ptr(&(pcp));	\
 })
 
-#define __raw_cpu_write(size, qual, pcp, val)				\
-do {									\
-	*(qual __my_cpu_type(pcp) *)__my_cpu_ptr(&(pcp)) = (val);	\
+#define __raw_cpu_write(size, qual, pcp, val)					\
+do {										\
+	*(qual __my_cpu_type(pcp) * __force)__my_cpu_ptr(&(pcp)) = (val);	\
 } while (0)
 
 #define __raw_cpu_read_const(pcp)	__raw_cpu_read(, , pcp)
#1 lore raw
The following commit has been merged into the timers/vdso branch of tip:

The following commit has been merged into the timers/vdso branch of tip:

Commit-ID:     bbef8e2c29c32f048fac8e07f884f827d028f1da
Gitweb:        https://git.kernel.org/tip/bbef8e2c29c32f048fac8e07f884f827d028f1da
Author:        Thomas Gleixner <[email protected]>
AuthorDate:    Sun, 18 Jan 2026 15:45:40 +01:00
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Sun, 18 Jan 2026 15:54:17 +01:00

x86/percpu: Make CONFIG_USE_X86_SEG_SUPPORT work with sparse

Now that sparse builds enforce the usage of typeof_unqual() the casts in __raw_cpu_read/write() cause sparse to emit tons of false postive warnings:

warning: cast removes address space '__percpu' of expression

Address this by annotating the casts with __force.

---
 arch/x86/include/asm/percpu.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
arch/x86/include/asm/percpu.h +4 -4
index 725d0ef..c55058f 100644
@@ -137,12 +137,12 @@
 
 #define __raw_cpu_read(size, qual, pcp)					\
 ({									\
-	*(qual __my_cpu_type(pcp) *)__my_cpu_ptr(&(pcp));		\
+	*(qual __my_cpu_type(pcp) * __force)__my_cpu_ptr(&(pcp));	\
 })
 
-#define __raw_cpu_write(size, qual, pcp, val)				\
-do {									\
-	*(qual __my_cpu_type(pcp) *)__my_cpu_ptr(&(pcp)) = (val);	\
+#define __raw_cpu_write(size, qual, pcp, val)					\
+do {										\
+	*(qual __my_cpu_type(pcp) * __force)__my_cpu_ptr(&(pcp)) = (val);	\
 } while (0)
 
 #define __raw_cpu_read_const(pcp)	__raw_cpu_read(, , pcp)
#2 lore raw
In reply to Thomas Gleixner
Quoted 24 lines · Thomas Gleixner

Now that sparse builds enforce the usage of typeof_unqual() the casts in __raw_cpu_read/write() cause sparse to emit tons of false postive warnings:

warning: cast removes address space '__percpu' of expression

Address this by annotating the casts with __force.

---
  arch/x86/include/asm/percpu.h |    8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
arch/x86/include/asm/percpu.h +1 -1
@@ -137,12 +137,12 @@
 
  #define __raw_cpu_read(size, qual, pcp)					\
  ({									\
-	*(qual __my_cpu_type(pcp) *)__my_cpu_ptr(&(pcp));		\
+	*(qual __my_cpu_type(pcp) * __force)__my_cpu_ptr(&(pcp));	\
  })

arch/x86/include/asm/percpu.h line 148

Quoted 10 lines
arch/x86/include/asm/percpu.h +3 -3
 
-#define __raw_cpu_write(size, qual, pcp, val)				\
-do {									\
-	*(qual __my_cpu_type(pcp) *)__my_cpu_ptr(&(pcp)) = (val);	\
+#define __raw_cpu_write(size, qual, pcp, val)					\
+do {										\
+	*(qual __my_cpu_type(pcp) * __force)__my_cpu_ptr(&(pcp)) = (val);	\
  } while (0)
 
  #define __raw_cpu_read_const(pcp)	__raw_cpu_read(, , pcp)

Perhaps these defines can be simplified a bit as:

#define __raw_cpu_read(size, qual, pcp) \
	(*(qual __my_cpu_type(pcp) * __force)__my_cpu_ptr(&(pcp)))
#define __raw_cpu_write(size, qual, pcp, val) \
	(*(qual __my_cpu_type(pcp) * __force)__my_cpu_ptr(&(pcp)) = (val))

Uros.