diff options
author | Tejun Heo <tj@kernel.org> | 2010-07-02 04:03:51 -0400 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2010-07-02 04:03:51 -0400 |
commit | 4ce48b37bfedc2bc11e61eae76784887e88b922c (patch) | |
tree | 0829ba93c3bb5f586bacd11c3f21711b3de04da2 /kernel | |
parent | cb444766996395d4370bcc17ec895dd4e13ceb72 (diff) |
workqueue: fix race condition in flush_workqueue()
When one flusher is cascading to the next flusher, it first sets
wq->first_flusher to the next one and sets up the next flush cycle.
If there's nothing to do for the next cycle, it clears
wq->flush_flusher and proceeds to the one after that.
If the woken up flusher checks wq->first_flusher before it gets
cleared, it will incorrectly assume the role of the first flusher,
which triggers BUG_ON() sanity check.
Fix it by checking wq->first_flusher again after grabbing the mutex.
Signed-off-by: Tejun Heo <tj@kernel.org>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/workqueue.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 558733801ac0..b59c946433f4 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c | |||
@@ -2138,6 +2138,10 @@ void flush_workqueue(struct workqueue_struct *wq) | |||
2138 | 2138 | ||
2139 | mutex_lock(&wq->flush_mutex); | 2139 | mutex_lock(&wq->flush_mutex); |
2140 | 2140 | ||
2141 | /* we might have raced, check again with mutex held */ | ||
2142 | if (wq->first_flusher != &this_flusher) | ||
2143 | goto out_unlock; | ||
2144 | |||
2141 | wq->first_flusher = NULL; | 2145 | wq->first_flusher = NULL; |
2142 | 2146 | ||
2143 | BUG_ON(!list_empty(&this_flusher.list)); | 2147 | BUG_ON(!list_empty(&this_flusher.list)); |