All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>
To: intel-xe@lists.freedesktop.org
Subject: [Intel-xe] [CI v8 12/18] drm/xe: Adjust to commit drm/gpuvm: reference count drm_gpuvm structures
Date: Fri,  3 Nov 2023 16:32:28 +0100	[thread overview]
Message-ID: <20231103153234.30407-12-thomas.hellstrom@linux.intel.com> (raw)
In-Reply-To: <20231103153234.30407-1-thomas.hellstrom@linux.intel.com>

Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
---
 drivers/gpu/drm/xe/xe_vm.c       | 30 ++++++++++++------------------
 drivers/gpu/drm/xe/xe_vm.h       |  5 ++---
 drivers/gpu/drm/xe/xe_vm_types.h |  2 --
 3 files changed, 14 insertions(+), 23 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c
index 46a87a4e42d8..bb44e5ca224a 100644
--- a/drivers/gpu/drm/xe/xe_vm.c
+++ b/drivers/gpu/drm/xe/xe_vm.c
@@ -1197,8 +1197,11 @@ static struct drm_gpuva_op *xe_vm_op_alloc(void)
 	return &op->base;
 }
 
+static void xe_vm_free(struct drm_gpuvm *gpuvm);
+
 static struct drm_gpuvm_ops gpuvm_ops = {
 	.op_alloc = xe_vm_op_alloc,
+	.vm_free = xe_vm_free,
 };
 
 static u64 pde_encode_pat_index(struct xe_device *xe, u16 pat_index)
@@ -1346,7 +1349,6 @@ struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags)
 		return ERR_PTR(-ENOMEM);
 
 	vm->xe = xe;
-	kref_init(&vm->refcount);
 
 	vm->size = 1ull << xe->info.va_bits;
 
@@ -1498,7 +1500,7 @@ struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags)
 	}
 	dma_resv_unlock(xe_vm_resv(vm));
 err_put:
-	drm_gpuvm_destroy(&vm->gpuvm);
+	//	drm_gpuvm_destroy(&vm->gpuvm);
 err_no_resv:
 	for_each_tile(tile, xe, id)
 		xe_range_fence_tree_fini(&vm->rftree[id]);
@@ -1586,6 +1588,10 @@ void xe_vm_close_and_put(struct xe_vm *vm)
 				xe_pt_destroy(vm->scratch_pt[id][i], vm->flags,
 					      NULL);
 		}
+		if (vm->pt_root[id]) {
+			xe_pt_destroy(vm->pt_root[id], vm->flags, NULL);
+			vm->pt_root[id] = NULL;
+		}
 	}
 	xe_vm_unlock(vm);
 
@@ -1639,29 +1645,17 @@ static void vm_destroy_work_func(struct work_struct *w)
 		}
 	}
 
-	/*
-	 * XXX: We delay destroying the PT root until the VM if freed as PT root
-	 * 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, false);
-	for_each_tile(tile, 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);
+	for_each_tile(tile, xe, id)
+		XE_WARN_ON(vm->pt_root[id]);
 
 	trace_xe_vm_free(vm);
 	dma_fence_put(vm->rebind_fence);
-	drm_gpuvm_destroy(&vm->gpuvm);
 	kfree(vm);
 }
 
-void xe_vm_free(struct kref *ref)
+static void xe_vm_free(struct drm_gpuvm *gpuvm)
 {
-	struct xe_vm *vm = container_of(ref, struct xe_vm, refcount);
+	struct xe_vm *vm = container_of(gpuvm, struct xe_vm, gpuvm);
 
 	/* To destroy the VM we need to be able to sleep */
 	queue_work(system_unbound_wq, &vm->destroy_work);
diff --git a/drivers/gpu/drm/xe/xe_vm.h b/drivers/gpu/drm/xe/xe_vm.h
index 88077214261f..a348dc56027c 100644
--- a/drivers/gpu/drm/xe/xe_vm.h
+++ b/drivers/gpu/drm/xe/xe_vm.h
@@ -24,20 +24,19 @@ struct xe_sync_entry;
 struct drm_exec;
 
 struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags);
-void xe_vm_free(struct kref *ref);
 
 struct xe_vm *xe_vm_lookup(struct xe_file *xef, u32 id);
 int xe_vma_cmp_vma_cb(const void *key, const struct rb_node *node);
 
 static inline struct xe_vm *xe_vm_get(struct xe_vm *vm)
 {
-	kref_get(&vm->refcount);
+	drm_gpuvm_get(&vm->gpuvm);
 	return vm;
 }
 
 static inline void xe_vm_put(struct xe_vm *vm)
 {
-	kref_put(&vm->refcount, xe_vm_free);
+	drm_gpuvm_put(&vm->gpuvm);
 }
 
 int xe_vm_lock(struct xe_vm *vm, bool intr);
