public inbox for linux-serial@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] serial: imx: Fix sysrq deadlock
@ 2021-09-29 21:43 Fabio Estevam
  2021-09-30  7:02 ` Uwe Kleine-König
  2021-09-30  7:54 ` Johan Hovold
  0 siblings, 2 replies; 7+ messages in thread
From: Fabio Estevam @ 2021-09-29 21:43 UTC (permalink / raw)
  To: gregkh; +Cc: michael, linux-serial, johan, marex, Fabio Estevam

The following sysrq command causes the following deadlock:

 # echo t > /proc/sysrq-trigger
 ....
[   20.325246] ======================================================
[   20.325252] WARNING: possible circular locking dependency detected
[   20.325260] 5.15.0-rc2-next-20210924-00004-gd2d6e664f29f-dirty #163
Not tainted
[   20.325273] ------------------------------------------------------
[   20.325279] sh/236 is trying to acquire lock:
[   20.325293] c1618614 (console_owner){-...}-{0:0}, at:
console_unlock+0x180/0x5bc
[   20.325361]
[   20.325361] but task is already holding lock:
[   20.325368] eefccc90 (&pool->lock){-.-.}-{2:2}, at:
show_workqueue_state+0x104/0x3c8
[   20.325432]
[   20.325432] which lock already depends on the new lock.

...

[   20.325657] -> #2 (&pool->lock/1){-.-.}-{2:2}:
[   20.325690]        __queue_work+0x114/0x810
[   20.325710]        queue_work_on+0x54/0x94
[   20.325727]        __imx_uart_rxint.constprop.0+0x1b4/0x2e0
[   20.325760]        imx_uart_int+0x270/0x310

This problem happens because uart_handle_sysrq_char() is called
with the lock held.

Fix this by using the same approach done in commit 5697df7322fe ("serial:
fsl_lpuart: split sysrq handling"), which calls 
uart_unlock_and_check_sysrq() to drop the lock prior to 
uart_handle_sysrq_char().

Signed-off-by: Fabio Estevam <festevam@denx.de>
---
Changes since v1:
- I noticed that when sending break + t via the terminal, the characters
were sometimes lost. Do the minimal changes to fix the deadlock without
missing the sysrq input.

 drivers/tty/serial/imx.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
index 8b121cd869e9..1c768dd3896d 100644
--- a/drivers/tty/serial/imx.c
+++ b/drivers/tty/serial/imx.c
@@ -788,6 +788,7 @@ static irqreturn_t __imx_uart_rxint(int irq, void *dev_id)
 	unsigned int rx, flg, ignored = 0;
 	struct tty_port *port = &sport->port.state->port;
 
+	uart_unlock_and_check_sysrq(&sport->port);
 	while (imx_uart_readl(sport, USR2) & USR2_RDR) {
 		u32 usr2;
 
@@ -846,6 +847,7 @@ static irqreturn_t __imx_uart_rxint(int irq, void *dev_id)
 out:
 	tty_flip_buffer_push(port);
 
+	spin_lock(&sport->port.lock);
 	return IRQ_HANDLED;
 }
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-10-01 13:48 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-09-29 21:43 [PATCH v2] serial: imx: Fix sysrq deadlock Fabio Estevam
2021-09-30  7:02 ` Uwe Kleine-König
2021-09-30  7:54 ` Johan Hovold
2021-09-30 13:45   ` Fabio Estevam
2021-10-01  7:52     ` Johan Hovold
2021-10-01 10:17       ` Fabio Estevam
2021-10-01 13:48         ` Johan Hovold

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox