Patch "serial: stm32: fix threaded interrupt handling" has been added to the 5.10-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    serial: stm32: fix threaded interrupt handling

to the 5.10-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     serial-stm32-fix-threaded-interrupt-handling.patch
and it can be found in the queue-5.10 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 737a62969d947084aa3355f46df58335bb16c1a2
Author: Johan Hovold <johan@xxxxxxxxxx>
Date:   Fri Apr 16 16:05:56 2021 +0200

    serial: stm32: fix threaded interrupt handling
    
    [ Upstream commit e359b4411c2836cf87c8776682d1b594635570de ]
    
    When DMA is enabled the receive handler runs in a threaded handler, but
    the primary handler up until very recently neither disabled interrupts
    in the device or used IRQF_ONESHOT. This would lead to a deadlock if an
    interrupt comes in while the threaded receive handler is running under
    the port lock.
    
    Commit ad7676812437 ("serial: stm32: fix a deadlock condition with
    wakeup event") claimed to fix an unrelated deadlock, but unfortunately
    also disabled interrupts in the threaded handler. While this prevents
    the deadlock mentioned in the previous paragraph it also defeats the
    purpose of using a threaded handler in the first place.
    
    Fix this by making the interrupt one-shot and not disabling interrupts
    in the threaded handler.
    
    Note that (receive) DMA must not be used for a console port as the
    threaded handler could be interrupted while holding the port lock,
    something which could lead to a deadlock in case an interrupt handler
    ends up calling printk.
    
    Fixes: ad7676812437 ("serial: stm32: fix a deadlock condition with wakeup event")
    Fixes: 3489187204eb ("serial: stm32: adding dma support")
    Cc: stable@xxxxxxxxxxxxxxx      # 4.9
    Cc: Alexandre TORGUE <alexandre.torgue@xxxxxx>
    Cc: Gerald Baeza <gerald.baeza@xxxxxx>
    Reviewed-by: Valentin Caron<valentin.caron@xxxxxxxxxxx>
    Signed-off-by: Johan Hovold <johan@xxxxxxxxxx>
    Link: https://lore.kernel.org/r/20210416140557.25177-3-johan@xxxxxxxxxx
    Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/tty/serial/stm32-usart.c b/drivers/tty/serial/stm32-usart.c
index 2cf9fc915510..844059861f9e 100644
--- a/drivers/tty/serial/stm32-usart.c
+++ b/drivers/tty/serial/stm32-usart.c
@@ -213,14 +213,11 @@ static void stm32_usart_receive_chars(struct uart_port *port, bool threaded)
 	struct tty_port *tport = &port->state->port;
 	struct stm32_port *stm32_port = to_stm32_port(port);
 	const struct stm32_usart_offsets *ofs = &stm32_port->info->ofs;
-	unsigned long c, flags;
+	unsigned long c;
 	u32 sr;
 	char flag;
 
-	if (threaded)
-		spin_lock_irqsave(&port->lock, flags);
-	else
-		spin_lock(&port->lock);
+	spin_lock(&port->lock);
 
 	while (stm32_usart_pending_rx(port, &sr, &stm32_port->last_res,
 				      threaded)) {
@@ -277,10 +274,7 @@ static void stm32_usart_receive_chars(struct uart_port *port, bool threaded)
 		uart_insert_char(port, sr, USART_SR_ORE, c, flag);
 	}
 
-	if (threaded)
-		spin_unlock_irqrestore(&port->lock, flags);
-	else
-		spin_unlock(&port->lock);
+	spin_unlock(&port->lock);
 
 	tty_flip_buffer_push(tport);
 }
@@ -653,7 +647,8 @@ static int stm32_usart_startup(struct uart_port *port)
 
 	ret = request_threaded_irq(port->irq, stm32_usart_interrupt,
 				   stm32_usart_threaded_interrupt,
-				   IRQF_NO_SUSPEND, name, port);
+				   IRQF_ONESHOT | IRQF_NO_SUSPEND,
+				   name, port);
 	if (ret)
 		return ret;
 
@@ -1126,6 +1121,13 @@ static int stm32_usart_of_dma_rx_probe(struct stm32_port *stm32port,
 	struct dma_async_tx_descriptor *desc = NULL;
 	int ret;
 
+	/*
+	 * Using DMA and threaded handler for the console could lead to
+	 * deadlocks.
+	 */
+	if (uart_console(port))
+		return -ENODEV;
+
 	/* Request DMA RX channel */
 	stm32port->rx_ch = dma_request_slave_channel(dev, "rx");
 	if (!stm32port->rx_ch) {



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux