Commit 88f7f881 authored by Nirmoy Das's avatar Nirmoy Das Committed by Alex Deucher

drm/amdgpu: separate out vm pasid assignment

Use new helper function amdgpu_vm_set_pasid() to
assign vm pasid value. This also ensures that we don't free
a pasid from vm code as pasids are allocated somewhere else.
Signed-off-by: default avatarNirmoy Das <nirmoy.das@amd.com>
Acked-by: default avatarFelix Kuehling <Felix.Kuehling@amd.com>
Reviewed-by: default avatarChristian König <christian.koenig@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent dcb388ed
...@@ -1287,11 +1287,22 @@ int amdgpu_amdkfd_gpuvm_acquire_process_vm(struct kgd_dev *kgd, ...@@ -1287,11 +1287,22 @@ int amdgpu_amdkfd_gpuvm_acquire_process_vm(struct kgd_dev *kgd,
if (avm->process_info) if (avm->process_info)
return -EINVAL; return -EINVAL;
/* Free the original amdgpu allocated pasid,
* will be replaced with kfd allocated pasid.
*/
if (avm->pasid) {
amdgpu_pasid_free(avm->pasid);
amdgpu_vm_set_pasid(adev, avm, 0);
}
/* Convert VM into a compute VM */ /* Convert VM into a compute VM */
ret = amdgpu_vm_make_compute(adev, avm, pasid); ret = amdgpu_vm_make_compute(adev, avm);
if (ret) if (ret)
return ret; return ret;
ret = amdgpu_vm_set_pasid(adev, avm, pasid);
if (ret)
return ret;
/* Initialize KFD part of the VM and process info */ /* Initialize KFD part of the VM and process info */
ret = init_kfd_vm(avm, process_info, ef); ret = init_kfd_vm(avm, process_info, ef);
if (ret) if (ret)
......
...@@ -1179,10 +1179,14 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv) ...@@ -1179,10 +1179,14 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
pasid = 0; pasid = 0;
} }
r = amdgpu_vm_init(adev, &fpriv->vm, pasid); r = amdgpu_vm_init(adev, &fpriv->vm);
if (r) if (r)
goto error_pasid; goto error_pasid;
r = amdgpu_vm_set_pasid(adev, &fpriv->vm, pasid);
if (r)
goto error_vm;
fpriv->prt_va = amdgpu_vm_bo_add(adev, &fpriv->vm, NULL); fpriv->prt_va = amdgpu_vm_bo_add(adev, &fpriv->vm, NULL);
if (!fpriv->prt_va) { if (!fpriv->prt_va) {
r = -ENOMEM; r = -ENOMEM;
...@@ -1210,8 +1214,10 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv) ...@@ -1210,8 +1214,10 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
amdgpu_vm_fini(adev, &fpriv->vm); amdgpu_vm_fini(adev, &fpriv->vm);
error_pasid: error_pasid:
if (pasid) if (pasid) {
amdgpu_pasid_free(pasid); amdgpu_pasid_free(pasid);
amdgpu_vm_set_pasid(adev, &fpriv->vm, 0);
}
kfree(fpriv); kfree(fpriv);
......
...@@ -2904,14 +2904,13 @@ long amdgpu_vm_wait_idle(struct amdgpu_vm *vm, long timeout) ...@@ -2904,14 +2904,13 @@ long amdgpu_vm_wait_idle(struct amdgpu_vm *vm, long timeout)
* *
* @adev: amdgpu_device pointer * @adev: amdgpu_device pointer
* @vm: requested vm * @vm: requested vm
* @pasid: Process address space identifier
* *
* Init @vm fields. * Init @vm fields.
* *
* Returns: * Returns:
* 0 for success, error for failure. * 0 for success, error for failure.
*/ */
int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, u32 pasid) int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm)
{ {
struct amdgpu_bo *root_bo; struct amdgpu_bo *root_bo;
struct amdgpu_bo_vm *root; struct amdgpu_bo_vm *root;
...@@ -2985,10 +2984,6 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, u32 pasid) ...@@ -2985,10 +2984,6 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, u32 pasid)
amdgpu_bo_unreserve(vm->root.bo); amdgpu_bo_unreserve(vm->root.bo);
r = amdgpu_vm_set_pasid(adev, vm, pasid);
if (r)
goto error_free_root;
INIT_KFIFO(vm->faults); INIT_KFIFO(vm->faults);
return 0; return 0;
...@@ -3044,7 +3039,6 @@ static int amdgpu_vm_check_clean_reserved(struct amdgpu_device *adev, ...@@ -3044,7 +3039,6 @@ static int amdgpu_vm_check_clean_reserved(struct amdgpu_device *adev,
* *
* @adev: amdgpu_device pointer * @adev: amdgpu_device pointer
* @vm: requested vm * @vm: requested vm
* @pasid: pasid to use
* *
* This only works on GFX VMs that don't have any BOs added and no * This only works on GFX VMs that don't have any BOs added and no
* page tables allocated yet. * page tables allocated yet.
...@@ -3052,7 +3046,6 @@ static int amdgpu_vm_check_clean_reserved(struct amdgpu_device *adev, ...@@ -3052,7 +3046,6 @@ static int amdgpu_vm_check_clean_reserved(struct amdgpu_device *adev,
* Changes the following VM parameters: * Changes the following VM parameters:
* - use_cpu_for_update * - use_cpu_for_update
* - pte_supports_ats * - pte_supports_ats
* - pasid (old PASID is released, because compute manages its own PASIDs)
* *
* Reinitializes the page directory to reflect the changed ATS * Reinitializes the page directory to reflect the changed ATS
* setting. * setting.
...@@ -3060,8 +3053,7 @@ static int amdgpu_vm_check_clean_reserved(struct amdgpu_device *adev, ...@@ -3060,8 +3053,7 @@ static int amdgpu_vm_check_clean_reserved(struct amdgpu_device *adev,
* Returns: * Returns:
* 0 for success, -errno for errors. * 0 for success, -errno for errors.
*/ */
int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm, int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm)
u32 pasid)
{ {
bool pte_support_ats = (adev->asic_type == CHIP_RAVEN); bool pte_support_ats = (adev->asic_type == CHIP_RAVEN);
int r; int r;
...@@ -3075,16 +3067,6 @@ int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm, ...@@ -3075,16 +3067,6 @@ int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm,
if (r) if (r)
goto unreserve_bo; goto unreserve_bo;
/* Free the original amdgpu allocated pasid,
* will be replaced with kfd allocated pasid.
*/
if (vm->pasid)
amdgpu_pasid_free(vm->pasid);
r = amdgpu_vm_set_pasid(adev, vm, pasid);
if (r)
goto unreserve_bo;
/* Check if PD needs to be reinitialized and do it before /* Check if PD needs to be reinitialized and do it before
* changing any other state, in case it fails. * changing any other state, in case it fails.
*/ */
...@@ -3094,7 +3076,7 @@ int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm, ...@@ -3094,7 +3076,7 @@ int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm,
to_amdgpu_bo_vm(vm->root.bo), to_amdgpu_bo_vm(vm->root.bo),
false); false);
if (r) if (r)
goto free_pasid_entry; goto unreserve_bo;
} }
/* Update VM state */ /* Update VM state */
...@@ -3111,7 +3093,7 @@ int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm, ...@@ -3111,7 +3093,7 @@ int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm,
r = amdgpu_bo_sync_wait(vm->root.bo, r = amdgpu_bo_sync_wait(vm->root.bo,
AMDGPU_FENCE_OWNER_UNDEFINED, true); AMDGPU_FENCE_OWNER_UNDEFINED, true);
if (r) if (r)
goto free_pasid_entry; goto unreserve_bo;
vm->update_funcs = &amdgpu_vm_cpu_funcs; vm->update_funcs = &amdgpu_vm_cpu_funcs;
} else { } else {
...@@ -3126,8 +3108,6 @@ int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm, ...@@ -3126,8 +3108,6 @@ int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm,
goto unreserve_bo; goto unreserve_bo;
free_pasid_entry:
amdgpu_vm_set_pasid(adev, vm, 0);
unreserve_bo: unreserve_bo:
amdgpu_bo_unreserve(vm->root.bo); amdgpu_bo_unreserve(vm->root.bo);
return r; return r;
......
...@@ -378,8 +378,8 @@ int amdgpu_vm_set_pasid(struct amdgpu_device *adev, struct amdgpu_vm *vm, ...@@ -378,8 +378,8 @@ int amdgpu_vm_set_pasid(struct amdgpu_device *adev, struct amdgpu_vm *vm,
u32 pasid); u32 pasid);
long amdgpu_vm_wait_idle(struct amdgpu_vm *vm, long timeout); long amdgpu_vm_wait_idle(struct amdgpu_vm *vm, long timeout);
int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, u32 pasid); int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm);
int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm, u32 pasid); int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm);
void amdgpu_vm_release_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm); void amdgpu_vm_release_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm);
void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm); void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm);
void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm, void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm,
......
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