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

2023-07-31 Thread Dmitry Osipenko
On 4/16/23 14:52, Dmitry Osipenko wrote:
> 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 
> Signed-off-by: Dmitry Osipenko 
> ---
>  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

-- 
Best regards,
Dmitry



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

2023-07-19 Thread Dmitry Osipenko
27.06.2023 15:01, Geert Uytterhoeven пишет:
> Hi Dmitry,
> 
> On Mon, Jun 26, 2023 at 6:11 PM Dmitry Osipenko
>  wrote:
>> On 6/25/23 18:36, Geert Uytterhoeven wrote:
>>> On Sun, Jun 25, 2023 at 2:41 PM Dmitry Osipenko
>>>  wrote:
 On 6/25/23 11:47, Geert Uytterhoeven wrote:
> On Sun, Apr 16, 2023 at 1:55 PM Dmitry Osipenko
>  wrote:
>> 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 
>> Signed-off-by: Dmitry Osipenko 
>
> Thanks for your patch!
>
>> --- a/drivers/gpu/drm/virtio/virtgpu_submit.c
>> +++ b/drivers/gpu/drm/virtio/virtgpu_submit.c
>
>> +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;
>> +
>> +   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
>>>
>>> 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!

Alright, I'll change it

-- 
Best regards,
Dmitry



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

2023-06-27 Thread Geert Uytterhoeven
Hi Dmitry,

On Mon, Jun 26, 2023 at 6:11 PM Dmitry Osipenko
 wrote:
> On 6/25/23 18:36, Geert Uytterhoeven wrote:
> > On Sun, Jun 25, 2023 at 2:41 PM Dmitry Osipenko
> >  wrote:
> >> On 6/25/23 11:47, Geert Uytterhoeven wrote:
> >>> On Sun, Apr 16, 2023 at 1:55 PM Dmitry Osipenko
> >>>  wrote:
>  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 
>  Signed-off-by: Dmitry Osipenko 
> >>>
> >>> Thanks for your patch!
> >>>
>  --- a/drivers/gpu/drm/virtio/virtgpu_submit.c
>  +++ b/drivers/gpu/drm/virtio/virtgpu_submit.c
> >>>
>  +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;
>  +
>  +   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
> >
> > 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

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@linux-m68k.org

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


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

2023-06-26 Thread Dmitry Osipenko
On 6/25/23 18:36, Geert Uytterhoeven wrote:
> Hi Dmitry,
> 
> On Sun, Jun 25, 2023 at 2:41 PM Dmitry Osipenko
>  wrote:
>> On 6/25/23 11:47, Geert Uytterhoeven wrote:
>>> On Sun, Apr 16, 2023 at 1:55 PM Dmitry Osipenko
>>>  wrote:
 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 
 Signed-off-by: Dmitry Osipenko 
>>>
>>> Thanks for your patch!
>>>
 --- a/drivers/gpu/drm/virtio/virtgpu_submit.c
 +++ b/drivers/gpu/drm/virtio/virtgpu_submit.c
>>>
 +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;
 +
 +   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
> 
> 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

-- 
Best regards,
Dmitry



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

2023-06-25 Thread Geert Uytterhoeven
Hi Dmitry,

On Sun, Jun 25, 2023 at 2:41 PM Dmitry Osipenko
 wrote:
> On 6/25/23 11:47, Geert Uytterhoeven wrote:
> > On Sun, Apr 16, 2023 at 1:55 PM Dmitry Osipenko
> >  wrote:
> >> 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 
> >> Signed-off-by: Dmitry Osipenko 
> >
> > Thanks for your patch!
> >
> >> --- a/drivers/gpu/drm/virtio/virtgpu_submit.c
> >> +++ b/drivers/gpu/drm/virtio/virtgpu_submit.c
> >
> >> +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;
> >> +
> >> +   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

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

Gr{oetje,eeting}s,

Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@linux-m68k.org

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


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

2023-06-25 Thread Dmitry Osipenko
On 6/25/23 11:47, Geert Uytterhoeven wrote:
> Hi Dmitry,
> 
> On Sun, Apr 16, 2023 at 1:55 PM Dmitry Osipenko
>  wrote:
>> 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 
>> Signed-off-by: Dmitry Osipenko 
> 
> Thanks for your patch!
> 
>> --- a/drivers/gpu/drm/virtio/virtgpu_submit.c
>> +++ b/drivers/gpu/drm/virtio/virtgpu_submit.c
> 
>> +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;
>> +
>> +   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

