All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@ziepe.ca>
To: Robin Murphy <robin.murphy@arm.com>
Cc: "Krzysztof Karas" <krzysztof.karas@intel.com>,
	intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	iommu@lists.linux.dev, "Andi Shyti" <andi.shyti@linux.intel.com>,
	"Joerg Roedel" <joro@8bytes.org>,
	"Michał Grzelak" <michal.grzelak@intel.com>,
	"Janusz Krzysztofik" <janusz.krzysztofik@linux.intel.com>,
	"Sebastian Brzezinka" <sebastian.brzezinka@intel.com>,
	"Krzysztof Niemiec" <krzysztof.niemiec@intel.com>
Subject: Re: [PATCH v2 3/3] drivers/iommu: Catch scatterlist length overflows
Date: Mon, 6 Jul 2026 11:45:46 -0300	[thread overview]
Message-ID: <20260706144546.GE107792@ziepe.ca> (raw)
In-Reply-To: <a381d265-e7a4-4fe7-9421-3553706d41c1@arm.com>

On Mon, Jul 06, 2026 at 02:08:14PM +0100, Robin Murphy wrote:

> modern use-cases anyway, and is being replaced, so limitations of a "legacy"
> API that don't have any meaningful impact to its existing users are hardly
> something to panic about. If DRM does want to be able to *reliably* map
> massive amounts of RAM then it can adopt the new IOMMU API, for this and all
> the other reasons that that new API was promised to be "better".

Yes the new API does solve these issues, and it avoids padding
destroying the iova contiguity.

> > So I wouldn't be quite so dismissive that this is not something a real
> > user can hit.
> 
> I'm not being dismissive - clearly it can be hit. My point is that anyone
> who *does* hit it can only expect it to fail (as indeed this particular IGT
> test seems to), because it has never worked.

Today you can allocate memory from hugetlbfs and map it through
RDMA. The user can set 1G hugetlbfs page size and allocate 16G of
memory, and RDMA map it. Databases and HPC, for example, love to do
work loads like this.

So there is an unlucky hugetlbfs FD that has an internal memory layout
that will build a scatterlist that cannot be mapped by the iommu.

The user's application that normally works will fail randomly and
infrequently for no fault of their own. This isn't "can only expect it
to fail".

> So yes, limiting any individual segment to <=2GB would end up avoiding both
> those conditions, but it would also impact plenty of cases that *do*
> currently work fine, e.g. 1GB+3GB+3GB. The limitation is really that you
> can't have two consecutive segments where the first starts exactly on a 4GB
> boundary and the sum of both their sizes >=4GB.

Yeah, but that's hard to express.

My feeling was supporting >2GB without a split is not really so
important. You are (righly) arguing these huge sizes are usually rare.
Places like RDMA where they are not rare people already added
re-assembly logic to join SGLs so HW optimizations for >= 4G mappings
can be used, so smaller splitting doesn't really matter.

> > API wise I expect any arbitary input to sg_alloc_table_from_pages() to
> > result in a scatterlist that iommu_dma_map_sg() will map. This
> > patch highlights there are cornere cases where that isn't true, it
> > should be fixed..
> 
> Technically sg_alloc_table_from_pages() carries no such assumption,
> only

There are lots of callers that just do sg_alloc_table_from_pages()
then dma_map_sg(). Callers can use this simplified API when they don't
need any segmentation logic in the DMA API.

> sg_alloc_table_from_pages_segment() (or __sg_alloc_table_from_pages()) with
> the correct dma_seg_boundary value for the given device. 

_segment is the segment size, not boundary. The sg_alloc_table
functions don't support the seg_boundary limitation.

So, how about instead of failing we just don't do any padding? Ie
ignore dma_seg_boundary, and hope the device is modern and doesn't
need it?

Alternatively, can we request to disable dma_seg_boundary somehow in
the driver and stick with the WARN_ON?

Jason

  reply	other threads:[~2026-07-06 14:45 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-01 10:44 [PATCH v2 0/3] drivers: Improve memory management for large object allocations when i915/shmem is used with iommu Krzysztof Karas
2026-07-01 10:44 ` [PATCH v2 1/3] drm/i915/gem: split shared memory allocation table logic Krzysztof Karas
2026-07-01 14:38   ` Andi Shyti
2026-07-02  6:18     ` Krzysztof Karas
2026-07-02 12:01       ` Robin Murphy
2026-07-01 10:44 ` [PATCH v2 2/3] drm/i915/shmem: Count mapped pages in a folio Krzysztof Karas
2026-07-01 10:44 ` [PATCH v2 3/3] drivers/iommu: Catch scatterlist length overflows Krzysztof Karas
2026-07-01 10:59   ` sashiko-bot
2026-07-01 11:59   ` Robin Murphy
2026-07-02  6:22     ` Krzysztof Karas
2026-07-02 12:17       ` Robin Murphy
2026-07-03 16:22   ` Jason Gunthorpe
2026-07-03 18:58     ` Robin Murphy
2026-07-03 20:35       ` Jason Gunthorpe
2026-07-06  7:43         ` Krzysztof Karas
2026-07-06 12:31           ` Jason Gunthorpe
2026-07-06 13:08         ` Robin Murphy
2026-07-06 14:45           ` Jason Gunthorpe [this message]
2026-07-09  7:18             ` Krzysztof Karas
2026-07-01 15:36 ` [PATCH v2 0/3] drivers: Improve memory management for large object allocations when i915/shmem is used with iommu Andi Shyti
2026-07-02  6:10   ` Krzysztof Karas
2026-07-01 15:44 ` ✓ i915.CI.BAT: success for drivers: Improve memory management for large object allocations when i915/shmem is used with iommu (rev3) Patchwork
2026-07-02  6:33 ` ✓ i915.CI.Full: " Patchwork
2026-07-09  8:23 ` ✗ i915.CI.BAT: failure for drivers: Improve memory management for large object allocations when i915/shmem is used with iommu (rev4) Patchwork

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=20260706144546.GE107792@ziepe.ca \
    --to=jgg@ziepe.ca \
    --cc=andi.shyti@linux.intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=iommu@lists.linux.dev \
    --cc=janusz.krzysztofik@linux.intel.com \
    --cc=joro@8bytes.org \
    --cc=krzysztof.karas@intel.com \
    --cc=krzysztof.niemiec@intel.com \
    --cc=michal.grzelak@intel.com \
    --cc=robin.murphy@arm.com \
    --cc=sebastian.brzezinka@intel.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.