From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id D364CA034E; Wed, 9 Feb 2022 16:39:33 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DE9CB426FE; Wed, 9 Feb 2022 16:39:14 +0100 (CET) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mails.dpdk.org (Postfix) with ESMTP id ADD32426F7 for ; Wed, 9 Feb 2022 16:39:13 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1644421153; x=1675957153; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IC8Lep/v+FRYZ82guMFN5AsOVayErX79DauTminEOyE=; b=GzS75LBm0Q4G1mIP+ZA066Ewqs8VjbC1orl/WNNMv4AiKAlMk5eBwrKQ N5Cc9YL3V/5z9VgF/Dtj65TJEdRfglLBNhDgRIwQRTr/DYP1FaBUEj1oK 3J/xid8q51FZIFKEGu0P75ZPMiYP1oT9hg8TLAKcvJUc1f2QI9SP6gnPT 8a30YcpBUEfj1poIV0YNPHEqZqzbzUXi6SVPQvEtyk+84H4FmpZkkxp7a iB4IGyC8XyIuKYP3AJiN/OFm88ZeDMQXFXVxGxezfOaLzqm9L85AEt1w8 EWNQNdrV0R85mBcgw7C0XG5fkl5QccbI/O/eIAwFbF68OjEvCWv8b5vhd A==; X-IronPort-AV: E=McAfee;i="6200,9189,10252"; a="312523475" X-IronPort-AV: E=Sophos;i="5.88,356,1635231600"; d="scan'208";a="312523475" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2022 07:39:12 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,356,1635231600"; d="scan'208";a="482362834" Received: from silpixa00400355.ir.intel.com (HELO silpixa00400355.ger.corp.intel.com) ([10.237.222.49]) by orsmga003.jf.intel.com with ESMTP; 09 Feb 2022 07:39:10 -0800 From: Ciara Power To: dev@dpdk.org Cc: roy.fan.zhang@intel.com, gakhil@marvell.com, anoobj@marvell.com, mdr@ashroe.eu, Ciara Power , Declan Doherty Subject: [PATCH v4 4/5] crypto: add asym session user data API Date: Wed, 9 Feb 2022 15:38:53 +0000 Message-Id: <20220209153854.2740455-5-ciara.power@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220209153854.2740455-1-ciara.power@intel.com> References: <20220209153854.2740455-1-ciara.power@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org A user data field is added to the asymmetric session structure. Relevant API added to get/set the field. Signed-off-by: Ciara Power Acked-by: Fan Zhang Acked-by: Anoob Joseph --- 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