[PATCH 52/52] drm/i915: Drop struct_mutex requirement for unpin_from_display_plane

Chris Wilson chris at chris-wilson.co.uk
Sat Jun 30 20:36:09 UTC 2018


Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
---
 drivers/gpu/drm/i915/i915_drv.h      | 12 ++++++-
 drivers/gpu/drm/i915/i915_gem.c      | 12 ++++---
 drivers/gpu/drm/i915/intel_display.c | 51 ++++++----------------------
 drivers/gpu/drm/i915/intel_fbdev.c   | 12 ++-----
 4 files changed, 31 insertions(+), 56 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index ca6260b546b4..9a61cfc6c726 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -3151,12 +3151,22 @@ int __must_check
 i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj, bool write);
 int __must_check
 i915_gem_object_set_to_cpu_domain(struct drm_i915_gem_object *obj, bool write);
+
 struct i915_vma * __must_check
 i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,
 				     u32 alignment,
 				     const struct i915_ggtt_view *view,
 				     unsigned int flags);
-void i915_gem_object_unpin_from_display_plane(struct i915_vma *vma);
+
+void __i915_gem_object_unpin_from_display_plane(struct i915_vma *vma);
+static inline void
+i915_gem_object_unpin_from_display_plane(struct i915_vma *vma)
+{
+	mutex_lock(&vma->vm->mutex);
+	__i915_gem_object_unpin_from_display_plane(vma);
+	mutex_unlock(&vma->vm->mutex);
+}
+
 int i915_gem_object_attach_phys(struct drm_i915_gem_object *obj,
 				int align);
 int i915_gem_open(struct drm_i915_private *i915, struct drm_file *file);
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 5d003cf9ef61..b147b2da78c4 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -1664,16 +1664,16 @@ static void i915_gem_object_bump_inactive_ggtt(struct drm_i915_gem_object *obj)
 	struct list_head *list;
 	struct i915_vma *vma;
 
+	lockdep_assert_held(&i915->ggtt.vm.mutex);
 	GEM_BUG_ON(!i915_gem_object_has_pinned_pages(obj));
 
-	mutex_lock(&i915->ggtt.vm.mutex);
 	for_each_ggtt_vma(vma, obj) {
 		if (!drm_mm_node_allocated(&vma->node))
 			continue;
 
+		lockdep_assert_held(&vma->vm->mutex);
 		list_move_tail(&vma->vm_link, &vma->vm->bound_list);
 	}
-	mutex_unlock(&i915->ggtt.vm.mutex);
 
 	spin_lock(&i915->mm.obj_lock);
 	list = obj->bind_count ? &i915->mm.bound_list : &i915->mm.unbound_list;
@@ -1760,7 +1760,9 @@ i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,
 		goto out_unpin;
 
 	/* And bump the LRU for this access */
+	mutex_lock(&to_i915(dev)->ggtt.vm.mutex);
 	i915_gem_object_bump_inactive_ggtt(obj);
+	mutex_unlock(&to_i915(dev)->ggtt.vm.mutex);
 
 	if (write_domain != 0)
 		intel_fb_obj_invalidate(obj,
@@ -3787,9 +3789,9 @@ i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,
 }
 
 void
