[PATCH v2 08/12] s390/percpu: Use percpu code section for this_cpu_cmpxchg128()

From: Heiko Carstens

Date: Fri Sep 18 2026 - 04:52:03 EST


Convert this_cpu_cmpxchg128() to make use of percpu code section
functionality. This is just for the sake of completeness, since
currently there is no in-kernel user of this_cpu_cmpxchg128().

Signed-off-by: Heiko Carstens <hca@xxxxxxxxxxxxx>
---
arch/s390/include/asm/percpu.h | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/arch/s390/include/asm/percpu.h b/arch/s390/include/asm/percpu.h
index 78c3aaa138f7..0eae65937c0d 100644
--- a/arch/s390/include/asm/percpu.h
+++ b/arch/s390/include/asm/percpu.h
@@ -312,15 +312,23 @@ do { \
#define this_cpu_cmpxchg128(pcp, oval, nval) \
({ \
typedef typeof(pcp) pcp_op_T__; \
- u128 old__, new__, ret__; \
+ u128 old__ = (oval), new__ = (nval); \
pcp_op_T__ *ptr__; \
- old__ = oval; \
- new__ = nval; \
- preempt_disable_notrace(); \
- ptr__ = raw_cpu_ptr(&(pcp)); \
- ret__ = cmpxchg128((void *)ptr__, old__, new__); \
- preempt_enable_notrace(); \
- ret__; \
+ \
+ ptr__ = PERCPU_PTR(&(pcp)); \
+ asm_inline volatile( \
+ __PCPU_BEGIN("%[lcreg]","%[lcoff]","%[ptr__]") \
+ " cdsg %[old__],%[new__],0(%[ptr__])\n" \
+ __PCPU_END("%[lcreg]") \
+ : [old__] "+&d" (old__), [ptr__] "+&a" (ptr__), \
+ "+m" (*ptr__), \
+ "=m" (((struct lowcore *)0)->percpu_register) \
+ : [new__] "d" (new__), \
+ [lcreg] "i" (LC_PERCPU_REGISTER), \
+ [lcoff] "i" (LC_PERCPU_OFFSET), \
+ "m" (((struct lowcore *)0)->percpu_offset) \
+ : "memory", "cc"); \
+ old__; \
})

#define arch_this_cpu_xchg(pcp, nval) \
--
2.53.0