* [PATCH v2] soundwire: bus: use pm_runtime_get_if_active() in sdw_handle_slave_alerts()
@ 2026-12-03 11:48 Vijendar Mukunda
2026-12-03 12:11 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Vijendar Mukunda @ 2026-12-03 11:48 UTC (permalink / raw)
To: vkoul
Cc: broonie, yung-chuan.liao, pierre-louis.bossart,
Basavaraj.Hiregoudar, Sunil-kumar.Dommati, venkataprasad.potturu,
Syed.SabaKareem, Mario.Limonciello, Poojitha.N, Richard.Gong,
linux-sound, linux-kernel, Vijendar Mukunda
This is a paranoia check based on code analysis. The issue has not been
observed in practice on any platform.
sdw_handle_slave_alerts() calls pm_runtime_get_sync(&slave->dev) which,
when slave->dev is not in RPM_ACTIVE, calls rpm_resume() on the slave.
rpm_resume() propagates synchronously up the parent chain: slave->dev ->
bus->dev -> manager->dev. If manager->dev is in RPM_SUSPENDING at that
point, rpm_resume() blocks on dev->power.wait_queue waiting for the
suspend to complete.
This creates a circular dependency: the manager's runtime_suspend callback
is blocked in cancel_work_sync() waiting for the alert work to finish,
while the alert work is blocked in pm_runtime_get_sync() waiting for the
manager's runtime_suspend to complete.
Fix this by first checking the manager device state using
pm_runtime_get_if_active() on slave->bus->dev->parent (the physical
manager device). This is an atomic check: if it returns 1 the usage
counter is incremented in the same operation and the manager cannot
transition to RPM_SUSPENDING while the reference is held.
- If the manager reference cannot be taken (ret == 0, manager not
RPM_ACTIVE): request an async resume via pm_request_resume(mgr_dev)
as a best-effort recovery and return early. For wake-capable
CLK_STOP_MODE peripherals the clock-stop wake mechanism re-asserts
the alert after the manager resumes. For other peripherals,
pm_request_resume() ensures the manager does not remain suspended
after completing the ongoing suspend. This breaks the deadlock for
the RPM_SUSPENDING case; the early return is harmless in RPM_RESUMING
and RPM_SUSPENDED states.
- If the manager reference is taken (ret > 0, manager is RPM_ACTIVE):
proceed with pm_runtime_resume_and_get(&slave->dev) to resume the
slave. Holding the manager reference prevents the manager from
entering RPM_SUSPENDING while the slave resumes, closing the deadlock
window for all slave PM states.
- If ret < 0 (-EINVAL, PM disabled on manager): fall through without a
manager reference. PM being disabled means no suspend/resume callbacks
run, so no deadlock risk. This is consistent with the original -EACCES
exemption for the slave.
pm_runtime_resume_and_get() is used for the slave (instead of
pm_runtime_get_sync()) because it does not increment the usage counter
on error, simplifying the error-path accounting. Introduce have_pm_ref
and have_mgr_ref booleans to guard the pm_runtime_put calls at io_err:
so they are only reached when a reference was actually taken. The
manager reference is released at the new mgr_put: label after io_err:.
Fixes: aa79293517b3 ("soundwire: bus: fix io error when processing alert event")
Signed-off-by: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
---
Changes since v1:
- Add opening paragraph to commit message framing this as a paranoia check
based on code analysis; not observed in practice on any platform.
- Use "circular dependency" instead of "deadlock" in commit message.
- Update pm_request_resume() description in commit message: distinguish
wake-capable CLK_STOP_MODE peripherals (clock-stop wake mechanism
re-asserts alert) from others (pm_request_resume() prevents manager
staying indefinitely suspended); clarify early return is harmless in
RPM_RESUMING and RPM_SUSPENDED states.
- Reword in-code comment: lead with "Paranoia check based on code
analysis," identify RPM_SUSPENDING as the only functionally significant
case, remove per-state breakdown, correct inaccurate statement about
peripheral losing power (replaced with clock-stop wake mechanism
description).
- Change dev_dbg to dev_warn; update message text to include "RPM_ACTIVE".
drivers/soundwire/bus.c | 55 +++++++++++++++++++++++++++++++++++++----
1 file changed, 50 insertions(+), 5 deletions(-)
diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c
index 15c66effbf4f..f156ecb80c3b 100644
--- a/drivers/soundwire/bus.c
+++ b/drivers/soundwire/bus.c
@@ -1667,15 +1667,55 @@ static int sdw_handle_slave_alerts(struct sdw_slave *slave)
u8 buf, buf2[2];
bool parity_check;
bool parity_quirk;
+ bool have_pm_ref = false;
+ bool have_mgr_ref = false;
+ struct device *mgr_dev = slave->bus->dev->parent;
sdw_modify_slave_status(slave, SDW_SLAVE_ALERT);
- ret = pm_runtime_get_sync(&slave->dev);
+ ret = pm_runtime_get_if_active(mgr_dev);
+ if (ret == 0) {
+ /*
+ * Paranoia check based on code analysis: this path is only
+ * functionally significant when the manager is in RPM_SUSPENDING.
+ * In that state, runtime_suspend() may be blocked in
+ * cancel_work_sync() waiting for this work to finish, while this
+ * work would block in pm_runtime_resume_and_get() waiting for the
+ * manager to complete its suspend - a circular dependency that
+ * neither side can break. Returning early breaks the deadlock.
+ *
+ * In RPM_RESUMING or RPM_SUSPENDED the early return is harmless.
+ * This issue has not been observed in practice; it is identified
+ * through code analysis.
+ *
+ * Request an async resume as a best-effort recovery: for
+ * wake-capable CLK_STOP_MODE peripherals the clock-stop wake
+ * mechanism re-asserts the alert after manager resumes; for other
+ * peripherals pm_request_resume() ensures the manager does not
+ * remain suspended after completing the ongoing suspend.
+ */
+ pm_request_resume(mgr_dev);
+ dev_warn(&slave->dev, "Alert deferred: manager not RPM_ACTIVE\n");
+ return 0;
+ }
+ if (ret > 0)
+ have_mgr_ref = true;
+ /*
+ * ret < 0 (-EINVAL): PM is disabled (CONFIG_PM=n or disable_depth > 0).
+ * Proceed without a manager reference.
+ */
+
+ ret = pm_runtime_resume_and_get(&slave->dev);
if (ret < 0 && ret != -EACCES) {
dev_err(&slave->dev, "Failed to resume device: %d\n", ret);
- pm_runtime_put_noidle(&slave->dev);
- return ret;
+ goto mgr_put;
}
+ if (ret >= 0)
+ have_pm_ref = true;
+ /*
+ * ret == -EACCES: PM is disabled on slave; proceed without a
+ * slave reference, consistent with the original -EACCES exemption.
+ */
/* Read Intstat 1, Intstat 2 and Intstat 3 registers */
ret = sdw_read_no_pm(slave, SDW_SCP_INT1);
@@ -1861,8 +1901,13 @@ static int sdw_handle_slave_alerts(struct sdw_slave *slave)
dev_warn(&slave->dev, "Reached MAX_RETRY on alert read\n");
io_err:
- pm_runtime_mark_last_busy(&slave->dev);
- pm_runtime_put_autosuspend(&slave->dev);
+ if (have_pm_ref) {
+ pm_runtime_mark_last_busy(&slave->dev);
+ pm_runtime_put_autosuspend(&slave->dev);
+ }
+mgr_put:
+ if (have_mgr_ref)
+ pm_runtime_put(mgr_dev);
return ret;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] soundwire: bus: use pm_runtime_get_if_active() in sdw_handle_slave_alerts()
2026-12-03 11:48 [PATCH v2] soundwire: bus: use pm_runtime_get_if_active() in sdw_handle_slave_alerts() Vijendar Mukunda
@ 2026-12-03 12:11 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-03 12:11 UTC (permalink / raw)
To: Vijendar Mukunda; +Cc: linux-sound
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] soundwire: bus: early return in sdw_handle_slave_alerts() drops
alerts
- [High] soundwire: bus: early return in sdw_handle_slave_alerts() hangs
qcom IRQ
--
commit 1fc0f1d3eacfdbaa69b03883111cd2662e12323a
Author: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
soundwire: bus: use pm_runtime_get_if_active() in sdw_handle_slave_alerts()
This commit checks the manager device with pm_runtime_get_if_active()
before calling pm_runtime_resume_and_get() on the slave in
sdw_handle_slave_alerts(), requesting an async resume and returning 0
early when the manager is not RPM_ACTIVE.
> diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c
> index 15c66effbf4f4..82d4902be0c9e 100644
> --- a/drivers/soundwire/bus.c
> +++ b/drivers/soundwire/bus.c
> @@ -1667,15 +1667,55 @@ static int sdw_handle_slave_alerts(struct sdw_slave *slave)
> u8 buf, buf2[2];
> bool parity_check;
> bool parity_quirk;
> + bool have_pm_ref = false;
> + bool have_mgr_ref = false;
> + struct device *mgr_dev = slave->bus->dev->parent;
>
> sdw_modify_slave_status(slave, SDW_SLAVE_ALERT);
>
> - ret = pm_runtime_get_sync(&slave->dev);
> + ret = pm_runtime_get_if_active(mgr_dev);
> + if (ret == 0) {
> + /*
> + * Paranoia check based on code analysis: this path is only
> + * functionally significant when the manager is in RPM_SUSPENDING.
> + * In that state, runtime_suspend() may be blocked in
> + * cancel_work_sync() waiting for this work to finish, while this
> + * work would block in pm_runtime_resume_and_get() waiting for the
> + * manager to complete its suspend - a circular dependency that
> + * neither side can break. Returning early breaks the deadlock.
> + *
> + * In RPM_RESUMING or RPM_SUSPENDED the early return is harmless.
> + * This issue has not been observed in practice; it is identified
> + * through code analysis.
> + *
> + * Request an async resume as a best-effort recovery: for
> + * wake-capable CLK_STOP_MODE peripherals the clock-stop wake
> + * mechanism re-asserts the alert after manager resumes; for other
> + * peripherals pm_request_resume() ensures the manager does not
> + * remain suspended after completing the ongoing suspend.
> + */
> + pm_request_resume(mgr_dev);
> + dev_warn(&slave->dev, "Alert deferred: manager not RPM_ACTIVE\n");
> + return 0;
> + }
[Severity: High]
Can returning 0 here drop peripheral alerts during runtime resume and
clock-stop suspend?
pm_runtime_get_if_active(mgr_dev) returns 0 whenever mgr_dev is not
RPM_ACTIVE, which includes RPM_RESUMING. In rpm_resume(), mgr_dev stays
in RPM_RESUMING until the manager's runtime_resume callback returns, and
calling pm_request_resume(mgr_dev) in that state is a no-op returning
-EINPROGRESS.
All three in-tree managers (AMD, Intel/Cadence, and Qualcomm) restart the
SoundWire clock and have interrupts enabled while mgr_dev is still in
RPM_RESUMING. On AMD, amd_resume_runtime() exits clock stop via
amd_sdw_clock_stop_exit() while RPM_RESUMING; if a waking peripheral
reports ALERT, amd_sdw_irq_thread() schedules amd_sdw_work and clears
ACP_SW_STATE_CHANGE_STATUS_0TO7 and ACP_SW_STATE_CHANGE_STATUS_8TO11.
Returning 0 without clearing SDW_SCP_INT1 drops the alert, and because
AMD performs no post-resume status re-poll, the peripheral remains latched
in SDW_SLAVE_ALERT with future state-change alerts suppressed. The same
loss occurs on clock-stop-mode-0 managers when mgr_dev is RPM_SUSPENDING
or RPM_SUSPENDED, as pm_request_resume() triggers a deferred resume
without a wake pulse or post-resume alert re-dispatch.
[Severity: High]
Does this early return deadlock swrm_runtime_suspend() and hang
qcom_swrm_irq_handler() on Qualcomm managers?
kworker / PM qcom_swrm_irq_handler()
swrm_runtime_suspend() [SWRM_INTERRUPT_STATUS_SLAVE_PEND_IRQ]
/* ctrl->dev is RPM_SUSPENDING */ do {
/* clock_stop_not_supported: */ sdw_handle_slave_status()
/* skips sdw_bus_clk_stop() */ sdw_handle_slave_alerts()
disable_irq(ctrl->irq) pm_runtime_get_if_active() == 0
<-- blocks forever dev_warn(...); return 0;
/* SDW_SCP_INT1 never cleared */
clear & re-read INTERRUPT_STATUS
} while (intr_sts_masked);
<-- spins forever
swrm_runtime_suspend() never masks SWRM_INTERRUPT_STATUS_SLAVE_PEND_IRQ
and skips sdw_bus_clk_stop() when ctrl->clock_stop_not_supported is set
(for any peripheral with clk_stop_mode1). With PING frames still running
and SDW_SCP_INT1 left uncleared, SWRM_INTERRUPT_STATUS_SLAVE_PEND_IRQ
stays asserted on every loop iteration, flooding unratelimited dev_warn()
messages while disable_irq() blocks forever waiting for the IRQ thread.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203114833.3096517-1-Vijendar.Mukunda@amd.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-03 12:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 11:48 [PATCH v2] soundwire: bus: use pm_runtime_get_if_active() in sdw_handle_slave_alerts() Vijendar Mukunda
2026-12-03 12:11 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox