Skip to content

Commit d5abe66

Browse files
Peter ZijlstraLinus Torvalds
authored andcommitted
[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: Peter Zijlstra <a.p.zijlstra@chello.nl> Acked-by: Ingo Molnar <mingo@elte.hu> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 6fb50ea commit d5abe66

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

‎include/linux/lockdep.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ extern void lock_release(struct lockdep_map *lock, int nested,
243243

244244
# define INIT_LOCKDEP .lockdep_recursion = 0,
245245

246+
#define lockdep_depth(tsk) ((tsk)->lockdep_depth)
247+
246248
#else /* !LOCKDEP */
247249

248250
static inline void lockdep_off(void)
@@ -277,6 +279,9 @@ static inline int lockdep_internal(void)
277279
* The class key takes no space if lockdep is disabled:
278280
*/
279281
struct lock_class_key { };
282+
283+
#define lockdep_depth(tsk) (0)
284+
280285
#endif /* !LOCKDEP */
281286

282287
#if defined(CONFIG_TRACE_IRQFLAGS) && defined(CONFIG_GENERIC_HARDIRQS)

‎kernel/workqueue.c‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include <linux/hardirq.h>
3131
#include <linux/mempolicy.h>
3232
#include <linux/freezer.h>
33+
#include <linux/kallsyms.h>
34+
#include <linux/debug_locks.h>
3335

3436
/*
3537
* 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)
253255
work_release(work);
254256
f(work);
255257

258+
if (unlikely(in_atomic() || lockdep_depth(current) > 0)) {
259+
printk(KERN_ERR "BUG: workqueue leaked lock or atomic: "
260+
"%s/0x%08x/%d\n",
261+
current->comm, preempt_count(),
262+
current->pid);
263+
printk(KERN_ERR " last function: ");
264+
print_symbol("%s\n", (unsigned long)f);
265+
debug_show_held_locks(current);
266+
dump_stack();
267+
}
268+
256269
spin_lock_irqsave(&cwq->lock, flags);
257270
cwq->remove_sequence++;
258271
wake_up(&cwq->work_done);

0 commit comments

Comments
 (0)