Skip to contentSkip to conversation

virgl: fence fd support

PATCH Superseded Robert Foss 3 participants 33 messages Oct 25, 2018 – Nov 5, 2018

Subsystems (4)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#7 lore raw

PATCH 2/5 drm/virtio: add uapi for in and out explicit fences

In reply to Robert Foss

Add a new field called fence_fd that will be used by userspace to send in-fences to the kernel and receive out-fences created by the kernel.

This uapi enables virtio to take advantage of explicit synchronization of dma-bufs.

There are two new flags:

* VIRTGPU_EXECBUF_FENCE_FD_IN to be used when passing an in-fence fd.
* VIRTGPU_EXECBUF_FENCE_FD_OUT to be used when requesting an out-fence fd

The execbuffer IOCTL is now read-write to allow the userspace to read the out-fence.

On error -1 should be returned in the fence_fd field.

---
Changes since v2:
- Since exbuf-flags is a new flag, check that unsupported flags aren't set.

 drivers/gpu/drm/virtio/virtgpu_ioctl.c |  5 +++++
 include/uapi/drm/virtgpu_drm.h         | 13 ++++++++++---
 2 files changed, 15 insertions(+), 3 deletions(-)
drivers/gpu/drm/virtio/virtgpu_ioctl.c +5 -0
index d01a9ed100d1..1af289b28fc4 100644
@@ -116,9 +116,14 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
 	struct ww_acquire_ctx ticket;
 	void *buf;
 
+	exbuf->fence_fd = -1;
+
 	if (vgdev->has_virgl_3d == false)
 		return -ENOSYS;
 
+	if ((exbuf->flags & ~VIRTGPU_EXECBUF_FLAGS))
+		return -EINVAL;
+
 	INIT_LIST_HEAD(&validate_list);
 	if (exbuf->num_bo_handles) {
 
include/uapi/drm/virtgpu_drm.h +10 -3
index 9a781f0611df..91062f4ac7c5 100644
@@ -47,6 +47,13 @@ extern "C" {
 #define DRM_VIRTGPU_WAIT     0x08
 #define DRM_VIRTGPU_GET_CAPS  0x09
 
+#define VIRTGPU_EXECBUF_FENCE_FD_IN	0x01
+#define VIRTGPU_EXECBUF_FENCE_FD_OUT	0x02
+#define VIRTGPU_EXECBUF_FLAGS  (\
+		VIRTGPU_EXECBUF_FENCE_FD_IN |\
+		VIRTGPU_EXECBUF_FENCE_FD_OUT |\
+		0)
+
 struct drm_virtgpu_map {
 	__u64 offset; /* use for mmap system call */
 	__u32 handle;
@@ -54,12 +61,12 @@ struct drm_virtgpu_map {
 };
 
 struct drm_virtgpu_execbuffer {
-	__u32		flags;		/* for future use */
+	__u32 flags;
 	__u32 size;
 	__u64 command; /* void* */
 	__u64 bo_handles;
 	__u32 num_bo_handles;
-	__u32 pad;
+	__s32 fence_fd;
 };
 
 #define VIRTGPU_PARAM_3D_FEATURES 1 /* do we have 3D features in the hw */
@@ -137,7 +144,7 @@ struct drm_virtgpu_get_caps {
 	DRM_IOWR(DRM_COMMAND_BASE + DRM_VIRTGPU_MAP, struct drm_virtgpu_map)
 
 #define DRM_IOCTL_VIRTGPU_EXECBUFFER \
-	DRM_IOW(DRM_COMMAND_BASE + DRM_VIRTGPU_EXECBUFFER,\
+	DRM_IOWR(DRM_COMMAND_BASE + DRM_VIRTGPU_EXECBUFFER,\
 		struct drm_virtgpu_execbuffer)
 
 #define DRM_IOCTL_VIRTGPU_GETPARAM \
Signature · 1 line
2.17.1
#25 lore raw

PATCH 4/5 drm/virtio: add out-fences support for explicit synchronization

In reply to Robert Foss

From: Gustavo Padovan <[email protected]>

On the out-fence side we get fence returned by the submitted draw call and attach it to a sync_file and send the sync_file fd to userspace. On error -1 is returned to userspace.

---
 drivers/gpu/drm/virtio/virtgpu_ioctl.c | 50 +++++++++++++++++++-------
 1 file changed, 38 insertions(+), 12 deletions(-)
drivers/gpu/drm/virtio/virtgpu_ioctl.c +38 -12
index 0368195966aa..32e714a1c753 100644
@@ -106,7 +106,7 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
 	struct virtio_gpu_device *vgdev = dev->dev_private;
 	struct virtio_gpu_fpriv *vfpriv = drm_file->driver_priv;
 	struct drm_gem_object *gobj;
-	struct virtio_gpu_fence *fence;
+	struct virtio_gpu_fence *out_fence;
 	struct virtio_gpu_object *qobj;
 	int ret;
 	uint32_t *bo_handles = NULL;
@@ -116,7 +116,9 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
 	int i;
 	struct ww_acquire_ctx ticket;
 	struct dma_fence *in_fence = NULL;
+	struct sync_file *sync_file;
 	int in_fence_fd = exbuf->fence_fd;
+	int out_fence_fd = -1;
 	void *buf;
 
 	exbuf->fence_fd = -1;
@@ -143,6 +145,14 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
 		}
 	}
 
+	if (exbuf->flags & VIRTGPU_EXECBUF_FENCE_FD_OUT) {
+		out_fence_fd = get_unused_fd_flags(O_CLOEXEC);
+		if (out_fence_fd < 0) {
+			ret = out_fence_fd;
+			goto out_in_fence;
+		}
+	}
+
 	INIT_LIST_HEAD(&validate_list);
 	if (exbuf->num_bo_handles) {
 
@@ -153,21 +163,21 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
 					   GFP_KERNEL | __GFP_ZERO);
 		if (!bo_handles || !buflist) {
 			ret = -ENOMEM;
-			goto out_in_fence;
+			goto out_unused_fd;
 		}
 
 		user_bo_handles = (void __user *)(uintptr_t)exbuf->bo_handles;
 		if (copy_from_user(bo_handles, user_bo_handles,
 				   exbuf->num_bo_handles * sizeof(uint32_t))) {
 			ret = -EFAULT;
-			goto out_in_fence;
+			goto out_unused_fd;
 		}
 
 		for (i = 0; i < exbuf->num_bo_handles; i++) {
 			gobj = drm_gem_object_lookup(drm_file, bo_handles[i]);
 			if (!gobj) {
 				ret = -ENOENT;
-				goto out_in_fence;
+				goto out_unused_fd;
 			}
 
 			qobj = gem_to_virtio_gpu_obj(gobj);
@@ -190,11 +200,22 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
 		goto out_unresv;
 	}
 
-	fence = virtio_gpu_fence_alloc(vgdev);
-	if (!fence) {
-		kfree(buf);
+	out_fence = virtio_gpu_fence_alloc(vgdev);
+	if(!out_fence) {
 		ret = -ENOMEM;
-		goto out_unresv;
+		goto out_memdup;
+	}
+
+	if (out_fence_fd >= 0) {
+		sync_file = sync_file_create(&out_fence->f);
+		if (!sync_file) {
+			dma_fence_put(&out_fence->f);
+			ret = -ENOMEM;
+			goto out_memdup;
+		}
+
+		exbuf->fence_fd = out_fence_fd;
+		fd_install(out_fence_fd, sync_file->file);
 	}
 
 	if (in_fence) {
@@ -203,23 +224,28 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
 	}
 
 	virtio_gpu_cmd_submit(vgdev, buf, exbuf->size,
-			      vfpriv->ctx_id, fence);
+			      vfpriv->ctx_id, out_fence);
 
-	ttm_eu_fence_buffer_objects(&ticket, &validate_list, &fence->f);
+	ttm_eu_fence_buffer_objects(&ticket, &validate_list, &out_fence->f);
 
 	/* fence the command bo */
 	virtio_gpu_unref_list(&validate_list);
 	kvfree(buflist);
-	dma_fence_put(&fence->f);
 	return 0;
 
+out_memdup:
+	kfree(buf);
 out_unresv:
 	ttm_eu_backoff_reservation(&ticket, &validate_list);
 out_free:
 	virtio_gpu_unref_list(&validate_list);
-out_in_fence:
+out_unused_fd:
 	kvfree(bo_handles);
 	kvfree(buflist);
+
+	if (out_fence_fd >= 0)
+		put_unused_fd(out_fence_fd);
+out_in_fence:
 	dma_fence_put(in_fence);
 	return ret;
 }
Signature · 1 line
2.17.1
#0 lore raw

cover virgl: fence fd support

This series implements fence support for drm/virtio and has been tested using qemu, kmscube and the below branches.

Rob Herring solved a reference counting issue and suggested a context check for the execbuf ioctl, his changes have been included in the below commits to keep the tree working at all commits.

The linux series can be found here:
https://gitlab.collabora.com/robertfoss/linux/commits/virtio_fences_v3

As for mesa, the branch can be found here:
https://gitlab.collabora.com/robertfoss/mesa/commits/virtio_fences_v3

Changes since v2:
- drm/virtio: add virtio_gpu_alloc_fence()
- Forward port and fix compilation issues
- drm/virtio: add uapi for in and out explicit fences
- Check exbuf->flags for unsupported flags

Gustavo Padovan (4):
drm/virtio: add virtio_gpu_alloc_fence()
drm/virtio: add in-fences support for explicit synchronization drm/virtio: add out-fences support for explicit synchronization drm/virtio: bump driver version after explicit synchronization
addition

Robert Foss (1):
drm/virtio: add uapi for in and out explicit fences

 drivers/gpu/drm/virtio/virtgpu_drv.h   |  22 +++--
 drivers/gpu/drm/virtio/virtgpu_fence.c |  41 ++++++---
 drivers/gpu/drm/virtio/virtgpu_ioctl.c | 118 +++++++++++++++++++++----
 drivers/gpu/drm/virtio/virtgpu_plane.c |  46 ++++++++--
 drivers/gpu/drm/virtio/virtgpu_vq.c    |  16 ++--
 include/uapi/drm/virtgpu_drm.h         |  13 ++-
 6 files changed, 201 insertions(+), 55 deletions(-)
Signature · 6 lines
2.17.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw

PATCH 1/5 drm/virtio: add virtio_gpu_alloc_fence()

From: Gustavo Padovan <[email protected]>

Refactor fence creation to remove the potential allocation failure from the cmd_submit and atomic_commit paths. Now the fence should be allocated first and just after we should proceed with the rest of the execution.

---
Changes since v2:
- Forward ported to upstream/master (4.20)

 drivers/gpu/drm/virtio/virtgpu_drv.h   | 18 ++++++----
 drivers/gpu/drm/virtio/virtgpu_fence.c | 41 ++++++++++++++++-------
 drivers/gpu/drm/virtio/virtgpu_ioctl.c | 38 +++++++++++++++++----
 drivers/gpu/drm/virtio/virtgpu_plane.c | 46 +++++++++++++++++++++++---
 drivers/gpu/drm/virtio/virtgpu_vq.c    | 16 ++++-----
 5 files changed, 121 insertions(+), 38 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.h +11 -7
index 65605e207bbe..e8d2a67d8049 100644
@@ -127,6 +127,7 @@ struct virtio_gpu_framebuffer {
 	int x1, y1, x2, y2; /* dirty rect */
 	spinlock_t dirty_lock;
 	uint32_t hw_res_handle;
+	struct virtio_gpu_fence *fence;
 };
 #define to_virtio_gpu_framebuffer(x) \
 	container_of(x, struct virtio_gpu_framebuffer, base)
@@ -263,7 +264,7 @@ void virtio_gpu_cmd_transfer_to_host_2d(struct virtio_gpu_device *vgdev,
 					uint32_t resource_id, uint64_t offset,
 					__le32 width, __le32 height,
 					__le32 x, __le32 y,
-					struct virtio_gpu_fence **fence);
+					struct virtio_gpu_fence *fence);
 void virtio_gpu_cmd_resource_flush(struct virtio_gpu_device *vgdev,
 				   uint32_t resource_id,
 				   uint32_t x, uint32_t y,
@@ -275,7 +276,7 @@ void virtio_gpu_cmd_set_scanout(struct virtio_gpu_device *vgdev,
 int virtio_gpu_object_attach(struct virtio_gpu_device *vgdev,
 			     struct virtio_gpu_object *obj,
 			     uint32_t resource_id,
-			     struct virtio_gpu_fence **fence);
+			     struct virtio_gpu_fence *fence);
 int virtio_gpu_attach_status_page(struct virtio_gpu_device *vgdev);
 int virtio_gpu_detach_status_page(struct virtio_gpu_device *vgdev);
 void virtio_gpu_cursor_ping(struct virtio_gpu_device *vgdev,
@@ -299,21 +300,21 @@ void virtio_gpu_cmd_context_detach_resource(struct virtio_gpu_device *vgdev,
 					    uint32_t resource_id);
 void virtio_gpu_cmd_submit(struct virtio_gpu_device *vgdev,
 			   void *data, uint32_t data_size,
-			   uint32_t ctx_id, struct virtio_gpu_fence **fence);
+			   uint32_t ctx_id, struct virtio_gpu_fence *fence);
 void virtio_gpu_cmd_transfer_from_host_3d(struct virtio_gpu_device *vgdev,
 					  uint32_t resource_id, uint32_t ctx_id,
 					  uint64_t offset, uint32_t level,
 					  struct virtio_gpu_box *box,
-					  struct virtio_gpu_fence **fence);
+					  struct virtio_gpu_fence *fence);
 void virtio_gpu_cmd_transfer_to_host_3d(struct virtio_gpu_device *vgdev,
 					uint32_t resource_id, uint32_t ctx_id,
 					uint64_t offset, uint32_t level,
 					struct virtio_gpu_box *box,
-					struct virtio_gpu_fence **fence);
+					struct virtio_gpu_fence *fence);
 void
 virtio_gpu_cmd_resource_create_3d(struct virtio_gpu_device *vgdev,
 				  struct virtio_gpu_resource_create_3d *rc_3d,
-				  struct virtio_gpu_fence **fence);
+				  struct virtio_gpu_fence *fence);
 void virtio_gpu_ctrl_ack(struct virtqueue *vq);
 void virtio_gpu_cursor_ack(struct virtqueue *vq);
 void virtio_gpu_fence_ack(struct virtqueue *vq);
