Commit 727ffdf2 authored by Christian König's avatar Christian König Committed by Alex Deucher
Browse files

drm/amdgpu: fix VM faults with per VM BOs



There was a small window between unreserve and second reserve where the
freshly allocated BO could have been evicted without the VM noticing it.

Signed-off-by: default avatarChristian König <christian.koenig@amd.com>
Reviewed-by: default avatarChunming Zhou <david1.zhou@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent 6a83a553
Loading
Loading
Loading
Loading
+20 −2
Original line number Diff line number Diff line
@@ -1745,9 +1745,27 @@ struct amdgpu_bo_va *amdgpu_vm_bo_add(struct amdgpu_device *adev,
	INIT_LIST_HEAD(&bo_va->valids);
	INIT_LIST_HEAD(&bo_va->invalids);

	if (bo)
	if (!bo)
		return bo_va;

	list_add_tail(&bo_va->base.bo_list, &bo->va);

	if (bo->tbo.resv != vm->root.base.bo->tbo.resv)
		return bo_va;

	if (bo->preferred_domains &
	    amdgpu_mem_type_to_domain(bo->tbo.mem.mem_type))
		return bo_va;

	/*
	 * We checked all the prerequisites, but it looks like this per VM BO
	 * is currently evicted. add the BO to the evicted list to make sure it
	 * is validated on next VM use to avoid fault.
	 * */
	spin_lock(&vm->status_lock);
	list_move_tail(&bo_va->base.vm_status, &vm->evicted);
	spin_unlock(&vm->status_lock);

	return bo_va;
}