Skip to contentSkip to conversation

drm/amdgpu: flush all cached ras bad pages to eeprom

PATCH In review YiPeng Chai 2 participants 3 messages Jul 9, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 drm/amdgpu: flush all cached ras bad pages to eeprom

Before uninstalling gpu driver, flush all cached ras bad pages to eeprom.

v2:
Put the same code into a function and reuse the function.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 35 ++++++++++++++++++++-----
 1 file changed, 29 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +29 -6
index 0e748cd55d43..d923151af752 100644
@@ -124,6 +124,8 @@ const char *get_ras_block_str(struct ras_common_if *ras_block)
 
 #define AMDGPU_RAS_RETIRE_PAGE_INTERVAL 100  //ms
 
+#define MAX_FLUSH_RETIRE_DWORK_TIMES  100
+
 enum amdgpu_ras_retire_page_reservation {
 	AMDGPU_RAS_RETIRE_PAGE_RESERVED,
 	AMDGPU_RAS_RETIRE_PAGE_PENDING,
@@ -2837,6 +2839,23 @@ static void amdgpu_ras_ecc_log_fini(struct ras_ecc_log_info *ecc_log)
 }
 #endif
 
+static bool amdgpu_ras_schedule_retirement_dwork(struct amdgpu_ras *con,
+				uint32_t delayed_ms)
+{
+	int ret;
+
+	mutex_lock(&con->umc_ecc_log.lock);
+	ret = radix_tree_tagged(&con->umc_ecc_log.de_page_tree,
+			UMC_ECC_NEW_DETECTED_TAG);
+	mutex_unlock(&con->umc_ecc_log.lock);
+
+	if (ret)
+		schedule_delayed_work(&con->page_retirement_dwork,
+			msecs_to_jiffies(delayed_ms));
+
+	return ret ? true : false;
+}
+
 static void amdgpu_ras_do_page_retirement(struct work_struct *work)
 {
 	struct amdgpu_ras *con = container_of(work, struct amdgpu_ras,
@@ -2858,12 +2877,8 @@ static void amdgpu_ras_do_page_retirement(struct work_struct *work)
 	if (err_cnt && con->is_rma)
 		amdgpu_ras_reset_gpu(adev);
 
-	mutex_lock(&con->umc_ecc_log.lock);
-	if (radix_tree_tagged(&con->umc_ecc_log.de_page_tree,
-				UMC_ECC_NEW_DETECTED_TAG))
-		schedule_delayed_work(&con->page_retirement_dwork,
-			msecs_to_jiffies(AMDGPU_RAS_RETIRE_PAGE_INTERVAL));
-	mutex_unlock(&con->umc_ecc_log.lock);
+	amdgpu_ras_schedule_retirement_dwork(con,
+			AMDGPU_RAS_RETIRE_PAGE_INTERVAL);
 }
 
 static int amdgpu_ras_poison_creation_handler(struct amdgpu_device *adev,
@@ -3179,11 +3194,19 @@ static int amdgpu_ras_recovery_fini(struct amdgpu_device *adev)
 {
 	struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
 	struct ras_err_handler_data *data = con->eh_data;
+	int max_flush_timeout = MAX_FLUSH_RETIRE_DWORK_TIMES;
+	bool ret;
 
 	/* recovery_init failed to init it, fini is useless */
 	if (!data)
 		return 0;
 
+	/* Save all cached bad pages to eeprom */
+	do {
+		flush_delayed_work(&con->page_retirement_dwork);
+		ret = amdgpu_ras_schedule_retirement_dwork(con, 0);
+	} while (ret && max_flush_timeout--);
+
 	if (con->page_retirement_thread)
 		kthread_stop(con->page_retirement_thread);
 
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 2/2 drm/amdgpu: timely save bad pages to eeprom after gpu ras reset is completed

The problem case is as follows:
1. GPU A triggers a gpu ras reset, and GPU A drives GPU B to also perform a gpu ras reset.
2. After gpu B ras reset started, gpu B queried a DE data. Since the DE data was queried in the ras reset thread instead of the page retirement thread, bad page retirement work would not be triggered. Then even if all gpu resets are completed, the bad pages will be cached in RAM until GPU B's bad page retirement work is triggered again and then saved to eeprom.

This patch can save the bad pages to eeprom in time after gpu ras reset is completed.

v2:
1. Add the above description to code comments.
2. Reuse existing function.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c |  6 +++++-
 drivers/gpu/drm/amd/amdgpu/umc_v12_0.c  | 18 ++++++++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +5 -1
index d923151af752..34226ae010c7 100644
@@ -2864,8 +2864,12 @@ static void amdgpu_ras_do_page_retirement(struct work_struct *work)
 	struct ras_err_data err_data;
 	unsigned long err_cnt;
 
-	if (amdgpu_in_reset(adev) || amdgpu_ras_in_recovery(adev))
+	/* If gpu reset is ongoing, delay retiring the bad pages */
+	if (amdgpu_in_reset(adev) || amdgpu_ras_in_recovery(adev)) {
+		amdgpu_ras_schedule_retirement_dwork(con,
+				AMDGPU_RAS_RETIRE_PAGE_INTERVAL * 3);
 		return;
+	}
 
 	amdgpu_ras_error_data_init(&err_data);
 
drivers/gpu/drm/amd/amdgpu/umc_v12_0.c +18 -0
index 0faa21d8a7b4..9dbb13adb661 100644
@@ -29,6 +29,7 @@
 #include "mp/mp_13_0_6_sh_mask.h"
 
 #define MAX_ECC_NUM_PER_RETIREMENT  32
+#define DELAYED_TIME_FOR_GPU_RESET  1000  //ms
 
 static inline uint64_t get_umc_v12_0_reg_offset(struct amdgpu_device *adev,
 					    uint32_t node_inst,
@@ -568,6 +569,23 @@ static int umc_v12_0_update_ecc_status(struct amdgpu_device *adev,
 
 	con->umc_ecc_log.de_queried_count++;
 
+	/* The problem case is as follows:
+	 * 1. GPU A triggers a gpu ras reset, and GPU A drives
+	 *    GPU B to also perform a gpu ras reset.
+	 * 2. After gpu B ras reset started, gpu B queried a DE
+	 *    data. Since the DE data was queried in the ras reset
+	 *    thread instead of the page retirement thread, bad
+	 *    page retirement work would not be triggered. Then
+	 *    even if all gpu resets are completed, the bad pages
+	 *    will be cached in RAM until GPU B's bad page retirement
+	 *    work is triggered again and then saved to eeprom.
+	 * Trigger delayed work to save the bad pages to eeprom in time
+	 * after gpu ras reset is completed.
+	 */
+	if (amdgpu_ras_in_recovery(adev))
+		schedule_delayed_work(&con->page_retirement_dwork,
+			msecs_to_jiffies(DELAYED_TIME_FOR_GPU_RESET));
+
 	return 0;
 }
 
Signature · 1 line
2.34.1
Reviewed-by on v2 2/2
#2 lore raw

RE: [PATCH V2 2/2] drm/amdgpu: timely save bad pages to eeprom after gpu ras reset is completed

[AMD Official Use Only - AMD Internal Distribution Only]

The series is:

Quoted 95 lines

-----Original Message-----
From: Chai, Thomas <[email protected]>
Sent: Tuesday, July 9, 2024 1:56 PM
To: [email protected]
Cc: Zhang, Hawking <[email protected]>; Zhou1, Tao <[email protected]>; Li, Candice <[email protected]>; Wang, Yang(Kevin) <[email protected]>; Yang, Stanley <[email protected]>; Chai, Thomas <[email protected]>
Subject: [PATCH V2 2/2] drm/amdgpu: timely save bad pages to eeprom after gpu ras reset is completed

The problem case is as follows:
1. GPU A triggers a gpu ras reset, and GPU A drives GPU B to also perform a gpu ras reset.
2. After gpu B ras reset started, gpu B queried a DE data. Since the DE data was queried in the ras reset thread instead of the page retirement thread, bad page retirement work would not be triggered. Then even if all gpu resets are completed, the bad pages will be cached in RAM until GPU B's bad page retirement work is triggered again and then saved to eeprom.

This patch can save the bad pages to eeprom in time after gpu ras reset is completed.

v2:
1. Add the above description to code comments.
2. Reuse existing function.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c |  6 +++++-
drivers/gpu/drm/amd/amdgpu/umc_v12_0.c  | 18 ++++++++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +5 -1
index d923151af752..34226ae010c7 100644
@@ -2864,8 +2864,12 @@ static void amdgpu_ras_do_page_retirement(struct
 work_struct *work)
      struct ras_err_data err_data;
      unsigned long err_cnt;
 
-     if (amdgpu_in_reset(adev) || amdgpu_ras_in_recovery(adev))
+     /* If gpu reset is ongoing, delay retiring the bad pages */
+     if (amdgpu_in_reset(adev) || amdgpu_ras_in_recovery(adev)) {
+             amdgpu_ras_schedule_retirement_dwork(con,
+                             AMDGPU_RAS_RETIRE_PAGE_INTERVAL * 3);
              return;
+     }
 
      amdgpu_ras_error_data_init(&err_data);
drivers/gpu/drm/amd/amdgpu/umc_v12_0.c +18 -1
index 0faa21d8a7b4..9dbb13adb661 100644
@@ -29,6 +29,7 @@
 #include "mp/mp_13_0_6_sh_mask.h"
 
 #define MAX_ECC_NUM_PER_RETIREMENT  32
+#define DELAYED_TIME_FOR_GPU_RESET  1000  //ms
 
 static inline uint64_t get_umc_v12_0_reg_offset(struct amdgpu_device *adev,
                                          uint32_t node_inst,
@@ -568,6 +569,23 @@ static int umc_v12_0_update_ecc_status(struct
 amdgpu_device *adev,
 
      con->umc_ecc_log.de_queried_count++;
 
+     /* The problem case is as follows:
+      * 1. GPU A triggers a gpu ras reset, and GPU A drives
+      *    GPU B to also perform a gpu ras reset.
+      * 2. After gpu B ras reset started, gpu B queried a DE
+      *    data. Since the DE data was queried in the ras reset
+      *    thread instead of the page retirement thread, bad
+      *    page retirement work would not be triggered. Then
+      *    even if all gpu resets are completed, the bad pages
+      *    will be cached in RAM until GPU B's bad page retirement
+      *    work is triggered again and then saved to eeprom.
+      * Trigger delayed work to save the bad pages to eeprom in time
+      * after gpu ras reset is completed.
+      */
+     if (amdgpu_ras_in_recovery(adev))
+             schedule_delayed_work(&con->page_retirement_dwork,
+                     msecs_to_jiffies(DELAYED_TIME_FOR_GPU_RESET));
+
      return 0;
 }
 
--

2.34.1