Re: [PATCH 2/2] drm: Revert syncobj timeline changes.

From: zhoucm1
Date: Thu Nov 08 2018 - 21:35:44 EST




On 2018å11æ09æ 00:52, Christian KÃnig wrote:
Am 08.11.18 um 17:07 schrieb Koenig, Christian:
Am 08.11.18 um 17:04 schrieb Eric Anholt:
Daniel suggested I submit this, since we're still seeing regressions
from it. This is a revert to before 48197bc564c7 ("drm: add syncobj
timeline support v9") and its followon fixes.
This is a harmless false positive from lockdep, Chouming and I are
already working on a fix.

On the other hand we had enough trouble with that patch, so if it really bothers you feel free to add my Acked-by: Christian KÃnig <christian.koenig@xxxxxxx> and push it.
NAK, please no, I don't think this needed, the Warning totally isn't related to syncobj timeline, but fence-array implementation flaw, just exposed by syncobj.
In addition, Christian already has a fix for this Warning, I've tested. Please Christian send to public review.

-David

Christian.


Christian.

Fixes this on first V3D testcase execution:

[ÂÂ 48.767088] ============================================
[ÂÂ 48.772410] WARNING: possible recursive locking detected
[ÂÂ 48.777739] 4.19.0-rc6+ #489 Not tainted
[ÂÂ 48.781668] --------------------------------------------
[ÂÂ 48.786993] shader_runner/3284 is trying to acquire lock:
[ÂÂ 48.792408] ce309d7f (&(&array->lock)->rlock){....}, at: dma_fence_add_callback+0x30/0x23c
[ÂÂ 48.800714]
[ÂÂ 48.800714] but task is already holding lock:
[ÂÂ 48.806559] c5952bd3 (&(&array->lock)->rlock){....}, at: dma_fence_add_callback+0x30/0x23c
[ÂÂ 48.814862]
[ÂÂ 48.814862] other info that might help us debug this:
[ÂÂ 48.821410]Â Possible unsafe locking scenario:
[ÂÂ 48.821410]
[ÂÂ 48.827338]ÂÂÂÂÂÂÂ CPU0
[ÂÂ 48.829788]ÂÂÂÂÂÂÂ ----
[ÂÂ 48.832239]ÂÂ lock(&(&array->lock)->rlock);
[ÂÂ 48.836434]ÂÂ lock(&(&array->lock)->rlock);
[ÂÂ 48.840640]
[ÂÂ 48.840640]Â *** DEADLOCK ***
[ÂÂ 48.840640]
[ÂÂ 48.846582]Â May be due to missing lock nesting notation
[Â 130.763560] 1 lock held by cts-runner/3270:
[Â 130.767745]Â #0: 7834b793 (&(&array->lock)->rlock){-...}, at: dma_fence_add_callback+0x30/0x23c
[Â 130.776461]
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ stack backtrace:
[Â 130.780825] CPU: 1 PID: 3270 Comm: cts-runner Not tainted 4.19.0-rc6+ #486
[Â 130.787706] Hardware name: Broadcom STB (Flattened Device Tree)
[Â 130.793645] [<c021269c>] (unwind_backtrace) from [<c020db1c>] (show_stack+0x10/0x14)
[Â 130.801404] [<c020db1c>] (show_stack) from [<c0c2c4b0>] (dump_stack+0xa8/0xd4)
[Â 130.808642] [<c0c2c4b0>] (dump_stack) from [<c0281a84>] (__lock_acquire+0x848/0x1a68)
[Â 130.816483] [<c0281a84>] (__lock_acquire) from [<c02835d8>] (lock_acquire+0xd8/0x22c)
[Â 130.824326] [<c02835d8>] (lock_acquire) from [<c0c49948>] (_raw_spin_lock_irqsave+0x54/0x68)
[Â 130.832777] [<c0c49948>] (_raw_spin_lock_irqsave) from [<c086bf54>] (dma_fence_add_callback+0x30/0x23c)
[Â 130.842183] [<c086bf54>] (dma_fence_add_callback) from [<c086d4c8>] (dma_fence_array_enable_signaling+0x58/0xec)
[Â 130.852371] [<c086d4c8>] (dma_fence_array_enable_signaling) from [<c086c00c>] (dma_fence_add_callback+0xe8/0x23c)
[Â 130.862647] [<c086c00c>] (dma_fence_add_callback) from [<c06d8774>] (drm_syncobj_wait_ioctl+0x518/0x614)
[Â 130.872143] [<c06d8774>] (drm_syncobj_wait_ioctl) from [<c06b8458>] (drm_ioctl_kernel+0xb0/0xf0)
[Â 130.880940] [<c06b8458>] (drm_ioctl_kernel) from [<c06b8818>] (drm_ioctl+0x1d8/0x390)
[Â 130.888782] [<c06b8818>] (drm_ioctl) from [<c03a4510>] (do_vfs_ioctl+0xb0/0x8ac)
[Â 130.896187] [<c03a4510>] (do_vfs_ioctl) from [<c03a4d40>] (ksys_ioctl+0x34/0x60)
[Â 130.903593] [<c03a4d40>] (ksys_ioctl) from [<c0201000>] (ret_fast_syscall+0x0/0x28)

Cc: Chunming Zhou <david1.zhou@xxxxxxx>
Cc: Christian KÃnig <christian.koenig@xxxxxxx>
Cc: Daniel Vetter <daniel.vetter@xxxxxxxx>
Signed-off-by: Eric Anholt <eric@xxxxxxxxxx>
---
ÂÂ drivers/gpu/drm/drm_syncobj.c | 359 +++++++---------------------------
ÂÂ include/drm/drm_syncobj.hÂÂÂÂ |Â 73 ++++---
ÂÂ 2 files changed, 105 insertions(+), 327 deletions(-)

diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c
index da8175d9c6ff..e2c5b3ca4824 100644
--- a/drivers/gpu/drm/drm_syncobj.c
+++ b/drivers/gpu/drm/drm_syncobj.c
@@ -56,9 +56,6 @@
ÂÂ #include "drm_internal.h"
ÂÂ #include <drm/drm_syncobj.h>
ÂÂ -/* merge normal syncobj to timeline syncobj, the point interval is 1 */
-#define DRM_SYNCOBJ_BINARY_POINT 1
-
ÂÂ struct drm_syncobj_stub_fence {
ÂÂÂÂÂÂ struct dma_fence base;
ÂÂÂÂÂÂ spinlock_t lock;
@@ -74,29 +71,7 @@ static const struct dma_fence_ops drm_syncobj_stub_fence_ops = {
ÂÂÂÂÂÂ .get_timeline_name = drm_syncobj_stub_fence_get_name,
ÂÂ };
ÂÂ -struct drm_syncobj_signal_pt {
-ÂÂÂ struct dma_fence_array *fence_array;
-ÂÂÂ u64ÂÂÂ value;
-ÂÂÂ struct list_head list;
-};
-
-static DEFINE_SPINLOCK(signaled_fence_lock);
-static struct dma_fence signaled_fence;
ÂÂ -static struct dma_fence *drm_syncobj_get_stub_fence(void)
-{
-ÂÂÂ spin_lock(&signaled_fence_lock);
-ÂÂÂ if (!signaled_fence.ops) {
-ÂÂÂÂÂÂÂ dma_fence_init(&signaled_fence,
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ &drm_syncobj_stub_fence_ops,
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ &signaled_fence_lock,
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ 0, 0);
-ÂÂÂÂÂÂÂ dma_fence_signal_locked(&signaled_fence);
-ÂÂÂ }
-ÂÂÂ spin_unlock(&signaled_fence_lock);
-
-ÂÂÂ return dma_fence_get(&signaled_fence);
-}
ÂÂ /**
ÂÂÂ * drm_syncobj_find - lookup and reference a sync object.
ÂÂÂ * @file_private: drm file private pointer
@@ -123,27 +98,6 @@ struct drm_syncobj *drm_syncobj_find(struct drm_file *file_private,
ÂÂ }
ÂÂ EXPORT_SYMBOL(drm_syncobj_find);
ÂÂ -static struct dma_fence *
-drm_syncobj_find_signal_pt_for_point(struct drm_syncobj *syncobj,
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ uint64_t point)
-{
-ÂÂÂ struct drm_syncobj_signal_pt *signal_pt;
-
-ÂÂÂ if ((syncobj->type == DRM_SYNCOBJ_TYPE_TIMELINE) &&
-ÂÂÂÂÂÂÂ (point <= syncobj->timeline))
-ÂÂÂÂÂÂÂ return drm_syncobj_get_stub_fence();
-
-ÂÂÂ list_for_each_entry(signal_pt, &syncobj->signal_pt_list, list) {
-ÂÂÂÂÂÂÂ if (point > signal_pt->value)
-ÂÂÂÂÂÂÂÂÂÂÂ continue;
-ÂÂÂÂÂÂÂ if ((syncobj->type == DRM_SYNCOBJ_TYPE_BINARY) &&
-ÂÂÂÂÂÂÂÂÂÂÂ (point != signal_pt->value))
-ÂÂÂÂÂÂÂÂÂÂÂ continue;
-ÂÂÂÂÂÂÂ return dma_fence_get(&signal_pt->fence_array->base);
-ÂÂÂ }
-ÂÂÂ return NULL;
-}
-
ÂÂ static void drm_syncobj_add_callback_locked(struct drm_syncobj *syncobj,
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ struct drm_syncobj_cb *cb,
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ drm_syncobj_func_t func)
@@ -152,158 +106,53 @@ static void drm_syncobj_add_callback_locked(struct drm_syncobj *syncobj,
ÂÂÂÂÂÂ list_add_tail(&cb->node, &syncobj->cb_list);
ÂÂ }
ÂÂ -static void drm_syncobj_fence_get_or_add_callback(struct drm_syncobj *syncobj,
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ struct dma_fence **fence,
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ struct drm_syncobj_cb *cb,
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ drm_syncobj_func_t func)
+static int drm_syncobj_fence_get_or_add_callback(struct drm_syncobj *syncobj,
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ struct dma_fence **fence,
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ struct drm_syncobj_cb *cb,
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ drm_syncobj_func_t func)
ÂÂ {
-ÂÂÂ u64 pt_value = 0;
-
-ÂÂÂ WARN_ON(*fence);
-
-ÂÂÂ if (syncobj->type == DRM_SYNCOBJ_TYPE_BINARY) {
-ÂÂÂÂÂÂÂ /*BINARY syncobj always wait on last pt */
-ÂÂÂÂÂÂÂ pt_value = syncobj->signal_point;
+ÂÂÂ int ret;
ÂÂ -ÂÂÂÂÂÂÂ if (pt_value == 0)
-ÂÂÂÂÂÂÂÂÂÂÂ pt_value += DRM_SYNCOBJ_BINARY_POINT;
-ÂÂÂ }
+ÂÂÂ *fence = drm_syncobj_fence_get(syncobj);
+ÂÂÂ if (*fence)
+ÂÂÂÂÂÂÂ return 1;
ÂÂ -ÂÂÂ mutex_lock(&syncobj->cb_mutex);
-ÂÂÂ spin_lock(&syncobj->pt_lock);
-ÂÂÂ *fence = drm_syncobj_find_signal_pt_for_point(syncobj, pt_value);
-ÂÂÂ spin_unlock(&syncobj->pt_lock);
-ÂÂÂ if (!*fence)
+ÂÂÂ spin_lock(&syncobj->lock);
+ÂÂÂ /* We've already tried once to get a fence and failed. Now that we
+ÂÂÂÂ * have the lock, try one more time just to be sure we don't add a
+ÂÂÂÂ * callback when a fence has already been set.
+ÂÂÂÂ */
+ÂÂÂ if (syncobj->fence) {
+ÂÂÂÂÂÂÂ *fence = dma_fence_get(rcu_dereference_protected(syncobj->fence,
+ lockdep_is_held(&syncobj->lock)));
+ÂÂÂÂÂÂÂ ret = 1;
+ÂÂÂ } else {
+ÂÂÂÂÂÂÂ *fence = NULL;
ÂÂÂÂÂÂÂÂÂÂ drm_syncobj_add_callback_locked(syncobj, cb, func);
-ÂÂÂ mutex_unlock(&syncobj->cb_mutex);
-}
-
-static void drm_syncobj_remove_callback(struct drm_syncobj *syncobj,
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ struct drm_syncobj_cb *cb)
-{
-ÂÂÂ mutex_lock(&syncobj->cb_mutex);
-ÂÂÂ list_del_init(&cb->node);
-ÂÂÂ mutex_unlock(&syncobj->cb_mutex);
-}
+ÂÂÂÂÂÂÂ ret = 0;
+ÂÂÂ }
+ÂÂÂ spin_unlock(&syncobj->lock);
ÂÂ -static void drm_syncobj_init(struct drm_syncobj *syncobj)
-{
-ÂÂÂ spin_lock(&syncobj->pt_lock);
-ÂÂÂ syncobj->timeline_context = dma_fence_context_alloc(1);
-ÂÂÂ syncobj->timeline = 0;
-ÂÂÂ syncobj->signal_point = 0;
-ÂÂÂ init_waitqueue_head(&syncobj->wq);
-
-ÂÂÂ INIT_LIST_HEAD(&syncobj->signal_pt_list);
-ÂÂÂ spin_unlock(&syncobj->pt_lock);
+ÂÂÂ return ret;
ÂÂ }
ÂÂ -static void drm_syncobj_fini(struct drm_syncobj *syncobj)
+void drm_syncobj_add_callback(struct drm_syncobj *syncobj,
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ struct drm_syncobj_cb *cb,
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ drm_syncobj_func_t func)
ÂÂ {
-ÂÂÂ struct drm_syncobj_signal_pt *signal_pt = NULL, *tmp;
-
-ÂÂÂ spin_lock(&syncobj->pt_lock);
-ÂÂÂ list_for_each_entry_safe(signal_pt, tmp,
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ &syncobj->signal_pt_list, list) {
-ÂÂÂÂÂÂÂ list_del(&signal_pt->list);
- dma_fence_put(&signal_pt->fence_array->base);
-ÂÂÂÂÂÂÂ kfree(signal_pt);
-ÂÂÂ }
-ÂÂÂ spin_unlock(&syncobj->pt_lock);
+ÂÂÂ spin_lock(&syncobj->lock);
+ÂÂÂ drm_syncobj_add_callback_locked(syncobj, cb, func);
+ÂÂÂ spin_unlock(&syncobj->lock);
ÂÂ }
ÂÂ -static int drm_syncobj_create_signal_pt(struct drm_syncobj *syncobj,
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ struct dma_fence *fence,
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ u64 point)
+void drm_syncobj_remove_callback(struct drm_syncobj *syncobj,
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ struct drm_syncobj_cb *cb)
ÂÂ {
-ÂÂÂ struct drm_syncobj_signal_pt *signal_pt =
-ÂÂÂÂÂÂÂ kzalloc(sizeof(struct drm_syncobj_signal_pt), GFP_KERNEL);
-ÂÂÂ struct drm_syncobj_signal_pt *tail_pt;
-ÂÂÂ struct dma_fence **fences;
-ÂÂÂ int num_fences = 0;
-ÂÂÂ int ret = 0, i;
-
-ÂÂÂ if (!signal_pt)
-ÂÂÂÂÂÂÂ return -ENOMEM;
-ÂÂÂ if (!fence)
-ÂÂÂÂÂÂÂ goto out;
-
-ÂÂÂ fences = kmalloc_array(sizeof(void *), 2, GFP_KERNEL);
-ÂÂÂ if (!fences) {
-ÂÂÂÂÂÂÂ ret = -ENOMEM;
-ÂÂÂÂÂÂÂ goto out;
-ÂÂÂ }
-ÂÂÂ fences[num_fences++] = dma_fence_get(fence);
-ÂÂÂ /* timeline syncobj must take this dependency */
-ÂÂÂ if (syncobj->type == DRM_SYNCOBJ_TYPE_TIMELINE) {
-ÂÂÂÂÂÂÂ spin_lock(&syncobj->pt_lock);
-ÂÂÂÂÂÂÂ if (!list_empty(&syncobj->signal_pt_list)) {
-ÂÂÂÂÂÂÂÂÂÂÂ tail_pt = list_last_entry(&syncobj->signal_pt_list,
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ struct drm_syncobj_signal_pt, list);
-ÂÂÂÂÂÂÂÂÂÂÂ fences[num_fences++] =
- dma_fence_get(&tail_pt->fence_array->base);
-ÂÂÂÂÂÂÂ }
-ÂÂÂÂÂÂÂ spin_unlock(&syncobj->pt_lock);
-ÂÂÂ }
-ÂÂÂ signal_pt->fence_array = dma_fence_array_create(num_fences, fences,
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ syncobj->timeline_context,
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ point, false);
-ÂÂÂ if (!signal_pt->fence_array) {
-ÂÂÂÂÂÂÂ ret = -ENOMEM;
-ÂÂÂÂÂÂÂ goto fail;
-ÂÂÂ }
-
-ÂÂÂ spin_lock(&syncobj->pt_lock);
-ÂÂÂ if (syncobj->signal_point >= point) {
-ÂÂÂÂÂÂÂ DRM_WARN("A later signal is ready!");
-ÂÂÂÂÂÂÂ spin_unlock(&syncobj->pt_lock);
-ÂÂÂÂÂÂÂ goto exist;
-ÂÂÂ }
-ÂÂÂ signal_pt->value = point;
-ÂÂÂ list_add_tail(&signal_pt->list, &syncobj->signal_pt_list);
-ÂÂÂ syncobj->signal_point = point;
-ÂÂÂ spin_unlock(&syncobj->pt_lock);
-ÂÂÂ wake_up_all(&syncobj->wq);
-
-ÂÂÂ return 0;
-exist:
-ÂÂÂ dma_fence_put(&signal_pt->fence_array->base);
-fail:
-ÂÂÂ for (i = 0; i < num_fences; i++)
-ÂÂÂÂÂÂÂ dma_fence_put(fences[i]);
-ÂÂÂ kfree(fences);
-out:
-ÂÂÂ kfree(signal_pt);
-ÂÂÂ return ret;
+ÂÂÂ spin_lock(&syncobj->lock);
+ÂÂÂ list_del_init(&cb->node);
+ÂÂÂ spin_unlock(&syncobj->lock);
ÂÂ }
ÂÂ -static void drm_syncobj_garbage_collection(struct drm_syncobj *syncobj)
-{
-ÂÂÂ struct drm_syncobj_signal_pt *signal_pt, *tmp, *tail_pt;
-
-ÂÂÂ spin_lock(&syncobj->pt_lock);
-ÂÂÂ tail_pt = list_last_entry(&syncobj->signal_pt_list,
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ struct drm_syncobj_signal_pt,
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ list);
-ÂÂÂ list_for_each_entry_safe(signal_pt, tmp,
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ &syncobj->signal_pt_list, list) {
-ÂÂÂÂÂÂÂ if (syncobj->type == DRM_SYNCOBJ_TYPE_BINARY &&
-ÂÂÂÂÂÂÂÂÂÂÂ signal_pt == tail_pt)
-ÂÂÂÂÂÂÂÂÂÂÂ continue;
-ÂÂÂÂÂÂÂ if (dma_fence_is_signaled(&signal_pt->fence_array->base)) {
-ÂÂÂÂÂÂÂÂÂÂÂ syncobj->timeline = signal_pt->value;
-ÂÂÂÂÂÂÂÂÂÂÂ list_del(&signal_pt->list);
- dma_fence_put(&signal_pt->fence_array->base);
-ÂÂÂÂÂÂÂÂÂÂÂ kfree(signal_pt);
-ÂÂÂÂÂÂÂ } else {
-ÂÂÂÂÂÂÂÂÂÂÂ /*signal_pt is in order in list, from small to big, so
-ÂÂÂÂÂÂÂÂÂÂÂÂ * the later must not be signal either */
-ÂÂÂÂÂÂÂÂÂÂÂ break;
-ÂÂÂÂÂÂÂ }
-ÂÂÂ }
-
-ÂÂÂ spin_unlock(&syncobj->pt_lock);
-}
ÂÂ /**
ÂÂÂ * drm_syncobj_replace_fence - replace fence in a sync object.
ÂÂÂ * @syncobj: Sync object to replace fence in
@@ -316,30 +165,28 @@ void drm_syncobj_replace_fence(struct drm_syncobj *syncobj,
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ u64 point,
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ struct dma_fence *fence)
ÂÂ {
-ÂÂÂ u64 pt_value = point;
-
-ÂÂÂ drm_syncobj_garbage_collection(syncobj);
-ÂÂÂ if (syncobj->type == DRM_SYNCOBJ_TYPE_BINARY) {
-ÂÂÂÂÂÂÂ if (!fence) {
-ÂÂÂÂÂÂÂÂÂÂÂ drm_syncobj_fini(syncobj);
-ÂÂÂÂÂÂÂÂÂÂÂ drm_syncobj_init(syncobj);
-ÂÂÂÂÂÂÂÂÂÂÂ return;
-ÂÂÂÂÂÂÂ }
-ÂÂÂÂÂÂÂ pt_value = syncobj->signal_point +
-ÂÂÂÂÂÂÂÂÂÂÂ DRM_SYNCOBJ_BINARY_POINT;
-ÂÂÂ }
-ÂÂÂ drm_syncobj_create_signal_pt(syncobj, fence, pt_value);
-ÂÂÂ if (fence) {
-ÂÂÂÂÂÂÂ struct drm_syncobj_cb *cur, *tmp;
-ÂÂÂÂÂÂÂ LIST_HEAD(cb_list);
+ÂÂÂ struct dma_fence *old_fence;
+ÂÂÂ struct drm_syncobj_cb *cur, *tmp;
+
+ÂÂÂ if (fence)
+ÂÂÂÂÂÂÂ dma_fence_get(fence);
+
+ÂÂÂ spin_lock(&syncobj->lock);
ÂÂ -ÂÂÂÂÂÂÂ mutex_lock(&syncobj->cb_mutex);
+ÂÂÂ old_fence = rcu_dereference_protected(syncobj->fence,
+ lockdep_is_held(&syncobj->lock));
+ÂÂÂ rcu_assign_pointer(syncobj->fence, fence);
+
+ÂÂÂ if (fence != old_fence) {
ÂÂÂÂÂÂÂÂÂÂ list_for_each_entry_safe(cur, tmp, &syncobj->cb_list, node) {
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ list_del_init(&cur->node);
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ cur->func(syncobj, cur);
ÂÂÂÂÂÂÂÂÂÂ }
-ÂÂÂÂÂÂÂ mutex_unlock(&syncobj->cb_mutex);
ÂÂÂÂÂÂ }
+
+ÂÂÂ spin_unlock(&syncobj->lock);
+
+ÂÂÂ dma_fence_put(old_fence);
ÂÂ }
ÂÂ EXPORT_SYMBOL(drm_syncobj_replace_fence);
ÂÂ @@ -362,64 +209,6 @@ static int drm_syncobj_assign_null_handle(struct drm_syncobj *syncobj)
ÂÂÂÂÂÂ return 0;
ÂÂ }
ÂÂ -static int
-drm_syncobj_point_get(struct drm_syncobj *syncobj, u64 point, u64 flags,
-ÂÂÂÂÂÂÂÂÂÂÂÂÂ struct dma_fence **fence)
-{
-ÂÂÂ int ret = 0;
-
-ÂÂÂ if (flags & DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT) {
-ÂÂÂÂÂÂÂ ret = wait_event_interruptible(syncobj->wq,
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ point <= syncobj->signal_point);
-ÂÂÂÂÂÂÂ if (ret < 0)
-ÂÂÂÂÂÂÂÂÂÂÂ return ret;
-ÂÂÂ }
-ÂÂÂ spin_lock(&syncobj->pt_lock);
-ÂÂÂ *fence = drm_syncobj_find_signal_pt_for_point(syncobj, point);
-ÂÂÂ if (!*fence)
-ÂÂÂÂÂÂÂ ret = -EINVAL;
-ÂÂÂ spin_unlock(&syncobj->pt_lock);
-ÂÂÂ return ret;
-}
-
-/**
- * drm_syncobj_search_fence - lookup and reference the fence in a sync object or
- * in a timeline point
- * @syncobj: sync object pointer
- * @point: timeline point
- * @flags: DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT or not
- * @fence: out parameter for the fence
- *
- * if flags is DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT, the function will block
- * here until specific timeline points is reached.
- * if not, you need a submit thread and block in userspace until all future
- * timeline points have materialized, only then you can submit to the kernel,
- * otherwise, function will fail to return fence.
- *
- * Returns 0 on success or a negative error value on failure. On success @fence
- * contains a reference to the fence, which must be released by calling
- * dma_fence_put().
- */
-int drm_syncobj_search_fence(struct drm_syncobj *syncobj, u64 point,
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ u64 flags, struct dma_fence **fence)
-{
-ÂÂÂ u64 pt_value = point;
-
-ÂÂÂ if (!syncobj)
-ÂÂÂÂÂÂÂ return -ENOENT;
-
-ÂÂÂ drm_syncobj_garbage_collection(syncobj);
-ÂÂÂ if (syncobj->type == DRM_SYNCOBJ_TYPE_BINARY) {
-ÂÂÂÂÂÂÂ /*BINARY syncobj always wait on last pt */
-ÂÂÂÂÂÂÂ pt_value = syncobj->signal_point;
-
-ÂÂÂÂÂÂÂ if (pt_value == 0)
-ÂÂÂÂÂÂÂÂÂÂÂ pt_value += DRM_SYNCOBJ_BINARY_POINT;
-ÂÂÂ }
-ÂÂÂ return drm_syncobj_point_get(syncobj, pt_value, flags, fence);
-}
-EXPORT_SYMBOL(drm_syncobj_search_fence);
-
ÂÂ /**
ÂÂÂ * drm_syncobj_find_fence - lookup and reference the fence in a sync object
ÂÂÂ * @file_private: drm file private pointer
@@ -429,7 +218,7 @@ EXPORT_SYMBOL(drm_syncobj_search_fence);
ÂÂÂ * @fence: out parameter for the fence
ÂÂÂ *
ÂÂÂ * This is just a convenience function that combines drm_syncobj_find() and
- * drm_syncobj_lookup_fence().
+ * drm_syncobj_fence_get().
ÂÂÂ *
ÂÂÂ * Returns 0 on success or a negative error value on failure. On success @fence
ÂÂÂ * contains a reference to the fence, which must be released by calling
@@ -440,11 +229,16 @@ int drm_syncobj_find_fence(struct drm_file *file_private,
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ struct dma_fence **fence)
ÂÂ {
ÂÂÂÂÂÂ struct drm_syncobj *syncobj = drm_syncobj_find(file_private, handle);
-ÂÂÂ int ret;
+ÂÂÂ int ret = 0;
ÂÂ -ÂÂÂ ret = drm_syncobj_search_fence(syncobj, point, flags, fence);
-ÂÂÂ if (syncobj)
-ÂÂÂÂÂÂÂ drm_syncobj_put(syncobj);
+ÂÂÂ if (!syncobj)
+ÂÂÂÂÂÂÂ return -ENOENT;
+
+ÂÂÂ *fence = drm_syncobj_fence_get(syncobj);
+ÂÂÂ if (!*fence) {
+ÂÂÂÂÂÂÂ ret = -EINVAL;
+ÂÂÂ }
+ÂÂÂ drm_syncobj_put(syncobj);
ÂÂÂÂÂÂ return ret;
ÂÂ }
ÂÂ EXPORT_SYMBOL(drm_syncobj_find_fence);
@@ -460,7 +254,7 @@ void drm_syncobj_free(struct kref *kref)
ÂÂÂÂÂÂ struct drm_syncobj *syncobj = container_of(kref,
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ struct drm_syncobj,
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ refcount);
-ÂÂÂ drm_syncobj_fini(syncobj);
+ÂÂÂ drm_syncobj_replace_fence(syncobj, 0, NULL);
ÂÂÂÂÂÂ kfree(syncobj);
ÂÂ }
ÂÂ EXPORT_SYMBOL(drm_syncobj_free);
@@ -489,13 +283,7 @@ int drm_syncobj_create(struct drm_syncobj **out_syncobj, uint32_t flags,
ÂÂ ÂÂÂÂÂÂ kref_init(&syncobj->refcount);
ÂÂÂÂÂÂ INIT_LIST_HEAD(&syncobj->cb_list);
-ÂÂÂ spin_lock_init(&syncobj->pt_lock);
-ÂÂÂ mutex_init(&syncobj->cb_mutex);
-ÂÂÂ if (flags & DRM_SYNCOBJ_CREATE_TYPE_TIMELINE)
-ÂÂÂÂÂÂÂ syncobj->type = DRM_SYNCOBJ_TYPE_TIMELINE;
-ÂÂÂ else
-ÂÂÂÂÂÂÂ syncobj->type = DRM_SYNCOBJ_TYPE_BINARY;
-ÂÂÂ drm_syncobj_init(syncobj);
+ÂÂÂ spin_lock_init(&syncobj->lock);
ÂÂ ÂÂÂÂÂÂ if (flags & DRM_SYNCOBJ_CREATE_SIGNALED) {
ÂÂÂÂÂÂÂÂÂÂ ret = drm_syncobj_assign_null_handle(syncobj);
@@ -778,8 +566,7 @@ drm_syncobj_create_ioctl(struct drm_device *dev, void *data,
ÂÂÂÂÂÂÂÂÂÂ return -EOPNOTSUPP;
ÂÂ ÂÂÂÂÂÂ /* no valid flags yet */
-ÂÂÂ if (args->flags & ~(DRM_SYNCOBJ_CREATE_SIGNALED |
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ DRM_SYNCOBJ_CREATE_TYPE_TIMELINE))
+ÂÂÂ if (args->flags & ~DRM_SYNCOBJ_CREATE_SIGNALED)
ÂÂÂÂÂÂÂÂÂÂ return -EINVAL;
ÂÂ ÂÂÂÂÂÂ return drm_syncobj_create_as_handle(file_private,
@@ -872,8 +659,9 @@ static void syncobj_wait_syncobj_func(struct drm_syncobj *syncobj,
ÂÂÂÂÂÂ struct syncobj_wait_entry *wait =
ÂÂÂÂÂÂÂÂÂÂ container_of(cb, struct syncobj_wait_entry, syncobj_cb);
ÂÂ -ÂÂÂ drm_syncobj_search_fence(syncobj, 0, 0, &wait->fence);
-
+ÂÂÂ /* This happens inside the syncobj lock */
+ÂÂÂ wait->fence = dma_fence_get(rcu_dereference_protected(syncobj->fence,
+ lockdep_is_held(&syncobj->lock)));
ÂÂÂÂÂÂ wake_up_process(wait->task);
ÂÂ }
ÂÂ @@ -899,8 +687,7 @@ static signed long drm_syncobj_array_wait_timeout(struct drm_syncobj **syncobjs,
ÂÂÂÂÂÂ signaled_count = 0;
ÂÂÂÂÂÂ for (i = 0; i < count; ++i) {
ÂÂÂÂÂÂÂÂÂÂ entries[i].task = current;
-ÂÂÂÂÂÂÂ drm_syncobj_search_fence(syncobjs[i], 0, 0,
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ &entries[i].fence);
+ÂÂÂÂÂÂÂ entries[i].fence = drm_syncobj_fence_get(syncobjs[i]);
ÂÂÂÂÂÂÂÂÂÂ if (!entries[i].fence) {
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ if (flags & DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT) {
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ continue;
@@ -931,9 +718,6 @@ static signed long drm_syncobj_array_wait_timeout(struct drm_syncobj **syncobjs,
ÂÂ ÂÂÂÂÂÂ if (flags & DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT) {
ÂÂÂÂÂÂÂÂÂÂ for (i = 0; i < count; ++i) {
-ÂÂÂÂÂÂÂÂÂÂÂ if (entries[i].fence)
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ continue;
-
drm_syncobj_fence_get_or_add_callback(syncobjs[i],
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ &entries[i].fence,
&entries[i].syncobj_cb,
@@ -1165,13 +949,12 @@ drm_syncobj_reset_ioctl(struct drm_device *dev, void *data,
ÂÂÂÂÂÂ if (ret < 0)
ÂÂÂÂÂÂÂÂÂÂ return ret;
ÂÂ -ÂÂÂ for (i = 0; i < args->count_handles; i++) {
-ÂÂÂÂÂÂÂ drm_syncobj_fini(syncobjs[i]);
-ÂÂÂÂÂÂÂ drm_syncobj_init(syncobjs[i]);
-ÂÂÂ }
+ÂÂÂ for (i = 0; i < args->count_handles; i++)
+ÂÂÂÂÂÂÂ drm_syncobj_replace_fence(syncobjs[i], 0, NULL);
+
ÂÂÂÂÂÂ drm_syncobj_array_free(syncobjs, args->count_handles);
ÂÂ -ÂÂÂ return ret;
+ÂÂÂ return 0;
ÂÂ }
ÂÂ ÂÂ int
diff --git a/include/drm/drm_syncobj.h b/include/drm/drm_syncobj.h
index 29244cbcd05e..2eda44def639 100644
--- a/include/drm/drm_syncobj.h
+++ b/include/drm/drm_syncobj.h
@@ -30,15 +30,10 @@
ÂÂ ÂÂ struct drm_syncobj_cb;
ÂÂ -enum drm_syncobj_type {
-ÂÂÂ DRM_SYNCOBJ_TYPE_BINARY,
-ÂÂÂ DRM_SYNCOBJ_TYPE_TIMELINE
-};
-
ÂÂ /**
ÂÂÂ * struct drm_syncobj - sync object.
ÂÂÂ *
- * This structure defines a generic sync object which is timeline based.
+ * This structure defines a generic sync object which wraps a &dma_fence.
ÂÂÂ */
ÂÂ struct drm_syncobj {
ÂÂÂÂÂÂ /**
@@ -46,42 +41,21 @@ struct drm_syncobj {
ÂÂÂÂÂÂÂ */
ÂÂÂÂÂÂ struct kref refcount;
ÂÂÂÂÂÂ /**
-ÂÂÂÂ * @type: indicate syncobj type
-ÂÂÂÂ */
-ÂÂÂ enum drm_syncobj_type type;
-ÂÂÂ /**
-ÂÂÂÂ * @wq: wait signal operation work queue
-ÂÂÂÂ */
-ÂÂÂ wait_queue_head_tÂÂÂ wq;
-ÂÂÂ /**
-ÂÂÂÂ * @timeline_context: fence context used by timeline
+ÂÂÂÂ * @fence:
+ÂÂÂÂ * NULL or a pointer to the fence bound to this object.
+ÂÂÂÂ *
+ÂÂÂÂ * This field should not be used directly. Use drm_syncobj_fence_get()
+ÂÂÂÂ * and drm_syncobj_replace_fence() instead.
ÂÂÂÂÂÂÂ */
-ÂÂÂ u64 timeline_context;
+ÂÂÂ struct dma_fence __rcu *fence;
ÂÂÂÂÂÂ /**
-ÂÂÂÂ * @timeline: syncobj timeline value, which indicates point is signaled.
+ÂÂÂÂ * @cb_list: List of callbacks to call when the &fence gets replaced.
ÂÂÂÂÂÂÂ */
-ÂÂÂ u64 timeline;
-ÂÂÂ /**
-ÂÂÂÂ * @signal_point: which indicates the latest signaler point.
-ÂÂÂÂ */
-ÂÂÂ u64 signal_point;
-ÂÂÂ /**
-ÂÂÂÂ * @signal_pt_list: signaler point list.
-ÂÂÂÂ */
-ÂÂÂ struct list_head signal_pt_list;
-
-ÂÂÂ /**
-ÂÂÂÂÂÂÂÂ * @cb_list: List of callbacks to call when the &fence gets replaced.
-ÂÂÂÂÂÂÂÂ */
ÂÂÂÂÂÂ struct list_head cb_list;
ÂÂÂÂÂÂ /**
-ÂÂÂÂ * @pt_lock: Protects pt list.
+ÂÂÂÂ * @lock: Protects &cb_list and write-locks &fence.
ÂÂÂÂÂÂÂ */
-ÂÂÂ spinlock_t pt_lock;
-ÂÂÂ /**
-ÂÂÂÂ * @cb_mutex: Protects syncobj cb list.
-ÂÂÂÂ */
-ÂÂÂ struct mutex cb_mutex;
+ÂÂÂ spinlock_t lock;
ÂÂÂÂÂÂ /**
ÂÂÂÂÂÂÂ * @file: A file backing for this syncobj.
ÂÂÂÂÂÂÂ */
@@ -94,7 +68,7 @@ typedef void (*drm_syncobj_func_t)(struct drm_syncobj *syncobj,
ÂÂ /**
ÂÂÂ * struct drm_syncobj_cb - callback for drm_syncobj_add_callback
ÂÂÂ * @node: used by drm_syncob_add_callback to append this struct to
- *ÂÂÂÂÂÂ &drm_syncobj.cb_list
+ *ÂÂÂÂÂ &drm_syncobj.cb_list
ÂÂÂ * @func: drm_syncobj_func_t to call
ÂÂÂ *
ÂÂÂ * This struct will be initialized by drm_syncobj_add_callback, additional
@@ -132,6 +106,29 @@ drm_syncobj_put(struct drm_syncobj *obj)
ÂÂÂÂÂÂ kref_put(&obj->refcount, drm_syncobj_free);
ÂÂ }
ÂÂ +/**
+ * drm_syncobj_fence_get - get a reference to a fence in a sync object
+ * @syncobj: sync object.
+ *
+ * This acquires additional reference to &drm_syncobj.fence contained in @obj,
+ * if not NULL. It is illegal to call this without already holding a reference.
+ * No locks required.
+ *
+ * Returns:
+ * Either the fence of @obj or NULL if there's none.
+ */
+static inline struct dma_fence *
+drm_syncobj_fence_get(struct drm_syncobj *syncobj)
+{
+ÂÂÂ struct dma_fence *fence;
+
+ÂÂÂ rcu_read_lock();
+ÂÂÂ fence = dma_fence_get_rcu_safe(&syncobj->fence);
+ÂÂÂ rcu_read_unlock();
+
+ÂÂÂ return fence;
+}
+
ÂÂ struct drm_syncobj *drm_syncobj_find(struct drm_file *file_private,
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ u32 handle);
ÂÂ void drm_syncobj_replace_fence(struct drm_syncobj *syncobj, u64 point,
@@ -145,7 +142,5 @@ int drm_syncobj_create(struct drm_syncobj **out_syncobj, uint32_t flags,
ÂÂ int drm_syncobj_get_handle(struct drm_file *file_private,
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ struct drm_syncobj *syncobj, u32 *handle);
ÂÂ int drm_syncobj_get_fd(struct drm_syncobj *syncobj, int *p_fd);
-int drm_syncobj_search_fence(struct drm_syncobj *syncobj, u64 point, u64 flags,
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ struct dma_fence **fence);
ÂÂ ÂÂ #endif
_______________________________________________
dri-devel mailing list
dri-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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