All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Joonho Lee" <mynameisjune111@gmail.com>, linux-sound@vger.kernel.org
Cc: virtualization@lists.linux.dev,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Eugenio Perez" <eperezma@redhat.com>
Subject: Re: [PATCH v11 14/14] ALSA: virtio: rebase ordinary capture accounting on RESET
Date: Sat, 31 Oct 2026 02:40:26 +0000	[thread overview]
Message-ID: <sashiko-outbox-191715@kernel.org> (raw)
In-Reply-To: <20261031020855.2402-15-mynameisjune111@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] ALSA: virtio: stale pcm_indirect state after RESET in PREPARED state
--

commit c77024b62d8010ad66e1fdcc36816a226c5bcfcc
Author: Joonho Lee <mynameisjune111@gmail.com>

ALSA: virtio: rebase ordinary capture accounting on RESET

This commit introduces virtsnd_pcm_indirect_reset() and
virtsnd_pcm_capture_indirect_ops to rebase ordinary capture indirect
positions and return discarded RX space when SNDRV_PCM_IOCTL_RESET is
called. It also suppresses nested ACK refills during the RESET pointer
observation and updates the period notification floor.

Link: https://sashiko.dev/#/patchset/20261030052629.27742-1-mynameisjune111%40gmail.com?part=14

> diff --git a/sound/virtio/virtio_pcm_ops.c b/sound/virtio/virtio_pcm_ops.c
> index f350d0c753763..9af0813acd77a 100644
> --- a/sound/virtio/virtio_pcm_ops.c
> +++ b/sound/virtio/virtio_pcm_ops.c

[ ... ]

