mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@suse.de>
To: linux-kernel@vger.kernel.org
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Kay Sievers <kay.sievers@vrfy.org>,
	Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>,
	Greg Kroah-Hartman <gregkh@suse.de>
Subject: [PATCH 02/46] sysfs: crash debugging
Date: Thu, 16 Oct 2008 10:10:03 -0700	[thread overview]
Message-ID: <1224177047-11859-2-git-send-email-gregkh@suse.de> (raw)
In-Reply-To: <20081016170954.GA11824@kroah.com>

From: Andrew Morton <akpm@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 <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>
---
 arch/x86/kernel/dumpstack_32.c |    2 ++
 arch/x86/kernel/dumpstack_64.c |    2 ++
 fs/sysfs/file.c                |   13 +++++++++++++
 include/linux/sysfs.h          |    6 ++++++
 4 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
index 201ee35..1a78180 100644
--- a/arch/x86/kernel/dumpstack_32.c
+++ b/arch/x86/kernel/dumpstack_32.c
@@ -13,6 +13,7 @@
 #include <linux/kexec.h>
 #include <linux/bug.h>
 #include <linux/nmi.h>
+#include <linux/sysfs.h>
 
 #include <asm/stacktrace.h>
 
@@ -343,6 +344,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
 	printk("DEBUG_PAGEALLOC");
 #endif
 	printk("\n");
+	sysfs_printk_last_file();
 	if (notify_die(DIE_OOPS, str, regs, err,
 			current->thread.trap_no, SIGSEGV) == NOTIFY_STOP)
 		return 1;
diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
index 086cc81..96a5db7 100644
--- a/arch/x86/kernel/dumpstack_64.c
+++ b/arch/x86/kernel/dumpstack_64.c
@@ -13,6 +13,7 @@
 #include <linux/kexec.h>
 #include <linux/bug.h>
 #include <linux/nmi.h>
+#include <linux/sysfs.h>
 
 #include <asm/stacktrace.h>
 
@@ -489,6 +490,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
 	printk("DEBUG_PAGEALLOC");
 #endif
 	printk("\n");
+	sysfs_printk_last_file();
 	if (notify_die(DIE_OOPS, str, regs, err,
 			current->thread.trap_no, SIGSEGV) == NOTIFY_STOP)
 		return 1;
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index c9e4e50..ce8339c 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -19,10 +19,18 @@
 #include <linux/poll.h>
 #include <linux/list.h>
 #include <linux/mutex.h>
+#include <linux/limits.h>
 #include <asm/uaccess.h>
 
 #include "sysfs.h"
 
+/* 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);
+}
+
 /*
  * There's one sysfs_buffer for each open file and one
  * 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)
 	struct sysfs_buffer *buffer;
 	struct sysfs_ops *ops;
 	int error = -EACCES;
+	char *p;
+
+	p = d_path(&file->f_path, 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))
diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
index 37fa241..8ec406a 100644
--- a/include/linux/sysfs.h
+++ b/include/linux/sysfs.h
@@ -119,6 +119,8 @@ void sysfs_remove_file_from_group(struct kobject *kobj,
 
 void sysfs_notify(struct kobject *kobj, char *dir, char *attr);
 
+void sysfs_printk_last_file(void);
+
 extern int __must_check sysfs_init(void);
 
 #else /* CONFIG_SYSFS */
@@ -231,6 +233,10 @@ static inline int __must_check sysfs_init(void)
 	return 0;
 }
 
+static inline void sysfs_printk_last_file(void)
+{
+}
+
 #endif /* CONFIG_SYSFS */
 
 #endif /* _SYSFS_H_ */
