All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bart Van Assche <bart.vanassche-Sjgp3cTcYWE@public.gmane.org>
To: Jason Gunthorpe <jgg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
Cc: Doug Ledford <dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>,
	linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Bart Van Assche <bart.vanassche-Sjgp3cTcYWE@public.gmane.org>
Subject: [PATCH v2 01/14] IB/srpt: Make it safe to use RCU for srpt_device.rch_list
Date: Tue, 16 Jan 2018 16:14:05 -0800	[thread overview]
Message-ID: <20180117001418.7852-2-bart.vanassche@wdc.com> (raw)
In-Reply-To: <20180117001418.7852-1-bart.vanassche-Sjgp3cTcYWE@public.gmane.org>

The next patch will iterate over rch_list from a context from which
it is not allowed to block. Hence make rch_list RCU-safe.

Signed-off-by: Bart Van Assche <bart.vanassche-Sjgp3cTcYWE@public.gmane.org>
---
 drivers/infiniband/ulp/srpt/ib_srpt.c | 13 ++++++++++---
 drivers/infiniband/ulp/srpt/ib_srpt.h |  2 ++
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/infiniband/ulp/srpt/ib_srpt.c b/drivers/infiniband/ulp/srpt/ib_srpt.c
index d78f60dcc2ba..4dd15378bc7c 100644
--- a/drivers/infiniband/ulp/srpt/ib_srpt.c
+++ b/drivers/infiniband/ulp/srpt/ib_srpt.c
@@ -1906,7 +1906,7 @@ static void srpt_free_ch(struct kref *kref)
 {
 	struct srpt_rdma_ch *ch = container_of(kref, struct srpt_rdma_ch, kref);
 
-	kfree(ch);
+	kfree_rcu(ch, rcu);
 }
 
 static void srpt_release_channel_work(struct work_struct *w)
@@ -1945,11 +1945,17 @@ static void srpt_release_channel_work(struct work_struct *w)
 			     srp_max_req_size, DMA_FROM_DEVICE);
 
 	mutex_lock(&sdev->mutex);
-	list_del_init(&ch->list);
+	list_del_rcu(&ch->list);
 	if (ch->release_done)
 		complete(ch->release_done);
 	mutex_unlock(&sdev->mutex);
 
+	synchronize_rcu();
+
+	mutex_lock(&sdev->mutex);
+	INIT_LIST_HEAD(&ch->list);
+	mutex_unlock(&sdev->mutex);
+
 	wake_up(&sdev->ch_releaseQ);
 
 	kref_put(&ch->kref, srpt_free_ch);
@@ -2064,6 +2070,7 @@ static int srpt_cm_req_recv(struct ib_cm_id *cm_id,
 		goto reject;
 	}
 
+	init_rcu_head(&ch->rcu);
 	kref_init(&ch->kref);
 	ch->zw_cqe.done = srpt_zerolength_write_done;
 	INIT_WORK(&ch->release_work, srpt_release_channel_work);
@@ -2190,7 +2197,7 @@ static int srpt_cm_req_recv(struct ib_cm_id *cm_id,
 	}
 
 	mutex_lock(&sdev->mutex);
-	list_add_tail(&ch->list, &sdev->rch_list);
+	list_add_tail_rcu(&ch->list, &sdev->rch_list);
 	mutex_unlock(&sdev->mutex);
 
 	goto out;
