Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp784986imm; Wed, 10 Oct 2018 04:23:16 -0700 (PDT) X-Google-Smtp-Source: ACcGV62YcuK2sPQTJLhyGg0a0Tf7lGL/ljkErkE0Yg7pV5pVkRc1XuNFgfSWRjWT7JtWudFagxPI X-Received: by 2002:a17:902:33c3:: with SMTP id b61-v6mr30087525plc.52.1539170596008; Wed, 10 Oct 2018 04:23:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539170595; cv=none; d=google.com; s=arc-20160816; b=SfaETEeTZjOoFbSLX1NRxpAF8AxDX8FTua7Tos3Q8sG+xD90GmjrdPbv4oCe0pdkRY kAsAHmnSB2l7Lqdeo7F1fhdCFsMtcV6WDnpAjBabvhOsKMU6+zWkp+ToSl+DrhJQJxr3 DKyoFW34RjCLH5/wJy9ebNwvZICL+t6JjgIAYcf3OQ3GNAD7KXLbVIZQGQ/n3d9697I5 Qis+PlzK59xZX9VYe7mjUJYiNZflb2qiJdtZccsFzg7krvqxgBBW3Jw26LsM3ZkqiiyA qn1fjrG039hPq1p3BlfgqMBpJF3qluc/nGTFOVF6ChtLwtwkKeWl7u4ksXHjrleI2uPM fhlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=dObbFQZGyXzlMbr1j4fSYsXXVzEUnB0sOQd04tUNgqo=; b=qplfsYrsObdAJMGwqGsv0jzuNqiqb9AHFPnnaRptSISwKYWP7za5VWQqxTlhPYsymz AIsgYC4kQP0+AySaBHOW+kN8OGCa8gh0ic4pGINbip+yeYfvJoPyVNfFT5I+fGy+wxMD o0aBL1nsS8aDVsguwXjRlDLS8irlJ5+AZU1pVkUas80fmoHrwQV7YBymr0fo7IXjJeZT RSdcviyMbXxp4sP10pTlCDMz0S6Zr0dHIxVuSyzAda1hYhXup0K9eczrVlz5zJkXEQSj xQ7WuqgPxYLBdEk3ROqhFe96jP5ZkUmpYDwbIxUV+bon6nmh5/tu+veAL8MOU1BVCGMF OmoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@armlinux.org.uk header.s=pandora-2014 header.b="RPl/HDsV"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p126-v6si10874025pfp.234.2018.10.10.04.23.00; Wed, 10 Oct 2018 04:23:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@armlinux.org.uk header.s=pandora-2014 header.b="RPl/HDsV"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726786AbeJJSoG (ORCPT + 99 others); Wed, 10 Oct 2018 14:44:06 -0400 Received: from pandora.armlinux.org.uk ([78.32.30.218]:47046 "EHLO pandora.armlinux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726468AbeJJSoG (ORCPT ); Wed, 10 Oct 2018 14:44:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2014; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=dObbFQZGyXzlMbr1j4fSYsXXVzEUnB0sOQd04tUNgqo=; b=RPl/HDsVX0HPAkWr1phrarQFu jSQSHJGWcswygngA76vjNW23ArKTgo+a7uJs88JteuvED3sDe+CgHZuFP4vSag8dN8tKSJmF6mwf2 xekN/7Whqm20LHZMl5HyCNase5P0Q6caA21mYT6UmGIp/zzY267VcS5GrmsqokfjAlMZg=; Received: from n2100.armlinux.org.uk ([fd8f:7570:feb6:1:214:fdff:fe10:4f86]:40686) by pandora.armlinux.org.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.90_1) (envelope-from ) id 1gACZB-0006OF-Lb; Wed, 10 Oct 2018 12:22:13 +0100 Received: from linux by n2100.armlinux.org.uk with local (Exim 4.90_1) (envelope-from ) id 1gACZ4-0001B8-GC; Wed, 10 Oct 2018 12:22:06 +0100 Date: Wed, 10 Oct 2018 12:22:01 +0100 From: Russell King - ARM Linux To: Stefan Agner Cc: Lucas Stach , p.zabel@pengutronix.de, airlied@linux.ie, gregkh@linuxfoundation.org, rafael@kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/2] drm/imx: make sure to cleanup DRM before unbinding components Message-ID: <20181010112201.GO30658@n2100.armlinux.org.uk> References: <83a28282a3f745a4cd4ca77d0593ad2e61359a5d.1539120077.git.stefan@agner.ch> <20181010103829.GN30658@n2100.armlinux.org.uk> <11a452de8e6b39c80ae8ff6b2cdc4cc8@agner.ch> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <11a452de8e6b39c80ae8ff6b2cdc4cc8@agner.ch> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 10, 2018 at 01:02:16PM +0200, Stefan Agner wrote: > [adding Lucas] > > On 10.10.2018 12:38, Russell King - ARM Linux wrote: > > On Tue, Oct 09, 2018 at 11:30:49PM +0200, Stefan Agner wrote: > >> In situations where a component fails to bind, a previously > >> successfully bound component might already registered itself > >> with the DRM framework (e.g. an encoder). When the master > >> component then calls drm_mode_config_cleanup, we end up in a > >> use after free sitution. > >> > >> Use the cleanup callback to make sure all framework level > >> cleanup is done by the time we unbind components. > > > > I'm not sure about this approach - the idea about the component bind > > and unbind callbacks is that unbind undoes _everything_ that bind has > > done, so everything is correctly ordered. If bind registers something, > > unbind should unregister it. > > > > What seems to be going on is that imx is registering stuff in bind() > > but not unregistering it in unbind(). > > Yes indeed, if that can be fixed this seems to be the better approach to > me. > > > > > Since imx was one of the drivers that the component helper was > > created for, if it's now crashing, that's a regression in the imx > > driver. Looking at the commit log, I'd say: > > > > commit 8e3b16e2117409625b89807de3912ff773aea354 > > Author: Lucas Stach > > Date: Thu Aug 11 11:18:49 2016 +0200 > > > > drm/imx: don't destroy mode objects manually on driver unbind > > > > Instead let drm_mode_config_cleanup() do the work when taking down > > the master device. This requires all cleanup functions to be > > properly hooked up to the mode object .destroy callback. > > > > Signed-off-by: Lucas Stach > > Signed-off-by: Philipp Zabel > > > > is probably responsible for introducing this problem, since the > > explicit calls were added by me when imx was stuck in staging due to > > the problems that the component helper solved. > > The commit above does not revert cleanly today, but a quick fixing > seemed to resolve the problem I am seeing... > > > > > I think what we have here are different opinions on how cleanup > > should be handled. > > In the regular case using the framework cleanup function before calling > component_unbind_all() works fine. > > Its really only the case where a subcomponent fails to bind where unbind > happens before calling drm_mode_config_cleanup(drm). I guess Lucas was > not aware of that special case...? As long as ->unbind undoes everything that ->bind does, it's not a problem. WRT using devres groups in one of your previous mails on this topic, consider what would happen if you use devm_* APIs in the bind callback and the component helper did not use devres groups. Any resources taken in the bind callback would not be freed until the device was unbound from the driver by the driver model. This means each time the bind callback gets called, new sets of resources are attempted to be acquired. If some resources are exclusive, the first bind attempt would succeed, but the second attempt would fail with -EBUSY for example. In the case of memory, the allocated memory would not be freed, but new memory would be allocated each time a bind was attempted. The alternative would be that devres must not be used at all in the bind/unbind callbacks - but then we'll be subject to the same error- prone cleanup that we see with driver probe functions prior to devres. Consider what the LDB bind/unbind callbacks would look like if devres was not permitted, and how the memory for the imx_ldb structure would be managed - you'd need some sort of ref-counting on the imx_ldb structure, and management of that in the encoder and optional connector destroy functions so you know when all embedded encoders and connectors in that structure have been "destroyed" by drm_mode_config_cleanup(), and hence it's safe to free the data structure. -- RMK's Patch system: http://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up According to speedtest.net: 11.9Mbps down 500kbps up