From: Fengnan Chang <changfengnan@bytedance.com>
To: Max Kellermann <max.kellermann@ionos.com>
Cc: Jens Axboe <axboe@kernel.dk>, Sasha Levin <sashal@kernel.org>,
Diangang Li <lidiangang@bytedance.com>,
io-uring@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [External] [PATCH] io_uring/io-wq: fix `max_workers` breakage and `nr_workers` underflow
Date: Fri, 12 Sep 2025 09:21:10 +0800 [thread overview]
Message-ID: <CAPFOzZujMZg14Ljp-YsgPqqcJhMFnU68e7XOf09pc=jwoTPytA@mail.gmail.com> (raw)
In-Reply-To: <20250912000609.1429966-1-max.kellermann@ionos.com>
Max Kellermann <max.kellermann@ionos.com> 于2025年9月12日周五 08:06写道:
>
> Commit 88e6c42e40de ("io_uring/io-wq: add check free worker before
> create new worker") reused the variable `do_create` for something
> else, abusing it for the free worker check.
>
> This caused the value to effectively always be `true` at the time
> `nr_workers < max_workers` was checked, but it should really be
> `false`. This means the `max_workers` setting was ignored, and worse:
> if the limit had already been reached, incrementing `nr_workers` was
> skipped even though another worker would be created.
>
> When later lots of workers exit, the `nr_workers` field could easily
> underflow, making the problem worse because more and more workers
> would be created without incrementing `nr_workers`.
Thanks, my mistake.
Reviewed-by: Fengnan Chang <changfengnan@bytedance.com>
>
> The simple solution is to use a different variable for the free worker
> check instead of using one variable for two different things.
>
> Cc: stable@vger.kernel.org
> Fixes: 88e6c42e40de ("io_uring/io-wq: add check free worker before create new worker")
> Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
> ---
> io_uring/io-wq.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/io_uring/io-wq.c b/io_uring/io-wq.c
> index 17dfaa0395c4..1d03b2fc4b25 100644
> --- a/io_uring/io-wq.c
> +++ b/io_uring/io-wq.c
> @@ -352,16 +352,16 @@ static void create_worker_cb(struct callback_head *cb)
> struct io_wq *wq;
>
> struct io_wq_acct *acct;
> - bool do_create = false;
> + bool activated_free_worker, do_create = false;
>
> worker = container_of(cb, struct io_worker, create_work);
> wq = worker->wq;
> acct = worker->acct;
>
> rcu_read_lock();
> - do_create = !io_acct_activate_free_worker(acct);
> + activated_free_worker = io_acct_activate_free_worker(acct);
> rcu_read_unlock();
> - if (!do_create)
> + if (activated_free_worker)
> goto no_need_create;
>
> raw_spin_lock(&acct->workers_lock);
> --
> 2.47.3
>
next prev parent reply other threads:[~2025-09-12 1:21 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-12 0:06 [PATCH] io_uring/io-wq: fix `max_workers` breakage and `nr_workers` underflow Max Kellermann
2025-09-12 1:21 ` Fengnan Chang [this message]
2025-09-15 19:06 ` Jens Axboe
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='CAPFOzZujMZg14Ljp-YsgPqqcJhMFnU68e7XOf09pc=jwoTPytA@mail.gmail.com' \
--to=changfengnan@bytedance.com \
--cc=axboe@kernel.dk \
--cc=io-uring@vger.kernel.org \
--cc=lidiangang@bytedance.com \
--cc=linux-kernel@vger.kernel.org \
--cc=max.kellermann@ionos.com \
--cc=sashal@kernel.org \
--cc=stable@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