Skip to content

Commit f011c9c

Browse files
fmoessbaueraxboe
authored andcommitted
io_uring/sqpoll: do not allow pinning outside of cpuset
The submit queue polling threads are userland threads that just never exit to the userland. When creating the thread with IORING_SETUP_SQ_AFF, the affinity of the poller thread is set to the cpu specified in sq_thread_cpu. However, this CPU can be outside of the cpuset defined by the cgroup cpuset controller. This violates the rules defined by the cpuset controller and is a potential issue for realtime applications. In b7ed6d8ffd6 we fixed the default affinity of the poller thread, in case no explicit pinning is required by inheriting the one of the creating task. In case of explicit pinning, the check is more complicated, as also a cpu outside of the parent cpumask is allowed. We implemented this by using cpuset_cpus_allowed (that has support for cgroup cpusets) and testing if the requested cpu is in the set. Fixes: 37d1e2e ("io_uring: move SQPOLL thread io-wq forked worker") Cc: [email protected] # 6.1+ Signed-off-by: Felix Moessbauer <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 0e0bcf0 commit f011c9c

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

io_uring/sqpoll.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/slab.h>
1111
#include <linux/audit.h>
1212
#include <linux/security.h>
13+
#include <linux/cpuset.h>
1314
#include <linux/io_uring.h>
1415

1516
#include <uapi/linux/io_uring.h>
@@ -460,10 +461,12 @@ __cold int io_sq_offload_create(struct io_ring_ctx *ctx,
460461
return 0;
461462

462463
if (p->flags & IORING_SETUP_SQ_AFF) {
464+
struct cpumask allowed_mask;
463465
int cpu = p->sq_thread_cpu;
464466

465467
ret = -EINVAL;
466-
if (cpu >= nr_cpu_ids || !cpu_online(cpu))
468+
cpuset_cpus_allowed(current, &allowed_mask);
469+
if (!cpumask_test_cpu(cpu, &allowed_mask))
467470
goto err_sqpoll;
468471
sqd->sq_cpu = cpu;
469472
} else {

0 commit comments

Comments
 (0)