[PATCH 06/17] drm/i915: Fix use-after-free of context during free_contexts

Chris Wilson chris at chris-wilson.co.uk
Fri Jun 30 23:11:08 UTC 2017

When iterating the list of contexts to free, we need to use a safe
iterator as we are freeing the link as we go. Pass an extra thick brown
paper bag.

Fixes: 5f09a9c8ab6b ("drm/i915: Allow contexts to be unreferenced locklessly")
Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
Cc: Joonas Lahtinen <joonas.lahtinen at linux.intel.com>
Cc: Tvrtko Ursulin <tvrtko.ursulin at intel.com>
Cc: Matthew Auld <matthew.auld at intel.com>
 drivers/gpu/drm/i915/i915_gem_context.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c
index 71d2ea7dab64..2eb5d8203999 100644
--- a/drivers/gpu/drm/i915/i915_gem_context.c
+++ b/drivers/gpu/drm/i915/i915_gem_context.c
@@ -193,11 +193,11 @@ static void i915_gem_context_free(struct i915_gem_context *ctx)
 static void contexts_free(struct drm_i915_private *i915)
 	struct llist_node *freed = llist_del_all(&i915->contexts.free_list);
-	struct i915_gem_context *ctx;
+	struct i915_gem_context *ctx, *cn;
-	llist_for_each_entry(ctx, freed, free_link)
+	llist_for_each_entry_safe(ctx, cn, freed, free_link)

More information about the Intel-gfx-trybot mailing list