linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bart Van Assche <bart.vanassche-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
To: Doug Ledford <dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Cc: Sagi Grimberg
	<sagig-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>,
	Sebastian Parschauer
	<sebastian.riemer-EIkl63zCoXaH+58JC4qpiA@public.gmane.org>,
	"linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
	<linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Subject: [PATCH 4/7] IB/srp: Fix a potential queue overflow in an error path
Date: Tue, 27 Oct 2015 15:02:44 -0700	[thread overview]
Message-ID: <562FF484.6030400@sandisk.com> (raw)
In-Reply-To: <562FF404.7000504-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>

Wait until memory registration has finished in the srp_queuecommand()
error path before invalidating memory regions to avoid a send queue
overflow.

Signed-off-by: Bart Van Assche <bart.vanassche-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
Cc: Sagi Grimberg <sagig-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
Cc: Sebastian Parschauer <sebastian.riemer-EIkl63zCoXaH+58JC4qpiA@public.gmane.org>
---
 drivers/infiniband/ulp/srp/ib_srp.c | 41 ++++++++++++++++++++++++++++++-------
 1 file changed, 34 insertions(+), 7 deletions(-)

diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c
index 1aa9a4c..6d17fe2 100644
--- a/drivers/infiniband/ulp/srp/ib_srp.c
+++ b/drivers/infiniband/ulp/srp/ib_srp.c
@@ -1044,7 +1044,7 @@ static int srp_connect_ch(struct srp_rdma_ch *ch, bool multich)
 	}
 }
 
-static int srp_inv_rkey(struct srp_rdma_ch *ch, u32 rkey)
+static int srp_inv_rkey(struct srp_rdma_ch *ch, u32 rkey, u32 send_flags)
 {
 	struct ib_send_wr *bad_wr;
 	struct ib_send_wr wr = {
@@ -1052,16 +1052,32 @@ static int srp_inv_rkey(struct srp_rdma_ch *ch, u32 rkey)
 		.wr_id		    = LOCAL_INV_WR_ID,
 		.next		    = NULL,
 		.num_sge	    = 0,
-		.send_flags	    = 0,
+		.send_flags	    = send_flags,
 		.ex.invalidate_rkey = rkey,
 	};
 
 	return ib_post_send(ch->qp, &wr, &bad_wr);
 }
 
+static bool srp_wait_until_done(struct srp_rdma_ch *ch, int i, long timeout)
+{
+	WARN_ON_ONCE(timeout <= 0);
+
+	for ( ; i > 0; i--) {
+		spin_lock_irq(&ch->lock);
+		srp_send_completion(ch->send_cq, ch);
+		spin_unlock_irq(&ch->lock);
+
+		if (wait_for_completion_timeout(&ch->done, timeout) > 0)
+			return true;
+	}
+	return false;
+}
+
 static void srp_unmap_data(struct scsi_cmnd *scmnd,
 			   struct srp_rdma_ch *ch,
-			   struct srp_request *req)
+			   struct srp_request *req,
+			   bool wait_for_first_unmap)
 {
 	struct srp_target_port *target = ch->target;
 	struct srp_device *dev = target->srp_host->srp_dev;
@@ -1077,13 +1093,19 @@ static void srp_unmap_data(struct scsi_cmnd *scmnd,
 		struct srp_fr_desc **pfr;
 
 		for (i = req->nmdesc, pfr = req->fr_list; i > 0; i--, pfr++) {
-			res = srp_inv_rkey(ch, (*pfr)->mr->rkey);
+			res = srp_inv_rkey(ch, (*pfr)->mr->rkey,
+					   wait_for_first_unmap ?
+					   IB_SEND_SIGNALED : 0);
 			if (res < 0) {
 				shost_printk(KERN_ERR, target->scsi_host, PFX
 				  "Queueing INV WR for rkey %#x failed (%d)\n",
 				  (*pfr)->mr->rkey, res);
 				queue_work(system_long_wq,
 					   &target->tl_err_work);
+			} else if (wait_for_first_unmap) {
+				wait_for_first_unmap = false;
+				WARN_ON_ONCE(!srp_wait_until_done(ch, 10,
+							msecs_to_jiffies(100)));
 			}
 		}
 		if (req->nmdesc)
@@ -1144,7 +1166,7 @@ static void srp_free_req(struct srp_rdma_ch *ch, struct srp_request *req,
 {
 	unsigned long flags;
 
-	srp_unmap_data(scmnd, ch, req);
+	srp_unmap_data(scmnd, ch, req, false);
 
 	spin_lock_irqsave(&ch->lock, flags);
 	ch->req_lim += req_lim_delta;
@@ -1982,7 +2004,12 @@ static void srp_send_completion(struct ib_cq *cq, void *ch_ptr)
 	struct srp_iu *iu;
 
 	while (ib_poll_cq(cq, 1, &wc) > 0) {
-		if (likely(wc.status == IB_WC_SUCCESS)) {
+		if (unlikely(wc.wr_id == LOCAL_INV_WR_ID)) {
+			complete(&ch->done);
+			if (wc.status != IB_WC_SUCCESS)
+				srp_handle_qp_err(wc.wr_id, wc.status, true,
+						  ch);
+		} else if (likely(wc.status == IB_WC_SUCCESS)) {
 			iu = (struct srp_iu *) (uintptr_t) wc.wr_id;
 			list_add(&iu->list, &ch->free_tx);
 		} else {
@@ -2084,7 +2111,7 @@ unlock_rport:
 	return ret;
 
 err_unmap:
-	srp_unmap_data(scmnd, ch, req);
+	srp_unmap_data(scmnd, ch, req, true);
 
 err_iu:
 	srp_put_tx_iu(ch, iu, SRP_IU_CMD);
-- 
2.1.4

--
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:[~2015-10-27 22:02 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-27 22:00 [PATCH 0/7] Fix an infinite loop in the SRP initiator Bart Van Assche
     [not found] ` <562FF404.7000504-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
2015-10-27 22:01   ` [PATCH 1/7] IB/srp: Fix a spelling error Bart Van Assche
     [not found]     ` <562FF427.3000306-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
2015-11-03 17:27       ` Sagi Grimberg
2015-10-27 22:01   ` [PATCH 2/7] IB/srp: Document srp_map_data() return value Bart Van Assche
     [not found]     ` <562FF43F.2000404-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
2015-11-03 17:28       ` Sagi Grimberg
2015-10-27 22:02   ` [PATCH 3/7] IB/srp: Rename work request ID labels Bart Van Assche
     [not found]     ` <562FF463.40107-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
2015-11-03 17:28       ` Sagi Grimberg
2015-10-27 22:02   ` Bart Van Assche [this message]
     [not found]     ` <562FF484.6030400-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
2015-11-03 17:36       ` [PATCH 4/7] IB/srp: Fix a potential queue overflow in an error path Sagi Grimberg
     [not found]         ` <5638F08D.9070206-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
2015-11-03 19:04           ` Bart Van Assche
     [not found]             ` <56390557.204-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
2015-11-03 19:56               ` Sagi Grimberg
     [not found]                 ` <56391181.8040207-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
2015-11-03 20:01                   ` Bart Van Assche
     [not found]                     ` <56391290.2080708-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
2015-11-03 20:13                       ` Sagi Grimberg
     [not found]                         ` <5639157C.2060107-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
2015-11-03 20:50                           ` Bart Van Assche
     [not found]                             ` <56391E33.5050300-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
2015-11-04  4:03                               ` Christoph Hellwig
     [not found]                                 ` <20151104040322.GA22142-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2015-11-04 22:19                                   ` Bart Van Assche
2015-10-27 22:03   ` [PATCH 5/7] IB/srp: Fix srp_map_data() error paths Bart Van Assche
2015-10-27 22:03   ` [PATCH 6/7] IB/srp: Introduce target->mr_pool_size Bart Van Assche
     [not found]     ` <562FF4BC.6030100-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
2015-11-03 17:37       ` Sagi Grimberg
2015-10-27 22:04   ` [PATCH 7/7] IB/srp: Avoid that mapping failure triggers an infinite loop Bart Van Assche
     [not found]     ` <562FF4D9.2060809-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
2015-11-03 17:43       ` Sagi Grimberg
     [not found]         ` <5638F25D.703-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
2015-11-03 18:56           ` Bart Van Assche
     [not found]             ` <5639034D.8000905-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
2015-11-03 18:59               ` Sagi Grimberg
     [not found]                 ` <5639040F.1040503-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
2015-11-03 19:12                   ` Bart Van Assche
     [not found]                     ` <56390730.703-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
2015-11-03 19:53                       ` Sagi Grimberg
2015-10-28 10:32   ` [PATCH 0/7] Fix an infinite loop in the SRP initiator Sagi Grimberg
     [not found]     ` <5630A454.40604-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
2015-10-28 15:32       ` Bart Van Assche

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=562FF484.6030400@sandisk.com \
    --to=bart.vanassche-xdaiopvojttbdgjk7y7tuq@public.gmane.org \
    --cc=dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=sagig-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org \
    --cc=sebastian.riemer-EIkl63zCoXaH+58JC4qpiA@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 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).