Skip to content

Commit cfb9b89

Browse files
pq-collaboraevelikov
authored andcommitted
drm/doc: device hot-unplug for userspace
Set up the expectations on how hot-unplugging a DRM device should look like to userspace. Written by Daniel Vetter's request and largely based on his comments in IRC and from https://lists.freedesktop.org/archives/dri-devel/2020-May/265484.html . A related Wayland protocol change proposal is at https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/35 Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch> Reviewed-by: Alex Deucher <alexander.deucher@amd.com> Acked-by: Noralf Trønnes <noralf@tronnes.org> Cc: Andrey Grodzovsky <andrey.grodzovsky@amd.com> Cc: Dave Airlie <airlied@redhat.com> Cc: Sean Paul <sean@poorly.run> Cc: Simon Ser <contact@emersion.fr> Cc: Ben Skeggs <skeggsb@gmail.com> Cc: Karol Herbst <kherbst@redhat.com> Acked-by: Simon Ser <contact@emersion.fr> Signed-off-by: Emil Velikov <emil.velikov@collabora.com> Link: https://patchwork.freedesktop.org/patch/msgid/20200707113805.30936-1-ppaalanen@gmail.com
1 parent 85b3bfa commit cfb9b89

1 file changed

Lines changed: 113 additions & 1 deletion

File tree

‎Documentation/gpu/drm-uapi.rst‎

Lines changed: 113 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. Copyright 2020 DisplayLink (UK) Ltd.
2+
13
===================
24
Userland interfaces
35
===================
@@ -162,6 +164,116 @@ other hand, a driver requires shared state between clients which is
162164
visible to user-space and accessible beyond open-file boundaries, they
163165
cannot support render nodes.
164166

167+
Device Hot-Unplug
168+
=================
169+
170+
.. note::
171+
The following is the plan. Implementation is not there yet
172+
(2020 May).
173+
174+
Graphics devices (display and/or render) may be connected via USB (e.g.
175+
display adapters or docking stations) or Thunderbolt (e.g. eGPU). An end
176+
user is able to hot-unplug this kind of devices while they are being
177+
used, and expects that the very least the machine does not crash. Any
178+
damage from hot-unplugging a DRM device needs to be limited as much as
179+
possible and userspace must be given the chance to handle it if it wants
180+
to. Ideally, unplugging a DRM device still lets a desktop continue to
181+
run, but that is going to need explicit support throughout the whole
182+
graphics stack: from kernel and userspace drivers, through display
183+
servers, via window system protocols, and in applications and libraries.
184+
185+
Other scenarios that should lead to the same are: unrecoverable GPU
186+
crash, PCI device disappearing off the bus, or forced unbind of a driver
187+
from the physical device.
188+
189+
In other words, from userspace perspective everything needs to keep on
190+
working more or less, until userspace stops using the disappeared DRM
191+
device and closes it completely. Userspace will learn of the device
192+
disappearance from the device removed uevent, ioctls returning ENODEV
193+
(or driver-specific ioctls returning driver-specific things), or open()
194+
returning ENXIO.
195+
196+
Only after userspace has closed all relevant DRM device and dmabuf file
197+
descriptors and removed all mmaps, the DRM driver can tear down its
198+
instance for the device that no longer exists. If the same physical
199+
device somehow comes back in the mean time, it shall be a new DRM
200+
device.
201+
202+
Similar to PIDs, chardev minor numbers are not recycled immediately. A
203+
new DRM device always picks the next free minor number compared to the
204+
previous one allocated, and wraps around when minor numbers are
205+
exhausted.
206+
207+
The goal raises at least the following requirements for the kernel and
208+
drivers.
209+
210+
Requirements for KMS UAPI
211+
-------------------------
212+
213+
- KMS connectors must change their status to disconnected.
214+
215+
- Legacy modesets and pageflips, and atomic commits, both real and
216+
TEST_ONLY, and any other ioctls either fail with ENODEV or fake
217+
success.
218+
219+
- Pending non-blocking KMS operations deliver the DRM events userspace
220+
is expecting. This applies also to ioctls that faked success.
221+
222+
- open() on a device node whose underlying device has disappeared will
223+
fail with ENXIO.
224+
225+
- Attempting to create a DRM lease on a disappeared DRM device will
226+
fail with ENODEV. Existing DRM leases remain and work as listed
227+
above.
228+
229+
Requirements for Render and Cross-Device UAPI
230+
---------------------------------------------
231+
232+
- All GPU jobs that can no longer run must have their fences
233+
force-signalled to avoid inflicting hangs on userspace.
234+
The associated error code is ENODEV.
235+
236+
- Some userspace APIs already define what should happen when the device
237+
disappears (OpenGL, GL ES: `GL_KHR_robustness`_; `Vulkan`_:
238+
VK_ERROR_DEVICE_LOST; etc.). DRM drivers are free to implement this
239+
behaviour the way they see best, e.g. returning failures in
240+
driver-specific ioctls and handling those in userspace drivers, or
241+
rely on uevents, and so on.
242+
243+
- dmabuf which point to memory that has disappeared will either fail to
244+
import with ENODEV or continue to be successfully imported if it would
245+
have succeeded before the disappearance. See also about memory maps
246+
below for already imported dmabufs.
247+
248+
- Attempting to import a dmabuf to a disappeared device will either fail
249+
with ENODEV or succeed if it would have succeeded without the
250+
disappearance.
251+
252+
- open() on a device node whose underlying device has disappeared will
253+
fail with ENXIO.
254+
255+
.. _GL_KHR_robustness: https://www.khronos.org/registry/OpenGL/extensions/KHR/KHR_robustness.txt
256+
.. _Vulkan: https://www.khronos.org/vulkan/
257+
258+
Requirements for Memory Maps
259+
----------------------------
260+
261+
Memory maps have further requirements that apply to both existing maps
262+
and maps created after the device has disappeared. If the underlying
263+
memory disappears, the map is created or modified such that reads and
264+
writes will still complete successfully but the result is undefined.
265+
This applies to both userspace mmap()'d memory and memory pointed to by
266+
dmabuf which might be mapped to other devices (cross-device dmabuf
267+
imports).
268+
269+
Raising SIGBUS is not an option, because userspace cannot realistically
270+
handle it. Signal handlers are global, which makes them extremely
271+
difficult to use correctly from libraries like those that Mesa produces.
272+
Signal handlers are not composable, you can't have different handlers
273+
for GPU1 and GPU2 from different vendors, and a third handler for
274+
mmapped regular files. Threads cause additional pain with signal
275+
handling as well.
276+
165277
.. _drm_driver_ioctl:
166278

167279
IOCTL Support on Device Nodes
@@ -199,7 +311,7 @@ EPERM/EACCES:
199311
difference between EACCES and EPERM.
200312

201313
ENODEV:
202-
The device is not (yet) present or fully initialized.
314+
The device is not present anymore or is not yet fully initialized.
203315

204316
EOPNOTSUPP:
205317
Feature (like PRIME, modesetting, GEM) is not supported by the driver.

0 commit comments

Comments
 (0)