From patchwork Thu Jun 14 11:02:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fan Zhang X-Patchwork-Id: 41118 X-Patchwork-Delegate: pablo.de.lara.guarch@intel.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6C9751E34F; Thu, 14 Jun 2018 13:12:21 +0200 (CEST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by dpdk.org (Postfix) with ESMTP id 12F5D1E345; Thu, 14 Jun 2018 13:12:19 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Jun 2018 04:12:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,222,1526367600"; d="scan'208";a="59181549" Received: from silpixa00398673.ir.intel.com (HELO silpixa00398673.ger.corp.intel.com) ([10.237.223.54]) by orsmga003.jf.intel.com with ESMTP; 14 Jun 2018 04:12:16 -0700 From: Fan Zhang To: dev@dpdk.org Cc: pablo.de.lara.guarch@intel.com, jianjay.zhou@huawei.com, stable@dpdk.org Date: Thu, 14 Jun 2018 12:02:57 +0100 Message-Id: <20180614110257.10967-1-roy.fan.zhang@intel.com> X-Mailer: git-send-email 2.13.6 Subject: [dpdk-dev] [PATCH] crypto/virtio: fix iv physical address 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" The physical address of IV required by Virtio was computed using crypto operations' physical address plus the offset. However not all crypto ops will have physical address field initialized and compute it runtimely is costly. This patch fixes this problem by adding iv field in virtio_crypto_op_cookie and does a memcpy of iv instead. Fixes: 82adb12a1fce ("crypto/virtio: support burst enqueue/dequeue") Cc: stable@dpdk.org Signed-off-by: Fan Zhang --- drivers/crypto/virtio/virtio_cryptodev.c | 6 ++++++ drivers/crypto/virtio/virtio_cryptodev.h | 3 +++ drivers/crypto/virtio/virtio_rxtx.c | 8 +++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/crypto/virtio/virtio_cryptodev.c b/drivers/crypto/virtio/virtio_cryptodev.c index df88953f6..6ffa7619c 100644 --- a/drivers/crypto/virtio/virtio_cryptodev.c +++ b/drivers/crypto/virtio/virtio_cryptodev.c @@ -1223,6 +1223,12 @@ virtio_crypto_sym_pad_op_ctrl_req( /* Get cipher xform from crypto xform chain */ cipher_xform = virtio_crypto_get_cipher_xform(xform); if (cipher_xform) { + if (cipher_xform->iv.length > VIRTIO_CRYPTO_MAX_IV_SIZE) { + VIRTIO_CRYPTO_SESSION_LOG_ERR( + "cipher IV cannot longer than %u", + VIRTIO_CRYPTO_MAX_IV_SIZE); + return -1; + } if (is_chainned) ret = virtio_crypto_sym_pad_cipher_param( &ctrl->u.sym_create_session.u.chain.para diff --git a/drivers/crypto/virtio/virtio_cryptodev.h b/drivers/crypto/virtio/virtio_cryptodev.h index e402c0309..676e008d9 100644 --- a/drivers/crypto/virtio/virtio_cryptodev.h +++ b/drivers/crypto/virtio/virtio_cryptodev.h @@ -16,6 +16,8 @@ #define NUM_ENTRY_VIRTIO_CRYPTO_OP 7 +#define VIRTIO_CRYPTO_MAX_IV_SIZE 32 + extern uint8_t cryptodev_virtio_driver_id; enum virtio_crypto_cmd_id { @@ -29,6 +31,7 @@ struct virtio_crypto_op_cookie { struct virtio_crypto_op_data_req data_req; struct virtio_crypto_inhdr inhdr; struct vring_desc desc[NUM_ENTRY_VIRTIO_CRYPTO_OP]; + uint8_t iv[VIRTIO_CRYPTO_MAX_IV_SIZE]; }; /* diff --git a/drivers/crypto/virtio/virtio_rxtx.c b/drivers/crypto/virtio/virtio_rxtx.c index 450392843..1b16221d0 100644 --- a/drivers/crypto/virtio/virtio_rxtx.c +++ b/drivers/crypto/virtio/virtio_rxtx.c @@ -203,6 +203,8 @@ virtqueue_crypto_sym_enqueue_xmit( uint16_t req_data_len = sizeof(struct virtio_crypto_op_data_req); uint32_t indirect_vring_addr_offset = req_data_len + sizeof(struct virtio_crypto_inhdr); + uint32_t indirect_iv_addr_offset = indirect_vring_addr_offset + + sizeof(struct vring_desc) * NUM_ENTRY_VIRTIO_CRYPTO_OP; struct rte_crypto_sym_op *sym_op = cop->sym; struct virtio_crypto_session *session = (struct virtio_crypto_session *)get_session_private_data( @@ -259,7 +261,11 @@ virtqueue_crypto_sym_enqueue_xmit( /* indirect vring: iv of cipher */ if (session->iv.length) { - desc[idx].addr = cop->phys_addr + session->iv.offset; + rte_memcpy(crypto_op_cookie->iv, rte_crypto_op_ctod_offset(cop, + uint8_t *, session->iv.offset), + session->iv.length); + desc[idx].addr = indirect_op_data_req_phys_addr + + indirect_iv_addr_offset; desc[idx].len = session->iv.length; desc[idx++].flags = VRING_DESC_F_NEXT; }