X-Git-Url: http://git.cascardo.info/?a=blobdiff_plain;f=kernel%2Flocking%2Fmutex.h;h=6cd6b8e9efd7f73175be41f46d062650da821af8;hb=8e4ef6386703835f91898334b72e48649646ec00;hp=a68bae5e852a08f1c0d75587b57c5e31835f937e;hpb=9454c23852ca6d7aec89fd6fd46a046c323caac3;p=cascardo%2Flinux.git diff --git a/kernel/locking/mutex.h b/kernel/locking/mutex.h index a68bae5e852a..6cd6b8e9efd7 100644 --- a/kernel/locking/mutex.h +++ b/kernel/locking/mutex.h @@ -17,14 +17,20 @@ __list_del((waiter)->list.prev, (waiter)->list.next) #ifdef CONFIG_MUTEX_SPIN_ON_OWNER +/* + * The mutex owner can get read and written to locklessly. + * We should use WRITE_ONCE when writing the owner value to + * avoid store tearing, otherwise, a thread could potentially + * read a partially written and incomplete owner value. + */ 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); } #else static inline void mutex_set_owner(struct mutex *lock)