linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Boqun Feng <boqun.feng@gmail.com>
To: Yuyang Du <duyuyang@gmail.com>
Cc: peterz@infradead.org, will.deacon@arm.com, mingo@kernel.org,
	bvanassche@acm.org, ming.lei@redhat.com, frederic@kernel.org,
	tglx@linutronix.de, paulmck@linux.ibm.com,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 11/17] locking/lockdep: Adjust lockdep selftest cases
Date: Wed, 29 May 2019 19:44:51 +0800	[thread overview]
Message-ID: <20190529114451.GA12812@tardis> (raw)
In-Reply-To: <20190516080015.16033-12-duyuyang@gmail.com>

[-- 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 --]

  reply	other threads:[~2019-05-29 11:45 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-16  7:59 [PATCH v2 00/17] Support for read-write lock deadlock detection Yuyang Du
2019-05-16  7:59 ` [PATCH v2 01/17] locking/lockdep: Add lock type enum to explicitly specify read or write locks Yuyang Du
2019-05-16  8:00 ` [PATCH v2 02/17] locking/lockdep: Add read-write type for dependency Yuyang Du
2019-05-29 11:37   ` Boqun Feng
2019-05-16  8:00 ` [PATCH v2 03/17] locking/lockdep: Add helper functions to operate on the searched path Yuyang Du
2019-05-16  8:00 ` [PATCH v2 04/17] locking/lockdep: Update direct dependency's read-write type if it exists Yuyang Du
2019-05-16  8:00 ` [PATCH v2 05/17] locking/lockdep: Rename deadlock check functions Yuyang Du
2019-05-16  8:00 ` [PATCH v2 06/17] locking/lockdep: Adjust BFS algorithm to support multiple matches Yuyang Du
2019-05-16  8:00 ` [PATCH v2 07/17] locking/lockdep: Introduce mark_lock_unaccessed() Yuyang Du
2019-05-16  8:00 ` [PATCH v2 08/17] locking/lockdep: Introduce chain_hlocks_type for held lock's read-write type Yuyang Du
2019-05-16  8:00 ` [PATCH v2 09/17] locking/lockdep: Hash held lock's read-write type into chain key Yuyang Du
2019-05-16  8:00 ` [PATCH v2 10/17] locking/lockdep: Support read-write lock's deadlock detection Yuyang Du
2019-05-16  8:00 ` [PATCH v2 11/17] locking/lockdep: Adjust lockdep selftest cases Yuyang Du
2019-05-29 11:44   ` Boqun Feng [this message]
2019-05-30  7:37     ` Yuyang Du
2019-05-16  8:00 ` [PATCH v2 12/17] locking/lockdep: Remove useless lock type assignment Yuyang Du
2019-05-16  8:00 ` [PATCH v2 13/17] locking/lockdep: Add nest lock type Yuyang Du
2019-05-16  8:00 ` [PATCH v2 14/17] locking/lockdep: Support recursive read locks Yuyang Du
2019-05-16  8:00 ` [PATCH v2 15/17] locking/lockdep: Adjust selftest case for recursive read lock Yuyang Du
2019-05-16  8:00 ` [PATCH v2 16/17] locking/lockdep: Add more lockdep selftest cases Yuyang Du
2019-05-16  8:00 ` [PATCH v2 17/17] locking/lockdep: Remove irq-safe to irq-unsafe read check Yuyang Du

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190529114451.GA12812@tardis \
    --to=boqun.feng@gmail.com \
    --cc=bvanassche@acm.org \
    --cc=duyuyang@gmail.com \
    --cc=frederic@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ming.lei@redhat.com \
    --cc=mingo@kernel.org \
    --cc=paulmck@linux.ibm.com \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=will.deacon@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).