From: Waiman Long <Waiman.Long@hp.com>
To: Ingo Molnar <mingo@kernel.org>, Peter Zijlstra <peterz@infradead.org>
Cc: linux-kernel@vger.kernel.org,
Scott J Norton <scott.norton@hp.com>,
Waiman Long <Waiman.Long@hp.com>
Subject: [PATCH] lockdep: restrict the use of recursive read_lock with qrwlock
Date: Fri, 20 Jun 2014 12:22:43 -0400 [thread overview]
Message-ID: <1403281363-33403-1-git-send-email-Waiman.Long@hp.com> (raw)
Unlike the original unfair rwlock implementation, queued rwlock
will grant lock according to the chronological sequence of the lock
requests except when the lock requester is in the interrupt context.
As a result, recursive read_lock calls will hang the process if there
is a write_lock call somewhere in between the read_lock calls.
This patch updates the lockdep implementation to look for recursive
read_lock calls when queued rwlock is being used.
Signed-off-by: Waiman Long <Waiman.Long@hp.com>
---
kernel/locking/lockdep.c | 12 ++++++++++++
1 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index d24e433..b6c9f2e 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -1766,12 +1766,22 @@ check_deadlock(struct task_struct *curr, struct held_lock *next,
if (hlock_class(prev) != hlock_class(next))
continue;
+#ifdef CONFIG_QUEUE_RWLOCK
+ /*
+ * Queue rwlock only allows read-after-read recursion of the
+ * same lock class when the latter read is in an interrupt
+ * context.
+ */
+ if ((read == 2) && prev->read && in_interrupt())
+ return 2;
+#else
/*
* Allow read-after-read recursion of the same
* lock class (i.e. read_lock(lock)+read_lock(lock)):
*/
if ((read == 2) && prev->read)
return 2;
+#endif
/*
* We're holding the nest_lock, which serializes this lock's
@@ -1852,8 +1862,10 @@ check_prev_add(struct task_struct *curr, struct held_lock *prev,
* write-lock never takes any other locks, then the reads are
* equivalent to a NOP.
*/
+#ifndef CONFIG_QUEUE_RWLOCK
if (next->read == 2 || prev->read == 2)
return 1;
+#endif
/*
* Is the <prev> -> <next> dependency already present?
*
--
1.7.1
reply other threads:[~2014-06-20 16:22 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=1403281363-33403-1-git-send-email-Waiman.Long@hp.com \
--to=waiman.long@hp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=scott.norton@hp.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
all inboxes | Powered by JetHome®