aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/workqueue.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-03-12 14:30:04 -0400
committerTejun Heo <tj@kernel.org>2013-03-12 14:30:04 -0400
commit8719dceae2f98a578507c0f6b49c93f320bd729c (patch)
tree3132f4c6ed84ec893bcad3aaec230fa78cede95d /kernel/workqueue.c
parent618b01eb426dd2d73a4b5e5ebc6379e4eee3b123 (diff)
workqueue: reject adjusting max_active or applying attrs to ordered workqueues
Adjusting max_active of or applying new workqueue_attrs to an ordered workqueue breaks its ordering guarantee. The former is obvious. The latter is because applying attrs creates a new pwq (pool_workqueue) and there is no ordering constraint between the old and new pwqs. Make apply_workqueue_attrs() and workqueue_set_max_active() trigger WARN_ON() if those operations are requested on an ordered workqueue and fail / ignore respectively. Signed-off-by: Tejun Heo <tj@kernel.org> Reviewed-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Diffstat (limited to 'kernel/workqueue.c')
-rw-r--r--kernel/workqueue.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 590f4d048ec7..cecd4ffe2c40 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -3494,9 +3494,14 @@ int apply_workqueue_attrs(struct workqueue_struct *wq,
3494 struct pool_workqueue *pwq, *last_pwq; 3494 struct pool_workqueue *pwq, *last_pwq;
3495 struct worker_pool *pool; 3495 struct worker_pool *pool;
3496 3496
3497 /* only unbound workqueues can change attributes */
3497 if (WARN_ON(!(wq->flags & WQ_UNBOUND))) 3498 if (WARN_ON(!(wq->flags & WQ_UNBOUND)))
3498 return -EINVAL; 3499 return -EINVAL;
3499 3500
3501 /* creating multiple pwqs breaks ordering guarantee */
3502 if (WARN_ON((wq->flags & __WQ_ORDERED) && !list_empty(&wq->pwqs)))
3503 return -EINVAL;
3504
3500 pwq = kmem_cache_zalloc(pwq_cache, GFP_KERNEL); 3505 pwq = kmem_cache_zalloc(pwq_cache, GFP_KERNEL);
3501 if (!pwq) 3506 if (!pwq)
3502 return -ENOMEM; 3507 return -ENOMEM;
@@ -3752,6 +3757,10 @@ void workqueue_set_max_active(struct workqueue_struct *wq, int max_active)
3752{ 3757{
3753 struct pool_workqueue *pwq; 3758 struct pool_workqueue *pwq;
3754 3759
3760 /* disallow meddling with max_active for ordered workqueues */
3761 if (WARN_ON(wq->flags & __WQ_ORDERED))
3762 return;
3763
3755 max_active = wq_clamp_max_active(max_active, wq->flags, wq->name); 3764 max_active = wq_clamp_max_active(max_active, wq->flags, wq->name);
3756 3765
3757 spin_lock_irq(&workqueue_lock); 3766 spin_lock_irq(&workqueue_lock);