linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH printk v5 00/30] wire up write_atomic() printing
@ 2024-05-02 21:38 John Ogness
  2024-05-02 21:38 ` [PATCH printk v5 08/30] serial: core: Provide low-level functions to lock port John Ogness
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: John Ogness @ 2024-05-02 21:38 UTC (permalink / raw)
  To: Petr Mladek
  Cc: Sergey Senozhatsky, Steven Rostedt, Thomas Gleixner,
	linux-kernel, Paul E. McKenney, Miguel Ojeda, Greg Kroah-Hartman,
	Jiri Slaby, linux-serial, Russell King, Tony Lindgren,
	Andy Shevchenko, Ilpo Järvinen, Uwe Kleine-König,
	Théo Lebrun, Linus Walleij, Hongyu Xie, Christophe JAILLET,
	Arnd Bergmann, Lino Sanfilippo, Andrew Morton, Lukas Wunner,
	Uros Bizjak, Kefeng Wang, Frederic Weisbecker, Neeraj Upadhyay,
	Joel Fernandes, Josh Triplett, Boqun Feng, Mathieu Desnoyers,
	Lai Jiangshan, Zqiang, rcu, Peter Zijlstra, Ingo Molnar,
	Will Deacon, Waiman Long

Hi,

This is v5 of a series to wire up the nbcon consoles so that
they actually perform printing using their write_atomic()
callback. v4 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 printk() calls
  will only store the messages. Upon exiting the emergency
  section, nbcon consoles are flushed directly and legacy
  console flushing is triggered via irq_work.

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

Note: With this series, a system with _only_ nbcon consoles
      registered will not perform console printing unless the
      console lock or nbcon port lock are used or on panic.
      This is on purpose. When nbcon kthreads are introduced,
      they will fill the gaps.

The changes since v4:

- In serial_core_add_one_port(), initialize the port lock
  before setting @cons (since uart_port_set_cons() uses the
  port lock).

- For unregister_console_locked(), take the con->device_lock
  when removing the console from the console list.

- Remove the struct nbcon_drvdata and instead rely on the port
  lock being taken when adding/removing uart nbcon console list
  items.

- Move the nbcon context for drivers into the struct console
  (formery in struct nbcon_drvdata).

- Simplify the port lock wrapper implementation since we can
  rely on the registration state not changing while the port
  lock is held.

- Change nbcon_driver_acquire() to nbcon_driver_try_acquire()
  in order to support try-semantics for the port lock wrappers.
  Also update its kerneldoc to clarify its usage.

- Implement true try-lock semantics for the try-variants of the
  port lock wrappers.

- Remove the retry-loop in __nbcon_atomic_flush_pending() since
  there is never a need to retry. If a context takes over
  ownership it also takes over responsibility to print the
  records.

- Invert the return value of nbcon_atomic_emit_one() and
  add kerneldoc and comments about the meaning of the return
  value.

- For nbcon_legacy_emit_next_record() use the same return
  value and kerneldoc explanation as nbcon_atomic_emit_one().

- Invert the meaning of the return value of
  __nbcon_atomic_flush_pending_con() and use various errno
  values to report the reason for failure.

- Add nbcon_atomic_flush_pending_con() to flush all records if
  records were added while flushing. (Once printer threads are
  available, we can rely on them to print the remaining
  records.)

- For nbcon_driver_release(), flush all records if records were
  added while holding the port lock. (Once printer threads are
  available, we can rely on them to print the remaining
  records.)

- Add nbcon_cpu_emergency_flush() to allow periodically
  flushing if there has been many records stored in emergency
  context. It also attempts legacy flushing when safe.

- Change lockdep_print_held_locks() and debug_show_all_locks()
  to rely on their callers marking emergency sections because
  these functions can be called in non-emergency situations.
  Note that debug_show_all_locks() still calls
  nbcon_cpu_emergency_flush() is case it used in emergency.

- Rename console_init_seq() to get_init_console_seq() and have
  it return the new seq rather than setting @newcon->seq.

- Change nbcon_init() to take the initial sequence number as
  an argument.

- For __pr_flush(), move the barrier() to ensure no
  intermediate use of the printing_via_unlock() macro.

- For nbcon_cpu_emergency_exit(), update the comments and
  WARN_ON_ONCE position as suggested.

- Move the printing_via_unlock() macro into internal.h so that
  it can be used by nbcon.c as well (in
  nbcon_cpu_emergency_flush()).

- Update the kerneldoc for nbcon callbacks write_atomic() and
  device_lock().

- Add clarification in console_srcu_read_flags() kerneldoc.

- Change kerneldoc nbcon_context_try_acquire() context to
  mention device_lock() or local_irq_save() requirement.

John Ogness

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

John Ogness (25):
  printk: Add notation to console_srcu locking
  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: Provide functions for drivers to acquire console for
    non-printing
  serial: core: Implement processing in port->lock wrapper
  printk: nbcon: Do not rely on proxy headers
  printk: nbcon: Fix kerneldoc for enums
  printk: Make console_is_usable() available to nbcon
  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: 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
  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             | 116 ++++++-
 include/linux/printk.h              |  33 +-
 include/linux/serial_core.h         | 117 ++++++-
 kernel/locking/lockdep.c            |  84 ++++-
 kernel/panic.c                      |   9 +
 kernel/printk/internal.h            |  71 +++-
 kernel/printk/nbcon.c               | 488 +++++++++++++++++++++++++++-
 kernel/printk/printk.c              | 303 +++++++++++++----
 kernel/printk/printk_ringbuffer.h   |   2 +
 kernel/printk/printk_safe.c         |  12 +
 kernel/rcu/tree_exp.h               |   9 +
 kernel/rcu/tree_stall.h             |  11 +
 15 files changed, 1148 insertions(+), 131 deletions(-)


base-commit: a2b4cab9da7746c42f87c13721d305baf0085a20
-- 
2.39.2


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

* [PATCH printk v5 08/30] serial: core: Provide low-level functions to lock port
  2024-05-02 21:38 [PATCH printk v5 00/30] wire up write_atomic() printing John Ogness
@ 2024-05-02 21:38 ` John Ogness
  2024-05-02 21:38 ` [PATCH printk v5 09/30] serial: core: Introduce wrapper to set @uart_port->cons John Ogness
  2024-05-02 21:38 ` [PATCH printk v5 12/30] serial: core: Implement processing in port->lock wrapper John Ogness
  2 siblings, 0 replies; 9+ messages in thread
