linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH printk v8 00/35] wire up write_atomic() printing
@ 2024-08-20  6:29 John Ogness
  2024-08-20  6:29 ` [PATCH printk v8 10/35] serial: core: Provide low-level functions to lock port John Ogness
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: John Ogness @ 2024-08-20  6:29 UTC (permalink / raw)
  To: Petr Mladek
  Cc: Sergey Senozhatsky, Steven Rostedt, Thomas Gleixner, linux-kernel,
	Miguel Ojeda, Paul E. McKenney, Greg Kroah-Hartman, Jiri Slaby,
	linux-serial, Russell King, Tony Lindgren, Andy Shevchenko,
	Geert Uytterhoeven, Arnd Bergmann, Uwe Kleine-König,
	Théo Lebrun, Linus Walleij, Lino Sanfilippo,
	Ilpo Järvinen, Konrad Dybcio, Sebastian Andrzej Siewior,
	Andrew Morton, Jani Nikula, Ryo Takakura, Uros Bizjak,
	Joel Granados, Lukas Wunner, Feng Tang, Baoquan He,
	Frederic Weisbecker, Neeraj Upadhyay, Joel Fernandes,
	Josh Triplett, Boqun Feng, Uladzislau Rezki, Mathieu Desnoyers,
	Lai Jiangshan, Zqiang, rcu, Peter Zijlstra, Ingo Molnar,
	Will Deacon, Waiman Long

Hi,

This is v8 of a series to wire up the nbcon consoles so that
they actually perform printing using their write_atomic()
callback. v7 is here [0]. For information about the motivation
of the atomic consoles, please read the cover letter of v1 [1].

The main focus of this series:

- For nbcon consoles, always call write_atomic() directly from
  printk() caller context for the panic CPU.

- For nbcon consoles, call write_atomic() when unlocking the
  console lock.

- Only perform the console lock/unlock dance if legacy or boot
  consoles are registered.

- For legacy consoles, if nbcon consoles are registered, do not
  attempt to print from printk() caller context for the panic
  CPU until nbcon consoles have had a chance to print the most
  significant messages.

- Mark emergency sections. In these sections, every printk()
  call will attempt to directly flush to the consoles using the
  EMERGENCY priority.

This series does _not_ include threaded printing or nbcon
drivers. Those features will be added in separate follow-up
series.

The changes since v7:

- Change printk_get_console_flush_type() to set preferred flush
  types.

- Change printk_get_console_flush_type() to also check for
  legacy consoles before seting @legacy_direct.

- Change vprintk_emit() to hack the struct console_flush_type
  for LOGLEVEL_SCHED rather than using local variables.

- Change console_cpu_notify() to also flush nbcon atomic
  consoles.

- Remove unnecessary flush type check in
  nbcon_atomic_flush_pending_con(). It is not needed until the
  threaded series.

- Fix compiling issues related to @legacy_allow_panic_sync for
  !CONFIG_PRINTK.

John Ogness

[0] https://lore.kernel.org/lkml/20240804005138.3722656-1-john.ogness@linutronix.de
[1] https://lore.kernel.org/lkml/20230302195618.156940-1-john.ogness@linutronix.de

John Ogness (30):
  printk: Add notation to console_srcu locking
  printk: nbcon: Consolidate alloc() and init()
  printk: nbcon: Clarify rules of the owner/waiter matching
  printk: nbcon: Remove return value for write_atomic()
  printk: nbcon: Add detailed doc for write_atomic()
  printk: nbcon: Add callbacks to synchronize with driver
  printk: nbcon: Use driver synchronization while (un)registering
  serial: core: Provide low-level functions to lock port
  serial: core: Introduce wrapper to set @uart_port->cons
  console: Improve console_srcu_read_flags() comments
  nbcon: Add API to acquire context for non-printing operations
  serial: core: Acquire nbcon context in port->lock wrapper
  printk: nbcon: Do not rely on proxy headers
  printk: Make console_is_usable() available to nbcon.c
  printk: Let console_is_usable() handle nbcon
  printk: Add @flags argument for console_is_usable()
  printk: nbcon: Add helper to assign priority based on CPU state
  printk: Track registered boot consoles
  printk: nbcon: Use nbcon consoles in console_flush_all()
  printk: Add is_printk_legacy_deferred()
  printk: nbcon: Flush new records on device_release()
  printk: Flush nbcon consoles first on panic
  printk: nbcon: Add unsafe flushing on panic
  printk: Avoid console_lock dance if no legacy or boot consoles
  printk: Track nbcon consoles
  printk: Coordinate direct printing in panic
  printk: Add helper for flush type logic
  panic: Mark emergency section in oops
  rcu: Mark emergency sections in rcu stalls
  lockdep: Mark emergency sections in lockdep splats

Petr Mladek (1):
  printk: Properly deal with nbcon consoles on seq init

Sebastian Andrzej Siewior (1):
  printk: Check printk_deferred_enter()/_exit() usage

Thomas Gleixner (3):
  printk: nbcon: Provide function to flush using write_atomic()
  printk: nbcon: Implement emergency sections
  panic: Mark emergency section in warn

 drivers/tty/serial/8250/8250_core.c |   6 +-
 drivers/tty/serial/amba-pl011.c     |   2 +-
 drivers/tty/serial/serial_core.c    |  16 +-
 include/linux/console.h             | 110 +++++-
 include/linux/printk.h              |  33 +-
 include/linux/serial_core.h         | 117 +++++-
 kernel/locking/lockdep.c            |  83 ++++-
 kernel/panic.c                      |   9 +
 kernel/printk/internal.h            | 137 ++++++-
 kernel/printk/nbcon.c               | 556 +++++++++++++++++++++++++---
 kernel/printk/printk.c              | 251 ++++++++++---
 kernel/printk/printk_ringbuffer.h   |   2 +
 kernel/printk/printk_safe.c         |  23 +-
 kernel/rcu/tree_exp.h               |   7 +
 kernel/rcu/tree_stall.h             |   9 +
 15 files changed, 1210 insertions(+), 151 deletions(-)


base-commit: bcc954c6caba01fca143162d5fbb90e46aa1ad80
-- 
2.39.2


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH printk v8 10/35] serial: core: Provide low-level functions to lock port
  2024-08-20  6:29 [PATCH printk v8 00/35] wire up write_atomic() printing John Ogness
@ 2024-08-20  6:29 ` John Ogness
  2024-08-20  6:29 ` [PATCH printk v8 11/35] serial: core: Introduce wrapper to set @uart_port->cons John Ogness
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: John Ogness @ 2024-08-20  6:29 UTC (permalink / raw)
  To: Petr Mladek
  Cc: Sergey Senozhatsky, Steven Rostedt, Thomas Gleixner, linux-kernel,
	Greg Kroah-Hartman, Jiri Slaby, linux-serial

It will be necessary at times for the uart nbcon console
drivers to acquire the port lock directly (without the
additional nbcon functionality of the port lock wrappers).
These are special cases such as the implementation of the
device_lock()/device_unlock() callbacks or for internal
port lock wrapper synchronization.

Provide low-level variants __uart_port_lock_irqsave() and
__uart_port_unlock_irqrestore() for this purpose.

Signed-off-by: John Ogness <john.ogness@linutronix.de>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 include/linux/serial_core.h | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
index aea25eef9a1a..8872cd21e70a 100644
--- a/include/linux/serial_core.h
+++ b/include/linux/serial_core.h
@@ -590,6 +590,24 @@ struct uart_port {
 	void			*private_data;		/* generic platform data pointer */
 };
 
+/*
+ * Only for console->device_lock()/_unlock() callbacks and internal
+ * port lock wrapper synchronization.
+ */
+static inline void __uart_port_lock_irqsave(struct uart_port *up, unsigned long *flags)
+{
+	spin_lock_irqsave(&up->lock, *flags);
+}
+
+/*
+ * Only for console->device_lock()/_unlock() callbacks and internal
+ * port lock wrapper synchronization.
+ */
+static inline void __uart_port_unlock_irqrestore(struct uart_port *up, unsigned long flags)
+{
+	spin_unlock_irqrestore(&up->lock, flags);
+}
+
 /**
  * uart_port_lock - Lock the UART port
  * @up:		Pointer to UART port structure
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH printk v8 11/35] serial: core: Introduce wrapper to set @uart_port->cons
  2024-08-20  6:29 [PATCH printk v8 00/35] wire up write_atomic() printing John Ogness
  2024-08-20  6:29 ` [PATCH printk v8 10/35] serial: core: Provide low-level functions to lock port John Ogness
@ 2024-08-20  6:29 ` John Ogness
  2024-08-20 11:12   ` Ilpo Järvinen
  2024-08-20  6:29 ` [PATCH printk v8 14/35] serial: core: Acquire nbcon context in port->lock wrapper John Ogness
  2024-08-21  9:21 ` [PATCH printk v8 00/35] wire up write_atomic() printing Petr Mladek
  3 siblings, 1 reply; 9+ messages in thread
From: John Ogness @ 2024-08-20  6:29 UTC (permalink / raw)
  To: Petr Mladek
  Cc: Sergey Senozhatsky, Steven Rostedt, Thomas Gleixner, linux-kernel,
	Greg Kroah-Hartman, Jiri Slaby, Russell King, Tony Lindgren,
	Andy Shevchenko, Geert Uytterhoeven, Arnd Bergmann,
	Uwe Kleine-König, Théo Lebrun, Linus Walleij,
	Lino Sanfilippo, Ilpo Järvinen, Konrad Dybcio,
	Sebastian Andrzej Siewior, linux-serial

Introduce uart_port_set_cons() as a wrapper to set @cons of a
uart_port. The wrapper sets @cons under the port lock in order
to prevent @cons from disappearing while another context is
holding the port lock. This is necessary for a follow-up
commit relating to the port lock wrappers, which rely on @cons
not changing between lock and unlock.

