[RFC][PATCH 7/7] lockdep: spin_lock_nest_lock()

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Linus Torvalds <torvalds@...>, David Miller <davem@...>, <jeremy@...>, <hugh@...>, <mingo@...>, <akpm@...>, <a.p.zijlstra@...>, <linux-kernel@...>, <davej@...>
Date: Monday, August 4, 2008 - 9:03 am

Expose the new lock protection lock.

This can be used to annotate places where we take multiple locks of the
same class and avoid deadlocks by always taking another (top-level) lock
first.

NOTE: we're still bound to the MAX_LOCK_DEPTH (48) limit.

Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
---
 include/linux/lockdep.h  |    2 ++
 include/linux/spinlock.h |    6 ++++++
 kernel/spinlock.c        |   11 +++++++++++
 3 files changed, 19 insertions(+)

Index: linux-2.6/include/linux/lockdep.h
===================================================================
--- linux-2.6.orig/include/linux/lockdep.h
+++ linux-2.6/include/linux/lockdep.h
@@ -410,8 +410,10 @@ static inline void print_irqtrace_events
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
 # ifdef CONFIG_PROVE_LOCKING
 #  define spin_acquire(l, s, t, i)		lock_acquire(l, s, t, 0, 2, NULL, i)
+#  define spin_acquire_nest(l, s, t, n, i)	lock_acquire(l, s, t, 0, 2, n, i)
 # else
 #  define spin_acquire(l, s, t, i)		lock_acquire(l, s, t, 0, 1, NULL, i)
+#  define spin_acquire_nest(l, s, t, n, i)	lock_acquire(l, s, t, 0, 1, NULL, i)
 # endif
 # define spin_release(l, n, i)			lock_release(l, n, i)
 #else
Index: linux-2.6/include/linux/spinlock.h
===================================================================
--- linux-2.6.orig/include/linux/spinlock.h
+++ linux-2.6/include/linux/spinlock.h
@@ -183,8 +183,14 @@ do {								\
 
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
 # define spin_lock_nested(lock, subclass) _spin_lock_nested(lock, subclass)
+# define spin_lock_nest_lock(lock, nest_lock)				\
+	 do {								\
+		 typecheck(struct lockdep_map *, &nest_lock->dep_map);	\
+		 _spin_lock_nest_lock(lock, &nest_lock->dep_map);	\
+	 } while (0)
 #else
 # define spin_lock_nested(lock, subclass) _spin_lock(lock)
+# define spin_lock_nest_lock(lock, nest_lock) _spin_lock(lock)
 #endif
 
 #define write_lock(lock)		_write_lock(lock)
Index: linux-2.6/kernel/spinlock.c
===================================================================
--- linux-2.6.orig/kernel/spinlock.c
+++ linux-2.6/kernel/spinlock.c
@@ -292,6 +292,7 @@ void __lockfunc _spin_lock_nested(spinlo
 }
 
 EXPORT_SYMBOL(_spin_lock_nested);
+
 unsigned long __lockfunc _spin_lock_irqsave_nested(spinlock_t *lock, int subclass)
 {
 	unsigned long flags;
@@ -314,6 +315,16 @@ unsigned long __lockfunc _spin_lock_irqs
 
 EXPORT_SYMBOL(_spin_lock_irqsave_nested);
 
+void __lockfunc _spin_lock_nest_lock(spinlock_t *lock,
+				     struct lockdep_map *nest_lock)
+{
+	preempt_disable();
+	spin_acquire_nest(&lock->dep_map, 0, 0, nest_lock, _RET_IP_);
+	LOCK_CONTENDED(lock, _raw_spin_trylock, _raw_spin_lock);
+}
+
+EXPORT_SYMBOL(_spin_lock_nest_lock)
+
 #endif
 
 void __lockfunc _spin_unlock(spinlock_t *lock)

-- 

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Peter Zijlstra, (Mon Aug 4, 9:03 am)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Peter Zijlstra, (Thu Aug 7, 7:25 am)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Jeremy Fitzhardinge, (Mon Aug 4, 2:06 pm)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Peter Zijlstra, (Mon Aug 4, 2:54 pm)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Jeremy Fitzhardinge, (Mon Aug 4, 3:26 pm)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Linus Torvalds, (Mon Aug 4, 3:31 pm)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Steven Rostedt, (Wed Oct 8, 11:27 am)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Nick Piggin, (Wed Oct 8, 11:52 am)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Steven Rostedt, (Wed Oct 8, 1:18 pm)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Linus Torvalds, (Wed Oct 8, 11:43 am)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Steven Rostedt, (Wed Oct 8, 12:03 pm)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Linus Torvalds, (Wed Oct 8, 12:19 pm)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Steven Rostedt, (Wed Oct 8, 12:53 pm)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Jeremy Fitzhardinge, (Mon Aug 4, 4:16 pm)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Peter Zijlstra, (Mon Aug 4, 3:39 pm)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Roland Dreier, (Mon Aug 4, 10:07 am)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Peter Zijlstra, (Mon Aug 4, 10:19 am)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Roland Dreier, (Mon Aug 4, 10:26 am)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Peter Zijlstra, (Mon Aug 4, 10:32 am)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Dave Jones, (Mon Aug 4, 10:53 am)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Peter Zijlstra, (Mon Aug 4, 10:56 am)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Andrea Arcangeli, (Mon Aug 4, 12:26 pm)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Peter Zijlstra, (Mon Aug 4, 12:38 pm)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), David Miller, (Mon Aug 4, 5:32 pm)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Andrea Arcangeli, (Mon Aug 4, 1:27 pm)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Peter Zijlstra, (Mon Aug 4, 2:48 pm)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Andrea Arcangeli, (Mon Aug 4, 1:46 pm)