cgroup: fix locking in cgroupstats_build()
PATCH 1/3 cgroup: fix locking in cgroupstats_build()
css_set_lock has been converted to css_set_rwsem, and rwsem can't nested inside rcu_read_lock.
Signed-off-by Li Zefan <[email protected]>
--- kernel/cgroup.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
kernel/cgroup.c +6 -2
@@ -2997,6 +2997,8 @@ int cgroupstats_build(struct cgroupstats *stats, struct dentry *dentry) kernfs_type(kn) != KERNFS_DIR)return -EINVAL ; +mutex_lock (&cgroup_mutex); +/* * We aren't being called from kernfs and there's no guarantee on * @kn->priv's validity. For this and css_tryget_from_dir(),
@@ -3004,10 +3006,12 @@ int cgroupstats_build(struct cgroupstats *stats, struct dentry *dentry)*/ rcu_read_lock (); cgrp =rcu_dereference (kn->priv); -if (!cgrp) { +if (!cgrp ||cgroup_is_dead (cgrp)) {rcu_read_unlock (); +mutex_unlock (&cgroup_mutex);return -ENOENT ; } +rcu_read_unlock ();css_task_iter_start (&cgrp->dummy_css, &it);while ((tsk =css_task_iter_next (&it))) {
@@ -3032,7 +3036,7 @@ int cgroupstats_build(struct cgroupstats *stats, struct dentry *dentry) }css_task_iter_end (&it); -rcu_read_unlock (); +mutex_unlock (&cgroup_mutex);return 0 ; }
Signature · 1 line
1.8.0.2
PATCH 2/3 cgroup: fix memory leak in cgroup_mount()
We should free the memory allocated in parse_cgroupfs_options() before calling this function again.
Signed-off-by Li Zefan <[email protected]>
--- kernel/cgroup.c | 2 ++ 1 file changed, 2 insertions(+)
kernel/cgroup.c +2 -0
@@ -1540,6 +1540,8 @@ retry:if (!atomic_inc_not_zero (&root->top_cgroup.refcnt)) {mutex_unlock (&cgroup_mutex);mutex_unlock (&cgroup_tree_mutex); +kfree (opts.release_agent); +kfree (opts.name);msleep (10 ); goto retry; }
Signature · 1 line
1.8.0.2
PATCH 3/3 cgroup: deal with dummp_top in cgroup_name() and cgroup_path()
In reply to Li ZefanMy kernel fails to boot, because blkcg calls cgroup_path() while cgroupfs is not mounted.
Fix both cgroup_name() and cgroup_path().
Signed-off-by Li Zefan <[email protected]>
--- include/linux/cgroup.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
include/linux/cgroup.h +10 -2
@@ -487,13 +487,21 @@ struct cgroup_subsys_state *seq_css(struct seq_file *seq);static inline int cgroup_name (struct cgroup *cgrp,char *buf,size_t buflen) { -return kernfs_name (cgrp->kn, buf, buflen); +/* dummy_top doesn't have a kn associated */ +if (cgrp->kn) +return kernfs_name (cgrp->kn, buf, buflen); +else +return strlcpy (buf,"/" , buflen); }static inline char *__must_check cgroup_path (struct cgroup *cgrp,char *buf,size_t buflen) { -return kernfs_path (cgrp->kn, buf, buflen); +/* dummy_top doesn't have a kn associated */ +if (cgrp->kn) +return kernfs_path (cgrp->kn, buf, buflen); +strlcpy (buf,"/" , buflen); +return (buflen <=2 ) ?NULL : buf; }static inline void pr_cont_cgroup_name (struct cgroup *cgrp)
Signature · 1 line
1.8.0.2
Tejun Heo
maintainerQuoted 4 lines · Li Zefan
css_set_lockhas been converted tocss_set_rwsem, and rwsem can't nested insidercu_read_lock.Signed-off-by Li Zefan <[email protected]>
Applied 1-3 to cgroup/for-3.15.
Thanks!
Signature · 1 line
tejun