The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] serial: 8250_omap: clear rx_running on zero-length DMA completes
@ 2026-05-21 13:30 Matthias Feser
  2026-05-22  5:40 ` Moteen Shah
  0 siblings, 1 reply; 14+ messages in thread
From: Matthias Feser @ 2026-05-21 13:30 UTC (permalink / raw)
  To: linux-serial@vger.kernel.org, gregkh@linuxfoundation.org,
	jirislaby@kernel.org
  Cc: linux-kernel@vger.kernel.org, k-willis@ti.com, m-shah@ti.com,
	msp@baylibre.com, andriy.shevchenko@linux.intel.com

On AM33xx RX DMA only triggers when the FIFO reaches the
configured threshold (typically 48 bytes). For smaller bursts
no DMA request is issued and the FIFO is drained by RX timeout.

In this case __dma_rx_do_complete() can legitimately see count == 0.

The current code exits early in this case and does not clear
dma->rx_running, leaving the DMA state inconsistent. This can
prevent RX DMA from restarting and may cause
omap_8250_rx_dma_flush() to fail, marking DMA as broken.

Fix this by always clearing dma->rx_running on exit.

Signed-off-by: Matthias Feser <mfe@KBSgmbhfr.onmicrosoft.com>
---
 drivers/tty/serial/8250/8250_omap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/tty/serial/8250/8250_omap.c b/drivers/tty/serial/8250/8250_omap.c
index c552c6b9a037..686e54859aa5 100644
--- a/drivers/tty/serial/8250/8250_omap.c
+++ b/drivers/tty/serial/8250/8250_omap.c
@@ -948,11 +948,11 @@ static void __dma_rx_do_complete(struct uart_8250_port *p)
 		goto out;
 	ret = tty_insert_flip_string(tty_port, dma->rx_buf, count);
 
-	dma->rx_running = 0;
 	p->port.icount.rx += ret;
 	p->port.icount.buf_overrun += count - ret;
 out:
 
+	dma->rx_running = 0;
 	tty_flip_buffer_push(tty_port);
 }
 
-- 
2.39.5


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

* Re: [PATCH] serial: 8250_omap: clear rx_running on zero-length DMA completes
  2026-05-21 13:30 [PATCH] serial: 8250_omap: clear rx_running on zero-length DMA completes Matthias Feser
@ 2026-05-22  5:40 ` Moteen Shah
  2026-05-22  8:24   ` [PATCH v2] " Matthias Feser
  0 siblings, 1 reply; 14+ messages in thread
From: Moteen Shah @ 2026-05-22  5:40 UTC (permalink / raw)
  To: Matthias Feser, linux-serial@vger.kernel.org,
	gregkh@linuxfoundation.org, jirislaby@kernel.org
  Cc: linux-kernel@vger.kernel.org, k-willis@ti.com, msp@baylibre.com,
	andriy.shevchenko@linux.intel.com

Hey Matthias,
Thanks for the patch.

On 21/05/26 19:00, Matthias Feser wrote:
> On AM33xx RX DMA only triggers when the FIFO reaches the
> configured threshold (typically 48 bytes). For smaller bursts
> no DMA request is issued and the FIFO is drained by RX timeout.
>
> In this case __dma_rx_do_complete() can legitimately see count == 0.
>
> The current code exits early in this case and does not clear
> dma->rx_running, leaving the DMA state inconsistent. This can
> prevent RX DMA from restarting and may cause
> omap_8250_rx_dma_flush() to fail, marking DMA as broken.
>
> Fix this by always clearing dma->rx_running on exit.
>
> Signed-off-by: Matthias Feser <mfe@KBSgmbhfr.onmicrosoft.com>
> ---
>   drivers/tty/serial/8250/8250_omap.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/tty/serial/8250/8250_omap.c b/drivers/tty/serial/8250/8250_omap.c
> index c552c6b9a037..686e54859aa5 100644
> --- a/drivers/tty/serial/8250/8250_omap.c
> +++ b/drivers/tty/serial/8250/8250_omap.c
> @@ -948,11 +948,11 @@ static void __dma_rx_do_complete(struct uart_8250_port *p)
>   		goto out;
>   	ret = tty_insert_flip_string(tty_port, dma->rx_buf, count);
>   
> -	dma->rx_running = 0;
>   	p->port.icount.rx += ret;
>   	p->port.icount.buf_overrun += count - ret;
>   out:
>   
> +	dma->rx_running = 0;
>   	tty_flip_buffer_push(tty_port);
>   }
>   

I think the better place should be just before the If(!count) check, 
this would mark the running status of the DMA as soon as the termination 
gets done.

Regards,
Moteen


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

* Re: [PATCH v2] serial: 8250_omap: clear rx_running on zero-length DMA completes
  2026-05-22  5:40 ` Moteen Shah
@ 2026-05-22  8:24   ` Matthias Feser
  2026-05-22  8:25     ` Moteen Shah
                       ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Matthias Feser @ 2026-05-22  8:24 UTC (permalink / raw)
  To: Moteen Shah, linux-serial@vger.kernel.org,
	gregkh@linuxfoundation.org, jirislaby@kernel.org
  Cc: linux-kernel@vger.kernel.org, k-willis@ti.com, msp@baylibre.com,
	andriy.shevchenko@linux.intel.com

Thanks for the fast response. I've updated the patch accordingly.

From: Matthias Feser <mfe@KBSgmbhfr.onmicrosoft.com>
Date: Fri, 22 May 2026 10:11:16 +0200
Subject: [PATCH v2] serial: 8250_omap: clear rx_running on zero-length DMA completes

On AM33xx RX DMA only triggers when the FIFO reaches the
configured threshold (typically 48 bytes). For smaller bursts
no DMA request is issued and the FIFO is drained by RX timeout.

In this case __dma_rx_do_complete() can legitimately see count == 0.

The current code exits early in this case and does not clear
dma->rx_running, leaving the DMA state inconsistent. This can
prevent RX DMA from restarting and may cause
omap_8250_rx_dma_flush() to fail, marking DMA as broken.

Fix this by clearing dma->rx_running once the DMA transfer has
completed or been terminated, even if no data was transferred.

Changes in v2:
- Move dma->rx_running clear before the count check so the state
  is updated immediately after DMA completion/termination

Signed-off-by: Matthias Feser <mfe@KBSgmbhfr.onmicrosoft.com>
---
 drivers/tty/serial/8250/8250_omap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/tty/serial/8250/8250_omap.c b/drivers/tty/serial/8250/8250_omap.c
index c552c6b9a037..76bc8ad324cb 100644
--- a/drivers/tty/serial/8250/8250_omap.c
+++ b/drivers/tty/serial/8250/8250_omap.c
@@ -944,11 +944,11 @@ static void __dma_rx_do_complete(struct uart_8250_port *p)
 				dev_err(p->port.dev, "teardown incomplete\n");
 		}
 	}
+	dma->rx_running = 0;
 	if (!count)
 		goto out;
 	ret = tty_insert_flip_string(tty_port, dma->rx_buf, count);
 
-	dma->rx_running = 0;
 	p->port.icount.rx += ret;
 	p->port.icount.buf_overrun += count - ret;
 out:
-- 
2.39.5


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

* Re: [PATCH v2] serial: 8250_omap: clear rx_running on zero-length DMA completes
  2026-05-22  8:24   ` [PATCH v2] " Matthias Feser
@ 2026-05-22  8:25     ` Moteen Shah
  2026-05-22  8:28     ` Moteen Shah
  2026-05-22  8:46     ` [PATCH v2] " gregkh
  2 siblings, 0 replies; 14+ messages in thread
From: Moteen Shah @ 2026-05-22  8:25 UTC (permalink / raw)
  To: Matthias Feser, linux-serial@vger.kernel.org,
	gregkh@linuxfoundation.org, jirislaby@kernel.org
  Cc: linux-kernel@vger.kernel.org, k-willis@ti.com, msp@baylibre.com,
	andriy.shevchenko@linux.intel.com


