pstore: add interface for dumpers and add task list dumper
v2 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.
Such a dumper is added which does task list 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
PATCH v2 1/8 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
@@ -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
@@ -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
PATCH v2 2/8 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
@@ -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
PATCH v2 3/8 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
@@ -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
PATCH v2 4/8 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
@@ -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 (×tamp); - 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
PATCH v2 5/8 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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH v2 6/8 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
@@ -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
@@ -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
@@ -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
PATCH v2 7/8 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
@@ -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
PATCH v2 8/8 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
@@ -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