DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH v4 0/5] crypto: improve asym session usage
@ 2022-02-09 15:38 Ciara Power
  2022-02-09 15:38 ` [PATCH v4 1/5] doc: replace asym crypto code with literal includes Ciara Power
                   ` (7 more replies)
  0 siblings, 8 replies; 31+ messages in thread
From: Ciara Power @ 2022-02-09 15:38 UTC (permalink / raw)
  To: dev; +Cc: roy.fan.zhang, gakhil, anoobj, mdr, Ciara Power

This patchset includes improvements for the asymmetric session.
The main change is to the session structure, which is now a single
mempool object, rather than having pointers to private data elsewhere.
This session structure is now hidden in an internal header,
so the app will never use it directly.

Some other changes include adding a user data API, and modifying
the return value for the create session function.
This create session function now also initialises the session,
and subsequently the clear/free functions have been merged into one.

Sample code in the programmer's guide that showed basic steps for
using Asymmetric crypto in DPDK has been replaced with literal includes
in the first patch of this patchset. This ensures all subsequent code
changes in the patchset are automatically reflected in the documentation.

v4:
  - Added new patch to add literal includes usage in programmer's guide.
  - Merged asym crypto session clear and free functions.
  - Reordered some function parameters.
  - Updated trace function for asym crypto session create.
  - Fixed cnxk clear, the PMD no longer needs to put private data
    back into a mempool.
  - Renamed struct field for max private session size.
  - Replaced __extension__ with RTE_STD_C11.
  - Moved some parameter validity checks to before functional code.
  - Reworded release note.
  - Removed mempool parameter from session configure function.
  - Removed docs code additions, these are included due to patch 1
    changing sample doc to use literal includes.
  - Initialised session variables as NULL.
  - Added possible error return values in user data API comment.

Ciara Power (5):
  doc: replace asym crypto code with literal includes
  crypto: use single buffer for asymmetric session
  crypto: hide asym session structure
  crypto: add asym session user data API
  crypto: modify return value for asym session create

 app/test-crypto-perf/cperf_ops.c             |  22 +-
 app/test-crypto-perf/cperf_test_throughput.c |   8 +-
 app/test/test_cryptodev_asym.c               | 380 ++++++-------------
 app/test/test_cryptodev_mod_test_vectors.h   |   4 +
 doc/guides/prog_guide/cryptodev_lib.rst      | 212 +++--------
 doc/guides/rel_notes/release_22_03.rst       |  14 +
 drivers/crypto/cnxk/cn10k_cryptodev_ops.c    |   6 +-
 drivers/crypto/cnxk/cn9k_cryptodev_ops.c     |   6 +-
 drivers/crypto/cnxk/cnxk_cryptodev_ops.c     |  21 +-
 drivers/crypto/cnxk/cnxk_cryptodev_ops.h     |   3 +-
 drivers/crypto/octeontx/otx_cryptodev_ops.c  |  30 +-
 drivers/crypto/openssl/rte_openssl_pmd.c     |   5 +-
 drivers/crypto/openssl/rte_openssl_pmd_ops.c |  24 +-
 drivers/crypto/qat/qat_asym.c                |  54 +--
 drivers/crypto/qat/qat_asym.h                |   5 +-
 lib/cryptodev/cryptodev_pmd.h                |  36 +-
 lib/cryptodev/cryptodev_trace_points.c       |   9 +-
 lib/cryptodev/rte_cryptodev.c                | 258 ++++++++-----
 lib/cryptodev/rte_cryptodev.h                | 133 ++++---
 lib/cryptodev/rte_cryptodev_trace.h          |  38 +-
 lib/cryptodev/version.map                    |   9 +-
 21 files changed, 517 insertions(+), 760 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 31+ messages in thread

* [PATCH v4 1/5] doc: replace asym crypto code with literal includes
  2022-02-09 15:38 [PATCH v4 0/5] crypto: improve asym session usage Ciara Power
@ 2022-02-09 15:38 ` Ciara Power
  2022-02-09 15:38 ` [PATCH v4 2/5] crypto: use single buffer for asymmetric session Ciara Power
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 31+ messages in thread
From: Ciara Power @ 2022-02-09 15:38 UTC (permalink / raw)
  To: dev; +Cc: roy.fan.zhang, gakhil, anoobj, mdr, Ciara Power, Declan Doherty

The programmer's guide for cryptodev included sample code for using
Asymmetric crypto. This is now replaced with direct code from the test
application, using literal includes. It is broken into snippets as the
test application didn't have all of the required code in one function.

Signed-off-by: Ciara Power <ciara.power@intel.com>
---
 app/test/test_cryptodev_asym.c             |   7 +-
 app/test/test_cryptodev_mod_test_vectors.h |   4 +
 doc/guides/prog_guide/cryptodev_lib.rst    | 176 ++++-----------------
 3 files changed, 37 insertions(+), 150 deletions(-)

diff --git a/app/test/test_cryptodev_asym.c b/app/test/test_cryptodev_asym.c
index 9d3a5589bb..8d7290f9ed 100644
--- a/app/test/test_cryptodev_asym.c
+++ b/app/test/test_cryptodev_asym.c
@@ -855,6 +855,7 @@ testsuite_setup(void)
 	test_vector.size = 0;
 	load_test_vectors();
 
+	/* Device, op pool and session configuration for asymmetric crypto. 8< */
 	ts_params->op_mpool = rte_crypto_op_pool_create(
 			"CRYPTO_ASYM_OP_POOL",
 			RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
@@ -953,7 +954,7 @@ testsuite_setup(void)
 
 	TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
 			"session mempool allocation failed");
-
+	/* >8 End of device, op pool and session configuration for asymmetric crypto section. */
 	return TEST_SUCCESS;
 }
 
@@ -1637,7 +1638,7 @@ test_mod_exp(void)
 				return TEST_SKIPPED;
 		}
 
-	/* generate crypto op data structure */
+	/* Create op, create session, and process packets. 8< */
 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
 	if (!op) {
 		RTE_LOG(ERR, USER1,
@@ -1696,7 +1697,7 @@ test_mod_exp(void)
 		status = TEST_FAILED;
 		goto error_exit;
 	}
-
+	/* >8 End of create op, create session, and process packets section. */
 	ret = verify_modexp(mod_exp, result_op);
 	if (ret) {
 		RTE_LOG(ERR, USER1,
diff --git a/app/test/test_cryptodev_mod_test_vectors.h b/app/test/test_cryptodev_mod_test_vectors.h
index c66f4b18bc..807ca7a47e 100644
--- a/app/test/test_cryptodev_mod_test_vectors.h
+++ b/app/test/test_cryptodev_mod_test_vectors.h
@@ -979,6 +979,7 @@ uint8_t base[] = {
 	0xA8, 0xEB, 0x7E, 0x78, 0xA0, 0x50
 };
 
+/* MODEX data. 8< */
 uint8_t mod_p[] = {
 	0x00, 0xb3, 0xa1, 0xaf, 0xb7, 0x13, 0x08, 0x00,
 	0x0a, 0x35, 0xdc, 0x2b, 0x20, 0x8d, 0xa1, 0xb5,
@@ -1000,6 +1001,7 @@ uint8_t mod_p[] = {
 };
 
 uint8_t mod_e[] = {0x01, 0x00, 0x01};
+/* >8 End of MODEX data. */
 
 /* Precomputed modular exponentiation for verification */
 uint8_t mod_exp[] = {
@@ -1041,6 +1043,7 @@ uint8_t mod_inv[] = {
 	0x9a, 0x66, 0x9a, 0x3a, 0xc1, 0xb8, 0x4b, 0xc3
 };
 
+/* MODEX vector. 8< */
 struct rte_crypto_asym_xform modex_xform = {
 	.next = NULL,
 	.xform_type = RTE_CRYPTO_ASYM_XFORM_MODEX,
@@ -1055,6 +1058,7 @@ struct rte_crypto_asym_xform modex_xform = {
 		}
 	}
 };
+/* >8 End of MODEX vector. */
 
 struct rte_crypto_asym_xform modinv_xform = {
 	.next = NULL,
diff --git a/doc/guides/prog_guide/cryptodev_lib.rst b/doc/guides/prog_guide/cryptodev_lib.rst
index 8766bc34a9..9f33f7a177 100644
--- a/doc/guides/prog_guide/cryptodev_lib.rst
+++ b/doc/guides/prog_guide/cryptodev_lib.rst
@@ -1119,162 +1119,44 @@ Asymmetric crypto Sample code
 There's a unit test application test_cryptodev_asym.c inside unit test framework that
 show how to setup and process asymmetric operations using cryptodev library.
 
-The following sample code shows the basic steps to compute modular exponentiation
-using 1024-bit modulus length using openssl PMD available in DPDK (performing other
-crypto operations is similar except change to respective op and xform setup).
+The following code samples are taken from the test application mentioned above,
+and show basic steps to compute modular exponentiation using an openssl PMD
+available in DPDK (performing other crypto operations is similar except change
+to respective op and xform setup).
 
-.. code-block:: c
+.. note::
+   The following code snippets are taken from multiple functions, so variable
+   names may differ slightly between sections.
 
-    /*
-     * Simple example to compute modular exponentiation with 1024-bit key
-     *
-     */
-    #define MAX_ASYM_SESSIONS	10
-    #define NUM_ASYM_BUFS	10
-
-    struct rte_mempool *crypto_op_pool, *asym_session_pool;
-    unsigned int asym_session_size;
-    int ret;
+Configure the virtual device, queue pairs, crypto op pool and session mempool.
 
-    /* Initialize EAL. */
-    ret = rte_eal_init(argc, argv);
-    if (ret < 0)
-        rte_exit(EXIT_FAILURE, "Invalid EAL arguments\n");
+.. literalinclude:: ../../../app/test/test_cryptodev_asym.c
+   :language: c
+   :start-after: Device, op pool and session configuration for asymmetric crypto. 8<
+   :end-before: >8 End of device, op pool and session configuration for asymmetric crypto section.
+   :dedent: 1
 
-    uint8_t socket_id = rte_socket_id();
-
-    /* Create crypto operation pool. */
-    crypto_op_pool = rte_crypto_op_pool_create(
-                                    "crypto_op_pool",
-                                    RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
-                                    NUM_ASYM_BUFS, 0, 0,
-                                    socket_id);
-    if (crypto_op_pool == NULL)
-        rte_exit(EXIT_FAILURE, "Cannot create crypto op pool\n");
-
-    /* Create the virtual crypto device. */
-    char args[128];
-    const char *crypto_name = "crypto_openssl";
-    snprintf(args, sizeof(args), "socket_id=%d", socket_id);
-    ret = rte_vdev_init(crypto_name, args);
-    if (ret != 0)
-        rte_exit(EXIT_FAILURE, "Cannot create virtual device");
+Create MODEX data vectors.
 
-    uint8_t cdev_id = rte_cryptodev_get_dev_id(crypto_name);
+.. literalinclude:: ../../../app/test/test_cryptodev_mod_test_vectors.h
+   :language: c
+   :start-after: MODEX data. 8<
+   :end-before: >8 End of MODEX data.
 
-    /* Get private asym session data size. */
-    asym_session_size = rte_cryptodev_get_asym_private_session_size(cdev_id);
+Setup crypto xform to do modular exponentiation using data vectors.
 
-    /*
-     * Create session mempool, with two objects per session,
-     * one for the session header and another one for the
-     * private asym session data for the crypto device.
-     */
-    asym_session_pool = rte_mempool_create("asym_session_pool",
-                                    MAX_ASYM_SESSIONS * 2,
-                                    asym_session_size,
-                                    0,
-                                    0, NULL, NULL, NULL,
-                                    NULL, socket_id,
-                                    0);
+.. literalinclude:: ../../../app/test/test_cryptodev_mod_test_vectors.h
+   :language: c
+   :start-after: MODEX vector. 8<
+   :end-before: >8 End of MODEX vector.
 
-    /* Configure the crypto device. */
-    struct rte_cryptodev_config conf = {
-        .nb_queue_pairs = 1,
-        .socket_id = socket_id
-    };
-    struct rte_cryptodev_qp_conf qp_conf = {
-        .nb_descriptors = 2048
-    };
+Generate crypto op, create and attach a session, then process packets.
 
-    if (rte_cryptodev_configure(cdev_id, &conf) < 0)
-        rte_exit(EXIT_FAILURE, "Failed to configure cryptodev %u", cdev_id);
-
-    if (rte_cryptodev_queue_pair_setup(cdev_id, 0, &qp_conf,
-                            socket_id, asym_session_pool) < 0)
-        rte_exit(EXIT_FAILURE, "Failed to setup queue pair\n");
-
-    if (rte_cryptodev_start(cdev_id) < 0)
-        rte_exit(EXIT_FAILURE, "Failed to start device\n");
-
-    /* Setup crypto xform to do modular exponentiation with 1024 bit
-	 * length modulus
-	 */
-    struct rte_crypto_asym_xform modex_xform = {
-		.next = NULL,
-		.xform_type = RTE_CRYPTO_ASYM_XFORM_MODEX,
-		.modex = {
-			.modulus = {
-				.data =
-				(uint8_t *)
-				("\xb3\xa1\xaf\xb7\x13\x08\x00\x0a\x35\xdc\x2b\x20\x8d"
-				"\xa1\xb5\xce\x47\x8a\xc3\x80\xf4\x7d\x4a\xa2\x62\xfd\x61\x7f"
-				"\xb5\xa8\xde\x0a\x17\x97\xa0\xbf\xdf\x56\x5a\x3d\x51\x56\x4f"
-				"\x70\x70\x3f\x63\x6a\x44\x5b\xad\x84\x0d\x3f\x27\x6e\x3b\x34"
-				"\x91\x60\x14\xb9\xaa\x72\xfd\xa3\x64\xd2\x03\xa7\x53\x87\x9e"
-				"\x88\x0b\xc1\x14\x93\x1a\x62\xff\xb1\x5d\x74\xcd\x59\x63\x18"
-				"\x11\x3d\x4f\xba\x75\xd4\x33\x4e\x23\x6b\x7b\x57\x44\xe1\xd3"
-				"\x03\x13\xa6\xf0\x8b\x60\xb0\x9e\xee\x75\x08\x9d\x71\x63\x13"
-				"\xcb\xa6\x81\x92\x14\x03\x22\x2d\xde\x55"),
-				.length = 128
-			},
-			.exponent = {
-				.data = (uint8_t *)("\x01\x00\x01"),
-				.length = 3
-			}
-		}
-    };
-    /* Create asym crypto session and initialize it for the crypto device. */
-    struct rte_cryptodev_asym_session *asym_session;
-    asym_session = rte_cryptodev_asym_session_create(asym_session_pool);
-    if (asym_session == NULL)
-        rte_exit(EXIT_FAILURE, "Session could not be created\n");
-
-    if (rte_cryptodev_asym_session_init(cdev_id, asym_session,
-                    &modex_xform, asym_session_pool) < 0)
-        rte_exit(EXIT_FAILURE, "Session could not be initialized "
-                    "for the crypto device\n");
-
-    /* Get a burst of crypto operations. */
-    struct rte_crypto_op *crypto_ops[1];
-    if (rte_crypto_op_bulk_alloc(crypto_op_pool,
-                            RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
-                            crypto_ops, 1) == 0)
-        rte_exit(EXIT_FAILURE, "Not enough crypto operations available\n");
-
-    /* Set up the crypto operations. */
-    struct rte_crypto_asym_op *asym_op = crypto_ops[0]->asym;
-
-	/* calculate mod exp of value 0xf8 */
-    static unsigned char base[] = {0xF8};
-    asym_op->modex.base.data = base;
-    asym_op->modex.base.length = sizeof(base);
-	asym_op->modex.base.iova = base;
-
-    /* Attach the asym crypto session to the operation */
-    rte_crypto_op_attach_asym_session(op, asym_session);
-
-    /* Enqueue the crypto operations in the crypto device. */
-    uint16_t num_enqueued_ops = rte_cryptodev_enqueue_burst(cdev_id, 0,
-                                            crypto_ops, 1);
-
-    /*
-     * Dequeue the crypto operations until all the operations
-     * are processed in the crypto device.
-     */
-    uint16_t num_dequeued_ops, total_num_dequeued_ops = 0;
-    do {
-        struct rte_crypto_op *dequeued_ops[1];
-        num_dequeued_ops = rte_cryptodev_dequeue_burst(cdev_id, 0,
-                                        dequeued_ops, 1);
-        total_num_dequeued_ops += num_dequeued_ops;
-
-        /* Check if operation was processed successfully */
-        if (dequeued_ops[0]->status != RTE_CRYPTO_OP_STATUS_SUCCESS)
-                rte_exit(EXIT_FAILURE,
-                        "Some operations were not processed correctly");
-
-    } while (total_num_dequeued_ops < num_enqueued_ops);
+.. literalinclude:: ../../../app/test/test_cryptodev_asym.c
+   :language: c
+   :start-after: Create op, create session, and process packets. 8<
+   :end-before: >8 End of create op, create session, and process packets section.
+   :dedent: 1
 
 
 Asymmetric Crypto Device API
-- 
2.25.1


^ permalink raw reply	[flat|nested] 31+ messages in thread

* [PATCH v4 2/5] crypto: use single buffer for asymmetric session
  2022-02-09 15:38 [PATCH v4 0/5] crypto: improve asym session usage Ciara Power
  2022-02-09 15:38 ` [PATCH v4 1/5] doc: replace asym crypto code with literal includes Ciara Power
@ 2022-02-09 15:38 ` Ciara Power
  2022-02-09 19:52   ` [EXT] " Akhil Goyal
  2022-02-09 15:38 ` [PATCH v4 3/5] crypto: hide asym session structure Ciara Power
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 31+ messages in thread
From: Ciara Power @ 2022-02-09 15:38 UTC (permalink / raw)
  To: dev
  Cc: roy.fan.zhang, gakhil, anoobj, mdr, Ciara Power, Declan Doherty,
	Ankur Dwivedi, Tejasree Kondoj, John Griffin, Fiona Trahe,
	Deepak Kumar Jain

Rather than using a session buffer that contains pointers to private
session data elsewhere, have a single session buffer.
This session is created for a driver ID, and the mempool element
contains space for the max session private data needed for any driver.

Signed-off-by: Ciara Power <ciara.power@intel.com>
Acked-by: Fan Zhang <roy.fan.zhang@intel.com>

---
v4:
  - Merged asym crypto session clear and free functions.
  - Reordered some function parameters.
  - Updated trace function for asym crypto session create.
  - Fixed cnxk clear, the PMD no longer needs to put private data
    back into a mempool.
  - Renamed struct field for max private session size.
  - Replaced __extension__ with RTE_STD_C11.
  - Moved some parameter validity checks to before functional code.
  - Reworded release note.
  - Removed mempool parameter from session configure function.
  - Removed docs code additions, these are included due to patch 1
    changing sample doc to use literal includes.
v3:
  - Corrected formatting of struct comments.
  - Increased size of max_priv_session_sz to uint16_t.
  - Removed trace for asym session init function that was
    previously removed.
  - Added documentation.
v2:
  - Renamed function typedef from "free" to "clear" as session private
    data isn't being freed in that function.
  - Moved user data API to separate patch.
  - Minor fixes to comments, formatting, return values.
---
 app/test-crypto-perf/cperf_ops.c             |  14 +-
 app/test-crypto-perf/cperf_test_throughput.c |   8 +-
 app/test/test_cryptodev_asym.c               | 272 +++++--------------
 doc/guides/prog_guide/cryptodev_lib.rst      |  21 +-
 doc/guides/rel_notes/release_22_03.rst       |   7 +
 drivers/crypto/cnxk/cn10k_cryptodev_ops.c    |   6 +-
 drivers/crypto/cnxk/cn9k_cryptodev_ops.c     |   6 +-
 drivers/crypto/cnxk/cnxk_cryptodev_ops.c     |  21 +-
 drivers/crypto/cnxk/cnxk_cryptodev_ops.h     |   3 +-
 drivers/crypto/octeontx/otx_cryptodev_ops.c  |  30 +-
 drivers/crypto/openssl/rte_openssl_pmd.c     |   5 +-
 drivers/crypto/openssl/rte_openssl_pmd_ops.c |  24 +-
 drivers/crypto/qat/qat_asym.c                |  54 +---
 drivers/crypto/qat/qat_asym.h                |   5 +-
 lib/cryptodev/cryptodev_pmd.h                |  21 +-
 lib/cryptodev/cryptodev_trace_points.c       |   9 +-
 lib/cryptodev/rte_cryptodev.c                | 213 ++++++++-------
 lib/cryptodev/rte_cryptodev.h                |  94 +++----
 lib/cryptodev/rte_cryptodev_trace.h          |  38 ++-
 lib/cryptodev/version.map                    |   7 +-
 20 files changed, 308 insertions(+), 550 deletions(-)

diff --git a/app/test-crypto-perf/cperf_ops.c b/app/test-crypto-perf/cperf_ops.c
index d975ae1ab8..b125c699de 100644
--- a/app/test-crypto-perf/cperf_ops.c
+++ b/app/test-crypto-perf/cperf_ops.c
@@ -735,7 +735,6 @@ cperf_create_session(struct rte_mempool *sess_mp,
 	struct rte_crypto_sym_xform aead_xform;
 	struct rte_cryptodev_sym_session *sess = NULL;
 	struct rte_crypto_asym_xform xform = {0};
-	int rc;
 
 	if (options->op_type == CPERF_ASYM_MODEX) {
 		xform.next = NULL;
@@ -745,19 +744,10 @@ cperf_create_session(struct rte_mempool *sess_mp,
 		xform.modex.exponent.data = perf_mod_e;
 		xform.modex.exponent.length = sizeof(perf_mod_e);
 
-		sess = (void *)rte_cryptodev_asym_session_create(sess_mp);
+		sess = (void *)rte_cryptodev_asym_session_create(dev_id, &xform, sess_mp);
 		if (sess == NULL)
 			return NULL;
-		rc = rte_cryptodev_asym_session_init(dev_id, (void *)sess,
-						     &xform, priv_mp);
-		if (rc < 0) {
-			if (sess != NULL) {
-				rte_cryptodev_asym_session_clear(dev_id,
-								 (void *)sess);
-				rte_cryptodev_asym_session_free((void *)sess);
-			}
-			return NULL;
-		}
+
 		return sess;
 	}
 #ifdef RTE_LIB_SECURITY
diff --git a/app/test-crypto-perf/cperf_test_throughput.c b/app/test-crypto-perf/cperf_test_throughput.c
index 51512af2ad..ee21ff27f7 100644
--- a/app/test-crypto-perf/cperf_test_throughput.c
+++ b/app/test-crypto-perf/cperf_test_throughput.c
@@ -35,11 +35,9 @@ cperf_throughput_test_free(struct cperf_throughput_ctx *ctx)
 	if (!ctx)
 		return;
 	if (ctx->sess) {
-		if (ctx->options->op_type == CPERF_ASYM_MODEX) {
-			rte_cryptodev_asym_session_clear(ctx->dev_id,
-							 (void *)ctx->sess);
-			rte_cryptodev_asym_session_free((void *)ctx->sess);
-		}
+		if (ctx->options->op_type == CPERF_ASYM_MODEX)
+			rte_cryptodev_asym_session_free(ctx->dev_id,
+					(void *)ctx->sess);
 #ifdef RTE_LIB_SECURITY
 		else if (ctx->options->op_type == CPERF_PDCP ||
 			 ctx->options->op_type == CPERF_DOCSIS ||
diff --git a/app/test/test_cryptodev_asym.c b/app/test/test_cryptodev_asym.c
index 8d7290f9ed..3e27d93380 100644
--- a/app/test/test_cryptodev_asym.c
+++ b/app/test/test_cryptodev_asym.c
@@ -452,7 +452,8 @@ test_cryptodev_asym_op(struct crypto_testsuite_params_asym *ts_params,
 	}
 
 	if (!sessionless) {
-		sess = rte_cryptodev_asym_session_create(ts_params->session_mpool);
+		sess = rte_cryptodev_asym_session_create(dev_id, &xform_tc,
+				ts_params->session_mpool);
 		if (!sess) {
 			snprintf(test_msg, ASYM_TEST_MSG_LEN,
 					"line %u "
@@ -462,15 +463,6 @@ test_cryptodev_asym_op(struct crypto_testsuite_params_asym *ts_params,
 			goto error_exit;
 		}
 
-		if (rte_cryptodev_asym_session_init(dev_id, sess, &xform_tc,
-				ts_params->session_mpool) < 0) {
-			snprintf(test_msg, ASYM_TEST_MSG_LEN,
-					"line %u FAILED: %s",
-					__LINE__, "unabled to config sym session");
-			status = TEST_FAILED;
-			goto error_exit;
-		}
-
 		rte_crypto_op_attach_asym_session(op, sess);
 	} else {
 		asym_op->xform = &xform_tc;
@@ -512,10 +504,8 @@ test_cryptodev_asym_op(struct crypto_testsuite_params_asym *ts_params,
 		snprintf(test_msg, ASYM_TEST_MSG_LEN, "SESSIONLESS PASS");
 
 error_exit:
-		if (sess != NULL) {
-			rte_cryptodev_asym_session_clear(dev_id, sess);
-			rte_cryptodev_asym_session_free(sess);
-		}
+		if (sess != NULL)
+			rte_cryptodev_asym_session_free(dev_id, sess);
 
 		if (op != NULL)
 			rte_crypto_op_free(op);
@@ -669,18 +659,11 @@ test_rsa_sign_verify(void)
 		return TEST_SKIPPED;
 	}
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
+	sess = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool);
 
 	if (!sess) {
 		RTE_LOG(ERR, USER1, "Session creation failed for "
 			"sign_verify\n");
-		return TEST_FAILED;
-	}
-
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform,
-				sess_mpool) < 0) {
-		RTE_LOG(ERR, USER1, "Unable to config asym session for "
-			"sign_verify\n");
 		status = TEST_FAILED;
 		goto error_exit;
 	}
@@ -688,9 +671,7 @@ test_rsa_sign_verify(void)
 	status = queue_ops_rsa_sign_verify(sess);
 
 error_exit:
-
-	rte_cryptodev_asym_session_clear(dev_id, sess);
-	rte_cryptodev_asym_session_free(sess);
+	rte_cryptodev_asym_session_free(dev_id, sess);
 
 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
 
@@ -718,17 +699,10 @@ test_rsa_enc_dec(void)
 		return TEST_SKIPPED;
 	}
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
+	sess = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool);
 
 	if (!sess) {
 		RTE_LOG(ERR, USER1, "Session creation failed for enc_dec\n");
-		return TEST_FAILED;
-	}
-
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform,
-				sess_mpool) < 0) {
-		RTE_LOG(ERR, USER1, "Unable to config asym session for "
-			"enc_dec\n");
 		status = TEST_FAILED;
 		goto error_exit;
 	}
@@ -737,8 +711,7 @@ test_rsa_enc_dec(void)
 
 error_exit:
 
-	rte_cryptodev_asym_session_clear(dev_id, sess);
-	rte_cryptodev_asym_session_free(sess);
+	rte_cryptodev_asym_session_free(dev_id, sess);
 
 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
 
@@ -765,28 +738,20 @@ test_rsa_sign_verify_crt(void)
 		return TEST_SKIPPED;
 	}
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
+	sess = rte_cryptodev_asym_session_create(dev_id, &rsa_xform_crt, sess_mpool);
 
 	if (!sess) {
 		RTE_LOG(ERR, USER1, "Session creation failed for "
 			"sign_verify_crt\n");
 		status = TEST_FAILED;
-		return status;
-	}
-
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform_crt,
-				sess_mpool) < 0) {
-		RTE_LOG(ERR, USER1, "Unable to config asym session for "
-			"sign_verify_crt\n");
-		status = TEST_FAILED;
 		goto error_exit;
 	}
+
 	status = queue_ops_rsa_sign_verify(sess);
 
 error_exit:
 
-	rte_cryptodev_asym_session_clear(dev_id, sess);
-	rte_cryptodev_asym_session_free(sess);
+	rte_cryptodev_asym_session_free(dev_id, sess);
 
 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
 
@@ -813,27 +778,20 @@ test_rsa_enc_dec_crt(void)
 		return TEST_SKIPPED;
 	}
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
+	sess = rte_cryptodev_asym_session_create(dev_id, &rsa_xform_crt, sess_mpool);
 
 	if (!sess) {
 		RTE_LOG(ERR, USER1, "Session creation failed for "
 			"enc_dec_crt\n");
-		return TEST_FAILED;
-	}
-
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform_crt,
-				sess_mpool) < 0) {
-		RTE_LOG(ERR, USER1, "Unable to config asym session for "
-			"enc_dec_crt\n");
 		status = TEST_FAILED;
 		goto error_exit;
 	}
+
 	status = queue_ops_rsa_enc_dec(sess);
 
 error_exit:
 
-	rte_cryptodev_asym_session_clear(dev_id, sess);
-	rte_cryptodev_asym_session_free(sess);
+	rte_cryptodev_asym_session_free(dev_id, sess);
 
 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
 
@@ -927,7 +885,6 @@ testsuite_setup(void)
 	/* configure qp */
 	ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
 	ts_params->qp_conf.mp_session = ts_params->session_mpool;
-	ts_params->qp_conf.mp_session_private = ts_params->session_mpool;
 	for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
 			dev_id, qp_id, &ts_params->qp_conf,
@@ -936,21 +893,9 @@ testsuite_setup(void)
 			qp_id, dev_id);
 	}
 
-	/* setup asym session pool */
-	unsigned int session_size = RTE_MAX(
-		rte_cryptodev_asym_get_private_session_size(dev_id),
-		rte_cryptodev_asym_get_header_session_size());
-	/*
-	 * Create mempool with TEST_NUM_SESSIONS * 2,
-	 * to include the session headers
-	 */
-	ts_params->session_mpool = rte_mempool_create(
-				"test_asym_sess_mp",
-				TEST_NUM_SESSIONS * 2,
-				session_size,
-				0, 0, NULL, NULL, NULL,
-				NULL, SOCKET_ID_ANY,
-				0);
+	ts_params->session_mpool = rte_cryptodev_asym_session_pool_create(
+			"test_asym_sess_mp", TEST_NUM_SESSIONS * 2, 0,
+			SOCKET_ID_ANY);
 
 	TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
 			"session mempool allocation failed");
@@ -1107,14 +1052,6 @@ test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
 	struct rte_crypto_asym_xform xform = *xfrm;
 	uint8_t peer[] = "01234567890123456789012345678901234567890123456789";
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
-	if (sess == NULL) {
-		RTE_LOG(ERR, USER1,
-				"line %u FAILED: %s", __LINE__,
-				"Session creation failed");
-		status = TEST_FAILED;
-		goto error_exit;
-	}
 	/* set up crypto op data structure */
 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
 	if (!op) {
@@ -1137,11 +1074,11 @@ test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
 	asym_op->dh.shared_secret.data = output;
 	asym_op->dh.shared_secret.length = sizeof(output);
 
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
-			sess_mpool) < 0) {
+	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
+	if (sess == NULL) {
 		RTE_LOG(ERR, USER1,
-				"line %u FAILED: %s",
-				__LINE__, "unabled to config sym session");
+				"line %u FAILED: %s", __LINE__,
+				"Session creation failed");
 		status = TEST_FAILED;
 		goto error_exit;
 	}
@@ -1176,10 +1113,8 @@ test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
 			asym_op->dh.shared_secret.length);
 
 error_exit:
-	if (sess != NULL) {
-		rte_cryptodev_asym_session_clear(dev_id, sess);
-		rte_cryptodev_asym_session_free(sess);
-	}
+	if (sess != NULL)
+		rte_cryptodev_asym_session_free(dev_id, sess);
 	if (op != NULL)
 		rte_crypto_op_free(op);
 	return status;
@@ -1199,14 +1134,6 @@ test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
 	uint8_t output[TEST_DH_MOD_LEN];
 	struct rte_crypto_asym_xform xform = *xfrm;
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
-	if (sess == NULL) {
-		RTE_LOG(ERR, USER1,
-				 "line %u FAILED: %s", __LINE__,
-				"Session creation failed");
-		status = TEST_FAILED;
-		goto error_exit;
-	}
 	/* set up crypto op data structure */
 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
 	if (!op) {
@@ -1225,11 +1152,11 @@ test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
 	asym_op->dh.priv_key.data = output;
 	asym_op->dh.priv_key.length = sizeof(output);
 
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
-			sess_mpool) < 0) {
+	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
+	if (sess == NULL) {
 		RTE_LOG(ERR, USER1,
-				"line %u FAILED: %s",
-				__LINE__, "unabled to config sym session");
+				"line %u FAILED: %s", __LINE__,
+				"Session creation failed");
 		status = TEST_FAILED;
 		goto error_exit;
 	}
@@ -1265,10 +1192,8 @@ test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
 
 
 error_exit:
-	if (sess != NULL) {
-		rte_cryptodev_asym_session_clear(dev_id, sess);
-		rte_cryptodev_asym_session_free(sess);
-	}
+	if (sess != NULL)
+		rte_cryptodev_asym_session_free(dev_id, sess);
 	if (op != NULL)
 		rte_crypto_op_free(op);
 
@@ -1290,14 +1215,6 @@ test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
 	uint8_t output[TEST_DH_MOD_LEN];
 	struct rte_crypto_asym_xform xform = *xfrm;
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
-	if (sess == NULL) {
-		RTE_LOG(ERR, USER1,
-				 "line %u FAILED: %s", __LINE__,
-				"Session creation failed");
-		status = TEST_FAILED;
-		goto error_exit;
-	}
 	/* set up crypto op data structure */
 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
 	if (!op) {
@@ -1324,11 +1241,11 @@ test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
 					0);
 	asym_op->dh.priv_key = dh_test_params.priv_key;
 
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
-			sess_mpool) < 0) {
+	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
+	if (sess == NULL) {
 		RTE_LOG(ERR, USER1,
-				"line %u FAILED: %s",
-				__LINE__, "unabled to config sym session");
+				"line %u FAILED: %s", __LINE__,
+				"Session creation failed");
 		status = TEST_FAILED;
 		goto error_exit;
 	}
@@ -1365,10 +1282,8 @@ test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
 			asym_op->dh.priv_key.data, asym_op->dh.priv_key.length);
 
 error_exit:
-	if (sess != NULL) {
-		rte_cryptodev_asym_session_clear(dev_id, sess);
-		rte_cryptodev_asym_session_free(sess);
-	}
+	if (sess != NULL)
+		rte_cryptodev_asym_session_free(dev_id, sess);
 	if (op != NULL)
 		rte_crypto_op_free(op);
 
@@ -1391,15 +1306,6 @@ test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
 	struct rte_crypto_asym_xform pub_key_xform;
 	struct rte_crypto_asym_xform xform = *xfrm;
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
-	if (sess == NULL) {
-		RTE_LOG(ERR, USER1,
-				 "line %u FAILED: %s", __LINE__,
-				"Session creation failed");
-		status = TEST_FAILED;
-		goto error_exit;
-	}
-
 	/* set up crypto op data structure */
 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
 	if (!op) {
@@ -1423,11 +1329,12 @@ test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
 	asym_op->dh.pub_key.length = sizeof(out_pub_key);
 	asym_op->dh.priv_key.data = out_prv_key;
 	asym_op->dh.priv_key.length = sizeof(out_prv_key);
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
-			sess_mpool) < 0) {
+
+	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
+	if (sess == NULL) {
 		RTE_LOG(ERR, USER1,
-				"line %u FAILED: %s",
-				__LINE__, "unabled to config sym session");
+				"line %u FAILED: %s", __LINE__,
+				"Session creation failed");
 		status = TEST_FAILED;
 		goto error_exit;
 	}
@@ -1462,10 +1369,8 @@ test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
 			out_pub_key, asym_op->dh.pub_key.length);
 
 error_exit:
-	if (sess != NULL) {
-		rte_cryptodev_asym_session_clear(dev_id, sess);
-		rte_cryptodev_asym_session_free(sess);
-	}
+	if (sess != NULL)
+		rte_cryptodev_asym_session_free(dev_id, sess);
 	if (op != NULL)
 		rte_crypto_op_free(op);
 
@@ -1514,7 +1419,7 @@ test_mod_inv(void)
 				return TEST_SKIPPED;
 		}
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
+	sess = rte_cryptodev_asym_session_create(dev_id, &modinv_xform, sess_mpool);
 	if (!sess) {
 		RTE_LOG(ERR, USER1, "line %u "
 				"FAILED: %s", __LINE__,
@@ -1523,15 +1428,6 @@ test_mod_inv(void)
 		goto error_exit;
 	}
 
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &modinv_xform,
-			sess_mpool) < 0) {
-		RTE_LOG(ERR, USER1,
-				"line %u FAILED: %s",
-				__LINE__, "unabled to config sym session");
-		status = TEST_FAILED;
-		goto error_exit;
-	}
-
 	/* generate crypto op data structure */
 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
 	if (!op) {
@@ -1583,10 +1479,8 @@ test_mod_inv(void)
 	}
 
 error_exit:
-	if (sess) {
-		rte_cryptodev_asym_session_clear(dev_id, sess);
-		rte_cryptodev_asym_session_free(sess);
-	}
+	if (sess)
+		rte_cryptodev_asym_session_free(dev_id, sess);
 
 	if (op)
 		rte_crypto_op_free(op);
@@ -1649,7 +1543,7 @@ test_mod_exp(void)
 		goto error_exit;
 	}
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
+	sess = rte_cryptodev_asym_session_create(dev_id, &modex_xform, sess_mpool);
 	if (!sess) {
 		RTE_LOG(ERR, USER1,
 				 "line %u "
@@ -1659,15 +1553,6 @@ test_mod_exp(void)
 		goto error_exit;
 	}
 
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &modex_xform,
-			sess_mpool) < 0) {
-		RTE_LOG(ERR, USER1,
-				"line %u FAILED: %s",
-				__LINE__, "unabled to config sym session");
-		status = TEST_FAILED;
-		goto error_exit;
-	}
-
 	asym_op = op->asym;
 	memcpy(input, base, sizeof(base));
 	asym_op->modex.base.data = input;
@@ -1706,10 +1591,8 @@ test_mod_exp(void)
 	}
 
 error_exit:
-	if (sess != NULL) {
-		rte_cryptodev_asym_session_clear(dev_id, sess);
-		rte_cryptodev_asym_session_free(sess);
-	}
+	if (sess != NULL)
+		rte_cryptodev_asym_session_free(dev_id, sess);
 
 	if (op != NULL)
 		rte_crypto_op_free(op);
@@ -1771,7 +1654,7 @@ test_dsa_sign(void)
 	uint8_t s[TEST_DH_MOD_LEN];
 	uint8_t dgst[] = "35d81554afaad2cf18f3a1770d5fedc4ea5be344";
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
+	sess = rte_cryptodev_asym_session_create(dev_id, &dsa_xform, sess_mpool);
 	if (sess == NULL) {
 		RTE_LOG(ERR, USER1,
 				 "line %u FAILED: %s", __LINE__,
@@ -1800,15 +1683,6 @@ test_dsa_sign(void)
 	debug_hexdump(stdout, "priv_key: ", dsa_xform.dsa.x.data,
 			dsa_xform.dsa.x.length);
 
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &dsa_xform,
-				sess_mpool) < 0) {
-		RTE_LOG(ERR, USER1,
-				"line %u FAILED: %s",
-				__LINE__, "unabled to config sym session");
-		status = TEST_FAILED;
-		goto error_exit;
-	}
-
 	/* attach asymmetric crypto session to crypto operations */
 	rte_crypto_op_attach_asym_session(op, sess);
 	asym_op->dsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
@@ -1882,10 +1756,8 @@ test_dsa_sign(void)
 		status = TEST_FAILED;
 	}
 error_exit:
-	if (sess != NULL) {
-		rte_cryptodev_asym_session_clear(dev_id, sess);
-		rte_cryptodev_asym_session_free(sess);
-	}
+	if (sess != NULL)
+		rte_cryptodev_asym_session_free(dev_id, sess);
 	if (op != NULL)
 		rte_crypto_op_free(op);
 	return status;
@@ -1944,15 +1816,6 @@ test_ecdsa_sign_verify(enum curve curve_id)
 
 	rte_cryptodev_info_get(dev_id, &dev_info);
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
-	if (sess == NULL) {
-		RTE_LOG(ERR, USER1,
-				"line %u FAILED: %s", __LINE__,
-				"Session creation failed\n");
-		status = TEST_FAILED;
-		goto exit;
-	}
-
 	/* Setup crypto op data structure */
 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
 	if (op == NULL) {
@@ -1970,11 +1833,11 @@ test_ecdsa_sign_verify(enum curve curve_id)
 	xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDSA;
 	xform.ec.curve_id = input_params.curve;
 
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
-				sess_mpool) < 0) {
+	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
+	if (sess == NULL) {
 		RTE_LOG(ERR, USER1,
 				"line %u FAILED: %s", __LINE__,
-				"Unable to config asym session\n");
+				"Session creation failed\n");
 		status = TEST_FAILED;
 		goto exit;
 	}
@@ -2082,10 +1945,8 @@ test_ecdsa_sign_verify(enum curve curve_id)
 	}
 
 exit:
-	if (sess != NULL) {
-		rte_cryptodev_asym_session_clear(dev_id, sess);
-		rte_cryptodev_asym_session_free(sess);
-	}
+	if (sess != NULL)
+		rte_cryptodev_asym_session_free(dev_id, sess);
 	if (op != NULL)
 		rte_crypto_op_free(op);
 	return status;
@@ -2157,15 +2018,6 @@ test_ecpm(enum curve curve_id)
 
 	rte_cryptodev_info_get(dev_id, &dev_info);
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
-	if (sess == NULL) {
-		RTE_LOG(ERR, USER1,
-				"line %u FAILED: %s", __LINE__,
-				"Session creation failed\n");
-		status = TEST_FAILED;
-		goto exit;
-	}
-
 	/* Setup crypto op data structure */
 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
 	if (op == NULL) {
@@ -2183,11 +2035,11 @@ test_ecpm(enum curve curve_id)
 	xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECPM;
 	xform.ec.curve_id = input_params.curve;
 
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
-				sess_mpool) < 0) {
+	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
+	if (sess == NULL) {
 		RTE_LOG(ERR, USER1,
 				"line %u FAILED: %s", __LINE__,
-				"Unable to config asym session\n");
+				"Session creation failed\n");
 		status = TEST_FAILED;
 		goto exit;
 	}
@@ -2255,10 +2107,8 @@ test_ecpm(enum curve curve_id)
 	}
 
 exit:
-	if (sess != NULL) {
-		rte_cryptodev_asym_session_clear(dev_id, sess);
-		rte_cryptodev_asym_session_free(sess);
-	}
+	if (sess != NULL)
+		rte_cryptodev_asym_session_free(dev_id, sess);
 	if (op != NULL)
 		rte_crypto_op_free(op);
 	return status;
diff --git a/doc/guides/prog_guide/cryptodev_lib.rst b/doc/guides/prog_guide/cryptodev_lib.rst
index 9f33f7a177..b4dbd384bf 100644
--- a/doc/guides/prog_guide/cryptodev_lib.rst
+++ b/doc/guides/prog_guide/cryptodev_lib.rst
@@ -1038,20 +1038,17 @@ It is the application's responsibility to create and manage the session mempools
 Application using both symmetric and asymmetric sessions should allocate and maintain
 different sessions pools for each type.
 
-An application can use ``rte_cryptodev_get_asym_session_private_size()`` to
-get the private size of asymmetric session on a given crypto device. This
-function would allow an application to calculate the max device asymmetric
-session size of all crypto devices to create a single session mempool.
-If instead an application creates multiple asymmetric session mempools,
-the Crypto device framework also provides ``rte_cryptodev_asym_get_header_session_size()`` to get
-the size of an uninitialized session.
+An application can use ``rte_cryptodev_asym_session_pool_create()`` to create a mempool
+with a specified number of elements. The element size will allow for the session header,
+and the max private session size.
+The max private session size is chosen based on available crypto devices,
+the biggest private session size is used. This means any of those devices can be used,
+and the mempool element will have available space for its private session data.
 
 Once the session mempools have been created, ``rte_cryptodev_asym_session_create()``
-is used to allocate an uninitialized asymmetric session from the given mempool.
-The session then must be initialized using ``rte_cryptodev_asym_session_init()``
-for each of the required crypto devices. An asymmetric transform chain
-is used to specify the operation and its parameters. See the section below for
-details on transforms.
+is used to allocate and initialize an asymmetric session from the given mempool.
+An asymmetric transform chain is used to specify the operation and its parameters.
+See the section below for details on transforms.
 
 When a session is no longer used, user must call ``rte_cryptodev_asym_session_clear()``
 for each of the crypto devices that are using the session, to free all driver
diff --git a/doc/guides/rel_notes/release_22_03.rst b/doc/guides/rel_notes/release_22_03.rst
index a820cc5596..ea4c5309a0 100644
--- a/doc/guides/rel_notes/release_22_03.rst
+++ b/doc/guides/rel_notes/release_22_03.rst
@@ -112,6 +112,13 @@ API Changes
 * ethdev: Old public macros and enumeration constants without ``RTE_ETH_`` prefix,
   which are kept for backward compatibility, are marked as deprecated.
 
+* cryptodev: The asymmetric session handling was modified to use a single
+  mempool object. An API ``rte_cryptodev_asym_session_pool_create`` was added
+  to create a mempool with element size big enough to hold the generic asymmetric
+  session header and max size for a device private session data.
+  The API ``rte_cryptodev_asym_session_init`` was removed as the initialization
+  is now moved to ``rte_cryptodev_asym_session_create``.
+
 
 ABI Changes
 -----------
diff --git a/drivers/crypto/cnxk/cn10k_cryptodev_ops.c b/drivers/crypto/cnxk/cn10k_cryptodev_ops.c
index d217bbf383..7390f976c6 100644
--- a/drivers/crypto/cnxk/cn10k_cryptodev_ops.c
+++ b/drivers/crypto/cnxk/cn10k_cryptodev_ops.c
@@ -157,8 +157,7 @@ cn10k_cpt_fill_inst(struct cnxk_cpt_qp *qp, struct rte_crypto_op *ops[],
 
 		if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
 			asym_op = op->asym;
-			ae_sess = get_asym_session_private_data(
-				asym_op->session, cn10k_cryptodev_driver_id);
+			ae_sess = get_asym_session_private_data(asym_op->session);
 			ret = cnxk_ae_enqueue(qp, op, infl_req, &inst[0],
 					      ae_sess);
 			if (unlikely(ret))
@@ -431,8 +430,7 @@ cn10k_cpt_dequeue_post_process(struct cnxk_cpt_qp *qp,
 			uintptr_t *mdata = infl_req->mdata;
 			struct cnxk_ae_sess *sess;
 
-			sess = get_asym_session_private_data(
-				op->session, cn10k_cryptodev_driver_id);
+			sess = get_asym_session_private_data(op->session);
 
 			cnxk_ae_post_process(cop, sess, (uint8_t *)mdata[0]);
 		}
diff --git a/drivers/crypto/cnxk/cn9k_cryptodev_ops.c b/drivers/crypto/cnxk/cn9k_cryptodev_ops.c
index ac1953b66d..59a06af30e 100644
--- a/drivers/crypto/cnxk/cn9k_cryptodev_ops.c
+++ b/drivers/crypto/cnxk/cn9k_cryptodev_ops.c
@@ -138,8 +138,7 @@ cn9k_cpt_inst_prep(struct cnxk_cpt_qp *qp, struct rte_crypto_op *op,
 
 		if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
 			asym_op = op->asym;
-			sess = get_asym_session_private_data(
-				asym_op->session, cn9k_cryptodev_driver_id);
+			sess = get_asym_session_private_data(asym_op->session);
 			ret = cnxk_ae_enqueue(qp, op, infl_req, inst, sess);
 			inst->w7.u64 = sess->cpt_inst_w7;
 		} else {
@@ -453,8 +452,7 @@ cn9k_cpt_dequeue_post_process(struct cnxk_cpt_qp *qp, struct rte_crypto_op *cop,
 			uintptr_t *mdata = infl_req->mdata;
 			struct cnxk_ae_sess *sess;
 
-			sess = get_asym_session_private_data(
-				op->session, cn9k_cryptodev_driver_id);
+			sess = get_asym_session_private_data(op->session);
 
 			cnxk_ae_post_process(cop, sess, (uint8_t *)mdata[0]);
 		}
diff --git a/drivers/crypto/cnxk/cnxk_cryptodev_ops.c b/drivers/crypto/cnxk/cnxk_cryptodev_ops.c
index a5fb68da02..7bfac186f9 100644
--- a/drivers/crypto/cnxk/cnxk_cryptodev_ops.c
+++ b/drivers/crypto/cnxk/cnxk_cryptodev_ops.c
@@ -658,10 +658,9 @@ void
 cnxk_ae_session_clear(struct rte_cryptodev *dev,
 		      struct rte_cryptodev_asym_session *sess)
 {
-	struct rte_mempool *sess_mp;
 	struct cnxk_ae_sess *priv;
 
-	priv = get_asym_session_private_data(sess, dev->driver_id);
+	priv = get_asym_session_private_data(sess);
 	if (priv == NULL)
 		return;
 
@@ -670,40 +669,28 @@ cnxk_ae_session_clear(struct rte_cryptodev *dev,
 
 	/* Reset and free object back to pool */
 	memset(priv, 0, cnxk_ae_session_size_get(dev));
-	sess_mp = rte_mempool_from_obj(priv);
-	set_asym_session_private_data(sess, dev->driver_id, NULL);
-	rte_mempool_put(sess_mp, priv);
 }
 
 int
 cnxk_ae_session_cfg(struct rte_cryptodev *dev,
 		    struct rte_crypto_asym_xform *xform,
-		    struct rte_cryptodev_asym_session *sess,
-		    struct rte_mempool *pool)
+		    struct rte_cryptodev_asym_session *sess)
 {
 	struct cnxk_cpt_vf *vf = dev->data->dev_private;
 	struct roc_cpt *roc_cpt = &vf->cpt;
-	struct cnxk_ae_sess *priv;
+	struct cnxk_ae_sess *priv = get_asym_session_private_data(sess);
 	union cpt_inst_w7 w7;
 	int ret;
 
-	if (rte_mempool_get(pool, (void **)&priv))
-		return -ENOMEM;
-
-	memset(priv, 0, sizeof(struct cnxk_ae_sess));
-
 	ret = cnxk_ae_fill_session_parameters(priv, xform);
-	if (ret) {
-		rte_mempool_put(pool, priv);
+	if (ret)
 		return ret;
-	}
 
 	w7.u64 = 0;
 	w7.s.egrp = roc_cpt->eng_grp[CPT_ENG_TYPE_AE];
 	priv->cpt_inst_w7 = w7.u64;
 	priv->cnxk_fpm_iova = vf->cnxk_fpm_iova;
 	priv->ec_grp = vf->ec_grp;
-	set_asym_session_private_data(sess, dev->driver_id, priv);
 
 	return 0;
 }
diff --git a/drivers/crypto/cnxk/cnxk_cryptodev_ops.h b/drivers/crypto/cnxk/cnxk_cryptodev_ops.h
index 0656ba9675..ab0f00ee7c 100644
--- a/drivers/crypto/cnxk/cnxk_cryptodev_ops.h
+++ b/drivers/crypto/cnxk/cnxk_cryptodev_ops.h
@@ -122,8 +122,7 @@ void cnxk_ae_session_clear(struct rte_cryptodev *dev,
 			   struct rte_cryptodev_asym_session *sess);
 int cnxk_ae_session_cfg(struct rte_cryptodev *dev,
 			struct rte_crypto_asym_xform *xform,
-			struct rte_cryptodev_asym_session *sess,
-			struct rte_mempool *pool);
+			struct rte_cryptodev_asym_session *sess);
 void cnxk_cpt_dump_on_err(struct cnxk_cpt_qp *qp);
 
 static inline union rte_event_crypto_metadata *
diff --git a/drivers/crypto/octeontx/otx_cryptodev_ops.c b/drivers/crypto/octeontx/otx_cryptodev_ops.c
index f7ca8a8a8e..cf3947f1ab 100644
--- a/drivers/crypto/octeontx/otx_cryptodev_ops.c
+++ b/drivers/crypto/octeontx/otx_cryptodev_ops.c
@@ -375,35 +375,23 @@ otx_cpt_asym_session_size_get(struct rte_cryptodev *dev __rte_unused)
 }
 
 static int
-otx_cpt_asym_session_cfg(struct rte_cryptodev *dev,
+otx_cpt_asym_session_cfg(struct rte_cryptodev *dev __rte_unused,
 			 struct rte_crypto_asym_xform *xform __rte_unused,
-			 struct rte_cryptodev_asym_session *sess,
-			 struct rte_mempool *pool)
+			 struct rte_cryptodev_asym_session *sess)
 {
-	struct cpt_asym_sess_misc *priv;
+	struct cpt_asym_sess_misc *priv = get_asym_session_private_data(sess);
 	int ret;
 
 	CPT_PMD_INIT_FUNC_TRACE();
 
-	if (rte_mempool_get(pool, (void **)&priv)) {
-		CPT_LOG_ERR("Could not allocate session private data");
-		return -ENOMEM;
-	}
-
-	memset(priv, 0, sizeof(struct cpt_asym_sess_misc));
-
 	ret = cpt_fill_asym_session_parameters(priv, xform);
 	if (ret) {
 		CPT_LOG_ERR("Could not configure session parameters");
-
-		/* Return session to mempool */
-		rte_mempool_put(pool, priv);
 		return ret;
 	}
 
 	priv->cpt_inst_w7 = 0;
 
-	set_asym_session_private_data(sess, dev->driver_id, priv);
 	return 0;
 }
 
@@ -412,11 +400,10 @@ otx_cpt_asym_session_clear(struct rte_cryptodev *dev,
 			   struct rte_cryptodev_asym_session *sess)
 {
 	struct cpt_asym_sess_misc *priv;
-	struct rte_mempool *sess_mp;
 
 	CPT_PMD_INIT_FUNC_TRACE();
 
-	priv = get_asym_session_private_data(sess, dev->driver_id);
+	priv = get_asym_session_private_data(sess);
 
 	if (priv == NULL)
 		return;
@@ -424,9 +411,6 @@ otx_cpt_asym_session_clear(struct rte_cryptodev *dev,
 	/* Free resources allocated during session configure */
 	cpt_free_asym_session_parameters(priv);
 	memset(priv, 0, otx_cpt_asym_session_size_get(dev));
-	sess_mp = rte_mempool_from_obj(priv);
-	set_asym_session_private_data(sess, dev->driver_id, NULL);
-	rte_mempool_put(sess_mp, priv);
 }
 
 static __rte_always_inline void * __rte_hot
@@ -471,8 +455,7 @@ otx_cpt_enq_single_asym(struct cpt_instance *instance,
 		return NULL;
 	}
 
-	sess = get_asym_session_private_data(asym_op->session,
-					     otx_cryptodev_driver_id);
+	sess = get_asym_session_private_data(asym_op->session);
 
 	/* Store phys_addr of the mdata to meta_buf */
 	params.meta_buf = rte_mempool_virt2iova(mdata);
@@ -852,8 +835,7 @@ otx_cpt_asym_post_process(struct rte_crypto_op *cop,
 	struct rte_crypto_asym_op *op = cop->asym;
 	struct cpt_asym_sess_misc *sess;
 
-	sess = get_asym_session_private_data(op->session,
-					     otx_cryptodev_driver_id);
+	sess = get_asym_session_private_data(op->session);
 
 	switch (sess->xfrm_type) {
 	case RTE_CRYPTO_ASYM_XFORM_RSA:
diff --git a/drivers/crypto/openssl/rte_openssl_pmd.c b/drivers/crypto/openssl/rte_openssl_pmd.c
index 5794ed8159..1e7e5f6849 100644
--- a/drivers/crypto/openssl/rte_openssl_pmd.c
+++ b/drivers/crypto/openssl/rte_openssl_pmd.c
@@ -747,10 +747,7 @@ get_session(struct openssl_qp *qp, struct rte_crypto_op *op)
 						cryptodev_driver_id);
 		} else {
 			if (likely(op->asym->session != NULL))
-				asym_sess = (struct openssl_asym_session *)
-						get_asym_session_private_data(
-						op->asym->session,
-						cryptodev_driver_id);
+				asym_sess = get_asym_session_private_data(op->asym->session);
 			if (asym_sess == NULL)
 				op->status =
 					RTE_CRYPTO_OP_STATUS_INVALID_SESSION;
diff --git a/drivers/crypto/openssl/rte_openssl_pmd_ops.c b/drivers/crypto/openssl/rte_openssl_pmd_ops.c
index 52715f86f8..92b9524bf3 100644
--- a/drivers/crypto/openssl/rte_openssl_pmd_ops.c
+++ b/drivers/crypto/openssl/rte_openssl_pmd_ops.c
@@ -1119,8 +1119,7 @@ static int openssl_set_asym_session_parameters(
 static int
 openssl_pmd_asym_session_configure(struct rte_cryptodev *dev __rte_unused,
 		struct rte_crypto_asym_xform *xform,
-		struct rte_cryptodev_asym_session *sess,
-		struct rte_mempool *mempool)
+		struct rte_cryptodev_asym_session *sess)
 {
 	void *asym_sess_private_data;
 	int ret;
@@ -1130,25 +1129,14 @@ openssl_pmd_asym_session_configure(struct rte_cryptodev *dev __rte_unused,
 		return -EINVAL;
 	}
 
-	if (rte_mempool_get(mempool, &asym_sess_private_data)) {
-		CDEV_LOG_ERR(
-			"Couldn't get object from session mempool");
-		return -ENOMEM;
-	}
-
+	asym_sess_private_data = get_asym_session_private_data(sess);
 	ret = openssl_set_asym_session_parameters(asym_sess_private_data,
 			xform);
 	if (ret != 0) {
 		OPENSSL_LOG(ERR, "failed configure session parameters");
-
-		/* Return session to mempool */
-		rte_mempool_put(mempool, asym_sess_private_data);
 		return ret;
 	}
 
-	set_asym_session_private_data(sess, dev->driver_id,
-			asym_sess_private_data);
-
 	return 0;
 }
 
@@ -1206,19 +1194,15 @@ static void openssl_reset_asym_session(struct openssl_asym_session *sess)
  * so it doesn't leave key material behind
  */
 static void
-openssl_pmd_asym_session_clear(struct rte_cryptodev *dev,
+openssl_pmd_asym_session_clear(struct rte_cryptodev *dev __rte_unused,
 		struct rte_cryptodev_asym_session *sess)
 {
-	uint8_t index = dev->driver_id;
-	void *sess_priv = get_asym_session_private_data(sess, index);
+	void *sess_priv = get_asym_session_private_data(sess);
 
 	/* Zero out the whole structure */
 	if (sess_priv) {
 		openssl_reset_asym_session(sess_priv);
 		memset(sess_priv, 0, sizeof(struct openssl_asym_session));
-		struct rte_mempool *sess_mp = rte_mempool_from_obj(sess_priv);
-		set_asym_session_private_data(sess, index, NULL);
-		rte_mempool_put(sess_mp, sess_priv);
 	}
 }
 
diff --git a/drivers/crypto/qat/qat_asym.c b/drivers/crypto/qat/qat_asym.c
index 09d8761c5f..6576e8c87c 100644
--- a/drivers/crypto/qat/qat_asym.c
+++ b/drivers/crypto/qat/qat_asym.c
@@ -491,9 +491,7 @@ qat_asym_build_request(void *in_op,
 
 	op->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
 	if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
-		ctx = (struct qat_asym_session *)
-			get_asym_session_private_data(
-			op->asym->session, qat_asym_driver_id);
+		ctx = get_asym_session_private_data(op->asym->session);
 		if (unlikely(ctx == NULL)) {
 			QAT_LOG(ERR, "Session has not been created for this device");
 			goto error;
@@ -711,8 +709,7 @@ qat_asym_process_response(void **op, uint8_t *resp,
 	}
 
 	if (rx_op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
-		ctx = (struct qat_asym_session *)get_asym_session_private_data(
-			rx_op->asym->session, qat_asym_driver_id);
+		ctx = get_asym_session_private_data(rx_op->asym->session);
 		qat_asym_collect_response(rx_op, cookie, ctx->xform);
 	} else if (rx_op->sess_type == RTE_CRYPTO_OP_SESSIONLESS) {
 		qat_asym_collect_response(rx_op, cookie, rx_op->asym->xform);
@@ -726,61 +723,42 @@ qat_asym_process_response(void **op, uint8_t *resp,
 }
 
 int
-qat_asym_session_configure(struct rte_cryptodev *dev,
+qat_asym_session_configure(struct rte_cryptodev *dev __rte_unused,
 		struct rte_crypto_asym_xform *xform,
-		struct rte_cryptodev_asym_session *sess,
-		struct rte_mempool *mempool)
+		struct rte_cryptodev_asym_session *sess)
 {
-	int err = 0;
-	void *sess_private_data;
 	struct qat_asym_session *session;
 
-	if (rte_mempool_get(mempool, &sess_private_data)) {
-		QAT_LOG(ERR,
-			"Couldn't get object from session mempool");
-		return -ENOMEM;
-	}
-
-	session = sess_private_data;
+	session = get_asym_session_private_data(sess);
 	if (xform->xform_type == RTE_CRYPTO_ASYM_XFORM_MODEX) {
 		if (xform->modex.exponent.length == 0 ||
 				xform->modex.modulus.length == 0) {
 			QAT_LOG(ERR, "Invalid mod exp input parameter");
-			err = -EINVAL;
-			goto error;
+			return -EINVAL;
 		}
 	} else if (xform->xform_type == RTE_CRYPTO_ASYM_XFORM_MODINV) {
 		if (xform->modinv.modulus.length == 0) {
 			QAT_LOG(ERR, "Invalid mod inv input parameter");
-			err = -EINVAL;
-			goto error;
+			return -EINVAL;
 		}
 	} else if (xform->xform_type == RTE_CRYPTO_ASYM_XFORM_RSA) {
 		if (xform->rsa.n.length == 0) {
 			QAT_LOG(ERR, "Invalid rsa input parameter");
-			err = -EINVAL;
-			goto error;
+			return -EINVAL;
 		}
 	} else if (xform->xform_type >= RTE_CRYPTO_ASYM_XFORM_TYPE_LIST_END
 			|| xform->xform_type <= RTE_CRYPTO_ASYM_XFORM_NONE) {
 		QAT_LOG(ERR, "Invalid asymmetric crypto xform");
-		err = -EINVAL;
-		goto error;
+		return -EINVAL;
 	} else {
 		QAT_LOG(ERR, "Asymmetric crypto xform not implemented");
-		err = -EINVAL;
-		goto error;
+		return -EINVAL;
 	}
 
 	session->xform = xform;
-	qat_asym_build_req_tmpl(sess_private_data);
-	set_asym_session_private_data(sess, dev->driver_id,
-		sess_private_data);
+	qat_asym_build_req_tmpl(session);
 
 	return 0;
-error:
-	rte_mempool_put(mempool, sess_private_data);
-	return err;
 }
 
 unsigned int qat_asym_session_get_private_size(
@@ -793,15 +771,9 @@ void
 qat_asym_session_clear(struct rte_cryptodev *dev,
 		struct rte_cryptodev_asym_session *sess)
 {
-	uint8_t index = dev->driver_id;
-	void *sess_priv = get_asym_session_private_data(sess, index);
+	void *sess_priv = get_asym_session_private_data(sess);
 	struct qat_asym_session *s = (struct qat_asym_session *)sess_priv;
 
-	if (sess_priv) {
+	if (sess_priv)
 		memset(s, 0, qat_asym_session_get_private_size(dev));
-		struct rte_mempool *sess_mp = rte_mempool_from_obj(sess_priv);
-
-		set_asym_session_private_data(sess, index, NULL);
-		rte_mempool_put(sess_mp, sess_priv);
-	}
 }
diff --git a/drivers/crypto/qat/qat_asym.h b/drivers/crypto/qat/qat_asym.h
index 308b6b2e0b..c9242a12ca 100644
--- a/drivers/crypto/qat/qat_asym.h
+++ b/drivers/crypto/qat/qat_asym.h
@@ -46,10 +46,9 @@ struct qat_asym_session {
 };
 
 int
-qat_asym_session_configure(struct rte_cryptodev *dev,
+qat_asym_session_configure(struct rte_cryptodev *dev __rte_unused,
 		struct rte_crypto_asym_xform *xform,
-		struct rte_cryptodev_asym_session *sess,
-		struct rte_mempool *mempool);
+		struct rte_cryptodev_asym_session *sess);
 
 unsigned int
 qat_asym_session_get_private_size(struct rte_cryptodev *dev);
diff --git a/lib/cryptodev/cryptodev_pmd.h b/lib/cryptodev/cryptodev_pmd.h
index b9146f652c..aeaccfa611 100644
--- a/lib/cryptodev/cryptodev_pmd.h
+++ b/lib/cryptodev/cryptodev_pmd.h
@@ -319,7 +319,6 @@ typedef int (*cryptodev_sym_configure_session_t)(struct rte_cryptodev *dev,
  * @param	dev		Crypto device pointer
  * @param	xform		Single or chain of crypto xforms
  * @param	session		Pointer to cryptodev's private session structure
- * @param	mp		Mempool where the private session is allocated
  *
  * @return
  *  - Returns 0 if private session structure have been created successfully.
@@ -329,8 +328,7 @@ typedef int (*cryptodev_sym_configure_session_t)(struct rte_cryptodev *dev,
  */
 typedef int (*cryptodev_asym_configure_session_t)(struct rte_cryptodev *dev,
 		struct rte_crypto_asym_xform *xform,
-		struct rte_cryptodev_asym_session *session,
-		struct rte_mempool *mp);
+		struct rte_cryptodev_asym_session *session);
 /**
  * Free driver private session data.
  *
@@ -340,12 +338,12 @@ typedef int (*cryptodev_asym_configure_session_t)(struct rte_cryptodev *dev,
 typedef void (*cryptodev_sym_free_session_t)(struct rte_cryptodev *dev,
 		struct rte_cryptodev_sym_session *sess);
 /**
- * Free asymmetric session private data.
+ * Clear asymmetric session private data.
  *
  * @param	dev		Crypto device pointer
  * @param	sess		Cryptodev session structure
  */
-typedef void (*cryptodev_asym_free_session_t)(struct rte_cryptodev *dev,
+typedef void (*cryptodev_asym_clear_session_t)(struct rte_cryptodev *dev,
 		struct rte_cryptodev_asym_session *sess);
 /**
  * Perform actual crypto processing (encrypt/digest or auth/decrypt)
@@ -429,7 +427,7 @@ struct rte_cryptodev_ops {
 	/**< Configure asymmetric Crypto session. */
 	cryptodev_sym_free_session_t sym_session_clear;
 	/**< Clear a Crypto sessions private data. */
-	cryptodev_asym_free_session_t asym_session_clear;
+	cryptodev_asym_clear_session_t asym_session_clear;
 	/**< Clear a Crypto sessions private data. */
 	union {
 		cryptodev_sym_cpu_crypto_process_t sym_cpu_process;
@@ -628,16 +626,9 @@ set_sym_session_private_data(struct rte_cryptodev_sym_session *sess,
 }
 
 static inline void *
-get_asym_session_private_data(const struct rte_cryptodev_asym_session *sess,
-		uint8_t driver_id) {
-	return sess->sess_private_data[driver_id];
-}
-
-static inline void
-set_asym_session_private_data(struct rte_cryptodev_asym_session *sess,
-		uint8_t driver_id, void *private_data)
+get_asym_session_private_data(struct rte_cryptodev_asym_session *sess)
 {
-	sess->sess_private_data[driver_id] = private_data;
+	return sess->sess_private_data;
 }
 
 #endif /* _CRYPTODEV_PMD_H_ */
diff --git a/lib/cryptodev/cryptodev_trace_points.c b/lib/cryptodev/cryptodev_trace_points.c
index 5d58951fd5..c5bfe08b79 100644
--- a/lib/cryptodev/cryptodev_trace_points.c
+++ b/lib/cryptodev/cryptodev_trace_points.c
@@ -24,6 +24,9 @@ RTE_TRACE_POINT_REGISTER(rte_cryptodev_trace_queue_pair_setup,
 RTE_TRACE_POINT_REGISTER(rte_cryptodev_trace_sym_session_pool_create,
 	lib.cryptodev.sym.pool.create)
 
+RTE_TRACE_POINT_REGISTER(rte_cryptodev_trace_asym_session_pool_create,
+	lib.cryptodev.asym.pool.create)
+
 RTE_TRACE_POINT_REGISTER(rte_cryptodev_trace_sym_session_create,
 	lib.cryptodev.sym.create)
 
@@ -39,15 +42,9 @@ RTE_TRACE_POINT_REGISTER(rte_cryptodev_trace_asym_session_free,
 RTE_TRACE_POINT_REGISTER(rte_cryptodev_trace_sym_session_init,
 	lib.cryptodev.sym.init)
 
-RTE_TRACE_POINT_REGISTER(rte_cryptodev_trace_asym_session_init,
-	lib.cryptodev.asym.init)
-
 RTE_TRACE_POINT_REGISTER(rte_cryptodev_trace_sym_session_clear,
 	lib.cryptodev.sym.clear)
 
-RTE_TRACE_POINT_REGISTER(rte_cryptodev_trace_asym_session_clear,
-	lib.cryptodev.asym.clear)
-
 RTE_TRACE_POINT_REGISTER(rte_cryptodev_trace_enqueue_burst,
 	lib.cryptodev.enq.burst)
 
diff --git a/lib/cryptodev/rte_cryptodev.c b/lib/cryptodev/rte_cryptodev.c
index a40536c5ea..d4cdc56912 100644
--- a/lib/cryptodev/rte_cryptodev.c
+++ b/lib/cryptodev/rte_cryptodev.c
@@ -195,7 +195,7 @@ const char *rte_crypto_asym_op_strings[] = {
 };
 
 /**
- * The private data structure stored in the session mempool private data.
+ * The private data structure stored in the sym session mempool private data.
  */
 struct rte_cryptodev_sym_session_pool_private_data {
 	uint16_t nb_drivers;
@@ -204,6 +204,14 @@ struct rte_cryptodev_sym_session_pool_private_data {
 	/**< session user data will be placed after sess_data */
 };
 
+/**
+ * The private data structure stored in the asym session mempool private data.
+ */
+struct rte_cryptodev_asym_session_pool_private_data {
+	uint16_t max_priv_session_sz;
+	/**< Size of private session data used when creating mempool */
+};
+
 int
 rte_cryptodev_get_cipher_algo_enum(enum rte_crypto_cipher_algorithm *algo_enum,
 		const char *algo_string)
@@ -1751,47 +1759,6 @@ rte_cryptodev_sym_session_init(uint8_t dev_id,
 	return 0;
 }
 
-int
-rte_cryptodev_asym_session_init(uint8_t dev_id,
-		struct rte_cryptodev_asym_session *sess,
-		struct rte_crypto_asym_xform *xforms,
-		struct rte_mempool *mp)
-{
-	struct rte_cryptodev *dev;
-	uint8_t index;
-	int ret;
-
-	if (!rte_cryptodev_is_valid_dev(dev_id)) {
-		CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
-		return -EINVAL;
-	}
-
-	dev = rte_cryptodev_pmd_get_dev(dev_id);
-
-	if (sess == NULL || xforms == NULL || dev == NULL)
-		return -EINVAL;
-
-	index = dev->driver_id;
-
-	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->asym_session_configure,
-				-ENOTSUP);
-
-	if (sess->sess_private_data[index] == NULL) {
-		ret = dev->dev_ops->asym_session_configure(dev,
-							xforms,
-							sess, mp);
-		if (ret < 0) {
-			CDEV_LOG_ERR(
-				"dev_id %d failed to configure session details",
-				dev_id);
-			return ret;
-		}
-	}
-
-	rte_cryptodev_trace_asym_session_init(dev_id, sess, xforms, mp);
-	return 0;
-}
-
 struct rte_mempool *
 rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
 	uint32_t elt_size, uint32_t cache_size, uint16_t user_data_size,
@@ -1834,6 +1801,53 @@ rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
 	return mp;
 }
 
+struct rte_mempool *
+rte_cryptodev_asym_session_pool_create(const char *name, uint32_t nb_elts,
+	uint32_t cache_size, int socket_id)
+{
+	struct rte_mempool *mp;
+	struct rte_cryptodev_asym_session_pool_private_data *pool_priv;
+	uint32_t obj_sz, obj_sz_aligned;
+	uint8_t dev_id, priv_sz, max_priv_sz = 0;
+
+	for (dev_id = 0; dev_id < RTE_CRYPTO_MAX_DEVS; dev_id++)
+		if (rte_cryptodev_is_valid_dev(dev_id)) {
+			priv_sz = rte_cryptodev_asym_get_private_session_size(dev_id);
+			if (priv_sz > max_priv_sz)
+				max_priv_sz = priv_sz;
+		}
+	if (max_priv_sz == 0) {
+		CDEV_LOG_INFO("Could not set max private session size\n");
+		return NULL;
+	}
+
+	obj_sz = rte_cryptodev_asym_get_header_session_size() + max_priv_sz;
+	obj_sz_aligned =  RTE_ALIGN_CEIL(obj_sz, RTE_CACHE_LINE_SIZE);
+
+	mp = rte_mempool_create(name, nb_elts, obj_sz_aligned, cache_size,
+			(uint32_t)(sizeof(*pool_priv)),
+			NULL, NULL, NULL, NULL,
+			socket_id, 0);
+	if (mp == NULL) {
+		CDEV_LOG_ERR("%s(name=%s) failed, rte_errno=%d\n",
+			__func__, name, rte_errno);
+		return NULL;
+	}
+
+	pool_priv = rte_mempool_get_priv(mp);
+	if (!pool_priv) {
+		CDEV_LOG_ERR("%s(name=%s) failed to get private data\n",
+			__func__, name);
+		rte_mempool_free(mp);
+		return NULL;
+	}
+	pool_priv->max_priv_session_sz = max_priv_sz;
+
+	rte_cryptodev_trace_asym_session_pool_create(name, nb_elts,
+		cache_size, mp);
+	return mp;
+}
+
 static unsigned int
 rte_cryptodev_sym_session_data_size(struct rte_cryptodev_sym_session *sess)
 {
@@ -1895,19 +1909,44 @@ rte_cryptodev_sym_session_create(struct rte_mempool *mp)
 }
 
 struct rte_cryptodev_asym_session *
-rte_cryptodev_asym_session_create(struct rte_mempool *mp)
+rte_cryptodev_asym_session_create(uint8_t dev_id,
+		struct rte_crypto_asym_xform *xforms, struct rte_mempool *mp)
 {
 	struct rte_cryptodev_asym_session *sess;
-	unsigned int session_size =
+	uint32_t session_priv_data_sz;
+	struct rte_cryptodev_asym_session_pool_private_data *pool_priv;
+	unsigned int session_header_size =
 			rte_cryptodev_asym_get_header_session_size();
+	struct rte_cryptodev *dev;
+	int ret;
+
+	if (!rte_cryptodev_is_valid_dev(dev_id)) {
+		CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
+		return NULL;
+	}
+
+	dev = rte_cryptodev_pmd_get_dev(dev_id);
+
+	if (dev == NULL)
+		return NULL;
 
 	if (!mp) {
 		CDEV_LOG_ERR("invalid mempool\n");
 		return NULL;
 	}
 
+	session_priv_data_sz = rte_cryptodev_asym_get_private_session_size(
+			dev_id);
+	pool_priv = rte_mempool_get_priv(mp);
+
+	if (pool_priv->max_priv_session_sz < session_priv_data_sz) {
+		CDEV_LOG_DEBUG(
+			"The private session data size used when creating the mempool is smaller than this device's private session data.");
+		return NULL;
+	}
+
 	/* Verify if provided mempool can hold elements big enough. */
-	if (mp->elt_size < session_size) {
+	if (mp->elt_size < session_header_size + session_priv_data_sz) {
 		CDEV_LOG_ERR(
 			"mempool elements too small to hold session objects");
 		return NULL;
@@ -1919,12 +1958,25 @@ rte_cryptodev_asym_session_create(struct rte_mempool *mp)
 		return NULL;
 	}
 
-	/* Clear device session pointer.
-	 * Include the flag indicating presence of private data
-	 */
-	memset(sess, 0, session_size);
+	sess->driver_id = dev->driver_id;
+	sess->max_priv_data_sz = pool_priv->max_priv_session_sz;
+
+	/* Clear device session pointer.*/
+	memset(sess->sess_private_data, 0, session_priv_data_sz);
+
+	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->asym_session_configure, NULL);
 
-	rte_cryptodev_trace_asym_session_create(mp, sess);
+	if (sess->sess_private_data[0] == 0) {
+		ret = dev->dev_ops->asym_session_configure(dev, xforms, sess);
+		if (ret < 0) {
+			CDEV_LOG_ERR(
+				"dev_id %d failed to configure session details",
+				dev_id);
+			return NULL;
+		}
+	}
+
+	rte_cryptodev_trace_asym_session_create(dev_id, xforms, mp, sess);
 	return sess;
 }
 
@@ -1959,30 +2011,6 @@ rte_cryptodev_sym_session_clear(uint8_t dev_id,
 	return 0;
 }
 
-int
-rte_cryptodev_asym_session_clear(uint8_t dev_id,
-		struct rte_cryptodev_asym_session *sess)
-{
-	struct rte_cryptodev *dev;
-
-	if (!rte_cryptodev_is_valid_dev(dev_id)) {
-		CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
-		return -EINVAL;
-	}
-
-	dev = rte_cryptodev_pmd_get_dev(dev_id);
-
-	if (dev == NULL || sess == NULL)
-		return -EINVAL;
-
-	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->asym_session_clear, -ENOTSUP);
-
-	dev->dev_ops->asym_session_clear(dev, sess);
-
-	rte_cryptodev_trace_sym_session_clear(dev_id, sess);
-	return 0;
-}
-
 int
 rte_cryptodev_sym_session_free(struct rte_cryptodev_sym_session *sess)
 {
@@ -2007,27 +2035,31 @@ rte_cryptodev_sym_session_free(struct rte_cryptodev_sym_session *sess)
 }
 
 int
-rte_cryptodev_asym_session_free(struct rte_cryptodev_asym_session *sess)
+rte_cryptodev_asym_session_free(uint8_t dev_id,
+		struct rte_cryptodev_asym_session *sess)
 {
-	uint8_t i;
-	void *sess_priv;
 	struct rte_mempool *sess_mp;
+	struct rte_cryptodev *dev;
 
-	if (sess == NULL)
+	if (!rte_cryptodev_is_valid_dev(dev_id)) {
+		CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
 		return -EINVAL;
-
-	/* Check that all device private data has been freed */
-	for (i = 0; i < nb_drivers; i++) {
-		sess_priv = get_asym_session_private_data(sess, i);
-		if (sess_priv != NULL)
-			return -EBUSY;
 	}
 
+	dev = rte_cryptodev_pmd_get_dev(dev_id);
+
+	if (dev == NULL || sess == NULL)
+		return -EINVAL;
+
+	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->asym_session_clear, -ENOTSUP);
+
+	dev->dev_ops->asym_session_clear(dev, sess);
+
 	/* Return session to mempool */
 	sess_mp = rte_mempool_from_obj(sess);
 	rte_mempool_put(sess_mp, sess);
 
-	rte_cryptodev_trace_asym_session_free(sess);
+	rte_cryptodev_trace_asym_session_free(dev_id, sess);
 	return 0;
 }
 
@@ -2061,12 +2093,7 @@ rte_cryptodev_sym_get_existing_header_session_size(
 unsigned int
 rte_cryptodev_asym_get_header_session_size(void)
 {
-	/*
-	 * Header contains pointers to the private data
-	 * of all registered drivers, and a flag which
-	 * indicates presence of private data
-	 */
-	return ((sizeof(void *) * nb_drivers) + sizeof(uint8_t));
+	return sizeof(struct rte_cryptodev_asym_session);
 }
 
 unsigned int
@@ -2092,7 +2119,6 @@ unsigned int
 rte_cryptodev_asym_get_private_session_size(uint8_t dev_id)
 {
 	struct rte_cryptodev *dev;
-	unsigned int header_size = sizeof(void *) * nb_drivers;
 	unsigned int priv_sess_size;
 
 	if (!rte_cryptodev_is_valid_dev(dev_id))
@@ -2104,11 +2130,8 @@ rte_cryptodev_asym_get_private_session_size(uint8_t dev_id)
 		return 0;
 
 	priv_sess_size = (*dev->dev_ops->asym_session_get_size)(dev);
-	if (priv_sess_size < header_size)
-		return header_size;
 
 	return priv_sess_size;
-
 }
 
 int
diff --git a/lib/cryptodev/rte_cryptodev.h b/lib/cryptodev/rte_cryptodev.h
index 59ea5a54df..a0ac81eaa0 100644
--- a/lib/cryptodev/rte_cryptodev.h
+++ b/lib/cryptodev/rte_cryptodev.h
@@ -919,9 +919,13 @@ struct rte_cryptodev_sym_session {
 };
 
 /** Cryptodev asymmetric crypto session */
-struct rte_cryptodev_asym_session {
-	__extension__ void *sess_private_data[0];
-	/**< Private asymmetric session material */
+RTE_STD_C11 struct rte_cryptodev_asym_session {
+	uint8_t driver_id;
+	/**< Session driver ID. */
+	uint16_t max_priv_data_sz;
+	/**< Size of private data used when creating mempool */
+	uint8_t padding[5];
+	uint8_t sess_private_data[0];
 };
 
 /**
@@ -956,6 +960,29 @@ rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
 	uint32_t elt_size, uint32_t cache_size, uint16_t priv_size,
 	int socket_id);
 
+/**
+ * Create an asymmetric session mempool.
+ *
+ * @param name
+ *   The unique mempool name.
+ * @param nb_elts
+ *   The number of elements in the mempool.
+ * @param cache_size
+ *   The number of per-lcore cache elements
+ * @param socket_id
+ *   The *socket_id* argument is the socket identifier in the case of
+ *   NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA
+ *   constraint for the reserved zone.
+ *
+ * @return
+ *  - On success return mempool
+ *  - On failure returns NULL
+ */
+__rte_experimental
+struct rte_mempool *
+rte_cryptodev_asym_session_pool_create(const char *name, uint32_t nb_elts,
+	uint32_t cache_size, int socket_id);
+
 /**
  * Create symmetric crypto session header (generic with no private data)
  *
@@ -971,15 +998,19 @@ rte_cryptodev_sym_session_create(struct rte_mempool *mempool);
 /**
  * Create asymmetric crypto session header (generic with no private data)
  *
- * @param   mempool    mempool to allocate asymmetric session
- *                     objects from
+ * @param   dev_id   ID of device that we want the session to be used on
+ * @param   xforms   Asymmetric crypto transform operations to apply on flow
+ *                   processed with this session
+ * @param   mp       mempool to allocate asymmetric session
+ *                   objects from
  * @return
  *  - On success return pointer to asym-session
  *  - On failure returns NULL
  */
 __rte_experimental
 struct rte_cryptodev_asym_session *
-rte_cryptodev_asym_session_create(struct rte_mempool *mempool);
+rte_cryptodev_asym_session_create(uint8_t dev_id,
+		struct rte_crypto_asym_xform *xforms, struct rte_mempool *mp);
 
 /**
  * Frees symmetric crypto session header, after checking that all
@@ -997,20 +1028,20 @@ int
 rte_cryptodev_sym_session_free(struct rte_cryptodev_sym_session *sess);
 
 /**
- * Frees asymmetric crypto session header, after checking that all
- * the device private data has been freed, returning it
- * to its original mempool.
+ * Clears and frees asymmetric crypto session header and private data,
+ * returning it to its original mempool.
  *
+ * @param   dev_id   ID of device that uses the asymmetric session.
  * @param   sess     Session header to be freed.
  *
  * @return
  *  - 0 if successful.
- *  - -EINVAL if session is NULL.
- *  - -EBUSY if not all device private data has been freed.
+ *  - -EINVAL if device is invalid or session is NULL.
  */
 __rte_experimental
 int
-rte_cryptodev_asym_session_free(struct rte_cryptodev_asym_session *sess);
+rte_cryptodev_asym_session_free(uint8_t dev_id,
+		struct rte_cryptodev_asym_session *sess);
 
 /**
  * Fill out private data for the device id, based on its device type.
@@ -1034,28 +1065,6 @@ rte_cryptodev_sym_session_init(uint8_t dev_id,
 			struct rte_crypto_sym_xform *xforms,
 			struct rte_mempool *mempool);
 
-/**
- * Initialize asymmetric session on a device with specific asymmetric xform
- *
- * @param   dev_id   ID of device that we want the session to be used on
- * @param   sess     Session to be set up on a device
- * @param   xforms   Asymmetric crypto transform operations to apply on flow
- *                   processed with this session
- * @param   mempool  Mempool to be used for internal allocation.
- *
- * @return
- *  - On success, zero.
- *  - -EINVAL if input parameters are invalid.
- *  - -ENOTSUP if crypto device does not support the crypto transform.
- *  - -ENOMEM if the private session could not be allocated.
- */
-__rte_experimental
-int
-rte_cryptodev_asym_session_init(uint8_t dev_id,
-			struct rte_cryptodev_asym_session *sess,
-			struct rte_crypto_asym_xform *xforms,
-			struct rte_mempool *mempool);
-
 /**
  * Frees private data for the device id, based on its device type,
  * returning it to its mempool. It is the application's responsibility
@@ -1074,21 +1083,6 @@ int
 rte_cryptodev_sym_session_clear(uint8_t dev_id,
 			struct rte_cryptodev_sym_session *sess);
 
-/**
- * Frees resources held by asymmetric session during rte_cryptodev_session_init
- *
- * @param   dev_id   ID of device that uses the asymmetric session.
- * @param   sess     Asymmetric session setup on device using
- *					 rte_cryptodev_session_init
- * @return
- *  - 0 if successful.
- *  - -EINVAL if device is invalid or session is NULL.
- */
-__rte_experimental
-int
-rte_cryptodev_asym_session_clear(uint8_t dev_id,
-			struct rte_cryptodev_asym_session *sess);
-
 /**
  * Get the size of the header session, for all registered drivers excluding
  * the user data size.
@@ -1116,7 +1110,7 @@ rte_cryptodev_sym_get_existing_header_session_size(
 		struct rte_cryptodev_sym_session *sess);
 
 /**
- * Get the size of the asymmetric session header, for all registered drivers.
+ * Get the size of the asymmetric session header.
  *
  * @return
  *   Size of the asymmetric header session.
diff --git a/lib/cryptodev/rte_cryptodev_trace.h b/lib/cryptodev/rte_cryptodev_trace.h
index d1f4f069a3..f4e1c870df 100644
--- a/lib/cryptodev/rte_cryptodev_trace.h
+++ b/lib/cryptodev/rte_cryptodev_trace.h
@@ -83,10 +83,22 @@ RTE_TRACE_POINT(
 	rte_trace_point_emit_u16(sess->user_data_sz);
 )
 
+RTE_TRACE_POINT(
+	rte_cryptodev_trace_asym_session_pool_create,
+	RTE_TRACE_POINT_ARGS(const char *name, uint32_t nb_elts,
+		uint32_t cache_size, void *mempool),
+	rte_trace_point_emit_string(name);
+	rte_trace_point_emit_u32(nb_elts);
+	rte_trace_point_emit_u32(cache_size);
+	rte_trace_point_emit_ptr(mempool);
+)
+
 RTE_TRACE_POINT(
 	rte_cryptodev_trace_asym_session_create,
-	RTE_TRACE_POINT_ARGS(void *mempool,
-		struct rte_cryptodev_asym_session *sess),
+	RTE_TRACE_POINT_ARGS(uint8_t dev_id, void *xforms,
+		void *mempool, struct rte_cryptodev_asym_session *sess),
+	rte_trace_point_emit_u8(dev_id);
+	rte_trace_point_emit_ptr(xforms);
 	rte_trace_point_emit_ptr(mempool);
 	rte_trace_point_emit_ptr(sess);
 )
@@ -99,7 +111,9 @@ RTE_TRACE_POINT(
 
 RTE_TRACE_POINT(
 	rte_cryptodev_trace_asym_session_free,
-	RTE_TRACE_POINT_ARGS(struct rte_cryptodev_asym_session *sess),
+	RTE_TRACE_POINT_ARGS(uint8_t dev_id,
+		struct rte_cryptodev_asym_session *sess),
+	rte_trace_point_emit_u8(dev_id);
 	rte_trace_point_emit_ptr(sess);
 )
 
@@ -117,17 +131,6 @@ RTE_TRACE_POINT(
 	rte_trace_point_emit_ptr(mempool);
 )
 
-RTE_TRACE_POINT(
-	rte_cryptodev_trace_asym_session_init,
-	RTE_TRACE_POINT_ARGS(uint8_t dev_id,
-		struct rte_cryptodev_asym_session *sess, void *xforms,
-		void *mempool),
-	rte_trace_point_emit_u8(dev_id);
-	rte_trace_point_emit_ptr(sess);
-	rte_trace_point_emit_ptr(xforms);
-	rte_trace_point_emit_ptr(mempool);
-)
-
 RTE_TRACE_POINT(
 	rte_cryptodev_trace_sym_session_clear,
 	RTE_TRACE_POINT_ARGS(uint8_t dev_id, void *sess),
@@ -135,13 +138,6 @@ RTE_TRACE_POINT(
 	rte_trace_point_emit_ptr(sess);
 )
 
-RTE_TRACE_POINT(
-	rte_cryptodev_trace_asym_session_clear,
-	RTE_TRACE_POINT_ARGS(uint8_t dev_id, void *sess),
-	rte_trace_point_emit_u8(dev_id);
-	rte_trace_point_emit_ptr(sess);
-)
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/cryptodev/version.map b/lib/cryptodev/version.map
index c50745fa8c..44d1aff0e2 100644
--- a/lib/cryptodev/version.map
+++ b/lib/cryptodev/version.map
@@ -55,10 +55,8 @@ EXPERIMENTAL {
 	rte_cryptodev_asym_get_header_session_size;
 	rte_cryptodev_asym_get_private_session_size;
 	rte_cryptodev_asym_get_xform_enum;
-	rte_cryptodev_asym_session_clear;
 	rte_cryptodev_asym_session_create;
 	rte_cryptodev_asym_session_free;
-	rte_cryptodev_asym_session_init;
 	rte_cryptodev_asym_xform_capability_check_modlen;
 	rte_cryptodev_asym_xform_capability_check_optype;
 	rte_cryptodev_sym_cpu_crypto_process;
@@ -81,9 +79,7 @@ EXPERIMENTAL {
 	__rte_cryptodev_trace_sym_session_free;
 	__rte_cryptodev_trace_asym_session_free;
 	__rte_cryptodev_trace_sym_session_init;
-	__rte_cryptodev_trace_asym_session_init;
 	__rte_cryptodev_trace_sym_session_clear;
-	__rte_cryptodev_trace_asym_session_clear;
 	__rte_cryptodev_trace_dequeue_burst;
 	__rte_cryptodev_trace_enqueue_burst;
 
@@ -104,6 +100,9 @@ EXPERIMENTAL {
 	rte_cryptodev_remove_deq_callback;
 	rte_cryptodev_remove_enq_callback;
 
+	# added 22.03
+	rte_cryptodev_asym_session_pool_create;
+	__rte_cryptodev_trace_asym_session_pool_create;
 };
 
 INTERNAL {
-- 
2.25.1


^ permalink raw reply	[flat|nested] 31+ messages in thread

* [PATCH v4 3/5] crypto: hide asym session structure
  2022-02-09 15:38 [PATCH v4 0/5] crypto: improve asym session usage Ciara Power
  2022-02-09 15:38 ` [PATCH v4 1/5] doc: replace asym crypto code with literal includes Ciara Power
  2022-02-09 15:38 ` [PATCH v4 2/5] crypto: use single buffer for asymmetric session Ciara Power
@ 2022-02-09 15:38 ` Ciara Power
  2022-02-09 15:38 ` [PATCH v4 4/5] crypto: add asym session user data API Ciara Power
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 31+ messages in thread
From: Ciara Power @ 2022-02-09 15:38 UTC (permalink / raw)
  To: dev; +Cc: roy.fan.zhang, gakhil, anoobj, mdr, Ciara Power, Declan Doherty

The rte_cryptodev_asym_session structure is now moved to an internal
header. This will no longer be used directly by apps,
private session data can be accessed via get API.

Signed-off-by: Ciara Power <ciara.power@intel.com>
Acked-by: Fan Zhang <roy.fan.zhang@intel.com>

---
v4:
  - Initialised session variables as NULL.
  - Removed docs code additions, these are included due to patch 1
    changing sample doc to use literal includes.
v3:
  - Removed the incorrect use of void * for asym session in drivers,
    these are internal and can use the struct directly as before.
  - Fixed other internal functions and comments that were incorrectly
    changed to use void *sess.
  - Added documentation.
---
 app/test-crypto-perf/cperf_ops.c        |  2 +-
 app/test/test_cryptodev_asym.c          | 34 ++++++++++++-------------
 doc/guides/prog_guide/cryptodev_lib.rst |  4 +++
 doc/guides/rel_notes/release_22_03.rst  |  2 ++
 lib/cryptodev/cryptodev_pmd.h           | 13 ++++++++++
 lib/cryptodev/rte_cryptodev.c           |  5 ++--
 lib/cryptodev/rte_cryptodev.h           | 15 ++---------
 lib/cryptodev/rte_cryptodev_trace.h     |  5 ++--
 8 files changed, 43 insertions(+), 37 deletions(-)

diff --git a/app/test-crypto-perf/cperf_ops.c b/app/test-crypto-perf/cperf_ops.c
index b125c699de..b8f590b397 100644
--- a/app/test-crypto-perf/cperf_ops.c
+++ b/app/test-crypto-perf/cperf_ops.c
@@ -21,7 +21,7 @@ cperf_set_ops_asym(struct rte_crypto_op **ops,
 		   uint64_t *tsc_start __rte_unused)
 {
 	uint16_t i;
-	struct rte_cryptodev_asym_session *asym_sess = (void *)sess;
+	void *asym_sess = (void *)sess;
 
 	for (i = 0; i < nb_ops; i++) {
 		struct rte_crypto_asym_op *asym_op = ops[i]->asym;
diff --git a/app/test/test_cryptodev_asym.c b/app/test/test_cryptodev_asym.c
index 3e27d93380..fff5c0d59a 100644
--- a/app/test/test_cryptodev_asym.c
+++ b/app/test/test_cryptodev_asym.c
@@ -46,7 +46,7 @@ struct crypto_testsuite_params_asym {
 };
 
 struct crypto_unittest_params {
-	struct rte_cryptodev_asym_session *sess;
+	void *sess;
 	struct rte_crypto_op *op;
 };
 
@@ -67,7 +67,7 @@ static uint32_t test_index;
 static struct crypto_testsuite_params_asym testsuite_params = { NULL };
 
 static int
-queue_ops_rsa_sign_verify(struct rte_cryptodev_asym_session *sess)
+queue_ops_rsa_sign_verify(void *sess)
 {
 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
 	struct rte_mempool *op_mpool = ts_params->op_mpool;
@@ -158,7 +158,7 @@ queue_ops_rsa_sign_verify(struct rte_cryptodev_asym_session *sess)
 }
 
 static int
-queue_ops_rsa_enc_dec(struct rte_cryptodev_asym_session *sess)
+queue_ops_rsa_enc_dec(void *sess)
 {
 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
 	struct rte_mempool *op_mpool = ts_params->op_mpool;
@@ -310,7 +310,7 @@ test_cryptodev_asym_op(struct crypto_testsuite_params_asym *ts_params,
 	struct rte_crypto_op *op = NULL;
 	struct rte_crypto_op *result_op = NULL;
 	struct rte_crypto_asym_xform xform_tc;
-	struct rte_cryptodev_asym_session *sess = NULL;
+	void *sess = NULL;
 	struct rte_cryptodev_asym_capability_idx cap_idx;
 	const struct rte_cryptodev_asymmetric_xform_capability *capability;
 	uint8_t dev_id = ts_params->valid_devs[0];
@@ -644,7 +644,7 @@ test_rsa_sign_verify(void)
 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
 	uint8_t dev_id = ts_params->valid_devs[0];
-	struct rte_cryptodev_asym_session *sess;
+	void *sess = NULL;
 	struct rte_cryptodev_info dev_info;
 	int status = TEST_SUCCESS;
 
@@ -684,7 +684,7 @@ test_rsa_enc_dec(void)
 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
 	uint8_t dev_id = ts_params->valid_devs[0];
-	struct rte_cryptodev_asym_session *sess;
+	void *sess = NULL;
 	struct rte_cryptodev_info dev_info;
 	int status = TEST_SUCCESS;
 
@@ -724,7 +724,7 @@ test_rsa_sign_verify_crt(void)
 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
 	uint8_t dev_id = ts_params->valid_devs[0];
-	struct rte_cryptodev_asym_session *sess;
+	void *sess = NULL;
 	struct rte_cryptodev_info dev_info;
 	int status = TEST_SUCCESS;
 
@@ -764,7 +764,7 @@ test_rsa_enc_dec_crt(void)
 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
 	uint8_t dev_id = ts_params->valid_devs[0];
-	struct rte_cryptodev_asym_session *sess;
+	void *sess = NULL;
 	struct rte_cryptodev_info dev_info;
 	int status = TEST_SUCCESS;
 
@@ -1046,7 +1046,7 @@ test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
 	uint8_t dev_id = ts_params->valid_devs[0];
 	struct rte_crypto_asym_op *asym_op = NULL;
 	struct rte_crypto_op *op = NULL, *result_op = NULL;
-	struct rte_cryptodev_asym_session *sess = NULL;
+	void *sess = NULL;
 	int status = TEST_SUCCESS;
 	uint8_t output[TEST_DH_MOD_LEN];
 	struct rte_crypto_asym_xform xform = *xfrm;
@@ -1129,7 +1129,7 @@ test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
 	uint8_t dev_id = ts_params->valid_devs[0];
 	struct rte_crypto_asym_op *asym_op = NULL;
 	struct rte_crypto_op *op = NULL, *result_op = NULL;
-	struct rte_cryptodev_asym_session *sess = NULL;
+	void *sess = NULL;
 	int status = TEST_SUCCESS;
 	uint8_t output[TEST_DH_MOD_LEN];
 	struct rte_crypto_asym_xform xform = *xfrm;
@@ -1210,7 +1210,7 @@ test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
 	uint8_t dev_id = ts_params->valid_devs[0];
 	struct rte_crypto_asym_op *asym_op = NULL;
 	struct rte_crypto_op *op = NULL, *result_op = NULL;
-	struct rte_cryptodev_asym_session *sess = NULL;
+	void *sess = NULL;
 	int status = TEST_SUCCESS;
 	uint8_t output[TEST_DH_MOD_LEN];
 	struct rte_crypto_asym_xform xform = *xfrm;
@@ -1299,7 +1299,7 @@ test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
 	uint8_t dev_id = ts_params->valid_devs[0];
 	struct rte_crypto_asym_op *asym_op = NULL;
 	struct rte_crypto_op *op = NULL, *result_op = NULL;
-	struct rte_cryptodev_asym_session *sess = NULL;
+	void *sess = NULL;
 	int status = TEST_SUCCESS;
 	uint8_t out_pub_key[TEST_DH_MOD_LEN];
 	uint8_t out_prv_key[TEST_DH_MOD_LEN];
@@ -1386,7 +1386,7 @@ test_mod_inv(void)
 	uint8_t dev_id = ts_params->valid_devs[0];
 	struct rte_crypto_asym_op *asym_op = NULL;
 	struct rte_crypto_op *op = NULL, *result_op = NULL;
-	struct rte_cryptodev_asym_session *sess = NULL;
+	void *sess = NULL;
 	int status = TEST_SUCCESS;
 	struct rte_cryptodev_asym_capability_idx cap_idx;
 	const struct rte_cryptodev_asymmetric_xform_capability *capability;
@@ -1499,7 +1499,7 @@ test_mod_exp(void)
 	uint8_t dev_id = ts_params->valid_devs[0];
 	struct rte_crypto_asym_op *asym_op = NULL;
 	struct rte_crypto_op *op = NULL, *result_op = NULL;
-	struct rte_cryptodev_asym_session *sess = NULL;
+	void *sess = NULL;
 	int status = TEST_SUCCESS;
 	struct rte_cryptodev_asym_capability_idx cap_idx;
 	const struct rte_cryptodev_asymmetric_xform_capability *capability;
@@ -1648,7 +1648,7 @@ test_dsa_sign(void)
 	uint8_t dev_id = ts_params->valid_devs[0];
 	struct rte_crypto_asym_op *asym_op = NULL;
 	struct rte_crypto_op *op = NULL, *result_op = NULL;
-	struct rte_cryptodev_asym_session *sess = NULL;
+	void *sess = NULL;
 	int status = TEST_SUCCESS;
 	uint8_t r[TEST_DH_MOD_LEN];
 	uint8_t s[TEST_DH_MOD_LEN];
@@ -1779,7 +1779,7 @@ test_ecdsa_sign_verify(enum curve curve_id)
 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
 	struct rte_mempool *op_mpool = ts_params->op_mpool;
 	struct crypto_testsuite_ecdsa_params input_params;
-	struct rte_cryptodev_asym_session *sess = NULL;
+	void *sess = NULL;
 	uint8_t dev_id = ts_params->valid_devs[0];
 	struct rte_crypto_op *result_op = NULL;
 	uint8_t output_buf_r[TEST_DATA_SIZE];
@@ -1981,7 +1981,7 @@ test_ecpm(enum curve curve_id)
 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
 	struct rte_mempool *op_mpool = ts_params->op_mpool;
 	struct crypto_testsuite_ecpm_params input_params;
-	struct rte_cryptodev_asym_session *sess = NULL;
+	void *sess = NULL;
 	uint8_t dev_id = ts_params->valid_devs[0];
 	struct rte_crypto_op *result_op = NULL;
 	uint8_t output_buf_x[TEST_DATA_SIZE];
diff --git a/doc/guides/prog_guide/cryptodev_lib.rst b/doc/guides/prog_guide/cryptodev_lib.rst
index b4dbd384bf..2607a9a7d7 100644
--- a/doc/guides/prog_guide/cryptodev_lib.rst
+++ b/doc/guides/prog_guide/cryptodev_lib.rst
@@ -1155,6 +1155,10 @@ Generate crypto op, create and attach a session, then process packets.
    :end-before: >8 End of create op, create session, and process packets section.
    :dedent: 1
 
+.. note::
+   The ``rte_cryptodev_asym_session`` struct is hidden from the application.
+   The ``sess`` pointer used above is a void pointer.
+
 
 Asymmetric Crypto Device API
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
diff --git a/doc/guides/rel_notes/release_22_03.rst b/doc/guides/rel_notes/release_22_03.rst
index ea4c5309a0..459b15bdde 100644
--- a/doc/guides/rel_notes/release_22_03.rst
+++ b/doc/guides/rel_notes/release_22_03.rst
@@ -116,6 +116,8 @@ API Changes
   mempool object. An API ``rte_cryptodev_asym_session_pool_create`` was added
   to create a mempool with element size big enough to hold the generic asymmetric
   session header and max size for a device private session data.
+  The session structure was moved to ``cryptodev_pmd.h``,
+  hiding it from applications.
   The API ``rte_cryptodev_asym_session_init`` was removed as the initialization
   is now moved to ``rte_cryptodev_asym_session_create``.
 
diff --git a/lib/cryptodev/cryptodev_pmd.h b/lib/cryptodev/cryptodev_pmd.h
index aeaccfa611..a3e2dd1d27 100644
--- a/lib/cryptodev/cryptodev_pmd.h
+++ b/lib/cryptodev/cryptodev_pmd.h
@@ -625,6 +625,19 @@ set_sym_session_private_data(struct rte_cryptodev_sym_session *sess,
 	sess->sess_data[driver_id].data = private_data;
 }
 
+/**
+ * @internal
+ * Cryptodev asymmetric crypto session.
+ */
+RTE_STD_C11 struct rte_cryptodev_asym_session {
+	uint8_t driver_id;
+	/**< Session driver ID. */
+	uint16_t max_priv_data_sz;
+	/**< Size of private data used when creating mempool */
+	uint8_t padding[5];
+	uint8_t sess_private_data[0];
+};
+
 static inline void *
 get_asym_session_private_data(struct rte_cryptodev_asym_session *sess)
 {
diff --git a/lib/cryptodev/rte_cryptodev.c b/lib/cryptodev/rte_cryptodev.c
index d4cdc56912..13236b88dc 100644
--- a/lib/cryptodev/rte_cryptodev.c
+++ b/lib/cryptodev/rte_cryptodev.c
@@ -1908,7 +1908,7 @@ rte_cryptodev_sym_session_create(struct rte_mempool *mp)
 	return sess;
 }
 
-struct rte_cryptodev_asym_session *
+void *
 rte_cryptodev_asym_session_create(uint8_t dev_id,
 		struct rte_crypto_asym_xform *xforms, struct rte_mempool *mp)
 {
@@ -2035,8 +2035,7 @@ rte_cryptodev_sym_session_free(struct rte_cryptodev_sym_session *sess)
 }
 
 int
-rte_cryptodev_asym_session_free(uint8_t dev_id,
-		struct rte_cryptodev_asym_session *sess)
+rte_cryptodev_asym_session_free(uint8_t dev_id, void *sess)
 {
 	struct rte_mempool *sess_mp;
 	struct rte_cryptodev *dev;
diff --git a/lib/cryptodev/rte_cryptodev.h b/lib/cryptodev/rte_cryptodev.h
index a0ac81eaa0..79c514dd59 100644
--- a/lib/cryptodev/rte_cryptodev.h
+++ b/lib/cryptodev/rte_cryptodev.h
@@ -918,16 +918,6 @@ struct rte_cryptodev_sym_session {
 	/**< Driver specific session material, variable size */
 };
 
-/** Cryptodev asymmetric crypto session */
-RTE_STD_C11 struct rte_cryptodev_asym_session {
-	uint8_t driver_id;
-	/**< Session driver ID. */
-	uint16_t max_priv_data_sz;
-	/**< Size of private data used when creating mempool */
-	uint8_t padding[5];
-	uint8_t sess_private_data[0];
-};
-
 /**
  * Create a symmetric session mempool.
  *
@@ -1008,7 +998,7 @@ rte_cryptodev_sym_session_create(struct rte_mempool *mempool);
  *  - On failure returns NULL
  */
 __rte_experimental
-struct rte_cryptodev_asym_session *
+void *
 rte_cryptodev_asym_session_create(uint8_t dev_id,
 		struct rte_crypto_asym_xform *xforms, struct rte_mempool *mp);
 
@@ -1040,8 +1030,7 @@ rte_cryptodev_sym_session_free(struct rte_cryptodev_sym_session *sess);
  */
 __rte_experimental
 int
-rte_cryptodev_asym_session_free(uint8_t dev_id,
-		struct rte_cryptodev_asym_session *sess);
+rte_cryptodev_asym_session_free(uint8_t dev_id, void *sess);
 
 /**
  * Fill out private data for the device id, based on its device type.
diff --git a/lib/cryptodev/rte_cryptodev_trace.h b/lib/cryptodev/rte_cryptodev_trace.h
index f4e1c870df..e0f4cba0e5 100644
--- a/lib/cryptodev/rte_cryptodev_trace.h
+++ b/lib/cryptodev/rte_cryptodev_trace.h
@@ -96,7 +96,7 @@ RTE_TRACE_POINT(
 RTE_TRACE_POINT(
 	rte_cryptodev_trace_asym_session_create,
 	RTE_TRACE_POINT_ARGS(uint8_t dev_id, void *xforms,
-		void *mempool, struct rte_cryptodev_asym_session *sess),
+		void *mempool, void *sess),
 	rte_trace_point_emit_u8(dev_id);
 	rte_trace_point_emit_ptr(xforms);
 	rte_trace_point_emit_ptr(mempool);
@@ -111,8 +111,7 @@ RTE_TRACE_POINT(
 
 RTE_TRACE_POINT(
 	rte_cryptodev_trace_asym_session_free,
-	RTE_TRACE_POINT_ARGS(uint8_t dev_id,
-		struct rte_cryptodev_asym_session *sess),
+	RTE_TRACE_POINT_ARGS(uint8_t dev_id, void *sess),
 	rte_trace_point_emit_u8(dev_id);
 	rte_trace_point_emit_ptr(sess);
 )
-- 
2.25.1


^ permalink raw reply	[flat|nested] 31+ messages in thread

* [PATCH v4 4/5] crypto: add asym session user data API
  2022-02-09 15:38 [PATCH v4 0/5] crypto: improve asym session usage Ciara Power
                   ` (2 preceding siblings ...)
  2022-02-09 15:38 ` [PATCH v4 3/5] crypto: hide asym session structure Ciara Power
@ 2022-02-09 15:38 ` Ciara Power
  2022-02-09 20:09   ` [EXT] " Akhil Goyal
  2022-02-09 15:38 ` [PATCH v4 5/5] crypto: modify return value for asym session create Ciara Power
                   ` (3 subsequent siblings)
  7 siblings, 1 reply; 31+ messages in thread
From: Ciara Power @ 2022-02-09 15:38 UTC (permalink / raw)
  To: dev; +Cc: roy.fan.zhang, gakhil, anoobj, mdr, Ciara Power, Declan Doherty

A user data field is added to the asymmetric session structure.
Relevant API added to get/set the field.

Signed-off-by: Ciara Power <ciara.power@intel.com>
Acked-by: Fan Zhang <roy.fan.zhang@intel.com>
Acked-by: Anoob Joseph <anoobj@marvell.com>

---
v4:
  - Reworded release notes.
  - Added possible error return values in function comment.
  - Removed docs code additions, these are included due to patch 1
    changing sample doc to use literal includes.
v3:
  - Corrected formatting of struct comments.
  - Added setting user data size in pool creation.
  - Added documentation.
v2: Corrected order of version map entries.
---
 app/test/test_cryptodev_asym.c          |  2 +-
 doc/guides/prog_guide/cryptodev_lib.rst | 19 ++++++++++++
 doc/guides/rel_notes/release_22_03.rst  |  6 +++-
 lib/cryptodev/cryptodev_pmd.h           |  4 ++-
 lib/cryptodev/rte_cryptodev.c           | 40 ++++++++++++++++++++++---
 lib/cryptodev/rte_cryptodev.h           | 35 +++++++++++++++++++++-
 lib/cryptodev/rte_cryptodev_trace.h     |  3 +-
 lib/cryptodev/version.map               |  2 ++
 8 files changed, 102 insertions(+), 9 deletions(-)

diff --git a/app/test/test_cryptodev_asym.c b/app/test/test_cryptodev_asym.c
index fff5c0d59a..f9691fe281 100644
--- a/app/test/test_cryptodev_asym.c
+++ b/app/test/test_cryptodev_asym.c
@@ -894,7 +894,7 @@ testsuite_setup(void)
 	}
 
 	ts_params->session_mpool = rte_cryptodev_asym_session_pool_create(
-			"test_asym_sess_mp", TEST_NUM_SESSIONS * 2, 0,
+			"test_asym_sess_mp", TEST_NUM_SESSIONS * 2, 0, 0,
 			SOCKET_ID_ANY);
 
 	TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
diff --git a/doc/guides/prog_guide/cryptodev_lib.rst b/doc/guides/prog_guide/cryptodev_lib.rst
index 2607a9a7d7..ba4c592b84 100644
--- a/doc/guides/prog_guide/cryptodev_lib.rst
+++ b/doc/guides/prog_guide/cryptodev_lib.rst
@@ -1110,6 +1110,25 @@ They operate on data buffer of type ``rte_crypto_param``.
 
 See *DPDK API Reference* for details on each rte_crypto_xxx_op_param struct
 
+Private user data
+~~~~~~~~~~~~~~~~~
+
+Similar to symmetric above, asymmetric also has a set and get API that provides a
+mechanism for an application to store and retrieve the private user data information
+stored along with the crypto session.
+
+.. code-block:: c
+
+	int rte_cryptodev_asym_session_set_user_data(void *sess,
+		void *data, uint16_t size);
+
+	void * rte_cryptodev_asym_session_get_user_data(void *sess);
+
+Please note the ``size`` passed to set API cannot be bigger than the predefined
+``user_data_sz`` when creating the session mempool, otherwise the function will
+return an error. Also when ``user_data_sz`` was defined as ``0`` when
+creating the session mempool, the get API will always return ``NULL``.
+
 Asymmetric crypto Sample code
 -----------------------------
 
diff --git a/doc/guides/rel_notes/release_22_03.rst b/doc/guides/rel_notes/release_22_03.rst
index 459b15bdde..a930cbbad6 100644
--- a/doc/guides/rel_notes/release_22_03.rst
+++ b/doc/guides/rel_notes/release_22_03.rst
@@ -78,6 +78,10 @@ New Features
 
   The new API ``rte_event_eth_rx_adapter_event_port_get()`` was added.
 
+* **Added an API for private user data in Asymmetric crypto session.**
+
+  An API was added for getting/setting an Asymmetric crypto session's user data.
+
 
 Removed Items
 -------------
@@ -115,7 +119,7 @@ API Changes
 * cryptodev: The asymmetric session handling was modified to use a single
   mempool object. An API ``rte_cryptodev_asym_session_pool_create`` was added
   to create a mempool with element size big enough to hold the generic asymmetric
-  session header and max size for a device private session data.
+  session header, max size for a device private session data, and user data size.
   The session structure was moved to ``cryptodev_pmd.h``,
   hiding it from applications.
   The API ``rte_cryptodev_asym_session_init`` was removed as the initialization
diff --git a/lib/cryptodev/cryptodev_pmd.h b/lib/cryptodev/cryptodev_pmd.h
index a3e2dd1d27..930430c63b 100644
--- a/lib/cryptodev/cryptodev_pmd.h
+++ b/lib/cryptodev/cryptodev_pmd.h
@@ -634,7 +634,9 @@ RTE_STD_C11 struct rte_cryptodev_asym_session {
 	/**< Session driver ID. */
 	uint16_t max_priv_data_sz;
 	/**< Size of private data used when creating mempool */
-	uint8_t padding[5];
+	uint16_t user_data_sz;
+	/**< Session user data will be placed after sess_data */
+	uint8_t padding[3];
 	uint8_t sess_private_data[0];
 };
 
diff --git a/lib/cryptodev/rte_cryptodev.c b/lib/cryptodev/rte_cryptodev.c
index 13236b88dc..916dbb6709 100644
--- a/lib/cryptodev/rte_cryptodev.c
+++ b/lib/cryptodev/rte_cryptodev.c
@@ -210,6 +210,8 @@ struct rte_cryptodev_sym_session_pool_private_data {
 struct rte_cryptodev_asym_session_pool_private_data {
 	uint16_t max_priv_session_sz;
 	/**< Size of private session data used when creating mempool */
+	uint16_t user_data_sz;
+	/**< Session user data will be placed after sess_private_data */
 };
 
 int
@@ -1803,7 +1805,7 @@ rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
 
 struct rte_mempool *
 rte_cryptodev_asym_session_pool_create(const char *name, uint32_t nb_elts,
-	uint32_t cache_size, int socket_id)
+	uint32_t cache_size, uint16_t user_data_size, int socket_id)
 {
 	struct rte_mempool *mp;
 	struct rte_cryptodev_asym_session_pool_private_data *pool_priv;
@@ -1821,7 +1823,8 @@ rte_cryptodev_asym_session_pool_create(const char *name, uint32_t nb_elts,
 		return NULL;
 	}
 
-	obj_sz = rte_cryptodev_asym_get_header_session_size() + max_priv_sz;
+	obj_sz = rte_cryptodev_asym_get_header_session_size() + max_priv_sz +
+			user_data_size;
 	obj_sz_aligned =  RTE_ALIGN_CEIL(obj_sz, RTE_CACHE_LINE_SIZE);
 
 	mp = rte_mempool_create(name, nb_elts, obj_sz_aligned, cache_size,
@@ -1842,9 +1845,10 @@ rte_cryptodev_asym_session_pool_create(const char *name, uint32_t nb_elts,
 		return NULL;
 	}
 	pool_priv->max_priv_session_sz = max_priv_sz;
+	pool_priv->user_data_sz = user_data_size;
 
 	rte_cryptodev_trace_asym_session_pool_create(name, nb_elts,
-		cache_size, mp);
+		user_data_size, cache_size, mp);
 	return mp;
 }
 
@@ -1959,10 +1963,11 @@ rte_cryptodev_asym_session_create(uint8_t dev_id,
 	}
 
 	sess->driver_id = dev->driver_id;
+	sess->user_data_sz = pool_priv->user_data_sz;
 	sess->max_priv_data_sz = pool_priv->max_priv_session_sz;
 
 	/* Clear device session pointer.*/
-	memset(sess->sess_private_data, 0, session_priv_data_sz);
+	memset(sess->sess_private_data, 0, session_priv_data_sz + sess->user_data_sz);
 
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->asym_session_configure, NULL);
 
@@ -2159,6 +2164,33 @@ rte_cryptodev_sym_session_get_user_data(
 	return (void *)(sess->sess_data + sess->nb_drivers);
 }
 
+int
+rte_cryptodev_asym_session_set_user_data(void *session, void *data, uint16_t size)
+{
+	struct rte_cryptodev_asym_session *sess = session;
+	if (sess == NULL)
+		return -EINVAL;
+
+	if (sess->user_data_sz < size)
+		return -ENOMEM;
+
+	rte_memcpy(sess->sess_private_data +
+			sess->max_priv_data_sz,
+			data, size);
+	return 0;
+}
+
+void *
+rte_cryptodev_asym_session_get_user_data(void *session)
+{
+	struct rte_cryptodev_asym_session *sess = session;
+	if (sess == NULL || sess->user_data_sz == 0)
+		return NULL;
+
+	return (void *)(sess->sess_private_data +
+			sess->max_priv_data_sz);
+}
+
 static inline void
 sym_crypto_fill_status(struct rte_crypto_sym_vec *vec, int32_t errnum)
 {
diff --git a/lib/cryptodev/rte_cryptodev.h b/lib/cryptodev/rte_cryptodev.h
index 79c514dd59..91110b08da 100644
--- a/lib/cryptodev/rte_cryptodev.h
+++ b/lib/cryptodev/rte_cryptodev.h
@@ -959,6 +959,8 @@ rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
  *   The number of elements in the mempool.
  * @param cache_size
  *   The number of per-lcore cache elements
+ * @param user_data_size
+ *   The size of user data to be placed after session private data.
  * @param socket_id
  *   The *socket_id* argument is the socket identifier in the case of
  *   NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA
@@ -971,7 +973,7 @@ rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
 __rte_experimental
 struct rte_mempool *
 rte_cryptodev_asym_session_pool_create(const char *name, uint32_t nb_elts,
-	uint32_t cache_size, int socket_id);
+	uint32_t cache_size, uint16_t user_data_size, int socket_id);
 
 /**
  * Create symmetric crypto session header (generic with no private data)
@@ -1201,6 +1203,37 @@ void *
 rte_cryptodev_sym_session_get_user_data(
 					struct rte_cryptodev_sym_session *sess);
 
+/**
+ * Store user data in an asymmetric session.
+ *
+ * @param	sess		Session pointer allocated by
+ *				*rte_cryptodev_asym_session_create*.
+ * @param	data		Pointer to the user data.
+ * @param	size		Size of the user data.
+ *
+ * @return
+ *  - On success, zero.
+ *  - -EINVAL if the session pointer is invalid.
+ *  - -ENOMEM if the available user data size is smaller than the size parameter.
+ */
+__rte_experimental
+int
+rte_cryptodev_asym_session_set_user_data(void *sess, void *data, uint16_t size);
+
+/**
+ * Get user data stored in an asymmetric session.
+ *
+ * @param	sess		Session pointer allocated by
+ *				*rte_cryptodev_asym_session_create*.
+ *
+ * @return
+ *  - On success return pointer to user data.
+ *  - On failure returns NULL.
+ */
+__rte_experimental
+void *
+rte_cryptodev_asym_session_get_user_data(void *sess);
+
 /**
  * Perform actual crypto processing (encrypt/digest or auth/decrypt)
  * on user provided data.
diff --git a/lib/cryptodev/rte_cryptodev_trace.h b/lib/cryptodev/rte_cryptodev_trace.h
index e0f4cba0e5..7a7f1268d9 100644
--- a/lib/cryptodev/rte_cryptodev_trace.h
+++ b/lib/cryptodev/rte_cryptodev_trace.h
@@ -86,9 +86,10 @@ RTE_TRACE_POINT(
 RTE_TRACE_POINT(
 	rte_cryptodev_trace_asym_session_pool_create,
 	RTE_TRACE_POINT_ARGS(const char *name, uint32_t nb_elts,
-		uint32_t cache_size, void *mempool),
+		uint16_t user_data_size, uint32_t cache_size, void *mempool),
 	rte_trace_point_emit_string(name);
 	rte_trace_point_emit_u32(nb_elts);
+	rte_trace_point_emit_u16(user_data_size);
 	rte_trace_point_emit_u32(cache_size);
 	rte_trace_point_emit_ptr(mempool);
 )
diff --git a/lib/cryptodev/version.map b/lib/cryptodev/version.map
index 44d1aff0e2..c7c5aefceb 100644
--- a/lib/cryptodev/version.map
+++ b/lib/cryptodev/version.map
@@ -101,7 +101,9 @@ EXPERIMENTAL {
 	rte_cryptodev_remove_enq_callback;
 
 	# added 22.03
+	rte_cryptodev_asym_session_get_user_data;
 	rte_cryptodev_asym_session_pool_create;
+	rte_cryptodev_asym_session_set_user_data;
 	__rte_cryptodev_trace_asym_session_pool_create;
 };
 
-- 
2.25.1


^ permalink raw reply	[flat|nested] 31+ messages in thread

* [PATCH v4 5/5] crypto: modify return value for asym session create
  2022-02-09 15:38 [PATCH v4 0/5] crypto: improve asym session usage Ciara Power
                   ` (3 preceding siblings ...)
  2022-02-09 15:38 ` [PATCH v4 4/5] crypto: add asym session user data API Ciara Power
@ 2022-02-09 15:38 ` Ciara Power
  2022-02-09 20:19   ` [EXT] " Akhil Goyal
  2022-02-10 14:01 ` [PATCH v5 0/5] crypto: improve asym session usage Ciara Power
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 31+ messages in thread
From: Ciara Power @ 2022-02-09 15:38 UTC (permalink / raw)
  To: dev; +Cc: roy.fan.zhang, gakhil, anoobj, mdr, Ciara Power, Declan Doherty

Rather than the asym session create function returning a session on
success, and a NULL value on error, it is modified to now return int
values - 0 on success or -EINVAL/-ENOTSUP/-ENOMEM on failure.
The session to be used is passed as input.

This adds clarity on the failure of the create function, which enables
treating the -ENOTSUP return as TEST_SKIPPED in test apps.

Signed-off-by: Ciara Power <ciara.power@intel.com>
Acked-by: Fan Zhang <roy.fan.zhang@intel.com>
Acked-by: Anoob Joseph <anoobj@marvell.com>

---
v4:
  - Reordered function parameters.
  - Removed docs code additions, these are included due to patch 1
    changing sample doc to use literal includes.
v3:
  - Fixed variable declarations, putting initialised variable last.
  - Made function comment for return value more generic.
  - Fixed log to include line break.
  - Added documentation.
---
 app/test-crypto-perf/cperf_ops.c       |  12 ++-
 app/test/test_cryptodev_asym.c         | 109 +++++++++++++------------
 doc/guides/rel_notes/release_22_03.rst |   3 +-
 lib/cryptodev/rte_cryptodev.c          |  26 +++---
 lib/cryptodev/rte_cryptodev.h          |  13 ++-
 5 files changed, 88 insertions(+), 75 deletions(-)

diff --git a/app/test-crypto-perf/cperf_ops.c b/app/test-crypto-perf/cperf_ops.c
index b8f590b397..479c40eead 100644
--- a/app/test-crypto-perf/cperf_ops.c
+++ b/app/test-crypto-perf/cperf_ops.c
@@ -734,7 +734,9 @@ cperf_create_session(struct rte_mempool *sess_mp,
 	struct rte_crypto_sym_xform auth_xform;
 	struct rte_crypto_sym_xform aead_xform;
 	struct rte_cryptodev_sym_session *sess = NULL;
+	void *asym_sess = NULL;
 	struct rte_crypto_asym_xform xform = {0};
+	int ret;
 
 	if (options->op_type == CPERF_ASYM_MODEX) {
 		xform.next = NULL;
@@ -744,11 +746,13 @@ cperf_create_session(struct rte_mempool *sess_mp,
 		xform.modex.exponent.data = perf_mod_e;
 		xform.modex.exponent.length = sizeof(perf_mod_e);
 
-		sess = (void *)rte_cryptodev_asym_session_create(dev_id, &xform, sess_mp);
-		if (sess == NULL)
+		ret = rte_cryptodev_asym_session_create(dev_id, &xform,
+				sess_mp, &asym_sess);
+		if (ret < 0) {
+			RTE_LOG(ERR, USER1, "Asym session create failed\n");
 			return NULL;
-
-		return sess;
+		}
+		return asym_sess;
 	}
 #ifdef RTE_LIB_SECURITY
 	/*
diff --git a/app/test/test_cryptodev_asym.c b/app/test/test_cryptodev_asym.c
index f9691fe281..1bddcb013e 100644
--- a/app/test/test_cryptodev_asym.c
+++ b/app/test/test_cryptodev_asym.c
@@ -317,7 +317,7 @@ test_cryptodev_asym_op(struct crypto_testsuite_params_asym *ts_params,
 	uint8_t input[TEST_DATA_SIZE] = {0};
 	uint8_t *result = NULL;
 
-	int status = TEST_SUCCESS;
+	int ret, status = TEST_SUCCESS;
 
 	xform_tc.next = NULL;
 	xform_tc.xform_type = data_tc->modex.xform_type;
@@ -452,14 +452,14 @@ test_cryptodev_asym_op(struct crypto_testsuite_params_asym *ts_params,
 	}
 
 	if (!sessionless) {
-		sess = rte_cryptodev_asym_session_create(dev_id, &xform_tc,
-				ts_params->session_mpool);
-		if (!sess) {
+		ret = rte_cryptodev_asym_session_create(dev_id, &xform_tc,
+				ts_params->session_mpool, &sess);
+		if (ret < 0) {
 			snprintf(test_msg, ASYM_TEST_MSG_LEN,
 					"line %u "
 					"FAILED: %s", __LINE__,
 					"Session creation failed");
-			status = TEST_FAILED;
+			status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 			goto error_exit;
 		}
 
@@ -646,7 +646,7 @@ test_rsa_sign_verify(void)
 	uint8_t dev_id = ts_params->valid_devs[0];
 	void *sess = NULL;
 	struct rte_cryptodev_info dev_info;
-	int status = TEST_SUCCESS;
+	int ret, status = TEST_SUCCESS;
 
 	/* Test case supports op with exponent key only,
 	 * Check in PMD feature flag for RSA exponent key type support.
@@ -659,12 +659,12 @@ test_rsa_sign_verify(void)
 		return TEST_SKIPPED;
 	}
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool);
+	ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool, &sess);
 
-	if (!sess) {
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1, "Session creation failed for "
 			"sign_verify\n");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto error_exit;
 	}
 
@@ -686,7 +686,7 @@ test_rsa_enc_dec(void)
 	uint8_t dev_id = ts_params->valid_devs[0];
 	void *sess = NULL;
 	struct rte_cryptodev_info dev_info;
-	int status = TEST_SUCCESS;
+	int ret, status = TEST_SUCCESS;
 
 	/* Test case supports op with exponent key only,
 	 * Check in PMD feature flag for RSA exponent key type support.
@@ -699,11 +699,11 @@ test_rsa_enc_dec(void)
 		return TEST_SKIPPED;
 	}
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool);
+	ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool, &sess);
 
-	if (!sess) {
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1, "Session creation failed for enc_dec\n");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto error_exit;
 	}
 
@@ -726,7 +726,7 @@ test_rsa_sign_verify_crt(void)
 	uint8_t dev_id = ts_params->valid_devs[0];
 	void *sess = NULL;
 	struct rte_cryptodev_info dev_info;
-	int status = TEST_SUCCESS;
+	int ret, status = TEST_SUCCESS;
 
 	/* Test case supports op with quintuple format key only,
 	 * Check im PMD feature flag for RSA quintuple key type support.
@@ -738,12 +738,12 @@ test_rsa_sign_verify_crt(void)
 		return TEST_SKIPPED;
 	}
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &rsa_xform_crt, sess_mpool);
+	ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform_crt, sess_mpool, &sess);
 
-	if (!sess) {
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1, "Session creation failed for "
 			"sign_verify_crt\n");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto error_exit;
 	}
 
@@ -766,7 +766,7 @@ test_rsa_enc_dec_crt(void)
 	uint8_t dev_id = ts_params->valid_devs[0];
 	void *sess = NULL;
 	struct rte_cryptodev_info dev_info;
-	int status = TEST_SUCCESS;
+	int ret, status = TEST_SUCCESS;
 
 	/* Test case supports op with quintuple format key only,
 	 * Check in PMD feature flag for RSA quintuple key type support.
@@ -778,12 +778,12 @@ test_rsa_enc_dec_crt(void)
 		return TEST_SKIPPED;
 	}
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &rsa_xform_crt, sess_mpool);
+	ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform_crt, sess_mpool, &sess);
 
-	if (!sess) {
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1, "Session creation failed for "
 			"enc_dec_crt\n");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto error_exit;
 	}
 
@@ -1047,7 +1047,7 @@ test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
 	struct rte_crypto_asym_op *asym_op = NULL;
 	struct rte_crypto_op *op = NULL, *result_op = NULL;
 	void *sess = NULL;
-	int status = TEST_SUCCESS;
+	int ret, status = TEST_SUCCESS;
 	uint8_t output[TEST_DH_MOD_LEN];
 	struct rte_crypto_asym_xform xform = *xfrm;
 	uint8_t peer[] = "01234567890123456789012345678901234567890123456789";
@@ -1074,12 +1074,12 @@ test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
 	asym_op->dh.shared_secret.data = output;
 	asym_op->dh.shared_secret.length = sizeof(output);
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
-	if (sess == NULL) {
+	ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
 				"line %u FAILED: %s", __LINE__,
 				"Session creation failed");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto error_exit;
 	}
 
@@ -1130,7 +1130,7 @@ test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
 	struct rte_crypto_asym_op *asym_op = NULL;
 	struct rte_crypto_op *op = NULL, *result_op = NULL;
 	void *sess = NULL;
-	int status = TEST_SUCCESS;
+	int ret, status = TEST_SUCCESS;
 	uint8_t output[TEST_DH_MOD_LEN];
 	struct rte_crypto_asym_xform xform = *xfrm;
 
@@ -1152,12 +1152,12 @@ test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
 	asym_op->dh.priv_key.data = output;
 	asym_op->dh.priv_key.length = sizeof(output);
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
-	if (sess == NULL) {
+	ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
 				"line %u FAILED: %s", __LINE__,
 				"Session creation failed");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto error_exit;
 	}
 
@@ -1211,7 +1211,7 @@ test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
 	struct rte_crypto_asym_op *asym_op = NULL;
 	struct rte_crypto_op *op = NULL, *result_op = NULL;
 	void *sess = NULL;
-	int status = TEST_SUCCESS;
+	int ret, status = TEST_SUCCESS;
 	uint8_t output[TEST_DH_MOD_LEN];
 	struct rte_crypto_asym_xform xform = *xfrm;
 
@@ -1241,12 +1241,12 @@ test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
 					0);
 	asym_op->dh.priv_key = dh_test_params.priv_key;
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
-	if (sess == NULL) {
+	ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
 				"line %u FAILED: %s", __LINE__,
 				"Session creation failed");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto error_exit;
 	}
 
@@ -1300,7 +1300,7 @@ test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
 	struct rte_crypto_asym_op *asym_op = NULL;
 	struct rte_crypto_op *op = NULL, *result_op = NULL;
 	void *sess = NULL;
-	int status = TEST_SUCCESS;
+	int ret, status = TEST_SUCCESS;
 	uint8_t out_pub_key[TEST_DH_MOD_LEN];
 	uint8_t out_prv_key[TEST_DH_MOD_LEN];
 	struct rte_crypto_asym_xform pub_key_xform;
@@ -1330,12 +1330,12 @@ test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
 	asym_op->dh.priv_key.data = out_prv_key;
 	asym_op->dh.priv_key.length = sizeof(out_prv_key);
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
-	if (sess == NULL) {
+	ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
 				"line %u FAILED: %s", __LINE__,
 				"Session creation failed");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto error_exit;
 	}
 
@@ -1419,12 +1419,12 @@ test_mod_inv(void)
 				return TEST_SKIPPED;
 		}
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &modinv_xform, sess_mpool);
-	if (!sess) {
+	ret = rte_cryptodev_asym_session_create(dev_id, &modinv_xform, sess_mpool, &sess);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1, "line %u "
 				"FAILED: %s", __LINE__,
 				"Session creation failed");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto error_exit;
 	}
 
@@ -1543,13 +1543,13 @@ test_mod_exp(void)
 		goto error_exit;
 	}
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &modex_xform, sess_mpool);
-	if (!sess) {
+	ret = rte_cryptodev_asym_session_create(dev_id, &modex_xform, sess_mpool, &sess);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
 				 "line %u "
 				"FAILED: %s", __LINE__,
 				"Session creation failed");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto error_exit;
 	}
 
@@ -1653,13 +1653,14 @@ test_dsa_sign(void)
 	uint8_t r[TEST_DH_MOD_LEN];
 	uint8_t s[TEST_DH_MOD_LEN];
 	uint8_t dgst[] = "35d81554afaad2cf18f3a1770d5fedc4ea5be344";
+	int ret;
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &dsa_xform, sess_mpool);
-	if (sess == NULL) {
+	ret = rte_cryptodev_asym_session_create(dev_id, &dsa_xform, sess_mpool, &sess);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
 				 "line %u FAILED: %s", __LINE__,
 				"Session creation failed");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto error_exit;
 	}
 	/* set up crypto op data structure */
@@ -1788,7 +1789,7 @@ test_ecdsa_sign_verify(enum curve curve_id)
 	struct rte_crypto_asym_op *asym_op;
 	struct rte_cryptodev_info dev_info;
 	struct rte_crypto_op *op = NULL;
-	int status = TEST_SUCCESS, ret;
+	int ret, status = TEST_SUCCESS;
 
 	switch (curve_id) {
 	case SECP192R1:
@@ -1833,12 +1834,12 @@ test_ecdsa_sign_verify(enum curve curve_id)
 	xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDSA;
 	xform.ec.curve_id = input_params.curve;
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
-	if (sess == NULL) {
+	ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
 				"line %u FAILED: %s", __LINE__,
 				"Session creation failed\n");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto exit;
 	}
 
@@ -1990,7 +1991,7 @@ test_ecpm(enum curve curve_id)
 	struct rte_crypto_asym_op *asym_op;
 	struct rte_cryptodev_info dev_info;
 	struct rte_crypto_op *op = NULL;
-	int status = TEST_SUCCESS, ret;
+	int ret, status = TEST_SUCCESS;
 
 	switch (curve_id) {
 	case SECP192R1:
@@ -2035,12 +2036,12 @@ test_ecpm(enum curve curve_id)
 	xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECPM;
 	xform.ec.curve_id = input_params.curve;
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
-	if (sess == NULL) {
+	ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
 				"line %u FAILED: %s", __LINE__,
 				"Session creation failed\n");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto exit;
 	}
 
diff --git a/doc/guides/rel_notes/release_22_03.rst b/doc/guides/rel_notes/release_22_03.rst
index a930cbbad6..640691c3ef 100644
--- a/doc/guides/rel_notes/release_22_03.rst
+++ b/doc/guides/rel_notes/release_22_03.rst
@@ -123,7 +123,8 @@ API Changes
   The session structure was moved to ``cryptodev_pmd.h``,
   hiding it from applications.
   The API ``rte_cryptodev_asym_session_init`` was removed as the initialization
-  is now moved to ``rte_cryptodev_asym_session_create``.
+  is now moved to ``rte_cryptodev_asym_session_create``, which was updated to
+  return an integer value to indicate initialisation errors.
 
 
 ABI Changes
diff --git a/lib/cryptodev/rte_cryptodev.c b/lib/cryptodev/rte_cryptodev.c
index 916dbb6709..727d271fb9 100644
--- a/lib/cryptodev/rte_cryptodev.c
+++ b/lib/cryptodev/rte_cryptodev.c
@@ -1912,9 +1912,10 @@ rte_cryptodev_sym_session_create(struct rte_mempool *mp)
 	return sess;
 }
 
-void *
+int
 rte_cryptodev_asym_session_create(uint8_t dev_id,
-		struct rte_crypto_asym_xform *xforms, struct rte_mempool *mp)
+		struct rte_crypto_asym_xform *xforms, struct rte_mempool *mp,
+		void **session)
 {
 	struct rte_cryptodev_asym_session *sess;
 	uint32_t session_priv_data_sz;
@@ -1926,17 +1927,17 @@ rte_cryptodev_asym_session_create(uint8_t dev_id,
 
 	if (!rte_cryptodev_is_valid_dev(dev_id)) {
 		CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
-		return NULL;
+		return -EINVAL;
 	}
 
 	dev = rte_cryptodev_pmd_get_dev(dev_id);
 
 	if (dev == NULL)
-		return NULL;
+		return -EINVAL;
 
 	if (!mp) {
 		CDEV_LOG_ERR("invalid mempool\n");
-		return NULL;
+		return -EINVAL;
 	}
 
 	session_priv_data_sz = rte_cryptodev_asym_get_private_session_size(
@@ -1946,22 +1947,23 @@ rte_cryptodev_asym_session_create(uint8_t dev_id,
 	if (pool_priv->max_priv_session_sz < session_priv_data_sz) {
 		CDEV_LOG_DEBUG(
 			"The private session data size used when creating the mempool is smaller than this device's private session data.");
-		return NULL;
+		return -EINVAL;
 	}
 
 	/* Verify if provided mempool can hold elements big enough. */
 	if (mp->elt_size < session_header_size + session_priv_data_sz) {
 		CDEV_LOG_ERR(
 			"mempool elements too small to hold session objects");
-		return NULL;
+		return -EINVAL;
 	}
 
 	/* Allocate a session structure from the session pool */
-	if (rte_mempool_get(mp, (void **)&sess)) {
+	if (rte_mempool_get(mp, session)) {
 		CDEV_LOG_ERR("couldn't get object from session mempool");
-		return NULL;
+		return -ENOMEM;
 	}
 
+	sess = *session;
 	sess->driver_id = dev->driver_id;
 	sess->user_data_sz = pool_priv->user_data_sz;
 	sess->max_priv_data_sz = pool_priv->max_priv_session_sz;
@@ -1969,7 +1971,7 @@ rte_cryptodev_asym_session_create(uint8_t dev_id,
 	/* Clear device session pointer.*/
 	memset(sess->sess_private_data, 0, session_priv_data_sz + sess->user_data_sz);
 
-	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->asym_session_configure, NULL);
+	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->asym_session_configure, -ENOTSUP);
 
 	if (sess->sess_private_data[0] == 0) {
 		ret = dev->dev_ops->asym_session_configure(dev, xforms, sess);
@@ -1977,12 +1979,12 @@ rte_cryptodev_asym_session_create(uint8_t dev_id,
 			CDEV_LOG_ERR(
 				"dev_id %d failed to configure session details",
 				dev_id);
-			return NULL;
+			return ret;
 		}
 	}
 
 	rte_cryptodev_trace_asym_session_create(dev_id, xforms, mp, sess);
-	return sess;
+	return 0;
 }
 
 int
diff --git a/lib/cryptodev/rte_cryptodev.h b/lib/cryptodev/rte_cryptodev.h
index 91110b08da..dba982e919 100644
--- a/lib/cryptodev/rte_cryptodev.h
+++ b/lib/cryptodev/rte_cryptodev.h
@@ -995,14 +995,19 @@ rte_cryptodev_sym_session_create(struct rte_mempool *mempool);
  *                   processed with this session
  * @param   mp       mempool to allocate asymmetric session
  *                   objects from
+ * @param   session  void ** for session to be used
+ *
  * @return
- *  - On success return pointer to asym-session
- *  - On failure returns NULL
+ *  - 0 on success.
+ *  - -EINVAL on invalid arguments.
+ *  - -ENOMEM on memory error for session allocation.
+ *  - -ENOTSUP if device doesn't support session configuration.
  */
 __rte_experimental
-void *
+int
 rte_cryptodev_asym_session_create(uint8_t dev_id,
-		struct rte_crypto_asym_xform *xforms, struct rte_mempool *mp);
+		struct rte_crypto_asym_xform *xforms, struct rte_mempool *mp,
+		void **session);
 
 /**
  * Frees symmetric crypto session header, after checking that all
-- 
2.25.1


^ permalink raw reply	[flat|nested] 31+ messages in thread

* RE: [EXT] [PATCH v4 2/5] crypto: use single buffer for asymmetric session
  2022-02-09 15:38 ` [PATCH v4 2/5] crypto: use single buffer for asymmetric session Ciara Power
@ 2022-02-09 19:52   ` Akhil Goyal
  0 siblings, 0 replies; 31+ messages in thread
From: Akhil Goyal @ 2022-02-09 19:52 UTC (permalink / raw)
  To: Ciara Power, dev
  Cc: roy.fan.zhang, Anoob Joseph, mdr, Declan Doherty, Ankur Dwivedi,
	Tejasree Kondoj, John Griffin, Fiona Trahe, Deepak Kumar Jain

Hi Ciara,
Few minor comments.

> -	/* setup asym session pool */
> -	unsigned int session_size = RTE_MAX(
> -		rte_cryptodev_asym_get_private_session_size(dev_id),
> -		rte_cryptodev_asym_get_header_session_size());
> -	/*
> -	 * Create mempool with TEST_NUM_SESSIONS * 2,
> -	 * to include the session headers
> -	 */
> -	ts_params->session_mpool = rte_mempool_create(
> -				"test_asym_sess_mp",
> -				TEST_NUM_SESSIONS * 2,
> -				session_size,
> -				0, 0, NULL, NULL, NULL,
> -				NULL, SOCKET_ID_ANY,
> -				0);
> +	ts_params->session_mpool =
> rte_cryptodev_asym_session_pool_create(
> +			"test_asym_sess_mp", TEST_NUM_SESSIONS * 2, 0,
> +			SOCKET_ID_ANY);

I believe TEST_NUM_SESSIONS * 2 is no more required.
It can be simply TEST_NUM_SESSIONS.

> 
>  	TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
>  			"session mempool allocation failed");
> @@ -1107,14 +1052,6 @@ test_dh_gen_shared_sec(struct

<snip> 

> @@ -628,16 +626,9 @@ set_sym_session_private_data(struct
> rte_cryptodev_sym_session *sess,
>  }
> 
>  static inline void *
> -get_asym_session_private_data(const struct rte_cryptodev_asym_session
> *sess,
> -		uint8_t driver_id) {
> -	return sess->sess_private_data[driver_id];
> -}
> -
> -static inline void
> -set_asym_session_private_data(struct rte_cryptodev_asym_session *sess,
> -		uint8_t driver_id, void *private_data)
> +get_asym_session_private_data(struct rte_cryptodev_asym_session *sess)
>  {
> -	sess->sess_private_data[driver_id] = private_data;
> +	return sess->sess_private_data;
>  }

I think we can safely remove this get API as well and use sess->sess_private_data
Directly.
Since we are removing set API, get can also be removed as session struct is visible to PMD.

>  /**
>   * Create symmetric crypto session header (generic with no private data)
>   *
> @@ -971,15 +998,19 @@ rte_cryptodev_sym_session_create(struct
> rte_mempool *mempool);
>  /**
>   * Create asymmetric crypto session header (generic with no private data)

This line need an update.


>   *
> - * @param   mempool    mempool to allocate asymmetric session
> - *                     objects from
> + * @param   dev_id   ID of device that we want the session to be used on
> + * @param   xforms   Asymmetric crypto transform operations to apply on flow
> + *                   processed with this session
> + * @param   mp       mempool to allocate asymmetric session
> + *                   objects from
>   * @return
>   *  - On success return pointer to asym-session
>   *  - On failure returns NULL
>   */
>  __rte_experimental
>  struct rte_cryptodev_asym_session *
> -rte_cryptodev_asym_session_create(struct rte_mempool *mempool);
> +rte_cryptodev_asym_session_create(uint8_t dev_id,
> +		struct rte_crypto_asym_xform *xforms, struct rte_mempool
> *mp);

<snip>

> diff --git a/lib/cryptodev/rte_cryptodev_trace.h
> b/lib/cryptodev/rte_cryptodev_trace.h
> index d1f4f069a3..f4e1c870df 100644
> --- a/lib/cryptodev/rte_cryptodev_trace.h
> +++ b/lib/cryptodev/rte_cryptodev_trace.h
> @@ -83,10 +83,22 @@ RTE_TRACE_POINT(
>  	rte_trace_point_emit_u16(sess->user_data_sz);
>  )
> 
> +RTE_TRACE_POINT(
> +	rte_cryptodev_trace_asym_session_pool_create,
> +	RTE_TRACE_POINT_ARGS(const char *name, uint32_t nb_elts,
> +		uint32_t cache_size, void *mempool),
> +	rte_trace_point_emit_string(name);
> +	rte_trace_point_emit_u32(nb_elts);
> +	rte_trace_point_emit_u32(cache_size);
> +	rte_trace_point_emit_ptr(mempool);
> +)
> +
>  RTE_TRACE_POINT(
>  	rte_cryptodev_trace_asym_session_create,
> -	RTE_TRACE_POINT_ARGS(void *mempool,
> -		struct rte_cryptodev_asym_session *sess),
> +	RTE_TRACE_POINT_ARGS(uint8_t dev_id, void *xforms,
> +		void *mempool, struct rte_cryptodev_asym_session *sess),

Sess is not an argument to sess_create API yet. This would be updated in your later patch.

> +	rte_trace_point_emit_u8(dev_id);
> +	rte_trace_point_emit_ptr(xforms);
>  	rte_trace_point_emit_ptr(mempool);
>  	rte_trace_point_emit_ptr(sess);
>  )


^ permalink raw reply	[flat|nested] 31+ messages in thread

* RE: [EXT] [PATCH v4 4/5] crypto: add asym session user data API
  2022-02-09 15:38 ` [PATCH v4 4/5] crypto: add asym session user data API Ciara Power
@ 2022-02-09 20:09   ` Akhil Goyal
  0 siblings, 0 replies; 31+ messages in thread
From: Akhil Goyal @ 2022-02-09 20:09 UTC (permalink / raw)
  To: Ciara Power, dev; +Cc: roy.fan.zhang, Anoob Joseph, mdr, Declan Doherty

> diff --git a/app/test/test_cryptodev_asym.c b/app/test/test_cryptodev_asym.c
> index fff5c0d59a..f9691fe281 100644
> --- a/app/test/test_cryptodev_asym.c
> +++ b/app/test/test_cryptodev_asym.c
> @@ -894,7 +894,7 @@ testsuite_setup(void)
>  	}
> 
>  	ts_params->session_mpool =
> rte_cryptodev_asym_session_pool_create(
> -			"test_asym_sess_mp", TEST_NUM_SESSIONS * 2, 0,
> +			"test_asym_sess_mp", TEST_NUM_SESSIONS * 2, 0, 0,
>  			SOCKET_ID_ANY);
> 

Multiply by 2 is not needed now.

> @@ -1803,7 +1805,7 @@ rte_cryptodev_sym_session_pool_create(const char
> *name, uint32_t nb_elts,
> 
>  struct rte_mempool *
>  rte_cryptodev_asym_session_pool_create(const char *name, uint32_t nb_elts,
> -	uint32_t cache_size, int socket_id)
> +	uint32_t cache_size, uint16_t user_data_size, int socket_id)
>  {
>  	struct rte_mempool *mp;
>  	struct rte_cryptodev_asym_session_pool_private_data *pool_priv;
> @@ -1821,7 +1823,8 @@ rte_cryptodev_asym_session_pool_create(const char
> *name, uint32_t nb_elts,
>  		return NULL;
>  	}
> 
> -	obj_sz = rte_cryptodev_asym_get_header_session_size() + max_priv_sz;
> +	obj_sz = rte_cryptodev_asym_get_header_session_size() + max_priv_sz
> +
> +			user_data_size;

Extra line

>  	obj_sz_aligned =  RTE_ALIGN_CEIL(obj_sz, RTE_CACHE_LINE_SIZE);
> 
>  	mp = rte_mempool_create(name, nb_elts, obj_sz_aligned, cache_size,


^ permalink raw reply	[flat|nested] 31+ messages in thread

* RE: [EXT] [PATCH v4 5/5] crypto: modify return value for asym session create
  2022-02-09 15:38 ` [PATCH v4 5/5] crypto: modify return value for asym session create Ciara Power
@ 2022-02-09 20:19   ` Akhil Goyal
  0 siblings, 0 replies; 31+ messages in thread
From: Akhil Goyal @ 2022-02-09 20:19 UTC (permalink / raw)
  To: Ciara Power, dev; +Cc: roy.fan.zhang, Anoob Joseph, mdr, Declan Doherty

> Rather than the asym session create function returning a session on
> success, and a NULL value on error, it is modified to now return int
> values - 0 on success or -EINVAL/-ENOTSUP/-ENOMEM on failure.
> The session to be used is passed as input.
> 
> This adds clarity on the failure of the create function, which enables
> treating the -ENOTSUP return as TEST_SKIPPED in test apps.
> 
> Signed-off-by: Ciara Power <ciara.power@intel.com>
> Acked-by: Fan Zhang <roy.fan.zhang@intel.com>
> Acked-by: Anoob Joseph <anoobj@marvell.com>
Acked-by: Akhil Goyal <gakhil@marvell.com>

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [PATCH v5 0/5] crypto: improve asym session usage
  2022-02-09 15:38 [PATCH v4 0/5] crypto: improve asym session usage Ciara Power
                   ` (4 preceding siblings ...)
  2022-02-09 15:38 ` [PATCH v4 5/5] crypto: modify return value for asym session create Ciara Power
@ 2022-02-10 14:01 ` Ciara Power
  2022-02-10 14:01   ` [PATCH v5 1/5] doc: replace asym crypto code with literal includes Ciara Power
                     ` (4 more replies)
  2022-02-10 15:53 ` [PATCH v6 0/5] crypto: improve asym session usage Ciara Power
  2022-02-11  9:29 ` [PATCH v7 " Ciara Power
  7 siblings, 5 replies; 31+ messages in thread
From: Ciara Power @ 2022-02-10 14:01 UTC (permalink / raw)
  To: dev; +Cc: roy.fan.zhang, gakhil, anoobj, mdr, Ciara Power

This patchset includes improvements for the asymmetric session.
The main change is to the session structure, which is now a single
mempool object, rather than having pointers to private data elsewhere.
This session structure is now hidden in an internal header,
so the app will never use it directly.

Some other changes include adding a user data API, and modifying
the return value for the create session function.
This create session function now also initialises the session,
and subsequently the clear/free functions have been merged into one.

Sample code in the programmer's guide that showed basic steps for
using Asymmetric crypto in DPDK has been replaced with literal includes
in the first patch of this patchset. This ensures all subsequent code
changes in the patchset are automatically reflected in the documentation.

v5:
  - Modified which patch the sess parameter is passed to session create
    trace function.
  - Reworded create session function description.
  - Removed get API for session private data, can be accessed directly.
  - Modified test application to create a session mempool for
    TEST_NUM_SESSIONS rather than TEST_NUM_SESSIONS * 2.

v4:
  - Added new patch to add literal includes usage in programmer's guide.
  - Merged asym crypto session clear and free functions.
  - Reordered some function parameters.
  - Updated trace function for asym crypto session create.
  - Fixed cnxk clear, the PMD no longer needs to put private data
    back into a mempool.
  - Renamed struct field for max private session size.
  - Replaced __extension__ with RTE_STD_C11.
  - Moved some parameter validity checks to before functional code.
  - Reworded release note.
  - Removed mempool parameter from session configure function.
  - Removed docs code additions, these are included due to patch 1
    changing sample doc to use literal includes.
  - Initialised session variables as NULL.
  - Added possible error return values in user data API comment.

v3:
  - Added documentation in relevant patches.
  - Fixed setting user data size.
  - Fixed hiding structure, it should not be hidden from PMDs.
  - Fixed some other small formatting issues.
  - Increased size of max_priv_session_sz to uint16_t.
  - Removed trace for asym session init function that was
    previously removed.

Ciara Power (5):
  doc: replace asym crypto code with literal includes
  crypto: use single buffer for asymmetric session
  crypto: hide asym session structure
  crypto: add asym session user data API
  crypto: modify return value for asym session create

 app/test-crypto-perf/cperf_ops.c             |  22 +-
 app/test-crypto-perf/cperf_test_throughput.c |   8 +-
 app/test/test_cryptodev_asym.c               | 380 ++++++-------------
 app/test/test_cryptodev_mod_test_vectors.h   |   4 +
 doc/guides/prog_guide/cryptodev_lib.rst      | 212 +++--------
 doc/guides/rel_notes/release_22_03.rst       |  14 +
 drivers/crypto/cnxk/cn10k_cryptodev_ops.c    |   8 +-
 drivers/crypto/cnxk/cn9k_cryptodev_ops.c     |   8 +-
 drivers/crypto/cnxk/cnxk_cryptodev_ops.c     |  22 +-
 drivers/crypto/cnxk/cnxk_cryptodev_ops.h     |   3 +-
 drivers/crypto/octeontx/otx_cryptodev_ops.c  |  32 +-
 drivers/crypto/openssl/rte_openssl_pmd.c     |   4 +-
 drivers/crypto/openssl/rte_openssl_pmd_ops.c |  24 +-
 drivers/crypto/qat/qat_asym.c                |  54 +--
 drivers/crypto/qat/qat_asym.h                |   5 +-
 lib/cryptodev/cryptodev_pmd.h                |  36 +-
 lib/cryptodev/cryptodev_trace_points.c       |   9 +-
 lib/cryptodev/rte_cryptodev.c                | 258 ++++++++-----
 lib/cryptodev/rte_cryptodev.h                | 136 ++++---
 lib/cryptodev/rte_cryptodev_trace.h          |  38 +-
 lib/cryptodev/version.map                    |   9 +-
 21 files changed, 524 insertions(+), 762 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 31+ messages in thread

* [PATCH v5 1/5] doc: replace asym crypto code with literal includes
  2022-02-10 14:01 ` [PATCH v5 0/5] crypto: improve asym session usage Ciara Power
@ 2022-02-10 14:01   ` Ciara Power
  2022-02-10 14:01   ` [PATCH v5 2/5] crypto: use single buffer for asymmetric session Ciara Power
                     ` (3 subsequent siblings)
  4 siblings, 0 replies; 31+ messages in thread
From: Ciara Power @ 2022-02-10 14:01 UTC (permalink / raw)
  To: dev; +Cc: roy.fan.zhang, gakhil, anoobj, mdr, Ciara Power, Declan Doherty

The programmer's guide for cryptodev included sample code for using
Asymmetric crypto. This is now replaced with direct code from the test
application, using literal includes. It is broken into snippets as the
test application didn't have all of the required code in one function.

Signed-off-by: Ciara Power <ciara.power@intel.com>
---
 app/test/test_cryptodev_asym.c             |   7 +-
 app/test/test_cryptodev_mod_test_vectors.h |   4 +
 doc/guides/prog_guide/cryptodev_lib.rst    | 176 ++++-----------------
 3 files changed, 37 insertions(+), 150 deletions(-)

diff --git a/app/test/test_cryptodev_asym.c b/app/test/test_cryptodev_asym.c
index 9d3a5589bb..8d7290f9ed 100644
--- a/app/test/test_cryptodev_asym.c
+++ b/app/test/test_cryptodev_asym.c
@@ -855,6 +855,7 @@ testsuite_setup(void)
 	test_vector.size = 0;
 	load_test_vectors();
 
+	/* Device, op pool and session configuration for asymmetric crypto. 8< */
 	ts_params->op_mpool = rte_crypto_op_pool_create(
 			"CRYPTO_ASYM_OP_POOL",
 			RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
@@ -953,7 +954,7 @@ testsuite_setup(void)
 
 	TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
 			"session mempool allocation failed");
-
+	/* >8 End of device, op pool and session configuration for asymmetric crypto section. */
 	return TEST_SUCCESS;
 }
 
@@ -1637,7 +1638,7 @@ test_mod_exp(void)
 				return TEST_SKIPPED;
 		}
 
-	/* generate crypto op data structure */
+	/* Create op, create session, and process packets. 8< */
 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
 	if (!op) {
 		RTE_LOG(ERR, USER1,
@@ -1696,7 +1697,7 @@ test_mod_exp(void)
 		status = TEST_FAILED;
 		goto error_exit;
 	}
-
+	/* >8 End of create op, create session, and process packets section. */
 	ret = verify_modexp(mod_exp, result_op);
 	if (ret) {
 		RTE_LOG(ERR, USER1,
diff --git a/app/test/test_cryptodev_mod_test_vectors.h b/app/test/test_cryptodev_mod_test_vectors.h
index c66f4b18bc..807ca7a47e 100644
--- a/app/test/test_cryptodev_mod_test_vectors.h
+++ b/app/test/test_cryptodev_mod_test_vectors.h
@@ -979,6 +979,7 @@ uint8_t base[] = {
 	0xA8, 0xEB, 0x7E, 0x78, 0xA0, 0x50
 };
 
+/* MODEX data. 8< */
 uint8_t mod_p[] = {
 	0x00, 0xb3, 0xa1, 0xaf, 0xb7, 0x13, 0x08, 0x00,
 	0x0a, 0x35, 0xdc, 0x2b, 0x20, 0x8d, 0xa1, 0xb5,
@@ -1000,6 +1001,7 @@ uint8_t mod_p[] = {
 };
 
 uint8_t mod_e[] = {0x01, 0x00, 0x01};
+/* >8 End of MODEX data. */
 
 /* Precomputed modular exponentiation for verification */
 uint8_t mod_exp[] = {
@@ -1041,6 +1043,7 @@ uint8_t mod_inv[] = {
 	0x9a, 0x66, 0x9a, 0x3a, 0xc1, 0xb8, 0x4b, 0xc3
 };
 
+/* MODEX vector. 8< */
 struct rte_crypto_asym_xform modex_xform = {
 	.next = NULL,
 	.xform_type = RTE_CRYPTO_ASYM_XFORM_MODEX,
@@ -1055,6 +1058,7 @@ struct rte_crypto_asym_xform modex_xform = {
 		}
 	}
 };
+/* >8 End of MODEX vector. */
 
 struct rte_crypto_asym_xform modinv_xform = {
 	.next = NULL,
diff --git a/doc/guides/prog_guide/cryptodev_lib.rst b/doc/guides/prog_guide/cryptodev_lib.rst
index 8766bc34a9..9f33f7a177 100644
--- a/doc/guides/prog_guide/cryptodev_lib.rst
+++ b/doc/guides/prog_guide/cryptodev_lib.rst
@@ -1119,162 +1119,44 @@ Asymmetric crypto Sample code
 There's a unit test application test_cryptodev_asym.c inside unit test framework that
 show how to setup and process asymmetric operations using cryptodev library.
 
-The following sample code shows the basic steps to compute modular exponentiation
-using 1024-bit modulus length using openssl PMD available in DPDK (performing other
-crypto operations is similar except change to respective op and xform setup).
+The following code samples are taken from the test application mentioned above,
+and show basic steps to compute modular exponentiation using an openssl PMD
+available in DPDK (performing other crypto operations is similar except change
+to respective op and xform setup).
 
-.. code-block:: c
+.. note::
+   The following code snippets are taken from multiple functions, so variable
+   names may differ slightly between sections.
 
-    /*
-     * Simple example to compute modular exponentiation with 1024-bit key
-     *
-     */
-    #define MAX_ASYM_SESSIONS	10
-    #define NUM_ASYM_BUFS	10
-
-    struct rte_mempool *crypto_op_pool, *asym_session_pool;
-    unsigned int asym_session_size;
-    int ret;
+Configure the virtual device, queue pairs, crypto op pool and session mempool.
 
-    /* Initialize EAL. */
-    ret = rte_eal_init(argc, argv);
-    if (ret < 0)
-        rte_exit(EXIT_FAILURE, "Invalid EAL arguments\n");
+.. literalinclude:: ../../../app/test/test_cryptodev_asym.c
+   :language: c
+   :start-after: Device, op pool and session configuration for asymmetric crypto. 8<
+   :end-before: >8 End of device, op pool and session configuration for asymmetric crypto section.
+   :dedent: 1
 
-    uint8_t socket_id = rte_socket_id();
-
-    /* Create crypto operation pool. */
-    crypto_op_pool = rte_crypto_op_pool_create(
-                                    "crypto_op_pool",
-                                    RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
-                                    NUM_ASYM_BUFS, 0, 0,
-                                    socket_id);
-    if (crypto_op_pool == NULL)
-        rte_exit(EXIT_FAILURE, "Cannot create crypto op pool\n");
-
-    /* Create the virtual crypto device. */
-    char args[128];
-    const char *crypto_name = "crypto_openssl";
-    snprintf(args, sizeof(args), "socket_id=%d", socket_id);
-    ret = rte_vdev_init(crypto_name, args);
-    if (ret != 0)
-        rte_exit(EXIT_FAILURE, "Cannot create virtual device");
+Create MODEX data vectors.
 
-    uint8_t cdev_id = rte_cryptodev_get_dev_id(crypto_name);
+.. literalinclude:: ../../../app/test/test_cryptodev_mod_test_vectors.h
+   :language: c
+   :start-after: MODEX data. 8<
+   :end-before: >8 End of MODEX data.
 
-    /* Get private asym session data size. */
-    asym_session_size = rte_cryptodev_get_asym_private_session_size(cdev_id);
+Setup crypto xform to do modular exponentiation using data vectors.
 
-    /*
-     * Create session mempool, with two objects per session,
-     * one for the session header and another one for the
-     * private asym session data for the crypto device.
-     */
-    asym_session_pool = rte_mempool_create("asym_session_pool",
-                                    MAX_ASYM_SESSIONS * 2,
-                                    asym_session_size,
-                                    0,
-                                    0, NULL, NULL, NULL,
-                                    NULL, socket_id,
-                                    0);
+.. literalinclude:: ../../../app/test/test_cryptodev_mod_test_vectors.h
+   :language: c
+   :start-after: MODEX vector. 8<
+   :end-before: >8 End of MODEX vector.
 
-    /* Configure the crypto device. */
-    struct rte_cryptodev_config conf = {
-        .nb_queue_pairs = 1,
-        .socket_id = socket_id
-    };
-    struct rte_cryptodev_qp_conf qp_conf = {
-        .nb_descriptors = 2048
-    };
+Generate crypto op, create and attach a session, then process packets.
 
-    if (rte_cryptodev_configure(cdev_id, &conf) < 0)
-        rte_exit(EXIT_FAILURE, "Failed to configure cryptodev %u", cdev_id);
-
-    if (rte_cryptodev_queue_pair_setup(cdev_id, 0, &qp_conf,
-                            socket_id, asym_session_pool) < 0)
-        rte_exit(EXIT_FAILURE, "Failed to setup queue pair\n");
-
-    if (rte_cryptodev_start(cdev_id) < 0)
-        rte_exit(EXIT_FAILURE, "Failed to start device\n");
-
-    /* Setup crypto xform to do modular exponentiation with 1024 bit
-	 * length modulus
-	 */
-    struct rte_crypto_asym_xform modex_xform = {
-		.next = NULL,
-		.xform_type = RTE_CRYPTO_ASYM_XFORM_MODEX,
-		.modex = {
-			.modulus = {
-				.data =
-				(uint8_t *)
-				("\xb3\xa1\xaf\xb7\x13\x08\x00\x0a\x35\xdc\x2b\x20\x8d"
-				"\xa1\xb5\xce\x47\x8a\xc3\x80\xf4\x7d\x4a\xa2\x62\xfd\x61\x7f"
-				"\xb5\xa8\xde\x0a\x17\x97\xa0\xbf\xdf\x56\x5a\x3d\x51\x56\x4f"
-				"\x70\x70\x3f\x63\x6a\x44\x5b\xad\x84\x0d\x3f\x27\x6e\x3b\x34"
-				"\x91\x60\x14\xb9\xaa\x72\xfd\xa3\x64\xd2\x03\xa7\x53\x87\x9e"
-				"\x88\x0b\xc1\x14\x93\x1a\x62\xff\xb1\x5d\x74\xcd\x59\x63\x18"
-				"\x11\x3d\x4f\xba\x75\xd4\x33\x4e\x23\x6b\x7b\x57\x44\xe1\xd3"
-				"\x03\x13\xa6\xf0\x8b\x60\xb0\x9e\xee\x75\x08\x9d\x71\x63\x13"
-				"\xcb\xa6\x81\x92\x14\x03\x22\x2d\xde\x55"),
-				.length = 128
-			},
-			.exponent = {
-				.data = (uint8_t *)("\x01\x00\x01"),
-				.length = 3
-			}
-		}
-    };
-    /* Create asym crypto session and initialize it for the crypto device. */
-    struct rte_cryptodev_asym_session *asym_session;
-    asym_session = rte_cryptodev_asym_session_create(asym_session_pool);
-    if (asym_session == NULL)
-        rte_exit(EXIT_FAILURE, "Session could not be created\n");
-
-    if (rte_cryptodev_asym_session_init(cdev_id, asym_session,
-                    &modex_xform, asym_session_pool) < 0)
-        rte_exit(EXIT_FAILURE, "Session could not be initialized "
-                    "for the crypto device\n");
-
-    /* Get a burst of crypto operations. */
-    struct rte_crypto_op *crypto_ops[1];
-    if (rte_crypto_op_bulk_alloc(crypto_op_pool,
-                            RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
-                            crypto_ops, 1) == 0)
-        rte_exit(EXIT_FAILURE, "Not enough crypto operations available\n");
-
-    /* Set up the crypto operations. */
-    struct rte_crypto_asym_op *asym_op = crypto_ops[0]->asym;
-
-	/* calculate mod exp of value 0xf8 */
-    static unsigned char base[] = {0xF8};
-    asym_op->modex.base.data = base;
-    asym_op->modex.base.length = sizeof(base);
-	asym_op->modex.base.iova = base;
-
-    /* Attach the asym crypto session to the operation */
-    rte_crypto_op_attach_asym_session(op, asym_session);
-
-    /* Enqueue the crypto operations in the crypto device. */
-    uint16_t num_enqueued_ops = rte_cryptodev_enqueue_burst(cdev_id, 0,
-                                            crypto_ops, 1);
-
-    /*
-     * Dequeue the crypto operations until all the operations
-     * are processed in the crypto device.
-     */
-    uint16_t num_dequeued_ops, total_num_dequeued_ops = 0;
-    do {
-        struct rte_crypto_op *dequeued_ops[1];
-        num_dequeued_ops = rte_cryptodev_dequeue_burst(cdev_id, 0,
-                                        dequeued_ops, 1);
-        total_num_dequeued_ops += num_dequeued_ops;
-
-        /* Check if operation was processed successfully */
-        if (dequeued_ops[0]->status != RTE_CRYPTO_OP_STATUS_SUCCESS)
-                rte_exit(EXIT_FAILURE,
-                        "Some operations were not processed correctly");
-
-    } while (total_num_dequeued_ops < num_enqueued_ops);
+.. literalinclude:: ../../../app/test/test_cryptodev_asym.c
+   :language: c
+   :start-after: Create op, create session, and process packets. 8<
+   :end-before: >8 End of create op, create session, and process packets section.
+   :dedent: 1
 
 
 Asymmetric Crypto Device API
-- 
2.25.1


^ permalink raw reply	[flat|nested] 31+ messages in thread

* [PATCH v5 2/5] crypto: use single buffer for asymmetric session
  2022-02-10 14:01 ` [PATCH v5 0/5] crypto: improve asym session usage Ciara Power
  2022-02-10 14:01   ` [PATCH v5 1/5] doc: replace asym crypto code with literal includes Ciara Power
@ 2022-02-10 14:01   ` Ciara Power
  2022-02-10 14:34     ` [EXT] " Anoob Joseph
  2022-02-10 14:01   ` [PATCH v5 3/5] crypto: hide asym session structure Ciara Power
                     ` (2 subsequent siblings)
  4 siblings, 1 reply; 31+ messages in thread
From: Ciara Power @ 2022-02-10 14:01 UTC (permalink / raw)
  To: dev
  Cc: roy.fan.zhang, gakhil, anoobj, mdr, Ciara Power, Declan Doherty,
	Ankur Dwivedi, Tejasree Kondoj, John Griffin, Fiona Trahe,
	Deepak Kumar Jain

Rather than using a session buffer that contains pointers to private
session data elsewhere, have a single session buffer.
This session is created for a driver ID, and the mempool element
contains space for the max session private data needed for any driver.

Signed-off-by: Ciara Power <ciara.power@intel.com>
Acked-by: Fan Zhang <roy.fan.zhang@intel.com>

---
v5:
  - Removed get API for session private data, can be accessed directly.
  - Modified test application to create a session mempool for
    TEST_NUM_SESSIONS rather than TEST_NUM_SESSIONS * 2.
  - Reworded create session function description.
  - Removed sess parameter from create session trace,
    to be added in a later patch.
v4:
  - Merged asym crypto session clear and free functions.
  - Reordered some function parameters.
  - Updated trace function for asym crypto session create.
  - Fixed cnxk clear, the PMD no longer needs to put private data
    back into a mempool.
  - Renamed struct field for max private session size.
  - Replaced __extension__ with RTE_STD_C11.
  - Moved some parameter validity checks to before functional code.
  - Reworded release note.
  - Removed mempool parameter from session configure function.
  - Removed docs code additions, these are included due to patch 1
    changing sample doc to use literal includes.
v3:
  - Corrected formatting of struct comments.
  - Increased size of max_priv_session_sz to uint16_t.
  - Removed trace for asym session init function that was
    previously removed.
  - Added documentation.
v2:
  - Renamed function typedef from "free" to "clear" as session private
    data isn't being freed in that function.
  - Moved user data API to separate patch.
  - Minor fixes to comments, formatting, return values.
---
 app/test-crypto-perf/cperf_ops.c             |  14 +-
 app/test-crypto-perf/cperf_test_throughput.c |   8 +-
 app/test/test_cryptodev_asym.c               | 272 +++++--------------
 doc/guides/prog_guide/cryptodev_lib.rst      |  21 +-
 doc/guides/rel_notes/release_22_03.rst       |   7 +
 drivers/crypto/cnxk/cn10k_cryptodev_ops.c    |   8 +-
 drivers/crypto/cnxk/cn9k_cryptodev_ops.c     |   8 +-
 drivers/crypto/cnxk/cnxk_cryptodev_ops.c     |  22 +-
 drivers/crypto/cnxk/cnxk_cryptodev_ops.h     |   3 +-
 drivers/crypto/octeontx/otx_cryptodev_ops.c  |  32 +--
 drivers/crypto/openssl/rte_openssl_pmd.c     |   4 +-
 drivers/crypto/openssl/rte_openssl_pmd_ops.c |  24 +-
 drivers/crypto/qat/qat_asym.c                |  54 +---
 drivers/crypto/qat/qat_asym.h                |   5 +-
 lib/cryptodev/cryptodev_pmd.h                |  23 +-
 lib/cryptodev/cryptodev_trace_points.c       |   9 +-
 lib/cryptodev/rte_cryptodev.c                | 213 ++++++++-------
 lib/cryptodev/rte_cryptodev.h                |  97 ++++---
 lib/cryptodev/rte_cryptodev_trace.h          |  38 ++-
 lib/cryptodev/version.map                    |   7 +-
 20 files changed, 315 insertions(+), 554 deletions(-)

diff --git a/app/test-crypto-perf/cperf_ops.c b/app/test-crypto-perf/cperf_ops.c
index d975ae1ab8..b125c699de 100644
--- a/app/test-crypto-perf/cperf_ops.c
+++ b/app/test-crypto-perf/cperf_ops.c
@@ -735,7 +735,6 @@ cperf_create_session(struct rte_mempool *sess_mp,
 	struct rte_crypto_sym_xform aead_xform;
 	struct rte_cryptodev_sym_session *sess = NULL;
 	struct rte_crypto_asym_xform xform = {0};
-	int rc;
 
 	if (options->op_type == CPERF_ASYM_MODEX) {
 		xform.next = NULL;
@@ -745,19 +744,10 @@ cperf_create_session(struct rte_mempool *sess_mp,
 		xform.modex.exponent.data = perf_mod_e;
 		xform.modex.exponent.length = sizeof(perf_mod_e);
 
-		sess = (void *)rte_cryptodev_asym_session_create(sess_mp);
+		sess = (void *)rte_cryptodev_asym_session_create(dev_id, &xform, sess_mp);
 		if (sess == NULL)
 			return NULL;
-		rc = rte_cryptodev_asym_session_init(dev_id, (void *)sess,
-						     &xform, priv_mp);
-		if (rc < 0) {
-			if (sess != NULL) {
-				rte_cryptodev_asym_session_clear(dev_id,
-								 (void *)sess);
-				rte_cryptodev_asym_session_free((void *)sess);
-			}
-			return NULL;
-		}
+
 		return sess;
 	}
 #ifdef RTE_LIB_SECURITY
diff --git a/app/test-crypto-perf/cperf_test_throughput.c b/app/test-crypto-perf/cperf_test_throughput.c
index 51512af2ad..ee21ff27f7 100644
--- a/app/test-crypto-perf/cperf_test_throughput.c
+++ b/app/test-crypto-perf/cperf_test_throughput.c
@@ -35,11 +35,9 @@ cperf_throughput_test_free(struct cperf_throughput_ctx *ctx)
 	if (!ctx)
 		return;
 	if (ctx->sess) {
-		if (ctx->options->op_type == CPERF_ASYM_MODEX) {
-			rte_cryptodev_asym_session_clear(ctx->dev_id,
-							 (void *)ctx->sess);
-			rte_cryptodev_asym_session_free((void *)ctx->sess);
-		}
+		if (ctx->options->op_type == CPERF_ASYM_MODEX)
+			rte_cryptodev_asym_session_free(ctx->dev_id,
+					(void *)ctx->sess);
 #ifdef RTE_LIB_SECURITY
 		else if (ctx->options->op_type == CPERF_PDCP ||
 			 ctx->options->op_type == CPERF_DOCSIS ||
diff --git a/app/test/test_cryptodev_asym.c b/app/test/test_cryptodev_asym.c
index 8d7290f9ed..88433faf1c 100644
--- a/app/test/test_cryptodev_asym.c
+++ b/app/test/test_cryptodev_asym.c
@@ -452,7 +452,8 @@ test_cryptodev_asym_op(struct crypto_testsuite_params_asym *ts_params,
 	}
 
 	if (!sessionless) {
-		sess = rte_cryptodev_asym_session_create(ts_params->session_mpool);
+		sess = rte_cryptodev_asym_session_create(dev_id, &xform_tc,
+				ts_params->session_mpool);
 		if (!sess) {
 			snprintf(test_msg, ASYM_TEST_MSG_LEN,
 					"line %u "
@@ -462,15 +463,6 @@ test_cryptodev_asym_op(struct crypto_testsuite_params_asym *ts_params,
 			goto error_exit;
 		}
 
-		if (rte_cryptodev_asym_session_init(dev_id, sess, &xform_tc,
-				ts_params->session_mpool) < 0) {
-			snprintf(test_msg, ASYM_TEST_MSG_LEN,
-					"line %u FAILED: %s",
-					__LINE__, "unabled to config sym session");
-			status = TEST_FAILED;
-			goto error_exit;
-		}
-
 		rte_crypto_op_attach_asym_session(op, sess);
 	} else {
 		asym_op->xform = &xform_tc;
@@ -512,10 +504,8 @@ test_cryptodev_asym_op(struct crypto_testsuite_params_asym *ts_params,
 		snprintf(test_msg, ASYM_TEST_MSG_LEN, "SESSIONLESS PASS");
 
 error_exit:
-		if (sess != NULL) {
-			rte_cryptodev_asym_session_clear(dev_id, sess);
-			rte_cryptodev_asym_session_free(sess);
-		}
+		if (sess != NULL)
+			rte_cryptodev_asym_session_free(dev_id, sess);
 
 		if (op != NULL)
 			rte_crypto_op_free(op);
@@ -669,18 +659,11 @@ test_rsa_sign_verify(void)
 		return TEST_SKIPPED;
 	}
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
+	sess = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool);
 
 	if (!sess) {
 		RTE_LOG(ERR, USER1, "Session creation failed for "
 			"sign_verify\n");
-		return TEST_FAILED;
-	}
-
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform,
-				sess_mpool) < 0) {
-		RTE_LOG(ERR, USER1, "Unable to config asym session for "
-			"sign_verify\n");
 		status = TEST_FAILED;
 		goto error_exit;
 	}
@@ -688,9 +671,7 @@ test_rsa_sign_verify(void)
 	status = queue_ops_rsa_sign_verify(sess);
 
 error_exit:
-
-	rte_cryptodev_asym_session_clear(dev_id, sess);
-	rte_cryptodev_asym_session_free(sess);
+	rte_cryptodev_asym_session_free(dev_id, sess);
 
 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
 
@@ -718,17 +699,10 @@ test_rsa_enc_dec(void)
 		return TEST_SKIPPED;
 	}
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
+	sess = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool);
 
 	if (!sess) {
 		RTE_LOG(ERR, USER1, "Session creation failed for enc_dec\n");
-		return TEST_FAILED;
-	}
-
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform,
-				sess_mpool) < 0) {
-		RTE_LOG(ERR, USER1, "Unable to config asym session for "
-			"enc_dec\n");
 		status = TEST_FAILED;
 		goto error_exit;
 	}
@@ -737,8 +711,7 @@ test_rsa_enc_dec(void)
 
 error_exit:
 
-	rte_cryptodev_asym_session_clear(dev_id, sess);
-	rte_cryptodev_asym_session_free(sess);
+	rte_cryptodev_asym_session_free(dev_id, sess);
 
 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
 
@@ -765,28 +738,20 @@ test_rsa_sign_verify_crt(void)
 		return TEST_SKIPPED;
 	}
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
+	sess = rte_cryptodev_asym_session_create(dev_id, &rsa_xform_crt, sess_mpool);
 
 	if (!sess) {
 		RTE_LOG(ERR, USER1, "Session creation failed for "
 			"sign_verify_crt\n");
 		status = TEST_FAILED;
-		return status;
-	}
-
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform_crt,
-				sess_mpool) < 0) {
-		RTE_LOG(ERR, USER1, "Unable to config asym session for "
-			"sign_verify_crt\n");
-		status = TEST_FAILED;
 		goto error_exit;
 	}
+
 	status = queue_ops_rsa_sign_verify(sess);
 
 error_exit:
 
-	rte_cryptodev_asym_session_clear(dev_id, sess);
-	rte_cryptodev_asym_session_free(sess);
+	rte_cryptodev_asym_session_free(dev_id, sess);
 
 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
 
@@ -813,27 +778,20 @@ test_rsa_enc_dec_crt(void)
 		return TEST_SKIPPED;
 	}
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
+	sess = rte_cryptodev_asym_session_create(dev_id, &rsa_xform_crt, sess_mpool);
 
 	if (!sess) {
 		RTE_LOG(ERR, USER1, "Session creation failed for "
 			"enc_dec_crt\n");
-		return TEST_FAILED;
-	}
-
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform_crt,
-				sess_mpool) < 0) {
-		RTE_LOG(ERR, USER1, "Unable to config asym session for "
-			"enc_dec_crt\n");
 		status = TEST_FAILED;
 		goto error_exit;
 	}
+
 	status = queue_ops_rsa_enc_dec(sess);
 
 error_exit:
 
-	rte_cryptodev_asym_session_clear(dev_id, sess);
-	rte_cryptodev_asym_session_free(sess);
+	rte_cryptodev_asym_session_free(dev_id, sess);
 
 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
 
@@ -927,7 +885,6 @@ testsuite_setup(void)
 	/* configure qp */
 	ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
 	ts_params->qp_conf.mp_session = ts_params->session_mpool;
-	ts_params->qp_conf.mp_session_private = ts_params->session_mpool;
 	for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
 			dev_id, qp_id, &ts_params->qp_conf,
@@ -936,21 +893,9 @@ testsuite_setup(void)
 			qp_id, dev_id);
 	}
 
-	/* setup asym session pool */
-	unsigned int session_size = RTE_MAX(
-		rte_cryptodev_asym_get_private_session_size(dev_id),
-		rte_cryptodev_asym_get_header_session_size());
-	/*
-	 * Create mempool with TEST_NUM_SESSIONS * 2,
-	 * to include the session headers
-	 */
-	ts_params->session_mpool = rte_mempool_create(
-				"test_asym_sess_mp",
-				TEST_NUM_SESSIONS * 2,
-				session_size,
-				0, 0, NULL, NULL, NULL,
-				NULL, SOCKET_ID_ANY,
-				0);
+	ts_params->session_mpool = rte_cryptodev_asym_session_pool_create(
+			"test_asym_sess_mp", TEST_NUM_SESSIONS, 0,
+			SOCKET_ID_ANY);
 
 	TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
 			"session mempool allocation failed");
@@ -1107,14 +1052,6 @@ test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
 	struct rte_crypto_asym_xform xform = *xfrm;
 	uint8_t peer[] = "01234567890123456789012345678901234567890123456789";
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
-	if (sess == NULL) {
-		RTE_LOG(ERR, USER1,
-				"line %u FAILED: %s", __LINE__,
-				"Session creation failed");
-		status = TEST_FAILED;
-		goto error_exit;
-	}
 	/* set up crypto op data structure */
 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
 	if (!op) {
@@ -1137,11 +1074,11 @@ test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
 	asym_op->dh.shared_secret.data = output;
 	asym_op->dh.shared_secret.length = sizeof(output);
 
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
-			sess_mpool) < 0) {
+	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
+	if (sess == NULL) {
 		RTE_LOG(ERR, USER1,
-				"line %u FAILED: %s",
-				__LINE__, "unabled to config sym session");
+				"line %u FAILED: %s", __LINE__,
+				"Session creation failed");
 		status = TEST_FAILED;
 		goto error_exit;
 	}
@@ -1176,10 +1113,8 @@ test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
 			asym_op->dh.shared_secret.length);
 
 error_exit:
-	if (sess != NULL) {
-		rte_cryptodev_asym_session_clear(dev_id, sess);
-		rte_cryptodev_asym_session_free(sess);
-	}
+	if (sess != NULL)
+		rte_cryptodev_asym_session_free(dev_id, sess);
 	if (op != NULL)
 		rte_crypto_op_free(op);
 	return status;
@@ -1199,14 +1134,6 @@ test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
 	uint8_t output[TEST_DH_MOD_LEN];
 	struct rte_crypto_asym_xform xform = *xfrm;
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
-	if (sess == NULL) {
-		RTE_LOG(ERR, USER1,
-				 "line %u FAILED: %s", __LINE__,
-				"Session creation failed");
-		status = TEST_FAILED;
-		goto error_exit;
-	}
 	/* set up crypto op data structure */
 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
 	if (!op) {
@@ -1225,11 +1152,11 @@ test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
 	asym_op->dh.priv_key.data = output;
 	asym_op->dh.priv_key.length = sizeof(output);
 
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
-			sess_mpool) < 0) {
+	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
+	if (sess == NULL) {
 		RTE_LOG(ERR, USER1,
-				"line %u FAILED: %s",
-				__LINE__, "unabled to config sym session");
+				"line %u FAILED: %s", __LINE__,
+				"Session creation failed");
 		status = TEST_FAILED;
 		goto error_exit;
 	}
@@ -1265,10 +1192,8 @@ test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
 
 
 error_exit:
-	if (sess != NULL) {
-		rte_cryptodev_asym_session_clear(dev_id, sess);
-		rte_cryptodev_asym_session_free(sess);
-	}
+	if (sess != NULL)
+		rte_cryptodev_asym_session_free(dev_id, sess);
 	if (op != NULL)
 		rte_crypto_op_free(op);
 
@@ -1290,14 +1215,6 @@ test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
 	uint8_t output[TEST_DH_MOD_LEN];
 	struct rte_crypto_asym_xform xform = *xfrm;
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
-	if (sess == NULL) {
-		RTE_LOG(ERR, USER1,
-				 "line %u FAILED: %s", __LINE__,
-				"Session creation failed");
-		status = TEST_FAILED;
-		goto error_exit;
-	}
 	/* set up crypto op data structure */
 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
 	if (!op) {
@@ -1324,11 +1241,11 @@ test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
 					0);
 	asym_op->dh.priv_key = dh_test_params.priv_key;
 
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
-			sess_mpool) < 0) {
+	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
+	if (sess == NULL) {
 		RTE_LOG(ERR, USER1,
-				"line %u FAILED: %s",
-				__LINE__, "unabled to config sym session");
+				"line %u FAILED: %s", __LINE__,
+				"Session creation failed");
 		status = TEST_FAILED;
 		goto error_exit;
 	}
@@ -1365,10 +1282,8 @@ test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
 			asym_op->dh.priv_key.data, asym_op->dh.priv_key.length);
 
 error_exit:
-	if (sess != NULL) {
-		rte_cryptodev_asym_session_clear(dev_id, sess);
-		rte_cryptodev_asym_session_free(sess);
-	}
+	if (sess != NULL)
+		rte_cryptodev_asym_session_free(dev_id, sess);
 	if (op != NULL)
 		rte_crypto_op_free(op);
 
@@ -1391,15 +1306,6 @@ test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
 	struct rte_crypto_asym_xform pub_key_xform;
 	struct rte_crypto_asym_xform xform = *xfrm;
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
-	if (sess == NULL) {
-		RTE_LOG(ERR, USER1,
-				 "line %u FAILED: %s", __LINE__,
-				"Session creation failed");
-		status = TEST_FAILED;
-		goto error_exit;
-	}
-
 	/* set up crypto op data structure */
 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
 	if (!op) {
@@ -1423,11 +1329,12 @@ test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
 	asym_op->dh.pub_key.length = sizeof(out_pub_key);
 	asym_op->dh.priv_key.data = out_prv_key;
 	asym_op->dh.priv_key.length = sizeof(out_prv_key);
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
-			sess_mpool) < 0) {
+
+	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
+	if (sess == NULL) {
 		RTE_LOG(ERR, USER1,
-				"line %u FAILED: %s",
-				__LINE__, "unabled to config sym session");
+				"line %u FAILED: %s", __LINE__,
+				"Session creation failed");
 		status = TEST_FAILED;
 		goto error_exit;
 	}
@@ -1462,10 +1369,8 @@ test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
 			out_pub_key, asym_op->dh.pub_key.length);
 
 error_exit:
-	if (sess != NULL) {
-		rte_cryptodev_asym_session_clear(dev_id, sess);
-		rte_cryptodev_asym_session_free(sess);
-	}
+	if (sess != NULL)
+		rte_cryptodev_asym_session_free(dev_id, sess);
 	if (op != NULL)
 		rte_crypto_op_free(op);
 
@@ -1514,7 +1419,7 @@ test_mod_inv(void)
 				return TEST_SKIPPED;
 		}
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
+	sess = rte_cryptodev_asym_session_create(dev_id, &modinv_xform, sess_mpool);
 	if (!sess) {
 		RTE_LOG(ERR, USER1, "line %u "
 				"FAILED: %s", __LINE__,
@@ -1523,15 +1428,6 @@ test_mod_inv(void)
 		goto error_exit;
 	}
 
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &modinv_xform,
-			sess_mpool) < 0) {
-		RTE_LOG(ERR, USER1,
-				"line %u FAILED: %s",
-				__LINE__, "unabled to config sym session");
-		status = TEST_FAILED;
-		goto error_exit;
-	}
-
 	/* generate crypto op data structure */
 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
 	if (!op) {
@@ -1583,10 +1479,8 @@ test_mod_inv(void)
 	}
 
 error_exit:
-	if (sess) {
-		rte_cryptodev_asym_session_clear(dev_id, sess);
-		rte_cryptodev_asym_session_free(sess);
-	}
+	if (sess)
+		rte_cryptodev_asym_session_free(dev_id, sess);
 
 	if (op)
 		rte_crypto_op_free(op);
@@ -1649,7 +1543,7 @@ test_mod_exp(void)
 		goto error_exit;
 	}
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
+	sess = rte_cryptodev_asym_session_create(dev_id, &modex_xform, sess_mpool);
 	if (!sess) {
 		RTE_LOG(ERR, USER1,
 				 "line %u "
@@ -1659,15 +1553,6 @@ test_mod_exp(void)
 		goto error_exit;
 	}
 
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &modex_xform,
-			sess_mpool) < 0) {
-		RTE_LOG(ERR, USER1,
-				"line %u FAILED: %s",
-				__LINE__, "unabled to config sym session");
-		status = TEST_FAILED;
-		goto error_exit;
-	}
-
 	asym_op = op->asym;
 	memcpy(input, base, sizeof(base));
 	asym_op->modex.base.data = input;
@@ -1706,10 +1591,8 @@ test_mod_exp(void)
 	}
 
 error_exit:
-	if (sess != NULL) {
-		rte_cryptodev_asym_session_clear(dev_id, sess);
-		rte_cryptodev_asym_session_free(sess);
-	}
+	if (sess != NULL)
+		rte_cryptodev_asym_session_free(dev_id, sess);
 
 	if (op != NULL)
 		rte_crypto_op_free(op);
@@ -1771,7 +1654,7 @@ test_dsa_sign(void)
 	uint8_t s[TEST_DH_MOD_LEN];
 	uint8_t dgst[] = "35d81554afaad2cf18f3a1770d5fedc4ea5be344";
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
+	sess = rte_cryptodev_asym_session_create(dev_id, &dsa_xform, sess_mpool);
 	if (sess == NULL) {
 		RTE_LOG(ERR, USER1,
 				 "line %u FAILED: %s", __LINE__,
@@ -1800,15 +1683,6 @@ test_dsa_sign(void)
 	debug_hexdump(stdout, "priv_key: ", dsa_xform.dsa.x.data,
 			dsa_xform.dsa.x.length);
 
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &dsa_xform,
-				sess_mpool) < 0) {
-		RTE_LOG(ERR, USER1,
-				"line %u FAILED: %s",
-				__LINE__, "unabled to config sym session");
-		status = TEST_FAILED;
-		goto error_exit;
-	}
-
 	/* attach asymmetric crypto session to crypto operations */
 	rte_crypto_op_attach_asym_session(op, sess);
 	asym_op->dsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
@@ -1882,10 +1756,8 @@ test_dsa_sign(void)
 		status = TEST_FAILED;
 	}
 error_exit:
-	if (sess != NULL) {
-		rte_cryptodev_asym_session_clear(dev_id, sess);
-		rte_cryptodev_asym_session_free(sess);
-	}
+	if (sess != NULL)
+		rte_cryptodev_asym_session_free(dev_id, sess);
 	if (op != NULL)
 		rte_crypto_op_free(op);
 	return status;
@@ -1944,15 +1816,6 @@ test_ecdsa_sign_verify(enum curve curve_id)
 
 	rte_cryptodev_info_get(dev_id, &dev_info);
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
-	if (sess == NULL) {
-		RTE_LOG(ERR, USER1,
-				"line %u FAILED: %s", __LINE__,
-				"Session creation failed\n");
-		status = TEST_FAILED;
-		goto exit;
-	}
-
 	/* Setup crypto op data structure */
 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
 	if (op == NULL) {
@@ -1970,11 +1833,11 @@ test_ecdsa_sign_verify(enum curve curve_id)
 	xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDSA;
 	xform.ec.curve_id = input_params.curve;
 
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
-				sess_mpool) < 0) {
+	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
+	if (sess == NULL) {
 		RTE_LOG(ERR, USER1,
 				"line %u FAILED: %s", __LINE__,
-				"Unable to config asym session\n");
+				"Session creation failed\n");
 		status = TEST_FAILED;
 		goto exit;
 	}
@@ -2082,10 +1945,8 @@ test_ecdsa_sign_verify(enum curve curve_id)
 	}
 
 exit:
-	if (sess != NULL) {
-		rte_cryptodev_asym_session_clear(dev_id, sess);
-		rte_cryptodev_asym_session_free(sess);
-	}
+	if (sess != NULL)
+		rte_cryptodev_asym_session_free(dev_id, sess);
 	if (op != NULL)
 		rte_crypto_op_free(op);
 	return status;
@@ -2157,15 +2018,6 @@ test_ecpm(enum curve curve_id)
 
 	rte_cryptodev_info_get(dev_id, &dev_info);
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
-	if (sess == NULL) {
-		RTE_LOG(ERR, USER1,
-				"line %u FAILED: %s", __LINE__,
-				"Session creation failed\n");
-		status = TEST_FAILED;
-		goto exit;
-	}
-
 	/* Setup crypto op data structure */
 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
 	if (op == NULL) {
@@ -2183,11 +2035,11 @@ test_ecpm(enum curve curve_id)
 	xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECPM;
 	xform.ec.curve_id = input_params.curve;
 
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
-				sess_mpool) < 0) {
+	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
+	if (sess == NULL) {
 		RTE_LOG(ERR, USER1,
 				"line %u FAILED: %s", __LINE__,
-				"Unable to config asym session\n");
+				"Session creation failed\n");
 		status = TEST_FAILED;
 		goto exit;
 	}
@@ -2255,10 +2107,8 @@ test_ecpm(enum curve curve_id)
 	}
 
 exit:
-	if (sess != NULL) {
-		rte_cryptodev_asym_session_clear(dev_id, sess);
-		rte_cryptodev_asym_session_free(sess);
-	}
+	if (sess != NULL)
+		rte_cryptodev_asym_session_free(dev_id, sess);
 	if (op != NULL)
 		rte_crypto_op_free(op);
 	return status;
diff --git a/doc/guides/prog_guide/cryptodev_lib.rst b/doc/guides/prog_guide/cryptodev_lib.rst
index 9f33f7a177..b4dbd384bf 100644
--- a/doc/guides/prog_guide/cryptodev_lib.rst
+++ b/doc/guides/prog_guide/cryptodev_lib.rst
@@ -1038,20 +1038,17 @@ It is the application's responsibility to create and manage the session mempools
 Application using both symmetric and asymmetric sessions should allocate and maintain
 different sessions pools for each type.
 
-An application can use ``rte_cryptodev_get_asym_session_private_size()`` to
-get the private size of asymmetric session on a given crypto device. This
-function would allow an application to calculate the max device asymmetric
-session size of all crypto devices to create a single session mempool.
-If instead an application creates multiple asymmetric session mempools,
-the Crypto device framework also provides ``rte_cryptodev_asym_get_header_session_size()`` to get
-the size of an uninitialized session.
+An application can use ``rte_cryptodev_asym_session_pool_create()`` to create a mempool
+with a specified number of elements. The element size will allow for the session header,
+and the max private session size.
+The max private session size is chosen based on available crypto devices,
+the biggest private session size is used. This means any of those devices can be used,
+and the mempool element will have available space for its private session data.
 
 Once the session mempools have been created, ``rte_cryptodev_asym_session_create()``
-is used to allocate an uninitialized asymmetric session from the given mempool.
-The session then must be initialized using ``rte_cryptodev_asym_session_init()``
-for each of the required crypto devices. An asymmetric transform chain
-is used to specify the operation and its parameters. See the section below for
-details on transforms.
+is used to allocate and initialize an asymmetric session from the given mempool.
+An asymmetric transform chain is used to specify the operation and its parameters.
+See the section below for details on transforms.
 
 When a session is no longer used, user must call ``rte_cryptodev_asym_session_clear()``
 for each of the crypto devices that are using the session, to free all driver
diff --git a/doc/guides/rel_notes/release_22_03.rst b/doc/guides/rel_notes/release_22_03.rst
index a820cc5596..ea4c5309a0 100644
--- a/doc/guides/rel_notes/release_22_03.rst
+++ b/doc/guides/rel_notes/release_22_03.rst
@@ -112,6 +112,13 @@ API Changes
 * ethdev: Old public macros and enumeration constants without ``RTE_ETH_`` prefix,
   which are kept for backward compatibility, are marked as deprecated.
 
+* cryptodev: The asymmetric session handling was modified to use a single
+  mempool object. An API ``rte_cryptodev_asym_session_pool_create`` was added
+  to create a mempool with element size big enough to hold the generic asymmetric
+  session header and max size for a device private session data.
+  The API ``rte_cryptodev_asym_session_init`` was removed as the initialization
+  is now moved to ``rte_cryptodev_asym_session_create``.
+
 
 ABI Changes
 -----------
diff --git a/drivers/crypto/cnxk/cn10k_cryptodev_ops.c b/drivers/crypto/cnxk/cn10k_cryptodev_ops.c
index d217bbf383..c4d5d039ec 100644
--- a/drivers/crypto/cnxk/cn10k_cryptodev_ops.c
+++ b/drivers/crypto/cnxk/cn10k_cryptodev_ops.c
@@ -157,8 +157,8 @@ cn10k_cpt_fill_inst(struct cnxk_cpt_qp *qp, struct rte_crypto_op *ops[],
 
 		if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
 			asym_op = op->asym;
-			ae_sess = get_asym_session_private_data(
-				asym_op->session, cn10k_cryptodev_driver_id);
+			ae_sess = (struct cnxk_ae_sess *)
+					asym_op->session->sess_private_data;
 			ret = cnxk_ae_enqueue(qp, op, infl_req, &inst[0],
 					      ae_sess);
 			if (unlikely(ret))
@@ -431,8 +431,8 @@ cn10k_cpt_dequeue_post_process(struct cnxk_cpt_qp *qp,
 			uintptr_t *mdata = infl_req->mdata;
 			struct cnxk_ae_sess *sess;
 
-			sess = get_asym_session_private_data(
-				op->session, cn10k_cryptodev_driver_id);
+			sess = (struct cnxk_ae_sess *)
+					op->session->sess_private_data;
 
 			cnxk_ae_post_process(cop, sess, (uint8_t *)mdata[0]);
 		}
diff --git a/drivers/crypto/cnxk/cn9k_cryptodev_ops.c b/drivers/crypto/cnxk/cn9k_cryptodev_ops.c
index ac1953b66d..b8ad4bf211 100644
--- a/drivers/crypto/cnxk/cn9k_cryptodev_ops.c
+++ b/drivers/crypto/cnxk/cn9k_cryptodev_ops.c
@@ -138,8 +138,8 @@ cn9k_cpt_inst_prep(struct cnxk_cpt_qp *qp, struct rte_crypto_op *op,
 
 		if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
 			asym_op = op->asym;
-			sess = get_asym_session_private_data(
-				asym_op->session, cn9k_cryptodev_driver_id);
+			sess = (struct cnxk_ae_sess *)
+					asym_op->session->sess_private_data;
 			ret = cnxk_ae_enqueue(qp, op, infl_req, inst, sess);
 			inst->w7.u64 = sess->cpt_inst_w7;
 		} else {
@@ -453,8 +453,8 @@ cn9k_cpt_dequeue_post_process(struct cnxk_cpt_qp *qp, struct rte_crypto_op *cop,
 			uintptr_t *mdata = infl_req->mdata;
 			struct cnxk_ae_sess *sess;
 
-			sess = get_asym_session_private_data(
-				op->session, cn9k_cryptodev_driver_id);
+			sess = (struct cnxk_ae_sess *)
+					op->session->sess_private_data;
 
 			cnxk_ae_post_process(cop, sess, (uint8_t *)mdata[0]);
 		}
diff --git a/drivers/crypto/cnxk/cnxk_cryptodev_ops.c b/drivers/crypto/cnxk/cnxk_cryptodev_ops.c
index a5fb68da02..72f5f1a6fe 100644
--- a/drivers/crypto/cnxk/cnxk_cryptodev_ops.c
+++ b/drivers/crypto/cnxk/cnxk_cryptodev_ops.c
@@ -658,10 +658,9 @@ void
 cnxk_ae_session_clear(struct rte_cryptodev *dev,
 		      struct rte_cryptodev_asym_session *sess)
 {
-	struct rte_mempool *sess_mp;
 	struct cnxk_ae_sess *priv;
 
-	priv = get_asym_session_private_data(sess, dev->driver_id);
+	priv = (struct cnxk_ae_sess *) sess->sess_private_data;
 	if (priv == NULL)
 		return;
 
@@ -670,40 +669,29 @@ cnxk_ae_session_clear(struct rte_cryptodev *dev,
 
 	/* Reset and free object back to pool */
 	memset(priv, 0, cnxk_ae_session_size_get(dev));
-	sess_mp = rte_mempool_from_obj(priv);
-	set_asym_session_private_data(sess, dev->driver_id, NULL);
-	rte_mempool_put(sess_mp, priv);
 }
 
 int
 cnxk_ae_session_cfg(struct rte_cryptodev *dev,
 		    struct rte_crypto_asym_xform *xform,
-		    struct rte_cryptodev_asym_session *sess,
-		    struct rte_mempool *pool)
+		    struct rte_cryptodev_asym_session *sess)
 {
 	struct cnxk_cpt_vf *vf = dev->data->dev_private;
 	struct roc_cpt *roc_cpt = &vf->cpt;
-	struct cnxk_ae_sess *priv;
+	struct cnxk_ae_sess *priv =
+			(struct cnxk_ae_sess *) sess->sess_private_data;
 	union cpt_inst_w7 w7;
 	int ret;
 
-	if (rte_mempool_get(pool, (void **)&priv))
-		return -ENOMEM;
-
-	memset(priv, 0, sizeof(struct cnxk_ae_sess));
-
 	ret = cnxk_ae_fill_session_parameters(priv, xform);
-	if (ret) {
-		rte_mempool_put(pool, priv);
+	if (ret)
 		return ret;
-	}
 
 	w7.u64 = 0;
 	w7.s.egrp = roc_cpt->eng_grp[CPT_ENG_TYPE_AE];
 	priv->cpt_inst_w7 = w7.u64;
 	priv->cnxk_fpm_iova = vf->cnxk_fpm_iova;
 	priv->ec_grp = vf->ec_grp;
-	set_asym_session_private_data(sess, dev->driver_id, priv);
 
 	return 0;
 }
diff --git a/drivers/crypto/cnxk/cnxk_cryptodev_ops.h b/drivers/crypto/cnxk/cnxk_cryptodev_ops.h
index 0656ba9675..ab0f00ee7c 100644
--- a/drivers/crypto/cnxk/cnxk_cryptodev_ops.h
+++ b/drivers/crypto/cnxk/cnxk_cryptodev_ops.h
@@ -122,8 +122,7 @@ void cnxk_ae_session_clear(struct rte_cryptodev *dev,
 			   struct rte_cryptodev_asym_session *sess);
 int cnxk_ae_session_cfg(struct rte_cryptodev *dev,
 			struct rte_crypto_asym_xform *xform,
-			struct rte_cryptodev_asym_session *sess,
-			struct rte_mempool *pool);
+			struct rte_cryptodev_asym_session *sess);
 void cnxk_cpt_dump_on_err(struct cnxk_cpt_qp *qp);
 
 static inline union rte_event_crypto_metadata *
diff --git a/drivers/crypto/octeontx/otx_cryptodev_ops.c b/drivers/crypto/octeontx/otx_cryptodev_ops.c
index f7ca8a8a8e..0cb6dbb38c 100644
--- a/drivers/crypto/octeontx/otx_cryptodev_ops.c
+++ b/drivers/crypto/octeontx/otx_cryptodev_ops.c
@@ -375,35 +375,24 @@ otx_cpt_asym_session_size_get(struct rte_cryptodev *dev __rte_unused)
 }
 
 static int
-otx_cpt_asym_session_cfg(struct rte_cryptodev *dev,
+otx_cpt_asym_session_cfg(struct rte_cryptodev *dev __rte_unused,
 			 struct rte_crypto_asym_xform *xform __rte_unused,
-			 struct rte_cryptodev_asym_session *sess,
-			 struct rte_mempool *pool)
+			 struct rte_cryptodev_asym_session *sess)
 {
-	struct cpt_asym_sess_misc *priv;
+	struct cpt_asym_sess_misc *priv = (struct cpt_asym_sess_misc *)
+			sess->sess_private_data;
 	int ret;
 
 	CPT_PMD_INIT_FUNC_TRACE();
 
-	if (rte_mempool_get(pool, (void **)&priv)) {
-		CPT_LOG_ERR("Could not allocate session private data");
-		return -ENOMEM;
-	}
-
-	memset(priv, 0, sizeof(struct cpt_asym_sess_misc));
-
 	ret = cpt_fill_asym_session_parameters(priv, xform);
 	if (ret) {
 		CPT_LOG_ERR("Could not configure session parameters");
-
-		/* Return session to mempool */
-		rte_mempool_put(pool, priv);
 		return ret;
 	}
 
 	priv->cpt_inst_w7 = 0;
 
-	set_asym_session_private_data(sess, dev->driver_id, priv);
 	return 0;
 }
 
@@ -412,11 +401,10 @@ otx_cpt_asym_session_clear(struct rte_cryptodev *dev,
 			   struct rte_cryptodev_asym_session *sess)
 {
 	struct cpt_asym_sess_misc *priv;
-	struct rte_mempool *sess_mp;
 
 	CPT_PMD_INIT_FUNC_TRACE();
 
-	priv = get_asym_session_private_data(sess, dev->driver_id);
+	priv = (struct cpt_asym_sess_misc *) sess->sess_private_data;
 
 	if (priv == NULL)
 		return;
@@ -424,9 +412,6 @@ otx_cpt_asym_session_clear(struct rte_cryptodev *dev,
 	/* Free resources allocated during session configure */
 	cpt_free_asym_session_parameters(priv);
 	memset(priv, 0, otx_cpt_asym_session_size_get(dev));
-	sess_mp = rte_mempool_from_obj(priv);
-	set_asym_session_private_data(sess, dev->driver_id, NULL);
-	rte_mempool_put(sess_mp, priv);
 }
 
 static __rte_always_inline void * __rte_hot
@@ -471,8 +456,8 @@ otx_cpt_enq_single_asym(struct cpt_instance *instance,
 		return NULL;
 	}
 
-	sess = get_asym_session_private_data(asym_op->session,
-					     otx_cryptodev_driver_id);
+	sess = (struct cpt_asym_sess_misc *)
+			asym_op->session->sess_private_data;
 
 	/* Store phys_addr of the mdata to meta_buf */
 	params.meta_buf = rte_mempool_virt2iova(mdata);
@@ -852,8 +837,7 @@ otx_cpt_asym_post_process(struct rte_crypto_op *cop,
 	struct rte_crypto_asym_op *op = cop->asym;
 	struct cpt_asym_sess_misc *sess;
 
-	sess = get_asym_session_private_data(op->session,
-					     otx_cryptodev_driver_id);
+	sess = (struct cpt_asym_sess_misc *) op->session->sess_private_data;
 
 	switch (sess->xfrm_type) {
 	case RTE_CRYPTO_ASYM_XFORM_RSA:
diff --git a/drivers/crypto/openssl/rte_openssl_pmd.c b/drivers/crypto/openssl/rte_openssl_pmd.c
index 5794ed8159..d80e1052e2 100644
--- a/drivers/crypto/openssl/rte_openssl_pmd.c
+++ b/drivers/crypto/openssl/rte_openssl_pmd.c
@@ -748,9 +748,7 @@ get_session(struct openssl_qp *qp, struct rte_crypto_op *op)
 		} else {
 			if (likely(op->asym->session != NULL))
 				asym_sess = (struct openssl_asym_session *)
-						get_asym_session_private_data(
-						op->asym->session,
-						cryptodev_driver_id);
+						op->asym->session->sess_private_data;
 			if (asym_sess == NULL)
 				op->status =
 					RTE_CRYPTO_OP_STATUS_INVALID_SESSION;
diff --git a/drivers/crypto/openssl/rte_openssl_pmd_ops.c b/drivers/crypto/openssl/rte_openssl_pmd_ops.c
index 52715f86f8..556fd226ed 100644
--- a/drivers/crypto/openssl/rte_openssl_pmd_ops.c
+++ b/drivers/crypto/openssl/rte_openssl_pmd_ops.c
@@ -1119,8 +1119,7 @@ static int openssl_set_asym_session_parameters(
 static int
 openssl_pmd_asym_session_configure(struct rte_cryptodev *dev __rte_unused,
 		struct rte_crypto_asym_xform *xform,
-		struct rte_cryptodev_asym_session *sess,
-		struct rte_mempool *mempool)
+		struct rte_cryptodev_asym_session *sess)
 {
 	void *asym_sess_private_data;
 	int ret;
@@ -1130,25 +1129,14 @@ openssl_pmd_asym_session_configure(struct rte_cryptodev *dev __rte_unused,
 		return -EINVAL;
 	}
 
-	if (rte_mempool_get(mempool, &asym_sess_private_data)) {
-		CDEV_LOG_ERR(
-			"Couldn't get object from session mempool");
-		return -ENOMEM;
-	}
-
+	asym_sess_private_data = sess->sess_private_data;
 	ret = openssl_set_asym_session_parameters(asym_sess_private_data,
 			xform);
 	if (ret != 0) {
 		OPENSSL_LOG(ERR, "failed configure session parameters");
-
-		/* Return session to mempool */
-		rte_mempool_put(mempool, asym_sess_private_data);
 		return ret;
 	}
 
-	set_asym_session_private_data(sess, dev->driver_id,
-			asym_sess_private_data);
-
 	return 0;
 }
 
@@ -1206,19 +1194,15 @@ static void openssl_reset_asym_session(struct openssl_asym_session *sess)
  * so it doesn't leave key material behind
  */
 static void
-openssl_pmd_asym_session_clear(struct rte_cryptodev *dev,
+openssl_pmd_asym_session_clear(struct rte_cryptodev *dev __rte_unused,
 		struct rte_cryptodev_asym_session *sess)
 {
-	uint8_t index = dev->driver_id;
-	void *sess_priv = get_asym_session_private_data(sess, index);
+	void *sess_priv = sess->sess_private_data;
 
 	/* Zero out the whole structure */
 	if (sess_priv) {
 		openssl_reset_asym_session(sess_priv);
 		memset(sess_priv, 0, sizeof(struct openssl_asym_session));
-		struct rte_mempool *sess_mp = rte_mempool_from_obj(sess_priv);
-		set_asym_session_private_data(sess, index, NULL);
-		rte_mempool_put(sess_mp, sess_priv);
 	}
 }
 
diff --git a/drivers/crypto/qat/qat_asym.c b/drivers/crypto/qat/qat_asym.c
index 09d8761c5f..f46eefd4b3 100644
--- a/drivers/crypto/qat/qat_asym.c
+++ b/drivers/crypto/qat/qat_asym.c
@@ -492,8 +492,7 @@ qat_asym_build_request(void *in_op,
 	op->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
 	if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
 		ctx = (struct qat_asym_session *)
-			get_asym_session_private_data(
-			op->asym->session, qat_asym_driver_id);
+				op->asym->session->sess_private_data;
 		if (unlikely(ctx == NULL)) {
 			QAT_LOG(ERR, "Session has not been created for this device");
 			goto error;
@@ -711,8 +710,8 @@ qat_asym_process_response(void **op, uint8_t *resp,
 	}
 
 	if (rx_op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
-		ctx = (struct qat_asym_session *)get_asym_session_private_data(
-			rx_op->asym->session, qat_asym_driver_id);
+		ctx = (struct qat_asym_session *)
+				rx_op->asym->session->sess_private_data;
 		qat_asym_collect_response(rx_op, cookie, ctx->xform);
 	} else if (rx_op->sess_type == RTE_CRYPTO_OP_SESSIONLESS) {
 		qat_asym_collect_response(rx_op, cookie, rx_op->asym->xform);
@@ -726,61 +725,42 @@ qat_asym_process_response(void **op, uint8_t *resp,
 }
 
 int
-qat_asym_session_configure(struct rte_cryptodev *dev,
+qat_asym_session_configure(struct rte_cryptodev *dev __rte_unused,
 		struct rte_crypto_asym_xform *xform,
-		struct rte_cryptodev_asym_session *sess,
-		struct rte_mempool *mempool)
+		struct rte_cryptodev_asym_session *sess)
 {
-	int err = 0;
-	void *sess_private_data;
 	struct qat_asym_session *session;
 
-	if (rte_mempool_get(mempool, &sess_private_data)) {
-		QAT_LOG(ERR,
-			"Couldn't get object from session mempool");
-		return -ENOMEM;
-	}
-
-	session = sess_private_data;
+	session = (struct qat_asym_session *) sess->sess_private_data;
 	if (xform->xform_type == RTE_CRYPTO_ASYM_XFORM_MODEX) {
 		if (xform->modex.exponent.length == 0 ||
 				xform->modex.modulus.length == 0) {
 			QAT_LOG(ERR, "Invalid mod exp input parameter");
-			err = -EINVAL;
-			goto error;
+			return -EINVAL;
 		}
 	} else if (xform->xform_type == RTE_CRYPTO_ASYM_XFORM_MODINV) {
 		if (xform->modinv.modulus.length == 0) {
 			QAT_LOG(ERR, "Invalid mod inv input parameter");
-			err = -EINVAL;
-			goto error;
+			return -EINVAL;
 		}
 	} else if (xform->xform_type == RTE_CRYPTO_ASYM_XFORM_RSA) {
 		if (xform->rsa.n.length == 0) {
 			QAT_LOG(ERR, "Invalid rsa input parameter");
-			err = -EINVAL;
-			goto error;
+			return -EINVAL;
 		}
 	} else if (xform->xform_type >= RTE_CRYPTO_ASYM_XFORM_TYPE_LIST_END
 			|| xform->xform_type <= RTE_CRYPTO_ASYM_XFORM_NONE) {
 		QAT_LOG(ERR, "Invalid asymmetric crypto xform");
-		err = -EINVAL;
-		goto error;
+		return -EINVAL;
 	} else {
 		QAT_LOG(ERR, "Asymmetric crypto xform not implemented");
-		err = -EINVAL;
-		goto error;
+		return -EINVAL;
 	}
 
 	session->xform = xform;
-	qat_asym_build_req_tmpl(sess_private_data);
-	set_asym_session_private_data(sess, dev->driver_id,
-		sess_private_data);
+	qat_asym_build_req_tmpl(session);
 
 	return 0;
-error:
-	rte_mempool_put(mempool, sess_private_data);
-	return err;
 }
 
 unsigned int qat_asym_session_get_private_size(
@@ -793,15 +773,9 @@ void
 qat_asym_session_clear(struct rte_cryptodev *dev,
 		struct rte_cryptodev_asym_session *sess)
 {
-	uint8_t index = dev->driver_id;
-	void *sess_priv = get_asym_session_private_data(sess, index);
+	void *sess_priv = sess->sess_private_data;
 	struct qat_asym_session *s = (struct qat_asym_session *)sess_priv;
 
-	if (sess_priv) {
+	if (sess_priv)
 		memset(s, 0, qat_asym_session_get_private_size(dev));
-		struct rte_mempool *sess_mp = rte_mempool_from_obj(sess_priv);
-
-		set_asym_session_private_data(sess, index, NULL);
-		rte_mempool_put(sess_mp, sess_priv);
-	}
 }
diff --git a/drivers/crypto/qat/qat_asym.h b/drivers/crypto/qat/qat_asym.h
index 308b6b2e0b..c9242a12ca 100644
--- a/drivers/crypto/qat/qat_asym.h
+++ b/drivers/crypto/qat/qat_asym.h
@@ -46,10 +46,9 @@ struct qat_asym_session {
 };
 
 int
-qat_asym_session_configure(struct rte_cryptodev *dev,
+qat_asym_session_configure(struct rte_cryptodev *dev __rte_unused,
 		struct rte_crypto_asym_xform *xform,
-		struct rte_cryptodev_asym_session *sess,
-		struct rte_mempool *mempool);
+		struct rte_cryptodev_asym_session *sess);
 
 unsigned int
 qat_asym_session_get_private_size(struct rte_cryptodev *dev);
diff --git a/lib/cryptodev/cryptodev_pmd.h b/lib/cryptodev/cryptodev_pmd.h
index b9146f652c..142bfb7c66 100644
--- a/lib/cryptodev/cryptodev_pmd.h
+++ b/lib/cryptodev/cryptodev_pmd.h
@@ -319,7 +319,6 @@ typedef int (*cryptodev_sym_configure_session_t)(struct rte_cryptodev *dev,
  * @param	dev		Crypto device pointer
  * @param	xform		Single or chain of crypto xforms
  * @param	session		Pointer to cryptodev's private session structure
- * @param	mp		Mempool where the private session is allocated
  *
  * @return
  *  - Returns 0 if private session structure have been created successfully.
@@ -329,8 +328,7 @@ typedef int (*cryptodev_sym_configure_session_t)(struct rte_cryptodev *dev,
  */
 typedef int (*cryptodev_asym_configure_session_t)(struct rte_cryptodev *dev,
 		struct rte_crypto_asym_xform *xform,
-		struct rte_cryptodev_asym_session *session,
-		struct rte_mempool *mp);
+		struct rte_cryptodev_asym_session *session);
 /**
  * Free driver private session data.
  *
@@ -340,12 +338,12 @@ typedef int (*cryptodev_asym_configure_session_t)(struct rte_cryptodev *dev,
 typedef void (*cryptodev_sym_free_session_t)(struct rte_cryptodev *dev,
 		struct rte_cryptodev_sym_session *sess);
 /**
- * Free asymmetric session private data.
+ * Clear asymmetric session private data.
  *
  * @param	dev		Crypto device pointer
  * @param	sess		Cryptodev session structure
  */
-typedef void (*cryptodev_asym_free_session_t)(struct rte_cryptodev *dev,
+typedef void (*cryptodev_asym_clear_session_t)(struct rte_cryptodev *dev,
 		struct rte_cryptodev_asym_session *sess);
 /**
  * Perform actual crypto processing (encrypt/digest or auth/decrypt)
@@ -429,7 +427,7 @@ struct rte_cryptodev_ops {
 	/**< Configure asymmetric Crypto session. */
 	cryptodev_sym_free_session_t sym_session_clear;
 	/**< Clear a Crypto sessions private data. */
-	cryptodev_asym_free_session_t asym_session_clear;
+	cryptodev_asym_clear_session_t asym_session_clear;
 	/**< Clear a Crypto sessions private data. */
 	union {
 		cryptodev_sym_cpu_crypto_process_t sym_cpu_process;
@@ -627,17 +625,4 @@ set_sym_session_private_data(struct rte_cryptodev_sym_session *sess,
 	sess->sess_data[driver_id].data = private_data;
 }
 
-static inline void *
-get_asym_session_private_data(const struct rte_cryptodev_asym_session *sess,
-		uint8_t driver_id) {
-	return sess->sess_private_data[driver_id];
-}
-
-static inline void
-set_asym_session_private_data(struct rte_cryptodev_asym_session *sess,
-		uint8_t driver_id, void *private_data)
-{
-	sess->sess_private_data[driver_id] = private_data;
-}
-
 #endif /* _CRYPTODEV_PMD_H_ */
diff --git a/lib/cryptodev/cryptodev_trace_points.c b/lib/cryptodev/cryptodev_trace_points.c
index 5d58951fd5..c5bfe08b79 100644
--- a/lib/cryptodev/cryptodev_trace_points.c
+++ b/lib/cryptodev/cryptodev_trace_points.c
@@ -24,6 +24,9 @@ RTE_TRACE_POINT_REGISTER(rte_cryptodev_trace_queue_pair_setup,
 RTE_TRACE_POINT_REGISTER(rte_cryptodev_trace_sym_session_pool_create,
 	lib.cryptodev.sym.pool.create)
 
+RTE_TRACE_POINT_REGISTER(rte_cryptodev_trace_asym_session_pool_create,
+	lib.cryptodev.asym.pool.create)
+
 RTE_TRACE_POINT_REGISTER(rte_cryptodev_trace_sym_session_create,
 	lib.cryptodev.sym.create)
 
@@ -39,15 +42,9 @@ RTE_TRACE_POINT_REGISTER(rte_cryptodev_trace_asym_session_free,
 RTE_TRACE_POINT_REGISTER(rte_cryptodev_trace_sym_session_init,
 	lib.cryptodev.sym.init)
 
-RTE_TRACE_POINT_REGISTER(rte_cryptodev_trace_asym_session_init,
-	lib.cryptodev.asym.init)
-
 RTE_TRACE_POINT_REGISTER(rte_cryptodev_trace_sym_session_clear,
 	lib.cryptodev.sym.clear)
 
-RTE_TRACE_POINT_REGISTER(rte_cryptodev_trace_asym_session_clear,
-	lib.cryptodev.asym.clear)
-
 RTE_TRACE_POINT_REGISTER(rte_cryptodev_trace_enqueue_burst,
 	lib.cryptodev.enq.burst)
 
diff --git a/lib/cryptodev/rte_cryptodev.c b/lib/cryptodev/rte_cryptodev.c
index a40536c5ea..b056d88ac2 100644
--- a/lib/cryptodev/rte_cryptodev.c
+++ b/lib/cryptodev/rte_cryptodev.c
@@ -195,7 +195,7 @@ const char *rte_crypto_asym_op_strings[] = {
 };
 
 /**
- * The private data structure stored in the session mempool private data.
+ * The private data structure stored in the sym session mempool private data.
  */
 struct rte_cryptodev_sym_session_pool_private_data {
 	uint16_t nb_drivers;
@@ -204,6 +204,14 @@ struct rte_cryptodev_sym_session_pool_private_data {
 	/**< session user data will be placed after sess_data */
 };
 
+/**
+ * The private data structure stored in the asym session mempool private data.
+ */
+struct rte_cryptodev_asym_session_pool_private_data {
+	uint16_t max_priv_session_sz;
+	/**< Size of private session data used when creating mempool */
+};
+
 int
 rte_cryptodev_get_cipher_algo_enum(enum rte_crypto_cipher_algorithm *algo_enum,
 		const char *algo_string)
@@ -1751,47 +1759,6 @@ rte_cryptodev_sym_session_init(uint8_t dev_id,
 	return 0;
 }
 
-int
-rte_cryptodev_asym_session_init(uint8_t dev_id,
-		struct rte_cryptodev_asym_session *sess,
-		struct rte_crypto_asym_xform *xforms,
-		struct rte_mempool *mp)
-{
-	struct rte_cryptodev *dev;
-	uint8_t index;
-	int ret;
-
-	if (!rte_cryptodev_is_valid_dev(dev_id)) {
-		CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
-		return -EINVAL;
-	}
-
-	dev = rte_cryptodev_pmd_get_dev(dev_id);
-
-	if (sess == NULL || xforms == NULL || dev == NULL)
-		return -EINVAL;
-
-	index = dev->driver_id;
-
-	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->asym_session_configure,
-				-ENOTSUP);
-
-	if (sess->sess_private_data[index] == NULL) {
-		ret = dev->dev_ops->asym_session_configure(dev,
-							xforms,
-							sess, mp);
-		if (ret < 0) {
-			CDEV_LOG_ERR(
-				"dev_id %d failed to configure session details",
-				dev_id);
-			return ret;
-		}
-	}
-
-	rte_cryptodev_trace_asym_session_init(dev_id, sess, xforms, mp);
-	return 0;
-}
-
 struct rte_mempool *
 rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
 	uint32_t elt_size, uint32_t cache_size, uint16_t user_data_size,
@@ -1834,6 +1801,53 @@ rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
 	return mp;
 }
 
+struct rte_mempool *
+rte_cryptodev_asym_session_pool_create(const char *name, uint32_t nb_elts,
+	uint32_t cache_size, int socket_id)
+{
+	struct rte_mempool *mp;
+	struct rte_cryptodev_asym_session_pool_private_data *pool_priv;
+	uint32_t obj_sz, obj_sz_aligned;
+	uint8_t dev_id, priv_sz, max_priv_sz = 0;
+
+	for (dev_id = 0; dev_id < RTE_CRYPTO_MAX_DEVS; dev_id++)
+		if (rte_cryptodev_is_valid_dev(dev_id)) {
+			priv_sz = rte_cryptodev_asym_get_private_session_size(dev_id);
+			if (priv_sz > max_priv_sz)
+				max_priv_sz = priv_sz;
+		}
+	if (max_priv_sz == 0) {
+		CDEV_LOG_INFO("Could not set max private session size\n");
+		return NULL;
+	}
+
+	obj_sz = rte_cryptodev_asym_get_header_session_size() + max_priv_sz;
+	obj_sz_aligned =  RTE_ALIGN_CEIL(obj_sz, RTE_CACHE_LINE_SIZE);
+
+	mp = rte_mempool_create(name, nb_elts, obj_sz_aligned, cache_size,
+			(uint32_t)(sizeof(*pool_priv)),
+			NULL, NULL, NULL, NULL,
+			socket_id, 0);
+	if (mp == NULL) {
+		CDEV_LOG_ERR("%s(name=%s) failed, rte_errno=%d\n",
+			__func__, name, rte_errno);
+		return NULL;
+	}
+
+	pool_priv = rte_mempool_get_priv(mp);
+	if (!pool_priv) {
+		CDEV_LOG_ERR("%s(name=%s) failed to get private data\n",
+			__func__, name);
+		rte_mempool_free(mp);
+		return NULL;
+	}
+	pool_priv->max_priv_session_sz = max_priv_sz;
+
+	rte_cryptodev_trace_asym_session_pool_create(name, nb_elts,
+		cache_size, mp);
+	return mp;
+}
+
 static unsigned int
 rte_cryptodev_sym_session_data_size(struct rte_cryptodev_sym_session *sess)
 {
@@ -1895,19 +1909,44 @@ rte_cryptodev_sym_session_create(struct rte_mempool *mp)
 }
 
 struct rte_cryptodev_asym_session *
-rte_cryptodev_asym_session_create(struct rte_mempool *mp)
+rte_cryptodev_asym_session_create(uint8_t dev_id,
+		struct rte_crypto_asym_xform *xforms, struct rte_mempool *mp)
 {
 	struct rte_cryptodev_asym_session *sess;
-	unsigned int session_size =
+	uint32_t session_priv_data_sz;
+	struct rte_cryptodev_asym_session_pool_private_data *pool_priv;
+	unsigned int session_header_size =
 			rte_cryptodev_asym_get_header_session_size();
+	struct rte_cryptodev *dev;
+	int ret;
+
+	if (!rte_cryptodev_is_valid_dev(dev_id)) {
+		CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
+		return NULL;
+	}
+
+	dev = rte_cryptodev_pmd_get_dev(dev_id);
+
+	if (dev == NULL)
+		return NULL;
 
 	if (!mp) {
 		CDEV_LOG_ERR("invalid mempool\n");
 		return NULL;
 	}
 
+	session_priv_data_sz = rte_cryptodev_asym_get_private_session_size(
+			dev_id);
+	pool_priv = rte_mempool_get_priv(mp);
+
+	if (pool_priv->max_priv_session_sz < session_priv_data_sz) {
+		CDEV_LOG_DEBUG(
+			"The private session data size used when creating the mempool is smaller than this device's private session data.");
+		return NULL;
+	}
+
 	/* Verify if provided mempool can hold elements big enough. */
-	if (mp->elt_size < session_size) {
+	if (mp->elt_size < session_header_size + session_priv_data_sz) {
 		CDEV_LOG_ERR(
 			"mempool elements too small to hold session objects");
 		return NULL;
@@ -1919,12 +1958,25 @@ rte_cryptodev_asym_session_create(struct rte_mempool *mp)
 		return NULL;
 	}
 
-	/* Clear device session pointer.
-	 * Include the flag indicating presence of private data
-	 */
-	memset(sess, 0, session_size);
+	sess->driver_id = dev->driver_id;
+	sess->max_priv_data_sz = pool_priv->max_priv_session_sz;
+
+	/* Clear device session pointer.*/
+	memset(sess->sess_private_data, 0, session_priv_data_sz);
+
+	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->asym_session_configure, NULL);
 
-	rte_cryptodev_trace_asym_session_create(mp, sess);
+	if (sess->sess_private_data[0] == 0) {
+		ret = dev->dev_ops->asym_session_configure(dev, xforms, sess);
+		if (ret < 0) {
+			CDEV_LOG_ERR(
+				"dev_id %d failed to configure session details",
+				dev_id);
+			return NULL;
+		}
+	}
+
+	rte_cryptodev_trace_asym_session_create(dev_id, xforms, mp);
 	return sess;
 }
 
@@ -1959,30 +2011,6 @@ rte_cryptodev_sym_session_clear(uint8_t dev_id,
 	return 0;
 }
 
-int
-rte_cryptodev_asym_session_clear(uint8_t dev_id,
-		struct rte_cryptodev_asym_session *sess)
-{
-	struct rte_cryptodev *dev;
-
-	if (!rte_cryptodev_is_valid_dev(dev_id)) {
-		CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
-		return -EINVAL;
-	}
-
-	dev = rte_cryptodev_pmd_get_dev(dev_id);
-
-	if (dev == NULL || sess == NULL)
-		return -EINVAL;
-
-	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->asym_session_clear, -ENOTSUP);
-
-	dev->dev_ops->asym_session_clear(dev, sess);
-
-	rte_cryptodev_trace_sym_session_clear(dev_id, sess);
-	return 0;
-}
-
 int
 rte_cryptodev_sym_session_free(struct rte_cryptodev_sym_session *sess)
 {
@@ -2007,27 +2035,31 @@ rte_cryptodev_sym_session_free(struct rte_cryptodev_sym_session *sess)
 }
 
 int
-rte_cryptodev_asym_session_free(struct rte_cryptodev_asym_session *sess)
+rte_cryptodev_asym_session_free(uint8_t dev_id,
+		struct rte_cryptodev_asym_session *sess)
 {
-	uint8_t i;
-	void *sess_priv;
 	struct rte_mempool *sess_mp;
+	struct rte_cryptodev *dev;
 
-	if (sess == NULL)
+	if (!rte_cryptodev_is_valid_dev(dev_id)) {
+		CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
 		return -EINVAL;
-
-	/* Check that all device private data has been freed */
-	for (i = 0; i < nb_drivers; i++) {
-		sess_priv = get_asym_session_private_data(sess, i);
-		if (sess_priv != NULL)
-			return -EBUSY;
 	}
 
+	dev = rte_cryptodev_pmd_get_dev(dev_id);
+
+	if (dev == NULL || sess == NULL)
+		return -EINVAL;
+
+	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->asym_session_clear, -ENOTSUP);
+
+	dev->dev_ops->asym_session_clear(dev, sess);
+
 	/* Return session to mempool */
 	sess_mp = rte_mempool_from_obj(sess);
 	rte_mempool_put(sess_mp, sess);
 
-	rte_cryptodev_trace_asym_session_free(sess);
+	rte_cryptodev_trace_asym_session_free(dev_id, sess);
 	return 0;
 }
 
@@ -2061,12 +2093,7 @@ rte_cryptodev_sym_get_existing_header_session_size(
 unsigned int
 rte_cryptodev_asym_get_header_session_size(void)
 {
-	/*
-	 * Header contains pointers to the private data
-	 * of all registered drivers, and a flag which
-	 * indicates presence of private data
-	 */
-	return ((sizeof(void *) * nb_drivers) + sizeof(uint8_t));
+	return sizeof(struct rte_cryptodev_asym_session);
 }
 
 unsigned int
@@ -2092,7 +2119,6 @@ unsigned int
 rte_cryptodev_asym_get_private_session_size(uint8_t dev_id)
 {
 	struct rte_cryptodev *dev;
-	unsigned int header_size = sizeof(void *) * nb_drivers;
 	unsigned int priv_sess_size;
 
 	if (!rte_cryptodev_is_valid_dev(dev_id))
@@ -2104,11 +2130,8 @@ rte_cryptodev_asym_get_private_session_size(uint8_t dev_id)
 		return 0;
 
 	priv_sess_size = (*dev->dev_ops->asym_session_get_size)(dev);
-	if (priv_sess_size < header_size)
-		return header_size;
 
 	return priv_sess_size;
-
 }
 
 int
diff --git a/lib/cryptodev/rte_cryptodev.h b/lib/cryptodev/rte_cryptodev.h
index 59ea5a54df..90e764017d 100644
--- a/lib/cryptodev/rte_cryptodev.h
+++ b/lib/cryptodev/rte_cryptodev.h
@@ -919,9 +919,13 @@ struct rte_cryptodev_sym_session {
 };
 
 /** Cryptodev asymmetric crypto session */
-struct rte_cryptodev_asym_session {
-	__extension__ void *sess_private_data[0];
-	/**< Private asymmetric session material */
+RTE_STD_C11 struct rte_cryptodev_asym_session {
+	uint8_t driver_id;
+	/**< Session driver ID. */
+	uint16_t max_priv_data_sz;
+	/**< Size of private data used when creating mempool */
+	uint8_t padding[5];
+	uint8_t sess_private_data[0];
 };
 
 /**
@@ -956,6 +960,29 @@ rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
 	uint32_t elt_size, uint32_t cache_size, uint16_t priv_size,
 	int socket_id);
 
+/**
+ * Create an asymmetric session mempool.
+ *
+ * @param name
+ *   The unique mempool name.
+ * @param nb_elts
+ *   The number of elements in the mempool.
+ * @param cache_size
+ *   The number of per-lcore cache elements
+ * @param socket_id
+ *   The *socket_id* argument is the socket identifier in the case of
+ *   NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA
+ *   constraint for the reserved zone.
+ *
+ * @return
+ *  - On success return mempool
+ *  - On failure returns NULL
+ */
+__rte_experimental
+struct rte_mempool *
+rte_cryptodev_asym_session_pool_create(const char *name, uint32_t nb_elts,
+	uint32_t cache_size, int socket_id);
+
 /**
  * Create symmetric crypto session header (generic with no private data)
  *
@@ -969,17 +996,22 @@ struct rte_cryptodev_sym_session *
 rte_cryptodev_sym_session_create(struct rte_mempool *mempool);
 
 /**
- * Create asymmetric crypto session header (generic with no private data)
+ * Create and initialise an asymmetric crypto session structure.
+ * Calls the PMD to configure the private session data.
  *
- * @param   mempool    mempool to allocate asymmetric session
- *                     objects from
+ * @param   dev_id   ID of device that we want the session to be used on
+ * @param   xforms   Asymmetric crypto transform operations to apply on flow
+ *                   processed with this session
+ * @param   mp       mempool to allocate asymmetric session
+ *                   objects from
  * @return
  *  - On success return pointer to asym-session
  *  - On failure returns NULL
  */
 __rte_experimental
 struct rte_cryptodev_asym_session *
-rte_cryptodev_asym_session_create(struct rte_mempool *mempool);
+rte_cryptodev_asym_session_create(uint8_t dev_id,
+		struct rte_crypto_asym_xform *xforms, struct rte_mempool *mp);
 
 /**
  * Frees symmetric crypto session header, after checking that all
@@ -997,20 +1029,20 @@ int
 rte_cryptodev_sym_session_free(struct rte_cryptodev_sym_session *sess);
 
 /**
- * Frees asymmetric crypto session header, after checking that all
- * the device private data has been freed, returning it
- * to its original mempool.
+ * Clears and frees asymmetric crypto session header and private data,
+ * returning it to its original mempool.
  *
+ * @param   dev_id   ID of device that uses the asymmetric session.
  * @param   sess     Session header to be freed.
  *
  * @return
  *  - 0 if successful.
- *  - -EINVAL if session is NULL.
- *  - -EBUSY if not all device private data has been freed.
+ *  - -EINVAL if device is invalid or session is NULL.
  */
 __rte_experimental
 int
-rte_cryptodev_asym_session_free(struct rte_cryptodev_asym_session *sess);
+rte_cryptodev_asym_session_free(uint8_t dev_id,
+		struct rte_cryptodev_asym_session *sess);
 
 /**
  * Fill out private data for the device id, based on its device type.
@@ -1034,28 +1066,6 @@ rte_cryptodev_sym_session_init(uint8_t dev_id,
 			struct rte_crypto_sym_xform *xforms,
 			struct rte_mempool *mempool);
 
-/**
- * Initialize asymmetric session on a device with specific asymmetric xform
- *
- * @param   dev_id   ID of device that we want the session to be used on
- * @param   sess     Session to be set up on a device
- * @param   xforms   Asymmetric crypto transform operations to apply on flow
- *                   processed with this session
- * @param   mempool  Mempool to be used for internal allocation.
- *
- * @return
- *  - On success, zero.
- *  - -EINVAL if input parameters are invalid.
- *  - -ENOTSUP if crypto device does not support the crypto transform.
- *  - -ENOMEM if the private session could not be allocated.
- */
-__rte_experimental
-int
-rte_cryptodev_asym_session_init(uint8_t dev_id,
-			struct rte_cryptodev_asym_session *sess,
-			struct rte_crypto_asym_xform *xforms,
-			struct rte_mempool *mempool);
-
 /**
  * Frees private data for the device id, based on its device type,
  * returning it to its mempool. It is the application's responsibility
@@ -1074,21 +1084,6 @@ int
 rte_cryptodev_sym_session_clear(uint8_t dev_id,
 			struct rte_cryptodev_sym_session *sess);
 
-/**
- * Frees resources held by asymmetric session during rte_cryptodev_session_init
- *
- * @param   dev_id   ID of device that uses the asymmetric session.
- * @param   sess     Asymmetric session setup on device using
- *					 rte_cryptodev_session_init
- * @return
- *  - 0 if successful.
- *  - -EINVAL if device is invalid or session is NULL.
- */
-__rte_experimental
-int
-rte_cryptodev_asym_session_clear(uint8_t dev_id,
-			struct rte_cryptodev_asym_session *sess);
-
 /**
  * Get the size of the header session, for all registered drivers excluding
  * the user data size.
@@ -1116,7 +1111,7 @@ rte_cryptodev_sym_get_existing_header_session_size(
 		struct rte_cryptodev_sym_session *sess);
 
 /**
- * Get the size of the asymmetric session header, for all registered drivers.
+ * Get the size of the asymmetric session header.
  *
  * @return
  *   Size of the asymmetric header session.
diff --git a/lib/cryptodev/rte_cryptodev_trace.h b/lib/cryptodev/rte_cryptodev_trace.h
index d1f4f069a3..a4fa9e8c7e 100644
--- a/lib/cryptodev/rte_cryptodev_trace.h
+++ b/lib/cryptodev/rte_cryptodev_trace.h
@@ -83,12 +83,22 @@ RTE_TRACE_POINT(
 	rte_trace_point_emit_u16(sess->user_data_sz);
 )
 
+RTE_TRACE_POINT(
+	rte_cryptodev_trace_asym_session_pool_create,
+	RTE_TRACE_POINT_ARGS(const char *name, uint32_t nb_elts,
+		uint32_t cache_size, void *mempool),
+	rte_trace_point_emit_string(name);
+	rte_trace_point_emit_u32(nb_elts);
+	rte_trace_point_emit_u32(cache_size);
+	rte_trace_point_emit_ptr(mempool);
+)
+
 RTE_TRACE_POINT(
 	rte_cryptodev_trace_asym_session_create,
-	RTE_TRACE_POINT_ARGS(void *mempool,
-		struct rte_cryptodev_asym_session *sess),
+	RTE_TRACE_POINT_ARGS(uint8_t dev_id, void *xforms, void *mempool),
+	rte_trace_point_emit_u8(dev_id);
+	rte_trace_point_emit_ptr(xforms);
 	rte_trace_point_emit_ptr(mempool);
-	rte_trace_point_emit_ptr(sess);
 )
 
 RTE_TRACE_POINT(
@@ -99,7 +109,9 @@ RTE_TRACE_POINT(
 
 RTE_TRACE_POINT(
 	rte_cryptodev_trace_asym_session_free,
-	RTE_TRACE_POINT_ARGS(struct rte_cryptodev_asym_session *sess),
+	RTE_TRACE_POINT_ARGS(uint8_t dev_id,
+		struct rte_cryptodev_asym_session *sess),
+	rte_trace_point_emit_u8(dev_id);
 	rte_trace_point_emit_ptr(sess);
 )
 
@@ -117,17 +129,6 @@ RTE_TRACE_POINT(
 	rte_trace_point_emit_ptr(mempool);
 )
 
-RTE_TRACE_POINT(
-	rte_cryptodev_trace_asym_session_init,
-	RTE_TRACE_POINT_ARGS(uint8_t dev_id,
-		struct rte_cryptodev_asym_session *sess, void *xforms,
-		void *mempool),
-	rte_trace_point_emit_u8(dev_id);
-	rte_trace_point_emit_ptr(sess);
-	rte_trace_point_emit_ptr(xforms);
-	rte_trace_point_emit_ptr(mempool);
-)
-
 RTE_TRACE_POINT(
 	rte_cryptodev_trace_sym_session_clear,
 	RTE_TRACE_POINT_ARGS(uint8_t dev_id, void *sess),
@@ -135,13 +136,6 @@ RTE_TRACE_POINT(
 	rte_trace_point_emit_ptr(sess);
 )
 
-RTE_TRACE_POINT(
-	rte_cryptodev_trace_asym_session_clear,
-	RTE_TRACE_POINT_ARGS(uint8_t dev_id, void *sess),
-	rte_trace_point_emit_u8(dev_id);
-	rte_trace_point_emit_ptr(sess);
-)
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/cryptodev/version.map b/lib/cryptodev/version.map
index c50745fa8c..44d1aff0e2 100644
--- a/lib/cryptodev/version.map
+++ b/lib/cryptodev/version.map
@@ -55,10 +55,8 @@ EXPERIMENTAL {
 	rte_cryptodev_asym_get_header_session_size;
 	rte_cryptodev_asym_get_private_session_size;
 	rte_cryptodev_asym_get_xform_enum;
-	rte_cryptodev_asym_session_clear;
 	rte_cryptodev_asym_session_create;
 	rte_cryptodev_asym_session_free;
-	rte_cryptodev_asym_session_init;
 	rte_cryptodev_asym_xform_capability_check_modlen;
 	rte_cryptodev_asym_xform_capability_check_optype;
 	rte_cryptodev_sym_cpu_crypto_process;
@@ -81,9 +79,7 @@ EXPERIMENTAL {
 	__rte_cryptodev_trace_sym_session_free;
 	__rte_cryptodev_trace_asym_session_free;
 	__rte_cryptodev_trace_sym_session_init;
-	__rte_cryptodev_trace_asym_session_init;
 	__rte_cryptodev_trace_sym_session_clear;
-	__rte_cryptodev_trace_asym_session_clear;
 	__rte_cryptodev_trace_dequeue_burst;
 	__rte_cryptodev_trace_enqueue_burst;
 
@@ -104,6 +100,9 @@ EXPERIMENTAL {
 	rte_cryptodev_remove_deq_callback;
 	rte_cryptodev_remove_enq_callback;
 
+	# added 22.03
+	rte_cryptodev_asym_session_pool_create;
+	__rte_cryptodev_trace_asym_session_pool_create;
 };
 
 INTERNAL {
-- 
2.25.1


^ permalink raw reply	[flat|nested] 31+ messages in thread

* [PATCH v5 3/5] crypto: hide asym session structure
  2022-02-10 14:01 ` [PATCH v5 0/5] crypto: improve asym session usage Ciara Power
  2022-02-10 14:01   ` [PATCH v5 1/5] doc: replace asym crypto code with literal includes Ciara Power
  2022-02-10 14:01   ` [PATCH v5 2/5] crypto: use single buffer for asymmetric session Ciara Power
@ 2022-02-10 14:01   ` Ciara Power
  2022-02-10 14:01   ` [PATCH v5 4/5] crypto: add asym session user data API Ciara Power
  2022-02-10 14:01   ` [PATCH v5 5/5] crypto: modify return value for asym session create Ciara Power
  4 siblings, 0 replies; 31+ messages in thread
From: Ciara Power @ 2022-02-10 14:01 UTC (permalink / raw)
  To: dev; +Cc: roy.fan.zhang, gakhil, anoobj, mdr, Ciara Power, Declan Doherty

The rte_cryptodev_asym_session structure is now moved to an internal
header. This will no longer be used directly by apps,
private session data can be accessed via get API.

Signed-off-by: Ciara Power <ciara.power@intel.com>
Acked-by: Fan Zhang <roy.fan.zhang@intel.com>

---
v4:
  - Initialised session variables as NULL.
  - Removed docs code additions, these are included due to patch 1
    changing sample doc to use literal includes.
v3:
  - Removed the incorrect use of void * for asym session in drivers,
    these are internal and can use the struct directly as before.
  - Fixed other internal functions and comments that were incorrectly
    changed to use void *sess.
  - Added documentation.
---
 app/test-crypto-perf/cperf_ops.c        |  2 +-
 app/test/test_cryptodev_asym.c          | 34 ++++++++++++-------------
 doc/guides/prog_guide/cryptodev_lib.rst |  4 +++
 doc/guides/rel_notes/release_22_03.rst  |  2 ++
 lib/cryptodev/cryptodev_pmd.h           | 13 ++++++++++
 lib/cryptodev/rte_cryptodev.c           |  5 ++--
 lib/cryptodev/rte_cryptodev.h           | 15 ++---------
 lib/cryptodev/rte_cryptodev_trace.h     |  3 +--
 8 files changed, 42 insertions(+), 36 deletions(-)

diff --git a/app/test-crypto-perf/cperf_ops.c b/app/test-crypto-perf/cperf_ops.c
index b125c699de..b8f590b397 100644
--- a/app/test-crypto-perf/cperf_ops.c
+++ b/app/test-crypto-perf/cperf_ops.c
@@ -21,7 +21,7 @@ cperf_set_ops_asym(struct rte_crypto_op **ops,
 		   uint64_t *tsc_start __rte_unused)
 {
 	uint16_t i;
-	struct rte_cryptodev_asym_session *asym_sess = (void *)sess;
+	void *asym_sess = (void *)sess;
 
 	for (i = 0; i < nb_ops; i++) {
 		struct rte_crypto_asym_op *asym_op = ops[i]->asym;
diff --git a/app/test/test_cryptodev_asym.c b/app/test/test_cryptodev_asym.c
index 88433faf1c..929d6efb24 100644
--- a/app/test/test_cryptodev_asym.c
+++ b/app/test/test_cryptodev_asym.c
@@ -46,7 +46,7 @@ struct crypto_testsuite_params_asym {
 };
 
 struct crypto_unittest_params {
-	struct rte_cryptodev_asym_session *sess;
+	void *sess;
 	struct rte_crypto_op *op;
 };
 
@@ -67,7 +67,7 @@ static uint32_t test_index;
 static struct crypto_testsuite_params_asym testsuite_params = { NULL };
 
 static int
-queue_ops_rsa_sign_verify(struct rte_cryptodev_asym_session *sess)
+queue_ops_rsa_sign_verify(void *sess)
 {
 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
 	struct rte_mempool *op_mpool = ts_params->op_mpool;
@@ -158,7 +158,7 @@ queue_ops_rsa_sign_verify(struct rte_cryptodev_asym_session *sess)
 }
 
 static int
-queue_ops_rsa_enc_dec(struct rte_cryptodev_asym_session *sess)
+queue_ops_rsa_enc_dec(void *sess)
 {
 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
 	struct rte_mempool *op_mpool = ts_params->op_mpool;
@@ -310,7 +310,7 @@ test_cryptodev_asym_op(struct crypto_testsuite_params_asym *ts_params,
 	struct rte_crypto_op *op = NULL;
 	struct rte_crypto_op *result_op = NULL;
 	struct rte_crypto_asym_xform xform_tc;
-	struct rte_cryptodev_asym_session *sess = NULL;
+	void *sess = NULL;
 	struct rte_cryptodev_asym_capability_idx cap_idx;
 	const struct rte_cryptodev_asymmetric_xform_capability *capability;
 	uint8_t dev_id = ts_params->valid_devs[0];
@@ -644,7 +644,7 @@ test_rsa_sign_verify(void)
 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
 	uint8_t dev_id = ts_params->valid_devs[0];
-	struct rte_cryptodev_asym_session *sess;
+	void *sess = NULL;
 	struct rte_cryptodev_info dev_info;
 	int status = TEST_SUCCESS;
 
@@ -684,7 +684,7 @@ test_rsa_enc_dec(void)
 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
 	uint8_t dev_id = ts_params->valid_devs[0];
-	struct rte_cryptodev_asym_session *sess;
+	void *sess = NULL;
 	struct rte_cryptodev_info dev_info;
 	int status = TEST_SUCCESS;
 
@@ -724,7 +724,7 @@ test_rsa_sign_verify_crt(void)
 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
 	uint8_t dev_id = ts_params->valid_devs[0];
-	struct rte_cryptodev_asym_session *sess;
+	void *sess = NULL;
 	struct rte_cryptodev_info dev_info;
 	int status = TEST_SUCCESS;
 
@@ -764,7 +764,7 @@ test_rsa_enc_dec_crt(void)
 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
 	uint8_t dev_id = ts_params->valid_devs[0];
-	struct rte_cryptodev_asym_session *sess;
+	void *sess = NULL;
 	struct rte_cryptodev_info dev_info;
 	int status = TEST_SUCCESS;
 
@@ -1046,7 +1046,7 @@ test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
 	uint8_t dev_id = ts_params->valid_devs[0];
 	struct rte_crypto_asym_op *asym_op = NULL;
 	struct rte_crypto_op *op = NULL, *result_op = NULL;
-	struct rte_cryptodev_asym_session *sess = NULL;
+	void *sess = NULL;
 	int status = TEST_SUCCESS;
 	uint8_t output[TEST_DH_MOD_LEN];
 	struct rte_crypto_asym_xform xform = *xfrm;
@@ -1129,7 +1129,7 @@ test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
 	uint8_t dev_id = ts_params->valid_devs[0];
 	struct rte_crypto_asym_op *asym_op = NULL;
 	struct rte_crypto_op *op = NULL, *result_op = NULL;
-	struct rte_cryptodev_asym_session *sess = NULL;
+	void *sess = NULL;
 	int status = TEST_SUCCESS;
 	uint8_t output[TEST_DH_MOD_LEN];
 	struct rte_crypto_asym_xform xform = *xfrm;
@@ -1210,7 +1210,7 @@ test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
 	uint8_t dev_id = ts_params->valid_devs[0];
 	struct rte_crypto_asym_op *asym_op = NULL;
 	struct rte_crypto_op *op = NULL, *result_op = NULL;
-	struct rte_cryptodev_asym_session *sess = NULL;
+	void *sess = NULL;
 	int status = TEST_SUCCESS;
 	uint8_t output[TEST_DH_MOD_LEN];
 	struct rte_crypto_asym_xform xform = *xfrm;
@@ -1299,7 +1299,7 @@ test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
 	uint8_t dev_id = ts_params->valid_devs[0];
 	struct rte_crypto_asym_op *asym_op = NULL;
 	struct rte_crypto_op *op = NULL, *result_op = NULL;
-	struct rte_cryptodev_asym_session *sess = NULL;
+	void *sess = NULL;
 	int status = TEST_SUCCESS;
 	uint8_t out_pub_key[TEST_DH_MOD_LEN];
 	uint8_t out_prv_key[TEST_DH_MOD_LEN];
@@ -1386,7 +1386,7 @@ test_mod_inv(void)
 	uint8_t dev_id = ts_params->valid_devs[0];
 	struct rte_crypto_asym_op *asym_op = NULL;
 	struct rte_crypto_op *op = NULL, *result_op = NULL;
-	struct rte_cryptodev_asym_session *sess = NULL;
+	void *sess = NULL;
 	int status = TEST_SUCCESS;
 	struct rte_cryptodev_asym_capability_idx cap_idx;
 	const struct rte_cryptodev_asymmetric_xform_capability *capability;
@@ -1499,7 +1499,7 @@ test_mod_exp(void)
 	uint8_t dev_id = ts_params->valid_devs[0];
 	struct rte_crypto_asym_op *asym_op = NULL;
 	struct rte_crypto_op *op = NULL, *result_op = NULL;
-	struct rte_cryptodev_asym_session *sess = NULL;
+	void *sess = NULL;
 	int status = TEST_SUCCESS;
 	struct rte_cryptodev_asym_capability_idx cap_idx;
 	const struct rte_cryptodev_asymmetric_xform_capability *capability;
@@ -1648,7 +1648,7 @@ test_dsa_sign(void)
 	uint8_t dev_id = ts_params->valid_devs[0];
 	struct rte_crypto_asym_op *asym_op = NULL;
 	struct rte_crypto_op *op = NULL, *result_op = NULL;
-	struct rte_cryptodev_asym_session *sess = NULL;
+	void *sess = NULL;
 	int status = TEST_SUCCESS;
 	uint8_t r[TEST_DH_MOD_LEN];
 	uint8_t s[TEST_DH_MOD_LEN];
@@ -1779,7 +1779,7 @@ test_ecdsa_sign_verify(enum curve curve_id)
 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
 	struct rte_mempool *op_mpool = ts_params->op_mpool;
 	struct crypto_testsuite_ecdsa_params input_params;
-	struct rte_cryptodev_asym_session *sess = NULL;
+	void *sess = NULL;
 	uint8_t dev_id = ts_params->valid_devs[0];
 	struct rte_crypto_op *result_op = NULL;
 	uint8_t output_buf_r[TEST_DATA_SIZE];
@@ -1981,7 +1981,7 @@ test_ecpm(enum curve curve_id)
 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
 	struct rte_mempool *op_mpool = ts_params->op_mpool;
 	struct crypto_testsuite_ecpm_params input_params;
-	struct rte_cryptodev_asym_session *sess = NULL;
+	void *sess = NULL;
 	uint8_t dev_id = ts_params->valid_devs[0];
 	struct rte_crypto_op *result_op = NULL;
 	uint8_t output_buf_x[TEST_DATA_SIZE];
diff --git a/doc/guides/prog_guide/cryptodev_lib.rst b/doc/guides/prog_guide/cryptodev_lib.rst
index b4dbd384bf..2607a9a7d7 100644
--- a/doc/guides/prog_guide/cryptodev_lib.rst
+++ b/doc/guides/prog_guide/cryptodev_lib.rst
@@ -1155,6 +1155,10 @@ Generate crypto op, create and attach a session, then process packets.
    :end-before: >8 End of create op, create session, and process packets section.
    :dedent: 1
 
+.. note::
+   The ``rte_cryptodev_asym_session`` struct is hidden from the application.
+   The ``sess`` pointer used above is a void pointer.
+
 
 Asymmetric Crypto Device API
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
diff --git a/doc/guides/rel_notes/release_22_03.rst b/doc/guides/rel_notes/release_22_03.rst
index ea4c5309a0..459b15bdde 100644
--- a/doc/guides/rel_notes/release_22_03.rst
+++ b/doc/guides/rel_notes/release_22_03.rst
@@ -116,6 +116,8 @@ API Changes
   mempool object. An API ``rte_cryptodev_asym_session_pool_create`` was added
   to create a mempool with element size big enough to hold the generic asymmetric
   session header and max size for a device private session data.
+  The session structure was moved to ``cryptodev_pmd.h``,
+  hiding it from applications.
   The API ``rte_cryptodev_asym_session_init`` was removed as the initialization
   is now moved to ``rte_cryptodev_asym_session_create``.
 
diff --git a/lib/cryptodev/cryptodev_pmd.h b/lib/cryptodev/cryptodev_pmd.h
index 142bfb7c66..63f9cf5427 100644
--- a/lib/cryptodev/cryptodev_pmd.h
+++ b/lib/cryptodev/cryptodev_pmd.h
@@ -625,4 +625,17 @@ set_sym_session_private_data(struct rte_cryptodev_sym_session *sess,
 	sess->sess_data[driver_id].data = private_data;
 }
 
+/**
+ * @internal
+ * Cryptodev asymmetric crypto session.
+ */
+RTE_STD_C11 struct rte_cryptodev_asym_session {
+	uint8_t driver_id;
+	/**< Session driver ID. */
+	uint16_t max_priv_data_sz;
+	/**< Size of private data used when creating mempool */
+	uint8_t padding[5];
+	uint8_t sess_private_data[0];
+};
+
 #endif /* _CRYPTODEV_PMD_H_ */
diff --git a/lib/cryptodev/rte_cryptodev.c b/lib/cryptodev/rte_cryptodev.c
index b056d88ac2..562cb4a2c4 100644
--- a/lib/cryptodev/rte_cryptodev.c
+++ b/lib/cryptodev/rte_cryptodev.c
@@ -1908,7 +1908,7 @@ rte_cryptodev_sym_session_create(struct rte_mempool *mp)
 	return sess;
 }
 
-struct rte_cryptodev_asym_session *
+void *
 rte_cryptodev_asym_session_create(uint8_t dev_id,
 		struct rte_crypto_asym_xform *xforms, struct rte_mempool *mp)
 {
@@ -2035,8 +2035,7 @@ rte_cryptodev_sym_session_free(struct rte_cryptodev_sym_session *sess)
 }
 
 int
-rte_cryptodev_asym_session_free(uint8_t dev_id,
-		struct rte_cryptodev_asym_session *sess)
+rte_cryptodev_asym_session_free(uint8_t dev_id, void *sess)
 {
 	struct rte_mempool *sess_mp;
 	struct rte_cryptodev *dev;
diff --git a/lib/cryptodev/rte_cryptodev.h b/lib/cryptodev/rte_cryptodev.h
index 90e764017d..4cf3f6c9d7 100644
--- a/lib/cryptodev/rte_cryptodev.h
+++ b/lib/cryptodev/rte_cryptodev.h
@@ -918,16 +918,6 @@ struct rte_cryptodev_sym_session {
 	/**< Driver specific session material, variable size */
 };
 
-/** Cryptodev asymmetric crypto session */
-RTE_STD_C11 struct rte_cryptodev_asym_session {
-	uint8_t driver_id;
-	/**< Session driver ID. */
-	uint16_t max_priv_data_sz;
-	/**< Size of private data used when creating mempool */
-	uint8_t padding[5];
-	uint8_t sess_private_data[0];
-};
-
 /**
  * Create a symmetric session mempool.
  *
@@ -1009,7 +999,7 @@ rte_cryptodev_sym_session_create(struct rte_mempool *mempool);
  *  - On failure returns NULL
  */
 __rte_experimental
-struct rte_cryptodev_asym_session *
+void *
 rte_cryptodev_asym_session_create(uint8_t dev_id,
 		struct rte_crypto_asym_xform *xforms, struct rte_mempool *mp);
 
@@ -1041,8 +1031,7 @@ rte_cryptodev_sym_session_free(struct rte_cryptodev_sym_session *sess);
  */
 __rte_experimental
 int
-rte_cryptodev_asym_session_free(uint8_t dev_id,
-		struct rte_cryptodev_asym_session *sess);
+rte_cryptodev_asym_session_free(uint8_t dev_id, void *sess);
 
 /**
  * Fill out private data for the device id, based on its device type.
diff --git a/lib/cryptodev/rte_cryptodev_trace.h b/lib/cryptodev/rte_cryptodev_trace.h
index a4fa9e8c7e..4b48c66199 100644
--- a/lib/cryptodev/rte_cryptodev_trace.h
+++ b/lib/cryptodev/rte_cryptodev_trace.h
@@ -109,8 +109,7 @@ RTE_TRACE_POINT(
 
 RTE_TRACE_POINT(
 	rte_cryptodev_trace_asym_session_free,
-	RTE_TRACE_POINT_ARGS(uint8_t dev_id,
-		struct rte_cryptodev_asym_session *sess),
+	RTE_TRACE_POINT_ARGS(uint8_t dev_id, void *sess),
 	rte_trace_point_emit_u8(dev_id);
 	rte_trace_point_emit_ptr(sess);
 )
-- 
2.25.1


^ permalink raw reply	[flat|nested] 31+ messages in thread

* [PATCH v5 4/5] crypto: add asym session user data API
  2022-02-10 14:01 ` [PATCH v5 0/5] crypto: improve asym session usage Ciara Power
                     ` (2 preceding siblings ...)
  2022-02-10 14:01   ` [PATCH v5 3/5] crypto: hide asym session structure Ciara Power
@ 2022-02-10 14:01   ` Ciara Power
  2022-02-10 14:01   ` [PATCH v5 5/5] crypto: modify return value for asym session create Ciara Power
  4 siblings, 0 replies; 31+ messages in thread
From: Ciara Power @ 2022-02-10 14:01 UTC (permalink / raw)
  To: dev; +Cc: roy.fan.zhang, gakhil, anoobj, mdr, Ciara Power, Declan Doherty

A user data field is added to the asymmetric session structure.
Relevant API added to get/set the field.

Signed-off-by: Ciara Power <ciara.power@intel.com>
Acked-by: Fan Zhang <roy.fan.zhang@intel.com>
Acked-by: Anoob Joseph <anoobj@marvell.com>

---
v4:
  - Reworded release notes.
  - Added possible error return values in function comment.
  - Removed docs code additions, these are included due to patch 1
    changing sample doc to use literal includes.
v3:
  - Corrected formatting of struct comments.
  - Added setting user data size in pool creation.
  - Added documentation.
v2: Corrected order of version map entries.
---
 app/test/test_cryptodev_asym.c          |  2 +-
 doc/guides/prog_guide/cryptodev_lib.rst | 19 ++++++++++++
 doc/guides/rel_notes/release_22_03.rst  |  6 +++-
 lib/cryptodev/cryptodev_pmd.h           |  4 ++-
 lib/cryptodev/rte_cryptodev.c           | 40 ++++++++++++++++++++++---
 lib/cryptodev/rte_cryptodev.h           | 35 +++++++++++++++++++++-
 lib/cryptodev/rte_cryptodev_trace.h     |  3 +-
 lib/cryptodev/version.map               |  2 ++
 8 files changed, 102 insertions(+), 9 deletions(-)

diff --git a/app/test/test_cryptodev_asym.c b/app/test/test_cryptodev_asym.c
index 929d6efb24..f0cb839a49 100644
--- a/app/test/test_cryptodev_asym.c
+++ b/app/test/test_cryptodev_asym.c
@@ -894,7 +894,7 @@ testsuite_setup(void)
 	}
 
 	ts_params->session_mpool = rte_cryptodev_asym_session_pool_create(
-			"test_asym_sess_mp", TEST_NUM_SESSIONS, 0,
+			"test_asym_sess_mp", TEST_NUM_SESSIONS, 0, 0,
 			SOCKET_ID_ANY);
 
 	TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
diff --git a/doc/guides/prog_guide/cryptodev_lib.rst b/doc/guides/prog_guide/cryptodev_lib.rst
index 2607a9a7d7..ba4c592b84 100644
--- a/doc/guides/prog_guide/cryptodev_lib.rst
+++ b/doc/guides/prog_guide/cryptodev_lib.rst
@@ -1110,6 +1110,25 @@ They operate on data buffer of type ``rte_crypto_param``.
 
 See *DPDK API Reference* for details on each rte_crypto_xxx_op_param struct
 
+Private user data
+~~~~~~~~~~~~~~~~~
+
+Similar to symmetric above, asymmetric also has a set and get API that provides a
+mechanism for an application to store and retrieve the private user data information
+stored along with the crypto session.
+
+.. code-block:: c
+
+	int rte_cryptodev_asym_session_set_user_data(void *sess,
+		void *data, uint16_t size);
+
+	void * rte_cryptodev_asym_session_get_user_data(void *sess);
+
+Please note the ``size`` passed to set API cannot be bigger than the predefined
+``user_data_sz`` when creating the session mempool, otherwise the function will
+return an error. Also when ``user_data_sz`` was defined as ``0`` when
+creating the session mempool, the get API will always return ``NULL``.
+
 Asymmetric crypto Sample code
 -----------------------------
 
diff --git a/doc/guides/rel_notes/release_22_03.rst b/doc/guides/rel_notes/release_22_03.rst
index 459b15bdde..a930cbbad6 100644
--- a/doc/guides/rel_notes/release_22_03.rst
+++ b/doc/guides/rel_notes/release_22_03.rst
@@ -78,6 +78,10 @@ New Features
 
   The new API ``rte_event_eth_rx_adapter_event_port_get()`` was added.
 
+* **Added an API for private user data in Asymmetric crypto session.**
+
+  An API was added for getting/setting an Asymmetric crypto session's user data.
+
 
 Removed Items
 -------------
@@ -115,7 +119,7 @@ API Changes
 * cryptodev: The asymmetric session handling was modified to use a single
   mempool object. An API ``rte_cryptodev_asym_session_pool_create`` was added
   to create a mempool with element size big enough to hold the generic asymmetric
-  session header and max size for a device private session data.
+  session header, max size for a device private session data, and user data size.
   The session structure was moved to ``cryptodev_pmd.h``,
   hiding it from applications.
   The API ``rte_cryptodev_asym_session_init`` was removed as the initialization
diff --git a/lib/cryptodev/cryptodev_pmd.h b/lib/cryptodev/cryptodev_pmd.h
index 63f9cf5427..d91902f6e0 100644
--- a/lib/cryptodev/cryptodev_pmd.h
+++ b/lib/cryptodev/cryptodev_pmd.h
@@ -634,7 +634,9 @@ RTE_STD_C11 struct rte_cryptodev_asym_session {
 	/**< Session driver ID. */
 	uint16_t max_priv_data_sz;
 	/**< Size of private data used when creating mempool */
-	uint8_t padding[5];
+	uint16_t user_data_sz;
+	/**< Session user data will be placed after sess_data */
+	uint8_t padding[3];
 	uint8_t sess_private_data[0];
 };
 
diff --git a/lib/cryptodev/rte_cryptodev.c b/lib/cryptodev/rte_cryptodev.c
index 562cb4a2c4..91d48d5886 100644
--- a/lib/cryptodev/rte_cryptodev.c
+++ b/lib/cryptodev/rte_cryptodev.c
@@ -210,6 +210,8 @@ struct rte_cryptodev_sym_session_pool_private_data {
 struct rte_cryptodev_asym_session_pool_private_data {
 	uint16_t max_priv_session_sz;
 	/**< Size of private session data used when creating mempool */
+	uint16_t user_data_sz;
+	/**< Session user data will be placed after sess_private_data */
 };
 
 int
@@ -1803,7 +1805,7 @@ rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
 
 struct rte_mempool *
 rte_cryptodev_asym_session_pool_create(const char *name, uint32_t nb_elts,
-	uint32_t cache_size, int socket_id)
+	uint32_t cache_size, uint16_t user_data_size, int socket_id)
 {
 	struct rte_mempool *mp;
 	struct rte_cryptodev_asym_session_pool_private_data *pool_priv;
@@ -1821,7 +1823,8 @@ rte_cryptodev_asym_session_pool_create(const char *name, uint32_t nb_elts,
 		return NULL;
 	}
 
-	obj_sz = rte_cryptodev_asym_get_header_session_size() + max_priv_sz;
+	obj_sz = rte_cryptodev_asym_get_header_session_size() + max_priv_sz +
+			user_data_size;
 	obj_sz_aligned =  RTE_ALIGN_CEIL(obj_sz, RTE_CACHE_LINE_SIZE);
 
 	mp = rte_mempool_create(name, nb_elts, obj_sz_aligned, cache_size,
@@ -1842,9 +1845,10 @@ rte_cryptodev_asym_session_pool_create(const char *name, uint32_t nb_elts,
 		return NULL;
 	}
 	pool_priv->max_priv_session_sz = max_priv_sz;
+	pool_priv->user_data_sz = user_data_size;
 
 	rte_cryptodev_trace_asym_session_pool_create(name, nb_elts,
-		cache_size, mp);
+		user_data_size, cache_size, mp);
 	return mp;
 }
 
@@ -1959,10 +1963,11 @@ rte_cryptodev_asym_session_create(uint8_t dev_id,
 	}
 
 	sess->driver_id = dev->driver_id;
+	sess->user_data_sz = pool_priv->user_data_sz;
 	sess->max_priv_data_sz = pool_priv->max_priv_session_sz;
 
 	/* Clear device session pointer.*/
-	memset(sess->sess_private_data, 0, session_priv_data_sz);
+	memset(sess->sess_private_data, 0, session_priv_data_sz + sess->user_data_sz);
 
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->asym_session_configure, NULL);
 
@@ -2159,6 +2164,33 @@ rte_cryptodev_sym_session_get_user_data(
 	return (void *)(sess->sess_data + sess->nb_drivers);
 }
 
+int
+rte_cryptodev_asym_session_set_user_data(void *session, void *data, uint16_t size)
+{
+	struct rte_cryptodev_asym_session *sess = session;
+	if (sess == NULL)
+		return -EINVAL;
+
+	if (sess->user_data_sz < size)
+		return -ENOMEM;
+
+	rte_memcpy(sess->sess_private_data +
+			sess->max_priv_data_sz,
+			data, size);
+	return 0;
+}
+
+void *
+rte_cryptodev_asym_session_get_user_data(void *session)
+{
+	struct rte_cryptodev_asym_session *sess = session;
+	if (sess == NULL || sess->user_data_sz == 0)
+		return NULL;
+
+	return (void *)(sess->sess_private_data +
+			sess->max_priv_data_sz);
+}
+
 static inline void
 sym_crypto_fill_status(struct rte_crypto_sym_vec *vec, int32_t errnum)
 {
diff --git a/lib/cryptodev/rte_cryptodev.h b/lib/cryptodev/rte_cryptodev.h
index 4cf3f6c9d7..1d7bd07680 100644
--- a/lib/cryptodev/rte_cryptodev.h
+++ b/lib/cryptodev/rte_cryptodev.h
@@ -959,6 +959,8 @@ rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
  *   The number of elements in the mempool.
  * @param cache_size
  *   The number of per-lcore cache elements
+ * @param user_data_size
+ *   The size of user data to be placed after session private data.
  * @param socket_id
  *   The *socket_id* argument is the socket identifier in the case of
  *   NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA
@@ -971,7 +973,7 @@ rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
 __rte_experimental
 struct rte_mempool *
 rte_cryptodev_asym_session_pool_create(const char *name, uint32_t nb_elts,
-	uint32_t cache_size, int socket_id);
+	uint32_t cache_size, uint16_t user_data_size, int socket_id);
 
 /**
  * Create symmetric crypto session header (generic with no private data)
@@ -1202,6 +1204,37 @@ void *
 rte_cryptodev_sym_session_get_user_data(
 					struct rte_cryptodev_sym_session *sess);
 
+/**
+ * Store user data in an asymmetric session.
+ *
+ * @param	sess		Session pointer allocated by
+ *				*rte_cryptodev_asym_session_create*.
+ * @param	data		Pointer to the user data.
+ * @param	size		Size of the user data.
+ *
+ * @return
+ *  - On success, zero.
+ *  - -EINVAL if the session pointer is invalid.
+ *  - -ENOMEM if the available user data size is smaller than the size parameter.
+ */
+__rte_experimental
+int
+rte_cryptodev_asym_session_set_user_data(void *sess, void *data, uint16_t size);
+
+/**
+ * Get user data stored in an asymmetric session.
+ *
+ * @param	sess		Session pointer allocated by
+ *				*rte_cryptodev_asym_session_create*.
+ *
+ * @return
+ *  - On success return pointer to user data.
+ *  - On failure returns NULL.
+ */
+__rte_experimental
+void *
+rte_cryptodev_asym_session_get_user_data(void *sess);
+
 /**
  * Perform actual crypto processing (encrypt/digest or auth/decrypt)
  * on user provided data.
diff --git a/lib/cryptodev/rte_cryptodev_trace.h b/lib/cryptodev/rte_cryptodev_trace.h
index 4b48c66199..005a4fe38b 100644
--- a/lib/cryptodev/rte_cryptodev_trace.h
+++ b/lib/cryptodev/rte_cryptodev_trace.h
@@ -86,9 +86,10 @@ RTE_TRACE_POINT(
 RTE_TRACE_POINT(
 	rte_cryptodev_trace_asym_session_pool_create,
 	RTE_TRACE_POINT_ARGS(const char *name, uint32_t nb_elts,
-		uint32_t cache_size, void *mempool),
+		uint16_t user_data_size, uint32_t cache_size, void *mempool),
 	rte_trace_point_emit_string(name);
 	rte_trace_point_emit_u32(nb_elts);
+	rte_trace_point_emit_u16(user_data_size);
 	rte_trace_point_emit_u32(cache_size);
 	rte_trace_point_emit_ptr(mempool);
 )
diff --git a/lib/cryptodev/version.map b/lib/cryptodev/version.map
index 44d1aff0e2..c7c5aefceb 100644
--- a/lib/cryptodev/version.map
+++ b/lib/cryptodev/version.map
@@ -101,7 +101,9 @@ EXPERIMENTAL {
 	rte_cryptodev_remove_enq_callback;
 
 	# added 22.03
+	rte_cryptodev_asym_session_get_user_data;
 	rte_cryptodev_asym_session_pool_create;
+	rte_cryptodev_asym_session_set_user_data;
 	__rte_cryptodev_trace_asym_session_pool_create;
 };
 
-- 
2.25.1


^ permalink raw reply	[flat|nested] 31+ messages in thread

* [PATCH v5 5/5] crypto: modify return value for asym session create
  2022-02-10 14:01 ` [PATCH v5 0/5] crypto: improve asym session usage Ciara Power
                     ` (3 preceding siblings ...)
  2022-02-10 14:01   ` [PATCH v5 4/5] crypto: add asym session user data API Ciara Power
@ 2022-02-10 14:01   ` Ciara Power
  4 siblings, 0 replies; 31+ messages in thread
From: Ciara Power @ 2022-02-10 14:01 UTC (permalink / raw)
  To: dev; +Cc: roy.fan.zhang, gakhil, anoobj, mdr, Ciara Power, Declan Doherty

Rather than the asym session create function returning a session on
success, and a NULL value on error, it is modified to now return int
values - 0 on success or -EINVAL/-ENOTSUP/-ENOMEM on failure.
The session to be used is passed as input.

This adds clarity on the failure of the create function, which enables
treating the -ENOTSUP return as TEST_SKIPPED in test apps.

Signed-off-by: Ciara Power <ciara.power@intel.com>
Acked-by: Fan Zhang <roy.fan.zhang@intel.com>
Acked-by: Anoob Joseph <anoobj@marvell.com>
Acked-by: Akhil Goyal <gakhil@marvell.com>

---
v5: Added session parameter to create session trace.
v4:
  - Reordered function parameters.
  - Removed docs code additions, these are included due to patch 1
    changing sample doc to use literal includes.
v3:
  - Fixed variable declarations, putting initialised variable last.
  - Made function comment for return value more generic.
  - Fixed log to include line break.
  - Added documentation.
---
 app/test-crypto-perf/cperf_ops.c       |  12 ++-
 app/test/test_cryptodev_asym.c         | 109 +++++++++++++------------
 doc/guides/rel_notes/release_22_03.rst |   3 +-
 lib/cryptodev/rte_cryptodev.c          |  28 ++++---
 lib/cryptodev/rte_cryptodev.h          |  13 ++-
 lib/cryptodev/rte_cryptodev_trace.h    |   4 +-
 6 files changed, 92 insertions(+), 77 deletions(-)

diff --git a/app/test-crypto-perf/cperf_ops.c b/app/test-crypto-perf/cperf_ops.c
index b8f590b397..479c40eead 100644
--- a/app/test-crypto-perf/cperf_ops.c
+++ b/app/test-crypto-perf/cperf_ops.c
@@ -734,7 +734,9 @@ cperf_create_session(struct rte_mempool *sess_mp,
 	struct rte_crypto_sym_xform auth_xform;
 	struct rte_crypto_sym_xform aead_xform;
 	struct rte_cryptodev_sym_session *sess = NULL;
+	void *asym_sess = NULL;
 	struct rte_crypto_asym_xform xform = {0};
+	int ret;
 
 	if (options->op_type == CPERF_ASYM_MODEX) {
 		xform.next = NULL;
@@ -744,11 +746,13 @@ cperf_create_session(struct rte_mempool *sess_mp,
 		xform.modex.exponent.data = perf_mod_e;
 		xform.modex.exponent.length = sizeof(perf_mod_e);
 
-		sess = (void *)rte_cryptodev_asym_session_create(dev_id, &xform, sess_mp);
-		if (sess == NULL)
+		ret = rte_cryptodev_asym_session_create(dev_id, &xform,
+				sess_mp, &asym_sess);
+		if (ret < 0) {
+			RTE_LOG(ERR, USER1, "Asym session create failed\n");
 			return NULL;
-
-		return sess;
+		}
+		return asym_sess;
 	}
 #ifdef RTE_LIB_SECURITY
 	/*
diff --git a/app/test/test_cryptodev_asym.c b/app/test/test_cryptodev_asym.c
index f0cb839a49..c2e1b4dafd 100644
--- a/app/test/test_cryptodev_asym.c
+++ b/app/test/test_cryptodev_asym.c
@@ -317,7 +317,7 @@ test_cryptodev_asym_op(struct crypto_testsuite_params_asym *ts_params,
 	uint8_t input[TEST_DATA_SIZE] = {0};
 	uint8_t *result = NULL;
 
-	int status = TEST_SUCCESS;
+	int ret, status = TEST_SUCCESS;
 
 	xform_tc.next = NULL;
 	xform_tc.xform_type = data_tc->modex.xform_type;
@@ -452,14 +452,14 @@ test_cryptodev_asym_op(struct crypto_testsuite_params_asym *ts_params,
 	}
 
 	if (!sessionless) {
-		sess = rte_cryptodev_asym_session_create(dev_id, &xform_tc,
-				ts_params->session_mpool);
-		if (!sess) {
+		ret = rte_cryptodev_asym_session_create(dev_id, &xform_tc,
+				ts_params->session_mpool, &sess);
+		if (ret < 0) {
 			snprintf(test_msg, ASYM_TEST_MSG_LEN,
 					"line %u "
 					"FAILED: %s", __LINE__,
 					"Session creation failed");
-			status = TEST_FAILED;
+			status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 			goto error_exit;
 		}
 
@@ -646,7 +646,7 @@ test_rsa_sign_verify(void)
 	uint8_t dev_id = ts_params->valid_devs[0];
 	void *sess = NULL;
 	struct rte_cryptodev_info dev_info;
-	int status = TEST_SUCCESS;
+	int ret, status = TEST_SUCCESS;
 
 	/* Test case supports op with exponent key only,
 	 * Check in PMD feature flag for RSA exponent key type support.
@@ -659,12 +659,12 @@ test_rsa_sign_verify(void)
 		return TEST_SKIPPED;
 	}
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool);
+	ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool, &sess);
 
-	if (!sess) {
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1, "Session creation failed for "
 			"sign_verify\n");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto error_exit;
 	}
 
@@ -686,7 +686,7 @@ test_rsa_enc_dec(void)
 	uint8_t dev_id = ts_params->valid_devs[0];
 	void *sess = NULL;
 	struct rte_cryptodev_info dev_info;
-	int status = TEST_SUCCESS;
+	int ret, status = TEST_SUCCESS;
 
 	/* Test case supports op with exponent key only,
 	 * Check in PMD feature flag for RSA exponent key type support.
@@ -699,11 +699,11 @@ test_rsa_enc_dec(void)
 		return TEST_SKIPPED;
 	}
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool);
+	ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool, &sess);
 
-	if (!sess) {
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1, "Session creation failed for enc_dec\n");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto error_exit;
 	}
 
@@ -726,7 +726,7 @@ test_rsa_sign_verify_crt(void)
 	uint8_t dev_id = ts_params->valid_devs[0];
 	void *sess = NULL;
 	struct rte_cryptodev_info dev_info;
-	int status = TEST_SUCCESS;
+	int ret, status = TEST_SUCCESS;
 
 	/* Test case supports op with quintuple format key only,
 	 * Check im PMD feature flag for RSA quintuple key type support.
@@ -738,12 +738,12 @@ test_rsa_sign_verify_crt(void)
 		return TEST_SKIPPED;
 	}
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &rsa_xform_crt, sess_mpool);
+	ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform_crt, sess_mpool, &sess);
 
-	if (!sess) {
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1, "Session creation failed for "
 			"sign_verify_crt\n");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto error_exit;
 	}
 
@@ -766,7 +766,7 @@ test_rsa_enc_dec_crt(void)
 	uint8_t dev_id = ts_params->valid_devs[0];
 	void *sess = NULL;
 	struct rte_cryptodev_info dev_info;
-	int status = TEST_SUCCESS;
+	int ret, status = TEST_SUCCESS;
 
 	/* Test case supports op with quintuple format key only,
 	 * Check in PMD feature flag for RSA quintuple key type support.
@@ -778,12 +778,12 @@ test_rsa_enc_dec_crt(void)
 		return TEST_SKIPPED;
 	}
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &rsa_xform_crt, sess_mpool);
+	ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform_crt, sess_mpool, &sess);
 
-	if (!sess) {
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1, "Session creation failed for "
 			"enc_dec_crt\n");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto error_exit;
 	}
 
@@ -1047,7 +1047,7 @@ test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
 	struct rte_crypto_asym_op *asym_op = NULL;
 	struct rte_crypto_op *op = NULL, *result_op = NULL;
 	void *sess = NULL;
-	int status = TEST_SUCCESS;
+	int ret, status = TEST_SUCCESS;
 	uint8_t output[TEST_DH_MOD_LEN];
 	struct rte_crypto_asym_xform xform = *xfrm;
 	uint8_t peer[] = "01234567890123456789012345678901234567890123456789";
@@ -1074,12 +1074,12 @@ test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
 	asym_op->dh.shared_secret.data = output;
 	asym_op->dh.shared_secret.length = sizeof(output);
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
-	if (sess == NULL) {
+	ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
 				"line %u FAILED: %s", __LINE__,
 				"Session creation failed");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto error_exit;
 	}
 
@@ -1130,7 +1130,7 @@ test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
 	struct rte_crypto_asym_op *asym_op = NULL;
 	struct rte_crypto_op *op = NULL, *result_op = NULL;
 	void *sess = NULL;
-	int status = TEST_SUCCESS;
+	int ret, status = TEST_SUCCESS;
 	uint8_t output[TEST_DH_MOD_LEN];
 	struct rte_crypto_asym_xform xform = *xfrm;
 
@@ -1152,12 +1152,12 @@ test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
 	asym_op->dh.priv_key.data = output;
 	asym_op->dh.priv_key.length = sizeof(output);
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
-	if (sess == NULL) {
+	ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
 				"line %u FAILED: %s", __LINE__,
 				"Session creation failed");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto error_exit;
 	}
 
@@ -1211,7 +1211,7 @@ test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
 	struct rte_crypto_asym_op *asym_op = NULL;
 	struct rte_crypto_op *op = NULL, *result_op = NULL;
 	void *sess = NULL;
-	int status = TEST_SUCCESS;
+	int ret, status = TEST_SUCCESS;
 	uint8_t output[TEST_DH_MOD_LEN];
 	struct rte_crypto_asym_xform xform = *xfrm;
 
@@ -1241,12 +1241,12 @@ test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
 					0);
 	asym_op->dh.priv_key = dh_test_params.priv_key;
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
-	if (sess == NULL) {
+	ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
 				"line %u FAILED: %s", __LINE__,
 				"Session creation failed");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto error_exit;
 	}
 
@@ -1300,7 +1300,7 @@ test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
 	struct rte_crypto_asym_op *asym_op = NULL;
 	struct rte_crypto_op *op = NULL, *result_op = NULL;
 	void *sess = NULL;
-	int status = TEST_SUCCESS;
+	int ret, status = TEST_SUCCESS;
 	uint8_t out_pub_key[TEST_DH_MOD_LEN];
 	uint8_t out_prv_key[TEST_DH_MOD_LEN];
 	struct rte_crypto_asym_xform pub_key_xform;
@@ -1330,12 +1330,12 @@ test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
 	asym_op->dh.priv_key.data = out_prv_key;
 	asym_op->dh.priv_key.length = sizeof(out_prv_key);
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
-	if (sess == NULL) {
+	ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
 				"line %u FAILED: %s", __LINE__,
 				"Session creation failed");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto error_exit;
 	}
 
@@ -1419,12 +1419,12 @@ test_mod_inv(void)
 				return TEST_SKIPPED;
 		}
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &modinv_xform, sess_mpool);
-	if (!sess) {
+	ret = rte_cryptodev_asym_session_create(dev_id, &modinv_xform, sess_mpool, &sess);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1, "line %u "
 				"FAILED: %s", __LINE__,
 				"Session creation failed");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto error_exit;
 	}
 
@@ -1543,13 +1543,13 @@ test_mod_exp(void)
 		goto error_exit;
 	}
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &modex_xform, sess_mpool);
-	if (!sess) {
+	ret = rte_cryptodev_asym_session_create(dev_id, &modex_xform, sess_mpool, &sess);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
 				 "line %u "
 				"FAILED: %s", __LINE__,
 				"Session creation failed");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto error_exit;
 	}
 
@@ -1653,13 +1653,14 @@ test_dsa_sign(void)
 	uint8_t r[TEST_DH_MOD_LEN];
 	uint8_t s[TEST_DH_MOD_LEN];
 	uint8_t dgst[] = "35d81554afaad2cf18f3a1770d5fedc4ea5be344";
+	int ret;
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &dsa_xform, sess_mpool);
-	if (sess == NULL) {
+	ret = rte_cryptodev_asym_session_create(dev_id, &dsa_xform, sess_mpool, &sess);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
 				 "line %u FAILED: %s", __LINE__,
 				"Session creation failed");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto error_exit;
 	}
 	/* set up crypto op data structure */
@@ -1788,7 +1789,7 @@ test_ecdsa_sign_verify(enum curve curve_id)
 	struct rte_crypto_asym_op *asym_op;
 	struct rte_cryptodev_info dev_info;
 	struct rte_crypto_op *op = NULL;
-	int status = TEST_SUCCESS, ret;
+	int ret, status = TEST_SUCCESS;
 
 	switch (curve_id) {
 	case SECP192R1:
@@ -1833,12 +1834,12 @@ test_ecdsa_sign_verify(enum curve curve_id)
 	xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDSA;
 	xform.ec.curve_id = input_params.curve;
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
-	if (sess == NULL) {
+	ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
 				"line %u FAILED: %s", __LINE__,
 				"Session creation failed\n");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto exit;
 	}
 
@@ -1990,7 +1991,7 @@ test_ecpm(enum curve curve_id)
 	struct rte_crypto_asym_op *asym_op;
 	struct rte_cryptodev_info dev_info;
 	struct rte_crypto_op *op = NULL;
-	int status = TEST_SUCCESS, ret;
+	int ret, status = TEST_SUCCESS;
 
 	switch (curve_id) {
 	case SECP192R1:
@@ -2035,12 +2036,12 @@ test_ecpm(enum curve curve_id)
 	xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECPM;
 	xform.ec.curve_id = input_params.curve;
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
-	if (sess == NULL) {
+	ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
 				"line %u FAILED: %s", __LINE__,
 				"Session creation failed\n");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto exit;
 	}
 
diff --git a/doc/guides/rel_notes/release_22_03.rst b/doc/guides/rel_notes/release_22_03.rst
index a930cbbad6..640691c3ef 100644
--- a/doc/guides/rel_notes/release_22_03.rst
+++ b/doc/guides/rel_notes/release_22_03.rst
@@ -123,7 +123,8 @@ API Changes
   The session structure was moved to ``cryptodev_pmd.h``,
   hiding it from applications.
   The API ``rte_cryptodev_asym_session_init`` was removed as the initialization
-  is now moved to ``rte_cryptodev_asym_session_create``.
+  is now moved to ``rte_cryptodev_asym_session_create``, which was updated to
+  return an integer value to indicate initialisation errors.
 
 
 ABI Changes
diff --git a/lib/cryptodev/rte_cryptodev.c b/lib/cryptodev/rte_cryptodev.c
index 91d48d5886..727d271fb9 100644
--- a/lib/cryptodev/rte_cryptodev.c
+++ b/lib/cryptodev/rte_cryptodev.c
@@ -1912,9 +1912,10 @@ rte_cryptodev_sym_session_create(struct rte_mempool *mp)
 	return sess;
 }
 
-void *
+int
 rte_cryptodev_asym_session_create(uint8_t dev_id,
-		struct rte_crypto_asym_xform *xforms, struct rte_mempool *mp)
+		struct rte_crypto_asym_xform *xforms, struct rte_mempool *mp,
+		void **session)
 {
 	struct rte_cryptodev_asym_session *sess;
 	uint32_t session_priv_data_sz;
@@ -1926,17 +1927,17 @@ rte_cryptodev_asym_session_create(uint8_t dev_id,
 
 	if (!rte_cryptodev_is_valid_dev(dev_id)) {
 		CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
-		return NULL;
+		return -EINVAL;
 	}
 
 	dev = rte_cryptodev_pmd_get_dev(dev_id);
 
 	if (dev == NULL)
-		return NULL;
+		return -EINVAL;
 
 	if (!mp) {
 		CDEV_LOG_ERR("invalid mempool\n");
-		return NULL;
+		return -EINVAL;
 	}
 
 	session_priv_data_sz = rte_cryptodev_asym_get_private_session_size(
@@ -1946,22 +1947,23 @@ rte_cryptodev_asym_session_create(uint8_t dev_id,
 	if (pool_priv->max_priv_session_sz < session_priv_data_sz) {
 		CDEV_LOG_DEBUG(
 			"The private session data size used when creating the mempool is smaller than this device's private session data.");
-		return NULL;
+		return -EINVAL;
 	}
 
 	/* Verify if provided mempool can hold elements big enough. */
 	if (mp->elt_size < session_header_size + session_priv_data_sz) {
 		CDEV_LOG_ERR(
 			"mempool elements too small to hold session objects");
-		return NULL;
+		return -EINVAL;
 	}
 
 	/* Allocate a session structure from the session pool */
-	if (rte_mempool_get(mp, (void **)&sess)) {
+	if (rte_mempool_get(mp, session)) {
 		CDEV_LOG_ERR("couldn't get object from session mempool");
-		return NULL;
+		return -ENOMEM;
 	}
 
+	sess = *session;
 	sess->driver_id = dev->driver_id;
 	sess->user_data_sz = pool_priv->user_data_sz;
 	sess->max_priv_data_sz = pool_priv->max_priv_session_sz;
@@ -1969,7 +1971,7 @@ rte_cryptodev_asym_session_create(uint8_t dev_id,
 	/* Clear device session pointer.*/
 	memset(sess->sess_private_data, 0, session_priv_data_sz + sess->user_data_sz);
 
-	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->asym_session_configure, NULL);
+	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->asym_session_configure, -ENOTSUP);
 
 	if (sess->sess_private_data[0] == 0) {
 		ret = dev->dev_ops->asym_session_configure(dev, xforms, sess);
@@ -1977,12 +1979,12 @@ rte_cryptodev_asym_session_create(uint8_t dev_id,
 			CDEV_LOG_ERR(
 				"dev_id %d failed to configure session details",
 				dev_id);
-			return NULL;
+			return ret;
 		}
 	}
 
-	rte_cryptodev_trace_asym_session_create(dev_id, xforms, mp);
-	return sess;
+	rte_cryptodev_trace_asym_session_create(dev_id, xforms, mp, sess);
+	return 0;
 }
 
 int
diff --git a/lib/cryptodev/rte_cryptodev.h b/lib/cryptodev/rte_cryptodev.h
index 1d7bd07680..19e2e70287 100644
--- a/lib/cryptodev/rte_cryptodev.h
+++ b/lib/cryptodev/rte_cryptodev.h
@@ -996,14 +996,19 @@ rte_cryptodev_sym_session_create(struct rte_mempool *mempool);
  *                   processed with this session
  * @param   mp       mempool to allocate asymmetric session
  *                   objects from
+ * @param   session  void ** for session to be used
+ *
  * @return
- *  - On success return pointer to asym-session
- *  - On failure returns NULL
+ *  - 0 on success.
+ *  - -EINVAL on invalid arguments.
+ *  - -ENOMEM on memory error for session allocation.
+ *  - -ENOTSUP if device doesn't support session configuration.
  */
 __rte_experimental
-void *
+int
 rte_cryptodev_asym_session_create(uint8_t dev_id,
-		struct rte_crypto_asym_xform *xforms, struct rte_mempool *mp);
+		struct rte_crypto_asym_xform *xforms, struct rte_mempool *mp,
+		void **session);
 
 /**
  * Frees symmetric crypto session header, after checking that all
diff --git a/lib/cryptodev/rte_cryptodev_trace.h b/lib/cryptodev/rte_cryptodev_trace.h
index 005a4fe38b..a3f6048e7d 100644
--- a/lib/cryptodev/rte_cryptodev_trace.h
+++ b/lib/cryptodev/rte_cryptodev_trace.h
@@ -96,10 +96,12 @@ RTE_TRACE_POINT(
 
 RTE_TRACE_POINT(
 	rte_cryptodev_trace_asym_session_create,
-	RTE_TRACE_POINT_ARGS(uint8_t dev_id, void *xforms, void *mempool),
+	RTE_TRACE_POINT_ARGS(uint8_t dev_id, void *xforms, void *mempool,
+			void *sess),
 	rte_trace_point_emit_u8(dev_id);
 	rte_trace_point_emit_ptr(xforms);
 	rte_trace_point_emit_ptr(mempool);
+	rte_trace_point_emit_ptr(sess);
 )
 
 RTE_TRACE_POINT(
-- 
2.25.1


^ permalink raw reply	[flat|nested] 31+ messages in thread

* RE: [EXT] [PATCH v5 2/5] crypto: use single buffer for asymmetric session
  2022-02-10 14:01   ` [PATCH v5 2/5] crypto: use single buffer for asymmetric session Ciara Power
@ 2022-02-10 14:34     ` Anoob Joseph
  0 siblings, 0 replies; 31+ messages in thread
From: Anoob Joseph @ 2022-02-10 14:34 UTC (permalink / raw)
  To: Ciara Power, dev
  Cc: roy.fan.zhang, Akhil Goyal, mdr, Declan Doherty, Ankur Dwivedi,
	Tejasree Kondoj, John Griffin, Fiona Trahe, Deepak Kumar Jain

Hi Ciara,

Minor nit inline. With that

Series Acked-by: Anoob Joseph <anoobj@marvell.com>

Thanks,
Anoob

> -----Original Message-----
> From: Ciara Power <ciara.power@intel.com>
> Sent: Thursday, February 10, 2022 7:32 PM
> To: dev@dpdk.org
> Cc: roy.fan.zhang@intel.com; Akhil Goyal <gakhil@marvell.com>; Anoob Joseph
> <anoobj@marvell.com>; mdr@ashroe.eu; Ciara Power
> <ciara.power@intel.com>; Declan Doherty <declan.doherty@intel.com>; Ankur
> Dwivedi <adwivedi@marvell.com>; Tejasree Kondoj <ktejasree@marvell.com>;
> John Griffin <john.griffin@intel.com>; Fiona Trahe <fiona.trahe@intel.com>;
> Deepak Kumar Jain <deepak.k.jain@intel.com>
> Subject: [EXT] [PATCH v5 2/5] crypto: use single buffer for asymmetric session
> 
> External Email
> 
> ----------------------------------------------------------------------
> Rather than using a session buffer that contains pointers to private
> session data elsewhere, have a single session buffer.
> This session is created for a driver ID, and the mempool element
> contains space for the max session private data needed for any driver.
> 
> Signed-off-by: Ciara Power <ciara.power@intel.com>
> Acked-by: Fan Zhang <roy.fan.zhang@intel.com>
> 
> ---
> v5:
>   - Removed get API for session private data, can be accessed directly.
>   - Modified test application to create a session mempool for
>     TEST_NUM_SESSIONS rather than TEST_NUM_SESSIONS * 2.
>   - Reworded create session function description.
>   - Removed sess parameter from create session trace,
>     to be added in a later patch.
> v4:
>   - Merged asym crypto session clear and free functions.
>   - Reordered some function parameters.
>   - Updated trace function for asym crypto session create.
>   - Fixed cnxk clear, the PMD no longer needs to put private data
>     back into a mempool.
>   - Renamed struct field for max private session size.
>   - Replaced __extension__ with RTE_STD_C11.
>   - Moved some parameter validity checks to before functional code.
>   - Reworded release note.
>   - Removed mempool parameter from session configure function.
>   - Removed docs code additions, these are included due to patch 1
>     changing sample doc to use literal includes.
> v3:
>   - Corrected formatting of struct comments.
>   - Increased size of max_priv_session_sz to uint16_t.
>   - Removed trace for asym session init function that was
>     previously removed.
>   - Added documentation.
> v2:
>   - Renamed function typedef from "free" to "clear" as session private
>     data isn't being freed in that function.
>   - Moved user data API to separate patch.
>   - Minor fixes to comments, formatting, return values.
> ---
>  app/test-crypto-perf/cperf_ops.c             |  14 +-
>  app/test-crypto-perf/cperf_test_throughput.c |   8 +-
>  app/test/test_cryptodev_asym.c               | 272 +++++--------------
>  doc/guides/prog_guide/cryptodev_lib.rst      |  21 +-
>  doc/guides/rel_notes/release_22_03.rst       |   7 +
>  drivers/crypto/cnxk/cn10k_cryptodev_ops.c    |   8 +-
>  drivers/crypto/cnxk/cn9k_cryptodev_ops.c     |   8 +-
>  drivers/crypto/cnxk/cnxk_cryptodev_ops.c     |  22 +-
>  drivers/crypto/cnxk/cnxk_cryptodev_ops.h     |   3 +-
>  drivers/crypto/octeontx/otx_cryptodev_ops.c  |  32 +--
>  drivers/crypto/openssl/rte_openssl_pmd.c     |   4 +-
>  drivers/crypto/openssl/rte_openssl_pmd_ops.c |  24 +-
>  drivers/crypto/qat/qat_asym.c                |  54 +---
>  drivers/crypto/qat/qat_asym.h                |   5 +-
>  lib/cryptodev/cryptodev_pmd.h                |  23 +-
>  lib/cryptodev/cryptodev_trace_points.c       |   9 +-
>  lib/cryptodev/rte_cryptodev.c                | 213 ++++++++-------
>  lib/cryptodev/rte_cryptodev.h                |  97 ++++---
>  lib/cryptodev/rte_cryptodev_trace.h          |  38 ++-
>  lib/cryptodev/version.map                    |   7 +-
>  20 files changed, 315 insertions(+), 554 deletions(-)
> 

[snip]

> diff --git a/drivers/crypto/cnxk/cnxk_cryptodev_ops.c
> b/drivers/crypto/cnxk/cnxk_cryptodev_ops.c
> index a5fb68da02..72f5f1a6fe 100644
> --- a/drivers/crypto/cnxk/cnxk_cryptodev_ops.c
> +++ b/drivers/crypto/cnxk/cnxk_cryptodev_ops.c
> @@ -658,10 +658,9 @@ void
>  cnxk_ae_session_clear(struct rte_cryptodev *dev,
>  		      struct rte_cryptodev_asym_session *sess)
>  {
> -	struct rte_mempool *sess_mp;
>  	struct cnxk_ae_sess *priv;
> 
> -	priv = get_asym_session_private_data(sess, dev->driver_id);
> +	priv = (struct cnxk_ae_sess *) sess->sess_private_data;
>  	if (priv == NULL)
>  		return;
> 
> @@ -670,40 +669,29 @@ cnxk_ae_session_clear(struct rte_cryptodev *dev,
> 
>  	/* Reset and free object back to pool */
>  	memset(priv, 0, cnxk_ae_session_size_get(dev));
> -	sess_mp = rte_mempool_from_obj(priv);
> -	set_asym_session_private_data(sess, dev->driver_id, NULL);
> -	rte_mempool_put(sess_mp, priv);
>  }
> 
>  int
>  cnxk_ae_session_cfg(struct rte_cryptodev *dev,
>  		    struct rte_crypto_asym_xform *xform,
> -		    struct rte_cryptodev_asym_session *sess,
> -		    struct rte_mempool *pool)
> +		    struct rte_cryptodev_asym_session *sess)
>  {
>  	struct cnxk_cpt_vf *vf = dev->data->dev_private;
>  	struct roc_cpt *roc_cpt = &vf->cpt;
> -	struct cnxk_ae_sess *priv;
> +	struct cnxk_ae_sess *priv =
> +			(struct cnxk_ae_sess *) sess->sess_private_data;

[Anoob] Rest of the code in cnxk follows reverse xmas tree. May be, can you move this up? Or may be just split declaration and assignment and you can retain the existing order?


^ permalink raw reply	[flat|nested] 31+ messages in thread

* [PATCH v6 0/5] crypto: improve asym session usage
  2022-02-09 15:38 [PATCH v4 0/5] crypto: improve asym session usage Ciara Power
                   ` (5 preceding siblings ...)
  2022-02-10 14:01 ` [PATCH v5 0/5] crypto: improve asym session usage Ciara Power
@ 2022-02-10 15:53 ` Ciara Power
  2022-02-10 15:54   ` [PATCH v6 1/5] doc: replace asym crypto code with literal includes Ciara Power
                     ` (5 more replies)
  2022-02-11  9:29 ` [PATCH v7 " Ciara Power
  7 siblings, 6 replies; 31+ messages in thread
From: Ciara Power @ 2022-02-10 15:53 UTC (permalink / raw)
  To: dev; +Cc: roy.fan.zhang, gakhil, anoobj, mdr, Ciara Power

This patchset includes improvements for the asymmetric session.
The main change is to the session structure, which is now a single
mempool object, rather than having pointers to private data elsewhere.
This session structure is now hidden in an internal header,
so the app will never use it directly.

Some other changes include adding a user data API, and modifying
the return value for the create session function.
This create session function now also initialises the session,
and subsequently the clear/free functions have been merged into one.

Sample code in the programmer's guide that showed basic steps for
using Asymmetric crypto in DPDK has been replaced with literal includes
in the first patch of this patchset. This ensures all subsequent code
changes in the patchset are automatically reflected in the documentation.

v6:
  - Reordered variable declarations to follow cnxk file format.
  - Added fix for crypto perf app asymmetric modex operation, there
    is no longer a need for private mempool, and the
    rte_cryptodev_asym_session_pool_create API should be used.

v5:
  - Modified which patch the sess parameter is passed to session create
    trace function.
  - Reworded create session function description.
  - Removed get API for session private data, can be accessed directly.
  - Modified test application to create a session mempool for
    TEST_NUM_SESSIONS rather than TEST_NUM_SESSIONS * 2.

v4:
  - Added new patch to add literal includes usage in programmer's guide.
  - Merged asym crypto session clear and free functions.
  - Reordered some function parameters.
  - Updated trace function for asym crypto session create.
  - Fixed cnxk clear, the PMD no longer needs to put private data
    back into a mempool.
  - Renamed struct field for max private session size.
  - Replaced __extension__ with RTE_STD_C11.
  - Moved some parameter validity checks to before functional code.
  - Reworded release note.
  - Removed mempool parameter from session configure function.
  - Removed docs code additions, these are included due to patch 1
    changing sample doc to use literal includes.
  - Initialised session variables as NULL.
  - Added possible error return values in user data API comment.

v3:
  - Added documentation in relevant patches.
  - Fixed setting user data size.
  - Fixed hiding structure, it should not be hidden from PMDs.
  - Fixed some other small formatting issues.
  - Increased size of max_priv_session_sz to uint16_t.
  - Removed trace for asym session init function that was
    previously removed.

Ciara Power (5):
  doc: replace asym crypto code with literal includes
  crypto: use single buffer for asymmetric session
  crypto: hide asym session structure
  crypto: add asym session user data API
  crypto: modify return value for asym session create

 app/test-crypto-perf/cperf_ops.c             |  22 +-
 app/test-crypto-perf/cperf_test_throughput.c |   8 +-
 app/test-crypto-perf/main.c                  |  26 +-
 app/test/test_cryptodev_asym.c               | 380 ++++++-------------
 app/test/test_cryptodev_mod_test_vectors.h   |   4 +
 doc/guides/prog_guide/cryptodev_lib.rst      | 212 +++--------
 doc/guides/rel_notes/release_22_03.rst       |  14 +
 drivers/crypto/cnxk/cn10k_cryptodev_ops.c    |   8 +-
 drivers/crypto/cnxk/cn9k_cryptodev_ops.c     |   8 +-
 drivers/crypto/cnxk/cnxk_cryptodev_ops.c     |  22 +-
 drivers/crypto/cnxk/cnxk_cryptodev_ops.h     |   3 +-
 drivers/crypto/octeontx/otx_cryptodev_ops.c  |  32 +-
 drivers/crypto/openssl/rte_openssl_pmd.c     |   4 +-
 drivers/crypto/openssl/rte_openssl_pmd_ops.c |  24 +-
 drivers/crypto/qat/qat_asym.c                |  54 +--
 drivers/crypto/qat/qat_asym.h                |   5 +-
 lib/cryptodev/cryptodev_pmd.h                |  36 +-
 lib/cryptodev/cryptodev_trace_points.c       |   9 +-
 lib/cryptodev/rte_cryptodev.c                | 258 ++++++++-----
 lib/cryptodev/rte_cryptodev.h                | 136 ++++---
 lib/cryptodev/rte_cryptodev_trace.h          |  38 +-
 lib/cryptodev/version.map                    |   9 +-
 22 files changed, 526 insertions(+), 786 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 31+ messages in thread

* [PATCH v6 1/5] doc: replace asym crypto code with literal includes
  2022-02-10 15:53 ` [PATCH v6 0/5] crypto: improve asym session usage Ciara Power
@ 2022-02-10 15:54   ` Ciara Power
  2022-02-10 16:36     ` Zhang, Roy Fan
  2022-02-10 15:54   ` [PATCH v6 2/5] crypto: use single buffer for asymmetric session Ciara Power
                     ` (4 subsequent siblings)
  5 siblings, 1 reply; 31+ messages in thread
From: Ciara Power @ 2022-02-10 15:54 UTC (permalink / raw)
  To: dev; +Cc: roy.fan.zhang, gakhil, anoobj, mdr, Ciara Power, Declan Doherty

The programmer's guide for cryptodev included sample code for using
Asymmetric crypto. This is now replaced with direct code from the test
application, using literal includes. It is broken into snippets as the
test application didn't have all of the required code in one function.

Signed-off-by: Ciara Power <ciara.power@intel.com>
Acked-by: Anoob Joseph <anoobj@marvell.com>
---
 app/test/test_cryptodev_asym.c             |   7 +-
 app/test/test_cryptodev_mod_test_vectors.h |   4 +
 doc/guides/prog_guide/cryptodev_lib.rst    | 176 ++++-----------------
 3 files changed, 37 insertions(+), 150 deletions(-)

diff --git a/app/test/test_cryptodev_asym.c b/app/test/test_cryptodev_asym.c
index 9d3a5589bb..8d7290f9ed 100644
--- a/app/test/test_cryptodev_asym.c
+++ b/app/test/test_cryptodev_asym.c
@@ -855,6 +855,7 @@ testsuite_setup(void)
 	test_vector.size = 0;
 	load_test_vectors();
 
+	/* Device, op pool and session configuration for asymmetric crypto. 8< */
 	ts_params->op_mpool = rte_crypto_op_pool_create(
 			"CRYPTO_ASYM_OP_POOL",
 			RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
@@ -953,7 +954,7 @@ testsuite_setup(void)
 
 	TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
 			"session mempool allocation failed");
-
+	/* >8 End of device, op pool and session configuration for asymmetric crypto section. */
 	return TEST_SUCCESS;
 }
 
@@ -1637,7 +1638,7 @@ test_mod_exp(void)
 				return TEST_SKIPPED;
 		}
 
-	/* generate crypto op data structure */
+	/* Create op, create session, and process packets. 8< */
 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
 	if (!op) {
 		RTE_LOG(ERR, USER1,
@@ -1696,7 +1697,7 @@ test_mod_exp(void)
 		status = TEST_FAILED;
 		goto error_exit;
 	}
-
+	/* >8 End of create op, create session, and process packets section. */
 	ret = verify_modexp(mod_exp, result_op);
 	if (ret) {
 		RTE_LOG(ERR, USER1,
diff --git a/app/test/test_cryptodev_mod_test_vectors.h b/app/test/test_cryptodev_mod_test_vectors.h
index c66f4b18bc..807ca7a47e 100644
--- a/app/test/test_cryptodev_mod_test_vectors.h
+++ b/app/test/test_cryptodev_mod_test_vectors.h
@@ -979,6 +979,7 @@ uint8_t base[] = {
 	0xA8, 0xEB, 0x7E, 0x78, 0xA0, 0x50
 };
 
+/* MODEX data. 8< */
 uint8_t mod_p[] = {
 	0x00, 0xb3, 0xa1, 0xaf, 0xb7, 0x13, 0x08, 0x00,
 	0x0a, 0x35, 0xdc, 0x2b, 0x20, 0x8d, 0xa1, 0xb5,
@@ -1000,6 +1001,7 @@ uint8_t mod_p[] = {
 };
 
 uint8_t mod_e[] = {0x01, 0x00, 0x01};
+/* >8 End of MODEX data. */
 
 /* Precomputed modular exponentiation for verification */
 uint8_t mod_exp[] = {
@@ -1041,6 +1043,7 @@ uint8_t mod_inv[] = {
 	0x9a, 0x66, 0x9a, 0x3a, 0xc1, 0xb8, 0x4b, 0xc3
 };
 
+/* MODEX vector. 8< */
 struct rte_crypto_asym_xform modex_xform = {
 	.next = NULL,
 	.xform_type = RTE_CRYPTO_ASYM_XFORM_MODEX,
@@ -1055,6 +1058,7 @@ struct rte_crypto_asym_xform modex_xform = {
 		}
 	}
 };
+/* >8 End of MODEX vector. */
 
 struct rte_crypto_asym_xform modinv_xform = {
 	.next = NULL,
diff --git a/doc/guides/prog_guide/cryptodev_lib.rst b/doc/guides/prog_guide/cryptodev_lib.rst
index 8766bc34a9..9f33f7a177 100644
--- a/doc/guides/prog_guide/cryptodev_lib.rst
+++ b/doc/guides/prog_guide/cryptodev_lib.rst
@@ -1119,162 +1119,44 @@ Asymmetric crypto Sample code
 There's a unit test application test_cryptodev_asym.c inside unit test framework that
 show how to setup and process asymmetric operations using cryptodev library.
 
-The following sample code shows the basic steps to compute modular exponentiation
-using 1024-bit modulus length using openssl PMD available in DPDK (performing other
-crypto operations is similar except change to respective op and xform setup).
+The following code samples are taken from the test application mentioned above,
+and show basic steps to compute modular exponentiation using an openssl PMD
+available in DPDK (performing other crypto operations is similar except change
+to respective op and xform setup).
 
-.. code-block:: c
+.. note::
+   The following code snippets are taken from multiple functions, so variable
+   names may differ slightly between sections.
 
-    /*
-     * Simple example to compute modular exponentiation with 1024-bit key
-     *
-     */
-    #define MAX_ASYM_SESSIONS	10
-    #define NUM_ASYM_BUFS	10
-
-    struct rte_mempool *crypto_op_pool, *asym_session_pool;
-    unsigned int asym_session_size;
-    int ret;
+Configure the virtual device, queue pairs, crypto op pool and session mempool.
 
-    /* Initialize EAL. */
-    ret = rte_eal_init(argc, argv);
-    if (ret < 0)
-        rte_exit(EXIT_FAILURE, "Invalid EAL arguments\n");
+.. literalinclude:: ../../../app/test/test_cryptodev_asym.c
+   :language: c
+   :start-after: Device, op pool and session configuration for asymmetric crypto. 8<
+   :end-before: >8 End of device, op pool and session configuration for asymmetric crypto section.
+   :dedent: 1
 
-    uint8_t socket_id = rte_socket_id();
-
-    /* Create crypto operation pool. */
-    crypto_op_pool = rte_crypto_op_pool_create(
-                                    "crypto_op_pool",
-                                    RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
-                                    NUM_ASYM_BUFS, 0, 0,
-                                    socket_id);
-    if (crypto_op_pool == NULL)
-        rte_exit(EXIT_FAILURE, "Cannot create crypto op pool\n");
-
-    /* Create the virtual crypto device. */
-    char args[128];
-    const char *crypto_name = "crypto_openssl";
-    snprintf(args, sizeof(args), "socket_id=%d", socket_id);
-    ret = rte_vdev_init(crypto_name, args);
-    if (ret != 0)
-        rte_exit(EXIT_FAILURE, "Cannot create virtual device");
+Create MODEX data vectors.
 
-    uint8_t cdev_id = rte_cryptodev_get_dev_id(crypto_name);
+.. literalinclude:: ../../../app/test/test_cryptodev_mod_test_vectors.h
+   :language: c
+   :start-after: MODEX data. 8<
+   :end-before: >8 End of MODEX data.
 
-    /* Get private asym session data size. */
-    asym_session_size = rte_cryptodev_get_asym_private_session_size(cdev_id);
+Setup crypto xform to do modular exponentiation using data vectors.
 
-    /*
-     * Create session mempool, with two objects per session,
-     * one for the session header and another one for the
-     * private asym session data for the crypto device.
-     */
-    asym_session_pool = rte_mempool_create("asym_session_pool",
-                                    MAX_ASYM_SESSIONS * 2,
-                                    asym_session_size,
-                                    0,
-                                    0, NULL, NULL, NULL,
-                                    NULL, socket_id,
-                                    0);
+.. literalinclude:: ../../../app/test/test_cryptodev_mod_test_vectors.h
+   :language: c
+   :start-after: MODEX vector. 8<
+   :end-before: >8 End of MODEX vector.
 
-    /* Configure the crypto device. */
-    struct rte_cryptodev_config conf = {
-        .nb_queue_pairs = 1,
-        .socket_id = socket_id
-    };
-    struct rte_cryptodev_qp_conf qp_conf = {
-        .nb_descriptors = 2048
-    };
+Generate crypto op, create and attach a session, then process packets.
 
-    if (rte_cryptodev_configure(cdev_id, &conf) < 0)
-        rte_exit(EXIT_FAILURE, "Failed to configure cryptodev %u", cdev_id);
-
-    if (rte_cryptodev_queue_pair_setup(cdev_id, 0, &qp_conf,
-                            socket_id, asym_session_pool) < 0)
-        rte_exit(EXIT_FAILURE, "Failed to setup queue pair\n");
-
-    if (rte_cryptodev_start(cdev_id) < 0)
-        rte_exit(EXIT_FAILURE, "Failed to start device\n");
-
-    /* Setup crypto xform to do modular exponentiation with 1024 bit
-	 * length modulus
-	 */
-    struct rte_crypto_asym_xform modex_xform = {
-		.next = NULL,
-		.xform_type = RTE_CRYPTO_ASYM_XFORM_MODEX,
-		.modex = {
-			.modulus = {
-				.data =
-				(uint8_t *)
-				("\xb3\xa1\xaf\xb7\x13\x08\x00\x0a\x35\xdc\x2b\x20\x8d"
-				"\xa1\xb5\xce\x47\x8a\xc3\x80\xf4\x7d\x4a\xa2\x62\xfd\x61\x7f"
-				"\xb5\xa8\xde\x0a\x17\x97\xa0\xbf\xdf\x56\x5a\x3d\x51\x56\x4f"
-				"\x70\x70\x3f\x63\x6a\x44\x5b\xad\x84\x0d\x3f\x27\x6e\x3b\x34"
-				"\x91\x60\x14\xb9\xaa\x72\xfd\xa3\x64\xd2\x03\xa7\x53\x87\x9e"
-				"\x88\x0b\xc1\x14\x93\x1a\x62\xff\xb1\x5d\x74\xcd\x59\x63\x18"
-				"\x11\x3d\x4f\xba\x75\xd4\x33\x4e\x23\x6b\x7b\x57\x44\xe1\xd3"
-				"\x03\x13\xa6\xf0\x8b\x60\xb0\x9e\xee\x75\x08\x9d\x71\x63\x13"
-				"\xcb\xa6\x81\x92\x14\x03\x22\x2d\xde\x55"),
-				.length = 128
-			},
-			.exponent = {
-				.data = (uint8_t *)("\x01\x00\x01"),
-				.length = 3
-			}
-		}
-    };
-    /* Create asym crypto session and initialize it for the crypto device. */
-    struct rte_cryptodev_asym_session *asym_session;
-    asym_session = rte_cryptodev_asym_session_create(asym_session_pool);
-    if (asym_session == NULL)
-        rte_exit(EXIT_FAILURE, "Session could not be created\n");
-
-    if (rte_cryptodev_asym_session_init(cdev_id, asym_session,
-                    &modex_xform, asym_session_pool) < 0)
-        rte_exit(EXIT_FAILURE, "Session could not be initialized "
-                    "for the crypto device\n");
-
-    /* Get a burst of crypto operations. */
-    struct rte_crypto_op *crypto_ops[1];
-    if (rte_crypto_op_bulk_alloc(crypto_op_pool,
-                            RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
-                            crypto_ops, 1) == 0)
-        rte_exit(EXIT_FAILURE, "Not enough crypto operations available\n");
-
-    /* Set up the crypto operations. */
-    struct rte_crypto_asym_op *asym_op = crypto_ops[0]->asym;
-
-	/* calculate mod exp of value 0xf8 */
-    static unsigned char base[] = {0xF8};
-    asym_op->modex.base.data = base;
-    asym_op->modex.base.length = sizeof(base);
-	asym_op->modex.base.iova = base;
-
-    /* Attach the asym crypto session to the operation */
-    rte_crypto_op_attach_asym_session(op, asym_session);
-
-    /* Enqueue the crypto operations in the crypto device. */
-    uint16_t num_enqueued_ops = rte_cryptodev_enqueue_burst(cdev_id, 0,
-                                            crypto_ops, 1);
-
-    /*
-     * Dequeue the crypto operations until all the operations
-     * are processed in the crypto device.
-     */
-    uint16_t num_dequeued_ops, total_num_dequeued_ops = 0;
-    do {
-        struct rte_crypto_op *dequeued_ops[1];
-        num_dequeued_ops = rte_cryptodev_dequeue_burst(cdev_id, 0,
-                                        dequeued_ops, 1);
-        total_num_dequeued_ops += num_dequeued_ops;
-
-        /* Check if operation was processed successfully */
-        if (dequeued_ops[0]->status != RTE_CRYPTO_OP_STATUS_SUCCESS)
-                rte_exit(EXIT_FAILURE,
-                        "Some operations were not processed correctly");
-
-    } while (total_num_dequeued_ops < num_enqueued_ops);
+.. literalinclude:: ../../../app/test/test_cryptodev_asym.c
+   :language: c
+   :start-after: Create op, create session, and process packets. 8<
+   :end-before: >8 End of create op, create session, and process packets section.
+   :dedent: 1
 
 
 Asymmetric Crypto Device API
-- 
2.25.1


^ permalink raw reply	[flat|nested] 31+ messages in thread

* [PATCH v6 2/5] crypto: use single buffer for asymmetric session
  2022-02-10 15:53 ` [PATCH v6 0/5] crypto: improve asym session usage Ciara Power
  2022-02-10 15:54   ` [PATCH v6 1/5] doc: replace asym crypto code with literal includes Ciara Power
@ 2022-02-10 15:54   ` Ciara Power
  2022-02-10 15:54   ` [PATCH v6 3/5] crypto: hide asym session structure Ciara Power
                     ` (3 subsequent siblings)
  5 siblings, 0 replies; 31+ messages in thread
From: Ciara Power @ 2022-02-10 15:54 UTC (permalink / raw)
  To: dev
  Cc: roy.fan.zhang, gakhil, anoobj, mdr, Ciara Power, Declan Doherty,
	Ankur Dwivedi, Tejasree Kondoj, John Griffin, Fiona Trahe,
	Deepak Kumar Jain

Rather than using a session buffer that contains pointers to private
session data elsewhere, have a single session buffer.
This session is created for a driver ID, and the mempool element
contains space for the max session private data needed for any driver.

Signed-off-by: Ciara Power <ciara.power@intel.com>
Acked-by: Fan Zhang <roy.fan.zhang@intel.com>
Acked-by: Anoob Joseph <anoobj@marvell.com>

---
v6:
  - Reordered variable declarations to follow cnxk file format.
  - Added fix for crypto perf app asymmetric modex operation, there
    is no longer a need for private mempool, and the
    rte_cryptodev_asym_session_pool_create API should be used.
v5:
  - Removed get API for session private data, can be accessed directly.
  - Modified test application to create a session mempool for
    TEST_NUM_SESSIONS rather than TEST_NUM_SESSIONS * 2.
  - Reworded create session function description.
  - Removed sess parameter from create session trace,
    to be added in a later patch.
v4:
  - Merged asym crypto session clear and free functions.
  - Reordered some function parameters.
  - Updated trace function for asym crypto session create.
  - Fixed cnxk clear, the PMD no longer needs to put private data
    back into a mempool.
  - Renamed struct field for max private session size.
  - Replaced __extension__ with RTE_STD_C11.
  - Moved some parameter validity checks to before functional code.
  - Reworded release note.
  - Removed mempool parameter from session configure function.
  - Removed docs code additions, these are included due to patch 1
    changing sample doc to use literal includes.
v3:
  - Corrected formatting of struct comments.
  - Increased size of max_priv_session_sz to uint16_t.
  - Removed trace for asym session init function that was
    previously removed.
  - Added documentation.
v2:
  - Renamed function typedef from "free" to "clear" as session private
    data isn't being freed in that function.
  - Moved user data API to separate patch.
  - Minor fixes to comments, formatting, return values.
---
 app/test-crypto-perf/cperf_ops.c             |  14 +-
 app/test-crypto-perf/cperf_test_throughput.c |   8 +-
 app/test-crypto-perf/main.c                  |  26 +-
 app/test/test_cryptodev_asym.c               | 272 +++++--------------
 doc/guides/prog_guide/cryptodev_lib.rst      |  21 +-
 doc/guides/rel_notes/release_22_03.rst       |   7 +
 drivers/crypto/cnxk/cn10k_cryptodev_ops.c    |   8 +-
 drivers/crypto/cnxk/cn9k_cryptodev_ops.c     |   8 +-
 drivers/crypto/cnxk/cnxk_cryptodev_ops.c     |  22 +-
 drivers/crypto/cnxk/cnxk_cryptodev_ops.h     |   3 +-
 drivers/crypto/octeontx/otx_cryptodev_ops.c  |  32 +--
 drivers/crypto/openssl/rte_openssl_pmd.c     |   4 +-
 drivers/crypto/openssl/rte_openssl_pmd_ops.c |  24 +-
 drivers/crypto/qat/qat_asym.c                |  54 +---
 drivers/crypto/qat/qat_asym.h                |   5 +-
 lib/cryptodev/cryptodev_pmd.h                |  23 +-
 lib/cryptodev/cryptodev_trace_points.c       |   9 +-
 lib/cryptodev/rte_cryptodev.c                | 213 ++++++++-------
 lib/cryptodev/rte_cryptodev.h                |  97 ++++---
 lib/cryptodev/rte_cryptodev_trace.h          |  38 ++-
 lib/cryptodev/version.map                    |   7 +-
 21 files changed, 317 insertions(+), 578 deletions(-)

diff --git a/app/test-crypto-perf/cperf_ops.c b/app/test-crypto-perf/cperf_ops.c
index d975ae1ab8..b125c699de 100644
--- a/app/test-crypto-perf/cperf_ops.c
+++ b/app/test-crypto-perf/cperf_ops.c
@@ -735,7 +735,6 @@ cperf_create_session(struct rte_mempool *sess_mp,
 	struct rte_crypto_sym_xform aead_xform;
 	struct rte_cryptodev_sym_session *sess = NULL;
 	struct rte_crypto_asym_xform xform = {0};
-	int rc;
 
 	if (options->op_type == CPERF_ASYM_MODEX) {
 		xform.next = NULL;
@@ -745,19 +744,10 @@ cperf_create_session(struct rte_mempool *sess_mp,
 		xform.modex.exponent.data = perf_mod_e;
 		xform.modex.exponent.length = sizeof(perf_mod_e);
 
-		sess = (void *)rte_cryptodev_asym_session_create(sess_mp);
+		sess = (void *)rte_cryptodev_asym_session_create(dev_id, &xform, sess_mp);
 		if (sess == NULL)
 			return NULL;
-		rc = rte_cryptodev_asym_session_init(dev_id, (void *)sess,
-						     &xform, priv_mp);
-		if (rc < 0) {
-			if (sess != NULL) {
-				rte_cryptodev_asym_session_clear(dev_id,
-								 (void *)sess);
-				rte_cryptodev_asym_session_free((void *)sess);
-			}
-			return NULL;
-		}
+
 		return sess;
 	}
 #ifdef RTE_LIB_SECURITY
diff --git a/app/test-crypto-perf/cperf_test_throughput.c b/app/test-crypto-perf/cperf_test_throughput.c
index 51512af2ad..ee21ff27f7 100644
--- a/app/test-crypto-perf/cperf_test_throughput.c
+++ b/app/test-crypto-perf/cperf_test_throughput.c
@@ -35,11 +35,9 @@ cperf_throughput_test_free(struct cperf_throughput_ctx *ctx)
 	if (!ctx)
 		return;
 	if (ctx->sess) {
-		if (ctx->options->op_type == CPERF_ASYM_MODEX) {
-			rte_cryptodev_asym_session_clear(ctx->dev_id,
-							 (void *)ctx->sess);
-			rte_cryptodev_asym_session_free((void *)ctx->sess);
-		}
+		if (ctx->options->op_type == CPERF_ASYM_MODEX)
+			rte_cryptodev_asym_session_free(ctx->dev_id,
+					(void *)ctx->sess);
 #ifdef RTE_LIB_SECURITY
 		else if (ctx->options->op_type == CPERF_PDCP ||
 			 ctx->options->op_type == CPERF_DOCSIS ||
diff --git a/app/test-crypto-perf/main.c b/app/test-crypto-perf/main.c
index 6fdb92fb7c..115bf923f8 100644
--- a/app/test-crypto-perf/main.c
+++ b/app/test-crypto-perf/main.c
@@ -74,34 +74,12 @@ create_asym_op_pool_socket(uint8_t dev_id, int32_t socket_id,
 {
 	char mp_name[RTE_MEMPOOL_NAMESIZE];
 	struct rte_mempool *mpool = NULL;
-	unsigned int session_size =
-		RTE_MAX(rte_cryptodev_asym_get_private_session_size(dev_id),
-			rte_cryptodev_asym_get_header_session_size());
-
-	if (session_pool_socket[socket_id].priv_mp == NULL) {
-		snprintf(mp_name, RTE_MEMPOOL_NAMESIZE, "perf_asym_priv_pool%u",
-			 socket_id);
-
-		mpool = rte_mempool_create(mp_name, nb_sessions, session_size,
-					   0, 0, NULL, NULL, NULL, NULL,
-					   socket_id, 0);
-		if (mpool == NULL) {
-			printf("Cannot create pool \"%s\" on socket %d\n",
-			       mp_name, socket_id);
-			return -ENOMEM;
-		}
-		printf("Allocated pool \"%s\" on socket %d\n", mp_name,
-		       socket_id);
-		session_pool_socket[socket_id].priv_mp = mpool;
-	}
 
 	if (session_pool_socket[socket_id].sess_mp == NULL) {
-
 		snprintf(mp_name, RTE_MEMPOOL_NAMESIZE, "perf_asym_sess_pool%u",
 			 socket_id);
-		mpool = rte_mempool_create(mp_name, nb_sessions,
-					   session_size, 0, 0, NULL, NULL, NULL,
-					   NULL, socket_id, 0);
+		mpool = rte_cryptodev_asym_session_pool_create(mp_name,
+				nb_sessions, 0, socket_id);
 		if (mpool == NULL) {
 			printf("Cannot create pool \"%s\" on socket %d\n",
 			       mp_name, socket_id);
diff --git a/app/test/test_cryptodev_asym.c b/app/test/test_cryptodev_asym.c
index 8d7290f9ed..88433faf1c 100644
--- a/app/test/test_cryptodev_asym.c
+++ b/app/test/test_cryptodev_asym.c
@@ -452,7 +452,8 @@ test_cryptodev_asym_op(struct crypto_testsuite_params_asym *ts_params,
 	}
 
 	if (!sessionless) {
-		sess = rte_cryptodev_asym_session_create(ts_params->session_mpool);
+		sess = rte_cryptodev_asym_session_create(dev_id, &xform_tc,
+				ts_params->session_mpool);
 		if (!sess) {
 			snprintf(test_msg, ASYM_TEST_MSG_LEN,
 					"line %u "
@@ -462,15 +463,6 @@ test_cryptodev_asym_op(struct crypto_testsuite_params_asym *ts_params,
 			goto error_exit;
 		}
 
-		if (rte_cryptodev_asym_session_init(dev_id, sess, &xform_tc,
-				ts_params->session_mpool) < 0) {
-			snprintf(test_msg, ASYM_TEST_MSG_LEN,
-					"line %u FAILED: %s",
-					__LINE__, "unabled to config sym session");
-			status = TEST_FAILED;
-			goto error_exit;
-		}
-
 		rte_crypto_op_attach_asym_session(op, sess);
 	} else {
 		asym_op->xform = &xform_tc;
@@ -512,10 +504,8 @@ test_cryptodev_asym_op(struct crypto_testsuite_params_asym *ts_params,
 		snprintf(test_msg, ASYM_TEST_MSG_LEN, "SESSIONLESS PASS");
 
 error_exit:
-		if (sess != NULL) {
-			rte_cryptodev_asym_session_clear(dev_id, sess);
-			rte_cryptodev_asym_session_free(sess);
-		}
+		if (sess != NULL)
+			rte_cryptodev_asym_session_free(dev_id, sess);
 
 		if (op != NULL)
 			rte_crypto_op_free(op);
@@ -669,18 +659,11 @@ test_rsa_sign_verify(void)
 		return TEST_SKIPPED;
 	}
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
+	sess = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool);
 
 	if (!sess) {
 		RTE_LOG(ERR, USER1, "Session creation failed for "
 			"sign_verify\n");
-		return TEST_FAILED;
-	}
-
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform,
-				sess_mpool) < 0) {
-		RTE_LOG(ERR, USER1, "Unable to config asym session for "
-			"sign_verify\n");
 		status = TEST_FAILED;
 		goto error_exit;
 	}
@@ -688,9 +671,7 @@ test_rsa_sign_verify(void)
 	status = queue_ops_rsa_sign_verify(sess);
 
 error_exit:
-
-	rte_cryptodev_asym_session_clear(dev_id, sess);
-	rte_cryptodev_asym_session_free(sess);
+	rte_cryptodev_asym_session_free(dev_id, sess);
 
 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
 
@@ -718,17 +699,10 @@ test_rsa_enc_dec(void)
 		return TEST_SKIPPED;
 	}
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
+	sess = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool);
 
 	if (!sess) {
 		RTE_LOG(ERR, USER1, "Session creation failed for enc_dec\n");
-		return TEST_FAILED;
-	}
-
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform,
-				sess_mpool) < 0) {
-		RTE_LOG(ERR, USER1, "Unable to config asym session for "
-			"enc_dec\n");
 		status = TEST_FAILED;
 		goto error_exit;
 	}
@@ -737,8 +711,7 @@ test_rsa_enc_dec(void)
 
 error_exit:
 
-	rte_cryptodev_asym_session_clear(dev_id, sess);
-	rte_cryptodev_asym_session_free(sess);
+	rte_cryptodev_asym_session_free(dev_id, sess);
 
 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
 
@@ -765,28 +738,20 @@ test_rsa_sign_verify_crt(void)
 		return TEST_SKIPPED;
 	}
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
+	sess = rte_cryptodev_asym_session_create(dev_id, &rsa_xform_crt, sess_mpool);
 
 	if (!sess) {
 		RTE_LOG(ERR, USER1, "Session creation failed for "
 			"sign_verify_crt\n");
 		status = TEST_FAILED;
-		return status;
-	}
-
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform_crt,
-				sess_mpool) < 0) {
-		RTE_LOG(ERR, USER1, "Unable to config asym session for "
-			"sign_verify_crt\n");
-		status = TEST_FAILED;
 		goto error_exit;
 	}
+
 	status = queue_ops_rsa_sign_verify(sess);
 
 error_exit:
 
-	rte_cryptodev_asym_session_clear(dev_id, sess);
-	rte_cryptodev_asym_session_free(sess);
+	rte_cryptodev_asym_session_free(dev_id, sess);
 
 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
 
@@ -813,27 +778,20 @@ test_rsa_enc_dec_crt(void)
 		return TEST_SKIPPED;
 	}
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
+	sess = rte_cryptodev_asym_session_create(dev_id, &rsa_xform_crt, sess_mpool);
 
 	if (!sess) {
 		RTE_LOG(ERR, USER1, "Session creation failed for "
 			"enc_dec_crt\n");
-		return TEST_FAILED;
-	}
-
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform_crt,
-				sess_mpool) < 0) {
-		RTE_LOG(ERR, USER1, "Unable to config asym session for "
-			"enc_dec_crt\n");
 		status = TEST_FAILED;
 		goto error_exit;
 	}
+
 	status = queue_ops_rsa_enc_dec(sess);
 
 error_exit:
 
-	rte_cryptodev_asym_session_clear(dev_id, sess);
-	rte_cryptodev_asym_session_free(sess);
+	rte_cryptodev_asym_session_free(dev_id, sess);
 
 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
 
@@ -927,7 +885,6 @@ testsuite_setup(void)
 	/* configure qp */
 	ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
 	ts_params->qp_conf.mp_session = ts_params->session_mpool;
-	ts_params->qp_conf.mp_session_private = ts_params->session_mpool;
 	for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
 			dev_id, qp_id, &ts_params->qp_conf,
@@ -936,21 +893,9 @@ testsuite_setup(void)
 			qp_id, dev_id);
 	}
 
-	/* setup asym session pool */
-	unsigned int session_size = RTE_MAX(
-		rte_cryptodev_asym_get_private_session_size(dev_id),
-		rte_cryptodev_asym_get_header_session_size());
-	/*
-	 * Create mempool with TEST_NUM_SESSIONS * 2,
-	 * to include the session headers
-	 */
-	ts_params->session_mpool = rte_mempool_create(
-				"test_asym_sess_mp",
-				TEST_NUM_SESSIONS * 2,
-				session_size,
-				0, 0, NULL, NULL, NULL,
-				NULL, SOCKET_ID_ANY,
-				0);
+	ts_params->session_mpool = rte_cryptodev_asym_session_pool_create(
+			"test_asym_sess_mp", TEST_NUM_SESSIONS, 0,
+			SOCKET_ID_ANY);
 
 	TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
 			"session mempool allocation failed");
@@ -1107,14 +1052,6 @@ test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
 	struct rte_crypto_asym_xform xform = *xfrm;
 	uint8_t peer[] = "01234567890123456789012345678901234567890123456789";
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
-	if (sess == NULL) {
-		RTE_LOG(ERR, USER1,
-				"line %u FAILED: %s", __LINE__,
-				"Session creation failed");
-		status = TEST_FAILED;
-		goto error_exit;
-	}
 	/* set up crypto op data structure */
 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
 	if (!op) {
@@ -1137,11 +1074,11 @@ test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
 	asym_op->dh.shared_secret.data = output;
 	asym_op->dh.shared_secret.length = sizeof(output);
 
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
-			sess_mpool) < 0) {
+	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
+	if (sess == NULL) {
 		RTE_LOG(ERR, USER1,
-				"line %u FAILED: %s",
-				__LINE__, "unabled to config sym session");
+				"line %u FAILED: %s", __LINE__,
+				"Session creation failed");
 		status = TEST_FAILED;
 		goto error_exit;
 	}
@@ -1176,10 +1113,8 @@ test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
 			asym_op->dh.shared_secret.length);
 
 error_exit:
-	if (sess != NULL) {
-		rte_cryptodev_asym_session_clear(dev_id, sess);
-		rte_cryptodev_asym_session_free(sess);
-	}
+	if (sess != NULL)
+		rte_cryptodev_asym_session_free(dev_id, sess);
 	if (op != NULL)
 		rte_crypto_op_free(op);
 	return status;
@@ -1199,14 +1134,6 @@ test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
 	uint8_t output[TEST_DH_MOD_LEN];
 	struct rte_crypto_asym_xform xform = *xfrm;
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
-	if (sess == NULL) {
-		RTE_LOG(ERR, USER1,
-				 "line %u FAILED: %s", __LINE__,
-				"Session creation failed");
-		status = TEST_FAILED;
-		goto error_exit;
-	}
 	/* set up crypto op data structure */
 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
 	if (!op) {
@@ -1225,11 +1152,11 @@ test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
 	asym_op->dh.priv_key.data = output;
 	asym_op->dh.priv_key.length = sizeof(output);
 
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
-			sess_mpool) < 0) {
+	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
+	if (sess == NULL) {
 		RTE_LOG(ERR, USER1,
-				"line %u FAILED: %s",
-				__LINE__, "unabled to config sym session");
+				"line %u FAILED: %s", __LINE__,
+				"Session creation failed");
 		status = TEST_FAILED;
 		goto error_exit;
 	}
@@ -1265,10 +1192,8 @@ test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
 
 
 error_exit:
-	if (sess != NULL) {
-		rte_cryptodev_asym_session_clear(dev_id, sess);
-		rte_cryptodev_asym_session_free(sess);
-	}
+	if (sess != NULL)
+		rte_cryptodev_asym_session_free(dev_id, sess);
 	if (op != NULL)
 		rte_crypto_op_free(op);
 
@@ -1290,14 +1215,6 @@ test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
 	uint8_t output[TEST_DH_MOD_LEN];
 	struct rte_crypto_asym_xform xform = *xfrm;
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
-	if (sess == NULL) {
-		RTE_LOG(ERR, USER1,
-				 "line %u FAILED: %s", __LINE__,
-				"Session creation failed");
-		status = TEST_FAILED;
-		goto error_exit;
-	}
 	/* set up crypto op data structure */
 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
 	if (!op) {
@@ -1324,11 +1241,11 @@ test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
 					0);
 	asym_op->dh.priv_key = dh_test_params.priv_key;
 
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
-			sess_mpool) < 0) {
+	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
+	if (sess == NULL) {
 		RTE_LOG(ERR, USER1,
-				"line %u FAILED: %s",
-				__LINE__, "unabled to config sym session");
+				"line %u FAILED: %s", __LINE__,
+				"Session creation failed");
 		status = TEST_FAILED;
 		goto error_exit;
 	}
@@ -1365,10 +1282,8 @@ test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
 			asym_op->dh.priv_key.data, asym_op->dh.priv_key.length);
 
 error_exit:
-	if (sess != NULL) {
-		rte_cryptodev_asym_session_clear(dev_id, sess);
-		rte_cryptodev_asym_session_free(sess);
-	}
+	if (sess != NULL)
+		rte_cryptodev_asym_session_free(dev_id, sess);
 	if (op != NULL)
 		rte_crypto_op_free(op);
 
@@ -1391,15 +1306,6 @@ test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
 	struct rte_crypto_asym_xform pub_key_xform;
 	struct rte_crypto_asym_xform xform = *xfrm;
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
-	if (sess == NULL) {
-		RTE_LOG(ERR, USER1,
-				 "line %u FAILED: %s", __LINE__,
-				"Session creation failed");
-		status = TEST_FAILED;
-		goto error_exit;
-	}
-
 	/* set up crypto op data structure */
 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
 	if (!op) {
@@ -1423,11 +1329,12 @@ test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
 	asym_op->dh.pub_key.length = sizeof(out_pub_key);
 	asym_op->dh.priv_key.data = out_prv_key;
 	asym_op->dh.priv_key.length = sizeof(out_prv_key);
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
-			sess_mpool) < 0) {
+
+	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
+	if (sess == NULL) {
 		RTE_LOG(ERR, USER1,
-				"line %u FAILED: %s",
-				__LINE__, "unabled to config sym session");
+				"line %u FAILED: %s", __LINE__,
+				"Session creation failed");
 		status = TEST_FAILED;
 		goto error_exit;
 	}
@@ -1462,10 +1369,8 @@ test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
 			out_pub_key, asym_op->dh.pub_key.length);
 
 error_exit:
-	if (sess != NULL) {
-		rte_cryptodev_asym_session_clear(dev_id, sess);
-		rte_cryptodev_asym_session_free(sess);
-	}
+	if (sess != NULL)
+		rte_cryptodev_asym_session_free(dev_id, sess);
 	if (op != NULL)
 		rte_crypto_op_free(op);
 
@@ -1514,7 +1419,7 @@ test_mod_inv(void)
 				return TEST_SKIPPED;
 		}
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
+	sess = rte_cryptodev_asym_session_create(dev_id, &modinv_xform, sess_mpool);
 	if (!sess) {
 		RTE_LOG(ERR, USER1, "line %u "
 				"FAILED: %s", __LINE__,
@@ -1523,15 +1428,6 @@ test_mod_inv(void)
 		goto error_exit;
 	}
 
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &modinv_xform,
-			sess_mpool) < 0) {
-		RTE_LOG(ERR, USER1,
-				"line %u FAILED: %s",
-				__LINE__, "unabled to config sym session");
-		status = TEST_FAILED;
-		goto error_exit;
-	}
-
 	/* generate crypto op data structure */
 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
 	if (!op) {
@@ -1583,10 +1479,8 @@ test_mod_inv(void)
 	}
 
 error_exit:
-	if (sess) {
-		rte_cryptodev_asym_session_clear(dev_id, sess);
-		rte_cryptodev_asym_session_free(sess);
-	}
+	if (sess)
+		rte_cryptodev_asym_session_free(dev_id, sess);
 
 	if (op)
 		rte_crypto_op_free(op);
@@ -1649,7 +1543,7 @@ test_mod_exp(void)
 		goto error_exit;
 	}
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
+	sess = rte_cryptodev_asym_session_create(dev_id, &modex_xform, sess_mpool);
 	if (!sess) {
 		RTE_LOG(ERR, USER1,
 				 "line %u "
@@ -1659,15 +1553,6 @@ test_mod_exp(void)
 		goto error_exit;
 	}
 
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &modex_xform,
-			sess_mpool) < 0) {
-		RTE_LOG(ERR, USER1,
-				"line %u FAILED: %s",
-				__LINE__, "unabled to config sym session");
-		status = TEST_FAILED;
-		goto error_exit;
-	}
-
 	asym_op = op->asym;
 	memcpy(input, base, sizeof(base));
 	asym_op->modex.base.data = input;
@@ -1706,10 +1591,8 @@ test_mod_exp(void)
 	}
 
 error_exit:
-	if (sess != NULL) {
-		rte_cryptodev_asym_session_clear(dev_id, sess);
-		rte_cryptodev_asym_session_free(sess);
-	}
+	if (sess != NULL)
+		rte_cryptodev_asym_session_free(dev_id, sess);
 
 	if (op != NULL)
 		rte_crypto_op_free(op);
@@ -1771,7 +1654,7 @@ test_dsa_sign(void)
 	uint8_t s[TEST_DH_MOD_LEN];
 	uint8_t dgst[] = "35d81554afaad2cf18f3a1770d5fedc4ea5be344";
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
+	sess = rte_cryptodev_asym_session_create(dev_id, &dsa_xform, sess_mpool);
 	if (sess == NULL) {
 		RTE_LOG(ERR, USER1,
 				 "line %u FAILED: %s", __LINE__,
@@ -1800,15 +1683,6 @@ test_dsa_sign(void)
 	debug_hexdump(stdout, "priv_key: ", dsa_xform.dsa.x.data,
 			dsa_xform.dsa.x.length);
 
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &dsa_xform,
-				sess_mpool) < 0) {
-		RTE_LOG(ERR, USER1,
-				"line %u FAILED: %s",
-				__LINE__, "unabled to config sym session");
-		status = TEST_FAILED;
-		goto error_exit;
-	}
-
 	/* attach asymmetric crypto session to crypto operations */
 	rte_crypto_op_attach_asym_session(op, sess);
 	asym_op->dsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
@@ -1882,10 +1756,8 @@ test_dsa_sign(void)
 		status = TEST_FAILED;
 	}
 error_exit:
-	if (sess != NULL) {
-		rte_cryptodev_asym_session_clear(dev_id, sess);
-		rte_cryptodev_asym_session_free(sess);
-	}
+	if (sess != NULL)
+		rte_cryptodev_asym_session_free(dev_id, sess);
 	if (op != NULL)
 		rte_crypto_op_free(op);
 	return status;
@@ -1944,15 +1816,6 @@ test_ecdsa_sign_verify(enum curve curve_id)
 
 	rte_cryptodev_info_get(dev_id, &dev_info);
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
-	if (sess == NULL) {
-		RTE_LOG(ERR, USER1,
-				"line %u FAILED: %s", __LINE__,
-				"Session creation failed\n");
-		status = TEST_FAILED;
-		goto exit;
-	}
-
 	/* Setup crypto op data structure */
 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
 	if (op == NULL) {
@@ -1970,11 +1833,11 @@ test_ecdsa_sign_verify(enum curve curve_id)
 	xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDSA;
 	xform.ec.curve_id = input_params.curve;
 
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
-				sess_mpool) < 0) {
+	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
+	if (sess == NULL) {
 		RTE_LOG(ERR, USER1,
 				"line %u FAILED: %s", __LINE__,
-				"Unable to config asym session\n");
+				"Session creation failed\n");
 		status = TEST_FAILED;
 		goto exit;
 	}
@@ -2082,10 +1945,8 @@ test_ecdsa_sign_verify(enum curve curve_id)
 	}
 
 exit:
-	if (sess != NULL) {
-		rte_cryptodev_asym_session_clear(dev_id, sess);
-		rte_cryptodev_asym_session_free(sess);
-	}
+	if (sess != NULL)
+		rte_cryptodev_asym_session_free(dev_id, sess);
 	if (op != NULL)
 		rte_crypto_op_free(op);
 	return status;
@@ -2157,15 +2018,6 @@ test_ecpm(enum curve curve_id)
 
 	rte_cryptodev_info_get(dev_id, &dev_info);
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
-	if (sess == NULL) {
-		RTE_LOG(ERR, USER1,
-				"line %u FAILED: %s", __LINE__,
-				"Session creation failed\n");
-		status = TEST_FAILED;
-		goto exit;
-	}
-
 	/* Setup crypto op data structure */
 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
 	if (op == NULL) {
@@ -2183,11 +2035,11 @@ test_ecpm(enum curve curve_id)
 	xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECPM;
 	xform.ec.curve_id = input_params.curve;
 
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
-				sess_mpool) < 0) {
+	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
+	if (sess == NULL) {
 		RTE_LOG(ERR, USER1,
 				"line %u FAILED: %s", __LINE__,
-				"Unable to config asym session\n");
+				"Session creation failed\n");
 		status = TEST_FAILED;
 		goto exit;
 	}
@@ -2255,10 +2107,8 @@ test_ecpm(enum curve curve_id)
 	}
 
 exit:
-	if (sess != NULL) {
-		rte_cryptodev_asym_session_clear(dev_id, sess);
-		rte_cryptodev_asym_session_free(sess);
-	}
+	if (sess != NULL)
+		rte_cryptodev_asym_session_free(dev_id, sess);
 	if (op != NULL)
 		rte_crypto_op_free(op);
 	return status;
diff --git a/doc/guides/prog_guide/cryptodev_lib.rst b/doc/guides/prog_guide/cryptodev_lib.rst
index 9f33f7a177..b4dbd384bf 100644
--- a/doc/guides/prog_guide/cryptodev_lib.rst
+++ b/doc/guides/prog_guide/cryptodev_lib.rst
@@ -1038,20 +1038,17 @@ It is the application's responsibility to create and manage the session mempools
 Application using both symmetric and asymmetric sessions should allocate and maintain
 different sessions pools for each type.
 
-An application can use ``rte_cryptodev_get_asym_session_private_size()`` to
-get the private size of asymmetric session on a given crypto device. This
-function would allow an application to calculate the max device asymmetric
-session size of all crypto devices to create a single session mempool.
-If instead an application creates multiple asymmetric session mempools,
-the Crypto device framework also provides ``rte_cryptodev_asym_get_header_session_size()`` to get
-the size of an uninitialized session.
+An application can use ``rte_cryptodev_asym_session_pool_create()`` to create a mempool
+with a specified number of elements. The element size will allow for the session header,
+and the max private session size.
+The max private session size is chosen based on available crypto devices,
+the biggest private session size is used. This means any of those devices can be used,
+and the mempool element will have available space for its private session data.
 
 Once the session mempools have been created, ``rte_cryptodev_asym_session_create()``
-is used to allocate an uninitialized asymmetric session from the given mempool.
-The session then must be initialized using ``rte_cryptodev_asym_session_init()``
-for each of the required crypto devices. An asymmetric transform chain
-is used to specify the operation and its parameters. See the section below for
-details on transforms.
+is used to allocate and initialize an asymmetric session from the given mempool.
+An asymmetric transform chain is used to specify the operation and its parameters.
+See the section below for details on transforms.
 
 When a session is no longer used, user must call ``rte_cryptodev_asym_session_clear()``
 for each of the crypto devices that are using the session, to free all driver
diff --git a/doc/guides/rel_notes/release_22_03.rst b/doc/guides/rel_notes/release_22_03.rst
index a820cc5596..ea4c5309a0 100644
--- a/doc/guides/rel_notes/release_22_03.rst
+++ b/doc/guides/rel_notes/release_22_03.rst
@@ -112,6 +112,13 @@ API Changes
 * ethdev: Old public macros and enumeration constants without ``RTE_ETH_`` prefix,
   which are kept for backward compatibility, are marked as deprecated.
 
+* cryptodev: The asymmetric session handling was modified to use a single
+  mempool object. An API ``rte_cryptodev_asym_session_pool_create`` was added
+  to create a mempool with element size big enough to hold the generic asymmetric
+  session header and max size for a device private session data.
+  The API ``rte_cryptodev_asym_session_init`` was removed as the initialization
+  is now moved to ``rte_cryptodev_asym_session_create``.
+
 
 ABI Changes
 -----------
diff --git a/drivers/crypto/cnxk/cn10k_cryptodev_ops.c b/drivers/crypto/cnxk/cn10k_cryptodev_ops.c
index d217bbf383..c4d5d039ec 100644
--- a/drivers/crypto/cnxk/cn10k_cryptodev_ops.c
+++ b/drivers/crypto/cnxk/cn10k_cryptodev_ops.c
@@ -157,8 +157,8 @@ cn10k_cpt_fill_inst(struct cnxk_cpt_qp *qp, struct rte_crypto_op *ops[],
 
 		if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
 			asym_op = op->asym;
-			ae_sess = get_asym_session_private_data(
-				asym_op->session, cn10k_cryptodev_driver_id);
+			ae_sess = (struct cnxk_ae_sess *)
+					asym_op->session->sess_private_data;
 			ret = cnxk_ae_enqueue(qp, op, infl_req, &inst[0],
 					      ae_sess);
 			if (unlikely(ret))
@@ -431,8 +431,8 @@ cn10k_cpt_dequeue_post_process(struct cnxk_cpt_qp *qp,
 			uintptr_t *mdata = infl_req->mdata;
 			struct cnxk_ae_sess *sess;
 
-			sess = get_asym_session_private_data(
-				op->session, cn10k_cryptodev_driver_id);
+			sess = (struct cnxk_ae_sess *)
+					op->session->sess_private_data;
 
 			cnxk_ae_post_process(cop, sess, (uint8_t *)mdata[0]);
 		}
diff --git a/drivers/crypto/cnxk/cn9k_cryptodev_ops.c b/drivers/crypto/cnxk/cn9k_cryptodev_ops.c
index ac1953b66d..b8ad4bf211 100644
--- a/drivers/crypto/cnxk/cn9k_cryptodev_ops.c
+++ b/drivers/crypto/cnxk/cn9k_cryptodev_ops.c
@@ -138,8 +138,8 @@ cn9k_cpt_inst_prep(struct cnxk_cpt_qp *qp, struct rte_crypto_op *op,
 
 		if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
 			asym_op = op->asym;
-			sess = get_asym_session_private_data(
-				asym_op->session, cn9k_cryptodev_driver_id);
+			sess = (struct cnxk_ae_sess *)
+					asym_op->session->sess_private_data;
 			ret = cnxk_ae_enqueue(qp, op, infl_req, inst, sess);
 			inst->w7.u64 = sess->cpt_inst_w7;
 		} else {
@@ -453,8 +453,8 @@ cn9k_cpt_dequeue_post_process(struct cnxk_cpt_qp *qp, struct rte_crypto_op *cop,
 			uintptr_t *mdata = infl_req->mdata;
 			struct cnxk_ae_sess *sess;
 
-			sess = get_asym_session_private_data(
-				op->session, cn9k_cryptodev_driver_id);
+			sess = (struct cnxk_ae_sess *)
+					op->session->sess_private_data;
 
 			cnxk_ae_post_process(cop, sess, (uint8_t *)mdata[0]);
 		}
diff --git a/drivers/crypto/cnxk/cnxk_cryptodev_ops.c b/drivers/crypto/cnxk/cnxk_cryptodev_ops.c
index a5fb68da02..7237dacb48 100644
--- a/drivers/crypto/cnxk/cnxk_cryptodev_ops.c
+++ b/drivers/crypto/cnxk/cnxk_cryptodev_ops.c
@@ -658,10 +658,9 @@ void
 cnxk_ae_session_clear(struct rte_cryptodev *dev,
 		      struct rte_cryptodev_asym_session *sess)
 {
-	struct rte_mempool *sess_mp;
 	struct cnxk_ae_sess *priv;
 
-	priv = get_asym_session_private_data(sess, dev->driver_id);
+	priv = (struct cnxk_ae_sess *) sess->sess_private_data;
 	if (priv == NULL)
 		return;
 
@@ -670,40 +669,29 @@ cnxk_ae_session_clear(struct rte_cryptodev *dev,
 
 	/* Reset and free object back to pool */
 	memset(priv, 0, cnxk_ae_session_size_get(dev));
-	sess_mp = rte_mempool_from_obj(priv);
-	set_asym_session_private_data(sess, dev->driver_id, NULL);
-	rte_mempool_put(sess_mp, priv);
 }
 
 int
 cnxk_ae_session_cfg(struct rte_cryptodev *dev,
 		    struct rte_crypto_asym_xform *xform,
-		    struct rte_cryptodev_asym_session *sess,
-		    struct rte_mempool *pool)
+		    struct rte_cryptodev_asym_session *sess)
 {
+	struct cnxk_ae_sess *priv =
+			(struct cnxk_ae_sess *) sess->sess_private_data;
 	struct cnxk_cpt_vf *vf = dev->data->dev_private;
 	struct roc_cpt *roc_cpt = &vf->cpt;
-	struct cnxk_ae_sess *priv;
 	union cpt_inst_w7 w7;
 	int ret;
 
-	if (rte_mempool_get(pool, (void **)&priv))
-		return -ENOMEM;
-
-	memset(priv, 0, sizeof(struct cnxk_ae_sess));
-
 	ret = cnxk_ae_fill_session_parameters(priv, xform);
-	if (ret) {
-		rte_mempool_put(pool, priv);
+	if (ret)
 		return ret;
-	}
 
 	w7.u64 = 0;
 	w7.s.egrp = roc_cpt->eng_grp[CPT_ENG_TYPE_AE];
 	priv->cpt_inst_w7 = w7.u64;
 	priv->cnxk_fpm_iova = vf->cnxk_fpm_iova;
 	priv->ec_grp = vf->ec_grp;
-	set_asym_session_private_data(sess, dev->driver_id, priv);
 
 	return 0;
 }
diff --git a/drivers/crypto/cnxk/cnxk_cryptodev_ops.h b/drivers/crypto/cnxk/cnxk_cryptodev_ops.h
index 0656ba9675..ab0f00ee7c 100644
--- a/drivers/crypto/cnxk/cnxk_cryptodev_ops.h
+++ b/drivers/crypto/cnxk/cnxk_cryptodev_ops.h
@@ -122,8 +122,7 @@ void cnxk_ae_session_clear(struct rte_cryptodev *dev,
 			   struct rte_cryptodev_asym_session *sess);
 int cnxk_ae_session_cfg(struct rte_cryptodev *dev,
 			struct rte_crypto_asym_xform *xform,
-			struct rte_cryptodev_asym_session *sess,
-			struct rte_mempool *pool);
+			struct rte_cryptodev_asym_session *sess);
 void cnxk_cpt_dump_on_err(struct cnxk_cpt_qp *qp);
 
 static inline union rte_event_crypto_metadata *
diff --git a/drivers/crypto/octeontx/otx_cryptodev_ops.c b/drivers/crypto/octeontx/otx_cryptodev_ops.c
index f7ca8a8a8e..0cb6dbb38c 100644
--- a/drivers/crypto/octeontx/otx_cryptodev_ops.c
+++ b/drivers/crypto/octeontx/otx_cryptodev_ops.c
@@ -375,35 +375,24 @@ otx_cpt_asym_session_size_get(struct rte_cryptodev *dev __rte_unused)
 }
 
 static int
-otx_cpt_asym_session_cfg(struct rte_cryptodev *dev,
+otx_cpt_asym_session_cfg(struct rte_cryptodev *dev __rte_unused,
 			 struct rte_crypto_asym_xform *xform __rte_unused,
-			 struct rte_cryptodev_asym_session *sess,
-			 struct rte_mempool *pool)
+			 struct rte_cryptodev_asym_session *sess)
 {
-	struct cpt_asym_sess_misc *priv;
+	struct cpt_asym_sess_misc *priv = (struct cpt_asym_sess_misc *)
+			sess->sess_private_data;
 	int ret;
 
 	CPT_PMD_INIT_FUNC_TRACE();
 
-	if (rte_mempool_get(pool, (void **)&priv)) {
-		CPT_LOG_ERR("Could not allocate session private data");
-		return -ENOMEM;
-	}
-
-	memset(priv, 0, sizeof(struct cpt_asym_sess_misc));
-
 	ret = cpt_fill_asym_session_parameters(priv, xform);
 	if (ret) {
 		CPT_LOG_ERR("Could not configure session parameters");
-
-		/* Return session to mempool */
-		rte_mempool_put(pool, priv);
 		return ret;
 	}
 
 	priv->cpt_inst_w7 = 0;
 
-	set_asym_session_private_data(sess, dev->driver_id, priv);
 	return 0;
 }
 
@@ -412,11 +401,10 @@ otx_cpt_asym_session_clear(struct rte_cryptodev *dev,
 			   struct rte_cryptodev_asym_session *sess)
 {
 	struct cpt_asym_sess_misc *priv;
-	struct rte_mempool *sess_mp;
 
 	CPT_PMD_INIT_FUNC_TRACE();
 
-	priv = get_asym_session_private_data(sess, dev->driver_id);
+	priv = (struct cpt_asym_sess_misc *) sess->sess_private_data;
 
 	if (priv == NULL)
 		return;
@@ -424,9 +412,6 @@ otx_cpt_asym_session_clear(struct rte_cryptodev *dev,
 	/* Free resources allocated during session configure */
 	cpt_free_asym_session_parameters(priv);
 	memset(priv, 0, otx_cpt_asym_session_size_get(dev));
-	sess_mp = rte_mempool_from_obj(priv);
-	set_asym_session_private_data(sess, dev->driver_id, NULL);
-	rte_mempool_put(sess_mp, priv);
 }
 
 static __rte_always_inline void * __rte_hot
@@ -471,8 +456,8 @@ otx_cpt_enq_single_asym(struct cpt_instance *instance,
 		return NULL;
 	}
 
-	sess = get_asym_session_private_data(asym_op->session,
-					     otx_cryptodev_driver_id);
+	sess = (struct cpt_asym_sess_misc *)
+			asym_op->session->sess_private_data;
 
 	/* Store phys_addr of the mdata to meta_buf */
 	params.meta_buf = rte_mempool_virt2iova(mdata);
@@ -852,8 +837,7 @@ otx_cpt_asym_post_process(struct rte_crypto_op *cop,
 	struct rte_crypto_asym_op *op = cop->asym;
 	struct cpt_asym_sess_misc *sess;
 
-	sess = get_asym_session_private_data(op->session,
-					     otx_cryptodev_driver_id);
+	sess = (struct cpt_asym_sess_misc *) op->session->sess_private_data;
 
 	switch (sess->xfrm_type) {
 	case RTE_CRYPTO_ASYM_XFORM_RSA:
diff --git a/drivers/crypto/openssl/rte_openssl_pmd.c b/drivers/crypto/openssl/rte_openssl_pmd.c
index 5794ed8159..d80e1052e2 100644
--- a/drivers/crypto/openssl/rte_openssl_pmd.c
+++ b/drivers/crypto/openssl/rte_openssl_pmd.c
@@ -748,9 +748,7 @@ get_session(struct openssl_qp *qp, struct rte_crypto_op *op)
 		} else {
 			if (likely(op->asym->session != NULL))
 				asym_sess = (struct openssl_asym_session *)
-						get_asym_session_private_data(
-						op->asym->session,
-						cryptodev_driver_id);
+						op->asym->session->sess_private_data;
 			if (asym_sess == NULL)
 				op->status =
 					RTE_CRYPTO_OP_STATUS_INVALID_SESSION;
diff --git a/drivers/crypto/openssl/rte_openssl_pmd_ops.c b/drivers/crypto/openssl/rte_openssl_pmd_ops.c
index 52715f86f8..556fd226ed 100644
--- a/drivers/crypto/openssl/rte_openssl_pmd_ops.c
+++ b/drivers/crypto/openssl/rte_openssl_pmd_ops.c
@@ -1119,8 +1119,7 @@ static int openssl_set_asym_session_parameters(
 static int
 openssl_pmd_asym_session_configure(struct rte_cryptodev *dev __rte_unused,
 		struct rte_crypto_asym_xform *xform,
-		struct rte_cryptodev_asym_session *sess,
-		struct rte_mempool *mempool)
+		struct rte_cryptodev_asym_session *sess)
 {
 	void *asym_sess_private_data;
 	int ret;
@@ -1130,25 +1129,14 @@ openssl_pmd_asym_session_configure(struct rte_cryptodev *dev __rte_unused,
 		return -EINVAL;
 	}
 
-	if (rte_mempool_get(mempool, &asym_sess_private_data)) {
-		CDEV_LOG_ERR(
-			"Couldn't get object from session mempool");
-		return -ENOMEM;
-	}
-
+	asym_sess_private_data = sess->sess_private_data;
 	ret = openssl_set_asym_session_parameters(asym_sess_private_data,
 			xform);
 	if (ret != 0) {
 		OPENSSL_LOG(ERR, "failed configure session parameters");
-
-		/* Return session to mempool */
-		rte_mempool_put(mempool, asym_sess_private_data);
 		return ret;
 	}
 
-	set_asym_session_private_data(sess, dev->driver_id,
-			asym_sess_private_data);
-
 	return 0;
 }
 
@@ -1206,19 +1194,15 @@ static void openssl_reset_asym_session(struct openssl_asym_session *sess)
  * so it doesn't leave key material behind
  */
 static void
-openssl_pmd_asym_session_clear(struct rte_cryptodev *dev,
+openssl_pmd_asym_session_clear(struct rte_cryptodev *dev __rte_unused,
 		struct rte_cryptodev_asym_session *sess)
 {
-	uint8_t index = dev->driver_id;
-	void *sess_priv = get_asym_session_private_data(sess, index);
+	void *sess_priv = sess->sess_private_data;
 
 	/* Zero out the whole structure */
 	if (sess_priv) {
 		openssl_reset_asym_session(sess_priv);
 		memset(sess_priv, 0, sizeof(struct openssl_asym_session));
-		struct rte_mempool *sess_mp = rte_mempool_from_obj(sess_priv);
-		set_asym_session_private_data(sess, index, NULL);
-		rte_mempool_put(sess_mp, sess_priv);
 	}
 }
 
diff --git a/drivers/crypto/qat/qat_asym.c b/drivers/crypto/qat/qat_asym.c
index 09d8761c5f..f46eefd4b3 100644
--- a/drivers/crypto/qat/qat_asym.c
+++ b/drivers/crypto/qat/qat_asym.c
@@ -492,8 +492,7 @@ qat_asym_build_request(void *in_op,
 	op->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
 	if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
 		ctx = (struct qat_asym_session *)
-			get_asym_session_private_data(
-			op->asym->session, qat_asym_driver_id);
+				op->asym->session->sess_private_data;
 		if (unlikely(ctx == NULL)) {
 			QAT_LOG(ERR, "Session has not been created for this device");
 			goto error;
@@ -711,8 +710,8 @@ qat_asym_process_response(void **op, uint8_t *resp,
 	}
 
 	if (rx_op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
-		ctx = (struct qat_asym_session *)get_asym_session_private_data(
-			rx_op->asym->session, qat_asym_driver_id);
+		ctx = (struct qat_asym_session *)
+				rx_op->asym->session->sess_private_data;
 		qat_asym_collect_response(rx_op, cookie, ctx->xform);
 	} else if (rx_op->sess_type == RTE_CRYPTO_OP_SESSIONLESS) {
 		qat_asym_collect_response(rx_op, cookie, rx_op->asym->xform);
@@ -726,61 +725,42 @@ qat_asym_process_response(void **op, uint8_t *resp,
 }
 
 int
-qat_asym_session_configure(struct rte_cryptodev *dev,
+qat_asym_session_configure(struct rte_cryptodev *dev __rte_unused,
 		struct rte_crypto_asym_xform *xform,
-		struct rte_cryptodev_asym_session *sess,
-		struct rte_mempool *mempool)
+		struct rte_cryptodev_asym_session *sess)
 {
-	int err = 0;
-	void *sess_private_data;
 	struct qat_asym_session *session;
 
-	if (rte_mempool_get(mempool, &sess_private_data)) {
-		QAT_LOG(ERR,
-			"Couldn't get object from session mempool");
-		return -ENOMEM;
-	}
-
-	session = sess_private_data;
+	session = (struct qat_asym_session *) sess->sess_private_data;
 	if (xform->xform_type == RTE_CRYPTO_ASYM_XFORM_MODEX) {
 		if (xform->modex.exponent.length == 0 ||
 				xform->modex.modulus.length == 0) {
 			QAT_LOG(ERR, "Invalid mod exp input parameter");
-			err = -EINVAL;
-			goto error;
+			return -EINVAL;
 		}
 	} else if (xform->xform_type == RTE_CRYPTO_ASYM_XFORM_MODINV) {
 		if (xform->modinv.modulus.length == 0) {
 			QAT_LOG(ERR, "Invalid mod inv input parameter");
-			err = -EINVAL;
-			goto error;
+			return -EINVAL;
 		}
 	} else if (xform->xform_type == RTE_CRYPTO_ASYM_XFORM_RSA) {
 		if (xform->rsa.n.length == 0) {
 			QAT_LOG(ERR, "Invalid rsa input parameter");
-			err = -EINVAL;
-			goto error;
+			return -EINVAL;
 		}
 	} else if (xform->xform_type >= RTE_CRYPTO_ASYM_XFORM_TYPE_LIST_END
 			|| xform->xform_type <= RTE_CRYPTO_ASYM_XFORM_NONE) {
 		QAT_LOG(ERR, "Invalid asymmetric crypto xform");
-		err = -EINVAL;
-		goto error;
+		return -EINVAL;
 	} else {
 		QAT_LOG(ERR, "Asymmetric crypto xform not implemented");
-		err = -EINVAL;
-		goto error;
+		return -EINVAL;
 	}
 
 	session->xform = xform;
-	qat_asym_build_req_tmpl(sess_private_data);
-	set_asym_session_private_data(sess, dev->driver_id,
-		sess_private_data);
+	qat_asym_build_req_tmpl(session);
 
 	return 0;
-error:
-	rte_mempool_put(mempool, sess_private_data);
-	return err;
 }
 
 unsigned int qat_asym_session_get_private_size(
@@ -793,15 +773,9 @@ void
 qat_asym_session_clear(struct rte_cryptodev *dev,
 		struct rte_cryptodev_asym_session *sess)
 {
-	uint8_t index = dev->driver_id;
-	void *sess_priv = get_asym_session_private_data(sess, index);
+	void *sess_priv = sess->sess_private_data;
 	struct qat_asym_session *s = (struct qat_asym_session *)sess_priv;
 
-	if (sess_priv) {
+	if (sess_priv)
 		memset(s, 0, qat_asym_session_get_private_size(dev));
-		struct rte_mempool *sess_mp = rte_mempool_from_obj(sess_priv);
-
-		set_asym_session_private_data(sess, index, NULL);
-		rte_mempool_put(sess_mp, sess_priv);
-	}
 }
diff --git a/drivers/crypto/qat/qat_asym.h b/drivers/crypto/qat/qat_asym.h
index 308b6b2e0b..c9242a12ca 100644
--- a/drivers/crypto/qat/qat_asym.h
+++ b/drivers/crypto/qat/qat_asym.h
@@ -46,10 +46,9 @@ struct qat_asym_session {
 };
 
 int
-qat_asym_session_configure(struct rte_cryptodev *dev,
+qat_asym_session_configure(struct rte_cryptodev *dev __rte_unused,
 		struct rte_crypto_asym_xform *xform,
-		struct rte_cryptodev_asym_session *sess,
-		struct rte_mempool *mempool);
+		struct rte_cryptodev_asym_session *sess);
 
 unsigned int
 qat_asym_session_get_private_size(struct rte_cryptodev *dev);
diff --git a/lib/cryptodev/cryptodev_pmd.h b/lib/cryptodev/cryptodev_pmd.h
index b9146f652c..142bfb7c66 100644
--- a/lib/cryptodev/cryptodev_pmd.h
+++ b/lib/cryptodev/cryptodev_pmd.h
@@ -319,7 +319,6 @@ typedef int (*cryptodev_sym_configure_session_t)(struct rte_cryptodev *dev,
  * @param	dev		Crypto device pointer
  * @param	xform		Single or chain of crypto xforms
  * @param	session		Pointer to cryptodev's private session structure
- * @param	mp		Mempool where the private session is allocated
  *
  * @return
  *  - Returns 0 if private session structure have been created successfully.
@@ -329,8 +328,7 @@ typedef int (*cryptodev_sym_configure_session_t)(struct rte_cryptodev *dev,
  */
 typedef int (*cryptodev_asym_configure_session_t)(struct rte_cryptodev *dev,
 		struct rte_crypto_asym_xform *xform,
-		struct rte_cryptodev_asym_session *session,
-		struct rte_mempool *mp);
+		struct rte_cryptodev_asym_session *session);
 /**
  * Free driver private session data.
  *
@@ -340,12 +338,12 @@ typedef int (*cryptodev_asym_configure_session_t)(struct rte_cryptodev *dev,
 typedef void (*cryptodev_sym_free_session_t)(struct rte_cryptodev *dev,
 		struct rte_cryptodev_sym_session *sess);
 /**
- * Free asymmetric session private data.
+ * Clear asymmetric session private data.
  *
  * @param	dev		Crypto device pointer
  * @param	sess		Cryptodev session structure
  */
-typedef void (*cryptodev_asym_free_session_t)(struct rte_cryptodev *dev,
+typedef void (*cryptodev_asym_clear_session_t)(struct rte_cryptodev *dev,
 		struct rte_cryptodev_asym_session *sess);
 /**
  * Perform actual crypto processing (encrypt/digest or auth/decrypt)
@@ -429,7 +427,7 @@ struct rte_cryptodev_ops {
 	/**< Configure asymmetric Crypto session. */
 	cryptodev_sym_free_session_t sym_session_clear;
 	/**< Clear a Crypto sessions private data. */
-	cryptodev_asym_free_session_t asym_session_clear;
+	cryptodev_asym_clear_session_t asym_session_clear;
 	/**< Clear a Crypto sessions private data. */
 	union {
 		cryptodev_sym_cpu_crypto_process_t sym_cpu_process;
@@ -627,17 +625,4 @@ set_sym_session_private_data(struct rte_cryptodev_sym_session *sess,
 	sess->sess_data[driver_id].data = private_data;
 }
 
-static inline void *
-get_asym_session_private_data(const struct rte_cryptodev_asym_session *sess,
-		uint8_t driver_id) {
-	return sess->sess_private_data[driver_id];
-}
-
-static inline void
-set_asym_session_private_data(struct rte_cryptodev_asym_session *sess,
-		uint8_t driver_id, void *private_data)
-{
-	sess->sess_private_data[driver_id] = private_data;
-}
-
 #endif /* _CRYPTODEV_PMD_H_ */
diff --git a/lib/cryptodev/cryptodev_trace_points.c b/lib/cryptodev/cryptodev_trace_points.c
index 5d58951fd5..c5bfe08b79 100644
--- a/lib/cryptodev/cryptodev_trace_points.c
+++ b/lib/cryptodev/cryptodev_trace_points.c
@@ -24,6 +24,9 @@ RTE_TRACE_POINT_REGISTER(rte_cryptodev_trace_queue_pair_setup,
 RTE_TRACE_POINT_REGISTER(rte_cryptodev_trace_sym_session_pool_create,
 	lib.cryptodev.sym.pool.create)
 
+RTE_TRACE_POINT_REGISTER(rte_cryptodev_trace_asym_session_pool_create,
+	lib.cryptodev.asym.pool.create)
+
 RTE_TRACE_POINT_REGISTER(rte_cryptodev_trace_sym_session_create,
 	lib.cryptodev.sym.create)
 
@@ -39,15 +42,9 @@ RTE_TRACE_POINT_REGISTER(rte_cryptodev_trace_asym_session_free,
 RTE_TRACE_POINT_REGISTER(rte_cryptodev_trace_sym_session_init,
 	lib.cryptodev.sym.init)
 
-RTE_TRACE_POINT_REGISTER(rte_cryptodev_trace_asym_session_init,
-	lib.cryptodev.asym.init)
-
 RTE_TRACE_POINT_REGISTER(rte_cryptodev_trace_sym_session_clear,
 	lib.cryptodev.sym.clear)
 
-RTE_TRACE_POINT_REGISTER(rte_cryptodev_trace_asym_session_clear,
-	lib.cryptodev.asym.clear)
-
 RTE_TRACE_POINT_REGISTER(rte_cryptodev_trace_enqueue_burst,
 	lib.cryptodev.enq.burst)
 
diff --git a/lib/cryptodev/rte_cryptodev.c b/lib/cryptodev/rte_cryptodev.c
index a40536c5ea..b056d88ac2 100644
--- a/lib/cryptodev/rte_cryptodev.c
+++ b/lib/cryptodev/rte_cryptodev.c
@@ -195,7 +195,7 @@ const char *rte_crypto_asym_op_strings[] = {
 };
 
 /**
- * The private data structure stored in the session mempool private data.
+ * The private data structure stored in the sym session mempool private data.
  */
 struct rte_cryptodev_sym_session_pool_private_data {
 	uint16_t nb_drivers;
@@ -204,6 +204,14 @@ struct rte_cryptodev_sym_session_pool_private_data {
 	/**< session user data will be placed after sess_data */
 };
 
+/**
+ * The private data structure stored in the asym session mempool private data.
+ */
+struct rte_cryptodev_asym_session_pool_private_data {
+	uint16_t max_priv_session_sz;
+	/**< Size of private session data used when creating mempool */
+};
+
 int
 rte_cryptodev_get_cipher_algo_enum(enum rte_crypto_cipher_algorithm *algo_enum,
 		const char *algo_string)
@@ -1751,47 +1759,6 @@ rte_cryptodev_sym_session_init(uint8_t dev_id,
 	return 0;
 }
 
-int
-rte_cryptodev_asym_session_init(uint8_t dev_id,
-		struct rte_cryptodev_asym_session *sess,
-		struct rte_crypto_asym_xform *xforms,
-		struct rte_mempool *mp)
-{
-	struct rte_cryptodev *dev;
-	uint8_t index;
-	int ret;
-
-	if (!rte_cryptodev_is_valid_dev(dev_id)) {
-		CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
-		return -EINVAL;
-	}
-
-	dev = rte_cryptodev_pmd_get_dev(dev_id);
-
-	if (sess == NULL || xforms == NULL || dev == NULL)
-		return -EINVAL;
-
-	index = dev->driver_id;
-
-	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->asym_session_configure,
-				-ENOTSUP);
-
-	if (sess->sess_private_data[index] == NULL) {
-		ret = dev->dev_ops->asym_session_configure(dev,
-							xforms,
-							sess, mp);
-		if (ret < 0) {
-			CDEV_LOG_ERR(
-				"dev_id %d failed to configure session details",
-				dev_id);
-			return ret;
-		}
-	}
-
-	rte_cryptodev_trace_asym_session_init(dev_id, sess, xforms, mp);
-	return 0;
-}
-
 struct rte_mempool *
 rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
 	uint32_t elt_size, uint32_t cache_size, uint16_t user_data_size,
@@ -1834,6 +1801,53 @@ rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
 	return mp;
 }
 
+struct rte_mempool *
+rte_cryptodev_asym_session_pool_create(const char *name, uint32_t nb_elts,
+	uint32_t cache_size, int socket_id)
+{
+	struct rte_mempool *mp;
+	struct rte_cryptodev_asym_session_pool_private_data *pool_priv;
+	uint32_t obj_sz, obj_sz_aligned;
+	uint8_t dev_id, priv_sz, max_priv_sz = 0;
+
+	for (dev_id = 0; dev_id < RTE_CRYPTO_MAX_DEVS; dev_id++)
+		if (rte_cryptodev_is_valid_dev(dev_id)) {
+			priv_sz = rte_cryptodev_asym_get_private_session_size(dev_id);
+			if (priv_sz > max_priv_sz)
+				max_priv_sz = priv_sz;
+		}
+	if (max_priv_sz == 0) {
+		CDEV_LOG_INFO("Could not set max private session size\n");
+		return NULL;
+	}
+
+	obj_sz = rte_cryptodev_asym_get_header_session_size() + max_priv_sz;
+	obj_sz_aligned =  RTE_ALIGN_CEIL(obj_sz, RTE_CACHE_LINE_SIZE);
+
+	mp = rte_mempool_create(name, nb_elts, obj_sz_aligned, cache_size,
+			(uint32_t)(sizeof(*pool_priv)),
+			NULL, NULL, NULL, NULL,
+			socket_id, 0);
+	if (mp == NULL) {
+		CDEV_LOG_ERR("%s(name=%s) failed, rte_errno=%d\n",
+			__func__, name, rte_errno);
+		return NULL;
+	}
+
+	pool_priv = rte_mempool_get_priv(mp);
+	if (!pool_priv) {
+		CDEV_LOG_ERR("%s(name=%s) failed to get private data\n",
+			__func__, name);
+		rte_mempool_free(mp);
+		return NULL;
+	}
+	pool_priv->max_priv_session_sz = max_priv_sz;
+
+	rte_cryptodev_trace_asym_session_pool_create(name, nb_elts,
+		cache_size, mp);
+	return mp;
+}
+
 static unsigned int
 rte_cryptodev_sym_session_data_size(struct rte_cryptodev_sym_session *sess)
 {
@@ -1895,19 +1909,44 @@ rte_cryptodev_sym_session_create(struct rte_mempool *mp)
 }
 
 struct rte_cryptodev_asym_session *
-rte_cryptodev_asym_session_create(struct rte_mempool *mp)
+rte_cryptodev_asym_session_create(uint8_t dev_id,
+		struct rte_crypto_asym_xform *xforms, struct rte_mempool *mp)
 {
 	struct rte_cryptodev_asym_session *sess;
-	unsigned int session_size =
+	uint32_t session_priv_data_sz;
+	struct rte_cryptodev_asym_session_pool_private_data *pool_priv;
+	unsigned int session_header_size =
 			rte_cryptodev_asym_get_header_session_size();
+	struct rte_cryptodev *dev;
+	int ret;
+
+	if (!rte_cryptodev_is_valid_dev(dev_id)) {
+		CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
+		return NULL;
+	}
+
+	dev = rte_cryptodev_pmd_get_dev(dev_id);
+
+	if (dev == NULL)
+		return NULL;
 
 	if (!mp) {
 		CDEV_LOG_ERR("invalid mempool\n");
 		return NULL;
 	}
 
+	session_priv_data_sz = rte_cryptodev_asym_get_private_session_size(
+			dev_id);
+	pool_priv = rte_mempool_get_priv(mp);
+
+	if (pool_priv->max_priv_session_sz < session_priv_data_sz) {
+		CDEV_LOG_DEBUG(
+			"The private session data size used when creating the mempool is smaller than this device's private session data.");
+		return NULL;
+	}
+
 	/* Verify if provided mempool can hold elements big enough. */
-	if (mp->elt_size < session_size) {
+	if (mp->elt_size < session_header_size + session_priv_data_sz) {
 		CDEV_LOG_ERR(
 			"mempool elements too small to hold session objects");
 		return NULL;
@@ -1919,12 +1958,25 @@ rte_cryptodev_asym_session_create(struct rte_mempool *mp)
 		return NULL;
 	}
 
-	/* Clear device session pointer.
-	 * Include the flag indicating presence of private data
-	 */
-	memset(sess, 0, session_size);
+	sess->driver_id = dev->driver_id;
+	sess->max_priv_data_sz = pool_priv->max_priv_session_sz;
+
+	/* Clear device session pointer.*/
+	memset(sess->sess_private_data, 0, session_priv_data_sz);
+
+	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->asym_session_configure, NULL);
 
-	rte_cryptodev_trace_asym_session_create(mp, sess);
+	if (sess->sess_private_data[0] == 0) {
+		ret = dev->dev_ops->asym_session_configure(dev, xforms, sess);
+		if (ret < 0) {
+			CDEV_LOG_ERR(
+				"dev_id %d failed to configure session details",
+				dev_id);
+			return NULL;
+		}
+	}
+
+	rte_cryptodev_trace_asym_session_create(dev_id, xforms, mp);
 	return sess;
 }
 
@@ -1959,30 +2011,6 @@ rte_cryptodev_sym_session_clear(uint8_t dev_id,
 	return 0;
 }
 
-int
-rte_cryptodev_asym_session_clear(uint8_t dev_id,
-		struct rte_cryptodev_asym_session *sess)
-{
-	struct rte_cryptodev *dev;
-
-	if (!rte_cryptodev_is_valid_dev(dev_id)) {
-		CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
-		return -EINVAL;
-	}
-
-	dev = rte_cryptodev_pmd_get_dev(dev_id);
-
-	if (dev == NULL || sess == NULL)
-		return -EINVAL;
-
-	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->asym_session_clear, -ENOTSUP);
-
-	dev->dev_ops->asym_session_clear(dev, sess);
-
-	rte_cryptodev_trace_sym_session_clear(dev_id, sess);
-	return 0;
-}
-
 int
 rte_cryptodev_sym_session_free(struct rte_cryptodev_sym_session *sess)
 {
@@ -2007,27 +2035,31 @@ rte_cryptodev_sym_session_free(struct rte_cryptodev_sym_session *sess)
 }
 
 int
-rte_cryptodev_asym_session_free(struct rte_cryptodev_asym_session *sess)
+rte_cryptodev_asym_session_free(uint8_t dev_id,
+		struct rte_cryptodev_asym_session *sess)
 {
-	uint8_t i;
-	void *sess_priv;
 	struct rte_mempool *sess_mp;
+	struct rte_cryptodev *dev;
 
-	if (sess == NULL)
+	if (!rte_cryptodev_is_valid_dev(dev_id)) {
+		CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
 		return -EINVAL;
-
-	/* Check that all device private data has been freed */
-	for (i = 0; i < nb_drivers; i++) {
-		sess_priv = get_asym_session_private_data(sess, i);
-		if (sess_priv != NULL)
-			return -EBUSY;
 	}
 
+	dev = rte_cryptodev_pmd_get_dev(dev_id);
+
+	if (dev == NULL || sess == NULL)
+		return -EINVAL;
+
+	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->asym_session_clear, -ENOTSUP);
+
+	dev->dev_ops->asym_session_clear(dev, sess);
+
 	/* Return session to mempool */
 	sess_mp = rte_mempool_from_obj(sess);
 	rte_mempool_put(sess_mp, sess);
 
-	rte_cryptodev_trace_asym_session_free(sess);
+	rte_cryptodev_trace_asym_session_free(dev_id, sess);
 	return 0;
 }
 
@@ -2061,12 +2093,7 @@ rte_cryptodev_sym_get_existing_header_session_size(
 unsigned int
 rte_cryptodev_asym_get_header_session_size(void)
 {
-	/*
-	 * Header contains pointers to the private data
-	 * of all registered drivers, and a flag which
-	 * indicates presence of private data
-	 */
-	return ((sizeof(void *) * nb_drivers) + sizeof(uint8_t));
+	return sizeof(struct rte_cryptodev_asym_session);
 }
 
 unsigned int
@@ -2092,7 +2119,6 @@ unsigned int
 rte_cryptodev_asym_get_private_session_size(uint8_t dev_id)
 {
 	struct rte_cryptodev *dev;
-	unsigned int header_size = sizeof(void *) * nb_drivers;
 	unsigned int priv_sess_size;
 
 	if (!rte_cryptodev_is_valid_dev(dev_id))
@@ -2104,11 +2130,8 @@ rte_cryptodev_asym_get_private_session_size(uint8_t dev_id)
 		return 0;
 
 	priv_sess_size = (*dev->dev_ops->asym_session_get_size)(dev);
-	if (priv_sess_size < header_size)
-		return header_size;
 
 	return priv_sess_size;
-
 }
 
 int
diff --git a/lib/cryptodev/rte_cryptodev.h b/lib/cryptodev/rte_cryptodev.h
index 59ea5a54df..90e764017d 100644
--- a/lib/cryptodev/rte_cryptodev.h
+++ b/lib/cryptodev/rte_cryptodev.h
@@ -919,9 +919,13 @@ struct rte_cryptodev_sym_session {
 };
 
 /** Cryptodev asymmetric crypto session */
-struct rte_cryptodev_asym_session {
-	__extension__ void *sess_private_data[0];
-	/**< Private asymmetric session material */
+RTE_STD_C11 struct rte_cryptodev_asym_session {
+	uint8_t driver_id;
+	/**< Session driver ID. */
+	uint16_t max_priv_data_sz;
+	/**< Size of private data used when creating mempool */
+	uint8_t padding[5];
+	uint8_t sess_private_data[0];
 };
 
 /**
@@ -956,6 +960,29 @@ rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
 	uint32_t elt_size, uint32_t cache_size, uint16_t priv_size,
 	int socket_id);
 
+/**
+ * Create an asymmetric session mempool.
+ *
+ * @param name
+ *   The unique mempool name.
+ * @param nb_elts
+ *   The number of elements in the mempool.
+ * @param cache_size
+ *   The number of per-lcore cache elements
+ * @param socket_id
+ *   The *socket_id* argument is the socket identifier in the case of
+ *   NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA
+ *   constraint for the reserved zone.
+ *
+ * @return
+ *  - On success return mempool
+ *  - On failure returns NULL
+ */
+__rte_experimental
+struct rte_mempool *
+rte_cryptodev_asym_session_pool_create(const char *name, uint32_t nb_elts,
+	uint32_t cache_size, int socket_id);
+
 /**
  * Create symmetric crypto session header (generic with no private data)
  *
@@ -969,17 +996,22 @@ struct rte_cryptodev_sym_session *
 rte_cryptodev_sym_session_create(struct rte_mempool *mempool);
 
 /**
- * Create asymmetric crypto session header (generic with no private data)
+ * Create and initialise an asymmetric crypto session structure.
+ * Calls the PMD to configure the private session data.
  *
- * @param   mempool    mempool to allocate asymmetric session
- *                     objects from
+ * @param   dev_id   ID of device that we want the session to be used on
+ * @param   xforms   Asymmetric crypto transform operations to apply on flow
+ *                   processed with this session
+ * @param   mp       mempool to allocate asymmetric session
+ *                   objects from
  * @return
  *  - On success return pointer to asym-session
  *  - On failure returns NULL
  */
 __rte_experimental
 struct rte_cryptodev_asym_session *
-rte_cryptodev_asym_session_create(struct rte_mempool *mempool);
+rte_cryptodev_asym_session_create(uint8_t dev_id,
+		struct rte_crypto_asym_xform *xforms, struct rte_mempool *mp);
 
 /**
  * Frees symmetric crypto session header, after checking that all
@@ -997,20 +1029,20 @@ int
 rte_cryptodev_sym_session_free(struct rte_cryptodev_sym_session *sess);
 
 /**
- * Frees asymmetric crypto session header, after checking that all
- * the device private data has been freed, returning it
- * to its original mempool.
+ * Clears and frees asymmetric crypto session header and private data,
+ * returning it to its original mempool.
  *
+ * @param   dev_id   ID of device that uses the asymmetric session.
  * @param   sess     Session header to be freed.
  *
  * @return
  *  - 0 if successful.
- *  - -EINVAL if session is NULL.
- *  - -EBUSY if not all device private data has been freed.
+ *  - -EINVAL if device is invalid or session is NULL.
  */
 __rte_experimental
 int
-rte_cryptodev_asym_session_free(struct rte_cryptodev_asym_session *sess);
+rte_cryptodev_asym_session_free(uint8_t dev_id,
+		struct rte_cryptodev_asym_session *sess);
 
 /**
  * Fill out private data for the device id, based on its device type.
@@ -1034,28 +1066,6 @@ rte_cryptodev_sym_session_init(uint8_t dev_id,
 			struct rte_crypto_sym_xform *xforms,
 			struct rte_mempool *mempool);
 
-/**
- * Initialize asymmetric session on a device with specific asymmetric xform
- *
- * @param   dev_id   ID of device that we want the session to be used on
- * @param   sess     Session to be set up on a device
- * @param   xforms   Asymmetric crypto transform operations to apply on flow
- *                   processed with this session
- * @param   mempool  Mempool to be used for internal allocation.
- *
- * @return
- *  - On success, zero.
- *  - -EINVAL if input parameters are invalid.
- *  - -ENOTSUP if crypto device does not support the crypto transform.
- *  - -ENOMEM if the private session could not be allocated.
- */
-__rte_experimental
-int
-rte_cryptodev_asym_session_init(uint8_t dev_id,
-			struct rte_cryptodev_asym_session *sess,
-			struct rte_crypto_asym_xform *xforms,
-			struct rte_mempool *mempool);
-
 /**
  * Frees private data for the device id, based on its device type,
  * returning it to its mempool. It is the application's responsibility
@@ -1074,21 +1084,6 @@ int
 rte_cryptodev_sym_session_clear(uint8_t dev_id,
 			struct rte_cryptodev_sym_session *sess);
 
-/**
- * Frees resources held by asymmetric session during rte_cryptodev_session_init
- *
- * @param   dev_id   ID of device that uses the asymmetric session.
- * @param   sess     Asymmetric session setup on device using
- *					 rte_cryptodev_session_init
- * @return
- *  - 0 if successful.
- *  - -EINVAL if device is invalid or session is NULL.
- */
-__rte_experimental
-int
-rte_cryptodev_asym_session_clear(uint8_t dev_id,
-			struct rte_cryptodev_asym_session *sess);
-
 /**
  * Get the size of the header session, for all registered drivers excluding
  * the user data size.
@@ -1116,7 +1111,7 @@ rte_cryptodev_sym_get_existing_header_session_size(
 		struct rte_cryptodev_sym_session *sess);
 
 /**
- * Get the size of the asymmetric session header, for all registered drivers.
+ * Get the size of the asymmetric session header.
  *
  * @return
  *   Size of the asymmetric header session.
diff --git a/lib/cryptodev/rte_cryptodev_trace.h b/lib/cryptodev/rte_cryptodev_trace.h
index d1f4f069a3..a4fa9e8c7e 100644
--- a/lib/cryptodev/rte_cryptodev_trace.h
+++ b/lib/cryptodev/rte_cryptodev_trace.h
@@ -83,12 +83,22 @@ RTE_TRACE_POINT(
 	rte_trace_point_emit_u16(sess->user_data_sz);
 )
 
+RTE_TRACE_POINT(
+	rte_cryptodev_trace_asym_session_pool_create,
+	RTE_TRACE_POINT_ARGS(const char *name, uint32_t nb_elts,
+		uint32_t cache_size, void *mempool),
+	rte_trace_point_emit_string(name);
+	rte_trace_point_emit_u32(nb_elts);
+	rte_trace_point_emit_u32(cache_size);
+	rte_trace_point_emit_ptr(mempool);
+)
+
 RTE_TRACE_POINT(
 	rte_cryptodev_trace_asym_session_create,
-	RTE_TRACE_POINT_ARGS(void *mempool,
-		struct rte_cryptodev_asym_session *sess),
+	RTE_TRACE_POINT_ARGS(uint8_t dev_id, void *xforms, void *mempool),
+	rte_trace_point_emit_u8(dev_id);
+	rte_trace_point_emit_ptr(xforms);
 	rte_trace_point_emit_ptr(mempool);
-	rte_trace_point_emit_ptr(sess);
 )
 
 RTE_TRACE_POINT(
@@ -99,7 +109,9 @@ RTE_TRACE_POINT(
 
 RTE_TRACE_POINT(
 	rte_cryptodev_trace_asym_session_free,
-	RTE_TRACE_POINT_ARGS(struct rte_cryptodev_asym_session *sess),
+	RTE_TRACE_POINT_ARGS(uint8_t dev_id,
+		struct rte_cryptodev_asym_session *sess),
+	rte_trace_point_emit_u8(dev_id);
 	rte_trace_point_emit_ptr(sess);
 )
 
@@ -117,17 +129,6 @@ RTE_TRACE_POINT(
 	rte_trace_point_emit_ptr(mempool);
 )
 
-RTE_TRACE_POINT(
-	rte_cryptodev_trace_asym_session_init,
-	RTE_TRACE_POINT_ARGS(uint8_t dev_id,
-		struct rte_cryptodev_asym_session *sess, void *xforms,
-		void *mempool),
-	rte_trace_point_emit_u8(dev_id);
-	rte_trace_point_emit_ptr(sess);
-	rte_trace_point_emit_ptr(xforms);
-	rte_trace_point_emit_ptr(mempool);
-)
-
 RTE_TRACE_POINT(
 	rte_cryptodev_trace_sym_session_clear,
 	RTE_TRACE_POINT_ARGS(uint8_t dev_id, void *sess),
@@ -135,13 +136,6 @@ RTE_TRACE_POINT(
 	rte_trace_point_emit_ptr(sess);
 )
 
-RTE_TRACE_POINT(
-	rte_cryptodev_trace_asym_session_clear,
-	RTE_TRACE_POINT_ARGS(uint8_t dev_id, void *sess),
-	rte_trace_point_emit_u8(dev_id);
-	rte_trace_point_emit_ptr(sess);
-)
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/cryptodev/version.map b/lib/cryptodev/version.map
index c50745fa8c..44d1aff0e2 100644
--- a/lib/cryptodev/version.map
+++ b/lib/cryptodev/version.map
@@ -55,10 +55,8 @@ EXPERIMENTAL {
 	rte_cryptodev_asym_get_header_session_size;
 	rte_cryptodev_asym_get_private_session_size;
 	rte_cryptodev_asym_get_xform_enum;
-	rte_cryptodev_asym_session_clear;
 	rte_cryptodev_asym_session_create;
 	rte_cryptodev_asym_session_free;
-	rte_cryptodev_asym_session_init;
 	rte_cryptodev_asym_xform_capability_check_modlen;
 	rte_cryptodev_asym_xform_capability_check_optype;
 	rte_cryptodev_sym_cpu_crypto_process;
@@ -81,9 +79,7 @@ EXPERIMENTAL {
 	__rte_cryptodev_trace_sym_session_free;
 	__rte_cryptodev_trace_asym_session_free;
 	__rte_cryptodev_trace_sym_session_init;
-	__rte_cryptodev_trace_asym_session_init;
 	__rte_cryptodev_trace_sym_session_clear;
-	__rte_cryptodev_trace_asym_session_clear;
 	__rte_cryptodev_trace_dequeue_burst;
 	__rte_cryptodev_trace_enqueue_burst;
 
@@ -104,6 +100,9 @@ EXPERIMENTAL {
 	rte_cryptodev_remove_deq_callback;
 	rte_cryptodev_remove_enq_callback;
 
+	# added 22.03
+	rte_cryptodev_asym_session_pool_create;
+	__rte_cryptodev_trace_asym_session_pool_create;
 };
 
 INTERNAL {
-- 
2.25.1


^ permalink raw reply	[flat|nested] 31+ messages in thread

* [PATCH v6 3/5] crypto: hide asym session structure
  2022-02-10 15:53 ` [PATCH v6 0/5] crypto: improve asym session usage Ciara Power
  2022-02-10 15:54   ` [PATCH v6 1/5] doc: replace asym crypto code with literal includes Ciara Power
  2022-02-10 15:54   ` [PATCH v6 2/5] crypto: use single buffer for asymmetric session Ciara Power
@ 2022-02-10 15:54   ` Ciara Power
  2022-02-10 15:54   ` [PATCH v6 4/5] crypto: add asym session user data API Ciara Power
                     ` (2 subsequent siblings)
  5 siblings, 0 replies; 31+ messages in thread
From: Ciara Power @ 2022-02-10 15:54 UTC (permalink / raw)
  To: dev; +Cc: roy.fan.zhang, gakhil, anoobj, mdr, Ciara Power, Declan Doherty

The rte_cryptodev_asym_session structure is now moved to an internal
header. This will no longer be used directly by apps,
private session data can be accessed via get API.

Signed-off-by: Ciara Power <ciara.power@intel.com>
Acked-by: Fan Zhang <roy.fan.zhang@intel.com>
Acked-by: Anoob Joseph <anoobj@marvell.com>

---
v4:
  - Initialised session variables as NULL.
  - Removed docs code additions, these are included due to patch 1
    changing sample doc to use literal includes.
v3:
  - Removed the incorrect use of void * for asym session in drivers,
    these are internal and can use the struct directly as before.
  - Fixed other internal functions and comments that were incorrectly
    changed to use void *sess.
  - Added documentation.
---
 app/test-crypto-perf/cperf_ops.c        |  2 +-
 app/test/test_cryptodev_asym.c          | 34 ++++++++++++-------------
 doc/guides/prog_guide/cryptodev_lib.rst |  4 +++
 doc/guides/rel_notes/release_22_03.rst  |  2 ++
 lib/cryptodev/cryptodev_pmd.h           | 13 ++++++++++
 lib/cryptodev/rte_cryptodev.c           |  5 ++--
 lib/cryptodev/rte_cryptodev.h           | 15 ++---------
 lib/cryptodev/rte_cryptodev_trace.h     |  3 +--
 8 files changed, 42 insertions(+), 36 deletions(-)

diff --git a/app/test-crypto-perf/cperf_ops.c b/app/test-crypto-perf/cperf_ops.c
index b125c699de..b8f590b397 100644
--- a/app/test-crypto-perf/cperf_ops.c
+++ b/app/test-crypto-perf/cperf_ops.c
@@ -21,7 +21,7 @@ cperf_set_ops_asym(struct rte_crypto_op **ops,
 		   uint64_t *tsc_start __rte_unused)
 {
 	uint16_t i;
-	struct rte_cryptodev_asym_session *asym_sess = (void *)sess;
+	void *asym_sess = (void *)sess;
 
 	for (i = 0; i < nb_ops; i++) {
 		struct rte_crypto_asym_op *asym_op = ops[i]->asym;
diff --git a/app/test/test_cryptodev_asym.c b/app/test/test_cryptodev_asym.c
index 88433faf1c..929d6efb24 100644
--- a/app/test/test_cryptodev_asym.c
+++ b/app/test/test_cryptodev_asym.c
@@ -46,7 +46,7 @@ struct crypto_testsuite_params_asym {
 };
 
 struct crypto_unittest_params {
-	struct rte_cryptodev_asym_session *sess;
+	void *sess;
 	struct rte_crypto_op *op;
 };
 
@@ -67,7 +67,7 @@ static uint32_t test_index;
 static struct crypto_testsuite_params_asym testsuite_params = { NULL };
 
 static int
-queue_ops_rsa_sign_verify(struct rte_cryptodev_asym_session *sess)
+queue_ops_rsa_sign_verify(void *sess)
 {
 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
 	struct rte_mempool *op_mpool = ts_params->op_mpool;
@@ -158,7 +158,7 @@ queue_ops_rsa_sign_verify(struct rte_cryptodev_asym_session *sess)
 }
 
 static int
-queue_ops_rsa_enc_dec(struct rte_cryptodev_asym_session *sess)
+queue_ops_rsa_enc_dec(void *sess)
 {
 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
 	struct rte_mempool *op_mpool = ts_params->op_mpool;
@@ -310,7 +310,7 @@ test_cryptodev_asym_op(struct crypto_testsuite_params_asym *ts_params,
 	struct rte_crypto_op *op = NULL;
 	struct rte_crypto_op *result_op = NULL;
 	struct rte_crypto_asym_xform xform_tc;
-	struct rte_cryptodev_asym_session *sess = NULL;
+	void *sess = NULL;
 	struct rte_cryptodev_asym_capability_idx cap_idx;
 	const struct rte_cryptodev_asymmetric_xform_capability *capability;
 	uint8_t dev_id = ts_params->valid_devs[0];
@@ -644,7 +644,7 @@ test_rsa_sign_verify(void)
 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
 	uint8_t dev_id = ts_params->valid_devs[0];
-	struct rte_cryptodev_asym_session *sess;
+	void *sess = NULL;
 	struct rte_cryptodev_info dev_info;
 	int status = TEST_SUCCESS;
 
@@ -684,7 +684,7 @@ test_rsa_enc_dec(void)
 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
 	uint8_t dev_id = ts_params->valid_devs[0];
-	struct rte_cryptodev_asym_session *sess;
+	void *sess = NULL;
 	struct rte_cryptodev_info dev_info;
 	int status = TEST_SUCCESS;
 
@@ -724,7 +724,7 @@ test_rsa_sign_verify_crt(void)
 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
 	uint8_t dev_id = ts_params->valid_devs[0];
-	struct rte_cryptodev_asym_session *sess;
+	void *sess = NULL;
 	struct rte_cryptodev_info dev_info;
 	int status = TEST_SUCCESS;
 
@@ -764,7 +764,7 @@ test_rsa_enc_dec_crt(void)
 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
 	uint8_t dev_id = ts_params->valid_devs[0];
-	struct rte_cryptodev_asym_session *sess;
+	void *sess = NULL;
 	struct rte_cryptodev_info dev_info;
 	int status = TEST_SUCCESS;
 
@@ -1046,7 +1046,7 @@ test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
 	uint8_t dev_id = ts_params->valid_devs[0];
 	struct rte_crypto_asym_op *asym_op = NULL;
 	struct rte_crypto_op *op = NULL, *result_op = NULL;
-	struct rte_cryptodev_asym_session *sess = NULL;
+	void *sess = NULL;
 	int status = TEST_SUCCESS;
 	uint8_t output[TEST_DH_MOD_LEN];
 	struct rte_crypto_asym_xform xform = *xfrm;
@@ -1129,7 +1129,7 @@ test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
 	uint8_t dev_id = ts_params->valid_devs[0];
 	struct rte_crypto_asym_op *asym_op = NULL;
 	struct rte_crypto_op *op = NULL, *result_op = NULL;
-	struct rte_cryptodev_asym_session *sess = NULL;
+	void *sess = NULL;
 	int status = TEST_SUCCESS;
 	uint8_t output[TEST_DH_MOD_LEN];
 	struct rte_crypto_asym_xform xform = *xfrm;
@@ -1210,7 +1210,7 @@ test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
 	uint8_t dev_id = ts_params->valid_devs[0];
 	struct rte_crypto_asym_op *asym_op = NULL;
 	struct rte_crypto_op *op = NULL, *result_op = NULL;
-	struct rte_cryptodev_asym_session *sess = NULL;
+	void *sess = NULL;
 	int status = TEST_SUCCESS;
 	uint8_t output[TEST_DH_MOD_LEN];
 	struct rte_crypto_asym_xform xform = *xfrm;
@@ -1299,7 +1299,7 @@ test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
 	uint8_t dev_id = ts_params->valid_devs[0];
 	struct rte_crypto_asym_op *asym_op = NULL;
 	struct rte_crypto_op *op = NULL, *result_op = NULL;
-	struct rte_cryptodev_asym_session *sess = NULL;
+	void *sess = NULL;
 	int status = TEST_SUCCESS;
 	uint8_t out_pub_key[TEST_DH_MOD_LEN];
 	uint8_t out_prv_key[TEST_DH_MOD_LEN];
@@ -1386,7 +1386,7 @@ test_mod_inv(void)
 	uint8_t dev_id = ts_params->valid_devs[0];
 	struct rte_crypto_asym_op *asym_op = NULL;
 	struct rte_crypto_op *op = NULL, *result_op = NULL;
-	struct rte_cryptodev_asym_session *sess = NULL;
+	void *sess = NULL;
 	int status = TEST_SUCCESS;
 	struct rte_cryptodev_asym_capability_idx cap_idx;
 	const struct rte_cryptodev_asymmetric_xform_capability *capability;
@@ -1499,7 +1499,7 @@ test_mod_exp(void)
 	uint8_t dev_id = ts_params->valid_devs[0];
 	struct rte_crypto_asym_op *asym_op = NULL;
 	struct rte_crypto_op *op = NULL, *result_op = NULL;
-	struct rte_cryptodev_asym_session *sess = NULL;
+	void *sess = NULL;
 	int status = TEST_SUCCESS;
 	struct rte_cryptodev_asym_capability_idx cap_idx;
 	const struct rte_cryptodev_asymmetric_xform_capability *capability;
@@ -1648,7 +1648,7 @@ test_dsa_sign(void)
 	uint8_t dev_id = ts_params->valid_devs[0];
 	struct rte_crypto_asym_op *asym_op = NULL;
 	struct rte_crypto_op *op = NULL, *result_op = NULL;
-	struct rte_cryptodev_asym_session *sess = NULL;
+	void *sess = NULL;
 	int status = TEST_SUCCESS;
 	uint8_t r[TEST_DH_MOD_LEN];
 	uint8_t s[TEST_DH_MOD_LEN];
@@ -1779,7 +1779,7 @@ test_ecdsa_sign_verify(enum curve curve_id)
 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
 	struct rte_mempool *op_mpool = ts_params->op_mpool;
 	struct crypto_testsuite_ecdsa_params input_params;
-	struct rte_cryptodev_asym_session *sess = NULL;
+	void *sess = NULL;
 	uint8_t dev_id = ts_params->valid_devs[0];
 	struct rte_crypto_op *result_op = NULL;
 	uint8_t output_buf_r[TEST_DATA_SIZE];
@@ -1981,7 +1981,7 @@ test_ecpm(enum curve curve_id)
 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
 	struct rte_mempool *op_mpool = ts_params->op_mpool;
 	struct crypto_testsuite_ecpm_params input_params;
-	struct rte_cryptodev_asym_session *sess = NULL;
+	void *sess = NULL;
 	uint8_t dev_id = ts_params->valid_devs[0];
 	struct rte_crypto_op *result_op = NULL;
 	uint8_t output_buf_x[TEST_DATA_SIZE];
diff --git a/doc/guides/prog_guide/cryptodev_lib.rst b/doc/guides/prog_guide/cryptodev_lib.rst
index b4dbd384bf..2607a9a7d7 100644
--- a/doc/guides/prog_guide/cryptodev_lib.rst
+++ b/doc/guides/prog_guide/cryptodev_lib.rst
@@ -1155,6 +1155,10 @@ Generate crypto op, create and attach a session, then process packets.
    :end-before: >8 End of create op, create session, and process packets section.
    :dedent: 1
 
+.. note::
+   The ``rte_cryptodev_asym_session`` struct is hidden from the application.
+   The ``sess`` pointer used above is a void pointer.
+
 
 Asymmetric Crypto Device API
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
diff --git a/doc/guides/rel_notes/release_22_03.rst b/doc/guides/rel_notes/release_22_03.rst
index ea4c5309a0..459b15bdde 100644
--- a/doc/guides/rel_notes/release_22_03.rst
+++ b/doc/guides/rel_notes/release_22_03.rst
@@ -116,6 +116,8 @@ API Changes
   mempool object. An API ``rte_cryptodev_asym_session_pool_create`` was added
   to create a mempool with element size big enough to hold the generic asymmetric
   session header and max size for a device private session data.
+  The session structure was moved to ``cryptodev_pmd.h``,
+  hiding it from applications.
   The API ``rte_cryptodev_asym_session_init`` was removed as the initialization
   is now moved to ``rte_cryptodev_asym_session_create``.
 
diff --git a/lib/cryptodev/cryptodev_pmd.h b/lib/cryptodev/cryptodev_pmd.h
index 142bfb7c66..63f9cf5427 100644
--- a/lib/cryptodev/cryptodev_pmd.h
+++ b/lib/cryptodev/cryptodev_pmd.h
@@ -625,4 +625,17 @@ set_sym_session_private_data(struct rte_cryptodev_sym_session *sess,
 	sess->sess_data[driver_id].data = private_data;
 }
 
+/**
+ * @internal
+ * Cryptodev asymmetric crypto session.
+ */
+RTE_STD_C11 struct rte_cryptodev_asym_session {
+	uint8_t driver_id;
+	/**< Session driver ID. */
+	uint16_t max_priv_data_sz;
+	/**< Size of private data used when creating mempool */
+	uint8_t padding[5];
+	uint8_t sess_private_data[0];
+};
+
 #endif /* _CRYPTODEV_PMD_H_ */
diff --git a/lib/cryptodev/rte_cryptodev.c b/lib/cryptodev/rte_cryptodev.c
index b056d88ac2..562cb4a2c4 100644
--- a/lib/cryptodev/rte_cryptodev.c
+++ b/lib/cryptodev/rte_cryptodev.c
@@ -1908,7 +1908,7 @@ rte_cryptodev_sym_session_create(struct rte_mempool *mp)
 	return sess;
 }
 
-struct rte_cryptodev_asym_session *
+void *
 rte_cryptodev_asym_session_create(uint8_t dev_id,
 		struct rte_crypto_asym_xform *xforms, struct rte_mempool *mp)
 {
@@ -2035,8 +2035,7 @@ rte_cryptodev_sym_session_free(struct rte_cryptodev_sym_session *sess)
 }
 
 int
-rte_cryptodev_asym_session_free(uint8_t dev_id,
-		struct rte_cryptodev_asym_session *sess)
+rte_cryptodev_asym_session_free(uint8_t dev_id, void *sess)
 {
 	struct rte_mempool *sess_mp;
 	struct rte_cryptodev *dev;
diff --git a/lib/cryptodev/rte_cryptodev.h b/lib/cryptodev/rte_cryptodev.h
index 90e764017d..4cf3f6c9d7 100644
--- a/lib/cryptodev/rte_cryptodev.h
+++ b/lib/cryptodev/rte_cryptodev.h
@@ -918,16 +918,6 @@ struct rte_cryptodev_sym_session {
 	/**< Driver specific session material, variable size */
 };
 
-/** Cryptodev asymmetric crypto session */
-RTE_STD_C11 struct rte_cryptodev_asym_session {
-	uint8_t driver_id;
-	/**< Session driver ID. */
-	uint16_t max_priv_data_sz;
-	/**< Size of private data used when creating mempool */
-	uint8_t padding[5];
-	uint8_t sess_private_data[0];
-};
-
 /**
  * Create a symmetric session mempool.
  *
@@ -1009,7 +999,7 @@ rte_cryptodev_sym_session_create(struct rte_mempool *mempool);
  *  - On failure returns NULL
  */
 __rte_experimental
-struct rte_cryptodev_asym_session *
+void *
 rte_cryptodev_asym_session_create(uint8_t dev_id,
 		struct rte_crypto_asym_xform *xforms, struct rte_mempool *mp);
 
@@ -1041,8 +1031,7 @@ rte_cryptodev_sym_session_free(struct rte_cryptodev_sym_session *sess);
  */
 __rte_experimental
 int
-rte_cryptodev_asym_session_free(uint8_t dev_id,
-		struct rte_cryptodev_asym_session *sess);
+rte_cryptodev_asym_session_free(uint8_t dev_id, void *sess);
 
 /**
  * Fill out private data for the device id, based on its device type.
diff --git a/lib/cryptodev/rte_cryptodev_trace.h b/lib/cryptodev/rte_cryptodev_trace.h
index a4fa9e8c7e..4b48c66199 100644
--- a/lib/cryptodev/rte_cryptodev_trace.h
+++ b/lib/cryptodev/rte_cryptodev_trace.h
@@ -109,8 +109,7 @@ RTE_TRACE_POINT(
 
 RTE_TRACE_POINT(
 	rte_cryptodev_trace_asym_session_free,
-	RTE_TRACE_POINT_ARGS(uint8_t dev_id,
-		struct rte_cryptodev_asym_session *sess),
+	RTE_TRACE_POINT_ARGS(uint8_t dev_id, void *sess),
 	rte_trace_point_emit_u8(dev_id);
 	rte_trace_point_emit_ptr(sess);
 )
-- 
2.25.1


^ permalink raw reply	[flat|nested] 31+ messages in thread

* [PATCH v6 4/5] crypto: add asym session user data API
  2022-02-10 15:53 ` [PATCH v6 0/5] crypto: improve asym session usage Ciara Power
                     ` (2 preceding siblings ...)
  2022-02-10 15:54   ` [PATCH v6 3/5] crypto: hide asym session structure Ciara Power
@ 2022-02-10 15:54   ` Ciara Power
  2022-02-10 15:54   ` [PATCH v6 5/5] crypto: modify return value for asym session create Ciara Power
  2022-02-10 22:37   ` [EXT] [PATCH v6 0/5] crypto: improve asym session usage Akhil Goyal
  5 siblings, 0 replies; 31+ messages in thread
From: Ciara Power @ 2022-02-10 15:54 UTC (permalink / raw)
  To: dev; +Cc: roy.fan.zhang, gakhil, anoobj, mdr, Ciara Power, Declan Doherty

A user data field is added to the asymmetric session structure.
Relevant API added to get/set the field.

Signed-off-by: Ciara Power <ciara.power@intel.com>
Acked-by: Fan Zhang <roy.fan.zhang@intel.com>
Acked-by: Anoob Joseph <anoobj@marvell.com>

---
v4:
  - Reworded release notes.
  - Added possible error return values in function comment.
  - Removed docs code additions, these are included due to patch 1
    changing sample doc to use literal includes.
v3:
  - Corrected formatting of struct comments.
  - Added setting user data size in pool creation.
  - Added documentation.
v2: Corrected order of version map entries.
---
 app/test-crypto-perf/main.c             |  2 +-
 app/test/test_cryptodev_asym.c          |  2 +-
 doc/guides/prog_guide/cryptodev_lib.rst | 19 ++++++++++++
 doc/guides/rel_notes/release_22_03.rst  |  6 +++-
 lib/cryptodev/cryptodev_pmd.h           |  4 ++-
 lib/cryptodev/rte_cryptodev.c           | 40 ++++++++++++++++++++++---
 lib/cryptodev/rte_cryptodev.h           | 35 +++++++++++++++++++++-
 lib/cryptodev/rte_cryptodev_trace.h     |  3 +-
 lib/cryptodev/version.map               |  2 ++
 9 files changed, 103 insertions(+), 10 deletions(-)

diff --git a/app/test-crypto-perf/main.c b/app/test-crypto-perf/main.c
index 115bf923f8..7544b88b80 100644
--- a/app/test-crypto-perf/main.c
+++ b/app/test-crypto-perf/main.c
@@ -79,7 +79,7 @@ create_asym_op_pool_socket(uint8_t dev_id, int32_t socket_id,
 		snprintf(mp_name, RTE_MEMPOOL_NAMESIZE, "perf_asym_sess_pool%u",
 			 socket_id);
 		mpool = rte_cryptodev_asym_session_pool_create(mp_name,
-				nb_sessions, 0, socket_id);
+				nb_sessions, 0, 0, socket_id);
 		if (mpool == NULL) {
 			printf("Cannot create pool \"%s\" on socket %d\n",
 			       mp_name, socket_id);
diff --git a/app/test/test_cryptodev_asym.c b/app/test/test_cryptodev_asym.c
index 929d6efb24..f0cb839a49 100644
--- a/app/test/test_cryptodev_asym.c
+++ b/app/test/test_cryptodev_asym.c
@@ -894,7 +894,7 @@ testsuite_setup(void)
 	}
 
 	ts_params->session_mpool = rte_cryptodev_asym_session_pool_create(
-			"test_asym_sess_mp", TEST_NUM_SESSIONS, 0,
+			"test_asym_sess_mp", TEST_NUM_SESSIONS, 0, 0,
 			SOCKET_ID_ANY);
 
 	TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
diff --git a/doc/guides/prog_guide/cryptodev_lib.rst b/doc/guides/prog_guide/cryptodev_lib.rst
index 2607a9a7d7..ba4c592b84 100644
--- a/doc/guides/prog_guide/cryptodev_lib.rst
+++ b/doc/guides/prog_guide/cryptodev_lib.rst
@@ -1110,6 +1110,25 @@ They operate on data buffer of type ``rte_crypto_param``.
 
 See *DPDK API Reference* for details on each rte_crypto_xxx_op_param struct
 
+Private user data
+~~~~~~~~~~~~~~~~~
+
+Similar to symmetric above, asymmetric also has a set and get API that provides a
+mechanism for an application to store and retrieve the private user data information
+stored along with the crypto session.
+
+.. code-block:: c
+
+	int rte_cryptodev_asym_session_set_user_data(void *sess,
+		void *data, uint16_t size);
+
+	void * rte_cryptodev_asym_session_get_user_data(void *sess);
+
+Please note the ``size`` passed to set API cannot be bigger than the predefined
+``user_data_sz`` when creating the session mempool, otherwise the function will
+return an error. Also when ``user_data_sz`` was defined as ``0`` when
+creating the session mempool, the get API will always return ``NULL``.
+
 Asymmetric crypto Sample code
 -----------------------------
 
diff --git a/doc/guides/rel_notes/release_22_03.rst b/doc/guides/rel_notes/release_22_03.rst
index 459b15bdde..a930cbbad6 100644
--- a/doc/guides/rel_notes/release_22_03.rst
+++ b/doc/guides/rel_notes/release_22_03.rst
@@ -78,6 +78,10 @@ New Features
 
   The new API ``rte_event_eth_rx_adapter_event_port_get()`` was added.
 
+* **Added an API for private user data in Asymmetric crypto session.**
+
+  An API was added for getting/setting an Asymmetric crypto session's user data.
+
 
 Removed Items
 -------------
@@ -115,7 +119,7 @@ API Changes
 * cryptodev: The asymmetric session handling was modified to use a single
   mempool object. An API ``rte_cryptodev_asym_session_pool_create`` was added
   to create a mempool with element size big enough to hold the generic asymmetric
-  session header and max size for a device private session data.
+  session header, max size for a device private session data, and user data size.
   The session structure was moved to ``cryptodev_pmd.h``,
   hiding it from applications.
   The API ``rte_cryptodev_asym_session_init`` was removed as the initialization
diff --git a/lib/cryptodev/cryptodev_pmd.h b/lib/cryptodev/cryptodev_pmd.h
index 63f9cf5427..d91902f6e0 100644
--- a/lib/cryptodev/cryptodev_pmd.h
+++ b/lib/cryptodev/cryptodev_pmd.h
@@ -634,7 +634,9 @@ RTE_STD_C11 struct rte_cryptodev_asym_session {
 	/**< Session driver ID. */
 	uint16_t max_priv_data_sz;
 	/**< Size of private data used when creating mempool */
-	uint8_t padding[5];
+	uint16_t user_data_sz;
+	/**< Session user data will be placed after sess_data */
+	uint8_t padding[3];
 	uint8_t sess_private_data[0];
 };
 
diff --git a/lib/cryptodev/rte_cryptodev.c b/lib/cryptodev/rte_cryptodev.c
index 562cb4a2c4..91d48d5886 100644
--- a/lib/cryptodev/rte_cryptodev.c
+++ b/lib/cryptodev/rte_cryptodev.c
@@ -210,6 +210,8 @@ struct rte_cryptodev_sym_session_pool_private_data {
 struct rte_cryptodev_asym_session_pool_private_data {
 	uint16_t max_priv_session_sz;
 	/**< Size of private session data used when creating mempool */
+	uint16_t user_data_sz;
+	/**< Session user data will be placed after sess_private_data */
 };
 
 int
@@ -1803,7 +1805,7 @@ rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
 
 struct rte_mempool *
 rte_cryptodev_asym_session_pool_create(const char *name, uint32_t nb_elts,
-	uint32_t cache_size, int socket_id)
+	uint32_t cache_size, uint16_t user_data_size, int socket_id)
 {
 	struct rte_mempool *mp;
 	struct rte_cryptodev_asym_session_pool_private_data *pool_priv;
@@ -1821,7 +1823,8 @@ rte_cryptodev_asym_session_pool_create(const char *name, uint32_t nb_elts,
 		return NULL;
 	}
 
-	obj_sz = rte_cryptodev_asym_get_header_session_size() + max_priv_sz;
+	obj_sz = rte_cryptodev_asym_get_header_session_size() + max_priv_sz +
+			user_data_size;
 	obj_sz_aligned =  RTE_ALIGN_CEIL(obj_sz, RTE_CACHE_LINE_SIZE);
 
 	mp = rte_mempool_create(name, nb_elts, obj_sz_aligned, cache_size,
@@ -1842,9 +1845,10 @@ rte_cryptodev_asym_session_pool_create(const char *name, uint32_t nb_elts,
 		return NULL;
 	}
 	pool_priv->max_priv_session_sz = max_priv_sz;
+	pool_priv->user_data_sz = user_data_size;
 
 	rte_cryptodev_trace_asym_session_pool_create(name, nb_elts,
-		cache_size, mp);
+		user_data_size, cache_size, mp);
 	return mp;
 }
 
@@ -1959,10 +1963,11 @@ rte_cryptodev_asym_session_create(uint8_t dev_id,
 	}
 
 	sess->driver_id = dev->driver_id;
+	sess->user_data_sz = pool_priv->user_data_sz;
 	sess->max_priv_data_sz = pool_priv->max_priv_session_sz;
 
 	/* Clear device session pointer.*/
-	memset(sess->sess_private_data, 0, session_priv_data_sz);
+	memset(sess->sess_private_data, 0, session_priv_data_sz + sess->user_data_sz);
 
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->asym_session_configure, NULL);
 
@@ -2159,6 +2164,33 @@ rte_cryptodev_sym_session_get_user_data(
 	return (void *)(sess->sess_data + sess->nb_drivers);
 }
 
+int
+rte_cryptodev_asym_session_set_user_data(void *session, void *data, uint16_t size)
+{
+	struct rte_cryptodev_asym_session *sess = session;
+	if (sess == NULL)
+		return -EINVAL;
+
+	if (sess->user_data_sz < size)
+		return -ENOMEM;
+
+	rte_memcpy(sess->sess_private_data +
+			sess->max_priv_data_sz,
+			data, size);
+	return 0;
+}
+
+void *
+rte_cryptodev_asym_session_get_user_data(void *session)
+{
+	struct rte_cryptodev_asym_session *sess = session;
+	if (sess == NULL || sess->user_data_sz == 0)
+		return NULL;
+
+	return (void *)(sess->sess_private_data +
+			sess->max_priv_data_sz);
+}
+
 static inline void
 sym_crypto_fill_status(struct rte_crypto_sym_vec *vec, int32_t errnum)
 {
diff --git a/lib/cryptodev/rte_cryptodev.h b/lib/cryptodev/rte_cryptodev.h
index 4cf3f6c9d7..1d7bd07680 100644
--- a/lib/cryptodev/rte_cryptodev.h
+++ b/lib/cryptodev/rte_cryptodev.h
@@ -959,6 +959,8 @@ rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
  *   The number of elements in the mempool.
  * @param cache_size
  *   The number of per-lcore cache elements
+ * @param user_data_size
+ *   The size of user data to be placed after session private data.
  * @param socket_id
  *   The *socket_id* argument is the socket identifier in the case of
  *   NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA
@@ -971,7 +973,7 @@ rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
 __rte_experimental
 struct rte_mempool *
 rte_cryptodev_asym_session_pool_create(const char *name, uint32_t nb_elts,
-	uint32_t cache_size, int socket_id);
+	uint32_t cache_size, uint16_t user_data_size, int socket_id);
 
 /**
  * Create symmetric crypto session header (generic with no private data)
@@ -1202,6 +1204,37 @@ void *
 rte_cryptodev_sym_session_get_user_data(
 					struct rte_cryptodev_sym_session *sess);
 
+/**
+ * Store user data in an asymmetric session.
+ *
+ * @param	sess		Session pointer allocated by
+ *				*rte_cryptodev_asym_session_create*.
+ * @param	data		Pointer to the user data.
+ * @param	size		Size of the user data.
+ *
+ * @return
+ *  - On success, zero.
+ *  - -EINVAL if the session pointer is invalid.
+ *  - -ENOMEM if the available user data size is smaller than the size parameter.
+ */
+__rte_experimental
+int
+rte_cryptodev_asym_session_set_user_data(void *sess, void *data, uint16_t size);
+
+/**
+ * Get user data stored in an asymmetric session.
+ *
+ * @param	sess		Session pointer allocated by
+ *				*rte_cryptodev_asym_session_create*.
+ *
+ * @return
+ *  - On success return pointer to user data.
+ *  - On failure returns NULL.
+ */
+__rte_experimental
+void *
+rte_cryptodev_asym_session_get_user_data(void *sess);
+
 /**
  * Perform actual crypto processing (encrypt/digest or auth/decrypt)
  * on user provided data.
diff --git a/lib/cryptodev/rte_cryptodev_trace.h b/lib/cryptodev/rte_cryptodev_trace.h
index 4b48c66199..005a4fe38b 100644
--- a/lib/cryptodev/rte_cryptodev_trace.h
+++ b/lib/cryptodev/rte_cryptodev_trace.h
@@ -86,9 +86,10 @@ RTE_TRACE_POINT(
 RTE_TRACE_POINT(
 	rte_cryptodev_trace_asym_session_pool_create,
 	RTE_TRACE_POINT_ARGS(const char *name, uint32_t nb_elts,
-		uint32_t cache_size, void *mempool),
+		uint16_t user_data_size, uint32_t cache_size, void *mempool),
 	rte_trace_point_emit_string(name);
 	rte_trace_point_emit_u32(nb_elts);
+	rte_trace_point_emit_u16(user_data_size);
 	rte_trace_point_emit_u32(cache_size);
 	rte_trace_point_emit_ptr(mempool);
 )
diff --git a/lib/cryptodev/version.map b/lib/cryptodev/version.map
index 44d1aff0e2..c7c5aefceb 100644
--- a/lib/cryptodev/version.map
+++ b/lib/cryptodev/version.map
@@ -101,7 +101,9 @@ EXPERIMENTAL {
 	rte_cryptodev_remove_enq_callback;
 
 	# added 22.03
+	rte_cryptodev_asym_session_get_user_data;
 	rte_cryptodev_asym_session_pool_create;
+	rte_cryptodev_asym_session_set_user_data;
 	__rte_cryptodev_trace_asym_session_pool_create;
 };
 
-- 
2.25.1


^ permalink raw reply	[flat|nested] 31+ messages in thread

* [PATCH v6 5/5] crypto: modify return value for asym session create
  2022-02-10 15:53 ` [PATCH v6 0/5] crypto: improve asym session usage Ciara Power
                     ` (3 preceding siblings ...)
  2022-02-10 15:54   ` [PATCH v6 4/5] crypto: add asym session user data API Ciara Power
@ 2022-02-10 15:54   ` Ciara Power
  2022-02-10 22:37   ` [EXT] [PATCH v6 0/5] crypto: improve asym session usage Akhil Goyal
  5 siblings, 0 replies; 31+ messages in thread
From: Ciara Power @ 2022-02-10 15:54 UTC (permalink / raw)
  To: dev; +Cc: roy.fan.zhang, gakhil, anoobj, mdr, Ciara Power, Declan Doherty

Rather than the asym session create function returning a session on
success, and a NULL value on error, it is modified to now return int
values - 0 on success or -EINVAL/-ENOTSUP/-ENOMEM on failure.
The session to be used is passed as input.

This adds clarity on the failure of the create function, which enables
treating the -ENOTSUP return as TEST_SKIPPED in test apps.

Signed-off-by: Ciara Power <ciara.power@intel.com>
Acked-by: Fan Zhang <roy.fan.zhang@intel.com>
Acked-by: Anoob Joseph <anoobj@marvell.com>
Acked-by: Akhil Goyal <gakhil@marvell.com>

---
v5: Added session parameter to create session trace.
v4:
  - Reordered function parameters.
  - Removed docs code additions, these are included due to patch 1
    changing sample doc to use literal includes.
v3:
  - Fixed variable declarations, putting initialised variable last.
  - Made function comment for return value more generic.
  - Fixed log to include line break.
  - Added documentation.
---
 app/test-crypto-perf/cperf_ops.c       |  12 ++-
 app/test/test_cryptodev_asym.c         | 109 +++++++++++++------------
 doc/guides/rel_notes/release_22_03.rst |   3 +-
 lib/cryptodev/rte_cryptodev.c          |  28 ++++---
 lib/cryptodev/rte_cryptodev.h          |  13 ++-
 lib/cryptodev/rte_cryptodev_trace.h    |   4 +-
 6 files changed, 92 insertions(+), 77 deletions(-)

diff --git a/app/test-crypto-perf/cperf_ops.c b/app/test-crypto-perf/cperf_ops.c
index b8f590b397..479c40eead 100644
--- a/app/test-crypto-perf/cperf_ops.c
+++ b/app/test-crypto-perf/cperf_ops.c
@@ -734,7 +734,9 @@ cperf_create_session(struct rte_mempool *sess_mp,
 	struct rte_crypto_sym_xform auth_xform;
 	struct rte_crypto_sym_xform aead_xform;
 	struct rte_cryptodev_sym_session *sess = NULL;
+	void *asym_sess = NULL;
 	struct rte_crypto_asym_xform xform = {0};
+	int ret;
 
 	if (options->op_type == CPERF_ASYM_MODEX) {
 		xform.next = NULL;
@@ -744,11 +746,13 @@ cperf_create_session(struct rte_mempool *sess_mp,
 		xform.modex.exponent.data = perf_mod_e;
 		xform.modex.exponent.length = sizeof(perf_mod_e);
 
-		sess = (void *)rte_cryptodev_asym_session_create(dev_id, &xform, sess_mp);
-		if (sess == NULL)
+		ret = rte_cryptodev_asym_session_create(dev_id, &xform,
+				sess_mp, &asym_sess);
+		if (ret < 0) {
+			RTE_LOG(ERR, USER1, "Asym session create failed\n");
 			return NULL;
-
-		return sess;
+		}
+		return asym_sess;
 	}
 #ifdef RTE_LIB_SECURITY
 	/*
diff --git a/app/test/test_cryptodev_asym.c b/app/test/test_cryptodev_asym.c
index f0cb839a49..c2e1b4dafd 100644
--- a/app/test/test_cryptodev_asym.c
+++ b/app/test/test_cryptodev_asym.c
@@ -317,7 +317,7 @@ test_cryptodev_asym_op(struct crypto_testsuite_params_asym *ts_params,
 	uint8_t input[TEST_DATA_SIZE] = {0};
 	uint8_t *result = NULL;
 
-	int status = TEST_SUCCESS;
+	int ret, status = TEST_SUCCESS;
 
 	xform_tc.next = NULL;
 	xform_tc.xform_type = data_tc->modex.xform_type;
@@ -452,14 +452,14 @@ test_cryptodev_asym_op(struct crypto_testsuite_params_asym *ts_params,
 	}
 
 	if (!sessionless) {
-		sess = rte_cryptodev_asym_session_create(dev_id, &xform_tc,
-				ts_params->session_mpool);
-		if (!sess) {
+		ret = rte_cryptodev_asym_session_create(dev_id, &xform_tc,
+				ts_params->session_mpool, &sess);
+		if (ret < 0) {
 			snprintf(test_msg, ASYM_TEST_MSG_LEN,
 					"line %u "
 					"FAILED: %s", __LINE__,
 					"Session creation failed");
-			status = TEST_FAILED;
+			status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 			goto error_exit;
 		}
 
@@ -646,7 +646,7 @@ test_rsa_sign_verify(void)
 	uint8_t dev_id = ts_params->valid_devs[0];
 	void *sess = NULL;
 	struct rte_cryptodev_info dev_info;
-	int status = TEST_SUCCESS;
+	int ret, status = TEST_SUCCESS;
 
 	/* Test case supports op with exponent key only,
 	 * Check in PMD feature flag for RSA exponent key type support.
@@ -659,12 +659,12 @@ test_rsa_sign_verify(void)
 		return TEST_SKIPPED;
 	}
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool);
+	ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool, &sess);
 
-	if (!sess) {
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1, "Session creation failed for "
 			"sign_verify\n");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto error_exit;
 	}
 
@@ -686,7 +686,7 @@ test_rsa_enc_dec(void)
 	uint8_t dev_id = ts_params->valid_devs[0];
 	void *sess = NULL;
 	struct rte_cryptodev_info dev_info;
-	int status = TEST_SUCCESS;
+	int ret, status = TEST_SUCCESS;
 
 	/* Test case supports op with exponent key only,
 	 * Check in PMD feature flag for RSA exponent key type support.
@@ -699,11 +699,11 @@ test_rsa_enc_dec(void)
 		return TEST_SKIPPED;
 	}
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool);
+	ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool, &sess);
 
-	if (!sess) {
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1, "Session creation failed for enc_dec\n");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto error_exit;
 	}
 
@@ -726,7 +726,7 @@ test_rsa_sign_verify_crt(void)
 	uint8_t dev_id = ts_params->valid_devs[0];
 	void *sess = NULL;
 	struct rte_cryptodev_info dev_info;
-	int status = TEST_SUCCESS;
+	int ret, status = TEST_SUCCESS;
 
 	/* Test case supports op with quintuple format key only,
 	 * Check im PMD feature flag for RSA quintuple key type support.
@@ -738,12 +738,12 @@ test_rsa_sign_verify_crt(void)
 		return TEST_SKIPPED;
 	}
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &rsa_xform_crt, sess_mpool);
+	ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform_crt, sess_mpool, &sess);
 
-	if (!sess) {
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1, "Session creation failed for "
 			"sign_verify_crt\n");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto error_exit;
 	}
 
@@ -766,7 +766,7 @@ test_rsa_enc_dec_crt(void)
 	uint8_t dev_id = ts_params->valid_devs[0];
 	void *sess = NULL;
 	struct rte_cryptodev_info dev_info;
-	int status = TEST_SUCCESS;
+	int ret, status = TEST_SUCCESS;
 
 	/* Test case supports op with quintuple format key only,
 	 * Check in PMD feature flag for RSA quintuple key type support.
@@ -778,12 +778,12 @@ test_rsa_enc_dec_crt(void)
 		return TEST_SKIPPED;
 	}
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &rsa_xform_crt, sess_mpool);
+	ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform_crt, sess_mpool, &sess);
 
-	if (!sess) {
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1, "Session creation failed for "
 			"enc_dec_crt\n");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto error_exit;
 	}
 
@@ -1047,7 +1047,7 @@ test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
 	struct rte_crypto_asym_op *asym_op = NULL;
 	struct rte_crypto_op *op = NULL, *result_op = NULL;
 	void *sess = NULL;
-	int status = TEST_SUCCESS;
+	int ret, status = TEST_SUCCESS;
 	uint8_t output[TEST_DH_MOD_LEN];
 	struct rte_crypto_asym_xform xform = *xfrm;
 	uint8_t peer[] = "01234567890123456789012345678901234567890123456789";
@@ -1074,12 +1074,12 @@ test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
 	asym_op->dh.shared_secret.data = output;
 	asym_op->dh.shared_secret.length = sizeof(output);
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
-	if (sess == NULL) {
+	ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
 				"line %u FAILED: %s", __LINE__,
 				"Session creation failed");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto error_exit;
 	}
 
@@ -1130,7 +1130,7 @@ test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
 	struct rte_crypto_asym_op *asym_op = NULL;
 	struct rte_crypto_op *op = NULL, *result_op = NULL;
 	void *sess = NULL;
-	int status = TEST_SUCCESS;
+	int ret, status = TEST_SUCCESS;
 	uint8_t output[TEST_DH_MOD_LEN];
 	struct rte_crypto_asym_xform xform = *xfrm;
 
@@ -1152,12 +1152,12 @@ test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
 	asym_op->dh.priv_key.data = output;
 	asym_op->dh.priv_key.length = sizeof(output);
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
-	if (sess == NULL) {
+	ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
 				"line %u FAILED: %s", __LINE__,
 				"Session creation failed");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto error_exit;
 	}
 
@@ -1211,7 +1211,7 @@ test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
 	struct rte_crypto_asym_op *asym_op = NULL;
 	struct rte_crypto_op *op = NULL, *result_op = NULL;
 	void *sess = NULL;
-	int status = TEST_SUCCESS;
+	int ret, status = TEST_SUCCESS;
 	uint8_t output[TEST_DH_MOD_LEN];
 	struct rte_crypto_asym_xform xform = *xfrm;
 
@@ -1241,12 +1241,12 @@ test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
 					0);
 	asym_op->dh.priv_key = dh_test_params.priv_key;
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
-	if (sess == NULL) {
+	ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
 				"line %u FAILED: %s", __LINE__,
 				"Session creation failed");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto error_exit;
 	}
 
@@ -1300,7 +1300,7 @@ test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
 	struct rte_crypto_asym_op *asym_op = NULL;
 	struct rte_crypto_op *op = NULL, *result_op = NULL;
 	void *sess = NULL;
-	int status = TEST_SUCCESS;
+	int ret, status = TEST_SUCCESS;
 	uint8_t out_pub_key[TEST_DH_MOD_LEN];
 	uint8_t out_prv_key[TEST_DH_MOD_LEN];
 	struct rte_crypto_asym_xform pub_key_xform;
@@ -1330,12 +1330,12 @@ test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
 	asym_op->dh.priv_key.data = out_prv_key;
 	asym_op->dh.priv_key.length = sizeof(out_prv_key);
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
-	if (sess == NULL) {
+	ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
 				"line %u FAILED: %s", __LINE__,
 				"Session creation failed");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto error_exit;
 	}
 
@@ -1419,12 +1419,12 @@ test_mod_inv(void)
 				return TEST_SKIPPED;
 		}
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &modinv_xform, sess_mpool);
-	if (!sess) {
+	ret = rte_cryptodev_asym_session_create(dev_id, &modinv_xform, sess_mpool, &sess);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1, "line %u "
 				"FAILED: %s", __LINE__,
 				"Session creation failed");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto error_exit;
 	}
 
@@ -1543,13 +1543,13 @@ test_mod_exp(void)
 		goto error_exit;
 	}
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &modex_xform, sess_mpool);
-	if (!sess) {
+	ret = rte_cryptodev_asym_session_create(dev_id, &modex_xform, sess_mpool, &sess);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
 				 "line %u "
 				"FAILED: %s", __LINE__,
 				"Session creation failed");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto error_exit;
 	}
 
@@ -1653,13 +1653,14 @@ test_dsa_sign(void)
 	uint8_t r[TEST_DH_MOD_LEN];
 	uint8_t s[TEST_DH_MOD_LEN];
 	uint8_t dgst[] = "35d81554afaad2cf18f3a1770d5fedc4ea5be344";
+	int ret;
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &dsa_xform, sess_mpool);
-	if (sess == NULL) {
+	ret = rte_cryptodev_asym_session_create(dev_id, &dsa_xform, sess_mpool, &sess);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
 				 "line %u FAILED: %s", __LINE__,
 				"Session creation failed");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto error_exit;
 	}
 	/* set up crypto op data structure */
@@ -1788,7 +1789,7 @@ test_ecdsa_sign_verify(enum curve curve_id)
 	struct rte_crypto_asym_op *asym_op;
 	struct rte_cryptodev_info dev_info;
 	struct rte_crypto_op *op = NULL;
-	int status = TEST_SUCCESS, ret;
+	int ret, status = TEST_SUCCESS;
 
 	switch (curve_id) {
 	case SECP192R1:
@@ -1833,12 +1834,12 @@ test_ecdsa_sign_verify(enum curve curve_id)
 	xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDSA;
 	xform.ec.curve_id = input_params.curve;
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
-	if (sess == NULL) {
+	ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
 				"line %u FAILED: %s", __LINE__,
 				"Session creation failed\n");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto exit;
 	}
 
@@ -1990,7 +1991,7 @@ test_ecpm(enum curve curve_id)
 	struct rte_crypto_asym_op *asym_op;
 	struct rte_cryptodev_info dev_info;
 	struct rte_crypto_op *op = NULL;
-	int status = TEST_SUCCESS, ret;
+	int ret, status = TEST_SUCCESS;
 
 	switch (curve_id) {
 	case SECP192R1:
@@ -2035,12 +2036,12 @@ test_ecpm(enum curve curve_id)
 	xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECPM;
 	xform.ec.curve_id = input_params.curve;
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
-	if (sess == NULL) {
+	ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
 				"line %u FAILED: %s", __LINE__,
 				"Session creation failed\n");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto exit;
 	}
 
diff --git a/doc/guides/rel_notes/release_22_03.rst b/doc/guides/rel_notes/release_22_03.rst
index a930cbbad6..640691c3ef 100644
--- a/doc/guides/rel_notes/release_22_03.rst
+++ b/doc/guides/rel_notes/release_22_03.rst
@@ -123,7 +123,8 @@ API Changes
   The session structure was moved to ``cryptodev_pmd.h``,
   hiding it from applications.
   The API ``rte_cryptodev_asym_session_init`` was removed as the initialization
-  is now moved to ``rte_cryptodev_asym_session_create``.
+  is now moved to ``rte_cryptodev_asym_session_create``, which was updated to
+  return an integer value to indicate initialisation errors.
 
 
 ABI Changes
diff --git a/lib/cryptodev/rte_cryptodev.c b/lib/cryptodev/rte_cryptodev.c
index 91d48d5886..727d271fb9 100644
--- a/lib/cryptodev/rte_cryptodev.c
+++ b/lib/cryptodev/rte_cryptodev.c
@@ -1912,9 +1912,10 @@ rte_cryptodev_sym_session_create(struct rte_mempool *mp)
 	return sess;
 }
 
-void *
+int
 rte_cryptodev_asym_session_create(uint8_t dev_id,
-		struct rte_crypto_asym_xform *xforms, struct rte_mempool *mp)
+		struct rte_crypto_asym_xform *xforms, struct rte_mempool *mp,
+		void **session)
 {
 	struct rte_cryptodev_asym_session *sess;
 	uint32_t session_priv_data_sz;
@@ -1926,17 +1927,17 @@ rte_cryptodev_asym_session_create(uint8_t dev_id,
 
 	if (!rte_cryptodev_is_valid_dev(dev_id)) {
 		CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
-		return NULL;
+		return -EINVAL;
 	}
 
 	dev = rte_cryptodev_pmd_get_dev(dev_id);
 
 	if (dev == NULL)
-		return NULL;
+		return -EINVAL;
 
 	if (!mp) {
 		CDEV_LOG_ERR("invalid mempool\n");
-		return NULL;
+		return -EINVAL;
 	}
 
 	session_priv_data_sz = rte_cryptodev_asym_get_private_session_size(
@@ -1946,22 +1947,23 @@ rte_cryptodev_asym_session_create(uint8_t dev_id,
 	if (pool_priv->max_priv_session_sz < session_priv_data_sz) {
 		CDEV_LOG_DEBUG(
 			"The private session data size used when creating the mempool is smaller than this device's private session data.");
-		return NULL;
+		return -EINVAL;
 	}
 
 	/* Verify if provided mempool can hold elements big enough. */
 	if (mp->elt_size < session_header_size + session_priv_data_sz) {
 		CDEV_LOG_ERR(
 			"mempool elements too small to hold session objects");
-		return NULL;
+		return -EINVAL;
 	}
 
 	/* Allocate a session structure from the session pool */
-	if (rte_mempool_get(mp, (void **)&sess)) {
+	if (rte_mempool_get(mp, session)) {
 		CDEV_LOG_ERR("couldn't get object from session mempool");
-		return NULL;
+		return -ENOMEM;
 	}
 
+	sess = *session;
 	sess->driver_id = dev->driver_id;
 	sess->user_data_sz = pool_priv->user_data_sz;
 	sess->max_priv_data_sz = pool_priv->max_priv_session_sz;
@@ -1969,7 +1971,7 @@ rte_cryptodev_asym_session_create(uint8_t dev_id,
 	/* Clear device session pointer.*/
 	memset(sess->sess_private_data, 0, session_priv_data_sz + sess->user_data_sz);
 
-	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->asym_session_configure, NULL);
+	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->asym_session_configure, -ENOTSUP);
 
 	if (sess->sess_private_data[0] == 0) {
 		ret = dev->dev_ops->asym_session_configure(dev, xforms, sess);
@@ -1977,12 +1979,12 @@ rte_cryptodev_asym_session_create(uint8_t dev_id,
 			CDEV_LOG_ERR(
 				"dev_id %d failed to configure session details",
 				dev_id);
-			return NULL;
+			return ret;
 		}
 	}
 
-	rte_cryptodev_trace_asym_session_create(dev_id, xforms, mp);
-	return sess;
+	rte_cryptodev_trace_asym_session_create(dev_id, xforms, mp, sess);
+	return 0;
 }
 
 int
diff --git a/lib/cryptodev/rte_cryptodev.h b/lib/cryptodev/rte_cryptodev.h
index 1d7bd07680..19e2e70287 100644
--- a/lib/cryptodev/rte_cryptodev.h
+++ b/lib/cryptodev/rte_cryptodev.h
@@ -996,14 +996,19 @@ rte_cryptodev_sym_session_create(struct rte_mempool *mempool);
  *                   processed with this session
  * @param   mp       mempool to allocate asymmetric session
  *                   objects from
+ * @param   session  void ** for session to be used
+ *
  * @return
- *  - On success return pointer to asym-session
- *  - On failure returns NULL
+ *  - 0 on success.
+ *  - -EINVAL on invalid arguments.
+ *  - -ENOMEM on memory error for session allocation.
+ *  - -ENOTSUP if device doesn't support session configuration.
  */
 __rte_experimental
-void *
+int
 rte_cryptodev_asym_session_create(uint8_t dev_id,
-		struct rte_crypto_asym_xform *xforms, struct rte_mempool *mp);
+		struct rte_crypto_asym_xform *xforms, struct rte_mempool *mp,
+		void **session);
 
 /**
  * Frees symmetric crypto session header, after checking that all
diff --git a/lib/cryptodev/rte_cryptodev_trace.h b/lib/cryptodev/rte_cryptodev_trace.h
index 005a4fe38b..a3f6048e7d 100644
--- a/lib/cryptodev/rte_cryptodev_trace.h
+++ b/lib/cryptodev/rte_cryptodev_trace.h
@@ -96,10 +96,12 @@ RTE_TRACE_POINT(
 
 RTE_TRACE_POINT(
 	rte_cryptodev_trace_asym_session_create,
-	RTE_TRACE_POINT_ARGS(uint8_t dev_id, void *xforms, void *mempool),
+	RTE_TRACE_POINT_ARGS(uint8_t dev_id, void *xforms, void *mempool,
+			void *sess),
 	rte_trace_point_emit_u8(dev_id);
 	rte_trace_point_emit_ptr(xforms);
 	rte_trace_point_emit_ptr(mempool);
+	rte_trace_point_emit_ptr(sess);
 )
 
 RTE_TRACE_POINT(
-- 
2.25.1


^ permalink raw reply	[flat|nested] 31+ messages in thread

* RE: [PATCH v6 1/5] doc: replace asym crypto code with literal includes
  2022-02-10 15:54   ` [PATCH v6 1/5] doc: replace asym crypto code with literal includes Ciara Power
@ 2022-02-10 16:36     ` Zhang, Roy Fan
  0 siblings, 0 replies; 31+ messages in thread
From: Zhang, Roy Fan @ 2022-02-10 16:36 UTC (permalink / raw)
  To: Power, Ciara, dev; +Cc: gakhil, anoobj, mdr, Doherty, Declan

> -----Original Message-----
> From: Power, Ciara <ciara.power@intel.com>
> Sent: Thursday, February 10, 2022 3:54 PM
> To: dev@dpdk.org
> Cc: Zhang, Roy Fan <roy.fan.zhang@intel.com>; gakhil@marvell.com;
> anoobj@marvell.com; mdr@ashroe.eu; Power, Ciara
> <ciara.power@intel.com>; Doherty, Declan <declan.doherty@intel.com>
> Subject: [PATCH v6 1/5] doc: replace asym crypto code with literal includes
> 
> The programmer's guide for cryptodev included sample code for using
> Asymmetric crypto. This is now replaced with direct code from the test
> application, using literal includes. It is broken into snippets as the
> test application didn't have all of the required code in one function.
> 
> Signed-off-by: Ciara Power <ciara.power@intel.com>
> Acked-by: Anoob Joseph <anoobj@marvell.com>
> ---
Acked-by: Fan Zhang <roy.fan.zhang@intel.com>

^ permalink raw reply	[flat|nested] 31+ messages in thread

* RE: [EXT] [PATCH v6 0/5] crypto: improve asym session usage
  2022-02-10 15:53 ` [PATCH v6 0/5] crypto: improve asym session usage Ciara Power
                     ` (4 preceding siblings ...)
  2022-02-10 15:54   ` [PATCH v6 5/5] crypto: modify return value for asym session create Ciara Power
@ 2022-02-10 22:37   ` Akhil Goyal
  5 siblings, 0 replies; 31+ messages in thread
From: Akhil Goyal @ 2022-02-10 22:37 UTC (permalink / raw)
  To: Ciara Power, dev; +Cc: roy.fan.zhang, Anoob Joseph, mdr


> This patchset includes improvements for the asymmetric session.
> The main change is to the session structure, which is now a single
> mempool object, rather than having pointers to private data elsewhere.
> This session structure is now hidden in an internal header,
> so the app will never use it directly.
> 
> Some other changes include adding a user data API, and modifying
> the return value for the create session function.
> This create session function now also initialises the session,
> and subsequently the clear/free functions have been merged into one.
> 
> Sample code in the programmer's guide that showed basic steps for
> using Asymmetric crypto in DPDK has been replaced with literal includes
> in the first patch of this patchset. This ensures all subsequent code
> changes in the patchset are automatically reflected in the documentation.
> 
> v6:
>   - Reordered variable declarations to follow cnxk file format.
>   - Added fix for crypto perf app asymmetric modex operation, there
>     is no longer a need for private mempool, and the
>     rte_cryptodev_asym_session_pool_create API should be used.
> 
> v5:
>   - Modified which patch the sess parameter is passed to session create
>     trace function.
>   - Reworded create session function description.
>   - Removed get API for session private data, can be accessed directly.
>   - Modified test application to create a session mempool for
>     TEST_NUM_SESSIONS rather than TEST_NUM_SESSIONS * 2.
> 
> v4:
>   - Added new patch to add literal includes usage in programmer's guide.
>   - Merged asym crypto session clear and free functions.
>   - Reordered some function parameters.
>   - Updated trace function for asym crypto session create.
>   - Fixed cnxk clear, the PMD no longer needs to put private data
>     back into a mempool.
>   - Renamed struct field for max private session size.
>   - Replaced __extension__ with RTE_STD_C11.
>   - Moved some parameter validity checks to before functional code.
>   - Reworded release note.
>   - Removed mempool parameter from session configure function.
>   - Removed docs code additions, these are included due to patch 1
>     changing sample doc to use literal includes.
>   - Initialised session variables as NULL.
>   - Added possible error return values in user data API comment.
> 
> v3:
>   - Added documentation in relevant patches.
>   - Fixed setting user data size.
>   - Fixed hiding structure, it should not be hidden from PMDs.
>   - Fixed some other small formatting issues.
>   - Increased size of max_priv_session_sz to uint16_t.
>   - Removed trace for asym session init function that was
>     previously removed.
> 
> Ciara Power (5):
>   doc: replace asym crypto code with literal includes
>   crypto: use single buffer for asymmetric session
>   crypto: hide asym session structure
>   crypto: add asym session user data API
>   crypto: modify return value for asym session create
> 
>  app/test-crypto-perf/cperf_ops.c             |  22 +-
>  app/test-crypto-perf/cperf_test_throughput.c |   8 +-
>  app/test-crypto-perf/main.c                  |  26 +-
>  app/test/test_cryptodev_asym.c               | 380 ++++++-------------
>  app/test/test_cryptodev_mod_test_vectors.h   |   4 +
>  doc/guides/prog_guide/cryptodev_lib.rst      | 212 +++--------
>  doc/guides/rel_notes/release_22_03.rst       |  14 +
>  drivers/crypto/cnxk/cn10k_cryptodev_ops.c    |   8 +-
>  drivers/crypto/cnxk/cn9k_cryptodev_ops.c     |   8 +-
>  drivers/crypto/cnxk/cnxk_cryptodev_ops.c     |  22 +-
>  drivers/crypto/cnxk/cnxk_cryptodev_ops.h     |   3 +-
>  drivers/crypto/octeontx/otx_cryptodev_ops.c  |  32 +-
>  drivers/crypto/openssl/rte_openssl_pmd.c     |   4 +-
>  drivers/crypto/openssl/rte_openssl_pmd_ops.c |  24 +-
>  drivers/crypto/qat/qat_asym.c                |  54 +--
>  drivers/crypto/qat/qat_asym.h                |   5 +-
>  lib/cryptodev/cryptodev_pmd.h                |  36 +-
>  lib/cryptodev/cryptodev_trace_points.c       |   9 +-
>  lib/cryptodev/rte_cryptodev.c                | 258 ++++++++-----
>  lib/cryptodev/rte_cryptodev.h                | 136 ++++---
>  lib/cryptodev/rte_cryptodev_trace.h          |  38 +-
>  lib/cryptodev/version.map                    |   9 +-
>  22 files changed, 526 insertions(+), 786 deletions(-)
> 
I see following warning in compilation
../app/test-crypto-perf/main.c: In function 'create_asym_op_pool_socket':
../app/test-crypto-perf/main.c:72:36: warning: unused parameter 'dev_id' [-Wunused-parameter]
   72 | create_asym_op_pool_socket(uint8_t dev_id, int32_t socket_id,
      |                            ~~~~~~~~^~~~~~

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [PATCH v7 0/5] crypto: improve asym session usage
  2022-02-09 15:38 [PATCH v4 0/5] crypto: improve asym session usage Ciara Power
                   ` (6 preceding siblings ...)
  2022-02-10 15:53 ` [PATCH v6 0/5] crypto: improve asym session usage Ciara Power
@ 2022-02-11  9:29 ` Ciara Power
  2022-02-11  9:29   ` [PATCH v7 1/5] doc: replace asym crypto code with literal includes Ciara Power
                     ` (5 more replies)
  7 siblings, 6 replies; 31+ messages in thread
From: Ciara Power @ 2022-02-11  9:29 UTC (permalink / raw)
  To: dev; +Cc: roy.fan.zhang, gakhil, anoobj, mdr, Ciara Power

This patchset includes improvements for the asymmetric session.
The main change is to the session structure, which is now a single
mempool object, rather than having pointers to private data elsewhere.
This session structure is now hidden in an internal header,
so the app will never use it directly.

Some other changes include adding a user data API, and modifying
the return value for the create session function.
This create session function now also initialises the session,
and subsequently the clear/free functions have been merged into one.

Sample code in the programmer's guide that showed basic steps for
using Asymmetric crypto in DPDK has been replaced with literal includes
in the first patch of this patchset. This ensures all subsequent code
changes in the patchset are automatically reflected in the documentation.

v7: Removed unused parameter to avoid compilation warning.

v6:
  - Reordered variable declarations to follow cnxk file format.
  - Added fix for crypto perf app asymmetric modex operation, there
    is no longer a need for private mempool, and the
    rte_cryptodev_asym_session_pool_create API should be used.

v5:
  - Modified which patch the sess parameter is passed to session create
    trace function.
  - Reworded create session function description.
  - Removed get API for session private data, can be accessed directly.
  - Modified test application to create a session mempool for
    TEST_NUM_SESSIONS rather than TEST_NUM_SESSIONS * 2.

v4:
  - Added new patch to add literal includes usage in programmer's guide.
  - Merged asym crypto session clear and free functions.
  - Reordered some function parameters.
  - Updated trace function for asym crypto session create.
  - Fixed cnxk clear, the PMD no longer needs to put private data
    back into a mempool.
  - Renamed struct field for max private session size.
  - Replaced __extension__ with RTE_STD_C11.
  - Moved some parameter validity checks to before functional code.
  - Reworded release note.
  - Removed mempool parameter from session configure function.
  - Removed docs code additions, these are included due to patch 1
    changing sample doc to use literal includes.
  - Initialised session variables as NULL.
  - Added possible error return values in user data API comment.

v3:
  - Added documentation in relevant patches.
  - Fixed setting user data size.
  - Fixed hiding structure, it should not be hidden from PMDs.
  - Fixed some other small formatting issues.
  - Increased size of max_priv_session_sz to uint16_t.
  - Removed trace for asym session init function that was
    previously removed.

Ciara Power (5):
  doc: replace asym crypto code with literal includes
  crypto: use single buffer for asymmetric session
  crypto: hide asym session structure
  crypto: add asym session user data API
  crypto: modify return value for asym session create

 app/test-crypto-perf/cperf_ops.c             |  22 +-
 app/test-crypto-perf/cperf_test_throughput.c |   8 +-
 app/test-crypto-perf/main.c                  |  31 +-
 app/test/test_cryptodev_asym.c               | 380 ++++++-------------
 app/test/test_cryptodev_mod_test_vectors.h   |   4 +
 doc/guides/prog_guide/cryptodev_lib.rst      | 212 +++--------
 doc/guides/rel_notes/release_22_03.rst       |  14 +
 drivers/crypto/cnxk/cn10k_cryptodev_ops.c    |   8 +-
 drivers/crypto/cnxk/cn9k_cryptodev_ops.c     |   8 +-
 drivers/crypto/cnxk/cnxk_cryptodev_ops.c     |  22 +-
 drivers/crypto/cnxk/cnxk_cryptodev_ops.h     |   3 +-
 drivers/crypto/octeontx/otx_cryptodev_ops.c  |  32 +-
 drivers/crypto/openssl/rte_openssl_pmd.c     |   4 +-
 drivers/crypto/openssl/rte_openssl_pmd_ops.c |  24 +-
 drivers/crypto/qat/qat_asym.c                |  54 +--
 drivers/crypto/qat/qat_asym.h                |   5 +-
 lib/cryptodev/cryptodev_pmd.h                |  36 +-
 lib/cryptodev/cryptodev_trace_points.c       |   9 +-
 lib/cryptodev/rte_cryptodev.c                | 258 ++++++++-----
 lib/cryptodev/rte_cryptodev.h                | 136 ++++---
 lib/cryptodev/rte_cryptodev_trace.h          |  38 +-
 lib/cryptodev/version.map                    |   9 +-
 22 files changed, 528 insertions(+), 789 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 31+ messages in thread

* [PATCH v7 1/5] doc: replace asym crypto code with literal includes
  2022-02-11  9:29 ` [PATCH v7 " Ciara Power
@ 2022-02-11  9:29   ` Ciara Power
  2022-02-11  9:29   ` [PATCH v7 2/5] crypto: use single buffer for asymmetric session Ciara Power
                     ` (4 subsequent siblings)
  5 siblings, 0 replies; 31+ messages in thread
From: Ciara Power @ 2022-02-11  9:29 UTC (permalink / raw)
  To: dev; +Cc: roy.fan.zhang, gakhil, anoobj, mdr, Ciara Power, Declan Doherty

The programmer's guide for cryptodev included sample code for using
Asymmetric crypto. This is now replaced with direct code from the test
application, using literal includes. It is broken into snippets as the
test application didn't have all of the required code in one function.

Signed-off-by: Ciara Power <ciara.power@intel.com>
Acked-by: Anoob Joseph <anoobj@marvell.com>
Acked-by: Fan Zhang <roy.fan.zhang@intel.com>
---
 app/test/test_cryptodev_asym.c             |   7 +-
 app/test/test_cryptodev_mod_test_vectors.h |   4 +
 doc/guides/prog_guide/cryptodev_lib.rst    | 176 ++++-----------------
 3 files changed, 37 insertions(+), 150 deletions(-)

diff --git a/app/test/test_cryptodev_asym.c b/app/test/test_cryptodev_asym.c
index 9d3a5589bb..8d7290f9ed 100644
--- a/app/test/test_cryptodev_asym.c
+++ b/app/test/test_cryptodev_asym.c
@@ -855,6 +855,7 @@ testsuite_setup(void)
 	test_vector.size = 0;
 	load_test_vectors();
 
+	/* Device, op pool and session configuration for asymmetric crypto. 8< */
 	ts_params->op_mpool = rte_crypto_op_pool_create(
 			"CRYPTO_ASYM_OP_POOL",
 			RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
@@ -953,7 +954,7 @@ testsuite_setup(void)
 
 	TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
 			"session mempool allocation failed");
-
+	/* >8 End of device, op pool and session configuration for asymmetric crypto section. */
 	return TEST_SUCCESS;
 }
 
@@ -1637,7 +1638,7 @@ test_mod_exp(void)
 				return TEST_SKIPPED;
 		}
 
-	/* generate crypto op data structure */
+	/* Create op, create session, and process packets. 8< */
 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
 	if (!op) {
 		RTE_LOG(ERR, USER1,
@@ -1696,7 +1697,7 @@ test_mod_exp(void)
 		status = TEST_FAILED;
 		goto error_exit;
 	}
-
+	/* >8 End of create op, create session, and process packets section. */
 	ret = verify_modexp(mod_exp, result_op);
 	if (ret) {
 		RTE_LOG(ERR, USER1,
diff --git a/app/test/test_cryptodev_mod_test_vectors.h b/app/test/test_cryptodev_mod_test_vectors.h
index c66f4b18bc..807ca7a47e 100644
--- a/app/test/test_cryptodev_mod_test_vectors.h
+++ b/app/test/test_cryptodev_mod_test_vectors.h
@@ -979,6 +979,7 @@ uint8_t base[] = {
 	0xA8, 0xEB, 0x7E, 0x78, 0xA0, 0x50
 };
 
+/* MODEX data. 8< */
 uint8_t mod_p[] = {
 	0x00, 0xb3, 0xa1, 0xaf, 0xb7, 0x13, 0x08, 0x00,
 	0x0a, 0x35, 0xdc, 0x2b, 0x20, 0x8d, 0xa1, 0xb5,
@@ -1000,6 +1001,7 @@ uint8_t mod_p[] = {
 };
 
 uint8_t mod_e[] = {0x01, 0x00, 0x01};
+/* >8 End of MODEX data. */
 
 /* Precomputed modular exponentiation for verification */
 uint8_t mod_exp[] = {
@@ -1041,6 +1043,7 @@ uint8_t mod_inv[] = {
 	0x9a, 0x66, 0x9a, 0x3a, 0xc1, 0xb8, 0x4b, 0xc3
 };
 
+/* MODEX vector. 8< */
 struct rte_crypto_asym_xform modex_xform = {
 	.next = NULL,
 	.xform_type = RTE_CRYPTO_ASYM_XFORM_MODEX,
@@ -1055,6 +1058,7 @@ struct rte_crypto_asym_xform modex_xform = {
 		}
 	}
 };
+/* >8 End of MODEX vector. */
 
 struct rte_crypto_asym_xform modinv_xform = {
 	.next = NULL,
diff --git a/doc/guides/prog_guide/cryptodev_lib.rst b/doc/guides/prog_guide/cryptodev_lib.rst
index 8766bc34a9..9f33f7a177 100644
--- a/doc/guides/prog_guide/cryptodev_lib.rst
+++ b/doc/guides/prog_guide/cryptodev_lib.rst
@@ -1119,162 +1119,44 @@ Asymmetric crypto Sample code
 There's a unit test application test_cryptodev_asym.c inside unit test framework that
 show how to setup and process asymmetric operations using cryptodev library.
 
-The following sample code shows the basic steps to compute modular exponentiation
-using 1024-bit modulus length using openssl PMD available in DPDK (performing other
-crypto operations is similar except change to respective op and xform setup).
+The following code samples are taken from the test application mentioned above,
+and show basic steps to compute modular exponentiation using an openssl PMD
+available in DPDK (performing other crypto operations is similar except change
+to respective op and xform setup).
 
-.. code-block:: c
+.. note::
+   The following code snippets are taken from multiple functions, so variable
+   names may differ slightly between sections.
 
-    /*
-     * Simple example to compute modular exponentiation with 1024-bit key
-     *
-     */
-    #define MAX_ASYM_SESSIONS	10
-    #define NUM_ASYM_BUFS	10
-
-    struct rte_mempool *crypto_op_pool, *asym_session_pool;
-    unsigned int asym_session_size;
-    int ret;
+Configure the virtual device, queue pairs, crypto op pool and session mempool.
 
-    /* Initialize EAL. */
-    ret = rte_eal_init(argc, argv);
-    if (ret < 0)
-        rte_exit(EXIT_FAILURE, "Invalid EAL arguments\n");
+.. literalinclude:: ../../../app/test/test_cryptodev_asym.c
+   :language: c
+   :start-after: Device, op pool and session configuration for asymmetric crypto. 8<
+   :end-before: >8 End of device, op pool and session configuration for asymmetric crypto section.
+   :dedent: 1
 
-    uint8_t socket_id = rte_socket_id();
-
-    /* Create crypto operation pool. */
-    crypto_op_pool = rte_crypto_op_pool_create(
-                                    "crypto_op_pool",
-                                    RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
-                                    NUM_ASYM_BUFS, 0, 0,
-                                    socket_id);
-    if (crypto_op_pool == NULL)
-        rte_exit(EXIT_FAILURE, "Cannot create crypto op pool\n");
-
-    /* Create the virtual crypto device. */
-    char args[128];
-    const char *crypto_name = "crypto_openssl";
-    snprintf(args, sizeof(args), "socket_id=%d", socket_id);
-    ret = rte_vdev_init(crypto_name, args);
-    if (ret != 0)
-        rte_exit(EXIT_FAILURE, "Cannot create virtual device");
+Create MODEX data vectors.
 
-    uint8_t cdev_id = rte_cryptodev_get_dev_id(crypto_name);
+.. literalinclude:: ../../../app/test/test_cryptodev_mod_test_vectors.h
+   :language: c
+   :start-after: MODEX data. 8<
+   :end-before: >8 End of MODEX data.
 
-    /* Get private asym session data size. */
-    asym_session_size = rte_cryptodev_get_asym_private_session_size(cdev_id);
+Setup crypto xform to do modular exponentiation using data vectors.
 
-    /*
-     * Create session mempool, with two objects per session,
-     * one for the session header and another one for the
-     * private asym session data for the crypto device.
-     */
-    asym_session_pool = rte_mempool_create("asym_session_pool",
-                                    MAX_ASYM_SESSIONS * 2,
-                                    asym_session_size,
-                                    0,
-                                    0, NULL, NULL, NULL,
-                                    NULL, socket_id,
-                                    0);
+.. literalinclude:: ../../../app/test/test_cryptodev_mod_test_vectors.h
+   :language: c
+   :start-after: MODEX vector. 8<
+   :end-before: >8 End of MODEX vector.
 
-    /* Configure the crypto device. */
-    struct rte_cryptodev_config conf = {
-        .nb_queue_pairs = 1,
-        .socket_id = socket_id
-    };
-    struct rte_cryptodev_qp_conf qp_conf = {
-        .nb_descriptors = 2048
-    };
+Generate crypto op, create and attach a session, then process packets.
 
-    if (rte_cryptodev_configure(cdev_id, &conf) < 0)
-        rte_exit(EXIT_FAILURE, "Failed to configure cryptodev %u", cdev_id);
-
-    if (rte_cryptodev_queue_pair_setup(cdev_id, 0, &qp_conf,
-                            socket_id, asym_session_pool) < 0)
-        rte_exit(EXIT_FAILURE, "Failed to setup queue pair\n");
-
-    if (rte_cryptodev_start(cdev_id) < 0)
-        rte_exit(EXIT_FAILURE, "Failed to start device\n");
-
-    /* Setup crypto xform to do modular exponentiation with 1024 bit
-	 * length modulus
-	 */
-    struct rte_crypto_asym_xform modex_xform = {
-		.next = NULL,
-		.xform_type = RTE_CRYPTO_ASYM_XFORM_MODEX,
-		.modex = {
-			.modulus = {
-				.data =
-				(uint8_t *)
-				("\xb3\xa1\xaf\xb7\x13\x08\x00\x0a\x35\xdc\x2b\x20\x8d"
-				"\xa1\xb5\xce\x47\x8a\xc3\x80\xf4\x7d\x4a\xa2\x62\xfd\x61\x7f"
-				"\xb5\xa8\xde\x0a\x17\x97\xa0\xbf\xdf\x56\x5a\x3d\x51\x56\x4f"
-				"\x70\x70\x3f\x63\x6a\x44\x5b\xad\x84\x0d\x3f\x27\x6e\x3b\x34"
-				"\x91\x60\x14\xb9\xaa\x72\xfd\xa3\x64\xd2\x03\xa7\x53\x87\x9e"
-				"\x88\x0b\xc1\x14\x93\x1a\x62\xff\xb1\x5d\x74\xcd\x59\x63\x18"
-				"\x11\x3d\x4f\xba\x75\xd4\x33\x4e\x23\x6b\x7b\x57\x44\xe1\xd3"
-				"\x03\x13\xa6\xf0\x8b\x60\xb0\x9e\xee\x75\x08\x9d\x71\x63\x13"
-				"\xcb\xa6\x81\x92\x14\x03\x22\x2d\xde\x55"),
-				.length = 128
-			},
-			.exponent = {
-				.data = (uint8_t *)("\x01\x00\x01"),
-				.length = 3
-			}
-		}
-    };
-    /* Create asym crypto session and initialize it for the crypto device. */
-    struct rte_cryptodev_asym_session *asym_session;
-    asym_session = rte_cryptodev_asym_session_create(asym_session_pool);
-    if (asym_session == NULL)
-        rte_exit(EXIT_FAILURE, "Session could not be created\n");
-
-    if (rte_cryptodev_asym_session_init(cdev_id, asym_session,
-                    &modex_xform, asym_session_pool) < 0)
-        rte_exit(EXIT_FAILURE, "Session could not be initialized "
-                    "for the crypto device\n");
-
-    /* Get a burst of crypto operations. */
-    struct rte_crypto_op *crypto_ops[1];
-    if (rte_crypto_op_bulk_alloc(crypto_op_pool,
-                            RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
-                            crypto_ops, 1) == 0)
-        rte_exit(EXIT_FAILURE, "Not enough crypto operations available\n");
-
-    /* Set up the crypto operations. */
-    struct rte_crypto_asym_op *asym_op = crypto_ops[0]->asym;
-
-	/* calculate mod exp of value 0xf8 */
-    static unsigned char base[] = {0xF8};
-    asym_op->modex.base.data = base;
-    asym_op->modex.base.length = sizeof(base);
-	asym_op->modex.base.iova = base;
-
-    /* Attach the asym crypto session to the operation */
-    rte_crypto_op_attach_asym_session(op, asym_session);
-
-    /* Enqueue the crypto operations in the crypto device. */
-    uint16_t num_enqueued_ops = rte_cryptodev_enqueue_burst(cdev_id, 0,
-                                            crypto_ops, 1);
-
-    /*
-     * Dequeue the crypto operations until all the operations
-     * are processed in the crypto device.
-     */
-    uint16_t num_dequeued_ops, total_num_dequeued_ops = 0;
-    do {
-        struct rte_crypto_op *dequeued_ops[1];
-        num_dequeued_ops = rte_cryptodev_dequeue_burst(cdev_id, 0,
-                                        dequeued_ops, 1);
-        total_num_dequeued_ops += num_dequeued_ops;
-
-        /* Check if operation was processed successfully */
-        if (dequeued_ops[0]->status != RTE_CRYPTO_OP_STATUS_SUCCESS)
-                rte_exit(EXIT_FAILURE,
-                        "Some operations were not processed correctly");
-
-    } while (total_num_dequeued_ops < num_enqueued_ops);
+.. literalinclude:: ../../../app/test/test_cryptodev_asym.c
+   :language: c
+   :start-after: Create op, create session, and process packets. 8<
+   :end-before: >8 End of create op, create session, and process packets section.
+   :dedent: 1
 
 
 Asymmetric Crypto Device API
-- 
2.25.1


^ permalink raw reply	[flat|nested] 31+ messages in thread

* [PATCH v7 2/5] crypto: use single buffer for asymmetric session
  2022-02-11  9:29 ` [PATCH v7 " Ciara Power
  2022-02-11  9:29   ` [PATCH v7 1/5] doc: replace asym crypto code with literal includes Ciara Power
@ 2022-02-11  9:29   ` Ciara Power
  2022-02-11  9:29   ` [PATCH v7 3/5] crypto: hide asym session structure Ciara Power
                     ` (3 subsequent siblings)
  5 siblings, 0 replies; 31+ messages in thread
From: Ciara Power @ 2022-02-11  9:29 UTC (permalink / raw)
  To: dev
  Cc: roy.fan.zhang, gakhil, anoobj, mdr, Ciara Power, Declan Doherty,
	Ankur Dwivedi, Tejasree Kondoj, John Griffin, Fiona Trahe,
	Deepak Kumar Jain

Rather than using a session buffer that contains pointers to private
session data elsewhere, have a single session buffer.
This session is created for a driver ID, and the mempool element
contains space for the max session private data needed for any driver.

Signed-off-by: Ciara Power <ciara.power@intel.com>
Acked-by: Fan Zhang <roy.fan.zhang@intel.com>
Acked-by: Anoob Joseph <anoobj@marvell.com>

---
v7: Fixed compilation warning for unused parameter.
v6:
  - Reordered variable declarations to follow cnxk file format.
  - Added fix for crypto perf app asymmetric modex operation, there
    is no longer a need for private mempool, and the
    rte_cryptodev_asym_session_pool_create API should be used.
v5:
  - Removed get API for session private data, can be accessed directly.
  - Modified test application to create a session mempool for
    TEST_NUM_SESSIONS rather than TEST_NUM_SESSIONS * 2.
  - Reworded create session function description.
  - Removed sess parameter from create session trace,
    to be added in a later patch.
v4:
  - Merged asym crypto session clear and free functions.
  - Reordered some function parameters.
  - Updated trace function for asym crypto session create.
  - Fixed cnxk clear, the PMD no longer needs to put private data
    back into a mempool.
  - Renamed struct field for max private session size.
  - Replaced __extension__ with RTE_STD_C11.
  - Moved some parameter validity checks to before functional code.
  - Reworded release note.
  - Removed mempool parameter from session configure function.
  - Removed docs code additions, these are included due to patch 1
    changing sample doc to use literal includes.
v3:
  - Corrected formatting of struct comments.
  - Increased size of max_priv_session_sz to uint16_t.
  - Removed trace for asym session init function that was
    previously removed.
  - Added documentation.
v2:
  - Renamed function typedef from "free" to "clear" as session private
    data isn't being freed in that function.
  - Moved user data API to separate patch.
  - Minor fixes to comments, formatting, return values.
---
 app/test-crypto-perf/cperf_ops.c             |  14 +-
 app/test-crypto-perf/cperf_test_throughput.c |   8 +-
 app/test-crypto-perf/main.c                  |  31 +--
 app/test/test_cryptodev_asym.c               | 272 +++++--------------
 doc/guides/prog_guide/cryptodev_lib.rst      |  21 +-
 doc/guides/rel_notes/release_22_03.rst       |   7 +
 drivers/crypto/cnxk/cn10k_cryptodev_ops.c    |   8 +-
 drivers/crypto/cnxk/cn9k_cryptodev_ops.c     |   8 +-
 drivers/crypto/cnxk/cnxk_cryptodev_ops.c     |  22 +-
 drivers/crypto/cnxk/cnxk_cryptodev_ops.h     |   3 +-
 drivers/crypto/octeontx/otx_cryptodev_ops.c  |  32 +--
 drivers/crypto/openssl/rte_openssl_pmd.c     |   4 +-
 drivers/crypto/openssl/rte_openssl_pmd_ops.c |  24 +-
 drivers/crypto/qat/qat_asym.c                |  54 +---
 drivers/crypto/qat/qat_asym.h                |   5 +-
 lib/cryptodev/cryptodev_pmd.h                |  23 +-
 lib/cryptodev/cryptodev_trace_points.c       |   9 +-
 lib/cryptodev/rte_cryptodev.c                | 213 ++++++++-------
 lib/cryptodev/rte_cryptodev.h                |  97 ++++---
 lib/cryptodev/rte_cryptodev_trace.h          |  38 ++-
 lib/cryptodev/version.map                    |   7 +-
 21 files changed, 319 insertions(+), 581 deletions(-)

diff --git a/app/test-crypto-perf/cperf_ops.c b/app/test-crypto-perf/cperf_ops.c
index d975ae1ab8..b125c699de 100644
--- a/app/test-crypto-perf/cperf_ops.c
+++ b/app/test-crypto-perf/cperf_ops.c
@@ -735,7 +735,6 @@ cperf_create_session(struct rte_mempool *sess_mp,
 	struct rte_crypto_sym_xform aead_xform;
 	struct rte_cryptodev_sym_session *sess = NULL;
 	struct rte_crypto_asym_xform xform = {0};
-	int rc;
 
 	if (options->op_type == CPERF_ASYM_MODEX) {
 		xform.next = NULL;
@@ -745,19 +744,10 @@ cperf_create_session(struct rte_mempool *sess_mp,
 		xform.modex.exponent.data = perf_mod_e;
 		xform.modex.exponent.length = sizeof(perf_mod_e);
 
-		sess = (void *)rte_cryptodev_asym_session_create(sess_mp);
+		sess = (void *)rte_cryptodev_asym_session_create(dev_id, &xform, sess_mp);
 		if (sess == NULL)
 			return NULL;
-		rc = rte_cryptodev_asym_session_init(dev_id, (void *)sess,
-						     &xform, priv_mp);
-		if (rc < 0) {
-			if (sess != NULL) {
-				rte_cryptodev_asym_session_clear(dev_id,
-								 (void *)sess);
-				rte_cryptodev_asym_session_free((void *)sess);
-			}
-			return NULL;
-		}
+
 		return sess;
 	}
 #ifdef RTE_LIB_SECURITY
diff --git a/app/test-crypto-perf/cperf_test_throughput.c b/app/test-crypto-perf/cperf_test_throughput.c
index 51512af2ad..ee21ff27f7 100644
--- a/app/test-crypto-perf/cperf_test_throughput.c
+++ b/app/test-crypto-perf/cperf_test_throughput.c
@@ -35,11 +35,9 @@ cperf_throughput_test_free(struct cperf_throughput_ctx *ctx)
 	if (!ctx)
 		return;
 	if (ctx->sess) {
-		if (ctx->options->op_type == CPERF_ASYM_MODEX) {
-			rte_cryptodev_asym_session_clear(ctx->dev_id,
-							 (void *)ctx->sess);
-			rte_cryptodev_asym_session_free((void *)ctx->sess);
-		}
+		if (ctx->options->op_type == CPERF_ASYM_MODEX)
+			rte_cryptodev_asym_session_free(ctx->dev_id,
+					(void *)ctx->sess);
 #ifdef RTE_LIB_SECURITY
 		else if (ctx->options->op_type == CPERF_PDCP ||
 			 ctx->options->op_type == CPERF_DOCSIS ||
diff --git a/app/test-crypto-perf/main.c b/app/test-crypto-perf/main.c
index 6fdb92fb7c..2531de43a2 100644
--- a/app/test-crypto-perf/main.c
+++ b/app/test-crypto-perf/main.c
@@ -69,39 +69,16 @@ const struct cperf_test cperf_testmap[] = {
 };
 
 static int
-create_asym_op_pool_socket(uint8_t dev_id, int32_t socket_id,
-			   uint32_t nb_sessions)
+create_asym_op_pool_socket(int32_t socket_id, uint32_t nb_sessions)
 {
 	char mp_name[RTE_MEMPOOL_NAMESIZE];
 	struct rte_mempool *mpool = NULL;
-	unsigned int session_size =
-		RTE_MAX(rte_cryptodev_asym_get_private_session_size(dev_id),
-			rte_cryptodev_asym_get_header_session_size());
-
-	if (session_pool_socket[socket_id].priv_mp == NULL) {
-		snprintf(mp_name, RTE_MEMPOOL_NAMESIZE, "perf_asym_priv_pool%u",
-			 socket_id);
-
-		mpool = rte_mempool_create(mp_name, nb_sessions, session_size,
-					   0, 0, NULL, NULL, NULL, NULL,
-					   socket_id, 0);
-		if (mpool == NULL) {
-			printf("Cannot create pool \"%s\" on socket %d\n",
-			       mp_name, socket_id);
-			return -ENOMEM;
-		}
-		printf("Allocated pool \"%s\" on socket %d\n", mp_name,
-		       socket_id);
-		session_pool_socket[socket_id].priv_mp = mpool;
-	}
 
 	if (session_pool_socket[socket_id].sess_mp == NULL) {
-
 		snprintf(mp_name, RTE_MEMPOOL_NAMESIZE, "perf_asym_sess_pool%u",
 			 socket_id);
-		mpool = rte_mempool_create(mp_name, nb_sessions,
-					   session_size, 0, 0, NULL, NULL, NULL,
-					   NULL, socket_id, 0);
+		mpool = rte_cryptodev_asym_session_pool_create(mp_name,
+				nb_sessions, 0, socket_id);
 		if (mpool == NULL) {
 			printf("Cannot create pool \"%s\" on socket %d\n",
 			       mp_name, socket_id);
@@ -336,7 +313,7 @@ cperf_initialize_cryptodev(struct cperf_options *opts, uint8_t *enabled_cdevs)
 		}
 
 		if (opts->op_type == CPERF_ASYM_MODEX)
-			ret = create_asym_op_pool_socket(cdev_id, socket_id,
+			ret = create_asym_op_pool_socket(socket_id,
 							 sessions_needed);
 		else
 			ret = fill_session_pool_socket(socket_id, max_sess_size,
diff --git a/app/test/test_cryptodev_asym.c b/app/test/test_cryptodev_asym.c
index 8d7290f9ed..88433faf1c 100644
--- a/app/test/test_cryptodev_asym.c
+++ b/app/test/test_cryptodev_asym.c
@@ -452,7 +452,8 @@ test_cryptodev_asym_op(struct crypto_testsuite_params_asym *ts_params,
 	}
 
 	if (!sessionless) {
-		sess = rte_cryptodev_asym_session_create(ts_params->session_mpool);
+		sess = rte_cryptodev_asym_session_create(dev_id, &xform_tc,
+				ts_params->session_mpool);
 		if (!sess) {
 			snprintf(test_msg, ASYM_TEST_MSG_LEN,
 					"line %u "
@@ -462,15 +463,6 @@ test_cryptodev_asym_op(struct crypto_testsuite_params_asym *ts_params,
 			goto error_exit;
 		}
 
-		if (rte_cryptodev_asym_session_init(dev_id, sess, &xform_tc,
-				ts_params->session_mpool) < 0) {
-			snprintf(test_msg, ASYM_TEST_MSG_LEN,
-					"line %u FAILED: %s",
-					__LINE__, "unabled to config sym session");
-			status = TEST_FAILED;
-			goto error_exit;
-		}
-
 		rte_crypto_op_attach_asym_session(op, sess);
 	} else {
 		asym_op->xform = &xform_tc;
@@ -512,10 +504,8 @@ test_cryptodev_asym_op(struct crypto_testsuite_params_asym *ts_params,
 		snprintf(test_msg, ASYM_TEST_MSG_LEN, "SESSIONLESS PASS");
 
 error_exit:
-		if (sess != NULL) {
-			rte_cryptodev_asym_session_clear(dev_id, sess);
-			rte_cryptodev_asym_session_free(sess);
-		}
+		if (sess != NULL)
+			rte_cryptodev_asym_session_free(dev_id, sess);
 
 		if (op != NULL)
 			rte_crypto_op_free(op);
@@ -669,18 +659,11 @@ test_rsa_sign_verify(void)
 		return TEST_SKIPPED;
 	}
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
+	sess = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool);
 
 	if (!sess) {
 		RTE_LOG(ERR, USER1, "Session creation failed for "
 			"sign_verify\n");
-		return TEST_FAILED;
-	}
-
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform,
-				sess_mpool) < 0) {
-		RTE_LOG(ERR, USER1, "Unable to config asym session for "
-			"sign_verify\n");
 		status = TEST_FAILED;
 		goto error_exit;
 	}
@@ -688,9 +671,7 @@ test_rsa_sign_verify(void)
 	status = queue_ops_rsa_sign_verify(sess);
 
 error_exit:
-
-	rte_cryptodev_asym_session_clear(dev_id, sess);
-	rte_cryptodev_asym_session_free(sess);
+	rte_cryptodev_asym_session_free(dev_id, sess);
 
 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
 
@@ -718,17 +699,10 @@ test_rsa_enc_dec(void)
 		return TEST_SKIPPED;
 	}
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
+	sess = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool);
 
 	if (!sess) {
 		RTE_LOG(ERR, USER1, "Session creation failed for enc_dec\n");
-		return TEST_FAILED;
-	}
-
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform,
-				sess_mpool) < 0) {
-		RTE_LOG(ERR, USER1, "Unable to config asym session for "
-			"enc_dec\n");
 		status = TEST_FAILED;
 		goto error_exit;
 	}
@@ -737,8 +711,7 @@ test_rsa_enc_dec(void)
 
 error_exit:
 
-	rte_cryptodev_asym_session_clear(dev_id, sess);
-	rte_cryptodev_asym_session_free(sess);
+	rte_cryptodev_asym_session_free(dev_id, sess);
 
 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
 
@@ -765,28 +738,20 @@ test_rsa_sign_verify_crt(void)
 		return TEST_SKIPPED;
 	}
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
+	sess = rte_cryptodev_asym_session_create(dev_id, &rsa_xform_crt, sess_mpool);
 
 	if (!sess) {
 		RTE_LOG(ERR, USER1, "Session creation failed for "
 			"sign_verify_crt\n");
 		status = TEST_FAILED;
-		return status;
-	}
-
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform_crt,
-				sess_mpool) < 0) {
-		RTE_LOG(ERR, USER1, "Unable to config asym session for "
-			"sign_verify_crt\n");
-		status = TEST_FAILED;
 		goto error_exit;
 	}
+
 	status = queue_ops_rsa_sign_verify(sess);
 
 error_exit:
 
-	rte_cryptodev_asym_session_clear(dev_id, sess);
-	rte_cryptodev_asym_session_free(sess);
+	rte_cryptodev_asym_session_free(dev_id, sess);
 
 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
 
@@ -813,27 +778,20 @@ test_rsa_enc_dec_crt(void)
 		return TEST_SKIPPED;
 	}
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
+	sess = rte_cryptodev_asym_session_create(dev_id, &rsa_xform_crt, sess_mpool);
 
 	if (!sess) {
 		RTE_LOG(ERR, USER1, "Session creation failed for "
 			"enc_dec_crt\n");
-		return TEST_FAILED;
-	}
-
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform_crt,
-				sess_mpool) < 0) {
-		RTE_LOG(ERR, USER1, "Unable to config asym session for "
-			"enc_dec_crt\n");
 		status = TEST_FAILED;
 		goto error_exit;
 	}
+
 	status = queue_ops_rsa_enc_dec(sess);
 
 error_exit:
 
-	rte_cryptodev_asym_session_clear(dev_id, sess);
-	rte_cryptodev_asym_session_free(sess);
+	rte_cryptodev_asym_session_free(dev_id, sess);
 
 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
 
@@ -927,7 +885,6 @@ testsuite_setup(void)
 	/* configure qp */
 	ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
 	ts_params->qp_conf.mp_session = ts_params->session_mpool;
-	ts_params->qp_conf.mp_session_private = ts_params->session_mpool;
 	for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
 			dev_id, qp_id, &ts_params->qp_conf,
@@ -936,21 +893,9 @@ testsuite_setup(void)
 			qp_id, dev_id);
 	}
 
-	/* setup asym session pool */
-	unsigned int session_size = RTE_MAX(
-		rte_cryptodev_asym_get_private_session_size(dev_id),
-		rte_cryptodev_asym_get_header_session_size());
-	/*
-	 * Create mempool with TEST_NUM_SESSIONS * 2,
-	 * to include the session headers
-	 */
-	ts_params->session_mpool = rte_mempool_create(
-				"test_asym_sess_mp",
-				TEST_NUM_SESSIONS * 2,
-				session_size,
-				0, 0, NULL, NULL, NULL,
-				NULL, SOCKET_ID_ANY,
-				0);
+	ts_params->session_mpool = rte_cryptodev_asym_session_pool_create(
+			"test_asym_sess_mp", TEST_NUM_SESSIONS, 0,
+			SOCKET_ID_ANY);
 
 	TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
 			"session mempool allocation failed");
@@ -1107,14 +1052,6 @@ test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
 	struct rte_crypto_asym_xform xform = *xfrm;
 	uint8_t peer[] = "01234567890123456789012345678901234567890123456789";
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
-	if (sess == NULL) {
-		RTE_LOG(ERR, USER1,
-				"line %u FAILED: %s", __LINE__,
-				"Session creation failed");
-		status = TEST_FAILED;
-		goto error_exit;
-	}
 	/* set up crypto op data structure */
 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
 	if (!op) {
@@ -1137,11 +1074,11 @@ test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
 	asym_op->dh.shared_secret.data = output;
 	asym_op->dh.shared_secret.length = sizeof(output);
 
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
-			sess_mpool) < 0) {
+	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
+	if (sess == NULL) {
 		RTE_LOG(ERR, USER1,
-				"line %u FAILED: %s",
-				__LINE__, "unabled to config sym session");
+				"line %u FAILED: %s", __LINE__,
+				"Session creation failed");
 		status = TEST_FAILED;
 		goto error_exit;
 	}
@@ -1176,10 +1113,8 @@ test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
 			asym_op->dh.shared_secret.length);
 
 error_exit:
-	if (sess != NULL) {
-		rte_cryptodev_asym_session_clear(dev_id, sess);
-		rte_cryptodev_asym_session_free(sess);
-	}
+	if (sess != NULL)
+		rte_cryptodev_asym_session_free(dev_id, sess);
 	if (op != NULL)
 		rte_crypto_op_free(op);
 	return status;
@@ -1199,14 +1134,6 @@ test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
 	uint8_t output[TEST_DH_MOD_LEN];
 	struct rte_crypto_asym_xform xform = *xfrm;
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
-	if (sess == NULL) {
-		RTE_LOG(ERR, USER1,
-				 "line %u FAILED: %s", __LINE__,
-				"Session creation failed");
-		status = TEST_FAILED;
-		goto error_exit;
-	}
 	/* set up crypto op data structure */
 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
 	if (!op) {
@@ -1225,11 +1152,11 @@ test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
 	asym_op->dh.priv_key.data = output;
 	asym_op->dh.priv_key.length = sizeof(output);
 
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
-			sess_mpool) < 0) {
+	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
+	if (sess == NULL) {
 		RTE_LOG(ERR, USER1,
-				"line %u FAILED: %s",
-				__LINE__, "unabled to config sym session");
+				"line %u FAILED: %s", __LINE__,
+				"Session creation failed");
 		status = TEST_FAILED;
 		goto error_exit;
 	}
@@ -1265,10 +1192,8 @@ test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
 
 
 error_exit:
-	if (sess != NULL) {
-		rte_cryptodev_asym_session_clear(dev_id, sess);
-		rte_cryptodev_asym_session_free(sess);
-	}
+	if (sess != NULL)
+		rte_cryptodev_asym_session_free(dev_id, sess);
 	if (op != NULL)
 		rte_crypto_op_free(op);
 
@@ -1290,14 +1215,6 @@ test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
 	uint8_t output[TEST_DH_MOD_LEN];
 	struct rte_crypto_asym_xform xform = *xfrm;
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
-	if (sess == NULL) {
-		RTE_LOG(ERR, USER1,
-				 "line %u FAILED: %s", __LINE__,
-				"Session creation failed");
-		status = TEST_FAILED;
-		goto error_exit;
-	}
 	/* set up crypto op data structure */
 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
 	if (!op) {
@@ -1324,11 +1241,11 @@ test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
 					0);
 	asym_op->dh.priv_key = dh_test_params.priv_key;
 
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
-			sess_mpool) < 0) {
+	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
+	if (sess == NULL) {
 		RTE_LOG(ERR, USER1,
-				"line %u FAILED: %s",
-				__LINE__, "unabled to config sym session");
+				"line %u FAILED: %s", __LINE__,
+				"Session creation failed");
 		status = TEST_FAILED;
 		goto error_exit;
 	}
@@ -1365,10 +1282,8 @@ test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
 			asym_op->dh.priv_key.data, asym_op->dh.priv_key.length);
 
 error_exit:
-	if (sess != NULL) {
-		rte_cryptodev_asym_session_clear(dev_id, sess);
-		rte_cryptodev_asym_session_free(sess);
-	}
+	if (sess != NULL)
+		rte_cryptodev_asym_session_free(dev_id, sess);
 	if (op != NULL)
 		rte_crypto_op_free(op);
 
@@ -1391,15 +1306,6 @@ test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
 	struct rte_crypto_asym_xform pub_key_xform;
 	struct rte_crypto_asym_xform xform = *xfrm;
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
-	if (sess == NULL) {
-		RTE_LOG(ERR, USER1,
-				 "line %u FAILED: %s", __LINE__,
-				"Session creation failed");
-		status = TEST_FAILED;
-		goto error_exit;
-	}
-
 	/* set up crypto op data structure */
 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
 	if (!op) {
@@ -1423,11 +1329,12 @@ test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
 	asym_op->dh.pub_key.length = sizeof(out_pub_key);
 	asym_op->dh.priv_key.data = out_prv_key;
 	asym_op->dh.priv_key.length = sizeof(out_prv_key);
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
-			sess_mpool) < 0) {
+
+	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
+	if (sess == NULL) {
 		RTE_LOG(ERR, USER1,
-				"line %u FAILED: %s",
-				__LINE__, "unabled to config sym session");
+				"line %u FAILED: %s", __LINE__,
+				"Session creation failed");
 		status = TEST_FAILED;
 		goto error_exit;
 	}
@@ -1462,10 +1369,8 @@ test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
 			out_pub_key, asym_op->dh.pub_key.length);
 
 error_exit:
-	if (sess != NULL) {
-		rte_cryptodev_asym_session_clear(dev_id, sess);
-		rte_cryptodev_asym_session_free(sess);
-	}
+	if (sess != NULL)
+		rte_cryptodev_asym_session_free(dev_id, sess);
 	if (op != NULL)
 		rte_crypto_op_free(op);
 
@@ -1514,7 +1419,7 @@ test_mod_inv(void)
 				return TEST_SKIPPED;
 		}
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
+	sess = rte_cryptodev_asym_session_create(dev_id, &modinv_xform, sess_mpool);
 	if (!sess) {
 		RTE_LOG(ERR, USER1, "line %u "
 				"FAILED: %s", __LINE__,
@@ -1523,15 +1428,6 @@ test_mod_inv(void)
 		goto error_exit;
 	}
 
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &modinv_xform,
-			sess_mpool) < 0) {
-		RTE_LOG(ERR, USER1,
-				"line %u FAILED: %s",
-				__LINE__, "unabled to config sym session");
-		status = TEST_FAILED;
-		goto error_exit;
-	}
-
 	/* generate crypto op data structure */
 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
 	if (!op) {
@@ -1583,10 +1479,8 @@ test_mod_inv(void)
 	}
 
 error_exit:
-	if (sess) {
-		rte_cryptodev_asym_session_clear(dev_id, sess);
-		rte_cryptodev_asym_session_free(sess);
-	}
+	if (sess)
+		rte_cryptodev_asym_session_free(dev_id, sess);
 
 	if (op)
 		rte_crypto_op_free(op);
@@ -1649,7 +1543,7 @@ test_mod_exp(void)
 		goto error_exit;
 	}
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
+	sess = rte_cryptodev_asym_session_create(dev_id, &modex_xform, sess_mpool);
 	if (!sess) {
 		RTE_LOG(ERR, USER1,
 				 "line %u "
@@ -1659,15 +1553,6 @@ test_mod_exp(void)
 		goto error_exit;
 	}
 
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &modex_xform,
-			sess_mpool) < 0) {
-		RTE_LOG(ERR, USER1,
-				"line %u FAILED: %s",
-				__LINE__, "unabled to config sym session");
-		status = TEST_FAILED;
-		goto error_exit;
-	}
-
 	asym_op = op->asym;
 	memcpy(input, base, sizeof(base));
 	asym_op->modex.base.data = input;
@@ -1706,10 +1591,8 @@ test_mod_exp(void)
 	}
 
 error_exit:
-	if (sess != NULL) {
-		rte_cryptodev_asym_session_clear(dev_id, sess);
-		rte_cryptodev_asym_session_free(sess);
-	}
+	if (sess != NULL)
+		rte_cryptodev_asym_session_free(dev_id, sess);
 
 	if (op != NULL)
 		rte_crypto_op_free(op);
@@ -1771,7 +1654,7 @@ test_dsa_sign(void)
 	uint8_t s[TEST_DH_MOD_LEN];
 	uint8_t dgst[] = "35d81554afaad2cf18f3a1770d5fedc4ea5be344";
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
+	sess = rte_cryptodev_asym_session_create(dev_id, &dsa_xform, sess_mpool);
 	if (sess == NULL) {
 		RTE_LOG(ERR, USER1,
 				 "line %u FAILED: %s", __LINE__,
@@ -1800,15 +1683,6 @@ test_dsa_sign(void)
 	debug_hexdump(stdout, "priv_key: ", dsa_xform.dsa.x.data,
 			dsa_xform.dsa.x.length);
 
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &dsa_xform,
-				sess_mpool) < 0) {
-		RTE_LOG(ERR, USER1,
-				"line %u FAILED: %s",
-				__LINE__, "unabled to config sym session");
-		status = TEST_FAILED;
-		goto error_exit;
-	}
-
 	/* attach asymmetric crypto session to crypto operations */
 	rte_crypto_op_attach_asym_session(op, sess);
 	asym_op->dsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
@@ -1882,10 +1756,8 @@ test_dsa_sign(void)
 		status = TEST_FAILED;
 	}
 error_exit:
-	if (sess != NULL) {
-		rte_cryptodev_asym_session_clear(dev_id, sess);
-		rte_cryptodev_asym_session_free(sess);
-	}
+	if (sess != NULL)
+		rte_cryptodev_asym_session_free(dev_id, sess);
 	if (op != NULL)
 		rte_crypto_op_free(op);
 	return status;
@@ -1944,15 +1816,6 @@ test_ecdsa_sign_verify(enum curve curve_id)
 
 	rte_cryptodev_info_get(dev_id, &dev_info);
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
-	if (sess == NULL) {
-		RTE_LOG(ERR, USER1,
-				"line %u FAILED: %s", __LINE__,
-				"Session creation failed\n");
-		status = TEST_FAILED;
-		goto exit;
-	}
-
 	/* Setup crypto op data structure */
 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
 	if (op == NULL) {
@@ -1970,11 +1833,11 @@ test_ecdsa_sign_verify(enum curve curve_id)
 	xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDSA;
 	xform.ec.curve_id = input_params.curve;
 
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
-				sess_mpool) < 0) {
+	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
+	if (sess == NULL) {
 		RTE_LOG(ERR, USER1,
 				"line %u FAILED: %s", __LINE__,
-				"Unable to config asym session\n");
+				"Session creation failed\n");
 		status = TEST_FAILED;
 		goto exit;
 	}
@@ -2082,10 +1945,8 @@ test_ecdsa_sign_verify(enum curve curve_id)
 	}
 
 exit:
-	if (sess != NULL) {
-		rte_cryptodev_asym_session_clear(dev_id, sess);
-		rte_cryptodev_asym_session_free(sess);
-	}
+	if (sess != NULL)
+		rte_cryptodev_asym_session_free(dev_id, sess);
 	if (op != NULL)
 		rte_crypto_op_free(op);
 	return status;
@@ -2157,15 +2018,6 @@ test_ecpm(enum curve curve_id)
 
 	rte_cryptodev_info_get(dev_id, &dev_info);
 
-	sess = rte_cryptodev_asym_session_create(sess_mpool);
-	if (sess == NULL) {
-		RTE_LOG(ERR, USER1,
-				"line %u FAILED: %s", __LINE__,
-				"Session creation failed\n");
-		status = TEST_FAILED;
-		goto exit;
-	}
-
 	/* Setup crypto op data structure */
 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
 	if (op == NULL) {
@@ -2183,11 +2035,11 @@ test_ecpm(enum curve curve_id)
 	xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECPM;
 	xform.ec.curve_id = input_params.curve;
 
-	if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
-				sess_mpool) < 0) {
+	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
+	if (sess == NULL) {
 		RTE_LOG(ERR, USER1,
 				"line %u FAILED: %s", __LINE__,
-				"Unable to config asym session\n");
+				"Session creation failed\n");
 		status = TEST_FAILED;
 		goto exit;
 	}
@@ -2255,10 +2107,8 @@ test_ecpm(enum curve curve_id)
 	}
 
 exit:
-	if (sess != NULL) {
-		rte_cryptodev_asym_session_clear(dev_id, sess);
-		rte_cryptodev_asym_session_free(sess);
-	}
+	if (sess != NULL)
+		rte_cryptodev_asym_session_free(dev_id, sess);
 	if (op != NULL)
 		rte_crypto_op_free(op);
 	return status;
diff --git a/doc/guides/prog_guide/cryptodev_lib.rst b/doc/guides/prog_guide/cryptodev_lib.rst
index 9f33f7a177..b4dbd384bf 100644
--- a/doc/guides/prog_guide/cryptodev_lib.rst
+++ b/doc/guides/prog_guide/cryptodev_lib.rst
@@ -1038,20 +1038,17 @@ It is the application's responsibility to create and manage the session mempools
 Application using both symmetric and asymmetric sessions should allocate and maintain
 different sessions pools for each type.
 
-An application can use ``rte_cryptodev_get_asym_session_private_size()`` to
-get the private size of asymmetric session on a given crypto device. This
-function would allow an application to calculate the max device asymmetric
-session size of all crypto devices to create a single session mempool.
-If instead an application creates multiple asymmetric session mempools,
-the Crypto device framework also provides ``rte_cryptodev_asym_get_header_session_size()`` to get
-the size of an uninitialized session.
+An application can use ``rte_cryptodev_asym_session_pool_create()`` to create a mempool
+with a specified number of elements. The element size will allow for the session header,
+and the max private session size.
+The max private session size is chosen based on available crypto devices,
+the biggest private session size is used. This means any of those devices can be used,
+and the mempool element will have available space for its private session data.
 
 Once the session mempools have been created, ``rte_cryptodev_asym_session_create()``
-is used to allocate an uninitialized asymmetric session from the given mempool.
-The session then must be initialized using ``rte_cryptodev_asym_session_init()``
-for each of the required crypto devices. An asymmetric transform chain
-is used to specify the operation and its parameters. See the section below for
-details on transforms.
+is used to allocate and initialize an asymmetric session from the given mempool.
+An asymmetric transform chain is used to specify the operation and its parameters.
+See the section below for details on transforms.
 
 When a session is no longer used, user must call ``rte_cryptodev_asym_session_clear()``
 for each of the crypto devices that are using the session, to free all driver
diff --git a/doc/guides/rel_notes/release_22_03.rst b/doc/guides/rel_notes/release_22_03.rst
index a820cc5596..ea4c5309a0 100644
--- a/doc/guides/rel_notes/release_22_03.rst
+++ b/doc/guides/rel_notes/release_22_03.rst
@@ -112,6 +112,13 @@ API Changes
 * ethdev: Old public macros and enumeration constants without ``RTE_ETH_`` prefix,
   which are kept for backward compatibility, are marked as deprecated.
 
+* cryptodev: The asymmetric session handling was modified to use a single
+  mempool object. An API ``rte_cryptodev_asym_session_pool_create`` was added
+  to create a mempool with element size big enough to hold the generic asymmetric
+  session header and max size for a device private session data.
+  The API ``rte_cryptodev_asym_session_init`` was removed as the initialization
+  is now moved to ``rte_cryptodev_asym_session_create``.
+
 
 ABI Changes
 -----------
diff --git a/drivers/crypto/cnxk/cn10k_cryptodev_ops.c b/drivers/crypto/cnxk/cn10k_cryptodev_ops.c
index d217bbf383..c4d5d039ec 100644
--- a/drivers/crypto/cnxk/cn10k_cryptodev_ops.c
+++ b/drivers/crypto/cnxk/cn10k_cryptodev_ops.c
@@ -157,8 +157,8 @@ cn10k_cpt_fill_inst(struct cnxk_cpt_qp *qp, struct rte_crypto_op *ops[],
 
 		if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
 			asym_op = op->asym;
-			ae_sess = get_asym_session_private_data(
-				asym_op->session, cn10k_cryptodev_driver_id);
+			ae_sess = (struct cnxk_ae_sess *)
+					asym_op->session->sess_private_data;
 			ret = cnxk_ae_enqueue(qp, op, infl_req, &inst[0],
 					      ae_sess);
 			if (unlikely(ret))
@@ -431,8 +431,8 @@ cn10k_cpt_dequeue_post_process(struct cnxk_cpt_qp *qp,
 			uintptr_t *mdata = infl_req->mdata;
 			struct cnxk_ae_sess *sess;
 
-			sess = get_asym_session_private_data(
-				op->session, cn10k_cryptodev_driver_id);
+			sess = (struct cnxk_ae_sess *)
+					op->session->sess_private_data;
 
 			cnxk_ae_post_process(cop, sess, (uint8_t *)mdata[0]);
 		}
diff --git a/drivers/crypto/cnxk/cn9k_cryptodev_ops.c b/drivers/crypto/cnxk/cn9k_cryptodev_ops.c
index ac1953b66d..b8ad4bf211 100644
--- a/drivers/crypto/cnxk/cn9k_cryptodev_ops.c
+++ b/drivers/crypto/cnxk/cn9k_cryptodev_ops.c
@@ -138,8 +138,8 @@ cn9k_cpt_inst_prep(struct cnxk_cpt_qp *qp, struct rte_crypto_op *op,
 
 		if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
 			asym_op = op->asym;
-			sess = get_asym_session_private_data(
-				asym_op->session, cn9k_cryptodev_driver_id);
+			sess = (struct cnxk_ae_sess *)
+					asym_op->session->sess_private_data;
 			ret = cnxk_ae_enqueue(qp, op, infl_req, inst, sess);
 			inst->w7.u64 = sess->cpt_inst_w7;
 		} else {
@@ -453,8 +453,8 @@ cn9k_cpt_dequeue_post_process(struct cnxk_cpt_qp *qp, struct rte_crypto_op *cop,
 			uintptr_t *mdata = infl_req->mdata;
 			struct cnxk_ae_sess *sess;
 
-			sess = get_asym_session_private_data(
-				op->session, cn9k_cryptodev_driver_id);
+			sess = (struct cnxk_ae_sess *)
+					op->session->sess_private_data;
 
 			cnxk_ae_post_process(cop, sess, (uint8_t *)mdata[0]);
 		}
diff --git a/drivers/crypto/cnxk/cnxk_cryptodev_ops.c b/drivers/crypto/cnxk/cnxk_cryptodev_ops.c
index a5fb68da02..7237dacb48 100644
--- a/drivers/crypto/cnxk/cnxk_cryptodev_ops.c
+++ b/drivers/crypto/cnxk/cnxk_cryptodev_ops.c
@@ -658,10 +658,9 @@ void
 cnxk_ae_session_clear(struct rte_cryptodev *dev,
 		      struct rte_cryptodev_asym_session *sess)
 {
-	struct rte_mempool *sess_mp;
 	struct cnxk_ae_sess *priv;
 
-	priv = get_asym_session_private_data(sess, dev->driver_id);
+	priv = (struct cnxk_ae_sess *) sess->sess_private_data;
 	if (priv == NULL)
 		return;
 
@@ -670,40 +669,29 @@ cnxk_ae_session_clear(struct rte_cryptodev *dev,
 
 	/* Reset and free object back to pool */
 	memset(priv, 0, cnxk_ae_session_size_get(dev));
-	sess_mp = rte_mempool_from_obj(priv);
-	set_asym_session_private_data(sess, dev->driver_id, NULL);
-	rte_mempool_put(sess_mp, priv);
 }
 
 int
 cnxk_ae_session_cfg(struct rte_cryptodev *dev,
 		    struct rte_crypto_asym_xform *xform,
-		    struct rte_cryptodev_asym_session *sess,
-		    struct rte_mempool *pool)
+		    struct rte_cryptodev_asym_session *sess)
 {
+	struct cnxk_ae_sess *priv =
+			(struct cnxk_ae_sess *) sess->sess_private_data;
 	struct cnxk_cpt_vf *vf = dev->data->dev_private;
 	struct roc_cpt *roc_cpt = &vf->cpt;
-	struct cnxk_ae_sess *priv;
 	union cpt_inst_w7 w7;
 	int ret;
 
-	if (rte_mempool_get(pool, (void **)&priv))
-		return -ENOMEM;
-
-	memset(priv, 0, sizeof(struct cnxk_ae_sess));
-
 	ret = cnxk_ae_fill_session_parameters(priv, xform);
-	if (ret) {
-		rte_mempool_put(pool, priv);
+	if (ret)
 		return ret;
-	}
 
 	w7.u64 = 0;
 	w7.s.egrp = roc_cpt->eng_grp[CPT_ENG_TYPE_AE];
 	priv->cpt_inst_w7 = w7.u64;
 	priv->cnxk_fpm_iova = vf->cnxk_fpm_iova;
 	priv->ec_grp = vf->ec_grp;
-	set_asym_session_private_data(sess, dev->driver_id, priv);
 
 	return 0;
 }
diff --git a/drivers/crypto/cnxk/cnxk_cryptodev_ops.h b/drivers/crypto/cnxk/cnxk_cryptodev_ops.h
index 0656ba9675..ab0f00ee7c 100644
--- a/drivers/crypto/cnxk/cnxk_cryptodev_ops.h
+++ b/drivers/crypto/cnxk/cnxk_cryptodev_ops.h
@@ -122,8 +122,7 @@ void cnxk_ae_session_clear(struct rte_cryptodev *dev,
 			   struct rte_cryptodev_asym_session *sess);
 int cnxk_ae_session_cfg(struct rte_cryptodev *dev,
 			struct rte_crypto_asym_xform *xform,
-			struct rte_cryptodev_asym_session *sess,
-			struct rte_mempool *pool);
+			struct rte_cryptodev_asym_session *sess);
 void cnxk_cpt_dump_on_err(struct cnxk_cpt_qp *qp);
 
 static inline union rte_event_crypto_metadata *
diff --git a/drivers/crypto/octeontx/otx_cryptodev_ops.c b/drivers/crypto/octeontx/otx_cryptodev_ops.c
index f7ca8a8a8e..0cb6dbb38c 100644
--- a/drivers/crypto/octeontx/otx_cryptodev_ops.c
+++ b/drivers/crypto/octeontx/otx_cryptodev_ops.c
@@ -375,35 +375,24 @@ otx_cpt_asym_session_size_get(struct rte_cryptodev *dev __rte_unused)
 }
 
 static int
-otx_cpt_asym_session_cfg(struct rte_cryptodev *dev,
+otx_cpt_asym_session_cfg(struct rte_cryptodev *dev __rte_unused,
 			 struct rte_crypto_asym_xform *xform __rte_unused,
-			 struct rte_cryptodev_asym_session *sess,
-			 struct rte_mempool *pool)
+			 struct rte_cryptodev_asym_session *sess)
 {
-	struct cpt_asym_sess_misc *priv;
+	struct cpt_asym_sess_misc *priv = (struct cpt_asym_sess_misc *)
+			sess->sess_private_data;
 	int ret;
 
 	CPT_PMD_INIT_FUNC_TRACE();
 
-	if (rte_mempool_get(pool, (void **)&priv)) {
-		CPT_LOG_ERR("Could not allocate session private data");
-		return -ENOMEM;
-	}
-
-	memset(priv, 0, sizeof(struct cpt_asym_sess_misc));
-
 	ret = cpt_fill_asym_session_parameters(priv, xform);
 	if (ret) {
 		CPT_LOG_ERR("Could not configure session parameters");
-
-		/* Return session to mempool */
-		rte_mempool_put(pool, priv);
 		return ret;
 	}
 
 	priv->cpt_inst_w7 = 0;
 
-	set_asym_session_private_data(sess, dev->driver_id, priv);
 	return 0;
 }
 
@@ -412,11 +401,10 @@ otx_cpt_asym_session_clear(struct rte_cryptodev *dev,
 			   struct rte_cryptodev_asym_session *sess)
 {
 	struct cpt_asym_sess_misc *priv;
-	struct rte_mempool *sess_mp;
 
 	CPT_PMD_INIT_FUNC_TRACE();
 
-	priv = get_asym_session_private_data(sess, dev->driver_id);
+	priv = (struct cpt_asym_sess_misc *) sess->sess_private_data;
 
 	if (priv == NULL)
 		return;
@@ -424,9 +412,6 @@ otx_cpt_asym_session_clear(struct rte_cryptodev *dev,
 	/* Free resources allocated during session configure */
 	cpt_free_asym_session_parameters(priv);
 	memset(priv, 0, otx_cpt_asym_session_size_get(dev));
-	sess_mp = rte_mempool_from_obj(priv);
-	set_asym_session_private_data(sess, dev->driver_id, NULL);
-	rte_mempool_put(sess_mp, priv);
 }
 
 static __rte_always_inline void * __rte_hot
@@ -471,8 +456,8 @@ otx_cpt_enq_single_asym(struct cpt_instance *instance,
 		return NULL;
 	}
 
-	sess = get_asym_session_private_data(asym_op->session,
-					     otx_cryptodev_driver_id);
+	sess = (struct cpt_asym_sess_misc *)
+			asym_op->session->sess_private_data;
 
 	/* Store phys_addr of the mdata to meta_buf */
 	params.meta_buf = rte_mempool_virt2iova(mdata);
@@ -852,8 +837,7 @@ otx_cpt_asym_post_process(struct rte_crypto_op *cop,
 	struct rte_crypto_asym_op *op = cop->asym;
 	struct cpt_asym_sess_misc *sess;
 
-	sess = get_asym_session_private_data(op->session,
-					     otx_cryptodev_driver_id);
+	sess = (struct cpt_asym_sess_misc *) op->session->sess_private_data;
 
 	switch (sess->xfrm_type) {
 	case RTE_CRYPTO_ASYM_XFORM_RSA:
diff --git a/drivers/crypto/openssl/rte_openssl_pmd.c b/drivers/crypto/openssl/rte_openssl_pmd.c
index 5794ed8159..d80e1052e2 100644
--- a/drivers/crypto/openssl/rte_openssl_pmd.c
+++ b/drivers/crypto/openssl/rte_openssl_pmd.c
@@ -748,9 +748,7 @@ get_session(struct openssl_qp *qp, struct rte_crypto_op *op)
 		} else {
 			if (likely(op->asym->session != NULL))
 				asym_sess = (struct openssl_asym_session *)
-						get_asym_session_private_data(
-						op->asym->session,
-						cryptodev_driver_id);
+						op->asym->session->sess_private_data;
 			if (asym_sess == NULL)
 				op->status =
 					RTE_CRYPTO_OP_STATUS_INVALID_SESSION;
diff --git a/drivers/crypto/openssl/rte_openssl_pmd_ops.c b/drivers/crypto/openssl/rte_openssl_pmd_ops.c
index 52715f86f8..556fd226ed 100644
--- a/drivers/crypto/openssl/rte_openssl_pmd_ops.c
+++ b/drivers/crypto/openssl/rte_openssl_pmd_ops.c
@@ -1119,8 +1119,7 @@ static int openssl_set_asym_session_parameters(
 static int
 openssl_pmd_asym_session_configure(struct rte_cryptodev *dev __rte_unused,
 		struct rte_crypto_asym_xform *xform,
-		struct rte_cryptodev_asym_session *sess,
-		struct rte_mempool *mempool)
+		struct rte_cryptodev_asym_session *sess)
 {
 	void *asym_sess_private_data;
 	int ret;
@@ -1130,25 +1129,14 @@ openssl_pmd_asym_session_configure(struct rte_cryptodev *dev __rte_unused,
 		return -EINVAL;
 	}
 
-	if (rte_mempool_get(mempool, &asym_sess_private_data)) {
-		CDEV_LOG_ERR(
-			"Couldn't get object from session mempool");
-		return -ENOMEM;
-	}
-
+	asym_sess_private_data = sess->sess_private_data;
 	ret = openssl_set_asym_session_parameters(asym_sess_private_data,
 			xform);
 	if (ret != 0) {
 		OPENSSL_LOG(ERR, "failed configure session parameters");
-
-		/* Return session to mempool */
-		rte_mempool_put(mempool, asym_sess_private_data);
 		return ret;
 	}
 
-	set_asym_session_private_data(sess, dev->driver_id,
-			asym_sess_private_data);
-
 	return 0;
 }
 
@@ -1206,19 +1194,15 @@ static void openssl_reset_asym_session(struct openssl_asym_session *sess)
  * so it doesn't leave key material behind
  */
 static void
-openssl_pmd_asym_session_clear(struct rte_cryptodev *dev,
+openssl_pmd_asym_session_clear(struct rte_cryptodev *dev __rte_unused,
 		struct rte_cryptodev_asym_session *sess)
 {
-	uint8_t index = dev->driver_id;
-	void *sess_priv = get_asym_session_private_data(sess, index);
+	void *sess_priv = sess->sess_private_data;
 
 	/* Zero out the whole structure */
 	if (sess_priv) {
 		openssl_reset_asym_session(sess_priv);
 		memset(sess_priv, 0, sizeof(struct openssl_asym_session));
-		struct rte_mempool *sess_mp = rte_mempool_from_obj(sess_priv);
-		set_asym_session_private_data(sess, index, NULL);
-		rte_mempool_put(sess_mp, sess_priv);
 	}
 }
 
diff --git a/drivers/crypto/qat/qat_asym.c b/drivers/crypto/qat/qat_asym.c
index 09d8761c5f..f46eefd4b3 100644
--- a/drivers/crypto/qat/qat_asym.c
+++ b/drivers/crypto/qat/qat_asym.c
@@ -492,8 +492,7 @@ qat_asym_build_request(void *in_op,
 	op->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
 	if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
 		ctx = (struct qat_asym_session *)
-			get_asym_session_private_data(
-			op->asym->session, qat_asym_driver_id);
+				op->asym->session->sess_private_data;
 		if (unlikely(ctx == NULL)) {
 			QAT_LOG(ERR, "Session has not been created for this device");
 			goto error;
@@ -711,8 +710,8 @@ qat_asym_process_response(void **op, uint8_t *resp,
 	}
 
 	if (rx_op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
-		ctx = (struct qat_asym_session *)get_asym_session_private_data(
-			rx_op->asym->session, qat_asym_driver_id);
+		ctx = (struct qat_asym_session *)
+				rx_op->asym->session->sess_private_data;
 		qat_asym_collect_response(rx_op, cookie, ctx->xform);
 	} else if (rx_op->sess_type == RTE_CRYPTO_OP_SESSIONLESS) {
 		qat_asym_collect_response(rx_op, cookie, rx_op->asym->xform);
@@ -726,61 +725,42 @@ qat_asym_process_response(void **op, uint8_t *resp,
 }
 
 int
-qat_asym_session_configure(struct rte_cryptodev *dev,
+qat_asym_session_configure(struct rte_cryptodev *dev __rte_unused,
 		struct rte_crypto_asym_xform *xform,
-		struct rte_cryptodev_asym_session *sess,
-		struct rte_mempool *mempool)
+		struct rte_cryptodev_asym_session *sess)
 {
-	int err = 0;
-	void *sess_private_data;
 	struct qat_asym_session *session;
 
-	if (rte_mempool_get(mempool, &sess_private_data)) {
-		QAT_LOG(ERR,
-			"Couldn't get object from session mempool");
-		return -ENOMEM;
-	}
-
-	session = sess_private_data;
+	session = (struct qat_asym_session *) sess->sess_private_data;
 	if (xform->xform_type == RTE_CRYPTO_ASYM_XFORM_MODEX) {
 		if (xform->modex.exponent.length == 0 ||
 				xform->modex.modulus.length == 0) {
 			QAT_LOG(ERR, "Invalid mod exp input parameter");
-			err = -EINVAL;
-			goto error;
+			return -EINVAL;
 		}
 	} else if (xform->xform_type == RTE_CRYPTO_ASYM_XFORM_MODINV) {
 		if (xform->modinv.modulus.length == 0) {
 			QAT_LOG(ERR, "Invalid mod inv input parameter");
-			err = -EINVAL;
-			goto error;
+			return -EINVAL;
 		}
 	} else if (xform->xform_type == RTE_CRYPTO_ASYM_XFORM_RSA) {
 		if (xform->rsa.n.length == 0) {
 			QAT_LOG(ERR, "Invalid rsa input parameter");
-			err = -EINVAL;
-			goto error;
+			return -EINVAL;
 		}
 	} else if (xform->xform_type >= RTE_CRYPTO_ASYM_XFORM_TYPE_LIST_END
 			|| xform->xform_type <= RTE_CRYPTO_ASYM_XFORM_NONE) {
 		QAT_LOG(ERR, "Invalid asymmetric crypto xform");
-		err = -EINVAL;
-		goto error;
+		return -EINVAL;
 	} else {
 		QAT_LOG(ERR, "Asymmetric crypto xform not implemented");
-		err = -EINVAL;
-		goto error;
+		return -EINVAL;
 	}
 
 	session->xform = xform;
-	qat_asym_build_req_tmpl(sess_private_data);
-	set_asym_session_private_data(sess, dev->driver_id,
-		sess_private_data);
+	qat_asym_build_req_tmpl(session);
 
 	return 0;
-error:
-	rte_mempool_put(mempool, sess_private_data);
-	return err;
 }
 
 unsigned int qat_asym_session_get_private_size(
@@ -793,15 +773,9 @@ void
 qat_asym_session_clear(struct rte_cryptodev *dev,
 		struct rte_cryptodev_asym_session *sess)
 {
-	uint8_t index = dev->driver_id;
-	void *sess_priv = get_asym_session_private_data(sess, index);
+	void *sess_priv = sess->sess_private_data;
 	struct qat_asym_session *s = (struct qat_asym_session *)sess_priv;
 
-	if (sess_priv) {
+	if (sess_priv)
 		memset(s, 0, qat_asym_session_get_private_size(dev));
-		struct rte_mempool *sess_mp = rte_mempool_from_obj(sess_priv);
-
-		set_asym_session_private_data(sess, index, NULL);
-		rte_mempool_put(sess_mp, sess_priv);
-	}
 }
diff --git a/drivers/crypto/qat/qat_asym.h b/drivers/crypto/qat/qat_asym.h
index 308b6b2e0b..c9242a12ca 100644
--- a/drivers/crypto/qat/qat_asym.h
+++ b/drivers/crypto/qat/qat_asym.h
@@ -46,10 +46,9 @@ struct qat_asym_session {
 };
 
 int
-qat_asym_session_configure(struct rte_cryptodev *dev,
+qat_asym_session_configure(struct rte_cryptodev *dev __rte_unused,
 		struct rte_crypto_asym_xform *xform,
-		struct rte_cryptodev_asym_session *sess,
-		struct rte_mempool *mempool);
+		struct rte_cryptodev_asym_session *sess);
 
 unsigned int
 qat_asym_session_get_private_size(struct rte_cryptodev *dev);
diff --git a/lib/cryptodev/cryptodev_pmd.h b/lib/cryptodev/cryptodev_pmd.h
index b9146f652c..142bfb7c66 100644
--- a/lib/cryptodev/cryptodev_pmd.h
+++ b/lib/cryptodev/cryptodev_pmd.h
@@ -319,7 +319,6 @@ typedef int (*cryptodev_sym_configure_session_t)(struct rte_cryptodev *dev,
  * @param	dev		Crypto device pointer
  * @param	xform		Single or chain of crypto xforms
  * @param	session		Pointer to cryptodev's private session structure
- * @param	mp		Mempool where the private session is allocated
  *
  * @return
  *  - Returns 0 if private session structure have been created successfully.
@@ -329,8 +328,7 @@ typedef int (*cryptodev_sym_configure_session_t)(struct rte_cryptodev *dev,
  */
 typedef int (*cryptodev_asym_configure_session_t)(struct rte_cryptodev *dev,
 		struct rte_crypto_asym_xform *xform,
-		struct rte_cryptodev_asym_session *session,
-		struct rte_mempool *mp);
+		struct rte_cryptodev_asym_session *session);
 /**
  * Free driver private session data.
  *
@@ -340,12 +338,12 @@ typedef int (*cryptodev_asym_configure_session_t)(struct rte_cryptodev *dev,
 typedef void (*cryptodev_sym_free_session_t)(struct rte_cryptodev *dev,
 		struct rte_cryptodev_sym_session *sess);
 /**
- * Free asymmetric session private data.
+ * Clear asymmetric session private data.
  *
  * @param	dev		Crypto device pointer
  * @param	sess		Cryptodev session structure
  */
-typedef void (*cryptodev_asym_free_session_t)(struct rte_cryptodev *dev,
+typedef void (*cryptodev_asym_clear_session_t)(struct rte_cryptodev *dev,
 		struct rte_cryptodev_asym_session *sess);
 /**
  * Perform actual crypto processing (encrypt/digest or auth/decrypt)
@@ -429,7 +427,7 @@ struct rte_cryptodev_ops {
 	/**< Configure asymmetric Crypto session. */
 	cryptodev_sym_free_session_t sym_session_clear;
 	/**< Clear a Crypto sessions private data. */
-	cryptodev_asym_free_session_t asym_session_clear;
+	cryptodev_asym_clear_session_t asym_session_clear;
 	/**< Clear a Crypto sessions private data. */
 	union {
 		cryptodev_sym_cpu_crypto_process_t sym_cpu_process;
@@ -627,17 +625,4 @@ set_sym_session_private_data(struct rte_cryptodev_sym_session *sess,
 	sess->sess_data[driver_id].data = private_data;
 }
 
-static inline void *
-get_asym_session_private_data(const struct rte_cryptodev_asym_session *sess,
-		uint8_t driver_id) {
-	return sess->sess_private_data[driver_id];
-}
-
-static inline void
-set_asym_session_private_data(struct rte_cryptodev_asym_session *sess,
-		uint8_t driver_id, void *private_data)
-{
-	sess->sess_private_data[driver_id] = private_data;
-}
-
 #endif /* _CRYPTODEV_PMD_H_ */
diff --git a/lib/cryptodev/cryptodev_trace_points.c b/lib/cryptodev/cryptodev_trace_points.c
index 5d58951fd5..c5bfe08b79 100644
--- a/lib/cryptodev/cryptodev_trace_points.c
+++ b/lib/cryptodev/cryptodev_trace_points.c
@@ -24,6 +24,9 @@ RTE_TRACE_POINT_REGISTER(rte_cryptodev_trace_queue_pair_setup,
 RTE_TRACE_POINT_REGISTER(rte_cryptodev_trace_sym_session_pool_create,
 	lib.cryptodev.sym.pool.create)
 
+RTE_TRACE_POINT_REGISTER(rte_cryptodev_trace_asym_session_pool_create,
+	lib.cryptodev.asym.pool.create)
+
 RTE_TRACE_POINT_REGISTER(rte_cryptodev_trace_sym_session_create,
 	lib.cryptodev.sym.create)
 
@@ -39,15 +42,9 @@ RTE_TRACE_POINT_REGISTER(rte_cryptodev_trace_asym_session_free,
 RTE_TRACE_POINT_REGISTER(rte_cryptodev_trace_sym_session_init,
 	lib.cryptodev.sym.init)
 
-RTE_TRACE_POINT_REGISTER(rte_cryptodev_trace_asym_session_init,
-	lib.cryptodev.asym.init)
-
 RTE_TRACE_POINT_REGISTER(rte_cryptodev_trace_sym_session_clear,
 	lib.cryptodev.sym.clear)
 
-RTE_TRACE_POINT_REGISTER(rte_cryptodev_trace_asym_session_clear,
-	lib.cryptodev.asym.clear)
-
 RTE_TRACE_POINT_REGISTER(rte_cryptodev_trace_enqueue_burst,
 	lib.cryptodev.enq.burst)
 
diff --git a/lib/cryptodev/rte_cryptodev.c b/lib/cryptodev/rte_cryptodev.c
index a40536c5ea..b056d88ac2 100644
--- a/lib/cryptodev/rte_cryptodev.c
+++ b/lib/cryptodev/rte_cryptodev.c
@@ -195,7 +195,7 @@ const char *rte_crypto_asym_op_strings[] = {
 };
 
 /**
- * The private data structure stored in the session mempool private data.
+ * The private data structure stored in the sym session mempool private data.
  */
 struct rte_cryptodev_sym_session_pool_private_data {
 	uint16_t nb_drivers;
@@ -204,6 +204,14 @@ struct rte_cryptodev_sym_session_pool_private_data {
 	/**< session user data will be placed after sess_data */
 };
 
+/**
+ * The private data structure stored in the asym session mempool private data.
+ */
+struct rte_cryptodev_asym_session_pool_private_data {
+	uint16_t max_priv_session_sz;
+	/**< Size of private session data used when creating mempool */
+};
+
 int
 rte_cryptodev_get_cipher_algo_enum(enum rte_crypto_cipher_algorithm *algo_enum,
 		const char *algo_string)
@@ -1751,47 +1759,6 @@ rte_cryptodev_sym_session_init(uint8_t dev_id,
 	return 0;
 }
 
-int
-rte_cryptodev_asym_session_init(uint8_t dev_id,
-		struct rte_cryptodev_asym_session *sess,
-		struct rte_crypto_asym_xform *xforms,
-		struct rte_mempool *mp)
-{
-	struct rte_cryptodev *dev;
-	uint8_t index;
-	int ret;
-
-	if (!rte_cryptodev_is_valid_dev(dev_id)) {
-		CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
-		return -EINVAL;
-	}
-
-	dev = rte_cryptodev_pmd_get_dev(dev_id);
-
-	if (sess == NULL || xforms == NULL || dev == NULL)
-		return -EINVAL;
-
-	index = dev->driver_id;
-
-	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->asym_session_configure,
-				-ENOTSUP);
-
-	if (sess->sess_private_data[index] == NULL) {
-		ret = dev->dev_ops->asym_session_configure(dev,
-							xforms,
-							sess, mp);
-		if (ret < 0) {
-			CDEV_LOG_ERR(
-				"dev_id %d failed to configure session details",
-				dev_id);
-			return ret;
-		}
-	}
-
-	rte_cryptodev_trace_asym_session_init(dev_id, sess, xforms, mp);
-	return 0;
-}
-
 struct rte_mempool *
 rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
 	uint32_t elt_size, uint32_t cache_size, uint16_t user_data_size,
@@ -1834,6 +1801,53 @@ rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
 	return mp;
 }
 
+struct rte_mempool *
+rte_cryptodev_asym_session_pool_create(const char *name, uint32_t nb_elts,
+	uint32_t cache_size, int socket_id)
+{
+	struct rte_mempool *mp;
+	struct rte_cryptodev_asym_session_pool_private_data *pool_priv;
+	uint32_t obj_sz, obj_sz_aligned;
+	uint8_t dev_id, priv_sz, max_priv_sz = 0;
+
+	for (dev_id = 0; dev_id < RTE_CRYPTO_MAX_DEVS; dev_id++)
+		if (rte_cryptodev_is_valid_dev(dev_id)) {
+			priv_sz = rte_cryptodev_asym_get_private_session_size(dev_id);
+			if (priv_sz > max_priv_sz)
+				max_priv_sz = priv_sz;
+		}
+	if (max_priv_sz == 0) {
+		CDEV_LOG_INFO("Could not set max private session size\n");
+		return NULL;
+	}
+
+	obj_sz = rte_cryptodev_asym_get_header_session_size() + max_priv_sz;
+	obj_sz_aligned =  RTE_ALIGN_CEIL(obj_sz, RTE_CACHE_LINE_SIZE);
+
+	mp = rte_mempool_create(name, nb_elts, obj_sz_aligned, cache_size,
+			(uint32_t)(sizeof(*pool_priv)),
+			NULL, NULL, NULL, NULL,
+			socket_id, 0);
+	if (mp == NULL) {
+		CDEV_LOG_ERR("%s(name=%s) failed, rte_errno=%d\n",
+			__func__, name, rte_errno);
+		return NULL;
+	}
+
+	pool_priv = rte_mempool_get_priv(mp);
+	if (!pool_priv) {
+		CDEV_LOG_ERR("%s(name=%s) failed to get private data\n",
+			__func__, name);
+		rte_mempool_free(mp);
+		return NULL;
+	}
+	pool_priv->max_priv_session_sz = max_priv_sz;
+
+	rte_cryptodev_trace_asym_session_pool_create(name, nb_elts,
+		cache_size, mp);
+	return mp;
+}
+
 static unsigned int
 rte_cryptodev_sym_session_data_size(struct rte_cryptodev_sym_session *sess)
 {
@@ -1895,19 +1909,44 @@ rte_cryptodev_sym_session_create(struct rte_mempool *mp)
 }
 
 struct rte_cryptodev_asym_session *
-rte_cryptodev_asym_session_create(struct rte_mempool *mp)
+rte_cryptodev_asym_session_create(uint8_t dev_id,
+		struct rte_crypto_asym_xform *xforms, struct rte_mempool *mp)
 {
 	struct rte_cryptodev_asym_session *sess;
-	unsigned int session_size =
+	uint32_t session_priv_data_sz;
+	struct rte_cryptodev_asym_session_pool_private_data *pool_priv;
+	unsigned int session_header_size =
 			rte_cryptodev_asym_get_header_session_size();
+	struct rte_cryptodev *dev;
+	int ret;
+
+	if (!rte_cryptodev_is_valid_dev(dev_id)) {
+		CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
+		return NULL;
+	}
+
+	dev = rte_cryptodev_pmd_get_dev(dev_id);
+
+	if (dev == NULL)
+		return NULL;
 
 	if (!mp) {
 		CDEV_LOG_ERR("invalid mempool\n");
 		return NULL;
 	}
 
+	session_priv_data_sz = rte_cryptodev_asym_get_private_session_size(
+			dev_id);
+	pool_priv = rte_mempool_get_priv(mp);
+
+	if (pool_priv->max_priv_session_sz < session_priv_data_sz) {
+		CDEV_LOG_DEBUG(
+			"The private session data size used when creating the mempool is smaller than this device's private session data.");
+		return NULL;
+	}
+
 	/* Verify if provided mempool can hold elements big enough. */
-	if (mp->elt_size < session_size) {
+	if (mp->elt_size < session_header_size + session_priv_data_sz) {
 		CDEV_LOG_ERR(
 			"mempool elements too small to hold session objects");
 		return NULL;
@@ -1919,12 +1958,25 @@ rte_cryptodev_asym_session_create(struct rte_mempool *mp)
 		return NULL;
 	}
 
-	/* Clear device session pointer.
-	 * Include the flag indicating presence of private data
-	 */
-	memset(sess, 0, session_size);
+	sess->driver_id = dev->driver_id;
+	sess->max_priv_data_sz = pool_priv->max_priv_session_sz;
+
+	/* Clear device session pointer.*/
+	memset(sess->sess_private_data, 0, session_priv_data_sz);
+
+	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->asym_session_configure, NULL);
 
-	rte_cryptodev_trace_asym_session_create(mp, sess);
+	if (sess->sess_private_data[0] == 0) {
+		ret = dev->dev_ops->asym_session_configure(dev, xforms, sess);
+		if (ret < 0) {
+			CDEV_LOG_ERR(
+				"dev_id %d failed to configure session details",
+				dev_id);
+			return NULL;
+		}
+	}
+
+	rte_cryptodev_trace_asym_session_create(dev_id, xforms, mp);
 	return sess;
 }
 
@@ -1959,30 +2011,6 @@ rte_cryptodev_sym_session_clear(uint8_t dev_id,
 	return 0;
 }
 
-int
-rte_cryptodev_asym_session_clear(uint8_t dev_id,
-		struct rte_cryptodev_asym_session *sess)
-{
-	struct rte_cryptodev *dev;
-
-	if (!rte_cryptodev_is_valid_dev(dev_id)) {
-		CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
-		return -EINVAL;
-	}
-
-	dev = rte_cryptodev_pmd_get_dev(dev_id);
-
-	if (dev == NULL || sess == NULL)
-		return -EINVAL;
-
-	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->asym_session_clear, -ENOTSUP);
-
-	dev->dev_ops->asym_session_clear(dev, sess);
-
-	rte_cryptodev_trace_sym_session_clear(dev_id, sess);
-	return 0;
-}
-
 int
 rte_cryptodev_sym_session_free(struct rte_cryptodev_sym_session *sess)
 {
@@ -2007,27 +2035,31 @@ rte_cryptodev_sym_session_free(struct rte_cryptodev_sym_session *sess)
 }
 
 int
-rte_cryptodev_asym_session_free(struct rte_cryptodev_asym_session *sess)
+rte_cryptodev_asym_session_free(uint8_t dev_id,
+		struct rte_cryptodev_asym_session *sess)
 {
-	uint8_t i;
-	void *sess_priv;
 	struct rte_mempool *sess_mp;
+	struct rte_cryptodev *dev;
 
-	if (sess == NULL)
+	if (!rte_cryptodev_is_valid_dev(dev_id)) {
+		CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
 		return -EINVAL;
-
-	/* Check that all device private data has been freed */
-	for (i = 0; i < nb_drivers; i++) {
-		sess_priv = get_asym_session_private_data(sess, i);
-		if (sess_priv != NULL)
-			return -EBUSY;
 	}
 
+	dev = rte_cryptodev_pmd_get_dev(dev_id);
+
+	if (dev == NULL || sess == NULL)
+		return -EINVAL;
+
+	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->asym_session_clear, -ENOTSUP);
+
+	dev->dev_ops->asym_session_clear(dev, sess);
+
 	/* Return session to mempool */
 	sess_mp = rte_mempool_from_obj(sess);
 	rte_mempool_put(sess_mp, sess);
 
-	rte_cryptodev_trace_asym_session_free(sess);
+	rte_cryptodev_trace_asym_session_free(dev_id, sess);
 	return 0;
 }
 
@@ -2061,12 +2093,7 @@ rte_cryptodev_sym_get_existing_header_session_size(
 unsigned int
 rte_cryptodev_asym_get_header_session_size(void)
 {
-	/*
-	 * Header contains pointers to the private data
-	 * of all registered drivers, and a flag which
-	 * indicates presence of private data
-	 */
-	return ((sizeof(void *) * nb_drivers) + sizeof(uint8_t));
+	return sizeof(struct rte_cryptodev_asym_session);
 }
 
 unsigned int
@@ -2092,7 +2119,6 @@ unsigned int
 rte_cryptodev_asym_get_private_session_size(uint8_t dev_id)
 {
 	struct rte_cryptodev *dev;
-	unsigned int header_size = sizeof(void *) * nb_drivers;
 	unsigned int priv_sess_size;
 
 	if (!rte_cryptodev_is_valid_dev(dev_id))
@@ -2104,11 +2130,8 @@ rte_cryptodev_asym_get_private_session_size(uint8_t dev_id)
 		return 0;
 
 	priv_sess_size = (*dev->dev_ops->asym_session_get_size)(dev);
-	if (priv_sess_size < header_size)
-		return header_size;
 
 	return priv_sess_size;
-
 }
 
 int
diff --git a/lib/cryptodev/rte_cryptodev.h b/lib/cryptodev/rte_cryptodev.h
index 59ea5a54df..90e764017d 100644
--- a/lib/cryptodev/rte_cryptodev.h
+++ b/lib/cryptodev/rte_cryptodev.h
@@ -919,9 +919,13 @@ struct rte_cryptodev_sym_session {
 };
 
 /** Cryptodev asymmetric crypto session */
-struct rte_cryptodev_asym_session {
-	__extension__ void *sess_private_data[0];
-	/**< Private asymmetric session material */
+RTE_STD_C11 struct rte_cryptodev_asym_session {
+	uint8_t driver_id;
+	/**< Session driver ID. */
+	uint16_t max_priv_data_sz;
+	/**< Size of private data used when creating mempool */
+	uint8_t padding[5];
+	uint8_t sess_private_data[0];
 };
 
 /**
@@ -956,6 +960,29 @@ rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
 	uint32_t elt_size, uint32_t cache_size, uint16_t priv_size,
 	int socket_id);
 
+/**
+ * Create an asymmetric session mempool.
+ *
+ * @param name
+ *   The unique mempool name.
+ * @param nb_elts
+ *   The number of elements in the mempool.
+ * @param cache_size
+ *   The number of per-lcore cache elements
+ * @param socket_id
+ *   The *socket_id* argument is the socket identifier in the case of
+ *   NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA
+ *   constraint for the reserved zone.
+ *
+ * @return
+ *  - On success return mempool
+ *  - On failure returns NULL
+ */
+__rte_experimental
+struct rte_mempool *
+rte_cryptodev_asym_session_pool_create(const char *name, uint32_t nb_elts,
+	uint32_t cache_size, int socket_id);
+
 /**
  * Create symmetric crypto session header (generic with no private data)
  *
@@ -969,17 +996,22 @@ struct rte_cryptodev_sym_session *
 rte_cryptodev_sym_session_create(struct rte_mempool *mempool);
 
 /**
- * Create asymmetric crypto session header (generic with no private data)
+ * Create and initialise an asymmetric crypto session structure.
+ * Calls the PMD to configure the private session data.
  *
- * @param   mempool    mempool to allocate asymmetric session
- *                     objects from
+ * @param   dev_id   ID of device that we want the session to be used on
+ * @param   xforms   Asymmetric crypto transform operations to apply on flow
+ *                   processed with this session
+ * @param   mp       mempool to allocate asymmetric session
+ *                   objects from
  * @return
  *  - On success return pointer to asym-session
  *  - On failure returns NULL
  */
 __rte_experimental
 struct rte_cryptodev_asym_session *
-rte_cryptodev_asym_session_create(struct rte_mempool *mempool);
+rte_cryptodev_asym_session_create(uint8_t dev_id,
+		struct rte_crypto_asym_xform *xforms, struct rte_mempool *mp);
 
 /**
  * Frees symmetric crypto session header, after checking that all
@@ -997,20 +1029,20 @@ int
 rte_cryptodev_sym_session_free(struct rte_cryptodev_sym_session *sess);
 
 /**
- * Frees asymmetric crypto session header, after checking that all
- * the device private data has been freed, returning it
- * to its original mempool.
+ * Clears and frees asymmetric crypto session header and private data,
+ * returning it to its original mempool.
  *
+ * @param   dev_id   ID of device that uses the asymmetric session.
  * @param   sess     Session header to be freed.
  *
  * @return
  *  - 0 if successful.
- *  - -EINVAL if session is NULL.
- *  - -EBUSY if not all device private data has been freed.
+ *  - -EINVAL if device is invalid or session is NULL.
  */
 __rte_experimental
 int
-rte_cryptodev_asym_session_free(struct rte_cryptodev_asym_session *sess);
+rte_cryptodev_asym_session_free(uint8_t dev_id,
+		struct rte_cryptodev_asym_session *sess);
 
 /**
  * Fill out private data for the device id, based on its device type.
@@ -1034,28 +1066,6 @@ rte_cryptodev_sym_session_init(uint8_t dev_id,
 			struct rte_crypto_sym_xform *xforms,
 			struct rte_mempool *mempool);
 
-/**
- * Initialize asymmetric session on a device with specific asymmetric xform
- *
- * @param   dev_id   ID of device that we want the session to be used on
- * @param   sess     Session to be set up on a device
- * @param   xforms   Asymmetric crypto transform operations to apply on flow
- *                   processed with this session
- * @param   mempool  Mempool to be used for internal allocation.
- *
- * @return
- *  - On success, zero.
- *  - -EINVAL if input parameters are invalid.
- *  - -ENOTSUP if crypto device does not support the crypto transform.
- *  - -ENOMEM if the private session could not be allocated.
- */
-__rte_experimental
-int
-rte_cryptodev_asym_session_init(uint8_t dev_id,
-			struct rte_cryptodev_asym_session *sess,
-			struct rte_crypto_asym_xform *xforms,
-			struct rte_mempool *mempool);
-
 /**
  * Frees private data for the device id, based on its device type,
  * returning it to its mempool. It is the application's responsibility
@@ -1074,21 +1084,6 @@ int
 rte_cryptodev_sym_session_clear(uint8_t dev_id,
 			struct rte_cryptodev_sym_session *sess);
 
-/**
- * Frees resources held by asymmetric session during rte_cryptodev_session_init
- *
- * @param   dev_id   ID of device that uses the asymmetric session.
- * @param   sess     Asymmetric session setup on device using
- *					 rte_cryptodev_session_init
- * @return
- *  - 0 if successful.
- *  - -EINVAL if device is invalid or session is NULL.
- */
-__rte_experimental
-int
-rte_cryptodev_asym_session_clear(uint8_t dev_id,
-			struct rte_cryptodev_asym_session *sess);
-
 /**
  * Get the size of the header session, for all registered drivers excluding
  * the user data size.
@@ -1116,7 +1111,7 @@ rte_cryptodev_sym_get_existing_header_session_size(
 		struct rte_cryptodev_sym_session *sess);
 
 /**
- * Get the size of the asymmetric session header, for all registered drivers.
+ * Get the size of the asymmetric session header.
  *
  * @return
  *   Size of the asymmetric header session.
diff --git a/lib/cryptodev/rte_cryptodev_trace.h b/lib/cryptodev/rte_cryptodev_trace.h
index d1f4f069a3..a4fa9e8c7e 100644
--- a/lib/cryptodev/rte_cryptodev_trace.h
+++ b/lib/cryptodev/rte_cryptodev_trace.h
@@ -83,12 +83,22 @@ RTE_TRACE_POINT(
 	rte_trace_point_emit_u16(sess->user_data_sz);
 )
 
+RTE_TRACE_POINT(
+	rte_cryptodev_trace_asym_session_pool_create,
+	RTE_TRACE_POINT_ARGS(const char *name, uint32_t nb_elts,
+		uint32_t cache_size, void *mempool),
+	rte_trace_point_emit_string(name);
+	rte_trace_point_emit_u32(nb_elts);
+	rte_trace_point_emit_u32(cache_size);
+	rte_trace_point_emit_ptr(mempool);
+)
+
 RTE_TRACE_POINT(
 	rte_cryptodev_trace_asym_session_create,
-	RTE_TRACE_POINT_ARGS(void *mempool,
-		struct rte_cryptodev_asym_session *sess),
+	RTE_TRACE_POINT_ARGS(uint8_t dev_id, void *xforms, void *mempool),
+	rte_trace_point_emit_u8(dev_id);
+	rte_trace_point_emit_ptr(xforms);
 	rte_trace_point_emit_ptr(mempool);
-	rte_trace_point_emit_ptr(sess);
 )
 
 RTE_TRACE_POINT(
@@ -99,7 +109,9 @@ RTE_TRACE_POINT(
 
 RTE_TRACE_POINT(
 	rte_cryptodev_trace_asym_session_free,
-	RTE_TRACE_POINT_ARGS(struct rte_cryptodev_asym_session *sess),
+	RTE_TRACE_POINT_ARGS(uint8_t dev_id,
+		struct rte_cryptodev_asym_session *sess),
+	rte_trace_point_emit_u8(dev_id);
 	rte_trace_point_emit_ptr(sess);
 )
 
@@ -117,17 +129,6 @@ RTE_TRACE_POINT(
 	rte_trace_point_emit_ptr(mempool);
 )
 
-RTE_TRACE_POINT(
-	rte_cryptodev_trace_asym_session_init,
-	RTE_TRACE_POINT_ARGS(uint8_t dev_id,
-		struct rte_cryptodev_asym_session *sess, void *xforms,
-		void *mempool),
-	rte_trace_point_emit_u8(dev_id);
-	rte_trace_point_emit_ptr(sess);
-	rte_trace_point_emit_ptr(xforms);
-	rte_trace_point_emit_ptr(mempool);
-)
-
 RTE_TRACE_POINT(
 	rte_cryptodev_trace_sym_session_clear,
 	RTE_TRACE_POINT_ARGS(uint8_t dev_id, void *sess),
@@ -135,13 +136,6 @@ RTE_TRACE_POINT(
 	rte_trace_point_emit_ptr(sess);
 )
 
-RTE_TRACE_POINT(
-	rte_cryptodev_trace_asym_session_clear,
-	RTE_TRACE_POINT_ARGS(uint8_t dev_id, void *sess),
-	rte_trace_point_emit_u8(dev_id);
-	rte_trace_point_emit_ptr(sess);
-)
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/cryptodev/version.map b/lib/cryptodev/version.map
index c50745fa8c..44d1aff0e2 100644
--- a/lib/cryptodev/version.map
+++ b/lib/cryptodev/version.map
@@ -55,10 +55,8 @@ EXPERIMENTAL {
 	rte_cryptodev_asym_get_header_session_size;
 	rte_cryptodev_asym_get_private_session_size;
 	rte_cryptodev_asym_get_xform_enum;
-	rte_cryptodev_asym_session_clear;
 	rte_cryptodev_asym_session_create;
 	rte_cryptodev_asym_session_free;
-	rte_cryptodev_asym_session_init;
 	rte_cryptodev_asym_xform_capability_check_modlen;
 	rte_cryptodev_asym_xform_capability_check_optype;
 	rte_cryptodev_sym_cpu_crypto_process;
@@ -81,9 +79,7 @@ EXPERIMENTAL {
 	__rte_cryptodev_trace_sym_session_free;
 	__rte_cryptodev_trace_asym_session_free;
 	__rte_cryptodev_trace_sym_session_init;
-	__rte_cryptodev_trace_asym_session_init;
 	__rte_cryptodev_trace_sym_session_clear;
-	__rte_cryptodev_trace_asym_session_clear;
 	__rte_cryptodev_trace_dequeue_burst;
 	__rte_cryptodev_trace_enqueue_burst;
 
@@ -104,6 +100,9 @@ EXPERIMENTAL {
 	rte_cryptodev_remove_deq_callback;
 	rte_cryptodev_remove_enq_callback;
 
+	# added 22.03
+	rte_cryptodev_asym_session_pool_create;
+	__rte_cryptodev_trace_asym_session_pool_create;
 };
 
 INTERNAL {
-- 
2.25.1


^ permalink raw reply	[flat|nested] 31+ messages in thread

* [PATCH v7 3/5] crypto: hide asym session structure
  2022-02-11  9:29 ` [PATCH v7 " Ciara Power
  2022-02-11  9:29   ` [PATCH v7 1/5] doc: replace asym crypto code with literal includes Ciara Power
  2022-02-11  9:29   ` [PATCH v7 2/5] crypto: use single buffer for asymmetric session Ciara Power
@ 2022-02-11  9:29   ` Ciara Power
  2022-02-11  9:29   ` [PATCH v7 4/5] crypto: add asym session user data API Ciara Power
                     ` (2 subsequent siblings)
  5 siblings, 0 replies; 31+ messages in thread
From: Ciara Power @ 2022-02-11  9:29 UTC (permalink / raw)
  To: dev; +Cc: roy.fan.zhang, gakhil, anoobj, mdr, Ciara Power, Declan Doherty

The rte_cryptodev_asym_session structure is now moved to an internal
header. This will no longer be used directly by apps,
private session data can be accessed via get API.

Signed-off-by: Ciara Power <ciara.power@intel.com>
Acked-by: Fan Zhang <roy.fan.zhang@intel.com>
Acked-by: Anoob Joseph <anoobj@marvell.com>

---
v4:
  - Initialised session variables as NULL.
  - Removed docs code additions, these are included due to patch 1
    changing sample doc to use literal includes.
v3:
  - Removed the incorrect use of void * for asym session in drivers,
    these are internal and can use the struct directly as before.
  - Fixed other internal functions and comments that were incorrectly
    changed to use void *sess.
  - Added documentation.
---
 app/test-crypto-perf/cperf_ops.c        |  2 +-
 app/test/test_cryptodev_asym.c          | 34 ++++++++++++-------------
 doc/guides/prog_guide/cryptodev_lib.rst |  4 +++
 doc/guides/rel_notes/release_22_03.rst  |  2 ++
 lib/cryptodev/cryptodev_pmd.h           | 13 ++++++++++
 lib/cryptodev/rte_cryptodev.c           |  5 ++--
 lib/cryptodev/rte_cryptodev.h           | 15 ++---------
 lib/cryptodev/rte_cryptodev_trace.h     |  3 +--
 8 files changed, 42 insertions(+), 36 deletions(-)

diff --git a/app/test-crypto-perf/cperf_ops.c b/app/test-crypto-perf/cperf_ops.c
index b125c699de..b8f590b397 100644
--- a/app/test-crypto-perf/cperf_ops.c
+++ b/app/test-crypto-perf/cperf_ops.c
@@ -21,7 +21,7 @@ cperf_set_ops_asym(struct rte_crypto_op **ops,
 		   uint64_t *tsc_start __rte_unused)
 {
 	uint16_t i;
-	struct rte_cryptodev_asym_session *asym_sess = (void *)sess;
+	void *asym_sess = (void *)sess;
 
 	for (i = 0; i < nb_ops; i++) {
 		struct rte_crypto_asym_op *asym_op = ops[i]->asym;
diff --git a/app/test/test_cryptodev_asym.c b/app/test/test_cryptodev_asym.c
index 88433faf1c..929d6efb24 100644
--- a/app/test/test_cryptodev_asym.c
+++ b/app/test/test_cryptodev_asym.c
@@ -46,7 +46,7 @@ struct crypto_testsuite_params_asym {
 };
 
 struct crypto_unittest_params {
-	struct rte_cryptodev_asym_session *sess;
+	void *sess;
 	struct rte_crypto_op *op;
 };
 
@@ -67,7 +67,7 @@ static uint32_t test_index;
 static struct crypto_testsuite_params_asym testsuite_params = { NULL };
 
 static int
-queue_ops_rsa_sign_verify(struct rte_cryptodev_asym_session *sess)
+queue_ops_rsa_sign_verify(void *sess)
 {
 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
 	struct rte_mempool *op_mpool = ts_params->op_mpool;
@@ -158,7 +158,7 @@ queue_ops_rsa_sign_verify(struct rte_cryptodev_asym_session *sess)
 }
 
 static int
-queue_ops_rsa_enc_dec(struct rte_cryptodev_asym_session *sess)
+queue_ops_rsa_enc_dec(void *sess)
 {
 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
 	struct rte_mempool *op_mpool = ts_params->op_mpool;
@@ -310,7 +310,7 @@ test_cryptodev_asym_op(struct crypto_testsuite_params_asym *ts_params,
 	struct rte_crypto_op *op = NULL;
 	struct rte_crypto_op *result_op = NULL;
 	struct rte_crypto_asym_xform xform_tc;
-	struct rte_cryptodev_asym_session *sess = NULL;
+	void *sess = NULL;
 	struct rte_cryptodev_asym_capability_idx cap_idx;
 	const struct rte_cryptodev_asymmetric_xform_capability *capability;
 	uint8_t dev_id = ts_params->valid_devs[0];
@@ -644,7 +644,7 @@ test_rsa_sign_verify(void)
 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
 	uint8_t dev_id = ts_params->valid_devs[0];
-	struct rte_cryptodev_asym_session *sess;
+	void *sess = NULL;
 	struct rte_cryptodev_info dev_info;
 	int status = TEST_SUCCESS;
 
@@ -684,7 +684,7 @@ test_rsa_enc_dec(void)
 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
 	uint8_t dev_id = ts_params->valid_devs[0];
-	struct rte_cryptodev_asym_session *sess;
+	void *sess = NULL;
 	struct rte_cryptodev_info dev_info;
 	int status = TEST_SUCCESS;
 
@@ -724,7 +724,7 @@ test_rsa_sign_verify_crt(void)
 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
 	uint8_t dev_id = ts_params->valid_devs[0];
-	struct rte_cryptodev_asym_session *sess;
+	void *sess = NULL;
 	struct rte_cryptodev_info dev_info;
 	int status = TEST_SUCCESS;
 
@@ -764,7 +764,7 @@ test_rsa_enc_dec_crt(void)
 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
 	uint8_t dev_id = ts_params->valid_devs[0];
-	struct rte_cryptodev_asym_session *sess;
+	void *sess = NULL;
 	struct rte_cryptodev_info dev_info;
 	int status = TEST_SUCCESS;
 
@@ -1046,7 +1046,7 @@ test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
 	uint8_t dev_id = ts_params->valid_devs[0];
 	struct rte_crypto_asym_op *asym_op = NULL;
 	struct rte_crypto_op *op = NULL, *result_op = NULL;
-	struct rte_cryptodev_asym_session *sess = NULL;
+	void *sess = NULL;
 	int status = TEST_SUCCESS;
 	uint8_t output[TEST_DH_MOD_LEN];
 	struct rte_crypto_asym_xform xform = *xfrm;
@@ -1129,7 +1129,7 @@ test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
 	uint8_t dev_id = ts_params->valid_devs[0];
 	struct rte_crypto_asym_op *asym_op = NULL;
 	struct rte_crypto_op *op = NULL, *result_op = NULL;
-	struct rte_cryptodev_asym_session *sess = NULL;
+	void *sess = NULL;
 	int status = TEST_SUCCESS;
 	uint8_t output[TEST_DH_MOD_LEN];
 	struct rte_crypto_asym_xform xform = *xfrm;
@@ -1210,7 +1210,7 @@ test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
 	uint8_t dev_id = ts_params->valid_devs[0];
 	struct rte_crypto_asym_op *asym_op = NULL;
 	struct rte_crypto_op *op = NULL, *result_op = NULL;
-	struct rte_cryptodev_asym_session *sess = NULL;
+	void *sess = NULL;
 	int status = TEST_SUCCESS;
 	uint8_t output[TEST_DH_MOD_LEN];
 	struct rte_crypto_asym_xform xform = *xfrm;
@@ -1299,7 +1299,7 @@ test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
 	uint8_t dev_id = ts_params->valid_devs[0];
 	struct rte_crypto_asym_op *asym_op = NULL;
 	struct rte_crypto_op *op = NULL, *result_op = NULL;
-	struct rte_cryptodev_asym_session *sess = NULL;
+	void *sess = NULL;
 	int status = TEST_SUCCESS;
 	uint8_t out_pub_key[TEST_DH_MOD_LEN];
 	uint8_t out_prv_key[TEST_DH_MOD_LEN];
@@ -1386,7 +1386,7 @@ test_mod_inv(void)
 	uint8_t dev_id = ts_params->valid_devs[0];
 	struct rte_crypto_asym_op *asym_op = NULL;
 	struct rte_crypto_op *op = NULL, *result_op = NULL;
-	struct rte_cryptodev_asym_session *sess = NULL;
+	void *sess = NULL;
 	int status = TEST_SUCCESS;
 	struct rte_cryptodev_asym_capability_idx cap_idx;
 	const struct rte_cryptodev_asymmetric_xform_capability *capability;
@@ -1499,7 +1499,7 @@ test_mod_exp(void)
 	uint8_t dev_id = ts_params->valid_devs[0];
 	struct rte_crypto_asym_op *asym_op = NULL;
 	struct rte_crypto_op *op = NULL, *result_op = NULL;
-	struct rte_cryptodev_asym_session *sess = NULL;
+	void *sess = NULL;
 	int status = TEST_SUCCESS;
 	struct rte_cryptodev_asym_capability_idx cap_idx;
 	const struct rte_cryptodev_asymmetric_xform_capability *capability;
@@ -1648,7 +1648,7 @@ test_dsa_sign(void)
 	uint8_t dev_id = ts_params->valid_devs[0];
 	struct rte_crypto_asym_op *asym_op = NULL;
 	struct rte_crypto_op *op = NULL, *result_op = NULL;
-	struct rte_cryptodev_asym_session *sess = NULL;
+	void *sess = NULL;
 	int status = TEST_SUCCESS;
 	uint8_t r[TEST_DH_MOD_LEN];
 	uint8_t s[TEST_DH_MOD_LEN];
@@ -1779,7 +1779,7 @@ test_ecdsa_sign_verify(enum curve curve_id)
 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
 	struct rte_mempool *op_mpool = ts_params->op_mpool;
 	struct crypto_testsuite_ecdsa_params input_params;
-	struct rte_cryptodev_asym_session *sess = NULL;
+	void *sess = NULL;
 	uint8_t dev_id = ts_params->valid_devs[0];
 	struct rte_crypto_op *result_op = NULL;
 	uint8_t output_buf_r[TEST_DATA_SIZE];
@@ -1981,7 +1981,7 @@ test_ecpm(enum curve curve_id)
 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
 	struct rte_mempool *op_mpool = ts_params->op_mpool;
 	struct crypto_testsuite_ecpm_params input_params;
-	struct rte_cryptodev_asym_session *sess = NULL;
+	void *sess = NULL;
 	uint8_t dev_id = ts_params->valid_devs[0];
 	struct rte_crypto_op *result_op = NULL;
 	uint8_t output_buf_x[TEST_DATA_SIZE];
diff --git a/doc/guides/prog_guide/cryptodev_lib.rst b/doc/guides/prog_guide/cryptodev_lib.rst
index b4dbd384bf..2607a9a7d7 100644
--- a/doc/guides/prog_guide/cryptodev_lib.rst
+++ b/doc/guides/prog_guide/cryptodev_lib.rst
@@ -1155,6 +1155,10 @@ Generate crypto op, create and attach a session, then process packets.
    :end-before: >8 End of create op, create session, and process packets section.
    :dedent: 1
 
+.. note::
+   The ``rte_cryptodev_asym_session`` struct is hidden from the application.
+   The ``sess`` pointer used above is a void pointer.
+
 
 Asymmetric Crypto Device API
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
diff --git a/doc/guides/rel_notes/release_22_03.rst b/doc/guides/rel_notes/release_22_03.rst
index ea4c5309a0..459b15bdde 100644
--- a/doc/guides/rel_notes/release_22_03.rst
+++ b/doc/guides/rel_notes/release_22_03.rst
@@ -116,6 +116,8 @@ API Changes
   mempool object. An API ``rte_cryptodev_asym_session_pool_create`` was added
   to create a mempool with element size big enough to hold the generic asymmetric
   session header and max size for a device private session data.
+  The session structure was moved to ``cryptodev_pmd.h``,
+  hiding it from applications.
   The API ``rte_cryptodev_asym_session_init`` was removed as the initialization
   is now moved to ``rte_cryptodev_asym_session_create``.
 
diff --git a/lib/cryptodev/cryptodev_pmd.h b/lib/cryptodev/cryptodev_pmd.h
index 142bfb7c66..63f9cf5427 100644
--- a/lib/cryptodev/cryptodev_pmd.h
+++ b/lib/cryptodev/cryptodev_pmd.h
@@ -625,4 +625,17 @@ set_sym_session_private_data(struct rte_cryptodev_sym_session *sess,
 	sess->sess_data[driver_id].data = private_data;
 }
 
+/**
+ * @internal
+ * Cryptodev asymmetric crypto session.
+ */
+RTE_STD_C11 struct rte_cryptodev_asym_session {
+	uint8_t driver_id;
+	/**< Session driver ID. */
+	uint16_t max_priv_data_sz;
+	/**< Size of private data used when creating mempool */
+	uint8_t padding[5];
+	uint8_t sess_private_data[0];
+};
+
 #endif /* _CRYPTODEV_PMD_H_ */
diff --git a/lib/cryptodev/rte_cryptodev.c b/lib/cryptodev/rte_cryptodev.c
index b056d88ac2..562cb4a2c4 100644
--- a/lib/cryptodev/rte_cryptodev.c
+++ b/lib/cryptodev/rte_cryptodev.c
@@ -1908,7 +1908,7 @@ rte_cryptodev_sym_session_create(struct rte_mempool *mp)
 	return sess;
 }
 
-struct rte_cryptodev_asym_session *
+void *
 rte_cryptodev_asym_session_create(uint8_t dev_id,
 		struct rte_crypto_asym_xform *xforms, struct rte_mempool *mp)
 {
@@ -2035,8 +2035,7 @@ rte_cryptodev_sym_session_free(struct rte_cryptodev_sym_session *sess)
 }
 
 int
-rte_cryptodev_asym_session_free(uint8_t dev_id,
-		struct rte_cryptodev_asym_session *sess)
+rte_cryptodev_asym_session_free(uint8_t dev_id, void *sess)
 {
 	struct rte_mempool *sess_mp;
 	struct rte_cryptodev *dev;
diff --git a/lib/cryptodev/rte_cryptodev.h b/lib/cryptodev/rte_cryptodev.h
index 90e764017d..4cf3f6c9d7 100644
--- a/lib/cryptodev/rte_cryptodev.h
+++ b/lib/cryptodev/rte_cryptodev.h
@@ -918,16 +918,6 @@ struct rte_cryptodev_sym_session {
 	/**< Driver specific session material, variable size */
 };
 
-/** Cryptodev asymmetric crypto session */
-RTE_STD_C11 struct rte_cryptodev_asym_session {
-	uint8_t driver_id;
-	/**< Session driver ID. */
-	uint16_t max_priv_data_sz;
-	/**< Size of private data used when creating mempool */
-	uint8_t padding[5];
-	uint8_t sess_private_data[0];
-};
-
 /**
  * Create a symmetric session mempool.
  *
@@ -1009,7 +999,7 @@ rte_cryptodev_sym_session_create(struct rte_mempool *mempool);
  *  - On failure returns NULL
  */
 __rte_experimental
-struct rte_cryptodev_asym_session *
+void *
 rte_cryptodev_asym_session_create(uint8_t dev_id,
 		struct rte_crypto_asym_xform *xforms, struct rte_mempool *mp);
 
@@ -1041,8 +1031,7 @@ rte_cryptodev_sym_session_free(struct rte_cryptodev_sym_session *sess);
  */
 __rte_experimental
 int
-rte_cryptodev_asym_session_free(uint8_t dev_id,
-		struct rte_cryptodev_asym_session *sess);
+rte_cryptodev_asym_session_free(uint8_t dev_id, void *sess);
 
 /**
  * Fill out private data for the device id, based on its device type.
diff --git a/lib/cryptodev/rte_cryptodev_trace.h b/lib/cryptodev/rte_cryptodev_trace.h
index a4fa9e8c7e..4b48c66199 100644
--- a/lib/cryptodev/rte_cryptodev_trace.h
+++ b/lib/cryptodev/rte_cryptodev_trace.h
@@ -109,8 +109,7 @@ RTE_TRACE_POINT(
 
 RTE_TRACE_POINT(
 	rte_cryptodev_trace_asym_session_free,
-	RTE_TRACE_POINT_ARGS(uint8_t dev_id,
-		struct rte_cryptodev_asym_session *sess),
+	RTE_TRACE_POINT_ARGS(uint8_t dev_id, void *sess),
 	rte_trace_point_emit_u8(dev_id);
 	rte_trace_point_emit_ptr(sess);
 )
-- 
2.25.1


^ permalink raw reply	[flat|nested] 31+ messages in thread

* [PATCH v7 4/5] crypto: add asym session user data API
  2022-02-11  9:29 ` [PATCH v7 " Ciara Power
                     ` (2 preceding siblings ...)
  2022-02-11  9:29   ` [PATCH v7 3/5] crypto: hide asym session structure Ciara Power
@ 2022-02-11  9:29   ` Ciara Power
  2022-02-11  9:29   ` [PATCH v7 5/5] crypto: modify return value for asym session create Ciara Power
  2022-02-11 14:29   ` [EXT] [PATCH v7 0/5] crypto: improve asym session usage Akhil Goyal
  5 siblings, 0 replies; 31+ messages in thread
From: Ciara Power @ 2022-02-11  9:29 UTC (permalink / raw)
  To: dev; +Cc: roy.fan.zhang, gakhil, anoobj, mdr, Ciara Power, Declan Doherty

A user data field is added to the asymmetric session structure.
Relevant API added to get/set the field.

Signed-off-by: Ciara Power <ciara.power@intel.com>
Acked-by: Fan Zhang <roy.fan.zhang@intel.com>
Acked-by: Anoob Joseph <anoobj@marvell.com>

---
v4:
  - Reworded release notes.
  - Added possible error return values in function comment.
  - Removed docs code additions, these are included due to patch 1
    changing sample doc to use literal includes.
v3:
  - Corrected formatting of struct comments.
  - Added setting user data size in pool creation.
  - Added documentation.
v2: Corrected order of version map entries.
---
 app/test-crypto-perf/main.c             |  2 +-
 app/test/test_cryptodev_asym.c          |  2 +-
 doc/guides/prog_guide/cryptodev_lib.rst | 19 ++++++++++++
 doc/guides/rel_notes/release_22_03.rst  |  6 +++-
 lib/cryptodev/cryptodev_pmd.h           |  4 ++-
 lib/cryptodev/rte_cryptodev.c           | 40 ++++++++++++++++++++++---
 lib/cryptodev/rte_cryptodev.h           | 35 +++++++++++++++++++++-
 lib/cryptodev/rte_cryptodev_trace.h     |  3 +-
 lib/cryptodev/version.map               |  2 ++
 9 files changed, 103 insertions(+), 10 deletions(-)

diff --git a/app/test-crypto-perf/main.c b/app/test-crypto-perf/main.c
index 2531de43a2..35a1193525 100644
--- a/app/test-crypto-perf/main.c
+++ b/app/test-crypto-perf/main.c
@@ -78,7 +78,7 @@ create_asym_op_pool_socket(int32_t socket_id, uint32_t nb_sessions)
 		snprintf(mp_name, RTE_MEMPOOL_NAMESIZE, "perf_asym_sess_pool%u",
 			 socket_id);
 		mpool = rte_cryptodev_asym_session_pool_create(mp_name,
-				nb_sessions, 0, socket_id);
+				nb_sessions, 0, 0, socket_id);
 		if (mpool == NULL) {
 			printf("Cannot create pool \"%s\" on socket %d\n",
 			       mp_name, socket_id);
diff --git a/app/test/test_cryptodev_asym.c b/app/test/test_cryptodev_asym.c
index 929d6efb24..f0cb839a49 100644
--- a/app/test/test_cryptodev_asym.c
+++ b/app/test/test_cryptodev_asym.c
@@ -894,7 +894,7 @@ testsuite_setup(void)
 	}
 
 	ts_params->session_mpool = rte_cryptodev_asym_session_pool_create(
-			"test_asym_sess_mp", TEST_NUM_SESSIONS, 0,
+			"test_asym_sess_mp", TEST_NUM_SESSIONS, 0, 0,
 			SOCKET_ID_ANY);
 
 	TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
diff --git a/doc/guides/prog_guide/cryptodev_lib.rst b/doc/guides/prog_guide/cryptodev_lib.rst
index 2607a9a7d7..ba4c592b84 100644
--- a/doc/guides/prog_guide/cryptodev_lib.rst
+++ b/doc/guides/prog_guide/cryptodev_lib.rst
@@ -1110,6 +1110,25 @@ They operate on data buffer of type ``rte_crypto_param``.
 
 See *DPDK API Reference* for details on each rte_crypto_xxx_op_param struct
 
+Private user data
+~~~~~~~~~~~~~~~~~
+
+Similar to symmetric above, asymmetric also has a set and get API that provides a
+mechanism for an application to store and retrieve the private user data information
+stored along with the crypto session.
+
+.. code-block:: c
+
+	int rte_cryptodev_asym_session_set_user_data(void *sess,
+		void *data, uint16_t size);
+
+	void * rte_cryptodev_asym_session_get_user_data(void *sess);
+
+Please note the ``size`` passed to set API cannot be bigger than the predefined
+``user_data_sz`` when creating the session mempool, otherwise the function will
+return an error. Also when ``user_data_sz`` was defined as ``0`` when
+creating the session mempool, the get API will always return ``NULL``.
+
 Asymmetric crypto Sample code
 -----------------------------
 
diff --git a/doc/guides/rel_notes/release_22_03.rst b/doc/guides/rel_notes/release_22_03.rst
index 459b15bdde..a930cbbad6 100644
--- a/doc/guides/rel_notes/release_22_03.rst
+++ b/doc/guides/rel_notes/release_22_03.rst
@@ -78,6 +78,10 @@ New Features
 
   The new API ``rte_event_eth_rx_adapter_event_port_get()`` was added.
 
+* **Added an API for private user data in Asymmetric crypto session.**
+
+  An API was added for getting/setting an Asymmetric crypto session's user data.
+
 
 Removed Items
 -------------
@@ -115,7 +119,7 @@ API Changes
 * cryptodev: The asymmetric session handling was modified to use a single
   mempool object. An API ``rte_cryptodev_asym_session_pool_create`` was added
   to create a mempool with element size big enough to hold the generic asymmetric
-  session header and max size for a device private session data.
+  session header, max size for a device private session data, and user data size.
   The session structure was moved to ``cryptodev_pmd.h``,
   hiding it from applications.
   The API ``rte_cryptodev_asym_session_init`` was removed as the initialization
diff --git a/lib/cryptodev/cryptodev_pmd.h b/lib/cryptodev/cryptodev_pmd.h
index 63f9cf5427..d91902f6e0 100644
--- a/lib/cryptodev/cryptodev_pmd.h
+++ b/lib/cryptodev/cryptodev_pmd.h
@@ -634,7 +634,9 @@ RTE_STD_C11 struct rte_cryptodev_asym_session {
 	/**< Session driver ID. */
 	uint16_t max_priv_data_sz;
 	/**< Size of private data used when creating mempool */
-	uint8_t padding[5];
+	uint16_t user_data_sz;
+	/**< Session user data will be placed after sess_data */
+	uint8_t padding[3];
 	uint8_t sess_private_data[0];
 };
 
diff --git a/lib/cryptodev/rte_cryptodev.c b/lib/cryptodev/rte_cryptodev.c
index 562cb4a2c4..91d48d5886 100644
--- a/lib/cryptodev/rte_cryptodev.c
+++ b/lib/cryptodev/rte_cryptodev.c
@@ -210,6 +210,8 @@ struct rte_cryptodev_sym_session_pool_private_data {
 struct rte_cryptodev_asym_session_pool_private_data {
 	uint16_t max_priv_session_sz;
 	/**< Size of private session data used when creating mempool */
+	uint16_t user_data_sz;
+	/**< Session user data will be placed after sess_private_data */
 };
 
 int
@@ -1803,7 +1805,7 @@ rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
 
 struct rte_mempool *
 rte_cryptodev_asym_session_pool_create(const char *name, uint32_t nb_elts,
-	uint32_t cache_size, int socket_id)
+	uint32_t cache_size, uint16_t user_data_size, int socket_id)
 {
 	struct rte_mempool *mp;
 	struct rte_cryptodev_asym_session_pool_private_data *pool_priv;
@@ -1821,7 +1823,8 @@ rte_cryptodev_asym_session_pool_create(const char *name, uint32_t nb_elts,
 		return NULL;
 	}
 
-	obj_sz = rte_cryptodev_asym_get_header_session_size() + max_priv_sz;
+	obj_sz = rte_cryptodev_asym_get_header_session_size() + max_priv_sz +
+			user_data_size;
 	obj_sz_aligned =  RTE_ALIGN_CEIL(obj_sz, RTE_CACHE_LINE_SIZE);
 
 	mp = rte_mempool_create(name, nb_elts, obj_sz_aligned, cache_size,
@@ -1842,9 +1845,10 @@ rte_cryptodev_asym_session_pool_create(const char *name, uint32_t nb_elts,
 		return NULL;
 	}
 	pool_priv->max_priv_session_sz = max_priv_sz;
+	pool_priv->user_data_sz = user_data_size;
 
 	rte_cryptodev_trace_asym_session_pool_create(name, nb_elts,
-		cache_size, mp);
+		user_data_size, cache_size, mp);
 	return mp;
 }
 
@@ -1959,10 +1963,11 @@ rte_cryptodev_asym_session_create(uint8_t dev_id,
 	}
 
 	sess->driver_id = dev->driver_id;
+	sess->user_data_sz = pool_priv->user_data_sz;
 	sess->max_priv_data_sz = pool_priv->max_priv_session_sz;
 
 	/* Clear device session pointer.*/
-	memset(sess->sess_private_data, 0, session_priv_data_sz);
+	memset(sess->sess_private_data, 0, session_priv_data_sz + sess->user_data_sz);
 
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->asym_session_configure, NULL);
 
@@ -2159,6 +2164,33 @@ rte_cryptodev_sym_session_get_user_data(
 	return (void *)(sess->sess_data + sess->nb_drivers);
 }
 
+int
+rte_cryptodev_asym_session_set_user_data(void *session, void *data, uint16_t size)
+{
+	struct rte_cryptodev_asym_session *sess = session;
+	if (sess == NULL)
+		return -EINVAL;
+
+	if (sess->user_data_sz < size)
+		return -ENOMEM;
+
+	rte_memcpy(sess->sess_private_data +
+			sess->max_priv_data_sz,
+			data, size);
+	return 0;
+}
+
+void *
+rte_cryptodev_asym_session_get_user_data(void *session)
+{
+	struct rte_cryptodev_asym_session *sess = session;
+	if (sess == NULL || sess->user_data_sz == 0)
+		return NULL;
+
+	return (void *)(sess->sess_private_data +
+			sess->max_priv_data_sz);
+}
+
 static inline void
 sym_crypto_fill_status(struct rte_crypto_sym_vec *vec, int32_t errnum)
 {
diff --git a/lib/cryptodev/rte_cryptodev.h b/lib/cryptodev/rte_cryptodev.h
index 4cf3f6c9d7..1d7bd07680 100644
--- a/lib/cryptodev/rte_cryptodev.h
+++ b/lib/cryptodev/rte_cryptodev.h
@@ -959,6 +959,8 @@ rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
  *   The number of elements in the mempool.
  * @param cache_size
  *   The number of per-lcore cache elements
+ * @param user_data_size
+ *   The size of user data to be placed after session private data.
  * @param socket_id
  *   The *socket_id* argument is the socket identifier in the case of
  *   NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA
@@ -971,7 +973,7 @@ rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
 __rte_experimental
 struct rte_mempool *
 rte_cryptodev_asym_session_pool_create(const char *name, uint32_t nb_elts,
-	uint32_t cache_size, int socket_id);
+	uint32_t cache_size, uint16_t user_data_size, int socket_id);
 
 /**
  * Create symmetric crypto session header (generic with no private data)
@@ -1202,6 +1204,37 @@ void *
 rte_cryptodev_sym_session_get_user_data(
 					struct rte_cryptodev_sym_session *sess);
 
+/**
+ * Store user data in an asymmetric session.
+ *
+ * @param	sess		Session pointer allocated by
+ *				*rte_cryptodev_asym_session_create*.
+ * @param	data		Pointer to the user data.
+ * @param	size		Size of the user data.
+ *
+ * @return
+ *  - On success, zero.
+ *  - -EINVAL if the session pointer is invalid.
+ *  - -ENOMEM if the available user data size is smaller than the size parameter.
+ */
+__rte_experimental
+int
+rte_cryptodev_asym_session_set_user_data(void *sess, void *data, uint16_t size);
+
+/**
+ * Get user data stored in an asymmetric session.
+ *
+ * @param	sess		Session pointer allocated by
+ *				*rte_cryptodev_asym_session_create*.
+ *
+ * @return
+ *  - On success return pointer to user data.
+ *  - On failure returns NULL.
+ */
+__rte_experimental
+void *
+rte_cryptodev_asym_session_get_user_data(void *sess);
+
 /**
  * Perform actual crypto processing (encrypt/digest or auth/decrypt)
  * on user provided data.
diff --git a/lib/cryptodev/rte_cryptodev_trace.h b/lib/cryptodev/rte_cryptodev_trace.h
index 4b48c66199..005a4fe38b 100644
--- a/lib/cryptodev/rte_cryptodev_trace.h
+++ b/lib/cryptodev/rte_cryptodev_trace.h
@@ -86,9 +86,10 @@ RTE_TRACE_POINT(
 RTE_TRACE_POINT(
 	rte_cryptodev_trace_asym_session_pool_create,
 	RTE_TRACE_POINT_ARGS(const char *name, uint32_t nb_elts,
-		uint32_t cache_size, void *mempool),
+		uint16_t user_data_size, uint32_t cache_size, void *mempool),
 	rte_trace_point_emit_string(name);
 	rte_trace_point_emit_u32(nb_elts);
+	rte_trace_point_emit_u16(user_data_size);
 	rte_trace_point_emit_u32(cache_size);
 	rte_trace_point_emit_ptr(mempool);
 )
diff --git a/lib/cryptodev/version.map b/lib/cryptodev/version.map
index 44d1aff0e2..c7c5aefceb 100644
--- a/lib/cryptodev/version.map
+++ b/lib/cryptodev/version.map
@@ -101,7 +101,9 @@ EXPERIMENTAL {
 	rte_cryptodev_remove_enq_callback;
 
 	# added 22.03
+	rte_cryptodev_asym_session_get_user_data;
 	rte_cryptodev_asym_session_pool_create;
+	rte_cryptodev_asym_session_set_user_data;
 	__rte_cryptodev_trace_asym_session_pool_create;
 };
 
-- 
2.25.1


^ permalink raw reply	[flat|nested] 31+ messages in thread

* [PATCH v7 5/5] crypto: modify return value for asym session create
  2022-02-11  9:29 ` [PATCH v7 " Ciara Power
                     ` (3 preceding siblings ...)
  2022-02-11  9:29   ` [PATCH v7 4/5] crypto: add asym session user data API Ciara Power
@ 2022-02-11  9:29   ` Ciara Power
  2022-02-11 14:29   ` [EXT] [PATCH v7 0/5] crypto: improve asym session usage Akhil Goyal
  5 siblings, 0 replies; 31+ messages in thread
From: Ciara Power @ 2022-02-11  9:29 UTC (permalink / raw)
  To: dev; +Cc: roy.fan.zhang, gakhil, anoobj, mdr, Ciara Power, Declan Doherty

Rather than the asym session create function returning a session on
success, and a NULL value on error, it is modified to now return int
values - 0 on success or -EINVAL/-ENOTSUP/-ENOMEM on failure.
The session to be used is passed as input.

This adds clarity on the failure of the create function, which enables
treating the -ENOTSUP return as TEST_SKIPPED in test apps.

Signed-off-by: Ciara Power <ciara.power@intel.com>
Acked-by: Fan Zhang <roy.fan.zhang@intel.com>
Acked-by: Anoob Joseph <anoobj@marvell.com>
Acked-by: Akhil Goyal <gakhil@marvell.com>

---
v5: Added session parameter to create session trace.
v4:
  - Reordered function parameters.
  - Removed docs code additions, these are included due to patch 1
    changing sample doc to use literal includes.
v3:
  - Fixed variable declarations, putting initialised variable last.
  - Made function comment for return value more generic.
  - Fixed log to include line break.
  - Added documentation.
---
 app/test-crypto-perf/cperf_ops.c       |  12 ++-
 app/test/test_cryptodev_asym.c         | 109 +++++++++++++------------
 doc/guides/rel_notes/release_22_03.rst |   3 +-
 lib/cryptodev/rte_cryptodev.c          |  28 ++++---
 lib/cryptodev/rte_cryptodev.h          |  13 ++-
 lib/cryptodev/rte_cryptodev_trace.h    |   4 +-
 6 files changed, 92 insertions(+), 77 deletions(-)

diff --git a/app/test-crypto-perf/cperf_ops.c b/app/test-crypto-perf/cperf_ops.c
index b8f590b397..479c40eead 100644
--- a/app/test-crypto-perf/cperf_ops.c
+++ b/app/test-crypto-perf/cperf_ops.c
@@ -734,7 +734,9 @@ cperf_create_session(struct rte_mempool *sess_mp,
 	struct rte_crypto_sym_xform auth_xform;
 	struct rte_crypto_sym_xform aead_xform;
 	struct rte_cryptodev_sym_session *sess = NULL;
+	void *asym_sess = NULL;
 	struct rte_crypto_asym_xform xform = {0};
+	int ret;
 
 	if (options->op_type == CPERF_ASYM_MODEX) {
 		xform.next = NULL;
@@ -744,11 +746,13 @@ cperf_create_session(struct rte_mempool *sess_mp,
 		xform.modex.exponent.data = perf_mod_e;
 		xform.modex.exponent.length = sizeof(perf_mod_e);
 
-		sess = (void *)rte_cryptodev_asym_session_create(dev_id, &xform, sess_mp);
-		if (sess == NULL)
+		ret = rte_cryptodev_asym_session_create(dev_id, &xform,
+				sess_mp, &asym_sess);
+		if (ret < 0) {
+			RTE_LOG(ERR, USER1, "Asym session create failed\n");
 			return NULL;
-
-		return sess;
+		}
+		return asym_sess;
 	}
 #ifdef RTE_LIB_SECURITY
 	/*
diff --git a/app/test/test_cryptodev_asym.c b/app/test/test_cryptodev_asym.c
index f0cb839a49..c2e1b4dafd 100644
--- a/app/test/test_cryptodev_asym.c
+++ b/app/test/test_cryptodev_asym.c
@@ -317,7 +317,7 @@ test_cryptodev_asym_op(struct crypto_testsuite_params_asym *ts_params,
 	uint8_t input[TEST_DATA_SIZE] = {0};
 	uint8_t *result = NULL;
 
-	int status = TEST_SUCCESS;
+	int ret, status = TEST_SUCCESS;
 
 	xform_tc.next = NULL;
 	xform_tc.xform_type = data_tc->modex.xform_type;
@@ -452,14 +452,14 @@ test_cryptodev_asym_op(struct crypto_testsuite_params_asym *ts_params,
 	}
 
 	if (!sessionless) {
-		sess = rte_cryptodev_asym_session_create(dev_id, &xform_tc,
-				ts_params->session_mpool);
-		if (!sess) {
+		ret = rte_cryptodev_asym_session_create(dev_id, &xform_tc,
+				ts_params->session_mpool, &sess);
+		if (ret < 0) {
 			snprintf(test_msg, ASYM_TEST_MSG_LEN,
 					"line %u "
 					"FAILED: %s", __LINE__,
 					"Session creation failed");
-			status = TEST_FAILED;
+			status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 			goto error_exit;
 		}
 
@@ -646,7 +646,7 @@ test_rsa_sign_verify(void)
 	uint8_t dev_id = ts_params->valid_devs[0];
 	void *sess = NULL;
 	struct rte_cryptodev_info dev_info;
-	int status = TEST_SUCCESS;
+	int ret, status = TEST_SUCCESS;
 
 	/* Test case supports op with exponent key only,
 	 * Check in PMD feature flag for RSA exponent key type support.
@@ -659,12 +659,12 @@ test_rsa_sign_verify(void)
 		return TEST_SKIPPED;
 	}
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool);
+	ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool, &sess);
 
-	if (!sess) {
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1, "Session creation failed for "
 			"sign_verify\n");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto error_exit;
 	}
 
@@ -686,7 +686,7 @@ test_rsa_enc_dec(void)
 	uint8_t dev_id = ts_params->valid_devs[0];
 	void *sess = NULL;
 	struct rte_cryptodev_info dev_info;
-	int status = TEST_SUCCESS;
+	int ret, status = TEST_SUCCESS;
 
 	/* Test case supports op with exponent key only,
 	 * Check in PMD feature flag for RSA exponent key type support.
@@ -699,11 +699,11 @@ test_rsa_enc_dec(void)
 		return TEST_SKIPPED;
 	}
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool);
+	ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool, &sess);
 
-	if (!sess) {
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1, "Session creation failed for enc_dec\n");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto error_exit;
 	}
 
@@ -726,7 +726,7 @@ test_rsa_sign_verify_crt(void)
 	uint8_t dev_id = ts_params->valid_devs[0];
 	void *sess = NULL;
 	struct rte_cryptodev_info dev_info;
-	int status = TEST_SUCCESS;
+	int ret, status = TEST_SUCCESS;
 
 	/* Test case supports op with quintuple format key only,
 	 * Check im PMD feature flag for RSA quintuple key type support.
@@ -738,12 +738,12 @@ test_rsa_sign_verify_crt(void)
 		return TEST_SKIPPED;
 	}
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &rsa_xform_crt, sess_mpool);
+	ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform_crt, sess_mpool, &sess);
 
-	if (!sess) {
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1, "Session creation failed for "
 			"sign_verify_crt\n");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto error_exit;
 	}
 
@@ -766,7 +766,7 @@ test_rsa_enc_dec_crt(void)
 	uint8_t dev_id = ts_params->valid_devs[0];
 	void *sess = NULL;
 	struct rte_cryptodev_info dev_info;
-	int status = TEST_SUCCESS;
+	int ret, status = TEST_SUCCESS;
 
 	/* Test case supports op with quintuple format key only,
 	 * Check in PMD feature flag for RSA quintuple key type support.
@@ -778,12 +778,12 @@ test_rsa_enc_dec_crt(void)
 		return TEST_SKIPPED;
 	}
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &rsa_xform_crt, sess_mpool);
+	ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform_crt, sess_mpool, &sess);
 
-	if (!sess) {
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1, "Session creation failed for "
 			"enc_dec_crt\n");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto error_exit;
 	}
 
@@ -1047,7 +1047,7 @@ test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
 	struct rte_crypto_asym_op *asym_op = NULL;
 	struct rte_crypto_op *op = NULL, *result_op = NULL;
 	void *sess = NULL;
-	int status = TEST_SUCCESS;
+	int ret, status = TEST_SUCCESS;
 	uint8_t output[TEST_DH_MOD_LEN];
 	struct rte_crypto_asym_xform xform = *xfrm;
 	uint8_t peer[] = "01234567890123456789012345678901234567890123456789";
@@ -1074,12 +1074,12 @@ test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
 	asym_op->dh.shared_secret.data = output;
 	asym_op->dh.shared_secret.length = sizeof(output);
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
-	if (sess == NULL) {
+	ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
 				"line %u FAILED: %s", __LINE__,
 				"Session creation failed");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto error_exit;
 	}
 
@@ -1130,7 +1130,7 @@ test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
 	struct rte_crypto_asym_op *asym_op = NULL;
 	struct rte_crypto_op *op = NULL, *result_op = NULL;
 	void *sess = NULL;
-	int status = TEST_SUCCESS;
+	int ret, status = TEST_SUCCESS;
 	uint8_t output[TEST_DH_MOD_LEN];
 	struct rte_crypto_asym_xform xform = *xfrm;
 
@@ -1152,12 +1152,12 @@ test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
 	asym_op->dh.priv_key.data = output;
 	asym_op->dh.priv_key.length = sizeof(output);
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
-	if (sess == NULL) {
+	ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
 				"line %u FAILED: %s", __LINE__,
 				"Session creation failed");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto error_exit;
 	}
 
@@ -1211,7 +1211,7 @@ test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
 	struct rte_crypto_asym_op *asym_op = NULL;
 	struct rte_crypto_op *op = NULL, *result_op = NULL;
 	void *sess = NULL;
-	int status = TEST_SUCCESS;
+	int ret, status = TEST_SUCCESS;
 	uint8_t output[TEST_DH_MOD_LEN];
 	struct rte_crypto_asym_xform xform = *xfrm;
 
@@ -1241,12 +1241,12 @@ test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
 					0);
 	asym_op->dh.priv_key = dh_test_params.priv_key;
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
-	if (sess == NULL) {
+	ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
 				"line %u FAILED: %s", __LINE__,
 				"Session creation failed");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto error_exit;
 	}
 
@@ -1300,7 +1300,7 @@ test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
 	struct rte_crypto_asym_op *asym_op = NULL;
 	struct rte_crypto_op *op = NULL, *result_op = NULL;
 	void *sess = NULL;
-	int status = TEST_SUCCESS;
+	int ret, status = TEST_SUCCESS;
 	uint8_t out_pub_key[TEST_DH_MOD_LEN];
 	uint8_t out_prv_key[TEST_DH_MOD_LEN];
 	struct rte_crypto_asym_xform pub_key_xform;
@@ -1330,12 +1330,12 @@ test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
 	asym_op->dh.priv_key.data = out_prv_key;
 	asym_op->dh.priv_key.length = sizeof(out_prv_key);
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
-	if (sess == NULL) {
+	ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
 				"line %u FAILED: %s", __LINE__,
 				"Session creation failed");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto error_exit;
 	}
 
@@ -1419,12 +1419,12 @@ test_mod_inv(void)
 				return TEST_SKIPPED;
 		}
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &modinv_xform, sess_mpool);
-	if (!sess) {
+	ret = rte_cryptodev_asym_session_create(dev_id, &modinv_xform, sess_mpool, &sess);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1, "line %u "
 				"FAILED: %s", __LINE__,
 				"Session creation failed");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto error_exit;
 	}
 
@@ -1543,13 +1543,13 @@ test_mod_exp(void)
 		goto error_exit;
 	}
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &modex_xform, sess_mpool);
-	if (!sess) {
+	ret = rte_cryptodev_asym_session_create(dev_id, &modex_xform, sess_mpool, &sess);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
 				 "line %u "
 				"FAILED: %s", __LINE__,
 				"Session creation failed");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto error_exit;
 	}
 
@@ -1653,13 +1653,14 @@ test_dsa_sign(void)
 	uint8_t r[TEST_DH_MOD_LEN];
 	uint8_t s[TEST_DH_MOD_LEN];
 	uint8_t dgst[] = "35d81554afaad2cf18f3a1770d5fedc4ea5be344";
+	int ret;
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &dsa_xform, sess_mpool);
-	if (sess == NULL) {
+	ret = rte_cryptodev_asym_session_create(dev_id, &dsa_xform, sess_mpool, &sess);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
 				 "line %u FAILED: %s", __LINE__,
 				"Session creation failed");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto error_exit;
 	}
 	/* set up crypto op data structure */
@@ -1788,7 +1789,7 @@ test_ecdsa_sign_verify(enum curve curve_id)
 	struct rte_crypto_asym_op *asym_op;
 	struct rte_cryptodev_info dev_info;
 	struct rte_crypto_op *op = NULL;
-	int status = TEST_SUCCESS, ret;
+	int ret, status = TEST_SUCCESS;
 
 	switch (curve_id) {
 	case SECP192R1:
@@ -1833,12 +1834,12 @@ test_ecdsa_sign_verify(enum curve curve_id)
 	xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDSA;
 	xform.ec.curve_id = input_params.curve;
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
-	if (sess == NULL) {
+	ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
 				"line %u FAILED: %s", __LINE__,
 				"Session creation failed\n");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto exit;
 	}
 
@@ -1990,7 +1991,7 @@ test_ecpm(enum curve curve_id)
 	struct rte_crypto_asym_op *asym_op;
 	struct rte_cryptodev_info dev_info;
 	struct rte_crypto_op *op = NULL;
-	int status = TEST_SUCCESS, ret;
+	int ret, status = TEST_SUCCESS;
 
 	switch (curve_id) {
 	case SECP192R1:
@@ -2035,12 +2036,12 @@ test_ecpm(enum curve curve_id)
 	xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECPM;
 	xform.ec.curve_id = input_params.curve;
 
-	sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
-	if (sess == NULL) {
+	ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
+	if (ret < 0) {
 		RTE_LOG(ERR, USER1,
 				"line %u FAILED: %s", __LINE__,
 				"Session creation failed\n");
-		status = TEST_FAILED;
+		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
 		goto exit;
 	}
 
diff --git a/doc/guides/rel_notes/release_22_03.rst b/doc/guides/rel_notes/release_22_03.rst
index a930cbbad6..640691c3ef 100644
--- a/doc/guides/rel_notes/release_22_03.rst
+++ b/doc/guides/rel_notes/release_22_03.rst
@@ -123,7 +123,8 @@ API Changes
   The session structure was moved to ``cryptodev_pmd.h``,
   hiding it from applications.
   The API ``rte_cryptodev_asym_session_init`` was removed as the initialization
-  is now moved to ``rte_cryptodev_asym_session_create``.
+  is now moved to ``rte_cryptodev_asym_session_create``, which was updated to
+  return an integer value to indicate initialisation errors.
 
 
 ABI Changes
diff --git a/lib/cryptodev/rte_cryptodev.c b/lib/cryptodev/rte_cryptodev.c
index 91d48d5886..727d271fb9 100644
--- a/lib/cryptodev/rte_cryptodev.c
+++ b/lib/cryptodev/rte_cryptodev.c
@@ -1912,9 +1912,10 @@ rte_cryptodev_sym_session_create(struct rte_mempool *mp)
 	return sess;
 }
 
-void *
+int
 rte_cryptodev_asym_session_create(uint8_t dev_id,
-		struct rte_crypto_asym_xform *xforms, struct rte_mempool *mp)
+		struct rte_crypto_asym_xform *xforms, struct rte_mempool *mp,
+		void **session)
 {
 	struct rte_cryptodev_asym_session *sess;
 	uint32_t session_priv_data_sz;
@@ -1926,17 +1927,17 @@ rte_cryptodev_asym_session_create(uint8_t dev_id,
 
 	if (!rte_cryptodev_is_valid_dev(dev_id)) {
 		CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
-		return NULL;
+		return -EINVAL;
 	}
 
 	dev = rte_cryptodev_pmd_get_dev(dev_id);
 
 	if (dev == NULL)
-		return NULL;
+		return -EINVAL;
 
 	if (!mp) {
 		CDEV_LOG_ERR("invalid mempool\n");
-		return NULL;
+		return -EINVAL;
 	}
 
 	session_priv_data_sz = rte_cryptodev_asym_get_private_session_size(
@@ -1946,22 +1947,23 @@ rte_cryptodev_asym_session_create(uint8_t dev_id,
 	if (pool_priv->max_priv_session_sz < session_priv_data_sz) {
 		CDEV_LOG_DEBUG(
 			"The private session data size used when creating the mempool is smaller than this device's private session data.");
-		return NULL;
+		return -EINVAL;
 	}
 
 	/* Verify if provided mempool can hold elements big enough. */
 	if (mp->elt_size < session_header_size + session_priv_data_sz) {
 		CDEV_LOG_ERR(
 			"mempool elements too small to hold session objects");
-		return NULL;
+		return -EINVAL;
 	}
 
 	/* Allocate a session structure from the session pool */
-	if (rte_mempool_get(mp, (void **)&sess)) {
+	if (rte_mempool_get(mp, session)) {
 		CDEV_LOG_ERR("couldn't get object from session mempool");
-		return NULL;
+		return -ENOMEM;
 	}
 
+	sess = *session;
 	sess->driver_id = dev->driver_id;
 	sess->user_data_sz = pool_priv->user_data_sz;
 	sess->max_priv_data_sz = pool_priv->max_priv_session_sz;
@@ -1969,7 +1971,7 @@ rte_cryptodev_asym_session_create(uint8_t dev_id,
 	/* Clear device session pointer.*/
 	memset(sess->sess_private_data, 0, session_priv_data_sz + sess->user_data_sz);
 
-	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->asym_session_configure, NULL);
+	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->asym_session_configure, -ENOTSUP);
 
 	if (sess->sess_private_data[0] == 0) {
 		ret = dev->dev_ops->asym_session_configure(dev, xforms, sess);
@@ -1977,12 +1979,12 @@ rte_cryptodev_asym_session_create(uint8_t dev_id,
 			CDEV_LOG_ERR(
 				"dev_id %d failed to configure session details",
 				dev_id);
-			return NULL;
+			return ret;
 		}
 	}
 
-	rte_cryptodev_trace_asym_session_create(dev_id, xforms, mp);
-	return sess;
+	rte_cryptodev_trace_asym_session_create(dev_id, xforms, mp, sess);
+	return 0;
 }
 
 int
diff --git a/lib/cryptodev/rte_cryptodev.h b/lib/cryptodev/rte_cryptodev.h
index 1d7bd07680..19e2e70287 100644
--- a/lib/cryptodev/rte_cryptodev.h
+++ b/lib/cryptodev/rte_cryptodev.h
@@ -996,14 +996,19 @@ rte_cryptodev_sym_session_create(struct rte_mempool *mempool);
  *                   processed with this session
  * @param   mp       mempool to allocate asymmetric session
  *                   objects from
+ * @param   session  void ** for session to be used
+ *
  * @return
- *  - On success return pointer to asym-session
- *  - On failure returns NULL
+ *  - 0 on success.
+ *  - -EINVAL on invalid arguments.
+ *  - -ENOMEM on memory error for session allocation.
+ *  - -ENOTSUP if device doesn't support session configuration.
  */
 __rte_experimental
-void *
+int
 rte_cryptodev_asym_session_create(uint8_t dev_id,
-		struct rte_crypto_asym_xform *xforms, struct rte_mempool *mp);
+		struct rte_crypto_asym_xform *xforms, struct rte_mempool *mp,
+		void **session);
 
 /**
  * Frees symmetric crypto session header, after checking that all
diff --git a/lib/cryptodev/rte_cryptodev_trace.h b/lib/cryptodev/rte_cryptodev_trace.h
index 005a4fe38b..a3f6048e7d 100644
--- a/lib/cryptodev/rte_cryptodev_trace.h
+++ b/lib/cryptodev/rte_cryptodev_trace.h
@@ -96,10 +96,12 @@ RTE_TRACE_POINT(
 
 RTE_TRACE_POINT(
 	rte_cryptodev_trace_asym_session_create,
-	RTE_TRACE_POINT_ARGS(uint8_t dev_id, void *xforms, void *mempool),
+	RTE_TRACE_POINT_ARGS(uint8_t dev_id, void *xforms, void *mempool,
+			void *sess),
 	rte_trace_point_emit_u8(dev_id);
 	rte_trace_point_emit_ptr(xforms);
 	rte_trace_point_emit_ptr(mempool);
+	rte_trace_point_emit_ptr(sess);
 )
 
 RTE_TRACE_POINT(
-- 
2.25.1


^ permalink raw reply	[flat|nested] 31+ messages in thread

* RE: [EXT] [PATCH v7 0/5] crypto: improve asym session usage
  2022-02-11  9:29 ` [PATCH v7 " Ciara Power
                     ` (4 preceding siblings ...)
  2022-02-11  9:29   ` [PATCH v7 5/5] crypto: modify return value for asym session create Ciara Power
@ 2022-02-11 14:29   ` Akhil Goyal
  5 siblings, 0 replies; 31+ messages in thread
From: Akhil Goyal @ 2022-02-11 14:29 UTC (permalink / raw)
  To: Ciara Power, dev; +Cc: roy.fan.zhang, Anoob Joseph, mdr

> This patchset includes improvements for the asymmetric session.
> The main change is to the session structure, which is now a single
> mempool object, rather than having pointers to private data elsewhere.
> This session structure is now hidden in an internal header,
> so the app will never use it directly.
> 
> Some other changes include adding a user data API, and modifying
> the return value for the create session function.
> This create session function now also initialises the session,
> and subsequently the clear/free functions have been merged into one.
> 
> Sample code in the programmer's guide that showed basic steps for
> using Asymmetric crypto in DPDK has been replaced with literal includes
> in the first patch of this patchset. This ensures all subsequent code
> changes in the patchset are automatically reflected in the documentation.
> 
> v7: Removed unused parameter to avoid compilation warning.
> 
> v6:
>   - Reordered variable declarations to follow cnxk file format.
>   - Added fix for crypto perf app asymmetric modex operation, there
>     is no longer a need for private mempool, and the
>     rte_cryptodev_asym_session_pool_create API should be used.
> 
> v5:
>   - Modified which patch the sess parameter is passed to session create
>     trace function.
>   - Reworded create session function description.
>   - Removed get API for session private data, can be accessed directly.
>   - Modified test application to create a session mempool for
>     TEST_NUM_SESSIONS rather than TEST_NUM_SESSIONS * 2.
> 
> v4:
>   - Added new patch to add literal includes usage in programmer's guide.
>   - Merged asym crypto session clear and free functions.
>   - Reordered some function parameters.
>   - Updated trace function for asym crypto session create.
>   - Fixed cnxk clear, the PMD no longer needs to put private data
>     back into a mempool.
>   - Renamed struct field for max private session size.
>   - Replaced __extension__ with RTE_STD_C11.
>   - Moved some parameter validity checks to before functional code.
>   - Reworded release note.
>   - Removed mempool parameter from session configure function.
>   - Removed docs code additions, these are included due to patch 1
>     changing sample doc to use literal includes.
>   - Initialised session variables as NULL.
>   - Added possible error return values in user data API comment.
> 
> v3:
>   - Added documentation in relevant patches.
>   - Fixed setting user data size.
>   - Fixed hiding structure, it should not be hidden from PMDs.
>   - Fixed some other small formatting issues.
>   - Increased size of max_priv_session_sz to uint16_t.
>   - Removed trace for asym session init function that was
>     previously removed.
> 
> Ciara Power (5):
>   doc: replace asym crypto code with literal includes
>   crypto: use single buffer for asymmetric session
>   crypto: hide asym session structure
>   crypto: add asym session user data API
>   crypto: modify return value for asym session create
> 
>  app/test-crypto-perf/cperf_ops.c             |  22 +-
>  app/test-crypto-perf/cperf_test_throughput.c |   8 +-
>  app/test-crypto-perf/main.c                  |  31 +-
>  app/test/test_cryptodev_asym.c               | 380 ++++++-------------
>  app/test/test_cryptodev_mod_test_vectors.h   |   4 +
>  doc/guides/prog_guide/cryptodev_lib.rst      | 212 +++--------
>  doc/guides/rel_notes/release_22_03.rst       |  14 +
>  drivers/crypto/cnxk/cn10k_cryptodev_ops.c    |   8 +-
>  drivers/crypto/cnxk/cn9k_cryptodev_ops.c     |   8 +-
>  drivers/crypto/cnxk/cnxk_cryptodev_ops.c     |  22 +-
>  drivers/crypto/cnxk/cnxk_cryptodev_ops.h     |   3 +-
>  drivers/crypto/octeontx/otx_cryptodev_ops.c  |  32 +-
>  drivers/crypto/openssl/rte_openssl_pmd.c     |   4 +-
>  drivers/crypto/openssl/rte_openssl_pmd_ops.c |  24 +-
>  drivers/crypto/qat/qat_asym.c                |  54 +--
>  drivers/crypto/qat/qat_asym.h                |   5 +-
>  lib/cryptodev/cryptodev_pmd.h                |  36 +-
>  lib/cryptodev/cryptodev_trace_points.c       |   9 +-
>  lib/cryptodev/rte_cryptodev.c                | 258 ++++++++-----
>  lib/cryptodev/rte_cryptodev.h                | 136 ++++---
>  lib/cryptodev/rte_cryptodev_trace.h          |  38 +-
>  lib/cryptodev/version.map                    |   9 +-
>  22 files changed, 528 insertions(+), 789 deletions(-)
> 
Series
Acked-by: Akhil Goyal <gakhil@marvell.com>

Applied to dpdk-next-crypto
Thanks.

^ permalink raw reply	[flat|nested] 31+ messages in thread

end of thread, other threads:[~2022-02-11 14:29 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-09 15:38 [PATCH v4 0/5] crypto: improve asym session usage Ciara Power
2022-02-09 15:38 ` [PATCH v4 1/5] doc: replace asym crypto code with literal includes Ciara Power
2022-02-09 15:38 ` [PATCH v4 2/5] crypto: use single buffer for asymmetric session Ciara Power
2022-02-09 19:52   ` [EXT] " Akhil Goyal
2022-02-09 15:38 ` [PATCH v4 3/5] crypto: hide asym session structure Ciara Power
2022-02-09 15:38 ` [PATCH v4 4/5] crypto: add asym session user data API Ciara Power
2022-02-09 20:09   ` [EXT] " Akhil Goyal
2022-02-09 15:38 ` [PATCH v4 5/5] crypto: modify return value for asym session create Ciara Power
2022-02-09 20:19   ` [EXT] " Akhil Goyal
2022-02-10 14:01 ` [PATCH v5 0/5] crypto: improve asym session usage Ciara Power
2022-02-10 14:01   ` [PATCH v5 1/5] doc: replace asym crypto code with literal includes Ciara Power
2022-02-10 14:01   ` [PATCH v5 2/5] crypto: use single buffer for asymmetric session Ciara Power
2022-02-10 14:34     ` [EXT] " Anoob Joseph
2022-02-10 14:01   ` [PATCH v5 3/5] crypto: hide asym session structure Ciara Power
2022-02-10 14:01   ` [PATCH v5 4/5] crypto: add asym session user data API Ciara Power
2022-02-10 14:01   ` [PATCH v5 5/5] crypto: modify return value for asym session create Ciara Power
2022-02-10 15:53 ` [PATCH v6 0/5] crypto: improve asym session usage Ciara Power
2022-02-10 15:54   ` [PATCH v6 1/5] doc: replace asym crypto code with literal includes Ciara Power
2022-02-10 16:36     ` Zhang, Roy Fan
2022-02-10 15:54   ` [PATCH v6 2/5] crypto: use single buffer for asymmetric session Ciara Power
2022-02-10 15:54   ` [PATCH v6 3/5] crypto: hide asym session structure Ciara Power
2022-02-10 15:54   ` [PATCH v6 4/5] crypto: add asym session user data API Ciara Power
2022-02-10 15:54   ` [PATCH v6 5/5] crypto: modify return value for asym session create Ciara Power
2022-02-10 22:37   ` [EXT] [PATCH v6 0/5] crypto: improve asym session usage Akhil Goyal
2022-02-11  9:29 ` [PATCH v7 " Ciara Power
2022-02-11  9:29   ` [PATCH v7 1/5] doc: replace asym crypto code with literal includes Ciara Power
2022-02-11  9:29   ` [PATCH v7 2/5] crypto: use single buffer for asymmetric session Ciara Power
2022-02-11  9:29   ` [PATCH v7 3/5] crypto: hide asym session structure Ciara Power
2022-02-11  9:29   ` [PATCH v7 4/5] crypto: add asym session user data API Ciara Power
2022-02-11  9:29   ` [PATCH v7 5/5] crypto: modify return value for asym session create Ciara Power
2022-02-11 14:29   ` [EXT] [PATCH v7 0/5] crypto: improve asym session usage Akhil Goyal

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).