-i915_gem_object_unpin_from_display_plane(struct i915_vma *vma)
+__i915_gem_object_unpin_from_display_plane(struct i915_vma *vma)
 {
-	i915_gem_object_assert_held(vma->obj);
+	lockdep_assert_held(&vma->vm->mutex);
 
 	if (WARN_ON(vma->obj->pin_global == 0))
 		return;
@@ -3800,7 +3802,7 @@ i915_gem_object_unpin_from_display_plane(struct i915_vma *vma)
 	/* Bump the LRU to try and avoid premature eviction whilst flipping  */
 	i915_gem_object_bump_inactive_ggtt(vma->obj);
 
-	i915_vma_unpin(vma);
+	__i915_vma_unpin(vma);
 }
 
 /**
diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
index 0d0f3853838a..7852d102e2d4 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -2094,8 +2094,6 @@ intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb,
 	unsigned int pinctl;
 	u32 alignment;
 
-	WARN_ON(!mutex_is_locked(&dev->struct_mutex));
-
 	alignment = intel_surf_alignment(fb, 0);
 
 	intel_fill_fb_ggtt_view(&view, fb, rotation);
@@ -2176,11 +2174,12 @@ intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb,
 
 void intel_unpin_fb_vma(struct i915_vma *vma, unsigned long flags)
 {
-	lockdep_assert_held(&vma->vm->i915->drm.struct_mutex);
-
+	mutex_lock(&vma->vm->mutex);
 	if (flags & PLANE_HAS_FENCE)
-		i915_vma_unpin_fence(vma);
-	i915_gem_object_unpin_from_display_plane(vma);
+		__i915_vma_unpin_fence(vma);
+	__i915_gem_object_unpin_from_display_plane(vma);
+	mutex_unlock(&vma->vm->mutex);
+
 	i915_vma_put(vma);
 }
 
@@ -2715,12 +2714,10 @@ intel_alloc_initial_plane_obj(struct intel_crtc *crtc,
 	if (size_aligned * 2 > dev_priv->stolen_usable_size)
 		return false;
 
-	mutex_lock(&dev->struct_mutex);
 	obj = i915_gem_object_create_stolen_for_preallocated(dev_priv,
 							     base_aligned,
 							     base_aligned,
 							     size_aligned);
-	mutex_unlock(&dev->struct_mutex);
 	if (!obj)
 		return false;
 
@@ -2850,13 +2847,11 @@ intel_find_initial_plane_obj(struct intel_crtc *intel_crtc,
 	return;
 
 valid_fb:
-	mutex_lock(&dev->struct_mutex);
 	intel_state->vma =
 		intel_pin_and_fence_fb_obj(fb,
 					   primary->state->rotation,
 					   intel_plane_uses_fence(intel_state),
 					   &intel_state->flags);
-	mutex_unlock(&dev->struct_mutex);
 	if (IS_ERR(intel_state->vma)) {
 		DRM_ERROR("failed to pin boot fb on pipe %d: %li\n",
 			  intel_crtc->pipe, PTR_ERR(intel_state->vma));
@@ -13011,8 +13006,6 @@ static void fb_obj_bump_render_priority(struct drm_i915_gem_object *obj)
  * bits.  Some older platforms need special physical address handling for
  * cursor planes.
  *
- * Must be called with struct_mutex held.
- *
  * Returns 0 on success, negative error code on failure.
  */
 int
