All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel@ffwll.ch>
To: Dave Airlie <airlied@gmail.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 1/8] sync_file: add type/flags to sync file object creation.
Date: Tue, 4 Apr 2017 09:08:57 +0200	[thread overview]
Message-ID: <20170404070857.wbpvd6tl6axkswxk@phenom.ffwll.local> (raw)
In-Reply-To: <20170404042733.17203-2-airlied@gmail.com>

On Tue, Apr 04, 2017 at 02:27:26PM +1000, Dave Airlie wrote:
> From: Dave Airlie <airlied@redhat.com>
> 
> This allows us to create sync files with different semantics,
> and clearly define the interoperation between them it also
> provides flags to allow for tweaks on those semantics.
> 
> This provides a validation interface for drivers that accept
> types from userspace so they can return EINVAL instead of ENOMEM.
> 
> This provides an ioctl for userspace to retrieve the type/flags
> of an object it may recieve from somewhere else.
> 
> Signed-off-by: Dave Airlie <airlied@redhat.com>

Since you've bothered to type the docs for the ioctl structs too, please
squash in the below (and double-check that kernel-doc is still happy):


diff --git a/Documentation/driver-api/dma-buf.rst b/Documentation/driver-api/dma-buf.rst
index 31671b469627..375848c590ce 100644
--- a/Documentation/driver-api/dma-buf.rst
+++ b/Documentation/driver-api/dma-buf.rst
@@ -163,3 +163,8 @@ DMA Fence uABI/Sync File
 .. kernel-doc:: include/linux/sync_file.h
    :internal:
 
+Sync File IOCTL Definitions
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+.. kernel-doc:: include/uapi/linux/sync_file.h
+   :internal:


With that: Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>

One open question: Do we expect the current sync_file_get_fence to only
ever work for a FENCE type sync_file? Might be good to clarify that in the
kernel-doc for sync_file_get_fence().
-Daniel



