All of lore.kernel.org
 help / color / mirror / Atom feed
From: John Ogness <john.ogness@linutronix.de>
To: Petr Mladek <pmladek@suse.com>
Cc: "Sergey Senozhatsky" <senozhatsky@chromium.org>,
	"Steven Rostedt" <rostedt@goodmis.org>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	linux-kernel@vger.kernel.org,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Jiri Slaby" <jirislaby@kernel.org>,
	"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	"Lukas Wunner" <lukas@wunner.de>,
	"Geert Uytterhoeven" <geert+renesas@glider.be>,
	linux-serial@vger.kernel.org
Subject: [PATCH printk v5 22/40] serial_core: replace uart_console_enabled() with uart_console_registered()
Date: Wed, 16 Nov 2022 17:27:34 +0106	[thread overview]
Message-ID: <20221116162152.193147-23-john.ogness@linutronix.de> (raw)
In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de>

All users of uart_console_enabled() really want to know if a console
is registered. It is not reliable to check for CON_ENABLED in order
to identify if a console is registered. Use console_is_registered()
instead.

A _locked() variant is provided because uart_set_options() is always
called with the console_list_lock held and must check if a console
is registered in order to synchronize with kgdboc.

Signed-off-by: John Ogness <john.ogness@linutronix.de>
Reviewed-by: Petr Mladek <pmladek@suse.com>
---
 drivers/tty/serial/8250/8250_core.c |  2 +-
 drivers/tty/serial/pic32_uart.c     |  2 +-
 drivers/tty/serial/serial_core.c    | 14 +++++++-------
 include/linux/serial_core.h         | 10 ++++++++--
 4 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c
index 94fbf0add2ce..74568292186f 100644
--- a/drivers/tty/serial/8250/8250_core.c
+++ b/drivers/tty/serial/8250/8250_core.c
@@ -565,7 +565,7 @@ serial8250_register_ports(struct uart_driver *drv, struct device *dev)
 
 		up->port.dev = dev;
 
-		if (uart_console_enabled(&up->port))
+		if (uart_console_registered(&up->port))
 			pm_runtime_get_sync(up->port.dev);
 
 		serial8250_apply_quirks(up);
diff --git a/drivers/tty/serial/pic32_uart.c b/drivers/tty/serial/pic32_uart.c
index 2beada66c824..1183b2a26539 100644
--- a/drivers/tty/serial/pic32_uart.c
+++ b/drivers/tty/serial/pic32_uart.c
@@ -919,7 +919,7 @@ static int pic32_uart_probe(struct platform_device *pdev)
 	}
 
 #ifdef CONFIG_SERIAL_PIC32_CONSOLE
