From: Eric Curtin <ericcurtin17@gmail.com>
To: Anton Yakovlev <anton.yakovlev@opensynergy.com>,
"Michael S. Tsirkin" <mst@redhat.com>
Cc: Takashi Iwai <tiwai@suse.de>, Jaroslav Kysela <perex@perex.cz>,
virtualization@lists.linux.dev, linux-sound@vger.kernel.org
Subject: [PATCH] ALSA: virtio: report device xruns from the pointer callbacks
Date: Mon, 30 Nov 2026 12:44:33 +0000 [thread overview]
Message-ID: <20261130124434.474178-1-ericcurtin17@gmail.com> (raw)
The pointer callbacks stopped checking xfer_xrun when the ack callback
was introduced, so an xrun event from the device was never reported.
Return SNDRV_PCM_POS_XRUN when it is set.
Fixes: fe981e67568c ("ALSA: virtio: use ack callback")
Signed-off-by: Eric Curtin <ericcurtin17@gmail.com>
---
Written with LLM assistance; reviewed by me. Not tested with a device that
sends xrun events.
sound/virtio/virtio_pcm_ops.c | 30 ++++++++++++++++++++++++------
1 file changed, 24 insertions(+), 6 deletions(-)
diff --git a/sound/virtio/virtio_pcm_ops.c b/sound/virtio/virtio_pcm_ops.c
index 1091100a4c98..a4b944a8a484 100644
--- a/sound/virtio/virtio_pcm_ops.c
+++ b/sound/virtio/virtio_pcm_ops.c
@@ -435,17 +435,26 @@ static int virtsnd_pcm_sync_stop(struct snd_pcm_substream *substream)
* substream for playback.
* @substream: Kernel ALSA substream.
*
- * Context: Any context.
- * Return: Hardware position in frames inside [0 ... buffer_size) range.
+ * Context: Any context. Takes and releases the VirtIO substream spinlock.
+ * Return: Hardware position in frames inside [0 ... buffer_size) range, or
+ * SNDRV_PCM_POS_XRUN if the device reported an xrun.
*/
static snd_pcm_uframes_t
virtsnd_pcm_pb_pointer(struct snd_pcm_substream *substream)
{
struct virtio_pcm_substream *vss = snd_pcm_substream_chip(substream);
+ size_t hw_ptr;
+
+ scoped_guard(spinlock_irqsave, &vss->lock) {
+ if (vss->xfer_xrun)
+ return SNDRV_PCM_POS_XRUN;
+
+ hw_ptr = vss->hw_ptr;
+ }
return snd_pcm_indirect_playback_pointer(substream,
&vss->pcm_indirect,
- vss->hw_ptr);
+ hw_ptr);
}
/**
@@ -453,17 +462,26 @@ virtsnd_pcm_pb_pointer(struct snd_pcm_substream *substream)
* substream for capture.
* @substream: Kernel ALSA substream.
*
- * Context: Any context.
- * Return: Hardware position in frames inside [0 ... buffer_size) range.
+ * Context: Any context. Takes and releases the VirtIO substream spinlock.
+ * Return: Hardware position in frames inside [0 ... buffer_size) range, or
+ * SNDRV_PCM_POS_XRUN if the device reported an xrun.
*/
static snd_pcm_uframes_t
virtsnd_pcm_cp_pointer(struct snd_pcm_substream *substream)
{
struct virtio_pcm_substream *vss = snd_pcm_substream_chip(substream);
+ size_t hw_ptr;
+
+ scoped_guard(spinlock_irqsave, &vss->lock) {
+ if (vss->xfer_xrun)
+ return SNDRV_PCM_POS_XRUN;
+
+ hw_ptr = vss->hw_ptr;
+ }
return snd_pcm_indirect_capture_pointer(substream,
&vss->pcm_indirect,
- vss->hw_ptr);
+ hw_ptr);
}
static void virtsnd_pcm_trans_copy(struct snd_pcm_substream *substream,
--
2.56.1
next reply other threads:[~2026-11-30 12:44 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 12:44 Eric Curtin [this message]
2026-11-30 12:52 ` [PATCH] ALSA: virtio: report device xruns from the pointer callbacks sashiko-bot
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=20261130124434.474178-1-ericcurtin17@gmail.com \
--to=ericcurtin17@gmail.com \
--cc=anton.yakovlev@opensynergy.com \
--cc=linux-sound@vger.kernel.org \
--cc=mst@redhat.com \
--cc=perex@perex.cz \
--cc=tiwai@suse.de \
--cc=virtualization@lists.linux.dev \
/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.