diff options
author | Jason Low <jason.low2@hpe.com> | 2016-05-21 00:19:36 +0200 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2016-06-03 12:06:10 +0200 |
commit | 6e2814745c67ab422b86262b05e6f23a56f28aa3 (patch) | |
tree | 5e69ae55af787319cca75bf6b767adc0180eaafb /kernel/locking/mutex-debug.h | |
parent | locking/rwsem: Optimize write lock by reducing operations in slowpath (diff) | |
download | linux-6e2814745c67ab422b86262b05e6f23a56f28aa3.tar.xz linux-6e2814745c67ab422b86262b05e6f23a56f28aa3.zip |
locking/mutex: Set and clear owner using WRITE_ONCE()
The mutex owner can get read and written to locklessly.
Use WRITE_ONCE when setting and clearing the owner field
in order to avoid optimizations such as store tearing. This
avoids situations where the owner field gets written to with
multiple stores and another thread could concurrently read
and use a partially written owner value.
Signed-off-by: Jason Low <jason.low2@hpe.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Davidlohr Bueso <dave@stgolabs.net>
Acked-by: Waiman Long <Waiman.Long@hpe.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Scott J Norton <scott.norton@hpe.com>
Cc: Terry Rudd <terry.rudd@hpe.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1463782776.2479.9.camel@j-VirtualBox
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'kernel/locking/mutex-debug.h')
-rw-r--r-- | kernel/locking/mutex-debug.h | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h index 0799fd3e4cfa..372e6530180d 100644 --- a/kernel/locking/mutex-debug.h +++ b/kernel/locking/mutex-debug.h @@ -29,12 +29,12 @@ extern void debug_mutex_init(struct mutex *lock, const char *name, static inline void mutex_set_owner(struct mutex *lock) { - lock->owner = current; + WRITE_ONCE(lock->owner, current); } static inline void mutex_clear_owner(struct mutex *lock) { - lock->owner = NULL; + WRITE_ONCE(lock->owner, NULL); } #define spin_lock_mutex(lock, flags) \ |