linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/4] 8250: DMA Fixes
@ 2022-11-08 12:19 Ilpo Järvinen
  2022-11-08 12:19 ` [PATCH v2 1/4] serial: 8250: Fall back to non-DMA Rx if IIR_RDI occurs Ilpo Järvinen
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Ilpo Järvinen @ 2022-11-08 12:19 UTC (permalink / raw)
  To: linux-serial, Greg Kroah-Hartman, Jiri Slaby, Andy Shevchenko
  Cc: linux-kernel, Gilles BULOZ, Ilpo Järvinen

Here are a number of 8250 DMA related fixes. The last one seems the
most serious problem able to corrupt the payload ordering.

v2:
- Tweak configure logic to match Andy's suggestion
- Cleaned up the tags from the oneliner patch

Ilpo Järvinen (4):
  serial: 8250: Fall back to non-DMA Rx if IIR_RDI occurs
  serial: 8250_lpss: Configure DMA also w/o DMA filter
  serial: 8250_lpss: Use 16B DMA burst with Elkhart Lake
  serial: 8250: Flush DMA Rx on RLSI

 drivers/tty/serial/8250/8250_lpss.c | 17 +++++++++++++----
 drivers/tty/serial/8250/8250_port.c |  7 +++++--
 2 files changed, 18 insertions(+), 6 deletions(-)

-- 
2.30.2


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

* [PATCH v2 1/4] serial: 8250: Fall back to non-DMA Rx if IIR_RDI occurs
  2022-11-08 12:19 [PATCH v2 0/4] 8250: DMA Fixes Ilpo Järvinen
@ 2022-11-08 12:19 ` Ilpo Järvinen
  2022-11-08 12:19 ` [PATCH v2 2/4] serial: 8250_lpss: Configure DMA also w/o DMA filter Ilpo Järvinen
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Ilpo Järvinen @ 2022-11-08 12:19 UTC (permalink / raw)
  To: linux-serial, Greg Kroah-Hartman, Jiri Slaby, Andy Shevchenko,
	Heikki Krogerus, linux-kernel
  Cc: Gilles BULOZ, Ilpo Järvinen, stable, Srikanth Thokala,
	Aman Kumar

DW UART sometimes triggers IIR_RDI during DMA Rx when IIR_RX_TIMEOUT
should have been triggered instead. Since IIR_RDI has higher priority
than IIR_RX_TIMEOUT, this causes the Rx to hang into interrupt loop.
The problem seems to occur at least with some combinations of
small-sized transfers (I've reproduced the problem on Elkhart Lake PSE
UARTs).

If there's already an on-going Rx DMA and IIR_RDI triggers, fall
graciously back to non-DMA Rx. That is, behave as if IIR_RX_TIMEOUT had
occurred.

8250_omap already considers IIR_RDI similar to this change so its
nothing unheard of.

Fixes: 75df022b5f89 ("serial: 8250_dma: Fix RX handling")
Cc: <stable@vger.kernel.org>
Co-developed-by: Srikanth Thokala <srikanth.thokala@intel.com>
Signed-off-by: Srikanth Thokala <srikanth.thokala@intel.com>
Co-developed-by: Aman Kumar <aman.kumar@intel.com>
Signed-off-by: Aman Kumar <aman.kumar@intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
 drivers/tty/serial/8250/8250_port.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index fe8662cd9402..92dd18716169 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -1897,6 +1897,10 @@ EXPORT_SYMBOL_GPL(serial8250_modem_status);
 static bool handle_rx_dma(struct uart_8250_port *up, unsigned int iir)
 {
 	switch (iir & 0x3f) {
+	case UART_IIR_RDI:
+		if (!up->dma->rx_running)
+			break;
+		fallthrough;
 	case UART_IIR_RX_TIMEOUT:
 		serial8250_rx_dma_flush(up);
 		fallthrough;
-- 
2.30.2


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

* [PATCH v2 2/4] serial: 8250_lpss: Configure DMA also w/o DMA filter
  2022-11-08 12:19 [PATCH v2 0/4] 8250: DMA Fixes Ilpo Järvinen
  2022-11-08 12:19 ` [PATCH v2 1/4] serial: 8250: Fall back to non-DMA Rx if IIR_RDI occurs Ilpo Järvinen
@ 2022-11-08 12:19 ` Ilpo Järvinen
  2022-11-08 12:19 ` [PATCH v2 3/4] serial: 8250_lpss: Use 16B DMA burst with Elkhart Lake Ilpo Järvinen
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Ilpo Järvinen @ 2022-11-08 12:19 UTC (permalink / raw)
  To: linux-serial, Greg Kroah-Hartman, Jiri Slaby, Andy Shevchenko,
	Ilpo Järvinen, linux-kernel
  Cc: Gilles BULOZ, stable

