return nouveau_fence_wait(fence, NULL, false, false);
}
+ /* try to take wchan's mutex, if we can't take it right away
+ * we have to fallback to software sync to prevent locking
+ * order issues
+ */
+ if (!mutex_trylock(&wchan->mutex)) {
+ free_semaphore(&sema->ref);
+ return nouveau_fence_wait(fence, NULL, false, false);
+ }
+
/* Make wchan wait until it gets signalled */
ret = emit_semaphore(wchan, NV_SW_SEMAPHORE_ACQUIRE, sema);
+ mutex_unlock(&wchan->mutex);
if (ret)
goto out;