diff mbox series

[v3,2/2] tty/sysrq: Dump printk ring buffer messages via sysrq

Message ID 57daf43c5270f7532b269b9f0e90d126ca012354.1705331453.git.sreenath.vijayan@sony.com
State New
Headers show
Series [v3,1/2] printk: Add function to dump printk buffer directly to consoles | expand

Commit Message

Sreenath Vijayan Jan. 17, 2024, 11:13 a.m. UTC
When terminal is unresponsive, one cannot use dmesg to view printk
ring buffer messages. Also, syslog services may be disabled,
to check the messages after a reboot, especially on embedded systems.
In this scenario, dump the printk ring buffer messages via sysrq
by pressing sysrq+D.

Signed-off-by: Sreenath Vijayan <sreenath.vijayan@sony.com>
Signed-off-by: Shimoyashiki Taichi <taichi.shimoyashiki@sony.com>
---
 Documentation/admin-guide/sysrq.rst |  2 ++
 drivers/tty/sysrq.c                 | 20 +++++++++++++++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)

Comments

John Ogness Jan. 18, 2024, 10:05 a.m. UTC | #1
On 2024-01-17, Sreenath Vijayan <sreenath.vijayan@sony.com> wrote:
> When terminal is unresponsive, one cannot use dmesg to view printk
> ring buffer messages. Also, syslog services may be disabled,
> to check the messages after a reboot, especially on embedded systems.
> In this scenario, dump the printk ring buffer messages via sysrq
> by pressing sysrq+D.

Note that using sysrq+g with kgdb or kdb it is already possible to dump
the printk ringbuffer messages. However using this new sysrq+D is much
more comfortable, less intrusive, and generally safer.

I have no problems with this change. But I guess the tty maintainers
will need to speak up about extending the sysrq list.

John
David Laight Jan. 18, 2024, 10:56 p.m. UTC | #2
From: Sreenath Vijayan
> Sent: 17 January 2024 11:14
....
>  /* Key Operations table and lock */
>  static DEFINE_SPINLOCK(sysrq_key_table_lock);
> 
> @@ -505,7 +523,7 @@ static const struct sysrq_key_op *sysrq_key_table[62] = {
>  	NULL,				/* A */
>  	NULL,				/* B */
>  	NULL,				/* C */
> -	NULL,				/* D */
> +	&sysrq_dmesg_dump_op,		/* D */
>  	NULL,				/* E */
>  	NULL,				/* F */
>  	NULL,				/* G */

That looks like it ought to use C99 initialisers:
	['D' - 'A'] = &sysrq_dmesg_dump_op,

Possible with a #define to hide the offset.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Greg Kroah-Hartman Jan. 19, 2024, 5:47 a.m. UTC | #3
On Thu, Jan 18, 2024 at 10:56:59PM +0000, David Laight wrote:
> From: Sreenath Vijayan
> > Sent: 17 January 2024 11:14
> ....
> >  /* Key Operations table and lock */
> >  static DEFINE_SPINLOCK(sysrq_key_table_lock);
> > 
> > @@ -505,7 +523,7 @@ static const struct sysrq_key_op *sysrq_key_table[62] = {
> >  	NULL,				/* A */
> >  	NULL,				/* B */
> >  	NULL,				/* C */
> > -	NULL,				/* D */
> > +	&sysrq_dmesg_dump_op,		/* D */
> >  	NULL,				/* E */
> >  	NULL,				/* F */
> >  	NULL,				/* G */
> 
> That looks like it ought to use C99 initialisers:
> 	['D' - 'A'] = &sysrq_dmesg_dump_op,
> 
> Possible with a #define to hide the offset.

Maybe in the future, but for now, let's leave it as-is please.

thanks,

greg k-h
diff mbox series

Patch

diff --git a/Documentation/admin-guide/sysrq.rst b/Documentation/admin-guide/sysrq.rst
index 51906e47327b..246a7b61a0eb 100644
--- a/Documentation/admin-guide/sysrq.rst
+++ b/Documentation/admin-guide/sysrq.rst
@@ -152,6 +152,8 @@  Command	    Function
             will be printed to your console. (``0``, for example would make
             it so that only emergency messages like PANICs or OOPSes would
             make it to your console.)
+
+``D``	    Dump the printk ring buffer
 =========== ===================================================================
 
 Okay, so what can I use them for?
diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
index 6b4a28bcf2f5..1976412706a4 100644
--- a/drivers/tty/sysrq.c
+++ b/drivers/tty/sysrq.c
@@ -450,6 +450,24 @@  static const struct sysrq_key_op sysrq_unrt_op = {
 	.enable_mask	= SYSRQ_ENABLE_RTNICE,
 };
 
+static void dmesg_dump_callback(struct work_struct *work)
+{
+	dump_printk_buffer();
+}
+
+static DECLARE_WORK(sysrq_dmesg_work, dmesg_dump_callback);
+
+static void sysrq_handle_dmesg_dump(u8 key)
+{
+	queue_work(system_unbound_wq, &sysrq_dmesg_work);
+}
+static struct sysrq_key_op sysrq_dmesg_dump_op = {
+	.handler        = sysrq_handle_dmesg_dump,
+	.help_msg       = "dump-dmesg(D)",
+	.action_msg     = "Dump dmesg",
+	.enable_mask    = SYSRQ_ENABLE_DUMP,
+};
+
 /* Key Operations table and lock */
 static DEFINE_SPINLOCK(sysrq_key_table_lock);
 
@@ -505,7 +523,7 @@  static const struct sysrq_key_op *sysrq_key_table[62] = {
 	NULL,				/* A */
 	NULL,				/* B */
 	NULL,				/* C */
-	NULL,				/* D */
+	&sysrq_dmesg_dump_op,		/* D */
 	NULL,				/* E */
 	NULL,				/* F */
 	NULL,				/* G */