[PATCH 0/6] Add two-byte cmpxchg emulation and wire it into the architectures
From: Bradley Morgan
Date: Fri Sep 11 2026 - 15:36:27 EST
Paul McKenney asked me off list to add cmpxchg_emu_u16() next to
cmpxchg_emu_u8() and wire it into the architectures that use the
one byte emulation, arc, ARMv6, csky, sh and xtensa.
Patch 1 adds the function, the prototype, and renames the Kconfig
symbol to ARCH_NEED_CMPXCHG_1_2_EMU since it now gates both
emulations. Patches 2 through 6 add case 2 beside each existing
case 1, following each file's current style. The function body
follows the two byte implementation in Paul's April 2024 RFC
series, of which only the one byte part landed as commit
a88d970c8bb5 ("lib: Add one-byte emulation function").
Per Paul's note, Arnd Bergmann's platform removal series was
checked before analyzing the users. It removes the imx31 and
omap24xx CPU_ARM1136R0 selectors, but INTEGRATOR_CM1136JFS still
selects CPU_ARM1136R0 until its scheduled removal in early 2027,
so the ARMv6 path in patch 3 is still live. The arc !LLSC path
already handles any size because it reads and writes through the
typed pointer under the atomic_ops lock, so only the LLSC switch
gains case 2.
Verification. The union splice is endian independent because h[i]
sits at byte offset 2*i on both layouts and i is (addr & 2) / 2,
so the selected halfword always matches the caller's byte offset.
A host test ran 240 cases across both halfword offsets, matching
and mismatching compares, against a byte level reference model,
all passing. The function also compiles big endian for ARM, which
matters because sh is a big endian user. lib/cmpxchg-emu.o builds
for arm with CONFIG_CPU_V6 and a test instantiation of cmpxchg()
on a u16 resolves to cmpxchg_emu_u16. The remaining checkpatch
warnings are the volatile and long line ones that the merged
cmpxchg_emu_u8() lines already carry.
Bradley Morgan (6):
lib: Add two-byte cmpxchg emulation function
ARC: Emulate two-byte cmpxchg
ARM: Emulate two-byte cmpxchg on ARMv6
csky: Emulate two-byte cmpxchg
sh: Emulate two-byte cmpxchg
xtensa: Emulate two-byte cmpxchg
arch/Kconfig | 2 +-
arch/arc/Kconfig | 2 +-
arch/arc/include/asm/cmpxchg.h | 3 +++
arch/arm/Kconfig | 2 +-
arch/arm/include/asm/cmpxchg.h | 3 +++
arch/csky/Kconfig | 2 +-
arch/csky/include/asm/cmpxchg.h | 9 ++++++++
arch/sh/Kconfig | 2 +-
arch/sh/include/asm/cmpxchg.h | 2 ++
arch/xtensa/Kconfig | 2 +-
arch/xtensa/include/asm/cmpxchg.h | 1 +
include/linux/cmpxchg-emu.h | 1 +
lib/Makefile | 2 +-
lib/cmpxchg-emu.c | 35 ++++++++++++++++++++++++++++---
14 files changed, 58 insertions(+), 10 deletions(-)
--
2.47.3