[PATCH 09/14] kfence: Use lockdep_assume_ctx_held() in kfence_report_error()

From: Bart Van Assche

Date: Mon Nov 02 2026 - 16:55:39 EST


Replace lockdep_assert_held(&meta->lock) with
lockdep_assume_ctx_held(&meta->lock) in kfence_report_error().

kfence_print_object() requires holding &meta->lock. In
kfence_report_error(), meta is optional (nullable), so the function
cannot be annotated with __must_hold(&meta->lock). Currently,
lockdep_assert_held(&meta->lock) implicitly assumes lock ownership for
Clang context analysis. Prepare for removing the context assumption from
lockdep_assert_held() by using lockdep_assume_ctx_held(&meta->lock)
inside the "if (meta)" block. This informs Clang context analysis that
meta->lock is held and preserves the runtime lockdep check.

Signed-off-by: Bart Van Assche <bvanassche@xxxxxxx>
---
mm/kfence/report.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/kfence/report.c b/mm/kfence/report.c
index d548536864b1..5b8588d35b77 100644
--- a/mm/kfence/report.c
+++ b/mm/kfence/report.c
@@ -286,7 +286,7 @@ kfence_report_error(unsigned long address, bool is_write, struct pt_regs *regs,
stack_trace_print(stack_entries + skipnr, num_stack_entries - skipnr, 0);

if (meta) {
- lockdep_assert_held(&meta->lock);
+ lockdep_assume_ctx_held(&meta->lock);
pr_err("\n");
kfence_print_object(NULL, meta);
}