From: Fan Zhang Date: Fri, 2 Oct 2020 15:36:01 +0000 (+0100) Subject: vhost/crypto: fix feature negotiation X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=ea1b835a0e74d80915e2e717f20418e2c9f948a2;p=dpdk.git vhost/crypto: fix feature negotiation 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 Reviewed-by: Maxime Coquelin --- diff --git a/doc/guides/rel_notes/release_20_11.rst b/doc/guides/rel_notes/release_20_11.rst index 48717ee536..b975b3e853 100644 --- a/doc/guides/rel_notes/release_20_11.rst +++ b/doc/guides/rel_notes/release_20_11.rst @@ -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. diff --git a/examples/vhost_crypto/main.c b/examples/vhost_crypto/main.c index d78fd9b810..11ad491597 100644 --- a/examples/vhost_crypto/main.c +++ b/examples/vhost_crypto/main.c @@ -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; diff --git a/lib/librte_vhost/rte_vhost_crypto.h b/lib/librte_vhost/rte_vhost_crypto.h index b54d61db69..c809c46a21 100644 --- a/lib/librte_vhost/rte_vhost_crypto.h +++ b/lib/librte_vhost/rte_vhost_crypto.h @@ -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 * diff --git a/lib/librte_vhost/rte_vhost_version.map b/lib/librte_vhost/rte_vhost_version.map index 55e98e557b..9183d6f2fc 100644 --- a/lib/librte_vhost/rte_vhost_version.map +++ b/lib/librte_vhost/rte_vhost_version.map @@ -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; diff --git a/lib/librte_vhost/vhost_crypto.c b/lib/librte_vhost/vhost_crypto.c index e08f9c6d75..6689c52df2 100644 --- a/lib/librte_vhost/vhost_crypto.c +++ b/lib/librte_vhost/vhost_crypto.c @@ -35,13 +35,12 @@ #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) {