Skip to contentSkip to conversation

drm/virtio: make resource id workaround runtime switchable.

PATCH Superseded Gerd Hoffmann 2 participants 3 messages Aug 22, 2019 – Aug 26, 2019

Subsystems (4)
lore
Share & tools
lore

Gerd Hoffmann

author maintainer
#0 lore raw

PATCH v2 1/1 drm/virtio: make resource id workaround runtime switchable.

Also update the comment with a reference to the virglrenderer fix.

---
 drivers/gpu/drm/virtio/virtgpu_object.c | 44 ++++++++++++++-----------
 1 file changed, 24 insertions(+), 20 deletions(-)
drivers/gpu/drm/virtio/virtgpu_object.c +24 -20
index b2da31310d24..e98aaa00578d 100644
@@ -27,34 +27,38 @@
 
 #include "virtgpu_drv.h"
 
+static int virtio_gpu_virglrenderer_workaround = 1;
+module_param_named(virglhack, virtio_gpu_virglrenderer_workaround, int, 0400);
+
 static int virtio_gpu_resource_id_get(struct virtio_gpu_device *vgdev,
 				       uint32_t *resid)
 {
-#if 0
-	int handle = ida_alloc(&vgdev->resource_ida, GFP_KERNEL);
-
-	if (handle < 0)
-		return handle;
-#else
-	static int handle;
-
-	/*
-	 * FIXME: dirty hack to avoid re-using IDs, virglrenderer
-	 * can't deal with that.  Needs fixing in virglrenderer, also
-	 * should figure a better way to handle that in the guest.
-	 */
-	handle++;
-#endif
-
-	*resid = handle + 1;
+	if (virtio_gpu_virglrenderer_workaround) {
+		/*
+		 * Hack to avoid re-using resource IDs.
+		 *
+		 * virglrenderer versions up to (and including) 0.7.0
+		 * can't deal with that.  virglrenderer commit
+		 * "f91a9dd35715 Fix unlinking resources from hash
+		 * table." (Feb 2019) fixes the bug.
+		 */
+		static int handle;
+		handle++;
+		*resid = handle + 1;
+	} else {
+		int handle = ida_alloc(&vgdev->resource_ida, GFP_KERNEL);
+		if (handle < 0)
+			return handle;
+		*resid = handle + 1;
+	}
 	return 0;
 }
 
 static void virtio_gpu_resource_id_put(struct virtio_gpu_device *vgdev, uint32_t id)
 {
-#if 0
-	ida_free(&vgdev->resource_ida, id - 1);
-#endif
+	if (!virtio_gpu_virglrenderer_workaround) {
+		ida_free(&vgdev->resource_ida, id - 1);
+	}
 }
 
 static void virtio_gpu_ttm_bo_destroy(struct ttm_buffer_object *tbo)
Signature · 1 line
2.18.1
reviewer Reviewed-by on v2 1/1
#1 lore raw
Quoted 4 lines · Gerd Hoffmann

Also update the comment with a reference to the virglrenderer fix.

Quoted 74 lines
---
 drivers/gpu/drm/virtio/virtgpu_object.c | 44 ++++++++++++++-----------
 1 file changed, 24 insertions(+), 20 deletions(-)
drivers/gpu/drm/virtio/virtgpu_object.c +24 -21
index b2da31310d24..e98aaa00578d 100644
@@ -27,34 +27,38 @@
 
 #include "virtgpu_drv.h"
 
