🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
14 messages
14 total messages Started by Jason Gunthorpe Mon, 23 Nov 2026 16:57
Re: [PATCH v3 03/24] dma-buf: Add the SGT DMA mapping type
#21166
Author: Jason Gunthorpe
Date: Mon, 23 Nov 2026 16:57
40 lines
13892 bytes
On Mon, Nov 23, 2026 at 02:36:46PM +0100, Christian König wrote:
> On 11/20/26 06:55, Alistair Popple wrote:
> > From: Jason Gunthorpe <jgg@nvidia.com>
> > 
> > The SGT (Scatter Gather Table) DMA mapping type represents the existing
> > sg_table/scatterlist based DMA mapping. For now it continues to use a
> > sg_table for map/unmap, but this will allow a future patch series to
> > convert to using a different data structure for importers without having
> > to convert all at once.
> 
> I strongly think we shouldn't have an SGT mapping type in the new DMA-buf mapping API.
> 
> Instead we should have something like either an array or an xarray
> of DMA addresses.

My plan was always to get there, but I don't think it is reasonable to
start there? There are too many places all over the place that are
just hardwired to do SGT right now.

Part of the design of this series was to allow the conversion away
from SGT to be done incrementally without breaking compatibility.

So it is effectively this:

> The framework should then either connect the SGT directly if both
> importer and export are using the "classic" interface 

And this:

> or convert
> from DMA-addr array to SGT and back if either of them are using this
> new interface.

Is something I imagined as a followup series.

As this is actually quite complicated and needs discussion exactly
what it will look like.

Jason
Re: [PATCH v3 03/24] dma-buf: Add the SGT DMA mapping type
#21812
Author: Jason Gunthorpe
Date: Tue, 24 Nov 2026 14:00
44 lines
14062 bytes
On Mon, Nov 23, 2026 at 07:37:41PM +0100, Christian König wrote:
> > Part of the design of this series was to allow the conversion away
> > from SGT to be done incrementally without breaking compatibility.
> 
> Do you know the joke from the hitchhikers guide to the galaxy where
> the dolphins are happy for exactly the same reasons?
> 
> I'm pushing against this plan for exactly the same reason because I
> think it will make the conversation away from SGT even more
> problematic than it already is.

I think it is well proven that trying to do big bang conversions in
software doesn't work well. :(
 
> > So it is effectively this:
> > 
> >> The framework should then either connect the SGT directly if both
> >> importer and export are using the "classic" interface 
> 
> Yeah but that should not be a separate mapping type, it's rather
> that we just convert back and forth from DMA addresses to SGT for
> compatibility reasons.

The mapping type is to support ualink/etc that don't do "DMA".

Only DMA API can create dma_addr_t's, you can't reuse those types for
something else.

And you still need a scheme to negotiate exactly what kind of
connection you need. Focusing on the SGT is missing the big picture of
why this was organized like this.

> > As this is actually quite complicated and needs discussion exactly
> > what it will look like.
> 
> Actually that is the easy step I think because quite a lot of
> drivers already convert the SGT to a DMA addr array outside of the
> DMA-buf framework anyway.

Given the importer an array is not so bad. Getting the sgt out of the
importer will be a debate.

Jason
Re: [PATCH v3 03/24] dma-buf: Add the SGT DMA mapping type
#21840
Author: Jason Gunthorpe
Date: Tue, 24 Nov 2026 14:20
47 lines
14626 bytes
On Tue, Nov 24, 2026 at 01:36:21PM +0100, Christian König wrote:
> > The core then negotiates compatible types and adds converters between them,
> 
> I have strong objections to that plan and would potentially NAK it.
> 
> DMA-buf should *NEVER* accept CPU physical addresses nor provide
> conversion between different address types.
> 
> Keep in mind that DMA-buf is solely a container for DMA addresses,
> nothing else and it should not provide any mapping functionality
> whatsoever.

dmabuf needs to provide support for drivers to help them use the
interface, and going from physical to dma_addr_t is absolutely a
common task every driver must do. I don't care how you call it, but it
is a service that must be provided by *something* and matched to the
needs of dmabuf.

