Skip to content

Commit

Permalink
UPSTREAM: drm/virtio: set seqno for dma-fence
Browse files Browse the repository at this point in the history
This is motivated by having meaningful ftrace events, but it also
fixes use cases where dma_fence_is_later is called, such as in
sync_file_merge.

In other drivers, fence creation and cmdbuf submission normally
happen atomically,

  mutex_lock();
  fence = dma_fence_create(..., ++timeline->seqno);
  submit_cmdbuf();
  mutex_unlock();

and have no such issue.  But in our driver, because most ioctls
queue commands into ctrlq, we do not want to grab a lock.  Instead,
we set seqno to 0 when a fence is created, and update it when the
command is finally queued and the seqno is known.

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20190429220825.156644-1-olvaffe@gmail.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
(cherry picked from commit efe2bf9)
Signed-off-by: Gurchetan Singh <gurchetansingh@chromium.org>

BUG=chromium:924405
TEST=glxgears in Crostini

Change-Id: If4e3a085ba9569814fc3c398b1d308a56a5dcaa9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/1684746
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Dominik Behr <dbehr@chromium.org>
Reviewed-by: Stéphane Marchesin <marcheu@chromium.org>
  • Loading branch information
olvaffe authored and Commit Bot committed Jul 15, 2019
1 parent 45e5f47 commit 2f22ba2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
1 change: 0 additions & 1 deletion drivers/gpu/drm/virtio/virtgpu_drv.h
Expand Up @@ -109,7 +109,6 @@ struct virtio_gpu_fence {
struct dma_fence f;
struct virtio_gpu_fence_driver *drv;
struct list_head node;
uint64_t seq;
};
#define to_virtio_fence(x) \
container_of(x, struct virtio_gpu_fence, f)
Expand Down
17 changes: 10 additions & 7 deletions drivers/gpu/drm/virtio/virtgpu_fence.c
Expand Up @@ -40,16 +40,14 @@ bool virtio_fence_signaled(struct dma_fence *f)
{
struct virtio_gpu_fence *fence = to_virtio_fence(f);

if (atomic64_read(&fence->drv->last_seq) >= fence->seq)
if (atomic64_read(&fence->drv->last_seq) >= fence->f.seqno)
return true;
return false;
}

static void virtio_fence_value_str(struct dma_fence *f, char *str, int size)
{
struct virtio_gpu_fence *fence = to_virtio_fence(f);

snprintf(str, size, "%llu", fence->seq);
snprintf(str, size, "%llu", f->seqno);
}

static void virtio_timeline_value_str(struct dma_fence *f, char *str, int size)
Expand All @@ -76,6 +74,11 @@ struct virtio_gpu_fence *virtio_gpu_fence_alloc(struct virtio_gpu_device *vgdev)
return fence;

fence->drv = drv;

/* This only partially initializes the fence because the seqno is
* unknown yet. The fence must not be used outside of the driver
* until virtio_gpu_fence_emit is called.
*/
dma_fence_init(&fence->f, &virtio_fence_ops, &drv->lock, drv->context, 0);

return fence;
Expand All @@ -89,13 +92,13 @@ int virtio_gpu_fence_emit(struct virtio_gpu_device *vgdev,
unsigned long irq_flags;

spin_lock_irqsave(&drv->lock, irq_flags);
fence->seq = ++drv->sync_seq;
fence->f.seqno = ++drv->sync_seq;
dma_fence_get(&fence->f);
list_add_tail(&fence->node, &drv->fences);
spin_unlock_irqrestore(&drv->lock, irq_flags);

cmd_hdr->flags |= cpu_to_le32(VIRTIO_GPU_FLAG_FENCE);
cmd_hdr->fence_id = cpu_to_le64(fence->seq);
cmd_hdr->fence_id = cpu_to_le64(fence->f.seqno);
return 0;
}

Expand All @@ -109,7 +112,7 @@ void virtio_gpu_fence_event_process(struct virtio_gpu_device *vgdev,
spin_lock_irqsave(&drv->lock, irq_flags);
atomic64_set(&vgdev->fence_drv.last_seq, last_seq);
list_for_each_entry_safe(fence, tmp, &drv->fences, node) {
if (last_seq < fence->seq)
if (last_seq < fence->f.seqno)
continue;
dma_fence_signal_locked(&fence->f);
list_del(&fence->node);
Expand Down

0 comments on commit 2f22ba2

Please sign in to comment.