All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ajay Kumar Nandam" <ajay.nandam@oss.qualcomm.com>
Cc: linux-sound@vger.kernel.org
Subject: Re: [PATCH 2/4] soundwire: qcom: disable runtime PM on controller unbind
Date: Thu, 03 Dec 2026 08:08:17 +0000	[thread overview]
Message-ID: <sashiko-outbox-247337@kernel.org> (raw)
In-Reply-To: <20261203-ak-gt-soundwire-qcom-mmrole-rework-v1-2-046ce68c8b0e@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] soundwire: qcom: unclocked peer MMIO writes in
  qcom_swrm_remove()
- [Medium] soundwire: qcom: hclk disable check in qcom_swrm_remove()
  desyncs on dead clk
- [Medium] soundwire: qcom: hclk refcount mismatch in qcom_swrm_remove()
  on ADSP restart
- [Medium] soundwire: qcom: pm_runtime_disable() before teardown allows
  unclocked MMIO
- [Low] soundwire: qcom: missing Fixes trailer for commit 74e79da9fd46
--

commit b31693c684ab42b0a6bf2fee75c49470bacdd1ea
Author: Ajay Kumar Nandam <ajay.nandam@oss.qualcomm.com>

> soundwire: qcom: disable runtime PM on controller unbind
>
> qcom_swrm_remove() does not balance the pm_runtime_enable() done in
> probe() for the default and primary roles. It also disables the
> interface clock even when runtime suspend already disabled it.
>
> During an ADSP restart, the controller can be removed while runtime
> suspended. This can leave runtime PM enabled for the old controller
> instance, or disable the interface clock twice.
>
> The dependent remove path already handles both cases. Do the same
> for the default and primary paths by disabling runtime PM before
> tearing down the bus, and only releasing the clock when it is still
> active.
>
> Co-developed-by: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
> Signed-off-by: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
> Signed-off-by: Ajay Kumar Nandam <ajay.nandam@oss.qualcomm.com>

[Severity: Low]
This fixes missing runtime PM teardown and an unbalanced
clk_disable_unprepare() in qcom_swrm_remove().  Should this include:

  Fixes: 74e79da9fd46 ("soundwire: qcom: add runtime pm support")

> diff --git a/drivers/soundwire/qcom.c b/drivers/soundwire/qcom.c
> index bd44d89132675..d23d6ec56fed9 100644
> --- a/drivers/soundwire/qcom.c
> +++ b/drivers/soundwire/qcom.c
> @@ -2051,6 +2051,10 @@ static void qcom_swrm_remove(struct platform_device *pdev)
>  		return;
>  	}
>  
> +	/* Balance probe()'s pm_runtime_enable() before tearing the bus down. */
> +	pm_runtime_disable(&pdev->dev);
> +	pm_runtime_dont_use_autosuspend(&pdev->dev);
> +
>  	/* delete bus before dropping peer_ctrl; in-flight ops deref it */
>  	sdw_bus_master_delete(&ctrl->bus);

[Severity: Medium]
Can disabling runtime PM before sdw_bus_master_delete() and ASoC DAI
teardown allow unclocked MMIO accesses from swrm_reg_show() or
qcom_swrm_startup()?

If &pdev->dev enters qcom_swrm_remove() runtime-suspended with ctrl->hclk
gated off (for example when autosuspend_delay_ms is 0 so
__device_release_driver()'s pm_runtime_put_sync() suspends synchronously),
pm_runtime_disable() makes subsequent pm_runtime_get_sync(ctrl->dev) calls
return -EACCES without enabling ctrl->hclk.

CPU0                              CPU1
qcom_swrm_remove()
  pm_runtime_disable(&pdev->dev)
                                  qcom_swrm_startup()
                                    pm_runtime_get_sync() -> -EACCES
                                    /* ignores -EACCES, returns 0 */
                                  qcom_swrm_shutdown()
                                    swrm_wait_for_wr_fifo_done()
                                      ctrl->reg_read() <-- unclocked MMIO
  sdw_bus_master_delete()
  ...
  devres_release_all()

Both swrm_reg_show() and qcom_swrm_startup() treat -EACCES from
pm_runtime_get_sync() as success, so a concurrent debugfs read before
sdw_bus_debugfs_exit() or a DAI callback before the devm ASoC component is
unregistered can issue unclocked MMIO accesses and cause an SError or bus
hang.

> @@ -2073,7 +2077,9 @@ static void qcom_swrm_remove(struct platform_device *pdev)
>  		ctrl->peer_ctrl = NULL;
>  	}

[Severity: High]
Can the primary remove path still issue unclocked MMIO writes to the
dependent peer when the interface clock provider is gone?

