fix dev_info_get in mlx secondary process
cover fix dev_info_get in mlx secondary process
Both drivers had the same problem.
Stephen Hemminger (2):
net/mlx4: fix crash in dev_info_get in secondary process net/mlx5: fix crash in dev_info_get in secondary process
drivers/net/mlx4/mlx4.c | 19 +++++++++---------- drivers/net/mlx4/mlx4.h | 1 + drivers/net/mlx4/mlx4_ethdev.c | 4 +--- drivers/net/mlx5/mlx5.c | 17 ++++++++--------- drivers/net/mlx5/mlx5.h | 1 + drivers/net/mlx5/mlx5_ethdev.c | 4 +--- 6 files changed, 21 insertions(+), 25 deletions(-)
Signature · 1 line
2.20.1
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
--- 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(-)
drivers/net/mlx4/mlx4.c +9 -10
@@ -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);
drivers/net/mlx4/mlx4.h +1 -0
@@ -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. */
drivers/net/mlx4/mlx4_ethdev.c +1 -3
@@ -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 |
Signature · 1 line
2.20.1
Re: [dpdk-dev] [PATCH 1/2] net/mlx4: fix crash in dev_info_get in secondary process
Hi Stephen
From: Stephen Hemminger
Quoted 4 lines
mlx4_dev_info_getcallsmlx4_get_ifname, butmlx4_get_ifnameuses priv-Quoted 1 line
ctx which is not a valid pointer in a secondary process. The fix is to cache the
value in primary.
Quoted 8 lines
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")Reported-by Suyang Ju <[email protected]>Signed-off-by Stephen Hemminger <[email protected]>
Thanks for the fix.
Quoted 84 lines
--- 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(-)drivers/net/mlx4/mlx4.c index renamed from drivers/net/mlx4/mlx4.c +0
-0
2e169b0887a7..bab2cadbe519100644drivers/net/mlx4/mlx4.c +1
-0@@ -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;drivers/net/mlx4/mlx4.c +8
-10err =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. */ drivers/net/mlx4/mlx4.c +0
-0mlx4_mtu_get (priv, &priv->mtu); DEBUG("port %u MTU is %u", priv->port, priv->mtu); diff --git
a/drivers/net/mlx4/mlx4.hb/drivers/net/mlx4/mlx4.hindexcd0d637ac2bf..81b529ee8030100644drivers/net/mlx4/mlx4.h +1
-0@@ -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.cb/drivers/net/mlx4/mlx4_ethdev.cindexceef921620a8..5d28c0116d21100644drivers/net/mlx4/mlx4_ethdev.c +1
-3@@ -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
Re: [dpdk-dev] [PATCH 1/2] net/mlx4: fix crash in dev_info_get in secondary process
In reply to Stephen HemmingerHi 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
Quoted 109 lines
-----Original Message-----
From: dev <[email protected]> On Behalf Of Stephen Hemminger
Sent: Friday, July 12, 2019 11:54 PM
To: Matan Azrad <[email protected]>; Shahaf Shuler <[email protected]>; Yongseok Koh <[email protected]>; Slava Ovsiienko <[email protected]>
Cc: [email protected]; [email protected]; Stephen Hemminger <[email protected]>; [email protected]
Subject: [dpdk-dev] [PATCH 1/2] net/mlx4: fix crash indev_info_getin secondary process
mlx4_dev_info_getcallsmlx4_get_ifname, butmlx4_get_ifnameusespriv->ctxwhich 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")Reported-by Suyang Ju <[email protected]>Signed-off-by Stephen Hemminger <[email protected]>--- 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(-)drivers/net/mlx4/mlx4.c +1
-0@@ -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;drivers/net/mlx4/mlx4.c +8
-10err =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. */ drivers/net/mlx4/mlx4.c +0
-0mlx4_mtu_get (priv, &priv->mtu);DEBUG ("port %u MTU is %u" , priv->port, priv->mtu);drivers/net/mlx4/mlx4.h +1
-0@@ -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. */drivers/net/mlx4/mlx4_ethdev.c +0
-1@@ -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. */ drivers/net/mlx4/mlx4_ethdev.c +1
-2info->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
Re: [dpdk-dev] [PATCH 1/2] net/mlx4: fix crash in dev_info_get in secondary process
Hi,
Quoted 118 lines
-----Original Message-----
From: Raslan Darawsheh
Sent: Sunday, August 4, 2019 9:58 AM
To: Stephen Hemminger <[email protected]>; Matan Azrad <[email protected]>; Shahaf Shuler <[email protected]>; Yongseok Koh <[email protected]>; Slava Ovsiienko <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: RE: [dpdk-dev] [PATCH 1/2] net/mlx4: fix crash indev_info_getin secondary processHi Stephen,
Wrong headline format:
net/mlx4: fix crash indev_info_getin secondary process can you please
fix it? You shouldn't use the _ in the title formatKindest regards,
Raslan Darawshehdrivers/net/mlx4/mlx4_ethdev.c mlx4_dev_infos_get(struct rte_eth_dev *dev,
Quoted 88 lines
-----Original Message-----
From: dev <[email protected]> On Behalf Of Stephen Hemminger
Sent: Friday, July 12, 2019 11:54 PM
To: Matan Azrad <[email protected]>; Shahaf Shuler <[email protected]>; Yongseok Koh <[email protected]>; Slava Ovsiienko <[email protected]>
Cc: [email protected]; [email protected]; Stephen Hemminger <[email protected]>; [email protected]
Subject: [dpdk-dev] [PATCH 1/2] net/mlx4: fix crash indev_info_getin secondary process
mlx4_dev_info_getcallsmlx4_get_ifname, butmlx4_get_ifnameusespriv->ctxwhich 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")Reported-by Suyang Ju <[email protected]>Signed-off-by Stephen Hemminger <[email protected]>--- 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(-)drivers/net/mlx4/mlx4.c index renamed from drivers/net/mlx4/mlx4.c +0
-0
2e169b0887a7..bab2cadbe519100644drivers/net/mlx4/mlx4.c +1
-0@@ -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;drivers/net/mlx4/mlx4.c +8
-10err =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. */ drivers/net/mlx4/mlx4.c +0
-0mlx4_mtu_get (priv, &priv->mtu); DEBUG("port %u MTU is %u", priv->port, priv->mtu); diff --git
a/drivers/net/mlx4/mlx4.hb/drivers/net/mlx4/mlx4.hindexcd0d637ac2bf..81b529ee8030100644drivers/net/mlx4/mlx4.h +1
-1@@ -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.cindexceef921620a8..5d28c0116d21100644drivers/net/mlx4/mlx4_ethdev.c +0
-0@@ -616,7 +616,6 @@ mlx4_dev_infos_get(struct rte_eth_dev *dev,struct
drivers/net/mlx4/mlx4_ethdev.c mlx4_dev_infos_get(struct rte_eth_dev *dev,
Quoted 8 lines
drivers/net/mlx4/mlx4_ethdev.c +0
-1rte_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
Quoted 12 lines
Quoted 9 lines
drivers/net/mlx4/mlx4_ethdev.c +1
-2rte_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 =Quoted 3 lines
ETH_LINK_SPEED_1G|
--
2.20.1
Patch applied to next-net-mlx after fixing wrong headline format,
Kindest regards,
Raslan Darawsheh
PATCH 2/2 net/mlx5: fix crash in dev_info_get in secondary process
In reply to Stephen Hemmingermlx5_dev_info_get calls mlx5_get_ifname, but mlx5_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.
--- drivers/net/mlx5/mlx5.c | 17 ++++++++--------- drivers/net/mlx5/mlx5.h | 1 + drivers/net/mlx5/mlx5_ethdev.c | 4 +--- 3 files changed, 10 insertions(+), 12 deletions(-)
drivers/net/mlx5/mlx5.c +8 -9
@@ -1105,6 +1105,7 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,int own_domain_id =0 ;uint16_t port_id;unsigned int i; +char ifname[IF_NAMESIZE ];/* Determine if this port representor is supposed to be spawned. */ if (switch_info->representor && dpdk_dev->devargs) {
@@ -1479,18 +1480,16 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev, mac.addr_bytes[0 ], mac.addr_bytes[1 ], mac.addr_bytes[2 ], mac.addr_bytes[3 ], mac.addr_bytes[4], mac.addr_bytes[5]); -#ifndef NDEBUG - { -char ifname[IF_NAMESIZE ]; -if (mlx5_get_ifname (eth_dev, &ifname) ==0 ) -DRV_LOG (DEBUG ,"port %u ifname is \"%s\"" , +if (mlx5_get_ifname (eth_dev, &ifname) ==0 ) { + priv->if_index =if_nametoindex (ifname); +DRV_LOG (DEBUG ,"port %u ifname is \"%s\"" , eth_dev->data->port_id, ifname); -else -DRV_LOG (DEBUG ,"port %u ifname is unknown" , - eth_dev->data->port_id); + }else { +DRV_LOG (DEBUG ,"port %u ifname is unknown" , + eth_dev->data->port_id); } -#endif +/* Get actual MTU if possible. */ err =mlx5_get_mtu (eth_dev, &priv->mtu);if (err) {
drivers/net/mlx5/mlx5.h +1 -0
@@ -342,6 +342,7 @@ struct mlx5_priv {uint16_t vlan_filter[MLX5_MAX_VLAN_IDS ];/* VLAN filters table. */ unsigned int vlan_filter_n;/* Number of configured VLAN filters. */ /* Device properties. */ +unsigned int if_index;/* Associated kernel network device index. */ uint16_t mtu;/* Configured MTU. */ unsigned int isolated:1; /* Whether isolated mode is enabled. */ unsigned int representor:1; /* Device is a port representor. */
drivers/net/mlx5/mlx5_ethdev.c +1 -3
@@ -605,7 +605,6 @@ mlx5_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info)struct mlx5_priv *priv = dev->data->dev_private;struct mlx5_dev_config *config = &priv->config;unsigned int max; -char ifname[IF_NAMESIZE ];/* FIXME: we should ask the device for these values. */ info->min_rx_bufsize =32 ;
@@ -626,8 +625,7 @@ mlx5_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info) info->rx_offload_capa = (mlx5_get_rx_port_offloads () | info->rx_queue_offload_capa); info->tx_offload_capa =mlx5_get_tx_port_offloads (dev); -if (mlx5_get_ifname (dev, &ifname) ==0 ) - info->if_index =if_nametoindex (ifname); + info->if_index = priv->if_index; info->reta_size = priv->reta_idx_n ? priv->reta_idx_n : config->ind_table_max_size; info->hash_key_size =MLX5_RSS_HASH_KEY_LEN ;
Signature · 1 line
2.20.1
Re: [dpdk-dev] [PATCH 2/2] net/mlx5: fix crash in dev_info_get in secondary process
Hi, Stephen
Quoted 1 line
mlx5_get_ifnameusespriv->ctxwhich is not a valid pointer in a secondary process.
1. Sorry, mlx5_priv structure does not contain ctx field. Do you mean priv->sh (shared context) ? This one is allocated with rte_zmalloc(), that supposes shared memory allocation and shared context structure should be valid within secondary process context.
It seems there is another issue - mlx5_get_ifname() uses priv->nl_socket_rdma which is process-specific socket handle (fd), so routine may fail.
2. Generally I'm OK with caching ifindex in priv structure - it seems the ifindex is permanent throughout interface lifetime. The mlx5_dev_spawn has a parameter mlx5_dev_spawn_data *spawn, it contains the successfully queried ifindex of the device being spawned - no need to query again.
The cached valued should be retrieved by mlx5_ifindex() routine and mlx5_get_ifname() should be refactored to use mlx5_ifindex().
WBR,
Slava
Quoted 102 lines
-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Friday, July 12, 2019 23:54
To: Matan Azrad <[email protected]>; Shahaf Shuler <[email protected]>; Yongseok Koh <[email protected]>; Slava Ovsiienko <[email protected]>
Cc: [email protected]; [email protected]; Stephen Hemminger <[email protected]>
Subject: [PATCH 2/2] net/mlx5: fix crash indev_info_getin secondary process
mlx5_dev_info_getcallsmlx5_get_ifname, butmlx5_get_ifnameuses priv-Quoted 1 line
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.
Fixes e60fbd5b24fc ("mlx5: add device configure/start/stop")Signed-off-by Stephen Hemminger <[email protected]>--- drivers/net/mlx5/mlx5.c | 17 ++++++++--------- drivers/net/mlx5/mlx5.h | 1 + drivers/net/mlx5/mlx5_ethdev.c | 4 +--- 3 files changed, 10 insertions(+), 12 deletions(-)drivers/net/mlx5/mlx5.c index renamed from drivers/net/mlx5/mlx5.c +0
-0
d93f92db56b5..27c5ef9b1763100644drivers/net/mlx5/mlx5.c +9
-8@@ -1105,6 +1105,7 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,int own_domain_id =0 ;uint16_t port_id;unsigned int i; +char ifname[IF_NAMESIZE ];/* Determine if this port representor is supposed to be spawned. */ if (switch_info->representor && dpdk_dev->devargs) { @@ -1479,18 +1480,16 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev, mac.addr_bytes[0 ], mac.addr_bytes[1 ], mac.addr_bytes[2 ], mac.addr_bytes[3 ], mac.addr_bytes[4], mac.addr_bytes[5]); -#ifndef NDEBUG - { -char ifname[IF_NAMESIZE ]; -if (mlx5_get_ifname (eth_dev, &ifname) ==0 ) -DRV_LOG (DEBUG ,"port %u ifname is \"%s\"" , +if (mlx5_get_ifname (eth_dev, &ifname) ==0 ) { + priv->if_index =if_nametoindex (ifname); +DRV_LOG (DEBUG ,"port %u ifname is \"%s\"" , eth_dev->data->port_id, ifname); -else -DRV_LOG (DEBUG ,"port %u ifname is unknown" , - eth_dev->data->port_id); + }else { +DRV_LOG (DEBUG ,"port %u ifname is unknown" , + eth_dev->data->port_id); } -#endif +/* Get actual MTU if possible. */ err =mlx5_get_mtu (eth_dev, &priv->mtu);if (err) {drivers/net/mlx5/mlx5.h index renamed from drivers/net/mlx5/mlx5.h +0
-0
5af3f413cdcb..a06ffd444255100644drivers/net/mlx5/mlx5.h +1
-0@@ -342,6 +342,7 @@ struct mlx5_priv {uint16_t vlan_filter[MLX5_MAX_VLAN_IDS ];/* VLAN filters table. */ unsigned int vlan_filter_n;/* Number of configured VLAN filters. */ /* Device properties. */ +unsigned int if_index;/* Associated kernel network device index. */ uint16_t mtu;/* Configured MTU. */ unsigned int isolated:1; /* Whether isolated mode is enabled. */ unsigned int representor:1; /* Device is a port representor. */ diff --git
a/drivers/net/mlx5/mlx5_ethdev.cb/drivers/net/mlx5/mlx5_ethdev.cindexeeefe4df3cd4..41e58db5e573100644drivers/net/mlx5/mlx5_ethdev.c +0
-1@@ -605,7 +605,6 @@ mlx5_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info)struct mlx5_priv *priv = dev->data->dev_private;struct mlx5_dev_config *config = &priv->config;unsigned int max; -char ifname[IF_NAMESIZE ];/* FIXME: we should ask the device for these values. */ drivers/net/mlx5/mlx5_ethdev.c +1
-2info->min_rx_bufsize =32 ;@@ -626,8 +625,7 @@ mlx5_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info) info->rx_offload_capa = (mlx5_get_rx_port_offloads() | info->rx_queue_offload_capa); info->tx_offload_capa =mlx5_get_tx_port_offloads (dev); -if (mlx5_get_ifname (dev, &ifname) ==0 ) - info->if_index =if_nametoindex (ifname); + info->if_index = priv->if_index; info->reta_size = priv->reta_idx_n ? priv->reta_idx_n : config->ind_table_max_size;
info->hash_key_size=MLX5_RSS_HASH_KEY_LEN;
--
2.20.1
cover net/mlx5: cache the associated network device ifindex
In reply to Stephen HemmingerIn mlx5 PMD the associated device index is retrieved via Netlink request to underlying Infiniband device driver. This network device index is permanent throughout the lifetime of device. We do not spawn the rte_eth_dev ports without associated network device, and if network device is being unbound we get the remove notification event message and rte_eth_dev port is also detached. So, we may store the ifindex in mlx5_device_spawn() routine at rte_eth_dev port creation and initialization time and use the cached value further instead of doing actual Netlink request.
This approach allows the query API routines like mlx5_link_update to be thread-safe due to Netlink request elimination. mlx5_link_update() may be called in asynchronous event handler concurrently and it may cause application hang.
This patch extends and updates the [1].
[1] http://patches.dpdk.org/patch/56417/
Viacheslav Ovsiienko (2):
net/mlx5: cache the associated network device ifindex Revert "net/mlx5: fix master device Netlink socket sharing"
drivers/net/mlx5/mlx5.c | 11 ++++ drivers/net/mlx5/mlx5.h | 7 +-- drivers/net/mlx5/mlx5_ethdev.c | 128 ++++------------------------------------- 3 files changed, 22 insertions(+), 124 deletions(-)
Signature · 1 line
1.8.3.1
PATCH 1/2 net/mlx5: cache the associated network device ifindex
The associated device index is retrieved via Netlink request to underlying Infiniband device driver. This network device index is permanent throughout the lifetime of device. We do not spawn the rte_eth_dev ports without associated network device, and if network device is being unbound we get the remove notification message and rte_eth_dev port is also detached. So, we may store the ifindex in mlx5_device_spawn() routine at rte_eth_dev port creation and initialization time and use the cached value further instead of doing actual Netlink request.
--- drivers/net/mlx5/mlx5.c | 11 +++++++++++ drivers/net/mlx5/mlx5.h | 1 + drivers/net/mlx5/mlx5_ethdev.c | 19 +++++++------------ 3 files changed, 19 insertions(+), 12 deletions(-)
drivers/net/mlx5/mlx5.c +11 -0
@@ -1630,6 +1630,17 @@ struct mlx5_dev_spawn_data { eth_dev->data->dev_flags |=RTE_ETH_DEV_REPRESENTOR ; eth_dev->data->representor_id = priv->representor_id; } +/* +* Store associated network device interface index. This index +* is permanent throughout the lifetime of device. We do not spawn +* rte_eth_dev ports without associated network device, and if +* network device is being unbound we get the remove notification +* message and rte_eth_dev port is also detached. So, we may store +* the ifindex here and use the cached value further. The network +* device name can be changed dynamically and should not be cached. +*/ +assert (spawn->ifindex); + priv->if_index = spawn->ifindex; eth_dev->data->dev_private = priv; priv->dev_data = eth_dev->data; eth_dev->data->mac_addrs = priv->mac;
drivers/net/mlx5/mlx5.h +1 -0
@@ -465,6 +465,7 @@ struct mlx5_priv {uint16_t domain_id;/* Switch domain identifier. */ uint16_t vport_id;/* Associated VF vport index (if any). */ int32_t representor_id;/* Port representor identifier. */ +unsigned int if_index;/* Associated kernel network device index. */ /* RX/TX queues. */ unsigned int rxqs_n;/* RX queues array size. */ unsigned int txqs_n;/* TX queues array size. */
drivers/net/mlx5/mlx5_ethdev.c +7 -12
@@ -225,10 +225,7 @@ struct ethtool_link_settings {assert (priv);assert (priv->sh); - ifindex = priv->nl_socket_rdma >=0 ? -mlx5_nl_ifindex (priv->nl_socket_rdma, - priv->sh->ibdev_name, - priv->ibv_port) :0 ; + ifindex =mlx5_ifindex (dev);if (!ifindex) {if (!priv->representor) return mlx5_get_master_ifname(priv->sh->ibdev_path,
@@ -299,14 +296,14 @@ struct ethtool_link_settings {unsigned int mlx5_ifindex (const struct rte_eth_dev *dev) { -char ifname[IF_NAMESIZE ]; +struct mlx5_priv *priv = dev->data->dev_private;unsigned int ifindex; -if (mlx5_get_ifname (dev, &ifname)) -return 0 ; - ifindex =if_nametoindex (ifname); +assert (priv); +assert (priv->if_index); + ifindex = priv->if_index;if (!ifindex) - rte_errno = errno; + rte_errno =ENXIO ;return ifindex; }
@@ -641,7 +638,6 @@ struct ethtool_link_settings {struct mlx5_priv *priv = dev->data->dev_private;struct mlx5_dev_config *config = &priv->config;unsigned int max; -char ifname[IF_NAMESIZE ];/* FIXME: we should ask the device for these values. */ info->min_rx_bufsize =32 ;
@@ -662,8 +658,7 @@ struct ethtool_link_settings { info->rx_offload_capa = (mlx5_get_rx_port_offloads () | info->rx_queue_offload_capa); info->tx_offload_capa =mlx5_get_tx_port_offloads (dev); -if (mlx5_get_ifname (dev, &ifname) ==0 ) - info->if_index =if_nametoindex (ifname); + info->if_index =mlx5_ifindex (dev); info->reta_size = priv->reta_idx_n ? priv->reta_idx_n : config->ind_table_max_size; info->hash_key_size =MLX5_RSS_HASH_KEY_LEN ;
Signature · 1 line
1.8.3.1
Re: [dpdk-dev] [PATCH 1/2] net/mlx5: cache the associated network device ifindex
drivers/net/mlx5/mlx5.c struct mlx5_dev_spawn_data { · line 1643
Quoted 11 lines · On Fri, 19 Jul 2019 05:31:44 +0000 Viacheslav Ovsiienko…
drivers/net/mlx5/mlx5.c +11
-0+/* +* Store associated network device interface index. This index +* is permanent throughout the lifetime of device. We do not spawn +* rte_eth_dev ports without associated network device, and if +* network device is being unbound we get the remove notification +* message and rte_eth_dev port is also detached. So, we may store +* the ifindex here and use the cached value further. The network +* device name can be changed dynamically and should not be cached. +*/ +assert (spawn->ifindex); + priv->if_index = spawn->ifindex;
This correct, but overkill.
1. The comment is way too wordy. Please stick to only a couple of lines. If you feel more explanation is necessary put that in the commit log.
2. It is perfectly okay to return 0 as a value in dev_info. Therefore the assert is unnecessary.
3. Where is "Reported-by:"
4. What was wrong with my simpler patch?
Re: [dpdk-dev] [PATCH 1/2] net/mlx5: cache the associated network device ifindex
Quoted 21 lines
-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Friday, July 19, 2019 19:16
To: Slava Ovsiienko <[email protected]>
Cc: [email protected]; Yongseok Koh <[email protected]>; Shahaf Shuler <[email protected]>
Subject: Re: [PATCH 1/2] net/mlx5: cache the associated network device ifindexdrivers/net/mlx5/mlx5.c struct mlx5_dev_spawn_data {
Quoted 8 lines · On Fri, 19 Jul 2019 05:31:44 +0000 Viacheslav Ovsiienko…
drivers/net/mlx5/mlx5.c +8
-0+/* +* Store associated network device interface index. This index +* is permanent throughout the lifetime of device. We do not spawn +* rte_eth_dev ports without associated network device, and if +* network device is being unbound we get the remove notification +* message and rte_eth_dev port is also detached. So, we may store +* the ifindex here and use the cached value further. The network +* device name can be changed dynamically and should not be cached.
Quoted 8 lines
drivers/net/mlx5/mlx5.c struct mlx5_dev_spawn_data { · line 1643
Quoted 3 lines
drivers/net/mlx5/mlx5.c +3
-0+*/ +assert (spawn->ifindex); + priv->if_index = spawn->ifindex;This correct, but overkill.
1. The comment is way too wordy. Please stick to only a couple of lines. If you feel more explanation is necessary put that in the commit log.
I'd prefer to see the issue description in the source, not by searching the git log for the appropriate commit. But OK, it does not matter.
Quoted 2 lines
2. It is perfectly okay to return 0 as a value in
dev_info. Therefore the assert is unnecessary.
Valid network interface index cannot be zero. For example, if_nametoindex() returns zero in case of error. Also, in mlx5 we do not spawn ports without attached network interfaces. Assert is not related to dev_info, it checks whether the mlx5_dev_spawn() is called with valid ifindex for valid port (ifindex checked against zero to validate infiniband port is active). We need this assert here.
Quoted 1 line
3. Where is "Reported-by:"
It is in cover letter:
"Proposed-by: Stephen Hemminger <[email protected]>"
Sorry, I forgot to add this one in commit message, will fix.
Quoted 1 line
4. What was wrong with my simpler patch?
Please, see the cover letter. Your patch fixes only the part of problem - the mlx5_dev_infos_get(). But it is just the case of unsafe mlx5_ifindex() usage. mlx5_ifindex() itself must be fixed instead.
WBR, Slava
Re: [dpdk-dev] [PATCH 1/2] net/mlx5: cache the associated network device ifindex
Quoted 47 lines · On Fri, 19 Jul 2019 16:41:38 +0000 Slava Ovsiienko <[email protected]>…
Quoted 21 lines
-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Friday, July 19, 2019 19:16
To: Slava Ovsiienko <[email protected]>
Cc: [email protected]; Yongseok Koh <[email protected]>; Shahaf Shuler <[email protected]>
Subject: Re: [PATCH 1/2] net/mlx5: cache the associated network device ifindexdrivers/net/mlx5/mlx5.c struct mlx5_dev_spawn_data {
Quoted 8 lines · On Fri, 19 Jul 2019 05:31:44 +0000 Viacheslav Ovsiienko…
drivers/net/mlx5/mlx5.c +8
-0+/* +* Store associated network device interface index. This index +* is permanent throughout the lifetime of device. We do not spawn +* rte_eth_dev ports without associated network device, and if +* network device is being unbound we get the remove notification +* message and rte_eth_dev port is also detached. So, we may store +* the ifindex here and use the cached value further. The network +* device name can be changed dynamically and should not be cached.
Quoted 8 lines
drivers/net/mlx5/mlx5.c struct mlx5_dev_spawn_data { · line 1643
Quoted 3 lines
drivers/net/mlx5/mlx5.c +3
-0+*/ +assert (spawn->ifindex); + priv->if_index = spawn->ifindex;This correct, but overkill.
1. The comment is way too wordy. Please stick to only a couple of lines. If you feel more explanation is necessary put that in the commit log.
I'd prefer to see the issue description in the source, not by searching the git log for the appropriate commit. But OK, it does not matter.
Quoted 2 lines
2. It is perfectly okay to return 0 as a value in
dev_info. Therefore the assert is unnecessary.Valid network interface index cannot be zero. For example,
if_nametoindex()returns zero in case of error. Also, in mlx5 we do not spawn ports without attached network interfaces. Assert is not related todev_info, it checks whether themlx5_dev_spawn()is called with valid ifindex for valid port (ifindex checked against zero to validate infiniband port is active). We need this assert here.Quoted 1 line
3. Where is "Reported-by:"
It is in cover letter:
"Proposed-by: Stephen Hemminger <[email protected]>"
Sorry, I forgot to add this one in commit message, will fix.
Quoted 6 lines
Quoted 1 line
4. What was wrong with my simpler patch?
Please, see the cover letter. Your patch fixes only the part of problem - the
mlx5_dev_infos_get(). But it is just the case of unsafemlx5_ifindex()usage.mlx5_ifindex()itself must be fixed instead.WBR, Slava
Will your patch be backported to stable?
It is critical that primary/secondary work on older releases.
Re: [dpdk-dev] [PATCH 1/2] net/mlx5: cache the associated network device ifindex
Quoted 65 lines
-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Friday, July 19, 2019 21:03
To: Slava Ovsiienko <[email protected]>
Cc: [email protected]; Yongseok Koh <[email protected]>; Shahaf Shuler <[email protected]>
Subject: Re: [PATCH 1/2] net/mlx5: cache the associated network device ifindexQuoted 5 lines · On Fri, 19 Jul 2019 16:41:38 +0000 Slava Ovsiienko <[email protected]>…
Quoted 5 lines
-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Friday, July 19, 2019 19:16
To: Slava Ovsiienko <[email protected]>
Cc: [email protected]; Yongseok Koh <[email protected]>; ShahafShuler
Quoted 22 lines
Quoted 22 lines
<[email protected]>
Subject: Re: [PATCH 1/2] net/mlx5: cache the associated network device ifindexdrivers/net/mlx5/mlx5.c struct mlx5_dev_spawn_data {
Quoted 8 lines · On Fri, 19 Jul 2019 05:31:44 +0000 Viacheslav Ovsiienko…
drivers/net/mlx5/mlx5.c +8
-0+/* +* Store associated network device interface index. This index +* is permanent throughout the lifetime of device. We do not spawn +* rte_eth_dev ports without associated network device, and if +* network device is being unbound we get the remove notification +* message and rte_eth_dev port is also detached. So, we may store +* the ifindex here and use the cached value further. The network +* device name can be changed dynamically and should not be cached.
drivers/net/mlx5/mlx5.c struct mlx5_dev_spawn_data { · line 1643
Quoted 3 lines
drivers/net/mlx5/mlx5.c +3
-0+*/ +assert (spawn->ifindex); + priv->if_index = spawn->ifindex;This correct, but overkill.
Quoted 5 lines
Quoted 2 lines
1. The comment is way too wordy. Please stick to only a couple of lines. If you feel more explanation is necessary put that in the commit log.
I'd prefer to see the issue description in the source, not by searching the git log for the appropriate commit. But OK, it does not
matter.
Quoted 9 lines
Quoted 3 lines
2. It is perfectly okay to return 0 as a value in
dev_info. Therefore the assert is unnecessary.Valid network interface index cannot be zero. For example,
if_nametoindex()returns zero in case of error. Also, in mlx5 we do not spawn ports without attached network interfaces. Assert is not related todev_info, it checks whether themlx5_dev_spawn()is called with valid ifindex for valid port (ifindex checked against zero to validateinfiniband port is active). We need this assert here.
Quoted 9 lines
Quoted 2 lines
3. Where is "Reported-by:"
It is in cover letter:
"Proposed-by: Stephen Hemminger <[email protected]>"
Sorry, I forgot to add this one in commit message, will fix.Quoted 1 line
4. What was wrong with my simpler patch?
Please, see the cover letter. Your patch fixes only the part of problem - the
mlx5_dev_infos_get(). But it is just the case of unsafe
Quoted 7 lines
mlx5_ifindex()usage.Quoted 3 lines
mlx5_ifindex()itself must be fixed instead.WBR, Slava
Will your patch be backported to stable?
It is critical that primary/secondary work on older releases.
Quite possible.
Is there the full-featured secondary processes support in 18.11 LTS? I think it's worth to recheck the hotplug feature in 18.11 to avoid ifindex unexpected change (try to unbound/rebound network device from/to PCI one, check whether it is disabled/rejected, etc).
With best regards, Slava
PATCH 2/2 Revert "net/mlx5: fix master device Netlink socket sharing"
In reply to Viacheslav OvsiienkoThis reverts commit e28111ac9864af09e826241a915dfff87a9c00ad. The netlink requests are replaced by ifindex caching and not needed anymore.
--- drivers/net/mlx5/mlx5.h | 6 --- drivers/net/mlx5/mlx5_ethdev.c | 109 ++--------------------------------------- 2 files changed, 3 insertions(+), 112 deletions(-)
drivers/net/mlx5/mlx5.h +0 -6
@@ -518,15 +518,9 @@ struct mlx5_priv {/* mlx5_ethdev.c */ int mlx5_get_ifname (const struct rte_eth_dev *dev,char (*ifname)[IF_NAMESIZE ]); -int mlx5_get_ifname_base (const struct rte_eth_dev *base, -const struct rte_eth_dev *dev, -char (*ifname)[IF_NAMESIZE ]);int mlx5_get_master_ifname (const char *ibdev_path,char (*ifname)[IF_NAMESIZE ]);unsigned int mlx5_ifindex (const struct rte_eth_dev *dev);int mlx5_ifreq (const struct rte_eth_dev *dev,int req,struct ifreq *ifr); -int mlx5_ifreq_base (const struct rte_eth_dev *base, -const struct rte_eth_dev *dev, -int req,struct ifreq *ifr);int mlx5_get_mtu (struct rte_eth_dev *dev,uint16_t *mtu);int mlx5_set_flags (struct rte_eth_dev *dev,unsigned int keep,unsigned int flags);
drivers/net/mlx5/mlx5_ethdev.c +3 -106
139 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Re: [dpdk-dev] [PATCH 2/2] Revert "net/mlx5: fix master device Netlink socket sharing"
Quoted 6 lines · On Fri, 19 Jul 2019 05:31:45 +0000 Viacheslav Ovsiienko…
This reverts commit
e28111ac9864af09e826241a915dfff87a9c00ad. The netlink requests are replaced by ifindex caching and not needed anymore.Signed-off-by Viacheslav Ovsiienko <[email protected]>Fixes e28111ac9864 ("net/mlx5: fix master device Netlink socket sharing")
Can mlx5 drop dependency o netlink (libmnl)?
Re: [dpdk-dev] [PATCH 2/2] Revert "net/mlx5: fix master device Netlink socket sharing"
Quoted 16 lines
-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Friday, July 19, 2019 19:17
To: Slava Ovsiienko <[email protected]>
Cc: [email protected]; Yongseok Koh <[email protected]>; Shahaf Shuler <[email protected]>
Subject: Re: [PATCH 2/2] Revert "net/mlx5: fix master device Netlink socket sharing"Quoted 4 lines · On Fri, 19 Jul 2019 05:31:45 +0000 Viacheslav Ovsiienko…
This reverts commit
e28111ac9864af09e826241a915dfff87a9c00ad. The netlink requests are replaced by ifindex caching and not needed anymore.
Quoted 6 lines
Quoted 3 lines
Signed-off-by Viacheslav Ovsiienko <[email protected]>Fixes e28111ac9864 ("net/mlx5: fix master device Netlink socketsharing")
Can mlx5 drop dependency o netlink (libmnl)?
What do you mean? Dependency on libmnl is already dropped. The few remaining Netlink requests do not use libmnl (but does libnl).
With best regards, Slava
Re: [dpdk-dev] [PATCH 2/2] Revert "net/mlx5: fix master device Netlink socket sharing"
Quoted 21 lines · On Fri, 19 Jul 2019 16:21:17 +0000 Slava Ovsiienko <[email protected]>…
Quoted 21 lines
-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Friday, July 19, 2019 19:17
To: Slava Ovsiienko <[email protected]>
Cc: [email protected]; Yongseok Koh <[email protected]>; Shahaf Shuler <[email protected]>
Subject: Re: [PATCH 2/2] Revert "net/mlx5: fix master device Netlink socket sharing"Quoted 7 lines · On Fri, 19 Jul 2019 05:31:45 +0000 Viacheslav Ovsiienko…
This reverts commit
e28111ac9864af09e826241a915dfff87a9c00ad. The netlink requests are replaced by ifindex caching and not needed anymore.Signed-off-by Viacheslav Ovsiienko <[email protected]>Fixes e28111ac9864 ("net/mlx5: fix master device Netlink socketsharing")
Quoted 6 lines
Quoted 1 line
Can mlx5 drop dependency o netlink (libmnl)?
What do you mean? Dependency on libmnl is already dropped. The few remaining Netlink requests do not use libmnl (but does libnl).
With best regards, Slava
Good to see, libnl is quite large, it would be good to drop that (or use libmnl instead).
v2 cover net/mlx5: cache the associated network device ifindex
In reply to Viacheslav OvsiienkoIn mlx5 PMD the associated device index is retrieved via Netlink request to underlying Infiniband device driver. This network device index is permanent throughout the lifetime of device. We do not spawn the rte_eth_dev ports without associated network device, and if network device is being unbound we get the remove notification event message and rte_eth_dev port is also detached. So, we may store the ifindex in mlx5_device_spawn() routine at rte_eth_dev port creation and initialization time and use the cached value further instead of doing actual Netlink request.
This approach allows the query API routines like mlx5_link_update to be thread-safe due to Netlink request elimination. mlx5_link_update() may be called in asynchronous event handler concurrently and it may cause application hang.
This patch extends and updates the [1].
[1] http://patches.dpdk.org/patch/56417/
---
v2:
-- comments addressed
v1:
-- http://patches.dpdk.org/cover/56749/
Viacheslav Ovsiienko (2):
net/mlx5: cache the associated network device ifindex Revert "net/mlx5: fix master device Netlink socket sharing"
drivers/net/mlx5/mlx5.c | 7 +++ drivers/net/mlx5/mlx5.h | 7 +-- drivers/net/mlx5/mlx5_ethdev.c | 128 ++++------------------------------------- 3 files changed, 18 insertions(+), 124 deletions(-)
Signature · 1 line
1.8.3.1
PATCH v2 1/2 net/mlx5: cache the associated network device ifindex
The associated device index is retrieved via Netlink request to underlying Infiniband device driver. This network device index is permanent throughout the lifetime of device. We do not spawn the rte_eth_dev ports without associated network device, and if network device is being unbound we get the remove notification message and rte_eth_dev port is also detached. So, we may store the ifindex in mlx5_device_spawn() routine at rte_eth_dev port creation and initialization time and use the cached value further instead of doing actual Netlink request.
--- drivers/net/mlx5/mlx5.c | 7 +++++++ drivers/net/mlx5/mlx5.h | 1 + drivers/net/mlx5/mlx5_ethdev.c | 19 +++++++------------ 3 files changed, 15 insertions(+), 12 deletions(-)
drivers/net/mlx5/mlx5.c +7 -0
@@ -1630,6 +1630,13 @@ struct mlx5_dev_spawn_data { eth_dev->data->dev_flags |=RTE_ETH_DEV_REPRESENTOR ; eth_dev->data->representor_id = priv->representor_id; } +/* +* Store associated network device interface index. This index +* is permanent throughout the lifetime of device. So, we may store +* the ifindex here and use the cached value further. +*/ +assert (spawn->ifindex); + priv->if_index = spawn->ifindex; eth_dev->data->dev_private = priv; priv->dev_data = eth_dev->data; eth_dev->data->mac_addrs = priv->mac;
drivers/net/mlx5/mlx5.h +1 -0
@@ -465,6 +465,7 @@ struct mlx5_priv {uint16_t domain_id;/* Switch domain identifier. */ uint16_t vport_id;/* Associated VF vport index (if any). */ int32_t representor_id;/* Port representor identifier. */ +unsigned int if_index;/* Associated kernel network device index. */ /* RX/TX queues. */ unsigned int rxqs_n;/* RX queues array size. */ unsigned int txqs_n;/* TX queues array size. */
drivers/net/mlx5/mlx5_ethdev.c +7 -12
@@ -225,10 +225,7 @@ struct ethtool_link_settings {assert (priv);assert (priv->sh); - ifindex = priv->nl_socket_rdma >=0 ? -mlx5_nl_ifindex (priv->nl_socket_rdma, - priv->sh->ibdev_name, - priv->ibv_port) :0 ; + ifindex =mlx5_ifindex (dev);if (!ifindex) {if (!priv->representor) return mlx5_get_master_ifname(priv->sh->ibdev_path,
@@ -299,14 +296,14 @@ struct ethtool_link_settings {unsigned int mlx5_ifindex (const struct rte_eth_dev *dev) { -char ifname[IF_NAMESIZE ]; +struct mlx5_priv *priv = dev->data->dev_private;unsigned int ifindex; -if (mlx5_get_ifname (dev, &ifname)) -return 0 ; - ifindex =if_nametoindex (ifname); +assert (priv); +assert (priv->if_index); + ifindex = priv->if_index;if (!ifindex) - rte_errno = errno; + rte_errno =ENXIO ;return ifindex; }
@@ -641,7 +638,6 @@ struct ethtool_link_settings {struct mlx5_priv *priv = dev->data->dev_private;struct mlx5_dev_config *config = &priv->config;unsigned int max; -char ifname[IF_NAMESIZE ];/* FIXME: we should ask the device for these values. */ info->min_rx_bufsize =32 ;
@@ -662,8 +658,7 @@ struct ethtool_link_settings { info->rx_offload_capa = (mlx5_get_rx_port_offloads () | info->rx_queue_offload_capa); info->tx_offload_capa =mlx5_get_tx_port_offloads (dev); -if (mlx5_get_ifname (dev, &ifname) ==0 ) - info->if_index =if_nametoindex (ifname); + info->if_index =mlx5_ifindex (dev); info->reta_size = priv->reta_idx_n ? priv->reta_idx_n : config->ind_table_max_size; info->hash_key_size =MLX5_RSS_HASH_KEY_LEN ;
Signature · 1 line
1.8.3.1
Re: [dpdk-dev] [PATCH v2 1/2] net/mlx5: cache the associated network device ifindex
Quoted 12 lines · Viacheslav Ovsiienko
The associated device index is retrieved via Netlink request to underlying Infiniband device driver. This network device index is permanent throughout the lifetime of device. We do not spawn the
rte_eth_devports without associated network device, and if network device is being unbound we get the remove notification message andrte_eth_devport is also detached. So, we may store the ifindex inmlx5_device_spawn()routine atrte_eth_devport creation and initialization time and use the cached value further instead of doing actual Netlink request.
Quoted 3 lines
Reported-by Stephen Hemminger <[email protected]>Signed-off-by Viacheslav Ovsiienko <[email protected]>---
Quoted 92 lines
drivers/net/mlx5/mlx5.c | 7 +++++++ drivers/net/mlx5/mlx5.h | 1 + drivers/net/mlx5/mlx5_ethdev.c | 19 +++++++------------ 3 files changed, 15 insertions(+), 12 deletions(-)drivers/net/mlx5/mlx5.c +7
-0@@ -1630,6 +1630,13 @@ struct mlx5_dev_spawn_data { eth_dev->data->dev_flags |=RTE_ETH_DEV_REPRESENTOR ; eth_dev->data->representor_id = priv->representor_id; } +/* +* Store associated network device interface index. This index +* is permanent throughout the lifetime of device. So, we may store +* the ifindex here and use the cached value further. +*/ +assert (spawn->ifindex); + priv->if_index = spawn->ifindex; eth_dev->data->dev_private = priv; priv->dev_data = eth_dev->data; eth_dev->data->mac_addrs = priv->mac;drivers/net/mlx5/mlx5.h +1
-0@@ -465,6 +465,7 @@ struct mlx5_priv {uint16_t domain_id;/* Switch domain identifier. */ uint16_t vport_id;/* Associated VF vport index (if any). */ int32_t representor_id;/* Port representor identifier. */ +unsigned int if_index;/* Associated kernel network device index. */ /* RX/TX queues. */ unsigned int rxqs_n;/* RX queues array size. */ unsigned int txqs_n;/* TX queues array size. */ drivers/net/mlx5/mlx5_ethdev.c +1
-4@@ -225,10 +225,7 @@ struct ethtool_link_settings {assert (priv);assert (priv->sh); - ifindex = priv->nl_socket_rdma >=0 ? -mlx5_nl_ifindex (priv->nl_socket_rdma, - priv->sh->ibdev_name, - priv->ibv_port) :0 ; + ifindex =mlx5_ifindex (dev);if (!ifindex) {if (!priv->representor) return mlx5_get_master_ifname(priv->sh->ibdev_path,@@ -299,14 +296,14 @@ struct ethtool_link_settings {unsigned int
mlx5_ifindex(const struct rte_eth_dev *dev)
{drivers/net/mlx5/mlx5_ethdev.c +1
-1-char ifname[IF_NAMESIZE ]; +struct mlx5_priv *priv = dev->data->dev_private;unsigned int ifindex;drivers/net/mlx5/mlx5_ethdev.c +3
-3-if (mlx5_get_ifname (dev, &ifname)) -return 0 ; - ifindex =if_nametoindex (ifname); +assert (priv); +assert (priv->if_index); + ifindex = priv->if_index;if (!ifindex)
drivers/net/mlx5/mlx5_ethdev.c +1
-1- rte_errno = errno; + rte_errno =ENXIO ;return ifindex; }drivers/net/mlx5/mlx5_ethdev.c +1
-3@@ -641,7 +638,6 @@ struct ethtool_link_settings {struct mlx5_priv *priv = dev->data->dev_private;struct mlx5_dev_config *config = &priv->config;unsigned int max; -char ifname[IF_NAMESIZE ];/* FIXME: we should ask the device for these values. */ info->min_rx_bufsize =32 ;@@ -662,8 +658,7 @@ struct ethtool_link_settings { info->rx_offload_capa = (mlx5_get_rx_port_offloads () | info->rx_queue_offload_capa); info->tx_offload_capa =mlx5_get_tx_port_offloads (dev); -if (mlx5_get_ifname (dev, &ifname) ==0 ) - info->if_index =if_nametoindex (ifname); + info->if_index =mlx5_ifindex (dev); info->reta_size = priv->reta_idx_n ? priv->reta_idx_n : config->ind_table_max_size; info->hash_key_size =MLX5_RSS_HASH_KEY_LEN ;Signature · 1 line
1.8.3.1
PATCH v2 2/2 Revert "net/mlx5: fix master device Netlink socket sharing"
In reply to Viacheslav OvsiienkoThis reverts commit e28111ac9864af09e826241a915dfff87a9c00ad. The netlink requests are replaced by ifindex caching and not needed anymore.
--- drivers/net/mlx5/mlx5.h | 6 --- drivers/net/mlx5/mlx5_ethdev.c | 109 ++--------------------------------------- 2 files changed, 3 insertions(+), 112 deletions(-)
drivers/net/mlx5/mlx5.h +0 -6
@@ -518,15 +518,9 @@ struct mlx5_priv {/* mlx5_ethdev.c */ int mlx5_get_ifname (const struct rte_eth_dev *dev,char (*ifname)[IF_NAMESIZE ]); -int mlx5_get_ifname_base (const struct rte_eth_dev *base, -const struct rte_eth_dev *dev, -char (*ifname)[IF_NAMESIZE ]);int mlx5_get_master_ifname (const char *ibdev_path,char (*ifname)[IF_NAMESIZE ]);unsigned int mlx5_ifindex (const struct rte_eth_dev *dev);int mlx5_ifreq (const struct rte_eth_dev *dev,int req,struct ifreq *ifr); -int mlx5_ifreq_base (const struct rte_eth_dev *base, -const struct rte_eth_dev *dev, -int req,struct ifreq *ifr);int mlx5_get_mtu (struct rte_eth_dev *dev,uint16_t *mtu);int mlx5_set_flags (struct rte_eth_dev *dev,unsigned int keep,unsigned int flags);
drivers/net/mlx5/mlx5_ethdev.c +3 -106
139 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Re: [dpdk-dev] [PATCH v2 2/2] Revert "net/mlx5: fix master device Netlink socket sharing"
Quoted 10 lines · Viacheslav Ovsiienko
This reverts commit
e28111ac9864af09e826241a915dfff87a9c00ad. The netlink requests are replaced by ifindex caching and not needed anymore.Signed-off-by Viacheslav Ovsiienko <[email protected]>Fixes e28111ac9864 ("net/mlx5: fix master device Netlink socket sharing")---
Quoted 175 lines
drivers/net/mlx5/mlx5.h| 6 ---drivers/net/mlx5/mlx5_ethdev.c| 109 ++---------------------------------------2 files changed, 3 insertions(+), 112 deletions(-)drivers/net/mlx5/mlx5.h +0
-6@@ -518,15 +518,9 @@ struct mlx5_priv {/* mlx5_ethdev.c */ int mlx5_get_ifname (const struct rte_eth_dev *dev,char (*ifname)[IF_NAMESIZE ]); -int mlx5_get_ifname_base (const struct rte_eth_dev *base, -const struct rte_eth_dev *dev, -char (*ifname)[IF_NAMESIZE ]);int mlx5_get_master_ifname (const char *ibdev_path,char (*ifname)[IF_NAMESIZE ]);unsigned int mlx5_ifindex (const struct rte_eth_dev *dev);int mlx5_ifreq (const struct rte_eth_dev *dev,int req,struct ifreq *ifr); -int mlx5_ifreq_base (const struct rte_eth_dev *base, -const struct rte_eth_dev *dev, -int req,struct ifreq *ifr);int mlx5_get_mtu (struct rte_eth_dev *dev,uint16_t *mtu);int mlx5_set_flags (struct rte_eth_dev *dev,unsigned int keep,unsigned int flags);drivers/net/mlx5/mlx5_ethdev.c +3
-106@@ -240,51 +240,6 @@ struct ethtool_link_settings { }/** -* Get interface name for the specified device, uses the extra base -* device resources to perform Netlink requests. -* -* This is a port representor-aware version of mlx5_get_master_ifname(). -* -* @param[in] base -* Pointer to Ethernet device to use Netlink socket from -* to perfrom requests. -* @param[in] dev -* Pointer to Ethernet device. -* @param[out] ifname -* Interface name output buffer. -* -* @return -* 0 on success, a negative errno value otherwise and rte_errno is set. -*/ -int -mlx5_get_ifname_base (const struct rte_eth_dev *base, -const struct rte_eth_dev *dev, -char (*ifname)[IF_NAMESIZE ]) -{ -struct mlx5_priv *priv = dev->data->dev_private; -struct mlx5_priv *priv_base = base->data->dev_private; -unsigned int ifindex; - -assert (priv); -assert (priv->sh); -assert (priv_base); - ifindex = priv_base->nl_socket_rdma >=0 ? -mlx5_nl_ifindex (priv_base->nl_socket_rdma, - priv->sh->ibdev_name, - priv->ibv_port) :0 ; -if (!ifindex) { -if (!priv->representor) -return mlx5_get_master_ifname (priv->sh->ibdev_path, - ifname); - rte_errno =ENXIO ; -return -rte_errno; - } -if (if_indextoname (ifindex, &(*ifname)[0 ])) -return 0 ; - rte_errno = errno; -return -rte_errno; -} -/** * Get the interface index from device name. * * @param[in] dev @@ -346,51 +301,6 @@ struct ethtool_link_settings { }/** -* Perform ifreq ioctl() on specified Ethernet device, -* ifindex, name and other attributes are requested -* on the base device to avoid specified device Netlink -* socket sharing (this is not thread-safe). -* -* @param[in] base -* Pointer to Ethernet device to get dev attributes. -* @param[in] dev -* Pointer to Ethernet device to perform ioctl. -* @param req -* Request number to pass to ioctl(). -* @param[out] ifr -* Interface request structure output buffer. -* -* @return -* 0 on success, a negative errno value otherwise and rte_errno is set. -*/ -int -mlx5_ifreq_base (const struct rte_eth_dev *base, -const struct rte_eth_dev *dev, -int req,struct ifreq *ifr) -{ -int sock =socket (PF_INET ,SOCK_DGRAM ,IPPROTO_IP ); -int ret =0 ; - -if (sock ==-1 ) { - rte_errno = errno; -return -rte_errno; - } - ret =mlx5_get_ifname_base (base, dev, &ifr->ifr_name); -if (ret) - goto error; - ret =ioctl (sock, req, ifr); -if (ret ==-1 ) { - rte_errno = errno; - goto error; - } -close (sock); -return 0 ; -error: -close (sock); -return -rte_errno; -} - -/** * Get device MTU. * * @param dev @@ -872,15 +782,7 @@ int mlx5_fw_version_get(struct rte_eth_dev *dev, char *fw_ver, size_t fw_size) ifr = (struct ifreq ) { .ifr_data = (void *)&edata, }; -/* -* Use special version of mlx5_ifreq() -* to get master device name with local -* device Netlink socket. Using master -* device Netlink socket is not thread -* safe. -*/ - ret =mlx5_ifreq_base (dev, master, -SIOCETHTOOL , &ifr); + ret =mlx5_ifreq (master,SIOCETHTOOL , &ifr); } }if (ret) {@@ -977,12 +879,7 @@ int mlx5_fw_version_get(struct rte_eth_dev *dev, char *fw_ver, size_t fw_size) ifr = (struct ifreq ) { .ifr_data = (void *)&gcmd, }; -/* -* Avoid using master Netlink socket. -* This is not thread-safe. -*/ - ret =mlx5_ifreq_base (dev, master, -SIOCETHTOOL , &ifr); + ret =mlx5_ifreq (master,SIOCETHTOOL , &ifr); } }if (ret) {@@ -1003,7 +900,7 @@ int mlx5_fw_version_get(struct rte_eth_dev *dev, char *fw_ver, size_t fw_size) *ecmd = gcmd; ifr.ifr_data = (void *)ecmd; - ret =mlx5_ifreq_base (dev, master ? master : dev,SIOCETHTOOL , &ifr); + ret =mlx5_ifreq (master ? master : dev,SIOCETHTOOL , &ifr);if (ret) {DRV_LOG (DEBUG , "port %u ioctl(SIOCETHTOOL,"Signature · 1 line
1.8.3.1
Re: [dpdk-dev] [PATCH v2 0/2] net/mlx5: cache the associated network device ifindex
In reply to Viacheslav OvsiienkoHi,
Quoted 32 lines
-----Original Message-----
From: dev <[email protected]> On Behalf Of Viacheslav Ovsiienko
Sent: Sunday, July 21, 2019 5:57 PM
To: [email protected]
Cc: Yongseok Koh <[email protected]>; Shahaf Shuler <[email protected]>; [email protected]
Subject: [dpdk-dev] [PATCH v2 0/2] net/mlx5: cache the associated network device ifindexIn mlx5 PMD the associated device index is retrieved via Netlink request to underlying Infiniband device driver. This network device index is permanent throughout the lifetime of device. We do not spawn the
rte_eth_devports without associated network device, and if network device is being unbound we get the remove notification event message andrte_eth_devport is also detached. So, we may store the ifindex inmlx5_device_spawn()routine atrte_eth_devport creation and initialization time and use the cached value further instead of doing actual Netlink request.This approach allows the query API routines like
mlx5_link_updateto be thread-safe due to Netlink request elimination.mlx5_link_update()may be called in asynchronous event handler concurrently and it may cause application hang.This patch extends and updates the [1].
[1]
https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fpatch
es.dpdk.org%2Fpatch%2F56417%2F&data=02%7C01%7Crasland%40mell anox.com%7C3c155fb435384529783608d70debb168%7Ca652971c7d2e4d9ba6 a4d149256f461b%7C0%7C0%7C636993178256642102&sdata=GNj8%2B79 %2FoBQzu7esmy4wN4e6WC7RHREDbV4OZTq6SOA%3D&reserved=0
Quoted 4 lines
Reported-by Stephen Hemminger <[email protected]>Signed-off-by Viacheslav Ovsiienko <[email protected]>---
Series applied to next-net-mlx
Kindest regards,
Raslan Darawsheh
Re: [dpdk-dev] [PATCH 2/2] net/mlx5: fix crash in dev_info_get in secondary process
In reply to Stephen HemmingerHi Stephen,
Can you please confirm that Slava's patch fixed your issue and this patch is not needed anymore for MLX5? So that I can take mlx4 patch only from this series?
Kindest regards,
Raslan Darawsheh
Quoted 103 lines
-----Original Message-----
From: dev <[email protected]> On Behalf Of Stephen Hemminger
Sent: Friday, July 12, 2019 11:54 PM
To: Matan Azrad <[email protected]>; Shahaf Shuler <[email protected]>; Yongseok Koh <[email protected]>; Slava Ovsiienko <[email protected]>
Cc: [email protected]; [email protected]; Stephen Hemminger <[email protected]>
Subject: [dpdk-dev] [PATCH 2/2] net/mlx5: fix crash indev_info_getin secondary process
mlx5_dev_info_getcallsmlx5_get_ifname, butmlx5_get_ifnameusespriv->ctxwhich 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.
Fixes e60fbd5b24fc ("mlx5: add device configure/start/stop")Signed-off-by Stephen Hemminger <[email protected]>--- drivers/net/mlx5/mlx5.c | 17 ++++++++--------- drivers/net/mlx5/mlx5.h | 1 + drivers/net/mlx5/mlx5_ethdev.c | 4 +--- 3 files changed, 10 insertions(+), 12 deletions(-)drivers/net/mlx5/mlx5.c +8
-9@@ -1105,6 +1105,7 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,int own_domain_id =0 ;uint16_t port_id;unsigned int i; +char ifname[IF_NAMESIZE ];/* Determine if this port representor is supposed to be spawned. */ if (switch_info->representor && dpdk_dev->devargs) {@@ -1479,18 +1480,16 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev, mac.addr_bytes[0 ], mac.addr_bytes[1 ], mac.addr_bytes[2 ], mac.addr_bytes[3 ], mac.addr_bytes[4], mac.addr_bytes[5]); -#ifndef NDEBUG - { -char ifname[IF_NAMESIZE ]; -if (mlx5_get_ifname (eth_dev, &ifname) ==0 ) -DRV_LOG (DEBUG ,"port %u ifname is \"%s\"" , +if (mlx5_get_ifname (eth_dev, &ifname) ==0 ) { + priv->if_index =if_nametoindex (ifname); +DRV_LOG (DEBUG ,"port %u ifname is \"%s\"" , eth_dev->data->port_id, ifname); -else -DRV_LOG (DEBUG ,"port %u ifname is unknown" , - eth_dev->data->port_id); + }else { +DRV_LOG (DEBUG ,"port %u ifname is unknown" , + eth_dev->data->port_id); } -#endif +/* Get actual MTU if possible. */ err =mlx5_get_mtu (eth_dev, &priv->mtu);if (err) {drivers/net/mlx5/mlx5.h +1
-0@@ -342,6 +342,7 @@ struct mlx5_priv {uint16_t vlan_filter[MLX5_MAX_VLAN_IDS ];/* VLAN filters table. */ unsigned int vlan_filter_n;/* Number of configured VLAN filters. */ /* Device properties. */ +unsigned int if_index;/* Associated kernel network device index. */ uint16_t mtu;/* Configured MTU. */ unsigned int isolated:1; /* Whether isolated mode is enabled. */ unsigned int representor:1; /* Device is a port representor. */drivers/net/mlx5/mlx5_ethdev.c +0
-1@@ -605,7 +605,6 @@ mlx5_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info)struct mlx5_priv *priv = dev->data->dev_private;struct mlx5_dev_config *config = &priv->config;unsigned int max; -char ifname[IF_NAMESIZE ];/* FIXME: we should ask the device for these values. */ drivers/net/mlx5/mlx5_ethdev.c +1
-2info->min_rx_bufsize =32 ;@@ -626,8 +625,7 @@ mlx5_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info) info->rx_offload_capa = (mlx5_get_rx_port_offloads() | info->rx_queue_offload_capa); info->tx_offload_capa =mlx5_get_tx_port_offloads (dev); -if (mlx5_get_ifname (dev, &ifname) ==0 ) - info->if_index =if_nametoindex (ifname); + info->if_index = priv->if_index; info->reta_size = priv->reta_idx_n ? priv->reta_idx_n : config->ind_table_max_size;
info->hash_key_size=MLX5_RSS_HASH_KEY_LEN;
--
2.20.1
Re: [dpdk-dev] [PATCH 2/2] net/mlx5: fix crash in dev_info_get in secondary process
Quoted 7 lines · On Wed, 31 Jul 2019 07:36:26 +0000 Raslan Darawsheh <[email protected]>…
Hi Stephen,
Can you please confirm that Slava's patch fixed your issue and this patch is not needed anymore for MLX5? So that I can take mlx4 patch only from this series?
Kindest regards,
Raslan Darawsheh
OK, but my other concern is that mlx5 patch will not backport cleanly to stable.