* [PATCH] Add a refcount check in dput()
@ 2007-09-10 22:13 Paul Menage
2007-09-15 8:39 ` Andrew Morton
0 siblings, 1 reply; 4+ messages in thread
From: Paul Menage @ 2007-09-10 22:13 UTC (permalink / raw)
To: viro; +Cc: linux-kernel
Add a BUG_ON() to check for passing an unreferenced dentry to dput().
This is analogous to the similar check in dget(), and will make
reference-counting bugs in filesystems more immediately obvious. (I
just spent a while debugging an oops that turned out to be due to
broken fs reference counting.)
Signed-off-by: Paul Menage <menage@google.com>
---
fs/dcache.c | 1 +
1 file changed, 1 insertion(+)
Index: container-2.6.23-rc3-mm1/fs/dcache.c
===================================================================
--- container-2.6.23-rc3-mm1.orig/fs/dcache.c
+++ container-2.6.23-rc3-mm1/fs/dcache.c
@@ -176,6 +176,7 @@ void dput(struct dentry *dentry)
if (!dentry)
return;
+ BUG_ON(!atomic_read(&dentry->d_count));
repeat:
if (atomic_read(&dentry->d_count) == 1)
might_sleep();
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Add a refcount check in dput()
2007-09-10 22:13 [PATCH] Add a refcount check in dput() Paul Menage
@ 2007-09-15 8:39 ` Andrew Morton
2007-09-17 18:21 ` Paul Menage
0 siblings, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2007-09-15 8:39 UTC (permalink / raw)
To: Paul Menage; +Cc: viro, linux-kernel
On Mon, 10 Sep 2007 15:13:19 -0700 (PDT) menage@google.com (Paul Menage) wrote:
> Add a BUG_ON() to check for passing an unreferenced dentry to dput().
>
> This is analogous to the similar check in dget(), and will make
> reference-counting bugs in filesystems more immediately obvious. (I
> just spent a while debugging an oops that turned out to be due to
> broken fs reference counting.)
>
> Signed-off-by: Paul Menage <menage@google.com>
>
> ---
> fs/dcache.c | 1 +
> 1 file changed, 1 insertion(+)
>
> Index: container-2.6.23-rc3-mm1/fs/dcache.c
> ===================================================================
> --- container-2.6.23-rc3-mm1.orig/fs/dcache.c
> +++ container-2.6.23-rc3-mm1/fs/dcache.c
> @@ -176,6 +176,7 @@ void dput(struct dentry *dentry)
> if (!dentry)
> return;
>
> + BUG_ON(!atomic_read(&dentry->d_count));
> repeat:
> if (atomic_read(&dentry->d_count) == 1)
> might_sleep();
eek, much too aggressive.
I added this:
--- a/fs/dcache.c~add-a-refcount-check-in-dput
+++ a/fs/dcache.c
@@ -176,6 +176,7 @@ void dput(struct dentry *dentry)
if (!dentry)
return;
+ WARN_ON_ONCE(!atomic_read(&dentry->d_count));
repeat:
if (atomic_read(&dentry->d_count) == 1)
might_sleep();
_
to the -mm-only-debugging-patches section of the -mm tree.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Add a refcount check in dput()
2007-09-15 8:39 ` Andrew Morton
@ 2007-09-17 18:21 ` Paul Menage
2007-09-17 20:48 ` Andrew Morton
0 siblings, 1 reply; 4+ messages in thread
From: Paul Menage @ 2007-09-17 18:21 UTC (permalink / raw)
To: Andrew Morton; +Cc: viro, linux-kernel
On 9/15/07, Andrew Morton <akpm@linux-foundation.org> wrote:
> >
> > + BUG_ON(!atomic_read(&dentry->d_count));
> > repeat:
> > if (atomic_read(&dentry->d_count) == 1)
> > might_sleep();
>
> eek, much too aggressive.
How about the equivalent BUG_ON() in dget()? I figure that they ought
to both be of the same strictness.
Paul
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Add a refcount check in dput()
2007-09-17 18:21 ` Paul Menage
@ 2007-09-17 20:48 ` Andrew Morton
0 siblings, 0 replies; 4+ messages in thread
From: Andrew Morton @ 2007-09-17 20:48 UTC (permalink / raw)
To: Paul Menage; +Cc: viro, linux-kernel
On Mon, 17 Sep 2007 11:21:35 -0700
"Paul Menage" <menage@google.com> wrote:
> On 9/15/07, Andrew Morton <akpm@linux-foundation.org> wrote:
> > >
> > > + BUG_ON(!atomic_read(&dentry->d_count));
> > > repeat:
> > > if (atomic_read(&dentry->d_count) == 1)
> > > might_sleep();
> >
> > eek, much too aggressive.
>
> How about the equivalent BUG_ON() in dget()? I figure that they ought
> to both be of the same strictness.
The one in dget() is known not to trigger - it's been there for a long time.
My problem with new BUG_ON's is that they get added thinking "no way will
this trigger" and lo, they do trigger and lots of people get their testing
disrupted for a whole release.
Long-standing checks like the one in dget() should perhaps be removed now
that we know they don't trigger - move them under some CONFIG_DEBUG_foo
option.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-09-17 20:49 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-09-10 22:13 [PATCH] Add a refcount check in dput() Paul Menage
2007-09-15 8:39 ` Andrew Morton
2007-09-17 18:21 ` Paul Menage
2007-09-17 20:48 ` Andrew Morton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox