FAILED: patch "[PATCH] io_uring: use signal based task_work running" failed to apply to 5.7-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 5.7-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]>.
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From ce593a6c480a22acba08795be313c0c6d49dd35d Mon Sep 17 00:00:00 2001
From: Jens Axboe <[email protected]>
Date: Tue, 30 Jun 2020 12:39:05 -0600
Subject: [PATCH] io_uring: use signal based task_work running
Since 5.7, we've been using task_work to trigger async running of requests in the context of the original task. This generally works great, but there's a case where if the task is currently blocked in the kernel waiting on a condition to become true, it won't process task_work. Even though the task is woken, it just checks whatever condition it's waiting on, and goes back to sleep if it's still false.
This is a problem if that very condition only becomes true when that task_work is run. An example of that is the task registering an eventfd with io_uring, and it's now blocked waiting on an eventfd read. That read could depend on a completion event, and that completion event won't get trigged until task_work has been run.
Use the TWA_SIGNAL notification for task_work, so that we ensure that the task always runs the work when queued.
fs/io_uring.c +24 -8
@@ -4072,6 +4072,21 @@ struct io_poll_table {int error; }; +static int io_req_task_work_add (struct io_kiocb *req,struct callback_head *cb, +int notify) +{ +struct task_struct *tsk = req->task; +int ret; + +if (req->ctx->flags &IORING_SETUP_SQPOLL ) + notify =0 ; + + ret =task_work_add (tsk, cb, notify); +if (!ret) +wake_up_process (tsk); +return ret; +} +static int __io_async_wake (struct io_kiocb *req,struct io_poll_iocb *poll,__poll_t mask,task_work_func_t func) {
@@ -4095,13 +4110,13 @@ static int __io_async_wake(struct io_kiocb *req, struct io_poll_iocb *poll,* of executing it. We can't safely execute it anyway, as we may not * have the needed state needed for it anyway. */ - ret =task_work_add (tsk, &req->task_work, true); + ret =io_req_task_work_add (req, &req->task_work,TWA_SIGNAL );if (unlikely (ret)) {WRITE_ONCE (poll->canceled, true); tsk =io_wq_get_task (req->ctx->io_wq); -task_work_add (tsk, &req->task_work, true); +task_work_add (tsk, &req->task_work,0 ); +wake_up_process (tsk); } -wake_up_process (tsk);return 1 ; }
@@ -6182,19 +6197,20 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events,do {prepare_to_wait_exclusive (&ctx->wait, &iowq.wq,TASK_INTERRUPTIBLE ); +/* make sure we run task_work before checking for signals */ if (current->task_works)task_work_run (); -if (io_should_wake (&iowq, false)) -break ; -schedule ();if (signal_pending (current)) { - ret = -EINTR ; + ret = -ERESTARTSYS ;break ; } +if (io_should_wake (&iowq, false)) +break ; +schedule (); }while (1 );finish_wait (&ctx->wait, &iowq.wq); -restore_saved_sigmask_unless (ret == -EINTR ); +restore_saved_sigmask_unless (ret == -ERESTARTSYS );return READ_ONCE (rings->cq.head) ==READ_ONCE (rings->cq.tail) ? ret :0 ; }
Sasha Levin
maintainerQuoted 30 lines · On Sun, Jul 05, 2020 at 01:26:56PM +0200, [email protected] wrote:
The patch below does not apply to the 5.7-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]>.thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From
ce593a6c480a22acba08795be313c0c6d49dd35dMon Sep 17 00:00:00 2001
From: Jens Axboe <[email protected]>
Date: Tue, 30 Jun 2020 12:39:05 -0600
Subject: [PATCH]io_uring: use signal basedtask_workrunningSince 5.7, we've been using
task_workto trigger async running of requests in the context of the original task. This generally works great, but there's a case where if the task is currently blocked in the kernel waiting on a condition to become true, it won't processtask_work. Even though the task is woken, it just checks whatever condition it's waiting on, and goes back to sleep if it's still false.This is a problem if that very condition only becomes true when that
task_workis run. An example of that is the task registering an eventfd withio_uring, and it's now blocked waiting on an eventfd read. That read could depend on a completion event, and that completion event won't get trigged untiltask_workhas been run.
Quoted 5 lines
Use the
TWA_SIGNALnotification fortask_work, so that we ensure that the task always runs the work when queued.Cc [email protected] # v5.7Signed-off-by Jens Axboe <[email protected]>
This patch depends on e91b48162332 ("task_work: teach task_work_add() to do signal_wake_up()"), I've queued both for 5.7.
Signature · 2 lines
Thanks, Sasha
Greg KH
maintainerQuoted 31 lines · Sasha Levin
Quoted 30 lines · On Sun, Jul 05, 2020 at 01:26:56PM +0200, [email protected] wrote:
The patch below does not apply to the 5.7-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]>.thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
Quoted 1 line
From
ce593a6c480a22acba08795be313c0c6d49dd35dMon Sep 17 00:00:00 2001From: Jens Axboe <[email protected]>
Date: Tue, 30 Jun 2020 12:39:05 -0600
Subject: [PATCH]io_uring: use signal basedtask_workrunningSince 5.7, we've been using
task_workto trigger async running of requests in the context of the original task. This generally works great, but there's a case where if the task is currently blocked in the kernel waiting on a condition to become true, it won't processtask_work. Even though the task is woken, it just checks whatever condition it's waiting on, and goes back to sleep if it's still false.This is a problem if that very condition only becomes true when that
task_workis run. An example of that is the task registering an eventfd withio_uring, and it's now blocked waiting on an eventfd read. That read could depend on a completion event, and that completion event won't get trigged untiltask_workhas been run.
Quoted 8 lines
Quoted 5 lines
Use the
TWA_SIGNALnotification fortask_work, so that we ensure that the task always runs the work when queued.Cc [email protected] # v5.7Signed-off-by Jens Axboe <[email protected]>This patch depends on
e91b48162332("task_work: teachtask_work_add()to dosignal_wake_up()"), I've queued both for 5.7.
Great, thanks for adding that.
greg k-h