Skip to contentSkip to conversation

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

PATCH In review YiPeng Chai 2 participants 9 messages Jun 20, 2024 – Jun 21, 2024

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

PATCH v2 1/4 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 86cb97d2155b..f674e34037b6 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
 
@@ -2804,7 +2804,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)
@@ -2823,7 +2824,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
 
@@ -2856,40 +2858,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 -ENOENT;
 	}
 
-	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 83437fef9df5..748bbac666e6 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 v2 2/4 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 | 37 ++++++++++++-------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h |  1 +
 2 files changed, 18 insertions(+), 20 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +17 -20
index f674e34037b6..308348b4644f 100644
@@ -2106,10 +2106,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);
 	}
@@ -2945,6 +2943,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;
@@ -2958,7 +2958,18 @@ 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) {
+				atomic_sub(poison_creation_count, &con->poison_creation_count);
+				atomic_sub(poison_creation_count, &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))
@@ -2969,24 +2980,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));
@@ -3066,6 +3061,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)) {
@@ -3117,6 +3113,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 748bbac666e6..0fa1148e6642 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
Reviewed-by on v2 2/4
#2 lore raw

RE: [PATCH V2 2/4] drm/amdgpu: refine poison creation interrupt handler

[AMD Official Use Only - AMD Internal Distribution Only]

Regards,
Hawking
-----Original Message-----
From: Chai, Thomas <[email protected]>
Sent: Thursday, June 20, 2024 13:40
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/4] 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 | 37 ++++++++++++-------------  drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h |  1 +
 2 files changed, 18 insertions(+), 20 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +3 -3
index f674e34037b6..308348b4644f 100644
@@ -2106,10 +2106,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);
        }
@@ -2945,6 +2943,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; @@ -2958,7 +2958,18 @@ 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) {
+ atomic_sub(poison_creation_count, &con->poison_creation_count);
+ atomic_sub(poison_creation_count, &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)) @@ -2969,24 +2980,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));
@@ -3066,6 +3061,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)) { @@ -3117,6 +3113,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 748bbac666e6..0fa1148e6642 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;

--
2.34.1

#3 lore raw

PATCH v2 3/4 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 | 56 ++++++++++++++++---------
 drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c | 12 +++---
 2 files changed, 44 insertions(+), 24 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +37 -19
index 308348b4644f..a4030dc12a1c 100644
@@ -2917,23 +2917,41 @@ 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;
+	}
 
 	/* for RMA, amdgpu_ras_poison_creation_handler will trigger gpu reset */
-	if (reset && !con->is_rma) {
+	if (reset_flags && !con->is_rma) {
+		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;
+
 		flush_delayed_work(&con->page_retirement_dwork);
 
 		con->gpu_reset_flags |= reset;
 		amdgpu_ras_reset_gpu(adev);
+
+		*gpu_reset = reset;
 	}
 
 	return 0;
@@ -2943,11 +2961,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()) {
 
@@ -2958,6 +2974,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);
@@ -2972,16 +2989,17 @@ 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))
+					atomic_sub(msg_count, &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 4a72ff8d8d80..38e7793137ee 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
Reviewed-by on v2 3/4
#4 lore raw

RE: [PATCH V2 3/4] drm/amdgpu: refine poison consumption interrupt handler

[AMD Official Use Only - AMD Internal Distribution Only]

Regards,
Hawking
-----Original Message-----
From: Chai, Thomas <[email protected]>
Sent: Thursday, June 20, 2024 13:40
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 3/4] drm/amdgpu: refine poison consumption interrupt handler

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 | 56 ++++++++++++++++---------  drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c | 12 +++---
 2 files changed, 44 insertions(+), 24 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +37 -19
index 308348b4644f..a4030dc12a1c 100644
@@ -2917,23 +2917,41 @@ 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;
+       }
 
        /* for RMA, amdgpu_ras_poison_creation_handler will trigger gpu reset */
-       if (reset && !con->is_rma) {
+       if (reset_flags && !con->is_rma) {
+               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;
+
                flush_delayed_work(&con->page_retirement_dwork);
 
                con->gpu_reset_flags |= reset;
                amdgpu_ras_reset_gpu(adev);
+
+               *gpu_reset = reset;
        }
 
        return 0;
@@ -2943,11 +2961,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()) {
 
@@ -2958,6 +2974,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);
@@ -2972,16 +2989,17 @@ 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))
+                                       atomic_sub(msg_count, &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 4a72ff8d8d80..38e7793137ee 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)

--
2.34.1

#5 lore raw

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

In reply to YiPeng Chai

Add gpu reset check and exception handling for
page retirement.

v2:
Clear poison consumption messages cached in fifo after
non mode-1 reset.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 52 +++++++++++++++++++++++++
 1 file changed, 52 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +52 -0
index a4030dc12a1c..ce7c7723e626 100644
@@ -1384,10 +1384,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;
 
@@ -2916,6 +2921,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)
 {
@@ -2946,12 +2959,20 @@ static int amdgpu_ras_poison_consumption_handler(struct amdgpu_device *adev,
 		else
 			reset = reset_flags;
 
+		/* If gpu reset is ongoing, not need to reset gpu again */
+		if (!down_read_trylock(&adev->reset_domain->sem))
+			return -EIO;
+		up_read(&adev->reset_domain->sem);
+
 		flush_delayed_work(&con->page_retirement_dwork);
 
 		con->gpu_reset_flags |= reset;
 		amdgpu_ras_reset_gpu(adev);
 
 		*gpu_reset = reset;
+
+		/* Wait for gpu recovery to complete */
+		flush_work(&con->recovery_work);
 	}
 
 	return 0;
@@ -3000,6 +3021,37 @@ static int amdgpu_ras_page_retirement_thread(void *param)
 			}
 		}
 
