From: Francesco Valla <francesco@valla.it>
To: Stjepan Poljak <stjepan.poljak@gmail.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
"Jason Wang" <jasowangio@gmail.com>,
"Eugenio Pérez" <eperezma@redhat.com>,
"Xuan Zhuo" <xuanzhuo@linux.alibaba.com>,
"Andy Lutomirski" <luto@kernel.org>,
"Bjorn Andersson" <andersson@kernel.org>,
"Mathieu Poirier" <mathieu.poirier@linaro.org>,
virtualization@lists.linux.dev, linux-remoteproc@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/2] virtio_ring: reject a split ring size that is not a power of two again
Date: Sat, 14 Nov 2026 08:57:55 +0100 [thread overview]
Message-ID: <avgUMQjBDIGskHBK@bywater> (raw)
In-Reply-To: <20261112154927.4004184-2-stjepan.poljak@gmail.com>
On Thu, Nov 12, 2026 at 04:49:16PM +0100, Stjepan Poljak wrote:
> The split ring indexes its avail and used rings with num - 1 as a mask,
> so its size must be a power of two. Commit 2a2d1382fe9d ("virtio: Add
> improved queue allocation API") moved that check from
> vring_new_virtqueue() into the new allocation path, which
> vring_new_virtqueue() does not use.
>
> remoteproc calls vring_new_virtqueue() with a ring size from the
> firmware, checked only to be non-zero. With 100 entries, for example,
> the driver would put buffers 4 and 8 in avail slot 0. The device would
> look for them at slots 4 and 8, possibly reading the wrong data.
>
> Put the check back for the split ring; the packed ring has no such
> restriction.
>
> Fixes: 2a2d1382fe9d ("virtio: Add improved queue allocation API")
> Signed-off-by: Stjepan Poljak <stjepan.poljak@gmail.com>
> ---
> remoteproc still reports this as -ENOMEM, although the "Bad virtqueue
> length" error names the cause. Returning an error pointer from
> vring_new_virtqueue() is left for later; the same change for
> vring_create_virtqueue() is here:
> https://lore.kernel.org/r/20261106055635.3019889-1-stjepan.poljak@gmail.com
>
> v2:
> - Log with dev_err() rather than dev_warn(), and say in the message why
> the length is bad (Francesco)
> ---
> drivers/virtio/virtio_ring.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
> index f683a2d6a200..f855b8d41575 100644
> --- a/drivers/virtio/virtio_ring.c
> +++ b/drivers/virtio/virtio_ring.c
> @@ -3513,6 +3513,13 @@ struct virtqueue *vring_new_virtqueue(unsigned int index,
> name, map);
> }
>
> + /* The split ring indexes its rings with num - 1 as a mask. */
> + if (!is_power_of_2(num)) {
> + dev_err(&vdev->dev,
> + "Bad virtqueue length %u (not a power of two)\n", num);
> + return NULL;
> + }
> +
> vring_init(&vring_split.vring, num, pages, vring_align);
> return __vring_new_virtqueue_split(index, &vring_split, vdev, weak_barriers,
> context, notify, callback, name,
> --
> 2.53.0
>
Reviewed-by: Francesco Valla <francesco@valla.it>
Tested-by: Francesco Valla <francesco@valla.it> # AM67A, rpmsg with R5F
next prev parent reply other threads:[~2026-11-14 7:58 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-12 15:49 [PATCH v2 0/2] virtio_ring: reject a split ring size that is not a power of two again Stjepan Poljak
2026-11-12 15:49 ` [PATCH v2 1/2] " Stjepan Poljak
2026-11-14 7:57 ` Francesco Valla [this message]
2026-11-12 15:49 ` [PATCH v2 2/2] tools/virtio: vringh_test: check that a split ring must be a power of two Stjepan Poljak
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=avgUMQjBDIGskHBK@bywater \
--to=francesco@valla.it \
--cc=andersson@kernel.org \
--cc=eperezma@redhat.com \
--cc=jasowangio@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-remoteproc@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mathieu.poirier@linaro.org \
--cc=mst@redhat.com \
--cc=stjepan.poljak@gmail.com \
--cc=virtualization@lists.linux.dev \
--cc=xuanzhuo@linux.alibaba.com \
/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.