Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
From: Bob Pearson <rpearsonhpe@gmail.com>
To: jgg@nvidia.com, yanjun.zhu@linux.dev, linux-rdma@vger.kernel.org
Cc: Bob Pearson <rpearsonhpe@gmail.com>
Subject: [PATCH for-next 4/6] RDMA/rxe: Let rxe_lookup_mcg use rcu_read_lock
Date: Fri,  3 Nov 2023 15:43:23 -0500	[thread overview]
Message-ID: <20231103204324.9606-5-rpearsonhpe@gmail.com> (raw)
In-Reply-To: <20231103204324.9606-1-rpearsonhpe@gmail.com>

Change locking of read side operations of the multicast group
red-black tree to use rcu read locking. This will allow changing
the mcast lock in the next patch to be changed to a mutex without
breaking rxe_recv.c.

Signed-off-by: Bob Pearson <rpearsonhpe@gmail.com>
---
 drivers/infiniband/sw/rxe/rxe_mcast.c | 35 +++++++--------------------
 drivers/infiniband/sw/rxe/rxe_verbs.h |  1 +
 2 files changed, 10 insertions(+), 26 deletions(-)

diff --git a/drivers/infiniband/sw/rxe/rxe_mcast.c b/drivers/infiniband/sw/rxe/rxe_mcast.c
index ec757b955979..d7b8e31ab480 100644
--- a/drivers/infiniband/sw/rxe/rxe_mcast.c
+++ b/drivers/infiniband/sw/rxe/rxe_mcast.c
@@ -148,7 +148,7 @@ static void __rxe_insert_mcg(struct rxe_mcg *mcg)
 			link = &(*link)->rb_right;
 	}
 
-	rb_link_node(&mcg->node, node, link);
+	rb_link_node_rcu(&mcg->node, node, link);
 	rb_insert_color(&mcg->node, tree);
 }
 
@@ -164,14 +164,13 @@ static void __rxe_remove_mcg(struct rxe_mcg *mcg)
 }
 
 /**
- * __rxe_lookup_mcg - lookup mcg in rxe->mcg_tree while holding lock
+ * rxe_lookup_mcg - lookup mcg in rxe->mcg_tree while holding lock
  * @rxe: rxe device object
  * @mgid: multicast IP address
  *
- * Context: caller must hold rxe->mcg_lock
  * Returns: mcg on success and takes a ref to mcg else NULL
  */
-static struct rxe_mcg *__rxe_lookup_mcg(struct rxe_dev *rxe,
+struct rxe_mcg *rxe_lookup_mcg(struct rxe_dev *rxe,
 					union ib_gid *mgid)
 {
 	struct rb_root *tree = &rxe->mcg_tree;
@@ -179,7 +178,8 @@ static struct rxe_mcg *__rxe_lookup_mcg(struct rxe_dev *rxe,
 	struct rb_node *node;
 	int cmp;
 
-	node = tree->rb_node;
+	rcu_read_lock();
+	node = rcu_dereference_raw(tree->rb_node);
 
 	while (node) {
 		mcg = rb_entry(node, struct rxe_mcg, node);
@@ -187,12 +187,13 @@ static struct rxe_mcg *__rxe_lookup_mcg(struct rxe_dev *rxe,
 		cmp = memcmp(&mcg->mgid, mgid, sizeof(*mgid));
 
 		if (cmp > 0)
-			node = node->rb_left;
+			node = rcu_dereference_raw(node->rb_left);
 		else if (cmp < 0)
-			node = node->rb_right;
+			node = rcu_dereference_raw(node->rb_right);
 		else
 			break;
 	}
+	rcu_read_unlock();
 
 	if (node) {
 		kref_get(&mcg->ref_cnt);
@@ -202,24 +203,6 @@ static struct rxe_mcg *__rxe_lookup_mcg(struct rxe_dev *rxe,
 	return NULL;
 }
 
-/**
- * rxe_lookup_mcg - lookup up mcg in red-back tree
- * @rxe: rxe device object
- * @mgid: multicast IP address
- *
- * Returns: mcg if found else NULL
- */
-struct rxe_mcg *rxe_lookup_mcg(struct rxe_dev *rxe, union ib_gid *mgid)
-{
-	struct rxe_mcg *mcg;
-
-	spin_lock_bh(&rxe->mcg_lock);
-	mcg = __rxe_lookup_mcg(rxe, mgid);
-	spin_unlock_bh(&rxe->mcg_lock);
-
-	return mcg;
-}
-
 /**
  * __rxe_init_mcg - initialize a new mcg
  * @rxe: rxe device
@@ -313,7 +296,7 @@ void rxe_cleanup_mcg(struct kref *kref)
 {
 	struct rxe_mcg *mcg = container_of(kref, typeof(*mcg), ref_cnt);
 
-	kfree(mcg);
+	kfree_rcu(mcg, rcu);
 }
 
 /**
diff --git a/drivers/infiniband/sw/rxe/rxe_verbs.h b/drivers/infiniband/sw/rxe/rxe_verbs.h
index 7be9e6232dd9..8058e5039322 100644
--- a/drivers/infiniband/sw/rxe/rxe_verbs.h
+++ b/drivers/infiniband/sw/rxe/rxe_verbs.h
@@ -345,6 +345,7 @@ struct rxe_mw {
 
 struct rxe_mcg {
 	struct rb_node		node;
+	struct rcu_head		rcu;
 	struct kref		ref_cnt;
 	struct rxe_dev		*rxe;
 	struct list_head	qp_list;
-- 
2.40.1


  parent reply	other threads:[~2023-11-03 20:44 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-03 20:43 [PATCH for-next 0/6] RDMA/rxe: Make multicast actually work Bob Pearson
2023-11-03 20:43 ` [PATCH for-next 1/6] RDMA/rxe: Cleanup rxe_ah/av_chk_attr Bob Pearson
2023-11-03 20:43 ` [PATCH for-next 2/6] RDMA/rxe: Handle loopback of mcast packets Bob Pearson
2023-11-04 12:30   ` Zhu Yanjun
2023-11-03 20:43 ` [PATCH for-next 3/6] RDMA/rxe: Register IP mcast address Bob Pearson
2023-11-04 12:42   ` Zhu Yanjun
2023-11-05 20:19     ` Bob Pearson
2023-11-06 13:26       ` Zhu Yanjun
2023-11-06 17:31         ` Bob Pearson
2023-11-08  1:24           ` Zhu Yanjun
2023-11-03 20:43 ` Bob Pearson [this message]
2023-11-03 20:43 ` [PATCH for-next 5/6] RDMA/rxe: Split multicast lock Bob Pearson
2023-11-03 20:43 ` [PATCH for-next 6/6] RDMA/rxe: Cleanup mcg lifetime Bob Pearson

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=20231103204324.9606-5-rpearsonhpe@gmail.com \
    --to=rpearsonhpe@gmail.com \
    --cc=jgg@nvidia.com \
    --cc=linux-rdma@vger.kernel.org \
    --cc=yanjun.zhu@linux.dev \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox