public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 5.15/5.10 1/2] blk-cgroup: support to track if policy is online
@ 2025-04-17  7:33 bin.lan.cn
  2025-04-17  7:33 ` [PATCH 5.15/5.10 2/2] blk-iocost: do not WARN if iocg was already offlined bin.lan.cn
  2025-04-18 15:42 ` [PATCH 5.15/5.10 1/2] blk-cgroup: support to track if policy is online Sasha Levin
  0 siblings, 2 replies; 4+ messages in thread
From: bin.lan.cn @ 2025-04-17  7:33 UTC (permalink / raw)
  To: gregkh, stable; +Cc: hch, yukuai3, tj, bin.lan.cn, axboe

From: Yu Kuai <yukuai3@huawei.com>

[ Upstream commit dfd6200a095440b663099d8d42f1efb0175a1ce3 ]

A new field 'online' is added to blkg_policy_data to fix following
2 problem:

1) In blkcg_activate_policy(), if pd_alloc_fn() with 'GFP_NOWAIT'
   failed, 'queue_lock' will be dropped and pd_alloc_fn() will try again
   without 'GFP_NOWAIT'. In the meantime, remove cgroup can race with
   it, and pd_offline_fn() will be called without pd_init_fn() and
   pd_online_fn(). This way null-ptr-deference can be triggered.

2) In order to synchronize pd_free_fn() from blkg_free_workfn() and
   blkcg_deactivate_policy(), 'list_del_init(&blkg->q_node)' will be
   delayed to blkg_free_workfn(), hence pd_offline_fn() can be called
   first in blkg_destroy(), and then blkcg_deactivate_policy() will
   call it again, we must prevent it.

The new field 'online' will be set after pd_online_fn() and will be
cleared after pd_offline_fn(), in the meantime pd_offline_fn() will only
be called if 'online' is set.

Signed-off-by: Yu Kuai <yukuai3@huawei.com>
Acked-by: Tejun Heo <tj@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20230119110350.2287325-3-yukuai1@huaweicloud.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Bin Lan <bin.lan.cn@windriver.com>
Signed-off-by: He Zhe <zhe.he@windriver.com>
---
Build test passed.
---
 block/blk-cgroup.c         | 24 +++++++++++++++++-------
 include/linux/blk-cgroup.h |  1 +
 2 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index 6180c680136b..e372a3fc264e 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -192,6 +192,7 @@ static struct blkcg_gq *blkg_alloc(struct blkcg *blkcg, struct request_queue *q,
 		blkg->pd[i] = pd;
 		pd->blkg = blkg;
 		pd->plid = i;
+		pd->online = false;
 	}
 
 	return blkg;
@@ -289,8 +290,11 @@ static struct blkcg_gq *blkg_create(struct blkcg *blkcg,
 		for (i = 0; i < BLKCG_MAX_POLS; i++) {
 			struct blkcg_policy *pol = blkcg_policy[i];
 
-			if (blkg->pd[i] && pol->pd_online_fn)
-				pol->pd_online_fn(blkg->pd[i]);
+			if (blkg->pd[i]) {
+				if (pol->pd_online_fn)
+					pol->pd_online_fn(blkg->pd[i]);
+				blkg->pd[i]->online = true;
+			}
 		}
 	}
 	blkg->online = true;
@@ -390,8 +394,11 @@ static void blkg_destroy(struct blkcg_gq *blkg)
 	for (i = 0; i < BLKCG_MAX_POLS; i++) {
 		struct blkcg_policy *pol = blkcg_policy[i];
 
-		if (blkg->pd[i] && pol->pd_offline_fn)
-			pol->pd_offline_fn(blkg->pd[i]);
+		if (blkg->pd[i] && blkg->pd[i]->online) {
+			if (pol->pd_offline_fn)
+				pol->pd_offline_fn(blkg->pd[i]);
+			blkg->pd[i]->online = false;
+		}
 	}
 
 	blkg->online = false;
@@ -1367,6 +1374,7 @@ int blkcg_activate_policy(struct request_queue *q,
 		blkg->pd[pol->plid] = pd;
 		pd->blkg = blkg;
 		pd->plid = pol->plid;
+		pd->online = false;
 	}
 
 	/* all allocated, init in the same order */
