s390/cmpxchg: make loop condition for 1,2 byte cases precise
authorJanis Schoetterl-Glausch <scgl@linux.ibm.com>
Wed, 16 Nov 2022 14:47:11 +0000 (15:47 +0100)
committerHeiko Carstens <hca@linux.ibm.com>
Mon, 21 Nov 2022 12:36:16 +0000 (13:36 +0100)
commit51098f0eb22e2f54055d75dd25bc84eff07d6d8a
tree1fe906286f11fce413e7f335b7d70e8350ab4459
parent4148575abe1e14af3cb9fd1a3c9c2a708ec0b1f9
s390/cmpxchg: make loop condition for 1,2 byte cases precise

The cmpxchg implementation for 1 and 2 bytes consists of a 4 byte
cmpxchg loop. Currently, the decision to retry is imprecise, looping if
bits outside the target byte(s) change instead of retrying until the
target byte(s) differ from the old value.
E.g. if an attempt to exchange (prev_left_0 old_bytes prev_right_0) is
made and it fails because the word at the address is
(prev_left_1 x prev_right_1) where both x != old_bytes and one of the
prev_*_1 values differs from the respective prev_*_0 value, the cmpxchg
is retried, even if by a semantic equivalent to a normal cmpxchg, the
exchange would fail.
Instead exit the loop if x != old_bytes and retry otherwise.

Signed-off-by: Janis Schoetterl-Glausch <scgl@linux.ibm.com>
Link: https://lore.kernel.org/r/20221116144711.3811011-1-scgl@linux.ibm.com
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
arch/s390/include/asm/cmpxchg.h
arch/s390/include/asm/uaccess.h