Commit e2ad8e2d authored by Christian König's avatar Christian König Committed by Alex Deucher

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: default avatarChristian König <christian.koenig@amd.com>
Reviewed-by: default avatarAlex Deucher <alexander.deucher@amd.com>
Acked-by: default avatarGuchun Chen <guchun.chen@amd.com>
Tested-by: default avatarMikhail Gavrilov <mikhail.v.gavrilov@gmail.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent 43aedbf4
...@@ -920,42 +920,51 @@ int amdgpu_vm_update_range(struct amdgpu_device *adev, struct amdgpu_vm *vm, ...@@ -920,42 +920,51 @@ int amdgpu_vm_update_range(struct amdgpu_device *adev, struct amdgpu_vm *vm,
return r; return r;
} }
static void amdgpu_vm_bo_get_memory(struct amdgpu_bo_va *bo_va,
struct amdgpu_mem_stats *stats)
{
struct amdgpu_vm *vm = bo_va->base.vm;
struct amdgpu_bo *bo = bo_va->base.bo;
if (!bo)
return;
/*
* For now ignore BOs which are currently locked and potentially
* changing their location.
*/
if (bo->tbo.base.resv != vm->root.bo->tbo.base.resv &&
!dma_resv_trylock(bo->tbo.base.resv))
return;
amdgpu_bo_get_memory(bo, stats);
if (bo->tbo.base.resv != vm->root.bo->tbo.base.resv)
dma_resv_unlock(bo->tbo.base.resv);
}
void amdgpu_vm_get_memory(struct amdgpu_vm *vm, void amdgpu_vm_get_memory(struct amdgpu_vm *vm,
struct amdgpu_mem_stats *stats) struct amdgpu_mem_stats *stats)
{ {
struct amdgpu_bo_va *bo_va, *tmp; struct amdgpu_bo_va *bo_va, *tmp;
spin_lock(&vm->status_lock); spin_lock(&vm->status_lock);
list_for_each_entry_safe(bo_va, tmp, &vm->idle, base.vm_status) { list_for_each_entry_safe(bo_va, tmp, &vm->idle, base.vm_status)
if (!bo_va->base.bo) amdgpu_vm_bo_get_memory(bo_va, stats);
continue;
amdgpu_bo_get_memory(bo_va->base.bo, stats); list_for_each_entry_safe(bo_va, tmp, &vm->evicted, base.vm_status)
} amdgpu_vm_bo_get_memory(bo_va, stats);
list_for_each_entry_safe(bo_va, tmp, &vm->evicted, base.vm_status) {
if (!bo_va->base.bo) list_for_each_entry_safe(bo_va, tmp, &vm->relocated, base.vm_status)
continue; amdgpu_vm_bo_get_memory(bo_va, stats);
amdgpu_bo_get_memory(bo_va->base.bo, stats);
} list_for_each_entry_safe(bo_va, tmp, &vm->moved, base.vm_status)
list_for_each_entry_safe(bo_va, tmp, &vm->relocated, base.vm_status) { amdgpu_vm_bo_get_memory(bo_va, stats);
if (!bo_va->base.bo)
continue; list_for_each_entry_safe(bo_va, tmp, &vm->invalidated, base.vm_status)
amdgpu_bo_get_memory(bo_va->base.bo, stats); amdgpu_vm_bo_get_memory(bo_va, stats);
}
list_for_each_entry_safe(bo_va, tmp, &vm->moved, base.vm_status) { list_for_each_entry_safe(bo_va, tmp, &vm->done, base.vm_status)
if (!bo_va->base.bo) amdgpu_vm_bo_get_memory(bo_va, stats);
continue;
amdgpu_bo_get_memory(bo_va->base.bo, stats);
}
list_for_each_entry_safe(bo_va, tmp, &vm->invalidated, base.vm_status) {
if (!bo_va->base.bo)
continue;
amdgpu_bo_get_memory(bo_va->base.bo, stats);
}
list_for_each_entry_safe(bo_va, tmp, &vm->done, base.vm_status) {
if (!bo_va->base.bo)
continue;
amdgpu_bo_get_memory(bo_va->base.bo, stats);
}
spin_unlock(&vm->status_lock); spin_unlock(&vm->status_lock);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment