aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--kernel/locking/mutex-debug.h4
-rw-r--r--kernel/locking/mutex.h10
2 files changed, 10 insertions, 4 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,
29 29
30static inline void mutex_set_owner(struct mutex *lock) 30static inline void mutex_set_owner(struct mutex *lock)
31{ 31{
32 lock->owner = current; 32 WRITE_ONCE(lock->owner, current);
33} 33}
34 34
35static inline void mutex_clear_owner(struct mutex *lock) 35static inline void mutex_clear_owner(struct mutex *lock)
36{ 36{
37 lock->owner = NULL; 37 WRITE_ONCE(lock->owner, NULL);
38} 38}
39 39
40#define spin_lock_mutex(lock, flags) \ 40#define spin_lock_mutex(lock, flags) \
diff --git a/kernel/locking/mutex.h b/kernel/locking/mutex.h
index 5cda397607f2..12f96199441c 100644
--- a/kernel/locking/mutex.h
+++ b/kernel/locking/mutex.h
@@ -17,14 +17,20 @@
17 __list_del((waiter)->list.prev, (waiter)->list.next) 17 __list_del((waiter)->list.prev, (waiter)->list.next)
18 18
19#ifdef CONFIG_MUTEX_SPIN_ON_OWNER 19#ifdef CONFIG_MUTEX_SPIN_ON_OWNER
20/*
21 * The mutex owner can get read and written to locklessly.
22 * We should use WRITE_ONCE when writing the owner value to
23 * avoid store tearing, otherwise, a thread could potentially
24 * read a partially written and incomplete owner value.
25 */
20static inline void mutex_set_owner(struct mutex *lock) 26static inline void mutex_set_owner(struct mutex *lock)
21{ 27{
22 lock->owner = current; 28 WRITE_ONCE(lock->owner, current);
23} 29}
24 30
25static inline void mutex_clear_owner(struct mutex *lock) 31static inline void mutex_clear_owner(struct mutex *lock)
26{ 32{
27 lock->owner = NULL; 33 WRITE_ONCE(lock->owner, NULL);
28} 34}
29#else 35#else
30static inline void mutex_set_owner(struct mutex *lock) 36static inline void mutex_set_owner(struct mutex *lock)