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

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

authored by

Thomas Gleixner and committed by
Greg Kroah-Hartman
08b08d7c 2d8a3178

+16 -16
+16 -16
drivers/tty/serial/dz.c
··· 268 268 } 269 269 /* If nothing to do or stopped or hardware stopped. */ 270 270 if (uart_circ_empty(xmit) || uart_tx_stopped(&dport->port)) { 271 - spin_lock(&dport->port.lock); 271 + uart_port_lock(&dport->port); 272 272 dz_stop_tx(&dport->port); 273 - spin_unlock(&dport->port.lock); 273 + uart_port_unlock(&dport->port); 274 274 return; 275 275 } 276 276 ··· 287 287 288 288 /* Are we are done. */ 289 289 if (uart_circ_empty(xmit)) { 290 - spin_lock(&dport->port.lock); 290 + uart_port_lock(&dport->port); 291 291 dz_stop_tx(&dport->port); 292 - spin_unlock(&dport->port.lock); 292 + uart_port_unlock(&dport->port); 293 293 } 294 294 } 295 295 ··· 415 415 return ret; 416 416 } 417 417 418 - spin_lock_irqsave(&dport->port.lock, flags); 418 + uart_port_lock_irqsave(&dport->port, &flags); 419 419 420 420 /* Enable interrupts. */ 421 421 tmp = dz_in(dport, DZ_CSR); 422 422 tmp |= DZ_RIE | DZ_TIE; 423 423 dz_out(dport, DZ_CSR, tmp); 424 424 425 - spin_unlock_irqrestore(&dport->port.lock, flags); 425 + uart_port_unlock_irqrestore(&dport->port, flags); 426 426 427 427 return 0; 428 428 } ··· 443 443 int irq_guard; 444 444 u16 tmp; 445 445 446 - spin_lock_irqsave(&dport->port.lock, flags); 446 + uart_port_lock_irqsave(&dport->port, &flags); 447 447 dz_stop_tx(&dport->port); 448 - spin_unlock_irqrestore(&dport->port.lock, flags); 448 + uart_port_unlock_irqrestore(&dport->port, flags); 449 449 450 450 irq_guard = atomic_add_return(-1, &mux->irq_guard); 451 451 if (!irq_guard) { ··· 491 491 unsigned long flags; 492 492 unsigned short tmp, mask = 1 << dport->port.line; 493 493 494 - spin_lock_irqsave(&uport->lock, flags); 494 + uart_port_lock_irqsave(uport, &flags); 495 495 tmp = dz_in(dport, DZ_TCR); 496 496 if (break_state) 497 497 tmp |= mask; 498 498 else 499 499 tmp &= ~mask; 500 500 dz_out(dport, DZ_TCR, tmp); 501 - spin_unlock_irqrestore(&uport->lock, flags); 501 + uart_port_unlock_irqrestore(uport, flags); 502 502 } 503 503 504 504 static int dz_encode_baud_rate(unsigned int baud) ··· 608 608 if (termios->c_cflag & CREAD) 609 609 cflag |= DZ_RXENAB; 610 610 611 - spin_lock_irqsave(&dport->port.lock, flags); 611 + uart_port_lock_irqsave(&dport->port, &flags); 612 612 613 613 uart_update_timeout(uport, termios->c_cflag, baud); 614 614 ··· 631 631 if (termios->c_iflag & IGNBRK) 632 632 dport->port.ignore_status_mask |= DZ_BREAK; 633 633 634 - spin_unlock_irqrestore(&dport->port.lock, flags); 634 + uart_port_unlock_irqrestore(&dport->port, flags); 635 635 } 636 636 637 637 /* ··· 645 645 struct dz_port *dport = to_dport(uport); 646 646 unsigned long flags; 647 647 648 - spin_lock_irqsave(&dport->port.lock, flags); 648 + uart_port_lock_irqsave(&dport->port, &flags); 649 649 if (state < 3) 650 650 dz_start_tx(&dport->port); 651 651 else 652 652 dz_stop_tx(&dport->port); 653 - spin_unlock_irqrestore(&dport->port.lock, flags); 653 + uart_port_unlock_irqrestore(&dport->port, flags); 654 654 } 655 655 656 656 ··· 811 811 unsigned short csr, tcr, trdy, mask; 812 812 int loops = 10000; 813 813 814 - spin_lock_irqsave(&dport->port.lock, flags); 814 + uart_port_lock_irqsave(&dport->port, &flags); 815 815 csr = dz_in(dport, DZ_CSR); 816 816 dz_out(dport, DZ_CSR, csr & ~DZ_TIE); 817 817 tcr = dz_in(dport, DZ_TCR); ··· 819 819 mask = tcr; 820 820 dz_out(dport, DZ_TCR, mask); 821 821 iob(); 822 - spin_unlock_irqrestore(&dport->port.lock, flags); 822 + uart_port_unlock_irqrestore(&dport->port, flags); 823 823 824 824 do { 825 825 trdy = dz_in(dport, DZ_CSR);