From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id B2A56A2EEB for ; Wed, 11 Sep 2019 18:06:10 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A78D41D483; Wed, 11 Sep 2019 18:06:10 +0200 (CEST) Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by dpdk.org (Postfix) with ESMTP id ACEB91D483 for ; Wed, 11 Sep 2019 18:06:09 +0200 (CEST) Received: by mail-wm1-f67.google.com with SMTP id p7so4147427wmp.4 for ; Wed, 11 Sep 2019 09:06:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=lx01cJfINm0BceBwOpw0kUtt0xYH7YrIDyIjKS+k008=; b=TvtzGYS9MwMVujOkHwlnbfAhT85IwsYEP/ni1mXCsdAjjjCN077P07kyudNoQcKk6C szkfcuhny/5//K3SlhzVXe6B7BGC9RxD8y7MhSEuY1wOVkp/y7yQWTaVv1b0iyWbwWVm eKOndLI9iqNvCevRm/LkJKay5cr2hSQ1DSINnSRr+SwofqHWjMV3k1x6oCOh8fwT2wG2 a9s0voIHGdhxuyxdywKcbhLOC6B+1VFSQWkV1L3iNFfkBPSIU1wpKkNmNYcqjFVc+Lya tYHNM8oN62/ouNrPtcAyrAVVjA5cfPA+9YnLgGZDXbzGARwy1SPx7u+fpsXzffSd1pqL yziQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=lx01cJfINm0BceBwOpw0kUtt0xYH7YrIDyIjKS+k008=; b=mA3GYtQCJ+90BVHbQWXn2+C/yJ648Cg8zRJqtWuxGwwMV9RWO3TW5r5yiTslabB3VC IPAV3+nGwTyutxTrfS0mM67XLszAy41kCQd8DK8QgKg6ZKXw0Pc1/drCzkcA6J20FRd1 n6leDuE5TY8mYFJpfQaHqmBDJYXbh21nCqNFEpcpJ4LTH99ulUGkyaw8x9oudYWa5Jgh CwzzKA7otW/lLguzUlFAoga6VZ9XYMKKoVl0v1o7FgburaHrkBumLrrt8Uj4sjeuUldj M7mZRluObEv84rDG/f1XXqoXQMERRsdVKUL5JaFTwVYD4dh+YVJngV+VTgo9oCr+bs6y HeuA== X-Gm-Message-State: APjAAAWVwZjXpXCsQINpdEn7eGqD4x/XmFmVWu8TPxBjXlwDEKjHse69 ggD548MyXTOLMf+wu7nQNUMa X-Google-Smtp-Source: APXvYqzqXkozfrTNqwUUq6c1H27S01IQg70ss7yFytd6uSAoqvhivlyoeBHUlUqIrS3wYc5VrhybeQ== X-Received: by 2002:a1c:ef07:: with SMTP id n7mr4622865wmh.28.1568217969460; Wed, 11 Sep 2019 09:06:09 -0700 (PDT) Received: from ascain.dev.6wind.com. (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id r65sm4407246wmr.9.2019.09.11.09.06.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2019 09:06:08 -0700 (PDT) From: Thierry Herbelot To: dev@dpdk.org Cc: Thomas Monjalon , stable@dpdk.org, declan.doherty@intel.com Date: Wed, 11 Sep 2019 18:06:01 +0200 Message-Id: X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-stable] [PATCH] drivers/crypto/openssl: use a local copy for the session contexts X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" Session contexts are used for temporary storage when processing a packet. If packets for the same session are to be processed simultaneously on multiple cores, separate contexts must be used. Note: with openssl 1.1.1 EVP_CIPHER_CTX can no longer be defined as a variable on the stack: it must be allocated. This in turn reduces the performance. Fixes: d61f70b4c918 ('crypto/libcrypto: add driver for OpenSSL library') Cc: stable@dpdk.org Cc: declan.doherty@intel.com Signed-off-by: Thierry Herbelot --- drivers/crypto/openssl/rte_openssl_pmd.c | 34 +++++++++++++++++------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/drivers/crypto/openssl/rte_openssl_pmd.c b/drivers/crypto/openssl/rte_openssl_pmd.c index 2f5552840741..ce2d12347737 100644 --- a/drivers/crypto/openssl/rte_openssl_pmd.c +++ b/drivers/crypto/openssl/rte_openssl_pmd.c @@ -1290,6 +1290,7 @@ process_openssl_combined_op int srclen, aadlen, status = -1; uint32_t offset; uint8_t taglen; + EVP_CIPHER_CTX *ctx_copy; /* * Segmented destination buffer is not supported for @@ -1326,6 +1327,8 @@ process_openssl_combined_op } taglen = sess->auth.digest_length; + ctx_copy = EVP_CIPHER_CTX_new(); + EVP_CIPHER_CTX_copy(ctx_copy, sess->cipher.ctx); if (sess->cipher.direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) { if (sess->auth.algo == RTE_CRYPTO_AUTH_AES_GMAC || @@ -1333,12 +1336,12 @@ process_openssl_combined_op status = process_openssl_auth_encryption_gcm( mbuf_src, offset, srclen, aad, aadlen, iv, - dst, tag, sess->cipher.ctx); + dst, tag, ctx_copy); else status = process_openssl_auth_encryption_ccm( mbuf_src, offset, srclen, aad, aadlen, iv, - dst, tag, taglen, sess->cipher.ctx); + dst, tag, taglen, ctx_copy); } else { if (sess->auth.algo == RTE_CRYPTO_AUTH_AES_GMAC || @@ -1346,14 +1349,15 @@ process_openssl_combined_op status = process_openssl_auth_decryption_gcm( mbuf_src, offset, srclen, aad, aadlen, iv, - dst, tag, sess->cipher.ctx); + dst, tag, ctx_copy); else status = process_openssl_auth_decryption_ccm( mbuf_src, offset, srclen, aad, aadlen, iv, - dst, tag, taglen, sess->cipher.ctx); + dst, tag, taglen, ctx_copy); } + EVP_CIPHER_CTX_free(ctx_copy); if (status != 0) { if (status == (-EFAULT) && sess->auth.operation == @@ -1372,6 +1376,7 @@ process_openssl_cipher_op { uint8_t *dst, *iv; int srclen, status; + EVP_CIPHER_CTX *ctx_copy; /* * Segmented destination buffer is not supported for @@ -1388,22 +1393,25 @@ process_openssl_cipher_op iv = rte_crypto_op_ctod_offset(op, uint8_t *, sess->iv.offset); + ctx_copy = EVP_CIPHER_CTX_new(); + EVP_CIPHER_CTX_copy(ctx_copy, sess->cipher.ctx); if (sess->cipher.mode == OPENSSL_CIPHER_LIB) if (sess->cipher.direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) status = process_openssl_cipher_encrypt(mbuf_src, dst, op->sym->cipher.data.offset, iv, - srclen, sess->cipher.ctx); + srclen, ctx_copy); else status = process_openssl_cipher_decrypt(mbuf_src, dst, op->sym->cipher.data.offset, iv, - srclen, sess->cipher.ctx); + srclen, ctx_copy); else status = process_openssl_cipher_des3ctr(mbuf_src, dst, op->sym->cipher.data.offset, iv, sess->cipher.key.data, srclen, - sess->cipher.ctx); + ctx_copy); + EVP_CIPHER_CTX_free(ctx_copy); if (status != 0) op->status = RTE_CRYPTO_OP_STATUS_ERROR; } @@ -1507,6 +1515,8 @@ process_openssl_auth_op(struct openssl_qp *qp, struct rte_crypto_op *op, { uint8_t *dst; int srclen, status; + EVP_MD_CTX *ctx_a; + HMAC_CTX *ctx_h; srclen = op->sym->auth.data.length; @@ -1514,14 +1524,20 @@ process_openssl_auth_op(struct openssl_qp *qp, struct rte_crypto_op *op, switch (sess->auth.mode) { case OPENSSL_AUTH_AS_AUTH: + ctx_a = EVP_MD_CTX_create(); + EVP_MD_CTX_copy_ex(ctx_a, sess->auth.auth.ctx); status = process_openssl_auth(mbuf_src, dst, op->sym->auth.data.offset, NULL, NULL, srclen, - sess->auth.auth.ctx, sess->auth.auth.evp_algo); + ctx_a, sess->auth.auth.evp_algo); + EVP_MD_CTX_destroy(ctx_a); break; case OPENSSL_AUTH_AS_HMAC: + ctx_h = HMAC_CTX_new(); + HMAC_CTX_copy(ctx_h, sess->auth.hmac.ctx); status = process_openssl_auth_hmac(mbuf_src, dst, op->sym->auth.data.offset, srclen, - sess->auth.hmac.ctx); + ctx_h); + HMAC_CTX_free(ctx_h); break; default: status = -1; -- 2.20.1