test/crypto-perf: fix memory allocation in asym case

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: ba588ce3f9 ("test/crypto-perf: test asymmetric crypto throughput")

Signed-off-by: Kiran Kumar K <kirankumark@marvell.com>
Acked-by: Akhil Goyal <gakhil@marvell.com>
This commit is contained in:
Kiran Kumar K 2021-10-29 10:06:58 +05:30 committed by Akhil Goyal
parent 3f956cea85
commit 9603e432bd
4 changed files with 22 additions and 4 deletions

View 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;

View 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;
}

View 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] = {

View 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