linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH tty v1 00/74] serial: wrappers for uart port lock
@ 2023-09-14 18:37 John Ogness
  2023-09-14 18:38 ` [PATCH tty v1 47/74] serial: pmac_zilog: Use port lock wrappers John Ogness
                   ` (4 more replies)
  0 siblings, 5 replies; 12+ messages in thread
From: John Ogness @ 2023-09-14 18:37 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Geert Uytterhoeven, Alim Akhtar, Peter Korsgaard, linux-stm32,
	Karol Gugala, Jerome Brunet, linux-samsung-soc, Kevin Hilman,
	Hugo Villeneuve, Hammer Hsieh, Jiamei Xie, NXP Linux Team,
	Vineet Gupta, Thierry Reding, Petr Mladek, Arend van Spriel,
	Sascha Hauer, Nicholas Piggin, linux-unisoc, Thomas Gleixner,
	Andrew Jeffery, linux-kernel, Samuel Holland, Richard Genoud,
	Pengutronix Kernel Team, Andrew Morton

When a serial port is used for kernel console output, then all
modifications to the UART registers which are done from other contexts,
e.g. getty, termios, are interference points for the kernel console.

So far this has been ignored and the printk output is based on the
principle of hope. The rework of the console infrastructure which aims to
support threaded and atomic consoles, requires to mark sections which
modify the UART registers as unsafe. This allows the atomic write function
to make informed decisions and eventually to restore operational state. It
also allows to prevent the regular UART code from modifying UART registers
while printk output is in progress.

All modifications of UART registers are guarded by the UART port lock,
which provides an obvious synchronization point with the console
infrastructure.

Provide and use wrapper functions for spin_[un]lock*(port->lock)
invocations so that the console mechanics can be applied later on at a
single place and does not require to copy the same logic all over the
drivers.

Patch 1 adds the wrapper functions.

Patches 2-74 switch all uart port locking call sites to use the new
wrappers. These patches were automatically generated using coccinelle.
The 2 used coccinelle scripts are included below and executed as
follows:

$ spatch --sp-file uartlock-1.cocci $FILE
$ spatch --sp-file uartlock-2.cocci --recursive-includes $FILE

This series brings no functional change.

Patches 2-74 contain identical commit message bodies. Feel free to
fold them into a single commit if that seems more reasonable.

Thomas Gleixner (74):
  serial: core: Provide port lock wrappers
  serial: core: Use lock wrappers
  serial: 21285: Use port lock wrappers
  serial: 8250_aspeed_vuart: Use port lock wrappers
  serial: 8250_bcm7271: Use port lock wrappers
  serial: 8250: Use port lock wrappers
  serial: 8250_dma: Use port lock wrappers
  serial: 8250_dw: Use port lock wrappers
  serial: 8250_exar: Use port lock wrappers
  serial: 8250_fsl: Use port lock wrappers
  serial: 8250_mtk: Use port lock wrappers
  serial: 8250_omap: Use port lock wrappers
  serial: 8250_pci1xxxx: Use port lock wrappers
  serial: altera_jtaguart: Use port lock wrappers
  serial: altera_uart: Use port lock wrappers
  serial: amba-pl010: Use port lock wrappers
  serial: amba-pl011: Use port lock wrappers
  serial: apb: Use port lock wrappers
  serial: ar933x: Use port lock wrappers
  serial: arc_uart: Use port lock wrappers
  serial: atmel: Use port lock wrappers
  serial: bcm63xx-uart: Use port lock wrappers
  serial: cpm_uart: Use port lock wrappers
  serial: digicolor: Use port lock wrappers
  serial: dz: Use port lock wrappers
  serial: linflexuart: Use port lock wrappers
  serial: fsl_lpuart: Use port lock wrappers
  serial: icom: Use port lock wrappers
  serial: imx: Use port lock wrappers
  serial: ip22zilog: Use port lock wrappers
  serial: jsm: Use port lock wrappers
  serial: liteuart: Use port lock wrappers
  serial: lpc32xx_hs: Use port lock wrappers
  serial: ma35d1: Use port lock wrappers
  serial: mcf: Use port lock wrappers
  serial: men_z135_uart: Use port lock wrappers
  serial: meson: Use port lock wrappers
  serial: milbeaut_usio: Use port lock wrappers
  serial: mpc52xx: Use port lock wrappers
  serial: mps2-uart: Use port lock wrappers
  serial: msm: Use port lock wrappers
  serial: mvebu-uart: Use port lock wrappers
  serial: omap: Use port lock wrappers
  serial: owl: Use port lock wrappers
  serial: pch: Use port lock wrappers
  serial: pic32: Use port lock wrappers
  serial: pmac_zilog: Use port lock wrappers
  serial: pxa: Use port lock wrappers
  serial: qcom-geni: Use port lock wrappers
  serial: rda: Use port lock wrappers
  serial: rp2: Use port lock wrappers
  serial: sa1100: Use port lock wrappers
  serial: samsung_tty: Use port lock wrappers
  serial: sb1250-duart: Use port lock wrappers
  serial: sc16is7xx: Use port lock wrappers
  serial: tegra: Use port lock wrappers
  serial: core: Use port lock wrappers
  serial: mctrl_gpio: Use port lock wrappers
  serial: txx9: Use port lock wrappers
  serial: sh-sci: Use port lock wrappers
  serial: sifive: Use port lock wrappers
  serial: sprd: Use port lock wrappers
  serial: st-asc: Use port lock wrappers
  serial: stm32: Use port lock wrappers
  serial: sunhv: Use port lock wrappers
  serial: sunplus-uart: Use port lock wrappers
  serial: sunsab: Use port lock wrappers
  serial: sunsu: Use port lock wrappers
  serial: sunzilog: Use port lock wrappers
  serial: timbuart: Use port lock wrappers
  serial: uartlite: Use port lock wrappers
  serial: ucc_uart: Use port lock wrappers
  serial: vt8500: Use port lock wrappers
  serial: xilinx_uartps: Use port lock wrappers

 drivers/tty/serial/21285.c                  |   8 +-
 drivers/tty/serial/8250/8250_aspeed_vuart.c |   6 +-
 drivers/tty/serial/8250/8250_bcm7271.c      |  28 +++---
 drivers/tty/serial/8250/8250_core.c         |  12 +--
 drivers/tty/serial/8250/8250_dma.c          |   8 +-
 drivers/tty/serial/8250/8250_dw.c           |   8 +-
 drivers/tty/serial/8250/8250_exar.c         |   4 +-
 drivers/tty/serial/8250/8250_fsl.c          |   6 +-
 drivers/tty/serial/8250/8250_mtk.c          |   8 +-
 drivers/tty/serial/8250/8250_omap.c         |  52 +++++-----
 drivers/tty/serial/8250/8250_pci1xxxx.c     |   8 +-
 drivers/tty/serial/8250/8250_port.c         | 100 ++++++++++----------
 drivers/tty/serial/altera_jtaguart.c        |  28 +++---
 drivers/tty/serial/altera_uart.c            |  20 ++--
 drivers/tty/serial/amba-pl010.c             |  20 ++--
 drivers/tty/serial/amba-pl011.c             |  72 +++++++-------
 drivers/tty/serial/apbuart.c                |   8 +-
 drivers/tty/serial/ar933x_uart.c            |  26 ++---
 drivers/tty/serial/arc_uart.c               |  16 ++--
 drivers/tty/serial/atmel_serial.c           |  24 ++---
 drivers/tty/serial/bcm63xx_uart.c           |  22 ++---
 drivers/tty/serial/cpm_uart.c               |   8 +-
 drivers/tty/serial/digicolor-usart.c        |  18 ++--
 drivers/tty/serial/dz.c                     |  32 +++----
 drivers/tty/serial/fsl_linflexuart.c        |  26 ++---
 drivers/tty/serial/fsl_lpuart.c             |  88 ++++++++---------
 drivers/tty/serial/icom.c                   |  26 ++---
 drivers/tty/serial/imx.c                    |  84 ++++++++--------
 drivers/tty/serial/ip22zilog.c              |  36 +++----
 drivers/tty/serial/jsm/jsm_neo.c            |   4 +-
 drivers/tty/serial/jsm/jsm_tty.c            |  16 ++--
 drivers/tty/serial/liteuart.c               |  20 ++--
 drivers/tty/serial/lpc32xx_hs.c             |  26 ++---
 drivers/tty/serial/ma35d1_serial.c          |  22 ++---
 drivers/tty/serial/mcf.c                    |  20 ++--
 drivers/tty/serial/men_z135_uart.c          |   8 +-
 drivers/tty/serial/meson_uart.c             |  30 +++---
 drivers/tty/serial/milbeaut_usio.c          |  16 ++--
 drivers/tty/serial/mpc52xx_uart.c           |  12 +--
 drivers/tty/serial/mps2-uart.c              |  16 ++--
 drivers/tty/serial/msm_serial.c             |  38 ++++----
 drivers/tty/serial/mvebu-uart.c             |  18 ++--
 drivers/tty/serial/omap-serial.c            |  38 ++++----
 drivers/tty/serial/owl-uart.c               |  26 ++---
 drivers/tty/serial/pch_uart.c               |  10 +-
 drivers/tty/serial/pic32_uart.c             |  20 ++--
 drivers/tty/serial/pmac_zilog.c             |  52 +++++-----
 drivers/tty/serial/pxa.c                    |  30 +++---
 drivers/tty/serial/qcom_geni_serial.c       |   8 +-
 drivers/tty/serial/rda-uart.c               |  34 +++----
 drivers/tty/serial/rp2.c                    |  20 ++--
 drivers/tty/serial/sa1100.c                 |  20 ++--
 drivers/tty/serial/samsung_tty.c            |  50 +++++-----
 drivers/tty/serial/sb1250-duart.c           |  12 +--
 drivers/tty/serial/sc16is7xx.c              |  40 ++++----
 drivers/tty/serial/serial-tegra.c           |  32 +++----
 drivers/tty/serial/serial_core.c            |  88 ++++++++---------
 drivers/tty/serial/serial_mctrl_gpio.c      |   4 +-
 drivers/tty/serial/serial_port.c            |   4 +-
 drivers/tty/serial/serial_txx9.c            |  26 ++---
 drivers/tty/serial/sh-sci.c                 |  68 ++++++-------
 drivers/tty/serial/sifive.c                 |  16 ++--
 drivers/tty/serial/sprd_serial.c            |  30 +++---
 drivers/tty/serial/st-asc.c                 |  18 ++--
 drivers/tty/serial/stm32-usart.c            |  38 ++++----
 drivers/tty/serial/sunhv.c                  |  28 +++---
 drivers/tty/serial/sunplus-uart.c           |  26 ++---
 drivers/tty/serial/sunsab.c                 |  34 +++----
 drivers/tty/serial/sunsu.c                  |  46 ++++-----
 drivers/tty/serial/sunzilog.c               |  42 ++++----
 drivers/tty/serial/timbuart.c               |   8 +-
 drivers/tty/serial/uartlite.c               |  18 ++--
 drivers/tty/serial/ucc_uart.c               |   4 +-
 drivers/tty/serial/vt8500_serial.c          |   8 +-
 drivers/tty/serial/xilinx_uartps.c          |  56 +++++------
 include/linux/serial_core.h                 |  91 ++++++++++++++++--
 76 files changed, 1086 insertions(+), 1007 deletions(-)


base-commit: 0bb80ecc33a8fb5a682236443c1e740d5c917d1d
-- 
2.39.2

--------------8<--------------
// uartlock-1.cocci

@r1@
struct uart_port *U;
@@

-spin_lock(&U->lock)
+uart_port_lock(U)

@r2@
struct uart_port *U;
@@

-spin_lock_irq(&U->lock)
+uart_port_lock_irq(U)

@r3@
struct uart_port *U;
identifier F;
@@

-spin_lock_irqsave(&U->lock, F)
+uart_port_lock_irqsave(U, &F)

@r4@
struct uart_port *U;
@@

-spin_unlock(&U->lock)
+uart_port_unlock(U)

@r5@
struct uart_port *U;
@@

-spin_unlock_irq(&U->lock)
+uart_port_unlock_irq(U)

@r6@
struct uart_port *U;
identifier F;
@@

-spin_unlock_irqrestore(&U->lock, F)
+uart_port_unlock_irqrestore(U, F)

@r7@
struct uart_port *U;
@@

-spin_trylock(&U->lock)
+uart_port_trylock(U)

@r8@
struct uart_port *U;
identifier F;
@@

-spin_trylock_irqsave(&U->lock, F)
+uart_port_trylock_irqsave(U, &F)

--------------8<--------------
// uartlock-2.cocci

@r10@
type T1;
identifier U;
@@

T1 {
   ...
   struct uart_port U;
   ...
};

@r11@
r10.T1 *E;
identifier r10.U;
@@

-spin_lock(&E->U.lock)
+uart_port_lock(&E->U)

@r12@
r10.T1 *E;
identifier r10.U;
@@

-spin_lock_irq(&E->U.lock)
+uart_port_lock_irq(&E->U)

@r13@
r10.T1 *E;
identifier r10.U;
identifier F;
@@

-spin_lock_irqsave(&E->U.lock, F)
+uart_port_lock_irqsave(&E->U, &F)

@r14@
r10.T1 *E;
identifier r10.U;
@@

-spin_unlock(&E->U.lock)
+uart_port_unlock(&E->U)

@r15@
r10.T1 *E;
identifier r10.U;
@@

-spin_unlock_irq(&E->U.lock)
+uart_port_unlock_irq(&E->U)

@r16@
r10.T1 *E;
identifier r10.U;
identifier F;
@@

-spin_unlock_irqrestore(&E->U.lock, F)
+uart_port_unlock_irqrestore(&E->U, F)

@r17@
r10.T1 *E;
identifier r10.U;
@@

-spin_trylock(&E->U.lock)
+uart_port_trylock(&E->U)

@r18@
r10.T1 *E;
identifier r10.U;
identifier F;
@@

-spin_trylock_irqsave(&E->U.lock, F)
+uart_port_trylock_irqsave(&E->U, &F)


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

* [PATCH tty v1 47/74] serial: pmac_zilog: Use port lock wrappers
  2023-09-14 18:37 [PATCH tty v1 00/74] serial: wrappers for uart port lock John Ogness
@ 2023-09-14 18:38 ` John Ogness
  2023-09-14 18:38 ` [PATCH tty v1 72/74] serial: ucc_uart: " John Ogness
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 12+ messages in thread
From: John Ogness @ 2023-09-14 18:38 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Petr Mladek, linuxppc-dev, linux-kernel, Nicholas Piggin,
	linux-serial, Ilpo Järvinen, Thomas Gleixner, Jiri Slaby

