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

seq_file: allocate seq_file from kmem_cache

For fine-grained debugging and usercopy protection.

Link: http://lkml.kernel.org/r/20180310085027.GA17121@avx2
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Reviewed-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Glauber Costa <glommer@gmail.com>
Cc: Vladimir Davydov <vdavydov.dev@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Alexey Dobriyan and committed by
Linus Torvalds
09652320 9ad553ab

+12 -2
+10 -2
fs/seq_file.c
··· 6 6 * initial implementation -- AV, Oct 2001. 7 7 */ 8 8 9 + #include <linux/cache.h> 9 10 #include <linux/fs.h> 10 11 #include <linux/export.h> 11 12 #include <linux/seq_file.h> ··· 19 18 20 19 #include <linux/uaccess.h> 21 20 #include <asm/page.h> 21 + 22 + static struct kmem_cache *seq_file_cache __ro_after_init; 22 23 23 24 static void seq_set_overflow(struct seq_file *m) 24 25 { ··· 54 51 55 52 WARN_ON(file->private_data); 56 53 57 - p = kzalloc(sizeof(*p), GFP_KERNEL); 54 + p = kmem_cache_zalloc(seq_file_cache, GFP_KERNEL); 58 55 if (!p) 59 56 return -ENOMEM; 60 57 ··· 369 366 { 370 367 struct seq_file *m = file->private_data; 371 368 kvfree(m->buf); 372 - kfree(m); 369 + kmem_cache_free(seq_file_cache, m); 373 370 return 0; 374 371 } 375 372 EXPORT_SYMBOL(seq_release); ··· 1109 1106 return NULL; 1110 1107 } 1111 1108 EXPORT_SYMBOL(seq_hlist_next_percpu); 1109 + 1110 + void __init seq_file_init(void) 1111 + { 1112 + seq_file_cache = KMEM_CACHE(seq_file, SLAB_PANIC); 1113 + }
+1
include/linux/seq_file.h
··· 240 240 241 241 extern struct hlist_node *seq_hlist_next_percpu(void *v, struct hlist_head __percpu *head, int *cpu, loff_t *pos); 242 242 243 + void seq_file_init(void); 243 244 #endif
+1
init/main.c
··· 715 715 vfs_caches_init(); 716 716 pagecache_init(); 717 717 signals_init(); 718 + seq_file_init(); 718 719 proc_root_init(); 719 720 nsfs_init(); 720 721 cpuset_init();