Skip to content

Commit f797488

Browse files
johnreitanGustavo Padovan
authored andcommitted
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
1 parent 7827912 commit f797488

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

‎drivers/dma-buf/sync_file.c‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ static long sync_file_ioctl_merge(struct sync_file *sync_file,
383383
return err;
384384
}
385385

386-
static void sync_fill_fence_info(struct dma_fence *fence,
386+
static int sync_fill_fence_info(struct dma_fence *fence,
387387
struct sync_fence_info *info)
388388
{
389389
strlcpy(info->obj_name, fence->ops->get_timeline_name(fence),
@@ -399,6 +399,8 @@ static void sync_fill_fence_info(struct dma_fence *fence,
399399
test_bit(DMA_FENCE_FLAG_TIMESTAMP_BIT, &fence->flags) ?
400400
ktime_to_ns(fence->timestamp) :
401401
ktime_set(0, 0);
402+
403+
return info->status;
402404
}
403405

404406
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,
424426
* sync_fence_info and return the actual number of fences on
425427
* info->num_fences.
426428
*/
427-
if (!info.num_fences)
429+
if (!info.num_fences) {
430+
info.status = dma_fence_is_signaled(sync_file->fence);
428431
goto no_fences;
432+
} else {
433+
info.status = 1;
434+
}
429435

430436
if (info.num_fences < num_fences)
431437
return -EINVAL;
@@ -435,8 +441,10 @@ static long sync_file_ioctl_fence_info(struct sync_file *sync_file,
435441
if (!fence_info)
436442
return -ENOMEM;
437443

438-
for (i = 0; i < num_fences; i++)
439-
sync_fill_fence_info(fences[i], &fence_info[i]);
444+
for (i = 0; i < num_fences; i++) {
445+
int status = sync_fill_fence_info(fences[i], &fence_info[i]);
446+
info.status = info.status <= 0 ? info.status : status;
447+
}
440448

441449
if (copy_to_user(u64_to_user_ptr(info.sync_fence_info), fence_info,
442450
size)) {
@@ -446,7 +454,6 @@ static long sync_file_ioctl_fence_info(struct sync_file *sync_file,
446454

447455
no_fences:
448456
sync_file_get_name(sync_file, info.name, sizeof(info.name));
449-
info.status = dma_fence_is_signaled(sync_file->fence);
450457
info.num_fences = num_fences;
451458

452459
if (copy_to_user((void __user *)arg, &info, sizeof(info)))

0 commit comments

Comments
 (0)