[dpdk-stable] patch 'cryptodev: fix checks related to device id' has been queued to LTS release 17.11.10

luca.boccassi at gmail.com luca.boccassi at gmail.com
Thu Dec 19 15:33:20 CET 2019


Hi,

FYI, your patch has been queued to LTS release 17.11.10

Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet.
It will be pushed if I get no objections before 12/21/19. So please
shout if anyone has objections.

Also note that after the patch there's a diff of the upstream commit vs the
patch applied to the branch. This will indicate if there was any rebasing
needed to apply to the stable branch. If there were code changes for rebasing
(ie: not only metadata diffs), please double check that the rebase was
correctly done.

Thanks.

Luca Boccassi

---
>From 72de277dd423cb96413e11b82cf3c781b283e92e Mon Sep 17 00:00:00 2001
From: Julien Meunier <julien.meunier at nokia.com>
Date: Wed, 16 Oct 2019 13:21:11 +0300
Subject: [PATCH] cryptodev: fix checks related to device id

[ upstream commit 3dd4435cf473f5d10b99282098821fb40b72380f ]

Each cryptodev are indexed with dev_id in the global rte_crypto_devices
variable. nb_devs is incremented / decremented each time a cryptodev is
created / deleted. The goal of nb_devs was to prevent the user to get an
invalid dev_id.

Let's imagine DPDK has configured N cryptodevs. If the cryptodev=1 is
removed at runtime, the latest cryptodev N cannot be accessible, because
nb_devs=N-1 with the current implementaion.

In order to prevent this kind of behavior, let's remove the check with
nb_devs and iterate in all the rte_crypto_devices elements: if data is
not NULL, that means a valid cryptodev is available.

Also, remove max_devs field and use RTE_CRYPTO_MAX_DEVS in order to
unify the code.

Fixes: d11b0f30df88 ("cryptodev: introduce API and framework for crypto devices")

Signed-off-by: Julien Meunier <julien.meunier at nokia.com>
Acked-by: Akhil Goyal <akhil.goyal at nxp.com>
---
 lib/librte_cryptodev/rte_cryptodev.c     | 30 +++++++++++++++++-------
 lib/librte_cryptodev/rte_cryptodev_pmd.h |  1 -
 2 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/lib/librte_cryptodev/rte_cryptodev.c b/lib/librte_cryptodev/rte_cryptodev.c
index ee3a2447ef..cdce7824c3 100644
--- a/lib/librte_cryptodev/rte_cryptodev.c
+++ b/lib/librte_cryptodev/rte_cryptodev.c
@@ -78,8 +78,7 @@ struct rte_cryptodev *rte_cryptodevs = &rte_crypto_devices[0];
 static struct rte_cryptodev_global cryptodev_globals = {
 		.devs			= &rte_crypto_devices[0],
 		.data			= { NULL },
-		.nb_devs		= 0,
-		.max_devs		= RTE_CRYPTO_MAX_DEVS
+		.nb_devs		= 0
 };
 
 struct rte_cryptodev_global *rte_cryptodev_globals = &cryptodev_globals;
@@ -415,7 +414,7 @@ rte_cryptodev_pmd_get_named_dev(const char *name)
 	if (name == NULL)
 		return NULL;
 
-	for (i = 0; i < rte_cryptodev_globals->max_devs; i++) {
+	for (i = 0; i < RTE_CRYPTO_MAX_DEVS; i++) {
 		dev = &rte_cryptodev_globals->devs[i];
 
 		if ((dev->attached == RTE_CRYPTODEV_ATTACHED) &&
@@ -426,12 +425,21 @@ rte_cryptodev_pmd_get_named_dev(const char *name)
 	return NULL;
 }
 
+static inline uint8_t
+rte_cryptodev_is_valid_device_data(uint8_t dev_id)
+{
+	if (rte_crypto_devices[dev_id].data == NULL)
+		return 0;
+
+	return 1;
+}
+
 unsigned int
 rte_cryptodev_pmd_is_valid_dev(uint8_t dev_id)
 {
 	struct rte_cryptodev *dev = NULL;
 
-	if (dev_id >= rte_cryptodev_globals->nb_devs)
+	if (!rte_cryptodev_is_valid_device_data(dev_id))
 		return 0;
 
 	dev = rte_cryptodev_pmd_get_dev(dev_id);
@@ -450,12 +458,15 @@ rte_cryptodev_get_dev_id(const char *name)
 	if (name == NULL)
 		return -1;
 
-	for (i = 0; i < rte_cryptodev_globals->nb_devs; i++)
+	for (i = 0; i < RTE_CRYPTO_MAX_DEVS; i++) {
+		if (!rte_cryptodev_is_valid_device_data(i))
+			continue;
 		if ((strcmp(rte_cryptodev_globals->devs[i].data->name, name)
 				== 0) &&
 				(rte_cryptodev_globals->devs[i].attached ==
 						RTE_CRYPTODEV_ATTACHED))
 			return i;
+	}
 
 	return -1;
 }
@@ -471,7 +482,7 @@ rte_cryptodev_device_count_by_driver(uint8_t driver_id)
 {
 	uint8_t i, dev_count = 0;
 
-	for (i = 0; i < rte_cryptodev_globals->max_devs; i++)
+	for (i = 0; i < RTE_CRYPTO_MAX_DEVS; i++)
 		if (rte_cryptodev_globals->devs[i].driver_id == driver_id &&
 			rte_cryptodev_globals->devs[i].attached ==
 					RTE_CRYPTODEV_ATTACHED)
@@ -486,9 +497,10 @@ rte_cryptodev_devices_get(const char *driver_name, uint8_t *devices,
 {
 	uint8_t i, count = 0;
 	struct rte_cryptodev *devs = rte_cryptodev_globals->devs;
-	uint8_t max_devs = rte_cryptodev_globals->max_devs;
 
-	for (i = 0; i < max_devs && count < nb_devices;	i++) {
+	for (i = 0; i < RTE_CRYPTO_MAX_DEVS && count < nb_devices; i++) {
+		if (!rte_cryptodev_is_valid_device_data(i))
+			continue;
 
 		if (devs[i].attached == RTE_CRYPTODEV_ATTACHED) {
 			int cmp;
@@ -981,7 +993,7 @@ rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info)
 {
 	struct rte_cryptodev *dev;
 
-	if (dev_id >= cryptodev_globals.nb_devs) {
+	if (!rte_cryptodev_pmd_is_valid_dev(dev_id)) {
 		CDEV_LOG_ERR("Invalid dev_id=%d", dev_id);
 		return;
 	}
diff --git a/lib/librte_cryptodev/rte_cryptodev_pmd.h b/lib/librte_cryptodev/rte_cryptodev_pmd.h
index 089848e0b2..2b40717c36 100644
--- a/lib/librte_cryptodev/rte_cryptodev_pmd.h
+++ b/lib/librte_cryptodev/rte_cryptodev_pmd.h
@@ -92,7 +92,6 @@ struct rte_cryptodev_global {
 	struct rte_cryptodev_data *data[RTE_CRYPTO_MAX_DEVS];
 	/**< Device private data */
 	uint8_t nb_devs;		/**< Number of devices found */
-	uint8_t max_devs;		/**< Max number of devices */
 };
 
 /* Cryptodev driver, containing the driver ID */
-- 
2.20.1

---
  Diff of the applied patch vs upstream commit (please double-check if non-empty:
---
--- -	2019-12-19 14:32:28.436975562 +0000
+++ 0053-cryptodev-fix-checks-related-to-device-id.patch	2019-12-19 14:32:26.073297191 +0000
@@ -1,8 +1,10 @@
-From 3dd4435cf473f5d10b99282098821fb40b72380f Mon Sep 17 00:00:00 2001
+From 72de277dd423cb96413e11b82cf3c781b283e92e Mon Sep 17 00:00:00 2001
 From: Julien Meunier <julien.meunier at nokia.com>
 Date: Wed, 16 Oct 2019 13:21:11 +0300
 Subject: [PATCH] cryptodev: fix checks related to device id
 
+[ upstream commit 3dd4435cf473f5d10b99282098821fb40b72380f ]
+
 Each cryptodev are indexed with dev_id in the global rte_crypto_devices
 variable. nb_devs is incremented / decremented each time a cryptodev is
 created / deleted. The goal of nb_devs was to prevent the user to get an
@@ -20,7 +22,6 @@
 unify the code.
 
 Fixes: d11b0f30df88 ("cryptodev: introduce API and framework for crypto devices")
-Cc: stable at dpdk.org
 
 Signed-off-by: Julien Meunier <julien.meunier at nokia.com>
 Acked-by: Akhil Goyal <akhil.goyal at nxp.com>
@@ -30,29 +31,29 @@
  2 files changed, 21 insertions(+), 10 deletions(-)
 
 diff --git a/lib/librte_cryptodev/rte_cryptodev.c b/lib/librte_cryptodev/rte_cryptodev.c
-index b16ef7b2c1..89aa2ed3e2 100644
+index ee3a2447ef..cdce7824c3 100644
 --- a/lib/librte_cryptodev/rte_cryptodev.c
 +++ b/lib/librte_cryptodev/rte_cryptodev.c
-@@ -50,8 +50,7 @@ struct rte_cryptodev *rte_cryptodevs = rte_crypto_devices;
+@@ -78,8 +78,7 @@ struct rte_cryptodev *rte_cryptodevs = &rte_crypto_devices[0];
  static struct rte_cryptodev_global cryptodev_globals = {
- 		.devs			= rte_crypto_devices,
+ 		.devs			= &rte_crypto_devices[0],
  		.data			= { NULL },
 -		.nb_devs		= 0,
 -		.max_devs		= RTE_CRYPTO_MAX_DEVS
 +		.nb_devs		= 0
  };
  
- /* spinlock for crypto device callbacks */
-@@ -512,7 +511,7 @@ rte_cryptodev_pmd_get_named_dev(const char *name)
+ struct rte_cryptodev_global *rte_cryptodev_globals = &cryptodev_globals;
+@@ -415,7 +414,7 @@ rte_cryptodev_pmd_get_named_dev(const char *name)
  	if (name == NULL)
  		return NULL;
  
--	for (i = 0; i < cryptodev_globals.max_devs; i++) {
+-	for (i = 0; i < rte_cryptodev_globals->max_devs; i++) {
 +	for (i = 0; i < RTE_CRYPTO_MAX_DEVS; i++) {
- 		dev = &cryptodev_globals.devs[i];
+ 		dev = &rte_cryptodev_globals->devs[i];
  
  		if ((dev->attached == RTE_CRYPTODEV_ATTACHED) &&
-@@ -523,12 +522,21 @@ rte_cryptodev_pmd_get_named_dev(const char *name)
+@@ -426,12 +425,21 @@ rte_cryptodev_pmd_get_named_dev(const char *name)
  	return NULL;
  }
  
@@ -70,42 +71,42 @@
  {
  	struct rte_cryptodev *dev = NULL;
  
--	if (dev_id >= cryptodev_globals.nb_devs)
+-	if (dev_id >= rte_cryptodev_globals->nb_devs)
 +	if (!rte_cryptodev_is_valid_device_data(dev_id))
  		return 0;
  
  	dev = rte_cryptodev_pmd_get_dev(dev_id);
-@@ -547,12 +555,15 @@ rte_cryptodev_get_dev_id(const char *name)
+@@ -450,12 +458,15 @@ rte_cryptodev_get_dev_id(const char *name)
  	if (name == NULL)
  		return -1;
  
--	for (i = 0; i < cryptodev_globals.nb_devs; i++)
+-	for (i = 0; i < rte_cryptodev_globals->nb_devs; i++)
 +	for (i = 0; i < RTE_CRYPTO_MAX_DEVS; i++) {
 +		if (!rte_cryptodev_is_valid_device_data(i))
 +			continue;
- 		if ((strcmp(cryptodev_globals.devs[i].data->name, name)
+ 		if ((strcmp(rte_cryptodev_globals->devs[i].data->name, name)
  				== 0) &&
- 				(cryptodev_globals.devs[i].attached ==
+ 				(rte_cryptodev_globals->devs[i].attached ==
  						RTE_CRYPTODEV_ATTACHED))
  			return i;
 +	}
  
  	return -1;
  }
-@@ -568,7 +579,7 @@ rte_cryptodev_device_count_by_driver(uint8_t driver_id)
+@@ -471,7 +482,7 @@ rte_cryptodev_device_count_by_driver(uint8_t driver_id)
  {
  	uint8_t i, dev_count = 0;
  
--	for (i = 0; i < cryptodev_globals.max_devs; i++)
+-	for (i = 0; i < rte_cryptodev_globals->max_devs; i++)
 +	for (i = 0; i < RTE_CRYPTO_MAX_DEVS; i++)
- 		if (cryptodev_globals.devs[i].driver_id == driver_id &&
- 			cryptodev_globals.devs[i].attached ==
+ 		if (rte_cryptodev_globals->devs[i].driver_id == driver_id &&
+ 			rte_cryptodev_globals->devs[i].attached ==
  					RTE_CRYPTODEV_ATTACHED)
-@@ -583,9 +594,10 @@ rte_cryptodev_devices_get(const char *driver_name, uint8_t *devices,
+@@ -486,9 +497,10 @@ rte_cryptodev_devices_get(const char *driver_name, uint8_t *devices,
  {
  	uint8_t i, count = 0;
- 	struct rte_cryptodev *devs = cryptodev_globals.devs;
--	uint8_t max_devs = cryptodev_globals.max_devs;
+ 	struct rte_cryptodev *devs = rte_cryptodev_globals->devs;
+-	uint8_t max_devs = rte_cryptodev_globals->max_devs;
  
 -	for (i = 0; i < max_devs && count < nb_devices;	i++) {
 +	for (i = 0; i < RTE_CRYPTO_MAX_DEVS && count < nb_devices; i++) {
@@ -114,7 +115,7 @@
  
  		if (devs[i].attached == RTE_CRYPTODEV_ATTACHED) {
  			int cmp;
-@@ -1101,7 +1113,7 @@ rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info)
+@@ -981,7 +993,7 @@ rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info)
  {
  	struct rte_cryptodev *dev;
  
@@ -124,10 +125,10 @@
  		return;
  	}
 diff --git a/lib/librte_cryptodev/rte_cryptodev_pmd.h b/lib/librte_cryptodev/rte_cryptodev_pmd.h
-index defe05ea05..fba14f2fa0 100644
+index 089848e0b2..2b40717c36 100644
 --- a/lib/librte_cryptodev/rte_cryptodev_pmd.h
 +++ b/lib/librte_cryptodev/rte_cryptodev_pmd.h
-@@ -61,7 +61,6 @@ struct rte_cryptodev_global {
+@@ -92,7 +92,6 @@ struct rte_cryptodev_global {
  	struct rte_cryptodev_data *data[RTE_CRYPTO_MAX_DEVS];
  	/**< Device private data */
  	uint8_t nb_devs;		/**< Number of devices found */


More information about the stable mailing list