> ---
>  drivers/dma-buf/sw_sync.c      |  2 +-
>  drivers/dma-buf/sync_file.c    | 62 +++++++++++++++++++++++++++++++++++++++---
>  drivers/gpu/drm/drm_atomic.c   |  2 +-
>  include/linux/sync_file.h      |  9 +++++-
>  include/uapi/linux/sync_file.h | 27 ++++++++++++++++++
>  5 files changed, 95 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/dma-buf/sw_sync.c b/drivers/dma-buf/sw_sync.c
> index 69c5ff3..1c47de6 100644
> --- a/drivers/dma-buf/sw_sync.c
> +++ b/drivers/dma-buf/sw_sync.c
> @@ -315,7 +315,7 @@ static long sw_sync_ioctl_create_fence(struct sync_timeline *obj,
>  		goto err;
>  	}
>  
> -	sync_file = sync_file_create(&pt->base);
> +	sync_file = sync_file_create(&pt->base, SYNC_FILE_TYPE_FENCE, 0);
>  	dma_fence_put(&pt->base);
>  	if (!sync_file) {
>  		err = -ENOMEM;
> diff --git a/drivers/dma-buf/sync_file.c b/drivers/dma-buf/sync_file.c
> index 2321035..b33af9d 100644
> --- a/drivers/dma-buf/sync_file.c
> +++ b/drivers/dma-buf/sync_file.c
> @@ -28,9 +28,32 @@
>  
>  static const struct file_operations sync_file_fops;
>  
> -static struct sync_file *sync_file_alloc(void)
> +/**
> + * sync_file_validate_type_flags - validate type/flags for support
> + * @type: type of sync file object
> + * @flags: flags to sync object.
> + *
> + * Validates the flags are correct so userspace can get a more
> + * detailed error type.
> + */
> +int sync_file_validate_type_flags(uint32_t type, uint32_t flags)
> +{
> +	if (flags)
> +		return -EINVAL;
> +	if (type != SYNC_FILE_TYPE_FENCE)
> +		return -EINVAL;
> +	return 0;
> +}
> +EXPORT_SYMBOL(sync_file_validate_type_flags);
> +
> +static struct sync_file *sync_file_alloc(uint32_t type, uint32_t flags)
>  {
>  	struct sync_file *sync_file;
> +	int ret;
> +
> +	ret = sync_file_validate_type_flags(type, flags);
> +	if (ret)
> +		return NULL;
>  
>  	sync_file = kzalloc(sizeof(*sync_file), GFP_KERNEL);
>  	if (!sync_file)
> @@ -47,6 +70,8 @@ static struct sync_file *sync_file_alloc(void)
>  
>  	INIT_LIST_HEAD(&sync_file->cb.node);
>  
> +	sync_file->type = type;
> +	sync_file->flags = flags;
>  	return sync_file;
>  
>  err:
> @@ -72,11 +97,13 @@ static void fence_check_cb_func(struct dma_fence *f, struct dma_fence_cb *cb)
>   * sync_file can be released with fput(sync_file->file). Returns the
>   * sync_file or NULL in case of error.
>   */
> -struct sync_file *sync_file_create(struct dma_fence *fence)
> +struct sync_file *sync_file_create(struct dma_fence *fence,
> +				   uint32_t type,
> +				   uint32_t flags)
>  {
>  	struct sync_file *sync_file;
>  
> -	sync_file = sync_file_alloc();
> +	sync_file = sync_file_alloc(type, flags);
>  	if (!sync_file)
>  		return NULL;
>  
> @@ -200,7 +227,10 @@ static struct sync_file *sync_file_merge(const char *name, struct sync_file *a,
>  	struct dma_fence **fences, **nfences, **a_fences, **b_fences;
>  	int i, i_a, i_b, num_fences, a_num_fences, b_num_fences;
>  
> -	sync_file = sync_file_alloc();
> +	if (a->type != b->type)
> +		return NULL;
> +
> +	sync_file = sync_file_alloc(a->type, a->flags);
>  	if (!sync_file)
>  		return NULL;
>  
> @@ -437,6 +467,27 @@ static long sync_file_ioctl_fence_info(struct sync_file *sync_file,
>  	return ret;
>  }
>  
> +static long sync_file_ioctl_type(struct sync_file *sync_file,
> +				 unsigned long arg)
> +{
> +	struct sync_file_type type;
> +	int ret;
> +	if (copy_from_user(&type, (void __user *)arg, sizeof(type)))
> +		return -EFAULT;
> +
> +	if (type.flags || type.type)
> +		return -EINVAL;
> +
> +	type.type = sync_file->type;
> +	type.flags = sync_file->flags;
> +
> +	if (copy_to_user((void __user *)arg, &type, sizeof(type)))
> +		ret = -EFAULT;
> +	else
> +		ret = 0;
> +	return ret;
> +}
> +
>  static long sync_file_ioctl(struct file *file, unsigned int cmd,
>  			    unsigned long arg)
>  {
> @@ -449,6 +500,9 @@ static long sync_file_ioctl(struct file *file, unsigned int cmd,
>  	case SYNC_IOC_FILE_INFO:
>  		return sync_file_ioctl_fence_info(sync_file, arg);
>  
> +	case SYNC_IOC_TYPE:
> +		return sync_file_ioctl_type(sync_file, arg);
> +
>  	default:
>  		return -ENOTTY;
>  	}
> diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
> index a567310..bb5a740 100644
> --- a/drivers/gpu/drm/drm_atomic.c
> +++ b/drivers/gpu/drm/drm_atomic.c
> @@ -1917,7 +1917,7 @@ static int setup_out_fence(struct drm_out_fence_state *fence_state,
>  	if (put_user(fence_state->fd, fence_state->out_fence_ptr))
>  		return -EFAULT;
>  
> -	fence_state->sync_file = sync_file_create(fence);
> +	fence_state->sync_file = sync_file_create(fence, SYNC_FILE_TYPE_FENCE, 0);
>  	if (!fence_state->sync_file)
>  		return -ENOMEM;
>  
> diff --git a/include/linux/sync_file.h b/include/linux/sync_file.h
> index 3e3ab84..ede4182 100644
> --- a/include/linux/sync_file.h
> +++ b/include/linux/sync_file.h
> @@ -20,6 +20,8 @@
>  #include <linux/spinlock.h>
>  #include <linux/dma-fence.h>
>  #include <linux/dma-fence-array.h>
> +#include <uapi/linux/sync_file.h>
> +
>  
>  /**
>   * struct sync_file - sync file to export to the userspace
> @@ -30,6 +32,8 @@
>   * @wq:			wait queue for fence signaling
>   * @fence:		fence with the fences in the sync_file
>   * @cb:			fence callback information
> + * @type:               sync file type
> + * @flags:              flags used to create sync file
>   */
>  struct sync_file {
>  	struct file		*file;
> @@ -43,11 +47,14 @@ struct sync_file {
>  
>  	struct dma_fence	*fence;
>  	struct dma_fence_cb cb;
> +	uint32_t type;
> +	uint32_t flags;
>  };
>  
>  #define POLL_ENABLED DMA_FENCE_FLAG_USER_BITS
>  
> -struct sync_file *sync_file_create(struct dma_fence *fence);
> +int sync_file_validate_type_flags(uint32_t type, uint32_t flags);
> +struct sync_file *sync_file_create(struct dma_fence *fence, uint32_t type, uint32_t flags);
>  struct dma_fence *sync_file_get_fence(int fd);
>  
>  #endif /* _LINUX_SYNC_H */
> diff --git a/include/uapi/linux/sync_file.h b/include/uapi/linux/sync_file.h
> index 5b287d6..f439cda 100644
> --- a/include/uapi/linux/sync_file.h
> +++ b/include/uapi/linux/sync_file.h
> @@ -69,6 +69,26 @@ struct sync_file_info {
>  #define SYNC_IOC_MAGIC		'>'
>  
>  /**
> + * DOC: SYNC_FILE_TYPE_FENCE - fence sync file object
> + *
> + * This sync file is a wrapper around a dma fence or a dma fence array.
> + * It can be merged with another fence sync file object to create a new
> + * merged object.
> + * The fence backing this object cannot be replaced.
> + * This is useful for shared fences.
> + */
> +#define SYNC_FILE_TYPE_FENCE 0
> +
> +/**
> + * struct sync_file_type - data returned from sync file type ioctl
> + * @type:	sync_file type
> + * @flags:	sync_file creation flags
> + */
> +struct sync_file_type {
> +	__u32	type;
> +	__u32	flags;
> +};
> +/**
>   * Opcodes  0, 1 and 2 were burned during a API change to avoid users of the
>   * old API to get weird errors when trying to handling sync_files. The API
>   * change happened during the de-stage of the Sync Framework when there was
> @@ -94,4 +114,11 @@ struct sync_file_info {
>   */
>  #define SYNC_IOC_FILE_INFO	_IOWR(SYNC_IOC_MAGIC, 4, struct sync_file_info)
>  
> +/**
> + * DOC: SYNC_IOC_TYPE - get creation type and flags of sync_file.
> + *
> + * Takes a struct sync_file_type. Returns the created values of type and flags.
> + */
> +#define SYNC_IOC_TYPE		_IOWR(SYNC_IOC_MAGIC, 5, struct sync_file_type)
> +
>  #endif /* _UAPI_LINUX_SYNC_H */
> -- 
> 2.9.3
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2017-04-04  7:09 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-04  4:27 [RFC] DRM synchronisation objects Dave Airlie
2017-04-04  4:27 ` [PATCH 1/8] sync_file: add type/flags to sync file object creation Dave Airlie
2017-04-04  7:08   ` Daniel Vetter [this message]
2017-04-04  4:27 ` [PATCH 2/8] sync_file: export some interfaces needed by drm sync objects Dave Airlie
2017-04-04  7:10   ` Daniel Vetter
2017-04-04  4:27 ` [PATCH 3/8] drm: introduce sync objects as sync file objects with no fd Dave Airlie
2017-04-04  7:42   ` Daniel Vetter
     [not found]     ` <CAPM=9tyj6k4hqJWrwDW8Ch+TZCOoXRuAK2g71ciUm5vxpwmkuw@mail.gmail.com>
     [not found]       ` <CAKMK7uFoFvsREVtSxsoOeM6OPDM-iGOATtcAK6p65LzG39D6oQ@mail.gmail.com>
2017-04-11  6:00         ` Daniel Vetter
2017-04-04  4:27 ` [PATCH 4/8] sync_file: add a mutex to protect fence and callback members. (v4) Dave Airlie
2017-04-04  7:52   ` Daniel Vetter
2017-04-04  8:07   ` Christian König
2017-04-11  2:57     ` Dave Airlie
2017-04-04  4:27 ` [PATCH 5/8] sync_file: add support for a semaphore object Dave Airlie
2017-04-04  7:59   ` Daniel Vetter
2017-04-04 11:52   ` Chris Wilson
2017-04-04 11:59     ` Chris Wilson
2017-04-04  4:27 ` [PATCH 6/8] drm/syncobj: add semaphore support helpers Dave Airlie
2017-04-04  8:07   ` Daniel Vetter
2017-04-04  4:27 ` [PATCH 7/8] amdgpu/cs: split out fence dependency checking Dave Airlie
2017-04-04  7:37   ` Christian König
2017-04-04  4:27 ` [PATCH 8/8] amdgpu: use sync file for shared semaphores (v2) Dave Airlie
2017-04-04  7:40   ` Christian König
2017-04-04  8:10     ` Daniel Vetter
2017-04-04 11:05       ` Christian König
2017-04-11  3:18         ` Dave Airlie
2017-04-11  6:55           ` Christian König
2017-04-04  4:35 ` [RFC] DRM synchronisation objects Dave Airlie
2017-04-04  8:02 ` Christian König
2017-04-04  8:11 ` Daniel Vetter
2017-04-11  3:22 [repost] drm sync objects cleaned up Dave Airlie
2017-04-11  3:22 ` [PATCH 1/8] sync_file: add type/flags to sync file object creation Dave Airlie
2017-04-12  4:57 drm sync objects (vn+1) Dave Airlie
     [not found] ` <20170412045726.13689-1-airlied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-04-12  4:57   ` [PATCH 1/8] sync_file: add type/flags to sync file object creation Dave Airlie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170404070857.wbpvd6tl6axkswxk@phenom.ffwll.local \
    --to=daniel@ffwll.ch \
    --cc=airlied@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.