[PATCH 4/5] drm/i915: Unconditionally call post_unpin after pinning

Maarten Lankhorst maarten.lankhorst at linux.intel.com
Sat Jul 3 05:38:33 UTC 2021


This requires the pin call to take an extra reference for
anything released by post_unpin, but makes it possible
to move over intel_context to i915_active.

Signed-off-by: Maarten Lankhorst <maarten.lankhorst at linux.intel.com>
---
 drivers/gpu/drm/i915/gem/i915_gem_object.h      | 6 ++++++
 drivers/gpu/drm/i915/gt/gen6_ppgtt.c            | 8 ++++++++
 drivers/gpu/drm/i915/gt/gen6_ppgtt.h            | 1 +
 drivers/gpu/drm/i915/gt/intel_context.c         | 6 +-----
 drivers/gpu/drm/i915/gt/intel_lrc.c             | 4 ++++
 drivers/gpu/drm/i915/gt/intel_ring_submission.c | 7 +++++++
 6 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/i915/gem/i915_gem_object.h b/drivers/gpu/drm/i915/gem/i915_gem_object.h
index ea3224a480c4..1a740d2f8f88 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_object.h
+++ b/drivers/gpu/drm/i915/gem/i915_gem_object.h
@@ -477,6 +477,12 @@ static inline void i915_gem_object_unpin_map(struct drm_i915_gem_object *obj)
 	i915_gem_object_unpin_pages(obj);
 }
 
+static inline void __i915_gem_object_pin_map(struct drm_i915_gem_object *obj)
+{
+	GEM_WARN_ON(!obj->mm.mapping);
+	__i915_gem_object_pin_pages(obj);
+}
+
 void __i915_gem_object_release_map(struct drm_i915_gem_object *obj);
 
 int i915_gem_object_prepare_read(struct drm_i915_gem_object *obj,
diff --git a/drivers/gpu/drm/i915/gt/gen6_ppgtt.c b/drivers/gpu/drm/i915/gt/gen6_ppgtt.c
index 1aee5e6b1b23..185935c3ef35 100644
--- a/drivers/gpu/drm/i915/gt/gen6_ppgtt.c
+++ b/drivers/gpu/drm/i915/gt/gen6_ppgtt.c
@@ -362,6 +362,14 @@ static struct i915_vma *pd_vma_create(struct gen6_ppgtt *ppgtt, int size)
 	return vma;
 }
 
+void __gen6_ppgtt_pin(struct i915_ppgtt *base)
+{
+	struct gen6_ppgtt *ppgtt = to_gen6_ppgtt(base);
+
+	GEM_BUG_ON(!atomic_read(&ppgtt->pin_count));
+	atomic_inc(&ppgtt->pin_count);
+}
+
 int gen6_ppgtt_pin(struct i915_ppgtt *base, struct i915_gem_ww_ctx *ww)
 {
 	struct gen6_ppgtt *ppgtt = to_gen6_ppgtt(base);
diff --git a/drivers/gpu/drm/i915/gt/gen6_ppgtt.h b/drivers/gpu/drm/i915/gt/gen6_ppgtt.h
index 6a61a5c3a85a..1f25c7a7329f 100644
--- a/drivers/gpu/drm/i915/gt/gen6_ppgtt.h
+++ b/drivers/gpu/drm/i915/gt/gen6_ppgtt.h
@@ -70,6 +70,7 @@ static inline struct gen6_ppgtt *to_gen6_ppgtt(struct i915_ppgtt *base)
 	     ++iter)
 
 int gen6_ppgtt_pin(struct i915_ppgtt *base, struct i915_gem_ww_ctx *ww);
+void __gen6_ppgtt_pin(struct i915_ppgtt *base);
 void gen6_ppgtt_unpin(struct i915_ppgtt *base);
 void gen6_ppgtt_unpin_all(struct i915_ppgtt *base);
 void gen6_ppgtt_enable(struct intel_gt *gt);
