DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] net/mlx5: fix master device Netlink socket sharing
@ 2019-06-06 12:23 Viacheslav Ovsiienko
  2019-06-11 18:29 ` Shahaf Shuler
  0 siblings, 1 reply; 2+ messages in thread
From: Viacheslav Ovsiienko @ 2019-06-06 12:23 UTC (permalink / raw)
  To: dev; +Cc: shahafs

There is the patch [1] that uses master device Netlink socket
to retrieve master device link settings. This is not thread safe
because this resource may be in use by other call to the master
device itself. Using the same Netlink socket concurrently from
the multiple threads causes Netlink requests malfunction and
must be eliminated. The patch replaces master Netlink socket
with the socket from representor device.

[1] http://patches.dpdk.org/patch/53120/

Fixes: 0333b2f584d9 ("net/mlx5: inherit master link settings for representors")
Signed-off-by: Viacheslav Ovsiienko <viacheslavo@mellanox.com>
---
 drivers/net/mlx5/mlx5.h        |   6 +++
 drivers/net/mlx5/mlx5_ethdev.c | 109 +++++++++++++++++++++++++++++++++++++++--
 2 files changed, 112 insertions(+), 3 deletions(-)

diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
index 0abce90..571e69c 100644
--- a/drivers/net/mlx5/mlx5.h
+++ b/drivers/net/mlx5/mlx5.h
@@ -396,9 +396,15 @@ 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);
diff --git a/drivers/net/mlx5/mlx5_ethdev.c b/drivers/net/mlx5/mlx5_ethdev.c
index ac0500a..26a1a3a 100644
--- a/drivers/net/mlx5/mlx5_ethdev.c
+++ b/drivers/net/mlx5/mlx5_ethdev.c
@@ -242,6 +242,51 @@ 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
@@ -303,6 +348,51 @@ 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
@@ -749,7 +839,15 @@ int mlx5_fw_version_get(struct rte_eth_dev *dev, char *fw_ver, size_t fw_size)
 				ifr = (struct ifreq) {
 					.ifr_data = (void *)&edata,
 				};
-				ret = mlx5_ifreq(master, SIOCETHTOOL, &ifr);
+				/*
+				 * 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);
 			}
 		}
 		if (ret) {
@@ -846,7 +944,12 @@ int mlx5_fw_version_get(struct rte_eth_dev *dev, char *fw_ver, size_t fw_size)
 				ifr = (struct ifreq) {
 					.ifr_data = (void *)&gcmd,
 				};
-				ret = mlx5_ifreq(master, SIOCETHTOOL, &ifr);
+				/*
+				 * Avoid using master Netlink socket.
+				 * This is not thread-safe.
+				 */
+				ret = mlx5_ifreq_base(dev, master,
+						      SIOCETHTOOL, &ifr);
 			}
 		}
 		if (ret) {
@@ -867,7 +970,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(master ? master : dev, SIOCETHTOOL, &ifr);
+	ret = mlx5_ifreq_base(dev, master ? master : dev, SIOCETHTOOL, &ifr);
 	if (ret) {
 		DRV_LOG(DEBUG,
 			"port %u ioctl(SIOCETHTOOL,"
-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [dpdk-dev] [PATCH] net/mlx5: fix master device Netlink socket sharing
  2019-06-06 12:23 [dpdk-dev] [PATCH] net/mlx5: fix master device Netlink socket sharing Viacheslav Ovsiienko
@ 2019-06-11 18:29 ` Shahaf Shuler
  0 siblings, 0 replies; 2+ messages in thread
From: Shahaf Shuler @ 2019-06-11 18:29 UTC (permalink / raw)
  To: Slava Ovsiienko, dev

Thursday, June 6, 2019 3:23 PM, Viacheslav Ovsiienko:
> Subject: [PATCH] net/mlx5: fix master device Netlink socket sharing
> 
> There is the patch [1] that uses master device Netlink socket to retrieve
> master device link settings. This is not thread safe because this resource may
> be in use by other call to the master device itself. Using the same Netlink
> socket concurrently from the multiple threads causes Netlink requests
> malfunction and must be eliminated. The patch replaces master Netlink
> socket with the socket from representor device.
> 
> [1] http://patches.dpdk.org/patch/53120/
> 
> Fixes: 0333b2f584d9 ("net/mlx5: inherit master link settings for
> representors")
> Signed-off-by: Viacheslav Ovsiienko <viacheslavo@mellanox.com>

Applied to next-net-mlx, thanks. 



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-06-11 18:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-06 12:23 [dpdk-dev] [PATCH] net/mlx5: fix master device Netlink socket sharing Viacheslav Ovsiienko
2019-06-11 18:29 ` Shahaf Shuler

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).