diff options
author | Tejun Heo <tj@kernel.org> | 2015-07-09 16:39:48 -0400 |
---|---|---|
committer | Jens Axboe <axboe@fb.com> | 2015-07-09 16:41:08 -0400 |
commit | 144232b34258c1fc19729e077c6fb161e30da07b (patch) | |
tree | 8f048fd73d864a8f41917068d6e610fc5b0e0f0b | |
parent | 838f13bf4b6737d4aec508558e45f81798fc2677 (diff) |
blkcg: blkcg_css_alloc() should grab blkcg_pol_mutex while iterating 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 <tj@kernel.org>
Fixes: e48453c386f3 ("block, cgroup: implement policy-specific per-blkcg data")
Cc: Vivek Goyal <vgoyal@redhat.com>
Cc: Arianna Avanzini <avanzini.arianna@gmail.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
-rw-r--r-- | block/blk-cgroup.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c index 2ff74ffcbb27..05b893de516b 100644 --- a/block/blk-cgroup.c +++ b/block/blk-cgroup.c | |||
@@ -844,6 +844,8 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css) | |||
844 | goto free_blkcg; | 844 | goto free_blkcg; |
845 | } | 845 | } |
846 | 846 | ||
847 | mutex_lock(&blkcg_pol_mutex); | ||
848 | |||
847 | for (i = 0; i < BLKCG_MAX_POLS ; i++) { | 849 | for (i = 0; i < BLKCG_MAX_POLS ; i++) { |
848 | struct blkcg_policy *pol = blkcg_policy[i]; | 850 | struct blkcg_policy *pol = blkcg_policy[i]; |
849 | struct blkcg_policy_data *cpd; | 851 | struct blkcg_policy_data *cpd; |
@@ -860,6 +862,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css) | |||
860 | BUG_ON(blkcg->pd[i]); | 862 | BUG_ON(blkcg->pd[i]); |
861 | cpd = kzalloc(pol->cpd_size, GFP_KERNEL); | 863 | cpd = kzalloc(pol->cpd_size, GFP_KERNEL); |
862 | if (!cpd) { | 864 | if (!cpd) { |
865 | mutex_unlock(&blkcg_pol_mutex); | ||
863 | ret = ERR_PTR(-ENOMEM); | 866 | ret = ERR_PTR(-ENOMEM); |
864 | goto free_pd_blkcg; | 867 | goto free_pd_blkcg; |
865 | } | 868 | } |
@@ -868,6 +871,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css) | |||
868 | pol->cpd_init_fn(blkcg); | 871 | pol->cpd_init_fn(blkcg); |
869 | } | 872 | } |
870 | 873 | ||
874 | mutex_unlock(&blkcg_pol_mutex); | ||
871 | done: | 875 | done: |
872 | spin_lock_init(&blkcg->lock); | 876 | spin_lock_init(&blkcg->lock); |
873 | INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC); | 877 | INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC); |