Skip to content

Commit e914985

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
locking/lockdep/selftests: Add mixed read-write ABBA tests
Currently lockdep has limited support for recursive readers, add a few mixed read-write ABBA selftests to show the extend of these limitations. [ 0.000000] ---------------------------------------------------------------------------- [ 0.000000] | spin |wlock |rlock |mutex | wsem | rsem | [ 0.000000] -------------------------------------------------------------------------- [ 0.000000] mixed read-lock/lock-write ABBA: |FAILED| | ok | [ 0.000000] mixed read-lock/lock-read ABBA: | ok | | ok | [ 0.000000] mixed write-lock/lock-write ABBA: | ok | | ok | This clearly illustrates the case where lockdep fails to find a deadlock. Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 0e70970 commit e914985

File tree

1 file changed

+115
-2
lines changed

1 file changed

+115
-2
lines changed

lib/locking-selftest.c

Lines changed: 115 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,103 @@ static void rsem_AA3(void)
362362
RSL(X2); // this one should fail
363363
}
364364

365+
/*
366+
* read_lock(A)
367+
* spin_lock(B)
368+
* spin_lock(B)
369+
* write_lock(A)
370+
*/
371+
static void rlock_ABBA1(void)
372+
{
373+
RL(X1);
374+
L(Y1);
375+
U(Y1);
376+
RU(X1);
377+
378+
L(Y1);
379+
WL(X1);
380+
WU(X1);
381+
U(Y1); // should fail
382+
}
383+
384+
static void rwsem_ABBA1(void)
385+
{
386+
RSL(X1);
387+
ML(Y1);
388+
MU(Y1);
389+
RSU(X1);
390+
391+
ML(Y1);
392+
WSL(X1);
393+
WSU(X1);
394+
MU(Y1); // should fail
395+
}
396+
397+
/*
398+
* read_lock(A)
399+
* spin_lock(B)
400+
* spin_lock(B)
401+
* read_lock(A)
402+
*/
403+
static void rlock_ABBA2(void)
404+
{
405+
RL(X1);
406+
L(Y1);
407+
U(Y1);
408+
RU(X1);
409+
410+
L(Y1);
411+
RL(X1);
412+
RU(X1);
413+
U(Y1); // should NOT fail
414+
}
415+
416+
static void rwsem_ABBA2(void)
417+
{
418+
RSL(X1);
419+
ML(Y1);
420+
MU(Y1);
421+
RSU(X1);
422+
423+
ML(Y1);
424+
RSL(X1);
425+
RSU(X1);
426+
MU(Y1); // should fail
427+
}
428+
429+
430+
/*
431+
* write_lock(A)
432+
* spin_lock(B)
433+
* spin_lock(B)
434+
* write_lock(A)
435+
*/
436+
static void rlock_ABBA3(void)
437+
{
438+
WL(X1);
439+
L(Y1);
440+
U(Y1);
441+
WU(X1);
442+
443+
L(Y1);
444+
WL(X1);
445+
WU(X1);
446+
U(Y1); // should fail
447+
}
448+
449+
static void rwsem_ABBA3(void)
450+
{
451+
WSL(X1);
452+
ML(Y1);
453+
MU(Y1);
454+
WSU(X1);
455+
456+
ML(Y1);
457+
WSL(X1);
458+
WSU(X1);
459+
MU(Y1); // should fail
460+
}
461+
365462
/*
366463
* ABBA deadlock:
367464
*/
@@ -1056,8 +1153,6 @@ static void dotest(void (*testcase_fn)(void), int expected, int lockclass_mask)
10561153
if (debug_locks != expected) {
10571154
unexpected_testcase_failures++;
10581155
pr_cont("FAILED|");
1059-
1060-
dump_stack();
10611156
} else {
10621157
testcase_successes++;
10631158
pr_cont(" ok |");
@@ -1933,6 +2028,24 @@ void locking_selftest(void)
19332028
dotest(rsem_AA3, FAILURE, LOCKTYPE_RWSEM);
19342029
pr_cont("\n");
19352030

2031+
print_testname("mixed read-lock/lock-write ABBA");
2032+
pr_cont(" |");
2033+
dotest(rlock_ABBA1, FAILURE, LOCKTYPE_RWLOCK);
2034+
pr_cont(" |");
2035+
dotest(rwsem_ABBA1, FAILURE, LOCKTYPE_RWSEM);
2036+
2037+
print_testname("mixed read-lock/lock-read ABBA");
2038+
pr_cont(" |");
2039+
dotest(rlock_ABBA2, SUCCESS, LOCKTYPE_RWLOCK);
2040+
pr_cont(" |");
2041+
dotest(rwsem_ABBA2, FAILURE, LOCKTYPE_RWSEM);
2042+
2043+
print_testname("mixed write-lock/lock-write ABBA");
2044+
pr_cont(" |");
2045+
dotest(rlock_ABBA3, FAILURE, LOCKTYPE_RWLOCK);
2046+
pr_cont(" |");
2047+
dotest(rwsem_ABBA3, FAILURE, LOCKTYPE_RWSEM);
2048+
19362049
printk(" --------------------------------------------------------------------------\n");
19372050

19382051
/*

0 commit comments

Comments
 (0)