diff mbox

[libmlx5] Add support for legacy context size

Message ID 1459078225-16205-1-git-send-email-majd@mellanox.com (mailing list archive)
State Not Applicable
Headers show

Commit Message

Majd Dibbiny March 27, 2016, 11:30 a.m. UTC
The ibv_cmd_get_context fails in older kernels when passing
a request length that the kernel doesn't know.
To avoid breaking compatibility of new libmlx5 and older kernels,
when ibv_cmd_get_context fails with the full request length,
we try once again with the legacy length.

Signed-off-by: Majd Dibbiny <majd@mellanox.com>
Reviewed-by: Yishai Hadas <yishaih@mellanox.com>
---
 src/mlx5.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

Comments

Yishai Hadas March 29, 2016, 7:07 a.m. UTC | #1
On 3/27/2016 2:30 PM, Majd Dibbiny wrote:
> The ibv_cmd_get_context fails in older kernels when passing
> a request length that the kernel doesn't know.
> To avoid breaking compatibility of new libmlx5 and older kernels,
> when ibv_cmd_get_context fails with the full request length,
> we try once again with the legacy length.
>
> Signed-off-by: Majd Dibbiny <majd@mellanox.com>
> Reviewed-by: Yishai Hadas <yishaih@mellanox.com>
> ---
>   src/mlx5.c | 27 +++++++++++++++++++++++++--
>   1 file changed, 25 insertions(+), 2 deletions(-)
>

Applied, thanks.
--
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/mlx5.c b/src/mlx5.c
index d19c376..7bd01bd 100644
--- a/src/mlx5.c
+++ b/src/mlx5.c
@@ -533,6 +533,28 @@  static int single_threaded_app(void)
 	return 0;
 }
 
+static int mlx5_cmd_get_context(struct mlx5_context *context,
+				struct mlx5_alloc_ucontext *req,
+				size_t req_len,
+				struct mlx5_alloc_ucontext_resp *resp,
+				size_t resp_len)
+{
+	if (!ibv_cmd_get_context(&context->ibv_ctx, &req->ibv_req,
+				 req_len, &resp->ibv_resp, resp_len))
+		return 0;
+
+	/* The ibv_cmd_get_context fails in older kernels when passing
+	 * a request length that the kernel doesn't know.
+	 * To avoid breaking compatibility of new libmlx5 and older
+	 * kernels, when ibv_cmd_get_context fails with the full
+	 * request length, we try once again with the legacy length.
+	 */
+	return ibv_cmd_get_context(&context->ibv_ctx, &req->ibv_req,
+				   offsetof(struct mlx5_alloc_ucontext,
+					    cqe_version),
+				   &resp->ibv_resp, resp_len);
+}
+
 static int mlx5_init_context(struct verbs_device *vdev,
 			     struct ibv_context *ctx, int cmd_fd)
 {
@@ -598,8 +620,9 @@  static int mlx5_init_context(struct verbs_device *vdev,
 	req.total_num_uuars = tot_uuars;
 	req.num_low_latency_uuars = low_lat_uuars;
 	req.cqe_version = MLX5_CQE_VERSION_V1;
-	if (ibv_cmd_get_context(&context->ibv_ctx, &req.ibv_req, sizeof req,
-				&resp.ibv_resp, sizeof resp))
+
+	if (mlx5_cmd_get_context(context, &req, sizeof(req), &resp,
+				 sizeof(resp)))
 		goto err_free_bf;
 
 	context->max_num_qps		= resp.qp_tab_size;