Skip to contentSkip to conversation

drm/syncobj: add DRM_IOCTL_SYNCOBJ_IMPORT/EXPORT_SYNC_FILE

PATCH Superseded Erik Kurzinger 3 participants 3 messages Jul 21, 2023

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 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/e6f5c81bf893010411f1b471d68bb493ed36af67
libdrm: https://gitlab.freedesktop.org/ekurzinger/drm/-/commit/22180768f85f1cce36ff34bbef34956b8803d6aa

V1 -> V2:
fixed conflict with DRM_IOCTL_MODE_GETFB2 re-ordered arguments of drm_syncobj_import_sync_file_fence

---
 drivers/gpu/drm/drm_internal.h |  4 +++
 drivers/gpu/drm/drm_ioctl.c    |  4 +++
 drivers/gpu/drm/drm_syncobj.c  | 62 ++++++++++++++++++++++++++++++----
 include/uapi/drm/drm.h         |  8 +++++
 4 files changed, 71 insertions(+), 7 deletions(-)
drivers/gpu/drm/drm_internal.h +4 -0
index ba12acd55139..903731937595 100644
@@ -255,6 +255,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
index f03ffbacfe9b..92d6da811afd 100644
@@ -711,6 +711,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 +55 -7

109 lines not on this page · raw message

include/uapi/drm/drm.h +8 -0
index 863e47200911..3a00eaa7cc33 100644
@@ -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 */
@@ -1191,6 +1197,8 @@ extern "C" {
 #define DRM_IOCTL_MODE_GETFB2		DRM_IOWR(0xCE, struct drm_mode_fb_cmd2)
 
 #define DRM_IOCTL_SYNCOBJ_EVENTFD	DRM_IOWR(0xCF, struct drm_syncobj_eventfd)
+#define DRM_IOCTL_SYNCOBJ_IMPORT_SYNC_FILE	DRM_IOWR(0xD0, struct drm_syncobj_sync_file)
+#define DRM_IOCTL_SYNCOBJ_EXPORT_SYNC_FILE	DRM_IOWR(0xD1, struct drm_syncobj_sync_file)
 
 /*
  * Device specific ioctls should only be in their respective headers
Signature · 1 line
2.41.0
#2 lore raw
In reply to Erik Kurzinger
kernel test robot noticed the following build errors:

Hi Erik,

kernel test robot noticed the following build errors:

[auto build test ERROR on drm-misc/drm-misc-next]
[also build test ERROR on drm-tip/drm-tip next-20230721]
[cannot apply to drm/drm-next drm-exynos/exynos-drm-next drm-intel/for-linux-next drm-intel/for-linux-next-fixes linus/master v6.5-rc2] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Erik-Kurzinger/drm-syncobj-add-DRM_IOCTL_SYNCOBJ_IMPORT-EXPORT_SYNC_FILE/20230722-003446
base:   git://anongit.freedesktop.org/drm/drm-misc drm-misc-next
patch link:    https://lore.kernel.org/r/a09e38a6-5ac3-75c1-eadd-38a265e0ae33%40nvidia.com
patch subject: [PATCH v2] drm/syncobj: add DRM_IOCTL_SYNCOBJ_IMPORT/EXPORT_SYNC_FILE
config: alpha-allyesconfig (https://download.01.org/0day-ci/archive/20230722/[email protected]/config)
compiler: alpha-linux-gcc (GCC) 12.3.0
reproduce: (https://download.01.org/0day-ci/archive/20230722/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

drivers/gpu/drm/drm_syncobj.c: In function 'drm_syncobj_fd_to_handle_ioctl':

>> drivers/gpu/drm/drm_syncobj.c:922:71: error: expected ')' before numeric constant
     922 |                                                           args->handle
         |                                                                       ^
         |                                                                       )
     923 |                                                           0 /* binary */);
         |                                                           ~            
   drivers/gpu/drm/drm_syncobj.c:920:58: note: to match this '('
     920 |                 return drm_syncobj_import_sync_file_fence(file_private,
         |                                                          ^
>> drivers/gpu/drm/drm_syncobj.c:920:24: error: too few arguments to function 'drm_syncobj_import_sync_file_fence'

920 | return drm_syncobj_import_sync_file_fence(file_private,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/gpu/drm/drm_syncobj.c:745:12: note: declared here
745 | static int drm_syncobj_import_sync_file_fence(struct drm_file *file_private,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

vim +922 drivers/gpu/drm/drm_syncobj.c

902
903 int
904 drm_syncobj_fd_to_handle_ioctl(struct drm_device *dev, void *data,
905 struct drm_file *file_private)
906 {
907 struct drm_syncobj_handle *args = data;
908
909 if (!drm_core_check_feature(dev, DRIVER_SYNCOBJ))
910 return -EOPNOTSUPP;
911
912 if (args->pad)
913 return -EINVAL;
914
915 if (args->flags != 0 &&
916 args->flags != DRM_SYNCOBJ_FD_TO_HANDLE_FLAGS_IMPORT_SYNC_FILE)
917 return -EINVAL;
918
919 if (args->flags & DRM_SYNCOBJ_FD_TO_HANDLE_FLAGS_IMPORT_SYNC_FILE)

 > 920			return drm_syncobj_import_sync_file_fence(file_private,
   921								  args->fd,
 > 922								  args->handle
   923								  0 /* binary */);

924
925 return drm_syncobj_fd_to_handle(file_private, args->fd,
926 &args->handle);
927 }
928

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki