mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Christian König" <christian.koenig@amd.com>
To: Alistair Popple <apopple@nvidia.com>
Cc: "Dave Airlie" <airlied@gmail.com>,
	"Jason Gunthorpe" <jgg@ziepe.ca>,
	"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: Tue, 1 Dec 2026 14:24:49 +0100	[thread overview]
Message-ID: <53a32383-4cf6-42ac-bbd5-476e69a3be5f@amd.com> (raw)
In-Reply-To: <aw6MunWRlt-_MIke@nvdebian.thelocal>

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!

That's one of the reasons why the exporter needs the IOMMU context of the importer for example, otherwise you can't forcefully remove IOMMU mappings without relying on the importer doing that for you.

>> But I can't say either what the low level API needs to look like and one of the major reasons I want DMA-buf separated from that low level API is that it seems like this needs a different field of expertise and responsibilities.
> 
> I get it, and I do appreciate the expertise provided here. However if DMA-buf
> is supposed to be some separate mechanism just for passing pointer types between
> exporter/importer with some lifetime and location negotiation rules it shouldn't
> also be seeking to impose constraints on what information those types actually
> contain. That is none of it's business and is up to what the low level API
> needs.

I have to admit that's a pretty good argument, but I would say the restriction is on the exporter, importer and which role is using what and not the low level API itself.

> If the low level API needs importer context and physical addresses to do
> anything useful then so be it.

As long as the low level API is only called by the exporter I have no problem with it taking physical addresses when it is sufficient for the use case.

I just think that we have use cases where the exporter needs to give additional information to the physical address to the IOMMU driver for example.

I need to attend some customer stuff now and will try to answer the rest of the mail later today.

Regards,
Christian.

>>>>>
>>>>> 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.
>>
>> That sounds totally sane to me, yes.
> 
> Ok. The problem is how this shared_buf_map() gets the importer context.
> 
> It would be easy enough to make work if an impoter could call eg.
> shared_buf_map(import_type, attachment) or something like that, but I got the
> impression from the middle-layer discussion that that would be undesirable and
> get NACKed because only exporter should call that. So not sure how to actually
> make that work, unless my impression there is wrong.
> 
>>>>>
>>>>> 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.
>>
>> I've thought about that as well for a while but came to the conclusion that we most likely want some more differentiation here.
>>
>> On the one hand we have the vendor agnostic things like PCI P2P, IOMMU, IOVAs, bus addresses, CPU physical addresses etc... which a vendor agnostic API should be dealing with.
> 
> Right - I'd like to tackle the vendor agnostic things, as they provide the most
> value. Vendor specific things have already been hacked up to work in all sorts
> of horrible ways, which is why I want to fix this so I can at least remove some
> of the horrid hacks from our code.
> 
>> On the other hand we have vendor specific things like XGMI, GDS/GWS/OA, I2C, I2S, doorbells, <just name the strange thing people stuffed into a DMA-buf> which only specific drivers understand.
>>
>> The problem is now that those things at least partially overlap, for example a doorbell which is ringed by a PCI P2P write.
> 
> I'd argue that a doorbell rung by a PCI P2P write isn't any different than any
> other PCI P2P access. The data in these buffers doesn't change the type from a
> buffer sharing perspective, the type of data in these buffers is always up to
> some other layer (eg. userspace), so I don't see the overlap.
> 
>>>>
>>>> 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.
>>
>> Yes that is a requirement of ROCm as well and we have hacked around such things massively with the KFD and all the rat tail of consequences seen by it.
> 
> I should introduce you to RM :-)
> 
> Thanks.
> 
>  - Alistair
> 
>>> That sounds reasonably complex. Do you have a vague plan, ideally in the form
>>> of data-structures/API definitions, that would help explain what it would look
>>> like?
>>>
>>> For now I have sent a simplified RFC series -
>>> https://lore.kernel.org/dri-devel/20261201-dmabuf_shared_buf_v1_xe_rc5-v1-0-b672717c7fc9@nvidia.com/T/#t - that drops the placement
>>> bits and implements the rough plan I outlined in
>>> https://lore.kernel.org/dri-devel/awZ_Os1pXelOGaFP@nvdebian.thelocal/ . I'm not
>>> sure it addresses everything, but I'd be interested in getting feedback on what
>>> it gets right and what specifically needs fixing/changing, and how, to satisfy
>>> the design constraints.
>>>
>>> Thanks.
>>>
>>>  - Alistair
>>>
>>>> Now maybe we can't call this dma-buf, but I think dma-buf is a subset of this.
>>
>> I would say that DMA-buf is the high level API which allows importers and exporters to exchange the data structures of the low level API.
>>
>> Christian.
>>
>>>>
>>>> Dave.
>>


  parent reply	other threads:[~2026-12-01 13:25 UTC|newest]

Thread overview: 49+ 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-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
     [not found]         ` <awT8prWsj11TBdmP@nvdebian.thelocal>
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
     [not found]                   ` <awZ_Os1pXelOGaFP@nvdebian.thelocal>
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
     [not found]                             ` <awfMy1d8ICL6mr9i@nvdebian.thelocal>
2026-11-26  9:58                               ` Christian König
2026-11-27  0:37                                 ` Jason Gunthorpe
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
     [not found]                     ` <aw1S9_aGYflXPzjU@nvdebian.thelocal>
2026-12-01  4:05                       ` Dave Airlie
2026-12-01  7:13                         ` Alistair Popple
2026-12-01  8:11                           ` Christian König
     [not found]                             ` <aw6MunWRlt-_MIke@nvdebian.thelocal>
2026-12-01 13:24                               ` Christian König [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-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-20  5:56 ` [PATCH v3 24/24] dma-buf: Add kunit tests for mapping type selection Alistair Popple

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=53a32383-4cf6-42ac-bbd5-476e69a3be5f@amd.com \
    --to=christian.koenig@amd.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=apopple@nvidia.com \
    --cc=axboe@kernel.dk \
    --cc=baolu.lu@linux.intel.com \
    --cc=chaitanyak@nvidia.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®