drm/amdgpu: Lock reset domain when VF get host FLR work message
Subsystems (2)
PATCH 1/1 drm/amdgpu: Lock reset domain when VF get host FLR work message
[Why]
When host detected FLR earlier than guest, it will do HW reset. Under multi process scenario, MES could use hardware resource and failed, if host complete FLR work.
[How]
- Lock reset domain in *mailbox_flr_work
- Use AMDGPU_HOST_FLR flag checking in gpu recover to aviod double locking
- Clear AMDGPU_HOST_FLR bit after recovery completes
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 7 ++++--- drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c | 4 ++++ drivers/gpu/drm/amd/amdgpu/mxgpu_nv.c | 4 ++++ drivers/gpu/drm/amd/amdgpu/mxgpu_vi.c | 4 ++++ 4 files changed, 16 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4 -3
@@ -5413,7 +5413,6 @@ static int amdgpu_device_reset_sriov(struct amdgpu_device *adev,if (!amdgpu_ras_get_fed_status (adev))amdgpu_virt_ready_to_reset (adev);amdgpu_virt_wait_reset (adev); -clear_bit (AMDGPU_HOST_FLR , &reset_context->flags); r =amdgpu_virt_request_full_gpu (adev, true); }else { r =amdgpu_virt_reset_gpu (adev);
@@ -6098,7 +6097,8 @@ static int amdgpu_device_halt_activities(struct amdgpu_device *adev,/* We need to lock reset domain only once both for XGMI and single device */ tmp_adev = list_first_entry(device_list_handle, struct amdgpu_device, reset_list); -amdgpu_device_lock_reset_domain (tmp_adev->reset_domain); +if (!test_bit (AMDGPU_HOST_FLR , &reset_context->flags)) +amdgpu_device_lock_reset_domain (tmp_adev->reset_domain);/* block all schedulers and reset given job's ring */ list_for_each_entry (tmp_adev, device_list_handle, reset_list) {
@@ -6293,7 +6293,8 @@ static void amdgpu_device_gpu_resume(struct amdgpu_device *adev, tmp_adev = list_first_entry(device_list, struct amdgpu_device, reset_list); -amdgpu_device_unlock_reset_domain (tmp_adev->reset_domain); +if (!test_bit (AMDGPU_HOST_FLR , &reset_context->flags)) +amdgpu_device_unlock_reset_domain (tmp_adev->reset_domain); }
drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c +4 -0
@@ -287,8 +287,12 @@ static void xgpu_ai_mailbox_flr_work(struct work_struct *work) reset_context.reset_req_dev = adev;clear_bit (AMDGPU_NEED_FULL_RESET , &reset_context.flags);set_bit (AMDGPU_HOST_FLR , &reset_context.flags); +amdgpu_device_lock_reset_domain (adev->reset_domain);amdgpu_device_gpu_recover (adev,NULL , &reset_context); + +amdgpu_device_unlock_reset_domain (adev->reset_domain); +clear_bit (AMDGPU_HOST_FLR , &reset_context.flags); } }
drivers/gpu/drm/amd/amdgpu/mxgpu_nv.c +4 -0
@@ -354,8 +354,12 @@ static void xgpu_nv_mailbox_flr_work(struct work_struct *work) reset_context.reset_req_dev = adev;clear_bit (AMDGPU_NEED_FULL_RESET , &reset_context.flags);set_bit (AMDGPU_HOST_FLR , &reset_context.flags); +amdgpu_device_lock_reset_domain (adev->reset_domain);amdgpu_device_gpu_recover (adev,NULL , &reset_context); + +amdgpu_device_unlock_reset_domain (adev->reset_domain); +clear_bit (AMDGPU_HOST_FLR , &reset_context.flags); } }
drivers/gpu/drm/amd/amdgpu/mxgpu_vi.c +4 -0
@@ -524,8 +524,12 @@ static void xgpu_vi_mailbox_flr_work(struct work_struct *work) reset_context.reset_req_dev = adev;clear_bit (AMDGPU_NEED_FULL_RESET , &reset_context.flags);set_bit (AMDGPU_HOST_FLR , &reset_context.flags); +amdgpu_device_lock_reset_domain (adev->reset_domain);amdgpu_device_gpu_recover (adev,NULL , &reset_context); + +amdgpu_device_unlock_reset_domain (adev->reset_domain); +clear_bit (AMDGPU_HOST_FLR , &reset_context.flags); } }
Signature · 1 line
2.25.1
[Public]
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_device_halt_activities(struct amdgpu_device *adev, · line 6104
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2
-1@@ -6098,7 +6097,8 @@ static int amdgpu_device_halt_activities(struct amdgpu_device *adev,/* We need to lock reset domain only once both for XGMI and single device */ tmp_adev = list_first_entry(device_list_handle, struct amdgpu_device, reset_list); -amdgpu_device_lock_reset_domain (tmp_adev->reset_domain); +if (!test_bit (AMDGPU_HOST_FLR , &reset_context->flags)) +amdgpu_device_lock_reset_domain (tmp_adev->reset_domain);/* block all schedulers and reset given job's ring */ list_for_each_entry (tmp_adev, device_list_handle, reset_list) {
The host should be waiting for amdgpu_virt_ready_to_reset before it reset, which happens after amdgpu_device_halt_activities, so I think the lock here is fine. Is the host side wait timing out for you? If so the root cause should be that we take too long to halt guest activity.
Teddy
Christian König
maintainerQuoted 31 lines · Yifan Zha
[Why]
When host detected FLR earlier than guest, it will do HW reset. Under multi process scenario, MES could use hardware resource and failed, if host complete FLR work.[How]
- Lock reset domain in*mailbox_flr_work
- UseAMDGPU_HOST_FLRflag checking in gpu recover to aviod double locking
- ClearAMDGPU_HOST_FLRbit after recovery completesSigned-off-by Yifan Zha <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 7 ++++--- drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c | 4 ++++ drivers/gpu/drm/amd/amdgpu/mxgpu_nv.c | 4 ++++ drivers/gpu/drm/amd/amdgpu/mxgpu_vi.c | 4 ++++ 4 files changed, 16 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-1@@ -5413,7 +5413,6 @@ static int amdgpu_device_reset_sriov(struct amdgpu_device *adev,if (!amdgpu_ras_get_fed_status (adev))amdgpu_virt_ready_to_reset (adev);amdgpu_virt_wait_reset (adev); -clear_bit (AMDGPU_HOST_FLR , &reset_context->flags); r =amdgpu_virt_request_full_gpu (adev, true); }else { r =amdgpu_virt_reset_gpu (adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_device_gpu_recover(struct amdgpu_device *adev, · line 6101
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2
-1@@ -6098,7 +6097,8 @@ static int amdgpu_device_gpu_recover(struct amdgpu_device *adev,/* We need to lock reset domain only once both for XGMI and single device */ tmp_adev = list_first_entry(device_list_handle, struct amdgpu_device, reset_list); -amdgpu_device_lock_reset_domain (tmp_adev->reset_domain); +if (!test_bit (AMDGPU_HOST_FLR , &reset_context->flags)) +amdgpu_device_lock_reset_domain (tmp_adev->reset_domain);
Clear NAK to that.
As far as I can see the health check and other operations are intentional outside of the lock.
Regards,
Christian.
Quoted 64 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2
-1/* block all schedulers and reset given job's ring */ list_for_each_entry (tmp_adev, device_list_handle, reset_list) {@@ -6293,7 +6293,8 @@ static void amdgpu_device_gpu_resume(struct amdgpu_device *adev, tmp_adev = list_first_entry(device_list, struct amdgpu_device, reset_list); -amdgpu_device_unlock_reset_domain (tmp_adev->reset_domain); +if (!test_bit (AMDGPU_HOST_FLR , &reset_context->flags)) +amdgpu_device_unlock_reset_domain (tmp_adev->reset_domain); }drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c +4
-0@@ -287,8 +287,12 @@ static void xgpu_ai_mailbox_flr_work(struct work_struct *work) reset_context.reset_req_dev = adev;clear_bit (AMDGPU_NEED_FULL_RESET , &reset_context.flags);set_bit (AMDGPU_HOST_FLR , &reset_context.flags); +amdgpu_device_lock_reset_domain (adev->reset_domain);amdgpu_device_gpu_recover (adev,NULL , &reset_context); + +amdgpu_device_unlock_reset_domain (adev->reset_domain); +clear_bit (AMDGPU_HOST_FLR , &reset_context.flags); } }drivers/gpu/drm/amd/amdgpu/mxgpu_nv.c +4
-0@@ -354,8 +354,12 @@ static void xgpu_nv_mailbox_flr_work(struct work_struct *work) reset_context.reset_req_dev = adev;clear_bit (AMDGPU_NEED_FULL_RESET , &reset_context.flags);set_bit (AMDGPU_HOST_FLR , &reset_context.flags); +amdgpu_device_lock_reset_domain (adev->reset_domain);amdgpu_device_gpu_recover (adev,NULL , &reset_context); + +amdgpu_device_unlock_reset_domain (adev->reset_domain); +clear_bit (AMDGPU_HOST_FLR , &reset_context.flags); } }drivers/gpu/drm/amd/amdgpu/mxgpu_vi.c +4
-0@@ -524,8 +524,12 @@ static void xgpu_vi_mailbox_flr_work(struct work_struct *work) reset_context.reset_req_dev = adev;clear_bit (AMDGPU_NEED_FULL_RESET , &reset_context.flags);set_bit (AMDGPU_HOST_FLR , &reset_context.flags); +amdgpu_device_lock_reset_domain (adev->reset_domain);amdgpu_device_gpu_recover (adev,NULL , &reset_context); + +amdgpu_device_unlock_reset_domain (adev->reset_domain); +clear_bit (AMDGPU_HOST_FLR , &reset_context.flags); } }
[AMD Official Use Only - AMD Internal Distribution Only]
Thanks Christian and Teddy for reviewing.
You are right, it is not good to get reset domain lock earlier.
The root cause is host driver did not waiting for guest response of FLR. It should be an expected behaviour.
We will change our DTP. So please ignore this patch.
Thanks.
Best regard,
Yifan Zha
________________________________
From: Koenig, Christian <[email protected]>
Sent: Wednesday, June 4, 2025 7:45 PM
To: Zha, YiFan(Even) <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; Deucher, Alexander <[email protected]>
Cc: Chen, Horace <[email protected]>; Deng, Emily <[email protected]>; Li, Yunxiang (Teddy) <[email protected]>; Yin, ZhenGuo (Chris) <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: Lock reset domain when VF get host FLR work message
Quoted 31 lines · Yifan Zha
[Why]
When host detected FLR earlier than guest, it will do HW reset. Under multi process scenario, MES could use hardware resource and failed, if host complete FLR work.[How]
- Lock reset domain in*mailbox_flr_work
- UseAMDGPU_HOST_FLRflag checking in gpu recover to aviod double locking
- ClearAMDGPU_HOST_FLRbit after recovery completesSigned-off-by Yifan Zha <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 7 ++++--- drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c | 4 ++++ drivers/gpu/drm/amd/amdgpu/mxgpu_nv.c | 4 ++++ drivers/gpu/drm/amd/amdgpu/mxgpu_vi.c | 4 ++++ 4 files changed, 16 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-1@@ -5413,7 +5413,6 @@ static int amdgpu_device_reset_sriov(struct amdgpu_device *adev,if (!amdgpu_ras_get_fed_status (adev))amdgpu_virt_ready_to_reset (adev);amdgpu_virt_wait_reset (adev); -clear_bit (AMDGPU_HOST_FLR , &reset_context->flags); r =amdgpu_virt_request_full_gpu (adev, true); }else { r =amdgpu_virt_reset_gpu (adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_device_gpu_recover(struct amdgpu_device *adev, · line 6101
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2
-1@@ -6098,7 +6097,8 @@ static int amdgpu_device_gpu_recover(struct amdgpu_device *adev,/* We need to lock reset domain only once both for XGMI and single device */ tmp_adev = list_first_entry(device_list_handle, struct amdgpu_device, reset_list); -amdgpu_device_lock_reset_domain (tmp_adev->reset_domain); +if (!test_bit (AMDGPU_HOST_FLR , &reset_context->flags)) +amdgpu_device_lock_reset_domain (tmp_adev->reset_domain);
Clear NAK to that.
As far as I can see the health check and other operations are intentional outside of the lock.
Regards,
Christian.
Quoted 64 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2
-1/* block all schedulers and reset given job's ring */ list_for_each_entry (tmp_adev, device_list_handle, reset_list) {@@ -6293,7 +6293,8 @@ static void amdgpu_device_gpu_resume(struct amdgpu_device *adev, tmp_adev = list_first_entry(device_list, struct amdgpu_device, reset_list); -amdgpu_device_unlock_reset_domain (tmp_adev->reset_domain); +if (!test_bit (AMDGPU_HOST_FLR , &reset_context->flags)) +amdgpu_device_unlock_reset_domain (tmp_adev->reset_domain); }drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c +4
-0@@ -287,8 +287,12 @@ static void xgpu_ai_mailbox_flr_work(struct work_struct *work) reset_context.reset_req_dev = adev;clear_bit (AMDGPU_NEED_FULL_RESET , &reset_context.flags);set_bit (AMDGPU_HOST_FLR , &reset_context.flags); +amdgpu_device_lock_reset_domain (adev->reset_domain);amdgpu_device_gpu_recover (adev,NULL , &reset_context); + +amdgpu_device_unlock_reset_domain (adev->reset_domain); +clear_bit (AMDGPU_HOST_FLR , &reset_context.flags); } }drivers/gpu/drm/amd/amdgpu/mxgpu_nv.c +4
-0@@ -354,8 +354,12 @@ static void xgpu_nv_mailbox_flr_work(struct work_struct *work) reset_context.reset_req_dev = adev;clear_bit (AMDGPU_NEED_FULL_RESET , &reset_context.flags);set_bit (AMDGPU_HOST_FLR , &reset_context.flags); +amdgpu_device_lock_reset_domain (adev->reset_domain);amdgpu_device_gpu_recover (adev,NULL , &reset_context); + +amdgpu_device_unlock_reset_domain (adev->reset_domain); +clear_bit (AMDGPU_HOST_FLR , &reset_context.flags); } }drivers/gpu/drm/amd/amdgpu/mxgpu_vi.c +4
-0@@ -524,8 +524,12 @@ static void xgpu_vi_mailbox_flr_work(struct work_struct *work) reset_context.reset_req_dev = adev;clear_bit (AMDGPU_NEED_FULL_RESET , &reset_context.flags);set_bit (AMDGPU_HOST_FLR , &reset_context.flags); +amdgpu_device_lock_reset_domain (adev->reset_domain);amdgpu_device_gpu_recover (adev,NULL , &reset_context); + +amdgpu_device_unlock_reset_domain (adev->reset_domain); +clear_bit (AMDGPU_HOST_FLR , &reset_context.flags); } }