Commit eae22e19 authored by Sean Anderson's avatar Sean Anderson Committed by Wentao Guan
Browse files

tty: xilinx_uartps: split sysrq handling

stable inclusion
from stable-v6.6.78
commit 8ea0e7b3d7b8f2f0fc9db491ff22a0abe120801c
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IBX1M5

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=8ea0e7b3d7b8f2f0fc9db491ff22a0abe120801c



--------------------------------

commit b06f388994500297bb91be60ffaf6825ecfd2afe upstream.

lockdep detects the following circular locking dependency:

CPU 0                      CPU 1
========================== ============================
cdns_uart_isr()            printk()
  uart_port_lock(port)       console_lock()
			     cdns_uart_console_write()
                               if (!port->sysrq)
                                 uart_port_lock(port)
  uart_handle_break()
    port->sysrq = ...
  uart_handle_sysrq_char()
    printk()
      console_lock()

The fixed commit attempts to avoid this situation by only taking the
port lock in cdns_uart_console_write if port->sysrq unset. However, if
(as shown above) cdns_uart_console_write runs before port->sysrq is set,
then it will try to take the port lock anyway. This may result in a
deadlock.

Fix this by splitting sysrq handling into two parts. We use the prepare
helper under the port lock and defer handling until we release the lock.

Fixes: 74ea66d4 ("tty: xuartps: Improve sysrq handling")
Signed-off-by: default avatarSean Anderson <sean.anderson@linux.dev>
Cc: stable@vger.kernel.org # c980248179d: serial: xilinx_uartps: Use port lock wrappers
Acked-by: default avatarJohn Ogness <john.ogness@linutronix.de>
Link: https://lore.kernel.org/r/20250110213822.2107462-1-sean.anderson@linux.dev


Signed-off-by: default avatarSean Anderson <sean.anderson@linux.dev>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 8ea0e7b3d7b8f2f0fc9db491ff22a0abe120801c)
Signed-off-by: default avatarWentao Guan <guanwentao@uniontech.com>
parent 5132dffc
Loading
Loading
Loading
Loading
+4 −6
Original line number Diff line number Diff line
@@ -268,7 +268,7 @@ static void cdns_uart_handle_rx(void *dev_id, unsigned int isrstatus)
				continue;
		}

		if (uart_handle_sysrq_char(port, data))
		if (uart_prepare_sysrq_char(port, data))
			continue;

		if (is_rxbs_support) {
@@ -369,7 +369,7 @@ static irqreturn_t cdns_uart_isr(int irq, void *dev_id)
	    !(readl(port->membase + CDNS_UART_CR) & CDNS_UART_CR_RX_DIS))
		cdns_uart_handle_rx(dev_id, isrstatus);

	spin_unlock(&port->lock);
	uart_unlock_and_check_sysrq(port);
	return IRQ_HANDLED;
}

@@ -1229,10 +1229,8 @@ static void cdns_uart_console_write(struct console *co, const char *s,
	unsigned int imr, ctrl;
	int locked = 1;

	if (port->sysrq)
		locked = 0;
	else if (oops_in_progress)
		locked = spin_trylock_irqsave(&port->lock, flags);
	if (oops_in_progress)
		locked = uart_port_trylock_irqsave(port, &flags);
	else
		spin_lock_irqsave(&port->lock, flags);