From: John Ogness @ 2024-05-02 21:38 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 55b1f3ba48ac..bb3324d49453 100644
--- a/include/linux/serial_core.h
+++ b/include/linux/serial_core.h
@@ -588,6 +588,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 v5 09/30] serial: core: Introduce wrapper to set @uart_port->cons
  2024-05-02 21:38 [PATCH printk v5 00/30] wire up write_atomic() printing John Ogness
  2024-05-02 21:38 ` [PATCH printk v5 08/30] serial: core: Provide low-level functions to lock port John Ogness
@ 2024-05-02 21:38 ` John Ogness
  2024-05-03  8:09   ` Théo Lebrun
                     ` (2 more replies)
  2024-05-02 21:38 ` [PATCH printk v5 12/30] serial: core: Implement processing in port->lock wrapper John Ogness
  2 siblings, 3 replies; 9+ messages in thread
From: John Ogness @ 2024-05-02 21:38 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, Ilpo Järvinen,
	Uwe Kleine-König, Théo Lebrun, Linus Walleij,
	Hongyu Xie, Christophe JAILLET, Arnd Bergmann, Lino Sanfilippo,
	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>
---
 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 b62ad9006780..41d74ee3d95a 100644
--- a/drivers/tty/serial/8250/8250_core.c
+++ b/drivers/tty/serial/8250/8250_core.c
@@ -627,11 +627,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;
 }
 
@@ -689,7 +689,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 cf2c890a560f..347aacf8400f 100644
--- a/drivers/tty/serial/amba-pl011.c
+++ b/drivers/tty/serial/amba-pl011.c
@@ -2496,7 +2496,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 d6a58a9e072a..0c13ea6a3afa 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -3145,8 +3145,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);
@@ -3155,13 +3162,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 bb3324d49453..038693774f21 100644
--- a/include/linux/serial_core.h
+++ b/include/linux/serial_core.h
@@ -606,6 +606,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 v5 12/30] serial: core: Implement processing in port->lock wrapper
  2024-05-02 21:38 [PATCH printk v5 00/30] wire up write_atomic() printing John Ogness
  2024-05-02 21:38 ` [PATCH printk v5 08/30] serial: core: Provide low-level functions to lock port John Ogness
  2024-05-02 21:38 ` [PATCH printk v5 09/30] serial: core: Introduce wrapper to set @uart_port->cons John Ogness
@ 2024-05-02 21:38 ` John Ogness
  2024-05-04 16:08   ` Greg Kroah-Hartman
  2024-05-20 12:22   ` Petr Mladek
  2 siblings, 2 replies; 9+ messages in thread
