From nobody Mon May 25 00:08:41 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0A66E3AD520; Wed, 20 May 2026 08:28:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779265703; cv=none; b=cvdaj2yUz1vEUAbOzdX+PX/YSKcsrb3bFNsEpfp/sI1/B4MSLEMOWKjrxGzzc2N7ScayBD2NpcLyjtahmbvDDFaSYVndKlMrDLfuZHYOghw6WKCsSgKyXSGYKmz+v04JezMeaLhIglvuYMK4kQJJMxKZ7t+BSFEwXGV4Pm0Sr/Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779265703; c=relaxed/simple; bh=hv64Fc7MwEFj3ub+ZoGlGg4Ec/X/rTs3JxuNmxGXAAI=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=WvvS441bd8iN0V9ZtenFar+iOcU3mnV5tYvwPf6n3pJxiqBiJ71FLLo+8kRvTvjVIcTQVbYfH4Hos01B3xVFRKo+PlXrRC+Ztsi5IePl1RQxmqYcupbBaNxsp+G+QT761F6XtH8tPCn+iW2VeHkjTwkikT4A8MgxFpih7/3Nf4I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=gdwBpo9U; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=QOocc0o1; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="gdwBpo9U"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="QOocc0o1" Date: Wed, 20 May 2026 08:28:10 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779265691; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0OTjmqMwqFk4I9ccH374tCtT/TrZe0GtKg2bgn0XlM8=; b=gdwBpo9UCSHurL1C7IWC/WaPg45NVbL1IP8ZF3paJ6DsEdQcgEFGmpGRVE8k8tK4eHzdQZ cUC/QB5SSp4w1uYns92VRni5TDlYSnRx/5wn9svRJ2ueODYN8Crtmb0yZbk/foCCOhXs2S MUppX8++yrvEcwD/wPgh105qrc+60C9YwGVlWS3ZmkWDy0TsZRYZfd4AF6Ridz4lfiSRwc V1/IffKhf4lztbqnBzAwh6VH6XY9MCY8szr1oQqcoq6jTkKT4d0WJ0IGo6oCZ0G5HPusXr brYmyWg/Mwnp3Zol8SNnhNoviHYdiaaCdXTof/0WPbLlQvMI5Xjxj6BGWGs+zw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779265691; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0OTjmqMwqFk4I9ccH374tCtT/TrZe0GtKg2bgn0XlM8=; b=QOocc0o1wnJMaFTCCcNXFg3ZldUVv5KFQwMq6QeyT2VJbA5rPwZ9EvsvlDEEiO3j2E2Cs5 H3BY3KGu+zgAOoAQ== From: "tip-bot2 for Bart Van Assche" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: locking/core] locking/rtmutex: Annotate API and implementation Cc: Bart Van Assche , "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20260508174520.1416285-1-bvanassche@acm.org> References: <20260508174520.1416285-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <177926569002.711.3211391251397841006.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the locking/core branch of tip: Commit-ID: a9e4e50519e99e5be2d69fa4eebec6a4848ae201 Gitweb: https://git.kernel.org/tip/a9e4e50519e99e5be2d69fa4eebec6a48= 48ae201 Author: Bart Van Assche AuthorDate: Fri, 08 May 2026 10:45:16 -07:00 Committer: Peter Zijlstra CommitterDate: Tue, 19 May 2026 13:49:01 +02:00 locking/rtmutex: Annotate API and implementation Enable context analysis for struct rt_mutex and annotate all functions that accept a struct rt_mutex pointer. In the __rt_mutex_lock_common() callers, instead of adding the __no_context_analysis annotation, emit a runtime warning if the __rt_mutex_lock_common() return value is not zero and add an __acquire() statement. Signed-off-by: Bart Van Assche Signed-off-by: Peter Zijlstra (Intel) Link: https://patch.msgid.link/20260508174520.1416285-1-bvanassche@acm.org --- include/linux/rtmutex.h | 22 +++++++++++++++------- kernel/locking/rtmutex.c | 4 ++++ kernel/locking/rtmutex_api.c | 31 ++++++++++++++++++++++++++++--- 3 files changed, 47 insertions(+), 10 deletions(-) diff --git a/include/linux/rtmutex.h b/include/linux/rtmutex.h index 78e7e58..9e1f012 100644 --- a/include/linux/rtmutex.h +++ b/include/linux/rtmutex.h @@ -56,6 +56,8 @@ static inline struct task_struct *rt_mutex_owner(struct r= t_mutex_base *lock) #endif extern void rt_mutex_base_init(struct rt_mutex_base *rtb); =20 +context_lock_struct(rt_mutex); + /** * The rt_mutex structure * @@ -108,8 +110,10 @@ do { \ extern void __rt_mutex_init(struct rt_mutex *lock, const char *name, struc= t lock_class_key *key); =20 #ifdef CONFIG_DEBUG_LOCK_ALLOC -extern void rt_mutex_lock_nested(struct rt_mutex *lock, unsigned int subcl= ass); -extern void _rt_mutex_lock_nest_lock(struct rt_mutex *lock, struct lockdep= _map *nest_lock); +extern void rt_mutex_lock_nested(struct rt_mutex *lock, unsigned int subcl= ass) + __acquires(lock); +extern void _rt_mutex_lock_nest_lock(struct rt_mutex *lock, struct lockdep= _map *nest_lock) + __acquires(lock); #define rt_mutex_lock(lock) rt_mutex_lock_nested(lock, 0) #define rt_mutex_lock_nest_lock(lock, nest_lock) \ do { \ @@ -118,15 +122,19 @@ extern void _rt_mutex_lock_nest_lock(struct rt_mutex = *lock, struct lockdep_map * } while (0) =20 #else -extern void rt_mutex_lock(struct rt_mutex *lock); +extern void rt_mutex_lock(struct rt_mutex *lock) __acquires(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 =20 -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_lock_interruptible(struct rt_mutex *lock) + __cond_acquires(0, lock); +extern int rt_mutex_lock_killable(struct rt_mutex *lock) + __cond_acquires(0, lock); +extern int rt_mutex_trylock(struct rt_mutex *lock) + __cond_acquires(true, lock); =20 -extern void rt_mutex_unlock(struct rt_mutex *lock); +extern void rt_mutex_unlock(struct rt_mutex *lock) + __releases(lock); =20 #endif diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c index 4f386ea..9147d6a 100644 --- a/kernel/locking/rtmutex.c +++ b/kernel/locking/rtmutex.c @@ -484,6 +484,7 @@ static __always_inline bool __waiter_less(struct rb_nod= e *a, const struct rb_nod =20 static __always_inline void rt_mutex_enqueue(struct rt_mutex_base *lock, struct rt_mutex_waiter *waite= r) + __must_hold(&lock->wait_lock) { lockdep_assert_held(&lock->wait_lock); =20 @@ -492,6 +493,7 @@ rt_mutex_enqueue(struct rt_mutex_base *lock, struct rt_= mutex_waiter *waiter) =20 static __always_inline void rt_mutex_dequeue(struct rt_mutex_base *lock, struct rt_mutex_waiter *waite= r) + __must_hold(&lock->wait_lock) { lockdep_assert_held(&lock->wait_lock); =20 @@ -1092,6 +1094,7 @@ static int __sched rt_mutex_adjust_prio_chain(struct = task_struct *task, 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) { lockdep_assert_held(&lock->wait_lock); =20 @@ -1319,6 +1322,7 @@ static int __sched task_blocks_on_rt_mutex(struct rt_= mutex_base *lock, */ static void __sched mark_wakeup_next_waiter(struct rt_wake_q_head *wqh, struct rt_mutex_base *lock) + __must_hold(&lock->wait_lock) { struct rt_mutex_waiter *waiter; =20 diff --git a/kernel/locking/rtmutex_api.c b/kernel/locking/rtmutex_api.c index 124219a..7c40b91 100644 --- a/kernel/locking/rtmutex_api.c +++ b/kernel/locking/rtmutex_api.c @@ -41,6 +41,7 @@ static __always_inline int __rt_mutex_lock_common(struct = rt_mutex *lock, unsigned int state, struct lockdep_map *nest_lock, unsigned int subclass) + __cond_acquires(0, lock) { int ret; =20 @@ -67,13 +68,27 @@ EXPORT_SYMBOL(rt_mutex_base_init); */ void __sched rt_mutex_lock_nested(struct rt_mutex *lock, unsigned int subc= lass) { - __rt_mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, NULL, subclass); + if (__rt_mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, NULL, subclass) = =3D=3D 0) + return; + /* + * The code below is never reached because __rt_mutex_lock_common() only + * returns an error code if interrupted by a signal or upon a timeout. + */ + WARN_ON_ONCE(true); + __acquire(lock); } EXPORT_SYMBOL_GPL(rt_mutex_lock_nested); =20 void __sched _rt_mutex_lock_nest_lock(struct rt_mutex *lock, struct lockde= p_map *nest_lock) { - __rt_mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, nest_lock, 0); + if (__rt_mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, nest_lock, 0) =3D= =3D 0) + return; + /* + * The code below is never reached because __rt_mutex_lock_common() only + * returns an error code if interrupted by a signal or upon a timeout. + */ + WARN_ON_ONCE(true); + __acquire(lock); } EXPORT_SYMBOL_GPL(_rt_mutex_lock_nest_lock); =20 @@ -86,7 +101,14 @@ EXPORT_SYMBOL_GPL(_rt_mutex_lock_nest_lock); */ void __sched rt_mutex_lock(struct rt_mutex *lock) { - __rt_mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, NULL, 0); + if (__rt_mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, NULL, 0) =3D=3D 0) + return; + /* + * The code below is never reached because __rt_mutex_lock_common() only + * returns an error code if interrupted by a signal or upon a timeout. + */ + WARN_ON_ONCE(true); + __acquire(lock); } EXPORT_SYMBOL_GPL(rt_mutex_lock); #endif @@ -157,6 +179,7 @@ void __sched rt_mutex_unlock(struct rt_mutex *lock) { mutex_release(&lock->dep_map, _RET_IP_); __rt_mutex_unlock(&lock->rtmutex); + __release(lock); } EXPORT_SYMBOL_GPL(rt_mutex_unlock); =20 @@ -182,6 +205,7 @@ int __sched __rt_mutex_futex_trylock(struct rt_mutex_ba= se *lock) */ bool __sched __rt_mutex_futex_unlock(struct rt_mutex_base *lock, struct rt_wake_q_head *wqh) + __must_hold(&lock->wait_lock) { lockdep_assert_held(&lock->wait_lock); =20 @@ -312,6 +336,7 @@ int __sched __rt_mutex_start_proxy_lock(struct rt_mutex= _base *lock, struct rt_mutex_waiter *waiter, struct task_struct *task, struct wake_q_head *wake_q) + __must_hold(&lock->wait_lock) { int ret; =20