Skip to content

RFC lockdep: Support deadlock detection for recursive read locks

Boqun Feng lkml 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest5 patches 0 repliesNew

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5lockdep/selftest: Add a R-L/L-W test case specific to chain cache behaviorlib/locking-selftest.c+47 -00 replies
2/5lockdep/selftest: Add more recursive read related test caseslib/locking-selftest.c+161 -00 replies
3/5lockdep: Demagic the return value of BFSkernel/locking/lockdep.c+79 -550 replies
4/5lockdep: Support deadlock detection for recursive read locks in check_noncircular()include/linux/lockdep.h kernel/locking/lockdep.c+81 -160 replies
5/5lockdep: Take read/write status in consideration when generate chainkeykernel/locking/lockdep.c+38 -220 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [RFC tip 0/5] lockdep: Support deadlock detection for recursive read locks

Hi Ingo and Peter,

As Peter pointed out:

	https://marc.info/?l=linux-kernel&m=150349072023540

The lockdep current has a limit support for recursive read locks, the deadlock case as follow could not be detected:

	read_lock(A);
				lock(B);
	lock(B);
				write_lock(A);

I got some inspiration from Gautham R Shenoy:

	https://lwn.net/Articles/332801/

, and came up with this series.

The basic idea is:

* Add recursive read locks into the graph

* Classify dependencies into R->R, N->R, R->N, N->N, where R
stands for recursive read lock, N stands for other locks.

* Extend __bfs() to go through all kinds of dependencies and the
read/write status could be changed in the traverse(i.e. with dependency N(A)->R(B) and N(B)->R(C), BFS could go from A to B and then to C).

* But don't allow use a lock B as a transfer station if B only has

	*->R dependencies to the previous lock and R->* dependencies to
	the next lock. This is because if a BFS traverse has such a B as
	a transfer station, the following exists:

		CPU0		CPU1		CPU2		CPU3
		lock(X);
		lock(Y);   	lock(Y);
				rlock(B);	rlock(B);
						lock(P);   	lock(P);
								lock(Q);
	
	The lock dependency breaks between CPU1 and CPU2, no deadlock.

In this way, we can reflect the real dependencies while taking recursive read locks into considerations.

This is readlly an RFC, as I'm 100% sure I cover all the cases related to read recursive locks, but I do add two sets of self testcases, and they did pass ;-)

This series consists of 5 patches:

Patch #1 introduces a new test case to test chain cache behavior on the recursive read deadlock detection.

Patch #2 introduces more complex cases for recursive read deadlock detection.

Patch #3 does a little bit clean-up on the return value of __bfs() and its friends.

Patch #4 adds recursive locks into dependency graph and extends BFS to allow deadlock detection for recursive read locks.

Patch #5 fixes the problem that lock chains and chainkeys don't treat read/write locks differently, which could miss the chance to detect a deadlock because a lock chain cache hit.

I plan to write more tests and play about this in next weeks, just send out for suggestions and comments.

Reviews and tests are welcome!

Regards,
Boqun