Skip to contentSkip to conversation

Upstreaming prep / all of mbrosts patches

PATCH In review Matthew Brost 8 participants 126 messages May 2, 2023 – Jun 12, 2023 Page 2 of 2

Subsystems (16)
lore
Share & tools
lore
maintainer
#78 lore raw

Re: [Intel-xe] [PATCH v2 17/31] drm/xe: NULL binding implementation

In reply to Matthew Brost
Quoted 3 lines · Matthew Brost

Add uAPI and implementation for NULL bindings. A NULL binding is defined as writes dropped and read zero. A single bit in the uAPI has been added which results in a single bit in the PTEs being set.

I have confirmed in the spec that this is the case for the BIT 9!

"If Null=1, the h/w will avoid the memory access and return all zero's for the read access with a null completion, write accesses are dropped"

The code looks good, but just a few questions / comments below.

Quoted 2 lines

NULL bindings are indended to be used to implement VK sparse bindings.

is there any example available or any documentation that could explain how this is used and why this is needed?

any IGT?

Quoted 31 lines
---
 drivers/gpu/drm/xe/xe_bo.h           |  1 +
 drivers/gpu/drm/xe/xe_exec.c         |  2 +
 drivers/gpu/drm/xe/xe_gt_pagefault.c |  4 +-
 drivers/gpu/drm/xe/xe_pt.c           | 77 ++++++++++++++++-------
 drivers/gpu/drm/xe/xe_vm.c           | 92 ++++++++++++++++++----------
 drivers/gpu/drm/xe/xe_vm.h           | 10 +++
 drivers/gpu/drm/xe/xe_vm_madvise.c   |  2 +-
 drivers/gpu/drm/xe/xe_vm_types.h     |  3 +
 include/uapi/drm/xe_drm.h            |  8 +++
 9 files changed, 144 insertions(+), 55 deletions(-)
drivers/gpu/drm/xe/xe_bo.h +1 -0
index 25457b3c757b..81051f456874 100644
@@ -56,6 +56,7 @@
 #define XE_PDE_IPS_64K			BIT_ULL(11)
 
 #define XE_GGTT_PTE_LM			BIT_ULL(1)
+#define XE_PTE_NULL			BIT_ULL(9)
 #define XE_USM_PPGTT_PTE_AE		BIT_ULL(10)
 #define XE_PPGTT_PTE_LM			BIT_ULL(11)
 #define XE_PDE_64K			BIT_ULL(6)
drivers/gpu/drm/xe/xe_exec.c +0 -0
index 90c46d092737..68f876afd13c 100644

drivers/gpu/drm/xe/xe_exec.c static int xe_exec_begin(struct xe_engine *e, struct ww_acquire_ctx *ww, · line 119

Quoted 4 lines
drivers/gpu/drm/xe/xe_exec.c +1 -0
@@ -116,6 +116,8 @@ static int xe_exec_begin(struct xe_engine *e, struct ww_acquire_ctx *ww,
 	 * to a location where the GPU can access it).
 	 */
 	list_for_each_entry(vma, &vm->rebind_list, rebind_link) {
+		XE_BUG_ON(xe_vma_is_null(vma));

Can we avoid BUG here? Maybe a WARN?

Quoted 537 lines
drivers/gpu/drm/xe/xe_exec.c +1 -0
+
 		if (xe_vma_is_userptr(vma))
 			continue;
 
drivers/gpu/drm/xe/xe_gt_pagefault.c +2 -2
index f7a066090a13..cfffe3398fe4 100644
@@ -526,8 +526,8 @@ static int handle_acc(struct xe_gt *gt, struct acc *acc)
 
 	trace_xe_vma_acc(vma);
 
-	/* Userptr can't be migrated, nothing to do */
-	if (xe_vma_is_userptr(vma))
+	/* Userptr or null can't be migrated, nothing to do */
+	if (xe_vma_has_no_bo(vma))
 		goto unlock_vm;
 
 	/* Lock VM and BOs dma-resv */
drivers/gpu/drm/xe/xe_pt.c +56 -21
index 2b5b05a8a084..b4edb751bfbb 100644
@@ -82,7 +82,9 @@ u64 gen8_pde_encode(struct xe_bo *bo, u64 bo_offset,
 static dma_addr_t vma_addr(struct xe_vma *vma, u64 offset,
 			   size_t page_size, bool *is_vram)
 {
-	if (xe_vma_is_userptr(vma)) {
+	if (xe_vma_is_null(vma)) {
+		return 0;
+	} else if (xe_vma_is_userptr(vma)) {
 		struct xe_res_cursor cur;
 		u64 page;
 
@@ -563,6 +565,10 @@ static bool xe_pt_hugepte_possible(u64 addr, u64 next, unsigned int level,
 	if (next - xe_walk->va_curs_start > xe_walk->curs->size)
 		return false;
 
+	/* null VMA's do not have dma adresses */
+	if (xe_walk->pte_flags & XE_PTE_NULL)
+		return true;
+
 	/* Is the DMA address huge PTE size aligned? */
 	size = next - addr;
 	dma = addr - xe_walk->va_curs_start + xe_res_dma(xe_walk->curs);
@@ -585,6 +591,10 @@ xe_pt_scan_64K(u64 addr, u64 next, struct xe_pt_stage_bind_walk *xe_walk)
 	if (next > xe_walk->l0_end_addr)
 		return false;
 
+	/* null VMA's do not have dma adresses */
+	if (xe_walk->pte_flags & XE_PTE_NULL)
+		return true;
+
 	xe_res_next(&curs, addr - xe_walk->va_curs_start);
 	for (; addr < next; addr += SZ_64K) {
 		if (!IS_ALIGNED(xe_res_dma(&curs), SZ_64K) || curs.size < SZ_64K)
@@ -630,17 +640,34 @@ xe_pt_stage_bind_entry(struct drm_pt *parent, pgoff_t offset,
 	struct xe_pt *xe_child;
 	bool covers;
 	int ret = 0;
-	u64 pte;
+	u64 pte = 0;
 
 	/* Is this a leaf entry ?*/
 	if (level == 0 || xe_pt_hugepte_possible(addr, next, level, xe_walk)) {
 		struct xe_res_cursor *curs = xe_walk->curs;
+		bool null = xe_walk->pte_flags & XE_PTE_NULL;
 
 		XE_WARN_ON(xe_walk->va_curs_start != addr);
 
-		pte = __gen8_pte_encode(xe_res_dma(curs) + xe_walk->dma_offset,
-					xe_walk->cache, xe_walk->pte_flags,
-					level);
+		if (null) {
+			pte |= XE_PAGE_PRESENT | XE_PAGE_RW;
+
+			if (unlikely(xe_walk->pte_flags & XE_PTE_READ_ONLY))
+				pte &= ~XE_PAGE_RW;
+
+			if (level == 1)
+				pte |= XE_PDE_PS_2M;
+			else if (level == 2)
+				pte |= XE_PDPE_PS_1G;
+
+			pte |= XE_PTE_NULL;
+		} else {
+			pte = __gen8_pte_encode(xe_res_dma(curs) +
+						xe_walk->dma_offset,
+						xe_walk->cache,
+						xe_walk->pte_flags,
+						level);
+		}
 		pte |= xe_walk->default_pte;
 
 		/*
@@ -658,7 +685,8 @@ xe_pt_stage_bind_entry(struct drm_pt *parent, pgoff_t offset,
 		if (unlikely(ret))
 			return ret;
 
-		xe_res_next(curs, next - addr);
+		if (!null)
+			xe_res_next(curs, next - addr);
 		xe_walk->va_curs_start = next;
 		*action = ACTION_CONTINUE;
 
@@ -751,7 +779,8 @@ xe_pt_stage_bind(struct xe_gt *gt, struct xe_vma *vma,
 		.gt = gt,
 		.curs = &curs,
 		.va_curs_start = xe_vma_start(vma),
-		.pte_flags = xe_vma_read_only(vma) ? XE_PTE_READ_ONLY : 0,
+		.pte_flags = xe_vma_read_only(vma) ? XE_PTE_READ_ONLY : 0 |
+			xe_vma_is_null(vma) ? XE_PTE_NULL : 0,
 		.wupd.entries = entries,
 		.needs_64K = (xe_vma_vm(vma)->flags & XE_VM_FLAGS_64K) &&
 			is_vram,
@@ -769,23 +798,28 @@ xe_pt_stage_bind(struct xe_gt *gt, struct xe_vma *vma,
 			gt_to_xe(gt)->mem.vram.io_start;
 		xe_walk.cache = XE_CACHE_WB;
 	} else {
-		if (!xe_vma_is_userptr(vma) && bo->flags & XE_BO_SCANOUT_BIT)
+		if (!xe_vma_has_no_bo(vma) && bo->flags & XE_BO_SCANOUT_BIT)
 			xe_walk.cache = XE_CACHE_WT;
 		else
 			xe_walk.cache = XE_CACHE_WB;
 	}
-	if (!xe_vma_is_userptr(vma) && xe_bo_is_stolen(bo))
+	if (!xe_vma_has_no_bo(vma) && xe_bo_is_stolen(bo))
 		xe_walk.dma_offset = xe_ttm_stolen_gpu_offset(xe_bo_device(bo));
 
 	xe_bo_assert_held(bo);
-	if (xe_vma_is_userptr(vma))
-		xe_res_first_sg(vma->userptr.sg, 0, xe_vma_size(vma), &curs);
-	else if (xe_bo_is_vram(bo) || xe_bo_is_stolen(bo))
-		xe_res_first(bo->ttm.resource, xe_vma_bo_offset(vma),
-			     xe_vma_size(vma), &curs);
-	else
-		xe_res_first_sg(xe_bo_get_sg(bo), xe_vma_bo_offset(vma),
-				xe_vma_size(vma), &curs);
+	if (!xe_vma_is_null(vma)) {
+		if (xe_vma_is_userptr(vma))
+			xe_res_first_sg(vma->userptr.sg, 0, xe_vma_size(vma),
+					&curs);
+		else if (xe_bo_is_vram(bo) || xe_bo_is_stolen(bo))
+			xe_res_first(bo->ttm.resource, xe_vma_bo_offset(vma),
+				     xe_vma_size(vma), &curs);
+		else
+			xe_res_first_sg(xe_bo_get_sg(bo), xe_vma_bo_offset(vma),
+					xe_vma_size(vma), &curs);
+	} else {
+		curs.size = xe_vma_size(vma);
+	}
 
 	ret = drm_pt_walk_range(&pt->drm, pt->level, xe_vma_start(vma),
 				xe_vma_end(vma), &xe_walk.drm);
@@ -979,7 +1013,7 @@ static void xe_pt_commit_locks_assert(struct xe_vma *vma)
 
 	if (xe_vma_is_userptr(vma))
 		lockdep_assert_held_read(&vm->userptr.notifier_lock);
-	else
+	else if (!xe_vma_is_null(vma))
 		dma_resv_assert_held(xe_vma_bo(vma)->ttm.base.resv);
 
 	dma_resv_assert_held(&vm->resv);
@@ -1283,7 +1317,8 @@ __xe_pt_bind_vma(struct xe_gt *gt, struct xe_vma *vma, struct xe_engine *e,
 	struct xe_vm_pgtable_update entries[XE_VM_MAX_LEVEL * 2 + 1];
 	struct xe_pt_migrate_pt_update bind_pt_update = {
 		.base = {
-			.ops = xe_vma_is_userptr(vma) ? &userptr_bind_ops : &bind_ops,
+			.ops = xe_vma_is_userptr(vma) ? &userptr_bind_ops :
+				&bind_ops,
 			.vma = vma,
 		},
 		.bind = true,
@@ -1348,7 +1383,7 @@ __xe_pt_bind_vma(struct xe_gt *gt, struct xe_vma *vma, struct xe_engine *e,
 				   DMA_RESV_USAGE_KERNEL :
 				   DMA_RESV_USAGE_BOOKKEEP);
 
-		if (!xe_vma_is_userptr(vma) && !xe_vma_bo(vma)->vm)
+		if (!xe_vma_has_no_bo(vma) && !xe_vma_bo(vma)->vm)
 			dma_resv_add_fence(xe_vma_bo(vma)->ttm.base.resv, fence,
 					   DMA_RESV_USAGE_BOOKKEEP);
 		xe_pt_commit_bind(vma, entries, num_entries, rebind,
@@ -1667,7 +1702,7 @@ __xe_pt_unbind_vma(struct xe_gt *gt, struct xe_vma *vma, struct xe_engine *e,
 				   DMA_RESV_USAGE_BOOKKEEP);
 
 		/* This fence will be installed by caller when doing eviction */
-		if (!xe_vma_is_userptr(vma) && !xe_vma_bo(vma)->vm)
+		if (!xe_vma_has_no_bo(vma) && !xe_vma_bo(vma)->vm)
 			dma_resv_add_fence(xe_vma_bo(vma)->ttm.base.resv, fence,
 					   DMA_RESV_USAGE_BOOKKEEP);
 		xe_pt_commit_unbind(vma, entries, num_entries,
drivers/gpu/drm/xe/xe_vm.c +61 -31
index f3608865e259..a46f44ab2546 100644
@@ -60,6 +60,7 @@ int xe_vma_userptr_pin_pages(struct xe_vma *vma)
 
 	lockdep_assert_held(&vm->lock);
 	XE_BUG_ON(!xe_vma_is_userptr(vma));
+	XE_BUG_ON(xe_vma_is_null(vma));
 retry:
 	if (vma->gpuva.flags & XE_VMA_DESTROYED)
 		return 0;
@@ -581,7 +582,7 @@ static void preempt_rebind_work_func(struct work_struct *w)
 		goto out_unlock;
 
 	list_for_each_entry(vma, &vm->rebind_list, rebind_link) {
-		if (xe_vma_is_userptr(vma) ||
+		if (xe_vma_has_no_bo(vma) ||
 		    vma->gpuva.flags & XE_VMA_DESTROYED)
 			continue;
 
@@ -813,7 +814,7 @@ static struct xe_vma *xe_vma_create(struct xe_vm *vm,
 				    struct xe_bo *bo,
 				    u64 bo_offset_or_userptr,
 				    u64 start, u64 end,
-				    bool read_only,
+				    bool read_only, bool null,
 				    u64 gt_mask)
 {
 	struct xe_vma *vma;
@@ -843,6 +844,8 @@ static struct xe_vma *xe_vma_create(struct xe_vm *vm,
 	vma->gpuva.va.range = end - start + 1;
 	if (read_only)
 		vma->gpuva.flags |= XE_VMA_READ_ONLY;
+	if (null)
+		vma->gpuva.flags |= XE_VMA_NULL;
 
 	if (gt_mask) {
 		vma->gt_mask = gt_mask;
@@ -862,23 +865,26 @@ static struct xe_vma *xe_vma_create(struct xe_vm *vm,
 		vma->gpuva.gem.obj = &bo->ttm.base;
 		vma->gpuva.gem.offset = bo_offset_or_userptr;
 		drm_gpuva_link(&vma->gpuva);
-	} else /* userptr */ {
-		u64 size = end - start + 1;
-		int err;
-
-		vma->gpuva.gem.offset = bo_offset_or_userptr;
+	} else /* userptr or null */ {
+		if (!null) {
+			u64 size = end - start + 1;
+			int err;
+
+			vma->gpuva.gem.offset = bo_offset_or_userptr;
+			err = mmu_interval_notifier_insert(&vma->userptr.notifier,
+							   current->mm,
+							   xe_vma_userptr(vma),
+							   size,
+							   &vma_userptr_notifier_ops);
+			if (err) {
+				kfree(vma);
+				vma = ERR_PTR(err);
+				return vma;
+			}
 
-		err = mmu_interval_notifier_insert(&vma->userptr.notifier,
-						   current->mm,
-						   xe_vma_userptr(vma), size,
-						   &vma_userptr_notifier_ops);
-		if (err) {
-			kfree(vma);
-			vma = ERR_PTR(err);
-			return vma;
+			vma->userptr.notifier_seq = LONG_MAX;
 		}
 
-		vma->userptr.notifier_seq = LONG_MAX;
 		xe_vm_get(vm);
 	}
 
@@ -916,6 +922,8 @@ static void xe_vma_destroy_late(struct xe_vma *vma)
 		 */
 		mmu_interval_notifier_remove(&vma->userptr.notifier);
 		xe_vm_put(vm);
+	} else if (xe_vma_is_null(vma)) {
+		xe_vm_put(vm);
 	} else {
 		xe_bo_put(xe_vma_bo(vma));
 	}
@@ -954,7 +962,7 @@ static void xe_vma_destroy(struct xe_vma *vma, struct dma_fence *fence)
 		list_del_init(&vma->userptr.invalidate_link);
 		spin_unlock(&vm->userptr.invalidated_lock);
 		list_del(&vma->userptr_link);
-	} else {
+	} else if (!xe_vma_is_null(vma)) {
 		xe_bo_assert_held(xe_vma_bo(vma));
 		drm_gpuva_unlink(&vma->gpuva);
 		if (!xe_vma_bo(vma)->vm)
@@ -1305,7 +1313,7 @@ void xe_vm_close_and_put(struct xe_vm *vm)
 	drm_gpuva_iter_for_each(gpuva, it) {
 		vma = gpuva_to_vma(gpuva);
 
-		if (xe_vma_is_userptr(vma)) {
+		if (xe_vma_has_no_bo(vma)) {
 			down_read(&vm->userptr.notifier_lock);
 			vma->gpuva.flags |= XE_VMA_DESTROYED;
 			up_read(&vm->userptr.notifier_lock);
@@ -1315,7 +1323,7 @@ void xe_vm_close_and_put(struct xe_vm *vm)
 		drm_gpuva_iter_remove(&it);
 
 		/* easy case, remove from VMA? */
-		if (xe_vma_is_userptr(vma) || xe_vma_bo(vma)->vm) {
+		if (xe_vma_has_no_bo(vma) || xe_vma_bo(vma)->vm) {
 			xe_vma_destroy(vma, NULL);
 			continue;
 		}
@@ -1964,7 +1972,7 @@ static int xe_vm_prefetch(struct xe_vm *vm, struct xe_vma *vma,
 
 	XE_BUG_ON(region > ARRAY_SIZE(region_to_mem_type));
 
-	if (!xe_vma_is_userptr(vma)) {
+	if (!xe_vma_has_no_bo(vma)) {
 		err = xe_bo_migrate(xe_vma_bo(vma), region_to_mem_type[region]);
 		if (err)
 			return err;
@@ -2170,6 +2178,7 @@ vm_bind_ioctl_ops_create(struct xe_vm *vm, struct xe_bo *bo,
 				operation & XE_VM_BIND_FLAG_IMMEDIATE;
 			op->map.read_only =
 				operation & XE_VM_BIND_FLAG_READONLY;
+			op->map.null = operation & XE_VM_BIND_FLAG_NULL;
 		}
 		break;
 	case XE_VM_BIND_OP_UNMAP:
@@ -2226,7 +2235,7 @@ vm_bind_ioctl_ops_create(struct xe_vm *vm, struct xe_bo *bo,
 }
 
 static struct xe_vma *new_vma(struct xe_vm *vm, struct drm_gpuva_op_map *op,
-			      u64 gt_mask, bool read_only)
+			      u64 gt_mask, bool read_only, bool null)
 {
 	struct xe_bo *bo = op->gem.obj ? gem_to_xe_bo(op->gem.obj) : NULL;
 	struct xe_vma *vma;
@@ -2242,7 +2251,7 @@ static struct xe_vma *new_vma(struct xe_vm *vm, struct drm_gpuva_op_map *op,
 	}
 	vma = xe_vma_create(vm, bo, op->gem.offset,
 			    op->va.addr, op->va.addr +
-			    op->va.range - 1, read_only,
+			    op->va.range - 1, read_only, null,
 			    gt_mask);
 	if (bo)
 		xe_bo_unlock(bo, &ww);
@@ -2254,7 +2263,7 @@ static struct xe_vma *new_vma(struct xe_vm *vm, struct drm_gpuva_op_map *op,
 			xe_vma_destroy(vma, NULL);
 			return ERR_PTR(err);
 		}
-	} else if(!bo->vm) {
+	} else if(!xe_vma_has_no_bo(vma) && !bo->vm) {
 		vm_insert_extobj(vm, vma);
 		err = add_preempt_fences(vm, bo);
 		if (err) {
@@ -2332,7 +2341,8 @@ static int vm_bind_ioctl_ops_parse(struct xe_vm *vm, struct xe_engine *e,
 				struct xe_vma *vma;
 
 				vma = new_vma(vm, &op->base.map,
-					      op->gt_mask, op->map.read_only);
+					      op->gt_mask, op->map.read_only,
+					      op->map.null );
 				if (IS_ERR(vma)) {
 					err = PTR_ERR(vma);
 					goto free_fence;
@@ -2347,9 +2357,13 @@ static int vm_bind_ioctl_ops_parse(struct xe_vm *vm, struct xe_engine *e,
 					bool read_only =
 						op->base.remap.unmap->va->flags &
 						XE_VMA_READ_ONLY;
+					bool null =
+						op->base.remap.unmap->va->flags &
+						XE_VMA_NULL;
 
 					vma = new_vma(vm, op->base.remap.prev,
-						      op->gt_mask, read_only);
+						      op->gt_mask, read_only,
+						      null);
 					if (IS_ERR(vma)) {
 						err = PTR_ERR(vma);
 						goto free_fence;
@@ -2364,8 +2378,13 @@ static int vm_bind_ioctl_ops_parse(struct xe_vm *vm, struct xe_engine *e,
 						op->base.remap.unmap->va->flags &
 						XE_VMA_READ_ONLY;
 
+					bool null =
+						op->base.remap.unmap->va->flags &
+						XE_VMA_NULL;
+
 					vma = new_vma(vm, op->base.remap.next,
-						      op->gt_mask, read_only);
+						      op->gt_mask, read_only,
+						      null);
 					if (IS_ERR(vma)) {
 						err = PTR_ERR(vma);
 						goto free_fence;
@@ -2853,11 +2872,12 @@ static void vm_bind_ioctl_ops_unwind(struct xe_vm *vm,
 #ifdef TEST_VM_ASYNC_OPS_ERROR
 #define SUPPORTED_FLAGS	\
 	(FORCE_ASYNC_OP_ERROR | XE_VM_BIND_FLAG_ASYNC | \
-	 XE_VM_BIND_FLAG_READONLY | XE_VM_BIND_FLAG_IMMEDIATE | 0xffff)
+	 XE_VM_BIND_FLAG_READONLY | XE_VM_BIND_FLAG_IMMEDIATE | \
+	 XE_VM_BIND_FLAG_NULL | 0xffff)
 #else
 #define SUPPORTED_FLAGS	\
 	(XE_VM_BIND_FLAG_ASYNC | XE_VM_BIND_FLAG_READONLY | \
-	 XE_VM_BIND_FLAG_IMMEDIATE | 0xffff)
+	 XE_VM_BIND_FLAG_IMMEDIATE | XE_VM_BIND_FLAG_NULL | 0xffff)
 #endif
 #define XE_64K_PAGE_MASK 0xffffull
 
@@ -2903,6 +2923,7 @@ static int vm_bind_ioctl_check_args(struct xe_device *xe,
 		u32 obj = (*bind_ops)[i].obj;
 		u64 obj_offset = (*bind_ops)[i].obj_offset;
 		u32 region = (*bind_ops)[i].region;
+		bool null = op &  XE_VM_BIND_FLAG_NULL;
 
 		if (i == 0) {
 			*async = !!(op & XE_VM_BIND_FLAG_ASYNC);
@@ -2929,8 +2950,12 @@ static int vm_bind_ioctl_check_args(struct xe_device *xe,
 		if (XE_IOCTL_ERR(xe, VM_BIND_OP(op) >
 				 XE_VM_BIND_OP_PREFETCH) ||
 		    XE_IOCTL_ERR(xe, op & ~SUPPORTED_FLAGS) ||
+		    XE_IOCTL_ERR(xe, obj && null) ||
+		    XE_IOCTL_ERR(xe, obj_offset && null) ||
+		    XE_IOCTL_ERR(xe, VM_BIND_OP(op) != XE_VM_BIND_OP_MAP &&
+				 null) ||
 		    XE_IOCTL_ERR(xe, !obj &&
-				 VM_BIND_OP(op) == XE_VM_BIND_OP_MAP) ||
+				 VM_BIND_OP(op) == XE_VM_BIND_OP_MAP && !null) ||
 		    XE_IOCTL_ERR(xe, !obj &&
 				 VM_BIND_OP(op) == XE_VM_BIND_OP_UNMAP_ALL) ||
 		    XE_IOCTL_ERR(xe, addr &&
@@ -3254,6 +3279,7 @@ int xe_vm_invalidate_vma(struct xe_vma *vma)
 	int ret;
 
 	XE_BUG_ON(!xe_vm_in_fault_mode(xe_vma_vm(vma)));
+	XE_BUG_ON(xe_vma_is_null(vma));
 	trace_xe_vma_usm_invalidate(vma);
 
 	/* Check that we don't race with page-table updates */
@@ -3313,8 +3339,11 @@ int xe_analyze_vm(struct drm_printer *p, struct xe_vm *vm, int gt_id)
 	drm_gpuva_iter_for_each(gpuva, it) {
 		struct xe_vma* vma = gpuva_to_vma(gpuva);
 		bool is_userptr = xe_vma_is_userptr(vma);
+		bool null = xe_vma_is_null(vma);
 
-		if (is_userptr) {
+		if (null) {
+			addr = 0;
+		} else if (is_userptr) {
 			struct xe_res_cursor cur;
 
 			xe_res_first_sg(vma->userptr.sg, 0, XE_PAGE_SIZE, &cur);
@@ -3324,7 +3353,8 @@ int xe_analyze_vm(struct drm_printer *p, struct xe_vm *vm, int gt_id)
 		}
 		drm_printf(p, " [%016llx-%016llx] S:0x%016llx A:%016llx %s\n",
 			   xe_vma_start(vma), xe_vma_end(vma), xe_vma_size(vma),
-			   addr, is_userptr ? "USR" : is_vram ? "VRAM" : "SYS");
+			   addr, null ? "NULL" :
+			   is_userptr ? "USR" : is_vram ? "VRAM" : "SYS");
 	}
 	up_read(&vm->lock);
 
drivers/gpu/drm/xe/xe_vm.h +10 -0
index 21b1054949c4..96e2c6b07bf8 100644
@@ -175,7 +175,17 @@ static inline void xe_vm_reactivate_rebind(struct xe_vm *vm)
 	}
 }
 
+static inline bool xe_vma_is_null(struct xe_vma *vma)
+{
+	return vma->gpuva.flags & XE_VMA_NULL;
+}
+
 static inline bool xe_vma_is_userptr(struct xe_vma *vma)
+{
+	return !xe_vma_bo(vma) && !xe_vma_is_null(vma);
+}
+
+static inline bool xe_vma_has_no_bo(struct xe_vma *vma)
 {
 	return !xe_vma_bo(vma);
 }
drivers/gpu/drm/xe/xe_vm_madvise.c +1 -1
index 02d27a354b36..03508645fa08 100644
@@ -227,7 +227,7 @@ get_vmas(struct xe_vm *vm, int *num_vmas, u64 addr, u64 range)
 	drm_gpuva_iter_for_each_range(gpuva, it, addr + range) {
 		struct xe_vma *vma = gpuva_to_vma(gpuva);
 
-		if (xe_vma_is_userptr(vma))
+		if (xe_vma_has_no_bo(vma))
 			continue;
 
 		if (*num_vmas == max_vmas) {
drivers/gpu/drm/xe/xe_vm_types.h +3 -0
index 243dc91a61b0..b61007b70502 100644
@@ -29,6 +29,7 @@ struct xe_vm;
 #define XE_VMA_ATOMIC_PTE_BIT	(DRM_GPUVA_USERBITS << 2)
 #define XE_VMA_FIRST_REBIND	(DRM_GPUVA_USERBITS << 3)
 #define XE_VMA_LAST_REBIND	(DRM_GPUVA_USERBITS << 4)
+#define XE_VMA_NULL		(DRM_GPUVA_USERBITS << 5)
 
 struct xe_vma {
 	/** @gpuva: Base GPUVA object */
@@ -315,6 +316,8 @@ struct xe_vma_op_map {
 	bool immediate;
 	/** @read_only: Read only */
 	bool read_only;
+	/** @null: NULL (writes dropped, read zero) */
+	bool null;
 };
 
 /** struct xe_vma_op_unmap - VMA unmap operation */
include/uapi/drm/xe_drm.h +8 -0
index b0b80aae3ee8..27c51946fadd 100644
@@ -447,6 +447,14 @@ struct drm_xe_vm_bind_op {
 	 * than differing the MAP to the page fault handler.
 	 */
 #define XE_VM_BIND_FLAG_IMMEDIATE	(0x1 << 18)
+	/*
+	 * When the NULL flag is set, the page tables are setup with a special
+	 * bit which indicates writes are dropped and all reads return zero. The
+	 * NULL flags is only valid for XE_VM_BIND_OP_MAP operations, the BO
+	 * handle MBZ, and the BO offset MBZ. This flag is intended to implement
+	 * VK sparse bindings.
+	 */
+#define XE_VM_BIND_FLAG_NULL		(0x1 << 19)
 
 	/** @reserved: Reserved */
 	__u64 reserved[2];
Signature · 1 line
2.34.1
author maintainer
#79 lore raw

Re: [Intel-xe] [PATCH v2 17/31] drm/xe: NULL binding implementation

Quoted 10 lines · Rodrigo Vivi
Quoted 3 lines · Matthew Brost

Add uAPI and implementation for NULL bindings. A NULL binding is defined as writes dropped and read zero. A single bit in the uAPI has been added which results in a single bit in the PTEs being set.

I have confirmed in the spec that this is the case for the BIT 9!

"If Null=1, the h/w will avoid the memory access and return all zero's for the read access with a null completion, write accesses are dropped"

Quoted 8 lines

The code looks good, but just a few questions / comments below.

Quoted 2 lines

NULL bindings are indended to be used to implement VK sparse bindings.

is there any example available or any documentation that could explain how this is used and why this is needed?

VK sparse being needs this:
https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkQueueBindSparse.html

Quoted 2 lines

any IGT?

https://patchwork.freedesktop.org/patch/534957/?series=117177&rev=2

Quoted 21 lines
Quoted 21 lines
---
 drivers/gpu/drm/xe/xe_bo.h           |  1 +
 drivers/gpu/drm/xe/xe_exec.c         |  2 +
 drivers/gpu/drm/xe/xe_gt_pagefault.c |  4 +-
 drivers/gpu/drm/xe/xe_pt.c           | 77 ++++++++++++++++-------
 drivers/gpu/drm/xe/xe_vm.c           | 92 ++++++++++++++++++----------
 drivers/gpu/drm/xe/xe_vm.h           | 10 +++
 drivers/gpu/drm/xe/xe_vm_madvise.c   |  2 +-
 drivers/gpu/drm/xe/xe_vm_types.h     |  3 +
 include/uapi/drm/xe_drm.h            |  8 +++
 9 files changed, 144 insertions(+), 55 deletions(-)
drivers/gpu/drm/xe/xe_bo.h +0 -0
index 25457b3c757b..81051f456874 100644
@@ -56,6 +56,7 @@
 #define XE_PDE_IPS_64K			BIT_ULL(11)
 
Quoted 17 lines
Quoted 10 lines
drivers/gpu/drm/xe/xe_bo.h +1 -0
 #define XE_GGTT_PTE_LM			BIT_ULL(1)
+#define XE_PTE_NULL			BIT_ULL(9)
 #define XE_USM_PPGTT_PTE_AE		BIT_ULL(10)
 #define XE_PPGTT_PTE_LM			BIT_ULL(11)
 #define XE_PDE_64K			BIT_ULL(6)
drivers/gpu/drm/xe/xe_exec.c +0 -0
index 90c46d092737..68f876afd13c 100644

drivers/gpu/drm/xe/xe_exec.c static int xe_exec_begin(struct xe_engine *e, struct ww_acquire_ctx *ww, · line 119

Quoted 4 lines
drivers/gpu/drm/xe/xe_exec.c +1 -0
@@ -116,6 +116,8 @@ static int xe_exec_begin(struct xe_engine *e, struct ww_acquire_ctx *ww,
 	 * to a location where the GPU can access it).
 	 */
 	list_for_each_entry(vma, &vm->rebind_list, rebind_link) {
+		XE_BUG_ON(xe_vma_is_null(vma));

Can we avoid BUG here? Maybe a WARN?

Sure.

Matt

Quoted 537 lines
Quoted 537 lines
drivers/gpu/drm/xe/xe_exec.c +1 -0
+
 		if (xe_vma_is_userptr(vma))
 			continue;
 
drivers/gpu/drm/xe/xe_gt_pagefault.c +2 -2
index f7a066090a13..cfffe3398fe4 100644
@@ -526,8 +526,8 @@ static int handle_acc(struct xe_gt *gt, struct acc *acc)
 
 	trace_xe_vma_acc(vma);
 
-	/* Userptr can't be migrated, nothing to do */
-	if (xe_vma_is_userptr(vma))
+	/* Userptr or null can't be migrated, nothing to do */
+	if (xe_vma_has_no_bo(vma))
 		goto unlock_vm;
 
 	/* Lock VM and BOs dma-resv */
drivers/gpu/drm/xe/xe_pt.c +56 -21
index 2b5b05a8a084..b4edb751bfbb 100644
@@ -82,7 +82,9 @@ u64 gen8_pde_encode(struct xe_bo *bo, u64 bo_offset,
 static dma_addr_t vma_addr(struct xe_vma *vma, u64 offset,
 			   size_t page_size, bool *is_vram)
 {
-	if (xe_vma_is_userptr(vma)) {
+	if (xe_vma_is_null(vma)) {
+		return 0;
+	} else if (xe_vma_is_userptr(vma)) {
 		struct xe_res_cursor cur;
 		u64 page;
 
@@ -563,6 +565,10 @@ static bool xe_pt_hugepte_possible(u64 addr, u64 next, unsigned int level,
 	if (next - xe_walk->va_curs_start > xe_walk->curs->size)
 		return false;
 
+	/* null VMA's do not have dma adresses */
+	if (xe_walk->pte_flags & XE_PTE_NULL)
+		return true;
+
 	/* Is the DMA address huge PTE size aligned? */
 	size = next - addr;
 	dma = addr - xe_walk->va_curs_start + xe_res_dma(xe_walk->curs);
@@ -585,6 +591,10 @@ xe_pt_scan_64K(u64 addr, u64 next, struct xe_pt_stage_bind_walk *xe_walk)
 	if (next > xe_walk->l0_end_addr)
 		return false;
 
+	/* null VMA's do not have dma adresses */
+	if (xe_walk->pte_flags & XE_PTE_NULL)
+		return true;
+
 	xe_res_next(&curs, addr - xe_walk->va_curs_start);
 	for (; addr < next; addr += SZ_64K) {
 		if (!IS_ALIGNED(xe_res_dma(&curs), SZ_64K) || curs.size < SZ_64K)
@@ -630,17 +640,34 @@ xe_pt_stage_bind_entry(struct drm_pt *parent, pgoff_t offset,
 	struct xe_pt *xe_child;
 	bool covers;
 	int ret = 0;
-	u64 pte;
+	u64 pte = 0;
 
 	/* Is this a leaf entry ?*/
 	if (level == 0 || xe_pt_hugepte_possible(addr, next, level, xe_walk)) {
 		struct xe_res_cursor *curs = xe_walk->curs;
+		bool null = xe_walk->pte_flags & XE_PTE_NULL;
 
 		XE_WARN_ON(xe_walk->va_curs_start != addr);
 
-		pte = __gen8_pte_encode(xe_res_dma(curs) + xe_walk->dma_offset,
-					xe_walk->cache, xe_walk->pte_flags,
-					level);
+		if (null) {
+			pte |= XE_PAGE_PRESENT | XE_PAGE_RW;
+
+			if (unlikely(xe_walk->pte_flags & XE_PTE_READ_ONLY))
+				pte &= ~XE_PAGE_RW;
+
+			if (level == 1)
+				pte |= XE_PDE_PS_2M;
+			else if (level == 2)
+				pte |= XE_PDPE_PS_1G;
+
+			pte |= XE_PTE_NULL;
+		} else {
+			pte = __gen8_pte_encode(xe_res_dma(curs) +
+						xe_walk->dma_offset,
+						xe_walk->cache,
+						xe_walk->pte_flags,
+						level);
+		}
 		pte |= xe_walk->default_pte;
 
 		/*
@@ -658,7 +685,8 @@ xe_pt_stage_bind_entry(struct drm_pt *parent, pgoff_t offset,
 		if (unlikely(ret))
 			return ret;
 
-		xe_res_next(curs, next - addr);
+		if (!null)
+			xe_res_next(curs, next - addr);
 		xe_walk->va_curs_start = next;
 		*action = ACTION_CONTINUE;
 
@@ -751,7 +779,8 @@ xe_pt_stage_bind(struct xe_gt *gt, struct xe_vma *vma,
 		.gt = gt,
 		.curs = &curs,
 		.va_curs_start = xe_vma_start(vma),
-		.pte_flags = xe_vma_read_only(vma) ? XE_PTE_READ_ONLY : 0,
+		.pte_flags = xe_vma_read_only(vma) ? XE_PTE_READ_ONLY : 0 |
+			xe_vma_is_null(vma) ? XE_PTE_NULL : 0,
 		.wupd.entries = entries,
 		.needs_64K = (xe_vma_vm(vma)->flags & XE_VM_FLAGS_64K) &&
 			is_vram,
@@ -769,23 +798,28 @@ xe_pt_stage_bind(struct xe_gt *gt, struct xe_vma *vma,
 			gt_to_xe(gt)->mem.vram.io_start;
 		xe_walk.cache = XE_CACHE_WB;
 	} else {
-		if (!xe_vma_is_userptr(vma) && bo->flags & XE_BO_SCANOUT_BIT)
+		if (!xe_vma_has_no_bo(vma) && bo->flags & XE_BO_SCANOUT_BIT)
 			xe_walk.cache = XE_CACHE_WT;
 		else
 			xe_walk.cache = XE_CACHE_WB;
 	}
-	if (!xe_vma_is_userptr(vma) && xe_bo_is_stolen(bo))
+	if (!xe_vma_has_no_bo(vma) && xe_bo_is_stolen(bo))
 		xe_walk.dma_offset = xe_ttm_stolen_gpu_offset(xe_bo_device(bo));
 
 	xe_bo_assert_held(bo);
-	if (xe_vma_is_userptr(vma))
-		xe_res_first_sg(vma->userptr.sg, 0, xe_vma_size(vma), &curs);
-	else if (xe_bo_is_vram(bo) || xe_bo_is_stolen(bo))
-		xe_res_first(bo->ttm.resource, xe_vma_bo_offset(vma),
-			     xe_vma_size(vma), &curs);
-	else
-		xe_res_first_sg(xe_bo_get_sg(bo), xe_vma_bo_offset(vma),
-				xe_vma_size(vma), &curs);
+	if (!xe_vma_is_null(vma)) {
+		if (xe_vma_is_userptr(vma))
+			xe_res_first_sg(vma->userptr.sg, 0, xe_vma_size(vma),
+					&curs);
+		else if (xe_bo_is_vram(bo) || xe_bo_is_stolen(bo))
+			xe_res_first(bo->ttm.resource, xe_vma_bo_offset(vma),
+				     xe_vma_size(vma), &curs);
+		else
+			xe_res_first_sg(xe_bo_get_sg(bo), xe_vma_bo_offset(vma),
+					xe_vma_size(vma), &curs);
+	} else {
+		curs.size = xe_vma_size(vma);
+	}
 
 	ret = drm_pt_walk_range(&pt->drm, pt->level, xe_vma_start(vma),
 				xe_vma_end(vma), &xe_walk.drm);
@@ -979,7 +1013,7 @@ static void xe_pt_commit_locks_assert(struct xe_vma *vma)
 
 	if (xe_vma_is_userptr(vma))
 		lockdep_assert_held_read(&vm->userptr.notifier_lock);
-	else
+	else if (!xe_vma_is_null(vma))
 		dma_resv_assert_held(xe_vma_bo(vma)->ttm.base.resv);
 
 	dma_resv_assert_held(&vm->resv);
@@ -1283,7 +1317,8 @@ __xe_pt_bind_vma(struct xe_gt *gt, struct xe_vma *vma, struct xe_engine *e,
 	struct xe_vm_pgtable_update entries[XE_VM_MAX_LEVEL * 2 + 1];
 	struct xe_pt_migrate_pt_update bind_pt_update = {
 		.base = {
-			.ops = xe_vma_is_userptr(vma) ? &userptr_bind_ops : &bind_ops,
+			.ops = xe_vma_is_userptr(vma) ? &userptr_bind_ops :
+				&bind_ops,
 			.vma = vma,
 		},
 		.bind = true,
@@ -1348,7 +1383,7 @@ __xe_pt_bind_vma(struct xe_gt *gt, struct xe_vma *vma, struct xe_engine *e,
 				   DMA_RESV_USAGE_KERNEL :
 				   DMA_RESV_USAGE_BOOKKEEP);
 
-		if (!xe_vma_is_userptr(vma) && !xe_vma_bo(vma)->vm)
+		if (!xe_vma_has_no_bo(vma) && !xe_vma_bo(vma)->vm)
 			dma_resv_add_fence(xe_vma_bo(vma)->ttm.base.resv, fence,
 					   DMA_RESV_USAGE_BOOKKEEP);
 		xe_pt_commit_bind(vma, entries, num_entries, rebind,
@@ -1667,7 +1702,7 @@ __xe_pt_unbind_vma(struct xe_gt *gt, struct xe_vma *vma, struct xe_engine *e,
 				   DMA_RESV_USAGE_BOOKKEEP);
 
 		/* This fence will be installed by caller when doing eviction */
-		if (!xe_vma_is_userptr(vma) && !xe_vma_bo(vma)->vm)
+		if (!xe_vma_has_no_bo(vma) && !xe_vma_bo(vma)->vm)
 			dma_resv_add_fence(xe_vma_bo(vma)->ttm.base.resv, fence,
 					   DMA_RESV_USAGE_BOOKKEEP);
 		xe_pt_commit_unbind(vma, entries, num_entries,
drivers/gpu/drm/xe/xe_vm.c +61 -31
index f3608865e259..a46f44ab2546 100644
@@ -60,6 +60,7 @@ int xe_vma_userptr_pin_pages(struct xe_vma *vma)
 
 	lockdep_assert_held(&vm->lock);
 	XE_BUG_ON(!xe_vma_is_userptr(vma));
+	XE_BUG_ON(xe_vma_is_null(vma));
 retry:
 	if (vma->gpuva.flags & XE_VMA_DESTROYED)
 		return 0;
@@ -581,7 +582,7 @@ static void preempt_rebind_work_func(struct work_struct *w)
 		goto out_unlock;
 
 	list_for_each_entry(vma, &vm->rebind_list, rebind_link) {
-		if (xe_vma_is_userptr(vma) ||
+		if (xe_vma_has_no_bo(vma) ||
 		    vma->gpuva.flags & XE_VMA_DESTROYED)
 			continue;
 
@@ -813,7 +814,7 @@ static struct xe_vma *xe_vma_create(struct xe_vm *vm,
 				    struct xe_bo *bo,
 				    u64 bo_offset_or_userptr,
 				    u64 start, u64 end,
-				    bool read_only,
+				    bool read_only, bool null,
 				    u64 gt_mask)
 {
 	struct xe_vma *vma;
@@ -843,6 +844,8 @@ static struct xe_vma *xe_vma_create(struct xe_vm *vm,
 	vma->gpuva.va.range = end - start + 1;
 	if (read_only)
 		vma->gpuva.flags |= XE_VMA_READ_ONLY;
+	if (null)
+		vma->gpuva.flags |= XE_VMA_NULL;
 
 	if (gt_mask) {
 		vma->gt_mask = gt_mask;
@@ -862,23 +865,26 @@ static struct xe_vma *xe_vma_create(struct xe_vm *vm,
 		vma->gpuva.gem.obj = &bo->ttm.base;
 		vma->gpuva.gem.offset = bo_offset_or_userptr;
 		drm_gpuva_link(&vma->gpuva);
-	} else /* userptr */ {
-		u64 size = end - start + 1;
-		int err;
-
-		vma->gpuva.gem.offset = bo_offset_or_userptr;
+	} else /* userptr or null */ {
+		if (!null) {
+			u64 size = end - start + 1;
+			int err;
+
+			vma->gpuva.gem.offset = bo_offset_or_userptr;
+			err = mmu_interval_notifier_insert(&vma->userptr.notifier,
+							   current->mm,
+							   xe_vma_userptr(vma),
+							   size,
+							   &vma_userptr_notifier_ops);
+			if (err) {
+				kfree(vma);
+				vma = ERR_PTR(err);
+				return vma;
+			}
 
-		err = mmu_interval_notifier_insert(&vma->userptr.notifier,
-						   current->mm,
-						   xe_vma_userptr(vma), size,
-						   &vma_userptr_notifier_ops);
-		if (err) {
-			kfree(vma);
-			vma = ERR_PTR(err);
-			return vma;
+			vma->userptr.notifier_seq = LONG_MAX;
 		}
 
-		vma->userptr.notifier_seq = LONG_MAX;
 		xe_vm_get(vm);
 	}
 
@@ -916,6 +922,8 @@ static void xe_vma_destroy_late(struct xe_vma *vma)
 		 */
 		mmu_interval_notifier_remove(&vma->userptr.notifier);
 		xe_vm_put(vm);
+	} else if (xe_vma_is_null(vma)) {
+		xe_vm_put(vm);
 	} else {
 		xe_bo_put(xe_vma_bo(vma));
 	}
@@ -954,7 +962,7 @@ static void xe_vma_destroy(struct xe_vma *vma, struct dma_fence *fence)
 		list_del_init(&vma->userptr.invalidate_link);
 		spin_unlock(&vm->userptr.invalidated_lock);
 		list_del(&vma->userptr_link);
-	} else {
+	} else if (!xe_vma_is_null(vma)) {
 		xe_bo_assert_held(xe_vma_bo(vma));
 		drm_gpuva_unlink(&vma->gpuva);
 		if (!xe_vma_bo(vma)->vm)
@@ -1305,7 +1313,7 @@ void xe_vm_close_and_put(struct xe_vm *vm)
 	drm_gpuva_iter_for_each(gpuva, it) {
 		vma = gpuva_to_vma(gpuva);
 
-		if (xe_vma_is_userptr(vma)) {
+		if (xe_vma_has_no_bo(vma)) {
 			down_read(&vm->userptr.notifier_lock);
 			vma->gpuva.flags |= XE_VMA_DESTROYED;
 			up_read(&vm->userptr.notifier_lock);
@@ -1315,7 +1323,7 @@ void xe_vm_close_and_put(struct xe_vm *vm)
 		drm_gpuva_iter_remove(&it);
 
 		/* easy case, remove from VMA? */
-		if (xe_vma_is_userptr(vma) || xe_vma_bo(vma)->vm) {
+		if (xe_vma_has_no_bo(vma) || xe_vma_bo(vma)->vm) {
 			xe_vma_destroy(vma, NULL);
 			continue;
 		}
@@ -1964,7 +1972,7 @@ static int xe_vm_prefetch(struct xe_vm *vm, struct xe_vma *vma,
 
 	XE_BUG_ON(region > ARRAY_SIZE(region_to_mem_type));
 
-	if (!xe_vma_is_userptr(vma)) {
+	if (!xe_vma_has_no_bo(vma)) {
 		err = xe_bo_migrate(xe_vma_bo(vma), region_to_mem_type[region]);
 		if (err)
 			return err;
@@ -2170,6 +2178,7 @@ vm_bind_ioctl_ops_create(struct xe_vm *vm, struct xe_bo *bo,
 				operation & XE_VM_BIND_FLAG_IMMEDIATE;
 			op->map.read_only =
 				operation & XE_VM_BIND_FLAG_READONLY;
+			op->map.null = operation & XE_VM_BIND_FLAG_NULL;
 		}
 		break;
 	case XE_VM_BIND_OP_UNMAP:
@@ -2226,7 +2235,7 @@ vm_bind_ioctl_ops_create(struct xe_vm *vm, struct xe_bo *bo,
 }
 
 static struct xe_vma *new_vma(struct xe_vm *vm, struct drm_gpuva_op_map *op,
-			      u64 gt_mask, bool read_only)
+			      u64 gt_mask, bool read_only, bool null)
 {
 	struct xe_bo *bo = op->gem.obj ? gem_to_xe_bo(op->gem.obj) : NULL;
 	struct xe_vma *vma;
@@ -2242,7 +2251,7 @@ static struct xe_vma *new_vma(struct xe_vm *vm, struct drm_gpuva_op_map *op,
 	}
 	vma = xe_vma_create(vm, bo, op->gem.offset,
 			    op->va.addr, op->va.addr +
-			    op->va.range - 1, read_only,
+			    op->va.range - 1, read_only, null,
 			    gt_mask);
 	if (bo)
 		xe_bo_unlock(bo, &ww);
@@ -2254,7 +2263,7 @@ static struct xe_vma *new_vma(struct xe_vm *vm, struct drm_gpuva_op_map *op,
 			xe_vma_destroy(vma, NULL);
 			return ERR_PTR(err);
 		}
-	} else if(!bo->vm) {
+	} else if(!xe_vma_has_no_bo(vma) && !bo->vm) {
 		vm_insert_extobj(vm, vma);
 		err = add_preempt_fences(vm, bo);
 		if (err) {
@@ -2332,7 +2341,8 @@ static int vm_bind_ioctl_ops_parse(struct xe_vm *vm, struct xe_engine *e,
 				struct xe_vma *vma;
 
 				vma = new_vma(vm, &op->base.map,
-					      op->gt_mask, op->map.read_only);
+					      op->gt_mask, op->map.read_only,
+					      op->map.null );
 				if (IS_ERR(vma)) {
 					err = PTR_ERR(vma);
 					goto free_fence;
@@ -2347,9 +2357,13 @@ static int vm_bind_ioctl_ops_parse(struct xe_vm *vm, struct xe_engine *e,
 					bool read_only =
 						op->base.remap.unmap->va->flags &
 						XE_VMA_READ_ONLY;
+					bool null =
+						op->base.remap.unmap->va->flags &
+						XE_VMA_NULL;
 
 					vma = new_vma(vm, op->base.remap.prev,
-						      op->gt_mask, read_only);
+						      op->gt_mask, read_only,
+						      null);
 					if (IS_ERR(vma)) {
 						err = PTR_ERR(vma);
 						goto free_fence;
@@ -2364,8 +2378,13 @@ static int vm_bind_ioctl_ops_parse(struct xe_vm *vm, struct xe_engine *e,
 						op->base.remap.unmap->va->flags &
 						XE_VMA_READ_ONLY;
 
+					bool null =
+						op->base.remap.unmap->va->flags &
+						XE_VMA_NULL;
+
 					vma = new_vma(vm, op->base.remap.next,
-						      op->gt_mask, read_only);
+						      op->gt_mask, read_only,
+						      null);
 					if (IS_ERR(vma)) {
 						err = PTR_ERR(vma);
 						goto free_fence;
@@ -2853,11 +2872,12 @@ static void vm_bind_ioctl_ops_unwind(struct xe_vm *vm,
 #ifdef TEST_VM_ASYNC_OPS_ERROR
 #define SUPPORTED_FLAGS	\
 	(FORCE_ASYNC_OP_ERROR | XE_VM_BIND_FLAG_ASYNC | \
-	 XE_VM_BIND_FLAG_READONLY | XE_VM_BIND_FLAG_IMMEDIATE | 0xffff)
+	 XE_VM_BIND_FLAG_READONLY | XE_VM_BIND_FLAG_IMMEDIATE | \
+	 XE_VM_BIND_FLAG_NULL | 0xffff)
 #else
 #define SUPPORTED_FLAGS	\
 	(XE_VM_BIND_FLAG_ASYNC | XE_VM_BIND_FLAG_READONLY | \
-	 XE_VM_BIND_FLAG_IMMEDIATE | 0xffff)
+	 XE_VM_BIND_FLAG_IMMEDIATE | XE_VM_BIND_FLAG_NULL | 0xffff)
 #endif
 #define XE_64K_PAGE_MASK 0xffffull
 
@@ -2903,6 +2923,7 @@ static int vm_bind_ioctl_check_args(struct xe_device *xe,
 		u32 obj = (*bind_ops)[i].obj;
 		u64 obj_offset = (*bind_ops)[i].obj_offset;
 		u32 region = (*bind_ops)[i].region;
+		bool null = op &  XE_VM_BIND_FLAG_NULL;
 
 		if (i == 0) {
 			*async = !!(op & XE_VM_BIND_FLAG_ASYNC);
@@ -2929,8 +2950,12 @@ static int vm_bind_ioctl_check_args(struct xe_device *xe,
 		if (XE_IOCTL_ERR(xe, VM_BIND_OP(op) >
 				 XE_VM_BIND_OP_PREFETCH) ||
 		    XE_IOCTL_ERR(xe, op & ~SUPPORTED_FLAGS) ||
+		    XE_IOCTL_ERR(xe, obj && null) ||
+		    XE_IOCTL_ERR(xe, obj_offset && null) ||
+		    XE_IOCTL_ERR(xe, VM_BIND_OP(op) != XE_VM_BIND_OP_MAP &&
+				 null) ||
 		    XE_IOCTL_ERR(xe, !obj &&
-				 VM_BIND_OP(op) == XE_VM_BIND_OP_MAP) ||
+				 VM_BIND_OP(op) == XE_VM_BIND_OP_MAP && !null) ||
 		    XE_IOCTL_ERR(xe, !obj &&
 				 VM_BIND_OP(op) == XE_VM_BIND_OP_UNMAP_ALL) ||
 		    XE_IOCTL_ERR(xe, addr &&
@@ -3254,6 +3279,7 @@ int xe_vm_invalidate_vma(struct xe_vma *vma)
 	int ret;
 
 	XE_BUG_ON(!xe_vm_in_fault_mode(xe_vma_vm(vma)));
+	XE_BUG_ON(xe_vma_is_null(vma));
 	trace_xe_vma_usm_invalidate(vma);
 
 	/* Check that we don't race with page-table updates */
@@ -3313,8 +3339,11 @@ int xe_analyze_vm(struct drm_printer *p, struct xe_vm *vm, int gt_id)
 	drm_gpuva_iter_for_each(gpuva, it) {
 		struct xe_vma* vma = gpuva_to_vma(gpuva);
 		bool is_userptr = xe_vma_is_userptr(vma);
+		bool null = xe_vma_is_null(vma);
 
-		if (is_userptr) {
+		if (null) {
+			addr = 0;
+		} else if (is_userptr) {
 			struct xe_res_cursor cur;
 
 			xe_res_first_sg(vma->userptr.sg, 0, XE_PAGE_SIZE, &cur);
@@ -3324,7 +3353,8 @@ int xe_analyze_vm(struct drm_printer *p, struct xe_vm *vm, int gt_id)
 		}
 		drm_printf(p, " [%016llx-%016llx] S:0x%016llx A:%016llx %s\n",
 			   xe_vma_start(vma), xe_vma_end(vma), xe_vma_size(vma),
-			   addr, is_userptr ? "USR" : is_vram ? "VRAM" : "SYS");
+			   addr, null ? "NULL" :
+			   is_userptr ? "USR" : is_vram ? "VRAM" : "SYS");
 	}
 	up_read(&vm->lock);
 
drivers/gpu/drm/xe/xe_vm.h +10 -0
index 21b1054949c4..96e2c6b07bf8 100644
@@ -175,7 +175,17 @@ static inline void xe_vm_reactivate_rebind(struct xe_vm *vm)
 	}
 }
 
+static inline bool xe_vma_is_null(struct xe_vma *vma)
+{
+	return vma->gpuva.flags & XE_VMA_NULL;
+}
+
 static inline bool xe_vma_is_userptr(struct xe_vma *vma)
+{
+	return !xe_vma_bo(vma) && !xe_vma_is_null(vma);
+}
+
+static inline bool xe_vma_has_no_bo(struct xe_vma *vma)
 {
 	return !xe_vma_bo(vma);
 }
drivers/gpu/drm/xe/xe_vm_madvise.c +1 -1
index 02d27a354b36..03508645fa08 100644
@@ -227,7 +227,7 @@ get_vmas(struct xe_vm *vm, int *num_vmas, u64 addr, u64 range)
 	drm_gpuva_iter_for_each_range(gpuva, it, addr + range) {
 		struct xe_vma *vma = gpuva_to_vma(gpuva);
 
-		if (xe_vma_is_userptr(vma))
+		if (xe_vma_has_no_bo(vma))
 			continue;
 
 		if (*num_vmas == max_vmas) {
drivers/gpu/drm/xe/xe_vm_types.h +3 -0
index 243dc91a61b0..b61007b70502 100644
@@ -29,6 +29,7 @@ struct xe_vm;
 #define XE_VMA_ATOMIC_PTE_BIT	(DRM_GPUVA_USERBITS << 2)
 #define XE_VMA_FIRST_REBIND	(DRM_GPUVA_USERBITS << 3)
 #define XE_VMA_LAST_REBIND	(DRM_GPUVA_USERBITS << 4)
+#define XE_VMA_NULL		(DRM_GPUVA_USERBITS << 5)
 
 struct xe_vma {
 	/** @gpuva: Base GPUVA object */
@@ -315,6 +316,8 @@ struct xe_vma_op_map {
 	bool immediate;
 	/** @read_only: Read only */
 	bool read_only;
+	/** @null: NULL (writes dropped, read zero) */
+	bool null;
 };
 
 /** struct xe_vma_op_unmap - VMA unmap operation */
include/uapi/drm/xe_drm.h +8 -0
index b0b80aae3ee8..27c51946fadd 100644
@@ -447,6 +447,14 @@ struct drm_xe_vm_bind_op {
 	 * than differing the MAP to the page fault handler.
 	 */
 #define XE_VM_BIND_FLAG_IMMEDIATE	(0x1 << 18)
+	/*
+	 * When the NULL flag is set, the page tables are setup with a special
+	 * bit which indicates writes are dropped and all reads return zero. The
+	 * NULL flags is only valid for XE_VM_BIND_OP_MAP operations, the BO
+	 * handle MBZ, and the BO offset MBZ. This flag is intended to implement
+	 * VK sparse bindings.
+	 */
+#define XE_VM_BIND_FLAG_NULL		(0x1 << 19)
 
 	/** @reserved: Reserved */
 	__u64 reserved[2];
Signature · 1 line
2.34.1
#80 lore raw

Re: [Intel-xe] [PATCH v2 17/31] drm/xe: NULL binding implementation

In reply to Matthew Brost
Quoted 29 lines · Matthew Brost

Add uAPI and implementation for NULL bindings. A NULL binding is defined
as writes dropped and read zero. A single bit in the uAPI has been added
which results in a single bit in the PTEs being set.

NULL bindings are indended to be used to implement VK sparse bindings.

---
 drivers/gpu/drm/xe/xe_bo.h           |  1 + drivers/gpu/drm/xe/xe_exec.c         |  2 + drivers/gpu/drm/xe/xe_gt_pagefault.c |  4 +- drivers/gpu/drm/xe/xe_pt.c           | 77 ++++++++++++++++------- drivers/gpu/drm/xe/xe_vm.c           | 92 ++++++++++++++++++-------- --
 drivers/gpu/drm/xe/xe_vm.h           | 10 +++ drivers/gpu/drm/xe/xe_vm_madvise.c   |  2 +- drivers/gpu/drm/xe/xe_vm_types.h     |  3 + include/uapi/drm/xe_drm.h            |  8 +++

 9 files changed, 144 insertions(+), 55 deletions(-)
drivers/gpu/drm/xe/xe_bo.h +0 -0
index 25457b3c757b..81051f456874 100644
@@ -56,6 +56,7 @@
  #define XE_PDE_IPS_64K                 BIT_ULL(11)
Quoted 3 lines


 #define XE_GGTT_PTE_LM                 BIT_ULL(1) +#define XE_PTE_NULL                    BIT_ULL(9)

This looks like something we want to encode in the PPGTT PTE, (We should really move those out to another header),rather than a flag we want to pass around in the vm code. So perhaps XE_PPGTT_PTE_NULL do follow the naming convention.

Quoted 55 lines

 #define XE_USM_PPGTT_PTE_AE            BIT_ULL(10) #define XE_PPGTT_PTE_LM                        BIT_ULL(11) #define XE_PDE_64K                     BIT_ULL(6)

drivers/gpu/drm/xe/xe_exec.c +2 -0
index 90c46d092737..68f876afd13c 100644
@@ -116,6 +116,8 @@ static int xe_exec_begin(struct xe_engine *e,
 struct ww_acquire_ctx *ww,
          * to a location where the GPU can access it).
          */
         list_for_each_entry(vma, &vm->rebind_list, rebind_link) {
+               XE_BUG_ON(xe_vma_is_null(vma));
+
                 if (xe_vma_is_userptr(vma))
                         continue;

drivers/gpu/drm/xe/xe_gt_pagefault.c +0 -0
index f7a066090a13..cfffe3398fe4 100644
@@ -526,8 +526,8 @@ static int handle_acc(struct xe_gt *gt, struct
 acc *acc)


        trace_xe_vma_acc(vma);

-       /* Userptr can't be migrated, nothing to do */ -       if (xe_vma_is_userptr(vma))
+       /* Userptr or null can't be migrated, nothing to do */ +       if (xe_vma_has_no_bo(vma))
                goto unlock_vm;

        /* Lock VM and BOs dma-resv */

drivers/gpu/drm/xe/xe_pt.c +3 -1
index 2b5b05a8a084..b4edb751bfbb 100644
@@ -82,7 +82,9 @@ u64 gen8_pde_encode(struct xe_bo *bo, u64
 bo_offset,
  static dma_addr_t vma_addr(struct xe_vma *vma, u64 offset,
                            size_t page_size, bool *is_vram)
  {
-       if (xe_vma_is_userptr(vma)) {
+       if (xe_vma_is_null(vma)) {
+               return 0;
+       } else if (xe_vma_is_userptr(vma)) {
                 struct xe_res_cursor cur;
                 u64 page;

drivers/gpu/drm/xe/xe_pt.c +0 -0
@@ -563,6 +565,10 @@ static bool xe_pt_hugepte_possible(u64 addr, u64
 next, unsigned int level,
         if (next - xe_walk->va_curs_start > xe_walk->curs->size)
                 return false;
Quoted 3 lines


+       /* null VMA's do not have dma adresses */
+       if (xe_walk->pte_flags & XE_PTE_NULL)

But here it is used as a flag determining PTE setup. These are different, see the documentation on pte_flags. Look for XE_PAGE_RW and XE_PTE_READ_ONLY for a similar difference. One is a bit in the PTE which may vary across hardware, the other one is a flag handed to the page-table walker indicating a NULL binding.

Quoted 26 lines

+               return true;
+
        /* Is the DMA address huge PTE size aligned? */ size = next - addr;
        dma = addr - xe_walk->va_curs_start + xe_res_dma(xe_walk-

Quoted 1 line

curs);

drivers/gpu/drm/xe/xe_pt.c +0 -0
@@ -585,6 +591,10 @@ xe_pt_scan_64K(u64 addr, u64 next, struct
 xe_pt_stage_bind_walk *xe_walk)
         if (next > xe_walk->l0_end_addr)
                 return false;


+       /* null VMA's do not have dma adresses */
+       if (xe_walk->pte_flags & XE_PTE_NULL)
+               return true;
+
        xe_res_next(&curs, addr - xe_walk->va_curs_start); for (; addr < next; addr += SZ_64K) {
                if (!IS_ALIGNED(xe_res_dma(&curs), SZ_64K) || curs.size < SZ_64K)

drivers/gpu/drm/xe/xe_pt.c +1 -1
@@ -630,17 +640,34 @@ xe_pt_stage_bind_entry(struct drm_pt *parent,
 pgoff_t offset,
         struct xe_pt *xe_child;
         bool covers;
         int ret = 0;
-       u64 pte;
+       u64 pte = 0;
Quoted 6 lines


        /* Is this a leaf entry ?*/
        if (level == 0 || xe_pt_hugepte_possible(addr, next, level, xe_walk)) {
                struct xe_res_cursor *curs = xe_walk->curs; +               bool null = xe_walk->pte_flags & XE_PTE_NULL;

Although lower-case, this might confuse code readers having had too little coffee. Could we use another name instead of null? null_vma?

Quoted 18 lines


                XE_WARN_ON(xe_walk->va_curs_start != addr);
-               pte = __gen8_pte_encode(xe_res_dma(curs) + xe_walk-

Quoted 1 line

dma_offset,

-                                       xe_walk->cache, xe_walk-

Quoted 1 line

pte_flags,

-                                       level);
+               if (null) {
+                       pte |= XE_PAGE_PRESENT | XE_PAGE_RW; +
+                       if (unlikely(xe_walk->pte_flags & XE_PTE_READ_ONLY))
+                               pte &= ~XE_PAGE_RW;

drivers/gpu/drm/xe/xe_pt.c +4 -0
+
+                       if (level == 1)
+                               pte |= XE_PDE_PS_2M;
+                       else if (level == 2)

drivers/gpu/drm/xe/xe_pt.c xe_pt_stage_bind_entry(struct drm_pt *parent, pgoff_t offset, · line 670

Quoted 10 lines
drivers/gpu/drm/xe/xe_pt.c +10 -0
+                               pte |= XE_PDPE_PS_1G;
+
+                       pte |= XE_PTE_NULL;
+               } else {
+                       pte = __gen8_pte_encode(xe_res_dma(curs) +
+                                               xe_walk->dma_offset,
+                                               xe_walk->cache,
+                                               xe_walk->pte_flags,
+                                               level);
+               }

Again, it looks like XE_PPGTT_PTE_NULL should just be or'ed to @default_pte at the walk start, skipping this conditional?

Quoted 81 lines

                pte |= xe_walk->default_pte;

                /*

drivers/gpu/drm/xe/xe_pt.c +0 -0
@@ -658,7 +685,8 @@ xe_pt_stage_bind_entry(struct drm_pt *parent,
 pgoff_t offset,
                 if (unlikely(ret))
                         return ret;


-               xe_res_next(curs, next - addr); +               if (!null)
+                       xe_res_next(curs, next - addr);

                xe_walk->va_curs_start = next;
                *action = ACTION_CONTINUE;

drivers/gpu/drm/xe/xe_pt.c +1 -1
@@ -751,7 +779,8 @@ xe_pt_stage_bind(struct xe_gt *gt, struct xe_vma
 *vma,
                 .gt = gt,
                 .curs = &curs,
                 .va_curs_start = xe_vma_start(vma),
-               .pte_flags = xe_vma_read_only(vma) ? XE_PTE_READ_ONLY
 : 0,
+               .pte_flags = xe_vma_read_only(vma) ? XE_PTE_READ_ONLY

: 0 |
+                       xe_vma_is_null(vma) ? XE_PTE_NULL : 0, .wupd.entries = entries,
                .needs_64K = (xe_vma_vm(vma)->flags & XE_VM_FLAGS_64K) &&
                        is_vram,

drivers/gpu/drm/xe/xe_pt.c +1 -1
@@ -769,23 +798,28 @@ xe_pt_stage_bind(struct xe_gt *gt, struct
 xe_vma *vma,
                         gt_to_xe(gt)->mem.vram.io_start;
                 xe_walk.cache = XE_CACHE_WB;
         } else {
-               if (!xe_vma_is_userptr(vma) && bo->flags &
 XE_BO_SCANOUT_BIT)
+               if (!xe_vma_has_no_bo(vma) && bo->flags &
 XE_BO_SCANOUT_BIT)
                         xe_walk.cache = XE_CACHE_WT;

                else
                        xe_walk.cache = XE_CACHE_WB;
        }
-       if (!xe_vma_is_userptr(vma) && xe_bo_is_stolen(bo)) +       if (!xe_vma_has_no_bo(vma) && xe_bo_is_stolen(bo)) xe_walk.dma_offset = xe_ttm_stolen_gpu_offset(xe_bo_device(bo));

        xe_bo_assert_held(bo);
-       if (xe_vma_is_userptr(vma))
-               xe_res_first_sg(vma->userptr.sg, 0, xe_vma_size(vma), &curs);
-       else if (xe_bo_is_vram(bo) || xe_bo_is_stolen(bo)) -               xe_res_first(bo->ttm.resource, xe_vma_bo_offset(vma), -                            xe_vma_size(vma), &curs);
-       else
-               xe_res_first_sg(xe_bo_get_sg(bo), xe_vma_bo_offset(vma),
-                               xe_vma_size(vma), &curs); +       if (!xe_vma_is_null(vma)) {
+               if (xe_vma_is_userptr(vma))
+                       xe_res_first_sg(vma->userptr.sg, 0, xe_vma_size(vma),
+                                       &curs);
+               else if (xe_bo_is_vram(bo) || xe_bo_is_stolen(bo)) +                       xe_res_first(bo->ttm.resource, xe_vma_bo_offset(vma),
+                                    xe_vma_size(vma), &curs); +               else
+                       xe_res_first_sg(xe_bo_get_sg(bo), xe_vma_bo_offset(vma),
+                                       xe_vma_size(vma), &curs); +       } else {
+               curs.size = xe_vma_size(vma);
+       }

        ret = drm_pt_walk_range(&pt->drm, pt->level, xe_vma_start(vma),
                                xe_vma_end(vma), &xe_walk.drm);

drivers/gpu/drm/xe/xe_pt.c +0 -0
@@ -979,7 +1013,7 @@ static void xe_pt_commit_locks_assert(struct
 xe_vma *vma)
Quoted 6 lines


        if (xe_vma_is_userptr(vma)) lockdep_assert_held_read(&vm->userptr.notifier_lock); -       else
+       else if (!xe_vma_is_null(vma)) dma_resv_assert_held(xe_vma_bo(vma)->ttm.base.resv);

Without looking at the code, IIRC there is a vma-range-specific resv needed to be held here. Could we assert the vm resv is held for NULL vmas similar to userptrs?

Quoted 10 lines


        dma_resv_assert_held(&vm->resv);

drivers/gpu/drm/xe/xe_pt.c +1 -1
@@ -1283,7 +1317,8 @@ __xe_pt_bind_vma(struct xe_gt *gt, struct
 xe_vma *vma, struct xe_engine *e,
         struct xe_vm_pgtable_update entries[XE_VM_MAX_LEVEL * 2 + 1];
         struct xe_pt_migrate_pt_update bind_pt_update = {
                 .base = {
-                       .ops = xe_vma_is_userptr(vma) ?
 &userptr_bind_ops : &bind_ops,
+                       .ops = xe_vma_is_userptr(vma) ?
Quoted 2 lines

&userptr_bind_ops :
+                               &bind_ops,

Unrelated change.

Quoted 31 lines

                        .vma = vma,
                },
                .bind = true,

drivers/gpu/drm/xe/xe_pt.c +0 -0
@@ -1348,7 +1383,7 @@ __xe_pt_bind_vma(struct xe_gt *gt, struct
 xe_vma *vma, struct xe_engine *e,

                                   DMA_RESV_USAGE_KERNEL :
                                   DMA_RESV_USAGE_BOOKKEEP);
-               if (!xe_vma_is_userptr(vma) && !xe_vma_bo(vma)->vm) +               if (!xe_vma_has_no_bo(vma) && !xe_vma_bo(vma)->vm) dma_resv_add_fence(xe_vma_bo(vma)-

Quoted 1 line

ttm.base.resv, fence,

                                           DMA_RESV_USAGE_BOOKKEEP); xe_pt_commit_bind(vma, entries, num_entries, rebind,

drivers/gpu/drm/xe/xe_pt.c +0 -0
@@ -1667,7 +1702,7 @@ __xe_pt_unbind_vma(struct xe_gt *gt, struct
 xe_vma *vma, struct xe_engine *e,
                                    DMA_RESV_USAGE_BOOKKEEP);


                /* This fence will be installed by caller when doing eviction */
-               if (!xe_vma_is_userptr(vma) && !xe_vma_bo(vma)->vm) +               if (!xe_vma_has_no_bo(vma) && !xe_vma_bo(vma)->vm) dma_resv_add_fence(xe_vma_bo(vma)-

Quoted 1 line

ttm.base.resv, fence,

                                           DMA_RESV_USAGE_BOOKKEEP); xe_pt_commit_unbind(vma, entries, num_entries,

drivers/gpu/drm/xe/xe_vm.c +0 -0
index f3608865e259..a46f44ab2546 100644
@@ -60,6 +60,7 @@ int xe_vma_userptr_pin_pages(struct xe_vma *vma)
Quoted 4 lines


        lockdep_assert_held(&vm->lock);
        XE_BUG_ON(!xe_vma_is_userptr(vma));
+       XE_BUG_ON(xe_vma_is_null(vma));

Isn't this caught by the BUG_ON just above?

Quoted 14 lines

 retry:
        if (vma->gpuva.flags & XE_VMA_DESTROYED)
                return 0;

drivers/gpu/drm/xe/xe_vm.c +0 -0
@@ -581,7 +582,7 @@ static void preempt_rebind_work_func(struct
 work_struct *w)
                 goto out_unlock;


        list_for_each_entry(vma, &vm->rebind_list, rebind_link) { -               if (xe_vma_is_userptr(vma) ||
+               if (xe_vma_has_no_bo(vma) || vma->gpuva.flags & XE_VMA_DESTROYED) continue;

drivers/gpu/drm/xe/xe_vm.c static struct xe_vma *xe_vma_create(struct xe_vm · line 818

Quoted 6 lines
drivers/gpu/drm/xe/xe_vm.c +1 -1
@@ -813,7 +814,7 @@ static struct xe_vma *xe_vma_create(struct xe_vm
 *vm,
                                     struct xe_bo *bo,
                                     u64 bo_offset_or_userptr,
                                     u64 start, u64 end,
-                                   bool read_only,
+                                   bool read_only, bool null,

Again, variable name.

Quoted 227 lines
drivers/gpu/drm/xe/xe_vm.c +0 -0
                                     u64 gt_mask)
  {

        struct xe_vma *vma;

drivers/gpu/drm/xe/xe_vm.c +2 -0
@@ -843,6 +844,8 @@ static struct xe_vma *xe_vma_create(struct xe_vm
 *vm,
         vma->gpuva.va.range = end - start + 1;
         if (read_only)
                 vma->gpuva.flags |= XE_VMA_READ_ONLY;
+       if (null)
+               vma->gpuva.flags |= XE_VMA_NULL;


        if (gt_mask) {
                vma->gt_mask = gt_mask;

drivers/gpu/drm/xe/xe_vm.c +16 -5
@@ -862,23 +865,26 @@ static struct xe_vma *xe_vma_create(struct
 xe_vm *vm,
                 vma->gpuva.gem.obj = &bo->ttm.base;
                 vma->gpuva.gem.offset = bo_offset_or_userptr;
                 drm_gpuva_link(&vma->gpuva);
-       } else /* userptr */ {
-               u64 size = end - start + 1;
-               int err;
-
-               vma->gpuva.gem.offset = bo_offset_or_userptr;
+       } else /* userptr or null */ {
+               if (!null) {
+                       u64 size = end - start + 1;
+                       int err;
+
+                       vma->gpuva.gem.offset = bo_offset_or_userptr;
+                       err = mmu_interval_notifier_insert(&vma-
 >userptr.notifier,
+                                                          current-
 >mm,
+                                                         
 xe_vma_userptr(vma),
+                                                          size,
+                                                         
 &vma_userptr_notifier_ops);
+                       if (err) {
+                               kfree(vma);
+                               vma = ERR_PTR(err);
+                               return vma;
+                       }


-               err = mmu_interval_notifier_insert(&vma-

Quoted 1 line

userptr.notifier,

-                                                  current->mm, -
xe_vma_userptr(vma), size,
-
&vma_userptr_notifier_ops);
-               if (err) {
-                       kfree(vma);
-                       vma = ERR_PTR(err);
-                       return vma;
+                       vma->userptr.notifier_seq = LONG_MAX; }

-               vma->userptr.notifier_seq = LONG_MAX; xe_vm_get(vm);
        }

drivers/gpu/drm/xe/xe_vm.c +2 -0
@@ -916,6 +922,8 @@ static void xe_vma_destroy_late(struct xe_vma
 *vma)
                  */
                 mmu_interval_notifier_remove(&vma->userptr.notifier);
                 xe_vm_put(vm);
+       } else if (xe_vma_is_null(vma)) {
+               xe_vm_put(vm);
         } else {
                 xe_bo_put(xe_vma_bo(vma));

        }

drivers/gpu/drm/xe/xe_vm.c +1 -1
@@ -954,7 +962,7 @@ static void xe_vma_destroy(struct xe_vma *vma,
 struct dma_fence *fence)
                 list_del_init(&vma->userptr.invalidate_link);
                 spin_unlock(&vm->userptr.invalidated_lock);
                 list_del(&vma->userptr_link);
-       } else {
+       } else if (!xe_vma_is_null(vma)) {
                 xe_bo_assert_held(xe_vma_bo(vma));
                 drm_gpuva_unlink(&vma->gpuva);

                if (!xe_vma_bo(vma)->vm)

drivers/gpu/drm/xe/xe_vm.c +0 -0
@@ -1305,7 +1313,7 @@ void xe_vm_close_and_put(struct xe_vm *vm)
         drm_gpuva_iter_for_each(gpuva, it) {
                 vma = gpuva_to_vma(gpuva);


-               if (xe_vma_is_userptr(vma)) {
+               if (xe_vma_has_no_bo(vma)) { down_read(&vm->userptr.notifier_lock); vma->gpuva.flags |= XE_VMA_DESTROYED; up_read(&vm->userptr.notifier_lock);

drivers/gpu/drm/xe/xe_vm.c +0 -0
@@ -1315,7 +1323,7 @@ void xe_vm_close_and_put(struct xe_vm *vm)
                 drm_gpuva_iter_remove(&it);


                /* easy case, remove from VMA? */
-               if (xe_vma_is_userptr(vma) || xe_vma_bo(vma)->vm) { +               if (xe_vma_has_no_bo(vma) || xe_vma_bo(vma)->vm) { xe_vma_destroy(vma, NULL); continue;
                }

drivers/gpu/drm/xe/xe_vm.c +0 -0
@@ -1964,7 +1972,7 @@ static int xe_vm_prefetch(struct xe_vm *vm,
 struct xe_vma *vma,


        XE_BUG_ON(region > ARRAY_SIZE(region_to_mem_type));
-       if (!xe_vma_is_userptr(vma)) {
+       if (!xe_vma_has_no_bo(vma)) {
                err = xe_bo_migrate(xe_vma_bo(vma), region_to_mem_type[region]);
                if (err)
                        return err;

drivers/gpu/drm/xe/xe_vm.c +0 -0
@@ -2170,6 +2178,7 @@ vm_bind_ioctl_ops_create(struct xe_vm *vm,
 struct xe_bo *bo,

                                operation & XE_VM_BIND_FLAG_IMMEDIATE;
                        op->map.read_only =
                                operation & XE_VM_BIND_FLAG_READONLY; +                       op->map.null = operation & XE_VM_BIND_FLAG_NULL;
                }
                break;
        case XE_VM_BIND_OP_UNMAP:

drivers/gpu/drm/xe/xe_vm.c +0 -0
@@ -2226,7 +2235,7 @@ vm_bind_ioctl_ops_create(struct xe_vm *vm,
 struct xe_bo *bo,
  }


 static struct xe_vma *new_vma(struct xe_vm *vm, struct drm_gpuva_op_map *op,
-                             u64 gt_mask, bool read_only) +                             u64 gt_mask, bool read_only, bool null) {
        struct xe_bo *bo = op->gem.obj ? gem_to_xe_bo(op->gem.obj) :
NULL;
        struct xe_vma *vma;

drivers/gpu/drm/xe/xe_vm.c +0 -0
@@ -2242,7 +2251,7 @@ static struct xe_vma *new_vma(struct xe_vm *vm,
 struct drm_gpuva_op_map *op,
         }
         vma = xe_vma_create(vm, bo, op->gem.offset,

                            op->va.addr, op->va.addr + -                           op->va.range - 1, read_only, +                           op->va.range - 1, read_only, null, gt_mask);
        if (bo)
                xe_bo_unlock(bo, &ww);

drivers/gpu/drm/xe/xe_vm.c +1 -1
@@ -2254,7 +2263,7 @@ static struct xe_vma *new_vma(struct xe_vm *vm,
 struct drm_gpuva_op_map *op,
                         xe_vma_destroy(vma, NULL);
                         return ERR_PTR(err);
                 }
-       } else if(!bo->vm) {
+       } else if(!xe_vma_has_no_bo(vma) && !bo->vm) {
                 vm_insert_extobj(vm, vma);
                 err = add_preempt_fences(vm, bo);

                if (err) {

drivers/gpu/drm/xe/xe_vm.c +0 -0
@@ -2332,7 +2341,8 @@ static int vm_bind_ioctl_ops_parse(struct xe_vm
 *vm, struct xe_engine *e,
                                 struct xe_vma *vma;


                                vma = new_vma(vm, &op->base.map, -                                             op->gt_mask, op-

Quoted 1 line

map.read_only);

+                                             op->gt_mask, op-

Quoted 1 line

map.read_only,

+                                             op->map.null ); if (IS_ERR(vma)) { err = PTR_ERR(vma); goto free_fence;

drivers/gpu/drm/xe/xe_vm.c +0 -0
@@ -2347,9 +2357,13 @@ static int vm_bind_ioctl_ops_parse(struct
 xe_vm *vm, struct xe_engine *e,

                                        bool read_only = op->base.remap.unmap-

Quoted 1 line

va->flags &

                                                XE_VMA_READ_ONLY; +                                       bool null =
+                                               op->base.remap.unmap-

Quoted 1 line

va->flags &

+                                               XE_VMA_NULL;
                                        vma = new_vma(vm, op-

Quoted 1 line

base.remap.prev,

-                                                     op->gt_mask, read_only);
+                                                     op->gt_mask, read_only,
+                                                     null); if (IS_ERR(vma)) { err = PTR_ERR(vma); goto free_fence;

drivers/gpu/drm/xe/xe_vm.c +0 -0
@@ -2364,8 +2378,13 @@ static int vm_bind_ioctl_ops_parse(struct
 xe_vm *vm, struct xe_engine *e,

                                                op->base.remap.unmap-

Quoted 1 line

va->flags &

                                                XE_VMA_READ_ONLY;
+                                       bool null =
+                                               op->base.remap.unmap-

Quoted 1 line

va->flags &

+                                               XE_VMA_NULL; +
                                        vma = new_vma(vm, op-

Quoted 1 line

base.remap.next,

-                                                     op->gt_mask, read_only);
+                                                     op->gt_mask, read_only,
+                                                     null); if (IS_ERR(vma)) { err = PTR_ERR(vma); goto free_fence;

drivers/gpu/drm/xe/xe_vm.c +3 -2
@@ -2853,11 +2872,12 @@ static void vm_bind_ioctl_ops_unwind(struct
 xe_vm *vm,
  #ifdef TEST_VM_ASYNC_OPS_ERROR
  #define SUPPORTED_FLAGS        \
         (FORCE_ASYNC_OP_ERROR | XE_VM_BIND_FLAG_ASYNC | \
-        XE_VM_BIND_FLAG_READONLY | XE_VM_BIND_FLAG_IMMEDIATE |
 0xffff)
+        XE_VM_BIND_FLAG_READONLY | XE_VM_BIND_FLAG_IMMEDIATE | \
+        XE_VM_BIND_FLAG_NULL | 0xffff)
  #else
  #define SUPPORTED_FLAGS        \
         (XE_VM_BIND_FLAG_ASYNC | XE_VM_BIND_FLAG_READONLY | \
-        XE_VM_BIND_FLAG_IMMEDIATE | 0xffff)
+        XE_VM_BIND_FLAG_IMMEDIATE | XE_VM_BIND_FLAG_NULL | 0xffff)
  #endif

 #define XE_64K_PAGE_MASK 0xffffull

drivers/gpu/drm/xe/xe_vm.c static int vm_bind_ioctl_check_args(struct · line 2927

Quoted 5 lines
drivers/gpu/drm/xe/xe_vm.c +1 -0
@@ -2903,6 +2923,7 @@ static int vm_bind_ioctl_check_args(struct
 xe_device *xe,
                 u32 obj = (*bind_ops)[i].obj;
                 u64 obj_offset = (*bind_ops)[i].obj_offset;
                 u32 region = (*bind_ops)[i].region;
+               bool null = op &  XE_VM_BIND_FLAG_NULL;

And in multiple other places...

Quoted 146 lines


                if (i == 0) {
                        *async = !!(op & XE_VM_BIND_FLAG_ASYNC);

drivers/gpu/drm/xe/xe_vm.c +0 -0
@@ -2929,8 +2950,12 @@ static int vm_bind_ioctl_check_args(struct
 xe_device *xe,

                if (XE_IOCTL_ERR(xe, VM_BIND_OP(op) > XE_VM_BIND_OP_PREFETCH) || XE_IOCTL_ERR(xe, op & ~SUPPORTED_FLAGS) || +                   XE_IOCTL_ERR(xe, obj && null) ||
+                   XE_IOCTL_ERR(xe, obj_offset && null) || +                   XE_IOCTL_ERR(xe, VM_BIND_OP(op) != XE_VM_BIND_OP_MAP &&
+                                null) ||
                    XE_IOCTL_ERR(xe, !obj &&
-                                VM_BIND_OP(op) == XE_VM_BIND_OP_MAP) ||
+                                VM_BIND_OP(op) == XE_VM_BIND_OP_MAP && !null) ||
                    XE_IOCTL_ERR(xe, !obj && VM_BIND_OP(op) == XE_VM_BIND_OP_UNMAP_ALL) ||
                    XE_IOCTL_ERR(xe, addr &&

drivers/gpu/drm/xe/xe_vm.c +0 -0
@@ -3254,6 +3279,7 @@ int xe_vm_invalidate_vma(struct xe_vma *vma)
         int ret;


        XE_BUG_ON(!xe_vm_in_fault_mode(xe_vma_vm(vma))); +       XE_BUG_ON(xe_vma_is_null(vma)); trace_xe_vma_usm_invalidate(vma);

        /* Check that we don't race with page-table updates */

drivers/gpu/drm/xe/xe_vm.c +1 -0
@@ -3313,8 +3339,11 @@ int xe_analyze_vm(struct drm_printer *p,
 struct xe_vm *vm, int gt_id)
         drm_gpuva_iter_for_each(gpuva, it) {
                 struct xe_vma* vma = gpuva_to_vma(gpuva);
                 bool is_userptr = xe_vma_is_userptr(vma);
+               bool null = xe_vma_is_null(vma);


-               if (is_userptr) {
+               if (null) {
+                       addr = 0;
+               } else if (is_userptr) {
                        struct xe_res_cursor cur;

                        xe_res_first_sg(vma->userptr.sg, 0, XE_PAGE_SIZE, &cur);

drivers/gpu/drm/xe/xe_vm.c +0 -0
@@ -3324,7 +3353,8 @@ int xe_analyze_vm(struct drm_printer *p, struct
 xe_vm *vm, int gt_id)
                 }

                drm_printf(p, " [%016llx-%016llx] S:0x%016llx A:%016llx %s\n",
                           xe_vma_start(vma), xe_vma_end(vma), xe_vma_size(vma),
-                          addr, is_userptr ? "USR" : is_vram ? "VRAM" : "SYS");
+                          addr, null ? "NULL" :
+                          is_userptr ? "USR" : is_vram ? "VRAM" :
"SYS");
        }
        up_read(&vm->lock);

drivers/gpu/drm/xe/xe_vm.h +0 -0
index 21b1054949c4..96e2c6b07bf8 100644
@@ -175,7 +175,17 @@ static inline void
 xe_vm_reactivate_rebind(struct xe_vm *vm)
         }
  }

drivers/gpu/drm/xe/xe_vm.h +5 -0
+static inline bool xe_vma_is_null(struct xe_vma *vma)
+{
+       return vma->gpuva.flags & XE_VMA_NULL;
+}
+

 static inline bool xe_vma_is_userptr(struct xe_vma *vma)

drivers/gpu/drm/xe/xe_vm.h +5 -0
+{
+       return !xe_vma_bo(vma) && !xe_vma_is_null(vma);
+}
+
+static inline bool xe_vma_has_no_bo(struct xe_vma *vma)

 {
        return !xe_vma_bo(vma);
 }

drivers/gpu/drm/xe/xe_vm_madvise.c +0 -0
index 02d27a354b36..03508645fa08 100644
@@ -227,7 +227,7 @@ get_vmas(struct xe_vm *vm, int *num_vmas, u64
 addr, u64 range)
         drm_gpuva_iter_for_each_range(gpuva, it, addr + range) {
                 struct xe_vma *vma = gpuva_to_vma(gpuva);


-               if (xe_vma_is_userptr(vma))
+               if (xe_vma_has_no_bo(vma))
                        continue;

                if (*num_vmas == max_vmas) {

drivers/gpu/drm/xe/xe_vm_types.h +1 -0
index 243dc91a61b0..b61007b70502 100644
@@ -29,6 +29,7 @@ struct xe_vm;
  #define XE_VMA_ATOMIC_PTE_BIT  (DRM_GPUVA_USERBITS << 2)
  #define XE_VMA_FIRST_REBIND    (DRM_GPUVA_USERBITS << 3)
  #define XE_VMA_LAST_REBIND     (DRM_GPUVA_USERBITS << 4)
+#define XE_VMA_NULL            (DRM_GPUVA_USERBITS << 5)


 struct xe_vma {
        /** @gpuva: Base GPUVA object */

drivers/gpu/drm/xe/xe_vm_types.h +2 -0
@@ -315,6 +316,8 @@ struct xe_vma_op_map {
         bool immediate;
         /** @read_only: Read only */
         bool read_only;
+       /** @null: NULL (writes dropped, read zero) */
+       bool null;
  };


 /** struct xe_vma_op_unmap - VMA unmap operation */

include/uapi/drm/xe_drm.h +2 -0
index b0b80aae3ee8..27c51946fadd 100644
@@ -447,6 +447,14 @@ struct drm_xe_vm_bind_op {
          * than differing the MAP to the page fault handler.
          */
  #define XE_VM_BIND_FLAG_IMMEDIATE      (0x1 << 18)
+       /*
+        * When the NULL flag is set, the page tables are setup with

a special
+        * bit which indicates writes are dropped and all reads return zero. The
+        * NULL flags is only valid for XE_VM_BIND_OP_MAP operations, the BO
+        * handle MBZ, and the BO offset MBZ. This flag is intended to implement
+        * VK sparse bindings.
+        */
+#define XE_VM_BIND_FLAG_NULL           (0x1 << 19)

        /** @reserved: Reserved */
        __u64 reserved[2];

author maintainer
#81 lore raw

PATCH v2 18/31 drm/xe: Avoid doing rebinds

In reply to Matthew Brost

If we dont change page sizes we can avoid doing rebinds rather just do a partial unbind. The algorithm to determine is page size is greedy as we assume all pages in the removed VMA are the largest page used in the VMA.

---
 drivers/gpu/drm/xe/xe_pt.c       |  4 ++
 drivers/gpu/drm/xe/xe_vm.c       | 71 +++++++++++++++++++++++++-------
 drivers/gpu/drm/xe/xe_vm_types.h | 17 ++++----
 3 files changed, 67 insertions(+), 25 deletions(-)
drivers/gpu/drm/xe/xe_pt.c +4 -0
index b4edb751bfbb..010f44260cda 100644
@@ -412,6 +412,8 @@ struct xe_pt_stage_bind_walk {
 	/* Input parameters for the walk */
 	/** @vm: The vm we're building for. */
 	struct xe_vm *vm;
+	/** @vma: The vma we are binding for. */
+	struct xe_vma *vma;
 	/** @gt: The gt we're building for. */
 	struct xe_gt *gt;
 	/** @cache: Desired cache level for the ptes */
@@ -688,6 +690,7 @@ xe_pt_stage_bind_entry(struct drm_pt *parent, pgoff_t offset,
 		if (!null)
 			xe_res_next(curs, next - addr);
 		xe_walk->va_curs_start = next;
+		xe_walk->vma->gpuva.flags |= (XE_VMA_PTE_4K << level);
 		*action = ACTION_CONTINUE;
 
 		return ret;
@@ -776,6 +779,7 @@ xe_pt_stage_bind(struct xe_gt *gt, struct xe_vma *vma,
 			.max_level = XE_PT_HIGHEST_LEVEL,
 		},
 		.vm = xe_vma_vm(vma),
+		.vma = vma,
 		.gt = gt,
 		.curs = &curs,
 		.va_curs_start = xe_vma_start(vma),
drivers/gpu/drm/xe/xe_vm.c +56 -15

113 lines not on this page · raw message

drivers/gpu/drm/xe/xe_vm_types.h +7 -10
index b61007b70502..d55ec8156caa 100644
@@ -30,6 +30,9 @@ struct xe_vm;
 #define XE_VMA_FIRST_REBIND	(DRM_GPUVA_USERBITS << 3)
 #define XE_VMA_LAST_REBIND	(DRM_GPUVA_USERBITS << 4)
 #define XE_VMA_NULL		(DRM_GPUVA_USERBITS << 5)
+#define XE_VMA_PTE_4K		(DRM_GPUVA_USERBITS << 6)
+#define XE_VMA_PTE_2M		(DRM_GPUVA_USERBITS << 7)
+#define XE_VMA_PTE_1G		(DRM_GPUVA_USERBITS << 8)
 
 struct xe_vma {
 	/** @gpuva: Base GPUVA object */
@@ -320,14 +323,6 @@ struct xe_vma_op_map {
 	bool null;
 };
 
-/** struct xe_vma_op_unmap - VMA unmap operation */
-struct xe_vma_op_unmap {
-	/** @start: start of the VMA unmap */
-	u64 start;
-	/** @range: range of the VMA unmap */
-	u64 range;
-};
-
 /** struct xe_vma_op_remap - VMA remap operation */
 struct xe_vma_op_remap {
 	/** @prev: VMA preceding part of a split mapping */
@@ -338,6 +333,10 @@ struct xe_vma_op_remap {
 	u64 start;
 	/** @range: range of the VMA unmap */
 	u64 range;
+	/** @skip_prev: skip prev rebind */
+	bool skip_prev;
+	/** @skip_next: skip next rebind */
+	bool skip_next;
 	/** @unmap_done: unmap operation in done */
 	bool unmap_done;
 };
@@ -395,8 +394,6 @@ struct xe_vma_op {
 	union {
 		/** @map: VMA map operation specific data */
 		struct xe_vma_op_map map;
-		/** @unmap: VMA unmap operation specific data */
-		struct xe_vma_op_unmap unmap;
 		/** @remap: VMA remap operation specific data */
 		struct xe_vma_op_remap remap;
 		/** @prefetch: VMA prefetch operation specific data */
Signature · 1 line
2.34.1
maintainer
#82 lore raw

Re: [Intel-xe] [PATCH v2 18/31] drm/xe: Avoid doing rebinds

Quoted 2 lines · Matthew Brost

If we dont change page sizes we can avoid doing rebinds rather just do a partial unbind. The algorithm to determine is page size is greedy as we

There's something off in this phrase... ^ around here...
maybe s/is/its/ ?

But about the rebinds and remaps I was not able to follow the changes below... probably if this patch was in a smaller series or if the code for the remap that this is based on was already merged that could be easier... or maybe someone with more deep knowledge in this area like Thomas would be the best one to review this.

Quoted 214 lines

assume all pages in the removed VMA are the largest page used in the VMA.

---
 drivers/gpu/drm/xe/xe_pt.c       |  4 ++
 drivers/gpu/drm/xe/xe_vm.c       | 71 +++++++++++++++++++++++++-------
 drivers/gpu/drm/xe/xe_vm_types.h | 17 ++++----
 3 files changed, 67 insertions(+), 25 deletions(-)
drivers/gpu/drm/xe/xe_pt.c +4 -0
index b4edb751bfbb..010f44260cda 100644
@@ -412,6 +412,8 @@ struct xe_pt_stage_bind_walk {
 	/* Input parameters for the walk */
 	/** @vm: The vm we're building for. */
 	struct xe_vm *vm;
+	/** @vma: The vma we are binding for. */
+	struct xe_vma *vma;
 	/** @gt: The gt we're building for. */
 	struct xe_gt *gt;
 	/** @cache: Desired cache level for the ptes */
@@ -688,6 +690,7 @@ xe_pt_stage_bind_entry(struct drm_pt *parent, pgoff_t offset,
 		if (!null)
 			xe_res_next(curs, next - addr);
 		xe_walk->va_curs_start = next;
+		xe_walk->vma->gpuva.flags |= (XE_VMA_PTE_4K << level);
 		*action = ACTION_CONTINUE;
 
 		return ret;
@@ -776,6 +779,7 @@ xe_pt_stage_bind(struct xe_gt *gt, struct xe_vma *vma,
 			.max_level = XE_PT_HIGHEST_LEVEL,
 		},
 		.vm = xe_vma_vm(vma),
+		.vma = vma,
 		.gt = gt,
 		.curs = &curs,
 		.va_curs_start = xe_vma_start(vma),
drivers/gpu/drm/xe/xe_vm.c +56 -15
index a46f44ab2546..e0ed7201aeb0 100644
@@ -2276,6 +2276,16 @@ static struct xe_vma *new_vma(struct xe_vm *vm, struct drm_gpuva_op_map *op,
 	return vma;
 }
 
+static u64 xe_vma_max_pte_size(struct xe_vma *vma)
+{
+	if (vma->gpuva.flags & XE_VMA_PTE_1G)
+		return SZ_1G;
+	else if (vma->gpuva.flags & XE_VMA_PTE_2M)
+		return SZ_2M;
+
+	return SZ_4K;
+}
+
 /*
  * Parse operations list and create any resources needed for the operations
  * prior to fully commiting to the operations. This setp can fail.
@@ -2352,6 +2362,13 @@ static int vm_bind_ioctl_ops_parse(struct xe_vm *vm, struct xe_engine *e,
 				break;
 			}
 			case DRM_GPUVA_OP_REMAP:
+			{
+				struct xe_vma *old =
+					gpuva_to_vma(op->base.remap.unmap->va);
+
+				op->remap.start = xe_vma_start(old);
+				op->remap.range = xe_vma_size(old);
+
 				if (op->base.remap.prev) {
 					struct xe_vma *vma;
 					bool read_only =
@@ -2370,6 +2387,20 @@ static int vm_bind_ioctl_ops_parse(struct xe_vm *vm, struct xe_engine *e,
 					}
 
 					op->remap.prev = vma;
+
+					/*
+					 * XXX: Not sure why userptr doesn't
+					 * work but really shouldn't be a use
+					 * case.
+					 */
+					op->remap.skip_prev = !xe_vma_is_userptr(old) &&
+						IS_ALIGNED(xe_vma_end(vma), xe_vma_max_pte_size(old));
+					if (op->remap.skip_prev) {
+						op->remap.range -=
+							xe_vma_end(vma) -
+							xe_vma_start(old);
+						op->remap.start = xe_vma_end(vma);
+					}
 				}
 
 				if (op->base.remap.next) {
@@ -2391,20 +2422,16 @@ static int vm_bind_ioctl_ops_parse(struct xe_vm *vm, struct xe_engine *e,
 					}
 
 					op->remap.next = vma;
+					op->remap.skip_next = !xe_vma_is_userptr(old) &&
+						IS_ALIGNED(xe_vma_start(vma), xe_vma_max_pte_size(old));
+					if (op->remap.skip_next)
+						op->remap.range -=
+							xe_vma_end(old) -
+							xe_vma_start(vma);
 				}
-
-				/* XXX: Support no doing remaps */
-				op->remap.start =
-					xe_vma_start(gpuva_to_vma(op->base.remap.unmap->va));
-				op->remap.range =
-					xe_vma_size(gpuva_to_vma(op->base.remap.unmap->va));
 				break;
+			}
 			case DRM_GPUVA_OP_UNMAP:
-				op->unmap.start =
-					xe_vma_start(gpuva_to_vma(op->base.unmap.va));
-				op->unmap.range =
-					xe_vma_size(gpuva_to_vma(op->base.unmap.va));
-				break;
 			case DRM_GPUVA_OP_PREFETCH:
 				/* Nothing to do */
 				break;
@@ -2445,10 +2472,23 @@ static int xe_vma_op_commit(struct xe_vm *vm, struct xe_vma_op *op)
 	case DRM_GPUVA_OP_REMAP:
 		prep_vma_destroy(vm, gpuva_to_vma(op->base.remap.unmap->va),
 				 true);
-		if (op->remap.prev)
+
+		if (op->remap.prev) {
 			err |= xe_vm_insert_vma(vm, op->remap.prev);
-		if (op->remap.next)
+			if (!err && op->remap.skip_prev)
+				op->remap.prev = NULL;
+		}
+		if (op->remap.next) {
 			err |= xe_vm_insert_vma(vm, op->remap.next);
+			if (!err && op->remap.skip_next)
+				op->remap.next = NULL;
+		}
+
+		/* Adjust for partial unbind after removin VMA from VM */
+		if (!err) {
+			op->base.remap.unmap->va->va.addr = op->remap.start;
+			op->base.remap.unmap->va->va.range = op->remap.range;
+		}
 		break;
 	case DRM_GPUVA_OP_UNMAP:
 		prep_vma_destroy(vm, gpuva_to_vma(op->base.unmap.va), true);
@@ -2518,9 +2558,10 @@ static int __xe_vma_op_execute(struct xe_vm *vm, struct xe_vma *vma,
 		bool next = !!op->remap.next;
 
 		if (!op->remap.unmap_done) {
-			vm->async_ops.munmap_rebind_inflight = true;
-			if (prev || next)
+			if (prev || next) {
+				vm->async_ops.munmap_rebind_inflight = true;
 				vma->gpuva.flags |= XE_VMA_FIRST_REBIND;
+			}
 			err = xe_vm_unbind(vm, vma, op->engine, op->syncs,
 					   op->num_syncs,
 					   !prev && !next ? op->fence : NULL,
drivers/gpu/drm/xe/xe_vm_types.h +7 -10
index b61007b70502..d55ec8156caa 100644
@@ -30,6 +30,9 @@ struct xe_vm;
 #define XE_VMA_FIRST_REBIND	(DRM_GPUVA_USERBITS << 3)
 #define XE_VMA_LAST_REBIND	(DRM_GPUVA_USERBITS << 4)
 #define XE_VMA_NULL		(DRM_GPUVA_USERBITS << 5)
+#define XE_VMA_PTE_4K		(DRM_GPUVA_USERBITS << 6)
+#define XE_VMA_PTE_2M		(DRM_GPUVA_USERBITS << 7)
+#define XE_VMA_PTE_1G		(DRM_GPUVA_USERBITS << 8)
 
 struct xe_vma {
 	/** @gpuva: Base GPUVA object */
@@ -320,14 +323,6 @@ struct xe_vma_op_map {
 	bool null;
 };
 
-/** struct xe_vma_op_unmap - VMA unmap operation */
-struct xe_vma_op_unmap {
-	/** @start: start of the VMA unmap */
-	u64 start;
-	/** @range: range of the VMA unmap */
-	u64 range;
-};
-
 /** struct xe_vma_op_remap - VMA remap operation */
 struct xe_vma_op_remap {
 	/** @prev: VMA preceding part of a split mapping */
@@ -338,6 +333,10 @@ struct xe_vma_op_remap {
 	u64 start;
 	/** @range: range of the VMA unmap */
 	u64 range;
+	/** @skip_prev: skip prev rebind */
+	bool skip_prev;
+	/** @skip_next: skip next rebind */
+	bool skip_next;
 	/** @unmap_done: unmap operation in done */
 	bool unmap_done;
 };
@@ -395,8 +394,6 @@ struct xe_vma_op {
 	union {
 		/** @map: VMA map operation specific data */
 		struct xe_vma_op_map map;
-		/** @unmap: VMA unmap operation specific data */
-		struct xe_vma_op_unmap unmap;
 		/** @remap: VMA remap operation specific data */
 		struct xe_vma_op_remap remap;
 		/** @prefetch: VMA prefetch operation specific data */
Signature · 1 line
2.34.1
author maintainer
#83 lore raw

PATCH v2 19/31 drm/xe: Reduce the number list links in xe_vma

In reply to Matthew Brost

5 list links in can be squashed into a union in xe_vma as being on the various list is mutually exclusive.

---
 drivers/gpu/drm/xe/xe_gt_pagefault.c |  2 +-
 drivers/gpu/drm/xe/xe_pt.c           |  5 +-
 drivers/gpu/drm/xe/xe_vm.c           | 29 ++++++------
 drivers/gpu/drm/xe/xe_vm_types.h     | 71 +++++++++++++++-------------
 4 files changed, 55 insertions(+), 52 deletions(-)
drivers/gpu/drm/xe/xe_gt_pagefault.c +1 -1
index cfffe3398fe4..d7bf6b0a0697 100644
@@ -157,7 +157,7 @@ static int handle_pagefault(struct xe_gt *gt, struct pagefault *pf)
 
 	if (xe_vma_is_userptr(vma) && write_locked) {
 		spin_lock(&vm->userptr.invalidated_lock);
-		list_del_init(&vma->userptr.invalidate_link);
+		list_del_init(&vma->invalidate_link);
 		spin_unlock(&vm->userptr.invalidated_lock);
 
 		ret = xe_vma_userptr_pin_pages(vma);
drivers/gpu/drm/xe/xe_pt.c +2 -3
index 010f44260cda..8eab8e1bbaf0 100644
@@ -1116,8 +1116,7 @@ static int xe_pt_userptr_inject_eagain(struct xe_vma *vma)
 
 		vma->userptr.divisor = divisor << 1;
 		spin_lock(&vm->userptr.invalidated_lock);
-		list_move_tail(&vma->userptr.invalidate_link,
-			       &vm->userptr.invalidated);
+		list_move_tail(&vma->invalidate_link, &vm->userptr.invalidated);
 		spin_unlock(&vm->userptr.invalidated_lock);
 		return true;
 	}
@@ -1724,7 +1723,7 @@ __xe_pt_unbind_vma(struct xe_gt *gt, struct xe_vma *vma, struct xe_engine *e,
 
 		if (!vma->gt_present) {
 			spin_lock(&vm->userptr.invalidated_lock);
-			list_del_init(&vma->userptr.invalidate_link);
+			list_del_init(&vma->invalidate_link);
 			spin_unlock(&vm->userptr.invalidated_lock);
 		}
 		up_read(&vm->userptr.notifier_lock);
drivers/gpu/drm/xe/xe_vm.c +14 -15
index e0ed7201aeb0..e5f2fffb2aec 100644
@@ -677,8 +677,7 @@ static bool vma_userptr_invalidate(struct mmu_interval_notifier *mni,
 	if (!xe_vm_in_fault_mode(vm) &&
 	    !(vma->gpuva.flags & XE_VMA_DESTROYED) && vma->gt_present) {
 		spin_lock(&vm->userptr.invalidated_lock);
-		list_move_tail(&vma->userptr.invalidate_link,
-			       &vm->userptr.invalidated);
+		list_move_tail(&vma->invalidate_link, &vm->userptr.invalidated);
 		spin_unlock(&vm->userptr.invalidated_lock);
 	}
 
@@ -726,8 +725,8 @@ int xe_vm_userptr_pin(struct xe_vm *vm)
 	/* Collect invalidated userptrs */
 	spin_lock(&vm->userptr.invalidated_lock);
 	list_for_each_entry_safe(vma, next, &vm->userptr.invalidated,
-				 userptr.invalidate_link) {
-		list_del_init(&vma->userptr.invalidate_link);
+				 invalidate_link) {
+		list_del_init(&vma->invalidate_link);
 		list_move_tail(&vma->userptr_link, &vm->userptr.repin_list);
 	}
 	spin_unlock(&vm->userptr.invalidated_lock);
@@ -830,12 +829,11 @@ static struct xe_vma *xe_vma_create(struct xe_vm *vm,
 		return vma;
 	}
 
-	/* FIXME: Way to many lists, should be able to reduce this */
+	/*
+	 * userptr_link, destroy_link, notifier.rebind_link,
+	 * invalidate_link
+	 */
 	INIT_LIST_HEAD(&vma->rebind_link);
-	INIT_LIST_HEAD(&vma->unbind_link);
-	INIT_LIST_HEAD(&vma->userptr_link);
-	INIT_LIST_HEAD(&vma->userptr.invalidate_link);
-	INIT_LIST_HEAD(&vma->notifier.rebind_link);
 	INIT_LIST_HEAD(&vma->extobj.link);
 
 	INIT_LIST_HEAD(&vma->gpuva.gem.entry);
@@ -953,15 +951,14 @@ static void xe_vma_destroy(struct xe_vma *vma, struct dma_fence *fence)
 	struct xe_vm *vm = xe_vma_vm(vma);
 
 	lockdep_assert_held_write(&vm->lock);
-	XE_BUG_ON(!list_empty(&vma->unbind_link));
 
 	if (xe_vma_is_userptr(vma)) {
 		XE_WARN_ON(!(vma->gpuva.flags & XE_VMA_DESTROYED));
 
 		spin_lock(&vm->userptr.invalidated_lock);
-		list_del_init(&vma->userptr.invalidate_link);
+		if (!list_empty(&vma->invalidate_link))
+			list_del_init(&vma->invalidate_link);
 		spin_unlock(&vm->userptr.invalidated_lock);
-		list_del(&vma->userptr_link);
 	} else if (!xe_vma_is_null(vma)) {
 		xe_bo_assert_held(xe_vma_bo(vma));
 		drm_gpuva_unlink(&vma->gpuva);
@@ -1328,7 +1325,9 @@ void xe_vm_close_and_put(struct xe_vm *vm)
 			continue;
 		}
 
-		list_add_tail(&vma->unbind_link, &contested);
+		if (!list_empty(&vma->destroy_link))
+			list_del_init(&vma->destroy_link);
+		list_add_tail(&vma->destroy_link, &contested);
 	}
 
 	/*
@@ -1356,8 +1355,8 @@ void xe_vm_close_and_put(struct xe_vm *vm)
 	 * Since we hold a refcount to the bo, we can remove and free
 	 * the members safely without locking.
 	 */
-	list_for_each_entry_safe(vma, next_vma, &contested, unbind_link) {
-		list_del_init(&vma->unbind_link);
+	list_for_each_entry_safe(vma, next_vma, &contested, destroy_link) {
+		list_del_init(&vma->destroy_link);
 		xe_vma_destroy_unlocked(vma);
 	}
 
drivers/gpu/drm/xe/xe_vm_types.h +38 -33

93 lines not on this page · raw message

Signature · 1 line
2.34.1
maintainer Reviewed-by on v2 19/31
#84 lore raw

Re: [Intel-xe] [PATCH v2 19/31] drm/xe: Reduce the number list links in xe_vma

Quoted 4 lines · Matthew Brost

5 list links in can be squashed into a union in xe_vma as being on the various list is mutually exclusive.

Quoted 228 lines
---
 drivers/gpu/drm/xe/xe_gt_pagefault.c |  2 +-
 drivers/gpu/drm/xe/xe_pt.c           |  5 +-
 drivers/gpu/drm/xe/xe_vm.c           | 29 ++++++------
 drivers/gpu/drm/xe/xe_vm_types.h     | 71 +++++++++++++++-------------
 4 files changed, 55 insertions(+), 52 deletions(-)
drivers/gpu/drm/xe/xe_gt_pagefault.c +1 -1
index cfffe3398fe4..d7bf6b0a0697 100644
@@ -157,7 +157,7 @@ static int handle_pagefault(struct xe_gt *gt, struct pagefault *pf)
 
 	if (xe_vma_is_userptr(vma) && write_locked) {
 		spin_lock(&vm->userptr.invalidated_lock);
-		list_del_init(&vma->userptr.invalidate_link);
+		list_del_init(&vma->invalidate_link);
 		spin_unlock(&vm->userptr.invalidated_lock);
 
 		ret = xe_vma_userptr_pin_pages(vma);
drivers/gpu/drm/xe/xe_pt.c +2 -3
index 010f44260cda..8eab8e1bbaf0 100644
@@ -1116,8 +1116,7 @@ static int xe_pt_userptr_inject_eagain(struct xe_vma *vma)
 
 		vma->userptr.divisor = divisor << 1;
 		spin_lock(&vm->userptr.invalidated_lock);
-		list_move_tail(&vma->userptr.invalidate_link,
-			       &vm->userptr.invalidated);
+		list_move_tail(&vma->invalidate_link, &vm->userptr.invalidated);
 		spin_unlock(&vm->userptr.invalidated_lock);
 		return true;
 	}
@@ -1724,7 +1723,7 @@ __xe_pt_unbind_vma(struct xe_gt *gt, struct xe_vma *vma, struct xe_engine *e,
 
 		if (!vma->gt_present) {
 			spin_lock(&vm->userptr.invalidated_lock);
-			list_del_init(&vma->userptr.invalidate_link);
+			list_del_init(&vma->invalidate_link);
 			spin_unlock(&vm->userptr.invalidated_lock);
 		}
 		up_read(&vm->userptr.notifier_lock);
drivers/gpu/drm/xe/xe_vm.c +14 -15
index e0ed7201aeb0..e5f2fffb2aec 100644
@@ -677,8 +677,7 @@ static bool vma_userptr_invalidate(struct mmu_interval_notifier *mni,
 	if (!xe_vm_in_fault_mode(vm) &&
 	    !(vma->gpuva.flags & XE_VMA_DESTROYED) && vma->gt_present) {
 		spin_lock(&vm->userptr.invalidated_lock);
-		list_move_tail(&vma->userptr.invalidate_link,
-			       &vm->userptr.invalidated);
+		list_move_tail(&vma->invalidate_link, &vm->userptr.invalidated);
 		spin_unlock(&vm->userptr.invalidated_lock);
 	}
 
@@ -726,8 +725,8 @@ int xe_vm_userptr_pin(struct xe_vm *vm)
 	/* Collect invalidated userptrs */
 	spin_lock(&vm->userptr.invalidated_lock);
 	list_for_each_entry_safe(vma, next, &vm->userptr.invalidated,
-				 userptr.invalidate_link) {
-		list_del_init(&vma->userptr.invalidate_link);
+				 invalidate_link) {
+		list_del_init(&vma->invalidate_link);
 		list_move_tail(&vma->userptr_link, &vm->userptr.repin_list);
 	}
 	spin_unlock(&vm->userptr.invalidated_lock);
@@ -830,12 +829,11 @@ static struct xe_vma *xe_vma_create(struct xe_vm *vm,
 		return vma;
 	}
 
-	/* FIXME: Way to many lists, should be able to reduce this */
+	/*
+	 * userptr_link, destroy_link, notifier.rebind_link,
+	 * invalidate_link
+	 */
 	INIT_LIST_HEAD(&vma->rebind_link);
-	INIT_LIST_HEAD(&vma->unbind_link);
-	INIT_LIST_HEAD(&vma->userptr_link);
-	INIT_LIST_HEAD(&vma->userptr.invalidate_link);
-	INIT_LIST_HEAD(&vma->notifier.rebind_link);
 	INIT_LIST_HEAD(&vma->extobj.link);
 
 	INIT_LIST_HEAD(&vma->gpuva.gem.entry);
@@ -953,15 +951,14 @@ static void xe_vma_destroy(struct xe_vma *vma, struct dma_fence *fence)
 	struct xe_vm *vm = xe_vma_vm(vma);
 
 	lockdep_assert_held_write(&vm->lock);
-	XE_BUG_ON(!list_empty(&vma->unbind_link));
 
 	if (xe_vma_is_userptr(vma)) {
 		XE_WARN_ON(!(vma->gpuva.flags & XE_VMA_DESTROYED));
 
 		spin_lock(&vm->userptr.invalidated_lock);
-		list_del_init(&vma->userptr.invalidate_link);
+		if (!list_empty(&vma->invalidate_link))
+			list_del_init(&vma->invalidate_link);
 		spin_unlock(&vm->userptr.invalidated_lock);
-		list_del(&vma->userptr_link);
 	} else if (!xe_vma_is_null(vma)) {
 		xe_bo_assert_held(xe_vma_bo(vma));
 		drm_gpuva_unlink(&vma->gpuva);
@@ -1328,7 +1325,9 @@ void xe_vm_close_and_put(struct xe_vm *vm)
 			continue;
 		}
 
-		list_add_tail(&vma->unbind_link, &contested);
+		if (!list_empty(&vma->destroy_link))
+			list_del_init(&vma->destroy_link);
+		list_add_tail(&vma->destroy_link, &contested);
 	}
 
 	/*
@@ -1356,8 +1355,8 @@ void xe_vm_close_and_put(struct xe_vm *vm)
 	 * Since we hold a refcount to the bo, we can remove and free
 	 * the members safely without locking.
 	 */
-	list_for_each_entry_safe(vma, next_vma, &contested, unbind_link) {
-		list_del_init(&vma->unbind_link);
+	list_for_each_entry_safe(vma, next_vma, &contested, destroy_link) {
+		list_del_init(&vma->destroy_link);
 		xe_vma_destroy_unlocked(vma);
 	}
 
drivers/gpu/drm/xe/xe_vm_types.h +38 -33
index d55ec8156caa..22def5483c12 100644
@@ -50,21 +50,32 @@ struct xe_vma {
 	 */
 	u64 gt_present;
 
-	/** @userptr_link: link into VM repin list if userptr */
-	struct list_head userptr_link;
+	union {
+		/** @userptr_link: link into VM repin list if userptr */
+		struct list_head userptr_link;
 
-	/**
-	 * @rebind_link: link into VM if this VMA needs rebinding, and
-	 * if it's a bo (not userptr) needs validation after a possible
-	 * eviction. Protected by the vm's resv lock.
-	 */
-	struct list_head rebind_link;
+		/**
+		 * @rebind_link: link into VM if this VMA needs rebinding, and
+		 * if it's a bo (not userptr) needs validation after a possible
+		 * eviction. Protected by the vm's resv lock.
+		 */
+		struct list_head rebind_link;
 
-	/**
-	 * @unbind_link: link or list head if an unbind of multiple VMAs, in
-	 * single unbind op, is being done.
-	 */
-	struct list_head unbind_link;
+		/** @destroy_link: link for contested VMAs on VM close */
+		struct list_head destroy_link;
+
+		/** @invalidate_link: Link for the vm::userptr.invalidated list */
+		struct list_head invalidate_link;
+
+		struct {
+			 /*
+			  * @notifier.rebind_link: link for
+			  * vm->notifier.rebind_list, protected by
+			  * vm->notifier.list_lock
+			  */
+			struct list_head rebind_link;
+		} notifier;
+	};
 
 	/** @destroy_cb: callback to destroy VMA when unbind job is done */
 	struct dma_fence_cb destroy_cb;
@@ -72,10 +83,22 @@ struct xe_vma {
 	/** @destroy_work: worker to destroy this BO */
 	struct work_struct destroy_work;
 
+	/** @usm: unified shared memory state */
+	struct {
+		/** @gt_invalidated: VMA has been invalidated */
+		u64 gt_invalidated;
+	} usm;
+
+	struct {
+		/**
+		 * @extobj.link: Link into vm's external object list.
+		 * protected by the vm lock.
+		 */
+		struct list_head link;
+	} extobj;
+
 	/** @userptr: user pointer state */
 	struct {
-		/** @invalidate_link: Link for the vm::userptr.invalidated list */
-		struct list_head invalidate_link;
 		/**
 		 * @notifier: MMU notifier for user pointer (invalidation call back)
 		 */
@@ -96,24 +119,6 @@ struct xe_vma {
 		u32 divisor;
 #endif
 	} userptr;
-
-	/** @usm: unified shared memory state */
-	struct {
-		/** @gt_invalidated: VMA has been invalidated */
-		u64 gt_invalidated;
-	} usm;
-
-	struct {
-		struct list_head rebind_link;
-	} notifier;
-
-	struct {
-		/**
-		 * @extobj.link: Link into vm's external object list.
-		 * protected by the vm lock.
-		 */
-		struct list_head link;
-	} extobj;
 };
 
 struct xe_device;
Signature · 1 line
2.34.1
#85 lore raw

Re: [Intel-xe] [PATCH v2 19/31] drm/xe: Reduce the number list links in xe_vma

In reply to Matthew Brost
Quoted 145 lines · Matthew Brost

5 list links in can be squashed into a union in xe_vma as being on the various list is mutually exclusive.

---
  drivers/gpu/drm/xe/xe_gt_pagefault.c |  2 +-
  drivers/gpu/drm/xe/xe_pt.c           |  5 +-
  drivers/gpu/drm/xe/xe_vm.c           | 29 ++++++------
  drivers/gpu/drm/xe/xe_vm_types.h     | 71 +++++++++++++++-------------
  4 files changed, 55 insertions(+), 52 deletions(-)
drivers/gpu/drm/xe/xe_gt_pagefault.c +1 -1
index cfffe3398fe4..d7bf6b0a0697 100644
@@ -157,7 +157,7 @@ static int handle_pagefault(struct xe_gt *gt, struct pagefault *pf)
 
  	if (xe_vma_is_userptr(vma) && write_locked) {
  		spin_lock(&vm->userptr.invalidated_lock);
-		list_del_init(&vma->userptr.invalidate_link);
+		list_del_init(&vma->invalidate_link);
  		spin_unlock(&vm->userptr.invalidated_lock);
 
  		ret = xe_vma_userptr_pin_pages(vma);
drivers/gpu/drm/xe/xe_pt.c +2 -3
index 010f44260cda..8eab8e1bbaf0 100644
@@ -1116,8 +1116,7 @@ static int xe_pt_userptr_inject_eagain(struct xe_vma *vma)
 
  		vma->userptr.divisor = divisor << 1;
  		spin_lock(&vm->userptr.invalidated_lock);
-		list_move_tail(&vma->userptr.invalidate_link,
-			       &vm->userptr.invalidated);
+		list_move_tail(&vma->invalidate_link, &vm->userptr.invalidated);
  		spin_unlock(&vm->userptr.invalidated_lock);
  		return true;
  	}
@@ -1724,7 +1723,7 @@ __xe_pt_unbind_vma(struct xe_gt *gt, struct xe_vma *vma, struct xe_engine *e,
 
  		if (!vma->gt_present) {
  			spin_lock(&vm->userptr.invalidated_lock);
-			list_del_init(&vma->userptr.invalidate_link);
+			list_del_init(&vma->invalidate_link);
  			spin_unlock(&vm->userptr.invalidated_lock);
  		}
  		up_read(&vm->userptr.notifier_lock);
drivers/gpu/drm/xe/xe_vm.c +14 -15
index e0ed7201aeb0..e5f2fffb2aec 100644
@@ -677,8 +677,7 @@ static bool vma_userptr_invalidate(struct mmu_interval_notifier *mni,
  	if (!xe_vm_in_fault_mode(vm) &&
  	    !(vma->gpuva.flags & XE_VMA_DESTROYED) && vma->gt_present) {
  		spin_lock(&vm->userptr.invalidated_lock);
-		list_move_tail(&vma->userptr.invalidate_link,
-			       &vm->userptr.invalidated);
+		list_move_tail(&vma->invalidate_link, &vm->userptr.invalidated);
  		spin_unlock(&vm->userptr.invalidated_lock);
  	}
 
@@ -726,8 +725,8 @@ int xe_vm_userptr_pin(struct xe_vm *vm)
  	/* Collect invalidated userptrs */
  	spin_lock(&vm->userptr.invalidated_lock);
  	list_for_each_entry_safe(vma, next, &vm->userptr.invalidated,
-				 userptr.invalidate_link) {
-		list_del_init(&vma->userptr.invalidate_link);
+				 invalidate_link) {
+		list_del_init(&vma->invalidate_link);
  		list_move_tail(&vma->userptr_link, &vm->userptr.repin_list);
  	}
  	spin_unlock(&vm->userptr.invalidated_lock);
@@ -830,12 +829,11 @@ static struct xe_vma *xe_vma_create(struct xe_vm *vm,
  		return vma;
  	}
 
-	/* FIXME: Way to many lists, should be able to reduce this */
+	/*
+	 * userptr_link, destroy_link, notifier.rebind_link,
+	 * invalidate_link
+	 */
  	INIT_LIST_HEAD(&vma->rebind_link);
-	INIT_LIST_HEAD(&vma->unbind_link);
-	INIT_LIST_HEAD(&vma->userptr_link);
-	INIT_LIST_HEAD(&vma->userptr.invalidate_link);
-	INIT_LIST_HEAD(&vma->notifier.rebind_link);
  	INIT_LIST_HEAD(&vma->extobj.link);
 
  	INIT_LIST_HEAD(&vma->gpuva.gem.entry);
@@ -953,15 +951,14 @@ static void xe_vma_destroy(struct xe_vma *vma, struct dma_fence *fence)
  	struct xe_vm *vm = xe_vma_vm(vma);
 
  	lockdep_assert_held_write(&vm->lock);
-	XE_BUG_ON(!list_empty(&vma->unbind_link));
 
  	if (xe_vma_is_userptr(vma)) {
  		XE_WARN_ON(!(vma->gpuva.flags & XE_VMA_DESTROYED));
 
  		spin_lock(&vm->userptr.invalidated_lock);
-		list_del_init(&vma->userptr.invalidate_link);
+		if (!list_empty(&vma->invalidate_link))
+			list_del_init(&vma->invalidate_link);
  		spin_unlock(&vm->userptr.invalidated_lock);
-		list_del(&vma->userptr_link);
  	} else if (!xe_vma_is_null(vma)) {
  		xe_bo_assert_held(xe_vma_bo(vma));
  		drm_gpuva_unlink(&vma->gpuva);
@@ -1328,7 +1325,9 @@ void xe_vm_close_and_put(struct xe_vm *vm)
  			continue;
  		}
 
-		list_add_tail(&vma->unbind_link, &contested);
+		if (!list_empty(&vma->destroy_link))
+			list_del_init(&vma->destroy_link);
+		list_add_tail(&vma->destroy_link, &contested);
  	}
 
  	/*
@@ -1356,8 +1355,8 @@ void xe_vm_close_and_put(struct xe_vm *vm)
  	 * Since we hold a refcount to the bo, we can remove and free
  	 * the members safely without locking.
  	 */
-	list_for_each_entry_safe(vma, next_vma, &contested, unbind_link) {
-		list_del_init(&vma->unbind_link);
+	list_for_each_entry_safe(vma, next_vma, &contested, destroy_link) {
+		list_del_init(&vma->destroy_link);
  		xe_vma_destroy_unlocked(vma);
  	}
 
drivers/gpu/drm/xe/xe_vm_types.h +3 -4
index d55ec8156caa..22def5483c12 100644
@@ -50,21 +50,32 @@ struct xe_vma {
  	 */
  	u64 gt_present;
 
-	/** @userptr_link: link into VM repin list if userptr */
-	struct list_head userptr_link;
+	union {
+		/** @userptr_link: link into VM repin list if userptr */
+		struct list_head userptr_link;
 
-	/**
-	 * @rebind_link: link into VM if this VMA needs rebinding, and

drivers/gpu/drm/xe/xe_vm_types.h struct xe_vma { · line 62

Quoted 10 lines
drivers/gpu/drm/xe/xe_vm_types.h +6 -4
-	 * if it's a bo (not userptr) needs validation after a possible
-	 * eviction. Protected by the vm's resv lock.
-	 */
-	struct list_head rebind_link;
+		/**
+		 * @rebind_link: link into VM if this VMA needs rebinding, and
+		 * if it's a bo (not userptr) needs validation after a possible
+		 * eviction. Protected by the vm's resv lock.
+		 */
+		struct list_head rebind_link;

Since the different lists have very different locking protection, I'm pretty sure you can come up with a scenario where this is invalid, for example a userptr vma being on the vm->userptr.repin_list and the vm->rebind_list simultaneously, if we, for example do a repin and then hit an -EINTR during xe_vm_lock_dma_resv() and then immediately a new userptr invalidation (now the rebind_link and userptr.invalidate_link are used on different lists), and then a new repin (now the rebind_link and userptr_link are used on different lists, simultaneously).

If you want to do a union like this, we either need to have the exact same locking rules for the links or they should be used for completely different purposes that can never happen together, like the userptr.invalidate_link and the notifier.rebind_link, one used for userptr only and the other for bo only.

I'm also pretty sure that a vma can be on the rebind_list and the notifier.rebind_list simultaneously, due to the different locking, with a similar reasoning as above.

So without the rule of exact same locking rules, it becomes practically impossible to reason that using a union is safe.

/Thomas

author maintainer
#86 lore raw

PATCH v2 20/31 drm/xe: Optimize size of xe_vma allocation

In reply to Matthew Brost

Reduce gt_mask to a u8 from a u64, only allocate userptr state if VMA is a userptr, and union of destroy callback and worker.

---
 drivers/gpu/drm/xe/xe_vm.c       | 14 +++--
 drivers/gpu/drm/xe/xe_vm_types.h | 88 +++++++++++++++++---------------
 2 files changed, 57 insertions(+), 45 deletions(-)
drivers/gpu/drm/xe/xe_vm.c +9 -5
index e5f2fffb2aec..e8d9939ee535 100644
@@ -814,7 +814,7 @@ static struct xe_vma *xe_vma_create(struct xe_vm *vm,
 				    u64 bo_offset_or_userptr,
 				    u64 start, u64 end,
 				    bool read_only, bool null,
-				    u64 gt_mask)
+				    u8 gt_mask)
 {
 	struct xe_vma *vma;
 	struct xe_gt *gt;
@@ -823,7 +823,11 @@ static struct xe_vma *xe_vma_create(struct xe_vm *vm,
 	XE_BUG_ON(start >= end);
 	XE_BUG_ON(end >= vm->size);
 
-	vma = kzalloc(sizeof(*vma), GFP_KERNEL);
+	if (!bo && !null)	/* userptr */
+		vma = kzalloc(sizeof(*vma), GFP_KERNEL);
+	else
+		vma = kzalloc(sizeof(*vma) - sizeof(struct xe_userptr),
+			      GFP_KERNEL);
 	if (!vma) {
 		vma = ERR_PTR(-ENOMEM);
 		return vma;
@@ -2149,7 +2153,7 @@ static void print_op(struct xe_device *xe, struct drm_gpuva_op *op)
 static struct drm_gpuva_ops *
 vm_bind_ioctl_ops_create(struct xe_vm *vm, struct xe_bo *bo,
 			 u64 bo_offset_or_userptr, u64 addr, u64 range,
-			 u32 operation, u64 gt_mask, u32 region)
+			 u32 operation, u8 gt_mask, u32 region)
 {
 	struct drm_gem_object *obj = bo ? &bo->ttm.base : NULL;
 	struct ww_acquire_ctx ww;
@@ -2234,7 +2238,7 @@ vm_bind_ioctl_ops_create(struct xe_vm *vm, struct xe_bo *bo,
 }
 
 static struct xe_vma *new_vma(struct xe_vm *vm, struct drm_gpuva_op_map *op,
-			      u64 gt_mask, bool read_only, bool null)
+			      u8 gt_mask, bool read_only, bool null)
 {
 	struct xe_bo *bo = op->gem.obj ? gem_to_xe_bo(op->gem.obj) : NULL;
 	struct xe_vma *vma;
@@ -3217,8 +3221,8 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 		u64 addr = bind_ops[i].addr;
 		u32 op = bind_ops[i].op;
 		u64 obj_offset = bind_ops[i].obj_offset;
-		u64 gt_mask = bind_ops[i].gt_mask;
 		u32 region = bind_ops[i].region;
+		u8 gt_mask = bind_ops[i].gt_mask;
 
 		ops[i] = vm_bind_ioctl_ops_create(vm, bos[i], obj_offset,
 						  addr, range, op, gt_mask,
drivers/gpu/drm/xe/xe_vm_types.h +48 -40

121 lines not on this page · raw message

Signature · 1 line
2.34.1
#87 lore raw

Re: [Intel-xe] [PATCH v2 20/31] drm/xe: Optimize size of xe_vma allocation

Quoted 2 lines · Matthew Brost

Reduce gt_mask to a u8 from a u64, only allocate userptr state if VMA is a userptr, and union of destroy callback and worker.

too many different things in one patch. could you please split the patch?

Quoted 193 lines
---
 drivers/gpu/drm/xe/xe_vm.c       | 14 +++--
 drivers/gpu/drm/xe/xe_vm_types.h | 88 +++++++++++++++++---------------
 2 files changed, 57 insertions(+), 45 deletions(-)
drivers/gpu/drm/xe/xe_vm.c +9 -5
index e5f2fffb2aec..e8d9939ee535 100644
@@ -814,7 +814,7 @@ static struct xe_vma *xe_vma_create(struct xe_vm *vm,
 				    u64 bo_offset_or_userptr,
 				    u64 start, u64 end,
 				    bool read_only, bool null,
-				    u64 gt_mask)
+				    u8 gt_mask)
 {
 	struct xe_vma *vma;
 	struct xe_gt *gt;
@@ -823,7 +823,11 @@ static struct xe_vma *xe_vma_create(struct xe_vm *vm,
 	XE_BUG_ON(start >= end);
 	XE_BUG_ON(end >= vm->size);
 
-	vma = kzalloc(sizeof(*vma), GFP_KERNEL);
+	if (!bo && !null)	/* userptr */
+		vma = kzalloc(sizeof(*vma), GFP_KERNEL);
+	else
+		vma = kzalloc(sizeof(*vma) - sizeof(struct xe_userptr),
+			      GFP_KERNEL);
 	if (!vma) {
 		vma = ERR_PTR(-ENOMEM);
 		return vma;
@@ -2149,7 +2153,7 @@ static void print_op(struct xe_device *xe, struct drm_gpuva_op *op)
 static struct drm_gpuva_ops *
 vm_bind_ioctl_ops_create(struct xe_vm *vm, struct xe_bo *bo,
 			 u64 bo_offset_or_userptr, u64 addr, u64 range,
-			 u32 operation, u64 gt_mask, u32 region)
+			 u32 operation, u8 gt_mask, u32 region)
 {
 	struct drm_gem_object *obj = bo ? &bo->ttm.base : NULL;
 	struct ww_acquire_ctx ww;
@@ -2234,7 +2238,7 @@ vm_bind_ioctl_ops_create(struct xe_vm *vm, struct xe_bo *bo,
 }
 
 static struct xe_vma *new_vma(struct xe_vm *vm, struct drm_gpuva_op_map *op,
-			      u64 gt_mask, bool read_only, bool null)
+			      u8 gt_mask, bool read_only, bool null)
 {
 	struct xe_bo *bo = op->gem.obj ? gem_to_xe_bo(op->gem.obj) : NULL;
 	struct xe_vma *vma;
@@ -3217,8 +3221,8 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 		u64 addr = bind_ops[i].addr;
 		u32 op = bind_ops[i].op;
 		u64 obj_offset = bind_ops[i].obj_offset;
-		u64 gt_mask = bind_ops[i].gt_mask;
 		u32 region = bind_ops[i].region;
+		u8 gt_mask = bind_ops[i].gt_mask;
 
 		ops[i] = vm_bind_ioctl_ops_create(vm, bos[i], obj_offset,
 						  addr, range, op, gt_mask,
drivers/gpu/drm/xe/xe_vm_types.h +48 -40
index 22def5483c12..df4797ec4d7f 100644
@@ -34,22 +34,34 @@ struct xe_vm;
 #define XE_VMA_PTE_2M		(DRM_GPUVA_USERBITS << 7)
 #define XE_VMA_PTE_1G		(DRM_GPUVA_USERBITS << 8)
 
+/** struct xe_userptr - User pointer */
+struct xe_userptr {
+	/**
+	 * @notifier: MMU notifier for user pointer (invalidation call back)
+	 */
+	struct mmu_interval_notifier notifier;
+	/** @sgt: storage for a scatter gather table */
+	struct sg_table sgt;
+	/** @sg: allocated scatter gather table */
+	struct sg_table *sg;
+	/** @notifier_seq: notifier sequence number */
+	unsigned long notifier_seq;
+	/**
+	 * @initial_bind: user pointer has been bound at least once.
+	 * write: vm->userptr.notifier_lock in read mode and vm->resv held.
+	 * read: vm->userptr.notifier_lock in write mode or vm->resv held.
+	 */
+	bool initial_bind;
+#if IS_ENABLED(CONFIG_DRM_XE_USERPTR_INVAL_INJECT)
+	u32 divisor;
+#endif
+};
+
+/** xe_vma - Virtual memory address */
 struct xe_vma {
 	/** @gpuva: Base GPUVA object */
 	struct drm_gpuva gpuva;
 
-	/** @gt_mask: GT mask of where to create binding for this VMA */
-	u64 gt_mask;
-
-	/**
-	 * @gt_present: GT mask of binding are present for this VMA.
-	 * protected by vm->lock, vm->resv and for userptrs,
-	 * vm->userptr.notifier_lock for writing. Needs either for reading,
-	 * but if reading is done under the vm->lock only, it needs to be held
-	 * in write mode.
-	 */
-	u64 gt_present;
-
 	union {
 		/** @userptr_link: link into VM repin list if userptr */
 		struct list_head userptr_link;
@@ -77,16 +89,29 @@ struct xe_vma {
 		} notifier;
 	};
 
-	/** @destroy_cb: callback to destroy VMA when unbind job is done */
-	struct dma_fence_cb destroy_cb;
+	union {
+		/** @destroy_cb: callback to destroy VMA when unbind job is done */
+		struct dma_fence_cb destroy_cb;
+		/** @destroy_work: worker to destroy this BO */
+		struct work_struct destroy_work;
+	};
 
-	/** @destroy_work: worker to destroy this BO */
-	struct work_struct destroy_work;
+	/** @gt_mask: GT mask of where to create binding for this VMA */
+	u8 gt_mask;
+
+	/**
+	 * @gt_present: GT mask of binding are present for this VMA.
+	 * protected by vm->lock, vm->resv and for userptrs,
+	 * vm->userptr.notifier_lock for writing. Needs either for reading,
+	 * but if reading is done under the vm->lock only, it needs to be held
+	 * in write mode.
+	 */
+	u8 gt_present;
 
 	/** @usm: unified shared memory state */
 	struct {
 		/** @gt_invalidated: VMA has been invalidated */
-		u64 gt_invalidated;
+		u8 gt_invalidated;
 	} usm;
 
 	struct {
@@ -97,28 +122,11 @@ struct xe_vma {
 		struct list_head link;
 	} extobj;
 
-	/** @userptr: user pointer state */
-	struct {
-		/**
-		 * @notifier: MMU notifier for user pointer (invalidation call back)
-		 */
-		struct mmu_interval_notifier notifier;
-		/** @sgt: storage for a scatter gather table */
-		struct sg_table sgt;
-		/** @sg: allocated scatter gather table */
-		struct sg_table *sg;
-		/** @notifier_seq: notifier sequence number */
-		unsigned long notifier_seq;
-		/**
-		 * @initial_bind: user pointer has been bound at least once.
-		 * write: vm->userptr.notifier_lock in read mode and vm->resv held.
-		 * read: vm->userptr.notifier_lock in write mode or vm->resv held.
-		 */
-		bool initial_bind;
-#if IS_ENABLED(CONFIG_DRM_XE_USERPTR_INVAL_INJECT)
-		u32 divisor;
-#endif
-	} userptr;
+	/**
+	 * @userptr: user pointer state, only allocated for VMAs that are
+	 * user pointers
+	 */
+	struct xe_userptr userptr;
 };
 
 struct xe_device;
@@ -387,7 +395,7 @@ struct xe_vma_op {
 	 */
 	struct async_op_fence *fence;
 	/** @gt_mask: gt mask for this operation */
-	u64 gt_mask;
+	u8 gt_mask;
 	/** @flags: operation flags */
 	enum xe_vma_op_flags flags;
 
Signature · 1 line
2.34.1
author maintainer
#88 lore raw

Re: [Intel-xe] [PATCH v2 20/31] drm/xe: Optimize size of xe_vma allocation

Quoted 6 lines · Rodrigo Vivi
Quoted 2 lines · Matthew Brost

Reduce gt_mask to a u8 from a u64, only allocate userptr state if VMA is a userptr, and union of destroy callback and worker.

too many different things in one patch. could you please split the patch?

Yes, will do.

Matt

Quoted 193 lines
Quoted 193 lines
---
 drivers/gpu/drm/xe/xe_vm.c       | 14 +++--
 drivers/gpu/drm/xe/xe_vm_types.h | 88 +++++++++++++++++---------------
 2 files changed, 57 insertions(+), 45 deletions(-)
drivers/gpu/drm/xe/xe_vm.c +9 -5
index e5f2fffb2aec..e8d9939ee535 100644
@@ -814,7 +814,7 @@ static struct xe_vma *xe_vma_create(struct xe_vm *vm,
 				    u64 bo_offset_or_userptr,
 				    u64 start, u64 end,
 				    bool read_only, bool null,
-				    u64 gt_mask)
+				    u8 gt_mask)
 {
 	struct xe_vma *vma;
 	struct xe_gt *gt;
@@ -823,7 +823,11 @@ static struct xe_vma *xe_vma_create(struct xe_vm *vm,
 	XE_BUG_ON(start >= end);
 	XE_BUG_ON(end >= vm->size);
 
-	vma = kzalloc(sizeof(*vma), GFP_KERNEL);
+	if (!bo && !null)	/* userptr */
+		vma = kzalloc(sizeof(*vma), GFP_KERNEL);
+	else
+		vma = kzalloc(sizeof(*vma) - sizeof(struct xe_userptr),
+			      GFP_KERNEL);
 	if (!vma) {
 		vma = ERR_PTR(-ENOMEM);
 		return vma;
@@ -2149,7 +2153,7 @@ static void print_op(struct xe_device *xe, struct drm_gpuva_op *op)
 static struct drm_gpuva_ops *
 vm_bind_ioctl_ops_create(struct xe_vm *vm, struct xe_bo *bo,
 			 u64 bo_offset_or_userptr, u64 addr, u64 range,
-			 u32 operation, u64 gt_mask, u32 region)
+			 u32 operation, u8 gt_mask, u32 region)
 {
 	struct drm_gem_object *obj = bo ? &bo->ttm.base : NULL;
 	struct ww_acquire_ctx ww;
@@ -2234,7 +2238,7 @@ vm_bind_ioctl_ops_create(struct xe_vm *vm, struct xe_bo *bo,
 }
 
 static struct xe_vma *new_vma(struct xe_vm *vm, struct drm_gpuva_op_map *op,
-			      u64 gt_mask, bool read_only, bool null)
+			      u8 gt_mask, bool read_only, bool null)
 {
 	struct xe_bo *bo = op->gem.obj ? gem_to_xe_bo(op->gem.obj) : NULL;
 	struct xe_vma *vma;
@@ -3217,8 +3221,8 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 		u64 addr = bind_ops[i].addr;
 		u32 op = bind_ops[i].op;
 		u64 obj_offset = bind_ops[i].obj_offset;
-		u64 gt_mask = bind_ops[i].gt_mask;
 		u32 region = bind_ops[i].region;
+		u8 gt_mask = bind_ops[i].gt_mask;
 
 		ops[i] = vm_bind_ioctl_ops_create(vm, bos[i], obj_offset,
 						  addr, range, op, gt_mask,
drivers/gpu/drm/xe/xe_vm_types.h +48 -40
index 22def5483c12..df4797ec4d7f 100644
@@ -34,22 +34,34 @@ struct xe_vm;
 #define XE_VMA_PTE_2M		(DRM_GPUVA_USERBITS << 7)
 #define XE_VMA_PTE_1G		(DRM_GPUVA_USERBITS << 8)
 
+/** struct xe_userptr - User pointer */
+struct xe_userptr {
+	/**
+	 * @notifier: MMU notifier for user pointer (invalidation call back)
+	 */
+	struct mmu_interval_notifier notifier;
+	/** @sgt: storage for a scatter gather table */
+	struct sg_table sgt;
+	/** @sg: allocated scatter gather table */
+	struct sg_table *sg;
+	/** @notifier_seq: notifier sequence number */
+	unsigned long notifier_seq;
+	/**
+	 * @initial_bind: user pointer has been bound at least once.
+	 * write: vm->userptr.notifier_lock in read mode and vm->resv held.
+	 * read: vm->userptr.notifier_lock in write mode or vm->resv held.
+	 */
+	bool initial_bind;
+#if IS_ENABLED(CONFIG_DRM_XE_USERPTR_INVAL_INJECT)
+	u32 divisor;
+#endif
+};
+
+/** xe_vma - Virtual memory address */
 struct xe_vma {
 	/** @gpuva: Base GPUVA object */
 	struct drm_gpuva gpuva;
 
-	/** @gt_mask: GT mask of where to create binding for this VMA */
-	u64 gt_mask;
-
-	/**
-	 * @gt_present: GT mask of binding are present for this VMA.
-	 * protected by vm->lock, vm->resv and for userptrs,
-	 * vm->userptr.notifier_lock for writing. Needs either for reading,
-	 * but if reading is done under the vm->lock only, it needs to be held
-	 * in write mode.
-	 */
-	u64 gt_present;
-
 	union {
 		/** @userptr_link: link into VM repin list if userptr */
 		struct list_head userptr_link;
@@ -77,16 +89,29 @@ struct xe_vma {
 		} notifier;
 	};
 
-	/** @destroy_cb: callback to destroy VMA when unbind job is done */
-	struct dma_fence_cb destroy_cb;
+	union {
+		/** @destroy_cb: callback to destroy VMA when unbind job is done */
+		struct dma_fence_cb destroy_cb;
+		/** @destroy_work: worker to destroy this BO */
+		struct work_struct destroy_work;
+	};
 
-	/** @destroy_work: worker to destroy this BO */
-	struct work_struct destroy_work;
+	/** @gt_mask: GT mask of where to create binding for this VMA */
+	u8 gt_mask;
+
+	/**
+	 * @gt_present: GT mask of binding are present for this VMA.
+	 * protected by vm->lock, vm->resv and for userptrs,
+	 * vm->userptr.notifier_lock for writing. Needs either for reading,
+	 * but if reading is done under the vm->lock only, it needs to be held
+	 * in write mode.
+	 */
+	u8 gt_present;
 
 	/** @usm: unified shared memory state */
 	struct {
 		/** @gt_invalidated: VMA has been invalidated */
-		u64 gt_invalidated;
+		u8 gt_invalidated;
 	} usm;
 
 	struct {
@@ -97,28 +122,11 @@ struct xe_vma {
 		struct list_head link;
 	} extobj;
 
-	/** @userptr: user pointer state */
-	struct {
-		/**
-		 * @notifier: MMU notifier for user pointer (invalidation call back)
-		 */
-		struct mmu_interval_notifier notifier;
-		/** @sgt: storage for a scatter gather table */
-		struct sg_table sgt;
-		/** @sg: allocated scatter gather table */
-		struct sg_table *sg;
-		/** @notifier_seq: notifier sequence number */
-		unsigned long notifier_seq;
-		/**
-		 * @initial_bind: user pointer has been bound at least once.
-		 * write: vm->userptr.notifier_lock in read mode and vm->resv held.
-		 * read: vm->userptr.notifier_lock in write mode or vm->resv held.
-		 */
-		bool initial_bind;
-#if IS_ENABLED(CONFIG_DRM_XE_USERPTR_INVAL_INJECT)
-		u32 divisor;
-#endif
-	} userptr;
+	/**
+	 * @userptr: user pointer state, only allocated for VMAs that are
+	 * user pointers
+	 */
+	struct xe_userptr userptr;
 };
 
 struct xe_device;
@@ -387,7 +395,7 @@ struct xe_vma_op {
 	 */
 	struct async_op_fence *fence;
 	/** @gt_mask: gt mask for this operation */
-	u64 gt_mask;
+	u8 gt_mask;
 	/** @flags: operation flags */
 	enum xe_vma_op_flags flags;
 
Signature · 1 line
2.34.1
#89 lore raw

Re: [Intel-xe] [PATCH v2 20/31] drm/xe: Optimize size of xe_vma allocation

In reply to Matthew Brost
Quoted 170 lines · Matthew Brost

Reduce gt_mask to a u8 from a u64, only allocate userptr state if VMA is a userptr, and union of destroy callback and worker.

---
  drivers/gpu/drm/xe/xe_vm.c       | 14 +++--
  drivers/gpu/drm/xe/xe_vm_types.h | 88 +++++++++++++++++---------------
  2 files changed, 57 insertions(+), 45 deletions(-)
drivers/gpu/drm/xe/xe_vm.c +9 -5
index e5f2fffb2aec..e8d9939ee535 100644
@@ -814,7 +814,7 @@ static struct xe_vma *xe_vma_create(struct xe_vm *vm,
  				    u64 bo_offset_or_userptr,
  				    u64 start, u64 end,
  				    bool read_only, bool null,
-				    u64 gt_mask)
+				    u8 gt_mask)
  {
  	struct xe_vma *vma;
  	struct xe_gt *gt;
@@ -823,7 +823,11 @@ static struct xe_vma *xe_vma_create(struct xe_vm *vm,
  	XE_BUG_ON(start >= end);
  	XE_BUG_ON(end >= vm->size);
 
-	vma = kzalloc(sizeof(*vma), GFP_KERNEL);
+	if (!bo && !null)	/* userptr */
+		vma = kzalloc(sizeof(*vma), GFP_KERNEL);
+	else
+		vma = kzalloc(sizeof(*vma) - sizeof(struct xe_userptr),
+			      GFP_KERNEL);
  	if (!vma) {
  		vma = ERR_PTR(-ENOMEM);
  		return vma;
@@ -2149,7 +2153,7 @@ static void print_op(struct xe_device *xe, struct drm_gpuva_op *op)
  static struct drm_gpuva_ops *
  vm_bind_ioctl_ops_create(struct xe_vm *vm, struct xe_bo *bo,
  			 u64 bo_offset_or_userptr, u64 addr, u64 range,
-			 u32 operation, u64 gt_mask, u32 region)
+			 u32 operation, u8 gt_mask, u32 region)
  {
  	struct drm_gem_object *obj = bo ? &bo->ttm.base : NULL;
  	struct ww_acquire_ctx ww;
@@ -2234,7 +2238,7 @@ vm_bind_ioctl_ops_create(struct xe_vm *vm, struct xe_bo *bo,
  }
 
  static struct xe_vma *new_vma(struct xe_vm *vm, struct drm_gpuva_op_map *op,
-			      u64 gt_mask, bool read_only, bool null)
+			      u8 gt_mask, bool read_only, bool null)
  {
  	struct xe_bo *bo = op->gem.obj ? gem_to_xe_bo(op->gem.obj) : NULL;
  	struct xe_vma *vma;
@@ -3217,8 +3221,8 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
  		u64 addr = bind_ops[i].addr;
  		u32 op = bind_ops[i].op;
  		u64 obj_offset = bind_ops[i].obj_offset;
-		u64 gt_mask = bind_ops[i].gt_mask;
  		u32 region = bind_ops[i].region;
+		u8 gt_mask = bind_ops[i].gt_mask;
 
  		ops[i] = vm_bind_ioctl_ops_create(vm, bos[i], obj_offset,
  						  addr, range, op, gt_mask,
drivers/gpu/drm/xe/xe_vm_types.h +42 -34
index 22def5483c12..df4797ec4d7f 100644
@@ -34,22 +34,34 @@ struct xe_vm;
  #define XE_VMA_PTE_2M		(DRM_GPUVA_USERBITS << 7)
  #define XE_VMA_PTE_1G		(DRM_GPUVA_USERBITS << 8)
 
+/** struct xe_userptr - User pointer */
+struct xe_userptr {
+	/**
+	 * @notifier: MMU notifier for user pointer (invalidation call back)
+	 */
+	struct mmu_interval_notifier notifier;
+	/** @sgt: storage for a scatter gather table */
+	struct sg_table sgt;
+	/** @sg: allocated scatter gather table */
+	struct sg_table *sg;
+	/** @notifier_seq: notifier sequence number */
+	unsigned long notifier_seq;
+	/**
+	 * @initial_bind: user pointer has been bound at least once.
+	 * write: vm->userptr.notifier_lock in read mode and vm->resv held.
+	 * read: vm->userptr.notifier_lock in write mode or vm->resv held.
+	 */
+	bool initial_bind;
+#if IS_ENABLED(CONFIG_DRM_XE_USERPTR_INVAL_INJECT)
+	u32 divisor;
+#endif
+};
+
+/** xe_vma - Virtual memory address */
  struct xe_vma {
  	/** @gpuva: Base GPUVA object */
  	struct drm_gpuva gpuva;
 
-	/** @gt_mask: GT mask of where to create binding for this VMA */
-	u64 gt_mask;
-
-	/**
-	 * @gt_present: GT mask of binding are present for this VMA.
-	 * protected by vm->lock, vm->resv and for userptrs,
-	 * vm->userptr.notifier_lock for writing. Needs either for reading,
-	 * but if reading is done under the vm->lock only, it needs to be held
-	 * in write mode.
-	 */
-	u64 gt_present;
-
  	union {
  		/** @userptr_link: link into VM repin list if userptr */
  		struct list_head userptr_link;
@@ -77,16 +89,29 @@ struct xe_vma {
  		} notifier;
  	};
 
-	/** @destroy_cb: callback to destroy VMA when unbind job is done */
-	struct dma_fence_cb destroy_cb;
+	union {
+		/** @destroy_cb: callback to destroy VMA when unbind job is done */
+		struct dma_fence_cb destroy_cb;
+		/** @destroy_work: worker to destroy this BO */
+		struct work_struct destroy_work;
+	};
 
-	/** @destroy_work: worker to destroy this BO */
-	struct work_struct destroy_work;
+	/** @gt_mask: GT mask of where to create binding for this VMA */
+	u8 gt_mask;
+
+	/**
+	 * @gt_present: GT mask of binding are present for this VMA.
+	 * protected by vm->lock, vm->resv and for userptrs,
+	 * vm->userptr.notifier_lock for writing. Needs either for reading,
+	 * but if reading is done under the vm->lock only, it needs to be held
+	 * in write mode.
+	 */
+	u8 gt_present;
 
  	/** @usm: unified shared memory state */
  	struct {
  		/** @gt_invalidated: VMA has been invalidated */
-		u64 gt_invalidated;
+		u8 gt_invalidated;
  	} usm;
 
  	struct {
@@ -97,28 +122,11 @@ struct xe_vma {
  		struct list_head link;
  	} extobj;
 
-	/** @userptr: user pointer state */
-	struct {
-		/**
-		 * @notifier: MMU notifier for user pointer (invalidation call back)
-		 */
-		struct mmu_interval_notifier notifier;
-		/** @sgt: storage for a scatter gather table */
-		struct sg_table sgt;
-		/** @sg: allocated scatter gather table */
-		struct sg_table *sg;
-		/** @notifier_seq: notifier sequence number */
-		unsigned long notifier_seq;
-		/**
-		 * @initial_bind: user pointer has been bound at least once.
-		 * write: vm->userptr.notifier_lock in read mode and vm->resv held.
-		 * read: vm->userptr.notifier_lock in write mode or vm->resv held.
-		 */

drivers/gpu/drm/xe/xe_vm_types.h struct xe_vma { · line 129

Quoted 10 lines
drivers/gpu/drm/xe/xe_vm_types.h +5 -5
-		bool initial_bind;
-#if IS_ENABLED(CONFIG_DRM_XE_USERPTR_INVAL_INJECT)
-		u32 divisor;
-#endif
-	} userptr;
+	/**
+	 * @userptr: user pointer state, only allocated for VMAs that are
+	 * user pointers
+	 */
+	struct xe_userptr userptr;

I think this is very fragile, What happens when someone doesn't read the code and simply adds a member after @userptr, or generic code accidently dereferences a field in @userptr?

Wouldn't the proper way to do this, if at all, to subclass xe_vma into an xe_vma_usertptr to guard against such things happening?

For the u8 space optimizations, also a pahole layout before and after the change would be beneficial in the commit message.

/Thomas

Quoted 12 lines
drivers/gpu/drm/xe/xe_vm_types.h +1 -1
  };
 
  struct xe_device;
@@ -387,7 +395,7 @@ struct xe_vma_op {
  	 */
  	struct async_op_fence *fence;
  	/** @gt_mask: gt mask for this operation */
-	u64 gt_mask;
+	u8 gt_mask;
  	/** @flags: operation flags */
  	enum xe_vma_op_flags flags;
 
author maintainer
#90 lore raw

PATCH v2 21/31 drm/gpuva: Add drm device to GPUVA manager

In reply to Matthew Brost

This is the logical place for this, will help with upcoming changes too.

---
 drivers/gpu/drm/drm_gpuva_mgr.c  |  3 +++
 drivers/gpu/drm/xe/xe_migrate.c  | 10 +++++-----
 drivers/gpu/drm/xe/xe_pt.c       | 18 +++++++++---------
 drivers/gpu/drm/xe/xe_vm.c       | 31 +++++++++++++++----------------
 drivers/gpu/drm/xe/xe_vm.h       | 10 ++++++++++
 drivers/gpu/drm/xe/xe_vm_types.h |  2 --
 include/drm/drm_gpuva_mgr.h      |  4 ++++
 7 files changed, 46 insertions(+), 32 deletions(-)
drivers/gpu/drm/drm_gpuva_mgr.c +3 -0
index bd7d27ee44bb..137322945e91 100644
@@ -413,6 +413,7 @@ static void __drm_gpuva_remove(struct drm_gpuva *va);
 /**
  * drm_gpuva_manager_init - initialize a &drm_gpuva_manager
  * @mgr: pointer to the &drm_gpuva_manager to initialize
+ * @drm: drm device
  * @name: the name of the GPU VA space
  * @start_offset: the start offset of the GPU VA space
  * @range: the size of the GPU VA space
@@ -427,6 +428,7 @@ static void __drm_gpuva_remove(struct drm_gpuva *va);
  */
 void
 drm_gpuva_manager_init(struct drm_gpuva_manager *mgr,
+		       struct drm_device *drm,
 		       const char *name,
 		       u64 start_offset, u64 range,
 		       u64 reserve_offset, u64 reserve_range,
@@ -437,6 +439,7 @@ drm_gpuva_manager_init(struct drm_gpuva_manager *mgr,
 	mgr->mm_start = start_offset;
 	mgr->mm_range = range;
 
+	mgr->drm = drm;
 	mgr->name = name ? name : "unknown";
 	mgr->ops = ops;
 
drivers/gpu/drm/xe/xe_migrate.c +5 -5
index b44aa094a466..0a393c5772e5 100644
@@ -129,7 +129,7 @@ static u64 xe_migrate_vram_ofs(u64 addr)
 static int xe_migrate_create_cleared_bo(struct xe_migrate *m, struct xe_vm *vm)
 {
 	struct xe_gt *gt = m->gt;
-	struct xe_device *xe = vm->xe;
+	struct xe_device *xe = xe_vm_device(vm);
 	size_t cleared_size;
 	u64 vram_addr;
 	bool is_vram;
@@ -175,7 +175,7 @@ static int xe_migrate_prepare_vm(struct xe_gt *gt, struct xe_migrate *m,
 	/* Need to be sure everything fits in the first PT, or create more */
 	XE_BUG_ON(m->batch_base_ofs + batch->size >= SZ_2M);
 
-	bo = xe_bo_create_pin_map(vm->xe, m->gt, vm,
+	bo = xe_bo_create_pin_map(xe_vm_device(vm), m->gt, vm,
 				  num_entries * XE_PAGE_SIZE,
 				  ttm_bo_type_kernel,
 				  XE_BO_CREATE_VRAM_IF_DGFX(m->gt) |
@@ -1051,7 +1051,7 @@ xe_migrate_update_pgtables_cpu(struct xe_migrate *m,
 
 	if (wait_vm && !dma_resv_test_signaled(&vm->resv,
 					       DMA_RESV_USAGE_BOOKKEEP)) {
-		vm_dbg(&vm->xe->drm, "wait on VM for munmap");
+		vm_dbg(&xe_vm_device(vm)->drm, "wait on VM for munmap");
 		return ERR_PTR(-ETIME);
 	}
 
@@ -1069,7 +1069,7 @@ xe_migrate_update_pgtables_cpu(struct xe_migrate *m,
 
 	if (vm) {
 		trace_xe_vm_cpu_bind(vm);
-		xe_device_wmb(vm->xe);
+		xe_device_wmb(xe_vm_device(vm));
 	}
 
 	fence = dma_fence_get_stub();
@@ -1263,7 +1263,7 @@ xe_migrate_update_pgtables(struct xe_migrate *m,
 	 * trigger preempts before moving forward
 	 */
 	if (first_munmap_rebind) {
-		vm_dbg(&vm->xe->drm, "wait on first_munmap_rebind");
+		vm_dbg(&xe_vm_device(vm)->drm, "wait on first_munmap_rebind");
 		err = job_add_deps(job, &vm->resv,
 				   DMA_RESV_USAGE_BOOKKEEP);
 		if (err)
drivers/gpu/drm/xe/xe_pt.c +9 -9
index 8eab8e1bbaf0..4167f666d98d 100644
@@ -218,7 +218,7 @@ struct xe_pt *xe_pt_create(struct xe_vm *vm, struct xe_gt *gt,
 	if (!pt)
 		return ERR_PTR(-ENOMEM);
 
-	bo = xe_bo_create_pin_map(vm->xe, gt, vm, SZ_4K,
+	bo = xe_bo_create_pin_map(xe_vm_device(vm), gt, vm, SZ_4K,
 				  ttm_bo_type_kernel,
 				  XE_BO_CREATE_VRAM_IF_DGFX(gt) |
 				  XE_BO_CREATE_IGNORE_MIN_PAGE_SIZE_BIT |
@@ -264,11 +264,11 @@ void xe_pt_populate_empty(struct xe_gt *gt, struct xe_vm *vm,
 		 * FIXME: Some memory is allocated already allocated to zero?
 		 * Find out which memory that is and avoid this memset...
 		 */
-		xe_map_memset(vm->xe, map, 0, 0, SZ_4K);
+		xe_map_memset(xe_vm_device(vm), map, 0, 0, SZ_4K);
 	} else {
 		empty = __xe_pt_empty_pte(gt, vm, pt->level);
 		for (i = 0; i < XE_PDES; i++)
-			xe_pt_write(vm->xe, map, i, empty);
+			xe_pt_write(xe_vm_device(vm), map, i, empty);
 	}
 }
 
@@ -355,7 +355,7 @@ int xe_pt_create_scratch(struct xe_device *xe, struct xe_gt *gt,
 	if (IS_ERR(vm->scratch_bo[id]))
 		return PTR_ERR(vm->scratch_bo[id]);
 
-	xe_map_memset(vm->xe, &vm->scratch_bo[id]->vmap, 0, 0,
+	xe_map_memset(xe_vm_device(vm), &vm->scratch_bo[id]->vmap, 0, 0,
 		      vm->scratch_bo[id]->size);
 
 	for (i = 0; i < vm->pt_root[id]->level; i++) {
@@ -538,7 +538,7 @@ xe_pt_insert_entry(struct xe_pt_stage_bind_walk *xe_walk, struct xe_pt *parent,
 		if (unlikely(xe_child))
 			parent->drm.dir->entries[offset] = &xe_child->drm;
 
-		xe_pt_write(xe_walk->vm->xe, map, offset, pte);
+		xe_pt_write(xe_vm_device(xe_walk->vm), map, offset, pte);
 		parent->num_live++;
 	} else {
 		/* Shared pt. Stage update. */
@@ -1337,7 +1337,7 @@ __xe_pt_bind_vma(struct xe_gt *gt, struct xe_vma *vma, struct xe_engine *e,
 	xe_vm_assert_held(vm);
 	XE_BUG_ON(xe_gt_is_media_type(gt));
 
-	vm_dbg(&xe_vma_vm(vma)->xe->drm,
+	vm_dbg(&xe_vma_device(vma)->drm,
 	       "Preparing bind, with range [%llx...%llx) engine %p.\n",
 	       xe_vma_start(vma), xe_vma_end(vma) - 1, e);
 
@@ -1366,7 +1366,7 @@ __xe_pt_bind_vma(struct xe_gt *gt, struct xe_vma *vma, struct xe_engine *e,
 
 
 		if (last_munmap_rebind)
-			vm_dbg(&vm->xe->drm, "last_munmap_rebind");
+			vm_dbg(&xe_vm_device(vm)->drm, "last_munmap_rebind");
 
 		/* TLB invalidation must be done before signaling rebind */
 		if (rebind && !xe_vm_no_dma_fences(xe_vma_vm(vma))) {
@@ -1401,7 +1401,7 @@ __xe_pt_bind_vma(struct xe_gt *gt, struct xe_vma *vma, struct xe_engine *e,
 			xe_bo_put_commit(&deferred);
 		}
 		if (!rebind && last_munmap_rebind && xe_vm_in_compute_mode(vm))
-			queue_work(vm->xe->ordered_wq,
+			queue_work(xe_vm_device(vm)->ordered_wq,
 				   &vm->preempt.rebind_work);
 	} else {
 		kfree(ifence);
@@ -1664,7 +1664,7 @@ __xe_pt_unbind_vma(struct xe_gt *gt, struct xe_vma *vma, struct xe_engine *e,
 	xe_vm_assert_held(vm);
 	XE_BUG_ON(xe_gt_is_media_type(gt));
 
-	vm_dbg(&xe_vma_vm(vma)->xe->drm,
+	vm_dbg(&xe_vma_device(vma)->drm,
 	       "Preparing unbind, with range [%llx...%llx) engine %p.\n",
 	       xe_vma_start(vma), xe_vma_end(vma) - 1, e);
 
drivers/gpu/drm/xe/xe_vm.c +15 -16
index e8d9939ee535..688130c509a4 100644
@@ -50,7 +50,7 @@ int xe_vma_userptr_check_repin(struct xe_vma *vma)
 int xe_vma_userptr_pin_pages(struct xe_vma *vma)
 {
 	struct xe_vm *vm = xe_vma_vm(vma);
-	struct xe_device *xe = vm->xe;
+	struct xe_device *xe = xe_vm_device(vm);
 	const unsigned long num_pages = xe_vma_size(vma) >> PAGE_SHIFT;
 	struct page **pages;
 	bool in_kthread = !current->mm;
@@ -852,12 +852,12 @@ static struct xe_vma *xe_vma_create(struct xe_vm *vm,
 	if (gt_mask) {
 		vma->gt_mask = gt_mask;
 	} else {
-		for_each_gt(gt, vm->xe, id)
+		for_each_gt(gt, xe_vm_device(vm), id)
 			if (!xe_gt_is_media_type(gt))
 				vma->gt_mask |= 0x1 << id;
 	}
 
-	if (vm->xe->info.platform == XE_PVC)
+	if (xe_vm_device(vm)->info.platform == XE_PVC)
 		vma->gpuva.flags |= XE_VMA_ATOMIC_PTE_BIT;
 
 	if (bo) {
@@ -904,7 +904,7 @@ static void vm_remove_extobj(struct xe_vma *vma)
 static void xe_vma_destroy_late(struct xe_vma *vma)
 {
 	struct xe_vm *vm = xe_vma_vm(vma);
-	struct xe_device *xe = vm->xe;
+	struct xe_device *xe = xe_vm_device(vm);
 	bool read_only = xe_vma_read_only(vma);
 
 	if (xe_vma_is_userptr(vma)) {
@@ -1084,7 +1084,6 @@ struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags)
 	if (!vm)
 		return ERR_PTR(-ENOMEM);
 
-	vm->xe = xe;
 	kref_init(&vm->refcount);
 	dma_resv_init(&vm->resv);
 
@@ -1125,7 +1124,7 @@ struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags)
 	if (err)
 		goto err_put;
 
-	drm_gpuva_manager_init(&vm->mgr, "Xe VM", 0, vm->size, 0, 0,
+	drm_gpuva_manager_init(&vm->mgr, &xe->drm, "Xe VM", 0, vm->size, 0, 0,
 			       &gpuva_ops);
 	if (IS_DGFX(xe) && xe->info.vram_flags & XE_VRAM_FLAGS_NEED64K)
 		vm->flags |= XE_VM_FLAGS_64K;
@@ -1284,7 +1283,7 @@ void xe_vm_close_and_put(struct xe_vm *vm)
 {
 	struct list_head contested;
 	struct ww_acquire_ctx ww;
-	struct xe_device *xe = vm->xe;
+	struct xe_device *xe = xe_vm_device(vm);
 	struct xe_gt *gt;
 	struct xe_vma *vma, *next_vma;
 	struct drm_gpuva *gpuva;
@@ -1387,7 +1386,7 @@ static void vm_destroy_work_func(struct work_struct *w)
 	struct xe_vm *vm =
 		container_of(w, struct xe_vm, destroy_work);
 	struct ww_acquire_ctx ww;
-	struct xe_device *xe = vm->xe;
+	struct xe_device *xe = xe_vm_device(vm);
 	struct xe_gt *gt;
 	u8 id;
 	void *lookup;
@@ -1481,7 +1480,7 @@ xe_vm_unbind_vma(struct xe_vma *vma, struct xe_engine *e,
 			return ERR_PTR(-ENOMEM);
 	}
 
-	for_each_gt(gt, vm->xe, id) {
+	for_each_gt(gt, xe_vm_device(vm), id) {
 		if (!(vma->gt_present & BIT(id)))
 			goto next;
 
@@ -1555,7 +1554,7 @@ xe_vm_bind_vma(struct xe_vma *vma, struct xe_engine *e,
 			return ERR_PTR(-ENOMEM);
 	}
 
-	for_each_gt(gt, vm->xe, id) {
+	for_each_gt(gt, xe_vm_device(vm), id) {
 		if (!(vma->gt_mask & BIT(id)))
 			goto next;
 
@@ -2061,7 +2060,7 @@ static int vm_insert_extobj(struct xe_vm *vm, struct xe_vma *vma)
 static int vm_bind_ioctl_lookup_vma(struct xe_vm *vm, struct xe_bo *bo,
 				    u64 addr, u64 range, u32 op)
 {
-	struct xe_device *xe = vm->xe;
+	struct xe_device *xe = xe_vm_device(vm);
 	struct xe_vma *vma;
 	bool async = !!(op & XE_VM_BIND_FLAG_ASYNC);
 
@@ -2164,7 +2163,7 @@ vm_bind_ioctl_ops_create(struct xe_vm *vm, struct xe_bo *bo,
 
 	lockdep_assert_held_write(&vm->lock);
 
-	vm_dbg(&vm->xe->drm,
+	vm_dbg(&xe_vm_device(vm)->drm,
 	       "op=%d, addr=0x%016llx, range=0x%016llx, bo_offset_or_userptr=0x%016llx",
 	       VM_BIND_OP(operation), addr, range, bo_offset_or_userptr);
 
@@ -2232,7 +2231,7 @@ vm_bind_ioctl_ops_create(struct xe_vm *vm, struct xe_bo *bo,
 
 	if (!IS_ERR(ops))
 		drm_gpuva_for_each_op(__op, ops)
-			print_op(vm->xe, __op);
+			print_op(xe_vm_device(vm), __op);
 
 	return ops;
 }
@@ -2783,7 +2782,7 @@ static void xe_vma_op_work_func(struct work_struct *w)
 			down_write(&vm->lock);
 			err = xe_vma_op_execute(vm, op);
 			if (err) {
-				drm_warn(&vm->xe->drm,
+				drm_warn(&xe_vm_device(vm)->drm,
 					 "Async VM op(%d) failed with %d",
 					 op->base.op, err);
 				vm_set_async_error(vm, err);
@@ -3103,7 +3102,7 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 
 			/* Rebinds may have been blocked, give worker a kick */
 			if (xe_vm_in_compute_mode(vm))
-				queue_work(vm->xe->ordered_wq,
+				queue_work(xe_vm_device(vm)->ordered_wq,
 					   &vm->preempt.rebind_work);
 		}
 
@@ -3315,7 +3314,7 @@ void xe_vm_unlock(struct xe_vm *vm, struct ww_acquire_ctx *ww)
  */
 int xe_vm_invalidate_vma(struct xe_vma *vma)
 {
-	struct xe_device *xe = xe_vma_vm(vma)->xe;
+	struct xe_device *xe = xe_vm_device(xe_vma_vm(vma));
 	struct xe_gt *gt;
 	u32 gt_needs_invalidate = 0;
 	int seqno[XE_MAX_GT];
drivers/gpu/drm/xe/xe_vm.h +10 -0
index 96e2c6b07bf8..cbbe95d6291f 100644
@@ -52,6 +52,11 @@ static inline bool xe_vm_is_closed(struct xe_vm *vm)
 struct xe_vma *
 xe_vm_find_overlapping_vma(struct xe_vm *vm, u64 start, u64 range);
 
+static inline struct xe_device *xe_vm_device(struct xe_vm *vm)
+{
+	return container_of(vm->mgr.drm, struct xe_device, drm);
+}
+
 static inline struct xe_vm *gpuva_to_vm(struct drm_gpuva *gpuva)
 {
 	return container_of(gpuva->mgr, struct xe_vm, mgr);
@@ -102,6 +107,11 @@ static inline struct xe_vm *xe_vma_vm(struct xe_vma *vma)
 	return container_of(vma->gpuva.mgr, struct xe_vm, mgr);
 }
 
+static inline struct xe_device *xe_vma_device(struct xe_vma *vma)
+{
+	return xe_vm_device(xe_vma_vm(vma));
+}
+
 static inline bool xe_vma_read_only(struct xe_vma *vma)
 {
 	return vma->gpuva.flags & XE_VMA_READ_ONLY;
drivers/gpu/drm/xe/xe_vm_types.h +0 -2
index df4797ec4d7f..fca42910dcae 100644
@@ -137,8 +137,6 @@ struct xe_vm {
 	/** @mgr: base GPUVA used to track VMAs */
 	struct drm_gpuva_manager mgr;
 
-	struct xe_device *xe;
-
 	struct kref refcount;
 
 	/* engine used for (un)binding vma's */
include/drm/drm_gpuva_mgr.h +4 -0
index 62169d850098..55b0acfdcc44 100644
@@ -169,6 +169,9 @@ static inline bool drm_gpuva_evicted(struct drm_gpuva *va)
  * There should be one manager instance per GPU virtual address space.
  */
 struct drm_gpuva_manager {
+	/** @drm: drm device */
+	struct drm_device *drm;
+
 	/**
 	 * @name: the name of the DRM GPU VA space
 	 */
@@ -204,6 +207,7 @@ struct drm_gpuva_manager {
 };
 
 void drm_gpuva_manager_init(struct drm_gpuva_manager *mgr,
+			    struct drm_device *drm,
 			    const char *name,
 			    u64 start_offset, u64 range,
 			    u64 reserve_offset, u64 reserve_range,
Signature · 1 line
2.34.1
#91 lore raw

Re: [Intel-xe] [PATCH v2 21/31] drm/gpuva: Add drm device to GPUVA manager

Quoted 1 line · Matthew Brost

This is the logical place for this, will help with upcoming changes too.

Please split the xe from the drm stuff in different patches and a bit more words of why would be better.

Quoted 380 lines
---
 drivers/gpu/drm/drm_gpuva_mgr.c  |  3 +++
 drivers/gpu/drm/xe/xe_migrate.c  | 10 +++++-----
 drivers/gpu/drm/xe/xe_pt.c       | 18 +++++++++---------
 drivers/gpu/drm/xe/xe_vm.c       | 31 +++++++++++++++----------------
 drivers/gpu/drm/xe/xe_vm.h       | 10 ++++++++++
 drivers/gpu/drm/xe/xe_vm_types.h |  2 --
 include/drm/drm_gpuva_mgr.h      |  4 ++++
 7 files changed, 46 insertions(+), 32 deletions(-)
drivers/gpu/drm/drm_gpuva_mgr.c +3 -0
index bd7d27ee44bb..137322945e91 100644
@@ -413,6 +413,7 @@ static void __drm_gpuva_remove(struct drm_gpuva *va);
 /**
  * drm_gpuva_manager_init - initialize a &drm_gpuva_manager
  * @mgr: pointer to the &drm_gpuva_manager to initialize
+ * @drm: drm device
  * @name: the name of the GPU VA space
  * @start_offset: the start offset of the GPU VA space
  * @range: the size of the GPU VA space
@@ -427,6 +428,7 @@ static void __drm_gpuva_remove(struct drm_gpuva *va);
  */
 void
 drm_gpuva_manager_init(struct drm_gpuva_manager *mgr,
+		       struct drm_device *drm,
 		       const char *name,
 		       u64 start_offset, u64 range,
 		       u64 reserve_offset, u64 reserve_range,
@@ -437,6 +439,7 @@ drm_gpuva_manager_init(struct drm_gpuva_manager *mgr,
 	mgr->mm_start = start_offset;
 	mgr->mm_range = range;
 
+	mgr->drm = drm;
 	mgr->name = name ? name : "unknown";
 	mgr->ops = ops;
 
drivers/gpu/drm/xe/xe_migrate.c +5 -5
index b44aa094a466..0a393c5772e5 100644
@@ -129,7 +129,7 @@ static u64 xe_migrate_vram_ofs(u64 addr)
 static int xe_migrate_create_cleared_bo(struct xe_migrate *m, struct xe_vm *vm)
 {
 	struct xe_gt *gt = m->gt;
-	struct xe_device *xe = vm->xe;
+	struct xe_device *xe = xe_vm_device(vm);
 	size_t cleared_size;
 	u64 vram_addr;
 	bool is_vram;
@@ -175,7 +175,7 @@ static int xe_migrate_prepare_vm(struct xe_gt *gt, struct xe_migrate *m,
 	/* Need to be sure everything fits in the first PT, or create more */
 	XE_BUG_ON(m->batch_base_ofs + batch->size >= SZ_2M);
 
-	bo = xe_bo_create_pin_map(vm->xe, m->gt, vm,
+	bo = xe_bo_create_pin_map(xe_vm_device(vm), m->gt, vm,
 				  num_entries * XE_PAGE_SIZE,
 				  ttm_bo_type_kernel,
 				  XE_BO_CREATE_VRAM_IF_DGFX(m->gt) |
@@ -1051,7 +1051,7 @@ xe_migrate_update_pgtables_cpu(struct xe_migrate *m,
 
 	if (wait_vm && !dma_resv_test_signaled(&vm->resv,
 					       DMA_RESV_USAGE_BOOKKEEP)) {
-		vm_dbg(&vm->xe->drm, "wait on VM for munmap");
+		vm_dbg(&xe_vm_device(vm)->drm, "wait on VM for munmap");
 		return ERR_PTR(-ETIME);
 	}
 
@@ -1069,7 +1069,7 @@ xe_migrate_update_pgtables_cpu(struct xe_migrate *m,
 
 	if (vm) {
 		trace_xe_vm_cpu_bind(vm);
-		xe_device_wmb(vm->xe);
+		xe_device_wmb(xe_vm_device(vm));
 	}
 
 	fence = dma_fence_get_stub();
@@ -1263,7 +1263,7 @@ xe_migrate_update_pgtables(struct xe_migrate *m,
 	 * trigger preempts before moving forward
 	 */
 	if (first_munmap_rebind) {
-		vm_dbg(&vm->xe->drm, "wait on first_munmap_rebind");
+		vm_dbg(&xe_vm_device(vm)->drm, "wait on first_munmap_rebind");
 		err = job_add_deps(job, &vm->resv,
 				   DMA_RESV_USAGE_BOOKKEEP);
 		if (err)
drivers/gpu/drm/xe/xe_pt.c +9 -9
index 8eab8e1bbaf0..4167f666d98d 100644
@@ -218,7 +218,7 @@ struct xe_pt *xe_pt_create(struct xe_vm *vm, struct xe_gt *gt,
 	if (!pt)
 		return ERR_PTR(-ENOMEM);
 
-	bo = xe_bo_create_pin_map(vm->xe, gt, vm, SZ_4K,
+	bo = xe_bo_create_pin_map(xe_vm_device(vm), gt, vm, SZ_4K,
 				  ttm_bo_type_kernel,
 				  XE_BO_CREATE_VRAM_IF_DGFX(gt) |
 				  XE_BO_CREATE_IGNORE_MIN_PAGE_SIZE_BIT |
@@ -264,11 +264,11 @@ void xe_pt_populate_empty(struct xe_gt *gt, struct xe_vm *vm,
 		 * FIXME: Some memory is allocated already allocated to zero?
 		 * Find out which memory that is and avoid this memset...
 		 */
-		xe_map_memset(vm->xe, map, 0, 0, SZ_4K);
+		xe_map_memset(xe_vm_device(vm), map, 0, 0, SZ_4K);
 	} else {
 		empty = __xe_pt_empty_pte(gt, vm, pt->level);
 		for (i = 0; i < XE_PDES; i++)
-			xe_pt_write(vm->xe, map, i, empty);
+			xe_pt_write(xe_vm_device(vm), map, i, empty);
 	}
 }
 
@@ -355,7 +355,7 @@ int xe_pt_create_scratch(struct xe_device *xe, struct xe_gt *gt,
 	if (IS_ERR(vm->scratch_bo[id]))
 		return PTR_ERR(vm->scratch_bo[id]);
 
-	xe_map_memset(vm->xe, &vm->scratch_bo[id]->vmap, 0, 0,
+	xe_map_memset(xe_vm_device(vm), &vm->scratch_bo[id]->vmap, 0, 0,
 		      vm->scratch_bo[id]->size);
 
 	for (i = 0; i < vm->pt_root[id]->level; i++) {
@@ -538,7 +538,7 @@ xe_pt_insert_entry(struct xe_pt_stage_bind_walk *xe_walk, struct xe_pt *parent,
 		if (unlikely(xe_child))
 			parent->drm.dir->entries[offset] = &xe_child->drm;
 
-		xe_pt_write(xe_walk->vm->xe, map, offset, pte);
+		xe_pt_write(xe_vm_device(xe_walk->vm), map, offset, pte);
 		parent->num_live++;
 	} else {
 		/* Shared pt. Stage update. */
@@ -1337,7 +1337,7 @@ __xe_pt_bind_vma(struct xe_gt *gt, struct xe_vma *vma, struct xe_engine *e,
 	xe_vm_assert_held(vm);
 	XE_BUG_ON(xe_gt_is_media_type(gt));
 
-	vm_dbg(&xe_vma_vm(vma)->xe->drm,
+	vm_dbg(&xe_vma_device(vma)->drm,
 	       "Preparing bind, with range [%llx...%llx) engine %p.\n",
 	       xe_vma_start(vma), xe_vma_end(vma) - 1, e);
 
@@ -1366,7 +1366,7 @@ __xe_pt_bind_vma(struct xe_gt *gt, struct xe_vma *vma, struct xe_engine *e,
 
 
 		if (last_munmap_rebind)
-			vm_dbg(&vm->xe->drm, "last_munmap_rebind");
+			vm_dbg(&xe_vm_device(vm)->drm, "last_munmap_rebind");
 
 		/* TLB invalidation must be done before signaling rebind */
 		if (rebind && !xe_vm_no_dma_fences(xe_vma_vm(vma))) {
@@ -1401,7 +1401,7 @@ __xe_pt_bind_vma(struct xe_gt *gt, struct xe_vma *vma, struct xe_engine *e,
 			xe_bo_put_commit(&deferred);
 		}
 		if (!rebind && last_munmap_rebind && xe_vm_in_compute_mode(vm))
-			queue_work(vm->xe->ordered_wq,
+			queue_work(xe_vm_device(vm)->ordered_wq,
 				   &vm->preempt.rebind_work);
 	} else {
 		kfree(ifence);
@@ -1664,7 +1664,7 @@ __xe_pt_unbind_vma(struct xe_gt *gt, struct xe_vma *vma, struct xe_engine *e,
 	xe_vm_assert_held(vm);
 	XE_BUG_ON(xe_gt_is_media_type(gt));
 
-	vm_dbg(&xe_vma_vm(vma)->xe->drm,
+	vm_dbg(&xe_vma_device(vma)->drm,
 	       "Preparing unbind, with range [%llx...%llx) engine %p.\n",
 	       xe_vma_start(vma), xe_vma_end(vma) - 1, e);
 
drivers/gpu/drm/xe/xe_vm.c +15 -16
index e8d9939ee535..688130c509a4 100644
@@ -50,7 +50,7 @@ int xe_vma_userptr_check_repin(struct xe_vma *vma)
 int xe_vma_userptr_pin_pages(struct xe_vma *vma)
 {
 	struct xe_vm *vm = xe_vma_vm(vma);
-	struct xe_device *xe = vm->xe;
+	struct xe_device *xe = xe_vm_device(vm);
 	const unsigned long num_pages = xe_vma_size(vma) >> PAGE_SHIFT;
 	struct page **pages;
 	bool in_kthread = !current->mm;
@@ -852,12 +852,12 @@ static struct xe_vma *xe_vma_create(struct xe_vm *vm,
 	if (gt_mask) {
 		vma->gt_mask = gt_mask;
 	} else {
-		for_each_gt(gt, vm->xe, id)
+		for_each_gt(gt, xe_vm_device(vm), id)
 			if (!xe_gt_is_media_type(gt))
 				vma->gt_mask |= 0x1 << id;
 	}
 
-	if (vm->xe->info.platform == XE_PVC)
+	if (xe_vm_device(vm)->info.platform == XE_PVC)
 		vma->gpuva.flags |= XE_VMA_ATOMIC_PTE_BIT;
 
 	if (bo) {
@@ -904,7 +904,7 @@ static void vm_remove_extobj(struct xe_vma *vma)
 static void xe_vma_destroy_late(struct xe_vma *vma)
 {
 	struct xe_vm *vm = xe_vma_vm(vma);
-	struct xe_device *xe = vm->xe;
+	struct xe_device *xe = xe_vm_device(vm);
 	bool read_only = xe_vma_read_only(vma);
 
 	if (xe_vma_is_userptr(vma)) {
@@ -1084,7 +1084,6 @@ struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags)
 	if (!vm)
 		return ERR_PTR(-ENOMEM);
 
-	vm->xe = xe;
 	kref_init(&vm->refcount);
 	dma_resv_init(&vm->resv);
 
@@ -1125,7 +1124,7 @@ struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags)
 	if (err)
 		goto err_put;
 
-	drm_gpuva_manager_init(&vm->mgr, "Xe VM", 0, vm->size, 0, 0,
+	drm_gpuva_manager_init(&vm->mgr, &xe->drm, "Xe VM", 0, vm->size, 0, 0,
 			       &gpuva_ops);
 	if (IS_DGFX(xe) && xe->info.vram_flags & XE_VRAM_FLAGS_NEED64K)
 		vm->flags |= XE_VM_FLAGS_64K;
@@ -1284,7 +1283,7 @@ void xe_vm_close_and_put(struct xe_vm *vm)
 {
 	struct list_head contested;
 	struct ww_acquire_ctx ww;
-	struct xe_device *xe = vm->xe;
+	struct xe_device *xe = xe_vm_device(vm);
 	struct xe_gt *gt;
 	struct xe_vma *vma, *next_vma;
 	struct drm_gpuva *gpuva;
@@ -1387,7 +1386,7 @@ static void vm_destroy_work_func(struct work_struct *w)
 	struct xe_vm *vm =
 		container_of(w, struct xe_vm, destroy_work);
 	struct ww_acquire_ctx ww;
-	struct xe_device *xe = vm->xe;
+	struct xe_device *xe = xe_vm_device(vm);
 	struct xe_gt *gt;
 	u8 id;
 	void *lookup;
@@ -1481,7 +1480,7 @@ xe_vm_unbind_vma(struct xe_vma *vma, struct xe_engine *e,
 			return ERR_PTR(-ENOMEM);
 	}
 
-	for_each_gt(gt, vm->xe, id) {
+	for_each_gt(gt, xe_vm_device(vm), id) {
 		if (!(vma->gt_present & BIT(id)))
 			goto next;
 
@@ -1555,7 +1554,7 @@ xe_vm_bind_vma(struct xe_vma *vma, struct xe_engine *e,
 			return ERR_PTR(-ENOMEM);
 	}
 
-	for_each_gt(gt, vm->xe, id) {
+	for_each_gt(gt, xe_vm_device(vm), id) {
 		if (!(vma->gt_mask & BIT(id)))
 			goto next;
 
@@ -2061,7 +2060,7 @@ static int vm_insert_extobj(struct xe_vm *vm, struct xe_vma *vma)
 static int vm_bind_ioctl_lookup_vma(struct xe_vm *vm, struct xe_bo *bo,
 				    u64 addr, u64 range, u32 op)
 {
-	struct xe_device *xe = vm->xe;
+	struct xe_device *xe = xe_vm_device(vm);
 	struct xe_vma *vma;
 	bool async = !!(op & XE_VM_BIND_FLAG_ASYNC);
 
@@ -2164,7 +2163,7 @@ vm_bind_ioctl_ops_create(struct xe_vm *vm, struct xe_bo *bo,
 
 	lockdep_assert_held_write(&vm->lock);
 
-	vm_dbg(&vm->xe->drm,
+	vm_dbg(&xe_vm_device(vm)->drm,
 	       "op=%d, addr=0x%016llx, range=0x%016llx, bo_offset_or_userptr=0x%016llx",
 	       VM_BIND_OP(operation), addr, range, bo_offset_or_userptr);
 
@@ -2232,7 +2231,7 @@ vm_bind_ioctl_ops_create(struct xe_vm *vm, struct xe_bo *bo,
 
 	if (!IS_ERR(ops))
 		drm_gpuva_for_each_op(__op, ops)
-			print_op(vm->xe, __op);
+			print_op(xe_vm_device(vm), __op);
 
 	return ops;
 }
@@ -2783,7 +2782,7 @@ static void xe_vma_op_work_func(struct work_struct *w)
 			down_write(&vm->lock);
 			err = xe_vma_op_execute(vm, op);
 			if (err) {
-				drm_warn(&vm->xe->drm,
+				drm_warn(&xe_vm_device(vm)->drm,
 					 "Async VM op(%d) failed with %d",
 					 op->base.op, err);
 				vm_set_async_error(vm, err);
@@ -3103,7 +3102,7 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 
 			/* Rebinds may have been blocked, give worker a kick */
 			if (xe_vm_in_compute_mode(vm))
-				queue_work(vm->xe->ordered_wq,
+				queue_work(xe_vm_device(vm)->ordered_wq,
 					   &vm->preempt.rebind_work);
 		}
 
@@ -3315,7 +3314,7 @@ void xe_vm_unlock(struct xe_vm *vm, struct ww_acquire_ctx *ww)
  */
 int xe_vm_invalidate_vma(struct xe_vma *vma)
 {
-	struct xe_device *xe = xe_vma_vm(vma)->xe;
+	struct xe_device *xe = xe_vm_device(xe_vma_vm(vma));
 	struct xe_gt *gt;
 	u32 gt_needs_invalidate = 0;
 	int seqno[XE_MAX_GT];
drivers/gpu/drm/xe/xe_vm.h +10 -0
index 96e2c6b07bf8..cbbe95d6291f 100644
@@ -52,6 +52,11 @@ static inline bool xe_vm_is_closed(struct xe_vm *vm)
 struct xe_vma *
 xe_vm_find_overlapping_vma(struct xe_vm *vm, u64 start, u64 range);
 
+static inline struct xe_device *xe_vm_device(struct xe_vm *vm)
+{
+	return container_of(vm->mgr.drm, struct xe_device, drm);
+}
+
 static inline struct xe_vm *gpuva_to_vm(struct drm_gpuva *gpuva)
 {
 	return container_of(gpuva->mgr, struct xe_vm, mgr);
@@ -102,6 +107,11 @@ static inline struct xe_vm *xe_vma_vm(struct xe_vma *vma)
 	return container_of(vma->gpuva.mgr, struct xe_vm, mgr);
 }
 
+static inline struct xe_device *xe_vma_device(struct xe_vma *vma)
+{
+	return xe_vm_device(xe_vma_vm(vma));
+}
+
 static inline bool xe_vma_read_only(struct xe_vma *vma)
 {
 	return vma->gpuva.flags & XE_VMA_READ_ONLY;
drivers/gpu/drm/xe/xe_vm_types.h +0 -2
index df4797ec4d7f..fca42910dcae 100644
@@ -137,8 +137,6 @@ struct xe_vm {
 	/** @mgr: base GPUVA used to track VMAs */
 	struct drm_gpuva_manager mgr;
 
-	struct xe_device *xe;
-
 	struct kref refcount;
 
 	/* engine used for (un)binding vma's */
include/drm/drm_gpuva_mgr.h +4 -0
index 62169d850098..55b0acfdcc44 100644
@@ -169,6 +169,9 @@ static inline bool drm_gpuva_evicted(struct drm_gpuva *va)
  * There should be one manager instance per GPU virtual address space.
  */
 struct drm_gpuva_manager {
+	/** @drm: drm device */
+	struct drm_device *drm;
+
 	/**
 	 * @name: the name of the DRM GPU VA space
 	 */
@@ -204,6 +207,7 @@ struct drm_gpuva_manager {
 };
 
 void drm_gpuva_manager_init(struct drm_gpuva_manager *mgr,
+			    struct drm_device *drm,
 			    const char *name,
 			    u64 start_offset, u64 range,
 			    u64 reserve_offset, u64 reserve_range,
Signature · 1 line
2.34.1
#92 lore raw

Re: [Intel-xe] [PATCH v2 21/31] drm/gpuva: Add drm device to GPUVA manager

Quoted 4 lines · Rodrigo Vivi
Quoted 1 line · Matthew Brost

This is the logical place for this, will help with upcoming changes too.

Please split the xe from the drm stuff in different patches and a bit more words of why would be better.

+1

/Thomas

author maintainer
#93 lore raw

PATCH v2 22/31 drm/gpuva: Move dma-resv to GPUVA manager

In reply to Matthew Brost

Logical place for this, will help with upcoming patches.

---
 drivers/gpu/drm/drm_gpuva_mgr.c  |  2 ++
 drivers/gpu/drm/xe/xe_bo.c       | 10 +++++-----
 drivers/gpu/drm/xe/xe_bo.h       |  2 +-
 drivers/gpu/drm/xe/xe_exec.c     |  4 ++--
 drivers/gpu/drm/xe/xe_migrate.c  |  4 ++--
 drivers/gpu/drm/xe/xe_pt.c       |  6 +++---
 drivers/gpu/drm/xe/xe_vm.c       | 34 ++++++++++++++++----------------
 drivers/gpu/drm/xe/xe_vm.h       | 12 ++++++++++-
 drivers/gpu/drm/xe/xe_vm_types.h |  6 +-----
 include/drm/drm_gpuva_mgr.h      |  6 ++++++
 10 files changed, 50 insertions(+), 36 deletions(-)
drivers/gpu/drm/drm_gpuva_mgr.c +2 -0
index 137322945e91..6d2d0f4d5018 100644
@@ -443,6 +443,8 @@ drm_gpuva_manager_init(struct drm_gpuva_manager *mgr,
 	mgr->name = name ? name : "unknown";
 	mgr->ops = ops;
 
+	dma_resv_init(&mgr->resv);
+
 	memset(&mgr->kernel_alloc_node, 0, sizeof(struct drm_gpuva));
 
 	if (reserve_range) {
drivers/gpu/drm/xe/xe_bo.c +5 -5
index a475d0584916..e0422ffb6327 100644
@@ -441,9 +441,9 @@ static int xe_bo_trigger_rebind(struct xe_device *xe, struct xe_bo *bo,
 			 * that we indeed have it locked, put the vma an the
 			 * vm's notifier.rebind_list instead and scoop later.
 			 */
-			if (dma_resv_trylock(&vm->resv))
+			if (dma_resv_trylock(xe_vm_resv(vm)))
 				vm_resv_locked = true;
-			else if (ctx->resv != &vm->resv) {
+			else if (ctx->resv != xe_vm_resv(vm)) {
 				spin_lock(&vm->notifier.list_lock);
 				list_move_tail(&vma->notifier.rebind_link,
 					       &vm->notifier.rebind_list);
@@ -456,7 +456,7 @@ static int xe_bo_trigger_rebind(struct xe_device *xe, struct xe_bo *bo,
 				list_add_tail(&vma->rebind_link, &vm->rebind_list);
 
 			if (vm_resv_locked)
-				dma_resv_unlock(&vm->resv);
+				dma_resv_unlock(xe_vm_resv(vm));
 		}
 	}
 
@@ -1240,7 +1240,7 @@ xe_bo_create_locked_range(struct xe_device *xe,
 		}
 	}
 
-	bo = __xe_bo_create_locked(xe, bo, gt, vm ? &vm->resv : NULL,
+	bo = __xe_bo_create_locked(xe, bo, gt, vm ? xe_vm_resv(vm) : NULL,
 				   vm && !xe_vm_no_dma_fences(vm) &&
 				   flags & XE_BO_CREATE_USER_BIT ?
 				   &vm->lru_bulk_move : NULL, size,
@@ -1555,7 +1555,7 @@ int xe_bo_validate(struct xe_bo *bo, struct xe_vm *vm, bool allow_res_evict)
 		xe_vm_assert_held(vm);
 
 		ctx.allow_res_evict = allow_res_evict;
-		ctx.resv = &vm->resv;
+		ctx.resv = xe_vm_resv(vm);
 	}
 
 	return ttm_bo_validate(&bo->ttm, &bo->placement, &ctx);
drivers/gpu/drm/xe/xe_bo.h +1 -1
index 81051f456874..9b401d30a130 100644
@@ -150,7 +150,7 @@ void xe_bo_unlock(struct xe_bo *bo, struct ww_acquire_ctx *ww);
 static inline void xe_bo_unlock_vm_held(struct xe_bo *bo)
 {
 	if (bo) {
-		XE_BUG_ON(bo->vm && bo->ttm.base.resv != &bo->vm->resv);
+		XE_BUG_ON(bo->vm && bo->ttm.base.resv != &bo->vm->mgr.resv);
 		if (bo->vm)
 			xe_vm_assert_held(bo->vm);
 		else
drivers/gpu/drm/xe/xe_exec.c +2 -2
index 68f876afd13c..b352fd6e1f4d 100644
@@ -327,7 +327,7 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 	/* Wait behind munmap style rebinds */
 	if (!xe_vm_no_dma_fences(vm)) {
 		err = drm_sched_job_add_resv_dependencies(&job->drm,
-							  &vm->resv,
+							  xe_vm_resv(vm),
 							  DMA_RESV_USAGE_KERNEL);
 		if (err)
 			goto err_put_job;
@@ -355,7 +355,7 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 	xe_sched_job_arm(job);
 	if (!xe_vm_no_dma_fences(vm)) {
 		/* Block userptr invalidations / BO eviction */
-		dma_resv_add_fence(&vm->resv,
+		dma_resv_add_fence(xe_vm_resv(vm),
 				   &job->drm.s_fence->finished,
 				   DMA_RESV_USAGE_BOOKKEEP);
 
drivers/gpu/drm/xe/xe_migrate.c +2 -2
index 0a393c5772e5..91a06c925a1e 100644
@@ -1049,7 +1049,7 @@ xe_migrate_update_pgtables_cpu(struct xe_migrate *m,
 					  DMA_RESV_USAGE_KERNEL))
 		return ERR_PTR(-ETIME);
 
-	if (wait_vm && !dma_resv_test_signaled(&vm->resv,
+	if (wait_vm && !dma_resv_test_signaled(xe_vm_resv(vm),
 					       DMA_RESV_USAGE_BOOKKEEP)) {
 		vm_dbg(&xe_vm_device(vm)->drm, "wait on VM for munmap");
 		return ERR_PTR(-ETIME);
@@ -1264,7 +1264,7 @@ xe_migrate_update_pgtables(struct xe_migrate *m,
 	 */
 	if (first_munmap_rebind) {
 		vm_dbg(&xe_vm_device(vm)->drm, "wait on first_munmap_rebind");
-		err = job_add_deps(job, &vm->resv,
+		err = job_add_deps(job, xe_vm_resv(vm),
 				   DMA_RESV_USAGE_BOOKKEEP);
 		if (err)
 			goto err_job;
drivers/gpu/drm/xe/xe_pt.c +3 -3
index 4167f666d98d..0f40f1950686 100644
@@ -1020,7 +1020,7 @@ static void xe_pt_commit_locks_assert(struct xe_vma *vma)
 	else if (!xe_vma_is_null(vma))
 		dma_resv_assert_held(xe_vma_bo(vma)->ttm.base.resv);
 
-	dma_resv_assert_held(&vm->resv);
+	dma_resv_assert_held(xe_vm_resv(vm));
 }
 
 static void xe_pt_commit_bind(struct xe_vma *vma,
@@ -1381,7 +1381,7 @@ __xe_pt_bind_vma(struct xe_gt *gt, struct xe_vma *vma, struct xe_engine *e,
 		}
 
 		/* add shared fence now for pagetable delayed destroy */
-		dma_resv_add_fence(&vm->resv, fence, !rebind &&
+		dma_resv_add_fence(xe_vm_resv(vm), fence, !rebind &&
 				   last_munmap_rebind ?
 				   DMA_RESV_USAGE_KERNEL :
 				   DMA_RESV_USAGE_BOOKKEEP);
@@ -1701,7 +1701,7 @@ __xe_pt_unbind_vma(struct xe_gt *gt, struct xe_vma *vma, struct xe_engine *e,
 		fence = &ifence->base.base;
 
 		/* add shared fence now for pagetable delayed destroy */
-		dma_resv_add_fence(&vm->resv, fence,
+		dma_resv_add_fence(xe_vm_resv(vm), fence,
 				   DMA_RESV_USAGE_BOOKKEEP);
 
 		/* This fence will be installed by caller when doing eviction */
drivers/gpu/drm/xe/xe_vm.c +17 -17
index 688130c509a4..8f7140501ff2 100644
@@ -307,7 +307,7 @@ static void resume_and_reinstall_preempt_fences(struct xe_vm *vm)
 	list_for_each_entry(e, &vm->preempt.engines, compute.link) {
 		e->ops->resume(e);
 
-		dma_resv_add_fence(&vm->resv, e->compute.pfence,
+		dma_resv_add_fence(xe_vm_resv(vm), e->compute.pfence,
 				   DMA_RESV_USAGE_BOOKKEEP);
 		xe_vm_fence_all_extobjs(vm, e->compute.pfence,
 					DMA_RESV_USAGE_BOOKKEEP);
@@ -345,7 +345,7 @@ int xe_vm_add_compute_engine(struct xe_vm *vm, struct xe_engine *e)
 
 	down_read(&vm->userptr.notifier_lock);
 
-	dma_resv_add_fence(&vm->resv, pfence,
+	dma_resv_add_fence(xe_vm_resv(vm), pfence,
 			   DMA_RESV_USAGE_BOOKKEEP);
 
 	xe_vm_fence_all_extobjs(vm, pfence, DMA_RESV_USAGE_BOOKKEEP);
@@ -603,7 +603,7 @@ static void preempt_rebind_work_func(struct work_struct *w)
 	}
 
 	/* Wait on munmap style VM unbinds */
-	wait = dma_resv_wait_timeout(&vm->resv,
+	wait = dma_resv_wait_timeout(xe_vm_resv(vm),
 				     DMA_RESV_USAGE_KERNEL,
 				     false, MAX_SCHEDULE_TIMEOUT);
 	if (wait <= 0) {
@@ -689,13 +689,13 @@ static bool vma_userptr_invalidate(struct mmu_interval_notifier *mni,
 	 * unbinds to complete, and those are attached as BOOKMARK fences
 	 * to the vm.
 	 */
-	dma_resv_iter_begin(&cursor, &vm->resv,
+	dma_resv_iter_begin(&cursor, xe_vm_resv(vm),
 			    DMA_RESV_USAGE_BOOKKEEP);
 	dma_resv_for_each_fence_unlocked(&cursor, fence)
 		dma_fence_enable_sw_signaling(fence);
 	dma_resv_iter_end(&cursor);
 
-	err = dma_resv_wait_timeout(&vm->resv,
+	err = dma_resv_wait_timeout(xe_vm_resv(vm),
 				    DMA_RESV_USAGE_BOOKKEEP,
 				    false, MAX_SCHEDULE_TIMEOUT);
 	XE_WARN_ON(err <= 0);
@@ -742,12 +742,12 @@ int xe_vm_userptr_pin(struct xe_vm *vm)
 	}
 
 	/* Take lock and move to rebind_list for rebinding. */
-	err = dma_resv_lock_interruptible(&vm->resv, NULL);
+	err = dma_resv_lock_interruptible(xe_vm_resv(vm), NULL);
 	if (err)
 		goto out_err;
 
 	list_splice_tail(&tmp_evict, &vm->rebind_list);
-	dma_resv_unlock(&vm->resv);
+	dma_resv_unlock(xe_vm_resv(vm));
 
 	return 0;
 
@@ -1085,7 +1085,6 @@ struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags)
 		return ERR_PTR(-ENOMEM);
 
 	kref_init(&vm->refcount);
-	dma_resv_init(&vm->resv);
 
 	vm->size = 1ull << xe_pt_shift(xe->info.vm_max_level + 1);
 
@@ -1120,12 +1119,13 @@ struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags)
 		xe_device_mem_access_get(xe);
 	}
 
-	err = dma_resv_lock_interruptible(&vm->resv, NULL);
+	drm_gpuva_manager_init(&vm->mgr, &xe->drm, "Xe VM", 0, vm->size, 0, 0,
+			       &gpuva_ops);
+
+	err = dma_resv_lock_interruptible(xe_vm_resv(vm), NULL);
 	if (err)
 		goto err_put;
 
-	drm_gpuva_manager_init(&vm->mgr, &xe->drm, "Xe VM", 0, vm->size, 0, 0,
-			       &gpuva_ops);
 	if (IS_DGFX(xe) && xe->info.vram_flags & XE_VRAM_FLAGS_NEED64K)
 		vm->flags |= XE_VM_FLAGS_64K;
 
@@ -1173,7 +1173,7 @@ struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags)
 
 		xe_pt_populate_empty(gt, vm, vm->pt_root[id]);
 	}
-	dma_resv_unlock(&vm->resv);
+	dma_resv_unlock(xe_vm_resv(vm));
 
 	/* Kernel migration VM shouldn't have a circular loop.. */
 	if (!(flags & XE_VM_FLAG_MIGRATION)) {
@@ -1230,10 +1230,10 @@ struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags)
 		if (vm->pt_root[id])
 			xe_pt_destroy(vm->pt_root[id], vm->flags, NULL);
 	}
-	dma_resv_unlock(&vm->resv);
+	dma_resv_unlock(xe_vm_resv(vm));
 	drm_gpuva_manager_destroy(&vm->mgr);
 err_put:
-	dma_resv_fini(&vm->resv);
+	dma_resv_fini(xe_vm_resv(vm));
 	kfree(vm);
 	if (!(flags & XE_VM_FLAG_MIGRATION)) {
 		xe_device_mem_access_put(xe);
@@ -1422,7 +1422,7 @@ static void vm_destroy_work_func(struct work_struct *w)
 
 	trace_xe_vm_free(vm);
 	dma_fence_put(vm->rebind_fence);
-	dma_resv_fini(&vm->resv);
+	dma_resv_fini(xe_vm_resv(vm));
 	kfree(vm);
 }
 
@@ -3298,7 +3298,7 @@ int xe_vm_lock(struct xe_vm *vm, struct ww_acquire_ctx *ww,
 
 void xe_vm_unlock(struct xe_vm *vm, struct ww_acquire_ctx *ww)
 {
-	dma_resv_unlock(&vm->resv);
+	dma_resv_unlock(xe_vm_resv(vm));
 	ww_acquire_fini(ww);
 }
 
@@ -3331,7 +3331,7 @@ int xe_vm_invalidate_vma(struct xe_vma *vma)
 			WARN_ON_ONCE(!mmu_interval_check_retry
 				     (&vma->userptr.notifier,
 				      vma->userptr.notifier_seq));
-			WARN_ON_ONCE(!dma_resv_test_signaled(&xe_vma_vm(vma)->resv,
+			WARN_ON_ONCE(!dma_resv_test_signaled(xe_vma_resv(vma),
 							     DMA_RESV_USAGE_BOOKKEEP));
 
 		} else {
drivers/gpu/drm/xe/xe_vm.h +11 -1
index cbbe95d6291f..81a9271be728 100644
@@ -57,6 +57,11 @@ static inline struct xe_device *xe_vm_device(struct xe_vm *vm)
 	return container_of(vm->mgr.drm, struct xe_device, drm);
 }
 
+static inline struct dma_resv *xe_vm_resv(struct xe_vm *vm)
+{
+	return &vm->mgr.resv;
+}
+
 static inline struct xe_vm *gpuva_to_vm(struct drm_gpuva *gpuva)
 {
 	return container_of(gpuva->mgr, struct xe_vm, mgr);
@@ -112,6 +117,11 @@ static inline struct xe_device *xe_vma_device(struct xe_vma *vma)
 	return xe_vm_device(xe_vma_vm(vma));
 }
 
+static inline struct dma_resv *xe_vma_resv(struct xe_vma *vma)
+{
+	return xe_vm_resv(xe_vma_vm(vma));
+}
+
 static inline bool xe_vma_read_only(struct xe_vma *vma)
 {
 	return vma->gpuva.flags & XE_VMA_READ_ONLY;
@@ -122,7 +132,7 @@ static inline u64 xe_vma_userptr(struct xe_vma *vma)
 	return vma->gpuva.gem.offset;
 }
 
-#define xe_vm_assert_held(vm) dma_resv_assert_held(&(vm)->resv)
+#define xe_vm_assert_held(vm) dma_resv_assert_held(&(vm)->mgr.resv)
 
 u64 xe_vm_pdp4_descriptor(struct xe_vm *vm, struct xe_gt *full_gt);
 
drivers/gpu/drm/xe/xe_vm_types.h +1 -5
index fca42910dcae..26571d171a43 100644
@@ -8,7 +8,6 @@
 
 #include <drm/drm_gpuva_mgr.h>
 
-#include <linux/dma-resv.h>
 #include <linux/kref.h>
 #include <linux/mmu_notifier.h>
 #include <linux/scatterlist.h>
@@ -131,7 +130,7 @@ struct xe_vma {
 
 struct xe_device;
 
-#define xe_vm_assert_held(vm) dma_resv_assert_held(&(vm)->resv)
+#define xe_vm_assert_held(vm) dma_resv_assert_held(&(vm)->mgr.resv)
 
 struct xe_vm {
 	/** @mgr: base GPUVA used to track VMAs */
@@ -142,9 +141,6 @@ struct xe_vm {
 	/* engine used for (un)binding vma's */
 	struct xe_engine *eng[XE_MAX_GT];
 
-	/** Protects @rebind_list and the page-table structures */
-	struct dma_resv resv;
-
 	/** @lru_bulk_move: Bulk LRU move list for this VM's BOs */
 	struct ttm_lru_bulk_move lru_bulk_move;
 
include/drm/drm_gpuva_mgr.h +6 -0
index 55b0acfdcc44..010b649e363f 100644
@@ -25,6 +25,7 @@
  * OTHER DEALINGS IN THE SOFTWARE.
  */
 
+#include <linux/dma-resv.h>
 #include <linux/maple_tree.h>
 #include <linux/mm.h>
 #include <linux/rbtree.h>
@@ -177,6 +178,11 @@ struct drm_gpuva_manager {
 	 */
 	const char *name;
 
+	/**
+	 * @resv: dma-resv for all private GEMs mapped in this address space
+	 */
+	struct dma_resv resv;
+
 	/**
 	 * @mm_start: start of the VA space
 	 */
Signature · 1 line
2.34.1
#94 lore raw

Re: [Intel-xe] [PATCH v2 22/31] drm/gpuva: Move dma-resv to GPUVA manager

Quoted 3 lines · Matthew Brost

Logical place for this, will help with upcoming patches.

This makes sense to me, but like the previuos patch please add a more elaborate commit message according to the linux patch submission guidelines, and split the drm- and xe changes when possible.

/Thomas

Quoted 385 lines
---
  drivers/gpu/drm/drm_gpuva_mgr.c  |  2 ++
  drivers/gpu/drm/xe/xe_bo.c       | 10 +++++-----
  drivers/gpu/drm/xe/xe_bo.h       |  2 +-
  drivers/gpu/drm/xe/xe_exec.c     |  4 ++--
  drivers/gpu/drm/xe/xe_migrate.c  |  4 ++--
  drivers/gpu/drm/xe/xe_pt.c       |  6 +++---
  drivers/gpu/drm/xe/xe_vm.c       | 34 ++++++++++++++++----------------
  drivers/gpu/drm/xe/xe_vm.h       | 12 ++++++++++-
  drivers/gpu/drm/xe/xe_vm_types.h |  6 +-----
  include/drm/drm_gpuva_mgr.h      |  6 ++++++
  10 files changed, 50 insertions(+), 36 deletions(-)
drivers/gpu/drm/drm_gpuva_mgr.c +2 -0
index 137322945e91..6d2d0f4d5018 100644
@@ -443,6 +443,8 @@ drm_gpuva_manager_init(struct drm_gpuva_manager *mgr,
  	mgr->name = name ? name : "unknown";
  	mgr->ops = ops;
 
+	dma_resv_init(&mgr->resv);
+
  	memset(&mgr->kernel_alloc_node, 0, sizeof(struct drm_gpuva));
 
  	if (reserve_range) {
drivers/gpu/drm/xe/xe_bo.c +5 -5
index a475d0584916..e0422ffb6327 100644
@@ -441,9 +441,9 @@ static int xe_bo_trigger_rebind(struct xe_device *xe, struct xe_bo *bo,
  			 * that we indeed have it locked, put the vma an the
  			 * vm's notifier.rebind_list instead and scoop later.
  			 */
-			if (dma_resv_trylock(&vm->resv))
+			if (dma_resv_trylock(xe_vm_resv(vm)))
  				vm_resv_locked = true;
-			else if (ctx->resv != &vm->resv) {
+			else if (ctx->resv != xe_vm_resv(vm)) {
  				spin_lock(&vm->notifier.list_lock);
  				list_move_tail(&vma->notifier.rebind_link,
  					       &vm->notifier.rebind_list);
@@ -456,7 +456,7 @@ static int xe_bo_trigger_rebind(struct xe_device *xe, struct xe_bo *bo,
  				list_add_tail(&vma->rebind_link, &vm->rebind_list);
 
  			if (vm_resv_locked)
-				dma_resv_unlock(&vm->resv);
+				dma_resv_unlock(xe_vm_resv(vm));
  		}
  	}
 
@@ -1240,7 +1240,7 @@ xe_bo_create_locked_range(struct xe_device *xe,
  		}
  	}
 
-	bo = __xe_bo_create_locked(xe, bo, gt, vm ? &vm->resv : NULL,
+	bo = __xe_bo_create_locked(xe, bo, gt, vm ? xe_vm_resv(vm) : NULL,
  				   vm && !xe_vm_no_dma_fences(vm) &&
  				   flags & XE_BO_CREATE_USER_BIT ?
  				   &vm->lru_bulk_move : NULL, size,
@@ -1555,7 +1555,7 @@ int xe_bo_validate(struct xe_bo *bo, struct xe_vm *vm, bool allow_res_evict)
  		xe_vm_assert_held(vm);
 
  		ctx.allow_res_evict = allow_res_evict;
-		ctx.resv = &vm->resv;
+		ctx.resv = xe_vm_resv(vm);
  	}
 
  	return ttm_bo_validate(&bo->ttm, &bo->placement, &ctx);
drivers/gpu/drm/xe/xe_bo.h +1 -1
index 81051f456874..9b401d30a130 100644
@@ -150,7 +150,7 @@ void xe_bo_unlock(struct xe_bo *bo, struct ww_acquire_ctx *ww);
  static inline void xe_bo_unlock_vm_held(struct xe_bo *bo)
  {
  	if (bo) {
-		XE_BUG_ON(bo->vm && bo->ttm.base.resv != &bo->vm->resv);
+		XE_BUG_ON(bo->vm && bo->ttm.base.resv != &bo->vm->mgr.resv);
  		if (bo->vm)
  			xe_vm_assert_held(bo->vm);
  		else
drivers/gpu/drm/xe/xe_exec.c +2 -2
index 68f876afd13c..b352fd6e1f4d 100644
@@ -327,7 +327,7 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
  	/* Wait behind munmap style rebinds */
  	if (!xe_vm_no_dma_fences(vm)) {
  		err = drm_sched_job_add_resv_dependencies(&job->drm,
-							  &vm->resv,
+							  xe_vm_resv(vm),
  							  DMA_RESV_USAGE_KERNEL);
  		if (err)
  			goto err_put_job;
@@ -355,7 +355,7 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
  	xe_sched_job_arm(job);
  	if (!xe_vm_no_dma_fences(vm)) {
  		/* Block userptr invalidations / BO eviction */
-		dma_resv_add_fence(&vm->resv,
+		dma_resv_add_fence(xe_vm_resv(vm),
  				   &job->drm.s_fence->finished,
  				   DMA_RESV_USAGE_BOOKKEEP);
 
drivers/gpu/drm/xe/xe_migrate.c +2 -2
index 0a393c5772e5..91a06c925a1e 100644
@@ -1049,7 +1049,7 @@ xe_migrate_update_pgtables_cpu(struct xe_migrate *m,
  					  DMA_RESV_USAGE_KERNEL))
  		return ERR_PTR(-ETIME);
 
-	if (wait_vm && !dma_resv_test_signaled(&vm->resv,
+	if (wait_vm && !dma_resv_test_signaled(xe_vm_resv(vm),
  					       DMA_RESV_USAGE_BOOKKEEP)) {
  		vm_dbg(&xe_vm_device(vm)->drm, "wait on VM for munmap");
  		return ERR_PTR(-ETIME);
@@ -1264,7 +1264,7 @@ xe_migrate_update_pgtables(struct xe_migrate *m,
  	 */
  	if (first_munmap_rebind) {
  		vm_dbg(&xe_vm_device(vm)->drm, "wait on first_munmap_rebind");
-		err = job_add_deps(job, &vm->resv,
+		err = job_add_deps(job, xe_vm_resv(vm),
  				   DMA_RESV_USAGE_BOOKKEEP);
  		if (err)
  			goto err_job;
drivers/gpu/drm/xe/xe_pt.c +3 -3
index 4167f666d98d..0f40f1950686 100644
@@ -1020,7 +1020,7 @@ static void xe_pt_commit_locks_assert(struct xe_vma *vma)
  	else if (!xe_vma_is_null(vma))
  		dma_resv_assert_held(xe_vma_bo(vma)->ttm.base.resv);
 
-	dma_resv_assert_held(&vm->resv);
+	dma_resv_assert_held(xe_vm_resv(vm));
  }
 
  static void xe_pt_commit_bind(struct xe_vma *vma,
@@ -1381,7 +1381,7 @@ __xe_pt_bind_vma(struct xe_gt *gt, struct xe_vma *vma, struct xe_engine *e,
  		}
 
  		/* add shared fence now for pagetable delayed destroy */
-		dma_resv_add_fence(&vm->resv, fence, !rebind &&
+		dma_resv_add_fence(xe_vm_resv(vm), fence, !rebind &&
  				   last_munmap_rebind ?
  				   DMA_RESV_USAGE_KERNEL :
  				   DMA_RESV_USAGE_BOOKKEEP);
@@ -1701,7 +1701,7 @@ __xe_pt_unbind_vma(struct xe_gt *gt, struct xe_vma *vma, struct xe_engine *e,
  		fence = &ifence->base.base;
 
  		/* add shared fence now for pagetable delayed destroy */
-		dma_resv_add_fence(&vm->resv, fence,
+		dma_resv_add_fence(xe_vm_resv(vm), fence,
  				   DMA_RESV_USAGE_BOOKKEEP);
 
  		/* This fence will be installed by caller when doing eviction */
drivers/gpu/drm/xe/xe_vm.c +17 -17
index 688130c509a4..8f7140501ff2 100644
@@ -307,7 +307,7 @@ static void resume_and_reinstall_preempt_fences(struct xe_vm *vm)
  	list_for_each_entry(e, &vm->preempt.engines, compute.link) {
  		e->ops->resume(e);
 
-		dma_resv_add_fence(&vm->resv, e->compute.pfence,
+		dma_resv_add_fence(xe_vm_resv(vm), e->compute.pfence,
  				   DMA_RESV_USAGE_BOOKKEEP);
  		xe_vm_fence_all_extobjs(vm, e->compute.pfence,
  					DMA_RESV_USAGE_BOOKKEEP);
@@ -345,7 +345,7 @@ int xe_vm_add_compute_engine(struct xe_vm *vm, struct xe_engine *e)
 
  	down_read(&vm->userptr.notifier_lock);
 
-	dma_resv_add_fence(&vm->resv, pfence,
+	dma_resv_add_fence(xe_vm_resv(vm), pfence,
  			   DMA_RESV_USAGE_BOOKKEEP);
 
  	xe_vm_fence_all_extobjs(vm, pfence, DMA_RESV_USAGE_BOOKKEEP);
@@ -603,7 +603,7 @@ static void preempt_rebind_work_func(struct work_struct *w)
  	}
 
  	/* Wait on munmap style VM unbinds */
-	wait = dma_resv_wait_timeout(&vm->resv,
+	wait = dma_resv_wait_timeout(xe_vm_resv(vm),
  				     DMA_RESV_USAGE_KERNEL,
  				     false, MAX_SCHEDULE_TIMEOUT);
  	if (wait <= 0) {
@@ -689,13 +689,13 @@ static bool vma_userptr_invalidate(struct mmu_interval_notifier *mni,
  	 * unbinds to complete, and those are attached as BOOKMARK fences
  	 * to the vm.
  	 */
-	dma_resv_iter_begin(&cursor, &vm->resv,
+	dma_resv_iter_begin(&cursor, xe_vm_resv(vm),
  			    DMA_RESV_USAGE_BOOKKEEP);
  	dma_resv_for_each_fence_unlocked(&cursor, fence)
  		dma_fence_enable_sw_signaling(fence);
  	dma_resv_iter_end(&cursor);
 
-	err = dma_resv_wait_timeout(&vm->resv,
+	err = dma_resv_wait_timeout(xe_vm_resv(vm),
  				    DMA_RESV_USAGE_BOOKKEEP,
  				    false, MAX_SCHEDULE_TIMEOUT);
  	XE_WARN_ON(err <= 0);
@@ -742,12 +742,12 @@ int xe_vm_userptr_pin(struct xe_vm *vm)
  	}
 
  	/* Take lock and move to rebind_list for rebinding. */
-	err = dma_resv_lock_interruptible(&vm->resv, NULL);
+	err = dma_resv_lock_interruptible(xe_vm_resv(vm), NULL);
  	if (err)
  		goto out_err;
 
  	list_splice_tail(&tmp_evict, &vm->rebind_list);
-	dma_resv_unlock(&vm->resv);
+	dma_resv_unlock(xe_vm_resv(vm));
 
  	return 0;
 
@@ -1085,7 +1085,6 @@ struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags)
  		return ERR_PTR(-ENOMEM);
 
  	kref_init(&vm->refcount);
-	dma_resv_init(&vm->resv);
 
  	vm->size = 1ull << xe_pt_shift(xe->info.vm_max_level + 1);
 
@@ -1120,12 +1119,13 @@ struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags)
  		xe_device_mem_access_get(xe);
  	}
 
-	err = dma_resv_lock_interruptible(&vm->resv, NULL);
+	drm_gpuva_manager_init(&vm->mgr, &xe->drm, "Xe VM", 0, vm->size, 0, 0,
+			       &gpuva_ops);
+
+	err = dma_resv_lock_interruptible(xe_vm_resv(vm), NULL);
  	if (err)
  		goto err_put;
 
-	drm_gpuva_manager_init(&vm->mgr, &xe->drm, "Xe VM", 0, vm->size, 0, 0,
-			       &gpuva_ops);
  	if (IS_DGFX(xe) && xe->info.vram_flags & XE_VRAM_FLAGS_NEED64K)
  		vm->flags |= XE_VM_FLAGS_64K;
 
@@ -1173,7 +1173,7 @@ struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags)
 
  		xe_pt_populate_empty(gt, vm, vm->pt_root[id]);
  	}
-	dma_resv_unlock(&vm->resv);
+	dma_resv_unlock(xe_vm_resv(vm));
 
  	/* Kernel migration VM shouldn't have a circular loop.. */
  	if (!(flags & XE_VM_FLAG_MIGRATION)) {
@@ -1230,10 +1230,10 @@ struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags)
  		if (vm->pt_root[id])
  			xe_pt_destroy(vm->pt_root[id], vm->flags, NULL);
  	}
-	dma_resv_unlock(&vm->resv);
+	dma_resv_unlock(xe_vm_resv(vm));
  	drm_gpuva_manager_destroy(&vm->mgr);
  err_put:
-	dma_resv_fini(&vm->resv);
+	dma_resv_fini(xe_vm_resv(vm));
  	kfree(vm);
  	if (!(flags & XE_VM_FLAG_MIGRATION)) {
  		xe_device_mem_access_put(xe);
@@ -1422,7 +1422,7 @@ static void vm_destroy_work_func(struct work_struct *w)
 
  	trace_xe_vm_free(vm);
  	dma_fence_put(vm->rebind_fence);
-	dma_resv_fini(&vm->resv);
+	dma_resv_fini(xe_vm_resv(vm));
  	kfree(vm);
  }
 
@@ -3298,7 +3298,7 @@ int xe_vm_lock(struct xe_vm *vm, struct ww_acquire_ctx *ww,
 
  void xe_vm_unlock(struct xe_vm *vm, struct ww_acquire_ctx *ww)
  {
-	dma_resv_unlock(&vm->resv);
+	dma_resv_unlock(xe_vm_resv(vm));
  	ww_acquire_fini(ww);
  }
 
@@ -3331,7 +3331,7 @@ int xe_vm_invalidate_vma(struct xe_vma *vma)
  			WARN_ON_ONCE(!mmu_interval_check_retry
  				     (&vma->userptr.notifier,
  				      vma->userptr.notifier_seq));
-			WARN_ON_ONCE(!dma_resv_test_signaled(&xe_vma_vm(vma)->resv,
+			WARN_ON_ONCE(!dma_resv_test_signaled(xe_vma_resv(vma),
  							     DMA_RESV_USAGE_BOOKKEEP));
 
  		} else {
drivers/gpu/drm/xe/xe_vm.h +11 -1
index cbbe95d6291f..81a9271be728 100644
@@ -57,6 +57,11 @@ static inline struct xe_device *xe_vm_device(struct xe_vm *vm)
  	return container_of(vm->mgr.drm, struct xe_device, drm);
  }
 
+static inline struct dma_resv *xe_vm_resv(struct xe_vm *vm)
+{
+	return &vm->mgr.resv;
+}
+
  static inline struct xe_vm *gpuva_to_vm(struct drm_gpuva *gpuva)
  {
  	return container_of(gpuva->mgr, struct xe_vm, mgr);
@@ -112,6 +117,11 @@ static inline struct xe_device *xe_vma_device(struct xe_vma *vma)
  	return xe_vm_device(xe_vma_vm(vma));
  }
 
+static inline struct dma_resv *xe_vma_resv(struct xe_vma *vma)
+{
+	return xe_vm_resv(xe_vma_vm(vma));
+}
+
  static inline bool xe_vma_read_only(struct xe_vma *vma)
  {
  	return vma->gpuva.flags & XE_VMA_READ_ONLY;
@@ -122,7 +132,7 @@ static inline u64 xe_vma_userptr(struct xe_vma *vma)
  	return vma->gpuva.gem.offset;
  }
 
-#define xe_vm_assert_held(vm) dma_resv_assert_held(&(vm)->resv)
+#define xe_vm_assert_held(vm) dma_resv_assert_held(&(vm)->mgr.resv)
 
  u64 xe_vm_pdp4_descriptor(struct xe_vm *vm, struct xe_gt *full_gt);
 
drivers/gpu/drm/xe/xe_vm_types.h +1 -5
index fca42910dcae..26571d171a43 100644
@@ -8,7 +8,6 @@
 
  #include <drm/drm_gpuva_mgr.h>
 
-#include <linux/dma-resv.h>
  #include <linux/kref.h>
  #include <linux/mmu_notifier.h>
  #include <linux/scatterlist.h>
@@ -131,7 +130,7 @@ struct xe_vma {
 
  struct xe_device;
 
-#define xe_vm_assert_held(vm) dma_resv_assert_held(&(vm)->resv)
+#define xe_vm_assert_held(vm) dma_resv_assert_held(&(vm)->mgr.resv)
 
  struct xe_vm {
  	/** @mgr: base GPUVA used to track VMAs */
@@ -142,9 +141,6 @@ struct xe_vm {
  	/* engine used for (un)binding vma's */
  	struct xe_engine *eng[XE_MAX_GT];
 
-	/** Protects @rebind_list and the page-table structures */
-	struct dma_resv resv;
-
  	/** @lru_bulk_move: Bulk LRU move list for this VM's BOs */
  	struct ttm_lru_bulk_move lru_bulk_move;
 
include/drm/drm_gpuva_mgr.h +6 -0
index 55b0acfdcc44..010b649e363f 100644
@@ -25,6 +25,7 @@
   * OTHER DEALINGS IN THE SOFTWARE.
   */
 
+#include <linux/dma-resv.h>
  #include <linux/maple_tree.h>
  #include <linux/mm.h>
  #include <linux/rbtree.h>
@@ -177,6 +178,11 @@ struct drm_gpuva_manager {
  	 */
  	const char *name;
 
+	/**
+	 * @resv: dma-resv for all private GEMs mapped in this address space
+	 */
+	struct dma_resv resv;
+
  	/**
  	 * @mm_start: start of the VA space
  	 */
author maintainer
#95 lore raw

PATCH v2 23/31 drm/gpuva: Add support for extobj

In reply to Matthew Brost

Manager maintains lists of GPUVA with extobjs.

---
 drivers/gpu/drm/drm_gpuva_mgr.c  | 45 +++++++++++++--
 drivers/gpu/drm/xe/xe_exec.c     | 24 ++++----
 drivers/gpu/drm/xe/xe_vm.c       | 99 +++++---------------------------
 drivers/gpu/drm/xe/xe_vm.h       |  3 -
 drivers/gpu/drm/xe/xe_vm_types.h | 16 ------
 include/drm/drm_gpuva_mgr.h      | 39 ++++++++++++-
 6 files changed, 105 insertions(+), 121 deletions(-)
drivers/gpu/drm/drm_gpuva_mgr.c +41 -4
index 6d2d0f4d5018..e8cd6e154336 100644
@@ -447,6 +447,9 @@ drm_gpuva_manager_init(struct drm_gpuva_manager *mgr,
 
 	memset(&mgr->kernel_alloc_node, 0, sizeof(struct drm_gpuva));
 
+	mgr->extobj.entries = 0;
+	INIT_LIST_HEAD(&mgr->extobj.list);
+
 	if (reserve_range) {
 		mgr->kernel_alloc_node.va.addr = reserve_offset;
 		mgr->kernel_alloc_node.va.range = reserve_range;
@@ -706,7 +709,8 @@ EXPORT_SYMBOL(drm_gpuva_remove);
  * @va: the &drm_gpuva to link
  *
  * This adds the given &va to the GPU VA list of the &drm_gem_object it is
- * associated with.
+ * associated with and to &drm_gpuva_manager.extobj.list if GPUVA maps an
+ * extobj.
  *
  * This function expects the caller to protect the GEM's GPUVA list against
  * concurrent access.
@@ -714,8 +718,14 @@ EXPORT_SYMBOL(drm_gpuva_remove);
 void
 drm_gpuva_link(struct drm_gpuva *va)
 {
-	if (likely(va->gem.obj))
+	if (likely(va->gem.obj)) {
 		list_add_tail(&va->gem.entry, &va->gem.obj->gpuva.list);
+		if (va->flags & DRM_GPUVA_EXTOBJ) {
+			list_add_tail(&va->gem.extobj_link,
+				      &va->mgr->extobj.list);
+			++va->mgr->extobj.entries;
+		}
+	}
 }
 EXPORT_SYMBOL(drm_gpuva_link);
 
@@ -724,7 +734,8 @@ EXPORT_SYMBOL(drm_gpuva_link);
  * @va: the &drm_gpuva to unlink
  *
  * This removes the given &va from the GPU VA list of the &drm_gem_object it is
- * associated with.
+ * associated with and from &drm_gpuva_manager.extobj.list if GPUVA maps an
+ * extobj.
  *
  * This function expects the caller to protect the GEM's GPUVA list against
  * concurrent access.
@@ -732,8 +743,13 @@ EXPORT_SYMBOL(drm_gpuva_link);
 void
 drm_gpuva_unlink(struct drm_gpuva *va)
 {
-	if (likely(va->gem.obj))
+	if (likely(va->gem.obj)) {
 		list_del_init(&va->gem.entry);
+		if (va->flags & DRM_GPUVA_EXTOBJ) {
+			list_del(&va->gem.extobj_link);
+			--va->mgr->extobj.entries;
+		}
+	}
 }
 EXPORT_SYMBOL(drm_gpuva_unlink);
 
@@ -871,6 +887,27 @@ drm_gpuva_interval_empty(struct drm_gpuva_manager *mgr, u64 addr, u64 range)
 }
 EXPORT_SYMBOL(drm_gpuva_interval_empty);
 
+/**
+ * drm_gpuva_add_fence - add fence to private and all extobj dma-resv
+ * @mgr: the &drm_gpuva_manager to add a fence to
+ * @fence: fence to add
+ * @private_usage: private dma-resv usage
+ * @extobj_usage: extobj dma-resv usage
+ *
+ * Returns: true if the interval is empty, false otherwise
+ */
+void drm_gpuva_add_fence(struct drm_gpuva_manager *mgr, struct dma_fence *fence,
+			 enum dma_resv_usage private_usage,
+			 enum dma_resv_usage extobj_usage)
+{
+	struct drm_gpuva *gpuva;
+
+	dma_resv_add_fence(&mgr->resv, fence, private_usage);
+	drm_gpuva_for_each_extobj(gpuva, mgr)
+		dma_resv_add_fence(gpuva->gem.obj->resv, fence, extobj_usage);
+}
+EXPORT_SYMBOL(drm_gpuva_add_fence);
+
 /**
  * drm_gpuva_map - helper to insert a &drm_gpuva from &drm_gpuva_fn_ops
  * callbacks
drivers/gpu/drm/xe/xe_exec.c +11 -13
index b352fd6e1f4d..2ae02f1500d5 100644
@@ -353,19 +353,17 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 	 * the job and let the DRM scheduler / backend clean up the job.
 	 */
 	xe_sched_job_arm(job);
-	if (!xe_vm_no_dma_fences(vm)) {
-		/* Block userptr invalidations / BO eviction */
-		dma_resv_add_fence(xe_vm_resv(vm),
-				   &job->drm.s_fence->finished,
-				   DMA_RESV_USAGE_BOOKKEEP);
-
-		/*
-		 * Make implicit sync work across drivers, assuming all external
-		 * BOs are written as we don't pass in a read / write list.
-		 */
-		xe_vm_fence_all_extobjs(vm, &job->drm.s_fence->finished,
-					DMA_RESV_USAGE_WRITE);
-	}
+
+	/*
+	 * Block userptr invalidations / BO eviction
+	 *
+	 * Make implicit sync work across drivers, assuming all external BOss
+	 * are written as we don't pass in a read / write list.
+	 */
+	if (!xe_vm_no_dma_fences(vm))
+		drm_gpuva_add_fence(&vm->mgr, &job->drm.s_fence->finished,
+				    DMA_RESV_USAGE_BOOKKEEP,
+				    DMA_RESV_USAGE_WRITE);
 
 	for (i = 0; i < num_syncs; i++)
 		xe_sync_entry_signal(&syncs[i], job,
drivers/gpu/drm/xe/xe_vm.c +15 -84

187 lines not on this page · raw message

drivers/gpu/drm/xe/xe_vm.h +0 -3
index 81a9271be728..12de652d8d1c 100644
@@ -232,9 +232,6 @@ void xe_vm_unlock_dma_resv(struct xe_vm *vm,
 			   struct ww_acquire_ctx *ww,
 			   struct list_head *objs);
 
-void xe_vm_fence_all_extobjs(struct xe_vm *vm, struct dma_fence *fence,
-			     enum dma_resv_usage usage);
-
 int xe_analyze_vm(struct drm_printer *p, struct xe_vm *vm, int gt_id);
 
 #if IS_ENABLED(CONFIG_DRM_XE_DEBUG_VM)
drivers/gpu/drm/xe/xe_vm_types.h +0 -16
index 26571d171a43..0b59bde3bc4e 100644
@@ -113,14 +113,6 @@ struct xe_vma {
 		u8 gt_invalidated;
 	} usm;
 
-	struct {
-		/**
-		 * @extobj.link: Link into vm's external object list.
-		 * protected by the vm lock.
-		 */
-		struct list_head link;
-	} extobj;
-
 	/**
 	 * @userptr: user pointer state, only allocated for VMAs that are
 	 * user pointers
@@ -189,14 +181,6 @@ struct xe_vm {
 	 */
 	struct work_struct destroy_work;
 
-	/** @extobj: bookkeeping for external objects. Protected by the vm lock */
-	struct {
-		/** @enties: number of external BOs attached this VM */
-		u32 entries;
-		/** @list: list of vmas with external bos attached */
-		struct list_head list;
-	} extobj;
-
 	/** @async_ops: async VM operations (bind / unbinds) */
 	struct {
 		/** @list: list of pending async VM ops */
include/drm/drm_gpuva_mgr.h +38 -1
index 010b649e363f..57861a7ed504 100644
@@ -54,10 +54,18 @@ enum drm_gpuva_flags {
 	 */
 	DRM_GPUVA_SPARSE = (1 << 1),
 
+	/**
+	 * @DRM_GPUVA_EXTOBJ:
+	 *
+	 * Flag indicating that the &drm_gpuva is a mapping of an extobj (GEN
+	 * not tied to a single address space).
+	 */
+	DRM_GPUVA_EXTOBJ = (1 << 2),
+
 	/**
 	 * @DRM_GPUVA_USERBITS: user defined bits
 	 */
-	DRM_GPUVA_USERBITS = (1 << 2),
+	DRM_GPUVA_USERBITS = (1 << 3),
 };
 
 /**
@@ -112,6 +120,12 @@ struct drm_gpuva {
 		 * @entry: the &list_head to attach this object to a &drm_gem_object
 		 */
 		struct list_head entry;
+
+		/**
+		 * @extobj_link: the &list_head to attach this object to a
+		 * @drm_gpuva_manager.extobj.list
+		 */
+		struct list_head extobj_link;
 	} gem;
 };
 
@@ -134,6 +148,10 @@ struct drm_gpuva *drm_gpuva_find_next(struct drm_gpuva_manager *mgr, u64 end);
 
 bool drm_gpuva_interval_empty(struct drm_gpuva_manager *mgr, u64 addr, u64 range);
 
+void drm_gpuva_add_fence(struct drm_gpuva_manager *mgr, struct dma_fence *fence,
+			 enum dma_resv_usage private_usage,
+			 enum dma_resv_usage extobj_usage);
+
 /**
  * drm_gpuva_evict - sets whether the backing GEM of this &drm_gpuva is evicted
  * @va: the &drm_gpuva to set the evict flag for
@@ -206,6 +224,17 @@ struct drm_gpuva_manager {
 	 */
 	struct drm_gpuva kernel_alloc_node;
 
+	/** @extobj: bookkeeping for external GEMs */
+	struct {
+		/**
+		 * @entries: number of external GEMs attached this address
+		 * space
+		 */
+		u32 entries;
+		/** @list: list of GPUVAs with external GEMs attached */
+		struct list_head list;
+	} extobj;
+
 	/**
 	 * @ops: &drm_gpuva_fn_ops providing the split/merge steps to drivers
 	 */
@@ -509,6 +538,14 @@ struct drm_gpuva_ops {
 	struct list_head list;
 };
 
+/**
+ * drm_gpuva_for_each_op - iterator to walk over &drm_gpuva of extobjs
+ * @va: &drm_gpuva to assign in each iteration step
+ * @mgr: &drm_gpuva_manager to walk extobj lisy
+ */
+#define drm_gpuva_for_each_extobj(va, mgr) \
+	list_for_each_entry(va, &(mgr)->extobj.list, gem.extobj_link)
+
 /**
  * drm_gpuva_for_each_op - iterator to walk over &drm_gpuva_ops
  * @op: &drm_gpuva_op to assign in each iteration step
Signature · 1 line
2.34.1
#96 lore raw

Re: [Intel-xe] [PATCH v2 23/31] drm/gpuva: Add support for extobj

Quoted 11 lines · Matthew Brost

Manager maintains lists of GPUVA with extobjs.

---
  drivers/gpu/drm/drm_gpuva_mgr.c  | 45 +++++++++++++--
  drivers/gpu/drm/xe/xe_exec.c     | 24 ++++----
  drivers/gpu/drm/xe/xe_vm.c       | 99 +++++---------------------------
  drivers/gpu/drm/xe/xe_vm.h       |  3 -
  drivers/gpu/drm/xe/xe_vm_types.h | 16 ------
  include/drm/drm_gpuva_mgr.h      | 39 ++++++++++++-
  6 files changed, 105 insertions(+), 121 deletions(-)

Please make a separate series with elaborate commit message and if possible, split the drm and xe parts.

Also it seems the handling of multiple vmas in a single vm pointing to the same extobj.

There is a bug in xe that I introduced that also forgets about that, but IIRC only on vma removal.

/Thomas

author maintainer
#97 lore raw

PATCH v2 24/31 drm/xe: Userptr refactor

In reply to Matthew Brost

Add GPUVA userptr flag, add GPUVA userptr sub-struct, and drop sg pointer. A larger follow on cleanup may push more of userptr implementation to GPUVA.

---
 drivers/gpu/drm/xe/xe_pt.c       |  6 +--
 drivers/gpu/drm/xe/xe_vm.c       | 41 +++++++++++----------
 drivers/gpu/drm/xe/xe_vm.h       | 23 +++++++-----
 drivers/gpu/drm/xe/xe_vm_types.h | 20 +++++-----
 include/drm/drm_gpuva_mgr.h      | 63 +++++++++++++++++++++-----------
 5 files changed, 89 insertions(+), 64 deletions(-)
drivers/gpu/drm/xe/xe_pt.c +3 -3
index 0f40f1950686..964baa24eba3 100644
@@ -92,8 +92,8 @@ static dma_addr_t vma_addr(struct xe_vma *vma, u64 offset,
 		page = offset >> PAGE_SHIFT;
 		offset &= (PAGE_SIZE - 1);
 
-		xe_res_first_sg(vma->userptr.sg, page << PAGE_SHIFT, page_size,
-				&cur);
+		xe_res_first_sg(&vma->userptr.sgt, page << PAGE_SHIFT,
+				page_size, &cur);
 		return xe_res_dma(&cur) + offset;
 	} else {
 		return xe_bo_addr(xe_vma_bo(vma), offset, page_size, is_vram);
@@ -813,7 +813,7 @@ xe_pt_stage_bind(struct xe_gt *gt, struct xe_vma *vma,
 	xe_bo_assert_held(bo);
 	if (!xe_vma_is_null(vma)) {
 		if (xe_vma_is_userptr(vma))
-			xe_res_first_sg(vma->userptr.sg, 0, xe_vma_size(vma),
+			xe_res_first_sg(&vma->userptr.sgt, 0, xe_vma_size(vma),
 					&curs);
 		else if (xe_bo_is_vram(bo) || xe_bo_is_stolen(bo))
 			xe_res_first(bo->ttm.resource, xe_vma_bo_offset(vma),
drivers/gpu/drm/xe/xe_vm.c +21 -20

115 lines not on this page · raw message

drivers/gpu/drm/xe/xe_vm.h +14 -9
index 12de652d8d1c..f279fa622260 100644
@@ -101,12 +101,6 @@ static inline u64 xe_vma_bo_offset(struct xe_vma *vma)
 	return vma->gpuva.gem.offset;
 }
 
-static inline struct xe_bo *xe_vma_bo(struct xe_vma *vma)
-{
-	return !vma->gpuva.gem.obj ? NULL :
-		container_of(vma->gpuva.gem.obj, struct xe_bo, ttm.base);
-}
-
 static inline struct xe_vm *xe_vma_vm(struct xe_vma *vma)
 {
 	return container_of(vma->gpuva.mgr, struct xe_vm, mgr);
@@ -129,7 +123,7 @@ static inline bool xe_vma_read_only(struct xe_vma *vma)
 
 static inline u64 xe_vma_userptr(struct xe_vma *vma)
 {
-	return vma->gpuva.gem.offset;
+	return vma->gpuva.userptr.address;
 }
 
 #define xe_vm_assert_held(vm) dma_resv_assert_held(&(vm)->mgr.resv)
@@ -197,12 +191,18 @@ static inline void xe_vm_reactivate_rebind(struct xe_vm *vm)
 
 static inline bool xe_vma_is_null(struct xe_vma *vma)
 {
-	return vma->gpuva.flags & XE_VMA_NULL;
+	return vma->gpuva.flags & DRM_GPUVA_SPARSE;
 }
 
 static inline bool xe_vma_is_userptr(struct xe_vma *vma)
 {
-	return !xe_vma_bo(vma) && !xe_vma_is_null(vma);
+	return vma->gpuva.flags & DRM_GPUVA_USERPTR;
+}
+
+static inline struct xe_bo *xe_vma_bo(struct xe_vma *vma)
+{
+	return xe_vma_is_null(vma) || xe_vma_is_userptr(vma) ? NULL :
+		container_of(vma->gpuva.gem.obj, struct xe_bo, ttm.base);
 }
 
 static inline bool xe_vma_has_no_bo(struct xe_vma *vma)
@@ -210,6 +210,11 @@ static inline bool xe_vma_has_no_bo(struct xe_vma *vma)
 	return !xe_vma_bo(vma);
 }
 
+static inline bool xe_vma_userptr_sg_mapped(struct xe_vma *vma)
+{
+	return vma->gpuva.flags & XE_VMA_USERPTR_SG_MAPPED;
+}
+
 int xe_vma_userptr_pin_pages(struct xe_vma *vma);
 
 int xe_vma_userptr_check_repin(struct xe_vma *vma);
drivers/gpu/drm/xe/xe_vm_types.h +9 -11
index 0b59bde3bc4e..ce1260b8d3ef 100644
@@ -23,15 +23,15 @@ struct xe_vm;
 #define TEST_VM_ASYNC_OPS_ERROR
 #define FORCE_ASYNC_OP_ERROR	BIT(31)
 
-#define XE_VMA_READ_ONLY	DRM_GPUVA_USERBITS
-#define XE_VMA_DESTROYED	(DRM_GPUVA_USERBITS << 1)
-#define XE_VMA_ATOMIC_PTE_BIT	(DRM_GPUVA_USERBITS << 2)
-#define XE_VMA_FIRST_REBIND	(DRM_GPUVA_USERBITS << 3)
-#define XE_VMA_LAST_REBIND	(DRM_GPUVA_USERBITS << 4)
-#define XE_VMA_NULL		(DRM_GPUVA_USERBITS << 5)
-#define XE_VMA_PTE_4K		(DRM_GPUVA_USERBITS << 6)
-#define XE_VMA_PTE_2M		(DRM_GPUVA_USERBITS << 7)
-#define XE_VMA_PTE_1G		(DRM_GPUVA_USERBITS << 8)
+#define XE_VMA_READ_ONLY		DRM_GPUVA_USERBITS
+#define XE_VMA_DESTROYED		(DRM_GPUVA_USERBITS << 1)
+#define XE_VMA_ATOMIC_PTE_BIT		(DRM_GPUVA_USERBITS << 2)
+#define XE_VMA_FIRST_REBIND		(DRM_GPUVA_USERBITS << 3)
+#define XE_VMA_LAST_REBIND		(DRM_GPUVA_USERBITS << 4)
+#define XE_VMA_USERPTR_SG_MAPPED	(DRM_GPUVA_USERBITS << 5)
+#define XE_VMA_PTE_4K			(DRM_GPUVA_USERBITS << 6)
+#define XE_VMA_PTE_2M			(DRM_GPUVA_USERBITS << 7)
+#define XE_VMA_PTE_1G			(DRM_GPUVA_USERBITS << 8)
 
 /** struct xe_userptr - User pointer */
 struct xe_userptr {
@@ -41,8 +41,6 @@ struct xe_userptr {
 	struct mmu_interval_notifier notifier;
 	/** @sgt: storage for a scatter gather table */
 	struct sg_table sgt;
-	/** @sg: allocated scatter gather table */
-	struct sg_table *sg;
 	/** @notifier_seq: notifier sequence number */
 	unsigned long notifier_seq;
 	/**
include/drm/drm_gpuva_mgr.h +42 -21

83 lines not on this page · raw message

Signature · 1 line
2.34.1
#98 lore raw

Re: [Intel-xe] [PATCH v2 24/31] drm/xe: Userptr refactor

Quoted 3 lines · Matthew Brost

Add GPUVA userptr flag, add GPUVA userptr sub-struct, and drop sg pointer. A larger follow on cleanup may push more of userptr implementation to GPUVA.

here as well, please have xe and drm changes in separated patches. But the final result looks good....

Quoted 351 lines
---
 drivers/gpu/drm/xe/xe_pt.c       |  6 +--
 drivers/gpu/drm/xe/xe_vm.c       | 41 +++++++++++----------
 drivers/gpu/drm/xe/xe_vm.h       | 23 +++++++-----
 drivers/gpu/drm/xe/xe_vm_types.h | 20 +++++-----
 include/drm/drm_gpuva_mgr.h      | 63 +++++++++++++++++++++-----------
 5 files changed, 89 insertions(+), 64 deletions(-)
drivers/gpu/drm/xe/xe_pt.c +3 -3
index 0f40f1950686..964baa24eba3 100644
@@ -92,8 +92,8 @@ static dma_addr_t vma_addr(struct xe_vma *vma, u64 offset,
 		page = offset >> PAGE_SHIFT;
 		offset &= (PAGE_SIZE - 1);
 
-		xe_res_first_sg(vma->userptr.sg, page << PAGE_SHIFT, page_size,
-				&cur);
+		xe_res_first_sg(&vma->userptr.sgt, page << PAGE_SHIFT,
+				page_size, &cur);
 		return xe_res_dma(&cur) + offset;
 	} else {
 		return xe_bo_addr(xe_vma_bo(vma), offset, page_size, is_vram);
@@ -813,7 +813,7 @@ xe_pt_stage_bind(struct xe_gt *gt, struct xe_vma *vma,
 	xe_bo_assert_held(bo);
 	if (!xe_vma_is_null(vma)) {
 		if (xe_vma_is_userptr(vma))
-			xe_res_first_sg(vma->userptr.sg, 0, xe_vma_size(vma),
+			xe_res_first_sg(&vma->userptr.sgt, 0, xe_vma_size(vma),
 					&curs);
 		else if (xe_bo_is_vram(bo) || xe_bo_is_stolen(bo))
 			xe_res_first(bo->ttm.resource, xe_vma_bo_offset(vma),
drivers/gpu/drm/xe/xe_vm.c +21 -20
index 336e21c710a5..4d734ec4d6ab 100644
@@ -73,13 +73,13 @@ int xe_vma_userptr_pin_pages(struct xe_vma *vma)
 	if (!pages)
 		return -ENOMEM;
 
-	if (vma->userptr.sg) {
+	if (xe_vma_userptr_sg_mapped(vma)) {
 		dma_unmap_sgtable(xe->drm.dev,
-				  vma->userptr.sg,
+				  &vma->userptr.sgt,
 				  read_only ? DMA_TO_DEVICE :
 				  DMA_BIDIRECTIONAL, 0);
-		sg_free_table(vma->userptr.sg);
-		vma->userptr.sg = NULL;
+		sg_free_table(&vma->userptr.sgt);
+		vma->gpuva.flags &= ~XE_VMA_USERPTR_SG_MAPPED;
 	}
 
 	pinned = ret = 0;
@@ -119,19 +119,19 @@ int xe_vma_userptr_pin_pages(struct xe_vma *vma)
 					0, (u64)pinned << PAGE_SHIFT,
 					GFP_KERNEL);
 	if (ret) {
-		vma->userptr.sg = NULL;
+		vma->gpuva.flags &= ~XE_VMA_USERPTR_SG_MAPPED;
 		goto out;
 	}
-	vma->userptr.sg = &vma->userptr.sgt;
+	vma->gpuva.flags |= XE_VMA_USERPTR_SG_MAPPED;
 
-	ret = dma_map_sgtable(xe->drm.dev, vma->userptr.sg,
+	ret = dma_map_sgtable(xe->drm.dev, &vma->userptr.sgt,
 			      read_only ? DMA_TO_DEVICE :
 			      DMA_BIDIRECTIONAL,
 			      DMA_ATTR_SKIP_CPU_SYNC |
 			      DMA_ATTR_NO_KERNEL_MAPPING);
 	if (ret) {
-		sg_free_table(vma->userptr.sg);
-		vma->userptr.sg = NULL;
+		sg_free_table(&vma->userptr.sgt);
+		vma->gpuva.flags &= ~XE_VMA_USERPTR_SG_MAPPED;
 		goto out;
 	}
 
@@ -820,15 +820,13 @@ static struct xe_vma *xe_vma_create(struct xe_vm *vm,
 	 */
 	INIT_LIST_HEAD(&vma->rebind_link);
 
-	INIT_LIST_HEAD(&vma->gpuva.gem.entry);
-	INIT_LIST_HEAD(&vma->gpuva.gem.extobj_link);
 	vma->gpuva.mgr = &vm->mgr;
 	vma->gpuva.va.addr = start;
 	vma->gpuva.va.range = end - start + 1;
 	if (read_only)
 		vma->gpuva.flags |= XE_VMA_READ_ONLY;
 	if (null)
-		vma->gpuva.flags |= XE_VMA_NULL;
+		vma->gpuva.flags |= DRM_GPUVA_SPARSE;
 
 	if (gt_mask) {
 		vma->gt_mask = gt_mask;
@@ -845,6 +843,8 @@ static struct xe_vma *xe_vma_create(struct xe_vm *vm,
 		xe_bo_assert_held(bo);
 
 		drm_gem_object_get(&bo->ttm.base);
+		INIT_LIST_HEAD(&vma->gpuva.gem.entry);
+		INIT_LIST_HEAD(&vma->gpuva.gem.extobj_link);
 		vma->gpuva.gem.obj = &bo->ttm.base;
 		vma->gpuva.gem.offset = bo_offset_or_userptr;
 		if (!bo->vm)
@@ -855,7 +855,8 @@ static struct xe_vma *xe_vma_create(struct xe_vm *vm,
 			u64 size = end - start + 1;
 			int err;
 
-			vma->gpuva.gem.offset = bo_offset_or_userptr;
+			vma->gpuva.flags |= DRM_GPUVA_USERPTR;
+			vma->gpuva.userptr.address= bo_offset_or_userptr;
 			err = mmu_interval_notifier_insert(&vma->userptr.notifier,
 							   current->mm,
 							   xe_vma_userptr(vma),
@@ -883,13 +884,13 @@ static void xe_vma_destroy_late(struct xe_vma *vma)
 	bool read_only = xe_vma_read_only(vma);
 
 	if (xe_vma_is_userptr(vma)) {
-		if (vma->userptr.sg) {
+		if (xe_vma_userptr_sg_mapped(vma)) {
 			dma_unmap_sgtable(xe->drm.dev,
-					  vma->userptr.sg,
+					  &vma->userptr.sgt,
 					  read_only ? DMA_TO_DEVICE :
 					  DMA_BIDIRECTIONAL, 0);
-			sg_free_table(vma->userptr.sg);
-			vma->userptr.sg = NULL;
+			sg_free_table(&vma->userptr.sgt);
+			vma->gpuva.flags &= ~XE_VMA_USERPTR_SG_MAPPED;
 		}
 
 		/*
@@ -2309,7 +2310,7 @@ static int vm_bind_ioctl_ops_parse(struct xe_vm *vm, struct xe_engine *e,
 						XE_VMA_READ_ONLY;
 					bool null =
 						op->base.remap.unmap->va->flags &
-						XE_VMA_NULL;
+						DRM_GPUVA_SPARSE;
 
 					vma = new_vma(vm, op->base.remap.prev,
 						      op->gt_mask, read_only,
@@ -2344,7 +2345,7 @@ static int vm_bind_ioctl_ops_parse(struct xe_vm *vm, struct xe_engine *e,
 
 					bool null =
 						op->base.remap.unmap->va->flags &
-						XE_VMA_NULL;
+						DRM_GPUVA_SPARSE;
 
 					vma = new_vma(vm, op->base.remap.next,
 						      op->gt_mask, read_only,
@@ -3320,7 +3321,7 @@ int xe_analyze_vm(struct drm_printer *p, struct xe_vm *vm, int gt_id)
 		} else if (is_userptr) {
 			struct xe_res_cursor cur;
 
-			xe_res_first_sg(vma->userptr.sg, 0, XE_PAGE_SIZE, &cur);
+			xe_res_first_sg(&vma->userptr.sgt, 0, XE_PAGE_SIZE, &cur);
 			addr = xe_res_dma(&cur);
 		} else {
 			addr = xe_bo_addr(xe_vma_bo(vma), 0, XE_PAGE_SIZE, &is_vram);
drivers/gpu/drm/xe/xe_vm.h +14 -9
index 12de652d8d1c..f279fa622260 100644
@@ -101,12 +101,6 @@ static inline u64 xe_vma_bo_offset(struct xe_vma *vma)
 	return vma->gpuva.gem.offset;
 }
 
-static inline struct xe_bo *xe_vma_bo(struct xe_vma *vma)
-{
-	return !vma->gpuva.gem.obj ? NULL :
-		container_of(vma->gpuva.gem.obj, struct xe_bo, ttm.base);
-}
-
 static inline struct xe_vm *xe_vma_vm(struct xe_vma *vma)
 {
 	return container_of(vma->gpuva.mgr, struct xe_vm, mgr);
@@ -129,7 +123,7 @@ static inline bool xe_vma_read_only(struct xe_vma *vma)
 
 static inline u64 xe_vma_userptr(struct xe_vma *vma)
 {
-	return vma->gpuva.gem.offset;
+	return vma->gpuva.userptr.address;
 }
 
 #define xe_vm_assert_held(vm) dma_resv_assert_held(&(vm)->mgr.resv)
@@ -197,12 +191,18 @@ static inline void xe_vm_reactivate_rebind(struct xe_vm *vm)
 
 static inline bool xe_vma_is_null(struct xe_vma *vma)
 {
-	return vma->gpuva.flags & XE_VMA_NULL;
+	return vma->gpuva.flags & DRM_GPUVA_SPARSE;
 }
 
 static inline bool xe_vma_is_userptr(struct xe_vma *vma)
 {
-	return !xe_vma_bo(vma) && !xe_vma_is_null(vma);
+	return vma->gpuva.flags & DRM_GPUVA_USERPTR;
+}
+
+static inline struct xe_bo *xe_vma_bo(struct xe_vma *vma)
+{
+	return xe_vma_is_null(vma) || xe_vma_is_userptr(vma) ? NULL :
+		container_of(vma->gpuva.gem.obj, struct xe_bo, ttm.base);
 }
 
 static inline bool xe_vma_has_no_bo(struct xe_vma *vma)
@@ -210,6 +210,11 @@ static inline bool xe_vma_has_no_bo(struct xe_vma *vma)
 	return !xe_vma_bo(vma);
 }
 
+static inline bool xe_vma_userptr_sg_mapped(struct xe_vma *vma)
+{
+	return vma->gpuva.flags & XE_VMA_USERPTR_SG_MAPPED;
+}
+
 int xe_vma_userptr_pin_pages(struct xe_vma *vma);
 
 int xe_vma_userptr_check_repin(struct xe_vma *vma);
drivers/gpu/drm/xe/xe_vm_types.h +9 -11
index 0b59bde3bc4e..ce1260b8d3ef 100644
@@ -23,15 +23,15 @@ struct xe_vm;
 #define TEST_VM_ASYNC_OPS_ERROR
 #define FORCE_ASYNC_OP_ERROR	BIT(31)
 
-#define XE_VMA_READ_ONLY	DRM_GPUVA_USERBITS
-#define XE_VMA_DESTROYED	(DRM_GPUVA_USERBITS << 1)
-#define XE_VMA_ATOMIC_PTE_BIT	(DRM_GPUVA_USERBITS << 2)
-#define XE_VMA_FIRST_REBIND	(DRM_GPUVA_USERBITS << 3)
-#define XE_VMA_LAST_REBIND	(DRM_GPUVA_USERBITS << 4)
-#define XE_VMA_NULL		(DRM_GPUVA_USERBITS << 5)
-#define XE_VMA_PTE_4K		(DRM_GPUVA_USERBITS << 6)
-#define XE_VMA_PTE_2M		(DRM_GPUVA_USERBITS << 7)
-#define XE_VMA_PTE_1G		(DRM_GPUVA_USERBITS << 8)
+#define XE_VMA_READ_ONLY		DRM_GPUVA_USERBITS
+#define XE_VMA_DESTROYED		(DRM_GPUVA_USERBITS << 1)
+#define XE_VMA_ATOMIC_PTE_BIT		(DRM_GPUVA_USERBITS << 2)
+#define XE_VMA_FIRST_REBIND		(DRM_GPUVA_USERBITS << 3)
+#define XE_VMA_LAST_REBIND		(DRM_GPUVA_USERBITS << 4)
+#define XE_VMA_USERPTR_SG_MAPPED	(DRM_GPUVA_USERBITS << 5)
+#define XE_VMA_PTE_4K			(DRM_GPUVA_USERBITS << 6)
+#define XE_VMA_PTE_2M			(DRM_GPUVA_USERBITS << 7)
+#define XE_VMA_PTE_1G			(DRM_GPUVA_USERBITS << 8)
 
 /** struct xe_userptr - User pointer */
 struct xe_userptr {
@@ -41,8 +41,6 @@ struct xe_userptr {
 	struct mmu_interval_notifier notifier;
 	/** @sgt: storage for a scatter gather table */
 	struct sg_table sgt;
-	/** @sg: allocated scatter gather table */
-	struct sg_table *sg;
 	/** @notifier_seq: notifier sequence number */
 	unsigned long notifier_seq;
 	/**
include/drm/drm_gpuva_mgr.h +42 -21
index 57861a7ed504..943c8fcda533 100644
@@ -62,10 +62,17 @@ enum drm_gpuva_flags {
 	 */
 	DRM_GPUVA_EXTOBJ = (1 << 2),
 
+	/**
+	 * @DRM_GPUVA_USERPTR:
+	 *
+	 * Flag indicating that the &drm_gpuva is a user pointer mapping.
+	 */
+	DRM_GPUVA_USERPTR = (1 << 3),
+
 	/**
 	 * @DRM_GPUVA_USERBITS: user defined bits
 	 */
-	DRM_GPUVA_USERBITS = (1 << 3),
+	DRM_GPUVA_USERBITS = (1 << 4),
 };
 
 /**
@@ -102,31 +109,45 @@ struct drm_gpuva {
 		u64 range;
 	} va;
 
-	/**
-	 * @gem: structure containing the &drm_gem_object and it's offset
-	 */
-	struct {
-		/**
-		 * @offset: the offset within the &drm_gem_object
-		 */
-		u64 offset;
-
-		/**
-		 * @obj: the mapped &drm_gem_object
-		 */
-		struct drm_gem_object *obj;
-
+	union {
 		/**
-		 * @entry: the &list_head to attach this object to a &drm_gem_object
+		 * @gem: structure containing the &drm_gem_object and it's
+		 * offset
 		 */
-		struct list_head entry;
+		struct {
+			/**
+			 * @offset: the offset within the &drm_gem_object
+			 */
+			u64 offset;
+
+			/**
+			 * @obj: the mapped &drm_gem_object
+			 */
+			struct drm_gem_object *obj;
+
+			/**
+			 * @entry: the &list_head to attach this object to a
+			 * &drm_gem_object
+			 */
+			struct list_head entry;
+
+			/**
+			 * @extobj_link: the &list_head to attach this object to
+			 * a @drm_gpuva_manager.extobj.list
+			 */
+			struct list_head extobj_link;
+		} gem;
 
 		/**
-		 * @extobj_link: the &list_head to attach this object to a
-		 * @drm_gpuva_manager.extobj.list
+		 * @userptr: structure containing user pointer state
 		 */
-		struct list_head extobj_link;
-	} gem;
+		struct {
+			/**
+			 * @address: user pointer address
+			 */
+			u64 address;
+		} userptr;
+	};
 };
 
 void drm_gpuva_link(struct drm_gpuva *va);
Signature · 1 line
2.34.1
#99 lore raw

Re: [Intel-xe] [PATCH v2 24/31] drm/xe: Userptr refactor

In reply to Matthew Brost

Hi, Matthew

In addition to Rodrigo's comments:

Quoted 4 lines · Matthew Brost

Add GPUVA userptr flag, add GPUVA userptr sub-struct,

and drop sg
pointer.

These are unrelated, right? If so, separate patch?

Thanks,

Thomas

author maintainer
#100 lore raw

PATCH v2 25/31 drm: execution context for GEM buffers v3

In reply to Matthew Brost

From: Christian König <[email protected]>

This adds the infrastructure for an execution context for GEM buffers which is similar to the existinc TTMs execbuf util and intended to replace it in the long term.

The basic functionality is that we abstracts the necessary loop to lock many different GEM buffers with automated deadlock and duplicate handling.

v2: drop xarray and use dynamic resized array instead, the locking
overhead is unecessary and measureable.
v3: drop duplicate tracking, radeon is really the only one needing that.

---
 Documentation/gpu/drm-mm.rst |  12 ++
 drivers/gpu/drm/Kconfig      |   6 +
 drivers/gpu/drm/Makefile     |   2 +
 drivers/gpu/drm/drm_exec.c   | 248 +++++++++++++++++++++++++++++++++++
 include/drm/drm_exec.h       | 115 ++++++++++++++++
 5 files changed, 383 insertions(+)
 create mode 100644 drivers/gpu/drm/drm_exec.c
 create mode 100644 include/drm/drm_exec.h
Documentation/gpu/drm-mm.rst +12 -0
index fe40ee686f6e..c9f120cfe730 100644
@@ -524,6 +524,18 @@ DRM Sync Objects
 .. kernel-doc:: drivers/gpu/drm/drm_syncobj.c
    :export:
 
+DRM Execution context
+=====================
+
+.. kernel-doc:: drivers/gpu/drm/drm_exec.c
+   :doc: Overview
+
+.. kernel-doc:: include/drm/drm_exec.h
+   :internal:
+
+.. kernel-doc:: drivers/gpu/drm/drm_exec.c
+   :export:
+
 GPU Scheduler
 =============
 
drivers/gpu/drm/Kconfig +6 -0
index e928284b4357..39c9d079d52a 100644
@@ -201,6 +201,12 @@ config DRM_TTM
 	  GPU memory types. Will be enabled automatically if a device driver
 	  uses it.
 
+config DRM_EXEC
+	tristate
+	depends on DRM
+	help
+	  Execution context for command submissions
+
 config DRM_BUDDY
 	tristate
 	depends on DRM
drivers/gpu/drm/Makefile +2 -0
index ad6267273503..ab728632d8a2 100644
@@ -80,6 +80,8 @@ obj-$(CONFIG_DRM_PANEL_ORIENTATION_QUIRKS) += drm_panel_orientation_quirks.o
 #
 # Memory-management helpers
 #
+#
+obj-$(CONFIG_DRM_EXEC) += drm_exec.o
 
 obj-$(CONFIG_DRM_BUDDY) += drm_buddy.o
 
drivers/gpu/drm/drm_exec.c new file +248 -0

248 lines not on this page · raw message

include/drm/drm_exec.h new file +115 -0

115 lines not on this page · raw message

Signature · 1 line
2.34.1
author maintainer
#101 lore raw

PATCH v2 26/31 drm/exec: Always compile drm_exec

In reply to Matthew Brost

We want some helpers for DRM exec in gpuva, alway compile this.

---
 drivers/gpu/drm/Makefile | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/Makefile +1 -2
index ab728632d8a2..40067970af04 100644
@@ -23,6 +23,7 @@ drm-y := \
 	drm_dumb_buffers.o \
 	drm_edid.o \
 	drm_encoder.o \
+	drm_exec.o \
 	drm_file.o \
 	drm_fourcc.o \
 	drm_framebuffer.o \
@@ -81,8 +82,6 @@ obj-$(CONFIG_DRM_PANEL_ORIENTATION_QUIRKS) += drm_panel_orientation_quirks.o
 # Memory-management helpers
 #
 #
-obj-$(CONFIG_DRM_EXEC) += drm_exec.o
-
 obj-$(CONFIG_DRM_BUDDY) += drm_buddy.o
 
 drm_dma_helper-y := drm_gem_dma_helper.o
Signature · 1 line
2.34.1
maintainer
#102 lore raw

Re: [Intel-xe] [PATCH v2 26/31] drm/exec: Always compile drm_exec

Quoted 21 lines · Matthew Brost

We want some helpers for DRM exec in gpuva, alway compile this.

---
 drivers/gpu/drm/Makefile | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/Makefile +1 -0
index ab728632d8a2..40067970af04 100644
@@ -23,6 +23,7 @@ drm-y := \
 	drm_dumb_buffers.o \
 	drm_edid.o \
 	drm_encoder.o \
+	drm_exec.o \
 	drm_file.o \
 	drm_fourcc.o \
 	drm_framebuffer.o \

drivers/gpu/drm/Makefile obj-$(CONFIG_DRM_PANEL_ORIENTATION_QUIRKS) += drm_panel_orientation_quirks.o · line 84

Quoted 4 lines
drivers/gpu/drm/Makefile +0 -1
@@ -81,8 +82,6 @@ obj-$(CONFIG_DRM_PANEL_ORIENTATION_QUIRKS) += drm_panel_orientation_quirks.o
 # Memory-management helpers
 #
 #
-obj-$(CONFIG_DRM_EXEC) += drm_exec.o

shouldn't this kill this kconfig entirely then?
Or should the helpers be split into some other common file?

Quoted 7 lines
drivers/gpu/drm/Makefile +0 -1
-
 obj-$(CONFIG_DRM_BUDDY) += drm_buddy.o
 
 drm_dma_helper-y := drm_gem_dma_helper.o
Signature · 1 line
2.34.1
author maintainer
#103 lore raw

Re: [Intel-xe] [PATCH v2 26/31] drm/exec: Always compile drm_exec

Quoted 21 lines · Rodrigo Vivi
Quoted 20 lines · Matthew Brost

We want some helpers for DRM exec in gpuva, alway compile this.

---
 drivers/gpu/drm/Makefile | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/Makefile +1 -0
index ab728632d8a2..40067970af04 100644
@@ -23,6 +23,7 @@ drm-y := \
 	drm_dumb_buffers.o \
 	drm_edid.o \
 	drm_encoder.o \
+	drm_exec.o \
 	drm_file.o \
 	drm_fourcc.o \
 	drm_framebuffer.o \
Quoted 9 lines

drivers/gpu/drm/Makefile obj-$(CONFIG_DRM_PANEL_ORIENTATION_QUIRKS) += drm_panel_orientation_quirks.o · line 84

Quoted 5 lines
drivers/gpu/drm/Makefile +0 -1
@@ -81,8 +82,6 @@ obj-$(CONFIG_DRM_PANEL_ORIENTATION_QUIRKS) += drm_panel_orientation_quirks.o
 # Memory-management helpers
 #
 #
-obj-$(CONFIG_DRM_EXEC) += drm_exec.o

shouldn't this kill this kconfig entirely then?
Or should the helpers be split into some other common file?

Yes we should kill this one entirely. Will fix.

Matt

Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/Makefile +0 -1
-
 obj-$(CONFIG_DRM_BUDDY) += drm_buddy.o
 
 drm_dma_helper-y := drm_gem_dma_helper.o
Signature · 1 line
2.34.1
author maintainer
#104 lore raw

Re: [Intel-xe] [PATCH v2 26/31] drm/exec: Always compile drm_exec

In reply to Rodrigo Vivi
Quoted 21 lines · Rodrigo Vivi
Quoted 20 lines · Matthew Brost

We want some helpers for DRM exec in gpuva, alway compile this.

---
 drivers/gpu/drm/Makefile | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/Makefile +1 -0
index ab728632d8a2..40067970af04 100644
@@ -23,6 +23,7 @@ drm-y := \
 	drm_dumb_buffers.o \
 	drm_edid.o \
 	drm_encoder.o \
+	drm_exec.o \
 	drm_file.o \
 	drm_fourcc.o \
 	drm_framebuffer.o \
Quoted 9 lines

drivers/gpu/drm/Makefile obj-$(CONFIG_DRM_PANEL_ORIENTATION_QUIRKS) += drm_panel_orientation_quirks.o · line 84

Quoted 5 lines
drivers/gpu/drm/Makefile +0 -1
@@ -81,8 +82,6 @@ obj-$(CONFIG_DRM_PANEL_ORIENTATION_QUIRKS) += drm_panel_orientation_quirks.o
 # Memory-management helpers
 #
 #
-obj-$(CONFIG_DRM_EXEC) += drm_exec.o

shouldn't this kill this kconfig entirely then?
Or should the helpers be split into some other common file?

I can probably post 28 & 29 in an independent series.

Matt

Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/Makefile +0 -1
-
 obj-$(CONFIG_DRM_BUDDY) += drm_buddy.o
 
 drm_dma_helper-y := drm_gem_dma_helper.o
Signature · 1 line
2.34.1
author maintainer
#105 lore raw

PATCH v2 27/31 drm/xe: Use drm_exec for locking rather than TTM exec helpers

In reply to Matthew Brost

drm_exec is intended to replace TTM exec helpers, use drm_exec. Also combine parts of drm_exec with gpuva where it makes sense (locking, fence installation).

---
 drivers/gpu/drm/drm_gpuva_mgr.c              |  67 ++++-
 drivers/gpu/drm/i915/display/intel_display.c |   6 +-
 drivers/gpu/drm/xe/Kconfig                   |   1 +
 drivers/gpu/drm/xe/tests/xe_bo.c             |  26 +-
 drivers/gpu/drm/xe/tests/xe_migrate.c        |   6 +-
 drivers/gpu/drm/xe/xe_bo.c                   |  56 ++--
 drivers/gpu/drm/xe/xe_bo.h                   |   6 +-
 drivers/gpu/drm/xe/xe_bo_evict.c             |  24 +-
 drivers/gpu/drm/xe/xe_bo_types.h             |   1 -
 drivers/gpu/drm/xe/xe_engine.c               |   7 +-
 drivers/gpu/drm/xe/xe_exec.c                 |  37 +--
 drivers/gpu/drm/xe/xe_gt_pagefault.c         |  55 +---
 drivers/gpu/drm/xe/xe_lrc.c                  |   8 +-
 drivers/gpu/drm/xe/xe_migrate.c              |  13 +-
 drivers/gpu/drm/xe/xe_vm.c                   | 283 ++++++++-----------
 drivers/gpu/drm/xe/xe_vm.h                   |  27 +-
 drivers/gpu/drm/xe/xe_vm_madvise.c           |  37 +--
 include/drm/drm_gpuva_mgr.h                  |  16 +-
 18 files changed, 315 insertions(+), 361 deletions(-)
drivers/gpu/drm/drm_gpuva_mgr.c +59 -8
index e8cd6e154336..93c912c34211 100644
@@ -483,6 +483,50 @@ drm_gpuva_manager_destroy(struct drm_gpuva_manager *mgr)
 }
 EXPORT_SYMBOL(drm_gpuva_manager_destroy);
 
+/**
+ * TODO
+ */
+int drm_gpuva_manager_lock(struct drm_gpuva_manager *mgr, struct drm_exec *exec,
+			   struct drm_gem_object *mgr_obj, bool intr,
+			   unsigned int num_fences)
+{
+	struct drm_gpuva *gpuva;
+	int ret;
+
+	drm_exec_init(exec, intr);
+	drm_exec_while_not_all_locked(exec) {
+		ret = drm_exec_prepare_obj(exec, mgr_obj, num_fences);
+		drm_exec_continue_on_contention(exec);
+		if (ret && ret != -EALREADY)
+			goto err_exec;
+
+		drm_gpuva_for_each_extobj(gpuva, mgr) {
+			ret = drm_exec_prepare_obj(exec, gpuva->gem.obj,
+						   num_fences);
+			drm_exec_break_on_contention(exec);
+			if (ret && ret != -EALREADY)
+				goto err_exec;
+		}
+	}
+
+	return 0;
+
+err_exec:
+	drm_exec_fini(exec);
+	return ret;
+}
+EXPORT_SYMBOL(drm_gpuva_manager_lock);
+
+/**
+ * TODO
+ */
+void drm_gpuva_manager_unlock(struct drm_gpuva_manager *mgr,
+			      struct drm_exec *exec)
+{
+	drm_exec_fini(exec);
+}
+EXPORT_SYMBOL(drm_gpuva_manager_unlock);
+
 static inline bool
 drm_gpuva_in_mm_range(struct drm_gpuva_manager *mgr, u64 addr, u64 range)
 {
@@ -888,7 +932,7 @@ drm_gpuva_interval_empty(struct drm_gpuva_manager *mgr, u64 addr, u64 range)
 EXPORT_SYMBOL(drm_gpuva_interval_empty);
 
 /**
- * drm_gpuva_add_fence - add fence to private and all extobj dma-resv
+ * drm_gpuva_manager_add_fence - add fence to private and all extobj dma-resv
  * @mgr: the &drm_gpuva_manager to add a fence to
  * @fence: fence to add
  * @private_usage: private dma-resv usage
@@ -896,17 +940,24 @@ EXPORT_SYMBOL(drm_gpuva_interval_empty);
  *
  * Returns: true if the interval is empty, false otherwise
  */
-void drm_gpuva_add_fence(struct drm_gpuva_manager *mgr, struct dma_fence *fence,
-			 enum dma_resv_usage private_usage,
-			 enum dma_resv_usage extobj_usage)
+void drm_gpuva_manager_add_fence(struct drm_gpuva_manager *mgr,
+				 struct drm_exec *exec,
+				 struct dma_fence *fence,
+				 enum dma_resv_usage private_usage,
+				 enum dma_resv_usage extobj_usage)
 {
-	struct drm_gpuva *gpuva;
+	struct drm_gem_object *obj;
+	unsigned long index;
+
+	dma_resv_assert_held(&mgr->resv);
 
 	dma_resv_add_fence(&mgr->resv, fence, private_usage);
-	drm_gpuva_for_each_extobj(gpuva, mgr)
-		dma_resv_add_fence(gpuva->gem.obj->resv, fence, extobj_usage);
+	drm_exec_for_each_locked_object(exec, index, obj)
+		if (likely(&mgr->resv != obj->resv))
+			dma_resv_add_fence(obj->resv, fence, extobj_usage);
 }
-EXPORT_SYMBOL(drm_gpuva_add_fence);
+EXPORT_SYMBOL(drm_gpuva_manager_add_fence);
+
 
 /**
  * drm_gpuva_map - helper to insert a &drm_gpuva from &drm_gpuva_fn_ops
drivers/gpu/drm/i915/display/intel_display.c +3 -3
index 28a227450329..aab1a3a0f06d 100644
@@ -7340,11 +7340,11 @@ static int i915_gem_object_read_from_page(struct xe_bo *bo,
 	void *virtual;
 	bool is_iomem;
 	int ret;
-	struct ww_acquire_ctx ww;
+	struct drm_exec exec;
 
 	XE_BUG_ON(size != 8);
 
-	ret = xe_bo_lock(bo, &ww, 0, true);
+	ret = xe_bo_lock(bo, &exec, 0, true);
 	if (ret)
 		return ret;
 
@@ -7361,7 +7361,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, &exec);
 	return ret;
 }
 #endif
drivers/gpu/drm/xe/Kconfig +1 -0
index f6f3b491d162..bbcc9b64b776 100644
@@ -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/tests/xe_bo.c +13 -13
index 9bd381e5b7a6..316c6cf2bb86 100644
@@ -175,17 +175,17 @@ static int evict_test_run_gt(struct xe_device *xe, struct xe_gt *gt, struct kuni
 	unsigned int bo_flags = XE_BO_CREATE_USER_BIT |
 		XE_BO_CREATE_VRAM_IF_DGFX(gt);
 	struct xe_vm *vm = xe_migrate_get_vm(xe->gt[0].migrate);
-	struct ww_acquire_ctx ww;
+	struct drm_exec exec;
 	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->info.vram_id);
 
 	for (i = 0; i < 2; ++i) {
-		xe_vm_lock(vm, &ww, 0, false);
+		xe_vm_lock(vm, &exec, 0, false);
 		bo = xe_bo_create(xe, NULL, vm, 0x10000, ttm_bo_type_device,
 				  bo_flags);
-		xe_vm_unlock(vm, &ww);
+		xe_vm_unlock(vm, &exec);
 		if (IS_ERR(bo)) {
 			KUNIT_FAIL(test, "bo create err=%pe\n", bo);
 			break;
@@ -198,9 +198,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, &exec, 0, false);
 		err = xe_bo_pin_external(external);
-		xe_bo_unlock(external, &ww);
+		xe_bo_unlock(external, &exec);
 		if (err) {
 			KUNIT_FAIL(test, "external bo pin err=%pe\n",
 				   ERR_PTR(err));
@@ -240,18 +240,18 @@ static int evict_test_run_gt(struct xe_device *xe, struct xe_gt *gt, struct kuni
 
 		if (i) {
 			down_read(&vm->lock);
-			xe_vm_lock(vm, &ww, 0, false);
+			xe_vm_lock(vm, &exec, 0, false);
 			err = xe_bo_validate(bo, bo->vm, false);
-			xe_vm_unlock(vm, &ww);
+			xe_vm_unlock(vm, &exec);
 			up_read(&vm->lock);
 			if (err) {
 				KUNIT_FAIL(test, "bo valid err=%pe\n",
 					   ERR_PTR(err));
 				goto cleanup_all;
 			}
-			xe_bo_lock(external, &ww, 0, false);
+			xe_bo_lock(external, &exec, 0, false);
 			err = xe_bo_validate(external, NULL, false);
-			xe_bo_unlock(external, &ww);
+			xe_bo_unlock(external, &exec);
 			if (err) {
 				KUNIT_FAIL(test, "external bo valid err=%pe\n",
 					   ERR_PTR(err));
@@ -259,18 +259,18 @@ 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, &exec, 0, false);
 		xe_bo_unpin_external(external);
-		xe_bo_unlock(external, &ww);
+		xe_bo_unlock(external, &exec);
 
 		xe_bo_put(external);
 		xe_bo_put(bo);
 		continue;
 
 cleanup_all:
-		xe_bo_lock(external, &ww, 0, false);
+		xe_bo_lock(external, &exec, 0, false);
 		xe_bo_unpin_external(external);
-		xe_bo_unlock(external, &ww);
+		xe_bo_unlock(external, &exec);
 cleanup_external:
 		xe_bo_put(external);
 cleanup_bo:
drivers/gpu/drm/xe/tests/xe_migrate.c +3 -3
index 0f4371ad1fd9..e1482b4491b1 100644
@@ -394,14 +394,14 @@ static int migrate_test_run_device(struct xe_device *xe)
 
 	for_each_gt(gt, xe, id) {
 		struct xe_migrate *m = gt->migrate;
-		struct ww_acquire_ctx ww;
+		struct drm_exec exec;
 
 		kunit_info(test, "Testing gt id %d.\n", id);
-		xe_vm_lock(m->eng->vm, &ww, 0, true);
+		xe_vm_lock(m->eng->vm, &exec, 0, true);
 		xe_device_mem_access_get(xe);
 		xe_migrate_sanity_test(m, test);
 		xe_device_mem_access_put(xe);
-		xe_vm_unlock(m->eng->vm, &ww);
+		xe_vm_unlock(m->eng->vm, &exec);
 	}
 
 	return 0;
drivers/gpu/drm/xe/xe_bo.c +23 -33

122 lines not on this page · raw message

drivers/gpu/drm/xe/xe_bo.h +3 -3
index 9b401d30a130..5a80ebf72d10 100644
@@ -75,6 +75,7 @@
 
 #define XE_BO_PROPS_INVALID	(-1)
 
+struct drm_exec;
 struct sg_table;
 
 struct xe_bo *xe_bo_alloc(void);
@@ -142,10 +143,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 xe_bo_lock(struct xe_bo *bo, struct drm_exec *exec,
 	       int num_resv, bool intr);
-
-void xe_bo_unlock(struct xe_bo *bo, struct ww_acquire_ctx *ww);
+void xe_bo_unlock(struct xe_bo *bo, struct drm_exec *exec);
 
 static inline void xe_bo_unlock_vm_held(struct xe_bo *bo)
 {
drivers/gpu/drm/xe/xe_bo_evict.c +13 -11
index 6642c5f52009..46d9d9eb110c 100644
@@ -3,6 +3,8 @@
  * Copyright © 2022 Intel Corporation
  */
 
+#include <drm/drm_exec.h>
+
 #include "xe_bo_evict.h"
 
 #include "xe_bo.h"
@@ -27,7 +29,7 @@
 int xe_bo_evict_all(struct xe_device *xe)
 {
 	struct ttm_device *bdev = &xe->ttm;
-	struct ww_acquire_ctx ww;
+	struct drm_exec exec;
 	struct xe_bo *bo;
 	struct xe_gt *gt;
 	struct list_head still_in_list;
@@ -62,9 +64,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, &exec, 0, false);
 		ret = xe_bo_evict_pinned(bo);
-		xe_bo_unlock(bo, &ww);
+		xe_bo_unlock(bo, &exec);
 		xe_bo_put(bo);
 		if (ret) {
 			spin_lock(&xe->pinned.lock);
@@ -96,9 +98,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, &exec, 0, false);
 		ret = xe_bo_evict_pinned(bo);
-		xe_bo_unlock(bo, &ww);
+		xe_bo_unlock(bo, &exec);
 		xe_bo_put(bo);
 		if (ret)
 			return ret;
@@ -123,7 +125,7 @@ int xe_bo_evict_all(struct xe_device *xe)
  */
 int xe_bo_restore_kernel(struct xe_device *xe)
 {
-	struct ww_acquire_ctx ww;
+	struct drm_exec exec;
 	struct xe_bo *bo;
 	int ret;
 
@@ -140,9 +142,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, &exec, 0, false);
 		ret = xe_bo_restore_pinned(bo);
-		xe_bo_unlock(bo, &ww);
+		xe_bo_unlock(bo, &exec);
 		if (ret) {
 			xe_bo_put(bo);
 			return ret;
@@ -182,7 +184,7 @@ int xe_bo_restore_kernel(struct xe_device *xe)
  */
 int xe_bo_restore_user(struct xe_device *xe)
 {
-	struct ww_acquire_ctx ww;
+	struct drm_exec exec;
 	struct xe_bo *bo;
 	struct xe_gt *gt;
 	struct list_head still_in_list;
@@ -204,9 +206,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, &exec, 0, false);
 		ret = xe_bo_restore_pinned(bo);
-		xe_bo_unlock(bo, &ww);
+		xe_bo_unlock(bo, &exec);
 		xe_bo_put(bo);
 		if (ret) {
 			spin_lock(&xe->pinned.lock);
drivers/gpu/drm/xe/xe_bo_types.h +0 -1
index 06de3330211d..2ba34a8c9b66 100644
@@ -11,7 +11,6 @@
 #include <drm/drm_mm.h>
 #include <drm/ttm/ttm_bo.h>
 #include <drm/ttm/ttm_device.h>
-#include <drm/ttm/ttm_execbuf_util.h>
 #include <drm/ttm/ttm_placement.h>
 
 struct xe_device;
drivers/gpu/drm/xe/xe_engine.c +4 -3
index 91600b1e8249..8b425b777259 100644
@@ -8,6 +8,7 @@
 #include <linux/nospec.h>
 
 #include <drm/drm_device.h>
+#include <drm/drm_exec.h>
 #include <drm/drm_file.h>
 #include <drm/xe_drm.h>
 
@@ -89,18 +90,18 @@ struct xe_engine *xe_engine_create(struct xe_device *xe, struct xe_vm *vm,
 				   u32 logical_mask, u16 width,
 				   struct xe_hw_engine *hwe, u32 flags)
 {
-	struct ww_acquire_ctx ww;
+	struct drm_exec exec;
 	struct xe_engine *e;
 	int err;
 
 	if (vm) {
-		err = xe_vm_lock(vm, &ww, 0, true);
+		err = xe_vm_lock(vm, &exec, 0, true);
 		if (err)
 			return ERR_PTR(err);
 	}
 	e = __xe_engine_create(xe, vm, logical_mask, width, hwe, flags);
 	if (vm)
-		xe_vm_unlock(vm, &ww);
+		xe_vm_unlock(vm, &exec);
 
 	return e;
 }
drivers/gpu/drm/xe/xe_exec.c +13 -24
index 2ae02f1500d5..9f7f1088c403 100644
@@ -6,6 +6,7 @@
 #include "xe_exec.h"
 
 #include <drm/drm_device.h>
+#include <drm/drm_exec.h>
 #include <drm/drm_file.h>
 #include <drm/xe_drm.h>
 
@@ -92,21 +93,16 @@
  *	Unlock all
  */
 
-static int xe_exec_begin(struct xe_engine *e, struct ww_acquire_ctx *ww,
-			 struct ttm_validate_buffer tv_onstack[],
-			 struct ttm_validate_buffer **tv,
-			 struct list_head *objs)
+static int xe_exec_begin(struct xe_engine *e, struct drm_exec *exec)
 {
 	struct xe_vm *vm = e->vm;
 	struct xe_vma *vma;
-	LIST_HEAD(dups);
 	int err;
 
-	*tv = NULL;
 	if (xe_vm_no_dma_fences(e->vm))
 		return 0;
 
-	err = xe_vm_lock_dma_resv(vm, ww, tv_onstack, tv, objs, true, 1);
+	err = xe_vm_lock_dma_resv(vm, exec, true, 1);
 	if (err)
 		return err;
 
@@ -123,8 +119,7 @@ static int xe_exec_begin(struct xe_engine *e, struct ww_acquire_ctx *ww,
 
 		err = xe_bo_validate(xe_vma_bo(vma), vm, false);
 		if (err) {
-			xe_vm_unlock_dma_resv(vm, tv_onstack, *tv, ww, objs);
-			*tv = NULL;
+			xe_vm_unlock_dma_resv(vm, exec);
 			return err;
 		}
 	}
@@ -132,14 +127,10 @@ static int xe_exec_begin(struct xe_engine *e, struct ww_acquire_ctx *ww,
 	return 0;
 }
 
-static void xe_exec_end(struct xe_engine *e,
-			struct ttm_validate_buffer *tv_onstack,
-			struct ttm_validate_buffer *tv,
-			struct ww_acquire_ctx *ww,
-			struct list_head *objs)
+static void xe_exec_end(struct xe_engine *e, struct drm_exec *exec)
 {
 	if (!xe_vm_no_dma_fences(e->vm))
-		xe_vm_unlock_dma_resv(e->vm, tv_onstack, tv, ww, objs);
+		xe_vm_unlock_dma_resv(e->vm, exec);
 }
 
 int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
@@ -149,17 +140,14 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 	struct drm_xe_exec *args = data;
 	struct drm_xe_sync __user *syncs_user = u64_to_user_ptr(args->syncs);
 	u64 __user *addresses_user = u64_to_user_ptr(args->address);
+	struct drm_exec exec;
 	struct xe_engine *engine;
 	struct xe_sync_entry *syncs = NULL;
 	u64 addresses[XE_HW_ENGINE_MAX_INSTANCE];
-	struct ttm_validate_buffer tv_onstack[XE_ONSTACK_TV];
-	struct ttm_validate_buffer *tv = NULL;
 	u32 i, num_syncs = 0;
 	struct xe_sched_job *job;
 	struct dma_fence *rebind_fence;
 	struct xe_vm *vm;
-	struct ww_acquire_ctx ww;
-	struct list_head objs;
 	bool write_locked;
 	int err = 0;
 
@@ -270,7 +258,7 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 			goto err_unlock_list;
 	}
 
-	err = xe_exec_begin(engine, &ww, tv_onstack, &tv, &objs);
+	err = xe_exec_begin(engine, &exec);
 	if (err)
 		goto err_unlock_list;
 
@@ -361,9 +349,10 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 	 * are written as we don't pass in a read / write list.
 	 */
 	if (!xe_vm_no_dma_fences(vm))
-		drm_gpuva_add_fence(&vm->mgr, &job->drm.s_fence->finished,
-				    DMA_RESV_USAGE_BOOKKEEP,
-				    DMA_RESV_USAGE_WRITE);
+		drm_gpuva_manager_add_fence(&vm->mgr, &exec,
+					    &job->drm.s_fence->finished,
+					    DMA_RESV_USAGE_BOOKKEEP,
+					    DMA_RESV_USAGE_WRITE);
 
 	for (i = 0; i < num_syncs; i++)
 		xe_sync_entry_signal(&syncs[i], job,
@@ -387,7 +376,7 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 	if (err)
 		xe_sched_job_put(job);
 err_engine_end:
-	xe_exec_end(engine, tv_onstack, tv, &ww, &objs);
+	xe_exec_end(engine, &exec);
 err_unlock_list:
 	if (write_locked)
 		up_write(&vm->lock);
drivers/gpu/drm/xe/xe_gt_pagefault.c +7 -48

103 lines not on this page · raw message

drivers/gpu/drm/xe/xe_lrc.c +5 -3
index ae605e7805de..3cc34efe8dd8 100644
@@ -3,6 +3,8 @@
  * Copyright © 2021 Intel Corporation
  */
 
+#include <drm/drm_exec.h>
+
 #include "xe_lrc.h"
 
 #include "regs/xe_engine_regs.h"
@@ -712,16 +714,16 @@ 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;
+	struct drm_exec exec;
 
 	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, &exec, 0, 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, &exec);
 	else
 		xe_bo_unlock_no_vm(lrc->bo);
 	xe_bo_put(lrc->bo);
drivers/gpu/drm/xe/xe_migrate.c +7 -6
index 91a06c925a1e..1dd497252640 100644
@@ -9,6 +9,7 @@
 #include <linux/sizes.h>
 
 #include <drm/drm_managed.h>
+#include <drm/drm_exec.h>
 #include <drm/ttm/ttm_tt.h>
 #include <drm/xe_drm.h>
 
@@ -86,13 +87,13 @@ struct xe_engine *xe_gt_migrate_engine(struct xe_gt *gt)
 static void xe_migrate_fini(struct drm_device *dev, void *arg)
 {
 	struct xe_migrate *m = arg;
-	struct ww_acquire_ctx ww;
+	struct drm_exec exec;
 
-	xe_vm_lock(m->eng->vm, &ww, 0, false);
+	xe_vm_lock(m->eng->vm, &exec, 0, false);
 	xe_bo_unpin(m->pt_bo);
 	if (m->cleared_bo)
 		xe_bo_unpin(m->cleared_bo);
-	xe_vm_unlock(m->eng->vm, &ww);
+	xe_vm_unlock(m->eng->vm, &exec);
 
 	dma_fence_put(m->fence);
 	if (m->cleared_bo)
@@ -315,7 +316,7 @@ struct xe_migrate *xe_migrate_init(struct xe_gt *gt)
 	struct xe_device *xe = gt_to_xe(gt);
 	struct xe_migrate *m;
 	struct xe_vm *vm;
-	struct ww_acquire_ctx ww;
+	struct drm_exec exec;
 	int err;
 
 	XE_BUG_ON(xe_gt_is_media_type(gt));
@@ -332,9 +333,9 @@ struct xe_migrate *xe_migrate_init(struct xe_gt *gt)
 	if (IS_ERR(vm))
 		return ERR_CAST(vm);
 
-	xe_vm_lock(vm, &ww, 0, false);
+	xe_vm_lock(vm, &exec, 0, false);
 	err = xe_migrate_prepare_vm(gt, m, vm);
-	xe_vm_unlock(vm, &ww);
+	xe_vm_unlock(vm, &exec);
 	if (err) {
 		xe_vm_close_and_put(vm);
 		return ERR_PTR(err);
drivers/gpu/drm/xe/xe_vm.c +120 -163

538 lines not on this page · raw message

drivers/gpu/drm/xe/xe_vm.h +9 -18
index f279fa622260..47b981d9fc04 100644
@@ -12,6 +12,7 @@
 #include "xe_vm_types.h"
 
 struct drm_device;
+struct drm_exec;
 struct drm_printer;
 struct drm_file;
 
@@ -38,10 +39,14 @@ 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 xe_vm_lock(struct xe_vm *vm, struct drm_exec *exec,
 	       int num_resv, bool intr);
+void xe_vm_unlock(struct xe_vm *vm, struct drm_exec *exec);
 
-void xe_vm_unlock(struct xe_vm *vm, struct ww_acquire_ctx *ww);
+int xe_vm_bo_lock(struct xe_vm *vm, struct xe_bo *bo, struct drm_exec *exec,
+		  int num_resv, bool intr);
+void xe_vm_bo_unlock(struct xe_vm *vm, struct xe_bo *bo, struct drm_exec *exec,
+		     bool lru_update);
 
 static inline bool xe_vm_is_closed(struct xe_vm *vm)
 {
@@ -219,23 +224,9 @@ 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,
+int xe_vm_lock_dma_resv(struct xe_vm *vm, struct drm_exec *exec, 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);
+void xe_vm_unlock_dma_resv(struct xe_vm *vm, struct drm_exec *exec);
 
 int xe_analyze_vm(struct drm_printer *p, struct xe_vm *vm, int gt_id);
 
drivers/gpu/drm/xe/xe_vm_madvise.c +19 -18
index 03508645fa08..a68bc6fec1de 100644
@@ -7,6 +7,7 @@
 
 #include <linux/nospec.h>
 
+#include <drm/drm_exec.h>
 #include <drm/ttm/ttm_tt.h>
 #include <drm/xe_drm.h>
 
@@ -28,16 +29,16 @@ 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;
+		struct drm_exec exec;
 
 		bo = xe_vma_bo(vmas[i]);
 
-		err = xe_bo_lock(bo, &ww, 0, true);
+		err = xe_bo_lock(bo, &exec, 0, 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, &exec);
 	}
 
 	return 0;
@@ -53,16 +54,16 @@ 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;
+		struct drm_exec exec;
 
 		bo = xe_vma_bo(vmas[i]);
 
-		err = xe_bo_lock(bo, &ww, 0, true);
+		err = xe_bo_lock(bo, &exec, 0, 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, &exec);
 	}
 
 	return 0;
@@ -89,17 +90,17 @@ 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;
+		struct drm_exec exec;
 
 		bo = xe_vma_bo(vmas[i]);
 
-		err = xe_bo_lock(bo, &ww, 0, true);
+		err = xe_bo_lock(bo, &exec, 0, 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, &exec);
 	}
 
 	return 0;
@@ -112,13 +113,13 @@ 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;
+		struct drm_exec exec;
 
 		bo = xe_vma_bo(vmas[i]);
 		if (XE_IOCTL_ERR(xe, !(bo->flags & XE_BO_CREATE_SYSTEM_BIT)))
 			return -EINVAL;
 
-		err = xe_bo_lock(bo, &ww, 0, true);
+		err = xe_bo_lock(bo, &exec, 0, true);
 		if (err)
 			return err;
 		bo->props.cpu_atomic = !!value;
@@ -130,7 +131,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, &exec);
 	}
 
 	return 0;
@@ -143,18 +144,18 @@ 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;
+		struct drm_exec exec;
 
 		bo = xe_vma_bo(vmas[i]);
 		if (XE_IOCTL_ERR(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, &exec, 0, true);
 		if (err)
 			return err;
 		bo->props.device_atomic = !!value;
-		xe_bo_unlock(bo, &ww);
+		xe_bo_unlock(bo, &exec);
 	}
 
 	return 0;
@@ -174,16 +175,16 @@ 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;
+		struct drm_exec exec;
 
 		bo = xe_vma_bo(vmas[i]);
 
-		err = xe_bo_lock(bo, &ww, 0, true);
+		err = xe_bo_lock(bo, &exec, 0, 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, &exec);
 	}
 
 	return 0;
include/drm/drm_gpuva_mgr.h +13 -3
index 943c8fcda533..a2f6d90ac899 100644
@@ -32,6 +32,8 @@
 #include <linux/spinlock.h>
 #include <linux/types.h>
 
+#include <drm/drm_exec.h>
+
 struct drm_gpuva_manager;
 struct drm_gpuva_fn_ops;
 struct drm_gpuva_prealloc;
@@ -169,9 +171,17 @@ struct drm_gpuva *drm_gpuva_find_next(struct drm_gpuva_manager *mgr, u64 end);
 
 bool drm_gpuva_interval_empty(struct drm_gpuva_manager *mgr, u64 addr, u64 range);
 
-void drm_gpuva_add_fence(struct drm_gpuva_manager *mgr, struct dma_fence *fence,
-			 enum dma_resv_usage private_usage,
-			 enum dma_resv_usage extobj_usage);
+int drm_gpuva_manager_lock(struct drm_gpuva_manager *mgr, struct drm_exec *exec,
+			   struct drm_gem_object *mgr_obj, bool intr,
+			   unsigned int num_fences);
+void drm_gpuva_manager_unlock(struct drm_gpuva_manager *mgr,
+			      struct drm_exec *exec);
+
+void drm_gpuva_manager_add_fence(struct drm_gpuva_manager *mgr,
+				 struct drm_exec *exec,
+				 struct dma_fence *fence,
+				 enum dma_resv_usage private_usage,
+				 enum dma_resv_usage extobj_usage);
 
 /**
  * drm_gpuva_evict - sets whether the backing GEM of this &drm_gpuva is evicted
Signature · 1 line
2.34.1
#106 lore raw

Re: [Intel-xe] [PATCH v2 27/31] drm/xe: Use drm_exec for locking rather than TTM exec helpers

Quoted 3 lines · Matthew Brost

drm_exec is intended to replace TTM exec helpers, use drm_exec. Also combine parts of drm_exec with gpuva where it makes sense (locking, fence installation).

here again... to many things in one patch and xe and drm mixed.

We need to split this up...

Quoted 1,672 lines
---
 drivers/gpu/drm/drm_gpuva_mgr.c              |  67 ++++-
 drivers/gpu/drm/i915/display/intel_display.c |   6 +-
 drivers/gpu/drm/xe/Kconfig                   |   1 +
 drivers/gpu/drm/xe/tests/xe_bo.c             |  26 +-
 drivers/gpu/drm/xe/tests/xe_migrate.c        |   6 +-
 drivers/gpu/drm/xe/xe_bo.c                   |  56 ++--
 drivers/gpu/drm/xe/xe_bo.h                   |   6 +-
 drivers/gpu/drm/xe/xe_bo_evict.c             |  24 +-
 drivers/gpu/drm/xe/xe_bo_types.h             |   1 -
 drivers/gpu/drm/xe/xe_engine.c               |   7 +-
 drivers/gpu/drm/xe/xe_exec.c                 |  37 +--
 drivers/gpu/drm/xe/xe_gt_pagefault.c         |  55 +---
 drivers/gpu/drm/xe/xe_lrc.c                  |   8 +-
 drivers/gpu/drm/xe/xe_migrate.c              |  13 +-
 drivers/gpu/drm/xe/xe_vm.c                   | 283 ++++++++-----------
 drivers/gpu/drm/xe/xe_vm.h                   |  27 +-
 drivers/gpu/drm/xe/xe_vm_madvise.c           |  37 +--
 include/drm/drm_gpuva_mgr.h                  |  16 +-
 18 files changed, 315 insertions(+), 361 deletions(-)
drivers/gpu/drm/drm_gpuva_mgr.c +59 -8
index e8cd6e154336..93c912c34211 100644
@@ -483,6 +483,50 @@ drm_gpuva_manager_destroy(struct drm_gpuva_manager *mgr)
 }
 EXPORT_SYMBOL(drm_gpuva_manager_destroy);
 
+/**
+ * TODO
+ */
+int drm_gpuva_manager_lock(struct drm_gpuva_manager *mgr, struct drm_exec *exec,
+			   struct drm_gem_object *mgr_obj, bool intr,
+			   unsigned int num_fences)
+{
+	struct drm_gpuva *gpuva;
+	int ret;
+
+	drm_exec_init(exec, intr);
+	drm_exec_while_not_all_locked(exec) {
+		ret = drm_exec_prepare_obj(exec, mgr_obj, num_fences);
+		drm_exec_continue_on_contention(exec);
+		if (ret && ret != -EALREADY)
+			goto err_exec;
+
+		drm_gpuva_for_each_extobj(gpuva, mgr) {
+			ret = drm_exec_prepare_obj(exec, gpuva->gem.obj,
+						   num_fences);
+			drm_exec_break_on_contention(exec);
+			if (ret && ret != -EALREADY)
+				goto err_exec;
+		}
+	}
+
+	return 0;
+
+err_exec:
+	drm_exec_fini(exec);
+	return ret;
+}
+EXPORT_SYMBOL(drm_gpuva_manager_lock);
+
+/**
+ * TODO
+ */
+void drm_gpuva_manager_unlock(struct drm_gpuva_manager *mgr,
+			      struct drm_exec *exec)
+{
+	drm_exec_fini(exec);
+}
+EXPORT_SYMBOL(drm_gpuva_manager_unlock);
+
 static inline bool
 drm_gpuva_in_mm_range(struct drm_gpuva_manager *mgr, u64 addr, u64 range)
 {
@@ -888,7 +932,7 @@ drm_gpuva_interval_empty(struct drm_gpuva_manager *mgr, u64 addr, u64 range)
 EXPORT_SYMBOL(drm_gpuva_interval_empty);
 
 /**
- * drm_gpuva_add_fence - add fence to private and all extobj dma-resv
+ * drm_gpuva_manager_add_fence - add fence to private and all extobj dma-resv
  * @mgr: the &drm_gpuva_manager to add a fence to
  * @fence: fence to add
  * @private_usage: private dma-resv usage
@@ -896,17 +940,24 @@ EXPORT_SYMBOL(drm_gpuva_interval_empty);
  *
  * Returns: true if the interval is empty, false otherwise
  */
-void drm_gpuva_add_fence(struct drm_gpuva_manager *mgr, struct dma_fence *fence,
-			 enum dma_resv_usage private_usage,
-			 enum dma_resv_usage extobj_usage)
+void drm_gpuva_manager_add_fence(struct drm_gpuva_manager *mgr,
+				 struct drm_exec *exec,
+				 struct dma_fence *fence,
+				 enum dma_resv_usage private_usage,
+				 enum dma_resv_usage extobj_usage)
 {
-	struct drm_gpuva *gpuva;
+	struct drm_gem_object *obj;
+	unsigned long index;
+
+	dma_resv_assert_held(&mgr->resv);
 
 	dma_resv_add_fence(&mgr->resv, fence, private_usage);
-	drm_gpuva_for_each_extobj(gpuva, mgr)
-		dma_resv_add_fence(gpuva->gem.obj->resv, fence, extobj_usage);
+	drm_exec_for_each_locked_object(exec, index, obj)
+		if (likely(&mgr->resv != obj->resv))
+			dma_resv_add_fence(obj->resv, fence, extobj_usage);
 }
-EXPORT_SYMBOL(drm_gpuva_add_fence);
+EXPORT_SYMBOL(drm_gpuva_manager_add_fence);
+
 
 /**
  * drm_gpuva_map - helper to insert a &drm_gpuva from &drm_gpuva_fn_ops
drivers/gpu/drm/i915/display/intel_display.c +3 -3
index 28a227450329..aab1a3a0f06d 100644
@@ -7340,11 +7340,11 @@ static int i915_gem_object_read_from_page(struct xe_bo *bo,
 	void *virtual;
 	bool is_iomem;
 	int ret;
-	struct ww_acquire_ctx ww;
+	struct drm_exec exec;
 
 	XE_BUG_ON(size != 8);
 
-	ret = xe_bo_lock(bo, &ww, 0, true);
+	ret = xe_bo_lock(bo, &exec, 0, true);
 	if (ret)
 		return ret;
 
@@ -7361,7 +7361,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, &exec);
 	return ret;
 }
 #endif
drivers/gpu/drm/xe/Kconfig +1 -0
index f6f3b491d162..bbcc9b64b776 100644
@@ -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/tests/xe_bo.c +13 -13
index 9bd381e5b7a6..316c6cf2bb86 100644
@@ -175,17 +175,17 @@ static int evict_test_run_gt(struct xe_device *xe, struct xe_gt *gt, struct kuni
 	unsigned int bo_flags = XE_BO_CREATE_USER_BIT |
 		XE_BO_CREATE_VRAM_IF_DGFX(gt);
 	struct xe_vm *vm = xe_migrate_get_vm(xe->gt[0].migrate);
-	struct ww_acquire_ctx ww;
+	struct drm_exec exec;
 	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->info.vram_id);
 
 	for (i = 0; i < 2; ++i) {
-		xe_vm_lock(vm, &ww, 0, false);
+		xe_vm_lock(vm, &exec, 0, false);
 		bo = xe_bo_create(xe, NULL, vm, 0x10000, ttm_bo_type_device,
 				  bo_flags);
-		xe_vm_unlock(vm, &ww);
+		xe_vm_unlock(vm, &exec);
 		if (IS_ERR(bo)) {
 			KUNIT_FAIL(test, "bo create err=%pe\n", bo);
 			break;
@@ -198,9 +198,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, &exec, 0, false);
 		err = xe_bo_pin_external(external);
-		xe_bo_unlock(external, &ww);
+		xe_bo_unlock(external, &exec);
 		if (err) {
 			KUNIT_FAIL(test, "external bo pin err=%pe\n",
 				   ERR_PTR(err));
@@ -240,18 +240,18 @@ static int evict_test_run_gt(struct xe_device *xe, struct xe_gt *gt, struct kuni
 
 		if (i) {
 			down_read(&vm->lock);
-			xe_vm_lock(vm, &ww, 0, false);
+			xe_vm_lock(vm, &exec, 0, false);
 			err = xe_bo_validate(bo, bo->vm, false);
-			xe_vm_unlock(vm, &ww);
+			xe_vm_unlock(vm, &exec);
 			up_read(&vm->lock);
 			if (err) {
 				KUNIT_FAIL(test, "bo valid err=%pe\n",
 					   ERR_PTR(err));
 				goto cleanup_all;
 			}
-			xe_bo_lock(external, &ww, 0, false);
+			xe_bo_lock(external, &exec, 0, false);
 			err = xe_bo_validate(external, NULL, false);
-			xe_bo_unlock(external, &ww);
+			xe_bo_unlock(external, &exec);
 			if (err) {
 				KUNIT_FAIL(test, "external bo valid err=%pe\n",
 					   ERR_PTR(err));
@@ -259,18 +259,18 @@ 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, &exec, 0, false);
 		xe_bo_unpin_external(external);
-		xe_bo_unlock(external, &ww);
+		xe_bo_unlock(external, &exec);
 
 		xe_bo_put(external);
 		xe_bo_put(bo);
 		continue;
 
 cleanup_all:
-		xe_bo_lock(external, &ww, 0, false);
+		xe_bo_lock(external, &exec, 0, false);
 		xe_bo_unpin_external(external);
-		xe_bo_unlock(external, &ww);
+		xe_bo_unlock(external, &exec);
 cleanup_external:
 		xe_bo_put(external);
 cleanup_bo:
drivers/gpu/drm/xe/tests/xe_migrate.c +3 -3
index 0f4371ad1fd9..e1482b4491b1 100644
@@ -394,14 +394,14 @@ static int migrate_test_run_device(struct xe_device *xe)
 
 	for_each_gt(gt, xe, id) {
 		struct xe_migrate *m = gt->migrate;
-		struct ww_acquire_ctx ww;
+		struct drm_exec exec;
 
 		kunit_info(test, "Testing gt id %d.\n", id);
-		xe_vm_lock(m->eng->vm, &ww, 0, true);
+		xe_vm_lock(m->eng->vm, &exec, 0, true);
 		xe_device_mem_access_get(xe);
 		xe_migrate_sanity_test(m, test);
 		xe_device_mem_access_put(xe);
-		xe_vm_unlock(m->eng->vm, &ww);
+		xe_vm_unlock(m->eng->vm, &exec);
 	}
 
 	return 0;
drivers/gpu/drm/xe/xe_bo.c +23 -33
index e0422ffb6327..a427edbf486b 100644
@@ -8,6 +8,7 @@
 #include <linux/dma-buf.h>
 
 #include <drm/drm_drv.h>
+#include <drm/drm_exec.h>
 #include <drm/drm_gem_ttm_helper.h>
 #include <drm/ttm/ttm_device.h>
 #include <drm/ttm/ttm_placement.h>
@@ -991,13 +992,13 @@ static void xe_gem_object_close(struct drm_gem_object *obj,
 	struct xe_bo *bo = gem_to_xe_bo(obj);
 
 	if (bo->vm && !xe_vm_no_dma_fences(bo->vm)) {
-		struct ww_acquire_ctx ww;
+		struct drm_exec exec;
 
 		XE_BUG_ON(!xe_bo_is_user(bo));
 
-		xe_bo_lock(bo, &ww, 0, false);
+		xe_bo_lock(bo, &exec, 0, false);
 		ttm_bo_set_bulk_move(&bo->ttm, NULL);
-		xe_bo_unlock(bo, &ww);
+		xe_bo_unlock(bo, &exec);
 	}
 }
 
@@ -1402,11 +1403,6 @@ int xe_bo_pin_external(struct xe_bo *bo)
 	}
 
 	ttm_bo_pin(&bo->ttm);
-
-	/*
-	 * FIXME: If we always use the reserve / unreserve functions for locking
-	 * we do not need this.
-	 */
 	ttm_bo_move_to_lru_tail_unlocked(&bo->ttm);
 
 	return 0;
@@ -1461,11 +1457,6 @@ int xe_bo_pin(struct xe_bo *bo)
 	}
 
 	ttm_bo_pin(&bo->ttm);
-
-	/*
-	 * FIXME: If we always use the reserve / unreserve functions for locking
-	 * we do not need this.
-	 */
 	ttm_bo_move_to_lru_tail_unlocked(&bo->ttm);
 
 	return 0;
@@ -1496,11 +1487,6 @@ void xe_bo_unpin_external(struct xe_bo *bo)
 	}
 
 	ttm_bo_unpin(&bo->ttm);
-
-	/*
-	 * FIXME: If we always use the reserve / unreserve functions for locking
-	 * we do not need this.
-	 */
 	ttm_bo_move_to_lru_tail_unlocked(&bo->ttm);
 }
 
@@ -1650,7 +1636,7 @@ 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 drm_exec exec;
 	struct xe_vm *vm = NULL;
 	struct xe_bo *bo;
 	unsigned bo_flags = XE_BO_CREATE_USER_BIT;
@@ -1686,7 +1672,7 @@ int xe_gem_create_ioctl(struct drm_device *dev, void *data,
 		vm = xe_vm_lookup(xef, args->vm_id);
 		if (XE_IOCTL_ERR(xe, !vm))
 			return -ENOENT;
-		err = xe_vm_lock(vm, &ww, 0, true);
+		err = xe_vm_lock(vm, &exec, 0, true);
 		if (err) {
 			xe_vm_put(vm);
 			return err;
@@ -1703,7 +1689,7 @@ int xe_gem_create_ioctl(struct drm_device *dev, void *data,
 	bo = xe_bo_create(xe, NULL, vm, args->size, ttm_bo_type_device,
 			  bo_flags);
 	if (vm) {
-		xe_vm_unlock(vm, &ww);
+		xe_vm_unlock(vm, &exec);
 		xe_vm_put(vm);
 	}
 
@@ -1744,26 +1730,30 @@ int xe_gem_mmap_offset_ioctl(struct drm_device *dev, void *data,
 	return 0;
 }
 
-int xe_bo_lock(struct xe_bo *bo, struct ww_acquire_ctx *ww,
+int xe_bo_lock(struct xe_bo *bo, struct drm_exec *exec,
 	       int num_resv, bool intr)
 {
-	struct ttm_validate_buffer tv_bo;
-	LIST_HEAD(objs);
-	LIST_HEAD(dups);
+	int err;
 
-	XE_BUG_ON(!ww);
+	drm_exec_init(exec, intr);
+	drm_exec_while_not_all_locked(exec) {
+		err = drm_exec_prepare_obj(exec, &bo->ttm.base,
+					   num_resv);
+		drm_exec_continue_on_contention(exec);
+		if (err && err != -EALREADY)
+			goto out_err;
+	}
 
-	tv_bo.num_shared = num_resv;
-	tv_bo.bo = &bo->ttm;;
-	list_add_tail(&tv_bo.head, &objs);
+	return 0;
 
-	return ttm_eu_reserve_buffers(ww, &objs, intr, &dups);
+out_err:
+	drm_exec_fini(exec);
+	return err;
 }
 
-void xe_bo_unlock(struct xe_bo *bo, struct ww_acquire_ctx *ww)
+void xe_bo_unlock(struct xe_bo *bo, struct drm_exec *exec)
 {
-	dma_resv_unlock(bo->ttm.base.resv);
-	ww_acquire_fini(ww);
+	drm_exec_fini(exec);
 }
 
 /**
drivers/gpu/drm/xe/xe_bo.h +3 -3
index 9b401d30a130..5a80ebf72d10 100644
@@ -75,6 +75,7 @@
 
 #define XE_BO_PROPS_INVALID	(-1)
 
+struct drm_exec;
 struct sg_table;
 
 struct xe_bo *xe_bo_alloc(void);
@@ -142,10 +143,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 xe_bo_lock(struct xe_bo *bo, struct drm_exec *exec,
 	       int num_resv, bool intr);
-
-void xe_bo_unlock(struct xe_bo *bo, struct ww_acquire_ctx *ww);
+void xe_bo_unlock(struct xe_bo *bo, struct drm_exec *exec);
 
 static inline void xe_bo_unlock_vm_held(struct xe_bo *bo)
 {
drivers/gpu/drm/xe/xe_bo_evict.c +13 -11
index 6642c5f52009..46d9d9eb110c 100644
@@ -3,6 +3,8 @@
  * Copyright © 2022 Intel Corporation
  */
 
+#include <drm/drm_exec.h>
+
 #include "xe_bo_evict.h"
 
 #include "xe_bo.h"
@@ -27,7 +29,7 @@
 int xe_bo_evict_all(struct xe_device *xe)
 {
 	struct ttm_device *bdev = &xe->ttm;
-	struct ww_acquire_ctx ww;
+	struct drm_exec exec;
 	struct xe_bo *bo;
 	struct xe_gt *gt;
 	struct list_head still_in_list;
@@ -62,9 +64,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, &exec, 0, false);
 		ret = xe_bo_evict_pinned(bo);
-		xe_bo_unlock(bo, &ww);
+		xe_bo_unlock(bo, &exec);
 		xe_bo_put(bo);
 		if (ret) {
 			spin_lock(&xe->pinned.lock);
@@ -96,9 +98,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, &exec, 0, false);
 		ret = xe_bo_evict_pinned(bo);
-		xe_bo_unlock(bo, &ww);
+		xe_bo_unlock(bo, &exec);
 		xe_bo_put(bo);
 		if (ret)
 			return ret;
@@ -123,7 +125,7 @@ int xe_bo_evict_all(struct xe_device *xe)
  */
 int xe_bo_restore_kernel(struct xe_device *xe)
 {
-	struct ww_acquire_ctx ww;
+	struct drm_exec exec;
 	struct xe_bo *bo;
 	int ret;
 
@@ -140,9 +142,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, &exec, 0, false);
 		ret = xe_bo_restore_pinned(bo);
-		xe_bo_unlock(bo, &ww);
+		xe_bo_unlock(bo, &exec);
 		if (ret) {
 			xe_bo_put(bo);
 			return ret;
@@ -182,7 +184,7 @@ int xe_bo_restore_kernel(struct xe_device *xe)
  */
 int xe_bo_restore_user(struct xe_device *xe)
 {
-	struct ww_acquire_ctx ww;
+	struct drm_exec exec;
 	struct xe_bo *bo;
 	struct xe_gt *gt;
 	struct list_head still_in_list;
@@ -204,9 +206,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, &exec, 0, false);
 		ret = xe_bo_restore_pinned(bo);
-		xe_bo_unlock(bo, &ww);
+		xe_bo_unlock(bo, &exec);
 		xe_bo_put(bo);
 		if (ret) {
 			spin_lock(&xe->pinned.lock);
drivers/gpu/drm/xe/xe_bo_types.h +0 -1
index 06de3330211d..2ba34a8c9b66 100644
@@ -11,7 +11,6 @@
 #include <drm/drm_mm.h>
 #include <drm/ttm/ttm_bo.h>
 #include <drm/ttm/ttm_device.h>
-#include <drm/ttm/ttm_execbuf_util.h>
 #include <drm/ttm/ttm_placement.h>
 
 struct xe_device;
drivers/gpu/drm/xe/xe_engine.c +4 -3
index 91600b1e8249..8b425b777259 100644
@@ -8,6 +8,7 @@
 #include <linux/nospec.h>
 
 #include <drm/drm_device.h>
+#include <drm/drm_exec.h>
 #include <drm/drm_file.h>
 #include <drm/xe_drm.h>
 
@@ -89,18 +90,18 @@ struct xe_engine *xe_engine_create(struct xe_device *xe, struct xe_vm *vm,
 				   u32 logical_mask, u16 width,
 				   struct xe_hw_engine *hwe, u32 flags)
 {
-	struct ww_acquire_ctx ww;
+	struct drm_exec exec;
 	struct xe_engine *e;
 	int err;
 
 	if (vm) {
-		err = xe_vm_lock(vm, &ww, 0, true);
+		err = xe_vm_lock(vm, &exec, 0, true);
 		if (err)
 			return ERR_PTR(err);
 	}
 	e = __xe_engine_create(xe, vm, logical_mask, width, hwe, flags);
 	if (vm)
-		xe_vm_unlock(vm, &ww);
+		xe_vm_unlock(vm, &exec);
 
 	return e;
 }
drivers/gpu/drm/xe/xe_exec.c +13 -24
index 2ae02f1500d5..9f7f1088c403 100644
@@ -6,6 +6,7 @@
 #include "xe_exec.h"
 
 #include <drm/drm_device.h>
+#include <drm/drm_exec.h>
 #include <drm/drm_file.h>
 #include <drm/xe_drm.h>
 
@@ -92,21 +93,16 @@
  *	Unlock all
  */
 
-static int xe_exec_begin(struct xe_engine *e, struct ww_acquire_ctx *ww,
-			 struct ttm_validate_buffer tv_onstack[],
-			 struct ttm_validate_buffer **tv,
-			 struct list_head *objs)
+static int xe_exec_begin(struct xe_engine *e, struct drm_exec *exec)
 {
 	struct xe_vm *vm = e->vm;
 	struct xe_vma *vma;
-	LIST_HEAD(dups);
 	int err;
 
-	*tv = NULL;
 	if (xe_vm_no_dma_fences(e->vm))
 		return 0;
 
-	err = xe_vm_lock_dma_resv(vm, ww, tv_onstack, tv, objs, true, 1);
+	err = xe_vm_lock_dma_resv(vm, exec, true, 1);
 	if (err)
 		return err;
 
@@ -123,8 +119,7 @@ static int xe_exec_begin(struct xe_engine *e, struct ww_acquire_ctx *ww,
 
 		err = xe_bo_validate(xe_vma_bo(vma), vm, false);
 		if (err) {
-			xe_vm_unlock_dma_resv(vm, tv_onstack, *tv, ww, objs);
-			*tv = NULL;
+			xe_vm_unlock_dma_resv(vm, exec);
 			return err;
 		}
 	}
@@ -132,14 +127,10 @@ static int xe_exec_begin(struct xe_engine *e, struct ww_acquire_ctx *ww,
 	return 0;
 }
 
-static void xe_exec_end(struct xe_engine *e,
-			struct ttm_validate_buffer *tv_onstack,
-			struct ttm_validate_buffer *tv,
-			struct ww_acquire_ctx *ww,
-			struct list_head *objs)
+static void xe_exec_end(struct xe_engine *e, struct drm_exec *exec)
 {
 	if (!xe_vm_no_dma_fences(e->vm))
-		xe_vm_unlock_dma_resv(e->vm, tv_onstack, tv, ww, objs);
+		xe_vm_unlock_dma_resv(e->vm, exec);
 }
 
 int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
@@ -149,17 +140,14 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 	struct drm_xe_exec *args = data;
 	struct drm_xe_sync __user *syncs_user = u64_to_user_ptr(args->syncs);
 	u64 __user *addresses_user = u64_to_user_ptr(args->address);
+	struct drm_exec exec;
 	struct xe_engine *engine;
 	struct xe_sync_entry *syncs = NULL;
 	u64 addresses[XE_HW_ENGINE_MAX_INSTANCE];
-	struct ttm_validate_buffer tv_onstack[XE_ONSTACK_TV];
-	struct ttm_validate_buffer *tv = NULL;
 	u32 i, num_syncs = 0;
 	struct xe_sched_job *job;
 	struct dma_fence *rebind_fence;
 	struct xe_vm *vm;
-	struct ww_acquire_ctx ww;
-	struct list_head objs;
 	bool write_locked;
 	int err = 0;
 
@@ -270,7 +258,7 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 			goto err_unlock_list;
 	}
 
-	err = xe_exec_begin(engine, &ww, tv_onstack, &tv, &objs);
+	err = xe_exec_begin(engine, &exec);
 	if (err)
 		goto err_unlock_list;
 
@@ -361,9 +349,10 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 	 * are written as we don't pass in a read / write list.
 	 */
 	if (!xe_vm_no_dma_fences(vm))
-		drm_gpuva_add_fence(&vm->mgr, &job->drm.s_fence->finished,
-				    DMA_RESV_USAGE_BOOKKEEP,
-				    DMA_RESV_USAGE_WRITE);
+		drm_gpuva_manager_add_fence(&vm->mgr, &exec,
+					    &job->drm.s_fence->finished,
+					    DMA_RESV_USAGE_BOOKKEEP,
+					    DMA_RESV_USAGE_WRITE);
 
 	for (i = 0; i < num_syncs; i++)
 		xe_sync_entry_signal(&syncs[i], job,
@@ -387,7 +376,7 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 	if (err)
 		xe_sched_job_put(job);
 err_engine_end:
-	xe_exec_end(engine, tv_onstack, tv, &ww, &objs);
+	xe_exec_end(engine, &exec);
 err_unlock_list:
 	if (write_locked)
 		up_write(&vm->lock);
drivers/gpu/drm/xe/xe_gt_pagefault.c +7 -48
index d7bf6b0a0697..1145c6eaa17d 100644
@@ -9,7 +9,7 @@
 #include <linux/circ_buf.h>
 
 #include <drm/drm_managed.h>
-#include <drm/ttm/ttm_execbuf_util.h>
+#include <drm/drm_exec.h>
 
 #include "xe_bo.h"
 #include "xe_gt.h"
@@ -84,11 +84,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;
@@ -109,10 +104,7 @@ static int handle_pagefault(struct xe_gt *gt, struct pagefault *pf)
 	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 drm_exec exec;
 	struct dma_fence *fence;
 	bool write_locked;
 	int ret = 0;
@@ -170,20 +162,7 @@ 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)) {
-		/* This path ensures the BO's LRU is updated */
-		ret = xe_bo_lock(bo, &ww, xe->info.tile_count, false);
-	} else {
-		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);
-	}
+	ret = xe_vm_bo_lock(vm, bo, &exec, xe->info.tile_count, false);
 	if (ret)
 		goto unlock_vm;
 
@@ -226,10 +205,7 @@ static int handle_pagefault(struct xe_gt *gt, struct pagefault *pf)
 	vma->usm.gt_invalidated &= ~BIT(gt->info.id);
 
 unlock_dma_resv:
-	if (only_needs_bo_lock(bo))
-		xe_bo_unlock(bo, &ww);
-	else
-		ttm_eu_backoff_reservation(&ww, &objs);
+	xe_vm_bo_unlock(vm, bo, &exec, true);
 unlock_vm:
 	if (!ret)
 		vm->usm.last_fault_vma = vma;
@@ -496,10 +472,7 @@ static int handle_acc(struct xe_gt *gt, struct acc *acc)
 	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;
+	struct drm_exec exec;
 	int ret = 0;
 
 	/* We only support ACC_TRIGGER at the moment */
@@ -532,28 +505,14 @@ static int handle_acc(struct xe_gt *gt, struct acc *acc)
 
 	/* Lock VM and BOs dma-resv */
 	bo = xe_vma_bo(vma);
-	if (only_needs_bo_lock(bo)) {
-		/* This path ensures the BO's LRU is updated */
-		ret = xe_bo_lock(bo, &ww, xe->info.tile_count, false);
-	} else {
-		tv_vm.num_shared = xe->info.tile_count;
-		tv_vm.bo = xe_vm_ttm_bo(vm);
-		list_add(&tv_vm.head, &objs);
-		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);
-	}
+	ret = xe_vm_bo_lock(vm, bo, &exec, xe->info.tile_count, false);
 	if (ret)
 		goto unlock_vm;
 
 	/* Migrate to VRAM, move should invalidate the VMA first */
 	ret = xe_bo_migrate(bo, XE_PL_VRAM0 + gt->info.vram_id);
 
-	if (only_needs_bo_lock(bo))
-		xe_bo_unlock(bo, &ww);
-	else
-		ttm_eu_backoff_reservation(&ww, &objs);
+	xe_vm_bo_unlock(vm, bo, &exec, true);
 unlock_vm:
 	up_read(&vm->lock);
 	xe_vm_put(vm);
drivers/gpu/drm/xe/xe_lrc.c +5 -3
index ae605e7805de..3cc34efe8dd8 100644
@@ -3,6 +3,8 @@
  * Copyright © 2021 Intel Corporation
  */
 
+#include <drm/drm_exec.h>
+
 #include "xe_lrc.h"
 
 #include "regs/xe_engine_regs.h"
@@ -712,16 +714,16 @@ 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;
+	struct drm_exec exec;
 
 	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, &exec, 0, 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, &exec);
 	else
 		xe_bo_unlock_no_vm(lrc->bo);
 	xe_bo_put(lrc->bo);
drivers/gpu/drm/xe/xe_migrate.c +7 -6
index 91a06c925a1e..1dd497252640 100644
@@ -9,6 +9,7 @@
 #include <linux/sizes.h>
 
 #include <drm/drm_managed.h>
+#include <drm/drm_exec.h>
 #include <drm/ttm/ttm_tt.h>
 #include <drm/xe_drm.h>
 
@@ -86,13 +87,13 @@ struct xe_engine *xe_gt_migrate_engine(struct xe_gt *gt)
 static void xe_migrate_fini(struct drm_device *dev, void *arg)
 {
 	struct xe_migrate *m = arg;
-	struct ww_acquire_ctx ww;
+	struct drm_exec exec;
 
-	xe_vm_lock(m->eng->vm, &ww, 0, false);
+	xe_vm_lock(m->eng->vm, &exec, 0, false);
 	xe_bo_unpin(m->pt_bo);
 	if (m->cleared_bo)
 		xe_bo_unpin(m->cleared_bo);
-	xe_vm_unlock(m->eng->vm, &ww);
+	xe_vm_unlock(m->eng->vm, &exec);
 
 	dma_fence_put(m->fence);
 	if (m->cleared_bo)
@@ -315,7 +316,7 @@ struct xe_migrate *xe_migrate_init(struct xe_gt *gt)
 	struct xe_device *xe = gt_to_xe(gt);
 	struct xe_migrate *m;
 	struct xe_vm *vm;
-	struct ww_acquire_ctx ww;
+	struct drm_exec exec;
 	int err;
 
 	XE_BUG_ON(xe_gt_is_media_type(gt));
@@ -332,9 +333,9 @@ struct xe_migrate *xe_migrate_init(struct xe_gt *gt)
 	if (IS_ERR(vm))
 		return ERR_CAST(vm);
 
-	xe_vm_lock(vm, &ww, 0, false);
+	xe_vm_lock(vm, &exec, 0, false);
 	err = xe_migrate_prepare_vm(gt, m, vm);
-	xe_vm_unlock(vm, &ww);
+	xe_vm_unlock(vm, &exec);
 	if (err) {
 		xe_vm_close_and_put(vm);
 		return ERR_PTR(err);
drivers/gpu/drm/xe/xe_vm.c +120 -163
index 4d734ec4d6ab..55cced8870e6 100644
@@ -7,7 +7,7 @@
 
 #include <linux/dma-fence-array.h>
 
-#include <drm/ttm/ttm_execbuf_util.h>
+#include <drm/drm_exec.h>
 #include <drm/ttm/ttm_tt.h>
 #include <drm/xe_drm.h>
 #include <linux/kthread.h>
@@ -260,10 +260,10 @@ 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_engine *e;
-	struct ww_acquire_ctx ww;
+	struct drm_exec exec;
 	int err;
 
-	err = xe_bo_lock(bo, &ww, vm->preempt.num_engines, true);
+	err = xe_bo_lock(bo, &exec, vm->preempt.num_engines, true);
 	if (err)
 		return err;
 
@@ -274,11 +274,12 @@ static int add_preempt_fences(struct xe_vm *vm, struct xe_bo *bo)
 					   DMA_RESV_USAGE_BOOKKEEP);
 		}
 
-	xe_bo_unlock(bo, &ww);
+	xe_bo_unlock(bo, &exec);
 	return 0;
 }
 
-static void resume_and_reinstall_preempt_fences(struct xe_vm *vm)
+static void resume_and_reinstall_preempt_fences(struct xe_vm *vm,
+						struct drm_exec *exec)
 {
 	struct xe_engine *e;
 
@@ -288,18 +289,15 @@ static void resume_and_reinstall_preempt_fences(struct xe_vm *vm)
 	list_for_each_entry(e, &vm->preempt.engines, compute.link) {
 		e->ops->resume(e);
 
-		drm_gpuva_add_fence(&vm->mgr, e->compute.pfence,
-				    DMA_RESV_USAGE_BOOKKEEP,
-				    DMA_RESV_USAGE_BOOKKEEP);
+		drm_gpuva_manager_add_fence(&vm->mgr, exec, e->compute.pfence,
+					    DMA_RESV_USAGE_BOOKKEEP,
+					    DMA_RESV_USAGE_BOOKKEEP);
 	}
 }
 
 int xe_vm_add_compute_engine(struct xe_vm *vm, struct xe_engine *e)
 {
-	struct ttm_validate_buffer tv_onstack[XE_ONSTACK_TV];
-	struct ttm_validate_buffer *tv;
-	struct ww_acquire_ctx ww;
-	struct list_head objs;
+	struct drm_exec exec;
 	struct dma_fence *pfence;
 	int err;
 	bool wait;
@@ -308,7 +306,7 @@ int xe_vm_add_compute_engine(struct xe_vm *vm, struct xe_engine *e)
 
 	down_write(&vm->lock);
 
-	err = xe_vm_lock_dma_resv(vm, &ww, tv_onstack, &tv, &objs, true, 1);
+	err = xe_vm_lock_dma_resv(vm, &exec, true, 1);
 	if (err)
 		goto out_unlock_outer;
 
@@ -325,9 +323,9 @@ int xe_vm_add_compute_engine(struct xe_vm *vm, struct xe_engine *e)
 
 	down_read(&vm->userptr.notifier_lock);
 
-	drm_gpuva_add_fence(&vm->mgr, pfence,
-			    DMA_RESV_USAGE_BOOKKEEP,
-			    DMA_RESV_USAGE_BOOKKEEP);
+	drm_gpuva_manager_add_fence(&vm->mgr, &exec, pfence,
+				    DMA_RESV_USAGE_BOOKKEEP,
+				    DMA_RESV_USAGE_BOOKKEEP);
 
 	/*
 	 * Check to see if a preemption on VM is in flight or userptr
@@ -341,7 +339,7 @@ int xe_vm_add_compute_engine(struct xe_vm *vm, struct xe_engine *e)
 	up_read(&vm->userptr.notifier_lock);
 
 out_unlock:
-	xe_vm_unlock_dma_resv(vm, tv_onstack, tv, &ww, &objs);
+	xe_vm_unlock_dma_resv(vm, &exec);
 out_unlock_outer:
 	up_write(&vm->lock);
 
@@ -367,25 +365,24 @@ int __xe_vm_userptr_needs_repin(struct xe_vm *vm)
 		list_empty(&vm->userptr.invalidated)) ? 0 : -EAGAIN;
 }
 
+static struct drm_gem_object *xe_vm_gem(struct xe_vm *vm)
+{
+	int idx = vm->flags & XE_VM_FLAG_MIGRATION ?
+		XE_VM_FLAG_GT_ID(vm->flags) : 0;
+
+	/* Safe to use index 0 as all BO in the VM share a single dma-resv lock */
+	return &vm->pt_root[idx]->bo->ttm.base;
+}
+
 /**
  * xe_vm_lock_dma_resv() - Lock the vm dma_resv object and the dma_resv
  * objects of the vm's external buffer objects.
- * @vm: The vm.
- * @ww: Pointer to a struct ww_acquire_ctx locking context.
- * @tv_onstack: Array size XE_ONSTACK_TV of storage for the struct
- * ttm_validate_buffers used for locking.
- * @tv: Pointer to a pointer that on output contains the actual storage used.
- * @objs: List head for the buffer objects locked.
+ * @vm: The vm
  * @intr: Whether to lock interruptible.
  * @num_shared: Number of dma-fence slots to reserve in the locked objects.
  *
  * Locks the vm dma-resv objects and all the dma-resv objects of the
- * buffer objects on the vm external object list. The TTM utilities require
- * a list of struct ttm_validate_buffers pointing to the actual buffer
- * objects to lock. Storage for those struct ttm_validate_buffers should
- * be provided in @tv_onstack, and is typically reserved on the stack
- * of the caller. If the size of @tv_onstack isn't sufficient, then
- * storage will be allocated internally using kvmalloc().
+ * buffer objects on the vm external object list.
  *
  * The function performs deadlock handling internally, and after a
  * successful return the ww locking transaction should be considered
@@ -395,46 +392,18 @@ int __xe_vm_userptr_needs_repin(struct xe_vm *vm)
  * @intr is set to true, -EINTR or -ERESTARTSYS may be returned. In case
  * of error, any locking performed has been reverted.
  */
-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,
+int xe_vm_lock_dma_resv(struct xe_vm *vm, struct drm_exec *exec, bool intr,
 			unsigned int num_shared)
 {
-	struct ttm_validate_buffer *tv_vm, *tv_bo;
 	struct xe_vma *vma, *next;
-	struct drm_gpuva *gpuva;
-	LIST_HEAD(dups);
 	int err;
 
 	lockdep_assert_held(&vm->lock);
 
-	if (vm->mgr.extobj.entries < XE_ONSTACK_TV) {
-		tv_vm = tv_onstack;
-	} else {
-		tv_vm = kvmalloc_array(vm->mgr.extobj.entries + 1,
-				       sizeof(*tv_vm),
-				       GFP_KERNEL);
-		if (!tv_vm)
-			return -ENOMEM;
-	}
-	tv_bo = tv_vm + 1;
-
-	INIT_LIST_HEAD(objs);
-	drm_gpuva_for_each_extobj(gpuva, &vm->mgr) {
-		tv_bo->num_shared = num_shared;
-		tv_bo->bo = &gem_to_xe_bo(gpuva->gem.obj)->ttm;
-
-		list_add_tail(&tv_bo->head, objs);
-		tv_bo++;
-	}
-	tv_vm->num_shared = num_shared;
-	tv_vm->bo = xe_vm_ttm_bo(vm);
-	list_add_tail(&tv_vm->head, objs);
-	err = ttm_eu_reserve_buffers(ww, objs, intr, &dups);
+	err = drm_gpuva_manager_lock(&vm->mgr, exec, xe_vm_gem(vm), intr,
+				     num_shared);
 	if (err)
-		goto out_err;
+		return err;
 
 	spin_lock(&vm->notifier.list_lock);
 	list_for_each_entry_safe(vma, next, &vm->notifier.rebind_list,
@@ -447,34 +416,22 @@ int xe_vm_lock_dma_resv(struct xe_vm *vm, struct ww_acquire_ctx *ww,
 	}
 	spin_unlock(&vm->notifier.list_lock);
 
-	*tv = tv_vm;
 	return 0;
-
-out_err:
-	if (tv_vm != tv_onstack)
-		kvfree(tv_vm);
-
-	return err;
 }
 
 /**
  * xe_vm_unlock_dma_resv() - Unlock reservation objects locked by
  * xe_vm_lock_dma_resv()
  * @vm: The vm.
- * @tv_onstack: The @tv_onstack array given to xe_vm_lock_dma_resv().
- * @tv: The value of *@tv given by xe_vm_lock_dma_resv().
- * @ww: The ww_acquire_context used for locking.
- * @objs: The list returned from xe_vm_lock_dma_resv().
  *
  * Unlocks the reservation objects and frees any memory allocated by
  * xe_vm_lock_dma_resv().
  */
-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)
+void xe_vm_unlock_dma_resv(struct xe_vm *vm, struct drm_exec *exec)
 {
+	struct drm_gem_object *obj, *skip = xe_vm_gem(vm);
+	unsigned long index;
+
 	/*
 	 * Nothing should've been able to enter the list while we were locked,
 	 * since we've held the dma-resvs of all the vm's external objects,
@@ -483,19 +440,20 @@ void xe_vm_unlock_dma_resv(struct xe_vm *vm,
 	 */
 	XE_WARN_ON(!list_empty(&vm->notifier.rebind_list));
 
-	ttm_eu_backoff_reservation(ww, objs);
-	if (tv && tv != tv_onstack)
-		kvfree(tv);
+	drm_exec_for_each_locked_object(exec, index, obj) {
+		struct xe_bo *bo = gem_to_xe_bo(obj);
+
+		if (obj != skip)
+			ttm_bo_move_to_lru_tail_unlocked(&bo->ttm);
+	}
+	drm_gpuva_manager_unlock(&vm->mgr, exec);
 }
 
 static void preempt_rebind_work_func(struct work_struct *w)
 {
 	struct xe_vm *vm = container_of(w, struct xe_vm, preempt.rebind_work);
+	struct drm_exec exec;
 	struct xe_vma *vma;
-	struct ttm_validate_buffer tv_onstack[XE_ONSTACK_TV];
-	struct ttm_validate_buffer *tv;
-	struct ww_acquire_ctx ww;
-	struct list_head objs;
 	struct dma_fence *rebind_fence;
 	unsigned int fence_count = 0;
 	LIST_HEAD(preempt_fences);
@@ -536,8 +494,7 @@ static void preempt_rebind_work_func(struct work_struct *w)
 			goto out_unlock_outer;
 	}
 
-	err = xe_vm_lock_dma_resv(vm, &ww, tv_onstack, &tv, &objs,
-				  false, vm->preempt.num_engines);
+	err = xe_vm_lock_dma_resv(vm, &exec, false, vm->preempt.num_engines);
 	if (err)
 		goto out_unlock_outer;
 
@@ -608,11 +565,11 @@ static void preempt_rebind_work_func(struct work_struct *w)
 
 	/* Point of no return. */
 	arm_preempt_fences(vm, &preempt_fences);
-	resume_and_reinstall_preempt_fences(vm);
+	resume_and_reinstall_preempt_fences(vm, &exec);
 	up_read(&vm->userptr.notifier_lock);
 
 out_unlock:
-	xe_vm_unlock_dma_resv(vm, tv_onstack, tv, &ww, &objs);
+	xe_vm_unlock_dma_resv(vm, &exec);
 out_unlock_outer:
 	if (err == -EAGAIN) {
 		trace_xe_vm_rebind_worker_retry(vm);
@@ -963,27 +920,16 @@ static void xe_vma_destroy(struct xe_vma *vma, struct dma_fence *fence)
 
 static void xe_vma_destroy_unlocked(struct xe_vma *vma)
 {
-	struct ttm_validate_buffer tv[2];
-	struct ww_acquire_ctx ww;
+	struct xe_vm *vm = xe_vma_vm(vma);
 	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);
-	}
-	err = ttm_eu_reserve_buffers(&ww, &objs, false, &dups);
+	err = xe_vm_bo_lock(vm, xe_bo_get(bo), &exec, 0, false);
 	XE_WARN_ON(err);
-
 	xe_vma_destroy(vma, NULL);
+	xe_vm_bo_unlock(vm, bo, &exec, false);
 
-	ttm_eu_backoff_reservation(&ww, &objs);
 	if (bo)
 		xe_bo_put(bo);
 }
@@ -1254,7 +1200,7 @@ static void vm_error_capture(struct xe_vm *vm, int err,
 void xe_vm_close_and_put(struct xe_vm *vm)
 {
 	struct list_head contested;
-	struct ww_acquire_ctx ww;
+	struct drm_exec exec;
 	struct xe_device *xe = xe_vm_device(vm);
 	struct xe_gt *gt;
 	struct xe_vma *vma, *next_vma;
@@ -1281,7 +1227,7 @@ void xe_vm_close_and_put(struct xe_vm *vm)
 	}
 
 	down_write(&vm->lock);
-	xe_vm_lock(vm, &ww, 0, false);
+	xe_vm_lock(vm, &exec, 0, false);
 	drm_gpuva_iter_for_each(gpuva, it) {
 		vma = gpuva_to_vma(gpuva);
 
@@ -1323,7 +1269,7 @@ void xe_vm_close_and_put(struct xe_vm *vm)
 					      NULL);
 		}
 	}
-	xe_vm_unlock(vm, &ww);
+	xe_vm_unlock(vm, &exec);
 
 	/*
 	 * VM is now dead, cannot re-add nodes to vm->vmas if it's NULL
@@ -1356,7 +1302,7 @@ static void vm_destroy_work_func(struct work_struct *w)
 {
 	struct xe_vm *vm =
 		container_of(w, struct xe_vm, destroy_work);
-	struct ww_acquire_ctx ww;
+	struct drm_exec exec;
 	struct xe_device *xe = xe_vm_device(vm);
 	struct xe_gt *gt;
 	u8 id;
@@ -1382,14 +1328,14 @@ static void vm_destroy_work_func(struct work_struct *w)
 	 * is needed for xe_vm_lock to work. If we remove that dependency this
 	 * can be moved to xe_vm_close_and_put.
 	 */
-	xe_vm_lock(vm, &ww, 0, false);
+	xe_vm_lock(vm, &exec, 0, false);
 	for_each_gt(gt, xe, id) {
 		if (vm->pt_root[id]) {
 			xe_pt_destroy(vm->pt_root[id], vm->flags, NULL);
 			vm->pt_root[id] = NULL;
 		}
 	}
-	xe_vm_unlock(vm, &ww);
+	xe_vm_unlock(vm, &exec);
 
 	trace_xe_vm_free(vm);
 	dma_fence_put(vm->rebind_fence);
@@ -1969,21 +1915,6 @@ static int xe_vm_prefetch(struct xe_vm *vm, struct xe_vma *vma,
 
 #define VM_BIND_OP(op)	(op & 0xffff)
 
-struct ttm_buffer_object *xe_vm_ttm_bo(struct xe_vm *vm)
-{
-	int idx = vm->flags & XE_VM_FLAG_MIGRATION ?
-		XE_VM_FLAG_GT_ID(vm->flags) : 0;
-
-	/* Safe to use index 0 as all BO in the VM share a single dma-resv lock */
-	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);
@@ -2088,7 +2019,7 @@ vm_bind_ioctl_ops_create(struct xe_vm *vm, struct xe_bo *bo,
 			 u32 operation, u8 gt_mask, u32 region)
 {
 	struct drm_gem_object *obj = bo ? &bo->ttm.base : NULL;
-	struct ww_acquire_ctx ww;
+	struct drm_exec exec;
 	struct drm_gpuva_ops *ops;
 	struct drm_gpuva_op *__op;
 	struct xe_vma_op *op;
@@ -2136,11 +2067,11 @@ vm_bind_ioctl_ops_create(struct xe_vm *vm, struct xe_bo *bo,
 	case XE_VM_BIND_OP_UNMAP_ALL:
 		XE_BUG_ON(!bo);
 
-		err = xe_bo_lock(bo, &ww, 0, true);
+		err = xe_bo_lock(bo, &exec, 0, 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, &exec);
 
 		drm_gpuva_for_each_op(__op, ops) {
 			struct xe_vma_op *op = gpuva_op_to_vma_op(__op);
@@ -2174,13 +2105,13 @@ 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;
+	struct drm_exec exec;
 	int err;
 
 	lockdep_assert_held_write(&vm->lock);
 
 	if (bo) {
-		err = xe_bo_lock(bo, &ww, 0, true);
+		err = xe_bo_lock(bo, &exec, 0, true);
 		if (err)
 			return ERR_PTR(err);
 	}
@@ -2189,7 +2120,7 @@ static struct xe_vma *new_vma(struct xe_vm *vm, struct drm_gpuva_op_map *op,
 			    op->va.range - 1, read_only, null,
 			    gt_mask);
 	if (bo)
-		xe_bo_unlock(bo, &ww);
+		xe_bo_unlock(bo, &exec);
 
 	if (xe_vma_is_userptr(vma)) {
 		err = xe_vma_userptr_pin_pages(vma);
@@ -2441,19 +2372,15 @@ static int xe_vma_op_commit(struct xe_vm *vm, struct xe_vma_op *op)
 static int __xe_vma_op_execute(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;
+	struct drm_exec exec;
 	int err;
+	bool lru_update = op->base.op != DRM_GPUVA_OP_UNMAP;
 
 	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) {
+	if (vbo)
 		/*
 		 * An unbind can drop the last reference to the BO and
 		 * the BO is needed for ttm_eu_backoff_reservation so
@@ -2461,22 +2388,15 @@ static int __xe_vma_op_execute(struct xe_vm *vm, struct xe_vma *vma,
 		 */
 		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);
+	err = xe_vm_bo_lock(vm, vbo, &exec, 1, false);
 	if (err) {
 		xe_bo_put(vbo);
 		return err;
 	}
 
 	xe_vm_assert_held(vm);
-	xe_bo_assert_held(xe_vma_bo(vma));
+	xe_bo_assert_held(vbo);
 
 	switch (op->base.op) {
 	case DRM_GPUVA_OP_MAP:
@@ -2552,7 +2472,7 @@ static int __xe_vma_op_execute(struct xe_vm *vm, struct xe_vma *vma,
 		XE_BUG_ON("NOT POSSIBLE");
 	}
 
-	ttm_eu_backoff_reservation(&ww, &objs);
+	xe_vm_bo_unlock(vm, vbo, &exec, lru_update);
 	if (err == -EAGAIN && xe_vma_is_userptr(vma)) {
 		lockdep_assert_held_write(&vm->lock);
 		err = xe_vma_userptr_pin_pages(vma);
@@ -3208,30 +3128,67 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 	return err == -ENODATA ? 0 : err;
 }
 
-/*
- * XXX: Using the TTM wrappers for now, likely can call into dma-resv code
- * directly to optimize. Also this likely should be an inline function.
- */
-int xe_vm_lock(struct xe_vm *vm, struct ww_acquire_ctx *ww,
+int xe_vm_lock(struct xe_vm *vm, struct drm_exec *exec,
 	       int num_resv, bool intr)
 {
-	struct ttm_validate_buffer tv_vm;
-	LIST_HEAD(objs);
-	LIST_HEAD(dups);
+	int err;
 
-	XE_BUG_ON(!ww);
+	drm_exec_init(exec, intr);
+	drm_exec_while_not_all_locked(exec) {
+		err = drm_exec_prepare_obj(exec, xe_vm_gem(vm),
+					   num_resv);
+		drm_exec_continue_on_contention(exec);
+		if (err && err != -EALREADY)
+			goto out_err;
+	}
 
-	tv_vm.num_shared = num_resv;
-	tv_vm.bo = xe_vm_ttm_bo(vm);;
-	list_add_tail(&tv_vm.head, &objs);
+	return 0;
 
-	return ttm_eu_reserve_buffers(ww, &objs, intr, &dups);
+out_err:
+	drm_exec_fini(exec);
+	return err;
 }
 
-void xe_vm_unlock(struct xe_vm *vm, struct ww_acquire_ctx *ww)
+void xe_vm_unlock(struct xe_vm *vm, struct drm_exec *exec)
 {
-	dma_resv_unlock(xe_vm_resv(vm));
-	ww_acquire_fini(ww);
+	drm_exec_fini(exec);
+}
+
+int xe_vm_bo_lock(struct xe_vm *vm, struct xe_bo *bo, struct drm_exec *exec,
+		  int num_resv, bool intr)
+{
+	int err;
+
+	drm_exec_init(exec, intr);
+	drm_exec_while_not_all_locked(exec) {
+		err = drm_exec_prepare_obj(exec, xe_vm_gem(vm),
+					   num_resv);
+		drm_exec_continue_on_contention(exec);
+		if (err && err != -EALREADY)
+			goto out_err;
+
+		if (bo && !bo->vm) {
+			err = drm_exec_prepare_obj(exec, &bo->ttm.base,
+						   num_resv);
+			drm_exec_continue_on_contention(exec);
+			if (err && err != -EALREADY)
+				goto out_err;
+		}
+	}
+
+	return 0;
+
+out_err:
+	drm_exec_fini(exec);
+	return err;
+}
+
+void xe_vm_bo_unlock(struct xe_vm *vm, struct xe_bo *bo, struct drm_exec *exec,
+		     bool lru_update)
+{
+	if (lru_update && bo && (!bo->vm || xe_vm_no_dma_fences(vm)))
+		ttm_bo_move_to_lru_tail_unlocked(&bo->ttm);
+	drm_exec_fini(exec);
 }
 
 /**
drivers/gpu/drm/xe/xe_vm.h +9 -18
index f279fa622260..47b981d9fc04 100644
@@ -12,6 +12,7 @@
 #include "xe_vm_types.h"
 
 struct drm_device;
+struct drm_exec;
 struct drm_printer;
 struct drm_file;
 
@@ -38,10 +39,14 @@ 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 xe_vm_lock(struct xe_vm *vm, struct drm_exec *exec,
 	       int num_resv, bool intr);
+void xe_vm_unlock(struct xe_vm *vm, struct drm_exec *exec);
 
-void xe_vm_unlock(struct xe_vm *vm, struct ww_acquire_ctx *ww);
+int xe_vm_bo_lock(struct xe_vm *vm, struct xe_bo *bo, struct drm_exec *exec,
+		  int num_resv, bool intr);
+void xe_vm_bo_unlock(struct xe_vm *vm, struct xe_bo *bo, struct drm_exec *exec,
+		     bool lru_update);
 
 static inline bool xe_vm_is_closed(struct xe_vm *vm)
 {
@@ -219,23 +224,9 @@ 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,
+int xe_vm_lock_dma_resv(struct xe_vm *vm, struct drm_exec *exec, 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);
+void xe_vm_unlock_dma_resv(struct xe_vm *vm, struct drm_exec *exec);
 
 int xe_analyze_vm(struct drm_printer *p, struct xe_vm *vm, int gt_id);
 
drivers/gpu/drm/xe/xe_vm_madvise.c +19 -18
index 03508645fa08..a68bc6fec1de 100644
@@ -7,6 +7,7 @@
 
 #include <linux/nospec.h>
 
+#include <drm/drm_exec.h>
 #include <drm/ttm/ttm_tt.h>
 #include <drm/xe_drm.h>
 
@@ -28,16 +29,16 @@ 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;
+		struct drm_exec exec;
 
 		bo = xe_vma_bo(vmas[i]);
 
-		err = xe_bo_lock(bo, &ww, 0, true);
+		err = xe_bo_lock(bo, &exec, 0, 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, &exec);
 	}
 
 	return 0;
@@ -53,16 +54,16 @@ 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;
+		struct drm_exec exec;
 
 		bo = xe_vma_bo(vmas[i]);
 
-		err = xe_bo_lock(bo, &ww, 0, true);
+		err = xe_bo_lock(bo, &exec, 0, 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, &exec);
 	}
 
 	return 0;
@@ -89,17 +90,17 @@ 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;
+		struct drm_exec exec;
 
 		bo = xe_vma_bo(vmas[i]);
 
-		err = xe_bo_lock(bo, &ww, 0, true);
+		err = xe_bo_lock(bo, &exec, 0, 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, &exec);
 	}
 
 	return 0;
@@ -112,13 +113,13 @@ 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;
+		struct drm_exec exec;
 
 		bo = xe_vma_bo(vmas[i]);
 		if (XE_IOCTL_ERR(xe, !(bo->flags & XE_BO_CREATE_SYSTEM_BIT)))
 			return -EINVAL;
 
-		err = xe_bo_lock(bo, &ww, 0, true);
+		err = xe_bo_lock(bo, &exec, 0, true);
 		if (err)
 			return err;
 		bo->props.cpu_atomic = !!value;
@@ -130,7 +131,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, &exec);
 	}
 
 	return 0;
@@ -143,18 +144,18 @@ 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;
+		struct drm_exec exec;
 
 		bo = xe_vma_bo(vmas[i]);
 		if (XE_IOCTL_ERR(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, &exec, 0, true);
 		if (err)
 			return err;
 		bo->props.device_atomic = !!value;
-		xe_bo_unlock(bo, &ww);
+		xe_bo_unlock(bo, &exec);
 	}
 
 	return 0;
@@ -174,16 +175,16 @@ 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;
+		struct drm_exec exec;
 
 		bo = xe_vma_bo(vmas[i]);
 
-		err = xe_bo_lock(bo, &ww, 0, true);
+		err = xe_bo_lock(bo, &exec, 0, 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, &exec);
 	}
 
 	return 0;
include/drm/drm_gpuva_mgr.h +13 -3
index 943c8fcda533..a2f6d90ac899 100644
@@ -32,6 +32,8 @@
 #include <linux/spinlock.h>
 #include <linux/types.h>
 
+#include <drm/drm_exec.h>
+
 struct drm_gpuva_manager;
 struct drm_gpuva_fn_ops;
 struct drm_gpuva_prealloc;
@@ -169,9 +171,17 @@ struct drm_gpuva *drm_gpuva_find_next(struct drm_gpuva_manager *mgr, u64 end);
 
 bool drm_gpuva_interval_empty(struct drm_gpuva_manager *mgr, u64 addr, u64 range);
 
-void drm_gpuva_add_fence(struct drm_gpuva_manager *mgr, struct dma_fence *fence,
-			 enum dma_resv_usage private_usage,
-			 enum dma_resv_usage extobj_usage);
+int drm_gpuva_manager_lock(struct drm_gpuva_manager *mgr, struct drm_exec *exec,
+			   struct drm_gem_object *mgr_obj, bool intr,
+			   unsigned int num_fences);
+void drm_gpuva_manager_unlock(struct drm_gpuva_manager *mgr,
+			      struct drm_exec *exec);
+
+void drm_gpuva_manager_add_fence(struct drm_gpuva_manager *mgr,
+				 struct drm_exec *exec,
+				 struct dma_fence *fence,
+				 enum dma_resv_usage private_usage,
+				 enum dma_resv_usage extobj_usage);
 
 /**
  * drm_gpuva_evict - sets whether the backing GEM of this &drm_gpuva is evicted
Signature · 1 line
2.34.1
#107 lore raw

Re: [Intel-xe] [PATCH v2 27/31] drm/xe: Use drm_exec for locking rather than TTM exec helpers

In reply to Matthew Brost
Quoted 52 lines · Matthew Brost

drm_exec is intended to replace TTM exec helpers, use drm_exec. Also combine parts of drm_exec with gpuva where it makes sense (locking, fence installation).

---
  drivers/gpu/drm/drm_gpuva_mgr.c              |  67 ++++-
  drivers/gpu/drm/i915/display/intel_display.c |   6 +-
  drivers/gpu/drm/xe/Kconfig                   |   1 +
  drivers/gpu/drm/xe/tests/xe_bo.c             |  26 +-
  drivers/gpu/drm/xe/tests/xe_migrate.c        |   6 +-
  drivers/gpu/drm/xe/xe_bo.c                   |  56 ++--
  drivers/gpu/drm/xe/xe_bo.h                   |   6 +-
  drivers/gpu/drm/xe/xe_bo_evict.c             |  24 +-
  drivers/gpu/drm/xe/xe_bo_types.h             |   1 -
  drivers/gpu/drm/xe/xe_engine.c               |   7 +-
  drivers/gpu/drm/xe/xe_exec.c                 |  37 +--
  drivers/gpu/drm/xe/xe_gt_pagefault.c         |  55 +---
  drivers/gpu/drm/xe/xe_lrc.c                  |   8 +-
  drivers/gpu/drm/xe/xe_migrate.c              |  13 +-
  drivers/gpu/drm/xe/xe_vm.c                   | 283 ++++++++-----------
  drivers/gpu/drm/xe/xe_vm.h                   |  27 +-
  drivers/gpu/drm/xe/xe_vm_madvise.c           |  37 +--
  include/drm/drm_gpuva_mgr.h                  |  16 +-
  18 files changed, 315 insertions(+), 361 deletions(-)
drivers/gpu/drm/drm_gpuva_mgr.c +16 -0
index e8cd6e154336..93c912c34211 100644
@@ -483,6 +483,50 @@ drm_gpuva_manager_destroy(struct drm_gpuva_manager *mgr)
  }
  EXPORT_SYMBOL(drm_gpuva_manager_destroy);
 
+/**
+ * TODO
+ */
+int drm_gpuva_manager_lock(struct drm_gpuva_manager *mgr, struct drm_exec *exec,
+			   struct drm_gem_object *mgr_obj, bool intr,
+			   unsigned int num_fences)
+{
+	struct drm_gpuva *gpuva;
+	int ret;
+
+	drm_exec_init(exec, intr);
+	drm_exec_while_not_all_locked(exec) {
+		ret = drm_exec_prepare_obj(exec, mgr_obj, num_fences);
+		drm_exec_continue_on_contention(exec);
+		if (ret && ret != -EALREADY)
+			goto err_exec;

drivers/gpu/drm/drm_gpuva_mgr.c drm_gpuva_manager_destroy(struct drm_gpuva_manager *mgr) · line 511

Quoted 10 lines
drivers/gpu/drm/drm_gpuva_mgr.c +10 -0
+
+		drm_gpuva_for_each_extobj(gpuva, mgr) {
+			ret = drm_exec_prepare_obj(exec, gpuva->gem.obj,
+						   num_fences);
+			drm_exec_break_on_contention(exec);
+			if (ret && ret != -EALREADY)
+				goto err_exec;
+		}
+	}
+

I think that in the not too distant future we want to include the bo_validate() in the drm_exec_while_not_all_locked() loop (the WW transaction), in order to be able to use sleeping WW locks for eviction. And then this helper wouldn't be flexible enough, since we'd want o avoid vfuncs and probably want to open-code the loop in the driver.

Since Rodrigo already commented on splitting things up, could we do the drm_exec as a separate part before drm_exec / GPUVA integration, since, given the above, the latter might not lend itself very well to the needed flexibility.

/Thomas

Quoted 1,610 lines
drivers/gpu/drm/drm_gpuva_mgr.c +33 -8
+	return 0;
+
+err_exec:
+	drm_exec_fini(exec);
+	return ret;
+}
+EXPORT_SYMBOL(drm_gpuva_manager_lock);
+
+/**
+ * TODO
+ */
+void drm_gpuva_manager_unlock(struct drm_gpuva_manager *mgr,
+			      struct drm_exec *exec)
+{
+	drm_exec_fini(exec);
+}
+EXPORT_SYMBOL(drm_gpuva_manager_unlock);
+
  static inline bool
  drm_gpuva_in_mm_range(struct drm_gpuva_manager *mgr, u64 addr, u64 range)
  {
@@ -888,7 +932,7 @@ drm_gpuva_interval_empty(struct drm_gpuva_manager *mgr, u64 addr, u64 range)
  EXPORT_SYMBOL(drm_gpuva_interval_empty);
 
  /**
- * drm_gpuva_add_fence - add fence to private and all extobj dma-resv
+ * drm_gpuva_manager_add_fence - add fence to private and all extobj dma-resv
   * @mgr: the &drm_gpuva_manager to add a fence to
   * @fence: fence to add
   * @private_usage: private dma-resv usage
@@ -896,17 +940,24 @@ EXPORT_SYMBOL(drm_gpuva_interval_empty);
   *
   * Returns: true if the interval is empty, false otherwise
   */
-void drm_gpuva_add_fence(struct drm_gpuva_manager *mgr, struct dma_fence *fence,
-			 enum dma_resv_usage private_usage,
-			 enum dma_resv_usage extobj_usage)
+void drm_gpuva_manager_add_fence(struct drm_gpuva_manager *mgr,
+				 struct drm_exec *exec,
+				 struct dma_fence *fence,
+				 enum dma_resv_usage private_usage,
+				 enum dma_resv_usage extobj_usage)
  {
-	struct drm_gpuva *gpuva;
+	struct drm_gem_object *obj;
+	unsigned long index;
+
+	dma_resv_assert_held(&mgr->resv);
 
  	dma_resv_add_fence(&mgr->resv, fence, private_usage);
-	drm_gpuva_for_each_extobj(gpuva, mgr)
-		dma_resv_add_fence(gpuva->gem.obj->resv, fence, extobj_usage);
+	drm_exec_for_each_locked_object(exec, index, obj)
+		if (likely(&mgr->resv != obj->resv))
+			dma_resv_add_fence(obj->resv, fence, extobj_usage);
  }
-EXPORT_SYMBOL(drm_gpuva_add_fence);
+EXPORT_SYMBOL(drm_gpuva_manager_add_fence);
+
 
  /**
   * drm_gpuva_map - helper to insert a &drm_gpuva from &drm_gpuva_fn_ops
drivers/gpu/drm/i915/display/intel_display.c +3 -3
index 28a227450329..aab1a3a0f06d 100644
@@ -7340,11 +7340,11 @@ static int i915_gem_object_read_from_page(struct xe_bo *bo,
  	void *virtual;
  	bool is_iomem;
  	int ret;
-	struct ww_acquire_ctx ww;
+	struct drm_exec exec;
 
  	XE_BUG_ON(size != 8);
 
-	ret = xe_bo_lock(bo, &ww, 0, true);
+	ret = xe_bo_lock(bo, &exec, 0, true);
  	if (ret)
  		return ret;
 
@@ -7361,7 +7361,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, &exec);
  	return ret;
  }
  #endif
drivers/gpu/drm/xe/Kconfig +1 -0
index f6f3b491d162..bbcc9b64b776 100644
@@ -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/tests/xe_bo.c +13 -13
index 9bd381e5b7a6..316c6cf2bb86 100644
@@ -175,17 +175,17 @@ static int evict_test_run_gt(struct xe_device *xe, struct xe_gt *gt, struct kuni
  	unsigned int bo_flags = XE_BO_CREATE_USER_BIT |
  		XE_BO_CREATE_VRAM_IF_DGFX(gt);
  	struct xe_vm *vm = xe_migrate_get_vm(xe->gt[0].migrate);
-	struct ww_acquire_ctx ww;
+	struct drm_exec exec;
  	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->info.vram_id);
 
  	for (i = 0; i < 2; ++i) {
-		xe_vm_lock(vm, &ww, 0, false);
+		xe_vm_lock(vm, &exec, 0, false);
  		bo = xe_bo_create(xe, NULL, vm, 0x10000, ttm_bo_type_device,
  				  bo_flags);
-		xe_vm_unlock(vm, &ww);
+		xe_vm_unlock(vm, &exec);
  		if (IS_ERR(bo)) {
  			KUNIT_FAIL(test, "bo create err=%pe\n", bo);
  			break;
@@ -198,9 +198,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, &exec, 0, false);
  		err = xe_bo_pin_external(external);
-		xe_bo_unlock(external, &ww);
+		xe_bo_unlock(external, &exec);
  		if (err) {
  			KUNIT_FAIL(test, "external bo pin err=%pe\n",
  				   ERR_PTR(err));
@@ -240,18 +240,18 @@ static int evict_test_run_gt(struct xe_device *xe, struct xe_gt *gt, struct kuni
 
  		if (i) {
  			down_read(&vm->lock);
-			xe_vm_lock(vm, &ww, 0, false);
+			xe_vm_lock(vm, &exec, 0, false);
  			err = xe_bo_validate(bo, bo->vm, false);
-			xe_vm_unlock(vm, &ww);
+			xe_vm_unlock(vm, &exec);
  			up_read(&vm->lock);
  			if (err) {
  				KUNIT_FAIL(test, "bo valid err=%pe\n",
  					   ERR_PTR(err));
  				goto cleanup_all;
  			}
-			xe_bo_lock(external, &ww, 0, false);
+			xe_bo_lock(external, &exec, 0, false);
  			err = xe_bo_validate(external, NULL, false);
-			xe_bo_unlock(external, &ww);
+			xe_bo_unlock(external, &exec);
  			if (err) {
  				KUNIT_FAIL(test, "external bo valid err=%pe\n",
  					   ERR_PTR(err));
@@ -259,18 +259,18 @@ 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, &exec, 0, false);
  		xe_bo_unpin_external(external);
-		xe_bo_unlock(external, &ww);
+		xe_bo_unlock(external, &exec);
 
  		xe_bo_put(external);
  		xe_bo_put(bo);
  		continue;
 
  cleanup_all:
-		xe_bo_lock(external, &ww, 0, false);
+		xe_bo_lock(external, &exec, 0, false);
  		xe_bo_unpin_external(external);
-		xe_bo_unlock(external, &ww);
+		xe_bo_unlock(external, &exec);
  cleanup_external:
  		xe_bo_put(external);
  cleanup_bo:
drivers/gpu/drm/xe/tests/xe_migrate.c +3 -3
index 0f4371ad1fd9..e1482b4491b1 100644
@@ -394,14 +394,14 @@ static int migrate_test_run_device(struct xe_device *xe)
 
  	for_each_gt(gt, xe, id) {
  		struct xe_migrate *m = gt->migrate;
-		struct ww_acquire_ctx ww;
+		struct drm_exec exec;
 
  		kunit_info(test, "Testing gt id %d.\n", id);
-		xe_vm_lock(m->eng->vm, &ww, 0, true);
+		xe_vm_lock(m->eng->vm, &exec, 0, true);
  		xe_device_mem_access_get(xe);
  		xe_migrate_sanity_test(m, test);
  		xe_device_mem_access_put(xe);
-		xe_vm_unlock(m->eng->vm, &ww);
+		xe_vm_unlock(m->eng->vm, &exec);
  	}
 
  	return 0;
drivers/gpu/drm/xe/xe_bo.c +23 -33
index e0422ffb6327..a427edbf486b 100644
@@ -8,6 +8,7 @@
  #include <linux/dma-buf.h>
 
  #include <drm/drm_drv.h>
+#include <drm/drm_exec.h>
  #include <drm/drm_gem_ttm_helper.h>
  #include <drm/ttm/ttm_device.h>
  #include <drm/ttm/ttm_placement.h>
@@ -991,13 +992,13 @@ static void xe_gem_object_close(struct drm_gem_object *obj,
  	struct xe_bo *bo = gem_to_xe_bo(obj);
 
  	if (bo->vm && !xe_vm_no_dma_fences(bo->vm)) {
-		struct ww_acquire_ctx ww;
+		struct drm_exec exec;
 
  		XE_BUG_ON(!xe_bo_is_user(bo));
 
-		xe_bo_lock(bo, &ww, 0, false);
+		xe_bo_lock(bo, &exec, 0, false);
  		ttm_bo_set_bulk_move(&bo->ttm, NULL);
-		xe_bo_unlock(bo, &ww);
+		xe_bo_unlock(bo, &exec);
  	}
  }
 
@@ -1402,11 +1403,6 @@ int xe_bo_pin_external(struct xe_bo *bo)
  	}
 
  	ttm_bo_pin(&bo->ttm);
-
-	/*
-	 * FIXME: If we always use the reserve / unreserve functions for locking
-	 * we do not need this.
-	 */
  	ttm_bo_move_to_lru_tail_unlocked(&bo->ttm);
 
  	return 0;
@@ -1461,11 +1457,6 @@ int xe_bo_pin(struct xe_bo *bo)
  	}
 
  	ttm_bo_pin(&bo->ttm);
-
-	/*
-	 * FIXME: If we always use the reserve / unreserve functions for locking
-	 * we do not need this.
-	 */
  	ttm_bo_move_to_lru_tail_unlocked(&bo->ttm);
 
  	return 0;
@@ -1496,11 +1487,6 @@ void xe_bo_unpin_external(struct xe_bo *bo)
  	}
 
  	ttm_bo_unpin(&bo->ttm);
-
-	/*
-	 * FIXME: If we always use the reserve / unreserve functions for locking
-	 * we do not need this.
-	 */
  	ttm_bo_move_to_lru_tail_unlocked(&bo->ttm);
  }
 
@@ -1650,7 +1636,7 @@ 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 drm_exec exec;
  	struct xe_vm *vm = NULL;
  	struct xe_bo *bo;
  	unsigned bo_flags = XE_BO_CREATE_USER_BIT;
@@ -1686,7 +1672,7 @@ int xe_gem_create_ioctl(struct drm_device *dev, void *data,
  		vm = xe_vm_lookup(xef, args->vm_id);
  		if (XE_IOCTL_ERR(xe, !vm))
  			return -ENOENT;
-		err = xe_vm_lock(vm, &ww, 0, true);
+		err = xe_vm_lock(vm, &exec, 0, true);
  		if (err) {
  			xe_vm_put(vm);
  			return err;
@@ -1703,7 +1689,7 @@ int xe_gem_create_ioctl(struct drm_device *dev, void *data,
  	bo = xe_bo_create(xe, NULL, vm, args->size, ttm_bo_type_device,
  			  bo_flags);
  	if (vm) {
-		xe_vm_unlock(vm, &ww);
+		xe_vm_unlock(vm, &exec);
  		xe_vm_put(vm);
  	}
 
@@ -1744,26 +1730,30 @@ int xe_gem_mmap_offset_ioctl(struct drm_device *dev, void *data,
  	return 0;
  }
 
-int xe_bo_lock(struct xe_bo *bo, struct ww_acquire_ctx *ww,
+int xe_bo_lock(struct xe_bo *bo, struct drm_exec *exec,
  	       int num_resv, bool intr)
  {
-	struct ttm_validate_buffer tv_bo;
-	LIST_HEAD(objs);
-	LIST_HEAD(dups);
+	int err;
 
-	XE_BUG_ON(!ww);
+	drm_exec_init(exec, intr);
+	drm_exec_while_not_all_locked(exec) {
+		err = drm_exec_prepare_obj(exec, &bo->ttm.base,
+					   num_resv);
+		drm_exec_continue_on_contention(exec);
+		if (err && err != -EALREADY)
+			goto out_err;
+	}
 
-	tv_bo.num_shared = num_resv;
-	tv_bo.bo = &bo->ttm;;
-	list_add_tail(&tv_bo.head, &objs);
+	return 0;
 
-	return ttm_eu_reserve_buffers(ww, &objs, intr, &dups);
+out_err:
+	drm_exec_fini(exec);
+	return err;
  }
 
-void xe_bo_unlock(struct xe_bo *bo, struct ww_acquire_ctx *ww)
+void xe_bo_unlock(struct xe_bo *bo, struct drm_exec *exec)
  {
-	dma_resv_unlock(bo->ttm.base.resv);
-	ww_acquire_fini(ww);
+	drm_exec_fini(exec);
  }
 
  /**
drivers/gpu/drm/xe/xe_bo.h +3 -3
index 9b401d30a130..5a80ebf72d10 100644
@@ -75,6 +75,7 @@
 
  #define XE_BO_PROPS_INVALID	(-1)
 
+struct drm_exec;
  struct sg_table;
 
  struct xe_bo *xe_bo_alloc(void);
@@ -142,10 +143,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 xe_bo_lock(struct xe_bo *bo, struct drm_exec *exec,
  	       int num_resv, bool intr);
-
-void xe_bo_unlock(struct xe_bo *bo, struct ww_acquire_ctx *ww);
+void xe_bo_unlock(struct xe_bo *bo, struct drm_exec *exec);
 
  static inline void xe_bo_unlock_vm_held(struct xe_bo *bo)
  {
drivers/gpu/drm/xe/xe_bo_evict.c +13 -11
index 6642c5f52009..46d9d9eb110c 100644
@@ -3,6 +3,8 @@
   * Copyright © 2022 Intel Corporation
   */
 
+#include <drm/drm_exec.h>
+
  #include "xe_bo_evict.h"
 
  #include "xe_bo.h"
@@ -27,7 +29,7 @@
  int xe_bo_evict_all(struct xe_device *xe)
  {
  	struct ttm_device *bdev = &xe->ttm;
-	struct ww_acquire_ctx ww;
+	struct drm_exec exec;
  	struct xe_bo *bo;
  	struct xe_gt *gt;
  	struct list_head still_in_list;
@@ -62,9 +64,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, &exec, 0, false);
  		ret = xe_bo_evict_pinned(bo);
-		xe_bo_unlock(bo, &ww);
+		xe_bo_unlock(bo, &exec);
  		xe_bo_put(bo);
  		if (ret) {
  			spin_lock(&xe->pinned.lock);
@@ -96,9 +98,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, &exec, 0, false);
  		ret = xe_bo_evict_pinned(bo);
-		xe_bo_unlock(bo, &ww);
+		xe_bo_unlock(bo, &exec);
  		xe_bo_put(bo);
  		if (ret)
  			return ret;
@@ -123,7 +125,7 @@ int xe_bo_evict_all(struct xe_device *xe)
   */
  int xe_bo_restore_kernel(struct xe_device *xe)
  {
-	struct ww_acquire_ctx ww;
+	struct drm_exec exec;
  	struct xe_bo *bo;
  	int ret;
 
@@ -140,9 +142,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, &exec, 0, false);
  		ret = xe_bo_restore_pinned(bo);
-		xe_bo_unlock(bo, &ww);
+		xe_bo_unlock(bo, &exec);
  		if (ret) {
  			xe_bo_put(bo);
  			return ret;
@@ -182,7 +184,7 @@ int xe_bo_restore_kernel(struct xe_device *xe)
   */
  int xe_bo_restore_user(struct xe_device *xe)
  {
-	struct ww_acquire_ctx ww;
+	struct drm_exec exec;
  	struct xe_bo *bo;
  	struct xe_gt *gt;
  	struct list_head still_in_list;
@@ -204,9 +206,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, &exec, 0, false);
  		ret = xe_bo_restore_pinned(bo);
-		xe_bo_unlock(bo, &ww);
+		xe_bo_unlock(bo, &exec);
  		xe_bo_put(bo);
  		if (ret) {
  			spin_lock(&xe->pinned.lock);
drivers/gpu/drm/xe/xe_bo_types.h +0 -1
index 06de3330211d..2ba34a8c9b66 100644
@@ -11,7 +11,6 @@
  #include <drm/drm_mm.h>
  #include <drm/ttm/ttm_bo.h>
  #include <drm/ttm/ttm_device.h>
-#include <drm/ttm/ttm_execbuf_util.h>
  #include <drm/ttm/ttm_placement.h>
 
  struct xe_device;
drivers/gpu/drm/xe/xe_engine.c +4 -3
index 91600b1e8249..8b425b777259 100644
@@ -8,6 +8,7 @@
  #include <linux/nospec.h>
 
  #include <drm/drm_device.h>
+#include <drm/drm_exec.h>
  #include <drm/drm_file.h>
  #include <drm/xe_drm.h>
 
@@ -89,18 +90,18 @@ struct xe_engine *xe_engine_create(struct xe_device *xe, struct xe_vm *vm,
  				   u32 logical_mask, u16 width,
  				   struct xe_hw_engine *hwe, u32 flags)
  {
-	struct ww_acquire_ctx ww;
+	struct drm_exec exec;
  	struct xe_engine *e;
  	int err;
 
  	if (vm) {
-		err = xe_vm_lock(vm, &ww, 0, true);
+		err = xe_vm_lock(vm, &exec, 0, true);
  		if (err)
  			return ERR_PTR(err);
  	}
  	e = __xe_engine_create(xe, vm, logical_mask, width, hwe, flags);
  	if (vm)
-		xe_vm_unlock(vm, &ww);
+		xe_vm_unlock(vm, &exec);
 
  	return e;
  }
drivers/gpu/drm/xe/xe_exec.c +13 -24
index 2ae02f1500d5..9f7f1088c403 100644
@@ -6,6 +6,7 @@
  #include "xe_exec.h"
 
  #include <drm/drm_device.h>
+#include <drm/drm_exec.h>
  #include <drm/drm_file.h>
  #include <drm/xe_drm.h>
 
@@ -92,21 +93,16 @@
   *	Unlock all
   */
 
-static int xe_exec_begin(struct xe_engine *e, struct ww_acquire_ctx *ww,
-			 struct ttm_validate_buffer tv_onstack[],
-			 struct ttm_validate_buffer **tv,
-			 struct list_head *objs)
+static int xe_exec_begin(struct xe_engine *e, struct drm_exec *exec)
  {
  	struct xe_vm *vm = e->vm;
  	struct xe_vma *vma;
-	LIST_HEAD(dups);
  	int err;
 
-	*tv = NULL;
  	if (xe_vm_no_dma_fences(e->vm))
  		return 0;
 
-	err = xe_vm_lock_dma_resv(vm, ww, tv_onstack, tv, objs, true, 1);
+	err = xe_vm_lock_dma_resv(vm, exec, true, 1);
  	if (err)
  		return err;
 
@@ -123,8 +119,7 @@ static int xe_exec_begin(struct xe_engine *e, struct ww_acquire_ctx *ww,
 
  		err = xe_bo_validate(xe_vma_bo(vma), vm, false);
  		if (err) {
-			xe_vm_unlock_dma_resv(vm, tv_onstack, *tv, ww, objs);
-			*tv = NULL;
+			xe_vm_unlock_dma_resv(vm, exec);
  			return err;
  		}
  	}
@@ -132,14 +127,10 @@ static int xe_exec_begin(struct xe_engine *e, struct ww_acquire_ctx *ww,
  	return 0;
  }
 
-static void xe_exec_end(struct xe_engine *e,
-			struct ttm_validate_buffer *tv_onstack,
-			struct ttm_validate_buffer *tv,
-			struct ww_acquire_ctx *ww,
-			struct list_head *objs)
+static void xe_exec_end(struct xe_engine *e, struct drm_exec *exec)
  {
  	if (!xe_vm_no_dma_fences(e->vm))
-		xe_vm_unlock_dma_resv(e->vm, tv_onstack, tv, ww, objs);
+		xe_vm_unlock_dma_resv(e->vm, exec);
  }
 
  int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
@@ -149,17 +140,14 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
  	struct drm_xe_exec *args = data;
  	struct drm_xe_sync __user *syncs_user = u64_to_user_ptr(args->syncs);
  	u64 __user *addresses_user = u64_to_user_ptr(args->address);
+	struct drm_exec exec;
  	struct xe_engine *engine;
  	struct xe_sync_entry *syncs = NULL;
  	u64 addresses[XE_HW_ENGINE_MAX_INSTANCE];
-	struct ttm_validate_buffer tv_onstack[XE_ONSTACK_TV];
-	struct ttm_validate_buffer *tv = NULL;
  	u32 i, num_syncs = 0;
  	struct xe_sched_job *job;
  	struct dma_fence *rebind_fence;
  	struct xe_vm *vm;
-	struct ww_acquire_ctx ww;
-	struct list_head objs;
  	bool write_locked;
  	int err = 0;
 
@@ -270,7 +258,7 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
  			goto err_unlock_list;
  	}
 
-	err = xe_exec_begin(engine, &ww, tv_onstack, &tv, &objs);
+	err = xe_exec_begin(engine, &exec);
  	if (err)
  		goto err_unlock_list;
 
@@ -361,9 +349,10 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
  	 * are written as we don't pass in a read / write list.
  	 */
  	if (!xe_vm_no_dma_fences(vm))
-		drm_gpuva_add_fence(&vm->mgr, &job->drm.s_fence->finished,
-				    DMA_RESV_USAGE_BOOKKEEP,
-				    DMA_RESV_USAGE_WRITE);
+		drm_gpuva_manager_add_fence(&vm->mgr, &exec,
+					    &job->drm.s_fence->finished,
+					    DMA_RESV_USAGE_BOOKKEEP,
+					    DMA_RESV_USAGE_WRITE);
 
  	for (i = 0; i < num_syncs; i++)
  		xe_sync_entry_signal(&syncs[i], job,
@@ -387,7 +376,7 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
  	if (err)
  		xe_sched_job_put(job);
  err_engine_end:
-	xe_exec_end(engine, tv_onstack, tv, &ww, &objs);
+	xe_exec_end(engine, &exec);
  err_unlock_list:
  	if (write_locked)
  		up_write(&vm->lock);
drivers/gpu/drm/xe/xe_gt_pagefault.c +7 -48
index d7bf6b0a0697..1145c6eaa17d 100644
@@ -9,7 +9,7 @@
  #include <linux/circ_buf.h>
 
  #include <drm/drm_managed.h>
-#include <drm/ttm/ttm_execbuf_util.h>
+#include <drm/drm_exec.h>
 
  #include "xe_bo.h"
  #include "xe_gt.h"
@@ -84,11 +84,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;
@@ -109,10 +104,7 @@ static int handle_pagefault(struct xe_gt *gt, struct pagefault *pf)
  	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 drm_exec exec;
  	struct dma_fence *fence;
  	bool write_locked;
  	int ret = 0;
@@ -170,20 +162,7 @@ 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)) {
-		/* This path ensures the BO's LRU is updated */
-		ret = xe_bo_lock(bo, &ww, xe->info.tile_count, false);
-	} else {
-		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);
-	}
+	ret = xe_vm_bo_lock(vm, bo, &exec, xe->info.tile_count, false);
  	if (ret)
  		goto unlock_vm;
 
@@ -226,10 +205,7 @@ static int handle_pagefault(struct xe_gt *gt, struct pagefault *pf)
  	vma->usm.gt_invalidated &= ~BIT(gt->info.id);
 
  unlock_dma_resv:
-	if (only_needs_bo_lock(bo))
-		xe_bo_unlock(bo, &ww);
-	else
-		ttm_eu_backoff_reservation(&ww, &objs);
+	xe_vm_bo_unlock(vm, bo, &exec, true);
  unlock_vm:
  	if (!ret)
  		vm->usm.last_fault_vma = vma;
@@ -496,10 +472,7 @@ static int handle_acc(struct xe_gt *gt, struct acc *acc)
  	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;
+	struct drm_exec exec;
  	int ret = 0;
 
  	/* We only support ACC_TRIGGER at the moment */
@@ -532,28 +505,14 @@ static int handle_acc(struct xe_gt *gt, struct acc *acc)
 
  	/* Lock VM and BOs dma-resv */
  	bo = xe_vma_bo(vma);
-	if (only_needs_bo_lock(bo)) {
-		/* This path ensures the BO's LRU is updated */
-		ret = xe_bo_lock(bo, &ww, xe->info.tile_count, false);
-	} else {
-		tv_vm.num_shared = xe->info.tile_count;
-		tv_vm.bo = xe_vm_ttm_bo(vm);
-		list_add(&tv_vm.head, &objs);
-		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);
-	}
+	ret = xe_vm_bo_lock(vm, bo, &exec, xe->info.tile_count, false);
  	if (ret)
  		goto unlock_vm;
 
  	/* Migrate to VRAM, move should invalidate the VMA first */
  	ret = xe_bo_migrate(bo, XE_PL_VRAM0 + gt->info.vram_id);
 
-	if (only_needs_bo_lock(bo))
-		xe_bo_unlock(bo, &ww);
-	else
-		ttm_eu_backoff_reservation(&ww, &objs);
+	xe_vm_bo_unlock(vm, bo, &exec, true);
  unlock_vm:
  	up_read(&vm->lock);
  	xe_vm_put(vm);
drivers/gpu/drm/xe/xe_lrc.c +5 -3
index ae605e7805de..3cc34efe8dd8 100644
@@ -3,6 +3,8 @@
   * Copyright © 2021 Intel Corporation
   */
 
+#include <drm/drm_exec.h>
+
  #include "xe_lrc.h"
 
  #include "regs/xe_engine_regs.h"
@@ -712,16 +714,16 @@ 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;
+	struct drm_exec exec;
 
  	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, &exec, 0, 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, &exec);
  	else
  		xe_bo_unlock_no_vm(lrc->bo);
  	xe_bo_put(lrc->bo);
drivers/gpu/drm/xe/xe_migrate.c +7 -6
index 91a06c925a1e..1dd497252640 100644
@@ -9,6 +9,7 @@
  #include <linux/sizes.h>
 
  #include <drm/drm_managed.h>
+#include <drm/drm_exec.h>
  #include <drm/ttm/ttm_tt.h>
  #include <drm/xe_drm.h>
 
@@ -86,13 +87,13 @@ struct xe_engine *xe_gt_migrate_engine(struct xe_gt *gt)
  static void xe_migrate_fini(struct drm_device *dev, void *arg)
  {
  	struct xe_migrate *m = arg;
-	struct ww_acquire_ctx ww;
+	struct drm_exec exec;
 
-	xe_vm_lock(m->eng->vm, &ww, 0, false);
+	xe_vm_lock(m->eng->vm, &exec, 0, false);
  	xe_bo_unpin(m->pt_bo);
  	if (m->cleared_bo)
  		xe_bo_unpin(m->cleared_bo);
-	xe_vm_unlock(m->eng->vm, &ww);
+	xe_vm_unlock(m->eng->vm, &exec);
 
  	dma_fence_put(m->fence);
  	if (m->cleared_bo)
@@ -315,7 +316,7 @@ struct xe_migrate *xe_migrate_init(struct xe_gt *gt)
  	struct xe_device *xe = gt_to_xe(gt);
  	struct xe_migrate *m;
  	struct xe_vm *vm;
-	struct ww_acquire_ctx ww;
+	struct drm_exec exec;
  	int err;
 
  	XE_BUG_ON(xe_gt_is_media_type(gt));
@@ -332,9 +333,9 @@ struct xe_migrate *xe_migrate_init(struct xe_gt *gt)
  	if (IS_ERR(vm))
  		return ERR_CAST(vm);
 
-	xe_vm_lock(vm, &ww, 0, false);
+	xe_vm_lock(vm, &exec, 0, false);
  	err = xe_migrate_prepare_vm(gt, m, vm);
-	xe_vm_unlock(vm, &ww);
+	xe_vm_unlock(vm, &exec);
  	if (err) {
  		xe_vm_close_and_put(vm);
  		return ERR_PTR(err);
drivers/gpu/drm/xe/xe_vm.c +120 -163
index 4d734ec4d6ab..55cced8870e6 100644
@@ -7,7 +7,7 @@
 
  #include <linux/dma-fence-array.h>
 
-#include <drm/ttm/ttm_execbuf_util.h>
+#include <drm/drm_exec.h>
  #include <drm/ttm/ttm_tt.h>
  #include <drm/xe_drm.h>
  #include <linux/kthread.h>
@@ -260,10 +260,10 @@ 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_engine *e;
-	struct ww_acquire_ctx ww;
+	struct drm_exec exec;
  	int err;
 
-	err = xe_bo_lock(bo, &ww, vm->preempt.num_engines, true);
+	err = xe_bo_lock(bo, &exec, vm->preempt.num_engines, true);
  	if (err)
  		return err;
 
@@ -274,11 +274,12 @@ static int add_preempt_fences(struct xe_vm *vm, struct xe_bo *bo)
  					   DMA_RESV_USAGE_BOOKKEEP);
  		}
 
-	xe_bo_unlock(bo, &ww);
+	xe_bo_unlock(bo, &exec);
  	return 0;
  }
 
-static void resume_and_reinstall_preempt_fences(struct xe_vm *vm)
+static void resume_and_reinstall_preempt_fences(struct xe_vm *vm,
+						struct drm_exec *exec)
  {
  	struct xe_engine *e;
 
@@ -288,18 +289,15 @@ static void resume_and_reinstall_preempt_fences(struct xe_vm *vm)
  	list_for_each_entry(e, &vm->preempt.engines, compute.link) {
  		e->ops->resume(e);
 
-		drm_gpuva_add_fence(&vm->mgr, e->compute.pfence,
-				    DMA_RESV_USAGE_BOOKKEEP,
-				    DMA_RESV_USAGE_BOOKKEEP);
+		drm_gpuva_manager_add_fence(&vm->mgr, exec, e->compute.pfence,
+					    DMA_RESV_USAGE_BOOKKEEP,
+					    DMA_RESV_USAGE_BOOKKEEP);
  	}
  }
 
  int xe_vm_add_compute_engine(struct xe_vm *vm, struct xe_engine *e)
  {
-	struct ttm_validate_buffer tv_onstack[XE_ONSTACK_TV];
-	struct ttm_validate_buffer *tv;
-	struct ww_acquire_ctx ww;
-	struct list_head objs;
+	struct drm_exec exec;
  	struct dma_fence *pfence;
  	int err;
  	bool wait;
@@ -308,7 +306,7 @@ int xe_vm_add_compute_engine(struct xe_vm *vm, struct xe_engine *e)
 
  	down_write(&vm->lock);
 
-	err = xe_vm_lock_dma_resv(vm, &ww, tv_onstack, &tv, &objs, true, 1);
+	err = xe_vm_lock_dma_resv(vm, &exec, true, 1);
  	if (err)
  		goto out_unlock_outer;
 
@@ -325,9 +323,9 @@ int xe_vm_add_compute_engine(struct xe_vm *vm, struct xe_engine *e)
 
  	down_read(&vm->userptr.notifier_lock);
 
-	drm_gpuva_add_fence(&vm->mgr, pfence,
-			    DMA_RESV_USAGE_BOOKKEEP,
-			    DMA_RESV_USAGE_BOOKKEEP);
+	drm_gpuva_manager_add_fence(&vm->mgr, &exec, pfence,
+				    DMA_RESV_USAGE_BOOKKEEP,
+				    DMA_RESV_USAGE_BOOKKEEP);
 
  	/*
  	 * Check to see if a preemption on VM is in flight or userptr
@@ -341,7 +339,7 @@ int xe_vm_add_compute_engine(struct xe_vm *vm, struct xe_engine *e)
  	up_read(&vm->userptr.notifier_lock);
 
  out_unlock:
-	xe_vm_unlock_dma_resv(vm, tv_onstack, tv, &ww, &objs);
+	xe_vm_unlock_dma_resv(vm, &exec);
  out_unlock_outer:
  	up_write(&vm->lock);
 
@@ -367,25 +365,24 @@ int __xe_vm_userptr_needs_repin(struct xe_vm *vm)
  		list_empty(&vm->userptr.invalidated)) ? 0 : -EAGAIN;
  }
 
+static struct drm_gem_object *xe_vm_gem(struct xe_vm *vm)
+{
+	int idx = vm->flags & XE_VM_FLAG_MIGRATION ?
+		XE_VM_FLAG_GT_ID(vm->flags) : 0;
+
+	/* Safe to use index 0 as all BO in the VM share a single dma-resv lock */
+	return &vm->pt_root[idx]->bo->ttm.base;
+}
+
  /**
   * xe_vm_lock_dma_resv() - Lock the vm dma_resv object and the dma_resv
   * objects of the vm's external buffer objects.
- * @vm: The vm.
- * @ww: Pointer to a struct ww_acquire_ctx locking context.
- * @tv_onstack: Array size XE_ONSTACK_TV of storage for the struct
- * ttm_validate_buffers used for locking.
- * @tv: Pointer to a pointer that on output contains the actual storage used.
- * @objs: List head for the buffer objects locked.
+ * @vm: The vm
   * @intr: Whether to lock interruptible.
   * @num_shared: Number of dma-fence slots to reserve in the locked objects.
   *
   * Locks the vm dma-resv objects and all the dma-resv objects of the
- * buffer objects on the vm external object list. The TTM utilities require
- * a list of struct ttm_validate_buffers pointing to the actual buffer
- * objects to lock. Storage for those struct ttm_validate_buffers should
- * be provided in @tv_onstack, and is typically reserved on the stack
- * of the caller. If the size of @tv_onstack isn't sufficient, then
- * storage will be allocated internally using kvmalloc().
+ * buffer objects on the vm external object list.
   *
   * The function performs deadlock handling internally, and after a
   * successful return the ww locking transaction should be considered
@@ -395,46 +392,18 @@ int __xe_vm_userptr_needs_repin(struct xe_vm *vm)
   * @intr is set to true, -EINTR or -ERESTARTSYS may be returned. In case
   * of error, any locking performed has been reverted.
   */
-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,
+int xe_vm_lock_dma_resv(struct xe_vm *vm, struct drm_exec *exec, bool intr,
  			unsigned int num_shared)
  {
-	struct ttm_validate_buffer *tv_vm, *tv_bo;
  	struct xe_vma *vma, *next;
-	struct drm_gpuva *gpuva;
-	LIST_HEAD(dups);
  	int err;
 
  	lockdep_assert_held(&vm->lock);
 
-	if (vm->mgr.extobj.entries < XE_ONSTACK_TV) {
-		tv_vm = tv_onstack;
-	} else {
-		tv_vm = kvmalloc_array(vm->mgr.extobj.entries + 1,
-				       sizeof(*tv_vm),
-				       GFP_KERNEL);
-		if (!tv_vm)
-			return -ENOMEM;
-	}
-	tv_bo = tv_vm + 1;
-
-	INIT_LIST_HEAD(objs);
-	drm_gpuva_for_each_extobj(gpuva, &vm->mgr) {
-		tv_bo->num_shared = num_shared;
-		tv_bo->bo = &gem_to_xe_bo(gpuva->gem.obj)->ttm;
-
-		list_add_tail(&tv_bo->head, objs);
-		tv_bo++;
-	}
-	tv_vm->num_shared = num_shared;
-	tv_vm->bo = xe_vm_ttm_bo(vm);
-	list_add_tail(&tv_vm->head, objs);
-	err = ttm_eu_reserve_buffers(ww, objs, intr, &dups);
+	err = drm_gpuva_manager_lock(&vm->mgr, exec, xe_vm_gem(vm), intr,
+				     num_shared);
  	if (err)
-		goto out_err;
+		return err;
 
  	spin_lock(&vm->notifier.list_lock);
  	list_for_each_entry_safe(vma, next, &vm->notifier.rebind_list,
@@ -447,34 +416,22 @@ int xe_vm_lock_dma_resv(struct xe_vm *vm, struct ww_acquire_ctx *ww,
  	}
  	spin_unlock(&vm->notifier.list_lock);
 
-	*tv = tv_vm;
  	return 0;
-
-out_err:
-	if (tv_vm != tv_onstack)
-		kvfree(tv_vm);
-
-	return err;
  }
 
  /**
   * xe_vm_unlock_dma_resv() - Unlock reservation objects locked by
   * xe_vm_lock_dma_resv()
   * @vm: The vm.
- * @tv_onstack: The @tv_onstack array given to xe_vm_lock_dma_resv().
- * @tv: The value of *@tv given by xe_vm_lock_dma_resv().
- * @ww: The ww_acquire_context used for locking.
- * @objs: The list returned from xe_vm_lock_dma_resv().
   *
   * Unlocks the reservation objects and frees any memory allocated by
   * xe_vm_lock_dma_resv().
   */
-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)
+void xe_vm_unlock_dma_resv(struct xe_vm *vm, struct drm_exec *exec)
  {
+	struct drm_gem_object *obj, *skip = xe_vm_gem(vm);
+	unsigned long index;
+
  	/*
  	 * Nothing should've been able to enter the list while we were locked,
  	 * since we've held the dma-resvs of all the vm's external objects,
@@ -483,19 +440,20 @@ void xe_vm_unlock_dma_resv(struct xe_vm *vm,
  	 */
  	XE_WARN_ON(!list_empty(&vm->notifier.rebind_list));
 
-	ttm_eu_backoff_reservation(ww, objs);
-	if (tv && tv != tv_onstack)
-		kvfree(tv);
+	drm_exec_for_each_locked_object(exec, index, obj) {
+		struct xe_bo *bo = gem_to_xe_bo(obj);
+
+		if (obj != skip)
+			ttm_bo_move_to_lru_tail_unlocked(&bo->ttm);
+	}
+	drm_gpuva_manager_unlock(&vm->mgr, exec);
  }
 
  static void preempt_rebind_work_func(struct work_struct *w)
  {
  	struct xe_vm *vm = container_of(w, struct xe_vm, preempt.rebind_work);
+	struct drm_exec exec;
  	struct xe_vma *vma;
-	struct ttm_validate_buffer tv_onstack[XE_ONSTACK_TV];
-	struct ttm_validate_buffer *tv;
-	struct ww_acquire_ctx ww;
-	struct list_head objs;
  	struct dma_fence *rebind_fence;
  	unsigned int fence_count = 0;
  	LIST_HEAD(preempt_fences);
@@ -536,8 +494,7 @@ static void preempt_rebind_work_func(struct work_struct *w)
  			goto out_unlock_outer;
  	}
 
-	err = xe_vm_lock_dma_resv(vm, &ww, tv_onstack, &tv, &objs,
-				  false, vm->preempt.num_engines);
+	err = xe_vm_lock_dma_resv(vm, &exec, false, vm->preempt.num_engines);
  	if (err)
  		goto out_unlock_outer;
 
@@ -608,11 +565,11 @@ static void preempt_rebind_work_func(struct work_struct *w)
 
  	/* Point of no return. */
  	arm_preempt_fences(vm, &preempt_fences);
-	resume_and_reinstall_preempt_fences(vm);
+	resume_and_reinstall_preempt_fences(vm, &exec);
  	up_read(&vm->userptr.notifier_lock);
 
  out_unlock:
-	xe_vm_unlock_dma_resv(vm, tv_onstack, tv, &ww, &objs);
+	xe_vm_unlock_dma_resv(vm, &exec);
  out_unlock_outer:
  	if (err == -EAGAIN) {
  		trace_xe_vm_rebind_worker_retry(vm);
@@ -963,27 +920,16 @@ static void xe_vma_destroy(struct xe_vma *vma, struct dma_fence *fence)
 
  static void xe_vma_destroy_unlocked(struct xe_vma *vma)
  {
-	struct ttm_validate_buffer tv[2];
-	struct ww_acquire_ctx ww;
+	struct xe_vm *vm = xe_vma_vm(vma);
  	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);
-	}
-	err = ttm_eu_reserve_buffers(&ww, &objs, false, &dups);
+	err = xe_vm_bo_lock(vm, xe_bo_get(bo), &exec, 0, false);
  	XE_WARN_ON(err);
-
  	xe_vma_destroy(vma, NULL);
+	xe_vm_bo_unlock(vm, bo, &exec, false);
 
-	ttm_eu_backoff_reservation(&ww, &objs);
  	if (bo)
  		xe_bo_put(bo);
  }
@@ -1254,7 +1200,7 @@ static void vm_error_capture(struct xe_vm *vm, int err,
  void xe_vm_close_and_put(struct xe_vm *vm)
  {
  	struct list_head contested;
-	struct ww_acquire_ctx ww;
+	struct drm_exec exec;
  	struct xe_device *xe = xe_vm_device(vm);
  	struct xe_gt *gt;
  	struct xe_vma *vma, *next_vma;
@@ -1281,7 +1227,7 @@ void xe_vm_close_and_put(struct xe_vm *vm)
  	}
 
  	down_write(&vm->lock);
-	xe_vm_lock(vm, &ww, 0, false);
+	xe_vm_lock(vm, &exec, 0, false);
  	drm_gpuva_iter_for_each(gpuva, it) {
  		vma = gpuva_to_vma(gpuva);
 
@@ -1323,7 +1269,7 @@ void xe_vm_close_and_put(struct xe_vm *vm)
  					      NULL);
  		}
  	}
-	xe_vm_unlock(vm, &ww);
+	xe_vm_unlock(vm, &exec);
 
  	/*
  	 * VM is now dead, cannot re-add nodes to vm->vmas if it's NULL
@@ -1356,7 +1302,7 @@ static void vm_destroy_work_func(struct work_struct *w)
  {
  	struct xe_vm *vm =
  		container_of(w, struct xe_vm, destroy_work);
-	struct ww_acquire_ctx ww;
+	struct drm_exec exec;
  	struct xe_device *xe = xe_vm_device(vm);
  	struct xe_gt *gt;
  	u8 id;
@@ -1382,14 +1328,14 @@ static void vm_destroy_work_func(struct work_struct *w)
  	 * is needed for xe_vm_lock to work. If we remove that dependency this
  	 * can be moved to xe_vm_close_and_put.
  	 */
-	xe_vm_lock(vm, &ww, 0, false);
+	xe_vm_lock(vm, &exec, 0, false);
  	for_each_gt(gt, xe, id) {
  		if (vm->pt_root[id]) {
  			xe_pt_destroy(vm->pt_root[id], vm->flags, NULL);
  			vm->pt_root[id] = NULL;
  		}
  	}
-	xe_vm_unlock(vm, &ww);
+	xe_vm_unlock(vm, &exec);
 
  	trace_xe_vm_free(vm);
  	dma_fence_put(vm->rebind_fence);
@@ -1969,21 +1915,6 @@ static int xe_vm_prefetch(struct xe_vm *vm, struct xe_vma *vma,
 
  #define VM_BIND_OP(op)	(op & 0xffff)
 
-struct ttm_buffer_object *xe_vm_ttm_bo(struct xe_vm *vm)
-{
-	int idx = vm->flags & XE_VM_FLAG_MIGRATION ?
-		XE_VM_FLAG_GT_ID(vm->flags) : 0;
-
-	/* Safe to use index 0 as all BO in the VM share a single dma-resv lock */
-	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);
@@ -2088,7 +2019,7 @@ vm_bind_ioctl_ops_create(struct xe_vm *vm, struct xe_bo *bo,
  			 u32 operation, u8 gt_mask, u32 region)
  {
  	struct drm_gem_object *obj = bo ? &bo->ttm.base : NULL;
-	struct ww_acquire_ctx ww;
+	struct drm_exec exec;
  	struct drm_gpuva_ops *ops;
  	struct drm_gpuva_op *__op;
  	struct xe_vma_op *op;
@@ -2136,11 +2067,11 @@ vm_bind_ioctl_ops_create(struct xe_vm *vm, struct xe_bo *bo,
  	case XE_VM_BIND_OP_UNMAP_ALL:
  		XE_BUG_ON(!bo);
 
-		err = xe_bo_lock(bo, &ww, 0, true);
+		err = xe_bo_lock(bo, &exec, 0, 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, &exec);
 
  		drm_gpuva_for_each_op(__op, ops) {
  			struct xe_vma_op *op = gpuva_op_to_vma_op(__op);
@@ -2174,13 +2105,13 @@ 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;
+	struct drm_exec exec;
  	int err;
 
  	lockdep_assert_held_write(&vm->lock);
 
  	if (bo) {
-		err = xe_bo_lock(bo, &ww, 0, true);
+		err = xe_bo_lock(bo, &exec, 0, true);
  		if (err)
  			return ERR_PTR(err);
  	}
@@ -2189,7 +2120,7 @@ static struct xe_vma *new_vma(struct xe_vm *vm, struct drm_gpuva_op_map *op,
  			    op->va.range - 1, read_only, null,
  			    gt_mask);
  	if (bo)
-		xe_bo_unlock(bo, &ww);
+		xe_bo_unlock(bo, &exec);
 
  	if (xe_vma_is_userptr(vma)) {
  		err = xe_vma_userptr_pin_pages(vma);
@@ -2441,19 +2372,15 @@ static int xe_vma_op_commit(struct xe_vm *vm, struct xe_vma_op *op)
  static int __xe_vma_op_execute(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;
+	struct drm_exec exec;
  	int err;
+	bool lru_update = op->base.op != DRM_GPUVA_OP_UNMAP;
 
  	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) {
+	if (vbo)
  		/*
  		 * An unbind can drop the last reference to the BO and
  		 * the BO is needed for ttm_eu_backoff_reservation so
@@ -2461,22 +2388,15 @@ static int __xe_vma_op_execute(struct xe_vm *vm, struct xe_vma *vma,
  		 */
  		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);
+	err = xe_vm_bo_lock(vm, vbo, &exec, 1, false);
  	if (err) {
  		xe_bo_put(vbo);
  		return err;
  	}
 
  	xe_vm_assert_held(vm);
-	xe_bo_assert_held(xe_vma_bo(vma));
+	xe_bo_assert_held(vbo);
 
  	switch (op->base.op) {
  	case DRM_GPUVA_OP_MAP:
@@ -2552,7 +2472,7 @@ static int __xe_vma_op_execute(struct xe_vm *vm, struct xe_vma *vma,
  		XE_BUG_ON("NOT POSSIBLE");
  	}
 
-	ttm_eu_backoff_reservation(&ww, &objs);
+	xe_vm_bo_unlock(vm, vbo, &exec, lru_update);
  	if (err == -EAGAIN && xe_vma_is_userptr(vma)) {
  		lockdep_assert_held_write(&vm->lock);
  		err = xe_vma_userptr_pin_pages(vma);
@@ -3208,30 +3128,67 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
  	return err == -ENODATA ? 0 : err;
  }
 
-/*
- * XXX: Using the TTM wrappers for now, likely can call into dma-resv code
- * directly to optimize. Also this likely should be an inline function.
- */
-int xe_vm_lock(struct xe_vm *vm, struct ww_acquire_ctx *ww,
+int xe_vm_lock(struct xe_vm *vm, struct drm_exec *exec,
  	       int num_resv, bool intr)
  {
-	struct ttm_validate_buffer tv_vm;
-	LIST_HEAD(objs);
-	LIST_HEAD(dups);
+	int err;
 
-	XE_BUG_ON(!ww);
+	drm_exec_init(exec, intr);
+	drm_exec_while_not_all_locked(exec) {
+		err = drm_exec_prepare_obj(exec, xe_vm_gem(vm),
+					   num_resv);
+		drm_exec_continue_on_contention(exec);
+		if (err && err != -EALREADY)
+			goto out_err;
+	}
 
-	tv_vm.num_shared = num_resv;
-	tv_vm.bo = xe_vm_ttm_bo(vm);;
-	list_add_tail(&tv_vm.head, &objs);
+	return 0;
 
-	return ttm_eu_reserve_buffers(ww, &objs, intr, &dups);
+out_err:
+	drm_exec_fini(exec);
+	return err;
  }
 
-void xe_vm_unlock(struct xe_vm *vm, struct ww_acquire_ctx *ww)
+void xe_vm_unlock(struct xe_vm *vm, struct drm_exec *exec)
  {
-	dma_resv_unlock(xe_vm_resv(vm));
-	ww_acquire_fini(ww);
+	drm_exec_fini(exec);
+}
+
+int xe_vm_bo_lock(struct xe_vm *vm, struct xe_bo *bo, struct drm_exec *exec,
+		  int num_resv, bool intr)
+{
+	int err;
+
+	drm_exec_init(exec, intr);
+	drm_exec_while_not_all_locked(exec) {
+		err = drm_exec_prepare_obj(exec, xe_vm_gem(vm),
+					   num_resv);
+		drm_exec_continue_on_contention(exec);
+		if (err && err != -EALREADY)
+			goto out_err;
+
+		if (bo && !bo->vm) {
+			err = drm_exec_prepare_obj(exec, &bo->ttm.base,
+						   num_resv);
+			drm_exec_continue_on_contention(exec);
+			if (err && err != -EALREADY)
+				goto out_err;
+		}
+	}
+
+	return 0;
+
+out_err:
+	drm_exec_fini(exec);
+	return err;
+}
+
+void xe_vm_bo_unlock(struct xe_vm *vm, struct xe_bo *bo, struct drm_exec *exec,
+		     bool lru_update)
+{
+	if (lru_update && bo && (!bo->vm || xe_vm_no_dma_fences(vm)))
+		ttm_bo_move_to_lru_tail_unlocked(&bo->ttm);
+	drm_exec_fini(exec);
  }
 
  /**
drivers/gpu/drm/xe/xe_vm.h +9 -18
index f279fa622260..47b981d9fc04 100644
@@ -12,6 +12,7 @@
  #include "xe_vm_types.h"
 
  struct drm_device;
+struct drm_exec;
  struct drm_printer;
  struct drm_file;
 
@@ -38,10 +39,14 @@ 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 xe_vm_lock(struct xe_vm *vm, struct drm_exec *exec,
  	       int num_resv, bool intr);
+void xe_vm_unlock(struct xe_vm *vm, struct drm_exec *exec);
 
-void xe_vm_unlock(struct xe_vm *vm, struct ww_acquire_ctx *ww);
+int xe_vm_bo_lock(struct xe_vm *vm, struct xe_bo *bo, struct drm_exec *exec,
+		  int num_resv, bool intr);
+void xe_vm_bo_unlock(struct xe_vm *vm, struct xe_bo *bo, struct drm_exec *exec,
+		     bool lru_update);
 
  static inline bool xe_vm_is_closed(struct xe_vm *vm)
  {
@@ -219,23 +224,9 @@ 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,
+int xe_vm_lock_dma_resv(struct xe_vm *vm, struct drm_exec *exec, 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);
+void xe_vm_unlock_dma_resv(struct xe_vm *vm, struct drm_exec *exec);
 
  int xe_analyze_vm(struct drm_printer *p, struct xe_vm *vm, int gt_id);
 
drivers/gpu/drm/xe/xe_vm_madvise.c +19 -18
index 03508645fa08..a68bc6fec1de 100644
@@ -7,6 +7,7 @@
 
  #include <linux/nospec.h>
 
+#include <drm/drm_exec.h>
  #include <drm/ttm/ttm_tt.h>
  #include <drm/xe_drm.h>
 
@@ -28,16 +29,16 @@ 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;
+		struct drm_exec exec;
 
  		bo = xe_vma_bo(vmas[i]);
 
-		err = xe_bo_lock(bo, &ww, 0, true);
+		err = xe_bo_lock(bo, &exec, 0, 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, &exec);
  	}
 
  	return 0;
@@ -53,16 +54,16 @@ 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;
+		struct drm_exec exec;
 
  		bo = xe_vma_bo(vmas[i]);
 
-		err = xe_bo_lock(bo, &ww, 0, true);
+		err = xe_bo_lock(bo, &exec, 0, 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, &exec);
  	}
 
  	return 0;
@@ -89,17 +90,17 @@ 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;
+		struct drm_exec exec;
 
  		bo = xe_vma_bo(vmas[i]);
 
-		err = xe_bo_lock(bo, &ww, 0, true);
+		err = xe_bo_lock(bo, &exec, 0, 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, &exec);
  	}
 
  	return 0;
@@ -112,13 +113,13 @@ 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;
+		struct drm_exec exec;
 
  		bo = xe_vma_bo(vmas[i]);
  		if (XE_IOCTL_ERR(xe, !(bo->flags & XE_BO_CREATE_SYSTEM_BIT)))
  			return -EINVAL;
 
-		err = xe_bo_lock(bo, &ww, 0, true);
+		err = xe_bo_lock(bo, &exec, 0, true);
  		if (err)
  			return err;
  		bo->props.cpu_atomic = !!value;
@@ -130,7 +131,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, &exec);
  	}
 
  	return 0;
@@ -143,18 +144,18 @@ 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;
+		struct drm_exec exec;
 
  		bo = xe_vma_bo(vmas[i]);
  		if (XE_IOCTL_ERR(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, &exec, 0, true);
  		if (err)
  			return err;
  		bo->props.device_atomic = !!value;
-		xe_bo_unlock(bo, &ww);
+		xe_bo_unlock(bo, &exec);
  	}
 
  	return 0;
@@ -174,16 +175,16 @@ 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;
+		struct drm_exec exec;
 
  		bo = xe_vma_bo(vmas[i]);
 
-		err = xe_bo_lock(bo, &ww, 0, true);
+		err = xe_bo_lock(bo, &exec, 0, 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, &exec);
  	}
 
  	return 0;
include/drm/drm_gpuva_mgr.h +13 -3
index 943c8fcda533..a2f6d90ac899 100644
@@ -32,6 +32,8 @@
  #include <linux/spinlock.h>
  #include <linux/types.h>
 
+#include <drm/drm_exec.h>
+
  struct drm_gpuva_manager;
  struct drm_gpuva_fn_ops;
  struct drm_gpuva_prealloc;
@@ -169,9 +171,17 @@ struct drm_gpuva *drm_gpuva_find_next(struct drm_gpuva_manager *mgr, u64 end);
 
  bool drm_gpuva_interval_empty(struct drm_gpuva_manager *mgr, u64 addr, u64 range);
 
-void drm_gpuva_add_fence(struct drm_gpuva_manager *mgr, struct dma_fence *fence,
-			 enum dma_resv_usage private_usage,
-			 enum dma_resv_usage extobj_usage);
+int drm_gpuva_manager_lock(struct drm_gpuva_manager *mgr, struct drm_exec *exec,
+			   struct drm_gem_object *mgr_obj, bool intr,
+			   unsigned int num_fences);
+void drm_gpuva_manager_unlock(struct drm_gpuva_manager *mgr,
+			      struct drm_exec *exec);
+
+void drm_gpuva_manager_add_fence(struct drm_gpuva_manager *mgr,
+				 struct drm_exec *exec,
+				 struct dma_fence *fence,
+				 enum dma_resv_usage private_usage,
+				 enum dma_resv_usage extobj_usage);
 
  /**
   * drm_gpuva_evict - sets whether the backing GEM of this &drm_gpuva is evicted
author maintainer
#108 lore raw

PATCH v2 28/31 drm/xe: Allow dma-fences as in-syncs for compute / faulting VM

In reply to Matthew Brost

This is allowed per the dma-fencing rules.

---
 drivers/gpu/drm/xe/xe_sync.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/gpu/drm/xe/xe_sync.c +7 -5
index 99f1ed87196d..1e4e4acb2c4a 100644
@@ -105,6 +105,7 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
 {
 	struct drm_xe_sync sync_in;
 	int err;
+	bool signal;
 
 	if (copy_from_user(&sync_in, sync_user, sizeof(*sync_user)))
 		return -EFAULT;
@@ -113,9 +114,10 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
 			 ~(SYNC_FLAGS_TYPE_MASK | DRM_XE_SYNC_SIGNAL)))
 		return -EINVAL;
 
+	signal = sync_in.flags & DRM_XE_SYNC_SIGNAL;
 	switch (sync_in.flags & SYNC_FLAGS_TYPE_MASK) {
 	case DRM_XE_SYNC_SYNCOBJ:
-		if (XE_IOCTL_ERR(xe, no_dma_fences))
+		if (XE_IOCTL_ERR(xe, no_dma_fences && signal))
 			return -ENOTSUPP;
 
 		if (XE_IOCTL_ERR(xe, upper_32_bits(sync_in.addr)))
@@ -125,7 +127,7 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
 		if (XE_IOCTL_ERR(xe, !sync->syncobj))
 			return -ENOENT;
 
-		if (!(sync_in.flags & DRM_XE_SYNC_SIGNAL)) {
+		if (!signal) {
 			sync->fence = drm_syncobj_fence_get(sync->syncobj);
 			if (XE_IOCTL_ERR(xe, !sync->fence))
 				return -EINVAL;
@@ -133,7 +135,7 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
 		break;
 
 	case DRM_XE_SYNC_TIMELINE_SYNCOBJ:
-		if (XE_IOCTL_ERR(xe, no_dma_fences))
+		if (XE_IOCTL_ERR(xe, no_dma_fences && signal))
 			return -ENOTSUPP;
 
 		if (XE_IOCTL_ERR(xe, upper_32_bits(sync_in.addr)))
@@ -146,7 +148,7 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
 		if (XE_IOCTL_ERR(xe, !sync->syncobj))
 			return -ENOENT;
 
-		if (sync_in.flags & DRM_XE_SYNC_SIGNAL) {
+		if (signal) {
 			sync->chain_fence = dma_fence_chain_alloc();
 			if (!sync->chain_fence)
 				return -ENOMEM;
@@ -168,7 +170,7 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
 		break;
 
 	case DRM_XE_SYNC_USER_FENCE:
-		if (XE_IOCTL_ERR(xe, !(sync_in.flags & DRM_XE_SYNC_SIGNAL)))
+		if (XE_IOCTL_ERR(xe, !signal))
 			return -ENOTSUPP;
 
 		if (XE_IOCTL_ERR(xe, sync_in.addr & 0x7))
Signature · 1 line
2.34.1
#109 lore raw

Re: [Intel-xe] [PATCH v2 28/31] drm/xe: Allow dma-fences as in-syncs for compute / faulting VM

Quoted 1 line · Matthew Brost

This is allowed per the dma-fencing rules.

it would be good a word saying 'why' we are doing this. only because we can it doesn't mean we should...

Quoted 69 lines
---
 drivers/gpu/drm/xe/xe_sync.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/gpu/drm/xe/xe_sync.c +7 -5
index 99f1ed87196d..1e4e4acb2c4a 100644
@@ -105,6 +105,7 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
 {
 	struct drm_xe_sync sync_in;
 	int err;
+	bool signal;
 
 	if (copy_from_user(&sync_in, sync_user, sizeof(*sync_user)))
 		return -EFAULT;
@@ -113,9 +114,10 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
 			 ~(SYNC_FLAGS_TYPE_MASK | DRM_XE_SYNC_SIGNAL)))
 		return -EINVAL;
 
+	signal = sync_in.flags & DRM_XE_SYNC_SIGNAL;
 	switch (sync_in.flags & SYNC_FLAGS_TYPE_MASK) {
 	case DRM_XE_SYNC_SYNCOBJ:
-		if (XE_IOCTL_ERR(xe, no_dma_fences))
+		if (XE_IOCTL_ERR(xe, no_dma_fences && signal))
 			return -ENOTSUPP;
 
 		if (XE_IOCTL_ERR(xe, upper_32_bits(sync_in.addr)))
@@ -125,7 +127,7 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
 		if (XE_IOCTL_ERR(xe, !sync->syncobj))
 			return -ENOENT;
 
-		if (!(sync_in.flags & DRM_XE_SYNC_SIGNAL)) {
+		if (!signal) {
 			sync->fence = drm_syncobj_fence_get(sync->syncobj);
 			if (XE_IOCTL_ERR(xe, !sync->fence))
 				return -EINVAL;
@@ -133,7 +135,7 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
 		break;
 
 	case DRM_XE_SYNC_TIMELINE_SYNCOBJ:
-		if (XE_IOCTL_ERR(xe, no_dma_fences))
+		if (XE_IOCTL_ERR(xe, no_dma_fences && signal))
 			return -ENOTSUPP;
 
 		if (XE_IOCTL_ERR(xe, upper_32_bits(sync_in.addr)))
@@ -146,7 +148,7 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
 		if (XE_IOCTL_ERR(xe, !sync->syncobj))
 			return -ENOENT;
 
-		if (sync_in.flags & DRM_XE_SYNC_SIGNAL) {
+		if (signal) {
 			sync->chain_fence = dma_fence_chain_alloc();
 			if (!sync->chain_fence)
 				return -ENOMEM;
@@ -168,7 +170,7 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
 		break;
 
 	case DRM_XE_SYNC_USER_FENCE:
-		if (XE_IOCTL_ERR(xe, !(sync_in.flags & DRM_XE_SYNC_SIGNAL)))
+		if (XE_IOCTL_ERR(xe, !signal))
 			return -ENOTSUPP;
 
 		if (XE_IOCTL_ERR(xe, sync_in.addr & 0x7))
Signature · 1 line
2.34.1
author maintainer
#110 lore raw

Re: [Intel-xe] [PATCH v2 28/31] drm/xe: Allow dma-fences as in-syncs for compute / faulting VM

Quoted 6 lines · Rodrigo Vivi
Quoted 1 line · Matthew Brost

This is allowed per the dma-fencing rules.

it would be good a word saying 'why' we are doing this. only because we can it doesn't mean we should...

This is allowed and encouraged the dma-fencing rule. This along with allowing compute VMs to export dma-fences on binds will result in a simpler compute UMD.

Sound ok?

Matt

Quoted 69 lines
Quoted 69 lines
---
 drivers/gpu/drm/xe/xe_sync.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/gpu/drm/xe/xe_sync.c +7 -5
index 99f1ed87196d..1e4e4acb2c4a 100644
@@ -105,6 +105,7 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
 {
 	struct drm_xe_sync sync_in;
 	int err;
+	bool signal;
 
 	if (copy_from_user(&sync_in, sync_user, sizeof(*sync_user)))
 		return -EFAULT;
@@ -113,9 +114,10 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
 			 ~(SYNC_FLAGS_TYPE_MASK | DRM_XE_SYNC_SIGNAL)))
 		return -EINVAL;
 
+	signal = sync_in.flags & DRM_XE_SYNC_SIGNAL;
 	switch (sync_in.flags & SYNC_FLAGS_TYPE_MASK) {
 	case DRM_XE_SYNC_SYNCOBJ:
-		if (XE_IOCTL_ERR(xe, no_dma_fences))
+		if (XE_IOCTL_ERR(xe, no_dma_fences && signal))
 			return -ENOTSUPP;
 
 		if (XE_IOCTL_ERR(xe, upper_32_bits(sync_in.addr)))
@@ -125,7 +127,7 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
 		if (XE_IOCTL_ERR(xe, !sync->syncobj))
 			return -ENOENT;
 
-		if (!(sync_in.flags & DRM_XE_SYNC_SIGNAL)) {
+		if (!signal) {
 			sync->fence = drm_syncobj_fence_get(sync->syncobj);
 			if (XE_IOCTL_ERR(xe, !sync->fence))
 				return -EINVAL;
@@ -133,7 +135,7 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
 		break;
 
 	case DRM_XE_SYNC_TIMELINE_SYNCOBJ:
-		if (XE_IOCTL_ERR(xe, no_dma_fences))
+		if (XE_IOCTL_ERR(xe, no_dma_fences && signal))
 			return -ENOTSUPP;
 
 		if (XE_IOCTL_ERR(xe, upper_32_bits(sync_in.addr)))
@@ -146,7 +148,7 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
 		if (XE_IOCTL_ERR(xe, !sync->syncobj))
 			return -ENOENT;
 
-		if (sync_in.flags & DRM_XE_SYNC_SIGNAL) {
+		if (signal) {
 			sync->chain_fence = dma_fence_chain_alloc();
 			if (!sync->chain_fence)
 				return -ENOMEM;
@@ -168,7 +170,7 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
 		break;
 
 	case DRM_XE_SYNC_USER_FENCE:
-		if (XE_IOCTL_ERR(xe, !(sync_in.flags & DRM_XE_SYNC_SIGNAL)))
+		if (XE_IOCTL_ERR(xe, !signal))
 			return -ENOTSUPP;
 
 		if (XE_IOCTL_ERR(xe, sync_in.addr & 0x7))
Signature · 1 line
2.34.1
maintainer Reviewed-by
#111 lore raw

Re: [Intel-xe] [PATCH v2 28/31] drm/xe: Allow dma-fences as in-syncs for compute / faulting VM

Quoted 8 lines · Matthew Brost
Quoted 6 lines · Rodrigo Vivi
Quoted 1 line · Matthew Brost

This is allowed per the dma-fencing rules.

it would be good a word saying 'why' we are doing this. only because we can it doesn't mean we should...

Quoted 5 lines

This is allowed and encouraged the dma-fencing rule. This along with allowing compute VMs to export dma-fences on binds will result in a simpler compute UMD.

Sound ok?

makes sense. with that

Quoted 72 lines

Matt

Quoted 69 lines
Quoted 69 lines
---
 drivers/gpu/drm/xe/xe_sync.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/gpu/drm/xe/xe_sync.c +7 -5
index 99f1ed87196d..1e4e4acb2c4a 100644
@@ -105,6 +105,7 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
 {
 	struct drm_xe_sync sync_in;
 	int err;
+	bool signal;
 
 	if (copy_from_user(&sync_in, sync_user, sizeof(*sync_user)))
 		return -EFAULT;
@@ -113,9 +114,10 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
 			 ~(SYNC_FLAGS_TYPE_MASK | DRM_XE_SYNC_SIGNAL)))
 		return -EINVAL;
 
+	signal = sync_in.flags & DRM_XE_SYNC_SIGNAL;
 	switch (sync_in.flags & SYNC_FLAGS_TYPE_MASK) {
 	case DRM_XE_SYNC_SYNCOBJ:
-		if (XE_IOCTL_ERR(xe, no_dma_fences))
+		if (XE_IOCTL_ERR(xe, no_dma_fences && signal))
 			return -ENOTSUPP;
 
 		if (XE_IOCTL_ERR(xe, upper_32_bits(sync_in.addr)))
@@ -125,7 +127,7 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
 		if (XE_IOCTL_ERR(xe, !sync->syncobj))
 			return -ENOENT;
 
-		if (!(sync_in.flags & DRM_XE_SYNC_SIGNAL)) {
+		if (!signal) {
 			sync->fence = drm_syncobj_fence_get(sync->syncobj);
 			if (XE_IOCTL_ERR(xe, !sync->fence))
 				return -EINVAL;
@@ -133,7 +135,7 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
 		break;
 
 	case DRM_XE_SYNC_TIMELINE_SYNCOBJ:
-		if (XE_IOCTL_ERR(xe, no_dma_fences))
+		if (XE_IOCTL_ERR(xe, no_dma_fences && signal))
 			return -ENOTSUPP;
 
 		if (XE_IOCTL_ERR(xe, upper_32_bits(sync_in.addr)))
@@ -146,7 +148,7 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
 		if (XE_IOCTL_ERR(xe, !sync->syncobj))
 			return -ENOENT;
 
-		if (sync_in.flags & DRM_XE_SYNC_SIGNAL) {
+		if (signal) {
 			sync->chain_fence = dma_fence_chain_alloc();
 			if (!sync->chain_fence)
 				return -ENOMEM;
@@ -168,7 +170,7 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
 		break;
 
 	case DRM_XE_SYNC_USER_FENCE:
-		if (XE_IOCTL_ERR(xe, !(sync_in.flags & DRM_XE_SYNC_SIGNAL)))
+		if (XE_IOCTL_ERR(xe, !signal))
 			return -ENOTSUPP;
 
 		if (XE_IOCTL_ERR(xe, sync_in.addr & 0x7))
Signature · 1 line
2.34.1
maintainer Reviewed-by on v2 28/31
#112 lore raw

Re: [Intel-xe] [PATCH v2 28/31] drm/xe: Allow dma-fences as in-syncs for compute / faulting VM

In reply to Matthew Brost
Quoted 3 lines · Matthew Brost

This is allowed per the dma-fencing rules.

LGTM.

Quoted 64 lines
---
  drivers/gpu/drm/xe/xe_sync.c | 12 +++++++-----
  1 file changed, 7 insertions(+), 5 deletions(-)
drivers/gpu/drm/xe/xe_sync.c +7 -5
index 99f1ed87196d..1e4e4acb2c4a 100644
@@ -105,6 +105,7 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
  {
  	struct drm_xe_sync sync_in;
  	int err;
+	bool signal;
 
  	if (copy_from_user(&sync_in, sync_user, sizeof(*sync_user)))
  		return -EFAULT;
@@ -113,9 +114,10 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
  			 ~(SYNC_FLAGS_TYPE_MASK | DRM_XE_SYNC_SIGNAL)))
  		return -EINVAL;
 
+	signal = sync_in.flags & DRM_XE_SYNC_SIGNAL;
  	switch (sync_in.flags & SYNC_FLAGS_TYPE_MASK) {
  	case DRM_XE_SYNC_SYNCOBJ:
-		if (XE_IOCTL_ERR(xe, no_dma_fences))
+		if (XE_IOCTL_ERR(xe, no_dma_fences && signal))
  			return -ENOTSUPP;
 
  		if (XE_IOCTL_ERR(xe, upper_32_bits(sync_in.addr)))
@@ -125,7 +127,7 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
  		if (XE_IOCTL_ERR(xe, !sync->syncobj))
  			return -ENOENT;
 
-		if (!(sync_in.flags & DRM_XE_SYNC_SIGNAL)) {
+		if (!signal) {
  			sync->fence = drm_syncobj_fence_get(sync->syncobj);
  			if (XE_IOCTL_ERR(xe, !sync->fence))
  				return -EINVAL;
@@ -133,7 +135,7 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
  		break;
 
  	case DRM_XE_SYNC_TIMELINE_SYNCOBJ:
-		if (XE_IOCTL_ERR(xe, no_dma_fences))
+		if (XE_IOCTL_ERR(xe, no_dma_fences && signal))
  			return -ENOTSUPP;
 
  		if (XE_IOCTL_ERR(xe, upper_32_bits(sync_in.addr)))
@@ -146,7 +148,7 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
  		if (XE_IOCTL_ERR(xe, !sync->syncobj))
  			return -ENOENT;
 
-		if (sync_in.flags & DRM_XE_SYNC_SIGNAL) {
+		if (signal) {
  			sync->chain_fence = dma_fence_chain_alloc();
  			if (!sync->chain_fence)
  				return -ENOMEM;
@@ -168,7 +170,7 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
  		break;
 
  	case DRM_XE_SYNC_USER_FENCE:
-		if (XE_IOCTL_ERR(xe, !(sync_in.flags & DRM_XE_SYNC_SIGNAL)))
+		if (XE_IOCTL_ERR(xe, !signal))
  			return -ENOTSUPP;
 
  		if (XE_IOCTL_ERR(xe, sync_in.addr & 0x7))
author maintainer
#113 lore raw

PATCH v2 29/31 drm/xe: Allow compute VMs to output dma-fences on binds

In reply to Matthew Brost

Binds are not long running jobs thus we can export dma-fences even if a VM is in compute mode.

---
 drivers/gpu/drm/xe/xe_vm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_vm.c +1 -1
index 55cced8870e6..07023506ce6b 100644
@@ -3047,7 +3047,7 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 	for (num_syncs = 0; num_syncs < args->num_syncs; num_syncs++) {
 		err = xe_sync_entry_parse(xe, xef, &syncs[num_syncs],
 					  &syncs_user[num_syncs], false,
-					  xe_vm_no_dma_fences(vm));
+					  xe_vm_in_fault_mode(vm));
 		if (err)
 			goto free_syncs;
 	}
Signature · 1 line
2.34.1
maintainer
#114 lore raw

Re: [Intel-xe] [PATCH v2 29/31] drm/xe: Allow compute VMs to output dma-fences on binds

Quoted 2 lines · Matthew Brost

Binds are not long running jobs thus we can export dma-fences even if a VM is in compute mode.

is this true independent of the series? or something changed in the series that made this to be true?

I wonder if this is not a good candidate for standalone patch...

Quoted 22 lines
---
 drivers/gpu/drm/xe/xe_vm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_vm.c +1 -1
index 55cced8870e6..07023506ce6b 100644
@@ -3047,7 +3047,7 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 	for (num_syncs = 0; num_syncs < args->num_syncs; num_syncs++) {
 		err = xe_sync_entry_parse(xe, xef, &syncs[num_syncs],
 					  &syncs_user[num_syncs], false,
-					  xe_vm_no_dma_fences(vm));
+					  xe_vm_in_fault_mode(vm));
 		if (err)
 			goto free_syncs;
 	}
Signature · 1 line
2.34.1
maintainer Reviewed-by on v2 29/31
#115 lore raw

Re: [Intel-xe] [PATCH v2 29/31] drm/xe: Allow compute VMs to output dma-fences on binds

In reply to Matthew Brost
Quoted 4 lines · Matthew Brost

Binds are not long running jobs thus we can export dma-fences even if a VM is in compute mode.

Quoted 17 lines
---
  drivers/gpu/drm/xe/xe_vm.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_vm.c +1 -1
index 55cced8870e6..07023506ce6b 100644
@@ -3047,7 +3047,7 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
  	for (num_syncs = 0; num_syncs < args->num_syncs; num_syncs++) {
  		err = xe_sync_entry_parse(xe, xef, &syncs[num_syncs],
  					  &syncs_user[num_syncs], false,
-					  xe_vm_no_dma_fences(vm));
+					  xe_vm_in_fault_mode(vm));
  		if (err)
  			goto free_syncs;
  	}
author maintainer
#116 lore raw

PATCH v2 30/31 drm/xe: remove async worker, sync binds, new error handling

In reply to Matthew Brost

Async worker is gone, all jobs and memory allocations done in IOCTL.

Async vs. sync now means when do bind operations complete relative to the IOCTL. Async completes when out-syncs signal while sync completes when the IOCTL returns. In-syncs and out-syncs are only allowed in async mode.

The error handling is similar to before, on memory allocation errors binds are pause, VM is put in an error state, and the bind IOCTL returns -ENOSPC. The user is allowed to issue sync unbinds, with the reclaim bit set, while in an error state. Bind operations without the reclaim bit set are rejected with -EALREADY until the exits the error state. To exit the error issue a restart bind operation which will pick up where the original failure left off.

TODO: Update kernel doc

---
 drivers/gpu/drm/xe/xe_engine.c          |   7 +-
 drivers/gpu/drm/xe/xe_engine_types.h    |   1 +
 drivers/gpu/drm/xe/xe_exec.c            |  42 --
 drivers/gpu/drm/xe/xe_sync.c            |  14 +-
 drivers/gpu/drm/xe/xe_sync.h            |   2 +-
 drivers/gpu/drm/xe/xe_vm.c              | 712 ++++++------------------
 drivers/gpu/drm/xe/xe_vm.h              |   2 -
 drivers/gpu/drm/xe/xe_vm_types.h        |  37 +-
 drivers/gpu/drm/xe/xe_wait_user_fence.c |  43 +-
 include/uapi/drm/xe_drm.h               |  79 +--
 10 files changed, 213 insertions(+), 726 deletions(-)
drivers/gpu/drm/xe/xe_engine.c +6 -1
index 8b425b777259..d26aadb5e727 100644
@@ -541,7 +541,10 @@ int xe_engine_create_ioctl(struct drm_device *dev, void *data,
 	if (XE_IOCTL_ERR(xe, eci[0].gt_id >= xe->info.tile_count))
 	       return -EINVAL;
 
-	if (eci[0].engine_class == DRM_XE_ENGINE_CLASS_VM_BIND) {
+	if (eci[0].engine_class >= DRM_XE_ENGINE_CLASS_VM_BIND_ASYNC) {
+		bool sync = eci[0].engine_class ==
+			DRM_XE_ENGINE_CLASS_VM_BIND_SYNC;
+	
 		for_each_gt(gt, xe, id) {
 			struct xe_engine *new;
 
@@ -564,6 +567,8 @@ int xe_engine_create_ioctl(struct drm_device *dev, void *data,
 					       args->width, hwe,
 					       ENGINE_FLAG_PERSISTENT |
 					       ENGINE_FLAG_VM |
+					       (sync ? 0 :
+						ENGINE_FLAG_VM_ASYNC) |
 					       (id ?
 					       ENGINE_FLAG_BIND_ENGINE_CHILD :
 					       0));
drivers/gpu/drm/xe/xe_engine_types.h +1 -0
index 36bfaeec23f4..4949edfa0980 100644
@@ -59,6 +59,7 @@ struct xe_engine {
 #define ENGINE_FLAG_VM			BIT(4)
 #define ENGINE_FLAG_BIND_ENGINE_CHILD	BIT(5)
 #define ENGINE_FLAG_WA			BIT(6)
+#define ENGINE_FLAG_VM_ASYNC		BIT(7)
 
 	/**
 	 * @flags: flags for this engine, should statically setup aside from ban
drivers/gpu/drm/xe/xe_exec.c +0 -42

54 lines not on this page · raw message

drivers/gpu/drm/xe/xe_sync.c +3 -11
index 1e4e4acb2c4a..c05142f9780a 100644
@@ -18,7 +18,6 @@
 #include "xe_sched_job_types.h"
 
 #define SYNC_FLAGS_TYPE_MASK 0x3
-#define SYNC_FLAGS_FENCE_INSTALLED	0x10000
 
 struct user_fence {
 	struct xe_device *xe;
@@ -221,12 +220,11 @@ int xe_sync_entry_add_deps(struct xe_sync_entry *sync, struct xe_sched_job *job)
 	return 0;
 }
 
-bool xe_sync_entry_signal(struct xe_sync_entry *sync, struct xe_sched_job *job,
+void xe_sync_entry_signal(struct xe_sync_entry *sync, struct xe_sched_job *job,
 			  struct dma_fence *fence)
 {
-	if (!(sync->flags & DRM_XE_SYNC_SIGNAL) ||
-	    sync->flags & SYNC_FLAGS_FENCE_INSTALLED)
-		return false;
+	if (!(sync->flags & DRM_XE_SYNC_SIGNAL))
+		return;
 
 	if (sync->chain_fence) {
 		drm_syncobj_add_point(sync->syncobj, sync->chain_fence,
@@ -258,12 +256,6 @@ bool xe_sync_entry_signal(struct xe_sync_entry *sync, struct xe_sched_job *job,
 		job->user_fence.addr = sync->addr;
 		job->user_fence.value = sync->timeline_value;
 	}
-
-	/* TODO: external BO? */
-
-	sync->flags |= SYNC_FLAGS_FENCE_INSTALLED;
-
-	return true;
 }
 
 void xe_sync_entry_cleanup(struct xe_sync_entry *sync)
drivers/gpu/drm/xe/xe_sync.h +1 -1
index 4cbcf7a19911..30958ddc4cdc 100644
@@ -19,7 +19,7 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
 int xe_sync_entry_wait(struct xe_sync_entry *sync);
 int xe_sync_entry_add_deps(struct xe_sync_entry *sync,
 			   struct xe_sched_job *job);
-bool xe_sync_entry_signal(struct xe_sync_entry *sync,
+void xe_sync_entry_signal(struct xe_sync_entry *sync,
 			  struct xe_sched_job *job,
 			  struct dma_fence *fence);
 void xe_sync_entry_cleanup(struct xe_sync_entry *sync);
drivers/gpu/drm/xe/xe_vm.c +183 -529

1,084 lines not on this page · raw message

drivers/gpu/drm/xe/xe_vm.h +0 -2
index 47b981d9fc04..908e0c764968 100644
@@ -171,8 +171,6 @@ struct dma_fence *xe_vm_rebind(struct xe_vm *vm, bool rebind_worker);
 
 int xe_vm_invalidate_vma(struct xe_vma *vma);
 
-int xe_vm_async_fence_wait_start(struct dma_fence *fence);
-
 extern struct ttm_device_funcs xe_ttm_funcs;
 
 struct ttm_buffer_object *xe_vm_ttm_bo(struct xe_vm *vm);
drivers/gpu/drm/xe/xe_vm_types.h +5 -32
index ce1260b8d3ef..b48d0eaa8939 100644
@@ -15,7 +15,6 @@
 #include "xe_device_types.h"
 #include "xe_pt_types.h"
 
-struct async_op_fence;
 struct xe_bo;
 struct xe_sync_entry;
 struct xe_vm;
@@ -143,7 +142,7 @@ struct xe_vm {
 	/** @flags: flags for this VM, statically setup a creation time */
 #define XE_VM_FLAGS_64K			BIT(0)
 #define XE_VM_FLAG_COMPUTE_MODE		BIT(1)
-#define XE_VM_FLAG_ASYNC_BIND_OPS	BIT(2)
+#define XE_VM_FLAG_ASYNC_DEFAULT	BIT(2)
 #define XE_VM_FLAG_MIGRATION		BIT(3)
 #define XE_VM_FLAG_SCRATCH_PAGE		BIT(4)
 #define XE_VM_FLAG_FAULT_MODE		BIT(5)
@@ -179,40 +178,18 @@ struct xe_vm {
 	 */
 	struct work_struct destroy_work;
 
-	/** @async_ops: async VM operations (bind / unbinds) */
+	/** @ops_state: VM operations (bind / unbinds) state*/
 	struct {
-		/** @list: list of pending async VM ops */
+		/** @list: list of pending VM ops */
 		struct list_head pending;
-		/** @work: worker to execute async VM ops */
-		struct work_struct work;
-		/** @lock: protects list of pending async VM ops and fences */
-		spinlock_t lock;
-		/** @error_capture: error capture state */
-		struct {
-			/** @mm: user MM */
-			struct mm_struct *mm;
-			/**
-			 * @addr: user pointer to copy error capture state too
-			 */
-			u64 addr;
-			/** @wq: user fence wait queue for VM errors */
-			wait_queue_head_t wq;
-		} error_capture;
-		/** @fence: fence state */
-		struct {
-			/** @context: context of async fence */
-			u64 context;
-			/** @seqno: seqno of async fence */
-			u32 seqno;
-		} fence;
-		/** @error: error state for async VM ops */
+		/** @error: error state for VM ops */
 		int error;
 		/**
 		 * @munmap_rebind_inflight: an munmap style VM bind is in the
 		 * middle of a set of ops which requires a rebind at the end.
 		 */
 		bool munmap_rebind_inflight;
-	} async_ops;
+	} ops_state;
 
 	/** @userptr: user pointer state */
 	struct {
@@ -366,10 +343,6 @@ struct xe_vma_op {
 	u32 num_syncs;
 	/** @link: async operation link */
 	struct list_head link;
-	/**
-	 * @fence: async operation fence, signaled on last operation complete
-	 */
-	struct async_op_fence *fence;
 	/** @gt_mask: gt mask for this operation */
 	u8 gt_mask;
 	/** @flags: operation flags */
drivers/gpu/drm/xe/xe_wait_user_fence.c +5 -38

88 lines not on this page · raw message

include/uapi/drm/xe_drm.h +9 -70

125 lines not on this page · raw message

Signature · 1 line
2.34.1
#117 lore raw

Re: [Intel-xe] [PATCH v2 30/31] drm/xe: remove async worker, sync binds, new error handling

Hi, Matthew

Some quick comments below. I really need to apply this patch to see the resulting code so I'll do a full review in the next version where I have something that applies cleanly.

/Thomas

Quoted 1 line · Matthew Brost

Async worker is gone, all jobs and memory allocations done in IOCTL.

Done synchronously?

Quoted 7 lines

Async vs. sync now means when do bind operations complete relative to the IOCTL. Async completes when out-syncs signal while sync completes when the IOCTL returns. In-syncs and out-syncs are only allowed in async
mode.

Quoted 8 lines

The error handling is similar to before, on memory allocation errors binds are pause, VM is put in an error state, and the bind IOCTL returns -ENOSPC. The user is allowed to issue sync unbinds, with the reclaim bit set, while in an error state. Bind operations without the reclaim bit set are rejected with -EALREADY until the exits the error state. To exit the error issue a restart bind operation which will pick
up where the original failure left off.

What about -EINTR?

Quoted 2 lines

TODO: Update kernel doc

This is done in the next patch in the series, right? so we can drop this TODO?

Quoted 16 lines

---
 drivers/gpu/drm/xe/xe_engine.c          |   7 +-
 drivers/gpu/drm/xe/xe_engine_types.h    |   1 +

 drivers/gpu/drm/xe/xe_exec.c            |  42 --
 drivers/gpu/drm/xe/xe_sync.c            |  14 +-
 drivers/gpu/drm/xe/xe_sync.h            |   2 +-

 drivers/gpu/drm/xe/xe_vm.c              | 712 ++++++---------------- --
 drivers/gpu/drm/xe/xe_vm.h              |   2 - drivers/gpu/drm/xe/xe_vm_types.h        |  37 +- drivers/gpu/drm/xe/xe_wait_user_fence.c |  43 +- include/uapi/drm/xe_drm.h               |  79 +--

 10 files changed, 213 insertions(+), 726 deletions(-)
author maintainer
#118 lore raw

PATCH v2 31/31 drm/xe/uapi: Add some VM bind kernel doc

In reply to Matthew Brost

Try to explain how VM bind works in Xe.

---
 include/uapi/drm/xe_drm.h | 45 ++++++++++++++++++++++++++++++++++++---
 1 file changed, 42 insertions(+), 3 deletions(-)
include/uapi/drm/xe_drm.h +42 -3
index cb4debe4ebda..c7137db2cbe8 100644
@@ -148,7 +148,16 @@ struct drm_xe_engine_class_instance {
 	 * Kernel only classes (not actual hardware engine class). Used for
 	 * creating ordered queues of VM bind operations.
 	 */
+	/**
+	 * @DRM_XE_ENGINE_CLASS_VM_BIND_ASYNC: VM bind engine which are allowed
+	 * to use in / out syncs. The out sync indicates bind op(s) completion.
+	 */
 #define DRM_XE_ENGINE_CLASS_VM_BIND_ASYNC	5
+	/**
+	 * @DRM_XE_ENGINE_CLASS_VM_BIND_SYNC: VM bind engine which are not
+	 * allowed to use in / out syncs, The IOCTL return indicates bind op(s)
+	 * completion.
+	 */
 #define DRM_XE_ENGINE_CLASS_VM_BIND_SYNC	6
 
 	__u16 engine_instance;
@@ -322,6 +331,7 @@ struct drm_xe_vm_create {
 
 #define DRM_XE_VM_CREATE_SCRATCH_PAGE	(0x1 << 0)
 #define DRM_XE_VM_CREATE_COMPUTE_MODE	(0x1 << 1)
+	/** @DRM_XE_VM_CREATE_ASYNC_DEFAULT: Default VM bind engine is async */
 #define DRM_XE_VM_CREATE_ASYNC_DEFAULT	(0x1 << 2)
 #define DRM_XE_VM_CREATE_FAULT_MODE	(0x1 << 3)
 
@@ -379,21 +389,44 @@ struct drm_xe_vm_bind_op {
 	/** @mem_region: Memory region to prefetch VMA to, instance not a mask */
 	__u32 region;
 
+	/** @XE_VM_BIND_OP_MAP: Map a buffer object */
 #define XE_VM_BIND_OP_MAP		0x0
+	/** @XE_VM_BIND_OP_UNMAP: Unmap a buffer object or userptr */
 #define XE_VM_BIND_OP_UNMAP		0x1
+	/** @XE_VM_BIND_OP_MAP_USERPTR: Map a userptr */
 #define XE_VM_BIND_OP_MAP_USERPTR	0x2
+	/**
+	 * @XE_VM_BIND_OP_RESTART: Restart last bind operation that failed with
+	 * -ENOSPC
+	 */
 #define XE_VM_BIND_OP_RESTART		0x3
+	/**
+	 * @XE_VM_BIND_OP_UNMAP_ALL: Unmap all mappings associated with a
+	 * buffer ibject
+	 */
 #define XE_VM_BIND_OP_UNMAP_ALL		0x4
+	/**
+	 * @XE_VM_BIND_OP_PREFETCH: For a deferred bind (faulting VM)
+	 * validate buffer object and (re)bind
+	 */
 #define XE_VM_BIND_OP_PREFETCH		0x5
-
+	/** @XE_VM_BIND_FLAG_READONLY: Set mapping to read only */
 #define XE_VM_BIND_FLAG_READONLY	(0x1 << 16)
+	/**
+	 * @XE_VM_BIND_FLAG_ASYNC: Sanity check for if using async bind engine
+	 * (in / out syncs) this set needs to be set.
+	 */
 #define XE_VM_BIND_FLAG_ASYNC		(0x1 << 17)
-	/*
+	/**
+	 * @XE_VM_BIND_FLAG_IMMEDIATE:
+	 *
 	 * Valid on a faulting VM only, do the MAP operation immediately rather
 	 * than differing the MAP to the page fault handler.
 	 */
 #define XE_VM_BIND_FLAG_IMMEDIATE	(0x1 << 18)
-	/*
+	/**
+	 * @XE_VM_BIND_FLAG_NULL:
+	 *
 	 * When the NULL flag is set, the page tables are setup with a special
 	 * bit which indicates writes are dropped and all reads return zero. The
 	 * NULL flags is only valid for XE_VM_BIND_OP_MAP operations, the BO
@@ -401,6 +434,12 @@ struct drm_xe_vm_bind_op {
 	 * VK sparse bindings.
 	 */
 #define XE_VM_BIND_FLAG_NULL		(0x1 << 19)
+	/**
+	 * @XE_VM_BIND_FLAG_RECLAIM: Should be set when a VM is in an error
+	 * state (bind op returns -ENOSPC), used with sync bind engines to issue
+	 * UNMAP operations which hopefully free enough memory so when VM is
+	 * restarted via @XE_VM_BIND_OP_RESTART the failed bind ops succeed.
+	 */
 #define XE_VM_BIND_FLAG_RECLAIM		(0x1 << 20)
 
 	/** @reserved: Reserved */
Signature · 1 line
2.34.1
Reviewed-by on v2 31/31
#119 lore raw

Re: [Intel-xe] [PATCH v2 31/31] drm/xe/uapi: Add some VM bind kernel doc

Quoted 1 line · Matthew Brost

Try to explain how VM bind works in Xe.

We will need more doc and likely with examples and all... but this is already something we need.

Quoted 99 lines
---
 include/uapi/drm/xe_drm.h | 45 ++++++++++++++++++++++++++++++++++++---
 1 file changed, 42 insertions(+), 3 deletions(-)
include/uapi/drm/xe_drm.h +42 -3
index cb4debe4ebda..c7137db2cbe8 100644
@@ -148,7 +148,16 @@ struct drm_xe_engine_class_instance {
 	 * Kernel only classes (not actual hardware engine class). Used for
 	 * creating ordered queues of VM bind operations.
 	 */
+	/**
+	 * @DRM_XE_ENGINE_CLASS_VM_BIND_ASYNC: VM bind engine which are allowed
+	 * to use in / out syncs. The out sync indicates bind op(s) completion.
+	 */
 #define DRM_XE_ENGINE_CLASS_VM_BIND_ASYNC	5
+	/**
+	 * @DRM_XE_ENGINE_CLASS_VM_BIND_SYNC: VM bind engine which are not
+	 * allowed to use in / out syncs, The IOCTL return indicates bind op(s)
+	 * completion.
+	 */
 #define DRM_XE_ENGINE_CLASS_VM_BIND_SYNC	6
 
 	__u16 engine_instance;
@@ -322,6 +331,7 @@ struct drm_xe_vm_create {
 
 #define DRM_XE_VM_CREATE_SCRATCH_PAGE	(0x1 << 0)
 #define DRM_XE_VM_CREATE_COMPUTE_MODE	(0x1 << 1)
+	/** @DRM_XE_VM_CREATE_ASYNC_DEFAULT: Default VM bind engine is async */
 #define DRM_XE_VM_CREATE_ASYNC_DEFAULT	(0x1 << 2)
 #define DRM_XE_VM_CREATE_FAULT_MODE	(0x1 << 3)
 
@@ -379,21 +389,44 @@ struct drm_xe_vm_bind_op {
 	/** @mem_region: Memory region to prefetch VMA to, instance not a mask */
 	__u32 region;
 
+	/** @XE_VM_BIND_OP_MAP: Map a buffer object */
 #define XE_VM_BIND_OP_MAP		0x0
+	/** @XE_VM_BIND_OP_UNMAP: Unmap a buffer object or userptr */
 #define XE_VM_BIND_OP_UNMAP		0x1
+	/** @XE_VM_BIND_OP_MAP_USERPTR: Map a userptr */
 #define XE_VM_BIND_OP_MAP_USERPTR	0x2
+	/**
+	 * @XE_VM_BIND_OP_RESTART: Restart last bind operation that failed with
+	 * -ENOSPC
+	 */
 #define XE_VM_BIND_OP_RESTART		0x3
+	/**
+	 * @XE_VM_BIND_OP_UNMAP_ALL: Unmap all mappings associated with a
+	 * buffer ibject
+	 */
 #define XE_VM_BIND_OP_UNMAP_ALL		0x4
+	/**
+	 * @XE_VM_BIND_OP_PREFETCH: For a deferred bind (faulting VM)
+	 * validate buffer object and (re)bind
+	 */
 #define XE_VM_BIND_OP_PREFETCH		0x5
-
+	/** @XE_VM_BIND_FLAG_READONLY: Set mapping to read only */
 #define XE_VM_BIND_FLAG_READONLY	(0x1 << 16)
+	/**
+	 * @XE_VM_BIND_FLAG_ASYNC: Sanity check for if using async bind engine
+	 * (in / out syncs) this set needs to be set.
+	 */
 #define XE_VM_BIND_FLAG_ASYNC		(0x1 << 17)
-	/*
+	/**
+	 * @XE_VM_BIND_FLAG_IMMEDIATE:
+	 *
 	 * Valid on a faulting VM only, do the MAP operation immediately rather
 	 * than differing the MAP to the page fault handler.
 	 */
 #define XE_VM_BIND_FLAG_IMMEDIATE	(0x1 << 18)
-	/*
+	/**
+	 * @XE_VM_BIND_FLAG_NULL:
+	 *
 	 * When the NULL flag is set, the page tables are setup with a special
 	 * bit which indicates writes are dropped and all reads return zero. The
 	 * NULL flags is only valid for XE_VM_BIND_OP_MAP operations, the BO
@@ -401,6 +434,12 @@ struct drm_xe_vm_bind_op {
 	 * VK sparse bindings.
 	 */
 #define XE_VM_BIND_FLAG_NULL		(0x1 << 19)
+	/**
+	 * @XE_VM_BIND_FLAG_RECLAIM: Should be set when a VM is in an error
+	 * state (bind op returns -ENOSPC), used with sync bind engines to issue
+	 * UNMAP operations which hopefully free enough memory so when VM is
+	 * restarted via @XE_VM_BIND_OP_RESTART the failed bind ops succeed.
+	 */
 #define XE_VM_BIND_FLAG_RECLAIM		(0x1 << 20)
 
 	/** @reserved: Reserved */
Signature · 1 line
2.34.1
maintainer Reviewed-by
#120 lore raw

Re: [Intel-xe] [PATCH v2 31/31] drm/xe/uapi: Add some VM bind kernel doc

Quoted 6 lines · Rodrigo Vivi
Quoted 1 line · Matthew Brost

Try to explain how VM bind works in Xe.

We will need more doc and likely with examples and all... but this is already something we need.

Quoted 99 lines
Quoted 99 lines
---
  include/uapi/drm/xe_drm.h | 45 ++++++++++++++++++++++++++++++++++++---
  1 file changed, 42 insertions(+), 3 deletions(-)
include/uapi/drm/xe_drm.h +42 -3
index cb4debe4ebda..c7137db2cbe8 100644
@@ -148,7 +148,16 @@ struct drm_xe_engine_class_instance {
  	 * Kernel only classes (not actual hardware engine class). Used for
  	 * creating ordered queues of VM bind operations.
  	 */
+	/**
+	 * @DRM_XE_ENGINE_CLASS_VM_BIND_ASYNC: VM bind engine which are allowed
+	 * to use in / out syncs. The out sync indicates bind op(s) completion.
+	 */
  #define DRM_XE_ENGINE_CLASS_VM_BIND_ASYNC	5
+	/**
+	 * @DRM_XE_ENGINE_CLASS_VM_BIND_SYNC: VM bind engine which are not
+	 * allowed to use in / out syncs, The IOCTL return indicates bind op(s)
+	 * completion.
+	 */
  #define DRM_XE_ENGINE_CLASS_VM_BIND_SYNC	6
 
  	__u16 engine_instance;
@@ -322,6 +331,7 @@ struct drm_xe_vm_create {
 
  #define DRM_XE_VM_CREATE_SCRATCH_PAGE	(0x1 << 0)
  #define DRM_XE_VM_CREATE_COMPUTE_MODE	(0x1 << 1)
+	/** @DRM_XE_VM_CREATE_ASYNC_DEFAULT: Default VM bind engine is async */
  #define DRM_XE_VM_CREATE_ASYNC_DEFAULT	(0x1 << 2)
  #define DRM_XE_VM_CREATE_FAULT_MODE	(0x1 << 3)
 
@@ -379,21 +389,44 @@ struct drm_xe_vm_bind_op {
  	/** @mem_region: Memory region to prefetch VMA to, instance not a mask */
  	__u32 region;
 
+	/** @XE_VM_BIND_OP_MAP: Map a buffer object */
  #define XE_VM_BIND_OP_MAP		0x0
+	/** @XE_VM_BIND_OP_UNMAP: Unmap a buffer object or userptr */
  #define XE_VM_BIND_OP_UNMAP		0x1
+	/** @XE_VM_BIND_OP_MAP_USERPTR: Map a userptr */
  #define XE_VM_BIND_OP_MAP_USERPTR	0x2
+	/**
+	 * @XE_VM_BIND_OP_RESTART: Restart last bind operation that failed with
+	 * -ENOSPC
+	 */
  #define XE_VM_BIND_OP_RESTART		0x3
+	/**
+	 * @XE_VM_BIND_OP_UNMAP_ALL: Unmap all mappings associated with a
+	 * buffer ibject
+	 */
  #define XE_VM_BIND_OP_UNMAP_ALL		0x4
+	/**
+	 * @XE_VM_BIND_OP_PREFETCH: For a deferred bind (faulting VM)
+	 * validate buffer object and (re)bind
+	 */
  #define XE_VM_BIND_OP_PREFETCH		0x5
-
+	/** @XE_VM_BIND_FLAG_READONLY: Set mapping to read only */
  #define XE_VM_BIND_FLAG_READONLY	(0x1 << 16)
+	/**
+	 * @XE_VM_BIND_FLAG_ASYNC: Sanity check for if using async bind engine
+	 * (in / out syncs) this set needs to be set.
+	 */
  #define XE_VM_BIND_FLAG_ASYNC		(0x1 << 17)
-	/*
+	/**
+	 * @XE_VM_BIND_FLAG_IMMEDIATE:
+	 *
  	 * Valid on a faulting VM only, do the MAP operation immediately rather
  	 * than differing the MAP to the page fault handler.
  	 */
  #define XE_VM_BIND_FLAG_IMMEDIATE	(0x1 << 18)
-	/*
+	/**
+	 * @XE_VM_BIND_FLAG_NULL:
+	 *
  	 * When the NULL flag is set, the page tables are setup with a special
  	 * bit which indicates writes are dropped and all reads return zero. The
  	 * NULL flags is only valid for XE_VM_BIND_OP_MAP operations, the BO
@@ -401,6 +434,12 @@ struct drm_xe_vm_bind_op {
  	 * VK sparse bindings.
  	 */
  #define XE_VM_BIND_FLAG_NULL		(0x1 << 19)
+	/**
+	 * @XE_VM_BIND_FLAG_RECLAIM: Should be set when a VM is in an error
+	 * state (bind op returns -ENOSPC), used with sync bind engines to issue
+	 * UNMAP operations which hopefully free enough memory so when VM is
+	 * restarted via @XE_VM_BIND_OP_RESTART the failed bind ops succeed.
+	 */
  #define XE_VM_BIND_FLAG_RECLAIM		(0x1 << 20)
 
  	/** @reserved: Reserved */
Signature · 1 line
2.34.1
#121 lore raw

[Intel-xe] ✗ CI.Patch_applied: failure for Upstreaming prep / all of mbrosts patches (rev2)

In reply to Matthew Brost
== Series Details ==

== Series Details ==

Series: Upstreaming prep / all of mbrosts patches (rev2)
URL : https://patchwork.freedesktop.org/series/117156/
State : failure

== Summary ==

=== Applying kernel patches on branch 'drm-xe-next' with base: === Base commit: 9a7a643c2 drm/xe: Fix media detection for pre-GMD_ID platforms === git am output follows ===
error: patch failed: drivers/gpu/drm/xe/xe_pt.c:778
error: drivers/gpu/drm/xe/xe_pt.c: patch does not apply
hint: Use 'git am --show-current-patch' to see the failed patch
Applying: drm/sched: Add run_wq argument to drm_sched_init
Applying: drm/sched: Move schedule policy to scheduler
Applying: drm/sched: Add DRM_SCHED_POLICY_SINGLE_ENTITY scheduling policy
Applying: drm/xe: Use DRM_SCHED_POLICY_SINGLE_ENTITY mode
Applying: drm/xe: Long running job update
Applying: drm/xe: Ensure LR engines are not persistent
Applying: drm/xe: Only try to lock external BOs in VM bind
Applying: drm/xe: VM LRU bulk move
Applying: drm/xe/guc: Read HXG fields from DW1 of G2H response
Applying: drm/xe/guc: Return the lower part of blocking H2G message
Applying: drm/xe/guc: Use doorbells for submission if possible
Applying: drm/xe/guc: Print doorbell ID in GuC engine debugfs entry
Applying: maple_tree: split up MA_STATE() macro
Applying: maple_tree: Export mas_preallocate
Applying: drm: manager to keep track of GPUs VA mappings
Applying: drm/xe: Port Xe to GPUVA
Patch failed at 0016 drm/xe: Port Xe to GPUVA
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".

#122 lore raw

Re: [Intel-xe] ✗ CI.Patch_applied: failure for Upstreaming prep / all of mbrosts patches (rev2)

Sent from my iPad

Quoted 38 lines · Patchwork

== Series Details ==

Series: Upstreaming prep / all of mbrosts patches (rev2)
URL : https://patchwork.freedesktop.org/series/117156/
State : failure

== Summary ==

=== Applying kernel patches on branch 'drm-xe-next' with base: === Base commit: 9a7a643c2 drm/xe: Fix media detection for pre-GMD_ID platforms === git am output follows ===
error: patch failed: drivers/gpu/drm/xe/xe_pt.c:778
error: drivers/gpu/drm/xe/xe_pt.c: patch does not apply
hint: Use 'git am --show-current-patch' to see the failed patch
Applying: drm/sched: Add run_wq argument to drm_sched_init
Applying: drm/sched: Move schedule policy to scheduler
Applying: drm/sched: Add DRM_SCHED_POLICY_SINGLE_ENTITY scheduling policy
Applying: drm/xe: Use DRM_SCHED_POLICY_SINGLE_ENTITY mode
Applying: drm/xe: Long running job update
Applying: drm/xe: Ensure LR engines are not persistent
Applying: drm/xe: Only try to lock external BOs in VM bind
Applying: drm/xe: VM LRU bulk move
Applying: drm/xe/guc: Read HXG fields from DW1 of G2H response
Applying: drm/xe/guc: Return the lower part of blocking H2G message
Applying: drm/xe/guc: Use doorbells for submission if possible
Applying: drm/xe/guc: Print doorbell ID in GuC engine debugfs entry
Applying: maple_tree: split up MA_STATE() macro
Applying: maple_tree: Export mas_preallocate
Applying: drm: manager to keep track of GPUs VA mappings
Applying: drm/xe: Port Xe to GPUVA
Patch failed at 0016 drm/xe: Port Xe to GPUVA
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".

#123 lore raw

Re: [Intel-xe] ✗ CI.Patch_applied: failure for Upstreaming prep / all of mbrosts patches (rev2)

In reply to Patchwork
Quoted 30 lines · Patchwork

== Series Details ==

Series: Upstreaming prep / all of mbrosts patches (rev2)
URL : https://patchwork.freedesktop.org/series/117156/
State : failure

== Summary ==

=== Applying kernel patches on branch 'drm-xe-next' with base: === Base commit: 9a7a643c2 drm/xe: Fix media detection for pre-GMD_ID platforms === git am output follows ===
error: patch failed: drivers/gpu/drm/xe/xe_pt.c:778
error: drivers/gpu/drm/xe/xe_pt.c: patch does not apply
hint: Use 'git am --show-current-patch' to see the failed patch
Applying: drm/sched: Add run_wq argument to drm_sched_init
Applying: drm/sched: Move schedule policy to scheduler
Applying: drm/sched: Add DRM_SCHED_POLICY_SINGLE_ENTITY scheduling policy
Applying: drm/xe: Use DRM_SCHED_POLICY_SINGLE_ENTITY mode
Applying: drm/xe: Long running job update
Applying: drm/xe: Ensure LR engines are not persistent
Applying: drm/xe: Only try to lock external BOs in VM bind
Applying: drm/xe: VM LRU bulk move
Applying: drm/xe/guc: Read HXG fields from DW1 of G2H response
Applying: drm/xe/guc: Return the lower part of blocking H2G message
Applying: drm/xe/guc: Use doorbells for submission if possible
Applying: drm/xe/guc: Print doorbell ID in GuC engine debugfs entry

Quoted 8 lines

Applying: maple_tree: split up MA_STATE() macro
Applying: maple_tree: Export mas_preallocate
Applying: drm: manager to keep track of GPUs VA mappings
Applying: drm/xe: Port Xe to GPUVA
Patch failed at 0016 drm/xe: Port Xe to GPUVA
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".

damn I hate Apple Mail. I wanted to select which message in the thread I am replying to, and it naturally assumes I want to quote and reply to the most recent.

Anyway, is there a Mesa branch that works with this series yet? Or will the current Xe branch work here? I already needed to use a special flavor of the branch because of shared object issues that hadn't been merged into the main MR, and I'm using @mlankhorst's uAPI header and validation, and my own compat ioctl function one line change to make 32 bit work.

Otherwise, if there's no working userspace for this yet, I'll just give it a pass at testing for now.

I did notice some typoes in the above comments or commit messages, though. Like "doorbels". I'll have to look over it again if it's worth noting any more.

#124 lore raw
In reply to Matthew Brost

Hi, Matthew

Quoted 13 lines · Matthew Brost

Series includes:

- DRM scheduler changes for firmware backends (1 to 1 entity to scheduler)
- LR workload story
- VM LRU handling
- GuC doorbell submission
- Basic GPUVA
- Sparse binding support
- GPUVA + extobj + drm exec (collaboration with dakr + Francois Dugast)
- GPUVA + userptr (minimal, more can be once Nouveua has userptr)
- Fix fencing rules for compute / fault mode
- Remove async worker for VM + error handling updates
- Kernel doc for VM bind

It would be beneficial to the reviewer if  you could make separate series where applicable with links to previous discussions and add information about whether all design issues /discussions were resolved or if anything was remaining and a brief guidance as to what is in each patch of the series.

/Thomas

Quoted 119 lines

Series is not fully ready for upstream and some of these things need to get merged upstream first but overall it is largely correct and certainly step in the right direction. Based on its size and the fact it took me 8 hours to rebase this today I'd say let's get this tree and fixup everything else in place.

Minor uAPI breakage, IGT series:
https://patchwork.freedesktop.org/series/117177/

gitlab link:
https://gitlab.freedesktop.org/drm/xe/kernel/-/merge_requests/344

Christian König (1):
drm: execution context for GEM buffers v3

Danilo Krummrich (2):
maple_tree: split up MA_STATE() macro
drm: manager to keep track of GPUs VA mappings

Matthew Brost (28):
drm/sched: Add run_wq argument to drm_sched_init drm/sched: Move schedule policy to scheduler drm/sched: Add DRM_SCHED_POLICY_SINGLE_ENTITY scheduling policy drm/xe: Use DRM_SCHED_POLICY_SINGLE_ENTITY mode drm/xe: Long running job update
drm/xe: Ensure LR engines are not persistent
drm/xe: Only try to lock external BOs in VM bind drm/xe: VM LRU bulk move
drm/xe/guc: Read HXG fields from DW1 of G2H response drm/xe/guc: Return the lower part of blocking H2G message drm/xe/guc: Use doorbells for submission if possible drm/xe/guc: Print doorbell ID in GuC engine debugfs entry
maple_tree: Export mas_preallocate
drm/xe: Port Xe to GPUVA
drm/xe: NULL binding implementation
drm/xe: Avoid doing rebinds
drm/xe: Reduce the number list links in xe_vma drm/xe: Optimize size of xe_vma allocation drm/gpuva: Add drm device to GPUVA manager drm/gpuva: Move dma-resv to GPUVA manager
drm/gpuva: Add support for extobj
drm/xe: Userptr refactor
drm/exec: Always compile drm_exec
drm/xe: Use drm_exec for locking rather than TTM exec helpers drm/xe: Allow dma-fences as in-syncs for compute / faulting VM drm/xe: Allow compute VMs to output dma-fences on binds drm/xe: remove async worker, sync binds, new error handling drm/xe/uapi: Add some VM bind kernel doc

  Documentation/gpu/drm-mm.rst                 |   43 +
  drivers/gpu/drm/Kconfig                      |    6 +
  drivers/gpu/drm/Makefile                     |    4 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c   |    3 +-
  drivers/gpu/drm/drm_debugfs.c                |   41 +
  drivers/gpu/drm/drm_exec.c                   |  248 ++
  drivers/gpu/drm/drm_gem.c                    |    3 +
  drivers/gpu/drm/drm_gpuva_mgr.c              | 1779 ++++++++++++
  drivers/gpu/drm/etnaviv/etnaviv_sched.c      |    5 +-
  drivers/gpu/drm/i915/display/intel_display.c |    6 +-
  drivers/gpu/drm/lima/lima_sched.c            |    5 +-
  drivers/gpu/drm/msm/msm_ringbuffer.c         |    5 +-
  drivers/gpu/drm/panfrost/panfrost_job.c      |    5 +-
  drivers/gpu/drm/scheduler/sched_entity.c     |   84 +-
  drivers/gpu/drm/scheduler/sched_fence.c      |    2 +-
  drivers/gpu/drm/scheduler/sched_main.c       |   88 +-
  drivers/gpu/drm/v3d/v3d_sched.c              |   25 +-
  drivers/gpu/drm/xe/Kconfig                   |    1 +
  drivers/gpu/drm/xe/regs/xe_guc_regs.h        |    1 +
  drivers/gpu/drm/xe/tests/xe_bo.c             |   26 +-
  drivers/gpu/drm/xe/tests/xe_migrate.c        |    6 +-
  drivers/gpu/drm/xe/xe_bo.c                   |  100 +-
  drivers/gpu/drm/xe/xe_bo.h                   |   13 +-
  drivers/gpu/drm/xe/xe_bo_evict.c             |   24 +-
  drivers/gpu/drm/xe/xe_bo_types.h             |    1 -
  drivers/gpu/drm/xe/xe_device.c               |    2 +-
  drivers/gpu/drm/xe/xe_dma_buf.c              |    2 +-
  drivers/gpu/drm/xe/xe_engine.c               |   50 +-
  drivers/gpu/drm/xe/xe_engine.h               |    4 +
  drivers/gpu/drm/xe/xe_engine_types.h         |    1 +
  drivers/gpu/drm/xe/xe_exec.c                 |  117 +-
  drivers/gpu/drm/xe/xe_execlist.c             |    3 +-
  drivers/gpu/drm/xe/xe_gt_pagefault.c         |   84 +-
  drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c  |   14 +-
  drivers/gpu/drm/xe/xe_guc.c                  |    6 +
  drivers/gpu/drm/xe/xe_guc_ct.c               |   12 +-
  drivers/gpu/drm/xe/xe_guc_engine_types.h     |    9 +
  drivers/gpu/drm/xe/xe_guc_pc.c               |    6 +-
  drivers/gpu/drm/xe/xe_guc_submit.c           |  398 ++-
  drivers/gpu/drm/xe/xe_guc_submit.h           |    1 +
  drivers/gpu/drm/xe/xe_guc_types.h            |    4 +
  drivers/gpu/drm/xe/xe_huc.c                  |    2 +-
  drivers/gpu/drm/xe/xe_lrc.c                  |    8 +-
  drivers/gpu/drm/xe/xe_migrate.c              |   31 +-
  drivers/gpu/drm/xe/xe_pt.c                   |  198 +-
  drivers/gpu/drm/xe/xe_sync.c                 |   26 +-
  drivers/gpu/drm/xe/xe_sync.h                 |    2 +-
  drivers/gpu/drm/xe/xe_trace.h                |   20 +-
  drivers/gpu/drm/xe/xe_vm.c                   | 2567 +++++++-----------
  drivers/gpu/drm/xe/xe_vm.h                   |  135 +-
  drivers/gpu/drm/xe/xe_vm_madvise.c           |  125 +-
  drivers/gpu/drm/xe/xe_vm_types.h             |  324 ++-
  drivers/gpu/drm/xe/xe_wait_user_fence.c      |   43 +-
  include/drm/drm_debugfs.h                    |   24 +
  include/drm/drm_drv.h                        |    7 +
  include/drm/drm_exec.h                       |  115 +
  include/drm/drm_gem.h                        |   75 +
  include/drm/drm_gpuva_mgr.h                  |  759 ++++++
  include/drm/gpu_scheduler.h                  |   29 +-
  include/linux/maple_tree.h                   |    7 +-
  include/uapi/drm/xe_drm.h                    |  128 +-
  lib/maple_tree.c                             |    1 +
  62 files changed, 5543 insertions(+), 2320 deletions(-)

create mode 100644 drivers/gpu/drm/drm_exec.c create mode 100644 drivers/gpu/drm/drm_gpuva_mgr.c create mode 100644 include/drm/drm_exec.h create mode 100644 include/drm/drm_gpuva_mgr.h

author maintainer
#125 lore raw
Quoted 17 lines · Thomas Hellström

Hi, Matthew

Quoted 13 lines · Matthew Brost

Series includes:

- DRM scheduler changes for firmware backends (1 to 1 entity to scheduler)
- LR workload story
- VM LRU handling
- GuC doorbell submission
- Basic GPUVA
- Sparse binding support
- GPUVA + extobj + drm exec (collaboration with dakr + Francois Dugast)
- GPUVA + userptr (minimal, more can be once Nouveua has userptr)
- Fix fencing rules for compute / fault mode
- Remove async worker for VM + error handling updates
- Kernel doc for VM bind

Quoted 6 lines

It would be beneficial to the reviewer if  you could make separate series where applicable with links to previous discussions and add information about whether all design issues /discussions were resolved or if anything was remaining and a brief guidance as to what is in each patch of the series.

Basically nothing has been reviewed, sad but this where we are. Most of this code is 2-3 months old too, I can't maintain like 5 branches out code and keep everything stable, hence 1 large series. Going forward, I'd ask for timely reviews, I make an effort to review code actively and if I'm asked review code I do it in a timely manner. In case, I think the team is just going to have get through this. Again this isn't truely upstream either, we just need to get this our repo. Any of the common code will also go through reviews on dri-devel before we go upstream.

Matt

Quoted 124 lines

/Thomas

Quoted 119 lines

Series is not fully ready for upstream and some of these things need to get merged upstream first but overall it is largely correct and certainly step in the right direction. Based on its size and the fact it took me 8 hours to rebase this today I'd say let's get this tree and fixup everything else in place.

Minor uAPI breakage, IGT series:
https://patchwork.freedesktop.org/series/117177/

gitlab link:
https://gitlab.freedesktop.org/drm/xe/kernel/-/merge_requests/344

Christian König (1):
drm: execution context for GEM buffers v3

Danilo Krummrich (2):
maple_tree: split up MA_STATE() macro
drm: manager to keep track of GPUs VA mappings

Matthew Brost (28):
drm/sched: Add run_wq argument to drm_sched_init drm/sched: Move schedule policy to scheduler drm/sched: Add DRM_SCHED_POLICY_SINGLE_ENTITY scheduling policy drm/xe: Use DRM_SCHED_POLICY_SINGLE_ENTITY mode drm/xe: Long running job update
drm/xe: Ensure LR engines are not persistent
drm/xe: Only try to lock external BOs in VM bind drm/xe: VM LRU bulk move
drm/xe/guc: Read HXG fields from DW1 of G2H response drm/xe/guc: Return the lower part of blocking H2G message drm/xe/guc: Use doorbells for submission if possible drm/xe/guc: Print doorbell ID in GuC engine debugfs entry
maple_tree: Export mas_preallocate
drm/xe: Port Xe to GPUVA
drm/xe: NULL binding implementation
drm/xe: Avoid doing rebinds
drm/xe: Reduce the number list links in xe_vma drm/xe: Optimize size of xe_vma allocation drm/gpuva: Add drm device to GPUVA manager drm/gpuva: Move dma-resv to GPUVA manager
drm/gpuva: Add support for extobj
drm/xe: Userptr refactor
drm/exec: Always compile drm_exec
drm/xe: Use drm_exec for locking rather than TTM exec helpers drm/xe: Allow dma-fences as in-syncs for compute / faulting VM drm/xe: Allow compute VMs to output dma-fences on binds drm/xe: remove async worker, sync binds, new error handling drm/xe/uapi: Add some VM bind kernel doc

  Documentation/gpu/drm-mm.rst                 |   43 +
  drivers/gpu/drm/Kconfig                      |    6 +
  drivers/gpu/drm/Makefile                     |    4 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c   |    3 +-
  drivers/gpu/drm/drm_debugfs.c                |   41 +
  drivers/gpu/drm/drm_exec.c                   |  248 ++
  drivers/gpu/drm/drm_gem.c                    |    3 +
  drivers/gpu/drm/drm_gpuva_mgr.c              | 1779 ++++++++++++
  drivers/gpu/drm/etnaviv/etnaviv_sched.c      |    5 +-
  drivers/gpu/drm/i915/display/intel_display.c |    6 +-
  drivers/gpu/drm/lima/lima_sched.c            |    5 +-
  drivers/gpu/drm/msm/msm_ringbuffer.c         |    5 +-
  drivers/gpu/drm/panfrost/panfrost_job.c      |    5 +-
  drivers/gpu/drm/scheduler/sched_entity.c     |   84 +-
  drivers/gpu/drm/scheduler/sched_fence.c      |    2 +-
  drivers/gpu/drm/scheduler/sched_main.c       |   88 +-
  drivers/gpu/drm/v3d/v3d_sched.c              |   25 +-
  drivers/gpu/drm/xe/Kconfig                   |    1 +
  drivers/gpu/drm/xe/regs/xe_guc_regs.h        |    1 +
  drivers/gpu/drm/xe/tests/xe_bo.c             |   26 +-
  drivers/gpu/drm/xe/tests/xe_migrate.c        |    6 +-
  drivers/gpu/drm/xe/xe_bo.c                   |  100 +-
  drivers/gpu/drm/xe/xe_bo.h                   |   13 +-
  drivers/gpu/drm/xe/xe_bo_evict.c             |   24 +-
  drivers/gpu/drm/xe/xe_bo_types.h             |    1 -
  drivers/gpu/drm/xe/xe_device.c               |    2 +-
  drivers/gpu/drm/xe/xe_dma_buf.c              |    2 +-
  drivers/gpu/drm/xe/xe_engine.c               |   50 +-
  drivers/gpu/drm/xe/xe_engine.h               |    4 +
  drivers/gpu/drm/xe/xe_engine_types.h         |    1 +
  drivers/gpu/drm/xe/xe_exec.c                 |  117 +-
  drivers/gpu/drm/xe/xe_execlist.c             |    3 +-
  drivers/gpu/drm/xe/xe_gt_pagefault.c         |   84 +-
  drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c  |   14 +-
  drivers/gpu/drm/xe/xe_guc.c                  |    6 +
  drivers/gpu/drm/xe/xe_guc_ct.c               |   12 +-
  drivers/gpu/drm/xe/xe_guc_engine_types.h     |    9 +
  drivers/gpu/drm/xe/xe_guc_pc.c               |    6 +-
  drivers/gpu/drm/xe/xe_guc_submit.c           |  398 ++-
  drivers/gpu/drm/xe/xe_guc_submit.h           |    1 +
  drivers/gpu/drm/xe/xe_guc_types.h            |    4 +
  drivers/gpu/drm/xe/xe_huc.c                  |    2 +-
  drivers/gpu/drm/xe/xe_lrc.c                  |    8 +-
  drivers/gpu/drm/xe/xe_migrate.c              |   31 +-
  drivers/gpu/drm/xe/xe_pt.c                   |  198 +-
  drivers/gpu/drm/xe/xe_sync.c                 |   26 +-
  drivers/gpu/drm/xe/xe_sync.h                 |    2 +-
  drivers/gpu/drm/xe/xe_trace.h                |   20 +-
  drivers/gpu/drm/xe/xe_vm.c                   | 2567 +++++++-----------
  drivers/gpu/drm/xe/xe_vm.h                   |  135 +-
  drivers/gpu/drm/xe/xe_vm_madvise.c           |  125 +-
  drivers/gpu/drm/xe/xe_vm_types.h             |  324 ++-
  drivers/gpu/drm/xe/xe_wait_user_fence.c      |   43 +-
  include/drm/drm_debugfs.h                    |   24 +
  include/drm/drm_drv.h                        |    7 +
  include/drm/drm_exec.h                       |  115 +
  include/drm/drm_gem.h                        |   75 +
  include/drm/drm_gpuva_mgr.h                  |  759 ++++++
  include/drm/gpu_scheduler.h                  |   29 +-
  include/linux/maple_tree.h                   |    7 +-
  include/uapi/drm/xe_drm.h                    |  128 +-
  lib/maple_tree.c                             |    1 +
  62 files changed, 5543 insertions(+), 2320 deletions(-)

create mode 100644 drivers/gpu/drm/drm_exec.c create mode 100644 drivers/gpu/drm/drm_gpuva_mgr.c create mode 100644 include/drm/drm_exec.h create mode 100644 include/drm/drm_gpuva_mgr.h