diff options
author | Tejun Heo <tj@kernel.org> | 2013-03-13 19:51:35 -0400 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2013-03-13 19:51:35 -0400 |
commit | 983ca25e738ee0c9c5435a503a6bb0034d4552b0 (patch) | |
tree | 24d945cc7c5476220f5d7c3a1fefddbc2f056373 /kernel/workqueue.c | |
parent | 699ce097efe8f45bc5c055e4f12cb1e271c270d9 (diff) |
workqueue: fix max_active handling in init_and_link_pwq()
Since 9e8cd2f589 ("workqueue: implement apply_workqueue_attrs()"),
init_and_link_pwq() may be called to initialize a new pool_workqueue
for a workqueue which is already online, but the function was setting
pwq->max_active to wq->saved_max_active without proper
synchronization.
Fix it by calling pwq_adjust_max_active() under proper locking instead
of manually setting max_active.
Signed-off-by: Tejun Heo <tj@kernel.org>
Diffstat (limited to 'kernel/workqueue.c')
-rw-r--r-- | kernel/workqueue.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 9e2ec4ca415a..756761480a1a 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c | |||
@@ -3771,21 +3771,25 @@ static void init_and_link_pwq(struct pool_workqueue *pwq, | |||
3771 | pwq->wq = wq; | 3771 | pwq->wq = wq; |
3772 | pwq->flush_color = -1; | 3772 | pwq->flush_color = -1; |
3773 | pwq->refcnt = 1; | 3773 | pwq->refcnt = 1; |
3774 | pwq->max_active = wq->saved_max_active; | ||
3775 | INIT_LIST_HEAD(&pwq->delayed_works); | 3774 | INIT_LIST_HEAD(&pwq->delayed_works); |
3776 | INIT_LIST_HEAD(&pwq->mayday_node); | 3775 | INIT_LIST_HEAD(&pwq->mayday_node); |
3777 | INIT_WORK(&pwq->unbound_release_work, pwq_unbound_release_workfn); | 3776 | INIT_WORK(&pwq->unbound_release_work, pwq_unbound_release_workfn); |
3778 | 3777 | ||
3779 | /* | ||
3780 | * Link @pwq and set the matching work_color. This is synchronized | ||
3781 | * with flush_mutex to avoid confusing flush_workqueue(). | ||
3782 | */ | ||
3783 | mutex_lock(&wq->flush_mutex); | 3778 | mutex_lock(&wq->flush_mutex); |
3784 | spin_lock_irq(&workqueue_lock); | 3779 | spin_lock_irq(&workqueue_lock); |
3785 | 3780 | ||
3781 | /* | ||
3782 | * Set the matching work_color. This is synchronized with | ||
3783 | * flush_mutex to avoid confusing flush_workqueue(). | ||
3784 | */ | ||
3786 | if (p_last_pwq) | 3785 | if (p_last_pwq) |
3787 | *p_last_pwq = first_pwq(wq); | 3786 | *p_last_pwq = first_pwq(wq); |
3788 | pwq->work_color = wq->work_color; | 3787 | pwq->work_color = wq->work_color; |
3788 | |||
3789 | /* sync max_active to the current setting */ | ||
3790 | pwq_adjust_max_active(pwq); | ||
3791 | |||
3792 | /* link in @pwq */ | ||
3789 | list_add_rcu(&pwq->pwqs_node, &wq->pwqs); | 3793 | list_add_rcu(&pwq->pwqs_node, &wq->pwqs); |
3790 | 3794 | ||
3791 | spin_unlock_irq(&workqueue_lock); | 3795 | spin_unlock_irq(&workqueue_lock); |