Skip to content

Commit b711d4e

Browse files
committed
io_uring: find and cancel head link async work on files exit
Commit f254ac0 ("io_uring: enable lookup of links holding inflight files") only handled 2 out of the three head link cases we have, we also need to lookup and cancel work that is blocked in io-wq if that work has a link that's holding a reference to the files structure. Put the "cancel head links that hold this request pending" logic into io_attempt_cancel(), which will to through the motions of finding and canceling head links that hold the current inflight files stable request pending. Cc: [email protected] Reported-by: Pavel Begunkov <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 9123e3a commit b711d4e

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

fs/io_uring.c

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8063,6 +8063,33 @@ static bool io_timeout_remove_link(struct io_ring_ctx *ctx,
80638063
return found;
80648064
}
80658065

8066+
static bool io_cancel_link_cb(struct io_wq_work *work, void *data)
8067+
{
8068+
return io_match_link(container_of(work, struct io_kiocb, work), data);
8069+
}
8070+
8071+
static void io_attempt_cancel(struct io_ring_ctx *ctx, struct io_kiocb *req)
8072+
{
8073+
enum io_wq_cancel cret;
8074+
8075+
/* cancel this particular work, if it's running */
8076+
cret = io_wq_cancel_work(ctx->io_wq, &req->work);
8077+
if (cret != IO_WQ_CANCEL_NOTFOUND)
8078+
return;
8079+
8080+
/* find links that hold this pending, cancel those */
8081+
cret = io_wq_cancel_cb(ctx->io_wq, io_cancel_link_cb, req, true);
8082+
if (cret != IO_WQ_CANCEL_NOTFOUND)
8083+
return;
8084+
8085+
/* if we have a poll link holding this pending, cancel that */
8086+
if (io_poll_remove_link(ctx, req))
8087+
return;
8088+
8089+
/* final option, timeout link is holding this req pending */
8090+
io_timeout_remove_link(ctx, req);
8091+
}
8092+
80668093
static void io_uring_cancel_files(struct io_ring_ctx *ctx,
80678094
struct files_struct *files)
80688095
{
@@ -8116,10 +8143,8 @@ static void io_uring_cancel_files(struct io_ring_ctx *ctx,
81168143
continue;
81178144
}
81188145
} else {
8119-
io_wq_cancel_work(ctx->io_wq, &cancel_req->work);
8120-
/* could be a link, check and remove if it is */
8121-
if (!io_poll_remove_link(ctx, cancel_req))
8122-
io_timeout_remove_link(ctx, cancel_req);
8146+
/* cancel this request, or head link requests */
8147+
io_attempt_cancel(ctx, cancel_req);
81238148
io_put_req(cancel_req);
81248149
}
81258150

0 commit comments

Comments
 (0)