sync_file: Return consistent status in SYNC_IOC_FILE_INFO

sync_file_ioctl_fence_info has a race between filling the status
of the underlying fences and the overall status of the sync_file.
If fence transitions in the time frame between its sync_fill_fence_info
and the later dma_fence_is_signaled for the sync_file, the returned
information is inconsistent showing non-signaled underlying fences but
an overall signaled state.

This patch changes sync_file_ioctl_fence_info to track what has been
encoded and using that as the overall sync_file status.

Tested-by: Vamsidhar Reddy Gaddam <vamsidhar.gaddam@arm.com>
Signed-off-by: John Einar Reitan <john.reitan@arm.com>
Cc: Sumit Semwal <sumit.semwal@linaro.org>
Cc: Gustavo Padovan <gustavo@padovan.org>
Cc: dri-devel@lists.freedesktop.org
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20171009134936.27219-1-john.reitan@arm.com
This commit is contained in:
John Einar Reitan 2017-10-09 15:49:36 +02:00 коммит произвёл Gustavo Padovan
Родитель 7827912725
Коммит f7974880cf
1 изменённых файлов: 12 добавлений и 5 удалений

Просмотреть файл

@ -383,7 +383,7 @@ err_put_fd:
return err; return err;
} }
static void sync_fill_fence_info(struct dma_fence *fence, static int sync_fill_fence_info(struct dma_fence *fence,
struct sync_fence_info *info) struct sync_fence_info *info)
{ {
strlcpy(info->obj_name, fence->ops->get_timeline_name(fence), strlcpy(info->obj_name, fence->ops->get_timeline_name(fence),
@ -399,6 +399,8 @@ static void sync_fill_fence_info(struct dma_fence *fence,
test_bit(DMA_FENCE_FLAG_TIMESTAMP_BIT, &fence->flags) ? test_bit(DMA_FENCE_FLAG_TIMESTAMP_BIT, &fence->flags) ?
ktime_to_ns(fence->timestamp) : ktime_to_ns(fence->timestamp) :
ktime_set(0, 0); ktime_set(0, 0);
return info->status;
} }
static long sync_file_ioctl_fence_info(struct sync_file *sync_file, static long sync_file_ioctl_fence_info(struct sync_file *sync_file,
@ -424,8 +426,12 @@ static long sync_file_ioctl_fence_info(struct sync_file *sync_file,
* sync_fence_info and return the actual number of fences on * sync_fence_info and return the actual number of fences on
* info->num_fences. * info->num_fences.
*/ */
if (!info.num_fences) if (!info.num_fences) {
info.status = dma_fence_is_signaled(sync_file->fence);
goto no_fences; goto no_fences;
} else {
info.status = 1;
}
if (info.num_fences < num_fences) if (info.num_fences < num_fences)
return -EINVAL; return -EINVAL;
@ -435,8 +441,10 @@ static long sync_file_ioctl_fence_info(struct sync_file *sync_file,
if (!fence_info) if (!fence_info)
return -ENOMEM; return -ENOMEM;
for (i = 0; i < num_fences; i++) for (i = 0; i < num_fences; i++) {
sync_fill_fence_info(fences[i], &fence_info[i]); int status = sync_fill_fence_info(fences[i], &fence_info[i]);
info.status = info.status <= 0 ? info.status : status;
}
if (copy_to_user(u64_to_user_ptr(info.sync_fence_info), fence_info, if (copy_to_user(u64_to_user_ptr(info.sync_fence_info), fence_info,
size)) { size)) {
@ -446,7 +454,6 @@ static long sync_file_ioctl_fence_info(struct sync_file *sync_file,
no_fences: no_fences:
sync_file_get_name(sync_file, info.name, sizeof(info.name)); sync_file_get_name(sync_file, info.name, sizeof(info.name));
info.status = dma_fence_is_signaled(sync_file->fence);
info.num_fences = num_fences; info.num_fences = num_fences;
if (copy_to_user((void __user *)arg, &info, sizeof(info))) if (copy_to_user((void __user *)arg, &info, sizeof(info)))