Skip to content

Commit 0cd9904

Browse files
committed
drm/xe: Add vm snapshot mutex for easily taking a vm snapshot during devcoredump
The devcoredump is done in fence signaling context. Because of this, we cannot take any of the normal mutexes or we would invert. Normal: Take vm->lock, dma_fence_wait() Devcoredump: from dma_fence_wait() context, take vm->lock. This doesn't work, and we only care about integrity, so take the locks around additions and removals of vma's. Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com> Reviewed-by: José Roberto de Souza <jose.souza@intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20240221133024.898315-5-maarten.lankhorst@linux.intel.com
1 parent ffb7249 commit 0cd9904

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

drivers/gpu/drm/xe/xe_vm.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,9 @@ static int xe_vm_insert_vma(struct xe_vm *vm, struct xe_vma *vma)
10551055
xe_assert(vm->xe, xe_vma_vm(vma) == vm);
10561056
lockdep_assert_held(&vm->lock);
10571057

1058+
mutex_lock(&vm->snap_mutex);
10581059
err = drm_gpuva_insert(&vm->gpuvm, &vma->gpuva);
1060+
mutex_unlock(&vm->snap_mutex);
10591061
XE_WARN_ON(err); /* Shouldn't be possible */
10601062

10611063
return err;
@@ -1066,7 +1068,9 @@ static void xe_vm_remove_vma(struct xe_vm *vm, struct xe_vma *vma)
10661068
xe_assert(vm->xe, xe_vma_vm(vma) == vm);
10671069
lockdep_assert_held(&vm->lock);
10681070

1071+
mutex_lock(&vm->snap_mutex);
10691072
drm_gpuva_remove(&vma->gpuva);
1073+
mutex_unlock(&vm->snap_mutex);
10701074
if (vm->usm.last_fault_vma == vma)
10711075
vm->usm.last_fault_vma = NULL;
10721076
}
@@ -1293,6 +1297,7 @@ struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags)
12931297
vm->flags = flags;
12941298

12951299
init_rwsem(&vm->lock);
1300+
mutex_init(&vm->snap_mutex);
12961301

12971302
INIT_LIST_HEAD(&vm->rebind_list);
12981303

@@ -1418,6 +1423,7 @@ struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags)
14181423
return ERR_PTR(err);
14191424

14201425
err_no_resv:
1426+
mutex_destroy(&vm->snap_mutex);
14211427
for_each_tile(tile, xe, id)
14221428
xe_range_fence_tree_fini(&vm->rftree[id]);
14231429
kfree(vm);
@@ -1517,6 +1523,8 @@ void xe_vm_close_and_put(struct xe_vm *vm)
15171523

15181524
up_write(&vm->lock);
15191525

1526+
mutex_destroy(&vm->snap_mutex);
1527+
15201528
mutex_lock(&xe->usm.lock);
15211529
if (vm->flags & XE_VM_FLAG_FAULT_MODE)
15221530
xe->usm.num_vm_in_fault_mode--;

drivers/gpu/drm/xe/xe_vm_types.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ struct xe_vm {
160160
* VM
161161
*/
162162
struct rw_semaphore lock;
163+
/**
164+
* @snap_mutex: Mutex used to guard insertions and removals from gpuva,
165+
* so we can take a snapshot safely from devcoredump.
166+
*/
167+
struct mutex snap_mutex;
163168

164169
/**
165170
* @rebind_list: list of VMAs that need rebinding. Protected by the

0 commit comments

Comments
 (0)