+static int virtio_gpu_virglrenderer_workaround = 1;
+module_param_named(virglhack, virtio_gpu_virglrenderer_workaround, int, 0400);
+
 static int virtio_gpu_resource_id_get(struct virtio_gpu_device *vgdev,
                                       uint32_t *resid)
 {
-#if 0
-       int handle = ida_alloc(&vgdev->resource_ida, GFP_KERNEL);
-
-       if (handle < 0)
-               return handle;
-#else
-       static int handle;
-
-       /*
-        * FIXME: dirty hack to avoid re-using IDs, virglrenderer
-        * can't deal with that.  Needs fixing in virglrenderer, also
-        * should figure a better way to handle that in the guest.
-        */
-       handle++;
-#endif
-
-       *resid = handle + 1;
+       if (virtio_gpu_virglrenderer_workaround) {
+               /*
+                * Hack to avoid re-using resource IDs.
+                *
+                * virglrenderer versions up to (and including) 0.7.0
+                * can't deal with that.  virglrenderer commit
+                * "f91a9dd35715 Fix unlinking resources from hash
+                * table." (Feb 2019) fixes the bug.
+                */
+               static int handle;
+               handle++;
+               *resid = handle + 1;
+       } else {
+               int handle = ida_alloc(&vgdev->resource_ida, GFP_KERNEL);
+               if (handle < 0)
+                       return handle;
+               *resid = handle + 1;
+       }
        return 0;
 }
 
 static void virtio_gpu_resource_id_put(struct virtio_gpu_device *vgdev, uint32_t id)
 {
-#if 0
-       ida_free(&vgdev->resource_ida, id - 1);
-#endif
+       if (!virtio_gpu_virglrenderer_workaround) {
+               ida_free(&vgdev->resource_ida, id - 1);
+       }
 }
 
 static void virtio_gpu_ttm_bo_destroy(struct ttm_buffer_object *tbo)
--

2.18.1

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

reviewer Reviewed-by on v2 1/1
#2 lore raw
In reply to Gerd Hoffmann
Quoted 4 lines · Gerd Hoffmann

Also update the comment with a reference to the virglrenderer fix.

Quoted 74 lines
---
 drivers/gpu/drm/virtio/virtgpu_object.c | 44 ++++++++++++++-----------
 1 file changed, 24 insertions(+), 20 deletions(-)
drivers/gpu/drm/virtio/virtgpu_object.c +24 -21
index b2da31310d24..e98aaa00578d 100644
@@ -27,34 +27,38 @@
 
 #include "virtgpu_drv.h"
 
+static int virtio_gpu_virglrenderer_workaround = 1;
+module_param_named(virglhack, virtio_gpu_virglrenderer_workaround, int, 0400);
+
 static int virtio_gpu_resource_id_get(struct virtio_gpu_device *vgdev,
                                       uint32_t *resid)
 {
-#if 0
-       int handle = ida_alloc(&vgdev->resource_ida, GFP_KERNEL);
-
-       if (handle < 0)
-               return handle;
-#else
-       static int handle;
-
-       /*
-        * FIXME: dirty hack to avoid re-using IDs, virglrenderer
-        * can't deal with that.  Needs fixing in virglrenderer, also
-        * should figure a better way to handle that in the guest.
-        */
-       handle++;
-#endif
-
-       *resid = handle + 1;
+       if (virtio_gpu_virglrenderer_workaround) {
+               /*
+                * Hack to avoid re-using resource IDs.
+                *
+                * virglrenderer versions up to (and including) 0.7.0
+                * can't deal with that.  virglrenderer commit
+                * "f91a9dd35715 Fix unlinking resources from hash
+                * table." (Feb 2019) fixes the bug.
+                */
+               static int handle;
+               handle++;
+               *resid = handle + 1;
+       } else {
+               int handle = ida_alloc(&vgdev->resource_ida, GFP_KERNEL);
+               if (handle < 0)
+                       return handle;
+               *resid = handle + 1;
+       }
        return 0;
 }
 
 static void virtio_gpu_resource_id_put(struct virtio_gpu_device *vgdev, uint32_t id)
 {
-#if 0
-       ida_free(&vgdev->resource_ida, id - 1);
-#endif
+       if (!virtio_gpu_virglrenderer_workaround) {
+               ida_free(&vgdev->resource_ida, id - 1);
+       }
 }
 
 static void virtio_gpu_ttm_bo_destroy(struct ttm_buffer_object *tbo)
--

2.18.1

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