Merge tag 'io_uring-5.8-2020-07-01' of git://git.kernel.dk/linux-block
Pull io_uring fixes from Jens Axboe: "One fix in here, for a regression in 5.7 where a task is waiting in the kernel for a condition, but that condition won't become true until task_work is run. And the task_work can't be run exactly because the task is waiting in the kernel, so we'll never make any progress. One example of that is registering an eventfd and queueing io_uring work, and then the task goes and waits in eventfd read with the expectation that it'll get woken (and read an event) when the io_uring request completes. The io_uring request is finished through task_work, which won't get run while the task is looping in eventfd read" * tag 'io_uring-5.8-2020-07-01' of git://git.kernel.dk/linux-block: io_uring: use signal based task_work running task_work: teach task_work_add() to do signal_wake_up()
This commit is contained in:
@@ -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 (signal_pending(current)) {
|
||||
ret = -ERESTARTSYS;
|
||||
break;
|
||||
}
|
||||
if (io_should_wake(&iowq, false))
|
||||
break;
|
||||
schedule();
|
||||
if (signal_pending(current)) {
|
||||
ret = -EINTR;
|
||||
break;
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user