drm/xe: Convert to drm_exec
Thomas Hellström
maintainerPATCH v2 1/6 drm/xe/bo: Simplify xe_bo_lock()
In reply to Thomas Hellströmxe_bo_lock() was, although it only grabbed a single lock, unnecessarily using ttm_eu_reserve_buffers(). Simplify and document the interface.
v2:
- Update also the xe_display subsysem.
--- drivers/gpu/drm/i915/display/intel_display.c | 5 +-- drivers/gpu/drm/xe/tests/xe_bo.c | 24 +++++------ drivers/gpu/drm/xe/xe_bo.c | 42 ++++++++++++-------- drivers/gpu/drm/xe/xe_bo.h | 5 +-- drivers/gpu/drm/xe/xe_bo_evict.c | 19 ++++----- drivers/gpu/drm/xe/xe_gt_pagefault.c | 41 +++++++------------ drivers/gpu/drm/xe/xe_vm.c | 27 +++++++------ drivers/gpu/drm/xe/xe_vm_madvise.c | 30 ++++++-------- 8 files changed, 90 insertions(+), 103 deletions(-)
drivers/gpu/drm/i915/display/intel_display.c +2 -3
@@ -6938,11 +6938,10 @@ static int i915_gem_object_read_from_page(struct xe_bo *bo,void *virtual;bool is_iomem;int ret; -struct ww_acquire_ctx ww;XE_WARN_ON (size !=8 ); - ret =xe_bo_lock (bo, &ww,0 , true); + ret =xe_bo_lock (bo, true);if (ret)return ret;
@@ -6959,7 +6958,7 @@ static int i915_gem_object_read_from_page(struct xe_bo *bo,ttm_bo_kunmap (&map); out_unlock: -xe_bo_unlock (bo, &ww); +xe_bo_unlock (bo); return ret; }#endif
drivers/gpu/drm/xe/tests/xe_bo.c +12 -12
@@ -203,9 +203,9 @@ static int evict_test_run_gt(struct xe_device *xe, struct xe_gt *gt, struct kuni goto cleanup_bo; } -xe_bo_lock (external, &ww,0 , false); +xe_bo_lock (external, false); err =xe_bo_pin_external (external); -xe_bo_unlock (external, &ww); +xe_bo_unlock (external);if (err) {KUNIT_FAIL (test,"external bo pin err=%pe\n" ,ERR_PTR (err));
@@ -268,9 +268,9 @@ static int evict_test_run_gt(struct xe_device *xe, struct xe_gt *gt, struct kuni ERR_PTR(err)); goto cleanup_all; } -xe_bo_lock (external, &ww,0 , false); +xe_bo_lock (external, false); err =xe_bo_validate (external,NULL , false); -xe_bo_unlock (external, &ww); +xe_bo_unlock (external);if (err) {KUNIT_FAIL (test,"external bo valid err=%pe\n" ,ERR_PTR (err));
@@ -278,28 +278,28 @@ static int evict_test_run_gt(struct xe_device *xe, struct xe_gt *gt, struct kuni } } -xe_bo_lock (external, &ww,0 , false); +xe_bo_lock (external, false);xe_bo_unpin_external (external); -xe_bo_unlock (external, &ww); +xe_bo_unlock (external);xe_bo_put (external); -xe_bo_lock (bo, &ww,0 , false); +xe_bo_lock (bo, false);__xe_bo_unset_bulk_move (bo); -xe_bo_unlock (bo, &ww); +xe_bo_unlock (bo);xe_bo_put (bo);continue ; cleanup_all: -xe_bo_lock (external, &ww,0 , false); +xe_bo_lock (external, false);xe_bo_unpin_external (external); -xe_bo_unlock (external, &ww); +xe_bo_unlock (external); cleanup_external:xe_bo_put (external); cleanup_bo: -xe_bo_lock (bo, &ww,0 , false); +xe_bo_lock (bo, false);__xe_bo_unset_bulk_move (bo); -xe_bo_unlock (bo, &ww); +xe_bo_unlock (bo);xe_bo_put (bo);break ; }
drivers/gpu/drm/xe/xe_bo.c +25 -17
64 lines not on this page · raw message
drivers/gpu/drm/xe/xe_bo.h +2 -3
@@ -149,10 +149,9 @@ static inline void xe_bo_assert_held(struct xe_bo *bo)dma_resv_assert_held ((bo)->ttm.base.resv); } -int xe_bo_lock (struct xe_bo *bo,struct ww_acquire_ctx *ww, -int num_resv,bool intr); +int xe_bo_lock (struct xe_bo *bo,bool intr); -void xe_bo_unlock (struct xe_bo *bo,struct ww_acquire_ctx *ww); +void xe_bo_unlock (struct xe_bo *bo);static inline void xe_bo_unlock_vm_held (struct xe_bo *bo) {
drivers/gpu/drm/xe/xe_bo_evict.c +8 -11
@@ -27,7 +27,6 @@int xe_bo_evict_all (struct xe_device *xe) {struct ttm_device *bdev = &xe->ttm; -struct ww_acquire_ctx ww;struct xe_bo *bo;struct xe_tile *tile;struct list_head still_in_list;
@@ -62,9 +61,9 @@ int xe_bo_evict_all(struct xe_device *xe)list_move_tail (&bo->pinned_link, &still_in_list);spin_unlock (&xe->pinned.lock); -xe_bo_lock (bo, &ww,0 , false); +xe_bo_lock (bo, false); ret =xe_bo_evict_pinned (bo); -xe_bo_unlock (bo, &ww); +xe_bo_unlock (bo);xe_bo_put (bo);if (ret) {spin_lock (&xe->pinned.lock);
@@ -96,9 +95,9 @@ int xe_bo_evict_all(struct xe_device *xe)list_move_tail (&bo->pinned_link, &xe->pinned.evicted);spin_unlock (&xe->pinned.lock); -xe_bo_lock (bo, &ww,0 , false); +xe_bo_lock (bo, false); ret =xe_bo_evict_pinned (bo); -xe_bo_unlock (bo, &ww); +xe_bo_unlock (bo);xe_bo_put (bo);if (ret)return ret;
@@ -123,7 +122,6 @@ int xe_bo_evict_all(struct xe_device *xe)*/ int xe_bo_restore_kernel (struct xe_device *xe) { -struct ww_acquire_ctx ww;struct xe_bo *bo;int ret;
@@ -140,9 +138,9 @@ int xe_bo_restore_kernel(struct xe_device *xe)list_move_tail (&bo->pinned_link, &xe->pinned.kernel_bo_present);spin_unlock (&xe->pinned.lock); -xe_bo_lock (bo, &ww,0 , false); +xe_bo_lock (bo, false); ret =xe_bo_restore_pinned (bo); -xe_bo_unlock (bo, &ww); +xe_bo_unlock (bo);if (ret) {xe_bo_put (bo);return ret;
@@ -184,7 +182,6 @@ int xe_bo_restore_kernel(struct xe_device *xe)*/ int xe_bo_restore_user (struct xe_device *xe) { -struct ww_acquire_ctx ww;struct xe_bo *bo;struct xe_tile *tile;struct list_head still_in_list;
@@ -206,9 +203,9 @@ int xe_bo_restore_user(struct xe_device *xe)xe_bo_get (bo);spin_unlock (&xe->pinned.lock); -xe_bo_lock (bo, &ww,0 , false); +xe_bo_lock (bo, false); ret =xe_bo_restore_pinned (bo); -xe_bo_unlock (bo, &ww); +xe_bo_unlock (bo);xe_bo_put (bo);if (ret) {spin_lock (&xe->pinned.lock);
drivers/gpu/drm/xe/xe_gt_pagefault.c +15 -26
73 lines not on this page · raw message
drivers/gpu/drm/xe/xe_vm.c +14 -13
@@ -267,13 +267,16 @@ static void arm_preempt_fences(struct xe_vm *vm, struct list_head *list)static int add_preempt_fences (struct xe_vm *vm,struct xe_bo *bo) {struct xe_exec_queue *q; -struct ww_acquire_ctx ww;int err; - err =xe_bo_lock (bo, &ww, vm->preempt.num_engines, true); + err =xe_bo_lock (bo, true);if (err)return err; + err =dma_resv_reserve_fences (bo->ttm.base.resv, vm->preempt.num_engines); +if (err) + goto unlock; +list_for_each_entry (q, &vm->preempt.engines, compute.link)if (q->compute.pfence) { dma_resv_add_fence(bo->ttm.base.resv,
@@ -281,8 +284,9 @@ static int add_preempt_fences(struct xe_vm *vm, struct xe_bo *bo) DMA_RESV_USAGE_BOOKKEEP); } -xe_bo_unlock (bo, &ww); -return 0 ; +unlock: +xe_bo_unlock (bo); +return err; }/**
@@ -1021,12 +1025,11 @@ bo_has_vm_references_locked(struct xe_bo *bo, struct xe_vm *vm,static bool bo_has_vm_references (struct xe_bo *bo,struct xe_vm *vm,struct xe_vma *ignore) { -struct ww_acquire_ctx ww;bool ret; -xe_bo_lock (bo, &ww,0 , false); +xe_bo_lock (bo, false); ret = !!bo_has_vm_references_locked (bo, vm, ignore); -xe_bo_unlock (bo, &ww); +xe_bo_unlock (bo);return ret; }
@@ -2267,7 +2270,6 @@ vm_bind_ioctl_ops_create(struct xe_vm *vm, struct xe_bo *bo, u32 operation, u8 tile_mask, u32 region) { struct drm_gem_object *obj = bo ? &bo->ttm.base : NULL; -struct ww_acquire_ctx ww;struct drm_gpuva_ops *ops;struct drm_gpuva_op *__op;struct xe_vma_op *op;
@@ -2325,11 +2327,11 @@ vm_bind_ioctl_ops_create(struct xe_vm *vm, struct xe_bo *bo,case XE_VM_BIND_OP_UNMAP_ALL :XE_WARN_ON (!bo); - err =xe_bo_lock (bo, &ww,0 , true); + err =xe_bo_lock (bo, true);if (err)return ERR_PTR (err); ops =drm_gpuva_gem_unmap_ops_create (&vm->mgr, obj); -xe_bo_unlock (bo, &ww); +xe_bo_unlock (bo);if (IS_ERR (ops))return ops;
@@ -2365,13 +2367,12 @@ static struct xe_vma *new_vma(struct xe_vm *vm, struct drm_gpuva_op_map *op, {struct xe_bo *bo = op->gem.obj ?gem_to_xe_bo (op->gem.obj) :NULL ;struct xe_vma *vma; -struct ww_acquire_ctx ww;int err;lockdep_assert_held_write (&vm->lock);if (bo) { - err =xe_bo_lock (bo, &ww,0 , true); + err =xe_bo_lock (bo, true);if (err)return ERR_PTR (err); }
@@ -2380,7 +2381,7 @@ static struct xe_vma *new_vma(struct xe_vm *vm, struct drm_gpuva_op_map *op, op->va.range -1 , read_only, is_null, tile_mask);if (bo) -xe_bo_unlock (bo, &ww); +xe_bo_unlock (bo);if (xe_vma_is_userptr (vma)) { err =xe_vma_userptr_pin_pages (vma);
drivers/gpu/drm/xe/xe_vm_madvise.c +12 -18
@@ -28,16 +28,15 @@ static int madvise_preferred_mem_class(struct xe_device *xe, struct xe_vm *vm,for (i =0 ; i < num_vmas; ++i) {struct xe_bo *bo; -struct ww_acquire_ctx ww; bo =xe_vma_bo (vmas[i]); - err =xe_bo_lock (bo, &ww,0 , true); + err =xe_bo_lock (bo, true);if (err)return err; bo->props.preferred_mem_class = value;xe_bo_placement_for_flags (xe, bo, bo->flags); -xe_bo_unlock (bo, &ww); +xe_bo_unlock (bo); }return 0 ;
@@ -53,16 +52,15 @@ static int madvise_preferred_gt(struct xe_device *xe, struct xe_vm *vm,for (i =0 ; i < num_vmas; ++i) {struct xe_bo *bo; -struct ww_acquire_ctx ww; bo =xe_vma_bo (vmas[i]); - err =xe_bo_lock (bo, &ww,0 , true); + err =xe_bo_lock (bo, true);if (err)return err; bo->props.preferred_gt = value;xe_bo_placement_for_flags (xe, bo, bo->flags); -xe_bo_unlock (bo, &ww); +xe_bo_unlock (bo); }return 0 ;
@@ -89,17 +87,16 @@ static int madvise_preferred_mem_class_gt(struct xe_device *xe,for (i =0 ; i < num_vmas; ++i) {struct xe_bo *bo; -struct ww_acquire_ctx ww; bo =xe_vma_bo (vmas[i]); - err =xe_bo_lock (bo, &ww,0 , true); + err =xe_bo_lock (bo, true);if (err)return err; bo->props.preferred_mem_class = mem_class; bo->props.preferred_gt = gt_id;xe_bo_placement_for_flags (xe, bo, bo->flags); -xe_bo_unlock (bo, &ww); +xe_bo_unlock (bo); }return 0 ;
@@ -112,13 +109,12 @@ static int madvise_cpu_atomic(struct xe_device *xe, struct xe_vm *vm,for (i =0 ; i < num_vmas; ++i) {struct xe_bo *bo; -struct ww_acquire_ctx ww; bo =xe_vma_bo (vmas[i]);if (XE_IOCTL_DBG (xe, !(bo->flags &XE_BO_CREATE_SYSTEM_BIT )))return -EINVAL ; - err =xe_bo_lock (bo, &ww,0 , true); + err =xe_bo_lock (bo, true);if (err)return err; bo->props.cpu_atomic = !!value;
@@ -130,7 +126,7 @@ static int madvise_cpu_atomic(struct xe_device *xe, struct xe_vm *vm,*/ if (bo->props.cpu_atomic)ttm_bo_unmap_virtual (&bo->ttm); -xe_bo_unlock (bo, &ww); +xe_bo_unlock (bo); }return 0 ;
@@ -143,18 +139,17 @@ static int madvise_device_atomic(struct xe_device *xe, struct xe_vm *vm,for (i =0 ; i < num_vmas; ++i) {struct xe_bo *bo; -struct ww_acquire_ctx ww; bo =xe_vma_bo (vmas[i]);if (XE_IOCTL_DBG (xe, !(bo->flags &XE_BO_CREATE_VRAM0_BIT ) && !(bo->flags &XE_BO_CREATE_VRAM1_BIT )))return -EINVAL ; - err =xe_bo_lock (bo, &ww,0 , true); + err =xe_bo_lock (bo, true);if (err)return err; bo->props.device_atomic = !!value; -xe_bo_unlock (bo, &ww); +xe_bo_unlock (bo); }return 0 ;
@@ -174,16 +169,15 @@ static int madvise_priority(struct xe_device *xe, struct xe_vm *vm,for (i =0 ; i < num_vmas; ++i) {struct xe_bo *bo; -struct ww_acquire_ctx ww; bo =xe_vma_bo (vmas[i]); - err =xe_bo_lock (bo, &ww,0 , true); + err =xe_bo_lock (bo, true);if (err)return err; bo->ttm.priority = value;ttm_bo_move_to_lru_tail (&bo->ttm); -xe_bo_unlock (bo, &ww); +xe_bo_unlock (bo); }return 0 ;
Signature · 1 line
2.41.0
Thomas Hellström
maintainerv2 cover drm/xe: Convert to drm_exec
Convert the driver to use drm_exec instead of ttm_eu_reserve_buffers().
v2:
- Update also the xe display subsystem.
Thomas Hellström (6):
drm/xe/bo: Simplify xe_bo_lock()
drm/xe/vm: Simplify and document xe_vm_lock()
drm/xe/bo: Remove the lock_no_vm()/unlock_no_vm() interface drm/xe: Rework xe_exec and the VM rebind worker to use the drm_exec
helper
drm/xe: Convert pagefaulting code to use drm_exec drm/xe: Convert remaining instances of ttm_eu_reserve_buffers to
drm_exec
drivers/gpu/drm/i915/display/intel_display.c | 5 +- drivers/gpu/drm/i915/display/intel_fb.c | 4 +- drivers/gpu/drm/xe/Kconfig | 1 + drivers/gpu/drm/xe/tests/xe_bo.c | 35 +- drivers/gpu/drm/xe/tests/xe_dma_buf.c | 4 +- drivers/gpu/drm/xe/tests/xe_migrate.c | 7 +- drivers/gpu/drm/xe/xe_bo.c | 47 +- drivers/gpu/drm/xe/xe_bo.h | 28 +- drivers/gpu/drm/xe/xe_bo_evict.c | 19 +- drivers/gpu/drm/xe/xe_dma_buf.c | 5 +- drivers/gpu/drm/xe/xe_exec.c | 71 +-- drivers/gpu/drm/xe/xe_exec_queue.c | 5 +- drivers/gpu/drm/xe/xe_gt_pagefault.c | 117 ++--- drivers/gpu/drm/xe/xe_lrc.c | 12 +- drivers/gpu/drm/xe/xe_migrate.c | 10 +- drivers/gpu/drm/xe/xe_vm.c | 462 +++++++++---------- drivers/gpu/drm/xe/xe_vm.h | 30 +- drivers/gpu/drm/xe/xe_vm_madvise.c | 30 +- 18 files changed, 385 insertions(+), 507 deletions(-)
Signature · 1 line
2.41.0
Thomas Hellström
maintainerPATCH v2 3/6 drm/xe/bo: Remove the lock_no_vm()/unlock_no_vm() interface
Apart from asserts, it's essentially the same as xe_bo_lock()/xe_bo_unlock(), and the usage intentions of this interface was unclear. Remove it.
v2:
- Update the xe_display subsystem as well.
--- drivers/gpu/drm/i915/display/intel_fb.c | 4 ++-- drivers/gpu/drm/xe/tests/xe_bo.c | 2 +- drivers/gpu/drm/xe/tests/xe_dma_buf.c | 4 ++-- drivers/gpu/drm/xe/tests/xe_migrate.c | 2 +- drivers/gpu/drm/xe/xe_bo.h | 23 ++--------------------- drivers/gpu/drm/xe/xe_dma_buf.c | 5 +++-- drivers/gpu/drm/xe/xe_lrc.c | 10 ++-------- 7 files changed, 13 insertions(+), 37 deletions(-)
drivers/gpu/drm/i915/display/intel_fb.c +2 -2
@@ -1892,9 +1892,9 @@ static void intel_user_framebuffer_destroy_vm(struct drm_framebuffer *fb)struct xe_bo *bo =intel_fb_obj (fb);/* Unpin our kernel fb first */ -xe_bo_lock_no_vm (bo,NULL ); +xe_bo_lock (bo, false);xe_bo_unpin (bo); - xe_bo_unlock_no_vm(bo); + xe_bo_unlock(bo); }xe_bo_put (intel_fb_obj (fb));#endif
drivers/gpu/drm/xe/tests/xe_bo.c +1 -1
@@ -143,7 +143,7 @@ static void ccs_test_run_gt(struct xe_device *xe, struct xe_gt *gt, ret =ccs_test_migrate (gt, bo, true,0ULL ,0ULL , test); out_unlock: -xe_bo_unlock_no_vm (bo); +xe_bo_unlock (bo);xe_bo_put (bo); }
drivers/gpu/drm/xe/tests/xe_dma_buf.c +2 -2
@@ -148,14 +148,14 @@ static void xe_test_dmabuf_import_same_driver(struct xe_device *xe)int err;/* Is everything where we expect it to be? */ -xe_bo_lock_no_vm (import_bo,NULL ); +xe_bo_lock (import_bo, false); err =xe_bo_validate (import_bo,NULL , false);if (err && err != -EINTR && err != -ERESTARTSYS )KUNIT_FAIL (test,"xe_bo_validate() failed with err=%d\n" , err);check_residency (test, bo, import_bo, dmabuf); -xe_bo_unlock_no_vm (import_bo); +xe_bo_unlock (import_bo); }drm_gem_object_put (import); }else if (PTR_ERR (import) != -EOPNOTSUPP ) {
drivers/gpu/drm/xe/tests/xe_migrate.c +1 -1
@@ -183,7 +183,7 @@ static void test_copy(struct xe_migrate *m, struct xe_bo *bo,xe_bo_vunmap (sysmem); out_unlock: -xe_bo_unlock_no_vm (sysmem); +xe_bo_unlock (sysmem);xe_bo_put (sysmem); }
drivers/gpu/drm/xe/xe_bo.h +2 -21
@@ -164,25 +164,6 @@ static inline void xe_bo_unlock_vm_held(struct xe_bo *bo) } } -static inline void xe_bo_lock_no_vm (struct xe_bo *bo, -struct ww_acquire_ctx *ctx) -{ -if (bo) { -XE_WARN_ON (bo->vm || (bo->ttm.type != ttm_bo_type_sg && - bo->ttm.base.resv != &bo->ttm.base._resv)); -dma_resv_lock (bo->ttm.base.resv, ctx); - } -} - -static inline void xe_bo_unlock_no_vm (struct xe_bo *bo) -{ -if (bo) { -XE_WARN_ON (bo->vm || (bo->ttm.type != ttm_bo_type_sg && - bo->ttm.base.resv != &bo->ttm.base._resv)); -dma_resv_unlock (bo->ttm.base.resv); - } -} -int xe_bo_pin_external (struct xe_bo *bo);int xe_bo_pin (struct xe_bo *bo);void xe_bo_unpin_external (struct xe_bo *bo);
@@ -197,9 +178,9 @@ static inline bool xe_bo_is_pinned(struct xe_bo *bo)static inline void xe_bo_unpin_map_no_vm (struct xe_bo *bo) {if (likely (bo)) { -xe_bo_lock_no_vm (bo,NULL ); +xe_bo_lock (bo, false);xe_bo_unpin (bo); -xe_bo_unlock_no_vm (bo); +xe_bo_unlock (bo);xe_bo_put (bo); }
drivers/gpu/drm/xe/xe_dma_buf.c +3 -2
@@ -153,9 +153,10 @@ static int xe_dma_buf_begin_cpu_access(struct dma_buf *dma_buf,if (!reads)return 0 ; -xe_bo_lock_no_vm (bo,NULL ); +/* Can we do interruptible lock here? */ +xe_bo_lock (bo, false); (void )xe_bo_migrate (bo,XE_PL_TT ); -xe_bo_unlock_no_vm (bo); +xe_bo_unlock (bo);return 0 ; }
drivers/gpu/drm/xe/xe_lrc.c +2 -8
@@ -790,15 +790,9 @@ int xe_lrc_init(struct xe_lrc *lrc, struct xe_hw_engine *hwe,void xe_lrc_finish (struct xe_lrc *lrc) {xe_hw_fence_ctx_finish (&lrc->fence_ctx); -if (lrc->bo->vm) -xe_vm_lock (lrc->bo->vm, false); -else -xe_bo_lock_no_vm (lrc->bo,NULL ); +xe_bo_lock (lrc->bo, false);xe_bo_unpin (lrc->bo); -if (lrc->bo->vm) -xe_vm_unlock (lrc->bo->vm); -else -xe_bo_unlock_no_vm (lrc->bo); +xe_bo_unlock (lrc->bo);xe_bo_put (lrc->bo); }
Signature · 1 line
2.41.0
Thomas Hellström
maintainerPATCH v2 5/6 drm/xe: Convert pagefaulting code to use drm_exec
In reply to Thomas HellströmReplace the calls into ttm_eu_reserve_buffers with the drm_exec helpers. Also reuse some code.
--- drivers/gpu/drm/xe/xe_gt_pagefault.c | 106 ++++++++++++--------------- drivers/gpu/drm/xe/xe_vm.c | 15 ++++ drivers/gpu/drm/xe/xe_vm.h | 3 + 3 files changed, 64 insertions(+), 60 deletions(-)
drivers/gpu/drm/xe/xe_gt_pagefault.c +46 -60
@@ -8,6 +8,7 @@#include <linux/bitfield.h> #include <linux/circ_buf.h> +#include <drm/drm_exec.h> #include <drm/drm_managed.h> #include <drm/ttm/ttm_execbuf_util.h>
@@ -84,11 +85,6 @@ static bool vma_matches(struct xe_vma *vma, u64 page_addr)return true; } -static bool only_needs_bo_lock (struct xe_bo *bo) -{ -return bo && bo->vm; -} -static struct xe_vma *lookup_vma (struct xe_vm *vm,u64 page_addr) {struct xe_vma *vma =NULL ;
@@ -103,17 +99,44 @@ static struct xe_vma *lookup_vma(struct xe_vm *vm, u64 page_addr)return vma; } +static int xe_pf_begin (struct drm_exec *exec,struct xe_vma *vma, +unsigned int num_shared,bool atomic,unsigned int id) +{ +struct xe_bo *bo =xe_vma_bo (vma); +struct xe_vm *vm =xe_vma_vm (vma); +int err; + + err =xe_vm_prepare_vma (exec, vma, num_shared); +if (err) +return err; + +if (atomic) { +if (xe_vma_is_userptr (vma)) { + err = -EACCES ; +return err; + } + +/* Migrate to VRAM, move should invalidate the VMA first */ + err =xe_bo_migrate (bo,XE_PL_VRAM0 + id); +if (err) +return err; + }else if (bo) { +/* Create backing store if needed */ + err =xe_bo_validate (bo, vm, true); +if (err) +return err; + } + +return 0 ; +} +static int handle_pagefault (struct xe_gt *gt,struct pagefault *pf) {struct xe_device *xe =gt_to_xe (gt);struct xe_tile *tile =gt_to_tile (gt); +struct drm_exec exec;struct xe_vm *vm;struct xe_vma *vma =NULL ; -struct xe_bo *bo; -LIST_HEAD (objs); -LIST_HEAD (dups); -struct ttm_validate_buffer tv_bo, tv_vm; -struct ww_acquire_ctx ww;struct dma_fence *fence;bool write_locked;int ret =0 ;
@@ -170,35 +193,10 @@ static int handle_pagefault(struct xe_gt *gt, struct pagefault *pf) }/* Lock VM and BOs dma-resv */ - bo =xe_vma_bo (vma); -if (!only_needs_bo_lock (bo)) { - tv_vm.num_shared = xe->info.tile_count; - tv_vm.bo =xe_vm_ttm_bo (vm); -list_add (&tv_vm.head, &objs); - } -if (bo) { - tv_bo.bo = &bo->ttm; - tv_bo.num_shared = xe->info.tile_count; -list_add (&tv_bo.head, &objs); - } - - ret =ttm_eu_reserve_buffers (&ww, &objs, false, &dups); -if (ret) - goto unlock_vm; - -if (atomic) { -if (xe_vma_is_userptr (vma)) { - ret = -EACCES ; - goto unlock_dma_resv; - } - -/* Migrate to VRAM, move should invalidate the VMA first */ - ret =xe_bo_migrate (bo,XE_PL_VRAM0 + tile->id); -if (ret) - goto unlock_dma_resv; - }else if (bo) { -/* Create backing store if needed */ - ret =xe_bo_validate (bo, vm, true); +drm_exec_init (&exec,0 ); + drm_exec_until_all_locked(&exec) { + ret =xe_pf_begin (&exec, vma, xe->info.tile_count, atomic, tile->id); +drm_exec_retry_on_contention (&exec);if (ret) goto unlock_dma_resv; }
@@ -225,7 +223,7 @@ static int handle_pagefault(struct xe_gt *gt, struct pagefault *pf) vma->usm.tile_invalidated &= ~BIT (gt_to_tile (gt)->id); unlock_dma_resv: -ttm_eu_backoff_reservation (&ww, &objs); +drm_exec_fini (&exec); unlock_vm:if (!ret) vm->usm.last_fault_vma = vma;
@@ -490,13 +488,9 @@ static int handle_acc(struct xe_gt *gt, struct acc *acc) {struct xe_device *xe =gt_to_xe (gt);struct xe_tile *tile =gt_to_tile (gt); +struct drm_exec exec;struct xe_vm *vm;struct xe_vma *vma; -struct xe_bo *bo; -LIST_HEAD (objs); -LIST_HEAD (dups); -struct ttm_validate_buffer tv_bo, tv_vm; -struct ww_acquire_ctx ww;int ret =0 ;/* We only support ACC_TRIGGER at the moment */
@@ -528,23 +522,15 @@ static int handle_acc(struct xe_gt *gt, struct acc *acc) goto unlock_vm;/* Lock VM and BOs dma-resv */ - bo =xe_vma_bo (vma); -if (!only_needs_bo_lock (bo)) { - tv_vm.num_shared = xe->info.tile_count; - tv_vm.bo =xe_vm_ttm_bo (vm); -list_add (&tv_vm.head, &objs); +drm_exec_init (&exec,0 ); + drm_exec_until_all_locked(&exec) { + ret =xe_pf_begin (&exec, vma, xe->info.tile_count, true, tile->id); +drm_exec_retry_on_contention (&exec); +if (ret) +break ; } - tv_bo.bo = &bo->ttm; - tv_bo.num_shared = xe->info.tile_count; -list_add (&tv_bo.head, &objs); - ret =ttm_eu_reserve_buffers (&ww, &objs, false, &dups); -if (ret) - goto unlock_vm; - -/* Migrate to VRAM, move should invalidate the VMA first */ - ret =xe_bo_migrate (bo,XE_PL_VRAM0 + tile->id); -ttm_eu_backoff_reservation (&ww, &objs); +drm_exec_fini (&exec); unlock_vm:up_read (&vm->lock);xe_vm_put (vm);
drivers/gpu/drm/xe/xe_vm.c +15 -0
@@ -1091,6 +1091,21 @@ static void xe_vma_destroy(struct xe_vma *vma, struct dma_fence *fence) } } +int xe_vm_prepare_vma (struct drm_exec *exec,struct xe_vma *vma, +unsigned int num_shared) +{ +struct xe_vm *vm =xe_vma_vm (vma); +struct xe_bo *bo =xe_vma_bo (vma); +int err; + +XE_WARN_ON (!vm); + err =drm_exec_prepare_obj (exec, &xe_vm_ttm_bo (vm)->base, num_shared); +if (!err && bo && !bo->vm) + err =drm_exec_prepare_obj (exec, &bo->ttm.base, num_shared); + +return err; +} +static void xe_vma_destroy_unlocked (struct xe_vma *vma) {struct ttm_validate_buffer tv[2 ];
drivers/gpu/drm/xe/xe_vm.h +3 -0
@@ -222,6 +222,9 @@ void xe_vm_fence_all_extobjs(struct xe_vm *vm, struct dma_fence *fence,int xe_analyze_vm (struct drm_printer *p,struct xe_vm *vm,int gt_id); +int xe_vm_prepare_vma (struct drm_exec *exec,struct xe_vma *vma, +unsigned int num_shared); +#if IS_ENABLED (CONFIG_DRM_XE_DEBUG_VM )#define vm_dbg drm_dbg#else
Signature · 1 line
2.41.0
Thomas Hellström
maintainerPATCH v2 2/6 drm/xe/vm: Simplify and document xe_vm_lock()
In reply to Thomas HellströmThe xe_vm_lock() function was unnecessarily using ttm_eu_reserve_buffers(). Simplify and document the interface.
--- drivers/gpu/drm/xe/tests/xe_bo.c | 9 +++-- drivers/gpu/drm/xe/tests/xe_migrate.c | 5 ++- drivers/gpu/drm/xe/xe_bo.c | 5 ++- drivers/gpu/drm/xe/xe_exec_queue.c | 5 ++- drivers/gpu/drm/xe/xe_lrc.c | 6 ++-- drivers/gpu/drm/xe/xe_migrate.c | 10 +++--- drivers/gpu/drm/xe/xe_vm.c | 50 +++++++++++++-------------- drivers/gpu/drm/xe/xe_vm.h | 5 ++- 8 files changed, 42 insertions(+), 53 deletions(-)
drivers/gpu/drm/xe/tests/xe_bo.c +4 -5
@@ -180,17 +180,16 @@ static int evict_test_run_gt(struct xe_device *xe, struct xe_gt *gt, struct kuniunsigned int bo_flags =XE_BO_CREATE_USER_BIT |XE_BO_CREATE_VRAM_IF_DGFX (gt_to_tile (gt));struct xe_vm *vm =xe_migrate_get_vm (xe_device_get_root_tile (xe)->migrate); -struct ww_acquire_ctx ww;int err, i;kunit_info (test,"Testing device %s gt id %u vram id %u\n" ,dev_name (xe->drm.dev), gt->info.id,gt_to_tile (gt)->id);for (i =0 ; i <2 ; ++i) { -xe_vm_lock (vm, &ww,0 , false); +xe_vm_lock (vm, false); bo =xe_bo_create (xe,NULL , vm,0x10000 , ttm_bo_type_device, bo_flags); -xe_vm_unlock (vm, &ww); +xe_vm_unlock (vm);if (IS_ERR (bo)) {KUNIT_FAIL (test,"bo create err=%pe\n" , bo);break ;
@@ -259,9 +258,9 @@ static int evict_test_run_gt(struct xe_device *xe, struct xe_gt *gt, struct kuniif (i) {down_read (&vm->lock); -xe_vm_lock (vm, &ww,0 , false); +xe_vm_lock (vm, false); err =xe_bo_validate (bo, bo->vm, false); -xe_vm_unlock (vm, &ww); +xe_vm_unlock (vm);up_read (&vm->lock);if (err) { KUNIT_FAIL(test, "bo valid err=%pe\n",
drivers/gpu/drm/xe/tests/xe_migrate.c +2 -3
@@ -396,14 +396,13 @@ static int migrate_test_run_device(struct xe_device *xe)for_each_tile (tile, xe, id) {struct xe_migrate *m = tile->migrate; -struct ww_acquire_ctx ww;kunit_info (test,"Testing tile id %d.\n" , id); -xe_vm_lock (m->q->vm, &ww,0 , true); +xe_vm_lock (m->q->vm, true);xe_device_mem_access_get (xe);xe_migrate_sanity_test (m, test);xe_device_mem_access_put (xe); -xe_vm_unlock (m->q->vm, &ww); +xe_vm_unlock (m->q->vm); }return 0 ;
drivers/gpu/drm/xe/xe_bo.c +2 -3
@@ -1749,7 +1749,6 @@ int xe_gem_create_ioctl(struct drm_device *dev, void *data,struct xe_device *xe =to_xe_device (dev);struct xe_file *xef =to_xe_file (file);struct drm_xe_gem_create *args = data; -struct ww_acquire_ctx ww;struct xe_vm *vm =NULL ;struct xe_bo *bo;unsigned int bo_flags =XE_BO_CREATE_USER_BIT ;
@@ -1787,7 +1786,7 @@ int xe_gem_create_ioctl(struct drm_device *dev, void *data, vm =xe_vm_lookup (xef, args->vm_id);if (XE_IOCTL_DBG (xe, !vm))return -ENOENT ; - err =xe_vm_lock (vm, &ww,0 , true); + err =xe_vm_lock (vm, true);if (err) {xe_vm_put (vm);return err;
@@ -1830,7 +1829,7 @@ int xe_gem_create_ioctl(struct drm_device *dev, void *data,xe_bo_put (bo); out_vm:if (vm) { -xe_vm_unlock (vm, &ww); +xe_vm_unlock (vm);xe_vm_put (vm); }return err;
drivers/gpu/drm/xe/xe_exec_queue.c +2 -3
@@ -111,18 +111,17 @@ struct xe_exec_queue *xe_exec_queue_create(struct xe_device *xe, struct xe_vm *v u32 logical_mask, u16 width, struct xe_hw_engine *hwe, u32 flags) { - struct ww_acquire_ctx ww; struct xe_exec_queue *q;int err;if (vm) { - err =xe_vm_lock (vm, &ww,0 , true); + err =xe_vm_lock (vm, true);if (err)return ERR_PTR (err); } q =__xe_exec_queue_create (xe, vm, logical_mask, width, hwe, flags);if (vm) -xe_vm_unlock (vm, &ww); +xe_vm_unlock (vm);return q; }
drivers/gpu/drm/xe/xe_lrc.c +2 -4
@@ -789,16 +789,14 @@ int xe_lrc_init(struct xe_lrc *lrc, struct xe_hw_engine *hwe,void xe_lrc_finish (struct xe_lrc *lrc) { -struct ww_acquire_ctx ww; -xe_hw_fence_ctx_finish (&lrc->fence_ctx);if (lrc->bo->vm) -xe_vm_lock (lrc->bo->vm, &ww,0 , false); +xe_vm_lock (lrc->bo->vm, false);else xe_bo_lock_no_vm (lrc->bo,NULL );xe_bo_unpin (lrc->bo);if (lrc->bo->vm) -xe_vm_unlock (lrc->bo->vm, &ww); +xe_vm_unlock (lrc->bo->vm);else xe_bo_unlock_no_vm (lrc->bo);xe_bo_put (lrc->bo);
drivers/gpu/drm/xe/xe_migrate.c +4 -6
@@ -88,13 +88,12 @@ struct xe_exec_queue *xe_tile_migrate_engine(struct xe_tile *tile)static void xe_migrate_fini (struct drm_device *dev,void *arg) {struct xe_migrate *m = arg; -struct ww_acquire_ctx ww; -xe_vm_lock (m->q->vm, &ww,0 , false); +xe_vm_lock (m->q->vm, false);xe_bo_unpin (m->pt_bo);if (m->cleared_bo)xe_bo_unpin (m->cleared_bo); -xe_vm_unlock (m->q->vm, &ww); +xe_vm_unlock (m->q->vm);dma_fence_put (m->fence);if (m->cleared_bo)
@@ -338,7 +337,6 @@ struct xe_migrate *xe_migrate_init(struct xe_tile *tile)struct xe_gt *primary_gt = tile->primary_gt;struct xe_migrate *m;struct xe_vm *vm; -struct ww_acquire_ctx ww;int err; m =drmm_kzalloc (&xe->drm,sizeof (*m),GFP_KERNEL );
@@ -353,9 +351,9 @@ struct xe_migrate *xe_migrate_init(struct xe_tile *tile)if (IS_ERR (vm))return ERR_CAST (vm); -xe_vm_lock (vm, &ww,0 , false); +xe_vm_lock (vm, false); err =xe_migrate_prepare_vm (tile, m, vm); -xe_vm_unlock (vm, &ww); +xe_vm_unlock (vm);if (err) {xe_vm_close_and_put (vm);return ERR_PTR (err);
drivers/gpu/drm/xe/xe_vm.c +24 -26
114 lines not on this page · raw message
drivers/gpu/drm/xe/xe_vm.h +2 -3
@@ -39,10 +39,9 @@ static inline void xe_vm_put(struct xe_vm *vm)kref_put (&vm->refcount, xe_vm_free); } -int xe_vm_lock (struct xe_vm *vm,struct ww_acquire_ctx *ww, -int num_resv,bool intr); +int xe_vm_lock (struct xe_vm *vm,bool intr); -void xe_vm_unlock (struct xe_vm *vm,struct ww_acquire_ctx *ww); +void xe_vm_unlock (struct xe_vm *vm);static inline bool xe_vm_is_closed (struct xe_vm *vm) {
Signature · 1 line
2.41.0
Thomas Hellström
maintainerPATCH v2 4/6 drm/xe: Rework xe_exec and the VM rebind worker to use the drm_exec helper
In reply to Thomas HellströmReplace the calls to ttm_eu_reserve_buffers() by using the drm_exec helper instead. Also make sure the locking loop covers any calls to xe_bo_validate() / ttm_bo_validate() so that these function calls may easily benefit from being called from within an unsealed locking transaction and may thus perform blocking dma_resv locks in the future.
For the unlock we remove an assert that the vm->rebind_list is empty when locks are released. Since if the error path is hit with a partly locked list, that assert may no longer hold true we chose to remove it.
--- drivers/gpu/drm/xe/Kconfig | 1 + drivers/gpu/drm/xe/xe_exec.c | 71 +++------ drivers/gpu/drm/xe/xe_vm.c | 281 ++++++++++++++++------------------- drivers/gpu/drm/xe/xe_vm.h | 22 +-- 4 files changed, 158 insertions(+), 217 deletions(-)
drivers/gpu/drm/xe/Kconfig +1 -0
@@ -8,6 +8,7 @@ config DRM_XE select SHMEM select TMPFS select DRM_BUDDY + select DRM_EXEC select DRM_KMS_HELPER select DRM_PANEL select DRM_SUBALLOC_HELPER
drivers/gpu/drm/xe/xe_exec.c +20 -51
141 lines not on this page · raw message
drivers/gpu/drm/xe/xe_vm.c +132 -149
369 lines not on this page · raw message
drivers/gpu/drm/xe/xe_vm.h +5 -17
@@ -21,6 +21,7 @@ struct ttm_validate_buffer;struct xe_exec_queue ;struct xe_file ;struct xe_sync_entry ; +struct drm_exec ;struct xe_vm *xe_vm_create (struct xe_device *xe,u32 flags);void xe_vm_free (struct kref *ref);
@@ -211,23 +212,10 @@ int xe_vma_userptr_pin_pages(struct xe_vma *vma);int xe_vma_userptr_check_repin (struct xe_vma *vma); -/* -* XE_ONSTACK_TV is used to size the tv_onstack array that is input -* to xe_vm_lock_dma_resv() and xe_vm_unlock_dma_resv(). -*/ -#define XE_ONSTACK_TV 20 -int xe_vm_lock_dma_resv (struct xe_vm *vm,struct ww_acquire_ctx *ww, -struct ttm_validate_buffer *tv_onstack, -struct ttm_validate_buffer **tv, -struct list_head *objs, -bool intr, -unsigned int num_shared); - -void xe_vm_unlock_dma_resv (struct xe_vm *vm, -struct ttm_validate_buffer *tv_onstack, -struct ttm_validate_buffer *tv, -struct ww_acquire_ctx *ww, -struct list_head *objs); +bool xe_vm_validate_should_retry (struct drm_exec *exec,int err,ktime_t *end); + +int xe_vm_lock_dma_resv (struct xe_vm *vm,struct drm_exec *exec, +unsigned int num_shared,bool lock_vm);void xe_vm_fence_all_extobjs (struct xe_vm *vm,struct dma_fence *fence,enum dma_resv_usage usage);
Signature · 1 line
2.41.0
Thomas Hellström
maintainerPATCH v2 6/6 drm/xe: Convert remaining instances of ttm_eu_reserve_buffers to drm_exec
In reply to Thomas HellströmThe VM_BIND functionality and vma destruction was locking potentially multiple dma_resv objects using the ttm_eu_reserve_buffers() function. Rework those to use the drm_exec helper, taking care that any calls to xe_bo_validate() ends up inside an unsealed locking transaction.
--- drivers/gpu/drm/xe/xe_vm.c | 91 +++++++++++++++----------------------- 1 file changed, 36 insertions(+), 55 deletions(-)
drivers/gpu/drm/xe/xe_vm.c +36 -55
@@ -1108,27 +1108,21 @@ int xe_vm_prepare_vma(struct drm_exec *exec, struct xe_vma *vma,static void xe_vma_destroy_unlocked (struct xe_vma *vma) { -struct ttm_validate_buffer tv[2 ]; -struct ww_acquire_ctx ww;struct xe_bo *bo =xe_vma_bo (vma); -LIST_HEAD (objs); -LIST_HEAD (dups); +struct drm_exec exec;int err; -memset (tv,0 ,sizeof (tv)); - tv[0 ].bo =xe_vm_ttm_bo (xe_vma_vm (vma)); -list_add (&tv[0 ].head, &objs); - -if (bo) { - tv[1 ].bo = &xe_bo_get (bo)->ttm; -list_add (&tv[1 ].head, &objs); +drm_exec_init (&exec,0 ); + drm_exec_until_all_locked(&exec) { + err =xe_vm_prepare_vma (&exec, vma,0 ); +drm_exec_retry_on_contention (&exec); +if (XE_WARN_ON (err)) +break ; } - err =ttm_eu_reserve_buffers (&ww, &objs, false, &dups); -XE_WARN_ON (err);xe_vma_destroy (vma,NULL ); -ttm_eu_backoff_reservation (&ww, &objs); +drm_exec_fini (&exec);if (bo)xe_bo_put (bo); }
@@ -2144,12 +2138,6 @@ struct ttm_buffer_object *xe_vm_ttm_bo(struct xe_vm *vm)return &vm->pt_root[idx]->bo->ttm; } -static void xe_vm_tv_populate (struct xe_vm *vm,struct ttm_validate_buffer *tv) -{ - tv->num_shared =1 ; - tv->bo =xe_vm_ttm_bo (vm); -} -static void vm_set_async_error (struct xe_vm *vm,int err) {lockdep_assert_held (&vm->lock);
@@ -2650,42 +2638,16 @@ static int xe_vma_op_commit(struct xe_vm *vm, struct xe_vma_op *op)return err; } -static int __xe_vma_op_execute (struct xe_vm *vm,struct xe_vma *vma, -struct xe_vma_op *op) +static int op_execute (struct drm_exec *exec,struct xe_vm *vm, +struct xe_vma *vma,struct xe_vma_op *op) { -LIST_HEAD (objs); -LIST_HEAD (dups); -struct ttm_validate_buffer tv_bo, tv_vm; -struct ww_acquire_ctx ww; -struct xe_bo *vbo;int err;lockdep_assert_held_write (&vm->lock); -xe_vm_tv_populate (vm, &tv_vm); -list_add_tail (&tv_vm.head, &objs); - vbo =xe_vma_bo (vma); -if (vbo) { -/* -* An unbind can drop the last reference to the BO and -* the BO is needed for ttm_eu_backoff_reservation so -* take a reference here. -*/ -xe_bo_get (vbo); - -if (!vbo->vm) { - tv_bo.bo = &vbo->ttm; - tv_bo.num_shared =1 ; -list_add (&tv_bo.head, &objs); - } - } - -again: - err =ttm_eu_reserve_buffers (&ww, &objs, true, &dups); -if (err) { -xe_bo_put (vbo); + err =xe_vm_prepare_vma (exec, vma,1 ); +if (err)return err; - }xe_vm_assert_held (vm);xe_bo_assert_held (xe_vma_bo (vma));
@@ -2764,17 +2726,36 @@ static int __xe_vma_op_execute(struct xe_vm *vm, struct xe_vma *vma,XE_WARN_ON ("NOT POSSIBLE" ); } -ttm_eu_backoff_reservation (&ww, &objs); +if (err) +trace_xe_vma_fail (vma); + +return err; +} + +static int __xe_vma_op_execute (struct xe_vm *vm,struct xe_vma *vma, +struct xe_vma_op *op) +{ +struct drm_exec exec; +int err; + +retry_userptr: +drm_exec_init (&exec,DRM_EXEC_INTERRUPTIBLE_WAIT ); + drm_exec_until_all_locked(&exec) { + err =op_execute (&exec, vm, vma, op); +drm_exec_retry_on_contention (&exec); +if (err) +break ; + } +drm_exec_fini (&exec); +if (err == -EAGAIN &&xe_vma_is_userptr (vma)) {lockdep_assert_held_write (&vm->lock); err =xe_vma_userptr_pin_pages (vma);if (!err) - goto again; - } -xe_bo_put (vbo); + goto retry_userptr; -if (err)trace_xe_vma_fail (vma); + }return err; }
Signature · 1 line
2.41.0
Patchwork
CI[Intel-xe] ✗ CI.Patch_applied: failure for drm/xe: Convert to drm_exec
In reply to Thomas Hellström== Series Details ==
== Series Details ==
Series: drm/xe: Convert to drm_exec
URL : https://patchwork.freedesktop.org/series/123100/
State : failure
== Summary ==
=== Applying kernel patches on branch 'drm-xe-next' with base: === Base commit: 72da4b45f drm/xe: Prevent return with locked vm === git am output follows ===
error: patch failed: drivers/gpu/drm/xe/xe_vm.c:267
error: drivers/gpu/drm/xe/xe_vm.c: patch does not apply
hint: Use 'git am --show-current-patch' to see the failed patch
Applying: drm/xe/bo: Simplify xe_bo_lock()
Patch failed at 0001 drm/xe/bo: Simplify xe_bo_lock()
When you have resolved this problem, run "git am --continue". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort".