Improve suspend callback usage
Subsystems (2)
cover Improve suspend callback usage
The shutdown() callback doesn't use the same code as suspend() callbacks. This series unifies them and then also improves error handling for all suspend flows.
Mario Limonciello (7):
drm/amd: Unify shutdown() callback behavior drm/amd: Stop exporting amdgpu_device_ip_suspend() outside
amdgpu_device
drm/amd: Remove comment about handling errors in
amdgpu_device_ip_suspend_phase1()
drm/amd: Don't always set IP block HW status to false drm/amd: Pass IP suspend errors up to callers drm/amd: Fix error handling with multiple userq IDRs drm/amd: Pass userq suspend failures up to caller
drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 - drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 19 ++++++++++------ drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 25 ++++++++++------------ 4 files changed, 25 insertions(+), 23 deletions(-)
Signature · 1 line
2.51.0
PATCH 1/7 drm/amd: Unify shutdown() callback behavior
[Why]
The shutdown() callback uses amdgpu_ip_suspend() which doesn't notify drm clients during shutdown. This could lead to hangs.
[How]
Change amdgpu_pci_shutdown() to call the same sequence as suspend/resume.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -1
@@ -2558,7 +2558,8 @@ amdgpu_pci_shutdown(struct pci_dev *pdev)*/ if (!amdgpu_passthrough (adev)) adev->mp1_state =PP_MP1_STATE_UNLOAD ; -amdgpu_device_ip_suspend (adev); +amdgpu_device_prepare (dev); +amdgpu_device_suspend (dev, true); adev->mp1_state =PP_MP1_STATE_NONE ; }
Signature · 1 line
2.51.0
Re: [PATCH 1/7] drm/amd: Unify shutdown() callback behavior
Quoted 18 lines · Mario Limonciello
[Why]
Theshutdown()callback usesamdgpu_ip_suspend()which doesn't notify drm clients during shutdown. This could lead to hangs.[How]
Changeamdgpu_pci_shutdown()to call the same sequence as suspend/resume.Signed-off-by Mario Limonciello <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c amdgpu_pci_shutdown(struct pci_dev *pdev) · line 2562
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2
-1@@ -2558,7 +2558,8 @@ amdgpu_pci_shutdown(struct pci_dev *pdev)*/ if (!amdgpu_passthrough (adev)) adev->mp1_state =PP_MP1_STATE_UNLOAD ; -amdgpu_device_ip_suspend (adev); +amdgpu_device_prepare (dev); +amdgpu_device_suspend (dev, true);
I think we did this before, but users complained that it took longer to shut down their systems.
Alex
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0
-1adev->mp1_state =PP_MP1_STATE_NONE ; } --2.51.0
Re: [PATCH 1/7] drm/amd: Unify shutdown() callback behavior
Quoted 15 lines · Alex Deucher
Quoted 13 lines · Mario Limonciello
[Why]
Theshutdown()callback usesamdgpu_ip_suspend()which doesn't notify drm clients during shutdown. This could lead to hangs.[How]
Changeamdgpu_pci_shutdown()to call the same sequence as suspend/resume.Signed-off-by Mario Limonciello <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c amdgpu_pci_shutdown(struct pci_dev *pdev) · line 2562
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2
-1@@ -2558,7 +2558,8 @@ amdgpu_pci_shutdown(struct pci_dev *pdev)*/ if (!amdgpu_passthrough (adev)) adev->mp1_state =PP_MP1_STATE_UNLOAD ; -amdgpu_device_ip_suspend (adev); +amdgpu_device_prepare (dev); +amdgpu_device_suspend (dev, true);I think we did this before, but users complained that it took longer to shut down their systems.
That's presumably from the evictions. I think that it should be improved because we now have:
drm/amd: Avoid evicting resources at S5
Quoted 9 lines
Alex
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0
-1adev->mp1_state =PP_MP1_STATE_NONE ; } --2.51.0
Alex Deucher
Reviewed-byRe: [PATCH 1/7] drm/amd: Unify shutdown() callback behavior
Quoted 32 lines · Mario Limonciello
Quoted 15 lines · Alex Deucher
Quoted 13 lines · Mario Limonciello
[Why]
Theshutdown()callback usesamdgpu_ip_suspend()which doesn't notify drm clients during shutdown. This could lead to hangs.[How]
Changeamdgpu_pci_shutdown()to call the same sequence as suspend/resume.Signed-off-by Mario Limonciello <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c amdgpu_pci_shutdown(struct pci_dev *pdev) · line 2562
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2
-1@@ -2558,7 +2558,8 @@ amdgpu_pci_shutdown(struct pci_dev *pdev)*/ if (!amdgpu_passthrough (adev)) adev->mp1_state =PP_MP1_STATE_UNLOAD ; -amdgpu_device_ip_suspend (adev); +amdgpu_device_prepare (dev); +amdgpu_device_suspend (dev, true);I think we did this before, but users complained that it took longer to shut down their systems.
Quoted 4 lines
That's presumably from the evictions. I think that it should be improved because we now have:
drm/amd: Avoid evicting resources at S5
That makes sense. The series is:
Quoted 11 lines
Quoted 10 lines
Alex
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0
-1adev->mp1_state =PP_MP1_STATE_NONE ; } --2.51.0
PATCH 2/7 drm/amd: Stop exporting amdgpu_device_ip_suspend() outside amdgpu_device
In reply to Mario Limoncielloamdgpu_device_ip_suspend() doesn't have a caller outside of amdgpu_device.c. Make it static.
No intended functional changes.
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 - drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -1
@@ -1637,7 +1637,6 @@ void amdgpu_driver_postclose_kms(struct drm_device *dev, struct drm_file *file_priv);void amdgpu_driver_release_kms (struct drm_device *dev); -int amdgpu_device_ip_suspend (struct amdgpu_device *adev);int amdgpu_device_prepare (struct drm_device *dev);void amdgpu_device_complete (struct drm_device *dev);int amdgpu_device_suspend (struct drm_device *dev,bool fbcon);
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
@@ -3888,7 +3888,7 @@ static int amdgpu_device_ip_suspend_phase2(struct amdgpu_device *adev)* in each IP into a state suitable for suspend. * Returns 0 on success, negative error code on failure. */ -int amdgpu_device_ip_suspend (struct amdgpu_device *adev) +static int amdgpu_device_ip_suspend (struct amdgpu_device *adev) {int r;
Signature · 1 line
2.51.0
PATCH 3/7 drm/amd: Remove comment about handling errors in amdgpu_device_ip_suspend_phase1()
In reply to Mario LimoncielloError handling was introduced in commit e095026f0066e ("drm/amdgpu:
validate suspend before function call") so the comment about TODO is no longer needed.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 1 - 1 file changed, 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -1
@@ -3773,7 +3773,6 @@ static int amdgpu_device_ip_suspend_phase1(struct amdgpu_device *adev)if (adev->ip_blocks[i].version->type !=AMD_IP_BLOCK_TYPE_DCE )continue ; -/* XXX handle errors */ r =amdgpu_ip_block_suspend (&adev->ip_blocks[i]);if (r)return r;
Signature · 1 line
2.51.0
Re: [PATCH 3/7] drm/amd: Remove comment about handling errors in amdgpu_device_ip_suspend_phase1()
Quoted 7 lines · Mario Limonciello
Error handling was introduced in commit
e095026f0066e("drm/amdgpu:
validate suspend before function call") so the comment about TODO is no longer needed.Fixes e095026f0066e ("drm/amdgpu: validate suspend before function call")Signed-off-by Mario Limonciello <[email protected]>
Quoted 19 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 1 - 1 file changed, 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-2@@ -3773,7 +3773,6 @@ static int amdgpu_device_ip_suspend_phase1(struct amdgpu_device *adev)if (adev->ip_blocks[i].version->type !=AMD_IP_BLOCK_TYPE_DCE )continue ; -/* XXX handle errors */ r =amdgpu_ip_block_suspend (&adev->ip_blocks[i]);if (r)return r; --2.51.0
PATCH 4/7 drm/amd: Don't always set IP block HW status to false
In reply to Mario Limoncielloamdgpu_device_ip_suspend_phase2() calls amdgpu_ip_block_suspend() which already sets HW block status to false when succeeding with IP suspend. Remove the explicit call in amdgpu_device_ip_suspend_phase2() so that the status is accurate.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 1 - 1 file changed, 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -1
@@ -3857,7 +3857,6 @@ static int amdgpu_device_ip_suspend_phase2(struct amdgpu_device *adev)/* XXX handle errors */ r =amdgpu_ip_block_suspend (&adev->ip_blocks[i]); - adev->ip_blocks[i].status.hw = false;/* handle putting the SMC in the appropriate state */ if (!amdgpu_sriov_vf (adev)) {
Signature · 1 line
2.51.0
PATCH 5/7 drm/amd: Pass IP suspend errors up to callers
In reply to Mario LimoncielloIf IP suspend fails the callers should be notified so that they can potentially react.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +8 -3
@@ -3855,8 +3855,9 @@ static int amdgpu_device_ip_suspend_phase2(struct amdgpu_device *adev) adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_PSP)continue ; -/* XXX handle errors */ r =amdgpu_ip_block_suspend (&adev->ip_blocks[i]); +if (r) +return r;/* handle putting the SMC in the appropriate state */ if (!amdgpu_sriov_vf (adev)) {
@@ -5216,7 +5217,9 @@ int amdgpu_device_suspend(struct drm_device *dev, bool notify_clients)amdgpu_ras_suspend (adev); -amdgpu_device_ip_suspend_phase1 (adev); + r =amdgpu_device_ip_suspend_phase1 (adev); +if (r) +return r;amdgpu_amdkfd_suspend (adev, !amdgpu_sriov_vf (adev) && !adev->in_runpm);amdgpu_userq_suspend (adev);
@@ -5229,7 +5232,9 @@ int amdgpu_device_suspend(struct drm_device *dev, bool notify_clients)amdgpu_fence_driver_hw_fini (adev); -amdgpu_device_ip_suspend_phase2 (adev); + r =amdgpu_device_ip_suspend_phase2 (adev); +if (r) +return r;if (amdgpu_sriov_vf (adev))amdgpu_virt_release_full_gpu (adev, false);
Signature · 1 line
2.51.0
PATCH 6/7 drm/amd: Fix error handling with multiple userq IDRs
In reply to Mario LimoncielloIf multiple userq IDR are in use and there is an error handling one at suspend or resume it will be silently discarded.
Switch the suspend/resume() code to use guards and return immediately.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 25 ++++++++++------------- 1 file changed, 11 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +11 -14
@@ -967,27 +967,25 @@ int amdgpu_userq_suspend(struct amdgpu_device *adev)struct amdgpu_usermode_queue *queue;struct amdgpu_userq_mgr *uqm, *tmp;int queue_id; -int ret =0 , r; +int r;if (!ip_mask)return 0 ; -mutex_lock (&adev->userq_mutex); +guard (mutex)(&adev->userq_mutex);list_for_each_entry_safe (uqm, tmp, &adev->userq_mgr_list, list) {cancel_delayed_work_sync (&uqm->resume_work); -mutex_lock (&uqm->userq_mutex); +guard (mutex)(&uqm->userq_mutex);idr_for_each_entry (&uqm->userq_idr, queue, queue_id) {if (adev->in_s0ix) r =amdgpu_userq_preempt_helper (uqm, queue);else r =amdgpu_userq_unmap_helper (uqm, queue);if (r) - ret = r; +return r; } -mutex_unlock (&uqm->userq_mutex); } -mutex_unlock (&adev->userq_mutex); -return ret; +return 0 ; }int amdgpu_userq_resume (struct amdgpu_device *adev)
@@ -996,26 +994,25 @@ int amdgpu_userq_resume(struct amdgpu_device *adev)struct amdgpu_usermode_queue *queue;struct amdgpu_userq_mgr *uqm, *tmp;int queue_id; -int ret =0 , r; +int r;if (!ip_mask)return 0 ; -mutex_lock (&adev->userq_mutex); +guard (mutex)(&adev->userq_mutex);list_for_each_entry_safe (uqm, tmp, &adev->userq_mgr_list, list) { -mutex_lock (&uqm->userq_mutex); +guard (mutex)(&uqm->userq_mutex);idr_for_each_entry (&uqm->userq_idr, queue, queue_id) {if (adev->in_s0ix) r =amdgpu_userq_restore_helper (uqm, queue);else r =amdgpu_userq_map_helper (uqm, queue);if (r) - ret = r; +return r; } -mutex_unlock (&uqm->userq_mutex); } -mutex_unlock (&adev->userq_mutex); -return ret; + +return 0 ; } int amdgpu_userq_stop_sched_for_enforce_isolation(struct amdgpu_device *adev,
Signature · 1 line
2.51.0
PATCH 7/7 drm/amd: Pass userq suspend failures up to caller
In reply to Mario LimoncielloIf a userq failed to suspend the rest of the suspend sequence may have problems. Pass the error code up to the caller for a decision on what to do.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -1
@@ -5222,7 +5222,9 @@ int amdgpu_device_suspend(struct drm_device *dev, bool notify_clients)return r;amdgpu_amdkfd_suspend (adev, !amdgpu_sriov_vf (adev) && !adev->in_runpm); -amdgpu_userq_suspend (adev); + r =amdgpu_userq_suspend (adev); +if (r) +return r; r =amdgpu_device_evict_resources (adev);if (r)
Signature · 1 line
2.51.0
Quoted 15 lines · Mario Limonciello
The
shutdown()callback doesn't use the same code assuspend()callbacks. This series unifies them and then also improves error handling for all suspend flows.Mario Limonciello (7):
drm/amd: Unifyshutdown()callback behavior drm/amd: Stop exportingamdgpu_device_ip_suspend()outside
amdgpu_device
drm/amd: Remove comment about handling errors in
amdgpu_device_ip_suspend_phase1()
drm/amd: Don't always set IP block HW status to false drm/amd: Pass IP suspend errors up to callers drm/amd: Fix error handling with multiple userq IDRs drm/amd: Pass userq suspend failures up to caller
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 - drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 19 ++++++++++------ drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 25 ++++++++++------------ 4 files changed, 25 insertions(+), 23 deletions(-)
ping?