drm/virtio: switch from ttm to gem shmem helpers.
Subsystems (4)
Gerd Hoffmann
maintainerv3 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.
v3:
- add gem array helpers.
- rework fencing.
cheers,
Gerd
Gerd Hoffmann (12):
drm: add gem array helpers
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: 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
drivers/gpu/drm/virtio/virtgpu_drv.h | 77 ++---- include/drm/drm_gem_array_helper.h | 15 ++ drivers/gpu/drm/drm_gem_array_helper.c | 78 ++++++ drivers/gpu/drm/virtio/virtgpu_drv.c | 20 +- drivers/gpu/drm/virtio/virtgpu_gem.c | 43 +--- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 154 ++++-------- drivers/gpu/drm/virtio/virtgpu_kms.c | 9 - drivers/gpu/drm/virtio/virtgpu_object.c | 210 +++++----------- 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 | 48 +++- drivers/gpu/drm/Makefile | 3 +- drivers/gpu/drm/virtio/Kconfig | 2 +- drivers/gpu/drm/virtio/Makefile | 2 +- 15 files changed, 272 insertions(+), 743 deletions(-) create mode 100644 include/drm/drm_gem_array_helper.h create mode 100644 drivers/gpu/drm/drm_gem_array_helper.c 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 v3 1/12 drm: add gem array helpers
Add struct and helper functions to manage an array of gem objects. See added kernel docs for details.
--- include/drm/drm_gem_array_helper.h | 15 +++++ drivers/gpu/drm/drm_gem_array_helper.c | 76 ++++++++++++++++++++++++++ drivers/gpu/drm/Makefile | 3 +- 3 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 include/drm/drm_gem_array_helper.h create mode 100644 drivers/gpu/drm/drm_gem_array_helper.c
include/drm/drm_gem_array_helper.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __DRM_GEM_ARRAY_HELPER_H__ +#define __DRM_GEM_ARRAY_HELPER_H__ + +struct drm_gem_object_array { +u32 nents; +struct drm_gem_object *objs[]; +}; + +struct drm_gem_object_array *drm_gem_array_alloc (u32 nents); +struct drm_gem_object_array * +drm_gem_array_from_handles (struct drm_file *drm_file,u32 *handles,u32 nents); +void drm_gem_array_put_free (struct drm_gem_object_array *objs); + +#endif /* __DRM_GEM_ARRAY_HELPER_H__ */
drivers/gpu/drm/drm_gem_array_helper.c new file +76 -0
76 lines not on this page · raw message
drivers/gpu/drm/Makefile +2 -1
@@ -43,7 +43,8 @@ drm_kms_helper-y := drm_crtc_helper.o drm_dp_helper.o drm_dsc.o drm_probe_helper drm_simple_kms_helper.o drm_modeset_helper.o \ drm_scdc_helper.o drm_gem_framebuffer_helper.o \ drm_atomic_state_helper.o drm_damage_helper.o \ - drm_format_helper.o drm_self_refresh_helper.o + drm_format_helper.o drm_self_refresh_helper.o \ + drm_gem_array_helper.o drm_kms_helper-$(CONFIG_DRM_PANEL_BRIDGE) += bridge/panel.o drm_kms_helper-$(CONFIG_DRM_FBDEV_EMULATION) += drm_fb_helper.o
Signature · 1 line
2.18.1
Re: [PATCH v3 01/12] drm: add gem array helpers
Hi Gerd,
Quoted 12 lines · Gerd Hoffmann
drivers/gpu/drm/drm_gem_array_helper.c new file +12
-0+/** +* drm_gem_array_from_handles -- lookup an array of gem handles. +* +* @drm_file: drm file-private structure to use for the handle look up +* @handles: the array of handles to lookup. +* @nents: the numer of handles. +* +* Returns: An array of gem objects on success, NULL on failure. +*/ +struct drm_gem_object_array * +drm_gem_array_from_handles (struct drm_file *drm_file,u32 *handles,u32 nents) +{
drivers/gpu/drm/drm_gem_array_helper.c line 53
Quoted 10 lines
drivers/gpu/drm/drm_gem_array_helper.c new file +10
-0+struct drm_gem_object_array *objs; +u32 i; + + objs =drm_gem_array_alloc (nents); +if (!objs) +return NULL ; + +for (i =0 ; i < nents; i++) { + objs->objs[i] =drm_gem_object_lookup (drm_file, handles[i]); +if (!objs->objs[i]) {
Missing object put for the 0..i-1 handles. Personally I would:
objs->nents = i;
drm_gem_array_put_free(objs);
return NULL;drivers/gpu/drm/drm_gem_array_helper.c line 59
Quoted 6 lines
drivers/gpu/drm/drm_gem_array_helper.c new file +6
-0+drm_gem_array_put_free (objs); +return NULL ; + } + } +return objs; +}
Missing EXPORT_SYMBOL?
Quoted 7 lines
drivers/gpu/drm/drm_gem_array_helper.c new file +7
-0+ +/** +* drm_gem_array_put_free -- put gem objects and free array. +* +* @objs: the gem object array. +*/ +void drm_gem_array_put_free (struct drm_gem_object_array *objs)
drivers/gpu/drm/drm_gem_array_helper.c line 76
Quoted 10 lines
drivers/gpu/drm/drm_gem_array_helper.c new file +10
-0+{ +u32 i; + +for (i =0 ; i < objs->nents; i++) { +if (!objs->objs[i]) +continue ; +drm_gem_object_put_unlocked (objs->objs[i]); + } +drm_gem_array_free (objs); +}
Ditto?
HTH
Emil
Gerd Hoffmann
maintainerRe: [PATCH v3 01/12] drm: add gem array helpers
Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/drm_gem_array_helper.c new file +6
-0+struct drm_gem_object_array * +drm_gem_array_from_handles (struct drm_file *drm_file,u32 *handles,u32 nents) +{ +struct drm_gem_object_array *objs; +u32 i; +
Quoted 8 lines
drivers/gpu/drm/drm_gem_array_helper.c line 53
Quoted 7 lines
drivers/gpu/drm/drm_gem_array_helper.c new file +7
-0+ objs =drm_gem_array_alloc (nents); +if (!objs) +return NULL ; + +for (i =0 ; i < nents; i++) { + objs->objs[i] =drm_gem_object_lookup (drm_file, handles[i]); +if (!objs->objs[i]) {Missing object put for the 0..i-1 handles. Personally I would:
No. drm_gem_array_alloc initializes objs->nents and drm_gem_array_put_free() loops over the whole array, skipping NULL pointers.
Quoted 7 lines
drivers/gpu/drm/drm_gem_array_helper.c line 59
Quoted 6 lines
drivers/gpu/drm/drm_gem_array_helper.c new file +6
-0+drm_gem_array_put_free (objs); +return NULL ; + } + } +return objs; +}Missing
EXPORT_SYMBOL?
Oops. I had that fixed. Possibly squashed into the wrong patch.
Quoted 1 line
Ditto?
Yes.
cheers,
Gerd
Re: [PATCH v3 01/12] drm: add gem array helpers
In reply to Gerd HoffmannQuoted 4 lines · Gerd Hoffmann
Add struct and helper functions to manage an array of gem objects. See added kernel docs for details.
Signed-off-by Gerd Hoffmann <[email protected]>
Hm, feels like jumping ahead here, I think there's too much still in-flight:
- Christian is pondering some improved ww_mutex lock/unlock helpers. That'll probably change a lot of this code too.
- If we do more helpers, then I think we should have a consistent story across everything. These here don't really fit into the existing gem lock/unlock helpers.
- We probably want to design something coherent to replace all the ttm execbuf utils, i.e. bo lookup, locking, updating reservation objects, all that.
- I think this needs more than one driver to proof itself.
Maybe long-term we could have a drm_gem_eu_helper.c or so which contains all that. But that's still some ways off.
I'd go back to the virtio-only conversion, and once we have more of this stuff settled, we can look at how to properly design some nice&consistent helpers.
Cheers, Daniel
Quoted 128 lines
--- include/drm/drm_gem_array_helper.h | 15 +++++ drivers/gpu/drm/drm_gem_array_helper.c | 76 ++++++++++++++++++++++++++ drivers/gpu/drm/Makefile | 3 +- 3 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 include/drm/drm_gem_array_helper.h create mode 100644 drivers/gpu/drm/drm_gem_array_helper.cinclude/drm/drm_gem_array_helper.h new file +15
-0@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __DRM_GEM_ARRAY_HELPER_H__ +#define __DRM_GEM_ARRAY_HELPER_H__ + +struct drm_gem_object_array { +u32 nents; +struct drm_gem_object *objs[]; +}; + +struct drm_gem_object_array *drm_gem_array_alloc (u32 nents); +struct drm_gem_object_array * +drm_gem_array_from_handles (struct drm_file *drm_file,u32 *handles,u32 nents); +void drm_gem_array_put_free (struct drm_gem_object_array *objs); + +#endif /* __DRM_GEM_ARRAY_HELPER_H__ */ drivers/gpu/drm/drm_gem_array_helper.c new file +76
-0@@ -0,0 +1,76 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include <drm/drm_gem.h> +#include <drm/drm_gem_array_helper.h> + +/** +* drm_gem_array_alloc -- allocate gem object array of the given size. +* +* @nents: number of entries needed. +* +* Returns: An array of gem objects on success, NULL on failure. +*/ +struct drm_gem_object_array *drm_gem_array_alloc (u32 nents) +{ +struct drm_gem_object_array *objs; +size_t size =sizeof (*objs) +sizeof (objs->objs[0 ]) * nents; + + objs =kzalloc (size,GFP_KERNEL ); +if (!objs) +return NULL ; + + objs->nents = nents; +return objs; +} +EXPORT_SYMBOL (drm_gem_array_alloc); + +static void drm_gem_array_free (struct drm_gem_object_array *objs) +{ +kfree (objs); +} + +/** +* drm_gem_array_from_handles -- lookup an array of gem handles. +* +* @drm_file: drm file-private structure to use for the handle look up +* @handles: the array of handles to lookup. +* @nents: the numer of handles. +* +* Returns: An array of gem objects on success, NULL on failure. +*/ +struct drm_gem_object_array * +drm_gem_array_from_handles (struct drm_file *drm_file,u32 *handles,u32 nents) +{ +struct drm_gem_object_array *objs; +u32 i; + + objs =drm_gem_array_alloc (nents); +if (!objs) +return NULL ; + +for (i =0 ; i < nents; i++) { + objs->objs[i] =drm_gem_object_lookup (drm_file, handles[i]); +if (!objs->objs[i]) { +drm_gem_array_put_free (objs); +return NULL ; + } + } +return objs; +} + +/** +* drm_gem_array_put_free -- put gem objects and free array. +* +* @objs: the gem object array. +*/ +void drm_gem_array_put_free (struct drm_gem_object_array *objs) +{ +u32 i; + +for (i =0 ; i < objs->nents; i++) { +if (!objs->objs[i]) +continue ; +drm_gem_object_put_unlocked (objs->objs[i]); + } +drm_gem_array_free (objs); +}drivers/gpu/drm/Makefile +2
-1@@ -43,7 +43,8 @@ drm_kms_helper-y := drm_crtc_helper.o drm_dp_helper.o drm_dsc.o drm_probe_helper drm_simple_kms_helper.o drm_modeset_helper.o \ drm_scdc_helper.o drm_gem_framebuffer_helper.o \ drm_atomic_state_helper.o drm_damage_helper.o \ - drm_format_helper.o drm_self_refresh_helper.o + drm_format_helper.o drm_self_refresh_helper.o \ + drm_gem_array_helper.o drm_kms_helper-$(CONFIG_DRM_PANEL_BRIDGE) += bridge/panel.o drm_kms_helper-$(CONFIG_DRM_FBDEV_EMULATION) += drm_fb_helper.oSignature · 1 line
2.18.1
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Gerd Hoffmann
maintainerPATCH v3 2/12 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 v3 2/12 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 · 6 lines
2.18.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Gerd Hoffmann
maintainerPATCH v3 3/12 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.
v2: use reservation_object_test_signaled_rcu for VIRTGPU_WAIT_NOWAIT.
--- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-)
drivers/gpu/drm/virtio/virtgpu_ioctl.c +10 -14
@@ -464,23 +464,19 @@ 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 ; +if (args->flags &VIRTGPU_WAIT_NOWAIT ) { + obj =drm_gem_object_lookup (file, args->handle); + ret =reservation_object_test_signaled_rcu (obj->resv, true); +drm_gem_object_put_unlocked (obj); +return ret ?0 : -EBUSY ; + } - 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; +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 v3 3/12 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.
v2: use reservation_object_test_signaled_rcu for VIRTGPU_WAIT_NOWAIT.
--- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-)
drivers/gpu/drm/virtio/virtgpu_ioctl.c +10 -14
@@ -464,23 +464,19 @@ 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 ; +if (args->flags &VIRTGPU_WAIT_NOWAIT ) { + obj =drm_gem_object_lookup (file, args->handle); + ret =reservation_object_test_signaled_rcu (obj->resv, true); +drm_gem_object_put_unlocked (obj); +return ret ?0 : -EBUSY ; + } - 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; +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 v3 4/12 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 v3 4/12 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 v3 5/12 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 v3 6/12 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 v3 6/12 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
Re: [PATCH v3 06/12] drm/virtio: drop no_wait argument from virtio_gpu_object_reserve
Quoted 3 lines · Gerd Hoffmann
All callers pass
no_wait= false.Signed-off-by Gerd Hoffmann <[email protected]>
Quoted 72 lines
--- 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
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [PATCH v3 06/12] drm/virtio: drop no_wait argument from virtio_gpu_object_reserve
In reply to Gerd HoffmannQuoted 3 lines · Gerd Hoffmann
All callers pass
no_wait= false.Signed-off-by Gerd Hoffmann <[email protected]>
Quoted 72 lines
--- 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
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Gerd Hoffmann
maintainerPATCH v3 7/12 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}.
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 != -ERESTARTSYS && 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 v3 7/12 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}.
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 != -ERESTARTSYS && 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
Re: [PATCH v3 07/12] drm/virtio: remove ttm calls from in virtio_gpu_object_{reserve,unreserve}
Quoted 16 lines · Gerd Hoffmann
Call reservation_object_* directly instead
of using ttm_bo_{reserve,unreserve}.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 407
Quoted 8 lines
drivers/gpu/drm/virtio/virtgpu_drv.h +2
-2@@ -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 != -ERESTARTSYS && r != -EINTR ) {
You only need to check for EINTR I think. ttm_bo_reserv does the EINVAL -> ERESTARTSYS remapping.
-Daniel
Quoted 15 lines
drivers/gpu/drm/virtio/virtgpu_drv.h +1
-1struct 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
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [PATCH v3 07/12] drm/virtio: remove ttm calls from in virtio_gpu_object_{reserve,unreserve}
In reply to Gerd HoffmannQuoted 16 lines · Gerd Hoffmann
Call reservation_object_* directly instead
of using ttm_bo_{reserve,unreserve}.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 407
Quoted 8 lines
drivers/gpu/drm/virtio/virtgpu_drv.h +2
-2@@ -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 != -ERESTARTSYS && r != -EINTR ) {
You only need to check for EINTR I think. ttm_bo_reserv does the EINVAL -> ERESTARTSYS remapping.
-Daniel
Quoted 15 lines
drivers/gpu/drm/virtio/virtgpu_drv.h +1
-1struct 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
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Gerd Hoffmann
maintainerPATCH v3 8/12 drm/virtio: rework virtio_gpu_execbuffer_ioctl fencing
In reply to Gerd HoffmannUse gem reservation helpers and direct reservation_object_* calls instead of ttm.
v3: Also attach the array of gem objects to the virtio command buffer, so we can drop the object references in the completion callback. Needed because ttm fence helpers grab a reference for us, but gem helpers don't.
--- drivers/gpu/drm/virtio/virtgpu_drv.h | 6 ++- drivers/gpu/drm/drm_gem_array_helper.c | 2 + drivers/gpu/drm/virtio/virtgpu_ioctl.c | 62 +++++++++++--------------- drivers/gpu/drm/virtio/virtgpu_vq.c | 16 ++++--- 4 files changed, 43 insertions(+), 43 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.h +4 -2
@@ -33,6 +33,7 @@#include <drm/drmP.h> #include <drm/drm_gem.h> +#include <drm/drm_gem_array_helper.h> #include <drm/drm_atomic.h> #include <drm/drm_encoder.h> #include <drm/drm_fb_helper.h>
@@ -115,9 +116,9 @@ struct virtio_gpu_vbuffer {char *resp_buf;int resp_size; -virtio_gpu_resp_cb resp_cb; +struct drm_gem_object_array *objs;struct list_head list; };
@@ -301,7 +302,8 @@ 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_fence *fence, +struct drm_gem_object_array *objs); 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/drm_gem_array_helper.c +2 -0
@@ -57,6 +57,7 @@ drm_gem_array_from_handles(struct drm_file *drm_file, u32 *handles, u32 nents) }return objs; } +EXPORT_SYMBOL (drm_gem_array_from_handles);/** * drm_gem_array_put_free -- put gem objects and free array.
@@ -74,3 +75,4 @@ void drm_gem_array_put_free(struct drm_gem_object_array *objs) }drm_gem_array_free (objs); } +EXPORT_SYMBOL (drm_gem_array_put_free);
drivers/gpu/drm/virtio/virtgpu_ioctl.c +26 -36
105 lines not on this page · raw message
drivers/gpu/drm/virtio/virtgpu_vq.c +11 -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) +drm_gem_array_put_free (entry->objs); +list_del (&entry->list); +free_vbuf (vgdev, entry); + } }void virtio_gpu_dequeue_cursor_func (struct work_struct *work)
@@ -939,7 +943,8 @@ 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_fence *fence, +struct drm_gem_object_array *objs) {struct virtio_gpu_cmd_submit *cmd_p;struct virtio_gpu_vbuffer *vbuf;
@@ -949,6 +954,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
Re: [PATCH v3 08/12] drm/virtio: rework virtio_gpu_execbuffer_ioctl fencing
Quoted 9 lines · Gerd Hoffmann
Use gem reservation helpers and direct reservation_object_* calls instead of ttm.
v3: Also attach the array of gem objects to the virtio command buffer, so we can drop the object references in the completion callback. Needed because ttm fence helpers grab a reference for us, but gem helpers don't.
Signed-off-by Gerd Hoffmann <[email protected]>
I think this looks reasonable now, but since it now touches virtio lifetime management I'm not sure I can convince myself of its correctness. I didn't spot anything fundamentally wrong with the remaining patches, so on 8-12:
But I think you want someone with clue about virtio to double-check stuff doesn't get leaked or the driver oopses somewhere. Specifically I'm not sure whether you have some more traps lurking around buffer destruction, since ttm keeps stuff on the lru for longer than just until all the fences are signalled.
Also, I strongly recommend you do a very basic igt to exercise this, i.e. allocate some buffers, submit them in a dummby op, then close the entire drmfd. The old version should at least have tripped over kasan, maybe even oopses somewhere.
-Daniel
Quoted 226 lines
--- drivers/gpu/drm/virtio/virtgpu_drv.h | 6 ++- drivers/gpu/drm/drm_gem_array_helper.c | 2 + drivers/gpu/drm/virtio/virtgpu_ioctl.c | 62 +++++++++++--------------- drivers/gpu/drm/virtio/virtgpu_vq.c | 16 ++++--- 4 files changed, 43 insertions(+), 43 deletions(-)drivers/gpu/drm/virtio/virtgpu_drv.h +4
-2@@ -33,6 +33,7 @@#include <drm/drmP.h> #include <drm/drm_gem.h> +#include <drm/drm_gem_array_helper.h> #include <drm/drm_atomic.h> #include <drm/drm_encoder.h> #include <drm/drm_fb_helper.h> @@ -115,9 +116,9 @@ struct virtio_gpu_vbuffer {char *resp_buf;int resp_size; -virtio_gpu_resp_cb resp_cb; +struct drm_gem_object_array *objs;struct list_head list; };@@ -301,7 +302,8 @@ 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_fence *fence, +struct drm_gem_object_array *objs); 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/drm_gem_array_helper.c +2
-0@@ -57,6 +57,7 @@ drm_gem_array_from_handles(struct drm_file *drm_file, u32 *handles, u32 nents) }return objs; } +EXPORT_SYMBOL (drm_gem_array_from_handles);/** * drm_gem_array_put_free -- put gem objects and free array. @@ -74,3 +75,4 @@ void drm_gem_array_put_free(struct drm_gem_object_array *objs) }drm_gem_array_free (objs); } +EXPORT_SYMBOL (drm_gem_array_put_free);drivers/gpu/drm/virtio/virtgpu_ioctl.c +26
-36@@ -105,14 +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 ; +struct drm_gem_object_array *buflist =NULL ;int i;struct ww_acquire_ctx ticket;struct sync_file *sync_file;@@ -155,15 +152,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 +167,22 @@ 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 =drm_gem_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 =drm_gem_lock_reservations (buflist->objs, buflist->nents, + &ticket); +if (ret) + goto out_unused_fd; + } buf =memdup_user (u64_to_user_ptr (exbuf->command), exbuf->size);if (IS_ERR (buf)) {@@ -219,25 +208,26 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,fd_install (out_fence_fd, sync_file->file); } +if (buflist) { +for (i =0 ; i < exbuf->num_bo_handles; i++) +reservation_object_add_excl_fence (buflist->objs[i]->resv, + &out_fence->f); +drm_gem_unlock_reservations (buflist->objs, buflist->nents, + &ticket); + } +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, out_fence, buflist);return 0 ; out_memdup:kfree (buf); out_unresv: -ttm_eu_backoff_reservation (&ticket, &validate_list); -out_free: -virtio_gpu_unref_list (&validate_list); +drm_gem_unlock_reservations (buflist->objs, buflist->nents, &ticket); out_unused_fd:kvfree (bo_handles); -kvfree (buflist); +if (buflist) +drm_gem_array_put_free (buflist);if (out_fence_fd >=0 )put_unused_fd (out_fence_fd);drivers/gpu/drm/virtio/virtgpu_vq.c +11
-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) +drm_gem_array_put_free (entry->objs); +list_del (&entry->list); +free_vbuf (vgdev, entry); + } }void virtio_gpu_dequeue_cursor_func (struct work_struct *work)@@ -939,7 +943,8 @@ 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_fence *fence, +struct drm_gem_object_array *objs) {struct virtio_gpu_cmd_submit *cmd_p;struct virtio_gpu_vbuffer *vbuf;@@ -949,6 +954,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
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Gerd Hoffmann
maintainerRe: [PATCH v3 08/12] drm/virtio: rework virtio_gpu_execbuffer_ioctl fencing
Hi,
Quoted 4 lines
Also, I strongly recommend you do a very basic igt to exercise this, i.e. allocate some buffers, submit them in a dummby op, then close the entire drmfd. The old version should at least have tripped over kasan, maybe even oopses somewhere.
Hmm, I suspect I have to extend igt for that (adding support for virtio ioctls), right?
A quick and dirty test (run webgl demo in firefox, then kill -9 both firefox and Xorg) didn't show any nasty surprises.
cheers,
Gerd
Chia-I Wu
reviewerRe: [PATCH v3 08/12] drm/virtio: rework virtio_gpu_execbuffer_ioctl fencing
I tried my best to review this series. I am not really a kernel dev so please take that with a grain of salt.
Quoted 21 lines · Gerd Hoffmann
Hi,
Quoted 4 lines
Also, I strongly recommend you do a very basic igt to exercise this, i.e. allocate some buffers, submit them in a dummby op, then close the entire drmfd. The old version should at least have tripped over kasan, maybe even oopses somewhere.
Hmm, I suspect I have to extend igt for that (adding support for virtio ioctls), right?
A quick and dirty test (run webgl demo in firefox, then kill -9 both firefox and Xorg) didn't show any nasty surprises.
cheers,
Gerd_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Gerd Hoffmann
maintainerRe: [PATCH v3 08/12] drm/virtio: rework virtio_gpu_execbuffer_ioctl fencing
In reply to Daniel VetterHi,
Quoted 4 lines
Also, I strongly recommend you do a very basic igt to exercise this, i.e. allocate some buffers, submit them in a dummby op, then close the entire drmfd. The old version should at least have tripped over kasan, maybe even oopses somewhere.
Hmm, I suspect I have to extend igt for that (adding support for virtio ioctls), right?
A quick and dirty test (run webgl demo in firefox, then kill -9 both firefox and Xorg) didn't show any nasty surprises.
cheers,
Gerd
Gerd Hoffmann
maintainerPATCH v3 8/12 drm/virtio: rework virtio_gpu_execbuffer_ioctl fencing
In reply to Gerd HoffmannUse gem reservation helpers and direct reservation_object_* calls instead of ttm.
v3: Also attach the array of gem objects to the virtio command buffer, so we can drop the object references in the completion callback. Needed because ttm fence helpers grab a reference for us, but gem helpers don't.
--- drivers/gpu/drm/virtio/virtgpu_drv.h | 6 ++- drivers/gpu/drm/drm_gem_array_helper.c | 2 + drivers/gpu/drm/virtio/virtgpu_ioctl.c | 62 +++++++++++--------------- drivers/gpu/drm/virtio/virtgpu_vq.c | 16 ++++--- 4 files changed, 43 insertions(+), 43 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.h +4 -2
@@ -33,6 +33,7 @@#include <drm/drmP.h> #include <drm/drm_gem.h> +#include <drm/drm_gem_array_helper.h> #include <drm/drm_atomic.h> #include <drm/drm_encoder.h> #include <drm/drm_fb_helper.h>
@@ -115,9 +116,9 @@ struct virtio_gpu_vbuffer {char *resp_buf;int resp_size; -virtio_gpu_resp_cb resp_cb; +struct drm_gem_object_array *objs;struct list_head list; };
@@ -301,7 +302,8 @@ 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_fence *fence, +struct drm_gem_object_array *objs); 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/drm_gem_array_helper.c +2 -0
@@ -57,6 +57,7 @@ drm_gem_array_from_handles(struct drm_file *drm_file, u32 *handles, u32 nents) }return objs; } +EXPORT_SYMBOL (drm_gem_array_from_handles);/** * drm_gem_array_put_free -- put gem objects and free array.
@@ -74,3 +75,4 @@ void drm_gem_array_put_free(struct drm_gem_object_array *objs) }drm_gem_array_free (objs); } +EXPORT_SYMBOL (drm_gem_array_put_free);
drivers/gpu/drm/virtio/virtgpu_ioctl.c +26 -36
105 lines not on this page · raw message
drivers/gpu/drm/virtio/virtgpu_vq.c +11 -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) +drm_gem_array_put_free (entry->objs); +list_del (&entry->list); +free_vbuf (vgdev, entry); + } }void virtio_gpu_dequeue_cursor_func (struct work_struct *work)
@@ -939,7 +943,8 @@ 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_fence *fence, +struct drm_gem_object_array *objs) {struct virtio_gpu_cmd_submit *cmd_p;struct virtio_gpu_vbuffer *vbuf;
@@ -949,6 +954,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 v3 9/12 drm/virtio: rework virtio_gpu_object_create fencing
In reply to Gerd HoffmannUse gem reservation helpers and direct reservation_object_* calls instead of ttm.
v3: Due to using the gem reservation object it is initialized and ready for use before calling ttm_bo_init, so we can also drop the tricky fence logic which checks whenever the command is in flight still. We can simply fence our object before submitting the virtio command and be done with it.
--- drivers/gpu/drm/virtio/virtgpu_drv.h | 6 ++- drivers/gpu/drm/virtio/virtgpu_object.c | 54 +++++++++---------------- drivers/gpu/drm/virtio/virtgpu_vq.c | 8 +++- 3 files changed, 30 insertions(+), 38 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.h +4 -2
@@ -258,7 +258,8 @@ 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_fence *fence); +struct virtio_gpu_fence *fence, +struct drm_gem_object_array *objs);void virtio_gpu_cmd_unref_resource (struct virtio_gpu_device *vgdev,uint32_t resource_id); void virtio_gpu_cmd_transfer_to_host_2d(struct virtio_gpu_device *vgdev,
@@ -319,7 +320,8 @@ 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_fence *fence); + struct virtio_gpu_fence *fence, + struct drm_gem_object_array *objs);void virtio_gpu_ctrl_ack (struct virtqueue *vq);void virtio_gpu_cursor_ack (struct virtqueue *vq);void virtio_gpu_fence_ack (struct virtqueue *vq);
drivers/gpu/drm/virtio/virtgpu_object.c +20 -34
74 lines not on this page · raw message
drivers/gpu/drm/virtio/virtgpu_vq.c +6 -2
@@ -391,13 +391,15 @@ 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_fence *fence) +struct virtio_gpu_fence *fence, +struct drm_gem_object_array *objs) {struct virtio_gpu_resource_create_2d *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_RESOURCE_CREATE_2D ); cmd_p->resource_id =cpu_to_le32 (bo->hw_res_handle);
@@ -864,13 +866,15 @@ 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_fence *fence) + struct virtio_gpu_fence *fence, + struct drm_gem_object_array *objs) { struct virtio_gpu_resource_create_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_RESOURCE_CREATE_3D ); cmd_p->resource_id =cpu_to_le32 (bo->hw_res_handle);
Signature · 1 line
2.18.1
Gerd Hoffmann
maintainerPATCH v3 9/12 drm/virtio: rework virtio_gpu_object_create fencing
In reply to Gerd HoffmannUse gem reservation helpers and direct reservation_object_* calls instead of ttm.
v3: Due to using the gem reservation object it is initialized and ready for use before calling ttm_bo_init, so we can also drop the tricky fence logic which checks whenever the command is in flight still. We can simply fence our object before submitting the virtio command and be done with it.
--- drivers/gpu/drm/virtio/virtgpu_drv.h | 6 ++- drivers/gpu/drm/virtio/virtgpu_object.c | 54 +++++++++---------------- drivers/gpu/drm/virtio/virtgpu_vq.c | 8 +++- 3 files changed, 30 insertions(+), 38 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.h +4 -2
@@ -258,7 +258,8 @@ 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_fence *fence); +struct virtio_gpu_fence *fence, +struct drm_gem_object_array *objs);void virtio_gpu_cmd_unref_resource (struct virtio_gpu_device *vgdev,uint32_t resource_id); void virtio_gpu_cmd_transfer_to_host_2d(struct virtio_gpu_device *vgdev,
@@ -319,7 +320,8 @@ 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_fence *fence); + struct virtio_gpu_fence *fence, + struct drm_gem_object_array *objs);void virtio_gpu_ctrl_ack (struct virtqueue *vq);void virtio_gpu_cursor_ack (struct virtqueue *vq);void virtio_gpu_fence_ack (struct virtqueue *vq);
drivers/gpu/drm/virtio/virtgpu_object.c +20 -34
74 lines not on this page · raw message
drivers/gpu/drm/virtio/virtgpu_vq.c +6 -2
@@ -391,13 +391,15 @@ 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_fence *fence) +struct virtio_gpu_fence *fence, +struct drm_gem_object_array *objs) {struct virtio_gpu_resource_create_2d *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_RESOURCE_CREATE_2D ); cmd_p->resource_id =cpu_to_le32 (bo->hw_res_handle);
@@ -864,13 +866,15 @@ 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_fence *fence) + struct virtio_gpu_fence *fence, + struct drm_gem_object_array *objs) { struct virtio_gpu_resource_create_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_RESOURCE_CREATE_3D ); cmd_p->resource_id =cpu_to_le32 (bo->hw_res_handle);
Signature · 1 line
2.18.1
Gerd Hoffmann
maintainerPATCH v3 10/12 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
@@ -218,9 +218,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 v3 11/12 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.
--- 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 | 148 ++++-------- 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(+), 551 deletions(-) delete mode 100644 drivers/gpu/drm/virtio/virtgpu_ttm.c
drivers/gpu/drm/virtio/virtgpu_drv.h +11 -41
@@ -34,14 +34,11 @@#include <drm/drmP.h> #include <drm/drm_gem.h> #include <drm/drm_gem_array_helper.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"
@@ -69,21 +66,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_vbuffer ;struct virtio_gpu_device ;
@@ -148,10 +140,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;
@@ -180,8 +168,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;
@@ -340,11 +326,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(
@@ -356,58 +337,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 != -ERESTARTSYS && 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;
@@ -417,7 +387,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_PRIME |DRIVER_RENDER |DRIVER_ATOMIC ,
@@ -209,15 +199,9 @@ static struct drm_driver driver = { .prime_fd_to_handle = drm_gem_prime_fd_to_handle, .gem_prime_export = drm_gem_prime_export, .gem_prime_import = drm_gem_prime_import, - .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"
@@ -269,7 +268,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) {
@@ -296,7 +295,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 ;
@@ -309,7 +308,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;
@@ -330,10 +328,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);
@@ -345,7 +339,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);
@@ -362,7 +356,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;
@@ -380,10 +373,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
@@ -399,7 +388,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 -107
199 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
@@ -974,17 +974,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) {
@@ -1023,6 +1027,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 ... */
@@ -1038,6 +1045,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
Re: [PATCH v3 11/12] drm/virtio: switch from ttm to gem shmem helpers
Hi Gerd,
drivers/gpu/drm/virtio/virtgpu_object.c static void virtio_gpu_resource_id_put(struct virtio_gpu_device *vgdev, uint32_t · line 72
Quoted 2 lines · Gerd Hoffmann
drivers/gpu/drm/virtio/virtgpu_object.c +1
-1-static void virtio_gpu_init_ttm_placement (struct virtio_gpu_object *vgbo) +static const struct drm_gem_object_funcs v3d_gem_funcs = {
s/v3d/virtio/g
Doubt I'll have the time for a proper review - just this and the 1/12 nits :-\
HTH
Emil
Re: [PATCH v3 11/12] drm/virtio: switch from ttm to gem shmem helpers
In reply to Gerd HoffmannHi Gerd,
drivers/gpu/drm/virtio/virtgpu_object.c static void virtio_gpu_resource_id_put(struct virtio_gpu_device *vgdev, uint32_t · line 72
Quoted 2 lines · Gerd Hoffmann
drivers/gpu/drm/virtio/virtgpu_object.c +1
-1-static void virtio_gpu_init_ttm_placement (struct virtio_gpu_object *vgbo) +static const struct drm_gem_object_funcs v3d_gem_funcs = {
s/v3d/virtio/g
Doubt I'll have the time for a proper review - just this and the 1/12 nits :-\
HTH
Emil
Gerd Hoffmann
maintainerPATCH v3 11/12 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.
--- 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 | 148 ++++-------- 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(+), 551 deletions(-) delete mode 100644 drivers/gpu/drm/virtio/virtgpu_ttm.c
drivers/gpu/drm/virtio/virtgpu_drv.h +11 -41
@@ -34,14 +34,11 @@#include <drm/drmP.h> #include <drm/drm_gem.h> #include <drm/drm_gem_array_helper.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"
@@ -69,21 +66,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_vbuffer ;struct virtio_gpu_device ;
@@ -148,10 +140,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;
@@ -180,8 +168,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;
@@ -340,11 +326,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(
@@ -356,58 +337,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 != -ERESTARTSYS && 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;
@@ -417,7 +387,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_PRIME |DRIVER_RENDER |DRIVER_ATOMIC ,
@@ -209,15 +199,9 @@ static struct drm_driver driver = { .prime_fd_to_handle = drm_gem_prime_fd_to_handle, .gem_prime_export = drm_gem_prime_export, .gem_prime_import = drm_gem_prime_import, - .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"
@@ -269,7 +268,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) {
@@ -296,7 +295,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 ;
@@ -309,7 +308,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;
@@ -330,10 +328,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);
@@ -345,7 +339,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);
@@ -362,7 +356,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;
@@ -380,10 +373,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
@@ -399,7 +388,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 -107
199 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
@@ -974,17 +974,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) {
@@ -1023,6 +1027,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 ... */
@@ -1038,6 +1045,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 v3 12/12 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
@@ -224,10 +224,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
@@ -264,10 +264,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 v3 12/12 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
@@ -224,10 +224,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
@@ -264,10 +264,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