From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796115388; b=nC3BDFPb7/BcIgNu0NQLJYJloaHbMCoU9u82xGIhQlhlTM1aqsgQrM512VqGVVRlJBaQ w8AMw6TAH80/eMbsA7XZbzRD2xC2X1qwOJrLu/IraSKhWLPijqIn3GzvkWEAgu5k8bT5Q zRgfr+cPGfhotjBDBieKF7oVRhPA1461UeN5wGr/jjXZUlWGjHmn7CQ4d2qOrPK+R9wu4 rXvpy25UnFvOdg4s/oJofh4xLrvyqi9gZFuafEW4KNsgB2Msl0w0Ooza983udL1rsEhCi 012gjURxnkf/x/V70ZX5n+hHG7XWbWvBDBQQvMHaSYsKHSc+opKMfad3i0Lc1g7BTgg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796115388; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=8KSsdZfWBb8B002dwoX4AEPgHr21FC9i3pdpR/oSTLg=; b=xZUQBg1d9zo/YrZ+f5J/Gs20vaLHdaROdr+tXEZTiQy9wKWiK0R7naWWEIUp5ttGEwTX XC0Qvk2UgA+OrfwrV1ldOmmKAs2HL0fctvVuFLFH1ZeBue9TC3B1Z0VnxqldcZErnE00X JJ1bpHpJ0mXTKclAxnL3ao2mnEinoOeroOEjqw0Z+Wmf/MApgi15HWv4YrSv1NmYwI44E ttKMxue8FdjyfayJw6h1lsbLNPbaXYWqX/ZVFe97IntPdi/3f127G3BvdTMLKrza0fKSL WOYZWmWWONMfB2bSZfQ1kP+FSI7PlgjfrmNwGzcz/h9K6tSrdVu4Y81nKoDRvRp3NNg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="MR6J/bNw"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 744ED606A31A for ; Tue, 1 Dec 2026 08:56:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=MR6J/bNw Received: by smtp.kernel.org (Postfix) with ESMTPSA id EF3801F000C1; Tue, 1 Dec 2026 08:56:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796115388; bh=8KSsdZfWBb8B002dwoX4AEPgHr21FC9i3pdpR/oSTLg=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=MR6J/bNwvPbyvdBc8HQHkcwhCWeqQ4katrGzDaFQNSUvYZNhK9mAP4VJGjs802kul o16/mt6I7MgOKMjoYCjewqlBOuiWKN6hy8Ja9bXFoCyiRuKyQPVhBit631YWknpiPA e3j936EKAPbJ5KIIQcpoNsTytrSnaeRDX0XaKqnOUPJWEl0Y0yq1X5YSeLv6C1iSrd EzJJHxJzY09R8fG0XOjnOCcHcs++wpehz3QrOOfqNORbkrvVAEC09UO+PcAp5DMrtB gFwEj6/Ze7xjOPU4/zdpM0eZ2IaXuAfcZNnmRto+n6MXJ4YRUYEIaW4RJzNcILEH2R Z3DIB1hhgPBBw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] soundwire: bus: use pm_runtime_get_if_active() in sdw_handle_slave_alerts() Reply-To: sashiko-reviews@lists.linux.dev To: "Vijendar Mukunda" Cc: linux-sound@vger.kernel.org In-Reply-To: <20261201082651.3700713-1-Vijendar.Mukunda@amd.com> References: <20261201082651.3700713-1-Vijendar.Mukunda@amd.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Tue, 01 Dec 2026 08:56:27 +0000 X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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_sla= ve *slave) > u8 buf, buf2[2]; > bool parity_check; > bool parity_quirk; > + bool have_pm_ref =3D false; > + bool have_mgr_ref =3D false; > + struct device *mgr_dev =3D slave->bus->dev->parent; > =20 > sdw_modify_slave_status(slave, SDW_SLAVE_ALERT); > =20 > - ret =3D pm_runtime_get_sync(&slave->dev); > + ret =3D pm_runtime_get_if_active(mgr_dev); > + if (ret =3D=3D 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 =3D 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 =3D 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() = =3D=3D 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 =3D 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 =3D 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 --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261201082651.3700= 713-1-Vijendar.Mukunda@amd.com?part=3D1