> @@ -1761,6 +1769,89 @@ static int virtsnd_pcm_sync_stop(struct snd_pcm_substream *substream)
>  	return virtsnd_pcm_sync_stop_locked(substream);
>  }
>  
> +/*
> + * The PCM lock covers indirect accounting and core completion. Once lib_reset
> + * changes hw_ptr, complete the core rebase even if refilling fails. The latched
> + * XRUN rejects subsequent pointer/ACK operations; the worker publishes XRUN to
> + * paused streams too. RESET success therefore does not imply stream recovery.
> + */
> +static int virtsnd_pcm_indirect_reset(struct snd_pcm_substream *substream)
> +{
> +	struct virtio_pcm_substream *vss = snd_pcm_substream_chip(substream);
> +	struct snd_pcm_runtime *runtime = substream->runtime;
> +	struct virtio_snd_queue *queue = virtsnd_pcm_queue(vss);
> +	struct virtsnd_pcm_transfer transfer = {};
> +	snd_pcm_uframes_t paused_ptr = 0;
> +	bool paused = runtime->state == SNDRV_PCM_STATE_PAUSED;
> +	int rc;
> +
> +	/* Only PCM-locked callbacks access this observation flag. */
> +	vss->indirect_reset_observing = true;
> +	rc = snd_pcm_lib_reset(substream);
> +	vss->indirect_reset_observing = false;
> +	if (rc)
> +		return rc;
> +	guard(spinlock_irqsave)(&queue->lock);
> +	guard(spinlock)(&vss->lock);
> +	if (vss->resetting)
> +		return 0;
> +	if (vss->xfer_xrun) {
> +		virtsnd_pcm_transfer_failed(vss);
> +		virtsnd_pcm_schedule_period_elapsed(vss);
> +		return 0;
> +	}
> +	if (!snd_pcm_running(substream) && !paused)
> +		return 0;

[Severity: Medium]
Can returning early here when the substream is in SNDRV_PCM_STATE_PREPARED
leave vss->pcm_indirect.appl_ptr and vss->pcm_indirect.sw_ready out of sync
with runtime->control->appl_ptr?

While in SNDRV_PCM_STATE_PREPARED (where vss->prepared is true and
vss->stopped is false), userspace can invoke SNDRV_PCM_IOCTL_SYNC_PTR
without SNDRV_PCM_SYNC_PTR_APPL to advance appl_ptr to N:

  snd_pcm_sync_ptr()
    pcm_lib_apply_appl_ptr()
      virtsnd_pcm_cp_ack()
        virtsnd_pcm_cp_ack_locked()
          snd_pcm_indirect_capture_transfer()

which sets vss->pcm_indirect.appl_ptr = N and
vss->pcm_indirect.sw_ready = -frames_to_bytes(runtime, N).

If userspace then calls SNDRV_PCM_IOCTL_RESET in SNDRV_PCM_STATE_PREPARED,
snd_pcm_lib_reset() sets runtime->status->hw_ptr = 0,
virtsnd_pcm_indirect_reset() returns 0 early without updating
vss->pcm_indirect, and snd_pcm_reset_substream() resets
runtime->control->appl_ptr = runtime->status->hw_ptr (0).

When the stream is subsequently started and virtsnd_pcm_cp_pointer() or
virtsnd_pcm_cp_ack() runs before appl_ptr reaches N,
snd_pcm_indirect_capture_transfer() sees diff = appl_ptr - rec->appl_ptr < 0:

  if (diff) {
          if (diff < -(snd_pcm_sframes_t) (runtime->boundary / 2))
                  diff += runtime->boundary;
          if (diff < 0)
                  return -EPIPE;

causing a false -EPIPE XRUN and a dev_err() message in
virtsnd_pcm_cp_ack_locked().

Should virtsnd_pcm_indirect_reset() also reset vss->pcm_indirect.sw_ready = 0
and vss->pcm_indirect.appl_ptr = runtime->status->hw_ptr when not running or
paused, similar to how virtsnd_pcm_reset() updates
vss->pcm_indirect.appl_ptr = runtime->status->hw_ptr?

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

      reply	other threads:[~2026-10-31  2:40 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-31  2:08 [PATCH v11 00/14] ALSA: virtio: staged capture recovery and PCM RESET synchronization Joonho Lee
2026-10-31  2:08 ` [PATCH v11 01/14] ALSA: virtio: Propagate PCM send failures through ACK Joonho Lee
2026-10-31  2:29   ` sashiko-bot
2026-10-31  2:08 ` [PATCH v11 02/14] ALSA: virtio: Recover PCM state after a failed start Joonho Lee
2026-10-31  2:31   ` sashiko-bot
2026-10-31  2:08 ` [PATCH v11 03/14] ALSA: virtio: Retain queued messages through device reset Joonho Lee
2026-10-31  2:40   ` sashiko-bot
2026-10-31  2:08 ` [PATCH v11 04/14] ALSA: virtio: Keep PCM DMA buffers alive through device ownership Joonho Lee
2026-10-31  2:33   ` sashiko-bot
2026-10-31  2:08 ` [PATCH v11 05/14] ALSA: virtio: Keep control payloads alive through DMA completion Joonho Lee
2026-10-31  2:20   ` sashiko-bot
2026-10-31  2:08 ` [PATCH v11 06/14] ALSA: virtio: wait through signals for PCM teardown Joonho Lee
2026-10-31  2:27   ` sashiko-bot
2026-10-31  2:08 ` [PATCH v11 07/14] ALSA: pcm: mark stop-threshold accesses for capture policy sampling Joonho Lee
2026-10-31  2:14   ` sashiko-bot
2026-10-31  2:08 ` [PATCH v11 08/14] ALSA: pcm: report partial progress under the stream lock Joonho Lee
2026-10-31  2:13   ` sashiko-bot
2026-10-31  2:08 ` [PATCH v11 09/14] ALSA: virtio: add staged capture accounting and lifecycle recovery Joonho Lee
2026-10-31  2:51   ` sashiko-bot
2026-10-31  2:08 ` [PATCH v11 10/14] ALSA: virtio: prioritize staged capture period work Joonho Lee
2026-10-31  2:15   ` sashiko-bot
2026-10-31  2:08 ` [PATCH v11 11/14] docs: describe virtio-sound capture options Joonho Lee
2026-10-31  2:16   ` sashiko-bot
2026-10-31  2:08 ` [PATCH v11 12/14] ALSA: pcm: add an optional reset operation under the stream lock Joonho Lee
2026-10-31  2:20   ` sashiko-bot
2026-10-31  2:08 ` [PATCH v11 13/14] ALSA: virtio: synchronize staged capture accounting during RESET Joonho Lee
2026-10-31  2:42   ` sashiko-bot
2026-10-31  2:08 ` [PATCH v11 14/14] ALSA: virtio: rebase ordinary capture accounting on RESET Joonho Lee
2026-10-31  2:40   ` 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-191715@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=eperezma@redhat.com \
    --cc=linux-sound@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=mynameisjune111@gmail.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 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.