Commit 7ef6b7f8 authored by Kent Russell's avatar Kent Russell Committed by Alex Deucher

drm/amdgpu: Make sure to reserve BOs before adding or removing

BOs need to be reserved before they are added or removed, so ensure that
they are reserved during kfd_mem_attach and kfd_mem_detach
Signed-off-by: default avatarKent Russell <kent.russell@amd.com>
Reviewed-by: default avatarFelix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent a6283010
...@@ -734,14 +734,19 @@ static int kfd_mem_attach(struct amdgpu_device *adev, struct kgd_mem *mem, ...@@ -734,14 +734,19 @@ static int kfd_mem_attach(struct amdgpu_device *adev, struct kgd_mem *mem,
} }
/* Add BO to VM internal data structures */ /* Add BO to VM internal data structures */
ret = amdgpu_bo_reserve(bo[i], false);
if (ret) {
pr_debug("Unable to reserve BO during memory attach");
goto unwind;
}
attachment[i]->bo_va = amdgpu_vm_bo_add(adev, vm, bo[i]); attachment[i]->bo_va = amdgpu_vm_bo_add(adev, vm, bo[i]);
amdgpu_bo_unreserve(bo[i]);
if (unlikely(!attachment[i]->bo_va)) { if (unlikely(!attachment[i]->bo_va)) {
ret = -ENOMEM; ret = -ENOMEM;
pr_err("Failed to add BO object to VM. ret == %d\n", pr_err("Failed to add BO object to VM. ret == %d\n",
ret); ret);
goto unwind; goto unwind;
} }
attachment[i]->va = va; attachment[i]->va = va;
attachment[i]->pte_flags = get_pte_flags(adev, mem); attachment[i]->pte_flags = get_pte_flags(adev, mem);
attachment[i]->adev = adev; attachment[i]->adev = adev;
...@@ -757,7 +762,9 @@ static int kfd_mem_attach(struct amdgpu_device *adev, struct kgd_mem *mem, ...@@ -757,7 +762,9 @@ static int kfd_mem_attach(struct amdgpu_device *adev, struct kgd_mem *mem,
if (!attachment[i]) if (!attachment[i])
continue; continue;
if (attachment[i]->bo_va) { if (attachment[i]->bo_va) {
amdgpu_bo_reserve(bo[i], true);
amdgpu_vm_bo_rmv(adev, attachment[i]->bo_va); amdgpu_vm_bo_rmv(adev, attachment[i]->bo_va);
amdgpu_bo_unreserve(bo[i]);
list_del(&attachment[i]->list); list_del(&attachment[i]->list);
} }
if (bo[i]) if (bo[i])
...@@ -1568,12 +1575,12 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu( ...@@ -1568,12 +1575,12 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu(
pr_debug("Release VA 0x%llx - 0x%llx\n", mem->va, pr_debug("Release VA 0x%llx - 0x%llx\n", mem->va,
mem->va + bo_size * (1 + mem->aql_queue)); mem->va + bo_size * (1 + mem->aql_queue));
ret = unreserve_bo_and_vms(&ctx, false, false);
/* Remove from VM internal data structures */ /* Remove from VM internal data structures */
list_for_each_entry_safe(entry, tmp, &mem->attachments, list) list_for_each_entry_safe(entry, tmp, &mem->attachments, list)
kfd_mem_detach(entry); kfd_mem_detach(entry);
ret = unreserve_bo_and_vms(&ctx, false, false);
/* Free the sync object */ /* Free the sync object */
amdgpu_sync_free(&mem->sync); amdgpu_sync_free(&mem->sync);
......
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