Blob Blame History Raw
From: Parav Pandit <parav@mellanox.com>
Date: Tue, 19 Jun 2018 10:59:16 +0300
Subject: IB: Make init_ah_attr_grh_fields set sgid_attr
Patch-mainline: v4.19-rc1
Git-commit: aa74f4878d61c83244ad8613082989b60a566ca4
References: bsc#1103992 FATE#326009

Use the sgid and other information from the path record to figure out the
sgid_attrs.

Store the selected table entry in the sgid_attr for everything else to
use.

Signed-off-by: Parav Pandit <parav@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Acked-by: Thomas Bogendoerfer <tbogendoerfer@suse.de>
---
 drivers/infiniband/core/cm.c              |   10 +++++++---
 drivers/infiniband/core/cma.c             |    2 ++
 drivers/infiniband/core/sa_query.c        |   19 +++++++++----------
 drivers/infiniband/ulp/ipoib/ipoib_main.c |    4 +++-
 4 files changed, 21 insertions(+), 14 deletions(-)

--- a/drivers/infiniband/core/cm.c
+++ b/drivers/infiniband/core/cm.c
@@ -554,10 +554,12 @@ static int cm_init_av_by_path(struct sa_
 
 	/*
 	 * av->ah_attr might be initialized based on wc or during
-	 * request processing time. So initialize a new ah_attr on stack.
+	 * request processing time which might have reference to sgid_attr.
+	 * So initialize a new ah_attr on stack.
 	 * If initialization fails, old ah_attr is used for sending any
 	 * responses. If initialization is successful, than new ah_attr
-	 * is used by overwriting the old one.
+	 * is used by overwriting the old one. So that right ah_attr
+	 * can be used to return an error response.
 	 */
 	ret = ib_init_ah_attr_from_path(cm_dev->ib_device, port->port_num, path,
 					&new_ah_attr);
@@ -567,8 +569,10 @@ static int cm_init_av_by_path(struct sa_
 	av->timeout = path->packet_life_time + 1;
 
 	ret = add_cm_id_to_port_list(cm_id_priv, av, port);
-	if (ret)
+	if (ret) {
+		rdma_destroy_ah_attr(&new_ah_attr);
 		return ret;
+	}
 	rdma_move_ah_attr(&av->ah_attr, &new_ah_attr);
 	return 0;
 }
--- a/drivers/infiniband/core/cma.c
+++ b/drivers/infiniband/core/cma.c
@@ -3508,6 +3508,8 @@ static int cma_sidr_rep_handler(struct i
 	}
 
 	ret = id_priv->id.event_handler(&id_priv->id, &event);
+
+	rdma_destroy_ah_attr(&event.param.ud.ah_attr);
 	if (ret) {
 		/* Destroy the CM ID by returning a non-zero value. */
 		id_priv->cm_id.ib = NULL;
--- a/drivers/infiniband/core/sa_query.c
+++ b/drivers/infiniband/core/sa_query.c
@@ -1301,21 +1301,20 @@ static int init_ah_attr_grh_fields(struc
 {
 	enum ib_gid_type type = sa_conv_pathrec_to_gid_type(rec);
 	struct net_device *ndev;
-	u16 gid_index;
-	int ret;
+	const struct ib_gid_attr *gid_attr;
 
 	ndev = ib_get_ndev_from_path(rec);
-	ret = ib_find_cached_gid_by_port(device, &rec->sgid, type,
-					 port_num, ndev, &gid_index);
+	gid_attr =
+		rdma_find_gid_by_port(device, &rec->sgid, type, port_num, ndev);
 	if (ndev)
 		dev_put(ndev);
-	if (ret)
-		return ret;
+	if (IS_ERR(gid_attr))
+		return PTR_ERR(gid_attr);
 
-	rdma_ah_set_grh(ah_attr, &rec->dgid,
-			be32_to_cpu(rec->flow_label),
-			gid_index, rec->hop_limit,
-			rec->traffic_class);
+	rdma_move_grh_sgid_attr(ah_attr, &rec->dgid,
+				be32_to_cpu(rec->flow_label),
+				rec->hop_limit,	rec->traffic_class,
+				gid_attr);
 	return 0;
 }
 
--- a/drivers/infiniband/ulp/ipoib/ipoib_main.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_main.c
@@ -770,8 +770,10 @@ static void path_rec_completion(int stat
 		struct rdma_ah_attr av;
 
 		if (!ib_init_ah_attr_from_path(priv->ca, priv->port,
-					       pathrec, &av))
+					       pathrec, &av)) {
 			ah = ipoib_create_ah(dev, priv->pd, &av);
+			rdma_destroy_ah_attr(&av);
+		}
 	}
 
 	spin_lock_irqsave(&priv->lock, flags);