From: tip-bot for Waiman Long <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, hpa@zytor.com, mingo@kernel.org,
torvalds@linux-foundation.org, peterz@infradead.org,
riel@redhat.com, Waiman.Long@hp.com, tglx@linutronix.de,
scott.norton@hp.com, fengguang.wu@intel.com,
maarten.lankhorst@canonical.com
Subject: [tip:locking/core] locking/lockdep: Restrict the use of recursive read_lock() with qrwlock
Date: Thu, 17 Jul 2014 04:00:03 -0700 [thread overview]
Message-ID: <tip-e0645a111cb44e01adc6bfff34f683323863f4d2@git.kernel.org> (raw)
In-Reply-To: <1403804351-405-2-git-send-email-Waiman.Long@hp.com>
Commit-ID: e0645a111cb44e01adc6bfff34f683323863f4d2
Gitweb: http://git.kernel.org/tip/e0645a111cb44e01adc6bfff34f683323863f4d2
Author: Waiman Long <Waiman.Long@hp.com>
AuthorDate: Thu, 26 Jun 2014 13:39:10 -0400
Committer: Ingo Molnar <mingo@kernel.org>
CommitDate: Thu, 17 Jul 2014 12:32:52 +0200
locking/lockdep: Restrict the use of recursive read_lock() with qrwlock
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.
Consequently, recursive read_lock calls will now 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. A new read state (3)
is used to mark those read_lock call that cannot be recursively called
except in the interrupt context. The new read state does exhaust the
2 bits available in held_lock:read bit field. The addition of any new
read state in the future may require a redesign of how all those bits
are squeezed together in the held_lock structure.
Signed-off-by: Waiman Long <Waiman.Long@hp.com>
Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Cc: Scott J Norton <scott.norton@hp.com>
Cc: Fengguang Wu <fengguang.wu@intel.com>
Cc: Maarten Lankhorst <maarten.lankhorst@canonical.com>
Cc: Rik van Riel <riel@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: http://lkml.kernel.org/r/1403804351-405-2-git-send-email-Waiman.Long@hp.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
include/linux/lockdep.h | 10 +++++++++-
kernel/locking/lockdep.c | 6 ++++++
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
index 008388f9..dadd6ba 100644
--- a/include/linux/lockdep.h
+++ b/include/linux/lockdep.h
@@ -478,16 +478,24 @@ static inline void print_irqtrace_events(struct task_struct *curr)
* on the per lock-class debug mode:
*/
+/*
+ * Read states in the 2-bit held_lock:read field:
+ * 0: Exclusive lock
+ * 1: Shareable lock, cannot be recursively called
+ * 2: Shareable lock, can be recursively called
+ * 3: Shareable lock, cannot be recursively called except in interrupt context
+ */
#define lock_acquire_exclusive(l, s, t, n, i) lock_acquire(l, s, t, 0, 1, n, i)
#define lock_acquire_shared(l, s, t, n, i) lock_acquire(l, s, t, 1, 1, n, i)
#define lock_acquire_shared_recursive(l, s, t, n, i) lock_acquire(l, s, t, 2, 1, n, i)
+#define lock_acquire_shared_irecursive(l, s, t, n, i) lock_acquire(l, s, t, 3, 1, n, i)
#define spin_acquire(l, s, t, i) lock_acquire_exclusive(l, s, t, NULL, i)
#define spin_acquire_nest(l, s, t, n, i) lock_acquire_exclusive(l, s, t, n, i)
#define spin_release(l, n, i) lock_release(l, n, i)
#define rwlock_acquire(l, s, t, i) lock_acquire_exclusive(l, s, t, NULL, i)
-#define rwlock_acquire_read(l, s, t, i) lock_acquire_shared_recursive(l, s, t, NULL, i)
+#define rwlock_acquire_read(l, s, t, i) lock_acquire_shared_irecursive(l, s, t, NULL, i)
#define rwlock_release(l, n, i) lock_release(l, n, i)
#define seqcount_acquire(l, s, t, i) lock_acquire_exclusive(l, s, t, NULL, i)
diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index 88d0d44..be83c3c 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -1776,6 +1776,12 @@ check_deadlock(struct task_struct *curr, struct held_lock *next,
return 2;
/*
+ * Recursive read-lock allowed only in interrupt context
+ */
+ if ((read == 3) && prev->read && in_interrupt())
+ return 2;
+
+ /*
* We're holding the nest_lock, which serializes this lock's
* nesting behaviour.
*/
next prev parent reply other threads:[~2014-07-17 11:01 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-26 17:39 [PATCH v5 0/2] lockdep: add support for queued rwlock Waiman Long
2014-06-26 17:39 ` [PATCH v5 1/2] lockdep: restrict the use of recursive read_lock with qrwlock Waiman Long
2014-07-17 11:00 ` tip-bot for Waiman Long [this message]
2014-06-26 17:39 ` [PATCH v5 2/2] locking-selftest: Support queue rwlock Waiman Long
2014-07-17 11:00 ` [tip:locking/core] locking/selftest: Support queued rwlock tip-bot for Waiman Long
2014-07-07 12:50 ` [PATCH v5 0/2] lockdep: add support for " Peter Zijlstra
2014-07-15 19:19 ` Waiman Long
-- strict thread matches above, loose matches on Subject: below --
2014-08-06 17:22 [PATCH v7 1/2] locking/lockdep: Restrict the use of recursive read_lock() with qrwlock Waiman Long
2014-08-13 10:56 ` [tip:locking/core] " tip-bot for Waiman Long
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=tip-e0645a111cb44e01adc6bfff34f683323863f4d2@git.kernel.org \
--to=tipbot@zytor.com \
--cc=Waiman.Long@hp.com \
--cc=fengguang.wu@intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=maarten.lankhorst@canonical.com \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=riel@redhat.com \
--cc=scott.norton@hp.com \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
/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