Skip to contentSkip to conversation

vhost-vDPA multiqueue

PATCH Superseded Jason Wang 2 participants 23 messages Jul 6, 2021 – Jul 15, 2021 2 messages not in the archive Networking

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Jason Wang

author
#0 lore raw

v2 cover vhost-vDPA multiqueue

Hi All:

This patch implements the multiqueue support for vhost-vDPA. The most important requirement the control virtqueue support. The virtio-net and vhost-net core are tweak to support control virtqueue as if what data queue pairs are done: a dedicated vhost_net device which is coupled with the NetClientState is intrdouced so most of the existing vhost codes could be reused with minor changes. With the control virtqueue, vhost-vDPA are extend to support creating and destroying multiqueue queue pairs plus the control virtqueue.

Tests are done via the vp_vdpa driver in L1 guest plus vdpa simulator on L0.

Please reivew.

Changes since V1:

- validating all features that depends on ctrl vq
- typo fixes and commit log tweaks
- fix build errors because max_qps is used before it is introduced

Thanks

Jason Wang (18):
vhost_net: remove the meaningless assignment in vhost_net_start_one()
vhost: use unsigned int for nvqs
vhost_net: do not assume nvqs is always 2
vhost-vdpa: remove the unnecessary check in vhost_vdpa_add()
vhost-vdpa: don't cleanup twice in vhost_vdpa_add()
vhost-vdpa: fix leaking of vhost_net in vhost_vdpa_add()
vhost-vdpa: tweak the error label in vhost_vdpa_add()
vhost-vdpa: fix the wrong assertion in vhost_vdpa_init()
vhost-vdpa: remove the unncessary queue_index assignment
vhost-vdpa: open device fd in net_init_vhost_vdpa()
vhost-vdpa: classify one time request
vhost-vdpa: prepare for the multiqueue support
vhost-vdpa: let net_vhost_vdpa_init() returns NetClientState *
net: introduce control client
vhost-net: control virtqueue support
virito-net: use "qps" instead of "queues" when possible
virtio-net: vhost control virtqueue support
vhost-vdpa: multiqueue support

 hw/net/vhost_net.c             |  48 +++++++---
 hw/net/virtio-net.c            | 165 ++++++++++++++++++---------------
 hw/virtio/vhost-vdpa.c         |  55 ++++++++++-
 include/hw/virtio/vhost-vdpa.h |   1 +
 include/hw/virtio/vhost.h      |   2 +-
 include/hw/virtio/virtio-net.h |   5 +-
 include/net/net.h              |   5 +
 include/net/vhost_net.h        |   7 +-
 net/net.c                      |  24 ++++-
 net/tap.c                      |   1 +
 net/vhost-user.c               |   1 +
 net/vhost-vdpa.c               | 156 ++++++++++++++++++++++++-------
 12 files changed, 332 insertions(+), 138 deletions(-)
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH v2 1/18 vhost_net: remove the meaningless assignment in vhost_net_start_one()

The nvqs and vqs have been initialized during vhost_net_init() and are not expected to change during the life cycle of vhost_net structure. So this patch removes the meaningless assignment.

---
 hw/net/vhost_net.c | 3 ---
 1 file changed, 3 deletions(-)
hw/net/vhost_net.c +0 -3
index 44c1ed92dc..6bd4184f96 100644
@@ -238,9 +238,6 @@ static int vhost_net_start_one(struct vhost_net *net,
     struct vhost_vring_file file = { };
     int r;
 
-    net->dev.nvqs = 2;
-    net->dev.vqs = net->vqs;
-
     r = vhost_dev_enable_notifiers(&net->dev, dev);
     if (r < 0) {
         goto fail_notifiers;
Signature · 1 line
2.25.1
author
#2 lore raw

PATCH v2 2/18 vhost: use unsigned int for nvqs

In reply to Jason Wang

Switch to use unsigned int for nvqs since it's not expected to be negative.

---
 include/hw/virtio/vhost.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/hw/virtio/vhost.h +1 -1
index 21a9a52088..ddd7d3d594 100644
@@ -71,7 +71,7 @@ struct vhost_dev {
     int n_tmp_sections;
     MemoryRegionSection *tmp_sections;
     struct vhost_virtqueue *vqs;
-    int nvqs;
+    unsigned int nvqs;
     /* the first virtqueue which would be used by this vhost dev */
     int vq_index;
     /* if non-zero, minimum required value for max_queues */
Signature · 1 line
2.25.1
author
#3 lore raw

PATCH v2 3/18 vhost_net: do not assume nvqs is always 2

In reply to Jason Wang

This patch switches to initialize dev.nvqs from the VhostNetOptions instead of assuming it was 2. This is useful for implementing control virtqueue support which will be a single vhost_net structure with a single cvq.

Note that nvqs is still set to 2 for all users and this patch does not change functionality.

---
 hw/net/vhost_net.c      | 2 +-
 include/net/vhost_net.h | 1 +
 net/tap.c               | 1 +
 net/vhost-user.c        | 1 +
 net/vhost-vdpa.c        | 1 +
 5 files changed, 5 insertions(+), 1 deletion(-)
hw/net/vhost_net.c +1 -1
index 6bd4184f96..ef1370bd92 100644
@@ -163,9 +163,9 @@ struct vhost_net *vhost_net_init(VhostNetOptions *options)
         goto fail;
     }
     net->nc = options->net_backend;
+    net->dev.nvqs = options->nvqs;
 
     net->dev.max_queues = 1;
-    net->dev.nvqs = 2;
     net->dev.vqs = net->vqs;
 
     if (backend_kernel) {
include/net/vhost_net.h +1 -0
index 172b0051d8..fba40cf695 100644
@@ -14,6 +14,7 @@ typedef struct VhostNetOptions {
     VhostBackendType backend_type;
     NetClientState *net_backend;
     uint32_t busyloop_timeout;
+    unsigned int nvqs;
     void *opaque;
 } VhostNetOptions;
 
net/tap.c +1 -0
index f5686bbf77..f716be3e3f 100644
@@ -749,6 +749,7 @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
             qemu_set_nonblock(vhostfd);
         }
         options.opaque = (void *)(uintptr_t)vhostfd;
+        options.nvqs = 2;
 
         s->vhost_net = vhost_net_init(&options);
         if (!s->vhost_net) {
net/vhost-user.c +1 -0
index ffbd94d944..b93918c5a4 100644
@@ -85,6 +85,7 @@ static int vhost_user_start(int queues, NetClientState *ncs[],
         options.net_backend = ncs[i];
         options.opaque      = be;
         options.busyloop_timeout = 0;
+        options.nvqs = 2;
         net = vhost_net_init(&options);
         if (!net) {
             error_report("failed to init vhost_net for queue %d", i);
net/vhost-vdpa.c +1 -0
index 19187dce8c..18b45ad777 100644
@@ -105,6 +105,7 @@ static int vhost_vdpa_add(NetClientState *ncs, void *be)
     options.net_backend = ncs;
     options.opaque      = be;
     options.busyloop_timeout = 0;
+    options.nvqs = 2;
 
     net = vhost_net_init(&options);
     if (!net) {
Signature · 1 line
2.25.1
author
#4 lore raw

PATCH v2 4/18 vhost-vdpa: remove the unnecessary check in vhost_vdpa_add()

In reply to Jason Wang

The VhostVDPAState is just allocated by qemu_new_net_client() via g_malloc0() in net_vhost_vdpa_init(). So s->vhost_net is NULL for sure, let's remove this unnecessary check in vhost_vdpa_add().

---
 net/vhost-vdpa.c | 4 ----
 1 file changed, 4 deletions(-)
net/vhost-vdpa.c +0 -4
index 18b45ad777..728e63ff54 100644
@@ -112,10 +112,6 @@ static int vhost_vdpa_add(NetClientState *ncs, void *be)
         error_report("failed to init vhost_net for queue");
         goto err;
     }
-    if (s->vhost_net) {
-        vhost_net_cleanup(s->vhost_net);
-        g_free(s->vhost_net);
-    }
     s->vhost_net = net;
     ret = vhost_vdpa_net_check_device_id(net);
     if (ret) {
Signature · 1 line
2.25.1
author
#5 lore raw

PATCH v2 5/18 vhost-vdpa: don't cleanup twice in vhost_vdpa_add()

In reply to Jason Wang

The previous vhost_net_cleanup is sufficient for freeing, calling vhost_vdpa_del() in this case will lead an extra round of free. Note that this kind of "double free" is safe since vhost_dev_cleanup() zero the whole structure.

---
 net/vhost-vdpa.c | 11 -----------
 1 file changed, 11 deletions(-)
net/vhost-vdpa.c +0 -11
index 728e63ff54..f5689a7c32 100644
@@ -82,16 +82,6 @@ static int vhost_vdpa_net_check_device_id(struct vhost_net *net)
     return ret;
 }
 
-static void vhost_vdpa_del(NetClientState *ncs)
-{
-    VhostVDPAState *s;
-    assert(ncs->info->type == NET_CLIENT_DRIVER_VHOST_VDPA);
-    s = DO_UPCAST(VhostVDPAState, nc, ncs);
-    if (s->vhost_net) {
-        vhost_net_cleanup(s->vhost_net);
-    }
-}
-
 static int vhost_vdpa_add(NetClientState *ncs, void *be)
 {
     VhostNetOptions options;
@@ -122,7 +112,6 @@ err:
     if (net) {
         vhost_net_cleanup(net);
     }
-    vhost_vdpa_del(ncs);
     return -1;
 }
 
Signature · 1 line
2.25.1
author
#6 lore raw

PATCH v2 6/18 vhost-vdpa: fix leaking of vhost_net in vhost_vdpa_add()

In reply to Jason Wang
Fixes 1e0a84ea49b68 ("vhost-vdpa: introduce vhost-vdpa net client")
---
 net/vhost-vdpa.c | 1 +
 1 file changed, 1 insertion(+)
net/vhost-vdpa.c +1 -0
index f5689a7c32..21f09c546f 100644
@@ -111,6 +111,7 @@ static int vhost_vdpa_add(NetClientState *ncs, void *be)
 err:
     if (net) {
         vhost_net_cleanup(net);
+        g_free(net);
     }
     return -1;
 }
Signature · 1 line
2.25.1
author
#7 lore raw

PATCH v2 7/18 vhost-vdpa: tweak the error label in vhost_vdpa_add()

In reply to Jason Wang

Introduce new error label to avoid the unnecessary checking of net pointer.

Fixes 1e0a84ea49b68 ("vhost-vdpa: introduce vhost-vdpa net client")
---
 net/vhost-vdpa.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
net/vhost-vdpa.c +6 -7
index 21f09c546f..0da7bc347a 100644
@@ -100,19 +100,18 @@ static int vhost_vdpa_add(NetClientState *ncs, void *be)
     net = vhost_net_init(&options);
     if (!net) {
         error_report("failed to init vhost_net for queue");
-        goto err;
+        goto err_init;
     }
     s->vhost_net = net;
     ret = vhost_vdpa_net_check_device_id(net);
     if (ret) {
-        goto err;
+        goto err_check;
     }
     return 0;
-err:
-    if (net) {
-        vhost_net_cleanup(net);
-        g_free(net);
-    }
+err_check:
+    vhost_net_cleanup(net);
+    g_free(net);
+err_init:
     return -1;
 }
 
Signature · 1 line
2.25.1
author
#8 lore raw

PATCH v2 8/18 vhost-vdpa: fix the wrong assertion in vhost_vdpa_init()

In reply to Jason Wang

Vhost_vdpa_add() can fail for various reasons, so the assertion of the succeed is wrong. Instead, we should free the NetClientState and propagate the error to the caller

---
 net/vhost-vdpa.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
net/vhost-vdpa.c +4 -1
index 0da7bc347a..87b181a74e 100644
@@ -174,7 +174,10 @@ static int net_vhost_vdpa_init(NetClientState *peer, const char *device,
     }
     s->vhost_vdpa.device_fd = vdpa_device_fd;
     ret = vhost_vdpa_add(nc, (void *)&s->vhost_vdpa);
-    assert(s->vhost_net);
+    if (ret) {
+        qemu_close(vdpa_device_fd);
+        qemu_del_net_client(nc);
+    }
     return ret;
 }
 
Signature · 1 line
2.25.1
author
#9 lore raw

PATCH v2 9/18 vhost-vdpa: remove the unncessary queue_index assignment

In reply to Jason Wang

The queue_index of NetClientState should be assigned in set_netdev() afterwards, so trying to net_vhost_vdpa_init() is meaningless. This patch removes this.

---
 net/vhost-vdpa.c | 1 -
 1 file changed, 1 deletion(-)
net/vhost-vdpa.c +0 -1
index 87b181a74e..572aed4ca2 100644
@@ -166,7 +166,6 @@ static int net_vhost_vdpa_init(NetClientState *peer, const char *device,
     assert(name);
     nc = qemu_new_net_client(&net_vhost_vdpa_info, peer, device, name);
     snprintf(nc->info_str, sizeof(nc->info_str), TYPE_VHOST_VDPA);
-    nc->queue_index = 0;
     s = DO_UPCAST(VhostVDPAState, nc, nc);
     vdpa_device_fd = qemu_open_old(vhostdev, O_RDWR);
     if (vdpa_device_fd == -1) {
Signature · 1 line
2.25.1
author
#10 lore raw

PATCH v2 10/18 vhost-vdpa: open device fd in net_init_vhost_vdpa()

In reply to Jason Wang

This path switches to open device fd in net_init_vhost_vpda(). This is used to prepare for the multiqueue support.

---
 net/vhost-vdpa.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)
net/vhost-vdpa.c +15 -8
index 572aed4ca2..e63a54a938 100644
@@ -157,24 +157,19 @@ static NetClientInfo net_vhost_vdpa_info = {
 };
 
 static int net_vhost_vdpa_init(NetClientState *peer, const char *device,
-                               const char *name, const char *vhostdev)
+                               const char *name, int vdpa_device_fd)
 {
     NetClientState *nc = NULL;
     VhostVDPAState *s;
-    int vdpa_device_fd = -1;
     int ret = 0;
     assert(name);
     nc = qemu_new_net_client(&net_vhost_vdpa_info, peer, device, name);
     snprintf(nc->info_str, sizeof(nc->info_str), TYPE_VHOST_VDPA);
     s = DO_UPCAST(VhostVDPAState, nc, nc);
-    vdpa_device_fd = qemu_open_old(vhostdev, O_RDWR);
-    if (vdpa_device_fd == -1) {
-        return -errno;
-    }
+
     s->vhost_vdpa.device_fd = vdpa_device_fd;
     ret = vhost_vdpa_add(nc, (void *)&s->vhost_vdpa);
     if (ret) {
-        qemu_close(vdpa_device_fd);
         qemu_del_net_client(nc);
     }
     return ret;
@@ -202,6 +197,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name,
                         NetClientState *peer, Error **errp)
 {
     const NetdevVhostVDPAOptions *opts;
+    int vdpa_device_fd, ret;
 
     assert(netdev->type == NET_CLIENT_DRIVER_VHOST_VDPA);
     opts = &netdev->u.vhost_vdpa;
@@ -210,5 +206,16 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name,
                           (char *)name, errp)) {
         return -1;
     }
-    return net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name, opts->vhostdev);
+
+    vdpa_device_fd = qemu_open_old(opts->vhostdev, O_RDWR);
+    if (vdpa_device_fd == -1) {
+        return -errno;
+    }
+
+    ret = net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name, vdpa_device_fd);
+    if (ret) {
+        qemu_close(vdpa_device_fd);
+    }
+
+    return ret;
 }
