All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Stjepan Poljak" <stjepan.poljak@gmail.com>
Cc: virtualization@lists.linux.dev,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Eugenio Perez" <eperezma@redhat.com>
Subject: Re: [PATCH 2/2] tools/virtio: vringh_test: check that a split ring must be a power of two
Date: Wed, 11 Nov 2026 17:42:04 +0000	[thread overview]
Message-ID: <sashiko-outbox-209429@kernel.org> (raw)
In-Reply-To: <20261111172947.3579982-3-stjepan.poljak@gmail.com>

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Medium] tools/virtio: memory leak of virtqueue in main() [1]
--

commit dacd77c2e0af2c3d6ebdce34137950d56c8f8e41
Author: Stjepan Poljak <stjepan.poljak@gmail.com>

tools/virtio: vringh_test: check that a split ring must be a power of two

This commit adds a check in vringh_test to verify that
vring_new_virtqueue() rejects a non-power-of-two split ring size.

> diff --git a/tools/virtio/vringh_test.c b/tools/virtio/vringh_test.c
> index 2a5d7f7d2d6ce..75c66385502de 100644
> --- a/tools/virtio/vringh_test.c
> +++ b/tools/virtio/vringh_test.c
> @@ -494,6 +494,17 @@ int main(int argc, char *argv[])
>  	__user_addr_max = __user_addr_min + USER_MEM;
>  	memset(__user_addr_min, 0, vring_size(RINGSIZE, ALIGN));
>  
> +	/*
> +	 * The split ring indexes its rings with num - 1 as a mask, so a
> +	 * size that is not a power of two must be refused.
> +	 */
> +	vq = vring_new_virtqueue(0, RINGSIZE - 1, ALIGN, &vdev, true, false,
> +				 __user_addr_min,
> +				 never_notify_host, never_callback_guest,
> +				 "guest vq");
> +	if (vq)
> +		errx(1, "vring_new_virtqueue accepted size %u", RINGSIZE - 1);
> +
>  	/* Set up guest side. */
>  	vq = vring_new_virtqueue(0, RINGSIZE, ALIGN, &vdev, true, false,
>  				 __user_addr_min,

[Severity: Medium]
This problem wasn't introduced by this patch, but does main() leak vq
[1] when running with --indirect?

Later in main(), the VIRTIO_RING_F_INDIRECT_DESC test branch reassigns vq
without calling vring_del_virtqueue(vq) first:

tools/virtio/vringh_test.c:main() {
	...
	if (__virtio_test_bit(&vdev, VIRTIO_RING_F_INDIRECT_DESC)) {
		...
		__virtio_clear_bit(&vdev, VIRTIO_RING_F_INDIRECT_DESC);
		vq = vring_new_virtqueue(0, RINGSIZE, ALIGN, &vdev, true,
					 false, __user_addr_min,
					 never_notify_host,
					 never_callback_guest,
					 "guest vq");
	...
}

This leaks the initial virtqueue and leaves it linked on vdev.vqs when the
cleanup path at the end of main() only deletes the second vq.

[1] https://sashiko.dev/#/bug/linux-e99ea9bc-10be-4c6a-b7f2-1998001de64b

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261111172947.3579982-1-stjepan.poljak@gmail.com?part=2

      reply	other threads:[~2026-11-11 17:42 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-11 17:29 [PATCH 0/2] virtio_ring: reject a split ring size that is not a power of two again Stjepan Poljak
2026-11-11 17:29 ` [PATCH 1/2] " Stjepan Poljak
2026-11-11 17:38   ` sashiko-bot
2026-11-11 21:51   ` Francesco Valla
2026-11-12 15:58     ` Stjepan Poljak
2026-11-11 17:29 ` [PATCH 2/2] tools/virtio: vringh_test: check that a split ring must be a power of two Stjepan Poljak
2026-11-11 17:42   ` 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-209429@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=eperezma@redhat.com \
    --cc=mst@redhat.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=stjepan.poljak@gmail.com \
    --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.