Skip to content

Commit 62cedf3

Browse files
peda-ringomolnar
authored andcommitted
locking/rtmutex: Allow specifying a subclass for nested locking
Needed for annotating rt_mutex locks. Tested-by: John Sperbeck <jsperbeck@google.com> Signed-off-by: Peter Rosin <peda@axentia.se> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Davidlohr Bueso <dave@stgolabs.net> Cc: Deepa Dinamani <deepadinamani@google.com> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Chang <dpf@google.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Philippe Ombredanne <pombredanne@nexb.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Will Deacon <will.deacon@arm.com> Cc: Wolfram Sang <wsa@the-dreams.de> Link: http://lkml.kernel.org/r/20180720083914.1950-2-peda@axentia.se Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent d72e90f commit 62cedf3

2 files changed

Lines changed: 32 additions & 4 deletions

File tree

‎include/linux/rtmutex.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,14 @@ static inline int rt_mutex_is_locked(struct rt_mutex *lock)
106106
extern void __rt_mutex_init(struct rt_mutex *lock, const char *name, struct lock_class_key *key);
107107
extern void rt_mutex_destroy(struct rt_mutex *lock);
108108

109+
#ifdef CONFIG_DEBUG_LOCK_ALLOC
110+
extern void rt_mutex_lock_nested(struct rt_mutex *lock, unsigned int subclass);
111+
#define rt_mutex_lock(lock) rt_mutex_lock_nested(lock, 0)
112+
#else
109113
extern void rt_mutex_lock(struct rt_mutex *lock);
114+
#define rt_mutex_lock_nested(lock, subclass) rt_mutex_lock(lock)
115+
#endif
116+
110117
extern int rt_mutex_lock_interruptible(struct rt_mutex *lock);
111118
extern int rt_mutex_timed_lock(struct rt_mutex *lock,
112119
struct hrtimer_sleeper *timeout);

‎kernel/locking/rtmutex.c‎

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,19 +1465,40 @@ rt_mutex_fastunlock(struct rt_mutex *lock,
14651465
rt_mutex_postunlock(&wake_q);
14661466
}
14671467

1468+
static inline void __rt_mutex_lock(struct rt_mutex *lock, unsigned int subclass)
1469+
{
1470+
might_sleep();
1471+
1472+
mutex_acquire(&lock->dep_map, subclass, 0, _RET_IP_);
1473+
rt_mutex_fastlock(lock, TASK_UNINTERRUPTIBLE, rt_mutex_slowlock);
1474+
}
1475+
1476+
#ifdef CONFIG_DEBUG_LOCK_ALLOC
1477+
/**
1478+
* rt_mutex_lock_nested - lock a rt_mutex
1479+
*
1480+
* @lock: the rt_mutex to be locked
1481+
* @subclass: the lockdep subclass
1482+
*/
1483+
void __sched rt_mutex_lock_nested(struct rt_mutex *lock, unsigned int subclass)
1484+
{
1485+
__rt_mutex_lock(lock, subclass);
1486+
}
1487+
EXPORT_SYMBOL_GPL(rt_mutex_lock_nested);
1488+
#endif
1489+
1490+
#ifndef CONFIG_DEBUG_LOCK_ALLOC
14681491
/**
14691492
* rt_mutex_lock - lock a rt_mutex
14701493
*
14711494
* @lock: the rt_mutex to be locked
14721495
*/
14731496
void __sched rt_mutex_lock(struct rt_mutex *lock)
14741497
{
1475-
might_sleep();
1476-
1477-
mutex_acquire(&lock->dep_map, 0, 0, _RET_IP_);
1478-
rt_mutex_fastlock(lock, TASK_UNINTERRUPTIBLE, rt_mutex_slowlock);
1498+
__rt_mutex_lock(lock, 0);
14791499
}
14801500
EXPORT_SYMBOL_GPL(rt_mutex_lock);
1501+
#endif
14811502

14821503
/**
14831504
* rt_mutex_lock_interruptible - lock a rt_mutex interruptible

0 commit comments

Comments
 (0)