+		if ((ret == -EIO) || (gpu_reset == AMDGPU_RAS_GPU_RESET_MODE1_RESET)) {
+			/* gpu mode-1 reset is ongoing or just completed ras mode-1 reset */
+			/* Clear poison creation request */
+			atomic_set(&con->poison_creation_count, 0);
+
+			/* Clear poison fifo */
+			amdgpu_ras_clear_poison_fifo(adev);
+
+			/* Clear all poison requests*/
+			atomic_set(&con->page_retirement_req_cnt, 0);
+
+			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 to save bad pages to eeprom */
+			schedule_delayed_work(&con->page_retirement_dwork, 0);
+		} else if (gpu_reset) {
+			/* gpu just completed mode-2 reset or other reset */
+			/* Clear poison consumption messages cached in fifo */
+			msg_count = kfifo_len(&con->poison_fifo);
+			if (msg_count) {
+				amdgpu_ras_clear_poison_fifo(adev);
+				atomic_sub(msg_count, &con->page_retirement_req_cnt);
+			}
+
+			/* Wake up work 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
Reviewed-by on v2 4/4
#6 lore raw

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

[AMD Official Use Only - AMD Internal Distribution Only]

Regards,
Hawking
-----Original Message-----
From: Chai, Thomas <[email protected]>
Sent: Thursday, June 20, 2024 13:40
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 4/4] drm/amdgpu: add gpu reset check and exception handling

Add gpu reset check and exception handling for page retirement.

v2:
Clear poison consumption messages cached in fifo after non mode-1 reset.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 52 +++++++++++++++++++++++++
 1 file changed, 52 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +11 -0
index a4030dc12a1c..ce7c7723e626 100644
@@ -1384,10 +1384,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;
 
@@ -2916,6 +2921,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)  { @@ -2946,12 +2959,20 @@ static int amdgpu_ras_poison_consumption_handler(struct amdgpu_device *adev,
                else
                        reset = reset_flags;

+ /* If gpu reset is ongoing, not need to reset gpu again */
+ if (!down_read_trylock(&adev->reset_domain->sem))
+ return -EIO;
+ up_read(&adev->reset_domain->sem);
+

                flush_delayed_work(&con->page_retirement_dwork);

                con->gpu_reset_flags |= reset;
                amdgpu_ras_reset_gpu(adev);

                *gpu_reset = reset;
+
+               /* Wait for gpu recovery to complete */
+               flush_work(&con->recovery_work);
        }

        return 0;
@@ -3000,6 +3021,37 @@ static int amdgpu_ras_page_retirement_thread(void *param)
                        }
                }

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

+                       /* gpu mode-1 reset is ongoing or just completed ras mode-1 reset */
+                       /* Clear poison creation request */
+                       atomic_set(&con->poison_creation_count, 0);

+
+ /* Clear poison fifo */
+ amdgpu_ras_clear_poison_fifo(adev);
+
+ /* Clear all poison requests*/
+ atomic_set(&con->page_retirement_req_cnt, 0);
+
+ 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 to save bad pages to eeprom */
+ schedule_delayed_work(&con->page_retirement_dwork, 0);
+ } else if (gpu_reset) {

+                       /* gpu just completed mode-2 reset or other reset */
+                       /* Clear poison consumption messages cached in fifo */
+                       msg_count = kfifo_len(&con->poison_fifo);
+                       if (msg_count) {

+ amdgpu_ras_clear_poison_fifo(adev);
+ atomic_sub(msg_count, &con->page_retirement_req_cnt);
+ }
+
+ /* Wake up work 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

#7 lore raw
In reply to YiPeng Chai

[AMD Official Use Only - AMD Internal Distribution Only]

Shall we make pre_de_queried_count to be local variable? Others look good to me

Regards,
Hawking

-----Original Message-----
From: Chai, Thomas <[email protected]>
Sent: Thursday, June 20, 2024 13:40
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 1/4] 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 +3 -2
index 86cb97d2155b..f674e34037b6 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
 
@@ -2804,7 +2804,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) @@ -2823,7 +2824,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

@@ -2856,40 +2858,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 -ENOENT;
        }

- 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, diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h
index 83437fef9df5..748bbac666e6 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h +2 -1
@@ -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;
 }

--
2.34.1

#8 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

prevd_queried_count and de_queried_count are used to accurately count the number of DE lost after driver receives a large number of poison creation interrupts.

Since amdgpu_ras_query_error_status can be called by page_retirment_thread, xxx_err_count sysfs and gpu recovery,
using local variable to save the old de_queried_count before calling amdgpu_ras_query_error_status in page_retirment_thread will be inaccurate.

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

-----Original Message-----
From: Zhang, Hawking <[email protected]>
Sent: Friday, June 21, 2024 2:37 PM
To: Chai, Thomas <[email protected]>; [email protected]
Cc: Zhou1, Tao <[email protected]>; Li, Candice <[email protected]>; Wang, Yang(Kevin) <[email protected]>; Yang, Stanley <[email protected]>
Subject: RE: [PATCH V2 1/4] drm/amdgpu: add variable to record the deferred error number read by driver

[AMD Official Use Only - AMD Internal Distribution Only]

Shall we make pre_de_queried_count to be local variable? Others look good to me

Regards,
Hawking

-----Original Message-----
From: Chai, Thomas <[email protected]>
Sent: Thursday, June 20, 2024 13:40
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 1/4] 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 +3 -2
index 86cb97d2155b..f674e34037b6 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
 
@@ -2804,7 +2804,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) @@ -2823,7 +2824,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

@@ -2856,40 +2858,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 -ENOENT;
        }

- 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, diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h
index 83437fef9df5..748bbac666e6 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h +2 -1
@@ -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;
 }

--
2.34.1