From 126d62c72d6ee950be5b0191dd9b0a552f1ebff8 Mon Sep 17 00:00:00 2001 From: Baolin Wang Date: Tue, 22 Dec 2020 16:57:27 +0800 Subject: [PATCH 2481/2944] alinux: blk-throttle: Fix the possible NULL service tree warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix #31917731 Since commit 2397611ac802 ("blk-throttle: Move service tree validation out of the throtl_rb_first()") was merged, we assume all places will validate the service tree before calling throtl_rb_first(). However the tg_drain_bios() did not validate the parent_sq->nr_pending before calling throtl_rb_first(), which will cause below warnings: [Tue Dec 15 15:44:20 2020] WARNING: CPU: 60 PID: 84672 at block/blk-throttle.c:690 throtl_rb_first.isra.20+0x10/0x20 [Tue Dec 15 15:44:21 2020] Call Trace: [Tue Dec 15 15:44:21 2020]  tg_drain_bios+0x15/0x80 [Tue Dec 15 15:44:21 2020]  blk_throtl_drain+0x6e/0x120 [Tue Dec 15 15:44:21 2020]  __blk_drain_queue+0xec/0x1b0 [Tue Dec 15 15:44:21 2020]  blk_drain_queue+0x22/0x40 [Tue Dec 15 15:44:21 2020]  blk_freeze_queue+0x29/0x40 [Tue Dec 15 15:44:21 2020]  blk_cleanup_queue+0x7e/0x170 [Tue Dec 15 15:44:21 2020]  cleanup_mapped_device+0xca/0x100 [dm_mod] [Tue Dec 15 15:44:21 2020]  free_dev+0x3a/0xb0 [dm_mod] So we should validate the parent sevice tree's pending tg before calling throtl_rb_first() to shut down this warning. Note the blk_throtl_drain() and tg_drain_bios() had been removed in mainline kernel, so the original commit 2397611ac802 is correct against the mainline kernel. Fixes: 2397611ac802 ("blk-throttle: Move service tree validation out of the throtl_rb_first()") Signed-off-by: Baolin Wang Reviewed-by: Joseph Qi --- block/blk-throttle.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/blk-throttle.c b/block/blk-throttle.c index 9c1222c..1197b01 100644 --- a/block/blk-throttle.c +++ b/block/blk-throttle.c @@ -2541,7 +2541,7 @@ static void tg_drain_bios(struct throtl_service_queue *parent_sq) { struct throtl_grp *tg; - while ((tg = throtl_rb_first(parent_sq))) { + while (parent_sq->nr_pending && (tg = throtl_rb_first(parent_sq))) { struct throtl_service_queue *sq = &tg->service_queue; struct bio *bio; -- 1.8.3.1