From: Cheng Xu <chengyou@linux.alibaba.com>
To: jgg@ziepe.ca, leon@kernel.org
Cc: linux-rdma@vger.kernel.org, KaiShen@linux.alibaba.com
Subject: [PATCH for-next v4 3/5] RDMA/erdma: Support non-contiguous kernel CQ buffers
Date: Thu, 17 Sep 2026 20:04:57 +0800 [thread overview]
Message-ID: <20260917120459.13286-4-chengyou@linux.alibaba.com> (raw)
In-Reply-To: <20260917120459.13286-1-chengyou@linux.alibaba.com>
A single coherent allocation for a kernel CQ can fail when memory is
fragmented.
Use page-sized coherent buffers and describe them with the existing MTT.
Keep the userspace CQ path and doorbell allocation unchanged.
Signed-off-by: Cheng Xu <chengyou@linux.alibaba.com>
---
drivers/infiniband/hw/erdma/erdma_cq.c | 14 ++---
drivers/infiniband/hw/erdma/erdma_verbs.c | 76 +++++++++--------------
drivers/infiniband/hw/erdma/erdma_verbs.h | 3 +-
3 files changed, 36 insertions(+), 57 deletions(-)
diff --git a/drivers/infiniband/hw/erdma/erdma_cq.c b/drivers/infiniband/hw/erdma/erdma_cq.c
index 4cc0254b0ab5..daec74f0aa6d 100644
--- a/drivers/infiniband/hw/erdma/erdma_cq.c
+++ b/drivers/infiniband/hw/erdma/erdma_cq.c
@@ -8,8 +8,8 @@
static void *get_next_valid_cqe(struct erdma_cq *cq)
{
- __be32 *cqe = get_queue_entry(cq->kern_cq.qbuf, cq->kern_cq.ci,
- cq->depth, CQE_SHIFT);
+ __be32 *cqe = erdma_kmem_get_entry(
+ &cq->kern_cq.qbuf_mem, cq->kern_cq.ci, cq->depth, CQE_SHIFT);
u32 owner = FIELD_GET(ERDMA_CQE_HDR_OWNER_MASK,
be32_to_cpu(READ_ONCE(*cqe)));
@@ -242,15 +242,15 @@ void erdma_remove_cqes_of_qp(struct ib_cq *ibcq, u32 qpn)
while (ncqe > 0) {
cur_cq_ci = prev_cq_ci + ncqe - 1;
- cqe = get_queue_entry(cq->kern_cq.qbuf, cur_cq_ci, cq->depth,
- CQE_SHIFT);
+ cqe = erdma_kmem_get_entry(&cq->kern_cq.qbuf_mem, cur_cq_ci,
+ cq->depth, CQE_SHIFT);
if (be32_to_cpu(cqe->qpn) == qpn) {
++nqp_cqe;
} else if (nqp_cqe) {
- dst_cqe = get_queue_entry(cq->kern_cq.qbuf,
- cur_cq_ci + nqp_cqe,
- cq->depth, CQE_SHIFT);
+ dst_cqe = erdma_kmem_get_entry(&cq->kern_cq.qbuf_mem,
+ cur_cq_ci + nqp_cqe,
+ cq->depth, CQE_SHIFT);
owner = FIELD_GET(ERDMA_CQE_HDR_OWNER_MASK,
be32_to_cpu(dst_cqe->hdr));
cqe->hdr = cpu_to_be32(
diff --git a/drivers/infiniband/hw/erdma/erdma_verbs.c b/drivers/infiniband/hw/erdma/erdma_verbs.c
index ec29701675ca..345b75377681 100644
--- a/drivers/infiniband/hw/erdma/erdma_verbs.c
+++ b/drivers/infiniband/hw/erdma/erdma_verbs.c
@@ -177,7 +177,6 @@ static int create_cq_cmd(struct erdma_ucontext *uctx, struct erdma_cq *cq)
struct erdma_dev *dev = to_edev(cq->ibcq.device);
struct erdma_cmdq_create_cq_req req;
struct erdma_mem *mem;
- u32 page_size;
erdma_cmdq_build_reqhdr(&req.hdr, CMDQ_SUBMOD_RDMA,
CMDQ_OPCODE_CREATE_CQ);
@@ -187,48 +186,34 @@ static int create_cq_cmd(struct erdma_ucontext *uctx, struct erdma_cq *cq)
req.cfg1 = FIELD_PREP(ERDMA_CMD_CREATE_CQ_EQN_MASK, cq->assoc_eqn);
if (rdma_is_kernel_res(&cq->ibcq.res)) {
- page_size = SZ_32M;
- req.cfg0 |= FIELD_PREP(ERDMA_CMD_CREATE_CQ_PAGESIZE_MASK,
- ilog2(page_size) - ERDMA_HW_PAGE_SHIFT);
- req.qbuf_addr_l = lower_32_bits(cq->kern_cq.qbuf_dma_addr);
- req.qbuf_addr_h = upper_32_bits(cq->kern_cq.qbuf_dma_addr);
-
- req.cfg1 |= FIELD_PREP(ERDMA_CMD_CREATE_CQ_MTT_CNT_MASK, 1) |
- FIELD_PREP(ERDMA_CMD_CREATE_CQ_MTT_LEVEL_MASK,
- ERDMA_MR_MTT_0LEVEL);
-
- req.first_page_offset = 0;
+ mem = &cq->kern_cq.qbuf_mem;
req.cq_dbrec_dma = cq->kern_cq.dbrec_dma;
} else {
mem = &cq->user_cq.qbuf_mem;
- req.cfg0 |=
- FIELD_PREP(ERDMA_CMD_CREATE_CQ_PAGESIZE_MASK,
- ilog2(mem->page_size) - ERDMA_HW_PAGE_SHIFT);
- if (mem->mtt_nents == 1) {
- req.qbuf_addr_l = lower_32_bits(mem->mtt->buf[0]);
- req.qbuf_addr_h = upper_32_bits(mem->mtt->buf[0]);
- req.cfg1 |=
- FIELD_PREP(ERDMA_CMD_CREATE_CQ_MTT_LEVEL_MASK,
- ERDMA_MR_MTT_0LEVEL);
- } else {
- req.qbuf_addr_l = lower_32_bits(mem->mtt->buf_dma);
- req.qbuf_addr_h = upper_32_bits(mem->mtt->buf_dma);
- req.cfg1 |=
- FIELD_PREP(ERDMA_CMD_CREATE_CQ_MTT_LEVEL_MASK,
- ERDMA_MR_MTT_1LEVEL);
- }
- req.cfg1 |= FIELD_PREP(ERDMA_CMD_CREATE_CQ_MTT_CNT_MASK,
- mem->mtt_nents);
-
- req.first_page_offset = mem->page_offset;
req.cq_dbrec_dma = cq->user_cq.dbrec_dma;
+ }
- if (uctx->ext_db.enable) {
- req.cfg1 |= FIELD_PREP(
- ERDMA_CMD_CREATE_CQ_MTT_DB_CFG_MASK, 1);
- req.cfg2 = FIELD_PREP(ERDMA_CMD_CREATE_CQ_DB_CFG_MASK,
- uctx->ext_db.cdb_off);
- }
+ req.cfg0 |= FIELD_PREP(ERDMA_CMD_CREATE_CQ_PAGESIZE_MASK,
+ ilog2(mem->page_size) - ERDMA_HW_PAGE_SHIFT);
+ if (mem->mtt_nents == 1) {
+ req.qbuf_addr_l = lower_32_bits(mem->mtt->buf[0]);
+ req.qbuf_addr_h = upper_32_bits(mem->mtt->buf[0]);
+ req.cfg1 |= FIELD_PREP(ERDMA_CMD_CREATE_CQ_MTT_LEVEL_MASK,
+ ERDMA_MR_MTT_0LEVEL);
+ } else {
+ req.qbuf_addr_l = lower_32_bits(mem->mtt->buf_dma);
+ req.qbuf_addr_h = upper_32_bits(mem->mtt->buf_dma);
+ req.cfg1 |= FIELD_PREP(ERDMA_CMD_CREATE_CQ_MTT_LEVEL_MASK,
+ ERDMA_MR_MTT_1LEVEL);
+ }
+ req.cfg1 |=
+ FIELD_PREP(ERDMA_CMD_CREATE_CQ_MTT_CNT_MASK, mem->mtt_nents);
+ req.first_page_offset = mem->page_offset;
+
+ if (uctx && uctx->ext_db.enable) {
+ req.cfg1 |= FIELD_PREP(ERDMA_CMD_CREATE_CQ_MTT_DB_CFG_MASK, 1);
+ req.cfg2 = FIELD_PREP(ERDMA_CMD_CREATE_CQ_DB_CFG_MASK,
+ uctx->ext_db.cdb_off);
}
return erdma_post_cmd_wait(&dev->cmdq, &req, sizeof(req), NULL, NULL,
@@ -1398,8 +1383,7 @@ int erdma_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata)
wait_for_completion(&cq->free);
if (rdma_is_kernel_res(&cq->ibcq.res)) {
- dma_free_coherent(&dev->pdev->dev, cq->depth << CQE_SHIFT,
- cq->kern_cq.qbuf, cq->kern_cq.qbuf_dma_addr);
+ put_mtt_entries(dev, &cq->kern_cq.qbuf_mem);
dma_pool_free(dev->db_pool, cq->kern_cq.dbrec,
cq->kern_cq.dbrec_dma);
} else {
@@ -1997,10 +1981,8 @@ static int erdma_init_kernel_cq(struct erdma_cq *cq)
{
struct erdma_dev *dev = to_edev(cq->ibcq.device);
- cq->kern_cq.qbuf =
- dma_alloc_coherent(&dev->pdev->dev, cq->depth << CQE_SHIFT,
- &cq->kern_cq.qbuf_dma_addr, GFP_KERNEL);
- if (!cq->kern_cq.qbuf)
+ if (erdma_alloc_kmem(dev, &cq->kern_cq.qbuf_mem,
+ cq->depth << CQE_SHIFT))
return -ENOMEM;
cq->kern_cq.dbrec = dma_pool_zalloc(dev->db_pool, GFP_KERNEL,
@@ -2015,8 +1997,7 @@ static int erdma_init_kernel_cq(struct erdma_cq *cq)
return 0;
err_out:
- dma_free_coherent(&dev->pdev->dev, cq->depth << CQE_SHIFT,
- cq->kern_cq.qbuf, cq->kern_cq.qbuf_dma_addr);
+ put_mtt_entries(dev, &cq->kern_cq.qbuf_mem);
return -ENOMEM;
}
@@ -2083,8 +2064,7 @@ int erdma_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,
erdma_unmap_user_dbrecords(ctx, &cq->user_cq.user_dbr_page);
put_mtt_entries(dev, &cq->user_cq.qbuf_mem);
} else {
- dma_free_coherent(&dev->pdev->dev, depth << CQE_SHIFT,
- cq->kern_cq.qbuf, cq->kern_cq.qbuf_dma_addr);
+ put_mtt_entries(dev, &cq->kern_cq.qbuf_mem);
dma_pool_free(dev->db_pool, cq->kern_cq.dbrec,
cq->kern_cq.dbrec_dma);
}
diff --git a/drivers/infiniband/hw/erdma/erdma_verbs.h b/drivers/infiniband/hw/erdma/erdma_verbs.h
index 401e76e846b9..28e898f1b6f5 100644
--- a/drivers/infiniband/hw/erdma/erdma_verbs.h
+++ b/drivers/infiniband/hw/erdma/erdma_verbs.h
@@ -352,8 +352,7 @@ struct erdma_qp {
};
struct erdma_kcq_info {
- void *qbuf;
- dma_addr_t qbuf_dma_addr;
+ struct erdma_mem qbuf_mem;
u32 ci;
u32 cmdsn;
u32 notify_cnt;
--
2.31.1
next prev parent reply other threads:[~2026-09-17 12:05 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-17 12:04 [PATCH for-next v4 0/5] RDMA/erdma: Support non-contiguous kernel queue buffers Cheng Xu
2026-09-17 12:04 ` [PATCH for-next v4 1/5] RDMA/erdma: Unwind kernel QP initialization failures Cheng Xu
2026-09-17 12:11 ` sashiko-bot
2026-09-17 12:04 ` [PATCH for-next v4 2/5] RDMA/erdma: Support non-contiguous kernel QP buffers Cheng Xu
2026-09-17 12:16 ` sashiko-bot
2026-09-17 12:04 ` Cheng Xu [this message]
2026-09-17 12:13 ` [PATCH for-next v4 3/5] RDMA/erdma: Support non-contiguous kernel CQ buffers sashiko-bot
2026-09-17 12:04 ` [PATCH for-next v4 4/5] RDMA/erdma: Unify userspace and kernel queue buffer management Cheng Xu
2026-09-17 12:13 ` sashiko-bot
2026-09-17 12:04 ` [PATCH for-next v4 5/5] RDMA/erdma: Move kernel QP helpers after memory helpers Cheng Xu
2026-09-17 12:10 ` sashiko-bot
2026-09-23 10:53 ` [PATCH for-next v4 0/5] RDMA/erdma: Support non-contiguous kernel queue buffers Leon Romanovsky
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=20260917120459.13286-4-chengyou@linux.alibaba.com \
--to=chengyou@linux.alibaba.com \
--cc=KaiShen@linux.alibaba.com \
--cc=jgg@ziepe.ca \
--cc=leon@kernel.org \
--cc=linux-rdma@vger.kernel.org \
/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