[PATCH v8 2/2] staging/android: refactor SYNC IOCTLs

2016-03-15 Thread kbuild test robot
Hi Gustavo,

[auto build test WARNING on staging/staging-testing]
[also build test WARNING on next-20160315]
[cannot apply to v4.5]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improving the system]

url:
https://github.com/0day-ci/linux/commits/Gustavo-Padovan/staging-android-remove-redundant-comments-on-sync_merge_data/20160315-051123
config: i386-randconfig-h1-03151610 (attached as .config)
reproduce:
# save the attached .config to linux build tree
make ARCH=i386 

All warnings (new ones prefixed by >>):

   In file included from include/linux/linkage.h:4:0,
from include/linux/fs.h:4,
from include/linux/debugfs.h:18,
from drivers/staging/android/sync.c:17:
   drivers/staging/android/sync.c: In function 'sync_file_ioctl_fence_info':
   drivers/staging/android/sync.c:535:19: warning: cast to pointer from integer 
of different size [-Wint-to-pointer-cast]
 if (copy_to_user((void __user *)info.sync_fence_info, fence_info,
  ^
   include/linux/compiler.h:147:30: note: in definition of macro '__trace_if'
 if (__builtin_constant_p(!!(cond)) ? !!(cond) :   \
 ^
>> drivers/staging/android/sync.c:535:2: note: in expansion of macro 'if'
 if (copy_to_user((void __user *)info.sync_fence_info, fence_info,
 ^
   drivers/staging/android/sync.c:535:19: warning: cast to pointer from integer 
of different size [-Wint-to-pointer-cast]
 if (copy_to_user((void __user *)info.sync_fence_info, fence_info,
  ^
   include/linux/compiler.h:147:42: note: in definition of macro '__trace_if'
 if (__builtin_constant_p(!!(cond)) ? !!(cond) :   \
 ^
>> drivers/staging/android/sync.c:535:2: note: in expansion of macro 'if'
 if (copy_to_user((void __user *)info.sync_fence_info, fence_info,
 ^
   drivers/staging/android/sync.c:535:19: warning: cast to pointer from integer 
of different size [-Wint-to-pointer-cast]
 if (copy_to_user((void __user *)info.sync_fence_info, fence_info,
  ^
   include/linux/compiler.h:158:16: note: in definition of macro '__trace_if'
  __r = !!(cond); \
   ^
>> drivers/staging/android/sync.c:535:2: note: in expansion of macro 'if'
 if (copy_to_user((void __user *)info.sync_fence_info, fence_info,
 ^

vim +/if +535 drivers/staging/android/sync.c

   519   * info->num_fences.
   520   */
   521  if (!info.num_fences)
   522  goto no_fences;
   523  
   524  if (info.num_fences < sync_file->num_fences)
   525  return -EINVAL;
   526  
   527  size = sync_file->num_fences * sizeof(*fence_info);
   528  fence_info = kzalloc(size, GFP_KERNEL);
   529  if (!fence_info)
   530  return -ENOMEM;
   531  
   532  for (i = 0; i < sync_file->num_fences; ++i)
   533  sync_fill_fence_info(sync_file->cbs[i].fence, 
_info[i]);
   534  
 > 535  if (copy_to_user((void __user *)info.sync_fence_info, 
 > fence_info,
   536   size)) {
   537  ret = -EFAULT;
   538  goto out;
   539  }
   540  
   541  no_fences:
   542  strlcpy(info.name, sync_file->name, sizeof(info.name));
   543  info.status = atomic_read(_file->status);

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation
-- next part --
A non-text attachment was scrubbed...
Name: .config.gz
Type: application/octet-stream
Size: 22770 bytes
Desc: not available
URL: 



[PATCH v8 2/2] staging/android: refactor SYNC IOCTLs

2016-03-14 Thread Gustavo Padovan
From: Gustavo Padovan 

Change SYNC_IOC_FILE_INFO (former SYNC_IOC_FENCE_INFO) behaviour to avoid
future API breaks and optimize buffer allocation.

Now num_fences can be filled by the caller to inform how many fences it
wants to retrieve from the kernel. If the num_fences passed is greater
than zero info->sync_fence_info should point to a buffer with enough space
to fit all fences.

However if num_fences passed to the kernel is 0, the kernel will reply
with number of fences of the sync_file.

Sending first an ioctl with num_fences = 0 can optimize buffer allocation,
in a first call with num_fences = 0 userspace will receive the actual
number of fences in the num_fences filed.

Then it can allocate a buffer with the correct size on sync_fence_info and
call SYNC_IOC_FILE_INFO again, but now with the actual value of num_fences
in the sync_file.

info->sync_fence_info was converted to __u64 pointer to prevent 32bit
compatibility issues. And a flags member was added.

An example userspace code for the later would be:

struct sync_file_info *info;
int err, size, num_fences;

info = malloc(sizeof(*info));

info.flags = 0;
err = ioctl(fd, SYNC_IOC_FILE_INFO, info);
num_fences = info->num_fences;

if (num_fences) {
info.flags = 0;
size = sizeof(struct sync_fence_info) * num_fences;
info->num_fences = num_fences;
info->sync_fence_info = (uint64_t) calloc(num_fences,
  sizeof(struct 
sync_fence_info));

err = ioctl(fd, SYNC_IOC_FILE_INFO, info);
}

Finally the IOCTLs numbers were changed to avoid any potential old
userspace running the old API to get weird errors. Changing the opcodes
will make them fail right away. This is just a precaution, there no
upstream users of these interfaces yet and the only user is Android, but
we don't expect anyone trying to run android userspace and all it
dependencies on top of upstream kernels.

Signed-off-by: Gustavo Padovan 
Reviewed-by: Maarten Lankhorst 
Acked-by: Greg Hackmann 
Acked-by: Rob Clark 
Acked-by: Daniel Vetter 

---
v2: fix fence_info memory leak

v3: Comments from Emil Velikov
- improve commit message
- remove __u64 cast
- remove check for output fields in file_info
- clean up sync_fill_fence_info()

Comments from Maarten Lankhorst
- remove in.num_fences && !in.sync_fence_info check
- remove info->len and use only num_fences to calculate size

Comments from Dan Carpenter
- fix info->sync_fence_info documentation

v4: remove allocated struct sync_file_info (comment from Maarten)

v5: merge all commits that were changing the ABI
---
 drivers/staging/android/sync.c  | 76 -
 drivers/staging/android/uapi/sync.h | 36 +-
 2 files changed, 67 insertions(+), 45 deletions(-)

diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index 3a8f210..ae81c95 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 || data.pad) {
+   err = -EINVAL;
+   goto err_put_fd;
+   }
+
fence2 = sync_file_fdget(data.fd2);
if (!fence2) {
err = -ENOENT;
@@ -479,13 +484,9 @@ err_put_fd:
return err;
 }

-static int sync_fill_fence_info(struct fence *fence, void *data, int size)
+static void sync_fill_fence_info(struct fence *fence,
+   struct sync_fence_info *info)
 {
-   struct sync_fence_info *info = data;
-
-   if (size < sizeof(*info))
-   return -ENOMEM;
-
strlcpy(info->obj_name, fence->ops->get_timeline_name(fence),
sizeof(info->obj_name));
strlcpy(info->driver_name, fence->ops->get_driver_name(fence),
@@ -495,58 +496,63 @@ static int sync_fill_fence_info(struct fence *fence, void 
*data, int size)
else
info->status = 0;
info->timestamp_ns = ktime_to_ns(fence->timestamp);
-
-   return sizeof(*info);
 }

 static long sync_file_ioctl_fence_info(struct sync_file *sync_file,
unsigned long arg)
 {
-   struct sync_file_info *info;
+   struct sync_file_info info;
+   struct sync_fence_info *fence_info = NULL;
__u32 size;
-   __u32 len = 0;
int ret, i;

-   if (copy_from_user(, (void __user *)arg, sizeof(size)))
+   if (copy_from_user(, (void __user *)arg, sizeof(info)))
return -EFAULT;

-   if (size < sizeof(struct sync_file_info))
+   if (info.flags || info.pad)
return -EINVAL;

-   if (size > 4096)
-   size = 4096;
-
-   info =