[PATCH -tip 4/5] x86/percpu: Introduce __raw_cpu_read_const() macro

From: Uros Bizjak
Date: Tue Apr 30 2024 - 05:21:54 EST


Introduce __raw_cpu_read_const() macro to further reduce ifdeffery
and differences between configs w/ and w/o USE_X86_SEG_SUPPORT.

No functional change intended.

Signed-off-by: Uros Bizjak <ubizjak@xxxxxxxxx>
Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
Cc: Borislav Petkov <bp@xxxxxxxxx>
Cc: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>
Cc: "H. Peter Anvin" <hpa@xxxxxxxxx>
---
arch/x86/include/asm/percpu.h | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h
index f360ac5fccde..d20255138426 100644
--- a/arch/x86/include/asm/percpu.h
+++ b/arch/x86/include/asm/percpu.h
@@ -156,6 +156,8 @@ do { \
*(qual __my_cpu_type(pcp) *)__my_cpu_ptr(&(pcp)) = (val); \
} while (0)

+#define __raw_cpu_read_const(pcp) __raw_cpu_read(, , pcp)
+
#else /* CONFIG_USE_X86_SEG_SUPPORT */

#define __raw_cpu_read(size, qual, _var) \
@@ -180,6 +182,12 @@ do { \
: [val] __pcpu_reg_imm_##size(pto_val__)); \
} while (0)

+/*
+ * The generic per-cpu infrastrucutre is not suitable for
+ * reading const-qualified variables.
+ */
+#define __raw_cpu_read_const(pcp) ({ BUILD_BUG(); (typeof(pcp))0; })
+
#endif /* CONFIG_USE_X86_SEG_SUPPORT */

#define percpu_stable_op(size, op, _var) \
@@ -470,16 +478,7 @@ do { \
#define this_cpu_write_8(pcp, val) __raw_cpu_write(8, volatile, pcp, val)
#endif

-#ifdef CONFIG_USE_X86_SEG_SUPPORT
-#define this_cpu_read_const(pcp) __raw_cpu_read(, , pcp)
-#else /* CONFIG_USE_X86_SEG_SUPPORT */
-
-/*
- * The generic per-cpu infrastrucutre is not suitable for
- * reading const-qualified variables.
- */
-#define this_cpu_read_const(pcp) ({ BUILD_BUG(); (typeof(pcp))0; })
-#endif /* CONFIG_USE_X86_SEG_SUPPORT */
+#define this_cpu_read_const(pcp) __raw_cpu_read_const(pcp)

#define this_cpu_read_stable_1(pcp) percpu_stable_op(1, "mov", pcp)
#define this_cpu_read_stable_2(pcp) percpu_stable_op(2, "mov", pcp)
--
2.44.0