From: "Christian König" <ckoenig.leichtzumerken@gmail.com>
To: "Christian König" <christian.koenig@amd.com>,
"Daniel Stone" <daniel@fooishbar.org>,
"Pekka Paalanen" <ppaalanen@gmail.com>,
"Sharma, Shashank" <Shashank.Sharma@amd.com>,
lkml <linux-kernel@vger.kernel.org>,
dri-devel <dri-devel@lists.freedesktop.org>,
"Nicolas Dufresne" <nicolas@ndufresne.ca>,
linaro-mm-sig@lists.linaro.org,
"Sumit Semwal" <sumit.semwal@linaro.org>,
linux-media <linux-media@vger.kernel.org>
Subject: Re: [Linaro-mm-sig] Re: DMA-buf and uncached system memory
Date: Mon, 4 Jul 2022 15:48:03 +0200 [thread overview]
Message-ID: <5eeefadd-7804-3876-c8da-3e6f1bcb9dc0@gmail.com> (raw)
In-Reply-To: <YrY0cQY1BTL5H7Xp@phenom.ffwll.local>
Hi Daniel,
Am 25.06.22 um 00:02 schrieb Daniel Vetter:
> On Thu, Jun 23, 2022 at 01:32:18PM +0200, Christian König wrote:
>> Am 23.06.22 um 13:27 schrieb Daniel Stone:
>>> [SNIP]
>>> 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.
> dma-buf does not require universal snooping.
>
> It does defacto require that all device access is coherent with all other
> device access, and consistent with the exporters notion of how cpu
> coherency is achieved. Not that coherent does not mean snooping, as long
> as all devices do unsnooped access and the exporter either does wc/uc or
> flushes caches that's perfectly fine, and how all the arm soc dma-buf
> sharing works.
We should probably start documenting that better.
> We did originally have the wording in there that you have to map/unamp
> around every device access, but that got dropped because no one was doing
> that anyway.
>
> Now where this totally breaks down is how we make this work, because the
> idea was that dma_buf_attach validates this all. Where this means all the
> hilarious reasons buffer sharing might not work:
> - wrong coherency mode (cpu cached or not)
> - not contiguous (we do check that, but only once we get the sg from
> dma_buf_attachment_map, which strictly speaking is a bit too late but
> most drivers do attach&map as one step so not that bad in practice)
> - whether the dma api will throw in bounce buffers or not
> - random shit like "oh this is in the wrong memory bank", which I think
> never landed in upstream
>
> p2p connectivity is about the only one that gets this right, yay. And the
> only reason we can even get it right is because all the information is
> exposed to drivers fully.
Yeah, that's why I designed P2P that way :)
I also don't think it's that bad, at least for radeon, nouveau and
amdgpu all the migration restrictions are actually handled correctly.
In other words when a DMA-buf is about to be used by another device we
use TTM to move the buffer around so that it can actually be accessed by
that device.
What I haven't foreseen in here is that we need to deal with different
caching behaviors between exporter and importer.
> The issue is that the device dma api refuses to share this information
> because it would "leak". Which sucks, because we have defacto build every
> single cross-device use-case of dma-buf on the assumption we can check
> this (up to gl/vk specs), but oh well.
>
> So in practice this gets sorted out by endless piles of hacks to make
> individual use-cases work.
>
> Oh and: This is definitely not limited to arm socs. x86 socs with intel
> at least have exactly all the same issues, and they get solved by adding
> various shitty hacks to the involved drivers (like i915+amdgpu). Luckily
> the intel camera driver isn't in upstream yet, since that would break a
> bunch of the hacks since suddently there will be now 2 cpu cache
> incoherent devices in an x86 system.
>
> Ideally someone fixes this, but I'm not hopeful.
>
> I recommend pouring more drinks.
>
> What is definitely not correct is claiming that dma-buf wasn't meant for
> this. We discussed cache coherency issues endless in budapest 12 or so
> years ago, I was there. It's just that the reality of the current
> implementation is falling short, and every time someone tries to fix it we
> get shouted down by dma api maintainers for looking behind their current.
Well that explains this, I've joined the party a year later and haven't
witnessed all of this.
> tldr; You have to magically know to not use cpu cached allocators on these
> machines.
Or reject the attachment. As far as I can see that is still the cleanest
option.
Regards,
Christian.
>
> Aside: This is also why vgem alloates wc memory on x86. It's the least
> common denominator that works. arm unfortunately doesn't allow you to
> allocate wc memory, so there stuff is simply somewhat broken.
> -Daniel
next prev parent reply other threads:[~2022-07-04 13:48 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-15 8:58 DMA-buf and uncached system memory Christian König
2021-02-15 9:06 ` Simon Ser
2021-02-15 9:34 ` Christian König
2021-02-15 11:53 ` Lucas Stach
2021-02-15 12:04 ` Christian König
2021-02-15 12:16 ` Lucas Stach
2021-02-15 12:25 ` Christian König
2021-02-15 14:41 ` David Laight
2021-02-15 14:54 ` [Linaro-mm-sig] " Christian König
2021-02-15 9:49 ` Thomas Zimmermann
2021-02-15 12:00 ` Thomas Zimmermann
2021-02-15 12:10 ` Christian König
2021-02-15 20:46 ` Nicolas Dufresne
2021-02-15 20:39 ` Nicolas Dufresne
[not found] ` <5822b325-766e-ce3c-50eb-d7f54f14fd0b@mediatek.com>
[not found] ` <39f7f41a-af8d-4700-37da-9401455afb98@amd.com>
2022-06-21 15:42 ` Nicolas Dufresne
2022-06-22 9:05 ` [Linaro-mm-sig] " Christian König
2021-02-16 9:25 ` Daniel Vetter
2022-06-22 19:39 ` Nicolas Dufresne
2022-06-22 23:34 ` Daniel Stone
2022-06-23 6:59 ` Christian König
2022-06-23 7:13 ` Pekka Paalanen
2022-06-23 7:26 ` Christian König
2022-06-23 8:04 ` Lucas Stach
2022-06-23 8:14 ` Christian König
2022-06-23 8:58 ` Lucas Stach
2022-06-23 9:09 ` Christian König
2022-06-23 9:33 ` Lucas Stach
2022-06-23 9:46 ` Christian König
2022-06-23 10:13 ` Lucas Stach
2022-06-23 11:10 ` Christian König
2022-06-23 11:27 ` Daniel Stone
2022-06-23 11:32 ` Christian König
2022-06-24 22:02 ` [Linaro-mm-sig] " Daniel Vetter
2022-07-04 13:48 ` Christian König [this message]
2022-08-09 14:46 ` Daniel Vetter
2022-08-10 5:55 ` Christian König
2022-06-23 11:29 ` Lucas Stach
2022-06-23 11:54 ` Christian König
2022-06-23 12:14 ` Lucas Stach
2022-06-23 12:52 ` Christian König
2022-06-23 15:26 ` Lucas Stach
2022-06-24 6:54 ` Christian König
2022-06-24 8:10 ` Lucas Stach
2022-06-27 13:54 ` Nicolas Dufresne
2022-06-27 14:06 ` Lucas Stach
2022-06-27 14:30 ` Nicolas Dufresne
2022-06-27 13:51 ` Nicolas Dufresne
2022-06-23 8:13 ` Thomas Zimmermann
2022-06-23 8:26 ` Christian König
2022-06-23 8:42 ` Thomas Zimmermann
2022-08-09 15:01 ` Rob Clark
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=5eeefadd-7804-3876-c8da-3e6f1bcb9dc0@gmail.com \
--to=ckoenig.leichtzumerken@gmail.com \
--cc=Shashank.Sharma@amd.com \
--cc=christian.koenig@amd.com \
--cc=daniel@fooishbar.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=nicolas@ndufresne.ca \
--cc=ppaalanen@gmail.com \
--cc=sumit.semwal@linaro.org \
/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