public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH 5.10 5.15 1/3] io_uring/sqpoll: do not allow pinning outside of cpuset
@ 2024-10-17 11:50 Felix Moessbauer
  2024-10-17 11:50 ` [PATCH 5.10 5.15 2/3] io_uring/sqpoll: retain test for whether the CPU is valid Felix Moessbauer
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Felix Moessbauer @ 2024-10-17 11:50 UTC (permalink / raw)
  To: stable; +Cc: io-uring, axboe, gregkh, Felix Moessbauer

commit f011c9cf04c06f16b24f583d313d3c012e589e50 upstream.

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: 37d1e2e3642e ("io_uring: move SQPOLL thread io-wq forked worker")
Signed-off-by: Felix Moessbauer <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jens Axboe <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
 io_uring/io_uring.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index 8ed2c65529714..6b6fd244233f8 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -56,6 +56,7 @@
 #include <linux/mm.h>
 #include <linux/mman.h>
 #include <linux/percpu.h>
+#include <linux/cpuset.h>
 #include <linux/slab.h>
 #include <linux/blkdev.h>
 #include <linux/bvec.h>
@@ -8746,10 +8747,12 @@ static int io_sq_offload_create(struct io_ring_ctx *ctx,
 			return 0;
 
 		if (p->flags & IORING_SETUP_SQ_AFF) {
+			struct cpumask allowed_mask;
 			int cpu = p->sq_thread_cpu;
 
 			ret = -EINVAL;
-			if (cpu >= nr_cpu_ids || !cpu_online(cpu))
+			cpuset_cpus_allowed(current, &allowed_mask);
+			if (!cpumask_test_cpu(cpu, &allowed_mask))
 				goto err_sqpoll;
 			sqd->sq_cpu = cpu;
 		} else {
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-10-18 10:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-17 11:50 [PATCH 5.10 5.15 1/3] io_uring/sqpoll: do not allow pinning outside of cpuset Felix Moessbauer
2024-10-17 11:50 ` [PATCH 5.10 5.15 2/3] io_uring/sqpoll: retain test for whether the CPU is valid Felix Moessbauer
2024-10-17 11:50 ` [PATCH 5.10 5.15 3/3] io_uring/sqpoll: do not put cpumask on stack Felix Moessbauer
2024-10-18 10:36 ` [PATCH 5.10 5.15 1/3] io_uring/sqpoll: do not allow pinning outside of cpuset Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox