Skip to contentSkip to conversation

pstore: add interface for dumpers and add task list dumper

PATCH Superseded [email protected] 2 participants 16 messages Oct 18, 2012 – Nov 18, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v3 cover pstore: add interface for dumpers and add task list dumper

From: Dragos Tatulea <[email protected]>

This patchset adds an interface for registering various clients (dumpers) that can save info into pstore at crash time.

2 dumpers are added:
* task list dumper
* Android logs dumper

v3 changes:
Added Android log dumping.

v2 changes:
v1 patchset was corrupted.

Adrian Hunter (4):
pstore: add flags
pstore: add debugfs support for causing dumps and panics
pstore: add support for external writers
pstore: do not run timer while pstore is not mounted

Dragos Tatulea (4):
pstore: allow storing different type id's in ram backend
pstore: add task list dumper
pstore: make sure pstore_write exists on flush error
pstore: max out console log level during sysfs dump switch

 fs/pstore/Kconfig      |   12 ++++
 fs/pstore/Makefile     |    1 +
 fs/pstore/dump_tasks.c |  107 ++++++++++++++++++++++++++++
 fs/pstore/inode.c      |    6 ++
 fs/pstore/internal.h   |    2 +
 fs/pstore/platform.c   |  184 ++++++++++++++++++++++++++++++++++++++++++++++--
 fs/pstore/ram.c        |   18 +++--
 include/linux/pstore.h |   46 ++++++++++--
 8 files changed, 356 insertions(+), 20 deletions(-)
 create mode 100644 fs/pstore/dump_tasks.c
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH v3 1/9 pstore: add flags

From: Adrian Hunter <[email protected]>

Let the back end tweak pstore behaviour. Flags added are:

PSTORE_NO_HEADINGS

Omit pstore heading lines from dumped data

PSTORE_MAX_KMSG_BYTES

Default kmsg_bytes to ULONG_MAX

---
 fs/pstore/platform.c   |    9 ++++++++-
 include/linux/pstore.h |    4 ++++
 2 files changed, 12 insertions(+), 1 deletion(-)
fs/pstore/platform.c +8 -1
index a40da07..c4ea778 100644
@@ -128,7 +128,11 @@ static void pstore_dump(struct kmsg_dumper *dumper,
 		size_t len;
 
 		dst = psinfo->buf;
-		hsize = sprintf(dst, "%s#%d Part%d\n", why, oopscount, part);
+		if (psinfo->flags & PSTORE_NO_HEADINGS)
+			hsize = 0;
+		else
+			hsize = sprintf(dst, "%s#%d Part%d\n", why, oopscount,
+					part);
 		size = psinfo->bufsize - hsize;
 		dst += hsize;
 
@@ -237,6 +241,9 @@ int pstore_register(struct pstore_info *psi)
 		return -EINVAL;
 	}
 
+	if (psinfo->flags & PSTORE_MAX_KMSG_BYTES)
+		kmsg_bytes = ULONG_MAX;
+
 	if (pstore_is_mounted())
 		pstore_get_records(0);
 
include/linux/pstore.h +4 -0
index ee3034a..55ab23f 100644
@@ -40,9 +40,13 @@ enum pstore_type_id {
 
 struct module;
 
+#define PSTORE_NO_HEADINGS	BIT(0)
+#define PSTORE_MAX_KMSG_BYTES	BIT(1)
+
 struct pstore_info {
 	struct module	*owner;
 	char		*name;
+	unsigned int	flags;
 	spinlock_t	buf_lock;	/* serialize access to 'buf' */
 	char		*buf;
 	size_t		bufsize;
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH v3 2/9 pstore: add debugfs support for causing dumps and panics

In reply to [email protected]

From: Adrian Hunter <[email protected]>

There are 2 debugfs files:

pstore/dump writing a kmsg dump reason code
will cause a dump to persistent storage

pstore/panic writing anything will cause
a panic

---
 fs/pstore/platform.c |   51 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
fs/pstore/platform.c +51 -0
index c4ea778..9d65723 100644
@@ -33,6 +33,7 @@
 #include <linux/hardirq.h>
 #include <linux/jiffies.h>
 #include <linux/workqueue.h>
+#include <linux/debugfs.h>
 
 #include "internal.h"
 
@@ -206,6 +207,54 @@ static int pstore_write_compat(enum pstore_type_id type,
 	return psi->write_buf(type, reason, id, part, psinfo->buf, size, psi);
 }
 
+#ifdef CONFIG_DEBUG_FS
+
+static DEFINE_SPINLOCK(dbg_lock);
+
+static int dbg_dump(void *data, u64 val)
+{
+	unsigned long flags;
+
+	switch (val) {
+	case KMSG_DUMP_PANIC:
+	case KMSG_DUMP_OOPS:
+	case KMSG_DUMP_EMERG:
+	case KMSG_DUMP_RESTART:
+	case KMSG_DUMP_HALT:
+	case KMSG_DUMP_POWEROFF:
+		spin_lock_irqsave(&dbg_lock, flags);
+		kmsg_dump(val);
+		spin_unlock_irqrestore(&dbg_lock, flags);
+		return 0;
+	}
+	return -EINVAL;
+}
+DEFINE_SIMPLE_ATTRIBUTE(dbg_dump_fops, NULL, dbg_dump, "%llu\n");
+
+static int dbg_panic(void *data, u64 val)
+{
+	panic(KERN_EMERG "pstore debugging panic!\n");
+	return 0;
+}
+DEFINE_SIMPLE_ATTRIBUTE(dbg_panic_fops, NULL, dbg_panic, "%llu\n");
+
+static void pstore_debugfs_init(void)
+{
+	struct dentry *root;
+
+	root = debugfs_create_dir("pstore", NULL);
+	debugfs_create_file("dump", S_IWUSR, root, NULL, &dbg_dump_fops);
+	debugfs_create_file("panic", S_IWUSR, root, NULL, &dbg_panic_fops);
+}
+
+#else
+
+static inline void pstore_debugfs_init(void)
+{
+}
+
+#endif
+
 /*
  * platform specific persistent storage driver registers with
  * us here. If pstore is already mounted, call the platform
@@ -257,6 +306,8 @@ int pstore_register(struct pstore_info *psi)
 		add_timer(&pstore_timer);
 	}
 
+	pstore_debugfs_init();
+
 	return 0;
 }
 EXPORT_SYMBOL_GPL(pstore_register);
Signature · 1 line
1.7.9.5
#3 lore raw

Re: [PATCH v3 2/9] pstore: add debugfs support for causing dumps and panics

Quoted 8 lines · On Thu, Oct 18, 2012 at 02:06:00PM +0300, [email protected] wrote:

From: Adrian Hunter <[email protected]>

There are 2 debugfs files:

pstore/dump writing a kmsg dump reason code
will cause a dump to persistent storage

Quoted 5 lines

pstore/panic writing anything will cause
a panic

---

Um... how is different from /proc/sysrq-trigger?.. At least sysrq has 'panic', and I guess it would be better to extend it if we need something more than this.

Thanks,
Anton.

#4 lore raw

PATCH v3 3/9 pstore: add support for external writers

In reply to [email protected]

From: Adrian Hunter <[email protected]>

Other modules that may wish to write to persistent storage are supported by adding a notifier and write function.

The notifier has 3 events: PSTORE_BEGIN, PSTORE_DUMP and PSTORE_END. External writers use the PSTORE_DUMP event whereas the PSTORE_BEGIN and PSTORE_END can be used by platform code to ensure the back end is powered up.

---
 fs/pstore/platform.c   |   88 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/pstore.h |   43 +++++++++++++++++++----
 2 files changed, 124 insertions(+), 7 deletions(-)
fs/pstore/platform.c +88 -0
index 9d65723..63ff377 100644
@@ -34,6 +34,7 @@
 #include <linux/jiffies.h>
 #include <linux/workqueue.h>
 #include <linux/debugfs.h>
+#include <linux/notifier.h>
 
 #include "internal.h"
 
@@ -74,6 +75,20 @@ void pstore_set_kmsg_bytes(int bytes)
 	kmsg_bytes = bytes;
 }
 
+static ATOMIC_NOTIFIER_HEAD(pstore_notifiers);
+
+int pstore_notifier_register(struct notifier_block *n)
+{
+	return atomic_notifier_chain_register(&pstore_notifiers, n);
+}
+EXPORT_SYMBOL_GPL(pstore_notifier_register);
+
+int pstore_notifier_unregister(struct notifier_block *n)
+{
+	return atomic_notifier_chain_unregister(&pstore_notifiers, n);
+}
+EXPORT_SYMBOL_GPL(pstore_notifier_unregister);
+
 /* Tag each group of saved records with a sequence number */
 static int	oopscount;
 
@@ -97,6 +112,26 @@ static const char *get_reason_str(enum kmsg_dump_reason reason)
 	}
 }
 
+static int pstore_ext_flush(void)
+{
+	int ret;
+
+	if (!psinfo->ext_len)
+		return 0;
+
+	ret = psinfo->write(psinfo->ext_type, psinfo->ext_reason,
+			    &psinfo->ext_id, psinfo->ext_part++,
+			    psinfo->ext_len, psinfo);
+
+	if (ret == 0 && psinfo->ext_reason == KMSG_DUMP_OOPS &&
+	    pstore_is_mounted())
+		pstore_new_entry = 1;
+
+	psinfo->ext_len = 0;
+
+	return ret;
+}
+
 /*
  * callback from kmsg_dump. (s2,l2) has the most recently
  * written bytes, older bytes are in (s1,l1). Save as much
@@ -122,6 +157,15 @@ static void pstore_dump(struct kmsg_dumper *dumper,
 	} else
 		spin_lock_irqsave(&psinfo->buf_lock, flags);
 	oopscount++;
+
+	psinfo->ext_id = 0;
+	psinfo->ext_len = 0;
+	psinfo->ext_part = 0;
+	psinfo->ext_type = PSTORE_TYPE_UNKNOWN;
+	psinfo->ext_reason = reason;
+
+	atomic_notifier_call_chain(&pstore_notifiers, PSTORE_BEGIN, psinfo);
+
 	while (total < kmsg_bytes) {
 		char *dst;
 		unsigned long size;
@@ -148,6 +192,13 @@ static void pstore_dump(struct kmsg_dumper *dumper,
 		total += hsize + len;
 		part++;
 	}
+
+	atomic_notifier_call_chain(&pstore_notifiers, PSTORE_DUMP, psinfo);
+
+	pstore_ext_flush();
+
+	atomic_notifier_call_chain(&pstore_notifiers, PSTORE_END, psinfo);
+
 	if (in_nmi()) {
 		if (is_locked)
 			spin_unlock(&psinfo->buf_lock);
@@ -368,5 +419,42 @@ static void pstore_timefunc(unsigned long dummy)
 	mod_timer(&pstore_timer, jiffies + msecs_to_jiffies(pstore_update_ms));
 }
 
+/* pstore_write must only be called from PSTORE_DUMP notifier callbacks */
+int pstore_write(enum pstore_type_id type, const char *buf, size_t size)
+{
+	size_t len;
+	int err = 0, err2;
+
+	if (!psinfo)
+		return -ENODEV;
+
+	/*
+	 * No locking is needed because pstore_write is called only from
+	 * PSTORE_DUMP notifier callbacks.
+	 */
+
+	if (type != psinfo->ext_type) {
+		err = pstore_ext_flush();
+		psinfo->ext_type = type;
+		psinfo->ext_part = 1;
+	}
+
+	while (size) {
+		len = min(size, psinfo->bufsize - psinfo->ext_len);
+		memcpy(psinfo->buf + psinfo->ext_len, buf, len);
+		psinfo->ext_len += len;
+		buf += len;
+		size -= len;
+		if (psinfo->ext_len == psinfo->bufsize) {
+			err2 = pstore_ext_flush();
+			if (err2 && !err)
+				err = err2;
+		}
+	}
+
+	return err;
+}
+EXPORT_SYMBOL_GPL(pstore_write);
+
 module_param(backend, charp, 0444);
 MODULE_PARM_DESC(backend, "Pstore backend to use");
include/linux/pstore.h +36 -7

65 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#5 lore raw

Re: [PATCH v3 3/9] pstore: add support for external writers

Quoted 20 lines · On Thu, Oct 18, 2012 at 02:06:01PM +0300, [email protected] wrote:

From: Adrian Hunter <[email protected]>

Other modules that may wish to write to persistent storage are supported by adding a notifier and write function.

The notifier has 3 events: PSTORE_BEGIN, PSTORE_DUMP and PSTORE_END. External writers use the PSTORE_DUMP event whereas the PSTORE_BEGIN and PSTORE_END can be used by platform code to ensure the back end is powered up.

---
 fs/pstore/platform.c   |   88 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/pstore.h |   43 +++++++++++++++++++----
 2 files changed, 124 insertions(+), 7 deletions(-)
fs/pstore/platform.c +0 -0
index 9d65723..63ff377 100644

[...]

fs/pstore/platform.c static void pstore_timefunc(unsigned long dummy) · line 426

Quoted 5 lines
fs/pstore/platform.c +5 -0
+/* pstore_write must only be called from PSTORE_DUMP notifier callbacks */
+int pstore_write(enum pstore_type_id type, const char *buf, size_t size)
+{
+	size_t len;
+	int err = 0, err2;

I guess there is no need for err2 here, you can place it in the while loop, in the if block.

Quoted 48 lines
fs/pstore/platform.c +32 -0
+
+	if (!psinfo)
+		return -ENODEV;
+
+	/*
+	 * No locking is needed because pstore_write is called only from
+	 * PSTORE_DUMP notifier callbacks.
+	 */
+
+	if (type != psinfo->ext_type) {
+		err = pstore_ext_flush();
+		psinfo->ext_type = type;
+		psinfo->ext_part = 1;
+	}
+
+	while (size) {
+		len = min(size, psinfo->bufsize - psinfo->ext_len);
+		memcpy(psinfo->buf + psinfo->ext_len, buf, len);
+		psinfo->ext_len += len;
+		buf += len;
+		size -= len;
+		if (psinfo->ext_len == psinfo->bufsize) {
+			err2 = pstore_ext_flush();
+			if (err2 && !err)
+				err = err2;
+		}
+	}
+
+	return err;
+}
+EXPORT_SYMBOL_GPL(pstore_write);
+
 module_param(backend, charp, 0444);
 MODULE_PARM_DESC(backend, "Pstore backend to use");
