aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/workqueue.c
diff options
context:
space:
mode:
authorThomas Tuttle <ttuttle@chromium.org>2011-09-14 19:22:28 -0400
committerHerton Ronaldo Krzesinski <herton.krzesinski@canonical.com>2011-10-17 13:32:53 -0400
commit2dfe1f24c61abf4bc4275fe164d0cc97d8d43c58 (patch)
tree589111fa690778bcc876a370c4f98627f4b21b67 /kernel/workqueue.c
parent6185ff7cca118512da1b0f67db981e14b2a7984a (diff)
workqueue: lock cwq access in drain_workqueue
BugLink: http://bugs.launchpad.net/bugs/868628 commit fa2563e41c3d6d6e8af437643981ed28ae0cb56d upstream. Take cwq->gcwq->lock to avoid racing between drain_workqueue checking to make sure the workqueues are empty and cwq_dec_nr_in_flight decrementing and then incrementing nr_active when it activates a delayed work. We discovered this when a corner case in one of our drivers resulted in us trying to destroy a workqueue in which the remaining work would always requeue itself again in the same workqueue. We would hit this race condition and trip the BUG_ON on workqueue.c:3080. Signed-off-by: Thomas Tuttle <ttuttle@chromium.org> Acked-by: Tejun Heo <tj@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'kernel/workqueue.c')
-rw-r--r--kernel/workqueue.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 0400553f0d0..aec02b6a1c4 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -3026,8 +3026,13 @@ reflush:
3026 3026
3027 for_each_cwq_cpu(cpu, wq) { 3027 for_each_cwq_cpu(cpu, wq) {
3028 struct cpu_workqueue_struct *cwq = get_cwq(cpu, wq); 3028 struct cpu_workqueue_struct *cwq = get_cwq(cpu, wq);
3029 bool drained;
3029 3030
3030 if (!cwq->nr_active && list_empty(&cwq->delayed_works)) 3031 spin_lock_irq(&cwq->gcwq->lock);
3032 drained = !cwq->nr_active && list_empty(&cwq->delayed_works);
3033 spin_unlock_irq(&cwq->gcwq->lock);
3034
3035 if (drained)
3031 continue; 3036 continue;
3032 3037
3033 if (++flush_cnt == 10 || 3038 if (++flush_cnt == 10 ||