Re: [PATCH -v2] lockdep: Enable the printing of held locks of remote running tasks and print task CPU

From: Tetsuo Handa

Date: Tue Jul 07 2026 - 09:21:48 EST


On 2026/07/07 16:20, Ingo Molnar wrote:
> TL;DR: it should be fine to print the held locks of running
> tasks too, as long as we print out a warning when we print
> such a task, so that users are aware of any racy output.

Is there a warning we print out?
We dropped WARNING: in this version, didn't we?

>
> Implementation:
> ==============
>
> Implement that change.
>
> Also re-flow the function and streamline the printout into
> a single statement for all cases, which changes
> the 'no locks held by' / '%d lock[s] held by' phrasing that had a
> dependency on English spelling of plurals, to a uniform:
>
> locks held by bash/1234: %d
>
> Which spells correctly for 0, 1 and higher values, and should also
> be easier to parse both for humans and for scripts.
>
> Finally, print out the last CPU a task has ran on. This is very
> useful information for races and for locking bugs in particular.
> This basically extends the 'on CPU#%d' message we print for
> running tasks to all tasks we print.

I like this change. Thank you. ;-)

# echo t > /proc/sysrq-trigger; sleep 3; dmesg -c | cut -b 15-

Before:

Showing all locks held in the system:
4 locks held by pr/legacy/16:
1 lock held by rcub/1/18:
#0: ffffffff92ba36c8 (rcu_state){+.+.}-{0:0}, at: rcu_boost_kthread+0x15c/0x5d0
3 locks held by bash/1221:
#0: ffff8cd5dd8df500 (sb_writers#3){.+.+}-{0:0}, at: ksys_write+0x9a/0x150
#1: ffffffff92b9e080 (rcu_read_lock){....}-{1:3}, at: __handle_sysrq+0x56/0x140
#2: ffffffff92b9e080 (rcu_read_lock){....}-{1:3}, at: debug_show_all_locks+0x3d/0x184

After:

Showing all locks held in the system:
locks held by pr/legacy/16: 4, last CPU#0:
#0: ffffffffaaf9a4a0 (console_lock){+.+.}-{0:0}, at: legacy_kthread_func+0x85/0x190
#1: ffffffffaaf9a4f8 (console_srcu){....}-{0:0}, at: console_flush_one_record+0x92/0x710
#2: ffffffffab1fb818 (printing_lock){+.+.}-{3:3}, at: vt_console_print+0x74/0x640
#3: ffffffffaaf9e080 (rcu_read_lock){....}-{1:3}, at: rt_spin_trylock+0x61/0x140
locks held by rcub/1/18: 1, on CPU#0:
#0: ffffffffaafa36c8 (rcu_state){+.+.}-{0:0}, at: rcu_boost_kthread+0x15c/0x5d0
locks held by bash/1206: 3, last CPU#0:
#0: ffff8c62894da500 (sb_writers#3){.+.+}-{0:0}, at: ksys_write+0x9a/0x150
#1: ffffffffaaf9e080 (rcu_read_lock){....}-{1:3}, at: __handle_sysrq+0x56/0x140
#2: ffffffffaaf9e080 (rcu_read_lock){....}-{1:3}, at: debug_show_all_locks+0x3d/0x184