cgroups.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: lizefan@huawei.com
Cc: containers@lists.linux-foundation.org, cgroups@vger.kernel.org,
	linux-kernel@vger.kernel.org, Tejun Heo <tj@kernel.org>
Subject: [PATCH 5/8] cgroup: make cgroup hold onto its kernfs_node
Date: Sat,  8 Feb 2014 11:38:26 -0500	[thread overview]
Message-ID: <1391877509-10855-6-git-send-email-tj@kernel.org> (raw)
In-Reply-To: <1391877509-10855-1-git-send-email-tj@kernel.org>

cgroup currently releases its kernfs_node when it gets removed.  While
not buggy, this makes cgroup->kn access rules complicated than
necessary and leads to things like get/put protection around
kernfs_remove() in cgroup_destroy_locked().  In addition, we want to
use kernfs_name/path() and friends but also want to be able to
determine a cgroup's name between removal and release.

This patch makes cgroup hold onto its kernfs_node until freed so that
cgroup->kn is always accessible.

Signed-off-by: Tejun Heo <tj@kernel.org>
---
 kernel/cgroup.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 6da820d..da8aef0 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -957,6 +957,8 @@ static void cgroup_free_fn(struct work_struct *work)
 
 	cgroup_pidlist_destroy_all(cgrp);
 
+	kernfs_put(cgrp->kn);
+
 	kfree(rcu_dereference_raw(cgrp->name));
 	kfree(cgrp);
 }
@@ -3784,6 +3786,12 @@ static long cgroup_create(struct cgroup *parent, const char *name_str,
 	}
 	cgrp->kn = kn;
 
+	/*
+	 * This extra ref will be put in cgroup_free_fn() and guarantees
+	 * that @cgrp->kn is always accessible.
+	 */
+	kernfs_get(kn);
+
 	cgrp->serial_nr = cgroup_serial_nr_next++;
 
 	/* allocation complete, commit to creation */
@@ -3964,7 +3972,6 @@ static int cgroup_destroy_locked(struct cgroup *cgrp)
 {
 	struct cgroup *child;
 	struct cgroup_subsys_state *css;
-	struct kernfs_node *kn;
 	bool empty;
 	int ssid;
 
@@ -4042,13 +4049,8 @@ static int cgroup_destroy_locked(struct cgroup *cgrp)
 	 * clearing of cgrp->kn->priv backpointer, which should happen
 	 * after all files under it have been removed.
 	 */
-	kn = cgrp->kn;
-	kernfs_get(kn);
-
-	kernfs_remove(cgrp->kn);
-
+	kernfs_remove(cgrp->kn);	/* @cgrp has an extra ref on its kn */
 	RCU_INIT_POINTER(*(void __rcu __force **)&cgrp->kn->priv, NULL);
-	kernfs_put(kn);
 
 	mutex_lock(&cgroup_mutex);
 
-- 
1.8.5.3

  parent reply	other threads:[~2014-02-08 16:38 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-08 16:38 [PATCHSET v2 cgroup/for-3.15] cgroup: cleanups after kernfs conversion Tejun Heo
2014-02-08 16:38 ` [PATCH 3/8] cgroup: remove cftype_set Tejun Heo
2014-02-08 16:38 ` Tejun Heo [this message]
2014-02-08 16:38 ` [PATCH 6/8] cgroup: remove cgroup->name Tejun Heo
     [not found]   ` <1391877509-10855-7-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2014-02-08 20:06     ` [PATCH v3 " Tejun Heo
2014-02-12  7:52     ` [PATCH " Li Zefan
     [not found]       ` <52FB2834.3090408-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2014-02-12  8:27         ` Tejun Heo
     [not found]           ` <20140212082713.GD7984-9pTldWuhBndy/B6EtB590w@public.gmane.org>
2014-02-12  8:52             ` Li Zefan
     [not found] ` <1391877509-10855-1-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2014-02-08 16:38   ` [PATCH 1/8] cgroup: warn if "xattr" is specified with "sane_behavior" Tejun Heo
2014-02-08 16:38   ` [PATCH 2/8] cgroup: relocate cgroup_rm_cftypes() Tejun Heo
2014-02-08 16:38   ` [PATCH 4/8] cgroup: simplify dynamic cftype addition and removal Tejun Heo
2014-02-08 16:38   ` [PATCH 7/8] cgroup: rename cgroupfs_root->number_of_cgroups to ->nr_cgrps and make it atomic_t Tejun Heo
2014-02-12  8:58   ` [PATCHSET v2 cgroup/for-3.15] cgroup: cleanups after kernfs conversion Li Zefan
2014-02-12 14:30   ` Tejun Heo
2014-02-08 16:38 ` [PATCH 8/8] cgroup: remove cgroupfs_root->refcnt Tejun Heo
  -- strict thread matches above, loose matches on Subject: below --
2014-01-28 23:59 [PATCHSET cgroup/for-3.15] cgroup: cleanups after kernfs conversion Tejun Heo
2014-01-28 23:59 ` [PATCH 5/8] cgroup: make cgroup hold onto its kernfs_node 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=1391877509-10855-6-git-send-email-tj@kernel.org \
    --to=tj@kernel.org \
    --cc=cgroups@vger.kernel.org \
    --cc=containers@lists.linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizefan@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 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).