Skip to contentSkip to conversation

RDMA/irdma: Add support for address handle re-use

PATCH In review Shiraz Saleem 2 participants 3 messages Jan 20, 2022 – Feb 9, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 RDMA/irdma: Add support for address handle re-use

From: Ismail Mustafa <[email protected]>

Address handles (AH) are a limited HW resource and some user applications may create large numbers of identical AH's. Avoid running out of AH's by reusing existing identical ones.

---
 drivers/infiniband/hw/irdma/main.c  |   3 +-
 drivers/infiniband/hw/irdma/main.h  |   3 +
 drivers/infiniband/hw/irdma/verbs.c | 216 ++++++++++++++++++++++++++----------
 drivers/infiniband/hw/irdma/verbs.h |   4 +
 4 files changed, 167 insertions(+), 59 deletions(-)
drivers/infiniband/hw/irdma/main.c +2 -1
index 51a4135..e9aaee8 100644
@@ -235,7 +235,8 @@ static void irdma_fill_device_info(struct irdma_device *iwdev, struct ice_pf *pf
 	rf->gen_ops.request_reset = irdma_request_reset;
 	rf->limits_sel = 7;
 	rf->iwdev = iwdev;
-
+	INIT_LIST_HEAD(&iwdev->ah_list);
+	mutex_init(&iwdev->ah_list_lock);
 	iwdev->netdev = vsi->netdev;
 	iwdev->vsi_num = vsi->vsi_num;
 	iwdev->init_state = INITIAL_STATE;
drivers/infiniband/hw/irdma/main.h +3 -0
index cb218ca..54d5c80 100644
@@ -332,6 +332,9 @@ struct irdma_device {
 	struct workqueue_struct *cleanup_wq;
 	struct irdma_sc_vsi vsi;
 	struct irdma_cm_core cm_core;
+	struct list_head ah_list;
+	struct mutex ah_list_lock; /* protect AH list access */
+	u32 ah_list_cnt;
 	u32 roce_cwnd;
 	u32 roce_ackcreds;
 	u32 vendor_id;
drivers/infiniband/hw/irdma/verbs.c +158 -58

282 lines not on this page · raw message

drivers/infiniband/hw/irdma/verbs.h +4 -0
index d0fdef8..4640bef 100644
@@ -7,6 +7,7 @@
 
 #define IRDMA_PKEY_TBL_SZ		1
 #define IRDMA_DEFAULT_PKEY		0xFFFF
+#define IRDMA_MAX_AH_LIST_SZ		0x20000
 
 struct irdma_ucontext {
 	struct ib_ucontext ibucontext;
@@ -43,6 +44,9 @@ struct irdma_ah {
 	struct irdma_av av;
 	u8 sgid_index;
 	union ib_gid dgid;
+	struct list_head list;
+	refcount_t refcnt;
+	struct irdma_ah *parent_ah; /* AH from cached list */
 };
 
 struct irdma_hmc_pble {
Signature · 1 line
1.8.3.1
maintainer
#1 lore raw
Quoted 18 lines · Shiraz Saleem
drivers/infiniband/hw/irdma/verbs.c +12 -5
+/**
+ * irdma_ah_exists - Check for existing identical AH
+ * @iwdev: irdma device
+ * @new_ah: AH to check for
+ *
+ * returns true if AH is found, false if not found.
+ */
+static bool irdma_ah_exists(struct irdma_device *iwdev,
+			    struct irdma_ah *new_ah)
+{
+	struct irdma_ah *ah;
 
-		if (!cnt) {
-			ibdev_dbg(&iwdev->ibdev,
-				  "VERBS: CQP create AH timed out");
-			err = -ETIMEDOUT;
-			goto error;
+	list_for_each_entry (ah, &iwdev->ah_list, list) {

drivers/infiniband/hw/irdma/verbs.c static int irdma_create_ah(struct ib_ah *ibah, · line 4285

Quoted 10 lines
drivers/infiniband/hw/irdma/verbs.c +8 -0
+		/* Set ah_valid and ah_id the same so memcmp can work */
+		new_ah->sc_ah.ah_info.ah_idx = ah->sc_ah.ah_info.ah_idx;
+		new_ah->sc_ah.ah_info.ah_valid = ah->sc_ah.ah_info.ah_valid;
+		if (!memcmp(&ah->sc_ah.ah_info, &new_ah->sc_ah.ah_info,
+			    sizeof(ah->sc_ah.ah_info))) {
+			refcount_inc(&ah->refcnt);
+			new_ah->parent_ah = ah;
+			return true;
 		}
 	}

So, the number of AHs is so large the HW has problems but you propose to use a linear search to de-dup them?

Are you sure?

Quoted 5 lines
drivers/infiniband/hw/irdma/verbs.c +5 -0
+static int irdma_create_user_ah(struct ib_ah *ibah,
+				struct rdma_ah_init_attr *attr,
+				struct ib_udata *udata)
+{
+	struct irdma_ah *ah = container_of(ibah, struct irdma_ah, ibah);

drivers/infiniband/hw/irdma/verbs.c static int irdma_destroy_ah(struct ib_ah *ibah, u32 ah_flags) · line 4343

Quoted 10 lines
drivers/infiniband/hw/irdma/verbs.c +10 -0
+	struct irdma_device *iwdev = to_iwdev(ibah->pd->device);
+	struct irdma_create_ah_resp uresp;
+	struct irdma_ah *parent_ah;
+	int err;
+
+	err = irdma_setup_ah(ibah, attr);
+	if (err)
+		return err;
+	if (attr->flags & RDMA_CREATE_AH_SLEEPABLE) {
+		mutex_lock(&iwdev->ah_list_lock);

User AH's are always sleepable, no need for these extra paths.

Jason

#2 lore raw
Quoted 27 lines

Subject: Re: [PATCH rdma-next] RDMA/irdma: Add support for address handle re- use

Quoted 23 lines · Shiraz Saleem
drivers/infiniband/hw/irdma/verbs.c +17 -5
+/**
+ * irdma_ah_exists - Check for existing identical AH
+ * @iwdev: irdma device
+ * @new_ah: AH to check for
+ *
+ * returns true if AH is found, false if not found.
+ */
+static bool irdma_ah_exists(struct irdma_device *iwdev,
+			    struct irdma_ah *new_ah)
+{
+	struct irdma_ah *ah;
 
-		if (!cnt) {
-			ibdev_dbg(&iwdev->ibdev,
-				  "VERBS: CQP create AH timed out");
-			err = -ETIMEDOUT;
-			goto error;
+	list_for_each_entry (ah, &iwdev->ah_list, list) {
+		/* Set ah_valid and ah_id the same so memcmp can work */
+		new_ah->sc_ah.ah_info.ah_idx = ah->sc_ah.ah_info.ah_idx;
+		new_ah->sc_ah.ah_info.ah_valid = ah->sc_ah.ah_info.ah_valid;
+		if (!memcmp(&ah->sc_ah.ah_info, &new_ah->sc_ah.ah_info,
+			    sizeof(ah->sc_ah.ah_info))) {
Quoted 8 lines

drivers/infiniband/hw/irdma/verbs.c static int irdma_create_ah(struct ib_ah *ibah, · line 4285

Quoted 5 lines
drivers/infiniband/hw/irdma/verbs.c +3 -0
+			refcount_inc(&ah->refcnt);
+			new_ah->parent_ah = ah;
+			return true;
 		}
 	}

So, the number of AHs is so large the HW has problems but you propose to use a linear search to de-dup them?

We will look into optimizing this search.

Quoted 10 lines
Quoted 10 lines
drivers/infiniband/hw/irdma/verbs.c +9 -0
+static int irdma_create_user_ah(struct ib_ah *ibah,
+				struct rdma_ah_init_attr *attr,
+				struct ib_udata *udata)
+{
+	struct irdma_ah *ah = container_of(ibah, struct irdma_ah, ibah);
+	struct irdma_device *iwdev = to_iwdev(ibah->pd->device);
+	struct irdma_create_ah_resp uresp;
+	struct irdma_ah *parent_ah;
+	int err;
Quoted 9 lines

drivers/infiniband/hw/irdma/verbs.c static int irdma_destroy_ah(struct ib_ah *ibah, u32 ah_flags) · line 4343

Quoted 6 lines
drivers/infiniband/hw/irdma/verbs.c +6 -0
+
+	err = irdma_setup_ah(ibah, attr);
+	if (err)
+		return err;
+	if (attr->flags & RDMA_CREATE_AH_SLEEPABLE) {
+		mutex_lock(&iwdev->ah_list_lock);

User AH's are always sleepable, no need for these extra paths.

Ok.

Thanks a lot for the feedback.

Shiraz