From: Chris Wilson Subject: Re: [PATCH] drm/i915: fix reference counting in i915_gem_create Date: Wed, 24 Jul 2013 15:36:40 +0100 Message-ID: <20130724143640.GA882@cantiga.alporthouse.com> References: <1374663659-3073-1-git-send-email-daniel.vetter@ffwll.ch> <1374667340-7786-1-git-send-email-daniel.vetter@ffwll.ch> <20130724133041.GJ3299@cantiga.alporthouse.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from fireflyinternet.com (s16502780.onlinehome-server.info [87.106.93.118]) by gabe.freedesktop.org (Postfix) with ESMTP id 3465AE6AF0 for ; Wed, 24 Jul 2013 07:36:46 -0700 (PDT) Content-Disposition: inline In-Reply-To: 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: Daniel Vetter Cc: Intel Graphics Development List-Id: intel-gfx@lists.freedesktop.org On Wed, Jul 24, 2013 at 03:48:28PM +0200, Daniel Vetter wrote: > On Wed, Jul 24, 2013 at 3:30 PM, Chris Wilson wrote: > > On Wed, Jul 24, 2013 at 02:02:20PM +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. > >> > >> v2: We need to make the trace call _before_ we drop our ref - the > >> object might very well be gone by then already. > > > > Pass the size into the tracepoint, that gets rid of the racy read (the > > actual userspace side we've allowed ourselves to be racy before). And > > keeps the function clean, if you rewrite it like I suggested. > > Well I honestly don't really see the upshot of the little diff you've > pasted on irc. The bug is that we call the wrong unreference function > and that we access the object after we've dropped the reference. Ignoring the typo, it is much neater code. The code that was there before my hack. -Chris -- Chris Wilson, Intel Open Source Technology Centre