From patchwork Fri Oct 2 15:36:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fan Zhang X-Patchwork-Id: 79548 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id CD6A3A04BA; Fri, 2 Oct 2020 17:36:15 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 519871D957; Fri, 2 Oct 2020 17:36:13 +0200 (CEST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by dpdk.org (Postfix) with ESMTP id F070F1D6F6; Fri, 2 Oct 2020 17:36:09 +0200 (CEST) IronPort-SDR: e6oejV2bY4Qrp0R4wr1RJzyldrhFQ8zt4rUSakF2oUHSG+YDEOnTMt/RBI43zV1i2oIT7cVZ5B 15fw2JRE+9CA== X-IronPort-AV: E=McAfee;i="6000,8403,9762"; a="247754196" X-IronPort-AV: E=Sophos;i="5.77,328,1596524400"; d="scan'208";a="247754196" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Oct 2020 08:36:08 -0700 IronPort-SDR: LnG7y4RMiSZGxsvTbQIozJ4uzOIm55GgSt3+zZsrmgLUOKTtOpDagVsk/avWxqZmp417GUCXUk xtWQP8LI7l5w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,328,1596524400"; d="scan'208";a="515193801" Received: from silpixa00398673.ir.intel.com (HELO silpixa00398673.ger.corp.intel.com) ([10.237.223.136]) by fmsmga006.fm.intel.com with ESMTP; 02 Oct 2020 08:36:06 -0700 From: Fan Zhang To: dev@dpdk.org Cc: chenbo.xia@intel.com, maxime.coquelin@redhat.com, changpeng.liu@intel.com, ferruh.yigit@intel.com, stable@dpdk.org, Fan Zhang Date: Fri, 2 Oct 2020 16:36:00 +0100 Message-Id: <20201002153601.84097-2-roy.fan.zhang@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201002153601.84097-1-roy.fan.zhang@intel.com> References: <20201002083615.45470-1-roy.fan.zhang@intel.com> <20201002153601.84097-1-roy.fan.zhang@intel.com> MIME-Version: 1.0 Subject: [dpdk-dev] [dpdk-dev v2 1/2] vhost: add backend type in driver start X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This patch adds an internal driver start function with a newly added backend type identifier as parameter. With this way different built-in driver types (net, crypto) can be identified. Signed-off-by: Fan Zhang --- lib/librte_vhost/socket.c | 39 ++++++++++++++++++++++++++++------- lib/librte_vhost/vhost_user.h | 8 +++++++ 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/lib/librte_vhost/socket.c b/lib/librte_vhost/socket.c index 0169d3648..a53e536ac 100644 --- a/lib/librte_vhost/socket.c +++ b/lib/librte_vhost/socket.c @@ -38,7 +38,7 @@ struct vhost_user_socket { bool is_server; bool reconnect; bool iommu_support; - bool use_builtin_virtio_net; + enum virtio_backend_type backend_type; bool extbuf; bool linearbuf; bool async_copy; @@ -224,7 +224,9 @@ vhost_user_add_connection(int fd, struct vhost_user_socket *vsocket) size = strnlen(vsocket->path, PATH_MAX); vhost_set_ifname(vid, vsocket->path, size); - vhost_set_builtin_virtio_net(vid, vsocket->use_builtin_virtio_net); + vhost_set_builtin_virtio_net(vid, + vsocket->backend_type == VIRTIO_DEV_BUILTIN_NET ? + true : false); vhost_attach_vdpa_device(vid, vsocket->vdpa_dev); @@ -632,7 +634,7 @@ rte_vhost_driver_disable_features(const char *path, uint64_t features) pthread_mutex_lock(&vhost_user.mutex); vsocket = find_vhost_user_socket(path); - /* Note that use_builtin_virtio_net is not affected by this function + /* Note that backend type is not affected by this function * since callers may want to selectively disable features of the * built-in vhost net device backend. */ @@ -681,7 +683,8 @@ rte_vhost_driver_set_features(const char *path, uint64_t features) /* Anyone setting feature bits is implementing their own vhost * device backend. */ - vsocket->use_builtin_virtio_net = false; + if (vsocket->backend_type == VIRTIO_DEV_BUILTIN_NET) + vsocket->backend_type = VIRTIO_DEV_UNKNOWN; } pthread_mutex_unlock(&vhost_user.mutex); @@ -899,7 +902,7 @@ rte_vhost_driver_register(const char *path, uint64_t flags) * rte_vhost_driver_set_features(), which will overwrite following * two values. */ - vsocket->use_builtin_virtio_net = true; + vsocket->backend_type = VIRTIO_DEV_BUILTIN_NET; vsocket->supported_features = VIRTIO_NET_SUPPORTED_FEATURES; vsocket->features = VIRTIO_NET_SUPPORTED_FEATURES; vsocket->protocol_features = VHOST_USER_PROTOCOL_FEATURES; @@ -1117,10 +1120,17 @@ vhost_driver_callback_get(const char *path) } int -rte_vhost_driver_start(const char *path) +vhost_driver_start(const char *path, enum virtio_backend_type backend_type) { struct vhost_user_socket *vsocket; static pthread_t fdset_tid; + int ret; + + if (backend_type <= VIRTIO_DEV_UNKNOWN || + backend_type > VIRTIO_DEV_BUILTIN_CRYPTO) { + VHOST_LOG_CONFIG(ERR, "Wrong backend type\n"); + return -1; + } pthread_mutex_lock(&vhost_user.mutex); vsocket = find_vhost_user_socket(path); @@ -1153,7 +1163,20 @@ rte_vhost_driver_start(const char *path) } if (vsocket->is_server) - return vhost_user_start_server(vsocket); + ret = vhost_user_start_server(vsocket); else - return vhost_user_start_client(vsocket); + ret = vhost_user_start_client(vsocket); + + if (ret < 0) + return ret; + + vsocket->backend_type = backend_type; + + return 0; +} + +int +rte_vhost_driver_start(const char *path) +{ + return vhost_driver_start(path, VIRTIO_DEV_BUILTIN_NET); } diff --git a/lib/librte_vhost/vhost_user.h b/lib/librte_vhost/vhost_user.h index 16fe03f88..9f526e676 100644 --- a/lib/librte_vhost/vhost_user.h +++ b/lib/librte_vhost/vhost_user.h @@ -158,6 +158,12 @@ typedef struct VhostUserMsg { /* The version of the protocol we support */ #define VHOST_USER_VERSION 0x1 +/* virtio backend types */ +enum virtio_backend_type { + VIRTIO_DEV_UNKNOWN = 0, /* Likely external */ + VIRTIO_DEV_BUILTIN_NET, /* Virtio-net device */ + VIRTIO_DEV_BUILTIN_CRYPTO, /* Virtio-crypto device */ +}; /* vhost_user.c */ int vhost_user_msg_handler(int vid, int fd); @@ -167,5 +173,7 @@ int vhost_user_iotlb_miss(struct virtio_net *dev, uint64_t iova, uint8_t perm); int read_fd_message(int sockfd, char *buf, int buflen, int *fds, int max_fds, int *fd_num); int send_fd_message(int sockfd, char *buf, int buflen, int *fds, int fd_num); +int vhost_driver_start(const char *path, + enum virtio_backend_type backend_type); #endif From patchwork Fri Oct 2 15:36:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fan Zhang X-Patchwork-Id: 79550 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 563DFA04BA; Fri, 2 Oct 2020 17:36:57 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id CE9E41D992; Fri, 2 Oct 2020 17:36:16 +0200 (CEST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by dpdk.org (Postfix) with ESMTP id C987D1D970; Fri, 2 Oct 2020 17:36:12 +0200 (CEST) IronPort-SDR: OhYx11x8tDTLTrXCaAvRrVdH+X5Uduvg18oYFr1XB0GL+rEEf5MT0cFwjJj2zXBlIoiPjCjRsV sezpQR+3SnCQ== X-IronPort-AV: E=McAfee;i="6000,8403,9762"; a="247754236" X-IronPort-AV: E=Sophos;i="5.77,328,1596524400"; d="scan'208";a="247754236" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Oct 2020 08:36:12 -0700 IronPort-SDR: G7CmaDQBrgnTEp1KrT3nil2v2QnQqS+QSsjlJBaX1rD0NDH6YTIwDsnaxQRWNYW2DDRuiGlAQl uyIg73l37WrA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,328,1596524400"; d="scan'208";a="515193808" Received: from silpixa00398673.ir.intel.com (HELO silpixa00398673.ger.corp.intel.com) ([10.237.223.136]) by fmsmga006.fm.intel.com with ESMTP; 02 Oct 2020 08:36:08 -0700 From: Fan Zhang To: dev@dpdk.org Cc: chenbo.xia@intel.com, maxime.coquelin@redhat.com, changpeng.liu@intel.com, ferruh.yigit@intel.com, stable@dpdk.org, Fan Zhang Date: Fri, 2 Oct 2020 16:36:01 +0100 Message-Id: <20201002153601.84097-3-roy.fan.zhang@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201002153601.84097-1-roy.fan.zhang@intel.com> References: <20201002083615.45470-1-roy.fan.zhang@intel.com> <20201002153601.84097-1-roy.fan.zhang@intel.com> MIME-Version: 1.0 Subject: [dpdk-dev] [dpdk-dev v2 2/2] vhost/crypto: fix feature negotiation X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 addtion 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: roy.fan.zhang@intel.com Signed-off-by: Fan Zhang Reviewed-by: Maxime Coquelin Tested-by: Jiang, YuX --- examples/vhost_crypto/main.c | 3 +- lib/librte_vhost/rte_vhost_crypto.h | 12 ++++++++ lib/librte_vhost/rte_vhost_version.map | 1 + lib/librte_vhost/vhost_crypto.c | 41 +++++++++++++++++--------- 4 files changed, 42 insertions(+), 15 deletions(-) diff --git a/examples/vhost_crypto/main.c b/examples/vhost_crypto/main.c index d78fd9b81..11ad49159 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 b54d61db6..c809c46a2 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 55e98e557..9183d6f2f 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 e08f9c6d7..6195958d2 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 vhost_driver_start(path, VIRTIO_DEV_BUILTIN_CRYPTO); +} + 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) {