Re: [PATCH 1/2] ARM: cmpxchg: support 2-byte xchg() on pre-ARMv6 CPUs

From: Arnd Bergmann

Date: Sat Oct 03 2026 - 06:14:28 EST


On Sat, Oct 3, 2026, at 11:38, Karl Mehltretter wrote:
> Pre-ARMv6 CPUs have no halfword swp, so __arch_xchg() only handles 1-
> and 4-byte exchanges there and turns any other size into a link error
> via __bad_xchg().

Note that 16-bit atomics are only in ARMv6K (1136r1, 1176),
not ARMv6 (1136r0).

> No C code needs a 16-bit xchg() on these CPUs, but the Rust atomic
> helpers in rust/helpers/atomic_ext.c provide xchg() for Atomic<i16>
> unconditionally, so building with CONFIG_RUST=y for ARMv5 fails:
>
> ld.lld: error: undefined symbol: __bad_xchg
> >>> referenced by helpers.c
> >>> rust/helpers/helpers.o:(rust_helper_atomic_i16_xchg)
>
> Implement the 2-byte case with interrupts disabled, as the pre-ARMv6
> atomic_t operations already do. This is safe because SMP requires
> ARMv6K or later.

This was previously impossible because you could have ARMv6 kernels
with SMP enabled, but now that Krzysztof has merged my series to
remove OMAP2 and i.MX6, this should work.

If anyone wants to backport this to older kernels, they would
also require d70242427110 ("ARM: rework ARM11 CPU selection logic").

Otherwise, this looks good,

Acked-by: Arnd Bergmann <arnd@xxxxxxxx>

Arnd