public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v5 0/2] lockdep: add support for queued rwlock
@ 2014-06-26 17:39 Waiman Long
  2014-06-26 17:39 ` [PATCH v5 1/2] lockdep: restrict the use of recursive read_lock with qrwlock Waiman Long
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Waiman Long @ 2014-06-26 17:39 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Maarten Lankhorst, Rik van Riel
  Cc: linux-kernel, Scott J Norton, Fengguang Wu, Waiman Long

v4->v5:
 - Add patch 2 to update the locking selftest code to handle recursive
   read_lock correctly. Patch 1 has no change.

v3->v4:
 - Document the new read state and move the conditional compilation code
   to lockdep.h.

v2->v3:
 - Add a new read mode (3) for rwlock (used in
   lock_acquire_shared_cond_recursive()) to avoid conflict with other
   use cases of lock_acquire_shared_recursive().

v1->v2:
 - Use less conditional & make it easier to read

With the merging of qrwlock into 3.16, it was found that the btrfs
filesystem hanged readily. A fix was devised and merged into rc2 and
the use of recursive read_lock call was part of the problem.

This patch series addes code to the lockdep subsystem to catch this
kind of recursive read_lock calls in kernel code. It also updates
the locking selftest to handle recursive read_lock correctly so that
it won't complain about test failures whether or not queue rwlock
is configured.

Waiman Long (2):
  lockdep: restrict the use of recursive read_lock with qrwlock
  locking-selftest: Support queue rwlock

 include/linux/lockdep.h  |   12 ++++++++++++
 kernel/locking/lockdep.c |    6 ++++++
 lib/locking-selftest.c   |   16 +++++++++++++---
 3 files changed, 31 insertions(+), 3 deletions(-)


^ permalink raw reply	[flat|nested] 8+ messages in thread
* [PATCH v7 1/2] locking/lockdep: Restrict the use of recursive read_lock() with qrwlock
@ 2014-08-06 17:22 Waiman Long
  2014-08-13 10:56 ` [tip:locking/core] " tip-bot for Waiman Long
  0 siblings, 1 reply; 8+ messages in thread
From: Waiman Long @ 2014-08-06 17:22 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Maarten Lankhorst, Rik van Riel
  Cc: linux-kernel, Scott J Norton, Fengguang Wu, Waiman Long,
	Peter Zijlstra

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. 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>
---
 include/linux/lockdep.h  |   10 +++++++++-
 kernel/locking/lockdep.c |    6 ++++++
 2 files changed, 15 insertions(+), 1 deletions(-)

diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
index 008388f..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 d24e433..097f8ad 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -3595,6 +3595,12 @@ void lock_acquire(struct lockdep_map *lock, unsigned int subclass,
 	raw_local_irq_save(flags);
 	check_flags(flags);
 
+	/*
+	 * An interrupt recursive read in interrupt context can be considered
+	 * to be the same as a recursive read from checking perspective.
+	 */
+	if ((read == 3) && in_interrupt())
+		read = 2;
 	current->lockdep_recursion = 1;
 	trace_lock_acquire(lock, subclass, trylock, read, check, nest_lock, ip);
 	__lock_acquire(lock, subclass, trylock, read, check,
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-08-13 10:58 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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:locking/core] locking/lockdep: Restrict the use of recursive read_lock() " tip-bot for Waiman Long
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox