DPDK patches and discussions
 help / color / mirror / Atom feed
From: Anoob Joseph <anoobj@marvell.com>
To: Akhil Goyal <gakhil@marvell.com>, Jerin Jacob <jerinj@marvell.com>
Cc: Anoob Joseph <anoobj@marvell.com>,
	Ankur Dwivedi <adwivedi@marvell.com>,
	Tejasree Kondoj <ktejasree@marvell.com>, <dev@dpdk.org>
Subject: [dpdk-dev] [PATCH] common/cpt: allocate auth key mem dynamically
Date: Wed, 14 Jul 2021 16:48:24 +0530	[thread overview]
Message-ID: <1626261504-164-1-git-send-email-anoobj@marvell.com> (raw)

Reduce session private data size by allocating auth_key dynamically as
required. Added auth_key_iova to eliminate any impact on fastpath.

Signed-off-by: Anoob Joseph <anoobj@marvell.com>
---
 drivers/common/cpt/cpt_mcode_defines.h               |  3 ++-
 drivers/common/cpt/cpt_ucode.h                       | 10 +++++++---
 drivers/crypto/octeontx/otx_cryptodev_ops.c          | 13 +++++++++++++
 drivers/crypto/octeontx2/otx2_cryptodev_ops.c        |  5 +++++
 drivers/crypto/octeontx2/otx2_cryptodev_ops_helper.h |  8 ++++++++
 5 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/drivers/common/cpt/cpt_mcode_defines.h b/drivers/common/cpt/cpt_mcode_defines.h
index 624bdcf..f63fae6 100644
--- a/drivers/common/cpt/cpt_mcode_defines.h
+++ b/drivers/common/cpt/cpt_mcode_defines.h
@@ -327,7 +327,8 @@ struct cpt_ctx {
 		mc_zuc_snow3g_ctx_t zs_ctx;
 		mc_kasumi_ctx_t k_ctx;
 	} mc_ctx;
-	uint8_t  auth_key[1024];
+	uint8_t *auth_key;
+	uint64_t auth_key_iova;
 };
 
 /* Prime and order fields of built-in elliptic curves */
