[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220603082139.sfdxb5ndwpvlhklh@penduick>
Date: Fri, 3 Jun 2022 10:21:39 +0200
From: Maxime Ripard <maxime@...no.tech>
To: Doug Anderson <dianders@...omium.org>
Cc: dri-devel <dri-devel@...ts.freedesktop.org>,
Hsin-Yi Wang <hsinyi@...omium.org>,
Abhinav Kumar <quic_abhinavk@...cinc.com>,
Philip Chen <philipchen@...omium.org>,
Sankeerth Billakanti <quic_sbillaka@...cinc.com>,
Robert Foss <robert.foss@...aro.org>,
freedreno <freedreno@...ts.freedesktop.org>,
Dmitry Baryshkov <dmitry.baryshkov@...aro.org>,
linux-arm-msm <linux-arm-msm@...r.kernel.org>,
Stephen Boyd <swboyd@...omium.org>,
Daniel Vetter <daniel@...ll.ch>,
David Airlie <airlied@...ux.ie>,
Maarten Lankhorst <maarten.lankhorst@...ux.intel.com>,
Thomas Zimmermann <tzimmermann@...e.de>,
LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v3 3/4] drm/bridge: Add devm_drm_bridge_add()
On Tue, May 31, 2022 at 02:06:34PM -0700, Doug Anderson wrote:
> On Mon, May 23, 2022 at 10:00 AM Doug Anderson <dianders@...omium.org> wrote:
> > On Sat, May 21, 2022 at 2:17 AM Maxime Ripard <maxime@...no.tech> wrote:
> > > 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 management.
> > > >
> > > > Suggested-by: Dmitry Baryshkov <dmitry.baryshkov@...aro.org>
> > > > Signed-off-by: Douglas Anderson <dianders@...omium.org>
> > >
> > > 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 removed
> > > but the DRM device is still around.
> >
> > 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. 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.
>
> 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 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 management.
> > >
> > > Suggested-by: Dmitry Baryshkov <dmitry.baryshkov@...aro.org>
> > > Signed-off-by: Douglas Anderson <dianders@...omium.org>
> >
> > 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 removed
> > but the DRM device is still around.
>=20
> 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.
- 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.
Maxime
Powered by blists - more mailing lists