From: Tejun Heo <tj@kernel.org>
To: axboe@kernel.dk
Cc: vgoyal@redhat.com, linux-kernel@vger.kernel.org,
avanzini.arianna@gmail.com, kernel-team@fb.com,
Tejun Heo <tj@kernel.org>
Subject: [PATCH 2/4] blkcg: blkcg_css_alloc() should grab blkcg_pol_mutex while iterating blkcg_policy[]
Date: Thu, 9 Jul 2015 16:39:48 -0400 [thread overview]
Message-ID: <1436474390-3762-3-git-send-email-tj@kernel.org> (raw)
In-Reply-To: <1436474390-3762-1-git-send-email-tj@kernel.org>
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>
---
block/blk-cgroup.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index 2ff74ff..05b893d 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -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;
@@ -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;
}
@@ -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);
--
2.4.3
next prev parent reply other threads:[~2015-07-09 20:40 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-09 20:39 [PATCHSET block/for-linus] blkcg: blkcg_policy_data fixes Tejun Heo
2015-07-09 20:39 ` [PATCH 1/4] blkcg: allow blkcg_pol_mutex to be grabbed from cgroup [file] methods Tejun Heo
2015-07-09 20:39 ` Tejun Heo [this message]
2015-07-09 20:39 ` [PATCH 3/4] blkcg: implement all_blkcgs list Tejun Heo
2015-07-09 20:39 ` [PATCH 4/4] blkcg: fix blkcg_policy_data allocation bug Tejun Heo
2015-07-10 14:28 ` [PATCHSET block/for-linus] blkcg: blkcg_policy_data fixes Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1436474390-3762-3-git-send-email-tj@kernel.org \
--to=tj@kernel.org \
--cc=avanzini.arianna@gmail.com \
--cc=axboe@kernel.dk \
--cc=kernel-team@fb.com \
--cc=linux-kernel@vger.kernel.org \
--cc=vgoyal@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).