Linux kernel and device drivers for NXP i.MX platforms
 help / color / mirror / Atom feed
* [PATCH v2] serial: imx: Use uart_port_lock_irq() instead of uart_port_lock()
@ 2024-12-10  3:42 Xiaolei Wang
  2024-12-10  9:00 ` Lucas Stach
  2024-12-10 10:37 ` Fabio Estevam
  0 siblings, 2 replies; 4+ messages in thread
From: Xiaolei Wang @ 2024-12-10  3:42 UTC (permalink / raw)
  To: l.stach, gregkh, jirislaby, shawnguo, s.hauer, kernel, festevam,
	esben, marex, ilpo.jarvinen, linux, stefan.eichenberger,
	l.sanfilippo, cniedermaier, rickaran, xiaolei.wang
  Cc: linux-kernel, linux-serial, imx, linux-arm-kernel

When executing 'ehco mem > /sys/power/state', the following
deadlock occurs. Since there is output during the serial
port entering the suspend process, the suspend will be
interrupted, resulting in the nesting of locks. Therefore,
use uart_port_lock_irq() instead of uart_port_unlock().

WARNING: inconsistent lock state
6.12.0-rc2-00002-g3c199ed5bd64-dirty #23 Not tainted
--------------------------------
inconsistent {IN-HARDIRQ-W} -> {HARDIRQ-ON-W} usage.
sh/494 [HC0[0]:SC0[0]:HE1:SE1] takes:
c4db5850 (&port_lock_key){?.-.}-{3:3}, at: imx_uart_enable_wakeup+0x14/0x254
{IN-HARDIRQ-W} state was registered at:
  lock_acquire+0x104/0x348
  _raw_spin_lock+0x48/0x84
  imx_uart_int+0x14/0x4dc
  __handle_irq_event_percpu+0xac/0x2fc
  handle_irq_event_percpu+0xc/0x40
  handle_irq_event+0x38/0x8c
  handle_fasteoi_irq+0xb4/0x1b8
  handle_irq_desc+0x1c/0x2c
  gic_handle_irq+0x6c/0xa0
  generic_handle_arch_irq+0x2c/0x64
  call_with_stack+0x18/0x20
  __irq_svc+0x9c/0xbc
  _raw_spin_unlock_irqrestore+0x2c/0x48
  uart_write+0xd8/0x3a0
  do_output_char+0x1a8/0x1e4
  n_tty_write+0x224/0x440
  file_tty_write.constprop.0+0x124/0x250
  do_iter_readv_writev+0x100/0x1e0
  vfs_writev+0xc4/0x448
  do_writev+0x68/0xf8
  ret_fast_syscall+0x0/0x1c
irq event stamp: 31593
hardirqs last  enabled at (31593): [<c1150e48>] _raw_spin_unlock_irqrestore+0x44/0x48
hardirqs last disabled at (31592): [<c07f32f0>] clk_enable_lock+0x60/0x120
softirqs last  enabled at (30334): [<c012d1d4>] handle_softirqs+0x2cc/0x478
softirqs last disabled at (30325): [<c012d510>] __irq_exit_rcu+0x120/0x15c

other info that might help us debug this:
 Possible unsafe locking scenario:

       CPU0
       ----
  lock(&port_lock_key);
  <Interrupt>
    lock(&port_lock_key);

Fixes: 3c199ed5bd64 ("serial: imx: Grab port lock in imx_uart_enable_wakeup()")
Signed-off-by: Xiaolei Wang <xiaolei.wang@windriver.com>
---

v1:
  https://patchwork.kernel.org/project/linux-arm-kernel/patch/20241209124732.693834-1-xiaolei.wang@windriver.com/
v2:
  use uart_port_lock_irq() instead of uart_port_lock_irqsave()

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

diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
index 17f70e4bee43..9c59ec128bb4 100644
--- a/drivers/tty/serial/imx.c
+++ b/drivers/tty/serial/imx.c
@@ -2692,7 +2692,7 @@ static void imx_uart_enable_wakeup(struct imx_port *sport, bool on)
 {
 	u32 ucr3;
 
-	uart_port_lock(&sport->port);
+	uart_port_lock_irq(&sport->port);
 
 	ucr3 = imx_uart_readl(sport, UCR3);
 	if (on) {
@@ -2714,7 +2714,7 @@ static void imx_uart_enable_wakeup(struct imx_port *sport, bool on)
 		imx_uart_writel(sport, ucr1, UCR1);
 	}
 
-	uart_port_unlock(&sport->port);
+	uart_port_unlock_irq(&sport->port);
 }
 
 static int imx_uart_suspend_noirq(struct device *dev)
