From: Bart Van Assche <bvanassche@acm.org>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>, Will Deacon <will@kernel.org>,
Boqun Feng <boqun@kernel.org>, Waiman Long <longman@redhat.com>,
linux-kernel@vger.kernel.org, Marco Elver <elver@google.com>,
"Paul E . McKenney" <paulmck@kernel.org>,
Christoph Hellwig <hch@lst.de>,
Bart Van Assche <bvanassche@acm.org>,
Thomas Gleixner <tglx@kernel.org>,
Nathan Chancellor <nathan@kernel.org>
Subject: [PATCH v2 05/14] futex: Annotate __attach_to_pi_owner() and fixup_pi_*owner()
Date: Mon, 9 Nov 2026 11:13:13 -0800 [thread overview]
Message-ID: <d91f131d57afdcd20a58034d39362e04a4387f05.1794250850.git.bvanassche@acm.org> (raw)
In-Reply-To: <cover.1794250850.git.bvanassche@acm.org>
Annotate __attach_to_pi_owner() with __must_hold(&p->pi_lock) and
annotate fixup_pi_state_owner() and fixup_pi_owner() with
__must_hold(q->lock_ptr).
__attach_to_pi_owner() modifies p->futex.pi_state_list and attaches a
new pi_state to owner task p, which requires holding p->pi_lock.
Enforce this requirement at compile time with __must_hold(&p->pi_lock).
__fixup_pi_state_owner() requires holding q->lock_ptr. Its caller
fixup_pi_state_owner() and outer caller fixup_pi_owner() must both be
called with the hash bucket lock held. Currently,
lockdep_assert_held(q->lock_ptr) in fixup_pi_state_owner() implicitly
assumes lock ownership for Clang context analysis. Prepare for removing
the context assumption from lockdep_assert_held() by annotating both
fixup_pi_state_owner() and fixup_pi_owner() with
__must_hold(q->lock_ptr).
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
kernel/futex/futex.h | 3 ++-
kernel/futex/pi.c | 3 +++
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/kernel/futex/futex.h b/kernel/futex/futex.h
index f00f0863ed44..3e162837e9d2 100644
--- a/kernel/futex/futex.h
+++ b/kernel/futex/futex.h
@@ -394,7 +394,8 @@ extern int futex_lock_pi_atomic(u32 __user *uaddr, struct futex_hash_bucket *hb,
extern int refill_pi_state_cache(void);
extern void get_pi_state(struct futex_pi_state *pi_state);
extern void put_pi_state(struct futex_pi_state *pi_state);
-extern int fixup_pi_owner(u32 __user *uaddr, struct futex_q *q, int locked);
+extern int fixup_pi_owner(u32 __user *uaddr, struct futex_q *q, int locked)
+ __must_hold(q->lock_ptr);
/*
* Express the locking dependencies for lockdep:
diff --git a/kernel/futex/pi.c b/kernel/futex/pi.c
index 98f1b962e59a..e0310776b484 100644
--- a/kernel/futex/pi.c
+++ b/kernel/futex/pi.c
@@ -420,6 +420,7 @@ static int handle_exit_race(u32 __user *uaddr, u32 uval)
static void __attach_to_pi_owner(struct task_struct *p, union futex_key *key,
struct futex_pi_state **ps)
+ __must_hold(&p->pi_lock)
{
/*
* No existing pi state. First waiter. [2]
@@ -912,6 +913,7 @@ static int __fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q,
static int fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q,
struct task_struct *argowner)
+ __must_hold(q->lock_ptr)
{
struct futex_pi_state *pi_state = q->pi_state;
int ret;
@@ -940,6 +942,7 @@ static int fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q,
* - <0 - on error (-EFAULT)
*/
int fixup_pi_owner(u32 __user *uaddr, struct futex_q *q, int locked)
+ __must_hold(q->lock_ptr)
{
if (locked) {
/*
next prev parent reply other threads:[~2026-11-09 19:14 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-09 19:13 [PATCH v2 00/14] Stop lockdep_assert_held*() from assuming lock ownership Bart Van Assche
2026-11-09 19:13 ` [PATCH v2 01/14] bit_spinlock: Fix the __bitlock() definition Bart Van Assche
2026-11-09 19:13 ` [PATCH v2 02/14] cleanup: Disable context analysis for __free() helpers Bart Van Assche
2026-11-09 19:13 ` [PATCH v2 03/14] tracing: Disable branch profiling for COMPILE_TEST builds Bart Van Assche
2026-11-09 19:13 ` [PATCH v2 04/14] srcu: Remove check from srcu_dereference_check() Bart Van Assche
2026-11-09 19:13 ` Bart Van Assche [this message]
2026-11-09 19:13 ` [PATCH v2 06/14] locking/rwsem: Annotate rwsem internal functions with __must_hold() Bart Van Assche
2026-11-09 19:13 ` [PATCH v2 07/14] nvme-fabrics: Annotate nvmf_lookup_transport() with __must_hold_shared() Bart Van Assche
2026-11-09 19:13 ` [PATCH v2 08/14] lockdep: Introduce lockdep_assume_ctx_held() Bart Van Assche
2026-11-09 19:13 ` [PATCH v2 09/14] kfence: Use lockdep_assume_ctx_held() in kfence_report_error() Bart Van Assche
2026-11-09 19:13 ` [PATCH v2 10/14] Bluetooth: Add lock context annotations for connection aliases Bart Van Assche
2026-11-09 19:13 ` [PATCH v2 11/14] futex: Verify exit_mutex ownership in futex_exit_recursive() Bart Van Assche
2026-11-09 19:13 ` [PATCH v2 12/14] lockdep: Stop lockdep_assert_held*() from assuming lock ownership Bart Van Assche
2026-11-09 19:13 ` [PATCH v2 13/14] compiler-context-analysis: Split the RCU assertion tests Bart Van Assche
2026-11-09 19:13 ` [PATCH v2 14/14] rcu: Introduce lockdep_assume_in_rcu_*() Bart Van Assche
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=d91f131d57afdcd20a58034d39362e04a4387f05.1794250850.git.bvanassche@acm.org \
--to=bvanassche@acm.org \
--cc=boqun@kernel.org \
--cc=elver@google.com \
--cc=hch@lst.de \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=mingo@redhat.com \
--cc=nathan@kernel.org \
--cc=paulmck@kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@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
all inboxes | Powered by JetHome®