Skip to content

Commit c127a2a

Browse files
isilenceaxboe
authored andcommitted
io_uring: fix linked deferred ->files cancellation
While looking for ->files in ->defer_list, consider that requests there may actually be links. Signed-off-by: Pavel Begunkov <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent b7ddce3 commit c127a2a

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

fs/io_uring.c

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8024,6 +8024,28 @@ static bool io_match_link(struct io_kiocb *preq, struct io_kiocb *req)
80248024
return false;
80258025
}
80268026

8027+
static inline bool io_match_files(struct io_kiocb *req,
8028+
struct files_struct *files)
8029+
{
8030+
return (req->flags & REQ_F_WORK_INITIALIZED) && req->work.files == files;
8031+
}
8032+
8033+
static bool io_match_link_files(struct io_kiocb *req,
8034+
struct files_struct *files)
8035+
{
8036+
struct io_kiocb *link;
8037+
8038+
if (io_match_files(req, files))
8039+
return true;
8040+
if (req->flags & REQ_F_LINK_HEAD) {
8041+
list_for_each_entry(link, &req->link_list, link_list) {
8042+
if (io_match_files(link, files))
8043+
return true;
8044+
}
8045+
}
8046+
return false;
8047+
}
8048+
80278049
/*
80288050
* We're looking to cancel 'req' because it's holding on to our files, but
80298051
* 'req' could be a link to another request. See if it is, and cancel that
@@ -8106,8 +8128,7 @@ static void io_cancel_defer_files(struct io_ring_ctx *ctx,
81068128

81078129
spin_lock_irq(&ctx->completion_lock);
81088130
list_for_each_entry_reverse(de, &ctx->defer_list, list) {
8109-
if ((de->req->flags & REQ_F_WORK_INITIALIZED)
8110-
&& de->req->work.files == files) {
8131+
if (io_match_link_files(de->req, files)) {
81118132
list_cut_position(&list, &ctx->defer_list, &de->list);
81128133
break;
81138134
}

0 commit comments

Comments
 (0)