[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL v2 39/44] virtio-net: vhost control virtqueue support
From: |
Michael S. Tsirkin |
Subject: |
[PULL v2 39/44] virtio-net: vhost control virtqueue support |
Date: |
Wed, 20 Oct 2021 06:21:00 -0400 |
From: Jason Wang <jasowang@redhat.com>
This patch implements the control virtqueue support for vhost. This
requires virtio-net to figure out the datapath queue pairs and control
virtqueue via is_datapath and pass the number of those two types
of virtqueues to vhost_net_start()/vhost_net_stop().
Signed-off-by: Jason Wang <jasowang@redhat.com>
Message-Id: <20211020045600.16082-10-jasowang@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
include/hw/virtio/virtio-net.h | 1 +
hw/net/vhost_net.c | 2 +-
hw/net/virtio-net.c | 23 +++++++++++++++++++----
3 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h
index 2903b79a92..eb87032627 100644
--- a/include/hw/virtio/virtio-net.h
+++ b/include/hw/virtio/virtio-net.h
@@ -196,6 +196,7 @@ struct VirtIONet {
int multiqueue;
uint16_t max_queue_pairs;
uint16_t curr_queue_pairs;
+ uint16_t max_ncs;
size_t config_size;
char *netclient_name;
char *netclient_type;
diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
index 3aabab06ea..0d888f29a6 100644
--- a/hw/net/vhost_net.c
+++ b/hw/net/vhost_net.c
@@ -326,7 +326,7 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
VirtIONet *n = VIRTIO_NET(dev);
int nvhosts = data_queue_pairs + cvq;
struct vhost_net *net;
- int r, e, i, last_index = data_qps * 2;
+ int r, e, i, last_index = data_queue_pairs * 2;
NetClientState *peer;
if (!cvq) {
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 7594f7ea92..f2014d5ea0 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -244,6 +244,7 @@ static void virtio_net_vhost_status(VirtIONet *n, uint8_t
status)
VirtIODevice *vdev = VIRTIO_DEVICE(n);
NetClientState *nc = qemu_get_queue(n->nic);
int queue_pairs = n->multiqueue ? n->max_queue_pairs : 1;
+ int cvq = n->max_ncs - n->max_queue_pairs;
if (!get_vhost_net(nc->peer)) {
return;
@@ -285,14 +286,14 @@ static void virtio_net_vhost_status(VirtIONet *n, uint8_t
status)
}
n->vhost_started = 1;
- r = vhost_net_start(vdev, n->nic->ncs, queue_pairs, 0);
+ r = vhost_net_start(vdev, n->nic->ncs, queue_pairs, cvq);
if (r < 0) {
error_report("unable to start vhost net: %d: "
"falling back on userspace virtio", -r);
n->vhost_started = 0;
}
} else {
- vhost_net_stop(vdev, n->nic->ncs, queue_pairs, 0);
+ vhost_net_stop(vdev, n->nic->ncs, queue_pairs, cvq);
n->vhost_started = 0;
}
}
@@ -3411,9 +3412,23 @@ static void virtio_net_device_realize(DeviceState *dev,
Error **errp)
return;
}
- n->max_queue_pairs = MAX(n->nic_conf.peers.queues, 1);
+ n->max_ncs = MAX(n->nic_conf.peers.queues, 1);
+
+ /*
+ * Figure out the datapath queue pairs since the backend could
+ * provide control queue via peers as well.
+ */
+ if (n->nic_conf.peers.queues) {
+ for (i = 0; i < n->max_ncs; i++) {
+ if (n->nic_conf.peers.ncs[i]->is_datapath) {
+ ++n->max_queue_pairs;
+ }
+ }
+ }
+ n->max_queue_pairs = MAX(n->max_queue_pairs, 1);
+
if (n->max_queue_pairs * 2 + 1 > VIRTIO_QUEUE_MAX) {
- error_setg(errp, "Invalid number of queue_pairs (= %" PRIu32 "), "
+ error_setg(errp, "Invalid number of queue pairs (= %" PRIu32 "), "
"must be a positive integer less than %d.",
n->max_queue_pairs, (VIRTIO_QUEUE_MAX - 1) / 2);
virtio_cleanup(vdev);
--
MST
- [PULL v2 30/44] bios-tables-test: don't disassemble empty files, (continued)
- [PULL v2 30/44] bios-tables-test: don't disassemble empty files, Michael S. Tsirkin, 2021/10/20
- [PULL v2 28/44] qdev/qbus: remove failover specific code, Michael S. Tsirkin, 2021/10/20
- [PULL v2 33/44] vhost-vdpa: prepare for the multiqueue support, Michael S. Tsirkin, 2021/10/20
- [PULL v2 32/44] vhost-vdpa: classify one time request, Michael S. Tsirkin, 2021/10/20
- [PULL v2 34/44] vhost-vdpa: let net_vhost_vdpa_init() returns NetClientState *, Michael S. Tsirkin, 2021/10/20
- [PULL v2 31/44] vhost-vdpa: open device fd in net_init_vhost_vdpa(), Michael S. Tsirkin, 2021/10/20
- [PULL v2 36/44] vhost-net: control virtqueue support, Michael S. Tsirkin, 2021/10/20
- [PULL v2 35/44] net: introduce control client, Michael S. Tsirkin, 2021/10/20
- [PULL v2 37/44] virtio-net: use "queue_pairs" instead of "queues" when possible, Michael S. Tsirkin, 2021/10/20
- [PULL v2 38/44] vhost: record the last virtqueue index for the virtio device, Michael S. Tsirkin, 2021/10/20
- [PULL v2 39/44] virtio-net: vhost control virtqueue support,
Michael S. Tsirkin <=
- [PULL v2 40/44] vhost-vdpa: multiqueue support, Michael S. Tsirkin, 2021/10/20
- [PULL v2 42/44] tests/acpi/bios-tables-test: add and allow changes to a new q35 DSDT table blob, Michael S. Tsirkin, 2021/10/20
- [PULL v2 41/44] pci: fix PCI resource reserve capability on BE, Michael S. Tsirkin, 2021/10/20
- [PULL v2 43/44] tests/acpi/pcihp: add unit tests for hotplug on multifunction bridges for q35, Michael S. Tsirkin, 2021/10/20
- [PULL v2 44/44] tests/acpi/bios-tables-test: update DSDT blob for multifunction bridge test, Michael S. Tsirkin, 2021/10/20
- Re: [PULL v2 00/44] pc,pci,virtio: features, fixes, tests, Richard Henderson, 2021/10/20