From: Thomas Gleixner <tglx@linutronix.de>

When a serial port is used for kernel console output, then all
modifications to the UART registers which are done from other contexts,
e.g. getty, termios, are interference points for the kernel console.

So far this has been ignored and the printk output is based on the
principle of hope. The rework of the console infrastructure which aims to
support threaded and atomic consoles, requires to mark sections which
modify the UART registers as unsafe. This allows the atomic write function
to make informed decisions and eventually to restore operational state. It
also allows to prevent the regular UART code from modifying UART registers
while printk output is in progress.

All modifications of UART registers are guarded by the UART port lock,
which provides an obvious synchronization point with the console
infrastructure.

To avoid adding this functionality to all UART drivers, wrap the
spin_[un]lock*() invocations for uart_port::lock into helper functions
which just contain the spin_[un]lock*() invocations for now. In a
subsequent step these helpers will gain the console synchronization
mechanisms.

Converted with coccinelle. No functional change.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 drivers/tty/serial/pmac_zilog.c | 52 ++++++++++++++++-----------------
 1 file changed, 26 insertions(+), 26 deletions(-)

diff --git a/drivers/tty/serial/pmac_zilog.c b/drivers/tty/serial/pmac_zilog.c
index 13668ffdb1e7..c8bf08c19c64 100644
--- a/drivers/tty/serial/pmac_zilog.c
+++ b/drivers/tty/serial/pmac_zilog.c
@@ -246,9 +246,9 @@ static bool pmz_receive_chars(struct uart_pmac_port *uap)
 #endif /* USE_CTRL_O_SYSRQ */
 		if (uap->port.sysrq) {
 			int swallow;
-			spin_unlock(&uap->port.lock);
+			uart_port_unlock(&uap->port);
 			swallow = uart_handle_sysrq_char(&uap->port, ch);
-			spin_lock(&uap->port.lock);
+			uart_port_lock(&uap->port);
 			if (swallow)
 				goto next_char;
 		}
@@ -435,7 +435,7 @@ static irqreturn_t pmz_interrupt(int irq, void *dev_id)
 	uap_a = pmz_get_port_A(uap);
 	uap_b = uap_a->mate;
 
-	spin_lock(&uap_a->port.lock);
+	uart_port_lock(&uap_a->port);
 	r3 = read_zsreg(uap_a, R3);
 
 	/* Channel A */
@@ -456,14 +456,14 @@ static irqreturn_t pmz_interrupt(int irq, void *dev_id)
 		rc = IRQ_HANDLED;
 	}
  skip_a:
-	spin_unlock(&uap_a->port.lock);
+	uart_port_unlock(&uap_a->port);
 	if (push)
 		tty_flip_buffer_push(&uap->port.state->port);
 
 	if (!uap_b)
 		goto out;
 
-	spin_lock(&uap_b->port.lock);
+	uart_port_lock(&uap_b->port);
 	push = false;
 	if (r3 & (CHBEXT | CHBTxIP | CHBRxIP)) {
 		if (!ZS_IS_OPEN(uap_b)) {
@@ -481,7 +481,7 @@ static irqreturn_t pmz_interrupt(int irq, void *dev_id)
 		rc = IRQ_HANDLED;
 	}
  skip_b:
-	spin_unlock(&uap_b->port.lock);
+	uart_port_unlock(&uap_b->port);
 	if (push)
 		tty_flip_buffer_push(&uap->port.state->port);
 
@@ -497,9 +497,9 @@ static inline u8 pmz_peek_status(struct uart_pmac_port *uap)
 	unsigned long flags;
 	u8 status;
 	
-	spin_lock_irqsave(&uap->port.lock, flags);
+	uart_port_lock_irqsave(&uap->port, &flags);
 	status = read_zsreg(uap, R0);
-	spin_unlock_irqrestore(&uap->port.lock, flags);
+	uart_port_unlock_irqrestore(&uap->port, flags);
 
 	return status;
 }
@@ -685,7 +685,7 @@ static void pmz_break_ctl(struct uart_port *port, int break_state)
 	else
 		clear_bits |= SND_BRK;
 
-	spin_lock_irqsave(&port->lock, flags);
+	uart_port_lock_irqsave(port, &flags);
 
 	new_reg = (uap->curregs[R5] | set_bits) & ~clear_bits;
 	if (new_reg != uap->curregs[R5]) {
@@ -693,7 +693,7 @@ static void pmz_break_ctl(struct uart_port *port, int break_state)
 		write_zsreg(uap, R5, uap->curregs[R5]);
 	}
 
-	spin_unlock_irqrestore(&port->lock, flags);
+	uart_port_unlock_irqrestore(port, flags);
 }
 
 #ifdef CONFIG_PPC_PMAC
@@ -865,18 +865,18 @@ static void pmz_irda_reset(struct uart_pmac_port *uap)
 {
 	unsigned long flags;
 
-	spin_lock_irqsave(&uap->port.lock, flags);
+	uart_port_lock_irqsave(&uap->port, &flags);
 	uap->curregs[R5] |= DTR;
 	write_zsreg(uap, R5, uap->curregs[R5]);
 	zssync(uap);
-	spin_unlock_irqrestore(&uap->port.lock, flags);
+	uart_port_unlock_irqrestore(&uap->port, flags);
 	msleep(110);
 
-	spin_lock_irqsave(&uap->port.lock, flags);
+	uart_port_lock_irqsave(&uap->port, &flags);
 	uap->curregs[R5] &= ~DTR;
 	write_zsreg(uap, R5, uap->curregs[R5]);
 	zssync(uap);
-	spin_unlock_irqrestore(&uap->port.lock, flags);
+	uart_port_unlock_irqrestore(&uap->port, flags);
 	msleep(10);
 }
 
@@ -896,9 +896,9 @@ static int pmz_startup(struct uart_port *port)
 	 * initialize the chip
 	 */
 	if (!ZS_IS_CONS(uap)) {
-		spin_lock_irqsave(&port->lock, flags);
+		uart_port_lock_irqsave(port, &flags);
 		pwr_delay = __pmz_startup(uap);
-		spin_unlock_irqrestore(&port->lock, flags);
+		uart_port_unlock_irqrestore(port, flags);
 	}	
 	sprintf(uap->irq_name, PMACZILOG_NAME"%d", uap->port.line);
 	if (request_irq(uap->port.irq, pmz_interrupt, IRQF_SHARED,
@@ -921,9 +921,9 @@ static int pmz_startup(struct uart_port *port)
 		pmz_irda_reset(uap);
 
 	/* Enable interrupt requests for the channel */
-	spin_lock_irqsave(&port->lock, flags);
+	uart_port_lock_irqsave(port, &flags);
 	pmz_interrupt_control(uap, 1);
-	spin_unlock_irqrestore(&port->lock, flags);
+	uart_port_unlock_irqrestore(port, flags);
 
 	return 0;
 }
@@ -933,7 +933,7 @@ static void pmz_shutdown(struct uart_port *port)
 	struct uart_pmac_port *uap = to_pmz(port);
 	unsigned long flags;
 
-	spin_lock_irqsave(&port->lock, flags);
+	uart_port_lock_irqsave(port, &flags);
 
 	/* Disable interrupt requests for the channel */
 	pmz_interrupt_control(uap, 0);
@@ -948,19 +948,19 @@ static void pmz_shutdown(struct uart_port *port)
 		pmz_maybe_update_regs(uap);
 	}
 
-	spin_unlock_irqrestore(&port->lock, flags);
+	uart_port_unlock_irqrestore(port, flags);
 
 	/* Release interrupt handler */
 	free_irq(uap->port.irq, uap);
 
-	spin_lock_irqsave(&port->lock, flags);
+	uart_port_lock_irqsave(port, &flags);
 
 	uap->flags &= ~PMACZILOG_FLAG_IS_OPEN;
 
 	if (!ZS_IS_CONS(uap))
 		pmz_set_scc_power(uap, 0);	/* Shut the chip down */
 
-	spin_unlock_irqrestore(&port->lock, flags);
+	uart_port_unlock_irqrestore(port, flags);
 }
 
 /* Shared by TTY driver and serial console setup.  The port lock is held
@@ -1247,7 +1247,7 @@ static void pmz_set_termios(struct uart_port *port, struct ktermios *termios,
 	struct uart_pmac_port *uap = to_pmz(port);
 	unsigned long flags;
 
-	spin_lock_irqsave(&port->lock, flags);	
+	uart_port_lock_irqsave(port, &flags);	
 
 	/* Disable IRQs on the port */
 	pmz_interrupt_control(uap, 0);
@@ -1259,7 +1259,7 @@ static void pmz_set_termios(struct uart_port *port, struct ktermios *termios,
 	if (ZS_IS_OPEN(uap))
 		pmz_interrupt_control(uap, 1);
 
-	spin_unlock_irqrestore(&port->lock, flags);
+	uart_port_unlock_irqrestore(port, flags);
 }
 
 static const char *pmz_type(struct uart_port *port)
@@ -1896,7 +1896,7 @@ static void pmz_console_write(struct console *con, const char *s, unsigned int c
 	struct uart_pmac_port *uap = &pmz_ports[con->index];
 	unsigned long flags;
 
-	spin_lock_irqsave(&uap->port.lock, flags);
+	uart_port_lock_irqsave(&uap->port, &flags);
 
 	/* Turn of interrupts and enable the transmitter. */
 	write_zsreg(uap, R1, uap->curregs[1] & ~TxINT_ENAB);
@@ -1908,7 +1908,7 @@ static void pmz_console_write(struct console *con, const char *s, unsigned int c
 	write_zsreg(uap, R1, uap->curregs[1]);
 	/* Don't disable the transmitter. */
 
-	spin_unlock_irqrestore(&uap->port.lock, flags);
+	uart_port_unlock_irqrestore(&uap->port, flags);
 }
 
 /*
-- 
2.39.2


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

* [PATCH tty v1 72/74] serial: ucc_uart: Use port lock wrappers
  2023-09-14 18:37 [PATCH tty v1 00/74] serial: wrappers for uart port lock John Ogness
  2023-09-14 18:38 ` [PATCH tty v1 47/74] serial: pmac_zilog: Use port lock wrappers John Ogness
@ 2023-09-14 18:38 ` John Ogness
  2023-09-15 15:06   ` Timur Tabi
  2023-09-14 19:01 ` [PATCH tty v1 00/74] serial: wrappers for uart port lock Maciej W. Rozycki
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 12+ messages in thread
From: John Ogness @ 2023-09-14 18:38 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Petr Mladek, Timur Tabi, linuxppc-dev, linux-kernel, linux-serial,
	Thomas Gleixner, Jiri Slaby

From: Thomas Gleixner <tglx@linutronix.de>

When a serial port is used for kernel console output, then all
modifications to the UART registers which are done from other contexts,
e.g. getty, termios, are interference points for the kernel console.

So far this has been ignored and the printk output is based on the
principle of hope. The rework of the console infrastructure which aims to
support threaded and atomic consoles, requires to mark sections which
modify the UART registers as unsafe. This allows the atomic write function
to make informed decisions and eventually to restore operational state. It
also allows to prevent the regular UART code from modifying UART registers
while printk output is in progress.

All modifications of UART registers are guarded by the UART port lock,
which provides an obvious synchronization point with the console
infrastructure.

To avoid adding this functionality to all UART drivers, wrap the
spin_[un]lock*() invocations for uart_port::lock into helper functions
which just contain the spin_[un]lock*() invocations for now. In a
subsequent step these helpers will gain the console synchronization
mechanisms.

Converted with coccinelle. No functional change.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 drivers/tty/serial/ucc_uart.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/serial/ucc_uart.c b/drivers/tty/serial/ucc_uart.c
index b06661b80f41..ed7a6bb5596a 100644
--- a/drivers/tty/serial/ucc_uart.c
+++ b/drivers/tty/serial/ucc_uart.c
@@ -931,7 +931,7 @@ static void qe_uart_set_termios(struct uart_port *port,
 	baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk / 16);
 
 	/* Do we really need a spinlock here? */
-	spin_lock_irqsave(&port->lock, flags);
+	uart_port_lock_irqsave(port, &flags);
 
 	/* Update the per-port timeout. */
 	uart_update_timeout(port, termios->c_cflag, baud);
@@ -949,7 +949,7 @@ static void qe_uart_set_termios(struct uart_port *port,
 		qe_setbrg(qe_port->us_info.tx_clock, baud, 16);
 	}
 
-	spin_unlock_irqrestore(&port->lock, flags);
+	uart_port_unlock_irqrestore(port, flags);
 }
 
 /*
-- 
2.39.2


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

* Re: [PATCH tty v1 00/74] serial: wrappers for uart port lock
  2023-09-14 18:37 [PATCH tty v1 00/74] serial: wrappers for uart port lock John Ogness
  2023-09-14 18:38 ` [PATCH tty v1 47/74] serial: pmac_zilog: Use port lock wrappers John Ogness
  2023-09-14 18:38 ` [PATCH tty v1 72/74] serial: ucc_uart: " John Ogness
@ 2023-09-14 19:01 ` Maciej W. Rozycki
  2023-09-15 12:04   ` Thomas Gleixner
  2023-09-15  9:12 ` Ilpo Järvinen
  2023-09-18  8:23 ` John Ogness
  4 siblings, 1 reply; 12+ messages in thread
From: Maciej W. Rozycki @ 2023-09-14 19:01 UTC (permalink / raw)
  To: John Ogness
  Cc: Geert Uytterhoeven, Alim Akhtar, Peter Korsgaard, linux-stm32,
	Karol Gugala, Jerome Brunet, linux-samsung-soc, Kevin Hilman,
	Hugo Villeneuve, Hammer Hsieh, Jiamei Xie, NXP Linux Team,
	Vineet Gupta, Thierry Reding, Petr Mladek, Arend van Spriel,
	Sascha Hauer, Nicholas Piggin, linux-unisoc, Thomas Gleixner,
	Andrew Jeffery, Greg Kroah-Hartman, linux-kernel, Samuel Holland,
	Richard Genoud, Pengutronix Kernel Team, Andrew Morton,
	Alexandre Belloni, linux-aspeed, Laxman Dewangan, Dmitry Rokosov,
	Xiongfeng Wang, Matthias Schiffer, delisun, Fabio Estevam,
	Ruan Jinjie, Matthew Howell, Jonathan Hunter, Gabriel Somlo,
	Hongyu Xie, Tobias Klauser, Yangtao Li, Martin Blumenstingl,
	linux-arm-msm, linux-actions, Biju Das, linux-amlogic,
	Michal Simek, Sherry Sun, Neil Armstrong, Chunyan Zhang

On Thu, 14 Sep 2023, John Ogness wrote:

> Patches 2-74 switch all uart port locking call sites to use the new
> wrappers. These patches were automatically generated using coccinelle.

 Hmm, no need to do this for drivers/tty/serial/zs.c?

  Maciej

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

* Re: [PATCH tty v1 00/74] serial: wrappers for uart port lock
  2023-09-14 18:37 [PATCH tty v1 00/74] serial: wrappers for uart port lock John Ogness
                   ` (2 preceding siblings ...)
  2023-09-14 19:01 ` [PATCH tty v1 00/74] serial: wrappers for uart port lock Maciej W. Rozycki
@ 2023-09-15  9:12 ` Ilpo Järvinen
  2023-09-16 19:42   ` John Ogness
  2023-09-18  8:23 ` John Ogness
  4 siblings, 1 reply; 12+ messages in thread
From: Ilpo Järvinen @ 2023-09-15  9:12 UTC (permalink / raw)
  To: John Ogness
  Cc: Geert Uytterhoeven, Alim Akhtar, Peter Korsgaard, linux-stm32,
	Karol Gugala, Jerome Brunet, linux-samsung-soc, Kevin Hilman,
	Hugo Villeneuve, Hammer Hsieh, Jiamei Xie, NXP Linux Team,
	Vineet Gupta, Thierry Reding, Petr Mladek, Arend van Spriel,
	Sascha Hauer, Nicholas Piggin, linux-unisoc, Thomas Gleixner,
	Andrew Jeffery, Greg Kroah-Hartman, LKML, Samuel Holland,
	Richard Genoud, Pengutronix Kernel Team, Andrew Morton,
	Maciej W. Rozycki, Alexandre Belloni, linux-aspeed,
	Laxman Dewangan, Dmitry Rokosov, Xiongfeng Wang,
	Matthias Schiffer, delisun, Fabio Estevam, Ruan Jinjie,
	Matthew Howell, Jonathan Hunter, Gabriel Somlo, Hongyu Xie,
	Tobias Klauser, Yangtao Li, Martin Blumenstingl, linux-arm-msm,
	linux-actions, Biju Das, linux-amlogic, Michal Simek, Sherry Sun

On Thu, 14 Sep 2023, John Ogness wrote:

> When a serial port is used for kernel console output, then all
> modifications to the UART registers which are done from other contexts,
> e.g. getty, termios, are interference points for the kernel console.
> 
> So far this has been ignored and the printk output is based on the
> principle of hope. The rework of the console infrastructure which aims to
> support threaded and atomic consoles, requires to mark sections which
> modify the UART registers as unsafe. This allows the atomic write function
> to make informed decisions and eventually to restore operational state. It
> also allows to prevent the regular UART code from modifying UART registers
> while printk output is in progress.

Hi John,

Would this also be useful to enable printing to console while under port's 
lock (by postponing the output until the lock is released)?

E.g., 8250_dw.c has had this commented out since the dawn on time:
        /*
         * FIXME: this deadlocks if port->lock is already held
         * dev_err(p->dev, "Couldn't set LCR to %d\n", value);
         */

