From: Abhijit Gangurde <abhijit.gangurde@amd.com>
To: <jgg@ziepe.ca>, <leon@kernel.org>
Cc: <allen.hubbe@amd.com>, <nikhil.agarwal@amd.com>,
<linux-rdma@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
"Abhijit Gangurde" <abhijit.gangurde@amd.com>
Subject: [for-next v4 2/4] RDMA/ionic: Check user ring alignment on the pinned umem
Date: Thu, 3 Dec 2026 16:38:03 +0530 [thread overview]
Message-ID: <20261203110805.2577721-3-abhijit.gangurde@amd.com> (raw)
In-Reply-To: <20261203110805.2577721-1-abhijit.gangurde@amd.com>
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@amd.com>
---
.../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
next prev parent reply other threads:[~2026-12-03 11:08 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 11:08 [for-next v4 0/4] RDMA/ionic: Accept CQ, SQ, and RQ rings as umem attributes Abhijit Gangurde
2026-12-03 11:08 ` [for-next v4 1/4] RDMA/ionic: Bound user queue depth and stride before shifting Abhijit Gangurde
2026-12-03 11:08 ` Abhijit Gangurde [this message]
2026-12-03 11:08 ` [for-next v4 3/4] RDMA/ionic: Accept CQ ring buffers as ioctl umem attributes Abhijit Gangurde
2026-12-03 11:08 ` [for-next v4 4/4] RDMA/ionic: Accept QP SQ and RQ rings " Abhijit Gangurde
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261203110805.2577721-3-abhijit.gangurde@amd.com \
--to=abhijit.gangurde@amd.com \
--cc=allen.hubbe@amd.com \
--cc=jgg@ziepe.ca \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=nikhil.agarwal@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®