patches for DPDK stable branches
 help / color / mirror / Atom feed
From: Akhil Goyal <akhil.goyal@nxp.com>
To: Julien Meunier <julien.meunier@nokia.com>,
	Declan Doherty <declan.doherty@intel.com>
Cc: "dev@dpdk.org" <dev@dpdk.org>,
	"stable@dpdk.org" <stable@dpdk.org>,
	Anoob Joseph <anoobj@marvell.com>,
	Fiona Trahe <fiona.trahe@intel.com>,
	"Ananyev, Konstantin" <konstantin.ananyev@intel.com>
Subject: Re: [dpdk-stable] [PATCH v2] cryptodev: fix check related to device id
Date: Wed, 16 Oct 2019 07:02:15 +0000	[thread overview]
Message-ID: <VE1PR04MB6639A3DEEB9295CFC9980EB8E6920@VE1PR04MB6639.eurprd04.prod.outlook.com> (raw)
In-Reply-To: <20191015165034.24276-1-julien.meunier@nokia.com>

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


  reply	other threads:[~2019-10-16  7:02 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-07  8:39 [dpdk-stable] [PATCH] cryptodev: fix invalid dev_id after a pmd close Julien Meunier
2019-10-03 12:49 ` [dpdk-stable] [dpdk-dev] " 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-stable] [PATCH v2] cryptodev: fix check related to device id Julien Meunier
2019-10-16  7:02   ` Akhil Goyal [this message]
2019-10-16  7:16     ` Meunier, Julien (Nokia - FR/Paris-Saclay)
2019-10-16 10:21 ` [dpdk-stable] [PATCH v3] " Julien Meunier
2019-10-16 12:49   ` Akhil Goyal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=VE1PR04MB6639A3DEEB9295CFC9980EB8E6920@VE1PR04MB6639.eurprd04.prod.outlook.com \
    --to=akhil.goyal@nxp.com \
    --cc=anoobj@marvell.com \
    --cc=declan.doherty@intel.com \
    --cc=dev@dpdk.org \
    --cc=fiona.trahe@intel.com \
    --cc=julien.meunier@nokia.com \
    --cc=konstantin.ananyev@intel.com \
    --cc=stable@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).