From 9e5f5ecb5eb6ce243b9835735b37c5959ec7dd6b Mon Sep 17 00:00:00 2001 From: Fan Zhang Date: Thu, 10 Jan 2019 14:50:20 +0000 Subject: [PATCH] cryptodev: add user data size to symmetric session This patch adds a user_data_sz field to cryptodev symmetric session. The field is used to check if reading or writing the session's user data field is eligible. Signed-off-by: Fan Zhang Acked-by: Fiona Trahe Acked-by: Akhil Goyal --- doc/guides/prog_guide/cryptodev_lib.rst | 4 + .../prog_guide/img/cryptodev_sym_sess.svg | 172 +++++++++--------- lib/librte_cryptodev/rte_cryptodev.c | 11 +- lib/librte_cryptodev/rte_cryptodev.h | 5 +- 4 files changed, 107 insertions(+), 85 deletions(-) diff --git a/doc/guides/prog_guide/cryptodev_lib.rst b/doc/guides/prog_guide/cryptodev_lib.rst index f68fb72d36..74a930b6d9 100644 --- a/doc/guides/prog_guide/cryptodev_lib.rst +++ b/doc/guides/prog_guide/cryptodev_lib.rst @@ -327,6 +327,10 @@ the set API to set the user data and retrieve it using get API. void * rte_cryptodev_sym_session_get_user_data( struct rte_cryptodev_sym_session *sess); +Please note the ``size`` passed to set API cannot be bigger than the predefined +``user_data_sz`` when creating the session header mempool, otherwise the +function will return error. Also when ``user_data_sz`` was defined as ``0`` when +creating the session header mempool, the get API will always return ``NULL``. For session-less mode, the private user data information can be placed along with the ``struct rte_crypto_op``. The ``rte_crypto_op::private_data_offset`` indicates the diff --git a/doc/guides/prog_guide/img/cryptodev_sym_sess.svg b/doc/guides/prog_guide/img/cryptodev_sym_sess.svg index 5c843f7369..20059cc0f2 100644 --- a/doc/guides/prog_guide/img/cryptodev_sym_sess.svg +++ b/doc/guides/prog_guide/img/cryptodev_sym_sess.svg @@ -37,7 +37,7 @@ showgrid="false" inkscape:zoom="1.7495789" inkscape:cx="208.74719" - inkscape:cy="216.52777" + inkscape:cy="170.80248" inkscape:window-x="0" inkscape:window-y="27" inkscape:window-maximized="1" @@ -150,7 +150,7 @@ id="filter_2">Rounded Rectangle.12Crypto Symmetric SessionRounded Rectangle.13Private Session Data + id="desc29">Private Session Data + id="text4129" + y="80.842018" + x="27.862804" + style="font-style:normal;font-weight:normal;font-size:30.00008965px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.75000226" + xml:space="preserve"> - +} session_data[]; +uint16_t user_data_sz; +user_data nb_drivers; + s.user_data_sz = pool_priv->user_data_sz; if ((rte_cryptodev_sym_get_existing_header_session_size(&s) > obj_size) || (s.nb_drivers <= dev->driver_id) || @@ -1307,7 +1308,8 @@ rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts, static unsigned int rte_cryptodev_sym_session_data_size(struct rte_cryptodev_sym_session *sess) { - return (sizeof(sess->sess_data[0]) * sess->nb_drivers); + return (sizeof(sess->sess_data[0]) * sess->nb_drivers) + + sess->user_data_sz; } struct rte_cryptodev_sym_session * @@ -1335,7 +1337,7 @@ rte_cryptodev_sym_session_create(struct rte_mempool *mp) } sess->nb_drivers = pool_priv->nb_drivers; - + sess->user_data_sz = pool_priv->user_data_sz; /* Clear device session pointer. * Include the flag indicating presence of user data @@ -1538,6 +1540,9 @@ rte_cryptodev_sym_session_set_user_data( if (sess == NULL) return -EINVAL; + if (sess->user_data_sz < size) + return -ENOMEM; + rte_memcpy(sess->sess_data + sess->nb_drivers, data, size); return 0; } @@ -1546,7 +1551,7 @@ void * __rte_experimental rte_cryptodev_sym_session_get_user_data( struct rte_cryptodev_sym_session *sess) { - if (sess == NULL) + if (sess == NULL || sess->user_data_sz == 0) return NULL; return (void *)(sess->sess_data + sess->nb_drivers); diff --git a/lib/librte_cryptodev/rte_cryptodev.h b/lib/librte_cryptodev/rte_cryptodev.h index 1bc4a375b4..b6a9321d5d 100644 --- a/lib/librte_cryptodev/rte_cryptodev.h +++ b/lib/librte_cryptodev/rte_cryptodev.h @@ -955,6 +955,8 @@ rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id, struct rte_cryptodev_sym_session { uint16_t nb_drivers; /**< number of elements in sess_data array */ + uint16_t user_data_sz; + /**< session user data will be placed after sess_data */ __extension__ struct { void *data; } sess_data[0]; @@ -1128,7 +1130,8 @@ 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. + * Get the size of the header session, for all registered drivers excluding + * the user data size. * * @return * Size of the symmetric eader session. -- 2.20.1