-- 
2.25.1


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

* Re: [PATCH v2] serial: imx: Use uart_port_lock_irq() instead of uart_port_lock()
  2024-12-10  3:42 [PATCH v2] serial: imx: Use uart_port_lock_irq() instead of uart_port_lock() Xiaolei Wang
@ 2024-12-10  9:00 ` Lucas Stach
  2024-12-10 10:37 ` Fabio Estevam
  1 sibling, 0 replies; 4+ messages in thread
From: Lucas Stach @ 2024-12-10  9:00 UTC (permalink / raw)
  To: Xiaolei Wang, gregkh, jirislaby, shawnguo, s.hauer, kernel,
	festevam, esben, marex, ilpo.jarvinen, linux, stefan.eichenberger,
	l.sanfilippo, cniedermaier, rickaran
  Cc: linux-kernel, linux-serial, imx, linux-arm-kernel

Am Dienstag, dem 10.12.2024 um 11:42 +0800 schrieb Xiaolei Wang:
> When executing 'ehco mem > /sys/power/state', the following
> deadlock occurs. Since there is output during the serial
> port entering the suspend process, the suspend will be
> interrupted, resulting in the nesting of locks. Therefore,
> use uart_port_lock_irq() instead of uart_port_unlock().
> 
> WARNING: inconsistent lock state
> 6.12.0-rc2-00002-g3c199ed5bd64-dirty #23 Not tainted
> --------------------------------
> inconsistent {IN-HARDIRQ-W} -> {HARDIRQ-ON-W} usage.
> sh/494 [HC0[0]:SC0[0]:HE1:SE1] takes:
> c4db5850 (&port_lock_key){?.-.}-{3:3}, at: imx_uart_enable_wakeup+0x14/0x254
> {IN-HARDIRQ-W} state was registered at:
>   lock_acquire+0x104/0x348
>   _raw_spin_lock+0x48/0x84
>   imx_uart_int+0x14/0x4dc
>   __handle_irq_event_percpu+0xac/0x2fc
>   handle_irq_event_percpu+0xc/0x40
>   handle_irq_event+0x38/0x8c
>   handle_fasteoi_irq+0xb4/0x1b8
>   handle_irq_desc+0x1c/0x2c
>   gic_handle_irq+0x6c/0xa0
>   generic_handle_arch_irq+0x2c/0x64
>   call_with_stack+0x18/0x20
>   __irq_svc+0x9c/0xbc
>   _raw_spin_unlock_irqrestore+0x2c/0x48
>   uart_write+0xd8/0x3a0
>   do_output_char+0x1a8/0x1e4
>   n_tty_write+0x224/0x440
>   file_tty_write.constprop.0+0x124/0x250
>   do_iter_readv_writev+0x100/0x1e0
>   vfs_writev+0xc4/0x448
>   do_writev+0x68/0xf8
>   ret_fast_syscall+0x0/0x1c
> irq event stamp: 31593
> hardirqs last  enabled at (31593): [<c1150e48>] _raw_spin_unlock_irqrestore+0x44/0x48
> hardirqs last disabled at (31592): [<c07f32f0>] clk_enable_lock+0x60/0x120
> softirqs last  enabled at (30334): [<c012d1d4>] handle_softirqs+0x2cc/0x478
> softirqs last disabled at (30325): [<c012d510>] __irq_exit_rcu+0x120/0x15c
> 
> other info that might help us debug this:
>  Possible unsafe locking scenario:
> 
>        CPU0
>        ----
>   lock(&port_lock_key);
>   <Interrupt>
>     lock(&port_lock_key);
> 
> Fixes: 3c199ed5bd64 ("serial: imx: Grab port lock in imx_uart_enable_wakeup()")
> Signed-off-by: Xiaolei Wang <xiaolei.wang@windriver.com>

