Skip to contentSkip to conversation

GPUVA with no uAPI changes

PATCH Superseded Matthew Brost 3 participants 11 messages Jul 8, 2023 – Jul 10, 2023

Subsystems (4)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Matthew Brost

author maintainer
#0 lore raw

v5 cover GPUVA with no uAPI changes

The patches from [1] rebased + address review feedback which do not include uAPI changes.

[1] https://patchwork.freedesktop.org/series/117156/

v2: Fix build error
v3: Fix lockdep splat CI caught
v4: Fix build error
v5: Pull in latest GPUVA versions

Danilo Krummrich (2):
drm: manager to keep track of GPUs VA mappings
drm: debugfs: provide infrastructure to dump a DRM GPU VA space

Matthew Brost (4):
drm/xe: Ban a VM if rebind worker hits an error drm/xe: Add helpers to hide struct xe_vma internals drm/xe: Remove __xe_vm_bind forward declaration drm/xe: Port Xe to GPUVA

 Documentation/gpu/drm-mm.rst                |   36 +
 drivers/gpu/drm/Makefile                    |    1 +
 drivers/gpu/drm/drm_debugfs.c               |   40 +
 drivers/gpu/drm/drm_gem.c                   |    3 +
 drivers/gpu/drm/drm_gpuva_mgr.c             | 1743 ++++++++++++++++
 drivers/gpu/drm/xe/tests/xe_migrate.c       |    2 +-
 drivers/gpu/drm/xe/xe_bo.c                  |    9 +-
 drivers/gpu/drm/xe/xe_device.c              |    2 +-
 drivers/gpu/drm/xe/xe_engine.c              |   13 +
 drivers/gpu/drm/xe/xe_exec.c                |    8 +-
 drivers/gpu/drm/xe/xe_gt_pagefault.c        |   23 +-
 drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c |   14 +-
 drivers/gpu/drm/xe/xe_migrate.c             |   10 +-
 drivers/gpu/drm/xe/xe_pt.c                  |  128 +-
 drivers/gpu/drm/xe/xe_pt.h                  |    2 +-
 drivers/gpu/drm/xe/xe_trace.h               |   15 +-
 drivers/gpu/drm/xe/xe_vm.c                  | 1973 +++++++++----------
 drivers/gpu/drm/xe/xe_vm.h                  |  106 +-
 drivers/gpu/drm/xe/xe_vm_madvise.c          |   90 +-
 drivers/gpu/drm/xe/xe_vm_types.h            |  183 +-
 include/drm/drm_debugfs.h                   |   25 +
 include/drm/drm_drv.h                       |    6 +
 include/drm/drm_gem.h                       |   52 +
 include/drm/drm_gpuva_mgr.h                 |  763 +++++++
 24 files changed, 3993 insertions(+), 1254 deletions(-)
 create mode 100644 drivers/gpu/drm/drm_gpuva_mgr.c
 create mode 100644 include/drm/drm_gpuva_mgr.h
Signature · 1 line
2.34.1
author maintainer
#1 lore raw

PATCH v5 1/6 drm/xe: Ban a VM if rebind worker hits an error

We cannot recover a VM if a rebind worker hits an error, ban the VM if happens to ensure we do not attempt to place this VM on the hardware again.

A follow up will inform the user if this happens.

v2: Return -ECANCELED in exec VM closed or banned, check for closed or banned within VM lock.
v3: Fix lockdep splat by looking engine outside of vm->lock
v4: Fix error path when engine lookup fails
v5: Add debug message in rebind worker on error, update comments wrt locking, add xe_vm_close helper

---
 drivers/gpu/drm/xe/xe_engine.c     |  13 ++++
 drivers/gpu/drm/xe/xe_exec.c       |   6 +-
 drivers/gpu/drm/xe/xe_trace.h      |   5 ++
 drivers/gpu/drm/xe/xe_vm.c         | 104 ++++++++++++++++++-----------
 drivers/gpu/drm/xe/xe_vm.h         |  13 +++-
 drivers/gpu/drm/xe/xe_vm_madvise.c |   2 +-
 drivers/gpu/drm/xe/xe_vm_types.h   |  10 ++-
 7 files changed, 107 insertions(+), 46 deletions(-)
drivers/gpu/drm/xe/xe_engine.c +13 -0
index 530f55a33b03..3831c5f82773 100644
@@ -597,10 +597,23 @@ int xe_engine_create_ioctl(struct drm_device *dev, void *data,
 		if (XE_IOCTL_ERR(xe, !vm))
 			return -ENOENT;
 
+		err = down_read_interruptible(&vm->lock);
+		if (err) {
+			xe_vm_put(vm);
+			return err;
+		}
+
+		if (XE_IOCTL_ERR(xe, xe_vm_is_closed_or_banned(vm))) {
+			up_read(&vm->lock);
+			xe_vm_put(vm);
+			return -ENOENT;
+		}
+
 		e = xe_engine_create(xe, vm, logical_mask,
 				     args->width, hwe,
 				     xe_vm_no_dma_fences(vm) ? 0 :
 				     ENGINE_FLAG_PERSISTENT);
+		up_read(&vm->lock);
 		xe_vm_put(vm);
 		if (IS_ERR(e))
 			return PTR_ERR(e);
drivers/gpu/drm/xe/xe_exec.c +3 -3
index c52edff9a358..bdf00e59e7a4 100644
@@ -297,9 +297,9 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 	if (err)
 		goto err_unlock_list;
 
-	if (xe_vm_is_closed(engine->vm)) {
-		drm_warn(&xe->drm, "Trying to schedule after vm is closed\n");
-		err = -EIO;
+	if (xe_vm_is_closed_or_banned(engine->vm)) {
+		drm_warn(&xe->drm, "Trying to schedule after vm is closed or banned\n");
+		err = -ECANCELED;
 		goto err_engine_end;
 	}
 
drivers/gpu/drm/xe/xe_trace.h +5 -0
index 02861c26e145..ca96a0a4bb80 100644
@@ -477,6 +477,11 @@ DECLARE_EVENT_CLASS(xe_vm,
 			      __entry->asid)
 );
 
+DEFINE_EVENT(xe_vm, xe_vm_kill,
+	     TP_PROTO(struct xe_vm *vm),
+	     TP_ARGS(vm)
+);
+
 DEFINE_EVENT(xe_vm, xe_vm_create,
 	     TP_PROTO(struct xe_vm *vm),
 	     TP_ARGS(vm)
drivers/gpu/drm/xe/xe_vm.c +66 -38

237 lines not on this page · raw message

drivers/gpu/drm/xe/xe_vm.h +12 -1
index 5edb7771629c..02b409dd77d5 100644
@@ -45,10 +45,21 @@ void xe_vm_unlock(struct xe_vm *vm, struct ww_acquire_ctx *ww);
 
 static inline bool xe_vm_is_closed(struct xe_vm *vm)
 {
-	/* Only guaranteed not to change when vm->resv is held */
+	/* Only guaranteed not to change when vm->lock is held */
 	return !vm->size;
 }
 
+static inline bool xe_vm_is_banned(struct xe_vm *vm)
+{
+	return vm->flags & XE_VM_FLAG_BANNED;
+}
+
+static inline bool xe_vm_is_closed_or_banned(struct xe_vm *vm)
+{
+	lockdep_assert_held(&vm->lock);
+	return xe_vm_is_closed(vm) || xe_vm_is_banned(vm);
+}
+
 struct xe_vma *
 xe_vm_find_overlapping_vma(struct xe_vm *vm, const struct xe_vma *vma);
 
drivers/gpu/drm/xe/xe_vm_madvise.c +1 -1
index 0f5eef337037..76458f8d57f3 100644
@@ -313,7 +313,7 @@ int xe_vm_madvise_ioctl(struct drm_device *dev, void *data,
 	if (XE_IOCTL_ERR(xe, !vm))
 		return -EINVAL;
 
-	if (XE_IOCTL_ERR(xe, xe_vm_is_closed(vm))) {
+	if (XE_IOCTL_ERR(xe, xe_vm_is_closed_or_banned(vm))) {
 		err = -ENOENT;
 		goto put_vm;
 	}
drivers/gpu/drm/xe/xe_vm_types.h +7 -3
index c148dd49a6ca..3c885211a8d1 100644
@@ -176,15 +176,19 @@ struct xe_vm {
 	struct xe_bo *scratch_bo[XE_MAX_TILES_PER_DEVICE];
 	struct xe_pt *scratch_pt[XE_MAX_TILES_PER_DEVICE][XE_VM_MAX_LEVEL];
 
-	/** @flags: flags for this VM, statically setup a creation time */
+	/**
+	 * @flags: flags for this VM, statically setup a creation time aside
+	 * from XE_VM_FLAG_BANNED which requires vm->lock to set / read safely
+	 */
 #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_MIGRATION		BIT(3)
 #define XE_VM_FLAG_SCRATCH_PAGE		BIT(4)
 #define XE_VM_FLAG_FAULT_MODE		BIT(5)
-#define XE_VM_FLAG_GT_ID(flags)		(((flags) >> 6) & 0x3)
-#define XE_VM_FLAG_SET_TILE_ID(tile)	((tile)->id << 6)
+#define XE_VM_FLAG_BANNED		BIT(6)
+#define XE_VM_FLAG_GT_ID(flags)		(((flags) >> 7) & 0x3)
+#define XE_VM_FLAG_SET_TILE_ID(tile)	((tile)->id << 7)
 	unsigned long flags;
 
 	/** @composite_fence_ctx: context composite fence */
Signature · 1 line
2.34.1
maintainer Reviewed-by on v5 1/6
#2 lore raw

Re: [Intel-xe] [PATCH v5 1/6] drm/xe: Ban a VM if rebind worker hits an error

Quoted 6 lines · Matthew Brost

We cannot recover a VM if a rebind worker hits an error, ban the VM if happens to ensure we do not attempt to place this VM on the hardware again.

A follow up will inform the user if this happens.

Quoted 8 lines

v2: Return -ECANCELED in exec VM closed or banned, check for closed or banned within VM lock.
v3: Fix lockdep splat by looking engine outside of vm->lock
v4: Fix error path when engine lookup fails
v5: Add debug message in rebind worker on error, update comments wrt locking, add xe_vm_close helper

Quoted 395 lines
---
  drivers/gpu/drm/xe/xe_engine.c     |  13 ++++
  drivers/gpu/drm/xe/xe_exec.c       |   6 +-
  drivers/gpu/drm/xe/xe_trace.h      |   5 ++
  drivers/gpu/drm/xe/xe_vm.c         | 104 ++++++++++++++++++-----------
  drivers/gpu/drm/xe/xe_vm.h         |  13 +++-
  drivers/gpu/drm/xe/xe_vm_madvise.c |   2 +-
  drivers/gpu/drm/xe/xe_vm_types.h   |  10 ++-
  7 files changed, 107 insertions(+), 46 deletions(-)
drivers/gpu/drm/xe/xe_engine.c +13 -0
index 530f55a33b03..3831c5f82773 100644
@@ -597,10 +597,23 @@ int xe_engine_create_ioctl(struct drm_device *dev, void *data,
  		if (XE_IOCTL_ERR(xe, !vm))
  			return -ENOENT;
 
+		err = down_read_interruptible(&vm->lock);
+		if (err) {
+			xe_vm_put(vm);
+			return err;
+		}
+
+		if (XE_IOCTL_ERR(xe, xe_vm_is_closed_or_banned(vm))) {
+			up_read(&vm->lock);
+			xe_vm_put(vm);
+			return -ENOENT;
+		}
+
  		e = xe_engine_create(xe, vm, logical_mask,
  				     args->width, hwe,
  				     xe_vm_no_dma_fences(vm) ? 0 :
  				     ENGINE_FLAG_PERSISTENT);
+		up_read(&vm->lock);
  		xe_vm_put(vm);
  		if (IS_ERR(e))
  			return PTR_ERR(e);
drivers/gpu/drm/xe/xe_exec.c +3 -3
index c52edff9a358..bdf00e59e7a4 100644
@@ -297,9 +297,9 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
  	if (err)
  		goto err_unlock_list;
 
-	if (xe_vm_is_closed(engine->vm)) {
-		drm_warn(&xe->drm, "Trying to schedule after vm is closed\n");
-		err = -EIO;
+	if (xe_vm_is_closed_or_banned(engine->vm)) {
+		drm_warn(&xe->drm, "Trying to schedule after vm is closed or banned\n");
+		err = -ECANCELED;
  		goto err_engine_end;
  	}
 
drivers/gpu/drm/xe/xe_trace.h +5 -0
index 02861c26e145..ca96a0a4bb80 100644
@@ -477,6 +477,11 @@ DECLARE_EVENT_CLASS(xe_vm,
  			      __entry->asid)
  );
 
+DEFINE_EVENT(xe_vm, xe_vm_kill,
+	     TP_PROTO(struct xe_vm *vm),
+	     TP_ARGS(vm)
+);
+
  DEFINE_EVENT(xe_vm, xe_vm_create,
  	     TP_PROTO(struct xe_vm *vm),
  	     TP_ARGS(vm)
drivers/gpu/drm/xe/xe_vm.c +66 -38
index dbff75a9087b..2e7547d13220 100644
@@ -514,6 +514,24 @@ void xe_vm_unlock_dma_resv(struct xe_vm *vm,
 
  #define XE_VM_REBIND_RETRY_TIMEOUT_MS 1000
 
+static void xe_vm_kill(struct xe_vm *vm)
+{
+	struct ww_acquire_ctx ww;
+	struct xe_engine *e;
+
+	lockdep_assert_held(&vm->lock);
+
+	xe_vm_lock(vm, &ww, 0, false);
+	vm->flags |= XE_VM_FLAG_BANNED;
+	trace_xe_vm_kill(vm);
+
+	list_for_each_entry(e, &vm->preempt.engines, compute.link)
+		e->ops->kill(e);
+	xe_vm_unlock(vm, &ww);
+
+	/* TODO: Inform user the VM is banned */
+}
+
  static void preempt_rebind_work_func(struct work_struct *w)
  {
  	struct xe_vm *vm = container_of(w, struct xe_vm, preempt.rebind_work);
@@ -533,13 +551,14 @@ static void preempt_rebind_work_func(struct work_struct *w)
  	XE_BUG_ON(!xe_vm_in_compute_mode(vm));
  	trace_xe_vm_rebind_worker_enter(vm);
 
-	if (xe_vm_is_closed(vm)) {
+	down_write(&vm->lock);
+
+	if (xe_vm_is_closed_or_banned(vm)) {
+		up_write(&vm->lock);
  		trace_xe_vm_rebind_worker_exit(vm);
  		return;
  	}
 
-	down_write(&vm->lock);
-
  retry:
  	if (vm->async_ops.error)
  		goto out_unlock_outer;
@@ -666,11 +685,14 @@ static void preempt_rebind_work_func(struct work_struct *w)
  			goto retry;
  		}
  	}
+	if (err) {
+		drm_warn(&vm->xe->drm, "VM worker error: %d\n", err);
+		xe_vm_kill(vm);
+	}
  	up_write(&vm->lock);
 
  	free_preempt_fences(&preempt_fences);
 
-	XE_WARN_ON(err < 0);	/* TODO: Kill VM or put in error state */
  	trace_xe_vm_rebind_worker_exit(vm);
  }
 
@@ -1140,11 +1162,12 @@ xe_vm_find_overlapping_vma(struct xe_vm *vm, const struct xe_vma *vma)
  {
  	struct rb_node *node;
 
-	if (xe_vm_is_closed(vm))
+	lockdep_assert_held(&vm->lock);
+
+	if (xe_vm_is_closed_or_banned(vm))
  		return NULL;
 
  	XE_BUG_ON(vma->end >= vm->size);
-	lockdep_assert_held(&vm->lock);
 
  	node = rb_find(vma, &vm->vmas, xe_vma_cmp_vma_cb);
 
@@ -1377,6 +1400,13 @@ static void vm_error_capture(struct xe_vm *vm, int err,
  	wake_up_all(&vm->async_ops.error_capture.wq);
  }
 
+static void xe_vm_close(struct xe_vm *vm)
+{
+	down_write(&vm->lock);
+	vm->size = 0;
+	up_write(&vm->lock);
+}
+
  void xe_vm_close_and_put(struct xe_vm *vm)
  {
  	struct rb_root contested = RB_ROOT;
@@ -1387,8 +1417,8 @@ void xe_vm_close_and_put(struct xe_vm *vm)
 
  	XE_BUG_ON(vm->preempt.num_engines);
 
-	vm->size = 0;
-	smp_mb();
+	xe_vm_close(vm);
+
  	flush_async_ops(vm);
  	if (xe_vm_in_compute_mode(vm))
  		flush_work(&vm->preempt.rebind_work);
@@ -3072,30 +3102,34 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
  	if (err)
  		return err;
 
-	vm = xe_vm_lookup(xef, args->vm_id);
-	if (XE_IOCTL_ERR(xe, !vm)) {
-		err = -EINVAL;
-		goto free_objs;
-	}
-
-	if (XE_IOCTL_ERR(xe, xe_vm_is_closed(vm))) {
-		drm_err(dev, "VM closed while we began looking up?\n");
-		err = -ENOENT;
-		goto put_vm;
-	}
-
  	if (args->engine_id) {
  		e = xe_engine_lookup(xef, args->engine_id);
  		if (XE_IOCTL_ERR(xe, !e)) {
  			err = -ENOENT;
-			goto put_vm;
+			goto free_objs;
  		}
+
  		if (XE_IOCTL_ERR(xe, !(e->flags & ENGINE_FLAG_VM))) {
  			err = -EINVAL;
  			goto put_engine;
  		}
  	}
 
+	vm = xe_vm_lookup(xef, args->vm_id);
+	if (XE_IOCTL_ERR(xe, !vm)) {
+		err = -EINVAL;
+		goto put_engine;
+	}
+
+	err = down_write_killable(&vm->lock);
+	if (err)
+		goto put_vm;
+
+	if (XE_IOCTL_ERR(xe, xe_vm_is_closed_or_banned(vm))) {
+		err = -ENOENT;
+		goto release_vm_lock;
+	}
+
  	if (VM_BIND_OP(bind_ops[0].op) == XE_VM_BIND_OP_RESTART) {
  		if (XE_IOCTL_ERR(xe, !(vm->flags & XE_VM_FLAG_ASYNC_BIND_OPS)))
  			err = -EOPNOTSUPP;
@@ -3105,10 +3139,8 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
  			err = -EPROTO;
 
  		if (!err) {
-			down_write(&vm->lock);
  			trace_xe_vm_restart(vm);
  			vm_set_async_error(vm, 0);
-			up_write(&vm->lock);
 
  			queue_work(system_unbound_wq, &vm->async_ops.work);
 
@@ -3117,13 +3149,13 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
  				xe_vm_queue_rebind_worker(vm);
  		}
 
-		goto put_engine;
+		goto release_vm_lock;
  	}
 
  	if (XE_IOCTL_ERR(xe, !vm->async_ops.error &&
  			 async != !!(vm->flags & XE_VM_FLAG_ASYNC_BIND_OPS))) {
  		err = -EOPNOTSUPP;
-		goto put_engine;
+		goto release_vm_lock;
  	}
 
  	for (i = 0; i < args->num_binds; ++i) {
@@ -3133,7 +3165,7 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
  		if (XE_IOCTL_ERR(xe, range > vm->size) ||
  		    XE_IOCTL_ERR(xe, addr > vm->size - range)) {
  			err = -EINVAL;
-			goto put_engine;
+			goto release_vm_lock;
  		}
 
  		if (bind_ops[i].tile_mask) {
@@ -3142,7 +3174,7 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
  			if (XE_IOCTL_ERR(xe, bind_ops[i].tile_mask &
  					 ~valid_tiles)) {
  				err = -EINVAL;
-				goto put_engine;
+				goto release_vm_lock;
  			}
  		}
  	}
@@ -3150,13 +3182,13 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
  	bos = kzalloc(sizeof(*bos) * args->num_binds, GFP_KERNEL);
  	if (!bos) {
  		err = -ENOMEM;
-		goto put_engine;
+		goto release_vm_lock;
  	}
 
  	vmas = kzalloc(sizeof(*vmas) * args->num_binds, GFP_KERNEL);
  	if (!vmas) {
  		err = -ENOMEM;
-		goto put_engine;
+		goto release_vm_lock;
  	}
 
  	for (i = 0; i < args->num_binds; ++i) {
@@ -3211,10 +3243,6 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
  			goto free_syncs;
  	}
 
-	err = down_write_killable(&vm->lock);
-	if (err)
-		goto free_syncs;
-
  	/* Do some error checking first to make the unwind easier */
  	for (i = 0; i < args->num_binds; ++i) {
  		u64 range = bind_ops[i].range;
@@ -3223,7 +3251,7 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 
  		err = __vm_bind_ioctl_lookup_vma(vm, bos[i], addr, range, op);
  		if (err)
-			goto release_vm_lock;
+			goto free_syncs;
  	}
 
  	for (i = 0; i < args->num_binds; ++i) {
@@ -3343,8 +3371,6 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
  			break;
  		}
  	}
-release_vm_lock:
-	up_write(&vm->lock);
  free_syncs:
  	while (num_syncs--) {
  		if (async && j &&
@@ -3357,11 +3383,13 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
  put_obj:
  	for (i = j; i < args->num_binds; ++i)
  		xe_bo_put(bos[i]);
+release_vm_lock:
+	up_write(&vm->lock);
+put_vm:
+	xe_vm_put(vm);
  put_engine:
  	if (e)
  		xe_engine_put(e);
-put_vm:
-	xe_vm_put(vm);
  free_objs:
  	kfree(bos);
  	kfree(vmas);
drivers/gpu/drm/xe/xe_vm.h +12 -1
index 5edb7771629c..02b409dd77d5 100644
@@ -45,10 +45,21 @@ void xe_vm_unlock(struct xe_vm *vm, struct ww_acquire_ctx *ww);
 
  static inline bool xe_vm_is_closed(struct xe_vm *vm)
  {
-	/* Only guaranteed not to change when vm->resv is held */
+	/* Only guaranteed not to change when vm->lock is held */
  	return !vm->size;
  }
 
+static inline bool xe_vm_is_banned(struct xe_vm *vm)
+{
+	return vm->flags & XE_VM_FLAG_BANNED;
+}
+
+static inline bool xe_vm_is_closed_or_banned(struct xe_vm *vm)
+{
+	lockdep_assert_held(&vm->lock);
+	return xe_vm_is_closed(vm) || xe_vm_is_banned(vm);
+}
+
  struct xe_vma *
  xe_vm_find_overlapping_vma(struct xe_vm *vm, const struct xe_vma *vma);
 
drivers/gpu/drm/xe/xe_vm_madvise.c +1 -1
index 0f5eef337037..76458f8d57f3 100644
@@ -313,7 +313,7 @@ int xe_vm_madvise_ioctl(struct drm_device *dev, void *data,
  	if (XE_IOCTL_ERR(xe, !vm))
  		return -EINVAL;
 
-	if (XE_IOCTL_ERR(xe, xe_vm_is_closed(vm))) {
+	if (XE_IOCTL_ERR(xe, xe_vm_is_closed_or_banned(vm))) {
  		err = -ENOENT;
  		goto put_vm;
  	}
drivers/gpu/drm/xe/xe_vm_types.h +7 -3
index c148dd49a6ca..3c885211a8d1 100644
@@ -176,15 +176,19 @@ struct xe_vm {
  	struct xe_bo *scratch_bo[XE_MAX_TILES_PER_DEVICE];
  	struct xe_pt *scratch_pt[XE_MAX_TILES_PER_DEVICE][XE_VM_MAX_LEVEL];
 
-	/** @flags: flags for this VM, statically setup a creation time */
+	/**
+	 * @flags: flags for this VM, statically setup a creation time aside
+	 * from XE_VM_FLAG_BANNED which requires vm->lock to set / read safely
+	 */
  #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_MIGRATION		BIT(3)
  #define XE_VM_FLAG_SCRATCH_PAGE		BIT(4)
  #define XE_VM_FLAG_FAULT_MODE		BIT(5)
-#define XE_VM_FLAG_GT_ID(flags)		(((flags) >> 6) & 0x3)
-#define XE_VM_FLAG_SET_TILE_ID(tile)	((tile)->id << 6)
+#define XE_VM_FLAG_BANNED		BIT(6)
+#define XE_VM_FLAG_GT_ID(flags)		(((flags) >> 7) & 0x3)
+#define XE_VM_FLAG_SET_TILE_ID(tile)	((tile)->id << 7)
  	unsigned long flags;
 
  	/** @composite_fence_ctx: context composite fence */
author maintainer
#3 lore raw

PATCH v5 2/6 drm/xe: Add helpers to hide struct xe_vma internals

In reply to Matthew Brost

This will help with the GPUVA port as the internals of struct xe_vma will change.

v2: Update comment around helpers

---
 drivers/gpu/drm/xe/xe_bo.c                  |   4 +-
 drivers/gpu/drm/xe/xe_exec.c                |   2 +-
 drivers/gpu/drm/xe/xe_gt_pagefault.c        |   7 +-
 drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c |  14 +-
 drivers/gpu/drm/xe/xe_pt.c                  |  88 +++++------
 drivers/gpu/drm/xe/xe_trace.h               |  10 +-
 drivers/gpu/drm/xe/xe_vm.c                  | 163 ++++++++++----------
 drivers/gpu/drm/xe/xe_vm.h                  |  76 +++++++--
 drivers/gpu/drm/xe/xe_vm_madvise.c          |  12 +-
 9 files changed, 211 insertions(+), 165 deletions(-)
drivers/gpu/drm/xe/xe_bo.c +2 -2
index e240df6c7ae6..5f0232555431 100644
@@ -426,7 +426,7 @@ static int xe_bo_trigger_rebind(struct xe_device *xe, struct xe_bo *bo,
 	}
 
 	list_for_each_entry(vma, &bo->vmas, bo_link) {
-		struct xe_vm *vm = vma->vm;
+		struct xe_vm *vm = xe_vma_vm(vma);
 
 		trace_xe_vma_evict(vma);
 
@@ -454,7 +454,7 @@ static int xe_bo_trigger_rebind(struct xe_device *xe, struct xe_bo *bo,
 
 		} else {
 			bool vm_resv_locked = false;
-			struct xe_vm *vm = vma->vm;
+			struct xe_vm *vm = xe_vma_vm(vma);
 
 			/*
 			 * We need to put the vma on the vm's rebind_list,
drivers/gpu/drm/xe/xe_exec.c +1 -1
index bdf00e59e7a4..ba13d20ed348 100644
@@ -126,7 +126,7 @@ static int xe_exec_begin(struct xe_engine *e, struct ww_acquire_ctx *ww,
 		if (xe_vma_is_userptr(vma))
 			continue;
 
-		err = xe_bo_validate(vma->bo, vm, false);
+		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;
drivers/gpu/drm/xe/xe_gt_pagefault.c +4 -3
index 6faebd02f3fb..0e91ab67d617 100644
@@ -77,7 +77,8 @@ static bool vma_is_valid(struct xe_gt *gt, struct xe_vma *vma)
 
 static bool vma_matches(struct xe_vma *vma, struct xe_vma *lookup)
 {
-	if (lookup->start > vma->end || lookup->end < vma->start)
+	if (xe_vma_start(lookup) > xe_vma_end(vma) - 1 ||
+	    xe_vma_end(lookup) - 1 < xe_vma_start(vma))
 		return false;
 
 	return true;
@@ -171,7 +172,7 @@ static int handle_pagefault(struct xe_gt *gt, struct pagefault *pf)
 	}
 
 	/* Lock VM and BOs dma-resv */
-	bo = vma->bo;
+	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);
@@ -538,7 +539,7 @@ static int handle_acc(struct xe_gt *gt, struct acc *acc)
 		goto unlock_vm;
 
 	/* Lock VM and BOs dma-resv */
-	bo = vma->bo;
+	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);
drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c +7 -7
index 2fcb477604e2..f77368a16409 100644
@@ -203,8 +203,8 @@ int xe_gt_tlb_invalidation_vma(struct xe_gt *gt,
 	if (!xe->info.has_range_tlb_invalidation) {
 		action[len++] = MAKE_INVAL_OP(XE_GUC_TLB_INVAL_FULL);
 	} else {
-		u64 start = vma->start;
-		u64 length = vma->end - vma->start + 1;
+		u64 start = xe_vma_start(vma);
+		u64 length = xe_vma_size(vma);
 		u64 align, end;
 
 		if (length < SZ_4K)
@@ -217,12 +217,12 @@ int xe_gt_tlb_invalidation_vma(struct xe_gt *gt,
 		 * address mask covering the required range.
 		 */
 		align = roundup_pow_of_two(length);
-		start = ALIGN_DOWN(vma->start, align);
-		end = ALIGN(vma->start + length, align);
+		start = ALIGN_DOWN(xe_vma_start(vma), align);
+		end = ALIGN(xe_vma_end(vma), align);
 		length = align;
 		while (start + length < end) {
 			length <<= 1;
-			start = ALIGN_DOWN(vma->start, length);
+			start = ALIGN_DOWN(xe_vma_start(vma), length);
 		}
 
 		/*
@@ -231,7 +231,7 @@ int xe_gt_tlb_invalidation_vma(struct xe_gt *gt,
 		 */
 		if (length >= SZ_2M) {
 			length = max_t(u64, SZ_16M, length);
-			start = ALIGN_DOWN(vma->start, length);
+			start = ALIGN_DOWN(xe_vma_start(vma), length);
 		}
 
 		XE_BUG_ON(length < SZ_4K);
@@ -240,7 +240,7 @@ int xe_gt_tlb_invalidation_vma(struct xe_gt *gt,
 		XE_BUG_ON(!IS_ALIGNED(start, length));
 
 		action[len++] = MAKE_INVAL_OP(XE_GUC_TLB_INVAL_PAGE_SELECTIVE);
-		action[len++] = vma->vm->usm.asid;
+		action[len++] = xe_vma_vm(vma)->usm.asid;
 		action[len++] = lower_32_bits(start);
 		action[len++] = upper_32_bits(start);
 		action[len++] = ilog2(length) - ilog2(SZ_4K);
drivers/gpu/drm/xe/xe_pt.c +44 -44

236 lines not on this page · raw message

drivers/gpu/drm/xe/xe_trace.h +5 -5
index ca96a0a4bb80..b3828e2f0aab 100644
@@ -18,7 +18,7 @@
 #include "xe_gt_types.h"
 #include "xe_guc_engine_types.h"
 #include "xe_sched_job.h"
-#include "xe_vm_types.h"
+#include "xe_vm.h"
 
 DECLARE_EVENT_CLASS(xe_gt_tlb_invalidation_fence,
 		    TP_PROTO(struct xe_gt_tlb_invalidation_fence *fence),
@@ -373,10 +373,10 @@ DECLARE_EVENT_CLASS(xe_vma,
 
 		    TP_fast_assign(
 			   __entry->vma = (unsigned long)vma;
-			   __entry->asid = vma->vm->usm.asid;
-			   __entry->start = vma->start;
-			   __entry->end = vma->end;
-			   __entry->ptr = (u64)vma->userptr.ptr;
+			   __entry->asid = xe_vma_vm(vma)->usm.asid;
+			   __entry->start = xe_vma_start(vma);
+			   __entry->end = xe_vma_end(vma) - 1;
+			   __entry->ptr = xe_vma_userptr(vma);
 			   ),
 
 		    TP_printk("vma=0x%016llx, asid=0x%05x, start=0x%012llx, end=0x%012llx, ptr=0x%012llx,",
drivers/gpu/drm/xe/xe_vm.c +82 -81

463 lines not on this page · raw message

drivers/gpu/drm/xe/xe_vm.h +60 -16

88 lines not on this page · raw message

drivers/gpu/drm/xe/xe_vm_madvise.c +6 -6
index 76458f8d57f3..f29a67cb941f 100644
@@ -30,7 +30,7 @@ static int madvise_preferred_mem_class(struct xe_device *xe, struct xe_vm *vm,
 		struct xe_bo *bo;
 		struct ww_acquire_ctx ww;
 
-		bo = vmas[i]->bo;
+		bo = xe_vma_bo(vmas[i]);
 
 		err = xe_bo_lock(bo, &ww, 0, true);
 		if (err)
@@ -55,7 +55,7 @@ static int madvise_preferred_gt(struct xe_device *xe, struct xe_vm *vm,
 		struct xe_bo *bo;
 		struct ww_acquire_ctx ww;
 
-		bo = vmas[i]->bo;
+		bo = xe_vma_bo(vmas[i]);
 
 		err = xe_bo_lock(bo, &ww, 0, true);
 		if (err)
@@ -91,7 +91,7 @@ static int madvise_preferred_mem_class_gt(struct xe_device *xe,
 		struct xe_bo *bo;
 		struct ww_acquire_ctx ww;
 
-		bo = vmas[i]->bo;
+		bo = xe_vma_bo(vmas[i]);
 
 		err = xe_bo_lock(bo, &ww, 0, true);
 		if (err)
@@ -114,7 +114,7 @@ static int madvise_cpu_atomic(struct xe_device *xe, struct xe_vm *vm,
 		struct xe_bo *bo;
 		struct ww_acquire_ctx ww;
 
-		bo = vmas[i]->bo;
+		bo = xe_vma_bo(vmas[i]);
 		if (XE_IOCTL_ERR(xe, !(bo->flags & XE_BO_CREATE_SYSTEM_BIT)))
 			return -EINVAL;
 
@@ -145,7 +145,7 @@ static int madvise_device_atomic(struct xe_device *xe, struct xe_vm *vm,
 		struct xe_bo *bo;
 		struct ww_acquire_ctx ww;
 
-		bo = vmas[i]->bo;
+		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;
@@ -176,7 +176,7 @@ static int madvise_priority(struct xe_device *xe, struct xe_vm *vm,
 		struct xe_bo *bo;
 		struct ww_acquire_ctx ww;
 
-		bo = vmas[i]->bo;
+		bo = xe_vma_bo(vmas[i]);
 
 		err = xe_bo_lock(bo, &ww, 0, true);
 		if (err)
Signature · 1 line
2.34.1
author maintainer
#4 lore raw

PATCH v5 3/6 drm: manager to keep track of GPUs VA mappings

In reply to Matthew Brost

From: Danilo Krummrich <[email protected]>

Add infrastructure to keep track of GPU virtual address (VA) mappings with a decicated VA space manager implementation.

New UAPIs, motivated by Vulkan sparse memory bindings graphics drivers start implementing, allow userspace applications to request multiple and arbitrary GPU VA mappings of buffer objects. The DRM GPU VA manager is intended to serve the following purposes in this context.

1) Provide infrastructure to track GPU VA allocations and mappings, making use of the maple_tree.

2) Generically connect GPU VA mappings to their backing buffers, in particular DRM GEM objects.

3) Provide a common implementation to perform more complex mapping operations on the GPU VA space. In particular splitting and merging of GPU VA mappings, e.g. for intersecting mapping requests or partial unmap requests.

---
 Documentation/gpu/drm-mm.rst    |   36 +
 drivers/gpu/drm/Makefile        |    1 +
 drivers/gpu/drm/drm_gem.c       |    3 +
 drivers/gpu/drm/drm_gpuva_mgr.c | 1743 +++++++++++++++++++++++++++++++
 include/drm/drm_drv.h           |    6 +
 include/drm/drm_gem.h           |   52 +
 include/drm/drm_gpuva_mgr.h     |  763 ++++++++++++++
 7 files changed, 2604 insertions(+)
 create mode 100644 drivers/gpu/drm/drm_gpuva_mgr.c
 create mode 100644 include/drm/drm_gpuva_mgr.h
Documentation/gpu/drm-mm.rst +36 -0
index a79fd3549ff8..b21df6ce9fcb 100644
@@ -466,6 +466,42 @@ DRM MM Range Allocator Function References
 .. kernel-doc:: drivers/gpu/drm/drm_mm.c
    :export:
 
+DRM GPU VA Manager
+==================
+
+Overview
+--------
+
+.. kernel-doc:: drivers/gpu/drm/drm_gpuva_mgr.c
+   :doc: Overview
+
+Split and Merge
+---------------
+
+.. kernel-doc:: drivers/gpu/drm/drm_gpuva_mgr.c
+   :doc: Split and Merge
+
+Locking
+-------
+
+.. kernel-doc:: drivers/gpu/drm/drm_gpuva_mgr.c
+   :doc: Locking
+
+Examples
+--------
+
+.. kernel-doc:: drivers/gpu/drm/drm_gpuva_mgr.c
+   :doc: Examples
+
+DRM GPU VA Manager Function References
+--------------------------------------
+
+.. kernel-doc:: include/drm/drm_gpuva_mgr.h
+   :internal:
+
+.. kernel-doc:: drivers/gpu/drm/drm_gpuva_mgr.c
+   :export:
+
 DRM Buddy Allocator
 ===================
 
drivers/gpu/drm/Makefile +1 -0
index ebd8ee1963c4..90ee955ef4d1 100644
@@ -45,6 +45,7 @@ drm-y := \
 	drm_vblank.o \
 	drm_vblank_work.o \
 	drm_vma_manager.o \
+	drm_gpuva_mgr.o \
 	drm_writeback.o
 drm-$(CONFIG_DRM_LEGACY) += \
 	drm_agpsupport.o \
drivers/gpu/drm/drm_gem.c +3 -0
index 1a5a2cd0d4ec..cd878ebddbd0 100644
@@ -164,6 +164,9 @@ void drm_gem_private_object_init(struct drm_device *dev,
 	if (!obj->resv)
 		obj->resv = &obj->_resv;
 
+	if (drm_core_check_feature(dev, DRIVER_GEM_GPUVA))
+		drm_gem_gpuva_init(obj);
+
 	drm_vma_node_reset(&obj->vma_node);
 	INIT_LIST_HEAD(&obj->lru_node);
 }
drivers/gpu/drm/drm_gpuva_mgr.c new file +1743 -0

1,743 lines not on this page · raw message

include/drm/drm_drv.h +6 -0
index b77f2c7275b7..9813fa759b75 100644
@@ -104,6 +104,12 @@ enum drm_driver_feature {
 	 * acceleration should be handled by two drivers that are connected using auxiliary bus.
 	 */
 	DRIVER_COMPUTE_ACCEL            = BIT(7),
+	/**
+	 * @DRIVER_GEM_GPUVA:
+	 *
+	 * Driver supports user defined GPU VA bindings for GEM objects.
+	 */
+	DRIVER_GEM_GPUVA		= BIT(8),
 
 	/* IMPORTANT: Below are all the legacy flags, add new ones above. */
 
include/drm/drm_gem.h +52 -0

68 lines not on this page · raw message

include/drm/drm_gpuva_mgr.h new file +763 -0

763 lines not on this page · raw message

Signature · 1 line
2.34.1
author maintainer
#5 lore raw

PATCH v5 4/6 drm: debugfs: provide infrastructure to dump a DRM GPU VA space

In reply to Matthew Brost

From: Danilo Krummrich <[email protected]>

This commit adds a function to dump a DRM GPU VA space and a macro for drivers to register the struct drm_info_list 'gpuvas' entry.

Most likely, most drivers might maintain one DRM GPU VA space per struct drm_file, but there might also be drivers not having a fixed relation between DRM GPU VA spaces and a DRM core infrastructure, hence we need the indirection via the driver iterating it's maintained DRM GPU VA spaces.

---
 drivers/gpu/drm/drm_debugfs.c | 40 +++++++++++++++++++++++++++++++++++
 include/drm/drm_debugfs.h     | 25 ++++++++++++++++++++++
 2 files changed, 65 insertions(+)
drivers/gpu/drm/drm_debugfs.c +40 -0
index 4855230ba2c6..c90dbcffa0dc 100644
@@ -39,6 +39,7 @@
 #include <drm/drm_file.h>
 #include <drm/drm_gem.h>
 #include <drm/drm_managed.h>
+#include <drm/drm_gpuva_mgr.h>
 
 #include "drm_crtc_internal.h"
 #include "drm_internal.h"
@@ -175,6 +176,45 @@ static const struct file_operations drm_debugfs_fops = {
 	.release = single_release,
 };
 
+/**
+ * drm_debugfs_gpuva_info - dump the given DRM GPU VA space
+ * @m: pointer to the &seq_file to write
+ * @mgr: the &drm_gpuva_manager representing the GPU VA space
+ *
+ * Dumps the GPU VA mappings of a given DRM GPU VA manager.
+ *
+ * For each DRM GPU VA space drivers should call this function from their
+ * &drm_info_list's show callback.
+ *
+ * Returns: 0 on success, -ENODEV if the &mgr is not initialized
+ */
+int drm_debugfs_gpuva_info(struct seq_file *m,
+			   struct drm_gpuva_manager *mgr)
+{
+	struct drm_gpuva *va, *kva = &mgr->kernel_alloc_node;
+
+	if (!mgr->name)
+		return -ENODEV;
+
+	seq_printf(m, "DRM GPU VA space (%s) [0x%016llx;0x%016llx]\n",
+		   mgr->name, mgr->mm_start, mgr->mm_start + mgr->mm_range);
+	seq_printf(m, "Kernel reserved node [0x%016llx;0x%016llx]\n",
+		   kva->va.addr, kva->va.addr + kva->va.range);
+	seq_puts(m, "\n");
+	seq_puts(m, " VAs | start              | range              | end                | object             | object offset\n");
+	seq_puts(m, "-------------------------------------------------------------------------------------------------------------\n");
+	drm_gpuva_for_each_va(va, mgr) {
+		if (unlikely(va == kva))
+			continue;
+
+		seq_printf(m, "     | 0x%016llx | 0x%016llx | 0x%016llx | 0x%016llx | 0x%016llx\n",
+			   va->va.addr, va->va.range, va->va.addr + va->va.range,
+			   (u64)va->gem.obj, va->gem.offset);
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL(drm_debugfs_gpuva_info);
 
 /**
  * drm_debugfs_create_files - Initialize a given set of debugfs files for DRM
include/drm/drm_debugfs.h +25 -0
index 7616f457ce70..cb2c1956a214 100644
@@ -34,6 +34,22 @@
 
 #include <linux/types.h>
 #include <linux/seq_file.h>
+
+#include <drm/drm_gpuva_mgr.h>
+
+/**
+ * DRM_DEBUGFS_GPUVA_INFO - &drm_info_list entry to dump a GPU VA space
+ * @show: the &drm_info_list's show callback
+ * @data: driver private data
+ *
+ * Drivers should use this macro to define a &drm_info_list entry to provide a
+ * debugfs file for dumping the GPU VA space regions and mappings.
+ *
+ * For each DRM GPU VA space drivers should call drm_debugfs_gpuva_info() from
+ * their @show callback.
+ */
+#define DRM_DEBUGFS_GPUVA_INFO(show, data) {"gpuvas", show, DRIVER_GEM_GPUVA, data}
+
 /**
  * struct drm_info_list - debugfs info list entry
  *
@@ -134,6 +150,9 @@ void drm_debugfs_add_file(struct drm_device *dev, const char *name,
 
 void drm_debugfs_add_files(struct drm_device *dev,
 			   const struct drm_debugfs_info *files, int count);
+
+int drm_debugfs_gpuva_info(struct seq_file *m,
+			   struct drm_gpuva_manager *mgr);
 #else
 static inline void drm_debugfs_create_files(const struct drm_info_list *files,
 					    int count, struct dentry *root,
@@ -155,6 +174,12 @@ static inline void drm_debugfs_add_files(struct drm_device *dev,
 					 const struct drm_debugfs_info *files,
 					 int count)
 {}
+
+static inline int drm_debugfs_gpuva_info(struct seq_file *m,
+					 struct drm_gpuva_manager *mgr)
+{
+	return 0;
+}
 #endif
 
 #endif /* _DRM_DEBUGFS_H_ */
Signature · 1 line
2.34.1
author maintainer
#6 lore raw

PATCH v5 5/6 drm/xe: Remove __xe_vm_bind forward declaration

In reply to Matthew Brost

Not needed so remove it.

---
 drivers/gpu/drm/xe/xe_vm.c | 5 -----
 1 file changed, 5 deletions(-)
drivers/gpu/drm/xe/xe_vm.c +0 -5
index ccc4c870260c..23619ea873ac 100644
@@ -696,11 +696,6 @@ static void preempt_rebind_work_func(struct work_struct *w)
 	trace_xe_vm_rebind_worker_exit(vm);
 }
 
-struct async_op_fence;
-static int __xe_vm_bind(struct xe_vm *vm, struct xe_vma *vma,
-			struct xe_engine *e, struct xe_sync_entry *syncs,
-			u32 num_syncs, struct async_op_fence *afence);
-
 static bool vma_userptr_invalidate(struct mmu_interval_notifier *mni,
 				   const struct mmu_notifier_range *range,
 				   unsigned long cur_seq)
Signature · 1 line
2.34.1
author maintainer
#7 lore raw

PATCH v5 6/6 drm/xe: Port Xe to GPUVA

In reply to Matthew Brost

Rather than open coding VM binds and VMA tracking, use the GPUVA library. GPUVA provides a common infrastructure for VM binds to use mmap / munmap semantics and support for VK sparse bindings.

The concepts are:

1) xe_vm inherits from drm_gpuva_manager
2) xe_vma inherits from drm_gpuva
3) xe_vma_op inherits from drm_gpuva_op
4) VM bind operations (MAP, UNMAP, PREFETCH, UNMAP_ALL) call into the GPUVA code to generate an VMA operations list which is parsed, committed, and executed.

v2 (CI): Add break after default in case statement.
v3: Rebase
v4: Fix some error handling
v5: Use unlocked version VMA in error paths
v6: Rebase, address some review feedback mainly Thomas H
v7: Fix compile error in xe_vma_op_unwind, address checkpatch

---
 drivers/gpu/drm/xe/tests/xe_migrate.c |    2 +-
 drivers/gpu/drm/xe/xe_bo.c            |    7 +-
 drivers/gpu/drm/xe/xe_device.c        |    2 +-
 drivers/gpu/drm/xe/xe_gt_pagefault.c  |   20 +-
 drivers/gpu/drm/xe/xe_migrate.c       |   10 +-
 drivers/gpu/drm/xe/xe_pt.c            |   40 +-
 drivers/gpu/drm/xe/xe_pt.h            |    2 +-
 drivers/gpu/drm/xe/xe_vm.c            | 1787 ++++++++++++-------------
 drivers/gpu/drm/xe/xe_vm.h            |   35 +-
 drivers/gpu/drm/xe/xe_vm_madvise.c    |   76 +-
 drivers/gpu/drm/xe/xe_vm_types.h      |  173 ++-
 11 files changed, 1061 insertions(+), 1093 deletions(-)
drivers/gpu/drm/xe/tests/xe_migrate.c +1 -1
index 4c79c1dfa772..aedfb3dd559e 100644
@@ -300,7 +300,7 @@ static void xe_migrate_sanity_test(struct xe_migrate *m, struct kunit *test)
 	/* First part of the test, are we updating our pagetable bo with a new entry? */
 	xe_map_wr(xe, &bo->vmap, XE_PAGE_SIZE * (NUM_KERNEL_PDE - 1), u64,
 		  0xdeaddeadbeefbeef);
-	expected = xe_pte_encode(NULL, pt, 0, XE_CACHE_WB, 0, 0);
+	expected = xe_pte_encode(NULL, pt, 0, XE_CACHE_WB, 0);
 	if (m->eng->vm->flags & XE_VM_FLAGS_64K)
 		expected |= XE_PTE_PS64;
 	if (xe_bo_is_vram(pt))
drivers/gpu/drm/xe/xe_bo.c +4 -3
index 5f0232555431..6353afa8d846 100644
@@ -412,7 +412,8 @@ static int xe_bo_trigger_rebind(struct xe_device *xe, struct xe_bo *bo,
 {
 	struct dma_resv_iter cursor;
 	struct dma_fence *fence;
-	struct xe_vma *vma;
+	struct drm_gpuva *gpuva;
+	struct drm_gem_object *obj = &bo->ttm.base;
 	int ret = 0;
 
 	dma_resv_assert_held(bo->ttm.base.resv);
@@ -425,7 +426,8 @@ static int xe_bo_trigger_rebind(struct xe_device *xe, struct xe_bo *bo,
 		dma_resv_iter_end(&cursor);
 	}
 
-	list_for_each_entry(vma, &bo->vmas, bo_link) {
+	drm_gem_for_each_gpuva(gpuva, obj) {
+		struct xe_vma *vma = gpuva_to_vma(gpuva);
 		struct xe_vm *vm = xe_vma_vm(vma);
 
 		trace_xe_vma_evict(vma);
@@ -454,7 +456,6 @@ static int xe_bo_trigger_rebind(struct xe_device *xe, struct xe_bo *bo,
 
 		} else {
 			bool vm_resv_locked = false;
-			struct xe_vm *vm = xe_vma_vm(vma);
 
 			/*
 			 * We need to put the vma on the vm's rebind_list,
drivers/gpu/drm/xe/xe_device.c +1 -1
index 07ae208af809..abfda93924c9 100644
@@ -135,7 +135,7 @@ static struct drm_driver driver = {
 	.driver_features =
 	    DRIVER_GEM |
 	    DRIVER_RENDER | DRIVER_SYNCOBJ |
-	    DRIVER_SYNCOBJ_TIMELINE,
+	    DRIVER_SYNCOBJ_TIMELINE | DRIVER_GEM_GPUVA,
 	.open = xe_file_open,
 	.postclose = xe_file_close,
 
drivers/gpu/drm/xe/xe_gt_pagefault.c +7 -13
index 0e91ab67d617..125e4744fa38 100644
@@ -75,10 +75,10 @@ static bool vma_is_valid(struct xe_gt *gt, struct xe_vma *vma)
 		!(BIT(gt->info.id) & vma->usm.tile_invalidated);
 }
 
-static bool vma_matches(struct xe_vma *vma, struct xe_vma *lookup)
+static bool vma_matches(struct xe_vma *vma, u64 page_addr)
 {
-	if (xe_vma_start(lookup) > xe_vma_end(vma) - 1 ||
-	    xe_vma_end(lookup) - 1 < xe_vma_start(vma))
+	if (page_addr > xe_vma_end(vma) - 1 ||
+	    page_addr + SZ_4K - 1 < xe_vma_start(vma))
 		return false;
 
 	return true;
@@ -91,16 +91,14 @@ static bool only_needs_bo_lock(struct xe_bo *bo)
 
 static struct xe_vma *lookup_vma(struct xe_vm *vm, u64 page_addr)
 {
-	struct xe_vma *vma = NULL, lookup;
+	struct xe_vma *vma = NULL;
 
-	lookup.start = page_addr;
-	lookup.end = lookup.start + SZ_4K - 1;
 	if (vm->usm.last_fault_vma) {   /* Fast lookup */
-		if (vma_matches(vm->usm.last_fault_vma, &lookup))
+		if (vma_matches(vm->usm.last_fault_vma, page_addr))
 			vma = vm->usm.last_fault_vma;
 	}
 	if (!vma)
-		vma = xe_vm_find_overlapping_vma(vm, &lookup);
+		vma = xe_vm_find_overlapping_vma(vm, page_addr, SZ_4K);
 
 	return vma;
 }
@@ -489,12 +487,8 @@ static struct xe_vma *get_acc_vma(struct xe_vm *vm, struct acc *acc)
 {
 	u64 page_va = acc->va_range_base + (ffs(acc->sub_granularity) - 1) *
 		sub_granularity_in_byte(acc->granularity);
-	struct xe_vma lookup;
-
-	lookup.start = page_va;
-	lookup.end = lookup.start + SZ_4K - 1;
 
-	return xe_vm_find_overlapping_vma(vm, &lookup);
+	return xe_vm_find_overlapping_vma(vm, page_va, SZ_4K);
 }
 
 static int handle_acc(struct xe_gt *gt, struct acc *acc)
drivers/gpu/drm/xe/xe_migrate.c +5 -5
index 41c90f6710ee..47addcd3e78f 100644
@@ -197,7 +197,7 @@ static int xe_migrate_prepare_vm(struct xe_tile *tile, struct xe_migrate *m,
 	/* Map the entire BO in our level 0 pt */
 	for (i = 0, level = 0; i < num_entries; level++) {
 		entry = xe_pte_encode(NULL, bo, i * XE_PAGE_SIZE,
-				      XE_CACHE_WB, 0, 0);
+				      XE_CACHE_WB, 0);
 
 		xe_map_wr(xe, &bo->vmap, map_ofs + level * 8, u64, entry);
 
@@ -216,7 +216,7 @@ static int xe_migrate_prepare_vm(struct xe_tile *tile, struct xe_migrate *m,
 		     i += vm->flags & XE_VM_FLAGS_64K ? XE_64K_PAGE_SIZE :
 		     XE_PAGE_SIZE) {
 			entry = xe_pte_encode(NULL, batch, i,
-					      XE_CACHE_WB, 0, 0);
+					      XE_CACHE_WB, 0);
 
 			xe_map_wr(xe, &bo->vmap, map_ofs + level * 8, u64,
 				  entry);
@@ -1159,7 +1159,8 @@ xe_migrate_update_pgtables(struct xe_migrate *m,
 	u64 addr;
 	int err = 0;
 	bool usm = !eng && xe->info.supports_usm;
-	bool first_munmap_rebind = vma && vma->first_munmap_rebind;
+	bool first_munmap_rebind = vma &&
+		vma->gpuva.flags & XE_VMA_FIRST_REBIND;
 	struct xe_engine *eng_override = !eng ? m->eng : eng;
 
 	/* Use the CPU if no in syncs and engine is idle */
@@ -1232,8 +1233,7 @@ xe_migrate_update_pgtables(struct xe_migrate *m,
 
 			BUG_ON(pt_bo->size != SZ_4K);
 
-			addr = xe_pte_encode(NULL, pt_bo, 0, XE_CACHE_WB,
-					     0, 0);
+			addr = xe_pte_encode(NULL, pt_bo, 0, XE_CACHE_WB, 0);
 			bb->cs[bb->len++] = lower_32_bits(addr);
 			bb->cs[bb->len++] = upper_32_bits(addr);
 		}
drivers/gpu/drm/xe/xe_pt.c +19 -21
index a697d43ec293..00855681c0d5 100644
@@ -100,15 +100,15 @@ static dma_addr_t vma_addr(struct xe_vma *vma, u64 offset,
 	}
 }
 
-static u64 __pte_encode(u64 pte, enum xe_cache_level cache, u32 flags,
-			u32 pt_level)
+static u64 __pte_encode(u64 pte, enum xe_cache_level cache,
+			struct xe_vma *vma, u32 pt_level)
 {
 	pte |= XE_PAGE_PRESENT | XE_PAGE_RW;
 
-	if (unlikely(flags & XE_PTE_FLAG_READ_ONLY))
+	if (unlikely(vma && xe_vma_read_only(vma)))
 		pte &= ~XE_PAGE_RW;
 
-	if (unlikely(flags & XE_PTE_FLAG_NULL))
+	if (unlikely(vma && xe_vma_is_null(vma)))
 		pte |= XE_PTE_NULL;
 
 	/* FIXME: I don't think the PPAT handling is correct for MTL */
@@ -142,7 +142,6 @@ static u64 __pte_encode(u64 pte, enum xe_cache_level cache, u32 flags,
  * @bo: If @vma is NULL, representing the memory to point to.
  * @offset: The offset into @vma or @bo.
  * @cache: The cache level indicating
- * @flags: Currently only supports PTE_READ_ONLY for read-only access.
  * @pt_level: The page-table level of the page-table into which the entry
  * is to be inserted.
  *
@@ -150,7 +149,7 @@ static u64 __pte_encode(u64 pte, enum xe_cache_level cache, u32 flags,
  */
 u64 xe_pte_encode(struct xe_vma *vma, struct xe_bo *bo,
 		  u64 offset, enum xe_cache_level cache,
-		  u32 flags, u32 pt_level)
+		  u32 pt_level)
 {
 	u64 pte;
 	bool is_vram;
@@ -162,11 +161,11 @@ u64 xe_pte_encode(struct xe_vma *vma, struct xe_bo *bo,
 
 	if (is_vram) {
 		pte |= XE_PPGTT_PTE_LM;
-		if (vma && vma->use_atomic_access_pte_bit)
+		if (vma && vma->gpuva.flags & XE_VMA_ATOMIC_PTE_BIT)
 			pte |= XE_USM_PPGTT_PTE_AE;
 	}
 
-	return __pte_encode(pte, cache, flags, pt_level);
+	return __pte_encode(pte, cache, vma, pt_level);
 }
 
 static u64 __xe_pt_empty_pte(struct xe_tile *tile, struct xe_vm *vm,
@@ -179,7 +178,7 @@ static u64 __xe_pt_empty_pte(struct xe_tile *tile, struct xe_vm *vm,
 
 	if (level == 0) {
 		u64 empty = xe_pte_encode(NULL, vm->scratch_bo[id], 0,
-					  XE_CACHE_WB, 0, 0);
+					  XE_CACHE_WB, 0);
 
 		return empty;
 	} else {
@@ -424,10 +423,9 @@ struct xe_pt_stage_bind_walk {
 	 */
 	bool needs_64K;
 	/**
-	 * @pte_flags: Flags determining PTE setup. These are not flags
-	 * encoded directly in the PTE. See @default_pte for those.
+	 * @vma: VMA being mapped
 	 */
-	u32 pte_flags;
+	struct xe_vma *vma;
 
 	/* Also input, but is updated during the walk*/
 	/** @curs: The DMA address cursor. */
@@ -564,7 +562,7 @@ static bool xe_pt_hugepte_possible(u64 addr, u64 next, unsigned int level,
 		return false;
 
 	/* null VMA's do not have dma addresses */
-	if (xe_walk->pte_flags & XE_PTE_FLAG_NULL)
+	if (xe_vma_is_null(xe_walk->vma))
 		return true;
 
 	/* Is the DMA address huge PTE size aligned? */
@@ -590,7 +588,7 @@ xe_pt_scan_64K(u64 addr, u64 next, struct xe_pt_stage_bind_walk *xe_walk)
 		return false;
 
 	/* null VMA's do not have dma addresses */
-	if (xe_walk->pte_flags & XE_PTE_FLAG_NULL)
+	if (xe_vma_is_null(xe_walk->vma))
 		return true;
 
 	xe_res_next(&curs, addr - xe_walk->va_curs_start);
@@ -643,14 +641,13 @@ xe_pt_stage_bind_entry(struct xe_ptw *parent, pgoff_t offset,
 	/* 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 is_null = xe_walk->pte_flags & XE_PTE_FLAG_NULL;
+		bool is_null = xe_vma_is_null(xe_walk->vma);
 
 		XE_WARN_ON(xe_walk->va_curs_start != addr);
 
 		pte = __pte_encode(is_null ? 0 :
 				   xe_res_dma(curs) + xe_walk->dma_offset,
-				   xe_walk->cache, xe_walk->pte_flags,
-				   level);
+				   xe_walk->cache, xe_walk->vma, level);
 		pte |= xe_walk->default_pte;
 
 		/*
@@ -762,7 +759,7 @@ xe_pt_stage_bind(struct xe_tile *tile, struct xe_vma *vma,
 		.tile = tile,
 		.curs = &curs,
 		.va_curs_start = xe_vma_start(vma),
-		.pte_flags = vma->pte_flags,
+		.vma = vma,
 		.wupd.entries = entries,
 		.needs_64K = (xe_vma_vm(vma)->flags & XE_VM_FLAGS_64K) && is_vram,
 	};
@@ -771,7 +768,7 @@ xe_pt_stage_bind(struct xe_tile *tile, struct xe_vma *vma,
 
 	if (is_vram) {
 		xe_walk.default_pte = XE_PPGTT_PTE_LM;
-		if (vma && vma->use_atomic_access_pte_bit)
+		if (vma && vma->gpuva.flags & XE_VMA_ATOMIC_PTE_BIT)
 			xe_walk.default_pte |= XE_USM_PPGTT_PTE_AE;
 		xe_walk.dma_offset = vram_region_gpu_offset(bo->ttm.resource);
 		xe_walk.cache = XE_CACHE_WB;
@@ -1343,6 +1340,7 @@ __xe_pt_bind_vma(struct xe_tile *tile, struct xe_vma *vma, struct xe_engine *e,
 					   syncs, num_syncs,
 					   &bind_pt_update.base);
 	if (!IS_ERR(fence)) {
+		bool last_munmap_rebind = vma->gpuva.flags & XE_VMA_LAST_REBIND;
 		LLIST_HEAD(deferred);
 
 		/* TLB invalidation must be done before signaling rebind */
@@ -1359,7 +1357,7 @@ __xe_pt_bind_vma(struct xe_tile *tile, struct xe_vma *vma, struct xe_engine *e,
 
 		/* add shared fence now for pagetable delayed destroy */
 		dma_resv_add_fence(&vm->resv, fence, !rebind &&
-				   vma->last_munmap_rebind ?
+				   last_munmap_rebind ?
 				   DMA_RESV_USAGE_KERNEL :
 				   DMA_RESV_USAGE_BOOKKEEP);
 
@@ -1377,7 +1375,7 @@ __xe_pt_bind_vma(struct xe_tile *tile, struct xe_vma *vma, struct xe_engine *e,
 			up_read(&vm->userptr.notifier_lock);
 			xe_bo_put_commit(&deferred);
 		}
-		if (!rebind && vma->last_munmap_rebind &&
+		if (!rebind && last_munmap_rebind &&
 		    xe_vm_in_compute_mode(vm))
 			queue_work(vm->xe->ordered_wq,
 				   &vm->preempt.rebind_work);
drivers/gpu/drm/xe/xe_pt.h +1 -1
index 54e8a043d353..aaf4b7b851e2 100644
@@ -50,5 +50,5 @@ u64 xe_pde_encode(struct xe_bo *bo, u64 bo_offset,
 
 u64 xe_pte_encode(struct xe_vma *vma, struct xe_bo *bo,
 		  u64 offset, enum xe_cache_level cache,
-		  u32 flags, u32 pt_level);
+		  u32 pt_level);
 #endif
drivers/gpu/drm/xe/xe_vm.c +866 -921

2,303 lines not on this page · raw message

drivers/gpu/drm/xe/xe_vm.h +26 -9
index 644a8aa604e8..eaf11ac8ff51 100644
@@ -6,6 +6,7 @@
 #ifndef _XE_VM_H_
 #define _XE_VM_H_
 
+#include "xe_bo_types.h"
 #include "xe_macros.h"
 #include "xe_map.h"
 #include "xe_vm_types.h"
@@ -61,7 +62,22 @@ static inline bool xe_vm_is_closed_or_banned(struct xe_vm *vm)
 }
 
 struct xe_vma *
-xe_vm_find_overlapping_vma(struct xe_vm *vm, struct xe_vma *vma);
+xe_vm_find_overlapping_vma(struct xe_vm *vm, u64 start, u64 range);
+
+static inline struct xe_vm *gpuva_to_vm(struct drm_gpuva *gpuva)
+{
+	return container_of(gpuva->mgr, struct xe_vm, mgr);
+}
+
+static inline struct xe_vma *gpuva_to_vma(struct drm_gpuva *gpuva)
+{
+	return container_of(gpuva, struct xe_vma, gpuva);
+}
+
+static inline struct xe_vma_op *gpuva_op_to_vma_op(struct drm_gpuva_op *op)
+{
+	return container_of(op, struct xe_vma_op, base);
+}
 
 /**
  * DOC: Provide accessors for vma members to facilitate easy change of
@@ -69,12 +85,12 @@ xe_vm_find_overlapping_vma(struct xe_vm *vm, struct xe_vma *vma);
  */
 static inline u64 xe_vma_start(struct xe_vma *vma)
 {
-	return vma->start;
+	return vma->gpuva.va.addr;
 }
 
 static inline u64 xe_vma_size(struct xe_vma *vma)
 {
-	return vma->end - vma->start + 1;
+	return vma->gpuva.va.range;
 }
 
 static inline u64 xe_vma_end(struct xe_vma *vma)
@@ -84,32 +100,33 @@ static inline u64 xe_vma_end(struct xe_vma *vma)
 
 static inline u64 xe_vma_bo_offset(struct xe_vma *vma)
 {
-	return vma->bo_offset;
+	return vma->gpuva.gem.offset;
 }
 
 static inline struct xe_bo *xe_vma_bo(struct xe_vma *vma)
 {
-	return vma->bo;
+	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 vma->vm;
+	return container_of(vma->gpuva.mgr, struct xe_vm, mgr);
 }
 
 static inline bool xe_vma_read_only(struct xe_vma *vma)
 {
-	return vma->pte_flags & XE_PTE_FLAG_READ_ONLY;
+	return vma->gpuva.flags & XE_VMA_READ_ONLY;
 }
 
 static inline u64 xe_vma_userptr(struct xe_vma *vma)
 {
-	return vma->userptr.ptr;
+	return vma->gpuva.gem.offset;
 }
 
 static inline bool xe_vma_is_null(struct xe_vma *vma)
 {
-	return vma->pte_flags & XE_PTE_FLAG_NULL;
+	return vma->gpuva.flags & DRM_GPUVA_SPARSE;
 }
 
 static inline bool xe_vma_has_no_bo(struct xe_vma *vma)
drivers/gpu/drm/xe/xe_vm_madvise.c +15 -61

96 lines not on this page · raw message

drivers/gpu/drm/xe/xe_vm_types.h +116 -57

217 lines not on this page · raw message

Signature · 1 line
2.34.1
#8 lore raw

[Intel-xe] ✓ CI.Patch_applied: success for GPUVA with no uAPI changes

In reply to Matthew Brost
== Series Details ==

== Series Details ==

Series: GPUVA with no uAPI changes
URL : https://patchwork.freedesktop.org/series/120385/
State : success

== Summary ==

=== Applying kernel patches on branch 'drm-xe-next' with base: === Base commit: 16b960c63 fixup! drm/xe: Introduce a new DRM driver for Intel GPUs === git am output follows ===
.git/rebase-apply/patch:545: trailing whitespace.
*
warning: 1 line adds whitespace errors.
Applying: drm/xe: Ban a VM if rebind worker hits an error
Applying: drm/xe: Add helpers to hide struct xe_vma internals
Applying: drm: manager to keep track of GPUs VA mappings
Applying: drm: debugfs: provide infrastructure to dump a DRM GPU VA space
Applying: drm/xe: Remove __xe_vm_bind forward declaration
Applying: drm/xe: Port Xe to GPUVA

CI Reviewed-by Thomas Hellström on the v5 series
#9 lore raw

[Intel-xe] ✗ CI.checkpatch: warning for GPUVA with no uAPI changes

In reply to Matthew Brost
== Series Details ==

== Series Details ==

Series: GPUVA with no uAPI changes
URL : https://patchwork.freedesktop.org/series/120385/
State : warning

== Summary ==

+ KERNEL=/kernel
+ git clone https://gitlab.freedesktop.org/drm/maintainer-tools mt Cloning into 'mt'...
warning: redirecting to https://gitlab.freedesktop.org/drm/maintainer-tools.git/
+ git -C mt rev-list -n1 origin/master c7d32770e3cd31d9fc134ce41f329b10aa33ee15
+ cd /kernel
+ git config --global --add safe.directory /kernel
+ git log -n1
commit f60cab4e861ed17f68752f0828a3c71be3b28bf6

Author: Matthew Brost <[email protected]>
Date:   Fri Jul 7 23:43:59 2023 -0700

drm/xe: Port Xe to GPUVA

Rather than open coding VM binds and VMA tracking, use the GPUVA library. GPUVA provides a common infrastructure for VM binds to use mmap / munmap semantics and support for VK sparse bindings.

The concepts are:

1) xe_vm inherits from drm_gpuva_manager
2) xe_vma inherits from drm_gpuva
3) xe_vma_op inherits from drm_gpuva_op
4) VM bind operations (MAP, UNMAP, PREFETCH, UNMAP_ALL) call into the GPUVA code to generate an VMA operations list which is parsed, committed, and executed.

v2 (CI): Add break after default in case statement.
v3: Rebase
v4: Fix some error handling
v5: Use unlocked version VMA in error paths
v6: Rebase, address some review feedback mainly Thomas H
v7: Fix compile error in xe_vma_op_unwind, address checkpatch

+ /mt/dim checkpatch 16b960c6321c6c67bf651a332b59166c2082d5c1 drm-intel
a950fcee8 drm/xe: Ban a VM if rebind worker hits an error
438dfbfb3 drm/xe: Add helpers to hide struct xe_vma internals
-:643: WARNING:AVOID_BUG: Do not crash the kernel unless it is absolutely unavoidable--use WARN_ON_ONCE() plus recovery code (if feasible) instead of BUG() or variants #643: FILE: drivers/gpu/drm/xe/xe_vm.c:1170:
+ XE_BUG_ON(xe_vma_end(vma) > vm->size);

-:652: WARNING:AVOID_BUG: Do not crash the kernel unless it is absolutely unavoidable--use WARN_ON_ONCE() plus recovery code (if feasible) instead of BUG() or variants #652: FILE: drivers/gpu/drm/xe/xe_vm.c:1179:
+ XE_BUG_ON(xe_vma_vm(vma) != vm);

-:661: WARNING:AVOID_BUG: Do not crash the kernel unless it is absolutely unavoidable--use WARN_ON_ONCE() plus recovery code (if feasible) instead of BUG() or variants #661: FILE: drivers/gpu/drm/xe/xe_vm.c:1187:
+ XE_BUG_ON(xe_vma_vm(vma) != vm);

-:751: CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis #751: FILE: drivers/gpu/drm/xe/xe_vm.c:2601:
+ XE_IOCTL_ERR(xe, (xe_vma_start(vma) != addr ||
+ xe_vma_end(vma) != addr + range) && !async))

-:858: WARNING:LONG_LINE: line length of 101 exceeds 100 columns #858: FILE: drivers/gpu/drm/xe/xe_vm.c:2803:
+ if (!xe_bo_can_migrate(xe_vma_bo(__vma), region_to_mem_type[region]))

-:867: WARNING:LONG_LINE: line length of 101 exceeds 100 columns #867: FILE: drivers/gpu/drm/xe/xe_vm.c:2817:
+ if (!xe_bo_can_migrate(xe_vma_bo(__vma), region_to_mem_type[region]))

-:893: WARNING:AVOID_BUG: Do not crash the kernel unless it is absolutely unavoidable--use WARN_ON_ONCE() plus recovery code (if feasible) instead of BUG() or variants #893: FILE: drivers/gpu/drm/xe/xe_vm.c:3446:
+ XE_BUG_ON(!xe_vm_in_fault_mode(xe_vma_vm(vma)));

total: 0 errors, 6 warnings, 1 checks, 947 lines checked
9c21730e6 drm: manager to keep track of GPUs VA mappings
Traceback (most recent call last):
File "scripts/spdxcheck.py", line 6, in <module>
from ply import lex, yacc
ModuleNotFoundError: No module named 'ply'
Traceback (most recent call last):
File "scripts/spdxcheck.py", line 6, in <module>
from ply import lex, yacc
ModuleNotFoundError: No module named 'ply'
-:104: WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating? #104:
new file mode 100644

-:562: ERROR:TRAILING_WHITESPACE: trailing whitespace #562: FILE: drivers/gpu/drm/drm_gpuva_mgr.c:454:
+ *^I^I^I$

-:712: CHECK:MACRO_ARG_REUSE: Macro argument reuse 'node' - possible side-effects? #712: FILE: drivers/gpu/drm/drm_gpuva_mgr.c:604:
+#define GPUVA_LAST(node) ((node)->va.addr + (node)->va.range - 1)

-:718: WARNING:PREFER_DEFINED_ATTRIBUTE_MACRO: __always_unused or __maybe_unused is preferred over __attribute__((__unused__)) #718: FILE: drivers/gpu/drm/drm_gpuva_mgr.c:610:
+ GPUVA_START, GPUVA_LAST, static __attribute__((unused)),

-:759: CHECK:BRACES: Blank lines aren't necessary after an open brace '{' #759: FILE: drivers/gpu/drm/drm_gpuva_mgr.c:651:
+{
+

-:811: CHECK:BRACES: Blank lines aren't necessary before a close brace '}' #811: FILE: drivers/gpu/drm/drm_gpuva_mgr.c:703:
+
+}

-:1123: ERROR:ASSIGN_IN_IF: do not use assignment in if condition #1123: FILE: drivers/gpu/drm/drm_gpuva_mgr.c:1015:
+ if ((map = op->prev)) {

-:1128: ERROR:ASSIGN_IN_IF: do not use assignment in if condition #1128: FILE: drivers/gpu/drm/drm_gpuva_mgr.c:1020:
+ if ((map = op->next)) {

-:1822: CHECK:LINE_SPACING: Please don't use multiple blank lines #1822: FILE: drivers/gpu/drm/drm_gpuva_mgr.c:1714:
+
+

-:2138: WARNING:NEW_TYPEDEFS: do not add new typedefs #2138: FILE: include/drm/drm_gpuva_mgr.h:189:
+typedef struct lockdep_map *lockdep_map_p;

-:2151: ERROR:COMPLEX_MACRO: Macros with complex values should be enclosed in parentheses #2151: FILE: include/drm/drm_gpuva_mgr.h:202:
+#define drm_gpuva_manager_set_ext_lock(mgr, lock) \
+ (mgr)->ext_lock = &(lock)->dep_map

-:2154: WARNING:NEW_TYPEDEFS: do not add new typedefs #2154: FILE: include/drm/drm_gpuva_mgr.h:205:
+typedef struct { /* nothing */ } lockdep_map_p;

-:2155: WARNING:SINGLE_STATEMENT_DO_WHILE_MACRO: Single statement macros should not use a do {} while (0) loop #2155: FILE: include/drm/drm_gpuva_mgr.h:206:
+#define drm_gpuva_manager_ext_assert_held(mgr) do { (void)(mgr); } while (0)

-:2285: CHECK:MACRO_ARG_REUSE: Macro argument reuse 'va__' - possible side-effects? #2285: FILE: include/drm/drm_gpuva_mgr.h:336:
+#define drm_gpuva_for_each_va_range(va__, mgr__, start__, end__) \
+ for (va__ = drm_gpuva_find_first((mgr__), (start__), (end__) - (start__)); \
+ va__ && (va__->va.addr < (end__)); \
+ va__ = drm_gpuva_next(va__))

-:2285: CHECK:MACRO_ARG_REUSE: Macro argument reuse 'start__' - possible side-effects? #2285: FILE: include/drm/drm_gpuva_mgr.h:336:
+#define drm_gpuva_for_each_va_range(va__, mgr__, start__, end__) \
+ for (va__ = drm_gpuva_find_first((mgr__), (start__), (end__) - (start__)); \
+ va__ && (va__->va.addr < (end__)); \
+ va__ = drm_gpuva_next(va__))

-:2285: CHECK:MACRO_ARG_REUSE: Macro argument reuse 'end__' - possible side-effects? #2285: FILE: include/drm/drm_gpuva_mgr.h:336:
+#define drm_gpuva_for_each_va_range(va__, mgr__, start__, end__) \
+ for (va__ = drm_gpuva_find_first((mgr__), (start__), (end__) - (start__)); \
+ va__ && (va__->va.addr < (end__)); \
+ va__ = drm_gpuva_next(va__))

-:2308: CHECK:MACRO_ARG_REUSE: Macro argument reuse 'va__' - possible side-effects? #2308: FILE: include/drm/drm_gpuva_mgr.h:359:
+#define drm_gpuva_for_each_va_range_safe(va__, next__, mgr__, start__, end__) \
+ for (va__ = drm_gpuva_find_first((mgr__), (start__), (end__) - (start__)), \

+	     next__ = drm_gpuva_next(va__); \
+	     va__ && (va__->va.addr < (end__)); \
+	     va__ = next__, next__ = drm_gpuva_next(va__))

-:2308: CHECK:MACRO_ARG_REUSE: Macro argument reuse 'next__' - possible side-effects? #2308: FILE: include/drm/drm_gpuva_mgr.h:359:
+#define drm_gpuva_for_each_va_range_safe(va__, next__, mgr__, start__, end__) \
+ for (va__ = drm_gpuva_find_first((mgr__), (start__), (end__) - (start__)), \

+	     next__ = drm_gpuva_next(va__); \
+	     va__ && (va__->va.addr < (end__)); \
+	     va__ = next__, next__ = drm_gpuva_next(va__))

-:2308: CHECK:MACRO_ARG_REUSE: Macro argument reuse 'start__' - possible side-effects? #2308: FILE: include/drm/drm_gpuva_mgr.h:359:
+#define drm_gpuva_for_each_va_range_safe(va__, next__, mgr__, start__, end__) \
+ for (va__ = drm_gpuva_find_first((mgr__), (start__), (end__) - (start__)), \

+	     next__ = drm_gpuva_next(va__); \
+	     va__ && (va__->va.addr < (end__)); \
+	     va__ = next__, next__ = drm_gpuva_next(va__))

-:2308: CHECK:MACRO_ARG_REUSE: Macro argument reuse 'end__' - possible side-effects? #2308: FILE: include/drm/drm_gpuva_mgr.h:359:
+#define drm_gpuva_for_each_va_range_safe(va__, next__, mgr__, start__, end__) \
+ for (va__ = drm_gpuva_find_first((mgr__), (start__), (end__) - (start__)), \

+	     next__ = drm_gpuva_next(va__); \
+	     va__ && (va__->va.addr < (end__)); \
+	     va__ = next__, next__ = drm_gpuva_next(va__))

-:2604: CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis #2604: FILE: include/drm/drm_gpuva_mgr.h:655:
+drm_gpuva_prefetch_ops_create(struct drm_gpuva_manager *mgr,
+ u64 addr, u64 range);

total: 4 errors, 5 warnings, 12 checks, 2644 lines checked
ece560d8c drm: debugfs: provide infrastructure to dump a DRM GPU VA space
b600ef25f drm/xe: Remove __xe_vm_bind forward declaration
f60cab4e8 drm/xe: Port Xe to GPUVA
-:563: WARNING:AVOID_BUG: Do not crash the kernel unless it is absolutely unavoidable--use WARN_ON_ONCE() plus recovery code (if feasible) instead of BUG() or variants #563: FILE: drivers/gpu/drm/xe/xe_vm.c:1143:
+ XE_BUG_ON(start + range > vm->size);

-:831: WARNING:AVOID_BUG: Do not crash the kernel unless it is absolutely unavoidable--use WARN_ON_ONCE() plus recovery code (if feasible) instead of BUG() or variants #831: FILE: drivers/gpu/drm/xe/xe_vm.c:1821:
+ XE_BUG_ON(!xe_vm_in_fault_mode(vm));

-:1038: WARNING:BLOCK_COMMENT_STYLE: Block comments use * on subsequent lines #1038: FILE: drivers/gpu/drm/xe/xe_vm.c:2170:
+ return -ENODATA; /* Not an actual error, IOCTL
+ cleans up returns and 0 */

-:1038: WARNING:BLOCK_COMMENT_STYLE: Block comments use a trailing */ on a separate line #1038: FILE: drivers/gpu/drm/xe/xe_vm.c:2170:
+ cleans up returns and 0 */

-:1040: CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis #1040: FILE: drivers/gpu/drm/xe/xe_vm.c:2172:
+ if (XE_IOCTL_ERR(xe, (xe_vma_start(vma) != addr ||
+ xe_vma_end(vma) != addr + range) && !async))

-:1046: WARNING:BLOCK_COMMENT_STYLE: Block comments use * on subsequent lines #1046: FILE: drivers/gpu/drm/xe/xe_vm.c:2178:
+ return -ENODATA; /* Not an actual error, IOCTL
+ cleans up returns and 0 */

-:1046: WARNING:BLOCK_COMMENT_STYLE: Block comments use a trailing */ on a separate line #1046: FILE: drivers/gpu/drm/xe/xe_vm.c:2178:
+ cleans up returns and 0 */

-:1049: WARNING:AVOID_BUG: Do not crash the kernel unless it is absolutely unavoidable--use WARN_ON_ONCE() plus recovery code (if feasible) instead of BUG() or variants #1049: FILE: drivers/gpu/drm/xe/xe_vm.c:2181:
+ XE_BUG_ON("NOT POSSIBLE");

-:1131: WARNING:AVOID_BUG: Do not crash the kernel unless it is absolutely unavoidable--use WARN_ON_ONCE() plus recovery code (if feasible) instead of BUG() or variants #1131: FILE: drivers/gpu/drm/xe/xe_vm.c:2234:
+ XE_BUG_ON("NOT POSSIBLE");

-:1293: WARNING:AVOID_BUG: Do not crash the kernel unless it is absolutely unavoidable--use WARN_ON_ONCE() plus recovery code (if feasible) instead of BUG() or variants #1293: FILE: drivers/gpu/drm/xe/xe_vm.c:2309:
+ XE_BUG_ON(!bo);

-:1324: WARNING:AVOID_BUG: Do not crash the kernel unless it is absolutely unavoidable--use WARN_ON_ONCE() plus recovery code (if feasible) instead of BUG() or variants #1324: FILE: drivers/gpu/drm/xe/xe_vm.c:2326:
+ XE_BUG_ON("NOT POSSIBLE");

-:1420: WARNING:AVOID_BUG: Do not crash the kernel unless it is absolutely unavoidable--use WARN_ON_ONCE() plus recovery code (if feasible) instead of BUG() or variants #1420: FILE: drivers/gpu/drm/xe/xe_vm.c:2403:
+ XE_BUG_ON(num_ops_list > 1 && !async);

-:1473: WARNING:AVOID_BUG: Do not crash the kernel unless it is absolutely unavoidable--use WARN_ON_ONCE() plus recovery code (if feasible) instead of BUG() or variants #1473: FILE: drivers/gpu/drm/xe/xe_vm.c:2432:
+ XE_BUG_ON(!first && !async);

-:1601: WARNING:AVOID_BUG: Do not crash the kernel unless it is absolutely unavoidable--use WARN_ON_ONCE() plus recovery code (if feasible) instead of BUG() or variants #1601: FILE: drivers/gpu/drm/xe/xe_vm.c:2521:
+ XE_BUG_ON("NOT POSSIBLE");

-:2010: WARNING:AVOID_BUG: Do not crash the kernel unless it is absolutely unavoidable--use WARN_ON_ONCE() plus recovery code (if feasible) instead of BUG() or variants #2010: FILE: drivers/gpu/drm/xe/xe_vm.c:2687:
+ XE_BUG_ON("NOT POSSIBLE");

-:2119: WARNING:AVOID_BUG: Do not crash the kernel unless it is absolutely unavoidable--use WARN_ON_ONCE() plus recovery code (if feasible) instead of BUG() or variants #2119: FILE: drivers/gpu/drm/xe/xe_vm.c:2746:
+ XE_BUG_ON("NOT POSSIBLE");

-:2214: WARNING:AVOID_BUG: Do not crash the kernel unless it is absolutely unavoidable--use WARN_ON_ONCE() plus recovery code (if feasible) instead of BUG() or variants #2214: FILE: drivers/gpu/drm/xe/xe_vm.c:2822:
+ XE_BUG_ON("NOT POSSIBLE");

total: 0 errors, 16 warnings, 1 checks, 2963 lines checked

#10 lore raw

[Intel-xe] ✗ CI.KUnit: failure for GPUVA with no uAPI changes

In reply to Matthew Brost
== Series Details ==

== Series Details ==

Series: GPUVA with no uAPI changes
URL : https://patchwork.freedesktop.org/series/120385/
State : failure

== Summary ==

+ trap cleanup EXIT
+ /kernel/tools/testing/kunit/kunit.py run --kunitconfig /kernel/drivers/gpu/drm/xe/.kunitconfig ERROR:root:In file included from ../drivers/gpu/drm/xe/xe_vm_types.h:9,

                 from ../drivers/gpu/drm/xe/xe_bo.h:11,
                 from ../drivers/gpu/drm/xe/xe_bo.c:6:
../include/drm/drm_gpuva_mgr.h:205:34: error: conflicting types for ‘lockdep_map_p’
  205 | typedef struct { /* nothing */ } lockdep_map_p;
      |                                  ^~~~~~~~~~~~~
In file included from ../include/linux/mm_types.h:12,
                 from ../include/drm/drm_mm.h:43,
                 from ../drivers/gpu/drm/xe/xe_bo_types.h:11,
                 from ../drivers/gpu/drm/xe/xe_bo.h:9,
                 from ../drivers/gpu/drm/xe/xe_bo.c:6:
../include/linux/maple_tree.h:191:34: note: previous declaration of ‘lockdep_map_p’ was here
  191 | typedef struct { /* nothing */ } lockdep_map_p;
      |                                  ^~~~~~~~~~~~~
In file included from ../drivers/gpu/drm/xe/xe_vm_types.h:9,
                 from ../drivers/gpu/drm/xe/xe_bo.h:11,
                 from ../drivers/gpu/drm/xe/xe_bo_evict.c:8:
../include/drm/drm_gpuva_mgr.h:205:34: error: conflicting types for ‘lockdep_map_p’
  205 | typedef struct { /* nothing */ } lockdep_map_p;
      |                                  ^~~~~~~~~~~~~
In file included from ../include/linux/mm_types.h:12,
                 from ../include/drm/drm_mm.h:43,
                 from ../drivers/gpu/drm/xe/xe_bo_types.h:11,
                 from ../drivers/gpu/drm/xe/xe_bo.h:9,
                 from ../drivers/gpu/drm/xe/xe_bo_evict.c:8:
../include/linux/maple_tree.h:191:34: note: previous declaration of ‘lockdep_map_p’ was here
  191 | typedef struct { /* nothing */ } lockdep_map_p;
      |                                  ^~~~~~~~~~~~~
In file included from ../drivers/gpu/drm/xe/xe_vm_types.h:9,
                 from ../drivers/gpu/drm/xe/xe_bb.c:15:
../include/drm/drm_gpuva_mgr.h:205:34: error: conflicting types for ‘lockdep_map_p’
  205 | typedef struct { /* nothing */ } lockdep_map_p;
      |                                  ^~~~~~~~~~~~~
In file included from ../include/linux/mm_types.h:12,
                 from ../include/linux/mmzone.h:22,
                 from ../include/linux/topology.h:33,
                 from ../include/linux/irq.h:19,
                 from ../include/asm-generic/hardirq.h:17,
                 from ../arch/um/include/asm/hardirq.h:5,
                 from ../include/linux/hardirq.h:11,
                 from ../include/linux/interrupt.h:11,
                 from ../include/drm/drm_util.h:35,
                 from ../drivers/gpu/drm/xe/xe_device.h:12,
                 from ../drivers/gpu/drm/xe/xe_bb.c:9:
../include/linux/maple_tree.h:191:34: note: previous declaration of ‘lockdep_map_p’ was here
  191 | typedef struct { /* nothing */ } lockdep_map_p;
      |                                  ^~~~~~~~~~~~~

make[6]: *** [../scripts/Makefile.build:252: drivers/gpu/drm/xe/xe_bb.o] Error 1 make[6]: *** Waiting for unfinished jobs....
make[6]: *** [../scripts/Makefile.build:252: drivers/gpu/drm/xe/xe_bo_evict.o] Error 1 make[6]: *** [../scripts/Makefile.build:252: drivers/gpu/drm/xe/xe_bo.o] Error 1 make[5]: *** [../scripts/Makefile.build:494: drivers/gpu/drm/xe] Error 2 make[5]: *** Waiting for unfinished jobs....
make[4]: *** [../scripts/Makefile.build:494: drivers/gpu/drm] Error 2 make[3]: *** [../scripts/Makefile.build:494: drivers/gpu] Error 2 make[3]: *** Waiting for unfinished jobs....
make[2]: *** [../scripts/Makefile.build:494: drivers] Error 2
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [/kernel/Makefile:2026: .] Error 2
make: *** [Makefile:226: __sub-make] Error 2

[06:47:02] Configuring KUnit Kernel ...
Generating .config ...
Populating config with:

$ make ARCH=um O=.kunit olddefconfig
[06:47:07] Building KUnit Kernel ...
Populating config with:
$ make ARCH=um O=.kunit olddefconfig
Building with:
$ make ARCH=um O=.kunit --jobs=48
+ cleanup
++ stat -c %u:%g /kernel
+ chown -R 1003:1003 /kernel