cgroups.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] cgroup: fix locking in cgroupstats_build()
@ 2014-02-14  8:54 Li Zefan
  2014-02-14  8:55 ` [PATCH 2/3] cgroup: fix memory leak in cgroup_mount() Li Zefan
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Li Zefan @ 2014-02-14  8:54 UTC (permalink / raw)
  To: Tejun Heo; +Cc: LKML, Cgroups

css_set_lock has been converted to css_set_rwsem, and rwsem can't
nested inside rcu_read_lock.

Signed-off-by: Li Zefan <lizefan@huawei.com>
---
 kernel/cgroup.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index af4ecc3..0e794ca 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -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;
 }
 
-- 
1.8.0.2

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-02-14 15:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-14  8:54 [PATCH 1/3] cgroup: fix locking in cgroupstats_build() Li Zefan
2014-02-14  8:55 ` [PATCH 2/3] cgroup: fix memory leak in cgroup_mount() Li Zefan
2014-02-14  8:56 ` [PATCH 3/3] cgroup: deal with dummp_top in cgroup_name() and cgroup_path() Li Zefan
     [not found] ` <52FDD9C4.1070001-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2014-02-14 15:57   ` [PATCH 1/3] cgroup: fix locking in cgroupstats_build() Tejun Heo

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).