Skip to contentSkip to conversation

drm/amdgpu: check vm ready by evicting

PATCH Superseded Qiang Yu 3 participants 3 messages Feb 21, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Qiang Yu

author
#0 lore raw

PATCH 1/1 drm/amdgpu: check vm ready by evicting

Workstation application ANSA/META get this error dmesg:
[drm:amdgpu_gem_va_ioctl [amdgpu]] *ERROR* Couldn't update BO_VA (-16)

This is caused by:
1. create a 256MB buffer in invisible VRAM
2. CPU map the buffer and access it causes vm_fault and try to move it to visible VRAM
3. force visible VRAM space and traverse all VRAM bos to check if evicting this bo is valuable
4. when checking a VM bo (in invisible VRAM), amdgpu_vm_evictable() will set amdgpu_vm->evicting, but latter due to not in visible VRAM, won't really evict it so not add it to amdgpu_vm->evicted
5. before next CS to clear the amdgpu_vm->evicting, user VM ops ioctl will pass amdgpu_vm_ready() (check amdgpu_vm->evicted) but fail in amdgpu_vm_bo_update_mapping() (check amdgpu_vm->evicting) and get this error log

This error won't affect functionality as next CS will finish the waiting VM ops. But we'd better clear the error log by check the evicting flag which really stop VM ops latter.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +7 -2
index 37acd8911168..2cd9f1a2e5fa 100644
@@ -770,11 +770,16 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm,
  * Check if all VM PDs/PTs are ready for updates
  *
  * Returns:
- * True if eviction list is empty.
+ * True if VM is not evicting.
  */
 bool amdgpu_vm_ready(struct amdgpu_vm *vm)
 {
-	return list_empty(&vm->evicted);
+	bool ret;
+
+	amdgpu_vm_eviction_lock(vm);
+	ret = !vm->evicting;
+	amdgpu_vm_eviction_unlock(vm);
+	return ret;
 }
 
 /**
Signature · 1 line
2.25.1
maintainer Reviewed-by on v1 1/1
#1 lore raw

Am 21.02.22 um 11:12 schrieb Qiang Yu:

Quoted 17 lines

Workstation application ANSA/META get this error dmesg:
[drm:amdgpu_gem_va_ioctl [amdgpu]] *ERROR* Couldn't update BO_VA (-16)

This is caused by:
1. create a 256MB buffer in invisible VRAM
2. CPU map the buffer and access it causes vm_fault and try to move it to visible VRAM
3. force visible VRAM space and traverse all VRAM bos to check if evicting this bo is valuable
4. when checking a VM bo (in invisible VRAM), amdgpu_vm_evictable()

    will set amdgpu_vm->evicting, but latter due to not in visible
    VRAM, won't really evict it so not add it to amdgpu_vm->evicted
5. before next CS to clear the amdgpu_vm->evicting, user VM ops
    ioctl will pass amdgpu_vm_ready() (check amdgpu_vm->evicted)
    but fail in amdgpu_vm_bo_update_mapping() (check
    amdgpu_vm->evicting) and get this error log
Quoted 5 lines

This error won't affect functionality as next CS will finish the waiting VM ops. But we'd better clear the error log by check the evicting flag which really stop VM ops latter.

Good work.

Quoted 27 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 9 +++++++--
  1 file changed, 7 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +7 -2
index 37acd8911168..2cd9f1a2e5fa 100644
@@ -770,11 +770,16 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm,
   * Check if all VM PDs/PTs are ready for updates
   *
   * Returns:
- * True if eviction list is empty.
+ * True if VM is not evicting.
   */
  bool amdgpu_vm_ready(struct amdgpu_vm *vm)
  {
-	return list_empty(&vm->evicted);
+	bool ret;
+
+	amdgpu_vm_eviction_lock(vm);
+	ret = !vm->evicting;
+	amdgpu_vm_eviction_unlock(vm);
+	return ret;
  }
 
  /**
#2 lore raw
In reply to Qiang Yu

Dear Qiang Yu,

Am 21.02.22 um 11:12 schrieb Qiang Yu:

Thank you for your patch. Reading the commit message summary, I have no idea what “check vm ready by evicting” means. Can you please rephrase it?

Quoted 1 line

Workstation application ANSA/META get this error dmesg:

What version, and how can this be reproduced exactly? Just by starting the application?

Quoted 16 lines

[drm:amdgpu_gem_va_ioctl [amdgpu]] *ERROR* Couldn't update BO_VA (-16)

This is caused by:
1. create a 256MB buffer in invisible VRAM
2. CPU map the buffer and access it causes vm_fault and try to move it to visible VRAM
3. force visible VRAM space and traverse all VRAM bos to check if evicting this bo is valuable
4. when checking a VM bo (in invisible VRAM), amdgpu_vm_evictable()

    will set amdgpu_vm->evicting, but latter due to not in visible
    VRAM, won't really evict it so not add it to amdgpu_vm->evicted
5. before next CS to clear the amdgpu_vm->evicting, user VM ops
    ioctl will pass amdgpu_vm_ready() (check amdgpu_vm->evicted)
    but fail in amdgpu_vm_bo_update_mapping() (check
    amdgpu_vm->evicting) and get this error log
Quoted 2 lines

This error won't affect functionality as next CS will finish the waiting VM ops. But we'd better clear the error log by check the

s/check/checking/

Quoted 1 line

evicting flag which really stop VM ops latter.

stop*s*?

Can you please elaborate. Christian’s and your discussions was quite long, so adding a summary, why this approach works and what possible regressions there are going to be might be warranted.

Kind regards,

Paul

Quoted 28 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 9 +++++++--
  1 file changed, 7 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +7 -2
index 37acd8911168..2cd9f1a2e5fa 100644
@@ -770,11 +770,16 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm,
   * Check if all VM PDs/PTs are ready for updates
   *
   * Returns:
- * True if eviction list is empty.
+ * True if VM is not evicting.
   */
  bool amdgpu_vm_ready(struct amdgpu_vm *vm)
  {
-	return list_empty(&vm->evicted);
+	bool ret;
+
+	amdgpu_vm_eviction_lock(vm);
+	ret = !vm->evicting;
+	amdgpu_vm_eviction_unlock(vm);
+	return ret;
  }
 
  /**