diff --git a/drivers/common/cpt/cpt_ucode.h b/drivers/common/cpt/cpt_ucode.h
index bb3a862..006411c 100644
--- a/drivers/common/cpt/cpt_ucode.h
+++ b/drivers/common/cpt/cpt_ucode.h
@@ -561,8 +561,7 @@ cpt_digest_gen_prep(uint32_t flags,
 	i = 0;
 
 	if (ctx->hmac) {
-		uint64_t k_dma = params->ctx_buf.dma_addr +
-			offsetof(struct cpt_ctx, auth_key);
+		uint64_t k_dma = ctx->auth_key_iova;
 		/* Key */
 		i = fill_sg_comp(gather_comp, i, k_dma,
 				 RTE_ALIGN_CEIL(key_len, 8));
@@ -2551,7 +2550,12 @@ cpt_fc_auth_set_key(struct cpt_ctx *cpt_ctx, auth_type_t type,
 
 	if (key_len) {
 		cpt_ctx->hmac = 1;
-		memset(cpt_ctx->auth_key, 0, sizeof(cpt_ctx->auth_key));
+
+		cpt_ctx->auth_key = rte_zmalloc(NULL, key_len, 8);
+		if (cpt_ctx->auth_key == NULL)
+			return -1;
+
+		cpt_ctx->auth_key_iova = rte_mem_virt2iova(cpt_ctx->auth_key);
 		memcpy(cpt_ctx->auth_key, key, key_len);
 		cpt_ctx->auth_key_len = key_len;
 		memset(fctx->hmac.ipad, 0, sizeof(fctx->hmac.ipad));
diff --git a/drivers/crypto/octeontx/otx_cryptodev_ops.c b/drivers/crypto/octeontx/otx_cryptodev_ops.c
index 24dfaa3..1470009 100644
--- a/drivers/crypto/octeontx/otx_cryptodev_ops.c
+++ b/drivers/crypto/octeontx/otx_cryptodev_ops.c
@@ -291,6 +291,11 @@ sym_session_configure(int driver_id, struct rte_crypto_sym_xform *xform,
 	if ((GET_SESS_FC_TYPE(misc) == HASH_HMAC) &&
 			cpt_mac_len_verify(&temp_xform->auth)) {
 		CPT_LOG_ERR("MAC length is not supported");
+		struct cpt_ctx *ctx = SESS_PRIV(misc);
+		if (ctx->auth_key != NULL) {
+			rte_free(ctx->auth_key);
+			ctx->auth_key = NULL;
+		}
 		ret = -ENOTSUP;
 		goto priv_put;
 	}
@@ -319,11 +324,19 @@ static void
 sym_session_clear(int driver_id, struct rte_cryptodev_sym_session *sess)
 {
 	void *priv = get_sym_session_private_data(sess, driver_id);
+	struct cpt_sess_misc *misc;
 	struct rte_mempool *pool;
+	struct cpt_ctx *ctx;
 
 	if (priv == NULL)
 		return;
 
+	misc = priv;
+	ctx = SESS_PRIV(misc);
+
+	if (ctx->auth_key != NULL)
+		rte_free(ctx->auth_key);
+
 	memset(priv, 0, cpt_get_session_size());
 
 	pool = rte_mempool_from_obj(priv);
diff --git a/drivers/crypto/octeontx2/otx2_cryptodev_ops.c b/drivers/crypto/octeontx2/otx2_cryptodev_ops.c
index bb73a16..42100154 100644
--- a/drivers/crypto/octeontx2/otx2_cryptodev_ops.c
+++ b/drivers/crypto/octeontx2/otx2_cryptodev_ops.c
@@ -408,6 +408,11 @@ sym_session_configure(int driver_id, struct rte_crypto_sym_xform *xform,
 	if ((GET_SESS_FC_TYPE(misc) == HASH_HMAC) &&
 			cpt_mac_len_verify(&temp_xform->auth)) {
 		CPT_LOG_ERR("MAC length is not supported");
+		struct cpt_ctx *ctx = SESS_PRIV(misc);
+		if (ctx->auth_key != NULL) {
+			rte_free(ctx->auth_key);
+			ctx->auth_key = NULL;
+		}
 		ret = -ENOTSUP;
 		goto priv_put;
 	}
diff --git a/drivers/crypto/octeontx2/otx2_cryptodev_ops_helper.h b/drivers/crypto/octeontx2/otx2_cryptodev_ops_helper.h
index 764daad..01c081a 100644
--- a/drivers/crypto/octeontx2/otx2_cryptodev_ops_helper.h
+++ b/drivers/crypto/octeontx2/otx2_cryptodev_ops_helper.h
@@ -11,11 +11,19 @@ static void
 sym_session_clear(int driver_id, struct rte_cryptodev_sym_session *sess)
 {
 	void *priv = get_sym_session_private_data(sess, driver_id);
+	struct cpt_sess_misc *misc;
 	struct rte_mempool *pool;
+	struct cpt_ctx *ctx;
 
 	if (priv == NULL)
 		return;
 
+	misc = priv;
+	ctx = SESS_PRIV(misc);
+
+	if (ctx->auth_key != NULL)
+		rte_free(ctx->auth_key);
+
 	memset(priv, 0, cpt_get_session_size());
 
 	pool = rte_mempool_from_obj(priv);
-- 
2.7.4


             reply	other threads:[~2021-07-14 11:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-14 11:18 Anoob Joseph [this message]
2021-07-18  9:27 ` Akhil Goyal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1626261504-164-1-git-send-email-anoobj@marvell.com \
    --to=anoobj@marvell.com \
    --cc=adwivedi@marvell.com \
    --cc=dev@dpdk.org \
    --cc=gakhil@marvell.com \
    --cc=jerinj@marvell.com \
    --cc=ktejasree@marvell.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).