From: Daniel Vetter Subject: Re: [PATCH 1/2] drm/i915: fix reference counting in i915_gem_create Date: Wed, 24 Jul 2013 23:25:39 +0200 Message-ID: <20130724212539.GA5939@phenom.ffwll.local> References: <1374673783-18900-1-git-send-email-daniel.vetter@ffwll.ch> <20130724170507.GB882@cantiga.alporthouse.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail-ee0-f47.google.com (mail-ee0-f47.google.com [74.125.83.47]) by gabe.freedesktop.org (Postfix) with ESMTP id B34BDE691D for ; Wed, 24 Jul 2013 14:25:41 -0700 (PDT) Received: by mail-ee0-f47.google.com with SMTP id e49so500178eek.20 for ; Wed, 24 Jul 2013 14:25:40 -0700 (PDT) Content-Disposition: inline In-Reply-To: <20130724170507.GB882@cantiga.alporthouse.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: intel-gfx-bounces+gcfxdi-intel-gfx=m.gmane.org@lists.freedesktop.org Errors-To: intel-gfx-bounces+gcfxdi-intel-gfx=m.gmane.org@lists.freedesktop.org To: Chris Wilson , Daniel Vetter , Intel Graphics Development List-Id: intel-gfx@lists.freedesktop.org On Wed, Jul 24, 2013 at 06:05:07PM +0100, Chris Wilson wrote: > On Wed, Jul 24, 2013 at 03:49:42PM +0200, Daniel Vetter wrote: > > This function is called without the dev->struct_mutex held, hence we > > need to use the _unlocked unreference variants. > > > > As soon as the object is registered userspace can sneak in here with a > > gem_close ioctl call, so the object can (and with my new evil tests > > actually does) get the final unreference in this place. The lack of > > locking then results in hilarity and some good leakage. > > > > To fix this we simply need to revert > > > > Chris Wilson > > > > v2: We need to make the trace call _before_ we drop our ref - the > > object might very well be gone by then already. > > > > v3: Just revert the original patch as suggested by Chris Wilson. > > > > Cc: Chris Wilson > > Signed-off-by: Daniel Vetter > > I'm sad to see this go, but we can fix any potential mutex contention > here by generically fixing _unlocked() - which is the better solution. > > Reviewed-by: Chris Wilson > > > --- > > drivers/gpu/drm/i915/i915_gem.c | 15 ++++++--------- > > 1 file changed, 6 insertions(+), 9 deletions(-) > > > > diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c > > index 957e65a..dc7e6de 100644 > > --- a/drivers/gpu/drm/i915/i915_gem.c > > +++ b/drivers/gpu/drm/i915/i915_gem.c > > @@ -219,18 +219,13 @@ i915_gem_create(struct drm_file *file, > > return -ENOMEM; > > > > ret = drm_gem_handle_create(file, &obj->base, &handle); > > - if (ret) { > > - drm_gem_object_release(&obj->base); > > - i915_gem_info_remove_obj(dev->dev_private, obj->base.size); > > - i915_gem_object_free(obj); > > - return ret; > > - } > > - > > /* drop reference from allocate - handle holds it now */ > > - drm_gem_object_unreference(&obj->base); > > - trace_i915_gem_object_create(obj); > > + drm_gem_object_unreference_unlocked(&obj->base); > > + if (ret) > > + return ret; > > > > *handle_p = handle; > > + > > return 0; > > However, I do like my return parameters clustered - any chance this > extra whitespace can be erradicated? Done and queued for -next, thanks for the review. -Daniel -- Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch