patches for DPDK stable branches
 help / color / mirror / Atom feed
* [dpdk-stable] [PATCH] net/mlx5: fix netlink rdma socket callback routine
@ 2019-09-10  8:05 Viacheslav Ovsiienko
  2019-09-10 11:49 ` [dpdk-stable] [dpdk-dev] " Raslan Darawsheh
  0 siblings, 1 reply; 2+ messages in thread
From: Viacheslav Ovsiienko @ 2019-09-10  8:05 UTC (permalink / raw)
  To: dev; +Cc: matan, stable

The mlx5 PMD uses Netlink socket to communicate with Infiniband
devices kernel drivers to perform some control and setup operations.
The kernel drivers send the information back to the user mode
with Netlink messages which are processed in libnl callback routine.
This routine perform reply message (or set of messages) processing
and returned the processing result in ibindex field of provided
context structure (of mlx5_nl_ifindex_data type). The zero ibindex
value meant an error of reply message processing. It was found in
some configurations the zero is valid value for ibindex and error
was wrongly raised. To avoid this the new flags field is provided
in context structure, attribute processing flags are introduced
and these flags are used to decide whether no error occurred and
valid queried values are returned.

Fixes: e505508a3858 ("net/mlx5: modify get ifindex routine for multiport IB")
Cc: stable@dpdk.org

Signed-off-by: Viacheslav Ovsiienko <viacheslavo@mellanox.com>
---
 drivers/net/mlx5/mlx5_nl.c | 44 ++++++++++++++++++++++++++------------------
 1 file changed, 26 insertions(+), 18 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_nl.c b/drivers/net/mlx5/mlx5_nl.c
index f0f57de..69b3fa5 100644
--- a/drivers/net/mlx5/mlx5_nl.c
+++ b/drivers/net/mlx5/mlx5_nl.c
@@ -90,12 +90,18 @@ struct mlx5_nl_mac_addr {
 	int mac_n; /**< Number of addresses in the array. */
 };
 
+#define MLX5_NL_CMD_GET_IB_NAME (1 << 0)
+#define MLX5_NL_CMD_GET_IB_INDEX (1 << 1)
+#define MLX5_NL_CMD_GET_NET_INDEX (1 << 2)
+#define MLX5_NL_CMD_GET_PORT_INDEX (1 << 3)
+
 /** Data structure used by mlx5_nl_cmdget_cb(). */
 struct mlx5_nl_ifindex_data {
 	const char *name; /**< IB device name (in). */
+	uint32_t flags; /**< found attribute flags (out). */
 	uint32_t ibindex; /**< IB device index (out). */
 	uint32_t ifindex; /**< Network interface index (out). */
-	uint32_t portnum; /**< IB device max port number. */
+	uint32_t portnum; /**< IB device max port number (out). */
 };
 
 /**
@@ -705,10 +711,6 @@ struct mlx5_nl_ifindex_data {
 {
 	struct mlx5_nl_ifindex_data *data = arg;
 	size_t off = NLMSG_HDRLEN;
-	uint32_t ibindex = 0;
-	uint32_t ifindex = 0;
-	uint32_t portnum = 0;
-	int found = 0;
 
 	if (nh->nlmsg_type !=
 	    RDMA_NL_GET_TYPE(RDMA_NL_NLDEV, RDMA_NLDEV_CMD_GET) &&
@@ -723,28 +725,26 @@ struct mlx5_nl_ifindex_data {
 			goto error;
 		switch (na->nla_type) {
 		case RDMA_NLDEV_ATTR_DEV_INDEX:
-			ibindex = *(uint32_t *)payload;
+			data->ibindex = *(uint32_t *)payload;
+			data->flags |= MLX5_NL_CMD_GET_IB_INDEX;
 			break;
 		case RDMA_NLDEV_ATTR_DEV_NAME:
 			if (!strcmp(payload, data->name))
-				found = 1;
+				data->flags |= MLX5_NL_CMD_GET_IB_NAME;
 			break;
 		case RDMA_NLDEV_ATTR_NDEV_INDEX:
-			ifindex = *(uint32_t *)payload;
+			data->ifindex = *(uint32_t *)payload;
+			data->flags |= MLX5_NL_CMD_GET_NET_INDEX;
 			break;
 		case RDMA_NLDEV_ATTR_PORT_INDEX:
-			portnum = *(uint32_t *)payload;
+			data->portnum = *(uint32_t *)payload;
+			data->flags |= MLX5_NL_CMD_GET_PORT_INDEX;
 			break;
 		default:
 			break;
 		}
 		off += NLA_ALIGN(na->nla_len);
 	}
-	if (found) {
-		data->ibindex = ibindex;
-		data->ifindex = ifindex;
-		data->portnum = portnum;
-	}
 	return 0;
 error:
 	rte_errno = EINVAL;
@@ -774,6 +774,7 @@ struct mlx5_nl_ifindex_data {
 	uint32_t seq = random();
 	struct mlx5_nl_ifindex_data data = {
 		.name = name,
+		.flags = 0,
 		.ibindex = 0, /* Determined during first pass. */
 		.ifindex = 0, /* Determined during second pass. */
 	};
@@ -799,8 +800,10 @@ struct mlx5_nl_ifindex_data {
 	ret = mlx5_nl_recv(nl, seq, mlx5_nl_cmdget_cb, &data);
 	if (ret < 0)
 		return 0;
-	if (!data.ibindex)
+	if (!(data.flags & MLX5_NL_CMD_GET_IB_NAME) ||
+	    !(data.flags & MLX5_NL_CMD_GET_IB_INDEX))
 		goto error;
+	data.flags = 0;
 	++seq;
 	req.nh.nlmsg_type = RDMA_NL_GET_TYPE(RDMA_NL_NLDEV,
 					     RDMA_NLDEV_CMD_PORT_GET);
@@ -822,7 +825,10 @@ struct mlx5_nl_ifindex_data {
 	ret = mlx5_nl_recv(nl, seq, mlx5_nl_cmdget_cb, &data);
 	if (ret < 0)
 		return 0;
-	if (!data.ifindex)
+	if (!(data.flags & MLX5_NL_CMD_GET_IB_NAME) ||
+	    !(data.flags & MLX5_NL_CMD_GET_IB_INDEX) ||
+	    !(data.flags & MLX5_NL_CMD_GET_NET_INDEX) ||
+	    !data.ifindex)
 		goto error;
 	return data.ifindex;
 error:
@@ -847,8 +853,8 @@ struct mlx5_nl_ifindex_data {
 {
 	uint32_t seq = random();
 	struct mlx5_nl_ifindex_data data = {
+		.flags = 0,
 		.name = name,
-		.ibindex = 0,
 		.ifindex = 0,
 		.portnum = 0,
 	};
@@ -866,7 +872,9 @@ struct mlx5_nl_ifindex_data {
 	ret = mlx5_nl_recv(nl, seq, mlx5_nl_cmdget_cb, &data);
 	if (ret < 0)
 		return 0;
-	if (!data.ibindex) {
+	if (!(data.flags & MLX5_NL_CMD_GET_IB_NAME) ||
+	    !(data.flags & MLX5_NL_CMD_GET_IB_INDEX) ||
+	    !(data.flags & MLX5_NL_CMD_GET_PORT_INDEX)) {
 		rte_errno = ENODEV;
 		return 0;
 	}
-- 
1.8.3.1


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

* Re: [dpdk-stable] [dpdk-dev] [PATCH] net/mlx5: fix netlink rdma socket callback routine
  2019-09-10  8:05 [dpdk-stable] [PATCH] net/mlx5: fix netlink rdma socket callback routine Viacheslav Ovsiienko
@ 2019-09-10 11:49 ` Raslan Darawsheh
  0 siblings, 0 replies; 2+ messages in thread
