From: "Luca Ceresoli" <luca.ceresoli@bootlin.com>
To: "Liu Ying" <victor.liu@nxp.com>,
"Andrzej Hajda" <andrzej.hajda@intel.com>,
"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>,
"Maxime Ripard" <mripard@kernel.org>,
"Thomas Zimmermann" <tzimmermann@suse.de>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>
Cc: "Marco Felsch" <m.felsch@pengutronix.de>,
<dri-devel@lists.freedesktop.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] drm/bridge: Fix refcount shown via debugfs for encoder_bridges_show()
Date: Mon, 16 Mar 2026 12:14:23 +0100 [thread overview]
Message-ID: <DH45VL1LHCP3.2MWX4VKP46H04@bootlin.com> (raw)
In-Reply-To: <b25719e0-21d3-4919-b95e-22b22bdbb388@nxp.com>
Hello Liu, Maxime,
On Mon Mar 16, 2026 at 10:47 AM CET, Liu Ying wrote:
>>>>>> @Maxime: based on the issue Liu is trying to work around, do you think it
>>>>>> would make sense to go back to the initial approach for that series?
>>>>>> I.e. drm_for_each_bridge_in_chain_scoped() grabs the chain lock, which is a
>>>>>> superset of the per-bridge refcount, and thus the refcount can be dropped?
>>>>>> This would remove the debugfs issue, slightly simplify
>>>>>> drm_for_each_bridge_in_chain_scoped(), and introduce no new issues AFAIK.
>>>>>
>>>>> Just my take on the chain lock approach - I agree Maxime's comment on [v2]
>>>>> that keeping the get/put is a better than using the chain lock to ensure
>>>>> the refcount is correct. The chain lock could be added later on if needed.
>>>>
>>>> Well, no, adding the chain mutex is necessary(*), otherwise Thread A could
>>>> iterate over the chain while thread B is adding/removing bridges to/from
>>>> the chain.
>>>>
>>>> And the chain mutex is a superset of the per-bridge refcount, so when
>>>> adding the mutex the refcount inside drm_for_each_bridge_in_chain_scoped()
>>>> becomes useless (and slightly hurting as it makes the refcount shown in
>>>> debugfs inconsistent, as you noticed).
>>>
>>> For better code readability, I think keeping the get/put is fine even if
>>> you add a lock
>>
>> The [v4] code with the removal of the extra refcount would not be more
>> complex. It would be a bit less code (no need for the DEFINE_FREE and
>> __free()). Maybe it'd need an extra comment to clarify when the
>> drm_bridge_put() is called.
>>
>> [v4] https://lore.kernel.org/all/20260113-drm-bridge-alloc-encoder-chain-mutex-v4-4-60f3135adc45@bootlin.com/
>>
>>> (maybe RCU list is better than mutex, since the chain is
>>> read often). That follows the idea that you mentioned in [1]: "every
>>> pointer to a drm_bridge stored somewhere is a reference to a bridge".
>>
>> That's true. However while it's an important pointer hygiene rule for
>> device drivers, for core code it's OK to deviate when there is a reason.
>>
>>> Plus, seems no performance issue with the get/put, as discussed in [v2].
>>
>> I confirm performance is surely not an issue here.
>>
>> All that said, I'm OK with either option:
>>
>> * no ref taken when the mutex is added
>> * ref taken when the mutex is added (as v4) + your patch to fix debugfs
>
> Maybe consider to take this patch first, since it doesn't hurt.
Yes, especially as the current debugfs output is non-intuitive.
> Even if
> we end up with the first option, the refcount is supposed to be correct
> anyway.
Well, if we apply this patch and then go for option 1 then this patch shall
be removed, or the refcount shown would be one-less than the expected
value, instead of one-more as it is now.
> Luca, do you think this patch deserves at least an A-b tag from you if not
> a R-b tag?
I've been waiting a bit in case Maxime or someone else wanted to chime
in. I'm reviewing it now.
Luca
--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
next prev parent reply other threads:[~2026-03-16 11:14 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-12 6:05 [PATCH] drm/bridge: Fix refcount shown via debugfs for encoder_bridges_show() Liu Ying
2026-03-12 17:30 ` Luca Ceresoli
2026-03-13 8:33 ` Liu Ying
2026-03-13 9:57 ` Luca Ceresoli
2026-03-13 10:22 ` Liu Ying
2026-03-13 17:32 ` Luca Ceresoli
2026-03-16 9:47 ` Liu Ying
2026-03-16 11:14 ` Luca Ceresoli [this message]
2026-03-17 2:04 ` Liu Ying
2026-03-17 8:15 ` Luca Ceresoli
2026-03-16 11:15 ` Luca Ceresoli
2026-03-17 2:35 ` Liu Ying
2026-03-17 8:15 ` 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=DH45VL1LHCP3.2MWX4VKP46H04@bootlin.com \
--to=luca.ceresoli@bootlin.com \
--cc=Laurent.pinchart@ideasonboard.com \
--cc=airlied@gmail.com \
--cc=andrzej.hajda@intel.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=jernej.skrabec@gmail.com \
--cc=jonas@kwiboo.se \
--cc=linux-kernel@vger.kernel.org \
--cc=m.felsch@pengutronix.de \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=neil.armstrong@linaro.org \
--cc=rfoss@kernel.org \
--cc=simona@ffwll.ch \
--cc=tzimmermann@suse.de \
--cc=victor.liu@nxp.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.