| @@ -75,7 +75,8 @@ static void mlx5_ib_srq_event(struct mlx5_core_srq *srq, enum mlx5_event type) · 74 unmodified lines |
| 75 | 75 | |
| 76 | 76 | static int create_srq_user(struct ib_pd *pd, struct mlx5_ib_srq *srq, |
| 77 | 77 | struct mlx5_create_srq_mbox_in **in, |
| 78 | | − struct ib_udata *udata, int buf_size, int *inlen) |
| 78 | + struct ib_udata *udata, int buf_size, int *inlen, |
| 79 | + int is_xrc) |
| 79 | 80 | { |
| 80 | 81 | struct mlx5_ib_dev *dev = to_mdev(pd->device); |
| 81 | 82 | struct mlx5_ib_create_srq ucmd = {}; |
| @@ -87,13 +88,8 @@ static int create_srq_user(struct ib_pd *pd, struct mlx5_ib_srq *srq, · 5 unmodified lines |
| 87 | 88 | int ncont; |
| 88 | 89 | u32 offset; |
| 89 | 90 | u32 uidx = MLX5_IB_DEFAULT_UIDX; |
| 90 | | − int drv_data = udata->inlen - sizeof(struct ib_uverbs_cmd_hdr); |
| 91 | 91 | |
| 92 | | − if (drv_data < 0) |
| 93 | | − return -EINVAL; |
| 94 | | − |
| 95 | | − ucmdlen = (drv_data < sizeof(ucmd)) ? |
| 96 | | − drv_data : sizeof(ucmd); |
| 92 | + ucmdlen = min(udata->inlen, sizeof(ucmd)); |
| 97 | 93 | |
| 98 | 94 | if (ib_copy_from_udata(&ucmd, udata, ucmdlen)) { |
| 99 | 95 | mlx5_ib_dbg(dev, "failed copy udata\n"); |
| @@ -103,15 +99,17 @@ static int create_srq_user(struct ib_pd *pd, struct mlx5_ib_srq *srq, · 3 unmodified lines |
| 103 | 99 | if (ucmd.reserved0 || ucmd.reserved1) |
| 104 | 100 | return -EINVAL; |
| 105 | 101 | |
| 106 | | − if (drv_data > sizeof(ucmd) && |
| 102 | + if (udata->inlen > sizeof(ucmd) && |
| 107 | 103 | !ib_is_udata_cleared(udata, sizeof(ucmd), |
| 108 | | − drv_data - sizeof(ucmd))) |
| 104 | + udata->inlen - sizeof(ucmd))) |
| 109 | 105 | return -EINVAL; |
| 110 | 106 | |
| 111 | | − err = get_srq_user_index(to_mucontext(pd->uobject->context), |
| 112 | | − &ucmd, udata->inlen, &uidx); |
| 113 | | − if (err) |
| 114 | | − return err; |
| 107 | + if (is_xrc) { |
| 108 | + err = get_srq_user_index(to_mucontext(pd->uobject->context), |
| 109 | + &ucmd, udata->inlen, &uidx); |
| 110 | + if (err) |
| 111 | + return err; |
| 112 | + } |
| 115 | 113 | |
| 116 | 114 | srq->wq_sig = !!(ucmd.flags & MLX5_SRQ_FLAG_SIGNATURE); |
| 117 | 115 | |
| @@ -151,7 +149,8 @@ static int create_srq_user(struct ib_pd *pd, struct mlx5_ib_srq *srq, · 33 unmodified lines |
| 151 | 149 | (*in)->ctx.log_pg_sz = page_shift - MLX5_ADAPTER_PAGE_SHIFT; |
| 152 | 150 | (*in)->ctx.pgoff_cqn = cpu_to_be32(offset << 26); |
| 153 | 151 | |
| 154 | | − if (MLX5_CAP_GEN(dev->mdev, cqe_version) == MLX5_CQE_VERSION_V1) { |
| 152 | + if ((MLX5_CAP_GEN(dev->mdev, cqe_version) == MLX5_CQE_VERSION_V1) && |
| 153 | + is_xrc){ |
| 155 | 154 | xsrqc = MLX5_ADDR_OF(create_xrc_srq_in, *in, |
| 156 | 155 | xrc_srq_context_entry); |
| 157 | 156 | MLX5_SET(xrc_srqc, xsrqc, user_index, uidx); |
| @@ -170,7 +169,7 @@ err_umem: · 12 unmodified lines |
| 170 | 169 | |
| 171 | 170 | static int create_srq_kernel(struct mlx5_ib_dev *dev, struct mlx5_ib_srq *srq, |
| 172 | 171 | struct mlx5_create_srq_mbox_in **in, int buf_size, |
| 173 | | − int *inlen) |
| 172 | + int *inlen, int is_xrc) |
| 174 | 173 | { |
| 175 | 174 | int err; |
| 176 | 175 | int i; |
| @@ -224,7 +223,8 @@ static int create_srq_kernel(struct mlx5_ib_dev *dev, struct mlx5_ib_srq *srq, · 47 unmodified lines |
| 224 | 223 | |
| 225 | 224 | (*in)->ctx.log_pg_sz = page_shift - MLX5_ADAPTER_PAGE_SHIFT; |
| 226 | 225 | |
| 227 | | − if (MLX5_CAP_GEN(dev->mdev, cqe_version) == MLX5_CQE_VERSION_V1) { |
| 226 | + if ((MLX5_CAP_GEN(dev->mdev, cqe_version) == MLX5_CQE_VERSION_V1) && |
| 227 | + is_xrc){ |
| 228 | 228 | xsrqc = MLX5_ADDR_OF(create_xrc_srq_in, *in, |
| 229 | 229 | xrc_srq_context_entry); |
| 230 | 230 | /* 0xffffff means we ask to work with cqe version 0 */ |
| @@ -302,10 +302,14 @@ struct ib_srq *mlx5_ib_create_srq(struct ib_pd *pd, · 71 unmodified lines |
| 302 | 302 | desc_size, init_attr->attr.max_wr, srq->msrq.max, srq->msrq.max_gs, |
| 303 | 303 | srq->msrq.max_avail_gather); |
| 304 | 304 | |
| 305 | + is_xrc = (init_attr->srq_type == IB_SRQT_XRC); |
| 306 | + |
| 305 | 307 | if (pd->uobject) |
| 306 | | − err = create_srq_user(pd, srq, &in, udata, buf_size, &inlen); |
| 308 | + err = create_srq_user(pd, srq, &in, udata, buf_size, &inlen, |
| 309 | + is_xrc); |
| 307 | 310 | else |
| 308 | | − err = create_srq_kernel(dev, srq, &in, buf_size, &inlen); |
| 311 | + err = create_srq_kernel(dev, srq, &in, buf_size, &inlen, |
| 312 | + is_xrc); |
| 309 | 313 | |
| 310 | 314 | if (err) { |
| 311 | 315 | mlx5_ib_warn(dev, "create srq %s failed, err %d\n", |
| @@ -313,7 +317,6 @@ struct ib_srq *mlx5_ib_create_srq(struct ib_pd *pd, · 1 unmodified line |
| 313 | 317 | goto err_srq; |
| 314 | 318 | } |
| 315 | 319 | |
| 316 | | − is_xrc = (init_attr->srq_type == IB_SRQT_XRC); |
| 317 | 320 | in->ctx.state_log_sz = ilog2(srq->msrq.max); |
| 318 | 321 | flgs = ((srq->msrq.wqe_shift - 4) | (is_xrc << 5) | (srq->wq_sig << 7)) << 24; |
| 319 | 322 | xrcdn = 0; |