Commit 1c407cb5 authored by Jason Gunthorpe's avatar Jason Gunthorpe

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: 41b2a71f ("IB/uverbs: Move ioctl path of create_cq and destroy_cq to a new file")
Link: https://lore.kernel.org/r/7-v1-caa70ba3d1ab+1436e-ucmd_mask_jgg@nvidia.comSigned-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
parent 26e990ba
...@@ -632,6 +632,7 @@ struct ib_device *_ib_alloc_device(size_t size) ...@@ -632,6 +632,7 @@ struct ib_device *_ib_alloc_device(size_t size)
BIT_ULL(IB_USER_VERBS_CMD_RESIZE_CQ); BIT_ULL(IB_USER_VERBS_CMD_RESIZE_CQ);
device->uverbs_ex_cmd_mask = 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_FLOW) |
BIT_ULL(IB_USER_VERBS_EX_CMD_CREATE_RWQ_IND_TBL) | BIT_ULL(IB_USER_VERBS_EX_CMD_CREATE_RWQ_IND_TBL) |
BIT_ULL(IB_USER_VERBS_EX_CMD_CREATE_WQ) | BIT_ULL(IB_USER_VERBS_EX_CMD_CREATE_WQ) |
......
...@@ -2831,6 +2831,9 @@ int bnxt_re_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, ...@@ -2831,6 +2831,9 @@ int bnxt_re_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,
struct bnxt_qplib_nq *nq = NULL; struct bnxt_qplib_nq *nq = NULL;
unsigned int nq_alloc_cnt; unsigned int nq_alloc_cnt;
if (attr->flags)
return -EOPNOTSUPP;
/* Validate CQ fields */ /* Validate CQ fields */
if (cqe < 1 || cqe > dev_attr->max_cq_wqes) { if (cqe < 1 || cqe > dev_attr->max_cq_wqes) {
ibdev_err(&rdev->ibdev, "Failed to create CQ -max exceeded"); ibdev_err(&rdev->ibdev, "Failed to create CQ -max exceeded");
......
...@@ -1006,7 +1006,7 @@ int c4iw_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, ...@@ -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); pr_debug("ib_dev %p entries %d\n", ibdev, entries);
if (attr->flags) if (attr->flags)
return -EINVAL; return -EOPNOTSUPP;
if (vector >= rhp->rdev.lldi.nciq) if (vector >= rhp->rdev.lldi.nciq)
return -EINVAL; return -EINVAL;
......
...@@ -1032,6 +1032,9 @@ int efa_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, ...@@ -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); ibdev_dbg(ibdev, "create_cq entries %d\n", entries);
if (attr->flags)
return -EOPNOTSUPP;
if (entries < 1 || entries > dev->dev_attr.max_cq_depth) { if (entries < 1 || entries > dev->dev_attr.max_cq_depth) {
ibdev_dbg(ibdev, ibdev_dbg(ibdev,
"cq: requested entries[%u] non-positive or greater than max[%u]\n", "cq: requested entries[%u] non-positive or greater than max[%u]\n",
......
...@@ -251,6 +251,9 @@ int hns_roce_create_cq(struct ib_cq *ib_cq, const struct ib_cq_init_attr *attr, ...@@ -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; u32 cq_entries = attr->cqe;
int ret; int ret;
if (attr->flags)
return -EOPNOTSUPP;
if (cq_entries < 1 || cq_entries > hr_dev->caps.max_cqes) { if (cq_entries < 1 || cq_entries > hr_dev->caps.max_cqes) {
ibdev_err(ibdev, "Failed to check CQ count %d max=%d\n", ibdev_err(ibdev, "Failed to check CQ count %d max=%d\n",
cq_entries, hr_dev->caps.max_cqes); cq_entries, hr_dev->caps.max_cqes);
......
...@@ -1107,6 +1107,9 @@ static int i40iw_create_cq(struct ib_cq *ibcq, ...@@ -1107,6 +1107,9 @@ static int i40iw_create_cq(struct ib_cq *ibcq,
int err_code; int err_code;
int entries = attr->cqe; int entries = attr->cqe;
if (attr->flags)
return -EOPNOTSUPP;
if (iwdev->closing) if (iwdev->closing)
return -ENODEV; return -ENODEV;
......
...@@ -2659,7 +2659,6 @@ static void *mlx4_ib_add(struct mlx4_dev *dev) ...@@ -2659,7 +2659,6 @@ static void *mlx4_ib_add(struct mlx4_dev *dev)
ib_set_device_ops(&ibdev->ib_dev, &mlx4_ib_dev_ops); ib_set_device_ops(&ibdev->ib_dev, &mlx4_ib_dev_ops);
ibdev->ib_dev.uverbs_ex_cmd_mask |= ibdev->ib_dev.uverbs_ex_cmd_mask |=
(1ull << IB_USER_VERBS_EX_CMD_CREATE_CQ) |
(1ull << IB_USER_VERBS_EX_CMD_CREATE_QP); (1ull << IB_USER_VERBS_EX_CMD_CREATE_QP);
if ((dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_RSS) && if ((dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_RSS) &&
......
...@@ -4143,7 +4143,6 @@ static int mlx5_ib_stage_caps_init(struct mlx5_ib_dev *dev) ...@@ -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_CREATE_AH) |
(1ull << IB_USER_VERBS_CMD_DESTROY_AH); (1ull << IB_USER_VERBS_CMD_DESTROY_AH);
dev->ib_dev.uverbs_ex_cmd_mask |= dev->ib_dev.uverbs_ex_cmd_mask |=
(1ull << IB_USER_VERBS_EX_CMD_CREATE_CQ) |
(1ull << IB_USER_VERBS_EX_CMD_CREATE_QP); (1ull << IB_USER_VERBS_EX_CMD_CREATE_QP);
if (MLX5_CAP_GEN(mdev, ipoib_enhanced_offloads) && if (MLX5_CAP_GEN(mdev, ipoib_enhanced_offloads) &&
......
...@@ -612,7 +612,7 @@ static int mthca_create_cq(struct ib_cq *ibcq, ...@@ -612,7 +612,7 @@ static int mthca_create_cq(struct ib_cq *ibcq,
udata, struct mthca_ucontext, ibucontext); udata, struct mthca_ucontext, ibucontext);
if (attr->flags) if (attr->flags)
return -EINVAL; return -EOPNOTSUPP;
if (entries < 1 || entries > to_mdev(ibdev)->limits.max_cqes) if (entries < 1 || entries > to_mdev(ibdev)->limits.max_cqes)
return -EINVAL; return -EINVAL;
......
...@@ -974,7 +974,7 @@ int ocrdma_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, ...@@ -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; struct ocrdma_create_cq_ureq ureq;
if (attr->flags) if (attr->flags)
return -EINVAL; return -EOPNOTSUPP;
if (udata) { if (udata) {
if (ib_copy_from_udata(&ureq, udata, sizeof(ureq))) if (ib_copy_from_udata(&ureq, udata, sizeof(ureq)))
......
...@@ -928,6 +928,9 @@ int qedr_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, ...@@ -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", "create_cq: called from %s. entries=%d, vector=%d\n",
udata ? "User Lib" : "Kernel", entries, vector); udata ? "User Lib" : "Kernel", entries, vector);
if (attr->flags)
return -EOPNOTSUPP;
if (entries > QEDR_MAX_CQES) { if (entries > QEDR_MAX_CQES) {
DP_ERR(dev, DP_ERR(dev,
"create cq: the number of entries %d is too high. Must be equal or below %d.\n", "create cq: the number of entries %d is too high. Must be equal or below %d.\n",
......
...@@ -584,7 +584,7 @@ int usnic_ib_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, ...@@ -584,7 +584,7 @@ int usnic_ib_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,
struct ib_udata *udata) struct ib_udata *udata)
{ {
if (attr->flags) if (attr->flags)
return -EINVAL; return -EOPNOTSUPP;
return 0; return 0;
} }
......
...@@ -119,6 +119,9 @@ int pvrdma_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, ...@@ -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); BUILD_BUG_ON(sizeof(struct pvrdma_cqe) != 64);
if (attr->flags)
return -EOPNOTSUPP;
entries = roundup_pow_of_two(entries); entries = roundup_pow_of_two(entries);
if (entries < 1 || entries > dev->dsr->caps.max_cqe) if (entries < 1 || entries > dev->dsr->caps.max_cqe)
return -EINVAL; return -EINVAL;
......
...@@ -211,7 +211,7 @@ int rvt_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, ...@@ -211,7 +211,7 @@ int rvt_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,
int err; int err;
if (attr->flags) if (attr->flags)
return -EINVAL; return -EOPNOTSUPP;
if (entries < 1 || entries > rdi->dparms.props.max_cqe) if (entries < 1 || entries > rdi->dparms.props.max_cqe)
return -EINVAL; return -EINVAL;
......
...@@ -771,7 +771,7 @@ static int rxe_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, ...@@ -771,7 +771,7 @@ static int rxe_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,
} }
if (attr->flags) if (attr->flags)
return -EINVAL; return -EOPNOTSUPP;
err = rxe_cq_chk_attr(rxe, NULL, attr->cqe, attr->comp_vector); err = rxe_cq_chk_attr(rxe, NULL, attr->cqe, attr->comp_vector);
if (err) if (err)
......
...@@ -1097,6 +1097,9 @@ int siw_create_cq(struct ib_cq *base_cq, const struct ib_cq_init_attr *attr, ...@@ -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); struct siw_cq *cq = to_siw_cq(base_cq);
int rv, size = attr->cqe; int rv, size = attr->cqe;
if (attr->flags)
return -EOPNOTSUPP;
if (atomic_inc_return(&sdev->num_cq) > SIW_MAX_CQ) { if (atomic_inc_return(&sdev->num_cq) > SIW_MAX_CQ) {
siw_dbg(base_cq->device, "too many CQ's\n"); siw_dbg(base_cq->device, "too many CQ's\n");
rv = -ENOMEM; rv = -ENOMEM;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment