DRM lease: Handling wp_drm_lease_device_v1::drm_fd errors
The DRM lease protocol doesn't specify a way to report issues opening a non-master fd for a DRM node.
At the moment, Mutter sends a client error:
wlroots skips the device creation if it can not get the fd and sends a no-memory error if the error happens on bind: (cc @bl4ckb0ne)
- https://gitlab.freedesktop.org/wlroots/wlroots/-/blob/master/types/wlr_drm_lease_v1.c#L499
- https://gitlab.freedesktop.org/wlroots/wlroots/-/blob/master/types/wlr_drm_lease_v1.c#L629
Smithay handles it like wlroots: (cc @Drakulix)
https://github.com/Smithay/smithay/blob/master/src/wayland/drm_lease/mod.rs#L420 https://github.com/Smithay/smithay/blob/master/src/wayland/drm_lease/mod.rs#L716
And KWin sends an invalid fd? (cc @Zamundaaa)
- https://invent.kde.org/plasma/kwin/-/blob/master/src/wayland/drmlease_v1.cpp#L232
- https://invent.kde.org/plasma/kwin/-/blob/master/src/backends/drm/drm_gpu.cpp#L109
This issue was found by @daenzer: https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3832
His set up has 2 GPUs: the primary connected to a display and the secondary one not connected.
I'd like to discuss a possible solution for this issue. I think that the protocol (or at least my interpretation of the protocol) covers this case:
The compositor will advertise one wp_drm_lease_device_v1 global for each DRM node. Some time after a client binds to the wp_drm_lease_device_v1 global, the compositor will send a drm_fd event [...] although there are no guarantees as to how long this takes - the compositor might need to wait until regaining DRM master
In my opinion, in a setup with 2 GPUs, this should fix the issue while following the protocol:
- A client connects. The compositor advertises 2 wp_drm_lease_device_v1 globals.
- The client binds to the first one without errors. The compositor sends drm_fd and the connectors.
- The client binds to the second wp_drm_lease_device_v1 global.
- The compositor fails to get a non-master DRM fd. No error is notified at this point.
- A connector is connected to the second wp_drm_lease_device_v1. The compositor tries to get a non-master DRM fd again:
- On success, it sends the drm_fd and the connectors.
- On error, it repeats steps 4 and 5 until it succeeds.
Does this look like a possible solution for you?