2024-04-01 10:19:50

by [email protected]

[permalink] [raw]
Subject: [PATCH] tty: serial: fixed uart irq maybe cause irq storm

From: "Gary Feng" <[email protected]>

if not disable uart irq before disable clk, uart irq maybe triggered after
disabled clk immediately, then maybe cause irq storm.

Reproduced the below call trace, see i2c not be connected, but irq storm
was triggered.

i2c_designware 30b70000.i2c: controller timed out
CPU: 2 PID: 2932 Comm: [email protected]
Tainted: G O 5.14.61-00094-geaa0149416cc-dirty #8
Hardware name: Semidrive kunlun x9 REF Board (DT)
Call trace:
[<ffff00000808a3cc>] dump_backtrace+0x0/0x3c0
[<ffff00000808a7a0>] show_stack+0x14/0x1c
[<ffff000008cef43c>] dump_stack+0xc4/0xfc
[<ffff00000814eb80>] __report_bad_irq+0x50/0xe0
[<ffff00000814eaec>] note_interrupt+0x248/0x28c
[<ffff00000814c0e8>] handle_irq_event+0x78/0xa4
[<ffff00000814fcb8>] handle_fasteoi_irq+0xe4/0x1b4
[<ffff00000814b060>] __handle_domain_irq+0x7c/0xbc
[<ffff00000808176c>] gic_handle_irq+0x4c/0xb8
[<ffff000008083230>] el1_irq+0xb0/0x124
[<ffff000008d09f5c>] _raw_spin_unlock_irqrestore+0x10/0x44
[<ffff00000865b784>] dw8250_set_termios+0x48/0xf4
[<ffff0000086545a4>] serial8250_set_termios+0x14/0x28
[<ffff00000864c4f4>] uart_change_speed+0x38/0x10c
[<ffff00000864e458>] uart_set_termios+0xd0/0x17c
[<ffff000008630ad4>] tty_set_termios+0x160/0x1e4
[<ffff00000863165c>] set_termios+0x32c/0x3bc
[<ffff000008631248>] tty_mode_ioctl+0x6f0/0x7d8
[<ffff000008631a6c>] n_tty_ioctl_helper+0x10c/0x1e8
[<ffff00000862d2c4>] n_tty_ioctl+0x120/0x194
[<ffff00000862a724>] tty_ioctl+0x658/0xa34
[<ffff0000082a8f40>] do_vfs_ioctl+0x554/0x810
[<ffff0000082a9368>] SyS_ioctl+0x88/0x94
Exception stack(0xffff00000ccf3ec0 to 0xffff00000ccf4000

Signed-off-by: chunguo.feng <[email protected]>
---
drivers/tty/serial/8250/8250_dw.c | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/drivers/tty/serial/8250/8250_dw.c b/drivers/tty/serial/8250/8250_dw.c
index c1d43f0..133c24e 100644
--- a/drivers/tty/serial/8250/8250_dw.c
+++ b/drivers/tty/serial/8250/8250_dw.c
@@ -359,6 +359,12 @@ static void dw8250_set_termios(struct uart_port *p, struct ktermios *termios,

rate = clk_round_rate(d->clk, newrate);
if (rate > 0 && p->uartclk != rate) {
+ /*Need disable uart irq before disabled clk, because uart irq maybe triggered after
+ * disabled clk immediately, then cause irq storm.
+ */
+ if (p->irq)
+ disabled_irq(p->irq);
+
clk_disable_unprepare(d->clk);
/*
* Note that any clock-notifer worker will block in
@@ -368,6 +374,9 @@ static void dw8250_set_termios(struct uart_port *p, struct ktermios *termios,
if (!ret)
p->uartclk = rate;
clk_prepare_enable(d->clk);
+
+ if (p->irq)
+ enable_irq(p->irq);
}

dw8250_do_set_termios(p, termios, old);
--
2.7.4



2024-04-01 10:32:48

by Greg KH

[permalink] [raw]
Subject: Re: [PATCH] tty: serial: fixed uart irq maybe cause irq storm

On Mon, Apr 01, 2024 at 06:19:06PM +0800, [email protected] wrote:
> From: "Gary Feng" <[email protected]>
>
> if not disable uart irq before disable clk, uart irq maybe triggered after
> disabled clk immediately, then maybe cause irq storm.
>
> Reproduced the below call trace, see i2c not be connected, but irq storm
> was triggered.
>
> i2c_designware 30b70000.i2c: controller timed out
> CPU: 2 PID: 2932 Comm: [email protected]
> Tainted: G O 5.14.61-00094-geaa0149416cc-dirty #8
> Hardware name: Semidrive kunlun x9 REF Board (DT)
> Call trace:
> [<ffff00000808a3cc>] dump_backtrace+0x0/0x3c0
> [<ffff00000808a7a0>] show_stack+0x14/0x1c
> [<ffff000008cef43c>] dump_stack+0xc4/0xfc
> [<ffff00000814eb80>] __report_bad_irq+0x50/0xe0
> [<ffff00000814eaec>] note_interrupt+0x248/0x28c
> [<ffff00000814c0e8>] handle_irq_event+0x78/0xa4
> [<ffff00000814fcb8>] handle_fasteoi_irq+0xe4/0x1b4
> [<ffff00000814b060>] __handle_domain_irq+0x7c/0xbc
> [<ffff00000808176c>] gic_handle_irq+0x4c/0xb8
> [<ffff000008083230>] el1_irq+0xb0/0x124
> [<ffff000008d09f5c>] _raw_spin_unlock_irqrestore+0x10/0x44
> [<ffff00000865b784>] dw8250_set_termios+0x48/0xf4
> [<ffff0000086545a4>] serial8250_set_termios+0x14/0x28
> [<ffff00000864c4f4>] uart_change_speed+0x38/0x10c
> [<ffff00000864e458>] uart_set_termios+0xd0/0x17c
> [<ffff000008630ad4>] tty_set_termios+0x160/0x1e4
> [<ffff00000863165c>] set_termios+0x32c/0x3bc
> [<ffff000008631248>] tty_mode_ioctl+0x6f0/0x7d8
> [<ffff000008631a6c>] n_tty_ioctl_helper+0x10c/0x1e8
> [<ffff00000862d2c4>] n_tty_ioctl+0x120/0x194
> [<ffff00000862a724>] tty_ioctl+0x658/0xa34
> [<ffff0000082a8f40>] do_vfs_ioctl+0x554/0x810
> [<ffff0000082a9368>] SyS_ioctl+0x88/0x94
> Exception stack(0xffff00000ccf3ec0 to 0xffff00000ccf4000
>
> Signed-off-by: chunguo.feng <[email protected]>
> ---
> drivers/tty/serial/8250/8250_dw.c | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/drivers/tty/serial/8250/8250_dw.c b/drivers/tty/serial/8250/8250_dw.c
> index c1d43f0..133c24e 100644
> --- a/drivers/tty/serial/8250/8250_dw.c
> +++ b/drivers/tty/serial/8250/8250_dw.c
> @@ -359,6 +359,12 @@ static void dw8250_set_termios(struct uart_port *p, struct ktermios *termios,
>
> rate = clk_round_rate(d->clk, newrate);
> if (rate > 0 && p->uartclk != rate) {
> + /*Need disable uart irq before disabled clk, because uart irq maybe triggered after
> + * disabled clk immediately, then cause irq storm.
> + */
> + if (p->irq)
> + disabled_irq(p->irq);
> +
> clk_disable_unprepare(d->clk);
> /*
> * Note that any clock-notifer worker will block in
> @@ -368,6 +374,9 @@ static void dw8250_set_termios(struct uart_port *p, struct ktermios *termios,
> if (!ret)
> p->uartclk = rate;
> clk_prepare_enable(d->clk);
> +
> + if (p->irq)
> + enable_irq(p->irq);
> }
>
> dw8250_do_set_termios(p, termios, old);
> --
> 2.7.4
>

Hi,

This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him
a patch that has triggered this response. He used to manually respond
to these common problems, but in order to save his sanity (he kept
writing the same thing over and over, yet to different people), I was
created. Hopefully you will not take offence and will fix the problem
in your patch and resubmit it so that it can be accepted into the Linux
kernel tree.

You are receiving this message because of the following common error(s)
as indicated below:

- This looks like a new version of a previously submitted patch, but you
did not list below the --- line any changes from the previous version.
Please read the section entitled "The canonical patch format" in the
kernel file, Documentation/process/submitting-patches.rst for what
needs to be done here to properly describe this.

If you wish to discuss this problem further, or you have questions about
how to resolve this issue, please feel free to respond to this email and
Greg will reply once he has dug out from the pending patches received
from other developers.

thanks,

greg k-h's patch email bot

2024-04-02 11:45:41

by Ilpo Järvinen

[permalink] [raw]
Subject: Re: [PATCH] tty: serial: fixed uart irq maybe cause irq storm

On Mon, 1 Apr 2024, [email protected] wrote:

> From: "Gary Feng" <[email protected]>
>
> if not disable uart irq before disable clk, uart irq maybe triggered after
> disabled clk immediately, then maybe cause irq storm.
>
> Reproduced the below call trace, see i2c not be connected, but irq storm
> was triggered.

This doesn't really explain what's going on here. Why is the irq being
triggered? You even seem to imply that nothing is connected so what
triggers is triggering that irq? Can we selectively disable only that
part, if it's e.g. empty tx condition or something?

> i2c_designware 30b70000.i2c: controller timed out
> CPU: 2 PID: 2932 Comm: [email protected]
> Tainted: G O 5.14.61-00094-geaa0149416cc-dirty #8
> Hardware name: Semidrive kunlun x9 REF Board (DT)
> Call trace:
> [<ffff00000808a3cc>] dump_backtrace+0x0/0x3c0
> [<ffff00000808a7a0>] show_stack+0x14/0x1c
> [<ffff000008cef43c>] dump_stack+0xc4/0xfc
> [<ffff00000814eb80>] __report_bad_irq+0x50/0xe0
> [<ffff00000814eaec>] note_interrupt+0x248/0x28c
> [<ffff00000814c0e8>] handle_irq_event+0x78/0xa4
> [<ffff00000814fcb8>] handle_fasteoi_irq+0xe4/0x1b4
> [<ffff00000814b060>] __handle_domain_irq+0x7c/0xbc
> [<ffff00000808176c>] gic_handle_irq+0x4c/0xb8
> [<ffff000008083230>] el1_irq+0xb0/0x124
> [<ffff000008d09f5c>] _raw_spin_unlock_irqrestore+0x10/0x44
> [<ffff00000865b784>] dw8250_set_termios+0x48/0xf4
> [<ffff0000086545a4>] serial8250_set_termios+0x14/0x28
> [<ffff00000864c4f4>] uart_change_speed+0x38/0x10c
> [<ffff00000864e458>] uart_set_termios+0xd0/0x17c
> [<ffff000008630ad4>] tty_set_termios+0x160/0x1e4
> [<ffff00000863165c>] set_termios+0x32c/0x3bc
> [<ffff000008631248>] tty_mode_ioctl+0x6f0/0x7d8
> [<ffff000008631a6c>] n_tty_ioctl_helper+0x10c/0x1e8
> [<ffff00000862d2c4>] n_tty_ioctl+0x120/0x194
> [<ffff00000862a724>] tty_ioctl+0x658/0xa34
> [<ffff0000082a8f40>] do_vfs_ioctl+0x554/0x810
> [<ffff0000082a9368>] SyS_ioctl+0x88/0x94
> Exception stack(0xffff00000ccf3ec0 to 0xffff00000ccf4000
>
> Signed-off-by: chunguo.feng <[email protected]>

Use your real name on signed-off line too. On From line you seem to
provide different name as here.

--
i.

> ---
> drivers/tty/serial/8250/8250_dw.c | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/drivers/tty/serial/8250/8250_dw.c b/drivers/tty/serial/8250/8250_dw.c
> index c1d43f0..133c24e 100644
> --- a/drivers/tty/serial/8250/8250_dw.c
> +++ b/drivers/tty/serial/8250/8250_dw.c
> @@ -359,6 +359,12 @@ static void dw8250_set_termios(struct uart_port *p, struct ktermios *termios,
>
> rate = clk_round_rate(d->clk, newrate);
> if (rate > 0 && p->uartclk != rate) {
> + /*Need disable uart irq before disabled clk, because uart irq maybe triggered after
> + * disabled clk immediately, then cause irq storm.
> + */
> + if (p->irq)
> + disabled_irq(p->irq);
> +
> clk_disable_unprepare(d->clk);
> /*
> * Note that any clock-notifer worker will block in
> @@ -368,6 +374,9 @@ static void dw8250_set_termios(struct uart_port *p, struct ktermios *termios,
> if (!ret)
> p->uartclk = rate;
> clk_prepare_enable(d->clk);
> +
> + if (p->irq)
> + enable_irq(p->irq);
> }
>
> dw8250_do_set_termios(p, termios, old);
>

2024-04-02 14:28:00

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH] tty: serial: fixed uart irq maybe cause irq storm

On Mon, Apr 01, 2024 at 06:19:06PM +0800, [email protected] wrote:
> From: "Gary Feng" <[email protected]>
>
> if not disable uart irq before disable clk, uart irq maybe triggered after
> disabled clk immediately, then maybe cause irq storm.
>
> Reproduced the below call trace, see i2c not be connected, but irq storm
> was triggered.

> i2c_designware 30b70000.i2c: controller timed out
> CPU: 2 PID: 2932 Comm: [email protected]
> Tainted: G O 5.14.61-00094-geaa0149416cc-dirty #8
> Hardware name: Semidrive kunlun x9 REF Board (DT)
> Call trace:
> [<ffff00000808a3cc>] dump_backtrace+0x0/0x3c0
> [<ffff00000808a7a0>] show_stack+0x14/0x1c
> [<ffff000008cef43c>] dump_stack+0xc4/0xfc
> [<ffff00000814eb80>] __report_bad_irq+0x50/0xe0
> [<ffff00000814eaec>] note_interrupt+0x248/0x28c
> [<ffff00000814c0e8>] handle_irq_event+0x78/0xa4
> [<ffff00000814fcb8>] handle_fasteoi_irq+0xe4/0x1b4
> [<ffff00000814b060>] __handle_domain_irq+0x7c/0xbc
> [<ffff00000808176c>] gic_handle_irq+0x4c/0xb8
> [<ffff000008083230>] el1_irq+0xb0/0x124
> [<ffff000008d09f5c>] _raw_spin_unlock_irqrestore+0x10/0x44
> [<ffff00000865b784>] dw8250_set_termios+0x48/0xf4
> [<ffff0000086545a4>] serial8250_set_termios+0x14/0x28
> [<ffff00000864c4f4>] uart_change_speed+0x38/0x10c
> [<ffff00000864e458>] uart_set_termios+0xd0/0x17c
> [<ffff000008630ad4>] tty_set_termios+0x160/0x1e4
> [<ffff00000863165c>] set_termios+0x32c/0x3bc
> [<ffff000008631248>] tty_mode_ioctl+0x6f0/0x7d8
> [<ffff000008631a6c>] n_tty_ioctl_helper+0x10c/0x1e8
> [<ffff00000862d2c4>] n_tty_ioctl+0x120/0x194
> [<ffff00000862a724>] tty_ioctl+0x658/0xa34
> [<ffff0000082a8f40>] do_vfs_ioctl+0x554/0x810
> [<ffff0000082a9368>] SyS_ioctl+0x88/0x94
> Exception stack(0xffff00000ccf3ec0 to 0xffff00000ccf4000

Please read
https://www.kernel.org/doc/html/latest/process/submitting-patches.html#backtraces-in-commit-messages
and update the commit message accordingly.

..

> + /*Need disable uart irq before disabled clk, because uart irq maybe triggered after
> + * disabled clk immediately, then cause irq storm.
> + */


/*
* Use canonical multi-line comment
* style and make sure the lines are not
* too long.
*/

..

FWIW, the patch that compares this with current clock rate most likely will be
reverted, meaning your fix might be not needed anymore, or has to be rebased.

--
With Best Regards,
Andy Shevchenko



2024-04-02 14:45:42

by Ilpo Järvinen

[permalink] [raw]
Subject: Re: [PATCH] tty: serial: fixed uart irq maybe cause irq storm

On Mon, 1 Apr 2024, Feng Chunguo wrote:

> Hi Greg KH,
>
> Sent this path again.
>
>  the irq should not be turned off here, what happens if some data comes in while this
> function is running?  Will it be lost?
> --> lost,not receive other irq.
>
>  When the uart was switching the baud rate from one to other,  this issue can be
> reproduced.


>> This feels wrong,
>> the irq should not be turned off here, what happens if some data comes in while this
>> function is running? Will it be lost? thanks, greg k-h

Changing rate always risks losing what's currently on wire due to timing
related corruption, I don't think there there's a way around that IRQ
being enabled or not.


--
i.