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 13/24] ASoC: qcom: audioreach: add speaker protection calibration trigger infrastructure
Date: Mon, 30 Nov 2026 21:34:55 +0000	[thread overview]
Message-ID: <sashiko-outbox-242007@kernel.org> (raw)
In-Reply-To: <20261130212258.7376-14-srinivas.kandagatla@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] ASoC: qcom: audioreach: missing cancel_delayed_work_sync() on
  module unload
- [Medium] ASoC: qcom: audioreach: watchdog race in
  audioreach_sp_finish_calibration()
- [Medium] ASoC: qcom: audioreach: desynchronized calibration state on
  timeout or error
- [Medium] ASoC: qcom: audioreach: split sp_operation_mode read across
  SP and VI modules
--

commit be3dacbf17b1806a48e11abe0048fb2d600d3603
Author: Ravi Hothi <ravi.hothi@oss.qualcomm.com>

ASoC: qcom: audioreach: add speaker protection calibration trigger infrastructure

This commit adds internal speaker protection operation mode state, an
edge-triggered calibration start helper with a 60-second watchdog, and
automatic reset to Normal mode on calibration completion.

> diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c
> index 2b5c083b8ae56..130298a287496 100644
> --- a/sound/soc/qcom/qdsp6/audioreach.c
> +++ b/sound/soc/qcom/qdsp6/audioreach.c
[ ... ]
> @@ -1482,6 +1485,48 @@ static int audioreach_gain_set(struct q6apm_graph *graph,
>  	return q6apm_send_cmd_sync(graph->apm, pkt, 0);
>  }
>  
> +u32 audioreach_get_sp_operation_mode(void)
> +{
> +	return READ_ONCE(sp_operation_mode);
> +}
> +
> +/*
> + * Calibration is edge-triggered rather than a user-visible mode.  Guard
> + * against a trigger write while a run is still in flight, and bound the
> + * armed state with a watchdog so a trigger without a matching playback
> + * does not leave the system in Calibration forever.
> + */
> +#define SP_CAL_WATCHDOG_SECS	60
> +
> +static void audioreach_sp_cal_watchdog_fn(struct work_struct *work);
> +static DECLARE_DELAYED_WORK(sp_cal_watchdog, audioreach_sp_cal_watchdog_fn);
> +
> +static void audioreach_sp_cal_watchdog_fn(struct work_struct *work)
> +{
> +	if (cmpxchg(&sp_operation_mode, PARAM_ID_SP_VI_OP_MODE_CALIBRATION,
> +		    PARAM_ID_SP_VI_OP_MODE_NORMAL) ==
> +	    PARAM_ID_SP_VI_OP_MODE_CALIBRATION)
> +		pr_info("audioreach: SP calibration watchdog fired, back to Normal\n");
> +}
> +
> +static void audioreach_sp_finish_calibration(void)
> +{
> +	WRITE_ONCE(sp_operation_mode, PARAM_ID_SP_VI_OP_MODE_NORMAL);
> +	cancel_delayed_work(&sp_cal_watchdog);
> +}

[Severity: Medium]
Can audioreach_sp_finish_calibration() cancel or abort a newly triggered
calibration run?

Because sp_operation_mode is reset to PARAM_ID_SP_VI_OP_MODE_NORMAL
before cancel_delayed_work(&sp_cal_watchdog), a concurrent
audioreach_trigger_sp_calibration() can re-arm sp_operation_mode in the
window between the two statements:

CPU0                                CPU1
audioreach_sp_finish_calibration()
  WRITE_ONCE(sp_operation_mode,
             ..._NORMAL)
                                    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

If the new run is never followed by playback, sp_operation_mode stays in
PARAM_ID_SP_VI_OP_MODE_CALIBRATION permanently and every future trigger
returns -EBUSY.  Similarly, because cancel_delayed_work() is not
synchronous, an already-dequeued audioreach_sp_cal_watchdog_fn() from
the old run can execute its cmpxchg() after CPU1 re-triggers and flip
the new run back to Normal immediately.

> +
> +int audioreach_trigger_sp_calibration(void)
> +{
> +	if (cmpxchg(&sp_operation_mode, PARAM_ID_SP_VI_OP_MODE_NORMAL,
> +		    PARAM_ID_SP_VI_OP_MODE_CALIBRATION) !=
> +	    PARAM_ID_SP_VI_OP_MODE_NORMAL)
> +		return -EBUSY;
> +
> +	schedule_delayed_work(&sp_cal_watchdog,
> +			      SP_CAL_WATCHDOG_SECS * HZ);
> +	return 0;
> +}

