Skip to contentSkip to conversation

drm/amdgpu: fix amdgpu_vm_bo_reset_state_machine

PATCH In review Christian König 4 participants 4 messages May 22 – May 26

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

PATCH 1/1 drm/amdgpu: fix amdgpu_vm_bo_reset_state_machine

Can't splice the list but need to handle each entry individually.

Otherwise we run into issues after a GPU reset.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +14 -3
index b523a7b97d6f..e91504f04d97 100644
@@ -266,12 +266,23 @@ static void amdgpu_vm_bo_idle(struct amdgpu_vm_bo_base *vm_bo)
  */
 static void amdgpu_vm_bo_reset_state_machine(struct amdgpu_vm *vm)
 {
+	struct amdgpu_vm_bo_base *vm_bo, *tmp;
+
+	/*
+	 * Don't use list splice here, we need the special handling for the root
+	 * PD and set the moved flag appropriately.
+	 */
 	amdgpu_vm_assert_locked(vm);
-	list_splice_init(&vm->kernel.idle, &vm->kernel.moved);
-	list_splice_init(&vm->always_valid.idle, &vm->always_valid.moved);
+	list_for_each_entry_safe(vm_bo, tmp, &vm->kernel.idle, vm_status)
+		amdgpu_vm_bo_moved(vm_bo);
+	list_for_each_entry_safe(vm_bo, tmp, &vm->always_valid.idle, vm_status)
+		amdgpu_vm_bo_moved(vm_bo);
 
 	spin_lock(&vm->individual_lock);
-	list_splice_init(&vm->individual.idle, &vm->individual.moved);
+	list_for_each_entry_safe(vm_bo, tmp, &vm->individual.idle, vm_status) {
+		vm_bo->moved = true;
+		list_move(&vm_bo->vm_status, &vm->individual.moved);
+	}
 	spin_unlock(&vm->individual_lock);
 }
 
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw

AMD General

The patch has been verified; feel free to add

Quoted 51 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Christian König
Sent: Friday, May 22, 2026 5:32 PM
To: Deucher, Alexander <[email protected]>; amd- [email protected]
Subject: [PATCH] drm/amdgpu: fix amdgpu_vm_bo_reset_state_machine

Can't splice the list but need to handle each entry individually.

Otherwise we run into issues after a GPU reset.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +14 -4
index b523a7b97d6f..e91504f04d97 100644
@@ -266,12 +266,23 @@ static void amdgpu_vm_bo_idle(struct
 amdgpu_vm_bo_base *vm_bo)
  */
 static void amdgpu_vm_bo_reset_state_machine(struct amdgpu_vm *vm)  {
+     struct amdgpu_vm_bo_base *vm_bo, *tmp;
+
+     /*
+      * Don't use list splice here, we need the special handling for the root
+      * PD and set the moved flag appropriately.
+      */
      amdgpu_vm_assert_locked(vm);
-     list_splice_init(&vm->kernel.idle, &vm->kernel.moved);
-     list_splice_init(&vm->always_valid.idle, &vm->always_valid.moved);
+     list_for_each_entry_safe(vm_bo, tmp, &vm->kernel.idle, vm_status)
+             amdgpu_vm_bo_moved(vm_bo);
+     list_for_each_entry_safe(vm_bo, tmp, &vm->always_valid.idle, vm_status)
+             amdgpu_vm_bo_moved(vm_bo);
 
      spin_lock(&vm->individual_lock);
-     list_splice_init(&vm->individual.idle, &vm->individual.moved);
+     list_for_each_entry_safe(vm_bo, tmp, &vm->individual.idle, vm_status) {
+             vm_bo->moved = true;
+             list_move(&vm_bo->vm_status, &vm->individual.moved);
+     }
      spin_unlock(&vm->individual_lock);
 }
 
--

2.43.0

Reviewed-by Sunil Khatri on v1 1/1
#2 lore raw
In reply to Christian König

I have also observed the same issue during reset and the patch is fixing it.

Regards
Sunil Khatri

Quoted 40 lines · Christian König

Can't splice the list but need to handle each entry individually.

Otherwise we run into issues after a GPU reset.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 17 ++++++++++++++---
  1 file changed, 14 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +14 -3
index b523a7b97d6f..e91504f04d97 100644
@@ -266,12 +266,23 @@ static void amdgpu_vm_bo_idle(struct amdgpu_vm_bo_base *vm_bo)
   */
  static void amdgpu_vm_bo_reset_state_machine(struct amdgpu_vm *vm)
  {
+	struct amdgpu_vm_bo_base *vm_bo, *tmp;
+
+	/*
+	 * Don't use list splice here, we need the special handling for the root
+	 * PD and set the moved flag appropriately.
+	 */
  	amdgpu_vm_assert_locked(vm);
-	list_splice_init(&vm->kernel.idle, &vm->kernel.moved);
-	list_splice_init(&vm->always_valid.idle, &vm->always_valid.moved);
+	list_for_each_entry_safe(vm_bo, tmp, &vm->kernel.idle, vm_status)
+		amdgpu_vm_bo_moved(vm_bo);
+	list_for_each_entry_safe(vm_bo, tmp, &vm->always_valid.idle, vm_status)
+		amdgpu_vm_bo_moved(vm_bo);
 
  	spin_lock(&vm->individual_lock);
-	list_splice_init(&vm->individual.idle, &vm->individual.moved);
+	list_for_each_entry_safe(vm_bo, tmp, &vm->individual.idle, vm_status) {
+		vm_bo->moved = true;
+		list_move(&vm_bo->vm_status, &vm->individual.moved);
+	}
  	spin_unlock(&vm->individual_lock);
  }
 
Acked-by on v1 1/1
#3 lore raw
In reply to Christian König
Quoted 5 lines · Christian König

Can't splice the list but need to handle each entry individually.

Otherwise we run into issues after a GPU reset.

Fixes 4cdbba5a16aa ("drm/amdgpu: restructure VM state machine v4")
Quoted 39 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +14 -4
index b523a7b97d6f..e91504f04d97 100644
@@ -266,12 +266,23 @@ static void amdgpu_vm_bo_idle(struct amdgpu_vm_bo_base *vm_bo)
  */
 static void amdgpu_vm_bo_reset_state_machine(struct amdgpu_vm *vm)
 {
+       struct amdgpu_vm_bo_base *vm_bo, *tmp;
+
+       /*
+        * Don't use list splice here, we need the special handling for the root
+        * PD and set the moved flag appropriately.
+        */
        amdgpu_vm_assert_locked(vm);
-       list_splice_init(&vm->kernel.idle, &vm->kernel.moved);
-       list_splice_init(&vm->always_valid.idle, &vm->always_valid.moved);
+       list_for_each_entry_safe(vm_bo, tmp, &vm->kernel.idle, vm_status)
+               amdgpu_vm_bo_moved(vm_bo);
+       list_for_each_entry_safe(vm_bo, tmp, &vm->always_valid.idle, vm_status)
+               amdgpu_vm_bo_moved(vm_bo);
 
        spin_lock(&vm->individual_lock);
-       list_splice_init(&vm->individual.idle, &vm->individual.moved);
+       list_for_each_entry_safe(vm_bo, tmp, &vm->individual.idle, vm_status) {
+               vm_bo->moved = true;
+               list_move(&vm_bo->vm_status, &vm->individual.moved);
+       }
        spin_unlock(&vm->individual_lock);
 }
 
--

2.43.0