-- 
 i.


> All modifications of UART registers are guarded by the UART port lock,
> which provides an obvious synchronization point with the console
> infrastructure.
> 
> Provide and use wrapper functions for spin_[un]lock*(port->lock)
> invocations so that the console mechanics can be applied later on at a
> single place and does not require to copy the same logic all over the
> drivers.
> 
> Patch 1 adds the wrapper functions.
> 
> Patches 2-74 switch all uart port locking call sites to use the new
> wrappers. These patches were automatically generated using coccinelle.
> The 2 used coccinelle scripts are included below and executed as
> follows:
> 
> $ spatch --sp-file uartlock-1.cocci $FILE
> $ spatch --sp-file uartlock-2.cocci --recursive-includes $FILE
> 
> This series brings no functional change.
> 
> Patches 2-74 contain identical commit message bodies. Feel free to
> fold them into a single commit if that seems more reasonable.
> 
> Thomas Gleixner (74):
>   serial: core: Provide port lock wrappers
>   serial: core: Use lock wrappers
>   serial: 21285: Use port lock wrappers
>   serial: 8250_aspeed_vuart: Use port lock wrappers
>   serial: 8250_bcm7271: Use port lock wrappers
>   serial: 8250: Use port lock wrappers
>   serial: 8250_dma: Use port lock wrappers
>   serial: 8250_dw: Use port lock wrappers
>   serial: 8250_exar: Use port lock wrappers
>   serial: 8250_fsl: Use port lock wrappers
>   serial: 8250_mtk: Use port lock wrappers
>   serial: 8250_omap: Use port lock wrappers
>   serial: 8250_pci1xxxx: Use port lock wrappers
>   serial: altera_jtaguart: Use port lock wrappers
>   serial: altera_uart: Use port lock wrappers
>   serial: amba-pl010: Use port lock wrappers
>   serial: amba-pl011: Use port lock wrappers
>   serial: apb: Use port lock wrappers
>   serial: ar933x: Use port lock wrappers
>   serial: arc_uart: Use port lock wrappers
>   serial: atmel: Use port lock wrappers
>   serial: bcm63xx-uart: Use port lock wrappers
>   serial: cpm_uart: Use port lock wrappers
>   serial: digicolor: Use port lock wrappers
>   serial: dz: Use port lock wrappers
>   serial: linflexuart: Use port lock wrappers
>   serial: fsl_lpuart: Use port lock wrappers
>   serial: icom: Use port lock wrappers
>   serial: imx: Use port lock wrappers
>   serial: ip22zilog: Use port lock wrappers
>   serial: jsm: Use port lock wrappers
>   serial: liteuart: Use port lock wrappers
>   serial: lpc32xx_hs: Use port lock wrappers
>   serial: ma35d1: Use port lock wrappers
>   serial: mcf: Use port lock wrappers
>   serial: men_z135_uart: Use port lock wrappers
>   serial: meson: Use port lock wrappers
>   serial: milbeaut_usio: Use port lock wrappers
>   serial: mpc52xx: Use port lock wrappers
>   serial: mps2-uart: Use port lock wrappers
>   serial: msm: Use port lock wrappers
>   serial: mvebu-uart: Use port lock wrappers
>   serial: omap: Use port lock wrappers
>   serial: owl: Use port lock wrappers
>   serial: pch: Use port lock wrappers
>   serial: pic32: Use port lock wrappers
>   serial: pmac_zilog: Use port lock wrappers
>   serial: pxa: Use port lock wrappers
>   serial: qcom-geni: Use port lock wrappers
>   serial: rda: Use port lock wrappers
>   serial: rp2: Use port lock wrappers
>   serial: sa1100: Use port lock wrappers
>   serial: samsung_tty: Use port lock wrappers
>   serial: sb1250-duart: Use port lock wrappers
>   serial: sc16is7xx: Use port lock wrappers
>   serial: tegra: Use port lock wrappers
>   serial: core: Use port lock wrappers
>   serial: mctrl_gpio: Use port lock wrappers
>   serial: txx9: Use port lock wrappers
>   serial: sh-sci: Use port lock wrappers
>   serial: sifive: Use port lock wrappers
>   serial: sprd: Use port lock wrappers
>   serial: st-asc: Use port lock wrappers
>   serial: stm32: Use port lock wrappers
>   serial: sunhv: Use port lock wrappers
>   serial: sunplus-uart: Use port lock wrappers
>   serial: sunsab: Use port lock wrappers
>   serial: sunsu: Use port lock wrappers
>   serial: sunzilog: Use port lock wrappers
>   serial: timbuart: Use port lock wrappers
>   serial: uartlite: Use port lock wrappers
>   serial: ucc_uart: Use port lock wrappers
>   serial: vt8500: Use port lock wrappers
>   serial: xilinx_uartps: Use port lock wrappers
> 
>  drivers/tty/serial/21285.c                  |   8 +-
>  drivers/tty/serial/8250/8250_aspeed_vuart.c |   6 +-
>  drivers/tty/serial/8250/8250_bcm7271.c      |  28 +++---
>  drivers/tty/serial/8250/8250_core.c         |  12 +--
>  drivers/tty/serial/8250/8250_dma.c          |   8 +-
>  drivers/tty/serial/8250/8250_dw.c           |   8 +-
>  drivers/tty/serial/8250/8250_exar.c         |   4 +-
>  drivers/tty/serial/8250/8250_fsl.c          |   6 +-
>  drivers/tty/serial/8250/8250_mtk.c          |   8 +-
>  drivers/tty/serial/8250/8250_omap.c         |  52 +++++-----
>  drivers/tty/serial/8250/8250_pci1xxxx.c     |   8 +-
>  drivers/tty/serial/8250/8250_port.c         | 100 ++++++++++----------
>  drivers/tty/serial/altera_jtaguart.c        |  28 +++---
>  drivers/tty/serial/altera_uart.c            |  20 ++--
>  drivers/tty/serial/amba-pl010.c             |  20 ++--
>  drivers/tty/serial/amba-pl011.c             |  72 +++++++-------
>  drivers/tty/serial/apbuart.c                |   8 +-
>  drivers/tty/serial/ar933x_uart.c            |  26 ++---
>  drivers/tty/serial/arc_uart.c               |  16 ++--
>  drivers/tty/serial/atmel_serial.c           |  24 ++---
>  drivers/tty/serial/bcm63xx_uart.c           |  22 ++---
>  drivers/tty/serial/cpm_uart.c               |   8 +-
>  drivers/tty/serial/digicolor-usart.c        |  18 ++--
>  drivers/tty/serial/dz.c                     |  32 +++----
>  drivers/tty/serial/fsl_linflexuart.c        |  26 ++---
>  drivers/tty/serial/fsl_lpuart.c             |  88 ++++++++---------
>  drivers/tty/serial/icom.c                   |  26 ++---
>  drivers/tty/serial/imx.c                    |  84 ++++++++--------
>  drivers/tty/serial/ip22zilog.c              |  36 +++----
>  drivers/tty/serial/jsm/jsm_neo.c            |   4 +-
>  drivers/tty/serial/jsm/jsm_tty.c            |  16 ++--
>  drivers/tty/serial/liteuart.c               |  20 ++--
>  drivers/tty/serial/lpc32xx_hs.c             |  26 ++---
>  drivers/tty/serial/ma35d1_serial.c          |  22 ++---
>  drivers/tty/serial/mcf.c                    |  20 ++--
>  drivers/tty/serial/men_z135_uart.c          |   8 +-
>  drivers/tty/serial/meson_uart.c             |  30 +++---
>  drivers/tty/serial/milbeaut_usio.c          |  16 ++--
>  drivers/tty/serial/mpc52xx_uart.c           |  12 +--
>  drivers/tty/serial/mps2-uart.c              |  16 ++--
>  drivers/tty/serial/msm_serial.c             |  38 ++++----
>  drivers/tty/serial/mvebu-uart.c             |  18 ++--
>  drivers/tty/serial/omap-serial.c            |  38 ++++----
>  drivers/tty/serial/owl-uart.c               |  26 ++---
>  drivers/tty/serial/pch_uart.c               |  10 +-
>  drivers/tty/serial/pic32_uart.c             |  20 ++--
>  drivers/tty/serial/pmac_zilog.c             |  52 +++++-----
>  drivers/tty/serial/pxa.c                    |  30 +++---
>  drivers/tty/serial/qcom_geni_serial.c       |   8 +-
>  drivers/tty/serial/rda-uart.c               |  34 +++----
>  drivers/tty/serial/rp2.c                    |  20 ++--
>  drivers/tty/serial/sa1100.c                 |  20 ++--
>  drivers/tty/serial/samsung_tty.c            |  50 +++++-----
>  drivers/tty/serial/sb1250-duart.c           |  12 +--
>  drivers/tty/serial/sc16is7xx.c              |  40 ++++----
>  drivers/tty/serial/serial-tegra.c           |  32 +++----
>  drivers/tty/serial/serial_core.c            |  88 ++++++++---------
>  drivers/tty/serial/serial_mctrl_gpio.c      |   4 +-
>  drivers/tty/serial/serial_port.c            |   4 +-
>  drivers/tty/serial/serial_txx9.c            |  26 ++---
>  drivers/tty/serial/sh-sci.c                 |  68 ++++++-------
>  drivers/tty/serial/sifive.c                 |  16 ++--
>  drivers/tty/serial/sprd_serial.c            |  30 +++---
>  drivers/tty/serial/st-asc.c                 |  18 ++--
>  drivers/tty/serial/stm32-usart.c            |  38 ++++----
>  drivers/tty/serial/sunhv.c                  |  28 +++---
>  drivers/tty/serial/sunplus-uart.c           |  26 ++---
>  drivers/tty/serial/sunsab.c                 |  34 +++----
>  drivers/tty/serial/sunsu.c                  |  46 ++++-----
>  drivers/tty/serial/sunzilog.c               |  42 ++++----
>  drivers/tty/serial/timbuart.c               |   8 +-
>  drivers/tty/serial/uartlite.c               |  18 ++--
>  drivers/tty/serial/ucc_uart.c               |   4 +-
>  drivers/tty/serial/vt8500_serial.c          |   8 +-
>  drivers/tty/serial/xilinx_uartps.c          |  56 +++++------
>  include/linux/serial_core.h                 |  91 ++++++++++++++++--
>  76 files changed, 1086 insertions(+), 1007 deletions(-)
> 
> 
> base-commit: 0bb80ecc33a8fb5a682236443c1e740d5c917d1d
> 

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

