mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Han Guangjiang <gj.han@foxmail.com>
To: yukuai1@huaweicloud.com, Jens Axboe <axboe@kernel.dk>,
	linux-block@vger.kernel.org (open list:BLOCK LAYER),
	linux-kernel@vger.kernel.org (open list)
Cc: hanguangjiang@lixiang.com, fanggeng@lixiang.com,
	yangchen11@lixiang.com, liangjie@lixiang.com
Subject: [PATCH v2] blk-throttle: fix access race during throttle policy activation
Date: Thu,  4 Sep 2025 16:17:26 +0800	[thread overview]
Message-ID: <tencent_2B678DA920124B08854638A6BE68746CCC05@qq.com> (raw)
In-Reply-To: <59464ad0-856c-4ec3-b5b7-e7799c337a84@yukuai.org.cn>

From: Han Guangjiang <hanguangjiang@lixiang.com>

On repeated cold boots we occasionally hit a NULL pointer crash in
blk_should_throtl() when throttling is consulted before the throttle
policy is fully enabled for the queue. Checking only q->td != NULL is
insufficient during early initialization, so blkg_to_pd() for the
throttle policy can still return NULL and blkg_to_tg() becomes NULL,
which later gets dereferenced.

 Unable to handle kernel NULL pointer dereference
 at virtual address 0000000000000156
 ...
 pc : submit_bio_noacct+0x14c/0x4c8
 lr : submit_bio_noacct+0x48/0x4c8
 sp : ffff800087f0b690
 x29: ffff800087f0b690 x28: 0000000000005f90 x27: ffff00068af393c0
 x26: 0000000000080000 x25: 000000000002fbc0 x24: ffff000684ddcc70
 x23: 0000000000000000 x22: 0000000000000000 x21: 0000000000000000
 x20: 0000000000080000 x19: ffff000684ddcd08 x18: ffffffffffffffff
 x17: 0000000000000000 x16: ffff80008132a550 x15: 0000ffff98020fff
 x14: 0000000000000000 x13: 1fffe000d11d7021 x12: ffff000688eb810c
 x11: ffff00077ec4bb80 x10: ffff000688dcb720 x9 : ffff80008068ef60
 x8 : 00000a6fb8a86e85 x7 : 000000000000111e x6 : 0000000000000002
 x5 : 0000000000000246 x4 : 0000000000015cff x3 : 0000000000394500
 x2 : ffff000682e35e40 x1 : 0000000000364940 x0 : 000000000000001a
 Call trace:
  submit_bio_noacct+0x14c/0x4c8
  verity_map+0x178/0x2c8
  __map_bio+0x228/0x250
  dm_submit_bio+0x1c4/0x678
  __submit_bio+0x170/0x230
  submit_bio_noacct_nocheck+0x16c/0x388
  submit_bio_noacct+0x16c/0x4c8
  submit_bio+0xb4/0x210
  f2fs_submit_read_bio+0x4c/0xf0
  f2fs_mpage_readpages+0x3b0/0x5f0
  f2fs_readahead+0x90/0xe8

Tighten blk_throtl_activated() to also require that the throttle policy
bit is set on the queue:

  return q->td != NULL &&
         test_bit(blkcg_policy_throtl.plid, q->blkcg_pols);

This prevents blk_should_throtl() from accessing throttle group state
until policy data has been attached to blkgs.

Fixes: a3166c51702b ("blk-throttle: delay initialization until configuration")
Co-developed-by: Liang Jie <liangjie@lixiang.com>
Signed-off-by: Liang Jie <liangjie@lixiang.com>
Signed-off-by: Han Guangjiang <hanguangjiang@lixiang.com>
---
v2:
 - remove the comment about freeze queue in blk_should_throtl()
 - Retitle: "blk-throttle: fix access race during throttle policy activation"
---
 block/blk-throttle.h | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/block/blk-throttle.h b/block/blk-throttle.h
index 3b27755bfbff..fbf97c531c48 100644
--- a/block/blk-throttle.h
+++ b/block/blk-throttle.h
@@ -156,7 +156,7 @@ void blk_throtl_cancel_bios(struct gendisk *disk);
 
 static inline bool blk_throtl_activated(struct request_queue *q)
 {
-	return q->td != NULL;
+	return q->td != NULL && test_bit(blkcg_policy_throtl.plid, q->blkcg_pols);
 }
 
 static inline bool blk_should_throtl(struct bio *bio)
@@ -164,11 +164,6 @@ static inline bool blk_should_throtl(struct bio *bio)
 	struct throtl_grp *tg;
 	int rw = bio_data_dir(bio);
 
-	/*
-	 * This is called under bio_queue_enter(), and it's synchronized with
-	 * the activation of blk-throtl, which is protected by
-	 * blk_mq_freeze_queue().
-	 */
 	if (!blk_throtl_activated(bio->bi_bdev->bd_queue))
 		return false;
 
-- 
2.25.1


  parent reply	other threads:[~2025-09-04  8:17 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-02 12:39 [PATCH] blk-throttle: check policy bit in blk_throtl_activated() gj.han
2025-09-02 17:06 ` Yu Kuai
2025-09-03  2:55   ` Han Guangjiang
2025-09-03  6:03     ` Yu Kuai
2025-09-03  7:21       ` Liang Jie
2025-09-03  8:24         ` Yu Kuai
2025-09-04  8:23           ` Han Guangjiang
2025-09-04  8:17   ` Han Guangjiang [this message]
2025-09-04  9:18     ` [PATCH v2] blk-throttle: fix access race during throttle policy activation Yu Kuai
2025-09-04 10:05       ` [PATCH] blk-throttle: check policy bit in blk_throtl_activated() Han Guangjiang
2025-09-04 10:59         ` Yu Kuai
2025-09-05  6:53       ` Han Guangjiang
2025-09-05  7:19         ` Yu Kuai
2025-09-04  8:19   ` Han Guangjiang

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=tencent_2B678DA920124B08854638A6BE68746CCC05@qq.com \
    --to=gj.han@foxmail.com \
    --cc=axboe@kernel.dk \
    --cc=fanggeng@lixiang.com \
    --cc=hanguangjiang@lixiang.com \
    --cc=liangjie@lixiang.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=yangchen11@lixiang.com \
    --cc=yukuai1@huaweicloud.com \
    /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

all inboxes | Powered by JetHome®