Skip to contentSkip to conversation

RDMA/ionic: Accept CQ, SQ, and RQ rings as umem attributes

PATCH Superseded Abhijit Gangurde 2 participants 5 messages Nov 26

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Abhijit Gangurde

author maintainer
#0 lore raw

v2 cover RDMA/ionic: Accept CQ, SQ, and RQ rings as umem attributes

Let userspace hand ionic queue rings to create_cq and create_qp as struct ib_uverbs_buffer_desc, instead of only as a raw address in the driver request. A ring may be a virtual address or a page-aligned slice of a dma-buf, so several rings can share one dma-buf.

The get_context bit IONIC_CTX_CMASK_CQ_QP_BUF_UMEM tells userspace it may send the descriptors. ionic_cq_req and ionic_qp_req are unchanged, so a provider that does not send them still uses the existing write path and ib_umem_get_va.

Userspace: https://github.com/linux-rdma/rdma-core/pull/1862

v2:
- Fix sashiko reported comments
- New patch 1: bound depth/stride shift counts
- Reject non-zero qdesc addr for dma-buf
- QP: pin validated descriptor copy
v1:
https://lore.kernel.org/linux-rdma/[email protected]/

Abhijit Gangurde (3):
RDMA/ionic: Bound user queue depth and stride before shifting RDMA/ionic: Accept CQ ring buffers as ioctl umem attributes RDMA/ionic: Accept QP SQ and RQ rings as ioctl umem attributes

 drivers/infiniband/hw/ionic/ionic_admin.c     |   2 +-
 .../infiniband/hw/ionic/ionic_controlpath.c   | 200 +++++++++++++++---
 drivers/infiniband/hw/ionic/ionic_ibdev.c     |  17 ++
 drivers/infiniband/hw/ionic/ionic_ibdev.h     |   2 +
 include/uapi/rdma/ionic-abi.h                 |   1 +
 include/uapi/rdma/ionic_user_ioctl_cmds.h     |  15 ++
 6 files changed, 203 insertions(+), 34 deletions(-)
 create mode 100644 include/uapi/rdma/ionic_user_ioctl_cmds.h
Signature · 1 line
2.43.0
author maintainer
#1 lore raw

PATCH v2 1/3 RDMA/ionic: Bound user queue depth and stride before shifting

ionic_validate_qdesc() uses depth_log2 and stride_log2 from the user request as shift counts without an upper bound. Both are u8, so BIT(depth_log2) and BIT_ULL(depth_log2 + stride_log2) can shift by the width of the type or more, which is undefined behaviour.

Where the shift count wraps, as on x86-64, the size check can be bypassed. With depth_log2 = 4, mask = 15 and stride_log2 = 60, the required size BIT_ULL(64) evaluates to 1, so a one page ring passes validation with a depth and stride it cannot hold.

Reject a depth_log2 above order_base_2(IONIC_MAX_DEPTH), and a depth_log2 + stride_log2 of BITS_PER_LONG_LONG or more, before either shift.

Fixes f3bdbd42702c ("RDMA/ionic: Create device queues to support admin operations")
---
 drivers/infiniband/hw/ionic/ionic_controlpath.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/infiniband/hw/ionic/ionic_controlpath.c +7 -0
index 8a0a1575a339..8a304d576852 100644
@@ -23,6 +23,13 @@ static int ionic_validate_qdesc(struct ionic_qdesc *q)
 	if (q->addr & (PAGE_SIZE - 1))
 		return -EINVAL;
 
+	/* Keep the shift counts below within the width of their types */
+	if (q->depth_log2 > order_base_2(IONIC_MAX_DEPTH))
+		return -EINVAL;
+
+	if (q->depth_log2 + q->stride_log2 >= BITS_PER_LONG_LONG)
+		return -EINVAL;
+
 	if (q->mask != BIT(q->depth_log2) - 1)
 		return -EINVAL;
 
Signature · 1 line
2.43.0
author maintainer
#2 lore raw

PATCH v2 2/3 RDMA/ionic: Accept CQ ring buffers as ioctl umem attributes

In reply to Abhijit Gangurde

Userspace can now pass each enabled CQ ring to create_cq as a struct ib_uverbs_buffer_desc in a per-UDMA driver attribute, instead of only as a raw address in ionic_cq_req.

Advertise support with IONIC_CTX_CMASK_CQ_QP_BUF_UMEM in the get_context response. Register two optional UVERBS_ATTR_UMEM attributes, IONIC_IB_ATTR_CREATE_CQ_BUF_UMEM_0 and _1, on UVERBS_METHOD_CQ_CREATE through ibdev->driver_def.

For each UDMA index in udma_mask, ionic_cq_get_user_umem() validates the qdesc and resolves the ring buffer:

- No attribute: pin req_cq->addr as before, with DMA_FROM_DEVICE.
- VA descriptor: desc.addr must equal req_cq->addr; pin as before.
- DMABUF descriptor: the descriptor locates the ring, so req_cq->addr must be zero. desc.addr is a page-aligned dma-buf offset; pin req_cq->size bytes from desc.fd at that offset.

A dma-buf ring has no qdesc address, so split the queue geometry checks out of ionic_validate_qdesc() into ionic_validate_qdesc_geom() and apply only those to a DMABUF descriptor. The other two cases keep the address check.

An attribute for a UDMA index that is not in udma_mask, or any other buffer type, is rejected with -EINVAL. The kernel admin CQ path passes no attribute bundle and is unchanged.

ionic_cq_req and ionic_cq_resp are not changed, so older providers continue to use the write command path.

---
 drivers/infiniband/hw/ionic/ionic_admin.c     |   2 +-
 .../infiniband/hw/ionic/ionic_controlpath.c   | 116 +++++++++++++++---
 drivers/infiniband/hw/ionic/ionic_ibdev.c     |  17 +++
 drivers/infiniband/hw/ionic/ionic_ibdev.h     |   2 +
 include/uapi/rdma/ionic-abi.h                 |   1 +
 include/uapi/rdma/ionic_user_ioctl_cmds.h     |  15 +++
 6 files changed, 132 insertions(+), 21 deletions(-)
 create mode 100644 include/uapi/rdma/ionic_user_ioctl_cmds.h
drivers/infiniband/hw/ionic/ionic_admin.c +1 -1
index 0ccd869ad8e6..67ce56acb4dc 100644
@@ -575,7 +575,7 @@ static struct ionic_vcq *ionic_create_rdma_admincq(struct ionic_ibdev *dev,
 	vcq->udma_mask = 1;
 	cq = &vcq->cq[0];
 
-	rc = ionic_create_cq_common(vcq, &buf, &attr, NULL, NULL,
+	rc = ionic_create_cq_common(vcq, &buf, &attr, NULL, NULL, NULL,
 				    NULL, 0);
 	if (rc)
 		goto err_init;
drivers/infiniband/hw/ionic/ionic_controlpath.c +96 -20

164 lines not on this page · raw message

drivers/infiniband/hw/ionic/ionic_ibdev.c +17 -0
index b4d4544bb7ac..e64c8e891f30 100644
@@ -11,6 +11,9 @@
 
 #include "ionic_ibdev.h"
 
+#define UVERBS_MODULE_NAME ionic_rdma
+#include <rdma/uverbs_named_ioctl.h>
+
 #define DRIVER_DESCRIPTION "AMD Pensando RoCE HCA driver"
 #define DEVICE_DESCRIPTION "AMD Pensando RoCE HCA"
 
@@ -217,6 +220,18 @@ static void ionic_disassociate_ucontext(struct ib_ucontext *ibcontext)
 	 */
 }
 
+ADD_UVERBS_ATTRIBUTES_SIMPLE(
+	ionic_cq_create,
+	UVERBS_OBJECT_CQ,
+	UVERBS_METHOD_CQ_CREATE,
+	UVERBS_ATTR_UMEM(IONIC_IB_ATTR_CREATE_CQ_BUF_UMEM_0, UA_OPTIONAL),
+	UVERBS_ATTR_UMEM(IONIC_IB_ATTR_CREATE_CQ_BUF_UMEM_1, UA_OPTIONAL));
+
+static const struct uapi_definition ionic_uapi_defs[] = {
+	UAPI_DEF_CHAIN_OBJ_TREE(UVERBS_OBJECT_CQ, &ionic_cq_create),
+	{},
+};
+
 static const struct ib_device_ops ionic_dev_ops = {
 	.owner = THIS_MODULE,
 	.driver_id = RDMA_DRIVER_IONIC,
@@ -376,6 +391,8 @@ static struct ionic_ibdev *ionic_create_ibdev(struct ionic_aux_dev *ionic_adev)
 
 	ionic_stats_init(dev);
 
+	ibdev->driver_def = ionic_uapi_defs;
+
 	rc = ib_register_device(ibdev, "ionic_%d", ibdev->dev.parent);
 	if (rc)
 		goto err_register;
drivers/infiniband/hw/ionic/ionic_ibdev.h +2 -0
index 127b79cdfc45..b25fe2f6c4b1 100644
@@ -10,6 +10,7 @@
 #include <rdma/uverbs_ioctl.h>
 
 #include <rdma/ionic-abi.h>
+#include <rdma/ionic_user_ioctl_cmds.h>
 #include <ionic_api.h>
 #include <ionic_regs.h>
 
@@ -491,6 +492,7 @@ int ionic_create_cq_common(struct ionic_vcq *vcq,
 			   const struct ib_cq_init_attr *attr,
 			   struct ionic_ctx *ctx,
 			   struct ib_udata *udata,
+			   const struct uverbs_attr_bundle *attrs,
 			   struct ionic_qdesc *req_cq,
 			   int udma_idx);
 int ionic_post_create_cq_cmd(struct ionic_cq *cq,
include/uapi/rdma/ionic-abi.h +1 -0
index ac48fcd19a4f..f503552bf23a 100644
@@ -24,6 +24,7 @@
 
 enum ionic_ctx_resp_comp_mask {
 	IONIC_CTX_CMASK_IONIC_FLAGS = 1 << 0,
+	IONIC_CTX_CMASK_CQ_QP_BUF_UMEM = 1 << 1,
 };
 
 struct ionic_ctx_req {
include/uapi/rdma/ionic_user_ioctl_cmds.h new file +15 -0
new file mode 100644
index 000000000000..98bb8d7238e6
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/* Copyright (C) 2026, Advanced Micro Devices, Inc */
+
+#ifndef IONIC_USER_IOCTL_CMDS_H
+#define IONIC_USER_IOCTL_CMDS_H
+
+#include <linux/types.h>
+#include <rdma/ib_user_ioctl_cmds.h>
+
+enum ionic_ib_create_cq_attrs {
+	IONIC_IB_ATTR_CREATE_CQ_BUF_UMEM_0 = UVERBS_ID_DRIVER_NS_WITH_UHW,
+	IONIC_IB_ATTR_CREATE_CQ_BUF_UMEM_1,
+};
+
+#endif
Signature · 1 line
2.43.0
author maintainer
#3 lore raw

PATCH v2 3/3 RDMA/ionic: Accept QP SQ and RQ rings as ioctl umem attributes

In reply to Abhijit Gangurde

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.

---
 .../infiniband/hw/ionic/ionic_controlpath.c   | 81 +++++++++++++++----
 1 file changed, 66 insertions(+), 15 deletions(-)
drivers/infiniband/hw/ionic/ionic_controlpath.c +66 -15
index bb27e7700553..a197aff8fee5 100644
@@ -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;
 
Signature · 1 line
2.43.0