Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Alistair Popple <apopple@nvidia.com>
To: "Christian König" <christian.koenig@amd.com>
Cc: "Jason Gunthorpe" <jgg@ziepe.ca>,
	"Dave Airlie" <airlied@gmail.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: Mon, 30 Nov 2026 22:52:15 +1100	[thread overview]
Message-ID: <aw1S9_aGYflXPzjU@nvdebian.thelocal> (raw)
In-Reply-To: <eae24bcc-5d49-4f7a-a66b-164e8ff73bdd@amd.com>

On 2026-11-28 at 00:44 +1100, Christian König <christian.koenig@amd.com> wrote...
> On 11/27/26 13:57, Jason Gunthorpe wrote:
> > 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.
> 
> Yes, because I think that this is not sufficient to prevent importers from doing nasty things.
> 
> >>> 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?
> 
> No, that doesn't even remotely belong to DMA-buf.
> 
> What could be done inside DMA-buf is converting dma-addr[] and SGT. Because we need that for backward compatibility.
> 
> But creating the DMA addresses from the physical addresses is low level DMA API and is not a task the DMA-buf framework should fulfill.
> 
> Again: DMA-buf is just the utility which allows importers and exporters to exchange information how to access a buffer.
> 
> >>> 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?
> 
> We shouldn't. That is not what I'm suggesting.
> 
> > 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.
> 
> Well I completely agree that this shouldn't be open coded in drivers, but it also doesn't belong into DMA-buf.
> 
> DMA-buf is just the utility which allows you to communicate the parameters and the result of the mapping/translation back and forth between importer and exporter.
>
> DMA-buf is not and should not be involved in creating the actually mapping, that is the job of a low level DMA API.

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.

 - Alistair

> Christian.
> 
> > 
> > Jason
> 


  reply	other threads:[~2026-12-01  4:42 UTC|newest]

Thread overview: 69+ 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 [this message]
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
2026-12-02 13:28                                         ` Jason Gunthorpe
2026-12-02 13:47                                           ` Christian König
2026-12-02 13:55                                             ` Jason Gunthorpe
2026-12-02 13:25                                       ` Jason Gunthorpe
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

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=aw1S9_aGYflXPzjU@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox