xe_vm_close() uses drm_dev_enter(), which only checks unplug. After a
permanent wedge, VM close can still write page tables in VRAM and request
TLB invalidation.

Use xe_device_io_get() around page-table clearing and TLB invalidation.
Skip these operations when device I/O is blocked or unplugged, while
still closing the VM and running software cleanup.

Take the gate after the pending-bind fence wait. Isolation waits for
hardware cleanup admitted before the block, without including that
fence wait in this function's gate.

Cc: Matthew Brost <[email protected]>
Cc: Thomas Hellström <[email protected]>
Cc: Himal Prasad Ghimiray <[email protected]>
Cc: Rodrigo Vivi <[email protected]>
Assisted-by: LLM
Suggested-by: Thomas Hellström <[email protected]>
Signed-off-by: Arvind Yadav <[email protected]>
---
 drivers/gpu/drm/xe/xe_vm.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c
index 645c5e906224..0a8dfe23cc20 100644
--- a/drivers/gpu/drm/xe/xe_vm.c
+++ b/drivers/gpu/drm/xe/xe_vm.c
@@ -1932,11 +1932,8 @@ struct xe_vm *xe_vm_create(struct xe_device *xe, u32 
flags, struct xe_file *xef)
 static void xe_vm_close(struct xe_vm *vm)
 {
        struct xe_device *xe = vm->xe;
-       bool bound;
        int idx;
 
-       bound = drm_dev_enter(&xe->drm, &idx);
-
        down_write(&vm->lock);
        xe_vm_lock(vm, false);
 
@@ -1955,13 +1952,15 @@ static void xe_vm_close(struct xe_vm *vm)
                                      DMA_RESV_USAGE_BOOKKEEP,
                                      false, MAX_SCHEDULE_TIMEOUT);
 
-               if (bound) {
+               if (!xe_device_io_get(xe, &idx)) {
                        for_each_tile(tile, xe, id)
                                if (vm->pt_root[id])
                                        xe_pt_clear(xe, vm->pt_root[id]);
 
                        for_each_gt(gt, xe, id)
                                xe_tlb_inval_vm(&gt->tlb_inval, vm);
+
+                       xe_device_io_put(idx);
                }
        }
 
@@ -1970,9 +1969,6 @@ static void xe_vm_close(struct xe_vm *vm)
 
        xe_vm_unlock(vm);
        up_write(&vm->lock);
-
-       if (bound)
-               drm_dev_exit(idx);
 }
 
 void xe_vm_close_and_put(struct xe_vm *vm)
-- 
2.43.0

Reply via email to