Skip to content

Commit 7876f93

Browse files
htejunaxboe
authored andcommitted
blkcg: implement all_blkcgs list
Add all_blkcgs list goes through blkcg->all_blkcgs_node and is protected by blkcg_pol_mutex. This will be used to fix blkcg_policy_data allocation bug. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Vivek Goyal <vgoyal@redhat.com> Cc: Arianna Avanzini <avanzini.arianna@gmail.com> Signed-off-by: Jens Axboe <axboe@fb.com>
1 parent 144232b commit 7876f93

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

block/blk-cgroup.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ struct cgroup_subsys_state * const blkcg_root_css = &blkcg_root.css;
4646

4747
static struct blkcg_policy *blkcg_policy[BLKCG_MAX_POLS];
4848

49+
static LIST_HEAD(all_blkcgs); /* protected by blkcg_pol_mutex */
50+
4951
static bool blkcg_policy_enabled(struct request_queue *q,
5052
const struct blkcg_policy *pol)
5153
{
@@ -817,6 +819,10 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
817819
{
818820
struct blkcg *blkcg = css_to_blkcg(css);
819821

822+
mutex_lock(&blkcg_pol_mutex);
823+
list_del(&blkcg->all_blkcgs_node);
824+
mutex_unlock(&blkcg_pol_mutex);
825+
820826
if (blkcg != &blkcg_root) {
821827
int i;
822828

@@ -833,6 +839,8 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
833839
struct cgroup_subsys_state *ret;
834840
int i;
835841

842+
mutex_lock(&blkcg_pol_mutex);
843+
836844
if (!parent_css) {
837845
blkcg = &blkcg_root;
838846
goto done;
@@ -844,8 +852,6 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
844852
goto free_blkcg;
845853
}
846854

847-
mutex_lock(&blkcg_pol_mutex);
848-
849855
for (i = 0; i < BLKCG_MAX_POLS ; i++) {
850856
struct blkcg_policy *pol = blkcg_policy[i];
851857
struct blkcg_policy_data *cpd;
@@ -862,7 +868,6 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
862868
BUG_ON(blkcg->pd[i]);
863869
cpd = kzalloc(pol->cpd_size, GFP_KERNEL);
864870
if (!cpd) {
865-
mutex_unlock(&blkcg_pol_mutex);
866871
ret = ERR_PTR(-ENOMEM);
867872
goto free_pd_blkcg;
868873
}
@@ -871,22 +876,24 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
871876
pol->cpd_init_fn(blkcg);
872877
}
873878

874-
mutex_unlock(&blkcg_pol_mutex);
875879
done:
876880
spin_lock_init(&blkcg->lock);
877881
INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
878882
INIT_HLIST_HEAD(&blkcg->blkg_list);
879883
#ifdef CONFIG_CGROUP_WRITEBACK
880884
INIT_LIST_HEAD(&blkcg->cgwb_list);
881885
#endif
886+
list_add_tail(&blkcg->all_blkcgs_node, &all_blkcgs);
887+
888+
mutex_unlock(&blkcg_pol_mutex);
882889
return &blkcg->css;
883890

884891
free_pd_blkcg:
885892
for (i--; i >= 0; i--)
886893
kfree(blkcg->pd[i]);
887-
888894
free_blkcg:
889895
kfree(blkcg);
896+
mutex_unlock(&blkcg_pol_mutex);
890897
return ret;
891898
}
892899

include/linux/blk-cgroup.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ struct blkcg {
4747

4848
struct blkcg_policy_data *pd[BLKCG_MAX_POLS];
4949

50+
struct list_head all_blkcgs_node;
5051
#ifdef CONFIG_CGROUP_WRITEBACK
5152
struct list_head cgwb_list;
5253
#endif

0 commit comments

Comments
 (0)