Skip to content

Commit 20bd723

Browse files
Algodev-githubaxboe
authored andcommitted
block: add missing group association in bio-cloning functions
When a bio is cloned, the newly created bio must be associated with the same blkcg as the original bio (if BLK_CGROUP is enabled). If this operation is not performed, then the new bio is not associated with any group, and the group of the current task is returned when the group of the bio is requested. Depending on the cloning frequency, this may cause a large percentage of the bios belonging to a given group to be treated as if belonging to other groups (in most cases as if belonging to the root group). The expected group isolation may thereby be broken. This commit adds the missing association in bio-cloning functions. Fixes: da2f0f7 ("Btrfs: add support for blkio controllers") Cc: [email protected] # v4.3+ Signed-off-by: Paolo Valente <[email protected]> Reviewed-by: Nikolay Borisov <[email protected]> Reviewed-by: Jeff Moyer <[email protected]> Acked-by: Tejun Heo <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent bfd279a commit 20bd723

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

block/bio.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,8 @@ void __bio_clone_fast(struct bio *bio, struct bio *bio_src)
583583
bio->bi_rw = bio_src->bi_rw;
584584
bio->bi_iter = bio_src->bi_iter;
585585
bio->bi_io_vec = bio_src->bi_io_vec;
586+
587+
bio_clone_blkcg_association(bio, bio_src);
586588
}
587589
EXPORT_SYMBOL(__bio_clone_fast);
588590

@@ -687,6 +689,8 @@ struct bio *bio_clone_bioset(struct bio *bio_src, gfp_t gfp_mask,
687689
}
688690
}
689691

692+
bio_clone_blkcg_association(bio, bio_src);
693+
690694
return bio;
691695
}
692696
EXPORT_SYMBOL(bio_clone_bioset);
@@ -2004,6 +2008,17 @@ void bio_disassociate_task(struct bio *bio)
20042008
}
20052009
}
20062010

2011+
/**
2012+
* bio_clone_blkcg_association - clone blkcg association from src to dst bio
2013+
* @dst: destination bio
2014+
* @src: source bio
2015+
*/
2016+
void bio_clone_blkcg_association(struct bio *dst, struct bio *src)
2017+
{
2018+
if (src->bi_css)
2019+
WARN_ON(bio_associate_blkcg(dst, src->bi_css));
2020+
}
2021+
20072022
#endif /* CONFIG_BLK_CGROUP */
20082023

20092024
static void __init biovec_init_slabs(void)

fs/btrfs/extent_io.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2697,12 +2697,6 @@ struct bio *btrfs_bio_clone(struct bio *bio, gfp_t gfp_mask)
26972697
btrfs_bio->csum = NULL;
26982698
btrfs_bio->csum_allocated = NULL;
26992699
btrfs_bio->end_io = NULL;
2700-
2701-
#ifdef CONFIG_BLK_CGROUP
2702-
/* FIXME, put this into bio_clone_bioset */
2703-
if (bio->bi_css)
2704-
bio_associate_blkcg(new, bio->bi_css);
2705-
#endif
27062700
}
27072701
return new;
27082702
}

include/linux/bio.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,11 +470,14 @@ extern unsigned int bvec_nr_vecs(unsigned short idx);
470470
int bio_associate_blkcg(struct bio *bio, struct cgroup_subsys_state *blkcg_css);
471471
int bio_associate_current(struct bio *bio);
472472
void bio_disassociate_task(struct bio *bio);
473+
void bio_clone_blkcg_association(struct bio *dst, struct bio *src);
473474
#else /* CONFIG_BLK_CGROUP */
474475
static inline int bio_associate_blkcg(struct bio *bio,
475476
struct cgroup_subsys_state *blkcg_css) { return 0; }
476477
static inline int bio_associate_current(struct bio *bio) { return -ENOENT; }
477478
static inline void bio_disassociate_task(struct bio *bio) { }
479+
static inline void bio_clone_blkcg_association(struct bio *dst,
480+
struct bio *src) { }
478481
#endif /* CONFIG_BLK_CGROUP */
479482

480483
#ifdef CONFIG_HIGHMEM

0 commit comments

Comments
 (0)