I will definitely NAK any direction to open code dma mapping in every
driver again. If we are going away from SGT then we are fixing all the
DRM mistakes, including the wrong open coded DMA mapping, sketchy use
of SGT, and abuse of P2P that seems to be endemic in drm.

Meaing the exporter constructs a phys_addr list, gets a P2P provider,
and some common code constructs what is passed to the importer. I
don't care if this is in "dmabuf" or some "dmabuf library" or
*whatever* but it must exist as common shared code.

dma_buf_phys_vec_to_sgt() is the template how to implement this
transformation.

> > and having SGT as a type is what allows that. It only exists for unconverted
> > exporters and importers and eventually goes away once everything is converted.
> > The idea being we don't have to convert everything all at once, whilst also being
> > able to add support for different interconnect types. Are you ok with the SGT
> > type if it is just transitional?
> 
> Not really, it just complicate things.
> 
> What we should do with the mapping interface is to add the
> information in which domain the DMA addresses are to be used.

You need to negotiate the actual C data types too, especially if you
want to do that nasty idea where dmabuf populates an iommu domain.

Jason
Re: [PATCH v3 03/24] dma-buf: Add the SGT DMA mapping type
#22055
Author: Jason Gunthorpe
Date: Tue, 24 Nov 2026 19:46
29 lines
13207 bytes
On Tue, Nov 24, 2026 at 05:02:31PM +0100, Christian König wrote:
> The whole conversion from phys_vec to DMA addresses is something
> some API should provide based on the data the exporter/importer have
> negotiated (e.g. p2pdma_provider for example).

Yeah, probably, and this is exactly why I think it will take some
time. Building a new something in lib/ like this is not a
straightforward task.

But also, this:

> > You need to negotiate the actual C data types too, especially if you
> > want to do that nasty idea where dmabuf populates an iommu domain.
> 
> Yeah agree as well, but to be honest that task is negligible. We
> first need to figure out where to put the code.

Means you need to get the phys_addr_t into the dma-buf code so it can
do this conversion.

I'm still absolutely NAKity against allowing any DRM driver visibility
to an importer's iommu_domain if we do this hack.

I don't see how to meet all these concerns without making dma-buf into
a "converter" framework...

Regards,
Jason
Re: [PATCH v3 03/24] dma-buf: Add the SGT DMA mapping type
#22646
Author: Jason Gunthorpe
Date: Wed, 25 Nov 2026 15:55
91 lines
15966 bytes
On Wed, Nov 25, 2026 at 12:19:08PM +0100, Christian König wrote:
> The low level API which talks for example to the IOMMU driver for
> creating the information how to access the buffer is simply not the
> task at hand for that framework. The stuff we already handle is more
> than complicated enough.

No matter what name you give it we need something in the middle that
can see the phys_addr_t and the iommu_domain..

If you don't want DMABUF to be that thing, then I'm not sure what you
have in mind.

> > If I drop the type/placement negotiation for now and focus on SGT removal I can
> > simplify things a lot. Plan would be something like:
> > 
> > 1) Introduce a new C data type (dma_phys_list?) for exporters to pass physical
> >    location info and context for mapping.
> 
> Something like this maybe?
> 
> struct {
> 	u32	mapping_type;
> 	u32	num_entries;
> 	union {
> 		dma_addr_t	*dma_addr;
> 		u64		*generic_64bit_addr;
> 		...
> 	};
> }
> ....

"phsyical location info" means phys_addr_t and related, not
dma_addr_t. Step #3 has it as the *input* to dma_phys_list_to_sgt().

The flow today has the exporter get a phys_addr_t (ie a struct page),
build a scatterlist and directly invoke the DMA API.

The primary issue here is the exporter *direct* call to the DMA API!

We cannot disconnect this from the DMA API, ie to use an iommu domain
or ualink, if exporting drivers are hardwiring calls into it.

