linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] serial: 8250: always disable IRQ during THRE test
@ 2025-10-14 11:47 Peng Zhang
  2025-10-14 12:19 ` Peng Zhang
  0 siblings, 1 reply; 4+ messages in thread
From: Peng Zhang @ 2025-10-14 11:47 UTC (permalink / raw)
  To: gregkh, jirislaby; +Cc: linux-kernel, linux-serial, songmuchun, Peng Zhang

commit 039d4926379b ("serial: 8250: Toggle IER bits on only after irq
has been set up") moved IRQ setup before the THRE test, so the interrupt
handler can run during the test and race with its IIR reads. This can
produce wrong THRE test results and cause spurious registration of the
serial8250_backup_timeout timer. Unconditionally disable the IRQ for the
short duration of the test and re-enable it afterwards to avoid the race.

Fixes: 039d4926379b ("serial: 8250: Toggle IER bits on only after irq has been set up")
Signed-off-by: Peng Zhang <zhangpeng.00@bytedance.com>
---
 drivers/tty/serial/8250/8250_port.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index 719faf92aa8a..addeef7a0d59 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -2147,8 +2147,7 @@ static void serial8250_THRE_test(struct uart_port *port)
 	if (up->port.flags & UPF_NO_THRE_TEST)
 		return;
 
-	if (port->irqflags & IRQF_SHARED)
-		disable_irq_nosync(port->irq);
+	disable_irq_nosync(port->irq);
 
 	/*
 	 * Test for UARTs that do not reassert THRE when the transmitter is idle and the interrupt
@@ -2170,8 +2169,7 @@ static void serial8250_THRE_test(struct uart_port *port)
 		serial_port_out(port, UART_IER, 0);
 	}
 
-	if (port->irqflags & IRQF_SHARED)
-		enable_irq(port->irq);
+	enable_irq(port->irq);
 
 	/*
 	 * If the interrupt is not reasserted, or we otherwise don't trust the iir, setup a timer to
-- 
2.20.1


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

* Re: [PATCH] serial: 8250: always disable IRQ during THRE test
  2025-10-14 11:47 [PATCH] serial: 8250: always disable IRQ during THRE test Peng Zhang
@ 2025-10-14 12:19 ` Peng Zhang
  2025-10-15 15:49   ` Jiri Slaby
  0 siblings, 1 reply; 4+ messages in thread
From: Peng Zhang @ 2025-10-14 12:19 UTC (permalink / raw)
  To: gregkh, jirislaby; +Cc: linux-kernel, linux-serial, songmuchun



在 2025/10/14 19:47, Peng Zhang 写道:
> commit 039d4926379b ("serial: 8250: Toggle IER bits on only after irq
> has been set up") moved IRQ setup before the THRE test, so the interrupt
> handler can run during the test and race with its IIR reads. This can
> produce wrong THRE test results and cause spurious registration of the
> serial8250_backup_timeout timer. Unconditionally disable the IRQ for the
> short duration of the test and re-enable it afterwards to avoid the race.
> 
> Fixes: 039d4926379b ("serial: 8250: Toggle IER bits on only after irq has been set up")
> Signed-off-by: Peng Zhang <zhangpeng.00@bytedance.com>
> ---
>   drivers/tty/serial/8250/8250_port.c | 6 ++----
>   1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
> index 719faf92aa8a..addeef7a0d59 100644
> --- a/drivers/tty/serial/8250/8250_port.c
> +++ b/drivers/tty/serial/8250/8250_port.c
> @@ -2147,8 +2147,7 @@ static void serial8250_THRE_test(struct uart_port *port)
>   	if (up->port.flags & UPF_NO_THRE_TEST)
>   		return;
>   
> -	if (port->irqflags & IRQF_SHARED)
> -		disable_irq_nosync(port->irq);
> +	disable_irq_nosync(port->irq);
disable_irq_nosync() may need to be changed to disable_irq() to prevent interrupts
that are currently being handled.>   
>   	/*
>   	 * Test for UARTs that do not reassert THRE when the transmitter is idle and the interrupt
> @@ -2170,8 +2169,7 @@ static void serial8250_THRE_test(struct uart_port *port)
>   		serial_port_out(port, UART_IER, 0);
>   	}
>   
> -	if (port->irqflags & IRQF_SHARED)
> -		enable_irq(port->irq);
> +	enable_irq(port->irq);
>   
>   	/*
>   	 * If the interrupt is not reasserted, or we otherwise don't trust the iir, setup a timer to


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

* Re: [PATCH] serial: 8250: always disable IRQ during THRE test
  2025-10-14 12:19 ` Peng Zhang
@ 2025-10-15 15:49   ` Jiri Slaby
  2025-10-18 18:56     ` Andy Shevchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Jiri Slaby @ 2025-10-15 15:49 UTC (permalink / raw)
  To: Peng Zhang, gregkh
  Cc: linux-kernel, linux-serial, songmuchun, Ilpo Järvinen,
	buytenh, Andy Shevchenko

On 14. 10. 25, 14:19, Peng Zhang wrote:
> 
> 
> 在 2025/10/14 19:47, Peng Zhang 写道:
>> commit 039d4926379b ("serial: 8250: Toggle IER bits on only after irq
>> has been set up") moved IRQ setup before the THRE test, so the interrupt
>> handler can run during the test and race with its IIR reads. This can
>> produce wrong THRE test results and cause spurious registration of the
>> serial8250_backup_timeout timer. Unconditionally disable the IRQ for the
>> short duration of the test and re-enable it afterwards to avoid the race.
>>
>> Fixes: 039d4926379b ("serial: 8250: Toggle IER bits on only after irq 
>> has been set up")
>> Signed-off-by: Peng Zhang <zhangpeng.00@bytedance.com>
>> ---
>>   drivers/tty/serial/8250/8250_port.c | 6 ++----
>>   1 file changed, 2 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/ 
>> serial/8250/8250_port.c
>> index 719faf92aa8a..addeef7a0d59 100644
>> --- a/drivers/tty/serial/8250/8250_port.c
>> +++ b/drivers/tty/serial/8250/8250_port.c
>> @@ -2147,8 +2147,7 @@ static void serial8250_THRE_test(struct 
>> uart_port *port)
>>       if (up->port.flags & UPF_NO_THRE_TEST)
>>           return;
>> -    if (port->irqflags & IRQF_SHARED)
>> -        disable_irq_nosync(port->irq);
>> +    disable_irq_nosync(port->irq);
> disable_irq_nosync() may need to be changed to disable_irq() to prevent 
> interrupts that are currently being handled.

Make sense to me. Care to Cc the people from 039d4926379b next time, so 
that they can comment?

>>       /*
>>        * Test for UARTs that do not reassert THRE when the transmitter 
>> is idle and the interrupt
>> @@ -2170,8 +2169,7 @@ static void serial8250_THRE_test(struct 
>> uart_port *port)
>>           serial_port_out(port, UART_IER, 0);
>>       }
>> -    if (port->irqflags & IRQF_SHARED)
>> -        enable_irq(port->irq);
>> +    enable_irq(port->irq);
>>       /*
>>        * If the interrupt is not reasserted, or we otherwise don't 
>> trust the iir, setup a timer to
> 


-- 
js
suse labs

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

* Re: [PATCH] serial: 8250: always disable IRQ during THRE test
  2025-10-15 15:49   ` Jiri Slaby
@ 2025-10-18 18:56     ` Andy Shevchenko
  0 siblings, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2025-10-18 18:56 UTC (permalink / raw)
  To: Jiri Slaby
  Cc: Peng Zhang, gregkh, linux-kernel, linux-serial, songmuchun,
	Ilpo Järvinen, buytenh

On Wed, Oct 15, 2025 at 05:49:34PM +0200, Jiri Slaby wrote:
> On 14. 10. 25, 14:19, Peng Zhang wrote:
> > 在 2025/10/14 19:47, Peng Zhang 写道:
> > > commit 039d4926379b ("serial: 8250: Toggle IER bits on only after irq
> > > has been set up") moved IRQ setup before the THRE test, so the interrupt
> > > handler can run during the test and race with its IIR reads. This can
> > > produce wrong THRE test results and cause spurious registration of the
> > > serial8250_backup_timeout timer. Unconditionally disable the IRQ for the
> > > short duration of the test and re-enable it afterwards to avoid the race.

...

> > > --- a/drivers/tty/serial/8250/8250_port.c
> > > +++ b/drivers/tty/serial/8250/8250_port.c
> > > @@ -2147,8 +2147,7 @@ static void serial8250_THRE_test(struct
> > > uart_port *port)
> > >       if (up->port.flags & UPF_NO_THRE_TEST)
> > >           return;
> > > -    if (port->irqflags & IRQF_SHARED)
> > > -        disable_irq_nosync(port->irq);
> > > +    disable_irq_nosync(port->irq);
> > disable_irq_nosync() may need to be changed to disable_irq() to prevent
> > interrupts that are currently being handled.
> 
> Make sense to me. Care to Cc the people from 039d4926379b next time, so that
> they can comment?

Thanks for sharing, Jiri!

The above commit message is unclear about the scope (HW wise) of the problem.
Is this only appears on a certain platform or on a wide range of
8250-compatible devices?

If this is only about a single platform, perhaps it needs a simple
UPF_NO_THRE_TEST flag to be set?

Otherwise, I think the above mentioned commit missed to explain the case of
the delayed THRE test. Brief look at the code doesn't reveal a problem to me:
the THRE test and timer backup is for Tx, and if we got already an interrupt
before THRE test it either Rx, so no timer is involved, or Tx on the platforms
that do _not_ need this backup solution. Ilpo, am I right?

-- 
With Best Regards,
Andy Shevchenko



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

end of thread, other threads:[~2025-10-18 18:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-14 11:47 [PATCH] serial: 8250: always disable IRQ during THRE test Peng Zhang
2025-10-14 12:19 ` Peng Zhang
2025-10-15 15:49   ` Jiri Slaby
2025-10-18 18:56     ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).