Skip to contentSkip to conversation

drm/amdgpu: Fix two reset triggered in a row

PATCH Superseded Yunxiang Li 6 participants 14 messages Apr 22, 2024 – Apr 25, 2024

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdgpu: Fix two reset triggered in a row

Reset request from KFD is missing a check for if a reset is already in progress, this causes a second reset to be triggered right after the previous one finishes. Add the check to align with the other reset sources.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +1 -1
index 3b4591f554f1..ce3dbb1cc2da 100644
@@ -283,7 +283,7 @@ int amdgpu_amdkfd_post_reset(struct amdgpu_device *adev)
 
 void amdgpu_amdkfd_gpu_reset(struct amdgpu_device *adev)
 {
-	if (amdgpu_device_should_recover_gpu(adev))
+	if (amdgpu_device_should_recover_gpu(adev) && !amdgpu_in_reset(adev))
 		amdgpu_reset_domain_schedule(adev->reset_domain,
 					     &adev->kfd.reset_work);
 }
Signature · 1 line
2.34.1
Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · Yunxiang Li

Reset request from KFD is missing a check for if a reset is already in progress, this causes a second reset to be triggered right after the previous one finishes. Add the check to align with the other reset sources.

Quoted 22 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +1 -2
index 3b4591f554f1..ce3dbb1cc2da 100644
@@ -283,7 +283,7 @@ int amdgpu_amdkfd_post_reset(struct amdgpu_device *adev)
 
 void amdgpu_amdkfd_gpu_reset(struct amdgpu_device *adev)
 {
-       if (amdgpu_device_should_recover_gpu(adev))
+       if (amdgpu_device_should_recover_gpu(adev) && !amdgpu_in_reset(adev))
                amdgpu_reset_domain_schedule(adev->reset_domain,
                                             &adev->kfd.reset_work);
 }
--

2.34.1

maintainer Reviewed-by
#2 lore raw
Quoted 5 lines · Alex Deucher
Quoted 3 lines · Yunxiang Li

Reset request from KFD is missing a check for if a reset is already in progress, this causes a second reset to be triggered right after the previous one finishes. Add the check to align with the other reset sources.

Quoted 22 lines
Quoted 22 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +1 -2
index 3b4591f554f1..ce3dbb1cc2da 100644
@@ -283,7 +283,7 @@ int amdgpu_amdkfd_post_reset(struct amdgpu_device *adev)
 
  void amdgpu_amdkfd_gpu_reset(struct amdgpu_device *adev)
  {
-       if (amdgpu_device_should_recover_gpu(adev))
+       if (amdgpu_device_should_recover_gpu(adev) && !amdgpu_in_reset(adev))
                 amdgpu_reset_domain_schedule(adev->reset_domain,
                                              &adev->kfd.reset_work);
  }
--

2.34.1

#3 lore raw
In reply to Yunxiang Li
Quoted 14 lines · Yunxiang Li

Reset request from KFD is missing a check for if a reset is already in progress, this causes a second reset to be triggered right after the previous one finishes. Add the check to align with the other reset sources.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +0 -0
index 3b4591f554f1..ce3dbb1cc2da 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c int amdgpu_amdkfd_post_reset(struct amdgpu_device *adev) · line 288

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +1 -1
@@ -283,7 +283,7 @@ int amdgpu_amdkfd_post_reset(struct amdgpu_device *adev)
 
 void amdgpu_amdkfd_gpu_reset(struct amdgpu_device *adev)
 {
-	if (amdgpu_device_should_recover_gpu(adev))
+	if (amdgpu_device_should_recover_gpu(adev) && !amdgpu_in_reset(adev))
 		amdgpu_reset_domain_schedule(adev->reset_domain,
 					     &adev->kfd.reset_work);

We can't do this technically as there are cases where we skip full device reset (even then amdgpu_in_reset will return true). The better thing to do is to move amdgpu_device_stop_pending_resets() later in gpu_recover()- if a device has undergone full reset, then cancel all pending resets. Presently it's happening earlier which could be why this issue is seen.

Thanks,
Lijo

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +0 -0
 }
#4 lore raw

[Public]

Quoted 2 lines

We can't do this technically as there are cases where we skip full device reset (even then amdgpu_in_reset will return true). The better thing to do is to move amdgpu_device_stop_pending_resets() later in gpu_recover()- if a device has undergone full reset, then cancel all pending resets. Presently it's happening earlier which could be why this issue is seen.