Reviewed-by: Lucas Stach <l.stach@pengutronix.de>

> ---
> 
> v1:
>   https://patchwork.kernel.org/project/linux-arm-kernel/patch/20241209124732.693834-1-xiaolei.wang@windriver.com/
> v2:
>   use uart_port_lock_irq() instead of uart_port_lock_irqsave()
> 
>  drivers/tty/serial/imx.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
> index 17f70e4bee43..9c59ec128bb4 100644
> --- a/drivers/tty/serial/imx.c
> +++ b/drivers/tty/serial/imx.c
> @@ -2692,7 +2692,7 @@ static void imx_uart_enable_wakeup(struct imx_port *sport, bool on)
>  {
>  	u32 ucr3;
>  
> -	uart_port_lock(&sport->port);
> +	uart_port_lock_irq(&sport->port);
>  
>  	ucr3 = imx_uart_readl(sport, UCR3);
>  	if (on) {
> @@ -2714,7 +2714,7 @@ static void imx_uart_enable_wakeup(struct imx_port *sport, bool on)
>  		imx_uart_writel(sport, ucr1, UCR1);
>  	}
>  
> -	uart_port_unlock(&sport->port);
> +	uart_port_unlock_irq(&sport->port);
>  }
>  
>  static int imx_uart_suspend_noirq(struct device *dev)


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

* Re: [PATCH v2] serial: imx: Use uart_port_lock_irq() instead of uart_port_lock()
  2024-12-10  3:42 [PATCH v2] serial: imx: Use uart_port_lock_irq() instead of uart_port_lock() Xiaolei Wang
  2024-12-10  9:00 ` Lucas Stach
@ 2024-12-10 10:37 ` Fabio Estevam
  2024-12-10 15:40   ` wang xiaolei
  1 sibling, 1 reply; 4+ messages in thread
From: Fabio Estevam @ 2024-12-10 10:37 UTC (permalink / raw)
  To: Xiaolei Wang
  Cc: l.stach, gregkh, jirislaby, shawnguo, s.hauer, kernel, esben,
	marex, ilpo.jarvinen, linux, stefan.eichenberger, l.sanfilippo,
	cniedermaier, rickaran, linux-kernel, linux-serial, imx,
	linux-arm-kernel

On Tue, Dec 10, 2024 at 12:43 AM Xiaolei Wang
<xiaolei.wang@windriver.com> wrote:
>
> When executing 'ehco mem > /sys/power/state', the following

ehco --> echo

Reviewed-by: Fabio Estevam <festevam@gmail.com>

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

* Re: [PATCH v2] serial: imx: Use uart_port_lock_irq() instead of uart_port_lock()
  2024-12-10 10:37 ` Fabio Estevam
@ 2024-12-10 15:40   ` wang xiaolei
  0 siblings, 0 replies; 4+ messages in thread
From: wang xiaolei @ 2024-12-10 15:40 UTC (permalink / raw)
  To: Fabio Estevam
  Cc: l.stach, gregkh, jirislaby, shawnguo, s.hauer, kernel, esben,
	marex, ilpo.jarvinen, linux, stefan.eichenberger, l.sanfilippo,
	cniedermaier, rickaran, linux-kernel, linux-serial, imx,
	linux-arm-kernel


On 12/10/24 9:37 PM, Fabio Estevam wrote:
> CAUTION: This email comes from a non Wind River email account!
> Do not click links or open attachments unless you recognize the sender and know the content is safe.
>
> On Tue, Dec 10, 2024 at 12:43 AM Xiaolei Wang
> <xiaolei.wang@windriver.com> wrote:
>> When executing 'ehco mem > /sys/power/state', the following
> ehco --> echo

Thanks, I will update the commit log in the next version


thanks

xiaolei

>
> Reviewed-by: Fabio Estevam <festevam@gmail.com>

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

end of thread, other threads:[~2024-12-10 15:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-10  3:42 [PATCH v2] serial: imx: Use uart_port_lock_irq() instead of uart_port_lock() Xiaolei Wang
2024-12-10  9:00 ` Lucas Stach
2024-12-10 10:37 ` Fabio Estevam
2024-12-10 15:40   ` wang xiaolei

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