Skip to content

Commit 9fbe565

Browse files
committed
Merge tag 'io_uring-5.8-2020-07-05' of git://git.kernel.dk/linux-block
Pull io_uring fix from Jens Axboe: "Andres reported a regression with the fix that was merged earlier this week, where his setup of using signals to interrupt io_uring CQ waits no longer worked correctly. Fix this, and also limit our use of TWA_SIGNAL to the case where we need it, and continue using TWA_RESUME for task_work as before. Since the original is marked for 5.7 stable, let's flush this one out early" * tag 'io_uring-5.8-2020-07-05' of git://git.kernel.dk/linux-block: io_uring: fix regression with always ignoring signals in io_cqring_wait()
2 parents 7783485 + b7db41c commit 9fbe565

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

fs/io_uring.c

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4072,14 +4072,22 @@ struct io_poll_table {
40724072
int error;
40734073
};
40744074

4075-
static int io_req_task_work_add(struct io_kiocb *req, struct callback_head *cb,
4076-
int notify)
4075+
static int io_req_task_work_add(struct io_kiocb *req, struct callback_head *cb)
40774076
{
40784077
struct task_struct *tsk = req->task;
4079-
int ret;
4078+
struct io_ring_ctx *ctx = req->ctx;
4079+
int ret, notify = TWA_RESUME;
40804080

4081-
if (req->ctx->flags & IORING_SETUP_SQPOLL)
4081+
/*
4082+
* SQPOLL kernel thread doesn't need notification, just a wakeup.
4083+
* If we're not using an eventfd, then TWA_RESUME is always fine,
4084+
* as we won't have dependencies between request completions for
4085+
* other kernel wait conditions.
4086+
*/
4087+
if (ctx->flags & IORING_SETUP_SQPOLL)
40824088
notify = 0;
4089+
else if (ctx->cq_ev_fd)
4090+
notify = TWA_SIGNAL;
40834091

40844092
ret = task_work_add(tsk, cb, notify);
40854093
if (!ret)
@@ -4110,7 +4118,7 @@ static int __io_async_wake(struct io_kiocb *req, struct io_poll_iocb *poll,
41104118
* of executing it. We can't safely execute it anyway, as we may not
41114119
* have the needed state needed for it anyway.
41124120
*/
4113-
ret = io_req_task_work_add(req, &req->task_work, TWA_SIGNAL);
4121+
ret = io_req_task_work_add(req, &req->task_work);
41144122
if (unlikely(ret)) {
41154123
WRITE_ONCE(poll->canceled, true);
41164124
tsk = io_wq_get_task(req->ctx->io_wq);
@@ -6201,7 +6209,14 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events,
62016209
if (current->task_works)
62026210
task_work_run();
62036211
if (signal_pending(current)) {
6204-
ret = -ERESTARTSYS;
6212+
if (current->jobctl & JOBCTL_TASK_WORK) {
6213+
spin_lock_irq(&current->sighand->siglock);
6214+
current->jobctl &= ~JOBCTL_TASK_WORK;
6215+
recalc_sigpending();
6216+
spin_unlock_irq(&current->sighand->siglock);
6217+
continue;
6218+
}
6219+
ret = -EINTR;
62056220
break;
62066221
}
62076222
if (io_should_wake(&iowq, false))
@@ -6210,7 +6225,7 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events,
62106225
} while (1);
62116226
finish_wait(&ctx->wait, &iowq.wq);
62126227

6213-
restore_saved_sigmask_unless(ret == -ERESTARTSYS);
6228+
restore_saved_sigmask_unless(ret == -EINTR);
62146229

62156230
return READ_ONCE(rings->cq.head) == READ_ONCE(rings->cq.tail) ? ret : 0;
62166231
}

0 commit comments

Comments
 (0)