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 v1 3/5] ALSA: virtio: Retain control requests through device reset
Date: Tue, 13 Oct 2026 05:43:52 +0000 [thread overview]
Message-ID: <sashiko-outbox-169006@kernel.org> (raw)
In-Reply-To: <9d5a0ff360e66bc4ddd28aa790d617edc875e20b.1791867377.git.mynameisjune111@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] virtio_sound: DMA mapping leak from uncalled virtqueue_detach_unused_buf()
- [Low] cleanup: mixing goto and scoped_guard in virtsnd_ctl_msg_send()
--
commit 58ca5d3aaf697e12525c1d956e26244a616c7d76
Author: Joonho Lee <mynameisjune111@gmail.com>
ALSA: virtio: Retain control requests through device reset
This commit updates the virtio sound driver to handle control message teardown
by keeping references to messages through device reset. It marks messages
canceled under the queue lock and defers freeing them until the queue has been
deleted.
> diff --git a/sound/virtio/virtio_card.c b/sound/virtio/virtio_card.c
> index 6f35276416fed..ed884327bb0ef 100644
> --- a/sound/virtio/virtio_card.c
> +++ b/sound/virtio/virtio_card.c
> @@ -349,13 +349,15 @@ static void virtsnd_remove(struct virtio_device *vdev)
> unsigned int i;
>
> virtsnd_disable_event_vq(snd);
> - virtsnd_ctl_msg_cancel_all(snd);
>
> if (snd->card)
> snd_card_free(snd->card);
>
> + virtsnd_ctl_msg_cancel_all(snd);
> +
> virtio_reset_device(vdev);
> vdev->config->del_vqs(vdev);
> + virtsnd_ctl_msg_cleanup(snd);
[Severity: Medium]
Does deleting the virtqueues here after reset without first detaching the
unused buffers leak pending DMA mappings? Because virtqueue_add_sgs() creates
DMA mappings for these buffers, if they aren't drained with
virtqueue_detach_unused_buf() before del_vqs(), those mappings might not be
unmapped.
[ ... ]
> @@ -385,6 +387,7 @@ static int virtsnd_freeze(struct virtio_device *vdev)
>
> virtio_reset_device(vdev);
> vdev->config->del_vqs(vdev);
> + virtsnd_ctl_msg_cleanup(snd);
[Severity: Medium]
Similarly, does suspending the device here destroy the virtqueues without
detaching and unmapping pending DMA buffers?
> diff --git a/sound/virtio/virtio_ctl_msg.c b/sound/virtio/virtio_ctl_msg.c
> index 6433c870f271a..3ad1e1e1b2054 100644
> --- a/sound/virtio/virtio_ctl_msg.c
> +++ b/sound/virtio/virtio_ctl_msg.c
> @@ -147,12 +150,17 @@ int virtsnd_ctl_msg_send(struct virtio_snd *snd, struct virtio_snd_msg *msg,
> psgs[nouts + nins++] = in_sgs;
>
> scoped_guard(spinlock_irqsave, &queue->lock) {
> - rc = virtqueue_add_sgs(queue->vqueue, psgs, nouts, nins, msg,
> - GFP_ATOMIC);
> + if (snd->ctl_msgs_blocked)
> + rc = -ENODEV;
> + else
> + rc = virtqueue_add_sgs(queue->vqueue, psgs, nouts, nins,
> + msg, GFP_ATOMIC);
> if (!rc) {
> notify = virtqueue_kick_prepare(queue->vqueue);
>
> list_add_tail(&msg->list, &snd->ctl_msgs);
> + if (notify)
> + virtqueue_notify(queue->vqueue);
> }
> }
[ ... ]
> @@ -187,6 +192,11 @@ int virtsnd_ctl_msg_send(struct virtio_snd *snd, struct virtio_snd_msg *msg,
> goto on_exit;
> }
>
> + if (READ_ONCE(msg->cancelled)) {
> + rc = -ENODEV;
> + goto on_exit;
> + }
> +
> switch (le32_to_cpu(response->code)) {
> case VIRTIO_SND_S_OK:
> rc = 0;
[Severity: Low]
This isn't a bug, but does mixing scope-based cleanup like scoped_guard with
traditional goto-based error handling (goto on_exit) violate the cleanup
guidelines?
The guidelines state that for a given routine, either all resources should be
converted to scope-based cleanup or none of them should be, to prevent brittle
ownership semantics and future bugs.
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1791867377.git.mynameisjune111@gmail.com?part=3
next prev parent reply other threads:[~2026-10-13 5:43 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-13 5:30 [PATCH v1 0/5] ALSA: virtio: Fix request lifetime and error recovery Joonho Lee
2026-10-13 5:30 ` [PATCH v1 1/5] ALSA: virtio: Notify queued PCM messages after send errors Joonho Lee
2026-10-13 5:40 ` sashiko-bot
2026-10-13 5:30 ` [PATCH v1 2/5] ALSA: virtio: Recover PCM state after a failed start Joonho Lee
2026-10-13 5:42 ` sashiko-bot
2026-10-13 5:30 ` [PATCH v1 3/5] ALSA: virtio: Retain control requests through device reset Joonho Lee
2026-10-13 5:43 ` sashiko-bot [this message]
2026-10-13 5:30 ` [PATCH v1 4/5] ALSA: virtio: Retain PCM DMA pages until messages are freed Joonho Lee
2026-10-13 5:39 ` sashiko-bot
2026-10-13 5:30 ` [PATCH v1 5/5] ALSA: virtio: Keep control payloads in refcounted messages Joonho Lee
2026-10-13 5:39 ` 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-169006@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 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.