[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 1/3] virtio-net: fix max vring buf size when set ring num
From: |
Michael S. Tsirkin |
Subject: |
Re: [PATCH 1/3] virtio-net: fix max vring buf size when set ring num |
Date: |
Mon, 19 Sep 2022 06:21:54 -0400 |
On Mon, Sep 19, 2022 at 05:39:13AM -0400, liuhaiwei wrote:
Pls write a commit log. Explain what is this patch fixing
and why this is the correct fix.
> Signed-off-by: liuhaiwei <liuhaiwei9699@126.com>
Please use your full first and last name.
No anonymous contributions.
> ---
> 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;
> + }
> +
Any less ugly ways to do this?
> /* 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