Re: [PATCH 5/9] dmaengine: dw-edma: HDMA: Fix possible race condition in remote setup

From: Serge Semin
Date: Mon Jun 19 2023 - 13:16:03 EST


On Fri, Jun 09, 2023 at 10:16:50AM +0200, Köry Maincent wrote:
> From: Kory Maincent <kory.maincent@xxxxxxxxxxx>
>
> When writing the linked list elements and pointer the control need to be
> written at the end. If the control is written and the SAR and DAR not
> stored we could face a race condition.
>
> Fixes: e74c39573d35 ("dmaengine: dw-edma: Add support for native HDMA")
> Signed-off-by: Kory Maincent <kory.maincent@xxxxxxxxxxx>

Once again. Is this a hypothetical bug or have you actually
experienced the denoted problem? If you do please describe the
circumstances, give more details. Otherwise it sounds weird. Here is
why.

DW eDMA HW manual states that the control LL DWORD is indeed supposed
to be written after the rest of the descriptor DWORDs are written. But
AFAICS it's only relevant for the LL tree entries recycling. Current
DW eDMA driver design doesn't truly implement that pattern. Instead
the DMA transfer is halted at the end of the chunk. Then the engine is
recharged with the next chunk and execution is started over. So the
runtime recycling isn't implemented (alas) for which the CB flag of
the control DWORD needs to be updated only after the rest of the LLI
fields.

If you described a hypothetical problem then it would be ok to accept
the change for the sake of consistency but I would have dropped the
Fixes tag and updated the patch description with more details of the
race condition you are talking about.

-Serge(y)

> ---
>
> This patch is fixing a commit which is only in dmaengine tree and not
> merged mainline.
> ---
> drivers/dma/dw-edma/dw-hdma-v0-core.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/dma/dw-edma/dw-hdma-v0-core.c b/drivers/dma/dw-edma/dw-hdma-v0-core.c
> index 0b77ddbe91b5..f28e1671a753 100644
> --- a/drivers/dma/dw-edma/dw-hdma-v0-core.c
> +++ b/drivers/dma/dw-edma/dw-hdma-v0-core.c
> @@ -162,10 +162,10 @@ static void dw_hdma_v0_write_ll_data(struct dw_edma_chunk *chunk, int i,
> } else {
> struct dw_hdma_v0_lli __iomem *lli = chunk->ll_region.vaddr.io + ofs;
>
> - writel(control, &lli->control);
> writel(size, &lli->transfer_size);
> writeq(sar, &lli->sar.reg);
> writeq(dar, &lli->dar.reg);
> + writel(control, &lli->control);
> }
> }
>
> @@ -182,8 +182,8 @@ static void dw_hdma_v0_write_ll_link(struct dw_edma_chunk *chunk,
> } else {
> struct dw_hdma_v0_llp __iomem *llp = chunk->ll_region.vaddr.io + ofs;
>
> - writel(control, &llp->control);
> writeq(pointer, &llp->llp.reg);
> + writel(control, &llp->control);
> }
> }
>
> --
> 2.25.1
>