From: Jens Axboe <axboe@kernel.dk>
To: io-uring@vger.kernel.org
Cc: Jens Axboe <axboe@kernel.dk>
Subject: [PATCH 2/2] io_uring/io-wq: don't trigger hung task for syzbot craziness
Date: Wed, 21 Jan 2026 16:22:17 -0700 [thread overview]
Message-ID: <20260121232546.260055-3-axboe@kernel.dk> (raw)
In-Reply-To: <20260121232546.260055-1-axboe@kernel.dk>
Use the same trick that blk_io_schedule() does to avoid triggering the
hung task warning (and potential reboot/panic, depending on system
settings), and only wait for half the hung task timeout at the time.
If we exceed the default IO_URING_EXIT_WAIT_MAX period where we expect
things to certainly have finished unless there's a bug, then throw a
WARN_ON_ONCE() for that case.
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
io_uring/io-wq.c | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/io_uring/io-wq.c b/io_uring/io-wq.c
index 2fa7d3601edb..aa670909fece 100644
--- a/io_uring/io-wq.c
+++ b/io_uring/io-wq.c
@@ -17,6 +17,7 @@
#include <linux/task_work.h>
#include <linux/audit.h>
#include <linux/mmu_context.h>
+#include <linux/sched/sysctl.h>
#include <uapi/linux/io_uring.h>
#include "io-wq.h"
@@ -1313,6 +1314,8 @@ static void io_wq_cancel_tw_create(struct io_wq *wq)
static void io_wq_exit_workers(struct io_wq *wq)
{
+ unsigned long timeout, warn_timeout;
+
if (!wq->task)
return;
@@ -1322,7 +1325,24 @@ static void io_wq_exit_workers(struct io_wq *wq)
io_wq_for_each_worker(wq, io_wq_worker_wake, NULL);
rcu_read_unlock();
io_worker_ref_put(wq);
- wait_for_completion(&wq->worker_done);
+
+ /*
+ * Shut up hung task complaint, see for example
+ *
+ * https://lore.kernel.org/all/696fc9e7.a70a0220.111c58.0006.GAE@google.com/
+ *
+ * where completely overloading the system with tons of long running
+ * io-wq items can easily trigger the hung task timeout. Only sleep
+ * uninterruptibly for half that time, and warn if we exceeded end
+ * up waiting more than IO_URING_EXIT_WAIT_MAX.
+ */
+ timeout = sysctl_hung_task_timeout_secs * HZ / 2;
+ warn_timeout = jiffies + IO_URING_EXIT_WAIT_MAX;
+ do {
+ if (wait_for_completion_timeout(&wq->worker_done, timeout))
+ break;
+ WARN_ON_ONCE(time_after(jiffies, warn_timeout));
+ } while (1);
spin_lock_irq(&wq->hash->wait.lock);
list_del_init(&wq->wait.entry);
--
2.51.0
prev parent reply other threads:[~2026-01-21 23:25 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-21 23:22 [PATCHSET 0/2] Avoid spurious syzbot induced hung task panics Jens Axboe
2026-01-21 23:22 ` [PATCH 1/2] io_uring: add IO_URING_EXIT_WAIT_MAX definition Jens Axboe
2026-01-21 23:22 ` Jens Axboe [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:
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=20260121232546.260055-3-axboe@kernel.dk \
--to=axboe@kernel.dk \
--cc=io-uring@vger.kernel.org \
/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