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

Configure Feed

Select the types of activity you want to include in your feed.

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

authored by

Thomas Gleixner and committed by
Greg Kroah-Hartman
de71068b 07e89352

+9 -9
+9 -9
drivers/tty/serial/uartlite.c
··· 216 216 unsigned long flags; 217 217 218 218 do { 219 - spin_lock_irqsave(&port->lock, flags); 219 + uart_port_lock_irqsave(port, &flags); 220 220 stat = uart_in32(ULITE_STATUS, port); 221 221 busy = ulite_receive(port, stat); 222 222 busy |= ulite_transmit(port, stat); 223 - spin_unlock_irqrestore(&port->lock, flags); 223 + uart_port_unlock_irqrestore(port, flags); 224 224 n++; 225 225 } while (busy); 226 226 ··· 238 238 unsigned long flags; 239 239 unsigned int ret; 240 240 241 - spin_lock_irqsave(&port->lock, flags); 241 + uart_port_lock_irqsave(port, &flags); 242 242 ret = uart_in32(ULITE_STATUS, port); 243 - spin_unlock_irqrestore(&port->lock, flags); 243 + uart_port_unlock_irqrestore(port, flags); 244 244 245 245 return ret & ULITE_STATUS_TXEMPTY ? TIOCSER_TEMT : 0; 246 246 } ··· 323 323 termios->c_cflag |= pdata->cflags & (PARENB | PARODD | CSIZE); 324 324 tty_termios_encode_baud_rate(termios, pdata->baud, pdata->baud); 325 325 326 - spin_lock_irqsave(&port->lock, flags); 326 + uart_port_lock_irqsave(port, &flags); 327 327 328 328 port->read_status_mask = ULITE_STATUS_RXVALID | ULITE_STATUS_OVERRUN 329 329 | ULITE_STATUS_TXFULL; ··· 346 346 /* update timeout */ 347 347 uart_update_timeout(port, termios->c_cflag, pdata->baud); 348 348 349 - spin_unlock_irqrestore(&port->lock, flags); 349 + uart_port_unlock_irqrestore(port, flags); 350 350 } 351 351 352 352 static const char *ulite_type(struct uart_port *port) ··· 495 495 int locked = 1; 496 496 497 497 if (oops_in_progress) { 498 - locked = spin_trylock_irqsave(&port->lock, flags); 498 + locked = uart_port_trylock_irqsave(port, &flags); 499 499 } else 500 - spin_lock_irqsave(&port->lock, flags); 500 + uart_port_lock_irqsave(port, &flags); 501 501 502 502 /* save and disable interrupt */ 503 503 ier = uart_in32(ULITE_STATUS, port) & ULITE_STATUS_IE; ··· 512 512 uart_out32(ULITE_CONTROL_IE, ULITE_CONTROL, port); 513 513 514 514 if (locked) 515 - spin_unlock_irqrestore(&port->lock, flags); 515 + uart_port_unlock_irqrestore(port, flags); 516 516 } 517 517 518 518 static int ulite_console_setup(struct console *co, char *options)