block/blk-cgroup-rwstat: use data_race() for online test
Subsystems (2)
PATCH v2 1/1 block/blk-cgroup-rwstat: use data_race() for online test
From: Tao Cui <[email protected]>
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.
---
Changes in v2:
- Update the stale kernel-doc comment that still mandates the queue lock.
--- block/blk-cgroup-rwstat.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
block/blk-cgroup-rwstat.c +2 -3
@@ -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) {
Signature · 1 line
2.43.0
Quoted 9 lines · Tao Cui
From: Tao Cui <[email protected]>
blkg_rwstat_recursive_sum()readspos_blkg->onlinewithout the queue lock that its doc comment requires, sinceblkcg_print_blkgs()stopped holding it in56cc24f59c14. Concurrent blkg_create/destroy flips ->online, tripping KCSAN. The race is harmless (RCU-protected, stale online only causes minor stat noise). Usedata_race()to annotate the intentional lockless read.
Quoted 4 lines
Also update the stale doc comment that still requires the queue lock.
Reviewed-by Yu Kuai <[email protected]>Signed-off-by Tao Cui <[email protected]>
Thanks.
Signature · 1 line
tejun
Quoted 8 lines · Tao Cui
blkg_rwstat_recursive_sum()readspos_blkg->onlinewithout the queue lock that its doc comment requires, sinceblkcg_print_blkgs()stopped holding it in56cc24f59c14. Concurrent blkg_create/destroy flips ->online, tripping KCSAN. The race is harmless (RCU-protected, stale online only causes minor stat noise). Usedata_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,
Signature · 1 line
Jens Axboe