-- 
1.6.0.2


  parent reply	other threads:[~2008-10-16 17:16 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-16 17:09 [GIT PATCH] driver core patches for your 2.6-git tree Greg KH
2008-10-16 17:10 ` [PATCH 01/46] modules: fix module "notes" kobject leak Greg Kroah-Hartman
2008-10-16 17:10 ` Greg Kroah-Hartman [this message]
2008-10-16 17:40   ` [PATCH 02/46] sysfs: crash debugging Mathieu Desnoyers
2008-10-20 20:57     ` Greg KH
2008-10-16 17:10 ` [PATCH 03/46] device create: block: convert device_create_drvdata to device_create Greg Kroah-Hartman
2008-10-16 17:10 ` [PATCH 04/46] device create: char: " Greg Kroah-Hartman
2008-10-16 17:10 ` [PATCH 05/46] device create: ieee1394: " Greg Kroah-Hartman
2008-10-16 17:10 ` [PATCH 06/46] device create: infiniband: " Greg Kroah-Hartman
2008-10-16 17:10 ` [PATCH 07/46] device create: misc: " Greg Kroah-Hartman
2008-10-16 17:10 ` [PATCH 08/46] device create: net: " Greg Kroah-Hartman
2008-10-16 17:10 ` [PATCH 09/46] device create: s390: " Greg Kroah-Hartman
2008-10-16 17:10 ` [PATCH 10/46] device create: scsi: " Greg Kroah-Hartman
2008-10-16 17:10 ` [PATCH 11/46] device create: sound: " Greg Kroah-Hartman
2008-10-16 17:10 ` [PATCH 12/46] device create: usb: " Greg Kroah-Hartman
2008-10-16 17:10 ` [PATCH 13/46] device create: video: " Greg Kroah-Hartman
2008-10-16 17:10 ` [PATCH 14/46] device create: ide: " Greg Kroah-Hartman
2008-10-16 17:10 ` [PATCH 15/46] device create: remove device_create_drvdata Greg Kroah-Hartman
2008-10-16 17:10 ` [PATCH 16/46] usb gadget: link fixes for serial gadget Greg Kroah-Hartman
2008-10-16 17:10 ` [PATCH 17/46] usb gadget: link fixes for gadget zero Greg Kroah-Hartman
2008-10-16 17:10 ` [PATCH 18/46] usb gadget: link fixes for MIDI gadget Greg Kroah-Hartman
2008-10-16 17:10 ` [PATCH 19/46] usb gadget: link fixes for printer gadget Greg Kroah-Hartman
2008-10-16 17:10 ` [PATCH 20/46] usb gadget: link fixes for storage gadget Greg Kroah-Hartman
2008-10-16 17:10 ` [PATCH 21/46] usb gadget: link fixes for cdc composite gadget Greg Kroah-Hartman
2008-10-16 17:10 ` [PATCH 22/46] usb gadget: link fixes for network gadget Greg Kroah-Hartman
2008-10-16 17:10 ` [PATCH 23/46] driver core: basic infrastructure for per-module dynamic debug messages Greg Kroah-Hartman
2008-10-16 17:10 ` [PATCH 24/46] driver core: make struct platform_pm_ops static Greg Kroah-Hartman
2008-10-16 17:10 ` [PATCH 25/46] sysfs: Support sysfs_notify from atomic context with new sysfs_notify_dirent Greg Kroah-Hartman
2008-10-16 17:10 ` [PATCH 26/46] drivers/firmware/iscsi_ibft.c: make 3 functions static Greg Kroah-Hartman
2008-10-16 17:10 ` [PATCH 27/46] Driver core: Clarify device cleanup Greg Kroah-Hartman
2008-10-16 17:10 ` [PATCH 28/46] Driver core: Fix cleanup in device_create_vargs() Greg Kroah-Hartman
2008-10-16 17:10 ` [PATCH 29/46] device model: Do a quickcheck for driver binding before doing an expensive check Greg Kroah-Hartman
2008-10-16 17:10 ` [PATCH 30/46] sysfs: fix deadlock Greg Kroah-Hartman
2008-10-16 17:10 ` [PATCH 31/46] debug: Introduce a dev_WARN() function Greg Kroah-Hartman
2008-10-16 17:10 ` [PATCH 32/46] debug: use dev_WARN() rather than WARN_ON() in device_pm_add() Greg Kroah-Hartman
2008-10-16 17:10 ` [PATCH 33/46] usb: turn dev_warn+WARN_ON combos into dev_WARN Greg Kroah-Hartman
2008-10-16 17:10 ` [PATCH 34/46] Driver core: make bus_find_device_by_name() more robust Greg Kroah-Hartman
2008-10-16 17:10 ` [PATCH 35/46] PNP: create device attributes via default device attributes Greg Kroah-Hartman
2008-10-16 17:10 ` [PATCH 36/46] sysfs: use ilookup5() instead of ilookup5_nowait() Greg Kroah-Hartman
2008-10-16 17:10 ` [PATCH 37/46] platform: add new device registration helper Greg Kroah-Hartman
2008-10-16 17:10 ` [PATCH 38/46] sysfs: Make dir and name args to sysfs_notify() const Greg Kroah-Hartman
2008-10-16 17:10 ` [PATCH 39/46] kobject: Fix kobject_rename and !CONFIG_SYSFS Greg Kroah-Hartman
2008-10-16 17:10 ` [PATCH 40/46] kobject: Cleanup " Greg Kroah-Hartman
2008-10-16 17:10 ` [PATCH 41/46] NET: convert the phy_device file to use bus_find_device_by_name Greg Kroah-Hartman
2008-10-16 17:10 ` [PATCH 42/46] Driver core: add bus_sort_breadthfirst() function Greg Kroah-Hartman
2008-10-16 17:10 ` [PATCH 43/46] UIO: Add alignment warnings for uio-mem Greg Kroah-Hartman
2008-10-16 17:10 ` [PATCH 44/46] UIO: Change driver name of uio_pdrv Greg Kroah-Hartman
2008-10-16 17:10 ` [PATCH 45/46] UIO: add automata sercos3 pci card support Greg Kroah-Hartman
2008-10-16 17:10 ` [PATCH 46/46] UIO: Fix mapping of logical and virtual memory Greg Kroah-Hartman
2008-10-17 15:31 ` [GIT PATCH] driver core patches for your 2.6-git tree Jason Baron
2008-10-17 18:01   ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1224177047-11859-2-git-send-email-gregkh@suse.de \
    --to=gregkh@suse.de \
    --cc=akpm@linux-foundation.org \
    --cc=kay.sievers@vrfy.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@polymtl.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome