Linux virtualization list
 help / color / mirror / Atom feed
* [PATCH] ALSA: virtio: report device xruns from the pointer callbacks
@ 2026-11-30 12:44 Eric Curtin
  2026-11-30 12:52 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages 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] 2+ messages in thread

* Re: [PATCH] ALSA: virtio: report device xruns from the pointer callbacks
  2026-11-30 12:44 [PATCH] ALSA: virtio: report device xruns from the pointer callbacks Eric Curtin
@ 2026-11-30 12:52 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-30 12:52 UTC (permalink / raw)
  To: Eric Curtin; +Cc: virtualization, Michael S. Tsirkin, Eugenio Perez

> 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>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130124434.474178-1-ericcurtin17@gmail.com?part=1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-30 12:52 UTC | newest]

Thread overview: 2+ messages (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
2026-11-30 12:52 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox