Skip to contentSkip to conversation

drm/amdgpu: Forbid kfd using cpu to update pt if vm is shared with gfx

PATCH In review YuBiao Wang 3 participants 3 messages Jun 21, 2023 – Jun 22, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdgpu: Forbid kfd using cpu to update pt if vm is shared with gfx

If a same GPU VM is shared by kfd and graphic operations, we must align the vm update mode to sdma, or cpu kmap will fail and cause null pointer issue.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5 -0
index 291977b93b1d..e105ff9e8041 100644
@@ -2239,6 +2239,7 @@ 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)
 {
 	bool pte_support_ats = (adev->asic_type == CHIP_RAVEN);
+	struct amdgpu_bo *bo = vm->root.bo;
 	int r;
 
 	r = amdgpu_bo_reserve(vm->root.bo, true);
@@ -2265,6 +2266,10 @@ int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm)
 	/* Update VM state */
 	vm->use_cpu_for_update = !!(adev->vm_manager.vm_update_mode &
 				    AMDGPU_VM_USE_CPU_FOR_COMPUTE);
+
+	if (bo && !(bo->flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED))
+		vm->use_cpu_for_update = false;
+
 	DRM_DEBUG_DRIVER("VM update mode is %s\n",
 			 vm->use_cpu_for_update ? "CPU" : "SDMA");
 	WARN_ONCE((vm->use_cpu_for_update &&
Signature · 1 line
2.34.1
#1 lore raw

Can we change the flags if needed. E.g. see what amdgpu_bo_pin_restricted does:

        if (!(bo->flags & AMDGPU_GEM_CREATE_NO_CPU_ACCESS))
                bo->flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
        amdgpu_bo_placement_from_domain(bo, domain);

This shouldn't really change anything about the BO placement because we only enable CPU page table updates on large-BAR GPUs by default. Alternatively, we could create VM BOs with AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED on large-BAR GPUs to make it possible to switch to CPU page table updates for compute VMs.

Regards,
  Felix

Am 2023-06-21 um 05:46 schrieb YuBiao Wang:

Quoted 32 lines

If a same GPU VM is shared by kfd and graphic operations, we must align the vm update mode to sdma, or cpu kmap will fail and cause null pointer issue.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 5 +++++
  1 file changed, 5 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5 -0
index 291977b93b1d..e105ff9e8041 100644
@@ -2239,6 +2239,7 @@ 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)
  {
  	bool pte_support_ats = (adev->asic_type == CHIP_RAVEN);
+	struct amdgpu_bo *bo = vm->root.bo;
  	int r;
 
  	r = amdgpu_bo_reserve(vm->root.bo, true);
@@ -2265,6 +2266,10 @@ int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm)
  	/* Update VM state */
  	vm->use_cpu_for_update = !!(adev->vm_manager.vm_update_mode &
  				    AMDGPU_VM_USE_CPU_FOR_COMPUTE);
+
+	if (bo && !(bo->flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED))
+		vm->use_cpu_for_update = false;
+
  	DRM_DEBUG_DRIVER("VM update mode is %s\n",
  			 vm->use_cpu_for_update ? "CPU" : "SDMA");
  	WARN_ONCE((vm->use_cpu_for_update &&
maintainer
#2 lore raw

I have no problem dropping the AMDGPU_GEM_CREATE_NO_CPU_ACCESS flag from page tables no matter if we have large BAR or not.

That should only be necessary when BOs are pinned and since we never pin page tables it shouldn't matter.

Just set AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED after switching to CPU based updates for all already allocated page tables.

Regards,
Christian.

Am 21.06.23 um 17:16 schrieb Felix Kuehling:

Quoted 46 lines

Can we change the flags if needed. E.g. see what amdgpu_bo_pin_restricted does:

        if (!(bo->flags & AMDGPU_GEM_CREATE_NO_CPU_ACCESS)) bo->flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED; amdgpu_bo_placement_from_domain(bo, domain);

This shouldn't really change anything about the BO placement because we only enable CPU page table updates on large-BAR GPUs by default. Alternatively, we could create VM BOs with AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED on large-BAR GPUs to make it possible to switch to CPU page table updates for compute VMs.

Regards,
  Felix

Am 2023-06-21 um 05:46 schrieb YuBiao Wang:

Quoted 33 lines

If a same GPU VM is shared by kfd and graphic operations, we must align the vm update mode to sdma, or cpu kmap will fail and cause null pointer issue.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 5 +++++

  1 file changed, 5 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -0
index 291977b93b1d..e105ff9e8041 100644
@@ -2239,6 +2239,7 @@ 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)
   {
       bool pte_support_ats = (adev->asic_type == CHIP_RAVEN);
+    struct amdgpu_bo *bo = vm->root.bo;
       int r;
         r = amdgpu_bo_reserve(vm->root.bo, true);
@@ -2265,6 +2266,10 @@ int amdgpu_vm_make_compute(struct 
 amdgpu_device *adev, struct amdgpu_vm *vm)
       /* Update VM state */

      vm->use_cpu_for_update = !!(adev->vm_manager.vm_update_mode & AMDGPU_VM_USE_CPU_FOR_COMPUTE);

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4 -0
+
+    if (bo && !(bo->flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED))
+        vm->use_cpu_for_update = false;
+

      DRM_DEBUG_DRIVER("VM update mode is %s\n", vm->use_cpu_for_update ? "CPU" : "SDMA"); WARN_ONCE((vm->use_cpu_for_update &&