From 3d59e21f75b1321b9eb7343d608889d5b63bf829 Mon Sep 17 00:00:00 2001 From: "yang.yang29@zte.com.cn" Date: Wed, 7 Jun 2023 13:42:32 +0800 Subject: [PATCH 1/3] rtmutex: Add rtmutex_lock_killable() commit bdcf220d6064da9072193b604f5fdaf9f7cf952f upstream. Add "killable" type to rtmutex. We need this since rtmutex are used as "normal" mutexes which do use this type. Signed-off-by: Thomas Gleixner --- include/linux/rtmutex.h | 1 + kernel/locking/rtmutex.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/include/linux/rtmutex.h b/include/linux/rtmutex.h index 6fd615a0eea9..81ece6a8291a 100644 --- a/include/linux/rtmutex.h +++ b/include/linux/rtmutex.h @@ -115,6 +115,7 @@ extern void rt_mutex_lock(struct rt_mutex *lock); #endif extern int rt_mutex_lock_interruptible(struct rt_mutex *lock); +extern int rt_mutex_lock_killable(struct rt_mutex *lock); extern int rt_mutex_timed_lock(struct rt_mutex *lock, struct hrtimer_sleeper *timeout); diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c index 1c3f56d3d9b6..a4b2af7718f8 100644 --- a/kernel/locking/rtmutex.c +++ b/kernel/locking/rtmutex.c @@ -1562,6 +1562,25 @@ int __sched __rt_mutex_futex_trylock(struct rt_mutex *lock) return __rt_mutex_slowtrylock(lock); } +/** + * rt_mutex_lock_killable - lock a rt_mutex killable + * + * @lock: the rt_mutex to be locked + * @detect_deadlock: deadlock detection on/off + * + * Returns: + * 0 on success + * -EINTR when interrupted by a signal + * -EDEADLK when the lock would deadlock (when deadlock detection is on) + */ +int __sched rt_mutex_lock_killable(struct rt_mutex *lock) +{ + might_sleep(); + + return rt_mutex_fastlock(lock, TASK_KILLABLE, rt_mutex_slowlock); +} +EXPORT_SYMBOL_GPL(rt_mutex_lock_killable); + /** * rt_mutex_timed_lock - lock a rt_mutex interruptible * the timeout structure is provided -- Gitee From ae2a84f3e8b43c570b05482ea90b614d980e005a Mon Sep 17 00:00:00 2001 From: "yang.yang29@zte.com.cn" Date: Wed, 7 Jun 2023 13:42:51 +0800 Subject: [PATCH 2/3] rtmutex: Make lock_killable work commit 6320c2a328b759909197f3ff76944b43141bc563 upstream. Locking an rt mutex killable does not work because signal handling is restricted to TASK_INTERRUPTIBLE. Use signal_pending_state() unconditionaly. Cc: stable-rt@vger.kernel.org Signed-off-by: Thomas Gleixner Signed-off-by: Sebastian Andrzej Siewior --- kernel/locking/rtmutex.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c index a4b2af7718f8..f058bb976212 100644 --- a/kernel/locking/rtmutex.c +++ b/kernel/locking/rtmutex.c @@ -1201,18 +1201,13 @@ __rt_mutex_slowlock(struct rt_mutex *lock, int state, if (try_to_take_rt_mutex(lock, current, waiter)) break; - /* - * TASK_INTERRUPTIBLE checks for signals and - * timeout. Ignored otherwise. - */ - if (likely(state == TASK_INTERRUPTIBLE)) { - /* Signal pending? */ - if (signal_pending(current)) - ret = -EINTR; - if (timeout && !timeout->task) - ret = -ETIMEDOUT; - if (ret) - break; + if (timeout && !timeout->task) { + ret = -ETIMEDOUT; + break; + } + if (signal_pending_state(state, current)) { + ret = -EINTR; + break; } raw_spin_unlock_irq(&lock->wait_lock); -- Gitee From a398cd623589f24c81c10ebb57f9b6e118b4d742 Mon Sep 17 00:00:00 2001 From: "yang.yang29@zte.com.cn" Date: Wed, 7 Jun 2023 13:45:57 +0800 Subject: [PATCH 3/3] rtmutex: Avoid include hell commit 66e71d123479ba1870a7b7ab6935f7f982379ca8 upstream. Include only the required raw types. This avoids pulling in the complete spinlock header which in turn requires rtmutex.h at some point. Signed-off-by: Thomas Gleixner --- include/linux/rtmutex.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/rtmutex.h b/include/linux/rtmutex.h index 81ece6a8291a..a355289b1fa1 100644 --- a/include/linux/rtmutex.h +++ b/include/linux/rtmutex.h @@ -15,7 +15,7 @@ #include #include -#include +#include extern int max_lock_depth; /* for sysctl */ -- Gitee