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 v8 05/14] ALSA: virtio: Keep control payloads alive through DMA completion
Date: Thu, 29 Oct 2026 05:54:03 +0000 [thread overview]
Message-ID: <sashiko-outbox-188779@kernel.org> (raw)
In-Reply-To: <20261029054354.2931-6-mynameisjune111@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] ALSA: virtio: misaligned virtio_snd_ctl_value access in virtsnd_kctl_get()
--
commit b0116a304a65fa5afc94f948da091c12c54f919b
Author: Joonho Lee <mynameisjune111@gmail.com>
ALSA: virtio: Keep control payloads alive through DMA completion
This commit moves control message headers and data payloads into a
reference-counted DMA buffer owned by struct virtio_snd_msg so that caller
cleanup on timeout or interruption does not invalidate in-flight DMA. It also
aligns scatterlist regions to the greater of the DMA cacheline and
struct virtio_snd_ctl_value alignment.
> diff --git a/sound/virtio/virtio_ctl_msg.c b/sound/virtio/virtio_ctl_msg.c
> index 7114bea4033a5..2e0ff15e729da 100644
> --- a/sound/virtio/virtio_ctl_msg.c
> +++ b/sound/virtio/virtio_ctl_msg.c
[ ... ]
> @@ -85,20 +161,85 @@ void *virtsnd_ctl_msg_response(struct virtio_snd_msg *msg)
> * Return: Allocated message on success, NULL on failure.
> */
> struct virtio_snd_msg *virtsnd_ctl_msg_alloc(size_t request_size,
> - size_t response_size, gfp_t gfp)
> + size_t response_size,
> + size_t request_data_size,
> + size_t response_data_size,
> + gfp_t gfp)
> {
[ ... ]
> + cache_alignment = dma_get_cache_alignment();
> + if (cache_alignment <= 0)
> + return NULL;
> + /* DMA coherence does not remove the CPU's type alignment requirement. */
> + alignment = max_t(size_t, cache_alignment,
> + __alignof__(struct virtio_snd_ctl_value));
[ ... ]
> diff --git a/sound/virtio/virtio_kctl.c b/sound/virtio/virtio_kctl.c
> index 45f7b6a5b3080..4cf75dedbe9a3 100644
> --- a/sound/virtio/virtio_kctl.c
> +++ b/sound/virtio/virtio_kctl.c
> @@ -161,10 +163,12 @@ static int virtsnd_kctl_get(struct snd_kcontrol *kcontrol,
> unsigned int i;
> int rc;
>
> - msg = virtsnd_ctl_msg_alloc(request_size, response_size, GFP_KERNEL);
> + msg = virtsnd_ctl_msg_alloc(request_size, response_size, 0, 0,
> + GFP_KERNEL);
[Severity: Medium]
Does packing both struct virtio_snd_hdr and struct virtio_snd_ctl_value into
response_size here leave kvalue misaligned in virtsnd_kctl_get()?
In sound/virtio/virtio_ctl_msg.c, virtsnd_ctl_msg_alloc() aligns the start of
each scatterlist region (including msg->sg_response) to a multiple of
__alignof__(struct virtio_snd_ctl_value) (8 bytes) via
virtsnd_ctl_msg_sg_init().
However, in sound/virtio/virtio_kctl.c, virtsnd_kctl_get() passes
response_size = sizeof(struct virtio_snd_hdr) + sizeof(*kvalue) and
response_data_size = 0, and then computes kvalue by adding the 4-byte
sizeof(struct virtio_snd_hdr) to the 8-byte-aligned response buffer:
sound/virtio/virtio_kctl.c:virtsnd_kctl_get() {
...
kvalue = (void *)((u8 *)virtsnd_ctl_msg_response(msg) +
sizeof(struct virtio_snd_hdr));
switch (type) {
...
case VIRTIO_SND_CTL_TYPE_INTEGER64:
for (i = 0; i < count; ++i)
uvalue->value.integer64.value[i] =
le64_to_cpu(kvalue->value.integer64[i]);
break;
...
}
Because virtsnd_ctl_msg_response(msg) is 8-byte aligned and
sizeof(struct virtio_snd_hdr) is 4 bytes, kvalue is guaranteed to be at an
address congruent to 4 mod 8. When userspace reads a control element with
type VIRTIO_SND_CTL_TYPE_INTEGER64 via SNDRV_CTL_IOCTL_ELEM_READ,
le64_to_cpu(kvalue->value.integer64[i]) performs an unaligned 64-bit typed
load through kvalue.
Note that a later commit in the series, 775188574a68 ("ALSA: virtio: add
staged capture accounting and lifecycle recovery"), addresses this by passing
sizeof(*kvalue) as response_data_size and retrieving kvalue via
virtsnd_ctl_msg_response_data(msg). Should that change be folded into this
commit so that kvalue is aligned here as intended?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261029054354.2931-1-mynameisjune111@gmail.com?part=5
next prev parent reply other threads:[~2026-10-29 5:54 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-29 5:43 [PATCH v8 00/14] ALSA: virtio: staged capture recovery and PCM RESET synchronization Joonho Lee
2026-10-29 5:43 ` [PATCH v8 01/14] ALSA: virtio: Propagate PCM send failures through ACK Joonho Lee
2026-10-29 5:43 ` [PATCH v8 02/14] ALSA: virtio: Recover PCM state after a failed start Joonho Lee
2026-10-29 6:10 ` sashiko-bot
2026-10-29 5:43 ` [PATCH v8 03/14] ALSA: virtio: Retain queued messages through device reset Joonho Lee
2026-10-29 5:43 ` [PATCH v8 04/14] ALSA: virtio: Keep PCM DMA buffers alive through device ownership Joonho Lee
2026-10-29 6:07 ` sashiko-bot
2026-10-29 5:43 ` [PATCH v8 05/14] ALSA: virtio: Keep control payloads alive through DMA completion Joonho Lee
2026-10-29 5:54 ` sashiko-bot [this message]
2026-10-29 5:43 ` [PATCH v8 06/14] ALSA: virtio: wait through signals for PCM teardown Joonho Lee
2026-10-29 5:43 ` [PATCH v8 07/14] ALSA: pcm: mark stop-threshold accesses for capture policy sampling Joonho Lee
2026-10-29 5:43 ` [PATCH v8 08/14] ALSA: pcm: stop paused streams before synchronizing teardown Joonho Lee
2026-10-29 6:04 ` sashiko-bot
2026-10-29 5:43 ` [PATCH v8 09/14] ALSA: virtio: add staged capture accounting and lifecycle recovery Joonho Lee
2026-10-29 6:23 ` sashiko-bot
2026-10-29 5:43 ` [PATCH v8 10/14] ALSA: virtio: prioritize staged capture period work Joonho Lee
2026-10-29 5:43 ` [PATCH v8 11/14] docs: describe virtio-sound capture options Joonho Lee
2026-10-29 5:43 ` [PATCH v8 12/14] ALSA: pcm: add an optional reset operation under the stream lock Joonho Lee
2026-10-29 5:43 ` [PATCH v8 13/14] ALSA: virtio: synchronize staged capture reset with PCM positions Joonho Lee
2026-10-29 6:05 ` sashiko-bot
2026-10-29 5:43 ` [PATCH v8 14/14] ALSA: virtio: synchronize indirect capture positions on reset Joonho Lee
2026-10-29 6:06 ` 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-188779@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