From: Pavel Begunkov <[email protected]>
To: Jens Axboe <[email protected]>, [email protected]
Cc: Dennis Zhou <[email protected]>, Tejun Heo <[email protected]>,
Christoph Lameter <[email protected]>, Joakim Hassila <[email protected]>
Subject: [PATCH 2/2] io_uring: fix shared sqpoll cancellation hangs
Date: Fri, 16 Apr 2021 01:22:52 +0100 [thread overview]
Message-ID: <4a39b2a97bd2c34084d49531a1c71d480132fe05.1618532491.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>
[ 736.982891] INFO: task iou-sqp-4294:4295 blocked for more than 122 seconds.
[ 736.982897] Call Trace:
[ 736.982901] schedule+0x68/0xe0
[ 736.982903] io_uring_cancel_sqpoll+0xdb/0x110
[ 736.982908] io_sqpoll_cancel_cb+0x24/0x30
[ 736.982911] io_run_task_work_head+0x28/0x50
[ 736.982913] io_sq_thread+0x4e3/0x720
We call io_uring_cancel_sqpoll() one by one for each ctx either in
sq_thread() itself or via task works, and it's intended to cancel all
requests of a specified context. However the function uses per-task
counters to track the number of inflight requests, so it counts more
requests than available via currect io_uring ctx and goes to sleep for
them to appear (e.g. from IRQ), that will never happen.
Reported-by: Joakim Hassila <[email protected]>
Reported-by: Jens Axboe <[email protected]>
Fixes: 37d1e2e3642e2 ("io_uring: move SQPOLL thread io-wq forked worker")
Signed-off-by: Pavel Begunkov <[email protected]>
---
fs/io_uring.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index dff34975d86b..c1c843b044c0 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -9000,10 +9000,11 @@ static void io_uring_cancel_sqpoll(struct io_ring_ctx *ctx)
WARN_ON_ONCE(!sqd || ctx->sq_data->thread != current);
+ percpu_ref_switch_to_atomic_sync(&ctx->refs);
atomic_inc(&tctx->in_idle);
do {
/* read completions before cancelations */
- inflight = tctx_inflight(tctx);
+ inflight = percpu_ref_atomic_count(&ctx->refs);
if (!inflight)
break;
io_uring_try_cancel_requests(ctx, current, NULL);
@@ -9014,7 +9015,7 @@ static void io_uring_cancel_sqpoll(struct io_ring_ctx *ctx)
* avoids a race where a completion comes in before we did
* prepare_to_wait().
*/
- if (inflight == tctx_inflight(tctx))
+ if (inflight == percpu_ref_atomic_count(&ctx->refs))
schedule();
finish_wait(&tctx->wait, &wait);
} while (1);
--
2.24.0
next prev parent reply other threads:[~2021-04-16 0:27 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-16 0:22 [PATCH 0/2] fix hangs with shared sqpoll Pavel Begunkov
2021-04-16 0:22 ` [PATCH 1/2] percpu_ref: add percpu_ref_atomic_count() Pavel Begunkov
2021-04-16 4:45 ` Dennis Zhou
2021-04-16 13:16 ` Pavel Begunkov
2021-04-16 14:10 ` Ming Lei
2021-04-16 14:37 ` Dennis Zhou
2021-04-19 2:03 ` Ming Lei
2021-04-16 15:31 ` Bart Van Assche
2021-04-16 15:34 ` Jens Axboe
2021-04-16 0:22 ` Pavel Begunkov [this message]
2021-04-16 0:26 ` [PATCH 0/2] fix hangs with shared sqpoll Pavel Begunkov
2021-04-16 13:04 ` Jens Axboe
2021-04-16 13:12 ` Pavel Begunkov
2021-04-16 13:58 ` Jens Axboe
2021-04-16 14:09 ` Pavel Begunkov
2021-04-16 14:42 ` Pavel Begunkov
[not found] ` <[email protected]>
2021-04-18 13:56 ` Pavel Begunkov
-- strict thread matches above, loose matches on Subject: below --
2021-04-18 13:52 [PATCH v2 " Pavel Begunkov
2021-04-18 13:52 ` [PATCH 2/2] io_uring: fix shared sqpoll cancellation hangs Pavel Begunkov
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=4a39b2a97bd2c34084d49531a1c71d480132fe05.1618532491.git.asml.silence@gmail.com \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[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