From: Petr Mladek <pmladek@suse.com>
To: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>,
Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org,
Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Subject: Re: [RFC][PATCH 2/2] printk: take console_sem when accessing console drivers list
Date: Wed, 24 Apr 2019 17:13:06 +0200 [thread overview]
Message-ID: <20190424151306.jcmygibltizcorgk@pathway.suse.cz> (raw)
In-Reply-To: <20190423062511.1118-3-sergey.senozhatsky@gmail.com>
On Tue 2019-04-23 15:25:11, Sergey Senozhatsky wrote:
> We need to take console_sem lock when we iterate console
> drivers list. Otherwise, another CPU can concurrently
> modify console drivers list or console drivers.
>
> Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
> ---
> kernel/printk/printk.c | 19 +++++++++++++------
> 1 file changed, 13 insertions(+), 6 deletions(-)
>
> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> index b0e361ca1bea..c2bccf58d03e 100644
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -2674,12 +2674,17 @@ void register_console(struct console *newcon)
> struct console_cmdline *c;
> static bool has_preferred;
>
> - if (console_drivers)
> - for_each_console(bcon)
> - if (WARN(bcon == newcon,
> - "console '%s%d' already registered\n",
> - bcon->name, bcon->index))
> - return;
> + console_lock();
> + if (console_drivers) {
> + for_each_console(bcon) {
> + if (bcon != newcon)
> + continue;
> + WARN(1, "console '%s%d' already registered\n",
> + bcon->name, bcon->index);
> + console_unlock();
> + return;
> + }
> + }
>
> /*
> * before we register a new CON_BOOT console, make sure we don't
> @@ -2691,6 +2696,7 @@ void register_console(struct console *newcon)
> if (!(bcon->flags & CON_BOOT)) {
> pr_info("Too late to register bootconsole %s%d\n",
> newcon->name, newcon->index);
> + console_unlock();
> return;
> }
> }
> @@ -2701,6 +2707,7 @@ void register_console(struct console *newcon)
>
> if (!has_preferred || bcon || !console_drivers)
> has_preferred = preferred_console >= 0;
> + console_unlock();
We should keep it until the console is added into the list. Otherwise
there are races with accessing the static has_preferred and
the global preferred_console variables.
Also the value of bcon should stay synchronized until we decide
about replaying the log.
IMHO, the only danger might be when con->match() or con->setup()
would want to take console_lock() as well. I checked few drivers
and they looked safe. But I did not check all of them.
What do you think, please?
Best Regards,
Petr
next prev parent reply other threads:[~2019-04-24 15:13 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-23 6:25 [RFC][PATCH 0/2] Access console drivers list under console_sem Sergey Senozhatsky
2019-04-23 6:25 ` [RFC][PATCH 1/2] printk: lock console_sem before we unregister boot consoles Sergey Senozhatsky
2019-04-24 14:49 ` Petr Mladek
2019-04-25 3:52 ` Sergey Senozhatsky
2019-04-25 6:43 ` Sergey Senozhatsky
2019-04-25 9:20 ` Petr Mladek
2019-04-25 16:05 ` Steven Rostedt
2019-04-25 7:50 ` Petr Mladek
2019-04-25 7:56 ` Sergey Senozhatsky
2019-04-25 9:37 ` Sergey Senozhatsky
2019-04-23 6:25 ` [RFC][PATCH 2/2] printk: take console_sem when accessing console drivers list Sergey Senozhatsky
2019-04-24 15:13 ` Petr Mladek [this message]
2019-04-25 5:19 ` Sergey Senozhatsky
2019-04-25 6:47 ` Sergey Senozhatsky
2019-04-25 8:53 ` Petr Mladek
2019-04-23 13:48 ` [RFC][PATCH 0/2] Access console drivers list under console_sem Steven Rostedt
2019-04-24 5:43 ` Sergey Senozhatsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190424151306.jcmygibltizcorgk@pathway.suse.cz \
--to=pmladek@suse.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=sergey.senozhatsky.work@gmail.com \
--cc=sergey.senozhatsky@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).