Skip to contentSkip to conversation

drm/amdgpu: add variable to record the deferred error number read by driver

PATCH Superseded YiPeng Chai 3 participants 12 messages Jun 18, 2024 – Jun 19, 2024

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/5 drm/amdgpu: add variable to record the deferred error number read by driver

Add variable to record the deferred error
number read by driver.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 62 ++++++++++++++++++-------
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h |  3 +-
 drivers/gpu/drm/amd/amdgpu/umc_v12_0.c  |  4 +-
 3 files changed, 48 insertions(+), 21 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +44 -18
index d0dcd3d37e6d..ec8e848122f9 100644
@@ -120,7 +120,7 @@ const char *get_ras_block_str(struct ras_common_if *ras_block)
 /* typical ECC bad page rate is 1 bad page per 100MB VRAM */
 #define RAS_BAD_PAGE_COVER              (100 * 1024 * 1024ULL)
 
-#define MAX_UMC_POISON_POLLING_TIME_ASYNC  100  //ms
+#define MAX_UMC_POISON_POLLING_TIME_ASYNC  300  //ms
 
 #define AMDGPU_RAS_RETIRE_PAGE_INTERVAL 100  //ms
 
@@ -2773,7 +2773,8 @@ static void amdgpu_ras_ecc_log_init(struct ras_ecc_log_info *ecc_log)
 	memset(&ecc_log->ecc_key, 0xad, sizeof(ecc_log->ecc_key));
 
 	INIT_RADIX_TREE(&ecc_log->de_page_tree, GFP_KERNEL);
-	ecc_log->de_updated = false;
+	ecc_log->de_queried_count = 0;
+	ecc_log->prev_de_queried_count = 0;
 }
 
 static void amdgpu_ras_ecc_log_fini(struct ras_ecc_log_info *ecc_log)
@@ -2792,7 +2793,8 @@ static void amdgpu_ras_ecc_log_fini(struct ras_ecc_log_info *ecc_log)
 	mutex_unlock(&ecc_log->lock);
 
 	mutex_destroy(&ecc_log->lock);
-	ecc_log->de_updated = false;
+	ecc_log->de_queried_count = 0;
+	ecc_log->prev_de_queried_count = 0;
 }
 #endif
 
@@ -2820,40 +2822,64 @@ static void amdgpu_ras_do_page_retirement(struct work_struct *work)
 	mutex_unlock(&con->umc_ecc_log.lock);
 }
 
