提交 d5abe669 编写于 作者: P Peter Zijlstra 提交者: Linus Torvalds

[PATCH] debug: workqueue locking sanity

Workqueue functions should not leak locks, assert so, printing the
last function ran.

Use macros in lockdep.h to avoid include dependency pains.

[akpm@osdl.org: build fix]
Signed-off-by: NPeter Zijlstra <a.p.zijlstra@chello.nl>
Acked-by: NIngo Molnar <mingo@elte.hu>
Signed-off-by: NAndrew Morton <akpm@osdl.org>
Signed-off-by: NLinus Torvalds <torvalds@osdl.org>
上级 6fb50ea7
...@@ -243,6 +243,8 @@ extern void lock_release(struct lockdep_map *lock, int nested, ...@@ -243,6 +243,8 @@ extern void lock_release(struct lockdep_map *lock, int nested,
# define INIT_LOCKDEP .lockdep_recursion = 0, # define INIT_LOCKDEP .lockdep_recursion = 0,
#define lockdep_depth(tsk) ((tsk)->lockdep_depth)
#else /* !LOCKDEP */ #else /* !LOCKDEP */
static inline void lockdep_off(void) static inline void lockdep_off(void)
...@@ -277,6 +279,9 @@ static inline int lockdep_internal(void) ...@@ -277,6 +279,9 @@ static inline int lockdep_internal(void)
* The class key takes no space if lockdep is disabled: * The class key takes no space if lockdep is disabled:
*/ */
struct lock_class_key { }; struct lock_class_key { };
#define lockdep_depth(tsk) (0)
#endif /* !LOCKDEP */ #endif /* !LOCKDEP */
#if defined(CONFIG_TRACE_IRQFLAGS) && defined(CONFIG_GENERIC_HARDIRQS) #if defined(CONFIG_TRACE_IRQFLAGS) && defined(CONFIG_GENERIC_HARDIRQS)
......
...@@ -30,6 +30,8 @@ ...@@ -30,6 +30,8 @@
#include <linux/hardirq.h> #include <linux/hardirq.h>
#include <linux/mempolicy.h> #include <linux/mempolicy.h>
#include <linux/freezer.h> #include <linux/freezer.h>
#include <linux/kallsyms.h>
#include <linux/debug_locks.h>
/* /*
* The per-CPU workqueue (if single thread, we always use the first * The per-CPU workqueue (if single thread, we always use the first
...@@ -253,6 +255,17 @@ static void run_workqueue(struct cpu_workqueue_struct *cwq) ...@@ -253,6 +255,17 @@ static void run_workqueue(struct cpu_workqueue_struct *cwq)
work_release(work); work_release(work);
f(work); f(work);
if (unlikely(in_atomic() || lockdep_depth(current) > 0)) {
printk(KERN_ERR "BUG: workqueue leaked lock or atomic: "
"%s/0x%08x/%d\n",
current->comm, preempt_count(),
current->pid);
printk(KERN_ERR " last function: ");
print_symbol("%s\n", (unsigned long)f);
debug_show_held_locks(current);
dump_stack();
}
spin_lock_irqsave(&cwq->lock, flags); spin_lock_irqsave(&cwq->lock, flags);
cwq->remove_sequence++; cwq->remove_sequence++;
wake_up(&cwq->work_done); wake_up(&cwq->work_done);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册