Skip to content

Commit 0315366

Browse files
danvetjnikula
authored andcommitted
drm/i915: Release ctx->syncobj on final put, not on ctx close
gem context refcounting is another exercise in least locking design it seems, where most things get destroyed upon context closure (which can race with anything really). Only the actual memory allocation and the locks survive while holding a reference. This tripped up Jason when reimplementing the single timeline feature in commit 00dae4d Author: Jason Ekstrand <[email protected]> Date: Thu Jul 8 10:48:12 2021 -0500 drm/i915: Implement SINGLE_TIMELINE with a syncobj (v4) We could fix the bug by holding ctx->mutex in execbuf and clear the pointer (again while holding the mutex) context_close, but it's cleaner to just make the context object actually invariant over its _entire_ lifetime. This way any other ioctl that's potentially racing, but holding a full reference, can still rely on ctx->syncobj being an immutable pointer. Which without this change, is not the case. Reviewed-by: Maarten Lankhorst <[email protected]> Signed-off-by: Daniel Vetter <[email protected]> Fixes: 00dae4d ("drm/i915: Implement SINGLE_TIMELINE with a syncobj (v4)") Cc: Jason Ekstrand <[email protected]> Cc: Chris Wilson <[email protected]> Cc: Tvrtko Ursulin <[email protected]> Cc: Joonas Lahtinen <[email protected]> Cc: Matthew Brost <[email protected]> Cc: Matthew Auld <[email protected]> Cc: Maarten Lankhorst <[email protected]> Cc: "Thomas Hellström" <[email protected]> Cc: Lionel Landwerlin <[email protected]> Cc: Dave Airlie <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] (cherry picked from commit c238980) Signed-off-by: Jani Nikula <[email protected]>
1 parent 04a3ab6 commit 0315366

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/gpu/drm/i915/gem/i915_gem_context.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,9 @@ void i915_gem_context_release(struct kref *ref)
986986
trace_i915_context_free(ctx);
987987
GEM_BUG_ON(!i915_gem_context_is_closed(ctx));
988988

989+
if (ctx->syncobj)
990+
drm_syncobj_put(ctx->syncobj);
991+
989992
mutex_destroy(&ctx->engines_mutex);
990993
mutex_destroy(&ctx->lut_mutex);
991994

@@ -1205,9 +1208,6 @@ static void context_close(struct i915_gem_context *ctx)
12051208
if (vm)
12061209
i915_vm_close(vm);
12071210

1208-
if (ctx->syncobj)
1209-
drm_syncobj_put(ctx->syncobj);
1210-
12111211
ctx->file_priv = ERR_PTR(-EBADF);
12121212

12131213
/*

0 commit comments

Comments
 (0)