[PATCH rdma-next 16/16] RDMA/restrack: Add restrack wrappers to set/get ID and type

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Leon Romanovsky <leonro@xxxxxxxxxxxx>

Avoid direct access to internal restrack values by providing
special wrappers and update previous occurrence for
rdma_res_to_id(), which translated from restrack entry to CM_ID
and not to restrack ID.

Signed-off-by: Leon Romanovsky <leonro@xxxxxxxxxxxx>
---
 drivers/infiniband/core/cma.c          |  6 +++---
 drivers/infiniband/core/restrack.c     | 16 ++++++++++++++
 drivers/infiniband/hw/cxgb4/restrack.c |  2 +-
 include/rdma/rdma_cm.h                 |  2 +-
 include/rdma/restrack.h                | 30 ++++++++++++++++++++++++++
 5 files changed, 51 insertions(+), 5 deletions(-)

diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
index 84f077b2b90a..3e1a9de7667c 100644
--- a/drivers/infiniband/core/cma.c
+++ b/drivers/infiniband/core/cma.c
@@ -162,17 +162,17 @@ struct iw_cm_id *rdma_iw_cm_id(struct rdma_cm_id *id)
 EXPORT_SYMBOL(rdma_iw_cm_id);
 
 /**
- * rdma_res_to_id() - return the rdma_cm_id pointer for this restrack.
+ * rdma_res_to_cmid() - return the rdma_cm_id pointer for this restrack.
  * @res: rdma resource tracking entry pointer
  */
-struct rdma_cm_id *rdma_res_to_id(struct rdma_restrack_entry *res)
+struct rdma_cm_id *rdma_res_to_cmid(struct rdma_restrack_entry *res)
 {
 	struct rdma_id_private *id_priv =
 		container_of(res, struct rdma_id_private, res);
 
 	return &id_priv->id;
 }
-EXPORT_SYMBOL(rdma_res_to_id);
+EXPORT_SYMBOL(rdma_res_to_cmid);
 
 static void cma_add_one(struct ib_device *device);
 static void cma_remove_one(struct ib_device *device, void *client_data);
diff --git a/drivers/infiniband/core/restrack.c b/drivers/infiniband/core/restrack.c
index ff1581347f66..ec43673f12f8 100644
--- a/drivers/infiniband/core/restrack.c
+++ b/drivers/infiniband/core/restrack.c
@@ -397,3 +397,19 @@ void rdma_rt_set_id_range(struct ib_device *dev, enum rdma_restrack_type type,
 	rt[type].reserved = reserved;
 }
 EXPORT_SYMBOL(rdma_rt_set_id_range);
+
+int rdma_rt_set_id(struct rdma_restrack_entry *res, u32 id)
+{
+	struct ib_device *dev = res_to_dev(res);
+	struct xarray *xa = rdma_dev_to_xa(dev, res->type);
+
+	if (xa_load(xa, id) == res) {
+		WARN_ONCE(true, "Tried to add non-unique %s entry %u\n",
+			  type2str(res->type), res->id);
+		return -EEXIST;
+	}
+
+	res->id = id;
+	return 0;
+}
+EXPORT_SYMBOL(rdma_rt_set_id);
diff --git a/drivers/infiniband/hw/cxgb4/restrack.c b/drivers/infiniband/hw/cxgb4/restrack.c
index 9a7520ee41e0..7224742f8b9a 100644
--- a/drivers/infiniband/hw/cxgb4/restrack.c
+++ b/drivers/infiniband/hw/cxgb4/restrack.c
@@ -198,7 +198,7 @@ union union_ep {
 static int fill_res_ep_entry(struct sk_buff *msg,
 			     struct rdma_restrack_entry *res)
 {
-	struct rdma_cm_id *cm_id = rdma_res_to_id(res);
+	struct rdma_cm_id *cm_id = rdma_res_to_cmid(res);
 	struct nlattr *table_attr;
 	struct c4iw_ep_common *epcp;
 	struct c4iw_listen_ep *listen_ep = NULL;
diff --git a/include/rdma/rdma_cm.h b/include/rdma/rdma_cm.h
index 60987a5903b7..008dc8bbe2fb 100644
--- a/include/rdma/rdma_cm.h
+++ b/include/rdma/rdma_cm.h
@@ -426,6 +426,6 @@ void rdma_read_gids(struct rdma_cm_id *cm_id, union ib_gid *sgid,
 		    union ib_gid *dgid);
 
 struct iw_cm_id *rdma_iw_cm_id(struct rdma_cm_id *cm_id);
-struct rdma_cm_id *rdma_res_to_id(struct rdma_restrack_entry *res);
+struct rdma_cm_id *rdma_res_to_cmid(struct rdma_restrack_entry *res);
 
 #endif /* RDMA_CM_H */
diff --git a/include/rdma/restrack.h b/include/rdma/restrack.h
index e70622bf3293..66591558c674 100644
--- a/include/rdma/restrack.h
+++ b/include/rdma/restrack.h
@@ -225,4 +225,34 @@ void rdma_rt_read_unlock(struct ib_device *dev, enum rdma_restrack_type type);
  */
 void rdma_rt_set_id_range(struct ib_device *dev, enum rdma_restrack_type type,
 			  u32 reserved, u32 max);
+/**
+ * rdma_res_to_id() - Unique ID as seen by restrack
+ * @res: resrouce to operate
+ *
+ * Return: unique ID
+ */
+static inline u32 rdma_res_to_id(struct rdma_restrack_entry *res)
+{
+	return res->id;
+}
+/**
+ * rdma_rt_set_id() - Set unique ID as seen by restrack,
+ *                    needed for HW-capable device
+ * @res: resrouce to operate
+ * @id: ID to set
+ *
+ * Return: 0 on success
+ */
+int rdma_rt_set_id(struct rdma_restrack_entry *res, u32 id);
+/**
+ * rdma_rt_set_type() - Set restrack entry type,
+ *                      prior to call rdma_restrack_add()
+ * @res: resrouce to operate
+ * @type: Actual type
+ */
+static inline void rdma_rt_set_type(struct rdma_restrack_entry *res,
+				    enum rdma_restrack_type type)
+{
+	res->type = type;
+}
 #endif /* _RDMA_RESTRACK_H_ */
-- 
2.19.1




[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux