Skip to contentSkip to conversation

drm/virtio: try remove ttm

PATCH Superseded Gerd Hoffmann 2 participants 20 messages Jun 17, 2019 – Jun 18, 2019

Subsystems (4)

v1 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
author maintainer
#1 lore raw

PATCH 1/4 drm/virtio: pass gem reservation object to ttm init

In reply to Gerd Hoffmann

With this gem and ttm will use the same reservation object, so mixing and matching ttm / gem reservation helpers should work fine.

---
 drivers/gpu/drm/virtio/virtgpu_object.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/virtio/virtgpu_object.c +2 -1
index b2da31310d24..242766d644a7 100644
@@ -132,7 +132,8 @@ int virtio_gpu_object_create(struct virtio_gpu_device *vgdev,
 	virtio_gpu_init_ttm_placement(bo);
 	ret = ttm_bo_init(&vgdev->mman.bdev, &bo->tbo, params->size,
 			  ttm_bo_type_device, &bo->placement, 0,
-			  true, acc_size, NULL, NULL,
+			  true, acc_size, NULL,
+			  bo->gem_base.resv,
 			  &virtio_gpu_ttm_bo_destroy);
 	/* ttm_bo_init failure will call the destroy */
 	if (ret != 0)
Signature · 1 line
2.18.1
author maintainer
#5 lore raw

PATCH 1/4 drm/virtio: pass gem reservation object to ttm init

In reply to Gerd Hoffmann

With this gem and ttm will use the same reservation object, so mixing and matching ttm / gem reservation helpers should work fine.

---
 drivers/gpu/drm/virtio/virtgpu_object.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/virtio/virtgpu_object.c +2 -1
index b2da31310d24..242766d644a7 100644
@@ -132,7 +132,8 @@ int virtio_gpu_object_create(struct virtio_gpu_device *vgdev,
 	virtio_gpu_init_ttm_placement(bo);
 	ret = ttm_bo_init(&vgdev->mman.bdev, &bo->tbo, params->size,
 			  ttm_bo_type_device, &bo->placement, 0,
-			  true, acc_size, NULL, NULL,
+			  true, acc_size, NULL,
+			  bo->gem_base.resv,
 			  &virtio_gpu_ttm_bo_destroy);
 	/* ttm_bo_init failure will call the destroy */
 	if (ret != 0)
Signature · 1 line
2.18.1
author maintainer
#6 lore raw

PATCH 2/4 drm/virtio: switch virtio_gpu_wait_ioctl() to gem helper.

In reply to Gerd Hoffmann

Use drm_gem_reservation_object_wait() in virtio_gpu_wait_ioctl().

---
 drivers/gpu/drm/virtio/virtgpu_ioctl.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)
drivers/gpu/drm/virtio/virtgpu_ioctl.c +4 -14
index c0ba1ead740f..e38a6bb46cc7 100644
@@ -464,23 +464,13 @@ static int virtio_gpu_wait_ioctl(struct drm_device *dev, void *data,
 			    struct drm_file *file)
 {
 	struct drm_virtgpu_3d_wait *args = data;
-	struct drm_gem_object *gobj = NULL;
-	struct virtio_gpu_object *qobj = NULL;
-	int ret;
-	bool nowait = false;
-
-	gobj = drm_gem_object_lookup(file, args->handle);
-	if (gobj == NULL)
-		return -ENOENT;
-
-	qobj = gem_to_virtio_gpu_obj(gobj);
+	long timeout = 15 * HZ;
 
 	if (args->flags & VIRTGPU_WAIT_NOWAIT)
-		nowait = true;
-	ret = virtio_gpu_object_wait(qobj, nowait);
+		timeout = 0;
 
-	drm_gem_object_put_unlocked(gobj);
-	return ret;
+	return drm_gem_reservation_object_wait(file, args->handle,
+					       true, timeout);
 }
 
 static int virtio_gpu_get_caps_ioctl(struct drm_device *dev,
Signature · 1 line
2.18.1
author maintainer
#10 lore raw

PATCH 3/4 drm/virtio: simplify cursor updates

In reply to Gerd Hoffmann

No need to do the reservation dance,
we can just wait on the fence directly.

---
 drivers/gpu/drm/virtio/virtgpu_plane.c | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)
drivers/gpu/drm/virtio/virtgpu_plane.c +3 -10
index 024c2aa0c929..4b805bf466d3 100644
@@ -184,7 +184,6 @@ static void virtio_gpu_cursor_plane_update(struct drm_plane *plane,
 	struct virtio_gpu_framebuffer *vgfb;
 	struct virtio_gpu_object *bo = NULL;
 	uint32_t handle;
-	int ret = 0;
 
 	if (plane->state->crtc)
 		output = drm_crtc_to_virtio_gpu_output(plane->state->crtc);
@@ -208,15 +207,9 @@ static void virtio_gpu_cursor_plane_update(struct drm_plane *plane,
 			 cpu_to_le32(plane->state->crtc_w),
 			 cpu_to_le32(plane->state->crtc_h),
 			 0, 0, vgfb->fence);
-		ret = virtio_gpu_object_reserve(bo, false);
-		if (!ret) {
-			reservation_object_add_excl_fence(bo->tbo.resv,
-							  &vgfb->fence->f);
-			dma_fence_put(&vgfb->fence->f);
-			vgfb->fence = NULL;
-			virtio_gpu_object_unreserve(bo);
-			virtio_gpu_object_wait(bo, false);
-		}
+		dma_fence_wait(&vgfb->fence->f, true);
+		dma_fence_put(&vgfb->fence->f);
+		vgfb->fence = NULL;
 	}
 
 	if (plane->state->fb != old_state->fb) {
Signature · 1 line
2.18.1
author maintainer
#15 lore raw

PATCH 3/4 drm/virtio: simplify cursor updates

In reply to Gerd Hoffmann

No need to do the reservation dance,
we can just wait on the fence directly.

---
 drivers/gpu/drm/virtio/virtgpu_plane.c | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)
drivers/gpu/drm/virtio/virtgpu_plane.c +3 -10
index 024c2aa0c929..4b805bf466d3 100644
@@ -184,7 +184,6 @@ static void virtio_gpu_cursor_plane_update(struct drm_plane *plane,
 	struct virtio_gpu_framebuffer *vgfb;
 	struct virtio_gpu_object *bo = NULL;
 	uint32_t handle;
-	int ret = 0;
 
 	if (plane->state->crtc)
 		output = drm_crtc_to_virtio_gpu_output(plane->state->crtc);
@@ -208,15 +207,9 @@ static void virtio_gpu_cursor_plane_update(struct drm_plane *plane,
 			 cpu_to_le32(plane->state->crtc_w),
 			 cpu_to_le32(plane->state->crtc_h),
 			 0, 0, vgfb->fence);
-		ret = virtio_gpu_object_reserve(bo, false);
-		if (!ret) {
-			reservation_object_add_excl_fence(bo->tbo.resv,
-							  &vgfb->fence->f);
-			dma_fence_put(&vgfb->fence->f);
-			vgfb->fence = NULL;
-			virtio_gpu_object_unreserve(bo);
-			virtio_gpu_object_wait(bo, false);
-		}
+		dma_fence_wait(&vgfb->fence->f, true);
+		dma_fence_put(&vgfb->fence->f);
+		vgfb->fence = NULL;
 	}
 
 	if (plane->state->fb != old_state->fb) {
Signature · 1 line
2.18.1
author maintainer
#16 lore raw

PATCH 4/4 drm/virtio: remove virtio_gpu_object_wait

In reply to Gerd Hoffmann

No users left.

---
 drivers/gpu/drm/virtio/virtgpu_drv.h    |  1 -
 drivers/gpu/drm/virtio/virtgpu_object.c | 13 -------------
 2 files changed, 14 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.h +0 -1
index 9e2d3062b01d..2cd96256ba37 100644
@@ -364,7 +364,6 @@ int virtio_gpu_object_kmap(struct virtio_gpu_object *bo);
 int virtio_gpu_object_get_sg_table(struct virtio_gpu_device *qdev,
 				   struct virtio_gpu_object *bo);
 void virtio_gpu_object_free_sg_table(struct virtio_gpu_object *bo);
-int virtio_gpu_object_wait(struct virtio_gpu_object *bo, bool no_wait);
 
 /* virtgpu_prime.c */
 struct sg_table *virtgpu_gem_prime_get_sg_table(struct drm_gem_object *obj);
drivers/gpu/drm/virtio/virtgpu_object.c +0 -13
index 242766d644a7..82bfbf983fd2 100644
@@ -233,16 +233,3 @@ void virtio_gpu_object_free_sg_table(struct virtio_gpu_object *bo)
 	kfree(bo->pages);
 	bo->pages = NULL;
 }
-
-int virtio_gpu_object_wait(struct virtio_gpu_object *bo, bool no_wait)
-{
-	int r;
-
-	r = ttm_bo_reserve(&bo->tbo, true, no_wait, NULL);
-	if (unlikely(r != 0))
-		return r;
-	r = ttm_bo_wait(&bo->tbo, true, no_wait);
-	ttm_bo_unreserve(&bo->tbo);
-	return r;
-}
-
Signature · 1 line
2.18.1

Gerd Hoffmann

author maintainer
#0 lore raw

cover drm/virtio: try remove ttm

ttm increasingly gets into the way while hacking on virtio-gpu memory management. So maybe we are better off without, using gem helpers instead?

Trying remove the dependency on ttm reservations looks like a good first first step to me. This patch series is a (small) start on that.

At the point I'm looking for comments whevener the plan and the initial patches look sane and for things I should possibly watch out for on the way.

thanks,
Gerd

Gerd Hoffmann (4):
drm/virtio: pass gem reservation object to ttm init drm/virtio: switch virtio_gpu_wait_ioctl() to gem helper. drm/virtio: simplify cursor updates
drm/virtio: remove virtio_gpu_object_wait

 drivers/gpu/drm/virtio/virtgpu_drv.h    |  1 -
 drivers/gpu/drm/virtio/virtgpu_ioctl.c  | 18 ++++--------------
 drivers/gpu/drm/virtio/virtgpu_object.c | 16 ++--------------
 drivers/gpu/drm/virtio/virtgpu_plane.c  | 13 +++----------
 4 files changed, 9 insertions(+), 39 deletions(-)
Signature · 6 lines
2.18.1

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

PATCH 2/4 drm/virtio: switch virtio_gpu_wait_ioctl() to gem helper.

Use drm_gem_reservation_object_wait() in virtio_gpu_wait_ioctl().

---
 drivers/gpu/drm/virtio/virtgpu_ioctl.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)