Fundamentally the need is for the driver to get the phys_addr list,
exactly like today, and then pass it to an op which formats that into
the right data structure for the importer. Be it dma_addr[],
iommu_domain, or some ualink_addr[] - or whatever.

This is the main issue here, disconnecting the exporters from being
hardwired to the DMA API.

That's what Alistair is explaining. This sequence:

> > 2) Introduce two new dma_buf_ops - map_dma_phys_list() and unmap_dma_phys_list()
> >    - which are replacements for {un}map_dma_buf that converted exporters use to
> >    return a dma_phys_list instead of returning a sg_table.
> >
> > 3) Move dma_buf_phys_vec_to_sgt() somewhere other than drivers/dma-buf and
> >    rename it dma_phys_list_to_sgt().

> > 4) Update dma_buf_{un}map_sgt() to call the new map_dma_phys_list() ops and
> >    dma_phys_list_to_sgt() to create an sg_table for unconverted importers
> >    importing from a converted exporter.

Effectively converts all the exporters to produce a phys_addr_t, and
then moves the DMA mapping action into one single place in common
code.

With one single place we can figure out how to replace it with a call
that does an iommu_domain:

> > 5) Add dma_buf_iommu_map() taking a IOMMU domain/iova/offset/size to be called
> >    from iommufd for mapping an attachment into an IOMMU domain.

But that relies on iommu_map having access to the dma_phys_list *which
is true physical*

> I think a whole bunch of other drivers would be really happy to use
> that interface as well, yes.

Right, that is clear now, that it is not just iommufd that wants a
dma_buf_iommu_map()

But I don't understand at all how you imagine to implement
dma_buf_iommu_map() if you don't want this in the DMABUF core code.

> That totally sounds like a plan to me.

I'm confused if you agreed to what Alistair said :(

Jason
Re: [PATCH v3 03/24] dma-buf: Add the SGT DMA mapping type
#22713
Author: Jason Gunthorpe
Date: Wed, 25 Nov 2026 19:07
86 lines
16047 bytes
On Wed, Nov 25, 2026 at 07:17:51PM +0100, Christian König wrote:
> On 11/25/26 16:55, Jason Gunthorpe wrote:
> > On Wed, Nov 25, 2026 at 12:19:08PM +0100, Christian König wrote:
> >> The low level API which talks for example to the IOMMU driver for
> >> creating the information how to access the buffer is simply not the
> >> task at hand for that framework. The stuff we already handle is more
> >> than complicated enough.
> > 
> > No matter what name you give it we need something in the middle that
> > can see the phys_addr_t and the iommu_domain..
> 
> No, absolutely not. That should be given to the exporter so that the
> exporter can call the DMA API to create the DMA addresses for the
> importer.

I think I've said it many times, and I thought you agreed: NAK to
giving GPU exporter drivers an iommu domain.

> The idea here is that the importer give all the information to the
> exporter so that the exporter can do the mapping on behalves of the
> importer.

No GPU driver must touch these internal details, they must only use
standard abstracted APIs that prevent them from abusing things.

My fear of DRM drivers abusing the DMA process is equal and possibly
greater than your fear of phys_addr_t :P

We are not giving DRM a nightmare API to continue to shoot us in the
foot with.

> > The primary issue here is the exporter *direct* call to the DMA API!
> 
> Why?

Because we need things to be mapped in ways the DMA API will never
support.

DMA API will never support something like dma_buf_iommu_map(). I have
no idea at all how you expect to build this if exporters are directly
calling DMA API. It is not possible.

> > We cannot disconnect this from the DMA API, ie to use an iommu domain
> > or ualink, if exporting drivers are hardwiring calls into it.
> 
> Well the plan is to not disconnect it at all. The exporting drivers
> just says to the underlying API here is my buffer please map that
> for this importer and that result is then given back to the importer
> through the DMA API again.

DMA API will only do basic PCI DMA mappings into dma_addr_t.

It will never handle iommu_domain, it will never handle ualink/etc.

Give us a plan for those if you don't like any of these ideas.

