Linux Sound subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Eric Curtin" <ericcurtin17@gmail.com>
Cc: virtualization@lists.linux.dev, linux-sound@vger.kernel.org,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Eugenio Perez" <eperezma@redhat.com>
Subject: Re: [PATCH] ALSA: virtio: report an xrun when a whole buffer passed unseen
Date: Mon, 30 Nov 2026 12:20:53 +0000	[thread overview]
Message-ID: <sashiko-outbox-241043@kernel.org> (raw)
In-Reply-To: <20261130115939.434308-1-ericcurtin17@gmail.com>

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] ALSA: virtio: ignored xfer_xrun state in
  virtsnd_pcm_pb_pointer() [1]
--

commit 8e4d30ac2cceb1e139c32d93ba83afe971b299a1
Author: Eric Curtin <ericcurtin17@gmail.com>

ALSA: virtio: report an xrun when a whole buffer passed unseen

This commit tracks bytes completed since the last pointer callback in
hw_unseen and reports SNDRV_PCM_POS_XRUN when an entire buffer passes
unseen.

> diff --git a/sound/virtio/virtio_pcm_ops.c b/sound/virtio/virtio_pcm_ops.c
> index 1091100a4c982..c7fdd837d38fd 100644
> --- a/sound/virtio/virtio_pcm_ops.c
> +++ b/sound/virtio/virtio_pcm_ops.c
[ ... ]
> @@ -430,6 +431,38 @@ static int virtsnd_pcm_sync_stop(struct snd_pcm_substream *substream)
>  	return 0;
>  }
>  
> +/*
> + * The pointer callback can only report a position inside the buffer, and both
> + * snd_pcm_indirect_{playback,capture}_pointer() and the PCM core derive the
> + * progress from it modulo the buffer size. A whole buffer completed since the
> + * previous call (the elapsed-period work delayed by a buffer time or more while
> + * the device kept completing messages) therefore looks like no progress: for
> + * playback the bytes stay in pcm_indirect.hw_ready and the core's hw_ptr stays a
> + * buffer behind, so nothing more is ever transferred and the stream stalls with
> + * a full buffer while still RUNNING. The device has then played (or captured)
> + * everything the application had provided for, which is an xrun: report it.
> + */
> +static snd_pcm_uframes_t
> +virtsnd_pcm_pointer(struct snd_pcm_substream *substream,
> +		    snd_pcm_uframes_t (*pointer)(struct snd_pcm_substream *,
> +						 struct snd_pcm_indirect *,
> +						 unsigned int))
> +{
> +	struct virtio_pcm_substream *vss = snd_pcm_substream_chip(substream);
> +	size_t hw_ptr, unseen;
> +
> +	scoped_guard(spinlock_irqsave, &vss->lock) {
> +		hw_ptr = vss->hw_ptr;
> +		unseen = vss->hw_unseen;
> +		vss->hw_unseen = 0;
> +	}
> +
> +	if (unseen >= vss->buffer_bytes)
> +		return SNDRV_PCM_POS_XRUN;

[Severity: High]
This problem wasn't introduced by this patch, but should
virtsnd_pcm_pointer() also check vss->xfer_xrun [1]?

When VIRTIO_SND_PCM_F_EVT_XRUNS is negotiated and the device sends a
VIRTIO_SND_EVT_PCM_XRUN event, virtsnd_pcm_event() sets vss->xfer_xrun =
true under vss->lock.  Commit fe981e67568c ("ALSA: virtio: use ack
callback") dropped the vss->xfer_xrun check from the pointer callback, so
device-reported xruns are silently ignored instead of returning
SNDRV_PCM_POS_XRUN.

[1] https://sashiko.dev/#/bug/linux-4c772c61-641e-49f3-a633-9a55f84dca60

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

      reply	other threads:[~2026-11-30 12:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 11:59 [PATCH] ALSA: virtio: report an xrun when a whole buffer passed unseen Eric Curtin
2026-11-30 12:20 ` 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-241043@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=eperezma@redhat.com \
    --cc=ericcurtin17@gmail.com \
    --cc=linux-sound@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox