From: Pavel Begunkov <[email protected]>
To: Jens Axboe <[email protected]>, [email protected]
Subject: [PATCH 2/2] io_uring: fix linked deferred ->files cancellation
Date: Sun, 6 Sep 2020 00:45:15 +0300 [thread overview]
Message-ID: <403cf67159f252b2f774e065984cd39120eaa9e4.1599340635.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>
While looking for ->files in ->defer_list, consider that requests there
may actually be links.
Signed-off-by: Pavel Begunkov <[email protected]>
---
fs/io_uring.c | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index 20b647afe206..f56e2cad97cc 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -8018,6 +8018,26 @@ 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 *file)
+{
+ return (req->flags & REQ_F_WORK_INITIALIZED) && req->work.files == file;
+}
+
+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
@@ -8100,8 +8120,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;
}
--
2.24.0
next prev parent reply other threads:[~2020-09-05 21:47 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-05 21:45 [PATCH for-5.9 0/2] fix deferred ->files cancel Pavel Begunkov
2020-09-05 21:45 ` [PATCH 1/2] io_uring: fix cancel of deferred reqs with ->files Pavel Begunkov
2020-09-05 21:45 ` Pavel Begunkov [this message]
2020-09-05 22:03 ` [PATCH for-5.9 0/2] fix deferred ->files cancel Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=403cf67159f252b2f774e065984cd39120eaa9e4.1599340635.git.asml.silence@gmail.com \
[email protected] \
[email protected] \
[email protected] \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox