[PATCH 2/2] drm/i915: Fix free cachelines not released on driver hot unbind

Janusz Krzysztofik janusz.krzysztofik at linux.intel.com
Tue May 7 12:39:27 UTC 2019


If there are active users of a device during driver unbind, the driver
now panics on non-empty list of free cachelines.

By design, cachelines which are not in use by active execlists are kept
on a list of free cachelines associated with a timeline and removed
from that list either when in use or when the timeline is destroyed.
Timelines in turn are assigned to contexts which may be associtated
with open file descriptors.

Desired behavior is to clean up active contexts first, unpinning the
contexts and resources, and so letting the timeline be freed, and the
panic is there to say that i915_timelines_fini() is called to early.
However, as long as user access to device resources is protected after
drm_dev_unplug() has been called, it should be safe to free contexts
and their associated resources earlier, without waiting for users to
close their open device file descriptors.

Fix it by releasing execlists and associated context resources from
i915_gem_contexts_fini() on driver hot unbind in addition to releasing
context HW IDs.  Since a sequence of required operations is already
called from i915_gem_context_free() which can't be used at that point
as the context is still open, move that sequence to a separate helper
function.

Signed-off-by: Janusz Krzysztofik <janusz.krzysztofik at linux.intel.com>
---
 drivers/gpu/drm/i915/i915_gem_context.c | 11 ++++++++---
 drivers/gpu/drm/i915/i915_timeline.c    |  2 +-
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c
index 8845eb10a778..0523c965ca35 100644
--- a/drivers/gpu/drm/i915/i915_gem_context.c
+++ b/drivers/gpu/drm/i915/i915_gem_context.c
@@ -285,13 +285,18 @@ static struct i915_gem_engines *default_engines(struct i915_gem_context *ctx)
 	return e;
 }
 
+static void cleanup_context(struct i915_gem_context *ctx)
+{
+	release_hw_id(ctx);
+	i915_ppgtt_put(ctx->ppgtt);
+}
+
 static void i915_gem_context_free(struct i915_gem_context *ctx)
 {
 	lockdep_assert_held(&ctx->i915->drm.struct_mutex);
 	GEM_BUG_ON(!i915_gem_context_is_closed(ctx));
 
-	release_hw_id(ctx);
-	i915_ppgtt_put(ctx->ppgtt);
+	cleanup_context(ctx);
 
 	free_engines(rcu_access_pointer(ctx->engines));
 	mutex_destroy(&ctx->engines_mutex);
@@ -702,7 +707,7 @@ void i915_gem_contexts_fini(struct drm_i915_private *i915)
 		list_for_each_entry_safe(ctx, cn, &i915->contexts.hw_id_list,
 					 hw_id_link) {
 			GEM_BUG_ON(atomic_read(&ctx->hw_id_pin_count));
-			release_hw_id(ctx);
+			cleanup_context(ctx);
 		}
 	}
 
diff --git a/drivers/gpu/drm/i915/i915_timeline.c b/drivers/gpu/drm/i915/i915_timeline.c
index 5fbea0892f33..3a6c5c15d445 100644
--- a/drivers/gpu/drm/i915/i915_timeline.c
+++ b/drivers/gpu/drm/i915/i915_timeline.c
@@ -568,7 +568,7 @@ void i915_timelines_fini(struct drm_i915_private *i915)
 	struct i915_gt_timelines *gt = &i915->gt.timelines;
 
 	GEM_BUG_ON(!list_empty(&gt->active_list));
-	GEM_BUG_ON(!list_empty(&gt->hwsp_free_list));
+	GEM_WARN_ON(!list_empty(&gt->hwsp_free_list));
 
 	mutex_destroy(&gt->mutex);
 }
-- 
2.20.1



More information about the Intel-gfx-trybot mailing list