Skip to content

Commit d0aac23

Browse files
Ming Leiaxboe
authored andcommitted
blk-cgroup: fix list corruption from reorder of WRITE ->lqueued
__blkcg_rstat_flush() can be run anytime, especially when blk_cgroup_bio_start is being executed. If WRITE of `->lqueued` is re-ordered with READ of 'bisc->lnode.next' in the loop of __blkcg_rstat_flush(), `next_bisc` can be assigned with one stat instance being added in blk_cgroup_bio_start(), then the local list in __blkcg_rstat_flush() could be corrupted. Fix the issue by adding one barrier. Cc: Tejun Heo <[email protected]> Cc: Waiman Long <[email protected]> Fixes: 3b8cc62 ("blk-cgroup: Optimize blkcg_rstat_flush()") Signed-off-by: Ming Lei <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 6da6680 commit d0aac23

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

block/blk-cgroup.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,16 @@ static void __blkcg_rstat_flush(struct blkcg *blkcg, int cpu)
10351035
struct blkg_iostat cur;
10361036
unsigned int seq;
10371037

1038+
/*
1039+
* Order assignment of `next_bisc` from `bisc->lnode.next` in
1040+
* llist_for_each_entry_safe and clearing `bisc->lqueued` for
1041+
* avoiding to assign `next_bisc` with new next pointer added
1042+
* in blk_cgroup_bio_start() in case of re-ordering.
1043+
*
1044+
* The pair barrier is implied in llist_add() in blk_cgroup_bio_start().
1045+
*/
1046+
smp_mb();
1047+
10381048
WRITE_ONCE(bisc->lqueued, false);
10391049

10401050
/* fetch the current per-cpu values */

0 commit comments

Comments
 (0)