* Re: [PATCH tty v1 00/74] serial: wrappers for uart port lock
  2023-09-14 19:01 ` [PATCH tty v1 00/74] serial: wrappers for uart port lock Maciej W. Rozycki
@ 2023-09-15 12:04   ` Thomas Gleixner
  2023-09-15 17:23     ` Maciej W. Rozycki
  0 siblings, 1 reply; 12+ messages in thread
From: Thomas Gleixner @ 2023-09-15 12:04 UTC (permalink / raw)
  To: Maciej W. Rozycki, John Ogness
  Cc: Geert Uytterhoeven, Alim Akhtar, Peter Korsgaard, linux-stm32,
	Karol Gugala, Jerome Brunet, linux-samsung-soc, Hugo Villeneuve,
	Hammer Hsieh, Jiamei Xie, NXP Linux Team, Vineet Gupta,
	Thierry Reding, Petr Mladek, Arend van Spriel, Sascha Hauer,
	Nicholas Piggin, linux-unisoc, Andrew Jeffery, Greg Kroah-Hartman,
	linux-kernel, Samuel Holland, Richard Genoud,
	Pengutronix Kernel Team, Andrew Morton, Alexandre Bello ni,
	linux-aspeed, Laxman Dewangan, Dmitry Rokosov, Xiongfeng Wang,
	Matthias Schiffer, delisun, Fabio Estevam, Ruan Jinjie,
	Matthew Howell, Jonathan Hunter, Gabriel Somlo, Hongyu Xie,
	Tobias Klauser, Yangtao Li, Martin Blumenstingl, linux-arm-msm,
	linux-actions, Biju Das, linux-amlogic, Michal Simek, Sherry Sun,
	Neil Armstrong, Chunyan Zhang, David S. Miller,
	Kumaravel Thiagarajan, Lukas Wunner, Sergey Organov, Mukesh Ojha,
	Maxime Coquelin, Kevin Hilman, Pali Rohár, Lino Sanfilippo,
	Tom Rix, Lorenzo Pieralisi, Al Cooper, Yuan Can, Isaac True,
	linux-tegra, Jiri Slaby, Rob Herring, Florian Fainelli,
	Mateusz Holenko, Kevin Cernekee, Andy Shevchenko, Shenwei Wang,
	Broadcom internal kernel review list, Joel Stanley, Chen-Yu Tsai,
	Ilpo =?utf -8?Q?J?= ärvinen, linux-snps-arc, Patrice Chotard,
	Jacky Huang, Arnd Bergmann, Uwe Kleine-König,
	Jonathan Neuschäfer, Vladimir Zapolskiy, Baolin Wang,
	Orson Zhai, Tharun Kumar P, Timur Tabi, Claudiu Beznea,
	Konrad Dybcio, Thierry Reding, Sudeep Holla, Shawn Guo,
	Andreas Färber, Baruch Siach, Valentin Caron, Tony Lindgren,
	Sebastian Andrzej Siewior, Liviu Dudau, A lexandre Torgue,
	sparclinux, Shan-Chun Hung, linux-riscv, Marek Vasut,
	Lech Perczak, Russell King, Nick Hu, Andy Gross, linux-serial,
	Lukas Bulwahn, Manivannan Sadhasivam, Johan Hovold,
	linux-mediatek, Paul Walmsley, Matthias Brugger, Andy Shevchenko,
	AngeloGioacchino Del Regno, linux-arm-kernel, Taichi Sugaya,
	Bjorn Andersson, Nicolas Ferre, Lucas Tanure, Andrew Davis,
	Krzysztof Kozlowski, Palmer Dabbelt, Takao Orito, linuxppc-dev

On Thu, Sep 14 2023 at 20:01, Maciej W. Rozycki wrote:

> On Thu, 14 Sep 2023, John Ogness wrote:
>
>> Patches 2-74 switch all uart port locking call sites to use the new
>> wrappers. These patches were automatically generated using coccinelle.
>
>  Hmm, no need to do this for drivers/tty/serial/zs.c?

zs.c does not use port lock at all. It has like a couple of other
drivers a local homebrewn spinlock.

Thanks,

        tglx

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

* Re: [PATCH tty v1 72/74] serial: ucc_uart: Use port lock wrappers
  2023-09-14 18:38 ` [PATCH tty v1 72/74] serial: ucc_uart: " John Ogness
@ 2023-09-15 15:06   ` Timur Tabi
  0 siblings, 0 replies; 12+ messages in thread
From: Timur Tabi @ 2023-09-15 15:06 UTC (permalink / raw)
  To: John Ogness
  Cc: Petr Mladek, Timur Tabi, Greg Kroah-Hartman, linuxppc-dev,
	linux-kernel, linux-serial, Thomas Gleixner, Jiri Slaby

On Thu, Sep 14, 2023 at 1:39 PM John Ogness <john.ogness@linutronix.de> wrote:

> Converted with coccinelle. No functional change.
>
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> ---
>  drivers/tty/serial/ucc_uart.c | 4 ++--

Acked-by: Timur Tabi <timur@kernel.org>

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

* Re: [PATCH tty v1 00/74] serial: wrappers for uart port lock
  2023-09-15 12:04   ` Thomas Gleixner
@ 2023-09-15 17:23     ` Maciej W. Rozycki
  2023-09-16 19:24       ` John Ogness
  0 siblings, 1 reply; 12+ messages in thread
From: Maciej W. Rozycki @ 2023-09-15 17:23 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: Geert Uytterhoeven, Alim Akhtar, linux-stm32, Karol Gugala,
	Jerome Brunet, linux-samsung-soc, Kevin Hilman, Hugo Villeneuve,
	Hammer Hsieh, Jiamei Xie, NXP Linux Team, Vineet Gupta,
	Thierry Reding, Petr Mladek, Arend van Spriel, Sascha Hauer,
	Nicholas Piggin, linux-unisoc, Andrew Jeffery, Greg Kroah-Hartman,
	linux-kernel, Samuel Holland, Richard Genoud,
	Pengutronix Kernel Team, Andrew Morton, Alexandre Bello ni,
	linux-aspeed, Laxman Dewangan, Dmitry Rokosov, Xiongfeng Wang,
	Matthias Schiffer, delisun, Fabio Estevam, Ruan Jinjie,
	Matthew Howell, Jonathan Hunter, Gabriel Somlo, Hongyu Xie,
	Tobias Klauser, John Ogness, Yangtao Li, Martin Blumenstingl,
	linux-arm-msm, linux-actions, Biju Das, linux-amlogic,
	Michal Simek, Sherry Sun, Neil Armstrong, Chunyan Zhang,
	David S. Miller

On Fri, 15 Sep 2023, Thomas Gleixner wrote:

> >> Patches 2-74 switch all uart port locking call sites to use the new
> >> wrappers. These patches were automatically generated using coccinelle.
> >
> >  Hmm, no need to do this for drivers/tty/serial/zs.c?
> 
> zs.c does not use port lock at all. It has like a couple of other
> drivers a local homebrewn spinlock.

 Ah, right, that's because there are registers shared between two ports 
within one SCC, so the spinlock has to be shared as well.

 This also indicates that dz.c is wrong and shouldn't be using a per-port 
spinlock as the DZ has a shared register set between all the four ports 
(it's a serial line multiplexer rather than a set discrete ports; up to 8 
lines are architecturally supported, though we don't have support in Linux 
for systems having those), e.g. there's only one 16-bit receiver buffer 
register for all the four ports, supplying the 8-bit character received 
along with the receive status and the number of the line this data arrived 
on, and similarly there's only one transmit data register, which supplies 
data to the next enabled line whose transmit buffer needs servicing, and 
the chip routes the data itself.  Therefore the driver ought to use a 
shared spinlock too.

 I guess it wasn't noticed so far because DZ devices aren't that common 
(and my usual test machine is currently broken too, pending an SRAM chip 
replacement, hopefully in the next few weeks) and then hardly ever more 
than one serial line has been used at a time with these devices.  It looks 
like the first issue for me to look into once the machine has been fixed.

 Maybe dz.c shouldn't be touched by this series then?  (Though obviously 
both drivers will have to be eventually adapted for the ultimate console 
rework.)

 Thanks for your input, as it turns out it has had an unexpected outcome.

  Maciej

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

* Re: [PATCH tty v1 00/74] serial: wrappers for uart port lock
  2023-09-15 17:23     ` Maciej W. Rozycki
@ 2023-09-16 19:24       ` John Ogness
  0 siblings, 0 replies; 12+ messages in thread
