Re: [PATCH v6 08/11] printk: Support setting initial console loglevel via console= on cmdline

From: Petr Mladek
Date: Thu Nov 14 2024 - 04:12:11 EST


On Mon 2024-10-28 16:45:52, Chris Down wrote:
> Extend the console= kernel command line parameter to support specifying
> per-console loglevels at boot time. This is achieved by introducing a
> new loglevel option that can be passed as a loglevel option within a
> console= stanza.
>
> For example, this is an example of how one might configure netconsole
> devices to print messages with a higher priority than loglevel 3
> (KERN_ERR) at startup:
>
> console=netcon0,loglevel:3
>
> --- a/Documentation/admin-guide/serial-console.rst
> +++ b/Documentation/admin-guide/serial-console.rst
> @@ -32,6 +32,33 @@ The format of this option is::
> and F is flow control ('r' for RTS). Default is
> 9600n8. The maximum baudrate is 115200.
>
> + One can also specify the per-console loglevel for this
> + console by providing a loglevel parameter, for example
> + "loglevel:4" to set this console's loglevel to 4. The
> + value provided can be from 0 (LOGLEVEL_EMERG) to 8

The real lower limit, enforced by clamp_loglevel(), is 1.

> + (LOGLEVEL_DEBUG + 1), and messages below that will be
> + emitted onto the console as they become available.
> +
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -3903,8 +3982,10 @@ static int try_enable_preferred_console(struct console *newcon,
> if (newcon->index < 0)
> newcon->index = c->index;
>
> - // TODO: Will be configurable in a later patch
> - newcon->level = -1;
> + if (c->level > 0)
> + newcon->level = c->level;
> + else
> + newcon->level = -1;

It seems that c->level is already set to -1 when it is not defined on
the command line. I think that that we could simply do:

newcon->level = c->level;

Just for record. We need to explicitely set newcon->level to -1 in
try_enable_default_console().


> newcon->classdev = NULL;
>

Otherwise, it looks good.

Best Regards,
Petr