From mboxrd@z Thu Jan 1 00:00:00 1970 From: Daniel Vetter Subject: Re: dma-buf and ->dev refcount fun Date: Tue, 25 Mar 2014 11:59:01 +0100 Message-ID: <20140325105901.GZ26878@phenom.ffwll.local> References: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail-ee0-f44.google.com (mail-ee0-f44.google.com [74.125.83.44]) by gabe.freedesktop.org (Postfix) with ESMTP id 14AC46E16C for ; Tue, 25 Mar 2014 03:59:05 -0700 (PDT) Received: by mail-ee0-f44.google.com with SMTP id e49so284608eek.17 for ; Tue, 25 Mar 2014 03:59:05 -0700 (PDT) Content-Disposition: inline In-Reply-To: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" To: David Herrmann Cc: USB list , dri-devel List-Id: dri-devel@lists.freedesktop.org On Tue, Mar 25, 2014 at 10:40:45AM +0100, David Herrmann wrote: > Hi > > On Tue, Mar 25, 2014 at 9:01 AM, Daniel Vetter wrote: > > Besides the issue at hand though I think drivers need to make sure > > that the device they use for attaching does outlive the dma-buf. Which > > for real hotpluggin probably means that drivers need to drop all > > attachment on unplug (the dma mapping is useless anyway) and just keep > > all their imported gem objects alive with just a reference to the > > dma-buf object itself. > > Drivers should never touch other drivers or even look at them. There > is no reason i915 is responsible of keeping udl alive. That gets > really messy and may introduce circular dependencies. > > I'd like to see exported dma-bufs reference their drm-device owner. > This way, the drm-device stays around until the dma-buf is removed. To > avoid lazy device destruction, a driver can (during unplug) simply > detach all dma-bufs if, and only if, they first made the dma-buf > somehow stand-alone. > > For example: udl can just move the allocated pages into the dma-buf, > mark it as dead and detach it. The udl-device can get destructed and > whenever i915 releases the dma-buf, the udl-dma-buf ops see it's dead > and just deref it / release dma-buf resources. But this is all not > needed if the exported dma-bufs just reference "drm_device", which is > imho the easiest fix. The issue at hand is the other way round, i.e. i915 exporting, udl importing. The i915/dma-buf falls over because the device struct referenced in the attachment disappeared. Dave fixed it by grabbing a reference, I think the better fix would be to simply not attach (since udl doesn't need it anyway). Either works. -Daniel -- Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch