Commit 7876f930 authored by Tejun Heo's avatar Tejun Heo Committed by Jens Axboe

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: default avatarTejun Heo <tj@kernel.org>
Cc: Vivek Goyal <vgoyal@redhat.com>
Cc: Arianna Avanzini <avanzini.arianna@gmail.com>
Signed-off-by: default avatarJens Axboe <axboe@fb.com>
parent 144232b3
...@@ -46,6 +46,8 @@ struct cgroup_subsys_state * const blkcg_root_css = &blkcg_root.css; ...@@ -46,6 +46,8 @@ struct cgroup_subsys_state * const blkcg_root_css = &blkcg_root.css;
static struct blkcg_policy *blkcg_policy[BLKCG_MAX_POLS]; static struct blkcg_policy *blkcg_policy[BLKCG_MAX_POLS];
static LIST_HEAD(all_blkcgs); /* protected by blkcg_pol_mutex */
static bool blkcg_policy_enabled(struct request_queue *q, static bool blkcg_policy_enabled(struct request_queue *q,
const struct blkcg_policy *pol) const struct blkcg_policy *pol)
{ {
...@@ -817,6 +819,10 @@ static void blkcg_css_free(struct cgroup_subsys_state *css) ...@@ -817,6 +819,10 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
{ {
struct blkcg *blkcg = css_to_blkcg(css); struct blkcg *blkcg = css_to_blkcg(css);
mutex_lock(&blkcg_pol_mutex);
list_del(&blkcg->all_blkcgs_node);
mutex_unlock(&blkcg_pol_mutex);
if (blkcg != &blkcg_root) { if (blkcg != &blkcg_root) {
int i; int i;
...@@ -833,6 +839,8 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css) ...@@ -833,6 +839,8 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
struct cgroup_subsys_state *ret; struct cgroup_subsys_state *ret;
int i; int i;
mutex_lock(&blkcg_pol_mutex);
if (!parent_css) { if (!parent_css) {
blkcg = &blkcg_root; blkcg = &blkcg_root;
goto done; goto done;
...@@ -844,8 +852,6 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css) ...@@ -844,8 +852,6 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
goto free_blkcg; goto free_blkcg;
} }
mutex_lock(&blkcg_pol_mutex);
for (i = 0; i < BLKCG_MAX_POLS ; i++) { for (i = 0; i < BLKCG_MAX_POLS ; i++) {
struct blkcg_policy *pol = blkcg_policy[i]; struct blkcg_policy *pol = blkcg_policy[i];
struct blkcg_policy_data *cpd; struct blkcg_policy_data *cpd;
...@@ -862,7 +868,6 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css) ...@@ -862,7 +868,6 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
BUG_ON(blkcg->pd[i]); BUG_ON(blkcg->pd[i]);
cpd = kzalloc(pol->cpd_size, GFP_KERNEL); cpd = kzalloc(pol->cpd_size, GFP_KERNEL);
if (!cpd) { if (!cpd) {
mutex_unlock(&blkcg_pol_mutex);
ret = ERR_PTR(-ENOMEM); ret = ERR_PTR(-ENOMEM);
goto free_pd_blkcg; goto free_pd_blkcg;
} }
...@@ -871,7 +876,6 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css) ...@@ -871,7 +876,6 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
pol->cpd_init_fn(blkcg); pol->cpd_init_fn(blkcg);
} }
mutex_unlock(&blkcg_pol_mutex);
done: done:
spin_lock_init(&blkcg->lock); spin_lock_init(&blkcg->lock);
INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC); INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
...@@ -879,14 +883,17 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css) ...@@ -879,14 +883,17 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
#ifdef CONFIG_CGROUP_WRITEBACK #ifdef CONFIG_CGROUP_WRITEBACK
INIT_LIST_HEAD(&blkcg->cgwb_list); INIT_LIST_HEAD(&blkcg->cgwb_list);
#endif #endif
list_add_tail(&blkcg->all_blkcgs_node, &all_blkcgs);
mutex_unlock(&blkcg_pol_mutex);
return &blkcg->css; return &blkcg->css;
free_pd_blkcg: free_pd_blkcg:
for (i--; i >= 0; i--) for (i--; i >= 0; i--)
kfree(blkcg->pd[i]); kfree(blkcg->pd[i]);
free_blkcg: free_blkcg:
kfree(blkcg); kfree(blkcg);
mutex_unlock(&blkcg_pol_mutex);
return ret; return ret;
} }
......
...@@ -47,6 +47,7 @@ struct blkcg { ...@@ -47,6 +47,7 @@ struct blkcg {
struct blkcg_policy_data *pd[BLKCG_MAX_POLS]; struct blkcg_policy_data *pd[BLKCG_MAX_POLS];
struct list_head all_blkcgs_node;
#ifdef CONFIG_CGROUP_WRITEBACK #ifdef CONFIG_CGROUP_WRITEBACK
struct list_head cgwb_list; struct list_head cgwb_list;
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment