2007-05-31 00:30:54

by Christoph Lameter

[permalink] [raw]
Subject: [RFC 2/4] CONFIG_STABLE: Switch off kmalloc(0) tests in slab allocators

We do not want kmalloc(0) to trigger stackdumps if this is a stable
kernel. kmalloc(0) is currently harmless.

Signed-off-by: Christoph Lameter <[email protected]>

---
include/linux/slub_def.h | 2 ++
mm/slab.c | 2 ++
2 files changed, 4 insertions(+)

Index: slub/include/linux/slub_def.h
===================================================================
--- slub.orig/include/linux/slub_def.h 2007-05-30 16:35:05.000000000 -0700
+++ slub/include/linux/slub_def.h 2007-05-30 16:37:39.000000000 -0700
@@ -74,6 +74,7 @@ extern struct kmem_cache kmalloc_caches[
*/
static inline int kmalloc_index(size_t size)
{
+#ifndef CONFIG_STABLE
/*
* We should return 0 if size == 0 (which would result in the
* kmalloc caller to get NULL) but we use the smallest object
@@ -81,6 +82,7 @@ static inline int kmalloc_index(size_t s
* we can discover locations where we do 0 sized allocations.
*/
WARN_ON_ONCE(size == 0);
+#endif

if (size > KMALLOC_MAX_SIZE)
return -1;
Index: slub/mm/slab.c
===================================================================
--- slub.orig/mm/slab.c 2007-05-30 16:35:05.000000000 -0700
+++ slub/mm/slab.c 2007-05-30 16:37:39.000000000 -0700
@@ -774,7 +774,9 @@ static inline struct kmem_cache *__find_
*/
BUG_ON(malloc_sizes[INDEX_AC].cs_cachep == NULL);
#endif
+#ifndef CONFIG_STABLE
WARN_ON_ONCE(size == 0);
+#endif
while (size > csizep->cs_size)
csizep++;


--


2007-05-31 19:52:23

by Zach Brown

[permalink] [raw]
Subject: Re: [RFC 2/4] CONFIG_STABLE: Switch off kmalloc(0) tests in slab allocators

> +#ifndef CONFIG_STABLE
> /*
> * We should return 0 if size == 0 (which would result in the
> * kmalloc caller to get NULL) but we use the smallest object
> @@ -81,6 +82,7 @@ static inline int kmalloc_index(size_t s
> * we can discover locations where we do 0 sized allocations.
> */
> WARN_ON_ONCE(size == 0);
> +#endif

> +#ifndef CONFIG_STABLE
> WARN_ON_ONCE(size == 0);
> +#endif

I wonder if there wouldn't be value in making a WARN_*() variant that
contained the ifdef internally so we could lose these tedious
surrounding ifdefs in call sites. WARN_DEVELOPER_WHEN(), or something.
I don't care what it's called.

- z

2007-05-31 21:41:19

by Andi Kleen

[permalink] [raw]
Subject: Re: [RFC 2/4] CONFIG_STABLE: Switch off kmalloc(0) tests in slab allocators

Zach Brown <[email protected]> writes:

> > +#ifndef CONFIG_STABLE
> > /*
> > * We should return 0 if size == 0 (which would result in the
> > * kmalloc caller to get NULL) but we use the smallest object
> > @@ -81,6 +82,7 @@ static inline int kmalloc_index(size_t s
> > * we can discover locations where we do 0 sized allocations.
> > */
> > WARN_ON_ONCE(size == 0);
> > +#endif
>
> > +#ifndef CONFIG_STABLE
> > WARN_ON_ONCE(size == 0);
> > +#endif
>
> I wonder if there wouldn't be value in making a WARN_*() variant that
> contained the ifdef internally so we could lose these tedious
> surrounding ifdefs in call sites. WARN_DEVELOPER_WHEN(), or something.
> I don't care what it's called.

Networking has had NETDEBUG(codeblock) for this. Perhaps something
similar would be useful (DEVELOPMENT(codeblock)) in addition
to the special WARN/BUG_ONs

-Andi