Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9e9c47d0 authored by Eli Cohen's avatar Eli Cohen Committed by Roland Dreier
Browse files

IB/mlx5: Allow creation of QPs with zero-length work queues



The current code attmepts to call ib_umem_get() even if the length is
zero, which causes a failure. Since the spec allows zero length work
queues, change the code so we don't call ib_umem_get() in those cases.

Signed-off-by: default avatarEli Cohen <eli@mellanox.com>
Signed-off-by: default avatarRoland Dreier <roland@purestorage.com>
parent 05bdb2ab
Loading
Loading
Loading
Loading
+29 −20
Original line number Diff line number Diff line
@@ -523,12 +523,12 @@ static int create_user_qp(struct mlx5_ib_dev *dev, struct ib_pd *pd,
{
	struct mlx5_ib_ucontext *context;
	struct mlx5_ib_create_qp ucmd;
	int page_shift;
	int page_shift = 0;
	int uar_index;
	int npages;
	u32 offset;
	u32 offset = 0;
	int uuarn;
	int ncont;
	int ncont = 0;
	int err;

	err = ib_copy_from_udata(&ucmd, udata, sizeof(ucmd));
@@ -564,6 +564,7 @@ static int create_user_qp(struct mlx5_ib_dev *dev, struct ib_pd *pd,
	if (err)
		goto err_uuar;

	if (ucmd.buf_addr && qp->buf_size) {
		qp->umem = ib_umem_get(pd->uobject->context, ucmd.buf_addr,
				       qp->buf_size, 0, 0);
		if (IS_ERR(qp->umem)) {
@@ -571,7 +572,11 @@ static int create_user_qp(struct mlx5_ib_dev *dev, struct ib_pd *pd,
			err = PTR_ERR(qp->umem);
			goto err_uuar;
		}
	} else {
		qp->umem = NULL;
	}

	if (qp->umem) {
		mlx5_ib_cont_pages(qp->umem, ucmd.buf_addr, &npages, &page_shift,
				   &ncont, NULL);
		err = mlx5_ib_get_buf_offset(ucmd.buf_addr, page_shift, &offset);
@@ -581,6 +586,7 @@ static int create_user_qp(struct mlx5_ib_dev *dev, struct ib_pd *pd,
		}
		mlx5_ib_dbg(dev, "addr 0x%llx, size %d, npages %d, page_shift %d, ncont %d, offset %d\n",
			    ucmd.buf_addr, qp->buf_size, npages, page_shift, ncont, offset);
	}

	*inlen = sizeof(**in) + sizeof(*(*in)->pas) * ncont;
	*in = mlx5_vzalloc(*inlen);
@@ -588,6 +594,7 @@ static int create_user_qp(struct mlx5_ib_dev *dev, struct ib_pd *pd,
		err = -ENOMEM;
		goto err_umem;
	}
	if (qp->umem)
		mlx5_ib_populate_pas(dev, qp->umem, page_shift, (*in)->pas, 0);
	(*in)->ctx.log_pg_sz_remote_qpn =
		cpu_to_be32((page_shift - MLX5_ADAPTER_PAGE_SHIFT) << 24);
@@ -619,6 +626,7 @@ static int create_user_qp(struct mlx5_ib_dev *dev, struct ib_pd *pd,
	mlx5_vfree(*in);

err_umem:
	if (qp->umem)
		ib_umem_release(qp->umem);

err_uuar:
@@ -632,6 +640,7 @@ static void destroy_qp_user(struct ib_pd *pd, struct mlx5_ib_qp *qp)

	context = to_mucontext(pd->uobject->context);
	mlx5_ib_db_unmap_user(context, &qp->db);
	if (qp->umem)
		ib_umem_release(qp->umem);
	free_uuar(&context->uuari, qp->uuarn);
}