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=1796390719; b=AU2BIOTp6CqN4ctX9PyPrGTKNUcJzn/s8Fp9ITD1XNQuOCkaEpTXGQo2rHxhie0xKtyO OUvyx/2UkMUxMlEzwNLrQkHjXgVlca0/LY8hHFdWfIQB7eOulTwZGKImBp6DQVHsmXo7O dM1VnzRGDXZecGqZTpWJCvQRR+rN6RnYHWWkiIzsK8U+O55HFjJsCGhJaCAoU/7LvPNti fbTYG6X+jfDuriASpMDZR1nkvMIJnboDZGXcRakZMTCP7/WvhGttWLTiRhI4n0nGAyKfi yJkgpahQQtn1E/IvZbFPwcv9oz3tYpseIz4H2X6+TuB3WRrGb+nHYA+bKMqKe+9zDUg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796390719; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=GxK8WH5M6AUQST8F6BdcVETbshKHcfk1C2SrpEnvVjY=; b=EkhQc5uadl+iOjCfuecOvH/uV5iPM6e1K8hX4LrtT9tlbymPPqfect13Lf+a9WGg8lyM 014fquoQmx+EUblBPoN5msa6Q4IcgBRevbpJ5rgIbYrUSWgiSF7qHJdpfZC/9bsjT7emI 0SK9s03KJ1cxmTVvlgWAawyPC4PMlW4/5KzdhjsZBTaa6623DGvnMbaCSnr8p3PXtQUyz zfOjeoGe7k8PFS+D/iAEZ1th4HOc3MWkBG9tubj+I1VEX34VFJYW2MkihiQwKNI6iX1JO E+4EZw52cHJfGAtRCw4EexuePgFXbRIeTqxZcCgV2QcJXZ/ZjW3FO2Yl71nAHrm5EQw== 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=FqvGe7Lv; 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 1C0F5606A330; Fri, 4 Dec 2026 13:25:18 +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=FqvGe7Lv Received: by smtp.kernel.org (Postfix) with ESMTPSA id 441F31F00A1B; Fri, 4 Dec 2026 13:25:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796390718; bh=GxK8WH5M6AUQST8F6BdcVETbshKHcfk1C2SrpEnvVjY=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=FqvGe7Lv8ombSWi/x6pOZJ+34jlEn2Hasn1NZjwVVGo79xI+ZnwcUyAasqosOGY1I Mbwq2iWjoZDwpRlsaRYUg8gFE7ytw86IGWPA8ky3DwdW2GlqUcK/pdGyWbSxyzI2Yi lEF4I3hHnFWtqch7OL/fozQpA5Zm0R6465zcDiltREkRLnWpMCkCID3lLaFQv/GqXy kOz1Ln/jwj2LTh2i71svIx3VSdBMSpwbLm+F9uKXrV+3Umiv7djxSD7YxF+0bTAAag EtKB5LaNJfNNGMdYKydBxgTdMOQc5PVL7VDOnR7zAzfQfBCirm/hTg10hRjX7clI5j XkyS68K+idSog== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v5 13/24] ASoC: qcom: audioreach: add speaker protection calibration trigger infrastructure Reply-To: sashiko-reviews@lists.linux.dev To: "Srinivas Kandagatla" Cc: linux-sound@vger.kernel.org, devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org In-Reply-To: <20261204113101.1141644-14-srinivas.kandagatla@oss.qualcomm.com> References: <20261204113101.1141644-1-srinivas.kandagatla@oss.qualcomm.com> <20261204113101.1141644-14-srinivas.kandagatla@oss.qualcomm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 13:25:17 +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 8 potential issues to consider: - [High] ASoC: qcom: audioreach: argument mismatch breaks compilation - [High] ASoC: qcom: audioreach: AB-BA deadlock on sp_vi_r0_lock and watchdog - [High] ASoC: qcom: q6apm: sp_cal_watchdog UAF due to early shutdown in apm_remove() - [Medium] ASoC: qcom: audioreach: races across sp_operation_mode, armed, and watchdog - [Medium] ASoC: qcom: audioreach: empty VI event falsely completes calibration - [Medium] ASoC: qcom: audioreach: missing VI disarm on error and watchdog desync - [Medium] ASoC: qcom: audioreach: audioreach_sp_shutdown() leaves calibration stuck - [Medium] ASoC: qcom: audioreach: split sp_operation_mode reads during graph setup -- commit 32fbe7bee8c50fa2ff9735485256480782651b1a Author: Ravi Hothi ASoC: qcom: audioreach: add speaker protection calibration trigger infrastr= ucture This commit introduces a module-global sp_operation_mode state and an edge-triggered calibration API guarded by a 60-second delayed work watchdog, automatically returning the mode to Normal when VI calibration reaches a terminal state. > diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/aud= ioreach.c > index a187e0b136330..be37681f467fb 100644 > --- a/sound/soc/qcom/qdsp6/audioreach.c > +++ b/sound/soc/qcom/qdsp6/audioreach.c [ ... ] > @@ -1456,6 +1459,65 @@ static int audioreach_gain_set(struct q6apm_graph = *graph, [ ... ] > +static void audioreach_sp_cal_watchdog_fn(struct work_struct *work) > +{ > + if (cmpxchg(&sp_operation_mode, PARAM_ID_SP_VI_OP_MODE_CALIBRATION, > + PARAM_ID_SP_VI_OP_MODE_NORMAL) !=3D > + PARAM_ID_SP_VI_OP_MODE_CALIBRATION) > + return; > + > + audioreach_sp_disarm_vi(); > + pr_info("audioreach: SP calibration watchdog fired, back to Normal\n"); > +} > + > +/* Finish before writing the mode so a trigger racing in cannot be clobb= ered */ > +static void audioreach_sp_finish_calibration(void) > +{ > + cancel_delayed_work_sync(&sp_cal_watchdog); > + WRITE_ONCE(sp_operation_mode, PARAM_ID_SP_VI_OP_MODE_NORMAL); > +} > + > +/* Release the delayed work from the module on unload so the timer canno= t fire */ > +void audioreach_sp_shutdown(void) > +{ > + cancel_delayed_work_sync(&sp_cal_watchdog); > +} > +EXPORT_SYMBOL_GPL(audioreach_sp_shutdown); [Severity: Medium] Can audioreach_sp_shutdown() leave sp_operation_mode wedged in Calibration across an ADSP subsystem restart? On an ADSP crash/restart, apr_pd_status() invokes apr_remove_device() -> apm_remove() and later re-probes via apm_probe() while snd-q6apm.ko stays loaded. Because audioreach_sp_shutdown() cancels sp_cal_watchdog without resetting sp_operation_mode to Normal or clearing sp_vi_r0.armed, no timer remains to revert the mode, leaving subsequent calibration triggers failing with -EBUSY and normal playback configuring Calibration mode until reboot or module reload. > + > +int audioreach_trigger_sp_calibration(void) > +{ > + if (cmpxchg(&sp_operation_mode, PARAM_ID_SP_VI_OP_MODE_NORMAL, > + PARAM_ID_SP_VI_OP_MODE_CALIBRATION) !=3D > + PARAM_ID_SP_VI_OP_MODE_NORMAL) > + return -EBUSY; > + > + schedule_delayed_work(&sp_cal_watchdog, > + SP_CAL_WATCHDOG_SECS * HZ); > + return 0; > +} [Severity: Medium] Can lockless updates to sp_operation_mode race with sp_vi_r0.armed and sp_cal_watchdog, causing a stale watchdog or completion to corrupt a new calibration run? CPU0 CPU1 ---- ---- audioreach_sp_cal_watchdog_fn() cmpxchg(&sp_operation_mode, CALIBRATION, NORMAL) audioreach_trigger_sp_calibration() cmpxchg(..., NORMAL, CALIBRATION) schedule_delayed_work(...) audioreach_arm_vi_calibration() sp_vi_r0.armed =3D true audioreach_sp_disarm_vi() sp_vi_r0.armed =3D false <-- disarms the new run Because sp_operation_mode is mutated via cmpxchg/WRITE_ONCE outside sp_vi_r0_lock, an expiring watchdog can disarm a newly triggered run so its events are silently dropped. Two related races share the same cause: if audioreach_sp_finish_calibration= () runs between cmpxchg() and schedule_delayed_work() in audioreach_trigger_sp_calibration(), it leaves an orphaned watchdog pending that will fire early on a later run (since schedule_delayed_work() does not re-arm a pending timer). Likewise, audioreach_sp_finish_calibration() unconditionally cancels sp_cal_watchdog and writes Normal without verifying run ownership, which can clobber a newly triggered run if the watchdog already expired or if audioreach_speaker_protection_vi() armed VI from a stale mode snapshot. Protecting sp_operation_mode, sp_vi_r0.armed, and watchdog scheduling under a shared lock or generation counter would close these races. [ ... ] > @@ -1506,10 +1568,6 @@ void audioreach_vi_calibration_event(struct device= *dev, > unsigned int i; > u32 bit; > =20 > - /* A payload with no entries gives no new information */ > - if (!num_ch) > - return; > - > guard(mutex)(&sp_vi_r0_lock); [Severity: Medium] Why was the zero-channel guard removed here? q6apm_vi_calibration_event() does not reject num_ch =3D=3D 0, and in audioreach_vi_calibration_event() both decisive and success start as true. An empty calibration event therefore skips the channel loop and falls throu= gh to record SP_VI_CALI_SUCCESS with num_ch =3D 0, wiping cached R0 values, disarming sp_vi_r0, and prematurely returning sp_operation_mode to Normal. [ ... ] > @@ -1566,14 +1624,16 @@ void audioreach_vi_calibration_event(struct devic= e *dev, > } > =20 > dev_info(dev, "VI calibration complete: %s\n", success ? "success" : "f= ailed"); > + > + /* Edge-triggered: the mode auto-returns to Normal on terminal state. */ > + audioreach_sp_finish_calibration(); > } [Severity: High] Does calling audioreach_sp_finish_calibration() while holding sp_vi_r0_lock create an ABBA deadlock with sp_cal_watchdog? CPU0 CPU1 ---- ---- lock(&sp_vi_r0_lock) lock(&sp_cal_watchdog) lock(&sp_cal_watchdog) lock(&sp_vi_r0_lock) *** DEADLOCK *** CPU0: audioreach_vi_calibration_event() -> audioreach_sp_finish_calibration= () -> cancel_delayed_work_sync(&sp_cal_watchdog) CPU1: audioreach_sp_cal_watchdog_fn() -> audioreach_sp_disarm_vi() audioreach_sp_finish_calibration() calls cancel_delayed_work_sync() before clearing sp_operation_mode, so an overlapping watchdog succeeds in cmpxchg() and blocks on sp_vi_r0_lock. Because audioreach_vi_calibration_event() runs on the single-threaded qcom_apr_rx workqueue, this permanently stalls all QDSP6 GPR/APR IPC and triggers a lockdep inversion warning on every terminal calibration event. Note that commit "ASoC: qcom: audioreach: send cached R0/T0 to the VI module in normal mode" later avoids this deadlock by droppi= ng audioreach_sp_disarm_vi() and switching to cancel_delayed_work(), which reintroduces races with a newly triggered run. > =20 > static int audioreach_speaker_protection(struct q6apm_graph *graph, > - const struct audioreach_module *module, > - uint32_t operation_mode) > + const struct audioreach_module *module) > { > return audioreach_send_u32_param(graph, module, PARAM_ID_SP_OP_MODE, > - operation_mode); > + READ_ONCE(sp_operation_mode)); > } [Severity: Medium] Can reading sp_operation_mode separately for MODULE_ID_SPEAKER_PROTECTION and MODULE_ID_SPEAKER_PROTECTION_VI configure the two modules in mismatched modes? q6apm_graph_media_format_pcm() calls audioreach_set_media_format() for each module in the graph across sleeping q6apm_send_cmd_sync() IPCs without snapshotting sp_operation_mode once per graph setup. A calibration trigger or watchdog expiry between the two modules can put SP in Normal and VI in Calibration (failing with VI_CALIBRATION_STATE_INCORRECT_OP_MODE), or SP in Calibration while VI stays in Normal without arming or registering events. [ ... ] > @@ -1640,11 +1701,13 @@ static int audioreach_speaker_protection_vi(struc= t q6apm_graph *graph, > return -EINVAL; > } > =20 > - audioreach_arm_vi_calibration(); > + if (mode =3D=3D PARAM_ID_SP_VI_OP_MODE_CALIBRATION) { > + audioreach_arm_vi_calibration(); > =20 > - rc =3D audioreach_register_events(graph, module); > - if (rc) > - return rc; > + rc =3D audioreach_register_events(graph, module); > + if (rc) > + return rc; > + } [Severity: Medium] Does returning an error after audioreach_arm_vi_calibration() leave sp_vi_r0.armed set? If audioreach_register_events(), audioreach_alloc_apm_cmd_pkt(), or q6apm_send_cmd_sync() fails, sp_vi_r0.armed stays true (allowing subsequent DSP events to wipe cached R0 values) while sp_operation_mode stays in Calibration until the watchdog fires. On watchdog timeout, audioreach_sp_disarm_vi() also leaves sp_vi_r0.state stuck in SP_VI_CALI_RUNNING, and commit "ASoC: qcom: audioreach: send cached R0/T0 to the VI module in normal mode" later drops audioreach_sp_disarm_vi() altogether, leaving sp_vi_r0.armed set as well. [ ... ] > @@ -1760,7 +1823,7 @@ int audioreach_set_media_format(struct q6apm_graph = *graph, > break; > case MODULE_ID_SPEAKER_PROTECTION: > rc =3D audioreach_speaker_protection(graph, module, > - PARAM_ID_SP_OP_MODE_CALIBRATION); > + READ_ONCE(sp_operation_mode)); > if (!rc) > rc =3D audioreach_module_enable(graph, module, true); [Severity: High] Does this commit compile? audioreach_speaker_protection() was changed to take 2 arguments, but this call site still passes 3; conversely, audioreach_speaker_protection_vi() was changed to take a 4th mode argument, but the MODULE_ID_SPEAKER_PROTECTION_VI case right below still passes only 3. This breaks builds whenever CONFIG_SND_SOC_QDSP6_APM is enabled and breaks git bisectability across the series (later commits in the series also mismatch these signatures before reconciling them). > diff --git a/sound/soc/qcom/qdsp6/q6apm.c b/sound/soc/qcom/qdsp6/q6apm.c > index c410e2f6e6a3f..6494eb80f0897 100644 > --- a/sound/soc/qcom/qdsp6/q6apm.c > +++ b/sound/soc/qcom/qdsp6/q6apm.c > @@ -950,6 +950,8 @@ static int apm_probe(gpr_device_t *gdev) > =20 > static void apm_remove(gpr_device_t *gdev) > { > + /* Release the SP calibration watchdog before the module goes away */ > + audioreach_sp_shutdown(); > g_apm =3D NULL; > of_platform_depopulate(&gdev->dev); > snd_soc_unregister_component(&gdev->dev); [Severity: High] Can sp_cal_watchdog be re-scheduled after audioreach_sp_shutdown() and fire after snd-q6apm.ko is unloaded? CPU0 CPU1 ---- ---- apm_remove() audioreach_sp_shutdown() cancel_delayed_work_sync(...) audioreach_trigger_sp_calibration() schedule_delayed_work(&sp_cal_watchdog) of_platform_depopulate(...) snd_soc_unregister_component(...) snd-q6apm.ko unloaded audioreach_sp_cal_watchdog_fn() <-- use-after-free in freed module Because audioreach_sp_shutdown() runs before of_platform_depopulate() and snd_soc_unregister_component(), the kcontrols remain active and can arm the 60-second watchdog again before teardown completes. The error path in apm_probe() when of_platform_populate() fails also calls snd_soc_unregister_component() without calling audioreach_sp_shutdown(). Calling audioreach_sp_shutdown() after both teardown calls (and keeping it rather than dropping it in commit "ASoC: qcom: audioreach: send cached R0/T0 to the VI module in normal mode") would prevent the use-after-free. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204113101.1141= 644-1-srinivas.kandagatla@oss.qualcomm.com?part=3D13