On Mon, Jan 08, 2007 at 12:51:03AM +0300, Oleg Nesterov wrote:
This is head-spinning :)
Spotted atleast these problems:
1. run_workqueue()->work.func()->flush_work()->mutex_lock(workqueue_mutex)
deadlocks if we are blocked in cleanup_workqueue_thread()->kthread_stop()
for the same worker thread to exit.
Looks possible in practice to me.
2.
CPU_DEAD->cleanup_workqueue_thread->(cwq->thread = NULL)->kthread_stop() ..
^^^^^^^^^^^^^^^^^^^^
|___ Problematic
Now while we are blocked here, if a work->func() calls
flush_workqueue->flush_cpu_workqueue, we clearly cant identify that event
thread is trying to flush its own queue (cwq->thread == current test
fails) and hence we will deadlock.
A lock_cpu_hotplug(), or any other ability to block concurrent hotplug
operations from happening, in run_workqueue would have avoided both the above
races.
Alternatively, for the second race, I guess we can avoid setting
cwq->thread = NULL in cleanup_workqueue_thread() till the thread has exited,
but I am not sure if that opens up any other race. The first race seems
harder to fix ..
I wonder if spin (spinroot.com) or some other formal model can make this job of
spotting-races easier for us ..
--
Regards,
vatsa
-