diff options
author | Oak Zeng <Oak.Zeng@amd.com> | 2018-08-29 13:33:52 -0400 |
---|---|---|
committer | Alex Deucher <alexander.deucher@amd.com> | 2018-08-29 13:34:49 -0400 |
commit | 1685b01a858872075bc258a350153de0c7e95404 (patch) | |
tree | 18b1596da9dc1a082b7c78f12fdd7dd092bf5c11 /drivers/gpu/drm/amd/amdgpu | |
parent | bdb1922abd620d24715906bac4d119274d98f4c9 (diff) |
drm/amdgpu: Set pasid for compute vm (v2)
To make a amdgpu vm to a compute vm, the old pasid will be freed and
replaced with a pasid managed by kfd. Kfd can't reuse original pasid
allocated by amdgpu because kfd uses different pasid policy with amdgpu.
For example, all graphic devices share one same pasid in a process.
v2: rebase (Alex)
Signed-off-by: Oak Zeng <Oak.Zeng@amd.com>
Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Diffstat (limited to 'drivers/gpu/drm/amd/amdgpu')
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 6 | ||||
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 10 | ||||
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 38 | ||||
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 2 |
4 files changed, 43 insertions, 13 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h index 2f379c183ed2..ba0057e94d5e 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | |||
@@ -162,11 +162,11 @@ uint64_t amdgpu_amdkfd_get_vram_usage(struct kgd_dev *kgd); | |||
162 | }) | 162 | }) |
163 | 163 | ||
164 | /* GPUVM API */ | 164 | /* GPUVM API */ |
165 | int amdgpu_amdkfd_gpuvm_create_process_vm(struct kgd_dev *kgd, void **vm, | 165 | int amdgpu_amdkfd_gpuvm_create_process_vm(struct kgd_dev *kgd, unsigned int pasid, |
166 | void **process_info, | 166 | void **vm, void **process_info, |
167 | struct dma_fence **ef); | 167 | struct dma_fence **ef); |
168 | int amdgpu_amdkfd_gpuvm_acquire_process_vm(struct kgd_dev *kgd, | 168 | int amdgpu_amdkfd_gpuvm_acquire_process_vm(struct kgd_dev *kgd, |
169 | struct file *filp, | 169 | struct file *filp, unsigned int pasid, |
170 | void **vm, void **process_info, | 170 | void **vm, void **process_info, |
171 | struct dma_fence **ef); | 171 | struct dma_fence **ef); |
172 | void amdgpu_amdkfd_gpuvm_destroy_cb(struct amdgpu_device *adev, | 172 | void amdgpu_amdkfd_gpuvm_destroy_cb(struct amdgpu_device *adev, |
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c index 2ef6e8557b65..1cbdd9a7538e 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | |||
@@ -1000,8 +1000,8 @@ create_evict_fence_fail: | |||
1000 | return ret; | 1000 | return ret; |
1001 | } | 1001 | } |
1002 | 1002 | ||
1003 | int amdgpu_amdkfd_gpuvm_create_process_vm(struct kgd_dev *kgd, void **vm, | 1003 | int amdgpu_amdkfd_gpuvm_create_process_vm(struct kgd_dev *kgd, unsigned int pasid, |
1004 | void **process_info, | 1004 | void **vm, void **process_info, |
1005 | struct dma_fence **ef) | 1005 | struct dma_fence **ef) |
1006 | { | 1006 | { |
1007 | struct amdgpu_device *adev = get_amdgpu_device(kgd); | 1007 | struct amdgpu_device *adev = get_amdgpu_device(kgd); |
@@ -1013,7 +1013,7 @@ int amdgpu_amdkfd_gpuvm_create_process_vm(struct kgd_dev *kgd, void **vm, | |||
1013 | return -ENOMEM; | 1013 | return -ENOMEM; |
1014 | 1014 | ||
1015 | /* Initialize AMDGPU part of the VM */ | 1015 | /* Initialize AMDGPU part of the VM */ |
1016 | ret = amdgpu_vm_init(adev, new_vm, AMDGPU_VM_CONTEXT_COMPUTE, 0); | 1016 | ret = amdgpu_vm_init(adev, new_vm, AMDGPU_VM_CONTEXT_COMPUTE, pasid); |
1017 | if (ret) { | 1017 | if (ret) { |
1018 | pr_err("Failed init vm ret %d\n", ret); | 1018 | pr_err("Failed init vm ret %d\n", ret); |
1019 | goto amdgpu_vm_init_fail; | 1019 | goto amdgpu_vm_init_fail; |
@@ -1036,7 +1036,7 @@ amdgpu_vm_init_fail: | |||
1036 | } | 1036 | } |
1037 | 1037 | ||
1038 | int amdgpu_amdkfd_gpuvm_acquire_process_vm(struct kgd_dev *kgd, | 1038 | int amdgpu_amdkfd_gpuvm_acquire_process_vm(struct kgd_dev *kgd, |
1039 | struct file *filp, | 1039 | struct file *filp, unsigned int pasid, |
1040 | void **vm, void **process_info, | 1040 | void **vm, void **process_info, |
1041 | struct dma_fence **ef) | 1041 | struct dma_fence **ef) |
1042 | { | 1042 | { |
@@ -1051,7 +1051,7 @@ int amdgpu_amdkfd_gpuvm_acquire_process_vm(struct kgd_dev *kgd, | |||
1051 | return -EINVAL; | 1051 | return -EINVAL; |
1052 | 1052 | ||
1053 | /* Convert VM into a compute VM */ | 1053 | /* Convert VM into a compute VM */ |
1054 | ret = amdgpu_vm_make_compute(adev, avm); | 1054 | ret = amdgpu_vm_make_compute(adev, avm, pasid); |
1055 | if (ret) | 1055 | if (ret) |
1056 | return ret; | 1056 | return ret; |
1057 | 1057 | ||
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c index 60c0609b78a4..272b7902a25c 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | |||
@@ -2740,7 +2740,7 @@ error_free_sched_entity: | |||
2740 | * Returns: | 2740 | * Returns: |
2741 | * 0 for success, -errno for errors. | 2741 | * 0 for success, -errno for errors. |
2742 | */ | 2742 | */ |
2743 | int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm) | 2743 | int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm, unsigned int pasid) |
2744 | { | 2744 | { |
2745 | bool pte_support_ats = (adev->asic_type == CHIP_RAVEN); | 2745 | bool pte_support_ats = (adev->asic_type == CHIP_RAVEN); |
2746 | int r; | 2746 | int r; |
@@ -2752,7 +2752,20 @@ int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm) | |||
2752 | /* Sanity checks */ | 2752 | /* Sanity checks */ |
2753 | if (!RB_EMPTY_ROOT(&vm->va.rb_root) || vm->root.entries) { | 2753 | if (!RB_EMPTY_ROOT(&vm->va.rb_root) || vm->root.entries) { |
2754 | r = -EINVAL; | 2754 | r = -EINVAL; |
2755 | goto error; | 2755 | goto unreserve_bo; |
2756 | } | ||
2757 | |||
2758 | if (pasid) { | ||
2759 | unsigned long flags; | ||
2760 | |||
2761 | spin_lock_irqsave(&adev->vm_manager.pasid_lock, flags); | ||
2762 | r = idr_alloc(&adev->vm_manager.pasid_idr, vm, pasid, pasid + 1, | ||
2763 | GFP_ATOMIC); | ||
2764 | spin_unlock_irqrestore(&adev->vm_manager.pasid_lock, flags); | ||
2765 | |||
2766 | if (r == -ENOSPC) | ||
2767 | goto unreserve_bo; | ||
2768 | r = 0; | ||
2756 | } | 2769 | } |
2757 | 2770 | ||
2758 | /* Check if PD needs to be reinitialized and do it before | 2771 | /* Check if PD needs to be reinitialized and do it before |
@@ -2763,7 +2776,7 @@ int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm) | |||
2763 | adev->vm_manager.root_level, | 2776 | adev->vm_manager.root_level, |
2764 | pte_support_ats); | 2777 | pte_support_ats); |
2765 | if (r) | 2778 | if (r) |
2766 | goto error; | 2779 | goto free_idr; |
2767 | } | 2780 | } |
2768 | 2781 | ||
2769 | /* Update VM state */ | 2782 | /* Update VM state */ |
@@ -2782,13 +2795,30 @@ int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm) | |||
2782 | idr_remove(&adev->vm_manager.pasid_idr, vm->pasid); | 2795 | idr_remove(&adev->vm_manager.pasid_idr, vm->pasid); |
2783 | spin_unlock_irqrestore(&adev->vm_manager.pasid_lock, flags); | 2796 | spin_unlock_irqrestore(&adev->vm_manager.pasid_lock, flags); |
2784 | 2797 | ||
2798 | /* Free the original amdgpu allocated pasid | ||
2799 | * Will be replaced with kfd allocated pasid | ||
2800 | */ | ||
2801 | amdgpu_pasid_free(vm->pasid); | ||
2785 | vm->pasid = 0; | 2802 | vm->pasid = 0; |
2786 | } | 2803 | } |
2787 | 2804 | ||
2788 | /* Free the shadow bo for compute VM */ | 2805 | /* Free the shadow bo for compute VM */ |
2789 | amdgpu_bo_unref(&vm->root.base.bo->shadow); | 2806 | amdgpu_bo_unref(&vm->root.base.bo->shadow); |
2790 | 2807 | ||
2791 | error: | 2808 | if (pasid) |
2809 | vm->pasid = pasid; | ||
2810 | |||
2811 | goto unreserve_bo; | ||
2812 | |||
2813 | free_idr: | ||
2814 | if (pasid) { | ||
2815 | unsigned long flags; | ||
2816 | |||
2817 | spin_lock_irqsave(&adev->vm_manager.pasid_lock, flags); | ||
2818 | idr_remove(&adev->vm_manager.pasid_idr, pasid); | ||
2819 | spin_unlock_irqrestore(&adev->vm_manager.pasid_lock, flags); | ||
2820 | } | ||
2821 | unreserve_bo: | ||
2792 | amdgpu_bo_unreserve(vm->root.base.bo); | 2822 | amdgpu_bo_unreserve(vm->root.base.bo); |
2793 | return r; | 2823 | return r; |
2794 | } | 2824 | } |
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h index 94fe47890adf..24b02c91ce0c 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | |||
@@ -297,7 +297,7 @@ void amdgpu_vm_manager_init(struct amdgpu_device *adev); | |||
297 | void amdgpu_vm_manager_fini(struct amdgpu_device *adev); | 297 | void amdgpu_vm_manager_fini(struct amdgpu_device *adev); |
298 | int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, | 298 | int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, |
299 | int vm_context, unsigned int pasid); | 299 | int vm_context, unsigned int pasid); |
300 | int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm); | 300 | int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm, unsigned int pasid); |
301 | void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm); | 301 | void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm); |
302 | bool amdgpu_vm_pasid_fault_credit(struct amdgpu_device *adev, | 302 | bool amdgpu_vm_pasid_fault_credit(struct amdgpu_device *adev, |
303 | unsigned int pasid); | 303 | unsigned int pasid); |