drm/amdgpu: handle the case of pci_channel_io_frozen only in amdgpu_pci_resume
Subsystems (2)
PATCH 1/1 drm/amdgpu: handle the case of pci_channel_io_frozen only in amdgpu_pci_resume
In current code, when a PCI error state pci_channel_io_normal is detectd, it will report PCI_ERS_RESULT_CAN_RECOVER status to PCI driver, and PCI driver will continue the execution of PCI resume callback report_resume by pci_walk_bridge, and the callback will go into amdgpu_pci_resume finally, where write lock is releasd unconditionally without acquiring such lock first. In this case, a deadlock will happen when other threads start to acquire the read lock.
To fix this, add a member in amdgpu_device strucutre to cache pci_channel_state, and only continue the execution in amdgpu_pci_resume when it's pci_channel_io_frozen.
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 6 ++++++ 2 files changed, 7 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
@@ -1094,6 +1094,7 @@ struct amdgpu_device {bool no_hw_access;struct pci_saved_state *pci_state; +pci_channel_state_t cached_state;struct amdgpu_reset_control *reset_cntl;uint32_t ip_versions[HW_ID_MAX ][HWIP_MAX_INSTANCE ];
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +6 -0
@@ -5368,6 +5368,8 @@ pci_ers_result_t amdgpu_pci_error_detected(struct pci_dev *pdev, pci_channel_stareturn PCI_ERS_RESULT_DISCONNECT ; } + adev->cached_state = state; +switch (state) {case pci_channel_io_normal:return PCI_ERS_RESULT_CAN_RECOVER ;
@@ -5510,6 +5512,10 @@ void amdgpu_pci_resume(struct pci_dev *pdev)DRM_INFO ("PCI error: resume callback!!\n" ); +/* Only continue execution for the case of pci_channel_io_frozen */ +if (adev->cached_state != pci_channel_io_frozen) +return ; +for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) {struct amdgpu_ring *ring = adev->rings[i];
Signature · 1 line
2.17.1
Quoted 25 lines · Guchun Chen
In current code, when a PCI error state
pci_channel_io_normalis detectd, it will reportPCI_ERS_RESULT_CAN_RECOVERstatus to PCI driver, and PCI driver will continue the execution of PCI resume callbackreport_resumebypci_walk_bridge, and the callback will go intoamdgpu_pci_resumefinally, where write lock is releasd unconditionally without acquiring such lock first. In this case, a deadlock will happen when other threads start to acquire the read lock.To fix this, add a member in
amdgpu_devicestrucutre to cachepci_channel_state, and only continue the execution inamdgpu_pci_resumewhen it'spci_channel_io_frozen.Fixes c9a6b82f45e2("drm/amdgpu: Implement DPC recovery")Suggested-by Andrey Grodzovsky <[email protected]>Signed-off-by Guchun Chen <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 6 ++++++ 2 files changed, 7 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu.h struct amdgpu_device { · line 1097
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0@@ -1094,6 +1094,7 @@ struct amdgpu_device {bool no_hw_access;struct pci_saved_state *pci_state; +pci_channel_state_t cached_state;
I would give a more descriptive name to this (e.g. pci_channel_state) Other then that Reviewed-by: Andrey Grodzovsky <[email protected]>
Andrey
Quoted 27 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0struct amdgpu_reset_control *reset_cntl;uint32_t ip_versions[HW_ID_MAX ][HWIP_MAX_INSTANCE ];drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +6
-0@@ -5368,6 +5368,8 @@ pci_ers_result_t amdgpu_pci_error_detected(struct pci_dev *pdev, pci_channel_stareturn PCI_ERS_RESULT_DISCONNECT ; } + adev->cached_state = state; +switch (state) {case pci_channel_io_normal:return PCI_ERS_RESULT_CAN_RECOVER ;@@ -5510,6 +5512,10 @@ void amdgpu_pci_resume(struct pci_dev *pdev)DRM_INFO ("PCI error: resume callback!!\n" ); +/* Only continue execution for the case of pci_channel_io_frozen */ +if (adev->cached_state != pci_channel_io_frozen) +return ; +for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) {struct amdgpu_ring *ring = adev->rings[i];
[Public]
Thanks Andrey, I will update the name to be " pci_channel_state " when submitting.
Regards,
Guchun
-----Original Message-----
From: Grodzovsky, Andrey <[email protected]>
Sent: Tuesday, October 5, 2021 12:04 AM
To: Chen, Guchun <[email protected]>; [email protected]; Koenig, Christian <[email protected]>; Pan, Xinhui <[email protected]>; Deucher, Alexander <[email protected]>; Liu, Monk <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: handle the case of pci_channel_io_frozen only in amdgpu_pci_resume
Quoted 26 lines · Guchun Chen
In current code, when a PCI error state
pci_channel_io_normalis detectd, it will reportPCI_ERS_RESULT_CAN_RECOVERstatus to PCI driver, and PCI driver will continue the execution of PCI resume callbackreport_resumebypci_walk_bridge, and the callback will go intoamdgpu_pci_resumefinally, where write lock is releasd unconditionally without acquiring such lock first. In this case, a deadlock will happen when other threads start to acquire the read lock.To fix this, add a member in
amdgpu_devicestrucutre to cachepci_channel_state, and only continue the execution inamdgpu_pci_resumewhen it'spci_channel_io_frozen.Fixes c9a6b82f45e2("drm/amdgpu: Implement DPC recovery")Suggested-by Andrey Grodzovsky <[email protected]>Signed-off-by Guchun Chen <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 6 ++++++ 2 files changed, 7 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu.h struct amdgpu_device { · line 1097
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0@@ -1094,6 +1094,7 @@ struct amdgpu_device {bool no_hw_access;struct pci_saved_state *pci_state; +pci_channel_state_t cached_state;
I would give a more descriptive name to this (e.g. pci_channel_state) Other then that Reviewed-by: Andrey Grodzovsky <[email protected]>
Andrey
Quoted 28 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0struct amdgpu_reset_control *reset_cntl;uint32_t ip_versions[HW_ID_MAX ][HWIP_MAX_INSTANCE ];drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2
-0@@ -5368,6 +5368,8 @@ pci_ers_result_t amdgpu_pci_error_detected(struct pci_dev *pdev, pci_channel_stareturn PCI_ERS_RESULT_DISCONNECT ; } + adev->cached_state = state; +switch (state) {case pci_channel_io_normal: return PCI_ERS_RESULT_CAN_RECOVER; @@ -5510,6 +5512,10 @@ void
amdgpu_pci_resume(struct pci_dev *pdev)DRM_INFO("PCI error: resume callback!!\n");drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4
-0+/* Only continue execution for the case of pci_channel_io_frozen */ +if (adev->cached_state != pci_channel_io_frozen) +return ; +for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) {struct amdgpu_ring *ring = adev->rings[i];