[PATCH for 2.6.24] fix workqueue creation API lockdep interaction

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Peter Zijlstra <peterz@...>
Cc: Dave Young <hidave.darkstar@...>, Linus Torvalds <torvalds@...>, Linux Kernel Mailing List <linux-kernel@...>, Ingo Molnar <mingo@...>, Oleg Nesterov <oleg@...>
Date: Tuesday, January 15, 2008 - 9:04 am

Dave Young reported warnings from lockdep that the workqueue API
can sometimes try to register lockdep classes with the same key
but different names. This is not permitted in lockdep.

Unfortunately, I was unaware of that restriction when I wrote
the code to debug workqueue problems with lockdep and used the
workqueue name as the lockdep class name. This can obviously
lead to the problem if the workqueue name is dynamic.

This patch solves the problem by always using a constant name
for the workqueue's lockdep class, namely either the constant
name that was passed in or a string consisting of the variable
name.

Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
---
Please be careful with this patch, I haven't been able to test it so far
because my powerbook doesn't have lockdep.

 include/linux/workqueue.h |   14 +++++++++++---
 kernel/workqueue.c        |    5 +++--
 2 files changed, 14 insertions(+), 5 deletions(-)

--- everything.orig/include/linux/workqueue.h	2008-01-15 02:10:55.098131131 +0100
+++ everything/include/linux/workqueue.h	2008-01-15 02:26:37.428130426 +0100
@@ -149,19 +149,27 @@ struct execute_work {
 
 extern struct workqueue_struct *
 __create_workqueue_key(const char *name, int singlethread,
-		       int freezeable, struct lock_class_key *key);
+		       int freezeable, struct lock_class_key *key,
+		       const char *lock_name);
 
 #ifdef CONFIG_LOCKDEP
 #define __create_workqueue(name, singlethread, freezeable)	\
 ({								\
 	static struct lock_class_key __key;			\
+	const char *__lock_name;				\
+								\
+	if (__builtin_constant_p(name))				\
+		__lock_name = (name);				\
+	else							\
+		__lock_name = #name;				\
 								\
 	__create_workqueue_key((name), (singlethread),		\
-			       (freezeable), &__key);		\
+			       (freezeable), &__key,		\
+			       __lock_name);			\
 })
 #else
 #define __create_workqueue(name, singlethread, freezeable)	\
-	__create_workqueue_key((name), (singlethread), (freezeable), NULL)
+	__create_workqueue_key((name), (singlethread), (freezeable), NULL, NULL)
 #endif
 
 #define create_workqueue(name) __create_workqueue((name), 0, 0)
--- everything.orig/kernel/workqueue.c	2008-01-15 02:15:13.578132867 +0100
+++ everything/kernel/workqueue.c	2008-01-15 02:18:40.518138455 +0100
@@ -722,7 +722,8 @@ static void start_workqueue_thread(struc
 struct workqueue_struct *__create_workqueue_key(const char *name,
 						int singlethread,
 						int freezeable,
-						struct lock_class_key *key)
+						struct lock_class_key *key,
+						const char *lock_name)
 {
 	struct workqueue_struct *wq;
 	struct cpu_workqueue_struct *cwq;
@@ -739,7 +740,7 @@ struct workqueue_struct *__create_workqu
 	}
 
 	wq->name = name;
-	lockdep_init_map(&wq->lockdep_map, name, key, 0);
+	lockdep_init_map(&wq->lockdep_map, lock_name, key, 0);
 	wq->singlethread = singlethread;
 	wq->freezeable = freezeable;
 	INIT_LIST_HEAD(&wq->list);


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

Messages in current thread:
2.6.24-rc7 lockdep warning when poweroff, Dave Young, (Mon Jan 14, 5:04 am)
Re: 2.6.24-rc7 lockdep warning when poweroff, Peter Zijlstra, (Mon Jan 14, 5:24 am)
Re: 2.6.24-rc7 lockdep warning when poweroff, Johannes Berg, (Mon Jan 14, 6:35 am)
Re: 2.6.24-rc7 lockdep warning when poweroff, Peter Zijlstra, (Mon Jan 14, 6:41 am)
Re: 2.6.24-rc7 lockdep warning when poweroff, Johannes Berg, (Mon Jan 14, 6:51 am)
Re: 2.6.24-rc7 lockdep warning when poweroff, Johannes Berg, (Tue Jan 15, 6:41 am)
Re: 2.6.24-rc7 lockdep warning when poweroff, Peter Zijlstra, (Tue Jan 15, 8:21 am)
Re: 2.6.24-rc7 lockdep warning when poweroff, Johannes Berg, (Tue Jan 15, 7:54 pm)
Re: 2.6.24-rc7 lockdep warning when poweroff, Johannes Berg, (Tue Jan 15, 8:39 am)
Re: 2.6.24-rc7 lockdep warning when poweroff, Peter Zijlstra, (Tue Jan 15, 8:47 am)
Re: 2.6.24-rc7 lockdep warning when poweroff, Ingo Molnar, (Wed Jan 16, 4:11 am)
[PATCH for 2.6.24] fix workqueue creation API lockdep intera..., Johannes Berg, (Tue Jan 15, 9:04 am)
Re: 2.6.24-rc7 lockdep warning when poweroff, Dave Young, (Mon Jan 14, 8:31 pm)
Re: 2.6.24-rc7 lockdep warning when poweroff, Dave Young, (Mon Jan 14, 9:24 pm)
Re: 2.6.24-rc7 lockdep warning when poweroff, Peter Zijlstra, (Tue Jan 15, 4:42 am)