* [PATCH] ALSA: virtio: report device xruns from the pointer callbacks
@ 2026-11-30 12:44 Eric Curtin
0 siblings, 0 replies; only message in thread
From: Eric Curtin @ 2026-11-30 12:44 UTC (permalink / raw)
To: Anton Yakovlev, Michael S. Tsirkin
Cc: Takashi Iwai, Jaroslav Kysela, virtualization, linux-sound
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-30 12:44 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 12:44 [PATCH] ALSA: virtio: report device xruns from the pointer callbacks Eric Curtin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox