From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.14 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796303032; b=0YeX30SUbVi2VrQNU8uN45suu5oFL09HneTZAgakz30ZIFJwvVX2jCvuPCSltI/tX8Av BBbUGfs6MMXRHihAgOPAyPzI+hSl6zj+c7ysJDSpNT0M+Yu93oXtnEIcPKNZArOrMzW6/ DF/4Wce/wfptl3ZZRbPyn7TivYwhdtHG9sSnT4ckaEtHmqJPJa1OXAG+4HGNepbigHrQv plV8mSDlOXnI3WRt3IxdfvCAA+HISkYYjDc0PJyz4se7KYVp6okenURLjPU0ssASPN0jW Azu3ijqrAeZGgNOjTpVBP+6XsMVqHfNgFt54sg3f9Wx2G3NjV+mwqpJEqp9psWclYHw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796303032; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date:MIME-Version:User-Agent: Subject:To:Cc:References:Content-Language:From:In-Reply-To: Content-Type:Content-Transfer-Encoding; bh=S0edem39P8m2+kiUqVBDsBSPVe92NTKR0kDgscmT/PU=; b=2JvN7CHkE6efOFcY+mDplme1WvRO7nHw2t0EcTupbL8KX2efIEuJ5tM1MMOOxzD5B8fJ zlYea/jYqhZ+EGjfVrFgSBgXt7eWrTB1o7Y+gJjkMmpL6j7psLRvIOcYas2Y7fz2X7bzp 272lGdlZV87kH8ihELV8Ja8HXHAYpxKuDcFym+GHok4BzocbjOwpE0EV9eKRai+h1wo3M Ay70FSiqZFWZ1N6NNu/TqjEY9IqoQ0Ptya6HVRZthOeHaFsOUFYI9qDv7wzYPMc3g2FPk ofx9v3AsEM+Srum0S8P0RUCiQYwMsabcqQu7zJ7iUVMewiVvUUvhatsa04GpOUJ5h2g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b="Ko/h5qXw"; arc=none smtp.remote-ip=95.215.58.14 Received: from mta1.migadu.com (out-14.mta1.migadu.com [95.215.58.14]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3BFBF606A322 for ; Thu, 3 Dec 2026 13:03:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3BFBF606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=Ko/h5qXw X-Envelope-To: linux-sound@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=NlzOaF9wI4wEOZaa0kCHho0oipeBsyUNOAQ/NRYriac=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796303029; v=1; x=1796907829; b=Ko/h5qXwyeibBQFSmTH7+f/2IJplXv+dS8FSdB2pVUdyXWo1Ba0xvAJeBi2xrP7dtG5jsawC KEKKH52KuDBNXKi3ZHpOYy07begYvc8WZN3kPnp+yKpXv7eASltIzEKgS3U5fbc3DWAvy2sBhP3 FsLhm3aCp+eDdOpc1cC7eQUY= X-Envelope-To: linux-sound@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 695050842c25bc02; Thu, 03 Dec 2026 13:03:49 +0000 X-Mizu-Trace-ID: 695050842c25bc02 X-Migadu-Flow: FLOW_OUT Message-ID: <3cdb895d-bb14-4925-92b8-0f267eb124cf@linux.dev> Date: Thu, 3 Dec 2026 14:02:49 +0100 X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] soundwire: bus: use pm_runtime_get_if_active() in sdw_handle_slave_alerts() To: sashiko-reviews@lists.linux.dev, Vijendar Mukunda , Bard Liao , "Liao, Bard" , Vinod Koul Cc: linux-sound@vger.kernel.org References: <20261203114833.3096517-1-Vijendar.Mukunda@amd.com> Content-Language: en-US From: Pierre-Louis Bossart In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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 > > 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: > [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. >