dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Jason Ekstrand <jason@jlekstrand.net>
To: "Christian König" <christian.koenig@amd.com>
Cc: "Chenbo Feng" <fengc@google.com>,
	"Daniel Stone" <daniels@collabora.com>,
	"Daniel Vetter" <daniel.vetter@ffwll.ch>,
	"James Jones" <jajones@nvidia.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>,
	"Dave Airlie" <airlied@redhat.com>,
	"Jesse Hall" <jessehall@google.com>,
	linux-media@vger.kernel.org
Subject: Re: [PATCH] RFC: dma-buf: Add an API for importing and exporting sync files
Date: Wed, 4 Mar 2020 10:41:28 -0600	[thread overview]
Message-ID: <CAOFGe97XSxgzCViOH=2+B2_d5P3vGifKmvAw-JrzRQbbRMRbcg@mail.gmail.com> (raw)
In-Reply-To: <CAOFGe95Gx=kX=sxwhx1FYmXQuPtGAKwt2V5YodQBwJXujE3WwA@mail.gmail.com>

On Wed, Mar 4, 2020 at 10:27 AM Jason Ekstrand <jason@jlekstrand.net> wrote:
>
> On Wed, Mar 4, 2020 at 2:34 AM Christian König <christian.koenig@amd.com> wrote:
> >
> > Am 03.03.20 um 20:10 schrieb Jason Ekstrand:
> > > On Thu, Feb 27, 2020 at 2:28 AM Christian König
> > > <christian.koenig@amd.com> wrote:
> > >> [SNIP]
> > >>> 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.
> > > Currently (as of v2), I'm using dma_fence_array and being careful to
> > > not bother constructing one if there's only one fence in play.  Is
> > > this insufficient?  If so, maybe we should consider improving
> > > dma_fence_array.
> >
> > That still won't work correctly in all cases. See the problem is not
> > only optimization, but also avoiding situations where userspace can
> > abuse the interface to do nasty things.
> >
> > For example if userspace just calls that function in a loop you can
> > create a long chain of dma_fence_array objects.
> >
> > If that chain is then suddenly released the recursive dropping of
> > references can overwrite the kernel stack.
> >
> > For reference see what dance is necessary in the dma_fence_chain_release
> > function to avoid that:
> > >         /* Manually unlink the chain as much as possible to avoid
> > > recursion
> > >          * and potential stack overflow.
> > >          */
> > >         while ((prev = rcu_dereference_protected(chain->prev, true))) {
> > ....
> >
> > It took me quite a while to figure out how to do this without causing
> > issues. But I don't see how this would be possible for dma_fence_array.
>
> Ah, I see the issue now!  It hadn't even occurred to me that userspace
> could use this to build up an infinite recursion chain.  That's nasty!
>  I'll give this some more thought and see if can come up with
> something clever.
>
> Here's one thought:  We could make dma_fence_array automatically
> collapse any arrays it references and instead directly reference their
> fences.  This way, no matter how much the client chains things, they
> will never get more than one dma_fence_array.  Of course, the
> difficulty here (answering my own question) comes if they ping-pong
> back-and-forth between something which constructs a dma_fence_array
> and something which constructs a dma_fence_chain to get
> array-of-chain-of-array-of-chain-of-...  More thought needed.

Answering my own questions again...  I think the
array-of-chain-of-array case is also solvable.

For array-of-chain, we can simply add all unsignaled dma_fences in the
chain to the array.  The array won't signal until all of them have
which is exactly the same behavior as if we'd added the chain itself.

For chain-of-array, we can add all unsignaled dma_fences in the array
to the same point in the chain.  There may be some fiddling with the
chain numbering required here but I think we can get it so the chain
won't signal until everything in the array has signaled and we get the
same behavior as if we'd added the dma_fence_array to the chain.

In both cases, we end up with either a single array or a single and
destruction doesn't require recursion.  Thoughts?

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

  reply	other threads:[~2020-03-04 16:41 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
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 [this message]
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='CAOFGe97XSxgzCViOH=2+B2_d5P3vGifKmvAw-JrzRQbbRMRbcg@mail.gmail.com' \
    --to=jason@jlekstrand.net \
    --cc=airlied@redhat.com \
    --cc=christian.koenig@amd.com \
    --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=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).