From: Henry Zhang <henryzhang62@gmail.com>
To: mripard@kernel.org, mcanal@igalia.com
Cc: dave.stevenson@raspberrypi.com, kernel-list@raspberrypi.com,
maarten.lankhorst@linux.intel.com, tzimmermann@suse.de,
airlied@gmail.com, simona@ffwll.ch,
dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
henryzhang62@gmail.com
Subject: Re: [PATCH] drm/vc4: dsi: Allocate the encoder per DRM device
Date: Wed, 18 Nov 2026 09:48:16 -0800 [thread overview]
Message-ID: <20261118174816.1382711-1-henryzhang62@gmail.com> (raw)
In-Reply-To: <av11cTfEuyFJW5h8@houat>
On Wed, Nov 18, 2026, Maxime Ripard wrote:
> On Tue, Nov 17, 2026 at 12:59:02PM -0800, Henry Zhang wrote:
> > The DSI encoder is embedded in struct vc4_dsi, which lives as long as
> > the DSI platform device
>
> That's not true.
>
> It's allocated with devm_drm_bridge_alloc() that will *not* free it in
> remove but give away its reference there.
>
> We have another reference taken in vc4_dsi_bind, that is only given up
> through a drm-managed action and thus will only be freed when the DRM
> device is destroyed.
You're right, thanks. struct vc4_dsi is refcounted through its bridge,
and the old DRM device keeps it alive. I'll fix that sentence. The
problem is not that struct vc4_dsi is freed too early, but that the
encoder embedded in it is used by two DRM devices at the same time.
> All vc4 components should be tied to the DRM device lifetime so that's
> not generally correct either. Something might have snuck back in though.
The encoder itself is DRM-managed: it is initialised with
drmm_encoder_init() and cleaned up when the DRM device is released.
But it is embedded in struct vc4_dsi, which outlives an unbind and is
shared by the next DRM device that binds the component. That part is
not tied to a single DRM device, since 6f0ca506c30e ("drm/vc4: dsi:
Switch to DRM-managed encoder initialization").
> Also, generally speaking, unloading panel drivers is unsupported at this
> point. It's a work in progress, but requires more changes to be safe.
Understood.
> This is surprising though. I'd like to see a detailed analysis of what's
> actually going on on mainline because it doesn't look right.
Maíra asked the same, so this answers both. It reproduces on
drm-misc-next (fb191ef62) on a Raspberry Pi 4, DSI1 in video mode, with
an out-of-tree DSI panel module and no downstream changes to vc4. The
compositor is stopped, a process holds /dev/dri/card1 open, the panel
module is unloaded and loaded again, then the held fd is closed:
1. Unloading the panel module detaches from the DSI host, which deletes
the DSI component and unbinds vc4. The held fd keeps the old DRM
device alive, with dsi->encoder still on its encoder list and the
DSI bridge still attached to it.
2. Loading it again binds a new DRM device. vc4_dsi_bind() calls
drmm_encoder_init() on the same dsi->encoder, which links it into
the new device's encoder list.
3. drm_bridge_attach() returns -EBUSY, as the bridge still belongs to
the old device, so the bind fails.
4. The failed bind releases the new DRM device. drm_encoder_cleanup()
unlinks dsi->encoder and clears it, but the old device's encoder
list still points to it.
5. Closing the held fd releases the old DRM device, which walks that
list: list corruption, the WARN in drmm_encoder_alloc_release() and
a NULL pointer dereference in drm_mode_config_cleanup().
Kprobes on drmm_encoder_init(), drm_bridge_attach() and
drm_encoder_cleanup() show it (condensed below). The old DRM device is
ffff000049249000, the new one ffff000041a79000, dsi->encoder is
ffff000044138000 and dsi->bridge ffff0000441380f0:
223.656483 drmm_encoder_init drm=ffff000041a79000 enc=ffff000044138000
223.656520 drm_bridge_attach enc=ffff000044138000 br=ffff0000441380f0
223.656529 drm_bridge_attach returned -16
223.715147 drm_encoder_cleanup enc=ffff000044138000 dev=ffff000041a79000
(held fd closed)
233.848952 drm_encoder_cleanup enc=ffff0000409cca58 dev=ffff000049249000
and the first list_del report shows the cleared dsi->encoder.head
(ffff000044138008) still linked in the old device's list:
[ 233.849039] list_del corruption. prev->next should be ffff0000409cca60, but was 0000000000000000. (prev=ffff000044138008)
[ 233.849099] WARNING: lib/list_debug.c:62 at __list_del_entry_valid_or_report+0x128/0x160, CPU#0: python3/2080
[ 233.849394] CPU: 0 UID: 0 PID: 2080 Comm: python3 Tainted: G C O 7.4.0-rc2-dmn-test+ #1 PREEMPT(full)
[ 233.849424] Hardware name: Raspberry Pi 4 Model B Rev 1.5 (DT)
[ 233.849448] pc : __list_del_entry_valid_or_report+0x128/0x160
[ 233.849465] lr : __list_del_entry_valid_or_report+0x128/0x160
[ 233.849734] Call trace:
[ 233.849744] __list_del_entry_valid_or_report+0x128/0x160 (P)
[ 233.849764] drm_encoder_cleanup+0xcc/0x150 [drm]
[ 233.849950] drmm_encoder_alloc_release+0x24/0x40 [drm]
[ 233.850090] drm_managed_release+0xb0/0x178 [drm]
[ 233.850231] drm_dev_put.part.0+0x98/0xd0 [drm]
[ 233.850371] drm_minor_release+0x20/0x50 [drm]
[ 233.850511] drm_release+0x110/0x148 [drm]
[ 233.850651] __fput+0xd4/0x300
[ 233.850672] fput_close_sync+0x48/0x110
[ 233.850690] filp_close_sync+0x2c/0x48
[ 233.850706] put_files_struct+0xd4/0x148
[ 233.850723] exit_files+0x4c/0x70
[ 233.850738] do_exit+0x25c/0xa20
[ 233.850756] do_group_exit+0x3c/0xa0
[ 233.850772] get_signal+0x920/0xa18
[ 233.850791] arch_do_signal_or_restart+0xa0/0x3f8
[ 233.850808] exit_to_user_mode_loop+0x100/0x188
[ 233.850825] el0_svc+0x1cc/0x1d0
[ 233.850845] el0t_64_sync_handler+0xa0/0xe8
[ 233.850864] el0t_64_sync+0x198/0x1a0
[ 233.850879] ---[ end trace 0000000000000000 ]---
[ 233.869067] WARNING: drivers/gpu/drm/drm_encoder.c:228 at drmm_encoder_alloc_release+0x30/0x40 [drm], CPU#0: python3/2080
[ 233.869478] CPU: 0 UID: 0 PID: 2080 Comm: python3 Tainted: G WC O 7.4.0-rc2-dmn-test+ #1 PREEMPT(full)
[ 233.869506] Hardware name: Raspberry Pi 4 Model B Rev 1.5 (DT)
[ 233.869529] pc : drmm_encoder_alloc_release+0x30/0x40 [drm]
[ 233.869668] lr : drm_managed_release+0xb0/0x178 [drm]
[ 233.870051] Call trace:
[ 233.870059] drmm_encoder_alloc_release+0x30/0x40 [drm] (P)
[ 233.870201] drm_dev_put.part.0+0x98/0xd0 [drm]
[ 233.870340] drm_minor_release+0x20/0x50 [drm]
[ 233.870479] drm_release+0x110/0x148 [drm]
[ 233.870619] __fput+0xd4/0x300
[ 233.870639] fput_close_sync+0x48/0x110
[ 233.870657] filp_close_sync+0x2c/0x48
[ 233.870672] put_files_struct+0xd4/0x148
[ 233.870688] exit_files+0x4c/0x70
[ 233.870703] do_exit+0x25c/0xa20
[ 233.870721] do_group_exit+0x3c/0xa0
[ 233.870737] get_signal+0x920/0xa18
[ 233.870755] arch_do_signal_or_restart+0xa0/0x3f8
[ 233.870772] exit_to_user_mode_loop+0x100/0x188
[ 233.870787] el0_svc+0x1cc/0x1d0
[ 233.870807] el0t_64_sync_handler+0xa0/0xe8
[ 233.870825] el0t_64_sync+0x198/0x1a0
[ 233.870839] ---[ end trace 0000000000000000 ]---
[two more list_del corruption reports with the same call trace cut]
[ 233.875117] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000008
[ 233.875331] Internal error: Oops: 0000000096000004 [#1] SMP
[ 233.875631] CPU: 0 UID: 0 PID: 2080 Comm: python3 Tainted: G WC O 7.4.0-rc2-dmn-test+ #1 PREEMPT(full)
[ 233.875679] Hardware name: Raspberry Pi 4 Model B Rev 1.5 (DT)
[ 233.875717] pc : drm_mode_config_cleanup+0x58/0x320 [drm]
[ 233.875875] lr : drm_mode_config_init_release+0x18/0x30 [drm]
[ 233.876371] Call trace:
[ 233.876383] drm_mode_config_cleanup+0x58/0x320 [drm] (P)
[ 233.876539] drm_mode_config_init_release+0x18/0x30 [drm]
[ 233.876692] drm_managed_release+0xb0/0x178 [drm]
[ 233.876842] drm_dev_put.part.0+0x98/0xd0 [drm]
[ 233.876998] drm_minor_release+0x20/0x50 [drm]
[ 233.877149] drm_release+0x110/0x148 [drm]
[ 233.877299] __fput+0xd4/0x300
[ 233.877330] fput_close_sync+0x48/0x110
[ 233.877355] filp_close_sync+0x2c/0x48
[ 233.877377] put_files_struct+0xd4/0x148
[ 233.877400] exit_files+0x4c/0x70
[ 233.877422] do_exit+0x25c/0xa20
[ 233.877446] do_group_exit+0x3c/0xa0
[ 233.877469] get_signal+0x920/0xa18
[ 233.877494] arch_do_signal_or_restart+0xa0/0x3f8
[ 233.877519] exit_to_user_mode_loop+0x100/0x188
[ 233.877542] el0_svc+0x1cc/0x1d0
[ 233.877567] el0t_64_sync_handler+0xa0/0xe8
[ 233.877593] el0t_64_sync+0x198/0x1a0
[ 233.877620] Code: eb0102bf 54000160 d1002294 f9404001 (f9400421)
[ 233.877643] ---[ end trace 0000000000000000 ]---
Additional sanitized trace excerpts are available on request.
With the patch, the same test on the same kernel still fails the bind
with -EBUSY, but closing the held fd gives no warning or oops, and
loading the panel module again afterwards brings the display back. This
was one focused run per build, not a stress test, and the patch does
not make the rebind succeed while the old device holds the bridge.
Would you prefer a v2 with the corrected description and the mainline
trace, or should this go with the panel unloading work?
Thanks,
Henry
next prev parent reply other threads:[~2026-11-18 17:48 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 20:59 Henry Zhang
2026-11-18 10:09 ` Maxime Ripard
2026-11-18 17:48 ` Henry Zhang [this message]
2026-11-18 14:00 ` Maíra Canal
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=20261118174816.1382711-1-henryzhang62@gmail.com \
--to=henryzhang62@gmail.com \
--cc=airlied@gmail.com \
--cc=dave.stevenson@raspberrypi.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=kernel-list@raspberrypi.com \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mcanal@igalia.com \
--cc=mripard@kernel.org \
--cc=simona@ffwll.ch \
--cc=tzimmermann@suse.de \
/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
all inboxes | Powered by JetHome®