lkml.org 
[lkml]   [2024]   [May]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v6 1/2] printk: Add function to replay kernel log on consoles

On Wed 2024-03-13 15:50:52, Sreenath Vijayan wrote:
> Add a generic function console_replay_all() for replaying
> the kernel log on consoles, in any context. It would allow
> viewing the logs on an unresponsive terminal via sysrq.
>
> Reuse the existing code from console_flush_on_panic() for
> resetting the sequence numbers, by introducing a new helper
> function __console_rewind_all(). It is safe to be called
> under console_lock().
>
> Try to acquire lock on the console subsystem without waiting.
> If successful, reset the sequence number to oldest available
> record on all consoles and call console_unlock() which will
> automatically flush the messages to the consoles.
>
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -4259,6 +4271,23 @@ void kmsg_dump_rewind(struct kmsg_dump_iter *iter)
> }
> EXPORT_SYMBOL_GPL(kmsg_dump_rewind);
>
> +/**
> + * console_replay_all - replay kernel log on consoles

It should rather be called "console_try_replay_all()" to make it clear
that it is just the best effort.

> + *
> + * Try to obtain lock on console subsystem and replay all
> + * available records in printk buffer on the consoles.
> + * Does nothing if lock is not obtained.
> + *
> + * Context: Any context.

This should be:

* Context: Any, except for NMI

Basically only lockless code is safe in NMI which is not the case here.

> + */
> +void console_replay_all(void)
> +{
> + if (console_trylock()) {
> + __console_rewind_all();
> + /* Consoles are flushed as part of console_unlock(). */
> + console_unlock();
> + }
> +}
> #endif

Otherwise, it looks good. With the two changes:

Reviewed-by: Petr Mladek <pmladek@suse.com>

I am sorry for the late review. I have been snowed under tasks.
Also I had healthy problems.

I have seen a mail that Greg has queued the patch in tty-next.
I am not sure if it still can be fixed. It will be perfectly fine
to change this by a followup patch.

Best Regards,
Petr

\
 
 \ /
  Last update: 2024-05-22 17:18    [W:0.058 / U:0.440 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site