[for-next v2 3/3] RDMA/ionic: Accept QP SQ and RQ rings as ioctl umem attributes
From: Abhijit Gangurde
Date: Wed Nov 25 2026 - 23:49:22 EST
Userspace passes each QP ring to create_qp as a
struct ib_uverbs_buffer_desc on the core attributes
UVERBS_ATTR_CREATE_QP_SQ_BUF_UMEM and
UVERBS_ATTR_CREATE_QP_RQ_BUF_UMEM. Those attributes are already
optional on UVERBS_METHOD_QP_CREATE. The get_context bit
IONIC_CTX_CMASK_CQ_QP_BUF_UMEM tells userspace it may send them.
ionic_get_user_q_umem() resolves one ring:
- No attribute: validate the qdesc address and pin it with
ib_umem_get_va, as before.
- VA descriptor: length equals the qdesc size and the address matches
the qdesc.
- DMABUF descriptor: the descriptor locates the ring, so qdesc.addr
must be zero. Check queue geometry only and require a page-aligned
dma-buf offset.
Any other descriptor is -EINVAL. The descriptor is copied from
userspace once, and that validated copy is pinned with
ib_umem_get_desc(), so the checks apply to the buffer that is pinned.
Access is 0, so the VA mapping direction stays DMA_TO_DEVICE. SRQ
creation passes no attribute bundle and keeps ib_umem_get_va. An SRQ
QP still only checks that the RQ qdesc is zero.
ionic_qp_req is not changed, so a provider that does not send the
attributes still creates a QP on the write path.
Signed-off-by: Abhijit Gangurde <abhijit.gangurde@xxxxxxx>
---
.../infiniband/hw/ionic/ionic_controlpath.c | 81 +++++++++++++++----
1 file changed, 66 insertions(+), 15 deletions(-)
diff --git a/drivers/infiniband/hw/ionic/ionic_controlpath.c b/drivers/infiniband/hw/ionic/ionic_controlpath.c
index bb27e7700553..a197aff8fee5 100644
--- a/drivers/infiniband/hw/ionic/ionic_controlpath.c
+++ b/drivers/infiniband/hw/ionic/ionic_controlpath.c
@@ -2009,10 +2009,60 @@ static void ionic_qp_sq_destroy_cmb(struct ionic_ibdev *dev,
ionic_put_cmb(dev->lif_cfg.lif, qp->sq_cmb_pgid, qp->sq_cmb_order);
}
+static int ionic_get_user_q_umem(struct ionic_ibdev *dev, struct ionic_qdesc *q,
+ const struct uverbs_attr_bundle *attrs,
+ u16 attr_id, struct ib_umem **umem_out)
+{
+ struct ib_uverbs_buffer_desc desc;
+ struct ib_umem *umem;
+ int rc;
+
+ if (attrs && uverbs_attr_is_valid(attrs, attr_id)) {
+ rc = uverbs_get_buffer_desc(attrs, attr_id, &desc);
+ if (rc)
+ return rc;
+
+ if (desc.length != q->size)
+ return -EINVAL;
+
+ if (desc.type == IB_UVERBS_BUFFER_TYPE_DMABUF) {
+ /* The descriptor locates the ring, not the qdesc */
+ if (q->addr || !IS_ALIGNED(desc.addr, PAGE_SIZE))
+ return -EINVAL;
+
+ rc = ionic_validate_qdesc_geom(q);
+ } else if (desc.type == IB_UVERBS_BUFFER_TYPE_VA &&
+ desc.addr == q->addr) {
+ rc = ionic_validate_qdesc(q);
+ } else {
+ rc = -EINVAL;
+ }
+ if (rc)
+ return rc;
+
+ /* Pin the copy that was checked; the attribute is user memory
+ * and may have changed since.
+ */
+ umem = ib_umem_get_desc(&dev->ibdev, &desc, 0);
+ } else {
+ rc = ionic_validate_qdesc(q);
+ if (rc)
+ return rc;
+
+ umem = ib_umem_get_va(&dev->ibdev, q->addr, q->size, 0);
+ }
+ if (IS_ERR(umem))
+ return PTR_ERR(umem);
+
+ *umem_out = umem;
+ return 0;
+}
+
static int ionic_qp_sq_init(struct ionic_ibdev *dev, struct ionic_ctx *ctx,
struct ionic_qp *qp, struct ionic_qdesc *sq,
struct ionic_tbl_buf *buf, int max_wr, int max_sge,
- int max_data, int sq_spec, struct ib_udata *udata)
+ int max_data, int sq_spec, struct ib_udata *udata,
+ const struct uverbs_attr_bundle *attrs)
{
u32 wqe_size;
int rc = 0;
@@ -2056,7 +2106,9 @@ static int ionic_qp_sq_init(struct ionic_ibdev *dev, struct ionic_ctx *ctx,
return rc;
if (udata) {
- rc = ionic_validate_qdesc(sq);
+ rc = ionic_get_user_q_umem(dev, sq, attrs,
+ UVERBS_ATTR_CREATE_QP_SQ_BUF_UMEM,
+ &qp->sq_umem);
if (rc)
return rc;
@@ -2070,10 +2122,6 @@ static int ionic_qp_sq_init(struct ionic_ibdev *dev, struct ionic_ctx *ctx,
qp->sq_meta = NULL;
qp->sq_msn_idx = NULL;
-
- qp->sq_umem = ib_umem_get_va(&dev->ibdev, sq->addr, sq->size, 0);
- if (IS_ERR(qp->sq_umem))
- return PTR_ERR(qp->sq_umem);
} else {
qp->sq_umem = NULL;
@@ -2276,7 +2324,8 @@ static void ionic_rq_destroy_cmb(struct ionic_ibdev *dev,
static int ionic_rq_init(struct ionic_ibdev *dev, struct ionic_ctx *ctx,
struct ionic_rq *rq, struct ionic_qdesc *qdesc,
struct ionic_tbl_buf *buf, int max_wr, int max_sge,
- int rq_spec, struct ib_udata *udata)
+ int rq_spec, struct ib_udata *udata,
+ const struct uverbs_attr_bundle *attrs)
{
u32 wqe_size;
int rc = 0;
@@ -2294,7 +2343,9 @@ static int ionic_rq_init(struct ionic_ibdev *dev, struct ionic_ctx *ctx,
return rc;
if (udata) {
- rc = ionic_validate_qdesc(qdesc);
+ rc = ionic_get_user_q_umem(dev, qdesc, attrs,
+ UVERBS_ATTR_CREATE_QP_RQ_BUF_UMEM,
+ &rq->umem);
if (rc)
return rc;
@@ -2307,10 +2358,6 @@ static int ionic_rq_init(struct ionic_ibdev *dev, struct ionic_ctx *ctx,
rq->q.stride_log2 = qdesc->stride_log2;
rq->meta = NULL;
-
- rq->umem = ib_umem_get_va(&dev->ibdev, qdesc->addr, qdesc->size, 0);
- if (IS_ERR(rq->umem))
- return PTR_ERR(rq->umem);
} else {
rq->umem = NULL;
@@ -2396,6 +2443,7 @@ int ionic_create_qp(struct ib_qp *ibqp, struct ib_qp_init_attr *attr,
struct ionic_qp *qp = to_ionic_qp(ibqp);
struct ionic_ctx *ctx =
rdma_udata_to_drv_context(udata, struct ionic_ctx, ibctx);
+ const struct uverbs_attr_bundle *attrs = NULL;
struct ionic_qp_resp resp = {};
struct ionic_qp_req req = {};
struct ionic_cq *cq;
@@ -2404,6 +2452,8 @@ int ionic_create_qp(struct ib_qp *ibqp, struct ib_qp_init_attr *attr,
int rc;
if (udata) {
+ attrs = rdma_udata_to_uverbs_attr_bundle(udata);
+
rc = ib_copy_validate_udata_in(udata, req, rsvd);
if (rc)
return rc;
@@ -2482,7 +2532,8 @@ int ionic_create_qp(struct ib_qp *ibqp, struct ib_qp_init_attr *attr,
rc = ionic_qp_sq_init(dev, ctx, qp, &req.sq, &sq_buf,
attr->cap.max_send_wr, attr->cap.max_send_sge,
- attr->cap.max_inline_data, req.sq_spec, udata);
+ attr->cap.max_inline_data, req.sq_spec, udata,
+ attrs);
if (rc)
goto err_sq;
@@ -2501,7 +2552,7 @@ int ionic_create_qp(struct ib_qp *ibqp, struct ib_qp_init_attr *attr,
qp->rq.qid = qp->qpid;
rc = ionic_rq_init(dev, ctx, &qp->rq, &req.rq, &rq_buf,
attr->cap.max_recv_wr, attr->cap.max_recv_sge,
- req.rq_spec, udata);
+ req.rq_spec, udata, attrs);
}
if (rc)
goto err_rq;
@@ -3108,7 +3159,7 @@ int ionic_create_srq(struct ib_srq *ibsrq, struct ib_srq_init_attr *attr,
rc = ionic_rq_init(dev, ctx, &srq->rq, &req.rq, &buf,
attr->attr.max_wr, attr->attr.max_sge,
- req.rq_spec, udata);
+ req.rq_spec, udata, NULL);
if (rc)
return rc;
--
2.43.0