Linux cgroups development
 help / color / mirror / Atom feed
From: Tao Cui <cui.tao@linux.dev>
To: Yu Kuai <yukuai@kernel.org>, axboe@kernel.dk, tj@kernel.org
Cc: cui.tao@linux.dev, hch@lst.de, dongsheng.yang@linux.dev,
	cengku@gmail.com, josef@toxicpanda.com, nilay@linux.ibm.com,
	ming.lei@redhat.com, yukuai@fygo.io, linux-block@vger.kernel.org,
	cgroups@vger.kernel.org
Subject: Re: [RFC PATCH v2 7/8] bfq: avoid blkg lookup from locked cgroup update
Date: Wed, 29 Jul 2026 15:33:03 +0800	[thread overview]
Message-ID: <45ea6216-a6f6-4828-afd3-8acea8b949ab@linux.dev> (raw)
In-Reply-To: <20260724123037.3004560-8-yukuai@kernel.org>



在 2026/7/24 20:30, Yu Kuai 写道:
> From: Yu Kuai <yukuai@fygo.io>
> 
> bfq_bio_bfqg() is called while bfqd->lock is held from the merge and
> request insertion paths.  It walks bio->bi_blkg and its parent chain to
> find the closest online BFQ group, and re-associates the bio by looking
> the chosen blkg up again through bio_associate_blkg_from_css().
> 
> Now that blkg creation runs under q->blkcg_mutex from the sleepable submit
> path, bio_associate_blkg_from_css() can sleep on a lookup miss, which BFQ
> must not do while holding bfqd->lock.  The blkg BFQ wants is already in
> hand from the ancestry walk, so update bio->bi_blkg by swapping references
> to that existing blkg directly instead of looking it up again by css.
> 

Just checking the new bfq helper that swaps a bio's blkg: it does the
blkg_put() without the NULL guard the old helper had.  Is there any path
where BFQ could see a bio that hasn't been associated yet (bi_blkg == NULL)?
The fallback branch calls it unconditionally, so if such a path exists it
would crash.  My reading is the bio is always associated before it reaches
BFQ, so it can't happen -- but wanted to ask in case I'm missing a path.

Thanks,
Tao

> Signed-off-by: Yu Kuai <yukuai@fygo.io>
> ---
>  block/bfq-cgroup.c | 16 +++++++++++++---
>  1 file changed, 13 insertions(+), 3 deletions(-)
> 
> diff --git a/block/bfq-cgroup.c b/block/bfq-cgroup.c
> index 42614aa78cd4..8a3ff9510386 100644
> --- a/block/bfq-cgroup.c
> +++ b/block/bfq-cgroup.c
> @@ -604,6 +604,16 @@ static void bfq_link_bfqg(struct bfq_data *bfqd, struct bfq_group *bfqg)
>  	}
>  }
>  
> +static void bfq_bio_update_blkg(struct bio *bio, struct blkcg_gq *blkg)
> +{
> +	if (bio->bi_blkg == blkg)
> +		return;
> +
> +	blkg_get(blkg);
> +	blkg_put(bio->bi_blkg);
> +	bio->bi_blkg = blkg;
> +}
> +
>  struct bfq_group *bfq_bio_bfqg(struct bfq_data *bfqd, struct bio *bio)
>  {
>  	struct blkcg_gq *blkg = bio->bi_blkg;
> @@ -616,13 +626,13 @@ struct bfq_group *bfq_bio_bfqg(struct bfq_data *bfqd, struct bio *bio)
>  		}
>  		bfqg = blkg_to_bfqg(blkg);
>  		if (bfqg->pd.online) {
> -			bio_associate_blkg_from_css(bio, &blkg->blkcg->css);
> +			bfq_bio_update_blkg(bio, blkg);
>  			return bfqg;
>  		}
>  		blkg = blkg->parent;
>  	}
> -	bio_associate_blkg_from_css(bio,
> -				&bfqg_to_blkg(bfqd->root_group)->blkcg->css);
> +	blkg = bfqg_to_blkg(bfqd->root_group);
> +	bfq_bio_update_blkg(bio, blkg);
>  	return bfqd->root_group;
>  }
>  


  reply	other threads:[~2026-07-29  7:34 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-24 12:30 [RFC PATCH v2 0/8] blk-cgroup: protect blkgs with blkcg_mutex Yu Kuai
2026-07-24 12:30 ` [RFC PATCH v2 1/8] block: associate blkg in submit_bio instead of bio_set_dev Yu Kuai
2026-07-27  8:16   ` yu kuai
2026-07-28  4:23     ` Christoph Hellwig
2026-07-29  8:28       ` yu kuai
2026-07-29  8:35         ` Christoph Hellwig
2026-07-29  8:05     ` Nilay Shroff
2026-07-29  9:49       ` yu kuai
2026-07-29  7:23   ` Tao Cui
2026-07-29  7:49     ` yu kuai
2026-07-24 12:30 ` [RFC PATCH v2 2/8] blk-throttle: protect throttle state with td lock Yu Kuai
2026-07-24 12:30 ` [RFC PATCH v2 3/8] blk-cgroup: protect blkgs with blkcg_mutex Yu Kuai
2026-07-29  7:29   ` Tao Cui
2026-07-29  7:54     ` yu kuai
2026-07-24 12:30 ` [RFC PATCH v2 4/8] blk-cgroup: remove blkg radix tree preloading Yu Kuai
2026-07-24 12:30 ` [RFC PATCH v2 5/8] blk-cgroup: allocate blkgs in blkg_create Yu Kuai
2026-07-24 12:30 ` [RFC PATCH v2 6/8] blk-cgroup: share blkg creation between lookup and config prep Yu Kuai
2026-07-24 12:30 ` [RFC PATCH v2 7/8] bfq: avoid blkg lookup from locked cgroup update Yu Kuai
2026-07-29  7:33   ` Tao Cui [this message]
2026-07-29  7:56     ` yu kuai
2026-07-24 12:30 ` [RFC PATCH v2 8/8] block: fail nowait bio submit if blkg allocation can't sleep Yu Kuai
2026-07-26  7:08 ` [syzbot ci] Re: blk-cgroup: protect blkgs with blkcg_mutex syzbot ci

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=45ea6216-a6f6-4828-afd3-8acea8b949ab@linux.dev \
    --to=cui.tao@linux.dev \
    --cc=axboe@kernel.dk \
    --cc=cengku@gmail.com \
    --cc=cgroups@vger.kernel.org \
    --cc=dongsheng.yang@linux.dev \
    --cc=hch@lst.de \
    --cc=josef@toxicpanda.com \
    --cc=linux-block@vger.kernel.org \
    --cc=ming.lei@redhat.com \
    --cc=nilay@linux.ibm.com \
    --cc=tj@kernel.org \
    --cc=yukuai@fygo.io \
    --cc=yukuai@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