All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel.vetter@ffwll.ch>
To: Intel Graphics Development <intel-gfx@lists.freedesktop.org>
Subject: [PATCH 08/13] dma-fence: cross-release annotations
Date: Wed,  7 Nov 2018 16:30:14 +0100	[thread overview]
Message-ID: <20181107153019.26401-8-daniel.vetter@ffwll.ch> (raw)
In-Reply-To: <20181107153019.26401-1-daniel.vetter@ffwll.ch>

dma-fence is a completion on steriods, which also allows hardware to
directly sync work among each another. It's supposed to be deadlock
free, so let's try to make sure that holds at least for the cpu-only
interactions and waits.

It's a bit much #ifdef, but I figured for the single case it's not
worth it to pull it all out.

Also, the single global lockdep map is intentional: dma_fences are
supposed to be shared, we need all drivers to be compatible to each
another in their locking hierarchy.

v2:
- handle #idef mess cleaner
- also annotate dma_fence_signal()

v3:
- Add a dma_fence_might_wait() function to annotate fastpaths
- Put it all into headers for other code to use

Cc: Sumit Semwal <sumit.semwal@linaro.org>
Cc: Gustavo Padovan <gustavo@padovan.org>
Cc: linux-media@vger.kernel.org
Cc: linaro-mm-sig@lists.linaro.org
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
---
 drivers/dma-buf/dma-fence.c | 14 ++++++++++++++
 include/linux/dma-fence.h   | 28 ++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+)

diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c
index 1551ca7df394..7d56d8b48624 100644
--- a/drivers/dma-buf/dma-fence.c
+++ b/drivers/dma-buf/dma-fence.c
@@ -30,6 +30,13 @@
 EXPORT_TRACEPOINT_SYMBOL(dma_fence_emit);
 EXPORT_TRACEPOINT_SYMBOL(dma_fence_enable_signal);
 
