[PATCH 3/5] drm/syncobj: add sync_file interaction.

Chris Wilson chris at chris-wilson.co.uk
Thu May 25 08:54:21 UTC 2017


On Wed, May 24, 2017 at 05:06:13PM +1000, Dave Airlie wrote:
> From: Dave Airlie <airlied at redhat.com>
> 
> This interface allows importing the fence from a sync_file into
> an existing drm sync object, or exporting the fence attached to
> an existing drm sync object into a new sync file object.
> 
> This should only be used to interact with sync files where necessary.
> 
> Reviewed-by: Sean Paul <seanpaul at chromium.org>
> Signed-off-by: Dave Airlie <airlied at redhat.com>
> ---
>  drivers/gpu/drm/drm_syncobj.c | 64 +++++++++++++++++++++++++++++++++++++++++--
>  include/uapi/drm/drm.h        |  2 ++
>  2 files changed, 64 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c
> index 8b87594..54d751e 100644
> --- a/drivers/gpu/drm/drm_syncobj.c
> +++ b/drivers/gpu/drm/drm_syncobj.c
> @@ -50,6 +50,7 @@
>  #include <linux/file.h>
>  #include <linux/fs.h>
>  #include <linux/anon_inodes.h>
> +#include <linux/sync_file.h>
>  
>  #include "drm_internal.h"
>  #include <drm/drm_syncobj.h>
> @@ -276,6 +277,48 @@ static int drm_syncobj_fd_to_handle(struct drm_file *file_private,
>  	return 0;
>  }
>  
> +int drm_syncobj_import_sync_file_fence(struct drm_file *file_private,
> +				       int fd, int handle)
> +{
> +	struct dma_fence *fence = sync_file_get_fence(fd);
> +	if (!fence)
> +		return -EINVAL;
> +
> +	return drm_syncobj_replace_fence(file_private, handle, fence);

Didn't replace_fence() acquire its own reference to fence, and so we
need to drop our reference afterwards?

> +}
> +
> +int drm_syncobj_export_sync_file(struct drm_file *file_private,
> +				 int handle, int *p_fd)
> +{
> +	int ret;
> +	struct dma_fence *fence;
> +	struct sync_file *sync_file;
> +	int fd = get_unused_fd_flags(O_CLOEXEC);
> +
> +	if (fd < 0)
> +		return fd;
> +
> +	ret = drm_syncobj_fence_get(file_private, handle, &fence);
> +	if (ret)
> +		goto err_put_fd;
> +
> +	sync_file = sync_file_create(fence);

Could move dma_fence_put() here and so drop the err_fence_put.

> +	if (!sync_file) {
> +		ret = -EINVAL;
> +		goto err_fence_put;
> +	}
> +
> +	fd_install(fd, sync_file->file);
> +
> +	dma_fence_put(fence);
> +	*p_fd = fd;
> +	return 0;
> +err_fence_put:
> +	dma_fence_put(fence);
> +err_put_fd:
> +	put_unused_fd(fd);
> +	return ret;
> +}
>  /**
>   * drm_syncobj_open - initalizes syncobj file-private structures at devnode open time
>   * @dev: drm_device which is being opened by userspace
> @@ -358,9 +401,17 @@ drm_syncobj_handle_to_fd_ioctl(struct drm_device *dev, void *data,
>  	if (!drm_core_check_feature(dev, DRIVER_SYNCOBJ))
>  		return -ENODEV;
>  
> -	if (args->pad || args->flags)
> +	if (args->pad)
> +		return -EINVAL;
> +
> +	if (args->flags != 0 &&
> +	    args->flags != DRM_SYNCOBJ_HANDLE_TO_FD_FLAGS_EXPORT_FENCE_SYNC_FILE)
>  		return -EINVAL;

DRM_SYNCOBJ_HANDLE_TO_FD_FLAGS_EXPORT_AS_SYNC_FILE ?

I'm sure if the addition of FENCE makes it any clearer in the
import/export names. The conversion of import is syncobj -> sync_file
and vice versa.
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre


More information about the dri-devel mailing list