public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 3/2] fix flush_workqueue() vs CPU_DEAD race
@ 2006-12-30 16:10 Oleg Nesterov
  2007-01-03  0:27 ` Andrew Morton
  0 siblings, 1 reply; 6+ messages in thread
From: Oleg Nesterov @ 2006-12-30 16:10 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Ingo Molnar, David Howells, Christoph Hellwig, Gautham R Shenoy,
	linux-kernel

"[PATCH 1/2] reimplement flush_workqueue()" fixed one race when CPU goes down
while flush_cpu_workqueue() plays with it. But there is another problem, CPU
can die before flush_workqueue() has a chance to call flush_cpu_workqueue().
In that case pending work_structs can migrate to CPU which was already checked,
so we should redo the "for_each_online_cpu(cpu)" loop.

Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>

--- mm-6.20-rc2/kernel/workqueue.c~3_race	2006-12-29 18:37:31.000000000 +0300
+++ mm-6.20-rc2/kernel/workqueue.c	2006-12-30 18:09:07.000000000 +0300
@@ -65,6 +65,7 @@ struct workqueue_struct {
 
 /* All the per-cpu workqueues on the system, for hotplug cpu to add/remove
    threads to each one as cpus come/go. */
+static long hotplug_sequence __read_mostly;
 static DEFINE_MUTEX(workqueue_mutex);
 static LIST_HEAD(workqueues);
 
@@ -454,10 +455,16 @@ void fastcall flush_workqueue(struct wor
 		/* Always use first cpu's area. */
 		flush_cpu_workqueue(per_cpu_ptr(wq->cpu_wq, singlethread_cpu));
 	} else {
+		long sequence;
 		int cpu;
+again:
+		sequence = hotplug_sequence;
 
 		for_each_online_cpu(cpu)
 			flush_cpu_workqueue(per_cpu_ptr(wq->cpu_wq, cpu));
+
+		if (unlikely(sequence != hotplug_sequence))
+			goto again;
 	}
 	mutex_unlock(&workqueue_mutex);
 }
@@ -874,6 +881,7 @@ static int __devinit workqueue_cpu_callb
 			cleanup_workqueue_thread(wq, hotcpu);
 		list_for_each_entry(wq, &workqueues, list)
 			take_over_work(wq, hotcpu);
+		hotplug_sequence++;
 		break;
 
 	case CPU_LOCK_RELEASE:


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2007-01-04  4:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-12-30 16:10 [PATCH 3/2] fix flush_workqueue() vs CPU_DEAD race Oleg Nesterov
2007-01-03  0:27 ` Andrew Morton
2007-01-03 14:04   ` Gautham R Shenoy
2007-01-03 15:17     ` Gautham R Shenoy
2007-01-03 17:26       ` Oleg Nesterov
2007-01-04  4:30         ` Gautham R Shenoy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox