From: David Hu <dhu@x6u.co>
To: Tatyana Nikolova <tatyana.e.nikolova@intel.com>,
Jason Gunthorpe <jgg@ziepe.ca>, Leon Romanovsky <leon@kernel.org>
Cc: linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org,
jmoroni@google.com, eagleshaw@google.com, xuehaohu@google.com
Subject: [PATCH rdma-next v2 6/6] RDMA/irdma: Support UMEM attribute for SRQ creation
Date: Thu, 15 Oct 2026 01:19:40 +0000 [thread overview]
Message-ID: <20261015011940.4122452-7-dhu@x6u.co> (raw)
In-Reply-To: <20261015011940.4122452-1-dhu@x6u.co>
From: David Hu <xuehaohu@google.com>
Support the standard 1-step queue buffer creation for SRQ by
`UVERBS_ATTR_CREATE_SRQ_BUF_UMEM` via `ib_umem_get_attr()`.
Set up hardware pble directly from the pinned SRQ umem via
`irdma_setup_q_pbl_from_umem()`.
Proper umem and pble cleanup, and error unwind are added into existing
`irdma_srq_free_rsrc()` upon SRQ destruction.
We maintain backward compatibility for the legacy 2-step registration if
the UMEM attribute is not provided.
Signed-off-by: David Hu <xuehaohu@google.com>
---
drivers/infiniband/hw/irdma/verbs.c | 68 ++++++++++++++++++++++++-----
1 file changed, 58 insertions(+), 10 deletions(-)
diff --git a/drivers/infiniband/hw/irdma/verbs.c b/drivers/infiniband/hw/irdma/verbs.c
index 4f0831813119..5d085933c7f0 100644
--- a/drivers/infiniband/hw/irdma/verbs.c
+++ b/drivers/infiniband/hw/irdma/verbs.c
@@ -1996,9 +1996,16 @@ static void irdma_srq_free_rsrc(struct irdma_pci_f *rf, struct irdma_srq *iwsrq)
iwsrq->kmem.va = NULL;
} else {
/* Not called in any failure path, so iwpbl is valid. */
- struct irdma_mr *iwmr = iwsrq->iwpbl->iwmr;
+ if (iwsrq->iwpbl) {
+ struct irdma_mr *iwmr = iwsrq->iwpbl->iwmr;
- refcount_dec(&iwmr->user_ring_refs);
+ if (iwmr && refcount_dec_and_test(&iwmr->user_ring_refs)) {
+ ib_umem_release(iwmr->region);
+ if (iwsrq->iwpbl->pbl_allocated)
+ irdma_free_pble(rf->pble_rsrc, &iwsrq->iwpbl->pble_alloc);
+ kfree(iwmr);
+ }
+ }
}
irdma_free_rsrc(rf, rf->allocated_srqs, srq->srq_uk.srq_id);
@@ -2425,6 +2432,7 @@ static int irdma_setup_umode_srq(struct irdma_device *iwdev,
struct ib_udata *udata,
struct uverbs_attr_bundle *attrs)
{
+ struct irdma_srq_uk_init_info *ukinfo = &info->srq_uk_init_info;
struct irdma_create_srq_req req = {};
struct irdma_ucontext *ucontext;
struct irdma_srq_mr *srqmr;
@@ -2440,14 +2448,49 @@ static int irdma_setup_umode_srq(struct irdma_device *iwdev,
if (ret)
return ret;
- spin_lock_irqsave(&ucontext->srq_reg_mem_list_lock, flags);
- iwpbl = irdma_get_pbl((unsigned long)req.user_srq_buf,
- &ucontext->srq_reg_mem_list);
- spin_unlock_irqrestore(&ucontext->srq_reg_mem_list_lock, flags);
- if (!iwpbl)
- return -EPROTO;
+ if (attrs && uverbs_attr_is_valid(attrs, UVERBS_ATTR_CREATE_SRQ_BUF_UMEM)) {
+ struct irdma_mem_reg_req srq_req = {};
+ struct ib_umem *umem;
+ u32 total;
+ u8 shift;
- iwsrq->iwpbl = iwpbl;
+ irdma_get_wqe_shift(ukinfo->uk_attrs, ukinfo->max_srq_frag_cnt, 0, &shift);
+ srq_req.rq_pages =
+ DIV_ROUND_UP((ukinfo->srq_size << shift) * IRDMA_QP_WQE_MIN_SIZE,
+ IRDMA_HW_PAGE_SIZE);
+ total = srq_req.rq_pages + IRDMA_SHADOW_PGCNT;
+
+ umem = ib_umem_get_attr(&iwdev->ibdev, attrs,
+ UVERBS_ATTR_CREATE_SRQ_BUF_UMEM,
+ total << IRDMA_HW_PAGE_SHIFT,
+ IB_ACCESS_LOCAL_WRITE);
+ if (IS_ERR(umem))
+ return PTR_ERR(umem);
+
+ iwsrq->iwpbl = irdma_setup_q_pbl_from_umem(iwdev, umem,
+ iwsrq->ibsrq.pd,
+ IRDMA_MEMREG_TYPE_SRQ,
+ &srq_req);
+ if (IS_ERR(iwsrq->iwpbl)) {
+ ret = PTR_ERR(iwsrq->iwpbl);
+ iwsrq->iwpbl = NULL;
+ ib_umem_release(umem);
+ return ret;
+ }
+ iwpbl = iwsrq->iwpbl;
+ } else {
+ if (!req.user_srq_buf)
+ return -EINVAL;
+
+ spin_lock_irqsave(&ucontext->srq_reg_mem_list_lock, flags);
+ iwpbl = irdma_get_pbl((unsigned long)req.user_srq_buf,
+ &ucontext->srq_reg_mem_list);
+ spin_unlock_irqrestore(&ucontext->srq_reg_mem_list_lock, flags);
+ if (!iwpbl)
+ return -EPROTO;
+
+ iwsrq->iwpbl = iwpbl;
+ }
srqmr = &iwpbl->srq_mr;
if (iwpbl->pbl_allocated) {
@@ -2615,7 +2658,12 @@ static int irdma_create_srq(struct ib_srq *ibsrq,
if (iwsrq->user_mode && iwsrq->iwpbl) {
struct irdma_mr *iwmr = iwsrq->iwpbl->iwmr;
- refcount_dec(&iwmr->user_ring_refs);
+ if (iwmr && refcount_dec_and_test(&iwmr->user_ring_refs)) {
+ ib_umem_release(iwmr->region);
+ if (iwsrq->iwpbl->pbl_allocated)
+ irdma_free_pble(rf->pble_rsrc, &iwsrq->iwpbl->pble_alloc);
+ kfree(iwmr);
+ }
}
irdma_free_rsrc(rf, rf->allocated_srqs, iwsrq->srq_num);
return err_code;
--
2.56.0.385.gd3acb90ef8-goog
prev parent reply other threads:[~2026-10-15 1:20 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-15 1:19 [PATCH rdma-next v2 0/6] RDMA/irdma: Add support for ioctl David Hu
2026-10-15 1:19 ` [PATCH rdma-next v2 1/6] RDMA/irdma: Plumb uverbs_attr_bundle for QP, SRQ David Hu
2026-10-15 1:19 ` [PATCH rdma-next v2 2/6] RDMA/irdma: Register irdma UVERBS ioctl namespace David Hu
2026-10-15 1:19 ` [PATCH rdma-next v2 3/6] RDMA/irdma: Support UMEM attribute for QP creation David Hu
2026-10-15 1:19 ` [PATCH rdma-next v2 4/6] RDMA/irdma: Split CQ setup to umode and kmode David Hu
2026-10-15 18:17 ` Leon Romanovsky
2026-10-15 21:19 ` David Hu
2026-10-15 1:19 ` [PATCH rdma-next v2 5/6] RDMA/irdma: Support UMEM attribute for CQ creation David Hu
2026-10-15 1:19 ` David Hu [this message]
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=20261015011940.4122452-7-dhu@x6u.co \
--to=dhu@x6u.co \
--cc=eagleshaw@google.com \
--cc=jgg@ziepe.ca \
--cc=jmoroni@google.com \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=tatyana.e.nikolova@intel.com \
--cc=xuehaohu@google.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®