drm/amdgpu: Make sure to reserve BOs before adding or removing
Subsystems (3)
PATCH 1/2 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 Kent Russell <[email protected]>
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +10 -3
@@ -798,14 +798,19 @@ static int kfd_mem_attach(struct amdgpu_device *adev, struct kgd_mem *mem, }/* 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]); +amdgpu_bo_unreserve (bo[i]);if (unlikely (!attachment[i]->bo_va)) { ret = -ENOMEM ;pr_err ("Failed to add BO object to VM. ret == %d\n" , ret); goto unwind; } - attachment[i]->va = va; attachment[i]->pte_flags =get_pte_flags (adev, mem); attachment[i]->adev = adev;
@@ -821,7 +826,9 @@ static int kfd_mem_attach(struct amdgpu_device *adev, struct kgd_mem *mem,if (!attachment[i])continue ;if (attachment[i]->bo_va) { +amdgpu_bo_reserve (bo[i], true);amdgpu_vm_bo_rmv (adev, attachment[i]->bo_va); +amdgpu_bo_unreserve (bo[i]);list_del (&attachment[i]->list); }if (bo[i])
@@ -1700,12 +1707,12 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu(pr_debug ("Release VA 0x%llx - 0x%llx\n" , mem->va, mem->va + bo_size * (1 + mem->aql_queue)); - ret =unreserve_bo_and_vms (&ctx, false, false); -/* Remove from VM internal data structures */ list_for_each_entry_safe (entry, tmp, &mem->attachments, list)kfd_mem_detach (entry); + ret =unreserve_bo_and_vms (&ctx, false, false); +/* Free the sync object */ amdgpu_sync_free (&mem->sync);
Signature · 1 line
2.25.1
PATCH 2/2 drm/amdgpu: Temporary exclude GTT BOs from KFD memory attachment
kfd_mem_attach is not sharing GTT BOs correctly between processes. This can cause kernel panics due to NULL pointers depending on which processes hold references to specific GTT BOs. Temporarily disable this functionality for now while a proper code refactor and proper fix is done.
Note that since we don't fully support IOMMU in device-isolation mode at this time, this temporary workaround won't break anything that isn't already broken.
Signed-off-by Kent Russell <[email protected]>
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +2 -0
@@ -769,6 +769,7 @@ static int kfd_mem_attach(struct amdgpu_device *adev, struct kgd_mem *mem, ret =kfd_mem_attach_userptr (adev, mem, &bo[i]);if (ret) goto unwind; +#if 0 #ifdef AMDKCL_AMDGPU_DMABUF_OPS } else if (mem->domain == AMDGPU_GEM_DOMAIN_GTT && mem->bo->tbo.type != ttm_bo_type_sg) {
@@ -780,6 +781,7 @@ static int kfd_mem_attach(struct amdgpu_device *adev, struct kgd_mem *mem, ret =kfd_mem_attach_dmabuf (adev, mem, &bo[i]);if (ret) goto unwind; +#endif #endif /* Enable peer acces to VRAM BO's */ } else if (mem->domain == AMDGPU_GEM_DOMAIN_VRAM &&
Signature · 1 line
2.25.1