<div dir="ltr">Yes, I believe this is the proper way for sync_file and syncobj to interact.  Again, I can't really review for all of the kernel details (though the seem ok to me) so this mostly applies to the API:<br><br>Reviewed-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 24, 2017 at 12:06 AM, Dave Airlie <span dir="ltr"><<a href="mailto:airlied@gmail.com" target="_blank">airlied@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">From: Dave Airlie <<a href="mailto:airlied@redhat.com">airlied@redhat.com</a>><br>
<br>
This interface allows importing the fence from a sync_file into<br>
an existing drm sync object, or exporting the fence attached to<br>
an existing drm sync object into a new sync file object.<br>
<br>
This should only be used to interact with sync files where necessary.<br>
<br>
Reviewed-by: Sean Paul <<a href="mailto:seanpaul@chromium.org">seanpaul@chromium.org</a>><br>
Signed-off-by: Dave Airlie <<a href="mailto:airlied@redhat.com">airlied@redhat.com</a>><br>
---<br>
 drivers/gpu/drm/drm_syncobj.c | 64 ++++++++++++++++++++++++++++++<wbr>+++++++++++--<br>
 include/uapi/drm/drm.h        |  2 ++<br>
 2 files changed, 64 insertions(+), 2 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/drm_syncobj.<wbr>c b/drivers/gpu/drm/drm_syncobj.<wbr>c<br>
index 8b87594..54d751e 100644<br>
--- a/drivers/gpu/drm/drm_syncobj.<wbr>c<br>
+++ b/drivers/gpu/drm/drm_syncobj.<wbr>c<br>
@@ -50,6 +50,7 @@<br>
 #include <linux/file.h><br>
 #include <linux/fs.h><br>
 #include <linux/anon_inodes.h><br>
+#include <linux/sync_file.h><br>
<br>
 #include "drm_internal.h"<br>
 #include <drm/drm_syncobj.h><br>
@@ -276,6 +277,48 @@ static int drm_syncobj_fd_to_handle(<wbr>struct drm_file *file_private,<br>
        return 0;<br>
 }<br>
<br>
+int drm_syncobj_import_sync_file_<wbr>fence(struct drm_file *file_private,<br>
+                                      int fd, int handle)<br>
+{<br>
+       struct dma_fence *fence = sync_file_get_fence(fd);<br>
+       if (!fence)<br>
+               return -EINVAL;<br>
+<br>
+       return drm_syncobj_replace_fence(<wbr>file_private, handle, fence);<br>
+}<br>
+<br>
+int drm_syncobj_export_sync_file(<wbr>struct drm_file *file_private,<br>
+                                int handle, int *p_fd)<br>
+{<br>
+       int ret;<br>
+       struct dma_fence *fence;<br>
+       struct sync_file *sync_file;<br>
+       int fd = get_unused_fd_flags(O_CLOEXEC)<wbr>;<br>
+<br>
+       if (fd < 0)<br>
+               return fd;<br>
+<br>
+       ret = drm_syncobj_fence_get(file_<wbr>private, handle, &fence);<br>
+       if (ret)<br>
+               goto err_put_fd;<br>
+<br>
+       sync_file = sync_file_create(fence);<br>
+       if (!sync_file) {<br>
+               ret = -EINVAL;<br>
+               goto err_fence_put;<br>
+       }<br>
+<br>
+       fd_install(fd, sync_file->file);<br>
+<br>
+       dma_fence_put(fence);<br>
+       *p_fd = fd;<br>
+       return 0;<br>
+err_fence_put:<br>
+       dma_fence_put(fence);<br>
+err_put_fd:<br>
+       put_unused_fd(fd);<br>
+       return ret;<br>
+}<br>
 /**<br>
  * drm_syncobj_open - initalizes syncobj file-private structures at devnode open time<br>
  * @dev: drm_device which is being opened by userspace<br>
@@ -358,9 +401,17 @@ drm_syncobj_handle_to_fd_<wbr>ioctl(struct drm_device *dev, void *data,<br>
        if (!drm_core_check_feature(dev, DRIVER_SYNCOBJ))<br>
                return -ENODEV;<br>
<br>
-       if (args->pad || args->flags)<br>
+       if (args->pad)<br>
+               return -EINVAL;<br>
+<br>
+       if (args->flags != 0 &&<br>
+           args->flags != DRM_SYNCOBJ_HANDLE_TO_FD_<wbr>FLAGS_EXPORT_FENCE_SYNC_FILE)<br>
                return -EINVAL;<br>
<br>
+       if (args->flags & DRM_SYNCOBJ_HANDLE_TO_FD_<wbr>FLAGS_EXPORT_FENCE_SYNC_FILE)<br>
+               return drm_syncobj_export_sync_file(<wbr>file_private, args->handle,<br>
+                                                   &args->fd);<br>
+<br>
        return drm_syncobj_handle_to_fd(file_<wbr>private, args->handle,<br>
                                        &args->fd);<br>
 }<br>
@@ -374,9 +425,18 @@ drm_syncobj_fd_to_handle_<wbr>ioctl(struct drm_device *dev, void *data,<br>
        if (!drm_core_check_feature(dev, DRIVER_SYNCOBJ))<br>
                return -ENODEV;<br>
<br>
-       if (args->pad || args->flags)<br>
+       if (args->pad)<br>
                return -EINVAL;<br>
<br>
+       if (args->flags != 0 &&<br>
+           args->flags != DRM_SYNCOBJ_FD_TO_HANDLE_<wbr>FLAGS_IMPORT_SYNC_FILE_FENCE)<br>
+               return -EINVAL;<br>
+<br>
+       if (args->flags & DRM_SYNCOBJ_FD_TO_HANDLE_<wbr>FLAGS_IMPORT_SYNC_FILE_FENCE)<br>
+               return drm_syncobj_import_sync_file_<wbr>fence(file_private,<br>
+                                                         args->fd,<br>
+                                                         args->handle);<br>
+<br>
        return drm_syncobj_fd_to_handle(file_<wbr>private, args->fd,<br>
                                        &args->handle);<br>
 }<br>
diff --git a/include/uapi/drm/drm.h b/include/uapi/drm/drm.h<br>
index d6e2f62..94c75be 100644<br>
--- a/include/uapi/drm/drm.h<br>
+++ b/include/uapi/drm/drm.h<br>
@@ -708,6 +708,8 @@ struct drm_syncobj_destroy {<br>
        __u32 pad;<br>
 };<br>
<br>
+#define DRM_SYNCOBJ_FD_TO_HANDLE_<wbr>FLAGS_IMPORT_SYNC_FILE_FENCE (1 << 0)<br>
+#define DRM_SYNCOBJ_HANDLE_TO_FD_<wbr>FLAGS_EXPORT_FENCE_SYNC_FILE (1 << 0)<br>
 struct drm_syncobj_handle {<br>
        __u32 handle;<br>
        __u32 flags;<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.9.4<br>
<br>
______________________________<wbr>_________________<br>
dri-devel mailing list<br>
<a href="mailto:dri-devel@lists.freedesktop.org">dri-devel@lists.freedesktop.<wbr>org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/dri-devel" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/dri-devel</a><br>
</font></span></blockquote></div><br></div>