If the platform doesn't use DMA device filter (as is the case with
Elkhart Lake), whole lpss8250_dma_setup() setup is skipped. This
results in skipping also *_maxburst setup which is undesirable.
Refactor lpss8250_dma_setup() to configure DMA even if filter is not
setup.

Cc: stable <stable@kernel.org>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
 drivers/tty/serial/8250/8250_lpss.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_lpss.c b/drivers/tty/serial/8250/8250_lpss.c
index 44cc755b1a29..7d9cddbfef40 100644
--- a/drivers/tty/serial/8250/8250_lpss.c
+++ b/drivers/tty/serial/8250/8250_lpss.c
@@ -277,8 +277,13 @@ static int lpss8250_dma_setup(struct lpss8250 *lpss, struct uart_8250_port *port
 	struct dw_dma_slave *rx_param, *tx_param;
 	struct device *dev = port->port.dev;
 
-	if (!lpss->dma_param.dma_dev)
+	if (!lpss->dma_param.dma_dev) {
+		dma = port->dma;
+		if (dma)
+			goto out_configuration_only;
+
 		return 0;
+	}
 
 	rx_param = devm_kzalloc(dev, sizeof(*rx_param), GFP_KERNEL);
 	if (!rx_param)
@@ -289,16 +294,18 @@ static int lpss8250_dma_setup(struct lpss8250 *lpss, struct uart_8250_port *port
 		return -ENOMEM;
 
 	*rx_param = lpss->dma_param;
-	dma->rxconf.src_maxburst = lpss->dma_maxburst;
-
 	*tx_param = lpss->dma_param;
-	dma->txconf.dst_maxburst = lpss->dma_maxburst;
 
 	dma->fn = lpss8250_dma_filter;
 	dma->rx_param = rx_param;
 	dma->tx_param = tx_param;
 
 	port->dma = dma;
+
+out_configuration_only:
+	dma->rxconf.src_maxburst = lpss->dma_maxburst;
+	dma->txconf.dst_maxburst = lpss->dma_maxburst;
+
 	return 0;
 }
 
-- 
2.30.2


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

* [PATCH v2 3/4] serial: 8250_lpss: Use 16B DMA burst with Elkhart Lake
  2022-11-08 12:19 [PATCH v2 0/4] 8250: DMA Fixes Ilpo Järvinen
  2022-11-08 12:19 ` [PATCH v2 1/4] serial: 8250: Fall back to non-DMA Rx if IIR_RDI occurs Ilpo Järvinen
  2022-11-08 12:19 ` [PATCH v2 2/4] serial: 8250_lpss: Configure DMA also w/o DMA filter Ilpo Järvinen
@ 2022-11-08 12:19 ` Ilpo Järvinen
  2022-11-08 12:19 ` [PATCH v2 4/4] serial: 8250: Flush DMA Rx on RLSI Ilpo Järvinen
  2022-11-08 12:47 ` [PATCH v2 0/4] 8250: DMA Fixes Andy Shevchenko
  4 siblings, 0 replies; 6+ messages in thread
From: Ilpo Järvinen @ 2022-11-08 12:19 UTC (permalink / raw)
  To: linux-serial, Greg Kroah-Hartman, Jiri Slaby, Andy Shevchenko,
	Ilpo Järvinen, linux-kernel
  Cc: Gilles BULOZ, stable, Wentong Wu

Configure DMA to use 16B burst size with Elkhart Lake. This makes the
bus use more efficient and works around an issue which occurs with the
previously used 1B.

The fix was initially developed by Srikanth Thokala and Aman Kumar.
This together with the previous config change is the cleaned up version
of the original fix.

Fixes: 0a9410b981e9 ("serial: 8250_lpss: Enable DMA on Intel Elkhart Lake")
Cc: <stable@vger.kernel.org> # serial: 8250_lpss: Configure DMA also w/o DMA filter
Reported-by: Wentong Wu <wentong.wu@intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
 drivers/tty/serial/8250/8250_lpss.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/tty/serial/8250/8250_lpss.c b/drivers/tty/serial/8250/8250_lpss.c
index 7d9cddbfef40..0e43bdfb7459 100644
--- a/drivers/tty/serial/8250/8250_lpss.c
+++ b/drivers/tty/serial/8250/8250_lpss.c
@@ -174,6 +174,8 @@ static int ehl_serial_setup(struct lpss8250 *lpss, struct uart_port *port)
 	 */
 	up->dma = dma;
 
+	lpss->dma_maxburst = 16;
+
 	port->set_termios = dw8250_do_set_termios;
 
 	return 0;
-- 
2.30.2


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

* [PATCH v2 4/4] serial: 8250: Flush DMA Rx on RLSI
  2022-11-08 12:19 [PATCH v2 0/4] 8250: DMA Fixes Ilpo Järvinen
                   ` (2 preceding siblings ...)
  2022-11-08 12:19 ` [PATCH v2 3/4] serial: 8250_lpss: Use 16B DMA burst with Elkhart Lake Ilpo Järvinen
@ 2022-11-08 12:19 ` Ilpo Järvinen
  2022-11-08 12:47 ` [PATCH v2 0/4] 8250: DMA Fixes Andy Shevchenko
  4 siblings, 0 replies; 6+ messages in thread
From: Ilpo Järvinen @ 2022-11-08 12:19 UTC (permalink / raw)
  To: linux-serial, Greg Kroah-Hartman, Jiri Slaby, Andy Shevchenko,
	Heikki Krogerus, linux-kernel
  Cc: Gilles BULOZ, Ilpo Järvinen, stable

Returning true from handle_rx_dma() without flushing DMA first creates
a data ordering hazard. If DMA Rx has handled any character at the
point when RLSI occurs, the non-DMA path handles any pending characters
jumping them ahead of those characters that are pending under DMA.

Fixes: 75df022b5f89 ("serial: 8250_dma: Fix RX handling")
Cc: <stable@vger.kernel.org>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
 drivers/tty/serial/8250/8250_port.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index 92dd18716169..388172289627 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -1901,10 +1901,9 @@ static bool handle_rx_dma(struct uart_8250_port *up, unsigned int iir)
 		if (!up->dma->rx_running)
 			break;
 		fallthrough;
+	case UART_IIR_RLSI:
 	case UART_IIR_RX_TIMEOUT:
 		serial8250_rx_dma_flush(up);
-		fallthrough;
-	case UART_IIR_RLSI:
 		return true;
 	}
 	return up->dma->rx_dma(up);
-- 
2.30.2


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

* Re: [PATCH v2 0/4] 8250: DMA Fixes
  2022-11-08 12:19 [PATCH v2 0/4] 8250: DMA Fixes Ilpo Järvinen
                   ` (3 preceding siblings ...)
  2022-11-08 12:19 ` [PATCH v2 4/4] serial: 8250: Flush DMA Rx on RLSI Ilpo Järvinen
@ 2022-11-08 12:47 ` Andy Shevchenko
  4 siblings, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2022-11-08 12:47 UTC (permalink / raw)
  To: Ilpo Järvinen
  Cc: linux-serial, Greg Kroah-Hartman, Jiri Slaby, linux-kernel,
	Gilles BULOZ

On Tue, Nov 08, 2022 at 02:19:48PM +0200, Ilpo Järvinen wrote:
> Here are a number of 8250 DMA related fixes. The last one seems the
> most serious problem able to corrupt the payload ordering.

Thank you for the update!
LGTM,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

> v2:
> - Tweak configure logic to match Andy's suggestion
> - Cleaned up the tags from the oneliner patch
> 
> Ilpo Järvinen (4):
>   serial: 8250: Fall back to non-DMA Rx if IIR_RDI occurs
>   serial: 8250_lpss: Configure DMA also w/o DMA filter
>   serial: 8250_lpss: Use 16B DMA burst with Elkhart Lake
>   serial: 8250: Flush DMA Rx on RLSI

-- 
With Best Regards,
Andy Shevchenko



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

end of thread, other threads:[~2022-11-08 12:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-08 12:19 [PATCH v2 0/4] 8250: DMA Fixes Ilpo Järvinen
2022-11-08 12:19 ` [PATCH v2 1/4] serial: 8250: Fall back to non-DMA Rx if IIR_RDI occurs Ilpo Järvinen
2022-11-08 12:19 ` [PATCH v2 2/4] serial: 8250_lpss: Configure DMA also w/o DMA filter Ilpo Järvinen
2022-11-08 12:19 ` [PATCH v2 3/4] serial: 8250_lpss: Use 16B DMA burst with Elkhart Lake Ilpo Järvinen
2022-11-08 12:19 ` [PATCH v2 4/4] serial: 8250: Flush DMA Rx on RLSI Ilpo Järvinen
2022-11-08 12:47 ` [PATCH v2 0/4] 8250: DMA Fixes 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).