Skip to content

Commit 605d055

Browse files
isilencegregkh
authored andcommitted
io_uring: break out of iowq iopoll on teardown
[ upstream commit 45500dc ] 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]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent b04f22b commit 605d055

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

io_uring/io-wq.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,16 @@ static void io_worker_ref_put(struct io_wq *wq)
181181
complete(&wq->worker_done);
182182
}
183183

184+
bool io_wq_worker_stopped(void)
185+
{
186+
struct io_worker *worker = current->worker_private;
187+
188+
if (WARN_ON_ONCE(!io_wq_current_is_worker()))
189+
return true;
190+
191+
return test_bit(IO_WQ_BIT_EXIT, &worker->wqe->wq->state);
192+
}
193+
184194
static void io_worker_cancel_cb(struct io_worker *worker)
185195
{
186196
struct io_wqe_acct *acct = io_wqe_get_acct(worker);

io_uring/io-wq.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ void io_wq_hash_work(struct io_wq_work *work, void *val);
5252

5353
int io_wq_cpu_affinity(struct io_wq *wq, cpumask_var_t mask);
5454
int io_wq_max_workers(struct io_wq *wq, int *new_count);
55+
bool io_wq_worker_stopped(void);
5556

5657
static inline bool io_wq_is_hashed(struct io_wq_work *work)
5758
{

io_uring/io_uring.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,6 +1823,8 @@ void io_wq_submit_work(struct io_wq_work *work)
18231823
if (!needs_poll) {
18241824
if (!(req->ctx->flags & IORING_SETUP_IOPOLL))
18251825
break;
1826+
if (io_wq_worker_stopped())
1827+
break;
18261828
cond_resched();
18271829
continue;
18281830
}

0 commit comments

Comments
 (0)