RDMA/core: Validate integrity handover device cap
authorMax Gurtovoy <maxg@mellanox.com>
Tue, 11 Jun 2019 15:52:51 +0000 (18:52 +0300)
committerJason Gunthorpe <jgg@mellanox.com>
Mon, 24 Jun 2019 14:49:27 +0000 (11:49 -0300)
Protect the case that a ULP tries to allocate a QP with signature
enabled flag while the LLD doesn't support this feature.
While we're here, also move integrity_en attribute from mlx5_qp to
ib_qp as a preparation for adding new integrity API to the rw-API
(that is part of ib_core module).

Signed-off-by: Max Gurtovoy <maxg@mellanox.com>
Signed-off-by: Israel Rukshin <israelr@mellanox.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
drivers/infiniband/core/verbs.c
drivers/infiniband/hw/mlx5/mlx5_ib.h
drivers/infiniband/hw/mlx5/qp.c
include/rdma/ib_verbs.h

index 399c0d17b2b994da3a1a1bd2f351e6fd3f1049ba..4a04e94a72db586c5a94c866d3fecf3f7bf8ec7f 100644 (file)
@@ -1158,6 +1158,10 @@ struct ib_qp *ib_create_qp_user(struct ib_pd *pd,
            qp_init_attr->cap.max_recv_sge))
                return ERR_PTR(-EINVAL);
 
+       if ((qp_init_attr->create_flags & IB_QP_CREATE_INTEGRITY_EN) &&
+           !(device->attrs.device_cap_flags & IB_DEVICE_INTEGRITY_HANDOVER))
+               return ERR_PTR(-EINVAL);
+
        /*
         * If the callers is using the RDMA API calculate the resources
         * needed for the RDMA READ/WRITE operations.
@@ -1233,6 +1237,8 @@ struct ib_qp *ib_create_qp_user(struct ib_pd *pd,
        qp->max_write_sge = qp_init_attr->cap.max_send_sge;
        qp->max_read_sge = min_t(u32, qp_init_attr->cap.max_send_sge,
                                 device->attrs.max_sge_rd);
+       if (qp_init_attr->create_flags & IB_QP_CREATE_INTEGRITY_EN)
+               qp->integrity_en = true;
 
        return qp;
 
index 5999792b56985a89f9e102162e1c55203c578ce1..d418219e68c69f081e7d14bb77f0e9a8f846beb8 100644 (file)
@@ -431,8 +431,6 @@ struct mlx5_ib_qp {
 
        int                     create_type;
 
-       bool                    integrity_en;
-
        struct list_head        qps_list;
        struct list_head        cq_recv_list;
        struct list_head        cq_send_list;
index 879162da63e3f2cfd158e1dbaafd9376eafec5a9..d77a64c551ead0e90ede0a95f644d46459fc8daa 100644 (file)
@@ -496,9 +496,6 @@ static int calc_sq_size(struct mlx5_ib_dev *dev, struct ib_qp_init_attr *attr,
                              sizeof(struct mlx5_wqe_inline_seg);
        attr->cap.max_inline_data = qp->max_inline_data;
 
-       if (attr->create_flags & IB_QP_CREATE_INTEGRITY_EN)
-               qp->integrity_en = true;
-
        wq_size = roundup_pow_of_two(attr->cap.max_send_wr * wqe_size);
        qp->sq.wqe_cnt = wq_size / MLX5_SEND_WQE_BB;
        if (qp->sq.wqe_cnt > (1 << MLX5_CAP_GEN(dev->mdev, log_max_qp_sz))) {
@@ -4714,7 +4711,7 @@ static int set_pi_umr_wr(const struct ib_send_wr *send_wr,
 
        if (unlikely(send_wr->num_sge != 0) ||
            unlikely(wr->access & IB_ACCESS_REMOTE_ATOMIC) ||
-           unlikely(!sig_mr->sig) || unlikely(!qp->integrity_en) ||
+           unlikely(!sig_mr->sig) || unlikely(!qp->ibqp.integrity_en) ||
            unlikely(!sig_mr->sig->sig_status_checked))
                return -EINVAL;
 
@@ -4763,7 +4760,7 @@ static int set_sig_umr_wr(const struct ib_send_wr *send_wr,
 
        if (unlikely(wr->wr.num_sge != 1) ||
            unlikely(wr->access_flags & IB_ACCESS_REMOTE_ATOMIC) ||
-           unlikely(!sig_mr->sig) || unlikely(!qp->integrity_en) ||
+           unlikely(!sig_mr->sig) || unlikely(!qp->ibqp.integrity_en) ||
            unlikely(!sig_mr->sig->sig_status_checked))
                return -EINVAL;
 
index 6de0ea1aafc333cf596926d90d76cdb47efba829..14b5eab76ed8411650f255a1cd3fe6470fba4283 100644 (file)
@@ -1711,6 +1711,7 @@ struct ib_qp {
        struct ib_qp_security  *qp_sec;
        u8                      port;
 
+       bool                    integrity_en;
        /*
         * Implementation details of the RDMA core, don't use in drivers:
         */