drm/amdgpu: Do a basic health check before reset
Subsystems (2)
PATCH 1/1 drm/amdgpu: Do a basic health check before reset
Check if the device is present in the bus before trying to recover. It could be that device itself is lost from the bus in some hang situations.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +24 -0
@@ -5536,6 +5536,23 @@ static inline void amdgpu_device_stop_pending_resets(struct amdgpu_device *adev) } +static int amdgpu_device_health_check (struct list_head *device_list_handle) +{ +struct amdgpu_device *tmp_adev; +int ret =0 ; +u32 status; + +list_for_each_entry (tmp_adev, device_list_handle, reset_list) { +pci_read_config_dword (tmp_adev->pdev,PCI_COMMAND , &status); +if (PCI_POSSIBLE_ERROR (status)) { +dev_err (tmp_adev->dev,"device lost from bus!" ); + ret = -ENODEV ; + } + } + +return ret; +} +/** * amdgpu_device_gpu_recover - reset the asic and recover scheduler *
@@ -5607,6 +5624,12 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev, device_list_handle = &device_list; } +if (!amdgpu_sriov_vf (adev)) { + r =amdgpu_device_health_check (device_list_handle); +if (r) + goto end_reset; + } +/* 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);
@@ -5772,6 +5795,7 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev, reset_list);amdgpu_device_unlock_reset_domain (tmp_adev->reset_domain); +end_reset:if (hive) {mutex_unlock (&hive->hive_lock);amdgpu_put_xgmi_hive (hive);
Signature · 1 line
2.25.1
[AMD Official Use Only - General]
Thanks & Regards
Asad
-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Wednesday, March 13, 2024 3:12 PM
To: [email protected]
Cc: Zhang, Hawking <[email protected]>; Deucher, Alexander <[email protected]>; Kamal, Asad <[email protected]>
Subject: [PATCH] drm/amdgpu: Do a basic health check before reset
Check if the device is present in the bus before trying to recover. It could be that device itself is lost from the bus in some hang situations.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +24 -0
@@ -5536,6 +5536,23 @@ static inline void amdgpu_device_stop_pending_resets(struct amdgpu_device *adev) } +static int amdgpu_device_health_check (struct list_head +*device_list_handle) { +struct amdgpu_device *tmp_adev; +int ret =0 ; +u32 status; + +list_for_each_entry (tmp_adev, device_list_handle, reset_list) { +pci_read_config_dword (tmp_adev->pdev,PCI_COMMAND , &status); +if (PCI_POSSIBLE_ERROR (status)) { +dev_err (tmp_adev->dev,"device lost from bus!" ); + ret = -ENODEV ; + } + } + +return ret; +} +/** * amdgpu_device_gpu_recover - reset the asic and recover scheduler *
@@ -5607,6 +5624,12 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev, device_list_handle = &device_list; } +if (!amdgpu_sriov_vf (adev)) { + r =amdgpu_device_health_check (device_list_handle); +if (r) + goto end_reset; + } +/* 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);
@@ -5772,6 +5795,7 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev, reset_list);amdgpu_device_unlock_reset_domain (tmp_adev->reset_domain); +end_reset:if (hive) {mutex_unlock (&hive->hive_lock);amdgpu_put_xgmi_hive (hive);
--
2.25.1
Quoted 18 lines · Lijo Lazar
Check if the device is present in the bus before trying to recover. It could be that device itself is lost from the bus in some hang situations.
Signed-off-by Lijo Lazar <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1
-0@@ -5536,6 +5536,23 @@ static inline void amdgpu_device_stop_pending_resets(struct amdgpu_device *adev) } +static int amdgpu_device_health_check (struct list_head *device_list_handle)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static inline void amdgpu_device_stop_pending_resets(struct amdgpu_device *adev) · line 5549
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +10
-0+{ +struct amdgpu_device *tmp_adev; +int ret =0 ; +u32 status; + +list_for_each_entry (tmp_adev, device_list_handle, reset_list) { +pci_read_config_dword (tmp_adev->pdev,PCI_COMMAND , &status); +if (PCI_POSSIBLE_ERROR (status)) { +dev_err (tmp_adev->dev,"device lost from bus!" ); + ret = -ENODEV ;
You could just return here. What's the point of looking for other devices if you're going to return an error anyway?
Regards,
Felix
Quoted 30 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +13
-0+ } + } + +return ret; +} +/** * amdgpu_device_gpu_recover - reset the asic and recover scheduler * @@ -5607,6 +5624,12 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev, device_list_handle = &device_list; } +if (!amdgpu_sriov_vf (adev)) { + r =amdgpu_device_health_check (device_list_handle); +if (r) + goto end_reset; + } +/* 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);@@ -5772,6 +5795,7 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev, reset_list);amdgpu_device_unlock_reset_domain (tmp_adev->reset_domain); +end_reset:if (hive) {mutex_unlock (&hive->hive_lock);amdgpu_put_xgmi_hive (hive);
Quoted 26 lines · Felix Kuehling
Quoted 24 lines · Lijo Lazar
Check if the device is present in the bus before trying to recover. It could be that device itself is lost from the bus in some hang situations.
Signed-off-by Lijo Lazar <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c| 24 ++++++++++++++++++++++1 file changed, 24 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0@@ -5536,6 +5536,23 @@ static inline void amdgpu_device_stop_pending_resets(struct amdgpu_device *adev) }+static int
amdgpu_device_health_check(struct list_head *device_list_handle)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +5
-0+{ + struct amdgpu_device *tmp_adev; + int ret = 0; + u32 status; +
Quoted 9 lines
Quoted 5 lines
+
list_for_each_entry(tmp_adev, device_list_handle, reset_list){ +pci_read_config_dword(tmp_adev->pdev, PCI_COMMAND, &status); + if (PCI_POSSIBLE_ERROR(status)) {
+dev_err(tmp_adev->dev, "device lost from bus!"); + ret =-ENODEV;You could just return here. What's the point of looking for other devices if you're going to return an error anyway?
This for XGMI case; the error is primarily for informational purpose to know which all devices in the hive got into a bad state.
Thanks,
Lijo
Quoted 36 lines
Regards,
FelixQuoted 32 lines
+ }
+ }drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4
-0+ + return ret; +} +/**
*amdgpu_device_gpu_recover- reset the asic and recover scheduler *drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +5
-0@@ -5607,6 +5624,12 @@ int amdgpu_device_gpu_recover(structamdgpu_device *adev, device_list_handle = &device_list; } + if (!amdgpu_sriov_vf(adev)) { + r = amdgpu_device_health_check(device_list_handle); + if (r) + goto end_reset; + } + /* We need to lock reset domain only once both for XGMI andsingle device */
tmp_adev= list_first_entry(device_list_handle, structamdgpu_device,
reset_list);drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0@@ -5772,6 +5795,7 @@ int amdgpu_device_gpu_recover(structamdgpu_device *adev, reset_list); amdgpu_device_unlock_reset_domain(tmp_adev->reset_domain);+end_reset:
if (hive) {
mutex_unlock(&hive->hive_lock);
amdgpu_put_xgmi_hive(hive);