Repository navigation
drm/rp1: dsi: Use a new DRM device for each DSI attach - #7772
Open
henryzhang62 wants to merge 1 commit into
Open
henryzhang62 wants to merge 1 commit into
henryzhang62 wants to merge 1 commit into
Conversation
The DRM device is allocated once, at platform probe, and set up again on every DSI host attach, but detach only unregisters it: nothing that the attach set up is cleaned up, and the device is never released, also not on remove. When the DSI panel driver is unloaded and loaded again, the second attach runs drmm_mode_config_init() and drm_simple_display_pipe_init() again on the same, still populated device, and then fails because the DSI bridge is still attached from the first attach: drm-rp1-dsi 1f00118000.dsi: rp1dsi_bind returned -16 The display then stays unusable until a reboot, and the reused device is left partly set up a second time. Give each attach its own DRM device, with the display pipe embedded in it, and its own DSI bridge, and undo the attach on detach: unplug and shut down the DRM device, stop the hardware, stop the interrupt handler from using the DRM device, turn off the CFG clock, remove the bridges and drop the reference to the DRM device. The DRM device, and the bridges attached to it, are released when its last user closes it, which can be after the next attach. A failed attach is undone the same way. Create the panel bridge with drm_panel_bridge_add() and remove it on detach, while the panel still exists, instead of using drmm_of_get_bridge(), whose release on the final put of the DRM device uses the panel after it has gone. The per-platform-device state no longer points at a DRM device: the DMA and DSI code logs with the platform device, and the interrupt handler uses the DRM device of the current attach, which detach clears and then waits for with synchronize_irq(). The CFG clock is now disabled once for each enable; before, it was disabled on unbind, on release of the DRM device and on shutdown. Signed-off-by: Henry Zhang <henryzhang62@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On a Pi 5, unloading a modular DSI panel driver and loading it again
leaves the DSI display dead until a reboot:
drm-rp1-dsi allocates its DRM device once, at platform probe, and sets it
up again on every DSI host attach, but detach only unregisters it. The
second attach re-runs drmm_mode_config_init() and
drm_simple_display_pipe_init() on the same, still populated device, and
drm_bridge_attach() of the DSI bridge, still attached from the first
attach, returns -EBUSY (the TODO in rp1dsi_host_detach() points at the
same gap). In the same lifetime: the DRM device is never released, also
not on remove; the DSI bridge is drm_bridge_add()ed on each attach and
never removed; drmm_of_get_bridge() releases the panel bridge on the
final put of the DRM device, after the panel has gone; the CFG clock is
disabled from unbind, DRM release and shutdown but enabled once; and
unbind stops the hardware before drm_atomic_helper_shutdown().
This gives each attach its own DRM device (pipe embedded) and DSI
bridge, undoes the attach on detach (unplug, atomic shutdown, stop,
clear the IRQ handler's pointer + synchronize_irq(), clock off, remove
the bridges, put), and unwinds a failed attach the same way. A DRM
device that is still open after detach stays valid until it is closed,
and a new attach works meanwhile.
Testing
Pi 5, packaged 6.18.50-1+rpt1 kernel (its rp1-dsi sources are identical
to rpi-6.18.y), this driver built out of tree, an out-of-tree modular
DSI panel driver:
"rp1dsi_bind returned -16"; the display only comes back after a reboot.
once, the panel attaches again, the desktop comes back;
dumb buffer: the attach succeeds while it is held (as card3), the
holder's ioctls get -ENODEV,
rmmod drm_rp1_dsiis refused while itis held, closing it releases the old device;
test-only module parameter, not part of this PR), then a retry: no
DRM device and no bridge left in the global bridge list after each
failure, each retry attaches;
device is created again and attaches;
the desktop, 50 with the desktop checked each time (desktop and
panel back every time).
The final build (without the test parameter) was re-checked with the
held-file case and 20 reload cycles.
While the old DRM device is held, the new connector is named DSI-3
instead of DSI-1 (the downstream DT-alias connector naming logs "Failed
to acquire type ID 1 for interface type DSI, ret -28"); it is DSI-1
again once the old device is released.
Memory
Unreclaimable slab grows by about 16 KB per reload (100 reloads without
the desktop: +1.6 MB, kmalloc-1k +773 objects). An ftrace of 1 KiB
kmalloc/kfree over 5 reloads left 46 objects unfreed: 40 are uevent
skbs from udev-worker queued on the uevent netlink socket of
gvfs-udisks2-volume-monitor, which does not read it (7.7 MB queued); the
other 6 belong to the instance loaded at the end. Those skbs should be
freed when the socket is read or closed, which was not checked. Other
slab sizes were not traced, so this does not rule out other leaks;
kmalloc-4k and kmalloc-8k (where a leaked DRM device would show) did not
grow.
Not tested
and still takes no reference to the bridge);
open (by inspection nothing uses the per-platform-device state after
the unplug);
Questions
keep one device and only rebuild the KMS state?
branch; do you want a Fixes: tag?
The analysis, the change and this description were prepared with the
help of an AI coding assistant (Claude Code).