From: sashiko-bot@kernel.org
To: "Joonho Lee" <mynameisjune111@gmail.com>
Cc: virtualization@lists.linux.dev,
"Michael S. Tsirkin" <mst@redhat.com>,
"Eugenio Perez" <eperezma@redhat.com>
Subject: Re: [PATCH v2 2/5] ALSA: virtio: Recover PCM state after a failed start
Date: Tue, 13 Oct 2026 08:04:46 +0000 [thread overview]
Message-ID: <sashiko-outbox-169220@kernel.org> (raw)
In-Reply-To: <9b9b0698d28e1d2b6d3a94f62cfbd97a7e308854.1791877396.git.mynameisjune111@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] sound: virtio: Data race on vss->stopped due to missing ALSA stream lock in prepare/hw_params
--
commit cf7b0007082a8c0e3a16320e4229781856250174
Author: Joonho Lee <mynameisjune111@gmail.com>
ALSA: virtio: Recover PCM state after a failed start
This commit modifies the capture trigger to disable transfers, mark the stream
as stopped, and arm the stop operating flag if a PCM START fails. It also adds
checks in the hw_params and prepare callbacks to reject retries if the stream
is stopped, until a subsequent sync_stop resolves the state.
> diff --git a/sound/virtio/virtio_pcm_ops.c b/sound/virtio/virtio_pcm_ops.c
> index a40ea394bf174..fe8e0dc3eafca 100644
> --- a/sound/virtio/virtio_pcm_ops.c
> +++ b/sound/virtio/virtio_pcm_ops.c
[ ... ]
> @@ -224,6 +233,12 @@ static int virtsnd_pcm_hw_params(struct snd_pcm_substream *substream,
> vss->sid);
> return -EBADFD;
> }
> + if (vss->stopped) {
[Severity: Medium]
Is it safe to read vss->stopped locklessly here?
ALSA explicitly drops the stream lock (group->mutex) before invoking
virtsnd_pcm_hw_params(), virtsnd_pcm_prepare(), and hw_free() (which calls
virtsnd_pcm_sync_stop()).
Concurrently, ioctls like SNDRV_PCM_IOCTL_FORWARD (which invoke the ack
callback) acquire group->mutex but not buffer_mutex.
This means virtsnd_pcm_pb_ack() can execute concurrently with
virtsnd_pcm_hw_params() or virtsnd_pcm_prepare() on the same substream.
Since the ack path writes to vss->stopped under vss->lock, reading it here
without vss->lock could result in a data race. A torn read or compiler
reordering could result in an incorrect stream state being observed.
> + dev_err(&vdev->dev, "SID %u: stream release failed\n",
> + vss->sid);
> + substream->runtime->stop_operating = true;
> + return -EBADFD;
> + }
>
> rc = virtsnd_pcm_dev_set_params(vss, params_buffer_bytes(hw_params),
[ ... ]
> @@ -274,6 +289,13 @@ static int virtsnd_pcm_prepare(struct snd_pcm_substream *substream)
> struct virtio_device *vdev = vss->snd->vdev;
> struct virtio_snd_msg *msg;
>
> + if (vss->stopped) {
[Severity: Medium]
Similarly, vss->stopped is read locklessly here in virtsnd_pcm_prepare().
Could this also race with concurrent ack callbacks for the same reason?
This problem wasn't introduced by this patch, but vss->stopped is also
written locklessly at the end of virtsnd_pcm_sync_stop().
Since virtsnd_pcm_sync_stop() is called from hw_free where ALSA also drops
group->mutex, could that lockless write also race with concurrent ack
callbacks?
> + dev_err(&vdev->dev, "SID %u: stream release failed\n",
> + vss->sid);
> + substream->runtime->stop_operating = true;
> + return -EBADFD;
> + }
> +
> if (!vss->suspended) {
> if (virtsnd_pcm_msg_pending_num(vss)) {
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1791877396.git.mynameisjune111@gmail.com?part=2
next prev parent reply other threads:[~2026-10-13 8:04 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-13 7:43 [PATCH v2 0/5] ALSA: virtio: Fix request lifetime and error recovery Joonho Lee
2026-10-13 7:43 ` [PATCH v2 1/5] ALSA: virtio: Propagate PCM send failures through ACK Joonho Lee
2026-10-13 7:54 ` sashiko-bot
2026-10-13 7:43 ` [PATCH v2 2/5] ALSA: virtio: Recover PCM state after a failed start Joonho Lee
2026-10-13 8:04 ` sashiko-bot [this message]
2026-10-13 8:58 ` Joonho Lee
2026-10-13 7:43 ` [PATCH v2 3/5] ALSA: virtio: Retain queued messages through device reset Joonho Lee
2026-10-13 7:53 ` sashiko-bot
2026-10-13 7:43 ` [PATCH v2 4/5] ALSA: virtio: Keep PCM DMA buffers alive through device ownership Joonho Lee
2026-10-13 8:01 ` sashiko-bot
2026-10-13 7:43 ` [PATCH v2 5/5] ALSA: virtio: Keep control payloads alive through DMA completion Joonho Lee
2026-10-13 7:52 ` sashiko-bot
2026-10-13 8:59 ` Joonho Lee
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-169220@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=eperezma@redhat.com \
--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