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=1796130753; b=O/asTR+sKw8hZhSJg/x/x741HbnUN18hPj3XUFMkA7MksCBLNJzS2d2SFrOXcFjai2Xk CELDFSQBZVaAL54bYLK/LcFf9l7Uitk1p837zCc8U2HcsFCC4h6uYUWXuMQ4IB8az5sTw ii9HMzo2+kQ9JkwUxNaXqcJQlK+QL6+0xpR8JhJ5ceYnHxyCoZ6d6CT29AwbDqCGryd/b QzAUVZf8a0v/Hbw6ej9FCdzrrFjlg+8x7UXfFimPYg9WyVYwYL3LR9JXNLNQ+A0IHJiIn zGewwmnKpsHuqz6GxAkBy13YHmDoUKdX6MRr54Okj2sDIF/cxLd5gyC7w625BlvqgfA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796130753; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=xgrIcX4IHDYOrR/RDTxvLGG55Qfzj39Vz/iJCEyp1Xg=; b=2dDz22DWdxajcNnTL+IiWU3HguHWCrWrUBjERyoM2LES3qRKy+aBg3w9Ysidwnyl/OvW rvWFxWvuMvQCBDpCeO+rmHkTBNKe8pt0EZjcsxnsfk44q7TFoFwwjAObQ/UOwflxCb/OQ zUWMoODsU/fH/hJmkxevJ2h5JiJv+9azIPRR8r7G32MnC1ndWudTRAGBF8OaO6sCa81Bl CHPNOcrMIN53JqMLHmzErLpNYeAU9aAELggRBJYot/DAk4/qOKaXBD96UVUGjKwDZI3lY gxL020gfHbndVLGXnBgRlpuA0voetlbDUK7pLEzSnjdhgNtQAGgk1N7oNlJlaeNd8kQ== 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=X5ecwWty; 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 688C5606A33E; Tue, 1 Dec 2026 13:12:33 +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=X5ecwWty Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1B6971F00929; Tue, 1 Dec 2026 13:12:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796130752; bh=xgrIcX4IHDYOrR/RDTxvLGG55Qfzj39Vz/iJCEyp1Xg=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=X5ecwWtycwmkC3wXwIGs1UAWW8RheNM3kIpsn4t58B/dET9hS2/N3rO9mSrV3jwqW YBPqeID6ElPW0jjmAZblicDUwPLg99bBoiQ7+WAE3Au9H6GjezxlXVtYNl4UtpYay6 sSBU/oMPvSN8g0AvW1rr8/vryuIL5PLCxUzuaJiuIo13J4Cz5Hd1bTtd7zgMIqUnlF ZR+vzXas87z77pxMcCHA5OfThE2ITW2IBTRBUaGhmky650HkO8FR+S94qcbCd/H6Bf S26QF6bo+GE/Fkbtfv64idT6Hz7JRSVEDVgkEIdOlWy6lKaCsNxQJidJXqgzpCo4jR vH+mprOyaZjmw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v4 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: <20261201124753.196748-14-srinivas.kandagatla@oss.qualcomm.com> References: <20261201124753.196748-1-srinivas.kandagatla@oss.qualcomm.com> <20261201124753.196748-14-srinivas.kandagatla@oss.qualcomm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Tue, 01 Dec 2026 13:12:31 +0000 X-Mailing-List: devicetree@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 4 potential issues to consider: - [High] ASoC: qcom: audioreach: missing cancel_delayed_work_sync() on module unload - [Medium] ASoC: qcom: audioreach: watchdog race in audioreach_sp_finish_calibration() - [Medium] ASoC: qcom: audioreach: desynchronized calibration state on timeout or error - [Medium] ASoC: qcom: audioreach: split sp_operation_mode read across SP and VI modules -- commit 1f0f3a4d2d0ba4e2a629bbda935112fa18551e13 Author: Ravi Hothi ASoC: qcom: audioreach: add speaker protection calibration trigger infrastr= ucture This commit introduces an internal speaker protection operation mode state with an edge-triggered calibration helper and a 60-second watchdog timer to return the mode to Normal. > diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/aud= ioreach.c > index c48ba63448dbd..dd0b70013a0ec 100644 > --- a/sound/soc/qcom/qdsp6/audioreach.c > +++ b/sound/soc/qcom/qdsp6/audioreach.c [ ... ] > @@ -1456,6 +1459,48 @@ static int audioreach_gain_set(struct q6apm_graph = *graph, > return q6apm_send_cmd_sync(graph->apm, pkt, 0); > } > =20 > +u32 audioreach_get_sp_operation_mode(void) > +{ > + return READ_ONCE(sp_operation_mode); > +} > + > +/* > + * Calibration is edge-triggered rather than a user-visible mode. Guard > + * against a trigger write while a run is still in flight, and bound the > + * armed state with a watchdog so a trigger without a matching playback > + * does not leave the system in Calibration forever. > + */ > +#define SP_CAL_WATCHDOG_SECS 60 > + > +static void audioreach_sp_cal_watchdog_fn(struct work_struct *work); > +static DECLARE_DELAYED_WORK(sp_cal_watchdog, audioreach_sp_cal_watchdog_= fn); > + > +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=3D > + PARAM_ID_SP_VI_OP_MODE_CALIBRATION) > + pr_info("audioreach: SP calibration watchdog fired, back to Normal\n"); > +} > + > +static void audioreach_sp_finish_calibration(void) > +{ > + WRITE_ONCE(sp_operation_mode, PARAM_ID_SP_VI_OP_MODE_NORMAL); > + cancel_delayed_work(&sp_cal_watchdog); > +} [Severity: Medium] Can a concurrent audioreach_trigger_sp_calibration() race with audioreach_sp_finish_calibration() and end up with no watchdog armed? CPU0 CPU1 audioreach_sp_finish_calibration() WRITE_ONCE(sp_operation_mode, ..._NORMAL) audioreach_trigger_sp_calibration() cmpxchg(&sp_operation_mode, ..._NORMAL, ..._CALIBRATION) schedule_delayed_work(&sp_cal_watch= dog, ...) cancel_delayed_work(&sp_cal_watchdog) <-- cancels CPU1's watchdog Because sp_operation_mode is reset to PARAM_ID_SP_VI_OP_MODE_NORMAL before cancel_delayed_work(&sp_cal_watchdog), CPU1 can re-enter calibration mode while the previous delayed work is still pending or about to be cancelled. This leaves sp_operation_mode in PARAM_ID_SP_VI_OP_MODE_CALIBRATION without a running watchdog timer, so if no playback completes, all future triggers fail with -EBUSY. Similarly, because cancel_delayed_work() does not wait for an in-flight audioreach_sp_cal_watchdog_fn() callback to finish, a callback that already started for the finishing run can run cmpxchg() after CPU1 triggers a new run and immediately flip the new run back to Normal. > + > +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: High] What stops sp_cal_watchdog from firing after the snd-q6apm module is unloaded? CONFIG_SND_SOC_QDSP6_APM is tristate and builds audioreach.o into snd-q6apm.ko, but neither apm_remove() nor a module exit path calls cancel_delayed_work_sync(&sp_cal_watchdog). If calibration is triggered and snd-q6apm is unloaded during the 60-second window, the timer expires after the module text and data are freed and executes audioreach_sp_cal_watchdog_fn() in unmapped memory (use-after-free). > @@ -1562,14 +1607,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(); > } > =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 MODULE_ID_SPEAKER_PROTECTION and MODULE_ID_SPEAKER_PROTECTION_VI be configured with different operation modes in the same graph? q6apm_graph_media_format_pcm() configures each module in the graph in turn and sleeps in q6apm_send_cmd_sync() on every command. Because audioreach_speaker_protection() and audioreach_speaker_protection_vi() read sp_operation_mode independently without serialization against audioreach_trigger_sp_calibration() or audioreach_sp_cal_watchdog_fn(), a trigger or watchdog timeout between the two calls configures one module in Normal mode and the other in Calibration mode. If SP is in Normal mode while VI is in Calibration mode, calibration fails with VI_CALIBRATION_STATE_INCORRECT_OP_MODE; if SP is in Calibration mode while VI is in Normal mode, sp_vi_r0 is never armed and calibration events are not registered, leaving sp_operation_mode stuck in Calibration until the watchdog expires. [ ... ] > @@ -1636,11 +1684,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 sp_vi_r0.armed stay out of sync with sp_operation_mode if the watchdog fires or if VI setup fails? When audioreach_sp_cal_watchdog_fn() times out after 60 seconds, it resets sp_operation_mode to PARAM_ID_SP_VI_OP_MODE_NORMAL without taking sp_vi_r0_lock to clear sp_vi_r0.armed or update sp_vi_r0.state. If a calibration playback started near the end of the 60-second window or takes longer than 60 seconds, the watchdog flips sp_operation_mode back to Normal while sp_vi_r0.armed remains true; a new audioreach_trigger_sp_calibration() call can then succeed and later be silently reset to Normal when a terminal event from the earlier run reaches audioreach_vi_calibration_event() and calls audioreach_sp_finish_calibration(). In addition, if audioreach_register_events(), audioreach_alloc_apm_cmd_pkt(), or q6apm_send_cmd_sync() fails in audioreach_speaker_protection_vi() after audioreach_arm_vi_calibration(), the error path returns with sp_vi_r0.armed still set to true and sp_operation_mode left in PARAM_ID_SP_VI_OP_MODE_CALIBRATION. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261201124753.1967= 48-1-srinivas.kandagatla@oss.qualcomm.com?part=3D13