-	if (uart_console_enabled(port)) {
+	if (uart_console_registered(port)) {
 		/* The peripheral clock has been enabled by console_setup,
 		 * so disable it till the port is used.
 		 */
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 179ee199df34..b9fbbee598b8 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -2223,11 +2223,11 @@ uart_set_options(struct uart_port *port, struct console *co,
 	/*
 	 * Ensure that the serial-console lock is initialised early.
 	 *
-	 * Note that the console-enabled check is needed because of kgdboc,
-	 * which can end up calling uart_set_options() for an already enabled
+	 * Note that the console-registered check is needed because
+	 * kgdboc can call uart_set_options() for an already registered
 	 * console via tty_find_polling_driver() and uart_poll_init().
 	 */
-	if (!uart_console_enabled(port) && !port->console_reinit)
+	if (!uart_console_registered_locked(port) && !port->console_reinit)
 		uart_port_spin_lock_init(port);
 
 	memset(&termios, 0, sizeof(struct ktermios));
@@ -2573,7 +2573,7 @@ uart_configure_port(struct uart_driver *drv, struct uart_state *state,
 		 * successfully registered yet, try to re-register it.
 		 * It may be that the port was not available.
 		 */
-		if (port->cons && !(port->cons->flags & CON_ENABLED))
+		if (port->cons && !console_is_registered(port->cons))
 			register_console(port->cons);
 
 		/*
@@ -2956,7 +2956,7 @@ static ssize_t console_show(struct device *dev,
 	mutex_lock(&port->mutex);
 	uport = uart_port_check(state);
 	if (uport)
-		console = uart_console_enabled(uport);
+		console = uart_console_registered(uport);
 	mutex_unlock(&port->mutex);
 
 	return sprintf(buf, "%c\n", console ? 'Y' : 'N');
@@ -2978,7 +2978,7 @@ static ssize_t console_store(struct device *dev,
 	mutex_lock(&port->mutex);
 	uport = uart_port_check(state);
 	if (uport) {
-		oldconsole = uart_console_enabled(uport);
+		oldconsole = uart_console_registered(uport);
 		if (oldconsole && !newconsole) {
 			ret = unregister_console(uport->cons);
 		} else if (!oldconsole && newconsole) {
@@ -3086,7 +3086,7 @@ int uart_add_one_port(struct uart_driver *drv, struct uart_port *uport)
 	 * If this port is in use as a console then the spinlock is already
 	 * initialised.
 	 */
-	if (!uart_console_enabled(uport))
+	if (!uart_console_registered(uport))
 		uart_port_spin_lock_init(uport);
 
 	if (uport->cons && uport->dev)
diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
index d657f2a42a7b..91871464b99d 100644
--- a/include/linux/serial_core.h
+++ b/include/linux/serial_core.h
@@ -743,9 +743,15 @@ static const bool earlycon_acpi_spcr_enable EARLYCON_USED_OR_UNUSED;
 static inline int setup_earlycon(char *buf) { return 0; }
 #endif
 
-static inline bool uart_console_enabled(struct uart_port *port)
+/* Variant of uart_console_registered() when the console_list_lock is held. */
+static inline bool uart_console_registered_locked(struct uart_port *port)
 {
-	return uart_console(port) && (port->cons->flags & CON_ENABLED);
+	return uart_console(port) && console_is_registered_locked(port->cons);
+}
+
+static inline bool uart_console_registered(struct uart_port *port)
+{
+	return uart_console(port) && console_is_registered(port->cons);
 }
 
 struct uart_port *uart_get_console(struct uart_port *ports, int nr,
-- 
2.30.2


  parent reply	other threads:[~2022-11-16 16:24 UTC|newest]

Thread overview: 83+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-16 16:21 [PATCH printk v5 00/40] reduce console_lock scope John Ogness
2022-11-16 16:21 ` John Ogness
2022-11-16 16:21 ` John Ogness
2022-11-16 16:21 ` John Ogness
2022-11-16 16:21 ` [PATCH printk v5 01/40] serial: kgdboc: Lock console list in probe function John Ogness
2022-11-16 16:21 ` [PATCH printk v5 02/40] printk: Convert console_drivers list to hlist John Ogness
2022-11-16 16:21 ` [PATCH printk v5 03/40] printk: Prepare for SRCU console list protection John Ogness
2022-12-01 18:22   ` Nathan Chancellor
2022-12-01 21:36     ` John Ogness
2022-12-01 21:56       ` Paul E. McKenney
2022-12-01 22:12         ` John Ogness
2022-12-02  0:21           ` Paul E. McKenney
2022-12-02 10:53             ` Petr Mladek
2022-11-16 16:21 ` [PATCH printk v5 04/40] printk: register_console: use "registered" for variable names John Ogness
2022-11-16 16:21 ` [PATCH printk v5 05/40] printk: move @seq initialization to helper John Ogness
2022-11-18  9:56   ` Petr Mladek
2022-11-16 16:21 ` [PATCH printk v5 06/40] printk: fix setting first seq for consoles John Ogness
2022-11-18 10:23   ` Petr Mladek
2022-11-18 10:52     ` John Ogness
2022-11-16 16:21 ` [PATCH printk v5 07/40] um: kmsg_dump: only dump when no output console available John Ogness
2022-11-16 16:21   ` John Ogness
2022-11-16 16:21 ` [PATCH printk v5 08/40] tty: serial: kgdboc: document console_lock usage John Ogness
2022-11-16 16:21 ` [PATCH printk v5 09/40] tty: tty_io: " John Ogness
2022-11-16 16:21 ` [PATCH printk v5 10/40] proc: consoles: " John Ogness
2022-11-16 16:21 ` [PATCH printk v5 11/40] printk: introduce console_list_lock John Ogness
2022-11-21 11:10   ` [PATCH printk v6 " John Ogness
2022-11-21 13:36     ` Petr Mladek
2022-11-16 16:21 ` [PATCH printk v5 12/40] console: introduce wrappers to read/write console flags John Ogness
2022-11-16 16:21 ` [PATCH printk v5 13/40] um: kmsg_dumper: use srcu console list iterator John Ogness
2022-11-16 16:21   ` John Ogness
2022-11-16 16:21 ` [PATCH printk v5 14/40] kdb: " John Ogness
2022-11-17  0:59   ` Doug Anderson
2022-11-16 16:21 ` [PATCH printk v5 15/40] printk: console_flush_all: " John Ogness
2022-11-16 16:21 ` [PATCH printk v5 16/40] printk: __pr_flush: " John Ogness
2022-11-16 16:21 ` [PATCH printk v5 17/40] printk: console_is_usable: use console_srcu_read_flags John Ogness
2022-11-16 16:21 ` [PATCH printk v5 18/40] printk: console_unblank: use srcu console list iterator John Ogness
2022-11-16 16:21 ` [PATCH printk v5 19/40] printk: console_flush_on_panic: " John Ogness
2022-11-16 16:21 ` [PATCH printk v5 20/40] printk: console_device: " John Ogness
2022-11-16 16:21 ` [PATCH printk v5 21/40] console: introduce console_is_registered() John Ogness
2022-11-16 16:21 ` John Ogness [this message]
2022-11-16 16:21 ` [PATCH printk v5 23/40] tty: nfcon: use console_is_registered() John Ogness
2022-11-17  8:18   ` Geert Uytterhoeven
2022-11-16 16:21 ` [PATCH printk v5 24/40] efi: earlycon: " John Ogness
2022-11-16 16:21 ` [PATCH printk v5 25/40] tty: hvc: " John Ogness
2022-11-16 16:21   ` John Ogness
2022-11-16 16:21 ` [PATCH printk v5 26/40] tty: serial: earlycon: " John Ogness
2022-11-16 16:21 ` [PATCH printk v5 27/40] tty: serial: pic32_uart: " John Ogness
2022-11-16 16:21 ` [PATCH printk v5 28/40] tty: serial: samsung_tty: " John Ogness
2022-11-16 16:21   ` John Ogness
2022-11-16 16:21 ` [PATCH printk v5 29/40] tty: serial: xilinx_uartps: " John Ogness
2022-11-16 16:21   ` John Ogness
2022-11-16 16:21 ` [PATCH printk v5 30/40] usb: early: xhci-dbc: " John Ogness
2022-11-16 16:21 ` [PATCH printk v5 31/40] netconsole: avoid CON_ENABLED misuse to track registration John Ogness
2022-11-16 16:21 ` [PATCH printk v5 32/40] printk, xen: fbfront: create/use safe function for forcing preferred John Ogness
2022-11-16 16:21   ` John Ogness
2022-11-16 16:21 ` [PATCH printk v5 33/40] tty: tty_io: use console_list_lock for list synchronization John Ogness
2022-11-16 16:21 ` [PATCH printk v5 34/40] proc: consoles: use console_list_lock for list iteration John Ogness
2022-11-16 16:21 ` [PATCH printk v5 35/40] tty: serial: kgdboc: use srcu console list iterator John Ogness
2022-11-17  0:59   ` Doug Anderson
2022-11-17  9:32     ` John Ogness
2022-11-16 16:21 ` [PATCH printk v5 36/40] tty: serial: kgdboc: use console_list_lock for list traversal John Ogness
2022-11-17  0:59   ` Doug Anderson
2022-11-16 16:21 ` [PATCH printk v5 37/40] tty: serial: kgdboc: synchronize tty_find_polling_driver() and register_console() John Ogness
2022-11-17  0:59   ` Doug Anderson
2022-11-17 10:00     ` John Ogness
2022-11-16 16:21 ` [PATCH printk v5 38/40] tty: serial: kgdboc: use console_list_lock to trap exit John Ogness
2022-11-17  0:56   ` Doug Anderson
2022-11-17 11:08     ` John Ogness
2022-11-16 16:21 ` [PATCH printk v5 39/40] printk: relieve console_lock of list synchronization duties John Ogness
2022-11-18 11:07   ` Petr Mladek
2022-11-16 16:21 ` [PATCH printk v5 40/40] tty: serial: sh-sci: use setup() callback for early console John Ogness
2022-11-18 11:22 ` [PATCH printk v5 00/40] reduce console_lock scope Petr Mladek
2022-11-18 11:22   ` Petr Mladek
2022-11-18 11:22   ` Petr Mladek
2022-11-18 11:22   ` Petr Mladek
2022-11-18 14:55   ` Petr Mladek
2022-11-18 14:55     ` Petr Mladek
2022-11-18 14:55     ` Petr Mladek
2022-11-18 14:55     ` Petr Mladek
2022-11-22 16:43 ` Greg Kroah-Hartman
2022-11-22 16:43   ` Greg Kroah-Hartman
2022-11-22 16:43   ` Greg Kroah-Hartman
2022-11-22 16:43   ` Greg Kroah-Hartman

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=20221116162152.193147-23-john.ogness@linutronix.de \
    --to=john.ogness@linutronix.de \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=geert+renesas@glider.be \
    --cc=gregkh@linuxfoundation.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=jirislaby@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=pmladek@suse.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.