-static void amdgpu_ras_poison_creation_handler(struct amdgpu_device *adev,
-				uint32_t timeout_ms)
+static int amdgpu_ras_poison_creation_handler(struct amdgpu_device *adev,
+				uint32_t poison_creation_count)
 {
 	int ret = 0;
 	struct ras_ecc_log_info *ecc_log;
 	struct ras_query_if info;
-	uint32_t timeout = timeout_ms;
+	uint32_t timeout = 0;
 	struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
+	uint64_t de_queried_count;
+	uint32_t new_detect_count, total_detect_count;
+	uint32_t need_query_count = poison_creation_count;
+	bool query_data_timeout = false;
 
 	memset(&info, 0, sizeof(info));
 	info.head.block = AMDGPU_RAS_BLOCK__UMC;
 
 	ecc_log = &ras->umc_ecc_log;
-	ecc_log->de_updated = false;
+	total_detect_count = 0;
 	do {
 		ret = amdgpu_ras_query_error_status(adev, &info);
-		if (ret) {
-			dev_err(adev->dev, "Failed to query ras error! ret:%d\n", ret);
-			return;
+		if (ret)
+			return ret;
+
+		de_queried_count = ecc_log->de_queried_count;
+		if (de_queried_count > ecc_log->prev_de_queried_count) {
+			new_detect_count = de_queried_count - ecc_log->prev_de_queried_count;
+			ecc_log->prev_de_queried_count = de_queried_count;
+			timeout = 0;
+		} else {
+			new_detect_count = 0;
 		}
 
-		if (timeout && !ecc_log->de_updated) {
-			msleep(1);
-			timeout--;
+		if (new_detect_count) {
+			total_detect_count += new_detect_count;
+		} else {
+			if (!timeout && need_query_count)
+				timeout = MAX_UMC_POISON_POLLING_TIME_ASYNC;
+
+			if (timeout) {
+				if (!--timeout) {
+					query_data_timeout = true;
+					break;
+				}
+				msleep(1);
+			}
 		}
-	} while (timeout && !ecc_log->de_updated);
+	} while (total_detect_count < need_query_count);
 
-	if (timeout_ms && !timeout) {
-		dev_warn(adev->dev, "Can't find deferred error\n");
-		return;
+	if (query_data_timeout) {
+		dev_warn(adev->dev, "Can't find deferred error! count: %u\n",
+			(need_query_count - total_detect_count));
+		return 0;
 	}
 
-	if (!ret)
+	if (total_detect_count)
 		schedule_delayed_work(&ras->page_retirement_dwork, 0);
+
+	return 0;
 }
 
 static int amdgpu_ras_poison_consumption_handler(struct amdgpu_device *adev,
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h +2 -1
index e70c45712ddb..c50f5f2b1f4f 100644
@@ -469,7 +469,8 @@ struct ras_ecc_log_info {
 	struct mutex lock;
 	siphash_key_t ecc_key;
 	struct radix_tree_root de_page_tree;
-	bool	de_updated;
+	uint64_t	de_queried_count;
+	uint64_t	prev_de_queried_count;
 };
 
 struct amdgpu_ras {
drivers/gpu/drm/amd/amdgpu/umc_v12_0.c +2 -2
index 6d6350f220b0..0faa21d8a7b4 100644
@@ -557,7 +557,7 @@ static int umc_v12_0_update_ecc_status(struct amdgpu_device *adev,
 	ret = amdgpu_umc_logs_ecc_err(adev, &con->umc_ecc_log.de_page_tree, ecc_err);
 	if (ret) {
 		if (ret == -EEXIST)
-			con->umc_ecc_log.de_updated = true;
+			con->umc_ecc_log.de_queried_count++;
 		else
 			dev_err(adev->dev, "Fail to log ecc error! ret:%d\n", ret);
 
@@ -566,7 +566,7 @@ static int umc_v12_0_update_ecc_status(struct amdgpu_device *adev,
 		return ret;
 	}
 
-	con->umc_ecc_log.de_updated = true;
+	con->umc_ecc_log.de_queried_count++;
 
 	return 0;
 }
Signature · 1 line
2.34.1
#1 lore raw

PATCH 2/5 drm/amdgpu: refine poison creation interrupt handler

In order to apply to the case where a large number of ras poison interrupts:
1. Change to use variable to record poison creation requests to avoid fifo full.
2. Prioritize handling poison creation requests instead of following the order of requests received by the driver.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 41 ++++++++++++-------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h |  1 +
 2 files changed, 21 insertions(+), 21 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +20 -21
index ec8e848122f9..13cd6a9234f2 100644
@@ -2093,10 +2093,8 @@ static void amdgpu_ras_interrupt_poison_creation_handler(struct ras_manager *obj
 	if (amdgpu_ip_version(obj->adev, UMC_HWIP, 0) >= IP_VERSION(12, 0, 0)) {
 		struct amdgpu_ras *con = amdgpu_ras_get_context(obj->adev);
 
-		amdgpu_ras_put_poison_req(obj->adev,
-			AMDGPU_RAS_BLOCK__UMC, 0, NULL, NULL, false);
-
 		atomic_inc(&con->page_retirement_req_cnt);
+		atomic_inc(&con->poison_creation_count);
 
 		wake_up(&con->page_retirement_wq);
 	}
@@ -2873,7 +2871,7 @@ static int amdgpu_ras_poison_creation_handler(struct amdgpu_device *adev,
 	if (query_data_timeout) {
 		dev_warn(adev->dev, "Can't find deferred error! count: %u\n",
 			(need_query_count - total_detect_count));
-		return 0;
+		return -ENOENT;
 	}
 
 	if (total_detect_count)
@@ -2908,6 +2906,8 @@ static int amdgpu_ras_page_retirement_thread(void *param)
 {
 	struct amdgpu_device *adev = (struct amdgpu_device *)param;
 	struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
+	uint32_t poison_creation_count;
+	int ret;
 	struct ras_poison_msg poison_msg;
 	enum amdgpu_ras_block ras_block;
 	bool poison_creation_is_handled = false;
@@ -2921,7 +2921,20 @@ static int amdgpu_ras_page_retirement_thread(void *param)
 		if (kthread_should_stop())
 			break;
 
-		atomic_dec(&con->page_retirement_req_cnt);
+
+		do {
+			poison_creation_count = atomic_read(&con->poison_creation_count);
+			ret = amdgpu_ras_poison_creation_handler(adev, poison_creation_count);
+			if (ret == -EIO)
+				break;
+
+			if (poison_creation_count) {
+				while (poison_creation_count--) {
+					atomic_dec(&con->poison_creation_count);
+					atomic_dec(&con->page_retirement_req_cnt);
+				}
+			}
+		} while (atomic_read(&con->poison_creation_count));
 
 #ifdef HAVE_KFIFO_PUT_NON_POINTER
 		if (!amdgpu_ras_get_poison_req(adev, &poison_msg))
@@ -2932,24 +2945,8 @@ static int amdgpu_ras_page_retirement_thread(void *param)
 		dev_dbg(adev->dev, "Start processing ras block %s(%d)\n",
 				ras_block_str(ras_block), ras_block);
 
-		if (ras_block == AMDGPU_RAS_BLOCK__UMC) {
-			amdgpu_ras_poison_creation_handler(adev,
-				MAX_UMC_POISON_POLLING_TIME_ASYNC);
-			poison_creation_is_handled = true;
-		} else {
-			/* poison_creation_is_handled:
-			 *   false: no poison creation interrupt, but it has poison
-			 *          consumption interrupt.
-			 *   true: It has poison creation interrupt at the beginning,
-			 *         but it has no poison creation interrupt later.
-			 */
-			amdgpu_ras_poison_creation_handler(adev,
-					poison_creation_is_handled ?
-					0 : MAX_UMC_POISON_POLLING_TIME_ASYNC);
 
 			amdgpu_ras_poison_consumption_handler(adev, &poison_msg);
-			poison_creation_is_handled = false;
-		}
 #else
         dev_info(adev->dev, "Start processing page retirement. request:%d\n",
                     atomic_read(&con->page_retirement_req_cnt));
@@ -3029,6 +3026,7 @@ int amdgpu_ras_recovery_init(struct amdgpu_device *adev)
 	mutex_init(&con->page_retirement_lock);
 	init_waitqueue_head(&con->page_retirement_wq);
 	atomic_set(&con->page_retirement_req_cnt, 0);
+	atomic_set(&con->poison_creation_count, 0);
 	con->page_retirement_thread =
 		kthread_run(amdgpu_ras_page_retirement_thread, adev, "umc_page_retirement");
 	if (IS_ERR(con->page_retirement_thread)) {
@@ -3080,6 +3078,7 @@ static int amdgpu_ras_recovery_fini(struct amdgpu_device *adev)
 		kthread_stop(con->page_retirement_thread);
 
 	atomic_set(&con->page_retirement_req_cnt, 0);
+	atomic_set(&con->poison_creation_count, 0);
 
 	mutex_destroy(&con->page_rsv_lock);
 
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h +1 -0
index c50f5f2b1f4f..91daf48be03a 100644
@@ -532,6 +532,7 @@ struct amdgpu_ras {
 	wait_queue_head_t page_retirement_wq;
 	struct mutex page_retirement_lock;
 	atomic_t page_retirement_req_cnt;
+	atomic_t poison_creation_count;
 	struct mutex page_rsv_lock;
 	DECLARE_KFIFO(poison_fifo, struct ras_poison_msg, 128);
 	struct ras_ecc_log_info  umc_ecc_log;
Signature · 1 line
2.34.1
#2 lore raw

PATCH 3/5 drm/amdgpu: refine poison consumption interrupt handler

In reply to YiPeng Chai

1. The poison fifo is only used for poison consumption requests.
2. Merge reset requests when poison fifo caches multiple poison consumption messages

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 58 +++++++++++++++++--------
 drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c | 12 ++---
 2 files changed, 46 insertions(+), 24 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +39 -19
index 13cd6a9234f2..898889600771 100644
@@ -2881,22 +2881,40 @@ static int amdgpu_ras_poison_creation_handler(struct amdgpu_device *adev,
 }
 
 static int amdgpu_ras_poison_consumption_handler(struct amdgpu_device *adev,
-			struct ras_poison_msg *poison_msg)
+			uint32_t msg_count, uint32_t *gpu_reset)
 {
 	struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
-	uint32_t reset = poison_msg->reset;
-	uint16_t pasid = poison_msg->pasid;
+	uint32_t reset_flags = 0, reset = 0;
+	struct ras_poison_msg msg;
+	int ret, i;
 
 	kgd2kfd_set_sram_ecc_flag(adev->kfd.dev);
 
-	if (poison_msg->pasid_fn)
-		poison_msg->pasid_fn(adev, pasid, poison_msg->data);
+	for (i = 0; i < msg_count; i++) {
+		ret = amdgpu_ras_get_poison_req(adev, &msg);
+		if (!ret)
+			continue;
+
+		if (msg.pasid_fn)
+			msg.pasid_fn(adev, msg.pasid, msg.data);
+
+		reset_flags |= msg.reset;
+	}
+
+	if (reset_flags) {
+		if (reset_flags & AMDGPU_RAS_GPU_RESET_MODE1_RESET)
+			reset = AMDGPU_RAS_GPU_RESET_MODE1_RESET;
+		else if (reset_flags & AMDGPU_RAS_GPU_RESET_MODE2_RESET)
+			reset = AMDGPU_RAS_GPU_RESET_MODE2_RESET;
+		else
+			reset = reset_flags;
 
-	if (reset) {
 		flush_delayed_work(&con->page_retirement_dwork);
 
 		con->gpu_reset_flags |= reset;
 		amdgpu_ras_reset_gpu(adev);
+
+		*gpu_reset = reset;
 	}
 
 	return 0;
@@ -2906,11 +2924,9 @@ static int amdgpu_ras_page_retirement_thread(void *param)
 {
 	struct amdgpu_device *adev = (struct amdgpu_device *)param;
 	struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
-	uint32_t poison_creation_count;
+	uint32_t poison_creation_count, msg_count;
+	uint32_t gpu_reset;
 	int ret;
-	struct ras_poison_msg poison_msg;
-	enum amdgpu_ras_block ras_block;
-	bool poison_creation_is_handled = false;
 
 	while (!kthread_should_stop()) {
 
@@ -2921,6 +2937,7 @@ static int amdgpu_ras_page_retirement_thread(void *param)
 		if (kthread_should_stop())
 			break;
 
+		gpu_reset = 0;
 
 		do {
 			poison_creation_count = atomic_read(&con->poison_creation_count);
@@ -2937,16 +2954,19 @@ static int amdgpu_ras_page_retirement_thread(void *param)
 		} while (atomic_read(&con->poison_creation_count));
 
 #ifdef HAVE_KFIFO_PUT_NON_POINTER
-		if (!amdgpu_ras_get_poison_req(adev, &poison_msg))
-			continue;
-
-		ras_block = poison_msg.block;
-
-		dev_dbg(adev->dev, "Start processing ras block %s(%d)\n",
-				ras_block_str(ras_block), ras_block);
-
+		if (ret != -EIO) {
+			msg_count = kfifo_len(&con->poison_fifo);
+			if (msg_count) {
+				ret = amdgpu_ras_poison_consumption_handler(adev,
+						msg_count, &gpu_reset);
+				if ((ret != -EIO) &&
+				    (gpu_reset != AMDGPU_RAS_GPU_RESET_MODE1_RESET)) {
+					while (msg_count--)
+						atomic_dec(&con->page_retirement_req_cnt);
+				}
+			}
+		}
 
-			amdgpu_ras_poison_consumption_handler(adev, &poison_msg);
 #else
         dev_info(adev->dev, "Start processing page retirement. request:%d\n",
                     atomic_read(&con->page_retirement_req_cnt));
drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c +7 -5
index 1dbe69eabb9a..47a46bf49a06 100644
@@ -296,13 +296,15 @@ int amdgpu_umc_pasid_poison_handler(struct amdgpu_device *adev,
 				struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
 
 #ifdef HAVE_KFIFO_PUT_NON_POINTER
-				amdgpu_ras_put_poison_req(adev,
+				int ret;
+
+				ret = amdgpu_ras_put_poison_req(adev,
 					block, pasid, pasid_fn, data, reset);
+				if (!ret) {
+					atomic_inc(&con->page_retirement_req_cnt);
+					wake_up(&con->page_retirement_wq);
+				}
 #endif
-
-				atomic_inc(&con->page_retirement_req_cnt);
-
-				wake_up(&con->page_retirement_wq);
 		}
 	} else {
 		if (adev->virt.ops && adev->virt.ops->ras_poison_handler)
Signature · 1 line
2.34.1
#3 lore raw

PATCH 4/5 drm/amdgpu: add completion to wait for ras reset to complete

In reply to YiPeng Chai

Add completion to wait for ras reset to complete.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 11 +++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h |  1 +
 2 files changed, 12 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +11 -0
index 898889600771..7f8e6ca07957 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_RAS_RECOVERY_COMPLETION_TIME  120000 //ms
+
 enum amdgpu_ras_retire_page_reservation {
 	AMDGPU_RAS_RETIRE_PAGE_RESERVED,
 	AMDGPU_RAS_RETIRE_PAGE_PENDING,
@@ -2518,6 +2520,8 @@ static void amdgpu_ras_do_recovery(struct work_struct *work)
 		atomic_set(&hive->ras_recovery, 0);
 		amdgpu_put_xgmi_hive(hive);
 	}
+
+	complete_all(&ras->ras_recovery_completion);
 }
 
 /* alloc/realloc bps array */
@@ -2911,10 +2915,16 @@ static int amdgpu_ras_poison_consumption_handler(struct amdgpu_device *adev,
 
 		flush_delayed_work(&con->page_retirement_dwork);
 
+		reinit_completion(&con->ras_recovery_completion);
+
 		con->gpu_reset_flags |= reset;
 		amdgpu_ras_reset_gpu(adev);
 
 		*gpu_reset = reset;
+		if (!wait_for_completion_timeout(&con->ras_recovery_completion,
+				msecs_to_jiffies(MAX_RAS_RECOVERY_COMPLETION_TIME)))
+			dev_err(adev->dev, "Waiting for GPU to complete ras reset timeout! reset:0x%x\n",
+				reset);
 	}
 
 	return 0;
@@ -3041,6 +3051,7 @@ int amdgpu_ras_recovery_init(struct amdgpu_device *adev)
 		}
 	}
 
+	init_completion(&con->ras_recovery_completion);
 	mutex_init(&con->page_rsv_lock);
 	INIT_KFIFO(con->poison_fifo);
 	mutex_init(&con->page_retirement_lock);
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h +1 -0
index 91daf48be03a..b47f03edac87 100644
@@ -537,6 +537,7 @@ struct amdgpu_ras {
 	DECLARE_KFIFO(poison_fifo, struct ras_poison_msg, 128);
 	struct ras_ecc_log_info  umc_ecc_log;
 	struct delayed_work page_retirement_dwork;
+	struct completion ras_recovery_completion;
 
 	/* Fatal error detected flag */
 	atomic_t fed;
Signature · 1 line
2.34.1
#4 lore raw

Re: [PATCH 4/5] drm/amdgpu: add completion to wait for ras reset to complete

Quoted 34 lines · YiPeng Chai

Add completion to wait for ras reset to complete.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 11 +++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h |  1 +
 2 files changed, 12 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +4 -0
index 898889600771..7f8e6ca07957 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_RAS_RECOVERY_COMPLETION_TIME  120000 //ms
+
 enum amdgpu_ras_retire_page_reservation {
 	AMDGPU_RAS_RETIRE_PAGE_RESERVED,
 	AMDGPU_RAS_RETIRE_PAGE_PENDING,
@@ -2518,6 +2520,8 @@ static void amdgpu_ras_do_recovery(struct work_struct *work)
 		atomic_set(&hive->ras_recovery, 0);
 		amdgpu_put_xgmi_hive(hive);
 	}
+
+	complete_all(&ras->ras_recovery_completion);
 }
 
 /* alloc/realloc bps array */
@@ -2911,10 +2915,16 @@ static int amdgpu_ras_poison_consumption_handler(struct amdgpu_device *adev,
 
 		flush_delayed_work(&con->page_retirement_dwork);
 

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c static int amdgpu_ras_poison_consumption_handler(struct amdgpu_device *adev, · line 2927

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +6 -0
+		reinit_completion(&con->ras_recovery_completion);
+
 		con->gpu_reset_flags |= reset;
 		amdgpu_ras_reset_gpu(adev);
 
 		*gpu_reset = reset;
+		if (!wait_for_completion_timeout(&con->ras_recovery_completion,
+				msecs_to_jiffies(MAX_RAS_RECOVERY_COMPLETION_TIME)))
+			dev_err(adev->dev, "Waiting for GPU to complete ras reset timeout! reset:0x%x\n",
+				reset);

If a mode-1 reset gets to execute first due to job timeout/hws detect cases in poison timeout, then the ras handler will never get executed. Why this wait is required?

Thanks,
Lijo

Quoted 23 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +1 -0
 	}
 
 	return 0;
@@ -3041,6 +3051,7 @@ int amdgpu_ras_recovery_init(struct amdgpu_device *adev)
 		}
 	}
 
+	init_completion(&con->ras_recovery_completion);
 	mutex_init(&con->page_rsv_lock);
 	INIT_KFIFO(con->poison_fifo);
 	mutex_init(&con->page_retirement_lock);
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h +1 -0
index 91daf48be03a..b47f03edac87 100644
@@ -537,6 +537,7 @@ struct amdgpu_ras {
 	DECLARE_KFIFO(poison_fifo, struct ras_poison_msg, 128);
 	struct ras_ecc_log_info  umc_ecc_log;
 	struct delayed_work page_retirement_dwork;
+	struct completion ras_recovery_completion;
 
 	/* Fatal error detected flag */
 	atomic_t fed;
#5 lore raw

RE: [PATCH 4/5] drm/amdgpu: add completion to wait for ras reset to complete

[AMD Official Use Only - AMD Internal Distribution Only]

-----------------
Best Regards,
Thomas

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Tuesday, June 18, 2024 6:09 PM
To: Chai, Thomas <[email protected]>; [email protected]
Cc: Zhang, Hawking <[email protected]>; Zhou1, Tao <[email protected]>; Li, Candice <[email protected]>; Wang, Yang(Kevin) <[email protected]>; Yang, Stanley <[email protected]>
Subject: Re: [PATCH 4/5] drm/amdgpu: add completion to wait for ras reset to complete

Quoted 48 lines · YiPeng Chai

Add completion to wait for ras reset to complete.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 11 +++++++++++
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h |  1 +
 2 files changed, 12 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +2 -0
index 898889600771..7f8e6ca07957 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_RAS_RECOVERY_COMPLETION_TIME  120000 //ms
+
 enum amdgpu_ras_retire_page_reservation {
      AMDGPU_RAS_RETIRE_PAGE_RESERVED,

AMDGPU_RAS_RETIRE_PAGE_PENDING,

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +8 -0
@@ -2518,6 +2520,8 @@ static void amdgpu_ras_do_recovery(struct work_struct *work)
              atomic_set(&hive->ras_recovery, 0);
              amdgpu_put_xgmi_hive(hive);
      }
+
+     complete_all(&ras->ras_recovery_completion);
 }
 
 /* alloc/realloc bps array */
@@ -2911,10 +2915,16 @@ static int
 amdgpu_ras_poison_consumption_handler(struct amdgpu_device *adev,
 
              flush_delayed_work(&con->page_retirement_dwork);
 
+             reinit_completion(&con->ras_recovery_completion);
+
              con->gpu_reset_flags |= reset;
              amdgpu_ras_reset_gpu(adev);
 
              *gpu_reset = reset;
+             if (!wait_for_completion_timeout(&con->ras_recovery_completion,
+                             msecs_to_jiffies(MAX_RAS_RECOVERY_COMPLETION_TIME)))
+                     dev_err(adev->dev, "Waiting for GPU to complete ras reset timeout! reset:0x%x\n",
+                             reset);
 
Quoted 2 lines

If a mode-1 reset gets to execute first due to job timeout/hws detect cases in poison timeout, then the ras handler will never get executed. Why this wait is required?

[Thomas] "[PATCH 5/5] drm/amdgpu: add gpu reset check and exception handling" add the check before ras gpu reset.

Thanks,
Lijo

Quoted 24 lines
      }

      return 0;
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +1 -0
@@ -3041,6 +3051,7 @@ int amdgpu_ras_recovery_init(struct amdgpu_device *adev)
              }
      }
 
+     init_completion(&con->ras_recovery_completion);
      mutex_init(&con->page_rsv_lock);
      INIT_KFIFO(con->poison_fifo);
      mutex_init(&con->page_retirement_lock);
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h +1 -0
index 91daf48be03a..b47f03edac87 100644
@@ -537,6 +537,7 @@ struct amdgpu_ras {
      DECLARE_KFIFO(poison_fifo, struct ras_poison_msg, 128);
      struct ras_ecc_log_info  umc_ecc_log;
      struct delayed_work page_retirement_dwork;
+     struct completion ras_recovery_completion;
 
      /* Fatal error detected flag */
      atomic_t fed;
#6 lore raw

RE: [PATCH 4/5] drm/amdgpu: add completion to wait for ras reset to complete

[AMD Official Use Only - AMD Internal Distribution Only]

-----------------
Best Regards,
Thomas

-----Original Message-----
From: Chai, Thomas
Sent: Tuesday, June 18, 2024 7:09 PM
To: Lazar, Lijo <[email protected]>; [email protected]
Cc: Zhang, Hawking <[email protected]>; Zhou1, Tao <[email protected]>; Li, Candice <[email protected]>; Wang, Yang(Kevin) <[email protected]>; Yang, Stanley <[email protected]>
Subject: RE: [PATCH 4/5] drm/amdgpu: add completion to wait for ras reset to complete

-----------------
Best Regards,
Thomas

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Tuesday, June 18, 2024 6:09 PM
To: Chai, Thomas <[email protected]>; [email protected]
Cc: Zhang, Hawking <[email protected]>; Zhou1, Tao <[email protected]>; Li, Candice <[email protected]>; Wang, Yang(Kevin) <[email protected]>; Yang, Stanley <[email protected]>
Subject: Re: [PATCH 4/5] drm/amdgpu: add completion to wait for ras reset to complete

Quoted 51 lines · YiPeng Chai

Add completion to wait for ras reset to complete.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 11 +++++++++++
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h |  1 +
 2 files changed, 12 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +2 -0
index 898889600771..7f8e6ca07957 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_RAS_RECOVERY_COMPLETION_TIME  120000 //ms
+
 enum amdgpu_ras_retire_page_reservation {
      AMDGPU_RAS_RETIRE_PAGE_RESERVED,

AMDGPU_RAS_RETIRE_PAGE_PENDING,

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +8 -0
@@ -2518,6 +2520,8 @@ static void amdgpu_ras_do_recovery(struct work_struct *work)
              atomic_set(&hive->ras_recovery, 0);
              amdgpu_put_xgmi_hive(hive);
      }
+
+     complete_all(&ras->ras_recovery_completion);
 }
 
 /* alloc/realloc bps array */
@@ -2911,10 +2915,16 @@ static int
 amdgpu_ras_poison_consumption_handler(struct amdgpu_device *adev,
 
              flush_delayed_work(&con->page_retirement_dwork);
 
+             reinit_completion(&con->ras_recovery_completion);
+
              con->gpu_reset_flags |= reset;
              amdgpu_ras_reset_gpu(adev);
 
              *gpu_reset = reset;
+             if (!wait_for_completion_timeout(&con->ras_recovery_completion,
+                             msecs_to_jiffies(MAX_RAS_RECOVERY_COMPLETION_TIME)))
+                     dev_err(adev->dev, "Waiting for GPU to complete ras reset timeout! reset:0x%x\n",
+                             reset);
 

If a mode-1 reset gets to execute first due to job timeout/hws detect cases in poison timeout, then the ras handler will never get executed. Why this wait is required?

Quoted 2 lines

Thanks,
Lijo

[Thomas] "[PATCH 5/5] drm/amdgpu: add gpu reset check and exception handling" add the check before ras gpu reset.
Poison ras reset is different from reset triggered by other fatal errors, and all poison RAS resets are triggered from here,
in order to distinguish other gpu resets and facilitate subsequent code processing, so add wait for gpu ras reset here.

Quoted 24 lines
      }

      return 0;
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +1 -0
@@ -3041,6 +3051,7 @@ int amdgpu_ras_recovery_init(struct amdgpu_device *adev)
              }
      }
 
+     init_completion(&con->ras_recovery_completion);
      mutex_init(&con->page_rsv_lock);
      INIT_KFIFO(con->poison_fifo);
      mutex_init(&con->page_retirement_lock);
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h +1 -0
index 91daf48be03a..b47f03edac87 100644
@@ -537,6 +537,7 @@ struct amdgpu_ras {
      DECLARE_KFIFO(poison_fifo, struct ras_poison_msg, 128);
      struct ras_ecc_log_info  umc_ecc_log;
      struct delayed_work page_retirement_dwork;
+     struct completion ras_recovery_completion;
 
      /* Fatal error detected flag */
      atomic_t fed;
#7 lore raw

Re: [PATCH 4/5] drm/amdgpu: add completion to wait for ras reset to complete

Quoted 81 lines · Thomas

[AMD Official Use Only - AMD Internal Distribution Only]

-----------------
Best Regards,
Thomas

-----Original Message-----
From: Chai, Thomas
Sent: Tuesday, June 18, 2024 7:09 PM
To: Lazar, Lijo <[email protected]>; [email protected]
Cc: Zhang, Hawking <[email protected]>; Zhou1, Tao <[email protected]>; Li, Candice <[email protected]>; Wang, Yang(Kevin) <[email protected]>; Yang, Stanley <[email protected]>
Subject: RE: [PATCH 4/5] drm/amdgpu: add completion to wait for ras reset to complete

-----------------
Best Regards,
Thomas

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Tuesday, June 18, 2024 6:09 PM
To: Chai, Thomas <[email protected]>; [email protected]
Cc: Zhang, Hawking <[email protected]>; Zhou1, Tao <[email protected]>; Li, Candice <[email protected]>; Wang, Yang(Kevin) <[email protected]>; Yang, Stanley <[email protected]>
Subject: Re: [PATCH 4/5] drm/amdgpu: add completion to wait for ras reset to complete

Quoted 50 lines · YiPeng Chai

Add completion to wait for ras reset to complete.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 11 +++++++++++
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h |  1 +
 2 files changed, 12 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +2 -0
index 898889600771..7f8e6ca07957 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_RAS_RECOVERY_COMPLETION_TIME  120000 //ms
+
 enum amdgpu_ras_retire_page_reservation {
      AMDGPU_RAS_RETIRE_PAGE_RESERVED,

AMDGPU_RAS_RETIRE_PAGE_PENDING,

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +8 -0
@@ -2518,6 +2520,8 @@ static void amdgpu_ras_do_recovery(struct work_struct *work)
              atomic_set(&hive->ras_recovery, 0);
              amdgpu_put_xgmi_hive(hive);
      }
+
+     complete_all(&ras->ras_recovery_completion);
 }
 
 /* alloc/realloc bps array */
@@ -2911,10 +2915,16 @@ static int
 amdgpu_ras_poison_consumption_handler(struct amdgpu_device *adev,
 
              flush_delayed_work(&con->page_retirement_dwork);
 
+             reinit_completion(&con->ras_recovery_completion);
+
              con->gpu_reset_flags |= reset;
              amdgpu_ras_reset_gpu(adev);
 
              *gpu_reset = reset;
+             if (!wait_for_completion_timeout(&con->ras_recovery_completion,
+                             msecs_to_jiffies(MAX_RAS_RECOVERY_COMPLETION_TIME)))
+                     dev_err(adev->dev, "Waiting for GPU to complete ras reset timeout! reset:0x%x\n",
+                             reset);
 

If a mode-1 reset gets to execute first due to job timeout/hws detect cases in poison timeout, then the ras handler will never get executed. Why this wait is required?

Quoted 7 lines
Quoted 2 lines

Thanks,
Lijo

[Thomas] "[PATCH 5/5] drm/amdgpu: add gpu reset check and exception handling" add the check before ras gpu reset.
Poison ras reset is different from reset triggered by other fatal errors, and all poison RAS resets are triggered from here,
in order to distinguish other gpu resets and facilitate subsequent code processing, so add wait for gpu ras reset here.

Reset mechanism resets the GPU state - whether it's triggered due to poison or fatal errors. As soon as the device is reset successfully, GPU operations can continue. So why there needs to be a special wait for poison triggred reset alone? Why not wait on the RAS recovery work object rather than another completion notification?

Thanks,
Lijo

Quoted 24 lines
Quoted 24 lines
      }

      return 0;
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +1 -0
@@ -3041,6 +3051,7 @@ int amdgpu_ras_recovery_init(struct amdgpu_device *adev)
              }
      }
 
+     init_completion(&con->ras_recovery_completion);
      mutex_init(&con->page_rsv_lock);
      INIT_KFIFO(con->poison_fifo);
      mutex_init(&con->page_retirement_lock);
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h +1 -0
index 91daf48be03a..b47f03edac87 100644
@@ -537,6 +537,7 @@ struct amdgpu_ras {
      DECLARE_KFIFO(poison_fifo, struct ras_poison_msg, 128);
      struct ras_ecc_log_info  umc_ecc_log;
      struct delayed_work page_retirement_dwork;
+     struct completion ras_recovery_completion;
 
      /* Fatal error detected flag */
      atomic_t fed;
#8 lore raw

RE: [PATCH 4/5] drm/amdgpu: add completion to wait for ras reset to complete

[AMD Official Use Only - AMD Internal Distribution Only]

-----------------
Best Regards,
Thomas

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Tuesday, June 18, 2024 8:00 PM
To: Chai, Thomas <[email protected]>; [email protected]
Cc: Zhang, Hawking <[email protected]>; Zhou1, Tao <[email protected]>; Li, Candice <[email protected]>; Wang, Yang(Kevin) <[email protected]>; Yang, Stanley <[email protected]>
Subject: Re: [PATCH 4/5] drm/amdgpu: add completion to wait for ras reset to complete

Quoted 93 lines · Thomas

[AMD Official Use Only - AMD Internal Distribution Only]

-----------------
Best Regards,
Thomas

-----Original Message-----
From: Chai, Thomas
Sent: Tuesday, June 18, 2024 7:09 PM
To: Lazar, Lijo <[email protected]>; [email protected]
Cc: Zhang, Hawking <[email protected]>; Zhou1, Tao <[email protected]>; Li, Candice <[email protected]>; Wang, Yang(Kevin) <[email protected]>; Yang, Stanley <[email protected]>
Subject: RE: [PATCH 4/5] drm/amdgpu: add completion to wait for ras reset to complete

-----------------
Best Regards,
Thomas

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Tuesday, June 18, 2024 6:09 PM
To: Chai, Thomas <[email protected]>; [email protected]
Cc: Zhang, Hawking <[email protected]>; Zhou1, Tao <[email protected]>; Li, Candice <[email protected]>; Wang, Yang(Kevin) <[email protected]>; Yang, Stanley <[email protected]>
Subject: Re: [PATCH 4/5] drm/amdgpu: add completion to wait for ras reset to complete

Quoted 52 lines · YiPeng Chai

Add completion to wait for ras reset to complete.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 11 +++++++++++
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h |  1 +
 2 files changed, 12 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +0 -0
index 898889600771..7f8e6ca07957 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

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +2 -0
+#define MAX_RAS_RECOVERY_COMPLETION_TIME  120000 //ms
+
 enum amdgpu_ras_retire_page_reservation {
      AMDGPU_RAS_RETIRE_PAGE_RESERVED,
      AMDGPU_RAS_RETIRE_PAGE_PENDING, @@ -2518,6 +2520,8 @@ static

void amdgpu_ras_do_recovery(struct work_struct *work)

              atomic_set(&hive->ras_recovery, 0);
              amdgpu_put_xgmi_hive(hive);
      }
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +8 -0
+
+     complete_all(&ras->ras_recovery_completion);
 }
 
 /* alloc/realloc bps array */
@@ -2911,10 +2915,16 @@ static int
 amdgpu_ras_poison_consumption_handler(struct amdgpu_device *adev,
 
              flush_delayed_work(&con->page_retirement_dwork);
 
+             reinit_completion(&con->ras_recovery_completion);
+
              con->gpu_reset_flags |= reset;
              amdgpu_ras_reset_gpu(adev);
 
              *gpu_reset = reset;
+             if (!wait_for_completion_timeout(&con->ras_recovery_completion,
+                             msecs_to_jiffies(MAX_RAS_RECOVERY_COMPLETION_TIME)))
+                     dev_err(adev->dev, "Waiting for GPU to complete ras reset timeout! reset:0x%x\n",
+                             reset);
 

If a mode-1 reset gets to execute first due to job timeout/hws detect cases in poison timeout, then the ras handler will never get executed. Why this wait is required?

Quoted 2 lines

Thanks,
Lijo

Quoted 8 lines

[Thomas] "[PATCH 5/5] drm/amdgpu: add gpu reset check and exception handling" add the check before ras gpu reset.
Poison ras reset is different from reset triggered by other fatal errors, and all poison RAS resets are triggered from here,
in order to distinguish other gpu resets and facilitate subsequent code processing, so add wait for gpu ras reset here.

Reset mechanism resets the GPU state - whether it's triggered due to poison or fatal errors. As soon as the device is reset successfully, GPU operations can continue.

So why there needs to be a special wait for poison triggred reset alone?

[Thomas] Different applications may randomly trigger poison errors before gpu reset.
Since poison gpu reset is triggered asynchronously, new poison consumption interrupts may occur in the period after gpu reset request is sent and before the GPU reset is actually performed..
In order to avoid performing a poison gpu reset again after completing the current poison gpu reset, It need to stay here to wait for gpu to complete reset and then clear the cached poison consumption messages.

Quoted 1 line

Why not wait on the RAS recovery work object rather than another completion notification?

[Thomas] Yes, "wait on RAS recovery work object" is a good idea, I will do it.

Thanks,
Lijo

Quoted 24 lines
Quoted 24 lines
      }

      return 0;
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +1 -0
@@ -3041,6 +3051,7 @@ int amdgpu_ras_recovery_init(struct amdgpu_device *adev)
              }
      }
 
+     init_completion(&con->ras_recovery_completion);
      mutex_init(&con->page_rsv_lock);
      INIT_KFIFO(con->poison_fifo);
      mutex_init(&con->page_retirement_lock);
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h +1 -0
index 91daf48be03a..b47f03edac87 100644
@@ -537,6 +537,7 @@ struct amdgpu_ras {
      DECLARE_KFIFO(poison_fifo, struct ras_poison_msg, 128);
      struct ras_ecc_log_info  umc_ecc_log;
      struct delayed_work page_retirement_dwork;
+     struct completion ras_recovery_completion;
 
      /* Fatal error detected flag */
      atomic_t fed;
#9 lore raw

PATCH 5/5 drm/amdgpu: add gpu reset check and exception handling

In reply to YiPeng Chai

Add gpu reset check and exception handling for
page retirement.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 43 +++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +43 -0
index 7f8e6ca07957..635dc86dbfd8 100644
@@ -1386,10 +1386,15 @@ int amdgpu_ras_query_error_status(struct amdgpu_device *adev, struct ras_query_i
 	memset(&qctx, 0, sizeof(qctx));
 	qctx.event_id = amdgpu_ras_acquire_event_id(adev, amdgpu_ras_intr_triggered() ?
 						   RAS_EVENT_TYPE_ISR : RAS_EVENT_TYPE_INVALID);
+
+	if (!down_read_trylock(&adev->reset_domain->sem))
+		return -EIO;
+
 	ret = amdgpu_ras_query_error_status_helper(adev, info,
 						   &err_data,
 						   &qctx,
 						   error_query_mode);
+	up_read(&adev->reset_domain->sem);
 	if (ret)
 		goto out_fini_err_data;
 
@@ -2884,6 +2889,14 @@ static int amdgpu_ras_poison_creation_handler(struct amdgpu_device *adev,
 	return 0;
 }
 
+static void amdgpu_ras_clear_poison_fifo(struct amdgpu_device *adev)
+{
+	struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
+	struct ras_poison_msg msg;
+
+	while (kfifo_get(&con->poison_fifo, &msg));
+}
+
 static int amdgpu_ras_poison_consumption_handler(struct amdgpu_device *adev,
 			uint32_t msg_count, uint32_t *gpu_reset)
 {
@@ -2913,6 +2926,11 @@ static int amdgpu_ras_poison_consumption_handler(struct amdgpu_device *adev,
 		else
 			reset = reset_flags;
 
+		/* Check if gpu is in reset state */
+		if (!down_read_trylock(&adev->reset_domain->sem))
+			return -EIO;
+		up_read(&adev->reset_domain->sem);
+
 		flush_delayed_work(&con->page_retirement_dwork);
 
 		reinit_completion(&con->ras_recovery_completion);
@@ -2977,6 +2995,31 @@ static int amdgpu_ras_page_retirement_thread(void *param)
 			}
 		}
 
+		if ((ret == -EIO) || (gpu_reset == AMDGPU_RAS_GPU_RESET_MODE1_RESET)) {
+			/* gpu is in mode-1 reset state */
+			/* Clear poison creation request */
+			while (atomic_read(&con->poison_creation_count))
+				atomic_dec(&con->poison_creation_count);
+
+			/* Clear poison consumption fifo */
+			amdgpu_ras_clear_poison_fifo(adev);
+
+			while (atomic_read(&con->page_retirement_req_cnt))
+				atomic_dec(&con->page_retirement_req_cnt);
+
+			if (ret == -EIO) {
+				/* Wait for mode-1 reset to complete */
+				down_read(&adev->reset_domain->sem);
+				up_read(&adev->reset_domain->sem);
+			}
+
+			/* Wake up work queue to save bad pages to eeprom */
+			schedule_delayed_work(&con->page_retirement_dwork, 0);
+		} else if (gpu_reset) {
+			/* gpu is in mode-2 reset or other reset state */
+			/* Wake up work queue to save bad pages to eeprom */
+			schedule_delayed_work(&con->page_retirement_dwork, 0);
+		}
 #else
         dev_info(adev->dev, "Start processing page retirement. request:%d\n",
                     atomic_read(&con->page_retirement_req_cnt));
Signature · 1 line
2.34.1
#10 lore raw

RE: [PATCH 5/5] drm/amdgpu: add gpu reset check and exception handling

-----Original Message-----
From: Chai, Thomas <[email protected]>
Sent: 2024年6月18日 14:34
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 5/5] drm/amdgpu: add gpu reset check and exception handling

Add gpu reset check and exception handling for page retirement.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 43 +++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +11 -0
index 7f8e6ca07957..635dc86dbfd8 100644
@@ -1386,10 +1386,15 @@ int amdgpu_ras_query_error_status(struct amdgpu_device *adev, struct ras_query_i
 	memset(&qctx, 0, sizeof(qctx));
 	qctx.event_id = amdgpu_ras_acquire_event_id(adev, amdgpu_ras_intr_triggered() ?
 						   RAS_EVENT_TYPE_ISR : RAS_EVENT_TYPE_INVALID);
+
+	if (!down_read_trylock(&adev->reset_domain->sem))
+		return -EIO;
+
 	ret = amdgpu_ras_query_error_status_helper(adev, info,
 						   &err_data,
 						   &qctx,
 						   error_query_mode);
+	up_read(&adev->reset_domain->sem);
 	if (ret)
 		goto out_fini_err_data;
 
@@ -2884,6 +2889,14 @@ static int amdgpu_ras_poison_creation_handler(struct amdgpu_device *adev,
 	return 0;
 }
 
+static void amdgpu_ras_clear_poison_fifo(struct amdgpu_device *adev) {
+	struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
+	struct ras_poison_msg msg;
+
+	while (kfifo_get(&con->poison_fifo, &msg)); }
+
 static int amdgpu_ras_poison_consumption_handler(struct amdgpu_device *adev,
 			uint32_t msg_count, uint32_t *gpu_reset)  { @@ -2913,6 +2926,11 @@ static int amdgpu_ras_poison_consumption_handler(struct amdgpu_device *adev,
 		else

reset = reset_flags;

+ /* Check if gpu is in reset state */
+ if (!down_read_trylock(&adev->reset_domain->sem))
+ return -EIO;
+ up_read(&adev->reset_domain->sem);

[Kevin]:
I'm confused that why not using 'amdgpu_in_reset()' helper function to check reset state?

Best Regards,
Kevin
+
flush_delayed_work(&con->page_retirement_dwork);

reinit_completion(&con->ras_recovery_completion);
@@ -2977,6 +2995,31 @@ static int amdgpu_ras_page_retirement_thread(void *param)
}
}

+ if ((ret == -EIO) || (gpu_reset == AMDGPU_RAS_GPU_RESET_MODE1_RESET)) {
+ /* gpu is in mode-1 reset state */
+ /* Clear poison creation request */
+ while (atomic_read(&con->poison_creation_count))
+ atomic_dec(&con->poison_creation_count);
[Kevin]:

Aha! It is better to use atomic_set() to instead of it.

Best Regards,
Kevin
+
+ /* Clear poison consumption fifo */
+ amdgpu_ras_clear_poison_fifo(adev);
+
+ while (atomic_read(&con->page_retirement_req_cnt))
+ atomic_dec(&con->page_retirement_req_cnt);
+
+ if (ret == -EIO) {
+ /* Wait for mode-1 reset to complete */
+ down_read(&adev->reset_domain->sem);
+ up_read(&adev->reset_domain->sem);
+ }
+
+ /* Wake up work queue to save bad pages to eeprom */
+ schedule_delayed_work(&con->page_retirement_dwork, 0);
+ } else if (gpu_reset) {
+ /* gpu is in mode-2 reset or other reset state */
+ /* Wake up work queue to save bad pages to eeprom */
+ schedule_delayed_work(&con->page_retirement_dwork, 0);
+ }

 #else
         dev_info(adev->dev, "Start processing page retirement. request:%d\n",
                     atomic_read(&con->page_retirement_req_cnt));

--
2.34.1

#11 lore raw

RE: [PATCH 5/5] drm/amdgpu: add gpu reset check and exception handling

[AMD Official Use Only - AMD Internal Distribution Only]

-----------------
Best Regards,
Thomas

-----Original Message-----
From: Wang, Yang(Kevin) <[email protected]>
Sent: Tuesday, June 18, 2024 3:19 PM
To: Chai, Thomas <[email protected]>; [email protected]
Cc: Zhang, Hawking <[email protected]>; Zhou1, Tao <[email protected]>; Li, Candice <[email protected]>; Yang, Stanley <[email protected]>
Subject: RE: [PATCH 5/5] drm/amdgpu: add gpu reset check and exception handling

-----Original Message-----
From: Chai, Thomas <[email protected]>
Sent: 2024年6月18日 14:34
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 5/5] drm/amdgpu: add gpu reset check and exception handling

Add gpu reset check and exception handling for page retirement.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 43 +++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +11 -0
index 7f8e6ca07957..635dc86dbfd8 100644
@@ -1386,10 +1386,15 @@ int amdgpu_ras_query_error_status(struct amdgpu_device *adev, struct ras_query_i
        memset(&qctx, 0, sizeof(qctx));
        qctx.event_id = amdgpu_ras_acquire_event_id(adev, amdgpu_ras_intr_triggered() ?
                                                   RAS_EVENT_TYPE_ISR : RAS_EVENT_TYPE_INVALID);
+
+       if (!down_read_trylock(&adev->reset_domain->sem))
+               return -EIO;
+
        ret = amdgpu_ras_query_error_status_helper(adev, info,
                                                   &err_data,
                                                   &qctx,
                                                   error_query_mode);
+       up_read(&adev->reset_domain->sem);
        if (ret)
                goto out_fini_err_data;
 
@@ -2884,6 +2889,14 @@ static int amdgpu_ras_poison_creation_handler(struct amdgpu_device *adev,
        return 0;
 }
 
+static void amdgpu_ras_clear_poison_fifo(struct amdgpu_device *adev) {
+       struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
+       struct ras_poison_msg msg;
+
+       while (kfifo_get(&con->poison_fifo, &msg)); }
+
 static int amdgpu_ras_poison_consumption_handler(struct amdgpu_device *adev,
                        uint32_t msg_count, uint32_t *gpu_reset)  { @@ -2913,6 +2926,11 @@ static int amdgpu_ras_poison_consumption_handler(struct amdgpu_device *adev,
                else
                        reset = reset_flags;

+ /* Check if gpu is in reset state */
+ if (!down_read_trylock(&adev->reset_domain->sem))
+ return -EIO;
+ up_read(&adev->reset_domain->sem);

Quoted 5 lines

[Kevin]:
I'm confused that why not using 'amdgpu_in_reset()' helper function to check reset state?

Best Regards,
Kevin

[Thomas] This function is called in page retirement thread.
According to Christian König's previous email suggestions that "It's illegal to call amdgpu_in_reset() from outside of the hw specific backends."

+

                flush_delayed_work(&con->page_retirement_dwork);

                reinit_completion(&con->ras_recovery_completion);
@@ -2977,6 +2995,31 @@ static int amdgpu_ras_page_retirement_thread(void *param)
                        }
                }

+ if ((ret == -EIO) || (gpu_reset == AMDGPU_RAS_GPU_RESET_MODE1_RESET)) {

+                       /* gpu is in mode-1 reset state */
+                       /* Clear poison creation request */
+                       while (atomic_read(&con->poison_creation_count))

+ atomic_dec(&con->poison_creation_count);
[Kevin]:

Aha! It is better to use atomic_set() to instead of it.

Best Regards,
Kevin
+
+ /* Clear poison consumption fifo */
+ amdgpu_ras_clear_poison_fifo(adev);
+
+ while (atomic_read(&con->page_retirement_req_cnt))
+ atomic_dec(&con->page_retirement_req_cnt);
+
+ if (ret == -EIO) {

+                               /* Wait for mode-1 reset to complete */
+                               down_read(&adev->reset_domain->sem);
+                               up_read(&adev->reset_domain->sem);

+ }
+
+ /* Wake up work queue to save bad pages to eeprom */
+ schedule_delayed_work(&con->page_retirement_dwork, 0);
+ } else if (gpu_reset) {

+                       /* gpu is in mode-2 reset or other reset state */
+                       /* Wake up work queue to save bad pages to eeprom */
+                       schedule_delayed_work(&con->page_retirement_dwork, 0);
+               }
 #else
         dev_info(adev->dev, "Start processing page retirement. request:%d\n",
                     atomic_read(&con->page_retirement_req_cnt));

--
2.34.1