All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
To: linux-kernel@vger.kernel.org
Cc: Ben Segall <bsegall@google.com>,
	Boqun Feng <boqun.feng@gmail.com>,
	Daniel Bristot de Oliveira <bristot@redhat.com>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Ingo Molnar <mingo@redhat.com>,
	Juri Lelli <juri.lelli@redhat.com>, Mel Gorman <mgorman@suse.de>,
	Peter Zijlstra <peterz@infradead.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	Waiman Long <longman@redhat.com>, Will Deacon <will@kernel.org>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Subject: [PATCH 04/11] locking/rtmutex: Add rt_mutex_lock_nest_lock() and rt_mutex_lock_killable().
Date: Mon, 29 Nov 2021 18:46:47 +0100	[thread overview]
Message-ID: <20211129174654.668506-5-bigeasy@linutronix.de> (raw)
In-Reply-To: <20211129174654.668506-1-bigeasy@linutronix.de>

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>
---
 include/linux/rtmutex.h      |  9 +++++++++
 kernel/locking/rtmutex_api.c | 30 ++++++++++++++++++++++++++----
 2 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/include/linux/rtmutex.h b/include/linux/rtmutex.h
index 9deedfeec2b17..7d049883a08ac 100644
--- a/include/linux/rtmutex.h
+++ b/include/linux/rtmutex.h
@@ -99,13 +99,22 @@ extern void __rt_mutex_init(struct rt_mutex *lock, const char *name, struct lock
 
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
 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_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
 extern void rt_mutex_lock(struct rt_mutex *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
 
 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 void rt_mutex_unlock(struct rt_mutex *lock);
diff --git a/kernel/locking/rtmutex_api.c b/kernel/locking/rtmutex_api.c
index 5c9299aaabae1..900220941caac 100644
--- a/kernel/locking/rtmutex_api.c
+++ b/kernel/locking/rtmutex_api.c
@@ -21,12 +21,13 @@ int max_lock_depth = 1024;
  */
 static __always_inline int __rt_mutex_lock_common(struct rt_mutex *lock,
 						  unsigned int state,
+						  struct lockdep_map *nest_lock,
 						  unsigned int subclass)
 {
 	int ret;
 
 	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);
 	if (ret)
 		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)
 {
-	__rt_mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, subclass);
+	__rt_mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, NULL, subclass);
 }
 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 */
 
 /**
@@ -61,7 +68,7 @@ EXPORT_SYMBOL_GPL(rt_mutex_lock_nested);
  */
 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);
 #endif
@@ -77,10 +84,25 @@ EXPORT_SYMBOL_GPL(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);
 
+/**
+ * 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
  *
-- 
2.34.0


  parent reply	other threads:[~2021-11-29 22:37 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-29 17:46 [PATCH 00/11] lockdep: Unbreak lockdep's selftest work on PREEMPT_RT Sebastian Andrzej Siewior
2021-11-29 17:46 ` [PATCH 01/11] sched: Trigger warning if ->migration_disabled counter underflows Sebastian Andrzej Siewior
2021-12-02 21:02   ` Peter Zijlstra
2021-12-06 15:15   ` [tip: locking/core] " tip-bot2 for Sebastian Andrzej Siewior
2021-11-29 17:46 ` [PATCH 02/11] locking: Remove rt_rwlock_is_contended() Sebastian Andrzej Siewior
2021-12-06 15:15   ` [tip: locking/core] " tip-bot2 for Sebastian Andrzej Siewior
2021-11-29 17:46 ` [PATCH 03/11] locking/rtmutex: Squash self-deadlock check for ww_rt_mutex Sebastian Andrzej Siewior
2021-12-06 15:15   ` [tip: locking/core] " tip-bot2 for Peter Zijlstra
2021-11-29 17:46 ` Sebastian Andrzej Siewior [this message]
2021-12-06 15:15   ` [tip: locking/core] locking/rtmutex: Add rt_mutex_lock_nest_lock() and rt_mutex_lock_killable() tip-bot2 for Sebastian Andrzej Siewior
2021-11-29 17:46 ` [PATCH 05/11] lockdep: Remove softirq accounting on PREEMPT_RT Sebastian Andrzej Siewior
2021-12-06 15:15   ` [tip: locking/core] " tip-bot2 for Thomas Gleixner
2021-11-29 17:46 ` [PATCH 06/11] lockdep/selftests: Avoid using local_lock_{acquire|release}() Sebastian Andrzej Siewior
2021-12-06 15:15   ` [tip: locking/core] " tip-bot2 for Sebastian Andrzej Siewior
2021-11-29 17:46 ` [PATCH 07/11] lockdep/selftests: Unbalanced migrate_disable() & rcu_read_lock() Sebastian Andrzej Siewior
2021-12-06 15:15   ` [tip: locking/core] " tip-bot2 for Sebastian Andrzej Siewior
2021-11-29 17:46 ` [PATCH 08/11] lockdep/selftests: Skip the softirq related tests on PREEMPT_RT Sebastian Andrzej Siewior
2021-12-06 15:15   ` [tip: locking/core] " tip-bot2 for Sebastian Andrzej Siewior
2021-11-29 17:46 ` [PATCH 09/11] lockdep/selftests: Adapt ww-tests for PREEMPT_RT Sebastian Andrzej Siewior
2021-12-06 15:15   ` [tip: locking/core] " tip-bot2 for Sebastian Andrzej Siewior
2021-11-29 17:46 ` [PATCH 10/11] x86/mm: Include spinlock_t definition in pgtable Sebastian Andrzej Siewior
2021-12-07 14:22   ` [tip: locking/core] " tip-bot2 for Sebastian Andrzej Siewior
2021-11-29 17:46 ` [PATCH 11/11] locking: Allow to include asm/spinlock_types.h from linux/spinlock_types_raw.h Sebastian Andrzej Siewior
2021-11-29 17:46   ` Sebastian Andrzej Siewior
2021-11-29 17:46   ` Sebastian Andrzej Siewior
2021-11-29 17:46   ` Sebastian Andrzej Siewior
2021-11-29 17:46   ` Sebastian Andrzej Siewior
2021-11-29 17:46   ` Sebastian Andrzej Siewior
2021-12-07 14:22   ` [tip: locking/core] " tip-bot2 for Sebastian Andrzej Siewior
2021-12-02 21:12 ` [PATCH 00/11] lockdep: Unbreak lockdep's selftest work on PREEMPT_RT Peter Zijlstra
2021-12-06 15:26   ` Sebastian Andrzej Siewior
2021-12-06 15:43     ` Peter Zijlstra
2021-12-07 14:19       ` Peter Zijlstra
2021-12-07 14:30         ` Sebastian Andrzej Siewior

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211129174654.668506-5-bigeasy@linutronix.de \
    --to=bigeasy@linutronix.de \
    --cc=boqun.feng@gmail.com \
    --cc=bristot@redhat.com \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    --cc=vincent.guittot@linaro.org \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.