OSDN Git Service

arm64: spinlock: Fix theoretical trylock() A-B-A with LSE atomics
authorWill Deacon <will.deacon@arm.com>
Wed, 31 Jan 2018 12:12:20 +0000 (12:12 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 30 May 2018 05:48:56 +0000 (07:48 +0200)
commit07b1d60d79e7772dddbfd69a2fa8b4f471feb582
treeeb4d8f784ce5c9b100b0b965eedfb668b9926e64
parentc9eb334707d765eec7b4f6e23b294725b03df6d2
arm64: spinlock: Fix theoretical trylock() A-B-A with LSE atomics

[ Upstream commit 202fb4ef81e3ec765c23bd1e6746a5c25b797d0e ]

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: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/arm64/include/asm/spinlock.h