vhost/crypto: fix feature negotiation
authorFan Zhang <roy.fan.zhang@intel.com>
Fri, 2 Oct 2020 15:36:01 +0000 (16:36 +0100)
committerFerruh Yigit <ferruh.yigit@intel.com>
Fri, 16 Oct 2020 17:18:47 +0000 (19:18 +0200)
This patch fixes the feature negotiation for vhost crypto during
initialization. The patch uses the newly created driver start
function to inform the driver type with the fixed vhost features.
In addition the patch provides a new API specifically used by
the application to start a vhost-crypto driver.

Fixes: 939066d96563 ("vhost/crypto: add public function implementation")
Cc: stable@dpdk.org
Signed-off-by: Fan Zhang <roy.fan.zhang@intel.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
doc/guides/rel_notes/release_20_11.rst
examples/vhost_crypto/main.c
lib/librte_vhost/rte_vhost_crypto.h
lib/librte_vhost/rte_vhost_version.map
lib/librte_vhost/vhost_crypto.c

index 48717ee..b975b3e 100644 (file)
@@ -381,6 +381,9 @@ API Changes
 
 * vhost: Moved vDPA APIs from experimental to stable.
 
+* vhost: Add a new function ``rte_vhost_crypto_driver_start`` to be called
+  instead of ``rte_vhost_driver_start`` by crypto applications.
+
 * cryptodev: The structure ``rte_crypto_sym_vec`` is updated to support both
   cpu_crypto synchrounous operation and asynchronous raw data-path APIs.
 
index d78fd9b..11ad491 100644 (file)
@@ -598,7 +598,8 @@ main(int argc, char *argv[])
                        rte_vhost_driver_callback_register(lo->socket_files[j],
                                &virtio_crypto_device_ops);
 
-                       ret = rte_vhost_driver_start(lo->socket_files[j]);
+                       ret = rte_vhost_crypto_driver_start(
+                                       lo->socket_files[j]);
                        if (ret < 0)  {
                                RTE_LOG(ERR, USER1, "failed to start vhost.\n");
                                goto error_exit;
index b54d61d..c809c46 100644 (file)
@@ -20,6 +20,18 @@ enum rte_vhost_crypto_zero_copy {
        RTE_VHOST_CRYPTO_MAX_ZERO_COPY_OPTIONS
 };
 
+/**
+ * Start vhost crypto driver
+ *
+ * @param path
+ *  The vhost-user socket file path
+ * @return
+ *  0 on success, -1 on failure
+ */
+__rte_experimental
+int
+rte_vhost_crypto_driver_start(const char *path);
+
 /**
  *  Create Vhost-crypto instance
  *
index 55e98e5..9183d6f 100644 (file)
@@ -55,6 +55,7 @@ EXPERIMENTAL {
        rte_vhost_driver_get_protocol_features;
        rte_vhost_driver_get_queue_num;
        rte_vhost_crypto_create;
+       rte_vhost_crypto_driver_start;
        rte_vhost_crypto_free;
        rte_vhost_crypto_fetch_requests;
        rte_vhost_crypto_finalize_requests;
index e08f9c6..6689c52 100644 (file)
 #define VC_LOG_DBG(fmt, args...)
 #endif
 
-#define VIRTIO_CRYPTO_FEATURES ((1 << VIRTIO_F_NOTIFY_ON_EMPTY) |      \
-               (1 << VIRTIO_RING_F_INDIRECT_DESC) |                    \
-               (1 << VIRTIO_RING_F_EVENT_IDX) |                        \
-               (1 << VIRTIO_CRYPTO_SERVICE_CIPHER) |                   \
-               (1 << VIRTIO_CRYPTO_SERVICE_MAC) |                      \
-               (1 << VIRTIO_NET_F_CTRL_VQ) |                           \
-               (1 << VHOST_USER_PROTOCOL_F_CONFIG))
+#define VIRTIO_CRYPTO_FEATURES ((1ULL << VIRTIO_F_NOTIFY_ON_EMPTY) |   \
+               (1ULL << VIRTIO_RING_F_INDIRECT_DESC) |                 \
+               (1ULL << VIRTIO_RING_F_EVENT_IDX) |                     \
+               (1ULL << VIRTIO_NET_F_CTRL_VQ) |                        \
+               (1ULL << VIRTIO_F_VERSION_1) |                          \
+               (1ULL << VHOST_USER_F_PROTOCOL_FEATURES))
 
 #define IOVA_TO_VVA(t, r, a, l, p)                                     \
        ((t)(uintptr_t)vhost_iova_to_vva(r->dev, r->vq, a, l, p))
@@ -1400,6 +1399,27 @@ vhost_crypto_complete_one_vm_requests(struct rte_crypto_op **ops,
        return processed;
 }
 
+int
+rte_vhost_crypto_driver_start(const char *path)
+{
+       uint64_t protocol_features;
+       int ret;
+
+       ret = rte_vhost_driver_set_features(path, VIRTIO_CRYPTO_FEATURES);
+       if (ret)
+               return -1;
+
+       ret = rte_vhost_driver_get_protocol_features(path, &protocol_features);
+       if (ret)
+               return -1;
+       protocol_features |= (1ULL << VHOST_USER_PROTOCOL_F_CONFIG);
+       ret = rte_vhost_driver_set_protocol_features(path, protocol_features);
+       if (ret)
+               return -1;
+
+       return rte_vhost_driver_start(path);
+}
+
 int
 rte_vhost_crypto_create(int vid, uint8_t cryptodev_id,
                struct rte_mempool *sess_pool,
@@ -1417,13 +1437,6 @@ rte_vhost_crypto_create(int vid, uint8_t cryptodev_id,
                return -EINVAL;
        }
 
-       ret = rte_vhost_driver_set_features(dev->ifname,
-                       VIRTIO_CRYPTO_FEATURES);
-       if (ret < 0) {
-               VC_LOG_ERR("Error setting features");
-               return -1;
-       }
-
        vcrypto = rte_zmalloc_socket(NULL, sizeof(*vcrypto),
                        RTE_CACHE_LINE_SIZE, socket_id);
        if (!vcrypto) {