From patchwork Tue Sep 10 13:51:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Slava Ovsiienko X-Patchwork-Id: 59100 X-Patchwork-Delegate: rasland@nvidia.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 41AB31EF1F; Tue, 10 Sep 2019 15:51:56 +0200 (CEST) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id 415021EDB2 for ; Tue, 10 Sep 2019 15:51:55 +0200 (CEST) Received: from Internal Mail-Server by MTLPINE1 (envelope-from viacheslavo@mellanox.com) with ESMTPS (AES256-SHA encrypted); 10 Sep 2019 16:51:53 +0300 Received: from pegasus12.mtr.labs.mlnx (pegasus12.mtr.labs.mlnx [10.210.17.40]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id x8ADprCB017610; Tue, 10 Sep 2019 16:51:53 +0300 Received: from pegasus12.mtr.labs.mlnx (localhost [127.0.0.1]) by pegasus12.mtr.labs.mlnx (8.14.7/8.14.7) with ESMTP id x8ADpr7H020376; Tue, 10 Sep 2019 13:51:53 GMT Received: (from viacheslavo@localhost) by pegasus12.mtr.labs.mlnx (8.14.7/8.14.7/Submit) id x8ADpqn4020375; Tue, 10 Sep 2019 13:51:52 GMT X-Authentication-Warning: pegasus12.mtr.labs.mlnx: viacheslavo set sender to viacheslavo@mellanox.com using -f From: Viacheslav Ovsiienko To: dev@dpdk.org Cc: rasland@mellanox.com, stable@dpdk.org Date: Tue, 10 Sep 2019 13:51:51 +0000 Message-Id: <1568123511-20153-1-git-send-email-viacheslavo@mellanox.com> X-Mailer: git-send-email 1.8.3.1 Subject: [dpdk-dev] [PATCH v2] net/mlx5: fix netlink rdma socket callback routine X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 --- v2: reverted back local parameter gathering within one Netlink message in callback routine. It allows to avoid parameters overwriting in case of reply contains multiple messages for all Infiniband devices in the system. v1: http://patches.dpdk.org/patch/59057/ drivers/net/mlx5/mlx5_nl.c | 57 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 17 deletions(-) diff --git a/drivers/net/mlx5/mlx5_nl.c b/drivers/net/mlx5/mlx5_nl.c index f0f57de..3e073c6 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). */ }; /** @@ -704,11 +710,10 @@ struct mlx5_nl_ifindex_data { mlx5_nl_cmdget_cb(struct nlmsghdr *nh, void *arg) { struct mlx5_nl_ifindex_data *data = arg; + struct mlx5_nl_ifindex_data local = { + .flags = 0, + }; 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,27 +728,37 @@ struct mlx5_nl_ifindex_data { goto error; switch (na->nla_type) { case RDMA_NLDEV_ATTR_DEV_INDEX: - ibindex = *(uint32_t *)payload; + local.ibindex = *(uint32_t *)payload; + local.flags |= MLX5_NL_CMD_GET_IB_INDEX; break; case RDMA_NLDEV_ATTR_DEV_NAME: if (!strcmp(payload, data->name)) - found = 1; + local.flags |= MLX5_NL_CMD_GET_IB_NAME; break; case RDMA_NLDEV_ATTR_NDEV_INDEX: - ifindex = *(uint32_t *)payload; + local.ifindex = *(uint32_t *)payload; + local.flags |= MLX5_NL_CMD_GET_NET_INDEX; break; case RDMA_NLDEV_ATTR_PORT_INDEX: - portnum = *(uint32_t *)payload; + local.portnum = *(uint32_t *)payload; + local.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; + /* + * It is possible to have multiple messages for all + * Infiniband devices in the system with appropriate name. + * So we should gather parameters locally and copy to + * query context only in case of coinciding device name. + */ + if (local.flags & MLX5_NL_CMD_GET_IB_NAME) { + data->flags = local.flags; + data->ibindex = local.ibindex; + data->ifindex = local.ifindex; + data->portnum = local.portnum; } return 0; error: @@ -774,6 +789,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 +815,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 +840,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 +868,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 +887,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; }