All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@nvidia.com>
To: Kashyap Desai <kashyap.desai@broadcom.com>
Cc: linux-rdma@vger.kernel.org, leonro@nvidia.com,
	Selvin Xavier <selvin.xavier@broadcom.com>,
	Andrew Gospodarek <andrew.gospodarek@broadcom.com>
Subject: Re: [PATCH rdma-rc v1] RDMA/core: fix sg_to_page mapping for boundary condition
Date: Fri, 26 Aug 2022 10:14:48 -0300	[thread overview]
Message-ID: <YwjHSBr3f4o0hXBX@nvidia.com> (raw)
In-Reply-To: <2651261c642ca672864c2c6c8e7a9774@mail.gmail.com>

On Mon, Aug 22, 2022 at 07:51:22PM +0530, Kashyap Desai wrote:

> Now, we will enter into below loop with dma_addr = page_addr =
> 0xffffffffffffe000 and "end_dma_addr = dma_addr + dma_len" is ZERO.
> eval 0xffffffffffffe000 + 8192
> hexadecimal: 0

This is called overflow.

Anything doing maths on the sgl's is likely to become broken by this -
which is why I think it is unnecessarily dangerous for the iommu code
to general dma addresses like this. It just shouldn't.

> > It should not create mappings that are so dangerous. There is really no
> reason to
> > use the last page of IOVA space that includes -1.
> 
> That is correct, but if API which deals with mapping they handle this kind
> of request gracefully is needed. Right ?

Ideally, but that is a game of wack a mole across the kernel, and
redoing algorithms to avoid overflowing addition is tricky stuff.

> I thought about better approach without creating regression and I found
> having loop using sg_dma_len can avoid such issues gracefully.
> How about original patch. ?

It overflows too.

You need to write the code so you never create the situation where
A+B=0 - don't try to fix things up after that happens.

Usually that means transforming the algorithm so that it works on a
"last byte" so we never need to compute an address that is +1 to the
last byte, which would be the overflown 0.

> Above revert is part of my test. In my setup "iommu_dma_forcedac = $2 =
> false".

So you opt into this behavior, OK

Jason

  reply	other threads:[~2022-08-26 13:15 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-16  8:11 [PATCH rdma-rc v1] RDMA/core: fix sg_to_page mapping for boundary condition Kashyap Desai
2022-08-18 23:52 ` Jason Gunthorpe
2022-08-19  9:43   ` Kashyap Desai
2022-08-19 11:48     ` Jason Gunthorpe
2022-08-22 14:21       ` Kashyap Desai
2022-08-26 13:14         ` Jason Gunthorpe [this message]
2022-09-01 12:06           ` Kashyap Desai
2022-09-06 17:33             ` Jason Gunthorpe
2022-09-12 11:02               ` Kashyap Desai
2022-09-20 19:14                 ` Jason Gunthorpe

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=YwjHSBr3f4o0hXBX@nvidia.com \
    --to=jgg@nvidia.com \
    --cc=andrew.gospodarek@broadcom.com \
    --cc=kashyap.desai@broadcom.com \
    --cc=leonro@nvidia.com \
    --cc=linux-rdma@vger.kernel.org \
    --cc=selvin.xavier@broadcom.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.