From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by dpdk.org (Postfix) with ESMTP id DD9355B1C for ; Wed, 14 Nov 2018 12:16:44 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Nov 2018 03:16:43 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,232,1539673200"; d="scan'208";a="107972856" Received: from silpixa00398673.ir.intel.com (HELO silpixa00398673.ger.corp.intel.com) ([10.237.223.54]) by fmsmga001.fm.intel.com with ESMTP; 14 Nov 2018 03:16:42 -0800 From: Fan Zhang To: dev@dpdk.org Cc: maxime.coquelin@redhat.com Date: Wed, 14 Nov 2018 11:16:42 +0000 Message-Id: <20181114111642.5526-1-roy.fan.zhang@intel.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20181030144852.43339-1-roy.fan.zhang@intel.com> References: <20181030144852.43339-1-roy.fan.zhang@intel.com> Subject: [dpdk-dev] [PATCH v2] examples/vhost_crypto: fix zero copy 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: , X-List-Received-Date: Wed, 14 Nov 2018 11:16:45 -0000 This patch fixes the zero copy enable problem for vhost crypto sample application. For some Crypto PMDs such as AESNI-MB and AESNI-GCM the data to be processed will be made a copy in the same buffer but next to the data. For example, to encrypt 64 bytes data the PMD will copy this data from offset 64 to offset 123. This requires the application provides the buffer with at least double of the data size. However there is no way for VMs to know this limitation. When zero-copy is enabled in Vhost the PMD may overwrite the buffer next to the VM data to be processed, and further cause problems such as Segmentation Fault or even worse, crashes the VM. To fix the problem the user should avoid enabling the zero copy for these Crypto PMDs. This patch adds the checking of the PMD names to see if zero copy can be applied. Fixes: 709521f4c2cd ("examples/vhost_crypto: support multi-core") Signed-off-by: Fan Zhang --- v2: - removed unecessary checks - Changed log message when zero-copy is not applicable. examples/vhost_crypto/main.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/examples/vhost_crypto/main.c b/examples/vhost_crypto/main.c index cbb5e49d2..f08babd97 100644 --- a/examples/vhost_crypto/main.c +++ b/examples/vhost_crypto/main.c @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -442,6 +443,9 @@ free_resource(void) struct lcore_option *lo = &options.los[i]; struct vhost_crypto_info *info = options.infos[i]; + if (!info) + continue; + rte_mempool_free(info->cop_pool); rte_mempool_free(info->sess_pool); @@ -493,6 +497,19 @@ main(int argc, char *argv[]) info->nb_vids = lo->nb_sockets; rte_cryptodev_info_get(info->cid, &dev_info); + if (options.zero_copy == RTE_VHOST_CRYPTO_ZERO_COPY_ENABLE) { +#define VHOST_CRYPTO_CDEV_NAME_AESNI_MB_PMD crypto_aesni_mb +#define VHOST_CRYPTO_CDEV_NAME_AESNI_GCM_PMD crypto_aesni_gcm + if (strstr(dev_info.driver_name, + RTE_STR(VHOST_CRYPTO_CDEV_NAME_AESNI_MB_PMD)) || + strstr(dev_info.driver_name, + RTE_STR(VHOST_CRYPTO_CDEV_NAME_AESNI_GCM_PMD))) + RTE_LOG(ERR, USER1, "Cannot enable zero-copy in %s\n", + dev_info.driver_name); + ret = -EPERM; + goto error_exit; + } + if (dev_info.max_nb_queue_pairs < info->qid + 1) { RTE_LOG(ERR, USER1, "Number of queues cannot over %u", dev_info.max_nb_queue_pairs); -- 2.13.6