linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bob Pearson <rpearsonhpe@gmail.com>
To: jgg@nvidia.com, zyjzyj2000@gmail.com, linux-rdma@vger.kernel.org
Cc: Bob Pearson <rpearsonhpe@gmail.com>
Subject: [PATCH for-next v10 15/17] RDMA/rxe: Add code to cleanup mcast memory
Date: Mon, 31 Jan 2022 16:08:48 -0600	[thread overview]
Message-ID: <20220131220849.10170-16-rpearsonhpe@gmail.com> (raw)
In-Reply-To: <20220131220849.10170-1-rpearsonhpe@gmail.com>

Well behaved applications will free all memory allocated by multicast
but programs which do not clean up properly can leave behind allocated
memory when the rxe driver is unloaded. This patch walks the red-black
tree holding multicast group elements and then walks the list of attached
qp's freeing the mca's and finally the mcg's.

Signed-off-by: Bob Pearson <rpearsonhpe@gmail.com>
---
 drivers/infiniband/sw/rxe/rxe.c       |  2 ++
 drivers/infiniband/sw/rxe/rxe_loc.h   |  1 +
 drivers/infiniband/sw/rxe/rxe_mcast.c | 31 +++++++++++++++++++++++++++
 3 files changed, 34 insertions(+)

diff --git a/drivers/infiniband/sw/rxe/rxe.c b/drivers/infiniband/sw/rxe/rxe.c
index c560d467a972..74c5521e9b3d 100644
--- a/drivers/infiniband/sw/rxe/rxe.c
+++ b/drivers/infiniband/sw/rxe/rxe.c
@@ -29,6 +29,8 @@ void rxe_dealloc(struct ib_device *ib_dev)
 	rxe_pool_cleanup(&rxe->mr_pool);
 	rxe_pool_cleanup(&rxe->mw_pool);
 
+	rxe_cleanup_mcast(rxe);
+
 	if (rxe->tfm)
 		crypto_free_shash(rxe->tfm);
 }
diff --git a/drivers/infiniband/sw/rxe/rxe_loc.h b/drivers/infiniband/sw/rxe/rxe_loc.h
index 409efeecd581..0bc1b7e2877c 100644
--- a/drivers/infiniband/sw/rxe/rxe_loc.h
+++ b/drivers/infiniband/sw/rxe/rxe_loc.h
@@ -44,6 +44,7 @@ struct rxe_mcg *rxe_lookup_mcg(struct rxe_dev *rxe, union ib_gid *mgid);
 int rxe_attach_mcast(struct ib_qp *ibqp, union ib_gid *mgid, u16 mlid);
 int rxe_detach_mcast(struct ib_qp *ibqp, union ib_gid *mgid, u16 mlid);
 void rxe_cleanup_mcg(struct kref *kref);
+void rxe_cleanup_mcast(struct rxe_dev *rxe);
 
 /* rxe_mmap.c */
 struct rxe_mmap_info {
diff --git a/drivers/infiniband/sw/rxe/rxe_mcast.c b/drivers/infiniband/sw/rxe/rxe_mcast.c
index ed23d0a270fd..00b4e3046d39 100644
--- a/drivers/infiniband/sw/rxe/rxe_mcast.c
+++ b/drivers/infiniband/sw/rxe/rxe_mcast.c
@@ -362,3 +362,34 @@ int rxe_detach_mcast(struct ib_qp *ibqp, union ib_gid *mgid, u16 mlid)
 
 	return rxe_mcast_drop_grp_elem(rxe, qp, mgid);
 }