@@ -1374,9 +1382,11 @@ int blkcg_activate_policy(struct request_queue *q,
 		list_for_each_entry_reverse(blkg, &q->blkg_list, q_node)
 			pol->pd_init_fn(blkg->pd[pol->plid]);
 
-	if (pol->pd_online_fn)
-		list_for_each_entry_reverse(blkg, &q->blkg_list, q_node)
+	list_for_each_entry_reverse(blkg, &q->blkg_list, q_node) {
+		if (pol->pd_online_fn)
 			pol->pd_online_fn(blkg->pd[pol->plid]);
+		blkg->pd[pol->plid]->online = true;
+	}
 
 	__set_bit(pol->plid, q->blkcg_pols);
 	ret = 0;
@@ -1438,7 +1448,7 @@ void blkcg_deactivate_policy(struct request_queue *q,
 
 		spin_lock(&blkcg->lock);
 		if (blkg->pd[pol->plid]) {
-			if (pol->pd_offline_fn)
+			if (blkg->pd[pol->plid]->online && pol->pd_offline_fn)
 				pol->pd_offline_fn(blkg->pd[pol->plid]);
 			pol->pd_free_fn(blkg->pd[pol->plid]);
 			blkg->pd[pol->plid] = NULL;
diff --git a/include/linux/blk-cgroup.h b/include/linux/blk-cgroup.h
index 27c363f6b281..c5eda86e4118 100644
--- a/include/linux/blk-cgroup.h
+++ b/include/linux/blk-cgroup.h
@@ -92,6 +92,7 @@ struct blkg_policy_data {
 	/* the blkg and policy id this per-policy data belongs to */
 	struct blkcg_gq			*blkg;
 	int				plid;
+	bool				online;
 };
 
 /*
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 5.15/5.10 2/2] blk-iocost: do not WARN if iocg was already offlined
  2025-04-17  7:33 [PATCH 5.15/5.10 1/2] blk-cgroup: support to track if policy is online bin.lan.cn
@ 2025-04-17  7:33 ` bin.lan.cn
  2025-04-18 15:57   ` Sasha Levin
  2025-04-18 15:42 ` [PATCH 5.15/5.10 1/2] blk-cgroup: support to track if policy is online Sasha Levin
  1 sibling, 1 reply; 4+ messages in thread
From: bin.lan.cn @ 2025-04-17  7:33 UTC (permalink / raw)
  To: gregkh, stable; +Cc: hch, yukuai3, tj, bin.lan.cn, axboe

From: Li Nan <linan122@huawei.com>

[ Upstream commit 01bc4fda9ea0a6b52f12326486f07a4910666cf6 ]

In iocg_pay_debt(), warn is triggered if 'active_list' is empty, which
is intended to confirm iocg is active when it has debt. However, warn
can be triggered during a blkcg or disk removal, if iocg_waitq_timer_fn()
is run 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

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 ensures
iocg is freed after iocg_waitq_timer_fn() returns.

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

Signed-off-by: Li Nan <linan122@huawei.com>
Reviewed-by: Yu Kuai <yukuai3@huawei.com>
Acked-by: Tejun Heo <tj@kernel.org>
Link: https://lore.kernel.org/r/20240419093257.3004211-1-linan666@huaweicloud.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Bin Lan <bin.lan.cn@windriver.com>
Signed-off-by: He Zhe <zhe.he@windriver.com>
---
Build test passed.
---
 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 ba23562abc80..08d397f063f3 100644
--- a/block/blk-iocost.c
+++ b/block/blk-iocost.c
@@ -1435,8 +1435,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.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 5.15/5.10 1/2] blk-cgroup: support to track if policy is online
  2025-04-17  7:33 [PATCH 5.15/5.10 1/2] blk-cgroup: support to track if policy is online bin.lan.cn
  2025-04-17  7:33 ` [PATCH 5.15/5.10 2/2] blk-iocost: do not WARN if iocg was already offlined bin.lan.cn
@ 2025-04-18 15:42 ` Sasha Levin
  1 sibling, 0 replies; 4+ messages in thread
From: Sasha Levin @ 2025-04-18 15:42 UTC (permalink / raw)
  To: stable; +Cc: bin.lan.cn, Sasha Levin

[ Sasha's backport helper bot ]

Hi,

✅ All tests passed successfully. No issues detected.
No action required from the submitter.

The upstream commit SHA1 provided is correct: dfd6200a095440b663099d8d42f1efb0175a1ce3

WARNING: Author mismatch between patch and upstream commit:
Backport author: bin.lan.cn@windriver.com
Commit author: Yu Kuai<yukuai3@huawei.com>

Status in newer kernel trees:
6.14.y | Present (exact SHA1)
6.13.y | Present (exact SHA1)
6.12.y | Present (exact SHA1)
6.6.y | Present (exact SHA1)
6.1.y | Not found
5.15.y | Not found

Note: The patch differs from the upstream commit:
---
1:  dfd6200a09544 ! 1:  d888a08386872 blk-cgroup: support to track if policy is online
    @@ Metadata
      ## Commit message ##
         blk-cgroup: support to track if policy is online
     
    +    [ Upstream commit dfd6200a095440b663099d8d42f1efb0175a1ce3 ]
    +
         A new field 'online' is added to blkg_policy_data to fix following
         2 problem:
     
    @@ Commit message
         Reviewed-by: Christoph Hellwig <hch@lst.de>
         Link: https://lore.kernel.org/r/20230119110350.2287325-3-yukuai1@huaweicloud.com
         Signed-off-by: Jens Axboe <axboe@kernel.dk>
    +    Signed-off-by: Bin Lan <bin.lan.cn@windriver.com>
    +    Signed-off-by: He Zhe <zhe.he@windriver.com>
     
      ## block/blk-cgroup.c ##
    -@@ block/blk-cgroup.c: static struct blkcg_gq *blkg_alloc(struct blkcg *blkcg, struct gendisk *disk,
    +@@ block/blk-cgroup.c: static struct blkcg_gq *blkg_alloc(struct blkcg *blkcg, struct request_queue *q,
      		blkg->pd[i] = pd;
      		pd->blkg = blkg;
      		pd->plid = i;
    @@ block/blk-cgroup.c: static struct blkcg_gq *blkg_alloc(struct blkcg *blkcg, stru
      	}
      
      	return blkg;
    -@@ block/blk-cgroup.c: static struct blkcg_gq *blkg_create(struct blkcg *blkcg, struct gendisk *disk,
    +@@ block/blk-cgroup.c: static struct blkcg_gq *blkg_create(struct blkcg *blkcg,
      		for (i = 0; i < BLKCG_MAX_POLS; i++) {
      			struct blkcg_policy *pol = blkcg_policy[i];
      
    @@ block/blk-cgroup.c: void blkcg_deactivate_policy(struct request_queue *q,
      			pol->pd_free_fn(blkg->pd[pol->plid]);
      			blkg->pd[pol->plid] = NULL;
     
    - ## block/blk-cgroup.h ##
    -@@ block/blk-cgroup.h: struct blkg_policy_data {
    + ## include/linux/blk-cgroup.h ##
    +@@ include/linux/blk-cgroup.h: struct blkg_policy_data {
      	/* the blkg and policy id this per-policy data belongs to */
      	struct blkcg_gq			*blkg;
      	int				plid;
---

Results of testing on various branches:

| Branch                    | Patch Apply | Build Test |
|---------------------------|-------------|------------|
| stable/linux-5.15.y       |  Success    |  Success   |

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 5.15/5.10 2/2] blk-iocost: do not WARN if iocg was already offlined
  2025-04-17  7:33 ` [PATCH 5.15/5.10 2/2] blk-iocost: do not WARN if iocg was already offlined bin.lan.cn
@ 2025-04-18 15:57   ` Sasha Levin
  0 siblings, 0 replies; 4+ messages in thread
From: Sasha Levin @ 2025-04-18 15:57 UTC (permalink / raw)
  To: stable; +Cc: bin.lan.cn, Sasha Levin

[ Sasha's backport helper bot ]

Hi,

✅ All tests passed successfully. No issues detected.
No action required from the submitter.

The upstream commit SHA1 provided is correct: 01bc4fda9ea0a6b52f12326486f07a4910666cf6

WARNING: Author mismatch between patch and upstream commit:
Backport author: bin.lan.cn@windriver.com
Commit author: Li Nan<linan122@huawei.com>

Status in newer kernel trees:
6.14.y | Present (exact SHA1)
6.13.y | Present (exact SHA1)
6.12.y | Present (exact SHA1)
6.6.y | Present (different SHA1: 1c172ac7afe4)
6.1.y | Present (different SHA1: 2e962785b508)
5.15.y | Not found

Note: The patch differs from the upstream commit:
---
1:  01bc4fda9ea0a ! 1:  62b4e00c59eb3 blk-iocost: do not WARN if iocg was already offlined
    @@ Metadata
      ## Commit message ##
         blk-iocost: do not WARN if iocg was already offlined
     
    +    [ Upstream commit 01bc4fda9ea0a6b52f12326486f07a4910666cf6 ]
    +
         In iocg_pay_debt(), warn is triggered if 'active_list' is empty, which
         is intended to confirm iocg is active when it has debt. However, warn
         can be triggered during a blkcg or disk removal, if iocg_waitq_timer_fn()
    @@ Commit message
         Acked-by: Tejun Heo <tj@kernel.org>
         Link: https://lore.kernel.org/r/20240419093257.3004211-1-linan666@huaweicloud.com
         Signed-off-by: Jens Axboe <axboe@kernel.dk>
    +    Signed-off-by: Bin Lan <bin.lan.cn@windriver.com>
    +    Signed-off-by: He Zhe <zhe.he@windriver.com>
     
      ## block/blk-iocost.c ##
     @@ block/blk-iocost.c: static void iocg_pay_debt(struct ioc_gq *iocg, u64 abs_vpay,
---

Results of testing on various branches:

| Branch                    | Patch Apply | Build Test |
|---------------------------|-------------|------------|
| stable/linux-5.15.y       |  Success    |  Success   |

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-04-18 15:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-17  7:33 [PATCH 5.15/5.10 1/2] blk-cgroup: support to track if policy is online bin.lan.cn
2025-04-17  7:33 ` [PATCH 5.15/5.10 2/2] blk-iocost: do not WARN if iocg was already offlined bin.lan.cn
2025-04-18 15:57   ` Sasha Levin
2025-04-18 15:42 ` [PATCH 5.15/5.10 1/2] blk-cgroup: support to track if policy is online Sasha Levin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox