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=1796393042; b=b6Y+2vuhd/9xCJcDbWfW7li5bib7fp58vT+WYMrZrFxCR8Jcr45ARj4kEelHEXgbLTuZ RkWbAXFG2FYUfNOtwQx44sF76XvwlPauI4L3/cl+TsFZOMPAh1EOUEigVr0jluwkwenWi ZvsjnKcw2kJAUaPfJ6hXtJNSuiW+PBo9cSOTWonMXhybxWdnxcULTpBYuklq4ZaGGBxwD D4kh21Mv1Pl3qyTLTl+hXPF2sRttua6sIs5qbsfCjyymV9ztLgIcIwzK+Wzb7EHvF3wYK Q+4mRCCQsZBYS+LKCAFEGL6taZK40xc8LMRugWETNHYczBauQwJNP5czQr+d9hHAntg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796393042; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=rY6n16jZ/YMeMfolwgV1oh9DKAPLXU92g9FiZTpkT4c=; b=fiaNjNnybZ2q7ZOlfz8peU0veHG9YAVVBeJjYhSVWG07i1j2wrStKiP3baL5v82zsyNU RFQW4CEs2iJNKZ6af3XWobwsuFUieOfAOBsYfiuFfZzJhZ4b8r7ksyHaPMw4/E8q8d1Kq ddHgSI4Kc4Syw/prCwYJ2c+JH3rNYNnz+FQ1BWc+brQ32A6iM8zAj3oZ0/Gt1peEbl7l5 Y0l5TBCfhkthoeatrXUiyhZrF5U1GfZd4TlVj7gW4NIqJH3t7rEXC9FLkZ8dZXieRDg5I 8PORSyug3Dv6caX3Cob+qv5nFdGiZSq4dNbAwIljGyx7Vmrx5sqr1Lo/X/4eTczCOag== 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=PcFyRTBf; 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 2FC49606A32D; Fri, 4 Dec 2026 14:04:01 +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=PcFyRTBf Received: by smtp.kernel.org (Postfix) with ESMTPSA id 67E0D1F000CE; Fri, 4 Dec 2026 14:04:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796393041; bh=rY6n16jZ/YMeMfolwgV1oh9DKAPLXU92g9FiZTpkT4c=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=PcFyRTBfIogbo0Ip3lROF8RCuJU26ftNDLnQs8Dfh7AMZ28ezfYti+A6pfEu+7TVm ZyK1ESndGJ8W8vHHgfui8W4oMEgk+2dqp0IA961//eN3pTCL4IIr+q+O3Hy5hemgx7 ItTfPRcFBzTrH7daF3W8x6IozMu8oKFS9yEy1oPekhHtn+Na2dluXX7Gs1/4h4m0FB ipv81dom7UWdL8NZpVtYZ1xKfUrPm6al2OGOTPHYEi9sMxKHg/RZlGQKw483pPGhnm VIB0lhGWW/OBxJ+yMwtqbhwySel+rf4aESBotRxEdh8p0McB5kV2gkQC0D/COAp/vi UdtysU7EPDegg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v5 18/24] ASoC: qcom: audioreach: add live speaker temperature (T0) readback 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-19-srinivas.kandagatla@oss.qualcomm.com> References: <20261204113101.1141644-1-srinivas.kandagatla@oss.qualcomm.com> <20261204113101.1141644-19-srinivas.kandagatla@oss.qualcomm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 14:04:01 +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 12 potential issues to consider: - [High] ASoC: qcom: audioreach: deadlock holding sp_vi_r0t0_cfg_lock across GPR IPC - [High] ASoC: qcom: audioreach: thermal read in calibration callback can deadlock - [High] ASoC: qcom: audioreach: uncancelled sp_cal_watchdog work on unload - [High] ASoC: qcom: audioreach: sp_cal_watchdog not cancelled on module unload - [High] ASoC: qcom: audioreach: audioreach_vi_calibration_event() caches 0 degC T0 - [Medium] ASoC: qcom: audioreach: TOCTOU race on sp_operation_mode in VI setup - [Medium] ASoC: qcom: audioreach: missing calibration teardown on VI setup errors - [Medium] ASoC: qcom: audioreach: T0 read with PA active and missing count check - [Medium] ASoC: qcom: audioreach: watchdog race in audioreach_sp_finish_calibration() - [Low] ASoC: qcom: audioreach: unchecked T0 range and s16 cast on calibration - [Low] ASoC: qcom: audioreach: commit omits regressive VI and lock changes - [Low] ASoC: qcom: audioreach: zero-channel VI event treated as calibration success -- commit 56bf9ae64c86f85671795a9786fef3749d76fe65 Author: Srinivas Kandagatla > ASoC: qcom: audioreach: add live speaker temperature (T0) readback > > A calibration needs each speaker's die temperature when R0 is measured, > so that the R0/T0 pair given back to the DSP is consistent. > > Let the machine driver register the speakers' thermal zones in VI > channel order with audioreach_sp_register_speaker_map(), and expose > their temperatures in Q6 format as a read-only "Speaker Protection T0" > control. Record T0 with R0 when a calibration completes. A slot that > cannot be read reports 0. > > Signed-off-by: Srinivas Kandagatla > Reported-by: kernel test robot > Closes: https://lore.kernel.org/oe-kbuild-all/202611231947.lq10qE2P-lkp@i= ntel.com/ [Severity: Low] Does the commit message omit several unrelated changes to audioreach_speaker_protection_vi() and audioreach_set_media_format()? Beyond adding T0 readback, this patch drops the sp_vi_r0t0_cfg snapshot so sp_vi_r0t0_cfg_lock is held across q6apm_send_cmd_sync(), deletes error cleanup after audioreach_register_events(), switches back from local mode to sp_operation_mode, and fixes the mismatched 4-argument call site left by commit "ASoC: qcom: audioreach: send cached R0/T0 to the VI module in normal mode". Those look like an accidental rebase or conflict resolution. > diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/aud= ioreach.c > index d1f6cd2b66354..cf6c686f88bdd 100644 > --- a/sound/soc/qcom/qdsp6/audioreach.c > +++ b/sound/soc/qcom/qdsp6/audioreach.c [ ... ] > +int audioreach_get_sp_vi_t0(long *vals, unsigned int count) > +{ > + unsigned int i, n; > + bool any_failed =3D false; > + > + guard(mutex)(&sp_speaker_map_lock); > + > + n =3D min(count, sp_speaker_map.num); > + for (i =3D 0; i < n; i++) { > + int mdeg; > + > + if (sp_speaker_map.tz[i] && > + !thermal_zone_get_temp(sp_speaker_map.tz[i], &mdeg)) { > + vals[i] =3D div_s64((s64)mdeg * 64, 1000); > + } else { > + vals[i] =3D 0; > + any_failed =3D true; > + } > + } > + for (; i < count; i++) > + vals[i] =3D 0; > + > + if (any_failed) > + return -EAGAIN; > + > + return n; > +} [Severity: High] Can calling audioreach_get_sp_vi_t0() from audioreach_vi_calibration_event() deadlock the single-threaded qcom_apr_rx workqueue? When a WSA884x PA is off and the SoundWire controller or WSA macro is runtime-suspended, thermal_zone_get_temp() resumes the hardware and sends a synchronous Q6PRM clock request whose response is processed on the same qcom_apr_rx workqueue: qcom_apr_rx (single-threaded wq) graph_callback() audioreach_vi_calibration_event() audioreach_get_sp_vi_t0() thermal_zone_get_temp() wsa884x_get_temp() pm_runtime_resume_and_get() swrm_runtime_resume() clk_prepare_enable(ctrl->hclk) wsa_macro_enable_clocks() q6prm_send_cmd_sync() wait_event_timeout(&prm->wait) <-- waits for prm_callback() on this same wq A concurrent userspace read of "Speaker Protection T0" or thermal sysfs holding sp_speaker_map_lock, tz->lock, or wsa884x->sp_lock inside q6prm_send_cmd_sync() also stalls qcom_apr_rx for the 5-second timeout, blocking all GPR responses and PCM callbacks. Sampling T0 outside the GPR RX workqueue avoids this. [ ... ] > @@ -1704,12 +1769,28 @@ void audioreach_vi_calibration_event(struct devic= e *dev, > if (success) { > - guard(mutex)(&sp_vi_r0t0_cfg_lock); > - sp_vi_r0t0_cfg.num_ch =3D num_ch; > - for (i =3D 0; i < num_ch; i++) > - sp_vi_r0t0_cfg.r0_cali_q24[i] =3D cali->cali_param[i].r0_cali_q24; > + int t0_rc =3D audioreach_get_sp_vi_t0(t0_live, num_ch); > + > + if (t0_rc < 0) { > + dev_warn(dev, > + "VI calibration: T0 unreadable, not caching R0/T0 (%d)\n", > + t0_rc); > + success =3D false; > + } else { [Severity: High] Can this still cache 0 degC for T0 when fewer than num_ch speaker thermal zones are registered? audioreach_get_sp_vi_t0() zero-fills slots past sp_speaker_map.num without setting any_failed and returns n >=3D 0, so the t0_rc < 0 check passes whenever sp_speaker_map.num < num_ch (for example on machine drivers that do not call audioreach_sp_register_speaker_map()). Storing 0 degC alongside a room-temperature R0 makes the DSP underestimate voice-coil temperature by 25 to 40 degC, defeating thermal limiting. Note that later commit "ASoC: qcom: audioreach: add speaker protection calibration state control" also removes the any_failed/-EAGAIN return and the t0_rc < 0 check altogether, which causes unreadable zones to cache 0 degC as well. Requiring num_ch > 0 and t0_rc =3D=3D (int)num_ch (and keeping the -EAGAIN check) prevents caching invalid T0 values. [Severity: Medium] Can audioreach_get_sp_vi_t0() read live hardware temperature here while the speaker PA is active? audioreach_vi_calibration_event() runs during active playback when wsa884x->pa_on is true, and wsa884x_get_temp() cannot sample TADC while the PA is on: it returns -EAGAIN on a fresh boot before any off-state read, or returns an arbitrarily stale cached temperature from earlier. Priming T0 before DAPM enables the PA (for instance during DAI prepare in audioreach_speaker_protection_vi()) would pair R0 with a fresh reading. Note that later commit "ASoC: qcom: audioreach: add speaker protection calibration state control" also drops the -EAGAIN check, turning the cold-boot failure into silently cached 0 degC values. [Severity: Low] What happens if the DSP sends a calibration event with num_ch =3D=3D 0? q6apm_vi_calibration_event() allows cali->num_ch =3D=3D 0 or a payload with= no cali_param entries to reach audioreach_vi_calibration_event() with num_ch =3D=3D 0. With zero iterations, decisive and success stay true and audioreach_get_sp_vi_t0(t0_live, 0) returns 0, overwriting sp_vi_r0t0_cfg.num_ch with 0 and wiping any previously cached R0/T0. > + guard(mutex)(&sp_vi_r0t0_cfg_lock); > + sp_vi_r0t0_cfg.num_ch =3D num_ch; > + for (i =3D 0; i < num_ch; i++) { > + sp_vi_r0t0_cfg.r0_cali_q24[i] =3D cali->cali_param[i].r0_cali_q24; > + sp_vi_r0t0_cfg.t0_cali_q6[i] =3D (s16)t0_live[i]; > + } > + } > } [Severity: Low] Should t0_live[i] be range-checked against [SP_VI_T0_MIN_Q6, SP_VI_T0_MAX_Q6] before narrowing to s16? WSA884x thermal zones can legitimately report up to 150 degC, which exceeds SP_VI_T0_MAX_Q6 (80 degC), so caching it unchecked sends an out-of-range T0 to the DSP and causes subsequent restore via audioreach_set_sp_vi_r0t0() to fail with -ERANGE. Out-of-range thermal readings outside s16 bounds would also silently wrap on the cast. [ ... ] > @@ -1794,11 +1875,8 @@ static int audioreach_speaker_protection_vi(struct= q6apm_graph *graph, > audioreach_arm_vi_calibration(); > =20 > rc =3D audioreach_register_events(graph, module); > - if (rc) { > - audioreach_sp_finish_calibration(); > - audioreach_sp_disarm_vi(); > + if (rc) > return rc; > - } > } [Severity: Medium] Does removing the cleanup here leave calibration armed and stuck in Calibration mode when audioreach_register_events(), packet allocation, or q6apm_send_cmd_sync() fails? sp_operation_mode stays in PARAM_ID_SP_VI_OP_MODE_CALIBRATION for up to 60 seconds (causing retries to return -EBUSY and intervening playback to configure Calibration mode), and sp_vi_r0.armed remains true indefinitely because audioreach_sp_cal_watchdog_fn() never clears it. Even with audioreach_vi_calibration_abort() added later in the series, returning early when no DSP events have arrived still leaves sp_operation_mode stuck in Calibration mode. [Severity: Medium] Can audioreach_sp_finish_calibration() race with a concurrent audioreach_trigger_sp_calibration() and cancel the new run's watchdog? audioreach_sp_finish_calibration() writes PARAM_ID_SP_VI_OP_MODE_NORMAL before calling cancel_delayed_work(&sp_cal_watchdog): CPU0 CPU1 audioreach_sp_finish_calibration() WRITE_ONCE(sp_operation_mode, NORMAL) audioreach_trigger_sp_calibration() cmpxchg(..., NORMAL, CALIBRATION) schedule_delayed_work(&sp_cal_watchdog) cancel_delayed_work( &sp_cal_watchdog) <-- cancels CPU1's watchdog An already-running audioreach_sp_cal_watchdog_fn() can also abort CPU1's new calibration run back to Normal because cancel_delayed_work() does not wait for it. Calling cancel_delayed_work_sync(&sp_cal_watchdog) before resetting sp_operation_mode closes both windows. [ ... ] > @@ -1862,26 +1940,23 @@ static int audioreach_speaker_protection_vi(struc= t q6apm_graph *graph, > if (rc) > return rc; > =20 > - if (mode =3D=3D PARAM_ID_SP_VI_OP_MODE_NORMAL) { > + if (sp_operation_mode =3D=3D PARAM_ID_SP_VI_OP_MODE_NORMAL) { [Severity: Medium] Does re-reading sp_operation_mode here introduce a data race and a TOCTOU mismatch with the local mode already sent to the DSP? sp_operation_mode is updated concurrently via cmpxchg() and WRITE_ONCE(), and q6apm_send_cmd_sync() sleeps just above. If calibration is triggered while q6apm_send_cmd_sync() sleeps, a Normal-mode VI module skips PARAM_ID_SP_TH_VI_R0T0_CFG; conversely, if calibration finishes or times out in that window, Normal-mode R0/T0 config is sent to a Calibration-mode module. Checking the snapshotted local mode avoids both. > struct apm_module_sp_th_vi_r0t0_cfg *r0t0_cfg; > - struct sp_vi_r0t0_cfg snap; > int r0t0_sz; > =20 > - /* Snapshot the cache so q6apm_send_cmd_sync runs with no locks held */ > - scoped_guard(mutex, &sp_vi_r0t0_cfg_lock) > - snap =3D sp_vi_r0t0_cfg; > + guard(mutex)(&sp_vi_r0t0_cfg_lock); [Severity: High] Can holding sp_vi_r0t0_cfg_lock across q6apm_send_cmd_sync() deadlock the single-threaded qcom_apr_rx workqueue? audioreach_vi_calibration_event() runs on qcom_apr_rx and acquires sp_vi_r0t0_cfg_lock, while q6apm_send_cmd_sync() waits for apm_callback() on the same workqueue: CPU0 (DAI prepare) qcom_apr_rx (single-threaded wq) ------------------ -------------------------------- audioreach_speaker_protection_vi() lock(&sp_vi_r0t0_cfg_lock) q6apm_send_cmd_sync() wait_event_timeout(&apm->wait) graph_callback() audioreach_vi_calibration_event() lock(&sp_vi_r0t0_cfg_lock) <-- bloc= ks apm_callback() <-- cannot run to wake &apm->wait This stalls all GPR responses and PCM callbacks for the 5-second command timeout and causes speaker protection activation to fail with -ETIMEDOUT. Keeping the stack snapshot under scoped_guard(mutex, &sp_vi_r0t0_cfg_lock) avoids holding the lock across IPC. [ ... ] > diff --git a/sound/soc/qcom/qdsp6/audioreach.h b/sound/soc/qcom/qdsp6/aud= ioreach.h > index 780d3df717d0e..e60e9c6561223 100644 > --- a/sound/soc/qcom/qdsp6/audioreach.h > +++ b/sound/soc/qcom/qdsp6/audioreach.h > @@ -1136,6 +1137,10 @@ u32 audioreach_get_sp_operation_mode(void); > int audioreach_trigger_sp_calibration(void); > void audioreach_get_sp_vi_r0t0(long *vals, unsigned int count); > int audioreach_set_sp_vi_r0t0(struct device *dev, const long *vals, unsi= gned int count); > +int audioreach_sp_register_speaker_map(struct thermal_zone_device * cons= t *tzs, > + unsigned int num); > +int audioreach_get_sp_vi_t0(long *vals, unsigned int count); > +int audioreach_add_sp_telemetry_controls(struct snd_soc_component *compo= nent); > void audioreach_vi_calibration_event(struct device *dev, > const struct event_id_vi_per_spkr_calibration *cali, > u32 num_ch); [Severity: High] Is sp_cal_watchdog left pending on module unload? audioreach_trigger_sp_calibration() schedules the 60-second module-global sp_cal_watchdog delayed work, and audioreach.h still declares audioreach_sp_shutdown(), but its implementation and call in apm_remove() were dropped by commit "ASoC: qcom: audioreach: send cached R0/T0 to the VI module in normal mode". Unloading snd-q6apm while the timer is pending leads to a use-after-free when audioreach_sp_cal_watchdog_fn() runs in freed module memory. [Severity: High] Can unloading snd-q6apm within 60 seconds of a calibration trigger crash the kernel when sp_cal_watchdog fires? apm_remove() unregisters the component without calling cancel_delayed_work_sync(&sp_cal_watchdog), leaving the timer queued on system_wq after module text and static data are freed. Restoring audioreach_sp_shutdown() and calling it in apm_remove() after component and child teardown prevents both the use-after-free and re-arming from userspace kcontrol writes. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204113101.1141= 644-1-srinivas.kandagatla@oss.qualcomm.com?part=3D18