Linux Sound subsystem development
 help / color / mirror / Atom feed
From: "Mukunda,Vijendar" <vijendar.mukunda@amd.com>
To: Pierre-Louis Bossart <pierre-louis.bossart@linux.dev>,
	sashiko-reviews@lists.linux.dev,
	Bard Liao <yung-chuan.liao@linux.intel.com>,
	"Liao, Bard" <bard.liao@intel.com>, Vinod Koul <vkoul@kernel.org>,
	srini@kernel.org
Cc: linux-sound@vger.kernel.org, "Dommati,
	Sunil-kumar" <Sunil-kumar.Dommati@amd.com>,
	Mario Limonciello <Mario.Limonciello@amd.com>
Subject: Re: [PATCH v2] soundwire: bus: use pm_runtime_get_if_active() in sdw_handle_slave_alerts()
Date: Thu, 3 Dec 2026 19:20:46 +0530	[thread overview]
Message-ID: <47b75028-5574-4a26-aee2-080a653760fc@amd.com> (raw)
In-Reply-To: <3cdb895d-bb14-4925-92b8-0f267eb124cf@linux.dev>



On 12/3/26 18:32, Pierre-Louis Bossart wrote:
> On 12/3/26 13:11, sashiko-bot@kernel.org wrote:
>> 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.
> I didn't realize that this seemingly harmless return 0 could get in the
> way of interrupt handling... Ugh.
>
> It's possible the same problem reported above occurs on Intel hardware.
> I vaguely remember that the Cadence IP will only throw an interrupt when
> the peripheral status changes from ATTACHED to ALERT. If we return
> without dealing with the interrupt registers, it's possible that the
> alert is not handled a second time.
>
> Bard, do you happen to remember the details of the interrupt handling? I
> no longer have access to the documentation.
> Adding Vinod as well since the bot seems to drop people in To: and CC:
++

The concern is valid. The circular dependency only arises when the
manager is in RPM_SUSPENDING: runtime_suspend blocks in cancel_work_sync()
waiting for the alert work, while the alert work blocks in
pm_runtime_resume_and_get() waiting for the manager's suspend to complete.

For RPM_RESUMING no cancel_work_sync() is in flight, so there is no
deadlock risk. The early return for RPM_RESUMING is therefore unnecessary.

@Pierre-Louis :Would restricting the early return to RPM_SUSPENDING only be
the right fix in your opinion?
>
>> [Severity: High]
>> Does this early return deadlock swrm_runtime_suspend() and hang
>> qcom_swrm_irq_handler() on Qualcomm managers?
Adding Srinivas from Qualcomm to this thread for confirmation.

Based on our code walkthrough of swrm_runtime_suspend(), when
clock_stop_not_supported is set, we do not see a disable_irq(ctrl->irq)
call. Instead the function calls clk_disable_unprepare(ctrl->hclk)
followed by enable_irq(ctrl->wake_irq). Our understanding is that once
clk_disable_unprepare() stops the hardware clock, register reads in
qcom_swrm_irq_handler() return 0, intr_sts_masked becomes 0, and the
do-while loop exits — so the hang and spin described above would not
occur. This looks like a false positive. Srinivas, please correct us if
our understanding of the Qualcomm code path is wrong.

The unratelimited dev_warn() flooding concern raised above is valid
regardless, and will be addressed in the next revision.
>>
>> 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.
>>


      reply	other threads:[~2026-12-03 13:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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
2026-12-03 13:02   ` Pierre-Louis Bossart
2026-12-03 13:50     ` Mukunda,Vijendar [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=47b75028-5574-4a26-aee2-080a653760fc@amd.com \
    --to=vijendar.mukunda@amd.com \
    --cc=Mario.Limonciello@amd.com \
    --cc=Sunil-kumar.Dommati@amd.com \
    --cc=bard.liao@intel.com \
    --cc=linux-sound@vger.kernel.org \
    --cc=pierre-louis.bossart@linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=srini@kernel.org \
    --cc=vkoul@kernel.org \
    --cc=yung-chuan.liao@linux.intel.com \
    /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