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

drm/amdgpu: add VM eviction lock v3

This allows to invalidate VM entries without taking the reservation lock.

v3: use -EBUSY
Signed-off-by: default avatarChristian König <christian.koenig@amd.com>
Reviewed-by: default avatarFelix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent 90b69cdc
...@@ -656,7 +656,7 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, ...@@ -656,7 +656,7 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm,
void *param) void *param)
{ {
struct amdgpu_vm_bo_base *bo_base, *tmp; struct amdgpu_vm_bo_base *bo_base, *tmp;
int r = 0; int r;
vm->bulk_moveable &= list_empty(&vm->evicted); vm->bulk_moveable &= list_empty(&vm->evicted);
...@@ -665,7 +665,7 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, ...@@ -665,7 +665,7 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm,
r = validate(param, bo); r = validate(param, bo);
if (r) if (r)
break; return r;
if (bo->tbo.type != ttm_bo_type_kernel) { if (bo->tbo.type != ttm_bo_type_kernel) {
amdgpu_vm_bo_moved(bo_base); amdgpu_vm_bo_moved(bo_base);
...@@ -678,7 +678,11 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, ...@@ -678,7 +678,11 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm,
} }
} }
return r; mutex_lock(&vm->eviction_lock);
vm->evicting = false;
mutex_unlock(&vm->eviction_lock);
return 0;
} }
/** /**
...@@ -1555,15 +1559,25 @@ static int amdgpu_vm_bo_update_mapping(struct amdgpu_device *adev, ...@@ -1555,15 +1559,25 @@ static int amdgpu_vm_bo_update_mapping(struct amdgpu_device *adev,
if (!(flags & AMDGPU_PTE_VALID)) if (!(flags & AMDGPU_PTE_VALID))
owner = AMDGPU_FENCE_OWNER_KFD; owner = AMDGPU_FENCE_OWNER_KFD;
mutex_lock(&vm->eviction_lock);
if (vm->evicting) {
r = -EBUSY;
goto error_unlock;
}
r = vm->update_funcs->prepare(&params, owner, exclusive); r = vm->update_funcs->prepare(&params, owner, exclusive);
if (r) if (r)
return r; goto error_unlock;
r = amdgpu_vm_update_ptes(&params, start, last + 1, addr, flags); r = amdgpu_vm_update_ptes(&params, start, last + 1, addr, flags);
if (r) if (r)
return r; goto error_unlock;
return vm->update_funcs->commit(&params, fence); r = vm->update_funcs->commit(&params, fence);
error_unlock:
mutex_unlock(&vm->eviction_lock);
return r;
} }
/** /**
...@@ -2518,11 +2532,19 @@ bool amdgpu_vm_evictable(struct amdgpu_bo *bo) ...@@ -2518,11 +2532,19 @@ bool amdgpu_vm_evictable(struct amdgpu_bo *bo)
if (!dma_resv_test_signaled_rcu(bo->tbo.base.resv, true)) if (!dma_resv_test_signaled_rcu(bo->tbo.base.resv, true))
return false; return false;
/* Try to block ongoing updates */
if (!mutex_trylock(&bo_base->vm->eviction_lock))
return false;
/* Don't evict VM page tables while they are updated */ /* Don't evict VM page tables while they are updated */
if (!dma_fence_is_signaled(bo_base->vm->last_direct) || if (!dma_fence_is_signaled(bo_base->vm->last_direct) ||
!dma_fence_is_signaled(bo_base->vm->last_delayed)) !dma_fence_is_signaled(bo_base->vm->last_delayed)) {
mutex_unlock(&bo_base->vm->eviction_lock);
return false; return false;
}
bo_base->vm->evicting = true;
mutex_unlock(&bo_base->vm->eviction_lock);
return true; return true;
} }
...@@ -2769,6 +2791,9 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, ...@@ -2769,6 +2791,9 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
vm->last_direct = dma_fence_get_stub(); vm->last_direct = dma_fence_get_stub();
vm->last_delayed = dma_fence_get_stub(); vm->last_delayed = dma_fence_get_stub();
mutex_init(&vm->eviction_lock);
vm->evicting = false;
amdgpu_vm_bo_param(adev, vm, adev->vm_manager.root_level, false, &bp); amdgpu_vm_bo_param(adev, vm, adev->vm_manager.root_level, false, &bp);
if (vm_context == AMDGPU_VM_CONTEXT_COMPUTE) if (vm_context == AMDGPU_VM_CONTEXT_COMPUTE)
bp.flags &= ~AMDGPU_GEM_CREATE_SHADOW; bp.flags &= ~AMDGPU_GEM_CREATE_SHADOW;
......
...@@ -239,6 +239,10 @@ struct amdgpu_vm { ...@@ -239,6 +239,10 @@ struct amdgpu_vm {
/* tree of virtual addresses mapped */ /* tree of virtual addresses mapped */
struct rb_root_cached va; struct rb_root_cached va;
/* Lock to prevent eviction while we are updating page tables */
struct mutex eviction_lock;
bool evicting;
/* BOs who needs a validation */ /* BOs who needs a validation */
struct list_head evicted; struct list_head evicted;
......
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