diff mbox

[v2,libmlx5] fix err return values to match ibv_post_send expectations

Message ID 1470679455-28911-1-git-send-email-jarod@redhat.com (mailing list archive)
State Not Applicable
Headers show

Commit Message

Jarod Wilson Aug. 8, 2016, 6:04 p.m. UTC
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

Reported-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Tested-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
CC: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
CC: Yishai Hadas <yishaih@mellanox.com>
Signed-off-by: Jarod Wilson <jarod@redhat.com>
---
 src/qp.c | 27 +++++++++------------------
 1 file changed, 9 insertions(+), 18 deletions(-)

Comments

Yishai Hadas Aug. 10, 2016, 11:53 a.m. UTC | #1
On 8/8/2016 9:04 PM, Jarod Wilson wrote:
> 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

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.

>
> Reported-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> Tested-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> CC: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
> CC: Yishai Hadas <yishaih@mellanox.com>
> Signed-off-by: Jarod Wilson <jarod@redhat.com>
> ---
>  src/qp.c | 27 +++++++++------------------
>  1 file changed, 9 insertions(+), 18 deletions(-)
>
> diff --git a/src/qp.c b/src/qp.c
> index 51e1176..38352e9 100644
> --- a/src/qp.c
> +++ b/src/qp.c
> @@ -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
>
>

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Jarod Wilson Aug. 11, 2016, 4:05 a.m. UTC | #2
On Wed, Aug 10, 2016 at 02:53:45PM +0300, Yishai Hadas wrote:
> On 8/8/2016 9:04 PM, Jarod Wilson wrote:
> >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
> 
> 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.

Works for me, thanks much.
Yishai Hadas Aug. 11, 2016, 10:18 a.m. UTC | #3
On 8/11/2016 7:05 AM, Jarod Wilson wrote:
>> 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.
>
> 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 majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/src/qp.c b/src/qp.c
index 51e1176..38352e9 100644
--- a/src/qp.c
+++ b/src/qp.c
@@ -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