mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-05 10:31:46 +09:00
io_uring/io-wq: do not allow pinning outside of cpuset
commit 0997aa5497c714edbb349ca366d28bd550ba3408 upstream.
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: da64d6db3b ("io_uring: One wqe per wq")
Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
Link: https://lore.kernel.org/r/20240910171157.166423-2-felix.moessbauer@siemens.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
d8920d2534
commit
fce514611f
@@ -13,6 +13,7 @@
|
|||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
#include <linux/rculist_nulls.h>
|
#include <linux/rculist_nulls.h>
|
||||||
#include <linux/cpu.h>
|
#include <linux/cpu.h>
|
||||||
|
#include <linux/cpuset.h>
|
||||||
#include <linux/task_work.h>
|
#include <linux/task_work.h>
|
||||||
#include <linux/audit.h>
|
#include <linux/audit.h>
|
||||||
#include <uapi/linux/io_uring.h>
|
#include <uapi/linux/io_uring.h>
|
||||||
@@ -1362,22 +1363,34 @@ static int io_wq_cpu_offline(unsigned int cpu, struct hlist_node *node)
|
|||||||
|
|
||||||
int io_wq_cpu_affinity(struct io_uring_task *tctx, cpumask_var_t mask)
|
int io_wq_cpu_affinity(struct io_uring_task *tctx, cpumask_var_t mask)
|
||||||
{
|
{
|
||||||
|
cpumask_var_t allowed_mask;
|
||||||
|
int ret = 0;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (!tctx || !tctx->io_wq)
|
if (!tctx || !tctx->io_wq)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
if (!alloc_cpumask_var(&allowed_mask, GFP_KERNEL))
|
||||||
|
return -ENOMEM;
|
||||||
|
cpuset_cpus_allowed(tctx->io_wq->task, allowed_mask);
|
||||||
|
|
||||||
rcu_read_lock();
|
rcu_read_lock();
|
||||||
for_each_node(i) {
|
for_each_node(i) {
|
||||||
struct io_wqe *wqe = tctx->io_wq->wqes[i];
|
struct io_wqe *wqe = tctx->io_wq->wqes[i];
|
||||||
|
if (mask) {
|
||||||
if (mask)
|
if (cpumask_subset(mask, allowed_mask))
|
||||||
cpumask_copy(wqe->cpu_mask, mask);
|
cpumask_copy(wqe->cpu_mask, mask);
|
||||||
else
|
else
|
||||||
cpumask_copy(wqe->cpu_mask, cpumask_of_node(i));
|
ret = -EINVAL;
|
||||||
|
} else {
|
||||||
|
if (!cpumask_and(wqe->cpu_mask, cpumask_of_node(i), allowed_mask))
|
||||||
|
cpumask_copy(wqe->cpu_mask, allowed_mask);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
rcu_read_unlock();
|
rcu_read_unlock();
|
||||||
return 0;
|
|
||||||
|
free_cpumask_var(allowed_mask);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user