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

fs, jfs: remove slab object constructor

Mempools based on slab caches with object constructors are risky because
element allocation can happen either from the slab cache itself, meaning
the constructor is properly called before returning, or from the mempool
reserve pool, meaning the constructor is not called before returning,
depending on the allocation context.

For this reason, we should disallow creating mempools based on slab caches
that have object constructors. Callers of mempool_alloc() will be
responsible for properly initializing the returned element.

Then, it doesn't matter if the element came from the slab cache or the
mempool reserved pool.

The only occurrence of a mempool being based on a slab cache with an
object constructor in the tree is in fs/jfs/jfs_metapage.c. Remove it and
properly initialize the element in alloc_metapage().

At the same time, META_free is never used, so remove it as well.

Signed-off-by: David Rientjes <rientjes@google.com>
Acked-by: Dave Kleikamp <dave.kleikamp@oracle.com>
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
ee146245 4db0c3c2

+12 -20
+12 -19
fs/jfs/jfs_metapage.c
··· 183 183 184 184 #endif 185 185 186 - static void init_once(void *foo) 187 - { 188 - struct metapage *mp = (struct metapage *)foo; 189 - 190 - mp->lid = 0; 191 - mp->lsn = 0; 192 - mp->flag = 0; 193 - mp->data = NULL; 194 - mp->clsn = 0; 195 - mp->log = NULL; 196 - set_bit(META_free, &mp->flag); 197 - init_waitqueue_head(&mp->wait); 198 - } 199 - 200 186 static inline struct metapage *alloc_metapage(gfp_t gfp_mask) 201 187 { 202 - return mempool_alloc(metapage_mempool, gfp_mask); 188 + struct metapage *mp = mempool_alloc(metapage_mempool, gfp_mask); 189 + 190 + if (mp) { 191 + mp->lid = 0; 192 + mp->lsn = 0; 193 + mp->data = NULL; 194 + mp->clsn = 0; 195 + mp->log = NULL; 196 + init_waitqueue_head(&mp->wait); 197 + } 198 + return mp; 203 199 } 204 200 205 201 static inline void free_metapage(struct metapage *mp) 206 202 { 207 - mp->flag = 0; 208 - set_bit(META_free, &mp->flag); 209 - 210 203 mempool_free(mp, metapage_mempool); 211 204 } 212 205 ··· 209 216 * Allocate the metapage structures 210 217 */ 211 218 metapage_cache = kmem_cache_create("jfs_mp", sizeof(struct metapage), 212 - 0, 0, init_once); 219 + 0, 0, NULL); 213 220 if (metapage_cache == NULL) 214 221 return -ENOMEM; 215 222
-1
fs/jfs/jfs_metapage.h
··· 48 48 49 49 /* metapage flag */ 50 50 #define META_locked 0 51 - #define META_free 1 52 51 #define META_dirty 2 53 52 #define META_sync 3 54 53 #define META_discard 4