mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] RDMA/erdma: handle ib_umem_find_best_pgsz() return value
@ 2025-02-21  7:03 Ваторопин Андрей
  2025-02-21  7:55 ` Cheng Xu
  0 siblings, 1 reply; 2+ messages in thread
From: Ваторопин Андрей @ 2025-02-21  7:03 UTC (permalink / raw)
  To: Kai Shen
  Cc: Ваторопин
	Андрей,
	Jason Gunthorpe, Leon Romanovsky, Wei Yongjun, Yang Li,
	linux-rdma, linux-kernel, lvc-project

From: Andrey Vatoropin <a.vatoropin@crpt.ru>

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@crpt.ru>
---
 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;
+	}
 	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);
-- 
2.43.0

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] RDMA/erdma: handle ib_umem_find_best_pgsz() return value
  2025-02-21  7:03 [PATCH] RDMA/erdma: handle ib_umem_find_best_pgsz() return value Ваторопин Андрей
@ 2025-02-21  7:55 ` Cheng Xu
  0 siblings, 0 replies; 2+ messages in thread
From: Cheng Xu @ 2025-02-21  7:55 UTC (permalink / raw)
  To: Ваторопин
	Андрей,
	Kai Shen
  Cc: Jason Gunthorpe, Leon Romanovsky, Wei Yongjun, Yang Li,
	linux-rdma, linux-kernel, lvc-project



On 2/21/25 3:03 PM, Ваторопин Андрей wrote:
> From: Andrey Vatoropin <a.vatoropin@crpt.ru>
> 
> 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@crpt.ru>
> ---
>  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@linux.alibaba.com>

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);

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-02-21  7:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-21  7:03 [PATCH] RDMA/erdma: handle ib_umem_find_best_pgsz() return value Ваторопин Андрей
2025-02-21  7:55 ` Cheng Xu

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®