[3/4] serial: qcom-geni: fix mapping of empty DMA buffer

Message ID 20230307164405.14218-4-johan+linaro@kernel.org
State New
Headers
Series serial: qcom-geni: fix console shutdown hang |

Commit Message

Johan Hovold March 7, 2023, 4:44 p.m. UTC
  Make sure that there is data in the ring buffer before trying to set up
a zero-length DMA transfer.

This specifically fixes the following warning when unmapping the empty
buffer on the sc8280xp-crd:

   WARNING: CPU: 0 PID: 138 at drivers/iommu/dma-iommu.c:1046 iommu_dma_unmap_page+0xbc/0xd8
   ...
   Call trace:
    iommu_dma_unmap_page+0xbc/0xd8
    dma_unmap_page_attrs+0x30/0x1c8
    geni_se_tx_dma_unprep+0x28/0x38
    qcom_geni_serial_isr+0x358/0x75c

Fixes: 2aaa43c70778 ("tty: serial: qcom-geni-serial: add support for serial engine DMA")
Cc: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Johan Hovold <johan+linaro@kernel.org>
---
 drivers/tty/serial/qcom_geni_serial.c | 3 +++
 1 file changed, 3 insertions(+)
  

Comments

Doug Anderson March 7, 2023, 6:41 p.m. UTC | #1
Hi,

On Tue, Mar 7, 2023 at 8:43 AM Johan Hovold <johan+linaro@kernel.org> wrote:
>
> Make sure that there is data in the ring buffer before trying to set up
> a zero-length DMA transfer.
>
> This specifically fixes the following warning when unmapping the empty
> buffer on the sc8280xp-crd:
>
>    WARNING: CPU: 0 PID: 138 at drivers/iommu/dma-iommu.c:1046 iommu_dma_unmap_page+0xbc/0xd8
>    ...
>    Call trace:
>     iommu_dma_unmap_page+0xbc/0xd8
>     dma_unmap_page_attrs+0x30/0x1c8
>     geni_se_tx_dma_unprep+0x28/0x38
>     qcom_geni_serial_isr+0x358/0x75c
>
> Fixes: 2aaa43c70778 ("tty: serial: qcom-geni-serial: add support for serial engine DMA")
> Cc: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> Signed-off-by: Johan Hovold <johan+linaro@kernel.org>
> ---
>  drivers/tty/serial/qcom_geni_serial.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/drivers/tty/serial/qcom_geni_serial.c b/drivers/tty/serial/qcom_geni_serial.c
> index 2aa3872e6283..9871225b2f9b 100644
> --- a/drivers/tty/serial/qcom_geni_serial.c
> +++ b/drivers/tty/serial/qcom_geni_serial.c
> @@ -631,6 +631,9 @@ static void qcom_geni_serial_start_tx_dma(struct uart_port *uport)
>         if (port->tx_dma_addr)
>                 return;
>
> +       if (uart_circ_empty(xmit))
> +               return;

I guess you could remove the uart_circ_empty() test in
qcom_geni_serial_handle_tx_dma() now? In any case, with or without
that:

Reviewed-by: Douglas Anderson <dianders@chromium.org>
  
Johan Hovold March 8, 2023, 7:51 a.m. UTC | #2
On Tue, Mar 07, 2023 at 10:41:46AM -0800, Doug Anderson wrote:
> Hi,
> 
> On Tue, Mar 7, 2023 at 8:43 AM Johan Hovold <johan+linaro@kernel.org> wrote:
> >
> > Make sure that there is data in the ring buffer before trying to set up
> > a zero-length DMA transfer.
> >
> > This specifically fixes the following warning when unmapping the empty
> > buffer on the sc8280xp-crd:
> >
> >    WARNING: CPU: 0 PID: 138 at drivers/iommu/dma-iommu.c:1046 iommu_dma_unmap_page+0xbc/0xd8
> >    ...
> >    Call trace:
> >     iommu_dma_unmap_page+0xbc/0xd8
> >     dma_unmap_page_attrs+0x30/0x1c8
> >     geni_se_tx_dma_unprep+0x28/0x38
> >     qcom_geni_serial_isr+0x358/0x75c
> >
> > Fixes: 2aaa43c70778 ("tty: serial: qcom-geni-serial: add support for serial engine DMA")
> > Cc: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> > Signed-off-by: Johan Hovold <johan+linaro@kernel.org>
> > ---
> >  drivers/tty/serial/qcom_geni_serial.c | 3 +++
> >  1 file changed, 3 insertions(+)
> >
> > diff --git a/drivers/tty/serial/qcom_geni_serial.c b/drivers/tty/serial/qcom_geni_serial.c
> > index 2aa3872e6283..9871225b2f9b 100644
> > --- a/drivers/tty/serial/qcom_geni_serial.c
> > +++ b/drivers/tty/serial/qcom_geni_serial.c
> > @@ -631,6 +631,9 @@ static void qcom_geni_serial_start_tx_dma(struct uart_port *uport)
> >         if (port->tx_dma_addr)
> >                 return;
> >
> > +       if (uart_circ_empty(xmit))
> > +               return;
> 
> I guess you could remove the uart_circ_empty() test in
> qcom_geni_serial_handle_tx_dma() now?

I considered that, but decided to leave it in as it makes the flow in
qcom_geni_serial_handle_tx_dma() a bit more obvious (and that function
already handles the related uart_write_wakeup() which the check could
potentially be combined with).

> In any case, with or without that:
> 
> Reviewed-by: Douglas Anderson <dianders@chromium.org>

Thanks for reviewing.

Johan
  

Patch

diff --git a/drivers/tty/serial/qcom_geni_serial.c b/drivers/tty/serial/qcom_geni_serial.c
index 2aa3872e6283..9871225b2f9b 100644
--- a/drivers/tty/serial/qcom_geni_serial.c
+++ b/drivers/tty/serial/qcom_geni_serial.c
@@ -631,6 +631,9 @@  static void qcom_geni_serial_start_tx_dma(struct uart_port *uport)
 	if (port->tx_dma_addr)
 		return;
 
+	if (uart_circ_empty(xmit))
+		return;
+
 	xmit_size = uart_circ_chars_pending(xmit);
 	if (xmit_size < WAKEUP_CHARS)
 		uart_write_wakeup(uport);