> > Fundamentally the need is for the driver to get the phys_addr list,
> > exactly like today, and then pass it to an op which formats that into
> > the right data structure for the importer. Be it dma_addr[],
> > iommu_domain, or some ualink_addr[] - or whatever.
> 
> No, the phys_addr type should only ever been seen by the DMA API and
> not by DMA-buf.

Again, I don't care how you label things or what "library" they live
in, I can't tell if we are nitpicking names or what.

But there needs to be some kind of abstraction that takes in
phys_addr_t and makes sgt, dma_addr_t, or iommu_domain depending on
what the importer needs.

Exporters must not open code that.

Obviously DMABUF is involved here *somehow* since it is the only thing
that knows an importer even exists.

Would you be happy if we made a 'dma mapping for dmabuf' library that
did all of this and DMABUF just passes its type opaquely and drivers
just call its tightly abstracted functions?

That is the component Alistair is proposing, he just prefixed it with
dmabuf_* as the namespace because, lets be honest, only dmabuf needs
this weird looking thing.

Jason
Re: [PATCH v3 03/24] dma-buf: Add the SGT DMA mapping type
#23258
Author: Dave Airlie
Date: Thu, 26 Nov 2026 22:29
107 lines
17916 bytes
On Thu, 26 Nov 2026 at 03:26, Christian König <christian.koenig@amd.com> wrote:
>
> On 11/24/26 07:23, Alistair Popple wrote:
> > On 2026-11-24 at 05:37 +1100, Christian König <christian.koenig@amd.com> wrote...
> >> On 11/23/26 17:57, Jason Gunthorpe wrote:
> >>> On Mon, Nov 23, 2026 at 02:36:46PM +0100, Christian König wrote:
> >>>> On 11/20/26 06:55, Alistair Popple wrote:
> >>>>> From: Jason Gunthorpe <jgg@nvidia.com>
> >>>>>
> >>>>> The SGT (Scatter Gather Table) DMA mapping type represents the existing
> >>>>> sg_table/scatterlist based DMA mapping. For now it continues to use a
> >>>>> sg_table for map/unmap, but this will allow a future patch series to
> >>>>> convert to using a different data structure for importers without having
> >>>>> to convert all at once.
> >>>>
> >>>> I strongly think we shouldn't have an SGT mapping type in the new DMA-buf mapping API.
> >>>>
> >>>> Instead we should have something like either an array or an xarray
> >>>> of DMA addresses.
> >>>
> >>> My plan was always to get there, but I don't think it is reasonable to
> >>> start there? There are too many places all over the place that are
> >>> just hardwired to do SGT right now.
> >
> > Right. There are around 70 drivers upstream that make use of the sg_table handed
> > down via a dma-buf import, so I don't think it's tractable to convert them all
> > in one go. So obviously we will need some way of phasing this in to give time
> > for each driver change to be implemented, reviewed, etc.
>
> My suggestion is not to convert all drivers in one go, but rather to come up with some sane representation of the DMA addresses instead of using an SGT in the new interface.
>
> > Obviously some of those will share a common structure/helper and conversions
> > will be similar, so that is an over-estimate. But based on an initial poke
> > around there are plenty of drivers that bake the sg_table more deeply into their
> > data structures.
> >
> >>> Part of the design of this series was to allow the conversion away
> >>> from SGT to be done incrementally without breaking compatibility.
> >>
> >> Do you know the joke from the hitchhikers guide to the galaxy where the dolphins are happy for exactly the same reasons?
> >>
> >> I'm pushing against this plan for exactly the same reason because I think it will make the conversation away from SGT even more problematic than it already is.
> >>
> >>> So it is effectively this:
> >>>
> >>>> The framework should then either connect the SGT directly if both
> >>>> importer and export are using the "classic" interface
> >>
> >> Yeah but that should not be a separate mapping type, it's rather that we just convert back and forth from DMA addresses to SGT for compatibility reasons.
> >
> > Right, I think this is actually fairly close to my plan, which is to provide a type
> > for each address class an exporter can produce - either a CPU physical address
> > or some device context + P2P/MMIO address but in future could be some other
> > interconnect type.
> >
> > The core then negotiates compatible types and adds converters between them,
>
> I have strong objections to that plan and would potentially NAK it.
>
> DMA-buf should *NEVER* accept CPU physical addresses nor provide conversion between different address types.
>
> Keep in mind that DMA-buf is solely a container for DMA addresses, nothing else and it should not provide any mapping functionality whatsoever.

