Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mm, mempool: disallow mempools based on slab caches with constructors

All occurrences of mempools based on slab caches with object constructors
have been removed from the tree, so disallow creating them.

We can only dereference mem->ctor in mm/mempool.c without including
mm/slab.h in include/linux/mempool.h. So simply note the restriction,
just like the comment restricting usage of __GFP_ZERO, and warn on kernels
with CONFIG_DEBUG_VM() if such a mempool is allocated from.

We don't want to incur this check on every element allocation, so use
VM_BUG_ON().

Signed-off-by: David Rientjes <rientjes@google.com>
Cc: Dave Kleikamp <shaggy@kernel.org>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Sebastian Ott <sebott@linux.vnet.ibm.com>
Cc: Mikulas Patocka <mpatocka@redhat.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

David Rientjes and committed by
Linus Torvalds
e244c9e6 ee146245

+4 -1
+2 -1
include/linux/mempool.h
··· 36 36 37 37 /* 38 38 * A mempool_alloc_t and mempool_free_t that get the memory from 39 - * a slab that is passed in through pool_data. 39 + * a slab cache that is passed in through pool_data. 40 + * Note: the slab cache may not have a ctor function. 40 41 */ 41 42 void *mempool_alloc_slab(gfp_t gfp_mask, void *pool_data); 42 43 void mempool_free_slab(void *element, void *pool_data);
+2
mm/mempool.c
··· 15 15 #include <linux/mempool.h> 16 16 #include <linux/blkdev.h> 17 17 #include <linux/writeback.h> 18 + #include "slab.h" 18 19 19 20 static void add_element(mempool_t *pool, void *element) 20 21 { ··· 335 334 void *mempool_alloc_slab(gfp_t gfp_mask, void *pool_data) 336 335 { 337 336 struct kmem_cache *mem = pool_data; 337 + VM_BUG_ON(mem->ctor); 338 338 return kmem_cache_alloc(mem, gfp_mask); 339 339 } 340 340 EXPORT_SYMBOL(mempool_alloc_slab);