* [PATCH] RDMA/rtrs: client: Fix clt_path::max_pages_per_mr calculation
@ 2025-12-23 3:43 Honggang LI
2025-12-23 14:08 ` Michael Gur
0 siblings, 1 reply; 3+ messages in thread
From: Honggang LI @ 2025-12-23 3:43 UTC (permalink / raw)
To: jinpu.wang, danil.kipnis; +Cc: jgg, leon, linux-rdma, linux-kernel, Honggang LI
If the low two bytes of ib_dev::attrs::max_mr_size are zeros, the `min3`
function will set clt_path::max_pages_per_mr to zero.
`alloc_path_reqs` will pass zero, which is invalid, as the third parameter
to `ib_alloc_mr`.
Fixes: 6a98d71daea1 ("RDMA/rtrs: client: main functionality")
Signed-off-by: Honggang LI <honggangli@163.com>
---
drivers/infiniband/ulp/rtrs/rtrs-clt.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/infiniband/ulp/rtrs/rtrs-clt.c b/drivers/infiniband/ulp/rtrs/rtrs-clt.c
index 71387811b281..b9d66e4fab07 100644
--- a/drivers/infiniband/ulp/rtrs/rtrs-clt.c
+++ b/drivers/infiniband/ulp/rtrs/rtrs-clt.c
@@ -1465,7 +1465,7 @@ static void query_fast_reg_mode(struct rtrs_clt_path *clt_path)
max_pages_per_mr = ib_dev->attrs.max_mr_size;
do_div(max_pages_per_mr, (1ull << mr_page_shift));
clt_path->max_pages_per_mr =
- min3(clt_path->max_pages_per_mr, (u32)max_pages_per_mr,
+ min(min_not_zero(clt_path->max_pages_per_mr, (u32)max_pages_per_mr),
ib_dev->attrs.max_fast_reg_page_list_len);
clt_path->clt->max_segments =
min(clt_path->max_pages_per_mr, clt_path->clt->max_segments);
--
2.52.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] RDMA/rtrs: client: Fix clt_path::max_pages_per_mr calculation
2025-12-23 3:43 [PATCH] RDMA/rtrs: client: Fix clt_path::max_pages_per_mr calculation Honggang LI
@ 2025-12-23 14:08 ` Michael Gur
2025-12-24 2:11 ` Honggang LI
0 siblings, 1 reply; 3+ messages in thread
From: Michael Gur @ 2025-12-23 14:08 UTC (permalink / raw)
To: Honggang LI, jinpu.wang, danil.kipnis; +Cc: jgg, leon, linux-rdma, linux-kernel
On 12/23/2025 5:43 AM, Honggang LI wrote:
> If the low two bytes of ib_dev::attrs::max_mr_size are zeros, the `min3`
> function will set clt_path::max_pages_per_mr to zero.
Can't see how if the low two bytes of max_mr_size are zero it would
cause the local variable max_pages_per_mr to zero.
The more probable cause is that max_mr_size bits in the range
[mr_page_shift+31:mr_page_shift] are zero. Since that's what's left
after division and cast to u32.
This means you are working on a device supporting more pages_per_mr than
can fit in a u32.
> `alloc_path_reqs` will pass zero, which is invalid, as the third parameter
> to `ib_alloc_mr`.
>
> Fixes: 6a98d71daea1 ("RDMA/rtrs: client: main functionality")
> Signed-off-by: Honggang LI <honggangli@163.com>
> ---
> drivers/infiniband/ulp/rtrs/rtrs-clt.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/infiniband/ulp/rtrs/rtrs-clt.c b/drivers/infiniband/ulp/rtrs/rtrs-clt.c
> index 71387811b281..b9d66e4fab07 100644
> --- a/drivers/infiniband/ulp/rtrs/rtrs-clt.c
> +++ b/drivers/infiniband/ulp/rtrs/rtrs-clt.c
> @@ -1465,7 +1465,7 @@ static void query_fast_reg_mode(struct rtrs_clt_path *clt_path)
> max_pages_per_mr = ib_dev->attrs.max_mr_size;
> do_div(max_pages_per_mr, (1ull << mr_page_shift));
> clt_path->max_pages_per_mr =
> - min3(clt_path->max_pages_per_mr, (u32)max_pages_per_mr,
> + min(min_not_zero(clt_path->max_pages_per_mr, (u32)max_pages_per_mr),
This still fixes the issue, but for readability, if max_pages_per_mr is
larger than U32_MAX, I'd set it to be U32_MAX.
Michael
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] RDMA/rtrs: client: Fix clt_path::max_pages_per_mr calculation
2025-12-23 14:08 ` Michael Gur
@ 2025-12-24 2:11 ` Honggang LI
0 siblings, 0 replies; 3+ messages in thread
From: Honggang LI @ 2025-12-24 2:11 UTC (permalink / raw)
To: Michael Gur; +Cc: jinpu.wang, danil.kipnis, jgg, leon, linux-rdma, linux-kernel
On Tue, Dec 23, 2025 at 04:08:19PM +0200, Michael Gur wrote:
> Subject: Re: [PATCH] RDMA/rtrs: client: Fix clt_path::max_pages_per_mr
> calculation
> From: Michael Gur <michaelgur@nvidia.com>
> Date: Tue, 23 Dec 2025 16:08:19 +0200
>
>
> On 12/23/2025 5:43 AM, Honggang LI wrote:
> > If the low two bytes of ib_dev::attrs::max_mr_size are zeros, the `min3`
> > function will set clt_path::max_pages_per_mr to zero.
>
> Can't see how if the low two bytes of max_mr_size are zero it would cause
> the local variable max_pages_per_mr to zero.
> The more probable cause is that max_mr_size bits in the range
> [mr_page_shift+31:mr_page_shift] are zero. Since that's what's left after
> division and cast to u32.
Yes, you are right. The irdma support max_mr_size is 0x200000000000.
[mr_page_shift+31:mr_page_shift], a.k.a [43,12] are zeros.
> This means you are working on a device supporting more pages_per_mr than can
> fit in a u32.
>
> > - min3(clt_path->max_pages_per_mr, (u32)max_pages_per_mr,
> > + min(min_not_zero(clt_path->max_pages_per_mr, (u32)max_pages_per_mr),
>
> This still fixes the issue, but for readability, if max_pages_per_mr is
> larger than U32_MAX, I'd set it to be U32_MAX.
I will set it to U32_MAX as you suggested.
thanks
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-12-24 2:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-23 3:43 [PATCH] RDMA/rtrs: client: Fix clt_path::max_pages_per_mr calculation Honggang LI
2025-12-23 14:08 ` Michael Gur
2025-12-24 2:11 ` Honggang LI
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).