drivers/gpu/drm/virtio/virtgpu_ioctl.c +4 -14
index c0ba1ead740f..e38a6bb46cc7 100644
@@ -464,23 +464,13 @@ static int virtio_gpu_wait_ioctl(struct drm_device *dev, void *data,
 			    struct drm_file *file)
 {
 	struct drm_virtgpu_3d_wait *args = data;
-	struct drm_gem_object *gobj = NULL;
-	struct virtio_gpu_object *qobj = NULL;
-	int ret;
-	bool nowait = false;
-
-	gobj = drm_gem_object_lookup(file, args->handle);
-	if (gobj == NULL)
-		return -ENOENT;
-
-	qobj = gem_to_virtio_gpu_obj(gobj);
+	long timeout = 15 * HZ;
 
 	if (args->flags & VIRTGPU_WAIT_NOWAIT)
-		nowait = true;
-	ret = virtio_gpu_object_wait(qobj, nowait);
+		timeout = 0;
 
-	drm_gem_object_put_unlocked(gobj);
-	return ret;
+	return drm_gem_reservation_object_wait(file, args->handle,
+					       true, timeout);
 }
 
 static int virtio_gpu_get_caps_ioctl(struct drm_device *dev,
Signature · 6 lines
2.18.1

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

PATCH 4/4 drm/virtio: remove virtio_gpu_object_wait

In reply to Gerd Hoffmann

No users left.

---
 drivers/gpu/drm/virtio/virtgpu_drv.h    |  1 -
 drivers/gpu/drm/virtio/virtgpu_object.c | 13 -------------
 2 files changed, 14 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.h +0 -1
index 9e2d3062b01d..2cd96256ba37 100644
@@ -364,7 +364,6 @@ int virtio_gpu_object_kmap(struct virtio_gpu_object *bo);
 int virtio_gpu_object_get_sg_table(struct virtio_gpu_device *qdev,
 				   struct virtio_gpu_object *bo);
 void virtio_gpu_object_free_sg_table(struct virtio_gpu_object *bo);
-int virtio_gpu_object_wait(struct virtio_gpu_object *bo, bool no_wait);
 
 /* virtgpu_prime.c */
 struct sg_table *virtgpu_gem_prime_get_sg_table(struct drm_gem_object *obj);
drivers/gpu/drm/virtio/virtgpu_object.c +0 -13
index 242766d644a7..82bfbf983fd2 100644
@@ -233,16 +233,3 @@ void virtio_gpu_object_free_sg_table(struct virtio_gpu_object *bo)
 	kfree(bo->pages);
 	bo->pages = NULL;
 }
-
-int virtio_gpu_object_wait(struct virtio_gpu_object *bo, bool no_wait)
-{
-	int r;
-
-	r = ttm_bo_reserve(&bo->tbo, true, no_wait, NULL);
-	if (unlikely(r != 0))
-		return r;
-	r = ttm_bo_wait(&bo->tbo, true, no_wait);
-	ttm_bo_unreserve(&bo->tbo);
-	return r;
-}
-
Signature · 6 lines
2.18.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] drm/virtio: pass gem reservation object to ttm init

In reply to Gerd Hoffmann
Quoted 5 lines · Gerd Hoffmann

With this gem and ttm will use the same reservation object, so mixing and matching ttm / gem reservation helpers should work fine.

While doing my prime doc+cleanup series I wondered whether we should do this for everyone, and perhaps even remove ttm_bo.ttm_resv. Only driver which doesn't yet have a gem_bo embedded in the same allocation is vmwgfx, and that would be easy to fix by adding a vmwgfx_resv somehwere.

Anyway, looks like a solid start into the convergence story.

Quoted 21 lines
---
 drivers/gpu/drm/virtio/virtgpu_object.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/virtio/virtgpu_object.c +2 -1
index b2da31310d24..242766d644a7 100644
@@ -132,7 +132,8 @@ int virtio_gpu_object_create(struct virtio_gpu_device *vgdev,
 	virtio_gpu_init_ttm_placement(bo);
 	ret = ttm_bo_init(&vgdev->mman.bdev, &bo->tbo, params->size,
 			  ttm_bo_type_device, &bo->placement, 0,
-			  true, acc_size, NULL, NULL,
+			  true, acc_size, NULL,
+			  bo->gem_base.resv,
 			  &virtio_gpu_ttm_bo_destroy);
 	/* ttm_bo_init failure will call the destroy */
 	if (ret != 0)
Signature · 1 line
2.18.1
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#3 lore raw

Re: [PATCH 1/4] drm/virtio: pass gem reservation object to ttm init

Quoted 7 lines · Daniel Vetter
Quoted 5 lines · Gerd Hoffmann

With this gem and ttm will use the same reservation object, so mixing and matching ttm / gem reservation helpers should work fine.

Quoted 8 lines

While doing my prime doc+cleanup series I wondered whether we should do this for everyone, and perhaps even remove ttm_bo.ttm_resv. Only driver which doesn't yet have a gem_bo embedded in the same allocation is vmwgfx, and that would be easy to fix by adding a vmwgfx_resv somehwere.

Anyway, looks like a solid start into the convergence story.

Aside: if virtio ever allows dma-buf sharing with something else (or multiple virtio-gpu instances), then together with my patch series this will fix dma-buf import. Atm virtio ignores the reservation object of the imported dma-buf, which for foreing objects really isn't correct. -Daniel

Quoted 27 lines
Quoted 22 lines
---
 drivers/gpu/drm/virtio/virtgpu_object.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/virtio/virtgpu_object.c +2 -1
index b2da31310d24..242766d644a7 100644
@@ -132,7 +132,8 @@ int virtio_gpu_object_create(struct virtio_gpu_device *vgdev,
 	virtio_gpu_init_ttm_placement(bo);
 	ret = ttm_bo_init(&vgdev->mman.bdev, &bo->tbo, params->size,
 			  ttm_bo_type_device, &bo->placement, 0,
-			  true, acc_size, NULL, NULL,
+			  true, acc_size, NULL,
+			  bo->gem_base.resv,
 			  &virtio_gpu_ttm_bo_destroy);
 	/* ttm_bo_init failure will call the destroy */
 	if (ret != 0)
Signature · 1 line
2.18.1
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#4 lore raw

Re: [PATCH 1/4] drm/virtio: pass gem reservation object to ttm init

In reply to Daniel Vetter
Quoted 7 lines · Daniel Vetter
Quoted 5 lines · Gerd Hoffmann

With this gem and ttm will use the same reservation object, so mixing and matching ttm / gem reservation helpers should work fine.

Quoted 8 lines

While doing my prime doc+cleanup series I wondered whether we should do this for everyone, and perhaps even remove ttm_bo.ttm_resv. Only driver which doesn't yet have a gem_bo embedded in the same allocation is vmwgfx, and that would be easy to fix by adding a vmwgfx_resv somehwere.

Anyway, looks like a solid start into the convergence story.

Aside: if virtio ever allows dma-buf sharing with something else (or multiple virtio-gpu instances), then together with my patch series this will fix dma-buf import. Atm virtio ignores the reservation object of the imported dma-buf, which for foreing objects really isn't correct. -Daniel

Quoted 27 lines
Quoted 22 lines
---
 drivers/gpu/drm/virtio/virtgpu_object.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/virtio/virtgpu_object.c +2 -1
index b2da31310d24..242766d644a7 100644
@@ -132,7 +132,8 @@ int virtio_gpu_object_create(struct virtio_gpu_device *vgdev,
 	virtio_gpu_init_ttm_placement(bo);
 	ret = ttm_bo_init(&vgdev->mman.bdev, &bo->tbo, params->size,
 			  ttm_bo_type_device, &bo->placement, 0,
-			  true, acc_size, NULL, NULL,
+			  true, acc_size, NULL,
+			  bo->gem_base.resv,
 			  &virtio_gpu_ttm_bo_destroy);
 	/* ttm_bo_init failure will call the destroy */
 	if (ret != 0)
Signature · 1 line
2.18.1
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#8 lore raw

Re: [PATCH 2/4] drm/virtio: switch virtio_gpu_wait_ioctl() to gem helper.

In reply to Gerd Hoffmann
Quoted 1 line · Gerd Hoffmann

Use drm_gem_reservation_object_wait() in virtio_gpu_wait_ioctl().

Would be good to mention here that with this the wait becomes lockless, we don't call ttm_bo_reserve/unreserve anymore.

Quoted 19 lines
---
 drivers/gpu/drm/virtio/virtgpu_ioctl.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)
drivers/gpu/drm/virtio/virtgpu_ioctl.c +0 -6
index c0ba1ead740f..e38a6bb46cc7 100644
@@ -464,23 +464,13 @@ static int virtio_gpu_wait_ioctl(struct drm_device *dev, void *data,
 			    struct drm_file *file)
 {
 	struct drm_virtgpu_3d_wait *args = data;
-	struct drm_gem_object *gobj = NULL;
-	struct virtio_gpu_object *qobj = NULL;
-	int ret;
-	bool nowait = false;
-
-	gobj = drm_gem_object_lookup(file, args->handle);

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

Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c +2 -6
-	if (gobj == NULL)
-		return -ENOENT;
-
-	qobj = gem_to_virtio_gpu_obj(gobj);
+	long timeout = 15 * HZ;
 
 	if (args->flags & VIRTGPU_WAIT_NOWAIT)
-		nowait = true;
-	ret = virtio_gpu_object_wait(qobj, nowait);
+		timeout = 0;

timeout of 0 gets upgrade to a 1 jiffy wait, which is probably not what you want here. You need to open-code ttm_bo_wait here and call reservation_object_test_signaled_rcu() for this case.

With that fixed Reviewed-by: Daniel Vetter <[email protected]>

Quoted 11 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c +2 -2
-	drm_gem_object_put_unlocked(gobj);
-	return ret;
+	return drm_gem_reservation_object_wait(file, args->handle,
+					       true, timeout);
 }
 
 static int virtio_gpu_get_caps_ioctl(struct drm_device *dev,
Signature · 1 line
2.18.1
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#9 lore raw

Re: [PATCH 2/4] drm/virtio: switch virtio_gpu_wait_ioctl() to gem helper.

In reply to Gerd Hoffmann
Quoted 1 line · Gerd Hoffmann

Use drm_gem_reservation_object_wait() in virtio_gpu_wait_ioctl().

Would be good to mention here that with this the wait becomes lockless, we don't call ttm_bo_reserve/unreserve anymore.

Quoted 19 lines
---
 drivers/gpu/drm/virtio/virtgpu_ioctl.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)
drivers/gpu/drm/virtio/virtgpu_ioctl.c +0 -6
index c0ba1ead740f..e38a6bb46cc7 100644
@@ -464,23 +464,13 @@ static int virtio_gpu_wait_ioctl(struct drm_device *dev, void *data,
 			    struct drm_file *file)
 {
 	struct drm_virtgpu_3d_wait *args = data;
-	struct drm_gem_object *gobj = NULL;
-	struct virtio_gpu_object *qobj = NULL;
-	int ret;
-	bool nowait = false;
-
-	gobj = drm_gem_object_lookup(file, args->handle);

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

Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c +2 -6
-	if (gobj == NULL)
-		return -ENOENT;
-
-	qobj = gem_to_virtio_gpu_obj(gobj);
+	long timeout = 15 * HZ;
 
 	if (args->flags & VIRTGPU_WAIT_NOWAIT)
-		nowait = true;
-	ret = virtio_gpu_object_wait(qobj, nowait);
+		timeout = 0;

timeout of 0 gets upgrade to a 1 jiffy wait, which is probably not what you want here. You need to open-code ttm_bo_wait here and call reservation_object_test_signaled_rcu() for this case.

With that fixed Reviewed-by: Daniel Vetter <[email protected]>

Quoted 11 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c +2 -2
-	drm_gem_object_put_unlocked(gobj);
-	return ret;
+	return drm_gem_reservation_object_wait(file, args->handle,
+					       true, timeout);
 }
 
 static int virtio_gpu_get_caps_ioctl(struct drm_device *dev,
Signature · 1 line
2.18.1
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
Reviewed-by on v1 3/4
#11 lore raw

Re: [PATCH 3/4] drm/virtio: simplify cursor updates

In reply to Gerd Hoffmann
Quoted 26 lines · Gerd Hoffmann

No need to do the reservation dance,
we can just wait on the fence directly.

---
 drivers/gpu/drm/virtio/virtgpu_plane.c | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)
drivers/gpu/drm/virtio/virtgpu_plane.c +0 -3
index 024c2aa0c929..4b805bf466d3 100644
@@ -184,7 +184,6 @@ static void virtio_gpu_cursor_plane_update(struct drm_plane *plane,
 	struct virtio_gpu_framebuffer *vgfb;
 	struct virtio_gpu_object *bo = NULL;
 	uint32_t handle;
-	int ret = 0;
 
 	if (plane->state->crtc)
 		output = drm_crtc_to_virtio_gpu_output(plane->state->crtc);
@@ -208,15 +207,9 @@ static void virtio_gpu_cursor_plane_update(struct drm_plane *plane,
 			 cpu_to_le32(plane->state->crtc_w),
 			 cpu_to_le32(plane->state->crtc_h),
 			 0, 0, vgfb->fence);
-		ret = virtio_gpu_object_reserve(bo, false);
-		if (!ret) {

drivers/gpu/drm/virtio/virtgpu_plane.c static void virtio_gpu_cursor_plane_update(struct drm_plane *plane, · line 212

Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_plane.c +3 -7
-			reservation_object_add_excl_fence(bo->tbo.resv,
-							  &vgfb->fence->f);
-			dma_fence_put(&vgfb->fence->f);
-			vgfb->fence = NULL;
-			virtio_gpu_object_unreserve(bo);
-			virtio_gpu_object_wait(bo, false);
-		}
+		dma_fence_wait(&vgfb->fence->f, true);
+		dma_fence_put(&vgfb->fence->f);
+		vgfb->fence = NULL;

Even nicer would be to add the fence using drm_atomic_set_fence_for_plane() in the prepare_fb hook. Assuming this isn't necessary for correctness (but then I kinda have questions about races and stuff).

But this gets the job done too I think, so:

Quoted 6 lines
drivers/gpu/drm/virtio/virtgpu_plane.c +0 -0
 	}
 
 	if (plane->state->fb != old_state->fb) {
Signature · 1 line
2.18.1
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
Reviewed-by on v1 3/4
#14 lore raw

Re: [PATCH 3/4] drm/virtio: simplify cursor updates

In reply to Gerd Hoffmann
Quoted 26 lines · Gerd Hoffmann

No need to do the reservation dance,
we can just wait on the fence directly.

---
 drivers/gpu/drm/virtio/virtgpu_plane.c | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)
drivers/gpu/drm/virtio/virtgpu_plane.c +0 -3
index 024c2aa0c929..4b805bf466d3 100644
@@ -184,7 +184,6 @@ static void virtio_gpu_cursor_plane_update(struct drm_plane *plane,
 	struct virtio_gpu_framebuffer *vgfb;
 	struct virtio_gpu_object *bo = NULL;
 	uint32_t handle;
-	int ret = 0;
 
 	if (plane->state->crtc)
 		output = drm_crtc_to_virtio_gpu_output(plane->state->crtc);
@@ -208,15 +207,9 @@ static void virtio_gpu_cursor_plane_update(struct drm_plane *plane,
 			 cpu_to_le32(plane->state->crtc_w),
 			 cpu_to_le32(plane->state->crtc_h),
 			 0, 0, vgfb->fence);
-		ret = virtio_gpu_object_reserve(bo, false);
-		if (!ret) {

drivers/gpu/drm/virtio/virtgpu_plane.c static void virtio_gpu_cursor_plane_update(struct drm_plane *plane, · line 212

Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_plane.c +3 -7
-			reservation_object_add_excl_fence(bo->tbo.resv,
-							  &vgfb->fence->f);
-			dma_fence_put(&vgfb->fence->f);
-			vgfb->fence = NULL;
-			virtio_gpu_object_unreserve(bo);
-			virtio_gpu_object_wait(bo, false);
-		}
+		dma_fence_wait(&vgfb->fence->f, true);
+		dma_fence_put(&vgfb->fence->f);
+		vgfb->fence = NULL;

Even nicer would be to add the fence using drm_atomic_set_fence_for_plane() in the prepare_fb hook. Assuming this isn't necessary for correctness (but then I kinda have questions about races and stuff).

But this gets the job done too I think, so:

Quoted 6 lines
drivers/gpu/drm/virtio/virtgpu_plane.c +0 -0
 	}
 
 	if (plane->state->fb != old_state->fb) {
Signature · 1 line
2.18.1
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
Reviewed-by on v1 4/4
#18 lore raw

Re: [PATCH 4/4] drm/virtio: remove virtio_gpu_object_wait

In reply to Gerd Hoffmann
Quoted 3 lines · Gerd Hoffmann

No users left.

Quoted 41 lines
---
 drivers/gpu/drm/virtio/virtgpu_drv.h    |  1 -
 drivers/gpu/drm/virtio/virtgpu_object.c | 13 -------------
 2 files changed, 14 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.h +0 -1
index 9e2d3062b01d..2cd96256ba37 100644
@@ -364,7 +364,6 @@ int virtio_gpu_object_kmap(struct virtio_gpu_object *bo);
 int virtio_gpu_object_get_sg_table(struct virtio_gpu_device *qdev,
 				   struct virtio_gpu_object *bo);
 void virtio_gpu_object_free_sg_table(struct virtio_gpu_object *bo);
-int virtio_gpu_object_wait(struct virtio_gpu_object *bo, bool no_wait);
 
 /* virtgpu_prime.c */
 struct sg_table *virtgpu_gem_prime_get_sg_table(struct drm_gem_object *obj);
drivers/gpu/drm/virtio/virtgpu_object.c +0 -13
index 242766d644a7..82bfbf983fd2 100644
@@ -233,16 +233,3 @@ void virtio_gpu_object_free_sg_table(struct virtio_gpu_object *bo)
 	kfree(bo->pages);
 	bo->pages = NULL;
 }
-
-int virtio_gpu_object_wait(struct virtio_gpu_object *bo, bool no_wait)
-{
-	int r;
-
-	r = ttm_bo_reserve(&bo->tbo, true, no_wait, NULL);
-	if (unlikely(r != 0))
-		return r;
-	r = ttm_bo_wait(&bo->tbo, true, no_wait);
-	ttm_bo_unreserve(&bo->tbo);
-	return r;
-}
-
Signature · 1 line
2.18.1
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#19 lore raw
In reply to Gerd Hoffmann
Quoted 10 lines · Gerd Hoffmann

ttm increasingly gets into the way while hacking on virtio-gpu memory management. So maybe we are better off without, using gem helpers instead?

Trying remove the dependency on ttm reservations looks like a good first first step to me. This patch series is a (small) start on that.

At the point I'm looking for comments whevener the plan and the initial patches look sane and for things I should possibly watch out for on the way.

This matches my own plan for aligning gem and ttm more, so +1 from me.

Long-term I'm not sure whether we should embed a drm_gem_object into the ttm_buffer_object, or whether we should extract more helpers from ttm into gem helpers, or something in-between. But there's a bunch of lower-hanging fruit to take care of first.

Cheers, Daniel

Quoted 24 lines

thanks,
Gerd

Gerd Hoffmann (4):
drm/virtio: pass gem reservation object to ttm init drm/virtio: switch virtio_gpu_wait_ioctl() to gem helper. drm/virtio: simplify cursor updates
drm/virtio: remove virtio_gpu_object_wait

 drivers/gpu/drm/virtio/virtgpu_drv.h    |  1 -
 drivers/gpu/drm/virtio/virtgpu_ioctl.c  | 18 ++++--------------
 drivers/gpu/drm/virtio/virtgpu_object.c | 16 ++--------------
 drivers/gpu/drm/virtio/virtgpu_plane.c  | 13 +++----------
 4 files changed, 9 insertions(+), 39 deletions(-)
Signature · 6 lines
2.18.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author maintainer
#12 lore raw

Re: [PATCH 3/4] drm/virtio: simplify cursor updates

In reply to Daniel Vetter
Quoted 4 lines

Even nicer would be to add the fence using drm_atomic_set_fence_for_plane() in the prepare_fb hook. Assuming this isn't necessary for correctness (but then I kinda have questions about races and stuff).

I'll have a look. Maybe this way I can drop struct virtio_gpu_framebuffer (where the fence is the only thing beside struct drm_framebuffer).

cheers,
Gerd

author maintainer
#13 lore raw

Re: [PATCH 3/4] drm/virtio: simplify cursor updates

In reply to Daniel Vetter
Quoted 4 lines

Even nicer would be to add the fence using drm_atomic_set_fence_for_plane() in the prepare_fb hook. Assuming this isn't necessary for correctness (but then I kinda have questions about races and stuff).

I'll have a look. Maybe this way I can drop struct virtio_gpu_framebuffer (where the fence is the only thing beside struct drm_framebuffer).

cheers,
Gerd