Skip to content

drm/rp1: dsi: Use a new DRM device for each DSI attach - #7772

Open
henryzhang62 wants to merge 1 commit into
raspberrypi:rpi-6.18.yfrom
henryzhang62:rp1-dsi-new-drm-device-per-attach
Open

henryzhang62 wants to merge 1 commit into
raspberrypi:rpi-6.18.yfrom
henryzhang62:rp1-dsi-new-drm-device-per-attach

Conversation

@henryzhang62

@henryzhang62 henryzhang62 commented Nov 18, 2026 •

Copy link
Copy Markdown

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 1f00118000.dsi: rp1dsi_bind returned -16

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:

  • Without the change: unload/load of the panel driver gives
    "rp1dsi_bind returned -16"; the display only comes back after a reboot.
  • With it, no kernel warnings in any of:
    • unload/load with no DRM file open: the old DRM device is released at
      once, the panel attaches again, the desktop comes back;
    • the same with a process holding the old card open with an mmapped
      dumb buffer: the attach succeeds while it is held (as card3), the
      holder's ioctls get -ENODEV, rmmod drm_rp1_dsi is refused while it
      is held, closing it releases the old device;
    • an attach failure forced after each of 7 steps of the attach (with a
      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;
    • rmmod/modprobe of drm-rp1-dsi with nothing attached: the panel
      device is created again and attaches;
    • 200 unload/load cycles restarting the desktop each time, 100 without
      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

  • a downstream bridge chip instead of a panel (that path is unchanged
    and still takes no reference to the bridge);
  • unbinding the platform device through sysfs while an old DRM device is
    open (by inspection nothing uses the per-platform-device state after
    the unplug);
  • a kernel with KASAN or kmemleak.

Questions

  • Is a new DRM device per attach acceptable here, or would you rather
    keep one device and only rebuild the KMS state?
  • The driver was added by "drm: Add RP1 DSI driver" on this rebased
    branch; do you want a Fixes: tag?
  • Should this also go to rpi-6.12.y?

The analysis, the change and this description were prepared with the
help of an AI coding assistant (Claude Code).

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant