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=1796285345; b=xNRYVhROF+NRQuviU0+a3o0QW+t7g3w96uZTKjeOOTtBEVNMBev4JZgJxTDIGxMIkyTI aQDmFJqluch0lqd3mQRvC7mMLNIHJaVUhGqKt8qSgDzdB25DnSw2fJj5DjbDLd/JGQTqM /T1B+1YkhUTzaOmS+mVIGpSIbHxeWyfTSWrbylnuCJqHmuqKpDnswafdz5fX0CcbkIxXo G7w0ACF8OrkXyy5G8pkPM5b6kT4bUS/iP/e9cqDq7x7j+sNRXJenFewll8jSb+KFV9QqW wEg6jEnwPStd479eI0N7vI2BUd/fFRYD0ff5a5TJpLmBHnXhJ4Q/BBhPwc3YqH6t7hw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796285345; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=TBbdr/zUiDPyOYzN5cF/VcVi9N6akeOh/dNNuYAkQic=; b=y4F85yYAG9qKjxGwgEgpBCyjMBNCyWjJuoLj1InHjKLBB51s4GbR29RXZrzdSQ/YgXR0 t2Vzt87MIrHYfSW9SXBPDIKAeH7UTqNI5dsKzMd8kuj6dBGkEh0zkG3iv1MiZXl7EZcy2 QCXYHnpkb2zLfkdqtfK9oSs462TJ84+aXHQ6+wI19TtSXQ9mbBXC0m2TjQytV2gwZ78FK 0XsDLXW6rWZRxe+yl37OT0ngGUNS4nPk1UyrM+uN5ORpjSBl4t86R5uhKFdYYA4eBVH/K 8uHk0fgiVM+2SzPUcoYq1jB4MEjwUQ81Y0c1R4ESIXDc5BLfH50bBdHks+Ci6+4rmWg== 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=oh3Qq2eT; 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 F1011606A32C for ; Thu, 3 Dec 2026 08:09:04 +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=oh3Qq2eT Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8F0321F00893; Thu, 3 Dec 2026 08:09:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796285344; bh=TBbdr/zUiDPyOYzN5cF/VcVi9N6akeOh/dNNuYAkQic=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=oh3Qq2eTJBrKWl02CVtOYcxvyJEk+ZfQz5gAx6mFH8fJKepX5SWuH2BBXEE3PyvyA YCPdlbMPtHB8Sj1/b6vyXd7oXEPN9FvOmDVoZYIOmHzXAfJlPv0dCfaf/l+R+BM3S8 W4pYylUHdK4zvH11qx7WGW2xfHsB7RkkwJrwUib5t5E5BW3EKfD4d8p8TOFNhB01i8 J83MWOfIxNi3sSZGEdD46/m8njm4B9tUWRN3OjaxfPuzfeO2/oQmyPNckg0JZiEjE9 qLl+1HXSbNlgLzwgBqztD35VgNgiZZJFOGxrLS2mNvaTEyrGGuTeOZpz4c5wIVT7Ji Vi3+R0jBZaMxA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 1/4] soundwire: qcom: don't touch registers when the iface clock is not live Reply-To: sashiko-reviews@lists.linux.dev To: "Ajay Kumar Nandam" Cc: linux-sound@vger.kernel.org In-Reply-To: <20261203-ak-gt-soundwire-qcom-mmrole-rework-v1-1-046ce68c8b0e@oss.qualcomm.com> References: <20261203-ak-gt-soundwire-qcom-mmrole-rework-v1-0-046ce68c8b0e@oss.qualcomm.com> <20261203-ak-gt-soundwire-qcom-mmrole-rework-v1-1-046ce68c8b0e@oss.qualcomm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 08:09:04 +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 7 potential issues to consider: - [High] soundwire: qcom: returning 0 from swrm_runtime_resume() allows unclocked MMIO - [High] soundwire: qcom: no-op runtime PM returns desynchronize hclk and IRQ state - [High] soundwire: qcom: swrm_runtime_resume() returns 0 when iface clock is not live - [Medium] soundwire: qcom: TOCTOU race in swrm_iface_clk_live() during ADSP restart - [Medium] soundwire: qcom: swrm_iface_clk_live() misuses clk_get_parent() for liveness - [Medium] soundwire: qcom: clk refcount desync when swrm_iface_clk_live() is false - [Low] soundwire: qcom: missing Fixes trailer for commit 74e79da9fd46 -- commit 683e39c266e972c60d809e7105dea93e9dd7f4e3 Author: Ajay Kumar Nandam > soundwire: qcom: don't touch registers when the iface clock is not live > > swrm_runtime_resume() and swrm_runtime_suspend() enable or disable the > interface clock before accessing controller registers. The clock's > parent provider can go away while the controller still holds a valid > struct clk. > > During an ADSP restart, this can happen when the provider disappears > before the SoundWire controller finishes its runtime-PM transition. > > Check that the interface clock still has a parent before touching the > clock or the registers it gates, and treat a missing parent as a > no-op. Do this check before the multi-master role is handled, so it > covers the dependent role's early-return path as well. > > Co-developed-by: Ravi Hothi > Signed-off-by: Ravi Hothi > Signed-off-by: Ajay Kumar Nandam [Severity: Low] This looks like a bug fix for the runtime PM callbacks. Should it include: Fixes: 74e79da9fd46 ("soundwire: qcom: add runtime pm support") > diff --git a/drivers/soundwire/qcom.c b/drivers/soundwire/qcom.c > index ad28a0fa345df..bd44d89132675 100644 > --- a/drivers/soundwire/qcom.c > +++ b/drivers/soundwire/qcom.c > @@ -2076,11 +2076,20 @@ static void qcom_swrm_remove(struct platform_devi= ce *pdev) > clk_disable_unprepare(ctrl->hclk); > } > =20 > +/* Check that the interface clock provider is still present. */ > +static bool swrm_iface_clk_live(struct qcom_swrm_ctrl *ctrl) > +{ > + return !IS_ERR_OR_NULL(clk_get_parent(ctrl->hclk)); > +} [Severity: Medium] Can clk_get_parent(ctrl->hclk) reliably tell whether the interface clock provider is still present? When ctrl->hclk's own provider unregisters, clk_unregister() replaces ops with clk_nodrv_ops and unlinks child_node without clearing core->parent. clk_get_parent() still returns non-NULL, letting runtime PM access unclocked registers, and if the parent later unregisters and is freed it dereferences a dangling core->parent pointer. It also misses grandparent unregistration (which marks descendants orphan without clearing core->parent) and sibling ADSP vote clocks such as q6afecc in kodiak.dtsi. Under !CONFIG_HAVE_CLK, clk_get_parent() is stubbed to return NULL, making runtime PM a permanent no-op. [Severity: Medium] Is there a race between swrm_iface_clk_live() and asynchronous ADSP clock teardown? clk_get_parent() drops prepare_lock before returning, so the parent clock can unregister right after the check: CPU0 CPU1 swrm_runtime_resume() swrm_iface_clk_live() -> true clk_unregister(parent) clk_core_set_parent_nolock(..., NULL) clk_prepare_enable(ctrl->hclk) ctrl->reg_write(...) <-- unclocked MMIO access Because clk_core_prepare(NULL) returns 0 on an orphaned clock, and the non-dependent path ignores the return value of clk_prepare_enable(), swrm_runtime_resume() proceeds into unclocked MMIO accesses. The same window exists across the sleeping waits in swrm_runtime_suspend(). > =20 > static int __maybe_unused swrm_runtime_resume(struct device *dev) > { > struct qcom_swrm_ctrl *ctrl =3D dev_get_drvdata(dev); > int ret; > =20 > + if (!swrm_iface_clk_live(ctrl)) > + return 0; [Severity: High] Can returning 0 here let callers access unclocked MMIO registers? When runtime_resume returns 0, rpm_resume() marks the device RPM_ACTIVE and reports success even though ctrl->hclk was never enabled. In qcom_swrm_remove(), pm_runtime_resume_and_get(peer->dev) then succeeds and writes SWRM_REG_INTERRUPT_CPU_EN and SWRM_COMP_CFG_ADDR to the unclocked peer, risking external aborts or bus hangs. Returning a negative error instead would keep the device RPM_SUSPENDED and let callers abort before touching registers. [Severity: High] Will returning 0 from swrm_runtime_resume() cause a double clk_disable_unprepare() when an autosuspended controller unbinds? During unbind of a suspended controller, __device_release_driver() runs pm_runtime_get_sync() (marking it RPM_ACTIVE without enabling hclk) and pm_runtime_put_sync(), which defers autosuspend and leaves it RPM_ACTIVE. qcom_swrm_remove() then calls clk_disable_unprepare(ctrl->hclk) a second time and triggers WARN() in clk_core_unprepare(). Commit "soundwire: qcom: disable runtime PM on controller unbind" does not avoid this, since pm_runtime_status_suspended() is false. [ ... ] > @@ -2159,6 +2168,9 @@ static int __maybe_unused swrm_runtime_suspend(stru= ct device *dev) > struct qcom_swrm_ctrl *ctrl =3D dev_get_drvdata(dev); > int ret; > =20 > + if (!swrm_iface_clk_live(ctrl)) > + return 0; [Severity: High] Does skipping swrm_runtime_suspend() desynchronize ctrl->irq and ctrl->hclk from runtime PM state? Returning 0 transitions an active controller to RPM_SUSPENDED without calling disable_irq(ctrl->irq) or clk_disable_unprepare(ctrl->hclk). While suspended, qcom_swrm_irq_handler() can still fire and read SWRM_REG_INTERRUPT_STATUS. When ADSP recovers and the parent clock re-attaches, the next swrm_runtime_resume() calls clk_prepare_enable(ctrl->hclk) a second time (leaking a reference) and calls enable_irq(ctrl->irq) on an already enabled IRQ, triggering an unbalanced-enable WARN() in __enable_irq(). [Severity: Medium] Can returning 0 here leak ctrl->hclk when an active dependent controller unbinds? QCOM_SWRM_MM_DEPENDENT controllers do not use autosuspend, so during unbind __device_release_driver() -> pm_runtime_put_sync() runs swrm_runtime_suspend() synchronously. When swrm_iface_clk_live() is false, this returns 0 without disabling ctrl->hclk and sets RPM_SUSPENDED. qcom_swrm_remove() then sees pm_runtime_status_suspended() as true and skips clk_disable_unprepare(ctrl->hclk), leaking the clock reference. Tracking whether ctrl->hclk is actually enabled would prevent runtime PM state from diverging from clock ownership. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203-ak-gt-soun= dwire-qcom-mmrole-rework-v1-0-046ce68c8b0e@oss.qualcomm.com?part=3D1