2023-10-13 11:49:29

by Pavel Krasavin

[permalink] [raw]
Subject: [PATCH v4] tty: serial: meson: fix hard LOCKUP on crtscts mode

From: Pavel Krasavin <[email protected]>

There might be hard lockup if we set crtscts mode on port without RTS/CTS configured:

# stty -F /dev/ttyAML6 crtscts; echo 1 > /dev/ttyAML6; echo 2 > /dev/ttyAML6
[ 95.890386] rcu: INFO: rcu_preempt detected stalls on CPUs/tasks:
[ 95.890857] rcu: 3-...0: (201 ticks this GP) idle=e33c/1/0x4000000000000000 softirq=5844/5846 fqs=4984
[ 95.900212] rcu: (detected by 2, t=21016 jiffies, g=7753, q=296 ncpus=4)
[ 95.906972] Task dump for CPU 3:
[ 95.910178] task:bash state:R running task stack:0 pid:205 ppid:1 flags:0x00000202
[ 95.920059] Call trace:
[ 95.922485] __switch_to+0xe4/0x168
[ 95.925951] 0xffffff8003477508
[ 95.974379] watchdog: Watchdog detected hard LOCKUP on cpu 3
[ 95.974424] Modules linked in: 88x2cs(O) rtc_meson_vrtc

Possible solution would be to not allow to setup crtscts on such port.

Tested on S905X3 based board.

Signed-off-by: Pavel Krasavin <[email protected]>
---
v4: More correct patch subject according to Jiri's note
v3: https://lore.kernel.org/lkml/[email protected]/
"From:" line added to the mail
v2: https://lore.kernel.org/lkml/[email protected]/
braces for single statement removed according to Dmitry's note
v1: https://lore.kernel.org/lkml/[email protected]/
---

