All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bob Pearson <rpearsonhpe@gmail.com>
To: linux-rdma@vger.kernel.org
Cc: Bob Pearson <rpearson@hpe.com>
Subject: [PATCH 15/20] Fixed a dumb bug
Date: Fri, 14 Aug 2020 23:58:39 -0500	[thread overview]
Message-ID: <20200815045912.8626-16-rpearson@hpe.com> (raw)
In-Reply-To: <20200815045912.8626-1-rpearson@hpe.com>

added code to prevent infinite loops in get l/rkey
added a drop_key in mr dereg (fixing the root cause of loops)

Signed-off-by: Bob Pearson <rpearson@hpe.com>
---
 drivers/infiniband/sw/rxe/rxe_mr.c    | 22 +++++++++++-----------
 drivers/infiniband/sw/rxe/rxe_mw.c    | 24 +++++++++++++-----------
 drivers/infiniband/sw/rxe/rxe_verbs.c |  1 +
 3 files changed, 25 insertions(+), 22 deletions(-)

diff --git a/drivers/infiniband/sw/rxe/rxe_mr.c b/drivers/infiniband/sw/rxe/rxe_mr.c
index ba4e33227633..533b02fc2d0e 100644
--- a/drivers/infiniband/sw/rxe/rxe_mr.c
+++ b/drivers/infiniband/sw/rxe/rxe_mr.c
@@ -34,20 +34,20 @@
 #include "rxe.h"
 #include "rxe_loc.h"
 
-/* choose a unique non zero random number for lkey */
+/* choose a unique non zero random number for lkey
+ * use high order bit to indicate MR vs MW */
 void rxe_set_mr_lkey(struct rxe_mr *mr)
 {
-	int ret;
 	u32 lkey;
-
-next_lkey:
-	get_random_bytes(&lkey, sizeof(lkey));
-	lkey &= 0x7fffffff;
-	if (unlikely(lkey == 0))
-		goto next_lkey;
-	ret = rxe_add_key(mr, &lkey);
-	if (unlikely(ret == -EAGAIN))
-		goto next_lkey;
+	int tries = 0;
+
+	do {
+		get_random_bytes(&lkey, sizeof(lkey));
+		lkey &= 0x7fffffff;
+		if (likely(lkey && (rxe_add_key(mr, &lkey) == 0)))
+			return;
+	} while (tries++ < 10);
+	pr_err("rxe_set_mr_lkey: unable to get random lkey\n");
 }
 
 #if 0
diff --git a/drivers/infiniband/sw/rxe/rxe_mw.c b/drivers/infiniband/sw/rxe/rxe_mw.c
index b45a04efa4a0..a0ff2543d0cd 100644
--- a/drivers/infiniband/sw/rxe/rxe_mw.c
+++ b/drivers/infiniband/sw/rxe/rxe_mw.c
@@ -35,22 +35,24 @@
 #include "rxe.h"
 #include "rxe_loc.h"
 
-/* choose a unique non zero random number for rkey */
+/* choose a unique non zero random number for rkey
+ * use high order bit to indicate MR vs MW */
 void rxe_set_mw_rkey(struct rxe_mw *mw)
 {
-	int ret;
 	u32 rkey;
-
-next_rkey:
-	get_random_bytes(&rkey, sizeof(rkey));
-	if (unlikely(rkey == 0))
-		goto next_rkey;
-	rkey |= 0x80000000;
-	ret = rxe_add_key(mw, &rkey);
-	if (unlikely(ret == -EAGAIN))
-		goto next_rkey;
+	int tries = 0;
+
+	do {
+		get_random_bytes(&rkey, sizeof(rkey));
+		rkey |= 0x80000000;
+		if (likely((rkey & 0x7fffffff) &&
+			   (rxe_add_key(mw, &rkey) == 0)))
+			return;
+	} while (tries++ < 10);
+	pr_err("rxe_set_mw_rkey: unable to get random rkey\n");
 }
 
+
 /* place holder alloc and dealloc routines
  * TODO add cross references between qp and mr with mw
  * and cleanup when one side is deleted. Enough to make
diff --git a/drivers/infiniband/sw/rxe/rxe_verbs.c b/drivers/infiniband/sw/rxe/rxe_verbs.c
index b91364ba2c68..476d90e3f91f 100644
--- a/drivers/infiniband/sw/rxe/rxe_verbs.c
+++ b/drivers/infiniband/sw/rxe/rxe_verbs.c
@@ -986,6 +986,7 @@ static int rxe_dereg_mr(struct ib_mr *ibmr, struct ib_udata *udata)
 	mr->state = RXE_MEM_STATE_ZOMBIE;
 	rxe_drop_ref(mr->pd);
 	rxe_drop_index(mr);
+	rxe_drop_key(mr);
 	rxe_drop_ref(mr);
 	return 0;
 }
-- 
2.25.1


  parent reply	other threads:[~2020-08-15 22:00 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-15  4:58 Memory windows support for rxe Bob Pearson
2020-08-15  4:58 ` [PATCH 01/20] Added ib_uverbs_wc_opcode to ib_user_verbs.h Bob Pearson
2020-08-15  4:58 ` [PATCH 02/20] Added missing IB_WR_BIND_MW opcode Bob Pearson
2020-08-15  4:58 ` [PATCH 03/20] Added bind_mw parameters to rxe_send_wr Bob Pearson
2020-08-15  4:58 ` [PATCH 04/20] Added stubs for alloc_mw and dealloc_mw verbs Bob Pearson
2020-08-15  4:58 ` [PATCH 05/20] Separated MR and MW objects Bob Pearson
2020-08-15  4:58 ` [PATCH 06/20] Added a basic rxe_mw struct Bob Pearson
2020-08-15  4:58 ` [PATCH 07/20] Implemented functional alloc_mw and dealloc_mw APIs Bob Pearson
2020-08-15  4:58 ` [PATCH 08/20] Added a stubbed bind_mw API Bob Pearson
2020-08-15  4:58 ` [PATCH 09/20] Fixed error logic in rxe_req.c Bob Pearson
2020-08-15  4:58 ` [PATCH 10/20] Extended pools to support both keys and indices Bob Pearson
2020-08-15  4:58 ` [PATCH 11/20] Gave MRs and MWs " Bob Pearson
2020-08-15  4:58 ` [PATCH 12/20] Cleanup after git pull Bob Pearson
2020-08-15  4:58 ` [PATCH 13/20] add debug print statements Bob Pearson
2020-08-15  4:58 ` [PATCH 14/20] Addresses an issue with hardened user copy Bob Pearson
2020-08-15  4:58 ` Bob Pearson [this message]
2020-08-15  4:58 ` [PATCH 16/20] Implemented stubbed invalidate APIs Bob Pearson
2020-08-15  4:58 ` [PATCH 17/20] Implemented functional " Bob Pearson
2020-08-15  4:58 ` [PATCH 18/20] cleanup Bob Pearson
2020-08-15  4:58 ` [PATCH 19/20] fixed white space issues Bob Pearson
2020-08-15  4:58 ` [PATCH 20/20] fixed checkpatch issues for all files in rxe Bob Pearson
2020-08-16  5:29   ` kernel test robot
2020-08-16  5:29     ` kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200815045912.8626-16-rpearson@hpe.com \
    --to=rpearsonhpe@gmail.com \
    --cc=linux-rdma@vger.kernel.org \
    --cc=rpearson@hpe.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.