locking/rtmutex: Add rt_mutex_lock_nest_lock() and rt_mutex_lock_killable().

The locking selftest for ww-mutex expects to operate directly on the
base-mutex which becomes a rtmutex on PREEMPT_RT.

Add a rtmutex based implementation of mutex_lock_nest_lock() and
mutex_lock_killable() named rt_mutex_lock_nest_lock() abd
rt_mutex_lock_killable().

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/r/20211129174654.668506-5-bigeasy@linutronix.de
This commit is contained in:
Sebastian Andrzej Siewior 2021-11-29 18:46:47 +01:00 committed by Peter Zijlstra
parent 02ea9fc96f
commit a364202192
2 changed files with 35 additions and 4 deletions

View File

@ -99,13 +99,22 @@ extern void __rt_mutex_init(struct rt_mutex *lock, const char *name, struct lock
#ifdef CONFIG_DEBUG_LOCK_ALLOC #ifdef CONFIG_DEBUG_LOCK_ALLOC
extern void rt_mutex_lock_nested(struct rt_mutex *lock, unsigned int subclass); extern void rt_mutex_lock_nested(struct rt_mutex *lock, unsigned int subclass);
extern void _rt_mutex_lock_nest_lock(struct rt_mutex *lock, struct lockdep_map *nest_lock);
#define rt_mutex_lock(lock) rt_mutex_lock_nested(lock, 0) #define rt_mutex_lock(lock) rt_mutex_lock_nested(lock, 0)
#define rt_mutex_lock_nest_lock(lock, nest_lock) \
do { \
typecheck(struct lockdep_map *, &(nest_lock)->dep_map); \
_rt_mutex_lock_nest_lock(lock, &(nest_lock)->dep_map); \
} while (0)
#else #else
extern void rt_mutex_lock(struct rt_mutex *lock); extern void rt_mutex_lock(struct rt_mutex *lock);
#define rt_mutex_lock_nested(lock, subclass) rt_mutex_lock(lock) #define rt_mutex_lock_nested(lock, subclass) rt_mutex_lock(lock)
#define rt_mutex_lock_nest_lock(lock, nest_lock) rt_mutex_lock(lock)
#endif #endif
extern int rt_mutex_lock_interruptible(struct rt_mutex *lock); extern int rt_mutex_lock_interruptible(struct rt_mutex *lock);
extern int rt_mutex_lock_killable(struct rt_mutex *lock);
extern int rt_mutex_trylock(struct rt_mutex *lock); extern int rt_mutex_trylock(struct rt_mutex *lock);
extern void rt_mutex_unlock(struct rt_mutex *lock); extern void rt_mutex_unlock(struct rt_mutex *lock);

View File

@ -21,12 +21,13 @@ int max_lock_depth = 1024;
*/ */
static __always_inline int __rt_mutex_lock_common(struct rt_mutex *lock, static __always_inline int __rt_mutex_lock_common(struct rt_mutex *lock,
unsigned int state, unsigned int state,
struct lockdep_map *nest_lock,
unsigned int subclass) unsigned int subclass)
{ {
int ret; int ret;
might_sleep(); might_sleep();
mutex_acquire(&lock->dep_map, subclass, 0, _RET_IP_); mutex_acquire_nest(&lock->dep_map, subclass, 0, nest_lock, _RET_IP_);
ret = __rt_mutex_lock(&lock->rtmutex, state); ret = __rt_mutex_lock(&lock->rtmutex, state);
if (ret) if (ret)
mutex_release(&lock->dep_map, _RET_IP_); mutex_release(&lock->dep_map, _RET_IP_);
@ -48,10 +49,16 @@ EXPORT_SYMBOL(rt_mutex_base_init);
*/ */
void __sched rt_mutex_lock_nested(struct rt_mutex *lock, unsigned int subclass) void __sched rt_mutex_lock_nested(struct rt_mutex *lock, unsigned int subclass)
{ {
__rt_mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, subclass); __rt_mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, NULL, subclass);
} }
EXPORT_SYMBOL_GPL(rt_mutex_lock_nested); EXPORT_SYMBOL_GPL(rt_mutex_lock_nested);
void __sched _rt_mutex_lock_nest_lock(struct rt_mutex *lock, struct lockdep_map *nest_lock)
{
__rt_mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, nest_lock, 0);
}
EXPORT_SYMBOL_GPL(_rt_mutex_lock_nest_lock);
#else /* !CONFIG_DEBUG_LOCK_ALLOC */ #else /* !CONFIG_DEBUG_LOCK_ALLOC */
/** /**
@ -61,7 +68,7 @@ EXPORT_SYMBOL_GPL(rt_mutex_lock_nested);
*/ */
void __sched rt_mutex_lock(struct rt_mutex *lock) void __sched rt_mutex_lock(struct rt_mutex *lock)
{ {
__rt_mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, 0); __rt_mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, NULL, 0);
} }
EXPORT_SYMBOL_GPL(rt_mutex_lock); EXPORT_SYMBOL_GPL(rt_mutex_lock);
#endif #endif
@ -77,10 +84,25 @@ 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)
{ {
return __rt_mutex_lock_common(lock, TASK_INTERRUPTIBLE, 0); return __rt_mutex_lock_common(lock, TASK_INTERRUPTIBLE, NULL, 0);
} }
EXPORT_SYMBOL_GPL(rt_mutex_lock_interruptible); EXPORT_SYMBOL_GPL(rt_mutex_lock_interruptible);
/**
* rt_mutex_lock_killable - lock a rt_mutex killable
*
* @lock: the rt_mutex to be locked
*
* Returns:
* 0 on success
* -EINTR when interrupted by a signal
*/
int __sched rt_mutex_lock_killable(struct rt_mutex *lock)
{
return __rt_mutex_lock_common(lock, TASK_KILLABLE, NULL, 0);
}
EXPORT_SYMBOL_GPL(rt_mutex_lock_killable);
/** /**
* rt_mutex_trylock - try to lock a rt_mutex * rt_mutex_trylock - try to lock a rt_mutex
* *