Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Srinivas Kandagatla" <srinivas.kandagatla@oss.qualcomm.com>
Cc: linux-sound@vger.kernel.org, devicetree@vger.kernel.org,
	robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v5 21/24] ASoC: qcom: x1e80100: register WSA speaker thermal zones for speaker protection
Date: Fri, 04 Dec 2026 14:16:32 +0000	[thread overview]
Message-ID: <sashiko-outbox-249948@kernel.org> (raw)
In-Reply-To: <20261204113101.1141644-22-srinivas.kandagatla@oss.qualcomm.com>

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
  == 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 <srinivas.kandagatla@oss.qualcomm.com>

> ASoC: qcom: x1e80100: register WSA speaker thermal zones for speaker protection
>
> 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 <srinivas.kandagatla@oss.qualcomm.com>

[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/audioreach.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 = SP_VI_CALI_RUNNING;
>  		sp_vi_r0.num_ch = 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 = 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 == 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 = 0, discarding any valid cached R0/T0 data.  The
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;
>  
> -	/* Back to Normal before anything else, so a racing trigger is clean */
> -	audioreach_sp_finish_calibration();
> -
>  	guard(mutex)(&sp_vi_r0_lock);
>  
>  	if (!sp_vi_r0.armed)
> @@ -1838,14 +1834,17 @@ void audioreach_vi_calibration_abort(struct device *dev)
>  	}
>  
>  	dev_info(dev, "VI calibration aborted: graph stopped before the DSP finished\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: audioreach:
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 watchdog
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, mode);
> +	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_VI.
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 = 0
(0 degC) in sp_vi_r0t0_cfg, introducing roughly a 25 degC offset error into
the DSP thermal protection model on subsequent playbacks.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204113101.1141644-1-srinivas.kandagatla@oss.qualcomm.com?part=21

  reply	other threads:[~2026-12-04 14:16 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 11:30 [PATCH v5 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
2026-12-04 11:30 ` [PATCH v5 01/24] ASoC: soc-core: bump MAX_DEFAULT_CH_MAP_SIZE to 18 Srinivas Kandagatla
2026-12-04 11:30 ` [PATCH v5 02/24] ASoC: soc-pcm: add multi_direction_codecs link flag Srinivas Kandagatla
2026-12-04 12:01   ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 03/24] ASoC: soc-dai: export snd_soc_dai_stream_valid Srinivas Kandagatla
2026-12-04 11:30 ` [PATCH v5 04/24] ASoC: qcom: sdw: add per-direction stream runtimes for multi_direction links Srinivas Kandagatla
2026-12-04 12:12   ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 05/24] ASoC: dt-bindings: qcom,wsa8840: allow one sound DAI cell Srinivas Kandagatla
2026-12-04 11:30 ` [PATCH v5 06/24] ASoC: codecs: wsa884x: add VI sense capture DAI Srinivas Kandagatla
2026-12-04 12:38   ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 07/24] ASoC: codecs: wsa883x: " Srinivas Kandagatla
2026-12-04 12:33   ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 08/24] ASoC: codecs: wsa884x: register the die temperature as a thermal zone Srinivas Kandagatla
2026-12-04 13:34   ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 09/24] ASoC: qcom: audioreach: add control link support to graphs Srinivas Kandagatla
2026-12-04 13:35   ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 10/24] ASoC: qcom: audioreach: run VI module in calibration mode with per-speaker events Srinivas Kandagatla
2026-12-04 13:32   ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 11/24] ASoC: qcom: q6apm-dai: add S32_LE format support Srinivas Kandagatla
2026-12-04 11:30 ` [PATCH v5 12/24] ASoC: qcom: audioreach: cache VI calibration results per speaker Srinivas Kandagatla
2026-12-04 13:32   ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 13/24] ASoC: qcom: audioreach: add speaker protection calibration trigger infrastructure Srinivas Kandagatla
2026-12-04 13:25   ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 14/24] ASoC: qcom: audioreach: send cached R0/T0 to the VI module in normal mode Srinivas Kandagatla
2026-12-04 13:43   ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 15/24] ASoC: qcom: audioreach: send static cfg blobs to speaker protection modules Srinivas Kandagatla
2026-12-04 13:50   ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 16/24] ASoC: qcom: audioreach: add speaker protection mixer controls Srinivas Kandagatla
2026-12-04 14:01   ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 17/24] ASoC: qcom: audioreach: pin SPEAKER_PROTECTION_VI media format Srinivas Kandagatla
2026-12-04 13:56   ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 18/24] ASoC: qcom: audioreach: add live speaker temperature (T0) readback Srinivas Kandagatla
2026-12-04 14:04   ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 19/24] ASoC: qcom: audioreach: add speaker protection calibration state control Srinivas Kandagatla
2026-12-04 13:59   ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 20/24] ASoC: qcom: x1e80100: carry WSA VI feedback on the WSA Playback BE link Srinivas Kandagatla
2026-12-04 14:11   ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 21/24] ASoC: qcom: x1e80100: register WSA speaker thermal zones for speaker protection Srinivas Kandagatla
2026-12-04 14:16   ` sashiko-bot [this message]
2026-12-04 11:30 ` [PATCH v5 22/24] arm64: dts: qcom: glymur-crd: add WSA speaker protection VI feedback Srinivas Kandagatla
2026-12-04 14:18   ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 23/24] arm64: dts: qcom: mahua-t14s: " Srinivas Kandagatla
2026-12-04 14:16   ` sashiko-bot
2026-12-04 11:31 ` [PATCH v5 24/24] arm64: dts: qcom: x1e78100-t14s: " Srinivas Kandagatla
2026-12-04 14:24   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-249948@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=srinivas.kandagatla@oss.qualcomm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox