From: "Yu Kuai" <yukuai@fnnas.com>
To: "Karl Mehltretter" <kmehltretter@gmail.com>,
"Tejun Heo" <tj@kernel.org>,
"Josef Bacik" <josef@toxicpanda.com>,
"Jens Axboe" <axboe@kernel.dk>, "yu kuai" <yukuai@fygo.io>
Cc: "Ming Lei" <ming.lei@redhat.com>,
"Christoph Hellwig" <hch@lst.de>,
"Yi Zhang" <yi.zhang@redhat.com>, <cgroups@vger.kernel.org>,
<linux-block@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<stable@vger.kernel.org>
Subject: Re: [PATCH] blk-cgroup: fix lost wakeup in blkg_destroy_all()
Date: Tue, 11 Aug 2026 19:14:37 +0800 [thread overview]
Message-ID: <0898e560-73a8-4f1e-af13-65042cec0c7d@fnnas.com> (raw)
In-Reply-To: <20260811110421.50747-1-kmehltretter@gmail.com>
Hi,
在 2026/8/11 19:04, Karl Mehltretter 写道:
> wake_up_var() requires a full barrier between making the wait condition
> true and its lockless waitqueue check. spin_unlock_irq() has only
> release semantics, so it does not order q->root_blkg = NULL against
> that check.
>
> During disk rebind, blkcg_init_disk() can therefore miss the wakeup and
> sleep indefinitely. Add the required smp_mb(). Also mark the store with
> WRITE_ONCE() since the waiter reads root_blkg locklessly with
> READ_ONCE(). An LKMM model permits the missed-wakeup outcome without
> the barrier and forbids it with the barrier.
>
> Fixes: 3dbaacf6ab68 ("blk-cgroup: wait for blkcg cleanup before initializing new disk")
Looks like this will be fixed by following patch as well:
[RFC PATCH v2 1/4] blk-cgroup: wait for old blkgs to leave queue before
disk rebind - Yu Kuai
<https://lore.kernel.org/all/20260811064744.1139446-2-yukuai@kernel.org/>
> Cc: stable@vger.kernel.org
> Assisted-by: Claude:claude-fable-5
> Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com>
> ---
> LKMM (herdtools7 7.58), with the store modeled by WRITE_ONCE(). flag
> is q->root_blkg (1 = set), lk the queue_lock, wq the var waitqueue
> occupancy. To model the fixed code, insert smp_mb() in P0 between
> smp_store_release(lk, 0) and READ_ONCE(*wq):
>
> C blkcg-rebind-buggy
> { flag=1; }
> P0(int *flag, int *lk, int *wq)
> {
> int r0;
> WRITE_ONCE(*flag, 0);
> smp_store_release(lk, 0);
> r0 = READ_ONCE(*wq);
> }
> P1(int *flag, int *lk, int *wq)
> {
> int r1;
> WRITE_ONCE(*wq, 1);
> smp_mb();
> r1 = READ_ONCE(*flag);
> }
> exists (0:r0=0 /\ 1:r1=1)
>
> herd7 -conf linux-kernel.cfg blkcg-rebind-buggy.litmus
>
> without smp_mb(): Sometimes
> with smp_mb(): Never
>
> block/blk-cgroup.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
> index d9676126c5b5d..2b3cf9caeaa31 100644
> --- a/block/blk-cgroup.c
> +++ b/block/blk-cgroup.c
> @@ -604,9 +604,11 @@ static void blkg_destroy_all(struct gendisk *disk)
> __clear_bit(pol->plid, q->blkcg_pols);
> }
>
> - q->root_blkg = NULL;
> + WRITE_ONCE(q->root_blkg, NULL);
> spin_unlock_irq(&q->queue_lock);
>
> + /* Order q->root_blkg store before wake_up_var()'s waitqueue check */
> + smp_mb();
> wake_up_var(&q->root_blkg);
> }
>
> --
> 2.53.0
>
--
Thanks,
Kuai
prev parent reply other threads:[~2026-08-11 11:14 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-11 11:04 [PATCH] blk-cgroup: fix lost wakeup in blkg_destroy_all() Karl Mehltretter
2026-08-11 11:14 ` Yu Kuai [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=0898e560-73a8-4f1e-af13-65042cec0c7d@fnnas.com \
--to=yukuai@fnnas.com \
--cc=axboe@kernel.dk \
--cc=cgroups@vger.kernel.org \
--cc=hch@lst.de \
--cc=josef@toxicpanda.com \
--cc=kmehltretter@gmail.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ming.lei@redhat.com \
--cc=stable@vger.kernel.org \
--cc=tj@kernel.org \
--cc=yi.zhang@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox