From: Claudiu Beznea <claudiu.beznea@tuxon.dev>
To: vkoul@kernel.org, Frank.Li@kernel.org, lgirdwood@gmail.com,
broonie@kernel.org, perex@perex.cz, tiwai@suse.com,
biju.das.jz@bp.renesas.com,
prabhakar.mahadev-lad.rj@bp.renesas.com, p.zabel@pengutronix.de,
geert+renesas@glider.be, fabrizio.castro.jz@renesas.com,
long.luu.ur@renesas.com
Cc: dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-sound@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Subject: sashiko.dev review (Re: [PATCH v4 13/17] dmaengine: sh: rz-dmac: Add cyclic DMA support)
Date: Mon, 20 Apr 2026 15:51:03 +0300 [thread overview]
Message-ID: <047007f9-d5cc-401a-846a-ab13ad0380b6@tuxon.dev> (raw)
In-Reply-To: <20260411114303.2814115-14-claudiu.beznea.uj@bp.renesas.com>
> commit cb66d54ec04fe2598560135c66410142d7295633
> Author: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
> dmaengine: sh: rz-dmac: Add cyclic DMA support
> This commit introduces cyclic DMA support to the RZ DMAC driver. It adds a
> per-channel status bit to mark cyclic channels and sets it during the DMA
> prepare callback. The IRQ handler then uses this bit to determine whether
> to invoke the cyclic callback function.
> > diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c
> > index 958ee45abc700..9a10430109e59 100644
> > --- a/drivers/dma/sh/rz-dmac.c
> > +++ b/drivers/dma/sh/rz-dmac.c
> [ ... ]
> > @@ -586,6 +645,55 @@ rz_dmac_prep_slave_sg(struct dma_chan *chan, struct
scatterlist *sgl,
> [ ... ]
> > + scoped_guard(spinlock_irqsave, &channel->vc.lock) {
> > + if (channel->status & BIT(RZ_DMAC_CHAN_STATUS_CYCLIC))
> > + return NULL;
> > +
> > + desc = list_first_entry_or_null(&channel->ld_free, struct
rz_dmac_desc, node);
> > + if (!desc)
> > + return NULL;
> > +
> > + list_del(&desc->node);
> > +
> > + channel->status |= BIT(RZ_DMAC_CHAN_STATUS_CYCLIC);
> > + }
> > +
> > + desc->type = RZ_DMAC_DESC_CYCLIC;
> > + desc->sgcount = period_len;
> Can tracking cyclic state via the global channel->status flag lead to
> cross-descriptor state corruption?
> If a prepared cyclic descriptor is freed via dmaengine_desc_free(), the
> global flag might not be cleared during virt-dma desc release, leaving
> the channel poisoned.
dmaengine_desc_free() works only for reusable descriptors. This functionality is
not implemented by the rz-dmac driver.
> Also, because the lock is dropped when exiting the scoped_guard before
> vchan_tx_prep() is called, a concurrent terminate_all() could potentially
> clear the flag before the descriptor is queued.
> Could the driver rely on the desc->type field instead of a global state
> flag to identify cyclic transfers?
I'm going to explore that but I think this will complicates the code further.
Vinod, Frank,
Could you please let me know if this is a valid expected usecase?
> [ ... ]
> > @@ -733,9 +841,18 @@ static u32
rz_dmac_calculate_residue_bytes_in_vd(struct rz_dmac_chan *channel,
> > }
> >
> > /* Calculate residue from next lmdesc to end of virtual desc */
> > - while (lmdesc->chcfg & CHCFG_DEM) {
> > - residue += lmdesc->tb;
> > - lmdesc = rz_dmac_get_next_lmdesc(channel->lmdesc.base, lmdesc);
> > + if (channel->status & BIT(RZ_DMAC_CHAN_STATUS_CYCLIC)) {
> > + u32 start_lmdesc_addr = rz_dmac_lmdesc_addr(channel,
desc->start_lmdesc);
> > +
> > + while (lmdesc->nxla != start_lmdesc_addr) {
> > + residue += lmdesc->tb;
> > + lmdesc = rz_dmac_get_next_lmdesc(channel->lmdesc.base,
lmdesc);
> > + }
> Will this loop calculate a monotonically decreasing residue for cyclic
> transfers?
Yes, according to my testing.
> ALSA requires the residue to be the exact, monotonically decreasing number
> of bytes remaining in the buffer. Iterating until the end of the descriptor
> ring and adding the lengths of subsequent periods might cause the returned
> residue to jump wildly depending on which period is currently executing.
> For example, in a 3-period buffer (A, B, C), executing period B might
> return a much larger residue than executing period A, since it would add
> the remaining bytes in the ring differently.
> Could this non-monotonic behavior trigger 'PCM position is invalid'
> errors in the ALSA framework, breaking audio playback?
Never see this in my testing.
> [ ... ]
> > @@ -924,10 +1041,14 @@ static irqreturn_t rz_dmac_irq_handler_thread(int
irq, void *dev_id)
> > if (!desc)
> > return IRQ_HANDLED;
> >
> > - vchan_cookie_complete(&desc->vd);
> > - channel->desc = NULL;
> > + if (channel->status & BIT(RZ_DMAC_CHAN_STATUS_CYCLIC)) {
> > + vchan_cyclic_callback(&desc->vd);
> > + } else {
> > + vchan_cookie_complete(&desc->vd);
> > + channel->desc = NULL;
> If a non-cyclic transfer completes while the global channel->status flag
> is set, could the IRQ handler erroneously call vchan_cyclic_callback()
> instead of vchan_cookie_complete(), permanently hanging the channel?
> Checking desc->type == RZ_DMAC_DESC_CYCLIC here instead might prevent
> misidentifying non-cyclic transfers as cyclic.
Once the channel is configured as cyclic it cannot be used otherwise. The use
has to call terminate_all(), synchornize() + re-get + re-prepare the transfers.
So, this exact scenario here is invalid according to the current use case.
If the status is set it means the channel->desc = NULL, which means the IRQ
handler is not executed up to this point.
next prev parent reply other threads:[~2026-04-20 12:51 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-11 11:42 [PATCH v4 00/17] Renesas: dmaengine and ASoC fixes Claudiu
2026-04-11 11:42 ` [PATCH v4 01/17] dmaengine: sh: rz-dmac: Move interrupt request after everything is set up Claudiu
2026-04-11 12:17 ` Biju Das
2026-04-11 12:34 ` Claudiu Beznea
2026-04-20 12:33 ` sashiko.dev review (Re: [PATCH v4 01/17] dmaengine: sh: rz-dmac: Move interrupt request after everything is set up) Claudiu Beznea
2026-04-11 11:42 ` [PATCH v4 02/17] dmaengine: sh: rz-dmac: Fix incorrect NULL check on list_first_entry() Claudiu
2026-04-11 11:42 ` [PATCH v4 03/17] dmaengine: sh: rz-dmac: Use list_first_entry_or_null() Claudiu
2026-04-11 11:42 ` [PATCH v4 04/17] dmaengine: sh: rz-dmac: Use rz_dmac_disable_hw() Claudiu
2026-04-20 12:34 ` sashiko.dev review (Re: [PATCH v4 04/17] dmaengine: sh: rz-dmac: Use rz_dmac_disable_hw()) Claudiu Beznea
2026-04-11 11:42 ` [PATCH v4 05/17] dmaengine: sh: rz-dmac: Do not disable the channel on error Claudiu
2026-04-11 12:30 ` Biju Das
2026-04-14 8:28 ` Claudiu Beznea
2026-04-11 11:42 ` [PATCH v4 06/17] dmaengine: sh: rz-dmac: Add helper to compute the lmdesc address Claudiu
2026-04-11 11:42 ` [PATCH v4 07/17] dmaengine: sh: rz-dmac: Save the start LM descriptor Claudiu
2026-04-11 12:34 ` Biju Das
2026-04-11 12:38 ` Claudiu Beznea
2026-04-11 12:50 ` Biju Das
2026-04-20 12:37 ` sashiko.dev review (Re: [PATCH v4 07/17] dmaengine: sh: rz-dmac: Save the start LM descriptor) Claudiu Beznea
2026-04-11 11:42 ` [PATCH v4 08/17] dmaengine: sh: rz-dmac: Add helper to check if the channel is enabled Claudiu
2026-04-11 11:42 ` [PATCH v4 09/17] dmaengine: sh: rz-dmac: Add helper to check if the channel is paused Claudiu
2026-04-11 11:42 ` [PATCH v4 10/17] dmaengine: sh: rz-dmac: Use virt-dma APIs for channel descriptor processing Claudiu
2026-04-20 12:41 ` sashiko.dev review (Re: [PATCH v4 10/17] dmaengine: sh: rz-dmac: Use virt-dma APIs for channel descriptor processing) Claudiu Beznea
2026-04-11 11:42 ` [PATCH v4 11/17] dmaengine: sh: rz-dmac: Refactor pause/resume code Claudiu
2026-04-20 12:42 ` sashiko.dev review (Re: [PATCH v4 11/17] dmaengine: sh: rz-dmac: Refactor pause/resume code) Claudiu Beznea
2026-04-11 11:42 ` [PATCH v4 12/17] dmaengine: sh: rz-dmac: Drop the update of channel->chctrl with CHCTRL_SETEN Claudiu
2026-04-11 11:42 ` [PATCH v4 13/17] dmaengine: sh: rz-dmac: Add cyclic DMA support Claudiu
2026-04-20 12:51 ` Claudiu Beznea [this message]
2026-04-11 11:43 ` [PATCH v4 14/17] dmaengine: sh: rz-dmac: Add suspend to RAM support Claudiu
2026-04-20 7:42 ` Biju Das
2026-04-20 14:15 ` Claudiu Beznea
2026-04-20 14:21 ` Biju Das
2026-04-20 14:37 ` Claudiu Beznea
2026-04-20 14:53 ` Biju Das
2026-04-20 12:52 ` sashiko.dev review (Re: [PATCH v4 14/17] dmaengine: sh: rz-dmac: Add suspend to RAM support) Claudiu Beznea
2026-04-11 11:43 ` [PATCH v4 15/17] ASoC: renesas: rz-ssi: Add pause support Claudiu
2026-04-11 11:43 ` [PATCH v4 16/17] ASoC: renesas: rz-ssi: Use generic PCM dmaengine APIs Claudiu
2026-04-11 11:43 ` [PATCH v4 17/17] dmaengine: sh: rz-dmac: Set the Link End (LE) bit on the last descriptor Claudiu
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=047007f9-d5cc-401a-846a-ab13ad0380b6@tuxon.dev \
--to=claudiu.beznea@tuxon.dev \
--cc=Frank.Li@kernel.org \
--cc=biju.das.jz@bp.renesas.com \
--cc=broonie@kernel.org \
--cc=claudiu.beznea.uj@bp.renesas.com \
--cc=dmaengine@vger.kernel.org \
--cc=fabrizio.castro.jz@renesas.com \
--cc=geert+renesas@glider.be \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=long.luu.ur@renesas.com \
--cc=p.zabel@pengutronix.de \
--cc=perex@perex.cz \
--cc=prabhakar.mahadev-lad.rj@bp.renesas.com \
--cc=tiwai@suse.com \
--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