From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.1 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82714C2D0F3 for ; Thu, 2 Apr 2020 00:50:25 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 564822072E for ; Thu, 2 Apr 2020 00:50:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="nYg9liIM" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 564822072E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EABA36E9BF; Thu, 2 Apr 2020 00:50:21 +0000 (UTC) Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by gabe.freedesktop.org (Postfix) with ESMTPS id 33C446E0F9; Thu, 2 Apr 2020 00:50:20 +0000 (UTC) Received: from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id A1C5B80E; Thu, 2 Apr 2020 02:50:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1585788616; bh=f+N86Qmo9hTitSTIr/mHRqjAQ+qSTEk0QtizQ5ODC5Y=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=nYg9liIMzNGgt/Hi4+F0ZKbhw8S06QN0nyrnFtSaeGK00Fu1ImppUW1qrYTaT26Za KwSQyc8hFAm1sRE6LDgIgzYxtTwknCijAtXpUAAEyQhWgKwq+KwGNl/nzLIFHRSPXz lY3NwkwW3GYJGXOUP+r4dwQV0MvOpcwPEznDfwok= Date: Thu, 2 Apr 2020 03:50:08 +0300 From: Laurent Pinchart To: Daniel Vetter Subject: Re: [PATCH 19/51] drm: Cleanups after drmm_add_final_kfree rollout Message-ID: <20200402005008.GA18964@pendragon.ideasonboard.com> References: <20200323144950.3018436-1-daniel.vetter@ffwll.ch> <20200323144950.3018436-20-daniel.vetter@ffwll.ch> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200323144950.3018436-20-daniel.vetter@ffwll.ch> User-Agent: Mutt/1.10.1 (2018-07-13) X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Intel Graphics Development , DRI Development , Thomas Zimmermann , Daniel Vetter , Sam Ravnborg , Dan Carpenter Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Hi Daniel, (On a side note, git-format-patch accepts a -v argument to specify the version, I didn't realize you were not aware of it :-)) On Mon, Mar 23, 2020 at 03:49:18PM +0100, Daniel Vetter wrote: > A few things: > - Update the example driver in the documentation. > - We can drop the old kfree in drm_dev_release. > - Add a WARN_ON check in drm_dev_register to make sure everyone calls > drmm_add_final_kfree and there's no leaks. > > v2: Restore the full cleanup, I accidentally left some moved code > behind when fixing the bisectability of the series. > > Acked-by: Sam Ravnborg > Acked-by: Thomas Zimmermann > Cc: Sam Ravnborg > Cc: Dan Carpenter > Signed-off-by: Daniel Vetter > --- > drivers/gpu/drm/drm_drv.c | 12 +++++------- > 1 file changed, 5 insertions(+), 7 deletions(-) > > diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c > index 877ded348b6e..7f9d7ea543a0 100644 > --- a/drivers/gpu/drm/drm_drv.c > +++ b/drivers/gpu/drm/drm_drv.c > @@ -297,8 +297,6 @@ void drm_minor_release(struct drm_minor *minor) > * > * drm_mode_config_cleanup(drm); > * drm_dev_fini(drm); > - * kfree(priv->userspace_facing); > - * kfree(priv); > * } > * > * static struct drm_driver driver_drm_driver = { > @@ -326,10 +324,11 @@ void drm_minor_release(struct drm_minor *minor) > * kfree(drm); > * return ret; > * } > + * drmm_add_final_kfree(drm, priv); > * > * drm_mode_config_init(drm); > * > - * priv->userspace_facing = kzalloc(..., GFP_KERNEL); > + * priv->userspace_facing = drmm_kzalloc(..., GFP_KERNEL); > * if (!priv->userspace_facing) > * return -ENOMEM; > * > @@ -837,10 +836,7 @@ static void drm_dev_release(struct kref *ref) > > drm_managed_release(dev); > > - if (!dev->driver->release && !dev->managed.final_kfree) { > - WARN_ON(!list_empty(&dev->managed.resources)); > - kfree(dev); > - } else if (dev->managed.final_kfree) > + if (dev->managed.final_kfree) > kfree(dev->managed.final_kfree); > } > > @@ -961,6 +957,8 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags) > if (!driver->load) > drm_mode_config_validate(dev); > > + WARN_ON(!dev->managed.final_kfree); That's too aggressive. Driver freeing their private object in .release() isn't wrong. I'd even go as far as saying that it should be the norm, until we manage to find a better way to handle that (which this series doesn't achieve). Many drivers need to allocate resources at probe time before they get a chance to init the drm device. Those resources must be released in the error handling paths of probe. By requiring drmm_add_final_kfree(), you're making that much more complex. I can't release those resources in the error path anymore after calling drmm_add_final_kfree(), or they will be released twice. And I can't rely on drmm_* to release them in all cases, as the error path may be hit before touching anything drm-related. Until we figure out a good way forward and test it on a significant number of drivers, let's not add WARN_ON() that will be hit with the majority of drivers, forcing them to be converted to something that is clearly half-baked. > + > if (drm_dev_needs_global_mutex(dev)) > mutex_lock(&drm_global_mutex); > -- Regards, Laurent Pinchart _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel