pstore/zone: Emit registration message as a single pr_info()
Subsystems (2)
PATCH RESEND v2 1/1 pstore/zone: Emit registration message as a single pr_info()
register_pstore_zone() prints its "registered ... as backend for ..." summary as a pr_info() followed by several pr_cont() calls.
pr_cont() is not atomic and has no log level of its own. It appends to whichever line was most recently opened by a printk(). If a pr_err() or pr_warn() from another CPU or an interrupt handler preempts the pr_info() / pr_cont() sequence, it closes the continuation between the fragments. This can cause parts of the pstore registration message to appear at the wrong log level and be interleaved with other messages.
Furthermore, this causes the detection of new warning and error messages in the kernel log to be unreliable.
Format the registration line into a seq_buf and emit it with a single pr_info() call, making the line atomic with respect to concurrent printk() callers. No functional change to registration.
--- fs/pstore/zone.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-)
fs/pstore/zone.c +13 -10
@@ -12,6 +12,7 @@#include <linux/slab.h> #include <linux/mount.h> #include <linux/printk.h> +#include <linux/seq_buf.h> #include <linux/fs.h> #include <linux/pstore_zone.h> #include <linux/kdev_t.h>
@@ -1301,6 +1302,10 @@ int register_pstore_zone(struct pstore_zone_info *info) {int err = -EINVAL ;struct psz_context *cxt = &pstore_zone_cxt; +char buf[256 ]; +struct seq_buf s; + +seq_buf_init (&s, buf,sizeof (buf));if (info->total_size <4096 ) {pr_warn ("total_size must be >= 4096\n" );
@@ -1383,30 +1388,28 @@ int register_pstore_zone(struct pstore_zone_info *info) } cxt->pstore.data = cxt; -pr_info ("registered %s as backend for" , info->name); cxt->pstore.max_reason = info->max_reason; cxt->pstore.name = info->name;if (info->kmsg_size) { cxt->pstore.flags |=PSTORE_FLAGS_DMESG ; -pr_cont (" kmsg(%s" , -kmsg_dump_reason_str (cxt->pstore.max_reason)); -if (cxt->pstore_zone_info->panic_write) -pr_cont (",panic_write" ); -pr_cont (")" ); +seq_buf_printf (&s," kmsg(%s%s)" , +kmsg_dump_reason_str (cxt->pstore.max_reason), + cxt->pstore_zone_info->panic_write ?",panic_write" :"" ); }if (info->pmsg_size) { cxt->pstore.flags |=PSTORE_FLAGS_PMSG ; -pr_cont (" pmsg" ); +seq_buf_puts (&s," pmsg" ); }if (info->console_size) { cxt->pstore.flags |=PSTORE_FLAGS_CONSOLE ; -pr_cont (" console" ); +seq_buf_puts (&s," console" ); }if (info->ftrace_size) { cxt->pstore.flags |=PSTORE_FLAGS_FTRACE ; -pr_cont (" ftrace" ); +seq_buf_puts (&s," ftrace" ); } -pr_cont ("\n" ); + +pr_info ("registered %s as backend for%s\n" , info->name,seq_buf_str (&s)); err =pstore_register (&cxt->pstore);if (err) {
Signature · 1 line
2.43.0
Jon Hunter
maintainerHi Kees,
Quoted 76 lines · Kartik Rajput
register_pstore_zone()prints its "registered ... as backend for ..." summary as apr_info()followed by severalpr_cont()calls.
pr_cont()is not atomic and has no log level of its own. It appends to whichever line was most recently opened by aprintk(). If apr_err()orpr_warn()from another CPU or an interrupt handler preempts thepr_info()/pr_cont()sequence, it closes the continuation between the fragments. This can cause parts of the pstore registration message to appear at the wrong log level and be interleaved with other messages.Furthermore, this causes the detection of new warning and error messages in the kernel log to be unreliable.
Format the registration line into a
seq_bufand emit it with a singlepr_info()call, making the line atomic with respect to concurrentprintk()callers. No functional change to registration.Signed-off-by Kartik Rajput <[email protected]>Acked-by Jon Hunter <[email protected]>--- fs/pstore/zone.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-)fs/pstore/zone.c +10
-8@@ -12,6 +12,7 @@#include <linux/slab.h> #include <linux/mount.h> #include <linux/printk.h> +#include <linux/seq_buf.h> #include <linux/fs.h> #include <linux/pstore_zone.h> #include <linux/kdev_t.h> @@ -1301,6 +1302,10 @@ int register_pstore_zone(struct pstore_zone_info *info) {int err = -EINVAL ;struct psz_context *cxt = &pstore_zone_cxt; +char buf[256 ]; +struct seq_buf s; + +seq_buf_init (&s, buf,sizeof (buf));if (info->total_size <4096 ) {pr_warn ("total_size must be >= 4096\n" );@@ -1383,30 +1388,28 @@ int register_pstore_zone(struct pstore_zone_info *info) } cxt->pstore.data = cxt; -pr_info ("registered %s as backend for" , info->name); cxt->pstore.max_reason = info->max_reason; cxt->pstore.name = info->name;if (info->kmsg_size) { cxt->pstore.flags |=PSTORE_FLAGS_DMESG ; -pr_cont (" kmsg(%s" , -kmsg_dump_reason_str (cxt->pstore.max_reason)); -if (cxt->pstore_zone_info->panic_write) -pr_cont (",panic_write" ); -pr_cont (")" ); +seq_buf_printf (&s," kmsg(%s%s)" , +kmsg_dump_reason_str (cxt->pstore.max_reason), + cxt->pstore_zone_info->panic_write ?",panic_write" :"" ); }if (info->pmsg_size) { cxt->pstore.flags |=PSTORE_FLAGS_PMSG ; -pr_cont (" pmsg" ); +seq_buf_puts (&s," pmsg" ); }if (info->console_size) { cxt->pstore.flags |=PSTORE_FLAGS_CONSOLE ; -pr_cont (" console" ); +seq_buf_puts (&s," console" ); }if (info->ftrace_size) {
fs/pstore/zone.c int register_pstore_zone(struct pstore_zone_info *info) · line 1415
Quoted 10 lines
fs/pstore/zone.c +3
-2cxt->pstore.flags |=PSTORE_FLAGS_FTRACE ; -pr_cont (" ftrace" ); +seq_buf_puts (&s," ftrace" ); } -pr_cont ("\n" ); + +pr_info ("registered %s as backend for%s\n" , info->name,seq_buf_str (&s)); err =pstore_register (&cxt->pstore);if (err) {
Any more feedback on this? Or can we queue this one up?
Thanks!
Jon
Signature · 1 line
nvpublic
Two comments below, but not worth a respin for these.
fs/pstore/zone.c int register_pstore_zone(struct pstore_zone_info *info) · line 1305
Quoted 5 lines · Kartik Rajput
fs/pstore/zone.c +1
-0@@ -1301,6 +1302,10 @@ int register_pstore_zone(struct pstore_zone_info *info) {int err = -EINVAL ;struct psz_context *cxt = &pstore_zone_cxt; +char buf[256 ];
The line can't get longer than about 50 characters, so 256 bytes of stack is a lot.
fs/pstore/zone.c int register_pstore_zone(struct pstore_zone_info *info) · line 1308
Quoted 3 lines
fs/pstore/zone.c +3
-0+struct seq_buf s; + +seq_buf_init (&s, buf,sizeof (buf));
DECLARE_SEQ_BUF(s, 64) would replace the buffer, the struct and this call with one line.
Signature · 2 lines
Thanks, Sasha