[10/13] drm/i915: Annotate dma_fence waits
diff mbox series

Message ID 20181107153019.26401-10-daniel.vetter@ffwll.ch
State New
Headers show
  • [01/13] locking/lockdep: restore cross-release checks
Related show

Commit Message

Daniel Vetter Nov. 7, 2018, 3:30 p.m. UTC
i915_request_wait is simply our i915-optimized version of
dma_fence_wait. They both use the exact same code. To help lockdep
discovering all the dependencies, annotate it.

v2: We do opportunistic retiring of dma-fences while holding
struct_mutex. The recursion this causes is intentional, and we do have
other paths which (hopefully) do depend upon the struct_mutex. 2nd
option to fix these annotations (and probably even better) would be
creating a dma_fence_signal_opportunistic, which doesnt have the
lockdep annotations. But that also doesn't guarantee that we'll
actually manage to signal fences without depending upon struct_mutex
somewhere, so might as well go with this trick here.

Aside, for non-i915 people: struct_mutex is our bkl. The locking rules
are ... complicated.

Cc: Jani Nikula <jani.nikula@linux.intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Cc: intel-gfx@lists.freedesktop.org
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
 drivers/gpu/drm/i915/i915_request.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff mbox series

diff --git a/drivers/gpu/drm/i915/i915_request.c b/drivers/gpu/drm/i915/i915_request.c
index 71107540581d..0f800b8967a4 100644
--- a/drivers/gpu/drm/i915/i915_request.c
+++ b/drivers/gpu/drm/i915/i915_request.c
@@ -30,6 +30,10 @@ 
 #include "i915_drv.h"
+static long __i915_request_wait(struct i915_request *rq,
+				unsigned int flags,
+				long timeout);
 static const char *i915_fence_get_driver_name(struct dma_fence *fence)
 	return "i915";
@@ -66,7 +70,7 @@  static signed long i915_fence_wait(struct dma_fence *fence,
 				   bool interruptible,
 				   signed long timeout)
-	return i915_request_wait(to_request(fence), interruptible, timeout);
+	return __i915_request_wait(to_request(fence), interruptible, timeout);
 static void i915_fence_release(struct dma_fence *fence)
@@ -1201,6 +1205,21 @@  static bool __i915_wait_request_check_and_reset(struct i915_request *request)
 long i915_request_wait(struct i915_request *rq,
 		       unsigned int flags,
 		       long timeout)
+	long ret;
+	if (!lockdep_is_held(&rq->i915->drm.struct_mutex))
+		dma_fence_wait_acquire();
+	ret = __i915_request_wait(rq, flags, timeout);
+	if (!lockdep_is_held(&rq->i915->drm.struct_mutex))
+		dma_fence_wait_release();
+	return ret;
+static long __i915_request_wait(struct i915_request *rq,
+				unsigned int flags,
+				long timeout)
 	const int state = flags & I915_WAIT_INTERRUPTIBLE ?