All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
To: Li Zefan <lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
Cc: shyju pv <shyju.pv-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>,
	Sanil kumar <sanil.kumar-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>,
	Masanari Iida
	<standby24x7-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	LKML <linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	Cgroups <cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	viro-RmSDqhL/yNMiFSDQTTA3OLVCufUGDwFn@public.gmane.org,
	levinsasha928-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Subject: Re: [PATCH] cgroup: fix dentry still in use bug when dropping css refs after umount
Date: Tue, 3 Jul 2012 15:52:18 -0700	[thread overview]
Message-ID: <20120703225218.GF555@google.com> (raw)
In-Reply-To: <20120703170317.GB555-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>

Hello,

Shyju, can you please test the following patch?

Sasha, can you please re-test your test case with this patch?  I don't
think fa980ca87d "cgroup: superblock can't be released with active
dentries" did anything useful.  cgroup always calls d_iput() and
d_release() in succession from the same context.  It may just have
stretched the timing a bit to hide the race.

Li, this patch reverts fa980ca87d and wraps dput() in css_dput_fn()
with s_active refs.  Positive dentry ref means that we have active ref
on sb, so wrapping the final dput() with extra s_active ref should
avoid premature super destruction.  I think we're horridly broken for
root cgroup tho - and it has been broken for very long time.  I think
it's mostly hidden because most (all?) controllers short-circuit root
cgroup.  Eh, well....

Thanks.

diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index b214fc2..15462a0 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -901,13 +901,10 @@ static void cgroup_diput(struct dentry *dentry, struct inode *inode)
 		mutex_unlock(&cgroup_mutex);
 
 		/*
-		 * We want to drop the active superblock reference from the
-		 * cgroup creation after all the dentry refs are gone -
-		 * kill_sb gets mighty unhappy otherwise.  Mark
-		 * dentry->d_fsdata with cgroup_diput() to tell
-		 * cgroup_d_release() to call deactivate_super().
+		 * Drop the active superblock reference that we took when we
+		 * created the cgroup
 		 */
