drm/syncobj: add DRM_IOCTL_SYNCOBJ_IMPORT/EXPORT_SYNC_FILE
Subsystems (2)
PATCH 1/1 drm/syncobj: add DRM_IOCTL_SYNCOBJ_IMPORT/EXPORT_SYNC_FILE
These new ioctls perform a task similar to DRM_IOCTL_SYNCOBJ_HANDLE_TO_FD/FD_TO_HANDLE with the IMPORT/EXPORT_SYNC_FILE flag set, except that they allow specifying the timeline point to import or export the fence to or from on a timeline syncobj.
This eliminates the need to use a temporary binary syncobj along with DRM_IOCTL_SYNCOBJ_TRANSFER to achieve such a thing, which is the technique userspace has had to employ up to this point. While that does work, it is rather awkward from the programmer's perspective. Since DRM syncobjs have been proposed as the basis for display server explicit synchronization protocols, e.g. [1] and [2], providing a more streamlined interface now seems worthwhile.
[1] https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/90
[2] https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/967
Accompanying userspace patches...
IGT: https://gitlab.freedesktop.org/ekurzinger/igt-gpu-tools/-/commit/241e7f379aeaa9b22a32277e77ad4011c8717a57
libdrm: https://gitlab.freedesktop.org/ekurzinger/drm/-/commit/b3961a592fc6f8b05f7e3a12413fb58eca2dbfa2
--- drivers/gpu/drm/drm_internal.h | 4 +++ drivers/gpu/drm/drm_ioctl.c | 4 +++ drivers/gpu/drm/drm_syncobj.c | 60 ++++++++++++++++++++++++++++++---- include/uapi/drm/drm.h | 9 +++++ 4 files changed, 71 insertions(+), 6 deletions(-)
drivers/gpu/drm/drm_internal.h +4 -0
@@ -253,6 +253,10 @@ int drm_syncobj_timeline_signal_ioctl(struct drm_device *dev, void *data, struct drm_file *file_private);int drm_syncobj_query_ioctl (struct drm_device *dev,void *data,struct drm_file *file_private); +int drm_syncobj_import_sync_file_ioctl (struct drm_device *dev,void *data, +struct drm_file *file_private); +int drm_syncobj_export_sync_file_ioctl (struct drm_device *dev,void *data, +struct drm_file *file_private);/* drm_framebuffer.c */ void drm_framebuffer_print_info(struct drm_printer *p, unsigned int indent,
drivers/gpu/drm/drm_ioctl.c +4 -0
@@ -710,6 +710,10 @@ static const struct drm_ioctl_desc drm_ioctls[] = { DRM_RENDER_ALLOW),DRM_IOCTL_DEF (DRM_IOCTL_SYNCOBJ_QUERY , drm_syncobj_query_ioctl,DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF (DRM_IOCTL_SYNCOBJ_IMPORT_SYNC_FILE , drm_syncobj_import_sync_file_ioctl, +DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF (DRM_IOCTL_SYNCOBJ_EXPORT_SYNC_FILE , drm_syncobj_export_sync_file_ioctl, +DRM_RENDER_ALLOW ),DRM_IOCTL_DEF (DRM_IOCTL_CRTC_GET_SEQUENCE , drm_crtc_get_sequence_ioctl,0 ),DRM_IOCTL_DEF (DRM_IOCTL_CRTC_QUEUE_SEQUENCE , drm_crtc_queue_sequence_ioctl,0 ), DRM_IOCTL_DEF(DRM_IOCTL_MODE_CREATE_LEASE, drm_mode_create_lease_ioctl, DRM_MASTER),
drivers/gpu/drm/drm_syncobj.c +54 -6
107 lines not on this page · raw message
include/uapi/drm/drm.h +9 -0
@@ -884,6 +884,12 @@ struct drm_syncobj_transfer {__u32 pad; }; +struct drm_syncobj_sync_file { +__u32 handle; +__u32 fd; +__u64 point; +}; +#define DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL (1 << 0)#define DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT (1 << 1)#define DRM_SYNCOBJ_WAIT_FLAGS_WAIT_AVAILABLE (1 << 2)/* wait for time point to become available */
@@ -1139,6 +1145,9 @@ extern "C" {#define DRM_IOCTL_SYNCOBJ_TRANSFER DRM_IOWR(0xCC, struct drm_syncobj_transfer)#define DRM_IOCTL_SYNCOBJ_TIMELINE_SIGNAL DRM_IOWR(0xCD, struct drm_syncobj_timeline_array) +#define DRM_IOCTL_SYNCOBJ_IMPORT_SYNC_FILE DRM_IOWR(0xCE, struct drm_syncobj_sync_file) +#define DRM_IOCTL_SYNCOBJ_EXPORT_SYNC_FILE DRM_IOWR(0xCF, struct drm_syncobj_sync_file) +/** * DRM_IOCTL_MODE_GETFB2 - Get framebuffer metadata. *
Signature · 1 line
2.41.0
Quoted 6 lines · Erik Kurzinger
These new ioctls perform a task similar to DRM_IOCTL_SYNCOBJ_HANDLE_TO_FD/FD_TO_HANDLE with the IMPORT/EXPORT_SYNC_FILE flag set, except that they allow specifying the timeline point to import or export the fence to or from on a timeline syncobj.
Quoted 7 lines
This eliminates the need to use a temporary binary syncobj along with
DRM_IOCTL_SYNCOBJ_TRANSFERto achieve such a thing, which is the technique userspace has had to employ up to this point. While that does work, it is rather awkward from the programmer's perspective. Since DRM syncobjs have been proposed as the basis for display server explicit synchronization protocols, e.g. [1] and [2], providing a more streamlined interface now seems worthwhile.
This looks like a good idea to me! The patch looks good as well, apart from one tricky issue, see below...
Quoted 6 lines
[1] https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/90
[2] https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/967Accompanying userspace patches...
IGT: https://gitlab.freedesktop.org/ekurzinger/igt-gpu-tools/-/commit/241e7f379aeaa9b22a32277e77ad4011c8717a57
libdrm: https://gitlab.freedesktop.org/ekurzinger/drm/-/commit/b3961a592fc6f8b05f7e3a12413fb58eca2dbfa2
(Unfortunately this isn't enough when it comes to user-space patches: the kernel rules require a "real" user of the new IOCTL, not just a libdr IOCTL wrapper. I will post a patch to make use of this from wlroots if that helps.)
Quoted 57 lines
Signed-off-by Erik Kurzinger <[email protected]>--- drivers/gpu/drm/drm_internal.h | 4 +++ drivers/gpu/drm/drm_ioctl.c | 4 +++ drivers/gpu/drm/drm_syncobj.c | 60 ++++++++++++++++++++++++++++++---- include/uapi/drm/drm.h | 9 +++++ 4 files changed, 71 insertions(+), 6 deletions(-)drivers/gpu/drm/drm_internal.h +4
-0@@ -253,6 +253,10 @@ int drm_syncobj_timeline_signal_ioctl(struct drm_device *dev, void *data, struct drm_file *file_private);int drm_syncobj_query_ioctl (struct drm_device *dev,void *data,struct drm_file *file_private); +int drm_syncobj_import_sync_file_ioctl (struct drm_device *dev,void *data, +struct drm_file *file_private); +int drm_syncobj_export_sync_file_ioctl (struct drm_device *dev,void *data, +struct drm_file *file_private);/* drm_framebuffer.c */ void drm_framebuffer_print_info(struct drm_printer *p, unsigned int indent,drivers/gpu/drm/drm_ioctl.c +4
-0@@ -710,6 +710,10 @@ static const struct drm_ioctl_desc drm_ioctls[] = { DRM_RENDER_ALLOW),DRM_IOCTL_DEF (DRM_IOCTL_SYNCOBJ_QUERY , drm_syncobj_query_ioctl,DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF (DRM_IOCTL_SYNCOBJ_IMPORT_SYNC_FILE , drm_syncobj_import_sync_file_ioctl, +DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF (DRM_IOCTL_SYNCOBJ_EXPORT_SYNC_FILE , drm_syncobj_export_sync_file_ioctl, +DRM_RENDER_ALLOW ),DRM_IOCTL_DEF (DRM_IOCTL_CRTC_GET_SEQUENCE , drm_crtc_get_sequence_ioctl,0 ),DRM_IOCTL_DEF (DRM_IOCTL_CRTC_QUEUE_SEQUENCE , drm_crtc_queue_sequence_ioctl,0 ), DRM_IOCTL_DEF(DRM_IOCTL_MODE_CREATE_LEASE, drm_mode_create_lease_ioctl, DRM_MASTER),drivers/gpu/drm/drm_syncobj.c +7
-0@@ -181,6 +181,13 @@* Note that if you want to transfer a struct &dma_fence_chain from a given * point on a timeline syncobj from/into a binary syncobj, you can use the * point 0 to mean take/replace the fence in the syncobj. +* +* &DRM_IOCTL_SYNCOBJ_IMPORT_SYNC_FILE and &DRM_IOCTL_SYNCOBJ_EXPORT_SYNC_FILE +* let the client import or export the struct &dma_fence_chain of a syncobj +* at a particular timeline point from or to a sync file. +* These behave similarly to &DRM_SYNCOBJ_FD_TO_HANDLE_FLAGS_IMPORT_SYNC_FILE +* and &DRM_SYNCOBJ_HANDLE_TO_FD_FLAGS_EXPORT_SYNC_FILE described above, except +* that they accommodate timeline syncobjs in addition to binary syncobjs. */ #include <linux/anon_inodes.h>
drivers/gpu/drm/drm_syncobj.c static int drm_syncobj_fd_to_handle(struct drm_file *file_private, · line 692
Quoted 5 lines
drivers/gpu/drm/drm_syncobj.c +1
-1@@ -682,10 +689,11 @@ static int drm_syncobj_fd_to_handle(struct drm_file *file_private, }static int drm_syncobj_import_sync_file_fence (struct drm_file *file_private, -int fd,int handle) +int fd,u64 point,int handle)
Nit: can we specify the point after the handle, for consistency with drm_syncobj_export_sync_file()? It's pretty easy to mix up these two arguments.
Quoted 112 lines
drivers/gpu/drm/drm_syncobj.c +46
-5{struct dma_fence *fence =sync_file_get_fence (fd);struct drm_syncobj *syncobj; +int ret =0 ;if (!fence)return -EINVAL ;@@ -696,14 +704,23 @@ static int drm_syncobj_import_sync_file_fence(struct drm_file *file_private,return -ENOENT ; } -drm_syncobj_replace_fence (syncobj, fence); +if (point ==0 ) { +drm_syncobj_replace_fence (syncobj, fence); + }else { +struct dma_fence_chain *chain =dma_fence_chain_alloc (); +if (chain) { +drm_syncobj_add_point (syncobj, chain, fence, point); + }else { + ret = -ENOMEM ; + } + }dma_fence_put (fence);drm_syncobj_put (syncobj); -return 0 ; +return ret; }static int drm_syncobj_export_sync_file (struct drm_file *file_private, -int handle,int *p_fd) +int handle,u64 point,int *p_fd) {int ret;struct dma_fence *fence;@@ -713,7 +730,7 @@ static int drm_syncobj_export_sync_file(struct drm_file *file_private,if (fd <0 )return fd; - ret =drm_syncobj_find_fence (file_private, handle,0 ,0 , &fence); + ret =drm_syncobj_find_fence (file_private, handle, point,0 , &fence);if (ret) goto err_put_fd;@@ -823,7 +840,7 @@ drm_syncobj_handle_to_fd_ioctl(struct drm_device *dev, void *data,if (args->flags &DRM_SYNCOBJ_HANDLE_TO_FD_FLAGS_EXPORT_SYNC_FILE )return drm_syncobj_export_sync_file (file_private, args->handle, - &args->fd); +0 /* binary */ , &args->fd);return drm_syncobj_handle_to_fd (file_private, args->handle, &args->fd);@@ -848,6 +865,7 @@ drm_syncobj_fd_to_handle_ioctl(struct drm_device *dev, void *data,if (args->flags &DRM_SYNCOBJ_FD_TO_HANDLE_FLAGS_IMPORT_SYNC_FILE )return drm_syncobj_import_sync_file_fence (file_private, args->fd, +0 /* binary */ , args->handle); return drm_syncobj_fd_to_handle(file_private, args->fd,@@ -1515,3 +1533,33 @@ int drm_syncobj_query_ioctl(struct drm_device *dev, void *data,return ret; } + +int drm_syncobj_import_sync_file_ioctl (struct drm_device *dev,void *data, +struct drm_file *file_private) +{ +struct drm_syncobj_sync_file *args = data; + +if (!drm_core_check_feature (dev, args->point ==0 ? +DRIVER_SYNCOBJ : +DRIVER_SYNCOBJ_TIMELINE )) +return -EOPNOTSUPP ; + +return drm_syncobj_import_sync_file_fence (file_private, + args->fd, + args->point, + args->handle); +} + +int drm_syncobj_export_sync_file_ioctl (struct drm_device *dev,void *data, +struct drm_file *file_private) +{ +struct drm_syncobj_sync_file *args = data; + +if (!drm_core_check_feature (dev, args->point ==0 ? +DRIVER_SYNCOBJ : +DRIVER_SYNCOBJ_TIMELINE )) +return -EOPNOTSUPP ; + +return drm_syncobj_export_sync_file (file_private, args->handle, + args->point, &args->fd); +}include/uapi/drm/drm.h +6
-0@@ -884,6 +884,12 @@ struct drm_syncobj_transfer {__u32 pad; }; +struct drm_syncobj_sync_file { +__u32 handle; +__u32 fd; +__u64 point; +}; +#define DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL (1 << 0)#define DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT (1 << 1)#define DRM_SYNCOBJ_WAIT_FLAGS_WAIT_AVAILABLE (1 << 2)/* wait for time point to become available */
include/uapi/drm/drm.h extern "C" { · line 1149
Quoted 5 lines
include/uapi/drm/drm.h +2
-0@@ -1139,6 +1145,9 @@ extern "C" {#define DRM_IOCTL_SYNCOBJ_TRANSFER DRM_IOWR(0xCC, struct drm_syncobj_transfer)#define DRM_IOCTL_SYNCOBJ_TIMELINE_SIGNAL DRM_IOWR(0xCD, struct drm_syncobj_timeline_array) +#define DRM_IOCTL_SYNCOBJ_IMPORT_SYNC_FILE DRM_IOWR(0xCE, struct drm_syncobj_sync_file) +#define DRM_IOCTL_SYNCOBJ_EXPORT_SYNC_FILE DRM_IOWR(0xCF, struct drm_syncobj_sync_file)
So, there is a footgun here, one that I hit myself with before: 0xCE is already used by DRM_IOCTL_MODE_GETFB2. And there is no check whatsoever about conflicting IOCTL numbers. The only reason I noticed is that I got some pretty weird behavior when trying to detect for the IOCTL availability in IGT, and someone from AMD noticed some GETFB2 IGT test breakage when trying my patches.
Quoted 5 lines
include/uapi/drm/drm.h +0
-1/** * DRM_IOCTL_MODE_GETFB2 - Get framebuffer metadata. * -- 2.41.0
Quoted 22 lines · Simon Ser
Quoted 6 lines · Erik Kurzinger
These new ioctls perform a task similar to DRM_IOCTL_SYNCOBJ_HANDLE_TO_FD/FD_TO_HANDLE with the IMPORT/EXPORT_SYNC_FILE flag set, except that they allow specifying the timeline point to import or export the fence to or from on a timeline syncobj.
Quoted 7 lines
This eliminates the need to use a temporary binary syncobj along with
DRM_IOCTL_SYNCOBJ_TRANSFERto achieve such a thing, which is the technique userspace has had to employ up to this point. While that does work, it is rather awkward from the programmer's perspective. Since DRM syncobjs have been proposed as the basis for display server explicit synchronization protocols, e.g. [1] and [2], providing a more streamlined interface now seems worthwhile.This looks like a good idea to me! The patch looks good as well, apart from one tricky issue, see below...
Quoted 8 lines
Quoted 3 lines
Accompanying userspace patches...
IGT: https://gitlab.freedesktop.org/ekurzinger/igt-gpu-tools/-/commit/241e7f379aeaa9b22a32277e77ad4011c8717a57
libdrm: https://gitlab.freedesktop.org/ekurzinger/drm/-/commit/b3961a592fc6f8b05f7e3a12413fb58eca2dbfa2(Unfortunately this isn't enough when it comes to user-space patches: the kernel rules require a "real" user of the new IOCTL, not just a libdr IOCTL wrapper. I will post a patch to make use of this from wlroots if that helps.)
Thanks for taking a look, Simon. If that's the case I could also update my Xwayland MR to use the new functions.
Quoted 195 lines
Quoted 57 lines
Signed-off-by Erik Kurzinger <[email protected]>--- drivers/gpu/drm/drm_internal.h | 4 +++ drivers/gpu/drm/drm_ioctl.c | 4 +++ drivers/gpu/drm/drm_syncobj.c | 60 ++++++++++++++++++++++++++++++---- include/uapi/drm/drm.h | 9 +++++ 4 files changed, 71 insertions(+), 6 deletions(-)drivers/gpu/drm/drm_internal.h +4
-0@@ -253,6 +253,10 @@ int drm_syncobj_timeline_signal_ioctl(struct drm_device *dev, void *data, struct drm_file *file_private);int drm_syncobj_query_ioctl (struct drm_device *dev,void *data,struct drm_file *file_private); +int drm_syncobj_import_sync_file_ioctl (struct drm_device *dev,void *data, +struct drm_file *file_private); +int drm_syncobj_export_sync_file_ioctl (struct drm_device *dev,void *data, +struct drm_file *file_private);/* drm_framebuffer.c */ void drm_framebuffer_print_info(struct drm_printer *p, unsigned int indent,drivers/gpu/drm/drm_ioctl.c +4
-0@@ -710,6 +710,10 @@ static const struct drm_ioctl_desc drm_ioctls[] = { DRM_RENDER_ALLOW),DRM_IOCTL_DEF (DRM_IOCTL_SYNCOBJ_QUERY , drm_syncobj_query_ioctl,DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF (DRM_IOCTL_SYNCOBJ_IMPORT_SYNC_FILE , drm_syncobj_import_sync_file_ioctl, +DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF (DRM_IOCTL_SYNCOBJ_EXPORT_SYNC_FILE , drm_syncobj_export_sync_file_ioctl, +DRM_RENDER_ALLOW ),DRM_IOCTL_DEF (DRM_IOCTL_CRTC_GET_SEQUENCE , drm_crtc_get_sequence_ioctl,0 ),DRM_IOCTL_DEF (DRM_IOCTL_CRTC_QUEUE_SEQUENCE , drm_crtc_queue_sequence_ioctl,0 ), DRM_IOCTL_DEF(DRM_IOCTL_MODE_CREATE_LEASE, drm_mode_create_lease_ioctl, DRM_MASTER),drivers/gpu/drm/drm_syncobj.c +7
-0@@ -181,6 +181,13 @@* Note that if you want to transfer a struct &dma_fence_chain from a given * point on a timeline syncobj from/into a binary syncobj, you can use the * point 0 to mean take/replace the fence in the syncobj. +* +* &DRM_IOCTL_SYNCOBJ_IMPORT_SYNC_FILE and &DRM_IOCTL_SYNCOBJ_EXPORT_SYNC_FILE +* let the client import or export the struct &dma_fence_chain of a syncobj +* at a particular timeline point from or to a sync file. +* These behave similarly to &DRM_SYNCOBJ_FD_TO_HANDLE_FLAGS_IMPORT_SYNC_FILE +* and &DRM_SYNCOBJ_HANDLE_TO_FD_FLAGS_EXPORT_SYNC_FILE described above, except +* that they accommodate timeline syncobjs in addition to binary syncobjs. */ #include <linux/anon_inodes.h> drivers/gpu/drm/drm_syncobj.c static int drm_syncobj_fd_to_handle(struct drm_file *file_private, · line 692
Quoted 5 lines
drivers/gpu/drm/drm_syncobj.c +1
-1@@ -682,10 +689,11 @@ static int drm_syncobj_fd_to_handle(struct drm_file *file_private, }static int drm_syncobj_import_sync_file_fence (struct drm_file *file_private, -int fd,int handle) +int fd,u64 point,int handle)Nit: can we specify the point after the handle, for consistency with
drm_syncobj_export_sync_file()? It's pretty easy to mix up these two arguments.Quoted 112 lines
drivers/gpu/drm/drm_syncobj.c +46
-5{struct dma_fence *fence =sync_file_get_fence (fd);struct drm_syncobj *syncobj; +int ret =0 ;if (!fence)return -EINVAL ;@@ -696,14 +704,23 @@ static int drm_syncobj_import_sync_file_fence(struct drm_file *file_private,return -ENOENT ; } -drm_syncobj_replace_fence (syncobj, fence); +if (point ==0 ) { +drm_syncobj_replace_fence (syncobj, fence); + }else { +struct dma_fence_chain *chain =dma_fence_chain_alloc (); +if (chain) { +drm_syncobj_add_point (syncobj, chain, fence, point); + }else { + ret = -ENOMEM ; + } + }dma_fence_put (fence);drm_syncobj_put (syncobj); -return 0 ; +return ret; }static int drm_syncobj_export_sync_file (struct drm_file *file_private, -int handle,int *p_fd) +int handle,u64 point,int *p_fd) {int ret;struct dma_fence *fence;@@ -713,7 +730,7 @@ static int drm_syncobj_export_sync_file(struct drm_file *file_private,if (fd <0 )return fd; - ret =drm_syncobj_find_fence (file_private, handle,0 ,0 , &fence); + ret =drm_syncobj_find_fence (file_private, handle, point,0 , &fence);if (ret) goto err_put_fd;@@ -823,7 +840,7 @@ drm_syncobj_handle_to_fd_ioctl(struct drm_device *dev, void *data,if (args->flags &DRM_SYNCOBJ_HANDLE_TO_FD_FLAGS_EXPORT_SYNC_FILE )return drm_syncobj_export_sync_file (file_private, args->handle, - &args->fd); +0 /* binary */ , &args->fd);return drm_syncobj_handle_to_fd (file_private, args->handle, &args->fd);@@ -848,6 +865,7 @@ drm_syncobj_fd_to_handle_ioctl(struct drm_device *dev, void *data,if (args->flags &DRM_SYNCOBJ_FD_TO_HANDLE_FLAGS_IMPORT_SYNC_FILE )return drm_syncobj_import_sync_file_fence (file_private, args->fd, +0 /* binary */ , args->handle); return drm_syncobj_fd_to_handle(file_private, args->fd,@@ -1515,3 +1533,33 @@ int drm_syncobj_query_ioctl(struct drm_device *dev, void *data,return ret; } + +int drm_syncobj_import_sync_file_ioctl (struct drm_device *dev,void *data, +struct drm_file *file_private) +{ +struct drm_syncobj_sync_file *args = data; + +if (!drm_core_check_feature (dev, args->point ==0 ? +DRIVER_SYNCOBJ : +DRIVER_SYNCOBJ_TIMELINE )) +return -EOPNOTSUPP ; + +return drm_syncobj_import_sync_file_fence (file_private, + args->fd, + args->point, + args->handle); +} + +int drm_syncobj_export_sync_file_ioctl (struct drm_device *dev,void *data, +struct drm_file *file_private) +{ +struct drm_syncobj_sync_file *args = data; + +if (!drm_core_check_feature (dev, args->point ==0 ? +DRIVER_SYNCOBJ : +DRIVER_SYNCOBJ_TIMELINE )) +return -EOPNOTSUPP ; + +return drm_syncobj_export_sync_file (file_private, args->handle, + args->point, &args->fd); +}include/uapi/drm/drm.h +6
-0@@ -884,6 +884,12 @@ struct drm_syncobj_transfer {__u32 pad; }; +struct drm_syncobj_sync_file { +__u32 handle; +__u32 fd; +__u64 point; +}; +#define DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL (1 << 0)#define DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT (1 << 1)#define DRM_SYNCOBJ_WAIT_FLAGS_WAIT_AVAILABLE (1 << 2)/* wait for time point to become available */ include/uapi/drm/drm.h extern "C" { · line 1149
Quoted 5 lines
include/uapi/drm/drm.h +2
-0@@ -1139,6 +1145,9 @@ extern "C" {#define DRM_IOCTL_SYNCOBJ_TRANSFER DRM_IOWR(0xCC, struct drm_syncobj_transfer)#define DRM_IOCTL_SYNCOBJ_TIMELINE_SIGNAL DRM_IOWR(0xCD, struct drm_syncobj_timeline_array) +#define DRM_IOCTL_SYNCOBJ_IMPORT_SYNC_FILE DRM_IOWR(0xCE, struct drm_syncobj_sync_file) +#define DRM_IOCTL_SYNCOBJ_EXPORT_SYNC_FILE DRM_IOWR(0xCF, struct drm_syncobj_sync_file)So, there is a footgun here, one that I hit myself with before:
0xCEis already used byDRM_IOCTL_MODE_GETFB2. And there is no check whatsoever about conflicting IOCTL numbers. The only reason I noticed is that I got some pretty weird behavior when trying to detect for the IOCTL availability in IGT, and someone from AMD noticed some GETFB2 IGT test breakage when trying my patches.Quoted 5 lines
include/uapi/drm/drm.h +0
-1/** * DRM_IOCTL_MODE_GETFB2 - Get framebuffer metadata. * -- 2.41.0
I had a look at the IGT and I'm not sure about the approach. It seems like the patch replaces occurrences of the old FLAGS_IMPORT_SYNC_FILE and FLAGS_EXPORT_SYNC_FILE plus TRANSFER with the new IOCTLs. However we still want to test the functionality of that old codepath: we need to continue to test that the old IOCTLs work as expected.
Are the old IOCTLs still sufficiently tested elsewhere? If not, we need to either duplicate the tests, either add a flag to the test function to select between old and new.
Also, it would be good to have some basic tests for invalid cases, e.g. for the invalid zero syncobj handle, for timeline points which haven't materialized yet, etc.
I wonder if we need to detect at runtime whether the IOCTL is available. I'm not sure what the IGT requirements are, is it supposed to run on any Linux version, or does it require drm-next?
It would help to post the IGT patches on the mailing list so that we can do a proper review there.
That's a fair point. With my IGT patch I don't think we would have coverage of the old path any more. I'll try to fix that somehow, and I think your suggestion of including some "invalid" cases is also a good one.
Anyway, apart from that I've posted a v2 of the kernel patch addressing your feedback from earlier. I've also rebased it on top of drm-misc-next.
Quoted 20 lines · Simon Ser
I had a look at the IGT and I'm not sure about the approach. It seems like the patch replaces occurrences of the old
FLAGS_IMPORT_SYNC_FILEandFLAGS_EXPORT_SYNC_FILEplus TRANSFER with the new IOCTLs. However we still want to test the functionality of that old codepath: we need to continue to test that the old IOCTLs work as expected.Are the old IOCTLs still sufficiently tested elsewhere? If not, we need to either duplicate the tests, either add a flag to the test function to select between old and new.
Also, it would be good to have some basic tests for invalid cases, e.g. for the invalid zero syncobj handle, for timeline points which haven't materialized yet, etc.
I wonder if we need to detect at runtime whether the IOCTL is available. I'm not sure what the IGT requirements are, is it supposed to run on any Linux version, or does it require drm-next?
It would help to post the IGT patches on the mailing list so that we can do a proper review there.