--- a/drivers/tty/serial/meson_uart.c 2023-10-12 15:44:02.410538523 +0300
+++ b/drivers/tty/serial/meson_uart.c 2023-10-12 15:58:06.242395253 +0300
@@ -380,10 +380,14 @@ static void meson_uart_set_termios(struc
else
val |= AML_UART_STOP_BIT_1SB;

- if (cflags & CRTSCTS)
- val &= ~AML_UART_TWO_WIRE_EN;
- else
+ if (cflags & CRTSCTS) {
+ if (port->flags & UPF_HARD_FLOW)
+ val &= ~AML_UART_TWO_WIRE_EN;
+ else
+ termios->c_cflag &= ~CRTSCTS;
+ } else {
val |= AML_UART_TWO_WIRE_EN;
+ }

writel(val, port->membase + AML_UART_CONTROL);

@@ -705,6 +709,7 @@ static int meson_uart_probe(struct platf
u32 fifosize = 64; /* Default is 64, 128 for EE UART_0 */
int ret = 0;
int irq;
+ bool has_rtscts;

if (pdev->dev.of_node)
pdev->id = of_alias_get_id(pdev->dev.of_node, "serial");
@@ -732,6 +737,7 @@ static int meson_uart_probe(struct platf
return irq;

of_property_read_u32(pdev->dev.of_node, "fifo-size", &fifosize);
+ has_rtscts = of_property_read_bool(pdev->dev.of_node, "uart-has-rtscts");

if (meson_ports[pdev->id]) {
return dev_err_probe(&pdev->dev, -EBUSY,
@@ -762,6 +768,8 @@ static int meson_uart_probe(struct platf
port->mapsize = resource_size(res_mem);
port->irq = irq;
port->flags = UPF_BOOT_AUTOCONF | UPF_LOW_LATENCY;
+ if (has_rtscts)
+ port->flags |= UPF_HARD_FLOW;
port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_MESON_CONSOLE);
port->dev = &pdev->dev;
port->line = pdev->id;


2023-10-13 14:18:43

by Dmitry Rokosov

[permalink] [raw]
Subject: Re: [PATCH v4] tty: serial: meson: fix hard LOCKUP on crtscts mode

I believe it would be necessary to include a 'Fixes' tag for that. Neil,
what do you think?
Since a HARDLOCKUP is an undesirable situation, I don't think we want to
have it in the LTS kernels either.

On Fri, Oct 13, 2023 at 11:48:39AM +0000, Pavel Krasavin wrote:
> From: Pavel Krasavin <[email protected]>
>
> There might be hard lockup if we set crtscts mode on port without RTS/CTS configured:
>
> # stty -F /dev/ttyAML6 crtscts; echo 1 > /dev/ttyAML6; echo 2 > /dev/ttyAML6
> [ 95.890386] rcu: INFO: rcu_preempt detected stalls on CPUs/tasks:
> [ 95.890857] rcu: 3-...0: (201 ticks this GP) idle=e33c/1/0x4000000000000000 softirq=5844/5846 fqs=4984
> [ 95.900212] rcu: (detected by 2, t=21016 jiffies, g=7753, q=296 ncpus=4)
> [ 95.906972] Task dump for CPU 3:
> [ 95.910178] task:bash state:R running task stack:0 pid:205 ppid:1 flags:0x00000202
> [ 95.920059] Call trace:
> [ 95.922485] __switch_to+0xe4/0x168
> [ 95.925951] 0xffffff8003477508
> [ 95.974379] watchdog: Watchdog detected hard LOCKUP on cpu 3
> [ 95.974424] Modules linked in: 88x2cs(O) rtc_meson_vrtc
>
> Possible solution would be to not allow to setup crtscts on such port.
>
> Tested on S905X3 based board.
>
> Signed-off-by: Pavel Krasavin <[email protected]>
> ---
> v4: More correct patch subject according to Jiri's note
> v3: https://lore.kernel.org/lkml/[email protected]/
> "From:" line added to the mail
> v2: https://lore.kernel.org/lkml/[email protected]/
> braces for single statement removed according to Dmitry's note
> v1: https://lore.kernel.org/lkml/[email protected]/
> ---
>
> --- a/drivers/tty/serial/meson_uart.c 2023-10-12 15:44:02.410538523 +0300
> +++ b/drivers/tty/serial/meson_uart.c 2023-10-12 15:58:06.242395253 +0300
> @@ -380,10 +380,14 @@ static void meson_uart_set_termios(struc
> else
> val |= AML_UART_STOP_BIT_1SB;
>
> - if (cflags & CRTSCTS)
> - val &= ~AML_UART_TWO_WIRE_EN;
> - else
> + if (cflags & CRTSCTS) {
> + if (port->flags & UPF_HARD_FLOW)
> + val &= ~AML_UART_TWO_WIRE_EN;
> + else
> + termios->c_cflag &= ~CRTSCTS;
> + } else {
> val |= AML_UART_TWO_WIRE_EN;
> + }
>
> writel(val, port->membase + AML_UART_CONTROL);
>
> @@ -705,6 +709,7 @@ static int meson_uart_probe(struct platf
> u32 fifosize = 64; /* Default is 64, 128 for EE UART_0 */
> int ret = 0;
> int irq;
> + bool has_rtscts;
>
> if (pdev->dev.of_node)
> pdev->id = of_alias_get_id(pdev->dev.of_node, "serial");
> @@ -732,6 +737,7 @@ static int meson_uart_probe(struct platf
> return irq;
>
> of_property_read_u32(pdev->dev.of_node, "fifo-size", &fifosize);
> + has_rtscts = of_property_read_bool(pdev->dev.of_node, "uart-has-rtscts");
>
> if (meson_ports[pdev->id]) {
> return dev_err_probe(&pdev->dev, -EBUSY,
> @@ -762,6 +768,8 @@ static int meson_uart_probe(struct platf
> port->mapsize = resource_size(res_mem);
> port->irq = irq;
> port->flags = UPF_BOOT_AUTOCONF | UPF_LOW_LATENCY;
> + if (has_rtscts)
> + port->flags |= UPF_HARD_FLOW;
> port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_MESON_CONSOLE);
> port->dev = &pdev->dev;
> port->line = pdev->id;
>
> _______________________________________________
> linux-amlogic mailing list
> [email protected]
> http://lists.infradead.org/mailman/listinfo/linux-amlogic

--
Thank you,
Dmitry

2023-10-13 15:37:31

by Neil Armstrong

[permalink] [raw]
Subject: Re: [PATCH v4] tty: serial: meson: fix hard LOCKUP on crtscts mode

On 13/10/2023 16:18, Dmitry Rokosov wrote:
> I believe it would be necessary to include a 'Fixes' tag for that. Neil,
> what do you think?
> Since a HARDLOCKUP is an undesirable situation, I don't think we want to
> have it in the LTS kernels either.

Yes, and please keep the previous Reviewed-by Dmitry and I added on v3 and send a v5 with the Fixes added.

It should be:
Fixes: ff7693d079e5 ("ARM: meson: serial: add MesonX SoC on-chip uart driver")

Hopefully it will be the last iteration.

Thanks,
Neil
>
> On Fri, Oct 13, 2023 at 11:48:39AM +0000, Pavel Krasavin wrote:
>> From: Pavel Krasavin <[email protected]>
>>
>> There might be hard lockup if we set crtscts mode on port without RTS/CTS configured:
>>
>> # stty -F /dev/ttyAML6 crtscts; echo 1 > /dev/ttyAML6; echo 2 > /dev/ttyAML6
>> [ 95.890386] rcu: INFO: rcu_preempt detected stalls on CPUs/tasks:
>> [ 95.890857] rcu: 3-...0: (201 ticks this GP) idle=e33c/1/0x4000000000000000 softirq=5844/5846 fqs=4984
>> [ 95.900212] rcu: (detected by 2, t=21016 jiffies, g=7753, q=296 ncpus=4)
>> [ 95.906972] Task dump for CPU 3:
>> [ 95.910178] task:bash state:R running task stack:0 pid:205 ppid:1 flags:0x00000202
>> [ 95.920059] Call trace:
>> [ 95.922485] __switch_to+0xe4/0x168
>> [ 95.925951] 0xffffff8003477508
>> [ 95.974379] watchdog: Watchdog detected hard LOCKUP on cpu 3
>> [ 95.974424] Modules linked in: 88x2cs(O) rtc_meson_vrtc
>>
>> Possible solution would be to not allow to setup crtscts on such port.
>>
>> Tested on S905X3 based board.
>>
>> Signed-off-by: Pavel Krasavin <[email protected]>
>> ---
>> v4: More correct patch subject according to Jiri's note
>> v3: https://lore.kernel.org/lkml/[email protected]/
>> "From:" line added to the mail
>> v2: https://lore.kernel.org/lkml/[email protected]/
>> braces for single statement removed according to Dmitry's note
>> v1: https://lore.kernel.org/lkml/[email protected]/
>> ---
>>
>> --- a/drivers/tty/serial/meson_uart.c 2023-10-12 15:44:02.410538523 +0300
>> +++ b/drivers/tty/serial/meson_uart.c 2023-10-12 15:58:06.242395253 +0300
>> @@ -380,10 +380,14 @@ static void meson_uart_set_termios(struc
>> else
>> val |= AML_UART_STOP_BIT_1SB;
>>
>> - if (cflags & CRTSCTS)
>> - val &= ~AML_UART_TWO_WIRE_EN;
>> - else
>> + if (cflags & CRTSCTS) {
>> + if (port->flags & UPF_HARD_FLOW)
>> + val &= ~AML_UART_TWO_WIRE_EN;
>> + else
>> + termios->c_cflag &= ~CRTSCTS;
>> + } else {
>> val |= AML_UART_TWO_WIRE_EN;
>> + }
>>
>> writel(val, port->membase + AML_UART_CONTROL);
>>
>> @@ -705,6 +709,7 @@ static int meson_uart_probe(struct platf
>> u32 fifosize = 64; /* Default is 64, 128 for EE UART_0 */
>> int ret = 0;
>> int irq;
>> + bool has_rtscts;
>>
>> if (pdev->dev.of_node)
>> pdev->id = of_alias_get_id(pdev->dev.of_node, "serial");
>> @@ -732,6 +737,7 @@ static int meson_uart_probe(struct platf
>> return irq;
>>
>> of_property_read_u32(pdev->dev.of_node, "fifo-size", &fifosize);
>> + has_rtscts = of_property_read_bool(pdev->dev.of_node, "uart-has-rtscts");
>>
>> if (meson_ports[pdev->id]) {
>> return dev_err_probe(&pdev->dev, -EBUSY,
>> @@ -762,6 +768,8 @@ static int meson_uart_probe(struct platf
>> port->mapsize = resource_size(res_mem);
>> port->irq = irq;
>> port->flags = UPF_BOOT_AUTOCONF | UPF_LOW_LATENCY;
>> + if (has_rtscts)
>> + port->flags |= UPF_HARD_FLOW;
>> port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_MESON_CONSOLE);
>> port->dev = &pdev->dev;
>> port->line = pdev->id;
>>
>> _______________________________________________
>> linux-amlogic mailing list
>> [email protected]
>> http://lists.infradead.org/mailman/listinfo/linux-amlogic
>

2023-10-13 16:22:22

by Pavel Krasavin

[permalink] [raw]
Subject: Re: [PATCH v4] tty: serial: meson: fix hard LOCKUP on crtscts mode

Dmitry, Neil,

----- "Neil Armstrong" <[email protected]> писал(а): -----
>> On 13/10/2023 16:18, Dmitry Rokosov wrote:
>> I believe it would be necessary to include a 'Fixes' tag for that. Neil,
>> what do you think?
>> Since a HARDLOCKUP is an undesirable situation, I don't think we want to
>> have it in the LTS kernels either.

> Yes, and please keep the previous Reviewed-by Dmitry and I added on v3 and send a v5 with the Fixes added.
Sorry for this.

> It should be:
> Fixes: ff7693d079e5 ("ARM: meson: serial: add MesonX SoC on-chip uart driver")
Got it.

> Hopefully it will be the last iteration.
I'll do my best. Thank you for your work on this patch.

Regards,
Pavel.