workqueue: don't clear cwq->thread until it exits
authorOleg Nesterov <[email protected]>
Wed, 9 May 2007 09:34:08 +0000 (02:34 -0700)
committerLinus Torvalds <[email protected]>
Wed, 9 May 2007 19:30:52 +0000 (12:30 -0700)
Pointed out by Srivatsa Vaddagiri.

cleanup_workqueue_thread() sets cwq->thread = NULL and does kthread_stop().
This breaks the "if (cwq->thread == current)" logic in flush_cpu_workqueue()
and leads to deadlock.

Kill the thead first, then clear cwq->thread. workqueue_mutex protects us
from create_workqueue_thread() so we don't need cwq->lock.

Signed-off-by: Oleg Nesterov <[email protected]>
Cc: Srivatsa Vaddagiri <[email protected]>
Cc: "Pallipadi, Venkatesh" <[email protected]>
Cc: Gautham shenoy <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
kernel/workqueue.c

index 1d1933cf3778163ca4e54f1a7c32055920599d2d..398c34ff6a54a90eb82f90856a75a29dc210bc2d 100644 (file)
@@ -625,17 +625,12 @@ EXPORT_SYMBOL_GPL(__create_workqueue);
 
 static void cleanup_workqueue_thread(struct workqueue_struct *wq, int cpu)
 {
-       struct cpu_workqueue_struct *cwq;
-       unsigned long flags;
-       struct task_struct *p;
+       struct cpu_workqueue_struct *cwq = per_cpu_ptr(wq->cpu_wq, cpu);
 
-       cwq = per_cpu_ptr(wq->cpu_wq, cpu);
-       spin_lock_irqsave(&cwq->lock, flags);
-       p = cwq->thread;
-       cwq->thread = NULL;
-       spin_unlock_irqrestore(&cwq->lock, flags);
-       if (p)
-               kthread_stop(p);
+       if (cwq->thread) {
+               kthread_stop(cwq->thread);
+               cwq->thread = NULL;
+       }
 }
 
 /**