Add emulation of two-byte cmpxchg()

These commits add a cmpxchg_emu_u16() function that emulates two-byte
cmpxchg() in terms of four-byte cmpxchg() for architectures not having
native instructions for this purpose.  They also make use of this
cmpxchg_emu_u16() function in those architectures, namely sh, arc, csky,
and xtensa.  This permits use of two-byte cmpxchg() in common code.

However, it sadly does not permit easy implementation of all algorithms
needing on two-byte atomic operations because there are some systems still
supported by Linux that do not have native two-byte store instructions.
There is reason to believe that these systems will soon no longer be
supported by Linux.
xtensa: Emulate two-byte cmpxchg

Xtensa has no two-byte atomic compare and swap, so the __cmpxchg()
switch lets case 2 fall through to __cmpxchg_called_with_bad_pointer(),
which is declared but never defined, so a two-byte cmpxchg() fails
at link time.

Route case 2 through the new cmpxchg_emu_u16(), which takes the
old and new values as unsigned long and narrows them itself, so
the call needs no extra casts.

Signed-off-by: Bradley Morgan <brads@mainlining.org>
Reviewed-by: Max Filippov <jcmvbkbc@gmail.com>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
1 file changed