Skip to contentSkip to conversation

blk-cgroup: three small fixes

PATCH Applied Ming Lei 3 participants 7 messages Nov 17, 2023 – Nov 20, 2023

Subsystems (2)
lore
Share & tools
lore

Ming Lei

author
#0 lore raw

cover blk-cgroup: three small fixes

Hello,

The first 2 fixes lockdep warnings.

The last one tries to deactivate policy after blkgs are destroyed.

Ming Lei (3):
blk-throttle: fix lockdep warning of "cgroup_mutex or RCU read lock
required!"
blk-cgroup: avoid to warn !rcu_read_lock_held() in blkg_lookup()
blk-cgroup: bypass blkcg_deactivate_policy after destroying

 block/blk-cgroup.c   | 13 +++++++++++++
 block/blk-cgroup.h   |  2 --
 block/blk-throttle.c |  2 ++
 3 files changed, 15 insertions(+), 2 deletions(-)
Signature · 1 line
2.41.0
author
#1 lore raw

PATCH 1/3 blk-throttle: fix lockdep warning of "cgroup_mutex or RCU read lock required!"

Inside blkg_for_each_descendant_pre(), both css_for_each_descendant_pre() and blkg_lookup() requires RCU read lock, and either cgroup_assert_mutex_or_rcu_locked() or rcu_read_lock_held() is called.

Fix the warning by adding rcu read lock.

---
 block/blk-throttle.c | 2 ++
 1 file changed, 2 insertions(+)
block/blk-throttle.c +2 -0
index 38a881cf97d0..050f8ac6fcb1 100644
@@ -1314,6 +1314,7 @@ static void tg_conf_updated(struct throtl_grp *tg, bool global)
 		   tg_bps_limit(tg, READ), tg_bps_limit(tg, WRITE),
 		   tg_iops_limit(tg, READ), tg_iops_limit(tg, WRITE));
 
+	rcu_read_lock();
 	/*
 	 * Update has_rules[] flags for the updated tg's subtree.  A tg is
 	 * considered to have rules if either the tg itself or any of its
@@ -1341,6 +1342,7 @@ static void tg_conf_updated(struct throtl_grp *tg, bool global)
 		this_tg->latency_target = max(this_tg->latency_target,
 				parent_tg->latency_target);
 	}
+	rcu_read_unlock();
 
 	/*
 	 * We're already holding queue_lock and know @tg is valid.  Let's
Signature · 1 line
2.41.0
author
#2 lore raw

PATCH 2/3 blk-cgroup: avoid to warn !rcu_read_lock_held() in blkg_lookup()

In reply to Ming Lei

So far, all callers either holds spin lock or rcu read explicitly, and most of the caller has added WARN_ON_ONCE(!rcu_read_lock_held()) or lockdep_assert_held(&disk->queue->queue_lock).

Remove WARN_ON_ONCE(!rcu_read_lock_held()) from blkg_lookup() for killing the false positive warning from blkg_conf_prep().

Fixes 83462a6c971c ("blkcg: Drop unnecessary RCU read [un]locks from blkg_conf_prep/finish()")
---
 block/blk-cgroup.h | 2 --
 1 file changed, 2 deletions(-)
block/blk-cgroup.h +0 -2
index 624c03c8fe64..fd482439afbc 100644
@@ -249,8 +249,6 @@ static inline struct blkcg_gq *blkg_lookup(struct blkcg *blkcg,
 {
 	struct blkcg_gq *blkg;
 
-	WARN_ON_ONCE(!rcu_read_lock_held());
-
 	if (blkcg == &blkcg_root)
 		return q->root_blkg;
 
Signature · 1 line
2.41.0
author
#3 lore raw

PATCH 3/3 blk-cgroup: bypass blkcg_deactivate_policy after destroying

In reply to Ming Lei

blkcg_deactivate_policy() can be called after blkg_destroy_all() returns, and it isn't necessary since blkg_destroy_all has covered policy deactivation.

---
 block/blk-cgroup.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
block/blk-cgroup.c +13 -0
index 4a42ea2972ad..4b48c2c44098 100644
@@ -577,6 +577,7 @@ static void blkg_destroy_all(struct gendisk *disk)
 	struct request_queue *q = disk->queue;
 	struct blkcg_gq *blkg, *n;
 	int count = BLKG_DESTROY_BATCH_SIZE;
+	int i;
 
 restart:
 	spin_lock_irq(&q->queue_lock);
@@ -602,6 +603,18 @@ static void blkg_destroy_all(struct gendisk *disk)
 		}
 	}
 
+	/*
+	 * Mark policy deactivated since policy offline has been done, and
+	 * the free is scheduled, so future blkcg_deactivate_policy() can
+	 * be bypassed
+	 */
+	for (i = 0; i < BLKCG_MAX_POLS; i++) {
+		struct blkcg_policy *pol = blkcg_policy[i];
+
+		if (pol)
+			__clear_bit(pol->plid, q->blkcg_pols);
+	}
+
 	q->root_blkg = NULL;
 	spin_unlock_irq(&q->queue_lock);
 }
Signature · 1 line
2.41.0
maintainer
#4 lore raw

Re: [PATCH 3/3] blk-cgroup: bypass blkcg_deactivate_policy after destroying

Hello, Ming.

Quoted 3 lines · Ming Lei

blkcg_deactivate_policy() can be called after blkg_destroy_all() returns, and it isn't necessary since blkg_destroy_all has covered policy deactivation.

Does this actually affect anything? This would matter iff a policy is deactivated for the queue between blkg_destroy_all() and the rest of the queue destruction, right? That's a really small window against very rare operations. The patch is already in and I'm not necessarily against the change but I'm curious what the motivation is.

Thanks.

Signature · 1 line
tejun
author
#5 lore raw

Re: [PATCH 3/3] blk-cgroup: bypass blkcg_deactivate_policy after destroying

Quoted 10 lines · Tejun Heo

Hello, Ming.

Quoted 3 lines · Ming Lei

blkcg_deactivate_policy() can be called after blkg_destroy_all() returns, and it isn't necessary since blkg_destroy_all has covered policy deactivation.

Does this actually affect anything? This would matter iff a policy is deactivated for the queue between blkg_destroy_all() and the rest of the queue destruction, right?

Yeah, it is true actually for throttle code.

thanks,
Ming

maintainer Applied
#6 lore raw
In reply to Ming Lei
Quoted 5 lines · Ming Lei

The first 2 fixes lockdep warnings.

The last one tries to deactivate policy after blkgs are destroyed.

Quoted 7 lines

Ming Lei (3):
blk-throttle: fix lockdep warning of "cgroup_mutex or RCU read lock
required!"
blk-cgroup: avoid to warn !rcu_read_lock_held() in blkg_lookup()
blk-cgroup: bypass blkcg_deactivate_policy after destroying

[...]

Applied, thanks!

[1/3] blk-throttle: fix lockdep warning of "cgroup_mutex or RCU read lock required!"

      commit: 27b13e209ddca5979847a1b57890e0372c1edcee
[2/3] blk-cgroup: avoid to warn !rcu_read_lock_held() in blkg_lookup()
      commit: 35a99d6557cacbc177314735342f77a2dda41872
[3/3] blk-cgroup: bypass blkcg_deactivate_policy after destroying
      commit: e63a57303599b17290cd8bc48e6f20b24289a8bc

Best regards,

Signature · 1 line
Jens Axboe