linux-doc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luca Ceresoli <luca.ceresoli@bootlin.com>
To: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Cc: "Maxime Ripard" <mripard@kernel.org>,
	"Simona Vetter" <simona@ffwll.ch>,
	"Inki Dae" <inki.dae@samsung.com>,
	"Jagan Teki" <jagan@amarulasolutions.com>,
	"Marek Szyprowski" <m.szyprowski@samsung.com>,
	"Catalin Marinas" <catalin.marinas@arm.com>,
	"Will Deacon" <will@kernel.org>,
	"Shawn Guo" <shawnguo@kernel.org>,
	"Sascha Hauer" <s.hauer@pengutronix.de>,
	"Pengutronix Kernel Team" <kernel@pengutronix.de>,
	"Fabio Estevam" <festevam@gmail.com>,
	"Daniel Thompson" <danielt@kernel.org>,
	"Andrzej Hajda" <andrzej.hajda@intel.com>,
	"Jonathan Corbet" <corbet@lwn.net>,
	"Paul Kocialkowski" <contact@paulk.fr>,
	"Neil Armstrong" <neil.armstrong@linaro.org>,
	"Robert Foss" <rfoss@kernel.org>,
	"Laurent Pinchart" <Laurent.pinchart@ideasonboard.com>,
	"Jonas Karlman" <jonas@kwiboo.se>,
	"Jernej Skrabec" <jernej.skrabec@gmail.com>,
	"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
	"Thomas Zimmermann" <tzimmermann@suse.de>,
	"David Airlie" <airlied@gmail.com>,
	"Hervé Codina" <herve.codina@bootlin.com>,
	"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
	linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org,
	linux-doc@vger.kernel.org,
	"Paul Kocialkowski" <paul.kocialkowski@bootlin.com>
Subject: Re: [PATCH v5 04/10] drm/bridge: add documentation of refcounted bridges
Date: Wed, 29 Jan 2025 14:11:35 +0100	[thread overview]
Message-ID: <20250129141135.28b01ff9@booty> (raw)
In-Reply-To: <yipjwosmkqsadvhulzh76ydqbfvv5npdafl3yzdjmikfa2yq4y@j7nj4audwxl7>

On Wed, 29 Jan 2025 14:22:30 +0200
Dmitry Baryshkov <dmitry.baryshkov@linaro.org> wrote:

