[PATCH 16/20] lockdep, mutex: Provide mutex_lock_nest_lock

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Peter Zijlstra
Date: Saturday, August 28, 2010 - 7:16 am

Provide the mutex_lock_nest_lock() annotation.

Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
---
 include/linux/lockdep.h |    3 +++
 include/linux/mutex.h   |    9 +++++++++
 kernel/mutex.c          |   25 +++++++++++++++++--------
 3 files changed, 29 insertions(+), 8 deletions(-)

Index: linux-2.6/include/linux/lockdep.h
===================================================================
--- linux-2.6.orig/include/linux/lockdep.h
+++ linux-2.6/include/linux/lockdep.h
@@ -492,12 +492,15 @@ static inline void print_irqtrace_events
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
 # ifdef CONFIG_PROVE_LOCKING
 #  define mutex_acquire(l, s, t, i)		lock_acquire(l, s, t, 0, 2, NULL, i)
+#  define mutex_acquire_nest(l, s, t, n, i)	lock_acquire(l, s, t, 0, 2, n, i)
 # else
 #  define mutex_acquire(l, s, t, i)		lock_acquire(l, s, t, 0, 1, NULL, i)
+#  define mutex_acquire_nest(l, s, t, n, i)	lock_acquire(l, s, t, 0, 1, n, i)
 # endif
 # define mutex_release(l, n, i)			lock_release(l, n, i)
 #else
 # define mutex_acquire(l, s, t, i)		do { } while (0)
+# define mutex_acquire_nest(l, s, t, n, i)	do { } while (0)
 # define mutex_release(l, n, i)			do { } while (0)
 #endif
 
