public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Steve Wise" <swise@opengridcomputing.com>
To: "'Sagi Grimberg'" <sagig@dev.mellanox.co.il>,
	"'Christoph Hellwig'" <hch@lst.de>, <linux-rdma@vger.kernel.org>
Cc: <bart.vanassche@sandisk.com>, <axboe@fb.com>,
	<linux-scsi@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH 3/9] IB: add a helper to safely drain a QP
Date: Mon, 16 Nov 2015 12:30:52 -0600	[thread overview]
Message-ID: <003001d1209c$ecb70760$c6251620$@opengridcomputing.com> (raw)
In-Reply-To: <564A067B.8030504@opengridcomputing.com>



> -----Original Message-----
> From: Steve Wise [mailto:swise@opengridcomputing.com]
> Sent: Monday, November 16, 2015 10:38 AM
> To: Sagi Grimberg; Christoph Hellwig; linux-rdma@vger.kernel.org
> Cc: bart.vanassche@sandisk.com; axboe@fb.com; linux-scsi@vger.kernel.org; linux-kernel@vger.kernel.org
> Subject: Re: [PATCH 3/9] IB: add a helper to safely drain a QP
> 
> On 11/15/2015 3:34 AM, Sagi Grimberg wrote:
> >
> >> +
> >> +struct ib_stop_cqe {
> >> +    struct ib_cqe    cqe;
> >> +    struct completion done;
> >> +};
> >> +
> >> +static void ib_stop_done(struct ib_cq *cq, struct ib_wc *wc)
> >> +{
> >> +    struct ib_stop_cqe *stop =
> >> +        container_of(wc->wr_cqe, struct ib_stop_cqe, cqe);
> >> +
> >> +    complete(&stop->done);
> >> +}
> >> +
> >> +/*
> >> + * Change a queue pair into the error state and wait until all receive
> >> + * completions have been processed before destroying it. This avoids
> >> that
> >> + * the receive completion handler can access the queue pair while it is
> >> + * being destroyed.
> >> + */
> >> +void ib_drain_qp(struct ib_qp *qp)
> >> +{
> >> +    struct ib_qp_attr attr = { .qp_state = IB_QPS_ERR };
> >> +    struct ib_stop_cqe stop = { };
> >> +    struct ib_recv_wr wr, *bad_wr;
> >> +    int ret;
> >> +
> >> +    wr.wr_cqe = &stop.cqe;
> >> +    stop.cqe.done = ib_stop_done;
> >> +    init_completion(&stop.done);
> >> +
> >> +    ret = ib_modify_qp(qp, &attr, IB_QP_STATE);
> >> +    if (ret) {
> >> +        WARN_ONCE(ret, "failed to drain QP: %d\n", ret);
> >> +        return;
> >> +    }
> >> +
> >> +    ret = ib_post_recv(qp, &wr, &bad_wr);
> >> +    if (ret) {
> >> +        WARN_ONCE(ret, "failed to drain QP: %d\n", ret);
> >> +        return;
> >> +    }
> >> +
> >> +    wait_for_completion(&stop.done);
> >> +}
> >
> > This is taken from srp, and srp drains using a recv wr due to a race
> > causing a use-after-free condition in srp which re-posts a recv buffer
> > in the recv completion handler. srp does not really care if there are
> > pending send flushes.
> >
> > I'm not sure if there are ordering rules for send/recv queues in
> > terms of flush completions, meaning that even if all recv flushes
> > were consumed maybe there are send flushes still pending.
> >
> > I think that for a general drain helper it would be useful to
> > make sure that both the recv _and_ send flushes were drained.
> >
> > So, something like:
> >
> > void ib_drain_qp(struct ib_qp *qp)
> > {
> >     struct ib_qp_attr attr = { .qp_state = IB_QPS_ERR };
> >     struct ib_stop_cqe rstop, sstop;
> >     struct ib_recv_wr rwr = {}, *bad_rwr;
> >     struct ib_send_wr swr = {}, *bad_swr;
> >     int ret;
> >
> >     rwr.wr_cqe = &rstop.cqe;
> >     rstop.cqe.done = ib_stop_done;
> >     init_completion(&rstop.done);
> >
> >     swr.wr_cqe = &sstop.cqe;
> >     sstop.cqe.done = ib_stop_done;
> >     init_completion(&sstop.done);
> >
> >     ret = ib_modify_qp(qp, &attr, IB_QP_STATE);
> >     if (ret) {
> >         WARN_ONCE(ret, "failed to drain QP: %d\n", ret);
> >         return;
> >     }
> >
> >     ret = ib_post_recv(qp, &rwr, &bad_rwr);
> >     if (ret) {
> >         WARN_ONCE(ret, "failed to drain recv queue: %d\n", ret);
> >         return;
> >     }
> >
> >     ret = ib_post_send(qp, &swr, &bad_swr);
> >     if (ret) {
> >         WARN_ONCE(ret, "failed to drain send queue: %d\n", ret);
> >         return;
> >     }
> >
> >     wait_for_completion(&rstop.done);
> >     wait_for_completion(&sstop.done);
> > }
> >
> > Thoughts?
> 
> This won't work for iWARP as per my previous email.  But I will code
> something up that will.
> 
> Steve

After looking at the nes driver, I don't see any common way to support drain w/o some serious driver mods.  Since SRP is the only
user, perhaps we can ignore iWARP for this function...


  reply	other threads:[~2015-11-16 18:30 UTC|newest]

Thread overview: 86+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-13 13:46 add a proper completion queue abstraction Christoph Hellwig
2015-11-13 13:46 ` [PATCH 1/9] move blk_iopoll to limit and make it generally available Christoph Hellwig
2015-11-13 15:23   ` Or Gerlitz
2015-11-14  7:02     ` Christoph Hellwig
2015-11-15  8:48       ` Sagi Grimberg
2015-11-15  9:04         ` Or Gerlitz
2015-11-15 13:16           ` Sagi Grimberg
2015-11-15 12:51         ` Christoph Hellwig
2015-11-13 19:19   ` Bart Van Assche
2015-11-14  7:02     ` Christoph Hellwig
2015-11-17 17:16       ` Bart Van Assche
2015-11-17 17:27         ` Bart Van Assche
2015-11-18 13:58         ` Christoph Hellwig
2015-11-13 13:46 ` [PATCH 2/9] IB: add a proper completion queue abstraction Christoph Hellwig
2015-11-13 18:25   ` Jason Gunthorpe
2015-11-13 19:57     ` Bart Van Assche
2015-11-13 22:06       ` Jason Gunthorpe
2015-11-14  7:13         ` Christoph Hellwig
2015-11-23 20:37           ` Jason Gunthorpe
2015-11-23 21:04             ` Bart Van Assche
2015-11-23 21:28               ` Jason Gunthorpe
2015-11-23 21:54                 ` Bart Van Assche
2015-11-23 22:18                   ` Jason Gunthorpe
2015-11-23 22:33                     ` Bart Van Assche
2015-11-23 23:06                       ` Jason Gunthorpe
     [not found]                         ` <B24F4DDE-709A-4D2D-8B26-4E83325DBB1A@asomi.com>
2015-11-24  0:00                           ` Jason Gunthorpe
2015-11-24  0:34                             ` Tom Talpey
2015-11-24  0:40                               ` Jason Gunthorpe
2015-11-24  2:35                             ` Caitlin Bestler
2015-11-24  7:03                               ` Jason Gunthorpe
2015-11-24 12:52                                 ` Tom Talpey
2015-11-14  7:08     ` Christoph Hellwig
2015-11-23 20:01       ` Jason Gunthorpe
2015-11-23 20:57         ` Christoph Hellwig
2015-11-15  9:40   ` Sagi Grimberg
2015-11-15 12:55     ` Christoph Hellwig
2015-11-15 13:21       ` Sagi Grimberg
2015-11-17 17:52   ` Bart Van Assche
2015-11-18  7:55     ` Sagi Grimberg
2015-11-18 18:20       ` Bart Van Assche
2015-11-20 10:16         ` Christoph Hellwig
2015-11-20 16:50           ` Bart Van Assche
2015-11-22  9:51             ` Sagi Grimberg
2015-11-22 10:13               ` Christoph Hellwig
2015-11-22 10:36                 ` Sagi Grimberg
2015-11-22 13:23                   ` Christoph Hellwig
2015-11-22 14:57                     ` Sagi Grimberg
2015-11-22 16:55                       ` Bart Van Assche
2015-11-18 14:00     ` Christoph Hellwig
2015-11-13 13:46 ` [PATCH 3/9] IB: add a helper to safely drain a QP Christoph Hellwig
2015-11-13 16:16   ` Steve Wise
2015-11-14  7:05     ` Christoph Hellwig
2015-11-15  9:34   ` Sagi Grimberg
2015-11-16 16:38     ` Steve Wise
2015-11-16 18:30       ` Steve Wise [this message]
2015-11-16 18:37         ` Sagi Grimberg
2015-11-16 19:03           ` Steve Wise
2015-11-17  8:54             ` Sagi Grimberg
2015-11-23 10:28             ` Sagi Grimberg
2015-11-23 10:35               ` Sagi Grimberg
2015-11-23 14:33                 ` 'Christoph Hellwig'
2015-11-23 14:48                 ` Steve Wise
2015-11-23 14:44               ` Steve Wise
2015-11-17 17:06     ` Bart Van Assche
2015-11-18  7:59       ` Sagi Grimberg
2015-11-18 11:32   ` Sagi Grimberg
2015-11-18 14:06     ` Christoph Hellwig
2015-11-18 15:21       ` Steve Wise
2015-11-13 13:46 ` [PATCH 4/9] srpt: chain RDMA READ/WRITE requests Christoph Hellwig
2015-11-18  1:17   ` Bart Van Assche
2015-11-18  9:15     ` Sagi Grimberg
2015-11-18 16:32       ` Bart Van Assche
2015-11-20 10:20         ` Christoph Hellwig
2015-11-18 14:06     ` Christoph Hellwig
2015-11-13 13:46 ` [PATCH 5/9] srpt: use the new CQ API Christoph Hellwig
2015-11-17 18:22   ` Bart Van Assche
2015-11-17 19:38   ` Bart Van Assche
2015-11-18 14:03     ` Christoph Hellwig
2015-11-13 13:46 ` [PATCH 6/9] srp: " Christoph Hellwig
2015-11-17 19:56   ` Bart Van Assche
2015-11-18 14:03     ` Christoph Hellwig
2015-11-13 13:46 ` [PATCH 7/9] IB/iser: Use a dedicated descriptor for login Christoph Hellwig
2015-11-15  9:14   ` Or Gerlitz
2015-11-13 13:46 ` [PATCH 8/9] IB/iser: Use helper for container_of Christoph Hellwig
2015-11-13 13:46 ` [PATCH 9/9] IB/iser: Convert to CQ abstraction Christoph Hellwig
2015-11-15  9:21   ` Or Gerlitz

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='003001d1209c$ecb70760$c6251620$@opengridcomputing.com' \
    --to=swise@opengridcomputing.com \
    --cc=axboe@fb.com \
    --cc=bart.vanassche@sandisk.com \
    --cc=hch@lst.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=sagig@dev.mellanox.co.il \
    /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