On 22/05/26 13:54, Matthias Feser wrote:
> Thanks for the fast response. I've updated the patch accordingly.
>
> From: Matthias Feser <mfe@KBSgmbhfr.onmicrosoft.com>
> Date: Fri, 22 May 2026 10:11:16 +0200
> Subject: [PATCH v2] serial: 8250_omap: clear rx_running on zero-length DMA completes
>
> On AM33xx RX DMA only triggers when the FIFO reaches the
> configured threshold (typically 48 bytes). For smaller bursts
> no DMA request is issued and the FIFO is drained by RX timeout.
>
> In this case __dma_rx_do_complete() can legitimately see count == 0.
>
> The current code exits early in this case and does not clear
> dma->rx_running, leaving the DMA state inconsistent. This can
> prevent RX DMA from restarting and may cause
> omap_8250_rx_dma_flush() to fail, marking DMA as broken.
>
> Fix this by clearing dma->rx_running once the DMA transfer has
> completed or been terminated, even if no data was transferred.
>
> Changes in v2:
> - Move dma->rx_running clear before the count check so the state
>    is updated immediately after DMA completion/termination
>
> Signed-off-by: Matthias Feser <mfe@KBSgmbhfr.onmicrosoft.com>
> ---
>   drivers/tty/serial/8250/8250_omap.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/tty/serial/8250/8250_omap.c b/drivers/tty/serial/8250/8250_omap.c
> index c552c6b9a037..76bc8ad324cb 100644
> --- a/drivers/tty/serial/8250/8250_omap.c
> +++ b/drivers/tty/serial/8250/8250_omap.c
> @@ -944,11 +944,11 @@ static void __dma_rx_do_complete(struct uart_8250_port *p)
>   				dev_err(p->port.dev, "teardown incomplete\n");
>   		}
>   	}
> +	dma->rx_running = 0;
>   	if (!count)
>   		goto out;
>   	ret = tty_insert_flip_string(tty_port, dma->rx_buf, count);
>   
> -	dma->rx_running = 0;
>   	p->port.icount.rx += ret;
>   	p->port.icount.buf_overrun += count - ret;
>   out:


Reviewed-by: Moteen Shah <m-shah@ti.com>

Regards,
Moteen


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

* Re: [PATCH v2] serial: 8250_omap: clear rx_running on zero-length DMA completes
  2026-05-22  8:24   ` [PATCH v2] " Matthias Feser
  2026-05-22  8:25     ` Moteen Shah
@ 2026-05-22  8:28     ` Moteen Shah
  2026-05-22  9:02       ` AW: [PATCH v3] " Matthias Feser
  2026-05-22  8:46     ` [PATCH v2] " gregkh
  2 siblings, 1 reply; 14+ messages in thread
From: Moteen Shah @ 2026-05-22  8:28 UTC (permalink / raw)
  To: Matthias Feser, linux-serial@vger.kernel.org,
	gregkh@linuxfoundation.org, jirislaby@kernel.org
  Cc: linux-kernel@vger.kernel.org, k-willis@ti.com, msp@baylibre.com,
	andriy.shevchenko@linux.intel.com


On 22/05/26 13:54, Matthias Feser wrote:
> Thanks for the fast response. I've updated the patch accordingly.
>
> From: Matthias Feser <mfe@KBSgmbhfr.onmicrosoft.com>
> Date: Fri, 22 May 2026 10:11:16 +0200
> Subject: [PATCH v2] serial: 8250_omap: clear rx_running on zero-length DMA completes
>
> On AM33xx RX DMA only triggers when the FIFO reaches the
> configured threshold (typically 48 bytes). For smaller bursts
> no DMA request is issued and the FIFO is drained by RX timeout.
>
> In this case __dma_rx_do_complete() can legitimately see count == 0.
>
> The current code exits early in this case and does not clear
> dma->rx_running, leaving the DMA state inconsistent. This can
> prevent RX DMA from restarting and may cause
> omap_8250_rx_dma_flush() to fail, marking DMA as broken.
>
> Fix this by clearing dma->rx_running once the DMA transfer has
> completed or been terminated, even if no data was transferred.
>
> Changes in v2:
> - Move dma->rx_running clear before the count check so the state
>    is updated immediately after DMA completion/termination

Just a nit pick here: I think the "Changes in v2:" line should come 
below the tear line(---) after signed-off-by.
Code wise LGTM.

Regards,
Moteen
>
> Signed-off-by: Matthias Feser <mfe@KBSgmbhfr.onmicrosoft.com>
> ---
>   drivers/tty/serial/8250/8250_omap.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/tty/serial/8250/8250_omap.c b/drivers/tty/serial/8250/8250_omap.c
> index c552c6b9a037..76bc8ad324cb 100644
> --- a/drivers/tty/serial/8250/8250_omap.c
> +++ b/drivers/tty/serial/8250/8250_omap.c
> @@ -944,11 +944,11 @@ static void __dma_rx_do_complete(struct uart_8250_port *p)
>   				dev_err(p->port.dev, "teardown incomplete\n");
>   		}
>   	}
> +	dma->rx_running = 0;
>   	if (!count)
>   		goto out;
>   	ret = tty_insert_flip_string(tty_port, dma->rx_buf, count);
>   
> -	dma->rx_running = 0;
>   	p->port.icount.rx += ret;
>   	p->port.icount.buf_overrun += count - ret;
>   out:

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

* Re: [PATCH v2] serial: 8250_omap: clear rx_running on zero-length DMA completes
  2026-05-22  8:24   ` [PATCH v2] " Matthias Feser
  2026-05-22  8:25     ` Moteen Shah
  2026-05-22  8:28     ` Moteen Shah
@ 2026-05-22  8:46     ` gregkh
  2 siblings, 0 replies; 14+ messages in thread
From: gregkh @ 2026-05-22  8:46 UTC (permalink / raw)
  To: Matthias Feser
  Cc: Moteen Shah, linux-serial@vger.kernel.org, jirislaby@kernel.org,
	linux-kernel@vger.kernel.org, k-willis@ti.com, msp@baylibre.com,
	andriy.shevchenko@linux.intel.com

On Fri, May 22, 2026 at 08:24:01AM +0000, Matthias Feser wrote:
> Thanks for the fast response. I've updated the patch accordingly.
> 
> From: Matthias Feser <mfe@KBSgmbhfr.onmicrosoft.com>
> Date: Fri, 22 May 2026 10:11:16 +0200
> Subject: [PATCH v2] serial: 8250_omap: clear rx_running on zero-length DMA completes
> 
> On AM33xx RX DMA only triggers when the FIFO reaches the
> configured threshold (typically 48 bytes). For smaller bursts
> no DMA request is issued and the FIFO is drained by RX timeout.
> 
> In this case __dma_rx_do_complete() can legitimately see count == 0.
> 
> The current code exits early in this case and does not clear
> dma->rx_running, leaving the DMA state inconsistent. This can
> prevent RX DMA from restarting and may cause
> omap_8250_rx_dma_flush() to fail, marking DMA as broken.
> 
> Fix this by clearing dma->rx_running once the DMA transfer has
> completed or been terminated, even if no data was transferred.
> 
> Changes in v2:
> - Move dma->rx_running clear before the count check so the state
>   is updated immediately after DMA completion/termination
> 
> Signed-off-by: Matthias Feser <mfe@KBSgmbhfr.onmicrosoft.com>
> ---
>  drivers/tty/serial/8250/8250_omap.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_omap.c b/drivers/tty/serial/8250/8250_omap.c
> index c552c6b9a037..76bc8ad324cb 100644
> --- a/drivers/tty/serial/8250/8250_omap.c
> +++ b/drivers/tty/serial/8250/8250_omap.c
> @@ -944,11 +944,11 @@ static void __dma_rx_do_complete(struct uart_8250_port *p)
>  				dev_err(p->port.dev, "teardown incomplete\n");
>  		}
>  	}
> +	dma->rx_running = 0;
>  	if (!count)
>  		goto out;
>  	ret = tty_insert_flip_string(tty_port, dma->rx_buf, count);
>  
> -	dma->rx_running = 0;
>  	p->port.icount.rx += ret;
>  	p->port.icount.buf_overrun += count - ret;
>  out:
> -- 
> 2.39.5
> 

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

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

* AW: [PATCH v3] serial: 8250_omap: clear rx_running on zero-length DMA completes
  2026-05-22  8:28     ` Moteen Shah
@ 2026-05-22  9:02       ` Matthias Feser
  2026-05-22 10:18         ` Moteen Shah
  0 siblings, 1 reply; 14+ messages in thread
From: Matthias Feser @ 2026-05-22  9:02 UTC (permalink / raw)
  To: Moteen Shah, linux-serial@vger.kernel.org,
	gregkh@linuxfoundation.org, jirislaby@kernel.org
  Cc: linux-kernel@vger.kernel.org, k-willis@ti.com, msp@baylibre.com,
	andriy.shevchenko@linux.intel.com

On AM33xx RX DMA only triggers when the FIFO reaches the
configured threshold (typically 48 bytes). For smaller bursts
no DMA request is issued and the FIFO is drained by RX timeout.

In this case __dma_rx_do_complete() can legitimately see count == 0.

The current code exits early in this case and does not clear
dma->rx_running, leaving the DMA state inconsistent. This can
prevent RX DMA from restarting and may cause
omap_8250_rx_dma_flush() to fail, marking DMA as broken.

Fix this by clearing dma->rx_running once the DMA transfer has
completed or been terminated, even if no data was transferred.

Signed-off-by: Matthias Feser <mfe@KBSgmbhfr.onmicrosoft.com>
---
Changes in v3:
- Move "Changes in v2" below the tear line as suggested

Changes in v2:
- Move dma->rx_running clear before the count check so the state
  is updated immediately after DMA completion/termination

 drivers/tty/serial/8250/8250_omap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/tty/serial/8250/8250_omap.c b/drivers/tty/serial/8250/8250_omap.c
index c552c6b9a037..76bc8ad324cb 100644
--- a/drivers/tty/serial/8250/8250_omap.c
+++ b/drivers/tty/serial/8250/8250_omap.c
@@ -944,11 +944,11 @@ static void __dma_rx_do_complete(struct uart_8250_port *p)
 				dev_err(p->port.dev, "teardown incomplete\n");
 		}
 	}
+	dma->rx_running = 0;
 	if (!count)
 		goto out;
 	ret = tty_insert_flip_string(tty_port, dma->rx_buf, count);
 
-	dma->rx_running = 0;
 	p->port.icount.rx += ret;
 	p->port.icount.buf_overrun += count - ret;
 out:
-- 
2.39.5


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

* Re: AW: [PATCH v3] serial: 8250_omap: clear rx_running on zero-length DMA completes
  2026-05-22  9:02       ` AW: [PATCH v3] " Matthias Feser
@ 2026-05-22 10:18         ` Moteen Shah
  2026-05-22 12:37           ` [PATCH v4] " Matthias Feser
  2026-05-26  7:35           ` [PATCH v5] " Matthias Feser
  0 siblings, 2 replies; 14+ messages in thread
From: Moteen Shah @ 2026-05-22 10:18 UTC (permalink / raw)
  To: Matthias Feser, linux-serial@vger.kernel.org,
	gregkh@linuxfoundation.org, jirislaby@kernel.org
  Cc: linux-kernel@vger.kernel.org, k-willis@ti.com, msp@baylibre.com,
	andriy.shevchenko@linux.intel.com


On 22/05/26 14:32, Matthias Feser wrote:
> On AM33xx RX DMA only triggers when the FIFO reaches the
> configured threshold (typically 48 bytes). For smaller bursts
> no DMA request is issued and the FIFO is drained by RX timeout.
>
> In this case __dma_rx_do_complete() can legitimately see count == 0.
>
> The current code exits early in this case and does not clear
> dma->rx_running, leaving the DMA state inconsistent. This can
> prevent RX DMA from restarting and may cause
> omap_8250_rx_dma_flush() to fail, marking DMA as broken.
>
> Fix this by clearing dma->rx_running once the DMA transfer has
> completed or been terminated, even if no data was transferred.
>
> Signed-off-by: Matthias Feser <mfe@KBSgmbhfr.onmicrosoft.com>
> ---
> Changes in v3:
> - Move "Changes in v2" below the tear line as suggested
>
> Changes in v2:
> - Move dma->rx_running clear before the count check so the state
>    is updated immediately after DMA completion/termination
>
>   drivers/tty/serial/8250/8250_omap.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/tty/serial/8250/8250_omap.c b/drivers/tty/serial/8250/8250_omap.c
> index c552c6b9a037..76bc8ad324cb 100644
> --- a/drivers/tty/serial/8250/8250_omap.c
> +++ b/drivers/tty/serial/8250/8250_omap.c
> @@ -944,11 +944,11 @@ static void __dma_rx_do_complete(struct uart_8250_port *p)
>   				dev_err(p->port.dev, "teardown incomplete\n");
>   		}
>   	}
> +	dma->rx_running = 0;

Nit: Add a newline above dma->rx_running, I think checkpatch would have 
caught it.
With the above change:
Reviewed-by: Moteen Shah <m-shah@ti.com>

Please pick the tag up in the next version if you intend to make one.

Thanks and Regards,
Moteen

>   	if (!count)
>   		goto out;
>   	ret = tty_insert_flip_string(tty_port, dma->rx_buf, count);
>   
> -	dma->rx_running = 0;
>   	p->port.icount.rx += ret;
>   	p->port.icount.buf_overrun += count - ret;
>   out:


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

