From: Jens Axboe <axboe@kernel.dk>
To: Fengnan Chang <changfengnan@bytedance.com>,
io-uring@vger.kernel.org, linux-kernel@vger.kernel.org,
peterz@infradead.org, rostedt@goodmis.org
Subject: Re: [PATCH] io_uring/io-wq: avoid repeated task_work scans during teardown
Date: Thu, 21 May 2026 10:58:51 -0600 [thread overview]
Message-ID: <469287b6-201a-497d-ac67-03e1336dd81a@kernel.dk> (raw)
In-Reply-To: <20260520031221.83210-1-changfengnan@bytedance.com>
On 5/19/26 9:12 PM, Fengnan Chang wrote:
> We hit hard-lockup reports from iou-wrk threads stuck in
> task_work_cancel_match() during io-wq teardown in syzkaller test.
> The root cause is that teardown repeatedly rescans the submitter task's
> full task_work list under pi_lock, once per matched item.
>
> Two spots are problematic:
>
> 1) io_wq_cancel_tw_create() loops calling task_work_cancel_match() to
> remove worker-creation callbacks one at a time. Each call re-walks
> the entire list from scratch while holding pi_lock.
>
> 2) io_worker_exit() unconditionally scans the submitter task_work list
> for its own create_work, even when it never queued one. With many
> workers exiting simultaneously against a large unrelated task_work
> list, this adds up fast.
>
> Fix (1) by adding task_work_cancel_match_all() that unlinks all matching
> callbacks in a single traversal, then iterating the returned list locally.
> Same try_cmpxchg() synchronisation as before, stops at the work_exited
> sentinel.
>
> Fix (2) by skipping the cancel entirely unless create_state indicates a
> pending create_work. Since create_state is exclusively owned via
> test_and_set_bit_lock, at most one callback can be queued per worker, so
> the cancel is also simplified from a loop to a single call.
>
> With this fix the reproducer (FIFO-open + MSG_RING SEND_FD stress) no
> longer triggers hard-lockup reports, and task_work_cancel_match samples
> drop to microseconds.
Looks good to me, nicer way to do this too.
--
Jens Axboe
next prev parent reply other threads:[~2026-05-21 16:58 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-20 3:12 Fengnan Chang
2026-05-20 13:44 ` Gabriel Krisman Bertazi
2026-05-21 7:14 ` changfengnan
2026-05-21 16:58 ` Jens Axboe [this message]
2026-06-15 7:33 ` changfengnan
2026-07-09 9:02 ` changfengnan
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=469287b6-201a-497d-ac67-03e1336dd81a@kernel.dk \
--to=axboe@kernel.dk \
--cc=changfengnan@bytedance.com \
--cc=io-uring@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.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
Powered by JetHome