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: "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, 24 Nov 2026 13:36:21 +0100	[thread overview]
Message-ID: <63eb7b6e-e0a8-4443-a434-0301ed59beae@amd.com> (raw)
In-Reply-To: <awT8prWsj11TBdmP@nvdebian.thelocal>

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.

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

The conversion between SGT and DMA address array is an exception we can make to aid transition between the old and the new interface, but that is basically a 1 to 1 copy between different data structures.

> As discussed a bit previously types also add enforcement of the rules around when
> the exporter type/location can change.
> 
> I do have most of this coded up, so can post a mega series of all patches if
> it's helpful to see the overall direction in code form. I didn't do that because
> this conversion of exporters to not return sg_tables makes it quite a large
> patch series, so I was going to post them as separate RFCs building on top of
> this. Not sure if you have a preference there?

I think we should have the core interface plus some test cases and at least one driver converted over as example of how the new interface would be used.

>>> And this:
>>>
>>>> or convert
>>>> from DMA-addr array to SGT and back if either of them are using this
>>>> new interface.
>>>look like 
>>> Is something I imagined as a followup series.
>>>
>>> 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.
>>
>> The more complicated one is then starting to come up with more bus types and doing optimization work.
> 
> Individually the actual data structure conversion isn't that hard, but there's
> a lot of them and the mapping types allow you to do them incrementally without
> breaking some unconverted importer importing from a converted exporter.

Breaking classic users is actually completely intentional because we most likely still have people abusing the struct page inside the SGT.

And those will need to be converted over to be using pure DMA addresses similar to how MSM has switched over recently.

So the whole idea is when you have classic to classic interface pass along the SGT between exporter and importer. Then move as much as possible drivers over to the new interface and start identifying where and why some drivers have problems.

Regards,
Christian.

> 
> That is also why I think adding the types now rather than later is reasonable.
> The rules for when an exporter may change type or placement are what most of the
> previous review discussion has been about, and I didn't want to drop them.
> 
> Thanks for looking.
> 
>  - Alistair
> 
>> Christian.
>>
>>>
>>> Jason
>>


  parent reply	other threads:[~2026-11-24 12:36 UTC|newest]

Thread overview: 31+ 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 [this message]
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=63eb7b6e-e0a8-4443-a434-0301ed59beae@amd.com \
    --to=christian.koenig@amd.com \
    --cc=aik@amd.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®