Commit 07b1d60d authored by Will Deacon's avatar Will Deacon Committed by Greg Kroah-Hartman

arm64: spinlock: Fix theoretical trylock() A-B-A with LSE atomics

[ Upstream commit 202fb4ef ]

If the spinlock "next" ticket wraps around between the initial LDR
and the cmpxchg in the LSE version of spin_trylock, then we can erroneously
think that we have successfuly acquired the lock because we only check
whether the next ticket return by the cmpxchg is equal to the owner ticket
in our updated lock word.

This patch fixes the issue by performing a full 32-bit check of the lock
word when trying to determine whether or not the CASA instruction updated
memory.
Reported-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
Signed-off-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent c9eb3347
...@@ -94,8 +94,8 @@ static inline int arch_spin_trylock(arch_spinlock_t *lock) ...@@ -94,8 +94,8 @@ static inline int arch_spin_trylock(arch_spinlock_t *lock)
" cbnz %w1, 1f\n" " cbnz %w1, 1f\n"
" add %w1, %w0, %3\n" " add %w1, %w0, %3\n"
" casa %w0, %w1, %2\n" " casa %w0, %w1, %2\n"
" and %w1, %w1, #0xffff\n" " sub %w1, %w1, %3\n"
" eor %w1, %w1, %w0, lsr #16\n" " eor %w1, %w1, %w0\n"
"1:") "1:")
: "=&r" (lockval), "=&r" (tmp), "+Q" (*lock) : "=&r" (lockval), "=&r" (tmp), "+Q" (*lock)
: "I" (1 << TICKET_SHIFT) : "I" (1 << TICKET_SHIFT)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment