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=1796393793; b=Gk6ZBKVieQAyHWYNEigPETN/9EipvIkXXpuIY2Ii17tNeQf7en3iGUHrk19r1OQZbVJC Fa2yeJ3X4j193iFjIbb5A3fTvjeNdfPFDYjjb69oi5m2bKRBkbHHqIxruOUtW63dr2qrY uw307IGIpzbOK2ivO9B4ZsbS3cDJB97OS32akfdNfzrMQWQkNyRQGWb6g+8opHOO7G+/s ELdMNtTtJVDH/Az+3BeYuvNtluVA2cqbuxx9DICzh+XEK0Ab6/Y7NsA18jN7QSCQgDOHl xc+W9cFBwz1j620/UGCsGL0jfVIG/tTTKJxFAP0IBqzwRSkP2JGIgYDXbInmhn8ydJw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796393793; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=WmQid2XS9oCagr141ZjqYDE96thA8SO4eB6sdhoFjBI=; b=QsiTraci67wQj0FIiwIpGvvPmJbM5/1407P3Fg/d9ZaDTGccxruNyxL1RU8fHruSPO1O gxZ+gtt2iYr/1IAp/+VR3Q3KpVdofsDbjPJ16av3lxj5Pk7CXv8KntJwnr8V+kpC307/q ezovKijbaz8B6d+sqDak89G7CPBviyN/o/PAQsB9ttjiS/w6PYW1IWaO5y7DzzynEYk3X wOveQIVn0j35+MkHyOrtxMVRHOfGADhdPG+QbdMG2JrLU3jAq9rx2wyb1JskvKLAK5Ipc CoQcQzCUUIEEZu+1oekPpv4j8up0SeAVWkRWpkEwQH86QH+6vdmgya4fv0jS3l7EExA== 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=X4BRy2gW; 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 34CB0606A33B; Fri, 4 Dec 2026 14:16:32 +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=X4BRy2gW Received: by smtp.kernel.org (Postfix) with ESMTPSA id 862AC1F0093A; Fri, 4 Dec 2026 14:16:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796393792; bh=WmQid2XS9oCagr141ZjqYDE96thA8SO4eB6sdhoFjBI=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=X4BRy2gW9iE1opEtMxVgALWHSYlejFH3lGtsgJrLYeFuxQ61P7Thz66vzF0kxe9y9 Ihl19UACWRCjbFKI7Uu9Lf1IsjRV8OvExOrKtHH1hZePvbtQHooYfJrPmuM0kYQFLN 81QRQGOI09MdsmkXNo9dg0uSI7EEKulFZMEfMVtgNL53CRgCymW30VNbuSVoC8uBAB JE3O+G+s927BECTVQsbT1p1yQa1L5g6DJ9edcYJWBpsQbp0LD5qbCjXDe1L98ZDPEJ GqcZwk8PKDIYCjhYIdEV5yI7mbz8KeoDi/pmmEdNOrk/hlSePTSgm/rgKVL6kDU/rq sb6QOANcy52yQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v5 21/24] ASoC: qcom: x1e80100: register WSA speaker thermal zones for speaker protection 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-22-srinivas.kandagatla@oss.qualcomm.com> References: <20261204113101.1141644-1-srinivas.kandagatla@oss.qualcomm.com> <20261204113101.1141644-22-srinivas.kandagatla@oss.qualcomm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 14:16:32 +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 11 potential issues to consider: - [High] ASoC: qcom: sp_cal_watchdog not cancelled on apm_remove() causing unload UAF - [High] ASoC: qcom: deadlock on qcom_apr_rx via audioreach_get_sp_vi_t0() - [High] ASoC: qcom: deadlock holding sp_vi_r0t0_cfg_lock across q6apm_send_cmd_sync() - [Medium] ASoC: qcom: undocumented audioreach.c edits mixed into x1e80100 commit - [Medium] ASoC: qcom: audioreach_vi_calibration_abort() skips mode reset on early abort - [Medium] ASoC: qcom: audioreach_vi_calibration_event() leaves stale last_state entries - [Medium] ASoC: qcom: audioreach_vi_calibration_event() treats num_ch =3D=3D 0 as success - [Medium] ASoC: qcom: audioreach_sp_finish_calibration() races with calibration trigger - [Medium] ASoC: qcom: races in audioreach_sp_finish_calibration() and watchdog - [Medium] ASoC: qcom: TOCTOU races from repeated sp_operation_mode reads - [Medium] ASoC: qcom: audioreach_vi_calibration_event() caches 0 degC when T0 unread -- commit 1e72e7acf4cbfb553e5573406d950d671352b644 Author: Srinivas Kandagatla > ASoC: qcom: x1e80100: register WSA speaker thermal zones for speaker prot= ection > > Look up the thermal zone of each WSA884x VI DAI on the WSA Playback > link, in DT order, and register them with > audioreach_sp_register_speaker_map() for the "Speaker Protection T0" > control. A missing zone is logged and leaves its slot reading 0. The > map is cleared when the link is torn down. > > Signed-off-by: Srinivas Kandagatla [Severity: Medium] Should the sound/soc/qcom/qdsp6/audioreach.c changes be split out of this commit? The commit message only describes registering WSA884x thermal zones in x1e80100.c, while the diff also makes three unmentioned edits to audioreach.c. In particular, reverting audioreach_speaker_protection() back to two arguments silently fixes a build failure introduced by commit "ASoC: qcom: audioreach: add speaker protection calibration state control", where audioreach_set_media_format() still passes two arguments. Folding that signature fix into the introducing commit keeps git bisect buildable across the series. > diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/aud= ioreach.c > index 166ce59347f8d..cf30c18fa25ff 100644 > --- a/sound/soc/qcom/qdsp6/audioreach.c > +++ b/sound/soc/qcom/qdsp6/audioreach.c > @@ -1731,7 +1731,6 @@ void audioreach_vi_calibration_event(struct device = *dev, > sp_vi_r0.state =3D SP_VI_CALI_RUNNING; > sp_vi_r0.num_ch =3D 0; > memset(sp_vi_r0.r0_cali_q24, 0, sizeof(sp_vi_r0.r0_cali_q24)); > - memset(sp_vi_r0.last_state, 0, sizeof(sp_vi_r0.last_state)); > } [Severity: Medium] Does removing this memset() leave stale calibration states in sp_vi_r0.last_state[]? Nothing else clears last_state before a run, and the loop below only writes indices 0..num_ch - 1, while audioreach_get_sp_vi_cal_state() returns all MAX_SP_VI_SPEAKERS slots to userspace. If a 2-channel calibration runs after a 4-channel calibration, slots 2 and 3 will still report the previous run's terminal states through the Speaker Protection Calibration State control. > for (i =3D 0; i < num_ch; i++) { [Severity: Medium] Can audioreach_vi_calibration_event() treat a zero-channel DSP event as a successful calibration and wipe the cached R0/T0 values? q6apm_vi_calibration_event() can pass num_ch =3D=3D 0 when cali->num_ch is = 0 or the payload carries no cali_param entries. With decisive and success initialized to true, the loop runs zero times and execution falls through to set sp_vi_r0t0_cfg.num_ch =3D 0, discarding any valid cached R0/T0 data. T= he if (!num_ch) return guard from commit "ASoC: qcom: audioreach: cache VI calibration results per speaker" was dropped in commit "ASoC: qcom: audioreach: add speaker protection calibration trigger infrastructure". [ ... ] > @@ -1806,9 +1805,6 @@ void audioreach_vi_calibration_abort(struct device = *dev) > { > unsigned int i; > =20 > - /* Back to Normal before anything else, so a racing trigger is clean */ > - audioreach_sp_finish_calibration(); > - > guard(mutex)(&sp_vi_r0_lock); > =20 > if (!sp_vi_r0.armed) > @@ -1838,14 +1834,17 @@ void audioreach_vi_calibration_abort(struct devic= e *dev) > } > =20 > dev_info(dev, "VI calibration aborted: graph stopped before the DSP fin= ished\n"); > + > + /* Edge-triggered: the mode auto-returns to Normal on abort too. */ > + audioreach_sp_finish_calibration(); > } [Severity: Medium] Does moving audioreach_sp_finish_calibration() here skip resetting sp_operation_mode when a calibration run aborts before the first DSP event? If prepare fails after audioreach_arm_vi_calibration() or the graph stops before any event arrives, sp_vi_r0.seen_states is still all zeroes, so audioreach_vi_calibration_abort() clears sp_vi_r0.armed and returns early without calling audioreach_sp_finish_calibration(). sp_operation_mode then stays in PARAM_ID_SP_VI_OP_MODE_CALIBRATION for up to 60 seconds, causing retries to fail with -EBUSY and normal playback to configure the DSP in calibration mode. Calling audioreach_sp_finish_calibration() right after clearing sp_vi_r0.armed avoids this. [Severity: High] Can unloading snd-q6apm while sp_cal_watchdog is pending cause a use-after-free? audioreach_trigger_sp_calibration() schedules the module-static delayed work sp_cal_watchdog for 60 seconds, but apm_remove() never cancels it synchronously (audioreach_sp_shutdown() is still declared in audioreach.h, after its definition and call were dropped in commit "ASoC: qcom: audioreac= h: send cached R0/T0 to the VI module in normal mode"). CPU0 kworker audioreach_trigger_sp_calibration() schedule_delayed_work(&sp_cal_watchdog, ...) rmmod snd-q6apm apm_remove() (watchdog still pending) module text and .bss freed audioreach_sp_cal_watchdog_fn() <-- use-after-free Calling cancel_delayed_work_sync(&sp_cal_watchdog) from apm_remove() closes this window. [Severity: Medium] Can audioreach_sp_finish_calibration() cancel the watchdog of a newly triggered calibration run? Because WRITE_ONCE(sp_operation_mode, PARAM_ID_SP_VI_OP_MODE_NORMAL) runs before cancel_delayed_work(&sp_cal_watchdog), a concurrent trigger can arm a new calibration and lose its 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 Calibration then stays armed indefinitely if no playback runs. [Severity: Medium] Can an in-flight audioreach_sp_cal_watchdog_fn() prematurely abort a new calibration run or leave sp_vi_r0.armed desynchronized? Because audioreach_sp_finish_calibration() uses asynchronous cancel_delayed_work(), a watchdog callback that is already running can execute cmpxchg(CALIBRATION -> NORMAL) after a fresh audioreach_trigger_sp_calibration() succeeds. In addition, when the watchd= og fires after audioreach_arm_vi_calibration(), it resets sp_operation_mode to NORMAL without taking sp_vi_r0_lock or clearing sp_vi_r0.armed, leaving the two state flags out of sync. > static int audioreach_speaker_protection(struct q6apm_graph *graph, > - const struct audioreach_module *module, > - u32 mode) > + const struct audioreach_module *module) > { > - return audioreach_send_u32_param(graph, module, PARAM_ID_SP_OP_MODE, mo= de); > + return audioreach_send_u32_param(graph, module, PARAM_ID_SP_OP_MODE, > + READ_ONCE(sp_operation_mode)); > } [Severity: Medium] Can reading sp_operation_mode separately in audioreach_speaker_protection() and audioreach_speaker_protection_vi() program the two speaker protection modules into mismatched modes? During audioreach_set_media_format(), blocking GPR commands run between configuring MODULE_ID_SPEAKER_PROTECTION and MODULE_ID_SPEAKER_PROTECTION_V= I. If calibration is triggered or the watchdog expires in between, one module gets Normal mode and the other gets Calibration mode. In addition, audioreach_speaker_protection_vi() later re-reads global sp_operation_mode without READ_ONCE() instead of checking its local mode snapshot, so it can either omit PARAM_ID_SP_TH_VI_R0T0_CFG in Normal mode or send it after configuring Calibration mode. Snapshotting sp_operation_mode once per graph prepare avoids both races. [Severity: High] Can holding sp_vi_r0t0_cfg_lock across q6apm_send_cmd_sync() in audioreach_speaker_protection_vi() deadlock with qcom_apr_rx? q6apm_send_cmd_sync() waits for apm_callback() to run on the single-threaded qcom_apr_rx workqueue, while audioreach_vi_calibration_event() runs on that same workqueue and acquires sp_vi_r0t0_cfg_lock on calibration completion: CPU0 qcom_apr_rx ---- ----------- audioreach_speaker_protection_vi() lock(&sp_vi_r0t0_cfg_lock) q6apm_send_cmd_sync() wait_event_timeout(&apm->wait) audioreach_vi_calibration_event() lock(&sp_vi_r0t0_cfg_lock) <-- blocks If a decisive calibration event is queued ahead of the APM_CMD_SET_CFG response, qcom_apr_rx stalls until the 5-second command timeout expires and speaker protection activation fails with -ETIMEDOUT. Copying sp_vi_r0t0_cfg under the lock and releasing it before calling q6apm_send_cmd_sync() breaks the dependency. > diff --git a/sound/soc/qcom/x1e80100.c b/sound/soc/qcom/x1e80100.c > index 745975574658c..938d444f0e4bc 100644 > --- a/sound/soc/qcom/x1e80100.c > +++ b/sound/soc/qcom/x1e80100.c [ ... ] > + /* Also drops the zones of a previous bind when none are found */ > + audioreach_sp_register_speaker_map(tzs, num); > +} [Severity: High] Can registering WSA884x thermal zones here deadlock the single-threaded qcom_apr_rx workqueue when audioreach_get_sp_vi_t0() reads a zone whose PA is off? When wsa884x->pa_on is false, thermal_zone_get_temp() -> wsa884x_get_temp() calls pm_runtime_resume_and_get(wsa884x->dev), which resumes the SoundWire controller and lpass_wsamacro -> q6prmcc -> q6prm_send_cmd_sync(). Because q6apm and q6prm share the single-threaded qcom_apr_rx workqueue, two deadlocks occur: qcom_apr_rx audioreach_vi_calibration_event() audioreach_get_sp_vi_t0() thermal_zone_get_temp() wsa884x_get_temp() pm_runtime_resume_and_get() -> ... -> q6prm_send_cmd_sync() wait_event_timeout(&prm->wait) <-- waits on qcom_apr_rx A userspace Speaker Protection T0 read can also ABBA deadlock with qcom_apr_rx by holding sp_speaker_map_lock while waiting in q6prm_send_cmd_sync() as qcom_apr_rx blocks on sp_speaker_map_lock inside audioreach_vi_calibration_event(). Either path stalls all GPR responses for 5 seconds per clock vote and causes calibration to record 0 degC as T0. [Severity: Medium] Will calibration on a freshly booted system silently cache 0 degC as the reference temperature T0? Before any PA-off temperature read has happened, wsa884x->temperature is 0. During calibration playback wsa884x->pa_on is true, so wsa884x_get_temp() returns -EAGAIN and thermal_zone_get_temp() fails with -ENODATA. audioreach_get_sp_vi_t0() converts that failure to 0 without returning an error, and audioreach_vi_calibration_event() then stores t0_cali_q6 =3D 0 (0 degC) in sp_vi_r0t0_cfg, introducing roughly a 25 degC offset error into the DSP thermal protection model on subsequent playbacks. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204113101.1141= 644-1-srinivas.kandagatla@oss.qualcomm.com?part=3D21