SLAB include file dependency fixes + kmemtrace updates
Subsystems (11)
Linus,
Please pull the latest kmemtrace-for-linus git tree from:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip.git kmemtrace-for-linus
We kept this topic separate from the main tracing tree due to the unexpectedly wide and messy-looking scope of the fixes Pekka needed to do to untangle various slab*.h, rcu*.h and fs.h dependency chains.
After the many preparatory fixes, the tree does a few straightforward changes to update kmemtrace to new-style tracing APIs and to sync up the user-tool-ABI.
( Please note that i rebased the tree exactly once, shortly after it
got finished, to make it all bisectable and reviewable: the perfect insight shown in the tree now was IMHO not humanly possible to achieve in advance.
In reality the real development flow did these changes exactly upside down: first we did the obvious change then all the non-obvious (and impossible to find via code reading) hidden dependency fixes, based on extensive testing.
It ended up being and looking quite a mess so the rebase was justified IMHO. This looked to me to be the exception that strengthens the rule, but plese let me know if this is frowned upon ... )
Known risks:
- Cross-arch or rare-config build breakages
No known regressions.
Thanks,
Ingo
------------------>
Eduard - Gabriel Munteanu (4):
kmemtrace, rcu: don't include unnecessary headers, allow kmemtrace w/ tracepoints
kmemtrace: use tracepoints
kmemtrace: kmemtrace_alloc() must fill type_id
kmemtrace: restore original tracing data binary format, improve ABI
Ingo Molnar (6):
kmemtrace, fs: uninline simple_transaction_set()
kmemtrace, fs: fix linux/fdtable.h header file dependencies kmemtrace, rcu: fix linux/rcutree.h and linux/rcuclassic.h dependencies kmemtrace, rcu: fix rcu_tree_trace.c data structure dependencies kmemtrace, rcu: fix rcupreempt.c data structure dependencies
kmemtrace: small cleanups
Pekka Enberg (9):
kmemtrace, fs, security: move alloc_secdata() and free_secdata() to linux/security.h kmemtrace, security: fix linux/key.h header file dependencies kmemtrace, befs: fix slab.h dependency problem
kmemtrace, squashfs: fix slab.h dependency problem in squasfs kmemtrace, kbuild: fix slab.h dependency problem in lib/decompress_inflate.c kmemtrace, kbuild: fix slab.h dependency problem in lib/decompress_bunzip2.c kmemtrace, kbuild: fix slab.h dependency problem in lib/decompress_unlzma.c kmemtrace, mm: fix slab.h dependency problem in mm/failslab.c
kmemtrace: trace kfree() calls with NULL or zero-length objects
fs/befs/debug.c | 1 + fs/libfs.c | 16 +++ fs/squashfs/export.c | 1 + include/linux/fdtable.h | 4 +- include/linux/fs.h | 35 +----- include/linux/key.h | 1 + include/linux/rcuclassic.h | 16 +-- include/linux/rcupdate.h | 1 - include/linux/rcupreempt.h | 53 ++------ include/linux/rcutree.h | 27 +---- include/linux/security.h | 24 ++++ include/linux/slab_def.h | 10 +- include/linux/slub_def.h | 12 +- include/trace/kmemtrace.h | 92 ++++++------- kernel/rcuclassic.c | 23 +++- kernel/rcupreempt.c | 48 ++++++- kernel/rcutree.c | 20 +++ kernel/rcutree.h | 10 ++ kernel/rcutree_trace.c | 2 + kernel/trace/kmemtrace.c | 319 ++++++++++++++++++++++++++++++------------- kernel/trace/trace.h | 6 + lib/decompress_bunzip2.c | 1 + lib/decompress_inflate.c | 1 + lib/decompress_unlzma.c | 1 + mm/failslab.c | 1 + mm/slab.c | 26 ++-- mm/slob.c | 30 ++--- mm/slub.c | 32 ++--- mm/util.c | 16 +++ 29 files changed, 493 insertions(+), 336 deletions(-) create mode 100644 kernel/rcutree.h
fs/befs/debug.c +1 -0
@@ -17,6 +17,7 @@#include <linux/spinlock.h> #include <linux/kernel.h> #include <linux/fs.h> +#include <linux/slab.h> #endif /* __KERNEL__ */
fs/libfs.c +16 -0
@@ -575,6 +575,21 @@ ssize_t memory_read_from_buffer(void *to, size_t count, loff_t *ppos,* possibly a read which collects the result - which is stored in a * file-local buffer. */ + +void simple_transaction_set (struct file *file,size_t n) +{ +struct simple_transaction_argresp *ar = file->private_data; + +BUG_ON (n >SIMPLE_TRANSACTION_LIMIT ); + +/* +* The barrier ensures that ar->size will really remain zero until +* ar->data is ready for reading. +*/ +smp_mb (); + ar->size = n; +} +char *simple_transaction_get (struct file *file,const char __user *buf,size_t size) {struct simple_transaction_argresp *ar;
@@ -820,6 +835,7 @@ EXPORT_SYMBOL(simple_sync_file);EXPORT_SYMBOL (simple_unlink);EXPORT_SYMBOL (simple_read_from_buffer);EXPORT_SYMBOL (memory_read_from_buffer); +EXPORT_SYMBOL (simple_transaction_set);EXPORT_SYMBOL (simple_transaction_get);EXPORT_SYMBOL (simple_transaction_read);EXPORT_SYMBOL (simple_transaction_release);
fs/squashfs/export.c +1 -0
@@ -40,6 +40,7 @@#include <linux/dcache.h> #include <linux/exportfs.h> #include <linux/zlib.h> +#include <linux/slab.h> #include "squashfs_fs.h" #include "squashfs_fs_sb.h"
include/linux/fdtable.h +3 -1
@@ -5,12 +5,14 @@#ifndef __LINUX_FDTABLE_H#define __LINUX_FDTABLE_H -#include <asm/atomic.h> #include <linux/posix_types.h> #include <linux/compiler.h> #include <linux/spinlock.h> #include <linux/rcupdate.h> #include <linux/types.h> +#include <linux/init.h> + +#include <asm/atomic.h> /* * The default fd array needs to be at least BITS_PER_LONG,
include/linux/fs.h +1 -34
@@ -2323,19 +2323,7 @@ ssize_t simple_transaction_read(struct file *file, char __user *buf, size_t size, loff_t *pos);int simple_transaction_release (struct inode *inode,struct file *file); -static inline void simple_transaction_set (struct file *file,size_t n) -{ -struct simple_transaction_argresp *ar = file->private_data; - -BUG_ON (n >SIMPLE_TRANSACTION_LIMIT ); - -/* -* The barrier ensures that ar->size will really remain zero until -* ar->data is ready for reading. -*/ -smp_mb (); - ar->size = n; -} +void simple_transaction_set (struct file *file,size_t n);/* * simple attribute files
@@ -2382,27 +2370,6 @@ ssize_t simple_attr_read(struct file *file, char __user *buf,ssize_t simple_attr_write (struct file *file,const char __user *buf,size_t len,loff_t *ppos); - -#ifdef CONFIG_SECURITY -static inline char *alloc_secdata (void ) -{ -return (char *)get_zeroed_page (GFP_KERNEL ); -} - -static inline void free_secdata (void *secdata) -{ -free_page ((unsigned long )secdata); -} -#else -static inline char *alloc_secdata (void ) -{ -return (char *)1 ; -} - -static inline void free_secdata (void *secdata) -{ } -#endif /* CONFIG_SECURITY */ -struct ctl_table ;int proc_nr_files (struct ctl_table *table,int write,struct file *filp,void __user *buffer,size_t *lenp,loff_t *ppos);
include/linux/key.h +1 -0
@@ -20,6 +20,7 @@#include <linux/rbtree.h> #include <linux/rcupdate.h> #include <linux/sysctl.h> +#include <linux/rwsem.h> #include <asm/atomic.h> #ifdef __KERNEL__
include/linux/rcuclassic.h +2 -14
@@ -36,7 +36,6 @@#include <linux/cache.h> #include <linux/spinlock.h> #include <linux/threads.h> -#include <linux/percpu.h> #include <linux/cpumask.h> #include <linux/seqlock.h>
@@ -108,25 +107,14 @@ struct rcu_data {struct rcu_head barrier; }; -DECLARE_PER_CPU(struct rcu_data, rcu_data); -DECLARE_PER_CPU(struct rcu_data, rcu_bh_data); -/* * Increment the quiescent state counter. * The counter is a bit degenerated: We do not need to know * how many quiescent states passed, just if there was at least * one since the start of the grace period. Thus just a flag. */ -static inline void rcu_qsctr_inc (int cpu) -{ -struct rcu_data *rdp = &per_cpu (rcu_data, cpu); - rdp->passed_quiesc =1 ; -} -static inline void rcu_bh_qsctr_inc (int cpu) -{ -struct rcu_data *rdp = &per_cpu (rcu_bh_data, cpu); - rdp->passed_quiesc =1 ; -} +extern void rcu_qsctr_inc (int cpu); +extern void rcu_bh_qsctr_inc (int cpu);extern int rcu_pending (int cpu);extern int rcu_needs_cpu (int cpu);
include/linux/rcupdate.h +0 -1
@@ -36,7 +36,6 @@#include <linux/cache.h> #include <linux/spinlock.h> #include <linux/threads.h> -#include <linux/percpu.h> #include <linux/cpumask.h> #include <linux/seqlock.h> #include <linux/lockdep.h>
include/linux/rcupreempt.h +10 -43
74 lines not on this page · raw message
include/linux/rcutree.h +2 -25
@@ -33,7 +33,6 @@#include <linux/cache.h> #include <linux/spinlock.h> #include <linux/threads.h> -#include <linux/percpu.h> #include <linux/cpumask.h> #include <linux/seqlock.h>
@@ -236,30 +235,8 @@ struct rcu_state {#endif /* #ifdef CONFIG_NO_HZ */ }; -extern struct rcu_state rcu_state; -DECLARE_PER_CPU(struct rcu_data, rcu_data); - -extern struct rcu_state rcu_bh_state; -DECLARE_PER_CPU(struct rcu_data, rcu_bh_data); - -/* -* Increment the quiescent state counter. -* The counter is a bit degenerated: We do not need to know -* how many quiescent states passed, just if there was at least -* one since the start of the grace period. Thus just a flag. -*/ -static inline void rcu_qsctr_inc (int cpu) -{ -struct rcu_data *rdp = &per_cpu (rcu_data, cpu); - rdp->passed_quiesc =1 ; - rdp->passed_quiesc_completed = rdp->completed; -} -static inline void rcu_bh_qsctr_inc (int cpu) -{ -struct rcu_data *rdp = &per_cpu (rcu_bh_data, cpu); - rdp->passed_quiesc =1 ; - rdp->passed_quiesc_completed = rdp->completed; -} +extern void rcu_qsctr_inc (int cpu); +extern void rcu_bh_qsctr_inc (int cpu);extern int rcu_pending (int cpu);extern int rcu_needs_cpu (int cpu);
include/linux/security.h +24 -0
@@ -32,6 +32,7 @@#include <linux/sched.h> #include <linux/key.h> #include <linux/xfrm.h> +#include <linux/gfp.h> #include <net/flow.h> /* Maximum number of letters for an LSM name string */
@@ -2953,5 +2954,28 @@ static inline void securityfs_remove(struct dentry *dentry)#endif +#ifdef CONFIG_SECURITY + +static inline char *alloc_secdata (void ) +{ +return (char *)get_zeroed_page (GFP_KERNEL ); +} + +static inline void free_secdata (void *secdata) +{ +free_page ((unsigned long )secdata); +} + +#else + +static inline char *alloc_secdata (void ) +{ +return (char *)1 ; +} + +static inline void free_secdata (void *secdata) +{ } +#endif /* CONFIG_SECURITY */ +#endif /* ! __LINUX_SECURITY_H */
include/linux/slab_def.h +5 -5
@@ -73,8 +73,8 @@ found: ret =kmem_cache_alloc_notrace (cachep, flags); -kmemtrace_mark_alloc (KMEMTRACE_TYPE_KMALLOC , _THIS_IP_, ret, - size,slab_buffer_size (cachep), flags); +trace_kmalloc (_THIS_IP_, ret, + size,slab_buffer_size (cachep), flags);return ret; }
@@ -128,9 +128,9 @@ found: ret =kmem_cache_alloc_node_notrace (cachep, flags, node); -kmemtrace_mark_alloc_node (KMEMTRACE_TYPE_KMALLOC , _THIS_IP_, - ret, size,slab_buffer_size (cachep), - flags, node); +trace_kmalloc_node (_THIS_IP_, ret, + size,slab_buffer_size (cachep), + flags, node);return ret; }
include/linux/slub_def.h +4 -8
@@ -233,8 +233,7 @@ static __always_inline void *kmalloc_large(size_t size, gfp_t flags)unsigned int order =get_order (size);void *ret = (void *)__get_free_pages (flags | __GFP_COMP, order); -kmemtrace_mark_alloc (KMEMTRACE_TYPE_KMALLOC , _THIS_IP_, ret, - size,PAGE_SIZE << order, flags); +trace_kmalloc (_THIS_IP_, ret, size,PAGE_SIZE << order, flags);return ret; }
@@ -255,9 +254,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags) ret =kmem_cache_alloc_notrace (s, flags); -kmemtrace_mark_alloc (KMEMTRACE_TYPE_KMALLOC , - _THIS_IP_, ret, - size, s->size, flags); +trace_kmalloc (_THIS_IP_, ret, size, s->size, flags);return ret; }
@@ -296,9 +293,8 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node) ret =kmem_cache_alloc_node_notrace (s, flags, node); -kmemtrace_mark_alloc_node (KMEMTRACE_TYPE_KMALLOC , - _THIS_IP_, ret, - size, s->size, flags, node); +trace_kmalloc_node (_THIS_IP_, ret, + size, s->size, flags, node);return ret; }
include/trace/kmemtrace.h +40 -52
105 lines not on this page · raw message
kernel/rcuclassic.c +21 -2
@@ -65,6 +65,7 @@ static struct rcu_ctrlblk rcu_ctrlblk = { .lock = __SPIN_LOCK_UNLOCKED(&rcu_ctrlblk.lock), .cpumask = CPU_BITS_NONE, }; +static struct rcu_ctrlblk rcu_bh_ctrlblk = { .cur =-300 , .completed =-300 ,
@@ -73,8 +74,26 @@ static struct rcu_ctrlblk rcu_bh_ctrlblk = { .cpumask = CPU_BITS_NONE, }; -DEFINE_PER_CPU(struct rcu_data, rcu_data) = { 0L }; -DEFINE_PER_CPU(struct rcu_data, rcu_bh_data) = { 0L }; +static DEFINE_PER_CPU(struct rcu_data, rcu_data); +static DEFINE_PER_CPU(struct rcu_data, rcu_bh_data); + +/* +* Increment the quiescent state counter. +* The counter is a bit degenerated: We do not need to know +* how many quiescent states passed, just if there was at least +* one since the start of the grace period. Thus just a flag. +*/ +void rcu_qsctr_inc (int cpu) +{ +struct rcu_data *rdp = &per_cpu (rcu_data, cpu); + rdp->passed_quiesc =1 ; +} + +void rcu_bh_qsctr_inc (int cpu) +{ +struct rcu_data *rdp = &per_cpu (rcu_bh_data, cpu); + rdp->passed_quiesc =1 ; +}static int blimit =10 ;static int qhimark =10000 ;
kernel/rcupreempt.c +44 -4
61 lines not on this page · raw message
kernel/rcutree.c +20 -0
@@ -78,6 +78,26 @@ DEFINE_PER_CPU(struct rcu_data, rcu_data);struct rcu_state rcu_bh_state =RCU_STATE_INITIALIZER (rcu_bh_state); DEFINE_PER_CPU(struct rcu_data, rcu_bh_data); +/* +* Increment the quiescent state counter. +* The counter is a bit degenerated: We do not need to know +* how many quiescent states passed, just if there was at least +* one since the start of the grace period. Thus just a flag. +*/ +void rcu_qsctr_inc (int cpu) +{ +struct rcu_data *rdp = &per_cpu (rcu_data, cpu); + rdp->passed_quiesc =1 ; + rdp->passed_quiesc_completed = rdp->completed; +} + +void rcu_bh_qsctr_inc (int cpu) +{ +struct rcu_data *rdp = &per_cpu (rcu_bh_data, cpu); + rdp->passed_quiesc =1 ; + rdp->passed_quiesc_completed = rdp->completed; +} +#ifdef CONFIG_NO_HZ DEFINE_PER_CPU(struct rcu_dynticks, rcu_dynticks) = { .dynticks_nesting = 1,
kernel/rcutree.h new file +10 -0
@@ -0,0 +1,10 @@ + +/* +* RCU implementation internal declarations: +*/ +extern struct rcu_state rcu_state; +DECLARE_PER_CPU(struct rcu_data, rcu_data); + +extern struct rcu_state rcu_bh_state; +DECLARE_PER_CPU(struct rcu_data, rcu_bh_data); +
kernel/rcutree_trace.c +2 -0
@@ -43,6 +43,8 @@#include <linux/debugfs.h> #include <linux/seq_file.h> +#include "rcutree.h" +static void print_one_rcu_data (struct seq_file *m,struct rcu_data *rdp) {if (!rdp->beenonline)
kernel/trace/kmemtrace.c +222 -97
413 lines not on this page · raw message
kernel/trace/trace.h +6 -0
@@ -182,6 +182,12 @@ struct trace_power {struct power_trace state_data; }; +enum kmemtrace_type_id { +KMEMTRACE_TYPE_KMALLOC =0 ,/* kmalloc() or kfree(). */ +KMEMTRACE_TYPE_CACHE ,/* kmem_cache_*(). */ +KMEMTRACE_TYPE_PAGES ,/* __get_free_pages() and friends. */ +}; +struct kmemtrace_alloc_entry {struct trace_entry ent;enum kmemtrace_type_id type_id;
lib/decompress_bunzip2.c +1 -0
@@ -50,6 +50,7 @@#endif /* !STATIC */ #include <linux/decompress/mm.h> +#include <linux/slab.h> #ifndef INT_MAX #define INT_MAX 0x7fffffff
lib/decompress_inflate.c +1 -0
@@ -23,6 +23,7 @@#endif /* STATIC */ #include <linux/decompress/mm.h> +#include <linux/slab.h> #define INBUF_LEN (16*1024)
lib/decompress_unlzma.c +1 -0
@@ -34,6 +34,7 @@#endif /* STATIC */ #include <linux/decompress/mm.h> +#include <linux/slab.h> #define MIN (a, b) (((a) < (b)) ? (a) : (b))
mm/failslab.c +1 -0
@@ -1,4 +1,5 @@#include <linux/fault-inject.h> +#include <linux/gfp.h> static struct { struct fault_attr attr;
mm/slab.c +12 -14
@@ -3565,8 +3565,8 @@ void *kmem_cache_alloc(struct kmem_cache *cachep, gfp_t flags) {void *ret =__cache_alloc (cachep, flags,__builtin_return_address (0 )); -kmemtrace_mark_alloc (KMEMTRACE_TYPE_CACHE , _RET_IP_, ret, -obj_size (cachep), cachep->buffer_size, flags); +trace_kmem_cache_alloc (_RET_IP_, ret, +obj_size (cachep), cachep->buffer_size, flags);return ret; }
@@ -3627,9 +3627,9 @@ void *kmem_cache_alloc_node(struct kmem_cache *cachep, gfp_t flags, int nodeid)void *ret =__cache_alloc_node (cachep, flags, nodeid,__builtin_return_address (0 )); -kmemtrace_mark_alloc_node (KMEMTRACE_TYPE_CACHE , _RET_IP_, ret, -obj_size (cachep), cachep->buffer_size, - flags, nodeid); +trace_kmem_cache_alloc_node (_RET_IP_, ret, +obj_size (cachep), cachep->buffer_size, + flags, nodeid);return ret; }
@@ -3657,9 +3657,8 @@ __do_kmalloc_node(size_t size, gfp_t flags, int node, void *caller)return cachep; ret =kmem_cache_alloc_node_notrace (cachep, flags, node); -kmemtrace_mark_alloc_node (KMEMTRACE_TYPE_KMALLOC , - (unsigned long ) caller, ret, - size, cachep->buffer_size, flags, node); +trace_kmalloc_node ((unsigned long ) caller, ret, + size, cachep->buffer_size, flags, node);return ret; }
@@ -3709,9 +3708,8 @@ static __always_inline void *__do_kmalloc(size_t size, gfp_t flags,return cachep; ret =__cache_alloc (cachep, flags, caller); -kmemtrace_mark_alloc (KMEMTRACE_TYPE_KMALLOC , - (unsigned long ) caller, ret, - size, cachep->buffer_size, flags); +trace_kmalloc ((unsigned long ) caller, ret, + size, cachep->buffer_size, flags);return ret; }
@@ -3757,7 +3755,7 @@ void kmem_cache_free(struct kmem_cache *cachep, void *objp)__cache_free (cachep, objp);local_irq_restore (flags); -kmemtrace_mark_free (KMEMTRACE_TYPE_CACHE , _RET_IP_, objp); +trace_kmem_cache_free (_RET_IP_, objp); }EXPORT_SYMBOL (kmem_cache_free);
@@ -3775,6 +3773,8 @@ void kfree(const void *objp)struct kmem_cache *c;unsigned long flags; +trace_kfree (_RET_IP_, objp); +if (unlikely (ZERO_OR_NULL_PTR (objp)))return ;local_irq_save (flags);
@@ -3784,8 +3784,6 @@ void kfree(const void *objp)debug_check_no_obj_freed (objp,obj_size (c));__cache_free (c, (void *)objp);local_irq_restore (flags); - -kmemtrace_mark_free (KMEMTRACE_TYPE_KMALLOC , _RET_IP_, objp); }EXPORT_SYMBOL (kfree);
mm/slob.c +13 -17
@@ -490,9 +490,8 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node) *m = size; ret = (void *)m + align; -kmemtrace_mark_alloc_node (KMEMTRACE_TYPE_KMALLOC , - _RET_IP_, ret, - size, size + align, gfp, node); +trace_kmalloc_node (_RET_IP_, ret, + size, size + align, gfp, node); }else {unsigned int order =get_order (size);
@@ -503,9 +502,8 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node) page->private = size; } -kmemtrace_mark_alloc_node (KMEMTRACE_TYPE_KMALLOC , - _RET_IP_, ret, - size,PAGE_SIZE << order, gfp, node); +trace_kmalloc_node (_RET_IP_, ret, + size,PAGE_SIZE << order, gfp, node); }return ret;
@@ -516,6 +514,8 @@ void kfree(const void *block) {struct slob_page *sp; +trace_kfree (_RET_IP_, block); +if (unlikely (ZERO_OR_NULL_PTR (block)))return ;
@@ -526,8 +526,6 @@ void kfree(const void *block)slob_free (m, *m + align); }else put_page (&sp->page); - -kmemtrace_mark_free (KMEMTRACE_TYPE_KMALLOC , _RET_IP_, block); }EXPORT_SYMBOL (kfree);
@@ -599,16 +597,14 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)if (c->size <PAGE_SIZE ) { b =slob_alloc (c->size, flags, c->align, node); -kmemtrace_mark_alloc_node (KMEMTRACE_TYPE_CACHE , - _RET_IP_, b, c->size, -SLOB_UNITS (c->size) *SLOB_UNIT , - flags, node); +trace_kmem_cache_alloc_node (_RET_IP_, b, c->size, +SLOB_UNITS (c->size) *SLOB_UNIT , + flags, node); }else { b =slob_new_pages (flags,get_order (c->size), node); -kmemtrace_mark_alloc_node (KMEMTRACE_TYPE_CACHE , - _RET_IP_, b, c->size, -PAGE_SIZE <<get_order (c->size), - flags, node); +trace_kmem_cache_alloc_node (_RET_IP_, b, c->size, +PAGE_SIZE <<get_order (c->size), + flags, node); }if (c->ctor)
@@ -646,7 +642,7 @@ void kmem_cache_free(struct kmem_cache *c, void *b)__kmem_cache_free (b, c->size); } -kmemtrace_mark_free (KMEMTRACE_TYPE_CACHE , _RET_IP_, b); +trace_kmem_cache_free (_RET_IP_, b); }EXPORT_SYMBOL (kmem_cache_free);
mm/slub.c +13 -19
@@ -1621,8 +1621,7 @@ void *kmem_cache_alloc(struct kmem_cache *s, gfp_t gfpflags) {void *ret =slab_alloc (s, gfpflags,-1 , _RET_IP_); -kmemtrace_mark_alloc (KMEMTRACE_TYPE_CACHE , _RET_IP_, ret, - s->objsize, s->size, gfpflags); +trace_kmem_cache_alloc (_RET_IP_, ret, s->objsize, s->size, gfpflags);return ret; }
@@ -1641,8 +1640,8 @@ void *kmem_cache_alloc_node(struct kmem_cache *s, gfp_t gfpflags, int node) {void *ret =slab_alloc (s, gfpflags, node, _RET_IP_); -kmemtrace_mark_alloc_node (KMEMTRACE_TYPE_CACHE , _RET_IP_, ret, - s->objsize, s->size, gfpflags, node); +trace_kmem_cache_alloc_node (_RET_IP_, ret, + s->objsize, s->size, gfpflags, node);return ret; }
@@ -1767,7 +1766,7 @@ void kmem_cache_free(struct kmem_cache *s, void *x)slab_free (s, page, x, _RET_IP_); -kmemtrace_mark_free (KMEMTRACE_TYPE_CACHE , _RET_IP_, x); +trace_kmem_cache_free (_RET_IP_, x); }EXPORT_SYMBOL (kmem_cache_free);
@@ -2702,8 +2701,7 @@ void *__kmalloc(size_t size, gfp_t flags) ret =slab_alloc (s, flags,-1 , _RET_IP_); -kmemtrace_mark_alloc (KMEMTRACE_TYPE_KMALLOC , _RET_IP_, ret, - size, s->size, flags); +trace_kmalloc (_RET_IP_, ret, size, s->size, flags);return ret; }
@@ -2729,10 +2727,9 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)if (unlikely (size >SLUB_MAX_SIZE )) { ret =kmalloc_large_node (size, flags, node); -kmemtrace_mark_alloc_node (KMEMTRACE_TYPE_KMALLOC , - _RET_IP_, ret, - size,PAGE_SIZE <<get_order (size), - flags, node); +trace_kmalloc_node (_RET_IP_, ret, + size,PAGE_SIZE <<get_order (size), + flags, node);return ret; }
@@ -2744,8 +2741,7 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node) ret =slab_alloc (s, flags, node, _RET_IP_); -kmemtrace_mark_alloc_node (KMEMTRACE_TYPE_KMALLOC , _RET_IP_, ret, - size, s->size, flags, node); +trace_kmalloc_node (_RET_IP_, ret, size, s->size, flags, node);return ret; }
@@ -2796,6 +2792,8 @@ void kfree(const void *x)struct page *page;void *object = (void *)x; +trace_kfree (_RET_IP_, x); +if (unlikely (ZERO_OR_NULL_PTR (x)))return ;
@@ -2806,8 +2804,6 @@ void kfree(const void *x)return ; }slab_free (page->slab, page, object, _RET_IP_); - -kmemtrace_mark_free (KMEMTRACE_TYPE_KMALLOC , _RET_IP_, x); }EXPORT_SYMBOL (kfree);
@@ -3290,8 +3286,7 @@ void *__kmalloc_track_caller(size_t size, gfp_t gfpflags, unsigned long caller) ret =slab_alloc (s, gfpflags,-1 , caller);/* Honor the call site pointer we recieved. */ -kmemtrace_mark_alloc (KMEMTRACE_TYPE_KMALLOC , caller, ret, size, - s->size, gfpflags); +trace_kmalloc (caller, ret, size, s->size, gfpflags);return ret; }
@@ -3313,8 +3308,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags, ret =slab_alloc (s, gfpflags, node, caller);/* Honor the call site pointer we recieved. */ -kmemtrace_mark_alloc_node (KMEMTRACE_TYPE_KMALLOC , caller, ret, - size, s->size, gfpflags, node); +trace_kmalloc_node (caller, ret, size, s->size, gfpflags, node);return ret; }
mm/util.c +16 -0
@@ -4,6 +4,7 @@#include <linux/module.h> #include <linux/err.h> #include <linux/sched.h> +#include <linux/tracepoint.h> #include <asm/uaccess.h> /**
@@ -236,3 +237,18 @@ int __attribute__((weak)) get_user_pages_fast(unsigned long start,return ret; }EXPORT_SYMBOL_GPL (get_user_pages_fast); + +/* Tracepoints definitions. */ +DEFINE_TRACE (kmalloc); +DEFINE_TRACE (kmem_cache_alloc); +DEFINE_TRACE (kmalloc_node); +DEFINE_TRACE (kmem_cache_alloc_node); +DEFINE_TRACE (kfree); +DEFINE_TRACE (kmem_cache_free); + +EXPORT_TRACEPOINT_SYMBOL (kmalloc); +EXPORT_TRACEPOINT_SYMBOL (kmem_cache_alloc); +EXPORT_TRACEPOINT_SYMBOL (kmalloc_node); +EXPORT_TRACEPOINT_SYMBOL (kmem_cache_alloc_node); +EXPORT_TRACEPOINT_SYMBOL (kfree); +EXPORT_TRACEPOINT_SYMBOL (kmem_cache_free);
Quoted 5 lines · Ingo Molnar
( Please note that i rebased the tree exactly once, shortly after it
got finished, to make it all bisectable and reviewable: the perfect insight shown in the tree now was IMHO not humanly possible to achieve in advance.
This is actually the rigth thing to do. Rebasing is not wrong, if it is done judiciously (and not on already-exposed stuff).
Rebasing is bad if
- you do it so late in the game that all test experience is basically worthless
- after you've pushed out and other people have seen and depend on that branch (and you didn't warn them)
- you do it to other peoples git commits, so that their tree (that was the source of the commit) now has the same commit duplicated as something else.
I wrote a posting about rebasing to Dave Airlie on dri-devel, that might be googleable. Hmm. Here:
http://www.mail-archive.com/[email protected]/msg39091.html
so rebase isn't bad, it's often a great way to fix things as you go along. It just goes with a few basic caveats.
Linus
Quoted 3 lines · Linus Torvalds
so rebase isn't bad, it's often a great way to fix things as you go along. It just goes with a few basic caveats.
Btw, rebasing gets a really bad name exactly because when those rules are violated, it ends up being _really_ painful and almost impossible for people to work together because the end result just ends up being some kind of patch-queue thing, and that just doesnt' work once the number of queue entries reach a certain pain threshold.
And it's happened in ACPI, DRI, ALSA, x86, etc, so those few basic caveats are easy to violate and then have everybody hate you. 'git rebase' is very useful (especially with '-i'), but it's really a dangerous tool in that it can really wreak havoc too.
Linus
Quoted 9 lines · Ingo Molnar
Please pull the latest kmemtrace-for-linus git tree from:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip.gitkmemtrace-for-linusWe kept this topic separate from the main tracing tree due to the unexpectedly wide and messy-looking scope of the fixes Pekka needed to do to untangle various slab*.h, rcu*.h and
fs.hdependency chains.
I'm not sure this is the tree that brings in the problem, but my wife's Mac Mini won't boot any more, and it looks like some slub or percpu issue, so regardless, roughly the right people are involved in the cc here already.
I get odd NUL page faults or GP faults in either __kmalloc, __kmalloc_track_caller or kmem_cache_alloc, and they all seem to happen on roughly the same code, ie it's something like this:
movq 752(%r13,%rax,8), %rdx # <variable>.cpu_slab, c
movl 24(%rdx), %eax # <variable>.objsize,
movl %eax, -44(%rbp) #, objsize
movq (%rdx), %r12 # <variable>.freelist, object
testq %r12, %r12 # object
je .L617 #,
mov 20(%rdx), %eax # <variable>.offset, <variable>.offset
-> movq (%r12,%rax,8), %rax #* object, tmp79
movq %rax, (%rdx) # tmp79, <variable>.freelistwhere that arrow points to the instruction that seems to be faulting.
I think it's this code:
object = c->freelist;
c->freelist = object[c->offset];and that "object[c->offset]" in particular.
I have not tried to bisect it yet, and I'll do that, but if this sounds familiar to anybody, please holler before I waste a lot of time on it.
Linus
Quoted 8 lines · Linus Torvalds
I'm not sure this is the tree that brings in the problem, but my wife's Mac Mini won't boot any more, and it looks like some slub or percpu issue, so regardless, roughly the right people are involved in the cc here already.
I get odd NUL page faults or GP faults in either
__kmalloc,__kmalloc_track_callerorkmem_cache_alloc
Hmm. Bisected to Andrew's big chunk of merges on April 1st. Right now I have
- bad: 527410ff7fc5d45fe41523c0ba061113dea22017 ("cirrusfb: GD5446 fixes")
- good: 63cd885426872254e82dac2d9e13ea4f720c21dc ("ntfs: remove private wrapper of endian helpers")
and all the commits in between are all from that same -mm series. Very interesting.
Anyway, the SLUB errors and the per-cpu'ness of the thing seems to have been a false lead and irrelevant.
Andrew, I'll continue to bisect. Looks like it might be the epoll changes (that's the only really 'core' thing there). Although I don't understand why those would make that Mac Mini unhappy, but not affect the other machines. So maybe I should just stop guessing until the bisection ends..
Linus
Quoted 5 lines · Linus Torvalds
Andrew, I'll continue to bisect. Looks like it might be the epoll changes (that's the only really 'core' thing there). Although I don't understand why those would make that Mac Mini unhappy, but not affect the other machines. So maybe I should just stop guessing until the bisection ends..
It bisected past them. I'm getting worried that it's timing-related, because nothing that remains looks even remotely interesting for that Mac mini, but right now:
- bad: 56fcef75117a153f298b3fe54af31053f53997dd
- good: bb233fdfc7b7cefe45bfa2e8d1b24e79c60a48e5
and there's not a whole lot of commits in between.
Linus
Quoted 9 lines · Linus Torvalds
It bisected past them. I'm getting worried that it's timing-related, because nothing that remains looks even remotely interesting for that Mac mini, but right now:
- bad:
56fcef75117a153f298b3fe54af31053f53997dd
- good:bb233fdfc7b7cefe45bfa2e8d1b24e79c60a48e5and there's not a whole lot of commits in between.
It's c3b1b1cbf002e65a3cabd479e68b5f35886a26db: 'ramfs: add support for "mode=" mount option'.
And I checked. Reverting it at the tip fixes it. So no random timing fluctuations.
So that commit causes some random SLAB corruption, that then (depending apparently on luck) may or may not crash in some odd random places later.
Wu?
Linus
Quoted 16 lines · Linus Torvalds
Quoted 9 lines · Linus Torvalds
It bisected past them. I'm getting worried that it's timing-related, because nothing that remains looks even remotely interesting for that Mac mini, but right now:
- bad:
56fcef75117a153f298b3fe54af31053f53997dd
- good:bb233fdfc7b7cefe45bfa2e8d1b24e79c60a48e5and there's not a whole lot of commits in between.
It's
c3b1b1cbf002e65a3cabd479e68b5f35886a26db: 'ramfs: add support for "mode=" mount option'.
Quoted 7 lines
And I checked. Reverting it at the tip fixes it. So no random timing fluctuations.
So that commit causes some random SLAB corruption, that then (depending apparently on luck) may or may not crash in some odd random places later.
Wu?
DON'T PANIC! -- The Hitchhiker's Guide to the Galaxy
I'm looking into this :)
Thanks,
Fengguang
PATCH 1/1 ramfs: add support for "mode=" mount option, fix
In reply to Linus TorvaldsQuoted 14 lines · Linus Torvalds
Quoted 9 lines · Linus Torvalds
It bisected past them. I'm getting worried that it's timing-related, because nothing that remains looks even remotely interesting for that Mac mini, but right now:
- bad:
56fcef75117a153f298b3fe54af31053f53997dd
- good:bb233fdfc7b7cefe45bfa2e8d1b24e79c60a48e5and there's not a whole lot of commits in between.
It's
c3b1b1cbf002e65a3cabd479e68b5f35886a26db: 'ramfs: add support for "mode=" mount option'.
Quoted 6 lines
And I checked. Reverting it at the tip fixes it. So no random timing fluctuations.
So that commit causes some random SLAB corruption, that then (depending apparently on luck) may or may not crash in some odd random places later.
ah - forget my previous mail then.
This commit does have a couple of genuinely odd looking lines.
For example:
+ sb->s_fs_info = fsi;
+
+ err = ramfs_parse_options(data, &fsi->mount_opts);
+ if (err)
+ goto fail;
Say we fail in ramfs_parse_options() and do the 'fail' pattern:
+fail:
+ kfree(fsi); + iput(inode); + return err;
so we have 'fsi' kfree()'d but dont clear sb->s_fs_info! That's almost always a bad practice. And indeed, in the kill_super callback:
+static void ramfs_kill_sb(struct super_block *sb) +{
+ kfree(sb->s_fs_info);
What ensures that this cannot be a double kfree() memory corruption? That pointer should have been cleared with something like the patch below. (totally untested)
And there's also another, probably just theoretical worry about another failure path:
+ fsi = kzalloc(sizeof(struct ramfs_fs_info), GFP_KERNEL);
+ if (!fsi) {
+ err = -ENOMEM;
+ goto fail;
+ }
+ sb->s_fs_info = fsi;
leaves sb->s_fs_info uninitialized in the failure case, and might hit this code unconditionally:
+static void ramfs_kill_sb(struct super_block *sb) +{
+ kfree(sb->s_fs_info);
+ kill_litter_super(sb);
+}
Leaving this code at the mercy of the external call environment initializing sb->s_fs_info. Which if it does not do (or stops doing in the future), can trigger a kfree of a random pointer.
(I think ->kill_super() gets called even if ->fill_super() fails, but i have not checked closely.)
These kinds of assymetric failure paths are really a red flag during review.
VFS infrastructure nit: we have 20 other similar looking but slightly differently implemented filesystem options parsers, in each filesystem. Might make sense to factor that out a bit and standardize it across all filesystems and make it all a bit safer. Duplicating code like that is never good IMHO.
Ingo
fs/ramfs/inode.c +11 -8
@@ -221,22 +221,23 @@ static int ramfs_fill_super(struct super_block * sb, void * data, int silent)save_mount_options (sb, data); fsi =kzalloc (sizeof (struct ramfs_fs_info ),GFP_KERNEL ); + sb->s_fs_info = fsi;if (!fsi) { err = -ENOMEM ; goto fail; } - sb->s_fs_info = fsi; err =ramfs_parse_options (data, &fsi->mount_opts);if (err) goto fail; - sb->s_maxbytes =MAX_LFS_FILESIZE ; - sb->s_blocksize =PAGE_CACHE_SIZE ; - sb->s_blocksize_bits =PAGE_CACHE_SHIFT ; - sb->s_magic =RAMFS_MAGIC ; - sb->s_op = &ramfs_ops; - sb->s_time_gran =1 ; + sb->s_maxbytes =MAX_LFS_FILESIZE ; + sb->s_blocksize =PAGE_CACHE_SIZE ; + sb->s_blocksize_bits =PAGE_CACHE_SHIFT ; + sb->s_magic =RAMFS_MAGIC ; + sb->s_op = &ramfs_ops; + sb->s_time_gran =1 ; + inode =ramfs_get_inode (sb,S_IFDIR | fsi->mount_opts.mode,0 );if (!inode) { err = -ENOMEM ;
@@ -244,14 +245,16 @@ static int ramfs_fill_super(struct super_block * sb, void * data, int silent) } root =d_alloc_root (inode); + sb->s_root = root;if (!root) { err = -ENOMEM ; goto fail; } - sb->s_root = root; +return 0 ; fail:kfree (fsi); + sb->s_fs_info =NULL ;iput (inode);return err; }
Re: [patch] ramfs: add support for "mode=" mount option, fix
Quoted 43 lines · Ingo Molnar
Quoted 14 lines · Linus Torvalds
Quoted 9 lines · Linus Torvalds
It bisected past them. I'm getting worried that it's timing-related, because nothing that remains looks even remotely interesting for that Mac mini, but right now:
- bad:
56fcef75117a153f298b3fe54af31053f53997dd
- good:bb233fdfc7b7cefe45bfa2e8d1b24e79c60a48e5and there's not a whole lot of commits in between.
It's
c3b1b1cbf002e65a3cabd479e68b5f35886a26db: 'ramfs: add support for "mode=" mount option'.Quoted 6 lines
And I checked. Reverting it at the tip fixes it. So no random timing fluctuations.
So that commit causes some random SLAB corruption, that then (depending apparently on luck) may or may not crash in some odd random places later.
ah - forget my previous mail then.
This commit does have a couple of genuinely odd looking lines.
For example:
(quoted diff) +5
-0+ sb->s_fs_info = fsi; + + err = ramfs_parse_options(data, &fsi->mount_opts); + if (err) + goto fail;Say we fail in
ramfs_parse_options()and do the 'fail' pattern:(quoted diff) +4
-0+fail: + kfree(fsi); + iput(inode); + return err;
Quoted 2 lines
so we have 'fsi' kfree()'d but dont clear
sb->s_fs_info! That's almost always a bad practice. And indeed, in thekill_super
Sorry - yes, the double kfree() shall be the root cause!
get_sb_nodev() calls kill_sb() after a failed fill_super():
error = fill_super(s, data, flags & MS_SILENT ? 1 : 0);
if (error) {
up_write(&s->s_umount);
deactivate_super(s);
return error;
}Quoted 29 lines
callback:
(quoted diff) +3
-0+static void ramfs_kill_sb(struct super_block *sb) +{ + kfree(sb->s_fs_info);What ensures that this cannot be a double
kfree()memory corruption? That pointer should have been cleared with something like the patch below. (totally untested)And there's also another, probably just theoretical worry about another failure path:
(quoted diff) +6
-0+ fsi = kzalloc(sizeof(struct ramfs_fs_info), GFP_KERNEL); + if (!fsi) { + err = -ENOMEM; + goto fail; + } + sb->s_fs_info = fsi;leaves
sb->s_fs_infouninitialized in the failure case, and might hit this code unconditionally:(quoted diff) +5
-0+static void ramfs_kill_sb(struct super_block *sb) +{ + kfree(sb->s_fs_info); + kill_litter_super(sb); +}
Quoted 6 lines
Leaving this code at the mercy of the external call environment initializing
sb->s_fs_info. Which if it does not do (or stops doing in the future), can trigger a kfree of a random pointer.(I think ->kill_super() gets called even if ->fill_super() fails, but i have not checked closely.)
You are right, see above.
Quoted 11 lines
These kinds of assymetric failure paths are really a red flag during review.
VFS infrastructure nit: we have 20 other similar looking but slightly differently implemented filesystem options parsers, in each filesystem. Might make sense to factor that out a bit and standardize it across all filesystems and make it all a bit safer. Duplicating code like that is never good IMHO.
Ingo
The patch looks pretty good and runs OK here.
Thanks,
Fengguang
Quoted 53 lines
fs/ramfs/inode.c +11
-8@@ -221,22 +221,23 @@ static int ramfs_fill_super(struct super_block * sb, void * data, int silent)save_mount_options (sb, data); fsi =kzalloc (sizeof (struct ramfs_fs_info ),GFP_KERNEL ); + sb->s_fs_info = fsi;if (!fsi) { err = -ENOMEM ; goto fail; } - sb->s_fs_info = fsi; err =ramfs_parse_options (data, &fsi->mount_opts);if (err) goto fail; - sb->s_maxbytes =MAX_LFS_FILESIZE ; - sb->s_blocksize =PAGE_CACHE_SIZE ; - sb->s_blocksize_bits =PAGE_CACHE_SHIFT ; - sb->s_magic =RAMFS_MAGIC ; - sb->s_op = &ramfs_ops; - sb->s_time_gran =1 ; + sb->s_maxbytes =MAX_LFS_FILESIZE ; + sb->s_blocksize =PAGE_CACHE_SIZE ; + sb->s_blocksize_bits =PAGE_CACHE_SHIFT ; + sb->s_magic =RAMFS_MAGIC ; + sb->s_op = &ramfs_ops; + sb->s_time_gran =1 ; + inode =ramfs_get_inode (sb,S_IFDIR | fsi->mount_opts.mode,0 );if (!inode) { err = -ENOMEM ;@@ -244,14 +245,16 @@ static int ramfs_fill_super(struct super_block * sb, void * data, int silent) } root =d_alloc_root (inode); + sb->s_root = root;if (!root) { err = -ENOMEM ; goto fail; } - sb->s_root = root; +return 0 ; fail:kfree (fsi); + sb->s_fs_info =NULL ;iput (inode);return err; }
Re: [patch] ramfs: add support for "mode=" mount option, fix
Quoted 105 lines · Wu Fengguang
Quoted 43 lines · Ingo Molnar
Quoted 14 lines · Linus Torvalds
Quoted 9 lines · Linus Torvalds
It bisected past them. I'm getting worried that it's timing-related, because nothing that remains looks even remotely interesting for that Mac mini, but right now:
- bad:
56fcef75117a153f298b3fe54af31053f53997dd
- good:bb233fdfc7b7cefe45bfa2e8d1b24e79c60a48e5and there's not a whole lot of commits in between.
It's
c3b1b1cbf002e65a3cabd479e68b5f35886a26db: 'ramfs: add support for "mode=" mount option'.Quoted 6 lines
And I checked. Reverting it at the tip fixes it. So no random timing fluctuations.
So that commit causes some random SLAB corruption, that then (depending apparently on luck) may or may not crash in some odd random places later.
ah - forget my previous mail then.
This commit does have a couple of genuinely odd looking lines.
For example:
(quoted diff) +5
-0+ sb->s_fs_info = fsi; + + err = ramfs_parse_options(data, &fsi->mount_opts); + if (err) + goto fail;Say we fail in
ramfs_parse_options()and do the 'fail' pattern:(quoted diff) +4
-0+fail: + kfree(fsi); + iput(inode); + return err;Quoted 2 lines
so we have 'fsi' kfree()'d but dont clear
sb->s_fs_info! That's almost always a bad practice. And indeed, in thekill_superSorry - yes, the double
kfree()shall be the root cause!
get_sb_nodev()callskill_sb()after a failedfill_super():error = fill_super(s, data, flags & MS_SILENT ? 1 : 0); if (error) { up_write(&s->s_umount); deactivate_super(s); return error; }Quoted 29 lines
callback:
(quoted diff) +3
-0+static void ramfs_kill_sb(struct super_block *sb) +{ + kfree(sb->s_fs_info);What ensures that this cannot be a double
kfree()memory corruption? That pointer should have been cleared with something like the patch below. (totally untested)And there's also another, probably just theoretical worry about another failure path:
(quoted diff) +6
-0+ fsi = kzalloc(sizeof(struct ramfs_fs_info), GFP_KERNEL); + if (!fsi) { + err = -ENOMEM; + goto fail; + } + sb->s_fs_info = fsi;leaves
sb->s_fs_infouninitialized in the failure case, and might hit this code unconditionally:(quoted diff) +5
-0+static void ramfs_kill_sb(struct super_block *sb) +{ + kfree(sb->s_fs_info); + kill_litter_super(sb); +}Quoted 6 lines
Leaving this code at the mercy of the external call environment initializing
sb->s_fs_info. Which if it does not do (or stops doing in the future), can trigger a kfree of a random pointer.(I think ->kill_super() gets called even if ->fill_super() fails, but i have not checked closely.)
You are right, see above.
Quoted 9 lines
These kinds of assymetric failure paths are really a red flag during review.
VFS infrastructure nit: we have 20 other similar looking but slightly differently implemented filesystem options parsers, in each filesystem. Might make sense to factor that out a bit and standardize it across all filesystems and make it all a bit safer. Duplicating code like that is never good IMHO.
Quoted 6 lines
Quoted 2 lines
Ingo
Acked-by Wu Fengguang <[email protected]>The patch looks pretty good and runs OK here.
ok, good - i didnt even build it - you can add my signoff too:
Thanks,
Ingo
PATCH 1/1 ramfs: fix double freeing s_fs_info on failed mount
From: Ingo Molnar <[email protected]>
If ramfs mount fails, s_fs_info will be freed twice in ramfs_fill_super() and ramfs_kill_sb(), leading to kernel oops.
Consolidate and beautify the code.
Make sure s_fs_info and s_root are in known good states.
--- fs/ramfs/inode.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-)
fs/ramfs/inode.c +11 -8
@@ -221,22 +221,23 @@ static int ramfs_fill_super(struct supersave_mount_options (sb, data); fsi =kzalloc (sizeof (struct ramfs_fs_info ),GFP_KERNEL ); + sb->s_fs_info = fsi;if (!fsi) { err = -ENOMEM ; goto fail; } - sb->s_fs_info = fsi; err =ramfs_parse_options (data, &fsi->mount_opts);if (err) goto fail; - sb->s_maxbytes =MAX_LFS_FILESIZE ; - sb->s_blocksize =PAGE_CACHE_SIZE ; - sb->s_blocksize_bits =PAGE_CACHE_SHIFT ; - sb->s_magic =RAMFS_MAGIC ; - sb->s_op = &ramfs_ops; - sb->s_time_gran =1 ; + sb->s_maxbytes =MAX_LFS_FILESIZE ; + sb->s_blocksize =PAGE_CACHE_SIZE ; + sb->s_blocksize_bits =PAGE_CACHE_SHIFT ; + sb->s_magic =RAMFS_MAGIC ; + sb->s_op = &ramfs_ops; + sb->s_time_gran =1 ; + inode =ramfs_get_inode (sb,S_IFDIR | fsi->mount_opts.mode,0 );if (!inode) { err = -ENOMEM ;
@@ -244,14 +245,16 @@ static int ramfs_fill_super(struct super } root =d_alloc_root (inode); + sb->s_root = root;if (!root) { err = -ENOMEM ; goto fail; } - sb->s_root = root; +return 0 ; fail:kfree (fsi); + sb->s_fs_info =NULL ;iput (inode);return err; }
Re: [PATCH] ramfs: fix double freeing s_fs_info on failed mount
Quoted 10 lines · Wu Fengguang
From: Ingo Molnar <[email protected]>
If ramfs mount fails,
s_fs_infowill be freed twice inramfs_fill_super()andramfs_kill_sb(), leading to kernel oops.Consolidate and beautify the code. Make sure
s_fs_infoands_rootare in known good states.Acked-by Wu Fengguang <[email protected]>Signed-off-by Ingo Molnar <[email protected]>
Nit: the commit is missing a Reported-by :)
Linus might not insist on seeing his name mentioned yet another time in a commit, but it's generally good practice to always add bug report info and names.
Note that in this case the really hard work was there: Linus had to spend at least 2 hours on tracking down and bisecting this bug. (and Linus probably did this super-fast compared to the average tester - most other bug reporters spend a day or more on bisection, limited by lack of practice and by the slowness of kernel builds on ordinary hardware.)
So the real human effort was spent there, not in my 5 minutes on fixing the bug that Linus served on a plate - while the commit only credits me. That's not fair :)
See the tip:out-of-tree local commit i made and sent out.
Ingo
Re: [PATCH] ramfs: fix double freeing s_fs_info on failed mount
Quoted 27 lines · Ingo Molnar
Quoted 10 lines · Wu Fengguang
From: Ingo Molnar <[email protected]>
If ramfs mount fails,
s_fs_infowill be freed twice inramfs_fill_super()andramfs_kill_sb(), leading to kernel oops.Consolidate and beautify the code. Make sure
s_fs_infoands_rootare in known good states.Acked-by Wu Fengguang <[email protected]>Signed-off-by Ingo Molnar <[email protected]>Nit: the commit is missing a Reported-by :)
Linus might not insist on seeing his name mentioned yet another time in a commit, but it's generally good practice to always add bug report info and names.
Note that in this case the really hard work was there: Linus had to spend at least 2 hours on tracking down and bisecting this bug. (and Linus probably did this super-fast compared to the average tester - most other bug reporters spend a day or more on bisection, limited by lack of practice and by the slowness of kernel builds on ordinary hardware.)
Quoted 3 lines
So the real human effort was spent there, not in my 5 minutes on fixing the bug that Linus served on a plate - while the commit only credits me. That's not fair :)
Good point! Thank you very much for mentoring me on this whole process!
Quoted 1 line
See the tip:out-of-tree local commit i made and sent out.
Yes I've seen that, very comprehensive changelog and solid&pretty code!
Best regards,
Fengguang Wu
PATCH 1/1 ramfs: add support for "mode=" mount option, fix
In reply to Wu FengguangQuoted 4 lines
From
7baa5532398708976ada2502ad11b37f872f6e9eMon Sep 17 00:00:00 2001
From: Ingo Molnar <[email protected]>
Date: Tue, 7 Apr 2009 07:28:01 +0200
Subject: [PATCH] ramfs: add support for "mode=" mount option, fix
Linus reported odd boot failures that showed memory corruption patterns in the SLUB code and bisected it down to c3b1b1cbf002e65a3cabd479e68b5f35886a26db: 'ramfs: add support for "mode=" mount option'.
That commit does have a couple of genuinely odd looking lines.
For example:
+ sb->s_fs_info = fsi;
+
+ err = ramfs_parse_options(data, &fsi->mount_opts);
+ if (err)
+ goto fail;
Say we fail in ramfs_parse_options() and do the 'fail' pattern:
+fail:
+ kfree(fsi); + iput(inode); + return err;
so we have 'fsi' kfree()'d but dont clear sb->s_fs_info! That's almost always a bad practice. And indeed, in the kill_super callback:
+static void ramfs_kill_sb(struct super_block *sb) +{
+ kfree(sb->s_fs_info);
What ensures that this cannot be a double kfree() memory corruption?
->kill_super() gets called even if ->fill_super() fails, so this is a double kfree() when there are no ramfs mount options - which results in memory corruption.
And there's also another, probably just theoretical worry about another failure path:
+ fsi = kzalloc(sizeof(struct ramfs_fs_info), GFP_KERNEL);
+ if (!fsi) {
+ err = -ENOMEM;
+ goto fail;
+ }
+ sb->s_fs_info = fsi;
leaves sb->s_fs_info uninitialized in the failure case, and might hit this code unconditionally:
+static void ramfs_kill_sb(struct super_block *sb) +{
+ kfree(sb->s_fs_info);
+ kill_litter_super(sb);
+}
Leaving this code at the mercy of the external call environment initializing sb->s_fs_info. Which if it does not do (or stops doing in the future), can trigger a kfree of a random pointer.
So improve this code a bit too, and improve the readability of other initializations here a bit.
--- fs/ramfs/inode.c | 19 +++++++++++-------- 1 files changed, 11 insertions(+), 8 deletions(-)
fs/ramfs/inode.c +11 -8
@@ -221,22 +221,23 @@ static int ramfs_fill_super(struct super_block * sb, void * data, int silent)save_mount_options (sb, data); fsi =kzalloc (sizeof (struct ramfs_fs_info ),GFP_KERNEL ); + sb->s_fs_info = fsi;if (!fsi) { err = -ENOMEM ; goto fail; } - sb->s_fs_info = fsi; err =ramfs_parse_options (data, &fsi->mount_opts);if (err) goto fail; - sb->s_maxbytes =MAX_LFS_FILESIZE ; - sb->s_blocksize =PAGE_CACHE_SIZE ; - sb->s_blocksize_bits =PAGE_CACHE_SHIFT ; - sb->s_magic =RAMFS_MAGIC ; - sb->s_op = &ramfs_ops; - sb->s_time_gran =1 ; + sb->s_maxbytes =MAX_LFS_FILESIZE ; + sb->s_blocksize =PAGE_CACHE_SIZE ; + sb->s_blocksize_bits =PAGE_CACHE_SHIFT ; + sb->s_magic =RAMFS_MAGIC ; + sb->s_op = &ramfs_ops; + sb->s_time_gran =1 ; + inode =ramfs_get_inode (sb,S_IFDIR | fsi->mount_opts.mode,0 );if (!inode) { err = -ENOMEM ;
@@ -244,14 +245,16 @@ static int ramfs_fill_super(struct super_block * sb, void * data, int silent) } root =d_alloc_root (inode); + sb->s_root = root;if (!root) { err = -ENOMEM ; goto fail; } - sb->s_root = root; +return 0 ; fail:kfree (fsi); + sb->s_fs_info =NULL ;iput (inode);return err; }
Quoted 16 lines · Linus Torvalds
Quoted 9 lines · Linus Torvalds
It bisected past them. I'm getting worried that it's timing-related, because nothing that remains looks even remotely interesting for that Mac mini, but right now:
- bad:
56fcef75117a153f298b3fe54af31053f53997dd
- good:bb233fdfc7b7cefe45bfa2e8d1b24e79c60a48e5and there's not a whole lot of commits in between.
It's
c3b1b1cbf002e65a3cabd479e68b5f35886a26db: 'ramfs: add support for "mode=" mount option'.
Quoted 7 lines
And I checked. Reverting it at the tip fixes it. So no random timing fluctuations.
So that commit causes some random SLAB corruption, that then (depending apparently on luck) may or may not crash in some odd random places later.
Wu?
Maybe this bug?
Thanks,
Fengguang
---
ramfs: fix double freeing s_fs_info
On a failed ramfs mount, s_fs_info will be freed twice in ramfs_fill_super() and ramfs_kill_sb(). Fix it by saving s_fs_info only on success.
---
fs/ramfs/inode.c +1 -1
@@ -225,7 +225,6 @@ static int ramfs_fill_super(struct super_block * sb, void * data, int silent) err = -ENOMEM ; goto fail; } - sb->s_fs_info = fsi; err =ramfs_parse_options (data, &fsi->mount_opts);if (err)
@@ -249,6 +248,7 @@ static int ramfs_fill_super(struct super_block * sb, void * data, int silent) goto fail; } sb->s_root = root; + sb->s_fs_info = fsi;return 0 ; fail:kfree (fsi);
(more folks Cc:-ed)
Quoted 30 lines · Linus Torvalds
Quoted 6 lines
git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip.gitkmemtrace-for-linusWe kept this topic separate from the main tracing tree due to the unexpectedly wide and messy-looking scope of the fixes Pekka needed to do to untangle various slab*.h, rcu*.h and
fs.hdependency chains.I'm not sure this is the tree that brings in the problem, but my wife's Mac Mini won't boot any more, and it looks like some slub or percpu issue, so regardless, roughly the right people are involved in the cc here already.
I get odd NUL page faults or GP faults in either
__kmalloc,__kmalloc_track_callerorkmem_cache_alloc, and they all seem to happen on roughly the same code, ie it's something like this:movq 752(%r13,%rax,8), %rdx # <variable>.cpu_slab, c movl 24(%rdx), %eax # <variable>.objsize, movl %eax, -44(%rbp) #, objsize movq (%rdx), %r12 # <variable>.freelist, object testq %r12, %r12 # object je .L617 #, mov 20(%rdx), %eax # <variable>.offset, <variable>.offset -> movq (%r12,%rax,8), %rax #* object, tmp79 movq %rax, (%rdx) # tmp79, <variable>.freelistwhere that arrow points to the instruction that seems to be faulting.
I think it's this code:
Quoted 8 lines
object = c->freelist; c->freelist = object[c->offset];and that "object[c->offset]" in particular.
I have not tried to bisect it yet, and I'll do that, but if this sounds familiar to anybody, please holler before I waste a lot of time on it.
Hm, this would suggest some sort of memory or data structure corruption.
There's no such pending bug (we wouldnt have pushed if there was anything of this severity). The historic track record:
- the kmemtrace hooks have been 100% problem free since last August. I mismerged them two times as SLUB changed upstream frequently them but there was no runtime failure that i can remember.
- percpu changes have a more spotty past: and the #GP might suggest something there: we can get a #GP if we go outside the %gs offset range and get a non-canonical address. All sorts of bugs have been observed here: runtime failures with #GP and memory corruption as well and linker bugs.
To investigate+exclude this angle, a precise .config, sha1, gcc and binutils version would be needed, to reproduce your exact kernel image. A dmesg would be helpful too - it's probably an EFI bootup which is rare, but i can try to take your bootup memory map dump in the dmesg and stuff it into an exactmap=<...> set of simulated memory environment - maybe that tickles the bug here too.
- [ stackprotector connects to percpu and got re-enabled - please double check you have it off in your config. ]
- [ cpumask changes have sometimes produced runtime crashes, and once a memory corruption - but only with CONFIG_CPUMASK_OFFSTACK=y which i doubt you have enabled. ]
So unless you have a good crash pattern with a smoking gun, and if it's reproducible but bisection does not lead anywhere (which your later mails suggest), it might make sense to boot up with the full array of memory related debugging checks enabled:
CONFIG_DEBUG_PAGEALLOC=y
CONFIG_SLUB_DEBUG=y
CONFIG_SLUB_DEBUG_ON=y
If the bug is timing or kernel image layout sensitive, this might hide it though.
Does it reproduce with maxcpus=1? If yes, it would weaken the percpu angle - paradoxially most of the percpu trouble we had during development was uniform and affected UP too.
Plus if it's a genuine memory corruptor and not timing sensitive and all other efforts fail, then there's also kmemcheck to try:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip.git kmemcheck
( Note: i merged this branch up to latest -git 30 seconds ago with 5
conflict resolutions half awake, but it will all be perfect, rest assured. [ If not - a build failure or so - have a look at the conflict resolutions ] If you try this you might have to tweak the .config a bit to make CONFIG_KMEMCHECK appear - it's dependent on a few things. Also - a kmemcheck false positive might hit the bootup sooner than a genuine memory corruption so even if it emits something, it might not be genuinely interesting. )
Ingo