Skip to content

Commit ae87221

Browse files
akpm00gregkh
authored andcommitted
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>
1 parent e943209 commit ae87221

4 files changed

Lines changed: 23 additions & 0 deletions

File tree

‎arch/x86/kernel/dumpstack_32.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/kexec.h>
1414
#include <linux/bug.h>
1515
#include <linux/nmi.h>
16+
#include <linux/sysfs.h>
1617

1718
#include <asm/stacktrace.h>
1819

@@ -343,6 +344,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
343344
printk("DEBUG_PAGEALLOC");
344345
#endif
345346
printk("\n");
347+
sysfs_printk_last_file();
346348
if (notify_die(DIE_OOPS, str, regs, err,
347349
current->thread.trap_no, SIGSEGV) == NOTIFY_STOP)
348350
return 1;

‎arch/x86/kernel/dumpstack_64.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/kexec.h>
1414
#include <linux/bug.h>
1515
#include <linux/nmi.h>
16+
#include <linux/sysfs.h>
1617

1718
#include <asm/stacktrace.h>
1819

@@ -489,6 +490,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
489490
printk("DEBUG_PAGEALLOC");
490491
#endif
491492
printk("\n");
493+
sysfs_printk_last_file();
492494
if (notify_die(DIE_OOPS, str, regs, err,
493495
current->thread.trap_no, SIGSEGV) == NOTIFY_STOP)
494496
return 1;

‎fs/sysfs/file.c‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,18 @@
1919
#include <linux/poll.h>
2020
#include <linux/list.h>
2121
#include <linux/mutex.h>
22+
#include <linux/limits.h>
2223
#include <asm/uaccess.h>
2324

2425
#include "sysfs.h"
2526

27+
/* used in crash dumps to help with debugging */
28+
static char last_sysfs_file[PATH_MAX];
29+
void sysfs_printk_last_file(void)
30+
{
31+
printk(KERN_EMERG "last sysfs file: %s\n", last_sysfs_file);
32+
}
33+
2634
/*
2735
* There's one sysfs_buffer for each open file and one
2836
* 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)
328336
struct sysfs_buffer *buffer;
329337
struct sysfs_ops *ops;
330338
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);
331344

332345
/* need attr_sd for attr and ops, its parent for kobj */
333346
if (!sysfs_get_active_two(attr_sd))

‎include/linux/sysfs.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ void sysfs_remove_file_from_group(struct kobject *kobj,
119119

120120
void sysfs_notify(struct kobject *kobj, char *dir, char *attr);
121121

122+
void sysfs_printk_last_file(void);
123+
122124
extern int __must_check sysfs_init(void);
123125

124126
#else /* CONFIG_SYSFS */
@@ -231,6 +233,10 @@ static inline int __must_check sysfs_init(void)
231233
return 0;
232234
}
233235

236+
static inline void sysfs_printk_last_file(void)
237+
{
238+
}
239+
234240
#endif /* CONFIG_SYSFS */
235241

236242
#endif /* _SYSFS_H_ */

0 commit comments

Comments
 (0)