From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id 533942B94 for ; Mon, 19 Nov 2018 11:11:15 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Nov 2018 02:11:14 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,252,1539673200"; d="scan'208";a="109731316" Received: from irsmsx103.ger.corp.intel.com ([163.33.3.157]) by orsmga002.jf.intel.com with ESMTP; 19 Nov 2018 02:11:13 -0800 Received: from irsmsx111.ger.corp.intel.com (10.108.20.4) by IRSMSX103.ger.corp.intel.com (163.33.3.157) with Microsoft SMTP Server (TLS) id 14.3.408.0; Mon, 19 Nov 2018 10:11:03 +0000 Received: from irsmsx101.ger.corp.intel.com ([169.254.1.134]) by irsmsx111.ger.corp.intel.com ([169.254.2.195]) with mapi id 14.03.0415.000; Mon, 19 Nov 2018 10:11:03 +0000 From: "Zhang, Roy Fan" To: "Ananyev, Konstantin" , "dev@dpdk.org" CC: "akhil.goyal@nxp.com" Thread-Topic: [dpdk-dev] [PATCH 2/2] cryptodev: change symmetric session structure Thread-Index: AQHUfQgyRB2rarpWGESl2D6Fb1X8pKVSeEIAgARsfUA= Date: Mon, 19 Nov 2018 10:11:03 +0000 Message-ID: <9F7182E3F746AB4EA17801C148F3C604334E6860@IRSMSX101.ger.corp.intel.com> References: <20181115172427.67607-1-roy.fan.zhang@intel.com> <20181115172427.67607-3-roy.fan.zhang@intel.com> <2601191342CEEE43887BDE71AB977258010CEB8E63@IRSMSX106.ger.corp.intel.com> In-Reply-To: <2601191342CEEE43887BDE71AB977258010CEB8E63@IRSMSX106.ger.corp.intel.com> Accept-Language: en-IE, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ctpclassification: CTP_NT x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiYWViNGMyNzctOGNiMy00YjQ5LTkwZDktMjI2ODNkMzQ5MTEyIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiemFPcGxcL1g5U2EwS0RTdFRYRGdDNWt3dXBIWmFmMmk0emhXTTZ0Z3dEbjZCdmF6dFhcL3cwN3N6ZUcraVowcExNIn0= dlp-product: dlpe-windows dlp-version: 11.0.400.15 dlp-reaction: no-action x-originating-ip: [163.33.239.181] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH 2/2] cryptodev: change symmetric session structure X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Nov 2018 10:11:16 -0000 Hi Konstantin, Thanks for the review. Comments inline. > -----Original Message----- > From: Ananyev, Konstantin > Sent: Friday, November 16, 2018 2:32 PM > To: Zhang, Roy Fan ; dev@dpdk.org > Cc: akhil.goyal@nxp.com > Subject: RE: [dpdk-dev] [PATCH 2/2] cryptodev: change symmetric session > structure >=20 > Hi Fan, >=20 > > > > This patch changes the symmetric session structure of cryptodev. > > The symmetric session now contains extra information for secure access > > purposes. The patch also includes the updates to the PMDs, test > > applications, and examples to fit the change. >=20 > Few more comments from me in-line below. > Also a generic question - docs also might also need to be updated? > Apart from that and naming collisions - looks good overall. > Konstantin >=20 > As a generic one - all the drivers for session-less sessions assume that > sess_mp is initialized with > DIM(sess_data[]) greater than their driver id. > It is a valid assumption, but should we add extra check in > rte_cryptodev_queue_pair_setup()? >=20 [Fan: Ok, will do.] =20 > ... > > /* Check that all device private data has been freed */ > > + /* Check that all device private data has been freed */ > > for (i =3D 0; i < nb_drivers; i++) { >=20 > As Fiona pointed we have to use sess->nb_drivers here. [Fan: Yes, you are right]=20 >=20 > > - sess_priv =3D get_sym_session_private_data(sess, i); > > - if (sess_priv !=3D NULL) > > + if (sess->sess_data[i].refcnt !=3D 0) > > return -EBUSY; > > } > > > > @@ -1336,14 +1408,24 @@ rte_cryptodev_asym_session_free(struct > > rte_cryptodev_asym_session *sess) > > > > > > unsigned int > > -rte_cryptodev_sym_get_header_session_size(void) > > +rte_cryptodev_sym_get_header_session_size( > > + struct rte_cryptodev_sym_session *sess) >=20 > That's a change in the public API, np in general, but I suppose needs to = be > documented (release notes?). [Yest that's right, I will update this in V2] >=20 > > { > > /* > > * Header contains pointers to the private data > > * of all registered drivers, and a flag which > > * indicates presence of user data > > */ > > - return ((sizeof(void *) * nb_drivers) + sizeof(uint8_t)); > > + if (!sess) { > > + struct rte_cryptodev_sym_session s =3D {0}; > > + s.nb_drivers =3D nb_drivers; > > + s.priv_size =3D 0; > > + > > + return (unsigned int)(sizeof(s) + > > + rte_cryptodev_sym_session_data_size(&s)); > > + } else > > + return (unsigned int)(sizeof(*sess) + > > + > rte_cryptodev_sym_session_data_size(sess)); > > } > > > > unsigned int __rte_experimental > > @@ -1361,7 +1443,6 @@ unsigned int > > rte_cryptodev_sym_get_private_session_size(uint8_t dev_id) { > > struct rte_cryptodev *dev; > > - unsigned int header_size =3D sizeof(void *) * nb_drivers; > > unsigned int priv_sess_size; > > > > if (!rte_cryptodev_pmd_is_valid_dev(dev_id)) > > @@ -1374,19 +1455,27 @@ > > rte_cryptodev_sym_get_private_session_size(uint8_t dev_id) > > > > priv_sess_size =3D (*dev->dev_ops->sym_session_get_size)(dev); > > > > - /* > > - * If size is less than session header size, > > - * return the latter, as this guarantees that > > - * sessionless operations will work > > - */ > > - if (priv_sess_size < header_size) > > - return header_size; > > - > > return priv_sess_size; > > > > } > > > > unsigned int __rte_experimental > > +rte_cryptodev_sym_get_max_private_session_size(void) > > +{ > > + unsigned int priv_sess_size =3D 0; > > + uint8_t dev_id; > > + > > + for (dev_id =3D 0; dev_id < rte_cryptodev_count(); dev_id++) { > > + unsigned int dev_p_size =3D > > + > rte_cryptodev_sym_get_private_session_size(dev_id); > > + > > + priv_sess_size =3D RTE_MAX(priv_sess_size, dev_p_size); > > + } > > + > > + return priv_sess_size; > > +} > > + > > +unsigned int __rte_experimental > > rte_cryptodev_asym_get_private_session_size(uint8_t dev_id) { > > struct rte_cryptodev *dev; > > @@ -1415,15 +1504,10 @@ rte_cryptodev_sym_session_set_user_data( > > void *data, > > uint16_t size) > > { > > - uint16_t off_set =3D sizeof(void *) * nb_drivers; > > - uint8_t *user_data_present =3D (uint8_t *)sess + off_set; > > - > > - if (sess =3D=3D NULL) > > + if (sess =3D=3D NULL || sess->priv_size < size) > > return -EINVAL; > > > > - *user_data_present =3D 1; > > - off_set +=3D sizeof(uint8_t); > > - rte_memcpy((uint8_t *)sess + off_set, data, size); > > + rte_memcpy(sess->sess_data + sess->nb_drivers, data, size); > > return 0; > > } > > > > @@ -1431,14 +1515,10 @@ void * __rte_experimental > > rte_cryptodev_sym_session_get_user_data( > > struct rte_cryptodev_sym_session > *sess) { > > - uint16_t off_set =3D sizeof(void *) * nb_drivers; > > - uint8_t *user_data_present =3D (uint8_t *)sess + off_set; > > - > > - if (sess =3D=3D NULL || !*user_data_present) > > + if (sess =3D=3D NULL || sess->priv_size =3D=3D 0) > > return NULL; > > > > - off_set +=3D sizeof(uint8_t); > > - return (uint8_t *)sess + off_set; > > + return (void *)(sess->sess_data + sess->nb_drivers); > > } > > > > /** Initialise rte_crypto_op mempool element */ diff --git > > a/lib/librte_cryptodev/rte_cryptodev.h > > b/lib/librte_cryptodev/rte_cryptodev.h > > index f9e7507da..999253f1f 100644 > > --- a/lib/librte_cryptodev/rte_cryptodev.h > > +++ b/lib/librte_cryptodev/rte_cryptodev.h > > @@ -951,14 +951,22 @@ rte_cryptodev_enqueue_burst(uint8_t dev_id, > uint16_t qp_id, > > dev->data->queue_pairs[qp_id], ops, nb_ops); } > > > > - > > /** Cryptodev symmetric crypto session > > * Each session is derived from a fixed xform chain. Therefore each se= ssion > > * has a fixed algo, key, op-type, digest_len etc. > > */ > > struct rte_cryptodev_sym_session { > > - __extension__ void *sess_private_data[0]; > > - /**< Private symmetric session material */ > > + uint64_t userdata; > > + /**< Can be used for external metadata */ > > + uint16_t nb_drivers; > > + /**< number of elements in sess_data array */ > > + uint16_t priv_size; > > + /**< session private data will be placed after sess_data */ > > + __extension__ struct { > > + void *data; > > + uint16_t refcnt; > > + } sess_data[0]; > > + /**< Driver specific session material, variable size */ > > }; > > > > /** Cryptodev asymmetric crypto session */ @@ -968,6 +976,31 @@ > > struct rte_cryptodev_asym_session { }; > > > > /** > > + * Create a symmetric 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 priv_size > > + * The private data size of each session. > > + * @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 size of the session > > + * - On failure returns 0 > > + */ > > +struct rte_mempool * > > +rte_cryptodev_sym_session_pool_create(const char *name, > > + uint32_t nb_elts, uint32_t cache_size, uint16_t priv_size, > > + int socket_id); >=20 > New function - needs experimental tag, I think. >=20 > > + > > +/** > > * Create symmetric crypto session header (generic with no private dat= a) > > * > > * @param mempool Symmetric session mempool to allocate session > > @@ -1097,13 +1130,22 @@ 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 private data size > > + * > > + * @param sess > > + * The sym cryptodev session pointer > > * > > * @return > > - * Size of the symmetric eader session. > > + * - If sess is not NULL, return the size of the header session incl= uding > > + * the private data size defined within sess. > > + * - If sess is NULL, return the size of the header session excluded > > + * the private data size. This way can be used for creating the sess= ion > > + * mempool but the user has to add its private data to this return > manually. > > */ > > unsigned int > > -rte_cryptodev_sym_get_header_session_size(void); > > +rte_cryptodev_sym_get_header_session_size( > > + struct rte_cryptodev_sym_session *sess); > > > > /** > > * Get the size of the asymmetric session header, for all registered d= rivers. > > @@ -1129,6 +1171,17 @@ unsigned int > > rte_cryptodev_sym_get_private_session_size(uint8_t dev_id); > > > > /** > > + * Get the maximum size of the private symmetric session data > > + * for all devices. > > + * > > + * @return > > + * - Size of the maximum private data, if successful. > > + * - 0 if there is no device in the system. > > + */ > > +unsigned int __rte_experimental > > +rte_cryptodev_sym_get_max_private_session_size(void); > > + > > +/** > > * Get the size of the private data for asymmetric session > > * on device > > *