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

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

authored by

Thomas Gleixner and committed by
Greg Kroah-Hartman
71007c5e c5d06662

+14 -14
+14 -14
drivers/tty/serial/sunhv.c
··· 217 217 struct tty_port *tport; 218 218 unsigned long flags; 219 219 220 - spin_lock_irqsave(&port->lock, flags); 220 + uart_port_lock_irqsave(port, &flags); 221 221 tport = receive_chars(port); 222 222 transmit_chars(port); 223 - spin_unlock_irqrestore(&port->lock, flags); 223 + uart_port_unlock_irqrestore(port, flags); 224 224 225 225 if (tport) 226 226 tty_flip_buffer_push(tport); ··· 271 271 if (ch == __DISABLED_CHAR) 272 272 return; 273 273 274 - spin_lock_irqsave(&port->lock, flags); 274 + uart_port_lock_irqsave(port, &flags); 275 275 276 276 while (limit-- > 0) { 277 277 long status = sun4v_con_putchar(ch); ··· 280 280 udelay(1); 281 281 } 282 282 283 - spin_unlock_irqrestore(&port->lock, flags); 283 + uart_port_unlock_irqrestore(port, flags); 284 284 } 285 285 286 286 /* port->lock held by caller. */ ··· 295 295 unsigned long flags; 296 296 int limit = 10000; 297 297 298 - spin_lock_irqsave(&port->lock, flags); 298 + uart_port_lock_irqsave(port, &flags); 299 299 300 300 while (limit-- > 0) { 301 301 long status = sun4v_con_putchar(CON_BREAK); ··· 304 304 udelay(1); 305 305 } 306 306 307 - spin_unlock_irqrestore(&port->lock, flags); 307 + uart_port_unlock_irqrestore(port, flags); 308 308 } 309 309 } 310 310 ··· 328 328 unsigned int iflag, cflag; 329 329 unsigned long flags; 330 330 331 - spin_lock_irqsave(&port->lock, flags); 331 + uart_port_lock_irqsave(port, &flags); 332 332 333 333 iflag = termios->c_iflag; 334 334 cflag = termios->c_cflag; ··· 343 343 uart_update_timeout(port, cflag, 344 344 (port->uartclk / (16 * quot))); 345 345 346 - spin_unlock_irqrestore(&port->lock, flags); 346 + uart_port_unlock_irqrestore(port, flags); 347 347 } 348 348 349 349 static const char *sunhv_type(struct uart_port *port) ··· 437 437 int locked = 1; 438 438 439 439 if (port->sysrq || oops_in_progress) 440 - locked = spin_trylock_irqsave(&port->lock, flags); 440 + locked = uart_port_trylock_irqsave(port, &flags); 441 441 else 442 - spin_lock_irqsave(&port->lock, flags); 442 + uart_port_lock_irqsave(port, &flags); 443 443 444 444 while (n > 0) { 445 445 unsigned long ra = __pa(con_write_page); ··· 470 470 } 471 471 472 472 if (locked) 473 - spin_unlock_irqrestore(&port->lock, flags); 473 + uart_port_unlock_irqrestore(port, flags); 474 474 } 475 475 476 476 static inline void sunhv_console_putchar(struct uart_port *port, char c) ··· 492 492 int i, locked = 1; 493 493 494 494 if (port->sysrq || oops_in_progress) 495 - locked = spin_trylock_irqsave(&port->lock, flags); 495 + locked = uart_port_trylock_irqsave(port, &flags); 496 496 else 497 - spin_lock_irqsave(&port->lock, flags); 497 + uart_port_lock_irqsave(port, &flags); 498 498 499 499 for (i = 0; i < n; i++) { 500 500 if (*s == '\n') ··· 503 503 } 504 504 505 505 if (locked) 506 - spin_unlock_irqrestore(&port->lock, flags); 506 + uart_port_unlock_irqrestore(port, flags); 507 507 } 508 508 509 509 static struct console sunhv_console = {