Skip to content

Commit

Permalink
io_uring: break out of iowq iopoll on teardown
Browse files Browse the repository at this point in the history
io-wq will retry iopoll even when it failed with -EAGAIN. If that
races with task exit, which sets TIF_NOTIFY_SIGNAL for all its workers,
such workers might potentially infinitely spin retrying iopoll again and
again and each time failing on some allocation / waiting / etc. Don't
keep spinning if io-wq is dying.

Fixes: 561fb04 ("io_uring: replace workqueue usage with io-wq")
Cc: [email protected]
Signed-off-by: Pavel Begunkov <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
isilence authored and axboe committed Sep 7, 2023
1 parent 76d3cce commit 45500dc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions io_uring/io-wq.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,16 @@ static void io_worker_ref_put(struct io_wq *wq)
complete(&wq->worker_done);
}

bool io_wq_worker_stopped(void)
{
struct io_worker *worker = current->worker_private;

if (WARN_ON_ONCE(!io_wq_current_is_worker()))
return true;

return test_bit(IO_WQ_BIT_EXIT, &worker->wq->state);
}

static void io_worker_cancel_cb(struct io_worker *worker)
{
struct io_wq_acct *acct = io_wq_get_acct(worker);
Expand Down
1 change: 1 addition & 0 deletions io_uring/io-wq.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ void io_wq_hash_work(struct io_wq_work *work, void *val);

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);
bool io_wq_worker_stopped(void);

static inline bool io_wq_is_hashed(struct io_wq_work *work)
{
Expand Down
2 changes: 2 additions & 0 deletions io_uring/io_uring.c
Original file line number Diff line number Diff line change
Expand Up @@ -1975,6 +1975,8 @@ void io_wq_submit_work(struct io_wq_work *work)
if (!needs_poll) {
if (!(req->ctx->flags & IORING_SETUP_IOPOLL))
break;
if (io_wq_worker_stopped())
break;
cond_resched();
continue;
}
Expand Down

0 comments on commit 45500dc

Please sign in to comment.