lkml.org 
[lkml]   [2019]   [Apr]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [RFC][PATCH 1/2] printk: lock console_sem before we unregister boot consoles
On Tue 2019-04-23 15:25:10, Sergey Senozhatsky wrote:
> The following pattern is not completely safe:
>
> for_each_console(bcon)
> if (bcon->flags & CON_BOOT)
> unregister_console(bcon);
>
> Because, in theory, console drivers list and console drivers
> can be modified concurrently from another CPU. Take console_sem
> lock, which protects console drivers list and console drivers,
> before we start iterating console drivers list.
>
> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> index 17102fd4c136..b0e361ca1bea 100644
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -2777,62 +2819,34 @@ void register_console(struct console *newcon)
> pr_info("%sconsole [%s%d] enabled\n",
> (newcon->flags & CON_BOOT) ? "boot" : "" ,
> newcon->name, newcon->index);
> - if (bcon &&
> - ((newcon->flags & (CON_CONSDEV | CON_BOOT)) == CON_CONSDEV) &&
> - !keep_bootcon) {
> - /* We need to iterate through all boot consoles, to make
> +
> + if (keep_bootcon)
> + return;
> +
> + if (bcon && (newcon->flags & (CON_CONSDEV|CON_BOOT)) == CON_CONSDEV) {
> + console_lock();
> + /*
> + * We need to iterate through all boot consoles, to make
> * sure we print everything out, before we unregister them.
> */

I wondered if moving the console locking could break the above
statement.

It seems that the comment has been invalid since the commit
8259cf4342029aad37660e ("printk: Ensure that "console
enabled" messages are printed on the console").

Could we remove it in this patch? It touches it indirectly anyway.

Otherwise, the patch looks fine to me:

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

> for_each_console(bcon)
> if (bcon->flags & CON_BOOT)
> - unregister_console(bcon);
> + __unregister_console(bcon);
> + console_unlock();
> + console_sysfs_notify();
> }
> }
> EXPORT_SYMBOL(register_console);

Best Regards,
Petr

\
 
 \ /
  Last update: 2019-04-24 16:50    [W:0.115 / U:6.452 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site