FAILED: patch "[PATCH] io_uring/sqpoll: fix io-wq affinity when IORING_SETUP_SQPOLL" failed to apply to 6.1-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 6.1-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.1.y
git checkout FETCH_HEAD
git cherry-pick -x ebdfefc09c6de7897962769bd3e63a2ff443ebf5
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2023090956-immersion-calorie-81e9@gregkh' --subject-prefix 'PATCH 6.1.y' HEAD^..
Possible dependencies:
ebdfefc09c6d ("io_uring/sqpoll: fix io-wq affinity when IORING_SETUP_SQPOLL is used") eb47943f2238 ("io-wq: Drop struct io_wqe")dfd63baf892c ("io-wq: Move wq accounting to io_wq")da64d6db3bd3 ("io_uring: One wqe per wq")01e68ce08a30 ("io_uring/io-wq: stop setting PF_NO_SETAFFINITY on io-wq workers") 88b80534f60f ("io_uring: make io_sqpoll_wait_sq return void")
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From ebdfefc09c6de7897962769bd3e63a2ff443ebf5 Mon Sep 17 00:00:00 2001
From: Jens Axboe <[email protected]>
Date: Sun, 13 Aug 2023 11:05:36 -0600
Subject: [PATCH] io_uring/sqpoll: fix io-wq affinity when IORING_SETUP_SQPOLL
is used
If we setup the ring with SQPOLL, then that polling thread has its own io-wq setup. This means that if the application uses IORING_REGISTER_IOWQ_AFF to set the io-wq affinity, we should not be setting it for the invoking task, but rather the sqpoll task.
Add an sqpoll helper that parks the thread and updates the affinity, and use that one if we're using SQPOLL.
io_uring/io-wq.c +6 -3
@@ -1306,13 +1306,16 @@ static int io_wq_cpu_offline(unsigned int cpu, struct hlist_node *node)return __io_wq_cpu_online (wq, cpu, false); } -int io_wq_cpu_affinity (struct io_wq *wq,cpumask_var_t mask) +int io_wq_cpu_affinity (struct io_uring_task *tctx,cpumask_var_t mask) { +if (!tctx || !tctx->io_wq) +return -EINVAL ; +rcu_read_lock ();if (mask) -cpumask_copy (wq->cpu_mask, mask); +cpumask_copy (tctx->io_wq->cpu_mask, mask);else -cpumask_copy (wq->cpu_mask, cpu_possible_mask); +cpumask_copy (tctx->io_wq->cpu_mask, cpu_possible_mask);rcu_read_unlock ();return 0 ;
io_uring/io-wq.h +1 -1
@@ -50,7 +50,7 @@ void io_wq_put_and_exit(struct io_wq *wq);void io_wq_enqueue (struct io_wq *wq,struct io_wq_work *work);void io_wq_hash_work (struct io_wq_work *work,void *val); -int io_wq_cpu_affinity (struct io_wq *wq,cpumask_var_t mask); +int io_wq_cpu_affinity (struct io_uring_task *tctx,cpumask_var_t mask);int io_wq_max_workers (struct io_wq *wq,int *new_count);static inline bool io_wq_is_hashed (struct io_wq_work *work)
io_uring/io_uring.c +18 -11
@@ -4183,16 +4183,28 @@ static int io_register_enable_rings(struct io_ring_ctx *ctx)return 0 ; } +static __cold int __io_register_iowq_aff (struct io_ring_ctx *ctx, +cpumask_var_t new_mask) +{ +int ret; + +if (!(ctx->flags &IORING_SETUP_SQPOLL )) { + ret =io_wq_cpu_affinity (current->io_uring, new_mask); + }else { +mutex_unlock (&ctx->uring_lock); + ret =io_sqpoll_wq_cpu_affinity (ctx, new_mask); +mutex_lock (&ctx->uring_lock); + } + +return ret; +} +static __cold int io_register_iowq_aff (struct io_ring_ctx *ctx,void __user *arg,unsigned len) { -struct io_uring_task *tctx = current->io_uring;cpumask_var_t new_mask;int ret; -if (!tctx || !tctx->io_wq) -return -EINVAL ; -if (!alloc_cpumask_var (&new_mask,GFP_KERNEL ))return -ENOMEM ;
@@ -4213,19 +4225,14 @@ static __cold int io_register_iowq_aff(struct io_ring_ctx *ctx,return -EFAULT ; } - ret =io_wq_cpu_affinity (tctx->io_wq, new_mask); + ret =__io_register_iowq_aff (ctx, new_mask);free_cpumask_var (new_mask);return ret; }static __cold int io_unregister_iowq_aff (struct io_ring_ctx *ctx) { -struct io_uring_task *tctx = current->io_uring; - -if (!tctx || !tctx->io_wq) -return -EINVAL ; - -return io_wq_cpu_affinity (tctx->io_wq,NULL ); +return __io_register_iowq_aff (ctx,NULL ); } static __cold int io_register_iowq_max_workers(struct io_ring_ctx *ctx,
io_uring/sqpoll.c +15 -0
@@ -421,3 +421,18 @@ __cold int io_sq_offload_create(struct io_ring_ctx *ctx,io_sq_thread_finish (ctx);return ret; } + +__cold int io_sqpoll_wq_cpu_affinity (struct io_ring_ctx *ctx, +cpumask_var_t mask) +{ +struct io_sq_data *sqd = ctx->sq_data; +int ret = -EINVAL ; + +if (sqd) { +io_sq_thread_park (sqd); + ret =io_wq_cpu_affinity (sqd->thread->io_uring, mask); +io_sq_thread_unpark (sqd); + } + +return ret; +}
io_uring/sqpoll.h +1 -0
@@ -27,3 +27,4 @@ void io_sq_thread_park(struct io_sq_data *sqd);void io_sq_thread_unpark (struct io_sq_data *sqd);void io_put_sq_data (struct io_sq_data *sqd);void io_sqpoll_wait_sq (struct io_ring_ctx *ctx); +int io_sqpoll_wq_cpu_affinity (struct io_ring_ctx *ctx,cpumask_var_t mask);