@@ -13065,24 +13058,13 @@ intel_prepare_plane_fb(struct drm_plane *plane,
 	if (!obj)
 		return 0;
 
-	ret = i915_gem_object_pin_pages(obj);
+	ret = intel_plane_pin_fb(to_intel_plane_state(new_state));
 	if (ret)
 		return ret;
 
-	ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
-	if (ret) {
-		i915_gem_object_unpin_pages(obj);
-		return ret;
-	}
-
-	ret = intel_plane_pin_fb(to_intel_plane_state(new_state));
-
+	mutex_lock(&dev_priv->drm.struct_mutex);
 	fb_obj_bump_render_priority(obj);
-
 	mutex_unlock(&dev_priv->drm.struct_mutex);
-	i915_gem_object_unpin_pages(obj);
-	if (ret)
-		return ret;
 
 	intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
 
@@ -13114,19 +13096,13 @@ intel_prepare_plane_fb(struct drm_plane *plane,
  * @old_state: the state from the previous modeset
  *
  * Cleans up a framebuffer that has just been removed from a plane.
- *
- * Must be called with struct_mutex held.
  */
 void
 intel_cleanup_plane_fb(struct drm_plane *plane,
 		       struct drm_plane_state *old_state)
 {
-	struct drm_i915_private *dev_priv = to_i915(plane->dev);
-
 	/* Should only be called after a successful intel_prepare_plane_fb()! */
-	mutex_lock(&dev_priv->drm.struct_mutex);
 	intel_plane_unpin_fb(to_intel_plane_state(old_state));
-	mutex_unlock(&dev_priv->drm.struct_mutex);
 }
 
 int
@@ -13454,12 +13430,11 @@ intel_legacy_cursor_update(struct drm_plane *plane,
 			   uint32_t src_w, uint32_t src_h,
 			   struct drm_modeset_acquire_ctx *ctx)
 {
-	struct drm_i915_private *dev_priv = to_i915(crtc->dev);
-	int ret;
 	struct drm_plane_state *old_plane_state, *new_plane_state;
 	struct intel_plane *intel_plane = to_intel_plane(plane);
-	struct drm_framebuffer *old_fb;
 	struct drm_crtc_state *crtc_state = crtc->state;
+	struct drm_framebuffer *old_fb;
+	int ret;
 
 	/*
 	 * When crtc is inactive or there is a modeset pending,
@@ -13514,13 +13489,9 @@ intel_legacy_cursor_update(struct drm_plane *plane,
 	if (ret)
 		goto out_free;
 
-	ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
-	if (ret)
-		goto out_free;
-
 	ret = intel_plane_pin_fb(to_intel_plane_state(new_plane_state));
 	if (ret)
-		goto out_unlock;
+		goto out_free;
 
 	intel_fb_obj_flush(intel_fb_obj(fb), ORIGIN_FLIP);
 
@@ -13543,8 +13514,6 @@ intel_legacy_cursor_update(struct drm_plane *plane,
 
 	intel_plane_unpin_fb(to_intel_plane_state(old_plane_state));
 
-out_unlock:
-	mutex_unlock(&dev_priv->drm.struct_mutex);
 out_free:
 	if (ret)
 		intel_plane_destroy_state(plane, new_plane_state);
diff --git a/drivers/gpu/drm/i915/intel_fbdev.c b/drivers/gpu/drm/i915/intel_fbdev.c
index fb2f9fce34cd..18e484ee2ea7 100644
--- a/drivers/gpu/drm/i915/intel_fbdev.c
+++ b/drivers/gpu/drm/i915/intel_fbdev.c
@@ -206,7 +206,6 @@ static int intelfb_create(struct drm_fb_helper *helper,
 		sizes->fb_height = intel_fb->base.height;
 	}
 
-	mutex_lock(&dev->struct_mutex);
 	intel_runtime_pm_get(dev_priv);
 
 	/* Pin the GGTT vma for our access via info->screen_base.
@@ -218,7 +217,7 @@ static int intelfb_create(struct drm_fb_helper *helper,
 					 false, &flags);
 	if (IS_ERR(vma)) {
 		ret = PTR_ERR(vma);
-		goto out_unlock;
+		goto out_pm;
 	}
 
 	fb = &ifbdev->fb->base;
@@ -276,15 +275,13 @@ static int intelfb_create(struct drm_fb_helper *helper,
 	ifbdev->vma_flags = flags;
 
 	intel_runtime_pm_put(dev_priv);
-	mutex_unlock(&dev->struct_mutex);
 	vga_switcheroo_client_fb_set(pdev, info);
 	return 0;
 
 out_unpin:
 	intel_unpin_fb_vma(vma, flags);
-out_unlock:
+out_pm:
 	intel_runtime_pm_put(dev_priv);
-	mutex_unlock(&dev->struct_mutex);
 	return ret;
 }
 
@@ -517,11 +514,8 @@ static void intel_fbdev_destroy(struct intel_fbdev *ifbdev)
 
 	drm_fb_helper_fini(&ifbdev->helper);
 
-	if (ifbdev->vma) {
-		mutex_lock(&ifbdev->helper.dev->struct_mutex);
+	if (ifbdev->vma)
 		intel_unpin_fb_vma(ifbdev->vma, ifbdev->vma_flags);
-		mutex_unlock(&ifbdev->helper.dev->struct_mutex);
-	}
 
 	if (ifbdev->fb)
 		drm_framebuffer_remove(&ifbdev->fb->base);
-- 
2.18.0



More information about the Intel-gfx-trybot mailing list