From: Frank Li <Frank.li@oss.nxp.com>
To: James Hilliard <james.hilliard1@gmail.com>
Cc: 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>,
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
Subject: Re: [PATCH v3 3/9] dmaengine: sun6i: take the device lock before the virtual channel lock
Date: Mon, 26 Oct 2026 16:05:54 -0500 [thread overview]
Message-ID: <at_Ass1wf_4vequG@SMW015318> (raw)
In-Reply-To: <20261023-submit-sun6i-dma-lifetime-next-v1-v3-3-ef1acb0be768@gmail.com>
On Fri, Oct 23, 2026 at 05:38:22PM -0600, James Hilliard wrote:
> The pending queue is protected by sdev->lock, while virt-dma uses vc.lock
> for descriptor lists and cookies. issue_pending() and resume() currently
> take the device lock inside the virtual-channel lock when queueing work.
>
> Take sdev->lock first in both paths, and inspect the physical-channel
> assignment after acquiring the locks. This establishes the nesting order
> needed to keep allocation and descriptor startup in one critical section.
> virt-dma preparation, submission and callback processing continue to use
> vc.lock independently.
>
> Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
> ---
Reviewed-by: Frank Li <Frank.Li@nxp.com>
> drivers/dma/sun6i-dma.c | 21 ++++++++++-----------
> 1 file changed, 10 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/dma/sun6i-dma.c b/drivers/dma/sun6i-dma.c
> index 3a6525dd3d32..435d7daa1c0f 100644
> --- a/drivers/dma/sun6i-dma.c
> +++ b/drivers/dma/sun6i-dma.c
> @@ -952,23 +952,24 @@ static int sun6i_dma_resume(struct dma_chan *chan)
> {
> struct sun6i_dma_dev *sdev = to_sun6i_dma_dev(chan->device);
> struct sun6i_vchan *vchan = to_sun6i_vchan(chan);
> - struct sun6i_pchan *pchan = vchan->phy;
> + struct sun6i_pchan *pchan;
> unsigned long flags;
>
> dev_dbg(dmaengine_chan_dev(chan), "vchan %p: resume\n", &vchan->vc);
>
> - spin_lock_irqsave(&vchan->vc.lock, flags);
> + spin_lock_irqsave(&sdev->lock, flags);
> + spin_lock(&vchan->vc.lock);
> + pchan = vchan->phy;
>
> if (pchan) {
> writel(DMA_CHAN_PAUSE_RESUME,
> pchan->base + DMA_CHAN_PAUSE);
> } else if (!list_empty(&vchan->vc.desc_issued)) {
> - spin_lock(&sdev->lock);
> list_add_tail(&vchan->node, &sdev->pending);
> - spin_unlock(&sdev->lock);
> }
>
> - spin_unlock_irqrestore(&vchan->vc.lock, flags);
> + spin_unlock(&vchan->vc.lock);
> + spin_unlock_irqrestore(&sdev->lock, flags);
>
> return 0;
> }
> @@ -1057,25 +1058,23 @@ static void sun6i_dma_issue_pending(struct dma_chan *chan)
> struct sun6i_vchan *vchan = to_sun6i_vchan(chan);
> unsigned long flags;
>
> - spin_lock_irqsave(&vchan->vc.lock, flags);
> + spin_lock_irqsave(&sdev->lock, flags);
> + spin_lock(&vchan->vc.lock);
>
> if (vchan_issue_pending(&vchan->vc)) {
> - spin_lock(&sdev->lock);
> -
> if (!vchan->phy && list_empty(&vchan->node)) {
> list_add_tail(&vchan->node, &sdev->pending);
> tasklet_schedule(&sdev->task);
> dev_dbg(dmaengine_chan_dev(chan), "vchan %p: issued\n",
> &vchan->vc);
> }
> -
> - spin_unlock(&sdev->lock);
> } else {
> dev_dbg(dmaengine_chan_dev(chan), "vchan %p: nothing to issue\n",
> &vchan->vc);
> }
>
> - spin_unlock_irqrestore(&vchan->vc.lock, flags);
> + spin_unlock(&vchan->vc.lock);
> + spin_unlock_irqrestore(&sdev->lock, flags);
> }
>
> static void sun6i_dma_free_chan_resources(struct dma_chan *chan)
>
> --
> 2.53.0
>
next prev parent reply other threads:[~2026-10-26 21:06 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-23 23:38 [PATCH v3 0/9] dmaengine: sun6i: fix interrupt routing and channel lifetime James Hilliard
2026-10-23 23:38 ` [PATCH v3 1/9] dmaengine: sun6i: fix physical channel index in interrupt handler James Hilliard
2026-10-23 23:38 ` [PATCH v3 2/9] dmaengine: sun6i: handle the last partial interrupt bank James Hilliard
2026-10-26 20:57 ` Frank Li
2026-10-23 23:38 ` [PATCH v3 3/9] dmaengine: sun6i: take the device lock before the virtual channel lock James Hilliard
2026-10-26 21:05 ` Frank Li [this message]
2026-10-23 23:38 ` [PATCH v3 4/9] dmaengine: sun6i: serialize physical channel ownership James Hilliard
2026-10-26 21:14 ` Frank Li
2026-10-26 21:42 ` James Hilliard
2026-10-23 23:38 ` [PATCH v3 5/9] dmaengine: sun6i: detach completed descriptors before invoking callbacks James Hilliard
2026-10-23 23:38 ` [PATCH v3 6/9] dmaengine: sun6i: retire interrupt state before reusing physical channels James Hilliard
2026-10-23 23:38 ` [PATCH v3 7/9] dmaengine: sun6i: track paused virtual channels James Hilliard
2026-10-23 23:38 ` [PATCH v3 8/9] dmaengine: sun6i: synchronize callbacks before releasing channel resources James Hilliard
2026-10-23 23:38 ` [PATCH v3 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=at_Ass1wf_4vequG@SMW015318 \
--to=frank.li@oss.nxp.com \
--cc=Frank.Li@kernel.org \
--cc=arnd@arndb.de \
--cc=cyeaa@connect.ust.hk \
--cc=dmaengine@vger.kernel.org \
--cc=james.hilliard1@gmail.com \
--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®