thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
586cba
From 0b27781f9984c67625c49a516c3e38fbf5fa1b1b Mon Sep 17 00:00:00 2001
586cba
From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= <eperezma@redhat.com>
586cba
Date: Thu, 21 Jul 2022 16:06:16 +0200
586cba
Subject: [PATCH 27/32] vdpa: Add x-svq to NetdevVhostVDPAOptions
586cba
MIME-Version: 1.0
586cba
Content-Type: text/plain; charset=UTF-8
586cba
Content-Transfer-Encoding: 8bit
586cba
586cba
RH-Author: Eugenio Pérez <eperezma@redhat.com>
586cba
RH-MergeRequest: 108: Net Control Virtqueue shadow Support
586cba
RH-Commit: [27/27] bd85496c2a8c1ebf34f908fca2be2ab9852fd0e9 (eperezmartin/qemu-kvm)
586cba
RH-Bugzilla: 1939363
586cba
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
586cba
RH-Acked-by: Cindy Lu <lulu@redhat.com>
586cba
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
586cba
586cba
Bugzilla: https://bugzilla.redhat.com/1939363
586cba
586cba
Upstream Status: git://git.qemu.org/qemu.git
586cba
586cba
commit 1576dbb5bbc49344c606e969ec749be70c0fd94e
586cba
Author: Eugenio Pérez <eperezma@redhat.com>
586cba
Date:   Wed Jul 20 08:59:46 2022 +0200
586cba
586cba
    vdpa: Add x-svq to NetdevVhostVDPAOptions
586cba
586cba
    Finally offering the possibility to enable SVQ from the command line.
586cba
586cba
    Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
586cba
    Acked-by: Markus Armbruster <armbru@redhat.com>
586cba
    Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
586cba
    Signed-off-by: Jason Wang <jasowang@redhat.com>
586cba
586cba
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
586cba
---
586cba
 net/vhost-vdpa.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++--
586cba
 qapi/net.json    |  9 +++++-
586cba
 2 files changed, 77 insertions(+), 4 deletions(-)
586cba
586cba
diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
586cba
index 8b76dac966..50672bcd66 100644
586cba
--- a/net/vhost-vdpa.c
586cba
+++ b/net/vhost-vdpa.c
586cba
@@ -75,6 +75,28 @@ const int vdpa_feature_bits[] = {
586cba
     VHOST_INVALID_FEATURE_BIT
586cba
 };
586cba
 
586cba
+/** Supported device specific feature bits with SVQ */
586cba
+static const uint64_t vdpa_svq_device_features =
586cba
+    BIT_ULL(VIRTIO_NET_F_CSUM) |
586cba
+    BIT_ULL(VIRTIO_NET_F_GUEST_CSUM) |
586cba
+    BIT_ULL(VIRTIO_NET_F_MTU) |
586cba
+    BIT_ULL(VIRTIO_NET_F_MAC) |
586cba
+    BIT_ULL(VIRTIO_NET_F_GUEST_TSO4) |
586cba
+    BIT_ULL(VIRTIO_NET_F_GUEST_TSO6) |
586cba
+    BIT_ULL(VIRTIO_NET_F_GUEST_ECN) |
586cba
+    BIT_ULL(VIRTIO_NET_F_GUEST_UFO) |
586cba
+    BIT_ULL(VIRTIO_NET_F_HOST_TSO4) |
586cba
+    BIT_ULL(VIRTIO_NET_F_HOST_TSO6) |
586cba
+    BIT_ULL(VIRTIO_NET_F_HOST_ECN) |
586cba
+    BIT_ULL(VIRTIO_NET_F_HOST_UFO) |
586cba
+    BIT_ULL(VIRTIO_NET_F_MRG_RXBUF) |
586cba
+    BIT_ULL(VIRTIO_NET_F_STATUS) |
586cba
+    BIT_ULL(VIRTIO_NET_F_CTRL_VQ) |
586cba
+    BIT_ULL(VIRTIO_F_ANY_LAYOUT) |
586cba
+    BIT_ULL(VIRTIO_NET_F_CTRL_MAC_ADDR) |
586cba
+    BIT_ULL(VIRTIO_NET_F_RSC_EXT) |
586cba
+    BIT_ULL(VIRTIO_NET_F_STANDBY);
586cba
+
586cba
 VHostNetState *vhost_vdpa_get_vhost_net(NetClientState *nc)
586cba
 {
586cba
     VhostVDPAState *s = DO_UPCAST(VhostVDPAState, nc, nc);
586cba
@@ -133,9 +155,13 @@ err_init:
586cba
 static void vhost_vdpa_cleanup(NetClientState *nc)
586cba
 {
586cba
     VhostVDPAState *s = DO_UPCAST(VhostVDPAState, nc, nc);
586cba
+    struct vhost_dev *dev = &s->vhost_net->dev;
586cba
 
586cba
     qemu_vfree(s->cvq_cmd_out_buffer);
586cba
     qemu_vfree(s->cvq_cmd_in_buffer);
586cba
+    if (dev->vq_index + dev->nvqs == dev->vq_index_end) {
586cba
+        g_clear_pointer(&s->vhost_vdpa.iova_tree, vhost_iova_tree_delete);
586cba
+    }
586cba
     if (s->vhost_net) {
586cba
         vhost_net_cleanup(s->vhost_net);
586cba
         g_free(s->vhost_net);
586cba
@@ -437,7 +463,9 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer,
586cba
                                            int vdpa_device_fd,
586cba
                                            int queue_pair_index,
586cba
                                            int nvqs,
586cba
-                                           bool is_datapath)
586cba
+                                           bool is_datapath,
586cba
+                                           bool svq,
586cba
+                                           VhostIOVATree *iova_tree)
586cba
 {
586cba
     NetClientState *nc = NULL;
586cba
     VhostVDPAState *s;
586cba
@@ -455,6 +483,8 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer,
586cba
 
586cba
     s->vhost_vdpa.device_fd = vdpa_device_fd;
586cba
     s->vhost_vdpa.index = queue_pair_index;
586cba
+    s->vhost_vdpa.shadow_vqs_enabled = svq;
586cba
+    s->vhost_vdpa.iova_tree = iova_tree;
586cba
     if (!is_datapath) {
586cba
         s->cvq_cmd_out_buffer = qemu_memalign(qemu_real_host_page_size,
586cba
                                             vhost_vdpa_net_cvq_cmd_page_len());
586cba
@@ -465,6 +495,8 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer,
586cba
 
586cba
         s->vhost_vdpa.shadow_vq_ops = &vhost_vdpa_net_svq_ops;
586cba
         s->vhost_vdpa.shadow_vq_ops_opaque = s;
586cba
+        error_setg(&s->vhost_vdpa.migration_blocker,
586cba
+                   "Migration disabled: vhost-vdpa uses CVQ.");
586cba
     }
586cba
     ret = vhost_vdpa_add(nc, (void *)&s->vhost_vdpa, queue_pair_index, nvqs);
586cba
     if (ret) {
586cba
@@ -474,6 +506,14 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer,
586cba
     return nc;
586cba
 }
586cba
 
586cba
+static int vhost_vdpa_get_iova_range(int fd,
586cba
+                                     struct vhost_vdpa_iova_range *iova_range)
586cba
+{
586cba
+    int ret = ioctl(fd, VHOST_VDPA_GET_IOVA_RANGE, iova_range);
586cba
+
586cba
+    return ret < 0 ? -errno : 0;
586cba
+}
586cba
+
586cba
 static int vhost_vdpa_get_features(int fd, uint64_t *features, Error **errp)
586cba
 {
586cba
     int ret = ioctl(fd, VHOST_GET_FEATURES, features);
586cba
@@ -524,6 +564,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name,
586cba
     uint64_t features;
586cba
     int vdpa_device_fd;
586cba
     g_autofree NetClientState **ncs = NULL;
586cba
+    g_autoptr(VhostIOVATree) iova_tree = NULL;
586cba
     NetClientState *nc;
586cba
     int queue_pairs, r, i, has_cvq = 0;
586cba
 
586cba
@@ -551,22 +592,45 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name,
586cba
         return queue_pairs;
586cba
     }
586cba
 
586cba
+    if (opts->x_svq) {
586cba
+        struct vhost_vdpa_iova_range iova_range;
586cba
+
586cba
+        uint64_t invalid_dev_features =
586cba
+            features & ~vdpa_svq_device_features &
586cba
+            /* Transport are all accepted at this point */
586cba
+            ~MAKE_64BIT_MASK(VIRTIO_TRANSPORT_F_START,
586cba
+                             VIRTIO_TRANSPORT_F_END - VIRTIO_TRANSPORT_F_START);
586cba
+
586cba
+        if (invalid_dev_features) {
586cba
+            error_setg(errp, "vdpa svq does not work with features 0x%" PRIx64,
586cba
+                       invalid_dev_features);
586cba
+            goto err_svq;
586cba
+        }
586cba
+
586cba
+        vhost_vdpa_get_iova_range(vdpa_device_fd, &iova_range);
586cba
+        iova_tree = vhost_iova_tree_new(iova_range.first, iova_range.last);
586cba
+    }
586cba
+
586cba
     ncs = g_malloc0(sizeof(*ncs) * queue_pairs);
586cba
 
586cba
     for (i = 0; i < queue_pairs; i++) {
586cba
         ncs[i] = net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name,
586cba
-                                     vdpa_device_fd, i, 2, true);
586cba
+                                     vdpa_device_fd, i, 2, true, opts->x_svq,
586cba
+                                     iova_tree);
586cba
         if (!ncs[i])
586cba
             goto err;
586cba
     }
586cba
 
586cba
     if (has_cvq) {
586cba
         nc = net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name,
586cba
-                                 vdpa_device_fd, i, 1, false);
586cba
+                                 vdpa_device_fd, i, 1, false,
586cba
+                                 opts->x_svq, iova_tree);
586cba
         if (!nc)
586cba
             goto err;
586cba
     }
586cba
 
586cba
+    /* iova_tree ownership belongs to last NetClientState */
586cba
+    g_steal_pointer(&iova_tree);
586cba
     return 0;
586cba
 
586cba
 err:
586cba
@@ -575,6 +639,8 @@ err:
586cba
             qemu_del_net_client(ncs[i]);
586cba
         }
586cba
     }
586cba
+
586cba
+err_svq:
586cba
     qemu_close(vdpa_device_fd);
586cba
 
586cba
     return -1;
586cba
diff --git a/qapi/net.json b/qapi/net.json
586cba
index b92f3f5fb4..92848e4362 100644
586cba
--- a/qapi/net.json
586cba
+++ b/qapi/net.json
586cba
@@ -445,12 +445,19 @@
586cba
 # @queues: number of queues to be created for multiqueue vhost-vdpa
586cba
 #          (default: 1)
586cba
 #
586cba
+# @x-svq: Start device with (experimental) shadow virtqueue. (Since 7.1)
586cba
+#         (default: false)
586cba
+#
586cba
+# Features:
586cba
+# @unstable: Member @x-svq is experimental.
586cba
+#
586cba
 # Since: 5.1
586cba
 ##
586cba
 { 'struct': 'NetdevVhostVDPAOptions',
586cba
   'data': {
586cba
     '*vhostdev':     'str',
586cba
-    '*queues':       'int' } }
586cba
+    '*queues':       'int',
586cba
+    '*x-svq':        {'type': 'bool', 'features' : [ 'unstable'] } } }
586cba
 
586cba
 ##
586cba
 # @NetClientDriver:
586cba
-- 
586cba
2.31.1
586cba