Is that because it's called dma-buf, if we just called it's shared-buf
would that alleviate things? I just feel like there are use-cases
where it containing CPU physical addresses might be what is optimal
for a certain scenario, and re-creating a whole parallel
infrastructure that ends up being 'I-can't-believe-it's-not-dma-buf'
would end up being bad.

If we need to shared object backings and have clearly typed and
negotiated on what the backing contains then we should allow it.
However I mostly agree on the mapping thing, I'd want drivers to
negotiate and natively support whatever backings they can rather than
having an intermediate trying to handle the conversions Not saying the
code doing the conversions can't be a helper, bit it shouldn't ever be
autoamtic or outside driver control.

Dave.
Re: [PATCH v3 03/24] dma-buf: Add the SGT DMA mapping type
#23278
Author: Jason Gunthorpe
Date: Fri, 27 Nov 2026 00:37
11 lines
12632 bytes
On Thu, Nov 26, 2026 at 10:58:13AM +0100, Christian König wrote:
> Would it help if have a call on Teams or similar services to discuss the whole thing?
> 
> That might be easier and especially faster than by mail.

I think that is a good idea, I suggest you and Alistair should pick a
time and see who else can come. From experience eu/au/eastern na
doesn't jive :)

Jason
Re: [PATCH v3 03/24] dma-buf: Add the SGT DMA mapping type
#23535
Author: Jason Gunthorpe
Date: Fri, 27 Nov 2026 12:57
65 lines
15564 bytes
On Fri, Nov 27, 2026 at 09:04:15AM +0100, Christian König wrote:

> If we somehow prevent the CPU physical address from being casted to
> a struct page and/or used with vmf_insert_pfn/page/dma_map_page
> etc.. then there is not much of a problem with passing around
> physical addresses.

I already offered that in v1 of the series using limits on
EXPORT_SYMBOL and you NAK'd it too.

> > If we need to shared object backings and have clearly typed and
> > negotiated on what the backing contains then we should allow it.
> > However I mostly agree on the mapping thing, I'd want drivers to
> > negotiate and natively support whatever backings they can rather than
> > having an intermediate trying to handle the conversions Not saying the
> 
> Yes, exactly that's my concern as well. We need to avoid this middle
> layer trap.

You avoid middle layers by having reasonable subsystem helpers for
things to use to build their stuff, especially to encapsulate common
patterns. These helpers are part of the subsystem, or in a related
subysstem helper library.

In Linux terms middle layer almost always means something wrapping a
function pointer callback into a driver and enforcing specific actions
on top of that. The recommended counter is to have the driver perform
the actions with helpers and not wrapper the ops. It particularly came
from the block world where they stuck something like SCSI after the
block ops but before the driver.

It is hard to see that DMABUF is anywhere close to a middle layer.

This is also why we don't understand your remarks about
dma_buf_phys_vec_to_sgt(). Of course it belongs in dmabuf, it produces
the dmabuf spec'd mangled scatterlist that only dmabuf uses. Where
else would you put this code?

> > code doing the conversions can't be a helper, bit it shouldn't ever be
> > autoamtic or outside driver control.

I think you do want it automatic, if an exporter is new and makes,
say, a dma_addr_t[] and the importer is old and wants a sgt, why
should we be open coding anything in every driver to deal with this?

You can argue if it is automatic because the driver called a very
general helper or automatic because the helper is wrapping a callback,
but that should be a fairly minor quibble not a huge thread full of
NAKs.

