1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
From: Andrew Morton <akpm@osdl.org>
Display the most-recently-opened sysfs file's name when oopsing.
From: Adrian Bunk <bunk@stusta.de>
Build fix
From: Greg Kroah-Hartman <gregkh@suse.de>
Modified to make the api call cleaner, and available to all arches if
need be. Also added it to x86-64's crash dump message.
Signed-off-by: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
arch/i386/kernel/traps.c | 1 +
arch/x86_64/kernel/traps.c | 1 +
fs/sysfs/file.c | 14 ++++++++++++++
include/linux/sysfs.h | 6 ++++++
4 files changed, 22 insertions(+)
--- a/arch/i386/kernel/traps.c
+++ b/arch/i386/kernel/traps.c
@@ -425,6 +425,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
@@ -533,6 +533,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);
/* Executive summary in case the oops scrolled away */
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -8,6 +8,7 @@
#include <linux/namei.h>
#include <linux/poll.h>
#include <linux/list.h>
+#include <linux/limits.h>
#include <asm/uaccess.h>
#include <asm/semaphore.h>
@@ -16,6 +17,13 @@
#define to_subsys(k) container_of(k,struct subsystem,kset.kobj)
#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
@@ -448,6 +456,7 @@ int sysfs_add_file(struct dentry * dir,
umode_t mode = (attr->mode & S_IALLUGO) | S_IFREG;
struct sysfs_dirent *sd;
int error = 0;
+ char *p;
mutex_lock(&dir->d_inode->i_mutex);
@@ -464,6 +473,11 @@ int sysfs_add_file(struct dentry * dir,
sd->s_elem.attr.attr = (void *)attr;
sysfs_attach_dirent(sd, parent_sd, NULL);
+ 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);
+
out_unlock:
mutex_unlock(&dir->d_inode->i_mutex);
return error;
--- a/include/linux/sysfs.h
+++ b/include/linux/sysfs.h
@@ -125,6 +125,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 sysfs_make_shadowed_dir(struct kobject *kobj,
@@ -240,6 +241,11 @@ static inline int __must_check sysfs_ini
return 0;
}
+static inline void sysfs_printk_last_file(void)
+{
+ ;
+}
+
#endif /* CONFIG_SYSFS */
#endif /* _SYSFS_H_ */
|