drm/amdgpu: Fix two reset triggered in a row
Subsystems (3)
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
@@ -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
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
Signed-off-by Yunxiang Li <[email protected]>--- 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@@ -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
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.
Acked-by Alex Deucher <[email protected]>
Quoted 22 lines
Quoted 22 lines
Signed-off-by Yunxiang Li <[email protected]>--- 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@@ -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
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.
Signed-off-by Yunxiang Li <[email protected]>--- 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
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}
[Public]
Quoted 2 lines
We can't do this technically as there are cases where we skip full device reset (even then
amdgpu_in_resetwill return true). The better thing to do is to moveamdgpu_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.
Christian König
maintainerAm 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_resetwill return true). The better thing to do is to moveamdgpu_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.
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
Signed-off-by Yunxiang Li <[email protected]>--- 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@@ -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); }
Felix Kuehling
maintainerQuoted 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
Signed-off-by Yunxiang Li <[email protected]>---
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@@ -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);}
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,
FelixQuoted 25 lines
Regards,
Christian.Quoted 20 lines
Signed-off-by Yunxiang Li <[email protected]>---
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@@ -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);}
[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
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.
[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.
PATCH v2 1/1 drm/amdgpu: Fix two reset triggered in a row
In reply to Yunxiang LiSome 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
Christian König
maintainerAm 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_resetsthey will be able to trigger an unnecessary reset.Move
amdgpu_device_stop_pending_resetsto after the reset is already done, since any reset scheduled after that point would be legitimate. Remove unnecessary and incorrect checks foramdgpu_in_resetthat was kinda serving this purpose.Signed-off-by Yunxiang Li <[email protected]>
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 addingamdgpu_in_resetcheck, move when we cancel pending resetsdrivers/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@@ -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@@ -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@@ -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@@ -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@@ -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",