Ultimately DMABUF has a fairly simple flow:
 1) Allow importer/exporter to negotiate what kind of interconnect
    they want to use (PCI, ualink, etc)
 2) Give the exporter enough information about the interconect path to
    make a placement decision
 3) Describe the exporter's buffer so any mappings/translation/etc can
    be setup for the importer
 4) Program the importers HW.

Many of these have very common patterns, like PCI GPUs always make the
same kind of VRAM placement decision in #2 based on P2P support. This
should all be in helpers under the dmabuf umbrella and not open coded.

Jason
Re: [PATCH v3 03/24] dma-buf: Add the SGT DMA mapping type
#24960
Author: Dave Airlie
Date: Tue, 01 Dec 2026 04:05
52 lines
15476 bytes
> The problem is I can't figure out how to build that low level API.
>
> The current low level DMA API can't correctly handle PCIe P2P, or IOMMUFD, or
> the KVM/confidential compute use-cases (I'm less familiar with those). It can
> only handle creating a DMA mapping for system memory for a specific importing
> device.
>
> So I assume you are talking about some new API. Following Dave's lead lets call
> that shared_buf_map(). That would need to take some importing device context
> so that it could dispatch to the correct mapping code and a list of physical
> locations the exporter needs mapped.
>
> At a high level something like:
>
> struct dma_addr_list *shared_buf_map(import_context, location_list);
>
> Where the import_context is some importer specific struct opaque to the exporter
> and the location list is a list of either PCIe MMIO or system RAM physical
> addresses.
>
> Every exporter ->map_dma_buf() should call shared_buf_map() instead of
> open-coding their own mapping code, as I think we all agree we don't want that
> open-coded.
>
> Placement selection can be dealt with as a separate topic, so setting that
> aside means passing in the same location list regardless of importing device.
> shared_buf_map() then has to dispatch to the correct mapping generation code -
> either DMA API, PCIe peer-to-peer API, IOMMUFD API, KVM API or maybe some other
> importing device/driver specific API.
>
> I could see how that could be made to work, but it seems more complex than
> a dma_buf exporter op that returns a list of physical locations and a helper
> library that importers call to do the mapping into whatever importer specific
> context is needed. Instead you would have to add importer specific callbacks
> that the shared_buf_map code could call along with plumbing the importer context
> through.

This is where I got to thinking it might end up, not that we have an
export function that actually exports anything, but merely advertises
this provider has an object with this fd and it can export it in these
ways.

Then on import we'd have to go into the exporter and setup the object
that gets shared between that specific importer/exporter combination
and not always have a singular export, but one per import, that I
suppose could be refcounted per export if lots of importers wanted the
same thing.

Now maybe we can't call this dma-buf, but I think dma-buf is a subset of this.

Dave.
Re: [PATCH v3 03/24] dma-buf: Add the SGT DMA mapping type
#25361
Author: Jason Gunthorpe
Date: Tue, 01 Dec 2026 16:22
19 lines
13517 bytes
On Tue, Dec 01, 2026 at 02:24:49PM +0100, Christian König wrote:

> First of all a physical address is only what the CPU can see, but
> there are a lot of use cases where you need to access resources the
> CPU can't reach. For example hidden device memory or even system
> memory where the CPU intentionally has no address for because of
> digital rights management reasons etc... Taking a look at all the
> use cases I have seen I would say that DMA-buf actually contains
> more non CPU accessible resources than CPU accessible ones.

I think these cases are the private interconnect like "XGMI,
GDS/GWS/OA, I2C, I2S" you mentioned.

It is really clear any solution needs something for DMA API users that
must be phys_addr_t based, and something to negotiate the universe of
botique interconnects that cannot use the DMA API.

Jason
Re: [PATCH v3 03/24] dma-buf: Add the SGT DMA mapping type
#25547
Author: Dave Airlie
Date: Wed, 02 Dec 2026 00:47
114 lines
18357 bytes
On Tue, 1 Dec 2026 at 23:25, Christian König <christian.koenig@amd.com> wrote:
>
> On 12/1/26 10:33, Alistair Popple wrote:
> > On 2026-12-01 at 19:11 +1100, Christian König <christian.koenig@amd.com> wrote...
> >> On 12/1/26 08:13, Alistair Popple wrote:
> >>> On 2026-12-01 at 15:05 +1100, Dave Airlie <airlied@gmail.com> wrote...
> >>>>> The problem is I can't figure out how to build that low level API.
> >>
> >> Seconded.
> >>
> >> I can give you quite a bunch of requirements based on what the high level DMA-buf API and uAPI has on functionality and based on what I have seen on use cases in the wild.
> >
> > I think a bunch of requirements would be helpful, because they've kind of been
> > scattered across threads at this point and I concluded it was kind of impossible
> > to build given the constraints.
> >
> > In particular the one thing that PCIe P2P, IOMMUFD, KVM, etc. all need is the
> > physical address. That is the vendor agnostic thing below but providing that has
> > been consistently NACKed and I can't see how you can make any low level API work
> > without having the physical address.
>
> Yeah good point, let's start with that one. There are multiple problems with using physical addresses.
>
> First of all a physical address is only what the CPU can see, but there are a lot of use cases where you need to access resources the CPU can't reach. For example hidden device memory or even system memory where the CPU intentionally has no address for because of digital rights management reasons etc... Taking a look at all the use cases I have seen I would say that DMA-buf actually contains more non CPU accessible resources than CPU accessible ones.
>
> Then especially for PCI a physical address is only halve the information you need. The importer can also need additional info to stitch together the TLP, like SH, snooping bit, atomic access ops etc....
>
> Then there is the reason that we have seen a tremendous amount of cases where importers abused the physical address and/or struct page pointer which was unfortunately accessible through the SGT. To be honest I can't count the number of CVE entries given to such bugs.
>
> There are some use cases for KVM for example which need physical addresses, but to be honest they look like corner cases.
>
> Ideally even the exporter shouldn't work with physically addresses I think. For example even when you have a PCI P2P API which fills in your mapping it should work with PCI BAR, offset and length and and not a physical address into the BAR.
>
> > I know in the past you've suggested passing all the importer context through to
> > the exporter, but that is also a complete non-starter. It lets arbitrary drivers
> > implement the mapping wrong and likely get all the life-times, which belong to
> > the importer, wrong. So until we can solve that I'm not really seeing much of
> > way forward here.
>
> WOW, wait a second. With the exception of the old interface which pins things down the lifetime of the mapping belongs to the exporter and not the importer!

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.

This directly conflicts with Jason's idea that I'm not giving
exporters the importers iommu_domain. I think we have to break this
deadlock to move forward.

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.

Then the importer has to give the exporter the "dma-buf", the type of
import and a set of meta-data about the type so the exporter can
create the mapping and track it, so it can clean it up later no matter
what the importer does. The exporter owns the lifetime of the object
and all things created from it. The exporter then gives back to the
importer a result of per-type meta-data.

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.
for iommufd, import meta-data is the iommu_domain, the exporter maps,
and hands back the correct table of addresses
for UALINK, import meta-data is some ualink handle, and the result is
some other ualink handle.

The common theme being the exporter has enough information to always
be able to clean up anything it exported.

If neither side gives on this I think it will continue to be stuck.

Dave.
Re: [PATCH v3 03/24] dma-buf: Add the SGT DMA mapping type
#25550
Author: Jason Gunthorpe
Date: Wed, 02 Dec 2026 01:30
76 lines
16061 bytes
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..

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.

> This directly conflicts with Jason's idea that I'm not giving
> exporters the importers iommu_domain. I think we have to break this
> deadlock to move forward.

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.

> 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.

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.

> 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.

But if that end up being the only thing that we disagree on then fine,
but no giving it directly to any DRM drivers.

Jason
Re: [PATCH v3 03/24] dma-buf: Add the SGT DMA mapping type
#25553
Author: Dave Airlie
Date: Wed, 02 Dec 2026 01:41
109 lines
18554 bytes
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.

> 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 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.

>
> > 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.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads