Skip to content

Commit 6da6680

Browse files
Ming Leiaxboe
authored andcommitted
blk-cgroup: fix list corruption from resetting io stat
Since commit 3b8cc62 ("blk-cgroup: Optimize blkcg_rstat_flush()"), each iostat instance is added to blkcg percpu list, so blkcg_reset_stats() can't reset the stat instance by memset(), otherwise the llist may be corrupted. Fix the issue by only resetting the counter part. Cc: Tejun Heo <[email protected]> Cc: Waiman Long <[email protected]> Cc: Jay Shin <[email protected]> Fixes: 3b8cc62 ("blk-cgroup: Optimize blkcg_rstat_flush()") Signed-off-by: Ming Lei <[email protected]> Acked-by: Tejun Heo <[email protected]> Reviewed-by: Waiman Long <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent efb905a commit 6da6680

File tree

1 file changed

+35
-23
lines changed

1 file changed

+35
-23
lines changed

block/blk-cgroup.c

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -618,12 +618,45 @@ static void blkg_destroy_all(struct gendisk *disk)
618618
spin_unlock_irq(&q->queue_lock);
619619
}
620620

621+
static void blkg_iostat_set(struct blkg_iostat *dst, struct blkg_iostat *src)
622+
{
623+
int i;
624+
625+
for (i = 0; i < BLKG_IOSTAT_NR; i++) {
626+
dst->bytes[i] = src->bytes[i];
627+
dst->ios[i] = src->ios[i];
628+
}
629+
}
630+
631+
static void __blkg_clear_stat(struct blkg_iostat_set *bis)
632+
{
633+
struct blkg_iostat cur = {0};
634+
unsigned long flags;
635+
636+
flags = u64_stats_update_begin_irqsave(&bis->sync);
637+
blkg_iostat_set(&bis->cur, &cur);
638+
blkg_iostat_set(&bis->last, &cur);
639+
u64_stats_update_end_irqrestore(&bis->sync, flags);
640+
}
641+
642+
static void blkg_clear_stat(struct blkcg_gq *blkg)
643+
{
644+
int cpu;
645+
646+
for_each_possible_cpu(cpu) {
647+
struct blkg_iostat_set *s = per_cpu_ptr(blkg->iostat_cpu, cpu);
648+
649+
__blkg_clear_stat(s);
650+
}
651+
__blkg_clear_stat(&blkg->iostat);
652+
}
653+
621654
static int blkcg_reset_stats(struct cgroup_subsys_state *css,
622655
struct cftype *cftype, u64 val)
623656
{
624657
struct blkcg *blkcg = css_to_blkcg(css);
625658
struct blkcg_gq *blkg;
626-
int i, cpu;
659+
int i;
627660

628661
mutex_lock(&blkcg_pol_mutex);
629662
spin_lock_irq(&blkcg->lock);
@@ -634,18 +667,7 @@ static int blkcg_reset_stats(struct cgroup_subsys_state *css,
634667
* anyway. If you get hit by a race, retry.
635668
*/
636669
hlist_for_each_entry(blkg, &blkcg->blkg_list, blkcg_node) {
637-
for_each_possible_cpu(cpu) {
638-
struct blkg_iostat_set *bis =
639-
per_cpu_ptr(blkg->iostat_cpu, cpu);
640-
memset(bis, 0, sizeof(*bis));
641-
642-
/* Re-initialize the cleared blkg_iostat_set */
643-
u64_stats_init(&bis->sync);
644-
bis->blkg = blkg;
645-
}
646-
memset(&blkg->iostat, 0, sizeof(blkg->iostat));
647-
u64_stats_init(&blkg->iostat.sync);
648-
670+
blkg_clear_stat(blkg);
649671
for (i = 0; i < BLKCG_MAX_POLS; i++) {
650672
struct blkcg_policy *pol = blkcg_policy[i];
651673

@@ -948,16 +970,6 @@ void blkg_conf_exit(struct blkg_conf_ctx *ctx)
948970
}
949971
EXPORT_SYMBOL_GPL(blkg_conf_exit);
950972

951-
static void blkg_iostat_set(struct blkg_iostat *dst, struct blkg_iostat *src)
952-
{
953-
int i;
954-
955-
for (i = 0; i < BLKG_IOSTAT_NR; i++) {
956-
dst->bytes[i] = src->bytes[i];
957-
dst->ios[i] = src->ios[i];
958-
}
959-
}
960-
961973
static void blkg_iostat_add(struct blkg_iostat *dst, struct blkg_iostat *src)
962974
{
963975
int i;

0 commit comments

Comments
 (0)