Signed-off-by: Ben Widawsky <ben at bwidawsk.net> --- drivers/gpu/drm/i915/i915_gem_context.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c index 8e218ad..5ac93f4 100644 --- a/drivers/gpu/drm/i915/i915_gem_context.c +++ b/drivers/gpu/drm/i915/i915_gem_context.c @@ -97,6 +97,11 @@ static int do_switch(struct i915_hw_context *to); +static inline bool is_default_context(struct i915_hw_context *ctx) +{ + return (ctx == ctx->ring->default_context); +} + static int get_context_size(struct drm_device *dev) { struct drm_i915_private *dev_priv = dev->dev_private; @@ -124,8 +129,10 @@ static int get_context_size(struct drm_device *dev) static void do_destroy(struct i915_hw_context *ctx) { - if (ctx->file_priv) + if (ctx->file_priv) { + WARN_ON(!is_default_context(ctx)); idr_remove(&ctx->file_priv->context_idr, ctx->id); + } drm_gem_object_unreference(&ctx->obj->base); kfree(ctx); @@ -177,11 +184,6 @@ err_out: return ERR_PTR(ret); } -static inline bool is_default_context(struct i915_hw_context *ctx) -{ - return (ctx == ctx->ring->default_context); -} - /** * The default context needs to exist per ring that uses contexts. It stores the * context state of the GPU for applications that don't utilize HW contexts, as @@ -213,7 +215,7 @@ static int create_default_context(struct drm_i915_private *dev_priv) if (ret) goto err_unpin; - DRM_DEBUG_DRIVER("Default HW context loaded\n"); + DRM_DEBUG_DRIVER("Default HW context loaded (%p)\n", ctx); return 0; err_unpin: @@ -275,6 +277,7 @@ static int context_idr_cleanup(int id, void *p, void *data) BUG_ON(id == DEFAULT_CONTEXT_ID); + DRM_DEBUG_DRIVER("Context %d closed before destroy.\n", ctx->id); do_destroy(ctx); return 0; @@ -453,8 +456,11 @@ int i915_switch_context(struct intel_ring_buffer *ring, return -EINVAL; to = i915_gem_context_get(ring, file->driver_priv, to_id); - if (to == NULL) + if (unlikely(!to)) { + BUG_ON(to_id == DEFAULT_CONTEXT_ID); + DRM_DEBUG_DRIVER("Couldn't find context %d\n", to_id); return -ENOENT; + } return do_switch(to); } @@ -517,6 +523,6 @@ int i915_gem_context_destroy_ioctl(struct drm_device *dev, void *data, mutex_unlock(&dev->struct_mutex); - DRM_DEBUG_DRIVER("HW context %d destroyed\n", args->ctx_id); + DRM_DEBUG_DRIVER("User destroyed context %d\n", args->ctx_id); return 0; } -- 1.8.2