All of lore.kernel.org
 help / color / mirror / Atom feed
From: <kyler.zhangkui@huawei.com>
To: <cgroups@vger.kernel.org>
Cc: <tj@kernel.org>, <zhihui.gao@huawei.com>, <chenjie6@huawei.com>,
	<lizefan@huawei.com>, Zhang Kui <kyler.zhangkui@huawei.com>,
	<stable@vger.kernel.org>
Subject: [PATCH] cgroup: bug fix of cgroup_root object was not released after cgroup umounted
Date: Mon, 14 Dec 2015 19:45:54 +0800	[thread overview]
Message-ID: <1450093554-24474-1-git-send-email-kyler.zhangkui@huawei.com> (raw)

From: Zhang Kui <kyler.zhangkui@huawei.com>

Newsgroups: gmane.linux.kernel.cgroups, gmane.linux.kernel

test case:
    # cat test.sh
    mkdir rootdir
    mount -t cgroup xxx rootdir -o cpu

    mkdir rootdir/0

    rmdir rootdir/0
    umount rootdir

    rmdir rootdir
    # ./test.sh
    # cat /proc/cgroups
    #subsys_name    hierarchy       num_cgroups     enabled
    cpuset  0       1       1
    cpu     1       1       1
    cpuacct 0       1       1
    blkio   0       1       1
    devices 0       1       1
    freezer 0       1       1
    debug   0       1       1

The rootdir's cgroup_root is not released after it is umounted, the cpu
subsystem hierarchy id is not zero.
After that, can not mount other subsystem except cpu on the folder
rootdir.
It is because "rmdir rootdir/0" real action is done in workqueue,
the sub-cgroup "0" has not beend delete from the root->cgrp.self.children
during running "umount rootdir".

Fix this by checking whether cgroup_root has online child on umounting.

Cc: <stable@vger.kernel.org> # 4.1.y+
Signed-off-by: Zhang Kui <kyler.zhangkui@huawei.com>
---
 kernel/cgroup.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index f1603c1..ec6aecc 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -2147,6 +2147,13 @@ static void cgroup_kill_sb(struct super_block *sb)
 {
 	struct kernfs_root *kf_root = kernfs_root_from_sb(sb);
 	struct cgroup_root *root = cgroup_root_from_kf(kf_root);
+	struct cgroup *child;
+	int live_child = 0;
+
+	mutex_lock(&cgroup_mutex);
+	cgroup_for_each_live_child(child, &root->cgrp) {
+		live_child++;
+	}
 
 	/*
 	 * If @root doesn't have any mounts or children, start killing it.
@@ -2155,12 +2162,12 @@ static void cgroup_kill_sb(struct super_block *sb)
 	 *
 	 * And don't kill the default root.
 	 */
-	if (!list_empty(&root->cgrp.self.children) ||
-	    root == &cgrp_dfl_root)
-		cgroup_put(&root->cgrp);
+	if (live_child || root == &cgrp_dfl_root)
+	cgroup_put(&root->cgrp);
 	else
 		percpu_ref_kill(&root->cgrp.self.refcnt);
 
+	mutex_unlock(&cgroup_mutex);
 	kernfs_kill_sb(sb);
 }
 
-- 
2.5.0


WARNING: multiple messages have this Message-ID (diff)
From: <kyler.zhangkui@huawei.com>
To: cgroups@vger.kernel.org
Cc: tj@kernel.org, zhihui.gao@huawei.com, chenjie6@huawei.com,
	lizefan@huawei.com, Zhang Kui <kyler.zhangkui@huawei.com>,
	stable@vger.kernel.org
Subject: [PATCH] cgroup: bug fix of cgroup_root object was not released after cgroup umounted
Date: Mon, 14 Dec 2015 19:45:54 +0800	[thread overview]
Message-ID: <1450093554-24474-1-git-send-email-kyler.zhangkui@huawei.com> (raw)

From: Zhang Kui <kyler.zhangkui@huawei.com>

Newsgroups: gmane.linux.kernel.cgroups, gmane.linux.kernel

test case:
    # cat test.sh
    mkdir rootdir
    mount -t cgroup xxx rootdir -o cpu

    mkdir rootdir/0

    rmdir rootdir/0
    umount rootdir

    rmdir rootdir
    # ./test.sh
    # cat /proc/cgroups
    #subsys_name    hierarchy       num_cgroups     enabled
    cpuset  0       1       1
    cpu     1       1       1
    cpuacct 0       1       1
    blkio   0       1       1
    devices 0       1       1
    freezer 0       1       1
    debug   0       1       1

The rootdir's cgroup_root is not released after it is umounted, the cpu
subsystem hierarchy id is not zero.
After that, can not mount other subsystem except cpu on the folder
rootdir.
It is because "rmdir rootdir/0" real action is done in workqueue,
the sub-cgroup "0" has not beend delete from the root->cgrp.self.children
during running "umount rootdir".

Fix this by checking whether cgroup_root has online child on umounting.

Cc: <stable@vger.kernel.org> # 4.1.y+
Signed-off-by: Zhang Kui <kyler.zhangkui@huawei.com>
---
 kernel/cgroup.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index f1603c1..ec6aecc 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -2147,6 +2147,13 @@ static void cgroup_kill_sb(struct super_block *sb)
 {
 	struct kernfs_root *kf_root = kernfs_root_from_sb(sb);
 	struct cgroup_root *root = cgroup_root_from_kf(kf_root);
+	struct cgroup *child;
+	int live_child = 0;
+
+	mutex_lock(&cgroup_mutex);
+	cgroup_for_each_live_child(child, &root->cgrp) {
+		live_child++;
+	}
 
 	/*
 	 * If @root doesn't have any mounts or children, start killing it.
@@ -2155,12 +2162,12 @@ static void cgroup_kill_sb(struct super_block *sb)
 	 *
 	 * And don't kill the default root.
 	 */
-	if (!list_empty(&root->cgrp.self.children) ||
-	    root == &cgrp_dfl_root)
-		cgroup_put(&root->cgrp);
+	if (live_child || root == &cgrp_dfl_root)
+	cgroup_put(&root->cgrp);
 	else
 		percpu_ref_kill(&root->cgrp.self.refcnt);
 
+	mutex_unlock(&cgroup_mutex);
 	kernfs_kill_sb(sb);
 }
 
-- 
2.5.0

             reply	other threads:[~2015-12-14 11:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-14 11:45 kyler.zhangkui [this message]
2015-12-14 11:45 ` [PATCH] cgroup: bug fix of cgroup_root object was not released after cgroup umounted kyler.zhangkui
2015-12-14 19:51 ` Tejun Heo

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=1450093554-24474-1-git-send-email-kyler.zhangkui@huawei.com \
    --to=kyler.zhangkui@huawei.com \
    --cc=cgroups@vger.kernel.org \
    --cc=chenjie6@huawei.com \
    --cc=lizefan@huawei.com \
    --cc=stable@vger.kernel.org \
    --cc=tj@kernel.org \
    --cc=zhihui.gao@huawei.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.