Limit qp resources accepted for ibv_create_qp() to the limits reported in ib_query_device(). Make sure that the limits returned to the caller following qp creation also lie within the reported device limits. (OFED 1.3 libmlx4 commit b612592e2c43472895ccc495183aa63980d8e7a5) Signed-off-by: Jack Morgenstein Index: libmlx4/src/qp.c =================================================================== --- libmlx4.orig/src/qp.c 2008-06-04 08:24:45.000000000 +0300 +++ libmlx4/src/qp.c 2008-06-04 08:24:49.000000000 +0300 @@ -619,6 +619,7 @@ void mlx4_set_sq_sizes(struct mlx4_qp *q enum ibv_qp_type type) { int wqe_size; + struct mlx4_context *ctx = to_mctx(qp->ibv_qp.context); wqe_size = (1 << qp->sq.wqe_shift) - sizeof (struct mlx4_wqe_ctrl_seg); switch (type) { @@ -636,8 +637,9 @@ void mlx4_set_sq_sizes(struct mlx4_qp *q } qp->sq.max_gs = wqe_size / sizeof (struct mlx4_wqe_data_seg); - cap->max_send_sge = qp->sq.max_gs; - qp->sq.max_post = qp->sq.wqe_cnt - qp->sq_spare_wqes; + cap->max_send_sge = min(ctx->max_sge, qp->sq.max_gs); + qp->sq.max_post = min(ctx->max_qp_wr, + qp->sq.wqe_cnt - qp->sq_spare_wqes); cap->max_send_wr = qp->sq.max_post; /* Index: libmlx4/src/verbs.c =================================================================== --- libmlx4.orig/src/verbs.c 2008-06-04 08:24:45.000000000 +0300 +++ libmlx4/src/verbs.c 2008-06-04 08:24:49.000000000 +0300 @@ -390,12 +390,14 @@ struct ibv_qp *mlx4_create_qp(struct ibv struct ibv_create_qp_resp resp; struct mlx4_qp *qp; int ret; + struct mlx4_context *context = to_mctx(pd->context); + /* Sanity check QP size before proceeding */ - if (attr->cap.max_send_wr > 65536 || - attr->cap.max_recv_wr > 65536 || - attr->cap.max_send_sge > 64 || - attr->cap.max_recv_sge > 64 || + if (attr->cap.max_send_wr > context->max_qp_wr || + attr->cap.max_recv_wr > context->max_qp_wr || + attr->cap.max_send_sge > context->max_sge || + attr->cap.max_recv_sge > context->max_sge || attr->cap.max_inline_data > 1024) return NULL; @@ -461,8 +463,14 @@ struct ibv_qp *mlx4_create_qp(struct ibv goto err_destroy; pthread_mutex_unlock(&to_mctx(pd->context)->qp_table_mutex); - qp->rq.wqe_cnt = qp->rq.max_post = attr->cap.max_recv_wr; + qp->rq.wqe_cnt = attr->cap.max_recv_wr; qp->rq.max_gs = attr->cap.max_recv_sge; + + /* adjust rq maxima to not exceed reported device maxima */ + attr->cap.max_recv_wr = min(context->max_qp_wr, attr->cap.max_recv_wr); + attr->cap.max_recv_sge = min(context->max_sge, attr->cap.max_recv_sge); + + qp->rq.max_post = attr->cap.max_recv_wr; mlx4_set_sq_sizes(qp, &attr->cap, attr->qp_type); qp->doorbell_qpn = htonl(qp->ibv_qp.qp_num << 8);