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

Janusz Krzysztofik janusz.krzysztofik at linux.intel.com
Mon May 6 08:55:05 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 | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c
index 83885bcad8b4..21b6e746df69 100644
--- a/drivers/gpu/drm/i915/i915_gem_context.c
+++ b/drivers/gpu/drm/i915/i915_gem_context.c
@@ -285,11 +285,8 @@ static struct i915_gem_engines *default_engines(struct i915_gem_context *ctx)
 	return e;
 }
 
-static void i915_gem_context_free(struct i915_gem_context *ctx)
+static void cleanup_context(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);
 
@@ -298,6 +295,14 @@ static void i915_gem_context_free(struct i915_gem_context *ctx)
 
 	if (ctx->timeline)
 		i915_timeline_put(ctx->timeline);
+}
+
+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));
+
+	cleanup_context(ctx);
 
 	kfree(ctx->name);
 	put_pid(ctx->pid);
@@ -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);
 		}
 	}
 
-- 
2.20.1



More information about the Intel-gfx-trybot mailing list