From: sashiko-bot@kernel.org
To: "Vladimir Bely" <vlwwwwww@gmail.com>
Cc: linux-sound@vger.kernel.org
Subject: Re: [PATCH v2 2/2] ASoC: qcom: q6asm-dai: retry playback queuing on -EAGAIN
Date: Sun, 29 Nov 2026 01:31:50 +0000 [thread overview]
Message-ID: <sashiko-outbox-239205@kernel.org> (raw)
In-Reply-To: <20261129011802.1025539-3-vlwwwwww@gmail.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] ASoC: qcom: q6asm-dai: full SMD FIFO in q6asm_dai_ack() breaks
trigger start
- [Low] ASoC: qcom: q6asm-dai: redundant stream lock cycle in
event_handler()
- [Low] ASoC: qcom: q6asm-dai: wrong commit subject in Fixes trailer
--
commit 2a93925c1ef34ca2638692fd522578e41fe20e98
Author: Vladimir Bely <vlwwwwww@gmail.com>
> ASoC: qcom: q6asm-dai: retry playback queuing on -EAGAIN
>
> q6asm_dai_ack() sends one ASM_DATA_CMD_WRITE_V2 APR packet per available
> period in a tight loop. On SoCs with a small SMD FIFO (such as MSM8916),
> an initial playback write burst or a buffer with many periods can fill the
> FIFO, making rpmsg_trysend() return -EAGAIN. q6asm_dai_ack() currently
> aborts and propagates -EAGAIN to ALSA, causing userspace writes to fail
> and playback to stall.
>
> Move playback period queuing into a helper q6asm_dai_queue_playback()
> called with the PCM stream lock held. Handle appl_ptr wrap around
> runtime->boundary, guard against appl_ptr moving behind queue_ptr (e.g.
> on SNDRV_PCM_IOCTL_RESET or appl_ptr rollback) by requiring
> avail <= runtime->buffer_size, and stop cleanly on -EAGAIN without
> returning an error. Retry from event_handler() on
> ASM_CLIENT_EVENT_DATA_WRITE_DONE under pcm_stream_lock_irqsave only when
> snd_pcm_running(substream) is true, so queuing stays serialized with ack,
> stop, XRUN, prepare, and close.
>
> Fixes: e386c2cf3df2 ("ASoC: qdsp6: q6asm: Add q6asm dai driver")
> Cc: stable@vger.kernel.org
> Signed-off-by: Vladimir Bely <vlwwwwww@gmail.com>
[Severity: Low]
The subject in the Fixes: tag belongs to commit 2a9e92d371db ("ASoC:
qdsp6: q6asm: Add q6asm dai driver"). Should this be:
Fixes: e386c2cf3df2 ("ASoC: qcom: q6asm-dai: schedule all available frames to avoid dsp under-runs")
> diff --git a/sound/soc/qcom/qdsp6/q6asm-dai.c b/sound/soc/qcom/qdsp6/q6asm-dai.c
> index 57cbce2bb0cb7..b2856e7a28e0d 100644
> --- a/sound/soc/qcom/qdsp6/q6asm-dai.c
> +++ b/sound/soc/qcom/qdsp6/q6asm-dai.c
> @@ -179,6 +179,40 @@ static const struct snd_compr_codec_caps q6asm_compr_caps = {
> .descriptor[0].formats = 0,
> };
>
> +/*
> + * Queue the periods the application has written so far. Each period is one
> + * APR packet sent with rpmsg_trysend(), and a burst can fill the small SMD
> + * FIFO (-EAGAIN). That is not an error: stop and retry when the DSP hands a
> + * buffer back (DATA_WRITE_DONE). Caller must hold the PCM stream lock.
> + */
> +static int q6asm_dai_queue_playback(struct q6asm_dai_rtd *prtd)
> +{
> + struct snd_pcm_runtime *runtime = prtd->substream->runtime;
> + int ret;
> +
> + while (prtd->state == Q6ASM_STREAM_RUNNING) {
> + snd_pcm_sframes_t avail = runtime->control->appl_ptr - prtd->queue_ptr;
> +
> + if (avail < 0)
> + avail += runtime->boundary;
> + if (avail < runtime->period_size || avail > runtime->buffer_size)
> + break;
> +
> + ret = q6asm_write_async(prtd->audio_client, prtd->stream_id,
> + prtd->pcm_count, 0, 0, 0);
> + if (ret == -EAGAIN)
> + break;
> + if (ret < 0)
> + return ret;
> +
> + prtd->queue_ptr += runtime->period_size;
> + if (prtd->queue_ptr >= runtime->boundary)
> + prtd->queue_ptr -= runtime->boundary;
> + }
> +
> + return 0;
> +}
[Severity: High]
Can filling the SMD FIFO in q6asm_dai_queue_playback() cause the
subsequent SNDRV_PCM_TRIGGER_START to fail with -EAGAIN?
q6asm_dai_prepare() sets prtd->state = Q6ASM_STREAM_RUNNING while
runtime->state is still SNDRV_PCM_STATE_PREPARED. When an initial write
burst in __snd_pcm_lib_xfer() reaches runtime->start_threshold,
pcm_lib_apply_appl_ptr() calls q6asm_dai_ack() ->
q6asm_dai_queue_playback() before calling snd_pcm_start():
sound/core/pcm_lib.c:__snd_pcm_lib_xfer() {
...
err = pcm_lib_apply_appl_ptr(substream, appl_ptr);
if (err < 0)
goto _end_unlock;
...
if (is_playback &&
runtime->state == SNDRV_PCM_STATE_PREPARED &&
snd_pcm_playback_hw_avail(runtime) >= (snd_pcm_sframes_t)runtime->start_threshold) {
err = snd_pcm_start(substream);
if (err < 0)
goto _end_unlock;
}
...
}
If q6asm_dai_queue_playback() fills the SMD FIFO until q6asm_write_async()
returns -EAGAIN and then returns 0, the immediately following
snd_pcm_start() -> q6asm_dai_trigger(SNDRV_PCM_TRIGGER_START) ->
q6asm_run_nowait() tries to send ASM_SESSION_CMD_RUN_V2 via
rpmsg_trysend() on the same exhausted SMD FIFO and fails with -EAGAIN.
snd_pcm_start() then runs snd_pcm_undo_start() and leaves runtime->state
in SNDRV_PCM_STATE_PREPARED with prtd->queue_ptr and port->dsp_buf already
advanced, while __snd_pcm_lib_xfer() returns the positive xfer count to
userspace. Because the DSP stream never starts (or whenever -EAGAIN is
hit with no buffers in flight on the DSP), ASM_CLIENT_EVENT_DATA_WRITE_DONE
never fires and playback stalls permanently.
> @@ -192,6 +226,15 @@ static void event_handler(uint32_t opcode, uint32_t token,
> break;
> case ASM_CLIENT_EVENT_DATA_WRITE_DONE:
> snd_pcm_period_elapsed(substream);
> + /* Push any periods left behind by a full SMD FIFO */
> + if (substream) {
> + scoped_guard(pcm_stream_lock_irqsave, substream) {
> + if (substream->runtime &&
> + snd_pcm_running(substream) &&
> + q6asm_dai_queue_playback(prtd) < 0)
> + pr_err_ratelimited("q6asm-dai: Error queuing playback buffer\n");
> + }
> + }
> break;
[Severity: Low]
snd_pcm_period_elapsed() already takes and releases
pcm_stream_lock_irqsave(substream) around
snd_pcm_period_elapsed_under_stream_lock(). Calling
snd_pcm_period_elapsed_under_stream_lock(substream) and
q6asm_dai_queue_playback(prtd) under a single
scoped_guard(pcm_stream_lock_irqsave, substream) (as q6apm-dai does) would
avoid taking the stream lock twice on every period and queue pending
periods before releasing the lock to woken userspace writers.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261129011802.1025539-1-vlwwwwww@gmail.com?part=2
prev parent reply other threads:[~2026-11-29 1:31 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 0:19 [PATCH 0/2] ASoC: qcom: qdsp6: handle SMD FIFO -EAGAIN in q6asm playback Vladimir Bely
2026-11-29 0:19 ` [PATCH 1/2] ASoC: qcom: q6asm: don't advance dsp_buf on failed write or read Vladimir Bely
2026-11-29 0:19 ` [PATCH 2/2] ASoC: qcom: q6asm-dai: retry playback queuing on -EAGAIN Vladimir Bely
2026-11-29 0:34 ` sashiko-bot
2026-11-29 1:18 ` [PATCH v2 0/2] ASoC: qcom: qdsp6: handle SMD FIFO -EAGAIN in q6asm playback Vladimir Bely
2026-11-29 9:20 ` [PATCH v3 " Vladimir Bely
2026-11-29 9:20 ` [PATCH v3 1/2] ASoC: qcom: q6asm: don't advance dsp_buf on failed write or read Vladimir Bely
2026-11-29 9:20 ` [PATCH v3 2/2] ASoC: qcom: q6asm-dai: retry playback queuing on -EAGAIN Vladimir Bely
2026-11-29 1:18 ` [PATCH v2 1/2] ASoC: qcom: q6asm: don't advance dsp_buf on failed write or read Vladimir Bely
2026-11-29 1:23 ` sashiko-bot
2026-11-29 1:18 ` [PATCH v2 2/2] ASoC: qcom: q6asm-dai: retry playback queuing on -EAGAIN Vladimir Bely
2026-11-29 1:31 ` sashiko-bot [this message]
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-239205@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=vlwwwwww@gmail.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