Signature · 1 line
2.25.1
author
#11 lore raw

PATCH v2 11/18 vhost-vdpa: classify one time request

In reply to Jason Wang

Vhost-vdpa uses one device multiqueue queue (pairs) model. So we need to classify the one time request (e.g SET_OWNER) and make sure those request were only called once per device.

This is used for multiqueue support.

---
 hw/virtio/vhost-vdpa.c         | 51 ++++++++++++++++++++++++++++++++--
 include/hw/virtio/vhost-vdpa.h |  1 +
 2 files changed, 49 insertions(+), 3 deletions(-)
hw/virtio/vhost-vdpa.c +48 -3
index 61ba313331..397f47bc11 100644
@@ -265,6 +265,13 @@ static void vhost_vdpa_add_status(struct vhost_dev *dev, uint8_t status)
     vhost_vdpa_call(dev, VHOST_VDPA_SET_STATUS, &s);
 }
 
+static bool vhost_vdpa_one_time_request(struct vhost_dev *dev)
+{
+    struct vhost_vdpa *v = dev->opaque;
+
+    return v->index != 0;
+}
+
 static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque)
 {
     struct vhost_vdpa *v;
@@ -277,6 +284,10 @@ static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque)
     v->listener = vhost_vdpa_memory_listener;
     v->msg_type = VHOST_IOTLB_MSG_V2;
 
+    if (vhost_vdpa_one_time_request(dev)) {
+        return 0;
+    }
+
     vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE |
                                VIRTIO_CONFIG_S_DRIVER);
 
@@ -387,6 +398,10 @@ static int vhost_vdpa_memslots_limit(struct vhost_dev *dev)
 static int vhost_vdpa_set_mem_table(struct vhost_dev *dev,
                                     struct vhost_memory *mem)
 {
+    if (vhost_vdpa_one_time_request(dev)) {
+        return 0;
+    }
+
     trace_vhost_vdpa_set_mem_table(dev, mem->nregions, mem->padding);
     if (trace_event_get_state_backends(TRACE_VHOST_VDPA_SET_MEM_TABLE) &&
         trace_event_get_state_backends(TRACE_VHOST_VDPA_DUMP_REGIONS)) {
@@ -410,6 +425,11 @@ static int vhost_vdpa_set_features(struct vhost_dev *dev,
                                    uint64_t features)
 {
     int ret;
+
+    if (vhost_vdpa_one_time_request(dev)) {
+        return 0;
+    }
+
     trace_vhost_vdpa_set_features(dev, features);
     ret = vhost_vdpa_call(dev, VHOST_SET_FEATURES, &features);
     uint8_t status = 0;
@@ -429,6 +449,10 @@ static int vhost_vdpa_set_backend_cap(struct vhost_dev *dev)
         0x1ULL << VHOST_BACKEND_F_IOTLB_BATCH;
     int r;
 
+    if (vhost_vdpa_one_time_request(dev)) {
+        return 0;
+    }
+
     if (vhost_vdpa_call(dev, VHOST_GET_BACKEND_FEATURES, &features)) {
         return 0;
     }
@@ -458,6 +482,10 @@ static int vhost_vdpa_reset_device(struct vhost_dev *dev)
     int ret;
     uint8_t status = 0;
 
+    if (vhost_vdpa_one_time_request(dev)) {
+        return 0;
+    }
+
     ret = vhost_vdpa_call(dev, VHOST_VDPA_SET_STATUS, &status);
     trace_vhost_vdpa_reset_device(dev, status);
     return ret;
@@ -545,11 +573,21 @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started)
 {
     struct vhost_vdpa *v = dev->opaque;
     trace_vhost_vdpa_dev_start(dev, started);
+
     if (started) {
-        uint8_t status = 0;
-        memory_listener_register(&v->listener, &address_space_memory);
         vhost_vdpa_host_notifiers_init(dev);
         vhost_vdpa_set_vring_ready(dev);
+    } else {
+        vhost_vdpa_host_notifiers_uninit(dev, dev->nvqs);
+    }
+
+    if (vhost_vdpa_one_time_request(dev)) {
+        return 0;
+    }
+
+    if (started) {
+        uint8_t status = 0;
+        memory_listener_register(&v->listener, &address_space_memory);
         vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK);
         vhost_vdpa_call(dev, VHOST_VDPA_GET_STATUS, &status);
 
@@ -558,7 +596,6 @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started)
         vhost_vdpa_reset_device(dev);
         vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE |
                                    VIRTIO_CONFIG_S_DRIVER);
-        vhost_vdpa_host_notifiers_uninit(dev, dev->nvqs);
         memory_listener_unregister(&v->listener);
 
         return 0;
@@ -568,6 +605,10 @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started)
 static int vhost_vdpa_set_log_base(struct vhost_dev *dev, uint64_t base,
                                      struct vhost_log *log)
 {
+    if (vhost_vdpa_one_time_request(dev)) {
+        return 0;
+    }
+
     trace_vhost_vdpa_set_log_base(dev, base, log->size, log->refcnt, log->fd,
                                   log->log);
     return vhost_vdpa_call(dev, VHOST_SET_LOG_BASE, &base);
@@ -633,6 +674,10 @@ static int vhost_vdpa_get_features(struct vhost_dev *dev,
 
 static int vhost_vdpa_set_owner(struct vhost_dev *dev)
 {
+    if (vhost_vdpa_one_time_request(dev)) {
+        return 0;
+    }
+
     trace_vhost_vdpa_set_owner(dev);
     return vhost_vdpa_call(dev, VHOST_SET_OWNER, NULL);
 }
include/hw/virtio/vhost-vdpa.h +1 -0
index 9188226d8b..e98e327f12 100644
@@ -21,6 +21,7 @@ typedef struct VhostVDPAHostNotifier {
 
 typedef struct vhost_vdpa {
     int device_fd;
+    int index;
     uint32_t msg_type;
     MemoryListener listener;
     struct vhost_dev *dev;
Signature · 1 line
2.25.1
author
#12 lore raw

PATCH v2 12/18 vhost-vdpa: prepare for the multiqueue support

In reply to Jason Wang

Unlike vhost-kernel, vhost-vdpa adapts a single device multiqueue model. So we need to simply use virtqueue index as the vhost virtqueue index. This is a must for multiqueue to work for vhost-vdpa.

---
 hw/virtio/vhost-vdpa.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/virtio/vhost-vdpa.c +2 -2
index 397f47bc11..e7e6b23108 100644
@@ -495,8 +495,8 @@ static int vhost_vdpa_get_vq_index(struct vhost_dev *dev, int idx)
 {
     assert(idx >= dev->vq_index && idx < dev->vq_index + dev->nvqs);
 
-    trace_vhost_vdpa_get_vq_index(dev, idx, idx - dev->vq_index);
-    return idx - dev->vq_index;
+    trace_vhost_vdpa_get_vq_index(dev, idx, idx);
+    return idx;
 }
 
 static int vhost_vdpa_set_vring_ready(struct vhost_dev *dev)
Signature · 1 line
2.25.1
author
#13 lore raw

PATCH v2 13/18 vhost-vdpa: let net_vhost_vdpa_init() returns NetClientState *

In reply to Jason Wang

This patch switches to let net_vhost_vdpa_init() to return NetClientState *. This is used for the callers to allocate multiqueue NetClientState for multiqueue support.

---
 net/vhost-vdpa.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
net/vhost-vdpa.c +12 -7
index e63a54a938..cc11b2ec40 100644
@@ -156,8 +156,10 @@ static NetClientInfo net_vhost_vdpa_info = {
         .has_ufo = vhost_vdpa_has_ufo,
 };
 
-static int net_vhost_vdpa_init(NetClientState *peer, const char *device,
-                               const char *name, int vdpa_device_fd)
+static NetClientState *net_vhost_vdpa_init(NetClientState *peer,
+                                           const char *device,
+                                           const char *name,
+                                           int vdpa_device_fd)
 {
     NetClientState *nc = NULL;
     VhostVDPAState *s;
@@ -171,8 +173,9 @@ static int net_vhost_vdpa_init(NetClientState *peer, const char *device,
     ret = vhost_vdpa_add(nc, (void *)&s->vhost_vdpa);
     if (ret) {
         qemu_del_net_client(nc);
+        return NULL;
     }
-    return ret;
+    return nc;
 }
 
 static int net_vhost_check_net(void *opaque, QemuOpts *opts, Error **errp)
@@ -197,7 +200,8 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name,
                         NetClientState *peer, Error **errp)
 {
     const NetdevVhostVDPAOptions *opts;
-    int vdpa_device_fd, ret;
+    int vdpa_device_fd;
+    NetClientState *nc;
 
     assert(netdev->type == NET_CLIENT_DRIVER_VHOST_VDPA);
     opts = &netdev->u.vhost_vdpa;
@@ -212,10 +216,11 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name,
         return -errno;
     }
 
-    ret = net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name, vdpa_device_fd);
-    if (ret) {
+    nc = net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name, vdpa_device_fd);
+    if (!nc) {
         qemu_close(vdpa_device_fd);
+        return -1;
     }
 
-    return ret;
+    return 0;
 }
Signature · 1 line
2.25.1
author
#14 lore raw

PATCH v2 14/18 net: introduce control client

In reply to Jason Wang

This patch introduces a boolean for the device has control queue which can accepts control command via network queue.

The first user would be the control virtqueue support for vhost.

---
 include/net/net.h |  5 +++++
 net/net.c         | 24 +++++++++++++++++++++---
 2 files changed, 26 insertions(+), 3 deletions(-)
include/net/net.h +5 -0
index 5d1508081f..4f400b8a09 100644
@@ -103,6 +103,7 @@ struct NetClientState {
     int vnet_hdr_len;
     bool is_netdev;
     bool do_not_pad; /* do not pad to the minimum ethernet frame length */
+    bool is_datapath;
     QTAILQ_HEAD(, NetFilterState) filters;
 };
 
@@ -134,6 +135,10 @@ NetClientState *qemu_new_net_client(NetClientInfo *info,
                                     NetClientState *peer,
                                     const char *model,
                                     const char *name);
+NetClientState *qemu_new_net_control_client(NetClientInfo *info,
+                                        NetClientState *peer,
+                                        const char *model,
+                                        const char *name);
 NICState *qemu_new_nic(NetClientInfo *info,
                        NICConf *conf,
                        const char *model,
net/net.c +21 -3
index 76bbb7c31b..fcaf9c7715 100644
@@ -237,7 +237,8 @@ static void qemu_net_client_setup(NetClientState *nc,
                                   NetClientState *peer,
                                   const char *model,
                                   const char *name,
-                                  NetClientDestructor *destructor)
+                                  NetClientDestructor *destructor,
+                                  bool is_datapath)
 {
     nc->info = info;
     nc->model = g_strdup(model);
@@ -256,6 +257,7 @@ static void qemu_net_client_setup(NetClientState *nc,
 
     nc->incoming_queue = qemu_new_net_queue(qemu_deliver_packet_iov, nc);
     nc->destructor = destructor;
+    nc->is_datapath = is_datapath;
     QTAILQ_INIT(&nc->filters);
 }
 
@@ -270,7 +272,23 @@ NetClientState *qemu_new_net_client(NetClientInfo *info,
 
     nc = g_malloc0(info->size);
     qemu_net_client_setup(nc, info, peer, model, name,
-                          qemu_net_client_destructor);
+                          qemu_net_client_destructor, true);
+
+    return nc;
+}
+
+NetClientState *qemu_new_net_control_client(NetClientInfo *info,
+                                            NetClientState *peer,
+                                            const char *model,
+                                            const char *name)
+{
+    NetClientState *nc;
+
+    assert(info->size >= sizeof(NetClientState));
+
+    nc = g_malloc0(info->size);
+    qemu_net_client_setup(nc, info, peer, model, name,
+                          qemu_net_client_destructor, false);
 
     return nc;
 }
@@ -295,7 +313,7 @@ NICState *qemu_new_nic(NetClientInfo *info,
 
     for (i = 0; i < queues; i++) {
         qemu_net_client_setup(&nic->ncs[i], info, peers[i], model, name,
-                              NULL);
+                              NULL, true);
         nic->ncs[i].queue_index = i;
     }
 
Signature · 1 line
2.25.1
author
#15 lore raw

PATCH v2 15/18 vhost-net: control virtqueue support

In reply to Jason Wang

We assume there's no cvq in the past, this is not true when we need control virtqueue support for vhost-user backends. So this patch implements the control virtqueue support for vhost-net. As datapath, the control virtqueue is also required to be coupled with the NetClientState. The vhost_net_start/stop() are tweaked to accept the number of datapath queue pairs plus the the number of control virtqueue for us to start and stop the vhost device.

---
 hw/net/vhost_net.c      | 43 ++++++++++++++++++++++++++++++-----------
 hw/net/virtio-net.c     |  4 ++--
 include/net/vhost_net.h |  6 ++++--
 3 files changed, 38 insertions(+), 15 deletions(-)
hw/net/vhost_net.c +32 -11
index ef1370bd92..4294fb9fc9 100644
@@ -311,11 +311,14 @@ static void vhost_net_stop_one(struct vhost_net *net,
 }
 
 int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
-                    int total_queues)
+                    int data_qps, int cvq)
 {
     BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(dev)));
     VirtioBusState *vbus = VIRTIO_BUS(qbus);
     VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
+    int total_notifiers = data_qps * 2 + cvq;
+    VirtIONet *n = VIRTIO_NET(dev);
+    int nvhosts = data_qps + cvq;
     struct vhost_net *net;
     int r, e, i;
     NetClientState *peer;
@@ -325,9 +328,14 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
         return -ENOSYS;
     }
 
-    for (i = 0; i < total_queues; i++) {
+    for (i = 0; i < nvhosts; i++) {
+
+        if (i < data_qps) {
+            peer = qemu_get_peer(ncs, i);
+        } else { /* Control Virtqueue */
+            peer = qemu_get_peer(ncs, n->max_queues);
+        }
 
-        peer = qemu_get_peer(ncs, i);
         net = get_vhost_net(peer);
         vhost_net_set_vq_index(net, i * 2);
 
@@ -340,14 +348,18 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
         }
      }
 
-    r = k->set_guest_notifiers(qbus->parent, total_queues * 2, true);
+    r = k->set_guest_notifiers(qbus->parent, total_notifiers, true);
     if (r < 0) {
         error_report("Error binding guest notifier: %d", -r);
         goto err;
     }
 
-    for (i = 0; i < total_queues; i++) {
-        peer = qemu_get_peer(ncs, i);
+    for (i = 0; i < nvhosts; i++) {
+        if (i < data_qps) {
+            peer = qemu_get_peer(ncs, i);
+        } else {
+            peer = qemu_get_peer(ncs, n->max_queues);
+        }
         r = vhost_net_start_one(get_vhost_net(peer), dev);
 
         if (r < 0) {
@@ -371,7 +383,7 @@ err_start:
         peer = qemu_get_peer(ncs , i);
         vhost_net_stop_one(get_vhost_net(peer), dev);
     }
-    e = k->set_guest_notifiers(qbus->parent, total_queues * 2, false);
+    e = k->set_guest_notifiers(qbus->parent, total_notifiers, false);
     if (e < 0) {
         fprintf(stderr, "vhost guest notifier cleanup failed: %d\n", e);
         fflush(stderr);
@@ -381,18 +393,27 @@ err:
 }
 
 void vhost_net_stop(VirtIODevice *dev, NetClientState *ncs,
-                    int total_queues)
+                    int data_qps, int cvq)
 {
     BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(dev)));
     VirtioBusState *vbus = VIRTIO_BUS(qbus);
     VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
+    VirtIONet *n = VIRTIO_NET(dev);
+    NetClientState *peer;
+    int total_notifiers = data_qps * 2 + cvq;
+    int nvhosts = data_qps + cvq;
     int i, r;
 
-    for (i = 0; i < total_queues; i++) {
-        vhost_net_stop_one(get_vhost_net(ncs[i].peer), dev);
+    for (i = 0; i < nvhosts; i++) {
+        if (i < data_qps) {
+            peer = qemu_get_peer(ncs, i);
+        } else {
+            peer = qemu_get_peer(ncs, n->max_queues);
+        }
+        vhost_net_stop_one(get_vhost_net(peer), dev);
     }
 
-    r = k->set_guest_notifiers(qbus->parent, total_queues * 2, false);
+    r = k->set_guest_notifiers(qbus->parent, total_notifiers, false);
     if (r < 0) {
         fprintf(stderr, "vhost guest notifier cleanup failed: %d\n", r);
         fflush(stderr);
hw/net/virtio-net.c +2 -2
index bd7958b9f0..614660274c 100644
@@ -285,14 +285,14 @@ static void virtio_net_vhost_status(VirtIONet *n, uint8_t status)
         }
 
         n->vhost_started = 1;
-        r = vhost_net_start(vdev, n->nic->ncs, queues);
+        r = vhost_net_start(vdev, n->nic->ncs, queues, 0);
         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, queues);
+        vhost_net_stop(vdev, n->nic->ncs, queues, 0);
         n->vhost_started = 0;
     }
 }
include/net/vhost_net.h +4 -2
index fba40cf695..e656e38af9 100644
@@ -21,8 +21,10 @@ typedef struct VhostNetOptions {
 uint64_t vhost_net_get_max_queues(VHostNetState *net);
 struct vhost_net *vhost_net_init(VhostNetOptions *options);
 
-int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, int total_queues);
-void vhost_net_stop(VirtIODevice *dev, NetClientState *ncs, int total_queues);
+int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
+                    int data_qps, int cvq);
+void vhost_net_stop(VirtIODevice *dev, NetClientState *ncs,
+                    int data_qps, int cvq);
 
 void vhost_net_cleanup(VHostNetState *net);
 
Signature · 1 line
2.25.1
author
#16 lore raw

PATCH v2 16/18 virito-net: use "qps" instead of "queues" when possible

In reply to Jason Wang

Most of the time, "queues" really means queue pairs. So this patch switch to use "qps" to avoid confusion.

---
 hw/net/vhost_net.c             |   6 +-
 hw/net/virtio-net.c            | 150 ++++++++++++++++-----------------
 include/hw/virtio/virtio-net.h |   4 +-
 3 files changed, 80 insertions(+), 80 deletions(-)
hw/net/vhost_net.c +3 -3
index 4294fb9fc9..fe2fd7e3d5 100644
@@ -333,7 +333,7 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
         if (i < data_qps) {
             peer = qemu_get_peer(ncs, i);
         } else { /* Control Virtqueue */
-            peer = qemu_get_peer(ncs, n->max_queues);
+            peer = qemu_get_peer(ncs, n->max_qps);
         }
 
         net = get_vhost_net(peer);
@@ -358,7 +358,7 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
         if (i < data_qps) {
             peer = qemu_get_peer(ncs, i);
         } else {
-            peer = qemu_get_peer(ncs, n->max_queues);
+            peer = qemu_get_peer(ncs, n->max_qps);
         }
         r = vhost_net_start_one(get_vhost_net(peer), dev);
 
@@ -408,7 +408,7 @@ void vhost_net_stop(VirtIODevice *dev, NetClientState *ncs,
         if (i < data_qps) {
             peer = qemu_get_peer(ncs, i);
         } else {
-            peer = qemu_get_peer(ncs, n->max_queues);
+            peer = qemu_get_peer(ncs, n->max_qps);
         }
         vhost_net_stop_one(get_vhost_net(peer), dev);
     }
hw/net/virtio-net.c +75 -75

447 lines not on this page · raw message

include/hw/virtio/virtio-net.h +2 -2
index 824a69c23f..a9b6dc252e 100644
@@ -194,8 +194,8 @@ struct VirtIONet {
     NICConf nic_conf;
     DeviceState *qdev;
     int multiqueue;
-    uint16_t max_queues;
-    uint16_t curr_queues;
+    uint16_t max_qps;
+    uint16_t curr_qps;
     size_t config_size;
     char *netclient_name;
     char *netclient_type;
Signature · 1 line
2.25.1
author
#17 lore raw

PATCH v2 17/18 virtio-net: vhost control virtqueue support

In reply to Jason Wang

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().

---
 hw/net/virtio-net.c            | 21 ++++++++++++++++++---
 include/hw/virtio/virtio-net.h |  1 +
 2 files changed, 19 insertions(+), 3 deletions(-)
hw/net/virtio-net.c +18 -3
index 36bd197087..f003687579 100644
@@ -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 qps = n->multiqueue ? n->max_qps : 1;
+    int cvq = n->max_ncs - n->max_qps;
 
     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, qps, 0);
+        r = vhost_net_start(vdev, n->nic->ncs, qps, 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, qps, 0);
+        vhost_net_stop(vdev, n->nic->ncs, qps, cvq);
         n->vhost_started = 0;
     }
 }
@@ -3367,7 +3368,21 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)
         return;
     }
 
-    n->max_qps = 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_qps;
+            }
+        }
+    }
+    n->max_qps = MAX(n->max_qps, 1);
+
     if (n->max_qps * 2 + 1 > VIRTIO_QUEUE_MAX) {
         error_setg(errp, "Invalid number of qps (= %" PRIu32 "), "
                    "must be a positive integer less than %d.",
include/hw/virtio/virtio-net.h +1 -0
index a9b6dc252e..ed4659c189 100644
@@ -194,6 +194,7 @@ struct VirtIONet {
     NICConf nic_conf;
     DeviceState *qdev;
     int multiqueue;
+    uint16_t max_ncs;
     uint16_t max_qps;
     uint16_t curr_qps;
     size_t config_size;
Signature · 1 line
2.25.1
author
#18 lore raw

PATCH v2 18/18 vhost-vdpa: multiqueue support

In reply to Jason Wang

This patch implements the multiqueue support for vhost-vdpa. This is done simply by reading the number of queue pairs from the config space and initialize the datapath and control path net client.

---
 net/vhost-vdpa.c | 104 +++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 95 insertions(+), 9 deletions(-)
net/vhost-vdpa.c +95 -9
index cc11b2ec40..01a667deb9 100644
@@ -18,6 +18,7 @@
 #include "qemu/error-report.h"
 #include "qemu/option.h"
 #include "qapi/error.h"
+#include <linux/vhost.h>
 #include <sys/ioctl.h>
 #include <err.h>
 #include "standard-headers/linux/virtio_net.h"
@@ -52,6 +53,14 @@ const int vdpa_feature_bits[] = {
     VIRTIO_NET_F_HOST_UFO,
     VIRTIO_NET_F_MRG_RXBUF,
     VIRTIO_NET_F_MTU,
+    VIRTIO_NET_F_CTRL_RX,
+    VIRTIO_NET_F_CTRL_RX_EXTRA,
+    VIRTIO_NET_F_CTRL_VLAN,
+    VIRTIO_NET_F_GUEST_ANNOUNCE,
+    VIRTIO_NET_F_CTRL_MAC_ADDR,
+    VIRTIO_NET_F_RSS,
+    VIRTIO_NET_F_MQ,
+    VIRTIO_NET_F_CTRL_VQ,
     VIRTIO_F_IOMMU_PLATFORM,
     VIRTIO_F_RING_PACKED,
     VIRTIO_NET_F_RSS,
@@ -82,7 +91,8 @@ static int vhost_vdpa_net_check_device_id(struct vhost_net *net)
     return ret;
 }
 
-static int vhost_vdpa_add(NetClientState *ncs, void *be)
+static int vhost_vdpa_add(NetClientState *ncs, void *be, int qp_index,
+                          int nvqs)
 {
     VhostNetOptions options;
     struct vhost_net *net = NULL;
@@ -95,7 +105,7 @@ static int vhost_vdpa_add(NetClientState *ncs, void *be)
     options.net_backend = ncs;
     options.opaque      = be;
     options.busyloop_timeout = 0;
-    options.nvqs = 2;
+    options.nvqs = nvqs;
 
     net = vhost_net_init(&options);
     if (!net) {
@@ -159,18 +169,28 @@ static NetClientInfo net_vhost_vdpa_info = {
 static NetClientState *net_vhost_vdpa_init(NetClientState *peer,
                                            const char *device,
                                            const char *name,
-                                           int vdpa_device_fd)
+                                           int vdpa_device_fd,
+                                           int qp_index,
+                                           int nvqs,
+                                           bool is_datapath)
 {
     NetClientState *nc = NULL;
     VhostVDPAState *s;
     int ret = 0;
     assert(name);
-    nc = qemu_new_net_client(&net_vhost_vdpa_info, peer, device, name);
+    if (is_datapath) {
+        nc = qemu_new_net_client(&net_vhost_vdpa_info, peer, device,
+                                 name);
+    } else {
+        nc = qemu_new_net_control_client(&net_vhost_vdpa_info, peer,
+                                         device, name);
+    }
     snprintf(nc->info_str, sizeof(nc->info_str), TYPE_VHOST_VDPA);
     s = DO_UPCAST(VhostVDPAState, nc, nc);
 
     s->vhost_vdpa.device_fd = vdpa_device_fd;
-    ret = vhost_vdpa_add(nc, (void *)&s->vhost_vdpa);
+    s->vhost_vdpa.index = qp_index;
+    ret = vhost_vdpa_add(nc, (void *)&s->vhost_vdpa, qp_index, nvqs);
     if (ret) {
         qemu_del_net_client(nc);
         return NULL;
@@ -196,12 +216,52 @@ static int net_vhost_check_net(void *opaque, QemuOpts *opts, Error **errp)
     return 0;
 }
 
+static int vhost_vdpa_get_max_qps(int fd, int *has_cvq, Error **errp)
+{
+    unsigned long config_size = offsetof(struct vhost_vdpa_config, buf);
+    struct vhost_vdpa_config *config;
+    __virtio16 *max_qps;
+    uint64_t features;
+    int ret;
+
+    ret = ioctl(fd, VHOST_GET_FEATURES, &features);
+    if (ret) {
+        error_setg(errp, "Fail to query features from vhost-vDPA device");
+        return ret;
+    }
+
+    if (features & (1 << VIRTIO_NET_F_CTRL_VQ)) {
+        *has_cvq = 1;
+    } else {
+        *has_cvq = 0;
+    }
+
+    if (features & (1 << VIRTIO_NET_F_MQ)) {
+        config = g_malloc0(config_size + sizeof(*max_qps));
+        config->off = offsetof(struct virtio_net_config, max_virtqueue_pairs);
+        config->len = sizeof(*max_qps);
+
+        ret = ioctl(fd, VHOST_VDPA_GET_CONFIG, config);
+        if (ret) {
+            error_setg(errp, "Fail to get config from vhost-vDPA device");
+            return -ret;
+        }
+
+        max_qps = (__virtio16 *)&config->buf;
+
+        return lduw_le_p(max_qps);
+    }
+
+    return 1;
+}
+
 int net_init_vhost_vdpa(const Netdev *netdev, const char *name,
                         NetClientState *peer, Error **errp)
 {
     const NetdevVhostVDPAOptions *opts;
     int vdpa_device_fd;
-    NetClientState *nc;
+    NetClientState **ncs, *nc;
+    int qps, i, has_cvq = 0;
 
     assert(netdev->type == NET_CLIENT_DRIVER_VHOST_VDPA);
     opts = &netdev->u.vhost_vdpa;
@@ -216,11 +276,37 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name,
         return -errno;
     }
 
-    nc = net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name, vdpa_device_fd);
-    if (!nc) {
+    qps = vhost_vdpa_get_max_qps(vdpa_device_fd, &has_cvq, errp);
+    if (qps < 0) {
         qemu_close(vdpa_device_fd);
-        return -1;
+        return qps;
+    }
+
+    ncs = g_malloc0(sizeof(*ncs) * qps);
+
+    for (i = 0; i < qps; i++) {
+        ncs[i] = net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name,
+                                     vdpa_device_fd, i, 2, true);
+        if (!ncs[i])
+            goto err;
+    }
+
+    if (has_cvq) {
+        nc = net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name,
+                                 vdpa_device_fd, i, 1, false);
+        if (!nc)
+            goto err;
     }
 
+    g_free(ncs);
     return 0;
+
+err:
+    if (i) {
+        qemu_del_net_client(ncs[0]);
+    }
+    qemu_close(vdpa_device_fd);
+    g_free(ncs);
+
+    return -1;
 }
Signature · 1 line
2.25.1
author
#19 lore raw
In reply to Jason Wang
Quoted 11 lines · Jason Wang

Hi All:

This patch implements the multiqueue support for vhost-vDPA. The most important requirement the control virtqueue support. The virtio-net and vhost-net core are tweak to support control virtqueue as if what data queue pairs are done: a dedicated vhost_net device which is coupled with the NetClientState is intrdouced so most of the existing vhost codes could be reused with minor changes. With the control virtqueue, vhost-vDPA are extend to support creating and destroying multiqueue queue pairs plus the control virtqueue.

Quoted 4 lines

Tests are done via the vp_vdpa driver in L1 guest plus vdpa simulator on L0.

Please reivew.

If no objection, I will queue this for 6.1.

Thanks

Quoted 43 lines

Changes since V1:

- validating all features that depends on ctrl vq
- typo fixes and commit log tweaks
- fix build errors because max_qps is used before it is introduced

Thanks

Jason Wang (18):
vhost_net: remove the meaningless assignment in vhost_net_start_one()
vhost: use unsigned int for nvqs
vhost_net: do not assume nvqs is always 2
vhost-vdpa: remove the unnecessary check in vhost_vdpa_add()
vhost-vdpa: don't cleanup twice in vhost_vdpa_add()
vhost-vdpa: fix leaking of vhost_net in vhost_vdpa_add()
vhost-vdpa: tweak the error label in vhost_vdpa_add()
vhost-vdpa: fix the wrong assertion in vhost_vdpa_init()
vhost-vdpa: remove the unncessary queue_index assignment
vhost-vdpa: open device fd in net_init_vhost_vdpa()
vhost-vdpa: classify one time request
vhost-vdpa: prepare for the multiqueue support
vhost-vdpa: let net_vhost_vdpa_init() returns NetClientState *
net: introduce control client
vhost-net: control virtqueue support
virito-net: use "qps" instead of "queues" when possible
virtio-net: vhost control virtqueue support
vhost-vdpa: multiqueue support

  hw/net/vhost_net.c             |  48 +++++++---
  hw/net/virtio-net.c            | 165 ++++++++++++++++++---------------
  hw/virtio/vhost-vdpa.c         |  55 ++++++++++-
  include/hw/virtio/vhost-vdpa.h |   1 +
  include/hw/virtio/vhost.h      |   2 +-
  include/hw/virtio/virtio-net.h |   5 +-
  include/net/net.h              |   5 +
  include/net/vhost_net.h        |   7 +-
  net/net.c                      |  24 ++++-
  net/tap.c                      |   1 +
  net/vhost-user.c               |   1 +
  net/vhost-vdpa.c               | 156 ++++++++++++++++++++++++-------
  12 files changed, 332 insertions(+), 138 deletions(-)
#20 lore raw
Quoted 16 lines · Jason Wang
Quoted 14 lines · Jason Wang

Hi All:

This patch implements the multiqueue support for vhost-vDPA. The most important requirement the control virtqueue support. The virtio-net and vhost-net core are tweak to support control virtqueue as if what data queue pairs are done: a dedicated vhost_net device which is coupled with the NetClientState is intrdouced so most of the existing vhost codes could be reused with minor changes. With the control virtqueue, vhost-vDPA are extend to support creating and destroying multiqueue queue pairs plus the control virtqueue.

Tests are done via the vp_vdpa driver in L1 guest plus vdpa simulator on L0.

Quoted 6 lines
Quoted 1 line

Please reivew.

If no objection, I will queue this for 6.1.

Thanks

Just to make sure I understand, this basically works by passing the cvq through to the guest right? Giving up on maintaining the state in qemu.

Quoted 44 lines
Quoted 44 lines

Changes since V1:

- validating all features that depends on ctrl vq
- typo fixes and commit log tweaks
- fix build errors because max_qps is used before it is introduced

Thanks

Jason Wang (18):
vhost_net: remove the meaningless assignment in vhost_net_start_one()
vhost: use unsigned int for nvqs
vhost_net: do not assume nvqs is always 2
vhost-vdpa: remove the unnecessary check in vhost_vdpa_add()
vhost-vdpa: don't cleanup twice in vhost_vdpa_add()
vhost-vdpa: fix leaking of vhost_net in vhost_vdpa_add()
vhost-vdpa: tweak the error label in vhost_vdpa_add()
vhost-vdpa: fix the wrong assertion in vhost_vdpa_init()
vhost-vdpa: remove the unncessary queue_index assignment
vhost-vdpa: open device fd in net_init_vhost_vdpa()
vhost-vdpa: classify one time request
vhost-vdpa: prepare for the multiqueue support
vhost-vdpa: let net_vhost_vdpa_init() returns NetClientState *
net: introduce control client
vhost-net: control virtqueue support
virito-net: use "qps" instead of "queues" when possible
virtio-net: vhost control virtqueue support
vhost-vdpa: multiqueue support

  hw/net/vhost_net.c             |  48 +++++++---
  hw/net/virtio-net.c            | 165 ++++++++++++++++++---------------
  hw/virtio/vhost-vdpa.c         |  55 ++++++++++-
  include/hw/virtio/vhost-vdpa.h |   1 +
  include/hw/virtio/vhost.h      |   2 +-
  include/hw/virtio/virtio-net.h |   5 +-
  include/net/net.h              |   5 +
  include/net/vhost_net.h        |   7 +-
  net/net.c                      |  24 ++++-
  net/tap.c                      |   1 +
  net/vhost-user.c               |   1 +
  net/vhost-vdpa.c               | 156 ++++++++++++++++++++++++-------
  12 files changed, 332 insertions(+), 138 deletions(-)

A message that is not in the archive (sent off-list or not yet received): CACGkMEs_sNOqdsDvpMR+Mx7TXY2wW8p_NVALvHLPgeAsiWNTGA@mail.gmail.com

A message that is not in the archive (sent off-list or not yet received): [email protected]

author
#23 lore raw
Quoted 30 lines · Michael S. Tsirkin
Quoted 29 lines · Jason Wang
Quoted 18 lines · Michael S. Tsirkin
Quoted 17 lines · Jason Wang
Quoted 15 lines · Jason Wang

Hi All:

This patch implements the multiqueue support for vhost-vDPA. The most important requirement the control virtqueue support. The virtio-net and vhost-net core are tweak to support control virtqueue as if what data queue pairs are done: a dedicated vhost_net device which is coupled with the NetClientState is intrdouced so most of the existing vhost codes could be reused with minor changes. With the control virtqueue, vhost-vDPA are extend to support creating and destroying multiqueue queue pairs plus the control virtqueue.

Tests are done via the vp_vdpa driver in L1 guest plus vdpa simulator on L0.

Please reivew.

Quoted 7 lines
Quoted 3 lines

If no objection, I will queue this for 6.1.

Thanks

Just to make sure I understand, this basically works by passing the cvq through to the guest right? Giving up on maintaining the state in qemu.

Yes, if I understand correctly. This is the conclusion since our last discussion.

Quoted 6 lines
Quoted 4 lines

We can handle migration by using shadow virtqueue on top (depends on the Eugenio's work), and multiple IOTLB support on the vhost-vDPA.

Thanks

I still think it's wrong to force userspace to use shadow vq or multiple IOTLB. These should be implementation detail.

Stick to a virtqueue interface doesn't mean we need to force the vendor to implement the hardware control virtqueue. See below.

Quoted 5 lines

Short term I'm inclined to say just switch to userspace emulation or to vhost for the duration of migration.
Long term I think we should push commands to the kernel and have it pass them to the PF.

So the issues are, I think we've discussed several times but it's time to figure them out now:

1) There's no guarantee that the control virtqueue is implemented in PF
2) Something like pushing commands will bring extra issues:
2.1) duplicating all the existing control virtqueue command via another uAPI 2.2) no asynchronous support
3) can't work for virtio_vdpa
4) bring extra complications for the nested virtualization

