From: Vladimir Bely <vlwwwwww@gmail.com>
To: Srinivas Kandagatla <srini@kernel.org>,
Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>
Cc: Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
linux-sound@vger.kernel.org, linux-arm-msm@vger.kernel.org,
linux-kernel@vger.kernel.org, Vladimir Bely <vlwwwwww@gmail.com>,
stable@vger.kernel.org
Subject: [PATCH v3 1/2] ASoC: qcom: q6asm: don't advance dsp_buf on failed write or read
Date: Sun, 29 Nov 2026 12:20:27 +0300 [thread overview]
Message-ID: <20261129092028.239529-2-vlwwwwww@gmail.com> (raw)
In-Reply-To: <20261129011802.1025539-1-vlwwwwww@gmail.com>
q6asm_write_async() and q6asm_read() increment port->dsp_buf under
ac->lock and release the lock before calling apr_send_pkt(). If
apr_send_pkt() fails (for example with -EAGAIN when the SMD FIFO is full
during a playback write burst on MSM8916), dsp_buf has already moved on
even though the DSP never received that buffer. Subsequent writes then
send out-of-sequence period addresses and tokens, and any retry skips the
failed period.
Hold ac->lock across apr_send_pkt() (which is atomic and non-blocking via
rpmsg_trysend()) and only advance port->dsp_buf when the packet was
actually accepted. Also clear port->buf and port->dsp_buf under ac->lock
in q6asm_audio_client_free_buf() (freeing the saved pointer after unlock)
and reject q6asm_write_async()/q6asm_read() with -EINVAL when !port->buf
or !port->num_periods, preventing races with concurrent unmap.
Fixes: 68fd8480bb7b ("ASoC: qdsp6: q6asm: Add support to audio stream apis")
Fixes: fdbb53d318aa ("ASoC: qdsp6: q6asm: do not sleep while atomic")
Cc: stable@vger.kernel.org
Signed-off-by: Vladimir Bely <vlwwwwww@gmail.com>
---
Changes in v3:
- Fix Fixes: trailer subject for 68fd8480bb7b and add Fixes: fdbb53d318aa
(reported by Sashiko AI review).
Changes in v2:
- Clear port->buf and port->dsp_buf under ac->lock in
q6asm_audio_client_free_buf() and reject q6asm_write_async()/q6asm_read()
when !port->buf or !port->num_periods.
sound/soc/qcom/qdsp6/q6asm.c | 44 ++++++++++++++++++++++--------------
1 file changed, 27 insertions(+), 17 deletions(-)
diff --git a/sound/soc/qcom/qdsp6/q6asm.c b/sound/soc/qcom/qdsp6/q6asm.c
index ee1930e41..54408fd64 100644
--- a/sound/soc/qcom/qdsp6/q6asm.c
+++ b/sound/soc/qcom/qdsp6/q6asm.c
@@ -427,13 +427,16 @@ static int __q6asm_memory_unmap(struct audio_client *ac,
static void q6asm_audio_client_free_buf(struct audio_client *ac,
struct audio_port_data *port)
{
+ struct audio_buffer *buf;
unsigned long flags;
spin_lock_irqsave(&ac->lock, flags);
port->num_periods = 0;
- spin_unlock_irqrestore(&ac->lock, flags);
- kfree(port->buf);
+ port->dsp_buf = 0;
+ buf = port->buf;
port->buf = NULL;
+ spin_unlock_irqrestore(&ac->lock, flags);
+ kfree(buf);
}
/**
@@ -1541,6 +1544,10 @@ int q6asm_read(struct audio_client *ac, uint32_t stream_id)
spin_lock_irqsave(&ac->lock, flags);
port = &ac->port[SNDRV_PCM_STREAM_CAPTURE];
+ if (!port->buf || !port->num_periods) {
+ spin_unlock_irqrestore(&ac->lock, flags);
+ return -EINVAL;
+ }
q6asm_add_hdr(ac, &pkt->hdr, pkt_size, false, stream_id);
ab = &port->buf[port->dsp_buf];
pkt->hdr.opcode = ASM_DATA_CMD_READ_V2;
@@ -1552,16 +1559,16 @@ int q6asm_read(struct audio_client *ac, uint32_t stream_id)
read->seq_id = port->dsp_buf;
pkt->hdr.token = port->dsp_buf;
- port->dsp_buf++;
-
- if (port->dsp_buf >= port->num_periods)
- port->dsp_buf = 0;
-
- spin_unlock_irqrestore(&ac->lock, flags);
rc = apr_send_pkt(ac->adev, pkt);
- if (rc == pkt_size)
+ if (rc == pkt_size) {
rc = 0;
- else
+ port->dsp_buf++;
+ if (port->dsp_buf >= port->num_periods)
+ port->dsp_buf = 0;
+ }
+ spin_unlock_irqrestore(&ac->lock, flags);
+
+ if (rc)
pr_err("read op[0x%x]rc[%d]\n", pkt->hdr.opcode, rc);
return rc;
@@ -1657,6 +1664,10 @@ int q6asm_write_async(struct audio_client *ac, uint32_t stream_id, uint32_t len,
spin_lock_irqsave(&ac->lock, flags);
port = &ac->port[SNDRV_PCM_STREAM_PLAYBACK];
+ if (!port->buf || !port->num_periods) {
+ spin_unlock_irqrestore(&ac->lock, flags);
+ return -EINVAL;
+ }
q6asm_add_hdr(ac, &pkt->hdr, pkt_size, false, stream_id);
ab = &port->buf[port->dsp_buf];
@@ -1673,15 +1684,14 @@ int q6asm_write_async(struct audio_client *ac, uint32_t stream_id, uint32_t len,
write->flags = wflags;
- port->dsp_buf++;
-
- if (port->dsp_buf >= port->num_periods)
- port->dsp_buf = 0;
-
- spin_unlock_irqrestore(&ac->lock, flags);
rc = apr_send_pkt(ac->adev, pkt);
- if (rc == pkt_size)
+ if (rc == pkt_size) {
rc = 0;
+ port->dsp_buf++;
+ if (port->dsp_buf >= port->num_periods)
+ port->dsp_buf = 0;
+ }
+ spin_unlock_irqrestore(&ac->lock, flags);
return rc;
}
--
2.43.0
next prev parent reply other threads:[~2026-11-29 9:20 UTC|newest]
Thread overview: 9+ 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 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 ` Vladimir Bely [this message]
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:18 ` [PATCH v2 2/2] ASoC: qcom: q6asm-dai: retry playback queuing on -EAGAIN Vladimir Bely
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=20261129092028.239529-2-vlwwwwww@gmail.com \
--to=vlwwwwww@gmail.com \
--cc=broonie@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--cc=srini@kernel.org \
--cc=stable@vger.kernel.org \
--cc=tiwai@suse.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
all inboxes | Powered by JetHome®