From: Gustavo Padovan <gustavo@padovan.org>
To: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Gustavo Padovan <gustavo.padovan@collabora.com>,
dri-devel@lists.freedesktop.org
Subject: Re: [PATCH] dma-buf/sw_sync: hold a fence reference when check if it signaled
Date: Thu, 27 Jul 2017 22:57:25 -0300 [thread overview]
Message-ID: <20170728015725.GA10461@jade> (raw)
In-Reply-To: <150118380756.4919.2232089537359321968@mail.alporthouse.com>
2017-07-27 Chris Wilson <chris@chris-wilson.co.uk>:
> Quoting Gustavo Padovan (2017-07-27 20:03:53)
> > From: Gustavo Padovan <gustavo.padovan@collabora.com>
> >
> > If userspace already dropped its own reference by closing the sw_sync
> > fence fd we might end up in a deadlock where
> > dma_fence_is_signaled_locked() will trigger the release of the fence a
> > thus try to hold the lock to remove the fence from the list.
>
> So the issue here is that call to dma_fence_is_signaled_lock() is
> triggering the unreference?
Exactly. I'll say that explicitely in the commit message.
>
> > We need to grab a reference to the fence before calling into this chain if
> > we want to avoid this issue.
> >
> > Cc: Chris Wilson <chris@chris-wilson.co.uk>
> > Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.com>
> > ---
> > drivers/dma-buf/sw_sync.c | 7 ++++++-
> > 1 file changed, 6 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/dma-buf/sw_sync.c b/drivers/dma-buf/sw_sync.c
> > index af1bc84..8291434 100644
> > --- a/drivers/dma-buf/sw_sync.c
> > +++ b/drivers/dma-buf/sw_sync.c
> > @@ -144,11 +144,16 @@ static void sync_timeline_signal(struct sync_timeline *obj, unsigned int inc)
> > obj->value += inc;
> >
> > list_for_each_entry_safe(pt, next, &obj->pt_list, link) {
> > - if (!dma_fence_is_signaled_locked(&pt->base))
> > + dma_fence_get(&pt->base);
>
> This would need to be dma_fence_get_rcu() to avoid grabbing the fence
> when its refcount has hit 0.
>
> > + if (!dma_fence_is_signaled_locked(&pt->base)) {
> > + dma_fence_put(&pt->base);
> > break;
> > + }
> >
> > list_del_init(&pt->link);
> > rb_erase(&pt->node, &obj->pt_tree);
>
> But if I understand correctly, we just need to unlink first, then
> signal.
>
> list_for_each_entry_safe() {
> if (!timeline_fence_signaled(&pt->base))
> break;
>
> list_del_init(&pt->link);
> rb_erase(&pt->node, &obj->pt_tree);
>
> dma_fence_signal_locked(&pt->base);
> }
>
> The challenge is in writing the comment to explain the open-coding.
That is cleaner and doesn't need the get/put dance. I'll come up with a
comment to explain it.
Gustavo
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2017-07-28 1:57 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-27 19:03 [PATCH] dma-buf/sw_sync: hold a fence reference when check if it signaled Gustavo Padovan
2017-07-27 19:30 ` Chris Wilson
2017-07-28 1:57 ` Gustavo Padovan [this message]
2017-07-28 8:28 ` Chris Wilson
2017-07-28 7:30 ` 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=20170728015725.GA10461@jade \
--to=gustavo@padovan.org \
--cc=chris@chris-wilson.co.uk \
--cc=dri-devel@lists.freedesktop.org \
--cc=gustavo.padovan@collabora.com \
/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.