qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/3] virtio-net: fix max vring buf size when set ring num


From: liuhaiwei
Subject: [PATCH 1/3] virtio-net: fix max vring buf size when set ring num
Date: Mon, 19 Sep 2022 05:39:13 -0400

Signed-off-by: liuhaiwei <liuhaiwei9699@126.com>
---
 hw/virtio/virtio.c         | 10 +++++++---
 include/hw/virtio/virtio.h |  1 +
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 5d607aeaa0..d93c20d747 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -2286,13 +2286,17 @@ void virtio_queue_set_rings(VirtIODevice *vdev, int n, 
hwaddr desc,
 
 void virtio_queue_set_num(VirtIODevice *vdev, int n, int num)
 {
+    int vq_max_size = VIRTQUEUE_MAX_SIZE;
+    if (!strcmp(vdev->name, "virtio-net")) {
+        vq_max_size = VIRTIO_NET_VQ_MAX_SIZE;
+    }
+
     /* Don't allow guest to flip queue between existent and
      * nonexistent states, or to set it to an invalid size.
      */
     if (!!num != !!vdev->vq[n].vring.num ||
-        num > VIRTQUEUE_MAX_SIZE ||
-        num < 0) {
-        return;
+        num > vq_max_size || num < 0) {
+           return;
     }
     vdev->vq[n].vring.num = num;
 }
diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
index db1c0ddf6b..1f4d2eb5d7 100644
--- a/include/hw/virtio/virtio.h
+++ b/include/hw/virtio/virtio.h
@@ -50,6 +50,7 @@ size_t virtio_feature_get_config_size(const VirtIOFeature 
*features,
 typedef struct VirtQueue VirtQueue;
 
 #define VIRTQUEUE_MAX_SIZE 1024
+#define VIRTIO_NET_VQ_MAX_SIZE (4096)
 
 typedef struct VirtQueueElement
 {
-- 
2.27.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]