From: John Ogness @ 2024-05-02 21:38 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, the wrappers must also
acquire/release the console and mark the region as unsafe. This
allows general port->lock synchronization to be synchronized
with the nbcon console ownership.

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>
---
 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 038693774f21..a2f307dce221 100644
--- a/include/linux/serial_core.h
+++ b/include/linux/serial_core.h
@@ -12,6 +12,8 @@
 #include <linux/console.h>
 #include <linux/interrupt.h>
 #include <linux/circ_buf.h>
+#include <linux/lockdep.h>
+#include <linux/printk.h>
 #include <linux/spinlock.h>
 #include <linux/sched.h>
 #include <linux/tty.h>
@@ -623,6 +625,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_driver_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_driver_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_driver_release(up->cons);
+}
+
 /**
  * uart_port_lock - Lock the UART port
  * @up:		Pointer to UART port structure
@@ -630,6 +686,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);
 }
 
 /**
@@ -639,6 +696,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);
 }
 
 /**
@@ -649,6 +707,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);
 }
 
 /**
@@ -659,7 +718,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;
 }
 
 /**
@@ -671,7 +738,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;
 }
 
 /**
@@ -680,6 +755,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);
 }
 
@@ -689,6 +765,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);
 }
 
@@ -699,6 +776,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 v5 09/30] serial: core: Introduce wrapper to set @uart_port->cons
  2024-05-02 21:38 ` [PATCH printk v5 09/30] serial: core: Introduce wrapper to set @uart_port->cons John Ogness
@ 2024-05-03  8:09   ` Théo Lebrun
  2024-05-04 16:08   ` Greg Kroah-Hartman
  2024-05-17 14:51   ` Petr Mladek
  2 siblings, 0 replies; 9+ messages in thread
From: Théo Lebrun @ 2024-05-03  8:09 UTC (permalink / raw)
  To: John Ogness, Petr Mladek
  Cc: Sergey Senozhatsky, Steven Rostedt, Thomas Gleixner,
	linux-kernel, Greg Kroah-Hartman, Jiri Slaby, Russell King,
	Tony Lindgren, Andy Shevchenko, Ilpo Järvinen,
	Uwe Kleine-König, Linus Walleij, Hongyu Xie,
	Christophe JAILLET, Arnd Bergmann, Lino Sanfilippo, linux-serial

Hello,

On Thu May 2, 2024 at 11:38 PM CEST, 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 series on Mobileye EyeQ5, a MIPS64 platform that uses PL011.

Tested-by: Théo Lebrun <theo.lebrun@bootlin.com> # EyeQ5, AMBA-PL011

Thanks,

--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com


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

* Re: [PATCH printk v5 12/30] serial: core: Implement processing in port->lock wrapper
  2024-05-02 21:38 ` [PATCH printk v5 12/30] serial: core: Implement processing in port->lock wrapper John Ogness
@ 2024-05-04 16:08   ` Greg Kroah-Hartman
  2024-05-20 12:22   ` Petr Mladek
  1 sibling, 0 replies; 9+ messages in thread
From: Greg Kroah-Hartman @ 2024-05-04 16:08 UTC (permalink / raw)
  To: John Ogness
  Cc: Petr Mladek, Sergey Senozhatsky, Steven Rostedt, Thomas Gleixner,
	linux-kernel, Jiri Slaby, linux-serial

On Thu, May 02, 2024 at 11:44:21PM +0206, John Ogness wrote:
> 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, the wrappers must also
> acquire/release the console and mark the region as unsafe. This
> allows general port->lock synchronization to be synchronized
> with the nbcon console ownership.
> 
> 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>
> ---
>  include/linux/serial_core.h | 82 ++++++++++++++++++++++++++++++++++++-
>  1 file changed, 80 insertions(+), 2 deletions(-)

Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

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

* Re: [PATCH printk v5 09/30] serial: core: Introduce wrapper to set @uart_port->cons
  2024-05-02 21:38 ` [PATCH printk v5 09/30] serial: core: Introduce wrapper to set @uart_port->cons John Ogness
  2024-05-03  8:09   ` Théo Lebrun
@ 2024-05-04 16:08   ` Greg Kroah-Hartman
  2024-05-17 14:51   ` Petr Mladek
  2 siblings, 0 replies; 9+ messages in thread
From: Greg Kroah-Hartman @ 2024-05-04 16:08 UTC (permalink / raw)
  To: John Ogness
  Cc: Petr Mladek, Sergey Senozhatsky, Steven Rostedt, Thomas Gleixner,
	linux-kernel, Jiri Slaby, Russell King, Tony Lindgren,
	Andy Shevchenko, Ilpo Järvinen, Uwe Kleine-König,
	Théo Lebrun, Linus Walleij, Hongyu Xie, Christophe JAILLET,
	Arnd Bergmann, Lino Sanfilippo, linux-serial

On Thu, May 02, 2024 at 11:44:18PM +0206, 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>

Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

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

* Re: [PATCH printk v5 09/30] serial: core: Introduce wrapper to set @uart_port->cons
  2024-05-02 21:38 ` [PATCH printk v5 09/30] serial: core: Introduce wrapper to set @uart_port->cons John Ogness
  2024-05-03  8:09   ` Théo Lebrun
  2024-05-04 16:08   ` Greg Kroah-Hartman
@ 2024-05-17 14:51   ` Petr Mladek
  2 siblings, 0 replies; 9+ messages in thread
From: Petr Mladek @ 2024-05-17 14:51 UTC (permalink / raw)
  To: John Ogness
  Cc: Sergey Senozhatsky, Steven Rostedt, Thomas Gleixner,
	linux-kernel, Greg Kroah-Hartman, Jiri Slaby, Russell King,
	Tony Lindgren, Andy Shevchenko, Ilpo Järvinen,
	Uwe Kleine-König, Théo Lebrun, Linus Walleij,
	Hongyu Xie, Christophe JAILLET, Arnd Bergmann, Lino Sanfilippo,
	linux-serial

On Thu 2024-05-02 23:44:18, 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>

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

Best Regards,
Petr

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

* Re: [PATCH printk v5 12/30] serial: core: Implement processing in port->lock wrapper
  2024-05-02 21:38 ` [PATCH printk v5 12/30] serial: core: Implement processing in port->lock wrapper John Ogness
  2024-05-04 16:08   ` Greg Kroah-Hartman
@ 2024-05-20 12:22   ` Petr Mladek
  1 sibling, 0 replies; 9+ messages in thread
From: Petr Mladek @ 2024-05-20 12:22 UTC (permalink / raw)
  To: John Ogness
  Cc: Sergey Senozhatsky, Steven Rostedt, Thomas Gleixner,
	linux-kernel, Greg Kroah-Hartman, Jiri Slaby, linux-serial

On Thu 2024-05-02 23:44:21, John Ogness wrote:
> 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, the wrappers must also
> acquire/release the console and mark the region as unsafe. This
> allows general port->lock synchronization to be synchronized
> with the nbcon console ownership.
> 
> 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>

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

Best Regards,
Petr

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

end of thread, other threads:[~2024-05-20 12:22 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-02 21:38 [PATCH printk v5 00/30] wire up write_atomic() printing John Ogness
2024-05-02 21:38 ` [PATCH printk v5 08/30] serial: core: Provide low-level functions to lock port John Ogness
2024-05-02 21:38 ` [PATCH printk v5 09/30] serial: core: Introduce wrapper to set @uart_port->cons John Ogness
2024-05-03  8:09   ` Théo Lebrun
2024-05-04 16:08   ` Greg Kroah-Hartman
2024-05-17 14:51   ` Petr Mladek
2024-05-02 21:38 ` [PATCH printk v5 12/30] serial: core: Implement processing in port->lock wrapper John Ogness
2024-05-04 16:08   ` Greg Kroah-Hartman
2024-05-20 12:22   ` Petr Mladek

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