@@ -341,9 +342,12 @@ void virtio_gpu_ttm_fini(struct virtio_gpu_device *vgdev);
 int virtio_gpu_mmap(struct file *filp, struct vm_area_struct *vma);
 
 /* virtio_gpu_fence.c */
+struct virtio_gpu_fence *virtio_gpu_fence_alloc(
+	struct virtio_gpu_device *vgdev);
+void virtio_gpu_fence_cleanup(struct virtio_gpu_fence *fence);
 int virtio_gpu_fence_emit(struct virtio_gpu_device *vgdev,
 			  struct virtio_gpu_ctrl_hdr *cmd_hdr,
-			  struct virtio_gpu_fence **fence);
+			  struct virtio_gpu_fence *fence);
 void virtio_gpu_fence_event_process(struct virtio_gpu_device *vdev,
 				    u64 last_seq);
 
drivers/gpu/drm/virtio/virtgpu_fence.c +29 -12

57 lines not on this page · raw message

drivers/gpu/drm/virtio/virtgpu_ioctl.c +32 -6
index 7bdf6f0e58a5..d01a9ed100d1 100644
@@ -168,8 +168,15 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
 		ret = PTR_ERR(buf);
 		goto out_unresv;
 	}
+
+	fence = virtio_gpu_fence_alloc(vgdev);
+	if (!fence) {
+		kfree(buf);
+		ret = -ENOMEM;
+		goto out_unresv;
+	}
 	virtio_gpu_cmd_submit(vgdev, buf, exbuf->size,
-			      vfpriv->ctx_id, &fence);
+			      vfpriv->ctx_id, fence);
 
 	ttm_eu_fence_buffer_objects(&ticket, &validate_list, &fence->f);
 
@@ -288,11 +295,17 @@ static int virtio_gpu_resource_create_ioctl(struct drm_device *dev, void *data,
 		rc_3d.nr_samples = cpu_to_le32(rc->nr_samples);
 		rc_3d.flags = cpu_to_le32(rc->flags);
 
+		fence = virtio_gpu_fence_alloc(vgdev);
+		if (!fence) {
+			ret = -ENOMEM;
+			goto fail_fence;
+		}
+
 		virtio_gpu_cmd_resource_create_3d(vgdev, &rc_3d, NULL);
-		ret = virtio_gpu_object_attach(vgdev, qobj, res_id, &fence);
+		ret = virtio_gpu_object_attach(vgdev, qobj, res_id, fence);
 		if (ret) {
-			ttm_eu_backoff_reservation(&ticket, &validate_list);
-			goto fail_unref;
+			virtio_gpu_fence_cleanup(fence);
+			goto fail_fence;
 		}
 		ttm_eu_fence_buffer_objects(&ticket, &validate_list, &fence->f);
 	}
@@ -319,6 +332,8 @@ static int virtio_gpu_resource_create_ioctl(struct drm_device *dev, void *data,
 		dma_fence_put(&fence->f);
 	}
 	return 0;
