io_uring: fix IO hang in io wq exit
Subsystems (2)
cover io_uring: fix IO hang in io wq exit
Hello,
The 1st patch add one helper, and the 2nd one fixes IO hang issue[1] reported by David Howells.
[1] https://lore.kernel.org/linux-block/[email protected]/
Ming Lei (2):
io_uring: add one helper for reaping iopoll events
io_uring: reap iopoll events before exiting io wq
io_uring/io_uring.c | 27 +++++++++++++------- io_uring/io_uring.h | 1 + io_uring/tctx.c | 60 +++++++++++++++++++++++++++++++++++++++------ 3 files changed, 71 insertions(+), 17 deletions(-)
Signature · 1 line
2.40.1
PATCH 1/2 io_uring: add one helper for reaping iopoll events
Prepare for reaping iopoll events before exiting io_wq, which may depend on iopoll.
--- io_uring/io_uring.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-)
io_uring/io_uring.c +18 -9
@@ -3214,6 +3214,23 @@ static __cold bool io_uring_try_cancel_iowq(struct io_ring_ctx *ctx)return ret; } +static bool iopoll_reap_events (struct io_ring_ctx *ctx,bool reap_all) +{ +bool reapped = false; + +/* SQPOLL thread does its own polling */ +if ((!(ctx->flags &IORING_SETUP_SQPOLL ) && reap_all) || + (ctx->sq_data && ctx->sq_data->thread == current)) { +while (!wq_list_empty (&ctx->iopoll_list)) { +io_iopoll_try_reap_events (ctx); + reapped = true; +cond_resched (); + } + } + +return reapped; +} +static __cold bool io_uring_try_cancel_requests (struct io_ring_ctx *ctx,struct task_struct *task,bool cancel_all)
@@ -3245,15 +3262,7 @@ static __cold bool io_uring_try_cancel_requests(struct io_ring_ctx *ctx, ret |= (cret !=IO_WQ_CANCEL_NOTFOUND ); } -/* SQPOLL thread does its own polling */ -if ((!(ctx->flags &IORING_SETUP_SQPOLL ) && cancel_all) || - (ctx->sq_data && ctx->sq_data->thread == current)) { -while (!wq_list_empty (&ctx->iopoll_list)) { -io_iopoll_try_reap_events (ctx); - ret = true; -cond_resched (); - } - } + ret =iopoll_reap_events (ctx, cancel_all);if ((ctx->flags &IORING_SETUP_DEFER_TASKRUN ) &&io_allowed_defer_tw_run (ctx))
Signature · 1 line
2.40.1
PATCH 2/2 io_uring: reap iopoll events before exiting io wq
In reply to Ming Leiio_uring delays reaping iopoll events into exit work, which is scheduled in io_uring_release(). But io wq is exited inside do_exit(), and wq code path may share resource with iopoll code path, such as request. If iopoll events aren't reaped, io wq exit can't be done, and cause IO hang.
The issue can be triggered when terminating 't/io_uring -n4 /dev/nullb0' with default null_blk parameters.
Fix it by reaping iopoll events in io_uring_clean_tctx() and moving io wq exit into workqueue context.
--- io_uring/io_uring.c | 2 +- io_uring/io_uring.h | 1 + io_uring/tctx.c | 60 +++++++++++++++++++++++++++++++++++++++------ 3 files changed, 54 insertions(+), 9 deletions(-)
io_uring/io_uring.c +1 -1
@@ -3214,7 +3214,7 @@ static __cold bool io_uring_try_cancel_iowq(struct io_ring_ctx *ctx)return ret; } -static bool iopoll_reap_events (struct io_ring_ctx *ctx,bool reap_all) +bool iopoll_reap_events (struct io_ring_ctx *ctx,bool reap_all) {bool reapped = false;
io_uring/io_uring.h +1 -0
@@ -63,6 +63,7 @@ void io_req_task_queue_fail(struct io_kiocb *req, int ret);void io_req_task_submit (struct io_kiocb *req,struct io_tw_state *ts);void tctx_task_work (struct callback_head *cb);__cold void io_uring_cancel_generic (bool cancel_all,struct io_sq_data *sqd); +bool iopoll_reap_events (struct io_ring_ctx *ctx,bool reap_all);int io_uring_alloc_task_context (struct task_struct *task,struct io_ring_ctx *ctx);
io_uring/tctx.c +52 -8
82 lines not on this page · raw message
Signature · 1 line
2.40.1