aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-08-13 11:01:54 -0400
committerTejun Heo <tj@kernel.org>2013-08-13 11:01:54 -0400
commitb77d7b6088377998ebf65eaea5e51008c2d75e94 (patch)
treecab54dcd2c0639b127eb7920f6459d5f84695da0
parent0ae78e0bf10ac38ab53548e18383afc9997eca22 (diff)
cgroup: cgroup_css_from_dir() now should be called with RCU read locked
cgroup->subsys[] will become RCU protected and thus all cgroup_css() usages should either be under RCU read lock or cgroup_mutex. This patch updates cgroup_css_from_dir() which returns the matching cgroup_subsys_state given a directory file and subsys_id so that it requires RCU read lock and updates its sole user perf_cgroup_connect(). Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Li Zefan <lizefan@huawei.com> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@redhat.com>
-rw-r--r--kernel/cgroup.c12
-rw-r--r--kernel/events/core.c3
2 files changed, 13 insertions, 2 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 5c6dd7ed26a7..cbb6314f1836 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -5616,8 +5616,14 @@ struct cgroup_subsys_state *css_lookup(struct cgroup_subsys *ss, int id)
5616} 5616}
5617EXPORT_SYMBOL_GPL(css_lookup); 5617EXPORT_SYMBOL_GPL(css_lookup);
5618 5618
5619/* 5619/**
5620 * get corresponding css from file open on cgroupfs directory 5620 * cgroup_css_from_dir - get corresponding css from file open on cgroup dir
5621 * @f: directory file of interest
5622 * @id: subsystem id of interest
5623 *
5624 * Must be called under RCU read lock. The caller is responsible for
5625 * pinning the returned css if it needs to be accessed outside the RCU
5626 * critical section.
5621 */ 5627 */
5622struct cgroup_subsys_state *cgroup_css_from_dir(struct file *f, int id) 5628struct cgroup_subsys_state *cgroup_css_from_dir(struct file *f, int id)
5623{ 5629{
@@ -5625,6 +5631,8 @@ struct cgroup_subsys_state *cgroup_css_from_dir(struct file *f, int id)
5625 struct inode *inode; 5631 struct inode *inode;
5626 struct cgroup_subsys_state *css; 5632 struct cgroup_subsys_state *css;
5627 5633
5634 WARN_ON_ONCE(!rcu_read_lock_held());
5635
5628 inode = file_inode(f); 5636 inode = file_inode(f);
5629 /* check in cgroup filesystem dir */ 5637 /* check in cgroup filesystem dir */
5630 if (inode->i_op != &cgroup_dir_inode_operations) 5638 if (inode->i_op != &cgroup_dir_inode_operations)
diff --git a/kernel/events/core.c b/kernel/events/core.c
index c199c4f24910..23261f957713 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -591,6 +591,8 @@ static inline int perf_cgroup_connect(int fd, struct perf_event *event,
591 if (!f.file) 591 if (!f.file)
592 return -EBADF; 592 return -EBADF;
593 593
594 rcu_read_lock();
595
594 css = cgroup_css_from_dir(f.file, perf_subsys_id); 596 css = cgroup_css_from_dir(f.file, perf_subsys_id);
595 if (IS_ERR(css)) { 597 if (IS_ERR(css)) {
596 ret = PTR_ERR(css); 598 ret = PTR_ERR(css);
@@ -617,6 +619,7 @@ static inline int perf_cgroup_connect(int fd, struct perf_event *event,
617 ret = -EINVAL; 619 ret = -EINVAL;
618 } 620 }
619out: 621out:
622 rcu_read_unlock();
620 fdput(f); 623 fdput(f);
621 return ret; 624 return ret;
622} 625}