blk-cgroup: clear blkg->pd[] with WRITE_ONCE() in blkcg_deactivate_policy()
Subsystems (3)
PATCH 1/1 blk-cgroup: clear blkg->pd[] with WRITE_ONCE() in blkcg_deactivate_policy()
From: Guopeng Zhang <[email protected]>
blkcg_activate_policy() installs blkg->pd[] entries with WRITE_ONCE() and also uses WRITE_ONCE() when clearing them on its error path. blkg_to_pd() is used by RCU readers and reads the same array with READ_ONCE().
blkcg_deactivate_policy() clears the entry with a plain store. Use WRITE_ONCE() there as well.
--- block/blk-cgroup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/blk-cgroup.c +1 -1
@@ -1691,7 +1691,7 @@ void blkcg_deactivate_policy(struct gendisk *disk,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 ; +WRITE_ONCE (blkg->pd[pol->plid],NULL ); }spin_unlock (&blkcg->lock); }
Signature · 1 line
2.43.0
Quoted 21 lines · Guopeng Zhang
From: Guopeng Zhang <[email protected]>
blkcg_activate_policy()installs blkg->pd[] entries withWRITE_ONCE()and also usesWRITE_ONCE()when clearing them on its error path.blkg_to_pd()is used by RCU readers and reads the same array withREAD_ONCE().
blkcg_deactivate_policy()clears the entry with a plain store. UseWRITE_ONCE()there as well.Fixes 56cc24f59c14 ("blk-cgroup: don't nest queue_lock under rcu in blkcg_print_blkgs()")Signed-off-by Guopeng Zhang <[email protected]>--- block/blk-cgroup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)block/blk-cgroup.c +0
-0
block/blk-cgroup.c void blkcg_deactivate_policy(struct gendisk *disk, · line 1697
Quoted 8 lines
block/blk-cgroup.c +1
-1@@ -1691,7 +1691,7 @@ void blkcg_deactivate_policy(struct gendisk *disk,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 ; +WRITE_ONCE (blkg->pd[pol->plid],NULL ); }spin_unlock (&blkcg->lock); }
FYI, this WRITE_ONCE() change is also in Yu Kuai's in-flight series that factors the pd teardown loop into a helper:
https://lore.kernel.org/all/[email protected]/
That series isn't merged yet (v3, 2026-06-25), so this minimal Fixes patch is still useful in the meantime -- just flagging the overlap.
Quoted 35 lines · Tao Cui
Quoted 21 lines · Guopeng Zhang
From: Guopeng Zhang <[email protected]>
blkcg_activate_policy()installs blkg->pd[] entries withWRITE_ONCE()and also usesWRITE_ONCE()when clearing them on its error path.blkg_to_pd()is used by RCU readers and reads the same array withREAD_ONCE().
blkcg_deactivate_policy()clears the entry with a plain store. UseWRITE_ONCE()there as well.Fixes 56cc24f59c14 ("blk-cgroup: don't nest queue_lock under rcu in blkcg_print_blkgs()")Signed-off-by Guopeng Zhang <[email protected]>--- block/blk-cgroup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)block/blk-cgroup.c +0
-0block/blk-cgroup.c void blkcg_deactivate_policy(struct gendisk *disk, · line 1697
Quoted 8 lines
block/blk-cgroup.c +1
-1@@ -1691,7 +1691,7 @@ void blkcg_deactivate_policy(struct gendisk *disk,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 ; +WRITE_ONCE (blkg->pd[pol->plid],NULL ); }spin_unlock (&blkcg->lock); }Reviewed-by Tao Cui <[email protected]>
Quoted 8 lines · Tao Cui
FYI, this
WRITE_ONCE()change is also in Yu Kuai's in-flight series that factors the pd teardown loop into a helper:https://lore.kernel.org/all/[email protected]/
That series isn't merged yet (v3, 2026-06-25), so this minimal Fixes patch is still useful in the meantime -- just flagging the overlap.
hello,
Thanks for the review, and thanks for pointing out the overlap.
If Yu's series gets merged first, this patch can simply be dropped.
Thanks,
Guopeng
Quoted 37 lines · Tao Cui
Quoted 35 lines · Guopeng Zhang
Quoted 21 lines
From: Guopeng Zhang <[email protected]>
blkcg_activate_policy()installs blkg->pd[] entries withWRITE_ONCE()and also usesWRITE_ONCE()when clearing them on its error path.blkg_to_pd()is used by RCU readers and reads the same array withREAD_ONCE().
blkcg_deactivate_policy()clears the entry with a plain store. UseWRITE_ONCE()there as well.Fixes 56cc24f59c14 ("blk-cgroup: don't nest queue_lock under rcu in blkcg_print_blkgs()")Signed-off-by Guopeng Zhang <[email protected]>--- block/blk-cgroup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)block/blk-cgroup.c +0
-0block/blk-cgroup.c void blkcg_deactivate_policy(struct gendisk *disk, · line 1697
Quoted 8 lines
block/blk-cgroup.c +1
-1@@ -1691,7 +1691,7 @@ void blkcg_deactivate_policy(struct gendisk *disk,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 ; +WRITE_ONCE (blkg->pd[pol->plid],NULL ); }spin_unlock (&blkcg->lock); }Reviewed-by Tao Cui <[email protected]>