-		dentry->d_fsdata = cgroup_diput;
+		deactivate_super(cgrp->root->sb);
 
 		/*
 		 * if we're getting rid of the cgroup, refcount should ensure
@@ -933,13 +930,6 @@ static int cgroup_delete(const struct dentry *d)
 	return 1;
 }
 
-static void cgroup_d_release(struct dentry *dentry)
-{
-	/* did cgroup_diput() tell me to deactivate super? */
-	if (dentry->d_fsdata == cgroup_diput)
-		deactivate_super(dentry->d_sb);
-}
-
 static void remove_dir(struct dentry *d)
 {
 	struct dentry *parent = dget(d->d_parent);
@@ -1547,7 +1537,6 @@ static int cgroup_get_rootdir(struct super_block *sb)
 	static const struct dentry_operations cgroup_dops = {
 		.d_iput = cgroup_diput,
 		.d_delete = cgroup_delete,
-		.d_release = cgroup_d_release,
 	};
 
 	struct inode *inode =
@@ -3894,8 +3883,12 @@ static void css_dput_fn(struct work_struct *work)
 {
 	struct cgroup_subsys_state *css =
 		container_of(work, struct cgroup_subsys_state, dput_work);
+	struct dentry *dentry = css->cgroup->dentry;
+	struct super_block *sb = dentry->d_sb;
 
-	dput(css->cgroup->dentry);
+	atomic_inc(&sb->s_active);
+	dput(dentry);
+	deactivate_super(sb);
 }
 
 static void init_cgroup_css(struct cgroup_subsys_state *css,

WARNING: multiple messages have this Message-ID (diff)
From: Tejun Heo <tj@kernel.org>
To: Li Zefan <lizefan@huawei.com>
Cc: shyju pv <shyju.pv@huawei.com>,
	Sanil kumar <sanil.kumar@huawei.com>,
	Masanari Iida <standby24x7@gmail.com>,
	LKML <linux-kernel@vger.kernel.org>,
	Cgroups <cgroups@vger.kernel.org>,
	viro@zeniv.linux.org.uk, levinsasha928@gmail.com
Subject: Re: [PATCH] cgroup: fix dentry still in use bug when dropping css refs after umount
Date: Tue, 3 Jul 2012 15:52:18 -0700	[thread overview]
Message-ID: <20120703225218.GF555@google.com> (raw)
In-Reply-To: <20120703170317.GB555@google.com>

Hello,

Shyju, can you please test the following patch?

Sasha, can you please re-test your test case with this patch?  I don't
think fa980ca87d "cgroup: superblock can't be released with active
dentries" did anything useful.  cgroup always calls d_iput() and
d_release() in succession from the same context.  It may just have
stretched the timing a bit to hide the race.

Li, this patch reverts fa980ca87d and wraps dput() in css_dput_fn()
with s_active refs.  Positive dentry ref means that we have active ref
on sb, so wrapping the final dput() with extra s_active ref should
avoid premature super destruction.  I think we're horridly broken for
root cgroup tho - and it has been broken for very long time.  I think
it's mostly hidden because most (all?) controllers short-circuit root
cgroup.  Eh, well....

Thanks.

diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index b214fc2..15462a0 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -901,13 +901,10 @@ static void cgroup_diput(struct dentry *dentry, struct inode *inode)
 		mutex_unlock(&cgroup_mutex);
 
 		/*
-		 * We want to drop the active superblock reference from the
-		 * cgroup creation after all the dentry refs are gone -
-		 * kill_sb gets mighty unhappy otherwise.  Mark
-		 * dentry->d_fsdata with cgroup_diput() to tell
-		 * cgroup_d_release() to call deactivate_super().
+		 * Drop the active superblock reference that we took when we
+		 * created the cgroup
 		 */
-		dentry->d_fsdata = cgroup_diput;
+		deactivate_super(cgrp->root->sb);
 
 		/*
 		 * if we're getting rid of the cgroup, refcount should ensure
@@ -933,13 +930,6 @@ static int cgroup_delete(const struct dentry *d)
 	return 1;
 }
 
-static void cgroup_d_release(struct dentry *dentry)
-{
-	/* did cgroup_diput() tell me to deactivate super? */
-	if (dentry->d_fsdata == cgroup_diput)
-		deactivate_super(dentry->d_sb);
-}
-
 static void remove_dir(struct dentry *d)
 {
 	struct dentry *parent = dget(d->d_parent);
@@ -1547,7 +1537,6 @@ static int cgroup_get_rootdir(struct super_block *sb)
 	static const struct dentry_operations cgroup_dops = {
 		.d_iput = cgroup_diput,
 		.d_delete = cgroup_delete,
-		.d_release = cgroup_d_release,
 	};
 
 	struct inode *inode =
@@ -3894,8 +3883,12 @@ static void css_dput_fn(struct work_struct *work)
 {
 	struct cgroup_subsys_state *css =
 		container_of(work, struct cgroup_subsys_state, dput_work);
+	struct dentry *dentry = css->cgroup->dentry;
+	struct super_block *sb = dentry->d_sb;
 
-	dput(css->cgroup->dentry);
+	atomic_inc(&sb->s_active);
+	dput(dentry);
+	deactivate_super(sb);
 }
 
 static void init_cgroup_css(struct cgroup_subsys_state *css,

  parent reply	other threads:[~2012-07-03 22:52 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-30  7:07 [PATCH] cgroup: fix dentry still in use bug when dropping css refs after umount Li Zefan
2012-06-30  7:07 ` Li Zefan
2012-06-30 14:34 ` Masanari Iida
     [not found] ` <4FEEA5CB.8070809-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2012-07-03 17:03   ` Tejun Heo
2012-07-03 17:03     ` Tejun Heo
     [not found]     ` <20120703170317.GB555-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-07-03 22:52       ` Tejun Heo [this message]
2012-07-03 22:52         ` Tejun Heo
     [not found]         ` <20120703225218.GF555-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-07-04  6:19           ` Li Zefan
2012-07-04  6:19             ` Li Zefan
     [not found]             ` <4FF3E063.5010604-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2012-07-08  6:35               ` Tejun Heo
2012-07-08  6:35                 ` Tejun Heo
     [not found]                 ` <20120708063536.GB19021-RcKxWJ4Cfj1J2suj2OqeGauc2jM2gXBXkQQo+JxHRPFibQn6LdNjmg@public.gmane.org>
2012-07-10  2:11                   ` Li Zefan
2012-07-10  2:11                     ` Li Zefan
     [not found]                     ` <4FFB8F39.9030209-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2012-07-16 16:45                       ` Tejun Heo
2012-07-16 16:45                         ` Tejun Heo
     [not found]         ` <4ff55c60.27da440a.65ec.ffff83dfSMTPIN_ADDED@mx.google.com>
     [not found]           ` <4ff55c60.27da440a.65ec.ffff83dfSMTPIN_ADDED-ATjtLOhZ0NVl57MIdRCFDg@public.gmane.org>
2012-07-07 23:46             ` [PATCH 1/2] Revert "cgroup: superblock can't be released with active dentries" 'Tejun Heo'
2012-07-07 23:46               ` 'Tejun Heo'
     [not found]               ` <20120707234634.GC16783-RcKxWJ4Cfj1J2suj2OqeGauc2jM2gXBXkQQo+JxHRPFibQn6LdNjmg@public.gmane.org>
2012-07-07 23:46                 ` [PATCH 2/2] cgroup: fix cgroup hierarchy umount race 'Tejun Heo'
2012-07-07 23:46                   ` 'Tejun Heo'
     [not found]                   ` <20120707234659.GD16783-RcKxWJ4Cfj1J2suj2OqeGauc2jM2gXBXkQQo+JxHRPFibQn6LdNjmg@public.gmane.org>
2012-07-14 12:08                     ` Al Viro
2012-07-14 12:08                       ` Al Viro
     [not found]                       ` <20120714120852.GK22927-3bDd1+5oDREiFSDQTTA3OLVCufUGDwFn@public.gmane.org>
2012-07-16 16:44                         ` 'Tejun Heo'
2012-07-16 16:44                           ` 'Tejun Heo'
2012-07-04  5:56       ` [PATCH] cgroup: fix dentry still in use bug when dropping css refs after umount Li Zefan
2012-07-04  5:56         ` Li Zefan

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=20120703225218.GF555@google.com \
    --to=tj-dgejt+ai2ygdnm+yrofe0a@public.gmane.org \
    --cc=cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=levinsasha928-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org \
    --cc=sanil.kumar-hv44wF8Li93QT0dZR+AlfA@public.gmane.org \
    --cc=shyju.pv-hv44wF8Li93QT0dZR+AlfA@public.gmane.org \
    --cc=standby24x7-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=viro-RmSDqhL/yNMiFSDQTTA3OLVCufUGDwFn@public.gmane.org \
    /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.