From: Pavel Begunkov <[email protected]>
To: Jens Axboe <[email protected]>, [email protected]
Subject: [PATCH 1/2] io_uring: fix cancel of deferred reqs with ->files
Date: Sun, 6 Sep 2020 00:45:14 +0300 [thread overview]
Message-ID: <76a24f63b598c6e698ceb7cbdbe0aad012d412e0.1599340635.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>
While trying to cancel requests with ->files, it also should look for 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 <[email protected]>
---
fs/io_uring.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index 2e3adf9d17dd..20b647afe206 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -8092,12 +8092,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_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);
--
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 ` Pavel Begunkov [this message]
2020-09-05 21:45 ` [PATCH 2/2] io_uring: fix linked deferred ->files cancellation Pavel Begunkov
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=76a24f63b598c6e698ceb7cbdbe0aad012d412e0.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