Commit f5694788 authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Ingo Molnar

rt_mutex: Add lockdep annotations

Now that (PI) futexes have their own private RT-mutex interface and
implementation we can easily add lockdep annotations to the existing
RT-mutex interface.
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 3942b771
...@@ -37,6 +37,9 @@ struct rt_mutex { ...@@ -37,6 +37,9 @@ struct rt_mutex {
int line; int line;
void *magic; void *magic;
#endif #endif
#ifdef CONFIG_DEBUG_LOCK_ALLOC
struct lockdep_map dep_map;
#endif
}; };
struct rt_mutex_waiter; struct rt_mutex_waiter;
...@@ -58,19 +61,33 @@ struct hrtimer_sleeper; ...@@ -58,19 +61,33 @@ struct hrtimer_sleeper;
#ifdef CONFIG_DEBUG_RT_MUTEXES #ifdef CONFIG_DEBUG_RT_MUTEXES
# define __DEBUG_RT_MUTEX_INITIALIZER(mutexname) \ # define __DEBUG_RT_MUTEX_INITIALIZER(mutexname) \
, .name = #mutexname, .file = __FILE__, .line = __LINE__ , .name = #mutexname, .file = __FILE__, .line = __LINE__
# define rt_mutex_init(mutex) __rt_mutex_init(mutex, __func__)
# define rt_mutex_init(mutex) \
do { \
static struct lock_class_key __key; \
__rt_mutex_init(mutex, __func__, &__key); \
} while (0)
extern void rt_mutex_debug_task_free(struct task_struct *tsk); extern void rt_mutex_debug_task_free(struct task_struct *tsk);
#else #else
# define __DEBUG_RT_MUTEX_INITIALIZER(mutexname) # define __DEBUG_RT_MUTEX_INITIALIZER(mutexname)
# define rt_mutex_init(mutex) __rt_mutex_init(mutex, NULL) # define rt_mutex_init(mutex) __rt_mutex_init(mutex, NULL, NULL)
# define rt_mutex_debug_task_free(t) do { } while (0) # define rt_mutex_debug_task_free(t) do { } while (0)
#endif #endif
#ifdef CONFIG_DEBUG_LOCK_ALLOC
#define __DEP_MAP_RT_MUTEX_INITIALIZER(mutexname) \
, .dep_map = { .name = #mutexname }
#else
#define __DEP_MAP_RT_MUTEX_INITIALIZER(mutexname)
#endif
#define __RT_MUTEX_INITIALIZER(mutexname) \ #define __RT_MUTEX_INITIALIZER(mutexname) \
{ .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(mutexname.wait_lock) \ { .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(mutexname.wait_lock) \
, .waiters = RB_ROOT \ , .waiters = RB_ROOT \
, .owner = NULL \ , .owner = NULL \
__DEBUG_RT_MUTEX_INITIALIZER(mutexname)} __DEBUG_RT_MUTEX_INITIALIZER(mutexname) \
__DEP_MAP_RT_MUTEX_INITIALIZER(mutexname)}
#define DEFINE_RT_MUTEX(mutexname) \ #define DEFINE_RT_MUTEX(mutexname) \
struct rt_mutex mutexname = __RT_MUTEX_INITIALIZER(mutexname) struct rt_mutex mutexname = __RT_MUTEX_INITIALIZER(mutexname)
...@@ -86,7 +103,7 @@ static inline int rt_mutex_is_locked(struct rt_mutex *lock) ...@@ -86,7 +103,7 @@ static inline int rt_mutex_is_locked(struct rt_mutex *lock)
return lock->owner != NULL; return lock->owner != NULL;
} }
extern void __rt_mutex_init(struct rt_mutex *lock, const char *name); extern void __rt_mutex_init(struct rt_mutex *lock, const char *name, struct lock_class_key *key);
extern void rt_mutex_destroy(struct rt_mutex *lock); extern void rt_mutex_destroy(struct rt_mutex *lock);
extern void rt_mutex_lock(struct rt_mutex *lock); extern void rt_mutex_lock(struct rt_mutex *lock);
......
...@@ -166,12 +166,16 @@ void debug_rt_mutex_free_waiter(struct rt_mutex_waiter *waiter) ...@@ -166,12 +166,16 @@ void debug_rt_mutex_free_waiter(struct rt_mutex_waiter *waiter)
memset(waiter, 0x22, sizeof(*waiter)); memset(waiter, 0x22, sizeof(*waiter));
} }
void debug_rt_mutex_init(struct rt_mutex *lock, const char *name) void debug_rt_mutex_init(struct rt_mutex *lock, const char *name, struct lock_class_key *key)
{ {
/* /*
* Make sure we are not reinitializing a held lock: * Make sure we are not reinitializing a held lock:
*/ */
debug_check_no_locks_freed((void *)lock, sizeof(*lock)); debug_check_no_locks_freed((void *)lock, sizeof(*lock));
lock->name = name; lock->name = name;
#ifdef CONFIG_DEBUG_LOCK_ALLOC
lockdep_init_map(&lock->dep_map, name, key, 0);
#endif
} }
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
extern void debug_rt_mutex_init_waiter(struct rt_mutex_waiter *waiter); extern void debug_rt_mutex_init_waiter(struct rt_mutex_waiter *waiter);
extern void debug_rt_mutex_free_waiter(struct rt_mutex_waiter *waiter); extern void debug_rt_mutex_free_waiter(struct rt_mutex_waiter *waiter);
extern void debug_rt_mutex_init(struct rt_mutex *lock, const char *name); extern void debug_rt_mutex_init(struct rt_mutex *lock, const char *name, struct lock_class_key *key);
extern void debug_rt_mutex_lock(struct rt_mutex *lock); extern void debug_rt_mutex_lock(struct rt_mutex *lock);
extern void debug_rt_mutex_unlock(struct rt_mutex *lock); extern void debug_rt_mutex_unlock(struct rt_mutex *lock);
extern void debug_rt_mutex_proxy_lock(struct rt_mutex *lock, extern void debug_rt_mutex_proxy_lock(struct rt_mutex *lock,
......
...@@ -1481,6 +1481,7 @@ void __sched rt_mutex_lock(struct rt_mutex *lock) ...@@ -1481,6 +1481,7 @@ void __sched rt_mutex_lock(struct rt_mutex *lock)
{ {
might_sleep(); might_sleep();
mutex_acquire(&lock->dep_map, 0, 0, _RET_IP_);
rt_mutex_fastlock(lock, TASK_UNINTERRUPTIBLE, rt_mutex_slowlock); rt_mutex_fastlock(lock, TASK_UNINTERRUPTIBLE, rt_mutex_slowlock);
} }
EXPORT_SYMBOL_GPL(rt_mutex_lock); EXPORT_SYMBOL_GPL(rt_mutex_lock);
...@@ -1496,9 +1497,16 @@ EXPORT_SYMBOL_GPL(rt_mutex_lock); ...@@ -1496,9 +1497,16 @@ EXPORT_SYMBOL_GPL(rt_mutex_lock);
*/ */
int __sched rt_mutex_lock_interruptible(struct rt_mutex *lock) int __sched rt_mutex_lock_interruptible(struct rt_mutex *lock)
{ {
int ret;
might_sleep(); might_sleep();
return rt_mutex_fastlock(lock, TASK_INTERRUPTIBLE, rt_mutex_slowlock); mutex_acquire(&lock->dep_map, 0, 0, _RET_IP_);
ret = rt_mutex_fastlock(lock, TASK_INTERRUPTIBLE, rt_mutex_slowlock);
if (ret)
mutex_release(&lock->dep_map, 1, _RET_IP_);
return ret;
} }
EXPORT_SYMBOL_GPL(rt_mutex_lock_interruptible); EXPORT_SYMBOL_GPL(rt_mutex_lock_interruptible);
...@@ -1526,11 +1534,18 @@ int __sched rt_mutex_futex_trylock(struct rt_mutex *lock) ...@@ -1526,11 +1534,18 @@ int __sched rt_mutex_futex_trylock(struct rt_mutex *lock)
int int
rt_mutex_timed_lock(struct rt_mutex *lock, struct hrtimer_sleeper *timeout) rt_mutex_timed_lock(struct rt_mutex *lock, struct hrtimer_sleeper *timeout)
{ {
int ret;
might_sleep(); might_sleep();
return rt_mutex_timed_fastlock(lock, TASK_INTERRUPTIBLE, timeout, mutex_acquire(&lock->dep_map, 0, 0, _RET_IP_);
ret = rt_mutex_timed_fastlock(lock, TASK_INTERRUPTIBLE, timeout,
RT_MUTEX_MIN_CHAINWALK, RT_MUTEX_MIN_CHAINWALK,
rt_mutex_slowlock); rt_mutex_slowlock);
if (ret)
mutex_release(&lock->dep_map, 1, _RET_IP_);
return ret;
} }
EXPORT_SYMBOL_GPL(rt_mutex_timed_lock); EXPORT_SYMBOL_GPL(rt_mutex_timed_lock);
...@@ -1547,10 +1562,16 @@ EXPORT_SYMBOL_GPL(rt_mutex_timed_lock); ...@@ -1547,10 +1562,16 @@ EXPORT_SYMBOL_GPL(rt_mutex_timed_lock);
*/ */
int __sched rt_mutex_trylock(struct rt_mutex *lock) int __sched rt_mutex_trylock(struct rt_mutex *lock)
{ {
int ret;
if (WARN_ON_ONCE(in_irq() || in_nmi() || in_serving_softirq())) if (WARN_ON_ONCE(in_irq() || in_nmi() || in_serving_softirq()))
return 0; return 0;
return rt_mutex_fasttrylock(lock, rt_mutex_slowtrylock); ret = rt_mutex_fasttrylock(lock, rt_mutex_slowtrylock);
if (ret)
mutex_acquire(&lock->dep_map, 0, 1, _RET_IP_);
return ret;
} }
EXPORT_SYMBOL_GPL(rt_mutex_trylock); EXPORT_SYMBOL_GPL(rt_mutex_trylock);
...@@ -1561,6 +1582,7 @@ EXPORT_SYMBOL_GPL(rt_mutex_trylock); ...@@ -1561,6 +1582,7 @@ EXPORT_SYMBOL_GPL(rt_mutex_trylock);
*/ */
void __sched rt_mutex_unlock(struct rt_mutex *lock) void __sched rt_mutex_unlock(struct rt_mutex *lock)
{ {
mutex_release(&lock->dep_map, 1, _RET_IP_);
rt_mutex_fastunlock(lock, rt_mutex_slowunlock); rt_mutex_fastunlock(lock, rt_mutex_slowunlock);
} }
EXPORT_SYMBOL_GPL(rt_mutex_unlock); EXPORT_SYMBOL_GPL(rt_mutex_unlock);
...@@ -1620,7 +1642,6 @@ void rt_mutex_destroy(struct rt_mutex *lock) ...@@ -1620,7 +1642,6 @@ void rt_mutex_destroy(struct rt_mutex *lock)
lock->magic = NULL; lock->magic = NULL;
#endif #endif
} }
EXPORT_SYMBOL_GPL(rt_mutex_destroy); EXPORT_SYMBOL_GPL(rt_mutex_destroy);
/** /**
...@@ -1632,14 +1653,15 @@ EXPORT_SYMBOL_GPL(rt_mutex_destroy); ...@@ -1632,14 +1653,15 @@ EXPORT_SYMBOL_GPL(rt_mutex_destroy);
* *
* Initializing of a locked rt lock is not allowed * Initializing of a locked rt lock is not allowed
*/ */
void __rt_mutex_init(struct rt_mutex *lock, const char *name) void __rt_mutex_init(struct rt_mutex *lock, const char *name,
struct lock_class_key *key)
{ {
lock->owner = NULL; lock->owner = NULL;
raw_spin_lock_init(&lock->wait_lock); raw_spin_lock_init(&lock->wait_lock);
lock->waiters = RB_ROOT; lock->waiters = RB_ROOT;
lock->waiters_leftmost = NULL; lock->waiters_leftmost = NULL;
debug_rt_mutex_init(lock, name); debug_rt_mutex_init(lock, name, key);
} }
EXPORT_SYMBOL_GPL(__rt_mutex_init); EXPORT_SYMBOL_GPL(__rt_mutex_init);
...@@ -1660,7 +1682,7 @@ EXPORT_SYMBOL_GPL(__rt_mutex_init); ...@@ -1660,7 +1682,7 @@ EXPORT_SYMBOL_GPL(__rt_mutex_init);
void rt_mutex_init_proxy_locked(struct rt_mutex *lock, void rt_mutex_init_proxy_locked(struct rt_mutex *lock,
struct task_struct *proxy_owner) struct task_struct *proxy_owner)
{ {
__rt_mutex_init(lock, NULL); __rt_mutex_init(lock, NULL, NULL);
debug_rt_mutex_proxy_lock(lock, proxy_owner); debug_rt_mutex_proxy_lock(lock, proxy_owner);
rt_mutex_set_owner(lock, proxy_owner); rt_mutex_set_owner(lock, proxy_owner);
} }
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#define debug_rt_mutex_proxy_lock(l,p) do { } while (0) #define debug_rt_mutex_proxy_lock(l,p) do { } while (0)
#define debug_rt_mutex_proxy_unlock(l) do { } while (0) #define debug_rt_mutex_proxy_unlock(l) do { } while (0)
#define debug_rt_mutex_unlock(l) do { } while (0) #define debug_rt_mutex_unlock(l) do { } while (0)
#define debug_rt_mutex_init(m, n) do { } while (0) #define debug_rt_mutex_init(m, n, k) do { } while (0)
#define debug_rt_mutex_deadlock(d, a ,l) do { } while (0) #define debug_rt_mutex_deadlock(d, a ,l) do { } while (0)
#define debug_rt_mutex_print_deadlock(w) do { } while (0) #define debug_rt_mutex_print_deadlock(w) do { } while (0)
#define debug_rt_mutex_reset_waiter(w) do { } while (0) #define debug_rt_mutex_reset_waiter(w) do { } while (0)
......
...@@ -1052,6 +1052,7 @@ config DEBUG_LOCK_ALLOC ...@@ -1052,6 +1052,7 @@ config DEBUG_LOCK_ALLOC
depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
select DEBUG_SPINLOCK select DEBUG_SPINLOCK
select DEBUG_MUTEXES select DEBUG_MUTEXES
select DEBUG_RT_MUTEXES if RT_MUTEXES
select LOCKDEP select LOCKDEP
help help
This feature will check whether any held lock (spinlock, rwlock, This feature will check whether any held lock (spinlock, rwlock,
...@@ -1067,6 +1068,7 @@ config PROVE_LOCKING ...@@ -1067,6 +1068,7 @@ config PROVE_LOCKING
select LOCKDEP select LOCKDEP
select DEBUG_SPINLOCK select DEBUG_SPINLOCK
select DEBUG_MUTEXES select DEBUG_MUTEXES
select DEBUG_RT_MUTEXES if RT_MUTEXES
select DEBUG_LOCK_ALLOC select DEBUG_LOCK_ALLOC
select TRACE_IRQFLAGS select TRACE_IRQFLAGS
default n default n
...@@ -1121,6 +1123,7 @@ config LOCK_STAT ...@@ -1121,6 +1123,7 @@ config LOCK_STAT
select LOCKDEP select LOCKDEP
select DEBUG_SPINLOCK select DEBUG_SPINLOCK
select DEBUG_MUTEXES select DEBUG_MUTEXES
select DEBUG_RT_MUTEXES if RT_MUTEXES
select DEBUG_LOCK_ALLOC select DEBUG_LOCK_ALLOC
default n default n
help help
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment