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 13/24] ASoC: qcom: audioreach: add speaker protection calibration trigger infrastructure
Date: Tue, 01 Dec 2026 13:12:31 +0000 [thread overview]
Message-ID: <sashiko-outbox-243352@kernel.org> (raw)
In-Reply-To: <20261201124753.196748-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 1f0f3a4d2d0ba4e2a629bbda935112fa18551e13
Author: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
ASoC: qcom: audioreach: add speaker protection calibration trigger infrastructure
This commit introduces an internal speaker protection operation mode state
with an edge-triggered calibration helper and a 60-second watchdog timer to
return the mode to Normal.
> diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c
> index c48ba63448dbd..dd0b70013a0ec 100644
> --- a/sound/soc/qcom/qdsp6/audioreach.c
> +++ b/sound/soc/qcom/qdsp6/audioreach.c
[ ... ]
> @@ -1456,6 +1459,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 a concurrent audioreach_trigger_sp_calibration() race with
audioreach_sp_finish_calibration() and end up with no watchdog armed?
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 CPU1's watchdog
Because sp_operation_mode is reset to PARAM_ID_SP_VI_OP_MODE_NORMAL before
cancel_delayed_work(&sp_cal_watchdog), CPU1 can re-enter calibration mode
while the previous delayed work is still pending or about to be cancelled.
This leaves sp_operation_mode in PARAM_ID_SP_VI_OP_MODE_CALIBRATION without
a running watchdog timer, so if no playback completes, all future triggers
fail with -EBUSY.
Similarly, because cancel_delayed_work() does not wait for an in-flight
audioreach_sp_cal_watchdog_fn() callback to finish, a callback that already
started for the finishing run can run cmpxchg() after CPU1 triggers a new
run and immediately flip the new run back to Normal.
> +
> +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]
What stops sp_cal_watchdog from firing 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 a module exit path calls
cancel_delayed_work_sync(&sp_cal_watchdog). If calibration is triggered
and snd-q6apm is unloaded during the 60-second window, the timer expires
after the module text and data are freed and executes
audioreach_sp_cal_watchdog_fn() in unmapped memory (use-after-free).
> @@ -1562,14 +1607,16 @@ void audioreach_vi_calibration_event(struct device *dev,
> }
>
> dev_info(dev, "VI calibration complete: %s\n", success ? "success" : "failed");
> +
> + /* Edge-triggered: the mode auto-returns to Normal on terminal state. */
> + audioreach_sp_finish_calibration();
> }
>
> static int audioreach_speaker_protection(struct q6apm_graph *graph,
> - const struct audioreach_module *module,
> - uint32_t operation_mode)
> + const struct audioreach_module *module)
> {
> return audioreach_send_u32_param(graph, module, PARAM_ID_SP_OP_MODE,
> - operation_mode);
> + READ_ONCE(sp_operation_mode));
> }
[Severity: Medium]
Can MODULE_ID_SPEAKER_PROTECTION and MODULE_ID_SPEAKER_PROTECTION_VI be
configured with different operation modes in the same graph?
q6apm_graph_media_format_pcm() configures each module in the graph in turn
and sleeps in q6apm_send_cmd_sync() on every command. Because
audioreach_speaker_protection() and audioreach_speaker_protection_vi() read
sp_operation_mode independently without serialization against
audioreach_trigger_sp_calibration() or audioreach_sp_cal_watchdog_fn(), a
trigger or watchdog timeout between the two calls configures one module in
Normal mode and the other in Calibration mode. If SP is in Normal mode
while VI is in Calibration mode, calibration fails with
VI_CALIBRATION_STATE_INCORRECT_OP_MODE; if SP is in Calibration mode while
VI is in Normal mode, sp_vi_r0 is never armed and calibration events are
not registered, leaving sp_operation_mode stuck in Calibration until the
watchdog expires.
[ ... ]
> @@ -1636,11 +1684,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]
Does sp_vi_r0.armed stay out of sync with sp_operation_mode if the watchdog
fires or if VI setup fails?
When audioreach_sp_cal_watchdog_fn() times out after 60 seconds, it resets
sp_operation_mode to PARAM_ID_SP_VI_OP_MODE_NORMAL without taking
sp_vi_r0_lock to clear sp_vi_r0.armed or update sp_vi_r0.state. If a
calibration playback started near the end of the 60-second window or takes
longer than 60 seconds, the watchdog flips sp_operation_mode back to Normal
while sp_vi_r0.armed remains true; a new audioreach_trigger_sp_calibration()
call can then succeed and later be silently reset to Normal when a terminal
event from the earlier run reaches audioreach_vi_calibration_event() and
calls audioreach_sp_finish_calibration().
In addition, if audioreach_register_events(),
audioreach_alloc_apm_cmd_pkt(), or q6apm_send_cmd_sync() fails in
audioreach_speaker_protection_vi() after audioreach_arm_vi_calibration(),
the error path returns with sp_vi_r0.armed still set to true and
sp_operation_mode left in PARAM_ID_SP_VI_OP_MODE_CALIBRATION.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201124753.196748-1-srinivas.kandagatla@oss.qualcomm.com?part=13
next prev parent reply other threads:[~2026-12-01 13:12 UTC|newest]
Thread overview: 33+ 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 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 [this message]
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 12:47 ` [PATCH v4 19/24] ASoC: qcom: audioreach: add speaker protection calibration state control Srinivas Kandagatla
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 12:47 ` [PATCH v4 22/24] arm64: dts: qcom: glymur-crd: add WSA speaker protection VI feedback Srinivas Kandagatla
2026-12-01 12:47 ` [PATCH v4 23/24] arm64: dts: qcom: mahua-t14s: " Srinivas Kandagatla
2026-12-01 12:47 ` [PATCH v4 24/24] arm64: dts: qcom: x1e78100-t14s: " 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-243352@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