The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH v2] block/blk-cgroup-rwstat: use data_race() for online test
@ 2026-08-03 13:34 Tao Cui
  2026-08-03 16:47 ` Tejun Heo
  2026-08-04  2:17 ` Jens Axboe
  0 siblings, 2 replies; 3+ messages in thread
From: Tao Cui @ 2026-08-03 13:34 UTC (permalink / raw)
  To: axboe
  Cc: tj, josef, yukuai, cgroups, linux-block, linux-kernel, cui.tao,
	Tao Cui

From: Tao Cui <cuitao@kylinos.cn>

blkg_rwstat_recursive_sum() reads pos_blkg->online without the queue
lock that its doc comment requires, since blkcg_print_blkgs() stopped
holding it in 56cc24f59c14.  Concurrent blkg_create/destroy flips
->online, tripping KCSAN.  The race is harmless (RCU-protected, stale
online only causes minor stat noise).  Use data_race() to annotate
the intentional lockless read.

Also update the stale doc comment that still requires the queue lock.

Reviewed-by: Yu Kuai <yukuai@fygo.io>
Signed-off-by: Tao Cui <cuitao@kylinos.cn>

---

Changes in v2:
- Update the stale kernel-doc comment that still mandates the queue lock.

Link: https://lore.kernel.org/all/20260802150413.29789-1-cui.tao@linux.dev/
---
 block/blk-cgroup-rwstat.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/block/blk-cgroup-rwstat.c b/block/blk-cgroup-rwstat.c
index aae910713814..2e9bf081cce2 100644
--- a/block/blk-cgroup-rwstat.c
+++ b/block/blk-cgroup-rwstat.c
@@ -88,8 +88,7 @@ EXPORT_SYMBOL_GPL(blkg_prfill_rwstat);
  * @sum: blkg_rwstat_sample structure containing the results
  *
  * Collect the blkg_rwstat specified by @blkg, @pol and @off and all its
- * online descendants and their aux counts.  The caller must be holding the
- * queue lock for online tests.
+ * online descendants and their aux counts.
  *
  * If @pol is NULL, blkg_rwstat is at @off bytes into @blkg; otherwise, it
  * is at @off bytes into @blkg's blkg_policy_data of the policy.
@@ -107,7 +106,7 @@ void blkg_rwstat_recursive_sum(struct blkcg_gq *blkg, struct blkcg_policy *pol,
 	blkg_for_each_descendant_pre(pos_blkg, pos_css, blkg) {
 		struct blkg_rwstat *rwstat;
 
-		if (!pos_blkg->online)
+		if (!data_race(pos_blkg->online))
 			continue;
 
 		if (pol) {
-- 
2.43.0


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

* Re: [PATCH v2] block/blk-cgroup-rwstat: use data_race() for online test
  2026-08-03 13:34 [PATCH v2] block/blk-cgroup-rwstat: use data_race() for online test Tao Cui
@ 2026-08-03 16:47 ` Tejun Heo
  2026-08-04  2:17 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Tejun Heo @ 2026-08-03 16:47 UTC (permalink / raw)
  To: Tao Cui; +Cc: axboe, josef, yukuai, cgroups, linux-block, linux-kernel, Tao Cui

On Mon, Aug 03, 2026 at 09:34:00PM +0800, Tao Cui wrote:
> From: Tao Cui <cuitao@kylinos.cn>
> 
> blkg_rwstat_recursive_sum() reads pos_blkg->online without the queue
> lock that its doc comment requires, since blkcg_print_blkgs() stopped
> holding it in 56cc24f59c14.  Concurrent blkg_create/destroy flips
> ->online, tripping KCSAN.  The race is harmless (RCU-protected, stale
> online only causes minor stat noise).  Use data_race() to annotate
> the intentional lockless read.
> 
> Also update the stale doc comment that still requires the queue lock.
> 
> Reviewed-by: Yu Kuai <yukuai@fygo.io>
> Signed-off-by: Tao Cui <cuitao@kylinos.cn>

Acked-by: Tejun Heo <tj@kernel.org>

Thanks.

-- 
tejun

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

* Re: [PATCH v2] block/blk-cgroup-rwstat: use data_race() for online test
  2026-08-03 13:34 [PATCH v2] block/blk-cgroup-rwstat: use data_race() for online test Tao Cui
  2026-08-03 16:47 ` Tejun Heo
@ 2026-08-04  2:17 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2026-08-04  2:17 UTC (permalink / raw)
  To: Tao Cui; +Cc: tj, josef, yukuai, cgroups, linux-block, linux-kernel, Tao Cui


On Mon, 03 Aug 2026 21:34:00 +0800, Tao Cui wrote:
> blkg_rwstat_recursive_sum() reads pos_blkg->online without the queue
> lock that its doc comment requires, since blkcg_print_blkgs() stopped
> holding it in 56cc24f59c14.  Concurrent blkg_create/destroy flips
> ->online, tripping KCSAN.  The race is harmless (RCU-protected, stale
> online only causes minor stat noise).  Use data_race() to annotate
> the intentional lockless read.
> 
> [...]

Applied, thanks!

[1/1] block/blk-cgroup-rwstat: use data_race() for online test
      (no commit info)

Best regards,
-- 
Jens Axboe




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

end of thread, other threads:[~2026-08-04  2:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-03 13:34 [PATCH v2] block/blk-cgroup-rwstat: use data_race() for online test Tao Cui
2026-08-03 16:47 ` Tejun Heo
2026-08-04  2:17 ` Jens Axboe

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