[for-next v4 4/4] RDMA/ionic: Accept QP SQ and RQ rings as ioctl umem attributes
From: Abhijit Gangurde
Date: Thu Dec 03 2026 - 06:08:45 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() now pins a ring with ib_umem_get_attr_or_va().
The core resolves the descriptor, so the ring can be a virtual address
or a dma-buf and the driver does not look inside it. The qdesc address
is not used when the attribute is present. Without the attribute the
ring is pinned from the qdesc address, as before.
A ring passed in the attribute must be exactly the qdesc size, so the
page table given to the device covers the ring and nothing else. Any
other length is rejected with -EINVAL.
Access is 0, so the VA mapping direction stays DMA_TO_DEVICE. SRQ
creation passes no attribute bundle and still pins the qdesc address.
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 | 34 +++++++++++++------
1 file changed, 23 insertions(+), 11 deletions(-)
diff --git a/drivers/infiniband/hw/ionic/ionic_controlpath.c b/drivers/infiniband/hw/ionic/ionic_controlpath.c
index c3a47aa108e4..a2a191f2af78 100644
--- a/drivers/infiniband/hw/ionic/ionic_controlpath.c
+++ b/drivers/infiniband/hw/ionic/ionic_controlpath.c
@@ -2009,7 +2009,8 @@ static void ionic_qp_sq_destroy_cmb(struct ionic_ibdev *dev,
}
static int ionic_get_user_q_umem(struct ionic_ibdev *dev, struct ionic_qdesc *q,
- struct ib_umem **umem_out)
+ const struct uverbs_attr_bundle *attrs,
+ u16 attr_id, struct ib_umem **umem_out)
{
struct ib_umem *umem;
int rc;
@@ -2018,12 +2019,13 @@ static int ionic_get_user_q_umem(struct ionic_ibdev *dev, struct ionic_qdesc *q,
if (rc)
return rc;
- umem = ib_umem_get_va(&dev->ibdev, q->addr, q->size, 0);
+ umem = ib_umem_get_attr_or_va(&dev->ibdev, attrs, attr_id,
+ q->addr, q->size, 0);
if (IS_ERR(umem))
return PTR_ERR(umem);
- /* The ring is given to the device as whole pages */
- if (ib_umem_offset(umem)) {
+ /* The device is given whole pages, and only those of the ring */
+ if (umem->length != q->size || ib_umem_offset(umem)) {
ib_umem_release(umem);
return -EINVAL;
}
@@ -2035,7 +2037,8 @@ static int ionic_get_user_q_umem(struct ionic_ibdev *dev, struct ionic_qdesc *q,
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;
@@ -2079,7 +2082,9 @@ static int ionic_qp_sq_init(struct ionic_ibdev *dev, struct ionic_ctx *ctx,
return rc;
if (udata) {
- rc = ionic_get_user_q_umem(dev, sq, &qp->sq_umem);
+ rc = ionic_get_user_q_umem(dev, sq, attrs,
+ UVERBS_ATTR_CREATE_QP_SQ_BUF_UMEM,
+ &qp->sq_umem);
if (rc)
return rc;
@@ -2294,7 +2299,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;
@@ -2312,7 +2318,9 @@ static int ionic_rq_init(struct ionic_ibdev *dev, struct ionic_ctx *ctx,
return rc;
if (udata) {
- rc = ionic_get_user_q_umem(dev, qdesc, &rq->umem);
+ rc = ionic_get_user_q_umem(dev, qdesc, attrs,
+ UVERBS_ATTR_CREATE_QP_RQ_BUF_UMEM,
+ &rq->umem);
if (rc)
return rc;
@@ -2410,6 +2418,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;
@@ -2418,6 +2427,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;
@@ -2496,7 +2507,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;
@@ -2515,7 +2527,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;
@@ -3122,7 +3134,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