Re: [PATCH v2 1/3] blk-cgroup: fix race between policy activation and blkg destruction

From: Zheng Qixing

Date: Thu Jan 15 2026 - 00:44:22 EST


diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index 3cffb68ba5d8..600f8c5843ea 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -1596,6 +1596,8 @@ int blkcg_activate_policy(struct gendisk *disk, const struct blkcg_policy *pol)
if (queue_is_mq(q))
memflags = blk_mq_freeze_queue(q);
+
+ mutex_lock(&q->blkcg_mutex);
retry:
spin_lock_irq(&q->queue_lock);
@@ -1658,6 +1660,7 @@ int blkcg_activate_policy(struct gendisk *disk, const struct blkcg_policy *pol)
spin_unlock_irq(&q->queue_lock);
out:
+ mutex_unlock(&q->blkcg_mutex);
if (queue_is_mq(q))
blk_mq_unfreeze_queue(q, memflags);
if (pinned_blkg)
Can you also protect blkg_destroy_all() will blkcg_mutex as well? Then all access for q->blkg_list will
be protected.
Why does blkg_destroy_all() also need blkcg_mutex?

After finishing ->pd_offline_fn() for blkgs and scheduling blkg_free_workfn() in blkg_destroy(),
blkg_destroy_all() clears the corresponding policy bit in q->blkcg_pols to avoid duplicate policy
teardown in blkcg_deactivate_policy().