linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jack Wang <jinpu.wang@cloud.ionos.com>
To: linux-rdma@vger.kernel.org
Cc: bvanassche@acm.org, leon@kernel.org, dledford@redhat.com,
	jgg@ziepe.ca, danil.kipnis@cloud.ionos.com,
	jinpu.wang@cloud.ionos.com, Gioh Kim <gi-oh.kim@cloud.ionos.com>
Subject: [PATCH for-next 04/13] RDMA/rtrs-clt: remove unnecessary dev_ref of rtrs_sess
Date: Mon, 12 Oct 2020 15:18:05 +0200	[thread overview]
Message-ID: <20201012131814.121096-5-jinpu.wang@cloud.ionos.com> (raw)
In-Reply-To: <20201012131814.121096-1-jinpu.wang@cloud.ionos.com>

From: Gioh Kim <gi-oh.kim@cloud.ionos.com>

dev_ref of rtrs_sess is used for counting connections sharing
the rtrs_ib_dev object. But rtrs_ib_dev has its own reference counter.
We can use rtrs_ib_dev_get/put.

Signed-off-by: Gioh Kim <gi-oh.kim@cloud.ionos.com>
Signed-off-by: Jack Wang <jinpu.wang@cloud.ionos.com>
---
 drivers/infiniband/ulp/rtrs/rtrs-clt.c | 35 +++++++++++---------------
 drivers/infiniband/ulp/rtrs/rtrs-pri.h |  1 -
 2 files changed, 14 insertions(+), 22 deletions(-)

diff --git a/drivers/infiniband/ulp/rtrs/rtrs-clt.c b/drivers/infiniband/ulp/rtrs/rtrs-clt.c
index 4677e8ed29ae..b1c0c1400c8a 100644
--- a/drivers/infiniband/ulp/rtrs/rtrs-clt.c
+++ b/drivers/infiniband/ulp/rtrs/rtrs-clt.c
@@ -1523,6 +1523,19 @@ static int create_con_cq_qp(struct rtrs_clt_con *con)
 	struct rtrs_msg_rkey_rsp *rsp;
 
 	lockdep_assert_held(&con->con_mutex);
+	/*
+	 * The whole session uses device from user connection.
+	 * Be careful not to close user connection before ib dev
+	 * is gracefully put.
+	 */
+	sess->s.dev = rtrs_ib_dev_find_or_add(con->c.cm_id->device,
+					      &dev_pd);
+	if (!sess->s.dev) {
+		rtrs_wrn(sess->clt,
+			 "rtrs_ib_dev_find_get_or_add(): no memory\n");
+		return -ENOMEM;
+	}
+
 	if (con->c.cid == 0) {
 		/*
 		 * One completion for each receive and two for each send
@@ -1531,23 +1544,7 @@ static int create_con_cq_qp(struct rtrs_clt_con *con)
 		 * in case qp gets into error state
 		 */
 		wr_queue_size = SERVICE_CON_QUEUE_DEPTH * 3 + 2;
-		/* We must be the first here */
-		if (WARN_ON(sess->s.dev))
-			return -EINVAL;
 
-		/*
-		 * The whole session uses device from user connection.
-		 * Be careful not to close user connection before ib dev
-		 * is gracefully put.
-		 */
-		sess->s.dev = rtrs_ib_dev_find_or_add(con->c.cm_id->device,
-						       &dev_pd);
-		if (!sess->s.dev) {
-			rtrs_wrn(sess->clt,
-				  "rtrs_ib_dev_find_get_or_add(): no memory\n");
-			return -ENOMEM;
-		}
-		sess->s.dev_ref = 1;
 		query_fast_reg_mode(sess);
 	} else {
 		/*
@@ -1560,8 +1557,6 @@ static int create_con_cq_qp(struct rtrs_clt_con *con)
 		if (WARN_ON(!sess->queue_depth))
 			return -EINVAL;
 
-		/* Shared between connections */
-		sess->s.dev_ref++;
 		wr_queue_size =
 			min_t(int, sess->s.dev->ib_dev->attrs.max_qp_wr,
 			      /* QD * (REQ + RSP + FR REGS or INVS) + drain */
@@ -1604,10 +1599,8 @@ static void destroy_con_cq_qp(struct rtrs_clt_con *con)
 		con->rsp_ius = NULL;
 		con->queue_size = 0;
 	}
-	if (sess->s.dev_ref && !--sess->s.dev_ref) {
-		rtrs_ib_dev_put(sess->s.dev);
+	if (rtrs_ib_dev_put(sess->s.dev))
 		sess->s.dev = NULL;
-	}
 }
 
 static void stop_cm(struct rtrs_clt_con *con)
