* [dpdk-dev] [PATCH] cryptodev: fix invalid dev_id after a pmd close
@ 2019-08-07 8:39 Julien Meunier
2019-10-03 12:49 ` Akhil Goyal
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Julien Meunier @ 2019-08-07 8:39 UTC (permalink / raw)
To: Pablo de Lara, Declan Doherty; +Cc: dev, stable
Each cryptodev are indexed with its 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 is 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.
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.
Fixes: d11b0f30df88 ("cryptodev: introduce API and framework for crypto devices")
Cc: stable@dpdk.org
Signed-off-by: Julien Meunier <julien.meunier@nokia.com>
---
lib/librte_cryptodev/rte_cryptodev.c | 42 ++++++++++++++++++++++++------------
1 file changed, 28 insertions(+), 14 deletions(-)
diff --git a/lib/librte_cryptodev/rte_cryptodev.c b/lib/librte_cryptodev/rte_cryptodev.c
index 43bc335..c8c7ffd 100644
--- a/lib/librte_cryptodev/rte_cryptodev.c
+++ b/lib/librte_cryptodev/rte_cryptodev.c
@@ -49,9 +49,7 @@ struct rte_cryptodev *rte_cryptodevs = rte_crypto_devices;
static struct rte_cryptodev_global cryptodev_globals = {
.devs = rte_crypto_devices,
- .data = { NULL },
- .nb_devs = 0,
- .max_devs = RTE_CRYPTO_MAX_DEVS
+ .data = { NULL }
};
/* spinlock for crypto device callbacks */
@@ -512,7 +510,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_CRYPTO_MAX_DEVS; i++) {
dev = &cryptodev_globals.devs[i];
if ((dev->attached == RTE_CRYPTODEV_ATTACHED) &&
@@ -523,12 +521,21 @@ rte_cryptodev_pmd_get_named_dev(const char *name)
return NULL;
}
+static 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 >= 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 +554,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_CRYPTO_MAX_DEVS; i++) {
+ if (!rte_cryptodev_is_valid_device_data(i))
+ continue;
if ((strcmp(cryptodev_globals.devs[i].data->name, name)
== 0) &&
(cryptodev_globals.devs[i].attached ==
RTE_CRYPTODEV_ATTACHED))
return i;
+ }
return -1;
}
@@ -560,7 +570,13 @@ rte_cryptodev_get_dev_id(const char *name)
uint8_t
rte_cryptodev_count(void)
{
- return cryptodev_globals.nb_devs;
+ uint8_t i, dev_count = 0;
+
+ for (i = 0; i < RTE_CRYPTO_MAX_DEVS; i++)
+ if (cryptodev_globals.devs[i].data != NULL)
+ dev_count++;
+
+ return dev_count;
}
uint8_t
@@ -568,7 +584,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_CRYPTO_MAX_DEVS; i++)
if (cryptodev_globals.devs[i].driver_id == driver_id &&
cryptodev_globals.devs[i].attached ==
RTE_CRYPTODEV_ATTACHED)
@@ -583,9 +599,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;
- 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;
@@ -736,8 +753,6 @@ rte_cryptodev_pmd_allocate(const char *name, int socket_id)
TAILQ_INIT(&(cryptodev->link_intr_cbs));
cryptodev->attached = RTE_CRYPTODEV_ATTACHED;
-
- cryptodev_globals.nb_devs++;
}
return cryptodev;
@@ -766,7 +781,6 @@ rte_cryptodev_pmd_release_device(struct rte_cryptodev *cryptodev)
return ret;
cryptodev->attached = RTE_CRYPTODEV_DETACHED;
- cryptodev_globals.nb_devs--;
return 0;
}
@@ -1099,7 +1113,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;
}
--
2.10.2
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [dpdk-dev] [PATCH] cryptodev: fix invalid dev_id after a pmd close
2019-08-07 8:39 [dpdk-dev] [PATCH] cryptodev: fix invalid dev_id after a pmd close Julien Meunier
@ 2019-10-03 12:49 ` Akhil Goyal
2019-10-15 13:44 ` Akhil Goyal
2019-10-15 16:50 ` [dpdk-dev] [PATCH v2] cryptodev: fix check related to device id Julien Meunier
2019-10-16 10:21 ` [dpdk-dev] [PATCH v3] " Julien Meunier
2 siblings, 1 reply; 9+ messages in thread
From: Akhil Goyal @ 2019-10-03 12:49 UTC (permalink / raw)
To: Julien Meunier, Pablo de Lara, Declan Doherty; +Cc: dev, stable
Hi Julien
>
> Each cryptodev are indexed with its 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 is 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.
>
> 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.
>
> Fixes: d11b0f30df88 ("cryptodev: introduce API and framework for crypto
> devices")
> Cc: stable@dpdk.org
>
> Signed-off-by: Julien Meunier <julien.meunier@nokia.com>
> ---
> lib/librte_cryptodev/rte_cryptodev.c | 42 ++++++++++++++++++++++++----------
> --
> 1 file changed, 28 insertions(+), 14 deletions(-)
>
> diff --git a/lib/librte_cryptodev/rte_cryptodev.c
> b/lib/librte_cryptodev/rte_cryptodev.c
> index 43bc335..c8c7ffd 100644
> --- a/lib/librte_cryptodev/rte_cryptodev.c
> +++ b/lib/librte_cryptodev/rte_cryptodev.c
> @@ -49,9 +49,7 @@ struct rte_cryptodev *rte_cryptodevs = rte_crypto_devices;
>
> static struct rte_cryptodev_global cryptodev_globals = {
> .devs = rte_crypto_devices,
> - .data = { NULL },
> - .nb_devs = 0,
> - .max_devs = RTE_CRYPTO_MAX_DEVS
> + .data = { NULL }
> };
>
> /* spinlock for crypto device callbacks */
> @@ -512,7 +510,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_CRYPTO_MAX_DEVS; i++) {
> dev = &cryptodev_globals.devs[i];
>
> if ((dev->attached == RTE_CRYPTODEV_ATTACHED) &&
> @@ -523,12 +521,21 @@ rte_cryptodev_pmd_get_named_dev(const char
> *name)
> return NULL;
> }
>
> +static 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 >= 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 +554,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_CRYPTO_MAX_DEVS; i++) {
> + if (!rte_cryptodev_is_valid_device_data(i))
> + continue;
> if ((strcmp(cryptodev_globals.devs[i].data->name, name)
> == 0) &&
> (cryptodev_globals.devs[i].attached ==
> RTE_CRYPTODEV_ATTACHED))
> return i;
> + }
>
> return -1;
> }
> @@ -560,7 +570,13 @@ rte_cryptodev_get_dev_id(const char *name)
> uint8_t
> rte_cryptodev_count(void)
> {
> - return cryptodev_globals.nb_devs;
> + uint8_t i, dev_count = 0;
> +
> + for (i = 0; i < RTE_CRYPTO_MAX_DEVS; i++)
> + if (cryptodev_globals.devs[i].data != NULL)
> + dev_count++;
> +
> + return dev_count;
> }
Why do you want to remove the nb_devs? We can have it updated (incremented/decremented)
While allocate/release of the device.
The point is, whenever somebody call rte_cryptodev_count() it will do a lookup of valid data
pointer.
>
> uint8_t
> @@ -568,7 +584,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_CRYPTO_MAX_DEVS; i++)
> if (cryptodev_globals.devs[i].driver_id == driver_id &&
> cryptodev_globals.devs[i].attached ==
> RTE_CRYPTODEV_ATTACHED)
> @@ -583,9 +599,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;
>
> - 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;
> @@ -736,8 +753,6 @@ rte_cryptodev_pmd_allocate(const char *name, int
> socket_id)
> TAILQ_INIT(&(cryptodev->link_intr_cbs));
>
> cryptodev->attached = RTE_CRYPTODEV_ATTACHED;
> -
> - cryptodev_globals.nb_devs++;
> }
>
> return cryptodev;
> @@ -766,7 +781,6 @@ rte_cryptodev_pmd_release_device(struct
> rte_cryptodev *cryptodev)
> return ret;
>
> cryptodev->attached = RTE_CRYPTODEV_DETACHED;
> - cryptodev_globals.nb_devs--;
> return 0;
> }
>
> @@ -1099,7 +1113,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;
> }
> --
> 2.10.2
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [dpdk-dev] [PATCH] cryptodev: fix invalid dev_id after a pmd close
2019-10-03 12:49 ` Akhil Goyal
@ 2019-10-15 13:44 ` Akhil Goyal
2019-10-15 14:39 ` Meunier, Julien (Nokia - FR/Paris-Saclay)
0 siblings, 1 reply; 9+ messages in thread
From: Akhil Goyal @ 2019-10-15 13:44 UTC (permalink / raw)
To: Akhil Goyal, Julien Meunier, Pablo de Lara, Declan Doherty; +Cc: dev, stable
>
> Hi Julien
>
> >
> > Each cryptodev are indexed with its 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 is 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.
> >
> > 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.
> >
> > Fixes: d11b0f30df88 ("cryptodev: introduce API and framework for crypto
> > devices")
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Julien Meunier <julien.meunier@nokia.com>
> > ---
// snip//
> > @@ -560,7 +570,13 @@ rte_cryptodev_get_dev_id(const char *name)
> > uint8_t
> > rte_cryptodev_count(void)
> > {
> > - return cryptodev_globals.nb_devs;
> > + uint8_t i, dev_count = 0;
> > +
> > + for (i = 0; i < RTE_CRYPTO_MAX_DEVS; i++)
> > + if (cryptodev_globals.devs[i].data != NULL)
> > + dev_count++;
> > +
> > + return dev_count;
> > }
>
> Why do you want to remove the nb_devs? We can have it updated
> (incremented/decremented)
> While allocate/release of the device.
> The point is, whenever somebody call rte_cryptodev_count() it will do a lookup
> of valid data
> pointer.
Could you please do the requested change. This patch need to be integrated by this week.
Thanks.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [dpdk-dev] [PATCH] cryptodev: fix invalid dev_id after a pmd close
2019-10-15 13:44 ` Akhil Goyal
@ 2019-10-15 14:39 ` Meunier, Julien (Nokia - FR/Paris-Saclay)
0 siblings, 0 replies; 9+ messages in thread
From: Meunier, Julien (Nokia - FR/Paris-Saclay) @ 2019-10-15 14:39 UTC (permalink / raw)
To: Akhil Goyal, Pablo de Lara, Declan Doherty; +Cc: dev, stable
Hi
On 15/10/2019 15:44, Akhil Goyal wrote:
>
>>
>> Hi Julien
>>
>>>
>>> Each cryptodev are indexed with its 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 is 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.
>>>
>>> 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.
>>>
>>> Fixes: d11b0f30df88 ("cryptodev: introduce API and framework for crypto
>>> devices")
>>> Cc: stable@dpdk.org
>>>
>>> Signed-off-by: Julien Meunier <julien.meunier@nokia.com>
>>> ---
> // snip//
>
>>> @@ -560,7 +570,13 @@ rte_cryptodev_get_dev_id(const char *name)
>>> uint8_t
>>> rte_cryptodev_count(void)
>>> {
>>> - return cryptodev_globals.nb_devs;
>>> + uint8_t i, dev_count = 0;
>>> +
>>> + for (i = 0; i < RTE_CRYPTO_MAX_DEVS; i++)
>>> + if (cryptodev_globals.devs[i].data != NULL)
>>> + dev_count++;
>>> +
>>> + return dev_count;
>>> }
>>
>> Why do you want to remove the nb_devs? We can have it updated
>> (incremented/decremented)
>> While allocate/release of the device.
>> The point is, whenever somebody call rte_cryptodev_count() it will do a lookup
>> of valid data
>> pointer.
>
> Could you please do the requested change. This patch need to be integrated by this week.
>
> Thanks.
>
Sorry, I was busy on other tasks. I will propose a new patch today by
keeping the nb_devs field.
Regards.
--
Julien Meunier
^ permalink raw reply [flat|nested] 9+ messages in thread
* [dpdk-dev] [PATCH v2] cryptodev: fix check related to device id
2019-08-07 8:39 [dpdk-dev] [PATCH] cryptodev: fix invalid dev_id after a pmd close Julien Meunier
2019-10-03 12:49 ` Akhil Goyal
@ 2019-10-15 16:50 ` Julien Meunier
2019-10-16 7:02 ` Akhil Goyal
2019-10-16 10:21 ` [dpdk-dev] [PATCH v3] " Julien Meunier
2 siblings, 1 reply; 9+ messages in thread
From: Julien Meunier @ 2019-10-15 16:50 UTC (permalink / raw)
To: Declan Doherty; +Cc: dev, stable, akhil.goyal
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")
Cc: stable@dpdk.org
Signed-off-by: Julien Meunier <julien.meunier@nokia.com>
---
v2:
* Restore nb_devs
* Update headline (check-git-log.sh)
* Update commit log
lib/librte_cryptodev/rte_cryptodev.c | 30 +++++++++++++++++++++---------
1 file changed, 21 insertions(+), 9 deletions(-)
diff --git a/lib/librte_cryptodev/rte_cryptodev.c b/lib/librte_cryptodev/rte_cryptodev.c
index b16ef7b..933c38d 100644
--- a/lib/librte_cryptodev/rte_cryptodev.c
+++ b/lib/librte_cryptodev/rte_cryptodev.c
@@ -50,8 +50,7 @@
static struct rte_cryptodev_global cryptodev_globals = {
.devs = rte_crypto_devices,
.data = { NULL },
- .nb_devs = 0,
- .max_devs = RTE_CRYPTO_MAX_DEVS
+ .nb_devs = 0
};
/* spinlock for crypto device callbacks */
@@ -512,7 +511,7 @@ struct rte_cryptodev *
if (name == NULL)
return NULL;
- for (i = 0; i < cryptodev_globals.max_devs; i++) {
+ for (i = 0; i < RTE_CRYPTO_MAX_DEVS; i++) {
dev = &cryptodev_globals.devs[i];
if ((dev->attached == RTE_CRYPTODEV_ATTACHED) &&
@@ -523,12 +522,21 @@ struct rte_cryptodev *
return NULL;
}
+static 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 >= 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 @@ struct rte_cryptodev *
if (name == NULL)
return -1;
- for (i = 0; i < 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)
== 0) &&
(cryptodev_globals.devs[i].attached ==
RTE_CRYPTODEV_ATTACHED))
return i;
+ }
return -1;
}
@@ -568,7 +579,7 @@ struct rte_cryptodev *
{
uint8_t i, dev_count = 0;
- for (i = 0; i < 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 ==
RTE_CRYPTODEV_ATTACHED)
@@ -583,9 +594,10 @@ struct rte_cryptodev *
{
uint8_t i, count = 0;
struct rte_cryptodev *devs = cryptodev_globals.devs;
- uint8_t max_devs = 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;
@@ -1101,7 +1113,7 @@ struct rte_cryptodev *
{
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;
}
--
1.8.3.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [dpdk-dev] [PATCH v2] cryptodev: fix check related to device id
2019-10-15 16:50 ` [dpdk-dev] [PATCH v2] cryptodev: fix check related to device id Julien Meunier
@ 2019-10-16 7:02 ` Akhil Goyal
2019-10-16 7:16 ` Meunier, Julien (Nokia - FR/Paris-Saclay)
0 siblings, 1 reply; 9+ messages in thread
From: Akhil Goyal @ 2019-10-16 7:02 UTC (permalink / raw)
To: Julien Meunier, Declan Doherty
Cc: dev, stable, Anoob Joseph, Fiona Trahe, Ananyev, Konstantin
Hi Julien,
A couple of nits. Please see inline.
Apart from that
Acked-by: Akhil Goyal <akhil.goyal@nxp.com>
>
> 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")
> Cc: stable@dpdk.org
>
> Signed-off-by: Julien Meunier <julien.meunier@nokia.com>
> ---
> v2:
> * Restore nb_devs
> * Update headline (check-git-log.sh)
> * Update commit log
>
> lib/librte_cryptodev/rte_cryptodev.c | 30 +++++++++++++++++++++---------
> 1 file changed, 21 insertions(+), 9 deletions(-)
>
> diff --git a/lib/librte_cryptodev/rte_cryptodev.c
> b/lib/librte_cryptodev/rte_cryptodev.c
> index b16ef7b..933c38d 100644
> --- a/lib/librte_cryptodev/rte_cryptodev.c
> +++ b/lib/librte_cryptodev/rte_cryptodev.c
> @@ -50,8 +50,7 @@
> static struct rte_cryptodev_global cryptodev_globals = {
> .devs = rte_crypto_devices,
> .data = { NULL },
> - .nb_devs = 0,
> - .max_devs = RTE_CRYPTO_MAX_DEVS
> + .nb_devs = 0
> };
Max_devs field shall also be removed from struct rte_cryptodev_global in "lib/librte_cryptodev/rte_cryptodev_pmd.h"
>
> /* spinlock for crypto device callbacks */
> @@ -512,7 +511,7 @@ struct rte_cryptodev *
> if (name == NULL)
> return NULL;
>
> - for (i = 0; i < cryptodev_globals.max_devs; i++) {
> + for (i = 0; i < RTE_CRYPTO_MAX_DEVS; i++) {
> dev = &cryptodev_globals.devs[i];
>
> if ((dev->attached == RTE_CRYPTODEV_ATTACHED) &&
> @@ -523,12 +522,21 @@ struct rte_cryptodev *
> return NULL;
> }
>
> +static uint8_t
> +rte_cryptodev_is_valid_device_data(uint8_t dev_id)
> +{
> + if (rte_crypto_devices[dev_id].data == NULL)
> + return 0;
> +
> + return 1;
> +}
rte_cryptodev_is_valid_device_data should be a static inline function.
> +
> unsigned int
> rte_cryptodev_pmd_is_valid_dev(uint8_t dev_id)
> {
> struct rte_cryptodev *dev = NULL;
>
> - if (dev_id >= 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 @@ struct rte_cryptodev *
> if (name == NULL)
> return -1;
>
> - for (i = 0; i < 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)
> == 0) &&
> (cryptodev_globals.devs[i].attached ==
> RTE_CRYPTODEV_ATTACHED))
> return i;
> + }
>
> return -1;
> }
> @@ -568,7 +579,7 @@ struct rte_cryptodev *
> {
> uint8_t i, dev_count = 0;
>
> - for (i = 0; i < 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 ==
> RTE_CRYPTODEV_ATTACHED)
> @@ -583,9 +594,10 @@ struct rte_cryptodev *
> {
> uint8_t i, count = 0;
> struct rte_cryptodev *devs = cryptodev_globals.devs;
> - uint8_t max_devs = 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;
> @@ -1101,7 +1113,7 @@ struct rte_cryptodev *
> {
> 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;
> }
> --
> 1.8.3.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [dpdk-dev] [PATCH v2] cryptodev: fix check related to device id
2019-10-16 7:02 ` Akhil Goyal
@ 2019-10-16 7:16 ` Meunier, Julien (Nokia - FR/Paris-Saclay)
0 siblings, 0 replies; 9+ messages in thread
From: Meunier, Julien (Nokia - FR/Paris-Saclay) @ 2019-10-16 7:16 UTC (permalink / raw)
To: Akhil Goyal, Declan Doherty
Cc: dev, stable, Anoob Joseph, Fiona Trahe, Ananyev, Konstantin
Hi,
Inline reply
On 16/10/2019 09:02, Akhil Goyal wrote:
> Hi Julien,
>
> A couple of nits. Please see inline.
>
> Apart from that
> Acked-by: Akhil Goyal <akhil.goyal@nxp.com>
>
>>
>> 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")
>> Cc: stable@dpdk.org
>>
>> Signed-off-by: Julien Meunier <julien.meunier@nokia.com>
>> ---
>> v2:
>> * Restore nb_devs
>> * Update headline (check-git-log.sh)
>> * Update commit log
>>
>> lib/librte_cryptodev/rte_cryptodev.c | 30 +++++++++++++++++++++---------
>> 1 file changed, 21 insertions(+), 9 deletions(-)
>>
>> diff --git a/lib/librte_cryptodev/rte_cryptodev.c
>> b/lib/librte_cryptodev/rte_cryptodev.c
>> index b16ef7b..933c38d 100644
>> --- a/lib/librte_cryptodev/rte_cryptodev.c
>> +++ b/lib/librte_cryptodev/rte_cryptodev.c
>> @@ -50,8 +50,7 @@
>> static struct rte_cryptodev_global cryptodev_globals = {
>> .devs = rte_crypto_devices,
>> .data = { NULL },
>> - .nb_devs = 0,
>> - .max_devs = RTE_CRYPTO_MAX_DEVS
>> + .nb_devs = 0
>> };
>
> Max_devs field shall also be removed from struct rte_cryptodev_global in "lib/librte_cryptodev/rte_cryptodev_pmd.h"
Oops, yes, I didn't clean-up all the code :) I will do that.
>>
>> /* spinlock for crypto device callbacks */
>> @@ -512,7 +511,7 @@ struct rte_cryptodev *
>> if (name == NULL)
>> return NULL;
>>
>> - for (i = 0; i < cryptodev_globals.max_devs; i++) {
>> + for (i = 0; i < RTE_CRYPTO_MAX_DEVS; i++) {
>> dev = &cryptodev_globals.devs[i];
>>
>> if ((dev->attached == RTE_CRYPTODEV_ATTACHED) &&
>> @@ -523,12 +522,21 @@ struct rte_cryptodev *
>> return NULL;
>> }
>>
>> +static uint8_t
>> +rte_cryptodev_is_valid_device_data(uint8_t dev_id)
>> +{
>> + if (rte_crypto_devices[dev_id].data == NULL)
>> + return 0;
>> +
>> + return 1;
>> +}
>
> rte_cryptodev_is_valid_device_data should be a static inline function.
OK.
>
>> +
>> unsigned int
>> rte_cryptodev_pmd_is_valid_dev(uint8_t dev_id)
>> {
>> struct rte_cryptodev *dev = NULL;
>>
>> - if (dev_id >= 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 @@ struct rte_cryptodev *
>> if (name == NULL)
>> return -1;
>>
>> - for (i = 0; i < 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)
>> == 0) &&
>> (cryptodev_globals.devs[i].attached ==
>> RTE_CRYPTODEV_ATTACHED))
>> return i;
>> + }
>>
>> return -1;
>> }
>> @@ -568,7 +579,7 @@ struct rte_cryptodev *
>> {
>> uint8_t i, dev_count = 0;
>>
>> - for (i = 0; i < 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 ==
>> RTE_CRYPTODEV_ATTACHED)
>> @@ -583,9 +594,10 @@ struct rte_cryptodev *
>> {
>> uint8_t i, count = 0;
>> struct rte_cryptodev *devs = cryptodev_globals.devs;
>> - uint8_t max_devs = 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;
>> @@ -1101,7 +1113,7 @@ struct rte_cryptodev *
>> {
>> 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;
>> }
>> --
>> 1.8.3.1
>
Thanks,
--
Julien Meunier
^ permalink raw reply [flat|nested] 9+ messages in thread
* [dpdk-dev] [PATCH v3] cryptodev: fix check related to device id
2019-08-07 8:39 [dpdk-dev] [PATCH] cryptodev: fix invalid dev_id after a pmd close Julien Meunier
2019-10-03 12:49 ` Akhil Goyal
2019-10-15 16:50 ` [dpdk-dev] [PATCH v2] cryptodev: fix check related to device id Julien Meunier
@ 2019-10-16 10:21 ` Julien Meunier
2019-10-16 12:49 ` Akhil Goyal
2 siblings, 1 reply; 9+ messages in thread
From: Julien Meunier @ 2019-10-16 10:21 UTC (permalink / raw)
To: Declan Doherty; +Cc: dev, stable, akhil.goyal
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")
Cc: stable@dpdk.org
Signed-off-by: Julien Meunier <julien.meunier@nokia.com>
---
v3:
* Set rte_cryptodev_is_valid_device_data as inline
* Remove max_devs in rte_cryptodev_global
v2:
* Restore nb_devs
* Update headline (check-git-log.sh)
* Update commit log
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 b16ef7b..89aa2ed 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;
static struct rte_cryptodev_global cryptodev_globals = {
.devs = rte_crypto_devices,
.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)
if (name == NULL)
return NULL;
- for (i = 0; i < cryptodev_globals.max_devs; i++) {
+ for (i = 0; i < RTE_CRYPTO_MAX_DEVS; i++) {
dev = &cryptodev_globals.devs[i];
if ((dev->attached == RTE_CRYPTODEV_ATTACHED) &&
@@ -523,12 +522,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 >= 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)
if (name == NULL)
return -1;
- for (i = 0; i < 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)
== 0) &&
(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)
{
uint8_t i, dev_count = 0;
- for (i = 0; i < 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 ==
RTE_CRYPTODEV_ATTACHED)
@@ -583,9 +594,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;
- 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;
@@ -1101,7 +1113,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 defe05e..fba14f2 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 {
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.10.2
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [dpdk-dev] [PATCH v3] cryptodev: fix check related to device id
2019-10-16 10:21 ` [dpdk-dev] [PATCH v3] " Julien Meunier
@ 2019-10-16 12:49 ` Akhil Goyal
0 siblings, 0 replies; 9+ messages in thread
From: Akhil Goyal @ 2019-10-16 12:49 UTC (permalink / raw)
To: Julien Meunier, Declan Doherty; +Cc: dev, stable
>
> 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")
> Cc: stable@dpdk.org
>
> Signed-off-by: Julien Meunier <julien.meunier@nokia.com>
Acked-by: Akhil Goyal <akhil.goyal@nxp.com>
Applied to dpdk-next-crypto
Thanks.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2019-10-16 12:49 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-07 8:39 [dpdk-dev] [PATCH] cryptodev: fix invalid dev_id after a pmd close Julien Meunier
2019-10-03 12:49 ` Akhil Goyal
2019-10-15 13:44 ` Akhil Goyal
2019-10-15 14:39 ` Meunier, Julien (Nokia - FR/Paris-Saclay)
2019-10-15 16:50 ` [dpdk-dev] [PATCH v2] cryptodev: fix check related to device id Julien Meunier
2019-10-16 7:02 ` Akhil Goyal
2019-10-16 7:16 ` Meunier, Julien (Nokia - FR/Paris-Saclay)
2019-10-16 10:21 ` [dpdk-dev] [PATCH v3] " Julien Meunier
2019-10-16 12:49 ` Akhil Goyal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).