Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

serial: pch: Use port lock wrappers

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>
Signed-off-by: John Ogness <john.ogness@linutronix.de>
Link: https://lore.kernel.org/r/20230914183831.587273-46-john.ogness@linutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Thomas Gleixner and committed by
Greg Kroah-Hartman
150b59a7 68dcb369

+5 -5
+5 -5
drivers/tty/serial/pch_uart.c
··· 1347 1347 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk / 16); 1348 1348 1349 1349 spin_lock_irqsave(&priv->lock, flags); 1350 - spin_lock(&port->lock); 1350 + uart_port_lock(port); 1351 1351 1352 1352 uart_update_timeout(port, termios->c_cflag, baud); 1353 1353 rtn = pch_uart_hal_set_line(priv, baud, parity, bits, stb); ··· 1360 1360 tty_termios_encode_baud_rate(termios, baud, baud); 1361 1361 1362 1362 out: 1363 - spin_unlock(&port->lock); 1363 + uart_port_unlock(port); 1364 1364 spin_unlock_irqrestore(&priv->lock, flags); 1365 1365 } 1366 1366 ··· 1581 1581 port_locked = 0; 1582 1582 } else if (oops_in_progress) { 1583 1583 priv_locked = spin_trylock(&priv->lock); 1584 - port_locked = spin_trylock(&priv->port.lock); 1584 + port_locked = uart_port_trylock(&priv->port); 1585 1585 } else { 1586 1586 spin_lock(&priv->lock); 1587 - spin_lock(&priv->port.lock); 1587 + uart_port_lock(&priv->port); 1588 1588 } 1589 1589 1590 1590 /* ··· 1604 1604 iowrite8(ier, priv->membase + UART_IER); 1605 1605 1606 1606 if (port_locked) 1607 - spin_unlock(&priv->port.lock); 1607 + uart_port_unlock(&priv->port); 1608 1608 if (priv_locked) 1609 1609 spin_unlock(&priv->lock); 1610 1610 local_irq_restore(flags);