If we manage to overcome 2.1 and 2.2 it's just a re-invention of control virtqueue.

Quoted 4 lines

So it worries me a bit that we are pushing this specific way into QEMU. If you are sure it won't push other vendors in this direction and we'll be able to back out later then ok, I won't nack it.

Let me clarify, control virtqueue + multiple IOTLB is just the uAPI but not the implementation. Parent/vendor is free to implement those semantics in their comfortable way:

1) Having a consistent (or re-using) uAPI to work for all kinds of control virtqueue or event virtqueue

2) Fit for all kinds of the hardware implementation

2.1) Hardware doesn't have control virtqueue but using registers. Parent just decode the cvq commands and translate them to register commands
2.2) Hardware doesn't have control virtqueue but using other device (e.g PF) to implement the semantics. Parent just decode the cvq commands and send them to the device that implements the semantic (PF) 2.3) Hardware does have control virtqueue with transport specific ASID support. Parent just assign a different PASID to cvq, and let userspace to use that cvq directly. 2.4) Hardware does have control virtqueue with device specific ASID support. Parent just assign a different device specific ASID and let userspace to use that cvq directly.

The above 4 should covers all the vendor cases that I know that at least 2.1 and 2.4 are supported by some vendors. Some vendors have the plan for 2.3.

Thanks

Quoted 43 lines
Quoted 43 lines
Quoted 43 lines
Quoted 43 lines
Quoted 43 lines

Changes since V1:

- validating all features that depends on ctrl vq
- typo fixes and commit log tweaks
- fix build errors because max_qps is used before it is introduced

Thanks

Jason Wang (18):
vhost_net: remove the meaningless assignment in vhost_net_start_one()
vhost: use unsigned int for nvqs
vhost_net: do not assume nvqs is always 2
vhost-vdpa: remove the unnecessary check in vhost_vdpa_add()
vhost-vdpa: don't cleanup twice in vhost_vdpa_add()
vhost-vdpa: fix leaking of vhost_net in vhost_vdpa_add()
vhost-vdpa: tweak the error label in vhost_vdpa_add()
vhost-vdpa: fix the wrong assertion in vhost_vdpa_init()
vhost-vdpa: remove the unncessary queue_index assignment
vhost-vdpa: open device fd in net_init_vhost_vdpa()
vhost-vdpa: classify one time request
vhost-vdpa: prepare for the multiqueue support
vhost-vdpa: let net_vhost_vdpa_init() returns NetClientState *
net: introduce control client
vhost-net: control virtqueue support
virito-net: use "qps" instead of "queues" when possible
virtio-net: vhost control virtqueue support
vhost-vdpa: multiqueue support

   hw/net/vhost_net.c             |  48 +++++++---
   hw/net/virtio-net.c            | 165 ++++++++++++++++++---------------
   hw/virtio/vhost-vdpa.c         |  55 ++++++++++-
   include/hw/virtio/vhost-vdpa.h |   1 +
   include/hw/virtio/vhost.h      |   2 +-
   include/hw/virtio/virtio-net.h |   5 +-
   include/net/net.h              |   5 +
   include/net/vhost_net.h        |   7 +-
   net/net.c                      |  24 ++++-
   net/tap.c                      |   1 +
   net/vhost-user.c               |   1 +
   net/vhost-vdpa.c               | 156 ++++++++++++++++++++++++-------
   12 files changed, 332 insertions(+), 138 deletions(-)
author
#24 lore raw
In reply to Jason Wang
Quoted 13 lines · Jason Wang
Quoted 11 lines · Jason Wang

Hi All:

This patch implements the multiqueue support for vhost-vDPA. The most important requirement the control virtqueue support. The virtio-net and vhost-net core are tweak to support control virtqueue as if what data queue pairs are done: a dedicated vhost_net device which is coupled with the NetClientState is intrdouced so most of the existing vhost codes could be reused with minor changes. With the control virtqueue, vhost-vDPA are extend to support creating and destroying multiqueue queue pairs plus the control virtqueue.

Quoted 7 lines
Quoted 4 lines

Tests are done via the vp_vdpa driver in L1 guest plus vdpa simulator on L0.

Please reivew.

If no objection, I will queue this for 6.1.

Hi Michael:

So we miss the soft freeze, want to know if the series is fine from your side, and if you'd like to merge them (for 6.2 probably?).

Thanks