Re: [PATCH v3 2/3] printk: Fix preferred console selection with multiple matches

From: Petr Mladek
Date: Tue Feb 11 2020 - 09:41:38 EST


On Thu 2020-02-06 15:02:25, Benjamin Herrenschmidt wrote:
> In the following circumstances, the rule of selecting the console
> corresponding to the last "console=" entry on the command line as
> the preferred console (CON_CONSDEV, ie, /dev/console) fails. This
> is a specific example, but it could happen with different consoles
> that have a similar name aliasing mechanism.
>
> This tentative fix register_console() to scan first for consoles
> specified on the command line, and only if none is found, to then
> scan for consoles specified by the architecture.
>
> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> index 17602d7b7ffc..5cf47a7b880c 100644
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -2674,8 +2679,13 @@ static int try_enable_new_console(struct console *newcon)
> /*
> * Some consoles, such as pstore and netconsole, can be enabled even
> * without matching.
> + *
> + * Note: We only do this test on the !user_specified pass so that such
> + * a statically enabled console that isn't user specified gets a chance
> + * to have its match() or setup() function called on our second pass
> + * through this function.

I had some troubles to part the comment. I wonder if the following is
more clear:

* Accept pre-enabled consoles only when match() and setup()
* was called.

And I would do the same check as in the for cycle:

if (newcon->flags & CON_ENABLED && c->user_specified == user_specified)
return 0;

With the above change:

Reviewed-by: Petr Mladek <pmladek@xxxxxxxx>

I could do the change when pushing if you agree and v4 is not needed
for other reasons.

Best Regards,
Petr

PS: JFYI, I am going to look at the 3rd patch tomorrow. I have to go now.