From: John Ogness @ 2023-09-16 19:24 UTC (permalink / raw)
  To: Maciej W. Rozycki, Thomas Gleixner
  Cc: Geert Uytterhoeven, Alim Akhtar, linux-stm32, Karol Gugala,
	Jerome Brunet, linux-samsung-soc, Hugo Villeneuve, Hammer Hsieh,
	Jiamei Xie, NXP Linux Team, Vineet Gupta, Thierry Reding,
	Petr Mladek, Arend van Spriel, Sascha Hauer, Nicholas Piggin,
	linux-unisoc, Andrew Jeffery, Greg Kroah-Hartman, linux-kernel,
	Samuel Holland, Richard Genoud, Pengutronix Kernel Team,
	Andrew Morton, Alexandre Belloni

On 2023-09-15, "Maciej W. Rozycki" <macro@orcam.me.uk> wrote:
> Maybe dz.c shouldn't be touched by this series then?

Correct. This series is only wrapping the uart port lock, which dz.c is
not using.

> Though obviously both drivers will have to be eventually adapted for
> the ultimate console rework.

Correct.

Thanks for clarifying how the hardware works.

John

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

* Re: [PATCH tty v1 00/74] serial: wrappers for uart port lock
  2023-09-15  9:12 ` Ilpo Järvinen
@ 2023-09-16 19:42   ` John Ogness
  0 siblings, 0 replies; 12+ messages in thread
From: John Ogness @ 2023-09-16 19:42 UTC (permalink / raw)
  To: Ilpo Järvinen
  Cc: Geert Uytterhoeven, Alim Akhtar, Peter Korsgaard, linux-stm32,
	Karol Gugala, Jerome Brunet, linux-samsung-soc, Kevin Hilman,
	Hugo Villeneuve, Hammer Hsieh, Jiamei Xie, NXP Linux Team,
	Vineet Gupta, Thierry Reding, Petr Mladek, Arend van Spriel,
	Sascha Hauer, Nicholas Piggin, linux-unisoc, Thomas Gleixner,
	Andrew Jeffery, Greg Kroah-Hartman, LKML, Samuel Holland,
	Richard Genoud, Pengutronix Kernel Team, Andrew Morton,
	Maciej W. Rozycki, Alexandre Belloni, linux-aspeed,
	Laxman Dewangan, Dmitry Rokosov, Xiongfeng Wang,
	Matthias Schiffer, delisun, Fabio Estevam, Ruan Jinjie,
	Matthew Howell, Jonathan Hunter, Gabriel Somlo, Hongyu Xie,
	Tobias Klauser, Yangtao Li, Martin Blumenstingl, linux-arm-msm,
	linux-actions, Biju Das, linux-amlogic, Michal Simek, Sherry Sun

On 2023-09-15, Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> wrote:
> Would this also be useful to enable printing to console while under
> port's lock (by postponing the output until the lock is released)?
>
> E.g., 8250_dw.c has had this commented out since the dawn on time:
>         /*
>          * FIXME: this deadlocks if port->lock is already held
>          * dev_err(p->dev, "Couldn't set LCR to %d\n", value);
>          */

Yes, this will fix such issues. However, only for consoles that are
converted to the new NBCON console type.

Good news, the 8250 driver will be the flagship driver that is converted
as part of the rework. So this particular issue will be solved then. I
will try to remember this so that I can remove the FIXME in the series.

Thanks for mentioning it.

John

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

* Re: [PATCH tty v1 00/74] serial: wrappers for uart port lock
  2023-09-14 18:37 [PATCH tty v1 00/74] serial: wrappers for uart port lock John Ogness
                   ` (3 preceding siblings ...)
  2023-09-15  9:12 ` Ilpo Järvinen
@ 2023-09-18  8:23 ` John Ogness
  2023-09-18  8:26   ` Greg Kroah-Hartman
  4 siblings, 1 reply; 12+ messages in thread
From: John Ogness @ 2023-09-18  8:23 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Geert Uytterhoeven, Alim Akhtar, Peter Korsgaard, linux-stm32,
	Karol Gugala, Jerome Brunet, linux-samsung-soc, Kevin Hilman,
	Hugo Villeneuve, Hammer Hsieh, Jiamei Xie, NXP Linux Team,
	Vineet Gupta, Thierry Reding, Petr Mladek, Arend van Spriel,
	Sascha Hauer, Nicholas Piggin, linux-unisoc, Thomas Gleixner,
	Andrew Jeffery, linux-kernel, Samuel Holland, Richard Genoud,
	Pengutronix Kernel Team, Andrew Morton

On 2023-09-14, John Ogness <john.ogness@linutronix.de> wrote:
> Provide and use wrapper functions for spin_[un]lock*(port->lock)
> invocations so that the console mechanics can be applied later on at a
> single place and does not require to copy the same logic all over the
> drivers.

For the full 74-patch series:

Signed-off-by: John Ogness <john.ogness@linutronix.de>

Sorry that my SoB was missing from the initial posting.

John Ogness

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

* Re: [PATCH tty v1 00/74] serial: wrappers for uart port lock
  2023-09-18  8:23 ` John Ogness
@ 2023-09-18  8:26   ` Greg Kroah-Hartman
  0 siblings, 0 replies; 12+ messages in thread
From: Greg Kroah-Hartman @ 2023-09-18  8:26 UTC (permalink / raw)
  To: John Ogness
  Cc: Geert Uytterhoeven, Alim Akhtar, Peter Korsgaard, linux-stm32,
	Karol Gugala, Jerome Brunet, linux-samsung-soc, Kevin Hilman,
	Hugo Villeneuve, Hammer Hsieh, Jiamei Xie, NXP Linux Team,
	Vineet Gupta, Thierry Reding, Petr Mladek, Arend van Spriel,
	Sascha Hauer, Nicholas Piggin, linux-unisoc, Thomas Gleixner,
	Andrew Jeffery, linux-kernel, Samuel Holland, Richard Genoud,
	Pengutronix Kernel Team, Andrew Morton

On Mon, Sep 18, 2023 at 10:29:30AM +0206, John Ogness wrote:
> On 2023-09-14, John Ogness <john.ogness@linutronix.de> wrote:
> > Provide and use wrapper functions for spin_[un]lock*(port->lock)
> > invocations so that the console mechanics can be applied later on at a
> > single place and does not require to copy the same logic all over the
> > drivers.
> 
> For the full 74-patch series:
> 
> Signed-off-by: John Ogness <john.ogness@linutronix.de>
> 
> Sorry that my SoB was missing from the initial posting.

Thanks for this, I'll rebuild my tree with this added.

greg k-h

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

end of thread, other threads:[~2023-09-18 10:10 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-14 18:37 [PATCH tty v1 00/74] serial: wrappers for uart port lock John Ogness
2023-09-14 18:38 ` [PATCH tty v1 47/74] serial: pmac_zilog: Use port lock wrappers John Ogness
2023-09-14 18:38 ` [PATCH tty v1 72/74] serial: ucc_uart: " John Ogness
2023-09-15 15:06   ` Timur Tabi
2023-09-14 19:01 ` [PATCH tty v1 00/74] serial: wrappers for uart port lock Maciej W. Rozycki
2023-09-15 12:04   ` Thomas Gleixner
2023-09-15 17:23     ` Maciej W. Rozycki
2023-09-16 19:24       ` John Ogness
2023-09-15  9:12 ` Ilpo Järvinen
2023-09-16 19:42   ` John Ogness
2023-09-18  8:23 ` John Ogness
2023-09-18  8:26   ` Greg Kroah-Hartman

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