This sounds like it is a design issue then, if different reset workers expect different resets to be triggered but they all use the same flag. I wonder if the other places that check this flags are correct. FWIW I was testing with SRIOV where it always does full reset and ran into this issue.

maintainer
#5 lore raw

Am 23.04.24 um 05:13 schrieb Li, Yunxiang (Teddy):

Quoted 5 lines

[Public]

Quoted 2 lines

We can't do this technically as there are cases where we skip full device reset (even then amdgpu_in_reset will return true). The better thing to do is to move amdgpu_device_stop_pending_resets() later in gpu_recover()- if a device has undergone full reset, then cancel all pending resets. Presently it's happening earlier which could be why this issue is seen.

This sounds like it is a design issue then, if different reset workers expect different resets to be triggered but they all use the same flag. I wonder if the other places that check this flags are correct. FWIW I was testing with SRIOV where it always does full reset and ran into this issue.

Lijo is correct. The idea here is that all reset sources which have been covered by a reset are canceled directly after the reset is completed.

The approach with checking amdgpu_in_reset() is broken because it can still happen that multiple sources signal at the same time that a reset is necessary.

Regards,
Christian.

maintainer NAK
#6 lore raw
In reply to Yunxiang Li

Am 22.04.24 um 21:45 schrieb Yunxiang Li:

Quoted 3 lines

Reset request from KFD is missing a check for if a reset is already in progress, this causes a second reset to be triggered right after the previous one finishes. Add the check to align with the other reset sources.

NAK, that isn't how this should be handled.

Instead all reset source which are handled by a previous reset should be canceled.

In other words there should be a cancel_work(&adev->kfd.reset_work); somewhere in the KFD code. When this doesn't work correctly then that is somehow missing.

If you see the use of amdgpu_in_reset() outside of the low level functions than that is clearly a bug.

Regards,
Christian.

Quoted 19 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +1 -1
index 3b4591f554f1..ce3dbb1cc2da 100644
@@ -283,7 +283,7 @@ int amdgpu_amdkfd_post_reset(struct amdgpu_device *adev)
 
  void amdgpu_amdkfd_gpu_reset(struct amdgpu_device *adev)
  {
-	if (amdgpu_device_should_recover_gpu(adev))
+	if (amdgpu_device_should_recover_gpu(adev) && !amdgpu_in_reset(adev))
  		amdgpu_reset_domain_schedule(adev->reset_domain,
  					     &adev->kfd.reset_work);
  }
maintainer
#7 lore raw
Quoted 5 lines · Christian König

Am 22.04.24 um 21:45 schrieb Yunxiang Li:

Quoted 3 lines

Reset request from KFD is missing a check for if a reset is already in progress, this causes a second reset to be triggered right after the previous one finishes. Add the check to align with the other reset sources.

Quoted 7 lines

NAK, that isn't how this should be handled.

Instead all reset source which are handled by a previous reset should be canceled.

In other words there should be a cancel_work(&adev->kfd.reset_work); somewhere in the KFD code. When this doesn't work correctly then that is somehow missing.

If you see the use of amdgpu_in_reset() outside of the low level functions than that is clearly a bug.

Do we need to do that for all reset workers in the driver separately? I don't see where this is done for other reset workers.

Regards,
  Felix

Quoted 25 lines

Regards,
Christian.

Quoted 20 lines

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +1 -1
index 3b4591f554f1..ce3dbb1cc2da 100644
@@ -283,7 +283,7 @@ int amdgpu_amdkfd_post_reset(struct amdgpu_device 
 *adev)
     void amdgpu_amdkfd_gpu_reset(struct amdgpu_device *adev)
   {
-    if (amdgpu_device_should_recover_gpu(adev))
+    if (amdgpu_device_should_recover_gpu(adev) && 
 !amdgpu_in_reset(adev))
           amdgpu_reset_domain_schedule(adev->reset_domain,
                            &adev->kfd.reset_work);

  }

#8 lore raw

Am 23.04.24 um 20:05 schrieb Felix Kuehling:

Quoted 7 lines · Christian König
Quoted 5 lines

Am 22.04.24 um 21:45 schrieb Yunxiang Li:

Quoted 3 lines

Reset request from KFD is missing a check for if a reset is already in progress, this causes a second reset to be triggered right after the previous one finishes. Add the check to align with the other reset sources.

Quoted 8 lines
Quoted 7 lines

