Linux-Fsdevel Archive on
help / color / mirror / Atom feed
From: Sasha Levin <>
Cc: Xiaoguang Wang <>,
	Jens Axboe <>, Sasha Levin <>,,
Subject: [PATCH AUTOSEL 5.6 45/50] io_uring: use cond_resched() in io_ring_ctx_wait_and_kill()
Date: Thu,  7 May 2020 10:27:21 -0400	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <>

From: Xiaoguang Wang <>

[ Upstream commit 3fd44c86711f71156b586c22b0495c58f69358bb ]

While working on to make io_uring sqpoll mode support syscalls that need
struct files_struct, I got cpu soft lockup in io_ring_ctx_wait_and_kill(),

    while (ctx->sqo_thread && !wq_has_sleeper(&ctx->sqo_wait))

above loop never has an chance to exit, it's because preempt isn't enabled
in the kernel, and the context calling io_ring_ctx_wait_and_kill() and
io_sq_thread() run in the same cpu, if io_sq_thread calls a cond_resched()
yield cpu and another context enters above loop, then io_sq_thread() will
always in runqueue and never exit.

Use cond_resched() can fix this issue.

Signed-off-by: Xiaoguang Wang <>
Signed-off-by: Jens Axboe <>
Signed-off-by: Sasha Levin <>
 fs/io_uring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index a46de2cfc28e8..b5ade01379029 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -6449,7 +6449,7 @@ static void io_ring_ctx_wait_and_kill(struct io_ring_ctx *ctx)
 	 * it could cause shutdown to hang.
 	while (ctx->sqo_thread && !wq_has_sleeper(&ctx->sqo_wait))
-		cpu_relax();
+		cond_resched();

      parent reply	other threads:[~2020-05-07 14:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <>
2020-05-07 14:27 ` [PATCH AUTOSEL 5.6 38/50] Fix use after free in get_tree_bdev() Sasha Levin
2020-05-07 14:27 ` [PATCH AUTOSEL 5.6 42/50] fibmap: Warn and return an error in case of block > INT_MAX Sasha Levin
2020-05-07 14:27 ` Sasha Levin [this message]

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:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \ \ \ \
    --subject='Re: [PATCH AUTOSEL 5.6 45/50] io_uring: use cond_resched() in io_ring_ctx_wait_and_kill()' \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).