Skip to content

Commit

Permalink
cgroup: cgroup_css_from_dir() now should be called with RCU read locked
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Tejun Heo committed Aug 13, 2013
1 parent 0ae78e0 commit b77d7b6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
12 changes: 10 additions & 2 deletions kernel/cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -5616,15 +5616,23 @@ struct cgroup_subsys_state *css_lookup(struct cgroup_subsys *ss, int id)
}
EXPORT_SYMBOL_GPL(css_lookup);

/*
* get corresponding css from file open on cgroupfs directory
/**
* cgroup_css_from_dir - get corresponding css from file open on cgroup dir
* @f: directory file of interest
* @id: subsystem id of interest
*
* Must be called under RCU read lock. The caller is responsible for
* pinning the returned css if it needs to be accessed outside the RCU
* critical section.
*/
struct cgroup_subsys_state *cgroup_css_from_dir(struct file *f, int id)
{
struct cgroup *cgrp;
struct inode *inode;
struct cgroup_subsys_state *css;

WARN_ON_ONCE(!rcu_read_lock_held());

inode = file_inode(f);
/* check in cgroup filesystem dir */
if (inode->i_op != &cgroup_dir_inode_operations)
Expand Down
3 changes: 3 additions & 0 deletions kernel/events/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,8 @@ static inline int perf_cgroup_connect(int fd, struct perf_event *event,
if (!f.file)
return -EBADF;

rcu_read_lock();

css = cgroup_css_from_dir(f.file, perf_subsys_id);
if (IS_ERR(css)) {
ret = PTR_ERR(css);
Expand All @@ -617,6 +619,7 @@ static inline int perf_cgroup_connect(int fd, struct perf_event *event,
ret = -EINVAL;
}
out:
rcu_read_unlock();
fdput(f);
return ret;
}
Expand Down

0 comments on commit b77d7b6

Please sign in to comment.