From akpm@linux-foundation.org Fri Aug 24 16:12:31 2007 From: Andrew Morton Date: Fri, 24 Aug 2007 16:11:54 -0700 Subject: sysfs: crash debugging To: mm-commits@vger.kernel.org Cc: akpm@linux-foundation.org, greg@kroah.com, kay.sievers@vrfy.org, mathieu.desnoyers@polymtl.ca Message-ID: <200708242311.l7ONBsvq019579@imap1.linux-foundation.org> Print the name of the last-accessed sysfs file when we oops, to help track down oopses which occur in sysfs store/read handlers. Because these oopses tend to not leave any trace of the offending code in the stack traces. Cc: Kay Sievers Cc: Mathieu Desnoyers Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- arch/i386/kernel/traps.c | 1 + arch/x86_64/kernel/traps.c | 1 + fs/sysfs/file.c | 14 ++++++++++++++ fs/sysfs/mount.c | 2 +- fs/sysfs/sysfs.h | 1 + include/linux/sysfs.h | 5 +++++ 6 files changed, 23 insertions(+), 1 deletion(-) --- a/arch/i386/kernel/traps.c +++ b/arch/i386/kernel/traps.c @@ -416,6 +416,7 @@ void die(const char * str, struct pt_reg #endif if (nl) printk("\n"); + sysfs_printk_last_file(); if (notify_die(DIE_OOPS, str, regs, err, current->thread.trap_no, SIGSEGV) != NOTIFY_STOP) { --- a/arch/x86_64/kernel/traps.c +++ b/arch/x86_64/kernel/traps.c @@ -521,6 +521,7 @@ void __kprobes __die(const char * str, s printk("DEBUG_PAGEALLOC"); #endif printk("\n"); + sysfs_printk_last_file(); notify_die(DIE_OOPS, str, regs, err, current->thread.trap_no, SIGSEGV); show_registers(regs); add_taint(TAINT_DIE); --- a/fs/sysfs/file.c +++ b/fs/sysfs/file.c @@ -9,12 +9,20 @@ #include #include #include +#include #include #include "sysfs.h" #define to_sattr(a) container_of(a,struct subsys_attribute, attr) +/* used in crash dumps to help with debugging */ +static char last_sysfs_file[PATH_MAX]; +void sysfs_printk_last_file(void) +{ + printk(KERN_EMERG "last sysfs file: %s\n", last_sysfs_file); +} + /* * Subsystem file operations. * These operations allow subsystems to have files that can be @@ -245,6 +253,12 @@ static int sysfs_open_file(struct inode struct sysfs_buffer * buffer; struct sysfs_ops * ops = NULL; int error; + char *p; + + p = d_path(file->f_dentry, sysfs_mount, last_sysfs_file, + sizeof(last_sysfs_file)); + if (p) + memmove(last_sysfs_file, p, strlen(p) + 1); /* need attr_sd for attr and ops, its parent for kobj */ if (!sysfs_get_active_two(attr_sd)) --- a/fs/sysfs/mount.c +++ b/fs/sysfs/mount.c @@ -14,7 +14,7 @@ /* Random magic number */ #define SYSFS_MAGIC 0x62656572 -static struct vfsmount *sysfs_mount; +struct vfsmount *sysfs_mount; struct super_block * sysfs_sb = NULL; struct kmem_cache *sysfs_dir_cachep; --- a/fs/sysfs/sysfs.h +++ b/fs/sysfs/sysfs.h @@ -52,6 +52,7 @@ struct sysfs_addrm_cxt { extern struct sysfs_dirent sysfs_root; extern struct kmem_cache *sysfs_dir_cachep; +extern struct vfsmount *sysfs_mount; extern struct dentry *sysfs_get_dentry(struct sysfs_dirent *sd); extern struct sysfs_dirent *sysfs_get_active(struct sysfs_dirent *sd); --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -132,6 +132,7 @@ void sysfs_remove_file_from_group(struct const struct attribute *attr, const char *group); void sysfs_notify(struct kobject * k, char *dir, char *attr); +void sysfs_printk_last_file(void); extern int __must_check sysfs_init(void); @@ -233,6 +234,10 @@ static inline int __must_check sysfs_ini return 0; } +static inline void sysfs_printk_last_file(void) +{ +} + #endif /* CONFIG_SYSFS */ #endif /* _SYSFS_H_ */