From: Leon Romanovsky <leon@kernel.org>
To: Cheng Xu <chengyou@linux.alibaba.com>
Cc: jgg@ziepe.ca, linux-rdma@vger.kernel.org, KaiShen@linux.alibaba.com
Subject: Re: [PATCH for-next v2 1/4] RDMA/erdma: Support non-contiguous kernel QP buffers
Date: Thu, 3 Sep 2026 12:10:33 +0300 [thread overview]
Message-ID: <20260903091033.GY24140@unreal> (raw)
In-Reply-To: <20260827082523.36294-2-chengyou@linux.alibaba.com>
On Thu, Aug 27, 2026 at 04:25:20PM +0800, Cheng Xu wrote:
> A single coherent allocation for kernel QP queues can fail for large
> queues when memory is fragmented.
>
> Allocate page-sized coherent buffers and describe them with the existing
> MTT. Keep the userspace QP path unchanged.
>
> Signed-off-by: Cheng Xu <chengyou@linux.alibaba.com>
> ---
> drivers/infiniband/hw/erdma/erdma_cq.c | 4 +-
> drivers/infiniband/hw/erdma/erdma_qp.c | 38 +++--
> drivers/infiniband/hw/erdma/erdma_verbs.c | 195 +++++++++++++---------
> drivers/infiniband/hw/erdma/erdma_verbs.h | 44 ++++-
> 4 files changed, 179 insertions(+), 102 deletions(-)
<...>
> +static void erdma_free_kmem(struct erdma_dev *dev, struct erdma_mem *mem)
> +{
> + struct erdma_buf_list *buf_list;
> + u32 i;
> +
> + if (!mem->kmem)
> + return;
Can it be null?
> +
> + buf_list = mem->kmem->buf_list;
> + if (buf_list) {
Write the unwinding section of erdma_alloc_kmem() to don't call to
erdma_free_kmem().
> + for (i = 0; i < mem->page_cnt; i++)
> + if (buf_list[i].buf)
> + dma_free_coherent(&dev->pdev->dev, PAGE_SIZE,
> + buf_list[i].buf,
> + buf_list[i].dma_addr);
> + kfree(buf_list);
> + }
> +
> + kfree(mem->kmem);
> + mem->kmem = NULL;
> +}
> +
> +static int erdma_alloc_kmem(struct erdma_dev *dev, struct erdma_mem *mem,
> + size_t size)
> +{
> + struct erdma_buf_list *buf_list;
> + u32 i;
> +
> + mem->type = ERDMA_KMEM;
> + mem->page_size = PAGE_SIZE;
> + mem->page_offset = 0;
> + mem->page_cnt = DIV_ROUND_UP(size, PAGE_SIZE);
> + mem->mtt_nents = mem->page_cnt;
> + mem->len = size;
> +
> + mem->kmem = kzalloc_obj(*mem->kmem);
> + if (!mem->kmem)
> + goto err_free_mem;
There is no point to call to erdma_free_kmem() here and you can return
immediately.
> +
> + buf_list = kcalloc(mem->page_cnt, sizeof(*buf_list), GFP_KERNEL);
> + if (!buf_list)
> + goto err_free_mem;
Please write error unwinding explicitly.
> + mem->kmem->buf_list = buf_list;
> +
> + for (i = 0; i < mem->page_cnt; i++) {
> + buf_list[i].buf = dma_alloc_coherent(&dev->pdev->dev, PAGE_SIZE,
> + &buf_list[i].dma_addr,
> + GFP_KERNEL);
> + if (!buf_list[i].buf)
> + goto err_free_mem;
> + }
> +
> + mem->mtt = erdma_create_mtt(dev, MTT_SIZE(mem->page_cnt), true);
> + if (IS_ERR(mem->mtt)) {
> + mem->mtt = NULL;
Why? You will release mem anyway.
> + goto err_free_mem;
> + }
> + for (i = 0; i < mem->page_cnt; i++)
> + mem->mtt->buf[i] = buf_list[i].dma_addr;
> +
> + return 0;
> +
> +err_free_mem:
> + erdma_free_kmem(dev, mem);
> + return -ENOMEM;
> +}
> +
<...>
> +struct erdma_buf_list {
> + void *buf;
> + dma_addr_t dma_addr;
> +};
This struct is very similar to scatter-gather list, why don't you use it
directly?
Thanks
next prev parent reply other threads:[~2026-09-03 9:10 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-27 8:25 [PATCH for-next v2 0/4] RDMA/erdma: Support non-contiguous kernel queue buffers Cheng Xu
2026-08-27 8:25 ` [PATCH for-next v2 1/4] RDMA/erdma: Support non-contiguous kernel QP buffers Cheng Xu
2026-09-03 9:10 ` Leon Romanovsky [this message]
2026-09-03 12:38 ` Cheng Xu
2026-09-09 6:21 ` Cheng Xu
2026-09-10 15:33 ` Leon Romanovsky
2026-09-11 2:41 ` Cheng Xu
2026-08-27 8:25 ` [PATCH for-next v2 2/4] RDMA/erdma: Support non-contiguous kernel CQ buffers Cheng Xu
2026-08-27 8:25 ` [PATCH for-next v2 3/4] RDMA/erdma: Unify userspace and kernel queue buffer management Cheng Xu
2026-09-03 9:12 ` Leon Romanovsky
2026-09-03 12:40 ` Cheng Xu
2026-08-27 8:25 ` [PATCH for-next v2 4/4] RDMA/erdma: Move kernel QP helpers after memory helpers Cheng Xu
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=20260903091033.GY24140@unreal \
--to=leon@kernel.org \
--cc=KaiShen@linux.alibaba.com \
--cc=chengyou@linux.alibaba.com \
--cc=jgg@ziepe.ca \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.