All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel@ffwll.ch>
To: Dave Airlie <airlied@gmail.com>
Cc: dri-devel <dri-devel@lists.freedesktop.org>,
	amd-gfx mailing list <amd-gfx@lists.freedesktop.org>
Subject: Re: [PATCH 2/4] sync_file: add replace and export some functionality
Date: Wed, 15 Mar 2017 09:55:55 +0100	[thread overview]
Message-ID: <20170315085555.7yxzl356cfsz5nyk@phenom.ffwll.local> (raw)
In-Reply-To: <CAPM=9tz9Bog0HQkMszjA79cuYqj9kuPXcv7VkTpXYNc051Wu1A@mail.gmail.com>

On Wed, Mar 15, 2017 at 02:19:16PM +1000, Dave Airlie wrote:
> >
> > uabi semantics question: Should we wake up everyone when the fence gets
> > replaced? What's the khr semaphore expectation here?
> 
> There are no real semantics for this case, you either wait the semaphore and
> replace it with NULL, or signal it where you replace the fence with a new fence.
> 
> Nobody should be using the sync_fence interfaces to poll on these fence fds.
> 
> So not crashing for non-vulkan behaviour is what we need.
> 
> The spec doesn't know anything other than this is an opaque fd,
> it shouldn't be doing operations on it, execpt importing it.
> 
> >>  static int sync_file_set_fence(struct sync_file *sync_file,
> >>                              struct dma_fence **fences, int num_fences)
> >>  {
> >> @@ -292,8 +328,10 @@ static void sync_file_free(struct kref *kref)
> >>       struct sync_file *sync_file = container_of(kref, struct sync_file,
> >>                                                    kref);
> >>
> >> -     if (test_bit(POLL_ENABLED, &sync_file->fence->flags))
> >> -             dma_fence_remove_callback(sync_file->fence, &sync_file->cb);
> >> +     if (sync_file->fence) {
> >> +             if (test_bit(POLL_ENABLED, &sync_file->fence->flags))
> >> +                     dma_fence_remove_callback(sync_file->fence, &sync_file->cb);
> >> +     }
> >>       dma_fence_put(sync_file->fence);
> >>       kfree(sync_file);
> >>  }
> >
> > I think you've missed _poll, won't that oops now?
> 
> I don't think it will, all the stuff do inside the poll handler is
> protected by the mutex
> or do you think we should hook the new fence if the old fence has poll enabled?

Yeah, or at least wake them up somehow and restart it. Or well at least
think what would happen when that does, and whether we care. If vk says
you get undefined behaviour when you replace the fence of a semaphore when
the old one hasn't signalled yet, then we don't need to do anything.

But if they spec some behaviour poll returning "ready" way after you've
replaced the fence and the new one is definitely not ready is a bit
confusing semantics. Or maybe that's exactly the semantics vulkan once,
but then we need to be careful with restarts and stuff.

wrt the oops I think there's a possibility of a use-after-free: Thus far
the wait inherited the fence reference from the sync_file (since poll
stops before the file ref is gone), but now the fence could disappear
underneath it. add_callback itself doesn't grab a reference on its own.

So either we need synchronous replacement for poll or grab a reference
there. I think at least ... coffee not yet entirely working. In any case,
this kind of nasty corner case is perfect for some vgem testing.
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2017-03-15  8:56 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-14  0:50 [rfc] amdgpu/sync_file shared semaphores Dave Airlie
2017-03-14  0:50 ` [PATCH 1/4] sync_file: add a mutex to protect fence and callback members Dave Airlie
     [not found]   ` <20170314005054.7487-3-airlied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-03-14  8:45     ` Daniel Vetter
2017-03-14  9:13       ` Christian König
     [not found]         ` <2cba21f6-731b-d112-f882-bef66a9b96c9-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
2017-03-14  9:29           ` Chris Wilson
     [not found]             ` <20170314092909.GE2118-aII6DKEyn0pWYbfKqPwjAkR8Iwp7RQ6xAL8bYrjMMd8@public.gmane.org>
2017-03-14  9:30               ` Christian König
2017-03-15  0:47                 ` Dave Airlie
     [not found]                   ` <CAPM=9twwjgBirFDenUmnorDdOZNiWHuzdBxawCiU7p9uS1o0_Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-03-15  2:20                     ` Dave Airlie
     [not found] ` <20170314005054.7487-1-airlied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-03-14  0:50   ` [PATCH libdrm] libdrm/amdgpu: add interface for kernel semaphores Dave Airlie
2017-03-14  2:00     ` zhoucm1
2017-03-14  2:52       ` Dave Airlie
     [not found]         ` <CAPM=9tzegdtiyEmbW+PqmVeQ+bXrNtrdKXuE3kB0dPMKnMir+Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-03-14  3:30           ` zhoucm1
     [not found]             ` <58C763E0.1-5C7GfCeVMHo@public.gmane.org>
2017-03-14  4:16               ` Dave Airlie
2017-03-14  8:56                 ` Daniel Vetter
2017-03-14  8:54             ` Daniel Vetter
2017-03-14  9:20               ` Christian König
2017-03-14 10:04                 ` zhoucm1
     [not found]                   ` <58C7C032.7060706-5C7GfCeVMHo@public.gmane.org>
2017-03-14 17:45                     ` Harry Wentland
     [not found]                       ` <8dea3303-480d-c29a-22ec-42adf3dab4ce-5C7GfCeVMHo@public.gmane.org>
2017-03-14 17:54                         ` Daniel Vetter
2017-03-14 18:10                         ` Christian König
2017-03-15  0:01                           ` Marek Olšák
     [not found]                             ` <CAAxE2A7xRWhkp-OC59iy2i91uj5mtVTHR0uHfDf745L-ixxHcw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-03-15  8:48                               ` Daniel Vetter
2017-03-15  9:35                                 ` Christian König
     [not found]     ` <20170314005054.7487-2-airlied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-03-15 10:30       ` Emil Velikov
2017-03-14  0:50   ` [PATCH 2/4] sync_file: add replace and export some functionality Dave Airlie
     [not found]     ` <20170314005054.7487-4-airlied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-03-14  8:48       ` Daniel Vetter
     [not found]         ` <20170314084851.covfl7sjwn3yadh5-dv86pmgwkMBes7Z6vYuT8azUEOm+Xw19@public.gmane.org>
2017-03-15  4:19           ` Dave Airlie
2017-03-15  8:55             ` Daniel Vetter [this message]
2017-03-16  5:18               ` Dave Airlie
2017-03-14  9:00     ` Chris Wilson
2017-03-14  0:50   ` [PATCH 3/4] amdgpu/cs: split out fence dependency checking Dave Airlie
2017-03-14  0:50   ` [PATCH 4/4] amdgpu: use sync file for shared semaphores Dave Airlie
     [not found]     ` <20170314005054.7487-6-airlied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-03-15  9:01       ` Daniel Vetter
     [not found]         ` <20170315090129.fneo5gafrz2jec32-dv86pmgwkMBes7Z6vYuT8azUEOm+Xw19@public.gmane.org>
2017-03-15  9:43           ` Christian König
2017-03-15  9:57             ` Daniel Vetter
2017-03-14  8:53 ` [rfc] amdgpu/sync_file " Daniel Vetter
     [not found]   ` <20170314085313.qmnnofqa6e6ozmwk-dv86pmgwkMBes7Z6vYuT8azUEOm+Xw19@public.gmane.org>
2017-03-15  1:09     ` Dave Airlie
     [not found]       ` <CAPM=9txSFTkz0y5hamBA7U7fu+X8x_wHG+X3xtWvm2PY4aCwsw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-03-15  8:47         ` Daniel Vetter

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=20170315085555.7yxzl356cfsz5nyk@phenom.ffwll.local \
    --to=daniel@ffwll.ch \
    --cc=airlied@gmail.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=dri-devel@lists.freedesktop.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.