From patchwork Mon Jan 24 15:03:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Power, Ciara" X-Patchwork-Id: 106354 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id CE1BAA04A8; Mon, 24 Jan 2022 16:04:39 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0F102427DB; Mon, 24 Jan 2022 16:04:27 +0100 (CET) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mails.dpdk.org (Postfix) with ESMTP id 1684141154 for ; Mon, 24 Jan 2022 16:04:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1643036664; x=1674572664; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WfxoP1SNmmoiM1PmIzipgZxliyo6UZIlZ09l1nFbXfg=; b=V9XF8IkPS2j1svuDzr+XkWJodrKHHE+wywxhfoL2uextyHcwM+4GQi7U WD5w4GdjjKM3HG9B32MQxOdxkEgYth07G3eZaEw6UBHxdLCE/TRCr8rZQ 3Id5t2PyExCdmlM9HrGFbAs0tFBF54/lpEaILaWEO+EiANcf83qsTzoN6 Q3XFtEW4U97FocdFjSJTnEIN3pozsm3qY+e5KkFEIFkEBSJDJfHeI72Vd SjjpGgx1Sy+xyQ0Zrq6OEe2yIX/rIq6ngaWz0PRRqQNuxy9l2Rjg3fNG3 xlugzf9FnrV7lRJrR5hXl8StIT+VN3Ifo5jI0pUQvqn+F23oSHYPyNuF7 A==; X-IronPort-AV: E=McAfee;i="6200,9189,10236"; a="332417209" X-IronPort-AV: E=Sophos;i="5.88,311,1635231600"; d="scan'208";a="332417209" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jan 2022 07:03:56 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,311,1635231600"; d="scan'208";a="476744136" Received: from silpixa00400355.ir.intel.com (HELO silpixa00400355.ger.corp.intel.com) ([10.237.222.49]) by orsmga003.jf.intel.com with ESMTP; 24 Jan 2022 07:03:54 -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 v2 3/4] crypto: add asym session user data API Date: Mon, 24 Jan 2022 15:03:38 +0000 Message-Id: <20220124150339.280090-4-ciara.power@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220124150339.280090-1-ciara.power@intel.com> References: <20220124150339.280090-1-ciara.power@intel.com> MIME-Version: 1.0 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 --- v2: Corrected order of version map entries. --- app/test/test_cryptodev_asym.c | 2 +- lib/cryptodev/cryptodev_pmd.h | 4 ++- lib/cryptodev/rte_cryptodev.c | 39 ++++++++++++++++++++++++++--- lib/cryptodev/rte_cryptodev.h | 34 ++++++++++++++++++++++++- lib/cryptodev/rte_cryptodev_trace.h | 3 ++- lib/cryptodev/version.map | 2 ++ 6 files changed, 76 insertions(+), 8 deletions(-) diff --git a/app/test/test_cryptodev_asym.c b/app/test/test_cryptodev_asym.c index f93f39af42..a81d6292f6 100644 --- a/app/test/test_cryptodev_asym.c +++ b/app/test/test_cryptodev_asym.c @@ -897,7 +897,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/lib/cryptodev/cryptodev_pmd.h b/lib/cryptodev/cryptodev_pmd.h index 2d12505d3c..a0f7bb0c05 100644 --- a/lib/cryptodev/cryptodev_pmd.h +++ b/lib/cryptodev/cryptodev_pmd.h @@ -636,7 +636,9 @@ __extension__ struct rte_cryptodev_asym_session { /**< Session driver ID. */ uint8_t max_priv_session_sz; /**< size of private session data used when creating mempool */ - uint8_t padding[6]; + uint16_t user_data_sz; + /**< session user data will be placed after sess_data */ + uint8_t padding[4]; uint8_t sess_private_data[0]; }; diff --git a/lib/cryptodev/rte_cryptodev.c b/lib/cryptodev/rte_cryptodev.c index c10b9bf05f..2a591930de 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 { uint8_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, @@ -1844,7 +1847,7 @@ rte_cryptodev_asym_session_pool_create(const char *name, uint32_t nb_elts, pool_priv->max_priv_session_sz = max_priv_sz; rte_cryptodev_trace_asym_session_pool_create(name, nb_elts, - cache_size, mp); + user_data_size, cache_size, mp); return mp; } @@ -1958,12 +1961,13 @@ rte_cryptodev_asym_session_create(struct rte_mempool *mp, uint8_t dev_id, } sess->driver_id = dev->driver_id; + sess->user_data_sz = pool_priv->user_data_sz; sess->max_priv_session_sz = pool_priv->max_priv_session_sz; /* Clear device session pointer. * Include the flag indicating presence of private data */ - 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); @@ -2173,6 +2177,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_session_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_session_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 af328de896..6a4d6d9934 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) @@ -1213,6 +1215,36 @@ 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. + * - On failure, a negative value. + */ +__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 2c9de4f6de..563c719598 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 b1f2d6c7f0..816f3e831d 100644 --- a/lib/cryptodev/version.map +++ b/lib/cryptodev/version.map @@ -104,7 +104,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; };