From: Leon Romanovsky <leon@kernel.org>
To: Jason Gunthorpe <jgg@nvidia.com>
Cc: "Margolin, Michael" <mrgolin@amazon.com>,
linux-rdma@vger.kernel.org, sleybo@amazon.com, matua@amazon.com,
gal.pressman@linux.dev, Firas Jahjah <firasj@amazon.com>,
Yonatan Nachum <ynachum@amazon.com>
Subject: Re: [PATCH for-next] RDMA/core: Fix best page size finding when it can cross SG entries
Date: Thu, 13 Feb 2025 19:35:10 +0200 [thread overview]
Message-ID: <20250213173510.GO17863@unreal> (raw)
In-Reply-To: <20250213144219.GB3754072@nvidia.com>
On Thu, Feb 13, 2025 at 10:42:19AM -0400, Jason Gunthorpe wrote:
> On Thu, Feb 13, 2025 at 04:30:11PM +0200, Margolin, Michael wrote:
> >
> > On 2/13/2025 4:04 PM, Jason Gunthorpe wrote:
> > > CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.
> > >
> > >
> > >
> > > On Thu, Feb 13, 2025 at 02:51:26PM +0200, Leon Romanovsky wrote:
> > > > diff --git a/drivers/infiniband/core/umem.c b/drivers/infiniband/core/umem.c
> > > > index e7e428369159..63a92d6cfbc2 100644
> > > > --- a/drivers/infiniband/core/umem.c
> > > > +++ b/drivers/infiniband/core/umem.c
> > > > @@ -112,8 +112,7 @@ unsigned long ib_umem_find_best_pgsz(struct ib_umem *umem,
> > > > /* If the current entry is physically contiguous with the previous
> > > > * one, no need to take its start addresses into consideration.
> > > > */
> > > > - if (curr_base + curr_len != sg_dma_address(sg)) {
> > > > -
> > > > + if (curr_base != sg_dma_address(sg) - curr_len) {
> > > > curr_base = sg_dma_address(sg);
> > > > curr_len = 0;
> > > I'm not sure about this, what ensures sg_dma_address() > curr_len?
> > >
> > > curr_base + curr_len could also overflow, we've seen that AMD IOMMU
> > > sometimes uses the very high addresess already
> >
> > I think the only case we care about where curr_base + curr_len can overflow
> > is when next sg_dma_address() == 0.
> >
> > But maybe we should just add an explicit check:
> >
> > - if (curr_base + curr_len != sg_dma_address(sg)) {
> > + if (curr_base + curr_len < curr_base ||
> > + curr_base + curr_len != sg_dma_address(sg)) {
> > curr_base = sg_dma_address(sg);
> > curr_len = 0;
>
> Ugh
>
> I wonder if we should try to make a overflow.h helper for these kinds
> of problems.
>
> /* Check if a + n == b, failing if a+n overflows */
> check_consecutive(a, n, b)
>
> ?
>
> It is a fairly common problem
>
> I suggest to take the patch as it originally was and try to propose
> the above helper?
My concern was with this line:
if (curr_base + curr_len != sg_dma_address(sg)) {
Initially curr_base is 0xFF.....FF and curr_len is 0.
So if this "if ..." is skipped (not possible but static checkers don't know),
we will advance curr_len and curr_base + curr_len will overflow.
I don't want to take original patch.
Thanks
>
> Jason
next prev parent reply other threads:[~2025-02-13 17:35 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-09 14:26 [PATCH for-next] RDMA/core: Fix best page size finding when it can cross SG entries Michael Margolin
2025-02-13 12:51 ` Leon Romanovsky
2025-02-13 14:04 ` Jason Gunthorpe
2025-02-13 14:30 ` Margolin, Michael
2025-02-13 14:42 ` Jason Gunthorpe
2025-02-13 17:25 ` Margolin, Michael
2025-02-13 17:35 ` Leon Romanovsky [this message]
2025-02-13 17:40 ` Jason Gunthorpe
2025-02-13 17:55 ` Leon Romanovsky
2025-02-13 18:12 ` Jason Gunthorpe
2025-02-14 5:55 ` Leon Romanovsky
2025-02-14 15:33 ` Jason Gunthorpe
2025-02-16 8:07 ` Leon Romanovsky
2025-02-17 8:40 ` Margolin, Michael
2025-02-13 12:53 ` Leon Romanovsky
2025-02-14 6:57 ` Leon Romanovsky
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=20250213173510.GO17863@unreal \
--to=leon@kernel.org \
--cc=firasj@amazon.com \
--cc=gal.pressman@linux.dev \
--cc=jgg@nvidia.com \
--cc=linux-rdma@vger.kernel.org \
--cc=matua@amazon.com \
--cc=mrgolin@amazon.com \
--cc=sleybo@amazon.com \
--cc=ynachum@amazon.com \
/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