From: Alistair Popple <apopple@nvidia.com>
To: Dave Airlie <airlied@gmail.com>
Cc: "Jason Gunthorpe" <jgg@ziepe.ca>,
"Christian König" <christian.koenig@amd.com>,
"Sumit Semwal" <sumit.semwal@linaro.org>,
"Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
"Simona Vetter" <simona.vetter@ffwll.ch>,
"Matthew Brost" <matthew.brost@intel.com>,
"Vivek Kasireddy" <vivek.kasireddy@intel.com>,
"Dongwon Kim" <dongwon.kim@intel.com>,
"Kevin Tian" <kevin.tian@intel.com>,
"Xu Yilun" <yilun.xu@linux.intel.com>,
"Karl Mehltretter" <kmehltretter@gmail.com>,
"Baolu Lu" <baolu.lu@linux.intel.com>,
"Felix Kuehling" <felix.kuehling@amd.com>,
"Alex Deucher" <alexander.deucher@amd.com>,
linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org,
intel-xe@lists.freedesktop.org, amd-gfx@lists.freedesktop.org,
linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org,
linux-rdma@vger.kernel.org, iommu@lists.linux.dev,
"Keith Busch" <kbusch@kernel.org>, "Jens Axboe" <axboe@kernel.dk>,
"Christoph Hellwig" <hch@lst.de>,
"Sagi Grimberg" <sagi@grimberg.me>,
linux-nvme@lists.infradead.org,
"David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@kernel.org>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
"Simon Horman" <horms@kernel.org>,
"Mina Almasry" <almasrymina@google.com>,
netdev@vger.kernel.org, "Alexey Kardashevskiy" <aik@amd.com>,
zhipingz@meta.com, treding@nvidia.com, jhubbard@nvidia.com,
chaitanyak@nvidia.com, "Leon Romanovsky" <leon@kernel.org>
Subject: Re: [PATCH v3 03/24] dma-buf: Add the SGT DMA mapping type
Date: Wed, 2 Dec 2026 14:54:07 +1100 [thread overview]
Message-ID: <aw-FM7FiJvl3R0El@nvdebian.thelocal> (raw)
In-Reply-To: <CAPM=9tzBhoM0cdGVZ-d1T8Dgxtmh6K-zXGLqz9JcswXtQ66EDQ@mail.gmail.com>
On 2026-12-02 at 12:41 +1100, Dave Airlie <airlied@gmail.com> wrote...
> On Wed, 2 Dec 2026 at 11:30, Jason Gunthorpe <jgg@ziepe.ca> wrote:
> >
> > On Wed, Dec 02, 2026 at 10:47:28AM +1000, Dave Airlie wrote:
> >
> > > I think this is clearly where the divide is. I'm with Christian here,
> > > the exporter allocate the resource, then it owns the lifetime of the
> > > resource. In order for it to have complete ownership of the lifetime
> > > of the resource it needs the ability to remove the resource from other
> > > users (i.e. importers). If the exporter wasn't to free some pages, it
> > > should have all the information necessary to do so but traversing a
> > > list of places the object has been imported and a method to forcible
> > > unlink it from that side.
> >
> > If you change iommu mappings without telling the driver you will
> > create data corruption as new mappings can fall to places the device
> > is still doing DMA.
> >
> > The driver MUST be involved in any reclaim/move/revoke process and
> > DMABUF already has APIs for that. Managing this lifetime is one of the
> > main things it does.
> >
> > I don't like this notion we can trust one side more than the other, it
> > isn't like the exporter drivers are amazing clean things either. There
> > is a reasonable level of nannying..
>
> This isn't just about trust, it's about lifetime and ownership. If the
> exporter owns the resource, the exporter should have all necessary
> information to invalidate the resource and give it back to the system.
It does - that is what the reclaim/move/revoke callbacks are for - to tell the
importer to stop using the resource and invalidate any mappings it holds to the
resource because it's about to give it back to the system.
That necessarily has to live in the importer. Take for example PCIe P2P - there
might not be any IOMMU involved, so the only way to tear down the mapping is to
program some importing devices specific MMU (or stop work or whatever importer
specific thing needs doing).
> > Importers are expected to unmap. I think we have to consider any one
> > that doesn't to be broken. You can't fix broken with more broken
> > things like force DMA unmapping and hoping that there is an iommu,
> > then hoping no corruption happens to crash the system.
>
> But we should allow the exporter to tell the imported to invalidate,
> wait for a response and then have the exporter free it. What the
> importer does in the invalidate is up to it, but the exporter controls
> the resource lifetime and any things bound to it. If the importer
> fails to invalidate the resource then that is a clear problem. But an
> exporter can at least control all the mappings for the resource and
> tear them down without leaking things.
I think we may be conflating two things here - the importer contract and a
method of enforcing it.
The revoke contract is "importer invalidates and unbinds from the resource", and
the design should assume that whatever implements that contract gets it correct
including tearing down any access paths.
Obviously nothing can enforce that the revoke code (or HW even!) is correct.
So what I'm hearing is that the exporter should be unmapping as a defense
against bad importers. I can definitely understand why that might be useful,
especially as some kind of debug thing, but I don't think we should be basing
the whole API design around the concept we can't trust importer to implement the
contract correctly. Especially as that defense might not actually exist in a lot
of cases anyway (eg. IOMMU disabled), in which case you have no choice but to
trust the importer got things right.
I also sense there might be a deeper belief that the mapping of a resource
(ie. the IOVA) is something owned by the resource rather than the user of that
resource. But there are actually two resources here, with different owners and
related but different lifetimes - the physical memory and the IOVA (ie. the
mapping to the physical memory).
Obviously the physical memory lifetime is owned and controlled by the exporter.
The IOVA forms part of the importers address space though, which is used for
more than just DMABUF, and so belongs to the importer so it can control it's
layout and lifetime.
Otherwise how say could the importer later reassign an IOVA for a different use?
It could call into the exporter to do the unmap, but then it has to trust that
the exporter does the right thing. Which is exactly why Jason is saying we're
implicitly trusting one side more than the other - we're saying we don't trust
importers to manipulate their own address space correctly so lets have the
exporter do it on behalf of the importer. Even though the exporter has nothing
to do with the IOVA.
It's worth pointing out this is how core-mm works too - it doesn't try and force
unmap things itself. It fires an mmu_notifier when it's about to move the memory
behind a mapping and whatever implements the notifier tears down any local
mappings, whether they be in a device MMU or an IOMMU or both.
> >
> > I just saw someone in drivers/media do the most insane thing with the
> > new DMA API, unbelievable. No matter what we build someone will find a
> > creative way to abuse it.
> >
> > We need to have a 3rd party "Switzerland" if you want to keep this
> > direction that limits the exposure of either side to the details.
>
> If I had rust for this I'd be happier, but we don't get a switzerland,
> but we should at least be speaking in terms of ownership and lifetime
> of resources and what can reasonable be defended against.
Agreed, and I think the crux of the problem is we don't agree on what owns a
mapping/IOVA of a resource.
However I don't think we need Rust to have "Switzerland". We could create
importer and exporter specific data-structures that only some core piece of code
gets to see both sides of. But so far I've sensed push back against that idea.
- Alistair
> >
> > > I think I'm still with Christian though. I think you need to export a
> > > "dma-buf" with a list of supported both platform and device specific
> > > types that it can be imported into.
> >
> > This was the entire idea behind the mapping type series, it came out
> > of Intel asking for support for ualink.
> >
> > > for dma-buf the import meta-data is the struct device, the output
> > > meta-data is a mapped sg for that device.
> > > for PCI P2P, import meta-data might be just the PCI address of the
> > > importer, snooping, atomic access?, maybe we validate it can be
> > > reached, but then we return PCI BAR + offset/length lists.
> >
> > No, the output is always a dma_addr_t, the dma api natively supports
> > P2P. You have to decorate it in a special flow to make it work.
> >
> > Also nothing uses PCI BAR + offset/length. If you want to make that
> > you can in your own "Switzerland" <shrug> but it is an unnatural
> > interface in practice.
>
> Okay maybe on that one we can give in, I do think path + offset/length
> lists might make sense for things like NVLINK/UALINK though were there
> is more arbitrary path to the resource than just what is CPU visible,
> but maybe dma_addr_t can encapsulate that, but for some things it
> might still make sense. A lot of this ends up being just "path cookie"
> + offset/length pairs of arbitary address that make sense for that
> path.
>
> > Even the P2P permitted placement selection shouldn't be open coded in
> > drivers, this is a bit tricky to do well and none of the DRM drivers
> > get there.
>
> Because nobody has written the code to do it?
>
> >
> > > for iommufd, import meta-data is the iommu_domain, the exporter maps,
> > > and hands back the correct table of addresses
> >
> > FWIW it is a huge pita to make things work like this inside iommufd
> > and if it gets messed up then iommufd will explode in a bad way.
> > It is so much easier to feed through phys_addr_t since we already have
> > this infrastructure.
>
> It's easier, but you don't respect lifetimes then.
>
> > But if that end up being the only thing that we disagree on then fine,
> > but no giving it directly to any DRM drivers.
>
> Most likely DRM drivers or any exporter will just want to add it to
> the mapping list and call a generic iommu interface to do the work.
> The big thing being they can control undoing it later.
>
> Dave.
next prev parent reply other threads:[~2026-12-02 3:54 UTC|newest]
Thread overview: 66+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 5:55 [PATCH v3 00/24] DMA-buf mapping types Alistair Popple
2026-11-20 5:55 ` [PATCH v3 01/24] treewide: Rename dma_buf_(un)map_attachment() to dma_buf_(un)map_sgt() Alistair Popple
2026-11-23 13:28 ` Christian König
2026-11-24 2:55 ` Alistair Popple
2026-11-20 5:55 ` [PATCH v3 02/24] dma-buf: Introduce DMA-buf mapping types Alistair Popple
2026-11-20 5:55 ` [PATCH v3 03/24] dma-buf: Add the SGT DMA mapping type Alistair Popple
2026-11-23 13:36 ` Christian König
2026-11-23 16:57 ` Jason Gunthorpe
2026-11-23 18:37 ` Christian König
2026-11-24 6:23 ` Alistair Popple
2026-11-24 12:36 ` Christian König
2026-11-24 14:20 ` Jason Gunthorpe
2026-11-24 16:02 ` Christian König
2026-11-24 19:46 ` Jason Gunthorpe
2026-11-25 7:18 ` Alistair Popple
2026-11-25 11:19 ` Christian König
2026-11-25 15:55 ` Jason Gunthorpe
2026-11-25 18:17 ` Christian König
2026-11-25 19:07 ` Jason Gunthorpe
2026-11-26 6:24 ` Alistair Popple
2026-11-26 9:58 ` Christian König
2026-11-27 0:37 ` Jason Gunthorpe
2026-11-27 4:10 ` Alistair Popple
2026-11-26 22:29 ` Dave Airlie
2026-11-27 8:04 ` Christian König
2026-11-27 12:57 ` Jason Gunthorpe
2026-11-27 13:44 ` Christian König
2026-11-30 11:52 ` Alistair Popple
2026-12-01 4:05 ` Dave Airlie
2026-12-01 7:13 ` Alistair Popple
2026-12-01 8:11 ` Christian König
2026-12-01 9:33 ` Alistair Popple
2026-12-01 13:24 ` Christian König
2026-12-01 16:22 ` Jason Gunthorpe
2026-12-02 0:47 ` Dave Airlie
2026-12-02 1:30 ` Jason Gunthorpe
2026-12-02 1:41 ` Dave Airlie
2026-12-02 3:54 ` Alistair Popple [this message]
2026-11-24 14:00 ` Jason Gunthorpe
2026-11-20 5:55 ` [PATCH v3 04/24] dma-buf: Negotiate the mapping type in dma_buf_dynamic_attach() Alistair Popple
2026-11-20 5:55 ` [PATCH v3 05/24] dma-buf: Route SGT related actions through the attachment's mapping type Alistair Popple
2026-11-20 5:55 ` [PATCH v3 06/24] dma-buf: Allow single exporter drivers to avoid the match_mapping function Alistair Popple
2026-11-20 5:55 ` [PATCH v3 07/24] dma-buf: Convert exporters allocating a table per map to the SGT mapping type Alistair Popple
2026-11-20 9:02 ` Karol Wachowski
2026-11-20 5:55 ` [PATCH v3 08/24] iommufd/selftest: Convert the test exporter " Alistair Popple
2026-11-20 5:55 ` [PATCH v3 09/24] dma-buf: Convert exporters keeping a table per attachment " Alistair Popple
2026-11-20 5:55 ` [PATCH v3 10/24] drm: Convert drm_gem_map_dma_buf() and its users " Alistair Popple
2026-11-20 5:55 ` [PATCH v3 11/24] drm/xe/dma-buf: Use " Alistair Popple
2026-11-20 5:55 ` [PATCH v3 12/24] drm/amdgpu: " Alistair Popple
2026-11-20 5:55 ` [PATCH v3 13/24] udmabuf: Convert to " Alistair Popple
2026-11-21 5:58 ` sashiko-bot
2026-11-20 5:55 ` [PATCH v3 14/24] drm/omapdrm: " Alistair Popple
2026-11-20 5:55 ` [PATCH v3 15/24] accel/ivpu: Convert the userptr exporter " Alistair Popple
2026-11-20 5:55 ` [PATCH v3 16/24] drm/vmwgfx: Use match_mapping instead of dummy calls Alistair Popple
2026-11-20 5:55 ` [PATCH v3 17/24] dma-buf: Convert dma_buf_phys_vec_to_sgt() and its users to the SGT mapping type Alistair Popple
2026-11-20 5:55 ` [PATCH v3 18/24] iio: buffer: convert to use " Alistair Popple
2026-11-20 5:55 ` [PATCH v3 19/24] functionfs: " Alistair Popple
2026-11-20 5:55 ` [PATCH v3 20/24] dma-buf: Remove unused SGT stuff from the common structures Alistair Popple
2026-11-20 5:55 ` [PATCH v3 21/24] dma-buf: Add kunit tests for mapping type Alistair Popple
2026-11-20 5:56 ` [PATCH v3 22/24] dma-buf: Let the exporter select mapping type at pin/map Alistair Popple
2026-11-20 5:56 ` [PATCH v3 23/24] dma-buf: Add dma_buf_mapping_map() returning a type-tagged mapping and implement it for sgt Alistair Popple
2026-11-21 5:58 ` sashiko-bot
2026-11-20 5:56 ` [PATCH v3 24/24] dma-buf: Add kunit tests for mapping type selection Alistair Popple
2026-11-21 5:58 ` sashiko-bot
2026-11-23 4:26 ` Alistair Popple
2026-11-21 5:58 ` [PATCH v3 00/24] DMA-buf mapping types sashiko-bot
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=aw-FM7FiJvl3R0El@nvdebian.thelocal \
--to=apopple@nvidia.com \
--cc=aik@amd.com \
--cc=airlied@gmail.com \
--cc=alexander.deucher@amd.com \
--cc=almasrymina@google.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=axboe@kernel.dk \
--cc=baolu.lu@linux.intel.com \
--cc=chaitanyak@nvidia.com \
--cc=christian.koenig@amd.com \
--cc=davem@davemloft.net \
--cc=dongwon.kim@intel.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=edumazet@kernel.org \
--cc=felix.kuehling@amd.com \
--cc=hch@lst.de \
--cc=horms@kernel.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=iommu@lists.linux.dev \
--cc=jgg@ziepe.ca \
--cc=jhubbard@nvidia.com \
--cc=kbusch@kernel.org \
--cc=kevin.tian@intel.com \
--cc=kmehltretter@gmail.com \
--cc=kuba@kernel.org \
--cc=leon@kernel.org \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=linux-rdma@vger.kernel.org \
--cc=matthew.brost@intel.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sagi@grimberg.me \
--cc=simona.vetter@ffwll.ch \
--cc=sumit.semwal@linaro.org \
--cc=thomas.hellstrom@linux.intel.com \
--cc=treding@nvidia.com \
--cc=vivek.kasireddy@intel.com \
--cc=yilun.xu@linux.intel.com \
--cc=zhipingz@meta.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.