Re: [PATCH v2 4/4] Revert "lockdep: Annotate lockdep assertions for context analysis"

From: Bart Van Assche

Date: Wed Feb 25 2026 - 14:27:26 EST


On 2/25/26 10:40 AM, Marco Elver wrote:
On Wed, 25 Feb 2026 at 19:33, Bart Van Assche <bvanassche@xxxxxxx> wrote:

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);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I think that's a hint that that we should just ld_semaphore a
first-class context_lock_struct. That will enable the analysis for all
ld_semaphore users.

This seems to be sufficient to solve the build errors if patch 4/4 is dropped:

diff --git a/include/linux/kernfs.h b/include/linux/kernfs.h
index b5a5f32fdfd1..9be0a2c8bb40 100644
--- a/include/linux/kernfs.h
+++ b/include/linux/kernfs.h
@@ -192,6 +192,7 @@ struct kernfs_elem_attr {
* accessible. Dereferencing elem or any other outer entity requires
* active reference.
*/
+context_lock_struct(kernfs_node);
struct kernfs_node {
atomic_t count;
atomic_t active;
diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
index c5cccc3fc1e8..2977873b84c5 100644
--- a/include/linux/tty_ldisc.h
+++ b/include/linux/tty_ldisc.h
@@ -14,6 +14,7 @@ struct tty_struct;
/*
* the semaphore definition
*/
+context_lock_struct(ld_semaphore);
struct ld_semaphore {
atomic_long_t count;
raw_spinlock_t wait_lock;

Bart.