diff --git a/drivers/gpu/drm/xe/xe_vm_types.h b/drivers/gpu/drm/xe/xe_vm_types.h
index f11ac81cf010..d643dccf9e73 100644
--- a/drivers/gpu/drm/xe/xe_vm_types.h
+++ b/drivers/gpu/drm/xe/xe_vm_types.h
@@ -137,8 +137,6 @@ struct xe_vm {
 
 	struct xe_device *xe;
 
-	struct kref refcount;
-
 	/* exec queue used for (un)binding vma's */
 	struct xe_exec_queue *q[XE_MAX_TILES_PER_DEVICE];
 
-- 
2.41.0


  parent reply	other threads:[~2023-11-03 15:33 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-03 15:32 [Intel-xe] [CI v8 01/18] drm/gpuvm: convert WARN() to drm_WARN() variants Thomas Hellström
2023-11-03 15:32 ` [Intel-xe] [CI v8 02/18] drm/gpuvm: don't always WARN in drm_gpuvm_check_overflow() Thomas Hellström
2023-11-03 15:32 ` [Intel-xe] [CI v8 03/18] drm/gpuvm: export drm_gpuvm_range_valid() Thomas Hellström
2023-11-03 15:32 ` [Intel-xe] [CI v8 04/18] drm/nouveau: make use of drm_gpuvm_range_valid() Thomas Hellström
2023-11-03 15:32 ` [Intel-xe] [CI v8 05/18] drm/gpuvm: add common dma-resv per struct drm_gpuvm Thomas Hellström
2023-11-03 15:32 ` [Intel-xe] [CI v8 06/18] drm/xe: Adjust to "drm/gpuvm: add common dma-resv per struct drm_gpuvm" Thomas Hellström
2023-11-03 15:32 ` [Intel-xe] [CI v8 07/18] drm/nouveau: make use of the GPUVM's shared dma-resv Thomas Hellström
2023-11-03 15:32 ` [Intel-xe] [CI v8 08/18] drm/gpuvm: add drm_gpuvm_flags to drm_gpuvm Thomas Hellström
2023-11-03 15:32 ` [Intel-xe] [CI v8 09/18] drm/xe: Adjust to commit "drm/gpuvm: add drm_gpuvm_flags to drm_gpuvm" Thomas Hellström
2023-11-12 22:07   ` Dafna Hirschfeld
2023-11-03 15:32 ` [Intel-xe] [CI v8 10/18] drm/nouveau: separately allocate struct nouveau_uvmm Thomas Hellström
2023-11-03 15:32 ` [Intel-xe] [CI v8 11/18] drm/gpuvm: reference count drm_gpuvm structures Thomas Hellström
2023-11-03 15:32 ` Thomas Hellström [this message]
2023-11-13  6:14   ` [Intel-xe] [CI v8 12/18] drm/xe: Adjust to commit " Dafna Hirschfeld
2023-11-03 15:32 ` [Intel-xe] [CI v8 13/18] drm/gpuvm: add an abstraction for a VM / BO combination Thomas Hellström
2023-11-03 15:32 ` [Intel-xe] [CI v8 14/18] drm/xe: Adjust to commit "drm/gpuvm: add an abstraction for a VM/BO combination" Thomas Hellström
2023-11-12 22:06   ` Dafna Hirschfeld
2023-11-03 15:32 ` [Intel-xe] [CI v8 15/18] drm/gpuvm: track/lock/validate external/evicted objects Thomas Hellström
2023-11-03 15:32 ` [Intel-xe] [CI v8 16/18] drm/xe: Adapt to GPUVM tracking of external / evicted objects Thomas Hellström
2023-11-03 15:32 ` [Intel-xe] [CI v8 17/18] drm/xe: Use DRM_GPUVM_RESV_PROTECTED for gpuvm Thomas Hellström
2023-11-03 15:32 ` [Intel-xe] [CI v8 18/18] drm/nouveau: use GPUVM common infrastructure Thomas Hellström
2023-11-03 15:35 ` [Intel-xe] ✓ CI.Patch_applied: success for series starting with [CI,v8,01/18] drm/gpuvm: convert WARN() to drm_WARN() variants Patchwork
2023-11-03 15:36 ` [Intel-xe] ✗ CI.checkpatch: warning " Patchwork
2023-11-03 15:37 ` [Intel-xe] ✓ CI.KUnit: success " Patchwork
2023-11-03 15:44 ` [Intel-xe] ✓ CI.Build: " Patchwork
2023-11-03 15:45 ` [Intel-xe] ✓ CI.Hooks: " Patchwork
2023-11-03 15:46 ` [Intel-xe] ✗ CI.checksparse: warning " Patchwork
2023-11-03 16:19 ` [Intel-xe] ✗ CI.BAT: failure " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231103153234.30407-12-thomas.hellstrom@linux.intel.com \
    --to=thomas.hellstrom@linux.intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.