NAK, that isn't how this should be handled.

Instead all reset source which are handled by a previous reset should be canceled.

In other words there should be a cancel_work(&adev->kfd.reset_work); somewhere in the KFD code. When this doesn't work correctly then that is somehow missing.

If you see the use of amdgpu_in_reset() outside of the low level functions than that is clearly a bug.

Do we need to do that for all reset workers in the driver separately? I don't see where this is done for other reset workers.

Yeah, I think so. But we don't have so many reset workers if I'm not completely mistaken.

We have the KFD, FLR, the per engine one in the scheduler and IIRC one more for the CP (illegal operation and register write).

I'm not sure about the CP one, but all others should be handled correctly with the V2 patch as far as I can see.

Regards,
Christian.

Quoted 30 lines

Regards,
  Felix

Quoted 25 lines

Regards,
Christian.

Quoted 20 lines

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +1 -1
index 3b4591f554f1..ce3dbb1cc2da 100644
@@ -283,7 +283,7 @@ int amdgpu_amdkfd_post_reset(struct 
 amdgpu_device *adev)
     void amdgpu_amdkfd_gpu_reset(struct amdgpu_device *adev)
   {
-    if (amdgpu_device_should_recover_gpu(adev))
+    if (amdgpu_device_should_recover_gpu(adev) && 
 !amdgpu_in_reset(adev))
           amdgpu_reset_domain_schedule(adev->reset_domain,
                            &adev->kfd.reset_work);

  }

#9 lore raw

[Public]

Quoted 3 lines

We have the KFD, FLR, the per engine one in the scheduler and IIRC one more for the CP (illegal operation and register write).

I'm not sure about the CP one, but all others should be handled correctly with the V2 patch as far as I can see.

Where can I find the CP one? Nothing came up when I search for amdgpu_device_gpu_recover

#10 lore raw

Am 24.04.24 um 15:13 schrieb Li, Yunxiang (Teddy):

Quoted 6 lines

[Public]

Quoted 3 lines

We have the KFD, FLR, the per engine one in the scheduler and IIRC one more for the CP (illegal operation and register write).

I'm not sure about the CP one, but all others should be handled correctly with the V2 patch as far as I can see.

Where can I find the CP one? Nothing came up when I search for amdgpu_device_gpu_recover

I had to dig that up as well in the code since I haven't looked into it in years.

Looks like that is handled by the scheduler work item now as well. See function gfx_v9_0_fault() for an example.

Regards,
Christian.

#11 lore raw

[Public]

Quoted 1 line

Looks like that is handled by the scheduler work item now as well. See function gfx_v9_0_fault() for an example.

Cool so it is blocked by drm_sched_stop also. I think that covers everything.

#12 lore raw

PATCH v2 1/1 drm/amdgpu: Fix two reset triggered in a row

In reply to Yunxiang Li

Some times a hang GPU causes multiple reset source to schedule resets, if the second source schedule after we call amdgpu_device_stop_pending_resets they will be able to trigger an unnecessary reset.

Move amdgpu_device_stop_pending_resets to after the reset is already done, since any reset scheduled after that point would be legitimate. Remove unnecessary and incorrect checks for amdgpu_in_reset that was kinda serving this purpose.

---
v2: instead of adding amdgpu_in_reset check, move when we cancel pending resets

 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 17 ++++++++---------
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c   |  2 +-
 drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c      |  2 +-
 drivers/gpu/drm/amd/amdgpu/mxgpu_nv.c      |  2 +-
 drivers/gpu/drm/amd/amdgpu/mxgpu_vi.c      |  2 +-
 5 files changed, 12 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +8 -9
index f8a34db5d9e3..28f6a1c38b17 100644
@@ -5061,8 +5061,6 @@ static int amdgpu_device_reset_sriov(struct amdgpu_device *adev,
 retry:
 	amdgpu_amdkfd_pre_reset(adev);
 
-	amdgpu_device_stop_pending_resets(adev);
-
 	if (from_hypervisor)
 		r = amdgpu_virt_request_full_gpu(adev, true);
 	else
@@ -5813,13 +5811,6 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
 				  r, adev_to_drm(tmp_adev)->unique);
 			tmp_adev->asic_reset_res = r;
 		}
-
-		if (!amdgpu_sriov_vf(tmp_adev))
-			/*
-			* Drop all pending non scheduler resets. Scheduler resets
-			* were already dropped during drm_sched_stop
-			*/
-			amdgpu_device_stop_pending_resets(tmp_adev);
 	}
 
 	/* Actual ASIC resets if needed.*/
@@ -5841,6 +5832,14 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
 			goto retry;
 	}
 
+	list_for_each_entry(tmp_adev, device_list_handle, reset_list) {
+		/*
+		 * Drop all pending non scheduler resets. Scheduler resets
+		 * were already dropped during drm_sched_stop
+		 */
+		amdgpu_device_stop_pending_resets(tmp_adev);
+	}
+
 skip_hw_reset:
 
 	/* Post ASIC reset for all devs .*/
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +1 -1
index 54ab51a4ada7..c2385178d6b3 100644
@@ -597,7 +597,7 @@ static void amdgpu_virt_update_vf2pf_work_item(struct work_struct *work)
 	if (ret) {
 		adev->virt.vf2pf_update_retry_cnt++;
 		if ((adev->virt.vf2pf_update_retry_cnt >= AMDGPU_VF2PF_UPDATE_MAX_RETRY_LIMIT) &&
-		    amdgpu_sriov_runtime(adev) && !amdgpu_in_reset(adev)) {
+		    amdgpu_sriov_runtime(adev)) {
 			amdgpu_ras_set_fed(adev, true);
 			if (amdgpu_reset_domain_schedule(adev->reset_domain,
 							  &adev->virt.flr_work))
drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c +1 -1
index 0c7275bca8f7..c5ba9c4757a8 100644
@@ -319,7 +319,7 @@ static int xgpu_ai_mailbox_rcv_irq(struct amdgpu_device *adev,
 
 	switch (event) {
 		case IDH_FLR_NOTIFICATION:
-		if (amdgpu_sriov_runtime(adev) && !amdgpu_in_reset(adev))
+		if (amdgpu_sriov_runtime(adev))
 			WARN_ONCE(!amdgpu_reset_domain_schedule(adev->reset_domain,
 								&adev->virt.flr_work),
 				  "Failed to queue work! at %s",
drivers/gpu/drm/amd/amdgpu/mxgpu_nv.c +1 -1
index aba00d961627..fa9d1b02f391 100644
@@ -358,7 +358,7 @@ static int xgpu_nv_mailbox_rcv_irq(struct amdgpu_device *adev,
 
 	switch (event) {
 	case IDH_FLR_NOTIFICATION:
-		if (amdgpu_sriov_runtime(adev) && !amdgpu_in_reset(adev))
+		if (amdgpu_sriov_runtime(adev))
 			WARN_ONCE(!amdgpu_reset_domain_schedule(adev->reset_domain,
 				   &adev->virt.flr_work),
 				  "Failed to queue work! at %s",
drivers/gpu/drm/amd/amdgpu/mxgpu_vi.c +1 -1
index 59f53c743362..14a065516ae4 100644
@@ -560,7 +560,7 @@ static int xgpu_vi_mailbox_rcv_irq(struct amdgpu_device *adev,
 		r = xgpu_vi_mailbox_rcv_msg(adev, IDH_FLR_NOTIFICATION);
 
 		/* only handle FLR_NOTIFY now */
-		if (!r && !amdgpu_in_reset(adev))
+		if (!r)
 			WARN_ONCE(!amdgpu_reset_domain_schedule(adev->reset_domain,
 								&adev->virt.flr_work),
 				  "Failed to queue work! at %s",
Signature · 1 line
2.34.1
maintainer
#13 lore raw

Am 23.04.24 um 16:44 schrieb Yunxiang Li:

Quoted 11 lines

Some times a hang GPU causes multiple reset source to schedule resets, if the second source schedule after we call amdgpu_device_stop_pending_resets they will be able to trigger an unnecessary reset.

Move amdgpu_device_stop_pending_resets to after the reset is already done, since any reset scheduled after that point would be legitimate. Remove unnecessary and incorrect checks for amdgpu_in_reset that was kinda serving this purpose.

Looks really good to me of hand, especially that so many cases of using amdgpu_in_reset() are removed.

But I'm just not deeply into each component to fully judge everything here.

So only Acked-by: Christian König <[email protected]> for now, if you need a more in deep review please ping me.

Regards,
Christian.

Quoted 105 lines

---
v2: instead of adding amdgpu_in_reset check, move when we cancel pending resets

  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 17 ++++++++---------
  drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c   |  2 +-
  drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c      |  2 +-
  drivers/gpu/drm/amd/amdgpu/mxgpu_nv.c      |  2 +-
  drivers/gpu/drm/amd/amdgpu/mxgpu_vi.c      |  2 +-
  5 files changed, 12 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +8 -9
index f8a34db5d9e3..28f6a1c38b17 100644
@@ -5061,8 +5061,6 @@ static int amdgpu_device_reset_sriov(struct amdgpu_device *adev,
  retry:
  	amdgpu_amdkfd_pre_reset(adev);
 
-	amdgpu_device_stop_pending_resets(adev);
-
  	if (from_hypervisor)
  		r = amdgpu_virt_request_full_gpu(adev, true);
  	else
@@ -5813,13 +5811,6 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
  				  r, adev_to_drm(tmp_adev)->unique);
  			tmp_adev->asic_reset_res = r;
  		}
-
-		if (!amdgpu_sriov_vf(tmp_adev))
-			/*
-			* Drop all pending non scheduler resets. Scheduler resets
-			* were already dropped during drm_sched_stop
-			*/
-			amdgpu_device_stop_pending_resets(tmp_adev);
  	}
 
  	/* Actual ASIC resets if needed.*/
@@ -5841,6 +5832,14 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
  			goto retry;
  	}
 
+	list_for_each_entry(tmp_adev, device_list_handle, reset_list) {
+		/*
+		 * Drop all pending non scheduler resets. Scheduler resets
+		 * were already dropped during drm_sched_stop
+		 */
+		amdgpu_device_stop_pending_resets(tmp_adev);
+	}
+
  skip_hw_reset:
 
  	/* Post ASIC reset for all devs .*/
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +1 -1
index 54ab51a4ada7..c2385178d6b3 100644
@@ -597,7 +597,7 @@ static void amdgpu_virt_update_vf2pf_work_item(struct work_struct *work)
  	if (ret) {
  		adev->virt.vf2pf_update_retry_cnt++;
  		if ((adev->virt.vf2pf_update_retry_cnt >= AMDGPU_VF2PF_UPDATE_MAX_RETRY_LIMIT) &&
-		    amdgpu_sriov_runtime(adev) && !amdgpu_in_reset(adev)) {
+		    amdgpu_sriov_runtime(adev)) {
  			amdgpu_ras_set_fed(adev, true);
  			if (amdgpu_reset_domain_schedule(adev->reset_domain,
  							  &adev->virt.flr_work))
drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c +1 -1
index 0c7275bca8f7..c5ba9c4757a8 100644
@@ -319,7 +319,7 @@ static int xgpu_ai_mailbox_rcv_irq(struct amdgpu_device *adev,
 
  	switch (event) {
  		case IDH_FLR_NOTIFICATION:
-		if (amdgpu_sriov_runtime(adev) && !amdgpu_in_reset(adev))
+		if (amdgpu_sriov_runtime(adev))
  			WARN_ONCE(!amdgpu_reset_domain_schedule(adev->reset_domain,
  								&adev->virt.flr_work),
  				  "Failed to queue work! at %s",
drivers/gpu/drm/amd/amdgpu/mxgpu_nv.c +1 -1
index aba00d961627..fa9d1b02f391 100644
@@ -358,7 +358,7 @@ static int xgpu_nv_mailbox_rcv_irq(struct amdgpu_device *adev,
 
  	switch (event) {
  	case IDH_FLR_NOTIFICATION:
-		if (amdgpu_sriov_runtime(adev) && !amdgpu_in_reset(adev))
+		if (amdgpu_sriov_runtime(adev))
  			WARN_ONCE(!amdgpu_reset_domain_schedule(adev->reset_domain,
  				   &adev->virt.flr_work),
  				  "Failed to queue work! at %s",
drivers/gpu/drm/amd/amdgpu/mxgpu_vi.c +1 -1
index 59f53c743362..14a065516ae4 100644
@@ -560,7 +560,7 @@ static int xgpu_vi_mailbox_rcv_irq(struct amdgpu_device *adev,
  		r = xgpu_vi_mailbox_rcv_msg(adev, IDH_FLR_NOTIFICATION);
 
  		/* only handle FLR_NOTIFY now */
-		if (!r && !amdgpu_in_reset(adev))
+		if (!r)
  			WARN_ONCE(!amdgpu_reset_domain_schedule(adev->reset_domain,
  								&adev->virt.flr_work),
  				  "Failed to queue work! at %s",