* [PATCH 1/3] virtio-net: fix max vring buf size when set ring num @ 2022-09-19 9:39 liuhaiwei 2022-09-19 9:39 ` [PATCH 2/3] virtio-net: update the default and max of rx/tx_queue_size liuhaiwei ` (2 more replies) 0 siblings, 3 replies; 6+ messages in thread From: liuhaiwei @ 2022-09-19 9:39 UTC (permalink / raw) To: qemu-devel; +Cc: mst, jasowang, liuhaiwei 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 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/3] virtio-net: update the default and max of rx/tx_queue_size 2022-09-19 9:39 [PATCH 1/3] virtio-net: fix max vring buf size when set ring num liuhaiwei @ 2022-09-19 9:39 ` liuhaiwei 2022-09-19 10:22 ` Michael S. Tsirkin 2022-09-19 9:39 ` [PATCH 3/3] virtio-net: set the max of queue size to 4096 liuhaiwei 2022-09-19 10:21 ` [PATCH 1/3] virtio-net: fix max vring buf size when set ring num Michael S. Tsirkin 2 siblings, 1 reply; 6+ messages in thread From: liuhaiwei @ 2022-09-19 9:39 UTC (permalink / raw) To: qemu-devel; +Cc: mst, jasowang, liuhaiwei Set the max of tx_queue_size to 4096 even if the backends are not vhost-user. Set the default of rx/tx_queue_size to 2048 if the backends are vhost-user, otherwise to 4096. Signed-off-by: liuhaiwei <liuhaiwei9699@126.com> --- hw/net/virtio-net.c | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index dd0d056fde..d63ef24e6a 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -52,12 +52,11 @@ #define MAX_VLAN (1 << 12) /* Per 802.1Q definition */ /* previously fixed value */ -#define VIRTIO_NET_RX_QUEUE_DEFAULT_SIZE 256 -#define VIRTIO_NET_TX_QUEUE_DEFAULT_SIZE 256 +#define VIRTIO_NET_VHOST_USER_DEFAULT_SIZE 2048 /* for now, only allow larger queue_pairs; with virtio-1, guest can downsize */ -#define VIRTIO_NET_RX_QUEUE_MIN_SIZE VIRTIO_NET_RX_QUEUE_DEFAULT_SIZE -#define VIRTIO_NET_TX_QUEUE_MIN_SIZE VIRTIO_NET_TX_QUEUE_DEFAULT_SIZE +#define VIRTIO_NET_RX_QUEUE_MIN_SIZE 256 +#define VIRTIO_NET_TX_QUEUE_MIN_SIZE 256 #define VIRTIO_NET_IP4_ADDR_SIZE 8 /* ipv4 saddr + daddr */ @@ -593,6 +592,28 @@ static int peer_has_ufo(VirtIONet *n) return n->has_ufo; } +static void virtio_net_set_default_queue_size(VirtIONet *n) +{ + NetClientState *peer = n->nic_conf.peers.ncs[0]; + + /* Default value is 0 if not set */ + if (n->net_conf.rx_queue_size == 0) { + if (peer && peer->info->type == NET_CLIENT_DRIVER_VHOST_USER) { + n->net_conf.rx_queue_size = VIRTIO_NET_VHOST_USER_DEFAULT_SIZE; + } else { + n->net_conf.rx_queue_size = VIRTIO_NET_VQ_MAX_SIZE; + } + } + + if (n->net_conf.tx_queue_size == 0) { + if (peer && peer->info->type == NET_CLIENT_DRIVER_VHOST_USER) { + n->net_conf.tx_queue_size = VIRTIO_NET_VHOST_USER_DEFAULT_SIZE; + } else { + n->net_conf.tx_queue_size = VIRTIO_NET_VQ_MAX_SIZE; + } + } +} + static void virtio_net_set_mrg_rx_bufs(VirtIONet *n, int mergeable_rx_bufs, int version_1, int hash_report) @@ -633,7 +654,7 @@ static int virtio_net_max_tx_queue_size(VirtIONet *n) * size. */ if (!peer) { - return VIRTIO_NET_TX_QUEUE_DEFAULT_SIZE; + return VIRTIO_NET_VQ_MAX_SIZE; } switch(peer->info->type) { @@ -641,7 +662,7 @@ static int virtio_net_max_tx_queue_size(VirtIONet *n) case NET_CLIENT_DRIVER_VHOST_VDPA: return VIRTQUEUE_MAX_SIZE; default: - return VIRTIO_NET_TX_QUEUE_DEFAULT_SIZE; + return VIRTIO_NET_VQ_MAX_SIZE; }; } @@ -3450,6 +3471,7 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp) virtio_net_set_config_size(n, n->host_features); virtio_init(vdev, VIRTIO_ID_NET, n->config_size); + virtio_net_set_default_queue_size(n); /* * We set a lower limit on RX queue size to what it always was. @@ -3750,10 +3772,8 @@ static Property virtio_net_properties[] = { TX_TIMER_INTERVAL), DEFINE_PROP_INT32("x-txburst", VirtIONet, net_conf.txburst, TX_BURST), DEFINE_PROP_STRING("tx", VirtIONet, net_conf.tx), - DEFINE_PROP_UINT16("rx_queue_size", VirtIONet, net_conf.rx_queue_size, - VIRTIO_NET_RX_QUEUE_DEFAULT_SIZE), - DEFINE_PROP_UINT16("tx_queue_size", VirtIONet, net_conf.tx_queue_size, - VIRTIO_NET_TX_QUEUE_DEFAULT_SIZE), + DEFINE_PROP_UINT16("rx_queue_size", VirtIONet, net_conf.rx_queue_size, 0), + DEFINE_PROP_UINT16("tx_queue_size", VirtIONet, net_conf.tx_queue_size, 0), DEFINE_PROP_UINT16("host_mtu", VirtIONet, net_conf.mtu, 0), DEFINE_PROP_BOOL("x-mtu-bypass-backend", VirtIONet, mtu_bypass_backend, true), -- 2.27.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 2/3] virtio-net: update the default and max of rx/tx_queue_size 2022-09-19 9:39 ` [PATCH 2/3] virtio-net: update the default and max of rx/tx_queue_size liuhaiwei @ 2022-09-19 10:22 ` Michael S. Tsirkin 0 siblings, 0 replies; 6+ messages in thread From: Michael S. Tsirkin @ 2022-09-19 10:22 UTC (permalink / raw) To: liuhaiwei; +Cc: qemu-devel, jasowang On Mon, Sep 19, 2022 at 05:39:14AM -0400, liuhaiwei wrote: > Set the max of tx_queue_size to 4096 even if the backends > are not vhost-user. > > Set the default of rx/tx_queue_size to 2048 if the backends > are vhost-user, otherwise to 4096. > > Signed-off-by: liuhaiwei <liuhaiwei9699@126.com> Pls include motivation for the change. A change like this will also need compat knobs to avoid breaking old machine types. > --- > hw/net/virtio-net.c | 40 ++++++++++++++++++++++++++++++---------- > 1 file changed, 30 insertions(+), 10 deletions(-) > > diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c > index dd0d056fde..d63ef24e6a 100644 > --- a/hw/net/virtio-net.c > +++ b/hw/net/virtio-net.c > @@ -52,12 +52,11 @@ > #define MAX_VLAN (1 << 12) /* Per 802.1Q definition */ > > /* previously fixed value */ > -#define VIRTIO_NET_RX_QUEUE_DEFAULT_SIZE 256 > -#define VIRTIO_NET_TX_QUEUE_DEFAULT_SIZE 256 > +#define VIRTIO_NET_VHOST_USER_DEFAULT_SIZE 2048 > > /* for now, only allow larger queue_pairs; with virtio-1, guest can downsize */ > -#define VIRTIO_NET_RX_QUEUE_MIN_SIZE VIRTIO_NET_RX_QUEUE_DEFAULT_SIZE > -#define VIRTIO_NET_TX_QUEUE_MIN_SIZE VIRTIO_NET_TX_QUEUE_DEFAULT_SIZE > +#define VIRTIO_NET_RX_QUEUE_MIN_SIZE 256 > +#define VIRTIO_NET_TX_QUEUE_MIN_SIZE 256 > > #define VIRTIO_NET_IP4_ADDR_SIZE 8 /* ipv4 saddr + daddr */ > > @@ -593,6 +592,28 @@ static int peer_has_ufo(VirtIONet *n) > > return n->has_ufo; > } > +static void virtio_net_set_default_queue_size(VirtIONet *n) > +{ > + NetClientState *peer = n->nic_conf.peers.ncs[0]; > + > + /* Default value is 0 if not set */ > + if (n->net_conf.rx_queue_size == 0) { > + if (peer && peer->info->type == NET_CLIENT_DRIVER_VHOST_USER) { > + n->net_conf.rx_queue_size = VIRTIO_NET_VHOST_USER_DEFAULT_SIZE; > + } else { > + n->net_conf.rx_queue_size = VIRTIO_NET_VQ_MAX_SIZE; > + } > + } > + > + if (n->net_conf.tx_queue_size == 0) { > + if (peer && peer->info->type == NET_CLIENT_DRIVER_VHOST_USER) { > + n->net_conf.tx_queue_size = VIRTIO_NET_VHOST_USER_DEFAULT_SIZE; > + } else { > + n->net_conf.tx_queue_size = VIRTIO_NET_VQ_MAX_SIZE; > + } > + } > +} > + > > static void virtio_net_set_mrg_rx_bufs(VirtIONet *n, int mergeable_rx_bufs, > int version_1, int hash_report) > @@ -633,7 +654,7 @@ static int virtio_net_max_tx_queue_size(VirtIONet *n) > * size. > */ > if (!peer) { > - return VIRTIO_NET_TX_QUEUE_DEFAULT_SIZE; > + return VIRTIO_NET_VQ_MAX_SIZE; > } > > switch(peer->info->type) { > @@ -641,7 +662,7 @@ static int virtio_net_max_tx_queue_size(VirtIONet *n) > case NET_CLIENT_DRIVER_VHOST_VDPA: > return VIRTQUEUE_MAX_SIZE; > default: > - return VIRTIO_NET_TX_QUEUE_DEFAULT_SIZE; > + return VIRTIO_NET_VQ_MAX_SIZE; > }; > } > > @@ -3450,6 +3471,7 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp) > > virtio_net_set_config_size(n, n->host_features); > virtio_init(vdev, VIRTIO_ID_NET, n->config_size); > + virtio_net_set_default_queue_size(n); > > /* > * We set a lower limit on RX queue size to what it always was. > @@ -3750,10 +3772,8 @@ static Property virtio_net_properties[] = { > TX_TIMER_INTERVAL), > DEFINE_PROP_INT32("x-txburst", VirtIONet, net_conf.txburst, TX_BURST), > DEFINE_PROP_STRING("tx", VirtIONet, net_conf.tx), > - DEFINE_PROP_UINT16("rx_queue_size", VirtIONet, net_conf.rx_queue_size, > - VIRTIO_NET_RX_QUEUE_DEFAULT_SIZE), > - DEFINE_PROP_UINT16("tx_queue_size", VirtIONet, net_conf.tx_queue_size, > - VIRTIO_NET_TX_QUEUE_DEFAULT_SIZE), > + DEFINE_PROP_UINT16("rx_queue_size", VirtIONet, net_conf.rx_queue_size, 0), > + DEFINE_PROP_UINT16("tx_queue_size", VirtIONet, net_conf.tx_queue_size, 0), > DEFINE_PROP_UINT16("host_mtu", VirtIONet, net_conf.mtu, 0), > DEFINE_PROP_BOOL("x-mtu-bypass-backend", VirtIONet, mtu_bypass_backend, > true), > -- > 2.27.0 ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 3/3] virtio-net: set the max of queue size to 4096 2022-09-19 9:39 [PATCH 1/3] virtio-net: fix max vring buf size when set ring num liuhaiwei 2022-09-19 9:39 ` [PATCH 2/3] virtio-net: update the default and max of rx/tx_queue_size liuhaiwei @ 2022-09-19 9:39 ` liuhaiwei 2022-09-19 10:23 ` Michael S. Tsirkin 2022-09-19 10:21 ` [PATCH 1/3] virtio-net: fix max vring buf size when set ring num Michael S. Tsirkin 2 siblings, 1 reply; 6+ messages in thread From: liuhaiwei @ 2022-09-19 9:39 UTC (permalink / raw) To: qemu-devel; +Cc: mst, jasowang, liuhaiwei Signed-off-by: liuhaiwei <liuhaiwei9699@126.com> --- hw/net/virtio-net.c | 8 ++++---- hw/virtio/virtio.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index d63ef24e6a..df16995146 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -3479,23 +3479,23 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp) * help from us (using virtio 1 and up). */ if (n->net_conf.rx_queue_size < VIRTIO_NET_RX_QUEUE_MIN_SIZE || - n->net_conf.rx_queue_size > VIRTQUEUE_MAX_SIZE || + n->net_conf.rx_queue_size > VIRTIO_NET_VQ_MAX_SIZE || !is_power_of_2(n->net_conf.rx_queue_size)) { error_setg(errp, "Invalid rx_queue_size (= %" PRIu16 "), " "must be a power of 2 between %d and %d.", n->net_conf.rx_queue_size, VIRTIO_NET_RX_QUEUE_MIN_SIZE, - VIRTQUEUE_MAX_SIZE); + VIRTIO_NET_VQ_MAX_SIZE); virtio_cleanup(vdev); return; } if (n->net_conf.tx_queue_size < VIRTIO_NET_TX_QUEUE_MIN_SIZE || - n->net_conf.tx_queue_size > VIRTQUEUE_MAX_SIZE || + n->net_conf.tx_queue_size > VIRTIO_NET_VQ_MAX_SIZE || !is_power_of_2(n->net_conf.tx_queue_size)) { error_setg(errp, "Invalid tx_queue_size (= %" PRIu16 "), " "must be a power of 2 between %d and %d", n->net_conf.tx_queue_size, VIRTIO_NET_TX_QUEUE_MIN_SIZE, - VIRTQUEUE_MAX_SIZE); + VIRTIO_NET_VQ_MAX_SIZE ); virtio_cleanup(vdev); return; } diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index d93c20d747..2f0c99e357 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -2427,7 +2427,7 @@ VirtQueue *virtio_add_queue(VirtIODevice *vdev, int queue_size, break; } - if (i == VIRTIO_QUEUE_MAX || queue_size > VIRTQUEUE_MAX_SIZE) + if (i == VIRTIO_QUEUE_MAX ) abort(); vdev->vq[i].vring.num = queue_size; -- 2.27.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 3/3] virtio-net: set the max of queue size to 4096 2022-09-19 9:39 ` [PATCH 3/3] virtio-net: set the max of queue size to 4096 liuhaiwei @ 2022-09-19 10:23 ` Michael S. Tsirkin 0 siblings, 0 replies; 6+ messages in thread From: Michael S. Tsirkin @ 2022-09-19 10:23 UTC (permalink / raw) To: liuhaiwei; +Cc: qemu-devel, jasowang same comments as other patches. besides ... On Mon, Sep 19, 2022 at 05:39:15AM -0400, liuhaiwei wrote: > Signed-off-by: liuhaiwei <liuhaiwei9699@126.com> > --- > hw/net/virtio-net.c | 8 ++++---- > hw/virtio/virtio.c | 2 +- > 2 files changed, 5 insertions(+), 5 deletions(-) coding style violations all over the place > > diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c > index d63ef24e6a..df16995146 100644 > --- a/hw/net/virtio-net.c > +++ b/hw/net/virtio-net.c > @@ -3479,23 +3479,23 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp) > * help from us (using virtio 1 and up). > */ > if (n->net_conf.rx_queue_size < VIRTIO_NET_RX_QUEUE_MIN_SIZE || > - n->net_conf.rx_queue_size > VIRTQUEUE_MAX_SIZE || > + n->net_conf.rx_queue_size > VIRTIO_NET_VQ_MAX_SIZE || > !is_power_of_2(n->net_conf.rx_queue_size)) { > error_setg(errp, "Invalid rx_queue_size (= %" PRIu16 "), " > "must be a power of 2 between %d and %d.", > n->net_conf.rx_queue_size, VIRTIO_NET_RX_QUEUE_MIN_SIZE, > - VIRTQUEUE_MAX_SIZE); > + VIRTIO_NET_VQ_MAX_SIZE); > virtio_cleanup(vdev); > return; > } > > if (n->net_conf.tx_queue_size < VIRTIO_NET_TX_QUEUE_MIN_SIZE || > - n->net_conf.tx_queue_size > VIRTQUEUE_MAX_SIZE || > + n->net_conf.tx_queue_size > VIRTIO_NET_VQ_MAX_SIZE || > !is_power_of_2(n->net_conf.tx_queue_size)) { > error_setg(errp, "Invalid tx_queue_size (= %" PRIu16 "), " > "must be a power of 2 between %d and %d", > n->net_conf.tx_queue_size, VIRTIO_NET_TX_QUEUE_MIN_SIZE, > - VIRTQUEUE_MAX_SIZE); > + VIRTIO_NET_VQ_MAX_SIZE ); > virtio_cleanup(vdev); > return; > } > diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c > index d93c20d747..2f0c99e357 100644 > --- a/hw/virtio/virtio.c > +++ b/hw/virtio/virtio.c > @@ -2427,7 +2427,7 @@ VirtQueue *virtio_add_queue(VirtIODevice *vdev, int queue_size, > break; > } > > - if (i == VIRTIO_QUEUE_MAX || queue_size > VIRTQUEUE_MAX_SIZE) > + if (i == VIRTIO_QUEUE_MAX ) > abort(); > > vdev->vq[i].vring.num = queue_size; > -- > 2.27.0 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/3] virtio-net: fix max vring buf size when set ring num 2022-09-19 9:39 [PATCH 1/3] virtio-net: fix max vring buf size when set ring num liuhaiwei 2022-09-19 9:39 ` [PATCH 2/3] virtio-net: update the default and max of rx/tx_queue_size liuhaiwei 2022-09-19 9:39 ` [PATCH 3/3] virtio-net: set the max of queue size to 4096 liuhaiwei @ 2022-09-19 10:21 ` Michael S. Tsirkin 2 siblings, 0 replies; 6+ messages in thread From: Michael S. Tsirkin @ 2022-09-19 10:21 UTC (permalink / raw) To: liuhaiwei; +Cc: qemu-devel, jasowang 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 ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-09-19 10:41 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2022-09-19 9:39 [PATCH 1/3] virtio-net: fix max vring buf size when set ring num liuhaiwei 2022-09-19 9:39 ` [PATCH 2/3] virtio-net: update the default and max of rx/tx_queue_size liuhaiwei 2022-09-19 10:22 ` Michael S. Tsirkin 2022-09-19 9:39 ` [PATCH 3/3] virtio-net: set the max of queue size to 4096 liuhaiwei 2022-09-19 10:23 ` Michael S. Tsirkin 2022-09-19 10:21 ` [PATCH 1/3] virtio-net: fix max vring buf size when set ring num Michael S. Tsirkin
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).