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

serial: 8250_pci1xxxx: 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-14-john.ogness@linutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Thomas Gleixner and committed by
Greg Kroah-Hartman
cbc35085 e4a13758

+4 -4
+4 -4
drivers/tty/serial/8250/8250_pci1xxxx.c
··· 225 225 if (port->suspended == 0 && port->dev) { 226 226 wakeup_mask = readb(up->port.membase + UART_WAKE_MASK_REG); 227 227 228 - spin_lock_irqsave(&port->lock, flags); 228 + uart_port_lock_irqsave(port, &flags); 229 229 port->mctrl &= ~TIOCM_OUT2; 230 230 port->ops->set_mctrl(port, port->mctrl); 231 - spin_unlock_irqrestore(&port->lock, flags); 231 + uart_port_unlock_irqrestore(port, flags); 232 232 233 233 ret = (wakeup_mask & UART_WAKE_SRCS) != UART_WAKE_SRCS; 234 234 } ··· 251 251 writeb(UART_WAKE_SRCS, port->membase + UART_WAKE_REG); 252 252 253 253 if (port->suspended == 0) { 254 - spin_lock_irqsave(&port->lock, flags); 254 + uart_port_lock_irqsave(port, &flags); 255 255 port->mctrl |= TIOCM_OUT2; 256 256 port->ops->set_mctrl(port, port->mctrl); 257 - spin_unlock_irqrestore(&port->lock, flags); 257 + uart_port_unlock_irqrestore(port, flags); 258 258 } 259 259 mutex_unlock(&tport->mutex); 260 260 }