]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
io_uring: fix cancel of deferred reqs with ->files
authorPavel Begunkov <asml.silence@gmail.com>
Sat, 5 Sep 2020 21:45:14 +0000 (00:45 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 12 Sep 2020 12:22:12 +0000 (14:22 +0200)
[ Upstream commit b7ddce3cbf010edbfac6c6d8cc708560a7bcd7a4 ]

While trying to cancel requests with ->files, it also should look for
requests in ->defer_list, otherwise it might end up hanging a thread.

Cancel all requests in ->defer_list up to the last request there with
matching ->files, that's needed to follow drain ordering semantics.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/io_uring.c

index 38f3ec15ba3b10d0e19d836670375137d56f343e..5f627194d0920c64f2fa816a178e0aba152209ef 100644 (file)
@@ -7675,12 +7675,38 @@ static void io_attempt_cancel(struct io_ring_ctx *ctx, struct io_kiocb *req)
        io_timeout_remove_link(ctx, req);
 }
 
+static void io_cancel_defer_files(struct io_ring_ctx *ctx,
+                                 struct files_struct *files)
+{
+       struct io_kiocb *req = NULL;
+       LIST_HEAD(list);
+
+       spin_lock_irq(&ctx->completion_lock);
+       list_for_each_entry_reverse(req, &ctx->defer_list, list) {
+               if ((req->flags & REQ_F_WORK_INITIALIZED)
+                       && req->work.files == files) {
+                       list_cut_position(&list, &ctx->defer_list, &req->list);
+                       break;
+               }
+       }
+       spin_unlock_irq(&ctx->completion_lock);
+
+       while (!list_empty(&list)) {
+               req = list_first_entry(&list, struct io_kiocb, list);
+               list_del_init(&req->list);
+               req_set_fail_links(req);
+               io_cqring_add_event(req, -ECANCELED);
+               io_double_put_req(req);
+       }
+}
+
 static void io_uring_cancel_files(struct io_ring_ctx *ctx,
                                  struct files_struct *files)
 {
        if (list_empty_careful(&ctx->inflight_list))
                return;
 
+       io_cancel_defer_files(ctx, files);
        /* cancel all at once, should be faster than doing it one by one*/
        io_wq_cancel_cb(ctx->io_wq, io_wq_files_match, files, true);