drm: fix deadlock of syncobj
Subsystems (2)
PATCH 1/1 drm: fix deadlock of syncobj
--- drivers/gpu/drm/drm_syncobj.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_syncobj.c +5 -2
@@ -344,13 +344,16 @@ void drm_syncobj_replace_fence(struct drm_syncobj *syncobj,drm_syncobj_create_signal_pt (syncobj, fence, pt_value);if (fence) {struct drm_syncobj_cb *cur, *tmp; +struct list_head cb_list; +INIT_LIST_HEAD (&cb_list);spin_lock (&syncobj->lock); -list_for_each_entry_safe (cur, tmp, &syncobj->cb_list, node) { +list_splice_init (&syncobj->cb_list, &cb_list); +spin_unlock (&syncobj->lock); +list_for_each_entry_safe (cur, tmp, &cb_list, node) {list_del_init (&cur->node); cur->func (syncobj, cur); } -spin_unlock (&syncobj->lock); } }EXPORT_SYMBOL (drm_syncobj_replace_fence);
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoting Chunming Zhou (2018-10-19 11:26:41)
Quoted 13 lines
Signed-off-by Chunming Zhou <[email protected]>Cc Daniel Vetter <[email protected]>Cc Chris Wilson <[email protected]>Cc Christian König <[email protected]>--- drivers/gpu/drm/drm_syncobj.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/gpu/drm/drm_syncobj.c +0
-0
drivers/gpu/drm/drm_syncobj.c void drm_syncobj_replace_fence(struct drm_syncobj *syncobj, · line 348
Quoted 5 lines
drivers/gpu/drm/drm_syncobj.c +2
-0@@ -344,13 +344,16 @@ void drm_syncobj_replace_fence(struct drm_syncobj *syncobj,drm_syncobj_create_signal_pt (syncobj, fence, pt_value);if (fence) {struct drm_syncobj_cb *cur, *tmp; +struct list_head cb_list; +INIT_LIST_HEAD (&cb_list);
LIST_HEAD(cb_list); // does both in one
drivers/gpu/drm/drm_syncobj.c void drm_syncobj_replace_fence(struct drm_syncobj *syncobj, · line 351
Quoted 3 lines
drivers/gpu/drm/drm_syncobj.c +1
-1spin_lock (&syncobj->lock); -list_for_each_entry_safe (cur, tmp, &syncobj->cb_list, node) { +list_splice_init (&syncobj->cb_list, &cb_list);
Steal the snapshot of the list under the lock, ok.
drivers/gpu/drm/drm_syncobj.c void drm_syncobj_replace_fence(struct drm_syncobj *syncobj, · line 354
Quoted 3 lines
drivers/gpu/drm/drm_syncobj.c +2
-0+spin_unlock (&syncobj->lock); +list_for_each_entry_safe (cur, tmp, &cb_list, node) {list_del_init (&cur->node);
Races against external caller of drm_syncobj_remove_callback(). However, it looks like that race is just fine, but we don't guard against the struct drm_syncobj_cb itself being freed, leading to all sort of fun for an interrupted drm_syncobj_array_wait_timeout.
That kfree seems to undermine the validity of stealing the list. -Chris
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 26 lines · Chris Wilson
Quoting Chunming Zhou (2018-10-19 11:26:41)
Quoted 13 lines
Signed-off-by Chunming Zhou <[email protected]>Cc Daniel Vetter <[email protected]>Cc Chris Wilson <[email protected]>Cc Christian König <[email protected]>--- drivers/gpu/drm/drm_syncobj.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/gpu/drm/drm_syncobj.c +0
-0drivers/gpu/drm/drm_syncobj.c void drm_syncobj_replace_fence(struct drm_syncobj *syncobj, · line 348
Quoted 5 lines
drivers/gpu/drm/drm_syncobj.c +2
-0@@ -344,13 +344,16 @@ void drm_syncobj_replace_fence(struct drm_syncobj *syncobj,drm_syncobj_create_signal_pt (syncobj, fence, pt_value);if (fence) {struct drm_syncobj_cb *cur, *tmp; +struct list_head cb_list; +INIT_LIST_HEAD (&cb_list);
LIST_HEAD(cb_list); // does both in onedrivers/gpu/drm/drm_syncobj.c void drm_syncobj_replace_fence(struct drm_syncobj *syncobj, · line 351
Quoted 3 lines
drivers/gpu/drm/drm_syncobj.c +1
-1spin_lock (&syncobj->lock); -list_for_each_entry_safe (cur, tmp, &syncobj->cb_list, node) { +list_splice_init (&syncobj->cb_list, &cb_list);Steal the snapshot of the list under the lock, ok.
Quoted 7 lines
drivers/gpu/drm/drm_syncobj.c void drm_syncobj_replace_fence(struct drm_syncobj *syncobj, · line 354
Quoted 3 lines
drivers/gpu/drm/drm_syncobj.c +2
-0+spin_unlock (&syncobj->lock); +list_for_each_entry_safe (cur, tmp, &cb_list, node) {list_del_init (&cur->node);Races against external caller of
drm_syncobj_remove_callback(). However, it looks like that race is just fine, but we don't guard against the structdrm_syncobj_cbitself being freed, leading to all sort of fun for an interrupteddrm_syncobj_array_wait_timeout.
Thanks quick review, I will use "while (!list_empty()) { e = list_first_entry(); list_del(e)" to avoid deadlock.
will send v2 in one minute.
Regards,
David Zhou
Quoted 3 lines
That kfree seems to undermine the validity of stealing the list. -Chris
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 31 lines · On 2018年10月19日 19:26, zhoucm1 wrote:
Quoted 28 lines · Chris Wilson
Quoting Chunming Zhou (2018-10-19 11:26:41)
Quoted 13 lines
Signed-off-by Chunming Zhou <[email protected]>Cc Daniel Vetter <[email protected]>Cc Chris Wilson <[email protected]>Cc Christian König <[email protected]>---
drivers/gpu/drm/drm_syncobj.c| 7 +++++--1 file changed, 5 insertions(+), 2 deletions(-)drivers/gpu/drm/drm_syncobj.c +0
-0drivers/gpu/drm/drm_syncobj.c void drm_syncobj_replace_fence(struct · line 349
Quoted 6 lines
drivers/gpu/drm/drm_syncobj.c +2
-0@@ -344,13 +344,16 @@ void drm_syncobj_replace_fence(structdrm_syncobj *syncobj, drm_syncobj_create_signal_pt(syncobj, fence, pt_value); if (fence) { struct drm_syncobj_cb *cur, *tmp; + struct list_head cb_list; + INIT_LIST_HEAD(&cb_list);
LIST_HEAD(cb_list); // does both in onedrivers/gpu/drm/drm_syncobj.c void drm_syncobj_replace_fence(struct drm_syncobj *syncobj, · line 351
Quoted 4 lines
drivers/gpu/drm/drm_syncobj.c +1
-1spin_lock (&syncobj->lock); - list_for_each_entry_safe(cur, tmp, &syncobj->cb_list, node) { + list_splice_init(&syncobj->cb_list, &cb_list);Steal the snapshot of the list under the lock, ok.
Quoted 8 lines
Quoted 7 lines
drivers/gpu/drm/drm_syncobj.c void drm_syncobj_replace_fence(struct drm_syncobj *syncobj, · line 354
Quoted 3 lines
drivers/gpu/drm/drm_syncobj.c +2
-0+spin_unlock (&syncobj->lock); + list_for_each_entry_safe(cur, tmp, &cb_list, node) { list_del_init(&cur->node);Races against external caller of
drm_syncobj_remove_callback(). However, it looks like that race is just fine, but we don't guard against the structdrm_syncobj_cbitself being freed, leading to all sort of fun for an interrupteddrm_syncobj_array_wait_timeout.Thanks quick review, I will use "while (!list_empty()) { e =
list_first_entry();list_del(e)" to avoid deadlock.
this still cannot resolve freeing problem, do you mind I change spinlock to mutex?
Thanks,
David Zhou
Quoted 9 lines
will send v2 in one minute.
Regards,
David ZhouQuoted 3 lines
That kfree seems to undermine the validity of stealing the list. -Chris
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Am 19.10.18 um 14:01 schrieb zhoucm1:
Quoted 44 lines · On 2018年10月19日 19:26, zhoucm1 wrote:
Quoted 41 lines · Chris Wilson
Quoted 38 lines
Quoting Chunming Zhou (2018-10-19 11:26:41)
Quoted 14 lines
Signed-off-by Chunming Zhou <[email protected]>Cc Daniel Vetter <[email protected]>Cc Chris Wilson <[email protected]>Cc Christian König <[email protected]>---
drivers/gpu/drm/drm_syncobj.c| 7 +++++--1 file changed, 5 insertions(+), 2 deletions(-)drivers/gpu/drm/drm_syncobj.c +0
-0drivers/gpu/drm/drm_syncobj.c void drm_syncobj_replace_fence(struct · line 349
Quoted 6 lines
drivers/gpu/drm/drm_syncobj.c +2
-0@@ -344,13 +344,16 @@ void drm_syncobj_replace_fence(structdrm_syncobj *syncobj, drm_syncobj_create_signal_pt(syncobj, fence, pt_value); if (fence) { struct drm_syncobj_cb *cur, *tmp; + struct list_head cb_list; + INIT_LIST_HEAD(&cb_list);
LIST_HEAD(cb_list); // does both in onedrivers/gpu/drm/drm_syncobj.c void drm_syncobj_replace_fence(struct drm_syncobj *syncobj, · line 351
Quoted 4 lines
drivers/gpu/drm/drm_syncobj.c +1
-1spin_lock (&syncobj->lock); - list_for_each_entry_safe(cur, tmp, &syncobj->cb_list, node) { + list_splice_init(&syncobj->cb_list, &cb_list);Steal the snapshot of the list under the lock, ok.
drivers/gpu/drm/drm_syncobj.c void drm_syncobj_replace_fence(struct drm_syncobj *syncobj, · line 354
Quoted 3 lines
drivers/gpu/drm/drm_syncobj.c +2
-0+spin_unlock (&syncobj->lock); + list_for_each_entry_safe(cur, tmp, &cb_list, node) { list_del_init(&cur->node);Races against external caller of
drm_syncobj_remove_callback(). However,
it looks like that race is just fine, but we don't guard against the structdrm_syncobj_cbitself being freed, leading to all sort of fun for
an interrupteddrm_syncobj_array_wait_timeout.
Quoted 4 lines
Quoted 2 lines
Thanks quick review, I will use "while (!list_empty()) { e =
list_first_entry();list_del(e)" to avoid deadlock.this still cannot resolve freeing problem, do you mind I change spinlock to mutex?
How does that help?
What you could do is to merge the array of fences into the beginning of the signal_pt, e.g. something like this:
struct drm_syncobj_signal_pt {
struct dma_fence fences[2];
struct dma_fence_array *fence_array;
u64 value;
struct list_head list;
};
This way the drm_syncobj_signal_pt is freed when the fence_array is freed. That should be sufficient if we correctly reference count the fence_array.
Christian.
Quoted 13 lines
Thanks,
David ZhouQuoted 9 lines
will send v2 in one minute.
Regards,
David ZhouQuoted 3 lines
That kfree seems to undermine the validity of stealing the list. -Chris
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 59 lines · Christian
Am 19.10.18 um 14:01 schrieb zhoucm1:
Quoted 42 lines · On 2018年10月19日 19:26, zhoucm1 wrote:
Quoted 40 lines · Chris Wilson
Quoted 38 lines
Quoting Chunming Zhou (2018-10-19 11:26:41)
Quoted 14 lines
Signed-off-by Chunming Zhou <[email protected]>Cc Daniel Vetter <[email protected]>Cc Chris Wilson <[email protected]>Cc Christian König <[email protected]>--- drivers/gpu/drm/drm_syncobj.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/gpu/drm/drm_syncobj.c +0
-0drivers/gpu/drm/drm_syncobj.c void drm_syncobj_replace_fence(struct · line 349
Quoted 6 lines
drivers/gpu/drm/drm_syncobj.c +2
-0@@ -344,13 +344,16 @@ void drm_syncobj_replace_fence(structdrm_syncobj *syncobj, drm_syncobj_create_signal_pt(syncobj, fence, pt_value); if (fence) { struct drm_syncobj_cb *cur, *tmp; + struct list_head cb_list; + INIT_LIST_HEAD(&cb_list);
LIST_HEAD(cb_list); // does both in onedrivers/gpu/drm/drm_syncobj.c void drm_syncobj_replace_fence(struct drm_syncobj *syncobj, · line 351
Quoted 4 lines
drivers/gpu/drm/drm_syncobj.c +1
-1spin_lock (&syncobj->lock); - list_for_each_entry_safe(cur, tmp, &syncobj->cb_list, node) { + list_splice_init(&syncobj->cb_list, &cb_list);Steal the snapshot of the list under the lock, ok.
drivers/gpu/drm/drm_syncobj.c void drm_syncobj_replace_fence(struct drm_syncobj *syncobj, · line 354
Quoted 3 lines
drivers/gpu/drm/drm_syncobj.c +2
-0+spin_unlock (&syncobj->lock); + list_for_each_entry_safe(cur, tmp, &cb_list, node) { list_del_init(&cur->node);Races against external caller of
drm_syncobj_remove_callback(). However,
it looks like that race is just fine, but we don't guard against the structdrm_syncobj_cbitself being freed, leading to all sort of fun for
an interrupteddrm_syncobj_array_wait_timeout.Quoted 4 lines
Quoted 2 lines
Thanks quick review, I will use "while (!list_empty()) { e =
list_first_entry();list_del(e)" to avoid deadlock.this still cannot resolve freeing problem, do you mind I change spinlock to mutex?
How does that help?
What you could do is to merge the array of fences into the beginning of the
signal_pt, e.g. something like this:struct
drm_syncobj_signal_pt{
structdma_fencefences[2];
structdma_fence_array*fence_array;
u64 value;
structlist_headlist;
};
Quoted 3 lines
This way the
drm_syncobj_signal_ptis freed when thefence_arrayis freed. That should be sufficient if we correctly reference count thefence_array.
I'm not sure what problem you said, the deadlock reason is :
Cb func will call drm_syncobj_search_fence, which will need to grab the lock, otherwise deadlock.
But when we steal list or use "while (!list_empty()) { e = list_first_entry(); list_del(e)", both will encounter another freeing problem, that is syncobj_cb could be freed when wait timeout.
If we change to use mutex, then we can move lock inside of _search_fence out. another way is we add a separate spinlock for signal_pt_list, not share one lock with cb_list.
Regards,
David
Quoted 11 lines
Christian.
Quoted 8 lines
Thanks,
David ZhouQuoted 6 lines
will send v2 in one minute.
Regards,
David ZhouQuoted 2 lines
That kfree seems to undermine the validity of stealing the list. -Chris
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Am 19.10.18 um 14:19 schrieb zhoucm1:
Quoted 65 lines · Christian
Quoted 59 lines
Am 19.10.18 um 14:01 schrieb zhoucm1:
Quoted 42 lines · On 2018年10月19日 19:26, zhoucm1 wrote:
Quoted 40 lines · Chris Wilson
Quoted 38 lines
Quoting Chunming Zhou (2018-10-19 11:26:41)
Quoted 14 lines
Signed-off-by Chunming Zhou <[email protected]>Cc Daniel Vetter <[email protected]>Cc Chris Wilson <[email protected]>Cc Christian König <[email protected]>---
drivers/gpu/drm/drm_syncobj.c| 7 +++++--1 file changed, 5 insertions(+), 2 deletions(-)drivers/gpu/drm/drm_syncobj.c +0
-0drivers/gpu/drm/drm_syncobj.c void drm_syncobj_replace_fence(struct · line 349
Quoted 6 lines
drivers/gpu/drm/drm_syncobj.c +2
-0@@ -344,13 +344,16 @@ void drm_syncobj_replace_fence(structdrm_syncobj *syncobj, drm_syncobj_create_signal_pt(syncobj, fence, pt_value); if (fence) { struct drm_syncobj_cb *cur, *tmp; + struct list_head cb_list; + INIT_LIST_HEAD(&cb_list);
LIST_HEAD(cb_list); // does both in onedrivers/gpu/drm/drm_syncobj.c void drm_syncobj_replace_fence(struct drm_syncobj *syncobj, · line 351
Quoted 4 lines
drivers/gpu/drm/drm_syncobj.c +1
-1spin_lock (&syncobj->lock); - list_for_each_entry_safe(cur, tmp, &syncobj->cb_list, node) { +list_splice_init (&syncobj->cb_list, &cb_list);Steal the snapshot of the list under the lock, ok.
drivers/gpu/drm/drm_syncobj.c void drm_syncobj_replace_fence(struct drm_syncobj *syncobj, · line 354
Quoted 3 lines
drivers/gpu/drm/drm_syncobj.c +2
-0+spin_unlock (&syncobj->lock); + list_for_each_entry_safe(cur, tmp, &cb_list, node) {list_del_init (&cur->node);Races against external caller of
drm_syncobj_remove_callback(). However,
it looks like that race is just fine, but we don't guard against the structdrm_syncobj_cbitself being freed, leading to all sort of fun for
an interrupteddrm_syncobj_array_wait_timeout.Quoted 4 lines
Quoted 2 lines
Thanks quick review, I will use "while (!list_empty()) { e =
list_first_entry();list_del(e)" to avoid deadlock.this still cannot resolve freeing problem, do you mind I change spinlock to mutex?
How does that help?
What you could do is to merge the array of fences into the beginning of the
signal_pt, e.g. something like this:struct
drm_syncobj_signal_pt{
structdma_fencefences[2];
structdma_fence_array*fence_array;
u64 value;
structlist_headlist;
};Quoted 3 lines
This way the
drm_syncobj_signal_ptis freed when thefence_arrayis freed. That should be sufficient if we correctly reference count thefence_array.
Quoted 8 lines
I'm not sure what problem you said, the deadlock reason is :
Cb func will calldrm_syncobj_search_fence, which will need to grab the lock, otherwise deadlock.But when we steal list or use "while (!list_empty()) { e =
list_first_entry();list_del(e)", both will encounter another freeing problem, that issyncobj_cbcould be freed when wait timeout.If we change to use mutex, then we can move lock inside of
_search_fenceout.another way is we add a separate spinlock for
signal_pt_list, not share one lock withcb_list.
Well of hand that sounds like the cleanest approach to me.
Christian.
Quoted 12 lines
Regards,
DavidQuoted 9 lines
Christian.
Quoted 6 lines
Thanks,
David ZhouQuoted 4 lines
will send v2 in one minute.
Regards,
David Zhou
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
That kfree seems to undermine the validity of stealing the list. -Chris
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel