arm64: spinlock: fix spin_unlock_wait for LSE atomics
authorWill Deacon <will.deacon@arm.com>
Wed, 8 Jun 2016 14:10:57 +0000 (15:10 +0100)
committerAlex Shi <alex.shi@linaro.org>
Thu, 23 Mar 2017 03:48:39 +0000 (11:48 +0800)
commit78732f2e083800c5044e3c4b8161e5fc7a1d4adc
treec74b5f314d04c7dc4346173669cc2b85da8ed832
parentb1c272801015672bac0fb0b4398cd94a47b70f66
arm64: spinlock: fix spin_unlock_wait for LSE atomics

Commit d86b8da04dfa ("arm64: spinlock: serialise spin_unlock_wait against
concurrent lockers") fixed spin_unlock_wait for LL/SC-based atomics under
the premise that the LSE atomics (in particular, the LDADDA instruction)
are indivisible.

Unfortunately, these instructions are only indivisible when used with the
-AL (full ordering) suffix and, consequently, the same issue can
theoretically be observed with LSE atomics, where a later (in program
order) load can be speculated before the write portion of the atomic
operation.

This patch fixes the issue by performing a CAS of the lock once we've
established that it's unlocked, in much the same way as the LL/SC code.

Fixes: d86b8da04dfa ("arm64: spinlock: serialise spin_unlock_wait against concurrent lockers")
Signed-off-by: Will Deacon <will.deacon@arm.com>
(cherry picked from commit 3a5facd09da848193f5bcb0dea098a298bc1a29d)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
arch/arm64/include/asm/spinlock.h