Blame SOURCES/kvm-vdpa-Extract-get-features-part-from-vhost_vdpa_get_m.patch

586cba
From 9a290bd74f983f3a65aa9ec5df2da9aa94bfdecd 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:05:42 +0200
586cba
Subject: [PATCH 25/32] vdpa: Extract get features part from
586cba
 vhost_vdpa_get_max_queue_pairs
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: [25/27] 654ad68e10a4df84cced923c64e72d500721ad67 (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 8170ab3f43989680491d00f1017f60b25d346114
586cba
Author: Eugenio Pérez <eperezma@redhat.com>
586cba
Date:   Wed Jul 20 08:59:44 2022 +0200
586cba
586cba
    vdpa: Extract get features part from vhost_vdpa_get_max_queue_pairs
586cba
586cba
    To know the device features is needed for CVQ SVQ, so SVQ knows if it
586cba
    can handle all commands or not. Extract from
586cba
    vhost_vdpa_get_max_queue_pairs so we can reuse it.
586cba
586cba
    Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
586cba
    Acked-by: Jason Wang <jasowang@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 | 30 ++++++++++++++++++++----------
586cba
 1 file changed, 20 insertions(+), 10 deletions(-)
586cba
586cba
diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
586cba
index df42822463..8b76dac966 100644
586cba
--- a/net/vhost-vdpa.c
586cba
+++ b/net/vhost-vdpa.c
586cba
@@ -474,20 +474,24 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer,
586cba
     return nc;
586cba
 }
586cba
 
586cba
-static int vhost_vdpa_get_max_queue_pairs(int fd, int *has_cvq, Error **errp)
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
+    if (unlikely(ret < 0)) {
586cba
+        error_setg_errno(errp, errno,
586cba
+                         "Fail to query features from vhost-vDPA device");
586cba
+    }
586cba
+    return ret;
586cba
+}
586cba
+
586cba
+static int vhost_vdpa_get_max_queue_pairs(int fd, uint64_t features,
586cba
+                                          int *has_cvq, Error **errp)
586cba
 {
586cba
     unsigned long config_size = offsetof(struct vhost_vdpa_config, buf);
586cba
     g_autofree struct vhost_vdpa_config *config = NULL;
586cba
     __virtio16 *max_queue_pairs;
586cba
-    uint64_t features;
586cba
     int ret;
586cba
 
586cba
-    ret = ioctl(fd, VHOST_GET_FEATURES, &features);
586cba
-    if (ret) {
586cba
-        error_setg(errp, "Fail to query features from vhost-vDPA device");
586cba
-        return ret;
586cba
-    }
586cba
-
586cba
     if (features & (1 << VIRTIO_NET_F_CTRL_VQ)) {
586cba
         *has_cvq = 1;
586cba
     } else {
586cba
@@ -517,10 +521,11 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name,
586cba
                         NetClientState *peer, Error **errp)
586cba
 {
586cba
     const NetdevVhostVDPAOptions *opts;
586cba
+    uint64_t features;
586cba
     int vdpa_device_fd;
586cba
     g_autofree NetClientState **ncs = NULL;
586cba
     NetClientState *nc;
586cba
-    int queue_pairs, i, has_cvq = 0;
586cba
+    int queue_pairs, r, i, has_cvq = 0;
586cba
 
586cba
     assert(netdev->type == NET_CLIENT_DRIVER_VHOST_VDPA);
586cba
     opts = &netdev->u.vhost_vdpa;
586cba
@@ -534,7 +539,12 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name,
586cba
         return -errno;
586cba
     }
586cba
 
586cba
-    queue_pairs = vhost_vdpa_get_max_queue_pairs(vdpa_device_fd,
586cba
+    r = vhost_vdpa_get_features(vdpa_device_fd, &features, errp);
586cba
+    if (unlikely(r < 0)) {
586cba
+        return r;
586cba
+    }
586cba
+
586cba
+    queue_pairs = vhost_vdpa_get_max_queue_pairs(vdpa_device_fd, features,
586cba
                                                  &has_cvq, errp);
586cba
     if (queue_pairs < 0) {
586cba
         qemu_close(vdpa_device_fd);
586cba
-- 
586cba
2.31.1
586cba