Skip to contentSkip to conversation

RDMA/erdma: Introduce custom implementation of drain_sq and drain_rq

PATCH Superseded Cheng Xu 5 participants 18 messages Aug 24, 2022 – Aug 31, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Cheng Xu

author maintainer
#0 lore raw

cover RDMA/erdma: Introduce custom implementation of drain_sq and drain_rq

Hi,

This series introduces erdma's implementation of drain_sq and drain_rq. Our hardware will stop processing any new WRs if QP state is error. So the default __ib_drain_sq and __ib_drain_rq in core code can not work for erdma. For this reason, we implement the drain_sq and drain_rq interfaces.

In SQ draining or RQ draining, we post both drain send wr and drain recv wr, and then modify_qp to error. At last, we wait the corresponding completion in the separated interface.

The first patch introduces internal post_send/post_recv for qp drain, and the second patch implements the drain_sq and drain_rq of erdma.

Thanks,
Cheng Xu

Cheng Xu (2):
RDMA/erdma: Introduce internal post_send/post_recv for qp drain RDMA/erdma: Add drain_sq and drain_rq support

 drivers/infiniband/hw/erdma/erdma_main.c  |   4 +-
 drivers/infiniband/hw/erdma/erdma_qp.c    | 116 +++++++++++++++++++++-
 drivers/infiniband/hw/erdma/erdma_verbs.h |  27 ++++-
 3 files changed, 136 insertions(+), 11 deletions(-)
Signature · 1 line
2.27.0
author maintainer
#1 lore raw

PATCH 1/2 RDMA/erdma: Introduce internal post_send/post_recv for qp drain

For erdma, hardware won't process newly posted send WRs or recv WRs after QP state changed to error, and no flush cqes will generated for them. So, internal post_send and post_recv functions are introduced to prevent the new send WRs or recv WRs.

---
 drivers/infiniband/hw/erdma/erdma_main.c  |  4 +-
 drivers/infiniband/hw/erdma/erdma_qp.c    | 45 ++++++++++++++++++++---
 drivers/infiniband/hw/erdma/erdma_verbs.h | 17 +++++++--
 3 files changed, 55 insertions(+), 11 deletions(-)
drivers/infiniband/hw/erdma/erdma_main.c +2 -2
index 07e743d24847..4921ebc1286d 100644
@@ -460,8 +460,8 @@ static const struct ib_device_ops erdma_device_ops = {
 	.mmap = erdma_mmap,
 	.mmap_free = erdma_mmap_free,
 	.modify_qp = erdma_modify_qp,
-	.post_recv = erdma_post_recv,
-	.post_send = erdma_post_send,
+	.post_recv = erdma_post_recv_nodrain,
+	.post_send = erdma_post_send_nodrain,
 	.poll_cq = erdma_poll_cq,
 	.query_device = erdma_query_device,
 	.query_gid = erdma_query_gid,
drivers/infiniband/hw/erdma/erdma_qp.c +40 -5

85 lines not on this page · raw message

drivers/infiniband/hw/erdma/erdma_verbs.h +13 -4
index c7baddb1f292..f4148fbac878 100644
@@ -195,6 +195,12 @@ struct erdma_qp_attrs {
 	u8 pd_len;
 };
 
+enum erdma_qp_flags {
+	ERDMA_QP_FLAGS_DRAIN_ISSUED = (1 << 0),
+	ERDMA_QP_FLAGS_TX_STOPPED = (1 << 1),
+	ERDMA_QP_FLAGS_RX_STOPPED = (1 << 2),
+};
+
 struct erdma_qp {
 	struct ib_qp ibqp;
 	struct kref ref;
@@ -202,6 +208,7 @@ struct erdma_qp {
 	struct erdma_dev *dev;
 	struct erdma_cep *cep;
 	struct rw_semaphore state_lock;
+	unsigned long flags;
 
 	union {
 		struct erdma_kqp kern_qp;
@@ -328,10 +335,12 @@ void erdma_mmap_free(struct rdma_user_mmap_entry *rdma_entry);
 void erdma_qp_get_ref(struct ib_qp *ibqp);
 void erdma_qp_put_ref(struct ib_qp *ibqp);
 struct ib_qp *erdma_get_ibqp(struct ib_device *dev, int id);
-int erdma_post_send(struct ib_qp *ibqp, const struct ib_send_wr *send_wr,
-		    const struct ib_send_wr **bad_send_wr);
-int erdma_post_recv(struct ib_qp *ibqp, const struct ib_recv_wr *recv_wr,
-		    const struct ib_recv_wr **bad_recv_wr);
+int erdma_post_send_nodrain(struct ib_qp *ibqp,
+			    const struct ib_send_wr *send_wr,
+			    const struct ib_send_wr **bad_send_wr);
+int erdma_post_recv_nodrain(struct ib_qp *ibqp,
+			    const struct ib_recv_wr *recv_wr,
+			    const struct ib_recv_wr **bad_recv_wr);
 int erdma_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc);
 struct ib_mr *erdma_ib_alloc_mr(struct ib_pd *ibpd, enum ib_mr_type mr_type,
 				u32 max_num_sg);
Signature · 1 line
2.27.0
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH for-next 1/2] RDMA/erdma: Introduce internal post_send/post_recv for qp drain

Quoted 5 lines · Cheng Xu

For erdma, hardware won't process newly posted send WRs or recv WRs after QP state changed to error, and no flush cqes will generated for them. So, internal post_send and post_recv functions are introduced to prevent the new send WRs or recv WRs.

Quoted 7 lines
---
 drivers/infiniband/hw/erdma/erdma_main.c  |  4 +-
 drivers/infiniband/hw/erdma/erdma_qp.c    | 45 ++++++++++++++++++++---
 drivers/infiniband/hw/erdma/erdma_verbs.h | 17 +++++++--
 3 files changed, 55 insertions(+), 11 deletions(-)

Thanks,

author maintainer
#3 lore raw

PATCH 2/2 RDMA/erdma: Add drain_sq and drain_rq support

In reply to Cheng Xu

For erdma, hardware won't process any WRs after modifying QP state to error, so the default __ib_drain_sq and __ib_drain_rq can not work for erdma device. Here, we introduce custom implementation of drain_sq and drain_rq interface to fit erdma hardware.

---
 drivers/infiniband/hw/erdma/erdma_qp.c    | 71 +++++++++++++++++++++++
 drivers/infiniband/hw/erdma/erdma_verbs.h | 10 ++++
 2 files changed, 81 insertions(+)
drivers/infiniband/hw/erdma/erdma_qp.c +71 -0
index abf8b134d076..57fdb946fbfd 100644
@@ -599,3 +599,74 @@ int erdma_post_recv_nodrain(struct ib_qp *ibqp,
 {
 	return erdma_post_recv(ibqp, recv_wr, bad_recv_wr, false);
 }
+
+static void erdma_drain_qp_done(struct ib_cq *cq, struct ib_wc *wc)
+{
+	struct erdma_drain_cqe *cqe =
+		container_of(wc->wr_cqe, struct erdma_drain_cqe, cqe);
+
+	complete(&cqe->done);
+}
+
+static void erdma_drain_qp_common(struct ib_qp *ibqp, struct completion *comp,
+				  struct ib_cq *ibcq)
+{
+	struct ib_qp_attr attr = { .qp_state = IB_QPS_ERR };
+	struct erdma_qp *qp = to_eqp(ibqp);
+	const struct ib_send_wr *bad_swr;
+	const struct ib_recv_wr *bad_rwr;
+	struct ib_rdma_wr swr = {
+		.wr = {
+			.next = NULL,
+			{ .wr_cqe   = &qp->kern_qp.sdrain.cqe, },
+			.opcode = IB_WR_RDMA_WRITE,
+			.send_flags = IB_SEND_SIGNALED,
+		},
+	};
+	struct ib_recv_wr rwr = {
+		.next = NULL,
+		.wr_cqe = &qp->kern_qp.rdrain.cqe,
+		.num_sge = 0,
+	};
+
+	if (qp->flags & ERDMA_QP_FLAGS_DRAIN_ISSUED)
+		goto wait_for_completion;
+
+	qp->flags |= ERDMA_QP_FLAGS_DRAIN_ISSUED;
+
+	qp->kern_qp.rdrain.cqe.done = erdma_drain_qp_done;
+	init_completion(&qp->kern_qp.rdrain.done);
+
+	qp->kern_qp.sdrain.cqe.done = erdma_drain_qp_done;
+	init_completion(&qp->kern_qp.sdrain.done);
+
+	if (erdma_post_recv(ibqp, &rwr, &bad_rwr, true))
+		return;
+
+	if (erdma_post_send(ibqp, &swr.wr, &bad_swr, true))
+		return;
+
+	if (ib_modify_qp(ibqp, &attr, IB_QP_STATE))
+		return;
+
+wait_for_completion:
+	if (ibcq->poll_ctx == IB_POLL_DIRECT)
+		while (wait_for_completion_timeout(comp, HZ / 10) <= 0)
+			ib_process_cq_direct(ibcq, -1);
+	else
+		wait_for_completion(comp);
+}
+
+void erdma_drain_sq(struct ib_qp *ibqp)
+{
+	struct erdma_qp *qp = to_eqp(ibqp);
+
+	erdma_drain_qp_common(ibqp, &qp->kern_qp.sdrain.done, ibqp->send_cq);
+}
+
+void erdma_drain_rq(struct ib_qp *ibqp)
+{
+	struct erdma_qp *qp = to_eqp(ibqp);
+
+	erdma_drain_qp_common(ibqp, &qp->kern_qp.rdrain.done, ibqp->recv_cq);
+}
drivers/infiniband/hw/erdma/erdma_verbs.h +10 -0
index f4148fbac878..4cec92c8a737 100644
@@ -133,6 +133,11 @@ struct erdma_uqp {
 	u32 rq_offset;
 };
 
+struct erdma_drain_cqe {
+	struct ib_cqe cqe;
+	struct completion done;
+};
+
 struct erdma_kqp {
 	u16 sq_pi;
 	u16 sq_ci;
@@ -155,6 +160,9 @@ struct erdma_kqp {
 	void *sq_db_info;
 	void *rq_db_info;
 
+	struct erdma_drain_cqe sdrain;
+	struct erdma_drain_cqe rdrain;
+
 	u8 sig_all;
 };
 
@@ -341,6 +349,8 @@ int erdma_post_send_nodrain(struct ib_qp *ibqp,
 int erdma_post_recv_nodrain(struct ib_qp *ibqp,
 			    const struct ib_recv_wr *recv_wr,
 			    const struct ib_recv_wr **bad_recv_wr);
+void erdma_drain_sq(struct ib_qp *ibqp);
+void erdma_drain_rq(struct ib_qp *ibqp);
 int erdma_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc);
 struct ib_mr *erdma_ib_alloc_mr(struct ib_pd *ibpd, enum ib_mr_type mr_type,
 				u32 max_num_sg);
Signature · 1 line
2.27.0
Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH for-next 2/2] RDMA/erdma: Add drain_sq and drain_rq support

Quoted 11 lines · Cheng Xu

For erdma, hardware won't process any WRs after modifying QP state to error, so the default __ib_drain_sq and __ib_drain_rq can not work for erdma device. Here, we introduce custom implementation of drain_sq and drain_rq interface to fit erdma hardware.

---
 drivers/infiniband/hw/erdma/erdma_qp.c    | 71 +++++++++++++++++++++++
 drivers/infiniband/hw/erdma/erdma_verbs.h | 10 ++++
 2 files changed, 81 insertions(+)

Thanks,

author maintainer
#5 lore raw

Re: [PATCH for-next 2/2] RDMA/erdma: Add drain_sq and drain_rq support

In reply to Cheng Xu
Quoted 117 lines · Cheng Xu

For erdma, hardware won't process any WRs after modifying QP state to error, so the default __ib_drain_sq and __ib_drain_rq can not work for erdma device. Here, we introduce custom implementation of drain_sq and drain_rq interface to fit erdma hardware.

---
 drivers/infiniband/hw/erdma/erdma_qp.c    | 71 +++++++++++++++++++++++
 drivers/infiniband/hw/erdma/erdma_verbs.h | 10 ++++
 2 files changed, 81 insertions(+)
drivers/infiniband/hw/erdma/erdma_qp.c +71 -0
index abf8b134d076..57fdb946fbfd 100644
@@ -599,3 +599,74 @@ int erdma_post_recv_nodrain(struct ib_qp *ibqp,
 {
 	return erdma_post_recv(ibqp, recv_wr, bad_recv_wr, false);
 }
+
+static void erdma_drain_qp_done(struct ib_cq *cq, struct ib_wc *wc)
+{
+	struct erdma_drain_cqe *cqe =
+		container_of(wc->wr_cqe, struct erdma_drain_cqe, cqe);
+
+	complete(&cqe->done);
+}
+
+static void erdma_drain_qp_common(struct ib_qp *ibqp, struct completion *comp,
+				  struct ib_cq *ibcq)
+{
+	struct ib_qp_attr attr = { .qp_state = IB_QPS_ERR };
+	struct erdma_qp *qp = to_eqp(ibqp);
+	const struct ib_send_wr *bad_swr;
+	const struct ib_recv_wr *bad_rwr;
+	struct ib_rdma_wr swr = {
+		.wr = {
+			.next = NULL,
+			{ .wr_cqe   = &qp->kern_qp.sdrain.cqe, },
+			.opcode = IB_WR_RDMA_WRITE,
+			.send_flags = IB_SEND_SIGNALED,
+		},
+	};
+	struct ib_recv_wr rwr = {
+		.next = NULL,
+		.wr_cqe = &qp->kern_qp.rdrain.cqe,
+		.num_sge = 0,
+	};
+
+	if (qp->flags & ERDMA_QP_FLAGS_DRAIN_ISSUED)
+		goto wait_for_completion;
+
+	qp->flags |= ERDMA_QP_FLAGS_DRAIN_ISSUED;
+
+	qp->kern_qp.rdrain.cqe.done = erdma_drain_qp_done;
+	init_completion(&qp->kern_qp.rdrain.done);
+
+	qp->kern_qp.sdrain.cqe.done = erdma_drain_qp_done;
+	init_completion(&qp->kern_qp.sdrain.done);
+
+	if (erdma_post_recv(ibqp, &rwr, &bad_rwr, true))
+		return;
+
+	if (erdma_post_send(ibqp, &swr.wr, &bad_swr, true))
+		return;
+
+	if (ib_modify_qp(ibqp, &attr, IB_QP_STATE))
+		return;
+
+wait_for_completion:
+	if (ibcq->poll_ctx == IB_POLL_DIRECT)
+		while (wait_for_completion_timeout(comp, HZ / 10) <= 0)
+			ib_process_cq_direct(ibcq, -1);
+	else
+		wait_for_completion(comp);
+}
+
+void erdma_drain_sq(struct ib_qp *ibqp)
+{
+	struct erdma_qp *qp = to_eqp(ibqp);
+
+	erdma_drain_qp_common(ibqp, &qp->kern_qp.sdrain.done, ibqp->send_cq);
+}
+
+void erdma_drain_rq(struct ib_qp *ibqp)
+{
+	struct erdma_qp *qp = to_eqp(ibqp);
+
+	erdma_drain_qp_common(ibqp, &qp->kern_qp.rdrain.done, ibqp->recv_cq);
+}
drivers/infiniband/hw/erdma/erdma_verbs.h +8 -0
index f4148fbac878..4cec92c8a737 100644
@@ -133,6 +133,11 @@ struct erdma_uqp {
 	u32 rq_offset;
 };
 
+struct erdma_drain_cqe {
+	struct ib_cqe cqe;
+	struct completion done;
+};
+
 struct erdma_kqp {
 	u16 sq_pi;
 	u16 sq_ci;
@@ -155,6 +160,9 @@ struct erdma_kqp {
 	void *sq_db_info;
 	void *rq_db_info;
 
+	struct erdma_drain_cqe sdrain;
+	struct erdma_drain_cqe rdrain;
+
 	u8 sig_all;
 };
 

drivers/infiniband/hw/erdma/erdma_verbs.h int erdma_post_send_nodrain(struct ib_qp *ibqp, · line 356

Quoted 8 lines
drivers/infiniband/hw/erdma/erdma_verbs.h +2 -0
@@ -341,6 +349,8 @@ int erdma_post_send_nodrain(struct ib_qp *ibqp,
 int erdma_post_recv_nodrain(struct ib_qp *ibqp,
 			    const struct ib_recv_wr *recv_wr,
 			    const struct ib_recv_wr **bad_recv_wr);
+void erdma_drain_sq(struct ib_qp *ibqp);
+void erdma_drain_rq(struct ib_qp *ibqp);
 int erdma_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc);
 struct ib_mr *erdma_ib_alloc_mr(struct ib_pd *ibpd, enum ib_mr_type mr_type,
 				u32 max_num_sg);

I'm sorry that I forgot to involved the corresponding assignment of struct ib_device_ops into this patch. I will send v2 to fix this.

drivers/infiniband/hw/erdma/erdma_main.c +2 -0
index 4921ebc1286d..e4ce77607f10 100644
@@ -446,6 +446,8 @@ static const struct ib_device_ops erdma_device_ops = {
        .dereg_mr = erdma_dereg_mr,
        .destroy_cq = erdma_destroy_cq,
        .destroy_qp = erdma_destroy_qp,
+       .drain_rq = erdma_drain_rq,
+       .drain_sq = erdma_drain_sq,
        .get_dma_mr = erdma_get_dma_mr,
        .get_port_immutable = erdma_get_port_immutable,
        .iw_accept = erdma_accept,
#6 lore raw
In reply to Cheng Xu
Quoted 4 lines · Cheng Xu

Hi,

This series introduces erdma's implementation of drain_sq and drain_rq. Our hardware will stop processing any new WRs if QP state is error.

Doesn't this violate the IB specification? Failing newly posted WRs before older WRs have flushed to the CQ means that ordering is not preserved. Many upper layers depend on this.

Tom.

Quoted 23 lines

So the default __ib_drain_sq and __ib_drain_rq in core code can not work for erdma. For this reason, we implement the drain_sq and drain_rq interfaces.

In SQ draining or RQ draining, we post both drain send wr and drain recv wr, and then modify_qp to error. At last, we wait the corresponding completion in the separated interface.

The first patch introduces internal post_send/post_recv for qp drain, and the second patch implements the drain_sq and drain_rq of erdma.

Thanks,
Cheng Xu

Cheng Xu (2):
RDMA/erdma: Introduce internal post_send/post_recv for qp drain RDMA/erdma: Add drain_sq and drain_rq support

  drivers/infiniband/hw/erdma/erdma_main.c  |   4 +-
  drivers/infiniband/hw/erdma/erdma_qp.c    | 116 +++++++++++++++++++++-
  drivers/infiniband/hw/erdma/erdma_verbs.h |  27 ++++-
  3 files changed, 136 insertions(+), 11 deletions(-)
#7 lore raw
Quoted 11 lines

-----Original Message-----
From: Tom Talpey <[email protected]>
Sent: Wednesday, 24 August 2022 16:09
To: Cheng Xu <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; [email protected]
Subject: [EXTERNAL] Re: [PATCH for-next 0/2] RDMA/erdma: Introduce custom implementation of drain_sq and drain_rq

Quoted 2 lines · Cheng Xu

Hi,

Quoted 8 lines
Quoted 1 line

This series introduces erdma's implementation of drain_sq and

drain_rq.

Quoted 1 line

Our hardware will stop processing any new WRs if QP state is error.

Doesn't this violate the IB specification? Failing newly posted WRs before older WRs have flushed to the CQ means that ordering is not preserved. Many upper layers depend on this.

It would be ok to synchronously fail the post_send()/post_recv() call if the QP is in error, or the WR is malformed. In that case, the WR does not translate into a WQE and will not produce a work completion.

Bernard.

Quoted 29 lines

Tom.

Quoted 1 line

So the default __ib_drain_sq and __ib_drain_rq in core code can not

work

Quoted 5 lines

for erdma. For this reason, we implement the drain_sq and drain_rq interfaces.

In SQ draining or RQ draining, we post both drain send wr and drain recv wr, and then modify_qp to error. At last, we wait the

corresponding

Quoted 3 lines

completion in the separated interface.

The first patch introduces internal post_send/post_recv for qp drain,

and

Quoted 11 lines

the second patch implements the drain_sq and drain_rq of erdma.

Thanks,
Cheng Xu

Cheng Xu (2):
RDMA/erdma: Introduce internal post_send/post_recv for qp drain RDMA/erdma: Add drain_sq and drain_rq support

  drivers/infiniband/hw/erdma/erdma_main.c  |   4 +-
  drivers/infiniband/hw/erdma/erdma_qp.c    | 116

+++++++++++++++++++++-

Quoted 3 lines
  drivers/infiniband/hw/erdma/erdma_verbs.h |  27 ++++-
  3 files changed, 136 insertions(+), 11 deletions(-)
author maintainer
#8 lore raw
In reply to Tom Talpey
Quoted 9 lines · Tom Talpey
Quoted 4 lines · Cheng Xu

Hi,

This series introduces erdma's implementation of drain_sq and drain_rq. Our hardware will stop processing any new WRs if QP state is error.

Doesn't this violate the IB specification? Failing newly posted WRs before older WRs have flushed to the CQ means that ordering is not preserved.

I agree with Bernard's point.

I'm not very familiar with with IB specification. But for RNIC/iWarp [1], post WR in Error state has two optional actions: "Post WQE, and then Flush it" or "Return an Immediate Error" (Showed in Figure 10). So, I think failing newly posted WRs is reasonable.

Quoted 1 line

Many upper layers depend on this.

For kernel verbs, erdma currently supports NoF. we tested the NoF cases, and found that it's never happened that newly WRs were posted after QP changed to error, and the drain_qp should be the terminal of IO process.

Also, in userspace, I find that many providers prevents new WRs if QP state is not right.

So, it seems ok in practice.

Thanks,
Cheng Xu

[1] http://www.rdmaconsortium.org/home/draft-hilland-iwarp-verbs-v1.0-RDMAC.pdf

#9 lore raw
Quoted 13 lines · Cheng Xu
Quoted 9 lines · Tom Talpey
Quoted 4 lines · Cheng Xu

Hi,

This series introduces erdma's implementation of drain_sq and drain_rq. Our hardware will stop processing any new WRs if QP state is error.

Doesn't this violate the IB specification? Failing newly posted WRs before older WRs have flushed to the CQ means that ordering is not preserved.

Quoted 6 lines

I agree with Bernard's point.

I'm not very familiar with with IB specification. But for RNIC/iWarp [1], post WR in Error state has two optional actions: "Post WQE, and then Flush it" or "Return an Immediate Error" (Showed in Figure 10). So, I think failing newly posted WRs is reasonable.

Both IB and iWARP allow new post-WR calls to fail synchronously if the QP is in the ERROR state. But the QP can only enter ERROR once the SQ and RQ are fully drained to the CQ(s). Until that happens, the WRs need to flush through.

Your code seems to start failing WR's when the TX_STOPPED or RX_STOPPED bits are set. But that bit is being set when the drain *begins*, not when it flushes through. That seems wrong, to me.

Quoted 8 lines
Quoted 1 line

Many upper layers depend on this.

For kernel verbs, erdma currently supports NoF. we tested the NoF cases, and found that it's never happened that newly WRs were posted after QP changed to error, and the drain_qp should be the terminal of IO process.

Also, in userspace, I find that many providers prevents new WRs if QP state is not right.

Sure, but your new STOPPED bits don't propagate up to userspace, right? The post calls will fail unexpectedly, because the QP is not yet in ERROR state.

I'm also concerned how consumers who are posting their own "drain" WQEs will behave. This is a common approach that many already take. But now they will see different behavior when posting them...

Tom.

Quoted 10 lines

So, it seems ok in practice.

Thanks,
Cheng Xu

[1] http://www.rdmaconsortium.org/home/draft-hilland-iwarp-verbs-v1.0-RDMAC.pdf

author maintainer
#10 lore raw
Quoted 16 lines · Tom Talpey
Quoted 15 lines · Cheng Xu
Quoted 9 lines · Tom Talpey
Quoted 4 lines · Cheng Xu

Hi,

This series introduces erdma's implementation of drain_sq and drain_rq. Our hardware will stop processing any new WRs if QP state is error.

Doesn't this violate the IB specification? Failing newly posted WRs before older WRs have flushed to the CQ means that ordering is not preserved.

I agree with Bernard's point.

Quoted 9 lines
Quoted 4 lines

I'm not very familiar with with IB specification. But for RNIC/iWarp [1], post WR in Error state has two optional actions: "Post WQE, and then Flush it" or "Return an Immediate Error" (Showed in Figure 10). So, I think failing newly posted WRs is reasonable.

<...> But the QP can only enter ERROR once the
SQ and RQ are fully drained to the CQ(s). Until that happens, the WRs need to flush through.

Emm, let's put erdma aside first, it seems that specification does not require this. According to "6.2.4 Error State" in the document [1]:

The following is done on entry into the Error state:
* The RI MUST flush any incomplete WRs on the SQ or RQ.
.....
* At some point in the execution of the flushing operation, the RI MUST begin to return an Immediate Error for any attempt to post a WR to a Work Queue;
....

As the second point says, The flushing operation and the behavior of returning Immediate Error are asynchronous. what you mentioned is not guaranteed. Failing the post_send/post_recv may happens at any time during modify_qp to error.

[1] http://www.rdmaconsortium.org/home/draft-hilland-iwarp-verbs-v1.0-RDMAC.pdf

Quoted 4 lines

Your code seems to start failing WR's when the TX_STOPPED or RX_STOPPED bits are set. But that bit is being set when the drain *begins*, not when it flushes through. That seems wrong, to me.

Back to erdma's scenario, As I explains above, I think failing immediately when flushing begins does not violate the specification.

Quoted 10 lines
Quoted 8 lines
Quoted 1 line

Many upper layers depend on this.

For kernel verbs, erdma currently supports NoF. we tested the NoF cases, and found that it's never happened that newly WRs were posted after QP changed to error, and the drain_qp should be the terminal of IO process.

Also, in userspace, I find that many providers prevents new WRs if QP state is not right.

Sure, but your new STOPPED bits don't propagate up to userspace, right?

Yes. they are only used for kernel QPs. The bits are used for setting an accurate time point to prevent newly WRs when modify qp to error.

Quoted 2 lines

The post calls will fail unexpectedly, because the QP is not yet in ERROR state.

Do you mean this happens in userspace or kernel? The new bits do not influence userspace, and erdma will have the same behavior with other providers in userspace.

For kernel, this is only used in drain_qp scenario. posting WRs and drain qp concurrently will lead uncertain results. This is also mentioned in the comment of ib_drain_qp:

* ensure that there are no other contexts that are posting WRs concurrently.
* Otherwise the drain is not guaranteed.

Quoted 4 lines

I'm also concerned how consumers who are posting their own "drain" WQEs will behave. This is a common approach that many already take. But now they will see different behavior when posting them...

For userspace, erdma is not special.
For kernel, I think the standard way to drain WR is using ib_drain_qp, not custom implementation. I'm not sure that there is some ULPs in kernel has their own drain flow.

Thanks,
Cheng Xu

Quoted 13 lines

Tom.

Quoted 10 lines

So, it seems ok in practice.

Thanks,
Cheng Xu

[1] http://www.rdmaconsortium.org/home/draft-hilland-iwarp-verbs-v1.0-RDMAC.pdf

#11 lore raw
Quoted 38 lines · Cheng Xu
Quoted 16 lines · Tom Talpey
Quoted 15 lines · Cheng Xu
Quoted 9 lines · Tom Talpey
Quoted 4 lines · Cheng Xu

Hi,

This series introduces erdma's implementation of drain_sq and drain_rq. Our hardware will stop processing any new WRs if QP state is error.

Doesn't this violate the IB specification? Failing newly posted WRs before older WRs have flushed to the CQ means that ordering is not preserved.

I agree with Bernard's point.

Quoted 9 lines
Quoted 4 lines

I'm not very familiar with with IB specification. But for RNIC/iWarp [1], post WR in Error state has two optional actions: "Post WQE, and then Flush it" or "Return an Immediate Error" (Showed in Figure 10). So, I think failing newly posted WRs is reasonable.

<...> But the QP can only enter ERROR once the
SQ and RQ are fully drained to the CQ(s). Until that happens, the WRs need to flush through.

Emm, let's put erdma aside first, it seems that specification does not require this. According to "6.2.4 Error State" in the document [1]:

The following is done on entry into the Error state:
* The RI MUST flush any incomplete WRs on the SQ or RQ.

    .....
  * At some point in the execution of the flushing operation, the RI
    MUST begin to return an Immediate Error for any attempt to post
    a WR to a Work Queue;
    ....
Quoted 5 lines

As the second point says, The flushing operation and the behavior of returning Immediate Error are asynchronous. what you mentioned is not guaranteed. Failing the post_send/post_recv may happens at any time during modify_qp to error.

[1] http://www.rdmaconsortium.org/home/draft-hilland-iwarp-verbs-v1.0-RDMAC.pdf

Well, that language is very imprecise, "at some point" is not exactly definitive. I'll explain one scenario that makes it problematic.

Quoted 7 lines
Quoted 4 lines

Your code seems to start failing WR's when the TX_STOPPED or RX_STOPPED bits are set. But that bit is being set when the drain *begins*, not when it flushes through. That seems wrong, to me.

Back to erdma's scenario, As I explains above, I think failing immediately when flushing begins does not violate the specification.

Consider a consumer which posts with a mix of IB_SEND_SIGNALED and also unsignaled WRs, for example, fast-memory registration followed by a send, a very typical storage consumer operation.

- post_wr(memreg, !signaled) => post success
- => operation success, no completion generated
- ... <= provider detects error here
- post_wr(send, signaled) => post fail (new in your patch)
- ... <= provider notifies async error, etc.

The consumer now knows there's an error, and needs to tear down. It must remove the DMA mapping before proceeding, but the hardware may still be using it. How does it determine the status of that first post_wr, so it may proceed?

The IB spec explicitly states that the post verb can only return the immediate error after the QP has exited the ERROR state, which includes all pending WRs having been flushed and made visible on the CQ. Here is an excerpt from the Post Send Request section 11.4.1.1 specifying its output modifiers:

-> Invalid QP state.
-> Note: This error is returned only when the QP is in the Reset, -> Init, or RTR states. It is not returned when the QP is in the Error -> or Send Queue Error states due to race conditions that could -> result in indeterminate behavior. Work Requests posted to the -> Send Queue while the QP is in the Error or Send Queue Error -> states are completed with a flush error.

So, the consumer will post a new, signaled, work request, and wait for it to "flush through" by polling the CQ. Because WR's always complete in-order, this final completion must appear after *all* prior WR's, and this gives the consumer the green light to proceed.

With your change, ERDMA will pre-emptively fail such a newly posted request, and generate no new completion. The consumer is left in limbo on the status of its prior requests. Providers must not override this.

Tom.

Quoted 54 lines
Quoted 10 lines
Quoted 8 lines
Quoted 1 line

Many upper layers depend on this.

For kernel verbs, erdma currently supports NoF. we tested the NoF cases, and found that it's never happened that newly WRs were posted after QP changed to error, and the drain_qp should be the terminal of IO process.

Also, in userspace, I find that many providers prevents new WRs if QP state is not right.

Sure, but your new STOPPED bits don't propagate up to userspace, right?

Yes. they are only used for kernel QPs. The bits are used for setting an accurate time point to prevent newly WRs when modify qp to error.

Quoted 2 lines

The post calls will fail unexpectedly, because the QP is not yet in ERROR state.

Do you mean this happens in userspace or kernel? The new bits do not influence userspace, and erdma will have the same behavior with other providers in userspace.

For kernel, this is only used in drain_qp scenario. posting WRs and drain qp concurrently will lead uncertain results. This is also mentioned in the comment of ib_drain_qp:

* ensure that there are no other contexts that are posting WRs concurrently.
* Otherwise the drain is not guaranteed.

Quoted 4 lines

I'm also concerned how consumers who are posting their own "drain" WQEs will behave. This is a common approach that many already take. But now they will see different behavior when posting them...

For userspace, erdma is not special.
For kernel, I think the standard way to drain WR is using ib_drain_qp, not custom implementation. I'm not sure that there is some ULPs in kernel has their own drain flow.

Thanks,
Cheng Xu

Quoted 13 lines

Tom.

Quoted 10 lines

So, it seems ok in practice.

Thanks,
Cheng Xu

[1] http://www.rdmaconsortium.org/home/draft-hilland-iwarp-verbs-v1.0-RDMAC.pdf

#12 lore raw
Quoted 3 lines · Tom Talpey

With your change, ERDMA will pre-emptively fail such a newly posted request, and generate no new completion. The consumer is left in limbo on the status of its prior requests. Providers must not override this.

Yeah, I tend to agree with Tom.

And I also want to point out that Linux RDMA verbs does not follow the SW specifications of either IBTA or the iWarp group. We have our own expectation for how these APIs work that our own ULPs rely on.

So pedantically debating what a software spec we don't follow says is not relavent. The utility is to understand the intention and use cases and ensure we cover the same. Usually this means we follow the spec :)

Jason

author maintainer
#13 lore raw
Quoted 8 lines · Jason Gunthorpe
Quoted 3 lines · Tom Talpey

With your change, ERDMA will pre-emptively fail such a newly posted request, and generate no new completion. The consumer is left in limbo on the status of its prior requests. Providers must not override this.

Yeah, I tend to agree with Tom.

Quoted 8 lines

And I also want to point out that Linux RDMA verbs does not follow the SW specifications of either IBTA or the iWarp group. We have our own expectation for how these APIs work that our own ULPs rely on.

So pedantically debating what a software spec we don't follow says is not relavent. The utility is to understand the intention and use cases and ensure we cover the same. Usually this means we follow the spec :)

Yeah, I totally agree with this.

Actually, I thought that ULPs do not concern about the details of how the flushing and modify_qp being performed in the drivers. The drain flow is handled by a single ib_drain_qp call for ULPs. While ib_drain_qp API allows vendor-custom implementation, this is invisible to ULPs.

For the ULPs which implement their own drain flow instead of using ib_drain_qp (I think it is rare in kernel), they will fail in erdma.

Anyway, since our implementation is disputed, We'd like to keep the same behavior with other vendors. Maybe firmware updating w/o driver changes or software flushing in driver will fix this.

Thanks,
Cheng Xu

#14 lore raw
Quoted 27 lines · Cheng Xu
Quoted 8 lines · Jason Gunthorpe
Quoted 3 lines · Tom Talpey

With your change, ERDMA will pre-emptively fail such a newly posted request, and generate no new completion. The consumer is left in limbo on the status of its prior requests. Providers must not override this.

Yeah, I tend to agree with Tom.

Quoted 8 lines

And I also want to point out that Linux RDMA verbs does not follow the SW specifications of either IBTA or the iWarp group. We have our own expectation for how these APIs work that our own ULPs rely on.

So pedantically debating what a software spec we don't follow says is not relavent. The utility is to understand the intention and use cases and ensure we cover the same. Usually this means we follow the spec :)

Yeah, I totally agree with this.

Actually, I thought that ULPs do not concern about the details of how the flushing and modify_qp being performed in the drivers. The drain flow is handled by a single ib_drain_qp call for ULPs. While ib_drain_qp API allows vendor-custom implementation, this is invisible to ULPs.

Quoted 6 lines

For the ULPs which implement their own drain flow instead of using ib_drain_qp (I think it is rare in kernel), they will fail in erdma.

Anyway, since our implementation is disputed, We'd like to keep the same behavior with other vendors. Maybe firmware updating w/o driver changes or software flushing in driver will fix this.

To be clear, my concern is about the ordering of CQE flushes with respect to the WR posting fails. Draining the CQs in whatever way you choose to optimize for your device is not the issue, although it seems odd to me that you need such a thing.

The problem is that your patch started failing the new requests _before_ the drain could be used to clean up. This introduced two new provider behaviors that consumers would not expect:

- first error detected in a post call (on the fast path!)
- inability to determine if prior requests were complete

I'd really suggest getting a copy of the full IB spec and examining the difference between QP "Error" and "SQ Error" states. They are subtle but important.

Tom.

author maintainer
#15 lore raw
Quoted 31 lines · Tom Talpey
Quoted 30 lines · Cheng Xu
Quoted 8 lines · Jason Gunthorpe
Quoted 3 lines · Tom Talpey

With your change, ERDMA will pre-emptively fail such a newly posted request, and generate no new completion. The consumer is left in limbo on the status of its prior requests. Providers must not override this.

Yeah, I tend to agree with Tom.

Quoted 8 lines

And I also want to point out that Linux RDMA verbs does not follow the SW specifications of either IBTA or the iWarp group. We have our own expectation for how these APIs work that our own ULPs rely on.

So pedantically debating what a software spec we don't follow says is not relavent. The utility is to understand the intention and use cases and ensure we cover the same. Usually this means we follow the spec :)

Yeah, I totally agree with this.

Actually, I thought that ULPs do not concern about the details of how the flushing and modify_qp being performed in the drivers. The drain flow is handled by a single ib_drain_qp call for ULPs. While ib_drain_qp API allows vendor-custom implementation, this is invisible to ULPs.

For the ULPs which implement their own drain flow instead of using ib_drain_qp  (I think it is rare in kernel), they will fail in erdma.

Quoted 9 lines
Quoted 3 lines

Anyway, since our implementation is disputed, We'd like to keep the same behavior with other vendors. Maybe firmware updating w/o driver changes or software flushing in driver will fix this.

To be clear, my concern is about the ordering of CQE flushes with respect to the WR posting fails.Draining the CQs in whatever way you choose to optimize for your device is not the issue, although it seems odd to me that you need such a thing.

Yeah, I understand what you concern about. I'm sorry that there may be ambiguity in my last reply.

After discussed internally, we would like to drop this patch (e.g., failing WRs before drain, or failing WRs in QP Error State), because it indeed has problem in the cases you mentioned. And we are seeking for new solutions. New solutions will not failing the WRs in drain cases, and by this erdma will have the same behavior with other vendors.

More, the reason why we introduced this patch is that our hardware do not flush newly WRs in QP Error State currently. So new solutions could be:
- Let our hardware flush newly WRs, or
- Flush WRs in our driver if hardware does not flush.
Either of them will eliminate the odd logic in this patch. For now, we tend the first option.

Thanks,
Cheng Xu

Quoted 12 lines

The problem is that your patch started failing the new requests _before_ the drain could be used to clean up. This introduced two new provider behaviors that consumers would not expect:

- first error detected in a post call (on the fast path!)
- inability to determine if prior requests were complete

I'd really suggest getting a copy of the full IB spec and examining the difference between QP "Error" and "SQ Error" states. They are subtle but important.

Tom.

author maintainer
#16 lore raw
In reply to Tom Talpey
Quoted 40 lines · Tom Talpey
Quoted 27 lines · Cheng Xu
Quoted 8 lines · Jason Gunthorpe
Quoted 3 lines · Tom Talpey

With your change, ERDMA will pre-emptively fail such a newly posted request, and generate no new completion. The consumer is left in limbo on the status of its prior requests. Providers must not override this.

Yeah, I tend to agree with Tom.

Quoted 8 lines

And I also want to point out that Linux RDMA verbs does not follow the SW specifications of either IBTA or the iWarp group. We have our own expectation for how these APIs work that our own ULPs rely on.

So pedantically debating what a software spec we don't follow says is not relavent. The utility is to understand the intention and use cases and ensure we cover the same. Usually this means we follow the spec :)

Yeah, I totally agree with this.

Actually, I thought that ULPs do not concern about the details of how the flushing and modify_qp being performed in the drivers. The drain flow is handled by a single ib_drain_qp call for ULPs. While ib_drain_qp API allows vendor-custom implementation, this is invisible to ULPs.

Quoted 6 lines

For the ULPs which implement their own drain flow instead of using ib_drain_qp  (I think it is rare in kernel), they will fail in erdma.

Anyway, since our implementation is disputed, We'd like to keep the same behavior with other vendors. Maybe firmware updating w/o driver changes or software flushing in driver will fix this.

To be clear, my concern is about the ordering of CQE flushes with respect to the WR posting fails. Draining the CQs in whatever way you choose to optimize for your device is not the issue, although it seems odd to me that you need such a thing.

Quoted 7 lines

The problem is that your patch started failing the new requests _before_ the drain could be used to clean up. This introduced two new provider behaviors that consumers would not expect:

- first error detected in a post call (on the fast path!)
- inability to determine if prior requests were complete

Yes, you are right. As I replied, we will drop this patch, and follow the common behaviors as other providers do.

Quoted 3 lines

I'd really suggest getting a copy of the full IB spec and examining the difference between QP "Error" and "SQ Error" states. They are subtle but important.

Yeah, I'm already doing this. Thanks very much.

Cheng Xu

Quoted 1 line

Tom.

author maintainer
#17 lore raw
In reply to Tom Talpey
Quoted 77 lines · Tom Talpey
Quoted 38 lines · Cheng Xu
Quoted 16 lines · Tom Talpey
Quoted 15 lines · Cheng Xu
Quoted 9 lines · Tom Talpey
Quoted 4 lines · Cheng Xu

Hi,

This series introduces erdma's implementation of drain_sq and drain_rq. Our hardware will stop processing any new WRs if QP state is error.

Doesn't this violate the IB specification? Failing newly posted WRs before older WRs have flushed to the CQ means that ordering is not preserved.

I agree with Bernard's point.

Quoted 9 lines
Quoted 4 lines

I'm not very familiar with with IB specification. But for RNIC/iWarp [1], post WR in Error state has two optional actions: "Post WQE, and then Flush it" or "Return an Immediate Error" (Showed in Figure 10). So, I think failing newly posted WRs is reasonable.

<...> But the QP can only enter ERROR once the
SQ and RQ are fully drained to the CQ(s). Until that happens, the WRs need to flush through.

Emm, let's put erdma aside first, it seems that specification does not require this. According to "6.2.4 Error State" in the document [1]:

  The following is done on entry into the Error state:
  * The RI MUST flush any incomplete WRs on the SQ or RQ.
    .....
  * At some point in the execution of the flushing operation, the RI MUST begin to return an Immediate Error for any attempt to post a WR to a Work Queue;
    ....

Quoted 5 lines

As the second point says, The flushing operation and the behavior of returning Immediate Error are asynchronous. what you mentioned is not guaranteed. Failing the post_send/post_recv may happens at any time during modify_qp to error.

[1] http://www.rdmaconsortium.org/home/draft-hilland-iwarp-verbs-v1.0-RDMAC.pdf

Well, that language is very imprecise, "at some point" is not exactly definitive. I'll explain one scenario that makes it problematic.

Quoted 7 lines
Quoted 4 lines

Your code seems to start failing WR's when the TX_STOPPED or RX_STOPPED bits are set. But that bit is being set when the drain *begins*, not when it flushes through. That seems wrong, to me.

Back to erdma's scenario, As I explains above, I think failing immediately when flushing begins does not violate the specification.

Consider a consumer which posts with a mix of IB_SEND_SIGNALED and also unsignaled WRs, for example, fast-memory registration followed by a send, a very typical storage consumer operation.

- post_wr(memreg, !signaled) => post success
-      => operation success, no completion generated
- ...  <= provider detects error here
- post_wr(send, signaled) => post fail (new in your patch)
- ...  <= provider notifies async error, etc.

The consumer now knows there's an error, and needs to tear down. It must remove the DMA mapping before proceeding, but the hardware may still be using it. How does it determine the status of that first post_wr, so it may proceed?

The IB spec explicitly states that the post verb can only return the immediate error after the QP has exited the ERROR state, which includes all pending WRs having been flushed and made visible on the CQ. Here is an excerpt from the Post Send Request section 11.4.1.1 specifying its output modifiers:

Quoted 8 lines

-> Invalid QP state.
-> Note: This error is returned only when the QP is in the Reset, -> Init, or RTR states. It is not returned when the QP is in the Error -> or Send Queue Error states due to race conditions that could -> result in indeterminate behavior. Work Requests posted to the -> Send Queue while the QP is in the Error or Send Queue Error -> states are completed with a flush error.

Get it, thanks. The IB spec seems to be more clear.

Quoted 5 lines

So, the consumer will post a new, signaled, work request, and wait for it to "flush through" by polling the CQ. Because WR's always complete in-order, this final completion must appear after *all* prior WR's, and this gives the consumer the green light to proceed.

Yeah, this is right, and the default ib_drain_qp do it in this way.

Quoted 3 lines

With your change, ERDMA will pre-emptively fail such a newly posted request, and generate no new completion. The consumer is left in limbo on the status of its prior requests. Providers must not override this.

For the ULPs that do not use ib_drain_qp interface, we will have problem.

But currently it seems that almost all the ULPs in kernel call ib_drain_qp to finish the drain flow. While ib_drain_qp allows vendors to have custom ib_drain_qp implementations which is invisible to ULPs.

Thanks,
Cheng Xu

Quoted 2 lines

Tom.