Linux block layer
 help / color / mirror / Atom feed
* [PATCH] blk-cgroup: clear blkg->pd[] with WRITE_ONCE() in blkcg_deactivate_policy()
@ 2026-07-07 12:58 Guopeng Zhang
  2026-07-08  5:10 ` Tao Cui
  0 siblings, 1 reply; 4+ messages in thread
From: Guopeng Zhang @ 2026-07-07 12:58 UTC (permalink / raw)
  To: Tejun Heo, Josef Bacik, Jens Axboe
  Cc: Yu Kuai, cgroups, linux-block, linux-kernel, Guopeng Zhang,
	Guopeng Zhang

From: Guopeng Zhang <zhangguopeng@kylinos.cn>

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.

Fixes: 56cc24f59c14 ("blk-cgroup: don't nest queue_lock under rcu in blkcg_print_blkgs()")
Signed-off-by: Guopeng Zhang <zhangguopeng@kylinos.cn>
---
 block/blk-cgroup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index d2a1f5903f24..a1dd69f99f5c 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -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);
 	}
-- 
2.43.0


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

* Re: [PATCH] blk-cgroup: clear blkg->pd[] with WRITE_ONCE() in blkcg_deactivate_policy()
  2026-07-07 12:58 [PATCH] blk-cgroup: clear blkg->pd[] with WRITE_ONCE() in blkcg_deactivate_policy() Guopeng Zhang
@ 2026-07-08  5:10 ` Tao Cui
  2026-07-08  5:29   ` Tao Cui
  0 siblings, 1 reply; 4+ messages in thread
From: Tao Cui @ 2026-07-08  5:10 UTC (permalink / raw)
  To: Guopeng Zhang, Tejun Heo, Josef Bacik, Jens Axboe
  Cc: cui.tao, Yu Kuai, cgroups, linux-block, linux-kernel,
	Guopeng Zhang



在 2026/7/7 20:58, Guopeng Zhang 写道:
> From: Guopeng Zhang <zhangguopeng@kylinos.cn>
> 
> 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.
> 
> Fixes: 56cc24f59c14 ("blk-cgroup: don't nest queue_lock under rcu in blkcg_print_blkgs()")
> Signed-off-by: Guopeng Zhang <zhangguopeng@kylinos.cn>
> ---
>  block/blk-cgroup.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
> index d2a1f5903f24..a1dd69f99f5c 100644
> --- a/block/blk-cgroup.c
> +++ b/block/blk-cgroup.c
> @@ -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 <cuitao@kylinos.cn>


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

* Re: [PATCH] blk-cgroup: clear blkg->pd[] with WRITE_ONCE() in blkcg_deactivate_policy()
  2026-07-08  5:10 ` Tao Cui
@ 2026-07-08  5:29   ` Tao Cui
  2026-07-08  5:59     ` Guopeng Zhang
  0 siblings, 1 reply; 4+ messages in thread
From: Tao Cui @ 2026-07-08  5:29 UTC (permalink / raw)
  To: Guopeng Zhang, Tejun Heo, Josef Bacik, Jens Axboe
  Cc: cui.tao, Yu Kuai, cgroups, linux-block, linux-kernel,
	Guopeng Zhang

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/20260625025739.2459651-5-yukuai@kernel.org/

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.

在 2026/7/8 13:10, Tao Cui 写道:
> 
> 
> 在 2026/7/7 20:58, Guopeng Zhang 写道:
>> From: Guopeng Zhang <zhangguopeng@kylinos.cn>
>>
>> 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.
>>
>> Fixes: 56cc24f59c14 ("blk-cgroup: don't nest queue_lock under rcu in blkcg_print_blkgs()")
>> Signed-off-by: Guopeng Zhang <zhangguopeng@kylinos.cn>
>> ---
>>  block/blk-cgroup.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
>> index d2a1f5903f24..a1dd69f99f5c 100644
>> --- a/block/blk-cgroup.c
>> +++ b/block/blk-cgroup.c
>> @@ -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 <cuitao@kylinos.cn>
> 


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

* Re: [PATCH] blk-cgroup: clear blkg->pd[] with WRITE_ONCE() in blkcg_deactivate_policy()
  2026-07-08  5:29   ` Tao Cui
@ 2026-07-08  5:59     ` Guopeng Zhang
  0 siblings, 0 replies; 4+ messages in thread
From: Guopeng Zhang @ 2026-07-08  5:59 UTC (permalink / raw)
  To: Tao Cui, Tejun Heo, Josef Bacik, Jens Axboe
  Cc: Yu Kuai, cgroups, linux-block, linux-kernel, Guopeng Zhang



在 2026/7/8 13:29, 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/20260625025739.2459651-5-yukuai@kernel.org/
> 
> 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
> 在 2026/7/8 13:10, Tao Cui 写道:
>>
>>
>> 在 2026/7/7 20:58, Guopeng Zhang 写道:
>>> From: Guopeng Zhang <zhangguopeng@kylinos.cn>
>>>
>>> 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.
>>>
>>> Fixes: 56cc24f59c14 ("blk-cgroup: don't nest queue_lock under rcu in blkcg_print_blkgs()")
>>> Signed-off-by: Guopeng Zhang <zhangguopeng@kylinos.cn>
>>> ---
>>>  block/blk-cgroup.c | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
>>> index d2a1f5903f24..a1dd69f99f5c 100644
>>> --- a/block/blk-cgroup.c
>>> +++ b/block/blk-cgroup.c
>>> @@ -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 <cuitao@kylinos.cn>
>>
> 


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

end of thread, other threads:[~2026-07-08  6:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-07 12:58 [PATCH] blk-cgroup: clear blkg->pd[] with WRITE_ONCE() in blkcg_deactivate_policy() Guopeng Zhang
2026-07-08  5:10 ` Tao Cui
2026-07-08  5:29   ` Tao Cui
2026-07-08  5:59     ` Guopeng Zhang

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