diff options
author | Simon Ser <contact@emersion.fr> | 2021-01-21 11:11:38 +0100 |
---|---|---|
committer | Emil Velikov <emil.l.velikov@gmail.com> | 2021-02-26 13:01:04 +0000 |
commit | 632f59fcbfc790a7546ceeac30c480b66901404c (patch) | |
tree | 5ef0925fa5176e0f10a2aa1e0b7e27e8443fe5be /xf86drm.h | |
parent | 523b3658aa8efa746417e916c987de23740ce313 (diff) |
xf86drm: warn about GEM handle reference counting
Users need to be careful when using drmPrimeHandleToFD or
drmPrimeFDToHandle directly. Mention GBM as a solution.
See [1] for an example mistake.
[1]: https://gitlab.freedesktop.org/drm/nouveau/-/issues/43#note_772661
Signed-off-by: Simon Ser <contact@emersion.fr>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Diffstat (limited to 'xf86drm.h')
-rw-r--r-- | xf86drm.h | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -813,6 +813,24 @@ extern char *drmGetDeviceNameFromFd(int fd); extern char *drmGetDeviceNameFromFd2(int fd); extern int drmGetNodeTypeFromFd(int fd); +/* Convert between GEM handles and DMA-BUF file descriptors. + * + * Warning: since GEM handles are not reference-counted and are unique per + * DRM file description, the caller is expected to perform its own reference + * counting. drmPrimeFDToHandle is guaranteed to return the same handle for + * different FDs if they reference the same underlying buffer object. This + * could even be a buffer object originally created on the same DRM FD. + * + * When sharing a DRM FD with an API such as EGL or GBM, the caller must not + * use drmPrimeHandleToFD nor drmPrimeFDToHandle. A single user-space + * reference-counting implementation is necessary to avoid double-closing GEM + * handles. + * + * Two processes can't share the same DRM FD and both use it to create or + * import GEM handles, even when using a single user-space reference-counting + * implementation like GBM, because GBM doesn't share its state between + * processes. + */ extern int drmPrimeHandleToFD(int fd, uint32_t handle, uint32_t flags, int *prime_fd); extern int drmPrimeFDToHandle(int fd, int prime_fd, uint32_t *handle); |