mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Frank Li <Frank.li@nxp.com>
To: Claudiu <claudiu.beznea@tuxon.dev>
Cc: vkoul@kernel.org, geert+renesas@glider.be,
	biju.das.jz@bp.renesas.com, fabrizio.castro.jz@renesas.com,
	prabhakar.mahadev-lad.rj@bp.renesas.com,
	dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org,
	Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>,
	stable@vger.kernel.org
Subject: Re: [PATCH v8 1/8] dmaengine: sh: rz-dmac: Protect the driver specific lists
Date: Wed, 25 Feb 2026 11:17:04 -0500	[thread overview]
Message-ID: <aZ8ggNdMiCDkZcBv@lizhi-Precision-Tower-5810> (raw)
In-Reply-To: <20260120133330.3738850-2-claudiu.beznea.uj@bp.renesas.com>

On Tue, Jan 20, 2026 at 03:33:23PM +0200, Claudiu wrote:
> From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
>
> The driver lists (ld_free, ld_queue) are used in
> rz_dmac_free_chan_resources(), rz_dmac_terminate_all(),
> rz_dmac_issue_pending(), and rz_dmac_irq_handler_thread(), all under
> the virtual channel lock. Take the same lock in rz_dmac_prep_slave_sg()
> and rz_dmac_prep_dma_memcpy() as well to avoid concurrency issues, since
> these functions also check whether the lists are empty and update or
> remove list entries.
>
> Fixes: 5000d37042a6 ("dmaengine: sh: Add DMAC driver for RZ/G2L SoC")
> Cc: stable@vger.kernel.org
> Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
> ---

Reviewed-by: Frank Li <Frank.Li@nxp.com>
>
> Changes in v8:
> - none
>
> Changes in v7:
> - none
>
> Changes in v6:
> - none
>
> Changes in v5:
> - none, this patch is new
>
>  drivers/dma/sh/rz-dmac.c | 57 ++++++++++++++++++++++------------------
>  1 file changed, 32 insertions(+), 25 deletions(-)
>
> diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c
> index 3dde4b006bcc..36f5fc80a17a 100644
> --- a/drivers/dma/sh/rz-dmac.c
> +++ b/drivers/dma/sh/rz-dmac.c
> @@ -10,6 +10,7 @@
>   */
>
>  #include <linux/bitfield.h>
> +#include <linux/cleanup.h>
>  #include <linux/dma-mapping.h>
>  #include <linux/dmaengine.h>
>  #include <linux/interrupt.h>
> @@ -453,6 +454,7 @@ static int rz_dmac_alloc_chan_resources(struct dma_chan *chan)
>  		if (!desc)
>  			break;
>
> +		/* No need to lock. This is called only for the 1st client. */
>  		list_add_tail(&desc->node, &channel->ld_free);
>  		channel->descs_allocated++;
>  	}
> @@ -508,18 +510,21 @@ rz_dmac_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dest, dma_addr_t src,
>  	dev_dbg(dmac->dev, "%s channel: %d src=0x%pad dst=0x%pad len=%zu\n",
>  		__func__, channel->index, &src, &dest, len);
>
> -	if (list_empty(&channel->ld_free))
> -		return NULL;
> +	scoped_guard(spinlock_irqsave, &channel->vc.lock) {
> +		if (list_empty(&channel->ld_free))
> +			return NULL;
> +
> +		desc = list_first_entry(&channel->ld_free, struct rz_dmac_desc, node);
>
> -	desc = list_first_entry(&channel->ld_free, struct rz_dmac_desc, node);
> +		desc->type = RZ_DMAC_DESC_MEMCPY;
> +		desc->src = src;
> +		desc->dest = dest;
> +		desc->len = len;
> +		desc->direction = DMA_MEM_TO_MEM;
>
> -	desc->type = RZ_DMAC_DESC_MEMCPY;
> -	desc->src = src;
> -	desc->dest = dest;
> -	desc->len = len;
> -	desc->direction = DMA_MEM_TO_MEM;
> +		list_move_tail(channel->ld_free.next, &channel->ld_queue);
> +	}
>
> -	list_move_tail(channel->ld_free.next, &channel->ld_queue);
>  	return vchan_tx_prep(&channel->vc, &desc->vd, flags);
>  }
>
> @@ -535,27 +540,29 @@ rz_dmac_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
>  	int dma_length = 0;
>  	int i = 0;
>
> -	if (list_empty(&channel->ld_free))
> -		return NULL;
> +	scoped_guard(spinlock_irqsave, &channel->vc.lock) {
> +		if (list_empty(&channel->ld_free))
> +			return NULL;
>
> -	desc = list_first_entry(&channel->ld_free, struct rz_dmac_desc, node);
> +		desc = list_first_entry(&channel->ld_free, struct rz_dmac_desc, node);
>
> -	for_each_sg(sgl, sg, sg_len, i) {
> -		dma_length += sg_dma_len(sg);
> -	}
> +		for_each_sg(sgl, sg, sg_len, i)
> +			dma_length += sg_dma_len(sg);
>
> -	desc->type = RZ_DMAC_DESC_SLAVE_SG;
> -	desc->sg = sgl;
> -	desc->sgcount = sg_len;
> -	desc->len = dma_length;
> -	desc->direction = direction;
> +		desc->type = RZ_DMAC_DESC_SLAVE_SG;
> +		desc->sg = sgl;
> +		desc->sgcount = sg_len;
> +		desc->len = dma_length;
> +		desc->direction = direction;
>
> -	if (direction == DMA_DEV_TO_MEM)
> -		desc->src = channel->src_per_address;
> -	else
> -		desc->dest = channel->dst_per_address;
> +		if (direction == DMA_DEV_TO_MEM)
> +			desc->src = channel->src_per_address;
> +		else
> +			desc->dest = channel->dst_per_address;
> +
> +		list_move_tail(channel->ld_free.next, &channel->ld_queue);
> +	}
>
> -	list_move_tail(channel->ld_free.next, &channel->ld_queue);
>  	return vchan_tx_prep(&channel->vc, &desc->vd, flags);
>  }
>
> --
> 2.43.0
>

  reply	other threads:[~2026-02-25 16:17 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-20 13:33 [PATCH v8 0/8] dmaengine: sh: rz-dmac: Add tx_status and pause/resume support Claudiu
2026-01-20 13:33 ` [PATCH v8 1/8] dmaengine: sh: rz-dmac: Protect the driver specific lists Claudiu
2026-02-25 16:17   ` Frank Li [this message]
2026-01-20 13:33 ` [PATCH v8 2/8] dmaengine: sh: rz-dmac: Move CHCTRL updates under spinlock Claudiu
2026-02-25 16:19   ` Frank Li
2026-01-20 13:33 ` [PATCH v8 3/8] dmaengine: sh: rz-dmac: Drop read of CHCTRL register Claudiu
2026-02-25 16:20   ` Frank Li
2026-01-20 13:33 ` [PATCH v8 4/8] dmaengine: sh: rz-dmac: Drop goto instruction and label Claudiu
2026-02-25 16:23   ` Frank Li
2026-01-20 13:33 ` [PATCH v8 5/8] dmaengine: sh: rz-dmac: Drop unnecessary local_irq_save() call Claudiu
2026-02-25 16:23   ` Frank Li
2026-01-20 13:33 ` [PATCH v8 6/8] dmaengine: sh: rz-dmac: Add rz_dmac_invalidate_lmdesc() Claudiu
2026-02-25 16:26   ` Frank Li
2026-01-20 13:33 ` [PATCH v8 7/8] dmaengine: sh: rz-dmac: Add device_tx_status() callback Claudiu
2026-02-25 16:43   ` Frank Li
2026-03-02 13:49     ` Claudiu Beznea
2026-03-04 16:37       ` Frank Li
2026-01-20 13:33 ` [PATCH v8 8/8] dmaengine: sh: rz-dmac: Add device_{pause,resume}() callbacks Claudiu
2026-02-25 16:49   ` Frank Li
2026-03-02 13:50     ` Claudiu Beznea
2026-01-29  9:44 ` [PATCH v8 0/8] dmaengine: sh: rz-dmac: Add tx_status and pause/resume support Claudiu Beznea

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aZ8ggNdMiCDkZcBv@lizhi-Precision-Tower-5810 \
    --to=frank.li@nxp.com \
    --cc=biju.das.jz@bp.renesas.com \
    --cc=claudiu.beznea.uj@bp.renesas.com \
    --cc=claudiu.beznea@tuxon.dev \
    --cc=dmaengine@vger.kernel.org \
    --cc=fabrizio.castro.jz@renesas.com \
    --cc=geert+renesas@glider.be \
    --cc=linux-kernel@vger.kernel.org \
    --cc=prabhakar.mahadev-lad.rj@bp.renesas.com \
    --cc=stable@vger.kernel.org \
    --cc=vkoul@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®