From patchwork Wed Aug 7 14:37:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Herbelot X-Patchwork-Id: 57533 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 011FC1B9A0; Wed, 7 Aug 2019 16:38:21 +0200 (CEST) Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by dpdk.org (Postfix) with ESMTP id 23D6E2B9E for ; Wed, 7 Aug 2019 16:38:01 +0200 (CEST) Received: by mail-wr1-f68.google.com with SMTP id r1so91598995wrl.7 for ; Wed, 07 Aug 2019 07:38:01 -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:in-reply-to:references :in-reply-to:references; bh=FVzZjSZCwjtSjhN39Ardbr6yKifb6QHpQkNIuBKoh2Q=; b=hEFT+/qvcpnYk6VEF1UCYyL6fJmF/86rmXAxJ3GCx1Crrih8O0E3+auSeY2wSLkEcL AxvDvGEE/Thq5lSW5GZAMrPfduCx1Ui/JpeK0tvTNsmuLiqE+FR0WbhXP/83e+RVaaLD 8aD6i51M+8T+xeg7iq6HjDlbH9xCj6jbs6C1++61yJDRhz9WrcZrp4vwyUvgon0V2eiM 2m5fYwW5oT4hgwjNwJaj+bSkbprEEYiqRSQDixrdCgTS6a3wvjim+5qrnFglyeQso/ok 5pcjOzt/HQtaVe1SsmYjgnV9kiLp9cjuKZGw6oGJI+LGwlcvA7WA1IGpuvc3noY43C6y FGmA== 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:in-reply-to :references:in-reply-to:references; bh=FVzZjSZCwjtSjhN39Ardbr6yKifb6QHpQkNIuBKoh2Q=; b=G69quTDJTUp3kH1pCETxsGJi/BlKtdtMMgKyueXujAr59Soqkm+jvd0/OnY0Apn3k7 85cQ8S/IG4VrJCJgA9ePyHiEs/c51JL0SLlN3nX8r2M3nzE2fEn5Y72tWPFpRLtqHW48 67p+GcA5YASQv+2BmO76DB48O8yU5I3XIjsu+Jf/64YLhHyCasODf/nQepCDTfMp7Dqe v6qWOdgJG4ga1u5Ly9/G5pmUUukDjzyXAEh3/Id5uBIh3UM6eoL9QcNLST4LNXix2zKq h7XhMq0TnEc77guRO54MyT35KS/jak64sXG0Nv90ezh4t47CwY3owmu1CbpJPuz6Njvi 3O1Q== X-Gm-Message-State: APjAAAWTmlP/Yje3yCOYh6YvzOfG1ELx7iGnVqvc8/S53Y2FsvoyTrru hgc7lqr2+MEEJcBwRn1ARluae/7Zjw== X-Google-Smtp-Source: APXvYqxWfoeibiwRsJAQbvEaxjLQlXcV6GWaiiv5zipZGROsBtgX1AHPDO9/scZvqpuYBRos8jZLyQ== X-Received: by 2002:adf:e691:: with SMTP id r17mr11541284wrm.67.1565188680467; Wed, 07 Aug 2019 07:38:00 -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 2sm133441211wrn.29.2019.08.07.07.37.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Aug 2019 07:37:59 -0700 (PDT) From: Thierry Herbelot To: dev@dpdk.org Cc: stable@dpdk.org, Thomas Monjalon Date: Wed, 7 Aug 2019 16:37:29 +0200 Message-Id: X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH 19.11 10/12] drivers/crypto/openssl: use a local copy for the session contexts 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" 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 at dpdk.org 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;