+
+#ifdef CONFIG_LOCKDEP_CROSSRELEASE
+struct lockdep_map_cross dma_fence_wait_map =
+	STATIC_CROSS_LOCKDEP_MAP_INIT("dma_fence_signal", &dma_fence_wait_map);
+EXPORT_SYMBOL(dma_fence_wait_map);
+#endif
+
 /*
  * fence context counter: each execution context should have its own
  * fence context, this allows checking if fences belong to the same
@@ -106,6 +113,8 @@ int dma_fence_signal_locked(struct dma_fence *fence)
 
 	lockdep_assert_held(fence->lock);
 
+	dma_fence_wait_release_commit();
+
 	if (WARN_ON(!fence))
 		return -EINVAL;
 
@@ -153,6 +162,8 @@ int dma_fence_signal(struct dma_fence *fence)
 	if (test_and_set_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags))
 		return -EINVAL;
 
+	dma_fence_wait_release_commit();
+
 	fence->timestamp = ktime_get();
 	set_bit(DMA_FENCE_FLAG_TIMESTAMP_BIT, &fence->flags);
 	trace_dma_fence_signaled(fence);
@@ -197,12 +208,15 @@ dma_fence_wait_timeout(struct dma_fence *fence, bool intr, signed long timeout)
 	if (WARN_ON(timeout < 0))
 		return -EINVAL;
 
+	dma_fence_wait_acquire();
 	trace_dma_fence_wait_start(fence);
 	if (fence->ops->wait)
 		ret = fence->ops->wait(fence, intr, timeout);
 	else
 		ret = dma_fence_default_wait(fence, intr, timeout);
 	trace_dma_fence_wait_end(fence);
+	dma_fence_wait_release();
+
 	return ret;
 }
 EXPORT_SYMBOL(dma_fence_wait_timeout);
diff --git a/include/linux/dma-fence.h b/include/linux/dma-fence.h
index 02dba8cd033d..8a045334a207 100644
--- a/include/linux/dma-fence.h
+++ b/include/linux/dma-fence.h
@@ -34,6 +34,34 @@ struct dma_fence;
 struct dma_fence_ops;
 struct dma_fence_cb;
 
+#ifdef CONFIG_LOCKDEP_CROSSRELEASE
+#include <linux/lockdep.h>
+extern struct lockdep_map_cross dma_fence_wait_map;
+
+static inline void dma_fence_wait_acquire(void)
+{
+	lock_acquire_exclusive(&dma_fence_wait_map.map, 0, 0, NULL, _RET_IP_);
+}
+static inline void dma_fence_wait_release(void)
+{
+	lock_release(&dma_fence_wait_map.map, 0, _RET_IP_);
+}
+static inline void dma_fence_wait_release_commit(void)
+{
+	lock_commit_crosslock(&dma_fence_wait_map.map);
+}
+#else
+static inline void dma_fence_wait_acquire(void) {}
+static inline void dma_fence_wait_release(void) {}
+static inline void dma_fence_wait_release_commit(void) {}
+#endif
+
+static inline void dma_fence_might_wait(void)
+{
+	dma_fence_wait_acquire();
+	dma_fence_wait_release();
+}
+
 /**
  * struct dma_fence - software synchronization primitive
  * @refcount: refcount for this fence
-- 
2.19.1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  parent reply	other threads:[~2018-11-07 15:30 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-07 15:30 [PATCH 01/13] locking/lockdep: restore cross-release checks Daniel Vetter
2018-11-07 15:30 ` [PATCH 02/13] kthread: finer-grained lockdep/cross-release completion Daniel Vetter
2018-11-07 15:30 ` [PATCH 03/13] lockdep: Remove GFP_NOLOCKDEP annotation Daniel Vetter
2018-11-07 15:30 ` [PATCH 04/13] kernel/lockdep: Make cross-release a config option Daniel Vetter
2018-11-07 15:30 ` [PATCH 05/13] mm: Check if mmu notifier callbacks are allowed to fail Daniel Vetter
2018-11-07 15:30 ` [PATCH 06/13] mm, notifier: Catch sleeping/blocking for !blockable Daniel Vetter
2018-11-07 15:30 ` [PATCH 07/13] mm, notifier: Add a lockdep map for invalidate_range_start Daniel Vetter
2018-11-07 15:30 ` Daniel Vetter [this message]
2018-11-07 15:30 ` [PATCH 09/13] reservation: Annotate dma_fence waits Daniel Vetter
2018-11-07 15:30 ` [PATCH 10/13] drm/i915: " Daniel Vetter
2018-11-07 15:30 ` [PATCH 11/13] drm/i915: annotate intel_atomic_commit_fence_wait Daniel Vetter
2018-11-07 15:30 ` [PATCH 12/13] HAX FOR CI: Enable cross-release Daniel Vetter
2018-11-08  9:31   ` [PATCH] " Daniel Vetter
2018-11-08  9:41     ` Chris Wilson
2018-11-20 11:00       ` Daniel Vetter
2018-11-20 10:58     ` Daniel Vetter
2018-11-22 16:35       ` Daniel Vetter
2018-11-23  8:53         ` Daniel Vetter
2018-11-23 12:45           ` Daniel Vetter
2018-11-23 13:24             ` Daniel Vetter
2018-11-07 15:30 ` [PATCH 13/13] Revert "locking/lockdep, cpu/hotplug: Annotate AP thread" Daniel Vetter
2018-11-07 16:51 ` ✗ Fi.CI.CHECKPATCH: warning for series starting with [01/13] locking/lockdep: restore cross-release checks Patchwork
2018-11-07 16:57 ` ✗ Fi.CI.SPARSE: " Patchwork
2018-11-07 17:07 ` ✗ Fi.CI.BAT: failure " Patchwork
2018-11-08 10:04 ` ✗ Fi.CI.CHECKPATCH: warning for series starting with [01/13] locking/lockdep: restore cross-release checks (rev2) Patchwork
2018-11-08 10:10 ` ✗ Fi.CI.SPARSE: " Patchwork
2018-11-08 10:21 ` ✗ Fi.CI.BAT: failure " Patchwork
2018-11-20 12:33 ` ✗ Fi.CI.CHECKPATCH: warning for series starting with [01/13] locking/lockdep: restore cross-release checks (rev3) Patchwork
2018-11-20 12:39 ` ✗ Fi.CI.SPARSE: " Patchwork
2018-11-20 12:53 ` ✗ Fi.CI.BAT: failure " Patchwork
2018-11-22 16:39 ` ✗ Fi.CI.BAT: failure for series starting with [01/13] locking/lockdep: restore cross-release checks (rev4) Patchwork
2018-11-23  8:57 ` ✗ Fi.CI.BAT: failure for series starting with [01/13] locking/lockdep: restore cross-release checks (rev5) Patchwork
2018-11-23 12:51 ` ✗ Fi.CI.CHECKPATCH: warning for series starting with [01/13] locking/lockdep: restore cross-release checks (rev6) Patchwork
2018-11-23 12:57 ` ✗ Fi.CI.SPARSE: " Patchwork
2018-11-23 13:08 ` ✗ Fi.CI.BAT: failure " Patchwork
2018-11-23 13:55 ` ✗ Fi.CI.CHECKPATCH: warning for series starting with [01/13] locking/lockdep: restore cross-release checks (rev7) Patchwork
2018-11-23 14:01 ` ✗ Fi.CI.SPARSE: " Patchwork
2018-11-23 14:12 ` ✗ Fi.CI.BAT: failure " Patchwork

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=20181107153019.26401-8-daniel.vetter@ffwll.ch \
    --to=daniel.vetter@ffwll.ch \
    --cc=intel-gfx@lists.freedesktop.org \
    /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.