vring_new_virtqueue() used to accept a split ring of any size, although
the ring is indexed with num - 1 as a mask. Check that it now refuses
one size short of RINGSIZE.

Without the preceding fix, vringh_test fails with:

  vringh_test: vring_new_virtqueue accepted size 255

With it, vring_new_virtqueue() prints:

  Bad virtqueue length 255 (not a power of two)

and the rest of the test runs as before.

Signed-off-by: Stjepan Poljak <[email protected]>
---
 tools/virtio/vringh_test.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/tools/virtio/vringh_test.c b/tools/virtio/vringh_test.c
index 2a5d7f7d2d6c..75c66385502d 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,
-- 
2.53.0


Reply via email to