Re: [PATCH v2 11/17] locking/lockdep: Adjust lockdep selftest cases

Boqun Feng
2019-05-29T11:45:01Z

[-- Attachment #1: Type: text/plain, Size: 5487 bytes --]

On Thu, May 16, 2019 at 04:00:09PM +0800, Yuyang Du wrote:
> With read-write lock support, some read-write lock cases need to be updated,
> specifically, some read-lock involved deadlocks are actually not deadlocks.
> Hope I am not wildly wrong.
>
> Signed-off-by: Yuyang Du <duyuyang@gmail.com>
> ---
> lib/locking-selftest.c | 44 +++++++++++++++++++++++++++++++++-----------
> 1 file changed, 33 insertions(+), 11 deletions(-)
>
> diff --git a/lib/locking-selftest.c b/lib/locking-selftest.c
> index a170554..f83f047 100644
> --- a/lib/locking-selftest.c
> +++ b/lib/locking-selftest.c
> @@ -424,7 +424,7 @@ static void rwsem_ABBA2(void)
> ML(Y1);
> RSL(X1);
> RSU(X1);
> - MU(Y1); // should fail
> + MU(Y1); // should NOT fail

I'm afraid you get this wrong ;-) reader of rwsem is non-recursive if I
understand correctly, so case like:

Task 0 Task 1

down_read(A);
mutex_lock(B);

down_read(A);
mutex_lock(B);

can be a deadlock, if we consider a third independent task:

Task 0 Task 1 Task 2

down_read(A);
mutex_lock(B);
down_write(A);
down_read(A);
mutex_lock(B);

in this case, Task 1 can not get it's lock for A, therefore, deadlock.

Regards,
Boqun

> }
>
>
> @@ -462,12 +462,13 @@ static void rwsem_ABBA3(void)
>
> /*
> * ABBA deadlock:
> + *
> + * Should fail except for either A or B is read lock.
> */
> -
> #define E() \
> \
> LOCK_UNLOCK_2(A, B); \
> - LOCK_UNLOCK_2(B, A); /* fail */
> + LOCK_UNLOCK_2(B, A);
>
> /*
> * 6 testcases:
> @@ -494,13 +495,15 @@ static void rwsem_ABBA3(void)
>
> /*
> * AB BC CA deadlock:
> + *
> + * Should fail except for read or recursive-read locks.
> */
>
> #define E() \
> \
> LOCK_UNLOCK_2(A, B); \
> LOCK_UNLOCK_2(B, C); \
> - LOCK_UNLOCK_2(C, A); /* fail */
> + LOCK_UNLOCK_2(C, A);
>
> /*
> * 6 testcases:
> @@ -527,13 +530,15 @@ static void rwsem_ABBA3(void)
>
> /*
> * AB CA BC deadlock:
> + *
> + * Should fail except for read or recursive-read locks.
> */
>
> #define E() \
> \
> LOCK_UNLOCK_2(A, B); \
> LOCK_UNLOCK_2(C, A); \
> - LOCK_UNLOCK_2(B, C); /* fail */
> + LOCK_UNLOCK_2(B, C);
>
> /*
> * 6 testcases:
> @@ -560,6 +565,8 @@ static void rwsem_ABBA3(void)
>
> /*
> * AB BC CD DA deadlock:
> + *
> + * Should fail except for read or recursive-read locks.
> */
>
> #define E() \
> @@ -567,7 +574,7 @@ static void rwsem_ABBA3(void)
> LOCK_UNLOCK_2(A, B); \
> LOCK_UNLOCK_2(B, C); \
> LOCK_UNLOCK_2(C, D); \
> - LOCK_UNLOCK_2(D, A); /* fail */
> + LOCK_UNLOCK_2(D, A);
>
> /*
> * 6 testcases:
> @@ -594,13 +601,15 @@ static void rwsem_ABBA3(void)
>
> /*
> * AB CD BD DA deadlock:
> + *
> + * Should fail except for read or recursive-read locks.
> */
> #define E() \
> \
> LOCK_UNLOCK_2(A, B); \
> LOCK_UNLOCK_2(C, D); \
> LOCK_UNLOCK_2(B, D); \
> - LOCK_UNLOCK_2(D, A); /* fail */
> + LOCK_UNLOCK_2(D, A);
>
> /*
> * 6 testcases:
> @@ -627,13 +636,15 @@ static void rwsem_ABBA3(void)
>
> /*
> * AB CD BC DA deadlock:
> + *
> + * Should fail except for read or recursive-read locks.
> */
> #define E() \
> \
> LOCK_UNLOCK_2(A, B); \
> LOCK_UNLOCK_2(C, D); \
> LOCK_UNLOCK_2(B, C); \
> - LOCK_UNLOCK_2(D, A); /* fail */
> + LOCK_UNLOCK_2(D, A);
>
> /*
> * 6 testcases:
> @@ -1238,7 +1249,7 @@ static inline void print_testname(const char *testname)
> /*
> * 'read' variant: rlocks must not trigger.
> */
> -#define DO_TESTCASE_6R(desc, name) \
> +#define DO_TESTCASE_6AA(desc, name) \
> print_testname(desc); \
> dotest(name##_spin, FAILURE, LOCKTYPE_SPIN); \
> dotest(name##_wlock, FAILURE, LOCKTYPE_RWLOCK); \
> @@ -1249,6 +1260,17 @@ static inline void print_testname(const char *testname)
> dotest_rt(name##_rtmutex, FAILURE, LOCKTYPE_RTMUTEX); \
> pr_cont("\n");
>
> +#define DO_TESTCASE_6R(desc, name) \
> + print_testname(desc); \
> + dotest(name##_spin, FAILURE, LOCKTYPE_SPIN); \
> + dotest(name##_wlock, FAILURE, LOCKTYPE_RWLOCK); \
> + dotest(name##_rlock, SUCCESS, LOCKTYPE_RWLOCK); \
> + dotest(name##_mutex, FAILURE, LOCKTYPE_MUTEX); \
> + dotest(name##_wsem, FAILURE, LOCKTYPE_RWSEM); \
> + dotest(name##_rsem, SUCCESS, LOCKTYPE_RWSEM); \
> + dotest_rt(name##_rtmutex, FAILURE, LOCKTYPE_RTMUTEX); \
> + pr_cont("\n");
> +
> #define DO_TESTCASE_2I(desc, name, nr) \
> DO_TESTCASE_1("hard-"desc, name##_hard, nr); \
> DO_TESTCASE_1("soft-"desc, name##_soft, nr);
> @@ -1991,7 +2013,7 @@ void locking_selftest(void)
> debug_locks_silent = !debug_locks_verbose;
> lockdep_set_selftest_task(current);
>
> - DO_TESTCASE_6R("A-A deadlock", AA);
> + DO_TESTCASE_6AA("A-A deadlock", AA);
> DO_TESTCASE_6R("A-B-B-A deadlock", ABBA);
> DO_TESTCASE_6R("A-B-B-C-C-A deadlock", ABBCCA);
> DO_TESTCASE_6R("A-B-C-A-B-C deadlock", ABCABC);
> @@ -2048,7 +2070,7 @@ void locking_selftest(void)
> pr_cont(" |");
> dotest(rlock_ABBA2, SUCCESS, LOCKTYPE_RWLOCK);
> pr_cont(" |");
> - dotest(rwsem_ABBA2, FAILURE, LOCKTYPE_RWSEM);
> + dotest(rwsem_ABBA2, SUCCESS, LOCKTYPE_RWSEM);
>
> print_testname("mixed write-lock/lock-write ABBA");
> pr_cont(" |");
> --
> 1.8.3.1
>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]