Skip to content

Commit e2ad8e2

Browse files
ChristianKoenigAMDalexdeucher
authored andcommitted
drm/amdgpu: make sure BOs are locked in amdgpu_vm_get_memory
We need to grab the lock of the BO or otherwise can run into a crash when we try to inspect the current location. Signed-off-by: Christian König <christian.koenig@amd.com> Reviewed-by: Alex Deucher <alexander.deucher@amd.com> Acked-by: Guchun Chen <guchun.chen@amd.com> Tested-by: Mikhail Gavrilov <mikhail.v.gavrilov@gmail.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
1 parent 43aedbf commit e2ad8e2

1 file changed

Lines changed: 39 additions & 30 deletions

File tree

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -920,42 +920,51 @@ int amdgpu_vm_update_range(struct amdgpu_device *adev, struct amdgpu_vm *vm,
920920
return r;
921921
}
922922

923+
static void amdgpu_vm_bo_get_memory(struct amdgpu_bo_va *bo_va,
924+
struct amdgpu_mem_stats *stats)
925+
{
926+
struct amdgpu_vm *vm = bo_va->base.vm;
927+
struct amdgpu_bo *bo = bo_va->base.bo;
928+
929+
if (!bo)
930+
return;
931+
932+
/*
933+
* For now ignore BOs which are currently locked and potentially
934+
* changing their location.
935+
*/
936+
if (bo->tbo.base.resv != vm->root.bo->tbo.base.resv &&
937+
!dma_resv_trylock(bo->tbo.base.resv))
938+
return;
939+
940+
amdgpu_bo_get_memory(bo, stats);
941+
if (bo->tbo.base.resv != vm->root.bo->tbo.base.resv)
942+
dma_resv_unlock(bo->tbo.base.resv);
943+
}
944+
923945
void amdgpu_vm_get_memory(struct amdgpu_vm *vm,
924946
struct amdgpu_mem_stats *stats)
925947
{
926948
struct amdgpu_bo_va *bo_va, *tmp;
927949

928950
spin_lock(&vm->status_lock);
929-
list_for_each_entry_safe(bo_va, tmp, &vm->idle, base.vm_status) {
930-
if (!bo_va->base.bo)
931-
continue;
932-
amdgpu_bo_get_memory(bo_va->base.bo, stats);
933-
}
934-
list_for_each_entry_safe(bo_va, tmp, &vm->evicted, base.vm_status) {
935-
if (!bo_va->base.bo)
936-
continue;
937-
amdgpu_bo_get_memory(bo_va->base.bo, stats);
938-
}
939-
list_for_each_entry_safe(bo_va, tmp, &vm->relocated, base.vm_status) {
940-
if (!bo_va->base.bo)
941-
continue;
942-
amdgpu_bo_get_memory(bo_va->base.bo, stats);
943-
}
944-
list_for_each_entry_safe(bo_va, tmp, &vm->moved, base.vm_status) {
945-
if (!bo_va->base.bo)
946-
continue;
947-
amdgpu_bo_get_memory(bo_va->base.bo, stats);
948-
}
949-
list_for_each_entry_safe(bo_va, tmp, &vm->invalidated, base.vm_status) {
950-
if (!bo_va->base.bo)
951-
continue;
952-
amdgpu_bo_get_memory(bo_va->base.bo, stats);
953-
}
954-
list_for_each_entry_safe(bo_va, tmp, &vm->done, base.vm_status) {
955-
if (!bo_va->base.bo)
956-
continue;
957-
amdgpu_bo_get_memory(bo_va->base.bo, stats);
958-
}
951+
list_for_each_entry_safe(bo_va, tmp, &vm->idle, base.vm_status)
952+
amdgpu_vm_bo_get_memory(bo_va, stats);
953+
954+
list_for_each_entry_safe(bo_va, tmp, &vm->evicted, base.vm_status)
955+
amdgpu_vm_bo_get_memory(bo_va, stats);
956+
957+
list_for_each_entry_safe(bo_va, tmp, &vm->relocated, base.vm_status)
958+
amdgpu_vm_bo_get_memory(bo_va, stats);
959+
960+
list_for_each_entry_safe(bo_va, tmp, &vm->moved, base.vm_status)
961+
amdgpu_vm_bo_get_memory(bo_va, stats);
962+
963+
list_for_each_entry_safe(bo_va, tmp, &vm->invalidated, base.vm_status)
964+
amdgpu_vm_bo_get_memory(bo_va, stats);
965+
966+
list_for_each_entry_safe(bo_va, tmp, &vm->done, base.vm_status)
967+
amdgpu_vm_bo_get_memory(bo_va, stats);
959968
spin_unlock(&vm->status_lock);
960969
}
961970

0 commit comments

Comments
 (0)