public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Bart Van Assche <bvanassche@acm.org>
Cc: Marco Elver <elver@google.com>,
	linux-kernel@vger.kernel.org, Ingo Molnar <mingo@redhat.com>,
	Will Deacon <will@kernel.org>, Boqun Feng <boqun@kernel.org>,
	Joel Granados <joel.granados@kernel.org>,
	Alexei Starovoitov <ast@kernel.org>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	Vlastimil Babka <vbabka@kernel.org>
Subject: Re: [PATCH] locking/rtmutex: Annotate API and implementation
Date: Mon, 4 May 2026 11:39:32 +0200	[thread overview]
Message-ID: <20260504093932.GR3126523@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20260502015354.430273-1-bvanassche@acm.org>

On Fri, May 01, 2026 at 06:53:49PM -0700, Bart Van Assche wrote:
> Add lock context annotations to the rtmutex API and implementation and
> enable lock context analysis.
> 
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>

This does not build, I need at least the below, but then PREEMPT_RT is
still not happy.

---
--- a/include/linux/rtmutex.h
+++ b/include/linux/rtmutex.h
@@ -20,7 +20,7 @@
 
 extern int max_lock_depth;
 
-struct rt_mutex_base {
+context_lock_struct(rt_mutex_base) {
 	raw_spinlock_t		wait_lock;
 	struct rb_root_cached   waiters __guarded_by(&wait_lock);
 	struct task_struct	*owner  __guarded_by(&wait_lock);
--- a/kernel/locking/rtmutex.c
+++ b/kernel/locking/rtmutex.c
@@ -314,6 +314,7 @@ static __always_inline bool rt_mutex_cmp
 static int __sched rt_mutex_slowtrylock(struct rt_mutex_base *lock);
 
 static __always_inline bool rt_mutex_try_acquire(struct rt_mutex_base *lock)
+	__cond_acquires(true, lock)
 {
 	/*
 	 * With debug enabled rt_mutex_cmpxchg trylock() will always fail.
@@ -1095,6 +1096,7 @@ static int __sched
 try_to_take_rt_mutex(struct rt_mutex_base *lock, struct task_struct *task,
 		     struct rt_mutex_waiter *waiter)
 	__must_hold(&lock->wait_lock)
+	__cond_acquires(nonzero, lock)
 {
 	lockdep_assert_held(&lock->wait_lock);
 
@@ -1625,6 +1627,7 @@ static int __sched rt_mutex_slowlock_blo
 					   struct rt_mutex_waiter *waiter,
 					   struct wake_q_head *wake_q)
 	__releases(&lock->wait_lock) __acquires(&lock->wait_lock)
+	__cond_acquires(0, lock)
 {
 	struct rt_mutex *rtm = container_of(lock, struct rt_mutex, rtmutex);
 	struct task_struct *owner;
@@ -1715,6 +1718,7 @@ static int __sched __rt_mutex_slowlock(s
 				       struct rt_mutex_waiter *waiter,
 				       struct wake_q_head *wake_q)
 	__must_hold(&lock->wait_lock)
+	__cond_acquires(0, lock)
 {
 	struct rt_mutex *rtm = container_of(lock, struct rt_mutex, rtmutex);
 	struct ww_mutex *ww = ww_container_of(rtm);
@@ -1773,6 +1777,7 @@ static inline int __rt_mutex_slowlock_lo
 					     unsigned int state,
 					     struct wake_q_head *wake_q)
 	__must_hold(&lock->wait_lock)
+	__cond_acquires(0, lock)
 {
 	struct rt_mutex_waiter waiter;
 	int ret;
@@ -1797,6 +1802,7 @@ static inline int __rt_mutex_slowlock_lo
 static int __sched rt_mutex_slowlock(struct rt_mutex_base *lock,
 				     struct ww_acquire_ctx *ww_ctx,
 				     unsigned int state)
+	__cond_acquires(0, lock)
 {
 	DEFINE_WAKE_Q(wake_q);
 	unsigned long flags;
@@ -1829,6 +1835,7 @@ static int __sched rt_mutex_slowlock(str
 
 static __always_inline int __rt_mutex_lock(struct rt_mutex_base *lock,
 					   unsigned int state)
+	__cond_acquires(0, lock)
 {
 	lockdep_assert(!current->pi_blocked_on);
 
--- a/kernel/locking/rtmutex_api.c
+++ b/kernel/locking/rtmutex_api.c
@@ -88,6 +88,7 @@ EXPORT_SYMBOL_GPL(_rt_mutex_lock_nest_lo
  * @lock: the rt_mutex to be locked
  */
 void __sched rt_mutex_lock(struct rt_mutex *lock)
+	__no_context_analysis /* ignoring the return value below is fine in this case */
 {
 	__rt_mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, NULL, 0);
 }
@@ -532,7 +533,7 @@ static __always_inline int __mutex_lock_
 					       unsigned int subclass,
 					       struct lockdep_map *nest_lock,
 					       unsigned long ip)
-	__acquires(lock)
+	__cond_acquires(0, lock)
 {
 	int ret;
 

  parent reply	other threads:[~2026-05-04  9:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-02  1:53 [PATCH] locking/rtmutex: Annotate API and implementation Bart Van Assche
2026-05-04  6:00 ` Marco Elver
2026-05-04  6:23   ` Bart Van Assche
2026-05-04  9:39 ` Peter Zijlstra [this message]
2026-05-04 11:56   ` Bart Van Assche
2026-05-04 12:41     ` Peter Zijlstra

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=20260504093932.GR3126523@noisy.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=ast@kernel.org \
    --cc=bigeasy@linutronix.de \
    --cc=boqun@kernel.org \
    --cc=bvanassche@acm.org \
    --cc=elver@google.com \
    --cc=joel.granados@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=vbabka@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox