[1/2] net/mlx4: fix crash in dev_info_get in secondary process

Message ID 20190712205425.17781-2-stephen@networkplumber.org (mailing list archive)
State Accepted, archived
Delegated to: Raslan Darawsheh
Headers
Series fix dev_info_get in mlx secondary process |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/intel-Performance-Testing success Performance Testing PASS
ci/mellanox-Performance-Testing success Performance Testing PASS
ci/Intel-compilation success Compilation OK

Commit Message

Stephen Hemminger July 12, 2019, 8:54 p.m. UTC
  mlx4_dev_info_get calls mlx4_get_ifname, but mlx4_get_ifname
uses priv->ctx which is not a valid pointer in a secondary
process. The fix is to cache the value in primary.

In the primary process, get and store the interface index of
the device so that secondary process can see it.

Bugzilla ID:320
Fixes: 61cbdd419478 ("net/mlx4: separate device control functions")
Cc: stable@dpdk.org
Reported-by: Suyang Ju <sju@paloaltonetworks.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/net/mlx4/mlx4.c        | 19 +++++++++----------
 drivers/net/mlx4/mlx4.h        |  1 +
 drivers/net/mlx4/mlx4_ethdev.c |  4 +---
 3 files changed, 11 insertions(+), 13 deletions(-)
  

Comments

Matan Azrad July 30, 2019, 1:48 p.m. UTC | #1
Hi Stephen

 From: Stephen Hemminger
> mlx4_dev_info_get calls mlx4_get_ifname, but mlx4_get_ifname uses priv-
> >ctx which is not a valid pointer in a secondary process. The fix is to cache the
> value in primary.
> 
> In the primary process, get and store the interface index of the device so
> that secondary process can see it.
> 
> Bugzilla ID:320
> Fixes: 61cbdd419478 ("net/mlx4: separate device control functions")
> Cc: stable@dpdk.org
> Reported-by: Suyang Ju <sju@paloaltonetworks.com>
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Matan Azrad <matan@mellanox.com>

Thanks for the fix.

> ---
>  drivers/net/mlx4/mlx4.c        | 19 +++++++++----------
>  drivers/net/mlx4/mlx4.h        |  1 +
>  drivers/net/mlx4/mlx4_ethdev.c |  4 +---
>  3 files changed, 11 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/net/mlx4/mlx4.c b/drivers/net/mlx4/mlx4.c index
> 2e169b0887a7..bab2cadbe519 100644
> --- a/drivers/net/mlx4/mlx4.c
> +++ b/drivers/net/mlx4/mlx4.c
> @@ -763,6 +763,7 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct
> rte_pci_device *pci_dev)
>  	};
>  	unsigned int vf;
>  	int i;
> +	char ifname[IF_NAMESIZE];
> 
>  	(void)pci_drv;
>  	err = mlx4_init_once();
> @@ -1002,17 +1003,15 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv,
> struct rte_pci_device *pci_dev)
>  		     mac.addr_bytes[4], mac.addr_bytes[5]);
>  		/* Register MAC address. */
>  		priv->mac[0] = mac;
> -#ifndef NDEBUG
> -		{
> -			char ifname[IF_NAMESIZE];
> -
> -			if (mlx4_get_ifname(priv, &ifname) == 0)
> -				DEBUG("port %u ifname is \"%s\"",
> -				      priv->port, ifname);
> -			else
> -				DEBUG("port %u ifname is unknown", priv-
> >port);
> +
> +		if (mlx4_get_ifname(priv, &ifname) == 0) {
> +			DEBUG("port %u ifname is \"%s\"",
> +			      priv->port, ifname);
> +			priv->if_index = if_nametoindex(ifname);
> +		} else {
> +			DEBUG("port %u ifname is unknown", priv->port);
>  		}
> -#endif
> +
>  		/* Get actual MTU if possible. */
>  		mlx4_mtu_get(priv, &priv->mtu);
>  		DEBUG("port %u MTU is %u", priv->port, priv->mtu); diff --git
> a/drivers/net/mlx4/mlx4.h b/drivers/net/mlx4/mlx4.h index
> cd0d637ac2bf..81b529ee8030 100644
> --- a/drivers/net/mlx4/mlx4.h
> +++ b/drivers/net/mlx4/mlx4.h
> @@ -159,6 +159,7 @@ struct mlx4_priv {
>  	struct ibv_device_attr device_attr; /**< Device properties. */
>  	struct ibv_pd *pd; /**< Protection Domain. */
>  	/* Device properties. */
> +	unsigned int if_index;	/**< Associated network device index */
>  	uint16_t mtu; /**< Configured MTU. */
>  	uint8_t port; /**< Physical port number. */
>  	uint32_t started:1; /**< Device started, flows enabled. */ diff --git
> a/drivers/net/mlx4/mlx4_ethdev.c b/drivers/net/mlx4/mlx4_ethdev.c index
> ceef921620a8..5d28c0116d21 100644
> --- a/drivers/net/mlx4/mlx4_ethdev.c
> +++ b/drivers/net/mlx4/mlx4_ethdev.c
> @@ -616,7 +616,6 @@ mlx4_dev_infos_get(struct rte_eth_dev *dev, struct
> rte_eth_dev_info *info)  {
>  	struct mlx4_priv *priv = dev->data->dev_private;
>  	unsigned int max;
> -	char ifname[IF_NAMESIZE];
> 
>  	/* FIXME: we should ask the device for these values. */
>  	info->min_rx_bufsize = 32;
> @@ -637,8 +636,7 @@ mlx4_dev_infos_get(struct rte_eth_dev *dev, struct
> rte_eth_dev_info *info)
>  	info->rx_queue_offload_capa = mlx4_get_rx_queue_offloads(priv);
>  	info->rx_offload_capa = (mlx4_get_rx_port_offloads(priv) |
>  				 info->rx_queue_offload_capa);
> -	if (mlx4_get_ifname(priv, &ifname) == 0)
> -		info->if_index = if_nametoindex(ifname);
> +	info->if_index = priv->if_index;
>  	info->hash_key_size = MLX4_RSS_HASH_KEY_SIZE;
>  	info->speed_capa =
>  			ETH_LINK_SPEED_1G |
> --
> 2.20.1
  
Raslan Darawsheh Aug. 4, 2019, 6:57 a.m. UTC | #2
Hi Stephen, 

Wrong headline format:
        net/mlx4: fix crash in dev_info_get in secondary process
can you please fix it? You shouldn't use the _ in the title format

Kindest regards,
Raslan Darawsheh

> -----Original Message-----
> From: dev <dev-bounces@dpdk.org> On Behalf Of Stephen Hemminger
> Sent: Friday, July 12, 2019 11:54 PM
> To: Matan Azrad <matan@mellanox.com>; Shahaf Shuler
> <shahafs@mellanox.com>; Yongseok Koh <yskoh@mellanox.com>; Slava
> Ovsiienko <viacheslavo@mellanox.com>
> Cc: dev@dpdk.org; sju@paloaltonetworks.com; Stephen Hemminger
> <stephen@networkplumber.org>; stable@dpdk.org
> Subject: [dpdk-dev] [PATCH 1/2] net/mlx4: fix crash in dev_info_get in
> secondary process
> 
> mlx4_dev_info_get calls mlx4_get_ifname, but mlx4_get_ifname
> uses priv->ctx which is not a valid pointer in a secondary
> process. The fix is to cache the value in primary.
> 
> In the primary process, get and store the interface index of
> the device so that secondary process can see it.
> 
> Bugzilla ID:320
> Fixes: 61cbdd419478 ("net/mlx4: separate device control functions")
> Cc: stable@dpdk.org
> Reported-by: Suyang Ju <sju@paloaltonetworks.com>
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
>  drivers/net/mlx4/mlx4.c        | 19 +++++++++----------
>  drivers/net/mlx4/mlx4.h        |  1 +
>  drivers/net/mlx4/mlx4_ethdev.c |  4 +---
>  3 files changed, 11 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/net/mlx4/mlx4.c b/drivers/net/mlx4/mlx4.c
> index 2e169b0887a7..bab2cadbe519 100644
> --- a/drivers/net/mlx4/mlx4.c
> +++ b/drivers/net/mlx4/mlx4.c
> @@ -763,6 +763,7 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct
> rte_pci_device *pci_dev)
>  	};
>  	unsigned int vf;
>  	int i;
> +	char ifname[IF_NAMESIZE];
> 
>  	(void)pci_drv;
>  	err = mlx4_init_once();
> @@ -1002,17 +1003,15 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv,
> struct rte_pci_device *pci_dev)
>  		     mac.addr_bytes[4], mac.addr_bytes[5]);
>  		/* Register MAC address. */
>  		priv->mac[0] = mac;
> -#ifndef NDEBUG
> -		{
> -			char ifname[IF_NAMESIZE];
> -
> -			if (mlx4_get_ifname(priv, &ifname) == 0)
> -				DEBUG("port %u ifname is \"%s\"",
> -				      priv->port, ifname);
> -			else
> -				DEBUG("port %u ifname is unknown", priv-
> >port);
> +
> +		if (mlx4_get_ifname(priv, &ifname) == 0) {
> +			DEBUG("port %u ifname is \"%s\"",
> +			      priv->port, ifname);
> +			priv->if_index = if_nametoindex(ifname);
> +		} else {
> +			DEBUG("port %u ifname is unknown", priv->port);
>  		}
> -#endif
> +
>  		/* Get actual MTU if possible. */
>  		mlx4_mtu_get(priv, &priv->mtu);
>  		DEBUG("port %u MTU is %u", priv->port, priv->mtu);
> diff --git a/drivers/net/mlx4/mlx4.h b/drivers/net/mlx4/mlx4.h
> index cd0d637ac2bf..81b529ee8030 100644
> --- a/drivers/net/mlx4/mlx4.h
> +++ b/drivers/net/mlx4/mlx4.h
> @@ -159,6 +159,7 @@ struct mlx4_priv {
>  	struct ibv_device_attr device_attr; /**< Device properties. */
>  	struct ibv_pd *pd; /**< Protection Domain. */
>  	/* Device properties. */
> +	unsigned int if_index;	/**< Associated network device index */
>  	uint16_t mtu; /**< Configured MTU. */
>  	uint8_t port; /**< Physical port number. */
>  	uint32_t started:1; /**< Device started, flows enabled. */
> diff --git a/drivers/net/mlx4/mlx4_ethdev.c
> b/drivers/net/mlx4/mlx4_ethdev.c
> index ceef921620a8..5d28c0116d21 100644
> --- a/drivers/net/mlx4/mlx4_ethdev.c
> +++ b/drivers/net/mlx4/mlx4_ethdev.c
> @@ -616,7 +616,6 @@ mlx4_dev_infos_get(struct rte_eth_dev *dev, struct
> rte_eth_dev_info *info)
>  {
>  	struct mlx4_priv *priv = dev->data->dev_private;
>  	unsigned int max;
> -	char ifname[IF_NAMESIZE];
> 
>  	/* FIXME: we should ask the device for these values. */
>  	info->min_rx_bufsize = 32;
> @@ -637,8 +636,7 @@ mlx4_dev_infos_get(struct rte_eth_dev *dev, struct
> rte_eth_dev_info *info)
>  	info->rx_queue_offload_capa = mlx4_get_rx_queue_offloads(priv);
>  	info->rx_offload_capa = (mlx4_get_rx_port_offloads(priv) |
>  				 info->rx_queue_offload_capa);
> -	if (mlx4_get_ifname(priv, &ifname) == 0)
> -		info->if_index = if_nametoindex(ifname);
> +	info->if_index = priv->if_index;
>  	info->hash_key_size = MLX4_RSS_HASH_KEY_SIZE;
>  	info->speed_capa =
>  			ETH_LINK_SPEED_1G |
> --
> 2.20.1
  
Raslan Darawsheh Aug. 5, 2019, 7:42 a.m. UTC | #3
Hi,
> -----Original Message-----
> From: Raslan Darawsheh
> Sent: Sunday, August 4, 2019 9:58 AM
> To: Stephen Hemminger <stephen@networkplumber.org>; Matan Azrad
> <matan@mellanox.com>; Shahaf Shuler <shahafs@mellanox.com>;
> Yongseok Koh <yskoh@mellanox.com>; Slava Ovsiienko
> <viacheslavo@mellanox.com>
> Cc: dev@dpdk.org; sju@paloaltonetworks.com; stable@dpdk.org
> Subject: RE: [dpdk-dev] [PATCH 1/2] net/mlx4: fix crash in dev_info_get in
> secondary process
> 
> Hi Stephen,
> 
> Wrong headline format:
>         net/mlx4: fix crash in dev_info_get in secondary process can you please
> fix it? You shouldn't use the _ in the title format
> 
> Kindest regards,
> Raslan Darawsheh
> 
> > -----Original Message-----
> > From: dev <dev-bounces@dpdk.org> On Behalf Of Stephen Hemminger
> > Sent: Friday, July 12, 2019 11:54 PM
> > To: Matan Azrad <matan@mellanox.com>; Shahaf Shuler
> > <shahafs@mellanox.com>; Yongseok Koh <yskoh@mellanox.com>; Slava
> > Ovsiienko <viacheslavo@mellanox.com>
> > Cc: dev@dpdk.org; sju@paloaltonetworks.com; Stephen Hemminger
> > <stephen@networkplumber.org>; stable@dpdk.org
> > Subject: [dpdk-dev] [PATCH 1/2] net/mlx4: fix crash in dev_info_get in
> > secondary process
> >
> > mlx4_dev_info_get calls mlx4_get_ifname, but mlx4_get_ifname uses
> > priv->ctx which is not a valid pointer in a secondary process. The fix
> > is to cache the value in primary.
> >
> > In the primary process, get and store the interface index of the
> > device so that secondary process can see it.
> >
> > Bugzilla ID:320
> > Fixes: 61cbdd419478 ("net/mlx4: separate device control functions")
> > Cc: stable@dpdk.org
> > Reported-by: Suyang Ju <sju@paloaltonetworks.com>
> > Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> > ---
> >  drivers/net/mlx4/mlx4.c        | 19 +++++++++----------
> >  drivers/net/mlx4/mlx4.h        |  1 +
> >  drivers/net/mlx4/mlx4_ethdev.c |  4 +---
> >  3 files changed, 11 insertions(+), 13 deletions(-)
> >
> > diff --git a/drivers/net/mlx4/mlx4.c b/drivers/net/mlx4/mlx4.c index
> > 2e169b0887a7..bab2cadbe519 100644
> > --- a/drivers/net/mlx4/mlx4.c
> > +++ b/drivers/net/mlx4/mlx4.c
> > @@ -763,6 +763,7 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv,
> > struct rte_pci_device *pci_dev)
> >  	};
> >  	unsigned int vf;
> >  	int i;
> > +	char ifname[IF_NAMESIZE];
> >
> >  	(void)pci_drv;
> >  	err = mlx4_init_once();
> > @@ -1002,17 +1003,15 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv,
> > struct rte_pci_device *pci_dev)
> >  		     mac.addr_bytes[4], mac.addr_bytes[5]);
> >  		/* Register MAC address. */
> >  		priv->mac[0] = mac;
> > -#ifndef NDEBUG
> > -		{
> > -			char ifname[IF_NAMESIZE];
> > -
> > -			if (mlx4_get_ifname(priv, &ifname) == 0)
> > -				DEBUG("port %u ifname is \"%s\"",
> > -				      priv->port, ifname);
> > -			else
> > -				DEBUG("port %u ifname is unknown", priv-
> > >port);
> > +
> > +		if (mlx4_get_ifname(priv, &ifname) == 0) {
> > +			DEBUG("port %u ifname is \"%s\"",
> > +			      priv->port, ifname);
> > +			priv->if_index = if_nametoindex(ifname);
> > +		} else {
> > +			DEBUG("port %u ifname is unknown", priv->port);
> >  		}
> > -#endif
> > +
> >  		/* Get actual MTU if possible. */
> >  		mlx4_mtu_get(priv, &priv->mtu);
> >  		DEBUG("port %u MTU is %u", priv->port, priv->mtu); diff --git
> > a/drivers/net/mlx4/mlx4.h b/drivers/net/mlx4/mlx4.h index
> > cd0d637ac2bf..81b529ee8030 100644
> > --- a/drivers/net/mlx4/mlx4.h
> > +++ b/drivers/net/mlx4/mlx4.h
> > @@ -159,6 +159,7 @@ struct mlx4_priv {
> >  	struct ibv_device_attr device_attr; /**< Device properties. */
> >  	struct ibv_pd *pd; /**< Protection Domain. */
> >  	/* Device properties. */
> > +	unsigned int if_index;	/**< Associated network device index */
> >  	uint16_t mtu; /**< Configured MTU. */
> >  	uint8_t port; /**< Physical port number. */
> >  	uint32_t started:1; /**< Device started, flows enabled. */ diff
> > --git a/drivers/net/mlx4/mlx4_ethdev.c
> > b/drivers/net/mlx4/mlx4_ethdev.c index ceef921620a8..5d28c0116d21
> > 100644
> > --- a/drivers/net/mlx4/mlx4_ethdev.c
> > +++ b/drivers/net/mlx4/mlx4_ethdev.c
> > @@ -616,7 +616,6 @@ mlx4_dev_infos_get(struct rte_eth_dev *dev,
> struct
> > rte_eth_dev_info *info)  {
> >  	struct mlx4_priv *priv = dev->data->dev_private;
> >  	unsigned int max;
> > -	char ifname[IF_NAMESIZE];
> >
> >  	/* FIXME: we should ask the device for these values. */
> >  	info->min_rx_bufsize = 32;
> > @@ -637,8 +636,7 @@ mlx4_dev_infos_get(struct rte_eth_dev *dev,
> struct
> > rte_eth_dev_info *info)
> >  	info->rx_queue_offload_capa = mlx4_get_rx_queue_offloads(priv);
> >  	info->rx_offload_capa = (mlx4_get_rx_port_offloads(priv) |
> >  				 info->rx_queue_offload_capa);
> > -	if (mlx4_get_ifname(priv, &ifname) == 0)
> > -		info->if_index = if_nametoindex(ifname);
> > +	info->if_index = priv->if_index;
> >  	info->hash_key_size = MLX4_RSS_HASH_KEY_SIZE;
> >  	info->speed_capa =
> >  			ETH_LINK_SPEED_1G |
> > --
> > 2.20.1


Patch applied to next-net-mlx after fixing wrong headline format,

Kindest regards,
Raslan Darawsheh
  

Patch

diff --git a/drivers/net/mlx4/mlx4.c b/drivers/net/mlx4/mlx4.c
index 2e169b0887a7..bab2cadbe519 100644
--- a/drivers/net/mlx4/mlx4.c
+++ b/drivers/net/mlx4/mlx4.c
@@ -763,6 +763,7 @@  mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
 	};
 	unsigned int vf;
 	int i;
+	char ifname[IF_NAMESIZE];
 
 	(void)pci_drv;
 	err = mlx4_init_once();
@@ -1002,17 +1003,15 @@  mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
 		     mac.addr_bytes[4], mac.addr_bytes[5]);
 		/* Register MAC address. */
 		priv->mac[0] = mac;
-#ifndef NDEBUG
-		{
-			char ifname[IF_NAMESIZE];
-
-			if (mlx4_get_ifname(priv, &ifname) == 0)
-				DEBUG("port %u ifname is \"%s\"",
-				      priv->port, ifname);
-			else
-				DEBUG("port %u ifname is unknown", priv->port);
+
+		if (mlx4_get_ifname(priv, &ifname) == 0) {
+			DEBUG("port %u ifname is \"%s\"",
+			      priv->port, ifname);
+			priv->if_index = if_nametoindex(ifname);
+		} else {
+			DEBUG("port %u ifname is unknown", priv->port);
 		}
-#endif
+
 		/* Get actual MTU if possible. */
 		mlx4_mtu_get(priv, &priv->mtu);
 		DEBUG("port %u MTU is %u", priv->port, priv->mtu);
diff --git a/drivers/net/mlx4/mlx4.h b/drivers/net/mlx4/mlx4.h
index cd0d637ac2bf..81b529ee8030 100644
--- a/drivers/net/mlx4/mlx4.h
+++ b/drivers/net/mlx4/mlx4.h
@@ -159,6 +159,7 @@  struct mlx4_priv {
 	struct ibv_device_attr device_attr; /**< Device properties. */
 	struct ibv_pd *pd; /**< Protection Domain. */
 	/* Device properties. */
+	unsigned int if_index;	/**< Associated network device index */
 	uint16_t mtu; /**< Configured MTU. */
 	uint8_t port; /**< Physical port number. */
 	uint32_t started:1; /**< Device started, flows enabled. */
diff --git a/drivers/net/mlx4/mlx4_ethdev.c b/drivers/net/mlx4/mlx4_ethdev.c
index ceef921620a8..5d28c0116d21 100644
--- a/drivers/net/mlx4/mlx4_ethdev.c
+++ b/drivers/net/mlx4/mlx4_ethdev.c
@@ -616,7 +616,6 @@  mlx4_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info)
 {
 	struct mlx4_priv *priv = dev->data->dev_private;
 	unsigned int max;
-	char ifname[IF_NAMESIZE];
 
 	/* FIXME: we should ask the device for these values. */
 	info->min_rx_bufsize = 32;
@@ -637,8 +636,7 @@  mlx4_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info)
 	info->rx_queue_offload_capa = mlx4_get_rx_queue_offloads(priv);
 	info->rx_offload_capa = (mlx4_get_rx_port_offloads(priv) |
 				 info->rx_queue_offload_capa);
-	if (mlx4_get_ifname(priv, &ifname) == 0)
-		info->if_index = if_nametoindex(ifname);
+	info->if_index = priv->if_index;
 	info->hash_key_size = MLX4_RSS_HASH_KEY_SIZE;
 	info->speed_capa =
 			ETH_LINK_SPEED_1G |