improve security instance setup
cover improve security instance setup
These patches make some minor improvements to the security instance setup for the QAT SYM and AESNI-MB PMDs.
David Coyle (2):
crypto/qat: improve security instance setup crypto/aesni_mb: improve security instance setup
drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c | 13 ++++--------- drivers/crypto/qat/qat_sym_pmd.c | 9 +++------ 2 files changed, 7 insertions(+), 15 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/2 crypto/qat: improve security instance setup
This patch makes some minor improvements to the security instance setup for the QAT SYM PMD. All of this setup code is now in one '#ifdef RTE_LIBRTE_SECURITY' block. Enabling the RTE_CRYPTODEV_FF_SECURITY feature for the device is also moved to this block.
--- drivers/crypto/qat/qat_sym_pmd.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/crypto/qat/qat_sym_pmd.c +3 -6
@@ -346,10 +346,6 @@ qat_sym_dev_create(struct qat_pci_device *qat_pci_dev, } } -#ifdef RTE_LIBRTE_SECURITY -struct rte_security_ctx *security_instance; -#endif -snprintf (name,RTE_CRYPTODEV_NAME_MAX_LEN ,"%s_%s" , qat_pci_dev->name,"sym" );QAT_LOG (DEBUG ,"Creating QAT SYM device %s" , name);
@@ -381,8 +377,7 @@ qat_sym_dev_create(struct qat_pci_device *qat_pci_dev,RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT |RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT |RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT | -RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED | -RTE_CRYPTODEV_FF_SECURITY ; +RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED ;if (rte_eal_process_type () !=RTE_PROC_PRIMARY )return 0 ;
@@ -392,6 +387,7 @@ qat_sym_dev_create(struct qat_pci_device *qat_pci_dev, qat_pci_dev->qat_dev_gen);#ifdef RTE_LIBRTE_SECURITY +struct rte_security_ctx *security_instance; security_instance =rte_malloc ("qat_sec" ,sizeof (struct rte_security_ctx ),RTE_CACHE_LINE_SIZE );
@@ -405,6 +401,7 @@ qat_sym_dev_create(struct qat_pci_device *qat_pci_dev, security_instance->ops = &security_qat_ops; security_instance->sess_cnt =0 ; cryptodev->security_ctx = security_instance; + cryptodev->feature_flags |=RTE_CRYPTODEV_FF_SECURITY ;#endif internals = cryptodev->data->dev_private;
Signature · 1 line
2.17.1
Re: [dpdk-dev] [PATCH v1 1/2] crypto/qat: improve security instance setup
Quoted 11 lines
-----Original Message-----
From: Coyle, David <[email protected]>
Sent: Thursday, July 16, 2020 4:36 PM
To: [email protected]; Doherty, Declan <[email protected]>; De Lara Guarch, Pablo <[email protected]>; Trahe, Fiona <[email protected]>
Cc: [email protected]; Ryan, Brendan <[email protected]>; O'loingsigh, Mairtin <[email protected]>; Coyle, David <[email protected]>
Subject: [PATCH v1 1/2]crypto/qat: improve security instance setup
Quoted 8 lines
This patch makes some minor improvements to the security instance setup for the QAT SYM PMD. All of this setup code is now in one '#ifdef
RTE_LIBRTE_SECURITY' block. Enabling theRTE_CRYPTODEV_FF_SECURITYfeature for the device is also moved to this block.Fixes 6f0ef237404b ("crypto/qat: support DOCSIS protocol")Signed-off-by David Coyle <[email protected]>
Re: [dpdk-dev] [PATCH v1 1/2] crypto/qat: improve security instance setup
Quoted 9 lines
Quoted 8 lines
This patch makes some minor improvements to the security instance setup for the QAT SYM PMD. All of this setup code is now in one '#ifdef
RTE_LIBRTE_SECURITY' block. Enabling theRTE_CRYPTODEV_FF_SECURITYfeature for the device is also moved to this block.Fixes 6f0ef237404b ("crypto/qat: support DOCSIS protocol")Signed-off-by David Coyle <[email protected]>Acked-by Fiona Trahe <[email protected]>
This patch is applied to dpdk-next-crypto
Please send next version for 2/2 of this series.
Re: [dpdk-dev] [PATCH v1 1/2] crypto/qat: improve security instance setup
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
This patch makes some minor improvements to the security instance setup for the QAT SYM PMD. All of this setup code is now in one '#ifdef
RTE_LIBRTE_SECURITY' block. Enabling theRTE_CRYPTODEV_FF_SECURITYfeature for the device is also moved to this block.
Quoted 8 lines
Quoted 4 lines
Quoted 3 lines
Fixes 6f0ef237404b ("crypto/qat: support DOCSIS protocol")Signed-off-by David Coyle <[email protected]>Acked-by Fiona Trahe <[email protected]>This patch is applied to dpdk-next-crypto
Please send next version for 2/2 of this series.
No this patch is pulled back. I suppose the memory leak is there in this patch also.
Re: [dpdk-dev] [PATCH v1 1/2] crypto/qat: improve security instance setup
Hi Akhil,
Quoted 12 lines
-----Original Message-----
From: Akhil Goyal <[email protected]>
Sent: Saturday, July 18, 2020 10:41 PMQuoted 4 lines
Quoted 4 lines
Quoted 4 lines
This patch makes some minor improvements to the security instance setup for the QAT SYM PMD. All of this setup code is now in one '#ifdef
RTE_LIBRTE_SECURITY' block. Enabling theRTE_CRYPTODEV_FF_SECURITYfeature for the device is also moved tothis block.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Fixes 6f0ef237404b ("crypto/qat: support DOCSIS protocol")Signed-off-by David Coyle <[email protected]>
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Acked-by Fiona Trahe <[email protected]>This patch is applied to dpdk-next-crypto
Please send next version for 2/2 of this series.
No this patch is pulled back. I suppose the memory leak is there in this patch also.
[DC] Yes, memory leak is here too and is fixed in v2
PATCH 2/2 crypto/aesni_mb: improve security instance setup
In reply to David CoyleThis patch makes some minor improvements to the security instance setup for the AESNI-MB PMD. All of this setup code is now in one '#ifdef AESNI_MB_DOCSIS_SEC_ENABLED' block. Enabling the RTE_CRYPTODEV_FF_SECURITY feature for the device is also moved to this block.
--- drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)
drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c +4 -9
@@ -1881,9 +1881,6 @@ cryptodev_aesni_mb_create(const char *name,struct aesni_mb_private *internals;enum aesni_mb_vector_mode vector_mode;MB_MGR *mb_mgr; -#ifdef AESNI_MB_DOCSIS_SEC_ENABLED -struct rte_security_ctx *security_instance; -#endif dev =rte_cryptodev_pmd_create (name, &vdev->device, init_params);if (dev ==NULL ) {
@@ -1912,13 +1909,10 @@ cryptodev_aesni_mb_create(const char *name,RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING |RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT |RTE_CRYPTODEV_FF_SYM_CPU_CRYPTO | - RTE_CRYPTODEV_FF_SYM_SESSIONLESS -#ifdef AESNI_MB_DOCSIS_SEC_ENABLED - |RTE_CRYPTODEV_FF_SECURITY -#endif - ; +RTE_CRYPTODEV_FF_SYM_SESSIONLESS ;#ifdef AESNI_MB_DOCSIS_SEC_ENABLED +struct rte_security_ctx *security_instance; security_instance =rte_malloc ("aesni_mb_sec" ,sizeof (struct rte_security_ctx ),RTE_CACHE_LINE_SIZE );
@@ -1932,6 +1926,7 @@ cryptodev_aesni_mb_create(const char *name, security_instance->ops = rte_aesni_mb_pmd_sec_ops; security_instance->sess_cnt =0 ; dev->security_ctx = security_instance; + dev->feature_flags |=RTE_CRYPTODEV_FF_SECURITY ;#endif /* Check CPU for support for AES instruction set */
@@ -2011,7 +2006,7 @@ cryptodev_aesni_mb_remove(struct rte_vdev_device *vdev)RTE_PER_LCORE (sync_mb_mgr) =NULL ; } -#ifdef RTE_LIBRTE_SECURITY +#ifdef AESNI_MB_DOCSIS_SEC_ENABLED rte_free (cryptodev->security_ctx);#endif
Signature · 1 line
2.17.1
Re: [dpdk-dev] [PATCH v1 2/2] crypto/aesni_mb: improve security instance setup
Hi David,
Quoted 44 lines
-----Original Message-----
From: Coyle, David <[email protected]>
Sent: Thursday, July 16, 2020 4:36 PM
To: [email protected]; Doherty, Declan <[email protected]>; De Lara Guarch, Pablo <[email protected]>; Trahe, Fiona <[email protected]>
Cc: [email protected]; Ryan, Brendan <[email protected]>; O'loingsigh, Mairtin <[email protected]>; Coyle, David <[email protected]>
Subject: [PATCH v1 2/2]crypto/aesni_mb: improve security instance setupThis patch makes some minor improvements to the security instance setup for the AESNI-MB PMD. All of this setup code is now in one '#ifdef
AESNI_MB_DOCSIS_SEC_ENABLED' block. Enabling theRTE_CRYPTODEV_FF_SECURITYfeature for the device is also moved to this block.Fixes fda5216fba55 ("crypto/aesni_mb: support DOCSIS protocol")Signed-off-by David Coyle <[email protected]>--- drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c +0
-5@@ -1881,9 +1881,6 @@ cryptodev_aesni_mb_create(const char *name,struct aesni_mb_private *internals;enum aesni_mb_vector_mode vector_mode;MB_MGR *mb_mgr; -#ifdef AESNI_MB_DOCSIS_SEC_ENABLED -struct rte_security_ctx *security_instance; -#endif dev =rte_cryptodev_pmd_create (name, &vdev->device, init_params);if (dev ==NULL ) {@@ -1912,13 +1909,10 @@ cryptodev_aesni_mb_create(const char *name,RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING |RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT | RTE_CRYPTODEV_FF_SYM_CPU_CRYPTO | - RTE_CRYPTODEV_FF_SYM_SESSIONLESS -#ifdef AESNI_MB_DOCSIS_SEC_ENABLED
drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c cryptodev_aesni_mb_create(const char *name, · line 1918
Quoted 10 lines
drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c +2
-3- |RTE_CRYPTODEV_FF_SECURITY -#endif - ; +RTE_CRYPTODEV_FF_SYM_SESSIONLESS ;#ifdef AESNI_MB_DOCSIS_SEC_ENABLED +struct rte_security_ctx *security_instance; security_instance =rte_malloc ("aesni_mb_sec" ,sizeof (struct rte_security_ctx ),RTE_CACHE_LINE_SIZE );
I see that there could be a potential memory leak here.
Assuming this malloc works, if alloc_init_mb_mgr() fails, this memory will not be freed. So I suggest two options:
1 - Free security_instance if alloc_init_mb_mgr() fails
2 - Move this piece of code after alloc_init_mb_mgr and free mb_mgr if this malloc fails.
Thanks,
Pablo
Re: [dpdk-dev] [PATCH v1 2/2] crypto/aesni_mb: improve security instance setup
Hi Pablo
Quoted 4 lines
-----Original Message-----
From: De Lara Guarch, Pablo <[email protected]>
Sent: Friday, July 17, 2020 8:29 PMQuoted 1 line
Quoted 13 lines
drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c cryptodev_aesni_mb_create(const char *name, · line 1918
Quoted 5 lines
#ifdef
AESNI_MB_DOCSIS_SEC_ENABLEDdrivers/crypto/aesni_mb/rte_aesni_mb_pmd.c +1
-0+struct rte_security_ctx *security_instance; security_instance =rte_malloc ("aesni_mb_sec" ,sizeof (struct rte_security_ctx ),RTE_CACHE_LINE_SIZE );I see that there could be a potential memory leak here.
Assuming this malloc works, ifalloc_init_mb_mgr()fails, this memory will not be freed.
So I suggest two options:
1 - Freesecurity_instanceifalloc_init_mb_mgr()fails
2 - Move this piece of code afteralloc_init_mb_mgrand freemb_mgrif this malloc fails.
[DC] Good catch, disappointed I didn't spot that myself :( This is fixed in v2 coming very shortly - used option 1 above
Quoted 1 line
v2 cover improve security instance setup
In reply to David CoyleThese patches make some improvements to the security instance setup for the QAT SYM and AESNI-MB PMDs.
David Coyle (2):
crypto/qat: improve security instance setup crypto/aesni-mb: improve security instance setup
drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c | 18 +++++----- drivers/crypto/qat/qat_sym_pmd.c | 42 ++++++++++++---------- 2 files changed, 33 insertions(+), 27 deletions(-)
Signature · 1 line
2.17.1
PATCH v2 1/2 crypto/qat: improve security instance setup
This patch makes some improvements to the security instance setup for the QAT SYM PMD, as follows:
- fix potential memory leak where the security instance was not freed if an error occurred later in the device creation
- tidy-up security instance initialization code by moving it all, including enabling the RTE_CRYPTODEV_FF_SECURITY feature, into one '#ifdef RTE_LIBRTE_SECURITY' block
--- drivers/crypto/qat/qat_sym_pmd.c | 42 ++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 18 deletions(-)
drivers/crypto/qat/qat_sym_pmd.c +24 -18
@@ -310,7 +310,7 @@ int qat_sym_dev_create(struct qat_pci_device *qat_pci_dev, struct qat_dev_cmd_param *qat_dev_cmd_param __rte_unused) { - int i = 0; + int i = 0, ret = 0;struct qat_device_info *qat_dev_instance = &qat_pci_devs[qat_pci_dev->qat_dev_id];
@@ -346,10 +346,6 @@ qat_sym_dev_create(struct qat_pci_device *qat_pci_dev, } } -#ifdef RTE_LIBRTE_SECURITY -struct rte_security_ctx *security_instance; -#endif -snprintf (name,RTE_CRYPTODEV_NAME_MAX_LEN ,"%s_%s" , qat_pci_dev->name,"sym" );QAT_LOG (DEBUG ,"Creating QAT SYM device %s" , name);
@@ -381,8 +377,7 @@ qat_sym_dev_create(struct qat_pci_device *qat_pci_dev,RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT |RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT |RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT | -RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED | -RTE_CRYPTODEV_FF_SECURITY ; +RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED ;if (rte_eal_process_type () !=RTE_PROC_PRIMARY )return 0 ;
@@ -392,19 +387,21 @@ qat_sym_dev_create(struct qat_pci_device *qat_pci_dev, qat_pci_dev->qat_dev_gen);#ifdef RTE_LIBRTE_SECURITY +struct rte_security_ctx *security_instance; security_instance =rte_malloc ("qat_sec" ,sizeof (struct rte_security_ctx ),RTE_CACHE_LINE_SIZE );if (security_instance ==NULL ) {QAT_LOG (ERR ,"rte_security_ctx memory alloc failed" ); -rte_cryptodev_pmd_destroy (cryptodev); -return -ENOMEM ; + ret = -ENOMEM ; + goto error; } security_instance->device = (void *)cryptodev; security_instance->ops = &security_qat_ops; security_instance->sess_cnt =0 ; cryptodev->security_ctx = security_instance; + cryptodev->feature_flags |=RTE_CRYPTODEV_FF_SECURITY ;#endif internals = cryptodev->data->dev_private;
@@ -428,10 +425,8 @@ qat_sym_dev_create(struct qat_pci_device *qat_pci_dev,QAT_LOG (DEBUG ,"QAT gen %d capabilities unknown" , qat_pci_dev->qat_dev_gen); -rte_cryptodev_pmd_destroy (cryptodev); -memset (&qat_dev_instance->sym_rte_dev,0 , -sizeof (qat_dev_instance->sym_rte_dev)); -return -(EINVAL ); + ret = -(EINVAL ); + goto error; } internals->capa_mz =rte_memzone_lookup (capa_memz_name);
@@ -442,12 +437,11 @@ qat_sym_dev_create(struct qat_pci_device *qat_pci_dev, }if (internals->capa_mz ==NULL ) {QAT_LOG (DEBUG , -"Error allocating memzone for capabilities, destroying PMD for %s" , +"Error allocating memzone for capabilities, destroying " +"PMD for %s" , name); -rte_cryptodev_pmd_destroy (cryptodev); -memset (&qat_dev_instance->sym_rte_dev,0 , -sizeof (qat_dev_instance->sym_rte_dev)); -return -EFAULT ; + ret = -EFAULT ; + goto error; }memcpy (internals->capa_mz->addr, capabilities, capa_size);
@@ -467,6 +461,17 @@ qat_sym_dev_create(struct qat_pci_device *qat_pci_dev, cryptodev->data->name, internals->sym_dev_id);return 0 ; + +error: +#ifdef RTE_LIBRTE_SECURITY +rte_free (cryptodev->security_ctx); + cryptodev->security_ctx =NULL ; +#endif +rte_cryptodev_pmd_destroy (cryptodev); +memset (&qat_dev_instance->sym_rte_dev,0 , +sizeof (qat_dev_instance->sym_rte_dev)); + +return ret; }int
@@ -485,6 +490,7 @@ qat_sym_dev_destroy(struct qat_pci_device *qat_pci_dev) cryptodev =rte_cryptodev_pmd_get_dev (qat_pci_dev->sym_dev->sym_dev_id);#ifdef RTE_LIBRTE_SECURITY rte_free (cryptodev->security_ctx); + cryptodev->security_ctx =NULL ;#endif rte_cryptodev_pmd_destroy (cryptodev); qat_pci_devs[qat_pci_dev->qat_dev_id].sym_rte_dev.name =NULL ;
Signature · 1 line
2.17.1
PATCH v2 2/2 crypto/aesni-mb: improve security instance setup
In reply to David CoyleThis patch makes some improvements to the security instance setup for the AESNI-MB PMD, as follows:
- fix potential memory leak where the security instance was not freed if an error occurred later in the device creation
- tidy-up security instance initialization code by moving it all, including enabling the RTE_CRYPTODEV_FF_SECURITY feature, into one '#ifdef AESNI_MB_DOCSIS_SEC_ENABLED' block
--- drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c +9 -9
@@ -1881,9 +1881,6 @@ cryptodev_aesni_mb_create(const char *name,struct aesni_mb_private *internals;enum aesni_mb_vector_mode vector_mode;MB_MGR *mb_mgr; -#ifdef AESNI_MB_DOCSIS_SEC_ENABLED -struct rte_security_ctx *security_instance; -#endif dev =rte_cryptodev_pmd_create (name, &vdev->device, init_params);if (dev ==NULL ) {
@@ -1912,13 +1909,10 @@ cryptodev_aesni_mb_create(const char *name,RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING |RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT |RTE_CRYPTODEV_FF_SYM_CPU_CRYPTO | - RTE_CRYPTODEV_FF_SYM_SESSIONLESS -#ifdef AESNI_MB_DOCSIS_SEC_ENABLED - |RTE_CRYPTODEV_FF_SECURITY -#endif - ; +RTE_CRYPTODEV_FF_SYM_SESSIONLESS ;#ifdef AESNI_MB_DOCSIS_SEC_ENABLED +struct rte_security_ctx *security_instance; security_instance =rte_malloc ("aesni_mb_sec" ,sizeof (struct rte_security_ctx ),RTE_CACHE_LINE_SIZE );
@@ -1932,6 +1926,7 @@ cryptodev_aesni_mb_create(const char *name, security_instance->ops = rte_aesni_mb_pmd_sec_ops; security_instance->sess_cnt =0 ; dev->security_ctx = security_instance; + dev->feature_flags |=RTE_CRYPTODEV_FF_SECURITY ;#endif /* Check CPU for support for AES instruction set */
@@ -1944,6 +1939,10 @@ cryptodev_aesni_mb_create(const char *name, mb_mgr =alloc_init_mb_mgr (vector_mode);if (mb_mgr ==NULL ) { +#ifdef AESNI_MB_DOCSIS_SEC_ENABLED +rte_free (dev->security_ctx); + dev->security_ctx =NULL ; +#endif rte_cryptodev_pmd_destroy (dev);return -ENOMEM ; }
@@ -2011,8 +2010,9 @@ cryptodev_aesni_mb_remove(struct rte_vdev_device *vdev)RTE_PER_LCORE (sync_mb_mgr) =NULL ; } -#ifdef RTE_LIBRTE_SECURITY +#ifdef AESNI_MB_DOCSIS_SEC_ENABLED rte_free (cryptodev->security_ctx); + cryptodev->security_ctx =NULL ;#endif return rte_cryptodev_pmd_destroy (cryptodev);
Signature · 1 line
2.17.1
Re: [dpdk-dev] [PATCH v2 2/2] crypto/aesni-mb: improve security instance setup
Quoted 20 lines
-----Original Message-----
From: Coyle, David <[email protected]>
Sent: Monday, July 20, 2020 1:16 PM
To: [email protected]; Doherty, Declan <[email protected]>; De Lara Guarch, Pablo <[email protected]>; Trahe, Fiona <[email protected]>
Cc: [email protected]; Ryan, Brendan <[email protected]>; O'loingsigh, Mairtin <[email protected]>; Coyle, David <[email protected]>
Subject: [PATCH v2 2/2]crypto/aesni-mb: improve security instance setupThis patch makes some improvements to the security instance setup for the AESNI-MB PMD, as follows:
- fix potential memory leak where the security instance was not freed if an error occurred later in the device creation
- tidy-up security instance initialization code by moving it all, including enabling theRTE_CRYPTODEV_FF_SECURITYfeature, into one '#ifdefAESNI_MB_DOCSIS_SEC_ENABLED' block
Quoted 3 lines
Fixes fda5216fba55 ("crypto/aesni_mb: support DOCSIS protocol")Signed-off-by David Coyle <[email protected]>
Quoted 4 lines
These patches make some improvements to the security instance setup for the QAT SYM and AESNI-MB PMDs.
Series Applied to dpdk-next-crypto
Thanks.