Re: DMA-buf and uncached system memory

From: Christian König
Date: Thu Jun 23 2022 - 07:32:33 EST


Am 23.06.22 um 13:27 schrieb Daniel Stone:
Hi Christian,

On Thu, 23 Jun 2022 at 12:11, Christian König <christian.koenig@xxxxxxx> wrote:
In fact DMA-buf sharing works fine on most of those SoCs because
everyone just assumes that all the accelerators don't snoop, so the
memory shared via DMA-buf is mostly CPU uncached. It only falls apart
for uses like the UVC cameras, where the shared buffer ends up being
CPU cached.
Well then the existing DMA-buf framework is not what you want to use for
this.

Non-coherent without explicit domain transfer points is just not going
to work. So why can't we solve the issue for DMA-buf in the same way as
the DMA API already solved it years ago: by adding the equivalent of
the dma_sync calls that do cache maintenance when necessary? On x86 (or
any system where things are mostly coherent) you could still no-op them
for the common case and only trigger cache cleaning if the importer
explicitly says that is going to do a non-snooping access.
Because DMA-buf is a framework for buffer sharing between cache coherent
devices which don't signal transitions.

We intentionally didn't implemented any of the dma_sync_* functions
because that would break the intended use case.

You can of course use DMA-buf in an incoherent environment, but then you
can't expect that this works all the time.

This is documented behavior and so far we have bluntly rejected any of
the complains that it doesn't work on most ARM SoCs and I don't really
see a way to do this differently.
For some strange reason, 'let's do buffer sharing but make sure it
doesn't work on Arm' wasn't exactly the intention of the groups who
came together under the Linaro umbrella to create dmabuf.

If it's really your belief that dmabuf requires universal snooping, I
recommend you send the patch to update the documentation, as well as
to remove DRIVER_PRIME from, realistically, most non-PCIE drivers.

Well, to be honest I think that would indeed be necessary.

What we have created are essentially two different worlds, one for PCI devices and one for the rest.

This was indeed not the intention, but it's a fact that basically all DMA-buf based PCI drivers assume coherent access.

Regards,
Christian.


Cheers,
Daniel