locking/xchg/alpha: Fix xchg() and cmpxchg() memory ordering bugs
authorAndrea Parri <[email protected]>
Thu, 22 Feb 2018 09:24:48 +0000 (10:24 +0100)
committerIngo Molnar <[email protected]>
Fri, 23 Feb 2018 07:38:16 +0000 (08:38 +0100)
commit472e8c55cf6622d1c112dc2bc777f68bbd4189db
tree8f91fed0fa1000eef3790b086903b6409ba50358
parent79d442461df7478cdd0c50d9b8a76f431f150fa3
locking/xchg/alpha: Fix xchg() and cmpxchg() memory ordering bugs

Successful RMW operations are supposed to be fully ordered, but
Alpha's xchg() and cmpxchg() do not meet this requirement.

Will Deacon noticed the bug:

  > So MP using xchg:
  >
  > WRITE_ONCE(x, 1)
  > xchg(y, 1)
  >
  > smp_load_acquire(y) == 1
  > READ_ONCE(x) == 0
  >
  > would be allowed.

... which thus violates the above requirement.

Fix it by adding a leading smp_mb() to the xchg() and cmpxchg() implementations.

Reported-by: Will Deacon <[email protected]>
Signed-off-by: Andrea Parri <[email protected]>
Acked-by: Paul E. McKenney <[email protected]>
Cc: Alan Stern <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: Ivan Kokshaysky <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Matt Turner <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: [email protected]
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
arch/alpha/include/asm/xchg.h