Re: [PATCH v8 9/9] dmaengine: dw-axi-dmac: guard shared IRQs across the controller lifetime

From: Frank Li

Date: Thu Nov 19 2026 - 11:51:53 EST


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@xxxxxxxxxx/
> Link: https://lore.kernel.org/r/sashiko-outbox-219846@xxxxxxxxxx/
> Signed-off-by: James Hilliard <james.hilliard1@xxxxxxxxx>
> ---
> 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
>