From: Petr Mladek <pmladek@suse.com>
To: John Ogness <john.ogness@linutronix.de>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>,
Steven Rostedt <rostedt@goodmis.org>,
Thomas Gleixner <tglx@linutronix.de>,
linux-kernel@vger.kernel.org,
Jason Wessel <jason.wessel@windriver.com>,
Daniel Thompson <daniel.thompson@linaro.org>,
Douglas Anderson <dianders@chromium.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jiri Slaby <jirislaby@kernel.org>,
kgdb-bugreport@lists.sourceforge.net,
linux-serial@vger.kernel.org
Subject: Re: [PATCH printk v2 21/38] serial: kgdboc: use srcu console list iterator
Date: Fri, 21 Oct 2022 17:09:24 +0200 [thread overview]
Message-ID: <Y1K2JP6LIf8H2Ub5@alley> (raw)
In-Reply-To: <20221019145600.1282823-22-john.ogness@linutronix.de>
On Wed 2022-10-19 17:01:43, John Ogness wrote:
> Use srcu console list iteration for safe console list traversal.
>
> Note that configure_kgdboc() still requires the console_lock in
> order to ensure that no console is in its write() callback when
> its direct() callback is called. Add comments to clarify this.
s/direct()/device()/
Do you know about such requirements or is it just
a conservative approach, please?
I ask because the comment in the code says "may assume".
Anyway, this would deserve a comment why the SRCU list iteration is
needed even when console_lock() is needed as well.
The reason is that further patches are going to synchronize
console_list manipulation with another lock and console_lock()
will be used only to serialize accessing con->write() callbacks.
Best Regards,
Petr
> Signed-off-by: John Ogness <john.ogness@linutronix.de>
> ---
> drivers/tty/serial/kgdboc.c | 21 ++++++++++++++++++---
> 1 file changed, 18 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
> index b17aa7e49894..e9d3f8c6e3dc 100644
> --- a/drivers/tty/serial/kgdboc.c
> +++ b/drivers/tty/serial/kgdboc.c
> @@ -171,6 +171,7 @@ static int configure_kgdboc(void)
> int err = -ENODEV;
> char *cptr = config;
> struct console *cons;
> + int cookie;
>
> if (!strlen(config) || isspace(config[0])) {
> err = 0;
> @@ -193,8 +194,14 @@ static int configure_kgdboc(void)
> if (!p)
> goto noconfig;
>
> + /*
> + * Stop console printing because the device() callback may
> + * assume the console is not within its write() callback.
> + */
> console_lock();
> - for_each_console(cons) {
> +
> + cookie = console_srcu_read_lock();
> + for_each_console_srcu(cons) {
> int idx;
> if (cons->device && cons->device(cons, &idx) == p &&
> idx == tty_line) {
> @@ -202,6 +209,8 @@ static int configure_kgdboc(void)
> break;
> }
> }
> + console_srcu_read_unlock(cookie);
> +
> console_unlock();
>
> kgdb_tty_driver = p;
> @@ -451,6 +460,7 @@ static void kgdboc_earlycon_pre_exp_handler(void)
> {
> struct console *con;
> static bool already_warned;
> + int cookie;
>
> if (already_warned)
> return;
> @@ -463,9 +473,14 @@ static void kgdboc_earlycon_pre_exp_handler(void)
> * serial drivers might be OK with this, print a warning once per
> * boot if we detect this case.
> */
> - for_each_console(con)
> + cookie = console_srcu_read_lock();
> + for_each_console_srcu(con) {
> if (con == kgdboc_earlycon_io_ops.cons)
> - return;
> + break;
> + }
> + console_srcu_read_unlock(cookie);
> + if (con)
> + return;
>
> already_warned = true;
> pr_warn("kgdboc_earlycon is still using bootconsole\n");
> --
> 2.30.2
next prev parent reply other threads:[~2022-10-21 15:09 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-19 14:55 [PATCH printk v2 00/38] reduce console_lock scope John Ogness
2022-10-19 14:55 ` [PATCH printk v2 01/38] serial: kgdboc: Lock console list in probe function John Ogness
2022-10-19 15:41 ` Greg Kroah-Hartman
2022-10-24 5:22 ` Sergey Senozhatsky
2022-10-25 0:34 ` Doug Anderson
2022-10-19 14:55 ` [PATCH printk v2 11/38] tty: serial: earlycon: use console_is_enabled() John Ogness
2022-10-19 16:01 ` Greg Kroah-Hartman
2022-10-21 13:51 ` Petr Mladek
2022-10-19 14:55 ` [PATCH printk v2 12/38] tty: serial: kgdboc: " John Ogness
2022-10-19 16:00 ` Greg Kroah-Hartman
2022-10-21 14:10 ` Petr Mladek
2022-10-24 22:46 ` Doug Anderson
2022-10-25 0:49 ` Doug Anderson
2022-10-25 11:28 ` John Ogness
2022-11-04 16:23 ` John Ogness
2022-11-07 8:47 ` Petr Mladek
2022-11-07 9:45 ` John Ogness
2022-10-19 14:55 ` [PATCH printk v2 13/38] tty: serial: pic32_uart: " John Ogness
2022-10-19 16:01 ` Greg Kroah-Hartman
2022-10-21 14:11 ` Petr Mladek
2022-10-19 14:55 ` [PATCH printk v2 14/38] tty: serial: samsung_tty: " John Ogness
2022-10-19 16:00 ` Greg Kroah-Hartman
2022-10-21 14:14 ` Petr Mladek
2022-10-19 14:55 ` [PATCH printk v2 15/38] tty: serial: serial_core: " John Ogness
2022-10-19 16:00 ` Greg Kroah-Hartman
2022-10-21 14:14 ` Petr Mladek
2022-10-19 14:55 ` [PATCH printk v2 16/38] tty: serial: xilinx_uartps: " John Ogness
2022-10-19 16:01 ` Greg Kroah-Hartman
2022-10-21 14:23 ` Petr Mladek
2022-10-19 14:55 ` [PATCH printk v2 21/38] serial: kgdboc: use srcu console list iterator John Ogness
2022-10-19 16:02 ` Greg Kroah-Hartman
2022-10-21 15:09 ` Petr Mladek [this message]
2022-10-25 0:33 ` Doug Anderson
2022-10-19 14:55 ` [PATCH printk v2 22/38] serial: kgdboc: document console_lock usage John Ogness
2022-10-20 7:42 ` Greg Kroah-Hartman
2022-10-25 0:36 ` Doug Anderson
2022-10-25 10:09 ` Petr Mladek
2022-10-19 14:55 ` [PATCH printk v2 34/38] serial: kgdboc: use console_list_lock instead of console_lock John Ogness
2022-10-20 7:52 ` Greg Kroah-Hartman
2022-10-27 10:13 ` Petr Mladek
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=Y1K2JP6LIf8H2Ub5@alley \
--to=pmladek@suse.com \
--cc=daniel.thompson@linaro.org \
--cc=dianders@chromium.org \
--cc=gregkh@linuxfoundation.org \
--cc=jason.wessel@windriver.com \
--cc=jirislaby@kernel.org \
--cc=john.ogness@linutronix.de \
--cc=kgdb-bugreport@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=senozhatsky@chromium.org \
--cc=tglx@linutronix.de \
/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).