[PATCH 0/6] Add two-byte cmpxchg emulation and wire it into the architectures

Bradley Morgan posted 6 patches 1 week, 6 days ago
There is a newer version of this series
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(-)
[PATCH 0/6] Add two-byte cmpxchg emulation and wire it into the architectures
Posted by Bradley Morgan 1 week, 6 days ago
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
Re: [PATCH 0/6] Add two-byte cmpxchg emulation and wire it into the architectures
Posted by Arnd Bergmann 1 week, 6 days ago
On Fri, Sep 11, 2026, at 21:25, Bradley Morgan wrote:
> 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.

I can still restructure this and pull the INTEGRATOR_CM1136JFS
removal a little earlier. At the moment, this is part of the
patch to remove CPU_ARM1136R0, which I had planned to submit
once the arch/arm/mach-*/ platform removal patches are done:

https://git.kernel.org/pub/scm/linux/kernel/git/soc/soc.git/commit/?id=a8cfcc5533e33a

I could turn the mach-versatile/Kconfig change into a separate
(trivial) patch and add it to the platform series to avoid
churn here. The armv6 cmpxchg() code would still exist
in 7.4 then, but be unreachable.

       Arnd
Re: [PATCH 0/6] Add two-byte cmpxchg emulation and wire it into the architectures
Posted by Bradley Morgan 1 week, 6 days ago
On 11 September 2026 21:17:15 BST, Arnd Bergmann <arnd@arndb.de> wrote:
>On Fri, Sep 11, 2026, at 21:25, Bradley Morgan wrote:
>> 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.
>
>I can still restructure this and pull the INTEGRATOR_CM1136JFS
>removal a little earlier. At the moment, this is part of the
>patch to remove CPU_ARM1136R0, which I had planned to submit
>once the arch/arm/mach-*/ platform removal patches are done:
>
>https://git.kernel.org/pub/scm/linux/kernel/git/soc/soc.git/commit/?id=a8cfcc5533e33a
>
>I could turn the mach-versatile/Kconfig change into a separate
>(trivial) patch and add it to the platform series to avoid
>churn here. The armv6 cmpxchg() code would still exist
>in 7.4 then, but be unreachable.
>
>       Arnd
Hi, is this like V2 required? Or a *ugh fine that's ok* kinda message?
--- Thanks!
https://lore.kernel.org/all/EE579805-42F2-4C58-B752-F28779EEB717@grrlz.net/