-- 
Best regards,
Dmitry



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

2023-06-25 Thread Geert Uytterhoeven
Hi Dmitry,

On Sun, Apr 16, 2023 at 1:55 PM Dmitry Osipenko
 wrote:
> 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 
> Signed-off-by: Dmitry Osipenko 

Thanks for your patch!

> --- a/drivers/gpu/drm/virtio/virtgpu_submit.c
> +++ b/drivers/gpu/drm/virtio/virtgpu_submit.c

> +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;
> +
> +   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.

> +* 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

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@linux-m68k.org

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


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

2023-05-01 Thread Dmitry Osipenko
On 4/16/23 14:52, Dmitry Osipenko wrote:
> 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 
> Signed-off-by: Dmitry Osipenko 
> ---
>  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

Tested-by: Pierre-Eric Pelloux-Prayer 

-- 
Best regards,
Dmitry



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

2023-04-16 Thread 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 
Signed-off-by: Dmitry Osipenko 
---
 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(-)

diff --git a/drivers/gpu/drm/virtio/virtgpu_drv.c 
b/drivers/gpu/drm/virtio/virtgpu_drv.c
index add075681e18..a22155577152 100644
--- a/drivers/gpu/drm/virtio/virtgpu_drv.c
+++ b/drivers/gpu/drm/virtio/virtgpu_drv.c
@@ -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,
 
diff --git a/drivers/gpu/drm/virtio/virtgpu_submit.c 
b/drivers/gpu/drm/virtio/virtgpu_submit.c
index cf3c04b16a7a..5a0f2526c1a0 100644
--- a/drivers/gpu/drm/virtio/virtgpu_submit.c
+++ b/drivers/gpu/drm/virtio/virtgpu_submit.c
@@ -14,11 +14,24 @@
 #include 
 
 #include 
+#include 
 #include 
 
 #include "virtgpu_drv.h"
 
+struct virtio_gpu_submit_post_dep {
+   struct drm_syncobj *syncobj;
+   struct dma_fence_chain *chain;
+   u64 point;
+};
+
 struct virtio_gpu_submit {
+   struct virtio_gpu_submit_post_dep *post_deps;
+   unsigned int num_out_syncobjs;
+
+   struct drm_syncobj **in_syncobjs;
+   unsigned int num_in_syncobjs;
+
struct virtio_gpu_object_array *buflist;
struct drm_virtgpu_execbuffer *exbuf;
struct virtio_gpu_fence *out_fence;
@@ -59,6 +72,199 @@ static int virtio_gpu_dma_fence_wait(struct 
virtio_gpu_submit *submit,
return 0;
 }
 
+static void virtio_gpu_free_syncobjs(struct drm_syncobj **syncobjs,
+u32 nr_syncobjs)
+{
+   u32 i = nr_syncobjs;
+
+   while (i--) {
+   if (syncobjs[i])
+   drm_syncobj_put(syncobjs[i]);
+   }
+
+   kvfree(syncobjs);
+}
+
+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;
+
+   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
+* 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;
+
+   memset(&syncobj_desc, 0, sizeof(syncobj_desc));
+
+   if (copy_from_user(&syncobj_desc,
+  u64_to_user_ptr(address),
+  min(syncobj_stride, sizeof(syncobj_desc {
+   ret = -EFAULT;
+   break;
+   }
+
+   if (syncobj_desc.flags & ~VIRTGPU_EXECBUF_SYNCOBJ_FLAGS) {
+   ret = -EINVAL;
+   break;
+   }
+
+   ret = drm_syncobj_find_fence(submit->file, syncobj_desc.handle,
+syncobj_desc.point, 0, &fence);
+   if (ret)
+   break;
+
+   ret = virtio_gpu_dma_fence_wait(submit, fence);
+
+   dma_fence_put(fence);
+   if (ret)
+   break;
+
+   if (syncobj_desc.flags & VIRTGPU_EXECBUF_SYNCOBJ_RESET) {
+   syncobjs[i] = drm_syncobj_find(submit->file,
+  syncobj_desc.handle);
+   if (!syncobjs[i]) {
+   ret = -EINVAL;
+   break;
+   }
+   }
+   }
+
+   if (ret) {
+   virtio_gpu_free_syncobjs(syncobjs, i);
+   return ret;
+   }
+
+   submit->num_in_syncobjs = num_in_syncobjs;
+   submit->in_syncobjs = syncobjs;
+
+   return ret;
+}
+
+static void virtio_gp