Linux Sound subsystem development
 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 v4 19/24] ASoC: qcom: audioreach: add speaker protection calibration state control
Date: Tue, 01 Dec 2026 13:27:26 +0000	[thread overview]
Message-ID: <sashiko-outbox-243396@kernel.org> (raw)
In-Reply-To: <20261201124753.196748-20-srinivas.kandagatla@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 6 potential
issues to consider:
- [Medium] ASoC: qcom: audioreach: early return in
  audioreach_vi_calibration_abort()
- [Medium] ASoC: qcom: audioreach: uncancelled sp_cal_watchdog work on
  module removal
- [Medium] ASoC: qcom: audioreach: unsynchronized sp_operation_mode
  reads across sleep
- [Low] ASoC: qcom: mode reset before cancel in
  audioreach_sp_finish_calibration()
- [Low] ASoC: qcom: audioreach: commit message omits calibrate control
  and abort logic
- [Low] ASoC: qcom: audioreach: stale last_state in
  audioreach_vi_calibration_event()
--

commit 697d5e439356354d15a2690401fd91d27d7875e4
Author: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>

> ASoC: qcom: audioreach: add speaker protection calibration state control
>
> Add a read-only "Speaker Protection Calibration State" control with
> each speaker's last calibration state, so userspace can follow a run.
>
> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>

[Severity: Low]
This isn't a bug, but the commit title and message only describe the
"Speaker Protection Calibration State" control and do not mention adding
the "Speaker Protection Calibrate" trigger control or the VI calibration
abort handling on graph stop and close.

> diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c
> index 3974191f9c536..cf30c18fa25ff 100644
> --- a/sound/soc/qcom/qdsp6/audioreach.c
> +++ b/sound/soc/qcom/qdsp6/audioreach.c

[ ... ]

> @@ -1718,6 +1736,8 @@ void audioreach_vi_calibration_event(struct device *dev,
>  	for (i = 0; i < num_ch; i++) {
>  		u32 state = cali->cali_param[i].state;
>  
> +		sp_vi_r0.last_state[i] = state;
> +
>  		if (sp_vi_cali_state_is_failure(state))
>  			success = false;
>  		else if (!sp_vi_cali_state_is_terminal(state))

[Severity: Low]
Does audioreach_vi_calibration_event() leave stale entries in
sp_vi_r0.last_state[] when a new run has fewer channels than a previous
run?

When the first event of a run arrives, audioreach_vi_calibration_event()
clears sp_vi_r0.r0_cali_q24, but not sp_vi_r0.last_state.  The loop above
only updates slots 0 .. num_ch - 1, while audioreach_get_sp_vi_cal_state()
copies all MAX_SP_VI_SPEAKERS entries to userspace.  Zeroing
sp_vi_r0.last_state alongside sp_vi_r0.r0_cali_q24 on the first event would
avoid reporting stale states for unused speaker slots.

> @@ -1780,6 +1800,46 @@ void audioreach_vi_calibration_event(struct device *dev,
>  	audioreach_sp_finish_calibration();
>  }
>  
> +/* A run cut short never reports a final state, close it out */
> +void audioreach_vi_calibration_abort(struct device *dev)
> +{
> +	unsigned int i;
> +
> +	guard(mutex)(&sp_vi_r0_lock);
> +
> +	if (!sp_vi_r0.armed)
> +		return;
> +
> +	sp_vi_r0.armed = false;
> +
> +	/* The DSP never reported on this run: keep the previous result */
> +	if (!memchr_inv(sp_vi_r0.seen_states, 0, sizeof(sp_vi_r0.seen_states)))
> +		return;

[Severity: Medium]
Does returning here before audioreach_sp_finish_calibration() leave
sp_operation_mode stuck in PARAM_ID_SP_VI_OP_MODE_CALIBRATION when a run is
aborted before the first DSP event arrives?

When a graph is closed without ever starting (such as on a prepare failure
covered by q6apm_graph_close()) or stopped before the DSP sends its first
calibration event, sp_vi_r0.seen_states is all zeros.  Returning early
skips audioreach_sp_finish_calibration(), leaving sp_operation_mode in
Calibration mode and sp_cal_watchdog pending for up to 60 seconds.  During
that window, retrying "Speaker Protection Calibrate" fails with -EBUSY, and
any normal playback configures the DSP in Calibration mode without normal
R0/T0 thermal protection.

Calling audioreach_sp_finish_calibration() before the seen_states check
would reset the mode and cancel the watchdog while still keeping the
previous calibration result.

> diff --git a/sound/soc/qcom/qdsp6/topology.c b/sound/soc/qcom/qdsp6/topology.c
> index a8fdd73cdecdd..16327961d6c1b 100644
> --- a/sound/soc/qcom/qdsp6/topology.c
> +++ b/sound/soc/qcom/qdsp6/topology.c
> @@ -1548,6 +1548,45 @@ static int audioreach_get_sp_t0(struct snd_kcontrol *kcontrol,

[ ... ]

> +static int audioreach_put_sp_calibrate(struct snd_kcontrol *kcontrol,
> +				       struct snd_ctl_elem_value *ucontrol)
> +{
> +	if (!ucontrol->value.integer.value[0])
> +		return 0;
> +
> +	return audioreach_trigger_sp_calibration() ? : 1;
> +}

[Severity: Medium]
Can sp_cal_watchdog fire after snd-q6apm is unloaded?

Exposing audioreach_trigger_sp_calibration() through this control lets
userspace schedule the 60-second sp_cal_watchdog delayed work, but
apm_remove() does not call cancel_delayed_work_sync(&sp_cal_watchdog) on
driver teardown (and audioreach_sp_finish_calibration() only uses
cancel_delayed_work()).  Unbinding and unloading snd-q6apm while the
watchdog is pending or running will execute audioreach_sp_cal_watchdog_fn()
in unmapped module memory.

[Severity: Low]
Can audioreach_sp_finish_calibration() cancel the watchdog of a newly
triggered calibration run or race with an in-flight watchdog callback?

sound/soc/qcom/qdsp6/audioreach.c:audioreach_sp_finish_calibration() {
	WRITE_ONCE(sp_operation_mode, PARAM_ID_SP_VI_OP_MODE_NORMAL);
	cancel_delayed_work(&sp_cal_watchdog);
}

Because sp_operation_mode is reset to NORMAL before cancel_delayed_work(),
a concurrent audioreach_put_sp_calibrate() can race as follows:

CPU0                                  CPU1
audioreach_vi_calibration_abort()
  audioreach_sp_finish_calibration()
    WRITE_ONCE(sp_operation_mode,
               ..._NORMAL)
                                      audioreach_put_sp_calibrate()
                                        audioreach_trigger_sp_calibration()
                                          cmpxchg(&sp_operation_mode,
                                                  ..._NORMAL,
                                                  ..._CALIBRATION)
                                          schedule_delayed_work(
                                            &sp_cal_watchdog, ...)
    cancel_delayed_work(&sp_cal_watchdog)
      <-- cancels new run's watchdog

In addition, because cancel_delayed_work() does not wait for an executing
audioreach_sp_cal_watchdog_fn(), an in-flight watchdog from the old run can
cmpxchg sp_operation_mode back to NORMAL after CPU1 has armed the new run.

[Severity: Medium]
Can a concurrent sp_operation_mode change while graph setup sleeps leave
the DSP speaker protection modules inconsistently configured?

audioreach_put_sp_calibrate(), audioreach_vi_calibration_abort() and
audioreach_sp_cal_watchdog_fn() update sp_operation_mode without
serializing against graph preparation:

sound/soc/qcom/qdsp6/audioreach.c:audioreach_speaker_protection_vi() {
	u32 mode = READ_ONCE(sp_operation_mode);
    ...
	op_cfg->cfg.operation_mode = mode;
    ...
	rc = q6apm_send_cmd_sync(graph->apm, pkt, 0);
    ...
	if (sp_operation_mode == PARAM_ID_SP_VI_OP_MODE_NORMAL) {

audioreach_speaker_protection_vi() snapshots sp_operation_mode into mode to
register events and send PARAM_ID_SP_VI_OP_MODE_CFG, then sleeps in
q6apm_send_cmd_sync(), and re-reads sp_operation_mode afterward.  If
audioreach_put_sp_calibrate() switches sp_operation_mode from NORMAL to
CALIBRATION during that sleep, the VI module is placed in NORMAL mode
without calibration events registered, but the second check sees
CALIBRATION and skips sending PARAM_ID_SP_TH_VI_R0T0_CFG.  Likewise,
audioreach_speaker_protection() and audioreach_speaker_protection_vi() read
sp_operation_mode independently across sleeping GPR commands, so the two
modules can be configured for different modes on the same graph.

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

  reply	other threads:[~2026-12-01 13:27 UTC|newest]

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