diff mbox

[v2] drm/i915: unreference default context on module unload

Message ID 1367587748-643-1-git-send-email-mika.kuoppala@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Mika Kuoppala May 3, 2013, 1:29 p.m. UTC
Before module unload is called, gpu_idle() will switch
to default context. This will increment ref count of base
object as the default context is 'running' on module unload
time. Unreference the drm object so that when context
is freed, base object is freed as well.

v2: added comment to explain the refcounts (Ben Widawsky)

Signed-off-by: Mika Kuoppala <mika.kuoppala@intel.com>
---
 drivers/gpu/drm/i915/i915_gem_context.c |    8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Ben Widawsky May 3, 2013, 3:53 p.m. UTC | #1
On Fri, May 03, 2013 at 04:29:08PM +0300, Mika Kuoppala wrote:
> Before module unload is called, gpu_idle() will switch
> to default context. This will increment ref count of base
> object as the default context is 'running' on module unload
> time. Unreference the drm object so that when context
> is freed, base object is freed as well.
> 
> v2: added comment to explain the refcounts (Ben Widawsky)
> 
> Signed-off-by: Mika Kuoppala <mika.kuoppala@intel.com>

I left an r-b on the other patch. You should feel free to add it if you
actually do what I say.

Reviewed-by: Ben Widawsky <ben@bwidawsk.net>
[snip]
Daniel Vetter May 3, 2013, 4:22 p.m. UTC | #2
On Fri, May 03, 2013 at 08:53:20AM -0700, Ben Widawsky wrote:
> On Fri, May 03, 2013 at 04:29:08PM +0300, Mika Kuoppala wrote:
> > Before module unload is called, gpu_idle() will switch
> > to default context. This will increment ref count of base
> > object as the default context is 'running' on module unload
> > time. Unreference the drm object so that when context
> > is freed, base object is freed as well.
> > 
> > v2: added comment to explain the refcounts (Ben Widawsky)
> > 
> > Signed-off-by: Mika Kuoppala <mika.kuoppala@intel.com>
> 
> I left an r-b on the other patch. You should feel free to add it if you
> actually do what I say.
> 
> Reviewed-by: Ben Widawsky <ben@bwidawsk.net>

Merged, thanks.
-Daniel
diff mbox

Patch

diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c
index 9e8c685..280617e 100644
--- a/drivers/gpu/drm/i915/i915_gem_context.c
+++ b/drivers/gpu/drm/i915/i915_gem_context.c
@@ -274,6 +274,14 @@  void i915_gem_context_fini(struct drm_device *dev)
 	intel_gpu_reset(dev);
 
 	i915_gem_object_unpin(dctx->obj);
+
+	/* When default context is created and switched to, base object refcount
+	 * will be 2 (+1 from object creation and +1 from do_switch()).
+	 * i915_gem_context_fini() will be called after gpu_idle() has switched
+	 * to default context. So we need to unreference the base object once
+	 * to offset the do_switch part, so that i915_gem_context_unreference()
+	 * can then free the base object correctly. */
+	drm_gem_object_unreference(&dctx->obj->base);
 	i915_gem_context_unreference(dctx);
 }