Skip to contentSkip to conversation

fix err return values to match ibv_post_send expectations

PATCH Superseded Jarod Wilson 3 participants 10 messages Aug 5, 2016 – Aug 11, 2016 9 messages not in the archive InfiniBand

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix err return values to match ibv_post_send expectations

The man page for ibv_post_send says:

RETURN VALUE

ibv_post_send() returns 0 on success, or the value of errno on failure (which indicates the failure reason).

QEMU looks for the return value, and in the ENOMEM case, waits and retries, but with mlx5, it ends up dropping requests and hanging, because of the unexpected -1 return instead of ENOMEM.

The fix is simple: set err = E<whatever> instead of -1, and eliminate use of errno = in _mlx5_post_send, just have mlx5_post_send assign the return from _mlx5_post_send in errno instead. This fix has been confirmed to resolves the issues seen with QEMU.

---
 src/qp.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
src/qp.c +5 -7
index 51e1176..2ad3ac0 100644
@@ -590,8 +590,7 @@ static inline int _mlx5_post_send(struct ibv_qp *ibqp, struct ibv_send_wr *wr,
 		if (unlikely(wr->opcode < 0 ||
 		    wr->opcode >= sizeof mlx5_ib_opcode / sizeof mlx5_ib_opcode[0])) {
 			mlx5_dbg(fp, MLX5_DBG_QP_SEND, "bad opcode %d\n", wr->opcode);
-			errno = EINVAL;
-			err = -1;
+			err = EINVAL;
 			*bad_wr = wr;
 			goto out;
 		}
@@ -599,8 +598,7 @@ static inline int _mlx5_post_send(struct ibv_qp *ibqp, struct ibv_send_wr *wr,
 		if (unlikely(mlx5_wq_overflow(&qp->sq, nreq,
 					      to_mcq(qp->ibv_qp->send_cq)))) {
 			mlx5_dbg(fp, MLX5_DBG_QP_SEND, "work queue overflow\n");
-			errno = ENOMEM;
-			err = -1;
+			err = ENOMEM;
 			*bad_wr = wr;
 			goto out;
 		}
@@ -608,8 +606,7 @@ static inline int _mlx5_post_send(struct ibv_qp *ibqp, struct ibv_send_wr *wr,
 		if (unlikely(wr->num_sge > qp->sq.max_gs)) {
 			mlx5_dbg(fp, MLX5_DBG_QP_SEND, "max gs exceeded %d (max = %d)\n",
 				 wr->num_sge, qp->sq.max_gs);
-			errno = ENOMEM;
-			err = -1;
+			err = ENOMEM;
 			*bad_wr = wr;
 			goto out;
 		}
@@ -918,7 +915,8 @@ int mlx5_post_send(struct ibv_qp *ibqp, struct ibv_send_wr *wr,
 	}
 #endif
 
-	return _mlx5_post_send(ibqp, wr, bad_wr);
+	errno = _mlx5_post_send(ibqp, wr, bad_wr);
+	return errno;
 }
 
 int mlx5_bind_mw(struct ibv_qp *qp, struct ibv_mw *mw,
Signature · 6 lines
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw
In reply to a message not in the archive

src/qp.c int mlx5_post_send(struct ibv_qp *ibqp, struct ibv_send_wr *wr, · line 919

Quoted 3 lines · Jarod Wilson
src/qp.c +2 -1
-	return _mlx5_post_send(ibqp, wr, bad_wr);
+	errno = _mlx5_post_send(ibqp, wr, bad_wr);
+	return errno;

Why still set errno? It was wrong in the first place..

Likely every use of errno in this provider should be reviewed.

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
In reply to a message not in the archive
Quoted 8 lines · Jason Gunthorpe

src/qp.c int mlx5_post_send(struct ibv_qp *ibqp, struct ibv_send_wr *wr, · line 919

Quoted 3 lines · Jarod Wilson
src/qp.c +2 -1
-	return _mlx5_post_send(ibqp, wr, bad_wr);
+	errno = _mlx5_post_send(ibqp, wr, bad_wr);
+	return errno;

Why still set errno? It was wrong in the first place..

Likely every use of errno in this provider should be reviewed.

Wasn't sure if something else might actually consume errno elsewhere, since it's a global, and the other code path in that function set errno. Could certainly just stick with returning the _mlx5_post_send() result directly.

Signature · 7 lines
Jarod Wilson
[email protected]

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#6 lore raw
In reply to a message not in the archive
Quoted 8 lines · Jarod Wilson
Quoted 7 lines · Jason Gunthorpe

src/qp.c int mlx5_post_send(struct ibv_qp *ibqp, struct ibv_send_wr *wr, · line 919

Quoted 3 lines · Jarod Wilson
src/qp.c +2 -1
-	return _mlx5_post_send(ibqp, wr, bad_wr);
+	errno = _mlx5_post_send(ibqp, wr, bad_wr);
+	return errno;

Why still set errno? It was wrong in the first place..

Quoted 6 lines
Quoted 1 line

Likely every use of errno in this provider should be reviewed.

Wasn't sure if something else might actually consume errno elsewhere, since it's a global, and the other code path in that function set errno. Could certainly just stick with returning the _mlx5_post_send() result directly.

If the man page doesn't document the function destroying errno, then it should preserve it. Do not just randomly set errno.

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#8 lore raw
In reply to a message not in the archive
Quoted 11 lines · Jason Gunthorpe
Quoted 10 lines · Jarod Wilson
Quoted 8 lines · Jason Gunthorpe

Review

Quoted 3 lines · Jarod Wilson
(quoted diff) +2 -1
-	return _mlx5_post_send(ibqp, wr, bad_wr);
+	errno = _mlx5_post_send(ibqp, wr, bad_wr);
+	return errno;

Why still set errno? It was wrong in the first place..

Likely every use of errno in this provider should be reviewed.

Quoted 7 lines
Quoted 4 lines

Wasn't sure if something else might actually consume errno elsewhere, since it's a global, and the other code path in that function set errno. Could certainly just stick with returning the _mlx5_post_send() result directly.

If the man page doesn't document the function destroying errno, then it should preserve it. Do not just randomly set errno.

$ man ibv_post_send
...
RETURN VALUE
       ibv_post_send() returns 0 on success, or the value of errno on
       failure (which indicates the failure reason).
...

This is a little bit terse, but looks to me like it means to say do set errno in ibv_post_send. I really am not terribly familiar with this code though, so I have no idea for sure if my interpretation is correct. Looks like libmlx4 does NOT twiddle errno though. I can certainly update the patch if consensus is that errno shouldn't be touched. Looks like mlx5_post_send() will need some additional work as well if that's the case though.

Signature · 7 lines
Jarod Wilson
[email protected]

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#10 lore raw
In reply to a message not in the archive
Quoted 10 lines · Jarod Wilson
Quoted 2 lines

If the man page doesn't document the function destroying errno, then it should preserve it. Do not just randomly set errno.

$ man ibv_post_send
...
RETURN VALUE
       ibv_post_send() returns 0 on success, or the value of errno on
       failure (which indicates the failure reason).
...
Quoted 3 lines

This is a little bit terse, but looks to me like it means to say do set errno in ibv_post_send. I really am not terribly familiar with this code

Yes, our man pages are a little baroque.

The phrase 'returns the value of errno' means it returns a E* value, not errno itself and leaves errno alone.

Using the phrase 'it returns an error number' would be clearer and more consistent with glibc documentation.

Quoted 3 lines

patch if consensus is that errno shouldn't be touched. Looks like mlx5_post_send() will need some additional work as well if that's the case though.

Most likely.

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#12 lore raw

PATCH v2 1/1 fix err return values to match ibv_post_send expectations

In reply to a message not in the archive

The man page for ibv_post_send says:

RETURN VALUE

ibv_post_send() returns 0 on success, or the value of errno on failure (which indicates the failure reason).

QEMU looks for the return value, and in the ENOMEM case, waits and retries, but with mlx5, it ends up dropping requests and hanging, because of the unexpected -1 return instead of ENOMEM.

The fix is simple: set err = E<whatever> instead of -1, and eliminate use of errno = in _mlx5_post_send, just have mlx5_post_send return the err from _mlx5_post_send instead. This fix has been confirmed to resolves the issues seen with QEMU.

While we're at it, fix the MW_DEBUG code paths to no muck with errno either.

v2: per discussion with Jason Gunthorpe, don't set errno in mlx5_post_send

CC Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
CC Yishai Hadas <yishaih-VPRAkNaXOzVWk0Htik3J/[email protected]>
---
 src/qp.c | 27 +++++++++------------------
 1 file changed, 9 insertions(+), 18 deletions(-)
src/qp.c +9 -18
index 51e1176..38352e9 100644
@@ -590,8 +590,7 @@ static inline int _mlx5_post_send(struct ibv_qp *ibqp, struct ibv_send_wr *wr,
 		if (unlikely(wr->opcode < 0 ||
 		    wr->opcode >= sizeof mlx5_ib_opcode / sizeof mlx5_ib_opcode[0])) {
 			mlx5_dbg(fp, MLX5_DBG_QP_SEND, "bad opcode %d\n", wr->opcode);
-			errno = EINVAL;
-			err = -1;
+			err = EINVAL;
 			*bad_wr = wr;
 			goto out;
 		}
@@ -599,8 +598,7 @@ static inline int _mlx5_post_send(struct ibv_qp *ibqp, struct ibv_send_wr *wr,
 		if (unlikely(mlx5_wq_overflow(&qp->sq, nreq,
 					      to_mcq(qp->ibv_qp->send_cq)))) {
 			mlx5_dbg(fp, MLX5_DBG_QP_SEND, "work queue overflow\n");
-			errno = ENOMEM;
-			err = -1;
+			err = ENOMEM;
 			*bad_wr = wr;
 			goto out;
 		}
@@ -608,8 +606,7 @@ static inline int _mlx5_post_send(struct ibv_qp *ibqp, struct ibv_send_wr *wr,
 		if (unlikely(wr->num_sge > qp->sq.max_gs)) {
 			mlx5_dbg(fp, MLX5_DBG_QP_SEND, "max gs exceeded %d (max = %d)\n",
 				 wr->num_sge, qp->sq.max_gs);
-			errno = ENOMEM;
-			err = -1;
+			err = ENOMEM;
 			*bad_wr = wr;
 			goto out;
 		}
@@ -899,22 +896,16 @@ int mlx5_post_send(struct ibv_qp *ibqp, struct ibv_send_wr *wr,
 {
 #ifdef MW_DEBUG
 	if (wr->opcode == IBV_WR_BIND_MW) {
-		if (wr->bind_mw.mw->type == IBV_MW_TYPE_1) {
-			errno = EINVAL;
-			return errno;
-		}
+		if (wr->bind_mw.mw->type == IBV_MW_TYPE_1)
+			return EINVAL;
 
 		if (!wr->bind_mw.bind_info.mr ||
 		    !wr->bind_mw.bind_info.addr ||
-		    !wr->bind_mw.bind_info.length) {
-			errno = EINVAL;
-			return errno;
-		}
+		    !wr->bind_mw.bind_info.length)
+			return EINVAL;
 
-		if (wr->bind_mw.bind_info.mr->pd != wr->bind_mw.mw->pd) {
-			errno = EINVAL;
-			return errno;
-		}
+		if (wr->bind_mw.bind_info.mr->pd != wr->bind_mw.mw->pd)
+			return EINVAL;
 	}
 #endif
 
Signature · 6 lines
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#14 lore raw
In reply to a message not in the archive
Quoted 11 lines · Jarod Wilson

The man page for ibv_post_send says:

RETURN VALUE

ibv_post_send() returns 0 on success, or the value of errno on failure (which indicates the failure reason).

QEMU looks for the return value, and in the ENOMEM case, waits and retries, but with mlx5, it ends up dropping requests and hanging, because of the unexpected -1 return instead of ENOMEM.

Quoted 8 lines

The fix is simple: set err = E<whatever> instead of -1, and eliminate use of errno = in _mlx5_post_send, just have mlx5_post_send return the err from _mlx5_post_send instead. This fix has been confirmed to resolves the issues seen with QEMU.

While we're at it, fix the MW_DEBUG code paths to no muck with errno either.

v2: per discussion with Jason Gunthorpe, don't set errno in mlx5_post_send

Your patch missed few other flows that should be fixed as part of mlx5_post_send. (e.g. set_data_inl_seg which returns -1, set_bind_wr which touches errno, etc).

Just fixed that with some other minor typos/changes to the commit log, will send it shortly as V3, left you as the Author to give you the credit for.

In addition,
Both mlx5_post_recv and mlx5_post_srq_recv should be fixed in the same manner, prepared another patch as some candidate fix will send it shortly as well.

Once the new candidate patches will pass our regression testing will take them officially into libmlx5.

Quoted 64 lines
CC Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
CC Yishai Hadas <yishaih-VPRAkNaXOzVWk0Htik3J/[email protected]>
---
 src/qp.c | 27 +++++++++------------------
 1 file changed, 9 insertions(+), 18 deletions(-)
src/qp.c +7 -14
index 51e1176..38352e9 100644
@@ -590,8 +590,7 @@ static inline int _mlx5_post_send(struct ibv_qp *ibqp, struct ibv_send_wr *wr,
 		if (unlikely(wr->opcode < 0 ||
 		    wr->opcode >= sizeof mlx5_ib_opcode / sizeof mlx5_ib_opcode[0])) {
 			mlx5_dbg(fp, MLX5_DBG_QP_SEND, "bad opcode %d\n", wr->opcode);
-			errno = EINVAL;
-			err = -1;
+			err = EINVAL;
 			*bad_wr = wr;
 			goto out;
 		}
@@ -599,8 +598,7 @@ static inline int _mlx5_post_send(struct ibv_qp *ibqp, struct ibv_send_wr *wr,
 		if (unlikely(mlx5_wq_overflow(&qp->sq, nreq,
 					      to_mcq(qp->ibv_qp->send_cq)))) {
 			mlx5_dbg(fp, MLX5_DBG_QP_SEND, "work queue overflow\n");
-			errno = ENOMEM;
-			err = -1;
+			err = ENOMEM;
 			*bad_wr = wr;
 			goto out;
 		}
@@ -608,8 +606,7 @@ static inline int _mlx5_post_send(struct ibv_qp *ibqp, struct ibv_send_wr *wr,
 		if (unlikely(wr->num_sge > qp->sq.max_gs)) {
 			mlx5_dbg(fp, MLX5_DBG_QP_SEND, "max gs exceeded %d (max = %d)\n",
 				 wr->num_sge, qp->sq.max_gs);
-			errno = ENOMEM;
-			err = -1;
+			err = ENOMEM;
 			*bad_wr = wr;
 			goto out;
 		}
@@ -899,22 +896,16 @@ int mlx5_post_send(struct ibv_qp *ibqp, struct ibv_send_wr *wr,
 {
 #ifdef MW_DEBUG
 	if (wr->opcode == IBV_WR_BIND_MW) {
-		if (wr->bind_mw.mw->type == IBV_MW_TYPE_1) {
-			errno = EINVAL;
-			return errno;
-		}
+		if (wr->bind_mw.mw->type == IBV_MW_TYPE_1)
+			return EINVAL;
 
 		if (!wr->bind_mw.bind_info.mr ||
 		    !wr->bind_mw.bind_info.addr ||
-		    !wr->bind_mw.bind_info.length) {
-			errno = EINVAL;
-			return errno;
-		}
+		    !wr->bind_mw.bind_info.length)
+			return EINVAL;

src/qp.c int mlx5_post_send(struct ibv_qp *ibqp, struct ibv_send_wr *wr, · line 911

Quoted 10 lines
src/qp.c +2 -4
 
-		if (wr->bind_mw.bind_info.mr->pd != wr->bind_mw.mw->pd) {
-			errno = EINVAL;
-			return errno;
-		}
+		if (wr->bind_mw.bind_info.mr->pd != wr->bind_mw.mw->pd)
+			return EINVAL;
 	}
 #endif
 

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#16 lore raw
In reply to a message not in the archive
Quoted 29 lines · Yishai Hadas
Quoted 11 lines · Jarod Wilson

The man page for ibv_post_send says:

RETURN VALUE

ibv_post_send() returns 0 on success, or the value of errno on failure (which indicates the failure reason).

QEMU looks for the return value, and in the ENOMEM case, waits and retries, but with mlx5, it ends up dropping requests and hanging, because of the unexpected -1 return instead of ENOMEM.

Quoted 8 lines

The fix is simple: set err = E<whatever> instead of -1, and eliminate use of errno = in _mlx5_post_send, just have mlx5_post_send return the err from _mlx5_post_send instead. This fix has been confirmed to resolves the issues seen with QEMU.

While we're at it, fix the MW_DEBUG code paths to no muck with errno either.

v2: per discussion with Jason Gunthorpe, don't set errno in mlx5_post_send

Your patch missed few other flows that should be fixed as part of mlx5_post_send. (e.g. set_data_inl_seg which returns -1, set_bind_wr which touches errno, etc).

Just fixed that with some other minor typos/changes to the commit log, will send it shortly as V3, left you as the Author to give you the credit for.

Quoted 7 lines

In addition,
Both mlx5_post_recv and mlx5_post_srq_recv should be fixed in the same manner, prepared another patch as some candidate fix will send it shortly as well.

Once the new candidate patches will pass our regression testing will take them officially into libmlx5.

Works for me, thanks much.

Signature · 7 lines
Jarod Wilson
[email protected]

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#18 lore raw
In reply to a message not in the archive
Quoted 9 lines · Jarod Wilson
Quoted 9 lines

Just fixed that with some other minor typos/changes to the commit log, will send it shortly as V3, left you as the Author to give you the credit for.

In addition,
Both mlx5_post_recv and mlx5_post_srq_recv should be fixed in the same manner, prepared another patch as some candidate fix will send it shortly as well.

Quoted 5 lines
Quoted 2 lines

Once the new candidate patches will pass our regression testing will take them officially into libmlx5.

Works for me, thanks much.

Fine, V3 and second patch to fix the recv flow were applied. --
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html