mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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>,
	Christoph Hellwig <hch@lst.de>,
	Steven Rostedt <rostedt@goodmis.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Nathan Chancellor <nathan@kernel.org>,
	Kees Cook <kees@kernel.org>, Jann Horn <jannh@google.com>,
	Bart Van Assche <bvanassche@acm.org>
Subject: [PATCH v2 4/4] Revert "lockdep: Annotate lockdep assertions for context analysis"
Date: Wed, 25 Feb 2026 10:32:44 -0800	[thread overview]
Message-ID: <20260225183244.4035378-5-bvanassche@acm.org> (raw)
In-Reply-To: <20260225183244.4035378-1-bvanassche@acm.org>

lockdep_assert_held() supports all data structures that have a member
with the name dep_map. __assume_ctx_lock() only supports data structures
that support lock context annotation. Remove __assume_ctx_lock() from
lockdep_assert_held(). This patch fixes the following build errors if
lock context analysis is enabled for the entire kernel tree:

drivers/tty/tty_ldisc.c:451:2: error: call to '__assume_ctx_lock' is ambiguous
  451 |         lockdep_assert_held_write(&tty->ldisc_sem);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

drivers/tty/tty_ldisc.c:451:2: error: call to '__assume_ctx_lock' is ambiguous
  451 |         lockdep_assert_held_write(&tty->ldisc_sem);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Fixes: 7c451541743c ("lockdep: Annotate lockdep assertions for context analysis")
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 include/linux/lockdep.h     | 12 ++++++------
 lib/test_context-analysis.c |  6 +++---
 mm/kfence/report.c          |  1 +
 3 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
index 621566345406..dd634103b014 100644
--- a/include/linux/lockdep.h
+++ b/include/linux/lockdep.h
@@ -282,16 +282,16 @@ extern void lock_unpin_lock(struct lockdep_map *lock, struct pin_cookie);
 	do { WARN_ON_ONCE(debug_locks && !(cond)); } while (0)
 
 #define lockdep_assert_held(l)		\
-	do { lockdep_assert(lockdep_is_held(l) != LOCK_STATE_NOT_HELD); __assume_ctx_lock(l); } while (0)
+	lockdep_assert(lockdep_is_held(l) != LOCK_STATE_NOT_HELD)
 
 #define lockdep_assert_not_held(l)	\
 	lockdep_assert(lockdep_is_held(l) != LOCK_STATE_HELD)
 
 #define lockdep_assert_held_write(l)	\
-	do { lockdep_assert(lockdep_is_held_type(l, 0)); __assume_ctx_lock(l); } while (0)
+	lockdep_assert(lockdep_is_held_type(l, 0))
 
 #define lockdep_assert_held_read(l)	\
-	do { lockdep_assert(lockdep_is_held_type(l, 1)); __assume_shared_ctx_lock(l); } while (0)
+	lockdep_assert(lockdep_is_held_type(l, 1))
 
 #define lockdep_assert_held_once(l)		\
 	lockdep_assert_once(lockdep_is_held(l) != LOCK_STATE_NOT_HELD)
@@ -389,10 +389,10 @@ extern int lockdep_is_held(const void *);
 #define lockdep_assert(c)			do { } while (0)
 #define lockdep_assert_once(c)			do { } while (0)
 
-#define lockdep_assert_held(l)			__assume_ctx_lock(l)
+#define lockdep_assert_held(l)			do { (void)(l); } while (0)
 #define lockdep_assert_not_held(l)		do { (void)(l); } while (0)
-#define lockdep_assert_held_write(l)		__assume_ctx_lock(l)
-#define lockdep_assert_held_read(l)		__assume_shared_ctx_lock(l)
+#define lockdep_assert_held_write(l)		do { (void)(l); } while (0)
+#define lockdep_assert_held_read(l)		do { (void)(l); } while (0)
 #define lockdep_assert_held_once(l)		do { (void)(l); } while (0)
 #define lockdep_assert_none_held_once()	do { } while (0)
 
diff --git a/lib/test_context-analysis.c b/lib/test_context-analysis.c
index 140efa8a9763..9846da75e9a3 100644
--- a/lib/test_context-analysis.c
+++ b/lib/test_context-analysis.c
@@ -68,7 +68,7 @@ static void __used test_common_helpers(void)
 	}											\
 	static void __used test_##class##_assert(struct test_##class##_data *d)			\
 	{											\
-		lockdep_assert_held(&d->lock);							\
+		__assume_ctx_lock(&d->lock);							\
 		op(d->counter);									\
 	}											\
 	static void __used test_##class##_guard(struct test_##class##_data *d)			\
@@ -199,7 +199,7 @@ static void __used test_mutex_trylock(struct test_mutex_data *d, atomic_t *a)
 
 static void __used test_mutex_assert(struct test_mutex_data *d)
 {
-	lockdep_assert_held(&d->mtx);
+	__assume_ctx_lock(&d->mtx);
 	d->counter++;
 }
 
@@ -311,7 +311,7 @@ static void __used test_rwsem_writer(struct test_rwsem_data *d)
 
 static void __used test_rwsem_assert(struct test_rwsem_data *d)
 {
-	rwsem_assert_held_nolockdep(&d->sem);
+	__assume_ctx_lock(&d->sem);
 	d->counter++;
 }
 
diff --git a/mm/kfence/report.c b/mm/kfence/report.c
index 787e87c26926..d50a3f256650 100644
--- a/mm/kfence/report.c
+++ b/mm/kfence/report.c
@@ -263,6 +263,7 @@ void kfence_report_error(unsigned long address, bool is_write, struct pt_regs *r
 
 	if (meta) {
 		lockdep_assert_held(&meta->lock);
+		__assume_ctx_lock(&meta->lock);
 		pr_err("\n");
 		kfence_print_object(NULL, meta);
 	}

  parent reply	other threads:[~2026-02-25 18:33 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-25 18:32 [PATCH v2 0/4] Lock context annotation fixes Bart Van Assche
2026-02-25 18:32 ` [PATCH v2 1/4] locking: Fix rwlock and spinlock lock context annotations Bart Van Assche
2026-02-28 10:56   ` [tip: locking/core] " tip-bot2 for Bart Van Assche
2026-03-12 16:36     ` Bart Van Assche
2026-02-25 18:32 ` [PATCH v2 2/4] signal: Fix the lock_task_sighand() annotation Bart Van Assche
2026-02-28 10:56   ` [tip: locking/core] " tip-bot2 for Bart Van Assche
2026-02-25 18:32 ` [PATCH v2 3/4] ww-mutex: Fix the ww_acquire_ctx function annotations Bart Van Assche
2026-02-28 10:56   ` [tip: locking/core] " tip-bot2 for Bart Van Assche
2026-02-25 18:32 ` Bart Van Assche [this message]
2026-02-25 18:40   ` [PATCH v2 4/4] Revert "lockdep: Annotate lockdep assertions for context analysis" Marco Elver
2026-02-25 19:22     ` Marco Elver
2026-02-25 19:27     ` Bart Van Assche
2026-02-25 18:44 ` [PATCH v2 0/4] Lock context annotation fixes Marco Elver

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=20260225183244.4035378-5-bvanassche@acm.org \
    --to=bvanassche@acm.org \
    --cc=boqun@kernel.org \
    --cc=elver@google.com \
    --cc=hch@lst.de \
    --cc=jannh@google.com \
    --cc=kees@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=mingo@redhat.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.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®