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 v18 07/12] ALSA: virtio: retain PCM DMA pages and validate capture ring ownership
Date: Fri, 06 Nov 2026 00:36:08 +0000 [thread overview]
Message-ID: <sashiko-outbox-200452@kernel.org> (raw)
In-Reply-To: <20261106000644.20460-8-mynameisjune111@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] ALSA: virtio: sw_ready desynchronization in virtsnd_pcm_cp_ack()
--
commit b314c942dc53f8c652b76808e69e1ee4418c9e8e
Author: Joonho Lee <mynameisjune111@gmail.com>
ALSA: virtio: retain PCM DMA pages and validate capture ring ownership
This commit retains references to ALSA PCM DMA pages (or uses driver-owned
buffers on NOMMU systems) until queued I/O messages are freed, and adds
validation for period boundaries and fixed-slot capture completions. It also
seeds the ordinary capture ring once per prepare and reserves the RX ring via
sw_ready until appl_ptr consumes the captured data.
> diff --git a/sound/virtio/virtio_pcm_ops.c b/sound/virtio/virtio_pcm_ops.c
> index 343700ec50476..bf9dafe149dac 100644
> --- a/sound/virtio/virtio_pcm_ops.c
> +++ b/sound/virtio/virtio_pcm_ops.c
[ ... ]
> @@ -433,8 +446,15 @@ static int virtsnd_pcm_trigger(struct snd_pcm_substream *substream, int command)
> substream->runtime->stop_operating = true;
> return -EBADFD;
> }
> - if (vss->direction == SNDRV_PCM_STREAM_CAPTURE)
> + if (vss->direction == SNDRV_PCM_STREAM_CAPTURE &&
> + !vss->capture_rx_seeded) {
> rc = virtsnd_pcm_msg_send(vss, 0, vss->buffer_bytes);
> + if (!rc) {
> + /* The full RX ring is reserved until userspace reads it. */
> + vss->pcm_indirect.sw_ready = vss->buffer_bytes;
> + vss->capture_rx_seeded = true;
> + }
> + }
> if (rc) {
> vss->stopped = true;
> substream->runtime->stop_operating = true;
[Severity: High]
Can userspace desynchronize or underflow vss->pcm_indirect.sw_ready via
SNDRV_PCM_IOCTL_SYNC_PTR in virtsnd_pcm_cp_ack()?
In sound/virtio/virtio_pcm_ops.c, virtsnd_pcm_ack_state() allows ACK in
SNDRV_PCM_STATE_PREPARED, and virtsnd_pcm_cp_ack() does not check
vss->capture_rx_seeded before calling snd_pcm_indirect_capture_transfer():
sound/virtio/virtio_pcm_ops.c:virtsnd_pcm_cp_ack() {
...
scoped_guard(spinlock_irqsave, &queue->lock) {
guard(spinlock)(&vss->lock);
if (vss->preparing || !vss->prepared)
return -EBADFD;
/* Keep only the post-STOP capture tail available during drain. */
if (vss->stopped &&
(vss->xfer_xrun ||
substream->runtime->state != SNDRV_PCM_STATE_DRAINING))
return -EBADFD;
if (vss->xfer_xrun) {
rc = -EPIPE;
} else {
transfer.indirect = vss->pcm_indirect;
rc = snd_pcm_indirect_capture_transfer(substream,
&transfer.indirect,
virtsnd_pcm_trans_copy);
...
}
If userspace invokes SNDRV_PCM_IOCTL_SYNC_PTR (without
SNDRV_PCM_SYNC_PTR_APPL) while the capture stream is in
SNDRV_PCM_STATE_PREPARED before SNDRV_PCM_TRIGGER_START,
pcm_lib_apply_appl_ptr() invokes virtsnd_pcm_cp_ack() ->
snd_pcm_indirect_capture_transfer(), which updates vss->pcm_indirect.appl_ptr
and decrements vss->pcm_indirect.sw_ready below zero while sw_data and
hw_data remain 0. When virtsnd_pcm_trigger() later handles
SNDRV_PCM_TRIGGER_START, it sets vss->pcm_indirect.sw_ready =
vss->buffer_bytes while vss->pcm_indirect.appl_ptr is already non-zero,
leaving sw_ready and sw_data out of sync with appl_ptr.
Similarly, after SNDRV_PCM_TRIGGER_START in SNDRV_PCM_STATE_RUNNING,
pcm_lib_apply_appl_ptr() only bounds each appl_ptr advance to
runtime->buffer_size rather than the unread captured frames. If userspace
uses SNDRV_PCM_IOCTL_SYNC_PTR to advance appl_ptr ahead of captured bytes
(for example when hw_ready is 0 before completions arrive),
snd_pcm_indirect_capture_transfer() subtracts frames_to_bytes(runtime, diff)
from rec->sw_ready without transferring anything.
Wouldn't subsequent period completions in virtsnd_pcm_cp_pointer() then see
rec->sw_ready < rec->sw_buffer_size and prematurely re-queue capture
descriptors before userspace reads them, or allow repeated SYNC_PTR calls to
underflow rec->sw_ready so (int)(rec->sw_buffer_size - rec->sw_ready) wraps
negative and calls virtsnd_pcm_msg_send() on already-queued descriptors?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261106000644.20460-1-mynameisjune111@gmail.com?part=7
next prev parent reply other threads:[~2026-11-06 0:36 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 0:06 [PATCH v18 00/12] ALSA: virtio: fix capture lifetime and accounting Joonho Lee
2026-11-06 0:06 ` [PATCH v18 01/12] ALSA: pcm: mark stop-threshold accesses for capture policy sampling Joonho Lee
2026-11-06 0:10 ` sashiko-bot
2026-11-06 0:06 ` [PATCH v18 02/12] ALSA: pcm: report partial progress under the stream lock Joonho Lee
2026-11-06 0:11 ` sashiko-bot
2026-11-06 0:06 ` [PATCH v18 03/12] ALSA: pcm: add an optional reset operation " Joonho Lee
2026-11-06 0:14 ` sashiko-bot
2026-11-06 0:06 ` [PATCH v18 04/12] ALSA: virtio: Propagate PCM send failures through ACK Joonho Lee
2026-11-06 0:35 ` sashiko-bot
2026-11-06 0:06 ` [PATCH v18 05/12] ALSA: virtio: Recover PCM state after a failed start Joonho Lee
2026-11-06 0:26 ` sashiko-bot
2026-11-06 0:06 ` [PATCH v18 06/12] ALSA: virtio: Retain queued messages through device reset Joonho Lee
2026-11-06 0:31 ` sashiko-bot
2026-11-06 0:06 ` [PATCH v18 07/12] ALSA: virtio: retain PCM DMA pages and validate capture ring ownership Joonho Lee
2026-11-06 0:36 ` sashiko-bot [this message]
2026-11-06 0:06 ` [PATCH v18 08/12] ALSA: virtio: Keep control payloads alive through DMA completion Joonho Lee
2026-11-06 0:14 ` sashiko-bot
2026-11-06 0:06 ` [PATCH v18 09/12] ALSA: virtio: wait through signals for PCM teardown Joonho Lee
2026-11-06 0:22 ` sashiko-bot
2026-11-06 0:06 ` [PATCH v18 10/12] ALSA: virtio: serialize staged capture lifecycle and defer paused XRUNs Joonho Lee
2026-11-06 0:30 ` sashiko-bot
2026-11-06 0:06 ` [PATCH v18 11/12] ALSA: virtio: prioritize staged capture period work Joonho Lee
2026-11-06 0:20 ` sashiko-bot
2026-11-06 0:06 ` [PATCH v18 12/12] docs: describe virtio-sound capture options Joonho Lee
2026-11-06 0:17 ` 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=sashiko-outbox-200452@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox