Message ID | 7-v1-caa70ba3d1ab+1436e-ucmd_mask_jgg@nvidia.com (mailing list archive) |
---|---|
State | Accepted |
Delegated to: | Jason Gunthorpe |
Headers | show |
Series | Reduce uverbs_cmd_mask and remove uverbs_ex_cmd_mask | expand |
> Subject: [PATCH 07/11] RDMA: Check flags during create_cq > > Each driver should check that the CQ attrs is supported. Unfortuantely when flags > was added to the CQ attrs the drivers were not updated, uverbs_ex_cmd_mask > was used to block it. This was missed when create CQ was converted to ioctl, so > non-zero flags could have been passed into drivers. > > Check that flags is zero in all drivers that don't use it, remove > IB_USER_VERBS_EX_CMD_CREATE_CQ from uverbs_ex_cmd_mask. > > Fixes: 41b2a71fc848 ("IB/uverbs: Move ioctl path of create_cq and destroy_cq to > a new file") > Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> > --- > drivers/infiniband/core/device.c | 1 + > drivers/infiniband/hw/bnxt_re/ib_verbs.c | 3 +++ > drivers/infiniband/hw/cxgb4/cq.c | 2 +- > drivers/infiniband/hw/efa/efa_verbs.c | 3 +++ > drivers/infiniband/hw/hns/hns_roce_cq.c | 3 +++ > drivers/infiniband/hw/i40iw/i40iw_verbs.c | 3 +++ > drivers/infiniband/hw/mlx4/main.c | 1 - > drivers/infiniband/hw/mlx5/main.c | 1 - > drivers/infiniband/hw/mthca/mthca_provider.c | 2 +- > drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 2 +- > drivers/infiniband/hw/qedr/verbs.c | 3 +++ > drivers/infiniband/hw/usnic/usnic_ib_verbs.c | 2 +- > drivers/infiniband/hw/vmw_pvrdma/pvrdma_cq.c | 3 +++ > drivers/infiniband/sw/rdmavt/cq.c | 2 +- > drivers/infiniband/sw/rxe/rxe_verbs.c | 2 +- > drivers/infiniband/sw/siw/siw_verbs.c | 3 +++ > 16 files changed, 28 insertions(+), 8 deletions(-) > [...] > a/drivers/infiniband/hw/i40iw/i40iw_verbs.c > b/drivers/infiniband/hw/i40iw/i40iw_verbs.c > index 26a61af2d3977f..4aade66ad2aea8 100644 > --- a/drivers/infiniband/hw/i40iw/i40iw_verbs.c > +++ b/drivers/infiniband/hw/i40iw/i40iw_verbs.c > @@ -1107,6 +1107,9 @@ static int i40iw_create_cq(struct ib_cq *ibcq, > int err_code; > int entries = attr->cqe; > > + if (attr->flags) > + return -EOPNOTSUPP; > + I am slightly confused. So these flags are set for drivers that support the extended create CQ API? Shiraz
On Tue, Oct 06, 2020 at 06:04:29PM +0000, Saleem, Shiraz wrote: > > a/drivers/infiniband/hw/i40iw/i40iw_verbs.c > > b/drivers/infiniband/hw/i40iw/i40iw_verbs.c > > index 26a61af2d3977f..4aade66ad2aea8 100644 > > +++ b/drivers/infiniband/hw/i40iw/i40iw_verbs.c > > @@ -1107,6 +1107,9 @@ static int i40iw_create_cq(struct ib_cq *ibcq, > > int err_code; > > int entries = attr->cqe; > > > > + if (attr->flags) > > + return -EOPNOTSUPP; > > + > > I am slightly confused. > So these flags are set for drivers that support the extended create CQ API? No, the flags can be set by any user or kernel program creating a CQ. The driver must ensure it supports all requested flags. Omitting the flags check was always a mistake because an in-kernel ULP could attempt to use them - luckily none due today. Jason
> Subject: Re: [PATCH 07/11] RDMA: Check flags during create_cq > > On Tue, Oct 06, 2020 at 06:04:29PM +0000, Saleem, Shiraz wrote: > > > a/drivers/infiniband/hw/i40iw/i40iw_verbs.c > > > b/drivers/infiniband/hw/i40iw/i40iw_verbs.c > > > index 26a61af2d3977f..4aade66ad2aea8 100644 > > > +++ b/drivers/infiniband/hw/i40iw/i40iw_verbs.c > > > @@ -1107,6 +1107,9 @@ static int i40iw_create_cq(struct ib_cq *ibcq, > > > int err_code; > > > int entries = attr->cqe; > > > > > > + if (attr->flags) > > > + return -EOPNOTSUPP; > > > + > > > > I am slightly confused. > > So these flags are set for drivers that support the extended create CQ API? > > No, the flags can be set by any user or kernel program creating a CQ. The driver > must ensure it supports all requested flags. > > Omitting the flags check was always a mistake because an in-kernel ULP could > attempt to use them - luckily none due today. > OK. Makes sense now. Thanks!
diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c index 44c3c3ecb9d6a6..0a888574674281 100644 --- a/drivers/infiniband/core/device.c +++ b/drivers/infiniband/core/device.c @@ -632,6 +632,7 @@ struct ib_device *_ib_alloc_device(size_t size) BIT_ULL(IB_USER_VERBS_CMD_RESIZE_CQ); device->uverbs_ex_cmd_mask = + BIT_ULL(IB_USER_VERBS_EX_CMD_CREATE_CQ) | BIT_ULL(IB_USER_VERBS_EX_CMD_CREATE_FLOW) | BIT_ULL(IB_USER_VERBS_EX_CMD_CREATE_RWQ_IND_TBL) | BIT_ULL(IB_USER_VERBS_EX_CMD_CREATE_WQ) | diff --git a/drivers/infiniband/hw/bnxt_re/ib_verbs.c b/drivers/infiniband/hw/bnxt_re/ib_verbs.c index 580cf541e225dc..6263885ff61d57 100644 --- a/drivers/infiniband/hw/bnxt_re/ib_verbs.c +++ b/drivers/infiniband/hw/bnxt_re/ib_verbs.c @@ -2837,6 +2837,9 @@ int bnxt_re_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, struct bnxt_qplib_nq *nq = NULL; unsigned int nq_alloc_cnt; + if (attr->flags) + return -EOPNOTSUPP; + /* Validate CQ fields */ if (cqe < 1 || cqe > dev_attr->max_cq_wqes) { ibdev_err(&rdev->ibdev, "Failed to create CQ -max exceeded"); diff --git a/drivers/infiniband/hw/cxgb4/cq.c b/drivers/infiniband/hw/cxgb4/cq.c index 28349ed5088540..2cb65be24770f1 100644 --- a/drivers/infiniband/hw/cxgb4/cq.c +++ b/drivers/infiniband/hw/cxgb4/cq.c @@ -1006,7 +1006,7 @@ int c4iw_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, pr_debug("ib_dev %p entries %d\n", ibdev, entries); if (attr->flags) - return -EINVAL; + return -EOPNOTSUPP; if (vector >= rhp->rdev.lldi.nciq) return -EINVAL; diff --git a/drivers/infiniband/hw/efa/efa_verbs.c b/drivers/infiniband/hw/efa/efa_verbs.c index e3d9a5a5f4d992..2fe5708b2d9d8c 100644 --- a/drivers/infiniband/hw/efa/efa_verbs.c +++ b/drivers/infiniband/hw/efa/efa_verbs.c @@ -1032,6 +1032,9 @@ int efa_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, ibdev_dbg(ibdev, "create_cq entries %d\n", entries); + if (attr->flags) + return -EOPNOTSUPP; + if (entries < 1 || entries > dev->dev_attr.max_cq_depth) { ibdev_dbg(ibdev, "cq: requested entries[%u] non-positive or greater than max[%u]\n", diff --git a/drivers/infiniband/hw/hns/hns_roce_cq.c b/drivers/infiniband/hw/hns/hns_roce_cq.c index 809b22aa5056c4..68f355fba425b5 100644 --- a/drivers/infiniband/hw/hns/hns_roce_cq.c +++ b/drivers/infiniband/hw/hns/hns_roce_cq.c @@ -251,6 +251,9 @@ int hns_roce_create_cq(struct ib_cq *ib_cq, const struct ib_cq_init_attr *attr, u32 cq_entries = attr->cqe; int ret; + if (attr->flags) + return -EOPNOTSUPP; + if (cq_entries < 1 || cq_entries > hr_dev->caps.max_cqes) { ibdev_err(ibdev, "Failed to check CQ count %d max=%d\n", cq_entries, hr_dev->caps.max_cqes); diff --git a/drivers/infiniband/hw/i40iw/i40iw_verbs.c b/drivers/infiniband/hw/i40iw/i40iw_verbs.c index 26a61af2d3977f..4aade66ad2aea8 100644 --- a/drivers/infiniband/hw/i40iw/i40iw_verbs.c +++ b/drivers/infiniband/hw/i40iw/i40iw_verbs.c @@ -1107,6 +1107,9 @@ static int i40iw_create_cq(struct ib_cq *ibcq, int err_code; int entries = attr->cqe; + if (attr->flags) + return -EOPNOTSUPP; + if (iwdev->closing) return -ENODEV; diff --git a/drivers/infiniband/hw/mlx4/main.c b/drivers/infiniband/hw/mlx4/main.c index 6216dfe6e9c79c..a6ae21721b124a 100644 --- a/drivers/infiniband/hw/mlx4/main.c +++ b/drivers/infiniband/hw/mlx4/main.c @@ -2659,7 +2659,6 @@ static void *mlx4_ib_add(struct mlx4_dev *dev) ib_set_device_ops(&ibdev->ib_dev, &mlx4_ib_dev_ops); ibdev->ib_dev.uverbs_ex_cmd_mask |= - (1ull << IB_USER_VERBS_EX_CMD_CREATE_CQ) | (1ull << IB_USER_VERBS_EX_CMD_CREATE_QP); if ((dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_RSS) && diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c index 39950d5230c0af..9e2f6a7967a61b 100644 --- a/drivers/infiniband/hw/mlx5/main.c +++ b/drivers/infiniband/hw/mlx5/main.c @@ -4143,7 +4143,6 @@ static int mlx5_ib_stage_caps_init(struct mlx5_ib_dev *dev) (1ull << IB_USER_VERBS_CMD_CREATE_AH) | (1ull << IB_USER_VERBS_CMD_DESTROY_AH); dev->ib_dev.uverbs_ex_cmd_mask |= - (1ull << IB_USER_VERBS_EX_CMD_CREATE_CQ) | (1ull << IB_USER_VERBS_EX_CMD_CREATE_QP); if (MLX5_CAP_GEN(mdev, ipoib_enhanced_offloads) && diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c index a01898ac99e224..5e798a6f75d715 100644 --- a/drivers/infiniband/hw/mthca/mthca_provider.c +++ b/drivers/infiniband/hw/mthca/mthca_provider.c @@ -612,7 +612,7 @@ static int mthca_create_cq(struct ib_cq *ibcq, udata, struct mthca_ucontext, ibucontext); if (attr->flags) - return -EINVAL; + return -EOPNOTSUPP; if (entries < 1 || entries > to_mdev(ibdev)->limits.max_cqes) return -EINVAL; diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c index 244dd22d53efa7..29ec0a808a19d8 100644 --- a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c +++ b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c @@ -974,7 +974,7 @@ int ocrdma_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, struct ocrdma_create_cq_ureq ureq; if (attr->flags) - return -EINVAL; + return -EOPNOTSUPP; if (udata) { if (ib_copy_from_udata(&ureq, udata, sizeof(ureq))) diff --git a/drivers/infiniband/hw/qedr/verbs.c b/drivers/infiniband/hw/qedr/verbs.c index 34c07a18c2c218..80373170ce51f5 100644 --- a/drivers/infiniband/hw/qedr/verbs.c +++ b/drivers/infiniband/hw/qedr/verbs.c @@ -928,6 +928,9 @@ int qedr_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, "create_cq: called from %s. entries=%d, vector=%d\n", udata ? "User Lib" : "Kernel", entries, vector); + if (attr->flags) + return -EOPNOTSUPP; + if (entries > QEDR_MAX_CQES) { DP_ERR(dev, "create cq: the number of entries %d is too high. Must be equal or below %d.\n", diff --git a/drivers/infiniband/hw/usnic/usnic_ib_verbs.c b/drivers/infiniband/hw/usnic/usnic_ib_verbs.c index a89d5816685af6..d6708d1db73af2 100644 --- a/drivers/infiniband/hw/usnic/usnic_ib_verbs.c +++ b/drivers/infiniband/hw/usnic/usnic_ib_verbs.c @@ -584,7 +584,7 @@ int usnic_ib_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, struct ib_udata *udata) { if (attr->flags) - return -EINVAL; + return -EOPNOTSUPP; return 0; } diff --git a/drivers/infiniband/hw/vmw_pvrdma/pvrdma_cq.c b/drivers/infiniband/hw/vmw_pvrdma/pvrdma_cq.c index 319546a39a0d5c..a119ac3e103c8d 100644 --- a/drivers/infiniband/hw/vmw_pvrdma/pvrdma_cq.c +++ b/drivers/infiniband/hw/vmw_pvrdma/pvrdma_cq.c @@ -119,6 +119,9 @@ int pvrdma_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, BUILD_BUG_ON(sizeof(struct pvrdma_cqe) != 64); + if (attr->flags) + return -EOPNOTSUPP; + entries = roundup_pow_of_two(entries); if (entries < 1 || entries > dev->dsr->caps.max_cqe) return -EINVAL; diff --git a/drivers/infiniband/sw/rdmavt/cq.c b/drivers/infiniband/sw/rdmavt/cq.c index 19248be1409335..20cc0799ac4bc4 100644 --- a/drivers/infiniband/sw/rdmavt/cq.c +++ b/drivers/infiniband/sw/rdmavt/cq.c @@ -211,7 +211,7 @@ int rvt_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, int err; if (attr->flags) - return -EINVAL; + return -EOPNOTSUPP; if (entries < 1 || entries > rdi->dparms.props.max_cqe) return -EINVAL; diff --git a/drivers/infiniband/sw/rxe/rxe_verbs.c b/drivers/infiniband/sw/rxe/rxe_verbs.c index fa4a0dd2e08c00..7baa8f5cba813e 100644 --- a/drivers/infiniband/sw/rxe/rxe_verbs.c +++ b/drivers/infiniband/sw/rxe/rxe_verbs.c @@ -771,7 +771,7 @@ static int rxe_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, } if (attr->flags) - return -EINVAL; + return -EOPNOTSUPP; err = rxe_cq_chk_attr(rxe, NULL, attr->cqe, attr->comp_vector); if (err) diff --git a/drivers/infiniband/sw/siw/siw_verbs.c b/drivers/infiniband/sw/siw/siw_verbs.c index 947b8b1cbe9af6..bcea5c5ace2b6b 100644 --- a/drivers/infiniband/sw/siw/siw_verbs.c +++ b/drivers/infiniband/sw/siw/siw_verbs.c @@ -1097,6 +1097,9 @@ int siw_create_cq(struct ib_cq *base_cq, const struct ib_cq_init_attr *attr, struct siw_cq *cq = to_siw_cq(base_cq); int rv, size = attr->cqe; + if (attr->flags) + return -EOPNOTSUPP; + if (atomic_inc_return(&sdev->num_cq) > SIW_MAX_CQ) { siw_dbg(base_cq->device, "too many CQ's\n"); rv = -ENOMEM;
Each driver should check that the CQ attrs is supported. Unfortuantely when flags was added to the CQ attrs the drivers were not updated, uverbs_ex_cmd_mask was used to block it. This was missed when create CQ was converted to ioctl, so non-zero flags could have been passed into drivers. Check that flags is zero in all drivers that don't use it, remove IB_USER_VERBS_EX_CMD_CREATE_CQ from uverbs_ex_cmd_mask. Fixes: 41b2a71fc848 ("IB/uverbs: Move ioctl path of create_cq and destroy_cq to a new file") Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> --- drivers/infiniband/core/device.c | 1 + drivers/infiniband/hw/bnxt_re/ib_verbs.c | 3 +++ drivers/infiniband/hw/cxgb4/cq.c | 2 +- drivers/infiniband/hw/efa/efa_verbs.c | 3 +++ drivers/infiniband/hw/hns/hns_roce_cq.c | 3 +++ drivers/infiniband/hw/i40iw/i40iw_verbs.c | 3 +++ drivers/infiniband/hw/mlx4/main.c | 1 - drivers/infiniband/hw/mlx5/main.c | 1 - drivers/infiniband/hw/mthca/mthca_provider.c | 2 +- drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 2 +- drivers/infiniband/hw/qedr/verbs.c | 3 +++ drivers/infiniband/hw/usnic/usnic_ib_verbs.c | 2 +- drivers/infiniband/hw/vmw_pvrdma/pvrdma_cq.c | 3 +++ drivers/infiniband/sw/rdmavt/cq.c | 2 +- drivers/infiniband/sw/rxe/rxe_verbs.c | 2 +- drivers/infiniband/sw/siw/siw_verbs.c | 3 +++ 16 files changed, 28 insertions(+), 8 deletions(-)