> On Wed, Jan 29, 2025 at 12:51:53PM +0100, Luca Ceresoli wrote:
> > Hi Maxime,
> > 
> > On Tue, 28 Jan 2025 15:49:23 +0100
> > Maxime Ripard <mripard@kernel.org> wrote:
> >   
> > > Hi,
> > > 
> > > On Wed, Jan 22, 2025 at 05:12:30PM +0100, Luca Ceresoli wrote:  
> > > > On Wed, 8 Jan 2025 17:02:04 +0100
> > > > Maxime Ripard <mripard@kernel.org> wrote:
> > > > 
> > > > [...]
> > > >     
> > > > > > > > And we'll also need some flag in drm_bridge to indicate that the device
> > > > > > > > is gone, similar to what drm_dev_enter()/drm_dev_exit() provides,
> > > > > > > > because now your bridge driver sticks around for much longer than your
> > > > > > > > device so the expectation that your device managed resources (clocks,
> > > > > > > > registers, etc.) are always going to be around.        
> > > > > > 
> > > > > > Yes, makes sense too. That should be a drm_bridge_enter/exit(), and
> > > > > > drm_bridge.c will need to be sprinkled with them I guess.      
> > > > > 
> > > > > The users would be the drivers, most likely. There's not much we can do
> > > > > at the framework level, unfortunately.    
> > > > 
> > > > Back to the idea of a "gone" flag, or perhaps an "unplugged" flag to
> > > > be consistent with the struct drm_device naming, and
> > > > drm_bridge_enter()/drm_bridge_exit(), I did a few experiments and have
> > > > a question.
> > > > 
> > > > In case:
> > > > 
> > > >   a) there is a notification callback to inform about bridges
> > > >      being removed, and
> > > >   b) all entities owning a struct drm_bridge pointer stop using
> > > >      that pointer when notified
> > > > 
> > > > 
> > > > With the above, there should be no need for
> > > > drm_bridge_enter()/drm_bridge_exit(). Nobody will be using a pointer to
> > > > a bridge that is being removed.
> > > > 
> > > > Now, about a), patch 1 in this series implements such a mechanism to
> > > > inform all bridges when a bridge is being removed. Note that the
> > > > "unplugged" flag would be set immediately after the notifier callback
> > > > is currently called: "unplugged == true" will never happen before the
> > > > callback, and after the callback there will be no pointer at all.
> > > > 
> > > > Patch 1 however is only notifying bridges, so other entities (e.g.
> > > > encoders) cannot be notified with this implementation. However a
> > > > different notification mechanism can be implemented. E.g. until v3 this
> > > > series was using a generic struct notifier_block for this goal [0], so
> > > > any part of the kernel can be notified.
> > > > 
> > > > About b), the notification appears simpler to implement in the various
> > > > drivers as it needs to be added in one place per driver. Also adding
> > > > drm_bridge_enter()/exit() can be trickier to get right for non-trivial
> > > > functions.
> > > > 
> > > > Do you see any drawback in using a notification mechanism instead of
> > > > drm_bridge_enter()/exit() + unplugged flag?    
> > > 
> > > Yeah, because we're not considering the same thing :)
> > > 
> > > The issue you're talking about is that you want to be notified that the
> > > next bridge has been removed and you shouldn't use the drm_bridge
> > > pointer anymore.
> > > 
> > > A notification mechanism sounds like a good solution there.
> > > 
> > > The other issue we have is that now, we will have the drm_bridge pointer
> > > still allocated and valid after its device has been removed.
> > > 
> > > In which case, you need to be able to tell the bridge driver whose
> > > device got removed that the devm resources aren't there anymore, and it
> > > shouldn't try to access them.
> > > 
> > > That's what drm_bridge_enter()/exit is here for.  
> > 
> > Let me rephrase to check I got what you mean.
> > 
> > A) On bridge removal, use a notifier to notify all consumers of that
> > bridge that they have to stop using the pointer to the bridge about to
> > be removed.
> > 
> > B) Internally in the bridge driver (provider) use
> > drm_bridge_enter()/exit() to forbid access to resources when the
> > hardware is unplugged.
> > 
> > And also: bridge consumers won't need to use drm_bridge_enter()/exit()
> > as they will clear their pointer before setting the unplugged flag.
> > 
> > Is my understanding of your idea correct?
> > 
> > If it is, I tend to agree, and I like it.
> > 
> > I like it, except for one point  I'm afraid. Why do we need enter/exit
> > inside the driver (provider) code? At driver release, the driver
> > instance won't exist anymore. Sure the private struct embedding a
> > struct drm_bridge will be still allocated for some time, but the struct
> > device will not exist, and the device driver instance as well.  
> 
> You have to sync several possible kinds of events: bridge calls from DRM
> core, from HDMI audio, CEC, DP AUX _and_ completely async device
> 'remove' / unbind callbacks.

Ah, yes, that make sense. Looks like the big picture w.r.t. notifiers
and enter/exit is clear -- until implementation time at least ;)

Thanks,
Luca

