* [PATCH] mm: Make it easier to catch NULL cache names
@ 2009-07-28 1:48 Benjamin Herrenschmidt
2009-07-28 2:52 ` Linus Torvalds
0 siblings, 1 reply; 8+ messages in thread
From: Benjamin Herrenschmidt @ 2009-07-28 1:48 UTC (permalink / raw)
To: Linus Torvalds; +Cc: Andrew Morton, Linux Kernel list, linux-mm
Right now, if you inadvertently pass NULL to kmem_cache_create() at boot
time, it crashes much later after boot somewhere deep inside sysfs which
makes it very non obvious to figure out what's going on.
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---
Yes, I did hit that :-) Something in ppc land using an array of caches
and got the names array out of sync with changes to the list of indices.
diff --git a/mm/slub.c b/mm/slub.c
index b9f1491..b5b5653 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -3292,6 +3292,8 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
{
struct kmem_cache *s;
+ BUG_ON(name == NULL);
+
down_write(&slub_lock);
s = find_mergeable(size, align, flags, name, ctor);
if (s) {
--
1.6.1.2.14.gf26b5
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH] mm: Make it easier to catch NULL cache names
2009-07-28 1:48 [PATCH] mm: Make it easier to catch NULL cache names Benjamin Herrenschmidt
@ 2009-07-28 2:52 ` Linus Torvalds
2009-07-28 2:55 ` Benjamin Herrenschmidt
0 siblings, 1 reply; 8+ messages in thread
From: Linus Torvalds @ 2009-07-28 2:52 UTC (permalink / raw)
To: Benjamin Herrenschmidt; +Cc: Andrew Morton, Linux Kernel list, linux-mm
On Tue, 28 Jul 2009, Benjamin Herrenschmidt wrote:
>
> Right now, if you inadvertently pass NULL to kmem_cache_create() at boot
> time, it crashes much later after boot somewhere deep inside sysfs which
> makes it very non obvious to figure out what's going on.
Please don't do BUG_ON() when there are alternatives.
In this case, something like
if (WARN_ON(!name))
return NULL;
would probably have worked too.
Linus
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] mm: Make it easier to catch NULL cache names
2009-07-28 2:52 ` Linus Torvalds
@ 2009-07-28 2:55 ` Benjamin Herrenschmidt
2009-07-28 5:01 ` David Rientjes
0 siblings, 1 reply; 8+ messages in thread
From: Benjamin Herrenschmidt @ 2009-07-28 2:55 UTC (permalink / raw)
To: Linus Torvalds; +Cc: Andrew Morton, Linux Kernel list, linux-mm
On Mon, 2009-07-27 at 19:52 -0700, Linus Torvalds wrote:
>
> On Tue, 28 Jul 2009, Benjamin Herrenschmidt wrote:
> >
> > Right now, if you inadvertently pass NULL to kmem_cache_create() at boot
> > time, it crashes much later after boot somewhere deep inside sysfs which
> > makes it very non obvious to figure out what's going on.
>
> Please don't do BUG_ON() when there are alternatives.
>
> In this case, something like
>
> if (WARN_ON(!name))
> return NULL;
>
> would probably have worked too.
Fair enough.. I'll send a new patch.
Cheers,
Ben.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] mm: Make it easier to catch NULL cache names
2009-07-28 2:55 ` Benjamin Herrenschmidt
@ 2009-07-28 5:01 ` David Rientjes
2009-07-28 7:39 ` Benjamin Herrenschmidt
0 siblings, 1 reply; 8+ messages in thread
From: David Rientjes @ 2009-07-28 5:01 UTC (permalink / raw)
To: Benjamin Herrenschmidt
Cc: Linus Torvalds, Andrew Morton, Linux Kernel list, linux-mm
On Tue, 28 Jul 2009, Benjamin Herrenschmidt wrote:
> > Please don't do BUG_ON() when there are alternatives.
> >
> > In this case, something like
> >
> > if (WARN_ON(!name))
> > return NULL;
> >
> > would probably have worked too.
>
> Fair enough.. I'll send a new patch.
>
Actually needs goto err, not return NULL, to appropriately panic when
SLAB_PANIC is set.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] mm: Make it easier to catch NULL cache names
2009-07-28 5:01 ` David Rientjes
@ 2009-07-28 7:39 ` Benjamin Herrenschmidt
0 siblings, 0 replies; 8+ messages in thread
From: Benjamin Herrenschmidt @ 2009-07-28 7:39 UTC (permalink / raw)
To: David Rientjes; +Cc: Linus Torvalds, Andrew Morton, Linux Kernel list, linux-mm
On Mon, 2009-07-27 at 22:01 -0700, David Rientjes wrote:
> On Tue, 28 Jul 2009, Benjamin Herrenschmidt wrote:
>
> > > Please don't do BUG_ON() when there are alternatives.
> > >
> > > In this case, something like
> > >
> > > if (WARN_ON(!name))
> > > return NULL;
> > >
> > > would probably have worked too.
> >
> > Fair enough.. I'll send a new patch.
> >
>
> Actually needs goto err, not return NULL, to appropriately panic when
> SLAB_PANIC is set.
Rats ! Why is it the trivial ones that are sooo hard :-)
New patch will have to wait til tomorrow, on my way home now.
Cheers,
Ben.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH] mm: Make it easier to catch NULL cache names
@ 2009-07-28 4:11 Benjamin Herrenschmidt
2009-07-29 0:06 ` Andrew Morton
0 siblings, 1 reply; 8+ messages in thread
From: Benjamin Herrenschmidt @ 2009-07-28 4:11 UTC (permalink / raw)
To: Linus Torvalds; +Cc: Andrew Morton, Linux Kernel list, linux-mm
Right now, if you inadvertently pass NULL to kmem_cache_create() at boot
time, it crashes much later after boot somewhere deep inside sysfs which
makes it very non obvious to figure out what's going on.
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---
Yes, I did hit that :-) Something in ppc land using an array of caches
and got the names array out of sync with changes to the list of indices.
mm/slub.c | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/mm/slub.c b/mm/slub.c
index b9f1491..e31fbe6 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -3292,6 +3292,9 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
{
struct kmem_cache *s;
+ if (WARN_ON(!name))
+ return NULL;
+
down_write(&slub_lock);
s = find_mergeable(size, align, flags, name, ctor);
if (s) {
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH] mm: Make it easier to catch NULL cache names
2009-07-28 4:11 Benjamin Herrenschmidt
@ 2009-07-29 0:06 ` Andrew Morton
2009-07-29 5:55 ` Benjamin Herrenschmidt
0 siblings, 1 reply; 8+ messages in thread
From: Andrew Morton @ 2009-07-29 0:06 UTC (permalink / raw)
To: Benjamin Herrenschmidt; +Cc: torvalds, linux-kernel, linux-mm, Pekka Enberg
On Tue, 28 Jul 2009 14:11:29 +1000
Benjamin Herrenschmidt <benh@kernel.crashing.org> wrote:
> Right now, if you inadvertently pass NULL to kmem_cache_create() at boot
> time, it crashes much later after boot somewhere deep inside sysfs which
> makes it very non obvious to figure out what's going on.
That must have been a pretty dumb piece of kernel code. It's a bit
questionable (IMO) whether we need to cater for really exceptional
bugs. But whatever.
slab used to have a check (__get_user) to see whether the ->name field
was still readable. This was to detect the case where the slab cache
was created from a kernel module and the module forgot to remove the
cache at rmmod-time. Subsequent reads of /proc/slabinfo would
confusingly go splat. The check seems to have been removed (from
slab.c, at least). If it is still there then it should be applied
consistently and across all slab versions. In which case that check
would make your patch arguably-unneeded. But it seems to have got
itself zapped.
> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> ---
>
> Yes, I did hit that :-) Something in ppc land using an array of caches
> and got the names array out of sync with changes to the list of indices.
>
> mm/slub.c | 3 +++
> 1 files changed, 3 insertions(+), 0 deletions(-)
>
> diff --git a/mm/slub.c b/mm/slub.c
> index b9f1491..e31fbe6 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -3292,6 +3292,9 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
> {
> struct kmem_cache *s;
>
> + if (WARN_ON(!name))
> + return NULL;
> +
> down_write(&slub_lock);
> s = find_mergeable(size, align, flags, name, ctor);
> if (s) {
Let's see:
slab.c: goes BUG
slob.c: will apparently go oops at some later time
slqb.c: does dump_stack(), returns NULL from kmem_cache_create()
slub.c: does WARN(), returns NULL from kmem_cache_create()
I think I'll apply the patch, cc Pekka then run away.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH] mm: Make it easier to catch NULL cache names
2009-07-29 0:06 ` Andrew Morton
@ 2009-07-29 5:55 ` Benjamin Herrenschmidt
0 siblings, 0 replies; 8+ messages in thread
From: Benjamin Herrenschmidt @ 2009-07-29 5:55 UTC (permalink / raw)
To: Andrew Morton; +Cc: torvalds, linux-kernel, linux-mm, Pekka Enberg
On Tue, 2009-07-28 at 17:06 -0700, Andrew Morton wrote:
> On Tue, 28 Jul 2009 14:11:29 +1000
> Benjamin Herrenschmidt <benh@kernel.crashing.org> wrote:
>
> > Right now, if you inadvertently pass NULL to kmem_cache_create() at boot
> > time, it crashes much later after boot somewhere deep inside sysfs which
> > makes it very non obvious to figure out what's going on.
>
> That must have been a pretty dumb piece of kernel code. It's a bit
> questionable (IMO) whether we need to cater for really exceptional
> bugs. But whatever.
:-)
It was an array of caches created from something like an enum and the
array of names got out of sync :-)
> slab used to have a check (__get_user) to see whether the ->name field
> was still readable. This was to detect the case where the slab cache
> was created from a kernel module and the module forgot to remove the
> cache at rmmod-time. Subsequent reads of /proc/slabinfo would
> confusingly go splat. The check seems to have been removed (from
> slab.c, at least). If it is still there then it should be applied
> consistently and across all slab versions. In which case that check
> would make your patch arguably-unneeded. But it seems to have got
> itself zapped.
That sounds like a better idea. However, it looks like we create sysfs
things and pass that pointer down to sysfs nowadays, so that's going to
blow up somewhere in the guts of sysfs unless we duplicate the string.
The advantage of duplicating the string would also be that we could
blow up right away if it's NULL :-)
Cheers,
Ben.
> > Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> > ---
> >
> > Yes, I did hit that :-) Something in ppc land using an array of caches
> > and got the names array out of sync with changes to the list of indices.
> >
> > mm/slub.c | 3 +++
> > 1 files changed, 3 insertions(+), 0 deletions(-)
> >
> > diff --git a/mm/slub.c b/mm/slub.c
> > index b9f1491..e31fbe6 100644
> > --- a/mm/slub.c
> > +++ b/mm/slub.c
> > @@ -3292,6 +3292,9 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
> > {
> > struct kmem_cache *s;
> >
> > + if (WARN_ON(!name))
> > + return NULL;
> > +
> > down_write(&slub_lock);
> > s = find_mergeable(size, align, flags, name, ctor);
> > if (s) {
>
> Let's see:
>
> slab.c: goes BUG
> slob.c: will apparently go oops at some later time
> slqb.c: does dump_stack(), returns NULL from kmem_cache_create()
> slub.c: does WARN(), returns NULL from kmem_cache_create()
>
>
> I think I'll apply the patch, cc Pekka then run away.
>
> --
> To unsubscribe, send a message with 'unsubscribe linux-mm' in
> the body to majordomo@kvack.org. For more info on Linux MM,
> see: http://www.linux-mm.org/ .
> Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2009-07-29 5:55 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-28 1:48 [PATCH] mm: Make it easier to catch NULL cache names Benjamin Herrenschmidt
2009-07-28 2:52 ` Linus Torvalds
2009-07-28 2:55 ` Benjamin Herrenschmidt
2009-07-28 5:01 ` David Rientjes
2009-07-28 7:39 ` Benjamin Herrenschmidt
-- strict thread matches above, loose matches on Subject: below --
2009-07-28 4:11 Benjamin Herrenschmidt
2009-07-29 0:06 ` Andrew Morton
2009-07-29 5:55 ` Benjamin Herrenschmidt
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).