Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] drm/xe/vm: Hold a device reference until VM teardown completes
@ 2026-11-23  8:14 Sanjay Yadav
  2026-11-23  8:32 ` ✗ CI.KUnit: failure for " Patchwork
  2026-11-23  8:35 ` [PATCH v2] " sashiko-bot
  0 siblings, 2 replies; 3+ messages in thread
From: Sanjay Yadav @ 2026-11-23  8:14 UTC (permalink / raw)
  To: intel-xe
  Cc: Matthew Brost, Thomas Hellström, Himal Prasad Ghimiray,
	Tejas Upadhyay

Since drm_gpuvm holds a device reference, the last VM put can drop the
last device reference and run device teardown in that context. Two such
contexts are workers that teardown itself waits for:

  The async BO free worker, freeing a page-table BO, flushes itself
  from xe_bo_dev_fini():

  WARNING: possible recursive locking detected
  kworker/7:0/50249 is trying to acquire lock:
  ((work_completion)(&bo_dev->async_free)), at: __flush_work+0x25d/0x640
  but task is already holding lock:
  ((work_completion)(&bo_dev->async_free)), at: process_one_work+0x26d/0x890
  ...
  Workqueue: events xe_bo_dev_work_func [xe]
  Call Trace:
   flush_work+0x2d/0x40
   xe_bo_dev_fini+0xe/0x20 [xe]
   xe_device_destroy+0x19/0xa0 [xe]
   drm_managed_release+0x8b/0x170
   drm_dev_put+0x69/0x90
   drm_gpuvm_free+0xc2/0x2e0 [drm_gpuvm]
   drm_gpuvm_put+0x48/0x80 [drm_gpuvm]
   xe_ttm_bo_destroy+0xfa/0x320 [xe]
   ttm_bo_release+0x70/0x310 [ttm]
   ttm_bo_fini+0x3c/0x70 [ttm]
   xe_gem_object_free+0x1a/0x30 [xe]
   drm_gem_object_free+0x1d/0x40
   xe_bo_dev_work_func+0x3a/0x60 [xe]

TTM's delayed delete worker drains its own workqueue from
ttm_device_fini(), and xe_ttm_bo_destroy() then uses the freed
xe_device.

Take a device reference in xe_vm_free() and drop it at the end of
vm_destroy_work_func(), so a VM put never drops the last device
reference. Queue the destroy work on the module-lifetime xe_destroy_wq,
as xe->destroy_wq is destroyed by device teardown.

v2:
- Replace v1 with a single fix in xe_vm_free(), which also covers TTM
  delayed delete (Sashiko).
- Drop the xe_bo_dev_fini() inline free and the async free wq move
  (Sashiko).
- Add Fixes: c2d72717e0a9.


Fixes: c2d72717e0a9 ("drm/gpuvm: take refcount on DRM device")
Fixes: 0e33330f1238 ("drm/xe: Add struct xe_pt_job_ops")
Cc: Matthew Brost <matthew.brost@intel.com>
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Cc: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
Cc: Tejas Upadhyay <tejas.upadhyay@intel.com>
Signed-off-by: Sanjay Yadav <sanjay.kumar.yadav@intel.com>
---
 drivers/gpu/drm/xe/xe_vm.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c
index dd855876f571..bd589b1268eb 100644
--- a/drivers/gpu/drm/xe/xe_vm.c
+++ b/drivers/gpu/drm/xe/xe_vm.c
@@ -2109,6 +2109,9 @@ static void vm_destroy_work_func(struct work_struct *w)
 		xe_file_put(vm->xef);
 
 	kfree(vm);
+
+	/* Pairs with xe_vm_free(), may run device teardown. */
+	drm_dev_put(&xe->drm);
 }
 
 static void xe_vm_free(struct drm_gpuvm *gpuvm)
@@ -2116,11 +2119,12 @@ static void xe_vm_free(struct drm_gpuvm *gpuvm)
 	struct xe_vm *vm = container_of(gpuvm, struct xe_vm, gpuvm);
 
 	/*
-	 * To destroy the VM we need to be able to sleep.
-	 * drm_gpuvm keeps at least one device reference at this
-	 * point so xe->destroy_wq must still be alive.
+	 * Destroy needs to sleep. Hold a device ref until it is done so a VM
+	 * put can't drop the last one, and use xe_destroy_wq since
+	 * xe->destroy_wq goes away with the device.
 	 */
-	queue_work(vm->xe->destroy_wq, &vm->destroy_work);
+	drm_dev_get(&vm->xe->drm);
+	xe_destroy_wq_queue(&vm->destroy_work);
 }
 
 struct xe_vm *xe_vm_lookup(struct xe_file *xef, u32 id)
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-23  8:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23  8:14 [PATCH v2] drm/xe/vm: Hold a device reference until VM teardown completes Sanjay Yadav
2026-11-23  8:32 ` ✗ CI.KUnit: failure for " Patchwork
2026-11-23  8:35 ` [PATCH v2] " sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox