From: Frank Li <Frank.li@oss.nxp.com>
To: James Hilliard <james.hilliard1@gmail.com>
Cc: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>,
Vinod Koul <vkoul@kernel.org>, Frank Li <Frank.Li@kernel.org>,
Sergey Khimich <serghox@gmail.com>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Sia Jee Heng <jee.heng.sia@intel.com>,
Baruch Siach <baruch@tkos.co.il>,
Mitch Barnett <mitch@accuratesound.ca>,
dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v8 9/9] dmaengine: dw-axi-dmac: guard shared IRQs across the controller lifetime
Date: Thu, 19 Nov 2026 10:50:48 -0600 [thread overview]
Message-ID: <av8o6KrTcLH1JEvZ@SMW015318> (raw)
In-Reply-To: <20261119-submit-dw-axi-dma-stop-pause-v1-v8-9-f8e7fe60594c@gmail.com>
On Thu, Nov 19, 2026 at 09:01:04AM -0700, James Hilliard wrote:
> An interrupt from another device on the shared line can run the handler
> before the DMA channel devices exist or while the register clocks are
> off. Checking the runtime PM status in the handler is not sufficient:
> the controller can already signal an interrupt in the resume callback,
> before the PM core marks the device active.
>
> Mask the controller and clear stale channel status before requesting
> the IRQs. Keep the global mask in place until DMA registration returns.
> A transfer that completes during registration leaves its channel status
> pending and is serviced when the controller interrupts are enabled.
>
> Serialize the hardware mask and handler readiness under a chip lock.
> Mask the source before withdrawing the handler and prevent a handler
> already processing channels from re-enabling it on exit. Drain each IRQ
> before disabling the clocks. This also covers forced system suspend and
> lets removal leave an already suspended controller powered down.
>
> Fixes: 1fe20f1b8454 ("dmaengine: Introduce DW AXI DMAC driver")
> Closes: https://lore.kernel.org/r/sashiko-outbox-216269@kernel.org/
> Link: https://lore.kernel.org/r/sashiko-outbox-219846@kernel.org/
> Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
> ---
> drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c | 119 ++++++++++++++++---------
> drivers/dma/dw-axi-dmac/dw-axi-dmac.h | 3 +
> 2 files changed, 81 insertions(+), 41 deletions(-)
>
> diff --git a/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c b/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
> index 531705f8f89b..eab3c31f77df 100644
> --- a/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
> +++ b/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
> @@ -277,6 +277,7 @@ static void axi_dma_hw_init(struct axi_dma_chip *chip)
> for (i = 0; i < chip->dw->hdata->nr_channels; i++) {
> axi_chan_irq_disable(&chip->dw->chan[i], DWAXIDMAC_IRQ_ALL);
> axi_chan_disable(&chip->dw->chan[i]);
> + axi_chan_irq_clear(&chip->dw->chan[i], DWAXIDMAC_IRQ_ALL);
> }
> ret = dma_set_mask_and_coherent(chip->dev, DMA_BIT_MASK(64));
> if (ret)
> @@ -1167,8 +1168,11 @@ static irqreturn_t dw_axi_dma_interrupt(int irq, void *dev_id)
>
> u32 status, i;
>
> - /* Disable DMAC interrupts. We'll enable them after processing channels */
> - axi_dma_irq_disable(chip);
> + scoped_guard(spinlock_irqsave, &chip->irq_lock) {
> + if (!chip->irq_ready)
Does pm_runtime_get_if_active() can resolve your problem?
Frank
> + return IRQ_NONE;
> + axi_dma_irq_disable(chip);
> + }
>
> /* Poll, clear and process every channel interrupt status */
> for (i = 0; i < dw->hdata->nr_channels; i++) {
> @@ -1189,8 +1193,10 @@ static irqreturn_t dw_axi_dma_interrupt(int irq, void *dev_id)
> spin_unlock_irqrestore(&chan->vc.lock, flags);
> }
>
> - /* Re-enable interrupts */
> - axi_dma_irq_enable(chip);
> + scoped_guard(spinlock_irqsave, &chip->irq_lock) {
> + if (chip->irq_ready)
> + axi_dma_irq_enable(chip);
> + }
>
> return IRQ_HANDLED;
> }
> @@ -1378,17 +1384,39 @@ static int dma_chan_resume(struct dma_chan *dchan)
> return ret;
> }
>
> -static int axi_dma_suspend(struct axi_dma_chip *chip)
> +static void axi_dma_start_irqs(struct axi_dma_chip *chip)
> {
> - axi_dma_irq_disable(chip);
> - axi_dma_disable(chip);
> + guard(spinlock_irqsave)(&chip->irq_lock);
>
> - clk_bulk_disable_unprepare(ARRAY_SIZE(chip->clks), chip->clks);
> + chip->irq_ready = true;
> + axi_dma_irq_enable(chip);
> +}
>
> - return 0;
> +static bool axi_dma_quiesce_irqs(struct axi_dma_chip *chip)
> +{
> + scoped_guard(spinlock_irqsave, &chip->irq_lock) {
> + if (!chip->irq_ready)
> + return false;
> + axi_dma_irq_disable(chip);
> + /* Flush the mask before withdrawing the handler. */
> + axi_dma_ioread32(chip, DMAC_CFG);
> + chip->irq_ready = false;
> + }
> +
> + for (unsigned int i = 0; i < DMAC_MAX_CHANNELS; i++)
> + if (chip->irq[i] > 0)
> + synchronize_irq(chip->irq[i]);
> +
> + return true;
> +}
> +
> +static void axi_dma_power_off(struct axi_dma_chip *chip)
> +{
> + axi_dma_disable(chip);
> + clk_bulk_disable_unprepare(ARRAY_SIZE(chip->clks), chip->clks);
> }
>
> -static int axi_dma_resume(struct axi_dma_chip *chip)
> +static int axi_dma_power_on(struct axi_dma_chip *chip)
> {
> int ret;
>
> @@ -1396,8 +1424,8 @@ static int axi_dma_resume(struct axi_dma_chip *chip)
> if (ret < 0)
> return ret;
>
> + axi_dma_irq_disable(chip);
> axi_dma_enable(chip);
> - axi_dma_irq_enable(chip);
>
> return 0;
> }
> @@ -1406,14 +1434,23 @@ static int __maybe_unused axi_dma_runtime_suspend(struct device *dev)
> {
> struct axi_dma_chip *chip = dev_get_drvdata(dev);
>
> - return axi_dma_suspend(chip);
> + if (axi_dma_quiesce_irqs(chip))
> + axi_dma_power_off(chip);
> +
> + return 0;
> }
>
> static int __maybe_unused axi_dma_runtime_resume(struct device *dev)
> {
> struct axi_dma_chip *chip = dev_get_drvdata(dev);
> + int ret;
>
> - return axi_dma_resume(chip);
> + ret = axi_dma_power_on(chip);
> + if (ret)
> + return ret;
> +
> + axi_dma_start_irqs(chip);
> + return 0;
> }
>
> static struct dma_chan *dw_axi_dma_of_xlate(struct of_phandle_args *dma_spec,
> @@ -1560,6 +1597,7 @@ static int dw_probe(struct platform_device *pdev)
> chip->dw = dw;
> chip->dev = &pdev->dev;
> chip->dw->hdata = hdata;
> + spin_lock_init(&chip->irq_lock);
>
> chip->regs = devm_platform_ioremap_resource(pdev, 0);
> if (IS_ERR(chip->regs))
> @@ -1614,10 +1652,6 @@ static int dw_probe(struct platform_device *pdev)
> vchan_init(&chan->vc, &dw->dma);
> }
>
> - ret = axi_req_irqs(pdev, chip);
> - if (ret)
> - return ret;
> -
> /* Set capabilities */
> dma_cap_set(DMA_MEMCPY, dw->dma.cap_mask);
> dma_cap_set(DMA_SLAVE, dw->dma.cap_mask);
> @@ -1656,26 +1690,30 @@ static int dw_probe(struct platform_device *pdev)
> dma_set_max_seg_size(&pdev->dev, MAX_BLOCK_SIZE);
> platform_set_drvdata(pdev, chip);
>
> - pm_runtime_enable(chip->dev);
> -
> - /*
> - * We can't just call pm_runtime_get here instead of
> - * pm_runtime_get_noresume + axi_dma_resume because we need
> - * driver to work also without Runtime PM.
> - */
> + /* Power up explicitly so probe also works without runtime PM. */
> pm_runtime_get_noresume(chip->dev);
> - ret = axi_dma_resume(chip);
> + ret = axi_dma_power_on(chip);
> if (ret < 0)
> - goto err_pm_disable;
> + goto err_pm_put;
>
> axi_dma_hw_init(chip);
>
> - pm_runtime_put(chip->dev);
> + ret = axi_req_irqs(pdev, chip);
> + if (ret)
> + goto err_power_off;
> +
> + ret = pm_runtime_set_active(chip->dev);
> + if (ret)
> + goto err_power_off;
> + pm_runtime_enable(chip->dev);
>
> ret = dmaenginem_async_device_register(&dw->dma);
> if (ret)
> goto err_pm_disable;
>
> + axi_dma_start_irqs(chip);
> + pm_runtime_put(chip->dev);
> +
> /* Register with OF helpers for DMA lookups */
> ret = of_dma_controller_register(pdev->dev.of_node,
> dw_axi_dma_of_xlate, dw);
> @@ -1690,6 +1728,11 @@ static int dw_probe(struct platform_device *pdev)
>
> err_pm_disable:
> pm_runtime_disable(chip->dev);
> +err_power_off:
> + axi_dma_power_off(chip);
> + pm_runtime_set_suspended(chip->dev);
> +err_pm_put:
> + pm_runtime_put_noidle(chip->dev);
>
> return ret;
> }
> @@ -1700,22 +1743,16 @@ static void dw_remove(struct platform_device *pdev)
> struct dw_axi_dma *dw = chip->dw;
> struct axi_dma_chan *chan, *_chan;
> u32 i;
> - int ret;
> -
> - /* Enable clk before accessing to registers */
> - ret = clk_bulk_prepare_enable(ARRAY_SIZE(chip->clks), chip->clks);
> - if (ret)
> - dev_warn(chip->dev, "failed to enable clocks before remove: %d\n",
> - ret);
> - axi_dma_irq_disable(chip);
> - for (i = 0; i < dw->hdata->nr_channels; i++) {
> - axi_chan_disable(&chip->dw->chan[i]);
> - axi_chan_irq_disable(&chip->dw->chan[i], DWAXIDMAC_IRQ_ALL);
> - }
> - axi_dma_disable(chip);
>
> pm_runtime_disable(chip->dev);
> - axi_dma_suspend(chip);
> + if (axi_dma_quiesce_irqs(chip)) {
> + for (i = 0; i < dw->hdata->nr_channels; i++) {
> + axi_chan_disable(&dw->chan[i]);
> + axi_chan_irq_disable(&dw->chan[i], DWAXIDMAC_IRQ_ALL);
> + }
> + axi_dma_power_off(chip);
> + }
> + pm_runtime_set_suspended(chip->dev);
>
> for (i = 0; i < DMAC_MAX_CHANNELS; i++)
> if (chip->irq[i] > 0)
> diff --git a/drivers/dma/dw-axi-dmac/dw-axi-dmac.h b/drivers/dma/dw-axi-dmac/dw-axi-dmac.h
> index b18c9880711a..80e4632c0d55 100644
> --- a/drivers/dma/dw-axi-dmac/dw-axi-dmac.h
> +++ b/drivers/dma/dw-axi-dmac/dw-axi-dmac.h
> @@ -14,6 +14,7 @@
> #include <linux/clk.h>
> #include <linux/device.h>
> #include <linux/dmaengine.h>
> +#include <linux/spinlock.h>
> #include <linux/types.h>
>
> #include "../virt-dma.h"
> @@ -70,6 +71,8 @@ struct dw_axi_dma {
> struct axi_dma_chip {
> struct device *dev;
> int irq[DMAC_MAX_CHANNELS];
> + spinlock_t irq_lock; /* Protects irq_ready and the global IRQ mask. */
> + bool irq_ready;
> void __iomem *regs;
> void __iomem *apb_regs;
> struct clk_bulk_data clks[2];
>
> --
> 2.53.0
>
prev parent reply other threads:[~2026-11-19 16:51 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 16:00 [PATCH v8 0/9] dmaengine: dw-axi-dmac: fix termination and pause acknowledgment James Hilliard
2026-11-19 16:00 ` [PATCH v8 1/9] dmaengine: dw-axi-dmac: keep cyclic mode in the descriptor James Hilliard
2026-11-19 16:00 ` [PATCH v8 2/9] dmaengine: dw-axi-dmac: poll the correct enable bit during termination James Hilliard
2026-11-19 16:17 ` Frank Li
2026-11-19 16:00 ` [PATCH v8 3/9] dmaengine: dw-axi-dmac: retain descriptors when termination times out James Hilliard
2026-11-19 16:18 ` Frank Li
2026-11-19 16:00 ` [PATCH v8 4/9] dmaengine: dw-axi-dmac: use atomic polling for suspend acknowledgment James Hilliard
2026-11-19 16:19 ` Frank Li
2026-11-19 16:01 ` [PATCH v8 5/9] dmaengine: dw-axi-dmac: preserve pending pause requests James Hilliard
2026-11-19 16:27 ` Frank Li
2026-11-19 16:01 ` [PATCH v8 6/9] dmaengine: dw-axi-dmac: retain descriptors until callbacks drain James Hilliard
2026-11-19 16:41 ` Frank Li
2026-11-19 16:01 ` [PATCH v8 7/9] dmaengine: dw-axi-dmac: serialize interrupt status with channel reuse James Hilliard
2026-11-19 16:44 ` Frank Li
2026-11-19 16:01 ` [PATCH v8 8/9] dmaengine: dw-axi-dmac: require an IRQ before registering the controller James Hilliard
2026-11-19 16:47 ` Frank Li
2026-11-19 16:01 ` [PATCH v8 9/9] dmaengine: dw-axi-dmac: guard shared IRQs across the controller lifetime James Hilliard
2026-11-19 16:50 ` Frank Li [this message]
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=av8o6KrTcLH1JEvZ@SMW015318 \
--to=frank.li@oss.nxp.com \
--cc=Eugeniy.Paltsev@synopsys.com \
--cc=Frank.Li@kernel.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=baruch@tkos.co.il \
--cc=dmaengine@vger.kernel.org \
--cc=james.hilliard1@gmail.com \
--cc=jee.heng.sia@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mitch@accuratesound.ca \
--cc=serghox@gmail.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