aboutsummaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
authorPavel Begunkov2020-09-06 00:45:15 +0300
committerJens Axboe2020-09-05 16:02:42 -0600
commitc127a2a1b7baa5eb40a7e2de4b7f0c51ccbbb2ef (patch)
tree11f0678b7a57b5e5765987de364c97d6edc6e202 /fs
parentb7ddce3cbf010edbfac6c6d8cc708560a7bcd7a4 (diff)
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 <asml.silence@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'fs')
-rw-r--r--fs/io_uring.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/fs/io_uring.c b/fs/io_uring.c
index 6129c67b0e3b..175fb647d099 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -8024,6 +8024,28 @@ static bool io_match_link(struct io_kiocb *preq, struct io_kiocb *req)
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
* '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,
spin_lock_irq(&ctx->completion_lock);
list_for_each_entry_reverse(de, &ctx->defer_list, list) {
- if ((de->req->flags & REQ_F_WORK_INITIALIZED)
- && de->req->work.files == files) {
+ if (io_match_link_files(de->req, files)) {
list_cut_position(&list, &ctx->defer_list, &de->list);
break;
}