Re: [PATCH printk v2 26/26] lockdep: Mark emergency section in lockdep splats

From: John Ogness
Date: Mon Feb 19 2024 - 06:11:50 EST


On 2024-02-18, Waiman Long <longman@xxxxxxxxxx> wrote:
> On 2/18/24 13:57, John Ogness wrote:
> lockdep.c has multiple functions that print stuff to the console, like
>
>  - print_circular_bug_header()
>  - print_bad_irq_dependency()
>  - print_deadlock_bug()
>  - print_collision()
>  - print_usage_bug()
>  - print_irq_inversion_bug()
>  - print_lock_invalid_wait_context()
>  - print_lock_nested_lock_not_held()
>  - print_unlock_imbalance_bug()
>  - print_lock_contention_bug()
>  - print_freed_lock_bug()
>  - print_held_locks_bug()
>  - lockdep_rcu_suspicious()
>
> So what is special about print_usage_bug() that it needs this
> emergency treatment but not the other ones?

I do not expect to be able to identify all "emergency printing" paths in
the kernel from the beginning. This series initially marks some sections
that are IMHO interesting for the feature.

As you are implying, for lockdep probably all printing should be
considered emergency. Is it preferred to place the markers outside the
high-level print functions, for example:

diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index 00465373d358..7a4e4f4a9156 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -2182,10 +2182,12 @@ check_noncircular(struct held_lock *src, struct held_lock *target,
*trace = save_trace();
}

+ nbcon_cpu_emergency_enter();
if (src->class_idx == target->class_idx)
print_deadlock_bug(current, src, target);
else
print_circular_bug(&src_entry, target_entry, src, target);
+ nbcon_cpu_emergency_exit();
}

return ret;

Or is it preferred to put them directly around the various pr_warn()
blocks (as the patch in this series is doing)?

John Ogness