aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Morton <akpm@linux-foundation.org>2007-08-24 19:11:54 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2008-10-16 12:24:41 -0400
commitae87221d3ce49d9de1e43756da834fd0bf05a2ad (patch)
treef96792656b00e95c307f3f37369c98a85ce38207
parente94320939f44e0cbaccc3f259a5778abced4949c (diff)
sysfs: crash debugging
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 <kay.sievers@vrfy.org> Cc: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r--arch/x86/kernel/dumpstack_32.c2
-rw-r--r--arch/x86/kernel/dumpstack_64.c2
-rw-r--r--fs/sysfs/file.c13
-rw-r--r--include/linux/sysfs.h6
4 files changed, 23 insertions, 0 deletions
diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
index 201ee359a1a9..1a78180f08d3 100644
--- a/arch/x86/kernel/dumpstack_32.c
+++ b/arch/x86/kernel/dumpstack_32.c
@@ -13,6 +13,7 @@
13#include <linux/kexec.h> 13#include <linux/kexec.h>
14#include <linux/bug.h> 14#include <linux/bug.h>
15#include <linux/nmi.h> 15#include <linux/nmi.h>
16#include <linux/sysfs.h>
16 17
17#include <asm/stacktrace.h> 18#include <asm/stacktrace.h>
18 19
@@ -343,6 +344,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
343 printk("DEBUG_PAGEALLOC"); 344 printk("DEBUG_PAGEALLOC");
344#endif 345#endif
345 printk("\n"); 346 printk("\n");
347 sysfs_printk_last_file();
346 if (notify_die(DIE_OOPS, str, regs, err, 348 if (notify_die(DIE_OOPS, str, regs, err,
347 current->thread.trap_no, SIGSEGV) == NOTIFY_STOP) 349 current->thread.trap_no, SIGSEGV) == NOTIFY_STOP)
348 return 1; 350 return 1;
diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
index 086cc8118e39..96a5db7da8a7 100644
--- a/arch/x86/kernel/dumpstack_64.c
+++ b/arch/x86/kernel/dumpstack_64.c
@@ -13,6 +13,7 @@
13#include <linux/kexec.h> 13#include <linux/kexec.h>
14#include <linux/bug.h> 14#include <linux/bug.h>
15#include <linux/nmi.h> 15#include <linux/nmi.h>
16#include <linux/sysfs.h>
16 17
17#include <asm/stacktrace.h> 18#include <asm/stacktrace.h>
18 19
@@ -489,6 +490,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
489 printk("DEBUG_PAGEALLOC"); 490 printk("DEBUG_PAGEALLOC");
490#endif 491#endif
491 printk("\n"); 492 printk("\n");
493 sysfs_printk_last_file();
492 if (notify_die(DIE_OOPS, str, regs, err, 494 if (notify_die(DIE_OOPS, str, regs, err,
493 current->thread.trap_no, SIGSEGV) == NOTIFY_STOP) 495 current->thread.trap_no, SIGSEGV) == NOTIFY_STOP)
494 return 1; 496 return 1;
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index c9e4e5091da1..ce8339c70a4b 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -19,10 +19,18 @@
19#include <linux/poll.h> 19#include <linux/poll.h>
20#include <linux/list.h> 20#include <linux/list.h>
21#include <linux/mutex.h> 21#include <linux/mutex.h>
22#include <linux/limits.h>
22#include <asm/uaccess.h> 23#include <asm/uaccess.h>
23 24
24#include "sysfs.h" 25#include "sysfs.h"
25 26
27/* used in crash dumps to help with debugging */
28static char last_sysfs_file[PATH_MAX];
29void sysfs_printk_last_file(void)
30{
31 printk(KERN_EMERG "last sysfs file: %s\n", last_sysfs_file);
32}
33
26/* 34/*
27 * There's one sysfs_buffer for each open file and one 35 * There's one sysfs_buffer for each open file and one
28 * sysfs_open_dirent for each sysfs_dirent with one or more open 36 * sysfs_open_dirent for each sysfs_dirent with one or more open
@@ -328,6 +336,11 @@ static int sysfs_open_file(struct inode *inode, struct file *file)
328 struct sysfs_buffer *buffer; 336 struct sysfs_buffer *buffer;
329 struct sysfs_ops *ops; 337 struct sysfs_ops *ops;
330 int error = -EACCES; 338 int error = -EACCES;
339 char *p;
340
341 p = d_path(&file->f_path, last_sysfs_file, sizeof(last_sysfs_file));
342 if (p)
343 memmove(last_sysfs_file, p, strlen(p) + 1);
331 344
332 /* need attr_sd for attr and ops, its parent for kobj */ 345 /* need attr_sd for attr and ops, its parent for kobj */
333 if (!sysfs_get_active_two(attr_sd)) 346 if (!sysfs_get_active_two(attr_sd))
diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
index 37fa24152bd8..8ec406afb3eb 100644
--- a/include/linux/sysfs.h
+++ b/include/linux/sysfs.h
@@ -119,6 +119,8 @@ void sysfs_remove_file_from_group(struct kobject *kobj,
119 119
120void sysfs_notify(struct kobject *kobj, char *dir, char *attr); 120void sysfs_notify(struct kobject *kobj, char *dir, char *attr);
121 121
122void sysfs_printk_last_file(void);
123
122extern int __must_check sysfs_init(void); 124extern int __must_check sysfs_init(void);
123 125
124#else /* CONFIG_SYSFS */ 126#else /* CONFIG_SYSFS */
@@ -231,6 +233,10 @@ static inline int __must_check sysfs_init(void)
231 return 0; 233 return 0;
232} 234}
233 235
236static inline void sysfs_printk_last_file(void)
237{
238}
239
234#endif /* CONFIG_SYSFS */ 240#endif /* CONFIG_SYSFS */
235 241
236#endif /* _SYSFS_H_ */ 242#endif /* _SYSFS_H_ */