Skip to content

Commit

Permalink
blkcg: blkcg_css_alloc() should grab blkcg_pol_mutex while iterating …
Browse files Browse the repository at this point in the history
…blkcg_policy[]

An entry in blkcg_policy[] is stable while there are non-bypassing
in-flight IOs on a request_queue which has the policy activated.  This
is why most derefs of blkcg_policy[] don't need explicit locking;
however, blkcg_css_alloc() isn't invoked from IO path and thus doesn't
have this protection and may race policies being added and removed.

Fix it by adding explicit blkcg_pol_mutex protection around
blkcg_policy[] iteration in blkcg_css_alloc().

Signed-off-by: Tejun Heo <[email protected]>
Fixes: e48453c ("block, cgroup: implement policy-specific per-blkcg data")
Cc: Vivek Goyal <[email protected]>
Cc: Arianna Avanzini <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
htejun authored and axboe committed Jul 9, 2015
1 parent 838f13b commit 144232b
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions block/blk-cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,8 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
goto free_blkcg;
}

mutex_lock(&blkcg_pol_mutex);

for (i = 0; i < BLKCG_MAX_POLS ; i++) {
struct blkcg_policy *pol = blkcg_policy[i];
struct blkcg_policy_data *cpd;
Expand All @@ -860,6 +862,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
BUG_ON(blkcg->pd[i]);
cpd = kzalloc(pol->cpd_size, GFP_KERNEL);
if (!cpd) {
mutex_unlock(&blkcg_pol_mutex);
ret = ERR_PTR(-ENOMEM);
goto free_pd_blkcg;
}
Expand All @@ -868,6 +871,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
pol->cpd_init_fn(blkcg);
}

mutex_unlock(&blkcg_pol_mutex);
done:
spin_lock_init(&blkcg->lock);
INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
Expand Down

0 comments on commit 144232b

Please sign in to comment.