Index: linux-2.6/include/linux/mutex.h
===================================================================
--- linux-2.6.orig/include/linux/mutex.h
+++ linux-2.6/include/linux/mutex.h
@@ -124,6 +124,7 @@ static inline int mutex_is_locked(struct
  */
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
 extern void mutex_lock_nested(struct mutex *lock, unsigned int subclass);
+extern void _mutex_lock_nest_lock(struct mutex *lock, struct lockdep_map *nest_lock);
 extern int __must_check mutex_lock_interruptible_nested(struct mutex *lock,
 					unsigned int subclass);
 extern int __must_check mutex_lock_killable_nested(struct mutex *lock,
@@ -132,6 +133,13 @@ extern int __must_check mutex_lock_killa
 #define mutex_lock(lock) mutex_lock_nested(lock, 0)
 #define mutex_lock_interruptible(lock) mutex_lock_interruptible_nested(lock, 0)
 #define mutex_lock_killable(lock) mutex_lock_killable_nested(lock, 0)
+
+#define mutex_lock_nest_lock(lock, nest_lock)				\
+do {									\
+	typecheck(struct lockdep_map *, &(nest_lock)->dep_map);		\
+	_mutex_lock_nest_lock(lock, &(nest_lock)->dep_map);		\
+} while (0)
+
 #else
 extern void mutex_lock(struct mutex *lock);
 extern int __must_check mutex_lock_interruptible(struct mutex *lock);
@@ -140,6 +148,7 @@ extern int __must_check mutex_lock_killa
 # define mutex_lock_nested(lock, subclass) mutex_lock(lock)
 # define mutex_lock_interruptible_nested(lock, subclass) mutex_lock_interruptible(lock)
 # define mutex_lock_killable_nested(lock, subclass) mutex_lock_killable(lock)
+# define mutex_lock_nest_lock(lock, nest_lock) mutex_lock(lock)
 #endif
 
 /*
Index: linux-2.6/kernel/mutex.c
===================================================================
--- linux-2.6.orig/kernel/mutex.c
+++ linux-2.6/kernel/mutex.c
@@ -140,14 +140,14 @@ EXPORT_SYMBOL(mutex_unlock);
  */
 static inline int __sched
 __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
-	       	unsigned long ip)
+		    struct lockdep_map *nest_lock, unsigned long ip)
 {
 	struct task_struct *task = current;
 	struct mutex_waiter waiter;
 	unsigned long flags;
 
 	preempt_disable();
-	mutex_acquire(&lock->dep_map, subclass, 0, ip);
+	mutex_acquire_nest(&lock->dep_map, subclass, 0, nest_lock, ip);
 
 #ifdef CONFIG_MUTEX_SPIN_ON_OWNER
 	/*
@@ -285,16 +285,25 @@ void __sched
 mutex_lock_nested(struct mutex *lock, unsigned int subclass)
 {
 	might_sleep();
-	__mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, subclass, _RET_IP_);
+	__mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, subclass, NULL, _RET_IP_);
 }
 
 EXPORT_SYMBOL_GPL(mutex_lock_nested);
 
+void __sched
+_mutex_lock_nest_lock(struct mutex *lock, struct lockdep_map *nest)
+{
+	might_sleep();
+	__mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, 0, nest, _RET_IP_);
+}
+
+EXPORT_SYMBOL_GPL(_mutex_lock_nest_lock);
+
 int __sched
 mutex_lock_killable_nested(struct mutex *lock, unsigned int subclass)
 {
 	might_sleep();
-	return __mutex_lock_common(lock, TASK_KILLABLE, subclass, _RET_IP_);
+	return __mutex_lock_common(lock, TASK_KILLABLE, subclass, NULL, _RET_IP_);
 }
 EXPORT_SYMBOL_GPL(mutex_lock_killable_nested);
 
@@ -303,7 +312,7 @@ mutex_lock_interruptible_nested(struct m
 {
 	might_sleep();
 	return __mutex_lock_common(lock, TASK_INTERRUPTIBLE,
-				   subclass, _RET_IP_);
+				   subclass, NULL, _RET_IP_);
 }
 
 EXPORT_SYMBOL_GPL(mutex_lock_interruptible_nested);
@@ -409,7 +418,7 @@ __mutex_lock_slowpath(atomic_t *lock_cou
 {
 	struct mutex *lock = container_of(lock_count, struct mutex, count);
 
-	__mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, 0, _RET_IP_);
+	__mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, 0, NULL, _RET_IP_);
 }
 
 static noinline int __sched
@@ -417,7 +426,7 @@ __mutex_lock_killable_slowpath(atomic_t 
 {
 	struct mutex *lock = container_of(lock_count, struct mutex, count);
 
-	return __mutex_lock_common(lock, TASK_KILLABLE, 0, _RET_IP_);
+	return __mutex_lock_common(lock, TASK_KILLABLE, 0, NULL, _RET_IP_);
 }
 
 static noinline int __sched
@@ -425,7 +434,7 @@ __mutex_lock_interruptible_slowpath(atom
 {
 	struct mutex *lock = container_of(lock_count, struct mutex, count);
 
-	return __mutex_lock_common(lock, TASK_INTERRUPTIBLE, 0, _RET_IP_);
+	return __mutex_lock_common(lock, TASK_INTERRUPTIBLE, 0, NULL, _RET_IP_);
 }
 #endif
 


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

Messages in current thread:
[PATCH 00/20] mm: Preemptibility -v4, Peter Zijlstra, (Sat Aug 28, 7:16 am)
[PATCH 01/20] powerpc: Use call_rcu_sched() for pagetables, Peter Zijlstra, (Sat Aug 28, 7:16 am)
[PATCH 02/20] mm: Improve page_lock_anon_vma() comment, Peter Zijlstra, (Sat Aug 28, 7:16 am)
[PATCH 05/20] mm: Simplify anon_vma refcounts, Peter Zijlstra, (Sat Aug 28, 7:16 am)
[PATCH 06/20] mm: Use refcounts for page_lock_anon_vma(), Peter Zijlstra, (Sat Aug 28, 7:16 am)
[PATCH 07/20] mm: Preemptible mmu_gather, Peter Zijlstra, (Sat Aug 28, 7:16 am)
[PATCH 08/20] powerpc: Preemptible mmu_gather, Peter Zijlstra, (Sat Aug 28, 7:16 am)
[PATCH 09/20] sparc: Preemptible mmu_gather, Peter Zijlstra, (Sat Aug 28, 7:16 am)
[PATCH 10/20] s390: preemptible mmu_gather, Peter Zijlstra, (Sat Aug 28, 7:16 am)
[PATCH 12/20] sh: Preemptible mmu_gather, Peter Zijlstra, (Sat Aug 28, 7:16 am)
[PATCH 13/20] um: Preemptible mmu_gather, Peter Zijlstra, (Sat Aug 28, 7:16 am)
[PATCH 14/20] ia64: Preemptible mmu_gather, Peter Zijlstra, (Sat Aug 28, 7:16 am)
[PATCH 16/20] lockdep, mutex: Provide mutex_lock_nest_lock, Peter Zijlstra, (Sat Aug 28, 7:16 am)
[PATCH 17/20] mutex: Provide mutex_is_contended, Peter Zijlstra, (Sat Aug 28, 7:16 am)
[PATCH 19/20] mm: Extended batches for generic mmu_gather, Peter Zijlstra, (Sat Aug 28, 7:16 am)
[PATCH 20/20] mm: Optimize page_lock_anon_vma() fast-path, Peter Zijlstra, (Sat Aug 28, 7:16 am)
Re: [PATCH 00/20] mm: Preemptibility -v4, Peter Zijlstra, (Sat Aug 28, 7:32 am)
Re: [PATCH 00/20] mm: Preemptibility -v4, Piotr Hosowicz, (Sat Aug 28, 7:56 am)
Re: [PATCH 00/20] mm: Preemptibility -v4, Peter Zijlstra, (Sat Aug 28, 8:10 am)
Re: [PATCH 05/20] mm: Simplify anon_vma refcounts, Pekka Enberg, (Sat Aug 28, 8:13 am)
Re: [PATCH 00/20] mm: Preemptibility -v4, Piotr Hosowicz, (Sat Aug 28, 8:17 am)
Re: [PATCH 00/20] mm: Preemptibility -v4, Pekka Enberg, (Sat Aug 28, 8:19 am)
Re: [PATCH 00/20] mm: Preemptibility -v4, Peter Zijlstra, (Sat Aug 28, 8:23 am)
Re: [PATCH 00/20] mm: Preemptibility -v4, Peter Zijlstra, (Sat Aug 28, 8:27 am)
Re: [PATCH 00/20] mm: Preemptibility -v4, Piotr Hosowicz, (Sat Aug 28, 9:01 am)
Re: [PATCH 00/20] mm: Preemptibility -v4, David Miller, (Sat Aug 28, 3:28 pm)
Re: [PATCH 00/20] mm: Preemptibility -v4, Peter Zijlstra, (Sat Aug 28, 3:41 pm)
Re: [PATCH 00/20] mm: Preemptibility -v4, Piotr Hosowicz, (Sun Aug 29, 5:46 am)
Re: [PATCH 00/20] mm: Preemptibility -v4, Peter Zijlstra, (Sun Aug 29, 6:37 am)
Re: [PATCH 00/20] mm: Preemptibility -v4, Piotr Hosowicz, (Sun Aug 29, 6:43 am)
Re: [PATCH 14/20] ia64: Preemptible mmu_gather, Peter Zijlstra, (Mon Aug 30, 8:44 am)
Re: [PATCH 01/20] powerpc: Use call_rcu_sched() for pagetables, Benjamin Herrenschmidt, (Mon Aug 30, 11:10 pm)
Re: [PATCH 08/20] powerpc: Preemptible mmu_gather, Benjamin Herrenschmidt, (Mon Aug 30, 11:26 pm)
Re: [PATCH 08/20] powerpc: Preemptible mmu_gather, Benjamin Herrenschmidt, (Mon Aug 30, 11:31 pm)
Re: [PATCH 08/20] powerpc: Preemptible mmu_gather, Peter Zijlstra, (Tue Aug 31, 2:14 am)
Re: [PATCH 00/20] mm: Preemptibility -v4, Piotr Hosowicz, (Tue Aug 31, 7:02 am)
Re: [PATCH 00/20] mm: Preemptibility -v4, Piotr Hosowicz, (Tue Aug 31, 7:14 am)
Re: [PATCH 00/20] mm: Preemptibility -v4, Piotr Hosowicz, (Thu Sep 2, 7:53 am)
Re: [PATCH 00/20] mm: Preemptibility -v4, Alex,Shi, (Mon Sep 13, 10:36 pm)
Re: [PATCH 00/20] mm: Preemptibility -v4, Peter Zijlstra, (Tue Sep 14, 12:42 am)