From: Gustavo Padovan gustavo.padovan@collabora.co.uk
Hi,
This patch series clean up IOCTLs and abi of sync framework and it is a follow up on the clean up series I've sent on Jan 21:
http://thread.gmane.org/gmane.comp.video.dri.devel/145509
The main changes here are:
* remove of SYNC_WAIT ioctl, poll() should be used instead. * rename some structs and macros to better reflect the new internal names. * clean up and improve ABI on SYNC_IOC_FILE_INFO * add flags filed to all ABI structs * make sync_file_info->len return only the size of the array of fence_infos
v2: - Check flags passed to the kernel (Maarten) - Rework len to report only the size of fence_infos array (Emil) - Fix fence_info type. Use __u64 pointer type (Emil, Maarten)
v3: - Rename fence_info to sync_fence_info (Maarten) - Fix check for info.name (Maarten) - Update commit description of patch 06 (Emil, Maarten)
Please review! Thanks.
Gustavo Padovan (11): staging/android: remove SYNC_WAIT ioctl staging/android: rename sync_pt_info to sync_fence_info staging/android: rename sync_file_info_data to sync_file_info staging/android: remove driver_data from struct sync_fence_info staging/android: remove len field from struct sync_fence_info staging/android: turn fence_info into a __u64 pointer staging/android: add num_fences field to struct sync_file_info staging/android: make info->len return only size of sync_fence_info array staging/android: rename SYNC_IOC_FENCE_INFO staging/android: add flags member to sync ioctl structs staging/android: remove redundant comments on sync_merge_data
drivers/staging/android/sw_sync.c | 14 ---- drivers/staging/android/sync.c | 129 +++++++++-------------------------- drivers/staging/android/sync.h | 20 ------ drivers/staging/android/trace/sync.h | 44 ------------ drivers/staging/android/uapi/sync.h | 50 ++++++-------- 5 files changed, 56 insertions(+), 201 deletions(-)
From: Gustavo Padovan gustavo.padovan@collabora.co.uk
This ioctl is replicating the work of poll() syscall so let's take the opportunity that this is still on staging tree and remove the duplication and force new users to use the poll() standard interface.
Signed-off-by: Gustavo Padovan gustavo.padovan@collabora.co.uk --- drivers/staging/android/sync.c | 52 ------------------------------------ drivers/staging/android/sync.h | 13 --------- drivers/staging/android/trace/sync.h | 44 ------------------------------ drivers/staging/android/uapi/sync.h | 7 ----- 4 files changed, 116 deletions(-)
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c index 5fa4779..381209a 100644 --- a/drivers/staging/android/sync.c +++ b/drivers/staging/android/sync.c @@ -300,44 +300,6 @@ struct sync_file *sync_file_merge(const char *name, } EXPORT_SYMBOL(sync_file_merge);
-int sync_file_wait(struct sync_file *sync_file, long timeout) -{ - long ret; - int i; - - if (timeout < 0) - timeout = MAX_SCHEDULE_TIMEOUT; - else - timeout = msecs_to_jiffies(timeout); - - trace_sync_wait(sync_file, 1); - for (i = 0; i < sync_file->num_fences; ++i) - trace_fence(sync_file->cbs[i].fence); - ret = wait_event_interruptible_timeout(sync_file->wq, - atomic_read(&sync_file->status) <= 0, - timeout); - trace_sync_wait(sync_file, 0); - - if (ret < 0) { - return ret; - } else if (ret == 0) { - if (timeout) { - pr_info("sync_file timeout on [%p] after %dms\n", - sync_file, jiffies_to_msecs(timeout)); - sync_dump(); - } - return -ETIME; - } - - ret = atomic_read(&sync_file->status); - if (ret) { - pr_info("sync_file error %ld on [%p]\n", ret, sync_file); - sync_dump(); - } - return ret; -} -EXPORT_SYMBOL(sync_file_wait); - static const char *android_fence_get_driver_name(struct fence *fence) { struct sync_timeline *parent = fence_parent(fence); @@ -478,17 +440,6 @@ static unsigned int sync_file_poll(struct file *file, poll_table *wait) return 0; }
-static long sync_file_ioctl_wait(struct sync_file *sync_file, - unsigned long arg) -{ - __s32 value; - - if (copy_from_user(&value, (void __user *)arg, sizeof(value))) - return -EFAULT; - - return sync_file_wait(sync_file, value); -} - static long sync_file_ioctl_merge(struct sync_file *sync_file, unsigned long arg) { @@ -629,9 +580,6 @@ static long sync_file_ioctl(struct file *file, unsigned int cmd, struct sync_file *sync_file = file->private_data;
switch (cmd) { - case SYNC_IOC_WAIT: - return sync_file_ioctl_wait(sync_file, arg); - case SYNC_IOC_MERGE: return sync_file_ioctl_merge(sync_file, arg);
diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h index 8980b55..af1af99 100644 --- a/drivers/staging/android/sync.h +++ b/drivers/staging/android/sync.h @@ -18,7 +18,6 @@ #include <linux/ktime.h> #include <linux/list.h> #include <linux/spinlock.h> -#include <linux/wait.h> #include <linux/fence.h>
#include "uapi/sync.h" @@ -230,18 +229,6 @@ void sync_file_put(struct sync_file *sync_file); */ void sync_file_install(struct sync_file *sync_file, int fd);
-/** - * sync_file_wait() - wait on sync file - * @sync_file: file to wait on - * @tiemout: timeout in ms - * - * Wait for @sync_file to be signaled or have an error. Waits indefinitely - * if @timeout < 0. - * - * Returns 0 if fence signaled, > 0 if it is still active and <0 on error - */ -int sync_file_wait(struct sync_file *sync_file, long timeout); - #ifdef CONFIG_DEBUG_FS
void sync_timeline_debug_add(struct sync_timeline *obj); diff --git a/drivers/staging/android/trace/sync.h b/drivers/staging/android/trace/sync.h index 87c60e9..a0f80f4 100644 --- a/drivers/staging/android/trace/sync.h +++ b/drivers/staging/android/trace/sync.h @@ -32,50 +32,6 @@ TRACE_EVENT(sync_timeline, TP_printk("name=%s value=%s", __get_str(name), __entry->value) );
-TRACE_EVENT(sync_wait, - TP_PROTO(struct sync_file *sync_file, int begin), - - TP_ARGS(sync_file, begin), - - TP_STRUCT__entry( - __string(name, sync_file->name) - __field(s32, status) - __field(u32, begin) - ), - - TP_fast_assign( - __assign_str(name, sync_file->name); - __entry->status = atomic_read(&sync_file->status); - __entry->begin = begin; - ), - - TP_printk("%s name=%s state=%d", __entry->begin ? "begin" : "end", - __get_str(name), __entry->status) -); - -TRACE_EVENT(fence, - TP_PROTO(struct fence *fence), - - TP_ARGS(fence), - - TP_STRUCT__entry( - __string(timeline, fence->ops->get_timeline_name(fence)) - __array(char, value, 32) - ), - - TP_fast_assign( - __assign_str(timeline, fence->ops->get_timeline_name(fence)); - if (fence->ops->fence_value_str) { - fence->ops->fence_value_str(fence, __entry->value, - sizeof(__entry->value)); - } else { - __entry->value[0] = '\0'; - } - ), - - TP_printk("name=%s value=%s", __get_str(timeline), __entry->value) -); - #endif /* if !defined(_TRACE_SYNC_H) || defined(TRACE_HEADER_MULTI_READ) */
/* This part must be outside protection */ diff --git a/drivers/staging/android/uapi/sync.h b/drivers/staging/android/uapi/sync.h index 73deb69..6c88c80 100644 --- a/drivers/staging/android/uapi/sync.h +++ b/drivers/staging/android/uapi/sync.h @@ -65,13 +65,6 @@ struct sync_file_info_data { #define SYNC_IOC_MAGIC '>'
/** - * DOC: SYNC_IOC_WAIT - wait for a fence to signal - * - * pass timeout in milliseconds. Waits indefinitely timeout < 0. - */ -#define SYNC_IOC_WAIT _IOW(SYNC_IOC_MAGIC, 0, __s32) - -/** * DOC: SYNC_IOC_MERGE - merge two fences * * Takes a struct sync_merge_data. Creates a new fence containing copies of
From: Gustavo Padovan gustavo.padovan@collabora.co.uk
As struct sync_pt doesn't exist anymore it is a good idea remove any reference to it in the sync_framework. sync_pts were replaced directly by fences and here we rename it to sync_fence_info to let the fence namespace clean.
v2: rename fence_info to sync_fence_info (Maarten)
Signed-off-by: Gustavo Padovan gustavo.padovan@collabora.co.uk --- drivers/staging/android/sync.c | 10 +++++----- drivers/staging/android/uapi/sync.h | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c index 381209a..f6ffb10 100644 --- a/drivers/staging/android/sync.c +++ b/drivers/staging/android/sync.c @@ -490,15 +490,15 @@ err_put_fd: return err; }
-static int sync_fill_pt_info(struct fence *fence, void *data, int size) +static int sync_fill_fence_info(struct fence *fence, void *data, int size) { - struct sync_pt_info *info = data; + struct sync_fence_info *info = data; int ret;
- if (size < sizeof(struct sync_pt_info)) + if (size < sizeof(*info)) return -ENOMEM;
- info->len = sizeof(struct sync_pt_info); + info->len = sizeof(*info);
if (fence->ops->fill_driver_data) { ret = fence->ops->fill_driver_data(fence, info->driver_data, @@ -553,7 +553,7 @@ static long sync_file_ioctl_fence_info(struct sync_file *sync_file, for (i = 0; i < sync_file->num_fences; ++i) { struct fence *fence = sync_file->cbs[i].fence;
- ret = sync_fill_pt_info(fence, (u8 *)data + len, size - len); + ret = sync_fill_fence_info(fence, (u8 *)data + len, size - len);
if (ret < 0) goto out; diff --git a/drivers/staging/android/uapi/sync.h b/drivers/staging/android/uapi/sync.h index 6c88c80..9a0c3cd 100644 --- a/drivers/staging/android/uapi/sync.h +++ b/drivers/staging/android/uapi/sync.h @@ -27,15 +27,15 @@ struct sync_merge_data { };
/** - * struct sync_pt_info - detailed sync_pt information - * @len: length of sync_pt_info including any driver_data + * struct sync_fence_info - detailed fence information + * @len: length of sync_fence_info including any driver_data * @obj_name: name of parent sync_timeline * @driver_name: name of driver implementing the parent - * @status: status of the sync_pt 0:active 1:signaled <0:error + * @status: status of the fence 0:active 1:signaled <0:error * @timestamp_ns: timestamp of status change in nanoseconds * @driver_data: any driver dependent data */ -struct sync_pt_info { +struct sync_fence_info { __u32 len; char obj_name[32]; char driver_name[32]; @@ -52,14 +52,14 @@ struct sync_pt_info { * userspace including pt_info. * @name: name of fence * @status: status of fence. 1: signaled 0:active <0:error - * @pt_info: a sync_pt_info struct for every sync_pt in the fence + * @sync_fence_info: array of sync_fence_info for every fence in the sync_file */ struct sync_file_info_data { __u32 len; char name[32]; __s32 status;
- __u8 pt_info[0]; + __u8 sync_fence_info[0]; };
#define SYNC_IOC_MAGIC '>'
From: Gustavo Padovan gustavo.padovan@collabora.co.uk
info_data is a bit redundant, let's keep it as only sync_file_info. It is also smaller.
Signed-off-by: Gustavo Padovan gustavo.padovan@collabora.co.uk --- drivers/staging/android/sync.c | 26 +++++++++++++------------- drivers/staging/android/uapi/sync.h | 9 ++++----- 2 files changed, 17 insertions(+), 18 deletions(-)
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c index f6ffb10..85a0e87 100644 --- a/drivers/staging/android/sync.c +++ b/drivers/staging/android/sync.c @@ -525,7 +525,7 @@ static int sync_fill_fence_info(struct fence *fence, void *data, int size) static long sync_file_ioctl_fence_info(struct sync_file *sync_file, unsigned long arg) { - struct sync_file_info_data *data; + struct sync_file_info *info; __u32 size; __u32 len = 0; int ret, i; @@ -533,27 +533,27 @@ static long sync_file_ioctl_fence_info(struct sync_file *sync_file, if (copy_from_user(&size, (void __user *)arg, sizeof(size))) return -EFAULT;
- if (size < sizeof(struct sync_file_info_data)) + if (size < sizeof(struct sync_file_info)) return -EINVAL;
if (size > 4096) size = 4096;
- data = kzalloc(size, GFP_KERNEL); - if (!data) + info = kzalloc(size, GFP_KERNEL); + if (!info) return -ENOMEM;
- strlcpy(data->name, sync_file->name, sizeof(data->name)); - data->status = atomic_read(&sync_file->status); - if (data->status >= 0) - data->status = !data->status; + strlcpy(info->name, sync_file->name, sizeof(info->name)); + info->status = atomic_read(&sync_file->status); + if (info->status >= 0) + info->status = !info->status;
- len = sizeof(struct sync_file_info_data); + len = sizeof(struct sync_file_info);
for (i = 0; i < sync_file->num_fences; ++i) { struct fence *fence = sync_file->cbs[i].fence;
- ret = sync_fill_fence_info(fence, (u8 *)data + len, size - len); + ret = sync_fill_fence_info(fence, (u8 *)info + len, size - len);
if (ret < 0) goto out; @@ -561,15 +561,15 @@ static long sync_file_ioctl_fence_info(struct sync_file *sync_file, len += ret; }
- data->len = len; + info->len = len;
- if (copy_to_user((void __user *)arg, data, len)) + if (copy_to_user((void __user *)arg, info, len)) ret = -EFAULT; else ret = 0;
out: - kfree(data); + kfree(info);
return ret; } diff --git a/drivers/staging/android/uapi/sync.h b/drivers/staging/android/uapi/sync.h index 9a0c3cd..fcc0b3c 100644 --- a/drivers/staging/android/uapi/sync.h +++ b/drivers/staging/android/uapi/sync.h @@ -46,15 +46,15 @@ struct sync_fence_info { };
/** - * struct sync_file_info_data - data returned from fence info ioctl + * struct sync_file_info - data returned from fence info ioctl * @len: ioctl caller writes the size of the buffer its passing in. - * ioctl returns length of sync_file_info_data returned to + * ioctl returns length of sync_file_info returned to * userspace including pt_info. * @name: name of fence * @status: status of fence. 1: signaled 0:active <0:error * @sync_fence_info: array of sync_fence_info for every fence in the sync_file */ -struct sync_file_info_data { +struct sync_file_info { __u32 len; char name[32]; __s32 status; @@ -84,7 +84,6 @@ struct sync_file_info_data { * pt_info is a buffer containing sync_pt_infos for every sync_pt in the fence. * To iterate over the sync_pt_infos, use the sync_pt_info.len field. */ -#define SYNC_IOC_FENCE_INFO _IOWR(SYNC_IOC_MAGIC, 2,\ - struct sync_file_info_data) +#define SYNC_IOC_FENCE_INFO _IOWR(SYNC_IOC_MAGIC, 2, struct sync_file_info)
#endif /* _UAPI_LINUX_SYNC_H */
From: Gustavo Padovan gustavo.padovan@collabora.co.uk
It is unclear in what situations driver_data should be used thus better do not upstream it for now. If a need arises in the future a discussion can be started to re-add it.
Signed-off-by: Gustavo Padovan gustavo.padovan@collabora.co.uk --- drivers/staging/android/sw_sync.c | 14 -------------- drivers/staging/android/sync.c | 21 --------------------- drivers/staging/android/sync.h | 7 ------- drivers/staging/android/uapi/sync.h | 5 +---- 4 files changed, 1 insertion(+), 46 deletions(-)
diff --git a/drivers/staging/android/sw_sync.c b/drivers/staging/android/sw_sync.c index 3bee959..af39ff5 100644 --- a/drivers/staging/android/sw_sync.c +++ b/drivers/staging/android/sw_sync.c @@ -47,19 +47,6 @@ static int sw_sync_fence_has_signaled(struct fence *fence) return (pt->value > obj->value) ? 0 : 1; }
-static int sw_sync_fill_driver_data(struct fence *fence, - void *data, int size) -{ - struct sw_sync_pt *pt = (struct sw_sync_pt *)fence; - - if (size < sizeof(pt->value)) - return -ENOMEM; - - memcpy(data, &pt->value, sizeof(pt->value)); - - return sizeof(pt->value); -} - static void sw_sync_timeline_value_str(struct sync_timeline *sync_timeline, char *str, int size) { @@ -78,7 +65,6 @@ static void sw_sync_fence_value_str(struct fence *fence, char *str, int size) static struct sync_timeline_ops sw_sync_timeline_ops = { .driver_name = "sw_sync", .has_signaled = sw_sync_fence_has_signaled, - .fill_driver_data = sw_sync_fill_driver_data, .timeline_value_str = sw_sync_timeline_value_str, .fence_value_str = sw_sync_fence_value_str, }; diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c index 85a0e87..d527878 100644 --- a/drivers/staging/android/sync.c +++ b/drivers/staging/android/sync.c @@ -351,16 +351,6 @@ static bool android_fence_enable_signaling(struct fence *fence) return true; }
-static int android_fence_fill_driver_data(struct fence *fence, - void *data, int size) -{ - struct sync_timeline *parent = fence_parent(fence); - - if (!parent->ops->fill_driver_data) - return 0; - return parent->ops->fill_driver_data(fence, data, size); -} - static void android_fence_value_str(struct fence *fence, char *str, int size) { @@ -394,7 +384,6 @@ static const struct fence_ops android_fence_ops = { .signaled = android_fence_signaled, .wait = fence_default_wait, .release = android_fence_release, - .fill_driver_data = android_fence_fill_driver_data, .fence_value_str = android_fence_value_str, .timeline_value_str = android_fence_timeline_value_str, }; @@ -493,22 +482,12 @@ err_put_fd: static int sync_fill_fence_info(struct fence *fence, void *data, int size) { struct sync_fence_info *info = data; - int ret;
if (size < sizeof(*info)) return -ENOMEM;
info->len = sizeof(*info);
- if (fence->ops->fill_driver_data) { - ret = fence->ops->fill_driver_data(fence, info->driver_data, - size - sizeof(*info)); - if (ret < 0) - return ret; - - info->len += ret; - } - strlcpy(info->obj_name, fence->ops->get_timeline_name(fence), sizeof(info->obj_name)); strlcpy(info->driver_name, fence->ops->get_driver_name(fence), diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h index af1af99..d2a1734 100644 --- a/drivers/staging/android/sync.h +++ b/drivers/staging/android/sync.h @@ -32,10 +32,6 @@ struct sync_file; * 1 if pt has signaled * 0 if pt has not signaled * <0 on error - * @fill_driver_data: write implementation specific driver data to data. - * should return an error if there is not enough room - * as specified by size. This information is returned - * to userspace by SYNC_IOC_FENCE_INFO. * @timeline_value_str: fill str with the value of the sync_timeline's counter * @fence_value_str: fill str with the value of the fence */ @@ -46,9 +42,6 @@ struct sync_timeline_ops { int (*has_signaled)(struct fence *fence);
/* optional */ - int (*fill_driver_data)(struct fence *fence, void *data, int size); - - /* optional */ void (*timeline_value_str)(struct sync_timeline *timeline, char *str, int size);
diff --git a/drivers/staging/android/uapi/sync.h b/drivers/staging/android/uapi/sync.h index fcc0b3c..4d8cf00 100644 --- a/drivers/staging/android/uapi/sync.h +++ b/drivers/staging/android/uapi/sync.h @@ -28,12 +28,11 @@ struct sync_merge_data {
/** * struct sync_fence_info - detailed fence information - * @len: length of sync_fence_info including any driver_data + * @len: length of sync_fence_info * @obj_name: name of parent sync_timeline * @driver_name: name of driver implementing the parent * @status: status of the fence 0:active 1:signaled <0:error * @timestamp_ns: timestamp of status change in nanoseconds - * @driver_data: any driver dependent data */ struct sync_fence_info { __u32 len; @@ -41,8 +40,6 @@ struct sync_fence_info { char driver_name[32]; __s32 status; __u64 timestamp_ns; - - __u8 driver_data[0]; };
/**
From: Gustavo Padovan gustavo.padovan@collabora.co.uk
After removing driver_data struct sync_fence_info has now a fixed size, thus it doesn't need any field to tell its size, it is already known.
Signed-off-by: Gustavo Padovan gustavo.padovan@collabora.co.uk --- drivers/staging/android/sync.c | 4 +--- drivers/staging/android/uapi/sync.h | 2 -- 2 files changed, 1 insertion(+), 5 deletions(-)
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c index d527878..2ab0c20 100644 --- a/drivers/staging/android/sync.c +++ b/drivers/staging/android/sync.c @@ -486,8 +486,6 @@ static int sync_fill_fence_info(struct fence *fence, void *data, int size) if (size < sizeof(*info)) return -ENOMEM;
- info->len = sizeof(*info); - strlcpy(info->obj_name, fence->ops->get_timeline_name(fence), sizeof(info->obj_name)); strlcpy(info->driver_name, fence->ops->get_driver_name(fence), @@ -498,7 +496,7 @@ static int sync_fill_fence_info(struct fence *fence, void *data, int size) info->status = 0; info->timestamp_ns = ktime_to_ns(fence->timestamp);
- return info->len; + return sizeof(*info); }
static long sync_file_ioctl_fence_info(struct sync_file *sync_file, diff --git a/drivers/staging/android/uapi/sync.h b/drivers/staging/android/uapi/sync.h index 4d8cf00..a0cf357 100644 --- a/drivers/staging/android/uapi/sync.h +++ b/drivers/staging/android/uapi/sync.h @@ -28,14 +28,12 @@ struct sync_merge_data {
/** * struct sync_fence_info - detailed fence information - * @len: length of sync_fence_info * @obj_name: name of parent sync_timeline * @driver_name: name of driver implementing the parent * @status: status of the fence 0:active 1:signaled <0:error * @timestamp_ns: timestamp of status change in nanoseconds */ struct sync_fence_info { - __u32 len; char obj_name[32]; char driver_name[32]; __s32 status;
From: Gustavo Padovan gustavo.padovan@collabora.co.uk
Turn sync_fence_info into __u64 type enable us to extend the struct in the future without breaking the ABI.
v2: use type __u64 for fence_info
v3: fix commit message to reflect the v2 change
Signed-off-by: Gustavo Padovan gustavo.padovan@collabora.co.uk --- drivers/staging/android/sync.c | 2 +- drivers/staging/android/uapi/sync.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c index 2ab0c20..8425457 100644 --- a/drivers/staging/android/sync.c +++ b/drivers/staging/android/sync.c @@ -525,7 +525,7 @@ static long sync_file_ioctl_fence_info(struct sync_file *sync_file, if (info->status >= 0) info->status = !info->status;
- len = sizeof(struct sync_file_info); + len = sizeof(struct sync_file_info) - sizeof(__u64);
for (i = 0; i < sync_file->num_fences; ++i) { struct fence *fence = sync_file->cbs[i].fence; diff --git a/drivers/staging/android/uapi/sync.h b/drivers/staging/android/uapi/sync.h index a0cf357..e649953 100644 --- a/drivers/staging/android/uapi/sync.h +++ b/drivers/staging/android/uapi/sync.h @@ -54,7 +54,7 @@ struct sync_file_info { char name[32]; __s32 status;
- __u8 sync_fence_info[0]; + __u64 sync_fence_info; };
#define SYNC_IOC_MAGIC '>'
Op 03-02-16 om 14:25 schreef Gustavo Padovan:
From: Gustavo Padovan gustavo.padovan@collabora.co.uk
Turn sync_fence_info into __u64 type enable us to extend the struct in the future without breaking the ABI.
v2: use type __u64 for fence_info
v3: fix commit message to reflect the v2 change
Signed-off-by: Gustavo Padovan gustavo.padovan@collabora.co.uk
drivers/staging/android/sync.c | 2 +- drivers/staging/android/uapi/sync.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c index 2ab0c20..8425457 100644 --- a/drivers/staging/android/sync.c +++ b/drivers/staging/android/sync.c @@ -525,7 +525,7 @@ static long sync_file_ioctl_fence_info(struct sync_file *sync_file, if (info->status >= 0) info->status = !info->status;
- len = sizeof(struct sync_file_info);
len = sizeof(struct sync_file_info) - sizeof(__u64);
for (i = 0; i < sync_file->num_fences; ++i) { struct fence *fence = sync_file->cbs[i].fence;
diff --git a/drivers/staging/android/uapi/sync.h b/drivers/staging/android/uapi/sync.h index a0cf357..e649953 100644 --- a/drivers/staging/android/uapi/sync.h +++ b/drivers/staging/android/uapi/sync.h @@ -54,7 +54,7 @@ struct sync_file_info { char name[32]; __s32 status;
- __u8 sync_fence_info[0];
- __u64 sync_fence_info;
};
#define SYNC_IOC_MAGIC '>'
This still doesn't do what you expect it to.
I think this is what you want is for userspace to do:
struct sync_file_info info;
info.flags = info.num_fences = 0; ioctl(fd, SYNC_IOC_FENCE_INFO, &info); if (info.num_fences) { info.sync_fence_info = (uintptr)kcalloc(info.num_fences, sizeof(struct sync_fence_info)); ioctl(fd, SYNC_IOC_FENCE_INFO, &info); }
Maybe userspace could preallocate the max in advance and set num_fences higher,
kernel would do something like:
num_fences = min(info.num_fences, sync->num_fences); struct sync_fence_info array[num_fences];
info.num_fences = sync->num_fences; if (num_fences && copy_to_user((void * __user)(unsigned long)info.sync_fence_info, array, num_fences * sizeof(array))) return -EFAULT;
Hi Maarten,
2016-02-03 Maarten Lankhorst maarten.lankhorst@linux.intel.com:
Op 03-02-16 om 14:25 schreef Gustavo Padovan:
From: Gustavo Padovan gustavo.padovan@collabora.co.uk
Turn sync_fence_info into __u64 type enable us to extend the struct in the future without breaking the ABI.
v2: use type __u64 for fence_info
v3: fix commit message to reflect the v2 change
Signed-off-by: Gustavo Padovan gustavo.padovan@collabora.co.uk
drivers/staging/android/sync.c | 2 +- drivers/staging/android/uapi/sync.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c index 2ab0c20..8425457 100644 --- a/drivers/staging/android/sync.c +++ b/drivers/staging/android/sync.c @@ -525,7 +525,7 @@ static long sync_file_ioctl_fence_info(struct sync_file *sync_file, if (info->status >= 0) info->status = !info->status;
- len = sizeof(struct sync_file_info);
len = sizeof(struct sync_file_info) - sizeof(__u64);
for (i = 0; i < sync_file->num_fences; ++i) { struct fence *fence = sync_file->cbs[i].fence;
diff --git a/drivers/staging/android/uapi/sync.h b/drivers/staging/android/uapi/sync.h index a0cf357..e649953 100644 --- a/drivers/staging/android/uapi/sync.h +++ b/drivers/staging/android/uapi/sync.h @@ -54,7 +54,7 @@ struct sync_file_info { char name[32]; __s32 status;
- __u8 sync_fence_info[0];
- __u64 sync_fence_info;
};
#define SYNC_IOC_MAGIC '>'
This still doesn't do what you expect it to.
I think this is what you want is for userspace to do:
struct sync_file_info info;
info.flags = info.num_fences = 0; ioctl(fd, SYNC_IOC_FENCE_INFO, &info); if (info.num_fences) { info.sync_fence_info = (uintptr)kcalloc(info.num_fences, sizeof(struct sync_fence_info)); ioctl(fd, SYNC_IOC_FENCE_INFO, &info); }
Maybe userspace could preallocate the max in advance and set num_fences higher,
kernel would do something like:
num_fences = min(info.num_fences, sync->num_fences); struct sync_fence_info array[num_fences];
info.num_fences = sync->num_fences; if (num_fences && copy_to_user((void * __user)(unsigned long)info.sync_fence_info, array, num_fences * sizeof(array))) return -EFAULT;
If we are going to call IOCTL twice I would actually have a new IOCTL only to fetch sync_fence_info.
First we would call
ioctl(fd, SYNC_IOC_FILE_INFO, &info);
where info is:
struct sync_file_info { char name[32]; __s32 status; __u32 flags; __u32 num_fences; };
then we would allocate a buffer with
size = info.num_fences * sizeof(struct sync_fence_info)
and call the new ioctl
ioctl(fd, SYNC_IOC_SYNC_FENCE_INFO, sync_fence_info);
This looks like a cleaner solution and doesn't break ABI. What do you think?
Gustavo
Op 03-02-16 om 21:09 schreef Gustavo Padovan:
Hi Maarten,
2016-02-03 Maarten Lankhorst maarten.lankhorst@linux.intel.com:
Op 03-02-16 om 14:25 schreef Gustavo Padovan:
From: Gustavo Padovan gustavo.padovan@collabora.co.uk
Turn sync_fence_info into __u64 type enable us to extend the struct in the future without breaking the ABI.
v2: use type __u64 for fence_info
v3: fix commit message to reflect the v2 change
Signed-off-by: Gustavo Padovan gustavo.padovan@collabora.co.uk
drivers/staging/android/sync.c | 2 +- drivers/staging/android/uapi/sync.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c index 2ab0c20..8425457 100644 --- a/drivers/staging/android/sync.c +++ b/drivers/staging/android/sync.c @@ -525,7 +525,7 @@ static long sync_file_ioctl_fence_info(struct sync_file *sync_file, if (info->status >= 0) info->status = !info->status;
- len = sizeof(struct sync_file_info);
len = sizeof(struct sync_file_info) - sizeof(__u64);
for (i = 0; i < sync_file->num_fences; ++i) { struct fence *fence = sync_file->cbs[i].fence;
diff --git a/drivers/staging/android/uapi/sync.h b/drivers/staging/android/uapi/sync.h index a0cf357..e649953 100644 --- a/drivers/staging/android/uapi/sync.h +++ b/drivers/staging/android/uapi/sync.h @@ -54,7 +54,7 @@ struct sync_file_info { char name[32]; __s32 status;
- __u8 sync_fence_info[0];
- __u64 sync_fence_info;
};
#define SYNC_IOC_MAGIC '>'
This still doesn't do what you expect it to.
I think this is what you want is for userspace to do:
struct sync_file_info info;
info.flags = info.num_fences = 0; ioctl(fd, SYNC_IOC_FENCE_INFO, &info); if (info.num_fences) { info.sync_fence_info = (uintptr)kcalloc(info.num_fences, sizeof(struct sync_fence_info)); ioctl(fd, SYNC_IOC_FENCE_INFO, &info); }
Maybe userspace could preallocate the max in advance and set num_fences higher,
kernel would do something like:
num_fences = min(info.num_fences, sync->num_fences); struct sync_fence_info array[num_fences];
info.num_fences = sync->num_fences; if (num_fences && copy_to_user((void * __user)(unsigned long)info.sync_fence_info, array, num_fences * sizeof(array))) return -EFAULT;
If we are going to call IOCTL twice I would actually have a new IOCTL only to fetch sync_fence_info.
First we would call
ioctl(fd, SYNC_IOC_FILE_INFO, &info);
where info is:
struct sync_file_info { char name[32]; __s32 status; __u32 flags; __u32 num_fences; };
then we would allocate a buffer with
size = info.num_fences * sizeof(struct sync_fence_info)
and call the new ioctl
ioctl(fd, SYNC_IOC_SYNC_FENCE_INFO, sync_fence_info);
This looks like a cleaner solution and doesn't break ABI. What do you think?
I think it's good taste that userspace specifies the size of the buffer it passes, so former feels more clean to me, since you need to pass num_fences anyway. But Daniel knows more about designing ioctl's than I do, so for exact behavior it's best to ask him.
~Maarten
2016-02-04 Maarten Lankhorst maarten.lankhorst@linux.intel.com:
Op 03-02-16 om 21:09 schreef Gustavo Padovan:
Hi Maarten,
2016-02-03 Maarten Lankhorst maarten.lankhorst@linux.intel.com:
Op 03-02-16 om 14:25 schreef Gustavo Padovan:
From: Gustavo Padovan gustavo.padovan@collabora.co.uk
Turn sync_fence_info into __u64 type enable us to extend the struct in the future without breaking the ABI.
v2: use type __u64 for fence_info
v3: fix commit message to reflect the v2 change
Signed-off-by: Gustavo Padovan gustavo.padovan@collabora.co.uk
drivers/staging/android/sync.c | 2 +- drivers/staging/android/uapi/sync.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c index 2ab0c20..8425457 100644 --- a/drivers/staging/android/sync.c +++ b/drivers/staging/android/sync.c @@ -525,7 +525,7 @@ static long sync_file_ioctl_fence_info(struct sync_file *sync_file, if (info->status >= 0) info->status = !info->status;
- len = sizeof(struct sync_file_info);
len = sizeof(struct sync_file_info) - sizeof(__u64);
for (i = 0; i < sync_file->num_fences; ++i) { struct fence *fence = sync_file->cbs[i].fence;
diff --git a/drivers/staging/android/uapi/sync.h b/drivers/staging/android/uapi/sync.h index a0cf357..e649953 100644 --- a/drivers/staging/android/uapi/sync.h +++ b/drivers/staging/android/uapi/sync.h @@ -54,7 +54,7 @@ struct sync_file_info { char name[32]; __s32 status;
- __u8 sync_fence_info[0];
- __u64 sync_fence_info;
};
#define SYNC_IOC_MAGIC '>'
This still doesn't do what you expect it to.
I think this is what you want is for userspace to do:
struct sync_file_info info;
info.flags = info.num_fences = 0; ioctl(fd, SYNC_IOC_FENCE_INFO, &info); if (info.num_fences) { info.sync_fence_info = (uintptr)kcalloc(info.num_fences, sizeof(struct sync_fence_info)); ioctl(fd, SYNC_IOC_FENCE_INFO, &info); }
Maybe userspace could preallocate the max in advance and set num_fences higher,
kernel would do something like:
num_fences = min(info.num_fences, sync->num_fences); struct sync_fence_info array[num_fences];
info.num_fences = sync->num_fences; if (num_fences && copy_to_user((void * __user)(unsigned long)info.sync_fence_info, array, num_fences * sizeof(array))) return -EFAULT;
If we are going to call IOCTL twice I would actually have a new IOCTL only to fetch sync_fence_info.
First we would call
ioctl(fd, SYNC_IOC_FILE_INFO, &info);
where info is:
struct sync_file_info { char name[32]; __s32 status; __u32 flags; __u32 num_fences; };
then we would allocate a buffer with
size = info.num_fences * sizeof(struct sync_fence_info)
and call the new ioctl
ioctl(fd, SYNC_IOC_SYNC_FENCE_INFO, sync_fence_info);
This looks like a cleaner solution and doesn't break ABI. What do you think?
I think it's good taste that userspace specifies the size of the buffer it passes, so former feels more clean to me, since you need to pass num_fences anyway.
Just to clarify, userspace specifies the size of the buffer in the solution I proposed. It would be
size = info.num_fences * sizeof(struct sync_fence_info)
sync_fence_info = malloc(size);
ioctl(fd, SYNC_IOC_SYNC_FENCE_INFO, sync_fence_info);
Op 04-02-16 om 14:05 schreef Gustavo Padovan:
2016-02-04 Maarten Lankhorst maarten.lankhorst@linux.intel.com:
Op 03-02-16 om 21:09 schreef Gustavo Padovan:
Hi Maarten,
2016-02-03 Maarten Lankhorst maarten.lankhorst@linux.intel.com:
Op 03-02-16 om 14:25 schreef Gustavo Padovan:
From: Gustavo Padovan gustavo.padovan@collabora.co.uk
Turn sync_fence_info into __u64 type enable us to extend the struct in the future without breaking the ABI.
v2: use type __u64 for fence_info
v3: fix commit message to reflect the v2 change
Signed-off-by: Gustavo Padovan gustavo.padovan@collabora.co.uk
drivers/staging/android/sync.c | 2 +- drivers/staging/android/uapi/sync.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c index 2ab0c20..8425457 100644 --- a/drivers/staging/android/sync.c +++ b/drivers/staging/android/sync.c @@ -525,7 +525,7 @@ static long sync_file_ioctl_fence_info(struct sync_file *sync_file, if (info->status >= 0) info->status = !info->status;
- len = sizeof(struct sync_file_info);
len = sizeof(struct sync_file_info) - sizeof(__u64);
for (i = 0; i < sync_file->num_fences; ++i) { struct fence *fence = sync_file->cbs[i].fence;
diff --git a/drivers/staging/android/uapi/sync.h b/drivers/staging/android/uapi/sync.h index a0cf357..e649953 100644 --- a/drivers/staging/android/uapi/sync.h +++ b/drivers/staging/android/uapi/sync.h @@ -54,7 +54,7 @@ struct sync_file_info { char name[32]; __s32 status;
- __u8 sync_fence_info[0];
- __u64 sync_fence_info;
};
#define SYNC_IOC_MAGIC '>'
This still doesn't do what you expect it to.
I think this is what you want is for userspace to do:
struct sync_file_info info;
info.flags = info.num_fences = 0; ioctl(fd, SYNC_IOC_FENCE_INFO, &info); if (info.num_fences) { info.sync_fence_info = (uintptr)kcalloc(info.num_fences, sizeof(struct sync_fence_info)); ioctl(fd, SYNC_IOC_FENCE_INFO, &info); }
Maybe userspace could preallocate the max in advance and set num_fences higher,
kernel would do something like:
num_fences = min(info.num_fences, sync->num_fences); struct sync_fence_info array[num_fences];
info.num_fences = sync->num_fences; if (num_fences && copy_to_user((void * __user)(unsigned long)info.sync_fence_info, array, num_fences * sizeof(array))) return -EFAULT;
If we are going to call IOCTL twice I would actually have a new IOCTL only to fetch sync_fence_info.
First we would call
ioctl(fd, SYNC_IOC_FILE_INFO, &info);
where info is:
struct sync_file_info { char name[32]; __s32 status; __u32 flags; __u32 num_fences; };
then we would allocate a buffer with
size = info.num_fences * sizeof(struct sync_fence_info)
and call the new ioctl
ioctl(fd, SYNC_IOC_SYNC_FENCE_INFO, sync_fence_info);
This looks like a cleaner solution and doesn't break ABI. What do you think?
I think it's good taste that userspace specifies the size of the buffer it passes, so former feels more clean to me, since you need to pass num_fences anyway.
Just to clarify, userspace specifies the size of the buffer in the solution I proposed. It would be
size = info.num_fences * sizeof(struct sync_fence_info)
sync_fence_info = malloc(size);
ioctl(fd, SYNC_IOC_SYNC_FENCE_INFO, sync_fence_info);
For someone writing a wrapper like valgrind would mean having prior knowledge of previous ioctl results too. Hence you would need something like
struct fence_collection { u32 num_fences; u32 pad; struct sync_fence_info fences[0]; }
in which case you might as well return it optionally as a pointer in sync_file_info.
~Maarten
On Wed, Feb 03, 2016 at 03:39:22PM +0100, Maarten Lankhorst wrote:
Op 03-02-16 om 14:25 schreef Gustavo Padovan:
From: Gustavo Padovan gustavo.padovan@collabora.co.uk
Turn sync_fence_info into __u64 type enable us to extend the struct in the future without breaking the ABI.
v2: use type __u64 for fence_info
v3: fix commit message to reflect the v2 change
Signed-off-by: Gustavo Padovan gustavo.padovan@collabora.co.uk
drivers/staging/android/sync.c | 2 +- drivers/staging/android/uapi/sync.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c index 2ab0c20..8425457 100644 --- a/drivers/staging/android/sync.c +++ b/drivers/staging/android/sync.c @@ -525,7 +525,7 @@ static long sync_file_ioctl_fence_info(struct sync_file *sync_file, if (info->status >= 0) info->status = !info->status;
- len = sizeof(struct sync_file_info);
len = sizeof(struct sync_file_info) - sizeof(__u64);
for (i = 0; i < sync_file->num_fences; ++i) { struct fence *fence = sync_file->cbs[i].fence;
diff --git a/drivers/staging/android/uapi/sync.h b/drivers/staging/android/uapi/sync.h index a0cf357..e649953 100644 --- a/drivers/staging/android/uapi/sync.h +++ b/drivers/staging/android/uapi/sync.h @@ -54,7 +54,7 @@ struct sync_file_info { char name[32]; __s32 status;
- __u8 sync_fence_info[0];
- __u64 sync_fence_info;
};
#define SYNC_IOC_MAGIC '>'
This still doesn't do what you expect it to.
I think this is what you want is for userspace to do:
struct sync_file_info info;
info.flags = info.num_fences = 0; ioctl(fd, SYNC_IOC_FENCE_INFO, &info); if (info.num_fences) { info.sync_fence_info = (uintptr)kcalloc(info.num_fences, sizeof(struct sync_fence_info)); ioctl(fd, SYNC_IOC_FENCE_INFO, &info);
s/kcalloc/calloc/ since this is userspace, i.e. yes I agree. In general if you have a variable sized array for your ioctl what you need to do in the kernel:
- compute how many you need. - if userspace array was too small, fail with -EINVAL - but _always_ update the array size to what would be needed.
Then the loop above which Maarten laid out will work nicely. Of course since it's a separate array then you also need separate copy_to_user calls (I didn't check whether that would work as-is). -Daniel
}
Maybe userspace could preallocate the max in advance and set num_fences higher,
kernel would do something like:
num_fences = min(info.num_fences, sync->num_fences); struct sync_fence_info array[num_fences];
info.num_fences = sync->num_fences; if (num_fences && copy_to_user((void * __user)(unsigned long)info.sync_fence_info, array, num_fences * sizeof(array))) return -EFAULT; _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/dri-devel
From: Gustavo Padovan gustavo.padovan@collabora.co.uk
Inform userspace how many fences are in the sync_fence_info field.
Signed-off-by: Gustavo Padovan gustavo.padovan@collabora.co.uk --- drivers/staging/android/sync.c | 2 ++ drivers/staging/android/uapi/sync.h | 2 ++ 2 files changed, 4 insertions(+)
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c index 8425457..e301b55 100644 --- a/drivers/staging/android/sync.c +++ b/drivers/staging/android/sync.c @@ -525,6 +525,8 @@ static long sync_file_ioctl_fence_info(struct sync_file *sync_file, if (info->status >= 0) info->status = !info->status;
+ info->num_fences = sync_file->num_fences; + len = sizeof(struct sync_file_info) - sizeof(__u64);
for (i = 0; i < sync_file->num_fences; ++i) { diff --git a/drivers/staging/android/uapi/sync.h b/drivers/staging/android/uapi/sync.h index e649953..fc7fbcf 100644 --- a/drivers/staging/android/uapi/sync.h +++ b/drivers/staging/android/uapi/sync.h @@ -47,12 +47,14 @@ struct sync_fence_info { * userspace including pt_info. * @name: name of fence * @status: status of fence. 1: signaled 0:active <0:error + * @num_fences number of fences in the sync_file * @sync_fence_info: array of sync_fence_info for every fence in the sync_file */ struct sync_file_info { __u32 len; char name[32]; __s32 status; + __u32 num_fences;
__u64 sync_fence_info; };
From: Gustavo Padovan gustavo.padovan@collabora.co.uk
The len member of struct sync_file_info was returning the size of the whole buffer (struct sync_file_info + sync_fence_infos at the of it). This commit change it to return only the size of the array of sync_fence_infos.
It also moves len to be right before the sync_fences_info field.
v2: fix check for name field (Maarten)
Signed-off-by: Gustavo Padovan gustavo.padovan@collabora.co.uk --- drivers/staging/android/sync.c | 17 ++++++++++++----- drivers/staging/android/uapi/sync.h | 7 +++---- 2 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c index e301b55..d6cf89f 100644 --- a/drivers/staging/android/sync.c +++ b/drivers/staging/android/sync.c @@ -502,14 +502,20 @@ static int sync_fill_fence_info(struct fence *fence, void *data, int size) static long sync_file_ioctl_fence_info(struct sync_file *sync_file, unsigned long arg) { - struct sync_file_info *info; + struct sync_file_info in, *info; __u32 size; - __u32 len = 0; + __u32 b_len, len = 0; int ret, i;
- if (copy_from_user(&size, (void __user *)arg, sizeof(size))) + if (copy_from_user(&in, (void __user *)arg, sizeof(*info))) return -EFAULT;
+ if (in.status || in.num_fences || in.sync_fence_info || + strcmp(in.name, "\0")) + return -EFAULT; + + size = in.len; + if (size < sizeof(struct sync_file_info)) return -EINVAL;
@@ -527,8 +533,9 @@ static long sync_file_ioctl_fence_info(struct sync_file *sync_file,
info->num_fences = sync_file->num_fences;
- len = sizeof(struct sync_file_info) - sizeof(__u64); + b_len = sizeof(struct sync_file_info) - sizeof(__u64);
+ len = b_len; for (i = 0; i < sync_file->num_fences; ++i) { struct fence *fence = sync_file->cbs[i].fence;
@@ -540,7 +547,7 @@ static long sync_file_ioctl_fence_info(struct sync_file *sync_file, len += ret; }
- info->len = len; + info->len = len - b_len;
if (copy_to_user((void __user *)arg, info, len)) ret = -EFAULT; diff --git a/drivers/staging/android/uapi/sync.h b/drivers/staging/android/uapi/sync.h index fc7fbcf..4e1d38b 100644 --- a/drivers/staging/android/uapi/sync.h +++ b/drivers/staging/android/uapi/sync.h @@ -42,19 +42,18 @@ struct sync_fence_info {
/** * struct sync_file_info - data returned from fence info ioctl - * @len: ioctl caller writes the size of the buffer its passing in. - * ioctl returns length of sync_file_info returned to - * userspace including pt_info. * @name: name of fence * @status: status of fence. 1: signaled 0:active <0:error * @num_fences number of fences in the sync_file + * @len: ioctl caller writes the size of the buffer its passing in. + * ioctl returns length of all fence_infos summed. * @sync_fence_info: array of sync_fence_info for every fence in the sync_file */ struct sync_file_info { - __u32 len; char name[32]; __s32 status; __u32 num_fences; + __u32 len;
__u64 sync_fence_info; };
From: Gustavo Padovan gustavo.padovan@collabora.co.uk
We don't use the 'fence' name to refer to sync_file anymore. So rename it to SYNC_IOC_FILE_INFO.
Signed-off-by: Gustavo Padovan gustavo.padovan@collabora.co.uk --- drivers/staging/android/sync.c | 2 +- drivers/staging/android/uapi/sync.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c index d6cf89f..36a6e62 100644 --- a/drivers/staging/android/sync.c +++ b/drivers/staging/android/sync.c @@ -569,7 +569,7 @@ static long sync_file_ioctl(struct file *file, unsigned int cmd, case SYNC_IOC_MERGE: return sync_file_ioctl_merge(sync_file, arg);
- case SYNC_IOC_FENCE_INFO: + case SYNC_IOC_FILE_INFO: return sync_file_ioctl_fence_info(sync_file, arg);
default: diff --git a/drivers/staging/android/uapi/sync.h b/drivers/staging/android/uapi/sync.h index 4e1d38b..6b687a8 100644 --- a/drivers/staging/android/uapi/sync.h +++ b/drivers/staging/android/uapi/sync.h @@ -80,6 +80,6 @@ struct sync_file_info { * pt_info is a buffer containing sync_pt_infos for every sync_pt in the fence. * To iterate over the sync_pt_infos, use the sync_pt_info.len field. */ -#define SYNC_IOC_FENCE_INFO _IOWR(SYNC_IOC_MAGIC, 2, struct sync_file_info) +#define SYNC_IOC_FILE_INFO _IOWR(SYNC_IOC_MAGIC, 2, struct sync_file_info)
#endif /* _UAPI_LINUX_SYNC_H */
From: Gustavo Padovan gustavo.padovan@collabora.co.uk
Play safe and add flags member to all structs. So we don't need to break API or create new IOCTL in the future if new features that requires flags arises.
v2: check if flags are valid (zero, in this case)
Signed-off-by: Gustavo Padovan gustavo.padovan@collabora.co.uk --- drivers/staging/android/sync.c | 7 ++++++- drivers/staging/android/uapi/sync.h | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c index 36a6e62..876a57b 100644 --- a/drivers/staging/android/sync.c +++ b/drivers/staging/android/sync.c @@ -445,6 +445,11 @@ static long sync_file_ioctl_merge(struct sync_file *sync_file, goto err_put_fd; }
+ if (data.flags) { + err = -EFAULT; + goto err_put_fd; + } + fence2 = sync_file_fdget(data.fd2); if (!fence2) { err = -ENOENT; @@ -510,7 +515,7 @@ static long sync_file_ioctl_fence_info(struct sync_file *sync_file, if (copy_from_user(&in, (void __user *)arg, sizeof(*info))) return -EFAULT;
- if (in.status || in.num_fences || in.sync_fence_info || + if (in.status || in.flags || in.num_fences || in.sync_fence_info || strcmp(in.name, "\0")) return -EFAULT;
diff --git a/drivers/staging/android/uapi/sync.h b/drivers/staging/android/uapi/sync.h index 6b687a8..48c6d45 100644 --- a/drivers/staging/android/uapi/sync.h +++ b/drivers/staging/android/uapi/sync.h @@ -19,11 +19,13 @@ * @fd2: file descriptor of second fence * @name: name of new fence * @fence: returns the fd of the new fence to userspace + * @flags: merge_data flags */ struct sync_merge_data { __s32 fd2; /* fd of second fence */ char name[32]; /* name of new fence */ __s32 fence; /* fd on newly created fence */ + __u32 flags; };
/** @@ -31,12 +33,14 @@ struct sync_merge_data { * @obj_name: name of parent sync_timeline * @driver_name: name of driver implementing the parent * @status: status of the fence 0:active 1:signaled <0:error + * @flags: fence_info flags * @timestamp_ns: timestamp of status change in nanoseconds */ struct sync_fence_info { char obj_name[32]; char driver_name[32]; __s32 status; + __u32 flags; __u64 timestamp_ns; };
@@ -44,6 +48,7 @@ struct sync_fence_info { * struct sync_file_info - data returned from fence info ioctl * @name: name of fence * @status: status of fence. 1: signaled 0:active <0:error + * @flags: sync_file_info flags * @num_fences number of fences in the sync_file * @len: ioctl caller writes the size of the buffer its passing in. * ioctl returns length of all fence_infos summed. @@ -52,6 +57,7 @@ struct sync_fence_info { struct sync_file_info { char name[32]; __s32 status; + __u32 flags; __u32 num_fences; __u32 len;
From: Gustavo Padovan gustavo.padovan@collabora.co.uk
struct sync_merge_data already have documentation on top of the struct definition. No need to duplicate it.
Signed-off-by: Gustavo Padovan gustavo.padovan@collabora.co.uk --- drivers/staging/android/uapi/sync.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/staging/android/uapi/sync.h b/drivers/staging/android/uapi/sync.h index 48c6d45..f56a6c2 100644 --- a/drivers/staging/android/uapi/sync.h +++ b/drivers/staging/android/uapi/sync.h @@ -22,9 +22,9 @@ * @flags: merge_data flags */ struct sync_merge_data { - __s32 fd2; /* fd of second fence */ - char name[32]; /* name of new fence */ - __s32 fence; /* fd on newly created fence */ + __s32 fd2; + char name[32]; + __s32 fence; __u32 flags; };
dri-devel@lists.freedesktop.org