From: Peter Zijlstra <a.p.zijlstra@chello.nl>
To: Ingo Molnar <mingo@elte.hu>, LKML <linux-kernel@vger.kernel.org>
Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>,
Steven Rostedt <rostedt@goodmis.org>,
Thomas Gleixner <tglx@linutronix.de>,
Peter Zijlstra <a.p.zijlstra@chello.nl>
Subject: [RFC][PATCH 1/7] lockdep: Implement extra recursive-read lock tests
Date: Sun, 17 Apr 2011 11:45:06 +0200 [thread overview]
Message-ID: <20110417095506.818055829@chello.nl> (raw)
In-Reply-To: 20110417094505.865828233@chello.nl
[-- Attachment #1: lockdep-test-recursive-read.patch --]
[-- Type: text/plain, Size: 2658 bytes --]
Lockdep is not able to detect simple rw deadlocks because it is not
tracking recursive read dependencies:
read_lock(A) --> spin_lock(B)
spin_lock(B) --> write_lock(A) /* should fail */
Furthermore, the following should not result in a deadlock for
recursive read locks:
read_lock(A) --> spin_lock(B)
spin_lock(B) --> read_lock(A) /* success */
Add these checks so that we may improve lockdep to accurately track
recursive read locks and report the correct answers.
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
---
lib/locking-selftest.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 61 insertions(+)
Index: tip/lib/locking-selftest.c
===================================================================
--- tip.orig/lib/locking-selftest.c
+++ tip/lib/locking-selftest.c
@@ -185,13 +185,16 @@ static void init_shared_classes(void)
#define ML(x) mutex_lock(&mutex_##x)
#define MU(x) mutex_unlock(&mutex_##x)
+#define MLU(x) ML(x); MU(x)
#define MI(x) mutex_init(&mutex_##x)
#define WSL(x) down_write(&rwsem_##x)
#define WSU(x) up_write(&rwsem_##x)
+#define WSLU(x) WSL(x); WSU(x)
#define RSL(x) down_read(&rwsem_##x)
#define RSU(x) up_read(&rwsem_##x)
+#define RSLU(x) RSL(x); RSU(x)
#define RWSI(x) init_rwsem(&rwsem_##x)
#define LOCK_UNLOCK_2(x,y) LOCK(x); LOCK(y); UNLOCK(y); UNLOCK(x)
@@ -300,6 +303,50 @@ static void rsem_AA3(void)
RSL(X2); // this one should fail
}
+static void rwlock_spinlock_ABBA(void)
+{
+ RL(A);
+ LU(B);
+ RU(A);
+
+ L(B);
+ WLU(A); /* fail */
+ U(B);
+}
+
+static void rlock_spinlock_ABBA(void)
+{
+ RL(A);
+ LU(B);
+ RU(A);
+
+ L(B);
+ RLU(A); /* not fail */
+ U(B);
+}
+
+static void rwsem_mutex_ABBA(void)
+{
+ RSL(A);
+ MLU(B);
+ RSU(A);
+
+ ML(B);
+ WSLU(A); /* fail */
+ MU(B);
+}
+
+static void rsem_mutex_ABBA(void)
+{
+ RSL(A);
+ MLU(B);
+ RSU(A);
+
+ ML(B);
+ RSLU(A); /* fail */
+ MU(B);
+}
+
/*
* ABBA deadlock:
*/
@@ -1174,6 +1221,20 @@ void locking_selftest(void)
dotest(rsem_AA3, FAILURE, LOCKTYPE_RWSEM);
printk("\n");
+ print_testname("mixed write-spin-read-lock");
+ printk(" |");
+ dotest(rwlock_spinlock_ABBA, FAILURE, LOCKTYPE_RWLOCK);
+ printk(" |");
+ dotest(rwsem_mutex_ABBA, FAILURE, LOCKTYPE_RWSEM);
+ printk("\n");
+
+ print_testname("mixed read-spin-read-lock");
+ printk(" |");
+ dotest(rlock_spinlock_ABBA, SUCCESS, LOCKTYPE_RWLOCK);
+ printk(" |");
+ dotest(rsem_mutex_ABBA, FAILURE, LOCKTYPE_RWSEM);
+ printk("\n");
+
printk(" --------------------------------------------------------------------------\n");
/*
next prev parent reply other threads:[~2011-04-17 9:58 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-17 9:45 [RFC][PATCH 0/7] lockdep: Support recurise-read locks Peter Zijlstra
2011-04-17 9:45 ` Peter Zijlstra [this message]
2011-04-17 9:45 ` [RFC][PATCH 2/7] lockdep: Remove redundant read checks Peter Zijlstra
2011-04-18 14:28 ` Steven Rostedt
2011-04-17 9:45 ` [RFC][PATCH 3/7] lockdep: Annotate read/write states Peter Zijlstra
2011-04-18 13:34 ` Yong Zhang
2011-04-18 16:34 ` Steven Rostedt
2011-04-18 16:36 ` Peter Zijlstra
2011-04-18 16:26 ` Steven Rostedt
2011-04-18 16:27 ` Steven Rostedt
2011-04-18 16:31 ` Steven Rostedt
2011-04-17 9:45 ` [RFC][PATCH 4/7] lockdep: Seperate lock ids for read/write acquires Peter Zijlstra
2011-04-18 16:46 ` Steven Rostedt
2011-04-18 16:49 ` Peter Zijlstra
2011-04-18 17:33 ` Steven Rostedt
2011-04-18 22:07 ` Peter Zijlstra
2011-04-17 9:45 ` [RFC][PATCH 5/7] lockdep: Rename lock_list::class Peter Zijlstra
2011-04-17 9:45 ` [RFC][PATCH 6/7] lockdep: Maintain rw_state entries in locklist Peter Zijlstra
2011-04-18 13:37 ` Yong Zhang
2011-04-17 9:45 ` [RFC][PATCH 7/7] lockdep: Consider the rw_state of lock while validating the chain Peter Zijlstra
2011-04-18 3:41 ` [RFC][PATCH 0/7] lockdep: Support recurise-read locks Tetsuo Handa
2011-04-22 7:19 ` Yong Zhang
2011-04-22 7:27 ` Yong Zhang
2011-04-22 7:44 ` Tetsuo Handa
2011-04-22 8:01 ` Yong Zhang
2011-04-22 8:31 ` Tetsuo Handa
2011-04-22 8:59 ` Yong Zhang
2011-04-22 9:19 ` Tetsuo Handa
2011-04-23 12:33 ` [PATCH] lockdep: ignore cached chain key for recursive read Yong Zhang
2011-04-23 13:04 ` Tetsuo Handa
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=20110417095506.818055829@chello.nl \
--to=a.p.zijlstra@chello.nl \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=penguin-kernel@I-love.SAKURA.ne.jp \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
/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