mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Amelie Delaunay <amelie.delaunay@foss.st.com>
To: Hyunjung Ko <hj351016@gmail.com>, Vinod Koul <vkoul@kernel.org>,
	Frank Li <Frank.Li@kernel.org>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>,
	Alexandre Torgue <alexandre.torgue@foss.st.com>,
	<dmaengine@vger.kernel.org>,
	<linux-stm32@st-md-mailman.stormreply.com>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>, <stable@vger.kernel.org>
Subject: Re: [PATCH v2] dmaengine: stm32-dmamux: don't call runtime PM under a spinlock
Date: Wed, 18 Nov 2026 19:21:38 +0100	[thread overview]
Message-ID: <512ee5b6-e257-4b77-846f-41ab8f6f90d0@foss.st.com> (raw)
In-Reply-To: <20261118152843.1126665-1-hj351016@gmail.com>

On 11/18/26 16:28, Hyunjung Ko wrote:
> stm32_dmamux_route_allocate() calls pm_runtime_resume_and_get() while
> holding dmamux->lock with interrupts disabled, and stm32_dmamux_free()
> calls pm_runtime_put_sync() in the same way.  The runtime callbacks
> enable and disable the clock with clk_prepare_enable() /
> clk_disable_unprepare(), which can sleep, and the device is not marked
> pm_runtime_irq_safe(), so both sleep in atomic context.
> 
> The lock was in the wrong place: it did not protect the runtime PM call,
> while the CCR write in stm32_dmamux_route_allocate() was left unlocked
> even though stm32_dmamux_free() writes the same register under the lock.
> Move the runtime PM calls outside the lock in both functions and take
> the lock for the CCR write instead, matching stm32_dmamux_free().
> 
> Fixes: 4f3ceca254e0 ("dmaengine: stm32-dmamux: Add PM Runtime support")
> Cc: stable@vger.kernel.org
> Suggested-by: Amelie Delaunay <amelie.delaunay@foss.st.com>
> Signed-off-by: Hyunjung Ko <hj351016@gmail.com>

I’ve tested your patch on the stm32mp157f-dk2. Thanks!

Reviewed-by: Amelie Delaunay <amelie.delaunay@foss.st.com>
Tested-by: Amelie Delaunay <amelie.delaunay@foss.st.com>

> ---
> v2: Amelie Delaunay pointed out that v1 was correct but incomplete:
>      - also take dmamux->lock for the CCR write in
>        stm32_dmamux_route_allocate(), which stm32_dmamux_free() already
>        does for the same register;
>      - also move pm_runtime_put_sync() out of the lock in
>        stm32_dmamux_free(), which has the same sleep-in-atomic problem.
>      Link to v1: https://lore.kernel.org/all/20261118082853.926607-1-hj351016@gmail.com/
> 
>   drivers/dma/stm32/stm32-dmamux.c | 13 ++++++-------
>   1 file changed, 6 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/dma/stm32/stm32-dmamux.c b/drivers/dma/stm32/stm32-dmamux.c
> index 5731871..8290122 100644
> --- a/drivers/dma/stm32/stm32-dmamux.c
> +++ b/drivers/dma/stm32/stm32-dmamux.c
> @@ -73,10 +73,10 @@ static void stm32_dmamux_free(struct device *dev, void *route_data)
>   	stm32_dmamux_write(dmamux->iomem, STM32_DMAMUX_CCR(mux->chan_id), 0);
>   	clear_bit(mux->chan_id, dmamux->dma_inuse);
>   
> -	pm_runtime_put_sync(dev);
> -
>   	spin_unlock_irqrestore(&dmamux->lock, flags);
>   
> +	pm_runtime_put_sync(dev);
> +
>   	dev_dbg(dev, "Unmapping DMAMUX(%u) to DMA%u(%u)\n",
>   		mux->request, mux->master, mux->chan_id);
>   
> @@ -139,13 +139,9 @@ static void *stm32_dmamux_route_allocate(struct of_phandle_args *dma_spec,
>   	}
>   
>   	/* Set dma request */
> -	spin_lock_irqsave(&dmamux->lock, flags);
>   	ret = pm_runtime_resume_and_get(&pdev->dev);
> -	if (ret < 0) {
> -		spin_unlock_irqrestore(&dmamux->lock, flags);
> +	if (ret < 0)
>   		goto err_put_dma_spec_np;
> -	}
> -	spin_unlock_irqrestore(&dmamux->lock, flags);
>   
>   	mux->request = dma_spec->args[0];
>   
> @@ -156,8 +152,11 @@ static void *stm32_dmamux_route_allocate(struct of_phandle_args *dma_spec,
>   	dma_spec->args[0] = mux->chan_id - min;
>   	dma_spec->args_count = 4;
>   
> +	spin_lock_irqsave(&dmamux->lock, flags);
>   	stm32_dmamux_write(dmamux->iomem, STM32_DMAMUX_CCR(mux->chan_id),
>   			   mux->request);
> +	spin_unlock_irqrestore(&dmamux->lock, flags);
> +
>   	dev_dbg(&pdev->dev, "Mapping DMAMUX(%u) to DMA%u(%u)\n",
>   		mux->request, mux->master, mux->chan_id);
>   


      parent reply	other threads:[~2026-11-18 18:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18  8:28 [PATCH] dmaengine: stm32-dmamux: don't resume " Hyunjung Ko
2026-11-18 15:25 ` Amelie Delaunay
2026-11-18 15:28   ` [PATCH v2] dmaengine: stm32-dmamux: don't call " Hyunjung Ko
2026-11-18 17:01     ` Frank Li
2026-11-18 18:21     ` Amelie Delaunay [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=512ee5b6-e257-4b77-846f-41ab8f6f90d0@foss.st.com \
    --to=amelie.delaunay@foss.st.com \
    --cc=Frank.Li@kernel.org \
    --cc=alexandre.torgue@foss.st.com \
    --cc=dmaengine@vger.kernel.org \
    --cc=hj351016@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=stable@vger.kernel.org \
    --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

all inboxes | Powered by JetHome®