+
+/**
+ * rxe_cleanup_mcast - cleanup all resources held by mcast
+ * @rxe: rxe object
+ *
+ * Called when rxe device is unloaded. Walk red-black tree to
+ * find all mcg's and then walk mcg->qp_list to find all mca's and
+ * free them. These should have been freed already if apps are
+ * well behaved.
+ */
+void rxe_cleanup_mcast(struct rxe_dev *rxe)
+{
+	struct rb_root *root = &rxe->mcg_tree;
+	struct rb_node *node, *next;
+	struct rxe_mcg *mcg;
+	struct rxe_mca *mca, *tmp;
+
+	for (node = rb_first(root); node; node = next) {
+		next = rb_next(node);
+		mcg = rb_entry(node, typeof(*mcg), node);
+
+		spin_lock_bh(&rxe->mcg_lock);
+		list_for_each_entry_safe(mca, tmp, &mcg->qp_list, qp_list)
+			kfree(mca);
+
+		__rxe_remove_mcg(mcg);
+		spin_unlock_bh(&rxe->mcg_lock);
+
+		kfree(mcg);
+	}
+}
-- 
2.32.0


  parent reply	other threads:[~2022-01-31 22:10 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-31 22:08 [PATCH for-next v10 00/17] Move two object pools to rxe_mcast.c Bob Pearson
2022-01-31 22:08 ` [PATCH for-next v10 01/17] RDMA/rxe: Move rxe_mcast_add/delete " Bob Pearson
2022-01-31 22:08 ` [PATCH for-next v10 02/17] RDMA/rxe: Move rxe_mcast_attach/detach " Bob Pearson
2022-01-31 22:08 ` [PATCH for-next v10 03/17] RDMA/rxe: Rename rxe_mc_grp and rxe_mc_elem Bob Pearson
2022-01-31 22:08 ` [PATCH for-next v10 04/17] RDMA/rxe: Enforce IBA o10-2.2.3 Bob Pearson
2022-01-31 22:08 ` [PATCH for-next v10 05/17] RDMA/rxe: Remove rxe_drop_all_macst_groups Bob Pearson
2022-01-31 22:08 ` [PATCH for-next v10 06/17] RDMA/rxe: Remove qp->grp_lock and qp->grp_list Bob Pearson
2022-01-31 22:08 ` [PATCH for-next v10 07/17] RDMA/rxe: Use kzmalloc/kfree for mca Bob Pearson
2022-02-01  1:03   ` kernel test robot
2022-02-01 14:53   ` Jason Gunthorpe
2022-02-01 20:00     ` Bob Pearson
2022-02-01 20:14       ` Jason Gunthorpe
2022-02-01 20:30         ` Bob Pearson
2022-02-01 18:20   ` kernel test robot
2022-01-31 22:08 ` [PATCH for-next v10 08/17] RDMA/rxe: Rename grp to mcg and mce to mca Bob Pearson
2022-01-31 22:08 ` [PATCH for-next v10 09/17] RDMA/rxe: Introduce RXECB(skb) Bob Pearson
2022-01-31 22:08 ` [PATCH for-next v10 10/17] RDMA/rxe: Split rxe_rcv_mcast_pkt into two phases Bob Pearson
2022-01-31 22:08 ` [PATCH for-next v10 11/17] RDMA/rxe: Replace mcg locks by rxe->mcg_lock Bob Pearson
2022-01-31 22:08 ` [PATCH for-next v10 12/17] RDMA/rxe: Replace pool key by rxe->mcg_tree Bob Pearson
2022-01-31 22:08 ` [PATCH for-next v10 13/17] RDMA/rxe: Remove key'ed object support Bob Pearson
2022-01-31 22:08 ` [PATCH for-next v10 14/17] RDMA/rxe: Remove mcg from rxe pools Bob Pearson
2022-01-31 22:08 ` Bob Pearson [this message]
2022-01-31 22:08 ` [PATCH for-next v10 16/17] RDMA/rxe: Add comments to rxe_mcast.c Bob Pearson
2022-01-31 22:08 ` [PATCH for-next v10 17/17] RDMA/rxe: Finish cleanup of rxe_mcast.c Bob Pearson
2022-02-01 14:36 ` [PATCH for-next v10 00/17] Move two object pools to rxe_mcast.c Jason Gunthorpe

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=20220131220849.10170-16-rpearsonhpe@gmail.com \
    --to=rpearsonhpe@gmail.com \
    --cc=jgg@nvidia.com \
    --cc=linux-rdma@vger.kernel.org \
    --cc=zyjzyj2000@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).