drm/virtio: switch from ttm to gem shmem helpers.
Subsystems (4)
Gerd Hoffmann
maintainerv6 cover drm/virtio: switch from ttm to gem shmem helpers.
ttm increasingly gets into the way while hacking on virtio-gpu memory management. It also overkill for what virtio-gpu needs. Lets get rid of it.
v6:
- largely rewrite fencing logic, using the virtio_gpu_array_* helpers
- add more patches to the series.
v5:
- fence bugfixes.
- minor optimizations.
v4:
- make gem array helpers private to virtio.
- misc minor fixes.
v3:
- add gem array helpers.
- rework fencing.
cheers,
Gerd
Gerd Hoffmann (18):
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
drm/virtio: drop no_wait argument from virtio_gpu_object_reserve drm/virtio: remove ttm calls from in
virtio_gpu_object_{reserve,unreserve} drm/virtio: add virtio_gpu_object_array & helpers drm/virtio: rework virtio_gpu_execbuffer_ioctl fencing drm/virtio: rework virtio_gpu_object_create fencing drm/virtio: drop virtio_gpu_object_list_validate/virtio_gpu_unref_list drm/virtio: switch from ttm to gem shmem helpers drm/virtio: remove virtio_gpu_alloc_object
drm/virtio: drop virtio_gpu_object_{ref,unref}
drm/virtio: rework virtio_gpu_transfer_from_host_ioctl fencing drm/virtio: rework virtio_gpu_transfer_to_host_ioctl fencing drm/virtio: rework virtio_gpu_cmd_context_{attach,detach}_resource drm/virtio: drop virtio_gpu_object_{reserve,unreserve} drm/virtio: add fence sanity check
drivers/gpu/drm/virtio/virtgpu_drv.h | 121 +++------- drivers/gpu/drm/virtio/virtgpu_drv.c | 20 +- drivers/gpu/drm/virtio/virtgpu_fence.c | 4 + drivers/gpu/drm/virtio/virtgpu_gem.c | 146 ++++++++---- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 222 ++++++----------- drivers/gpu/drm/virtio/virtgpu_kms.c | 9 - drivers/gpu/drm/virtio/virtgpu_object.c | 220 +++++------------ drivers/gpu/drm/virtio/virtgpu_plane.c | 13 +- drivers/gpu/drm/virtio/virtgpu_prime.c | 37 --- drivers/gpu/drm/virtio/virtgpu_ttm.c | 304 ------------------------ drivers/gpu/drm/virtio/virtgpu_vq.c | 72 ++++-- drivers/gpu/drm/virtio/Kconfig | 2 +- drivers/gpu/drm/virtio/Makefile | 2 +- 13 files changed, 338 insertions(+), 834 deletions(-) delete mode 100644 drivers/gpu/drm/virtio/virtgpu_ttm.c
Signature · 6 lines
2.18.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Gerd Hoffmann
maintainerPATCH v6 1/18 drm/virtio: pass gem reservation object to ttm init
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
@@ -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
Gerd Hoffmann
maintainerPATCH v6 1/18 drm/virtio: pass gem reservation object to ttm init
In reply to Gerd HoffmannWith 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
@@ -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
Gerd Hoffmann
maintainerPATCH v6 2/18 drm/virtio: switch virtio_gpu_wait_ioctl() to gem helper.
In reply to Gerd HoffmannUse drm_gem_reservation_object_wait() in virtio_gpu_wait_ioctl(). This also makes the ioctl run lockless.
v5: handle lookup failure.
v2: use reservation_object_test_signaled_rcu for VIRTGPU_WAIT_NOWAIT.
--- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 28 ++++++++++++-------------- 1 file changed, 13 insertions(+), 15 deletions(-)
drivers/gpu/drm/virtio/virtgpu_ioctl.c +13 -15
@@ -464,23 +464,21 @@ 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 ; +struct drm_gem_object *obj; +long timeout =15 *HZ ;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); - -if (args->flags &VIRTGPU_WAIT_NOWAIT ) - nowait = true; - ret =virtio_gpu_object_wait (qobj, nowait); - -drm_gem_object_put_unlocked (gobj); -return ret; +if (args->flags &VIRTGPU_WAIT_NOWAIT ) { + obj =drm_gem_object_lookup (file, args->handle); +if (obj ==NULL ) +return -ENOENT ; + ret =reservation_object_test_signaled_rcu (obj->resv, true); +drm_gem_object_put_unlocked (obj); +return ret ?0 : -EBUSY ; + } + +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
Gerd Hoffmann
maintainerPATCH v6 2/18 drm/virtio: switch virtio_gpu_wait_ioctl() to gem helper.
In reply to Gerd HoffmannUse drm_gem_reservation_object_wait() in virtio_gpu_wait_ioctl(). This also makes the ioctl run lockless.
v5: handle lookup failure.
v2: use reservation_object_test_signaled_rcu for VIRTGPU_WAIT_NOWAIT.
--- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 28 ++++++++++++-------------- 1 file changed, 13 insertions(+), 15 deletions(-)
drivers/gpu/drm/virtio/virtgpu_ioctl.c +13 -15
@@ -464,23 +464,21 @@ 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 ; +struct drm_gem_object *obj; +long timeout =15 *HZ ;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); - -if (args->flags &VIRTGPU_WAIT_NOWAIT ) - nowait = true; - ret =virtio_gpu_object_wait (qobj, nowait); - -drm_gem_object_put_unlocked (gobj); -return ret; +if (args->flags &VIRTGPU_WAIT_NOWAIT ) { + obj =drm_gem_object_lookup (file, args->handle); +if (obj ==NULL ) +return -ENOENT ; + ret =reservation_object_test_signaled_rcu (obj->resv, true); +drm_gem_object_put_unlocked (obj); +return ret ?0 : -EBUSY ; + } + +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
Gerd Hoffmann
maintainerPATCH v6 3/18 drm/virtio: simplify cursor updates
In reply to Gerd HoffmannNo 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
@@ -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
Gerd Hoffmann
maintainerPATCH v6 3/18 drm/virtio: simplify cursor updates
In reply to Gerd HoffmannNo 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
@@ -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 · 6 lines
2.18.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Gerd Hoffmann
maintainerPATCH v6 4/18 drm/virtio: remove virtio_gpu_object_wait
In reply to Gerd HoffmannNo 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
@@ -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
@@ -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
maintainerPATCH v6 4/18 drm/virtio: remove virtio_gpu_object_wait
In reply to Gerd HoffmannNo 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
@@ -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
@@ -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
Gerd Hoffmann
maintainerPATCH v6 5/18 drm/virtio: drop no_wait argument from virtio_gpu_object_reserve
In reply to Gerd HoffmannAll callers pass no_wait = false.
--- drivers/gpu/drm/virtio/virtgpu_drv.h | 5 ++--- drivers/gpu/drm/virtio/virtgpu_gem.c | 4 ++-- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.h +2 -3
@@ -398,12 +398,11 @@ static inline u64 virtio_gpu_object_mmap_offset(struct virtio_gpu_object *bo)return drm_vma_node_offset_addr (&bo->tbo.vma_node); } -static inline int virtio_gpu_object_reserve (struct virtio_gpu_object *bo, -bool no_wait) +static inline int virtio_gpu_object_reserve (struct virtio_gpu_object *bo) {int r; - r =ttm_bo_reserve (&bo->tbo, true, no_wait,NULL ); + r =ttm_bo_reserve (&bo->tbo, true, false,NULL );if (unlikely (r !=0 )) {if (r != -ERESTARTSYS ) { struct virtio_gpu_device *qdev =
drivers/gpu/drm/virtio/virtgpu_gem.c +2 -2
@@ -140,7 +140,7 @@ int virtio_gpu_gem_object_open(struct drm_gem_object *obj,if (!vgdev->has_virgl_3d)return 0 ; - r =virtio_gpu_object_reserve (qobj, false); + r =virtio_gpu_object_reserve (qobj);if (r)return r;
@@ -161,7 +161,7 @@ void virtio_gpu_gem_object_close(struct drm_gem_object *obj,if (!vgdev->has_virgl_3d)return ; - r =virtio_gpu_object_reserve (qobj, false); + r =virtio_gpu_object_reserve (qobj);if (r)return ;
drivers/gpu/drm/virtio/virtgpu_ioctl.c +2 -2
@@ -375,7 +375,7 @@ static int virtio_gpu_transfer_from_host_ioctl(struct drm_device *dev, qobj =gem_to_virtio_gpu_obj (gobj); - ret =virtio_gpu_object_reserve (qobj, false); + ret =virtio_gpu_object_reserve (qobj);if (ret) goto out;
@@ -425,7 +425,7 @@ static int virtio_gpu_transfer_to_host_ioctl(struct drm_device *dev, void *data, qobj =gem_to_virtio_gpu_obj (gobj); - ret =virtio_gpu_object_reserve (qobj, false); + ret =virtio_gpu_object_reserve (qobj);if (ret) goto out;
Signature · 1 line
2.18.1
Gerd Hoffmann
maintainerPATCH v6 5/18 drm/virtio: drop no_wait argument from virtio_gpu_object_reserve
In reply to Gerd HoffmannAll callers pass no_wait = false.
--- drivers/gpu/drm/virtio/virtgpu_drv.h | 5 ++--- drivers/gpu/drm/virtio/virtgpu_gem.c | 4 ++-- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.h +2 -3
@@ -398,12 +398,11 @@ static inline u64 virtio_gpu_object_mmap_offset(struct virtio_gpu_object *bo)return drm_vma_node_offset_addr (&bo->tbo.vma_node); } -static inline int virtio_gpu_object_reserve (struct virtio_gpu_object *bo, -bool no_wait) +static inline int virtio_gpu_object_reserve (struct virtio_gpu_object *bo) {int r; - r =ttm_bo_reserve (&bo->tbo, true, no_wait,NULL ); + r =ttm_bo_reserve (&bo->tbo, true, false,NULL );if (unlikely (r !=0 )) {if (r != -ERESTARTSYS ) { struct virtio_gpu_device *qdev =
drivers/gpu/drm/virtio/virtgpu_gem.c +2 -2
@@ -140,7 +140,7 @@ int virtio_gpu_gem_object_open(struct drm_gem_object *obj,if (!vgdev->has_virgl_3d)return 0 ; - r =virtio_gpu_object_reserve (qobj, false); + r =virtio_gpu_object_reserve (qobj);if (r)return r;
@@ -161,7 +161,7 @@ void virtio_gpu_gem_object_close(struct drm_gem_object *obj,if (!vgdev->has_virgl_3d)return ; - r =virtio_gpu_object_reserve (qobj, false); + r =virtio_gpu_object_reserve (qobj);if (r)return ;
drivers/gpu/drm/virtio/virtgpu_ioctl.c +2 -2
@@ -375,7 +375,7 @@ static int virtio_gpu_transfer_from_host_ioctl(struct drm_device *dev, qobj =gem_to_virtio_gpu_obj (gobj); - ret =virtio_gpu_object_reserve (qobj, false); + ret =virtio_gpu_object_reserve (qobj);if (ret) goto out;
@@ -425,7 +425,7 @@ static int virtio_gpu_transfer_to_host_ioctl(struct drm_device *dev, void *data, qobj =gem_to_virtio_gpu_obj (gobj); - ret =virtio_gpu_object_reserve (qobj, false); + ret =virtio_gpu_object_reserve (qobj);if (ret) goto out;
Signature · 6 lines
2.18.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Gerd Hoffmann
maintainerPATCH v6 6/18 drm/virtio: remove ttm calls from in virtio_gpu_object_{reserve, unreserve}
In reply to Gerd HoffmannCall reservation_object_* directly instead
of using ttm_bo_{reserve,unreserve}.
v4: check for EINTR only.
v3: check for EINTR too.
--- drivers/gpu/drm/virtio/virtgpu_drv.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.h +3 -3
@@ -402,9 +402,9 @@ static inline int virtio_gpu_object_reserve(struct virtio_gpu_object *bo) {int r; - r =ttm_bo_reserve (&bo->tbo, true, false,NULL ); + r =reservation_object_lock_interruptible (bo->gem_base.resv,NULL );if (unlikely (r !=0 )) { -if (r != -ERESTARTSYS ) { +if (r != -EINTR ) {struct virtio_gpu_device *qdev = bo->gem_base.dev->dev_private;dev_err (qdev->dev,"%p reserve failed\n" , bo);
@@ -416,7 +416,7 @@ static inline int virtio_gpu_object_reserve(struct virtio_gpu_object *bo)static inline void virtio_gpu_object_unreserve (struct virtio_gpu_object *bo) { -ttm_bo_unreserve (&bo->tbo); +reservation_object_unlock (bo->gem_base.resv); }/* virgl debufs */
Signature · 1 line
2.18.1
Gerd Hoffmann
maintainerPATCH v6 6/18 drm/virtio: remove ttm calls from in virtio_gpu_object_{reserve,unreserve}
In reply to Gerd HoffmannCall reservation_object_* directly instead
of using ttm_bo_{reserve,unreserve}.
v4: check for EINTR only.
v3: check for EINTR too.
--- drivers/gpu/drm/virtio/virtgpu_drv.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.h +3 -3
@@ -402,9 +402,9 @@ static inline int virtio_gpu_object_reserve(struct virtio_gpu_object *bo) {int r; - r =ttm_bo_reserve (&bo->tbo, true, false,NULL ); + r =reservation_object_lock_interruptible (bo->gem_base.resv,NULL );if (unlikely (r !=0 )) { -if (r != -ERESTARTSYS ) { +if (r != -EINTR ) {struct virtio_gpu_device *qdev = bo->gem_base.dev->dev_private;dev_err (qdev->dev,"%p reserve failed\n" , bo);
@@ -416,7 +416,7 @@ static inline int virtio_gpu_object_reserve(struct virtio_gpu_object *bo)static inline void virtio_gpu_object_unreserve (struct virtio_gpu_object *bo) { -ttm_bo_unreserve (&bo->tbo); +reservation_object_unlock (bo->gem_base.resv); }/* virgl debufs */
Signature · 6 lines
2.18.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Chia-I Wu
reviewerRe: [PATCH v6 06/18] drm/virtio: remove ttm calls from in virtio_gpu_object_{reserve,unreserve}
Quoted 18 lines · Gerd Hoffmann
Call reservation_object_* directly instead
of using ttm_bo_{reserve,unreserve}.v4: check for EINTR only.
v3: check for EINTR too.Signed-off-by Gerd Hoffmann <[email protected]>Reviewed-by Daniel Vetter <[email protected]>--- drivers/gpu/drm/virtio/virtgpu_drv.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/gpu/drm/virtio/virtgpu_drv.h +0
-0
drivers/gpu/drm/virtio/virtgpu_drv.h static inline int virtio_gpu_object_reserve(struct virtio_gpu_object *bo) · line 405
Quoted 5 lines
drivers/gpu/drm/virtio/virtgpu_drv.h +1
-1@@ -402,9 +402,9 @@ static inline int virtio_gpu_object_reserve(struct virtio_gpu_object *bo) {int r; - r =ttm_bo_reserve (&bo->tbo, true, false,NULL ); + r =reservation_object_lock_interruptible (bo->gem_base.resv,NULL );
Can you elaborate a bit about how TTM keeps the BOs alive in, for example, virtio_gpu_transfer_from_host_ioctl? In that function, only three TTM functions are called: ttm_bo_reserve, ttm_bo_validate, and ttm_bo_unreserve. I am curious how they keep the BO alive.
Quoted 18 lines
drivers/gpu/drm/virtio/virtgpu_drv.h +2
-3if (unlikely (r !=0 )) { -if (r != -ERESTARTSYS ) { +if (r != -EINTR ) {struct virtio_gpu_device *qdev = bo->gem_base.dev->dev_private;dev_err (qdev->dev,"%p reserve failed\n" , bo);@@ -416,7 +416,7 @@ static inline int virtio_gpu_object_reserve(struct virtio_gpu_object *bo)static inline void virtio_gpu_object_unreserve (struct virtio_gpu_object *bo) { -ttm_bo_unreserve (&bo->tbo); +reservation_object_unlock (bo->gem_base.resv); }/* virgl debufs */ --2.18.1
Gerd Hoffmann
maintainerRe: [PATCH v6 06/18] drm/virtio: remove ttm calls from in virtio_gpu_object_{reserve,unreserve}
Hi,
Quoted 6 lines
drivers/gpu/drm/virtio/virtgpu_drv.h static inline int virtio_gpu_object_reserve(struct virtio_gpu_object *bo) · line 405
Quoted 2 lines
drivers/gpu/drm/virtio/virtgpu_drv.h +1
-1- r =ttm_bo_reserve (&bo->tbo, true, false,NULL ); + r =reservation_object_lock_interruptible (bo->gem_base.resv,NULL );Can you elaborate a bit about how TTM keeps the BOs alive in, for example,
virtio_gpu_transfer_from_host_ioctl? In that function, only three TTM functions are called:ttm_bo_reserve,ttm_bo_validate, andttm_bo_unreserve. I am curious how they keep the BO alive.
It can't go away between reserve and unreserve, and I think it also can't be evicted then. Havn't checked how ttm implements that.
cheers,
Gerd
Chia-I Wu
reviewerRe: [PATCH v6 06/18] drm/virtio: remove ttm calls from in virtio_gpu_object_{reserve, unreserve}
Quoted 5 lines · Gerd Hoffmann
Hi,
Quoted 2 lines
Quoted 2 lines
drivers/gpu/drm/virtio/virtgpu_drv.h +1
-1- r =ttm_bo_reserve (&bo->tbo, true, false,NULL ); + r =reservation_object_lock_interruptible (bo->gem_base.resv,NULL );
Quoted 7 lines
Quoted 4 lines
Can you elaborate a bit about how TTM keeps the BOs alive in, for example,
virtio_gpu_transfer_from_host_ioctl? In that function, only three TTM functions are called:ttm_bo_reserve,ttm_bo_validate, andttm_bo_unreserve. I am curious how they keep the BO alive.It can't go away between reserve and unreserve, and I think it also can't be evicted then. Havn't checked how ttm implements that.
Hm, but the vbuf using the BO outlives the reserve/unreserve section. The NO_EVICT flag applies only when the BO is still alive. Someone needs to hold a reference to the BO to keep it alive, otherwise the BO can go away before the vbuf is retired.
I can be wrong, but on the other hand, it seems fine for a BO to go away before the vbuf using it is retired. When that happens, the driver emits a RESOURCE_UNREF vbuf which is *after* the original vbuf.
Quoted 4 lines
cheers,
Gerd
Chia-I Wu
reviewerRe: [PATCH v6 06/18] drm/virtio: remove ttm calls from in virtio_gpu_object_{reserve,unreserve}
In reply to Gerd HoffmannQuoted 5 lines · Gerd Hoffmann
Hi,
Quoted 2 lines
Quoted 2 lines
drivers/gpu/drm/virtio/virtgpu_drv.h +1
-1- r =ttm_bo_reserve (&bo->tbo, true, false,NULL ); + r =reservation_object_lock_interruptible (bo->gem_base.resv,NULL );
Quoted 7 lines
Quoted 4 lines
Can you elaborate a bit about how TTM keeps the BOs alive in, for example,
virtio_gpu_transfer_from_host_ioctl? In that function, only three TTM functions are called:ttm_bo_reserve,ttm_bo_validate, andttm_bo_unreserve. I am curious how they keep the BO alive.It can't go away between reserve and unreserve, and I think it also can't be evicted then. Havn't checked how ttm implements that.
Hm, but the vbuf using the BO outlives the reserve/unreserve section. The NO_EVICT flag applies only when the BO is still alive. Someone needs to hold a reference to the BO to keep it alive, otherwise the BO can go away before the vbuf is retired.
I can be wrong, but on the other hand, it seems fine for a BO to go away before the vbuf using it is retired. When that happens, the driver emits a RESOURCE_UNREF vbuf which is *after* the original vbuf.
Quoted 4 lines
cheers,
Gerd
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Gerd Hoffmann
maintainerRe: [PATCH v6 06/18] drm/virtio: remove ttm calls from in virtio_gpu_object_{reserve,unreserve}
Quoted 11 lines · Chia-I Wu
Quoted 10 lines · Gerd Hoffmann
Hi,
Quoted 6 lines
drivers/gpu/drm/virtio/virtgpu_drv.h static inline int virtio_gpu_object_reserve(struct virtio_gpu_object *bo) · line 405
Quoted 2 lines
drivers/gpu/drm/virtio/virtgpu_drv.h +1
-1- r =ttm_bo_reserve (&bo->tbo, true, false,NULL ); + r =reservation_object_lock_interruptible (bo->gem_base.resv,NULL );Can you elaborate a bit about how TTM keeps the BOs alive in, for example,
virtio_gpu_transfer_from_host_ioctl? In that function, only three TTM functions are called:ttm_bo_reserve,ttm_bo_validate, andttm_bo_unreserve. I am curious how they keep the BO alive.
Quoted 6 lines
Quoted 2 lines
It can't go away between reserve and unreserve, and I think it also can't be evicted then. Havn't checked how ttm implements that.
Hm, but the vbuf using the BO outlives the reserve/unreserve section. The
NO_EVICTflag applies only when the BO is still alive. Someone needs to hold a reference to the BO to keep it alive, otherwise the BO can go away before the vbuf is retired.
Note that patches 14+15 rework virtio_gpu_transfer_*_ioctl to keep gem reference until the command is finished and patch 17 drops virtio_gpu_object_{reserve,unreserve} altogether.
Maybe I should try to reorder the series, then squash 6+17 to reduce confusion. I suspect that'll cause quite a few conflicts though ...
cheers,
Gerd
Chia-I Wu
reviewerRe: [PATCH v6 06/18] drm/virtio: remove ttm calls from in virtio_gpu_object_{reserve, unreserve}
Quoted 20 lines · Gerd Hoffmann
Quoted 11 lines · Chia-I Wu
Quoted 10 lines · Gerd Hoffmann
Hi,
Quoted 6 lines
drivers/gpu/drm/virtio/virtgpu_drv.h static inline int virtio_gpu_object_reserve(struct virtio_gpu_object *bo) · line 405
Quoted 2 lines
drivers/gpu/drm/virtio/virtgpu_drv.h +1
-1- r =ttm_bo_reserve (&bo->tbo, true, false,NULL ); + r =reservation_object_lock_interruptible (bo->gem_base.resv,NULL );Can you elaborate a bit about how TTM keeps the BOs alive in, for example,
virtio_gpu_transfer_from_host_ioctl? In that function, only three TTM functions are called:ttm_bo_reserve,ttm_bo_validate, andttm_bo_unreserve. I am curious how they keep the BO alive.Quoted 6 lines
Quoted 2 lines
It can't go away between reserve and unreserve, and I think it also can't be evicted then. Havn't checked how ttm implements that.
Hm, but the vbuf using the BO outlives the reserve/unreserve section. The
NO_EVICTflag applies only when the BO is still alive. Someone needs to hold a reference to the BO to keep it alive, otherwise the BO can go away before the vbuf is retired.
Quoted 6 lines
Note that patches 14+15 rework virtio_gpu_transfer_*_ioctl to keep gem reference until the command is finished and patch 17 drops virtio_gpu_object_{reserve,unreserve} altogether.
Maybe I should try to reorder the series, then squash 6+17 to reduce confusion. I suspect that'll cause quite a few conflicts though ...
This may be well-known and is what you meant by "the fence keeps the bo alive", but I finally realize that ttm_bo_put delays the deletion of a BO when it is busy.
In the current design, vbuf does not hold references to its BOs. Nor do fences. It is possible for a BO to lose all its references and gets virtio_gpu_gem_free_object()ed while it is still busy. The key is ttm_bo_put.
ttm_bo_put calls ttm_bo_cleanup_refs_or_queue to decide whether to delete the BO immediately (when the BO is already idle) or to queue the BO to a delayed delete list (when the BO is still busy). If a BO is queued to the delayed delete list, ttm_bo_delayed_delete is called every 10ms (HZ/100 to be exact) to scan through the list and delete idled BOs.
I wrote a simple test (attached) and added a bunch of printk's to confirm this.
Anyway, I believe the culprit is patch 11, when we switch from ttm_bo_put to drm_gem_shmem_free_object to free a BO whose last reference is gone. The deletion becomes immediately after the switch. We need to fix vbuf to refcount its BOs before we can do the switch.
Quoted 4 lines
cheers,
Gerd
/* gcc -std=c11 -D_GNU_SOURCE -o virtio-gpu-bo virtio-gpu-bo.c */
#include <assert.h>
#include <stdint.h>
#include <stdio.h>
#include <fcntl.h>
#include <libdrm/drm.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#define PIPE_BUFFER 0
#define VIRGL_FORMAT_R8_UNORM 64
#define VIRGL_BIND_CONSTANT_BUFFER (1 << 6)
#define DRM_VIRTGPU_RESOURCE_CREATE 0x04
#define DRM_IOCTL_VIRTGPU_RESOURCE_CREATE \
DRM_IOWR(DRM_COMMAND_BASE + DRM_VIRTGPU_RESOURCE_CREATE, \
struct drm_virtgpu_resource_create)
struct drm_virtgpu_resource_create {
uint32_t target;
uint32_t format;
uint32_t bind;
uint32_t width;
uint32_t height;
uint32_t depth;
uint32_t array_size;
uint32_t last_level;
uint32_t nr_samples;
uint32_t flags;
uint32_t bo_handle;
uint32_t res_handle;
uint32_t size;
uint32_t stride;
};struct drm_virtgpu_3d_box {
uint32_t x, y, z;
uint32_t w, h, d;
};#define DRM_VIRTGPU_TRANSFER_TO_HOST 0x07
#define DRM_IOCTL_VIRTGPU_TRANSFER_TO_HOST \
DRM_IOWR(DRM_COMMAND_BASE + DRM_VIRTGPU_TRANSFER_TO_HOST, \
struct drm_virtgpu_3d_transfer_to_host)
struct drm_virtgpu_3d_transfer_to_host {
uint32_t bo_handle;
struct drm_virtgpu_3d_box box;
uint32_t level;
uint32_t offset;
}; static uint32_t buffer_create(int fd, uint32_t size)
{
struct drm_virtgpu_resource_create args = {
.target = PIPE_BUFFER,
.format = VIRGL_FORMAT_R8_UNORM,
.bind = VIRGL_BIND_CONSTANT_BUFFER,
.width = size,
.height = 1,
.depth = 1,
.array_size = 1,
.nr_samples = 1,
};
int ret = ioctl(fd, DRM_IOCTL_VIRTGPU_RESOURCE_CREATE, &args);
assert(!ret);
return args.bo_handle;
}static void buffer_close(int fd, uint32_t bo)
{
struct drm_gem_close args = {
.handle = bo,
};
int ret = ioctl(fd, DRM_IOCTL_GEM_CLOSE, &args);
assert(!ret);
}
static void transfer_to_host(int fd, uint32_t bo, uint32_t size)
{
struct drm_virtgpu_3d_transfer_to_host args = {
.bo_handle = bo,
.box.w = size,
.box.h = 1,
.box.d = 1,
};
int ret = ioctl(fd, DRM_IOCTL_VIRTGPU_TRANSFER_TO_HOST, &args);
assert(!ret);
}int main()
{
const uint32_t size = 1 * 1024 * 1024;
int fd = open("/dev/dri/renderD128", O_RDWR);
assert(fd >= 0);
uint32_t bo = buffer_create(fd, size);
printf("transfer and close the BO immediately...\n");
transfer_to_host(fd, bo, size);
buffer_close(fd, bo);
printf("wait for 1 second...\n");
usleep(1000 * 1000);
close(fd);
return 0;
}_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Chia-I Wu
reviewerRe: [PATCH v6 06/18] drm/virtio: remove ttm calls from in virtio_gpu_object_{reserve,unreserve}
In reply to Gerd HoffmannQuoted 20 lines · Gerd Hoffmann
Quoted 11 lines · Chia-I Wu
Quoted 10 lines · Gerd Hoffmann
Hi,
Quoted 6 lines
drivers/gpu/drm/virtio/virtgpu_drv.h static inline int virtio_gpu_object_reserve(struct virtio_gpu_object *bo) · line 405
Quoted 2 lines
drivers/gpu/drm/virtio/virtgpu_drv.h +1
-1- r =ttm_bo_reserve (&bo->tbo, true, false,NULL ); + r =reservation_object_lock_interruptible (bo->gem_base.resv,NULL );Can you elaborate a bit about how TTM keeps the BOs alive in, for example,
virtio_gpu_transfer_from_host_ioctl? In that function, only three TTM functions are called:ttm_bo_reserve,ttm_bo_validate, andttm_bo_unreserve. I am curious how they keep the BO alive.Quoted 6 lines
Quoted 2 lines
It can't go away between reserve and unreserve, and I think it also can't be evicted then. Havn't checked how ttm implements that.
Hm, but the vbuf using the BO outlives the reserve/unreserve section. The
NO_EVICTflag applies only when the BO is still alive. Someone needs to hold a reference to the BO to keep it alive, otherwise the BO can go away before the vbuf is retired.
Quoted 6 lines
Note that patches 14+15 rework virtio_gpu_transfer_*_ioctl to keep gem reference until the command is finished and patch 17 drops virtio_gpu_object_{reserve,unreserve} altogether.
Maybe I should try to reorder the series, then squash 6+17 to reduce confusion. I suspect that'll cause quite a few conflicts though ...
This may be well-known and is what you meant by "the fence keeps the bo alive", but I finally realize that ttm_bo_put delays the deletion of a BO when it is busy.
In the current design, vbuf does not hold references to its BOs. Nor do fences. It is possible for a BO to lose all its references and gets virtio_gpu_gem_free_object()ed while it is still busy. The key is ttm_bo_put.
ttm_bo_put calls ttm_bo_cleanup_refs_or_queue to decide whether to delete the BO immediately (when the BO is already idle) or to queue the BO to a delayed delete list (when the BO is still busy). If a BO is queued to the delayed delete list, ttm_bo_delayed_delete is called every 10ms (HZ/100 to be exact) to scan through the list and delete idled BOs.
I wrote a simple test (attached) and added a bunch of printk's to confirm this.
Anyway, I believe the culprit is patch 11, when we switch from ttm_bo_put to drm_gem_shmem_free_object to free a BO whose last reference is gone. The deletion becomes immediately after the switch. We need to fix vbuf to refcount its BOs before we can do the switch.
Quoted 4 lines
cheers,
Gerd
/* gcc -std=c11 -D_GNU_SOURCE -o virtio-gpu-bo virtio-gpu-bo.c */
#include <assert.h>
#include <stdint.h>
#include <stdio.h>
#include <fcntl.h>
#include <libdrm/drm.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#define PIPE_BUFFER 0
#define VIRGL_FORMAT_R8_UNORM 64
#define VIRGL_BIND_CONSTANT_BUFFER (1 << 6)
#define DRM_VIRTGPU_RESOURCE_CREATE 0x04
#define DRM_IOCTL_VIRTGPU_RESOURCE_CREATE \
DRM_IOWR(DRM_COMMAND_BASE + DRM_VIRTGPU_RESOURCE_CREATE, \
struct drm_virtgpu_resource_create)
struct drm_virtgpu_resource_create {
uint32_t target;
uint32_t format;
uint32_t bind;
uint32_t width;
uint32_t height;
uint32_t depth;
uint32_t array_size;
uint32_t last_level;
uint32_t nr_samples;
uint32_t flags;
uint32_t bo_handle;
uint32_t res_handle;
uint32_t size;
uint32_t stride;
};struct drm_virtgpu_3d_box {
uint32_t x, y, z;
uint32_t w, h, d;
};#define DRM_VIRTGPU_TRANSFER_TO_HOST 0x07
#define DRM_IOCTL_VIRTGPU_TRANSFER_TO_HOST \
DRM_IOWR(DRM_COMMAND_BASE + DRM_VIRTGPU_TRANSFER_TO_HOST, \
struct drm_virtgpu_3d_transfer_to_host)
struct drm_virtgpu_3d_transfer_to_host {
uint32_t bo_handle;
struct drm_virtgpu_3d_box box;
uint32_t level;
uint32_t offset;
}; static uint32_t buffer_create(int fd, uint32_t size)
{
struct drm_virtgpu_resource_create args = {
.target = PIPE_BUFFER,
.format = VIRGL_FORMAT_R8_UNORM,
.bind = VIRGL_BIND_CONSTANT_BUFFER,
.width = size,
.height = 1,
.depth = 1,
.array_size = 1,
.nr_samples = 1,
};
int ret = ioctl(fd, DRM_IOCTL_VIRTGPU_RESOURCE_CREATE, &args);
assert(!ret);
return args.bo_handle;
}static void buffer_close(int fd, uint32_t bo)
{
struct drm_gem_close args = {
.handle = bo,
};
int ret = ioctl(fd, DRM_IOCTL_GEM_CLOSE, &args);
assert(!ret);
}
static void transfer_to_host(int fd, uint32_t bo, uint32_t size)
{
struct drm_virtgpu_3d_transfer_to_host args = {
.bo_handle = bo,
.box.w = size,
.box.h = 1,
.box.d = 1,
};
int ret = ioctl(fd, DRM_IOCTL_VIRTGPU_TRANSFER_TO_HOST, &args);
assert(!ret);
}int main()
{
const uint32_t size = 1 * 1024 * 1024;
int fd = open("/dev/dri/renderD128", O_RDWR);
assert(fd >= 0);
uint32_t bo = buffer_create(fd, size);
printf("transfer and close the BO immediately...\n");
transfer_to_host(fd, bo, size);
buffer_close(fd, bo);
printf("wait for 1 second...\n");
usleep(1000 * 1000);
close(fd);
return 0;
}_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Gerd Hoffmann
maintainerRe: [PATCH v6 06/18] drm/virtio: remove ttm calls from in virtio_gpu_object_{reserve,unreserve}
In reply to Chia-I WuQuoted 11 lines · Chia-I Wu
Quoted 10 lines · Gerd Hoffmann
Hi,
Quoted 6 lines
drivers/gpu/drm/virtio/virtgpu_drv.h static inline int virtio_gpu_object_reserve(struct virtio_gpu_object *bo) · line 405
Quoted 2 lines
drivers/gpu/drm/virtio/virtgpu_drv.h +1
-1- r =ttm_bo_reserve (&bo->tbo, true, false,NULL ); + r =reservation_object_lock_interruptible (bo->gem_base.resv,NULL );Can you elaborate a bit about how TTM keeps the BOs alive in, for example,
virtio_gpu_transfer_from_host_ioctl? In that function, only three TTM functions are called:ttm_bo_reserve,ttm_bo_validate, andttm_bo_unreserve. I am curious how they keep the BO alive.
Quoted 6 lines
Quoted 2 lines
It can't go away between reserve and unreserve, and I think it also can't be evicted then. Havn't checked how ttm implements that.
Hm, but the vbuf using the BO outlives the reserve/unreserve section. The
NO_EVICTflag applies only when the BO is still alive. Someone needs to hold a reference to the BO to keep it alive, otherwise the BO can go away before the vbuf is retired.
Note that patches 14+15 rework virtio_gpu_transfer_*_ioctl to keep gem reference until the command is finished and patch 17 drops virtio_gpu_object_{reserve,unreserve} altogether.
Maybe I should try to reorder the series, then squash 6+17 to reduce confusion. I suspect that'll cause quite a few conflicts though ...
cheers,
Gerd
Gerd Hoffmann
maintainerRe: [PATCH v6 06/18] drm/virtio: remove ttm calls from in virtio_gpu_object_{reserve,unreserve}
In reply to Chia-I WuHi,
Quoted 6 lines
drivers/gpu/drm/virtio/virtgpu_drv.h static inline int virtio_gpu_object_reserve(struct virtio_gpu_object *bo) · line 405
Quoted 2 lines
drivers/gpu/drm/virtio/virtgpu_drv.h +1
-1- r =ttm_bo_reserve (&bo->tbo, true, false,NULL ); + r =reservation_object_lock_interruptible (bo->gem_base.resv,NULL );Can you elaborate a bit about how TTM keeps the BOs alive in, for example,
virtio_gpu_transfer_from_host_ioctl? In that function, only three TTM functions are called:ttm_bo_reserve,ttm_bo_validate, andttm_bo_unreserve. I am curious how they keep the BO alive.
It can't go away between reserve and unreserve, and I think it also can't be evicted then. Havn't checked how ttm implements that.
cheers,
Gerd
Gerd Hoffmann
maintainerPATCH v6 7/18 drm/virtio: add virtio_gpu_object_array & helpers
In reply to Gerd HoffmannSome helper functions to manage an array of gem objects.
v6:
- add ticket to struct virtio_gpu_object_array.
- add virtio_gpu_array_{lock,unlock}_resv helpers.
- add virtio_gpu_array_add_fence helper.
v5: some small optimizations (Chia-I Wu).
v4: make them virtio-private instead of generic helpers.
--- drivers/gpu/drm/virtio/virtgpu_drv.h | 17 ++++++ drivers/gpu/drm/virtio/virtgpu_gem.c | 83 ++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+)
drivers/gpu/drm/virtio/virtgpu_drv.h +17 -0
@@ -84,6 +84,12 @@ struct virtio_gpu_object {#define gem_to_virtio_gpu_obj (gobj) \ container_of((gobj), struct virtio_gpu_object, gem_base) +struct virtio_gpu_object_array { +struct ww_acquire_ctx ticket; +u32 nents, total; +struct drm_gem_object *objs[]; +}; +struct virtio_gpu_vbuffer ;struct virtio_gpu_device ;
@@ -251,6 +257,17 @@ int virtio_gpu_mode_dumb_mmap(struct drm_file *file_priv,struct drm_device *dev, uint32_t handle, uint64_t *offset_p); +struct virtio_gpu_object_array *virtio_gpu_array_alloc (u32 nents); +struct virtio_gpu_object_array * +virtio_gpu_array_from_handles (struct drm_file *drm_file,u32 *handles,u32 nents); +void virtio_gpu_array_add_obj (struct virtio_gpu_object_array *objs, +struct drm_gem_object *obj); +int virtio_gpu_array_lock_resv (struct virtio_gpu_object_array *objs); +void virtio_gpu_array_unlock_resv (struct virtio_gpu_object_array *objs); +void virtio_gpu_array_add_fence (struct virtio_gpu_object_array *objs, +struct dma_fence *fence); +void virtio_gpu_array_put_free (struct virtio_gpu_object_array *objs); +/* virtio vg */ int virtio_gpu_alloc_vbufs (struct virtio_gpu_device *vgdev);void virtio_gpu_free_vbufs (struct virtio_gpu_device *vgdev);
drivers/gpu/drm/virtio/virtgpu_gem.c +83 -0
86 lines not on this page · raw message
Signature · 1 line
2.18.1
Gerd Hoffmann
maintainerPATCH v6 7/18 drm/virtio: add virtio_gpu_object_array & helpers
In reply to Gerd HoffmannSome helper functions to manage an array of gem objects.
v6:
- add ticket to struct virtio_gpu_object_array.
- add virtio_gpu_array_{lock,unlock}_resv helpers.
- add virtio_gpu_array_add_fence helper.
v5: some small optimizations (Chia-I Wu).
v4: make them virtio-private instead of generic helpers.
--- drivers/gpu/drm/virtio/virtgpu_drv.h | 17 ++++++ drivers/gpu/drm/virtio/virtgpu_gem.c | 83 ++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+)
drivers/gpu/drm/virtio/virtgpu_drv.h +17 -0
@@ -84,6 +84,12 @@ struct virtio_gpu_object {#define gem_to_virtio_gpu_obj (gobj) \ container_of((gobj), struct virtio_gpu_object, gem_base) +struct virtio_gpu_object_array { +struct ww_acquire_ctx ticket; +u32 nents, total; +struct drm_gem_object *objs[]; +}; +struct virtio_gpu_vbuffer ;struct virtio_gpu_device ;
@@ -251,6 +257,17 @@ int virtio_gpu_mode_dumb_mmap(struct drm_file *file_priv,struct drm_device *dev, uint32_t handle, uint64_t *offset_p); +struct virtio_gpu_object_array *virtio_gpu_array_alloc (u32 nents); +struct virtio_gpu_object_array * +virtio_gpu_array_from_handles (struct drm_file *drm_file,u32 *handles,u32 nents); +void virtio_gpu_array_add_obj (struct virtio_gpu_object_array *objs, +struct drm_gem_object *obj); +int virtio_gpu_array_lock_resv (struct virtio_gpu_object_array *objs); +void virtio_gpu_array_unlock_resv (struct virtio_gpu_object_array *objs); +void virtio_gpu_array_add_fence (struct virtio_gpu_object_array *objs, +struct dma_fence *fence); +void virtio_gpu_array_put_free (struct virtio_gpu_object_array *objs); +/* virtio vg */ int virtio_gpu_alloc_vbufs (struct virtio_gpu_device *vgdev);void virtio_gpu_free_vbufs (struct virtio_gpu_device *vgdev);
drivers/gpu/drm/virtio/virtgpu_gem.c +83 -0
86 lines not on this page · raw message
Signature · 6 lines
2.18.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Chia-I Wu
reviewerRe: [PATCH v6 07/18] drm/virtio: add virtio_gpu_object_array & helpers
Quoted 81 lines · Gerd Hoffmann
Some helper functions to manage an array of gem objects.
v6:
- add ticket to structvirtio_gpu_object_array.
- add virtio_gpu_array_{lock,unlock}_resv helpers.
- addvirtio_gpu_array_add_fencehelper.
v5: some small optimizations (Chia-I Wu).
v4: make them virtio-private instead of generic helpers.Signed-off-by Gerd Hoffmann <[email protected]>--- drivers/gpu/drm/virtio/virtgpu_drv.h | 17 ++++++ drivers/gpu/drm/virtio/virtgpu_gem.c | 83 ++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+)drivers/gpu/drm/virtio/virtgpu_drv.h +17
-0@@ -84,6 +84,12 @@ struct virtio_gpu_object {#define gem_to_virtio_gpu_obj (gobj) \ container_of((gobj), struct virtio_gpu_object, gem_base) +struct virtio_gpu_object_array { +struct ww_acquire_ctx ticket; +u32 nents, total; +struct drm_gem_object *objs[]; +}; +struct virtio_gpu_vbuffer ;struct virtio_gpu_device ;@@ -251,6 +257,17 @@ int virtio_gpu_mode_dumb_mmap(struct drm_file *file_priv,struct drm_device *dev, uint32_t handle, uint64_t *offset_p); +struct virtio_gpu_object_array *virtio_gpu_array_alloc (u32 nents); +struct virtio_gpu_object_array * +virtio_gpu_array_from_handles (struct drm_file *drm_file,u32 *handles,u32 nents); +void virtio_gpu_array_add_obj (struct virtio_gpu_object_array *objs, +struct drm_gem_object *obj); +int virtio_gpu_array_lock_resv (struct virtio_gpu_object_array *objs); +void virtio_gpu_array_unlock_resv (struct virtio_gpu_object_array *objs); +void virtio_gpu_array_add_fence (struct virtio_gpu_object_array *objs, +struct dma_fence *fence); +void virtio_gpu_array_put_free (struct virtio_gpu_object_array *objs); +/* virtio vg */ int virtio_gpu_alloc_vbufs (struct virtio_gpu_device *vgdev);void virtio_gpu_free_vbufs (struct virtio_gpu_device *vgdev);drivers/gpu/drm/virtio/virtgpu_gem.c +22
-0@@ -169,3 +169,86 @@ void virtio_gpu_gem_object_close(struct drm_gem_object *obj, qobj->hw_res_handle);virtio_gpu_object_unreserve (qobj); } + +struct virtio_gpu_object_array *virtio_gpu_array_alloc (u32 nents) +{ +struct virtio_gpu_object_array *objs; +size_t size =sizeof (*objs) +sizeof (objs->objs[0 ]) * nents; + + objs =kmalloc (size,GFP_KERNEL ); +if (!objs) +return NULL ; + + objs->nents =0 ; + objs->total = nents; +return objs; +} + +static void virtio_gpu_array_free (struct virtio_gpu_object_array *objs) +{ +kfree (objs); +} + +struct virtio_gpu_object_array * +virtio_gpu_array_from_handles (struct drm_file *drm_file,u32 *handles,u32 nents)
drivers/gpu/drm/virtio/virtgpu_gem.c void virtio_gpu_gem_object_close(struct drm_gem_object *obj, · line 203
Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_gem.c +10
-0+{ +struct virtio_gpu_object_array *objs; +u32 i; + + objs =virtio_gpu_array_alloc (nents); +if (!objs) +return NULL ; + +for (i =0 ; i < nents; i++) { + objs->nents = i;
This line can be moved into the if-block just below.
Quoted 54 lines
drivers/gpu/drm/virtio/virtgpu_gem.c +51
-1+ objs->objs[i] =drm_gem_object_lookup (drm_file, handles[i]); +if (!objs->objs[i]) { +virtio_gpu_array_put_free (objs); +return NULL ; + } + } + objs->nents = i; +return objs; +} + +void virtio_gpu_array_add_obj (struct virtio_gpu_object_array *objs, +struct drm_gem_object *obj) +{ +if (WARN_ON_ONCE (objs->nents == objs->total)) +return ; + +drm_gem_object_get (obj); + objs->objs[objs->nents] = obj; + objs->nents++; +} + +int virtio_gpu_array_lock_resv (struct virtio_gpu_object_array *objs) +{ +return drm_gem_lock_reservations (objs->objs, objs->nents, + &objs->ticket); +} + +void virtio_gpu_array_unlock_resv (struct virtio_gpu_object_array *objs) +{ +drm_gem_unlock_reservations (objs->objs, objs->nents, + &objs->ticket); +} + +void virtio_gpu_array_add_fence (struct virtio_gpu_object_array *objs, +struct dma_fence *fence) +{ +int i; + +for (i =0 ; i < objs->nents; i++) +reservation_object_add_excl_fence (objs->objs[i]->resv, + fence); +} + +void virtio_gpu_array_put_free (struct virtio_gpu_object_array *objs) +{ +u32 i; + +for (i =0 ; i < objs->nents; i++) +drm_gem_object_put_unlocked (objs->objs[i]); +virtio_gpu_array_free (objs); +} --2.18.1
Chia-I Wu
reviewerRe: [PATCH v6 07/18] drm/virtio: add virtio_gpu_object_array & helpers
Quoted 111 lines · Chia-I Wu
Quoted 81 lines · Gerd Hoffmann
Some helper functions to manage an array of gem objects.
v6:
- add ticket to structvirtio_gpu_object_array.
- add virtio_gpu_array_{lock,unlock}_resv helpers.
- addvirtio_gpu_array_add_fencehelper.
v5: some small optimizations (Chia-I Wu).
v4: make them virtio-private instead of generic helpers.Signed-off-by Gerd Hoffmann <[email protected]>--- drivers/gpu/drm/virtio/virtgpu_drv.h | 17 ++++++ drivers/gpu/drm/virtio/virtgpu_gem.c | 83 ++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+)drivers/gpu/drm/virtio/virtgpu_drv.h +17
-0@@ -84,6 +84,12 @@ struct virtio_gpu_object {#define gem_to_virtio_gpu_obj (gobj) \ container_of((gobj), struct virtio_gpu_object, gem_base) +struct virtio_gpu_object_array { +struct ww_acquire_ctx ticket; +u32 nents, total; +struct drm_gem_object *objs[]; +}; +struct virtio_gpu_vbuffer ;struct virtio_gpu_device ;@@ -251,6 +257,17 @@ int virtio_gpu_mode_dumb_mmap(struct drm_file *file_priv,struct drm_device *dev, uint32_t handle, uint64_t *offset_p); +struct virtio_gpu_object_array *virtio_gpu_array_alloc (u32 nents); +struct virtio_gpu_object_array * +virtio_gpu_array_from_handles (struct drm_file *drm_file,u32 *handles,u32 nents); +void virtio_gpu_array_add_obj (struct virtio_gpu_object_array *objs, +struct drm_gem_object *obj); +int virtio_gpu_array_lock_resv (struct virtio_gpu_object_array *objs); +void virtio_gpu_array_unlock_resv (struct virtio_gpu_object_array *objs); +void virtio_gpu_array_add_fence (struct virtio_gpu_object_array *objs, +struct dma_fence *fence); +void virtio_gpu_array_put_free (struct virtio_gpu_object_array *objs); +/* virtio vg */ int virtio_gpu_alloc_vbufs (struct virtio_gpu_device *vgdev);void virtio_gpu_free_vbufs (struct virtio_gpu_device *vgdev);drivers/gpu/drm/virtio/virtgpu_gem.c +22
-0@@ -169,3 +169,86 @@ void virtio_gpu_gem_object_close(struct drm_gem_object *obj, qobj->hw_res_handle);virtio_gpu_object_unreserve (qobj); } + +struct virtio_gpu_object_array *virtio_gpu_array_alloc (u32 nents) +{ +struct virtio_gpu_object_array *objs; +size_t size =sizeof (*objs) +sizeof (objs->objs[0 ]) * nents; + + objs =kmalloc (size,GFP_KERNEL ); +if (!objs) +return NULL ; + + objs->nents =0 ; + objs->total = nents; +return objs; +} + +static void virtio_gpu_array_free (struct virtio_gpu_object_array *objs) +{ +kfree (objs); +} + +struct virtio_gpu_object_array * +virtio_gpu_array_from_handles (struct drm_file *drm_file,u32 *handles,u32 nents)drivers/gpu/drm/virtio/virtgpu_gem.c void virtio_gpu_gem_object_close(struct drm_gem_object *obj, · line 203
Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_gem.c +10
-0+{ +struct virtio_gpu_object_array *objs; +u32 i; + + objs =virtio_gpu_array_alloc (nents); +if (!objs) +return NULL ; + +for (i =0 ; i < nents; i++) { + objs->nents = i;This line can be moved into the if-block just below.
Quoted 17 lines
drivers/gpu/drm/virtio/virtgpu_gem.c +17
-0+ objs->objs[i] =drm_gem_object_lookup (drm_file, handles[i]); +if (!objs->objs[i]) { +virtio_gpu_array_put_free (objs); +return NULL ; + } + } + objs->nents = i; +return objs; +} + +void virtio_gpu_array_add_obj (struct virtio_gpu_object_array *objs, +struct drm_gem_object *obj) +{ +if (WARN_ON_ONCE (objs->nents == objs->total)) +return ; + +drm_gem_object_get (obj);
Quoted 8 lines
drivers/gpu/drm/virtio/virtgpu_gem.c void virtio_gpu_gem_object_close(struct drm_gem_object *obj, · line 228
Quoted 8 lines
drivers/gpu/drm/virtio/virtgpu_gem.c +8
-0+ objs->objs[objs->nents] = obj; + objs->nents++; +} + +int virtio_gpu_array_lock_resv (struct virtio_gpu_object_array *objs) +{ +return drm_gem_lock_reservations (objs->objs, objs->nents, + &objs->ticket);
Unlike in other drivers where an "object array" is only needed in execbuffer, we will use this in several places, and often with only 1 object in the array. Can we special case that and do a quick reservation_object_lock?
Quoted 29 lines
Quoted 29 lines
drivers/gpu/drm/virtio/virtgpu_gem.c +26
-1+} + +void virtio_gpu_array_unlock_resv (struct virtio_gpu_object_array *objs) +{ +drm_gem_unlock_reservations (objs->objs, objs->nents, + &objs->ticket); +} + +void virtio_gpu_array_add_fence (struct virtio_gpu_object_array *objs, +struct dma_fence *fence) +{ +int i; + +for (i =0 ; i < objs->nents; i++) +reservation_object_add_excl_fence (objs->objs[i]->resv, + fence); +} + +void virtio_gpu_array_put_free (struct virtio_gpu_object_array *objs) +{ +u32 i; + +for (i =0 ; i < objs->nents; i++) +drm_gem_object_put_unlocked (objs->objs[i]); +virtio_gpu_array_free (objs); +} --2.18.1
Gerd Hoffmann
maintainerRe: [PATCH v6 07/18] drm/virtio: add virtio_gpu_object_array & helpers
Quoted 8 lines
Quoted 4 lines
drivers/gpu/drm/virtio/virtgpu_gem.c void virtio_gpu_gem_object_close(struct drm_gem_object *obj, · line 228
Quoted 4 lines
drivers/gpu/drm/virtio/virtgpu_gem.c +4
-0+int virtio_gpu_array_lock_resv (struct virtio_gpu_object_array *objs) +{ +return drm_gem_lock_reservations (objs->objs, objs->nents, + &objs->ticket);Unlike in other drivers where an "object array" is only needed in execbuffer, we will use this in several places, and often with only 1 object in the array. Can we special case that and do a quick
reservation_object_lock?
Yes, done.
Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/virtio/virtgpu_gem.c void virtio_gpu_gem_object_close(struct drm_gem_object *obj, · line 236
Quoted 6 lines
drivers/gpu/drm/virtio/virtgpu_gem.c +6
-0+void virtio_gpu_array_unlock_resv (struct virtio_gpu_object_array *objs) +{ +drm_gem_unlock_reservations (objs->objs, objs->nents, + &objs->ticket); +} +
Likewise here.
cheers,
Gerd
Gerd Hoffmann
maintainerRe: [PATCH v6 07/18] drm/virtio: add virtio_gpu_object_array & helpers
In reply to Chia-I WuQuoted 8 lines
Quoted 4 lines
drivers/gpu/drm/virtio/virtgpu_gem.c void virtio_gpu_gem_object_close(struct drm_gem_object *obj, · line 228
Quoted 4 lines
drivers/gpu/drm/virtio/virtgpu_gem.c +4
-0+int virtio_gpu_array_lock_resv (struct virtio_gpu_object_array *objs) +{ +return drm_gem_lock_reservations (objs->objs, objs->nents, + &objs->ticket);Unlike in other drivers where an "object array" is only needed in execbuffer, we will use this in several places, and often with only 1 object in the array. Can we special case that and do a quick
reservation_object_lock?
Yes, done.
Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/virtio/virtgpu_gem.c void virtio_gpu_gem_object_close(struct drm_gem_object *obj, · line 236
Quoted 6 lines
drivers/gpu/drm/virtio/virtgpu_gem.c +6
-0+void virtio_gpu_array_unlock_resv (struct virtio_gpu_object_array *objs) +{ +drm_gem_unlock_reservations (objs->objs, objs->nents, + &objs->ticket); +} +
Likewise here.
cheers,
Gerd
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Chia-I Wu
reviewerRe: [PATCH v6 07/18] drm/virtio: add virtio_gpu_object_array & helpers
In reply to Chia-I WuQuoted 111 lines · Chia-I Wu
Quoted 81 lines · Gerd Hoffmann
Some helper functions to manage an array of gem objects.
v6:
- add ticket to structvirtio_gpu_object_array.
- add virtio_gpu_array_{lock,unlock}_resv helpers.
- addvirtio_gpu_array_add_fencehelper.
v5: some small optimizations (Chia-I Wu).
v4: make them virtio-private instead of generic helpers.Signed-off-by Gerd Hoffmann <[email protected]>--- drivers/gpu/drm/virtio/virtgpu_drv.h | 17 ++++++ drivers/gpu/drm/virtio/virtgpu_gem.c | 83 ++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+)drivers/gpu/drm/virtio/virtgpu_drv.h +17
-0@@ -84,6 +84,12 @@ struct virtio_gpu_object {#define gem_to_virtio_gpu_obj (gobj) \ container_of((gobj), struct virtio_gpu_object, gem_base) +struct virtio_gpu_object_array { +struct ww_acquire_ctx ticket; +u32 nents, total; +struct drm_gem_object *objs[]; +}; +struct virtio_gpu_vbuffer ;struct virtio_gpu_device ;@@ -251,6 +257,17 @@ int virtio_gpu_mode_dumb_mmap(struct drm_file *file_priv,struct drm_device *dev, uint32_t handle, uint64_t *offset_p); +struct virtio_gpu_object_array *virtio_gpu_array_alloc (u32 nents); +struct virtio_gpu_object_array * +virtio_gpu_array_from_handles (struct drm_file *drm_file,u32 *handles,u32 nents); +void virtio_gpu_array_add_obj (struct virtio_gpu_object_array *objs, +struct drm_gem_object *obj); +int virtio_gpu_array_lock_resv (struct virtio_gpu_object_array *objs); +void virtio_gpu_array_unlock_resv (struct virtio_gpu_object_array *objs); +void virtio_gpu_array_add_fence (struct virtio_gpu_object_array *objs, +struct dma_fence *fence); +void virtio_gpu_array_put_free (struct virtio_gpu_object_array *objs); +/* virtio vg */ int virtio_gpu_alloc_vbufs (struct virtio_gpu_device *vgdev);void virtio_gpu_free_vbufs (struct virtio_gpu_device *vgdev);drivers/gpu/drm/virtio/virtgpu_gem.c +22
-0@@ -169,3 +169,86 @@ void virtio_gpu_gem_object_close(struct drm_gem_object *obj, qobj->hw_res_handle);virtio_gpu_object_unreserve (qobj); } + +struct virtio_gpu_object_array *virtio_gpu_array_alloc (u32 nents) +{ +struct virtio_gpu_object_array *objs; +size_t size =sizeof (*objs) +sizeof (objs->objs[0 ]) * nents; + + objs =kmalloc (size,GFP_KERNEL ); +if (!objs) +return NULL ; + + objs->nents =0 ; + objs->total = nents; +return objs; +} + +static void virtio_gpu_array_free (struct virtio_gpu_object_array *objs) +{ +kfree (objs); +} + +struct virtio_gpu_object_array * +virtio_gpu_array_from_handles (struct drm_file *drm_file,u32 *handles,u32 nents)drivers/gpu/drm/virtio/virtgpu_gem.c void virtio_gpu_gem_object_close(struct drm_gem_object *obj, · line 203
Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_gem.c +10
-0+{ +struct virtio_gpu_object_array *objs; +u32 i; + + objs =virtio_gpu_array_alloc (nents); +if (!objs) +return NULL ; + +for (i =0 ; i < nents; i++) { + objs->nents = i;This line can be moved into the if-block just below.
Quoted 17 lines
drivers/gpu/drm/virtio/virtgpu_gem.c +17
-0+ objs->objs[i] =drm_gem_object_lookup (drm_file, handles[i]); +if (!objs->objs[i]) { +virtio_gpu_array_put_free (objs); +return NULL ; + } + } + objs->nents = i; +return objs; +} + +void virtio_gpu_array_add_obj (struct virtio_gpu_object_array *objs, +struct drm_gem_object *obj) +{ +if (WARN_ON_ONCE (objs->nents == objs->total)) +return ; + +drm_gem_object_get (obj);
Quoted 8 lines
drivers/gpu/drm/virtio/virtgpu_gem.c void virtio_gpu_gem_object_close(struct drm_gem_object *obj, · line 228
Quoted 8 lines
drivers/gpu/drm/virtio/virtgpu_gem.c +8
-0+ objs->objs[objs->nents] = obj; + objs->nents++; +} + +int virtio_gpu_array_lock_resv (struct virtio_gpu_object_array *objs) +{ +return drm_gem_lock_reservations (objs->objs, objs->nents, + &objs->ticket);
Unlike in other drivers where an "object array" is only needed in execbuffer, we will use this in several places, and often with only 1 object in the array. Can we special case that and do a quick reservation_object_lock?
Quoted 29 lines
Quoted 29 lines
drivers/gpu/drm/virtio/virtgpu_gem.c +26
-1+} + +void virtio_gpu_array_unlock_resv (struct virtio_gpu_object_array *objs) +{ +drm_gem_unlock_reservations (objs->objs, objs->nents, + &objs->ticket); +} + +void virtio_gpu_array_add_fence (struct virtio_gpu_object_array *objs, +struct dma_fence *fence) +{ +int i; + +for (i =0 ; i < objs->nents; i++) +reservation_object_add_excl_fence (objs->objs[i]->resv, + fence); +} + +void virtio_gpu_array_put_free (struct virtio_gpu_object_array *objs) +{ +u32 i; + +for (i =0 ; i < objs->nents; i++) +drm_gem_object_put_unlocked (objs->objs[i]); +virtio_gpu_array_free (objs); +} --2.18.1
Gerd Hoffmann
maintainerRe: [PATCH v6 07/18] drm/virtio: add virtio_gpu_object_array & helpers
In reply to Chia-I WuQuoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ for (i = 0; i < nents; i++) { + objs->nents = i;This line can be moved into the if-block just below.
Quoted 5 lines
drivers/gpu/drm/virtio/virtgpu_gem.c +5
-0+ objs->objs[i] =drm_gem_object_lookup (drm_file, handles[i]); +if (!objs->objs[i]) { +virtio_gpu_array_put_free (objs); +return NULL ; + }
Done.
cheers,
Gerd
Gerd Hoffmann
maintainerRe: [PATCH v6 07/18] drm/virtio: add virtio_gpu_object_array & helpers
In reply to Chia-I WuQuoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ for (i = 0; i < nents; i++) { + objs->nents = i;This line can be moved into the if-block just below.
Quoted 5 lines
drivers/gpu/drm/virtio/virtgpu_gem.c +5
-0+ objs->objs[i] =drm_gem_object_lookup (drm_file, handles[i]); +if (!objs->objs[i]) { +virtio_gpu_array_put_free (objs); +return NULL ; + }
Done.
cheers,
Gerd
Chia-I Wu
reviewerRe: [PATCH v6 07/18] drm/virtio: add virtio_gpu_object_array & helpers
In reply to Gerd HoffmannQuoted 81 lines · Gerd Hoffmann
Some helper functions to manage an array of gem objects.
v6:
- add ticket to structvirtio_gpu_object_array.
- add virtio_gpu_array_{lock,unlock}_resv helpers.
- addvirtio_gpu_array_add_fencehelper.
v5: some small optimizations (Chia-I Wu).
v4: make them virtio-private instead of generic helpers.Signed-off-by Gerd Hoffmann <[email protected]>--- drivers/gpu/drm/virtio/virtgpu_drv.h | 17 ++++++ drivers/gpu/drm/virtio/virtgpu_gem.c | 83 ++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+)drivers/gpu/drm/virtio/virtgpu_drv.h +17
-0@@ -84,6 +84,12 @@ struct virtio_gpu_object {#define gem_to_virtio_gpu_obj (gobj) \ container_of((gobj), struct virtio_gpu_object, gem_base) +struct virtio_gpu_object_array { +struct ww_acquire_ctx ticket; +u32 nents, total; +struct drm_gem_object *objs[]; +}; +struct virtio_gpu_vbuffer ;struct virtio_gpu_device ;@@ -251,6 +257,17 @@ int virtio_gpu_mode_dumb_mmap(struct drm_file *file_priv,struct drm_device *dev, uint32_t handle, uint64_t *offset_p); +struct virtio_gpu_object_array *virtio_gpu_array_alloc (u32 nents); +struct virtio_gpu_object_array * +virtio_gpu_array_from_handles (struct drm_file *drm_file,u32 *handles,u32 nents); +void virtio_gpu_array_add_obj (struct virtio_gpu_object_array *objs, +struct drm_gem_object *obj); +int virtio_gpu_array_lock_resv (struct virtio_gpu_object_array *objs); +void virtio_gpu_array_unlock_resv (struct virtio_gpu_object_array *objs); +void virtio_gpu_array_add_fence (struct virtio_gpu_object_array *objs, +struct dma_fence *fence); +void virtio_gpu_array_put_free (struct virtio_gpu_object_array *objs); +/* virtio vg */ int virtio_gpu_alloc_vbufs (struct virtio_gpu_device *vgdev);void virtio_gpu_free_vbufs (struct virtio_gpu_device *vgdev);drivers/gpu/drm/virtio/virtgpu_gem.c +22
-0@@ -169,3 +169,86 @@ void virtio_gpu_gem_object_close(struct drm_gem_object *obj, qobj->hw_res_handle);virtio_gpu_object_unreserve (qobj); } + +struct virtio_gpu_object_array *virtio_gpu_array_alloc (u32 nents) +{ +struct virtio_gpu_object_array *objs; +size_t size =sizeof (*objs) +sizeof (objs->objs[0 ]) * nents; + + objs =kmalloc (size,GFP_KERNEL ); +if (!objs) +return NULL ; + + objs->nents =0 ; + objs->total = nents; +return objs; +} + +static void virtio_gpu_array_free (struct virtio_gpu_object_array *objs) +{ +kfree (objs); +} + +struct virtio_gpu_object_array * +virtio_gpu_array_from_handles (struct drm_file *drm_file,u32 *handles,u32 nents)
drivers/gpu/drm/virtio/virtgpu_gem.c void virtio_gpu_gem_object_close(struct drm_gem_object *obj, · line 203
Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_gem.c +10
-0+{ +struct virtio_gpu_object_array *objs; +u32 i; + + objs =virtio_gpu_array_alloc (nents); +if (!objs) +return NULL ; + +for (i =0 ; i < nents; i++) { + objs->nents = i;
This line can be moved into the if-block just below.
Quoted 54 lines
drivers/gpu/drm/virtio/virtgpu_gem.c +51
-1+ objs->objs[i] =drm_gem_object_lookup (drm_file, handles[i]); +if (!objs->objs[i]) { +virtio_gpu_array_put_free (objs); +return NULL ; + } + } + objs->nents = i; +return objs; +} + +void virtio_gpu_array_add_obj (struct virtio_gpu_object_array *objs, +struct drm_gem_object *obj) +{ +if (WARN_ON_ONCE (objs->nents == objs->total)) +return ; + +drm_gem_object_get (obj); + objs->objs[objs->nents] = obj; + objs->nents++; +} + +int virtio_gpu_array_lock_resv (struct virtio_gpu_object_array *objs) +{ +return drm_gem_lock_reservations (objs->objs, objs->nents, + &objs->ticket); +} + +void virtio_gpu_array_unlock_resv (struct virtio_gpu_object_array *objs) +{ +drm_gem_unlock_reservations (objs->objs, objs->nents, + &objs->ticket); +} + +void virtio_gpu_array_add_fence (struct virtio_gpu_object_array *objs, +struct dma_fence *fence) +{ +int i; + +for (i =0 ; i < objs->nents; i++) +reservation_object_add_excl_fence (objs->objs[i]->resv, + fence); +} + +void virtio_gpu_array_put_free (struct virtio_gpu_object_array *objs) +{ +u32 i; + +for (i =0 ; i < objs->nents; i++) +drm_gem_object_put_unlocked (objs->objs[i]); +virtio_gpu_array_free (objs); +} --2.18.1
Gerd Hoffmann
maintainerPATCH v6 8/18 drm/virtio: rework virtio_gpu_execbuffer_ioctl fencing
In reply to Gerd HoffmannRework fencing workflow, starting with virtio_gpu_execbuffer_ioctl. Stop using ttm helpers, use the virtio_gpu_array_* helpers (which work on the reservation objects directly) instead.
New workflow:
(1) All gem objects needed by a command are added to a virtio_gpu_object_array.
(2) All reservation objects will be locked (virtio_gpu_array_lock_resv).
(3) virtio_gpu_fence_emit() completes fence initialization.
(4) fence gets added to the objects, reservation objects are unlocked (virtio_gpu_array_add_fence, virtio_gpu_array_unlock_resv).
(5) virtio command is submitted to the host.
(6) The completion callback (virtio_gpu_dequeue_ctrl_func) will drop object references and free virtio_gpu_object_array.
v6: rewrite most of the patch.
--- drivers/gpu/drm/virtio/virtgpu_drv.h | 6 ++- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 56 +++++++++----------------- drivers/gpu/drm/virtio/virtgpu_vq.c | 21 +++++++--- 3 files changed, 38 insertions(+), 45 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.h +4 -2
@@ -121,9 +121,9 @@ struct virtio_gpu_vbuffer {char *resp_buf;int resp_size; -virtio_gpu_resp_cb resp_cb; +struct virtio_gpu_object_array *objs;struct list_head list; };
@@ -318,7 +318,9 @@ void virtio_gpu_cmd_context_detach_resource(struct virtio_gpu_device *vgdev, uint32_t resource_id);void virtio_gpu_cmd_submit (struct virtio_gpu_device *vgdev,void *data,uint32_t data_size, -uint32_t ctx_id,struct virtio_gpu_fence *fence); +uint32_t ctx_id, +struct virtio_gpu_object_array *objs, +struct virtio_gpu_fence *fence); void virtio_gpu_cmd_transfer_from_host_3d(struct virtio_gpu_device *vgdev, uint32_t resource_id, uint32_t ctx_id, uint64_t offset, uint32_t level,
drivers/gpu/drm/virtio/virtgpu_ioctl.c +18 -38
98 lines not on this page · raw message
drivers/gpu/drm/virtio/virtgpu_vq.c +16 -5
@@ -191,7 +191,7 @@ void virtio_gpu_dequeue_ctrl_func(struct work_struct *work) }while (!virtqueue_enable_cb (vgdev->ctrlq.vq));spin_unlock (&vgdev->ctrlq.qlock); -list_for_each_entry_safe (entry, tmp, &reclaim_list, list) { +list_for_each_entry (entry, &reclaim_list, list) { resp = (struct virtio_gpu_ctrl_hdr *)entry->resp_buf;trace_virtio_gpu_cmd_response (vgdev->ctrlq.vq, resp);
@@ -218,14 +218,18 @@ void virtio_gpu_dequeue_ctrl_func(struct work_struct *work) }if (entry->resp_cb) entry->resp_cb (vgdev, entry); - -list_del (&entry->list); -free_vbuf (vgdev, entry); }wake_up (&vgdev->ctrlq.ack_queue);if (fence_id)virtio_gpu_fence_event_process (vgdev, fence_id); + +list_for_each_entry_safe (entry, tmp, &reclaim_list, list) { +if (entry->objs) +virtio_gpu_array_put_free (entry->objs); +list_del (&entry->list); +free_vbuf (vgdev, entry); + } }void virtio_gpu_dequeue_cursor_func (struct work_struct *work)
@@ -337,6 +341,10 @@ static int virtio_gpu_queue_fenced_ctrl_buffer(struct virtio_gpu_device *vgdev,if (fence)virtio_gpu_fence_emit (vgdev, hdr, fence); +if (vbuf->objs) { +virtio_gpu_array_add_fence (vbuf->objs, &fence->f); +virtio_gpu_array_unlock_resv (vbuf->objs); + } rc =virtio_gpu_queue_ctrl_buffer_locked (vgdev, vbuf);spin_unlock (&vgdev->ctrlq.qlock);return rc;
@@ -939,7 +947,9 @@ void virtio_gpu_cmd_transfer_from_host_3d(struct virtio_gpu_device *vgdev,void virtio_gpu_cmd_submit (struct virtio_gpu_device *vgdev,void *data,uint32_t data_size, -uint32_t ctx_id,struct virtio_gpu_fence *fence) +uint32_t ctx_id, +struct virtio_gpu_object_array *objs, +struct virtio_gpu_fence *fence) {struct virtio_gpu_cmd_submit *cmd_p;struct virtio_gpu_vbuffer *vbuf;
@@ -949,6 +959,7 @@ void virtio_gpu_cmd_submit(struct virtio_gpu_device *vgdev, vbuf->data_buf = data; vbuf->data_size = data_size; + vbuf->objs = objs; cmd_p->hdr.type =cpu_to_le32 (VIRTIO_GPU_CMD_SUBMIT_3D ); cmd_p->hdr.ctx_id =cpu_to_le32 (ctx_id);
Signature · 1 line
2.18.1
Gerd Hoffmann
maintainerPATCH v6 8/18 drm/virtio: rework virtio_gpu_execbuffer_ioctl fencing
In reply to Gerd HoffmannRework fencing workflow, starting with virtio_gpu_execbuffer_ioctl. Stop using ttm helpers, use the virtio_gpu_array_* helpers (which work on the reservation objects directly) instead.
New workflow:
(1) All gem objects needed by a command are added to a virtio_gpu_object_array.
(2) All reservation objects will be locked (virtio_gpu_array_lock_resv).
(3) virtio_gpu_fence_emit() completes fence initialization.
(4) fence gets added to the objects, reservation objects are unlocked (virtio_gpu_array_add_fence, virtio_gpu_array_unlock_resv).
(5) virtio command is submitted to the host.
(6) The completion callback (virtio_gpu_dequeue_ctrl_func) will drop object references and free virtio_gpu_object_array.
v6: rewrite most of the patch.
--- drivers/gpu/drm/virtio/virtgpu_drv.h | 6 ++- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 56 +++++++++----------------- drivers/gpu/drm/virtio/virtgpu_vq.c | 21 +++++++--- 3 files changed, 38 insertions(+), 45 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.h +4 -2
@@ -121,9 +121,9 @@ struct virtio_gpu_vbuffer {char *resp_buf;int resp_size; -virtio_gpu_resp_cb resp_cb; +struct virtio_gpu_object_array *objs;struct list_head list; };
@@ -318,7 +318,9 @@ void virtio_gpu_cmd_context_detach_resource(struct virtio_gpu_device *vgdev, uint32_t resource_id);void virtio_gpu_cmd_submit (struct virtio_gpu_device *vgdev,void *data,uint32_t data_size, -uint32_t ctx_id,struct virtio_gpu_fence *fence); +uint32_t ctx_id, +struct virtio_gpu_object_array *objs, +struct virtio_gpu_fence *fence); void virtio_gpu_cmd_transfer_from_host_3d(struct virtio_gpu_device *vgdev, uint32_t resource_id, uint32_t ctx_id, uint64_t offset, uint32_t level,
drivers/gpu/drm/virtio/virtgpu_ioctl.c +18 -38
98 lines not on this page · raw message
drivers/gpu/drm/virtio/virtgpu_vq.c +16 -5
@@ -191,7 +191,7 @@ void virtio_gpu_dequeue_ctrl_func(struct work_struct *work) }while (!virtqueue_enable_cb (vgdev->ctrlq.vq));spin_unlock (&vgdev->ctrlq.qlock); -list_for_each_entry_safe (entry, tmp, &reclaim_list, list) { +list_for_each_entry (entry, &reclaim_list, list) { resp = (struct virtio_gpu_ctrl_hdr *)entry->resp_buf;trace_virtio_gpu_cmd_response (vgdev->ctrlq.vq, resp);
@@ -218,14 +218,18 @@ void virtio_gpu_dequeue_ctrl_func(struct work_struct *work) }if (entry->resp_cb) entry->resp_cb (vgdev, entry); - -list_del (&entry->list); -free_vbuf (vgdev, entry); }wake_up (&vgdev->ctrlq.ack_queue);if (fence_id)virtio_gpu_fence_event_process (vgdev, fence_id); + +list_for_each_entry_safe (entry, tmp, &reclaim_list, list) { +if (entry->objs) +virtio_gpu_array_put_free (entry->objs); +list_del (&entry->list); +free_vbuf (vgdev, entry); + } }void virtio_gpu_dequeue_cursor_func (struct work_struct *work)
@@ -337,6 +341,10 @@ static int virtio_gpu_queue_fenced_ctrl_buffer(struct virtio_gpu_device *vgdev,if (fence)virtio_gpu_fence_emit (vgdev, hdr, fence); +if (vbuf->objs) { +virtio_gpu_array_add_fence (vbuf->objs, &fence->f); +virtio_gpu_array_unlock_resv (vbuf->objs); + } rc =virtio_gpu_queue_ctrl_buffer_locked (vgdev, vbuf);spin_unlock (&vgdev->ctrlq.qlock);return rc;
@@ -939,7 +947,9 @@ void virtio_gpu_cmd_transfer_from_host_3d(struct virtio_gpu_device *vgdev,void virtio_gpu_cmd_submit (struct virtio_gpu_device *vgdev,void *data,uint32_t data_size, -uint32_t ctx_id,struct virtio_gpu_fence *fence) +uint32_t ctx_id, +struct virtio_gpu_object_array *objs, +struct virtio_gpu_fence *fence) {struct virtio_gpu_cmd_submit *cmd_p;struct virtio_gpu_vbuffer *vbuf;
@@ -949,6 +959,7 @@ void virtio_gpu_cmd_submit(struct virtio_gpu_device *vgdev, vbuf->data_buf = data; vbuf->data_size = data_size; + vbuf->objs = objs; cmd_p->hdr.type =cpu_to_le32 (VIRTIO_GPU_CMD_SUBMIT_3D ); cmd_p->hdr.ctx_id =cpu_to_le32 (ctx_id);
Signature · 6 lines
2.18.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Chia-I Wu
reviewerRe: [PATCH v6 08/18] drm/virtio: rework virtio_gpu_execbuffer_ioctl fencing
Quoted 194 lines · Gerd Hoffmann
Rework fencing workflow, starting with
virtio_gpu_execbuffer_ioctl. Stop using ttm helpers, use the virtio_gpu_array_* helpers (which work on the reservation objects directly) instead.New workflow:
(1) All gem objects needed by a command are added to a
virtio_gpu_object_array.
(2) All reservation objects will be locked (virtio_gpu_array_lock_resv).
(3)virtio_gpu_fence_emit()completes fence initialization.
(4) fence gets added to the objects, reservation objects are unlocked (virtio_gpu_array_add_fence,virtio_gpu_array_unlock_resv).
(5) virtio command is submitted to the host.
(6) The completion callback (virtio_gpu_dequeue_ctrl_func) will drop object references and freevirtio_gpu_object_array.v6: rewrite most of the patch.
Signed-off-by Gerd Hoffmann <[email protected]>--- drivers/gpu/drm/virtio/virtgpu_drv.h | 6 ++- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 56 +++++++++----------------- drivers/gpu/drm/virtio/virtgpu_vq.c | 21 +++++++--- 3 files changed, 38 insertions(+), 45 deletions(-)drivers/gpu/drm/virtio/virtgpu_drv.h +4
-2@@ -121,9 +121,9 @@ struct virtio_gpu_vbuffer {char *resp_buf;int resp_size; -virtio_gpu_resp_cb resp_cb; +struct virtio_gpu_object_array *objs;struct list_head list; };@@ -318,7 +318,9 @@ void virtio_gpu_cmd_context_detach_resource(struct virtio_gpu_device *vgdev, uint32_t resource_id);void virtio_gpu_cmd_submit (struct virtio_gpu_device *vgdev,void *data,uint32_t data_size, -uint32_t ctx_id,struct virtio_gpu_fence *fence); +uint32_t ctx_id, +struct virtio_gpu_object_array *objs, +struct virtio_gpu_fence *fence); void virtio_gpu_cmd_transfer_from_host_3d(struct virtio_gpu_device *vgdev, uint32_t resource_id, uint32_t ctx_id, uint64_t offset, uint32_t level,drivers/gpu/drm/virtio/virtgpu_ioctl.c +18
-38@@ -105,16 +105,11 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,struct drm_virtgpu_execbuffer *exbuf = data;struct virtio_gpu_device *vgdev = dev->dev_private;struct virtio_gpu_fpriv *vfpriv = drm_file->driver_priv; -struct drm_gem_object *gobj;struct virtio_gpu_fence *out_fence; -struct virtio_gpu_object *qobj;int ret;uint32_t *bo_handles =NULL ;void __user *user_bo_handles =NULL ; -struct list_head validate_list; -struct ttm_validate_buffer *buflist =NULL ; -int i; -struct ww_acquire_ctx ticket; +struct virtio_gpu_object_array *buflist =NULL ;struct sync_file *sync_file;int in_fence_fd = exbuf->fence_fd;int out_fence_fd =-1 ;@@ -155,15 +150,10 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,return out_fence_fd; } -INIT_LIST_HEAD (&validate_list);if (exbuf->num_bo_handles) { - bo_handles =kvmalloc_array (exbuf->num_bo_handles, -sizeof (uint32_t ),GFP_KERNEL ); - buflist =kvmalloc_array (exbuf->num_bo_handles, -sizeof (struct ttm_validate_buffer ), -GFP_KERNEL | __GFP_ZERO); -if (!bo_handles || !buflist) { +sizeof (uint32_t ),GFP_KERNEL ); +if (!bo_handles) { ret = -ENOMEM ; goto out_unused_fd; }@@ -175,25 +165,21 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data, goto out_unused_fd; } -for (i =0 ; i < exbuf->num_bo_handles; i++) { - gobj =drm_gem_object_lookup (drm_file, bo_handles[i]); -if (!gobj) { - ret = -ENOENT ; - goto out_unused_fd; - } - - qobj =gem_to_virtio_gpu_obj (gobj); - buflist[i].bo = &qobj->tbo; - -list_add (&buflist[i].head, &validate_list); + buflist =virtio_gpu_array_from_handles (drm_file, bo_handles, + exbuf->num_bo_handles); +if (!buflist) { + ret = -ENOENT ; + goto out_unused_fd; }kvfree (bo_handles); bo_handles =NULL ; } - ret =virtio_gpu_object_list_validate (&ticket, &validate_list); -if (ret) - goto out_free; +if (buflist) { + ret =virtio_gpu_array_lock_resv (buflist); +if (ret) + goto out_unused_fd; + } buf =memdup_user (u64_to_user_ptr (exbuf->command), exbuf->size);if (IS_ERR (buf)) {@@ -220,24 +206,18 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data, }virtio_gpu_cmd_submit (vgdev, buf, exbuf->size, - vfpriv->ctx_id, out_fence); - -ttm_eu_fence_buffer_objects (&ticket, &validate_list, &out_fence->f); - -/* fence the command bo */ -virtio_gpu_unref_list (&validate_list); -kvfree (buflist); + vfpriv->ctx_id, buflist, out_fence);return 0 ; out_memdup:kfree (buf); out_unresv: -ttm_eu_backoff_reservation (&ticket, &validate_list); -out_free: -virtio_gpu_unref_list (&validate_list); +if (buflist) +virtio_gpu_array_unlock_resv (buflist); out_unused_fd:kvfree (bo_handles); -kvfree (buflist); +if (buflist) +virtio_gpu_array_put_free (buflist);if (out_fence_fd >=0 )put_unused_fd (out_fence_fd);drivers/gpu/drm/virtio/virtgpu_vq.c +8
-4@@ -191,7 +191,7 @@ void virtio_gpu_dequeue_ctrl_func(struct work_struct *work) }while (!virtqueue_enable_cb (vgdev->ctrlq.vq));spin_unlock (&vgdev->ctrlq.qlock); -list_for_each_entry_safe (entry, tmp, &reclaim_list, list) { +list_for_each_entry (entry, &reclaim_list, list) { resp = (struct virtio_gpu_ctrl_hdr *)entry->resp_buf;trace_virtio_gpu_cmd_response (vgdev->ctrlq.vq, resp);@@ -218,14 +218,18 @@ void virtio_gpu_dequeue_ctrl_func(struct work_struct *work) }if (entry->resp_cb) entry->resp_cb (vgdev, entry); - -list_del (&entry->list); -free_vbuf (vgdev, entry); }wake_up (&vgdev->ctrlq.ack_queue);if (fence_id)virtio_gpu_fence_event_process (vgdev, fence_id); + +list_for_each_entry_safe (entry, tmp, &reclaim_list, list) { +if (entry->objs) +virtio_gpu_array_put_free (entry->objs); +list_del (&entry->list); +free_vbuf (vgdev, entry); + } }void virtio_gpu_dequeue_cursor_func (struct work_struct *work)
drivers/gpu/drm/virtio/virtgpu_vq.c static int virtio_gpu_queue_fenced_ctrl_buffer(struct virtio_gpu_device *vgdev, · line 347
Quoted 7 lines
drivers/gpu/drm/virtio/virtgpu_vq.c +4
-0@@ -337,6 +341,10 @@ static int virtio_gpu_queue_fenced_ctrl_buffer(struct virtio_gpu_device *vgdev,if (fence)virtio_gpu_fence_emit (vgdev, hdr, fence); +if (vbuf->objs) { +virtio_gpu_array_add_fence (vbuf->objs, &fence->f); +virtio_gpu_array_unlock_resv (vbuf->objs); + }
This is with the spinlock held. Maybe we should move the virtio_gpu_array_unlock_resv call out of the critical section.
I am actually more concerned about virtio_gpu_array_add_fence, but it is also harder to move. Should we add a kref to the object array?
This bothers me because I recently ran into a CPU-bound game with very bad lock contention here.
Quoted 25 lines
drivers/gpu/drm/virtio/virtgpu_vq.c +4
-2rc =virtio_gpu_queue_ctrl_buffer_locked (vgdev, vbuf);spin_unlock (&vgdev->ctrlq.qlock);return rc;@@ -939,7 +947,9 @@ void virtio_gpu_cmd_transfer_from_host_3d(struct virtio_gpu_device *vgdev,void virtio_gpu_cmd_submit (struct virtio_gpu_device *vgdev,void *data,uint32_t data_size, -uint32_t ctx_id,struct virtio_gpu_fence *fence) +uint32_t ctx_id, +struct virtio_gpu_object_array *objs, +struct virtio_gpu_fence *fence) {struct virtio_gpu_cmd_submit *cmd_p;struct virtio_gpu_vbuffer *vbuf;@@ -949,6 +959,7 @@ void virtio_gpu_cmd_submit(struct virtio_gpu_device *vgdev, vbuf->data_buf = data; vbuf->data_size = data_size; + vbuf->objs = objs; cmd_p->hdr.type =cpu_to_le32 (VIRTIO_GPU_CMD_SUBMIT_3D ); cmd_p->hdr.ctx_id =cpu_to_le32 (ctx_id); --2.18.1
Gerd Hoffmann
maintainerRe: [PATCH v6 08/18] drm/virtio: rework virtio_gpu_execbuffer_ioctl fencing
Hi,
Quoted 8 lines
drivers/gpu/drm/virtio/virtgpu_vq.c static int virtio_gpu_queue_fenced_ctrl_buffer(struct virtio_gpu_device *vgdev, · line 347
Quoted 6 lines
if (fence) virtio_gpu_fence_emit(vgdev, hdr, fence);drivers/gpu/drm/virtio/virtgpu_vq.c +4
-0+if (vbuf->objs) { +virtio_gpu_array_add_fence (vbuf->objs, &fence->f); +virtio_gpu_array_unlock_resv (vbuf->objs); + }This is with the spinlock held. Maybe we should move the
virtio_gpu_array_unlock_resvcall out of the critical section.
That would bring back the race ...
Quoted 2 lines
I am actually more concerned about
virtio_gpu_array_add_fence, but it is also harder to move. Should we add a kref to the object array?
Yep, refcounting would be the other way to fix the race.
Quoted 2 lines
This bothers me because I recently ran into a CPU-bound game with very bad lock contention here.
Hmm. Any clue where this comes from? Multiple threads competing for virtio buffers I guess? Maybe we should have larger virtqueues?
cheers,
Gerd
Chia-I Wu
reviewerRe: [PATCH v6 08/18] drm/virtio: rework virtio_gpu_execbuffer_ioctl fencing
Quoted 9 lines · Gerd Hoffmann
Hi,
Quoted 6 lines
Quoted 6 lines
if (fence) virtio_gpu_fence_emit(vgdev, hdr, fence);drivers/gpu/drm/virtio/virtgpu_vq.c +4
-0+if (vbuf->objs) { +virtio_gpu_array_add_fence (vbuf->objs, &fence->f); +virtio_gpu_array_unlock_resv (vbuf->objs); + }
Quoted 4 lines
Quoted 2 lines
This is with the spinlock held. Maybe we should move the
virtio_gpu_array_unlock_resvcall out of the critical section.That would bring back the race ...
Right...
Quoted 11 lines
Quoted 3 lines
I am actually more concerned about
virtio_gpu_array_add_fence, but it is also harder to move. Should we add a kref to the object array?Yep, refcounting would be the other way to fix the race.
Quoted 2 lines
This bothers me because I recently ran into a CPU-bound game with very bad lock contention here.
Hmm. Any clue where this comes from? Multiple threads competing for virtio buffers I guess? Maybe we should have larger virtqueues?
The game was single-threaded. I guess it was the game and Xorg competing for virtio buffers. That was also on an older kernel without explicit fences. The userspace had to create dummy resources frequently to do VIRTIO_IOCTL_RESOURCE_WAIT.
I think this is fine for now as far as I am concerned. I can look into this more closely after this series lands.
Quoted 4 lines
cheers,
Gerd
Chia-I Wu
reviewerRe: [PATCH v6 08/18] drm/virtio: rework virtio_gpu_execbuffer_ioctl fencing
Quoted 27 lines · Chia-I Wu
Quoted 9 lines · Gerd Hoffmann
Hi,
Quoted 6 lines
Quoted 6 lines
if (fence) virtio_gpu_fence_emit(vgdev, hdr, fence);drivers/gpu/drm/virtio/virtgpu_vq.c +4
-0+if (vbuf->objs) { +virtio_gpu_array_add_fence (vbuf->objs, &fence->f); +virtio_gpu_array_unlock_resv (vbuf->objs); + }Quoted 4 lines
Quoted 2 lines
This is with the spinlock held. Maybe we should move the
virtio_gpu_array_unlock_resvcall out of the critical section.That would bring back the race ...
Right...
Quoted 11 lines
Quoted 3 lines
I am actually more concerned about
virtio_gpu_array_add_fence, but it is also harder to move. Should we add a kref to the object array?Yep, refcounting would be the other way to fix the race.
Quoted 2 lines
This bothers me because I recently ran into a CPU-bound game with very bad lock contention here.
Hmm. Any clue where this comes from? Multiple threads competing for virtio buffers I guess? Maybe we should have larger virtqueues?
Quoted 7 lines
The game was single-threaded. I guess it was the game and Xorg competing for virtio buffers. That was also on an older kernel without explicit fences. The userspace had to create dummy resources frequently to do
VIRTIO_IOCTL_RESOURCE_WAIT.I think this is fine for now as far as I am concerned. I can look into this more closely after this series lands.
It was virtio_gpu_dequeue_ctrl_func who wanted to grab the lock to handle the responses. I sent a patch for it
https://patchwork.freedesktop.org/series/63529/
Quoted 6 lines
Quoted 6 lines
cheers,
Gerd
Chia-I Wu
reviewerRe: [PATCH v6 08/18] drm/virtio: rework virtio_gpu_execbuffer_ioctl fencing
In reply to Chia-I WuQuoted 27 lines · Chia-I Wu
Quoted 9 lines · Gerd Hoffmann
Hi,
Quoted 6 lines
Quoted 6 lines
if (fence) virtio_gpu_fence_emit(vgdev, hdr, fence);drivers/gpu/drm/virtio/virtgpu_vq.c +4
-0+if (vbuf->objs) { +virtio_gpu_array_add_fence (vbuf->objs, &fence->f); +virtio_gpu_array_unlock_resv (vbuf->objs); + }Quoted 4 lines
Quoted 2 lines
This is with the spinlock held. Maybe we should move the
virtio_gpu_array_unlock_resvcall out of the critical section.That would bring back the race ...
Right...
Quoted 11 lines
Quoted 3 lines
I am actually more concerned about
virtio_gpu_array_add_fence, but it is also harder to move. Should we add a kref to the object array?Yep, refcounting would be the other way to fix the race.
Quoted 2 lines
This bothers me because I recently ran into a CPU-bound game with very bad lock contention here.
Hmm. Any clue where this comes from? Multiple threads competing for virtio buffers I guess? Maybe we should have larger virtqueues?
Quoted 7 lines
The game was single-threaded. I guess it was the game and Xorg competing for virtio buffers. That was also on an older kernel without explicit fences. The userspace had to create dummy resources frequently to do
VIRTIO_IOCTL_RESOURCE_WAIT.I think this is fine for now as far as I am concerned. I can look into this more closely after this series lands.
It was virtio_gpu_dequeue_ctrl_func who wanted to grab the lock to handle the responses. I sent a patch for it
https://patchwork.freedesktop.org/series/63529/
Quoted 6 lines
Quoted 6 lines
cheers,
Gerd
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Gerd Hoffmann
maintainerRe: [PATCH v6 08/18] drm/virtio: rework virtio_gpu_execbuffer_ioctl fencing
In reply to Chia-I WuHi,
Quoted 8 lines
drivers/gpu/drm/virtio/virtgpu_vq.c static int virtio_gpu_queue_fenced_ctrl_buffer(struct virtio_gpu_device *vgdev, · line 347
Quoted 6 lines
if (fence) virtio_gpu_fence_emit(vgdev, hdr, fence);drivers/gpu/drm/virtio/virtgpu_vq.c +4
-0+if (vbuf->objs) { +virtio_gpu_array_add_fence (vbuf->objs, &fence->f); +virtio_gpu_array_unlock_resv (vbuf->objs); + }This is with the spinlock held. Maybe we should move the
virtio_gpu_array_unlock_resvcall out of the critical section.
That would bring back the race ...
Quoted 2 lines
I am actually more concerned about
virtio_gpu_array_add_fence, but it is also harder to move. Should we add a kref to the object array?
Yep, refcounting would be the other way to fix the race.
Quoted 2 lines
This bothers me because I recently ran into a CPU-bound game with very bad lock contention here.
Hmm. Any clue where this comes from? Multiple threads competing for virtio buffers I guess? Maybe we should have larger virtqueues?
cheers,
Gerd
Chia-I Wu
reviewerRe: [PATCH v6 08/18] drm/virtio: rework virtio_gpu_execbuffer_ioctl fencing
In reply to Gerd HoffmannQuoted 194 lines · Gerd Hoffmann
Rework fencing workflow, starting with
virtio_gpu_execbuffer_ioctl. Stop using ttm helpers, use the virtio_gpu_array_* helpers (which work on the reservation objects directly) instead.New workflow:
(1) All gem objects needed by a command are added to a
virtio_gpu_object_array.
(2) All reservation objects will be locked (virtio_gpu_array_lock_resv).
(3)virtio_gpu_fence_emit()completes fence initialization.
(4) fence gets added to the objects, reservation objects are unlocked (virtio_gpu_array_add_fence,virtio_gpu_array_unlock_resv).
(5) virtio command is submitted to the host.
(6) The completion callback (virtio_gpu_dequeue_ctrl_func) will drop object references and freevirtio_gpu_object_array.v6: rewrite most of the patch.
Signed-off-by Gerd Hoffmann <[email protected]>--- drivers/gpu/drm/virtio/virtgpu_drv.h | 6 ++- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 56 +++++++++----------------- drivers/gpu/drm/virtio/virtgpu_vq.c | 21 +++++++--- 3 files changed, 38 insertions(+), 45 deletions(-)drivers/gpu/drm/virtio/virtgpu_drv.h +4
-2@@ -121,9 +121,9 @@ struct virtio_gpu_vbuffer {char *resp_buf;int resp_size; -virtio_gpu_resp_cb resp_cb; +struct virtio_gpu_object_array *objs;struct list_head list; };@@ -318,7 +318,9 @@ void virtio_gpu_cmd_context_detach_resource(struct virtio_gpu_device *vgdev, uint32_t resource_id);void virtio_gpu_cmd_submit (struct virtio_gpu_device *vgdev,void *data,uint32_t data_size, -uint32_t ctx_id,struct virtio_gpu_fence *fence); +uint32_t ctx_id, +struct virtio_gpu_object_array *objs, +struct virtio_gpu_fence *fence); void virtio_gpu_cmd_transfer_from_host_3d(struct virtio_gpu_device *vgdev, uint32_t resource_id, uint32_t ctx_id, uint64_t offset, uint32_t level,drivers/gpu/drm/virtio/virtgpu_ioctl.c +18
-38@@ -105,16 +105,11 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,struct drm_virtgpu_execbuffer *exbuf = data;struct virtio_gpu_device *vgdev = dev->dev_private;struct virtio_gpu_fpriv *vfpriv = drm_file->driver_priv; -struct drm_gem_object *gobj;struct virtio_gpu_fence *out_fence; -struct virtio_gpu_object *qobj;int ret;uint32_t *bo_handles =NULL ;void __user *user_bo_handles =NULL ; -struct list_head validate_list; -struct ttm_validate_buffer *buflist =NULL ; -int i; -struct ww_acquire_ctx ticket; +struct virtio_gpu_object_array *buflist =NULL ;struct sync_file *sync_file;int in_fence_fd = exbuf->fence_fd;int out_fence_fd =-1 ;@@ -155,15 +150,10 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,return out_fence_fd; } -INIT_LIST_HEAD (&validate_list);if (exbuf->num_bo_handles) { - bo_handles =kvmalloc_array (exbuf->num_bo_handles, -sizeof (uint32_t ),GFP_KERNEL ); - buflist =kvmalloc_array (exbuf->num_bo_handles, -sizeof (struct ttm_validate_buffer ), -GFP_KERNEL | __GFP_ZERO); -if (!bo_handles || !buflist) { +sizeof (uint32_t ),GFP_KERNEL ); +if (!bo_handles) { ret = -ENOMEM ; goto out_unused_fd; }@@ -175,25 +165,21 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data, goto out_unused_fd; } -for (i =0 ; i < exbuf->num_bo_handles; i++) { - gobj =drm_gem_object_lookup (drm_file, bo_handles[i]); -if (!gobj) { - ret = -ENOENT ; - goto out_unused_fd; - } - - qobj =gem_to_virtio_gpu_obj (gobj); - buflist[i].bo = &qobj->tbo; - -list_add (&buflist[i].head, &validate_list); + buflist =virtio_gpu_array_from_handles (drm_file, bo_handles, + exbuf->num_bo_handles); +if (!buflist) { + ret = -ENOENT ; + goto out_unused_fd; }kvfree (bo_handles); bo_handles =NULL ; } - ret =virtio_gpu_object_list_validate (&ticket, &validate_list); -if (ret) - goto out_free; +if (buflist) { + ret =virtio_gpu_array_lock_resv (buflist); +if (ret) + goto out_unused_fd; + } buf =memdup_user (u64_to_user_ptr (exbuf->command), exbuf->size);if (IS_ERR (buf)) {@@ -220,24 +206,18 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data, }virtio_gpu_cmd_submit (vgdev, buf, exbuf->size, - vfpriv->ctx_id, out_fence); - -ttm_eu_fence_buffer_objects (&ticket, &validate_list, &out_fence->f); - -/* fence the command bo */ -virtio_gpu_unref_list (&validate_list); -kvfree (buflist); + vfpriv->ctx_id, buflist, out_fence);return 0 ; out_memdup:kfree (buf); out_unresv: -ttm_eu_backoff_reservation (&ticket, &validate_list); -out_free: -virtio_gpu_unref_list (&validate_list); +if (buflist) +virtio_gpu_array_unlock_resv (buflist); out_unused_fd:kvfree (bo_handles); -kvfree (buflist); +if (buflist) +virtio_gpu_array_put_free (buflist);if (out_fence_fd >=0 )put_unused_fd (out_fence_fd);drivers/gpu/drm/virtio/virtgpu_vq.c +8
-4@@ -191,7 +191,7 @@ void virtio_gpu_dequeue_ctrl_func(struct work_struct *work) }while (!virtqueue_enable_cb (vgdev->ctrlq.vq));spin_unlock (&vgdev->ctrlq.qlock); -list_for_each_entry_safe (entry, tmp, &reclaim_list, list) { +list_for_each_entry (entry, &reclaim_list, list) { resp = (struct virtio_gpu_ctrl_hdr *)entry->resp_buf;trace_virtio_gpu_cmd_response (vgdev->ctrlq.vq, resp);@@ -218,14 +218,18 @@ void virtio_gpu_dequeue_ctrl_func(struct work_struct *work) }if (entry->resp_cb) entry->resp_cb (vgdev, entry); - -list_del (&entry->list); -free_vbuf (vgdev, entry); }wake_up (&vgdev->ctrlq.ack_queue);if (fence_id)virtio_gpu_fence_event_process (vgdev, fence_id); + +list_for_each_entry_safe (entry, tmp, &reclaim_list, list) { +if (entry->objs) +virtio_gpu_array_put_free (entry->objs); +list_del (&entry->list); +free_vbuf (vgdev, entry); + } }void virtio_gpu_dequeue_cursor_func (struct work_struct *work)
drivers/gpu/drm/virtio/virtgpu_vq.c static int virtio_gpu_queue_fenced_ctrl_buffer(struct virtio_gpu_device *vgdev, · line 347
Quoted 7 lines
drivers/gpu/drm/virtio/virtgpu_vq.c +4
-0@@ -337,6 +341,10 @@ static int virtio_gpu_queue_fenced_ctrl_buffer(struct virtio_gpu_device *vgdev,if (fence)virtio_gpu_fence_emit (vgdev, hdr, fence); +if (vbuf->objs) { +virtio_gpu_array_add_fence (vbuf->objs, &fence->f); +virtio_gpu_array_unlock_resv (vbuf->objs); + }
This is with the spinlock held. Maybe we should move the virtio_gpu_array_unlock_resv call out of the critical section.
I am actually more concerned about virtio_gpu_array_add_fence, but it is also harder to move. Should we add a kref to the object array?
This bothers me because I recently ran into a CPU-bound game with very bad lock contention here.
Quoted 25 lines
drivers/gpu/drm/virtio/virtgpu_vq.c +4
-2rc =virtio_gpu_queue_ctrl_buffer_locked (vgdev, vbuf);spin_unlock (&vgdev->ctrlq.qlock);return rc;@@ -939,7 +947,9 @@ void virtio_gpu_cmd_transfer_from_host_3d(struct virtio_gpu_device *vgdev,void virtio_gpu_cmd_submit (struct virtio_gpu_device *vgdev,void *data,uint32_t data_size, -uint32_t ctx_id,struct virtio_gpu_fence *fence) +uint32_t ctx_id, +struct virtio_gpu_object_array *objs, +struct virtio_gpu_fence *fence) {struct virtio_gpu_cmd_submit *cmd_p;struct virtio_gpu_vbuffer *vbuf;@@ -949,6 +959,7 @@ void virtio_gpu_cmd_submit(struct virtio_gpu_device *vgdev, vbuf->data_buf = data; vbuf->data_size = data_size; + vbuf->objs = objs; cmd_p->hdr.type =cpu_to_le32 (VIRTIO_GPU_CMD_SUBMIT_3D ); cmd_p->hdr.ctx_id =cpu_to_le32 (ctx_id); --2.18.1
Gerd Hoffmann
maintainerPATCH v6 9/18 drm/virtio: rework virtio_gpu_object_create fencing
In reply to Gerd HoffmannRework fencing workflow. Stop using ttm helpers, use the virtio_gpu_array_* helpers instead.
Due to using the gem reservation object it is initialized and ready for use before calling ttm_bo_init. So we can simply use the standard fencing workflow and drop the tricky logic which checks whenever the command is in flight still.
v6: rewrite most of the patch.
--- drivers/gpu/drm/virtio/virtgpu_drv.h | 2 + drivers/gpu/drm/virtio/virtgpu_object.c | 74 +++++++++++-------------- drivers/gpu/drm/virtio/virtgpu_vq.c | 4 ++ 3 files changed, 37 insertions(+), 43 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.h +2 -0
@@ -274,6 +274,7 @@ void virtio_gpu_free_vbufs(struct virtio_gpu_device *vgdev);void virtio_gpu_cmd_create_resource (struct virtio_gpu_device *vgdev,struct virtio_gpu_object *bo,struct virtio_gpu_object_params *params, +struct virtio_gpu_object_array *objs,struct virtio_gpu_fence *fence);void virtio_gpu_cmd_unref_resource (struct virtio_gpu_device *vgdev,uint32_t resource_id);
@@ -336,6 +337,7 @@ void virtio_gpu_cmd_resource_create_3d(struct virtio_gpu_device *vgdev, struct virtio_gpu_object *bo, struct virtio_gpu_object_params *params, + struct virtio_gpu_object_array *objs, struct virtio_gpu_fence *fence);void virtio_gpu_ctrl_ack (struct virtqueue *vq);void virtio_gpu_cursor_ack (struct virtqueue *vq);
drivers/gpu/drm/virtio/virtgpu_object.c +31 -43
100 lines not on this page · raw message
drivers/gpu/drm/virtio/virtgpu_vq.c +4 -0
@@ -395,6 +395,7 @@ static int virtio_gpu_queue_cursor(struct virtio_gpu_device *vgdev,void virtio_gpu_cmd_create_resource (struct virtio_gpu_device *vgdev,struct virtio_gpu_object *bo,struct virtio_gpu_object_params *params, +struct virtio_gpu_object_array *objs,struct virtio_gpu_fence *fence) {struct virtio_gpu_resource_create_2d *cmd_p;
@@ -402,6 +403,7 @@ void virtio_gpu_cmd_create_resource(struct virtio_gpu_device *vgdev, cmd_p =virtio_gpu_alloc_cmd (vgdev, &vbuf,sizeof (*cmd_p));memset (cmd_p,0 ,sizeof (*cmd_p)); + vbuf->objs = objs; cmd_p->hdr.type =cpu_to_le32 (VIRTIO_GPU_CMD_RESOURCE_CREATE_2D ); cmd_p->resource_id =cpu_to_le32 (bo->hw_res_handle);
@@ -868,6 +870,7 @@ void virtio_gpu_cmd_resource_create_3d(struct virtio_gpu_device *vgdev, struct virtio_gpu_object *bo, struct virtio_gpu_object_params *params, + struct virtio_gpu_object_array *objs, struct virtio_gpu_fence *fence) { struct virtio_gpu_resource_create_3d *cmd_p;
@@ -875,6 +878,7 @@ virtio_gpu_cmd_resource_create_3d(struct virtio_gpu_device *vgdev, cmd_p =virtio_gpu_alloc_cmd (vgdev, &vbuf,sizeof (*cmd_p));memset (cmd_p,0 ,sizeof (*cmd_p)); + vbuf->objs = objs; cmd_p->hdr.type =cpu_to_le32 (VIRTIO_GPU_CMD_RESOURCE_CREATE_3D ); cmd_p->resource_id =cpu_to_le32 (bo->hw_res_handle);
Signature · 1 line
2.18.1
Gerd Hoffmann
maintainerPATCH v6 9/18 drm/virtio: rework virtio_gpu_object_create fencing
In reply to Gerd HoffmannRework fencing workflow. Stop using ttm helpers, use the virtio_gpu_array_* helpers instead.
Due to using the gem reservation object it is initialized and ready for use before calling ttm_bo_init. So we can simply use the standard fencing workflow and drop the tricky logic which checks whenever the command is in flight still.
v6: rewrite most of the patch.
--- drivers/gpu/drm/virtio/virtgpu_drv.h | 2 + drivers/gpu/drm/virtio/virtgpu_object.c | 74 +++++++++++-------------- drivers/gpu/drm/virtio/virtgpu_vq.c | 4 ++ 3 files changed, 37 insertions(+), 43 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.h +2 -0
@@ -274,6 +274,7 @@ void virtio_gpu_free_vbufs(struct virtio_gpu_device *vgdev);void virtio_gpu_cmd_create_resource (struct virtio_gpu_device *vgdev,struct virtio_gpu_object *bo,struct virtio_gpu_object_params *params, +struct virtio_gpu_object_array *objs,struct virtio_gpu_fence *fence);void virtio_gpu_cmd_unref_resource (struct virtio_gpu_device *vgdev,uint32_t resource_id);
@@ -336,6 +337,7 @@ void virtio_gpu_cmd_resource_create_3d(struct virtio_gpu_device *vgdev, struct virtio_gpu_object *bo, struct virtio_gpu_object_params *params, + struct virtio_gpu_object_array *objs, struct virtio_gpu_fence *fence);void virtio_gpu_ctrl_ack (struct virtqueue *vq);void virtio_gpu_cursor_ack (struct virtqueue *vq);
drivers/gpu/drm/virtio/virtgpu_object.c +31 -43
100 lines not on this page · raw message
drivers/gpu/drm/virtio/virtgpu_vq.c +4 -0
@@ -395,6 +395,7 @@ static int virtio_gpu_queue_cursor(struct virtio_gpu_device *vgdev,void virtio_gpu_cmd_create_resource (struct virtio_gpu_device *vgdev,struct virtio_gpu_object *bo,struct virtio_gpu_object_params *params, +struct virtio_gpu_object_array *objs,struct virtio_gpu_fence *fence) {struct virtio_gpu_resource_create_2d *cmd_p;
@@ -402,6 +403,7 @@ void virtio_gpu_cmd_create_resource(struct virtio_gpu_device *vgdev, cmd_p =virtio_gpu_alloc_cmd (vgdev, &vbuf,sizeof (*cmd_p));memset (cmd_p,0 ,sizeof (*cmd_p)); + vbuf->objs = objs; cmd_p->hdr.type =cpu_to_le32 (VIRTIO_GPU_CMD_RESOURCE_CREATE_2D ); cmd_p->resource_id =cpu_to_le32 (bo->hw_res_handle);
@@ -868,6 +870,7 @@ void virtio_gpu_cmd_resource_create_3d(struct virtio_gpu_device *vgdev, struct virtio_gpu_object *bo, struct virtio_gpu_object_params *params, + struct virtio_gpu_object_array *objs, struct virtio_gpu_fence *fence) { struct virtio_gpu_resource_create_3d *cmd_p;
@@ -875,6 +878,7 @@ virtio_gpu_cmd_resource_create_3d(struct virtio_gpu_device *vgdev, cmd_p =virtio_gpu_alloc_cmd (vgdev, &vbuf,sizeof (*cmd_p));memset (cmd_p,0 ,sizeof (*cmd_p)); + vbuf->objs = objs; cmd_p->hdr.type =cpu_to_le32 (VIRTIO_GPU_CMD_RESOURCE_CREATE_3D ); cmd_p->resource_id =cpu_to_le32 (bo->hw_res_handle);
Signature · 1 line
2.18.1
Gerd Hoffmann
maintainerPATCH v6 10/18 drm/virtio: drop virtio_gpu_object_list_validate/virtio_gpu_unref_list
In reply to Gerd HoffmannNo users left.
--- drivers/gpu/drm/virtio/virtgpu_drv.h | 3 -- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 39 -------------------------- 2 files changed, 42 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.h +0 -3
@@ -223,9 +223,6 @@ struct virtio_gpu_fpriv {/* virtio_ioctl.c */ #define DRM_VIRTIO_NUM_IOCTLS 10extern struct drm_ioctl_desc virtio_gpu_ioctls[DRM_VIRTIO_NUM_IOCTLS ]; -int virtio_gpu_object_list_validate (struct ww_acquire_ctx *ticket, -struct list_head *head); -void virtio_gpu_unref_list (struct list_head *head);/* virtio_kms.c */ int virtio_gpu_init (struct drm_device *dev);
drivers/gpu/drm/virtio/virtgpu_ioctl.c +0 -39
@@ -54,45 +54,6 @@ static int virtio_gpu_map_ioctl(struct drm_device *dev, void *data, &virtio_gpu_map->offset); } -int virtio_gpu_object_list_validate (struct ww_acquire_ctx *ticket, -struct list_head *head) -{ -struct ttm_operation_ctx ctx = { false, false }; -struct ttm_validate_buffer *buf; -struct ttm_buffer_object *bo; -struct virtio_gpu_object *qobj; -int ret; - - ret =ttm_eu_reserve_buffers (ticket, head, true,NULL , true); -if (ret !=0 ) -return ret; - -list_for_each_entry (buf, head, head) { - bo = buf->bo; - qobj = container_of(bo, struct virtio_gpu_object, tbo); - ret =ttm_bo_validate (bo, &qobj->placement, &ctx); -if (ret) { -ttm_eu_backoff_reservation (ticket, head); -return ret; - } - } -return 0 ; -} - -void virtio_gpu_unref_list (struct list_head *head) -{ -struct ttm_validate_buffer *buf; -struct ttm_buffer_object *bo; -struct virtio_gpu_object *qobj; - -list_for_each_entry (buf, head, head) { - bo = buf->bo; - qobj = container_of(bo, struct virtio_gpu_object, tbo); - -drm_gem_object_put_unlocked (&qobj->gem_base); - } -} -/* * Usage of execbuffer: * Relocations need to take into account the full VIRTIO_GPUDrawable size.
Signature · 1 line
2.18.1
Gerd Hoffmann
maintainerPATCH v6 10/18 drm/virtio: drop virtio_gpu_object_list_validate/virtio_gpu_unref_list
In reply to Gerd HoffmannNo users left.
--- drivers/gpu/drm/virtio/virtgpu_drv.h | 3 -- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 39 -------------------------- 2 files changed, 42 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.h +0 -3
@@ -223,9 +223,6 @@ struct virtio_gpu_fpriv {/* virtio_ioctl.c */ #define DRM_VIRTIO_NUM_IOCTLS 10extern struct drm_ioctl_desc virtio_gpu_ioctls[DRM_VIRTIO_NUM_IOCTLS ]; -int virtio_gpu_object_list_validate (struct ww_acquire_ctx *ticket, -struct list_head *head); -void virtio_gpu_unref_list (struct list_head *head);/* virtio_kms.c */ int virtio_gpu_init (struct drm_device *dev);
drivers/gpu/drm/virtio/virtgpu_ioctl.c +0 -39
@@ -54,45 +54,6 @@ static int virtio_gpu_map_ioctl(struct drm_device *dev, void *data, &virtio_gpu_map->offset); } -int virtio_gpu_object_list_validate (struct ww_acquire_ctx *ticket, -struct list_head *head) -{ -struct ttm_operation_ctx ctx = { false, false }; -struct ttm_validate_buffer *buf; -struct ttm_buffer_object *bo; -struct virtio_gpu_object *qobj; -int ret; - - ret =ttm_eu_reserve_buffers (ticket, head, true,NULL , true); -if (ret !=0 ) -return ret; - -list_for_each_entry (buf, head, head) { - bo = buf->bo; - qobj = container_of(bo, struct virtio_gpu_object, tbo); - ret =ttm_bo_validate (bo, &qobj->placement, &ctx); -if (ret) { -ttm_eu_backoff_reservation (ticket, head); -return ret; - } - } -return 0 ; -} - -void virtio_gpu_unref_list (struct list_head *head) -{ -struct ttm_validate_buffer *buf; -struct ttm_buffer_object *bo; -struct virtio_gpu_object *qobj; - -list_for_each_entry (buf, head, head) { - bo = buf->bo; - qobj = container_of(bo, struct virtio_gpu_object, tbo); - -drm_gem_object_put_unlocked (&qobj->gem_base); - } -} -/* * Usage of execbuffer: * Relocations need to take into account the full VIRTIO_GPUDrawable size.
Signature · 1 line
2.18.1
Gerd Hoffmann
maintainerPATCH v6 11/18 drm/virtio: switch from ttm to gem shmem helpers
In reply to Gerd Hoffmannvirtio-gpu basically needs a sg_table for the bo, to tell the host where the backing pages for the object are. So the gem shmem helpers are a perfect fit. Some drm_gem_object_funcs need thin wrappers to update the host state, but otherwise the helpers handle everything just fine.
Once the fencing was sorted the switch was surprisingly easy and for the most part just removing the ttm code.
v4: fix drm_gem_object_funcs name.
--- drivers/gpu/drm/virtio/virtgpu_drv.h | 52 +--- drivers/gpu/drm/virtio/virtgpu_drv.c | 20 +- drivers/gpu/drm/virtio/virtgpu_gem.c | 16 +- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 19 +- drivers/gpu/drm/virtio/virtgpu_kms.c | 9 - drivers/gpu/drm/virtio/virtgpu_object.c | 146 ++++-------- drivers/gpu/drm/virtio/virtgpu_prime.c | 37 --- drivers/gpu/drm/virtio/virtgpu_ttm.c | 304 ------------------------ drivers/gpu/drm/virtio/virtgpu_vq.c | 24 +- drivers/gpu/drm/virtio/Kconfig | 2 +- drivers/gpu/drm/virtio/Makefile | 2 +- 11 files changed, 82 insertions(+), 549 deletions(-) delete mode 100644 drivers/gpu/drm/virtio/virtgpu_ttm.c
drivers/gpu/drm/virtio/virtgpu_drv.h +11 -41
@@ -33,14 +33,11 @@#include <drm/drmP.h> #include <drm/drm_gem.h> +#include <drm/drm_gem_shmem_helper.h> #include <drm/drm_atomic.h> #include <drm/drm_encoder.h> #include <drm/drm_fb_helper.h> #include <drm/drm_probe_helper.h> -#include <drm/ttm/ttm_bo_api.h> -#include <drm/ttm/ttm_bo_driver.h> -#include <drm/ttm/ttm_placement.h> -#include <drm/ttm/ttm_module.h> #define DRIVER_NAME "virtio_gpu"#define DRIVER_DESC "virtio GPU"
@@ -68,21 +65,16 @@ struct virtio_gpu_object_params { };struct virtio_gpu_object { -struct drm_gem_object gem_base; +struct drm_gem_shmem_object base;uint32_t hw_res_handle;struct sg_table *pages;uint32_t mapped; -void *vmap;bool dumb; -struct ttm_place placement_code; -struct ttm_placement placement; -struct ttm_buffer_object tbo; -struct ttm_bo_kmap_obj kmap;bool created; };#define gem_to_virtio_gpu_obj (gobj) \ - container_of((gobj), struct virtio_gpu_object, gem_base) + container_of((gobj), struct virtio_gpu_object, base.base)struct virtio_gpu_object_array {struct ww_acquire_ctx ticket;
@@ -153,10 +145,6 @@ struct virtio_gpu_framebuffer {#define to_virtio_gpu_framebuffer (x) \ container_of(x, struct virtio_gpu_framebuffer, base) -struct virtio_gpu_mman { -struct ttm_bo_device bdev; -}; -struct virtio_gpu_queue {struct virtqueue *vq;spinlock_t qlock;
@@ -185,8 +173,6 @@ struct virtio_gpu_device {struct virtio_device *vdev; -struct virtio_gpu_mman mman; -struct virtio_gpu_output outputs[VIRTIO_GPU_MAX_SCANOUTS ];uint32_t num_scanouts;
@@ -357,11 +343,6 @@ struct drm_plane *virtio_gpu_plane_init(struct virtio_gpu_device *vgdev,enum drm_plane_type type, int index); -/* virtio_gpu_ttm.c */ -int virtio_gpu_ttm_init (struct virtio_gpu_device *vgdev); -void virtio_gpu_ttm_fini (struct virtio_gpu_device *vgdev); -int virtio_gpu_mmap (struct file *filp,struct vm_area_struct *vma); -/* virtio_gpu_fence.c */ bool virtio_fence_signaled (struct dma_fence *f); struct virtio_gpu_fence *virtio_gpu_fence_alloc(
@@ -373,58 +354,47 @@ void virtio_gpu_fence_event_process(struct virtio_gpu_device *vdev, u64 last_seq);/* virtio_gpu_object */ +struct drm_gem_object *virtio_gpu_create_object (struct drm_device *dev, +size_t size);int virtio_gpu_object_create (struct virtio_gpu_device *vgdev,struct virtio_gpu_object_params *params,struct virtio_gpu_object **bo_ptr,struct virtio_gpu_fence *fence); -void virtio_gpu_object_kunmap (struct virtio_gpu_object *bo); -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);/* virtgpu_prime.c */ -struct sg_table *virtgpu_gem_prime_get_sg_table (struct drm_gem_object *obj);struct drm_gem_object *virtgpu_gem_prime_import_sg_table (struct drm_device *dev,struct dma_buf_attachment *attach,struct sg_table *sgt); -void *virtgpu_gem_prime_vmap (struct drm_gem_object *obj); -void virtgpu_gem_prime_vunmap (struct drm_gem_object *obj,void *vaddr); -int virtgpu_gem_prime_mmap (struct drm_gem_object *obj, -struct vm_area_struct *vma);static inline struct virtio_gpu_object *virtio_gpu_object_ref (struct virtio_gpu_object *bo) { -ttm_bo_get (&bo->tbo); +drm_gem_object_get (&bo->base.base);return bo; }static inline void virtio_gpu_object_unref (struct virtio_gpu_object **bo) { -struct ttm_buffer_object *tbo; -if ((*bo) ==NULL )return ; - tbo = &((*bo)->tbo); -ttm_bo_put (tbo); +drm_gem_object_put (&(*bo)->base.base); *bo =NULL ; }static inline u64 virtio_gpu_object_mmap_offset (struct virtio_gpu_object *bo) { -return drm_vma_node_offset_addr (&bo->tbo.vma_node); +return drm_vma_node_offset_addr (&bo->base.base.vma_node); }static inline int virtio_gpu_object_reserve (struct virtio_gpu_object *bo) {int r; - r =reservation_object_lock_interruptible (bo->gem_base.resv,NULL ); + r =reservation_object_lock_interruptible (bo->base.base.resv,NULL );if (unlikely (r !=0 )) {if (r != -EINTR ) {struct virtio_gpu_device *qdev = - bo->gem_base.dev->dev_private; + bo->base.base.dev->dev_private;dev_err (qdev->dev,"%p reserve failed\n" , bo); }return r;
@@ -434,7 +404,7 @@ static inline int virtio_gpu_object_reserve(struct virtio_gpu_object *bo)static inline void virtio_gpu_object_unreserve (struct virtio_gpu_object *bo) { -reservation_object_unlock (bo->gem_base.resv); +reservation_object_unlock (bo->base.base.resv); }/* virgl debufs */
drivers/gpu/drm/virtio/virtgpu_drv.c +2 -18
@@ -182,17 +182,7 @@ MODULE_AUTHOR("Dave Airlie <[email protected]>");MODULE_AUTHOR ("Gerd Hoffmann <[email protected]>" );MODULE_AUTHOR ("Alon Levy" ); -static const struct file_operations virtio_gpu_driver_fops = { - .owner =THIS_MODULE , - .open = drm_open, - .mmap = virtio_gpu_mmap, - .poll = drm_poll, - .read = drm_read, - .unlocked_ioctl = drm_ioctl, - .release = drm_release, - .compat_ioctl = drm_compat_ioctl, - .llseek = noop_llseek, -}; +DEFINE_DRM_GEM_SHMEM_FOPS (virtio_gpu_driver_fops);static struct drm_driver driver = { .driver_features =DRIVER_MODESET |DRIVER_GEM |DRIVER_RENDER |DRIVER_ATOMIC ,
@@ -207,15 +197,9 @@ static struct drm_driver driver = {#endif .prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle, - .gem_prime_get_sg_table = virtgpu_gem_prime_get_sg_table, .gem_prime_import_sg_table = virtgpu_gem_prime_import_sg_table, - .gem_prime_vmap = virtgpu_gem_prime_vmap, - .gem_prime_vunmap = virtgpu_gem_prime_vunmap, - .gem_prime_mmap = virtgpu_gem_prime_mmap, - .gem_free_object_unlocked = virtio_gpu_gem_free_object, - .gem_open_object = virtio_gpu_gem_object_open, - .gem_close_object = virtio_gpu_gem_object_close, + .gem_create_object = virtio_gpu_create_object, .fops = &virtio_gpu_driver_fops, .ioctls = virtio_gpu_ioctls,
drivers/gpu/drm/virtio/virtgpu_gem.c +4 -12
@@ -26,14 +26,6 @@#include <drm/drmP.h> #include "virtgpu_drv.h" -void virtio_gpu_gem_free_object (struct drm_gem_object *gem_obj) -{ -struct virtio_gpu_object *obj =gem_to_virtio_gpu_obj (gem_obj); - -if (obj) -virtio_gpu_object_unref (&obj); -} -struct virtio_gpu_object * virtio_gpu_alloc_object(struct drm_device *dev, struct virtio_gpu_object_params *params,
@@ -64,16 +56,16 @@ int virtio_gpu_gem_create(struct drm_file *file,if (IS_ERR (obj))return PTR_ERR (obj); - ret =drm_gem_handle_create (file, &obj->gem_base, &handle); + ret =drm_gem_handle_create (file, &obj->base.base, &handle);if (ret) { -drm_gem_object_release (&obj->gem_base); +drm_gem_object_release (&obj->base.base);return ret; } - *obj_p = &obj->gem_base; + *obj_p = &obj->base.base;/* drop reference from allocate - handle holds it now */ -drm_gem_object_put_unlocked (&obj->gem_base); +drm_gem_object_put_unlocked (&obj->base.base); *handle_p = handle;return 0 ;
drivers/gpu/drm/virtio/virtgpu_ioctl.c +4 -15
@@ -27,7 +27,6 @@#include <drm/drmP.h> #include <drm/virtgpu_drm.h> -#include <drm/ttm/ttm_execbuf_util.h> #include <linux/sync_file.h> #include "virtgpu_drv.h"
@@ -259,7 +258,7 @@ static int virtio_gpu_resource_create_ioctl(struct drm_device *dev, void *data,dma_fence_put (&fence->f);if (IS_ERR (qobj))return PTR_ERR (qobj); - obj = &qobj->gem_base; + obj = &qobj->base.base; ret =drm_gem_handle_create (file_priv, obj, &handle);if (ret) {
@@ -286,7 +285,7 @@ static int virtio_gpu_resource_info_ioctl(struct drm_device *dev, void *data, qobj =gem_to_virtio_gpu_obj (gobj); - ri->size = qobj->gem_base.size; + ri->size = qobj->base.base.size; ri->res_handle = qobj->hw_res_handle;drm_gem_object_put_unlocked (gobj);return 0 ;
@@ -299,7 +298,6 @@ static int virtio_gpu_transfer_from_host_ioctl(struct drm_device *dev,struct virtio_gpu_device *vgdev = dev->dev_private;struct virtio_gpu_fpriv *vfpriv = file->driver_priv;struct drm_virtgpu_3d_transfer_from_host *args = data; -struct ttm_operation_ctx ctx = { true, false };struct drm_gem_object *gobj =NULL ;struct virtio_gpu_object *qobj =NULL ;struct virtio_gpu_fence *fence;
@@ -320,10 +318,6 @@ static int virtio_gpu_transfer_from_host_ioctl(struct drm_device *dev,if (ret) goto out; - ret =ttm_bo_validate (&qobj->tbo, &qobj->placement, &ctx); -if (unlikely (ret)) - goto out_unres; -convert_to_hw_box (&box, &args->box); fence =virtio_gpu_fence_alloc (vgdev);
@@ -335,7 +329,7 @@ static int virtio_gpu_transfer_from_host_ioctl(struct drm_device *dev, (vgdev, qobj->hw_res_handle, vfpriv->ctx_id, offset, args->level, &box, fence); -reservation_object_add_excl_fence (qobj->tbo.resv, +reservation_object_add_excl_fence (qobj->base.base.resv, &fence->f);dma_fence_put (&fence->f);
@@ -352,7 +346,6 @@ static int virtio_gpu_transfer_to_host_ioctl(struct drm_device *dev, void *data,struct virtio_gpu_device *vgdev = dev->dev_private;struct virtio_gpu_fpriv *vfpriv = file->driver_priv;struct drm_virtgpu_3d_transfer_to_host *args = data; -struct ttm_operation_ctx ctx = { true, false };struct drm_gem_object *gobj =NULL ;struct virtio_gpu_object *qobj =NULL ;struct virtio_gpu_fence *fence;
@@ -370,10 +363,6 @@ static int virtio_gpu_transfer_to_host_ioctl(struct drm_device *dev, void *data,if (ret) goto out; - ret =ttm_bo_validate (&qobj->tbo, &qobj->placement, &ctx); -if (unlikely (ret)) - goto out_unres; -convert_to_hw_box (&box, &args->box);if (!vgdev->has_virgl_3d) { virtio_gpu_cmd_transfer_to_host_2d
@@ -389,7 +378,7 @@ static int virtio_gpu_transfer_to_host_ioctl(struct drm_device *dev, void *data, (vgdev, qobj, vfpriv ? vfpriv->ctx_id :0 , offset, args->level, &box, fence); -reservation_object_add_excl_fence (qobj->tbo.resv, +reservation_object_add_excl_fence (qobj->base.base.resv, &fence->f);dma_fence_put (&fence->f); }
drivers/gpu/drm/virtio/virtgpu_kms.c +0 -9
@@ -171,12 +171,6 @@ int virtio_gpu_init(struct drm_device *dev) goto err_vbufs; } - ret =virtio_gpu_ttm_init (vgdev); -if (ret) { -DRM_ERROR ("failed to init ttm %d\n" , ret); - goto err_ttm; - } -/* get display info */ virtio_cread(vgdev->vdev, struct virtio_gpu_config, num_scanouts, &num_scanouts);
@@ -208,8 +202,6 @@ int virtio_gpu_init(struct drm_device *dev)return 0 ; err_scanouts: -virtio_gpu_ttm_fini (vgdev); -err_ttm:virtio_gpu_free_vbufs (vgdev); err_vbufs: vgdev->vdev->config->del_vqs (vgdev->vdev);
@@ -240,7 +232,6 @@ void virtio_gpu_deinit(struct drm_device *dev) vgdev->vdev->config->del_vqs (vgdev->vdev);virtio_gpu_modeset_fini (vgdev); -virtio_gpu_ttm_fini (vgdev);virtio_gpu_free_vbufs (vgdev);virtio_gpu_cleanup_cap_cache (vgdev);kfree (vgdev->capsets);
drivers/gpu/drm/virtio/virtgpu_object.c +41 -105
202 lines not on this page · raw message
drivers/gpu/drm/virtio/virtgpu_prime.c +0 -37
@@ -28,46 +28,9 @@* device that might share buffers with virtgpu */ -struct sg_table *virtgpu_gem_prime_get_sg_table (struct drm_gem_object *obj) -{ -struct virtio_gpu_object *bo =gem_to_virtio_gpu_obj (obj); - -if (!bo->tbo.ttm->pages || !bo->tbo.ttm->num_pages) -/* should not happen */ -return ERR_PTR (-EINVAL ); - -return drm_prime_pages_to_sg (bo->tbo.ttm->pages, - bo->tbo.ttm->num_pages); -} -struct drm_gem_object *virtgpu_gem_prime_import_sg_table (struct drm_device *dev,struct dma_buf_attachment *attach,struct sg_table *table) {return ERR_PTR (-ENODEV ); } - -void *virtgpu_gem_prime_vmap (struct drm_gem_object *obj) -{ -struct virtio_gpu_object *bo =gem_to_virtio_gpu_obj (obj); -int ret; - - ret =virtio_gpu_object_kmap (bo); -if (ret) -return NULL ; -return bo->vmap; -} - -void virtgpu_gem_prime_vunmap (struct drm_gem_object *obj,void *vaddr) -{ -virtio_gpu_object_kunmap (gem_to_virtio_gpu_obj (obj)); -} - -int virtgpu_gem_prime_mmap (struct drm_gem_object *obj, -struct vm_area_struct *vma) -{ -struct virtio_gpu_object *bo =gem_to_virtio_gpu_obj (obj); - - bo->gem_base.vma_node.vm_node.start = bo->tbo.vma_node.vm_node.start; -return drm_gem_prime_mmap (obj, vma); -}
drivers/gpu/drm/virtio/virtgpu_ttm.c deleted +0 -304
304 lines not on this page · raw message
drivers/gpu/drm/virtio/virtgpu_vq.c +18 -6
@@ -979,17 +979,21 @@ int virtio_gpu_object_attach(struct virtio_gpu_device *vgdev,bool use_dma_api = !virtio_has_iommu_quirk (vgdev->vdev);struct virtio_gpu_mem_entry *ents;struct scatterlist *sg; -int si, nents; +int si, nents, ret;if (WARN_ON_ONCE (!obj->created))return -EINVAL ; +if (WARN_ON_ONCE (obj->pages)) +return -EINVAL ; -if (!obj->pages) { -int ret; + ret =drm_gem_shmem_pin (&obj->base.base); +if (ret <0 ) +return -EINVAL ; - ret =virtio_gpu_object_get_sg_table (vgdev, obj); -if (ret) -return ret; + obj->pages =drm_gem_shmem_get_sg_table (&obj->base.base); +if (obj->pages ==NULL ) { +drm_gem_shmem_unpin (&obj->base.base); +return -EINVAL ; }if (use_dma_api) {
@@ -1028,6 +1032,9 @@ void virtio_gpu_object_detach(struct virtio_gpu_device *vgdev, {bool use_dma_api = !virtio_has_iommu_quirk (vgdev->vdev); +if (WARN_ON_ONCE (!obj->pages)) +return ; +if (use_dma_api && obj->mapped) {struct virtio_gpu_fence *fence =virtio_gpu_fence_alloc (vgdev);/* detach backing and wait for the host process it ... */
@@ -1043,6 +1050,11 @@ void virtio_gpu_object_detach(struct virtio_gpu_device *vgdev, }else {virtio_gpu_cmd_resource_inval_backing (vgdev, obj->hw_res_handle,NULL ); } + +sg_free_table (obj->pages); + obj->pages =NULL ; + +drm_gem_shmem_unpin (&obj->base.base); } void virtio_gpu_cursor_ping(struct virtio_gpu_device *vgdev,
drivers/gpu/drm/virtio/Kconfig +1 -1
@@ -3,7 +3,7 @@ config DRM_VIRTIO_GPU tristate "Virtio GPU driver" depends on DRM && VIRTIO && MMU select DRM_KMS_HELPER - select DRM_TTM + select DRM_GEM_SHMEM_HELPER help This is the virtual GPU driver for virtio. It can be used with QEMU based VMMs (like KVM or Xen).
drivers/gpu/drm/virtio/Makefile +1 -1
@@ -4,7 +4,7 @@ # Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher. virtio-gpu-y := virtgpu_drv.o virtgpu_kms.o virtgpu_gem.o \ - virtgpu_display.o virtgpu_vq.o virtgpu_ttm.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
Signature · 1 line
2.18.1
Gerd Hoffmann
maintainerPATCH v6 11/18 drm/virtio: switch from ttm to gem shmem helpers
In reply to Gerd Hoffmannvirtio-gpu basically needs a sg_table for the bo, to tell the host where the backing pages for the object are. So the gem shmem helpers are a perfect fit. Some drm_gem_object_funcs need thin wrappers to update the host state, but otherwise the helpers handle everything just fine.
Once the fencing was sorted the switch was surprisingly easy and for the most part just removing the ttm code.
v4: fix drm_gem_object_funcs name.
--- drivers/gpu/drm/virtio/virtgpu_drv.h | 52 +--- drivers/gpu/drm/virtio/virtgpu_drv.c | 20 +- drivers/gpu/drm/virtio/virtgpu_gem.c | 16 +- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 19 +- drivers/gpu/drm/virtio/virtgpu_kms.c | 9 - drivers/gpu/drm/virtio/virtgpu_object.c | 146 ++++-------- drivers/gpu/drm/virtio/virtgpu_prime.c | 37 --- drivers/gpu/drm/virtio/virtgpu_ttm.c | 304 ------------------------ drivers/gpu/drm/virtio/virtgpu_vq.c | 24 +- drivers/gpu/drm/virtio/Kconfig | 2 +- drivers/gpu/drm/virtio/Makefile | 2 +- 11 files changed, 82 insertions(+), 549 deletions(-) delete mode 100644 drivers/gpu/drm/virtio/virtgpu_ttm.c
drivers/gpu/drm/virtio/virtgpu_drv.h +11 -41
@@ -33,14 +33,11 @@#include <drm/drmP.h> #include <drm/drm_gem.h> +#include <drm/drm_gem_shmem_helper.h> #include <drm/drm_atomic.h> #include <drm/drm_encoder.h> #include <drm/drm_fb_helper.h> #include <drm/drm_probe_helper.h> -#include <drm/ttm/ttm_bo_api.h> -#include <drm/ttm/ttm_bo_driver.h> -#include <drm/ttm/ttm_placement.h> -#include <drm/ttm/ttm_module.h> #define DRIVER_NAME "virtio_gpu"#define DRIVER_DESC "virtio GPU"
@@ -68,21 +65,16 @@ struct virtio_gpu_object_params { };struct virtio_gpu_object { -struct drm_gem_object gem_base; +struct drm_gem_shmem_object base;uint32_t hw_res_handle;struct sg_table *pages;uint32_t mapped; -void *vmap;bool dumb; -struct ttm_place placement_code; -struct ttm_placement placement; -struct ttm_buffer_object tbo; -struct ttm_bo_kmap_obj kmap;bool created; };#define gem_to_virtio_gpu_obj (gobj) \ - container_of((gobj), struct virtio_gpu_object, gem_base) + container_of((gobj), struct virtio_gpu_object, base.base)struct virtio_gpu_object_array {struct ww_acquire_ctx ticket;
@@ -153,10 +145,6 @@ struct virtio_gpu_framebuffer {#define to_virtio_gpu_framebuffer (x) \ container_of(x, struct virtio_gpu_framebuffer, base) -struct virtio_gpu_mman { -struct ttm_bo_device bdev; -}; -struct virtio_gpu_queue {struct virtqueue *vq;spinlock_t qlock;
@@ -185,8 +173,6 @@ struct virtio_gpu_device {struct virtio_device *vdev; -struct virtio_gpu_mman mman; -struct virtio_gpu_output outputs[VIRTIO_GPU_MAX_SCANOUTS ];uint32_t num_scanouts;
@@ -357,11 +343,6 @@ struct drm_plane *virtio_gpu_plane_init(struct virtio_gpu_device *vgdev,enum drm_plane_type type, int index); -/* virtio_gpu_ttm.c */ -int virtio_gpu_ttm_init (struct virtio_gpu_device *vgdev); -void virtio_gpu_ttm_fini (struct virtio_gpu_device *vgdev); -int virtio_gpu_mmap (struct file *filp,struct vm_area_struct *vma); -/* virtio_gpu_fence.c */ bool virtio_fence_signaled (struct dma_fence *f); struct virtio_gpu_fence *virtio_gpu_fence_alloc(
@@ -373,58 +354,47 @@ void virtio_gpu_fence_event_process(struct virtio_gpu_device *vdev, u64 last_seq);/* virtio_gpu_object */ +struct drm_gem_object *virtio_gpu_create_object (struct drm_device *dev, +size_t size);int virtio_gpu_object_create (struct virtio_gpu_device *vgdev,struct virtio_gpu_object_params *params,struct virtio_gpu_object **bo_ptr,struct virtio_gpu_fence *fence); -void virtio_gpu_object_kunmap (struct virtio_gpu_object *bo); -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);/* virtgpu_prime.c */ -struct sg_table *virtgpu_gem_prime_get_sg_table (struct drm_gem_object *obj);struct drm_gem_object *virtgpu_gem_prime_import_sg_table (struct drm_device *dev,struct dma_buf_attachment *attach,struct sg_table *sgt); -void *virtgpu_gem_prime_vmap (struct drm_gem_object *obj); -void virtgpu_gem_prime_vunmap (struct drm_gem_object *obj,void *vaddr); -int virtgpu_gem_prime_mmap (struct drm_gem_object *obj, -struct vm_area_struct *vma);static inline struct virtio_gpu_object *virtio_gpu_object_ref (struct virtio_gpu_object *bo) { -ttm_bo_get (&bo->tbo); +drm_gem_object_get (&bo->base.base);return bo; }static inline void virtio_gpu_object_unref (struct virtio_gpu_object **bo) { -struct ttm_buffer_object *tbo; -if ((*bo) ==NULL )return ; - tbo = &((*bo)->tbo); -ttm_bo_put (tbo); +drm_gem_object_put (&(*bo)->base.base); *bo =NULL ; }static inline u64 virtio_gpu_object_mmap_offset (struct virtio_gpu_object *bo) { -return drm_vma_node_offset_addr (&bo->tbo.vma_node); +return drm_vma_node_offset_addr (&bo->base.base.vma_node); }static inline int virtio_gpu_object_reserve (struct virtio_gpu_object *bo) {int r; - r =reservation_object_lock_interruptible (bo->gem_base.resv,NULL ); + r =reservation_object_lock_interruptible (bo->base.base.resv,NULL );if (unlikely (r !=0 )) {if (r != -EINTR ) {struct virtio_gpu_device *qdev = - bo->gem_base.dev->dev_private; + bo->base.base.dev->dev_private;dev_err (qdev->dev,"%p reserve failed\n" , bo); }return r;
@@ -434,7 +404,7 @@ static inline int virtio_gpu_object_reserve(struct virtio_gpu_object *bo)static inline void virtio_gpu_object_unreserve (struct virtio_gpu_object *bo) { -reservation_object_unlock (bo->gem_base.resv); +reservation_object_unlock (bo->base.base.resv); }/* virgl debufs */
drivers/gpu/drm/virtio/virtgpu_drv.c +2 -18
@@ -182,17 +182,7 @@ MODULE_AUTHOR("Dave Airlie <[email protected]>");MODULE_AUTHOR ("Gerd Hoffmann <[email protected]>" );MODULE_AUTHOR ("Alon Levy" ); -static const struct file_operations virtio_gpu_driver_fops = { - .owner =THIS_MODULE , - .open = drm_open, - .mmap = virtio_gpu_mmap, - .poll = drm_poll, - .read = drm_read, - .unlocked_ioctl = drm_ioctl, - .release = drm_release, - .compat_ioctl = drm_compat_ioctl, - .llseek = noop_llseek, -}; +DEFINE_DRM_GEM_SHMEM_FOPS (virtio_gpu_driver_fops);static struct drm_driver driver = { .driver_features =DRIVER_MODESET |DRIVER_GEM |DRIVER_RENDER |DRIVER_ATOMIC ,
@@ -207,15 +197,9 @@ static struct drm_driver driver = {#endif .prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle, - .gem_prime_get_sg_table = virtgpu_gem_prime_get_sg_table, .gem_prime_import_sg_table = virtgpu_gem_prime_import_sg_table, - .gem_prime_vmap = virtgpu_gem_prime_vmap, - .gem_prime_vunmap = virtgpu_gem_prime_vunmap, - .gem_prime_mmap = virtgpu_gem_prime_mmap, - .gem_free_object_unlocked = virtio_gpu_gem_free_object, - .gem_open_object = virtio_gpu_gem_object_open, - .gem_close_object = virtio_gpu_gem_object_close, + .gem_create_object = virtio_gpu_create_object, .fops = &virtio_gpu_driver_fops, .ioctls = virtio_gpu_ioctls,
drivers/gpu/drm/virtio/virtgpu_gem.c +4 -12
@@ -26,14 +26,6 @@#include <drm/drmP.h> #include "virtgpu_drv.h" -void virtio_gpu_gem_free_object (struct drm_gem_object *gem_obj) -{ -struct virtio_gpu_object *obj =gem_to_virtio_gpu_obj (gem_obj); - -if (obj) -virtio_gpu_object_unref (&obj); -} -struct virtio_gpu_object * virtio_gpu_alloc_object(struct drm_device *dev, struct virtio_gpu_object_params *params,
@@ -64,16 +56,16 @@ int virtio_gpu_gem_create(struct drm_file *file,if (IS_ERR (obj))return PTR_ERR (obj); - ret =drm_gem_handle_create (file, &obj->gem_base, &handle); + ret =drm_gem_handle_create (file, &obj->base.base, &handle);if (ret) { -drm_gem_object_release (&obj->gem_base); +drm_gem_object_release (&obj->base.base);return ret; } - *obj_p = &obj->gem_base; + *obj_p = &obj->base.base;/* drop reference from allocate - handle holds it now */ -drm_gem_object_put_unlocked (&obj->gem_base); +drm_gem_object_put_unlocked (&obj->base.base); *handle_p = handle;return 0 ;
drivers/gpu/drm/virtio/virtgpu_ioctl.c +4 -15
@@ -27,7 +27,6 @@#include <drm/drmP.h> #include <drm/virtgpu_drm.h> -#include <drm/ttm/ttm_execbuf_util.h> #include <linux/sync_file.h> #include "virtgpu_drv.h"
@@ -259,7 +258,7 @@ static int virtio_gpu_resource_create_ioctl(struct drm_device *dev, void *data,dma_fence_put (&fence->f);if (IS_ERR (qobj))return PTR_ERR (qobj); - obj = &qobj->gem_base; + obj = &qobj->base.base; ret =drm_gem_handle_create (file_priv, obj, &handle);if (ret) {
@@ -286,7 +285,7 @@ static int virtio_gpu_resource_info_ioctl(struct drm_device *dev, void *data, qobj =gem_to_virtio_gpu_obj (gobj); - ri->size = qobj->gem_base.size; + ri->size = qobj->base.base.size; ri->res_handle = qobj->hw_res_handle;drm_gem_object_put_unlocked (gobj);return 0 ;
@@ -299,7 +298,6 @@ static int virtio_gpu_transfer_from_host_ioctl(struct drm_device *dev,struct virtio_gpu_device *vgdev = dev->dev_private;struct virtio_gpu_fpriv *vfpriv = file->driver_priv;struct drm_virtgpu_3d_transfer_from_host *args = data; -struct ttm_operation_ctx ctx = { true, false };struct drm_gem_object *gobj =NULL ;struct virtio_gpu_object *qobj =NULL ;struct virtio_gpu_fence *fence;
@@ -320,10 +318,6 @@ static int virtio_gpu_transfer_from_host_ioctl(struct drm_device *dev,if (ret) goto out; - ret =ttm_bo_validate (&qobj->tbo, &qobj->placement, &ctx); -if (unlikely (ret)) - goto out_unres; -convert_to_hw_box (&box, &args->box); fence =virtio_gpu_fence_alloc (vgdev);
@@ -335,7 +329,7 @@ static int virtio_gpu_transfer_from_host_ioctl(struct drm_device *dev, (vgdev, qobj->hw_res_handle, vfpriv->ctx_id, offset, args->level, &box, fence); -reservation_object_add_excl_fence (qobj->tbo.resv, +reservation_object_add_excl_fence (qobj->base.base.resv, &fence->f);dma_fence_put (&fence->f);
@@ -352,7 +346,6 @@ static int virtio_gpu_transfer_to_host_ioctl(struct drm_device *dev, void *data,struct virtio_gpu_device *vgdev = dev->dev_private;struct virtio_gpu_fpriv *vfpriv = file->driver_priv;struct drm_virtgpu_3d_transfer_to_host *args = data; -struct ttm_operation_ctx ctx = { true, false };struct drm_gem_object *gobj =NULL ;struct virtio_gpu_object *qobj =NULL ;struct virtio_gpu_fence *fence;
@@ -370,10 +363,6 @@ static int virtio_gpu_transfer_to_host_ioctl(struct drm_device *dev, void *data,if (ret) goto out; - ret =ttm_bo_validate (&qobj->tbo, &qobj->placement, &ctx); -if (unlikely (ret)) - goto out_unres; -convert_to_hw_box (&box, &args->box);if (!vgdev->has_virgl_3d) { virtio_gpu_cmd_transfer_to_host_2d
@@ -389,7 +378,7 @@ static int virtio_gpu_transfer_to_host_ioctl(struct drm_device *dev, void *data, (vgdev, qobj, vfpriv ? vfpriv->ctx_id :0 , offset, args->level, &box, fence); -reservation_object_add_excl_fence (qobj->tbo.resv, +reservation_object_add_excl_fence (qobj->base.base.resv, &fence->f);dma_fence_put (&fence->f); }
drivers/gpu/drm/virtio/virtgpu_kms.c +0 -9
@@ -171,12 +171,6 @@ int virtio_gpu_init(struct drm_device *dev) goto err_vbufs; } - ret =virtio_gpu_ttm_init (vgdev); -if (ret) { -DRM_ERROR ("failed to init ttm %d\n" , ret); - goto err_ttm; - } -/* get display info */ virtio_cread(vgdev->vdev, struct virtio_gpu_config, num_scanouts, &num_scanouts);
@@ -208,8 +202,6 @@ int virtio_gpu_init(struct drm_device *dev)return 0 ; err_scanouts: -virtio_gpu_ttm_fini (vgdev); -err_ttm:virtio_gpu_free_vbufs (vgdev); err_vbufs: vgdev->vdev->config->del_vqs (vgdev->vdev);
@@ -240,7 +232,6 @@ void virtio_gpu_deinit(struct drm_device *dev) vgdev->vdev->config->del_vqs (vgdev->vdev);virtio_gpu_modeset_fini (vgdev); -virtio_gpu_ttm_fini (vgdev);virtio_gpu_free_vbufs (vgdev);virtio_gpu_cleanup_cap_cache (vgdev);kfree (vgdev->capsets);
drivers/gpu/drm/virtio/virtgpu_object.c +41 -105
202 lines not on this page · raw message
drivers/gpu/drm/virtio/virtgpu_prime.c +0 -37
@@ -28,46 +28,9 @@* device that might share buffers with virtgpu */ -struct sg_table *virtgpu_gem_prime_get_sg_table (struct drm_gem_object *obj) -{ -struct virtio_gpu_object *bo =gem_to_virtio_gpu_obj (obj); - -if (!bo->tbo.ttm->pages || !bo->tbo.ttm->num_pages) -/* should not happen */ -return ERR_PTR (-EINVAL ); - -return drm_prime_pages_to_sg (bo->tbo.ttm->pages, - bo->tbo.ttm->num_pages); -} -struct drm_gem_object *virtgpu_gem_prime_import_sg_table (struct drm_device *dev,struct dma_buf_attachment *attach,struct sg_table *table) {return ERR_PTR (-ENODEV ); } - -void *virtgpu_gem_prime_vmap (struct drm_gem_object *obj) -{ -struct virtio_gpu_object *bo =gem_to_virtio_gpu_obj (obj); -int ret; - - ret =virtio_gpu_object_kmap (bo); -if (ret) -return NULL ; -return bo->vmap; -} - -void virtgpu_gem_prime_vunmap (struct drm_gem_object *obj,void *vaddr) -{ -virtio_gpu_object_kunmap (gem_to_virtio_gpu_obj (obj)); -} - -int virtgpu_gem_prime_mmap (struct drm_gem_object *obj, -struct vm_area_struct *vma) -{ -struct virtio_gpu_object *bo =gem_to_virtio_gpu_obj (obj); - - bo->gem_base.vma_node.vm_node.start = bo->tbo.vma_node.vm_node.start; -return drm_gem_prime_mmap (obj, vma); -}
drivers/gpu/drm/virtio/virtgpu_ttm.c deleted +0 -304
304 lines not on this page · raw message
drivers/gpu/drm/virtio/virtgpu_vq.c +18 -6
@@ -979,17 +979,21 @@ int virtio_gpu_object_attach(struct virtio_gpu_device *vgdev,bool use_dma_api = !virtio_has_iommu_quirk (vgdev->vdev);struct virtio_gpu_mem_entry *ents;struct scatterlist *sg; -int si, nents; +int si, nents, ret;if (WARN_ON_ONCE (!obj->created))return -EINVAL ; +if (WARN_ON_ONCE (obj->pages)) +return -EINVAL ; -if (!obj->pages) { -int ret; + ret =drm_gem_shmem_pin (&obj->base.base); +if (ret <0 ) +return -EINVAL ; - ret =virtio_gpu_object_get_sg_table (vgdev, obj); -if (ret) -return ret; + obj->pages =drm_gem_shmem_get_sg_table (&obj->base.base); +if (obj->pages ==NULL ) { +drm_gem_shmem_unpin (&obj->base.base); +return -EINVAL ; }if (use_dma_api) {
@@ -1028,6 +1032,9 @@ void virtio_gpu_object_detach(struct virtio_gpu_device *vgdev, {bool use_dma_api = !virtio_has_iommu_quirk (vgdev->vdev); +if (WARN_ON_ONCE (!obj->pages)) +return ; +if (use_dma_api && obj->mapped) {struct virtio_gpu_fence *fence =virtio_gpu_fence_alloc (vgdev);/* detach backing and wait for the host process it ... */
@@ -1043,6 +1050,11 @@ void virtio_gpu_object_detach(struct virtio_gpu_device *vgdev, }else {virtio_gpu_cmd_resource_inval_backing (vgdev, obj->hw_res_handle,NULL ); } + +sg_free_table (obj->pages); + obj->pages =NULL ; + +drm_gem_shmem_unpin (&obj->base.base); } void virtio_gpu_cursor_ping(struct virtio_gpu_device *vgdev,
drivers/gpu/drm/virtio/Kconfig +1 -1
@@ -3,7 +3,7 @@ config DRM_VIRTIO_GPU tristate "Virtio GPU driver" depends on DRM && VIRTIO && MMU select DRM_KMS_HELPER - select DRM_TTM + select DRM_GEM_SHMEM_HELPER help This is the virtual GPU driver for virtio. It can be used with QEMU based VMMs (like KVM or Xen).
drivers/gpu/drm/virtio/Makefile +1 -1
@@ -4,7 +4,7 @@ # Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher. virtio-gpu-y := virtgpu_drv.o virtgpu_kms.o virtgpu_gem.o \ - virtgpu_display.o virtgpu_vq.o virtgpu_ttm.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
Signature · 6 lines
2.18.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v6 11/18] drm/virtio: switch from ttm to gem shmem helpers
Hi Gerd,
Quoted 1 line · Gerd Hoffmann
.gem_prime_import_sg_table =
virtgpu_gem_prime_import_sg_table,
I think that you can drop this entry-point. AFAICT it's only purpose is to return an error - something already handled by core DRM when the function pointer is NULL.
It's not strictly related to this series, so feel free to keep is a separate standalone patch.
-Emil
Re: [PATCH v6 11/18] drm/virtio: switch from ttm to gem shmem helpers
In reply to Gerd HoffmannHi Gerd,
Quoted 1 line · Gerd Hoffmann
.gem_prime_import_sg_table =
virtgpu_gem_prime_import_sg_table,
I think that you can drop this entry-point. AFAICT it's only purpose is to return an error - something already handled by core DRM when the function pointer is NULL.
It's not strictly related to this series, so feel free to keep is a separate standalone patch.
-Emil
Chia-I Wu
reviewerRe: [PATCH v6 11/18] drm/virtio: switch from ttm to gem shmem helpers
In reply to Gerd HoffmannQuoted 189 lines · Gerd Hoffmann
virtio-gpu basically needs a
sg_tablefor the bo, to tell the host where the backing pages for the object are. So the gem shmem helpers are a perfect fit. Somedrm_gem_object_funcsneed thin wrappers to update the host state, but otherwise the helpers handle everything just fine.Once the fencing was sorted the switch was surprisingly easy and for the most part just removing the ttm code.
v4: fix
drm_gem_object_funcsname.Signed-off-by Gerd Hoffmann <[email protected]>Acked-by Daniel Vetter <[email protected]>--- drivers/gpu/drm/virtio/virtgpu_drv.h | 52 +--- drivers/gpu/drm/virtio/virtgpu_drv.c | 20 +- drivers/gpu/drm/virtio/virtgpu_gem.c | 16 +- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 19 +- drivers/gpu/drm/virtio/virtgpu_kms.c | 9 - drivers/gpu/drm/virtio/virtgpu_object.c | 146 ++++-------- drivers/gpu/drm/virtio/virtgpu_prime.c | 37 --- drivers/gpu/drm/virtio/virtgpu_ttm.c | 304 ------------------------ drivers/gpu/drm/virtio/virtgpu_vq.c | 24 +- drivers/gpu/drm/virtio/Kconfig | 2 +- drivers/gpu/drm/virtio/Makefile | 2 +- 11 files changed, 82 insertions(+), 549 deletions(-) delete mode 100644 drivers/gpu/drm/virtio/virtgpu_ttm.cdrivers/gpu/drm/virtio/virtgpu_drv.h +11
-41@@ -33,14 +33,11 @@#include <drm/drmP.h> #include <drm/drm_gem.h> +#include <drm/drm_gem_shmem_helper.h> #include <drm/drm_atomic.h> #include <drm/drm_encoder.h> #include <drm/drm_fb_helper.h> #include <drm/drm_probe_helper.h> -#include <drm/ttm/ttm_bo_api.h> -#include <drm/ttm/ttm_bo_driver.h> -#include <drm/ttm/ttm_placement.h> -#include <drm/ttm/ttm_module.h> #define DRIVER_NAME "virtio_gpu"#define DRIVER_DESC "virtio GPU"@@ -68,21 +65,16 @@ struct virtio_gpu_object_params { };struct virtio_gpu_object { -struct drm_gem_object gem_base; +struct drm_gem_shmem_object base;uint32_t hw_res_handle;struct sg_table *pages;uint32_t mapped; -void *vmap;bool dumb; -struct ttm_place placement_code; -struct ttm_placement placement; -struct ttm_buffer_object tbo; -struct ttm_bo_kmap_obj kmap;bool created; };#define gem_to_virtio_gpu_obj (gobj) \ - container_of((gobj), struct virtio_gpu_object, gem_base) + container_of((gobj), struct virtio_gpu_object, base.base)struct virtio_gpu_object_array {struct ww_acquire_ctx ticket;@@ -153,10 +145,6 @@ struct virtio_gpu_framebuffer {#define to_virtio_gpu_framebuffer (x) \ container_of(x, struct virtio_gpu_framebuffer, base) -struct virtio_gpu_mman { -struct ttm_bo_device bdev; -}; -struct virtio_gpu_queue {struct virtqueue *vq;spinlock_t qlock;@@ -185,8 +173,6 @@ struct virtio_gpu_device {struct virtio_device *vdev; -struct virtio_gpu_mman mman; -struct virtio_gpu_output outputs[VIRTIO_GPU_MAX_SCANOUTS ];uint32_t num_scanouts;@@ -357,11 +343,6 @@ struct drm_plane *virtio_gpu_plane_init(struct virtio_gpu_device *vgdev,enum drm_plane_type type, int index); -/* virtio_gpu_ttm.c */ -int virtio_gpu_ttm_init (struct virtio_gpu_device *vgdev); -void virtio_gpu_ttm_fini (struct virtio_gpu_device *vgdev); -int virtio_gpu_mmap (struct file *filp,struct vm_area_struct *vma); -/* virtio_gpu_fence.c */ bool virtio_fence_signaled (struct dma_fence *f); struct virtio_gpu_fence *virtio_gpu_fence_alloc(@@ -373,58 +354,47 @@ void virtio_gpu_fence_event_process(struct virtio_gpu_device *vdev, u64 last_seq);/* virtio_gpu_object */ +struct drm_gem_object *virtio_gpu_create_object (struct drm_device *dev, +size_t size);int virtio_gpu_object_create (struct virtio_gpu_device *vgdev,struct virtio_gpu_object_params *params,struct virtio_gpu_object **bo_ptr,struct virtio_gpu_fence *fence); -void virtio_gpu_object_kunmap (struct virtio_gpu_object *bo); -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);/* virtgpu_prime.c */ -struct sg_table *virtgpu_gem_prime_get_sg_table (struct drm_gem_object *obj);struct drm_gem_object *virtgpu_gem_prime_import_sg_table (struct drm_device *dev,struct dma_buf_attachment *attach,struct sg_table *sgt); -void *virtgpu_gem_prime_vmap (struct drm_gem_object *obj); -void virtgpu_gem_prime_vunmap (struct drm_gem_object *obj,void *vaddr); -int virtgpu_gem_prime_mmap (struct drm_gem_object *obj, -struct vm_area_struct *vma);static inline struct virtio_gpu_object *virtio_gpu_object_ref (struct virtio_gpu_object *bo) { -ttm_bo_get (&bo->tbo); +drm_gem_object_get (&bo->base.base);return bo; }static inline void virtio_gpu_object_unref (struct virtio_gpu_object **bo) { -struct ttm_buffer_object *tbo; -if ((*bo) ==NULL )return ; - tbo = &((*bo)->tbo); -ttm_bo_put (tbo); +drm_gem_object_put (&(*bo)->base.base); *bo =NULL ; }static inline u64 virtio_gpu_object_mmap_offset (struct virtio_gpu_object *bo) { -return drm_vma_node_offset_addr (&bo->tbo.vma_node); +return drm_vma_node_offset_addr (&bo->base.base.vma_node); }static inline int virtio_gpu_object_reserve (struct virtio_gpu_object *bo) {int r; - r =reservation_object_lock_interruptible (bo->gem_base.resv,NULL ); + r =reservation_object_lock_interruptible (bo->base.base.resv,NULL );if (unlikely (r !=0 )) {if (r != -EINTR ) {struct virtio_gpu_device *qdev = - bo->gem_base.dev->dev_private; + bo->base.base.dev->dev_private;dev_err (qdev->dev,"%p reserve failed\n" , bo); }return r;@@ -434,7 +404,7 @@ static inline int virtio_gpu_object_reserve(struct virtio_gpu_object *bo)static inline void virtio_gpu_object_unreserve (struct virtio_gpu_object *bo) { -reservation_object_unlock (bo->gem_base.resv); +reservation_object_unlock (bo->base.base.resv); }/* virgl debufs */ drivers/gpu/drm/virtio/virtgpu_drv.c +0
-2@@ -182,17 +182,7 @@ MODULE_AUTHOR("Dave Airlie <[email protected]>");MODULE_AUTHOR ("Gerd Hoffmann <[email protected]>" );MODULE_AUTHOR ("Alon Levy" ); -static const struct file_operations virtio_gpu_driver_fops = { - .owner =THIS_MODULE ,
drivers/gpu/drm/virtio/virtgpu_drv.c MODULE_AUTHOR("Dave Airlie <[email protected]>"); · line 185
Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_drv.c +1
-9- .open = drm_open, - .mmap = virtio_gpu_mmap, - .poll = drm_poll, - .read = drm_read, - .unlocked_ioctl = drm_ioctl, - .release = drm_release, - .compat_ioctl = drm_compat_ioctl, - .llseek = noop_llseek, -}; +DEFINE_DRM_GEM_SHMEM_FOPS (virtio_gpu_driver_fops);
We used to have TTM_PL_FLAG_CACHED. With this, it seems mmap now calls drm_gem_mmap_obj indirectly and sets the memory type to writecombine.
Quoted 836 lines
drivers/gpu/drm/virtio/virtgpu_drv.c +1
-7static struct drm_driver driver = { .driver_features =DRIVER_MODESET |DRIVER_GEM |DRIVER_RENDER |DRIVER_ATOMIC ,@@ -207,15 +197,9 @@ static struct drm_driver driver = {#endif .prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle, - .gem_prime_get_sg_table = virtgpu_gem_prime_get_sg_table, .gem_prime_import_sg_table = virtgpu_gem_prime_import_sg_table, - .gem_prime_vmap = virtgpu_gem_prime_vmap, - .gem_prime_vunmap = virtgpu_gem_prime_vunmap, - .gem_prime_mmap = virtgpu_gem_prime_mmap, - .gem_free_object_unlocked = virtio_gpu_gem_free_object, - .gem_open_object = virtio_gpu_gem_object_open, - .gem_close_object = virtio_gpu_gem_object_close, + .gem_create_object = virtio_gpu_create_object, .fops = &virtio_gpu_driver_fops, .ioctls = virtio_gpu_ioctls,drivers/gpu/drm/virtio/virtgpu_gem.c +4
-12@@ -26,14 +26,6 @@#include <drm/drmP.h> #include "virtgpu_drv.h" -void virtio_gpu_gem_free_object (struct drm_gem_object *gem_obj) -{ -struct virtio_gpu_object *obj =gem_to_virtio_gpu_obj (gem_obj); - -if (obj) -virtio_gpu_object_unref (&obj); -} -struct virtio_gpu_object * virtio_gpu_alloc_object(struct drm_device *dev, struct virtio_gpu_object_params *params,@@ -64,16 +56,16 @@ int virtio_gpu_gem_create(struct drm_file *file,if (IS_ERR (obj))return PTR_ERR (obj); - ret =drm_gem_handle_create (file, &obj->gem_base, &handle); + ret =drm_gem_handle_create (file, &obj->base.base, &handle);if (ret) { -drm_gem_object_release (&obj->gem_base); +drm_gem_object_release (&obj->base.base);return ret; } - *obj_p = &obj->gem_base; + *obj_p = &obj->base.base;/* drop reference from allocate - handle holds it now */ -drm_gem_object_put_unlocked (&obj->gem_base); +drm_gem_object_put_unlocked (&obj->base.base); *handle_p = handle;return 0 ;drivers/gpu/drm/virtio/virtgpu_ioctl.c +4
-15@@ -27,7 +27,6 @@#include <drm/drmP.h> #include <drm/virtgpu_drm.h> -#include <drm/ttm/ttm_execbuf_util.h> #include <linux/sync_file.h> #include "virtgpu_drv.h" @@ -259,7 +258,7 @@ static int virtio_gpu_resource_create_ioctl(struct drm_device *dev, void *data,dma_fence_put (&fence->f);if (IS_ERR (qobj))return PTR_ERR (qobj); - obj = &qobj->gem_base; + obj = &qobj->base.base; ret =drm_gem_handle_create (file_priv, obj, &handle);if (ret) {@@ -286,7 +285,7 @@ static int virtio_gpu_resource_info_ioctl(struct drm_device *dev, void *data, qobj =gem_to_virtio_gpu_obj (gobj); - ri->size = qobj->gem_base.size; + ri->size = qobj->base.base.size; ri->res_handle = qobj->hw_res_handle;drm_gem_object_put_unlocked (gobj);return 0 ;@@ -299,7 +298,6 @@ static int virtio_gpu_transfer_from_host_ioctl(struct drm_device *dev,struct virtio_gpu_device *vgdev = dev->dev_private;struct virtio_gpu_fpriv *vfpriv = file->driver_priv;struct drm_virtgpu_3d_transfer_from_host *args = data; -struct ttm_operation_ctx ctx = { true, false };struct drm_gem_object *gobj =NULL ;struct virtio_gpu_object *qobj =NULL ;struct virtio_gpu_fence *fence;@@ -320,10 +318,6 @@ static int virtio_gpu_transfer_from_host_ioctl(struct drm_device *dev,if (ret) goto out; - ret =ttm_bo_validate (&qobj->tbo, &qobj->placement, &ctx); -if (unlikely (ret)) - goto out_unres; -convert_to_hw_box (&box, &args->box); fence =virtio_gpu_fence_alloc (vgdev);@@ -335,7 +329,7 @@ static int virtio_gpu_transfer_from_host_ioctl(struct drm_device *dev, (vgdev, qobj->hw_res_handle, vfpriv->ctx_id, offset, args->level, &box, fence); -reservation_object_add_excl_fence (qobj->tbo.resv, +reservation_object_add_excl_fence (qobj->base.base.resv, &fence->f);dma_fence_put (&fence->f);@@ -352,7 +346,6 @@ static int virtio_gpu_transfer_to_host_ioctl(struct drm_device *dev, void *data,struct virtio_gpu_device *vgdev = dev->dev_private;struct virtio_gpu_fpriv *vfpriv = file->driver_priv;struct drm_virtgpu_3d_transfer_to_host *args = data; -struct ttm_operation_ctx ctx = { true, false };struct drm_gem_object *gobj =NULL ;struct virtio_gpu_object *qobj =NULL ;struct virtio_gpu_fence *fence;@@ -370,10 +363,6 @@ static int virtio_gpu_transfer_to_host_ioctl(struct drm_device *dev, void *data,if (ret) goto out; - ret =ttm_bo_validate (&qobj->tbo, &qobj->placement, &ctx); -if (unlikely (ret)) - goto out_unres; -convert_to_hw_box (&box, &args->box);if (!vgdev->has_virgl_3d) { virtio_gpu_cmd_transfer_to_host_2d@@ -389,7 +378,7 @@ static int virtio_gpu_transfer_to_host_ioctl(struct drm_device *dev, void *data, (vgdev, qobj, vfpriv ? vfpriv->ctx_id :0 , offset, args->level, &box, fence); -reservation_object_add_excl_fence (qobj->tbo.resv, +reservation_object_add_excl_fence (qobj->base.base.resv, &fence->f);dma_fence_put (&fence->f); }drivers/gpu/drm/virtio/virtgpu_kms.c +0
-9@@ -171,12 +171,6 @@ int virtio_gpu_init(struct drm_device *dev) goto err_vbufs; } - ret =virtio_gpu_ttm_init (vgdev); -if (ret) { -DRM_ERROR ("failed to init ttm %d\n" , ret); - goto err_ttm; - } -/* get display info */ virtio_cread(vgdev->vdev, struct virtio_gpu_config, num_scanouts, &num_scanouts);@@ -208,8 +202,6 @@ int virtio_gpu_init(struct drm_device *dev)return 0 ; err_scanouts: -virtio_gpu_ttm_fini (vgdev); -err_ttm:virtio_gpu_free_vbufs (vgdev); err_vbufs: vgdev->vdev->config->del_vqs (vgdev->vdev);@@ -240,7 +232,6 @@ void virtio_gpu_deinit(struct drm_device *dev) vgdev->vdev->config->del_vqs (vgdev->vdev);virtio_gpu_modeset_fini (vgdev); -virtio_gpu_ttm_fini (vgdev);virtio_gpu_free_vbufs (vgdev);virtio_gpu_cleanup_cap_cache (vgdev);kfree (vgdev->capsets);drivers/gpu/drm/virtio/virtgpu_object.c +41
-105@@ -23,8 +23,6 @@* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include <drm/ttm/ttm_execbuf_util.h> -#include "virtgpu_drv.h" static int virtio_gpu_resource_id_get(struct virtio_gpu_device *vgdev,@@ -57,39 +55,45 @@ static void virtio_gpu_resource_id_put(struct virtio_gpu_device *vgdev, uint32_t#endif } -static void virtio_gpu_ttm_bo_destroy (struct ttm_buffer_object *tbo) +static void virtio_gpu_free_object (struct drm_gem_object *obj) { -struct virtio_gpu_object *bo; -struct virtio_gpu_device *vgdev; - - bo = container_of(tbo, struct virtio_gpu_object, tbo); - vgdev = (struct virtio_gpu_device *)bo->gem_base.dev->dev_private; +struct virtio_gpu_object *bo =gem_to_virtio_gpu_obj (obj); +struct virtio_gpu_device *vgdev = bo->base.base.dev->dev_private; +if (bo->pages) +virtio_gpu_object_detach (vgdev, bo);if (bo->created)virtio_gpu_cmd_unref_resource (vgdev, bo->hw_res_handle); -if (bo->pages) -virtio_gpu_object_free_sg_table (bo); -if (bo->vmap) -virtio_gpu_object_kunmap (bo); -drm_gem_object_release (&bo->gem_base);virtio_gpu_resource_id_put (vgdev, bo->hw_res_handle); -kfree (bo); + +drm_gem_shmem_free_object (obj); } -static void virtio_gpu_init_ttm_placement (struct virtio_gpu_object *vgbo) +static const struct drm_gem_object_funcs virtio_gpu_gem_funcs = { + .free = virtio_gpu_free_object, + .open = virtio_gpu_gem_object_open, + .close = virtio_gpu_gem_object_close, + + .print_info = drm_gem_shmem_print_info, + .pin = drm_gem_shmem_pin, + .unpin = drm_gem_shmem_unpin, + .get_sg_table = drm_gem_shmem_get_sg_table, + .vmap = drm_gem_shmem_vmap, + .vunmap = drm_gem_shmem_vunmap, + .vm_ops = &drm_gem_shmem_vm_ops, +}; + +struct drm_gem_object *virtio_gpu_create_object (struct drm_device *dev, +size_t size) { -u32 c =1 ; +struct virtio_gpu_object *bo; - vgbo->placement.placement = &vgbo->placement_code; - vgbo->placement.busy_placement = &vgbo->placement_code; - vgbo->placement_code.fpfn =0 ; - vgbo->placement_code.lpfn =0 ; - vgbo->placement_code.flags = -TTM_PL_MASK_CACHING |TTM_PL_FLAG_TT | -TTM_PL_FLAG_NO_EVICT ; - vgbo->placement.num_placement = c; - vgbo->placement.num_busy_placement = c; + bo =kzalloc (sizeof (*bo),GFP_KERNEL ); +if (!bo) +return NULL ; + bo->base.base.funcs = &virtio_gpu_gem_funcs; +return &bo->base.base; } int virtio_gpu_object_create(struct virtio_gpu_device *vgdev,@@ -98,27 +102,22 @@ int virtio_gpu_object_create(struct virtio_gpu_device *vgdev, struct virtio_gpu_fence *fence) {struct virtio_gpu_object_array *objs =NULL ; +struct drm_gem_shmem_object *shmem_obj;struct virtio_gpu_object *bo; -size_t acc_size;int ret; *bo_ptr =NULL ; - acc_size =ttm_bo_dma_acc_size (&vgdev->mman.bdev, params->size, -sizeof (struct virtio_gpu_object )); + params->size =roundup (params->size,PAGE_SIZE ); + shmem_obj =drm_gem_shmem_create (vgdev->ddev, params->size); +if (IS_ERR (shmem_obj)) +return PTR_ERR (shmem_obj); + bo =gem_to_virtio_gpu_obj (&shmem_obj->base); - bo =kzalloc (sizeof (struct virtio_gpu_object ),GFP_KERNEL ); -if (bo ==NULL ) -return -ENOMEM ; ret =virtio_gpu_resource_id_get (vgdev, &bo->hw_res_handle);if (ret <0 ) goto err_free_gem; - params->size =roundup (params->size,PAGE_SIZE ); - ret =drm_gem_object_init (vgdev->ddev, &bo->gem_base, params->size); -if (ret !=0 ) - goto err_put_id; - bo->dumb = params->dumb;if (fence) {@@ -126,7 +125,7 @@ int virtio_gpu_object_create(struct virtio_gpu_device *vgdev, objs =virtio_gpu_array_alloc (1 );if (!objs) goto err_put_id; -virtio_gpu_array_add_obj (objs, &bo->gem_base); +virtio_gpu_array_add_obj (objs, &bo->base.base); ret =virtio_gpu_array_lock_resv (objs);if (ret !=0 )@@ -141,15 +140,11 @@ int virtio_gpu_object_create(struct virtio_gpu_device *vgdev, objs, fence); } -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 , - bo->gem_base.resv, - &virtio_gpu_ttm_bo_destroy); -/* ttm_bo_init failure will call the destroy */ -if (ret !=0 ) + ret =virtio_gpu_object_attach (vgdev, bo,NULL ); +if (ret !=0 ) { +virtio_gpu_free_object (&shmem_obj->base);return ret; + } *bo_ptr = bo;return 0 ;@@ -159,65 +154,6 @@ int virtio_gpu_object_create(struct virtio_gpu_device *vgdev, err_put_id:virtio_gpu_resource_id_put (vgdev, bo->hw_res_handle); err_free_gem: -kfree (bo); +drm_gem_shmem_free_object (&shmem_obj->base);return ret; } - -void virtio_gpu_object_kunmap (struct virtio_gpu_object *bo) -{ - bo->vmap =NULL ; -ttm_bo_kunmap (&bo->kmap); -} - -int virtio_gpu_object_kmap (struct virtio_gpu_object *bo) -{ -bool is_iomem; -int r; - -WARN_ON (bo->vmap); - - r =ttm_bo_kmap (&bo->tbo,0 , bo->tbo.num_pages, &bo->kmap); -if (r) -return r; - bo->vmap =ttm_kmap_obj_virtual (&bo->kmap, &is_iomem); -return 0 ; -} - -int virtio_gpu_object_get_sg_table (struct virtio_gpu_device *qdev, -struct virtio_gpu_object *bo) -{ -int ret; -struct page **pages = bo->tbo.ttm->pages; -int nr_pages = bo->tbo.num_pages; -struct ttm_operation_ctx ctx = { - .interruptible = false, - .no_wait_gpu = false - }; - -/* wtf swapping */ -if (bo->pages) -return 0 ; - -if (bo->tbo.ttm->state == tt_unpopulated) - bo->tbo.ttm->bdev->driver->ttm_tt_populate (bo->tbo.ttm, &ctx); - bo->pages =kmalloc (sizeof (struct sg_table ),GFP_KERNEL ); -if (!bo->pages) - goto out; - - ret =sg_alloc_table_from_pages (bo->pages, pages, nr_pages,0 , - nr_pages <<PAGE_SHIFT ,GFP_KERNEL ); -if (ret) - goto out; -return 0 ; -out: -kfree (bo->pages); - bo->pages =NULL ; -return -ENOMEM ; -} - -void virtio_gpu_object_free_sg_table (struct virtio_gpu_object *bo) -{ -sg_free_table (bo->pages); -kfree (bo->pages); - bo->pages =NULL ; -}drivers/gpu/drm/virtio/virtgpu_prime.c +0
-37@@ -28,46 +28,9 @@* device that might share buffers with virtgpu */ -struct sg_table *virtgpu_gem_prime_get_sg_table (struct drm_gem_object *obj) -{ -struct virtio_gpu_object *bo =gem_to_virtio_gpu_obj (obj); - -if (!bo->tbo.ttm->pages || !bo->tbo.ttm->num_pages) -/* should not happen */ -return ERR_PTR (-EINVAL ); - -return drm_prime_pages_to_sg (bo->tbo.ttm->pages, - bo->tbo.ttm->num_pages); -} -struct drm_gem_object *virtgpu_gem_prime_import_sg_table (struct drm_device *dev,struct dma_buf_attachment *attach,struct sg_table *table) {return ERR_PTR (-ENODEV ); } - -void *virtgpu_gem_prime_vmap (struct drm_gem_object *obj) -{ -struct virtio_gpu_object *bo =gem_to_virtio_gpu_obj (obj); -int ret; - - ret =virtio_gpu_object_kmap (bo); -if (ret) -return NULL ; -return bo->vmap; -} - -void virtgpu_gem_prime_vunmap (struct drm_gem_object *obj,void *vaddr) -{ -virtio_gpu_object_kunmap (gem_to_virtio_gpu_obj (obj)); -} - -int virtgpu_gem_prime_mmap (struct drm_gem_object *obj, -struct vm_area_struct *vma) -{ -struct virtio_gpu_object *bo =gem_to_virtio_gpu_obj (obj); - - bo->gem_base.vma_node.vm_node.start = bo->tbo.vma_node.vm_node.start; -return drm_gem_prime_mmap (obj, vma); -}drivers/gpu/drm/virtio/virtgpu_ttm.c deleted +0
-304@@ -1,304 +0,0 @@ -/* -* Copyright (C) 2015 Red Hat, Inc. -* All Rights Reserved. -* -* Authors: -* Dave Airlie -* Alon Levy -* -* Permission is hereby granted, free of charge, to any person obtaining a -* copy of this software and associated documentation files (the "Software"), -* to deal in the Software without restriction, including without limitation -* the rights to use, copy, modify, merge, publish, distribute, sublicense, -* and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in -* all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR -* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -* OTHER DEALINGS IN THE SOFTWARE. -*/ - -#include <drm/ttm/ttm_bo_api.h> -#include <drm/ttm/ttm_bo_driver.h> -#include <drm/ttm/ttm_placement.h> -#include <drm/ttm/ttm_page_alloc.h> -#include <drm/ttm/ttm_module.h> -#include <drm/drmP.h> -#include <drm/drm.h> -#include <drm/virtgpu_drm.h> -#include "virtgpu_drv.h" - -#include <linux/delay.h> - -static struct -virtio_gpu_device *virtio_gpu_get_vgdev (struct ttm_bo_device *bdev) -{ -struct virtio_gpu_mman *mman; -struct virtio_gpu_device *vgdev; - - mman = container_of(bdev, struct virtio_gpu_mman, bdev); - vgdev = container_of(mman, struct virtio_gpu_device, mman); -return vgdev; -} - -int virtio_gpu_mmap (struct file *filp,struct vm_area_struct *vma) -{ -struct drm_file *file_priv; -struct virtio_gpu_device *vgdev; -int r; - - file_priv = filp->private_data; - vgdev = file_priv->minor->dev->dev_private; -if (vgdev ==NULL ) { -DRM_ERROR ( -"filp->private_data->minor->dev->dev_private == NULL\n" ); -return -EINVAL ; - } - r =ttm_bo_mmap (filp, vma, &vgdev->mman.bdev); - -return r; -} - -static int virtio_gpu_invalidate_caches (struct ttm_bo_device *bdev, -uint32_t flags) -{ -return 0 ; -} - -static int ttm_bo_man_get_node (struct ttm_mem_type_manager *man, -struct ttm_buffer_object *bo, -const struct ttm_place *place, -struct ttm_mem_reg *mem) -{ - mem->mm_node = (void *)1 ; -return 0 ; -} - -static void ttm_bo_man_put_node (struct ttm_mem_type_manager *man, -struct ttm_mem_reg *mem) -{ - mem->mm_node = (void *)NULL ; -} - -static int ttm_bo_man_init (struct ttm_mem_type_manager *man, -unsigned long p_size) -{ -return 0 ; -} - -static int ttm_bo_man_takedown (struct ttm_mem_type_manager *man) -{ -return 0 ; -} - -static void ttm_bo_man_debug (struct ttm_mem_type_manager *man, -struct drm_printer *printer) -{ -} - -static const struct ttm_mem_type_manager_func virtio_gpu_bo_manager_func = { - .init = ttm_bo_man_init, - .takedown = ttm_bo_man_takedown, - .get_node = ttm_bo_man_get_node, - .put_node = ttm_bo_man_put_node, - .debug = ttm_bo_man_debug -}; - -static int virtio_gpu_init_mem_type (struct ttm_bo_device *bdev,uint32_t type, -struct ttm_mem_type_manager *man) -{ -switch (type) { -case TTM_PL_SYSTEM : -/* System memory */ - man->flags =TTM_MEMTYPE_FLAG_MAPPABLE ; - man->available_caching =TTM_PL_MASK_CACHING ; - man->default_caching =TTM_PL_FLAG_CACHED ; -break ; -case TTM_PL_TT : - man->func = &virtio_gpu_bo_manager_func; - man->flags =TTM_MEMTYPE_FLAG_MAPPABLE ; - man->available_caching =TTM_PL_MASK_CACHING ; - man->default_caching =TTM_PL_FLAG_CACHED ; -break ; -default : -DRM_ERROR ("Unsupported memory type %u\n" , (unsigned int )type); -return -EINVAL ; - } -return 0 ; -} - -static void virtio_gpu_evict_flags (struct ttm_buffer_object *bo, -struct ttm_placement *placement) -{ -static const struct ttm_place placements = { - .fpfn =0 , - .lpfn =0 , - .flags =TTM_PL_MASK_CACHING |TTM_PL_FLAG_SYSTEM , - }; - - placement->placement = &placements; - placement->busy_placement = &placements; - placement->num_placement =1 ; - placement->num_busy_placement =1 ; -} - -static int virtio_gpu_verify_access (struct ttm_buffer_object *bo, -struct file *filp) -{ -return 0 ; -} - -static int virtio_gpu_ttm_io_mem_reserve (struct ttm_bo_device *bdev, -struct ttm_mem_reg *mem) -{ -struct ttm_mem_type_manager *man = &bdev->man[mem->mem_type]; - - mem->bus.addr =NULL ; - mem->bus.offset =0 ; - mem->bus.size = mem->num_pages <<PAGE_SHIFT ; - mem->bus.base =0 ; - mem->bus.is_iomem = false; -if (!(man->flags &TTM_MEMTYPE_FLAG_MAPPABLE )) -return -EINVAL ; -switch (mem->mem_type) { -case TTM_PL_SYSTEM : -case TTM_PL_TT : -/* system memory */ -return 0 ; -default : -return -EINVAL ; - } -return 0 ; -} - -static void virtio_gpu_ttm_io_mem_free (struct ttm_bo_device *bdev, -struct ttm_mem_reg *mem) -{ -} - -/* -* TTM backend functions. -*/ -struct virtio_gpu_ttm_tt { -struct ttm_dma_tt ttm; -struct virtio_gpu_object *obj; -}; - -static int virtio_gpu_ttm_tt_bind (struct ttm_tt *ttm, -struct ttm_mem_reg *bo_mem) -{ -struct virtio_gpu_ttm_tt *gtt = - container_of(ttm, struct virtio_gpu_ttm_tt, ttm.ttm); -struct virtio_gpu_device *vgdev = -virtio_gpu_get_vgdev (gtt->obj->tbo.bdev); - -virtio_gpu_object_attach (vgdev, gtt->obj,NULL ); -return 0 ; -} - -static int virtio_gpu_ttm_tt_unbind (struct ttm_tt *ttm) -{ -struct virtio_gpu_ttm_tt *gtt = - container_of(ttm, struct virtio_gpu_ttm_tt, ttm.ttm); -struct virtio_gpu_device *vgdev = -virtio_gpu_get_vgdev (gtt->obj->tbo.bdev); - -virtio_gpu_object_detach (vgdev, gtt->obj); -return 0 ; -} - -static void virtio_gpu_ttm_tt_destroy (struct ttm_tt *ttm) -{ -struct virtio_gpu_ttm_tt *gtt = - container_of(ttm, struct virtio_gpu_ttm_tt, ttm.ttm); - -ttm_dma_tt_fini (>t->ttm); -kfree (gtt); -} - -static struct ttm_backend_func virtio_gpu_tt_func = { - .bind = &virtio_gpu_ttm_tt_bind, - .unbind = &virtio_gpu_ttm_tt_unbind, - .destroy = &virtio_gpu_ttm_tt_destroy, -}; - -static struct ttm_tt *virtio_gpu_ttm_tt_create (struct ttm_buffer_object *bo, -uint32_t page_flags) -{ -struct virtio_gpu_device *vgdev; -struct virtio_gpu_ttm_tt *gtt; - - vgdev =virtio_gpu_get_vgdev (bo->bdev); - gtt =kzalloc (sizeof (struct virtio_gpu_ttm_tt ),GFP_KERNEL ); -if (gtt ==NULL ) -return NULL ; - gtt->ttm.ttm.func = &virtio_gpu_tt_func; - gtt->obj = container_of(bo, struct virtio_gpu_object, tbo); -if (ttm_dma_tt_init (>t->ttm, bo, page_flags)) { -kfree (gtt); -return NULL ; - } -return >t->ttm.ttm; -} - -static void virtio_gpu_bo_swap_notify (struct ttm_buffer_object *tbo) -{ -struct virtio_gpu_object *bo; - - bo = container_of(tbo, struct virtio_gpu_object, tbo); - -if (bo->pages) -virtio_gpu_object_free_sg_table (bo); -} - -static struct ttm_bo_driver virtio_gpu_bo_driver = { - .ttm_tt_create = &virtio_gpu_ttm_tt_create, - .invalidate_caches = &virtio_gpu_invalidate_caches, - .init_mem_type = &virtio_gpu_init_mem_type, - .eviction_valuable = ttm_bo_eviction_valuable, - .evict_flags = &virtio_gpu_evict_flags, - .verify_access = &virtio_gpu_verify_access, - .io_mem_reserve = &virtio_gpu_ttm_io_mem_reserve, - .io_mem_free = &virtio_gpu_ttm_io_mem_free, - .swap_notify = &virtio_gpu_bo_swap_notify, -}; - -int virtio_gpu_ttm_init (struct virtio_gpu_device *vgdev) -{ -int r; - -/* No others user of address space so set it to 0 */ - r =ttm_bo_device_init (&vgdev->mman.bdev, - &virtio_gpu_bo_driver, - vgdev->ddev->anon_inode->i_mapping, - false); -if (r) { -DRM_ERROR ("failed initializing buffer object driver(%d).\n" , r); - goto err_dev_init; - } - - r =ttm_bo_init_mm (&vgdev->mman.bdev,TTM_PL_TT ,0 ); -if (r) { -DRM_ERROR ("Failed initializing GTT heap.\n" ); - goto err_mm_init; - } -return 0 ; - -err_mm_init: -ttm_bo_device_release (&vgdev->mman.bdev); -err_dev_init: -return r; -} - -void virtio_gpu_ttm_fini (struct virtio_gpu_device *vgdev) -{ -ttm_bo_device_release (&vgdev->mman.bdev); -DRM_INFO ("virtio_gpu: ttm finalized\n" ); -}drivers/gpu/drm/virtio/virtgpu_vq.c +18
-6@@ -979,17 +979,21 @@ int virtio_gpu_object_attach(struct virtio_gpu_device *vgdev,bool use_dma_api = !virtio_has_iommu_quirk (vgdev->vdev);struct virtio_gpu_mem_entry *ents;struct scatterlist *sg; -int si, nents; +int si, nents, ret;if (WARN_ON_ONCE (!obj->created))return -EINVAL ; +if (WARN_ON_ONCE (obj->pages)) +return -EINVAL ; -if (!obj->pages) { -int ret; + ret =drm_gem_shmem_pin (&obj->base.base); +if (ret <0 ) +return -EINVAL ; - ret =virtio_gpu_object_get_sg_table (vgdev, obj); -if (ret) -return ret; + obj->pages =drm_gem_shmem_get_sg_table (&obj->base.base); +if (obj->pages ==NULL ) { +drm_gem_shmem_unpin (&obj->base.base); +return -EINVAL ; }if (use_dma_api) {@@ -1028,6 +1032,9 @@ void virtio_gpu_object_detach(struct virtio_gpu_device *vgdev, {bool use_dma_api = !virtio_has_iommu_quirk (vgdev->vdev); +if (WARN_ON_ONCE (!obj->pages)) +return ; +if (use_dma_api && obj->mapped) {struct virtio_gpu_fence *fence =virtio_gpu_fence_alloc (vgdev);/* detach backing and wait for the host process it ... */ @@ -1043,6 +1050,11 @@ void virtio_gpu_object_detach(struct virtio_gpu_device *vgdev, }else {virtio_gpu_cmd_resource_inval_backing (vgdev, obj->hw_res_handle,NULL ); } + +sg_free_table (obj->pages); + obj->pages =NULL ; + +drm_gem_shmem_unpin (&obj->base.base); } void virtio_gpu_cursor_ping(struct virtio_gpu_device *vgdev,drivers/gpu/drm/virtio/Kconfig +1
-1@@ -3,7 +3,7 @@ config DRM_VIRTIO_GPU tristate "Virtio GPU driver" depends on DRM && VIRTIO && MMU select DRM_KMS_HELPER - select DRM_TTM + select DRM_GEM_SHMEM_HELPER help This is the virtual GPU driver for virtio. It can be used with QEMU based VMMs (like KVM or Xen).drivers/gpu/drm/virtio/Makefile +1
-2@@ -4,7 +4,7 @@ # Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher. virtio-gpu-y := virtgpu_drv.o virtgpu_kms.o virtgpu_gem.o \ - virtgpu_display.o virtgpu_vq.o virtgpu_ttm.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 --2.18.1
Chia-I Wu
reviewerRe: [PATCH v6 11/18] drm/virtio: switch from ttm to gem shmem helpers
In reply to Gerd HoffmannQuoted 189 lines · Gerd Hoffmann
virtio-gpu basically needs a
sg_tablefor the bo, to tell the host where the backing pages for the object are. So the gem shmem helpers are a perfect fit. Somedrm_gem_object_funcsneed thin wrappers to update the host state, but otherwise the helpers handle everything just fine.Once the fencing was sorted the switch was surprisingly easy and for the most part just removing the ttm code.
v4: fix
drm_gem_object_funcsname.Signed-off-by Gerd Hoffmann <[email protected]>Acked-by Daniel Vetter <[email protected]>--- drivers/gpu/drm/virtio/virtgpu_drv.h | 52 +--- drivers/gpu/drm/virtio/virtgpu_drv.c | 20 +- drivers/gpu/drm/virtio/virtgpu_gem.c | 16 +- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 19 +- drivers/gpu/drm/virtio/virtgpu_kms.c | 9 - drivers/gpu/drm/virtio/virtgpu_object.c | 146 ++++-------- drivers/gpu/drm/virtio/virtgpu_prime.c | 37 --- drivers/gpu/drm/virtio/virtgpu_ttm.c | 304 ------------------------ drivers/gpu/drm/virtio/virtgpu_vq.c | 24 +- drivers/gpu/drm/virtio/Kconfig | 2 +- drivers/gpu/drm/virtio/Makefile | 2 +- 11 files changed, 82 insertions(+), 549 deletions(-) delete mode 100644 drivers/gpu/drm/virtio/virtgpu_ttm.cdrivers/gpu/drm/virtio/virtgpu_drv.h +11
-41@@ -33,14 +33,11 @@#include <drm/drmP.h> #include <drm/drm_gem.h> +#include <drm/drm_gem_shmem_helper.h> #include <drm/drm_atomic.h> #include <drm/drm_encoder.h> #include <drm/drm_fb_helper.h> #include <drm/drm_probe_helper.h> -#include <drm/ttm/ttm_bo_api.h> -#include <drm/ttm/ttm_bo_driver.h> -#include <drm/ttm/ttm_placement.h> -#include <drm/ttm/ttm_module.h> #define DRIVER_NAME "virtio_gpu"#define DRIVER_DESC "virtio GPU"@@ -68,21 +65,16 @@ struct virtio_gpu_object_params { };struct virtio_gpu_object { -struct drm_gem_object gem_base; +struct drm_gem_shmem_object base;uint32_t hw_res_handle;struct sg_table *pages;uint32_t mapped; -void *vmap;bool dumb; -struct ttm_place placement_code; -struct ttm_placement placement; -struct ttm_buffer_object tbo; -struct ttm_bo_kmap_obj kmap;bool created; };#define gem_to_virtio_gpu_obj (gobj) \ - container_of((gobj), struct virtio_gpu_object, gem_base) + container_of((gobj), struct virtio_gpu_object, base.base)struct virtio_gpu_object_array {struct ww_acquire_ctx ticket;@@ -153,10 +145,6 @@ struct virtio_gpu_framebuffer {#define to_virtio_gpu_framebuffer (x) \ container_of(x, struct virtio_gpu_framebuffer, base) -struct virtio_gpu_mman { -struct ttm_bo_device bdev; -}; -struct virtio_gpu_queue {struct virtqueue *vq;spinlock_t qlock;@@ -185,8 +173,6 @@ struct virtio_gpu_device {struct virtio_device *vdev; -struct virtio_gpu_mman mman; -struct virtio_gpu_output outputs[VIRTIO_GPU_MAX_SCANOUTS ];uint32_t num_scanouts;@@ -357,11 +343,6 @@ struct drm_plane *virtio_gpu_plane_init(struct virtio_gpu_device *vgdev,enum drm_plane_type type, int index); -/* virtio_gpu_ttm.c */ -int virtio_gpu_ttm_init (struct virtio_gpu_device *vgdev); -void virtio_gpu_ttm_fini (struct virtio_gpu_device *vgdev); -int virtio_gpu_mmap (struct file *filp,struct vm_area_struct *vma); -/* virtio_gpu_fence.c */ bool virtio_fence_signaled (struct dma_fence *f); struct virtio_gpu_fence *virtio_gpu_fence_alloc(@@ -373,58 +354,47 @@ void virtio_gpu_fence_event_process(struct virtio_gpu_device *vdev, u64 last_seq);/* virtio_gpu_object */ +struct drm_gem_object *virtio_gpu_create_object (struct drm_device *dev, +size_t size);int virtio_gpu_object_create (struct virtio_gpu_device *vgdev,struct virtio_gpu_object_params *params,struct virtio_gpu_object **bo_ptr,struct virtio_gpu_fence *fence); -void virtio_gpu_object_kunmap (struct virtio_gpu_object *bo); -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);/* virtgpu_prime.c */ -struct sg_table *virtgpu_gem_prime_get_sg_table (struct drm_gem_object *obj);struct drm_gem_object *virtgpu_gem_prime_import_sg_table (struct drm_device *dev,struct dma_buf_attachment *attach,struct sg_table *sgt); -void *virtgpu_gem_prime_vmap (struct drm_gem_object *obj); -void virtgpu_gem_prime_vunmap (struct drm_gem_object *obj,void *vaddr); -int virtgpu_gem_prime_mmap (struct drm_gem_object *obj, -struct vm_area_struct *vma);static inline struct virtio_gpu_object *virtio_gpu_object_ref (struct virtio_gpu_object *bo) { -ttm_bo_get (&bo->tbo); +drm_gem_object_get (&bo->base.base);return bo; }static inline void virtio_gpu_object_unref (struct virtio_gpu_object **bo) { -struct ttm_buffer_object *tbo; -if ((*bo) ==NULL )return ; - tbo = &((*bo)->tbo); -ttm_bo_put (tbo); +drm_gem_object_put (&(*bo)->base.base); *bo =NULL ; }static inline u64 virtio_gpu_object_mmap_offset (struct virtio_gpu_object *bo) { -return drm_vma_node_offset_addr (&bo->tbo.vma_node); +return drm_vma_node_offset_addr (&bo->base.base.vma_node); }static inline int virtio_gpu_object_reserve (struct virtio_gpu_object *bo) {int r; - r =reservation_object_lock_interruptible (bo->gem_base.resv,NULL ); + r =reservation_object_lock_interruptible (bo->base.base.resv,NULL );if (unlikely (r !=0 )) {if (r != -EINTR ) {struct virtio_gpu_device *qdev = - bo->gem_base.dev->dev_private; + bo->base.base.dev->dev_private;dev_err (qdev->dev,"%p reserve failed\n" , bo); }return r;@@ -434,7 +404,7 @@ static inline int virtio_gpu_object_reserve(struct virtio_gpu_object *bo)static inline void virtio_gpu_object_unreserve (struct virtio_gpu_object *bo) { -reservation_object_unlock (bo->gem_base.resv); +reservation_object_unlock (bo->base.base.resv); }/* virgl debufs */ drivers/gpu/drm/virtio/virtgpu_drv.c +0
-2@@ -182,17 +182,7 @@ MODULE_AUTHOR("Dave Airlie <[email protected]>");MODULE_AUTHOR ("Gerd Hoffmann <[email protected]>" );MODULE_AUTHOR ("Alon Levy" ); -static const struct file_operations virtio_gpu_driver_fops = { - .owner =THIS_MODULE ,
drivers/gpu/drm/virtio/virtgpu_drv.c MODULE_AUTHOR("Dave Airlie <[email protected]>"); · line 185
Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_drv.c +1
-9- .open = drm_open, - .mmap = virtio_gpu_mmap, - .poll = drm_poll, - .read = drm_read, - .unlocked_ioctl = drm_ioctl, - .release = drm_release, - .compat_ioctl = drm_compat_ioctl, - .llseek = noop_llseek, -}; +DEFINE_DRM_GEM_SHMEM_FOPS (virtio_gpu_driver_fops);
We used to have TTM_PL_FLAG_CACHED. With this, it seems mmap now calls drm_gem_mmap_obj indirectly and sets the memory type to writecombine.
Quoted 836 lines
drivers/gpu/drm/virtio/virtgpu_drv.c +1
-7static struct drm_driver driver = { .driver_features =DRIVER_MODESET |DRIVER_GEM |DRIVER_RENDER |DRIVER_ATOMIC ,@@ -207,15 +197,9 @@ static struct drm_driver driver = {#endif .prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle, - .gem_prime_get_sg_table = virtgpu_gem_prime_get_sg_table, .gem_prime_import_sg_table = virtgpu_gem_prime_import_sg_table, - .gem_prime_vmap = virtgpu_gem_prime_vmap, - .gem_prime_vunmap = virtgpu_gem_prime_vunmap, - .gem_prime_mmap = virtgpu_gem_prime_mmap, - .gem_free_object_unlocked = virtio_gpu_gem_free_object, - .gem_open_object = virtio_gpu_gem_object_open, - .gem_close_object = virtio_gpu_gem_object_close, + .gem_create_object = virtio_gpu_create_object, .fops = &virtio_gpu_driver_fops, .ioctls = virtio_gpu_ioctls,drivers/gpu/drm/virtio/virtgpu_gem.c +4
-12@@ -26,14 +26,6 @@#include <drm/drmP.h> #include "virtgpu_drv.h" -void virtio_gpu_gem_free_object (struct drm_gem_object *gem_obj) -{ -struct virtio_gpu_object *obj =gem_to_virtio_gpu_obj (gem_obj); - -if (obj) -virtio_gpu_object_unref (&obj); -} -struct virtio_gpu_object * virtio_gpu_alloc_object(struct drm_device *dev, struct virtio_gpu_object_params *params,@@ -64,16 +56,16 @@ int virtio_gpu_gem_create(struct drm_file *file,if (IS_ERR (obj))return PTR_ERR (obj); - ret =drm_gem_handle_create (file, &obj->gem_base, &handle); + ret =drm_gem_handle_create (file, &obj->base.base, &handle);if (ret) { -drm_gem_object_release (&obj->gem_base); +drm_gem_object_release (&obj->base.base);return ret; } - *obj_p = &obj->gem_base; + *obj_p = &obj->base.base;/* drop reference from allocate - handle holds it now */ -drm_gem_object_put_unlocked (&obj->gem_base); +drm_gem_object_put_unlocked (&obj->base.base); *handle_p = handle;return 0 ;drivers/gpu/drm/virtio/virtgpu_ioctl.c +4
-15@@ -27,7 +27,6 @@#include <drm/drmP.h> #include <drm/virtgpu_drm.h> -#include <drm/ttm/ttm_execbuf_util.h> #include <linux/sync_file.h> #include "virtgpu_drv.h" @@ -259,7 +258,7 @@ static int virtio_gpu_resource_create_ioctl(struct drm_device *dev, void *data,dma_fence_put (&fence->f);if (IS_ERR (qobj))return PTR_ERR (qobj); - obj = &qobj->gem_base; + obj = &qobj->base.base; ret =drm_gem_handle_create (file_priv, obj, &handle);if (ret) {@@ -286,7 +285,7 @@ static int virtio_gpu_resource_info_ioctl(struct drm_device *dev, void *data, qobj =gem_to_virtio_gpu_obj (gobj); - ri->size = qobj->gem_base.size; + ri->size = qobj->base.base.size; ri->res_handle = qobj->hw_res_handle;drm_gem_object_put_unlocked (gobj);return 0 ;@@ -299,7 +298,6 @@ static int virtio_gpu_transfer_from_host_ioctl(struct drm_device *dev,struct virtio_gpu_device *vgdev = dev->dev_private;struct virtio_gpu_fpriv *vfpriv = file->driver_priv;struct drm_virtgpu_3d_transfer_from_host *args = data; -struct ttm_operation_ctx ctx = { true, false };struct drm_gem_object *gobj =NULL ;struct virtio_gpu_object *qobj =NULL ;struct virtio_gpu_fence *fence;@@ -320,10 +318,6 @@ static int virtio_gpu_transfer_from_host_ioctl(struct drm_device *dev,if (ret) goto out; - ret =ttm_bo_validate (&qobj->tbo, &qobj->placement, &ctx); -if (unlikely (ret)) - goto out_unres; -convert_to_hw_box (&box, &args->box); fence =virtio_gpu_fence_alloc (vgdev);@@ -335,7 +329,7 @@ static int virtio_gpu_transfer_from_host_ioctl(struct drm_device *dev, (vgdev, qobj->hw_res_handle, vfpriv->ctx_id, offset, args->level, &box, fence); -reservation_object_add_excl_fence (qobj->tbo.resv, +reservation_object_add_excl_fence (qobj->base.base.resv, &fence->f);dma_fence_put (&fence->f);@@ -352,7 +346,6 @@ static int virtio_gpu_transfer_to_host_ioctl(struct drm_device *dev, void *data,struct virtio_gpu_device *vgdev = dev->dev_private;struct virtio_gpu_fpriv *vfpriv = file->driver_priv;struct drm_virtgpu_3d_transfer_to_host *args = data; -struct ttm_operation_ctx ctx = { true, false };struct drm_gem_object *gobj =NULL ;struct virtio_gpu_object *qobj =NULL ;struct virtio_gpu_fence *fence;@@ -370,10 +363,6 @@ static int virtio_gpu_transfer_to_host_ioctl(struct drm_device *dev, void *data,if (ret) goto out; - ret =ttm_bo_validate (&qobj->tbo, &qobj->placement, &ctx); -if (unlikely (ret)) - goto out_unres; -convert_to_hw_box (&box, &args->box);if (!vgdev->has_virgl_3d) { virtio_gpu_cmd_transfer_to_host_2d@@ -389,7 +378,7 @@ static int virtio_gpu_transfer_to_host_ioctl(struct drm_device *dev, void *data, (vgdev, qobj, vfpriv ? vfpriv->ctx_id :0 , offset, args->level, &box, fence); -reservation_object_add_excl_fence (qobj->tbo.resv, +reservation_object_add_excl_fence (qobj->base.base.resv, &fence->f);dma_fence_put (&fence->f); }drivers/gpu/drm/virtio/virtgpu_kms.c +0
-9@@ -171,12 +171,6 @@ int virtio_gpu_init(struct drm_device *dev) goto err_vbufs; } - ret =virtio_gpu_ttm_init (vgdev); -if (ret) { -DRM_ERROR ("failed to init ttm %d\n" , ret); - goto err_ttm; - } -/* get display info */ virtio_cread(vgdev->vdev, struct virtio_gpu_config, num_scanouts, &num_scanouts);@@ -208,8 +202,6 @@ int virtio_gpu_init(struct drm_device *dev)return 0 ; err_scanouts: -virtio_gpu_ttm_fini (vgdev); -err_ttm:virtio_gpu_free_vbufs (vgdev); err_vbufs: vgdev->vdev->config->del_vqs (vgdev->vdev);@@ -240,7 +232,6 @@ void virtio_gpu_deinit(struct drm_device *dev) vgdev->vdev->config->del_vqs (vgdev->vdev);virtio_gpu_modeset_fini (vgdev); -virtio_gpu_ttm_fini (vgdev);virtio_gpu_free_vbufs (vgdev);virtio_gpu_cleanup_cap_cache (vgdev);kfree (vgdev->capsets);drivers/gpu/drm/virtio/virtgpu_object.c +41
-105@@ -23,8 +23,6 @@* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include <drm/ttm/ttm_execbuf_util.h> -#include "virtgpu_drv.h" static int virtio_gpu_resource_id_get(struct virtio_gpu_device *vgdev,@@ -57,39 +55,45 @@ static void virtio_gpu_resource_id_put(struct virtio_gpu_device *vgdev, uint32_t#endif } -static void virtio_gpu_ttm_bo_destroy (struct ttm_buffer_object *tbo) +static void virtio_gpu_free_object (struct drm_gem_object *obj) { -struct virtio_gpu_object *bo; -struct virtio_gpu_device *vgdev; - - bo = container_of(tbo, struct virtio_gpu_object, tbo); - vgdev = (struct virtio_gpu_device *)bo->gem_base.dev->dev_private; +struct virtio_gpu_object *bo =gem_to_virtio_gpu_obj (obj); +struct virtio_gpu_device *vgdev = bo->base.base.dev->dev_private; +if (bo->pages) +virtio_gpu_object_detach (vgdev, bo);if (bo->created)virtio_gpu_cmd_unref_resource (vgdev, bo->hw_res_handle); -if (bo->pages) -virtio_gpu_object_free_sg_table (bo); -if (bo->vmap) -virtio_gpu_object_kunmap (bo); -drm_gem_object_release (&bo->gem_base);virtio_gpu_resource_id_put (vgdev, bo->hw_res_handle); -kfree (bo); + +drm_gem_shmem_free_object (obj); } -static void virtio_gpu_init_ttm_placement (struct virtio_gpu_object *vgbo) +static const struct drm_gem_object_funcs virtio_gpu_gem_funcs = { + .free = virtio_gpu_free_object, + .open = virtio_gpu_gem_object_open, + .close = virtio_gpu_gem_object_close, + + .print_info = drm_gem_shmem_print_info, + .pin = drm_gem_shmem_pin, + .unpin = drm_gem_shmem_unpin, + .get_sg_table = drm_gem_shmem_get_sg_table, + .vmap = drm_gem_shmem_vmap, + .vunmap = drm_gem_shmem_vunmap, + .vm_ops = &drm_gem_shmem_vm_ops, +}; + +struct drm_gem_object *virtio_gpu_create_object (struct drm_device *dev, +size_t size) { -u32 c =1 ; +struct virtio_gpu_object *bo; - vgbo->placement.placement = &vgbo->placement_code; - vgbo->placement.busy_placement = &vgbo->placement_code; - vgbo->placement_code.fpfn =0 ; - vgbo->placement_code.lpfn =0 ; - vgbo->placement_code.flags = -TTM_PL_MASK_CACHING |TTM_PL_FLAG_TT | -TTM_PL_FLAG_NO_EVICT ; - vgbo->placement.num_placement = c; - vgbo->placement.num_busy_placement = c; + bo =kzalloc (sizeof (*bo),GFP_KERNEL ); +if (!bo) +return NULL ; + bo->base.base.funcs = &virtio_gpu_gem_funcs; +return &bo->base.base; } int virtio_gpu_object_create(struct virtio_gpu_device *vgdev,@@ -98,27 +102,22 @@ int virtio_gpu_object_create(struct virtio_gpu_device *vgdev, struct virtio_gpu_fence *fence) {struct virtio_gpu_object_array *objs =NULL ; +struct drm_gem_shmem_object *shmem_obj;struct virtio_gpu_object *bo; -size_t acc_size;int ret; *bo_ptr =NULL ; - acc_size =ttm_bo_dma_acc_size (&vgdev->mman.bdev, params->size, -sizeof (struct virtio_gpu_object )); + params->size =roundup (params->size,PAGE_SIZE ); + shmem_obj =drm_gem_shmem_create (vgdev->ddev, params->size); +if (IS_ERR (shmem_obj)) +return PTR_ERR (shmem_obj); + bo =gem_to_virtio_gpu_obj (&shmem_obj->base); - bo =kzalloc (sizeof (struct virtio_gpu_object ),GFP_KERNEL ); -if (bo ==NULL ) -return -ENOMEM ; ret =virtio_gpu_resource_id_get (vgdev, &bo->hw_res_handle);if (ret <0 ) goto err_free_gem; - params->size =roundup (params->size,PAGE_SIZE ); - ret =drm_gem_object_init (vgdev->ddev, &bo->gem_base, params->size); -if (ret !=0 ) - goto err_put_id; - bo->dumb = params->dumb;if (fence) {@@ -126,7 +125,7 @@ int virtio_gpu_object_create(struct virtio_gpu_device *vgdev, objs =virtio_gpu_array_alloc (1 );if (!objs) goto err_put_id; -virtio_gpu_array_add_obj (objs, &bo->gem_base); +virtio_gpu_array_add_obj (objs, &bo->base.base); ret =virtio_gpu_array_lock_resv (objs);if (ret !=0 )@@ -141,15 +140,11 @@ int virtio_gpu_object_create(struct virtio_gpu_device *vgdev, objs, fence); } -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 , - bo->gem_base.resv, - &virtio_gpu_ttm_bo_destroy); -/* ttm_bo_init failure will call the destroy */ -if (ret !=0 ) + ret =virtio_gpu_object_attach (vgdev, bo,NULL ); +if (ret !=0 ) { +virtio_gpu_free_object (&shmem_obj->base);return ret; + } *bo_ptr = bo;return 0 ;@@ -159,65 +154,6 @@ int virtio_gpu_object_create(struct virtio_gpu_device *vgdev, err_put_id:virtio_gpu_resource_id_put (vgdev, bo->hw_res_handle); err_free_gem: -kfree (bo); +drm_gem_shmem_free_object (&shmem_obj->base);return ret; } - -void virtio_gpu_object_kunmap (struct virtio_gpu_object *bo) -{ - bo->vmap =NULL ; -ttm_bo_kunmap (&bo->kmap); -} - -int virtio_gpu_object_kmap (struct virtio_gpu_object *bo) -{ -bool is_iomem; -int r; - -WARN_ON (bo->vmap); - - r =ttm_bo_kmap (&bo->tbo,0 , bo->tbo.num_pages, &bo->kmap); -if (r) -return r; - bo->vmap =ttm_kmap_obj_virtual (&bo->kmap, &is_iomem); -return 0 ; -} - -int virtio_gpu_object_get_sg_table (struct virtio_gpu_device *qdev, -struct virtio_gpu_object *bo) -{ -int ret; -struct page **pages = bo->tbo.ttm->pages; -int nr_pages = bo->tbo.num_pages; -struct ttm_operation_ctx ctx = { - .interruptible = false, - .no_wait_gpu = false - }; - -/* wtf swapping */ -if (bo->pages) -return 0 ; - -if (bo->tbo.ttm->state == tt_unpopulated) - bo->tbo.ttm->bdev->driver->ttm_tt_populate (bo->tbo.ttm, &ctx); - bo->pages =kmalloc (sizeof (struct sg_table ),GFP_KERNEL ); -if (!bo->pages) - goto out; - - ret =sg_alloc_table_from_pages (bo->pages, pages, nr_pages,0 , - nr_pages <<PAGE_SHIFT ,GFP_KERNEL ); -if (ret) - goto out; -return 0 ; -out: -kfree (bo->pages); - bo->pages =NULL ; -return -ENOMEM ; -} - -void virtio_gpu_object_free_sg_table (struct virtio_gpu_object *bo) -{ -sg_free_table (bo->pages); -kfree (bo->pages); - bo->pages =NULL ; -}drivers/gpu/drm/virtio/virtgpu_prime.c +0
-37@@ -28,46 +28,9 @@* device that might share buffers with virtgpu */ -struct sg_table *virtgpu_gem_prime_get_sg_table (struct drm_gem_object *obj) -{ -struct virtio_gpu_object *bo =gem_to_virtio_gpu_obj (obj); - -if (!bo->tbo.ttm->pages || !bo->tbo.ttm->num_pages) -/* should not happen */ -return ERR_PTR (-EINVAL ); - -return drm_prime_pages_to_sg (bo->tbo.ttm->pages, - bo->tbo.ttm->num_pages); -} -struct drm_gem_object *virtgpu_gem_prime_import_sg_table (struct drm_device *dev,struct dma_buf_attachment *attach,struct sg_table *table) {return ERR_PTR (-ENODEV ); } - -void *virtgpu_gem_prime_vmap (struct drm_gem_object *obj) -{ -struct virtio_gpu_object *bo =gem_to_virtio_gpu_obj (obj); -int ret; - - ret =virtio_gpu_object_kmap (bo); -if (ret) -return NULL ; -return bo->vmap; -} - -void virtgpu_gem_prime_vunmap (struct drm_gem_object *obj,void *vaddr) -{ -virtio_gpu_object_kunmap (gem_to_virtio_gpu_obj (obj)); -} - -int virtgpu_gem_prime_mmap (struct drm_gem_object *obj, -struct vm_area_struct *vma) -{ -struct virtio_gpu_object *bo =gem_to_virtio_gpu_obj (obj); - - bo->gem_base.vma_node.vm_node.start = bo->tbo.vma_node.vm_node.start; -return drm_gem_prime_mmap (obj, vma); -}drivers/gpu/drm/virtio/virtgpu_ttm.c deleted +0
-304@@ -1,304 +0,0 @@ -/* -* Copyright (C) 2015 Red Hat, Inc. -* All Rights Reserved. -* -* Authors: -* Dave Airlie -* Alon Levy -* -* Permission is hereby granted, free of charge, to any person obtaining a -* copy of this software and associated documentation files (the "Software"), -* to deal in the Software without restriction, including without limitation -* the rights to use, copy, modify, merge, publish, distribute, sublicense, -* and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in -* all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR -* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -* OTHER DEALINGS IN THE SOFTWARE. -*/ - -#include <drm/ttm/ttm_bo_api.h> -#include <drm/ttm/ttm_bo_driver.h> -#include <drm/ttm/ttm_placement.h> -#include <drm/ttm/ttm_page_alloc.h> -#include <drm/ttm/ttm_module.h> -#include <drm/drmP.h> -#include <drm/drm.h> -#include <drm/virtgpu_drm.h> -#include "virtgpu_drv.h" - -#include <linux/delay.h> - -static struct -virtio_gpu_device *virtio_gpu_get_vgdev (struct ttm_bo_device *bdev) -{ -struct virtio_gpu_mman *mman; -struct virtio_gpu_device *vgdev; - - mman = container_of(bdev, struct virtio_gpu_mman, bdev); - vgdev = container_of(mman, struct virtio_gpu_device, mman); -return vgdev; -} - -int virtio_gpu_mmap (struct file *filp,struct vm_area_struct *vma) -{ -struct drm_file *file_priv; -struct virtio_gpu_device *vgdev; -int r; - - file_priv = filp->private_data; - vgdev = file_priv->minor->dev->dev_private; -if (vgdev ==NULL ) { -DRM_ERROR ( -"filp->private_data->minor->dev->dev_private == NULL\n" ); -return -EINVAL ; - } - r =ttm_bo_mmap (filp, vma, &vgdev->mman.bdev); - -return r; -} - -static int virtio_gpu_invalidate_caches (struct ttm_bo_device *bdev, -uint32_t flags) -{ -return 0 ; -} - -static int ttm_bo_man_get_node (struct ttm_mem_type_manager *man, -struct ttm_buffer_object *bo, -const struct ttm_place *place, -struct ttm_mem_reg *mem) -{ - mem->mm_node = (void *)1 ; -return 0 ; -} - -static void ttm_bo_man_put_node (struct ttm_mem_type_manager *man, -struct ttm_mem_reg *mem) -{ - mem->mm_node = (void *)NULL ; -} - -static int ttm_bo_man_init (struct ttm_mem_type_manager *man, -unsigned long p_size) -{ -return 0 ; -} - -static int ttm_bo_man_takedown (struct ttm_mem_type_manager *man) -{ -return 0 ; -} - -static void ttm_bo_man_debug (struct ttm_mem_type_manager *man, -struct drm_printer *printer) -{ -} - -static const struct ttm_mem_type_manager_func virtio_gpu_bo_manager_func = { - .init = ttm_bo_man_init, - .takedown = ttm_bo_man_takedown, - .get_node = ttm_bo_man_get_node, - .put_node = ttm_bo_man_put_node, - .debug = ttm_bo_man_debug -}; - -static int virtio_gpu_init_mem_type (struct ttm_bo_device *bdev,uint32_t type, -struct ttm_mem_type_manager *man) -{ -switch (type) { -case TTM_PL_SYSTEM : -/* System memory */ - man->flags =TTM_MEMTYPE_FLAG_MAPPABLE ; - man->available_caching =TTM_PL_MASK_CACHING ; - man->default_caching =TTM_PL_FLAG_CACHED ; -break ; -case TTM_PL_TT : - man->func = &virtio_gpu_bo_manager_func; - man->flags =TTM_MEMTYPE_FLAG_MAPPABLE ; - man->available_caching =TTM_PL_MASK_CACHING ; - man->default_caching =TTM_PL_FLAG_CACHED ; -break ; -default : -DRM_ERROR ("Unsupported memory type %u\n" , (unsigned int )type); -return -EINVAL ; - } -return 0 ; -} - -static void virtio_gpu_evict_flags (struct ttm_buffer_object *bo, -struct ttm_placement *placement) -{ -static const struct ttm_place placements = { - .fpfn =0 , - .lpfn =0 , - .flags =TTM_PL_MASK_CACHING |TTM_PL_FLAG_SYSTEM , - }; - - placement->placement = &placements; - placement->busy_placement = &placements; - placement->num_placement =1 ; - placement->num_busy_placement =1 ; -} - -static int virtio_gpu_verify_access (struct ttm_buffer_object *bo, -struct file *filp) -{ -return 0 ; -} - -static int virtio_gpu_ttm_io_mem_reserve (struct ttm_bo_device *bdev, -struct ttm_mem_reg *mem) -{ -struct ttm_mem_type_manager *man = &bdev->man[mem->mem_type]; - - mem->bus.addr =NULL ; - mem->bus.offset =0 ; - mem->bus.size = mem->num_pages <<PAGE_SHIFT ; - mem->bus.base =0 ; - mem->bus.is_iomem = false; -if (!(man->flags &TTM_MEMTYPE_FLAG_MAPPABLE )) -return -EINVAL ; -switch (mem->mem_type) { -case TTM_PL_SYSTEM : -case TTM_PL_TT : -/* system memory */ -return 0 ; -default : -return -EINVAL ; - } -return 0 ; -} - -static void virtio_gpu_ttm_io_mem_free (struct ttm_bo_device *bdev, -struct ttm_mem_reg *mem) -{ -} - -/* -* TTM backend functions. -*/ -struct virtio_gpu_ttm_tt { -struct ttm_dma_tt ttm; -struct virtio_gpu_object *obj; -}; - -static int virtio_gpu_ttm_tt_bind (struct ttm_tt *ttm, -struct ttm_mem_reg *bo_mem) -{ -struct virtio_gpu_ttm_tt *gtt = - container_of(ttm, struct virtio_gpu_ttm_tt, ttm.ttm); -struct virtio_gpu_device *vgdev = -virtio_gpu_get_vgdev (gtt->obj->tbo.bdev); - -virtio_gpu_object_attach (vgdev, gtt->obj,NULL ); -return 0 ; -} - -static int virtio_gpu_ttm_tt_unbind (struct ttm_tt *ttm) -{ -struct virtio_gpu_ttm_tt *gtt = - container_of(ttm, struct virtio_gpu_ttm_tt, ttm.ttm); -struct virtio_gpu_device *vgdev = -virtio_gpu_get_vgdev (gtt->obj->tbo.bdev); - -virtio_gpu_object_detach (vgdev, gtt->obj); -return 0 ; -} - -static void virtio_gpu_ttm_tt_destroy (struct ttm_tt *ttm) -{ -struct virtio_gpu_ttm_tt *gtt = - container_of(ttm, struct virtio_gpu_ttm_tt, ttm.ttm); - -ttm_dma_tt_fini (>t->ttm); -kfree (gtt); -} - -static struct ttm_backend_func virtio_gpu_tt_func = { - .bind = &virtio_gpu_ttm_tt_bind, - .unbind = &virtio_gpu_ttm_tt_unbind, - .destroy = &virtio_gpu_ttm_tt_destroy, -}; - -static struct ttm_tt *virtio_gpu_ttm_tt_create (struct ttm_buffer_object *bo, -uint32_t page_flags) -{ -struct virtio_gpu_device *vgdev; -struct virtio_gpu_ttm_tt *gtt; - - vgdev =virtio_gpu_get_vgdev (bo->bdev); - gtt =kzalloc (sizeof (struct virtio_gpu_ttm_tt ),GFP_KERNEL ); -if (gtt ==NULL ) -return NULL ; - gtt->ttm.ttm.func = &virtio_gpu_tt_func; - gtt->obj = container_of(bo, struct virtio_gpu_object, tbo); -if (ttm_dma_tt_init (>t->ttm, bo, page_flags)) { -kfree (gtt); -return NULL ; - } -return >t->ttm.ttm; -} - -static void virtio_gpu_bo_swap_notify (struct ttm_buffer_object *tbo) -{ -struct virtio_gpu_object *bo; - - bo = container_of(tbo, struct virtio_gpu_object, tbo); - -if (bo->pages) -virtio_gpu_object_free_sg_table (bo); -} - -static struct ttm_bo_driver virtio_gpu_bo_driver = { - .ttm_tt_create = &virtio_gpu_ttm_tt_create, - .invalidate_caches = &virtio_gpu_invalidate_caches, - .init_mem_type = &virtio_gpu_init_mem_type, - .eviction_valuable = ttm_bo_eviction_valuable, - .evict_flags = &virtio_gpu_evict_flags, - .verify_access = &virtio_gpu_verify_access, - .io_mem_reserve = &virtio_gpu_ttm_io_mem_reserve, - .io_mem_free = &virtio_gpu_ttm_io_mem_free, - .swap_notify = &virtio_gpu_bo_swap_notify, -}; - -int virtio_gpu_ttm_init (struct virtio_gpu_device *vgdev) -{ -int r; - -/* No others user of address space so set it to 0 */ - r =ttm_bo_device_init (&vgdev->mman.bdev, - &virtio_gpu_bo_driver, - vgdev->ddev->anon_inode->i_mapping, - false); -if (r) { -DRM_ERROR ("failed initializing buffer object driver(%d).\n" , r); - goto err_dev_init; - } - - r =ttm_bo_init_mm (&vgdev->mman.bdev,TTM_PL_TT ,0 ); -if (r) { -DRM_ERROR ("Failed initializing GTT heap.\n" ); - goto err_mm_init; - } -return 0 ; - -err_mm_init: -ttm_bo_device_release (&vgdev->mman.bdev); -err_dev_init: -return r; -} - -void virtio_gpu_ttm_fini (struct virtio_gpu_device *vgdev) -{ -ttm_bo_device_release (&vgdev->mman.bdev); -DRM_INFO ("virtio_gpu: ttm finalized\n" ); -}drivers/gpu/drm/virtio/virtgpu_vq.c +18
-6@@ -979,17 +979,21 @@ int virtio_gpu_object_attach(struct virtio_gpu_device *vgdev,bool use_dma_api = !virtio_has_iommu_quirk (vgdev->vdev);struct virtio_gpu_mem_entry *ents;struct scatterlist *sg; -int si, nents; +int si, nents, ret;if (WARN_ON_ONCE (!obj->created))return -EINVAL ; +if (WARN_ON_ONCE (obj->pages)) +return -EINVAL ; -if (!obj->pages) { -int ret; + ret =drm_gem_shmem_pin (&obj->base.base); +if (ret <0 ) +return -EINVAL ; - ret =virtio_gpu_object_get_sg_table (vgdev, obj); -if (ret) -return ret; + obj->pages =drm_gem_shmem_get_sg_table (&obj->base.base); +if (obj->pages ==NULL ) { +drm_gem_shmem_unpin (&obj->base.base); +return -EINVAL ; }if (use_dma_api) {@@ -1028,6 +1032,9 @@ void virtio_gpu_object_detach(struct virtio_gpu_device *vgdev, {bool use_dma_api = !virtio_has_iommu_quirk (vgdev->vdev); +if (WARN_ON_ONCE (!obj->pages)) +return ; +if (use_dma_api && obj->mapped) {struct virtio_gpu_fence *fence =virtio_gpu_fence_alloc (vgdev);/* detach backing and wait for the host process it ... */ @@ -1043,6 +1050,11 @@ void virtio_gpu_object_detach(struct virtio_gpu_device *vgdev, }else {virtio_gpu_cmd_resource_inval_backing (vgdev, obj->hw_res_handle,NULL ); } + +sg_free_table (obj->pages); + obj->pages =NULL ; + +drm_gem_shmem_unpin (&obj->base.base); } void virtio_gpu_cursor_ping(struct virtio_gpu_device *vgdev,drivers/gpu/drm/virtio/Kconfig +1
-1@@ -3,7 +3,7 @@ config DRM_VIRTIO_GPU tristate "Virtio GPU driver" depends on DRM && VIRTIO && MMU select DRM_KMS_HELPER - select DRM_TTM + select DRM_GEM_SHMEM_HELPER help This is the virtual GPU driver for virtio. It can be used with QEMU based VMMs (like KVM or Xen).drivers/gpu/drm/virtio/Makefile +1
-2@@ -4,7 +4,7 @@ # Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher. virtio-gpu-y := virtgpu_drv.o virtgpu_kms.o virtgpu_gem.o \ - virtgpu_display.o virtgpu_vq.o virtgpu_ttm.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 --2.18.1
Gerd Hoffmann
maintainerPATCH v6 12/18 drm/virtio: remove virtio_gpu_alloc_object
In reply to Gerd HoffmannThin wrapper around virtio_gpu_object_create(),
but calling that directly works equally well.
--- drivers/gpu/drm/virtio/virtgpu_drv.h | 4 ---- drivers/gpu/drm/virtio/virtgpu_gem.c | 23 ++++------------------- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 6 +++--- 3 files changed, 7 insertions(+), 26 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.h +0 -4
@@ -229,10 +229,6 @@ int virtio_gpu_gem_object_open(struct drm_gem_object *obj, struct drm_file *file);void virtio_gpu_gem_object_close (struct drm_gem_object *obj,struct drm_file *file); -struct virtio_gpu_object * -virtio_gpu_alloc_object (struct drm_device *dev, -struct virtio_gpu_object_params *params, -struct virtio_gpu_fence *fence);int virtio_gpu_mode_dumb_create (struct drm_file *file_priv,struct drm_device *dev,struct drm_mode_create_dumb *args);
drivers/gpu/drm/virtio/virtgpu_gem.c +4 -19
@@ -26,35 +26,20 @@#include <drm/drmP.h> #include "virtgpu_drv.h" -struct virtio_gpu_object * -virtio_gpu_alloc_object (struct drm_device *dev, -struct virtio_gpu_object_params *params, -struct virtio_gpu_fence *fence) -{ -struct virtio_gpu_device *vgdev = dev->dev_private; -struct virtio_gpu_object *obj; -int ret; - - ret =virtio_gpu_object_create (vgdev, params, &obj, fence); -if (ret) -return ERR_PTR (ret); - -return obj; -} -int virtio_gpu_gem_create (struct drm_file *file,struct drm_device *dev,struct virtio_gpu_object_params *params,struct drm_gem_object **obj_p,uint32_t *handle_p) { +struct virtio_gpu_device *vgdev = dev->dev_private;struct virtio_gpu_object *obj;int ret;u32 handle; - obj =virtio_gpu_alloc_object (dev, params,NULL ); -if (IS_ERR (obj)) -return PTR_ERR (obj); + ret =virtio_gpu_object_create (vgdev, params, &obj,NULL ); +if (ret <0 ) +return ret; ret =drm_gem_handle_create (file, &obj->base.base, &handle);if (ret) {
drivers/gpu/drm/virtio/virtgpu_ioctl.c +3 -3
@@ -254,10 +254,10 @@ static int virtio_gpu_resource_create_ioctl(struct drm_device *dev, void *data, fence =virtio_gpu_fence_alloc (vgdev);if (!fence)return -ENOMEM ; - qobj =virtio_gpu_alloc_object (dev, ¶ms, fence); + ret =virtio_gpu_object_create (vgdev, ¶ms, &qobj, fence);dma_fence_put (&fence->f); -if (IS_ERR (qobj)) -return PTR_ERR (qobj); +if (ret <0 ) +return ret; obj = &qobj->base.base; ret =drm_gem_handle_create (file_priv, obj, &handle);
Signature · 1 line
2.18.1
Gerd Hoffmann
maintainerPATCH v6 12/18 drm/virtio: remove virtio_gpu_alloc_object
In reply to Gerd HoffmannThin wrapper around virtio_gpu_object_create(),
but calling that directly works equally well.
--- drivers/gpu/drm/virtio/virtgpu_drv.h | 4 ---- drivers/gpu/drm/virtio/virtgpu_gem.c | 23 ++++------------------- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 6 +++--- 3 files changed, 7 insertions(+), 26 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.h +0 -4
@@ -229,10 +229,6 @@ int virtio_gpu_gem_object_open(struct drm_gem_object *obj, struct drm_file *file);void virtio_gpu_gem_object_close (struct drm_gem_object *obj,struct drm_file *file); -struct virtio_gpu_object * -virtio_gpu_alloc_object (struct drm_device *dev, -struct virtio_gpu_object_params *params, -struct virtio_gpu_fence *fence);int virtio_gpu_mode_dumb_create (struct drm_file *file_priv,struct drm_device *dev,struct drm_mode_create_dumb *args);
drivers/gpu/drm/virtio/virtgpu_gem.c +4 -19
@@ -26,35 +26,20 @@#include <drm/drmP.h> #include "virtgpu_drv.h" -struct virtio_gpu_object * -virtio_gpu_alloc_object (struct drm_device *dev, -struct virtio_gpu_object_params *params, -struct virtio_gpu_fence *fence) -{ -struct virtio_gpu_device *vgdev = dev->dev_private; -struct virtio_gpu_object *obj; -int ret; - - ret =virtio_gpu_object_create (vgdev, params, &obj, fence); -if (ret) -return ERR_PTR (ret); - -return obj; -} -int virtio_gpu_gem_create (struct drm_file *file,struct drm_device *dev,struct virtio_gpu_object_params *params,struct drm_gem_object **obj_p,uint32_t *handle_p) { +struct virtio_gpu_device *vgdev = dev->dev_private;struct virtio_gpu_object *obj;int ret;u32 handle; - obj =virtio_gpu_alloc_object (dev, params,NULL ); -if (IS_ERR (obj)) -return PTR_ERR (obj); + ret =virtio_gpu_object_create (vgdev, params, &obj,NULL ); +if (ret <0 ) +return ret; ret =drm_gem_handle_create (file, &obj->base.base, &handle);if (ret) {
drivers/gpu/drm/virtio/virtgpu_ioctl.c +3 -3
@@ -254,10 +254,10 @@ static int virtio_gpu_resource_create_ioctl(struct drm_device *dev, void *data, fence =virtio_gpu_fence_alloc (vgdev);if (!fence)return -ENOMEM ; - qobj =virtio_gpu_alloc_object (dev, ¶ms, fence); + ret =virtio_gpu_object_create (vgdev, ¶ms, &qobj, fence);dma_fence_put (&fence->f); -if (IS_ERR (qobj)) -return PTR_ERR (qobj); +if (ret <0 ) +return ret; obj = &qobj->base.base; ret =drm_gem_handle_create (file_priv, obj, &handle);
Signature · 6 lines
2.18.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Gerd Hoffmann
maintainerPATCH v6 13/18 drm/virtio: drop virtio_gpu_object_{ref,unref}
In reply to Gerd HoffmannNo users left.
--- drivers/gpu/drm/virtio/virtgpu_drv.h | 15 --------------- 1 file changed, 15 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.h +0 -15
@@ -362,21 +362,6 @@ struct drm_gem_object *virtgpu_gem_prime_import_sg_table( struct drm_device *dev, struct dma_buf_attachment *attach, struct sg_table *sgt); -static inline struct virtio_gpu_object * -virtio_gpu_object_ref (struct virtio_gpu_object *bo) -{ -drm_gem_object_get (&bo->base.base); -return bo; -} - -static inline void virtio_gpu_object_unref (struct virtio_gpu_object **bo) -{ -if ((*bo) ==NULL ) -return ; -drm_gem_object_put (&(*bo)->base.base); - *bo =NULL ; -} -static inline u64 virtio_gpu_object_mmap_offset (struct virtio_gpu_object *bo) {return drm_vma_node_offset_addr (&bo->base.base.vma_node);
Signature · 1 line
2.18.1
Gerd Hoffmann
maintainerPATCH v6 13/18 drm/virtio: drop virtio_gpu_object_{ref,unref}
In reply to Gerd HoffmannNo users left.
--- drivers/gpu/drm/virtio/virtgpu_drv.h | 15 --------------- 1 file changed, 15 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.h +0 -15
@@ -362,21 +362,6 @@ struct drm_gem_object *virtgpu_gem_prime_import_sg_table( struct drm_device *dev, struct dma_buf_attachment *attach, struct sg_table *sgt); -static inline struct virtio_gpu_object * -virtio_gpu_object_ref (struct virtio_gpu_object *bo) -{ -drm_gem_object_get (&bo->base.base); -return bo; -} - -static inline void virtio_gpu_object_unref (struct virtio_gpu_object **bo) -{ -if ((*bo) ==NULL ) -return ; -drm_gem_object_put (&(*bo)->base.base); - *bo =NULL ; -} -static inline u64 virtio_gpu_object_mmap_offset (struct virtio_gpu_object *bo) {return drm_vma_node_offset_addr (&bo->base.base.vma_node);
Signature · 6 lines
2.18.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Gerd Hoffmann
maintainerPATCH v6 14/18 drm/virtio: rework virtio_gpu_transfer_from_host_ioctl fencing
In reply to Gerd HoffmannSwitch to the virtio_gpu_array_* helper workflow.
--- drivers/gpu/drm/virtio/virtgpu_drv.h | 3 ++- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 35 +++++++++++--------------- drivers/gpu/drm/virtio/virtgpu_vq.c | 8 ++++-- 3 files changed, 23 insertions(+), 23 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.h +2 -1
@@ -302,9 +302,10 @@ void virtio_gpu_cmd_submit(struct virtio_gpu_device *vgdev,struct virtio_gpu_object_array *objs, struct virtio_gpu_fence *fence);void virtio_gpu_cmd_transfer_from_host_3d (struct virtio_gpu_device *vgdev, -uint32_t resource_id,uint32_t ctx_id, +uint32_t ctx_id,uint64_t offset,uint32_t level,struct virtio_gpu_box *box, +struct virtio_gpu_object_array *objs,struct virtio_gpu_fence *fence); void virtio_gpu_cmd_transfer_to_host_3d(struct virtio_gpu_device *vgdev, struct virtio_gpu_object *bo,
drivers/gpu/drm/virtio/virtgpu_ioctl.c +15 -20
@@ -298,8 +298,7 @@ static int virtio_gpu_transfer_from_host_ioctl(struct drm_device *dev,struct virtio_gpu_device *vgdev = dev->dev_private;struct virtio_gpu_fpriv *vfpriv = file->driver_priv;struct drm_virtgpu_3d_transfer_from_host *args = data; -struct drm_gem_object *gobj =NULL ; -struct virtio_gpu_object *qobj =NULL ; +struct virtio_gpu_object_array *objs;struct virtio_gpu_fence *fence;int ret;u32 offset = args->offset;
@@ -308,35 +307,31 @@ static int virtio_gpu_transfer_from_host_ioctl(struct drm_device *dev,if (vgdev->has_virgl_3d == false)return -ENOSYS ; - gobj =drm_gem_object_lookup (file, args->bo_handle); -if (gobj ==NULL ) + objs =virtio_gpu_array_from_handles (file, &args->bo_handle,1 ); +if (objs ==NULL )return -ENOENT ; - qobj =gem_to_virtio_gpu_obj (gobj); - - ret =virtio_gpu_object_reserve (qobj); -if (ret) - goto out; + ret =virtio_gpu_array_lock_resv (objs); +if (ret !=0 ) + goto err_put_free;convert_to_hw_box (&box, &args->box); fence =virtio_gpu_fence_alloc (vgdev);if (!fence) { ret = -ENOMEM ; - goto out_unres; + goto err_unlock; }virtio_gpu_cmd_transfer_from_host_3d - (vgdev, qobj->hw_res_handle, - vfpriv->ctx_id, offset, args->level, - &box, fence); -reservation_object_add_excl_fence (qobj->base.base.resv, - &fence->f); - + (vgdev, vfpriv->ctx_id, offset, args->level, + &box, objs, fence);dma_fence_put (&fence->f); -out_unres: -virtio_gpu_object_unreserve (qobj); -out: -drm_gem_object_put_unlocked (gobj); +return 0 ; + +err_unlock: +virtio_gpu_array_unlock_resv (objs); +err_put_free: +virtio_gpu_array_put_free (objs);return ret; }
drivers/gpu/drm/virtio/virtgpu_vq.c +6 -2
@@ -928,20 +928,24 @@ void virtio_gpu_cmd_transfer_to_host_3d(struct virtio_gpu_device *vgdev, }void virtio_gpu_cmd_transfer_from_host_3d (struct virtio_gpu_device *vgdev, -uint32_t resource_id,uint32_t ctx_id, +uint32_t ctx_id,uint64_t offset,uint32_t level,struct virtio_gpu_box *box, +struct virtio_gpu_object_array *objs,struct virtio_gpu_fence *fence) { +struct virtio_gpu_object *bo =gem_to_virtio_gpu_obj (objs->objs[0 ]);struct virtio_gpu_transfer_host_3d *cmd_p;struct virtio_gpu_vbuffer *vbuf; cmd_p =virtio_gpu_alloc_cmd (vgdev, &vbuf,sizeof (*cmd_p));memset (cmd_p,0 ,sizeof (*cmd_p)); + vbuf->objs = objs; + cmd_p->hdr.type =cpu_to_le32 (VIRTIO_GPU_CMD_TRANSFER_FROM_HOST_3D ); cmd_p->hdr.ctx_id =cpu_to_le32 (ctx_id); - cmd_p->resource_id =cpu_to_le32 (resource_id); + cmd_p->resource_id =cpu_to_le32 (bo->hw_res_handle); cmd_p->box = *box; cmd_p->offset =cpu_to_le64 (offset); cmd_p->level =cpu_to_le32 (level);
Signature · 1 line
2.18.1
Chia-I Wu
reviewerRe: [PATCH v6 14/18] drm/virtio: rework virtio_gpu_transfer_from_host_ioctl fencing
Quoted 2 lines · Gerd Hoffmann
Switch to the virtio_gpu_array_* helper workflow.
(just repeating my question on patch 6)
Does this fix the obj refcount issue? When was the issue introduced?
Quoted 122 lines
Signed-off-by Gerd Hoffmann <[email protected]>--- drivers/gpu/drm/virtio/virtgpu_drv.h | 3 ++- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 35 +++++++++++--------------- drivers/gpu/drm/virtio/virtgpu_vq.c | 8 ++++-- 3 files changed, 23 insertions(+), 23 deletions(-)drivers/gpu/drm/virtio/virtgpu_drv.h +2
-1@@ -302,9 +302,10 @@ void virtio_gpu_cmd_submit(struct virtio_gpu_device *vgdev,struct virtio_gpu_object_array *objs, struct virtio_gpu_fence *fence);void virtio_gpu_cmd_transfer_from_host_3d (struct virtio_gpu_device *vgdev, -uint32_t resource_id,uint32_t ctx_id, +uint32_t ctx_id,uint64_t offset,uint32_t level,struct virtio_gpu_box *box, +struct virtio_gpu_object_array *objs,struct virtio_gpu_fence *fence); void virtio_gpu_cmd_transfer_to_host_3d(struct virtio_gpu_device *vgdev, struct virtio_gpu_object *bo,drivers/gpu/drm/virtio/virtgpu_ioctl.c +15
-20@@ -298,8 +298,7 @@ static int virtio_gpu_transfer_from_host_ioctl(struct drm_device *dev,struct virtio_gpu_device *vgdev = dev->dev_private;struct virtio_gpu_fpriv *vfpriv = file->driver_priv;struct drm_virtgpu_3d_transfer_from_host *args = data; -struct drm_gem_object *gobj =NULL ; -struct virtio_gpu_object *qobj =NULL ; +struct virtio_gpu_object_array *objs;struct virtio_gpu_fence *fence;int ret;u32 offset = args->offset;@@ -308,35 +307,31 @@ static int virtio_gpu_transfer_from_host_ioctl(struct drm_device *dev,if (vgdev->has_virgl_3d == false)return -ENOSYS ; - gobj =drm_gem_object_lookup (file, args->bo_handle); -if (gobj ==NULL ) + objs =virtio_gpu_array_from_handles (file, &args->bo_handle,1 ); +if (objs ==NULL )return -ENOENT ; - qobj =gem_to_virtio_gpu_obj (gobj); - - ret =virtio_gpu_object_reserve (qobj); -if (ret) - goto out; + ret =virtio_gpu_array_lock_resv (objs); +if (ret !=0 ) + goto err_put_free;convert_to_hw_box (&box, &args->box); fence =virtio_gpu_fence_alloc (vgdev);if (!fence) { ret = -ENOMEM ; - goto out_unres; + goto err_unlock; }virtio_gpu_cmd_transfer_from_host_3d - (vgdev, qobj->hw_res_handle, - vfpriv->ctx_id, offset, args->level, - &box, fence); -reservation_object_add_excl_fence (qobj->base.base.resv, - &fence->f); - + (vgdev, vfpriv->ctx_id, offset, args->level, + &box, objs, fence);dma_fence_put (&fence->f); -out_unres: -virtio_gpu_object_unreserve (qobj); -out: -drm_gem_object_put_unlocked (gobj); +return 0 ; + +err_unlock: +virtio_gpu_array_unlock_resv (objs); +err_put_free: +virtio_gpu_array_put_free (objs);return ret; }drivers/gpu/drm/virtio/virtgpu_vq.c +6
-3@@ -928,20 +928,24 @@ void virtio_gpu_cmd_transfer_to_host_3d(struct virtio_gpu_device *vgdev, }void virtio_gpu_cmd_transfer_from_host_3d (struct virtio_gpu_device *vgdev, -uint32_t resource_id,uint32_t ctx_id, +uint32_t ctx_id,uint64_t offset,uint32_t level,struct virtio_gpu_box *box, +struct virtio_gpu_object_array *objs,struct virtio_gpu_fence *fence) { +struct virtio_gpu_object *bo =gem_to_virtio_gpu_obj (objs->objs[0 ]);struct virtio_gpu_transfer_host_3d *cmd_p;struct virtio_gpu_vbuffer *vbuf; cmd_p =virtio_gpu_alloc_cmd (vgdev, &vbuf,sizeof (*cmd_p));memset (cmd_p,0 ,sizeof (*cmd_p)); + vbuf->objs = objs; + cmd_p->hdr.type =cpu_to_le32 (VIRTIO_GPU_CMD_TRANSFER_FROM_HOST_3D ); cmd_p->hdr.ctx_id =cpu_to_le32 (ctx_id); - cmd_p->resource_id =cpu_to_le32 (resource_id); + cmd_p->resource_id =cpu_to_le32 (bo->hw_res_handle); cmd_p->box = *box; cmd_p->offset =cpu_to_le64 (offset); cmd_p->level =cpu_to_le32 (level); --2.18.1
Gerd Hoffmann
maintainerRe: [PATCH v6 14/18] drm/virtio: rework virtio_gpu_transfer_from_host_ioctl fencing
Quoted 6 lines · Chia-I Wu
Quoted 2 lines · Gerd Hoffmann
Switch to the virtio_gpu_array_* helper workflow.
(just repeating my question on patch 6)
Does this fix the obj refcount issue? When was the issue introduced?
obj refcount should be fine in both old and new code.
old code:
drm_gem_object_lookup
drm_gem_object_put_unlocked
new code:
virtio_gpu_array_from_handles virtio_gpu_array_put_free (in virtio_gpu_dequeue_ctrl_func).
Or did I miss something?
cheers,
Gerd
Chia-I Wu
reviewerRe: [PATCH v6 14/18] drm/virtio: rework virtio_gpu_transfer_from_host_ioctl fencing
Quoted 15 lines · Gerd Hoffmann
Quoted 6 lines · Chia-I Wu
Quoted 2 lines · Gerd Hoffmann
Switch to the virtio_gpu_array_* helper workflow.
(just repeating my question on patch 6)
Does this fix the obj refcount issue? When was the issue introduced?
obj refcount should be fine in both old and new code.
old code:
drm_gem_object_lookup
drm_gem_object_put_unlocked
Quoted 5 lines
new code:
virtio_gpu_array_from_handlesvirtio_gpu_array_put_free(invirtio_gpu_dequeue_ctrl_func).Or did I miss something?
In the old code, drm_gem_object_put_unlocked is called before the vbuf using the object is retired. Isn't that what object array wants to fix?
We get away with that because the host only sees hw_res_handles, and executes the commands in order.
Maybe it was me who missed something..?
Quoted 4 lines
cheers,
Gerd
Gerd Hoffmann
maintainerRe: [PATCH v6 14/18] drm/virtio: rework virtio_gpu_transfer_from_host_ioctl fencing
Quoted 16 lines · Chia-I Wu
Quoted 15 lines · Gerd Hoffmann
Quoted 6 lines · Chia-I Wu
Quoted 2 lines · Gerd Hoffmann
Switch to the virtio_gpu_array_* helper workflow.
(just repeating my question on patch 6)
Does this fix the obj refcount issue? When was the issue introduced?
obj refcount should be fine in both old and new code.
old code:
drm_gem_object_lookup
drm_gem_object_put_unlocked
Quoted 8 lines
Quoted 5 lines
new code:
virtio_gpu_array_from_handlesvirtio_gpu_array_put_free(invirtio_gpu_dequeue_ctrl_func).Or did I miss something?
In the old code,
drm_gem_object_put_unlockedis called before the vbuf using the object is retired. Isn't that what object array wants to fix?
I think the fence keeps the bo alive.
cheers,
Gerd
Gerd Hoffmann
maintainerRe: [PATCH v6 14/18] drm/virtio: rework virtio_gpu_transfer_from_host_ioctl fencing
In reply to Chia-I WuQuoted 16 lines · Chia-I Wu
Quoted 15 lines · Gerd Hoffmann
Quoted 6 lines · Chia-I Wu
Quoted 2 lines · Gerd Hoffmann
Switch to the virtio_gpu_array_* helper workflow.
(just repeating my question on patch 6)
Does this fix the obj refcount issue? When was the issue introduced?
obj refcount should be fine in both old and new code.
old code:
drm_gem_object_lookup
drm_gem_object_put_unlocked
Quoted 8 lines
Quoted 5 lines
new code:
virtio_gpu_array_from_handlesvirtio_gpu_array_put_free(invirtio_gpu_dequeue_ctrl_func).Or did I miss something?
In the old code,
drm_gem_object_put_unlockedis called before the vbuf using the object is retired. Isn't that what object array wants to fix?
I think the fence keeps the bo alive.
cheers,
Gerd
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Chia-I Wu
reviewerRe: [PATCH v6 14/18] drm/virtio: rework virtio_gpu_transfer_from_host_ioctl fencing
In reply to Gerd HoffmannQuoted 15 lines · Gerd Hoffmann
Quoted 6 lines · Chia-I Wu
Quoted 2 lines · Gerd Hoffmann
Switch to the virtio_gpu_array_* helper workflow.
(just repeating my question on patch 6)
Does this fix the obj refcount issue? When was the issue introduced?
obj refcount should be fine in both old and new code.
old code:
drm_gem_object_lookup
drm_gem_object_put_unlocked
Quoted 5 lines
new code:
virtio_gpu_array_from_handlesvirtio_gpu_array_put_free(invirtio_gpu_dequeue_ctrl_func).Or did I miss something?
In the old code, drm_gem_object_put_unlocked is called before the vbuf using the object is retired. Isn't that what object array wants to fix?
We get away with that because the host only sees hw_res_handles, and executes the commands in order.
Maybe it was me who missed something..?
Quoted 4 lines
cheers,
Gerd
Gerd Hoffmann
maintainerRe: [PATCH v6 14/18] drm/virtio: rework virtio_gpu_transfer_from_host_ioctl fencing
In reply to Chia-I WuQuoted 6 lines · Chia-I Wu
Quoted 2 lines · Gerd Hoffmann
Switch to the virtio_gpu_array_* helper workflow.
(just repeating my question on patch 6)
Does this fix the obj refcount issue? When was the issue introduced?
obj refcount should be fine in both old and new code.
old code:
drm_gem_object_lookup
drm_gem_object_put_unlocked
new code:
virtio_gpu_array_from_handles virtio_gpu_array_put_free (in virtio_gpu_dequeue_ctrl_func).
Or did I miss something?
cheers,
Gerd
Gerd Hoffmann
maintainerPATCH v6 14/18 drm/virtio: rework virtio_gpu_transfer_from_host_ioctl fencing
In reply to Gerd HoffmannSwitch to the virtio_gpu_array_* helper workflow.
--- drivers/gpu/drm/virtio/virtgpu_drv.h | 3 ++- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 35 +++++++++++--------------- drivers/gpu/drm/virtio/virtgpu_vq.c | 8 ++++-- 3 files changed, 23 insertions(+), 23 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.h +2 -1
@@ -302,9 +302,10 @@ void virtio_gpu_cmd_submit(struct virtio_gpu_device *vgdev,struct virtio_gpu_object_array *objs, struct virtio_gpu_fence *fence);void virtio_gpu_cmd_transfer_from_host_3d (struct virtio_gpu_device *vgdev, -uint32_t resource_id,uint32_t ctx_id, +uint32_t ctx_id,uint64_t offset,uint32_t level,struct virtio_gpu_box *box, +struct virtio_gpu_object_array *objs,struct virtio_gpu_fence *fence); void virtio_gpu_cmd_transfer_to_host_3d(struct virtio_gpu_device *vgdev, struct virtio_gpu_object *bo,
drivers/gpu/drm/virtio/virtgpu_ioctl.c +15 -20
@@ -298,8 +298,7 @@ static int virtio_gpu_transfer_from_host_ioctl(struct drm_device *dev,struct virtio_gpu_device *vgdev = dev->dev_private;struct virtio_gpu_fpriv *vfpriv = file->driver_priv;struct drm_virtgpu_3d_transfer_from_host *args = data; -struct drm_gem_object *gobj =NULL ; -struct virtio_gpu_object *qobj =NULL ; +struct virtio_gpu_object_array *objs;struct virtio_gpu_fence *fence;int ret;u32 offset = args->offset;
@@ -308,35 +307,31 @@ static int virtio_gpu_transfer_from_host_ioctl(struct drm_device *dev,if (vgdev->has_virgl_3d == false)return -ENOSYS ; - gobj =drm_gem_object_lookup (file, args->bo_handle); -if (gobj ==NULL ) + objs =virtio_gpu_array_from_handles (file, &args->bo_handle,1 ); +if (objs ==NULL )return -ENOENT ; - qobj =gem_to_virtio_gpu_obj (gobj); - - ret =virtio_gpu_object_reserve (qobj); -if (ret) - goto out; + ret =virtio_gpu_array_lock_resv (objs); +if (ret !=0 ) + goto err_put_free;convert_to_hw_box (&box, &args->box); fence =virtio_gpu_fence_alloc (vgdev);if (!fence) { ret = -ENOMEM ; - goto out_unres; + goto err_unlock; }virtio_gpu_cmd_transfer_from_host_3d - (vgdev, qobj->hw_res_handle, - vfpriv->ctx_id, offset, args->level, - &box, fence); -reservation_object_add_excl_fence (qobj->base.base.resv, - &fence->f); - + (vgdev, vfpriv->ctx_id, offset, args->level, + &box, objs, fence);dma_fence_put (&fence->f); -out_unres: -virtio_gpu_object_unreserve (qobj); -out: -drm_gem_object_put_unlocked (gobj); +return 0 ; + +err_unlock: +virtio_gpu_array_unlock_resv (objs); +err_put_free: +virtio_gpu_array_put_free (objs);return ret; }
drivers/gpu/drm/virtio/virtgpu_vq.c +6 -2
@@ -928,20 +928,24 @@ void virtio_gpu_cmd_transfer_to_host_3d(struct virtio_gpu_device *vgdev, }void virtio_gpu_cmd_transfer_from_host_3d (struct virtio_gpu_device *vgdev, -uint32_t resource_id,uint32_t ctx_id, +uint32_t ctx_id,uint64_t offset,uint32_t level,struct virtio_gpu_box *box, +struct virtio_gpu_object_array *objs,struct virtio_gpu_fence *fence) { +struct virtio_gpu_object *bo =gem_to_virtio_gpu_obj (objs->objs[0 ]);struct virtio_gpu_transfer_host_3d *cmd_p;struct virtio_gpu_vbuffer *vbuf; cmd_p =virtio_gpu_alloc_cmd (vgdev, &vbuf,sizeof (*cmd_p));memset (cmd_p,0 ,sizeof (*cmd_p)); + vbuf->objs = objs; + cmd_p->hdr.type =cpu_to_le32 (VIRTIO_GPU_CMD_TRANSFER_FROM_HOST_3D ); cmd_p->hdr.ctx_id =cpu_to_le32 (ctx_id); - cmd_p->resource_id =cpu_to_le32 (resource_id); + cmd_p->resource_id =cpu_to_le32 (bo->hw_res_handle); cmd_p->box = *box; cmd_p->offset =cpu_to_le64 (offset); cmd_p->level =cpu_to_le32 (level);
Signature · 1 line
2.18.1
Gerd Hoffmann
maintainerPATCH v6 15/18 drm/virtio: rework virtio_gpu_transfer_to_host_ioctl fencing
In reply to Gerd HoffmannSwitch to the virtio_gpu_array_* helper workflow.
--- drivers/gpu/drm/virtio/virtgpu_drv.h | 2 +- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 43 ++++++++++++-------------- drivers/gpu/drm/virtio/virtgpu_vq.c | 5 ++- 3 files changed, 25 insertions(+), 25 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.h +1 -1
@@ -308,10 +308,10 @@ void virtio_gpu_cmd_transfer_from_host_3d(struct virtio_gpu_device *vgdev,struct virtio_gpu_object_array *objs, struct virtio_gpu_fence *fence);void virtio_gpu_cmd_transfer_to_host_3d (struct virtio_gpu_device *vgdev, -struct virtio_gpu_object *bo,uint32_t ctx_id,uint64_t offset,uint32_t level,struct virtio_gpu_box *box, +struct virtio_gpu_object_array *objs,struct virtio_gpu_fence *fence); void virtio_gpu_cmd_resource_create_3d(struct virtio_gpu_device *vgdev,
drivers/gpu/drm/virtio/virtgpu_ioctl.c +20 -23
67 lines not on this page · raw message
drivers/gpu/drm/virtio/virtgpu_vq.c +4 -1
@@ -899,12 +899,13 @@ virtio_gpu_cmd_resource_create_3d(struct virtio_gpu_device *vgdev, }void virtio_gpu_cmd_transfer_to_host_3d (struct virtio_gpu_device *vgdev, -struct virtio_gpu_object *bo,uint32_t ctx_id,uint64_t offset,uint32_t level,struct virtio_gpu_box *box, +struct virtio_gpu_object_array *objs,struct virtio_gpu_fence *fence) { +struct virtio_gpu_object *bo =gem_to_virtio_gpu_obj (objs->objs[0 ]);struct virtio_gpu_transfer_host_3d *cmd_p;struct virtio_gpu_vbuffer *vbuf;bool use_dma_api = !virtio_has_iommu_quirk (vgdev->vdev);
@@ -917,6 +918,8 @@ void virtio_gpu_cmd_transfer_to_host_3d(struct virtio_gpu_device *vgdev, cmd_p =virtio_gpu_alloc_cmd (vgdev, &vbuf,sizeof (*cmd_p));memset (cmd_p,0 ,sizeof (*cmd_p)); + vbuf->objs = objs; + cmd_p->hdr.type =cpu_to_le32 (VIRTIO_GPU_CMD_TRANSFER_TO_HOST_3D ); cmd_p->hdr.ctx_id =cpu_to_le32 (ctx_id); cmd_p->resource_id =cpu_to_le32 (bo->hw_res_handle);
Signature · 1 line
2.18.1
Chia-I Wu
reviewerRe: [PATCH v6 15/18] drm/virtio: rework virtio_gpu_transfer_to_host_ioctl fencing
Quoted 51 lines · Gerd Hoffmann
Switch to the virtio_gpu_array_* helper workflow.
Signed-off-by Gerd Hoffmann <[email protected]>--- drivers/gpu/drm/virtio/virtgpu_drv.h | 2 +- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 43 ++++++++++++-------------- drivers/gpu/drm/virtio/virtgpu_vq.c | 5 ++- 3 files changed, 25 insertions(+), 25 deletions(-)drivers/gpu/drm/virtio/virtgpu_drv.h +1
-1@@ -308,10 +308,10 @@ void virtio_gpu_cmd_transfer_from_host_3d(struct virtio_gpu_device *vgdev,struct virtio_gpu_object_array *objs, struct virtio_gpu_fence *fence);void virtio_gpu_cmd_transfer_to_host_3d (struct virtio_gpu_device *vgdev, -struct virtio_gpu_object *bo,uint32_t ctx_id,uint64_t offset,uint32_t level,struct virtio_gpu_box *box, +struct virtio_gpu_object_array *objs,struct virtio_gpu_fence *fence); void virtio_gpu_cmd_resource_create_3d(struct virtio_gpu_device *vgdev,drivers/gpu/drm/virtio/virtgpu_ioctl.c +3
-7@@ -341,47 +341,44 @@ static int virtio_gpu_transfer_to_host_ioctl(struct drm_device *dev, void *data,struct virtio_gpu_device *vgdev = dev->dev_private;struct virtio_gpu_fpriv *vfpriv = file->driver_priv;struct drm_virtgpu_3d_transfer_to_host *args = data; -struct drm_gem_object *gobj =NULL ; -struct virtio_gpu_object *qobj =NULL ; +struct virtio_gpu_object_array *objs;struct virtio_gpu_fence *fence;struct virtio_gpu_box box;int ret;u32 offset = args->offset; - gobj =drm_gem_object_lookup (file, args->bo_handle); -if (gobj ==NULL ) + objs =virtio_gpu_array_from_handles (file, &args->bo_handle,1 ); +if (objs ==NULL )return -ENOENT ; - qobj =gem_to_virtio_gpu_obj (gobj); - - ret =virtio_gpu_object_reserve (qobj);
drivers/gpu/drm/virtio/virtgpu_ioctl.c static int virtio_gpu_transfer_to_host_ioctl(struct drm_device *dev, void *data, · line 359
Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c +2
-4-if (ret) - goto out; -convert_to_hw_box (&box, &args->box);if (!vgdev->has_virgl_3d) {virtio_gpu_cmd_transfer_to_host_2d - (vgdev, qobj, offset, + (vgdev,gem_to_virtio_gpu_obj (objs->objs[0 ]), offset, box.w, box.h, box.x, box.y,NULL ); +virtio_gpu_array_put_free (objs);
Don't we need this in non-3D case as well?
Quoted 68 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c +15
-12}else { + ret =virtio_gpu_array_lock_resv (objs); +if (ret !=0 ) + goto err_put_free; + + ret = -ENOMEM ; fence =virtio_gpu_fence_alloc (vgdev); -if (!fence) { - ret = -ENOMEM ; - goto out_unres; - } +if (!fence) + goto err_unlock; +virtio_gpu_cmd_transfer_to_host_3d - (vgdev, qobj, + (vgdev, vfpriv ? vfpriv->ctx_id :0 , offset, - args->level, &box, fence); -reservation_object_add_excl_fence (qobj->base.base.resv, - &fence->f); + args->level, &box, objs, fence);dma_fence_put (&fence->f); } +return 0 ; -out_unres: -virtio_gpu_object_unreserve (qobj); -out: -drm_gem_object_put_unlocked (gobj); +err_unlock: +virtio_gpu_array_unlock_resv (objs); +err_put_free: +virtio_gpu_array_put_free (objs);return ret; }drivers/gpu/drm/virtio/virtgpu_vq.c +4
-2@@ -899,12 +899,13 @@ virtio_gpu_cmd_resource_create_3d(struct virtio_gpu_device *vgdev, }void virtio_gpu_cmd_transfer_to_host_3d (struct virtio_gpu_device *vgdev, -struct virtio_gpu_object *bo,uint32_t ctx_id,uint64_t offset,uint32_t level,struct virtio_gpu_box *box, +struct virtio_gpu_object_array *objs,struct virtio_gpu_fence *fence) { +struct virtio_gpu_object *bo =gem_to_virtio_gpu_obj (objs->objs[0 ]);struct virtio_gpu_transfer_host_3d *cmd_p;struct virtio_gpu_vbuffer *vbuf;bool use_dma_api = !virtio_has_iommu_quirk (vgdev->vdev);@@ -917,6 +918,8 @@ void virtio_gpu_cmd_transfer_to_host_3d(struct virtio_gpu_device *vgdev, cmd_p =virtio_gpu_alloc_cmd (vgdev, &vbuf,sizeof (*cmd_p));memset (cmd_p,0 ,sizeof (*cmd_p)); + vbuf->objs = objs; + cmd_p->hdr.type =cpu_to_le32 (VIRTIO_GPU_CMD_TRANSFER_TO_HOST_3D ); cmd_p->hdr.ctx_id =cpu_to_le32 (ctx_id); cmd_p->resource_id =cpu_to_le32 (bo->hw_res_handle); --2.18.1
Gerd Hoffmann
maintainerRe: [PATCH v6 15/18] drm/virtio: rework virtio_gpu_transfer_to_host_ioctl fencing
Hi,
Quoted 8 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c static int virtio_gpu_transfer_to_host_ioctl(struct drm_device *dev, void *data, · line 359
Quoted 7 lines
convert_to_hw_box(&box, &args->box); if (!vgdev->has_virgl_3d) { virtio_gpu_cmd_transfer_to_host_2ddrivers/gpu/drm/virtio/virtgpu_ioctl.c +2
-1- (vgdev, qobj, offset, + (vgdev,gem_to_virtio_gpu_obj (objs->objs[0 ]), offset, box.w, box.h, box.x, box.y,NULL ); +virtio_gpu_array_put_free (objs);Don't we need this in non-3D case as well?
No, ...
Quoted 8 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c static int virtio_gpu_transfer_to_host_ioctl(struct drm_device *dev, void *data, · line 373
Quoted 8 lines
virtio_gpu_cmd_transfer_to_host_3ddrivers/gpu/drm/virtio/virtgpu_ioctl.c +2
-4- (vgdev, qobj, + (vgdev, vfpriv ? vfpriv->ctx_id :0 , offset, - args->level, &box, fence); -reservation_object_add_excl_fence (qobj->base.base.resv, - &fence->f); + args->level, &box, objs, fence);
... 3d case passes the objs list to virtio_gpu_cmd_transfer_to_host_3d, so it gets added to the vbuf and released when the command is finished.
cheers,
Gerd
Chia-I Wu
reviewerRe: [PATCH v6 15/18] drm/virtio: rework virtio_gpu_transfer_to_host_ioctl fencing
Quoted 23 lines · Gerd Hoffmann
Hi,
Quoted 8 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c static int virtio_gpu_transfer_to_host_ioctl(struct drm_device *dev, void *data, · line 359
Quoted 7 lines
convert_to_hw_box(&box, &args->box); if (!vgdev->has_virgl_3d) { virtio_gpu_cmd_transfer_to_host_2ddrivers/gpu/drm/virtio/virtgpu_ioctl.c +2
-1- (vgdev, qobj, offset, + (vgdev,gem_to_virtio_gpu_obj (objs->objs[0 ]), offset, box.w, box.h, box.x, box.y,NULL ); +virtio_gpu_array_put_free (objs);Don't we need this in non-3D case as well?
No, ...
Quoted 8 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c static int virtio_gpu_transfer_to_host_ioctl(struct drm_device *dev, void *data, · line 373
Quoted 8 lines
virtio_gpu_cmd_transfer_to_host_3ddrivers/gpu/drm/virtio/virtgpu_ioctl.c +2
-4- (vgdev, qobj, + (vgdev, vfpriv ? vfpriv->ctx_id :0 , offset, - args->level, &box, fence); -reservation_object_add_excl_fence (qobj->base.base.resv, - &fence->f); + args->level, &box, objs, fence);
Quoted 2 lines
... 3d case passes the objs list to
virtio_gpu_cmd_transfer_to_host_3d, so it gets added to the vbuf and released when the command is finished.
Why doesn't this apply to virtio_gpu_cmd_transfer_to_host_2d?
When object array was introduced, it was said that the object array was to keep the objects alive until the vbuf using the objects is retired.. That sounded applicable to any vbuf that uses objects.
Quoted 4 lines
cheers,
Gerd
Chia-I Wu
reviewerRe: [PATCH v6 15/18] drm/virtio: rework virtio_gpu_transfer_to_host_ioctl fencing
In reply to Gerd HoffmannQuoted 23 lines · Gerd Hoffmann
Hi,
Quoted 8 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c static int virtio_gpu_transfer_to_host_ioctl(struct drm_device *dev, void *data, · line 359
Quoted 7 lines
convert_to_hw_box(&box, &args->box); if (!vgdev->has_virgl_3d) { virtio_gpu_cmd_transfer_to_host_2ddrivers/gpu/drm/virtio/virtgpu_ioctl.c +2
-1- (vgdev, qobj, offset, + (vgdev,gem_to_virtio_gpu_obj (objs->objs[0 ]), offset, box.w, box.h, box.x, box.y,NULL ); +virtio_gpu_array_put_free (objs);Don't we need this in non-3D case as well?
No, ...
Quoted 8 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c static int virtio_gpu_transfer_to_host_ioctl(struct drm_device *dev, void *data, · line 373
Quoted 8 lines
virtio_gpu_cmd_transfer_to_host_3ddrivers/gpu/drm/virtio/virtgpu_ioctl.c +2
-4- (vgdev, qobj, + (vgdev, vfpriv ? vfpriv->ctx_id :0 , offset, - args->level, &box, fence); -reservation_object_add_excl_fence (qobj->base.base.resv, - &fence->f); + args->level, &box, objs, fence);
Quoted 2 lines
... 3d case passes the objs list to
virtio_gpu_cmd_transfer_to_host_3d, so it gets added to the vbuf and released when the command is finished.
Why doesn't this apply to virtio_gpu_cmd_transfer_to_host_2d?
When object array was introduced, it was said that the object array was to keep the objects alive until the vbuf using the objects is retired.. That sounded applicable to any vbuf that uses objects.
Quoted 4 lines
cheers,
Gerd
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Gerd Hoffmann
maintainerRe: [PATCH v6 15/18] drm/virtio: rework virtio_gpu_transfer_to_host_ioctl fencing
Quoted 24 lines · Chia-I Wu
Quoted 23 lines · Gerd Hoffmann
Hi,
Quoted 8 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c static int virtio_gpu_transfer_to_host_ioctl(struct drm_device *dev, void *data, · line 359
Quoted 7 lines
convert_to_hw_box(&box, &args->box); if (!vgdev->has_virgl_3d) { virtio_gpu_cmd_transfer_to_host_2ddrivers/gpu/drm/virtio/virtgpu_ioctl.c +2
-1- (vgdev, qobj, offset, + (vgdev,gem_to_virtio_gpu_obj (objs->objs[0 ]), offset, box.w, box.h, box.x, box.y,NULL ); +virtio_gpu_array_put_free (objs);Don't we need this in non-3D case as well?
No, ...
Quoted 8 lines
Quoted 8 lines
virtio_gpu_cmd_transfer_to_host_3ddrivers/gpu/drm/virtio/virtgpu_ioctl.c +2
-4- (vgdev, qobj, + (vgdev, vfpriv ? vfpriv->ctx_id :0 , offset, - args->level, &box, fence); -reservation_object_add_excl_fence (qobj->base.base.resv, - &fence->f); + args->level, &box, objs, fence);
Quoted 3 lines
Quoted 2 lines
... 3d case passes the objs list to
virtio_gpu_cmd_transfer_to_host_3d, so it gets added to the vbuf and released when the command is finished.Why doesn't this apply to
virtio_gpu_cmd_transfer_to_host_2d?
Hmm, yes, makes sense to handle both the same way.
With virgl=off qemu processes the commands from the guest synchronously, so it'll work fine as-is. So you can't hit the theoretical race window in practice. But depending on that host-side implementation detail isn't a good idea indeed.
cheers,
Gerd
Gerd Hoffmann
maintainerRe: [PATCH v6 15/18] drm/virtio: rework virtio_gpu_transfer_to_host_ioctl fencing
Quoted 11 lines
Quoted 3 lines
Quoted 2 lines
... 3d case passes the objs list to
virtio_gpu_cmd_transfer_to_host_3d, so it gets added to the vbuf and released when the command is finished.Why doesn't this apply to
virtio_gpu_cmd_transfer_to_host_2d?Hmm, yes, makes sense to handle both the same way.
With virgl=off qemu processes the commands from the guest synchronously, so it'll work fine as-is. So you can't hit the theoretical race window in practice. But depending on that host-side implementation detail isn't a good idea indeed.
Branch with incremental fixes:
https://git.kraxel.org/cgit/linux/log/?h=drm-virtio-kill-ttm
I'll be offline three weeks now, will resume this when I'm back.
cheers,
Gerd
Gerd Hoffmann
maintainerRe: [PATCH v6 15/18] drm/virtio: rework virtio_gpu_transfer_to_host_ioctl fencing
In reply to Chia-I WuQuoted 24 lines · Chia-I Wu
Quoted 23 lines · Gerd Hoffmann
Hi,
Quoted 8 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c static int virtio_gpu_transfer_to_host_ioctl(struct drm_device *dev, void *data, · line 359
Quoted 7 lines
convert_to_hw_box(&box, &args->box); if (!vgdev->has_virgl_3d) { virtio_gpu_cmd_transfer_to_host_2ddrivers/gpu/drm/virtio/virtgpu_ioctl.c +2
-1- (vgdev, qobj, offset, + (vgdev,gem_to_virtio_gpu_obj (objs->objs[0 ]), offset, box.w, box.h, box.x, box.y,NULL ); +virtio_gpu_array_put_free (objs);Don't we need this in non-3D case as well?
No, ...
Quoted 8 lines
Quoted 8 lines
virtio_gpu_cmd_transfer_to_host_3ddrivers/gpu/drm/virtio/virtgpu_ioctl.c +2
-4- (vgdev, qobj, + (vgdev, vfpriv ? vfpriv->ctx_id :0 , offset, - args->level, &box, fence); -reservation_object_add_excl_fence (qobj->base.base.resv, - &fence->f); + args->level, &box, objs, fence);
Quoted 3 lines
Quoted 2 lines
... 3d case passes the objs list to
virtio_gpu_cmd_transfer_to_host_3d, so it gets added to the vbuf and released when the command is finished.Why doesn't this apply to
virtio_gpu_cmd_transfer_to_host_2d?
Hmm, yes, makes sense to handle both the same way.
With virgl=off qemu processes the commands from the guest synchronously, so it'll work fine as-is. So you can't hit the theoretical race window in practice. But depending on that host-side implementation detail isn't a good idea indeed.
cheers,
Gerd
Gerd Hoffmann
maintainerRe: [PATCH v6 15/18] drm/virtio: rework virtio_gpu_transfer_to_host_ioctl fencing
In reply to Chia-I WuHi,
Quoted 8 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c static int virtio_gpu_transfer_to_host_ioctl(struct drm_device *dev, void *data, · line 359
Quoted 7 lines
convert_to_hw_box(&box, &args->box); if (!vgdev->has_virgl_3d) { virtio_gpu_cmd_transfer_to_host_2ddrivers/gpu/drm/virtio/virtgpu_ioctl.c +2
-1- (vgdev, qobj, offset, + (vgdev,gem_to_virtio_gpu_obj (objs->objs[0 ]), offset, box.w, box.h, box.x, box.y,NULL ); +virtio_gpu_array_put_free (objs);Don't we need this in non-3D case as well?
No, ...
Quoted 8 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c static int virtio_gpu_transfer_to_host_ioctl(struct drm_device *dev, void *data, · line 373
Quoted 8 lines
virtio_gpu_cmd_transfer_to_host_3ddrivers/gpu/drm/virtio/virtgpu_ioctl.c +2
-4- (vgdev, qobj, + (vgdev, vfpriv ? vfpriv->ctx_id :0 , offset, - args->level, &box, fence); -reservation_object_add_excl_fence (qobj->base.base.resv, - &fence->f); + args->level, &box, objs, fence);
... 3d case passes the objs list to virtio_gpu_cmd_transfer_to_host_3d, so it gets added to the vbuf and released when the command is finished.
cheers,
Gerd
Chia-I Wu
reviewerRe: [PATCH v6 15/18] drm/virtio: rework virtio_gpu_transfer_to_host_ioctl fencing
In reply to Gerd HoffmannQuoted 51 lines · Gerd Hoffmann
Switch to the virtio_gpu_array_* helper workflow.
Signed-off-by Gerd Hoffmann <[email protected]>--- drivers/gpu/drm/virtio/virtgpu_drv.h | 2 +- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 43 ++++++++++++-------------- drivers/gpu/drm/virtio/virtgpu_vq.c | 5 ++- 3 files changed, 25 insertions(+), 25 deletions(-)drivers/gpu/drm/virtio/virtgpu_drv.h +1
-1@@ -308,10 +308,10 @@ void virtio_gpu_cmd_transfer_from_host_3d(struct virtio_gpu_device *vgdev,struct virtio_gpu_object_array *objs, struct virtio_gpu_fence *fence);void virtio_gpu_cmd_transfer_to_host_3d (struct virtio_gpu_device *vgdev, -struct virtio_gpu_object *bo,uint32_t ctx_id,uint64_t offset,uint32_t level,struct virtio_gpu_box *box, +struct virtio_gpu_object_array *objs,struct virtio_gpu_fence *fence); void virtio_gpu_cmd_resource_create_3d(struct virtio_gpu_device *vgdev,drivers/gpu/drm/virtio/virtgpu_ioctl.c +3
-7@@ -341,47 +341,44 @@ static int virtio_gpu_transfer_to_host_ioctl(struct drm_device *dev, void *data,struct virtio_gpu_device *vgdev = dev->dev_private;struct virtio_gpu_fpriv *vfpriv = file->driver_priv;struct drm_virtgpu_3d_transfer_to_host *args = data; -struct drm_gem_object *gobj =NULL ; -struct virtio_gpu_object *qobj =NULL ; +struct virtio_gpu_object_array *objs;struct virtio_gpu_fence *fence;struct virtio_gpu_box box;int ret;u32 offset = args->offset; - gobj =drm_gem_object_lookup (file, args->bo_handle); -if (gobj ==NULL ) + objs =virtio_gpu_array_from_handles (file, &args->bo_handle,1 ); +if (objs ==NULL )return -ENOENT ; - qobj =gem_to_virtio_gpu_obj (gobj); - - ret =virtio_gpu_object_reserve (qobj);
drivers/gpu/drm/virtio/virtgpu_ioctl.c static int virtio_gpu_transfer_to_host_ioctl(struct drm_device *dev, void *data, · line 359
Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c +2
-4-if (ret) - goto out; -convert_to_hw_box (&box, &args->box);if (!vgdev->has_virgl_3d) {virtio_gpu_cmd_transfer_to_host_2d - (vgdev, qobj, offset, + (vgdev,gem_to_virtio_gpu_obj (objs->objs[0 ]), offset, box.w, box.h, box.x, box.y,NULL ); +virtio_gpu_array_put_free (objs);
Don't we need this in non-3D case as well?
Quoted 68 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c +15
-12}else { + ret =virtio_gpu_array_lock_resv (objs); +if (ret !=0 ) + goto err_put_free; + + ret = -ENOMEM ; fence =virtio_gpu_fence_alloc (vgdev); -if (!fence) { - ret = -ENOMEM ; - goto out_unres; - } +if (!fence) + goto err_unlock; +virtio_gpu_cmd_transfer_to_host_3d - (vgdev, qobj, + (vgdev, vfpriv ? vfpriv->ctx_id :0 , offset, - args->level, &box, fence); -reservation_object_add_excl_fence (qobj->base.base.resv, - &fence->f); + args->level, &box, objs, fence);dma_fence_put (&fence->f); } +return 0 ; -out_unres: -virtio_gpu_object_unreserve (qobj); -out: -drm_gem_object_put_unlocked (gobj); +err_unlock: +virtio_gpu_array_unlock_resv (objs); +err_put_free: +virtio_gpu_array_put_free (objs);return ret; }drivers/gpu/drm/virtio/virtgpu_vq.c +4
-2@@ -899,12 +899,13 @@ virtio_gpu_cmd_resource_create_3d(struct virtio_gpu_device *vgdev, }void virtio_gpu_cmd_transfer_to_host_3d (struct virtio_gpu_device *vgdev, -struct virtio_gpu_object *bo,uint32_t ctx_id,uint64_t offset,uint32_t level,struct virtio_gpu_box *box, +struct virtio_gpu_object_array *objs,struct virtio_gpu_fence *fence) { +struct virtio_gpu_object *bo =gem_to_virtio_gpu_obj (objs->objs[0 ]);struct virtio_gpu_transfer_host_3d *cmd_p;struct virtio_gpu_vbuffer *vbuf;bool use_dma_api = !virtio_has_iommu_quirk (vgdev->vdev);@@ -917,6 +918,8 @@ void virtio_gpu_cmd_transfer_to_host_3d(struct virtio_gpu_device *vgdev, cmd_p =virtio_gpu_alloc_cmd (vgdev, &vbuf,sizeof (*cmd_p));memset (cmd_p,0 ,sizeof (*cmd_p)); + vbuf->objs = objs; + cmd_p->hdr.type =cpu_to_le32 (VIRTIO_GPU_CMD_TRANSFER_TO_HOST_3D ); cmd_p->hdr.ctx_id =cpu_to_le32 (ctx_id); cmd_p->resource_id =cpu_to_le32 (bo->hw_res_handle); --2.18.1
Gerd Hoffmann
maintainerPATCH v6 15/18 drm/virtio: rework virtio_gpu_transfer_to_host_ioctl fencing
In reply to Gerd HoffmannSwitch to the virtio_gpu_array_* helper workflow.
--- drivers/gpu/drm/virtio/virtgpu_drv.h | 2 +- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 43 ++++++++++++-------------- drivers/gpu/drm/virtio/virtgpu_vq.c | 5 ++- 3 files changed, 25 insertions(+), 25 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.h +1 -1
@@ -308,10 +308,10 @@ void virtio_gpu_cmd_transfer_from_host_3d(struct virtio_gpu_device *vgdev,struct virtio_gpu_object_array *objs, struct virtio_gpu_fence *fence);void virtio_gpu_cmd_transfer_to_host_3d (struct virtio_gpu_device *vgdev, -struct virtio_gpu_object *bo,uint32_t ctx_id,uint64_t offset,uint32_t level,struct virtio_gpu_box *box, +struct virtio_gpu_object_array *objs,struct virtio_gpu_fence *fence); void virtio_gpu_cmd_resource_create_3d(struct virtio_gpu_device *vgdev,
drivers/gpu/drm/virtio/virtgpu_ioctl.c +20 -23
67 lines not on this page · raw message
drivers/gpu/drm/virtio/virtgpu_vq.c +4 -1
@@ -899,12 +899,13 @@ virtio_gpu_cmd_resource_create_3d(struct virtio_gpu_device *vgdev, }void virtio_gpu_cmd_transfer_to_host_3d (struct virtio_gpu_device *vgdev, -struct virtio_gpu_object *bo,uint32_t ctx_id,uint64_t offset,uint32_t level,struct virtio_gpu_box *box, +struct virtio_gpu_object_array *objs,struct virtio_gpu_fence *fence) { +struct virtio_gpu_object *bo =gem_to_virtio_gpu_obj (objs->objs[0 ]);struct virtio_gpu_transfer_host_3d *cmd_p;struct virtio_gpu_vbuffer *vbuf;bool use_dma_api = !virtio_has_iommu_quirk (vgdev->vdev);
@@ -917,6 +918,8 @@ void virtio_gpu_cmd_transfer_to_host_3d(struct virtio_gpu_device *vgdev, cmd_p =virtio_gpu_alloc_cmd (vgdev, &vbuf,sizeof (*cmd_p));memset (cmd_p,0 ,sizeof (*cmd_p)); + vbuf->objs = objs; + cmd_p->hdr.type =cpu_to_le32 (VIRTIO_GPU_CMD_TRANSFER_TO_HOST_3D ); cmd_p->hdr.ctx_id =cpu_to_le32 (ctx_id); cmd_p->resource_id =cpu_to_le32 (bo->hw_res_handle);
Signature · 1 line
2.18.1
Gerd Hoffmann
maintainerPATCH v6 16/18 drm/virtio: rework virtio_gpu_cmd_context_{attach, detach}_resource
In reply to Gerd HoffmannSwitch to the virtio_gpu_array_* helper workflow.
--- drivers/gpu/drm/virtio/virtgpu_drv.h | 4 ++-- drivers/gpu/drm/virtio/virtgpu_gem.c | 24 +++++++++++------------- drivers/gpu/drm/virtio/virtgpu_vq.c | 10 ++++++---- 3 files changed, 19 insertions(+), 19 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.h +2 -2
@@ -292,10 +292,10 @@ void virtio_gpu_cmd_context_destroy(struct virtio_gpu_device *vgdev, uint32_t id);void virtio_gpu_cmd_context_attach_resource (struct virtio_gpu_device *vgdev,uint32_t ctx_id, -uint32_t resource_id); +struct virtio_gpu_object_array *objs);void virtio_gpu_cmd_context_detach_resource (struct virtio_gpu_device *vgdev,uint32_t ctx_id, -uint32_t resource_id); +struct virtio_gpu_object_array *objs); void virtio_gpu_cmd_submit(struct virtio_gpu_device *vgdev, void *data, uint32_t data_size, uint32_t ctx_id,
drivers/gpu/drm/virtio/virtgpu_gem.c +11 -13
@@ -111,19 +111,18 @@ int virtio_gpu_gem_object_open(struct drm_gem_object *obj, {struct virtio_gpu_device *vgdev = obj->dev->dev_private;struct virtio_gpu_fpriv *vfpriv = file->driver_priv; -struct virtio_gpu_object *qobj =gem_to_virtio_gpu_obj (obj); -int r; +struct virtio_gpu_object_array *objs;if (!vgdev->has_virgl_3d)return 0 ; - r =virtio_gpu_object_reserve (qobj); -if (r) -return r; + objs =virtio_gpu_array_alloc (1 ); +if (!objs) +return -ENOMEM ; +virtio_gpu_array_add_obj (objs, obj);virtio_gpu_cmd_context_attach_resource (vgdev, vfpriv->ctx_id, - qobj->hw_res_handle); -virtio_gpu_object_unreserve (qobj); + objs);return 0 ; }
@@ -132,19 +131,18 @@ void virtio_gpu_gem_object_close(struct drm_gem_object *obj, {struct virtio_gpu_device *vgdev = obj->dev->dev_private;struct virtio_gpu_fpriv *vfpriv = file->driver_priv; -struct virtio_gpu_object *qobj =gem_to_virtio_gpu_obj (obj); -int r; +struct virtio_gpu_object_array *objs;if (!vgdev->has_virgl_3d)return ; - r =virtio_gpu_object_reserve (qobj); -if (r) + objs =virtio_gpu_array_alloc (1 ); +if (!objs)return ; +virtio_gpu_array_add_obj (objs, obj);virtio_gpu_cmd_context_detach_resource (vgdev, vfpriv->ctx_id, - qobj->hw_res_handle); -virtio_gpu_object_unreserve (qobj); + objs); }struct virtio_gpu_object_array *virtio_gpu_array_alloc (u32 nents)
drivers/gpu/drm/virtio/virtgpu_vq.c +6 -4
@@ -835,8 +835,9 @@ void virtio_gpu_cmd_context_destroy(struct virtio_gpu_device *vgdev,void virtio_gpu_cmd_context_attach_resource (struct virtio_gpu_device *vgdev,uint32_t ctx_id, -uint32_t resource_id) +struct virtio_gpu_object_array *objs) { +struct virtio_gpu_object *bo =gem_to_virtio_gpu_obj (objs->objs[0 ]);struct virtio_gpu_ctx_resource *cmd_p;struct virtio_gpu_vbuffer *vbuf;
@@ -845,15 +846,16 @@ void virtio_gpu_cmd_context_attach_resource(struct virtio_gpu_device *vgdev, cmd_p->hdr.type =cpu_to_le32 (VIRTIO_GPU_CMD_CTX_ATTACH_RESOURCE ); cmd_p->hdr.ctx_id =cpu_to_le32 (ctx_id); - cmd_p->resource_id =cpu_to_le32 (resource_id); + cmd_p->resource_id =cpu_to_le32 (bo->hw_res_handle);virtio_gpu_queue_ctrl_buffer (vgdev, vbuf); }void virtio_gpu_cmd_context_detach_resource (struct virtio_gpu_device *vgdev,uint32_t ctx_id, -uint32_t resource_id) +struct virtio_gpu_object_array *objs) { +struct virtio_gpu_object *bo =gem_to_virtio_gpu_obj (objs->objs[0 ]);struct virtio_gpu_ctx_resource *cmd_p;struct virtio_gpu_vbuffer *vbuf;
@@ -862,7 +864,7 @@ void virtio_gpu_cmd_context_detach_resource(struct virtio_gpu_device *vgdev, cmd_p->hdr.type =cpu_to_le32 (VIRTIO_GPU_CMD_CTX_DETACH_RESOURCE ); cmd_p->hdr.ctx_id =cpu_to_le32 (ctx_id); - cmd_p->resource_id =cpu_to_le32 (resource_id); + cmd_p->resource_id =cpu_to_le32 (bo->hw_res_handle);virtio_gpu_queue_ctrl_buffer (vgdev, vbuf); }
Signature · 1 line
2.18.1
Gerd Hoffmann
maintainerPATCH v6 16/18 drm/virtio: rework virtio_gpu_cmd_context_{attach,detach}_resource
In reply to Gerd HoffmannSwitch to the virtio_gpu_array_* helper workflow.
--- drivers/gpu/drm/virtio/virtgpu_drv.h | 4 ++-- drivers/gpu/drm/virtio/virtgpu_gem.c | 24 +++++++++++------------- drivers/gpu/drm/virtio/virtgpu_vq.c | 10 ++++++---- 3 files changed, 19 insertions(+), 19 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.h +2 -2
@@ -292,10 +292,10 @@ void virtio_gpu_cmd_context_destroy(struct virtio_gpu_device *vgdev, uint32_t id);void virtio_gpu_cmd_context_attach_resource (struct virtio_gpu_device *vgdev,uint32_t ctx_id, -uint32_t resource_id); +struct virtio_gpu_object_array *objs);void virtio_gpu_cmd_context_detach_resource (struct virtio_gpu_device *vgdev,uint32_t ctx_id, -uint32_t resource_id); +struct virtio_gpu_object_array *objs); void virtio_gpu_cmd_submit(struct virtio_gpu_device *vgdev, void *data, uint32_t data_size, uint32_t ctx_id,
drivers/gpu/drm/virtio/virtgpu_gem.c +11 -13
@@ -111,19 +111,18 @@ int virtio_gpu_gem_object_open(struct drm_gem_object *obj, {struct virtio_gpu_device *vgdev = obj->dev->dev_private;struct virtio_gpu_fpriv *vfpriv = file->driver_priv; -struct virtio_gpu_object *qobj =gem_to_virtio_gpu_obj (obj); -int r; +struct virtio_gpu_object_array *objs;if (!vgdev->has_virgl_3d)return 0 ; - r =virtio_gpu_object_reserve (qobj); -if (r) -return r; + objs =virtio_gpu_array_alloc (1 ); +if (!objs) +return -ENOMEM ; +virtio_gpu_array_add_obj (objs, obj);virtio_gpu_cmd_context_attach_resource (vgdev, vfpriv->ctx_id, - qobj->hw_res_handle); -virtio_gpu_object_unreserve (qobj); + objs);return 0 ; }
@@ -132,19 +131,18 @@ void virtio_gpu_gem_object_close(struct drm_gem_object *obj, {struct virtio_gpu_device *vgdev = obj->dev->dev_private;struct virtio_gpu_fpriv *vfpriv = file->driver_priv; -struct virtio_gpu_object *qobj =gem_to_virtio_gpu_obj (obj); -int r; +struct virtio_gpu_object_array *objs;if (!vgdev->has_virgl_3d)return ; - r =virtio_gpu_object_reserve (qobj); -if (r) + objs =virtio_gpu_array_alloc (1 ); +if (!objs)return ; +virtio_gpu_array_add_obj (objs, obj);virtio_gpu_cmd_context_detach_resource (vgdev, vfpriv->ctx_id, - qobj->hw_res_handle); -virtio_gpu_object_unreserve (qobj); + objs); }struct virtio_gpu_object_array *virtio_gpu_array_alloc (u32 nents)
drivers/gpu/drm/virtio/virtgpu_vq.c +6 -4
@@ -835,8 +835,9 @@ void virtio_gpu_cmd_context_destroy(struct virtio_gpu_device *vgdev,void virtio_gpu_cmd_context_attach_resource (struct virtio_gpu_device *vgdev,uint32_t ctx_id, -uint32_t resource_id) +struct virtio_gpu_object_array *objs) { +struct virtio_gpu_object *bo =gem_to_virtio_gpu_obj (objs->objs[0 ]);struct virtio_gpu_ctx_resource *cmd_p;struct virtio_gpu_vbuffer *vbuf;
@@ -845,15 +846,16 @@ void virtio_gpu_cmd_context_attach_resource(struct virtio_gpu_device *vgdev, cmd_p->hdr.type =cpu_to_le32 (VIRTIO_GPU_CMD_CTX_ATTACH_RESOURCE ); cmd_p->hdr.ctx_id =cpu_to_le32 (ctx_id); - cmd_p->resource_id =cpu_to_le32 (resource_id); + cmd_p->resource_id =cpu_to_le32 (bo->hw_res_handle);virtio_gpu_queue_ctrl_buffer (vgdev, vbuf); }void virtio_gpu_cmd_context_detach_resource (struct virtio_gpu_device *vgdev,uint32_t ctx_id, -uint32_t resource_id) +struct virtio_gpu_object_array *objs) { +struct virtio_gpu_object *bo =gem_to_virtio_gpu_obj (objs->objs[0 ]);struct virtio_gpu_ctx_resource *cmd_p;struct virtio_gpu_vbuffer *vbuf;
@@ -862,7 +864,7 @@ void virtio_gpu_cmd_context_detach_resource(struct virtio_gpu_device *vgdev, cmd_p->hdr.type =cpu_to_le32 (VIRTIO_GPU_CMD_CTX_DETACH_RESOURCE ); cmd_p->hdr.ctx_id =cpu_to_le32 (ctx_id); - cmd_p->resource_id =cpu_to_le32 (resource_id); + cmd_p->resource_id =cpu_to_le32 (bo->hw_res_handle);virtio_gpu_queue_ctrl_buffer (vgdev, vbuf); }
Signature · 6 lines
2.18.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Gurchetan Singh
reviewerRe: [PATCH v6 16/18] drm/virtio: rework virtio_gpu_cmd_context_{attach, detach}_resource
Quoted 73 lines · Gerd Hoffmann
Switch to the virtio_gpu_array_* helper workflow.
Signed-off-by Gerd Hoffmann <[email protected]>--- drivers/gpu/drm/virtio/virtgpu_drv.h | 4 ++-- drivers/gpu/drm/virtio/virtgpu_gem.c | 24 +++++++++++------------- drivers/gpu/drm/virtio/virtgpu_vq.c | 10 ++++++---- 3 files changed, 19 insertions(+), 19 deletions(-)drivers/gpu/drm/virtio/virtgpu_drv.h +2
-2@@ -292,10 +292,10 @@ void virtio_gpu_cmd_context_destroy(structvirtio_gpu_device *vgdev, uint32_t id);void virtio_gpu_cmd_context_attach_resource (struct virtio_gpu_device *vgdev,uint32_t ctx_id, -uint32_t resource_id); +struct virtio_gpu_object_array *objs);void virtio_gpu_cmd_context_detach_resource (struct virtio_gpu_device *vgdev,uint32_t ctx_id, -uint32_t resource_id); + struct virtio_gpu_object_array*objs);
void virtio_gpu_cmd_submit(structvirtio_gpu_device*vgdev,
void *data,uint32_tdata_size,uint32_tctx_id,drivers/gpu/drm/virtio/virtgpu_gem.c +7
-9@@ -111,19 +111,18 @@ int virtio_gpu_gem_object_open(struct drm_gem_object *obj, {struct virtio_gpu_device *vgdev = obj->dev->dev_private;struct virtio_gpu_fpriv *vfpriv = file->driver_priv; -struct virtio_gpu_object *qobj =gem_to_virtio_gpu_obj (obj); -int r; +struct virtio_gpu_object_array *objs;if (!vgdev->has_virgl_3d)return 0 ; - r =virtio_gpu_object_reserve (qobj); -if (r) -return r; + objs =virtio_gpu_array_alloc (1 ); +if (!objs) +return -ENOMEM ; +virtio_gpu_array_add_obj (objs, obj);virtio_gpu_cmd_context_attach_resource (vgdev, vfpriv->ctx_id, - qobj->hw_res_handle); -virtio_gpu_object_unreserve (qobj); + objs);return 0 ; }@@ -132,19 +131,18 @@ void virtio_gpu_gem_object_close(struct drm_gem_object *obj, {struct virtio_gpu_device *vgdev = obj->dev->dev_private;struct virtio_gpu_fpriv *vfpriv = file->driver_priv; -struct virtio_gpu_object *qobj =gem_to_virtio_gpu_obj (obj); -int r; +struct virtio_gpu_object_array *objs;
drivers/gpu/drm/virtio/virtgpu_gem.c void virtio_gpu_gem_object_close(struct · line 144
Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_gem.c +3
-2if (!vgdev->has_virgl_3d)return ; - r =virtio_gpu_object_reserve (qobj); -if (r) + objs =virtio_gpu_array_alloc (1 ); +if (!objs)return ; +virtio_gpu_array_add_obj (objs, obj);
This seems to call drm_gem_object_get. Without adding the objects to the vbuf, aren't we missing the corresponding drm_gem_object_put_unlocked?
Some miscellaneous comments:
1) Maybe virtio_gpu_array can have it's own header and file? virtgpu_drv.h is getting rather big..
2) What data are you trying to protect with the additional references? Is it host side resources (i.e, the host GL texture or buffer object) or is it guest side resources (fences)? Guest side resources seem properly counted to me. GL is supposed to reference count pending resources as well, but that's not always the case in practice. A little blurb somewhere like "hold on to 3D GEM buffers until the host response as a safety measure" or "we could potential cause a kernel oops if [...]" would be useful.
The guest side looks sufficiently referenced to me, while the GL spec indicates
Quoted 62 lines
drivers/gpu/drm/virtio/virtgpu_gem.c +1
-2virtio_gpu_cmd_context_detach_resource (vgdev, vfpriv->ctx_id, - qobj->hw_res_handle); -virtio_gpu_object_unreserve (qobj); + objs); }struct
virtio_gpu_object_array*virtio_gpu_array_alloc(u32 nents)drivers/gpu/drm/virtio/virtgpu_vq.c +2
-1@@ -835,8 +835,9 @@ void virtio_gpu_cmd_context_destroy(structvirtio_gpu_device *vgdev, void virtio_gpu_cmd_context_attach_resource(struct virtio_gpu_device *vgdev, uint32_t ctx_id, - uint32_t resource_id) + struct virtio_gpu_object_array *objs) { + struct virtio_gpu_object *bo =gem_to_virtio_gpu_obj(objs->objs[0]); struct virtio_gpu_ctx_resource *cmd_p; struct virtio_gpu_vbuffer *vbuf;drivers/gpu/drm/virtio/virtgpu_vq.c +3
-2@@ -845,15 +846,16 @@ void virtio_gpu_cmd_context_attach_resource(struct virtio_gpu_device *vgdev, cmd_p->hdr.type =cpu_to_le32 (VIRTIO_GPU_CMD_CTX_ATTACH_RESOURCE ); cmd_p->hdr.ctx_id =cpu_to_le32 (ctx_id); - cmd_p->resource_id =cpu_to_le32 (resource_id); + cmd_p->resource_id =cpu_to_le32 (bo->hw_res_handle);virtio_gpu_queue_ctrl_buffer (vgdev, vbuf); }void virtio_gpu_cmd_context_detach_resource (struct virtio_gpu_device *vgdev,uint32_t ctx_id, -uint32_t resource_id) +struct virtio_gpu_object_array *objs) { + struct virtio_gpu_object *bo =gem_to_virtio_gpu_obj(objs->objs[0]); struct virtio_gpu_ctx_resource *cmd_p; struct virtio_gpu_vbuffer *vbuf;drivers/gpu/drm/virtio/virtgpu_vq.c +1
-2@@ -862,7 +864,7 @@ void virtio_gpu_cmd_context_detach_resource(struct virtio_gpu_device *vgdev, cmd_p->hdr.type =cpu_to_le32 (VIRTIO_GPU_CMD_CTX_DETACH_RESOURCE ); cmd_p->hdr.ctx_id =cpu_to_le32 (ctx_id); - cmd_p->resource_id =cpu_to_le32 (resource_id); + cmd_p->resource_id =cpu_to_le32 (bo->hw_res_handle);virtio_gpu_queue_ctrl_buffer (vgdev, vbuf); } --
Quoted 3 lines
2.18.1
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Gurchetan Singh
reviewerRe: [PATCH v6 16/18] drm/virtio: rework virtio_gpu_cmd_context_{attach, detach}_resource
In reply to Gerd HoffmannQuoted 73 lines · Gerd Hoffmann
Switch to the virtio_gpu_array_* helper workflow.
Signed-off-by Gerd Hoffmann <[email protected]>--- drivers/gpu/drm/virtio/virtgpu_drv.h | 4 ++-- drivers/gpu/drm/virtio/virtgpu_gem.c | 24 +++++++++++------------- drivers/gpu/drm/virtio/virtgpu_vq.c | 10 ++++++---- 3 files changed, 19 insertions(+), 19 deletions(-)drivers/gpu/drm/virtio/virtgpu_drv.h +2
-2@@ -292,10 +292,10 @@ void virtio_gpu_cmd_context_destroy(structvirtio_gpu_device *vgdev, uint32_t id);void virtio_gpu_cmd_context_attach_resource (struct virtio_gpu_device *vgdev,uint32_t ctx_id, -uint32_t resource_id); +struct virtio_gpu_object_array *objs);void virtio_gpu_cmd_context_detach_resource (struct virtio_gpu_device *vgdev,uint32_t ctx_id, -uint32_t resource_id); + struct virtio_gpu_object_array*objs);
void virtio_gpu_cmd_submit(structvirtio_gpu_device*vgdev,
void *data,uint32_tdata_size,uint32_tctx_id,drivers/gpu/drm/virtio/virtgpu_gem.c +7
-9@@ -111,19 +111,18 @@ int virtio_gpu_gem_object_open(struct drm_gem_object *obj, {struct virtio_gpu_device *vgdev = obj->dev->dev_private;struct virtio_gpu_fpriv *vfpriv = file->driver_priv; -struct virtio_gpu_object *qobj =gem_to_virtio_gpu_obj (obj); -int r; +struct virtio_gpu_object_array *objs;if (!vgdev->has_virgl_3d)return 0 ; - r =virtio_gpu_object_reserve (qobj); -if (r) -return r; + objs =virtio_gpu_array_alloc (1 ); +if (!objs) +return -ENOMEM ; +virtio_gpu_array_add_obj (objs, obj);virtio_gpu_cmd_context_attach_resource (vgdev, vfpriv->ctx_id, - qobj->hw_res_handle); -virtio_gpu_object_unreserve (qobj); + objs);return 0 ; }@@ -132,19 +131,18 @@ void virtio_gpu_gem_object_close(struct drm_gem_object *obj, {struct virtio_gpu_device *vgdev = obj->dev->dev_private;struct virtio_gpu_fpriv *vfpriv = file->driver_priv; -struct virtio_gpu_object *qobj =gem_to_virtio_gpu_obj (obj); -int r; +struct virtio_gpu_object_array *objs;
drivers/gpu/drm/virtio/virtgpu_gem.c void virtio_gpu_gem_object_close(struct · line 144
Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_gem.c +3
-2if (!vgdev->has_virgl_3d)return ; - r =virtio_gpu_object_reserve (qobj); -if (r) + objs =virtio_gpu_array_alloc (1 ); +if (!objs)return ; +virtio_gpu_array_add_obj (objs, obj);
This seems to call drm_gem_object_get. Without adding the objects to the vbuf, aren't we missing the corresponding drm_gem_object_put_unlocked?
Some miscellaneous comments:
1) Maybe virtio_gpu_array can have it's own header and file? virtgpu_drv.h is getting rather big..
2) What data are you trying to protect with the additional references? Is it host side resources (i.e, the host GL texture or buffer object) or is it guest side resources (fences)? Guest side resources seem properly counted to me. GL is supposed to reference count pending resources as well, but that's not always the case in practice. A little blurb somewhere like "hold on to 3D GEM buffers until the host response as a safety measure" or "we could potential cause a kernel oops if [...]" would be useful.
The guest side looks sufficiently referenced to me, while the GL spec indicates
Quoted 62 lines
drivers/gpu/drm/virtio/virtgpu_gem.c +1
-2virtio_gpu_cmd_context_detach_resource (vgdev, vfpriv->ctx_id, - qobj->hw_res_handle); -virtio_gpu_object_unreserve (qobj); + objs); }struct
virtio_gpu_object_array*virtio_gpu_array_alloc(u32 nents)drivers/gpu/drm/virtio/virtgpu_vq.c +2
-1@@ -835,8 +835,9 @@ void virtio_gpu_cmd_context_destroy(structvirtio_gpu_device *vgdev, void virtio_gpu_cmd_context_attach_resource(struct virtio_gpu_device *vgdev, uint32_t ctx_id, - uint32_t resource_id) + struct virtio_gpu_object_array *objs) { + struct virtio_gpu_object *bo =gem_to_virtio_gpu_obj(objs->objs[0]); struct virtio_gpu_ctx_resource *cmd_p; struct virtio_gpu_vbuffer *vbuf;drivers/gpu/drm/virtio/virtgpu_vq.c +3
-2@@ -845,15 +846,16 @@ void virtio_gpu_cmd_context_attach_resource(struct virtio_gpu_device *vgdev, cmd_p->hdr.type =cpu_to_le32 (VIRTIO_GPU_CMD_CTX_ATTACH_RESOURCE ); cmd_p->hdr.ctx_id =cpu_to_le32 (ctx_id); - cmd_p->resource_id =cpu_to_le32 (resource_id); + cmd_p->resource_id =cpu_to_le32 (bo->hw_res_handle);virtio_gpu_queue_ctrl_buffer (vgdev, vbuf); }void virtio_gpu_cmd_context_detach_resource (struct virtio_gpu_device *vgdev,uint32_t ctx_id, -uint32_t resource_id) +struct virtio_gpu_object_array *objs) { + struct virtio_gpu_object *bo =gem_to_virtio_gpu_obj(objs->objs[0]); struct virtio_gpu_ctx_resource *cmd_p; struct virtio_gpu_vbuffer *vbuf;drivers/gpu/drm/virtio/virtgpu_vq.c +1
-2@@ -862,7 +864,7 @@ void virtio_gpu_cmd_context_detach_resource(struct virtio_gpu_device *vgdev, cmd_p->hdr.type =cpu_to_le32 (VIRTIO_GPU_CMD_CTX_DETACH_RESOURCE ); cmd_p->hdr.ctx_id =cpu_to_le32 (ctx_id); - cmd_p->resource_id =cpu_to_le32 (resource_id); + cmd_p->resource_id =cpu_to_le32 (bo->hw_res_handle);virtio_gpu_queue_ctrl_buffer (vgdev, vbuf); } --
Quoted 3 lines
2.18.1
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Gerd Hoffmann
maintainerRe: [PATCH v6 16/18] drm/virtio: rework virtio_gpu_cmd_context_{attach,detach}_resource
Quoted 78 lines · Gurchetan Singh
Quoted 76 lines · Gerd Hoffmann
Switch to the virtio_gpu_array_* helper workflow.
Signed-off-by Gerd Hoffmann <[email protected]>--- drivers/gpu/drm/virtio/virtgpu_drv.h | 4 ++-- drivers/gpu/drm/virtio/virtgpu_gem.c | 24 +++++++++++------------- drivers/gpu/drm/virtio/virtgpu_vq.c | 10 ++++++---- 3 files changed, 19 insertions(+), 19 deletions(-)drivers/gpu/drm/virtio/virtgpu_drv.h +2
-2@@ -292,10 +292,10 @@ void virtio_gpu_cmd_context_destroy(structvirtio_gpu_device *vgdev, uint32_t id);void virtio_gpu_cmd_context_attach_resource (struct virtio_gpu_device *vgdev,uint32_t ctx_id, -uint32_t resource_id); +struct virtio_gpu_object_array *objs);void virtio_gpu_cmd_context_detach_resource (struct virtio_gpu_device *vgdev,uint32_t ctx_id, -uint32_t resource_id); + struct virtio_gpu_object_array*objs);
void virtio_gpu_cmd_submit(structvirtio_gpu_device*vgdev,
void *data,uint32_tdata_size,uint32_tctx_id,drivers/gpu/drm/virtio/virtgpu_gem.c +7
-9@@ -111,19 +111,18 @@ int virtio_gpu_gem_object_open(struct drm_gem_object *obj, {struct virtio_gpu_device *vgdev = obj->dev->dev_private;struct virtio_gpu_fpriv *vfpriv = file->driver_priv; -struct virtio_gpu_object *qobj =gem_to_virtio_gpu_obj (obj); -int r; +struct virtio_gpu_object_array *objs;if (!vgdev->has_virgl_3d)return 0 ; - r =virtio_gpu_object_reserve (qobj); -if (r) -return r; + objs =virtio_gpu_array_alloc (1 ); +if (!objs) +return -ENOMEM ; +virtio_gpu_array_add_obj (objs, obj);virtio_gpu_cmd_context_attach_resource (vgdev, vfpriv->ctx_id, - qobj->hw_res_handle); -virtio_gpu_object_unreserve (qobj); + objs);return 0 ; }@@ -132,19 +131,18 @@ void virtio_gpu_gem_object_close(struct drm_gem_object *obj, {struct virtio_gpu_device *vgdev = obj->dev->dev_private;struct virtio_gpu_fpriv *vfpriv = file->driver_priv; -struct virtio_gpu_object *qobj =gem_to_virtio_gpu_obj (obj); -int r; +struct virtio_gpu_object_array *objs;if (!vgdev->has_virgl_3d)return ;
Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_gem.c void virtio_gpu_gem_object_close(struct drm_gem_object *obj, · line 143
Quoted 7 lines
drivers/gpu/drm/virtio/virtgpu_gem.c +3
-2- r =virtio_gpu_object_reserve (qobj); -if (r) + objs =virtio_gpu_array_alloc (1 ); +if (!objs)return ; +virtio_gpu_array_add_obj (objs, obj);This seems to call
drm_gem_object_get. Without adding the objects to the vbuf, aren't we missing the correspondingdrm_gem_object_put_unlocked?
Yes. Fixed.
Quoted 3 lines
Some miscellaneous comments:
1) Maybevirtio_gpu_arraycan have it's own header and file?virtgpu_drv.his getting rather big..
Longer-term it might move out anyway due to becoming a generic drm helper.
Quoted 3 lines
2) What data are you trying to protect with the additional references? Is it host side resources (i.e, the host GL texture or buffer object) or is it guest side resources (fences)?
Protect the (guest) gem object, specifically make sure the bo->hw_res_handle stays valid.
cheers,
Gerd
Gerd Hoffmann
maintainerRe: [PATCH v6 16/18] drm/virtio: rework virtio_gpu_cmd_context_{attach,detach}_resource
In reply to Gurchetan SinghQuoted 78 lines · Gurchetan Singh
Quoted 76 lines · Gerd Hoffmann
Switch to the virtio_gpu_array_* helper workflow.
Signed-off-by Gerd Hoffmann <[email protected]>--- drivers/gpu/drm/virtio/virtgpu_drv.h | 4 ++-- drivers/gpu/drm/virtio/virtgpu_gem.c | 24 +++++++++++------------- drivers/gpu/drm/virtio/virtgpu_vq.c | 10 ++++++---- 3 files changed, 19 insertions(+), 19 deletions(-)drivers/gpu/drm/virtio/virtgpu_drv.h +2
-2@@ -292,10 +292,10 @@ void virtio_gpu_cmd_context_destroy(structvirtio_gpu_device *vgdev, uint32_t id);void virtio_gpu_cmd_context_attach_resource (struct virtio_gpu_device *vgdev,uint32_t ctx_id, -uint32_t resource_id); +struct virtio_gpu_object_array *objs);void virtio_gpu_cmd_context_detach_resource (struct virtio_gpu_device *vgdev,uint32_t ctx_id, -uint32_t resource_id); + struct virtio_gpu_object_array*objs);
void virtio_gpu_cmd_submit(structvirtio_gpu_device*vgdev,
void *data,uint32_tdata_size,uint32_tctx_id,drivers/gpu/drm/virtio/virtgpu_gem.c +7
-9@@ -111,19 +111,18 @@ int virtio_gpu_gem_object_open(struct drm_gem_object *obj, {struct virtio_gpu_device *vgdev = obj->dev->dev_private;struct virtio_gpu_fpriv *vfpriv = file->driver_priv; -struct virtio_gpu_object *qobj =gem_to_virtio_gpu_obj (obj); -int r; +struct virtio_gpu_object_array *objs;if (!vgdev->has_virgl_3d)return 0 ; - r =virtio_gpu_object_reserve (qobj); -if (r) -return r; + objs =virtio_gpu_array_alloc (1 ); +if (!objs) +return -ENOMEM ; +virtio_gpu_array_add_obj (objs, obj);virtio_gpu_cmd_context_attach_resource (vgdev, vfpriv->ctx_id, - qobj->hw_res_handle); -virtio_gpu_object_unreserve (qobj); + objs);return 0 ; }@@ -132,19 +131,18 @@ void virtio_gpu_gem_object_close(struct drm_gem_object *obj, {struct virtio_gpu_device *vgdev = obj->dev->dev_private;struct virtio_gpu_fpriv *vfpriv = file->driver_priv; -struct virtio_gpu_object *qobj =gem_to_virtio_gpu_obj (obj); -int r; +struct virtio_gpu_object_array *objs;if (!vgdev->has_virgl_3d)return ;
Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_gem.c void virtio_gpu_gem_object_close(struct drm_gem_object *obj, · line 143
Quoted 7 lines
drivers/gpu/drm/virtio/virtgpu_gem.c +3
-2- r =virtio_gpu_object_reserve (qobj); -if (r) + objs =virtio_gpu_array_alloc (1 ); +if (!objs)return ; +virtio_gpu_array_add_obj (objs, obj);This seems to call
drm_gem_object_get. Without adding the objects to the vbuf, aren't we missing the correspondingdrm_gem_object_put_unlocked?
Yes. Fixed.
Quoted 3 lines
Some miscellaneous comments:
1) Maybevirtio_gpu_arraycan have it's own header and file?virtgpu_drv.his getting rather big..
Longer-term it might move out anyway due to becoming a generic drm helper.
Quoted 3 lines
2) What data are you trying to protect with the additional references? Is it host side resources (i.e, the host GL texture or buffer object) or is it guest side resources (fences)?
Protect the (guest) gem object, specifically make sure the bo->hw_res_handle stays valid.
cheers,
Gerd
Gerd Hoffmann
maintainerPATCH v6 17/18 drm/virtio: drop virtio_gpu_object_{reserve, unreserve}
In reply to Gerd HoffmannNo users left.
--- drivers/gpu/drm/virtio/virtgpu_drv.h | 21 --------------------- 1 file changed, 21 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.h +0 -21
@@ -368,27 +368,6 @@ static inline u64 virtio_gpu_object_mmap_offset(struct virtio_gpu_object *bo)return drm_vma_node_offset_addr (&bo->base.base.vma_node); } -static inline int virtio_gpu_object_reserve (struct virtio_gpu_object *bo) -{ -int r; - - r =reservation_object_lock_interruptible (bo->base.base.resv,NULL ); -if (unlikely (r !=0 )) { -if (r != -EINTR ) { -struct virtio_gpu_device *qdev = - bo->base.base.dev->dev_private; -dev_err (qdev->dev,"%p reserve failed\n" , bo); - } -return r; - } -return 0 ; -} - -static inline void virtio_gpu_object_unreserve (struct virtio_gpu_object *bo) -{ -reservation_object_unlock (bo->base.base.resv); -} -/* virgl debufs */ int virtio_gpu_debugfs_init (struct drm_minor *minor);
Signature · 1 line
2.18.1
Gerd Hoffmann
maintainerPATCH v6 17/18 drm/virtio: drop virtio_gpu_object_{reserve,unreserve}
In reply to Gerd HoffmannNo users left.
--- drivers/gpu/drm/virtio/virtgpu_drv.h | 21 --------------------- 1 file changed, 21 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.h +0 -21
@@ -368,27 +368,6 @@ static inline u64 virtio_gpu_object_mmap_offset(struct virtio_gpu_object *bo)return drm_vma_node_offset_addr (&bo->base.base.vma_node); } -static inline int virtio_gpu_object_reserve (struct virtio_gpu_object *bo) -{ -int r; - - r =reservation_object_lock_interruptible (bo->base.base.resv,NULL ); -if (unlikely (r !=0 )) { -if (r != -EINTR ) { -struct virtio_gpu_device *qdev = - bo->base.base.dev->dev_private; -dev_err (qdev->dev,"%p reserve failed\n" , bo); - } -return r; - } -return 0 ; -} - -static inline void virtio_gpu_object_unreserve (struct virtio_gpu_object *bo) -{ -reservation_object_unlock (bo->base.base.resv); -} -/* virgl debufs */ int virtio_gpu_debugfs_init (struct drm_minor *minor);
Signature · 6 lines
2.18.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Gerd Hoffmann
maintainerPATCH v6 18/18 drm/virtio: add fence sanity check
In reply to Gerd HoffmannMake sure we don't leak half-initialized fences outside the driver.
--- drivers/gpu/drm/virtio/virtgpu_fence.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/gpu/drm/virtio/virtgpu_fence.c +4 -0
@@ -41,6 +41,10 @@ bool virtio_fence_signaled(struct dma_fence *f) {struct virtio_gpu_fence *fence =to_virtio_fence (f); +if (WARN_ON_ONCE (fence->f.seqno ==0 )) +/* leaked fence outside driver before completing +* initialization with virtio_gpu_fence_emit */ +return false;if (atomic64_read (&fence->drv->last_seq) >= fence->f.seqno)return true;return false;
Signature · 1 line
2.18.1
Gerd Hoffmann
maintainerPATCH v6 18/18 drm/virtio: add fence sanity check
In reply to Gerd HoffmannMake sure we don't leak half-initialized fences outside the driver.
--- drivers/gpu/drm/virtio/virtgpu_fence.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/gpu/drm/virtio/virtgpu_fence.c +4 -0
@@ -41,6 +41,10 @@ bool virtio_fence_signaled(struct dma_fence *f) {struct virtio_gpu_fence *fence =to_virtio_fence (f); +if (WARN_ON_ONCE (fence->f.seqno ==0 )) +/* leaked fence outside driver before completing +* initialization with virtio_gpu_fence_emit */ +return false;if (atomic64_read (&fence->drv->last_seq) >= fence->f.seqno)return true;return false;
Signature · 1 line
2.18.1