From: Andy Duan <fugang.duan@nxp.com>
To: "gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>
Cc: "linux-serial@vger.kernel.org" <linux-serial@vger.kernel.org>,
"jslaby@suse.com" <jslaby@suse.com>,
Andy Duan <fugang.duan@nxp.com>,
"u.kleine-koenig@pengutronix.de" <u.kleine-koenig@pengutronix.de>,
"festevam@gmail.com" <festevam@gmail.com>
Subject: [PATCH tty/serial 1/1] tty: serial: imx: fix sysrq lockdep issue
Date: Fri, 22 Nov 2019 10:00:53 +0000 [thread overview]
Message-ID: <1574416632-32321-1-git-send-email-fugang.duan@nxp.com> (raw)
From: Fugang Duan <fugang.duan@nxp.com>
commit dbdda842fe96 ("printk: Add console owner and waiter logic to
load balance console writes") introduces the lockdep issue for imx
serial driver in sysrq case:
CPU0 CPU1
---- ----
lock(&port_lock_key);
lock(console_owner);
lock(&port_lock_key);
lock(console_owner);
It should unlock port_lock_key in handle_sysrq().
lockdep splats:
======================================================
WARNING: possible circular locking dependency detected
------------------------------------------------------
swapper/0/0 is trying to acquire lock:
c141e540 (console_owner){-...}, at: console_unlock+0x180/0x5e4
but task is already holding lock:
d864e450 (&port_lock_key){-.-.}, at: imx_uart_rxint+0x18/0x294
which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #1 (&port_lock_key){-.-.}:
imx_uart_console_write+0x1b4/0x1dc
console_unlock+0x2a4/0x5e4
register_console+0x1ec/0x3b4
uart_add_one_port+0x480/0x4e8
platform_drv_probe+0x48/0x98
really_probe+0x1d8/0x34c
driver_probe_device+0x5c/0x168
device_driver_attach+0x58/0x60
__driver_attach+0x58/0xd0
bus_for_each_dev+0x74/0xbc
bus_add_driver+0x150/0x1dc
driver_register+0x74/0x108
imx_uart_init+0x20/0x40
do_one_initcall+0x84/0x348
kernel_init_freeable+0x11c/0x1e0
kernel_init+0x8/0x110
ret_from_fork+0x14/0x20
0x0
-> #0 (console_owner){-...}:
lock_acquire+0xcc/0x204
console_unlock+0x208/0x5e4
vprintk_emit+0x108/0x2c8
vprintk_default+0x20/0x28
printk+0x2c/0x58
__handle_sysrq+0x178/0x1f0
imx_uart_rxint+0x234/0x294
imx_uart_int+0x210/0x2f0
__handle_irq_event_percpu+0x48/0x34c
handle_irq_event_percpu+0x2c/0x88
handle_irq_event+0x38/0x5c
handle_fasteoi_irq+0xc8/0x180
generic_handle_irq+0x20/0x34
__handle_domain_irq+0x64/0xdc
gic_handle_irq+0x48/0x9c
__irq_svc+0x70/0x98
cpuidle_enter_state+0x16c/0x520
cpuidle_enter_state+0x16c/0x520
cpuidle_enter+0x28/0x38
do_idle+0x1dc/0x2b0
cpu_startup_entry+0x18/0x1c
start_kernel+0x404/0x4cc
other info that might help us debug this:
Possible unsafe locking scenario:
CPU0 CPU1
---- ----
lock(&port_lock_key);
lock(console_owner);
lock(&port_lock_key);
lock(console_owner);
*** DEADLOCK ***
3 locks held by swapper/0/0:
#0: d864e450 (&port_lock_key){-.-.}, at: imx_uart_rxint+0x18/0x294
#1: c141eb88 (rcu_read_lock){....}, at: __handle_sysrq+0x0/0x1f0
#2: c141e4c0 (console_lock){+.+.}, at: vprintk_emit+0xfc/0x2c8
stack backtrace:
CPU: 0 PID: 0 Comm: swapper/0 Tainted: G W
Hardware name: Freescale i.MX6 Quad/DualLite (Device Tree)
[<c0112e30>] (unwind_backtrace) from [<c010cdc0>] (show_stack+0x10/0x14)
[<c010cdc0>] (show_stack) from [<c0d2a73c>] (dump_stack+0xe0/0x114)
[<c0d2a73c>] (dump_stack) from [<c018f744>] (check_noncircular+0x138/0x1ec)
[<c018f744>] (check_noncircular) from [<c0191730>] (__lock_acquire+0xe00/0x2418)
[<c0191730>] (__lock_acquire) from [<c01935c0>] (lock_acquire+0xcc/0x204)
[<c01935c0>] (lock_acquire) from [<c019e41c>] (console_unlock+0x208/0x5e4)
[<c019e41c>] (console_unlock) from [<c019fd38>] (vprintk_emit+0x108/0x2c8)
[<c019fd38>] (vprintk_emit) from [<c019ff18>] (vprintk_default+0x20/0x28)
[<c019ff18>] (vprintk_default) from [<c01a04e0>] (printk+0x2c/0x58)
[<c01a04e0>] (printk) from [<c061e990>] (__handle_sysrq+0x178/0x1f0)
[<c061e990>] (__handle_sysrq) from [<c0635cb0>] (imx_uart_rxint+0x234/0x294)
[<c0635cb0>] (imx_uart_rxint) from [<c06376a8>] (imx_uart_int+0x210/0x2f0)
[<c06376a8>] (imx_uart_int) from [<c01a1cdc>] (__handle_irq_event_percpu+0x48/0x34c)
[<c01a1cdc>] (__handle_irq_event_percpu) from [<c01a200c>] (handle_irq_event_percpu+0x2c/0x88)
[<c01a200c>] (handle_irq_event_percpu) from [<c01a20a0>] (handle_irq_event+0x38/0x5c)
[<c01a20a0>] (handle_irq_event) from [<c01a6930>] (handle_fasteoi_irq+0xc8/0x180)
[<c01a6930>] (handle_fasteoi_irq) from [<c01a0e10>] (generic_handle_irq+0x20/0x34)
[<c01a0e10>] (generic_handle_irq) from [<c01a1418>] (__handle_domain_irq+0x64/0xdc)
[<c01a1418>] (__handle_domain_irq) from [<c054bcd0>] (gic_handle_irq+0x48/0x9c)
[<c054bcd0>] (gic_handle_irq) from [<c0101a70>] (__irq_svc+0x70/0x98)
Exception stack(0xc1401ed8 to 0xc1401f20)
1ec0: 00000001 00000006
1ee0: 00000000 c140c600 00000001 5b0881e8 c140f934 db6eadb8 c1504668 0000098b
1f00: 0000098b 5c28eb3d 00000000 c1401f28 c0194520 c0938fcc 20070013 ffffffff
[<c0101a70>] (__irq_svc) from [<c0938fcc>] (cpuidle_enter_state+0x16c/0x520)
[<c0938fcc>] (cpuidle_enter_state) from [<c09393bc>] (cpuidle_enter+0x28/0x38)
[<c09393bc>] (cpuidle_enter) from [<c016f6a4>] (do_idle+0x1dc/0x2b0)
[<c016f6a4>] (do_idle) from [<c016fb2c>] (cpu_startup_entry+0x18/0x1c)
[<c016fb2c>] (cpu_startup_entry) from [<c1300e20>] (start_kernel+0x404/0x4cc)
Signed-off-by: Fugang Duan <fugang.duan@nxp.com>
---
drivers/tty/serial/imx.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
index a9e20e6..a665439 100644
--- a/drivers/tty/serial/imx.c
+++ b/drivers/tty/serial/imx.c
@@ -736,6 +736,7 @@ static irqreturn_t imx_uart_rxint(int irq, void *dev_id)
while (imx_uart_readl(sport, USR2) & USR2_RDR) {
u32 usr2;
+ int sysrq;
flg = TTY_NORMAL;
sport->port.icount.rx++;
@@ -749,7 +750,11 @@ static irqreturn_t imx_uart_rxint(int irq, void *dev_id)
continue;
}
- if (uart_handle_sysrq_char(&sport->port, (unsigned char)rx))
+ spin_unlock(&sport->port.lock);
+ sysrq = uart_handle_sysrq_char(&sport->port, (unsigned char)rx);
+ spin_lock(&sport->port.lock);
+
+ if (sysrq)
continue;
if (unlikely(rx & URXD_ERR)) {
--
2.7.4
next reply other threads:[~2019-11-22 10:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-22 10:00 Andy Duan [this message]
2019-11-22 10:33 ` [PATCH tty/serial 1/1] tty: serial: imx: fix sysrq lockdep issue Uwe Kleine-König
2019-11-25 1:23 ` [EXT] " Andy Duan
2019-11-26 9:53 ` Petr Mladek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1574416632-32321-1-git-send-email-fugang.duan@nxp.com \
--to=fugang.duan@nxp.com \
--cc=festevam@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=jslaby@suse.com \
--cc=linux-serial@vger.kernel.org \
--cc=u.kleine-koenig@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox