FAILED: patch "[PATCH] io_uring: include dying ring in task_work "should cancel"" failed to apply to 6.6-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 6.6-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.6.y
git checkout FETCH_HEAD
git cherry-pick -x 3539b1467e94336d5854ebf976d9627bfb65d6c3
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2025092127-emit-dean-5272@gregkh' --subject-prefix 'PATCH 6.6.y' HEAD^..
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 3539b1467e94336d5854ebf976d9627bfb65d6c3 Mon Sep 17 00:00:00 2001
From: Jens Axboe <[email protected]>
Date: Thu, 18 Sep 2025 10:21:14 -0600
Subject: [PATCH] io_uring: include dying ring in task_work "should cancel"
state
When running task_work for an exiting task, rather than perform the issue retry attempt, the task_work is canceled. However, this isn't done for a ring that has been closed. This can lead to requests being successfully completed post the ring being closed, which is somewhat confusing and surprising to an application.
Rather than just check the task exit state, also include the ring ref state in deciding whether or not to terminate a given request when run from task_work.
io_uring/io_uring.c +4 -2
@@ -1406,8 +1406,10 @@ static void io_req_task_cancel(struct io_kiocb *req, io_tw_token_t tw)void io_req_task_submit (struct io_kiocb *req,io_tw_token_t tw) { -io_tw_lock (req->ctx, tw); -if (unlikely (io_should_terminate_tw ())) +struct io_ring_ctx *ctx = req->ctx; + +io_tw_lock (ctx, tw); +if (unlikely (io_should_terminate_tw (ctx)))io_req_defer_failed (req, -EFAULT );else if (req->flags &REQ_F_FORCE_ASYNC )io_queue_iowq (req);
io_uring/io_uring.h +2 -2
@@ -476,9 +476,9 @@ static inline bool io_allowed_run_tw(struct io_ring_ctx *ctx)* 2) PF_KTHREAD is set, in which case the invoker of the task_work is * our fallback task_work. */ -static inline bool io_should_terminate_tw (void ) +static inline bool io_should_terminate_tw (struct io_ring_ctx *ctx) { -return current->flags & (PF_KTHREAD |PF_EXITING ); +return (current->flags & (PF_KTHREAD |PF_EXITING )) ||percpu_ref_is_dying (&ctx->refs); }static inline void io_req_queue_tw_complete (struct io_kiocb *req,s32 res)
io_uring/poll.c +1 -1
@@ -224,7 +224,7 @@ static int io_poll_check_events(struct io_kiocb *req, io_tw_token_t tw) {int v; -if (unlikely (io_should_terminate_tw ())) +if (unlikely (io_should_terminate_tw (req->ctx)))return -ECANCELED ; do {
io_uring/timeout.c +1 -1
@@ -324,7 +324,7 @@ static void io_req_task_link_timeout(struct io_kiocb *req, io_tw_token_t tw)int ret;if (prev) { -if (!io_should_terminate_tw ()) { +if (!io_should_terminate_tw (req->ctx)) {struct io_cancel_data cd = { .ctx = req->ctx, .data = prev->cqe.user_data,
io_uring/uring_cmd.c +1 -1
@@ -118,7 +118,7 @@ static void io_uring_cmd_work(struct io_kiocb *req, io_tw_token_t tw) struct io_uring_cmd *ioucmd = io_kiocb_to_cmd(req, struct io_uring_cmd);unsigned int flags =IO_URING_F_COMPLETE_DEFER ; -if (io_should_terminate_tw ()) +if (io_should_terminate_tw (req->ctx)) flags |=IO_URING_F_TASK_DEAD ;/* task_work executor checks the deffered list completion */
Jens Axboe
maintainerQuoted 6 lines · On 9/21/25 6:32 AM, [email protected] wrote:
The patch below does not apply to the 6.6-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]>.
Quoted 8 lines
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.6.y
git checkoutFETCH_HEAD
git cherry-pick -x3539b1467e94336d5854ebf976d9627bfb65d6c3
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2025092127-emit-dean-5272@gregkh' --subject-prefix 'PATCH 6.6.y' HEAD^..
Ditto on the 6.6-stable side.
Signature · 1 line
Jens Axboe
From 04a06705eb404dfc986171993c82d28a44c81402 Mon Sep 17 00:00:00 2001
From: Jens Axboe <[email protected]>
Date: Thu, 18 Sep 2025 10:21:14 -0600
Subject: [PATCH 2/2] io_uring: include dying ring in task_work "should cancel"
state
Commit 3539b1467e94336d5854ebf976d9627bfb65d6c3 upstream.
When running task_work for an exiting task, rather than perform the issue retry attempt, the task_work is canceled. However, this isn't done for a ring that has been closed. This can lead to requests being successfully completed post the ring being closed, which is somewhat confusing and surprising to an application.
Rather than just check the task exit state, also include the ring ref state in deciding whether or not to terminate a given request when run from task_work.
--- io_uring/io_uring.c | 6 ++++-- io_uring/io_uring.h | 4 ++-- io_uring/poll.c | 2 +- io_uring/timeout.c | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-)
io_uring/io_uring.c +4 -2
@@ -1459,8 +1459,10 @@ static void io_req_task_cancel(struct io_kiocb *req, struct io_tw_state *ts)void io_req_task_submit (struct io_kiocb *req,struct io_tw_state *ts) { -io_tw_lock (req->ctx, ts); -if (unlikely (io_should_terminate_tw ())) +struct io_ring_ctx *ctx = req->ctx; + +io_tw_lock (ctx, ts); +if (unlikely (io_should_terminate_tw (ctx)))io_req_defer_failed (req, -EFAULT );else if (req->flags &REQ_F_FORCE_ASYNC )io_queue_iowq (req);
io_uring/io_uring.h +2 -2
@@ -402,9 +402,9 @@ static inline bool io_allowed_run_tw(struct io_ring_ctx *ctx)* 2) PF_KTHREAD is set, in which case the invoker of the task_work is * our fallback task_work. */ -static inline bool io_should_terminate_tw (void ) +static inline bool io_should_terminate_tw (struct io_ring_ctx *ctx) { -return current->flags & (PF_KTHREAD |PF_EXITING ); +return (current->flags & (PF_KTHREAD |PF_EXITING )) ||percpu_ref_is_dying (&ctx->refs); }static inline void io_req_queue_tw_complete (struct io_kiocb *req,s32 res)
io_uring/poll.c +1 -1
@@ -258,7 +258,7 @@ static int io_poll_check_events(struct io_kiocb *req, struct io_tw_state *ts) {int v; -if (unlikely (io_should_terminate_tw ())) +if (unlikely (io_should_terminate_tw (req->ctx)))return -ECANCELED ; do {
io_uring/timeout.c +1 -1
@@ -307,7 +307,7 @@ static void io_req_task_link_timeout(struct io_kiocb *req, struct io_tw_state *tint ret = -ENOENT ;if (prev) { -if (!io_should_terminate_tw ()) { +if (!io_should_terminate_tw (req->ctx)) {struct io_cancel_data cd = { .ctx = req->ctx, .data = prev->cqe.user_data,
Signature · 1 line
2.51.0
From a4f4390cd3ce0a339754655f8210cfe33465e3c8 Mon Sep 17 00:00:00 2001
From: Jens Axboe <[email protected]>
Date: Thu, 18 Sep 2025 11:27:06 -0600
Subject: [PATCH 1/2] io_uring: backport io_should_terminate_tw()
Parts of commit b6f58a3f4aa8dba424356c7a69388a81f4459300 upstream.
Backport io_should_terminate_tw() helper to judge whether task_work should be run or terminated.
--- io_uring/io_uring.c | 3 +-- io_uring/io_uring.h | 13 +++++++++++++ io_uring/poll.c | 3 +-- io_uring/timeout.c | 2 +- 4 files changed, 16 insertions(+), 5 deletions(-)
io_uring/io_uring.c +1 -2
@@ -1460,8 +1460,7 @@ static void io_req_task_cancel(struct io_kiocb *req, struct io_tw_state *ts)void io_req_task_submit (struct io_kiocb *req,struct io_tw_state *ts) {io_tw_lock (req->ctx, ts); -/* req->task == current here, checking PF_EXITING is safe */ -if (unlikely (req->task->flags &PF_EXITING )) +if (unlikely (io_should_terminate_tw ()))io_req_defer_failed (req, -EFAULT );else if (req->flags &REQ_F_FORCE_ASYNC )io_queue_iowq (req);
io_uring/io_uring.h +13 -0
@@ -394,6 +394,19 @@ static inline bool io_allowed_run_tw(struct io_ring_ctx *ctx) ctx->submitter_task == current); } +/* +* Terminate the request if either of these conditions are true: +* +* 1) It's being executed by the original task, but that task is marked +* with PF_EXITING as it's exiting. +* 2) PF_KTHREAD is set, in which case the invoker of the task_work is +* our fallback task_work. +*/ +static inline bool io_should_terminate_tw (void ) +{ +return current->flags & (PF_KTHREAD |PF_EXITING ); +} +static inline void io_req_queue_tw_complete (struct io_kiocb *req,s32 res) {io_req_set_res (req, res,0 );
io_uring/poll.c +1 -2
@@ -258,8 +258,7 @@ static int io_poll_check_events(struct io_kiocb *req, struct io_tw_state *ts) {int v; -/* req->task == current here, checking PF_EXITING is safe */ -if (unlikely (req->task->flags &PF_EXITING )) +if (unlikely (io_should_terminate_tw ()))return -ECANCELED ; do {
io_uring/timeout.c +1 -1
@@ -307,7 +307,7 @@ static void io_req_task_link_timeout(struct io_kiocb *req, struct io_tw_state *tint ret = -ENOENT ;if (prev) { -if (!(req->task->flags &PF_EXITING )) { +if (!io_should_terminate_tw ()) {struct io_cancel_data cd = { .ctx = req->ctx, .data = prev->cqe.user_data,
Signature · 1 line
2.51.0
Greg KH
maintainerQuoted 9 lines · Jens Axboe
Quoted 8 lines · On 9/21/25 6:32 AM, [email protected] wrote:
The patch below does not apply to the 6.6-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:
Quoted 8 lines
Quoted 6 lines
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.6.y
git checkoutFETCH_HEAD
git cherry-pick -x3539b1467e94336d5854ebf976d9627bfb65d6c3
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2025092127-emit-dean-5272@gregkh' --subject-prefix 'PATCH 6.6.y' HEAD^..Ditto on the 6.6-stable side.
Now applied, thanks.
greg k-h