include/linux/pstore.h +5 -0
index 55ab23f..1bf7f4b 100644
@@ -40,17 +40,27 @@ enum pstore_type_id {
 
 struct module;
 
+/* Notifier events */
+#define PSTORE_BEGIN		1
+#define PSTORE_DUMP		2
+#define PSTORE_END		3
+
 #define PSTORE_NO_HEADINGS	BIT(0)

include/linux/pstore.h enum pstore_type_id { · line 53

Quoted 10 lines
include/linux/pstore.h +0 -7
 #define PSTORE_MAX_KMSG_BYTES	BIT(1)
 
 struct pstore_info {
-	struct module	*owner;
-	char		*name;
-	unsigned int	flags;
-	spinlock_t	buf_lock;	/* serialize access to 'buf' */
-	char		*buf;
-	size_t		bufsize;
-	struct mutex	read_mutex;	/* serialize open/read/close */

That's why I don't like "pretty" formatting for structs. :) The change is unrelated, so please don't do this.

Quoted 49 lines
include/linux/pstore.h +31 -0
+	struct module		*owner;
+	char			*name;
+	unsigned int		flags;
+	spinlock_t		buf_lock;	/* serialize access to 'buf' */
+	char			*buf;
+	size_t			bufsize;
+	struct mutex		read_mutex;	/* serialize open/read/close */
+	u64			ext_id;
+	size_t			ext_len;
+	unsigned int		ext_part;
+	enum pstore_type_id	ext_type;
+	enum kmsg_dump_reason	ext_reason;
 	int		(*open)(struct pstore_info *psi);
 	int		(*close)(struct pstore_info *psi);
 	ssize_t		(*read)(u64 *id, enum pstore_type_id *type,
@@ -70,12 +80,31 @@ struct pstore_info {
 
 #ifdef CONFIG_PSTORE
 extern int pstore_register(struct pstore_info *);
+extern int pstore_notifier_register(struct notifier_block *n);
+extern int pstore_notifier_unregister(struct notifier_block *n);
+/* pstore_write must only be called from PSTORE_DUMP notifier callbacks */
+extern int pstore_write(enum pstore_type_id type, const char *buf, size_t size);
 #else
 static inline int
 pstore_register(struct pstore_info *psi)
 {
 	return -ENODEV;
 }
+static inline int
+pstore_notifier_register(struct notifier_block *n)
+{
+	return 0;
+}
+static inline int
+pstore_notifier_unregister(struct notifier_block *n)
+{
+	return 0;
+}
+static inline int
+pstore_write(enum pstore_type_id type, const char *buf, size_t size)
+{
+	return 0;
+}
 #endif
 
 #endif /*_LINUX_PSTORE_H*/
Signature · 1 line
1.7.9.5
#6 lore raw

PATCH v3 4/9 pstore: allow storing different type id's in ram backend

In reply to [email protected]

From: Dragos Tatulea <[email protected]>

Added pstore_type_id in message header when storing to ram. On write, take into account the contents of this header and set the type accordingly.

---
 fs/pstore/ram.c |   18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
fs/pstore/ram.c +11 -7
index 1a4f6da..e1684ef 100644
@@ -157,23 +157,30 @@ static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type,
 	time->tv_nsec = 0;
 
 	size = persistent_ram_old_size(prz);
+	if (!size)
+		return 0;
 	*buf = kmalloc(size, GFP_KERNEL);
 	if (*buf == NULL)
 		return -ENOMEM;
 	memcpy(*buf, persistent_ram_old(prz), size);
+	/* Read header. */
+	sscanf(*buf, "%u" RAMOOPS_KERNMSG_HDR "%lu.%lu",
+		type, &time->tv_sec, &time->tv_nsec);
+	time->tv_nsec *= 1000;
 
 	return size;
 }
 
-static size_t ramoops_write_kmsg_hdr(struct persistent_ram_zone *prz)
+static size_t ramoops_write_kmsg_hdr(struct persistent_ram_zone *prz,
+				     enum pstore_type_id type)
 {
 	char *hdr;
 	struct timeval timestamp;
 	size_t len;
 
 	do_gettimeofday(&timestamp);
-	hdr = kasprintf(GFP_ATOMIC, RAMOOPS_KERNMSG_HDR "%lu.%lu\n",
-		(long)timestamp.tv_sec, (long)timestamp.tv_usec);
+	hdr = kasprintf(GFP_ATOMIC, "%u" RAMOOPS_KERNMSG_HDR "%lu.%lu\n",
+		type, (long)timestamp.tv_sec, (long)timestamp.tv_usec);
 	WARN_ON_ONCE(!hdr);
 	len = hdr ? strlen(hdr) : 0;
 	persistent_ram_write(prz, hdr, len);
@@ -204,9 +211,6 @@ static int notrace ramoops_pstore_write_buf(enum pstore_type_id type,
 		return 0;
 	}
 
-	if (type != PSTORE_TYPE_DMESG)
-		return -EINVAL;
-
 	/* Out of the various dmesg dump types, ramoops is currently designed
 	 * to only store crash logs, rather than storing general kernel logs.
 	 */
@@ -226,7 +230,7 @@ static int notrace ramoops_pstore_write_buf(enum pstore_type_id type,
 	if (part != 1)
 		return -ENOSPC;
 
-	hlen = ramoops_write_kmsg_hdr(prz);
+	hlen = ramoops_write_kmsg_hdr(prz, type);
 	if (size + hlen > prz->buffer_size)
 		size = prz->buffer_size - hlen;
 	persistent_ram_write(prz, buf, size);
Signature · 1 line
1.7.9.5
#7 lore raw

Re: [PATCH v3 4/9] pstore: allow storing different type id's in ram backend

Quoted 8 lines · On Thu, Oct 18, 2012 at 02:06:02PM +0300, [email protected] wrote:

From: Dragos Tatulea <[email protected]>

Added pstore_type_id in message header when storing to ram. On write, take into account the contents of this header and set the type accordingly.

---

[...]

fs/pstore/ram.c static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type, · line 183

Quoted 13 lines
fs/pstore/ram.c +4 -3
-static size_t ramoops_write_kmsg_hdr(struct persistent_ram_zone *prz)
+static size_t ramoops_write_kmsg_hdr(struct persistent_ram_zone *prz,
+				     enum pstore_type_id type)
 {
 	char *hdr;
 	struct timeval timestamp;
 	size_t len;
 
 	do_gettimeofday(&timestamp);
-	hdr = kasprintf(GFP_ATOMIC, RAMOOPS_KERNMSG_HDR "%lu.%lu\n",
-		(long)timestamp.tv_sec, (long)timestamp.tv_usec);
+	hdr = kasprintf(GFP_ATOMIC, "%u" RAMOOPS_KERNMSG_HDR "%lu.%lu\n",
+		type, (long)timestamp.tv_sec, (long)timestamp.tv_usec);

This will probably break scripts (and the main purpose for the header is to make it somewhat scripts-parsable). It's safer to change it to

RAMOOPS_KERNMSG_HDR "%lu.%lu %u"

Thanks,
Anton.

#8 lore raw

PATCH v3 5/9 pstore: add task list dumper

In reply to [email protected]

From: Dragos Tatulea <[email protected]>

The task dumper can dump task information during a panic. This is equivalent to a magic sysrq 't' command but the result is captured from the console and written to persistent storage. Note that this happens after pstore dumps kernel messages because the task dump will overwrite other kernel messages.

There is a single module parameter "enabled" which must be used to enable task dumping.

---
 fs/pstore/Kconfig      |   12 ++++++
 fs/pstore/Makefile     |    1 +
 fs/pstore/dump_tasks.c |  107 ++++++++++++++++++++++++++++++++++++++++++++++++
 fs/pstore/inode.c      |    3 ++
 include/linux/pstore.h |    1 +
 5 files changed, 124 insertions(+)
 create mode 100644 fs/pstore/dump_tasks.c
fs/pstore/Kconfig +12 -0
index ca71db6..ee967c5 100644
@@ -48,3 +48,15 @@ config PSTORE_RAM
 	  "ramoops.ko".
 
 	  For more information, see Documentation/ramoops.txt.
+
+config PSTORE_DUMP_TASKS
+	bool "Dump task information"
+	default n
+	depends on PSTORE
+	help
+	  This option allows a dump of task information during a
+	  panic.  This is equivalent to a magic sysrq 't' command
+	  but the result is captured from the console and written
+	  to persistent storage.  Note that this happens after
+	  pstore dumps kernel messages because the task dump will
+	  overwrite other kernel messages.
fs/pstore/Makefile +1 -0
index 4c9095c..14b5c83 100644
@@ -9,3 +9,4 @@ obj-$(CONFIG_PSTORE_FTRACE)	+= ftrace.o
 
 ramoops-objs += ram.o ram_core.o
 obj-$(CONFIG_PSTORE_RAM)	+= ramoops.o
+obj-$(CONFIG_PSTORE_DUMP_TASKS)	+= dump_tasks.o
fs/pstore/dump_tasks.c new file +107 -0

107 lines not on this page · raw message

fs/pstore/inode.c +3 -0
index 4ab572e..4800c09 100644
@@ -321,6 +321,9 @@ int pstore_mkfile(enum pstore_type_id type, char *psname, u64 id,
 	case PSTORE_TYPE_MCE:
 		sprintf(name, "mce-%s-%lld", psname, id);
 		break;
+	case PSTORE_TYPE_TASK_DUMP:
+		sprintf(name, "tasks-%s-%lld", psname, id);
+		break;
 	case PSTORE_TYPE_UNKNOWN:
 		sprintf(name, "unknown-%s-%lld", psname, id);
 		break;
include/linux/pstore.h +1 -0
index 1bf7f4b..48dcafb 100644
@@ -35,6 +35,7 @@ enum pstore_type_id {
 	PSTORE_TYPE_MCE		= 1,
 	PSTORE_TYPE_CONSOLE	= 2,
 	PSTORE_TYPE_FTRACE	= 3,
+	PSTORE_TYPE_TASK_DUMP	= 4,
 	PSTORE_TYPE_UNKNOWN	= 255
 };
 
Signature · 1 line
1.7.9.5
#9 lore raw

Re: [PATCH v3 5/9] pstore: add task list dumper

Quoted 11 lines · On Thu, Oct 18, 2012 at 02:06:03PM +0300, [email protected] wrote:

From: Dragos Tatulea <[email protected]>

The task dumper can dump task information during a panic. This is equivalent to a magic sysrq 't' command but the result is captured from the console and written to persistent storage. Note that this happens after pstore dumps kernel messages because the task dump will overwrite other kernel messages.

There is a single module parameter "enabled" which must be used to enable task dumping.

This is a very very strange approach to accomplish this.

Plus, we have the console dumper already, so I think it should be done the other way around: if you want a tasklist dumped during panic, introduce a generic feature for the panic logging, i.e. just print tasks after/before panic trace.

Or am I missing the point of the patch?

Quoted 17 lines
---
 fs/pstore/Kconfig      |   12 ++++++
 fs/pstore/Makefile     |    1 +
 fs/pstore/dump_tasks.c |  107 ++++++++++++++++++++++++++++++++++++++++++++++++
 fs/pstore/inode.c      |    3 ++
 include/linux/pstore.h |    1 +
 5 files changed, 124 insertions(+)
 create mode 100644 fs/pstore/dump_tasks.c
fs/pstore/Kconfig +0 -0
index ca71db6..ee967c5 100644

fs/pstore/Kconfig config PSTORE_RAM · line 54

Quoted 7 lines
fs/pstore/Kconfig +4 -0
@@ -48,3 +48,15 @@ config PSTORE_RAM
 	  "ramoops.ko".
 
 	  For more information, see Documentation/ramoops.txt.
+
+config PSTORE_DUMP_TASKS
+	bool "Dump task information"
+	default n

'default n' is there by default. :) So no need for this line.

Thanks,
Anton.

#10 lore raw

PATCH v3 6/9 pstore: do not run timer while pstore is not mounted

In reply to [email protected]

From: Adrian Hunter <[email protected]>

A timer is used to periodically check for new dumps. The timer is not needed unless pstore is mounted, so disable it otherwise.

---
 fs/pstore/inode.c    |    3 +++
 fs/pstore/internal.h |    2 ++
 fs/pstore/platform.c |   36 +++++++++++++++++++++++++++++-------
 3 files changed, 34 insertions(+), 7 deletions(-)
fs/pstore/inode.c +3 -0
index 4800c09..5e20a8d 100644
@@ -397,6 +397,8 @@ static int pstore_fill_super(struct super_block *sb, void *data, int silent)
 
 	pstore_get_records(0);
 
+	pstore_add_timer();
+
 	return 0;
 }
 
@@ -408,6 +410,7 @@ static struct dentry *pstore_mount(struct file_system_type *fs_type,
 
 static void pstore_kill_sb(struct super_block *sb)
 {
+	pstore_del_timer();
 	kill_litter_super(sb);
 	pstore_sb = NULL;
 }
fs/pstore/internal.h +2 -0
index 4847f58..c7b8197 100644
@@ -54,4 +54,6 @@ extern int	pstore_mkfile(enum pstore_type_id, char *psname, u64 id,
 			      struct timespec time, struct pstore_info *psi);
 extern int	pstore_is_mounted(void);
 
+extern void pstore_add_timer(void);
+extern void pstore_del_timer(void);
 #endif
fs/pstore/platform.c +29 -7
index 63ff377..3a4c38f 100644
@@ -54,6 +54,8 @@ static int pstore_new_entry;
 
 static void pstore_timefunc(unsigned long);
 static DEFINE_TIMER(pstore_timer, pstore_timefunc, 0, 0);
+static DEFINE_SPINLOCK(pstore_timer_lock);
+static int pstore_timer_on;
 
 static void pstore_dowork(struct work_struct *);
 static DECLARE_WORK(pstore_work, pstore_dowork);
@@ -351,12 +353,6 @@ int pstore_register(struct pstore_info *psi)
 	pstore_register_console();
 	pstore_register_ftrace();
 
-	if (pstore_update_ms >= 0) {
-		pstore_timer.expires = jiffies +
-			msecs_to_jiffies(pstore_update_ms);
-		add_timer(&pstore_timer);
-	}
-
 	pstore_debugfs_init();
 
 	return 0;
@@ -411,12 +407,38 @@ static void pstore_dowork(struct work_struct *work)
 
 static void pstore_timefunc(unsigned long dummy)
 {
+	unsigned long flags;
+
 	if (pstore_new_entry) {
 		pstore_new_entry = 0;
 		schedule_work(&pstore_work);
 	}
 
-	mod_timer(&pstore_timer, jiffies + msecs_to_jiffies(pstore_update_ms));
+	spin_lock_irqsave(&pstore_timer_lock, flags);
+	if (pstore_timer_on)
+		mod_timer(&pstore_timer,
+				jiffies + msecs_to_jiffies(pstore_update_ms));
+	spin_unlock_irqrestore(&pstore_timer_lock, flags);
+}
+
+void pstore_add_timer(void)
+{
+	pstore_timer_on = 1;
+	if (pstore_update_ms >= 0) {
+		pstore_timer.expires = jiffies +
+			msecs_to_jiffies(pstore_update_ms);
+		add_timer(&pstore_timer);
+	}
+}
+
+void pstore_del_timer(void)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(&pstore_timer_lock, flags);
+	pstore_timer_on = 0;
+	spin_unlock_irqrestore(&pstore_timer_lock, flags);
+	del_timer_sync(&pstore_timer);
 }
 
 /* pstore_write must only be called from PSTORE_DUMP notifier callbacks */
Signature · 1 line
1.7.9.5
#11 lore raw

PATCH v3 7/9 pstore: make sure pstore_write exists on flush error

In reply to [email protected]

From: Dragos Tatulea <[email protected]>

Return error if flushing to backend failed.

---
 fs/pstore/platform.c |    8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
fs/pstore/platform.c +3 -5
index 3a4c38f..25f59ed 100644
@@ -445,7 +445,7 @@ void pstore_del_timer(void)
 int pstore_write(enum pstore_type_id type, const char *buf, size_t size)
 {
 	size_t len;
-	int err = 0, err2;
+	int err = 0;
 
 	if (!psinfo)
 		return -ENODEV;
@@ -461,16 +461,14 @@ int pstore_write(enum pstore_type_id type, const char *buf, size_t size)
 		psinfo->ext_part = 1;
 	}
 
-	while (size) {
+	while (size && !err) {
 		len = min(size, psinfo->bufsize - psinfo->ext_len);
 		memcpy(psinfo->buf + psinfo->ext_len, buf, len);
 		psinfo->ext_len += len;
 		buf += len;
 		size -= len;
 		if (psinfo->ext_len == psinfo->bufsize) {
-			err2 = pstore_ext_flush();
-			if (err2 && !err)
-				err = err2;
+			err = pstore_ext_flush();
 		}
 	}
 
Signature · 1 line
1.7.9.5
#12 lore raw

Re: [PATCH v3 7/9] pstore: make sure pstore_write exists on flush error

Quoted 3 lines · On Thu, Oct 18, 2012 at 02:06:05PM +0300, [email protected] wrote:

From: Dragos Tatulea <[email protected]>

Return error if flushing to backend failed.

I think you can easily fold this into 'pstore: add support for external writers'.

Thanks.

Quoted 39 lines
---
 fs/pstore/platform.c |    8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
fs/pstore/platform.c +3 -5
index 3a4c38f..25f59ed 100644
@@ -445,7 +445,7 @@ void pstore_del_timer(void)
 int pstore_write(enum pstore_type_id type, const char *buf, size_t size)
 {
 	size_t len;
-	int err = 0, err2;
+	int err = 0;
 
 	if (!psinfo)
 		return -ENODEV;
@@ -461,16 +461,14 @@ int pstore_write(enum pstore_type_id type, const char *buf, size_t size)
 		psinfo->ext_part = 1;
 	}
 
-	while (size) {
+	while (size && !err) {
 		len = min(size, psinfo->bufsize - psinfo->ext_len);
 		memcpy(psinfo->buf + psinfo->ext_len, buf, len);
 		psinfo->ext_len += len;
 		buf += len;
 		size -= len;
 		if (psinfo->ext_len == psinfo->bufsize) {
-			err2 = pstore_ext_flush();
-			if (err2 && !err)
-				err = err2;
+			err = pstore_ext_flush();
 		}
 	}
 
Signature · 1 line
1.7.9.5
#13 lore raw

PATCH v3 8/9 pstore: max out console log level during sysfs dump switch

In reply to [email protected]

From: Dragos Tatulea <[email protected]>

Otherwise we might miss out on some pstore dumpers that use printks below current log level.

---
 fs/pstore/platform.c |    4 ++++
 1 file changed, 4 insertions(+)
fs/pstore/platform.c +4 -0
index 25f59ed..e3ad13e 100644
@@ -267,6 +267,7 @@ static DEFINE_SPINLOCK(dbg_lock);
 static int dbg_dump(void *data, u64 val)
 {
 	unsigned long flags;
+	int saved_loglevel;
 
 	switch (val) {
 	case KMSG_DUMP_PANIC:
@@ -276,7 +277,10 @@ static int dbg_dump(void *data, u64 val)
 	case KMSG_DUMP_HALT:
 	case KMSG_DUMP_POWEROFF:
 		spin_lock_irqsave(&dbg_lock, flags);
+		saved_loglevel = console_loglevel;
+		console_loglevel =  15;
 		kmsg_dump(val);
+		console_loglevel = saved_loglevel;
 		spin_unlock_irqrestore(&dbg_lock, flags);
 		return 0;
 	}
Signature · 1 line
1.7.9.5
#14 lore raw

Re: [PATCH v3 8/9] pstore: max out console log level during sysfs dump switch

Quoted 4 lines · On Thu, Oct 18, 2012 at 02:06:06PM +0300, [email protected] wrote:

From: Dragos Tatulea <[email protected]>

Otherwise we might miss out on some pstore dumpers that use printks below current log level.

If anything, this should be folded into 'pstore: add debugfs support for causing dumps and panics'. But I'm not sure about the debugfs stuff anyway.

Quoted 30 lines
---
 fs/pstore/platform.c |    4 ++++
 1 file changed, 4 insertions(+)
fs/pstore/platform.c +4 -0
index 25f59ed..e3ad13e 100644
@@ -267,6 +267,7 @@ static DEFINE_SPINLOCK(dbg_lock);
 static int dbg_dump(void *data, u64 val)
 {
 	unsigned long flags;
+	int saved_loglevel;
 
 	switch (val) {
 	case KMSG_DUMP_PANIC:
@@ -276,7 +277,10 @@ static int dbg_dump(void *data, u64 val)
 	case KMSG_DUMP_HALT:
 	case KMSG_DUMP_POWEROFF:
 		spin_lock_irqsave(&dbg_lock, flags);
+		saved_loglevel = console_loglevel;
+		console_loglevel =  15;
 		kmsg_dump(val);
+		console_loglevel = saved_loglevel;
 		spin_unlock_irqrestore(&dbg_lock, flags);
 		return 0;
 	}
Signature · 1 line
1.7.9.5
#15 lore raw

PATCH v3 9/9 pstore: add android log dumping

In reply to [email protected]

From: Dragos Tatulea <[email protected]>

Dump android binary logs to pstore on panic.

Change-Id I8ba59d498eae252f4c3844ece8be2a9c4979ecd2
---
 drivers/staging/android/Kconfig  |   12 ++++++
 drivers/staging/android/logger.c |   87 ++++++++++++++++++++++++++++++++++++++
 fs/pstore/inode.c                |   12 ++++++
 include/linux/pstore.h           |   16 ++++---
 4 files changed, 121 insertions(+), 6 deletions(-)
drivers/staging/android/Kconfig +12 -0
index 0ce50d1..72b0de3 100644
@@ -49,6 +49,18 @@ config ANDROID_INTF_ALARM_DEV
 	  elapsed realtime, and a non-wakeup alarm on the monotonic clock.
 	  Also exports the alarm interface to user-space.
 
+config ANDROID_LOGGER_PANIC_DUMP
+	bool "Panic dump to pstore"
+	default n
+	depends on ANDROID_LOGGER
+	depends on PSTORE
+	help
+	  This options allows the panic dumping of log data to persistent
+	  storage. If the 'enabled' parameter is non-zero, during a panic
+	  each log will be copied in binary format to pstore and, after
+	  the next boot, will appear as files in the pstore file system.
+
+
 endif # if ANDROID
 
 endmenu
drivers/staging/android/logger.c +87 -0

105 lines not on this page · raw message

fs/pstore/inode.c +12 -0
index 5e20a8d..8b1179d 100644
@@ -324,6 +324,18 @@ int pstore_mkfile(enum pstore_type_id type, char *psname, u64 id,
 	case PSTORE_TYPE_TASK_DUMP:
 		sprintf(name, "tasks-%s-%lld", psname, id);
 		break;
+	case PSTORE_TYPE_ANDROID_LOG_MAIN:
+		sprintf(name, "android_log_main-%s-%lld", psname, id);
+		break;
+	case PSTORE_TYPE_ANDROID_LOG_EVENTS:
+		sprintf(name, "android_log_events-%s-%lld", psname, id);
+		break;
+	case PSTORE_TYPE_ANDROID_LOG_RADIO:
+		sprintf(name, "android_log_radio-%s-%lld", psname, id);
+		break;
+	case PSTORE_TYPE_ANDROID_LOG_SYSTEM:
+		sprintf(name, "android_log_system-%s-%lld", psname, id);
+		break;
 	case PSTORE_TYPE_UNKNOWN:
 		sprintf(name, "unknown-%s-%lld", psname, id);
 		break;
include/linux/pstore.h +10 -6
index 48dcafb..08b496a 100644
@@ -31,12 +31,16 @@
 
 /* types */
 enum pstore_type_id {
-	PSTORE_TYPE_DMESG	= 0,
-	PSTORE_TYPE_MCE		= 1,
-	PSTORE_TYPE_CONSOLE	= 2,
-	PSTORE_TYPE_FTRACE	= 3,
-	PSTORE_TYPE_TASK_DUMP	= 4,
-	PSTORE_TYPE_UNKNOWN	= 255
+	PSTORE_TYPE_DMESG		= 0,
+	PSTORE_TYPE_MCE			= 1,
+	PSTORE_TYPE_CONSOLE		= 2,
+	PSTORE_TYPE_FTRACE		= 3,
+	PSTORE_TYPE_TASK_DUMP		= 4,
+	PSTORE_TYPE_ANDROID_LOG_MAIN	= 5,
+	PSTORE_TYPE_ANDROID_LOG_EVENTS	= 6,
+	PSTORE_TYPE_ANDROID_LOG_RADIO	= 7,
+	PSTORE_TYPE_ANDROID_LOG_SYSTEM	= 8,
+	PSTORE_TYPE_UNKNOWN		= 255
 };
 
 struct module;
Signature · 1 line
1.7.9.5