Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp109916iof; Sun, 5 Jun 2022 22:40:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzkK7dzv+3L2xkEICYZ3ndNYSlblyazKWf5sgeUr9/NHg6s4kdquEYJx9krp7hYXsqcMzXM X-Received: by 2002:a63:f5e:0:b0:3fd:23e1:e086 with SMTP id 30-20020a630f5e000000b003fd23e1e086mr13790785pgp.61.1654494057115; Sun, 05 Jun 2022 22:40:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654494057; cv=none; d=google.com; s=arc-20160816; b=PetrTL9Fd1DCYZpSq+iO5WgefFwNJMRFkmjI9av+c7FW2DMhqG+bYoLU6mDLX8Y97N 7Y+Uszt8Ep9rs6ldPd13S6kBWwopP1tpGLyqTXnB3D8676eD0sW0vTUhtYHaFSplHQ82 GWRCl3arsOcwHXytqBn0oxTiPkk0DzOqrPaE0ffavyRWp1KTxTOViotg/d5dtF7NYwjn pIG8SyzlNDOzyzOxeAqB+d2PAZzUilqfN4iOsPviJvFXT1AkO/ODSl5D3SzJnIHscOFl thW6XRUBL41/ce77T1fC0JkJFObtJQKOlwYofcsnqbqViSQMrD50jmkmIIiquklhqWRq zKug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:feedback-id:dkim-signature:dkim-signature; bh=SUEjLwclojF3h4q4JNOjl27iBteEa2wqAi2mc0xoM04=; b=ZtKav2TfHGtrblMD3cYdOXxpxuwAXkX+4rTmtUxJwrztfrtD6/5cpGGuF6CXQWlc8R MA/b4EeKKKrKjeQd9Hnj05IUzjUCdINf2ooW27um2w/hFXuD1mxTPPuPRUN8Jqb7LsoN 2mYG/S8Jhzwu3KBcsySYoY41/NIw1dbX8SaOhBHDqtSjtCj44K2dx1X4HTxa++1JjL++ cdFyznf64LaiRWV1YQDipTYFaSixpIY9xtFJMTxUBTi+XVQDr/2n/YaYJWspL13uC5A4 39FOqG9tCmeUoTkNSCb7QjXUtbuZzheWYA1BQVNK6OXF2JWLmDub8W59nejs2bcdaeeT WQ9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (expired) header.i=@cerno.tech header.s=fm3; dkim=neutral (expired) header.i=@messagingengine.com header.s=fm1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cerno.tech Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id c6-20020a170902d48600b0015be178cbf4si12554809plg.188.2022.06.05.22.40.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jun 2022 22:40:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=neutral (expired) header.i=@cerno.tech header.s=fm3; dkim=neutral (expired) header.i=@messagingengine.com header.s=fm1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cerno.tech Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5B3766A056; Sun, 5 Jun 2022 21:47:35 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245067AbiFCOOT (ORCPT + 99 others); Fri, 3 Jun 2022 10:14:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244720AbiFCOOR (ORCPT ); Fri, 3 Jun 2022 10:14:17 -0400 Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30F5F3E5E2; Fri, 3 Jun 2022 07:14:13 -0700 (PDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id E5659320090E; Fri, 3 Jun 2022 10:14:10 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Fri, 03 Jun 2022 10:14:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cerno.tech; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm3; t=1654265650; x= 1654352050; bh=SUEjLwclojF3h4q4JNOjl27iBteEa2wqAi2mc0xoM04=; b=m 9xqqHlmTpZU6gtfdc8O1atMLX8zDzT+WurnmYtbGtbM8e0Nrw9py/LQ68mtDUTRy BCHkNgrN7PM8bTB2w2yH+sIQre1uLzej+qnbJVVeC2/dH8JZTHtlFzyzvy0o1ODR CsQPuNmPgGIjgXfkoJQYaYnY/AIeeCKKyOGF/e1zML1kOl6kXyNpuOlAqDBl1haS 1tcIfbfBW4S8e1kOzNERuSdyzOQTWsh3xxa+euUYkhVQ72uTy9XzyigtZ8YMz8a9 qI/cmZsKpeOmgNBfeNrZB8S6/TbiNQiE6mt79AROUJGimnwccP6TemS2iHEnokMW uYpeoZIauIkDXRrR3v/WA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1654265650; x= 1654352050; bh=SUEjLwclojF3h4q4JNOjl27iBteEa2wqAi2mc0xoM04=; b=F BVMNDbwa6QDDvFWWlkmo3Nzj1sBpgvrq8mhFwdJSXxfn1D4zMActSDNmlmnKs/Jb gNKg9L0BLGFAAHB7AM4kFgu2U27qDj7Mm6o3L/RRcLbt2084HO2mjSt532F7ByZC JHDjREjkxGXsmp1OhNNyQCRKzdassPz6jlAW5zjamubqSEKfC7TEWvDfPgEgxKgm cTTrO86d1FZu0aEPSnY+33Rkw5p7o2+uJxe2otd3BEnTLV/H23KMV/Es2eQS2eDt iQAa1dmRCD7AiNuXCbXIDqmSlqq5NUm9JYtZwqhQl/NINSoNAEaUG0wxlARCSmki dZHk+PU0/9Kjua7qvypjQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrleeigdejvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvvefukfhfgggtugfgjgesthhqredttddtvdenucfhrhhomhepofgrgihi mhgvucftihhprghrugcuoehmrgigihhmvgestggvrhhnohdrthgvtghhqeenucggtffrrg htthgvrhhnpeetgfelgefggeekkefggfeludeiudffjeffgeevveekjedukedtudeuteef teefgfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe hmrgigihhmvgestggvrhhnohdrthgvtghh X-ME-Proxy: Feedback-ID: i8771445c:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 3 Jun 2022 10:14:08 -0400 (EDT) Date: Fri, 3 Jun 2022 16:14:05 +0200 From: Maxime Ripard To: Dmitry Baryshkov Cc: Doug Anderson , dri-devel , Hsin-Yi Wang , Abhinav Kumar , Philip Chen , Sankeerth Billakanti , Robert Foss , freedreno , linux-arm-msm , Stephen Boyd , Daniel Vetter , David Airlie , Maarten Lankhorst , Thomas Zimmermann , LKML Subject: Re: [PATCH v3 3/4] drm/bridge: Add devm_drm_bridge_add() Message-ID: <20220603141405.dybjn3blifau6662@penduick> References: <20220510192944.2408515-1-dianders@chromium.org> <20220510122726.v3.3.Iba4b9bf6c7a1ee5ea2835ad7bd5eaf84d7688520@changeid> <20220521091751.opeiqbmc5c2okdq6@houat> <20220603082139.sfdxb5ndwpvlhklh@penduick> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 03, 2022 at 01:19:16PM +0300, Dmitry Baryshkov wrote: > On Fri, 3 Jun 2022 at 11:21, Maxime Ripard wrote: > > > > On Tue, May 31, 2022 at 02:06:34PM -0700, Doug Anderson wrote: > > > On Mon, May 23, 2022 at 10:00 AM Doug Anderson wrote: > > > > On Sat, May 21, 2022 at 2:17 AM Maxime Ripard w= rote: > > > > > On Tue, May 10, 2022 at 12:29:43PM -0700, Douglas Anderson wrote: > > > > > > This adds a devm managed version of drm_bridge_add(). Like other > > > > > > "devm" function listed in drm_bridge.h, this function takes an > > > > > > explicit "dev" to use for the lifetime management. A few notes: > > > > > > * In general we have a "struct device" for bridges that makes a= good > > > > > > candidate for where the lifetime matches exactly what we want. > > > > > > * The "bridge->dev->dev" device appears to be the encoder > > > > > > device. That's not the right device to use for lifetime manag= ement. > > > > > > > > > > > > Suggested-by: Dmitry Baryshkov > > > > > > Signed-off-by: Douglas Anderson > > > > > > > > > > If we are to introduce more managed helpers, I think it'd be wise= r to > > > > > introduce them as DRM-managed, and not device managed. > > > > > > > > > > Otherwise, you'll end up in a weird state when a device has been = removed > > > > > but the DRM device is still around. > > > > > > > > I'm kinda confused. In this case there is no DRM device for the bri= dge > > > > and, as per my CL description, "bridge-dev->dev" appears to be the > > > > encoder device. I wasn't personally involved in discussions about i= t, > > > > but I was under the impression that this was expected / normal. Thus > > > > we can't make this DRM-managed. > > > > > > Since I didn't hear a reply, > > > > Gah, I replied but it looks like somehow it never reached the ML... > > > > Here was my original reply: > > > > > > > This adds a devm managed version of drm_bridge_add(). Like other > > > > > "devm" function listed in drm_bridge.h, this function takes an > > > > > explicit "dev" to use for the lifetime management. A few notes: > > > > > * In general we have a "struct device" for bridges that makes a g= ood > > > > > candidate for where the lifetime matches exactly what we want. > > > > > * The "bridge->dev->dev" device appears to be the encoder > > > > > device. That's not the right device to use for lifetime managem= ent. > > > > > > > > > > Suggested-by: Dmitry Baryshkov > > > > > Signed-off-by: Douglas Anderson > > > > > > > > If we are to introduce more managed helpers, I think it'd be wiser = to > > > > introduce them as DRM-managed, and not device managed. > > > > > > > > Otherwise, you'll end up in a weird state when a device has been re= moved > > > > but the DRM device is still around. > > >=3D20 > > > I'm kinda confused. In this case there is no DRM device for the bridge > > > and, as per my CL description, "bridge-dev->dev" appears to be the > > > encoder device. > > > > bridge->dev seems right though? > > > > > I wasn't personally involved in discussions about it, but I was under > > > the impression that this was expected / normal. Thus we can't make > > > this DRM-managed. > > > > Still, I don't think devm is the right solution to this either. > > > > The underlying issue is two-fold: > > > > - Encoders can have a pointer to a bridge through of_drm_find_bridge > > or similar. However, bridges are traditionally tied to their device > > lifetime (by calling drm_bridge_add in probe, and drm_bridge_remove > > in remove). Encoders will typically be tied to the DRM device > > however, and that one sticks around until the last application > > closes it. We can thus very easily end up with a dangling pointer, > > and a use-after-free. > > > > - It's not the case yet, but it doesn't seem far fetch to expose > > properties of bridges to the userspace. In that case, the userspace > > would be likely to still hold references to objects that aren't > > there anymore when the bridge is gone. > > > > The first is obviously a larger concern, but if we can find a solution > > that would accomodate the second it would be great. > > > > As far as I can see, we should fix in two steps: > > > > - in drm_bridge_attach, we should add a device-managed call that will > > unregister the main DRM device. We don't allow to probe the main DRM > > device when the bridge isn't there yet in most case, so it makes > > sense to remove it once the bridge is no longer there as well. >=20 > The problem is that I do not see a good way to unregister the main DRM > device outside of it's driver code. That's what drmm helpers are doing though: they'll defer the cleanup until the last user has closed its fd. > > - When the DRM device is removed, have the core cleanup any bridge > > registered. That will remove the need to have drm_bridge_remove in > > the first place. > > > > > I'll assume that my response addressed your concerns. Assuming I get > > > reviews for the other two patches in this series I'll plan to land > > > this with Dmitry's review. > > > > I still don't think it's a good idea to merge it. It gives an illusion > > of being safe, but it's really far from it. >=20 > It is more of removing the boilerplate code spread over all the > drivers rather than about particular safety. >=20 > I'd propose to land devm_drm_bridge_add (and deprecate calling > drm_bridge_remove from the bridge driver at some point) and work on > the whole drm_device <-> drm_bridge problem in the meantime. Do you really expect that to happen? :) Anyway, it's been merged, it's too late now anyway. I don't really feel like it's a good thing, but it doesn't really make the situation worse either. Maxime