From: Daniel Vetter Subject: Re: Possible fb ref count issue with drm_plane_force_disable() Date: Fri, 11 Apr 2014 09:19:56 +0200 Message-ID: <20140411071956.GT9262@phenom.ffwll.local> References: <534684E8.9000203@ti.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail-ee0-f51.google.com (mail-ee0-f51.google.com [74.125.83.51]) by gabe.freedesktop.org (Postfix) with ESMTP id C75EB6E351 for ; Fri, 11 Apr 2014 00:19:59 -0700 (PDT) Received: by mail-ee0-f51.google.com with SMTP id c13so3804387eek.10 for ; Fri, 11 Apr 2014 00:19:58 -0700 (PDT) Content-Disposition: inline In-Reply-To: <534684E8.9000203@ti.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" To: Tomi Valkeinen Cc: dri-devel List-Id: dri-devel@lists.freedesktop.org On Thu, Apr 10, 2014 at 02:47:52PM +0300, Tomi Valkeinen wrote: > Hi, > > I've been debugging omapdrm issues on top of the latest drm mainline > changes. Sometimes a drm_framebuffer ref count drops to -1 when aborting > a drm application, or unloading the modules. > > The setup is very basic, just a single crtc with the crtc's primary plane. > > What seems to happen is: > > - App is started > > - fb is created, and taken into use by omapdrm. omapdrm takes a ref to > the fb. > > - the app is starts to shut down > > - drm_framebuffer_remove is called > > - fb->refcount.refcount > 1, so it goes to disable stuff > > - drm_plane_force_disable is called for the primary plane > > - drm_plane_force_disable does plane->disable_plane, which on omapdrm > puts stuff on a workqueue as plane cannot be disabled immediately > > - drm_plane_force_disable calls __drm_framebuffer_unreference() > > - at the end of drm_framebuffer_remove(), there's > drm_framebuffer_unreference, which causes ref count to go to zero, and > the fb to be destroyed > > - a bit later, the queued work is ran, which does > drm_framebuffer_unreference(), and ref count goes to -1. Here omapdrm is > removing the ref that had been taken in the beginning. > > > So the explicit unref done by drm_plane_force_disable() seems a bit out > of place. I can't figure out which drm_framebuffer_reference() would be > the matching one for the unref done by drm_plane_force_disable(). > > Any ideas what ref is that? Or is the __drm_framebuffer_unreference() > extra in drm_plane_force_disable()? plane->fb is holding a reference which should have been acquired in drm_mode_setplane. It's not really explicit since drm_framebuffer_lookup implicitly grabs a ref for you. Hence when we disable the plane and set plane->fb = NULL we must drop that ref again. So that's not the bug, but clearly something goes wrong somewhere. -Daniel -- Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch