From: James Hilliard <james.hilliard1@gmail.com>
To: Vinod Koul <vkoul@kernel.org>, Frank Li <Frank.Li@kernel.org>,
Chen-Yu Tsai <wens@kernel.org>,
Jernej Skrabec <jernej.skrabec@gmail.com>,
Samuel Holland <samuel@sholland.org>,
Arnd Bergmann <arnd@arndb.de>,
Maxime Ripard <mripard@kernel.org>,
Jens Kuske <jenskuske@gmail.com>,
Jean-Francois Moine <moinejf@free.fr>
Cc: Hongling Zeng <zenghongling@kylinos.cn>,
Chengfeng Ye <cyeaa@connect.ust.hk>,
Nguyen Minh Tien <tien.nguyenminh@embeddedlinux.blog>,
dmaengine@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org,
James Hilliard <james.hilliard1@gmail.com>,
Frank Li <Frank.Li@nxp.com>
Subject: [PATCH v4 5/9] dmaengine: sun6i: detach completed descriptors before invoking callbacks
Date: Sun, 15 Nov 2026 02:32:53 -0700 [thread overview]
Message-ID: <20261115-submit-sun6i-dma-lifetime-next-v1-v4-5-043cd476a45f@gmail.com> (raw)
In-Reply-To: <20261115-submit-sun6i-dma-lifetime-next-v1-v4-0-043cd476a45f@gmail.com>
Finite completion publishes a descriptor to virt-dma but leaves pchan->desc
pointing to it until the allocator runs. The virtual-channel tasklet may
free that descriptor first. A residue query for another incomplete cookie
can still pass the retired descriptor to sun6i_get_chan_size().
Clear the active descriptor pointer before publishing completion. An
assigned physical channel without a descriptor is ready for the allocator
to start its next transfer or release it. Use that state in place of the
completed-descriptor pointer, so residue queries and termination only
consult descriptors still owned by the physical channel.
Fixes: 555859308723 ("dmaengine: sun6i: Add driver for the Allwinner A31 DMA controller")
Reviewed-by: Frank Li <Frank.Li@nxp.com>
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
---
drivers/dma/sun6i-dma.c | 23 ++++++++++-------------
1 file changed, 10 insertions(+), 13 deletions(-)
diff --git a/drivers/dma/sun6i-dma.c b/drivers/dma/sun6i-dma.c
index 5d39a2c0c2e1..c30e244e50ea 100644
--- a/drivers/dma/sun6i-dma.c
+++ b/drivers/dma/sun6i-dma.c
@@ -198,7 +198,6 @@ struct sun6i_pchan {
void __iomem *base;
struct sun6i_vchan *vchan;
struct sun6i_desc *desc;
- struct sun6i_desc *done;
};
struct sun6i_vchan {
@@ -492,16 +491,12 @@ static int sun6i_dma_start_desc(struct sun6i_vchan *vchan)
if (!pchan)
return -EAGAIN;
- if (!desc) {
- pchan->desc = NULL;
- pchan->done = NULL;
+ if (!desc)
return -EAGAIN;
- }
list_del(&desc->node);
pchan->desc = to_sun6i_desc(&desc->tx);
- pchan->done = NULL;
sun6i_dma_dump_lli(vchan, pchan->desc->v_lli, pchan->desc->p_lli);
@@ -538,7 +533,7 @@ static void sun6i_dma_tasklet(struct tasklet_struct *t)
pchan = vchan->phy;
- if (pchan && pchan->done) {
+ if (pchan && !pchan->desc) {
if (sun6i_dma_start_desc(vchan)) {
/*
* No current txd associated with this channel
@@ -584,6 +579,7 @@ static irqreturn_t sun6i_dma_interrupt(int irq, void *dev_id)
u32 channels_per_reg = sdev->cfg->num_channels_per_reg;
struct sun6i_vchan *vchan;
struct sun6i_pchan *pchan;
+ struct sun6i_desc *desc;
unsigned long flags;
int i, j, ret = IRQ_NONE;
u32 status;
@@ -603,13 +599,15 @@ static irqreturn_t sun6i_dma_interrupt(int irq, void *dev_id)
i * channels_per_reg + j < sdev->num_pchans; j++) {
pchan = sdev->pchans + i * channels_per_reg + j;
vchan = pchan->vchan;
- if (vchan && (status & vchan->irq_type)) {
+ desc = pchan->desc;
+ if (vchan && desc && (status & vchan->irq_type)) {
spin_lock(&vchan->vc.lock);
if (vchan->cyclic) {
- vchan_cyclic_callback(&pchan->desc->vd);
+ vchan_cyclic_callback(&desc->vd);
} else {
- vchan_cookie_complete(&pchan->desc->vd);
- pchan->done = pchan->desc;
+ /* Completion transfers ownership to virt-dma. */
+ pchan->desc = NULL;
+ vchan_cookie_complete(&desc->vd);
}
spin_unlock(&vchan->vc.lock);
}
@@ -985,7 +983,7 @@ static int sun6i_dma_terminate_all(struct dma_chan *chan)
pchan = vchan->phy;
list_del_init(&vchan->node);
- if (pchan && pchan->desc && pchan->desc != pchan->done) {
+ if (pchan && pchan->desc) {
struct virt_dma_desc *vd = &pchan->desc->vd;
vchan_terminate_vdesc(vd);
@@ -1001,7 +999,6 @@ static int sun6i_dma_terminate_all(struct dma_chan *chan)
vchan->phy = NULL;
pchan->vchan = NULL;
pchan->desc = NULL;
- pchan->done = NULL;
}
spin_unlock(&vchan->vc.lock);
--
2.53.0
next prev parent reply other threads:[~2026-11-15 9:33 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-15 9:32 [PATCH v4 0/9] dmaengine: sun6i: fix interrupt routing and channel lifetime James Hilliard
2026-11-15 9:32 ` [PATCH v4 1/9] dmaengine: sun6i: fix physical channel index in interrupt handler James Hilliard
2026-11-15 9:32 ` [PATCH v4 2/9] dmaengine: sun6i: handle the last partial interrupt bank James Hilliard
2026-11-18 20:06 ` Frank Li
2026-11-15 9:32 ` [PATCH v4 3/9] dmaengine: sun6i: take the device lock before the virtual channel lock James Hilliard
2026-11-15 9:32 ` [PATCH v4 4/9] dmaengine: sun6i: serialize physical channel ownership James Hilliard
2026-11-15 9:32 ` James Hilliard [this message]
2026-11-15 9:32 ` [PATCH v4 6/9] dmaengine: sun6i: retire interrupt state before reusing physical channels James Hilliard
2026-11-15 9:32 ` [PATCH v4 7/9] dmaengine: sun6i: track paused virtual channels James Hilliard
2026-11-18 20:08 ` Frank Li
2026-11-15 9:32 ` [PATCH v4 8/9] dmaengine: sun6i: synchronize callbacks before releasing channel resources James Hilliard
2026-11-15 9:32 ` [PATCH v4 9/9] dmaengine: sun6i: keep cyclic state with the prepared descriptor James Hilliard
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=20261115-submit-sun6i-dma-lifetime-next-v1-v4-5-043cd476a45f@gmail.com \
--to=james.hilliard1@gmail.com \
--cc=Frank.Li@kernel.org \
--cc=Frank.Li@nxp.com \
--cc=arnd@arndb.de \
--cc=cyeaa@connect.ust.hk \
--cc=dmaengine@vger.kernel.org \
--cc=jenskuske@gmail.com \
--cc=jernej.skrabec@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sunxi@lists.linux.dev \
--cc=moinejf@free.fr \
--cc=mripard@kernel.org \
--cc=samuel@sholland.org \
--cc=tien.nguyenminh@embeddedlinux.blog \
--cc=vkoul@kernel.org \
--cc=wens@kernel.org \
--cc=zenghongling@kylinos.cn \
/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®