Signed-off-by: John Ogness <john.ogness@linutronix.de>
Tested-by: Théo Lebrun <theo.lebrun@bootlin.com> # EyeQ5, AMBA-PL011
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Petr Mladek <pmladek@suse.com>
---
 drivers/tty/serial/8250/8250_core.c |  6 +++---
 drivers/tty/serial/amba-pl011.c     |  2 +-
 drivers/tty/serial/serial_core.c    | 16 ++++++++--------
 include/linux/serial_core.h         | 17 +++++++++++++++++
 4 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c
index 29e4b83e0376..5f9f06911795 100644
--- a/drivers/tty/serial/8250/8250_core.c
+++ b/drivers/tty/serial/8250/8250_core.c
@@ -423,11 +423,11 @@ static int univ8250_console_setup(struct console *co, char *options)
 
 	port = &serial8250_ports[co->index].port;
 	/* link port to console */
-	port->cons = co;
+	uart_port_set_cons(port, co);
 
 	retval = serial8250_console_setup(port, options, false);
 	if (retval != 0)
-		port->cons = NULL;
+		uart_port_set_cons(port, NULL);
 	return retval;
 }
 
@@ -485,7 +485,7 @@ static int univ8250_console_match(struct console *co, char *name, int idx,
 			continue;
 
 		co->index = i;
-		port->cons = co;
+		uart_port_set_cons(port, co);
 		return serial8250_console_setup(port, options, true);
 	}
 
diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c
index 8b1644f5411e..7d0134ecd82f 100644
--- a/drivers/tty/serial/amba-pl011.c
+++ b/drivers/tty/serial/amba-pl011.c
@@ -2480,7 +2480,7 @@ static int pl011_console_match(struct console *co, char *name, int idx,
 			continue;
 
 		co->index = i;
-		port->cons = co;
+		uart_port_set_cons(port, co);
 		return pl011_console_setup(co, options);
 	}
 
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 9a18d0b95a41..61c7e1268957 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -3168,8 +3168,15 @@ static int serial_core_add_one_port(struct uart_driver *drv, struct uart_port *u
 	state->uart_port = uport;
 	uport->state = state;
 
+	/*
+	 * If this port is in use as a console then the spinlock is already
+	 * initialised.
+	 */
+	if (!uart_console_registered(uport))
+		uart_port_spin_lock_init(uport);
+
 	state->pm_state = UART_PM_STATE_UNDEFINED;
-	uport->cons = drv->cons;
+	uart_port_set_cons(uport, drv->cons);
 	uport->minor = drv->tty_driver->minor_start + uport->line;
 	uport->name = kasprintf(GFP_KERNEL, "%s%d", drv->dev_name,
 				drv->tty_driver->name_base + uport->line);
@@ -3178,13 +3185,6 @@ static int serial_core_add_one_port(struct uart_driver *drv, struct uart_port *u
 		goto out;
 	}
 
-	/*
-	 * If this port is in use as a console then the spinlock is already
-	 * initialised.
-	 */
-	if (!uart_console_registered(uport))
-		uart_port_spin_lock_init(uport);
-
 	if (uport->cons && uport->dev)
 		of_console_check(uport->dev->of_node, uport->cons->name, uport->line);
 
diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
index 8872cd21e70a..2cf03ff2056a 100644
--- a/include/linux/serial_core.h
+++ b/include/linux/serial_core.h
@@ -608,6 +608,23 @@ static inline void __uart_port_unlock_irqrestore(struct uart_port *up, unsigned
 	spin_unlock_irqrestore(&up->lock, flags);
 }
 
+/**
+ * uart_port_set_cons - Safely set the @cons field for a uart
+ * @up:		The uart port to set
+ * @con:	The new console to set to
+ *
+ * This function must be used to set @up->cons. It uses the port lock to
+ * synchronize with the port lock wrappers in order to ensure that the console
+ * cannot change or disappear while another context is holding the port lock.
+ */
+static inline void uart_port_set_cons(struct uart_port *up, struct console *con)
+{
+	unsigned long flags;
+
+	__uart_port_lock_irqsave(up, &flags);
+	up->cons = con;
+	__uart_port_unlock_irqrestore(up, flags);
+}
 /**
  * uart_port_lock - Lock the UART port
  * @up:		Pointer to UART port structure
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH printk v8 14/35] serial: core: Acquire nbcon context in port->lock wrapper
  2024-08-20  6:29 [PATCH printk v8 00/35] wire up write_atomic() printing John Ogness
  2024-08-20  6:29 ` [PATCH printk v8 10/35] serial: core: Provide low-level functions to lock port John Ogness
  2024-08-20  6:29 ` [PATCH printk v8 11/35] serial: core: Introduce wrapper to set @uart_port->cons John Ogness
@ 2024-08-20  6:29 ` John Ogness
  2024-08-21  9:21 ` [PATCH printk v8 00/35] wire up write_atomic() printing Petr Mladek
  3 siblings, 0 replies; 9+ messages in thread
From: John Ogness @ 2024-08-20  6:29 UTC (permalink / raw)
  To: Petr Mladek
  Cc: Sergey Senozhatsky, Steven Rostedt, Thomas Gleixner, linux-kernel,
	Greg Kroah-Hartman, Jiri Slaby, linux-serial

Currently the port->lock wrappers uart_port_lock(),
uart_port_unlock() (and their variants) only lock/unlock
the spin_lock.

If the port is an nbcon console that has implemented the
write_atomic() callback, the wrappers must also acquire/release
the console context and mark the region as unsafe. This allows
general port->lock synchronization to be synchronized against
the nbcon write_atomic() callback.

Note that __uart_port_using_nbcon() relies on the port->lock
being held while a console is added and removed from the
console list (i.e. all uart nbcon drivers *must* take the
port->lock in their device_lock() callbacks).

Signed-off-by: John Ogness <john.ogness@linutronix.de>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Petr Mladek <pmladek@suse.com>
---
 include/linux/serial_core.h | 82 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 80 insertions(+), 2 deletions(-)

diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
index 2cf03ff2056a..4ab65874a850 100644
--- a/include/linux/serial_core.h
+++ b/include/linux/serial_core.h
@@ -11,6 +11,8 @@
 #include <linux/compiler.h>
 #include <linux/console.h>
 #include <linux/interrupt.h>
+#include <linux/lockdep.h>
+#include <linux/printk.h>
 #include <linux/spinlock.h>
 #include <linux/sched.h>
 #include <linux/tty.h>
@@ -625,6 +627,60 @@ static inline void uart_port_set_cons(struct uart_port *up, struct console *con)
 	up->cons = con;
 	__uart_port_unlock_irqrestore(up, flags);
 }
+
+/* Only for internal port lock wrapper usage. */
+static inline bool __uart_port_using_nbcon(struct uart_port *up)
+{
+	lockdep_assert_held_once(&up->lock);
+
+	if (likely(!uart_console(up)))
+		return false;
+
+	/*
+	 * @up->cons is only modified under the port lock. Therefore it is
+	 * certain that it cannot disappear here.
+	 *
+	 * @up->cons->node is added/removed from the console list under the
+	 * port lock. Therefore it is certain that the registration status
+	 * cannot change here, thus @up->cons->flags can be read directly.
+	 */
+	if (hlist_unhashed_lockless(&up->cons->node) ||
+	    !(up->cons->flags & CON_NBCON) ||
+	    !up->cons->write_atomic) {
+		return false;
+	}
+
+	return true;
+}
+
+/* Only for internal port lock wrapper usage. */
+static inline bool __uart_port_nbcon_try_acquire(struct uart_port *up)
+{
+	if (!__uart_port_using_nbcon(up))
+		return true;
+
+	return nbcon_device_try_acquire(up->cons);
+}
+
+/* Only for internal port lock wrapper usage. */
+static inline void __uart_port_nbcon_acquire(struct uart_port *up)
+{
+	if (!__uart_port_using_nbcon(up))
+		return;
+
+	while (!nbcon_device_try_acquire(up->cons))
+		cpu_relax();
+}
+
+/* Only for internal port lock wrapper usage. */
+static inline void __uart_port_nbcon_release(struct uart_port *up)
+{
+	if (!__uart_port_using_nbcon(up))
+		return;
+
+	nbcon_device_release(up->cons);
+}
+
 /**
  * uart_port_lock - Lock the UART port
  * @up:		Pointer to UART port structure
@@ -632,6 +688,7 @@ static inline void uart_port_set_cons(struct uart_port *up, struct console *con)
 static inline void uart_port_lock(struct uart_port *up)
 {
 	spin_lock(&up->lock);
+	__uart_port_nbcon_acquire(up);
 }
 
 /**
@@ -641,6 +698,7 @@ static inline void uart_port_lock(struct uart_port *up)
 static inline void uart_port_lock_irq(struct uart_port *up)
 {
 	spin_lock_irq(&up->lock);
+	__uart_port_nbcon_acquire(up);
 }
 
 /**
@@ -651,6 +709,7 @@ static inline void uart_port_lock_irq(struct uart_port *up)
 static inline void uart_port_lock_irqsave(struct uart_port *up, unsigned long *flags)
 {
 	spin_lock_irqsave(&up->lock, *flags);
+	__uart_port_nbcon_acquire(up);
 }
 
 /**
@@ -661,7 +720,15 @@ static inline void uart_port_lock_irqsave(struct uart_port *up, unsigned long *f
  */
 static inline bool uart_port_trylock(struct uart_port *up)
 {
-	return spin_trylock(&up->lock);
+	if (!spin_trylock(&up->lock))
+		return false;
+
+	if (!__uart_port_nbcon_try_acquire(up)) {
+		spin_unlock(&up->lock);
+		return false;
+	}
+
+	return true;
 }
 
 /**
@@ -673,7 +740,15 @@ static inline bool uart_port_trylock(struct uart_port *up)
  */
 static inline bool uart_port_trylock_irqsave(struct uart_port *up, unsigned long *flags)
 {
-	return spin_trylock_irqsave(&up->lock, *flags);
+	if (!spin_trylock_irqsave(&up->lock, *flags))
+		return false;
+
+	if (!__uart_port_nbcon_try_acquire(up)) {
+		spin_unlock_irqrestore(&up->lock, *flags);
+		return false;
+	}
+
+	return true;
 }
 
 /**
@@ -682,6 +757,7 @@ static inline bool uart_port_trylock_irqsave(struct uart_port *up, unsigned long
  */
 static inline void uart_port_unlock(struct uart_port *up)
 {
+	__uart_port_nbcon_release(up);
 	spin_unlock(&up->lock);
 }
 
@@ -691,6 +767,7 @@ static inline void uart_port_unlock(struct uart_port *up)
  */
 static inline void uart_port_unlock_irq(struct uart_port *up)
 {
+	__uart_port_nbcon_release(up);
 	spin_unlock_irq(&up->lock);
 }
 
@@ -701,6 +778,7 @@ static inline void uart_port_unlock_irq(struct uart_port *up)
  */
 static inline void uart_port_unlock_irqrestore(struct uart_port *up, unsigned long flags)
 {
+	__uart_port_nbcon_release(up);
 	spin_unlock_irqrestore(&up->lock, flags);
 }
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH printk v8 11/35] serial: core: Introduce wrapper to set @uart_port->cons
  2024-08-20  6:29 ` [PATCH printk v8 11/35] serial: core: Introduce wrapper to set @uart_port->cons John Ogness
@ 2024-08-20 11:12   ` Ilpo Järvinen
  0 siblings, 0 replies; 9+ messages in thread
From: Ilpo Järvinen @ 2024-08-20 11:12 UTC (permalink / raw)
  To: John Ogness
  Cc: Petr Mladek, Sergey Senozhatsky, Steven Rostedt, Thomas Gleixner,
	LKML, Greg Kroah-Hartman, Jiri Slaby, Russell King, Tony Lindgren,
	Andy Shevchenko, Geert Uytterhoeven, Arnd Bergmann,
	Uwe Kleine-König, Théo Lebrun, Linus Walleij,
	Lino Sanfilippo, Konrad Dybcio, Sebastian Andrzej Siewior,
	linux-serial

[-- Attachment #1: Type: text/plain, Size: 4812 bytes --]

On Tue, 20 Aug 2024, John Ogness wrote:

> Introduce uart_port_set_cons() as a wrapper to set @cons of a
> uart_port. The wrapper sets @cons under the port lock in order
> to prevent @cons from disappearing while another context is
> holding the port lock. This is necessary for a follow-up
> commit relating to the port lock wrappers, which rely on @cons
> not changing between lock and unlock.
> 
> Signed-off-by: John Ogness <john.ogness@linutronix.de>
> Tested-by: Théo Lebrun <theo.lebrun@bootlin.com> # EyeQ5, AMBA-PL011
> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Reviewed-by: Petr Mladek <pmladek@suse.com>

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

-- 
 i.

> ---
>  drivers/tty/serial/8250/8250_core.c |  6 +++---
>  drivers/tty/serial/amba-pl011.c     |  2 +-
>  drivers/tty/serial/serial_core.c    | 16 ++++++++--------
>  include/linux/serial_core.h         | 17 +++++++++++++++++
>  4 files changed, 29 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c
> index 29e4b83e0376..5f9f06911795 100644
> --- a/drivers/tty/serial/8250/8250_core.c
> +++ b/drivers/tty/serial/8250/8250_core.c
> @@ -423,11 +423,11 @@ static int univ8250_console_setup(struct console *co, char *options)
>  
>  	port = &serial8250_ports[co->index].port;
>  	/* link port to console */
> -	port->cons = co;
> +	uart_port_set_cons(port, co);
>  
>  	retval = serial8250_console_setup(port, options, false);
>  	if (retval != 0)
> -		port->cons = NULL;
> +		uart_port_set_cons(port, NULL);
>  	return retval;
>  }
>  
> @@ -485,7 +485,7 @@ static int univ8250_console_match(struct console *co, char *name, int idx,
>  			continue;
>  
>  		co->index = i;
> -		port->cons = co;
> +		uart_port_set_cons(port, co);
>  		return serial8250_console_setup(port, options, true);
>  	}
>  
> diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c
> index 8b1644f5411e..7d0134ecd82f 100644
> --- a/drivers/tty/serial/amba-pl011.c
> +++ b/drivers/tty/serial/amba-pl011.c
> @@ -2480,7 +2480,7 @@ static int pl011_console_match(struct console *co, char *name, int idx,
>  			continue;
>  
>  		co->index = i;
> -		port->cons = co;
> +		uart_port_set_cons(port, co);
>  		return pl011_console_setup(co, options);
>  	}
>  
> diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
> index 9a18d0b95a41..61c7e1268957 100644
> --- a/drivers/tty/serial/serial_core.c
> +++ b/drivers/tty/serial/serial_core.c
> @@ -3168,8 +3168,15 @@ static int serial_core_add_one_port(struct uart_driver *drv, struct uart_port *u
>  	state->uart_port = uport;
>  	uport->state = state;
>  
> +	/*
> +	 * If this port is in use as a console then the spinlock is already
> +	 * initialised.
> +	 */
> +	if (!uart_console_registered(uport))
> +		uart_port_spin_lock_init(uport);
> +
>  	state->pm_state = UART_PM_STATE_UNDEFINED;
> -	uport->cons = drv->cons;
> +	uart_port_set_cons(uport, drv->cons);
>  	uport->minor = drv->tty_driver->minor_start + uport->line;
>  	uport->name = kasprintf(GFP_KERNEL, "%s%d", drv->dev_name,
>  				drv->tty_driver->name_base + uport->line);
> @@ -3178,13 +3185,6 @@ static int serial_core_add_one_port(struct uart_driver *drv, struct uart_port *u
>  		goto out;
>  	}
>  
> -	/*
> -	 * If this port is in use as a console then the spinlock is already
> -	 * initialised.
> -	 */
> -	if (!uart_console_registered(uport))
> -		uart_port_spin_lock_init(uport);
> -
>  	if (uport->cons && uport->dev)
>  		of_console_check(uport->dev->of_node, uport->cons->name, uport->line);
>  
> diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
> index 8872cd21e70a..2cf03ff2056a 100644
> --- a/include/linux/serial_core.h
> +++ b/include/linux/serial_core.h
> @@ -608,6 +608,23 @@ static inline void __uart_port_unlock_irqrestore(struct uart_port *up, unsigned
>  	spin_unlock_irqrestore(&up->lock, flags);
>  }
>  
> +/**
> + * uart_port_set_cons - Safely set the @cons field for a uart
> + * @up:		The uart port to set
> + * @con:	The new console to set to
> + *
> + * This function must be used to set @up->cons. It uses the port lock to
> + * synchronize with the port lock wrappers in order to ensure that the console
> + * cannot change or disappear while another context is holding the port lock.
> + */
> +static inline void uart_port_set_cons(struct uart_port *up, struct console *con)
> +{
> +	unsigned long flags;
> +
> +	__uart_port_lock_irqsave(up, &flags);
> +	up->cons = con;
> +	__uart_port_unlock_irqrestore(up, flags);
> +}
>  /**
>   * uart_port_lock - Lock the UART port
>   * @up:		Pointer to UART port structure
> 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH printk v8 00/35] wire up write_atomic() printing
  2024-08-20  6:29 [PATCH printk v8 00/35] wire up write_atomic() printing John Ogness
                   ` (2 preceding siblings ...)
  2024-08-20  6:29 ` [PATCH printk v8 14/35] serial: core: Acquire nbcon context in port->lock wrapper John Ogness
@ 2024-08-21  9:21 ` Petr Mladek
  2024-08-21  9:28   ` Sebastian Andrzej Siewior
  3 siblings, 1 reply; 9+ messages in thread
From: Petr Mladek @ 2024-08-21  9:21 UTC (permalink / raw)
  To: John Ogness
  Cc: Sergey Senozhatsky, Steven Rostedt, Thomas Gleixner, linux-kernel,
	Miguel Ojeda, Paul E. McKenney, Greg Kroah-Hartman, Jiri Slaby,
	linux-serial, Russell King, Tony Lindgren, Andy Shevchenko,
	Geert Uytterhoeven, Arnd Bergmann, Uwe Kleine-König,
	Théo Lebrun, Linus Walleij, Lino Sanfilippo,
	Ilpo Järvinen, Konrad Dybcio, Sebastian Andrzej Siewior,
	Andrew Morton, Jani Nikula, Ryo Takakura, Uros Bizjak,
	Joel Granados, Lukas Wunner, Feng Tang, Baoquan He,
	Frederic Weisbecker, Neeraj Upadhyay, Joel Fernandes,
	Josh Triplett, Boqun Feng, Uladzislau Rezki, Mathieu Desnoyers,
	Lai Jiangshan, Zqiang, rcu, Peter Zijlstra, Ingo Molnar,
	Will Deacon, Waiman Long

On Tue 2024-08-20 08:35:26, John Ogness wrote:
> Hi,
> 
> This is v8 of a series to wire up the nbcon consoles so that
> they actually perform printing using their write_atomic()
> callback. v7 is here [0]. For information about the motivation
> of the atomic consoles, please read the cover letter of v1 [1].
> 
> The main focus of this series:
> 
> - For nbcon consoles, always call write_atomic() directly from
>   printk() caller context for the panic CPU.
> 
> - For nbcon consoles, call write_atomic() when unlocking the
>   console lock.
> 
> - Only perform the console lock/unlock dance if legacy or boot
>   consoles are registered.
> 
> - For legacy consoles, if nbcon consoles are registered, do not
>   attempt to print from printk() caller context for the panic
>   CPU until nbcon consoles have had a chance to print the most
>   significant messages.
> 
> - Mark emergency sections. In these sections, every printk()
>   call will attempt to directly flush to the consoles using the
>   EMERGENCY priority.
> 
> This series does _not_ include threaded printing or nbcon
> drivers. Those features will be added in separate follow-up
> series.

The series seems to be ready for linux-next from my POV.

I am going to push it there once I get approval from John about
the proposed update of the commit message for the 30th patch,
see https://lore.kernel.org/r/ZsWvRETyuh1Yq80j@pathway.suse.cz

Best Regards,
Petr

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH printk v8 00/35] wire up write_atomic() printing
  2024-08-21  9:21 ` [PATCH printk v8 00/35] wire up write_atomic() printing Petr Mladek
@ 2024-08-21  9:28   ` Sebastian Andrzej Siewior
  2024-08-21 14:09     ` Petr Mladek
  0 siblings, 1 reply; 9+ messages in thread
From: Sebastian Andrzej Siewior @ 2024-08-21  9:28 UTC (permalink / raw)
  To: Petr Mladek
  Cc: John Ogness, Sergey Senozhatsky, Steven Rostedt, Thomas Gleixner,
	linux-kernel, Miguel Ojeda, Paul E. McKenney, Greg Kroah-Hartman,
	Jiri Slaby, linux-serial, Russell King, Tony Lindgren,
	Andy Shevchenko, Geert Uytterhoeven, Arnd Bergmann,
	Uwe Kleine-König, Théo Lebrun, Linus Walleij,
	Lino Sanfilippo, Ilpo Järvinen, Konrad Dybcio, Andrew Morton,
	Jani Nikula, Ryo Takakura, Uros Bizjak, Joel Granados,
	Lukas Wunner, Feng Tang, Baoquan He, Frederic Weisbecker,
	Neeraj Upadhyay, Joel Fernandes, Josh Triplett, Boqun Feng,
	Uladzislau Rezki, Mathieu Desnoyers, Lai Jiangshan, Zqiang, rcu,
	Peter Zijlstra, Ingo Molnar, Will Deacon, Waiman Long

On 2024-08-21 11:21:41 [+0200], Petr Mladek wrote:
> The series seems to be ready for linux-next from my POV.
> 
> I am going to push it there once I get approval from John about
> the proposed update of the commit message for the 30th patch,
> see https://lore.kernel.org/r/ZsWvRETyuh1Yq80j@pathway.suse.cz

If it is just the commit message, couldn't you push it now to next now
and then simply rebase it with an updated commit message?

> Best Regards,
> Petr

Sebastian

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH printk v8 00/35] wire up write_atomic() printing
  2024-08-21  9:28   ` Sebastian Andrzej Siewior
@ 2024-08-21 14:09     ` Petr Mladek
  2024-08-21 14:20       ` Sebastian Andrzej Siewior
  0 siblings, 1 reply; 9+ messages in thread
From: Petr Mladek @ 2024-08-21 14:09 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior
  Cc: John Ogness, Sergey Senozhatsky, Steven Rostedt, Thomas Gleixner,
	linux-kernel, Miguel Ojeda, Paul E. McKenney, Greg Kroah-Hartman,
	Jiri Slaby, linux-serial, Russell King, Tony Lindgren,
	Andy Shevchenko, Geert Uytterhoeven, Arnd Bergmann,
	Uwe Kleine-König, Théo Lebrun, Linus Walleij,
	Lino Sanfilippo, Ilpo Järvinen, Konrad Dybcio, Andrew Morton,
	Jani Nikula, Ryo Takakura, Uros Bizjak, Joel Granados,
	Lukas Wunner, Feng Tang, Baoquan He, Frederic Weisbecker,
	Neeraj Upadhyay, Joel Fernandes, Josh Triplett, Boqun Feng,
	Uladzislau Rezki, Mathieu Desnoyers, Lai Jiangshan, Zqiang, rcu,
	Peter Zijlstra, Ingo Molnar, Will Deacon, Waiman Long

On Wed 2024-08-21 11:28:41, Sebastian Andrzej Siewior wrote:
> On 2024-08-21 11:21:41 [+0200], Petr Mladek wrote:
> > The series seems to be ready for linux-next from my POV.
> > 
> > I am going to push it there once I get approval from John about
> > the proposed update of the commit message for the 30th patch,
> > see https://lore.kernel.org/r/ZsWvRETyuh1Yq80j@pathway.suse.cz
> 
> If it is just the commit message, couldn't you push it now to next now
> and then simply rebase it with an updated commit message?

I see. It seems that John has vacation and can't respond quickly.

OK, I have pushed the patchset into printk/linux.git,
branch rework/write_atomic. It should appear in
the next rebase of linux-next.

Best Regards,
Petr

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH printk v8 00/35] wire up write_atomic() printing
  2024-08-21 14:09     ` Petr Mladek
@ 2024-08-21 14:20       ` Sebastian Andrzej Siewior
  0 siblings, 0 replies; 9+ messages in thread
From: Sebastian Andrzej Siewior @ 2024-08-21 14:20 UTC (permalink / raw)
  To: Petr Mladek
  Cc: John Ogness, Sergey Senozhatsky, Steven Rostedt, Thomas Gleixner,
	linux-kernel, Miguel Ojeda, Paul E. McKenney, Greg Kroah-Hartman,
	Jiri Slaby, linux-serial, Russell King, Tony Lindgren,
	Andy Shevchenko, Geert Uytterhoeven, Arnd Bergmann,
	Uwe Kleine-König, Théo Lebrun, Linus Walleij,
	Lino Sanfilippo, Ilpo Järvinen, Konrad Dybcio, Andrew Morton,
	Jani Nikula, Ryo Takakura, Uros Bizjak, Joel Granados,
	Lukas Wunner, Feng Tang, Baoquan He, Frederic Weisbecker,
	Neeraj Upadhyay, Joel Fernandes, Josh Triplett, Boqun Feng,
	Uladzislau Rezki, Mathieu Desnoyers, Lai Jiangshan, Zqiang, rcu,
	Peter Zijlstra, Ingo Molnar, Will Deacon, Waiman Long

On 2024-08-21 16:09:59 [+0200], Petr Mladek wrote:
> I see. It seems that John has vacation and can't respond quickly.
> 
> OK, I have pushed the patchset into printk/linux.git,
> branch rework/write_atomic. It should appear in
> the next rebase of linux-next.

Thank you.

> Best Regards,
> Petr

Sebastian

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-08-21 14:20 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-20  6:29 [PATCH printk v8 00/35] wire up write_atomic() printing John Ogness
2024-08-20  6:29 ` [PATCH printk v8 10/35] serial: core: Provide low-level functions to lock port John Ogness
2024-08-20  6:29 ` [PATCH printk v8 11/35] serial: core: Introduce wrapper to set @uart_port->cons John Ogness
2024-08-20 11:12   ` Ilpo Järvinen
2024-08-20  6:29 ` [PATCH printk v8 14/35] serial: core: Acquire nbcon context in port->lock wrapper John Ogness
2024-08-21  9:21 ` [PATCH printk v8 00/35] wire up write_atomic() printing Petr Mladek
2024-08-21  9:28   ` Sebastian Andrzej Siewior
2024-08-21 14:09     ` Petr Mladek
2024-08-21 14:20       ` Sebastian Andrzej Siewior

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).