From: sashiko-bot@kernel.org
To: "Joy Zou" <joy.zou@oss.nxp.com>
Cc: imx@lists.linux.dev, dmaengine@vger.kernel.org, vkoul@kernel.org,
Frank.Li@kernel.org
Subject: Re: [PATCH v8 5/5] dmaengine: fsl-edma: add runtime suspend/resume support
Date: Wed, 25 Nov 2026 11:23:17 +0000 [thread overview]
Message-ID: <sashiko-outbox-233227@kernel.org> (raw)
In-Reply-To: <20261125-b4-edma-runtime-opt-mo-v8-5-81345a3bfb52@oss.nxp.com>
Thank you for your contribution! Sashiko AI review found 11 potential
issues to consider:
- [High] dmaengine: fsl-edma: NULL dereference on masked channels in
fsl_edma3_or_tx_handler()
- [High] dmaengine: fsl-edma: refcount underflow and unclocked MMIO on
pm_runtime_get_if_active() < 0
- [High] dmaengine: fsl-edma: unclocked MMIO access in fsl_edma_probe()
when CONFIG_PM is disabled
- [High] dmaengine: fsl-edma: missing CR restore in
fsl_edma_resume_early()
- [High] dmaengine: fsl-edma: DMA registration before setup_irq() and
channel PM
- [High] dmaengine: fsl-edma: NULL deref on masked channel in
fsl_edma3_or_tx_handler()
- [High] dmaengine: fsl-edma: fsl_edma_cleanup_vchan() leaks chan_dev
and causes UAF
- [High] dmaengine: fsl-edma: IRQ storm and bad RPM ordering in
fsl_edma_tx_handler()
- [High] dmaengine: fsl-edma: broken channel runtime PM on mcf-edma in
mcf_edma_probe()
- [Medium] dmaengine: fsl-edma: async runtime PM put in fsl_edma_probe()
leaks clocks
- [Medium] dmaengine: fsl-edma: active channels with srcid 0 skipped in
suspend/resume
--
commit 904c5737dc3c2174c965ff0d6fb29328fd87a5f5
Author: Joy Zou <joy.zou@oss.nxp.com>
dmaengine: fsl-edma: add runtime suspend/resume support
This commit adds runtime PM support for the FSL eDMA controller and its
per-channel devices, managing controller and channel clocks as well as
per-channel power domains through runtime suspend and resume callbacks.
> diff --git a/drivers/dma/fsl-edma-common.c b/drivers/dma/fsl-edma-common.c
> index 4f7a942673ebc..4ab56294ac776 100644
> --- a/drivers/dma/fsl-edma-common.c
> +++ b/drivers/dma/fsl-edma-common.c
[ ... ]
> @@ -1087,7 +1084,12 @@ int fsl_edma_alloc_chan_resources(struct dma_chan *chan)
> struct fsl_edma_chan *fsl_chan = to_fsl_edma_chan(chan);
> int ret = 0;
>
> - clk_prepare_enable(fsl_chan->clk);
> + ret = pm_runtime_resume_and_get(&fsl_chan->vchan.chan.dev->device);
> + if (ret < 0) {
> + dev_err(&fsl_chan->vchan.chan.dev->device, "Failed to resume device: %d\n", ret);
> + return ret;
> + }
[Severity: High]
Does this break mcf-edma when CONFIG_PM is enabled?
fsl_edma_alloc_chan_resources() is shared with mcf-edma, so
pm_runtime_resume_and_get() requires runtime PM to be enabled on the
registered channel device. In commit "dmaengine: mcf-edma: enable runtime
PM for eDMA engine and channel" earlier in this series, mcf_edma_probe()
calls devm_pm_runtime_enable(chan_dev) before dma_async_device_register()
allocates mcf_chan->vchan.chan.dev:
drivers/dma/mcf-edma-main.c:mcf_edma_probe() {
...
for (i = 0; i < mcf_edma->n_chans; i++) {
struct fsl_edma_chan *mcf_chan = &mcf_edma->chans[i];
struct device *chan_dev;
chan_dev = &mcf_chan->vchan.chan.dev->device;
...
ret = devm_pm_runtime_enable(chan_dev);
...
ret = dma_async_device_register(&mcf_edma->dma_dev);
...
}
Because mcf_chan->vchan.chan.dev is still NULL in that loop,
devm_pm_runtime_enable(chan_dev) dereferences a near-NULL pointer during
probe when CONFIG_PM=y, and the channel devices allocated later by
dma_async_device_register() never have runtime PM enabled.
> diff --git a/drivers/dma/fsl-edma-main.c b/drivers/dma/fsl-edma-main.c
> index fdb2577d1ccb5..5500eb17f579e 100644
> --- a/drivers/dma/fsl-edma-main.c
> +++ b/drivers/dma/fsl-edma-main.c
> @@ -37,15 +37,35 @@ static irqreturn_t fsl_edma_tx_handler(int irq, void *dev_id)
> unsigned int intr, ch;
> struct edma_regs *regs = &fsl_edma->regs;
>
> + /*
> + * A racy or spurious interrupt for an already-suspended
> + * controller or channel is an extremely rare corner case and
> + * highly unlikely in practice.
> + */
> + if (pm_runtime_get_if_active(fsl_edma->dma_dev.dev) == 0)
> + return IRQ_NONE;
>
> intr = edma_readl(fsl_edma, regs->intl);
> - if (!intr)
> + if (!intr) {
> + pm_runtime_put(fsl_edma->dma_dev.dev);
> return IRQ_NONE;
> + }
[Severity: High]
Can checking pm_runtime_get_if_active() == 0 underflow power.usage_count
and access unclocked registers when runtime PM is disabled?
pm_runtime_get_if_active() returns -EINVAL without incrementing
power.usage_count when runtime PM is disabled on a device, such as during
system suspend and resume transitions after __device_suspend_late()
disables runtime PM on idle runtime-suspended channels before IRQs are
masked in dpm_suspend_noirq(). Because -EINVAL != 0, this check (along
with the matching checks in fsl_edma3_err_check(), fsl_edma3_tx_handler(),
fsl_edma3_or_err_handler(), and fsl_edma_err_handler()) proceeds to read
channel registers on suspended channels whose clocks or power domains are
off and then calls pm_runtime_put() without a matching get.
> + pm_runtime_put(fsl_edma->dma_dev.dev);
> for (ch = 0; ch < fsl_edma->n_chans; ch++) {
> + struct fsl_edma_chan *fsl_chan = &fsl_edma->chans[ch];
> +
> + if (fsl_edma->chan_masked & BIT(ch))
> + continue;
> +
> + if (pm_runtime_get_if_active(&fsl_chan->vchan.chan.dev->device) == 0)
> + continue;
> +
> if (intr & (0x1 << ch)) {
> edma_writeb(fsl_edma, EDMA_CINT_CINT(ch), regs->cint);
> fsl_edma_tx_chan_handler(&fsl_edma->chans[ch]);
> }
> + pm_runtime_put(&fsl_chan->vchan.chan.dev->device);
> }
> return IRQ_HANDLED;
> }
[Severity: High]
Can skipping channels when pm_runtime_get_if_active() returns 0 cause a
hard-IRQ storm and hang in synchronize_irq() during channel suspend?
In fsl_edma_free_chan_resources(), fsl_edma_disable_request() disables
further DMA requests without clearing an already-latched interrupt flag,
and then calls pm_runtime_put_sync_suspend(). rpm_suspend() sets the
channel's runtime_status to RPM_SUSPENDING before calling
fsl_edma_chan_runtime_suspend() -> synchronize_irq(). While the channel is
in RPM_SUSPENDING, pm_runtime_get_if_active() returns 0 even though
fsl_chan->clk is still enabled, so this handler (as well as
fsl_edma_err_handler(), fsl_edma3_or_err_handler(), fsl_edma3_err_check(),
and fsl_edma3_tx_handler()) returns IRQ_HANDLED without clearing the
hardware interrupt status bit, leaving the level-triggered interrupt line
asserted forever.
In addition, fsl_edma_tx_handler() and fsl_edma_err_handler() call
pm_runtime_get_if_active() and pm_runtime_put() on every unmasked channel
before testing whether that channel's bit is set in intr or err, which
cycles power.lock and usage_count on unrelated active channels and can
cause a concurrent pm_runtime_put_sync_suspend() on another channel to fail
with -EAGAIN.
Finally, both handlers call pm_runtime_put(fsl_edma->dma_dev.dev) before
the loop, even though regs->cint, regs->cerr, regs->cerq, and regs->ceei
accessed inside the loop are global controller registers clocked by
fsl_edma->dmaclk.
[ ... ]
> @@ -132,13 +158,23 @@ static irqreturn_t fsl_edma3_tx_handler(int irq, void *dev_id)
> struct fsl_edma_chan *fsl_chan = dev_id;
> unsigned int intr;
>
> - intr = edma_readl_chreg(fsl_chan, ch_int);
> - if (!intr)
> + /*
> + * A racy or spurious interrupt for an already-suspended
> + * channel is an extremely rare corner case and highly unlikely in
> + * practice.
> + */
> + if (pm_runtime_get_if_active(&fsl_chan->vchan.chan.dev->device) == 0)
> return IRQ_NONE;
[Severity: High]
Can this dereference a NULL fsl_chan->vchan.chan.dev pointer when a channel
is masked via dma-channel-mask on controllers using
fsl_edma3_or_irq_init()?
In fsl_edma_probe(), channels matching fsl_edma->chan_masked skip
vchan_init(), so dmaenginem_async_device_register() never allocates
fsl_chan->vchan.chan.dev for them. Unlike the other shared interrupt
handlers, fsl_edma3_or_tx_handler() calls fsl_edma3_tx_handler() for every
channel in [start, end) without checking fsl_edma->chan_masked:
drivers/dma/fsl-edma-main.c:fsl_edma3_or_tx_handler() {
...
for (i = start; i < end; i++) {
chan = &fsl_edma->chans[i];
fsl_edma3_tx_handler(irq, chan);
}
...
}
[ ... ]
> @@ -730,11 +828,11 @@ static int fsl_edma_probe(struct platform_device *pdev)
> regs = &fsl_edma->regs;
> }
>
> - fsl_edma->dmaclk = devm_clk_get_optional_enabled(&pdev->dev, "dma");
> + fsl_edma->dmaclk = devm_clk_get_optional(&pdev->dev, "dma");
> if (IS_ERR(fsl_edma->dmaclk))
> return dev_err_probe(&pdev->dev,
> PTR_ERR(fsl_edma->dmaclk),
> - "Failed to get/enable DMA clock.\n");
> + "Failed to get DMA clock.\n");
[Severity: High]
What enables dmaclk, muxclk, and fsl_chan->clk when CONFIG_PM is disabled?
Although the commit message states that ARCH_MXC selects CONFIG_PM,
CONFIG_FSL_EDMA does not depend on PM and also supports platforms that do
not select CONFIG_PM, including ARCH_LAYERSCAPE (fsl,ls1028a-edma and
fsl,vf610-edma), ARCH_S32 (nxp,s32g2-edma), and 32-bit ARM ARCH_MXC
(SOC_VF610 and SOC_IMX7ULP). With devm_clk_get_optional() and
devm_clk_bulk_get_optional() replacing the _enabled variants here and
pm_runtime_resume_and_get() replacing clk_prepare_enable() in
fsl_edma_alloc_chan_resources(), none of the clocks are enabled when
CONFIG_PM=n, causing unclocked MMIO register accesses during probe and
channel use.
[ ... ]
> @@ -869,11 +960,56 @@ static int fsl_edma_probe(struct platform_device *pdev)
>
> platform_set_drvdata(pdev, fsl_edma);
>
> + ret = devm_pm_runtime_enable(&pdev->dev);
> + if (ret)
> + return dev_err_probe(&pdev->dev, ret, "Can't enable eDMA engine PM runtime!\n");
> +
> + PM_RUNTIME_ACQUIRE_IF_ENABLED(&pdev->dev, pm);
> + ret = PM_RUNTIME_ACQUIRE_ERR(&pm);
> + if (ret)
> + return dev_err_probe(&pdev->dev, ret, "Failed to resume eDMA engine!\n");
> +
> ret = dmaenginem_async_device_register(&fsl_edma->dma_dev);
> if (ret)
> return dev_err_probe(&pdev->dev, ret,
> "Can't register Freescale eDMA engine.\n");
>
> + for (i = 0; i < fsl_edma->n_chans; i++) {
> + struct fsl_edma_chan *fsl_chan = &fsl_edma->chans[i];
> + struct device *chan_dev;
> +
> + if (fsl_edma->chan_masked & BIT(i))
> + continue;
> +
> + chan_dev = &fsl_chan->vchan.chan.dev->device;
> + dev_set_drvdata(chan_dev, fsl_chan);
> + dev_pm_domain_set(chan_dev, &fsl_edma_chan_pm_domain);
> +
> + if (fsl_chan->pd_dev) {
> + fsl_chan->pd_dev_link = device_link_add(chan_dev, fsl_chan->pd_dev,
> + DL_FLAG_STATELESS |
> + DL_FLAG_PM_RUNTIME);
> + if (!fsl_chan->pd_dev_link) {
> + return dev_err_probe(&pdev->dev, -EINVAL,
> + "Failed to add device_link to %d!\n", i);
> + }
> + }
> + ret = devm_pm_runtime_enable(chan_dev);
> + if (ret)
> + return dev_err_probe(&pdev->dev, ret,
> + "Can't enable eDMA channel PM runtime!\n");
[Severity: High]
Does enabling runtime PM and attaching fsl_edma_chan_pm_domain on chan_dev
lead to a use-after-free on driver unbind?
dmaenginem_async_device_register() registers a devres action on &pdev->dev
to run dma_async_device_unregister(), while fsl_edma_remove() runs before
&pdev->dev devres teardown and calls fsl_edma_cleanup_vchan(), which removes
every channel from dmadev->channels:
drivers/dma/fsl-edma-common.c:fsl_edma_cleanup_vchan() {
...
list_for_each_entry_safe(chan, _chan,
&dmadev->channels, vchan.chan.device_node) {
list_del(&chan->vchan.chan.device_node);
tasklet_kill(&chan->vchan.task);
}
}
When dma_async_device_unregister() subsequently runs during devres release,
dmadev->channels is already empty, so the per-channel chan_dev devices are
never unregistered and remain active with runtime PM enabled and drvdata
pointing to the freed fsl_chan structure.
> +
> + PM_RUNTIME_ACQUIRE_IF_ENABLED(chan_dev, pm);
> + ret = PM_RUNTIME_ACQUIRE_ERR(&pm);
> + if (ret)
> + return dev_err_probe(&pdev->dev, ret,
> + "Failed to resume eDMA channel %d!\n",
> + fsl_chan->vchan.chan.chan_id);
> +
> + edma_write_tcdreg(fsl_chan, cpu_to_le32(0), csr);
> + fsl_edma_chan_mux(fsl_chan, 0, false);
> + }
[Severity: Medium]
Can fsl_edma_probe() leak clock prepare/enable references if a later probe
step fails?
PM_RUNTIME_ACQUIRE_IF_ENABLED() synchronously resumes &pdev->dev and each
chan_dev (enabling muxclk, dmaclk, and fsl_chan->clk), but releases them via
asynchronous pm_runtime_put(), which only queues suspend work on pm_wq. If
fsl_edma_probe() fails or defers after resuming the engine or any channel,
devres teardown disables runtime PM on chan_dev and &pdev->dev, which
cancels the pending suspend work via __pm_runtime_barrier() without running
fsl_edma_chan_runtime_suspend() or fsl_edma_runtime_suspend(), leaving the
clocks prepared and enabled.
> ret = devm_of_dma_controller_register(&pdev->dev, np,
> drvdata->dmamuxs ? fsl_edma_xlate : fsl_edma3_xlate,
> fsl_edma);
> @@ -885,6 +1021,10 @@ static int fsl_edma_probe(struct platform_device *pdev)
> if (!(drvdata->flags & FSL_EDMA_DRV_SPLIT_REG))
> edma_writel(fsl_edma, EDMA_CR_ERGA | EDMA_CR_ERCA, regs->cr);
>
> + ret = fsl_edma->drvdata->setup_irq(pdev, fsl_edma);
> + if (ret)
> + return dev_err_probe(&pdev->dev, ret, "Failed to setup IRQ!\n");
> +
> return 0;
> }
[Severity: High]
Doesn't registering the DMA device and OF DMA controller before channel
runtime PM and setup_irq() expose uninitialized channels to consumers and
to pm_wq?
A client requesting a channel after dmaenginem_async_device_register() or
devm_of_dma_controller_register() can enter fsl_edma_alloc_chan_resources()
before devm_pm_runtime_enable(chan_dev) runs (failing in
pm_runtime_resume_and_get() with -EACCES) or before setup_irq() populates
fsl_chan->txirq, fsl_chan->errirq, and their handlers (skipping
request_irq() in fsl_edma_alloc_chan_resources()). Meanwhile, the
asynchronous pm_runtime_put(chan_dev) in the channel loop queues
fsl_edma_chan_runtime_suspend() on pm_wq, which reads fsl_edma->txirq,
fsl_edma->txirq_16_31, fsl_edma->errirq, fsl_chan->txirq, and
fsl_chan->errirq concurrently with setup_irq() writing them.
> @@ -907,6 +1047,19 @@ static int fsl_edma_suspend_late(struct device *dev)
> fsl_chan = &fsl_edma->chans[i];
> if (fsl_edma->chan_masked & BIT(i))
> continue;
> +
> + /*
> + * Skip channel if:
> + * 1. Runtime PM already suspended.
> + * 2. Channel without power domain, and the channel source ID is zero,
> + * so the channel isn't assigned.
> + */
> + if (pm_runtime_status_suspended(&fsl_chan->vchan.chan.dev->device) ||
> + (!(fsl_edma->drvdata->flags & FSL_EDMA_DRV_HAS_PD) &&
> + (fsl_edma->drvdata->flags & FSL_EDMA_DRV_SPLIT_REG) &&
> + !fsl_chan->srcid))
> + continue;
[Severity: Medium]
Doesn't checking !fsl_chan->srcid here and in fsl_edma_resume_early() skip
active channels that legitimately have srcid == 0?
Unassigned channels are already runtime-suspended and caught by
pm_runtime_status_suspended(). On FSL_EDMA_DRV_SPLIT_REG controllers
without FSL_EDMA_DRV_HAS_PD (such as imx8ulp, imx93, imx95, and s32g2), an
allocated, runtime-active channel has srcid == 0 when used for DMA_MEMCPY
or when channel 0 is allocated via fsl_edma3_xlate() on controllers without
FSL_EDMA_DRV_HAS_CHMUX (such as imx93-edma3 and s32g2-edma). Skipping
those channels leaves them in pm_state == RUNNING across system suspend and
skips clearing their TCD csr on resume.
> @@ -926,19 +1079,56 @@ static int fsl_edma_resume_early(struct device *dev)
> {
> struct fsl_edma_engine *fsl_edma = dev_get_drvdata(dev);
> struct fsl_edma_chan *fsl_chan;
> - struct edma_regs *regs = &fsl_edma->regs;
> int i;
>
> for (i = 0; i < fsl_edma->n_chans; i++) {
> fsl_chan = &fsl_edma->chans[i];
> if (fsl_edma->chan_masked & BIT(i))
> continue;
> +
> + if (pm_runtime_status_suspended(&fsl_chan->vchan.chan.dev->device) ||
> + (!(fsl_edma->drvdata->flags & FSL_EDMA_DRV_HAS_PD) &&
> + (fsl_edma->drvdata->flags & FSL_EDMA_DRV_SPLIT_REG) &&
> + !fsl_chan->srcid))
> + continue;
> +
> fsl_chan->pm_state = RUNNING;
> edma_write_tcdreg(fsl_chan, 0, csr);
> if (fsl_chan->srcid != 0)
> fsl_edma_chan_mux(fsl_chan, fsl_chan->srcid, true);
> }
>
> + return 0;
> +}
> +
> +/* edma engine runtime system/resume */
> +static int fsl_edma_runtime_suspend(struct device *dev)
> +{
> + struct fsl_edma_engine *fsl_edma = dev_get_drvdata(dev);
> +
> + clk_bulk_disable_unprepare(fsl_edma->drvdata->dmamuxs, fsl_edma->muxclk);
> +
> + clk_disable_unprepare(fsl_edma->dmaclk);
> +
> + return 0;
> +}
> +
> +static int fsl_edma_runtime_resume(struct device *dev)
> +{
> + struct fsl_edma_engine *fsl_edma = dev_get_drvdata(dev);
> + struct edma_regs *regs = &fsl_edma->regs;
> + int ret;
> +
> + ret = clk_bulk_prepare_enable(fsl_edma->drvdata->dmamuxs, fsl_edma->muxclk);
> + if (ret)
> + return ret;
> +
> + ret = clk_prepare_enable(fsl_edma->dmaclk);
> + if (ret) {
> + clk_bulk_disable_unprepare(fsl_edma->drvdata->dmamuxs, fsl_edma->muxclk);
> + return ret;
> + }
> +
> if (!(fsl_edma->drvdata->flags & FSL_EDMA_DRV_SPLIT_REG))
> edma_writel(fsl_edma, EDMA_CR_ERGA | EDMA_CR_ERCA, regs->cr);
>
> return 0;
> }
[Severity: High]
Does moving the regs->cr write from fsl_edma_resume_early() to
fsl_edma_runtime_resume() lose the EDMA_CR_ERGA | EDMA_CR_ERCA setting
across system suspend when a channel is allocated?
When any channel is allocated, fsl_edma_alloc_chan_resources() holds a
runtime PM reference that keeps both the channel and the parent controller
device RPM_ACTIVE across system suspend and resume. Because
fsl_edma_pm_ops does not use pm_runtime_force_suspend() and
pm_runtime_force_resume(), fsl_edma_runtime_resume() does not run during
system resume in that case, leaving regs->cr unconfigured on non-SPLIT_REG
controllers (vf610, ls1028a, and imx7ulp).
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-b4-edma-runtime-opt-mo-v8-0-81345a3bfb52@oss.nxp.com?part=5
prev parent reply other threads:[~2026-11-25 11:23 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 10:58 [PATCH v8 0/5] add runtime suspend/resume support joy.zou
2026-11-25 10:58 ` [PATCH v8 1/5] dmaengine: fsl-edma: use devm_clk_get_optional_enabled() for channel clock joy.zou
2026-11-25 10:58 ` [PATCH v8 2/5] dmaengine: fsl-edma: use devm_clk_get_optional() for DMA engine clock joy.zou
2026-11-25 10:58 ` [PATCH v8 3/5] dmaengine: fsl-edma: convert DMAMUX clock handling to bulk clock API joy.zou
2026-11-25 10:58 ` [PATCH v8 4/5] dmaengine: mcf-edma: enable runtime PM for eDMA engine and channel Joy Zou
2026-11-25 11:03 ` sashiko-bot
2026-11-25 10:58 ` [PATCH v8 5/5] dmaengine: fsl-edma: add runtime suspend/resume support Joy Zou
2026-11-25 11:23 ` sashiko-bot [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=sashiko-outbox-233227@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Frank.Li@kernel.org \
--cc=dmaengine@vger.kernel.org \
--cc=imx@lists.linux.dev \
--cc=joy.zou@oss.nxp.com \
--cc=sashiko-reviews@lists.linux.dev \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.