All of lore.kernel.org
 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/cnxk: allocate auth key mem dynamically
Date: Fri, 16 Jul 2021 10:43:29 +0530	[thread overview]
Message-ID: <1626412409-268-1-git-send-email-anoobj@marvell.com> (raw)

Reduce session private data size by allocating auth_key dynamically as
required.

Signed-off-by: Anoob Joseph <anoobj@marvell.com>
---
 drivers/common/cnxk/roc_se.c             |  6 +++++-
 drivers/common/cnxk/roc_se.h             |  2 +-
 drivers/crypto/cnxk/cnxk_cryptodev_ops.c | 11 +++++++++++
 drivers/crypto/cnxk/cnxk_se.h            |  3 +--
 4 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/drivers/common/cnxk/roc_se.c b/drivers/common/cnxk/roc_se.c
index 3f74175..b04de79 100644
--- a/drivers/common/cnxk/roc_se.c
+++ b/drivers/common/cnxk/roc_se.c
@@ -206,7 +206,11 @@ roc_se_auth_key_set(struct roc_se_ctx *se_ctx, roc_se_auth_type type,
 
 	if (key_len) {
 		se_ctx->hmac = 1;
-		memset(se_ctx->auth_key, 0, sizeof(se_ctx->auth_key));
+
+		se_ctx->auth_key = plt_zmalloc(key_len, 8);
+		if (se_ctx->auth_key == NULL)
+			return -1;
+
 		memcpy(se_ctx->auth_key, key, key_len);
 		se_ctx->auth_key_len = key_len;
 		memset(fctx->hmac.ipad, 0, sizeof(fctx->hmac.ipad));
diff --git a/drivers/common/cnxk/roc_se.h b/drivers/common/cnxk/roc_se.h
index 43a40dd..5c7e2ca 100644
--- a/drivers/common/cnxk/roc_se.h
+++ b/drivers/common/cnxk/roc_se.h
@@ -261,7 +261,7 @@ struct roc_se_ctx {
 		struct roc_se_zuc_snow3g_ctx zs_ctx;
 		struct roc_se_kasumi_ctx k_ctx;
 	} se_ctx;
-	uint8_t auth_key[1024];
+	uint8_t *auth_key;
 };
 
 int __roc_api roc_se_auth_key_set(struct roc_se_ctx *se_ctx,
diff --git a/drivers/crypto/cnxk/cnxk_cryptodev_ops.c b/drivers/crypto/cnxk/cnxk_cryptodev_ops.c
index 694eef7..440dbc3a 100644
--- a/drivers/crypto/cnxk/cnxk_cryptodev_ops.c
+++ b/drivers/crypto/cnxk/cnxk_cryptodev_ops.c
@@ -552,6 +552,11 @@ sym_session_configure(struct roc_cpt *roc_cpt, int driver_id,
 	if ((sess_priv->roc_se_ctx.fc_type == ROC_SE_HASH_HMAC) &&
 	    cpt_mac_len_verify(&xform->auth)) {
 		plt_dp_err("MAC length is not supported");
+		if (sess_priv->roc_se_ctx.auth_key != NULL) {
+			plt_free(sess_priv->roc_se_ctx.auth_key);
+			sess_priv->roc_se_ctx.auth_key = NULL;
+		}
+
 		ret = -ENOTSUP;
 		goto priv_put;
 	}
@@ -587,11 +592,17 @@ void
 sym_session_clear(int driver_id, struct rte_cryptodev_sym_session *sess)
 {
 	void *priv = get_sym_session_private_data(sess, driver_id);
+	struct cnxk_se_sess *sess_priv;
 	struct rte_mempool *pool;
 
 	if (priv == NULL)
 		return;
 
+	sess_priv = priv;
+
+	if (sess_priv->roc_se_ctx.auth_key != NULL)
+		plt_free(sess_priv->roc_se_ctx.auth_key);
+
 	memset(priv, 0, cnxk_cpt_sym_session_get_size(NULL));
 
 	pool = rte_mempool_from_obj(priv);
diff --git a/drivers/crypto/cnxk/cnxk_se.h b/drivers/crypto/cnxk/cnxk_se.h
index d83910f..3ed6b90 100644
--- a/drivers/crypto/cnxk/cnxk_se.h
+++ b/drivers/crypto/cnxk/cnxk_se.h
@@ -273,8 +273,7 @@ cpt_digest_gen_prep(uint32_t flags, uint64_t d_lens,
 	i = 0;
 
 	if (ctx->hmac) {
-		uint64_t k_vaddr = (uint64_t)params->ctx_buf.vaddr +
-				   offsetof(struct roc_se_ctx, auth_key);
+		uint64_t k_vaddr = (uint64_t)ctx->auth_key;
 		/* Key */
 		i = fill_sg_comp(gather_comp, i, k_vaddr,
 				 RTE_ALIGN_CEIL(key_len, 8));
-- 
2.7.4


             reply	other threads:[~2021-07-16  5:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-16  5:13 Anoob Joseph [this message]
2021-07-18  9:12 ` [dpdk-dev] [PATCH] common/cnxk: allocate auth key mem dynamically 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=1626412409-268-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.