Linux virtualization list
 help / color / mirror / Atom feed
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 5/5] ALSA: virtio: Keep control payloads in refcounted messages
Date: Tue, 13 Oct 2026 05:39:54 +0000	[thread overview]
Message-ID: <sashiko-outbox-169001@kernel.org> (raw)
In-Reply-To: <9aac47803de024cd66c56cc594560c69b5a8a526.1791867377.git.mynameisjune111@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] virtio/snd: DMA cacheline sharing for control message payloads
--

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

ALSA: virtio: Keep control payloads in refcounted messages
    
Control requests can include scatterlists that point to caller-owned
payloads. A synchronous send can time out while the device still owns
those descriptors, so the caller can free a TLV or other payload before
a late device access.

> diff --git a/sound/virtio/virtio_ctl_msg.c b/sound/virtio/virtio_ctl_msg.c
> index 3ad1e1e1b2054..62d4c529922ca 100644
> --- a/sound/virtio/virtio_ctl_msg.c
> +++ b/sound/virtio/virtio_ctl_msg.c

[ ... ]

> @@ -85,20 +119,43 @@ 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)
>  {
>  	struct virtio_snd_msg *msg;
> -
> -	if (!request_size || !response_size)
> +	size_t total_size = sizeof(*msg);
> +	u8 *data;
> +
> +	if (!request_size || !response_size || request_size > UINT_MAX ||
> +	    response_size > UINT_MAX || request_data_size > UINT_MAX ||
> +	    response_data_size > UINT_MAX ||
> +	    check_add_overflow(total_size, request_size, &total_size) ||
> +	    check_add_overflow(total_size, response_size, &total_size) ||
> +	    check_add_overflow(total_size, request_data_size, &total_size) ||
> +	    check_add_overflow(total_size, response_data_size, &total_size))
>  		return NULL;
>  
> -	msg = kzalloc(sizeof(*msg) + request_size + response_size, gfp);
> +	msg = kzalloc(total_size, gfp);
>  	if (!msg)
>  		return NULL;
>  
> -	sg_init_one(&msg->sg_request, (u8 *)msg + sizeof(*msg), request_size);
> -	sg_init_one(&msg->sg_response, (u8 *)msg + sizeof(*msg) + request_size,
> -		    response_size);
> +	data = (u8 *)msg + sizeof(*msg);
> +	sg_init_one(&msg->sg_request, data, (unsigned int)request_size);
> +	data += request_size;
> +	sg_init_one(&msg->sg_response, data, (unsigned int)response_size);
> +	data += response_size;
> +	msg->request_data_size = request_data_size;
> +	msg->response_data_size = response_data_size;
> +	if (request_data_size) {
> +		sg_init_one(&msg->sg_request_data, data,
> +			    (unsigned int)request_data_size);
> +		data += request_data_size;
> +	}
> +	if (response_data_size)
> +		sg_init_one(&msg->sg_response_data, data,
> +			    (unsigned int)response_data_size);

[Severity: High]
Does packing these DMA buffers tightly together after the virtio_snd_msg
struct cause cacheline sharing issues?

Because sizeof(*msg) and the header sizes are not aligned to
ARCH_DMA_MINALIGN, these buffers might share CPU cachelines with each other
and with CPU-accessed fields of virtio_snd_msg (like ref_count and
cancelled).

On non-cache-coherent architectures, mapping a buffer as DMA_FROM_DEVICE
(such as sg_response and sg_response_data) causes the DMA API to invalidate
the shared cacheline upon unmapping so the CPU sees the device's writes.

If the CPU concurrently modifies msg->cancelled or msg->ref_count in that
same cacheline (e.g., upon a timeout), could those writes be silently
discarded by the cache invalidation?

Previously, payloads were allocated separately via kzalloc(size), which
guaranteed safe ARCH_DMA_MINALIGN boundaries. Embedding them inline appears
to introduce a DMA cacheline sharing hazard.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1791867377.git.mynameisjune111@gmail.com?part=5

      reply	other threads:[~2026-10-13  5:39 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
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 [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-169001@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