All of lore.kernel.org
 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 v3 19/24] ASoC: qcom: audioreach: add speaker protection calibration state control
Date: Mon, 30 Nov 2026 21:47:27 +0000	[thread overview]
Message-ID: <sashiko-outbox-242043@kernel.org> (raw)
In-Reply-To: <20261130212258.7376-20-srinivas.kandagatla@oss.qualcomm.com>

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

commit c58591aa133913ac270206bd175386cd596ee808
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 message only mentions the read-only
"Speaker Protection Calibration State" control while the patch also adds
the "Speaker Protection Calibrate" trigger control and 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 789f9fc3c9795..0a6c881f5cd46 100644
> --- a/sound/soc/qcom/qdsp6/audioreach.c
> +++ b/sound/soc/qcom/qdsp6/audioreach.c
[ ... ]
> @@ -1806,6 +1826,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 calling audioreach_sp_finish_calibration()
leave sp_operation_mode stuck in PARAM_ID_SP_VI_OP_MODE_CALIBRATION when
a graph is closed or stopped before the first DSP event arrives?

When q6apm_graph_close() aborts an armed graph that was never started
(or q6apm_graph_stop() runs before any EVENT_ID_VI_PER_SPKR_CALIBRATION
event is received), sp_vi_r0.seen_states is still all zeros.  Returning
after clearing sp_vi_r0.armed skips audioreach_sp_finish_calibration(),
so sp_operation_mode remains in calibration mode until the 60-second
sp_cal_watchdog expires: retries of "Speaker Protection Calibrate" fail
with -EBUSY, and any normal playback started in the meantime configures
the DSP in calibration mode without sending PARAM_ID_SP_TH_VI_R0T0_CFG.

Calling audioreach_sp_finish_calibration() before returning when
seen_states is all zeros avoids leaving calibration mode active.

> +
> +	sp_vi_r0.state = SP_VI_CALI_ABORTED;
> +
> +	for (i = 0; i < MAX_SP_VI_SPEAKERS; i++) {
> +		u32 state = sp_vi_r0.last_state[i];
> +
> +		/* Slot never reported: not part of this run */
> +		if (!sp_vi_r0.seen_states[i])
> +			continue;
> +
> +		if (sp_vi_cali_state_is_terminal(state))
> +			continue;
> +
> +		dev_info(dev, "VI calibration channel %u: aborted while %s\n",
> +			 i, sp_vi_cali_state_name(state));
> +		sp_vi_r0.last_state[i] = VI_CALIBRATION_STATE_INACTIVE;
> +	}
> +
> +	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: Low]
Can audioreach_sp_finish_calibration() cancel the watchdog of a newly
triggered calibration run if userspace writes to "Speaker Protection
Calibrate" concurrently?

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()
runs, a concurrent audioreach_put_sp_calibrate() call can pass the
cmpxchg() in audioreach_trigger_sp_calibration() and schedule
sp_cal_watchdog, only for the finishing context to cancel it:

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

Also, because cancel_delayed_work() does not wait for an in-flight
audioreach_sp_cal_watchdog_fn() callback, an expiring watchdog from the
previous run can execute its cmpxchg() right after CPU1 re-arms
sp_operation_mode and reset the new run back to NORMAL.

> diff --git a/sound/soc/qcom/qdsp6/topology.c b/sound/soc/qcom/qdsp6/topology.c
> index 0e28c68c735d2..a19efbb889a8e 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 toggling sp_operation_mode from userspace while
q6apm_graph_media_format_pcm() is sleeping in synchronous GPR commands
configure the speaker protection modules inconsistently?

In audioreach_speaker_protection_vi(), sp_operation_mode is snapshotted
into mode at function entry, but re-read from the global variable after
q6apm_send_cmd_sync() sleeps:

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) {
		...
}

If audioreach_put_sp_calibrate() flips sp_operation_mode from NORMAL to
CALIBRATION while q6apm_send_cmd_sync() is waiting, the DSP receives
NORMAL in PARAM_ID_SP_VI_OP_MODE_CFG (without calibration events
registered), while the post-sleep check sees CALIBRATION and skips
sending PARAM_ID_SP_TH_VI_R0T0_CFG.  Similarly, because
q6apm_graph_media_format_pcm() calls audioreach_speaker_protection() and
audioreach_speaker_protection_vi() across sleeping GPR commands without
a shared mode snapshot, MODULE_ID_SPEAKER_PROTECTION and
MODULE_ID_SPEAKER_PROTECTION_VI can be configured in different modes for
the same graph.

> @@ -1557,6 +1596,30 @@ static const struct snd_kcontrol_new audioreach_sp_telemetry_controls[] = {
[ ... ]
> +	{
> +		/*
> +		 * Write-only edge trigger.  Writing 1 arms a calibration run
> +		 * for the next (or current) WSA playback graph; the mode
> +		 * returns to Normal on its own once the DSP reports terminal
> +		 * state, on graph abort, or on the watchdog timeout.
> +		 */
> +		.iface	= SNDRV_CTL_ELEM_IFACE_MIXER,
> +		.name	= "Speaker Protection Calibrate",
> +		.access	= SNDRV_CTL_ELEM_ACCESS_READWRITE |
> +			  SNDRV_CTL_ELEM_ACCESS_VOLATILE,
> +		.info	= audioreach_info_sp_calibrate,
> +		.get	= audioreach_get_sp_calibrate,
> +		.put	= audioreach_put_sp_calibrate,
> +	},
>  };

[Severity: Medium]
Can unloading snd-q6apm after arming "Speaker Protection Calibrate"
cause a use-after-free when sp_cal_watchdog fires?

Writing 1 to this control schedules the static 60-second sp_cal_watchdog
delayed work in audioreach_trigger_sp_calibration(), but neither
apm_remove() nor module teardown calls
cancel_delayed_work_sync(&sp_cal_watchdog).  If snd-q6apm is unloaded
while the watchdog timer is still pending or its work callback is in
flight, audioreach_sp_cal_watchdog_fn() will execute after the module
text and data have been unmapped.

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

  reply	other threads:[~2026-11-30 21:47 UTC|newest]

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

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-242043@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.