Commit 652caba5 authored by Jason Gunthorpe's avatar Jason Gunthorpe

RDMA: Check srq_type during create_srq

uverbs was blocking srq_types the driver doesn't support based on the
CREATE_XSRQ cmd_mask. Fix all drivers to check for supported srq_types
during create_srq and move CREATE_XSRQ to the core code.

Link: https://lore.kernel.org/r/5-v1-caa70ba3d1ab+1436e-ucmd_mask_jgg@nvidia.comSigned-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
parent 44ce37bc
...@@ -610,6 +610,7 @@ struct ib_device *_ib_alloc_device(size_t size) ...@@ -610,6 +610,7 @@ struct ib_device *_ib_alloc_device(size_t size)
BIT_ULL(IB_USER_VERBS_CMD_CREATE_CQ) | BIT_ULL(IB_USER_VERBS_CMD_CREATE_CQ) |
BIT_ULL(IB_USER_VERBS_CMD_CREATE_QP) | BIT_ULL(IB_USER_VERBS_CMD_CREATE_QP) |
BIT_ULL(IB_USER_VERBS_CMD_CREATE_SRQ) | BIT_ULL(IB_USER_VERBS_CMD_CREATE_SRQ) |
BIT_ULL(IB_USER_VERBS_CMD_CREATE_XSRQ) |
BIT_ULL(IB_USER_VERBS_CMD_DEALLOC_MW) | BIT_ULL(IB_USER_VERBS_CMD_DEALLOC_MW) |
BIT_ULL(IB_USER_VERBS_CMD_DEALLOC_PD) | BIT_ULL(IB_USER_VERBS_CMD_DEALLOC_PD) |
BIT_ULL(IB_USER_VERBS_CMD_DEREG_MR) | BIT_ULL(IB_USER_VERBS_CMD_DEREG_MR) |
......
...@@ -2680,6 +2680,9 @@ int c4iw_create_srq(struct ib_srq *ib_srq, struct ib_srq_init_attr *attrs, ...@@ -2680,6 +2680,9 @@ int c4iw_create_srq(struct ib_srq *ib_srq, struct ib_srq_init_attr *attrs,
int ret; int ret;
int wr_len; int wr_len;
if (attrs->srq_type != IB_SRQT_BASIC)
return -EOPNOTSUPP;
pr_debug("%s ib_pd %p\n", __func__, pd); pr_debug("%s ib_pd %p\n", __func__, pd);
php = to_c4iw_pd(pd); php = to_c4iw_pd(pd);
......
...@@ -288,6 +288,10 @@ int hns_roce_create_srq(struct ib_srq *ib_srq, ...@@ -288,6 +288,10 @@ int hns_roce_create_srq(struct ib_srq *ib_srq,
int ret; int ret;
u32 cqn; u32 cqn;
if (init_attr->srq_type != IB_SRQT_BASIC &&
init_attr->srq_type != IB_SRQT_XRC)
return -EOPNOTSUPP;
/* Check the actual SRQ wqe and SRQ sge num */ /* Check the actual SRQ wqe and SRQ sge num */
if (init_attr->attr.max_wr >= hr_dev->caps.max_srq_wrs || if (init_attr->attr.max_wr >= hr_dev->caps.max_srq_wrs ||
init_attr->attr.max_sge > hr_dev->caps.max_srq_sges) init_attr->attr.max_sge > hr_dev->caps.max_srq_sges)
......
...@@ -2657,9 +2657,6 @@ static void *mlx4_ib_add(struct mlx4_dev *dev) ...@@ -2657,9 +2657,6 @@ static void *mlx4_ib_add(struct mlx4_dev *dev)
ibdev->ib_dev.num_comp_vectors = dev->caps.num_comp_vectors; ibdev->ib_dev.num_comp_vectors = dev->caps.num_comp_vectors;
ibdev->ib_dev.dev.parent = &dev->persist->pdev->dev; ibdev->ib_dev.dev.parent = &dev->persist->pdev->dev;
ibdev->ib_dev.uverbs_cmd_mask |=
(1ull << IB_USER_VERBS_CMD_CREATE_XSRQ);
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_CQ) |
......
...@@ -86,6 +86,10 @@ int mlx4_ib_create_srq(struct ib_srq *ib_srq, ...@@ -86,6 +86,10 @@ int mlx4_ib_create_srq(struct ib_srq *ib_srq,
int err; int err;
int i; int i;
if (init_attr->srq_type != IB_SRQT_BASIC &&
init_attr->srq_type != IB_SRQT_XRC)
return -EOPNOTSUPP;
/* Sanity check SRQ size before proceeding */ /* Sanity check SRQ size before proceeding */
if (init_attr->attr.max_wr >= dev->dev->caps.max_srq_wqes || if (init_attr->attr.max_wr >= dev->dev->caps.max_srq_wqes ||
init_attr->attr.max_sge > dev->dev->caps.max_srq_sge) init_attr->attr.max_sge > dev->dev->caps.max_srq_sge)
......
...@@ -4141,8 +4141,7 @@ static int mlx5_ib_stage_caps_init(struct mlx5_ib_dev *dev) ...@@ -4141,8 +4141,7 @@ static int mlx5_ib_stage_caps_init(struct mlx5_ib_dev *dev)
dev->ib_dev.uverbs_cmd_mask |= dev->ib_dev.uverbs_cmd_mask |=
(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);
(1ull << IB_USER_VERBS_CMD_CREATE_XSRQ);
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_CQ) |
(1ull << IB_USER_VERBS_EX_CMD_CREATE_QP) | (1ull << IB_USER_VERBS_EX_CMD_CREATE_QP) |
......
...@@ -226,6 +226,11 @@ int mlx5_ib_create_srq(struct ib_srq *ib_srq, ...@@ -226,6 +226,11 @@ int mlx5_ib_create_srq(struct ib_srq *ib_srq,
struct mlx5_srq_attr in = {}; struct mlx5_srq_attr in = {};
__u32 max_srq_wqes = 1 << MLX5_CAP_GEN(dev->mdev, log_max_srq_sz); __u32 max_srq_wqes = 1 << MLX5_CAP_GEN(dev->mdev, log_max_srq_sz);
if (init_attr->srq_type != IB_SRQT_BASIC &&
init_attr->srq_type != IB_SRQT_XRC &&
init_attr->srq_type != IB_SRQT_TM)
return -EOPNOTSUPP;
/* Sanity check SRQ size before proceeding */ /* Sanity check SRQ size before proceeding */
if (init_attr->attr.max_wr >= max_srq_wqes) { if (init_attr->attr.max_wr >= max_srq_wqes) {
mlx5_ib_dbg(dev, "max_wr %d, cap %d\n", mlx5_ib_dbg(dev, "max_wr %d, cap %d\n",
......
...@@ -1770,6 +1770,9 @@ int ocrdma_create_srq(struct ib_srq *ibsrq, struct ib_srq_init_attr *init_attr, ...@@ -1770,6 +1770,9 @@ int ocrdma_create_srq(struct ib_srq *ibsrq, struct ib_srq_init_attr *init_attr,
struct ocrdma_dev *dev = get_ocrdma_dev(ibsrq->device); struct ocrdma_dev *dev = get_ocrdma_dev(ibsrq->device);
struct ocrdma_srq *srq = get_ocrdma_srq(ibsrq); struct ocrdma_srq *srq = get_ocrdma_srq(ibsrq);
if (init_attr->srq_type != IB_SRQT_BASIC)
return -EOPNOTSUPP;
if (init_attr->attr.max_sge > dev->attr.max_recv_sge) if (init_attr->attr.max_sge > dev->attr.max_recv_sge)
return -EINVAL; return -EINVAL;
if (init_attr->attr.max_wr > dev->attr.max_rqe) if (init_attr->attr.max_wr > dev->attr.max_rqe)
......
...@@ -188,9 +188,6 @@ static void qedr_roce_register_device(struct qedr_dev *dev) ...@@ -188,9 +188,6 @@ static void qedr_roce_register_device(struct qedr_dev *dev)
dev->ibdev.node_type = RDMA_NODE_IB_CA; dev->ibdev.node_type = RDMA_NODE_IB_CA;
ib_set_device_ops(&dev->ibdev, &qedr_roce_dev_ops); ib_set_device_ops(&dev->ibdev, &qedr_roce_dev_ops);
dev->ibdev.uverbs_cmd_mask |=
QEDR_UVERBS(CREATE_XSRQ);
} }
static const struct ib_device_ops qedr_dev_ops = { static const struct ib_device_ops qedr_dev_ops = {
......
...@@ -1546,6 +1546,10 @@ int qedr_create_srq(struct ib_srq *ibsrq, struct ib_srq_init_attr *init_attr, ...@@ -1546,6 +1546,10 @@ int qedr_create_srq(struct ib_srq *ibsrq, struct ib_srq_init_attr *init_attr,
"create SRQ called from %s (pd %p)\n", "create SRQ called from %s (pd %p)\n",
(udata) ? "User lib" : "kernel", pd); (udata) ? "User lib" : "kernel", pd);
if (init_attr->srq_type != IB_SRQT_BASIC &&
init_attr->srq_type != IB_SRQT_XRC)
return -EOPNOTSUPP;
rc = qedr_check_srq_params(dev, init_attr, udata); rc = qedr_check_srq_params(dev, init_attr, udata);
if (rc) if (rc)
return -EINVAL; return -EINVAL;
......
...@@ -121,7 +121,7 @@ int pvrdma_create_srq(struct ib_srq *ibsrq, struct ib_srq_init_attr *init_attr, ...@@ -121,7 +121,7 @@ int pvrdma_create_srq(struct ib_srq *ibsrq, struct ib_srq_init_attr *init_attr,
dev_warn(&dev->pdev->dev, dev_warn(&dev->pdev->dev,
"shared receive queue type %d not supported\n", "shared receive queue type %d not supported\n",
init_attr->srq_type); init_attr->srq_type);
return -EINVAL; return -EOPNOTSUPP;
} }
if (init_attr->attr.max_wr > dev->dsr->caps.max_srq_wr || if (init_attr->attr.max_wr > dev->dsr->caps.max_srq_wr ||
......
...@@ -265,6 +265,9 @@ static int rxe_create_srq(struct ib_srq *ibsrq, struct ib_srq_init_attr *init, ...@@ -265,6 +265,9 @@ static int rxe_create_srq(struct ib_srq *ibsrq, struct ib_srq_init_attr *init,
struct rxe_srq *srq = to_rsrq(ibsrq); struct rxe_srq *srq = to_rsrq(ibsrq);
struct rxe_create_srq_resp __user *uresp = NULL; struct rxe_create_srq_resp __user *uresp = NULL;
if (init->srq_type != IB_SRQT_BASIC)
return -EOPNOTSUPP;
if (udata) { if (udata) {
if (udata->outlen < sizeof(*uresp)) if (udata->outlen < sizeof(*uresp))
return -EINVAL; return -EINVAL;
......
...@@ -1555,6 +1555,9 @@ int siw_create_srq(struct ib_srq *base_srq, ...@@ -1555,6 +1555,9 @@ int siw_create_srq(struct ib_srq *base_srq,
base_ucontext); base_ucontext);
int rv; int rv;
if (init_attrs->srq_type != IB_SRQT_BASIC)
return -EOPNOTSUPP;
if (atomic_inc_return(&sdev->num_srq) > SIW_MAX_SRQ) { if (atomic_inc_return(&sdev->num_srq) > SIW_MAX_SRQ) {
siw_dbg_pd(base_srq->pd, "too many SRQ's\n"); siw_dbg_pd(base_srq->pd, "too many SRQ'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