Re: [PATCH RFC cmpxchg 0/8] Provide emulation for one- and two-byte cmpxchg()

From: Paul E. McKenney
Date: Mon Apr 08 2024 - 13:48:08 EST


Hello!

This series provides emulation functions for one-byte cmpxchg, and uses it
for those architectures not supporting this in hardware. The emulation
is in terms of the fully ordered four-byte cmpxchg() that is supplied
by all of these architectures. This was tested by making x86 forget
that it can do one-byte cmpxchg() natively:

88a9b3f7a924 ("EXP arch/x86: Test one-byte cmpxchg emulation")

This commit is local to -rcu and is of course not intended for mainline.

If accepted, RCU Tasks will use this capability in place of the current
rcu_trc_cmpxchg_need_qs() open-coding of this emulation.

1. sparc32: make __cmpxchg_u32() return u32, courtesy of Al Viro.

2. sparc32: make the first argument of __cmpxchg_u64() volatile u64 *,
courtesy of Al Viro.

3. sparc32: unify __cmpxchg_u{32,64}, courtesy of Al Viro.

4. sparc32: add __cmpxchg_u{8,16}() and teach __cmpxchg() to handle those
sizes, courtesy of Al Viro.

5. parisc: __cmpxchg_u32(): lift conversion into the callers, courtesy of
Al Viro.

6. parisc: unify implementations of __cmpxchg_u{8,32,64}, courtesy of
Al Viro.

7. parisc: add missing export of __cmpxchg_u8(), courtesy of Al Viro.

8. parisc: add u16 support to cmpxchg(), courtesy of Al Viro.

9. lib: Add one-byte emulation function.

10. ARC: Emulate one-byte cmpxchg.

11. csky: Emulate one-byte cmpxchg.

12. sh: Emulate one-byte cmpxchg.

13. xtensa: Emulate one-byte cmpxchg.

14. riscv: Emulate one-byte cmpxchg.

Changes since v1:

o Add native support for sparc32 and parisc, courtesy of Al Viro.

o Remove two-byte emulation due to architectures that still do not
support two-byte load and store instructions, per Arnd Bergmann
feedback. (Yes, there are a few systems out there that do not
even support one-byte load instructions, but these are slated
for removal anyway.)

o Fix numerous casting bugs spotted by kernel test robot.

o Fix SPDX header. "//" for .c files and "/*" for .h files.
I am sure that there is a good reason for this. ;-)

Thanx, Paul

------------------------------------------------------------------------

arch/parisc/include/asm/cmpxchg.h | 19 +++++-------
arch/parisc/kernel/parisc_ksyms.c | 1
arch/parisc/lib/bitops.c | 52 +++++++++++-----------------------
arch/sparc/include/asm/cmpxchg_32.h | 18 +++++------
arch/sparc/lib/atomic32.c | 47 +++++++++++++-----------------
b/arch/Kconfig | 3 +
b/arch/arc/Kconfig | 1
b/arch/arc/include/asm/cmpxchg.h | 32 +++++++++++++++-----
b/arch/csky/Kconfig | 1
b/arch/csky/include/asm/cmpxchg.h | 10 ++++++
b/arch/parisc/include/asm/cmpxchg.h | 3 -
b/arch/parisc/kernel/parisc_ksyms.c | 1
b/arch/parisc/lib/bitops.c | 6 +--
b/arch/riscv/Kconfig | 1
b/arch/riscv/include/asm/cmpxchg.h | 13 ++++++++
b/arch/sh/Kconfig | 1
b/arch/sh/include/asm/cmpxchg.h | 2 +
b/arch/sparc/include/asm/cmpxchg_32.h | 4 +-
b/arch/sparc/lib/atomic32.c | 4 +-
b/arch/xtensa/Kconfig | 1
b/arch/xtensa/include/asm/cmpxchg.h | 2 +
b/include/linux/cmpxchg-emu.h | 15 +++++++++
b/lib/Makefile | 1
b/lib/cmpxchg-emu.c | 45 +++++++++++++++++++++++++++++
24 files changed, 184 insertions(+), 99 deletions(-)