mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-11-30 14:26:42 +07:00
6e2814745c
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>
55 lines
1.5 KiB
C
55 lines
1.5 KiB
C
/*
|
|
* Mutexes: blocking mutual exclusion locks
|
|
*
|
|
* started by Ingo Molnar:
|
|
*
|
|
* Copyright (C) 2004, 2005, 2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
|
|
*
|
|
* This file contains mutex debugging related internal prototypes, for the
|
|
* !CONFIG_DEBUG_MUTEXES case. Most of them are NOPs:
|
|
*/
|
|
|
|
#define spin_lock_mutex(lock, flags) \
|
|
do { spin_lock(lock); (void)(flags); } while (0)
|
|
#define spin_unlock_mutex(lock, flags) \
|
|
do { spin_unlock(lock); (void)(flags); } while (0)
|
|
#define mutex_remove_waiter(lock, waiter, ti) \
|
|
__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)
|
|
{
|
|
WRITE_ONCE(lock->owner, current);
|
|
}
|
|
|
|
static inline void mutex_clear_owner(struct mutex *lock)
|
|
{
|
|
WRITE_ONCE(lock->owner, NULL);
|
|
}
|
|
#else
|
|
static inline void mutex_set_owner(struct mutex *lock)
|
|
{
|
|
}
|
|
|
|
static inline void mutex_clear_owner(struct mutex *lock)
|
|
{
|
|
}
|
|
#endif
|
|
|
|
#define debug_mutex_wake_waiter(lock, waiter) do { } while (0)
|
|
#define debug_mutex_free_waiter(waiter) do { } while (0)
|
|
#define debug_mutex_add_waiter(lock, waiter, ti) do { } while (0)
|
|
#define debug_mutex_unlock(lock) do { } while (0)
|
|
#define debug_mutex_init(lock, name, key) do { } while (0)
|
|
|
|
static inline void
|
|
debug_mutex_lock_common(struct mutex *lock, struct mutex_waiter *waiter)
|
|
{
|
|
}
|