diff options
author | Gustavo Padovan <gustavo.padovan@collabora.com> | 2017-07-29 11:22:16 -0400 |
---|---|---|
committer | Gustavo Padovan <gustavo.padovan@collabora.com> | 2017-07-31 13:11:15 -0400 |
commit | 3792b7c1a70815fe4e954221c096f9278638fd21 (patch) | |
tree | 4bbd50bc1eaa3e450f3258d78f64dccc735064a4 /drivers/dma-buf | |
parent | 150b6a9d7d6fffb95c0a5349960a10569e8218b5 (diff) |
dma-buf/sw_sync: clean up list before signaling the fence
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 and
thus try to hold the lock to remove the fence from the list.
dma_fence_is_signaled_locked() tries to release/free the fence and hold
the lock in the process.
We fix that by changing the order operation and clean up the list and
rb-tree first.
v2: Drop fence get/put dance and manipulate the list first (Chris Wilson)
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Link: https://patchwork.freedesktop.org/patch/msgid/20170729152217.8362-2-gustavo@padovan.org
Diffstat (limited to 'drivers/dma-buf')
-rw-r--r-- | drivers/dma-buf/sw_sync.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/drivers/dma-buf/sw_sync.c b/drivers/dma-buf/sw_sync.c index ef0cc08f5dfb..38cc7389a6c1 100644 --- a/drivers/dma-buf/sw_sync.c +++ b/drivers/dma-buf/sw_sync.c | |||
@@ -213,11 +213,21 @@ static void sync_timeline_signal(struct sync_timeline *obj, unsigned int inc) | |||
213 | obj->value += inc; | 213 | obj->value += inc; |
214 | 214 | ||
215 | list_for_each_entry_safe(pt, next, &obj->pt_list, link) { | 215 | list_for_each_entry_safe(pt, next, &obj->pt_list, link) { |
216 | if (!dma_fence_is_signaled_locked(&pt->base)) | 216 | if (!timeline_fence_signaled(&pt->base)) |
217 | break; | 217 | break; |
218 | 218 | ||
219 | list_del_init(&pt->link); | 219 | list_del_init(&pt->link); |
220 | rb_erase(&pt->node, &obj->pt_tree); | 220 | rb_erase(&pt->node, &obj->pt_tree); |
221 | |||
222 | /* | ||
223 | * A signal callback may release the last reference to this | ||
224 | * fence, causing it to be freed. That operation has to be | ||
225 | * last to avoid a use after free inside this loop, and must | ||
226 | * be after we remove the fence from the timeline in order to | ||
227 | * prevent deadlocking on timeline->lock inside | ||
228 | * timeline_fence_release(). | ||
229 | */ | ||
230 | dma_fence_signal_locked(&pt->base); | ||
221 | } | 231 | } |
222 | 232 | ||
223 | spin_unlock_irq(&obj->lock); | 233 | spin_unlock_irq(&obj->lock); |