From: Tejun Heo Subject: [PATCH 1/3] cgroup: make sure parent won't be destroyed before its children Date: Mon, 8 Apr 2013 19:23:31 -0700 Message-ID: <1365474213-13354-2-git-send-email-tj@kernel.org> References: <1365474213-13354-1-git-send-email-tj@kernel.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=0dvtTPrYEwvro/QMGPaQzXIPskKVHQps7saTVOWFK20=; b=kxjAtrRwpuqzx2VjJXcm5L01y6tPI+j8YmHHoZDPpAhBxQ0w/r8KAQa9uMrFyfjdhE 4rwd2FrgKXanZ3PoQEMoT0xAUKFAsJJ7vWNXtPOmvwPiK5z4xH0Y3yUKvGClLZmB0aK8 lAPNB9X9zlul+h87fxZvvI8mfNie5nAEmQvz4HldImtAGrmMwuZla0Tdzf4amlhFo45D qZEJVJz9tIskzFOcN5JdK9hVaTcjfybOauf8OrZ69RrPmbH8Hkdu0OlOhoGi2CDFUpYF NGdHY4iEKl2jj9EYcujOjdGya3ZpnirMYn+iCHRp7J+klNjt/nJLkSeuaushC+doUQPx 5POQ== In-Reply-To: <1365474213-13354-1-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: containers-bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org Errors-To: containers-bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org To: mingo-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org Cc: namhyung.kim-Hm3cg6mZ9cc@public.gmane.org, a.p.zijlstra-/NLkJaSkS4VmR6Xm/wNWPw@public.gmane.org, containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org, linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, eranian-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org, mhocko-AlSwsSmVLrQ@public.gmane.org, paulus-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org, acme-f8uhVLnGfZaxAyOMLChx1axOck334EZe@public.gmane.org, Tejun Heo , cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org From: Li Zefan Suppose we rmdir a cgroup and there're still css refs, this cgroup won't be freed. Then we rmdir the parent cgroup, and the parent is freed immediately due to css ref draining to 0. Now it would be a disaster if the still-alive child cgroup tries to access its parent. Make sure this won't happen. Signed-off-by: Li Zefan Reviewed-by: Michal Hocko Acked-by: KAMEZAWA Hiroyuki Signed-off-by: Tejun Heo --- kernel/cgroup.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/kernel/cgroup.c b/kernel/cgroup.c index ba3e24a..d7dfa64 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c @@ -876,6 +876,13 @@ static void cgroup_free_fn(struct work_struct *work) mutex_unlock(&cgroup_mutex); /* + * We get a ref to the parent's dentry, and put the ref when + * this cgroup is being freed, so it's guaranteed that the + * parent won't be destroyed before its children. + */ + dput(cgrp->parent->dentry); + + /* * Drop the active superblock reference that we took when we * created the cgroup */ @@ -4168,6 +4175,9 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry, for_each_subsys(root, ss) dget(dentry); + /* hold a ref to the parent's dentry */ + dget(parent->dentry); + /* creation succeeded, notify subsystems */ for_each_subsys(root, ss) { err = online_css(ss, cgrp); -- 1.8.1.4