Just above these lines, qcom_swrm_remove() resumes the dependent peer and
writes its registers whenever pm_runtime_resume_and_get() succeeds:

drivers/soundwire/qcom.c:qcom_swrm_remove() {
	...
		ret = pm_runtime_resume_and_get(peer->dev);
		if (ret < 0) {
			dev_err(&pdev->dev, "peer resume failed on remove: %d\n", ret);
		} else {
			peer->reg_write(peer,
					peer->reg_layout[SWRM_REG_INTERRUPT_CPU_EN], 0);
			/* disable peer SWRM; releases shared SWR_CLK */
			peer->reg_write(peer, SWRM_COMP_CFG_ADDR, 0);
			pm_runtime_put(peer->dev);
		}
	...
}

After commit "soundwire: qcom: don't touch registers when the iface clock is
not live", swrm_runtime_resume() returns 0 without calling
clk_prepare_enable(peer->hclk) when swrm_iface_clk_live(peer) is false.
During an ADSP restart, pm_runtime_resume_and_get(peer->dev) then returns 0
while peer->hclk is dead and gated, so qcom_swrm_remove() writes to
unclocked peer MMIO registers and risks an SError or bus hang.  Checking
swrm_iface_clk_live(peer) before the peer->reg_write() calls would avoid
this.

>  
> -	clk_disable_unprepare(ctrl->hclk);
> +	/* Skip if runtime suspend already dropped the clock. */
> +	if (!pm_runtime_status_suspended(&pdev->dev))
> +		clk_disable_unprepare(ctrl->hclk);
>  }

[Severity: Medium]
Does checking pm_runtime_status_suspended(&pdev->dev) still match whether
ctrl->hclk is prepared and enabled after commit "soundwire: qcom: don't
touch registers when the iface clock is not live"?

When swrm_iface_clk_live(ctrl) is false, both swrm_runtime_resume() and
swrm_runtime_suspend() return 0 without calling clk_prepare_enable() or
clk_disable_unprepare(), so the runtime PM core still transitions
runtime_status between RPM_SUSPENDED and RPM_ACTIVE while ctrl->hclk is
left unchanged.  That can either leak the ctrl->hclk prepare/enable count
(if runtime suspend returns 0 on a dead clock before remove) or disable
ctrl->hclk when the parent provider is already gone.  Tracking whether
ctrl->hclk is enabled in driver state would avoid relying on runtime PM
status here.

[Severity: Medium]
Can this still call clk_disable_unprepare(ctrl->hclk) twice during an ADSP
restart on a runtime-suspended default or primary controller?

Before calling device_remove() -> qcom_swrm_remove(),
__device_release_driver() calls pm_runtime_get_sync(dev) followed by
pm_runtime_put_sync(dev).  If the controller was already RPM_SUSPENDED
(ctrl->hclk count 0) and the clock parent disappeared, pm_runtime_get_sync()
invokes swrm_runtime_resume(), which returns 0 without enabling ctrl->hclk
and transitions runtime_status to RPM_ACTIVE.  Because default and primary
roles enable a 3000 ms autosuspend delay in qcom_swrm_probe(),
pm_runtime_put_sync() only arms the autosuspend timer and leaves
runtime_status at RPM_ACTIVE, so qcom_swrm_remove() calls
clk_disable_unprepare(ctrl->hclk) a second time and triggers
clk_core_disable()/clk_core_unprepare() warnings.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-ak-gt-soundwire-qcom-mmrole-rework-v1-0-046ce68c8b0e@oss.qualcomm.com?part=2

  reply	other threads:[~2026-12-03  8:08 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03  7:41 [PATCH 0/4] soundwire: qcom: controller lifecycle fixes on unbind/reprobe Ajay Kumar Nandam
2026-12-03  7:41 ` [PATCH 1/4] soundwire: qcom: don't touch registers when the iface clock is not live Ajay Kumar Nandam
2026-12-03  8:09   ` sashiko-bot
2026-12-03  7:41 ` [PATCH 2/4] soundwire: qcom: disable runtime PM on controller unbind Ajay Kumar Nandam
2026-12-03  8:08   ` sashiko-bot [this message]
2026-12-03  7:41 ` [PATCH 3/4] soundwire: qcom: dispose IRQ mappings " Ajay Kumar Nandam
2026-12-03  7:55   ` sashiko-bot
2026-12-03  7:41 ` [PATCH 4/4] soundwire: qcom: reconcile a retained peripheral after controller re-probe Ajay Kumar Nandam
2026-12-03  8:08   ` sashiko-bot

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-247337@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=ajay.nandam@oss.qualcomm.com \
    --cc=linux-sound@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.