]> git.droids-corp.org - dpdk.git/commitdiff
test/crypto-perf: fix memory allocation in asym case
authorKiran Kumar K <kirankumark@marvell.com>
Fri, 29 Oct 2021 04:36:58 +0000 (10:06 +0530)
committerAkhil Goyal <gakhil@marvell.com>
Thu, 4 Nov 2021 18:46:27 +0000 (19:46 +0100)
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>
Acked-by: Akhil Goyal <gakhil@marvell.com>
app/test-crypto-perf/cperf_ops.c
app/test-crypto-perf/cperf_test_common.c
app/test-crypto-perf/cperf_test_vectors.c
app/test-crypto-perf/cperf_test_vectors.h

index 263841c339cc1212d9551939338cc401168d09c5..d975ae1ab8b4017b97c0143edaedcb0382ee7bcc 100644 (file)
@@ -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;
index 89f13fdebd8f3efd74a41a27c4c59ac48f9d33af..97a1ea47ad5b437dbf2aa317071ed16662e699b0 100644 (file)
@@ -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;
        }
 
index e578ec143468eccc1e651d4f718aa3bd76e7f28d..dafcfc0c6c158be24af06dcd48eb1b4e3e310053 100644 (file)
@@ -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] = {
index 92818c22b72f1c9e5a4e63a37aff9d45d65e6ac7..70f2839cd63ff9a53adef7e446b71cb2a84bc639 100644 (file)
@@ -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