From: sashiko-bot@kernel.org
To: "Vijendar Mukunda" <Vijendar.Mukunda@amd.com>
Cc: linux-sound@vger.kernel.org
Subject: Re: [PATCH] soundwire: bus: use pm_runtime_get_if_active() in sdw_handle_slave_alerts()
Date: Tue, 01 Dec 2026 08:56:27 +0000 [thread overview]
Message-ID: <sashiko-outbox-242897@kernel.org> (raw)
In-Reply-To: <20261201082651.3700713-1-Vijendar.Mukunda@amd.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] soundwire: bus: sdw_handle_slave_alerts() drops alerts during
RPM_RESUMING
- [High] soundwire: bus: early return in sdw_handle_slave_alerts() hangs
qcom IRQ
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [High] soundwire: race between sdw_irq_dispose_mapping() and
sdw_handle_slave_alerts() [1]
--
commit 5b44fb227649378eb41f6e363683a96229baf7ac
Author: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
soundwire: bus: use pm_runtime_get_if_active() in sdw_handle_slave_alerts()
This commit checks the runtime PM state of the manager device with
pm_runtime_get_if_active() before resuming the slave in
sdw_handle_slave_alerts(), deferring alert handling with
pm_request_resume() when the manager is not active to avoid a deadlock
with the manager's runtime_suspend callback.
> diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c
> index 15c66effbf4f4..5dc3598eb85f6 100644
> --- a/drivers/soundwire/bus.c
> +++ b/drivers/soundwire/bus.c
> @@ -1667,15 +1667,60 @@ 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) {
> + /*
> + * Manager is not RPM_ACTIVE (RPM_SUSPENDED, RPM_SUSPENDING, or
> + * RPM_RESUMING). Return early to avoid I/O on potentially
> + * inaccessible hardware and to prevent a deadlock: if the manager
> + * is in RPM_SUSPENDING, its runtime_suspend callback may be blocked
> + * in cancel_work_sync() waiting for this work, while this work
> + * would block in pm_runtime_resume_and_get() waiting for the
> + * manager to complete its suspend.
> + *
> + * Request an async resume so the deferred alert is re-serviced:
> + * - RPM_SUSPENDING: pm_request_resume() sets deferred_resume so
> + * the manager resumes immediately after its suspend completes;
> + * on resume the peripheral re-asserts the alert via the first
> + * PING frame and the interrupt fires again.
> + * - RPM_RESUMING: pm_request_resume() is a no-op (device already
> + * resuming); after the manager reaches RPM_ACTIVE, the peripheral
> + * re-asserts the alert via the first PING frame.
> + * - RPM_SUSPENDED: pm_request_resume() triggers an async resume;
> + * after resume the peripheral re-asserts via PING.
> + *
> + * When the SoundWire link fully powers off (e.g. D3 or equivalent),
> + * the peripheral loses power and its alert state does not survive;
> + * pm_request_resume() is unnecessary but harmless.
> + */
> + pm_request_resume(mgr_dev);
> + dev_dbg(&slave->dev, "Alert deferred: manager not active\n");
> + return 0;
> + }
[Severity: High]
Can returning early when mgr_dev is in RPM_RESUMING drop the peripheral
alert and leave future alerts wedged?
mgr_dev remains in RPM_RESUMING until the manager's runtime_resume callback
returns, but manager drivers restart the SoundWire bus clock and enable
interrupts inside runtime_resume before returning. For example,
amd_resume_runtime() calls amd_sdw_clock_stop_exit(), which restarts the
clock and PING frames before calling sdw_bus_exit_clk_stop(), and
swrm_runtime_resume() even calls sdw_handle_slave_status() directly:
drivers/soundwire/qcom.c:swrm_runtime_resume() {
...
qcom_swrm_get_device_status(ctrl);
sdw_handle_slave_status(&ctrl->bus, ctrl->status);
...
}
When the first PING frame after clock restart arrives while mgr_dev is
still in RPM_RESUMING, the manager IRQ/work handler clears its state-change
interrupt status register and calls sdw_handle_slave_alerts(). With
pm_runtime_get_if_active(mgr_dev) returning 0 and pm_request_resume()
doing nothing in RPM_RESUMING, sdw_handle_slave_alerts() returns without
clearing SDW_SCP_INT1 on the peripheral. Because the peripheral stays in
SDW_SLAVE_ALERT on subsequent PING frames with no new ATTACHED-to-ALERT
transition, no further state-change interrupt fires once mgr_dev reaches
RPM_ACTIVE.
[Severity: High]
Can returning 0 here without clearing the peripheral's alert registers
cause qcom_swrm_irq_handler() to spin forever and deadlock
swrm_runtime_suspend()?
Unlike Cadence and AMD managers, qcom_swrm_irq_handler() runs as a threaded
IRQ handler that loops until SWRM_INTERRUPT_STATUS_SLAVE_PEND_IRQ clears:
drivers/soundwire/qcom.c:qcom_swrm_irq_handler() {
...
case SWRM_INTERRUPT_STATUS_SLAVE_PEND_IRQ:
devnum = qcom_swrm_get_alert_slave_dev_num(ctrl);
if (devnum < 0) {
dev_err_ratelimited(ctrl->dev,
"no slave alert found.spurious interrupt\n");
} else {
sdw_handle_slave_status(&ctrl->bus, ctrl->status);
}
break;
...
ctrl->reg_write(ctrl, ctrl->reg_layout[SWRM_REG_INTERRUPT_CLEAR],
intr_sts);
ctrl->reg_read(ctrl, ctrl->reg_layout[SWRM_REG_INTERRUPT_STATUS],
&intr_sts);
intr_sts_masked = intr_sts & ctrl->intr_mask;
} while (intr_sts_masked);
CPU0 CPU1
swrm_runtime_suspend()
/* mgr_dev is RPM_SUSPENDING */
qcom_swrm_irq_handler()
do {
sdw_handle_slave_status()
sdw_handle_slave_alerts()
pm_runtime_get_if_active() == 0
return 0;
/* SLAVE_PEND_IRQ still set */
} while (intr_sts_masked);
<-- spins forever
disable_irq(ctrl->irq)
<-- waits for IRQ thread
Because sdw_handle_slave_alerts() returns without clearing SDW_SCP_INT1 on
the peripheral, SWRM_INTERRUPT_STATUS_SLAVE_PEND_IRQ remains asserted in
SWRM_REG_INTERRUPT_STATUS, so qcom_swrm_irq_handler() never exits its loop
and disable_irq() in swrm_runtime_suspend() hangs waiting for it.
[Severity: High]
This problem wasn't introduced by this patch, but nothing serializes
[1] sdw_irq_dispose_mapping() against sdw_handle_slave_alerts()
calling handle_nested_irq(slave->irq):
CPU0 CPU1
device_release_driver_internal()
sdw_bus_remove()
slave->probed = false
device_unbind_cleanup()
...
sdw_irq_dispose_mapping()
irq_dispose_mapping(slave->irq)
...
delete_irq_desc()
sdw_handle_slave_alerts()
handle_nested_irq(slave->irq)
desc = irq_to_desc(irq)
raw_spin_lock_irq(&desc->lock)
<-- NULL pointer dereference
1ccb7bb13c00 ("soundwire: Move handle_nested_irq outside of sdw_dev_lock")
moved handle_nested_irq(slave->irq) ahead of slave->sdw_dev_lock and the
slave->probed check, while sdw_irq_dispose_mapping() disposes of the IRQ
descriptor without clearing slave->irq or synchronizing with alert work.
[1] https://sashiko.dev/#/bug/linux-90121507-1cdf-435b-b5f4-ce9da544a790
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201082651.3700713-1-Vijendar.Mukunda@amd.com?part=1
next prev parent reply other threads:[~2026-12-01 8:56 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 8:26 [PATCH] soundwire: bus: use pm_runtime_get_if_active() in sdw_handle_slave_alerts() Vijendar Mukunda
2026-12-01 8:56 ` sashiko-bot [this message]
2026-12-01 10:34 ` Mukunda,Vijendar
2026-12-01 10:34 ` Mukunda,Vijendar
2026-12-01 17:14 ` Pierre-Louis Bossart
2026-12-02 6:43 ` Mukunda,Vijendar
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-242897@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Vijendar.Mukunda@amd.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.