+fail_fence:
+ttm_eu_backoff_reservation(&ticket, &validate_list);
 fail_unref:
 	if (vgdev->has_virgl_3d) {
 		virtio_gpu_unref_list(&validate_list);
@@ -383,10 +398,16 @@ static int virtio_gpu_transfer_from_host_ioctl(struct drm_device *dev,
 		goto out_unres;
 
 	convert_to_hw_box(&box, &args->box);
+
+	fence = virtio_gpu_fence_alloc(vgdev);
+	if (!fence) {
+		ret = -ENOMEM;
+		goto out_unres;
+	}
 	virtio_gpu_cmd_transfer_from_host_3d
 		(vgdev, qobj->hw_res_handle,
 		 vfpriv->ctx_id, offset, args->level,
-		 &box, &fence);
+		 &box, fence);
 	reservation_object_add_excl_fence(qobj->tbo.resv,
 					  &fence->f);
 
@@ -432,10 +453,15 @@ static int virtio_gpu_transfer_to_host_ioctl(struct drm_device *dev, void *data,
 			(vgdev, qobj->hw_res_handle, offset,
 			 box.w, box.h, box.x, box.y, NULL);
 	} else {
+		fence = virtio_gpu_fence_alloc(vgdev);
+		if (!fence) {
+			ret = -ENOMEM;
+			goto out_unres;
+		}
 		virtio_gpu_cmd_transfer_to_host_3d
 			(vgdev, qobj->hw_res_handle,
 			 vfpriv ? vfpriv->ctx_id : 0, offset,
-			 args->level, &box, &fence);
+			 args->level, &box, fence);
 		reservation_object_add_excl_fence(qobj->tbo.resv,
 						  &fence->f);
 		dma_fence_put(&fence->f);
drivers/gpu/drm/virtio/virtgpu_plane.c +41 -5

73 lines not on this page · raw message

drivers/gpu/drm/virtio/virtgpu_vq.c +8 -8
index 020070d483d3..93593c496fdb 100644
@@ -319,7 +319,7 @@ static int virtio_gpu_queue_ctrl_buffer(struct virtio_gpu_device *vgdev,
 static int virtio_gpu_queue_fenced_ctrl_buffer(struct virtio_gpu_device *vgdev,
 					       struct virtio_gpu_vbuffer *vbuf,
 					       struct virtio_gpu_ctrl_hdr *hdr,
-					       struct virtio_gpu_fence **fence)
+					       struct virtio_gpu_fence *fence)
 {
 	struct virtqueue *vq = vgdev->ctrlq.vq;
 	int rc;
@@ -485,7 +485,7 @@ void virtio_gpu_cmd_transfer_to_host_2d(struct virtio_gpu_device *vgdev,
 					uint32_t resource_id, uint64_t offset,
 					__le32 width, __le32 height,
 					__le32 x, __le32 y,
-					struct virtio_gpu_fence **fence)
+					struct virtio_gpu_fence *fence)
 {
 	struct virtio_gpu_transfer_to_host_2d *cmd_p;
 	struct virtio_gpu_vbuffer *vbuf;
@@ -509,7 +509,7 @@ virtio_gpu_cmd_resource_attach_backing(struct virtio_gpu_device *vgdev,
 				       uint32_t resource_id,
 				       struct virtio_gpu_mem_entry *ents,
 				       uint32_t nents,
-				       struct virtio_gpu_fence **fence)
+				       struct virtio_gpu_fence *fence)
 {
 	struct virtio_gpu_resource_attach_backing *cmd_p;
 	struct virtio_gpu_vbuffer *vbuf;
@@ -764,7 +764,7 @@ void virtio_gpu_cmd_context_detach_resource(struct virtio_gpu_device *vgdev,
 void
 virtio_gpu_cmd_resource_create_3d(struct virtio_gpu_device *vgdev,
 				  struct virtio_gpu_resource_create_3d *rc_3d,
-				  struct virtio_gpu_fence **fence)
+				  struct virtio_gpu_fence *fence)
 {
 	struct virtio_gpu_resource_create_3d *cmd_p;
 	struct virtio_gpu_vbuffer *vbuf;
@@ -783,7 +783,7 @@ void virtio_gpu_cmd_transfer_to_host_3d(struct virtio_gpu_device *vgdev,
 					uint32_t resource_id, uint32_t ctx_id,
 					uint64_t offset, uint32_t level,
 					struct virtio_gpu_box *box,
-					struct virtio_gpu_fence **fence)
+					struct virtio_gpu_fence *fence)
 {
 	struct virtio_gpu_transfer_host_3d *cmd_p;
 	struct virtio_gpu_vbuffer *vbuf;
@@ -805,7 +805,7 @@ void virtio_gpu_cmd_transfer_from_host_3d(struct virtio_gpu_device *vgdev,
 					  uint32_t resource_id, uint32_t ctx_id,
 					  uint64_t offset, uint32_t level,
 					  struct virtio_gpu_box *box,
-					  struct virtio_gpu_fence **fence)
+					  struct virtio_gpu_fence *fence)
 {
 	struct virtio_gpu_transfer_host_3d *cmd_p;
 	struct virtio_gpu_vbuffer *vbuf;
@@ -825,7 +825,7 @@ void virtio_gpu_cmd_transfer_from_host_3d(struct virtio_gpu_device *vgdev,
 
 void virtio_gpu_cmd_submit(struct virtio_gpu_device *vgdev,
 			   void *data, uint32_t data_size,
-			   uint32_t ctx_id, struct virtio_gpu_fence **fence)
+			   uint32_t ctx_id, struct virtio_gpu_fence *fence)
 {
 	struct virtio_gpu_cmd_submit *cmd_p;
 	struct virtio_gpu_vbuffer *vbuf;
@@ -846,7 +846,7 @@ void virtio_gpu_cmd_submit(struct virtio_gpu_device *vgdev,
 int virtio_gpu_object_attach(struct virtio_gpu_device *vgdev,
 			     struct virtio_gpu_object *obj,
 			     uint32_t resource_id,
-			     struct virtio_gpu_fence **fence)
+			     struct virtio_gpu_fence *fence)
 {
 	struct virtio_gpu_mem_entry *ents;
 	struct scatterlist *sg;
Signature · 6 lines
2.17.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#22 lore raw

PATCH 3/5 drm/virtio: add in-fences support for explicit synchronization

In reply to Robert Foss

From: Gustavo Padovan <[email protected]>

When the execbuf call receives an in-fence it will get the dma_fence related to that fence fd and wait on it before submitting the draw call.

---
 drivers/gpu/drm/virtio/virtgpu_ioctl.c | 43 ++++++++++++++++++++------
 1 file changed, 34 insertions(+), 9 deletions(-)
drivers/gpu/drm/virtio/virtgpu_ioctl.c +34 -9
index 1af289b28fc4..0368195966aa 100644
@@ -28,6 +28,7 @@
 #include <drm/drmP.h>
 #include <drm/virtgpu_drm.h>
 #include <drm/ttm/ttm_execbuf_util.h>
+#include <linux/sync_file.h>
 
 #include "virtgpu_drv.h"
 
@@ -114,6 +115,8 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
 	struct ttm_validate_buffer *buflist = NULL;
 	int i;
 	struct ww_acquire_ctx ticket;
+	struct dma_fence *in_fence = NULL;
+	int in_fence_fd = exbuf->fence_fd;
 	void *buf;
 
 	exbuf->fence_fd = -1;
@@ -124,6 +127,22 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
 	if ((exbuf->flags & ~VIRTGPU_EXECBUF_FLAGS))
 		return -EINVAL;
 
+	if (exbuf->flags & VIRTGPU_EXECBUF_FENCE_FD_IN) {
+		in_fence = sync_file_get_fence(in_fence_fd);
+		if (!in_fence)
+			return -EINVAL;
+
+		/*
+		 * Wait if the fence is from a foreign context, or if the fence
+		 * array contains any fence from a foreign context.
+		 */
+		if (!dma_fence_match_context(in_fence, vgdev->fence_drv.context)) {
+			ret = dma_fence_wait(in_fence, true);
+			if (ret)
+				return ret;
+		}
+	}
+
 	INIT_LIST_HEAD(&validate_list);
 	if (exbuf->num_bo_handles) {
 
@@ -133,26 +152,22 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
 					   sizeof(struct ttm_validate_buffer),
 					   GFP_KERNEL | __GFP_ZERO);
 		if (!bo_handles || !buflist) {
-			kvfree(bo_handles);
-			kvfree(buflist);
-			return -ENOMEM;
+			ret = -ENOMEM;
+			goto out_in_fence;
 		}
 
 		user_bo_handles = (void __user *)(uintptr_t)exbuf->bo_handles;
 		if (copy_from_user(bo_handles, user_bo_handles,
 				   exbuf->num_bo_handles * sizeof(uint32_t))) {
 			ret = -EFAULT;
-			kvfree(bo_handles);
-			kvfree(buflist);
-			return ret;
+			goto out_in_fence;
 		}
 
 		for (i = 0; i < exbuf->num_bo_handles; i++) {
 			gobj = drm_gem_object_lookup(drm_file, bo_handles[i]);
 			if (!gobj) {
-				kvfree(bo_handles);
-				kvfree(buflist);
-				return -ENOENT;
+				ret = -ENOENT;
+				goto out_in_fence;
 			}
 
 			qobj = gem_to_virtio_gpu_obj(gobj);
@@ -161,6 +176,7 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
 			list_add(&buflist[i].head, &validate_list);
 		}
 		kvfree(bo_handles);
+		bo_handles = NULL;
 	}
 
 	ret = virtio_gpu_object_list_validate(&ticket, &validate_list);
@@ -180,6 +196,12 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
 		ret = -ENOMEM;
 		goto out_unresv;
 	}
+
+	if (in_fence) {
+		dma_fence_put(in_fence);
+		in_fence = NULL;
+	}
+
 	virtio_gpu_cmd_submit(vgdev, buf, exbuf->size,
 			      vfpriv->ctx_id, fence);
 
@@ -195,7 +217,10 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
 	ttm_eu_backoff_reservation(&ticket, &validate_list);
 out_free:
 	virtio_gpu_unref_list(&validate_list);
+out_in_fence:
+	kvfree(bo_handles);
 	kvfree(buflist);
+	dma_fence_put(in_fence);
 	return ret;
 }
 
Signature · 6 lines
2.17.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#28 lore raw

PATCH 5/5 drm/virtio: bump driver version after explicit synchronization addition

In reply to Robert Foss

From: Gustavo Padovan <[email protected]>

To reflect the (backward compatible) changes in the uabi we are bumping the driver's version.

---
 drivers/gpu/drm/virtio/virtgpu_drv.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.h +2 -2
index e8d2a67d8049..a26483b5016e 100644
@@ -46,8 +46,8 @@
 #define DRIVER_DATE "0"
 
 #define DRIVER_MAJOR 0
-#define DRIVER_MINOR 0
-#define DRIVER_PATCHLEVEL 1
+#define DRIVER_MINOR 1
+#define DRIVER_PATCHLEVEL 0
 
 /* virtgpu_drm_bus.c */
 int drm_virtio_init(struct drm_driver *driver, struct virtio_device *vdev);
Signature · 6 lines
2.17.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
maintainer
#8 lore raw

Re: [PATCH 2/5] drm/virtio: add uapi for in and out explicit fences

In reply to Robert Foss

Hi,

include/uapi/drm/virtgpu_drm.h struct drm_virtgpu_get_caps { · line 148

Quoted 7 lines

The execbuffer IOCTL is now read-write to allow the userspace to read the out-fence.

#define DRM_IOCTL_VIRTGPU_EXECBUFFER \

include/uapi/drm/virtgpu_drm.h +1 -1
-	DRM_IOW(DRM_COMMAND_BASE + DRM_VIRTGPU_EXECBUFFER,\
+	DRM_IOWR(DRM_COMMAND_BASE + DRM_VIRTGPU_EXECBUFFER,\
 		struct drm_virtgpu_execbuffer)

That changes the ioctl number and breaks the userspace api.

cheers,
Gerd

maintainer
#15 lore raw

Re: [PATCH 2/5] drm/virtio: add uapi for in and out explicit fences

In reply to Robert Foss

Hi,

include/uapi/drm/virtgpu_drm.h struct drm_virtgpu_get_caps { · line 148

Quoted 7 lines

The execbuffer IOCTL is now read-write to allow the userspace to read the out-fence.

#define DRM_IOCTL_VIRTGPU_EXECBUFFER \

include/uapi/drm/virtgpu_drm.h +1 -1
-	DRM_IOW(DRM_COMMAND_BASE + DRM_VIRTGPU_EXECBUFFER,\
+	DRM_IOWR(DRM_COMMAND_BASE + DRM_VIRTGPU_EXECBUFFER,\
 		struct drm_virtgpu_execbuffer)

That changes the ioctl number and breaks the userspace api.

cheers,
Gerd

#9 lore raw

Re: [PATCH 2/5] drm/virtio: add uapi for in and out explicit fences

In reply to Gerd Hoffmann

HI Gerd,

Quoted 6 lines · Gerd Hoffmann

Hi,

Quoted 2 lines

The execbuffer IOCTL is now read-write to allow the userspace to read the out-fence.

Quoted 7 lines

include/uapi/drm/virtgpu_drm.h struct drm_virtgpu_get_caps { · line 148

Quoted 4 lines

#define DRM_IOCTL_VIRTGPU_EXECBUFFER \

include/uapi/drm/virtgpu_drm.h +1 -1
-     DRM_IOW(DRM_COMMAND_BASE + DRM_VIRTGPU_EXECBUFFER,\
+     DRM_IOWR(DRM_COMMAND_BASE + DRM_VIRTGPU_EXECBUFFER,\
              struct drm_virtgpu_execbuffer)

That changes the ioctl number and breaks the userspace api.

Have you looked at the drm_ioctl() implementation? AFAICT it explicitly caters for this kind of changes.

-Emil

#14 lore raw

Re: [PATCH 2/5] drm/virtio: add uapi for in and out explicit fences

In reply to Gerd Hoffmann

HI Gerd,

Quoted 6 lines · Gerd Hoffmann

Hi,

Quoted 2 lines

The execbuffer IOCTL is now read-write to allow the userspace to read the out-fence.

Quoted 7 lines

include/uapi/drm/virtgpu_drm.h struct drm_virtgpu_get_caps { · line 148

Quoted 4 lines

#define DRM_IOCTL_VIRTGPU_EXECBUFFER \

include/uapi/drm/virtgpu_drm.h +1 -1
-     DRM_IOW(DRM_COMMAND_BASE + DRM_VIRTGPU_EXECBUFFER,\
+     DRM_IOWR(DRM_COMMAND_BASE + DRM_VIRTGPU_EXECBUFFER,\
              struct drm_virtgpu_execbuffer)

That changes the ioctl number and breaks the userspace api.

Have you looked at the drm_ioctl() implementation? AFAICT it explicitly caters for this kind of changes.

-Emil

maintainer
#10 lore raw

Re: [PATCH 2/5] drm/virtio: add uapi for in and out explicit fences

In reply to Emil Velikov
Quoted 14 lines · Emil Velikov

HI Gerd,

Quoted 11 lines · Gerd Hoffmann

Hi,

Quoted 7 lines

The execbuffer IOCTL is now read-write to allow the userspace to read the out-fence.

#define DRM_IOCTL_VIRTGPU_EXECBUFFER \

include/uapi/drm/virtgpu_drm.h +1 -1
-     DRM_IOW(DRM_COMMAND_BASE + DRM_VIRTGPU_EXECBUFFER,\
+     DRM_IOWR(DRM_COMMAND_BASE + DRM_VIRTGPU_EXECBUFFER,\
              struct drm_virtgpu_execbuffer)
Quoted 4 lines
Quoted 2 lines

That changes the ioctl number and breaks the userspace api.

Have you looked at the drm_ioctl() implementation? AFAICT it explicitly caters for this kind of changes.

Looking ...

The direction bits are not used to lookup the ioctl functions, so it should work indeed.

Series doesn't apply to drm-misc-next and needs a rebase.

cheers,
Gerd

maintainer
#13 lore raw

Re: [PATCH 2/5] drm/virtio: add uapi for in and out explicit fences

In reply to Emil Velikov
Quoted 14 lines · Emil Velikov

HI Gerd,

Quoted 11 lines · Gerd Hoffmann

Hi,

Quoted 7 lines

The execbuffer IOCTL is now read-write to allow the userspace to read the out-fence.

#define DRM_IOCTL_VIRTGPU_EXECBUFFER \

include/uapi/drm/virtgpu_drm.h +1 -1
-     DRM_IOW(DRM_COMMAND_BASE + DRM_VIRTGPU_EXECBUFFER,\
+     DRM_IOWR(DRM_COMMAND_BASE + DRM_VIRTGPU_EXECBUFFER,\
              struct drm_virtgpu_execbuffer)
Quoted 4 lines
Quoted 2 lines

That changes the ioctl number and breaks the userspace api.

Have you looked at the drm_ioctl() implementation? AFAICT it explicitly caters for this kind of changes.

Looking ...

The direction bits are not used to lookup the ioctl functions, so it should work indeed.

Series doesn't apply to drm-misc-next and needs a rebase.

cheers,
Gerd

#11 lore raw

Re: [PATCH 2/5] drm/virtio: add uapi for in and out explicit fences

In reply to Gerd Hoffmann
Quoted 18 lines · Gerd Hoffmann
Quoted 16 lines · Emil Velikov

HI Gerd,

Quoted 13 lines · Gerd Hoffmann

Hi,

include/uapi/drm/virtgpu_drm.h struct drm_virtgpu_get_caps { · line 148

Quoted 7 lines

The execbuffer IOCTL is now read-write to allow the userspace to read the out-fence.

#define DRM_IOCTL_VIRTGPU_EXECBUFFER \

include/uapi/drm/virtgpu_drm.h +1 -1
-     DRM_IOW(DRM_COMMAND_BASE + DRM_VIRTGPU_EXECBUFFER,\
+     DRM_IOWR(DRM_COMMAND_BASE + DRM_VIRTGPU_EXECBUFFER,\
              struct drm_virtgpu_execbuffer)

That changes the ioctl number and breaks the userspace api.

Quoted 8 lines
Quoted 2 lines

Have you looked at the drm_ioctl() implementation? AFAICT it explicitly caters for this kind of changes.

Looking ...

The direction bits are not used to lookup the ioctl functions, so it should work indeed.

Nice, thanks for confirming.

Quoted 2 lines

Series doesn't apply to drm-misc-next and needs a rebase.

Might be nicer to address that alongside any feedback. Otherwise it'll be spamming people just for the sake of rebasing.

If i find some time I'll post some comments later on today.

HTH
Emil

#12 lore raw

Re: [PATCH 2/5] drm/virtio: add uapi for in and out explicit fences

In reply to Gerd Hoffmann
Quoted 18 lines · Gerd Hoffmann
Quoted 16 lines · Emil Velikov

HI Gerd,

Quoted 13 lines · Gerd Hoffmann

Hi,

include/uapi/drm/virtgpu_drm.h struct drm_virtgpu_get_caps { · line 148

Quoted 7 lines

The execbuffer IOCTL is now read-write to allow the userspace to read the out-fence.

#define DRM_IOCTL_VIRTGPU_EXECBUFFER \

include/uapi/drm/virtgpu_drm.h +1 -1
-     DRM_IOW(DRM_COMMAND_BASE + DRM_VIRTGPU_EXECBUFFER,\
+     DRM_IOWR(DRM_COMMAND_BASE + DRM_VIRTGPU_EXECBUFFER,\
              struct drm_virtgpu_execbuffer)

That changes the ioctl number and breaks the userspace api.

Quoted 8 lines
Quoted 2 lines

Have you looked at the drm_ioctl() implementation? AFAICT it explicitly caters for this kind of changes.

Looking ...

The direction bits are not used to lookup the ioctl functions, so it should work indeed.

Nice, thanks for confirming.

Quoted 2 lines

Series doesn't apply to drm-misc-next and needs a rebase.

Might be nicer to address that alongside any feedback. Otherwise it'll be spamming people just for the sake of rebasing.

If i find some time I'll post some comments later on today.

HTH
Emil
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#2 lore raw

Re: [PATCH 1/5] drm/virtio: add virtio_gpu_alloc_fence()

In reply to Robert Foss

Hi Rob,

Quoted 7 lines · Robert Foss

From: Gustavo Padovan <[email protected]>

Refactor fence creation to remove the potential allocation failure from the cmd_submit and atomic_commit paths. Now the fence should be allocated first and just after we should proceed with the rest of the execution.

Commit does a bit more that what the above says:
- dummy, factor out fence creation/destruction
- use per virtio_gpu_framebuffer fence

Personally I'd keep the two separate patches and elaborate on the latter. Obviously in that case, one will need to add 3 lines worth of virtio_gpu_fence_alloc() in virtio_gpu_cursor_plane_update which will be nuked with the next patch.

Not a big deal, but it's up-to the maintainer to make the final call if it's worth splitting or not.

Couple of minor nitpicks below.

Quoted 7 lines
        struct virtio_gpu_device *vgdev = dev->dev_private;
        struct virtio_gpu_output *output = NULL;
        struct virtio_gpu_framebuffer *vgfb;
-       struct virtio_gpu_fence *fence = NULL;
        struct virtio_gpu_object *bo = NULL;
        uint32_t handle;
        int ret = 0;

Add the virtio_gpu_fence_alloc()? And yes it will be nuked with patch 2/...

drivers/gpu/drm/virtio/virtgpu_fence.c static const struct dma_fence_ops virtio_fence_ops = { · line 78

Quoted 9 lines
drivers/gpu/drm/virtio/virtgpu_fence.c +9 -0
+struct virtio_gpu_fence *virtio_gpu_fence_alloc(struct virtio_gpu_device *vgdev)
+{
+       struct virtio_gpu_fence_driver *drv = &vgdev->fence_drv;
+       struct virtio_gpu_fence *fence = kzalloc(sizeof(struct virtio_gpu_fence), GFP_ATOMIC);
+       if (!fence)
+               return fence;
+
+       fence->drv = drv;
+       dma_fence_init(&fence->f, &virtio_fence_ops, &drv->lock, drv->context, 0);

Oh no, lines over 80 col... while the original code is pretty and neat.

drivers/gpu/drm/virtio/virtgpu_fence.c static const struct dma_fence_ops virtio_fence_ops = { · line 91

Quoted 13 lines
drivers/gpu/drm/virtio/virtgpu_fence.c +13 -0
+
+       return fence;
+}
+
+void virtio_gpu_fence_cleanup(struct virtio_gpu_fence *fence)
+{
+       if (!fence)
+               return;
+
+       if (fence->drv)
+               dma_fence_put(&fence->f);
+       else
+               kfree(fence);

I'm not sure if/how we reach the else case here?

drivers/gpu/drm/virtio/virtgpu_fence.c static const struct dma_fence_ops virtio_fence_ops = { · line 97

Quoted 7 lines
drivers/gpu/drm/virtio/virtgpu_fence.c +3 -1
+}
+
 int virtio_gpu_fence_emit(struct virtio_gpu_device *vgdev,
                          struct virtio_gpu_ctrl_hdr *cmd_hdr,
-                         struct virtio_gpu_fence **fence)
+                         struct virtio_gpu_fence *fence)
 {

With a follow-up commit, we can drop the no longer needed return type. Which it turns out was never checked ...

drivers/gpu/drm/virtio/virtgpu_ioctl.c static int virtio_gpu_resource_create_ioctl(struct drm_device *dev, void *data, · line 335

Quoted 5 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c +1 -0
@@ -319,6 +332,8 @@ static int virtio_gpu_resource_create_ioctl(struct drm_device *dev, void *data,
                dma_fence_put(&fence->f);
        }
        return 0;
+fail_fence:

The error labels seems to be called after what they do, not what fails. fail_backoff seems better IMHO.

drivers/gpu/drm/virtio/virtgpu_ioctl.c static int virtio_gpu_resource_create_ioctl(struct drm_device *dev, void *data, · line 336

Quoted 1 line
drivers/gpu/drm/virtio/virtgpu_ioctl.c +1 -0
+ttm_eu_backoff_reservation(&ticket, &validate_list);

Indentation seems off (or my client ate it)?

HTH
Emil

#6 lore raw

Re: [PATCH 1/5] drm/virtio: add virtio_gpu_alloc_fence()

In reply to Robert Foss

Hi Rob,

Quoted 7 lines · Robert Foss

From: Gustavo Padovan <[email protected]>

Refactor fence creation to remove the potential allocation failure from the cmd_submit and atomic_commit paths. Now the fence should be allocated first and just after we should proceed with the rest of the execution.

Commit does a bit more that what the above says:
- dummy, factor out fence creation/destruction
- use per virtio_gpu_framebuffer fence

Personally I'd keep the two separate patches and elaborate on the latter. Obviously in that case, one will need to add 3 lines worth of virtio_gpu_fence_alloc() in virtio_gpu_cursor_plane_update which will be nuked with the next patch.

Not a big deal, but it's up-to the maintainer to make the final call if it's worth splitting or not.

Couple of minor nitpicks below.

Quoted 7 lines
        struct virtio_gpu_device *vgdev = dev->dev_private;
        struct virtio_gpu_output *output = NULL;
        struct virtio_gpu_framebuffer *vgfb;
-       struct virtio_gpu_fence *fence = NULL;
        struct virtio_gpu_object *bo = NULL;
        uint32_t handle;
        int ret = 0;

Add the virtio_gpu_fence_alloc()? And yes it will be nuked with patch 2/...

drivers/gpu/drm/virtio/virtgpu_fence.c static const struct dma_fence_ops virtio_fence_ops = { · line 78

Quoted 9 lines
drivers/gpu/drm/virtio/virtgpu_fence.c +9 -0
+struct virtio_gpu_fence *virtio_gpu_fence_alloc(struct virtio_gpu_device *vgdev)
+{
+       struct virtio_gpu_fence_driver *drv = &vgdev->fence_drv;
+       struct virtio_gpu_fence *fence = kzalloc(sizeof(struct virtio_gpu_fence), GFP_ATOMIC);
+       if (!fence)
+               return fence;
+
+       fence->drv = drv;
+       dma_fence_init(&fence->f, &virtio_fence_ops, &drv->lock, drv->context, 0);

Oh no, lines over 80 col... while the original code is pretty and neat.

drivers/gpu/drm/virtio/virtgpu_fence.c static const struct dma_fence_ops virtio_fence_ops = { · line 91

Quoted 13 lines
drivers/gpu/drm/virtio/virtgpu_fence.c +13 -0
+
+       return fence;
+}
+
+void virtio_gpu_fence_cleanup(struct virtio_gpu_fence *fence)
+{
+       if (!fence)
+               return;
+
+       if (fence->drv)
+               dma_fence_put(&fence->f);
+       else
+               kfree(fence);

I'm not sure if/how we reach the else case here?

drivers/gpu/drm/virtio/virtgpu_fence.c static const struct dma_fence_ops virtio_fence_ops = { · line 97

Quoted 7 lines
drivers/gpu/drm/virtio/virtgpu_fence.c +3 -1
+}
+
 int virtio_gpu_fence_emit(struct virtio_gpu_device *vgdev,
                          struct virtio_gpu_ctrl_hdr *cmd_hdr,
-                         struct virtio_gpu_fence **fence)
+                         struct virtio_gpu_fence *fence)
 {

With a follow-up commit, we can drop the no longer needed return type. Which it turns out was never checked ...

drivers/gpu/drm/virtio/virtgpu_ioctl.c static int virtio_gpu_resource_create_ioctl(struct drm_device *dev, void *data, · line 335

Quoted 5 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c +1 -0
@@ -319,6 +332,8 @@ static int virtio_gpu_resource_create_ioctl(struct drm_device *dev, void *data,
                dma_fence_put(&fence->f);
        }
        return 0;
+fail_fence:

The error labels seems to be called after what they do, not what fails. fail_backoff seems better IMHO.

drivers/gpu/drm/virtio/virtgpu_ioctl.c static int virtio_gpu_resource_create_ioctl(struct drm_device *dev, void *data, · line 336

Quoted 1 line
drivers/gpu/drm/virtio/virtgpu_ioctl.c +1 -0
+ttm_eu_backoff_reservation(&ticket, &validate_list);

Indentation seems off (or my client ate it)?

HTH
Emil

Reviewed-by on v1 2/5
#16 lore raw

Re: [PATCH 2/5] drm/virtio: add uapi for in and out explicit fences

In reply to Robert Foss

Hi Rob,

Quoted 33 lines · Robert Foss

Add a new field called fence_fd that will be used by userspace to send in-fences to the kernel and receive out-fences created by the kernel.

This uapi enables virtio to take advantage of explicit synchronization of dma-bufs.

There are two new flags:

* VIRTGPU_EXECBUF_FENCE_FD_IN to be used when passing an in-fence fd.
* VIRTGPU_EXECBUF_FENCE_FD_OUT to be used when requesting an out-fence fd

The execbuffer IOCTL is now read-write to allow the userspace to read the out-fence.

On error -1 should be returned in the fence_fd field.

---
Changes since v2:
- Since exbuf-flags is a new flag, check that unsupported flags aren't set.

 drivers/gpu/drm/virtio/virtgpu_ioctl.c |  5 +++++
 include/uapi/drm/virtgpu_drm.h         | 13 ++++++++++---
 2 files changed, 15 insertions(+), 3 deletions(-)
drivers/gpu/drm/virtio/virtgpu_ioctl.c +0 -0
index d01a9ed100d1..1af289b28fc4 100644

drivers/gpu/drm/virtio/virtgpu_ioctl.c static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data, · line 120

Quoted 5 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c +2 -0
@@ -116,9 +116,14 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
        struct ww_acquire_ctx ticket;
        void *buf;
 
+       exbuf->fence_fd = -1;
+

Move this after the sanity checking.

drivers/gpu/drm/virtio/virtgpu_ioctl.c static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data, · line 126

Quoted 6 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c +3 -0
        if (vgdev->has_virgl_3d == false)
                return -ENOSYS;
 
+       if ((exbuf->flags & ~VIRTGPU_EXECBUF_FLAGS))
+               return -EINVAL;
+

I assume this did this trigger when using old userspace?

With those the patch is

Thanks
Emil

Reviewed-by on v1 3/5
#23 lore raw

Re: [PATCH 3/5] drm/virtio: add in-fences support for explicit synchronization

In reply to Robert Foss

Hi Rob,

Quoted 7 lines · Robert Foss
drivers/gpu/drm/virtio/virtgpu_ioctl.c +3 -0
@@ -124,6 +127,22 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
        if ((exbuf->flags & ~VIRTGPU_EXECBUF_FLAGS))
                return -EINVAL;
 
+       if (exbuf->flags & VIRTGPU_EXECBUF_FENCE_FD_IN) {
+               in_fence = sync_file_get_fence(in_fence_fd);
+               if (!in_fence)

drivers/gpu/drm/virtio/virtgpu_ioctl.c static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data, · line 142

Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c +10 -0
+                       return -EINVAL;
+
+               /*
+                * Wait if the fence is from a foreign context, or if the fence
+                * array contains any fence from a foreign context.
+                */
+               if (!dma_fence_match_context(in_fence, vgdev->fence_drv.context)) {
+                       ret = dma_fence_wait(in_fence, true);
+                       if (ret)
+                               return ret;

Aren't we missing dma_fence_put() before the return here?

With that

-Emil

Reviewed-by on v1 3/5
#24 lore raw

Re: [PATCH 3/5] drm/virtio: add in-fences support for explicit synchronization

In reply to Robert Foss

Hi Rob,

Quoted 7 lines · Robert Foss
drivers/gpu/drm/virtio/virtgpu_ioctl.c +3 -0
@@ -124,6 +127,22 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
        if ((exbuf->flags & ~VIRTGPU_EXECBUF_FLAGS))
                return -EINVAL;
 
+       if (exbuf->flags & VIRTGPU_EXECBUF_FENCE_FD_IN) {
+               in_fence = sync_file_get_fence(in_fence_fd);
+               if (!in_fence)

drivers/gpu/drm/virtio/virtgpu_ioctl.c static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data, · line 142

Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c +10 -0
+                       return -EINVAL;
+
+               /*
+                * Wait if the fence is from a foreign context, or if the fence
+                * array contains any fence from a foreign context.
+                */
+               if (!dma_fence_match_context(in_fence, vgdev->fence_drv.context)) {
+                       ret = dma_fence_wait(in_fence, true);
+                       if (ret)
+                               return ret;

Aren't we missing dma_fence_put() before the return here?

With that

-Emil

Reviewed-by on v1 4/5
#26 lore raw

Re: [PATCH 4/5] drm/virtio: add out-fences support for explicit synchronization

In reply to Robert Foss

Hi Rob,

Quoted 7 lines · Robert Foss

From: Gustavo Padovan <[email protected]>

On the out-fence side we get fence returned by the submitted draw call and attach it to a sync_file and send the sync_file fd to userspace. On error -1 is returned to userspace.

Can we have both an IN and OUT fence at the same time? Either way, please mention that in the commit message.

Quoted 32 lines
---
 drivers/gpu/drm/virtio/virtgpu_ioctl.c | 50 +++++++++++++++++++-------
 1 file changed, 38 insertions(+), 12 deletions(-)
drivers/gpu/drm/virtio/virtgpu_ioctl.c +3 -1
index 0368195966aa..32e714a1c753 100644
@@ -106,7 +106,7 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
        struct virtio_gpu_device *vgdev = dev->dev_private;
        struct virtio_gpu_fpriv *vfpriv = drm_file->driver_priv;
        struct drm_gem_object *gobj;
-       struct virtio_gpu_fence *fence;
+       struct virtio_gpu_fence *out_fence;
        struct virtio_gpu_object *qobj;
        int ret;
        uint32_t *bo_handles = NULL;
@@ -116,7 +116,9 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
        int i;
        struct ww_acquire_ctx ticket;
        struct dma_fence *in_fence = NULL;
+       struct sync_file *sync_file;
        int in_fence_fd = exbuf->fence_fd;
+       int out_fence_fd = -1;
        void *buf;
 
        exbuf->fence_fd = -1;
@@ -143,6 +145,14 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
                }

drivers/gpu/drm/virtio/virtgpu_ioctl.c static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data, · line 155

Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c +8 -0
        }
 
+       if (exbuf->flags & VIRTGPU_EXECBUF_FENCE_FD_OUT) {
+               out_fence_fd = get_unused_fd_flags(O_CLOEXEC);
+               if (out_fence_fd < 0) {
+                       ret = out_fence_fd;
+                       goto out_in_fence;
+               }
+       }
+

If the answer to the above is "no" we want a check around here.

With that the patch is

-Emil

Reviewed-by on v1 4/5
#27 lore raw

Re: [PATCH 4/5] drm/virtio: add out-fences support for explicit synchronization

In reply to Robert Foss

Hi Rob,

Quoted 7 lines · Robert Foss

From: Gustavo Padovan <[email protected]>

On the out-fence side we get fence returned by the submitted draw call and attach it to a sync_file and send the sync_file fd to userspace. On error -1 is returned to userspace.

Can we have both an IN and OUT fence at the same time? Either way, please mention that in the commit message.

Quoted 32 lines
---
 drivers/gpu/drm/virtio/virtgpu_ioctl.c | 50 +++++++++++++++++++-------
 1 file changed, 38 insertions(+), 12 deletions(-)
drivers/gpu/drm/virtio/virtgpu_ioctl.c +3 -1
index 0368195966aa..32e714a1c753 100644
@@ -106,7 +106,7 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
        struct virtio_gpu_device *vgdev = dev->dev_private;
        struct virtio_gpu_fpriv *vfpriv = drm_file->driver_priv;
        struct drm_gem_object *gobj;
-       struct virtio_gpu_fence *fence;
+       struct virtio_gpu_fence *out_fence;
        struct virtio_gpu_object *qobj;
        int ret;
        uint32_t *bo_handles = NULL;
@@ -116,7 +116,9 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
        int i;
        struct ww_acquire_ctx ticket;
        struct dma_fence *in_fence = NULL;
+       struct sync_file *sync_file;
        int in_fence_fd = exbuf->fence_fd;
+       int out_fence_fd = -1;
        void *buf;
 
        exbuf->fence_fd = -1;
@@ -143,6 +145,14 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
                }

drivers/gpu/drm/virtio/virtgpu_ioctl.c static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data, · line 155

Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c +8 -0
        }
 
+       if (exbuf->flags & VIRTGPU_EXECBUF_FENCE_FD_OUT) {
+               out_fence_fd = get_unused_fd_flags(O_CLOEXEC);
+               if (out_fence_fd < 0) {
+                       ret = out_fence_fd;
+                       goto out_in_fence;
+               }
+       }
+

If the answer to the above is "no" we want a check around here.

With that the patch is

-Emil

Reviewed-by on v1 5/5
#29 lore raw

Re: [PATCH 5/5] drm/virtio: bump driver version after explicit synchronization addition

In reply to Robert Foss
Quoted 8 lines · Robert Foss

From: Gustavo Padovan <[email protected]>

To reflect the (backward compatible) changes in the uabi we are bumping the driver's version.

Not strictly required, but doesn't hurt either.

-Emil

Reviewed-by on v1 2/5
#17 lore raw

Re: [PATCH 2/5] drm/virtio: add uapi for in and out explicit fences

In reply to Robert Foss

Hi Rob,

Quoted 33 lines · Robert Foss

Add a new field called fence_fd that will be used by userspace to send in-fences to the kernel and receive out-fences created by the kernel.

This uapi enables virtio to take advantage of explicit synchronization of dma-bufs.

There are two new flags:

* VIRTGPU_EXECBUF_FENCE_FD_IN to be used when passing an in-fence fd.
* VIRTGPU_EXECBUF_FENCE_FD_OUT to be used when requesting an out-fence fd

The execbuffer IOCTL is now read-write to allow the userspace to read the out-fence.

On error -1 should be returned in the fence_fd field.

---
Changes since v2:
- Since exbuf-flags is a new flag, check that unsupported flags aren't set.

 drivers/gpu/drm/virtio/virtgpu_ioctl.c |  5 +++++
 include/uapi/drm/virtgpu_drm.h         | 13 ++++++++++---
 2 files changed, 15 insertions(+), 3 deletions(-)
drivers/gpu/drm/virtio/virtgpu_ioctl.c +0 -0
index d01a9ed100d1..1af289b28fc4 100644

drivers/gpu/drm/virtio/virtgpu_ioctl.c static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data, · line 120

Quoted 5 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c +2 -0
@@ -116,9 +116,14 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
        struct ww_acquire_ctx ticket;
        void *buf;
 
+       exbuf->fence_fd = -1;
+

Move this after the sanity checking.

drivers/gpu/drm/virtio/virtgpu_ioctl.c static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data, · line 126

Quoted 6 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c +3 -0
        if (vgdev->has_virgl_3d == false)
                return -ENOSYS;
 
+       if ((exbuf->flags & ~VIRTGPU_EXECBUF_FLAGS))
+               return -EINVAL;
+

I assume this did this trigger when using old userspace?

With those the patch is

Thanks
Emil
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Reviewed-by on v1 5/5
#30 lore raw

Re: [PATCH 5/5] drm/virtio: bump driver version after explicit synchronization addition

In reply to Robert Foss
Quoted 8 lines · Robert Foss

From: Gustavo Padovan <[email protected]>

To reflect the (backward compatible) changes in the uabi we are bumping the driver's version.

Not strictly required, but doesn't hurt either.

-Emil
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#31 lore raw
In reply to Robert Foss

Hi Rob,

Quoted 9 lines · Robert Foss

This series implements fence support for drm/virtio and has been tested using qemu, kmscube and the below branches.

Rob Herring solved a reference counting issue and suggested a context check for the execbuf ioctl, his changes have been included in the below commits to keep the tree working at all commits.

I've put forward some mostly minor suggestions. The patches look pretty good but there's one piece missing:

Quoted 7 lines

The linux series can be found here:
https://gitlab.collabora.com/robertfoss/linux/commits/virtio_fences_v3

As for mesa, the branch can be found here:
https://gitlab.collabora.com/robertfoss/mesa/commits/virtio_fences_v3

Namely: This should be out for review. The kernel and userspace side of IOCTLs should happen roughly at the same time. Otherwise, there's a huge chance of merging one side of the component, while the other needs architectural changes.

HTH
Emil

#32 lore raw
In reply to Robert Foss

Hi Rob,

Quoted 9 lines · Robert Foss

This series implements fence support for drm/virtio and has been tested using qemu, kmscube and the below branches.

Rob Herring solved a reference counting issue and suggested a context check for the execbuf ioctl, his changes have been included in the below commits to keep the tree working at all commits.

I've put forward some mostly minor suggestions. The patches look pretty good but there's one piece missing:

Quoted 7 lines

The linux series can be found here:
https://gitlab.collabora.com/robertfoss/linux/commits/virtio_fences_v3

As for mesa, the branch can be found here:
https://gitlab.collabora.com/robertfoss/mesa/commits/virtio_fences_v3

Namely: This should be out for review. The kernel and userspace side of IOCTLs should happen roughly at the same time. Otherwise, there's a huge chance of merging one side of the component, while the other needs architectural changes.

HTH
Emil
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#3 lore raw

Re: [PATCH 1/5] drm/virtio: add virtio_gpu_alloc_fence()

In reply to Emil Velikov

Hey Emil,

Quoted 15 lines · Emil Velikov

Hi Rob,

Quoted 7 lines · Robert Foss

From: Gustavo Padovan <[email protected]>

Refactor fence creation to remove the potential allocation failure from the cmd_submit and atomic_commit paths. Now the fence should be allocated first and just after we should proceed with the rest of the execution.

Commit does a bit more that what the above says:
- dummy, factor out fence creation/destruction
- use per virtio_gpu_framebuffer fence

Quoted 7 lines

Personally I'd keep the two separate patches and elaborate on the latter. Obviously in that case, one will need to add 3 lines worth of virtio_gpu_fence_alloc() in virtio_gpu_cursor_plane_update which will be nuked with the next patch.

Not a big deal, but it's up-to the maintainer to make the final call if it's worth splitting or not.

Agreed, I'll hold off with this change until then.

Quoted 15 lines

Couple of minor nitpicks below.

Quoted 7 lines
         struct virtio_gpu_device *vgdev = dev->dev_private;
         struct virtio_gpu_output *output = NULL;
         struct virtio_gpu_framebuffer *vgfb;
-       struct virtio_gpu_fence *fence = NULL;
         struct virtio_gpu_object *bo = NULL;
         uint32_t handle;
         int ret = 0;

Add the virtio_gpu_fence_alloc()? And yes it will be nuked with patch 2/...

Quoted 10 lines

drivers/gpu/drm/virtio/virtgpu_fence.c static const struct dma_fence_ops virtio_fence_ops = { · line 78

Quoted 9 lines
drivers/gpu/drm/virtio/virtgpu_fence.c +9 -0
+struct virtio_gpu_fence *virtio_gpu_fence_alloc(struct virtio_gpu_device *vgdev)
+{
+       struct virtio_gpu_fence_driver *drv = &vgdev->fence_drv;
+       struct virtio_gpu_fence *fence = kzalloc(sizeof(struct virtio_gpu_fence), GFP_ATOMIC);
+       if (!fence)
+               return fence;
+
+       fence->drv = drv;
+       dma_fence_init(&fence->f, &virtio_fence_ops, &drv->lock, drv->context, 0);

Oh no, lines over 80 col... while the original code is pretty and neat.

Ack

Quoted 15 lines
Quoted 4 lines
drivers/gpu/drm/virtio/virtgpu_fence.c +3 -0
+
+       return fence;
+}

drivers/gpu/drm/virtio/virtgpu_fence.c static const struct dma_fence_ops virtio_fence_ops = { · line 91

Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_fence.c +10 -0
+
+void virtio_gpu_fence_cleanup(struct virtio_gpu_fence *fence)
+{
+       if (!fence)
+               return;
+
+       if (fence->drv)
+               dma_fence_put(&fence->f);
+       else
+               kfree(fence);

I'm not sure if/how we reach the else case here?

That case should never be hit, and if it is that's a bug. Fixed in v4.

Quoted 12 lines

drivers/gpu/drm/virtio/virtgpu_fence.c static const struct dma_fence_ops virtio_fence_ops = { · line 97

Quoted 8 lines
drivers/gpu/drm/virtio/virtgpu_fence.c +3 -1
+}
+
  int virtio_gpu_fence_emit(struct virtio_gpu_device *vgdev,
                           struct virtio_gpu_ctrl_hdr *cmd_hdr,
-                         struct virtio_gpu_fence **fence)
+                         struct virtio_gpu_fence *fence)
  {

With a follow-up commit, we can drop the no longer needed return type. Which it turns out was never checked ...

Fixed during drm-misc-next rebase for v4.

Quoted 10 lines

drivers/gpu/drm/virtio/virtgpu_ioctl.c static int virtio_gpu_resource_create_ioctl(struct drm_device *dev, void *data, · line 335

Quoted 7 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c +1 -0
@@ -319,6 +332,8 @@ static int virtio_gpu_resource_create_ioctl(struct drm_device *dev, void *data,
                 dma_fence_put(&fence->f);
         }
         return 0;
+fail_fence:

The error labels seems to be called after what they do, not what fails. fail_backoff seems better IMHO.

Agreed. Fixed in v4.

Quoted 3 lines

drivers/gpu/drm/virtio/virtgpu_ioctl.c static int virtio_gpu_resource_create_ioctl(struct drm_device *dev, void *data, · line 336

Quoted 2 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c +1 -0
+ttm_eu_backoff_reservation(&ticket, &validate_list);

Indentation seems off (or my client ate it)?

No, the indentation is bad here. Fixed in v4.

Thanks for the feedback Emil.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#18 lore raw

Re: [PATCH 2/5] drm/virtio: add uapi for in and out explicit fences

In reply to Emil Velikov
Quoted 39 lines · Emil Velikov

Hi Rob,

Quoted 36 lines · Robert Foss

Add a new field called fence_fd that will be used by userspace to send in-fences to the kernel and receive out-fences created by the kernel.

This uapi enables virtio to take advantage of explicit synchronization of dma-bufs.

There are two new flags:

* VIRTGPU_EXECBUF_FENCE_FD_IN to be used when passing an in-fence fd.
* VIRTGPU_EXECBUF_FENCE_FD_OUT to be used when requesting an out-fence fd

The execbuffer IOCTL is now read-write to allow the userspace to read the out-fence.

On error -1 should be returned in the fence_fd field.

---
Changes since v2:
- Since exbuf-flags is a new flag, check that unsupported flags aren't set.

  drivers/gpu/drm/virtio/virtgpu_ioctl.c |  5 +++++
  include/uapi/drm/virtgpu_drm.h         | 13 ++++++++++---
  2 files changed, 15 insertions(+), 3 deletions(-)
drivers/gpu/drm/virtio/virtgpu_ioctl.c +0 -0
index d01a9ed100d1..1af289b28fc4 100644
@@ -116,9 +116,14 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
         struct ww_acquire_ctx ticket;
         void *buf;
 
Quoted 3 lines

drivers/gpu/drm/virtio/virtgpu_ioctl.c static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data, · line 120

Quoted 2 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c +2 -0
+       exbuf->fence_fd = -1;
+

Move this after the sanity checking.

Agreed. Fixed in v4

Quoted 8 lines

drivers/gpu/drm/virtio/virtgpu_ioctl.c static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data, · line 126

Quoted 7 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c +3 -0
         if (vgdev->has_virgl_3d == false)
                 return -ENOSYS;
 
+       if ((exbuf->flags & ~VIRTGPU_EXECBUF_FLAGS))
+               return -EINVAL;
+

I assume this did this trigger when using old userspace?

No, not as far as I'm aware. This check is there to prevent userspace from polluting the bitspace of flag, so that all free bits can be used for new flags.

As far as I understand this is pointed out by a drm driver development document written by danvet, which I unfortunately can't seem to find the link for at the moment.

Quoted 7 lines

With those the patch is

Thanks
Emil

#19 lore raw

Re: [PATCH 2/5] drm/virtio: add uapi for in and out explicit fences

Quoted 53 lines · Robert Foss
Quoted 39 lines · Emil Velikov

Hi Rob,

Quoted 36 lines · Robert Foss

Add a new field called fence_fd that will be used by userspace to send in-fences to the kernel and receive out-fences created by the kernel.

This uapi enables virtio to take advantage of explicit synchronization of dma-bufs.

There are two new flags:

* VIRTGPU_EXECBUF_FENCE_FD_IN to be used when passing an in-fence fd.
* VIRTGPU_EXECBUF_FENCE_FD_OUT to be used when requesting an out-fence fd

The execbuffer IOCTL is now read-write to allow the userspace to read the out-fence.

On error -1 should be returned in the fence_fd field.

---
Changes since v2:
- Since exbuf-flags is a new flag, check that unsupported flags aren't set.

  drivers/gpu/drm/virtio/virtgpu_ioctl.c |  5 +++++
  include/uapi/drm/virtgpu_drm.h         | 13 ++++++++++---
  2 files changed, 15 insertions(+), 3 deletions(-)
drivers/gpu/drm/virtio/virtgpu_ioctl.c +0 -0
index d01a9ed100d1..1af289b28fc4 100644
@@ -116,9 +116,14 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
         struct ww_acquire_ctx ticket;
         void *buf;
 
Quoted 3 lines

drivers/gpu/drm/virtio/virtgpu_ioctl.c static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data, · line 120

Quoted 2 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c +2 -0
+       exbuf->fence_fd = -1;
+

Move this after the sanity checking.

Agreed. Fixed in v4

Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c +3 -0
         if (vgdev->has_virgl_3d == false)
                 return -ENOSYS;
 
+       if ((exbuf->flags & ~VIRTGPU_EXECBUF_FLAGS))
+               return -EINVAL;
+
Quoted 9 lines
Quoted 1 line

I assume this did this trigger when using old userspace?

No, not as far as I'm aware. This check is there to prevent userspace from polluting the bitspace of flag, so that all free bits can be used for new flags.

As far as I understand this is pointed out by a drm driver development document written by danvet, which I unfortunately can't seem to find the link for at the moment.

Yes that is correct. What I was asking is:

Does a kernel with this patch, work with mesa lacking the corresponding updates? I'd imagine things work just fine.

-Emil

#21 lore raw

Re: [PATCH 2/5] drm/virtio: add uapi for in and out explicit fences

In reply to Robert Foss
Quoted 53 lines · Robert Foss
Quoted 39 lines · Emil Velikov

Hi Rob,

Quoted 36 lines · Robert Foss

Add a new field called fence_fd that will be used by userspace to send in-fences to the kernel and receive out-fences created by the kernel.

This uapi enables virtio to take advantage of explicit synchronization of dma-bufs.

There are two new flags:

* VIRTGPU_EXECBUF_FENCE_FD_IN to be used when passing an in-fence fd.
* VIRTGPU_EXECBUF_FENCE_FD_OUT to be used when requesting an out-fence fd

The execbuffer IOCTL is now read-write to allow the userspace to read the out-fence.

On error -1 should be returned in the fence_fd field.

---
Changes since v2:
- Since exbuf-flags is a new flag, check that unsupported flags aren't set.

  drivers/gpu/drm/virtio/virtgpu_ioctl.c |  5 +++++
  include/uapi/drm/virtgpu_drm.h         | 13 ++++++++++---
  2 files changed, 15 insertions(+), 3 deletions(-)
drivers/gpu/drm/virtio/virtgpu_ioctl.c +0 -0
index d01a9ed100d1..1af289b28fc4 100644
@@ -116,9 +116,14 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
         struct ww_acquire_ctx ticket;
         void *buf;
 
Quoted 3 lines

drivers/gpu/drm/virtio/virtgpu_ioctl.c static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data, · line 120

Quoted 2 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c +2 -0
+       exbuf->fence_fd = -1;
+

Move this after the sanity checking.

Agreed. Fixed in v4

Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c +3 -0
         if (vgdev->has_virgl_3d == false)
                 return -ENOSYS;
 
+       if ((exbuf->flags & ~VIRTGPU_EXECBUF_FLAGS))
+               return -EINVAL;
+
Quoted 9 lines
Quoted 1 line

I assume this did this trigger when using old userspace?

No, not as far as I'm aware. This check is there to prevent userspace from polluting the bitspace of flag, so that all free bits can be used for new flags.

As far as I understand this is pointed out by a drm driver development document written by danvet, which I unfortunately can't seem to find the link for at the moment.

Yes that is correct. What I was asking is:

Does a kernel with this patch, work with mesa lacking the corresponding updates? I'd imagine things work just fine.

-Emil

#20 lore raw

Re: [PATCH 2/5] drm/virtio: add uapi for in and out explicit fences

In reply to Emil Velikov

Hey Emil,

Quoted 59 lines · Emil Velikov
Quoted 58 lines · Robert Foss
Quoted 39 lines · Emil Velikov

Hi Rob,

Quoted 36 lines · Robert Foss

Add a new field called fence_fd that will be used by userspace to send in-fences to the kernel and receive out-fences created by the kernel.

This uapi enables virtio to take advantage of explicit synchronization of dma-bufs.

There are two new flags:

* VIRTGPU_EXECBUF_FENCE_FD_IN to be used when passing an in-fence fd.
* VIRTGPU_EXECBUF_FENCE_FD_OUT to be used when requesting an out-fence fd

The execbuffer IOCTL is now read-write to allow the userspace to read the out-fence.

On error -1 should be returned in the fence_fd field.

---
Changes since v2:
- Since exbuf-flags is a new flag, check that unsupported flags aren't set.

   drivers/gpu/drm/virtio/virtgpu_ioctl.c |  5 +++++
   include/uapi/drm/virtgpu_drm.h         | 13 ++++++++++---
   2 files changed, 15 insertions(+), 3 deletions(-)
drivers/gpu/drm/virtio/virtgpu_ioctl.c +0 -0
index d01a9ed100d1..1af289b28fc4 100644
@@ -116,9 +116,14 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
          struct ww_acquire_ctx ticket;
          void *buf;
 
Quoted 3 lines

drivers/gpu/drm/virtio/virtgpu_ioctl.c static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data, · line 120

Quoted 2 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c +2 -0
+       exbuf->fence_fd = -1;
+

Move this after the sanity checking.

Agreed. Fixed in v4

Quoted 8 lines

drivers/gpu/drm/virtio/virtgpu_ioctl.c static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data, · line 126

Quoted 7 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c +3 -0
          if (vgdev->has_virgl_3d == false)
                  return -ENOSYS;
 
+       if ((exbuf->flags & ~VIRTGPU_EXECBUF_FLAGS))
+               return -EINVAL;
+

I assume this did this trigger when using old userspace?

No, not as far as I'm aware. This check is there to prevent userspace from polluting the bitspace of flag, so that all free bits can be used for new flags.

Quoted 8 lines
Quoted 4 lines

As far as I understand this is pointed out by a drm driver development document written by danvet, which I unfortunately can't seem to find the link for at the moment.

Yes that is correct. What I was asking is:

Does a kernel with this patch, work with mesa lacking the corresponding updates? I'd imagine things work just fine.

Yes it does!

Quoted 7 lines

-Emil
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

maintainer
#4 lore raw

Re: [PATCH 1/5] drm/virtio: add virtio_gpu_alloc_fence()

In reply to Robert Foss
Quoted 18 lines
Quoted 18 lines · Robert Foss
Quoted 7 lines

From: Gustavo Padovan <[email protected]>

Refactor fence creation to remove the potential allocation failure from the cmd_submit and atomic_commit paths. Now the fence should be allocated first and just after we should proceed with the rest of the execution.

Commit does a bit more that what the above says:
- dummy, factor out fence creation/destruction
- use per virtio_gpu_framebuffer fence

Personally I'd keep the two separate patches and elaborate on the latter. Obviously in that case, one will need to add 3 lines worth of virtio_gpu_fence_alloc() in virtio_gpu_cursor_plane_update which will be nuked with the next patch.

Quoted 4 lines
Quoted 2 lines

Not a big deal, but it's up-to the maintainer to make the final call if it's worth splitting or not.

Agreed, I'll hold off with this change until then.

No need to split this, but a bit more verbose commit message would be good.

cheers,
Gerd

maintainer
#5 lore raw

Re: [PATCH 1/5] drm/virtio: add virtio_gpu_alloc_fence()

In reply to Robert Foss
Quoted 18 lines
Quoted 18 lines · Robert Foss
Quoted 7 lines

From: Gustavo Padovan <[email protected]>

Refactor fence creation to remove the potential allocation failure from the cmd_submit and atomic_commit paths. Now the fence should be allocated first and just after we should proceed with the rest of the execution.

Commit does a bit more that what the above says:
- dummy, factor out fence creation/destruction
- use per virtio_gpu_framebuffer fence

Personally I'd keep the two separate patches and elaborate on the latter. Obviously in that case, one will need to add 3 lines worth of virtio_gpu_fence_alloc() in virtio_gpu_cursor_plane_update which will be nuked with the next patch.

Quoted 4 lines
Quoted 2 lines

Not a big deal, but it's up-to the maintainer to make the final call if it's worth splitting or not.

Agreed, I'll hold off with this change until then.

No need to split this, but a bit more verbose commit message would be good.

cheers,
Gerd