From: Breno Leitao <leitao@debian.org>
To: Tejun Heo <tj@kernel.org>
Cc: linux-kernel@vger.kernel.org,
Lai Jiangshan <jiangshanlai@gmail.com>,
stable@vger.kernel.org
Subject: Re: [PATCH wq/for-7.4-fixes] workqueue: Fix drain_workqueue() missing work items chained across pwqs
Date: Mon, 2 Nov 2026 02:59:13 -0800 [thread overview]
Message-ID: <auhlROvLdDKg7-x6@gmail.com> (raw)
In-Reply-To: <20261030164210.3735018-1-tj@kernel.org>
On Fri, Oct 30, 2026 at 06:42:10AM -1000, Tejun Heo wrote:
> drain_workqueue() flushes the workqueue, then checks each pwq under its
> pool's lock and returns once a pass finds every pwq empty. Only chained
> queueing is allowed meanwhile, and a chained work item can land on a pwq
> other than the one the queueing work item is executing on. The pass misses
> it when:
>
> 1. The pass finds pwq A empty.
> 2. A work item executing on pwq B queues a work item on pwq A.
> 3. The work item on pwq B finishes.
> 4. The pass finds pwq B empty.
>
> drain_workqueue() returns with the work item on pwq A pending, and
> destroy_workqueue() can then trip WARN_ON(pwq_busy()) and leak the
> workqueue.
Very nice finding, basically drain_workqueue() could return while the
tail of a chain was still pending.
> Add wq->drain_seq, which counts chained queueings while the workqueue is
> draining. drain_workqueue() reads it before each flush and retries if it
> changed by the end of the check pass. Flushing once more after an empty pass
> is not enough, as a longer chain is missed the same way.
I am curious about a work function that keeps re-queueing itself
forever. That is a bug in the caller for sure, but the current code can
escape it by luck through this race (and then leak the workqueue), while
with this patch drain_workqueue() will loop forever. Is my reading
correct here?
> Verified with reproducers of both shapes: self-requeueing work items on an
> unbound workqueue and chained queue_work_on() of another work item on a
> per-cpu workqueue.
>
> Fixes: c8efcc258946 ("workqueue: allow chained queueing during destruction")
> Cc: stable@vger.kernel.org # v2.6.38+
> Signed-off-by: Tejun Heo <tj@kernel.org>
Reviewed-by: Breno Leitao <leitao@debian.org>
next prev parent reply other threads:[~2026-11-02 10:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-30 16:42 Tejun Heo
2026-11-02 10:59 ` Breno Leitao [this message]
2026-11-02 18:21 ` Tejun Heo
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=auhlROvLdDKg7-x6@gmail.com \
--to=leitao@debian.org \
--cc=jiangshanlai@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=tj@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
all inboxes | Powered by JetHome®