Skip to content

Commit e5e1170

Browse files
committed
Merge tag 'wq-for-6.6-rc5-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq
Pull workqueue fixes from Tejun Heo: - Fix access-after-free in pwq allocation error path - Implicitly ordered unbound workqueues should lose the implicit ordering if an attribute change which isn't compatible with ordered operation is requested. However, attribute changes requested through the sysfs interface weren't doing that leaving no way to override the implicit ordering through the sysfs interface. Fix it. - Other doc and misc updates * tag 'wq-for-6.6-rc5-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq: workqueue: fix -Wformat-truncation in create_worker workqueue: Override implicit ordered attribute in workqueue_apply_unbound_cpumask() workqueue: Use the kmem_cache_free() instead of kfree() to release pwq workqueue: doc: Fix function and sysfs path errors workqueue: Fix UAF report by KASAN in pwq_release_workfn()
2 parents e8c127b + 5d9c7a1 commit e5e1170

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

Documentation/core-api/workqueue.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ unbound worker-pools and only one work item could be active at any given
244244
time thus achieving the same ordering property as ST wq.
245245

246246
In the current implementation the above configuration only guarantees
247-
ST behavior within a given NUMA node. Instead ``alloc_ordered_queue()`` should
247+
ST behavior within a given NUMA node. Instead ``alloc_ordered_workqueue()`` should
248248
be used to achieve system-wide ST behavior.
249249

250250

@@ -390,7 +390,7 @@ The default affinity scope can be changed with the module parameter
390390
scope can be changed using ``apply_workqueue_attrs()``.
391391

392392
If ``WQ_SYSFS`` is set, the workqueue will have the following affinity scope
393-
related interface files under its ``/sys/devices/virtual/WQ_NAME/``
393+
related interface files under its ``/sys/devices/virtual/workqueue/WQ_NAME/``
394394
directory.
395395

396396
``affinity_scope``

Documentation/translations/zh_CN/core-api/workqueue.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ workqueue将自动创建与属性相匹配的后备工作者池。调节并发
202202
同的排序属性。
203203

204204
在目前的实现中,上述配置只保证了特定NUMA节点内的ST行为。相反,
205-
``alloc_ordered_queue()`` 应该被用来实现全系统的ST行为。
205+
``alloc_ordered_workqueue()`` 应该被用来实现全系统的ST行为。
206206

207207

208208
执行场景示例

kernel/workqueue.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2166,7 +2166,7 @@ static struct worker *create_worker(struct worker_pool *pool)
21662166
{
21672167
struct worker *worker;
21682168
int id;
2169-
char id_buf[16];
2169+
char id_buf[23];
21702170

21712171
/* ID is needed to determine kthread name */
21722172
id = ida_alloc(&pool->worker_ida, GFP_KERNEL);
@@ -4600,12 +4600,22 @@ static int alloc_and_link_pwqs(struct workqueue_struct *wq)
46004600
}
46014601
cpus_read_unlock();
46024602

4603+
/* for unbound pwq, flush the pwq_release_worker ensures that the
4604+
* pwq_release_workfn() completes before calling kfree(wq).
4605+
*/
4606+
if (ret)
4607+
kthread_flush_worker(pwq_release_worker);
4608+
46034609
return ret;
46044610

46054611
enomem:
46064612
if (wq->cpu_pwq) {
4607-
for_each_possible_cpu(cpu)
4608-
kfree(*per_cpu_ptr(wq->cpu_pwq, cpu));
4613+
for_each_possible_cpu(cpu) {
4614+
struct pool_workqueue *pwq = *per_cpu_ptr(wq->cpu_pwq, cpu);
4615+
4616+
if (pwq)
4617+
kmem_cache_free(pwq_cache, pwq);
4618+
}
46094619
free_percpu(wq->cpu_pwq);
46104620
wq->cpu_pwq = NULL;
46114621
}
@@ -5782,9 +5792,13 @@ static int workqueue_apply_unbound_cpumask(const cpumask_var_t unbound_cpumask)
57825792
list_for_each_entry(wq, &workqueues, list) {
57835793
if (!(wq->flags & WQ_UNBOUND))
57845794
continue;
5795+
57855796
/* creating multiple pwqs breaks ordering guarantee */
5786-
if (wq->flags & __WQ_ORDERED)
5787-
continue;
5797+
if (!list_empty(&wq->pwqs)) {
5798+
if (wq->flags & __WQ_ORDERED_EXPLICIT)
5799+
continue;
5800+
wq->flags &= ~__WQ_ORDERED;
5801+
}
57885802

57895803
ctx = apply_wqattrs_prepare(wq, wq->unbound_attrs, unbound_cpumask);
57905804
if (IS_ERR(ctx)) {

0 commit comments

Comments
 (0)