]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
RDMA/bnxt_re: Use ib_umem_get_cq_buf_or_va() for user CQ buffer
authorJiri Pirko <jiri@nvidia.com>
Fri, 29 May 2026 13:43:05 +0000 (15:43 +0200)
committerJason Gunthorpe <jgg@nvidia.com>
Fri, 29 May 2026 23:19:58 +0000 (20:19 -0300)
Pin the user CQ buffer with ib_umem_get_cq_buf_or_va() and take
ownership of the umem in the driver. Apply the same ownership
pattern to the resize path.

Link: https://patch.msgid.link/r/20260529134312.2836341-10-jiri@resnulli.us
Signed-off-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
drivers/infiniband/hw/bnxt_re/ib_verbs.c
drivers/infiniband/hw/bnxt_re/ib_verbs.h

index 5e8fa7bf99cb09e7750e398ed770bd221e6783fe..c1c4ddc615e28655b4665d7009274f8848fa090e 100644 (file)
@@ -3455,6 +3455,7 @@ int bnxt_re_destroy_cq(struct ib_cq *ib_cq, struct ib_udata *udata)
 
        atomic_dec(&rdev->stats.res.cq_count);
        kfree(cq->cql);
+       ib_umem_release(cq->umem);
        return ib_respond_empty_udata(udata);
 }
 
@@ -3495,17 +3496,15 @@ int bnxt_re_create_user_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *att
                entries = bnxt_re_init_depth(attr->cqe + 1,
                                             dev_attr->max_cq_wqes + 1, uctx);
 
-       if (!ibcq->umem) {
-               ibcq->umem = ib_umem_get_va(&rdev->ibdev, req.cq_va,
+       cq->umem = ib_umem_get_cq_buf_or_va(&rdev->ibdev, attrs, req.cq_va,
                                            entries * sizeof(struct cq_base),
                                            IB_ACCESS_LOCAL_WRITE);
-               if (IS_ERR(ibcq->umem))
-                       return PTR_ERR(ibcq->umem);
-       }
+       if (IS_ERR(cq->umem))
+               return PTR_ERR(cq->umem);
 
-       rc = bnxt_re_setup_sginfo(rdev, ibcq->umem, &cq->qplib_cq.sg_info);
+       rc = bnxt_re_setup_sginfo(rdev, cq->umem, &cq->qplib_cq.sg_info);
        if (rc)
-               return rc;
+               goto free_umem;
 
        cq->qplib_cq.dpi = &uctx->dpi;
        cq->qplib_cq.max_wqe = entries;
@@ -3515,7 +3514,7 @@ int bnxt_re_create_user_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *att
 
        rc = bnxt_qplib_create_cq(&rdev->qplib_res, &cq->qplib_cq);
        if (rc)
-               return rc;
+               goto free_umem;
 
        cq->ib_cq.cqe = entries;
        cq->cq_period = cq->qplib_cq.period;
@@ -3528,8 +3527,10 @@ int bnxt_re_create_user_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *att
                hash_add(rdev->cq_hash, &cq->hash_entry, cq->qplib_cq.id);
                /* Allocate a page */
                cq->uctx_cq_page = (void *)get_zeroed_page(GFP_KERNEL);
-               if (!cq->uctx_cq_page)
-                       return -ENOMEM;
+               if (!cq->uctx_cq_page) {
+                       rc = -ENOMEM;
+                       goto destroy_cq;
+               }
 
                resp.comp_mask |= BNXT_RE_CQ_TOGGLE_PAGE_SUPPORT;
        }
@@ -3537,15 +3538,17 @@ int bnxt_re_create_user_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *att
        resp.tail = cq->qplib_cq.hwq.cons;
        resp.phase = cq->qplib_cq.period;
        rc = ib_respond_udata(udata, resp);
-       if (rc) {
-               bnxt_qplib_destroy_cq(&rdev->qplib_res, &cq->qplib_cq);
+       if (rc)
                goto free_mem;
-       }
 
        return 0;
 
 free_mem:
        free_page((unsigned long)cq->uctx_cq_page);
+destroy_cq:
+       bnxt_qplib_destroy_cq(&rdev->qplib_res, &cq->qplib_cq);
+free_umem:
+       ib_umem_release(cq->umem);
        return rc;
 }
 
@@ -3609,8 +3612,8 @@ static void bnxt_re_resize_cq_complete(struct bnxt_re_cq *cq)
 
        cq->qplib_cq.max_wqe = cq->resize_cqe;
        if (cq->resize_umem) {
-               ib_umem_release(cq->ib_cq.umem);
-               cq->ib_cq.umem = cq->resize_umem;
+               ib_umem_release(cq->umem);
+               cq->umem = cq->resize_umem;
                cq->resize_umem = NULL;
                cq->resize_cqe = 0;
        }
@@ -4206,7 +4209,7 @@ int bnxt_re_poll_cq(struct ib_cq *ib_cq, int num_entries, struct ib_wc *wc)
        /* User CQ; the only processing we do is to
         * complete any pending CQ resize operation.
         */
-       if (cq->ib_cq.umem) {
+       if (cq->umem) {
                if (cq->resize_umem)
                        bnxt_re_resize_cq_complete(cq);
                return 0;
index ebc393e6da4fd418dae5e94e91c3e0a9587d632b..4d6d1259a7956b2fdbdd1f7f8dbd627facc945fd 100644 (file)
@@ -109,6 +109,7 @@ struct bnxt_re_cq {
        struct bnxt_qplib_cqe   *cql;
 #define MAX_CQL_PER_POLL       1024
        u32                     max_cql;
+       struct ib_umem          *umem;
        struct ib_umem          *resize_umem;
        int                     resize_cqe;
        void                    *uctx_cq_page;