drm/vc4: dsi: Allocate the encoder per DRM device
Subsystems (3)
PATCH 1/1 drm/vc4: dsi: Allocate the encoder per DRM device
The DSI encoder is embedded in struct vc4_dsi, which lives as long as the DSI platform device, but it is initialised with drmm_encoder_init() and so is only cleaned up when the DRM device is released. The DRM device can outlive the unbind of the vc4 components: unloading the DSI panel driver detaches from the DSI host, which deletes the DSI component and unbinds the whole vc4 DRM device, but a compositor that keeps the DRM device open keeps it alive.
If the panel driver is loaded again before that, the new DRM device binds the DSI component and calls drmm_encoder_init() on the encoder that is still on the old DRM device's encoder list. The old device's release later cleans it up from under the new one. On a Raspberry Pi 4 with a 6.18-based kernel, closing the old DRM device then gave:
WARNING: drivers/gpu/drm/drm_encoder.c:214 at drmm_encoder_alloc_release+0x30/0x40 [drm] Call trace: drmm_encoder_alloc_release <- drm_dev_put <- drm_gem_dmabuf_release <- __fput Unable to handle kernel NULL pointer dereference at virtual address 0000000000000008 pc : drm_mode_config_cleanup+0x5c/0x2f0 [drm] Call trace: drm_mode_config_cleanup <- drm_managed_release <- drm_dev_put
Allocate the encoder in bind with drmm_encoder_alloc(), so each DRM device has its own and releases only its own. The DSI bridge is still
shared: while the old DRM device holds it, drm_bridge_attach() in the new bind fails with -EBUSY, so binding again before the old DRM device is released now fails cleanly instead of corrupting both devices.
The analysis, this change and this description were prepared with the help of an AI coding assistant (Claude Code).
---
Testing:
- On this base (drm-misc-next 467ac0b56aeb): compile-tested only, arm64 defconfig with DRM_VC4=m, W=1, no new warnings.
- A backport to a downstream Raspberry Pi 6.18.34 kernel, on a Raspberry Pi 4 with an out-of-tree modular DSI panel driver: with the compositor stopped and a process holding /dev/dri/card1 open, unload the panel driver and load it again. The bind now fails cleanly:
vc4-drm gpu: failed to bind fe700000.dsi (ops vc4_dsi_ops [vc4]): -16 vc4-drm gpu: adev bind failed: -16
the panel probe fails with -16, and there is no warning or oops, also when the holder then closes the old DRM device. Unloading and loading the panel driver again after that brings back the display and the compositor. Without the change, the same kernel gave the warning and oops above. The backport differs from this patch in two
ways: that kernel still gets the panel bridge with drmm_of_get_bridge(), which has a use-after-free of its own in this sequence, so the test kernel used devm_drm_of_get_bridge() instead (not needed here, where the panel bridge is refcounted); and a downstream DSI restart worker that used the embedded encoder now follows a pointer to the current one.
The -EBUSY is final: the panel probe is not retried when the old DRM device goes away, so the panel driver has to be loaded again. Would you prefer the DSI host to wait for the old DRM device to be released before adding its component again, or a bridge allocated per bind?
Not addressed: a connector probe that is already running when the panel is removed can still call into the panel driver.
This applies to drm-misc-next on its own. It also applies on top of my "drm/vc4: dsi: Serialize register writes through the DMA workaround", and it does not touch the code changed by my vc4 DSI series <[email protected]>.
Tools: Claude Code (an AI coding assistant) analysed the crash logs and the vc4/DRM lifetimes, located the introducing commit, wrote the change and this description, built and checkpatch-checked it, and ran the backport test on the board, at my request.
drivers/gpu/drm/vc4/vc4_dsi.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-)
drivers/gpu/drm/vc4/vc4_dsi.c +23 -12
@@ -546,9 +546,18 @@ struct vc4_dsi_variant { }; +/* +* The encoder of one DRM device. The DRM device can outlive the unbind of +* this component, so a later bind must not reuse the encoder of an earlier +* one: allocate one per bind, managed by the DRM device. +*/ +struct vc4_dsi_encoder { +struct vc4_encoder base; +struct vc4_dsi *dsi; +}; +/* General DSI hardware state. */ struct vc4_dsi { -struct vc4_encoder encoder;struct mipi_dsi_host dsi_host;struct platform_device *pdev;
@@ -601,7 +610,7 @@ struct vc4_dsi { container_of_const(host, struct vc4_dsi, dsi_host)#define to_vc4_dsi (_encoder) \ - container_of_const(_encoder, struct vc4_dsi, encoder.base) + (container_of_const(_encoder, struct vc4_dsi_encoder, base.base)->dsi)#define bridge_to_vc4_dsi (_bridge) \ container_of_const(_bridge, struct vc4_dsi, bridge)
@@ -1626,7 +1635,8 @@ static int vc4_dsi_bind(struct device *dev, struct device *master, void *data)struct platform_device *pdev =to_platform_device (dev);struct drm_device *drm =dev_get_drvdata (master);struct vc4_dsi *dsi =dev_get_drvdata (dev); -struct drm_encoder *encoder = &dsi->encoder.base; +struct vc4_dsi_encoder *dsi_encoder; +struct drm_encoder *encoder;int ret;drm_bridge_get (&dsi->bridge);
@@ -1637,9 +1647,6 @@ static int vc4_dsi_bind(struct device *dev, struct device *master, void *data) dsi->variant =of_device_get_match_data (dev); - dsi->encoder.type = dsi->variant->port ? -VC4_ENCODER_TYPE_DSI1 :VC4_ENCODER_TYPE_DSI0 ; - dsi->regs =vc4_ioremap_regs (pdev,0 );if (IS_ERR (dsi->regs))return PTR_ERR (dsi->regs);
@@ -1758,12 +1765,16 @@ static int vc4_dsi_bind(struct device *dev, struct device *master, void *data)if (ret)return ret; - ret =drmm_encoder_init (drm, encoder, - &vc4_dsi_encoder_funcs, -DRM_MODE_ENCODER_DSI , -NULL ); -if (ret) -return ret; + dsi_encoder = drmm_encoder_alloc(drm, struct vc4_dsi_encoder, base.base, + &vc4_dsi_encoder_funcs, +DRM_MODE_ENCODER_DSI ,NULL ); +if (IS_ERR (dsi_encoder)) +return PTR_ERR (dsi_encoder); + + dsi_encoder->dsi = dsi; + dsi_encoder->base.type = dsi->variant->port ? +VC4_ENCODER_TYPE_DSI1 :VC4_ENCODER_TYPE_DSI0 ; + encoder = &dsi_encoder->base.base; ret =devm_pm_runtime_enable (dev);if (ret)
base-commit: 467ac0b56aebc804360f276feffbc9032c265a6e
Signature · 1 line
2.47.3
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce: - [Critical] drm/vc4: dsi: unmanaged OF clock…
Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce:
- [Critical] drm/vc4: dsi: unmanaged OF clock provider in vc4_dsi_init_phy_clocks() [1]
--
commit 809765ced535c89f7b7aa0f22cdfc9aa61cc56b3
Author: Henry Zhang <[email protected]>
drm/vc4: dsi: Allocate the encoder per DRM device
This commit moves the VC4 DSI encoder out of struct vc4_dsi into a DRM-managed struct vc4_dsi_encoder allocated in vc4_dsi_bind() so that re-binding the DSI component while an older DRM device is still open does not reuse or corrupt the old encoder.
Quoted 4 lines
drivers/gpu/drm/vc4/vc4_dsi.c +0
-0
[ ... ]
Quoted 13 lines
drivers/gpu/drm/vc4/vc4_dsi.c +3
-6@@ -1758,12 +1765,16 @@ static int vc4_dsi_bind(struct device *dev, struct device *master, void *data)if (ret)return ret; - ret =drmm_encoder_init (drm, encoder, - &vc4_dsi_encoder_funcs, -DRM_MODE_ENCODER_DSI , -NULL ); -if (ret) -return ret; + dsi_encoder = drmm_encoder_alloc(drm, struct vc4_dsi_encoder, base.base, + &vc4_dsi_encoder_funcs, +DRM_MODE_ENCODER_DSI ,NULL );
drivers/gpu/drm/vc4/vc4_dsi.c static int vc4_dsi_bind(struct device *dev, struct device *master, void *data) · line 1780
Quoted 10 lines
drivers/gpu/drm/vc4/vc4_dsi.c +7
-0+if (IS_ERR (dsi_encoder)) +return PTR_ERR (dsi_encoder); + + dsi_encoder->dsi = dsi; + dsi_encoder->base.type = dsi->variant->port ? +VC4_ENCODER_TYPE_DSI1 :VC4_ENCODER_TYPE_DSI0 ; + encoder = &dsi_encoder->base.base; ret =devm_pm_runtime_enable (dev);if (ret)
[Severity: Critical]
This problem wasn't introduced by this patch, but does vc4_dsi_init_phy_clocks() just above this hunk leave a dangling OF clock provider behind [1] when vc4_dsi_bind() later fails or the component is unbound?
drivers/gpu/drm/vc4/vc4_dsi.c:vc4_dsi_init_phy_clocks() {
dsi->clk_onecell = devm_kzalloc(dev, ...);
...
return of_clk_add_hw_provider(dev->of_node,
of_clk_hw_onecell_get,
dsi->clk_onecell);
}Because vc4_dsi_init_phy_clocks() registers the provider with the unmanaged of_clk_add_hw_provider() instead of devm_of_clk_add_hw_provider(), unbinding the component (or failing later in vc4_dsi_bind(), such as when drm_bridge_attach() returns -EBUSY) frees the devres-managed dsi->clk_onecell while the provider stays on of_clk_providers, causing a use-after-free in of_clk_hw_onecell_get() on subsequent clock lookups.
[1] https://sashiko.dev/#/bug/linux-4c5f4ec7-e4cd-4631-aa06-37e8551cebec
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 5 lines · On Tue, Nov 17, 2026 at 1:14 PM <[email protected]> wrote:
[Severity: Critical]
This problem wasn't introduced by this patch, but doesvc4_dsi_init_phy_clocks()just above this hunk leave a dangling OF clock provider behind [1] whenvc4_dsi_bind()later fails or the component is unbound?
Thanks. This is pre-existing and independent of this patch; I sent a
separate fix:
[PATCH] drm/vc4: dsi: Register the PHY clock provider with devm
https://lore.kernel.org/all/[email protected]/
It confirms the stale provider after unbind and after a failed bind at runtime; the use-after-free lookup itself was not reproduced on my Pi 4, since no clock lookup on the DSI node happened in the tests.
Maxime Ripard
maintainerQuoted 2 lines · Henry Zhang
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.
Quoted 6 lines
but it is initialised with
drmm_encoder_init()and so is only cleaned up when the DRM device is released. The DRM device can outlive the unbind of the vc4 components: unloading the DSI panel driver detaches from the DSI host, which deletes the DSI component and unbinds the whole vc4 DRM device, but a compositor that keeps the DRM device open keeps it alive.
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.
Also, generally speaking, unloading panel drivers is unsupported at this point. It's a work in progress, but requires more changes to be safe.
Quoted 11 lines
If the panel driver is loaded again before that, the new DRM device binds the DSI component and calls
drmm_encoder_init()on the encoder that is still on the old DRM device's encoder list. The old device's release later cleans it up from under the new one. On a Raspberry Pi 4 with a 6.18-based kernel, closing the old DRM device then gave:WARNING: drivers/gpu/drm/drm_encoder.c:214 at drmm_encoder_alloc_release+0x30/0x40 [drm] Call trace: drmm_encoder_alloc_release <- drm_dev_put <- drm_gem_dmabuf_release <- __fput Unable to handle kernel NULL pointer dereference at virtual address 0000000000000008 pc : drm_mode_config_cleanup+0x5c/0x2f0 [drm] Call trace: drm_mode_config_cleanup <- drm_managed_release <- drm_dev_put
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.
Maxime
Quoted 4 lines · Maxime Ripard
Quoted 2 lines · Henry Zhang
The DSI encoder is embedded in struct
vc4_dsi, which lives as long as the DSI platform device
Quoted 8 lines
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.
Quoted 2 lines
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").
Quoted 2 lines
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.
Quoted 2 lines
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
Maíra Canal
reviewerHi Henry,
Quoted 14 lines · Henry Zhang
The DSI encoder is embedded in struct
vc4_dsi, which lives as long as the DSI platform device, but it is initialised withdrmm_encoder_init()and so is only cleaned up when the DRM device is released. The DRM device can outlive the unbind of the vc4 components: unloading the DSI panel driver detaches from the DSI host, which deletes the DSI component and unbinds the whole vc4 DRM device, but a compositor that keeps the DRM device open keeps it alive.If the panel driver is loaded again before that, the new DRM device binds the DSI component and calls
drmm_encoder_init()on the encoder that is still on the old DRM device's encoder list. The old device's release later cleans it up from under the new one. On a Raspberry Pi 4 with a 6.18-based kernel, closing the old DRM device then gave:
Quoted 5 lines
WARNING: drivers/gpu/drm/drm_encoder.c:214 at drmm_encoder_alloc_release+0x30/0x40 [drm] Call trace: drmm_encoder_alloc_release <- drm_dev_put <- drm_gem_dmabuf_release <- __fput Unable to handle kernel NULL pointer dereference at virtual address 0000000000000008 pc : drm_mode_config_cleanup+0x5c/0x2f0 [drm] Call trace: drm_mode_config_cleanup <- drm_managed_release <- drm_dev_put
Could you reproduce this issue on top of drm-misc-next? The downstream kernel differs from upstream in several ways. If you are able to reproduce it, could you please provide the full call trace?
Best regards,
- Maíra
Quoted 137 lines
Allocate the encoder in bind with
drmm_encoder_alloc(), so each DRM device has its own and releases only its own. The DSI bridge is still
shared: while the old DRM device holds it,drm_bridge_attach()in the new bind fails with-EBUSY, so binding again before the old DRM device is released now fails cleanly instead of corrupting both devices.The analysis, this change and this description were prepared with the help of an AI coding assistant (Claude Code).
Fixes 6f0ca506c30e ("drm/vc4: dsi: Switch to DRM-managed encoder initialization")Signed-off-by Henry Zhang <[email protected]>---
Testing:- On this base (drm-misc-next
467ac0b56aeb): compile-tested only, arm64 defconfig with DRM_VC4=m, W=1, no new warnings.- A backport to a downstream Raspberry Pi 6.18.34 kernel, on a Raspberry Pi 4 with an out-of-tree modular DSI panel driver: with the compositor stopped and a process holding
/dev/dri/card1open, unload the panel driver and load it again. The bind now fails cleanly:vc4-drm gpu: failed to bind fe700000.dsi (ops
vc4_dsi_ops[vc4]): -16 vc4-drm gpu: adev bind failed: -16the panel probe fails with -16, and there is no warning or oops, also when the holder then closes the old DRM device. Unloading and loading the panel driver again after that brings back the display and the compositor. Without the change, the same kernel gave the warning and oops above. The backport differs from this patch in two
ways: that kernel still gets the panel bridge withdrmm_of_get_bridge(), which has a use-after-free of its own in this sequence, so the test kernel useddevm_drm_of_get_bridge()instead (not needed here, where the panel bridge is refcounted); and a downstream DSI restart worker that used the embedded encoder now follows a pointer to the current one.The
-EBUSYis final: the panel probe is not retried when the old DRM device goes away, so the panel driver has to be loaded again. Would you prefer the DSI host to wait for the old DRM device to be released before adding its component again, or a bridge allocated per bind?Not addressed: a connector probe that is already running when the panel is removed can still call into the panel driver.
This applies to drm-misc-next on its own. It also applies on top of my "drm/vc4: dsi: Serialize register writes through the DMA workaround", and it does not touch the code changed by my vc4 DSI series <[email protected]>.
Tools: Claude Code (an AI coding assistant) analysed the crash logs and the vc4/DRM lifetimes, located the introducing commit, wrote the change and this description, built and checkpatch-checked it, and ran the backport test on the board, at my request.
drivers/gpu/drm/vc4/vc4_dsi.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-)drivers/gpu/drm/vc4/vc4_dsi.c +23
-12@@ -546,9 +546,18 @@ struct vc4_dsi_variant { }; +/* +* The encoder of one DRM device. The DRM device can outlive the unbind of +* this component, so a later bind must not reuse the encoder of an earlier +* one: allocate one per bind, managed by the DRM device. +*/ +struct vc4_dsi_encoder { +struct vc4_encoder base; +struct vc4_dsi *dsi; +}; +/* General DSI hardware state. */ struct vc4_dsi { -struct vc4_encoder encoder;struct mipi_dsi_host dsi_host;struct platform_device *pdev;@@ -601,7 +610,7 @@ struct vc4_dsi { container_of_const(host, struct vc4_dsi, dsi_host)#define to_vc4_dsi (_encoder) \ - container_of_const(_encoder, struct vc4_dsi, encoder.base) + (container_of_const(_encoder, struct vc4_dsi_encoder, base.base)->dsi)#define bridge_to_vc4_dsi (_bridge) \ container_of_const(_bridge, struct vc4_dsi, bridge)@@ -1626,7 +1635,8 @@ static int vc4_dsi_bind(struct device *dev, struct device *master, void *data)struct platform_device *pdev =to_platform_device (dev);struct drm_device *drm =dev_get_drvdata (master);struct vc4_dsi *dsi =dev_get_drvdata (dev); -struct drm_encoder *encoder = &dsi->encoder.base; +struct vc4_dsi_encoder *dsi_encoder; +struct drm_encoder *encoder;int ret;drm_bridge_get (&dsi->bridge);@@ -1637,9 +1647,6 @@ static int vc4_dsi_bind(struct device *dev, struct device *master, void *data) dsi->variant =of_device_get_match_data (dev); - dsi->encoder.type = dsi->variant->port ? -VC4_ENCODER_TYPE_DSI1 :VC4_ENCODER_TYPE_DSI0 ; - dsi->regs =vc4_ioremap_regs (pdev,0 );if (IS_ERR (dsi->regs))return PTR_ERR (dsi->regs);@@ -1758,12 +1765,16 @@ static int vc4_dsi_bind(struct device *dev, struct device *master, void *data)if (ret)return ret; - ret =drmm_encoder_init (drm, encoder, - &vc4_dsi_encoder_funcs, -DRM_MODE_ENCODER_DSI , -NULL ); -if (ret) -return ret; + dsi_encoder = drmm_encoder_alloc(drm, struct vc4_dsi_encoder, base.base, + &vc4_dsi_encoder_funcs, +DRM_MODE_ENCODER_DSI ,NULL ); +if (IS_ERR (dsi_encoder)) +return PTR_ERR (dsi_encoder); + + dsi_encoder->dsi = dsi; + dsi_encoder->base.type = dsi->variant->port ? +VC4_ENCODER_TYPE_DSI1 :VC4_ENCODER_TYPE_DSI0 ; + encoder = &dsi_encoder->base.base; ret =devm_pm_runtime_enable (dev);if (ret)base-commit:
467ac0b56aebc804360f276feffbc9032c265a6e