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=1796074496; b=KFc5l21Yg83cv7WmnTcWdBAlKegGoffm0XOaWFBBcAcbCpYTjMzEqDSdSd1cbqpZnGDJ ZN39i24aKwVt+9bdPkU89Szgg80khB7szvL6H9LKWoZcDGWSydM0/u129PGqlasfcx0Jc KOdBmR2Az9LOy+V6FWkJFeyRBX+hx9n/N1hagNJNU0c6FhsZEEm8RQs6ROZi/L+p+QCU3 f3n3JT1kIK4XaakR2Cdd6XH5+lUKZV2cdhQYtlC3i7VCFSF8PhF0tM/LA0Ze+hhpyL84P /a4funMPN2XXbbJ9lvcc+Ik1uVJtn2QsuHK/s1dbGP0pyxaLikVyQr+ogu9Df/Iq4UA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796074496; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=au/+6nmgC3nRHoT4uxKqjm+7ou4JY1Foq5VI21+hgoc=; b=subeiqgug8w7frjhy+X4MPfDqUyrh4gR45xfI6xae6lrYOoA5nSVSkjLd8SF4lfGpuSh 5tsdsyO582lwNFrtqSjcik/Q7y+t2gWK0/RgCjCGFu5hDoOzdUr32cq+d61f7X6jegtzn PGX5A8XcArQMPLinGjBxfxQfSS4PAM7dQS5rWwgBp3c0+MLHIZ17g0gThgvj1mzHb2vem 4eQIQTWPFm1u/TascgCROJfM8A7DGgkayq2CK6n2TR+kZxGMWybLakaTp0rX9MWij1Wa5 ghRSU7daINPDDHCQcYhv4MyQm8gVZMt7OljCpKb9ZuUb1y55LrxgdRZA2jGpl17wTqw== 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=k4hrqrT2; 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 40689606A339; Mon, 30 Nov 2026 21:34:56 +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=k4hrqrT2 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9EAB01F00A22; Mon, 30 Nov 2026 21:34:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796074495; bh=au/+6nmgC3nRHoT4uxKqjm+7ou4JY1Foq5VI21+hgoc=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=k4hrqrT2eZxK2NoDIFecwxViUxtTBYTJitHD4TAiU7LDB9uexuWBicuQvzZzDzT+z /iIktRf+7ESegcODpzi1Py1C+2LPnKPhu5ZXhR6GB3jxM+eRdI72/L1tAjg1UBx+Vk Bs2VMAMEFSit1MS0BvgZbc20JvBJKSPvUmeUw7wHRc7T/qGBFZ68gQc81GrkgmQ/H1 4NepA1wHsbKwwAjlYs5l5N+4tcUXKsMwDBSh6R+VldFS0kl5LhS+6ErJpj9JuaTtxx G+7V5YT25Fe1HXibJyb8X+sm2gicOEmdrU621lIR4NV5QTXdGQoxgE4fClc+2GPUBY 2Vv2dOkXRMChA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v3 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: <20261130212258.7376-14-srinivas.kandagatla@oss.qualcomm.com> References: <20261130212258.7376-1-srinivas.kandagatla@oss.qualcomm.com> <20261130212258.7376-14-srinivas.kandagatla@oss.qualcomm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 21:34:55 +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 be3dacbf17b1806a48e11abe0048fb2d600d3603 Author: Ravi Hothi ASoC: qcom: audioreach: add speaker protection calibration trigger infrastr= ucture This commit adds internal speaker protection operation mode state, an edge-triggered calibration start helper with a 60-second watchdog, and automatic reset to Normal mode on calibration completion. > diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/aud= ioreach.c > index 2b5c083b8ae56..130298a287496 100644 > --- a/sound/soc/qcom/qdsp6/audioreach.c > +++ b/sound/soc/qcom/qdsp6/audioreach.c [ ... ] > @@ -1482,6 +1485,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 audioreach_sp_finish_calibration() cancel or abort a newly triggered calibration run? Because sp_operation_mode is reset to PARAM_ID_SP_VI_OP_MODE_NORMAL before cancel_delayed_work(&sp_cal_watchdog), a concurrent audioreach_trigger_sp_calibration() can re-arm sp_operation_mode in the window between the two statements: 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_watchdo= g, ...) cancel_delayed_work(&sp_cal_watchdog) <-- cancels new run's watchdog If the new run is never followed by playback, sp_operation_mode stays in PARAM_ID_SP_VI_OP_MODE_CALIBRATION permanently and every future trigger returns -EBUSY. Similarly, because cancel_delayed_work() is not synchronous, an already-dequeued audioreach_sp_cal_watchdog_fn() from the old run can execute its cmpxchg() after CPU1 re-triggers and flip the new run back to Normal immediately. > + > +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] Can sp_cal_watchdog remain queued on system_percpu_wq 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 q6apm_audio_remove() calls cancel_delayed_work_sync(&sp_cal_watchdog). Unloading the module while the 60-second watchdog is pending leaves the timer and work item active in freed module memory, causing a use-after-free when the timer fires. [ ... ] > @@ -1639,6 +1686,7 @@ static int audioreach_speaker_protection_vi(struct = q6apm_graph *graph, > const struct audioreach_module *module, > const struct audioreach_module_config *mcfg) > { > + u32 mode =3D READ_ONCE(sp_operation_mode); > u32 num_channels =3D mcfg->num_channels; > struct apm_module_sp_vi_op_mode_cfg *op_cfg; > struct apm_module_sp_vi_channel_map_cfg *cm_cfg; > @@ -1662,11 +1710,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] Can sp_operation_mode and sp_vi_r0.armed get out of sync when the watchdog fires or when VI module setup fails? If audioreach_sp_cal_watchdog_fn() fires while a calibration stream is already armed (for example, playback starts near the end of the 60-second window and runs past it), the watchdog resets sp_operation_mode to Normal without clearing sp_vi_r0.armed. A second audioreach_trigger_sp_calibration() call can then succeed while the first run is still active on the DSP, and when the first run reaches a terminal event, audioreach_vi_calibration_event() calls audioreach_sp_finish_calibration() and silently disarms the second trigger. In addition, if audioreach_register_events(), audioreach_alloc_apm_cmd_pkt(), or q6apm_send_cmd_sync() fails in audioreach_speaker_protection_vi(), the error path returns with sp_vi_r0.armed still set to true. [ ... ] > @@ -1781,8 +1831,7 @@ int audioreach_set_media_format(struct q6apm_graph = *graph, > rc =3D audioreach_gapless_set_media_format(graph, module, cfg); > break; > case MODULE_ID_SPEAKER_PROTECTION: > - rc =3D audioreach_speaker_protection(graph, module, > - PARAM_ID_SP_OP_MODE_CALIBRATION); > + rc =3D audioreach_speaker_protection(graph, module); > if (!rc) > rc =3D audioreach_module_enable(graph, module, true); [Severity: Medium] Can MODULE_ID_SPEAKER_PROTECTION and MODULE_ID_SPEAKER_PROTECTION_VI be configured with different operation modes during the same graph setup? q6apm_graph_media_format_pcm() iterates over the modules in a graph and sleeps in q6apm_send_cmd_sync() for each one. Because audioreach_speaker_protection() and audioreach_speaker_protection_vi() each do their own unlocked READ_ONCE(sp_operation_mode), a concurrent audioreach_trigger_sp_calibration() or watchdog timeout between the two calls configures one module in Normal mode and the other in Calibration mode. That either causes the DSP to fail calibration with VI_CALIBRATION_STATE_INCORRECT_OP_MODE or leaves MODULE_ID_SPEAKER_PROTECTI= ON in Calibration mode while VI runs in Normal mode without arming sp_vi_r0.armed or registering calibration events. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261130212258.7376= -1-srinivas.kandagatla@oss.qualcomm.com?part=3D13