diff --git a/drivers/infiniband/ulp/rtrs/rtrs-pri.h b/drivers/infiniband/ulp/rtrs/rtrs-pri.h
index 0a93c87ef92b..287ff78921c7 100644
--- a/drivers/infiniband/ulp/rtrs/rtrs-pri.h
+++ b/drivers/infiniband/ulp/rtrs/rtrs-pri.h
@@ -103,7 +103,6 @@ struct rtrs_sess {
 	unsigned int		con_num;
 	unsigned int		recon_cnt;
 	struct rtrs_ib_dev	*dev;
-	int			dev_ref;
 	struct ib_cqe		*hb_cqe;
 	void			(*hb_err_handler)(struct rtrs_con *con);
 	struct workqueue_struct *hb_wq;
-- 
2.25.1


  parent reply	other threads:[~2020-10-12 13:18 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-12 13:18 [PATCH for-next 00/13] rtrs: misc fix and cleanup Jack Wang
2020-10-12 13:18 ` [PATCH for-next 01/13] RDMA/rtrs-clt: remove destroy_con_cq_qo in case route resolving failed Jack Wang
2020-10-12 13:18 ` [PATCH for-next 02/13] RDMA/rtrs-clt: remove outdated comment in create_con_cq_qp Jack Wang
2020-10-12 13:18 ` [PATCH for-next 03/13] RDMA/rtrs-clt: avoid run destroy_con_cq_qp/create_con_cq_qp in parallel Jack Wang
2020-10-12 13:18 ` Jack Wang [this message]
2020-10-13 14:22   ` [PATCH for-next 04/13] RDMA/rtrs-clt: remove unnecessary dev_ref of rtrs_sess Jinpu Wang
2020-10-12 13:18 ` [PATCH for-next 05/13] RDMA/rtrs: removed unused filed list of rtrs_iu Jack Wang
2020-10-12 13:25   ` Jinpu Wang
2020-10-12 13:18 ` [PATCH for-next 06/13] RDMA/rtrs: remove unnecessary argument dir of rtrs_iu_free Jack Wang
2020-10-12 13:18 ` [PATCH for-next 07/13] RDMA/rtrs-clt: remove duplicated switch-case handling for CM error events Jack Wang
2020-10-12 13:18 ` [PATCH for-next 08/13] RDMA/ibtrs-clt: missing error from rtrs_rdma_conn_established Jack Wang
2020-10-12 13:23   ` Jinpu Wang
2020-10-12 13:18 ` [PATCH for-next 09/13] RDMA/rtrs-clt: remove duplicated code Jack Wang
2020-10-12 13:18 ` [PATCH for-next 10/13] RDMA/rtrs-srv: fix typo Jack Wang
2020-10-12 13:18 ` [PATCH for-next 11/13] RDMA/rtrs-srv: kill rtrs_srv_change_state_get_old Jack Wang
2020-10-12 13:18 ` [PATCH for-next 12/13] RDMA/rtrs: introduce rtrs_post_send Jack Wang
2020-10-12 13:18 ` [PATCH for-next 13/13] RDMA/rtrs-clt: remove 'addr' from rtrs_clt_add_path_to_arr Jack Wang

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=20201012131814.121096-5-jinpu.wang@cloud.ionos.com \
    --to=jinpu.wang@cloud.ionos.com \
    --cc=bvanassche@acm.org \
    --cc=danil.kipnis@cloud.ionos.com \
    --cc=dledford@redhat.com \
    --cc=gi-oh.kim@cloud.ionos.com \
    --cc=jgg@ziepe.ca \
    --cc=leon@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    /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).