]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.19.31/serial-uartps-fix-stuck-isr-if-rx-disabled-with-non-empty-fifo.patch
Linux 4.14.108
[thirdparty/kernel/stable-queue.git] / releases / 4.19.31 / serial-uartps-fix-stuck-isr-if-rx-disabled-with-non-empty-fifo.patch
1 From 7abab1605139bc41442864c18f9573440f7ca105 Mon Sep 17 00:00:00 2001
2 From: Anssi Hannula <anssi.hannula@bitwise.fi>
3 Date: Fri, 15 Feb 2019 18:45:08 +0200
4 Subject: serial: uartps: Fix stuck ISR if RX disabled with non-empty FIFO
5
6 From: Anssi Hannula <anssi.hannula@bitwise.fi>
7
8 commit 7abab1605139bc41442864c18f9573440f7ca105 upstream.
9
10 If RX is disabled while there are still unprocessed bytes in RX FIFO,
11 cdns_uart_handle_rx() called from interrupt handler will get stuck in
12 the receive loop as read bytes will not get removed from the RX FIFO
13 and CDNS_UART_SR_RXEMPTY bit will never get set.
14
15 Avoid the stuck handler by checking first if RX is disabled. port->lock
16 protects against race with RX-disabling functions.
17
18 This HW behavior was mentioned by Nathan Rossi in 43e98facc4a3 ("tty:
19 xuartps: Fix RX hang, and TX corruption in termios call") which fixed a
20 similar issue in cdns_uart_set_termios().
21 The behavior can also be easily verified by e.g. setting
22 CDNS_UART_CR_RX_DIS at the beginning of cdns_uart_handle_rx() - the
23 following loop will then get stuck.
24
25 Resetting the FIFO using RXRST would not set RXEMPTY either so simply
26 issuing a reset after RX-disable would not work.
27
28 I observe this frequently on a ZynqMP board during heavy RX load at 1M
29 baudrate when the reader process exits and thus RX gets disabled.
30
31 Fixes: 61ec9016988f ("tty/serial: add support for Xilinx PS UART")
32 Signed-off-by: Anssi Hannula <anssi.hannula@bitwise.fi>
33 Cc: stable@vger.kernel.org
34 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
35
36 ---
37 drivers/tty/serial/xilinx_uartps.c | 8 +++++++-
38 1 file changed, 7 insertions(+), 1 deletion(-)
39
40 --- a/drivers/tty/serial/xilinx_uartps.c
41 +++ b/drivers/tty/serial/xilinx_uartps.c
42 @@ -362,7 +362,13 @@ static irqreturn_t cdns_uart_isr(int irq
43 cdns_uart_handle_tx(dev_id);
44 isrstatus &= ~CDNS_UART_IXR_TXEMPTY;
45 }
46 - if (isrstatus & CDNS_UART_IXR_RXMASK)
47 +
48 + /*
49 + * Skip RX processing if RX is disabled as RXEMPTY will never be set
50 + * as read bytes will not be removed from the FIFO.
51 + */
52 + if (isrstatus & CDNS_UART_IXR_RXMASK &&
53 + !(readl(port->membase + CDNS_UART_CR) & CDNS_UART_CR_RX_DIS))
54 cdns_uart_handle_rx(dev_id, isrstatus);
55
56 spin_unlock(&port->lock);