Commit c127a2a1 authored by Pavel Begunkov's avatar Pavel Begunkov Committed by Jens Axboe

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: default avatarPavel Begunkov <asml.silence@gmail.com>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent b7ddce3c
...@@ -8024,6 +8024,28 @@ static bool io_match_link(struct io_kiocb *preq, struct io_kiocb *req) ...@@ -8024,6 +8024,28 @@ static bool io_match_link(struct io_kiocb *preq, struct io_kiocb *req)
return false; return false;
} }
static inline bool io_match_files(struct io_kiocb *req,
struct files_struct *files)
{
return (req->flags & REQ_F_WORK_INITIALIZED) && req->work.files == files;
}
static bool io_match_link_files(struct io_kiocb *req,
struct files_struct *files)
{
struct io_kiocb *link;
if (io_match_files(req, files))
return true;
if (req->flags & REQ_F_LINK_HEAD) {
list_for_each_entry(link, &req->link_list, link_list) {
if (io_match_files(link, files))
return true;
}
}
return false;
}
/* /*
* We're looking to cancel 'req' because it's holding on to our files, but * We're looking to cancel 'req' because it's holding on to our files, but
* 'req' could be a link to another request. See if it is, and cancel that * '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, ...@@ -8106,8 +8128,7 @@ static void io_cancel_defer_files(struct io_ring_ctx *ctx,
spin_lock_irq(&ctx->completion_lock); spin_lock_irq(&ctx->completion_lock);
list_for_each_entry_reverse(de, &ctx->defer_list, list) { list_for_each_entry_reverse(de, &ctx->defer_list, list) {
if ((de->req->flags & REQ_F_WORK_INITIALIZED) if (io_match_link_files(de->req, files)) {
&& de->req->work.files == files) {
list_cut_position(&list, &ctx->defer_list, &de->list); list_cut_position(&list, &ctx->defer_list, &de->list);
break; break;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment