Skip to content

Commit c7849be

Browse files
Xiaoguang Wangaxboe
authored andcommitted
io_uring: fix __io_iopoll_check deadlock in io_sq_thread
Since commit a3a0e43 ("io_uring: don't enter poll loop if we have CQEs pending"), if we already events pending, we won't enter poll loop. In case SETUP_IOPOLL and SETUP_SQPOLL are both enabled, if app has been terminated and don't reap pending events which are already in cq ring, and there are some reqs in poll_list, io_sq_thread will enter __io_iopoll_check(), and find pending events, then return, this loop will never have a chance to exit. I have seen this issue in fio stress tests, to fix this issue, let io_sq_thread call io_iopoll_getevents() with argument 'min' being zero, and remove __io_iopoll_check(). Fixes: a3a0e43 ("io_uring: don't enter poll loop if we have CQEs pending") Signed-off-by: Xiaoguang Wang <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 7143b5a commit c7849be

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

fs/io_uring.c

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,11 +1672,17 @@ static void io_iopoll_reap_events(struct io_ring_ctx *ctx)
16721672
mutex_unlock(&ctx->uring_lock);
16731673
}
16741674

1675-
static int __io_iopoll_check(struct io_ring_ctx *ctx, unsigned *nr_events,
1676-
long min)
1675+
static int io_iopoll_check(struct io_ring_ctx *ctx, unsigned *nr_events,
1676+
long min)
16771677
{
16781678
int iters = 0, ret = 0;
16791679

1680+
/*
1681+
* We disallow the app entering submit/complete with polling, but we
1682+
* still need to lock the ring to prevent racing with polled issue
1683+
* that got punted to a workqueue.
1684+
*/
1685+
mutex_lock(&ctx->uring_lock);
16801686
do {
16811687
int tmin = 0;
16821688

@@ -1712,21 +1718,6 @@ static int __io_iopoll_check(struct io_ring_ctx *ctx, unsigned *nr_events,
17121718
ret = 0;
17131719
} while (min && !*nr_events && !need_resched());
17141720

1715-
return ret;
1716-
}
1717-
1718-
static int io_iopoll_check(struct io_ring_ctx *ctx, unsigned *nr_events,
1719-
long min)
1720-
{
1721-
int ret;
1722-
1723-
/*
1724-
* We disallow the app entering submit/complete with polling, but we
1725-
* still need to lock the ring to prevent racing with polled issue
1726-
* that got punted to a workqueue.
1727-
*/
1728-
mutex_lock(&ctx->uring_lock);
1729-
ret = __io_iopoll_check(ctx, nr_events, min);
17301721
mutex_unlock(&ctx->uring_lock);
17311722
return ret;
17321723
}
@@ -5118,7 +5109,7 @@ static int io_sq_thread(void *data)
51185109
*/
51195110
mutex_lock(&ctx->uring_lock);
51205111
if (!list_empty(&ctx->poll_list))
5121-
__io_iopoll_check(ctx, &nr_events, 0);
5112+
io_iopoll_getevents(ctx, &nr_events, 0);
51225113
else
51235114
inflight = 0;
51245115
mutex_unlock(&ctx->uring_lock);

0 commit comments

Comments
 (0)