LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH 3/3] workqueue: don't clear cwq->thread until it exits
@ 2007-01-11 23:12 Oleg Nesterov
  0 siblings, 0 replies; only message in thread
From: Oleg Nesterov @ 2007-01-11 23:12 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Srivatsa Vaddagiri, Pallipadi, Venkatesh, Gautham shenoy,
	Ingo Molnar, David Howells, Linus Torvalds, linux-kernel

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 <oleg@tv-sign.ru>

--- mm-6.20-rc3/kernel/workqueue.c~3_thread	2007-01-11 22:22:58.000000000 +0300
+++ mm-6.20-rc3/kernel/workqueue.c	2007-01-12 01:44:39.000000000 +0300
@@ -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;
+	}
 }
 
 /**


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2007-01-11 23:13 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-01-11 23:12 [PATCH 3/3] workqueue: don't clear cwq->thread until it exits Oleg Nesterov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).