* RE: [PATCH v4] serial: 8250_omap: clear rx_running on zero-length DMA completes
  2026-05-22 10:18         ` Moteen Shah
@ 2026-05-22 12:37           ` Matthias Feser
  2026-05-23  5:47             ` gregkh
  2026-05-26  7:35           ` [PATCH v5] " Matthias Feser
  1 sibling, 1 reply; 14+ messages in thread
From: Matthias Feser @ 2026-05-22 12:37 UTC (permalink / raw)
  To: Moteen Shah, linux-serial@vger.kernel.org,
	gregkh@linuxfoundation.org, jirislaby@kernel.org
  Cc: linux-kernel@vger.kernel.org, k-willis@ti.com, msp@baylibre.com,
	andriy.shevchenko@linux.intel.com

On AM33xx RX DMA only triggers when the FIFO reaches the
configured threshold (typically 48 bytes). For smaller bursts
no DMA request is issued and the FIFO is drained by RX timeout.

In this case __dma_rx_do_complete() can legitimately see count == 0.

The current code exits early in this case and does not clear
dma->rx_running, leaving the DMA state inconsistent. This can
prevent RX DMA from restarting and may cause
omap_8250_rx_dma_flush() to fail, marking DMA as broken.

Fix this by clearing dma->rx_running once the DMA transfer has
completed or been terminated, even if no data was transferred.

Signed-off-by: Matthias Feser <mfe@KBSgmbhfr.onmicrosoft.com>
Reviewed-by: Moteen Shah <m-shah@ti.com>
---
Changes in v4:
- Add blank line before dma->rx_running as suggested

Changes in v3:
- Move "Changes in v2" below the tear line as suggested

Changes in v2:
- Move dma->rx_running clear before the count check

 drivers/tty/serial/8250/8250_omap.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/8250/8250_omap.c b/drivers/tty/serial/8250/8250_omap.c
index c552c6b9a037..3c7775df27ef 100644
--- a/drivers/tty/serial/8250/8250_omap.c
+++ b/drivers/tty/serial/8250/8250_omap.c
@@ -944,11 +944,12 @@ static void __dma_rx_do_complete(struct uart_8250_port *p)
 				dev_err(p->port.dev, "teardown incomplete\n");
 		}
 	}
+
+	dma->rx_running = 0;
 	if (!count)
 		goto out;
 	ret = tty_insert_flip_string(tty_port, dma->rx_buf, count);
 
-	dma->rx_running = 0;
 	p->port.icount.rx += ret;
 	p->port.icount.buf_overrun += count - ret;
 out:
-- 
2.39.5


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

* Re: [PATCH v4] serial: 8250_omap: clear rx_running on zero-length DMA completes
  2026-05-22 12:37           ` [PATCH v4] " Matthias Feser
@ 2026-05-23  5:47             ` gregkh
  0 siblings, 0 replies; 14+ messages in thread
From: gregkh @ 2026-05-23  5:47 UTC (permalink / raw)
  To: Matthias Feser
  Cc: Moteen Shah, linux-serial@vger.kernel.org, jirislaby@kernel.org,
	linux-kernel@vger.kernel.org, k-willis@ti.com, msp@baylibre.com,
	andriy.shevchenko@linux.intel.com

On Fri, May 22, 2026 at 12:37:25PM +0000, Matthias Feser wrote:
> On AM33xx RX DMA only triggers when the FIFO reaches the
> configured threshold (typically 48 bytes). For smaller bursts
> no DMA request is issued and the FIFO is drained by RX timeout.
> 
> In this case __dma_rx_do_complete() can legitimately see count == 0.
> 
> The current code exits early in this case and does not clear
> dma->rx_running, leaving the DMA state inconsistent. This can
> prevent RX DMA from restarting and may cause
> omap_8250_rx_dma_flush() to fail, marking DMA as broken.
> 
> Fix this by clearing dma->rx_running once the DMA transfer has
> completed or been terminated, even if no data was transferred.
> 
> Signed-off-by: Matthias Feser <mfe@KBSgmbhfr.onmicrosoft.com>
> Reviewed-by: Moteen Shah <m-shah@ti.com>
> ---
> Changes in v4:
> - Add blank line before dma->rx_running as suggested

Please properly start a new thread, don't have this patch be in reply to
another one, the "Re:" in it is a bit odd, don't you think?

And what commit id does this fix?  Should it be backported to stable
kernels?  If so, how far back?

thanks,

greg k-h

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

* [PATCH v5] serial: 8250_omap: clear rx_running on zero-length DMA completes
  2026-05-22 10:18         ` Moteen Shah
  2026-05-22 12:37           ` [PATCH v4] " Matthias Feser
@ 2026-05-26  7:35           ` Matthias Feser
  2026-06-02 18:37             ` andriy.shevchenko
  1 sibling, 1 reply; 14+ messages in thread
From: Matthias Feser @ 2026-05-26  7:35 UTC (permalink / raw)
  To: Moteen Shah, linux-serial@vger.kernel.org,
	gregkh@linuxfoundation.org, jirislaby@kernel.org
  Cc: linux-kernel@vger.kernel.org, k-willis@ti.com, msp@baylibre.com,
	andriy.shevchenko@linux.intel.com

On AM33xx RX DMA only triggers when the FIFO reaches the
configured threshold (typically 48 bytes). For smaller bursts
no DMA request is issued and the FIFO is drained by RX timeout.

In this case __dma_rx_do_complete() can legitimately see count == 0.

The current code exits early in this case and does not clear
dma->rx_running, leaving the DMA state inconsistent. This can
prevent RX DMA from restarting and may cause
omap_8250_rx_dma_flush() to fail, marking DMA as broken.

Fix this by clearing dma->rx_running once the DMA transfer has
completed or been terminated, even if no data was transferred.

Fixes: a5fd8945a478 ("serial: 8250: 8250_omap.c: Clear DMA RX running status only after DMA termination is done")
Cc: stable@vger.kernel.org
Signed-off-by: Matthias Feser <mfe@KBSgmbhfr.onmicrosoft.com>
Reviewed-by: Moteen Shah <m-shah@ti.com>
---
Changes in v5:
- Add missing metadata (Fixes tag and Cc: stable)

Changes in v4:
- Add blank line before dma->rx_running as suggested

Changes in v3:
- Move "Changes in v2" below the tear line as suggested

Changes in v2:
- Move dma->rx_running clear before the count check

 drivers/tty/serial/8250/8250_omap.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/8250/8250_omap.c b/drivers/tty/serial/8250/8250_omap.c
index c552c6b9a037..3c7775df27ef 100644
--- a/drivers/tty/serial/8250/8250_omap.c
+++ b/drivers/tty/serial/8250/8250_omap.c
@@ -944,11 +944,12 @@ static void __dma_rx_do_complete(struct uart_8250_port *p)
 				dev_err(p->port.dev, "teardown incomplete\n");
 		}
 	}
+
+	dma->rx_running = 0;
 	if (!count)
 		goto out;
 	ret = tty_insert_flip_string(tty_port, dma->rx_buf, count);
 
-	dma->rx_running = 0;
 	p->port.icount.rx += ret;
 	p->port.icount.buf_overrun += count - ret;
 out:
-- 
2.39.5


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

* Re: [PATCH v5] serial: 8250_omap: clear rx_running on zero-length DMA completes
  2026-05-26  7:35           ` [PATCH v5] " Matthias Feser
@ 2026-06-02 18:37             ` andriy.shevchenko
  2026-06-08 11:00               ` Matthias Feser
  0 siblings, 1 reply; 14+ messages in thread
From: andriy.shevchenko @ 2026-06-02 18:37 UTC (permalink / raw)
  To: Matthias Feser
  Cc: Moteen Shah, linux-serial@vger.kernel.org,
	gregkh@linuxfoundation.org, jirislaby@kernel.org,
	linux-kernel@vger.kernel.org, k-willis@ti.com, msp@baylibre.com

On Tue, May 26, 2026 at 07:35:09AM +0000, Matthias Feser wrote:
> On AM33xx RX DMA only triggers when the FIFO reaches the
> configured threshold (typically 48 bytes). For smaller bursts
> no DMA request is issued and the FIFO is drained by RX timeout.
> 
> In this case __dma_rx_do_complete() can legitimately see count == 0.
> 
> The current code exits early in this case and does not clear
> dma->rx_running, leaving the DMA state inconsistent. This can
> prevent RX DMA from restarting and may cause
> omap_8250_rx_dma_flush() to fail, marking DMA as broken.
> 
> Fix this by clearing dma->rx_running once the DMA transfer has
> completed or been terminated, even if no data was transferred.

...

> +	dma->rx_running = 0;
>  	if (!count)
>  		goto out;
>  	ret = tty_insert_flip_string(tty_port, dma->rx_buf, count);
>  
> -	dma->rx_running = 0;

I'm wondering if this opens a window when dma->rx_buf may be rewritten (or
unmapped or something else) before tty layer has a chance to insert bytes to
its ring buffer. I.o.w. is this change synchronous to other threads?

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v5] serial: 8250_omap: clear rx_running on zero-length DMA completes
  2026-06-02 18:37             ` andriy.shevchenko
@ 2026-06-08 11:00               ` Matthias Feser
  2026-06-08 11:35                 ` andriy.shevchenko
  0 siblings, 1 reply; 14+ messages in thread
From: Matthias Feser @ 2026-06-08 11:00 UTC (permalink / raw)
  To: andriy.shevchenko@linux.intel.com
  Cc: Moteen Shah, linux-serial@vger.kernel.org,
	gregkh@linuxfoundation.org, jirislaby@kernel.org,
	linux-kernel@vger.kernel.org, k-willis@ti.com, msp@baylibre.com

On Tue, Jun 02, 2026, Andy Shevchenko wrote:
> I'm wondering if this opens a window when dma->rx_buf may be
> rewritten (or unmapped or something else) before tty layer has
> a chance to insert bytes to its ring buffer. I.o.w. is this
> change synchronous to other threads?

Good point.

RX DMA can be started from the DMA callback, the IRQ path, and
runtime resume. These paths appear to be protected by the same
driver locking.

At the point where rx_running is cleared, DMA has already been
terminated.

So I don't see a window where rx_buf could be overwritten, but
please let me know if there is a path where this could happen.

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

* Re: [PATCH v5] serial: 8250_omap: clear rx_running on zero-length DMA completes
  2026-06-08 11:00               ` Matthias Feser
@ 2026-06-08 11:35                 ` andriy.shevchenko
  0 siblings, 0 replies; 14+ messages in thread
From: andriy.shevchenko @ 2026-06-08 11:35 UTC (permalink / raw)
  To: Matthias Feser
  Cc: Moteen Shah, linux-serial@vger.kernel.org,
	gregkh@linuxfoundation.org, jirislaby@kernel.org,
	linux-kernel@vger.kernel.org, k-willis@ti.com, msp@baylibre.com

On Mon, Jun 08, 2026 at 11:00:44AM +0000, Matthias Feser wrote:
> On Tue, Jun 02, 2026, Andy Shevchenko wrote:
> > I'm wondering if this opens a window when dma->rx_buf may be
> > rewritten (or unmapped or something else) before tty layer has
> > a chance to insert bytes to its ring buffer. I.o.w. is this
> > change synchronous to other threads?
> 
> Good point.
> 
> RX DMA can be started from the DMA callback, the IRQ path, and
> runtime resume. These paths appear to be protected by the same
> driver locking.
> 
> At the point where rx_running is cleared, DMA has already been
> terminated.
> 
> So I don't see a window where rx_buf could be overwritten, but
> please let me know if there is a path where this could happen.

I don't see either, that's why I was wondering. Btw, does AI notice
anything of a such? I haven't checked Sashiko myself, others may
have also run some other AI tools for that.

-- 
With Best Regards,
Andy Shevchenko



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

end of thread, other threads:[~2026-06-08 11:35 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-21 13:30 [PATCH] serial: 8250_omap: clear rx_running on zero-length DMA completes Matthias Feser
2026-05-22  5:40 ` Moteen Shah
2026-05-22  8:24   ` [PATCH v2] " Matthias Feser
2026-05-22  8:25     ` Moteen Shah
2026-05-22  8:28     ` Moteen Shah
2026-05-22  9:02       ` AW: [PATCH v3] " Matthias Feser
2026-05-22 10:18         ` Moteen Shah
2026-05-22 12:37           ` [PATCH v4] " Matthias Feser
2026-05-23  5:47             ` gregkh
2026-05-26  7:35           ` [PATCH v5] " Matthias Feser
2026-06-02 18:37             ` andriy.shevchenko
2026-06-08 11:00               ` Matthias Feser
2026-06-08 11:35                 ` andriy.shevchenko
2026-05-22  8:46     ` [PATCH v2] " gregkh

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