summaryrefslogtreecommitdiff
path: root/fs/io_uring.c
diff options
context:
space:
mode:
authorPavel Begunkov <asml.silence@gmail.com>2020-09-06 00:45:14 +0300
committerJens Axboe <axboe@kernel.dk>2020-09-06 00:59:51 +0300
commitb7ddce3cbf010edbfac6c6d8cc708560a7bcd7a4 (patch)
tree024015addf58f2ed8c79b89d6c20be7cefc418b6 /fs/io_uring.c
parentc183edff33fdcd639d222a8f473bf44602adc655 (diff)
downloadlinux-b7ddce3cbf010edbfac6c6d8cc708560a7bcd7a4.tar.xz
io_uring: fix cancel of deferred reqs with ->files
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>
Diffstat (limited to 'fs/io_uring.c')
-rw-r--r--fs/io_uring.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/fs/io_uring.c b/fs/io_uring.c
index f703182df2d4..6129c67b0e3b 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -8098,12 +8098,39 @@ 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_defer_entry *de = NULL;
+ LIST_HEAD(list);
+
+ 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) {
+ list_cut_position(&list, &ctx->defer_list, &de->list);
+ break;
+ }
+ }
+ spin_unlock_irq(&ctx->completion_lock);
+
+ while (!list_empty(&list)) {
+ de = list_first_entry(&list, struct io_defer_entry, list);
+ list_del_init(&de->list);
+ req_set_fail_links(de->req);
+ io_put_req(de->req);
+ io_req_complete(de->req, -ECANCELED);
+ kfree(de);
+ }
+}
+
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);