diff --git a/drivers/gpu/drm/i915/gt/intel_context.c b/drivers/gpu/drm/i915/gt/intel_context.c
index 4033184f13b9..156db93de426 100644
--- a/drivers/gpu/drm/i915/gt/intel_context.c
+++ b/drivers/gpu/drm/i915/gt/intel_context.c
@@ -203,7 +203,6 @@ static void intel_context_post_unpin(struct intel_context *ce)
 int __intel_context_do_pin_ww(struct intel_context *ce,
 			      struct i915_gem_ww_ctx *ww)
 {
-	bool handoff = false;
 	void *vaddr;
 	int err = 0;
 
@@ -261,7 +260,6 @@ int __intel_context_do_pin_ww(struct intel_context *ce,
 			 i915_ggtt_offset(ce->ring->vma),
 			 ce->ring->head, ce->ring->tail);
 
-		handoff = true;
 		smp_mb__before_atomic(); /* flush pin before it is visible */
 		atomic_inc(&ce->pin_count);
 	}
@@ -271,8 +269,7 @@ int __intel_context_do_pin_ww(struct intel_context *ce,
 err_unlock:
 	mutex_unlock(&ce->pin_mutex);
 err_post_unpin:
-	if (!handoff)
-		ce->ops->post_unpin(ce);
+	ce->ops->post_unpin(ce);
 err_release:
 	i915_active_release(&ce->active);
 err_ctx_unpin:
@@ -313,7 +310,6 @@ void intel_context_unpin(struct intel_context *ce)
 
 	CE_TRACE(ce, "unpin\n");
 	ce->ops->unpin(ce);
-	ce->ops->post_unpin(ce);
 
 	/*
 	 * Once released, we may asynchronously drop the active reference.
diff --git a/drivers/gpu/drm/i915/gt/intel_lrc.c b/drivers/gpu/drm/i915/gt/intel_lrc.c
index a27bac0a4bfb..74ea3bcee169 100644
--- a/drivers/gpu/drm/i915/gt/intel_lrc.c
+++ b/drivers/gpu/drm/i915/gt/intel_lrc.c
@@ -922,6 +922,8 @@ lrc_pin(struct intel_context *ce,
 		lrc_init_state(ce, engine, vaddr);
 
 	ce->lrc.lrca = lrc_update_regs(ce, engine, ce->ring->tail);
+
+	__i915_gem_object_pin_map(ce->state->obj);
 	return 0;
 }
 
@@ -929,6 +931,8 @@ void lrc_unpin(struct intel_context *ce)
 {
 	check_redzone((void *)ce->lrc_reg_state - LRC_STATE_OFFSET,
 		      ce->engine);
+
+	i915_gem_object_unpin_map(ce->state->obj);
 }
 
 void lrc_post_unpin(struct intel_context *ce)
diff --git a/drivers/gpu/drm/i915/gt/intel_ring_submission.c b/drivers/gpu/drm/i915/gt/intel_ring_submission.c
index 5d42a12ef3d6..8b1942942986 100644
--- a/drivers/gpu/drm/i915/gt/intel_ring_submission.c
+++ b/drivers/gpu/drm/i915/gt/intel_ring_submission.c
@@ -499,6 +499,7 @@ static void __context_unpin_ppgtt(struct intel_context *ce)
 
 static void ring_context_unpin(struct intel_context *ce)
 {
+	__context_unpin_ppgtt(ce);
 }
 
 static void ring_context_post_unpin(struct intel_context *ce)
@@ -574,6 +575,12 @@ static int ring_context_alloc(struct intel_context *ce)
 
 static int ring_context_pin(struct intel_context *ce, void *unused)
 {
+	struct i915_address_space *vm;
+
+	vm = vm_alias(ce->vm);
+	if (vm)
+		__gen6_ppgtt_pin(i915_vm_to_ppgtt((vm)));
+
 	return 0;
 }
 
-- 
2.31.0



More information about the Intel-gfx-trybot mailing list