fix weird kmalloc bug

fix weird kmalloc bug

Post by Paul Mackerra » Mon, 16 Jun 2003 04:40:05



Last night, Manfred and I found an interesting bug with kmalloc on
ppc32, where the kmalloc in alloc_super() (fs/super.c) was requesting
432 bytes but only getting 256 bytes.  The reason was that PAGE_SIZE
wasn't defined at the point where the kmalloc() inline function
occurs.  Thus the CACHE(32) entry got omitted from the list in
kmalloc_sizes.h, and kmalloc therefore used the entry in
malloc_sizes[] before the correct entry.

This patch fixes it by including asm/page.h and asm/cache.h in
linux/slab.h.  The list in kmalloc_sizes.h depends on L1_CACHE_BYTES
as well as PAGE_SIZE, which is why I added asm/cache.h.

Paul.

diff -urN linux-2.5/include/linux/slab.h pmac-2.5-smp/include/linux/slab.h
--- linux-2.5/include/linux/slab.h      2003-06-12 10:43:55.000000000 +1000

 #include       <linux/gfp.h>
 #include       <linux/types.h>
+#include       <asm/page.h>
+#include       <asm/cache.h>

 /* flags for kmem_cache_alloc() */
 #define        SLAB_NOFS               GFP_NOFS
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
 
 

fix weird kmalloc bug

Post by David S. Mille » Mon, 16 Jun 2003 08:10:07



> This patch fixes it by including asm/page.h and asm/cache.h in
> linux/slab.h.  The list in kmalloc_sizes.h depends on L1_CACHE_BYTES
> as well as PAGE_SIZE, which is why I added asm/cache.h.

Please use linux/cache.h, we should provide some kind of
"#error don't directly include asm/blah.h" protection into
various headers such as asm/cache.h, asm/delay.h, etc.

--

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/