thebeanogamer / rpms / qemu-kvm

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