diff --git a/drivers/infiniband/ulp/srpt/ib_srpt.h b/drivers/infiniband/ulp/srpt/ib_srpt.h
index 11ce8c94a051..0ab59c60f2ef 100644
--- a/drivers/infiniband/ulp/srpt/ib_srpt.h
+++ b/drivers/infiniband/ulp/srpt/ib_srpt.h
@@ -244,6 +244,7 @@ enum rdma_ch_state {
  * @qp:            IB queue pair used for communicating over this channel.
  * @cq:            IB completion queue for this channel.
  * @zw_cqe:	   Zero-length write CQE.
+ * @rcu:           RCU head.
  * @kref:	   kref for this channel.
  * @rq_size:       IB receive queue size.
  * @max_rsp_size:  Maximum size of an RSP response message in bytes.
@@ -276,6 +277,7 @@ struct srpt_rdma_ch {
 	struct ib_qp		*qp;
 	struct ib_cq		*cq;
 	struct ib_cqe		zw_cqe;
+	struct rcu_head		rcu;
 	struct kref		kref;
 	int			rq_size;
 	u32			max_rsp_size;
-- 
2.15.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2018-01-17  0:14 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-17  0:14 [PATCH v2 00/14] IB/srpt: Add RDMA/CM support Bart Van Assche
     [not found] ` <20180117001418.7852-1-bart.vanassche-Sjgp3cTcYWE@public.gmane.org>
2018-01-17  0:14   ` Bart Van Assche [this message]
2018-01-17  0:14   ` [PATCH v2 02/14] IB/srpt: Rework srpt_disconnect_ch_sync() Bart Van Assche
2018-01-17  0:14   ` [PATCH v2 03/14] IB/srpt: Add P_Key support Bart Van Assche
2018-01-17  0:14   ` [PATCH v2 04/14] IB/srpt: One target per port Bart Van Assche
2018-01-17  0:14   ` [PATCH v2 05/14] IB/srpt: Use the source GID as session name Bart Van Assche
2018-01-17  0:14   ` [PATCH v2 06/14] IB/srpt: Rework multi-channel support Bart Van Assche
2018-01-17  0:14   ` [PATCH v2 07/14] IB/srpt: Simplify srpt_close_session() Bart Van Assche
2018-01-17  0:14   ` [PATCH v2 08/14] IB/srpt: Log all zero-length writes and completions Bart Van Assche
2018-01-17  0:14   ` [PATCH v2 09/14] IB/srpt: Fix login-related race conditions Bart Van Assche
2018-01-17  0:14   ` [PATCH v2 10/14] IB/srpt: Fix a race condition related to wait list processing Bart Van Assche
2018-01-17  0:14   ` [PATCH v2 11/14] IB/srpt: Avoid that wait list processing triggers command reordering Bart Van Assche
2018-01-17  0:14   ` [PATCH v2 12/14] IB/srpt: Prepare RDMA/CM support Bart Van Assche
2018-01-17  0:14   ` [PATCH v2 13/14] IB/srpt: Move the code for parsing struct ib_cm_req_event_param Bart Van Assche
2018-01-17  0:14   ` [PATCH v2 14/14] IB/srpt: Add RDMA/CM support Bart Van Assche
2018-01-17 23:14   ` [PATCH v2 00/14] " Doug Ledford
     [not found]     ` <1516230870.3403.292.camel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2018-01-30  0:23       ` Bart Van Assche
     [not found]         ` <1517271807.2687.65.camel-Sjgp3cTcYWE@public.gmane.org>
2018-01-30 17:43           ` Doug Ledford
     [not found]             ` <1517334206.27592.291.camel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2018-01-30 18:19               ` Bart Van Assche
     [not found]                 ` <1517336389.2589.22.camel-Sjgp3cTcYWE@public.gmane.org>
2018-01-30 22:29                   ` Doug Ledford
     [not found]                     ` <1517351373.19117.6.camel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2018-02-12 18:04                       ` Bart Van Assche
2018-01-17 23:33   ` Doug Ledford
     [not found]     ` <1516231986.3403.296.camel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2018-01-17 23:41       ` Bart Van Assche
     [not found]         ` <1516232517.2820.93.camel-Sjgp3cTcYWE@public.gmane.org>
2018-01-18  1:34           ` Doug Ledford

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=20180117001418.7852-2-bart.vanassche@wdc.com \
    --to=bart.vanassche-sjgp3ctcywe@public.gmane.org \
    --cc=dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=jgg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org \
    --cc=linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.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 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.