Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751950AbdHGVyq (ORCPT ); Mon, 7 Aug 2017 17:54:46 -0400 Received: from galahad.ideasonboard.com ([185.26.127.97]:42743 "EHLO galahad.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751662AbdHGVyp (ORCPT ); Mon, 7 Aug 2017 17:54:45 -0400 From: Laurent Pinchart To: Daniel Vetter Cc: Greg Kroah-Hartman , Noralf =?ISO-8859-1?Q?Tr=F8nnes?= , Ilia Mirkin , Eric Anholt , Daniel Vetter , Thierry Reding , "linux-kernel@vger.kernel.org" , "dri-devel@lists.freedesktop.org" Subject: Re: [PATCH v5 2/6] drm/bridge: Add a devm_ allocator for panel bridge. Date: Tue, 08 Aug 2017 00:54:59 +0300 Message-ID: <1623957.7egAK3pKHU@avalon> User-Agent: KMail/4.14.10 (Linux/4.9.34-gentoo; KDE/4.14.32; x86_64; ; ) In-Reply-To: <20170807145939.bx23xyejkcfp76ze@phenom.ffwll.local> References: <20170718210510.12229-1-eric@anholt.net> <30057693.2anM9zYF0F@avalon> <20170807145939.bx23xyejkcfp76ze@phenom.ffwll.local> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by nfs id v77Lsqno008037 Content-Length: 4742 Lines: 99 Hi Daniel, On Monday 07 Aug 2017 16:59:39 Daniel Vetter wrote: > On Mon, Aug 07, 2017 at 01:22:23PM +0300, Laurent Pinchart wrote: > > On Monday 07 Aug 2017 11:25:07 Daniel Vetter wrote: > >> On Sat, Aug 05, 2017 at 12:59:07PM +0200, Noralf Tr?nnes wrote: > >>> Den 05.08.2017 00.19, skrev Ilia Mirkin: > >>>> On Fri, Aug 4, 2017 at 4:43 PM, Eric Anholt wrote: > >>>>> Laurent Pinchart writes: > >>>>>> On Tuesday 18 Jul 2017 14:05:06 Eric Anholt wrote: > >>>>>>> This will let drivers reduce the error cleanup they need, in > >>>>>>> particular the "is_panel_bridge" flag. > >>>>>>> > >>>>>>> v2: Slight cleanup of remove function by Andrzej > >>>>>> > >>>>>> I just want to point out that, in the context of Daniel's work on > >>>>>> hot-unplug, 90% of the devm_* allocations are wrong and will get in > >>>>>> the way. All DRM core objects that are accessible one way or > >>>>>> another from userspace will need to be properly reference-counted > >>>>>> and freed only when the last reference disappears, which could be > >>>>>> well after the corresponding device is removed. I believe this > >>>>>> could be one such objects :-/ > >>>>> > >>>>> Sure, if you're hotplugging, your life is pain. For > >>>>> non-hotpluggable devices, like our SOC platform devices (current > >>>>> panel-bridge consumers), this still seems like an excellent > >>>>> simplification of memory management. > >>>> > >>>> At that point you may as well make your module non-unloadable, and > >>>> return failure when trying to remove a device from management by the > >>>> driver (whatever the opposite of "probe" is, I forget). Hotplugging > >>>> doesn't only happen when physically removing, it can happen for all > >>>> kinds of reasons... and userspace may still hold references in some > >>>> of those cases. > >>> > >>> If drm_open() gets a ref on dev->dev and puts it in drm_release(), > >>> won't that delay devm_* cleanup until userspace is done? > >> > >> No. drm_device is the thing that is refcounted for userspace references > >> like open FD (we're not perfect about it, e.g. sysfs and dma-buf/fence > >> don't). > >> > >> devm_ otoh is tied to the lifetime of the underlying device, and that > >> one can get outlived by drm_device. Or at least afaiui, devm_ stuff is > >> nuked on unplug, and not when the final sw reference of the struct device > >> disappears. > >> > >> Not sure tough, it's complicated. > > > > It's complicated when you have to understand the behaviour by reading the > > code, but the behaviour isn't that complex. devm resources are released > > both > > > > 1. right after the driver's .remove() operation returns > > 2. when the device is deleted (last reference released) > > Right, I had vague memories when reading the code ... But iirc there's > also some way to delay cleanup until it's deleted, maybe we could exploit > that (and wrap it up into a drm_devm_add wrapper)? > > Plan B, but that is a lot more ugly, would be to create a fake struct > device that we never bind (hence remove can't be called) and use to track > the lifetime of drm_device stuff. Would avoid re-inventing all the devm_ > functions, but would also result in a dummy device in sysfs. If we wanted to go that way, we should decouple devm_* from struct device (or even struct kobject) and tie it to a new resource tracker structure. The current devm_* API would remain the same, embedding that resource tracker object in struct device, but we could also use the machinery with the resource tracker object directly. However, I'm not convince we should do so. We don't have any automatic memory allocation system for DRM objects (such as framebuffers or planes). Instead, drivers must implement a destroy operation for the object, and the core calls it when the last reference to the object goes away. This works fine, and I don't see what would prevent use from implementing the same mechanism for bridges or other similar structures. > Why is this stuff tied to struct device and not struct kobject anyway. Or > at least something we could embed in random cool place (like drm_device). > > Greg, any ideas how we could simplify management of stuff that's created > at driver load, but its lifetime tied to something which isn't directly a > struct device? > > > It's the first one that makes devm_* allocation unsuitable for any > > structure that is accessible from userspace (such as in file operation > > handlers). > > Yeah, if we could release at 2. it would be perfect I think ... It wouldn't, as unbind/rebind cycles would allocate new objects each time without freeing the previous ones until the device is deleted. -- Regards, Laurent Pinchart