[for-next v4 2/4] RDMA/ionic: Check user ring alignment on the pinned umem

From: Abhijit Gangurde

Date: Thu Dec 03 2026 - 06:08:48 EST


ionic_validate_qdesc() rejects a user CQ, SQ or RQ ring when the
address in the request is zero or not page aligned. That only works
while the request address is the one place a ring can come from.

Check the pinned umem instead. Add ionic_cq_get_user_umem() and
ionic_get_user_q_umem(), which validate the queue geometry, pin the
ring and reject it with -EINVAL when ib_umem_offset() is not zero.
ionic_validate_qdesc() no longer looks at the address.

A ring that is not page aligned is still rejected with -EINVAL. A
zero address is no longer special-cased. Like any other unmapped
address, it fails with -EFAULT when the ring is pinned.

This prepares for rings passed as ioctl umem attributes, where the
buffer is described by the attribute and not by the request address.

Signed-off-by: Abhijit Gangurde <abhijit.gangurde@xxxxxxx>
---
.../infiniband/hw/ionic/ionic_controlpath.c | 79 +++++++++++++------
1 file changed, 54 insertions(+), 25 deletions(-)

diff --git a/drivers/infiniband/hw/ionic/ionic_controlpath.c b/drivers/infiniband/hw/ionic/ionic_controlpath.c
index 717ab78b603c..3abb8c01daf6 100644
--- a/drivers/infiniband/hw/ionic/ionic_controlpath.c
+++ b/drivers/infiniband/hw/ionic/ionic_controlpath.c
@@ -14,13 +14,9 @@
#define ionic_set_ecn(tos) (((tos) | 2u) & ~1u)
#define ionic_clear_ecn(tos) ((tos) & ~3u)

-static int ionic_validate_qdesc(struct ionic_qdesc *q)
+static int ionic_validate_qdesc(const struct ionic_qdesc *q)
{
- if (!q->addr || !q->size || !q->mask ||
- !q->depth_log2 || !q->stride_log2)
- return -EINVAL;
-
- if (q->addr & (PAGE_SIZE - 1))
+ if (!q->size || !q->mask || !q->depth_log2 || !q->stride_log2)
return -EINVAL;

/* Keep the shift counts below within the width of their types */
@@ -80,6 +76,31 @@ static void ionic_put_cqid(struct ionic_ibdev *dev, u32 cqid)
ionic_resid_put(&dev->inuse_cqid, bitid);
}

+static int ionic_cq_get_user_umem(struct ionic_ibdev *dev, struct ionic_cq *cq,
+ const struct ionic_qdesc *req_cq)
+{
+ struct ib_umem *umem;
+ int rc;
+
+ rc = ionic_validate_qdesc(req_cq);
+ if (rc)
+ return rc;
+
+ umem = ib_umem_get_cq_buf_or_va(&dev->ibdev, NULL, req_cq->addr,
+ req_cq->size, IB_ACCESS_LOCAL_WRITE);
+ if (IS_ERR(umem))
+ return PTR_ERR(umem);
+
+ /* The ring is given to the device as whole pages */
+ if (ib_umem_offset(umem)) {
+ ib_umem_release(umem);
+ return -EINVAL;
+ }
+
+ cq->umem = umem;
+ return 0;
+}
+
int ionic_create_cq_common(struct ionic_vcq *vcq,
struct ionic_tbl_buf *buf,
const struct ib_cq_init_attr *attr,
@@ -113,18 +134,10 @@ int ionic_create_cq_common(struct ionic_vcq *vcq,
INIT_LIST_HEAD(&cq->flush_rq);

if (udata) {
- rc = ionic_validate_qdesc(req_cq);
+ rc = ionic_cq_get_user_umem(dev, cq, req_cq);
if (rc)
goto err_qdesc;

- cq->umem = ib_umem_get_cq_buf_or_va(&dev->ibdev, NULL,
- req_cq->addr, req_cq->size,
- IB_ACCESS_LOCAL_WRITE);
- if (IS_ERR(cq->umem)) {
- rc = PTR_ERR(cq->umem);
- goto err_qdesc;
- }
-
cq->q.ptr = NULL;
cq->q.size = req_cq->size;
cq->q.mask = req_cq->mask;
@@ -1963,6 +1976,30 @@ 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,
+ struct ib_umem **umem_out)
+{
+ struct ib_umem *umem;
+ int rc;
+
+ 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);
+
+ /* The ring is given to the device as whole pages */
+ if (ib_umem_offset(umem)) {
+ ib_umem_release(umem);
+ return -EINVAL;
+ }
+
+ *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,
@@ -2010,7 +2047,7 @@ 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, &qp->sq_umem);
if (rc)
return rc;

@@ -2024,10 +2061,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;

@@ -2247,7 +2280,7 @@ 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, &rq->umem);
if (rc)
return rc;

@@ -2260,10 +2293,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;

--
2.43.0