[PATCH v7 8/8] dmaengine: dw-axi-dmac: guard shared IRQs across the controller lifetime

From: James Hilliard

Date: Tue Nov 17 2026 - 19:08:28 EST


Requesting a shared interrupt allows the handler to run before probe has
enabled the clocks or registered the DMA channel devices. Initializing
the virtual channels first protects their locks, but does not make the
register accesses or channel-device diagnostics safe. The same register
access problem exists when another device raises a shared interrupt while
the controller is runtime-suspended.

Publish IRQ readiness after hardware initialization and DMA registration.
Once published, take a runtime PM reference only if the controller is
already active. This keeps the clocks enabled through the handler without
waking an idle controller for another device's interrupt. Drain handlers
before disabling clocks, including during forced system suspend, which
does not wait for their runtime PM references.

Keep the initial power reference until registration completes and mark
the manually resumed device active before enabling runtime PM. Balance
the clocks and reference on probe failure. Resume through runtime PM on
removal so an active controller does not acquire an extra clock reference.

Withdraw IRQ readiness and mask the controller before releasing its
shared IRQs. A handler already in flight can re-enable the source on
exit, so mask it again after draining all IRQs, while the clocks are
still enabled.

Fixes: 1fe20f1b8454 ("dmaengine: Introduce DW AXI DMAC driver")
Closes: https://lore.kernel.org/r/sashiko-outbox-216269@xxxxxxxxxx/
Signed-off-by: James Hilliard <james.hilliard1@xxxxxxxxx>
---
drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c | 77 ++++++++++++++++++++------
drivers/dma/dw-axi-dmac/dw-axi-dmac.h | 1 +
2 files changed, 60 insertions(+), 18 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 0116c44d3bef..b1d753036744 100644
--- a/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
+++ b/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
@@ -276,6 +276,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)
@@ -1166,6 +1167,14 @@ static irqreturn_t dw_axi_dma_interrupt(int irq, void *dev_id)

u32 status, i;

+ /* Pair with publication after channel registration in dw_probe(). */
+ if (!smp_load_acquire(&chip->irq_ready))
+ return IRQ_NONE;
+
+ /* Shared interrupts can arrive while the controller is suspended. */
+ if (IS_ENABLED(CONFIG_PM) && pm_runtime_get_if_active(chip->dev) <= 0)
+ return IRQ_NONE;
+
/* Disable DMAC interrupts. We'll enable them after processing channels */
axi_dma_irq_disable(chip);

@@ -1191,6 +1200,9 @@ static irqreturn_t dw_axi_dma_interrupt(int irq, void *dev_id)
/* Re-enable interrupts */
axi_dma_irq_enable(chip);

+ if (IS_ENABLED(CONFIG_PM))
+ pm_runtime_put(chip->dev);
+
return IRQ_HANDLED;
}

@@ -1377,12 +1389,28 @@ 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_quiesce_irqs(struct axi_dma_chip *chip)
{
axi_dma_irq_disable(chip);
- axi_dma_disable(chip);
+ for (unsigned int i = 0; i < DMAC_MAX_CHANNELS; i++)
+ if (chip->irq[i] > 0)
+ synchronize_irq(chip->irq[i]);
+
+ /* A handler already in progress may have re-enabled interrupts. */
+ axi_dma_irq_disable(chip);
+}

+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_suspend(struct axi_dma_chip *chip)
+{
+ /* System sleep can suspend despite an IRQ handler's runtime PM reference. */
+ axi_dma_quiesce_irqs(chip);
+ axi_dma_power_off(chip);

return 0;
}
@@ -1651,8 +1679,6 @@ 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
@@ -1661,16 +1687,23 @@ static int dw_probe(struct platform_device *pdev)
pm_runtime_get_noresume(chip->dev);
ret = axi_dma_resume(chip);
if (ret < 0)
- goto err_pm_disable;
+ goto err_pm_put;

axi_dma_hw_init(chip);

- pm_runtime_put(chip->dev);
+ ret = pm_runtime_set_active(chip->dev);
+ if (ret)
+ goto err_suspend;
+ pm_runtime_enable(chip->dev);

ret = dmaenginem_async_device_register(&dw->dma);
if (ret)
goto err_pm_disable;

+ /* Publish initialized hardware and channel devices to the IRQ handler. */
+ smp_store_release(&chip->irq_ready, true);
+ 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);
@@ -1685,6 +1718,11 @@ static int dw_probe(struct platform_device *pdev)

err_pm_disable:
pm_runtime_disable(chip->dev);
+err_suspend:
+ axi_dma_suspend(chip);
+ pm_runtime_set_suspended(chip->dev);
+err_pm_put:
+ pm_runtime_put_noidle(chip->dev);

return ret;
}
@@ -1697,21 +1735,24 @@ static void dw_remove(struct platform_device *pdev)
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);
+ WRITE_ONCE(chip->irq_ready, false);
+ ret = pm_runtime_resume_and_get(chip->dev);
+ pm_runtime_disable(chip->dev);
+ if (ret < 0) {
+ dev_warn(chip->dev, "failed to resume before remove: %d\n", ret);
+ goto free_irqs;
}
- axi_dma_disable(chip);

- pm_runtime_disable(chip->dev);
- axi_dma_suspend(chip);
+ 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_put_noidle(chip->dev);
+ pm_runtime_set_suspended(chip->dev);

+free_irqs:
for (i = 0; i < DMAC_MAX_CHANNELS; i++)
if (chip->irq[i] > 0)
devm_free_irq(chip->dev, chip->irq[i], chip);
diff --git a/drivers/dma/dw-axi-dmac/dw-axi-dmac.h b/drivers/dma/dw-axi-dmac/dw-axi-dmac.h
index b18c9880711a..926d14b23615 100644
--- a/drivers/dma/dw-axi-dmac/dw-axi-dmac.h
+++ b/drivers/dma/dw-axi-dmac/dw-axi-dmac.h
@@ -70,6 +70,7 @@ struct dw_axi_dma {
struct axi_dma_chip {
struct device *dev;
int irq[DMAC_MAX_CHANNELS];
+ bool irq_ready;
void __iomem *regs;
void __iomem *apb_regs;
struct clk_bulk_data clks[2];

--
2.53.0