Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1328834

Re: [PATCH v3 06/11] staging/android: turn fence_info into a __u64 pointer

From Daniel Vetter <daniel@ffwll.ch>
Newsgroups linux.kernel
Subject Re: [PATCH v3 06/11] staging/android: turn fence_info into a __u64 pointer
Date 2016-02-08 10:10 +0100
Message-ID <qZPZx-3ac-21@gated-at.bofh.it> (permalink)
References <qY5Fo-2vi-9@gated-at.bofh.it> <qY5P5-2zD-21@gated-at.bofh.it> <qY6L8-38w-11@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

Back to linux.kernel | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

[PATCH v3 00/11] android sync framework: clean up IOCTLs and ABI  Gustavo Padovan <gustavo@padovan.org> - 2016-02-03 14:30 +0100
  [PATCH v3 03/11] staging/android: rename sync_file_info_data to sync_file_info Gustavo Padovan <gustavo@padovan.org> - 2016-02-03 14:30 +0100
  [PATCH v3 01/11] staging/android: remove SYNC_WAIT ioctl Gustavo Padovan <gustavo@padovan.org> - 2016-02-03 14:30 +0100
  [PATCH v3 05/11] staging/android: remove len field from struct sync_fence_info Gustavo Padovan <gustavo@padovan.org> - 2016-02-03 14:30 +0100
  [PATCH v3 09/11] staging/android: rename SYNC_IOC_FENCE_INFO Gustavo Padovan <gustavo@padovan.org> - 2016-02-03 14:30 +0100
  [PATCH v3 08/11] staging/android: make info->len return only size of sync_fence_info array Gustavo Padovan <gustavo@padovan.org> - 2016-02-03 14:30 +0100
  [PATCH v3 07/11] staging/android: add num_fences field to struct sync_file_info Gustavo Padovan <gustavo@padovan.org> - 2016-02-03 14:30 +0100
  [PATCH v3 10/11] staging/android: add flags member to sync ioctl structs Gustavo Padovan <gustavo@padovan.org> - 2016-02-03 14:30 +0100
  [PATCH v3 11/11] staging/android: remove redundant comments on sync_merge_data Gustavo Padovan <gustavo@padovan.org> - 2016-02-03 14:30 +0100
  [PATCH v3 02/11] staging/android: rename sync_pt_info to sync_fence_info Gustavo Padovan <gustavo@padovan.org> - 2016-02-03 14:30 +0100
  [PATCH v3 04/11] staging/android: remove driver_data from struct sync_fence_info Gustavo Padovan <gustavo@padovan.org> - 2016-02-03 14:30 +0100
  [PATCH v3 06/11] staging/android: turn fence_info into a __u64 pointer Gustavo Padovan <gustavo@padovan.org> - 2016-02-03 14:40 +0100
    Re: [PATCH v3 06/11] staging/android: turn fence_info into a __u64  pointer Maarten Lankhorst <maarten.lankhorst@linux.intel.com> - 2016-02-03 15:40 +0100
      Re: [PATCH v3 06/11] staging/android: turn fence_info into a __u64  pointer Gustavo Padovan <gustavo@padovan.org> - 2016-02-03 21:20 +0100
        Re: [PATCH v3 06/11] staging/android: turn fence_info into a __u64  pointer Maarten Lankhorst <maarten.lankhorst@linux.intel.com> - 2016-02-04 11:00 +0100
          Re: [PATCH v3 06/11] staging/android: turn fence_info into a __u64  pointer Gustavo Padovan <gustavo.padovan@collabora.co.uk> - 2016-02-04 14:10 +0100
            Re: [PATCH v3 06/11] staging/android: turn fence_info into a __u64  pointer Maarten Lankhorst <maarten.lankhorst@linux.intel.com> - 2016-02-04 14:30 +0100
      Re: [PATCH v3 06/11] staging/android: turn fence_info into a __u64  pointer Daniel Vetter <daniel@ffwll.ch> - 2016-02-08 10:10 +0100

csiph-web