From: Tao Cui <cui.tao@linux.dev>
To: Zizhi Wo <wozizhi@huaweicloud.com>,
axboe@kernel.dk, tj@kernel.org, josef@toxicpanda.com,
linux-block@vger.kernel.org
Cc: cui.tao@linux.dev, cgroups@vger.kernel.org, yangerkun@huawei.com,
chengzhihao1@huawei.com, houtao1@huawei.com, yukuai@fygo.io
Subject: Re: [PATCH 1/2] blk-cgroup: fix blkg leak in blkg_create() error path
Date: Tue, 23 Jun 2026 09:16:01 +0800 [thread overview]
Message-ID: <38704548-786f-4ec7-afd4-228aa8d68ad7@linux.dev> (raw)
In-Reply-To: <20260622070714.1158886-2-wozizhi@huaweicloud.com>
Hi Zizhi,
Thanks for the patch. I ran into the same issue and posted a fix for it
earlier:
https://lore.kernel.org/all/20260507061229.57466-1-cuitao@kylinos.cn/
The leak fix is identical to yours (blkg_put() -> percpu_ref_kill()),
plus one extra change: moving blkg->online = true into the success
block:
if (likely(!ret)) {
...
+ blkg->online = true;
}
- blkg->online = true;
On the failure path the blkg was never inserted into any list, and its
blkg->pd[i]->online flags were not set either (those are in the same
block). Leaving blkg->online = true marks a blkg as online that was
never created -- inconsistent with pd[]->online and with
blkg_destroy(), which clears blkg->online = false. Not observable
today, since the failed blkg is on no list and unreachable by the
online readers, but the flag should track the actual insertion.
(This was sent to the cgroups list rather than linux-block, hence the
overlap.)
Thanks,
Tao
在 2026/6/22 15:07, Zizhi Wo 写道:
> When radix_tree_insert() fails in blkg_create(), the error path calls
> blkg_put() to release the blkg. This was correct when blkg->refcnt was an
> atomic_t: blkg_put() dropped it to 0 and triggered the release path.
>
> But commit 7fcf2b033b84 ("blkcg: change blkg reference counting to use
> percpu_ref") switched refcnt to a percpu_ref. In percpu mode
> percpu_ref_put() never checks for zero, so the release callback is never
> invoked. This blkg is on neither blkcg->blkg_list nor queue->blkg_list, so
> blkg_destroy_all() / blkcg_destroy_blkgs() can never reach it to call
> blkg_destroy()->percpu_ref_kill() either, cause the leak.
>
> Fix it by killing the percpu_ref instead, which switches it to atomic mode
> and drops the initial ref.
>
> Fixes: 7fcf2b033b84 ("blkcg: change blkg reference counting to use percpu_ref")
> Signed-off-by: Zizhi Wo <wozizhi@huaweicloud.com>
> Signed-off-by: Zizhi Wo <wozizhi@huawei.com>
> ---
> block/blk-cgroup.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
> index bc63bd220865..6386fe413994 100644
> --- a/block/blk-cgroup.c
> +++ b/block/blk-cgroup.c
> @@ -437,11 +437,11 @@ static struct blkcg_gq *blkg_create(struct blkcg *blkcg, struct gendisk *disk,
>
> if (!ret)
> return blkg;
>
> /* @blkg failed fully initialized, use the usual release path */
> - blkg_put(blkg);
> + percpu_ref_kill(&blkg->refcnt);
> return ERR_PTR(ret);
>
> err_put_css:
> css_put(&blkcg->css);
> err_free_blkg:
next prev parent reply other threads:[~2026-06-23 1:16 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-22 7:07 [PATCH 0/2] fix two issues in blkg_create() error path Zizhi Wo
2026-06-22 7:07 ` [PATCH 1/2] blk-cgroup: fix blkg leak " Zizhi Wo
2026-06-23 1:16 ` Tao Cui [this message]
2026-06-23 1:38 ` Zizhi Wo
2026-06-22 7:07 ` [PATCH 2/2] blk-cgroup: fix null-ptr-deref by freeing blkg pd on blkg_create " Zizhi Wo
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=38704548-786f-4ec7-afd4-228aa8d68ad7@linux.dev \
--to=cui.tao@linux.dev \
--cc=axboe@kernel.dk \
--cc=cgroups@vger.kernel.org \
--cc=chengzhihao1@huawei.com \
--cc=houtao1@huawei.com \
--cc=josef@toxicpanda.com \
--cc=linux-block@vger.kernel.org \
--cc=tj@kernel.org \
--cc=wozizhi@huaweicloud.com \
--cc=yangerkun@huawei.com \
--cc=yukuai@fygo.io \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.