Skip to content

Commit 0997aa5

Browse files
fmoessbaueraxboe
authored andcommitted
io_uring/io-wq: do not allow pinning outside of cpuset
The io worker threads are userland threads that just never exit to the userland. By that, they are also assigned to a cgroup (the group of the creating task). When changing the affinity of the io_wq thread via syscall, we must only allow cpumasks within the limits defined by the cpuset controller of the cgroup (if enabled). Fixes: da64d6d ("io_uring: One wqe per wq") Signed-off-by: Felix Moessbauer <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 90bfb28 commit 0997aa5

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

io_uring/io-wq.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/slab.h>
1414
#include <linux/rculist_nulls.h>
1515
#include <linux/cpu.h>
16+
#include <linux/cpuset.h>
1617
#include <linux/task_work.h>
1718
#include <linux/audit.h>
1819
#include <linux/mmu_context.h>
@@ -1322,17 +1323,29 @@ static int io_wq_cpu_offline(unsigned int cpu, struct hlist_node *node)
13221323

13231324
int io_wq_cpu_affinity(struct io_uring_task *tctx, cpumask_var_t mask)
13241325
{
1326+
cpumask_var_t allowed_mask;
1327+
int ret = 0;
1328+
13251329
if (!tctx || !tctx->io_wq)
13261330
return -EINVAL;
13271331

1332+
if (!alloc_cpumask_var(&allowed_mask, GFP_KERNEL))
1333+
return -ENOMEM;
1334+
13281335
rcu_read_lock();
1329-
if (mask)
1330-
cpumask_copy(tctx->io_wq->cpu_mask, mask);
1331-
else
1332-
cpumask_copy(tctx->io_wq->cpu_mask, cpu_possible_mask);
1336+
cpuset_cpus_allowed(tctx->io_wq->task, allowed_mask);
1337+
if (mask) {
1338+
if (cpumask_subset(mask, allowed_mask))
1339+
cpumask_copy(tctx->io_wq->cpu_mask, mask);
1340+
else
1341+
ret = -EINVAL;
1342+
} else {
1343+
cpumask_copy(tctx->io_wq->cpu_mask, allowed_mask);
1344+
}
13331345
rcu_read_unlock();
13341346

1335-
return 0;
1347+
free_cpumask_var(allowed_mask);
1348+
return ret;
13361349
}
13371350

13381351
/*

0 commit comments

Comments
 (0)