[PATCH v2] blk-iocost: do not WARNING if iocg has already offlined

From: linan666
Date: Fri Apr 19 2024 - 05:42:22 EST


From: Li Nan <linan122@xxxxxxxxxx>

In iocg_pay_debt(), warn is triggered if 'active_list' is empty, which
is intended to confirm iocg is avitve when it has debt. However, warn
can be triggered during a blkcg or disk is being removed, as
iocg_waitq_timer_fn() is awakened at that time.

WARNING: CPU: 0 PID: 2344971 at block/blk-iocost.c:1402 iocg_pay_debt+0x14c/0x190
Call trace:
iocg_pay_debt+0x14c/0x190
iocg_kick_waitq+0x438/0x4c0
iocg_waitq_timer_fn+0xd8/0x130
__run_hrtimer+0x144/0x45c
__hrtimer_run_queues+0x16c/0x244
hrtimer_interrupt+0x2cc/0x7b0
ps: This issue was got in linux 5.10, but it also exists in the mainline.

The warn in this situation is meaningless. Since this iocg is being
removed, the state of the 'active_list' is irrelevant, and 'waitq_timer'
is canceled after removing 'active_list' in ioc_pd_free(), which ensure
iocg is freed after iocg_waitq_timer_fn() returns.

Therefore, add the check if iocg has already offlined to avoid warn
when removing a blkcg or disk.

Signed-off-by: Li Nan <linan122@xxxxxxxxxx>
Reviewed-by: Yu Kuai <yukuai3@xxxxxxxxxx>
Acked-by: Tejun Heo <tj@xxxxxxxxxx>
---
v2:
- Indicate in the message that there is also an issue with deleting
the disk.
- add comment for check pd.online.

block/blk-iocost.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/block/blk-iocost.c b/block/blk-iocost.c
index baa20c85799d..690ca99dfaca 100644
--- a/block/blk-iocost.c
+++ b/block/blk-iocost.c
@@ -1439,8 +1439,11 @@ static void iocg_pay_debt(struct ioc_gq *iocg, u64 abs_vpay,
lockdep_assert_held(&iocg->ioc->lock);
lockdep_assert_held(&iocg->waitq.lock);

- /* make sure that nobody messed with @iocg */
- WARN_ON_ONCE(list_empty(&iocg->active_list));
+ /*
+ * make sure that nobody messed with @iocg. Check iocg->pd.online
+ * to avoid warn when removing blkcg or disk.
+ */
+ WARN_ON_ONCE(list_empty(&iocg->active_list) && iocg->pd.online);
WARN_ON_ONCE(iocg->inuse > 1);

iocg->abs_vdebt -= min(abs_vpay, iocg->abs_vdebt);
--
2.39.2