Thread (11 messages) flat view 11 messages, 4 authors, 2d ago

Re: [PATCH v2 2/3] blk-cgroup: store blkcg in bio instead of blkg

From: "yu kuai" <yukuai@fygo.io>
Date: 2026-09-15 15:43:56
Also in: cgroups, dm-devel, gfs2, linux-bcache, linux-block, linux-fsdevel, linux-mm, linux-raid, lkml, llvm

Hi,

在 2026/9/15 14:49, Christoph Hellwig 写道:
On Sun, Sep 13, 2026 at 02:54:39PM +0800, Yu Kuai wrote:
quoted
@@ -6243,10 +6245,17 @@ static void bfq_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq,
  	bool idle_timer_disabled = false;
  	blk_opf_t cmd_flags;
  	LIST_HEAD(free);
  
  #ifdef CONFIG_BFQ_GROUP_IOSCHED
+	/*
+	 * Pin the blkg used to look up bfqg.  If this is the first IO for
+	 * the blkcg on this queue, create the bfqg before holding bfqd->lock.
+	 */
+	if (rq->bio && !bio_flagged(rq->bio, BIO_BLKG_REF))
+		bio_blkg(rq->bio);
Can rq->bio be NULL here?  flush or empty passthrough request should
never enter the scheuler.
Yes, rq->bio should never be NULL.
quoted
  	if (!cgroup_subsys_on_dfl(io_cgrp_subsys) && rq->bio)
  		bfqg_stats_update_legacy_io(q, rq);
But I guess given that the code below checks it, we should at least
be consistent, so I guess it is better to keep it for now.
quoted
  
  static inline void dm_bio_record(struct dm_bio_details *bd, struct bio *bio)
  {
  	bd->bi_bdev = bio->bi_bdev;
-	bd->bi_flags = bio->bi_flags;
+	/* Restoring an ownership bit cannot recreate the associated reference. */
+	bd->bi_flags = bio->bi_flags & ~(1U << BIO_BLKG_REF);
I have a bit of a hard time parsing this, the line also is overly
long.
This is an issue found by AI, if the new flag is recorded to bi_flags, and the flag can be
restored to new bio by dm_bio_restore() without actually acquire a blkg reference. And I
checked this is the only place to read/write bi_flags directly in driver.

-- 
Thanks,
Kuai
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help