Skip to contentSkip to conversation

Add sync object UAPI support to VirtIO-GPU driver

PATCH Applied Dmitry Osipenko 6 participants 28 messages Apr 16, 2023 – Jul 31, 2023

Subsystems (4)
lore
Share & tools
lore

Dmitry Osipenko

author maintainer
#0 lore raw

v6 cover Add sync object UAPI support to VirtIO-GPU driver

We have multiple Vulkan context types that are awaiting for the addition of the sync object DRM UAPI support to the VirtIO-GPU kernel driver:

1. Venus context
2. Native contexts (virtio-freedreno, virtio-intel, virtio-amdgpu)

Mesa core supports DRM sync object UAPI, providing Vulkan drivers with a generic fencing implementation that we want to utilize.

This patch adds initial sync objects support. It creates fundament for a further fencing improvements. Later on we will want to extend the VirtIO-GPU fencing API with passing fence IDs to host for waiting, it will be a new additional VirtIO-GPU IOCTL and more. Today we have several VirtIO-GPU context drivers in works that require VirtIO-GPU to support sync objects UAPI.

The patch is heavily inspired by the sync object UAPI implementation of the MSM driver.

Changelog:

v6: - Added zeroing out of syncobj_desc, as was suggested by Emil Velikov.

- Fixed memleak in error code path which was spotted by Emil Velikov.

- Switched to u32/u64 instead of uint_t. Previously was keeping uint_t style of the virtgpu_ioctl.c, in the end decided to change it because it's not a proper kernel coding style after all.

- Kept single drm_virtgpu_execbuffer_syncobj struct for both in/out sync objects. There was a little concern about whether it would be worthwhile to have separate in/out descriptors, in practice it's unlikely that we will extend the descs in a foreseeable future. There is no overhead in using same struct since we want to pad it to 64b anyways and it shouldn't be a problem to separate the descs later on if we will want to do that.

- Added r-b from Emil Velikov.

v5: - Factored out dma-fence unwrap API usage into separate patch as was
suggested by Emil Velikov.

- Improved and documented the job submission reorderings as was requested by Emil Velikov. Sync file FD is now installed after job is submitted to virtio to further optimize reorderings.

- Added comment for the kvalloc, as was requested by Emil Velikov.

- The num_in/out_syncobjs now is set only after completed parsing of pre/post deps, as was requested by Emil Velikov.

v4: - Added r-b from Rob Clark to the "refactoring" patch.

- Replaced for/while(ptr && itr) with if (ptr), like was suggested by Rob Clark.

- Dropped NOWARN and NORETRY GFP flags and switched syncobj patch to use kvmalloc.

- Removed unused variables from syncobj patch that were borrowed by accident from another (upcoming) patch after one of git rebases.

v3: - Switched to use dma_fence_unwrap_for_each(), like was suggested by
Rob Clark.

- Fixed missing dma_fence_put() in error code path that was spotted by Rob Clark.

- Removed obsoleted comment to virtio_gpu_execbuffer_ioctl(), like was suggested by Rob Clark.

v2: - Fixed chain-fence context matching by making use of
dma_fence_chain_contained().

- Fixed potential uninitialized var usage in error code patch of parse_post_deps(). MSM driver had a similar issue that is fixed already in upstream.

- Added new patch that refactors job submission code path. I found that it was very difficult to add a new/upcoming host-waits feature because of how variables are passed around the code, the virtgpu_ioctl.c also was growing to unmanageable size.

Dmitry Osipenko (3):
drm/virtio: Refactor and optimize job submission code path drm/virtio: Wait for each dma-fence of in-fence array individually drm/virtio: Support sync objects

 drivers/gpu/drm/virtio/Makefile         |   2 +-
 drivers/gpu/drm/virtio/virtgpu_drv.c    |   3 +-
 drivers/gpu/drm/virtio/virtgpu_drv.h    |   4 +
 drivers/gpu/drm/virtio/virtgpu_ioctl.c  | 182 --------
 drivers/gpu/drm/virtio/virtgpu_submit.c | 530 ++++++++++++++++++++++++
 include/uapi/drm/virtgpu_drm.h          |  16 +-
 6 files changed, 552 insertions(+), 185 deletions(-)
 create mode 100644 drivers/gpu/drm/virtio/virtgpu_submit.c
Signature · 1 line
2.39.2
author maintainer
#1 lore raw

PATCH v6 1/3 drm/virtio: Refactor and optimize job submission code path

Move virtio_gpu_execbuffer_ioctl() into separate virtgpu_submit.c file, refactoring and optimizing the code along the way to ease addition of new features to the ioctl.

The optimization is done by using optimal ordering of the job's submission steps, reducing code path from the start of the ioctl to the point of pushing job to virtio queue. Job's initialization is now performed before in-fence is awaited and out-fence setup is made after sending out job to virtio.

Reviewed-by; Emil Velikov <[email protected]>

---
 drivers/gpu/drm/virtio/Makefile         |   2 +-
 drivers/gpu/drm/virtio/virtgpu_drv.h    |   4 +
 drivers/gpu/drm/virtio/virtgpu_ioctl.c  | 182 ---------------
 drivers/gpu/drm/virtio/virtgpu_submit.c | 295 ++++++++++++++++++++++++
 4 files changed, 300 insertions(+), 183 deletions(-)
 create mode 100644 drivers/gpu/drm/virtio/virtgpu_submit.c
drivers/gpu/drm/virtio/Makefile +1 -1
index b99fa4a73b68..d2e1788a8227 100644
@@ -6,6 +6,6 @@
 virtio-gpu-y := virtgpu_drv.o virtgpu_kms.o virtgpu_gem.o virtgpu_vram.o \
 	virtgpu_display.o virtgpu_vq.o \
 	virtgpu_fence.o virtgpu_object.o virtgpu_debugfs.o virtgpu_plane.o \
-	virtgpu_ioctl.o virtgpu_prime.o virtgpu_trace_points.o
+	virtgpu_ioctl.o virtgpu_prime.o virtgpu_trace_points.o virtgpu_submit.o
 
 obj-$(CONFIG_DRM_VIRTIO_GPU) += virtio-gpu.o
drivers/gpu/drm/virtio/virtgpu_drv.h +4 -0
index af6ffb696086..4126c384286b 100644
@@ -486,4 +486,8 @@ void virtio_gpu_vram_unmap_dma_buf(struct device *dev,
 				   struct sg_table *sgt,
 				   enum dma_data_direction dir);
 
+/* virtgpu_submit.c */
+int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
+				struct drm_file *file);
+
 #endif
drivers/gpu/drm/virtio/virtgpu_ioctl.c +0 -182

194 lines not on this page · raw message

drivers/gpu/drm/virtio/virtgpu_submit.c new file +295 -0

295 lines not on this page · raw message

Signature · 1 line
2.39.2
author maintainer
#2 lore raw

PATCH v6 2/3 drm/virtio: Wait for each dma-fence of in-fence array individually

In reply to Dmitry Osipenko

Use dma-fence-unwrap API for waiting each dma-fence of the in-fence array individually. Sync file's in-fence array always has a non-matching fence context ID, which doesn't allow to skip waiting of fences with a matching context ID in a case of a merged sync file fence.

Reviewed-by; Emil Velikov <[email protected]>

---
 drivers/gpu/drm/virtio/virtgpu_submit.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
drivers/gpu/drm/virtio/virtgpu_submit.c +18 -2
index 84e7c4d9d8c7..cf3c04b16a7a 100644
@@ -32,8 +32,8 @@ struct virtio_gpu_submit {
 	void *buf;
 };
 
-static int virtio_gpu_dma_fence_wait(struct virtio_gpu_submit *submit,
-				     struct dma_fence *in_fence)
+static int virtio_gpu_do_fence_wait(struct virtio_gpu_submit *submit,
+				    struct dma_fence *in_fence)
 {
 	u32 context = submit->fence_ctx + submit->ring_idx;
 
@@ -43,6 +43,22 @@ static int virtio_gpu_dma_fence_wait(struct virtio_gpu_submit *submit,
 	return dma_fence_wait(in_fence, true);
 }
 
+static int virtio_gpu_dma_fence_wait(struct virtio_gpu_submit *submit,
+				     struct dma_fence *fence)
+{
+	struct dma_fence_unwrap itr;
+	struct dma_fence *f;
+	int err;
+
+	dma_fence_unwrap_for_each(f, &itr, fence) {
+		err = virtio_gpu_do_fence_wait(submit, f);
+		if (err)
+			return err;
+	}
+
+	return 0;
+}
+
 static int virtio_gpu_fence_event_create(struct drm_device *dev,
 					 struct drm_file *file,
 					 struct virtio_gpu_fence *fence,
Signature · 1 line
2.39.2
author maintainer
#3 lore raw

PATCH v6 3/3 drm/virtio: Support sync objects

In reply to Dmitry Osipenko

Add sync object DRM UAPI support to VirtIO-GPU driver. Sync objects support is needed by native context VirtIO-GPU Mesa drivers, it also will be used by Venus and Virgl contexts.

Reviewed-by; Emil Velikov <[email protected]>

---
 drivers/gpu/drm/virtio/virtgpu_drv.c    |   3 +-
 drivers/gpu/drm/virtio/virtgpu_submit.c | 219 ++++++++++++++++++++++++
 include/uapi/drm/virtgpu_drm.h          |  16 +-
 3 files changed, 236 insertions(+), 2 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.c +2 -1
index add075681e18..a22155577152 100644
@@ -176,7 +176,8 @@ static const struct drm_driver driver = {
 	 * If KMS is disabled DRIVER_MODESET and DRIVER_ATOMIC are masked
 	 * out via drm_device::driver_features:
 	 */
-	.driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_RENDER | DRIVER_ATOMIC,
+	.driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_RENDER | DRIVER_ATOMIC |
+			   DRIVER_SYNCOBJ | DRIVER_SYNCOBJ_TIMELINE,
 	.open = virtio_gpu_driver_open,
 	.postclose = virtio_gpu_driver_postclose,
 
drivers/gpu/drm/virtio/virtgpu_submit.c +219 -0

254 lines not on this page · raw message

include/uapi/drm/virtgpu_drm.h +15 -1
index 7b158fcb02b4..b1d0e56565bc 100644
@@ -64,6 +64,16 @@ struct drm_virtgpu_map {
 	__u32 pad;
 };
 
+#define VIRTGPU_EXECBUF_SYNCOBJ_RESET		0x01
+#define VIRTGPU_EXECBUF_SYNCOBJ_FLAGS ( \
+		VIRTGPU_EXECBUF_SYNCOBJ_RESET | \
+		0)
+struct drm_virtgpu_execbuffer_syncobj {
+	__u32 handle;
+	__u32 flags;
+	__u64 point;
+};
+
 /* fence_fd is modified on success if VIRTGPU_EXECBUF_FENCE_FD_OUT flag is set. */
 struct drm_virtgpu_execbuffer {
 	__u32 flags;
@@ -73,7 +83,11 @@ struct drm_virtgpu_execbuffer {
 	__u32 num_bo_handles;
 	__s32 fence_fd; /* in/out fence fd (see VIRTGPU_EXECBUF_FENCE_FD_IN/OUT) */
 	__u32 ring_idx; /* command ring index (see VIRTGPU_EXECBUF_RING_IDX) */
-	__u32 pad;
+	__u32 syncobj_stride; /* size of @drm_virtgpu_execbuffer_syncobj */
+	__u32 num_in_syncobjs;
+	__u32 num_out_syncobjs;
+	__u64 in_syncobjs;
+	__u64 out_syncobjs;
 };
 
 #define VIRTGPU_PARAM_3D_FEATURES 1 /* do we have 3D features in the hw */
Signature · 1 line
2.39.2
author maintainer Tested-by Pierre-Eric Pelloux-Prayer on v6 3/3
#4 lore raw

Re: [PATCH v6 3/3] drm/virtio: Support sync objects

Quoted 11 lines · Dmitry Osipenko

Add sync object DRM UAPI support to VirtIO-GPU driver. Sync objects support is needed by native context VirtIO-GPU Mesa drivers, it also will be used by Venus and Virgl contexts.

Reviewed-by; Emil Velikov <[email protected]>

---
 drivers/gpu/drm/virtio/virtgpu_drv.c    |   3 +-
 drivers/gpu/drm/virtio/virtgpu_submit.c | 219 ++++++++++++++++++++++++
 include/uapi/drm/virtgpu_drm.h          |  16 +-
 3 files changed, 236 insertions(+), 2 deletions(-)

Pierre-Eric tested this v6 patchset with the AMDGPU native context. He has problems his email/ML setup and is unable to reply here. I asked him to provide his t-b on the Mesa MR [1] and now replicating it here.

[1]
https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21658#note_1889792

Signature · 2 lines
Best regards,
Dmitry
#5 lore raw

Re: [PATCH v6 3/3] drm/virtio: Support sync objects

In reply to Dmitry Osipenko

Hi Dmitry,

Quoted 6 lines · Dmitry Osipenko

Add sync object DRM UAPI support to VirtIO-GPU driver. Sync objects support is needed by native context VirtIO-GPU Mesa drivers, it also will be used by Venus and Virgl contexts.

Reviewed-by; Emil Velikov <[email protected]>

Thanks for your patch!

Quoted 9 lines
drivers/gpu/drm/virtio/virtgpu_submit.c +6 -0
 
+static int
+virtio_gpu_parse_deps(struct virtio_gpu_submit *submit)
+{
+       struct drm_virtgpu_execbuffer *exbuf = submit->exbuf;
+       struct drm_virtgpu_execbuffer_syncobj syncobj_desc;
+       size_t syncobj_stride = exbuf->syncobj_stride;

drivers/gpu/drm/virtio/virtgpu_submit.c static int virtio_gpu_dma_fence_wait(struct virtio_gpu_submit *submit, · line 103

Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_submit.c +10 -0
+       u32 num_in_syncobjs = exbuf->num_in_syncobjs;
+       struct drm_syncobj **syncobjs;
+       int ret = 0, i;
+
+       if (!num_in_syncobjs)
+               return 0;
+
+       /*
+        * kvalloc at first tries to allocate memory using kmalloc and
+        * falls back to vmalloc only on failure. It also uses GFP_NOWARN

GFP_NOWARN does not exist.

drivers/gpu/drm/virtio/virtgpu_submit.c static int virtio_gpu_dma_fence_wait(struct virtio_gpu_submit *submit, · line 114

Quoted 11 lines
drivers/gpu/drm/virtio/virtgpu_submit.c +11 -0
+        * internally for allocations larger than a page size, preventing
+        * storm of KMSG warnings.
+        */
+       syncobjs = kvcalloc(num_in_syncobjs, sizeof(*syncobjs), GFP_KERNEL);
+       if (!syncobjs)
+               return -ENOMEM;
+
+       for (i = 0; i < num_in_syncobjs; i++) {
+               u64 address = exbuf->in_syncobjs + i * syncobj_stride;
+               struct dma_fence *fence;
+

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
author maintainer
#6 lore raw

Re: [PATCH v6 3/3] drm/virtio: Support sync objects

Quoted 26 lines · Geert Uytterhoeven

Hi Dmitry,

Quoted 6 lines · Dmitry Osipenko

Add sync object DRM UAPI support to VirtIO-GPU driver. Sync objects support is needed by native context VirtIO-GPU Mesa drivers, it also will be used by Venus and Virgl contexts.

Reviewed-by; Emil Velikov <[email protected]>

Thanks for your patch!

Quoted 13 lines
drivers/gpu/drm/virtio/virtgpu_submit.c +10 -0
 
+static int
+virtio_gpu_parse_deps(struct virtio_gpu_submit *submit)
+{
+       struct drm_virtgpu_execbuffer *exbuf = submit->exbuf;
+       struct drm_virtgpu_execbuffer_syncobj syncobj_desc;
+       size_t syncobj_stride = exbuf->syncobj_stride;
+       u32 num_in_syncobjs = exbuf->num_in_syncobjs;
+       struct drm_syncobj **syncobjs;
+       int ret = 0, i;
+
Quoted 8 lines

drivers/gpu/drm/virtio/virtgpu_submit.c static int virtio_gpu_dma_fence_wait(struct virtio_gpu_submit *submit, · line 103

Quoted 6 lines
drivers/gpu/drm/virtio/virtgpu_submit.c +6 -0
+       if (!num_in_syncobjs)
+               return 0;
+
+       /*
+        * kvalloc at first tries to allocate memory using kmalloc and
+        * falls back to vmalloc only on failure. It also uses GFP_NOWARN

GFP_NOWARN does not exist.

https://elixir.bootlin.com/linux/v6.4-rc7/source/include/linux/gfp_types.h#L38

Signature · 2 lines
Best regards,
Dmitry
#7 lore raw

Re: [PATCH v6 3/3] drm/virtio: Support sync objects

Hi Dmitry,

Quoted 34 lines · Dmitry Osipenko
Quoted 24 lines · Geert Uytterhoeven
Quoted 6 lines · Dmitry Osipenko

Add sync object DRM UAPI support to VirtIO-GPU driver. Sync objects support is needed by native context VirtIO-GPU Mesa drivers, it also will be used by Venus and Virgl contexts.

Reviewed-by; Emil Velikov <[email protected]>

Thanks for your patch!

Quoted 13 lines
drivers/gpu/drm/virtio/virtgpu_submit.c +10 -0
 
+static int
+virtio_gpu_parse_deps(struct virtio_gpu_submit *submit)
+{
+       struct drm_virtgpu_execbuffer *exbuf = submit->exbuf;
+       struct drm_virtgpu_execbuffer_syncobj syncobj_desc;
+       size_t syncobj_stride = exbuf->syncobj_stride;
+       u32 num_in_syncobjs = exbuf->num_in_syncobjs;
+       struct drm_syncobj **syncobjs;
+       int ret = 0, i;
+
Quoted 8 lines

drivers/gpu/drm/virtio/virtgpu_submit.c static int virtio_gpu_dma_fence_wait(struct virtio_gpu_submit *submit, · line 103

Quoted 6 lines
drivers/gpu/drm/virtio/virtgpu_submit.c +6 -0
+       if (!num_in_syncobjs)
+               return 0;
+
+       /*
+        * kvalloc at first tries to allocate memory using kmalloc and
+        * falls back to vmalloc only on failure. It also uses GFP_NOWARN

GFP_NOWARN does not exist.

Quoted 1 line

https://elixir.bootlin.com/linux/v6.4-rc7/source/include/linux/gfp_types.h#L38

That line defines "__GFP_NOWARN", not "GFP_NOWARN". C is case- and underscore-sensitive. as is "git grep -w" ;-)

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
author maintainer
#8 lore raw

Re: [PATCH v6 3/3] drm/virtio: Support sync objects

Quoted 38 lines · Geert Uytterhoeven

Hi Dmitry,

Quoted 34 lines · Dmitry Osipenko
Quoted 32 lines · Geert Uytterhoeven
Quoted 6 lines · Dmitry Osipenko

Add sync object DRM UAPI support to VirtIO-GPU driver. Sync objects support is needed by native context VirtIO-GPU Mesa drivers, it also will be used by Venus and Virgl contexts.

Reviewed-by; Emil Velikov <[email protected]>

Thanks for your patch!

Quoted 9 lines
drivers/gpu/drm/virtio/virtgpu_submit.c +6 -0
 
+static int
+virtio_gpu_parse_deps(struct virtio_gpu_submit *submit)
+{
+       struct drm_virtgpu_execbuffer *exbuf = submit->exbuf;
+       struct drm_virtgpu_execbuffer_syncobj syncobj_desc;
+       size_t syncobj_stride = exbuf->syncobj_stride;

drivers/gpu/drm/virtio/virtgpu_submit.c static int virtio_gpu_dma_fence_wait(struct virtio_gpu_submit *submit, · line 103

Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_submit.c +10 -0
+       u32 num_in_syncobjs = exbuf->num_in_syncobjs;
+       struct drm_syncobj **syncobjs;
+       int ret = 0, i;
+
+       if (!num_in_syncobjs)
+               return 0;
+
+       /*
+        * kvalloc at first tries to allocate memory using kmalloc and
+        * falls back to vmalloc only on failure. It also uses GFP_NOWARN

GFP_NOWARN does not exist.

Quoted 4 lines
Quoted 1 line

https://elixir.bootlin.com/linux/v6.4-rc7/source/include/linux/gfp_types.h#L38

That line defines "__GFP_NOWARN", not "GFP_NOWARN". C is case- and underscore-sensitive. as is "git grep -w" ;-)

The removal of underscores was done intentionally for improving readability of the comment

Signature · 2 lines
Best regards,
Dmitry
#9 lore raw

Re: [PATCH v6 3/3] drm/virtio: Support sync objects

Hi Dmitry,

Quoted 37 lines · Dmitry Osipenko
Quoted 36 lines · Geert Uytterhoeven
Quoted 34 lines · Dmitry Osipenko
Quoted 32 lines · Geert Uytterhoeven
Quoted 6 lines · Dmitry Osipenko

Add sync object DRM UAPI support to VirtIO-GPU driver. Sync objects support is needed by native context VirtIO-GPU Mesa drivers, it also will be used by Venus and Virgl contexts.

Reviewed-by; Emil Velikov <[email protected]>

Thanks for your patch!

Quoted 9 lines
drivers/gpu/drm/virtio/virtgpu_submit.c +6 -0
 
+static int
+virtio_gpu_parse_deps(struct virtio_gpu_submit *submit)
+{
+       struct drm_virtgpu_execbuffer *exbuf = submit->exbuf;
+       struct drm_virtgpu_execbuffer_syncobj syncobj_desc;
+       size_t syncobj_stride = exbuf->syncobj_stride;

drivers/gpu/drm/virtio/virtgpu_submit.c static int virtio_gpu_dma_fence_wait(struct virtio_gpu_submit *submit, · line 103

Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_submit.c +10 -0
+       u32 num_in_syncobjs = exbuf->num_in_syncobjs;
+       struct drm_syncobj **syncobjs;
+       int ret = 0, i;
+
+       if (!num_in_syncobjs)
+               return 0;
+
+       /*
+        * kvalloc at first tries to allocate memory using kmalloc and
+        * falls back to vmalloc only on failure. It also uses GFP_NOWARN

GFP_NOWARN does not exist.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

https://elixir.bootlin.com/linux/v6.4-rc7/source/include/linux/gfp_types.h#L38

That line defines "__GFP_NOWARN", not "GFP_NOWARN". C is case- and underscore-sensitive. as is "git grep -w" ;-)

The removal of underscores was done intentionally for improving readability of the comment

Please don't do that, as IMHO it actually hampers readability:
1. For some xxx, both GFP_xxx and __GFP_xxx are defined, so it does matter which one you are referring to,
2. After dropping the underscores, "git grep -w" can no longer find the definition, nor its users.

Thanks!

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
author maintainer
#10 lore raw

Re: [PATCH v6 3/3] drm/virtio: Support sync objects

27.06.2023 15:01, Geert Uytterhoeven пишет:

Quoted 49 lines

Hi Dmitry,

Quoted 37 lines · Dmitry Osipenko
Quoted 36 lines · Geert Uytterhoeven
Quoted 34 lines · Dmitry Osipenko
Quoted 32 lines · Geert Uytterhoeven
Quoted 6 lines · Dmitry Osipenko

Add sync object DRM UAPI support to VirtIO-GPU driver. Sync objects support is needed by native context VirtIO-GPU Mesa drivers, it also will be used by Venus and Virgl contexts.

Reviewed-by; Emil Velikov <[email protected]>

Thanks for your patch!

Quoted 9 lines
drivers/gpu/drm/virtio/virtgpu_submit.c +6 -0
 
+static int
+virtio_gpu_parse_deps(struct virtio_gpu_submit *submit)
+{
+       struct drm_virtgpu_execbuffer *exbuf = submit->exbuf;
+       struct drm_virtgpu_execbuffer_syncobj syncobj_desc;
+       size_t syncobj_stride = exbuf->syncobj_stride;

drivers/gpu/drm/virtio/virtgpu_submit.c static int virtio_gpu_dma_fence_wait(struct virtio_gpu_submit *submit, · line 103

Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_submit.c +10 -0
+       u32 num_in_syncobjs = exbuf->num_in_syncobjs;
+       struct drm_syncobj **syncobjs;
+       int ret = 0, i;
+
+       if (!num_in_syncobjs)
+               return 0;
+
+       /*
+        * kvalloc at first tries to allocate memory using kmalloc and
+        * falls back to vmalloc only on failure. It also uses GFP_NOWARN

GFP_NOWARN does not exist.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

https://elixir.bootlin.com/linux/v6.4-rc7/source/include/linux/gfp_types.h#L38

That line defines "__GFP_NOWARN", not "GFP_NOWARN". C is case- and underscore-sensitive. as is "git grep -w" ;-)

The removal of underscores was done intentionally for improving readability of the comment

Quoted 7 lines

Please don't do that, as IMHO it actually hampers readability:
1. For some xxx, both GFP_xxx and __GFP_xxx are defined, so it does matter which one you are referring to,
2. After dropping the underscores, "git grep -w" can no longer find the definition, nor its users.

Thanks!

Alright, I'll change it

Signature · 2 lines
Best regards,
Dmitry
author maintainer Applied
#11 lore raw

Re: [PATCH v6 3/3] drm/virtio: Support sync objects

In reply to Dmitry Osipenko
Quoted 11 lines · Dmitry Osipenko

Add sync object DRM UAPI support to VirtIO-GPU driver. Sync objects support is needed by native context VirtIO-GPU Mesa drivers, it also will be used by Venus and Virgl contexts.

Reviewed-by; Emil Velikov <[email protected]>

---
 drivers/gpu/drm/virtio/virtgpu_drv.c    |   3 +-
 drivers/gpu/drm/virtio/virtgpu_submit.c | 219 ++++++++++++++++++++++++
 include/uapi/drm/virtgpu_drm.h          |  16 +-
 3 files changed, 236 insertions(+), 2 deletions(-)

Applied to misc-next

Made a minor comment change that was requested by Geert Uytterhoeven and took into account that outfence now could be NULL after the recent virtio-gpu changes

Signature · 2 lines
Best regards,
Dmitry
#12 lore raw
In reply to Dmitry Osipenko
Quoted 17 lines · Dmitry Osipenko

We have multiple Vulkan context types that are awaiting for the addition of the sync object DRM UAPI support to the VirtIO-GPU kernel driver:

1. Venus context
2. Native contexts (virtio-freedreno, virtio-intel, virtio-amdgpu)

Mesa core supports DRM sync object UAPI, providing Vulkan drivers with a generic fencing implementation that we want to utilize.

This patch adds initial sync objects support. It creates fundament for a further fencing improvements. Later on we will want to extend the VirtIO-GPU
fencing API with passing fence IDs to host for waiting, it will be a new additional VirtIO-GPU IOCTL and more. Today we have several VirtIO-GPU context
drivers in works that require VirtIO-GPU to support sync objects UAPI.

Quoted 3 lines

The patch is heavily inspired by the sync object UAPI implementation of the MSM driver.

The changes seem good, but I would recommend getting a full end-to-end solution (i.e, you've proxied the host fence with these changes and shared with the host compositor) working first. You'll never know what you'll find after completing this exercise. Or is that the plan already?

Typically, you want to land the uAPI and virtio spec changes last. Mesa/gfxstream/virglrenderer/crosvm all have the ability to test out unstable uAPIs ...

Quoted 84 lines

Changelog:

v6: - Added zeroing out of syncobj_desc, as was suggested by Emil Velikov.

- Fixed memleak in error code path which was spotted by Emil Velikov.

- Switched to u32/u64 instead of uint_t. Previously was keeping uint_t style of the virtgpu_ioctl.c, in the end decided to change it because it's not a proper kernel coding style after all.

- Kept single drm_virtgpu_execbuffer_syncobj struct for both in/out sync objects. There was a little concern about whether it would be worthwhile to have separate in/out descriptors, in practice it's unlikely that we will extend the descs in a foreseeable future. There is no overhead in using same struct since we want to pad it to 64b anyways and it shouldn't be a problem to separate the descs later on if we will want to do that.

- Added r-b from Emil Velikov.

v5: - Factored out dma-fence unwrap API usage into separate patch as was
suggested by Emil Velikov.

- Improved and documented the job submission reorderings as was requested by Emil Velikov. Sync file FD is now installed after job is submitted to virtio to further optimize reorderings.

- Added comment for the kvalloc, as was requested by Emil Velikov.

- The num_in/out_syncobjs now is set only after completed parsing of pre/post deps, as was requested by Emil Velikov.

v4: - Added r-b from Rob Clark to the "refactoring" patch.

- Replaced for/while(ptr && itr) with if (ptr), like was suggested by Rob Clark.

- Dropped NOWARN and NORETRY GFP flags and switched syncobj patch to use kvmalloc.

- Removed unused variables from syncobj patch that were borrowed by accident from another (upcoming) patch after one of git rebases.

v3: - Switched to use dma_fence_unwrap_for_each(), like was suggested by
Rob Clark.

- Fixed missing dma_fence_put() in error code path that was spotted by Rob Clark.

- Removed obsoleted comment to virtio_gpu_execbuffer_ioctl(), like was suggested by Rob Clark.

v2: - Fixed chain-fence context matching by making use of
dma_fence_chain_contained().

- Fixed potential uninitialized var usage in error code patch of parse_post_deps(). MSM driver had a similar issue that is fixed already in upstream.

- Added new patch that refactors job submission code path. I found that it was very difficult to add a new/upcoming host-waits feature because of how variables are passed around the code, the
virtgpu_ioctl.c
also was growing to unmanageable size.

Dmitry Osipenko (3):
drm/virtio: Refactor and optimize job submission code path drm/virtio: Wait for each dma-fence of in-fence array individually drm/virtio: Support sync objects

 drivers/gpu/drm/virtio/Makefile         |   2 +-
 drivers/gpu/drm/virtio/virtgpu_drv.c    |   3 +-
 drivers/gpu/drm/virtio/virtgpu_drv.h    |   4 +
 drivers/gpu/drm/virtio/virtgpu_ioctl.c  | 182 --------
 drivers/gpu/drm/virtio/virtgpu_submit.c | 530 ++++++++++++++++++++++++
 include/uapi/drm/virtgpu_drm.h          |  16 +-
 6 files changed, 552 insertions(+), 185 deletions(-)
 create mode 100644 drivers/gpu/drm/virtio/virtgpu_submit.c

--
2.39.2

author maintainer
#13 lore raw

Hello Gurchetan,

Quoted 24 lines · Gurchetan Singh
Quoted 17 lines · Dmitry Osipenko

We have multiple Vulkan context types that are awaiting for the addition of the sync object DRM UAPI support to the VirtIO-GPU kernel driver:

1. Venus context
2. Native contexts (virtio-freedreno, virtio-intel, virtio-amdgpu)

Mesa core supports DRM sync object UAPI, providing Vulkan drivers with a generic fencing implementation that we want to utilize.

This patch adds initial sync objects support. It creates fundament for a further fencing improvements. Later on we will want to extend the VirtIO-GPU
fencing API with passing fence IDs to host for waiting, it will be a new additional VirtIO-GPU IOCTL and more. Today we have several VirtIO-GPU context
drivers in works that require VirtIO-GPU to support sync objects UAPI.

Quoted 3 lines

The patch is heavily inspired by the sync object UAPI implementation of the MSM driver.

Quoted 8 lines

The changes seem good, but I would recommend getting a full end-to-end solution (i.e, you've proxied the host fence with these changes and shared with the host compositor) working first. You'll never know what you'll find after completing this exercise. Or is that the plan already?

Typically, you want to land the uAPI and virtio spec changes last. Mesa/gfxstream/virglrenderer/crosvm all have the ability to test out unstable uAPIs ...

The proxied host fence isn't directly related to sync objects, though I prepared code such that it could be extended with a proxied fence later on, based on a prototype that was made some time ago.

The proxied host fence shouldn't require UAPI changes, but only virtio-gpu proto extension. Normally, all in-fences belong to a job's context, and thus, waits are skipped by the guest kernel. Hence, fence proxying is a separate feature from sync objects, it can be added without sync objects.

Sync objects primarily wanted by native context drivers because Mesa relies on the sync object UAPI presence. It's one of direct blockers for Intel and AMDGPU drivers, both of which has been using this sync object UAPI for a few months and now wanting it to land upstream.

Signature · 2 lines
Best regards,
Dmitry
#14 lore raw
Quoted 33 lines · Dmitry Osipenko

Hello Gurchetan,

Quoted 29 lines · Gurchetan Singh
Quoted 17 lines · Dmitry Osipenko

We have multiple Vulkan context types that are awaiting for the addition of the sync object DRM UAPI support to the VirtIO-GPU kernel driver:

1. Venus context
2. Native contexts (virtio-freedreno, virtio-intel, virtio-amdgpu)

Mesa core supports DRM sync object UAPI, providing Vulkan drivers with a generic fencing implementation that we want to utilize.

This patch adds initial sync objects support. It creates fundament for a further fencing improvements. Later on we will want to extend the VirtIO-GPU
fencing API with passing fence IDs to host for waiting, it will be a new additional VirtIO-GPU IOCTL and more. Today we have several VirtIO-GPU context
drivers in works that require VirtIO-GPU to support sync objects UAPI.

Quoted 3 lines

The patch is heavily inspired by the sync object UAPI implementation of the MSM driver.

The changes seem good, but I would recommend getting a full end-to-end solution (i.e, you've proxied the host fence with these changes and shared with the host compositor) working first. You'll never know what you'll find after completing this exercise. Or is that the plan already?

Quoted 7 lines
Quoted 3 lines

Typically, you want to land the uAPI and virtio spec changes last. Mesa/gfxstream/virglrenderer/crosvm all have the ability to test out unstable uAPIs ...

The proxied host fence isn't directly related to sync objects, though I prepared code such that it could be extended with a proxied fence later on, based on a prototype that was made some time ago.

Proxying the host fence is the novel bit. If you have code that does this, you should rebase/send that out (even as an RFC) so it's easier to see how the pieces fit.

Right now, if you've only tested synchronization objects between the same virtio-gpu context that skips the guest side wait, I think you can already do that with the current uAPI (since ideally you'd wait on the host side and can encode the sync resource in the command stream).

Also, try to come with a simple test (so we can meet requirements here [a]) that showcases the new feature/capability. An example would be the virtio-intel native context sharing a fence with KMS or even Wayland.

[a] https://dri.freedesktop.org/docs/drm/gpu/drm-uapi.html#open-source-userspace-requirements

Quoted 16 lines

The proxied host fence shouldn't require UAPI changes, but only virtio-gpu proto extension. Normally, all in-fences belong to a job's context, and thus, waits are skipped by the guest kernel. Hence, fence proxying is a separate feature from sync objects, it can be added without sync objects.

Sync objects primarily wanted by native context drivers because Mesa relies on the sync object UAPI presence. It's one of direct blockers for Intel and AMDGPU drivers, both of which has been using this sync object UAPI for a few months and now wanting it to land upstream.

--
Best regards,
Dmitry

author maintainer
#15 lore raw
In reply to Dmitry Osipenko
Quoted 9 lines · Dmitry Osipenko

We have multiple Vulkan context types that are awaiting for the addition of the sync object DRM UAPI support to the VirtIO-GPU kernel driver:

1. Venus context
2. Native contexts (virtio-freedreno, virtio-intel, virtio-amdgpu)

Mesa core supports DRM sync object UAPI, providing Vulkan drivers with a generic fencing implementation that we want to utilize.

Quoted 8 lines

This patch adds initial sync objects support. It creates fundament for a further fencing improvements. Later on we will want to extend the VirtIO-GPU fencing API with passing fence IDs to host for waiting, it will be a new additional VirtIO-GPU IOCTL and more. Today we have several VirtIO-GPU context drivers in works that require VirtIO-GPU to support sync objects UAPI.

The patch is heavily inspired by the sync object UAPI implementation of the MSM driver.

Gerd, do you have any objections to merging this series?

We have AMDGPU [1] and Intel [2] native context WIP drivers depending on the sync object support. It is the only part missing from kernel today that is wanted by the native context drivers. Otherwise, there are few other things in Qemu and virglrenderer left to sort out.

[1] https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21658
[2] https://gitlab.freedesktop.org/digetx/mesa/-/commits/native-context-iris

Signature · 2 lines
Best regards,
Dmitry
maintainer Acked-by
#16 lore raw
Quoted 16 lines · Dmitry Osipenko
Quoted 15 lines · Dmitry Osipenko

We have multiple Vulkan context types that are awaiting for the addition of the sync object DRM UAPI support to the VirtIO-GPU kernel driver:

1. Venus context
2. Native contexts (virtio-freedreno, virtio-intel, virtio-amdgpu)

Mesa core supports DRM sync object UAPI, providing Vulkan drivers with a generic fencing implementation that we want to utilize.

This patch adds initial sync objects support. It creates fundament for a further fencing improvements. Later on we will want to extend the VirtIO-GPU fencing API with passing fence IDs to host for waiting, it will be a new additional VirtIO-GPU IOCTL and more. Today we have several VirtIO-GPU context drivers in works that require VirtIO-GPU to support sync objects UAPI.

Quoted 4 lines
Quoted 2 lines

The patch is heavily inspired by the sync object UAPI implementation of the MSM driver.

Gerd, do you have any objections to merging this series?

No objections. Can't spot any issues, but I also don't follow drm close enough to be able to review the sync object logic in detail.

take care,
Gerd

author maintainer
#17 lore raw
Quoted 20 lines · Gerd Hoffmann
Quoted 19 lines · Dmitry Osipenko
Quoted 17 lines · Dmitry Osipenko

We have multiple Vulkan context types that are awaiting for the addition of the sync object DRM UAPI support to the VirtIO-GPU kernel driver:

1. Venus context
2. Native contexts (virtio-freedreno, virtio-intel, virtio-amdgpu)

Mesa core supports DRM sync object UAPI, providing Vulkan drivers with a generic fencing implementation that we want to utilize.

This patch adds initial sync objects support. It creates fundament for a further fencing improvements. Later on we will want to extend the VirtIO-GPU fencing API with passing fence IDs to host for waiting, it will be a new additional VirtIO-GPU IOCTL and more. Today we have several VirtIO-GPU context drivers in works that require VirtIO-GPU to support sync objects UAPI.

The patch is heavily inspired by the sync object UAPI implementation of the MSM driver.

Quoted 6 lines
Quoted 1 line

Gerd, do you have any objections to merging this series?

No objections. Can't spot any issues, but I also don't follow drm close enough to be able to review the sync object logic in detail.

Thanks, I'll work with Gurchetan on resolving his questions and will apply the patches as soon as he'll give his ack.

Signature · 2 lines
Best regards,
Dmitry
#18 lore raw
In reply to Dmitry Osipenko
Quoted 24 lines · Dmitry Osipenko
Quoted 11 lines · Dmitry Osipenko

We have multiple Vulkan context types that are awaiting for the addition of the sync object DRM UAPI support to the VirtIO-GPU kernel driver:

1. Venus context
2. Native contexts (virtio-freedreno, virtio-intel, virtio-amdgpu)

Mesa core supports DRM sync object UAPI, providing Vulkan drivers with a generic fencing implementation that we want to utilize.

This patch adds initial sync objects support. It creates fundament for a further fencing improvements. Later on we will want to extend the

VirtIO-GPU

Quoted 2 lines

fencing API with passing fence IDs to host for waiting, it will be a new additional VirtIO-GPU IOCTL and more. Today we have several VirtIO-GPU

context

Quoted 3 lines

drivers in works that require VirtIO-GPU to support sync objects UAPI.

The patch is heavily inspired by the sync object UAPI implementation of

the

Quoted 1 line

MSM driver.

Gerd, do you have any objections to merging this series?

Quoted 8 lines

We have AMDGPU [1] and Intel [2] native context WIP drivers depending on the sync object support. It is the only part missing from kernel today that is wanted by the native context drivers. Otherwise, there are few other things in Qemu and virglrenderer left to sort out.

[1] https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21658
[2]
https://gitlab.freedesktop.org/digetx/mesa/-/commits/native-context-iris

I'm not saying this change isn't good, just it's probably possible to implement the native contexts (even up to even VK1.2) without it. But this patch series may be the most ergonomic way to do it, given how Mesa is designed. But you probably want one of Mesa MRs reviewed first before merging (I added a comment on the amdgpu change) and that is a requirement [a].

[a] "The userspace side must be fully reviewed and tested to the standards of that user space project. For e.g. mesa this means piglit testcases and review on the mailing list. This is again to ensure that the new interface actually gets the job done." -- from the requirements

Quoted 7 lines

--
Best regards,
Dmitry

#19 lore raw
Quoted 31 lines · Gurchetan Singh
Quoted 27 lines · Dmitry Osipenko
Quoted 9 lines · Dmitry Osipenko

We have multiple Vulkan context types that are awaiting for the addition of the sync object DRM UAPI support to the VirtIO-GPU kernel driver:

1. Venus context
2. Native contexts (virtio-freedreno, virtio-intel, virtio-amdgpu)

Mesa core supports DRM sync object UAPI, providing Vulkan drivers with a generic fencing implementation that we want to utilize.

Quoted 8 lines

This patch adds initial sync objects support. It creates fundament for a further fencing improvements. Later on we will want to extend the VirtIO-GPU fencing API with passing fence IDs to host for waiting, it will be a new additional VirtIO-GPU IOCTL and more. Today we have several VirtIO-GPU context drivers in works that require VirtIO-GPU to support sync objects UAPI.

The patch is heavily inspired by the sync object UAPI implementation of the MSM driver.

Gerd, do you have any objections to merging this series?

We have AMDGPU [1] and Intel [2] native context WIP drivers depending on the sync object support. It is the only part missing from kernel today that is wanted by the native context drivers. Otherwise, there are few other things in Qemu and virglrenderer left to sort out.

Quoted 8 lines
Quoted 2 lines

[1] https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21658
[2] https://gitlab.freedesktop.org/digetx/mesa/-/commits/native-context-iris

I'm not saying this change isn't good, just it's probably possible to implement the native contexts (even up to even VK1.2) without it. But this patch series may be the most ergonomic way to do it, given how Mesa is designed. But you probably want one of Mesa MRs reviewed first before merging (I added a comment on the amdgpu change) and that is a requirement [a].

[a] "The userspace side must be fully reviewed and tested to the standards of that user space project. For e.g. mesa this means piglit testcases and review on the mailing list. This is again to ensure that the new interface actually gets the job done." -- from the requirements

tbh, the syncobj support is all drm core, the only driver specifics is the ioctl parsing. IMHO existing tests and the two existing consumers are sufficient. (Also, considering that additional non-drm dependencies involved.)

If this was for the core drm syncobj implementation, and not just driver ioctl parsing and wiring up the core helpers, I would agree with you.

BR,
-R

#20 lore raw
Quoted 59 lines · Rob Clark
Quoted 4 lines · Gurchetan Singh

On Mon, May 1, 2023 at 8:38 AM Dmitry Osipenko <

Quoted 3 lines · [email protected]> wrote:
Quoted 3 lines · Dmitry Osipenko
Quoted 1 line

We have multiple Vulkan context types that are awaiting for the

addition

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

of the sync object DRM UAPI support to the VirtIO-GPU kernel driver:

1. Venus context
2. Native contexts (virtio-freedreno, virtio-intel, virtio-amdgpu)

Mesa core supports DRM sync object UAPI, providing Vulkan drivers

with a

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

generic fencing implementation that we want to utilize.

This patch adds initial sync objects support. It creates fundament

for a

Quoted 1 line
Quoted 1 line
Quoted 1 line

further fencing improvements. Later on we will want to extend the

VirtIO-GPU

Quoted 1 line
Quoted 1 line
Quoted 1 line

fencing API with passing fence IDs to host for waiting, it will be a

new

Quoted 1 line
Quoted 1 line
Quoted 1 line

additional VirtIO-GPU IOCTL and more. Today we have several

VirtIO-GPU context

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

drivers in works that require VirtIO-GPU to support sync objects UAPI.

The patch is heavily inspired by the sync object UAPI implementation

of the

Quoted 11 lines
Quoted 11 lines
Quoted 1 line

MSM driver.

Gerd, do you have any objections to merging this series?

We have AMDGPU [1] and Intel [2] native context WIP drivers depending on the sync object support. It is the only part missing from kernel today that is wanted by the native context drivers. Otherwise, there are few other things in Qemu and virglrenderer left to sort out.

[1] https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21658
[2]

https://gitlab.freedesktop.org/digetx/mesa/-/commits/native-context-iris

Quoted 3 lines

I'm not saying this change isn't good, just it's probably possible to

implement the native contexts (even up to even VK1.2) without it. But this patch series may be the most ergonomic way to do it, given how Mesa is designed. But you probably want one of Mesa MRs reviewed first before merging (I added a comment on the amdgpu change) and that is a requirement [a].

Quoted 2 lines

[a] "The userspace side must be fully reviewed and tested to the

standards of that user space project. For e.g. mesa this means piglit testcases and review on the mailing list. This is again to ensure that the new interface actually gets the job done." -- from the requirements

Quoted 1 line
Quoted 5 lines

tbh, the syncobj support is all drm core, the only driver specifics is the ioctl parsing. IMHO existing tests and the two existing consumers are sufficient. (Also, considering that additional non-drm dependencies involved.)

Can we get one of the Mesa MRs reviewed first? There's currently no virtio-intel MR AFAICT, and the amdgpu one is marked as "Draft:".

Even for the amdgpu, Pierre suggests the feature "will be marked as experimental both in Mesa and virglrenderer" and we can revise as needed. The DRM requirements seem to warn against adding an UAPI too hastily...

You can get the deqp-vk 1.2 tests to pass with the current UAPI, if you just change your mesa <--> virglrenderer protocol a little. Perhaps that way is even better, since you plumb the in sync-obj into host-side command submission.

Without inter-context sharing of the fence, this MR really only adds guest kernel syntactic sugar.

Note I'm not against syntactic sugar, but I just want to point out that you can likely merge the native context work without any UAPI changes, in case it's not clear.

If this was for the core drm syncobj implementation, and not just

Quoted 3 lines

driver ioctl parsing and wiring up the core helpers, I would agree with you.

There are several possible and viable paths to get the features in question (VK1.2 syncobjs, and inter-context fence sharing). There are paths entirely without the syncobj, paths that only use the syncobj for the inter-context fence sharing case and create host syncobjs for VK1.2, paths that also use guest syncobjs in every proxied command submission.

It's really hard to tell which one is better. Here's my suggestion:

1) Get the native contexts reviewed/merged in Mesa/virglrenderer using the current UAPI. Options for VK1.2 include: pushing down the syncobjs to the host, and simulating the syncobj (as already done). It's fine to mark these contexts as "experimental" like msm-experimental. That will allow you to experiment with the protocols, come up with tests, and hopefully determine an answer to the host versus guest syncobj question.

2) Once you've completed (1), try to add UAPI changes for features that are missing or things that are suboptimal with the knowledge gained from doing (2).

WDYT?

Quoted 4 lines

BR,
-R

author maintainer
#21 lore raw

On 5/12/23 03:17, Gurchetan Singh wrote:
...

Quoted 39 lines

Can we get one of the Mesa MRs reviewed first? There's currently no virtio-intel MR AFAICT, and the amdgpu one is marked as "Draft:".

Even for the amdgpu, Pierre suggests the feature "will be marked as experimental both in Mesa and virglrenderer" and we can revise as needed. The DRM requirements seem to warn against adding an UAPI too hastily...

You can get the deqp-vk 1.2 tests to pass with the current UAPI, if you just change your mesa <--> virglrenderer protocol a little. Perhaps that way is even better, since you plumb the in sync-obj into host-side command submission.

Without inter-context sharing of the fence, this MR really only adds guest kernel syntactic sugar.

Note I'm not against syntactic sugar, but I just want to point out that you can likely merge the native context work without any UAPI changes, in case it's not clear.

If this was for the core drm syncobj implementation, and not just

Quoted 3 lines

driver ioctl parsing and wiring up the core helpers, I would agree with you.

There are several possible and viable paths to get the features in question (VK1.2 syncobjs, and inter-context fence sharing). There are paths entirely without the syncobj, paths that only use the syncobj for the inter-context fence sharing case and create host syncobjs for VK1.2, paths that also use guest syncobjs in every proxied command submission.

It's really hard to tell which one is better. Here's my suggestion:

1) Get the native contexts reviewed/merged in Mesa/virglrenderer using the current UAPI. Options for VK1.2 include: pushing down the syncobjs to the host, and simulating the syncobj (as already done). It's fine to mark these contexts as "experimental" like msm-experimental. That will allow you to experiment with the protocols, come up with tests, and hopefully determine an answer to the host versus guest syncobj question.

Quoted 5 lines

2) Once you've completed (1), try to add UAPI changes for features that are missing or things that are suboptimal with the knowledge gained from doing (2).

WDYT?

Having syncobj support available by DRM driver is a mandatory requirement for native contexts because userspace (Mesa) relies on sync objects support presence. In particular, Intel Mesa driver checks whether DRM driver supports sync objects to decide which features are available, ANV depends on the syncobj support.

I'm not familiar with a history of Venus and its limitations. Perhaps the reason it's using host-side syncobjs is to have 1:1 Vulkan API mapping between guest and host. Not sure if Venus could use guest syncobjs instead or there are problems with that.

When syncobj was initially added to kernel, it was done from the needs of supporting Vulkan wait API. For Venus the actual Vulkan driver is on host side, while for native contexts it's on guest side. Native contexts don't need syncobj on host side, it will be unnecessary overhead for every nctx to have it on host. Hence, if there is no good reason for host-side syncobjs, then why do that?

Native contexts pass deqp synchronization tests, they use sync objects universally for both GL and VK. Games work, piglit/deqp passing. What else you're wanting to test? Turnip?

The AMDGPU code has been looked and it looks good. It's a draft for now because of the missing sync objects UAPI and other virglrender/Qemu changes required to get KMS working. Maybe it will be acceptable to merge the Mesa part once kernel will get sync objects supported, will need to revisit it.

I'm not opening MR for virtio-intel because it has open questions that need to be resolved first.

Signature · 2 lines
Best regards,
Dmitry
#22 lore raw
Quoted 64 lines · Dmitry Osipenko

On 5/12/23 03:17, Gurchetan Singh wrote:
...

Quoted 10 lines

Can we get one of the Mesa MRs reviewed first? There's currently no virtio-intel MR AFAICT, and the amdgpu one is marked as "Draft:".

Even for the amdgpu, Pierre suggests the feature "will be marked as experimental both in Mesa and virglrenderer" and we can revise as needed. The DRM requirements seem to warn against adding an UAPI too hastily...

You can get the deqp-vk 1.2 tests to pass with the current UAPI, if you just change your mesa <--> virglrenderer protocol a little. Perhaps that way is even better, since you plumb the in sync-obj into host-side

command

Quoted 3 lines

submission.

Without inter-context sharing of the fence, this MR really only adds

guest

Quoted 3 lines

kernel syntactic sugar.

Note I'm not against syntactic sugar, but I just want to point out that

you

Quoted 1 line

can likely merge the native context work without any UAPI changes, in

case

Quoted 8 lines

it's not clear.

If this was for the core drm syncobj implementation, and not just

Quoted 3 lines

driver ioctl parsing and wiring up the core helpers, I would agree with you.

There are several possible and viable paths to get the features in

question

Quoted 3 lines

(VK1.2 syncobjs, and inter-context fence sharing). There are paths entirely without the syncobj, paths that only use the syncobj for the inter-context fence sharing case and create host syncobjs for VK1.2,

paths

Quoted 5 lines

that also use guest syncobjs in every proxied command submission.

It's really hard to tell which one is better. Here's my suggestion:

1) Get the native contexts reviewed/merged in Mesa/virglrenderer using

the

Quoted 1 line

current UAPI. Options for VK1.2 include: pushing down the syncobjs to

the

Quoted 6 lines

host, and simulating the syncobj (as already done). It's fine to mark these contexts as "experimental" like msm-experimental. That will allow you to experiment with the protocols, come up with tests, and hopefully determine an answer to the host versus guest syncobj question.

2) Once you've completed (1), try to add UAPI changes for features that

are

Quoted 1 line

missing or things that are suboptimal with the knowledge gained from

doing

Quoted 3 lines

(2).

WDYT?

Having syncobj support available by DRM driver is a mandatory requirement for native contexts because userspace (Mesa) relies on sync objects support presence. In particular, Intel Mesa driver checks whether DRM driver supports sync objects to decide which features are available, ANV depends on the syncobj support.

Quoted 5 lines

I'm not familiar with a history of Venus and its limitations. Perhaps the reason it's using host-side syncobjs is to have 1:1 Vulkan API mapping between guest and host. Not sure if Venus could use guest syncobjs instead or there are problems with that.

Why not submit a Venus MR? It's already in-tree, and you can see how your API works in scenarios with a host side timeline semaphore (aka syncobj). I think they are also interested in fencing/sync improvements.

Quoted 7 lines

When syncobj was initially added to kernel, it was done from the needs of supporting Vulkan wait API. For Venus the actual Vulkan driver is on host side, while for native contexts it's on guest side. Native contexts don't need syncobj on host side, it will be unnecessary overhead for every nctx to have it on host. Hence, if there is no good reason for host-side syncobjs, then why do that?

Depends on your threading model. You can have the following scenarios:

1) N guest contexts : 1 host thread
2) N guest contexts : N host threads for each context
3) 1:1 thread

I think the native context is single-threaded (1), IIRC? If the goal is to push command submission to the host (for inter-context sharing), I think you'll at-least want (2). For a 1:1 model (a la gfxstream), one host thread can put another thread's out_sync_objs as it's in_sync_objs (in the same virtgpu context). I think that's kind of the goal of timeline semaphores, with the example given by Khronos as with a compute thread + a graphics thread.

I'm not saying one threading model is better than any other, perhaps the native context using the host driver in the guest is so good, it doesn't matter. I'm just saying these are the types of discussions we can have if we tried to get one the Mesa MRs merged first ;-)

Quoted 4 lines

Native contexts pass deqp synchronization tests, they use sync objects universally for both GL and VK. Games work, piglit/deqp passing. What else you're wanting to test? Turnip?

Turnip would also fulfill the requirements, since most of the native context stuff is already wired for freedreno.

Quoted 4 lines

The AMDGPU code has been looked and it looks good. It's a draft for now because of the missing sync objects UAPI and other virglrender/Qemu changes required to get KMS working.

Get it out of draft mode then :-). How long would that take?

Also, there's crosvm which builds on standard Linux, so I wouldn't consider QEMU patches as a requirement. Just Mesa/virglrenderer part.

Quoted 4 lines

Maybe it will be acceptable to
merge the Mesa part once kernel will get sync objects supported, will need to revisit it.

You can think of my commentary as the following suggestions:

- You can probably get native contexts and deqp-vk 1.2 working with the current UAPI
- It would be terrific to see inter-context fence sharing working (with the wait pushed down to the host), that's something the current UAPI can't do
- Work iteratively (i.e, it's fine to merge Mesa/virglrenderer MRs as "experimental") and in steps, no need to figure everything out at once

Now these are just suggestions, and while I think they are good, you can safely ignore them.

But there's also the DRM requirements, which state "userspace side must be fully reviewed and tested to the standards of that user-space project.". So I think to meet the minimum requirements, I think we should at-least have one of the following (not all, just one) reviewed:

1) venus using the new uapi
2) gfxstream vk using the new uapi
3) amdgpu nctx out of "draft" mode and using the new uapi.
4) virtio-intel using new uapi
5) turnip using your new uapi

Depending on which one you chose, maybe we can get it done within 1-2 weeks?

I'm not opening MR for virtio-intel because it has open questions that

Quoted 7 lines

need to be resolved first.

--
Best regards,
Dmitry

Tested-by
#23 lore raw
Quoted 120 lines · Gurchetan Singh
Quoted 55 lines · Dmitry Osipenko

On 5/12/23 03:17, Gurchetan Singh wrote:
...

Quoted 39 lines

Can we get one of the Mesa MRs reviewed first? There's currently no virtio-intel MR AFAICT, and the amdgpu one is marked as "Draft:".

Even for the amdgpu, Pierre suggests the feature "will be marked as experimental both in Mesa and virglrenderer" and we can revise as needed. The DRM requirements seem to warn against adding an UAPI too hastily...

You can get the deqp-vk 1.2 tests to pass with the current UAPI, if you just change your mesa <--> virglrenderer protocol a little. Perhaps that way is even better, since you plumb the in sync-obj into host-side command submission.

Without inter-context sharing of the fence, this MR really only adds guest kernel syntactic sugar.

Note I'm not against syntactic sugar, but I just want to point out that you can likely merge the native context work without any UAPI changes, in case it's not clear.

If this was for the core drm syncobj implementation, and not just

Quoted 3 lines

driver ioctl parsing and wiring up the core helpers, I would agree with you.

There are several possible and viable paths to get the features in question (VK1.2 syncobjs, and inter-context fence sharing). There are paths entirely without the syncobj, paths that only use the syncobj for the inter-context fence sharing case and create host syncobjs for VK1.2, paths that also use guest syncobjs in every proxied command submission.

It's really hard to tell which one is better. Here's my suggestion:

1) Get the native contexts reviewed/merged in Mesa/virglrenderer using the current UAPI. Options for VK1.2 include: pushing down the syncobjs to the host, and simulating the syncobj (as already done). It's fine to mark these contexts as "experimental" like msm-experimental. That will allow you to experiment with the protocols, come up with tests, and hopefully determine an answer to the host versus guest syncobj question.

Quoted 5 lines

2) Once you've completed (1), try to add UAPI changes for features that are missing or things that are suboptimal with the knowledge gained from doing (2).

WDYT?

Having syncobj support available by DRM driver is a mandatory requirement for native contexts because userspace (Mesa) relies on sync objects support presence. In particular, Intel Mesa driver checks whether DRM driver supports sync objects to decide which features are available, ANV depends on the syncobj support.

Quoted 4 lines

I'm not familiar with a history of Venus and its limitations. Perhaps the reason it's using host-side syncobjs is to have 1:1 Vulkan API mapping between guest and host. Not sure if Venus could use guest syncobjs instead or there are problems with that.

Why not submit a Venus MR? It's already in-tree, and you can see how your API works in scenarios with a host side timeline semaphore (aka syncobj). I think they are also interested in fencing/sync improvements.

Quoted 8 lines

When syncobj was initially added to kernel, it was done from the needs of supporting Vulkan wait API. For Venus the actual Vulkan driver is on host side, while for native contexts it's on guest side. Native contexts don't need syncobj on host side, it will be unnecessary overhead for every nctx to have it on host. Hence, if there is no good reason for host-side syncobjs, then why do that?

Depends on your threading model. You can have the following scenarios:

1) N guest contexts : 1 host thread
2) N guest contexts : N host threads for each context
3) 1:1 thread

I think the native context is single-threaded (1), IIRC? If the goal is to push command submission to the host (for inter-context sharing), I think you'll at-least want (2). For a 1:1 model (a la gfxstream), one host thread can put another thread's out_sync_objs as it's in_sync_objs (in the same virtgpu context). I think that's kind of the goal of timeline semaphores, with the example given by Khronos as with a compute thread + a graphics thread.

I'm not saying one threading model is better than any other, perhaps the native context using the host driver in the guest is so good, it doesn't matter. I'm just saying these are the types of discussions we can have if we tried to get one the Mesa MRs merged first ;-)

Quoted 4 lines

Native contexts pass deqp synchronization tests, they use sync objects universally for both GL and VK. Games work, piglit/deqp passing. What else you're wanting to test? Turnip?

Turnip would also fulfill the requirements, since most of the native context stuff is already wired for freedreno.

Quoted 5 lines

The AMDGPU code has been looked and it looks good. It's a draft for now because of the missing sync objects UAPI and other virglrender/Qemu changes required to get KMS working.

Get it out of draft mode then :-). How long would that take?

Also, there's crosvm which builds on standard Linux, so I wouldn't consider QEMU patches as a requirement. Just Mesa/virglrenderer part.

Quoted 4 lines

Maybe it will be acceptable to
merge the Mesa part once kernel will get sync objects supported, will need to revisit it.

You can think of my commentary as the following suggestions:

- You can probably get native contexts and deqp-vk 1.2 working with the current UAPI
- It would be terrific to see inter-context fence sharing working (with the wait pushed down to the host), that's something the current UAPI can't do
- Work iteratively (i.e, it's fine to merge Mesa/virglrenderer MRs as "experimental") and in steps, no need to figure everything out at once

Now these are just suggestions, and while I think they are good, you can safely ignore them.

Quoted 7 lines

But there's also the DRM requirements, which state "userspace side must be fully reviewed and tested to the standards of that user-space project.". So I think to meet the minimum requirements, I think we should at-least have one of the following (not all, just one) reviewed:

1) venus using the new uapi
2) gfxstream vk using the new uapi
3) amdgpu nctx out of "draft" mode and using the new uapi.
4) virtio-intel using new uapi
5) turnip using your new uapi

forgot to mention this earlier, but
https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23533

Dmitry, you can also add, if you haven't already:

Quoted 9 lines

Depending on which one you chose, maybe we can get it done within 1-2 weeks?

Quoted 7 lines

I'm not opening MR for virtio-intel because it has open questions that need to be resolved first.

--
Best regards,
Dmitry

author maintainer
#24 lore raw

27.06.2023 20:16, Rob Clark пишет:
...

Quoted 10 lines
Quoted 9 lines

Now these are just suggestions, and while I think they are good, you can safely ignore them.

But there's also the DRM requirements, which state "userspace side must be fully reviewed and tested to the standards of that user-space project.". So I think to meet the minimum requirements, I think we should at-least have one of the following (not all, just one) reviewed:

1) venus using the new uapi
2) gfxstream vk using the new uapi
3) amdgpu nctx out of "draft" mode and using the new uapi.
4) virtio-intel using new uapi
5) turnip using your new uapi

Quoted 6 lines

forgot to mention this earlier, but
https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23533

Dmitry, you can also add, if you haven't already:

Gurchetan, Turnip Mesa virtio support is ready to be merged upstream, it's using this new syncobj UAPI. Could you please give yours r-b if you don't have objections?

Signature · 2 lines
Best regards,
Dmitry
#25 lore raw
Quoted 19 lines · Dmitry Osipenko

27.06.2023 20:16, Rob Clark пишет:
...

Quoted 1 line
Quoted 1 line

Now these are just suggestions, and while I think they are good, you

can safely ignore them.

Quoted 2 lines
Quoted 2 lines

But there's also the DRM requirements, which state "userspace side must

be fully reviewed and tested to the standards of that user-space project.". So I think to meet the minimum requirements, I think we should at-least have one of the following (not all, just one) reviewed:

Quoted 10 lines
Quoted 6 lines

1) venus using the new uapi
2) gfxstream vk using the new uapi
3) amdgpu nctx out of "draft" mode and using the new uapi.
4) virtio-intel using new uapi
5) turnip using your new uapi

forgot to mention this earlier, but
https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23533

Quoted 8 lines
Quoted 3 lines

Dmitry, you can also add, if you haven't already:

Gurchetan, Turnip Mesa virtio support is ready to be merged upstream, it's using this new syncobj UAPI. Could you please give yours r-b if you don't have objections?

Given that Turnip native contexts are reviewed using this UAPI, your change does now meet the requirements and is ready to merge.

One thing I noticed is you might need explicit padding between num_out_syncobjs and in_syncobjs. Otherwise, feel free to add my acked-by.

Quoted 6 lines

--
Best regards,
Dmitry

author maintainer
#26 lore raw
Quoted 31 lines · Gurchetan Singh
Quoted 19 lines · Dmitry Osipenko

27.06.2023 20:16, Rob Clark пишет:
...

Quoted 1 line
Quoted 1 line

Now these are just suggestions, and while I think they are good, you

can safely ignore them.

Quoted 2 lines
Quoted 2 lines

But there's also the DRM requirements, which state "userspace side must

be fully reviewed and tested to the standards of that user-space project.". So I think to meet the minimum requirements, I think we should at-least have one of the following (not all, just one) reviewed:

Quoted 10 lines
Quoted 6 lines

1) venus using the new uapi
2) gfxstream vk using the new uapi
3) amdgpu nctx out of "draft" mode and using the new uapi.
4) virtio-intel using new uapi
5) turnip using your new uapi

forgot to mention this earlier, but
https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23533

Quoted 8 lines
Quoted 3 lines

Dmitry, you can also add, if you haven't already:

Gurchetan, Turnip Mesa virtio support is ready to be merged upstream, it's using this new syncobj UAPI. Could you please give yours r-b if you don't have objections?

Quoted 6 lines

Given that Turnip native contexts are reviewed using this UAPI, your change does now meet the requirements and is ready to merge.

One thing I noticed is you might need explicit padding between num_out_syncobjs and in_syncobjs. Otherwise, feel free to add my acked-by.

The padding looks okay as-as, all the struct size and u64s are properly aligned. I'll merge the patch soon, thanks.

Signature · 2 lines
Best regards,
Dmitry
author maintainer Applied
#27 lore raw
In reply to Dmitry Osipenko
Quoted 3 lines

Dmitry Osipenko (3):
drm/virtio: Refactor and optimize job submission code path drm/virtio: Wait for each dma-fence of in-fence array individually

Applied these two patches to misc-next. The syncobj patch will wait for the turnip Mesa MR.

Signature · 2 lines
Best regards,
Dmitry