5.8 stable inclusion request
Subsystems (2)
Hi,
Can I get these two queued up, in this order:
commit b7ddce3cbf010edbfac6c6d8cc708560a7bcd7a4
Author: Pavel Begunkov <[email protected]> Date: Sun Sep 6 00:45:14 2020 +0300
io_uring: fix cancel of deferred reqs with ->files
and
commit c127a2a1b7baa5eb40a7e2de4b7f0c51ccbbb2ef (tag: io_uring-5.9-2020-09-06, origin/i o_uring-5.9, io_uring-5.9)
Author: Pavel Begunkov <[email protected]> Date: Sun Sep 6 00:45:15 2020 +0300
io_uring: fix linked deferred ->files cancellation
which should both cherry-pick cleanly into the 5.8-stable tree.
Thanks!
Signature · 1 line
Jens Axboe
Quoted 12 lines · Jens Axboe
Hi,
Can I get these two queued up, in this order:
commit
b7ddce3cbf010edbfac6c6d8cc708560a7bcd7a4Author: Pavel Begunkov <[email protected]> Date: Sun Sep 6 00:45:14 2020 +0300io_uring: fix cancel of deferred reqs with ->filesand
Quoted 8 lines
commit
c127a2a1b7baa5eb40a7e2de4b7f0c51ccbbb2ef(tag: io_uring-5.9-2020-09-06, origin/i o_uring-5.9, io_uring-5.9)Author: Pavel Begunkov <[email protected]> Date: Sun Sep 6 00:45:15 2020 +0300io_uring: fix linked deferred ->files cancellationwhich should both cherry-pick cleanly into the 5.8-stable tree.
They do pick cleanly, but missing some infrastructure... I'll send these in separately.
Signature · 1 line
Jens Axboe
Quoted 18 lines · Jens Axboe
Quoted 17 lines · Jens Axboe
Hi,
Can I get these two queued up, in this order:
commit
b7ddce3cbf010edbfac6c6d8cc708560a7bcd7a4Author: Pavel Begunkov <[email protected]> Date: Sun Sep 6 00:45:14 2020 +0300io_uring: fix cancel of deferred reqs with ->filesand
commit
c127a2a1b7baa5eb40a7e2de4b7f0c51ccbbb2ef(tag: io_uring-5.9-2020-09-06, origin/i o_uring-5.9, io_uring-5.9)Author: Pavel Begunkov <[email protected]> Date: Sun Sep 6 00:45:15 2020 +0300
Quoted 6 lines
Quoted 3 lines
io_uring: fix linked deferred ->files cancellationwhich should both cherry-pick cleanly into the 5.8-stable tree.
They do pick cleanly, but missing some infrastructure... I'll send these in separately.
Here you go, these work and are tested.
Signature · 1 line
Jens Axboe
From faaff9b554082ef41acdb314b920ea03b5ce95c9 Mon Sep 17 00:00:00 2001
From: Pavel Begunkov <[email protected]>
Date: Sun, 6 Sep 2020 00:45:15 +0300
Subject: [PATCH 2/2] io_uring: fix linked deferred ->files cancellation
[ Upstream commit c127a2a1b7baa5eb40a7e2de4b7f0c51ccbbb2ef ]
While looking for ->files in ->defer_list, consider that requests there may actually be links.
--- fs/io_uring.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-)
fs/io_uring.c +23 -2
@@ -7600,6 +7600,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
@@ -7682,8 +7704,7 @@ static void io_cancel_defer_files(struct io_ring_ctx *ctx,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) { +if (io_match_link_files (req, files)) {list_cut_position (&list, &ctx->defer_list, &req->list);break ; }
Signature · 1 line
2.28.0
From 02cad2a0bbbfe48aa575573deae15cc2431872ff Mon Sep 17 00:00:00 2001
From: Pavel Begunkov <[email protected]>
Date: Sun, 6 Sep 2020 00:45:14 +0300
Subject: [PATCH 1/2] io_uring: fix cancel of deferred reqs with ->files
[ 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.
--- fs/io_uring.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
fs/io_uring.c +26 -0
@@ -7674,12 +7674,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);
Signature · 1 line
2.28.0
Quoted 19 lines · Jens Axboe
Quoted 18 lines · Jens Axboe
Quoted 17 lines · Jens Axboe
Hi,
Can I get these two queued up, in this order:
commit
b7ddce3cbf010edbfac6c6d8cc708560a7bcd7a4Author: Pavel Begunkov <[email protected]> Date: Sun Sep 6 00:45:14 2020 +0300io_uring: fix cancel of deferred reqs with ->filesand
commit
c127a2a1b7baa5eb40a7e2de4b7f0c51ccbbb2ef(tag: io_uring-5.9-2020-09-06, origin/i o_uring-5.9, io_uring-5.9)Author: Pavel Begunkov <[email protected]> Date: Sun Sep 6 00:45:15 2020 +0300
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
io_uring: fix linked deferred ->files cancellationwhich should both cherry-pick cleanly into the 5.8-stable tree.
They do pick cleanly, but missing some infrastructure... I'll send these in separately.
Here you go, these work and are tested.
Queued up, thanks!
Signature · 2 lines
Thanks, Sasha