dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: "Christian König" <christian.koenig@amd.com>
To: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>,
	Jason Ekstrand <jason@jlekstrand.net>
Cc: "Daniel Stone" <daniels@collabora.com>,
	"Daniel Vetter" <daniel.vetter@ffwll.ch>,
	"James Jones" <jajones@nvidia.com>,
	"Chenbo Feng" <fengc@google.com>,
	LKML <linux-kernel@vger.kernel.org>,
	"Greg Hackmann" <ghackmann@google.com>,
	linaro-mm-sig@lists.linaro.org,
	"Kristian Høgsberg" <hoegsberg@google.com>,
	"Maling list - DRI developers" <dri-devel@lists.freedesktop.org>,
	"Jesse Hall" <jessehall@google.com>,
	"Dave Airlie" <airlied@redhat.com>,
	linux-media@vger.kernel.org
Subject: Re: [PATCH] RFC: dma-buf: Add an API for importing and exporting sync files
Date: Thu, 27 Feb 2020 09:28:28 +0100	[thread overview]
Message-ID: <810a26e7-4294-a615-b7ee-18148ac70641@amd.com> (raw)
In-Reply-To: <CAP+8YyEUz29fXDW5kO_0ZG6c849=TuFWCK8ynT3LuM+Tn+rMzw@mail.gmail.com>

Am 26.02.20 um 17:46 schrieb Bas Nieuwenhuizen:
> On Wed, Feb 26, 2020 at 4:29 PM Jason Ekstrand <jason@jlekstrand.net> wrote:
>> On Wed, Feb 26, 2020 at 4:05 AM Daniel Vetter <daniel@ffwll.ch> wrote:
>>> On Wed, Feb 26, 2020 at 10:16:05AM +0100, Christian König wrote:
>>> [SNIP]
>>>> Just imagine that you access some DMA-buf with a shader and that operation
>>>> is presented as a fence on the DMA-bufs reservation object. And now you can
>>>> go ahead and replace that fence and free up the memory.
>>>>
>>>> Tricking the Linux kernel into allocating page tables in that freed memory
>>>> is trivial and that's basically it you can overwrite page tables with your
>>>> shader and gain access to all of system memory :)
>>>>
>>>> What we could do is to always make sure that the added fences will complete
>>>> later than the already existing ones, but that is also rather tricky to get
>>>> right. I wouldn't do that if we don't have a rather big use case for this.
>> Right.  I thought about that but I'm still learning how dma_resv
>> works.  It'd be easy enough to make a fence array that contains both
>> the old fence and the new fence and replace the old fence with that.
>> What I don't know is the proper way to replace the exclusive fence
>> safely.  Some sort of atomic_cpxchg loop, perhaps?  I presume there's
>> some way of doing it properly because DRM drivers are doing it all the
>> time.

First of all you need to grab the lock of the dma_resv object or you 
can't replace the exclusive nor the shared ones.

This way you don't need to do a atomic_cmpxchg or anything else and 
still guarantee correct ordering.

> I think for an exclusive fence you may need to create a fence array
> that includes the existing exclusive and shared fences in the dma_resv
> combined with the added fence.

Yes, that at least gives us the correct synchronization.

> However, I'm not sure what the best way is to do garbage collection on
> that so that we don't get an impossibly list of fence arrays.

Exactly yes. That's also the reason why the dma_fence_chain container I 
came up with for the sync timeline stuff has such a rather sophisticated 
garbage collection.

When some of the included fences signal you need to free up the 
array/chain and make sure that the memory for the container can be reused.

>   (Note
> the dma_resv has a lock that needs to be taken before adding an
> exclusive fence, might be useful). Some code that does a thing like
> this is __dma_resv_make_exclusive in
> drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c 

Wanted to move that into dma_resv.c for quite a while since there are 
quite a few other cases where we need this.

Regards,
Christian.

> The other piece of the puzzle is that on the submit path this would
> need something to ignore implicit fences. And there semantically the
> question comes up whether it is safe for a driver to ignore exclusive
> fences from another driver. (and then we have amdgpu which has its own
> rules on exclusiveness of its shared fences based on the context. e.g.
> the current option to ignore implicit fences for a buffer still syncs
> on exclusive fences on the buffer).

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2020-02-27  8:28 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-25 23:58 [PATCH] RFC: dma-buf: Add an API for importing and exporting sync files Jason Ekstrand
2020-02-26  9:16 ` Christian König
2020-02-26 10:05   ` Daniel Vetter
2020-02-26 15:28     ` Jason Ekstrand
2020-02-26 16:46       ` Bas Nieuwenhuizen
2020-02-27  8:28         ` Christian König [this message]
2020-03-03 19:10           ` Jason Ekstrand
2020-03-04  8:34             ` Christian König
2020-03-04 16:27               ` Jason Ekstrand
2020-03-04 16:41                 ` Jason Ekstrand
2020-03-05 13:06                   ` Christian König
2020-03-05 15:54                     ` Jason Ekstrand
2020-03-09 16:21                       ` Christian König
2020-03-11  3:43                         ` Jason Ekstrand
2020-02-26 18:09 ` [PATCH] RFC: dma-buf: Add an API for importing and exporting sync files (v2) Jason Ekstrand
2020-03-03 19:03   ` [PATCH] RFC: dma-buf: Add an API for importing and exporting sync files (v3) Jason Ekstrand
2020-03-03 19:05     ` Jason Ekstrand
2020-03-11  3:43     ` [PATCH 1/3] dma-buf: add dma_fence_array_for_each (v2) Jason Ekstrand
2020-03-11  3:43       ` [PATCH 2/3] dma-buf: add dma_resv_get_singleton (v2) Jason Ekstrand
2020-03-11  3:43       ` [PATCH 3/3] RFC: dma-buf: Add an API for importing and exporting sync files (v4) Jason Ekstrand
2020-03-11 13:18         ` Christian König
2020-03-12 15:57           ` Jason Ekstrand
2020-03-13 10:33             ` Christian König
2020-03-17 21:21         ` [PATCH 3/3] RFC: dma-buf: Add an API for importing and exporting sync files (v5) Jason Ekstrand
2020-09-30  9:39           ` Michel Dänzer
2020-09-30  9:55             ` Daniel Vetter
2021-03-15 21:11               ` Jason Ekstrand
2021-03-15 21:30                 ` Daniel Vetter
2021-03-15 21:04           ` [PATCH 0/3] dma-buf: Add an API for exporting sync files (v6) Jason Ekstrand
2021-03-15 21:04             ` [PATCH 1/3] dma-buf: add dma_fence_array_for_each (v2) Jason Ekstrand
2021-03-15 21:04             ` [PATCH 2/3] dma-buf: add dma_resv_get_singleton (v2) Jason Ekstrand
2021-03-15 21:04             ` [PATCH 3/3] dma-buf: Add an API for exporting sync files (v6) Jason Ekstrand
2021-03-15 23:10               ` Jason Ekstrand
2021-03-16  8:51                 ` Michel Dänzer
2021-03-16 14:35                   ` Jason Ekstrand
2021-03-16  0:10               ` kernel test robot
2021-03-16  2:37               ` kernel test robot
2021-03-16  0:15             ` [PATCH 0/3] " Jason Ekstrand
2021-03-16  4:53             ` [PATCH 0/3] dma-buf: Add an API for exporting sync files (v7) Jason Ekstrand
2021-03-16  4:53               ` [PATCH 1/3] dma-buf: add dma_fence_array_for_each (v2) Jason Ekstrand
2021-03-16  4:53               ` [PATCH 2/3] dma-buf: add dma_resv_get_singleton_rcu (v3) Jason Ekstrand
2021-03-16  4:53               ` [PATCH 3/3] dma-buf: Add an API for exporting sync files (v7) Jason Ekstrand
2021-03-16  8:06                 ` kernel test robot
2021-03-17 22:19               ` [PATCH 0/3] dma-buf: Add an API for exporting sync files (v8) Jason Ekstrand
2021-03-17 22:19                 ` [PATCH 1/3] dma-buf: add dma_fence_array_for_each (v2) Jason Ekstrand
2021-03-18  9:38                   ` Christian König
2021-03-18 13:13                     ` Daniel Vetter
2021-03-19  1:40                       ` Jason Ekstrand
2021-03-17 22:19                 ` [PATCH 2/3] dma-buf: add dma_resv_get_singleton_rcu (v3) Jason Ekstrand
2021-03-17 22:19                 ` [PATCH 3/3] dma-buf: Add an API for exporting sync files (v8) Jason Ekstrand
2021-03-23 17:57                   ` Jason Ekstrand
2021-03-23 19:06                     ` Simon Ser
2021-03-23 19:34                       ` Jason Ekstrand

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=810a26e7-4294-a615-b7ee-18148ac70641@amd.com \
    --to=christian.koenig@amd.com \
    --cc=airlied@redhat.com \
    --cc=bas@basnieuwenhuizen.nl \
    --cc=daniel.vetter@ffwll.ch \
    --cc=daniels@collabora.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=fengc@google.com \
    --cc=ghackmann@google.com \
    --cc=hoegsberg@google.com \
    --cc=jajones@nvidia.com \
    --cc=jason@jlekstrand.net \
    --cc=jessehall@google.com \
    --cc=linaro-mm-sig@lists.linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).