Add a simple helper telling a tw handler whether it should cancel requests, i.e. when the owner task is exiting. Signed-off-by: Pavel Begunkov <asml.silence@xxxxxxxxx> --- fs/io_uring.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 8011a61e6bd4..272a180ab7ee 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -1304,6 +1304,11 @@ static inline void req_ref_get(struct io_kiocb *req) atomic_inc(&req->refs); } +static inline bool io_should_fail_tw(struct io_kiocb *req) +{ + return unlikely(req->task->flags & PF_EXITING); +} + static inline void io_submit_flush_completions(struct io_ring_ctx *ctx) { if (!wq_list_empty(&ctx->submit_state.compl_reqs)) @@ -2641,8 +2646,8 @@ static void io_req_task_cancel(struct io_kiocb *req, bool *locked) static void io_req_task_submit(struct io_kiocb *req, bool *locked) { io_tw_lock(req->ctx, locked); - /* req->task == current here, checking PF_EXITING is safe */ - if (likely(!(req->task->flags & PF_EXITING))) + + if (!io_should_fail_tw(req)) io_queue_sqe(req); else io_req_complete_failed(req, -EFAULT); @@ -5867,8 +5872,7 @@ static int io_poll_check_events(struct io_kiocb *req, bool locked) struct io_ring_ctx *ctx = req->ctx; int v; - /* req->task == current here, checking PF_EXITING is safe */ - if (unlikely(req->task->flags & PF_EXITING)) + if (io_should_fail_tw(req)) return -ECANCELED; do { @@ -7418,7 +7422,7 @@ static void io_req_task_link_timeout(struct io_kiocb *req, bool *locked) int ret = -ENOENT; if (prev) { - if (!(req->task->flags & PF_EXITING)) + if (!io_should_fail_tw(req)) ret = io_try_cancel_userdata(req, prev->cqe.user_data); io_req_complete_post(req, ret ?: -ETIME, 0); io_put_req(prev); -- 2.36.0