DPDK patches and discussions
 help / color / mirror / Atom feed
From: <kirankumark@marvell.com>
To: Declan Doherty <declan.doherty@intel.com>,
	Ciara Power <ciara.power@intel.com>
Cc: <dev@dpdk.org>, Kiran Kumar K <kirankumark@marvell.com>
Subject: [dpdk-dev] [PATCH] test/crypto-perf: fix crash issue with asym perf test
Date: Fri, 29 Oct 2021 10:06:58 +0530	[thread overview]
Message-ID: <20211029043658.3809156-1-kirankumark@marvell.com> (raw)

From: Kiran Kumar K <kirankumark@marvell.com>

While populating the crypto ops in case of asymmetric, result
is being allocated from stack. This is causing crash in the
application. And operation type is also not being initialized
properly. Adding a fix by allocating the result from global
memory and initialized the operation memory properly.

Fixes: ba588ce3f9339 ("test/crypto-perf: test asymmetric crypto throughput")

Signed-off-by: Kiran Kumar K <kirankumark@marvell.com>
---
 app/test-crypto-perf/cperf_ops.c          |  5 ++---
 app/test-crypto-perf/cperf_test_common.c  | 18 +++++++++++++++++-
 app/test-crypto-perf/cperf_test_vectors.c |  2 ++
 app/test-crypto-perf/cperf_test_vectors.h |  1 +
 4 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/app/test-crypto-perf/cperf_ops.c b/app/test-crypto-perf/cperf_ops.c
index 263841c339..d975ae1ab8 100644
--- a/app/test-crypto-perf/cperf_ops.c
+++ b/app/test-crypto-perf/cperf_ops.c
@@ -21,7 +21,6 @@ cperf_set_ops_asym(struct rte_crypto_op **ops,
 		   uint64_t *tsc_start __rte_unused)
 {
 	uint16_t i;
-	uint8_t result[sizeof(perf_mod_p)] = { 0 };
 	struct rte_cryptodev_asym_session *asym_sess = (void *)sess;
 
 	for (i = 0; i < nb_ops; i++) {
@@ -30,8 +29,8 @@ cperf_set_ops_asym(struct rte_crypto_op **ops,
 		ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
 		asym_op->modex.base.data = perf_base;
 		asym_op->modex.base.length = sizeof(perf_base);
-		asym_op->modex.result.data = result;
-		asym_op->modex.result.length = sizeof(result);
+		asym_op->modex.result.data = perf_mod_result;
+		asym_op->modex.result.length = sizeof(perf_mod_result);
 		rte_crypto_op_attach_asym_session(ops[i], asym_sess);
 	}
 	return 0;
diff --git a/app/test-crypto-perf/cperf_test_common.c b/app/test-crypto-perf/cperf_test_common.c
index 89f13fdebd..97a1ea47ad 100644
--- a/app/test-crypto-perf/cperf_test_common.c
+++ b/app/test-crypto-perf/cperf_test_common.c
@@ -82,6 +82,20 @@ fill_multi_seg_mbuf(struct rte_mbuf *m, struct rte_mempool *mp,
 	m->next = NULL;
 }
 
+static void
+mempool_asym_obj_init(struct rte_mempool *mp, __rte_unused void *opaque_arg,
+		      void *obj, __rte_unused unsigned int i)
+{
+	struct rte_crypto_op *op = obj;
+
+	/* Set crypto operation */
+	op->type = RTE_CRYPTO_OP_TYPE_ASYMMETRIC;
+	op->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
+	op->sess_type = RTE_CRYPTO_OP_WITH_SESSION;
+	op->phys_addr = rte_mem_virt2iova(obj);
+	op->mempool = mp;
+}
+
 static void
 mempool_obj_init(struct rte_mempool *mp,
 		 void *opaque_arg,
@@ -146,13 +160,15 @@ cperf_alloc_common_memory(const struct cperf_options *options,
 			 rte_socket_id());
 		*pool = rte_crypto_op_pool_create(
 			pool_name, RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
-			options->pool_sz, 0, 0, rte_socket_id());
+			options->pool_sz, RTE_MEMPOOL_CACHE_MAX_SIZE, 0,
+			rte_socket_id());
 		if (*pool == NULL) {
 			RTE_LOG(ERR, USER1,
 				"Cannot allocate mempool for device %u\n",
 				dev_id);
 			return -1;
 		}
+		rte_mempool_obj_iter(*pool, mempool_asym_obj_init, NULL);
 		return 0;
 	}
 
diff --git a/app/test-crypto-perf/cperf_test_vectors.c b/app/test-crypto-perf/cperf_test_vectors.c
index e578ec1434..dafcfc0c6c 100644
--- a/app/test-crypto-perf/cperf_test_vectors.c
+++ b/app/test-crypto-perf/cperf_test_vectors.c
@@ -34,6 +34,8 @@ uint8_t perf_mod_p[129] = {
 	0x55
 };
 
+uint8_t perf_mod_result[sizeof(perf_mod_p)];
+
 uint8_t perf_mod_e[3] = {0x01, 0x00, 0x01};
 
 uint8_t plaintext[2048] = {
diff --git a/app/test-crypto-perf/cperf_test_vectors.h b/app/test-crypto-perf/cperf_test_vectors.h
index 92818c22b7..70f2839cd6 100644
--- a/app/test-crypto-perf/cperf_test_vectors.h
+++ b/app/test-crypto-perf/cperf_test_vectors.h
@@ -93,5 +93,6 @@ extern uint8_t digest[2048];
 extern uint8_t perf_base[20];
 extern uint8_t perf_mod_p[129];
 extern uint8_t perf_mod_e[3];
+extern uint8_t perf_mod_result[sizeof(perf_mod_p)];
 
 #endif
-- 
2.25.1


             reply	other threads:[~2021-10-29  4:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-29  4:36 kirankumark [this message]
  -- strict thread matches above, loose matches on Subject: below --
2021-10-29  4:33 kirankumark

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=20211029043658.3809156-1-kirankumark@marvell.com \
    --to=kirankumark@marvell.com \
    --cc=ciara.power@intel.com \
    --cc=declan.doherty@intel.com \
    --cc=dev@dpdk.org \
    /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).