-- 
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

  reply	other threads:[~2025-01-29 13:11 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-31 10:39 [PATCH v5 00/10] Add support for hot-pluggable DRM bridges Luca Ceresoli
2024-12-31 10:39 ` [PATCH v5 01/10] drm/bridge: allow bridges to be informed about added and removed bridges Luca Ceresoli
2024-12-31 10:39 ` [PATCH v5 02/10] drm/encoder: add drm_encoder_cleanup_from() Luca Ceresoli
2024-12-31 10:39 ` [PATCH v5 03/10] drm/bridge: add support for refcounted DRM bridges Luca Ceresoli
2024-12-31 11:11   ` Jani Nikula
2025-01-02 12:03     ` Luca Ceresoli
2025-01-03  9:36       ` Jani Nikula
2024-12-31 10:39 ` [PATCH v5 04/10] drm/bridge: add documentation of refcounted bridges Luca Ceresoli
2024-12-31 17:54   ` Randy Dunlap
2025-01-02 12:02     ` Luca Ceresoli
2025-01-06 10:39   ` Maxime Ripard
2025-01-06 12:24     ` Dmitry Baryshkov
2025-01-06 14:49       ` Maxime Ripard
2025-01-07 10:35         ` Dmitry Baryshkov
2025-01-07 15:12           ` Maxime Ripard
2025-01-08 15:24           ` Luca Ceresoli
2025-01-08 15:24       ` Luca Ceresoli
2025-01-08 16:02         ` Maxime Ripard
2025-01-22 16:12           ` Luca Ceresoli
2025-01-28 14:49             ` Maxime Ripard
2025-01-29 11:51               ` Luca Ceresoli
2025-01-29 12:22                 ` Dmitry Baryshkov
2025-01-29 13:11                   ` Luca Ceresoli [this message]
2024-12-31 10:39 ` [PATCH v5 05/10] drm/tests: bridge: add KUnit tests for DRM bridges (init and destroy) Luca Ceresoli
2024-12-31 10:40 ` [PATCH v5 06/10] drm/bridge: ti-sn65dsi83: use dynamic lifetime management Luca Ceresoli
2024-12-31 10:40 ` [PATCH v5 07/10] drm/bridge: panel: " Luca Ceresoli
2024-12-31 10:40 ` [PATCH v5 08/10] drm/bridge: samsung-dsim: use supporting variable for out_bridge Luca Ceresoli
2024-12-31 14:57   ` Dmitry Baryshkov
2025-01-02 12:01     ` Luca Ceresoli
2025-01-03  6:00       ` Dmitry Baryshkov
2025-01-10 10:58       ` Luca Ceresoli
2025-01-16 10:32         ` Luca Ceresoli
2025-01-16 10:56           ` Dmitry Baryshkov
2025-01-21 11:27             ` Luca Ceresoli
2025-01-21 11:57               ` Dmitry Baryshkov
2025-01-28 15:52                 ` Maxime Ripard
2025-01-16 12:26           ` Maxime Ripard
2025-01-21 11:27             ` Luca Ceresoli
2025-01-28 15:09               ` Maxime Ripard
2025-01-29 11:51                 ` Luca Ceresoli
2025-02-04 15:44                   ` Maxime Ripard
2024-12-31 10:40 ` [PATCH v5 09/10] drm/bridge: samsung-dsim: refcount the out_bridge Luca Ceresoli
2024-12-31 14:58   ` Dmitry Baryshkov
2024-12-31 10:40 ` [PATCH v5 10/10] drm/bridge: hotplug-bridge: add driver to support hot-pluggable DSI bridges Luca Ceresoli
2024-12-31 15:29   ` Dmitry Baryshkov
2025-01-02 12:01     ` Luca Ceresoli
2025-09-09 15:29       ` Luca Ceresoli
2025-09-09 15:39         ` Luca Ceresoli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250129141135.28b01ff9@booty \
    --to=luca.ceresoli@bootlin.com \
    --cc=Laurent.pinchart@ideasonboard.com \
    --cc=airlied@gmail.com \
    --cc=andrzej.hajda@intel.com \
    --cc=catalin.marinas@arm.com \
    --cc=contact@paulk.fr \
    --cc=corbet@lwn.net \
    --cc=danielt@kernel.org \
    --cc=dmitry.baryshkov@linaro.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=festevam@gmail.com \
    --cc=herve.codina@bootlin.com \
    --cc=inki.dae@samsung.com \
    --cc=jagan@amarulasolutions.com \
    --cc=jernej.skrabec@gmail.com \
    --cc=jonas@kwiboo.se \
    --cc=kernel@pengutronix.de \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=neil.armstrong@linaro.org \
    --cc=paul.kocialkowski@bootlin.com \
    --cc=rfoss@kernel.org \
    --cc=s.hauer@pengutronix.de \
    --cc=shawnguo@kernel.org \
    --cc=simona@ffwll.ch \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=tzimmermann@suse.de \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).