From: Raslan Darawsheh @ 2019-09-10 11:49 UTC (permalink / raw)
  To: Slava Ovsiienko, dev; +Cc: Matan Azrad, stable

Hi,
> -----Original Message-----
> From: dev <dev-bounces@dpdk.org> On Behalf Of Viacheslav Ovsiienko
> Sent: Tuesday, September 10, 2019 11:05 AM
> To: dev@dpdk.org
> Cc: Matan Azrad <matan@mellanox.com>; stable@dpdk.org
> Subject: [dpdk-dev] [PATCH] net/mlx5: fix netlink rdma socket callback
> routine
> 
> The mlx5 PMD uses Netlink socket to communicate with Infiniband
> devices kernel drivers to perform some control and setup operations.
> The kernel drivers send the information back to the user mode
> with Netlink messages which are processed in libnl callback routine.
> This routine perform reply message (or set of messages) processing
> and returned the processing result in ibindex field of provided
> context structure (of mlx5_nl_ifindex_data type). The zero ibindex
> value meant an error of reply message processing. It was found in
> some configurations the zero is valid value for ibindex and error
> was wrongly raised. To avoid this the new flags field is provided
> in context structure, attribute processing flags are introduced
> and these flags are used to decide whether no error occurred and
> valid queried values are returned.
> 
> Fixes: e505508a3858 ("net/mlx5: modify get ifindex routine for multiport IB")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Viacheslav Ovsiienko <viacheslavo@mellanox.com>

Patch applied to next-net-mlx,

Kindest regards,
Raslan Darawsheh


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

end of thread, other threads:[~2019-09-10 11:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-10  8:05 [dpdk-stable] [PATCH] net/mlx5: fix netlink rdma socket callback routine Viacheslav Ovsiienko
2019-09-10 11:49 ` [dpdk-stable] [dpdk-dev] " Raslan Darawsheh

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