Skip to contentSkip to conversation

drm/amdgpu: refine eeprom data check

PATCH In review ganglxie 4 participants 5 messages Jul 11, 2025

Subsystems (2)
lore
Share & tools
lore

ganglxie

author
#0 lore raw

PATCH 1/2 drm/amdgpu: refine eeprom data check

add eeprom data checksum check before driver unload. reset eeprom and save correct data to eeprom when check failed

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       |  1 +
 .../gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c    | 25 +++++++++++++++++++
 .../gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.h    |  2 ++
 3 files changed, 28 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -0
index 571b70da4562..1009b60f6ae4 100644
@@ -2560,6 +2560,7 @@ amdgpu_pci_remove(struct pci_dev *pdev)
 	struct drm_device *dev = pci_get_drvdata(pdev);
 	struct amdgpu_device *adev = drm_to_adev(dev);
 
+	amdgpu_ras_eeprom_check_and_recover(adev);
 	amdgpu_xcp_dev_unplug(adev);
 	amdgpu_gmc_prepare_nps_mode_change(adev);
 	drm_dev_unplug(dev);
drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c +25 -0
index 2af14c369bb9..2458c67526c9 100644
@@ -1522,3 +1522,28 @@ int amdgpu_ras_eeprom_check(struct amdgpu_ras_eeprom_control *control)
 
 	return res < 0 ? res : 0;
 }
+
+void amdgpu_ras_eeprom_check_and_recover(struct amdgpu_device *adev)
+{
+	struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
+	struct amdgpu_ras_eeprom_control *control = &ras->eeprom_control;
+	int res = 0;
+
+	if (!control->is_eeprom_valid)
+		return;
+	res = __verify_ras_table_checksum(control);
+	if (res) {
+		dev_warn(adev->dev,
+			"RAS table incorrect checksum or error:%d, try to recover\n",
+			res);
+		if (!amdgpu_ras_eeprom_reset_table(control))
+			if (!amdgpu_ras_save_bad_pages(adev, NULL))
+				if (!__verify_ras_table_checksum(control)) {
+					dev_info(adev->dev, "RAS table recovery succeed\n");
+					return;
+				}
+		dev_err(adev->dev, "RAS table recovery failed\n");
+		control->is_eeprom_valid = false;
+	}
+	return;
+}
\ No newline at end of file
drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.h +2 -0
index 35c69ac3dbeb..ebfca4cb5688 100644
@@ -161,6 +161,8 @@ void amdgpu_ras_debugfs_set_ret_size(struct amdgpu_ras_eeprom_control *control);
 
 int amdgpu_ras_eeprom_check(struct amdgpu_ras_eeprom_control *control);
 
+void amdgpu_ras_eeprom_check_and_recover(struct amdgpu_device *adev);
+
 extern const struct file_operations amdgpu_ras_debugfs_eeprom_size_ops;
 extern const struct file_operations amdgpu_ras_debugfs_eeprom_table_ops;
 
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 2/2 drm/amdgpu: refine bad page loading when in the same nps mode

