locking/lockdep: Improve the deadlock scenario print for sync and read lock
authorBoqun Feng <boqun.feng@gmail.com>
Fri, 13 Jan 2023 23:57:22 +0000 (15:57 -0800)
committerBoqun Feng <boqun.feng@gmail.com>
Mon, 27 Mar 2023 18:16:04 +0000 (11:16 -0700)
commit0471db447cb7de56bbe2fedd9256b4d2b8ef642a
tree18e5bd3335b4c8d33427766eff6ab10ee5cbf0b8
parent60a1a64ec0c08e02f2cd4372cd3971e9d5eb2b37
locking/lockdep: Improve the deadlock scenario print for sync and read lock

Lock scenario print is always a weak spot of lockdep splats. Improvement
can be made if we rework the dependency search and the error printing.

However without touching the graph search, we can improve a little for
the circular deadlock case, since we have the to-be-added lock
dependency, and know whether these two locks are read/write/sync.

In order to know whether a held_lock is sync or not, a bit was
"stolen" from ->references, which reduce our limit for the same lock
class nesting from 2^12 to 2^11, and it should still be good enough.

Besides, since we now have bit in held_lock for sync, we don't need the
"hardirqoffs being 1" trick, and also we can avoid the __lock_release()
if we jump out of __lock_acquire() before the held_lock stored.

With these changes, a deadlock case evolved with read lock and sync gets
a better print-out from:

[...]  Possible unsafe locking scenario:
[...]
[...]        CPU0                    CPU1
[...]        ----                    ----
[...]   lock(srcuA);
[...]                                lock(srcuB);
[...]                                lock(srcuA);
[...]   lock(srcuB);

to

[...]  Possible unsafe locking scenario:
[...]
[...]        CPU0                    CPU1
[...]        ----                    ----
[...]   rlock(srcuA);
[...]                                lock(srcuB);
[...]                                lock(srcuA);
[...]   sync(srcuB);

Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
include/linux/lockdep.h
kernel/locking/lockdep.c