Re: [PATCH] RDMA/erdma: handle ib_umem_find_best_pgsz() return value
From: Cheng Xu
Date: Fri Feb 21 2025 - 02:55:49 EST
On 2/21/25 3:03 PM, Ваторопин Андрей wrote:
> From: Andrey Vatoropin <a.vatoropin@xxxxxxx>
>
> The ib_umem_find_best_pgsz function is necessary for obtaining the optimal
> hardware page size. In the comment above, function has statement:
> "Drivers always supporting PAGE_SIZE or smaller will never see a 0 result."
>
> But it's hard to prove this holds true for the erdma driver.
>
> Similar to other drivers that use ib_umem_find_best_pgsz, it is essential
> to add an error handler to manage potential error situations in the future.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Fixes: 155055771704 ("RDMA/erdma: Add verbs implementation")
> Signed-off-by: Andrey Vatoropin <a.vatoropin@xxxxxxx>
> ---
> drivers/infiniband/hw/erdma/erdma_verbs.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/infiniband/hw/erdma/erdma_verbs.c b/drivers/infiniband/hw/erdma/erdma_verbs.c
> index 51d619edb6c5..7ad38fb84661 100644
> --- a/drivers/infiniband/hw/erdma/erdma_verbs.c
> +++ b/drivers/infiniband/hw/erdma/erdma_verbs.c
> @@ -781,6 +781,10 @@ static int get_mtt_entries(struct erdma_dev *dev, struct erdma_mem *mem,
> mem->page_size = ib_umem_find_best_pgsz(mem->umem, req_page_size, virt);
> + if (!mem->page_size) {
> + ret = -EINVAL;
> + goto error_ret;
> + }
Thanks,
I think ib_umem_find_best_pgsz won't fail in erdma, because we always set the corresponding bit
of PAGE_SIZE in the req_page_size, which can let ib_umem_find_best_pgsz find an answer at least.
If fixing it can make SVACE happy, I'm OK with this patch.
Acked-by: Cheng Xu <chengyou@xxxxxxxxxxxxxxxxx>
Regards,
Cheng Xu
> mem->page_offset = start & (mem->page_size - 1);
> mem->mtt_nents = ib_umem_num_dma_blocks(mem->umem, mem->page_size);
> mem->page_cnt = mem->mtt_nents;
> mem->mtt = erdma_create_mtt(dev, MTT_SIZE(mem->page_cnt),
> force_continuous);