mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Michael Gur <michaelgur@nvidia.com>
To: Honggang LI <honggangli@163.com>,
	haris.iqbal@ionos.com, jinpu.wang@ionos.com
Cc: jgg@ziepe.ca, leon@kernel.org, danil.kipnis@cloud.ionos.com,
	linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] RDMA/rtrs: client: Fix clt_path::max_pages_per_mr calculation
Date: Wed, 24 Dec 2025 13:36:54 +0200	[thread overview]
Message-ID: <4b78fce8-5ead-468c-809d-72cb3479c69f@nvidia.com> (raw)
In-Reply-To: <20251224095030.156465-1-honggangli@163.com>


On 12/24/2025 11:50 AM, Honggang LI wrote:
> If device max_mr_size bits in the range [mr_page_shift+31:mr_page_shift]
> are zero, 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`.
>
> v1 -> v2:
> Correct the commit message and set max_pages_per_mr to U32_MAX
> as Michael Gur suggested.
> 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, 2 insertions(+)
>
> diff --git a/drivers/infiniband/ulp/rtrs/rtrs-clt.c b/drivers/infiniband/ulp/rtrs/rtrs-clt.c
> index 71387811b281..e477d2c0ff35 100644
> --- a/drivers/infiniband/ulp/rtrs/rtrs-clt.c
> +++ b/drivers/infiniband/ulp/rtrs/rtrs-clt.c
> @@ -1464,6 +1464,8 @@ static void query_fast_reg_mode(struct rtrs_clt_path *clt_path)
>   	mr_page_shift      = max(12, ffs(ib_dev->attrs.page_size_cap) - 1);
>   	max_pages_per_mr   = ib_dev->attrs.max_mr_size;
>   	do_div(max_pages_per_mr, (1ull << mr_page_shift));
> +	if ((u32)max_pages_per_mr == 0)
> +		max_pages_per_mr = U32_MAX;
>   	clt_path->max_pages_per_mr =
>   		min3(clt_path->max_pages_per_mr, (u32)max_pages_per_mr,
>   		     ib_dev->attrs.max_fast_reg_page_list_len);

Checking after casting means you'll also assign U32_MAX when it's zero 
before the casting.
For that to happen in this case we'd need to have a device with 
max_mr_size smaller than it's lowest supported page_size.
I think it's safe to assume these are not valid device attributes, so 
we're safe here.

Reviewed-by: Michael Gur <michaelgur@nvidia.com>


  reply	other threads:[~2025-12-24 11:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-24  9:50 Honggang LI
2025-12-24 11:36 ` Michael Gur [this message]
2025-12-25 12:33 ` Leon Romanovsky
2025-12-29  2:49   ` Honggang LI

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=4b78fce8-5ead-468c-809d-72cb3479c69f@nvidia.com \
    --to=michaelgur@nvidia.com \
    --cc=danil.kipnis@cloud.ionos.com \
    --cc=haris.iqbal@ionos.com \
    --cc=honggangli@163.com \
    --cc=jgg@ziepe.ca \
    --cc=jinpu.wang@ionos.com \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.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

all inboxes | Powered by JetHome®