[Severity: High]
Can sp_cal_watchdog remain queued on system_percpu_wq after the
snd-q6apm module is unloaded?

CONFIG_SND_SOC_QDSP6_APM is tristate and builds audioreach.o into
snd-q6apm.ko, but neither apm_remove() nor q6apm_audio_remove() calls
cancel_delayed_work_sync(&sp_cal_watchdog).  Unloading the module while
the 60-second watchdog is pending leaves the timer and work item active
in freed module memory, causing a use-after-free when the timer fires.

[ ... ]

> @@ -1639,6 +1686,7 @@ static int audioreach_speaker_protection_vi(struct q6apm_graph *graph,
>  					    const struct audioreach_module *module,
>  					    const struct audioreach_module_config *mcfg)
>  {
> +	u32 mode = READ_ONCE(sp_operation_mode);
>  	u32 num_channels = mcfg->num_channels;
>  	struct apm_module_sp_vi_op_mode_cfg *op_cfg;
>  	struct apm_module_sp_vi_channel_map_cfg *cm_cfg;
> @@ -1662,11 +1710,13 @@ static int audioreach_speaker_protection_vi(struct q6apm_graph *graph,
>  		return -EINVAL;
>  	}
>  
> -	audioreach_arm_vi_calibration();
> +	if (mode == PARAM_ID_SP_VI_OP_MODE_CALIBRATION) {
> +		audioreach_arm_vi_calibration();
>  
> -	rc = audioreach_register_events(graph, module);
> -	if (rc)
> -		return rc;
> +		rc = audioreach_register_events(graph, module);
> +		if (rc)
> +			return rc;
> +	}

[Severity: Medium]
Can sp_operation_mode and sp_vi_r0.armed get out of sync when the
watchdog fires or when VI module setup fails?

If audioreach_sp_cal_watchdog_fn() fires while a calibration stream is
already armed (for example, playback starts near the end of the
60-second window and runs past it), the watchdog resets
sp_operation_mode to Normal without clearing sp_vi_r0.armed.  A second
audioreach_trigger_sp_calibration() call can then succeed while the
first run is still active on the DSP, and when the first run reaches a
terminal event, audioreach_vi_calibration_event() calls
audioreach_sp_finish_calibration() and silently disarms the second
trigger.

In addition, if audioreach_register_events(),
audioreach_alloc_apm_cmd_pkt(), or q6apm_send_cmd_sync() fails in
audioreach_speaker_protection_vi(), the error path returns with
sp_vi_r0.armed still set to true.

[ ... ]

> @@ -1781,8 +1831,7 @@ int audioreach_set_media_format(struct q6apm_graph *graph,
>  		rc = audioreach_gapless_set_media_format(graph, module, cfg);
>  		break;
>  	case MODULE_ID_SPEAKER_PROTECTION:
> -		rc = audioreach_speaker_protection(graph, module,
> -						   PARAM_ID_SP_OP_MODE_CALIBRATION);
> +		rc = audioreach_speaker_protection(graph, module);
>  		if (!rc)
>  			rc = audioreach_module_enable(graph, module, true);

[Severity: Medium]
Can MODULE_ID_SPEAKER_PROTECTION and MODULE_ID_SPEAKER_PROTECTION_VI be
configured with different operation modes during the same graph setup?

q6apm_graph_media_format_pcm() iterates over the modules in a graph and
sleeps in q6apm_send_cmd_sync() for each one.  Because
audioreach_speaker_protection() and audioreach_speaker_protection_vi()
each do their own unlocked READ_ONCE(sp_operation_mode), a concurrent
audioreach_trigger_sp_calibration() or watchdog timeout between the two
calls configures one module in Normal mode and the other in Calibration
mode.  That either causes the DSP to fail calibration with
VI_CALIBRATION_STATE_INCORRECT_OP_MODE or leaves MODULE_ID_SPEAKER_PROTECTION
in Calibration mode while VI runs in Normal mode without arming
sp_vi_r0.armed or registering calibration events.

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

  reply	other threads:[~2026-11-30 21:34 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 [this message]
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
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-242007@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.