Re: [PATCH 08/14] lockdep: Introduce lockdep_assume_ctx_held()

From: Bart Van Assche

Date: Thu Nov 05 2026 - 11:59:14 EST


On 11/5/26 12:37 AM, Peter Zijlstra wrote:
So the only convincing rationale from 0/n for doing this was that the
current annotation can hide the need, and thus cause a lacking of
__must_hold() on the function.

Yes.

I'm not sure I understand how this alternative form of the same avoids
that same problem, and the above doesn't seem to mention the whole
problem -- either that, or I just can't read this morning.

You are right that the patch description is not clear enough. I will fix
this when I post a second version of this patch series.

+/**
+ * lockdep_assume_shared_ctx_held() - assume and verify shared lock ownership
+ * @var: context lock instance pointer
+ *
+ * Instruct the compiler's context analysis to assume that @var is held with
+ * shared access from this point on and verify at runtime with
+ * lockdep_assert_held() that @var is held. Use this macro for reader-writer
+ * locks, e.g. rwlock_t and struct rw_semaphore, in code paths where shared
+ * lock ownership cannot be proven at compile time. @var is evaluated only
+ * once.
+ *
+ * Since lockdep_assert_held() is used, no lockdep warning is reported if
+ * @var is held for writing instead of for reading. Holding a lock
+ * exclusively implies that shared access is allowed. Use
+ * lockdep_assume_ctx_held() if exclusive access is required.

We do have lockdep_assert_held_read(), which then requires a shared
access.

+ * @var must point at a lock object that is tracked by lockdep, i.e. that
+ * has a dep_map member. For context locks that are not tracked by lockdep,
+ * e.g. the RCU context tokens, use __assume_shared_ctx_lock() instead.
+ */
+#define lockdep_assume_shared_ctx_held(var) \
+ _lockdep_assume_shared_ctx_held(var, __UNIQUE_ID(ctx_lock))
Whether or not to use lockdep_assert_held_read() in the definition of
_lockdep_assume_shared_ctx_held() is the aspect in this patch series I
was not sure of. If nobody objects I will switch to
lockdep_assert_held_read() in this macro.

Thanks,

Bart.