when loading bad page in the same nps mode, need to set the other fields in eeprom records manually besides retired_page

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +15 -0
index f8a8c8502013..94d4639c68df 100644
@@ -2860,6 +2860,13 @@ static int __amdgpu_ras_convert_rec_array_from_rom(struct amdgpu_device *adev,
 			if (amdgpu_umc_pages_in_a_row(adev, err_data,
 					bps[0].retired_page << AMDGPU_GPU_PAGE_SHIFT))
 				return -EINVAL;
+			for (i = 0; i < adev->umc.retire_unit; i++) {
+				err_data->err_addr[i].address = bps[0].address;
+				err_data->err_addr[i].mem_channel = bps[0].mem_channel;
+				err_data->err_addr[i].bank = bps[0].bank;
+				err_data->err_addr[i].err_type = bps[0].err_type;
+				err_data->err_addr[i].mcumc_id = bps[0].mcumc_id;
+			}
 		} else {
 			if (amdgpu_ras_mca2pa_by_idx(adev, &bps[0], err_data))
 				return -EINVAL;
@@ -2891,6 +2898,7 @@ static int __amdgpu_ras_convert_rec_from_rom(struct amdgpu_device *adev,
 				struct eeprom_table_record *bps, struct ras_err_data *err_data,
 				enum amdgpu_memory_partition nps)
 {
+	int i = 0;
 	enum amdgpu_memory_partition save_nps;
 
 	save_nps = (bps->retired_page >> UMC_NPS_SHIFT) & UMC_NPS_MASK;
@@ -2900,6 +2908,13 @@ static int __amdgpu_ras_convert_rec_from_rom(struct amdgpu_device *adev,
 		if (amdgpu_umc_pages_in_a_row(adev, err_data,
 				bps->retired_page << AMDGPU_GPU_PAGE_SHIFT))
 			return -EINVAL;
+		for (i = 0; i < adev->umc.retire_unit; i++) {
+			err_data->err_addr[i].address = bps->address;
+			err_data->err_addr[i].mem_channel = bps->mem_channel;
+			err_data->err_addr[i].bank = bps->bank;
+			err_data->err_addr[i].err_type = bps->err_type;
+			err_data->err_addr[i].mcumc_id = bps->mcumc_id;
+		}
 	} else {
 		if (bps->address) {
 			if (amdgpu_ras_mca2pa_by_idx(adev, bps, err_data))
Signature · 1 line
2.34.1
#2 lore raw
In reply to ganglxie
Quoted 27 lines · ganglxie

add eeprom data checksum check before driver unload. reset eeprom and save correct data to eeprom when check failed

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       |  1 +
 .../gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c    | 25 +++++++++++++++++++
 .../gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.h    |  2 ++
 3 files changed, 28 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -0
index 571b70da4562..1009b60f6ae4 100644
@@ -2560,6 +2560,7 @@ amdgpu_pci_remove(struct pci_dev *pdev)
 	struct drm_device *dev = pci_get_drvdata(pdev);
 	struct amdgpu_device *adev = drm_to_adev(dev);
 
+	amdgpu_ras_eeprom_check_and_recover(adev);
 	amdgpu_xcp_dev_unplug(adev);
 	amdgpu_gmc_prepare_nps_mode_change(adev);
 	drm_dev_unplug(dev);
drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c +0 -0
index 2af14c369bb9..2458c67526c9 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c int amdgpu_ras_eeprom_check(struct amdgpu_ras_eeprom_control *control) · line 1528

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c +4 -0
@@ -1522,3 +1522,28 @@ int amdgpu_ras_eeprom_check(struct amdgpu_ras_eeprom_control *control)
 
 	return res < 0 ? res : 0;
 }
+
+void amdgpu_ras_eeprom_check_and_recover(struct amdgpu_device *adev)
+{
+	struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);

Doesn't this require a NULL check?

Thanks,
Lijo

Quoted 35 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c +21 -0
+	struct amdgpu_ras_eeprom_control *control = &ras->eeprom_control;
+	int res = 0;
+
+	if (!control->is_eeprom_valid)
+		return;
+	res = __verify_ras_table_checksum(control);
+	if (res) {
+		dev_warn(adev->dev,
+			"RAS table incorrect checksum or error:%d, try to recover\n",
+			res);
+		if (!amdgpu_ras_eeprom_reset_table(control))
+			if (!amdgpu_ras_save_bad_pages(adev, NULL))
+				if (!__verify_ras_table_checksum(control)) {
+					dev_info(adev->dev, "RAS table recovery succeed\n");
+					return;
+				}
+		dev_err(adev->dev, "RAS table recovery failed\n");
+		control->is_eeprom_valid = false;
+	}
+	return;
+}
\ No newline at end of file
drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.h +2 -0
index 35c69ac3dbeb..ebfca4cb5688 100644
@@ -161,6 +161,8 @@ void amdgpu_ras_debugfs_set_ret_size(struct amdgpu_ras_eeprom_control *control);
 
 int amdgpu_ras_eeprom_check(struct amdgpu_ras_eeprom_control *control);
 
+void amdgpu_ras_eeprom_check_and_recover(struct amdgpu_device *adev);
+
 extern const struct file_operations amdgpu_ras_debugfs_eeprom_size_ops;
 extern const struct file_operations amdgpu_ras_debugfs_eeprom_table_ops;
 
#3 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

Thanks, will add this NULL check

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Friday, July 11, 2025 3:17 PM
To: Xie, Patrick <[email protected]>; [email protected]
Cc: Zhou1, Tao <[email protected]>
Subject: Re: [PATCH 1/2] drm/amdgpu: refine eeprom data check

Quoted 29 lines · ganglxie

add eeprom data checksum check before driver unload. reset eeprom and save correct data to eeprom when check failed

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       |  1 +
 .../gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c    | 25 +++++++++++++++++++
 .../gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.h    |  2 ++
 3 files changed, 28 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -0
index 571b70da4562..1009b60f6ae4 100644
@@ -2560,6 +2560,7 @@ amdgpu_pci_remove(struct pci_dev *pdev)
      struct drm_device *dev = pci_get_drvdata(pdev);
      struct amdgpu_device *adev = drm_to_adev(dev);
 
+     amdgpu_ras_eeprom_check_and_recover(adev);
      amdgpu_xcp_dev_unplug(adev);
      amdgpu_gmc_prepare_nps_mode_change(adev);
      drm_dev_unplug(dev);
drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c +0 -0
index 2af14c369bb9..2458c67526c9 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c int amdgpu_ras_eeprom_check(struct · line 1528

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c +4 -0
@@ -1522,3 +1522,28 @@ int amdgpu_ras_eeprom_check(struct
 amdgpu_ras_eeprom_control *control)
 
      return res < 0 ? res : 0;
 }
+
+void amdgpu_ras_eeprom_check_and_recover(struct amdgpu_device *adev)
+{
+     struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);

Doesn't this require a NULL check?

Thanks,
Lijo

Quoted 40 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c +21 -0
+     struct amdgpu_ras_eeprom_control *control = &ras->eeprom_control;
+     int res = 0;
+
+     if (!control->is_eeprom_valid)
+             return;
+     res = __verify_ras_table_checksum(control);
+     if (res) {
+             dev_warn(adev->dev,
+                     "RAS table incorrect checksum or error:%d, try to recover\n",
+                     res);
+             if (!amdgpu_ras_eeprom_reset_table(control))
+                     if (!amdgpu_ras_save_bad_pages(adev, NULL))
+                             if (!__verify_ras_table_checksum(control)) {
+                                     dev_info(adev->dev, "RAS table recovery succeed\n");
+                                     return;
+                             }
+             dev_err(adev->dev, "RAS table recovery failed\n");
+             control->is_eeprom_valid = false;
+     }
+     return;
+}
\ No newline at end of file
drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.h +2 -0
index 35c69ac3dbeb..ebfca4cb5688 100644
@@ -161,6 +161,8 @@ void amdgpu_ras_debugfs_set_ret_size(struct
 amdgpu_ras_eeprom_control *control);
 
 int amdgpu_ras_eeprom_check(struct amdgpu_ras_eeprom_control
 *control);
 
+void amdgpu_ras_eeprom_check_and_recover(struct amdgpu_device *adev);
+
 extern const struct file_operations

amdgpu_ras_debugfs_eeprom_size_ops;
extern const struct file_operations
amdgpu_ras_debugfs_eeprom_table_ops;

#4 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

It's better to add ras support check, ras is not supported on any ASIC.

Tao

Quoted 105 lines

-----Original Message-----
From: Xie, Patrick <[email protected]>
Sent: Friday, July 11, 2025 3:47 PM
To: Lazar, Lijo <[email protected]>; [email protected]
Cc: Zhou1, Tao <[email protected]>
Subject: RE: [PATCH 1/2] drm/amdgpu: refine eeprom data check

[AMD Official Use Only - AMD Internal Distribution Only]

Thanks, will add this NULL check

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Friday, July 11, 2025 3:17 PM
To: Xie, Patrick <[email protected]>; [email protected]
Cc: Zhou1, Tao <[email protected]>
Subject: Re: [PATCH 1/2] drm/amdgpu: refine eeprom data check

Quoted 29 lines · ganglxie

add eeprom data checksum check before driver unload. reset eeprom and save correct data to eeprom when check failed

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       |  1 +
 .../gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c    | 25 +++++++++++++++++++
 .../gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.h    |  2 ++
 3 files changed, 28 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -0
index 571b70da4562..1009b60f6ae4 100644
@@ -2560,6 +2560,7 @@ amdgpu_pci_remove(struct pci_dev *pdev)
      struct drm_device *dev = pci_get_drvdata(pdev);
      struct amdgpu_device *adev = drm_to_adev(dev);
 
+     amdgpu_ras_eeprom_check_and_recover(adev);
      amdgpu_xcp_dev_unplug(adev);
      amdgpu_gmc_prepare_nps_mode_change(adev);
      drm_dev_unplug(dev);
drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c +0 -0
index 2af14c369bb9..2458c67526c9 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c int amdgpu_ras_eeprom_check(struct · line 1528

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c +4 -0
@@ -1522,3 +1522,28 @@ int amdgpu_ras_eeprom_check(struct
 amdgpu_ras_eeprom_control *control)
 
      return res < 0 ? res : 0;
 }
+
+void amdgpu_ras_eeprom_check_and_recover(struct amdgpu_device *adev)
+{
+     struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);

Doesn't this require a NULL check?

Thanks,
Lijo

Quoted 40 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c +21 -0
+     struct amdgpu_ras_eeprom_control *control = &ras->eeprom_control;
+     int res = 0;
+
+     if (!control->is_eeprom_valid)
+             return;
+     res = __verify_ras_table_checksum(control);
+     if (res) {
+             dev_warn(adev->dev,
+                     "RAS table incorrect checksum or error:%d, try to recover\n",
+                     res);
+             if (!amdgpu_ras_eeprom_reset_table(control))
+                     if (!amdgpu_ras_save_bad_pages(adev, NULL))
+                             if (!__verify_ras_table_checksum(control)) {
+                                     dev_info(adev->dev, "RAS table recovery succeed\n");
+                                     return;
+                             }
+             dev_err(adev->dev, "RAS table recovery failed\n");
+             control->is_eeprom_valid = false;
+     }
+     return;
+}
\ No newline at end of file
drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.h +2 -0
index 35c69ac3dbeb..ebfca4cb5688 100644
@@ -161,6 +161,8 @@ void amdgpu_ras_debugfs_set_ret_size(struct
 amdgpu_ras_eeprom_control *control);
 
 int amdgpu_ras_eeprom_check(struct amdgpu_ras_eeprom_control
 *control);
 
+void amdgpu_ras_eeprom_check_and_recover(struct amdgpu_device *adev);
+
 extern const struct file_operations

amdgpu_ras_debugfs_eeprom_size_ops;
extern const struct file_operations
amdgpu_ras_debugfs_eeprom_table_ops;