Skip to contentSkip to conversation

drm/amdgpu: refine amdgpu ras event id core code

PATCH In review Yang Wang 2 participants 6 messages Jul 8, 2024

Subsystems (3)
lore
Share & tools
lore

Yang Wang

author
#0 lore raw

PATCH v4 1/4 drm/amdgpu: refine amdgpu ras event id core code

v1:
- use unified event id to manage ras events
- add a new function amdgpu_ras_query_error_status_with_event() to accept event type as parameter.

v2:
add a warn log to show the location of function failure when calling amdgpu_ras_mark_event(). (Tao Zhou)

v3:
change RAS_EVENT_TYPE_ISR to RAS_EVENT_TYPE_FATAL.

v4:
rename amdgpu_ras_get_recovery_event() to
amdgpu_ras_get_fatal_error_event().

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c |   2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c |   4 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 101 +++++++++++++++++++-----
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h |  21 +++--
 drivers/gpu/drm/amd/amdgpu_ras.c        |   0
 5 files changed, 102 insertions(+), 26 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/amdgpu_ras.c
drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c +1 -1
index 7945173321a2..19158cc30f31 100644
@@ -119,7 +119,7 @@ static struct aca_regs_dump {
 static void aca_smu_bank_dump(struct amdgpu_device *adev, int idx, int total, struct aca_bank *bank,
 			      struct ras_query_context *qctx)
 {
-	u64 event_id = qctx ? qctx->event_id : 0ULL;
+	u64 event_id = qctx ? qctx->evid.event_id : RAS_EVENT_INVALID_ID;
 	int i;
 
 	RAS_EVENT_LOG(adev, event_id, HW_ERR "Accelerator Check Architecture events logged\n");
drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c +2 -2
index 9d3a3c778504..2542bd7aa7c7 100644
@@ -274,7 +274,7 @@ int amdgpu_mca_smu_set_debug_mode(struct amdgpu_device *adev, bool enable)
 static void amdgpu_mca_smu_mca_bank_dump(struct amdgpu_device *adev, int idx, struct mca_bank_entry *entry,
 					 struct ras_query_context *qctx)
 {
-	u64 event_id = qctx->event_id;
+	u64 event_id = qctx ? qctx->evid.event_id : RAS_EVENT_INVALID_ID;
 
 	RAS_EVENT_LOG(adev, event_id, HW_ERR "Accelerator Check Architecture events logged\n");
 	RAS_EVENT_LOG(adev, event_id, HW_ERR "aca entry[%02d].STATUS=0x%016llx\n",
@@ -543,7 +543,7 @@ static int mca_dump_show(struct seq_file *m, enum amdgpu_mca_error_type type)
 
 	amdgpu_mca_bank_set_init(&mca_set);
 
-	qctx.event_id = 0ULL;
+	qctx.evid.event_id = RAS_EVENT_INVALID_ID;
 	ret = amdgpu_mca_smu_get_mca_set(adev, type, &mca_set, &qctx);
 	if (ret)
 		goto err_free_mca_set;
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +83 -18

199 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h +16 -5
index 18d994c98a25..fd6a4c55bdc9 100644
@@ -68,9 +68,15 @@ struct amdgpu_iv_entry;
 /* The high three bits indicates socketid */
 #define AMDGPU_RAS_GET_FEATURES(val)  ((val) & ~AMDGPU_RAS_FEATURES_SOCKETID_MASK)
 
+#define RAS_EVENT_INVALID_ID		(BIT_ULL(63))
+#define RAS_EVENT_ID_IS_VALID(x)	(!((x) & BIT_ULL(63)))
+
 #define RAS_EVENT_LOG(adev, id, fmt, ...)	\
 	amdgpu_ras_event_log_print((adev), (id), (fmt), ##__VA_ARGS__)
 
+#define amdgpu_ras_mark_ras_event(adev, type)	\
+	(amdgpu_ras_mark_ras_event_caller((adev), (type), __builtin_return_address(0)))
+
 enum amdgpu_ras_block {
 	AMDGPU_RAS_BLOCK__UMC = 0,
 	AMDGPU_RAS_BLOCK__SDMA,
@@ -427,20 +433,25 @@ struct umc_ecc_info {
 };
 
 enum ras_event_type {
-	RAS_EVENT_TYPE_INVALID = -1,
-	RAS_EVENT_TYPE_ISR = 0,
+	RAS_EVENT_TYPE_INVALID = 0,
+	RAS_EVENT_TYPE_FATAL,
 	RAS_EVENT_TYPE_COUNT,
 };
 
 struct ras_event_manager {
-	atomic64_t seqnos[RAS_EVENT_TYPE_COUNT];
+	atomic64_t seqno;
+	u64 last_seqno[RAS_EVENT_TYPE_COUNT];
 };
 
-struct ras_query_context {
+struct ras_event_id {
 	enum ras_event_type type;
 	u64 event_id;
 };
 
+struct ras_query_context {
+	struct ras_event_id evid;
+};
+
 typedef int (*pasid_notify)(struct amdgpu_device *adev,
 		uint16_t pasid, void *data);
 
@@ -947,8 +958,8 @@ void amdgpu_ras_del_mca_err_addr(struct ras_err_info *err_info,
 void amdgpu_ras_set_fed(struct amdgpu_device *adev, bool status);
 bool amdgpu_ras_get_fed_status(struct amdgpu_device *adev);
 
-bool amdgpu_ras_event_id_is_valid(struct amdgpu_device *adev, u64 id);
 u64 amdgpu_ras_acquire_event_id(struct amdgpu_device *adev, enum ras_event_type type);
+int amdgpu_ras_mark_ras_event_caller(struct amdgpu_device *adev, enum ras_event_type type, const void *caller);
 
 int amdgpu_ras_reserve_page(struct amdgpu_device *adev, uint64_t pfn);
 
drivers/gpu/drm/amd/amdgpu_ras.c new file +0 -0
new file mode 100644
index 000000000000..e69de29bb2d1
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v4 2/4 drm/amdgpu: add ras POSION_CREATION event id support

add amdgpu ras POSION_CREATION event id support.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 17 ++++++++++++++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h |  1 +
 2 files changed, 15 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +14 -3
index a40886d0f507..c7e68c5e90cd 100644
@@ -2116,8 +2116,17 @@ static void amdgpu_ras_interrupt_poison_consumption_handler(struct ras_manager *
 static void amdgpu_ras_interrupt_poison_creation_handler(struct ras_manager *obj,
 				struct amdgpu_iv_entry *entry)
 {
-	dev_info(obj->adev->dev,
-		"Poison is created\n");
+	struct amdgpu_device *adev = obj->adev;
+	enum ras_event_type type = RAS_EVENT_TYPE_POISON_CREATION;
+	u64 event_id;
+	int ret;
+
+	ret = amdgpu_ras_mark_ras_event(adev, type);
+	if (ret)
+		return;
+
+	event_id = amdgpu_ras_acquire_event_id(adev, type);
+	RAS_EVENT_LOG(adev, event_id, "Poison is created\n");
 
 	if (amdgpu_ip_version(obj->adev, UMC_HWIP, 0) >= IP_VERSION(12, 0, 0)) {
 		struct amdgpu_ras *con = amdgpu_ras_get_context(obj->adev);
@@ -2889,6 +2898,7 @@ static int amdgpu_ras_poison_creation_handler(struct amdgpu_device *adev,
 	uint32_t new_detect_count, total_detect_count;
 	uint32_t need_query_count = poison_creation_count;
 	bool query_data_timeout = false;
+	enum ras_event_type type = RAS_EVENT_TYPE_POISON_CREATION;
 
 	memset(&info, 0, sizeof(info));
 	info.head.block = AMDGPU_RAS_BLOCK__UMC;
@@ -2896,7 +2906,7 @@ static int amdgpu_ras_poison_creation_handler(struct amdgpu_device *adev,
 	ecc_log = &ras->umc_ecc_log;
 	total_detect_count = 0;
 	do {
-		ret = amdgpu_ras_query_error_status(adev, &info);
+		ret = amdgpu_ras_query_error_status_with_event(adev, &info, type);
 		if (ret)
 			return ret;
 
@@ -3974,6 +3984,7 @@ u64 amdgpu_ras_acquire_event_id(struct amdgpu_device *adev, enum ras_event_type
 
 	switch (type) {
 	case RAS_EVENT_TYPE_FATAL:
+	case RAS_EVENT_TYPE_POISON_CREATION:
 		event_mgr = __get_ras_event_mgr(adev);
 		if (!event_mgr)
 			return RAS_EVENT_INVALID_ID;
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h +1 -0
index fd6a4c55bdc9..69eb5fd4640f 100644
@@ -435,6 +435,7 @@ struct umc_ecc_info {
 enum ras_event_type {
 	RAS_EVENT_TYPE_INVALID = 0,
 	RAS_EVENT_TYPE_FATAL,
+	RAS_EVENT_TYPE_POISON_CREATION,
 	RAS_EVENT_TYPE_COUNT,
 };
 
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH v4 3/4 drm/amdgpu: add ras POSION_CONSUMPTION event id support

In reply to Yang Wang

add amdgpu ras POSION_CONSUMPTION event id support.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c         | 16 +++++++++++++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h         |  1 +
 drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c | 15 ++++++++++++---
 3 files changed, 26 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +13 -3
index c7e68c5e90cd..ca09316fbb6a 100644
@@ -2076,10 +2076,17 @@ static void amdgpu_ras_interrupt_poison_consumption_handler(struct ras_manager *
 	struct amdgpu_ras_block_object *block_obj =
 		amdgpu_ras_get_ras_block(adev, obj->head.block, 0);
 	struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
+	enum ras_event_type type = RAS_EVENT_TYPE_POISON_CONSUMPTION;
+	u64 event_id;
+	int ret;
 
 	if (!block_obj || !con)
 		return;
 
+	ret = amdgpu_ras_mark_ras_event(adev, type);
+	if (ret)
+		return;
+
 	/* both query_poison_status and handle_poison_consumption are optional,
 	 * but at least one of them should be implemented if we need poison
 	 * consumption handler
@@ -2104,8 +2111,10 @@ static void amdgpu_ras_interrupt_poison_consumption_handler(struct ras_manager *
 	 * For RMA case, amdgpu_umc_poison_handler will handle gpu reset.
 	 */
 	if (poison_stat && !con->is_rma) {
-		dev_info(adev->dev, "GPU reset for %s RAS poison consumption is issued!\n",
-				block_obj->ras_comm.name);
+		event_id = amdgpu_ras_acquire_event_id(adev, type);
+		RAS_EVENT_LOG(adev, event_id,
+			      "GPU reset for %s RAS poison consumption is issued!\n",
+			      block_obj->ras_comm.name);
 		amdgpu_ras_reset_gpu(adev);
 	}
 
@@ -2498,7 +2507,7 @@ static enum ras_event_type amdgpu_ras_get_fatal_error_event(struct amdgpu_device
 	if (amdgpu_ras_intr_triggered())
 		return RAS_EVENT_TYPE_FATAL;
 	else
-		return RAS_EVENT_TYPE_INVALID;
+		return RAS_EVENT_TYPE_POISON_CONSUMPTION;
 }
 
 static void amdgpu_ras_do_recovery(struct work_struct *work)
@@ -3985,6 +3994,7 @@ u64 amdgpu_ras_acquire_event_id(struct amdgpu_device *adev, enum ras_event_type
 	switch (type) {
 	case RAS_EVENT_TYPE_FATAL:
 	case RAS_EVENT_TYPE_POISON_CREATION:
+	case RAS_EVENT_TYPE_POISON_CONSUMPTION:
 		event_mgr = __get_ras_event_mgr(adev);
 		if (!event_mgr)
 			return RAS_EVENT_INVALID_ID;
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h +1 -0
index 69eb5fd4640f..49ec8edcbe39 100644
@@ -436,6 +436,7 @@ enum ras_event_type {
 	RAS_EVENT_TYPE_INVALID = 0,
 	RAS_EVENT_TYPE_FATAL,
 	RAS_EVENT_TYPE_POISON_CREATION,
+	RAS_EVENT_TYPE_POISON_CONSUMPTION,
 	RAS_EVENT_TYPE_COUNT,
 };
 
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +12 -3
index 816800555f7f..8a10a0e42846 100644
@@ -27,6 +27,7 @@
 #include "soc15_int.h"
 #include "kfd_device_queue_manager.h"
 #include "kfd_smi_events.h"
+#include "amdgpu_ras.h"
 
 /*
  * GFX9 SQ Interrupts
@@ -144,9 +145,11 @@ static void event_interrupt_poison_consumption_v9(struct kfd_node *dev,
 				uint16_t pasid, uint16_t client_id)
 {
 	enum amdgpu_ras_block block = 0;
-	int old_poison;
 	uint32_t reset = 0;
 	struct kfd_process *p = kfd_lookup_process_by_pasid(pasid);
+	enum ras_event_type type = RAS_EVENT_TYPE_POISON_CONSUMPTION;
+	u64 event_id;
+	int old_poison, ret;
 
 	if (!p)
 		return;
@@ -191,10 +194,16 @@ static void event_interrupt_poison_consumption_v9(struct kfd_node *dev,
 		return;
 	}
 
+	ret = amdgpu_ras_mark_ras_event(dev->adev, type);
+	if (ret)
+		return;
+
 	kfd_signal_poison_consumed_event(dev, pasid);
 
-	dev_warn(dev->adev->dev,
-		 "poison is consumed by client %d, kick off gpu reset flow\n", client_id);
+	event_id = amdgpu_ras_acquire_event_id(dev->adev, type);
+
+	RAS_EVENT_LOG(dev->adev, event_id,
+		      "poison is consumed by client %d, kick off gpu reset flow\n", client_id);
 
 	amdgpu_amdkfd_ras_pasid_poison_consumption_handler(dev->adev,
 		block, pasid, NULL, NULL, reset);
Signature · 1 line
2.34.1
Reviewed-by Reviewed-by Tao Zhou on v4 3/4
#3 lore raw

RE: [PATCH v4 3/4] drm/amdgpu: add ras POSION_CONSUMPTION event id support

[AMD Official Use Only - AMD Internal Distribution Only]

amdgpu_ras_get_fatal_error_event(struct amdgpu_device

        if (amdgpu_ras_intr_triggered())
                return RAS_EVENT_TYPE_FATAL;
        else

- return RAS_EVENT_TYPE_INVALID;
+ return RAS_EVENT_TYPE_POISON_CONSUMPTION;
}

Keep in mind that this is temp solution to treat poison as fatal. Moving forward, we will need to check poison handling option to determine return poison consumption or invalid event here.

The series is

Regards,
Hawking
-----Original Message-----
From: Wang, Yang(Kevin) <[email protected]>
Sent: Monday, July 8, 2024 11:25
To: [email protected]
Cc: Zhang, Hawking <[email protected]>; Zhou1, Tao <[email protected]>
Subject: [PATCH v4 3/4] drm/amdgpu: add ras POSION_CONSUMPTION event id support

add amdgpu ras POSION_CONSUMPTION event id support.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c         | 16 +++++++++++++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h         |  1 +
 drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c | 15 ++++++++++++---
 3 files changed, 26 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +12 -3
index c7e68c5e90cd..ca09316fbb6a 100644
@@ -2076,10 +2076,17 @@ static void amdgpu_ras_interrupt_poison_consumption_handler(struct ras_manager *
        struct amdgpu_ras_block_object *block_obj =
                amdgpu_ras_get_ras_block(adev, obj->head.block, 0);
        struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
+       enum ras_event_type type = RAS_EVENT_TYPE_POISON_CONSUMPTION;
+       u64 event_id;
+       int ret;
 
        if (!block_obj || !con)
                return;
 
+       ret = amdgpu_ras_mark_ras_event(adev, type);
+       if (ret)
+               return;
+
        /* both query_poison_status and handle_poison_consumption are optional,
         * but at least one of them should be implemented if we need poison
         * consumption handler
@@ -2104,8 +2111,10 @@ static void amdgpu_ras_interrupt_poison_consumption_handler(struct ras_manager *
         * For RMA case, amdgpu_umc_poison_handler will handle gpu reset.
         */
        if (poison_stat && !con->is_rma) {
-               dev_info(adev->dev, "GPU reset for %s RAS poison consumption is issued!\n",
-                               block_obj->ras_comm.name);
+               event_id = amdgpu_ras_acquire_event_id(adev, type);
+               RAS_EVENT_LOG(adev, event_id,
+                             "GPU reset for %s RAS poison consumption is issued!\n",
+                             block_obj->ras_comm.name);
                amdgpu_ras_reset_gpu(adev);
        }
 
@@ -2498,7 +2507,7 @@ static enum ras_event_type amdgpu_ras_get_fatal_error_event(struct amdgpu_device
        if (amdgpu_ras_intr_triggered())
                return RAS_EVENT_TYPE_FATAL;
        else
-               return RAS_EVENT_TYPE_INVALID;
+               return RAS_EVENT_TYPE_POISON_CONSUMPTION;
 }
 
 static void amdgpu_ras_do_recovery(struct work_struct *work) @@ -3985,6 +3994,7 @@ u64 amdgpu_ras_acquire_event_id(struct amdgpu_device *adev, enum ras_event_type
        switch (type) {
        case RAS_EVENT_TYPE_FATAL:
        case RAS_EVENT_TYPE_POISON_CREATION:
+       case RAS_EVENT_TYPE_POISON_CONSUMPTION:
                event_mgr = __get_ras_event_mgr(adev);
                if (!event_mgr)
                        return RAS_EVENT_INVALID_ID;
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h +1 -0
index 69eb5fd4640f..49ec8edcbe39 100644
@@ -436,6 +436,7 @@ enum ras_event_type {
        RAS_EVENT_TYPE_INVALID = 0,
        RAS_EVENT_TYPE_FATAL,
        RAS_EVENT_TYPE_POISON_CREATION,
+       RAS_EVENT_TYPE_POISON_CONSUMPTION,
        RAS_EVENT_TYPE_COUNT,
 };
 
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +13 -3
index 816800555f7f..8a10a0e42846 100644
@@ -27,6 +27,7 @@
 #include "soc15_int.h"
 #include "kfd_device_queue_manager.h"
 #include "kfd_smi_events.h"
+#include "amdgpu_ras.h"
 
 /*
  * GFX9 SQ Interrupts
@@ -144,9 +145,11 @@ static void event_interrupt_poison_consumption_v9(struct kfd_node *dev,
                                uint16_t pasid, uint16_t client_id)  {
        enum amdgpu_ras_block block = 0;
-       int old_poison;
        uint32_t reset = 0;
        struct kfd_process *p = kfd_lookup_process_by_pasid(pasid);
+       enum ras_event_type type = RAS_EVENT_TYPE_POISON_CONSUMPTION;
+       u64 event_id;
+       int old_poison, ret;
 
        if (!p)
                return;
@@ -191,10 +194,16 @@ static void event_interrupt_poison_consumption_v9(struct kfd_node *dev,
                return;
        }
 
+       ret = amdgpu_ras_mark_ras_event(dev->adev, type);
+       if (ret)
+               return;
+
        kfd_signal_poison_consumed_event(dev, pasid);
 
-       dev_warn(dev->adev->dev,
-                "poison is consumed by client %d, kick off gpu reset flow\n", client_id);
+       event_id = amdgpu_ras_acquire_event_id(dev->adev, type);
+
+       RAS_EVENT_LOG(dev->adev, event_id,
+                     "poison is consumed by client %d, kick off gpu reset flow\n",
+client_id);
 
        amdgpu_amdkfd_ras_pasid_poison_consumption_handler(dev->adev,
                block, pasid, NULL, NULL, reset);

--
2.34.1

author Reviewed-by Hawking Zhang Reviewed-by Tao Zhou
#4 lore raw

RE: [PATCH v4 3/4] drm/amdgpu: add ras POSION_CONSUMPTION event id support

[AMD Official Use Only - AMD Internal Distribution Only]

-----Original Message-----
From: Zhang, Hawking <[email protected]>
Sent: Monday, July 8, 2024 1:06 PM
To: Wang, Yang(Kevin) <[email protected]>; [email protected]
Cc: Zhou1, Tao <[email protected]>
Subject: RE: [PATCH v4 3/4] drm/amdgpu: add ras POSION_CONSUMPTION event id support

[AMD Official Use Only - AMD Internal Distribution Only]

amdgpu_ras_get_fatal_error_event(struct amdgpu_device

        if (amdgpu_ras_intr_triggered())
                return RAS_EVENT_TYPE_FATAL;
        else

- return RAS_EVENT_TYPE_INVALID;
+ return RAS_EVENT_TYPE_POISON_CONSUMPTION;
}

Keep in mind that this is temp solution to treat poison as fatal. Moving forward, we will need to check poison handling option to determine return poison consumption or invalid event here. [Kevin]:
Yes, agree, this is a temp solution and will be refine later.

Best Regards,
Kevin

The series is

Regards,
Hawking
-----Original Message-----
From: Wang, Yang(Kevin) <[email protected]>
Sent: Monday, July 8, 2024 11:25
To: [email protected]
Cc: Zhang, Hawking <[email protected]>; Zhou1, Tao <[email protected]>
Subject: [PATCH v4 3/4] drm/amdgpu: add ras POSION_CONSUMPTION event id support

add amdgpu ras POSION_CONSUMPTION event id support.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c         | 16 +++++++++++++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h         |  1 +
 drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c | 15 ++++++++++++---
 3 files changed, 26 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +12 -3
index c7e68c5e90cd..ca09316fbb6a 100644
@@ -2076,10 +2076,17 @@ static void amdgpu_ras_interrupt_poison_consumption_handler(struct ras_manager *
        struct amdgpu_ras_block_object *block_obj =
                amdgpu_ras_get_ras_block(adev, obj->head.block, 0);
        struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
+       enum ras_event_type type = RAS_EVENT_TYPE_POISON_CONSUMPTION;
+       u64 event_id;
+       int ret;
 
        if (!block_obj || !con)
                return;
 
+       ret = amdgpu_ras_mark_ras_event(adev, type);
+       if (ret)
+               return;
+
        /* both query_poison_status and handle_poison_consumption are optional,
         * but at least one of them should be implemented if we need poison
         * consumption handler
@@ -2104,8 +2111,10 @@ static void amdgpu_ras_interrupt_poison_consumption_handler(struct ras_manager *
         * For RMA case, amdgpu_umc_poison_handler will handle gpu reset.
         */
        if (poison_stat && !con->is_rma) {
-               dev_info(adev->dev, "GPU reset for %s RAS poison consumption is issued!\n",
-                               block_obj->ras_comm.name);
+               event_id = amdgpu_ras_acquire_event_id(adev, type);
+               RAS_EVENT_LOG(adev, event_id,
+                             "GPU reset for %s RAS poison consumption is issued!\n",
+                             block_obj->ras_comm.name);
                amdgpu_ras_reset_gpu(adev);
        }
 
@@ -2498,7 +2507,7 @@ static enum ras_event_type amdgpu_ras_get_fatal_error_event(struct amdgpu_device
        if (amdgpu_ras_intr_triggered())
                return RAS_EVENT_TYPE_FATAL;
        else
-               return RAS_EVENT_TYPE_INVALID;
+               return RAS_EVENT_TYPE_POISON_CONSUMPTION;
 }
 
 static void amdgpu_ras_do_recovery(struct work_struct *work) @@ -3985,6 +3994,7 @@ u64 amdgpu_ras_acquire_event_id(struct amdgpu_device *adev, enum ras_event_type
        switch (type) {
        case RAS_EVENT_TYPE_FATAL:
        case RAS_EVENT_TYPE_POISON_CREATION:
+       case RAS_EVENT_TYPE_POISON_CONSUMPTION:
                event_mgr = __get_ras_event_mgr(adev);
                if (!event_mgr)
                        return RAS_EVENT_INVALID_ID; diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h

index 69eb5fd4640f..49ec8edcbe39 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h +1 -0
@@ -436,6 +436,7 @@ enum ras_event_type {
        RAS_EVENT_TYPE_INVALID = 0,
        RAS_EVENT_TYPE_FATAL,
        RAS_EVENT_TYPE_POISON_CREATION,
+       RAS_EVENT_TYPE_POISON_CONSUMPTION,
        RAS_EVENT_TYPE_COUNT,
 };
 
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +13 -3
index 816800555f7f..8a10a0e42846 100644
@@ -27,6 +27,7 @@
 #include "soc15_int.h"
 #include "kfd_device_queue_manager.h"
 #include "kfd_smi_events.h"
+#include "amdgpu_ras.h"
 
 /*
  * GFX9 SQ Interrupts
@@ -144,9 +145,11 @@ static void event_interrupt_poison_consumption_v9(struct kfd_node *dev,
                                uint16_t pasid, uint16_t client_id)  {
        enum amdgpu_ras_block block = 0;
-       int old_poison;
        uint32_t reset = 0;
        struct kfd_process *p = kfd_lookup_process_by_pasid(pasid);
+       enum ras_event_type type = RAS_EVENT_TYPE_POISON_CONSUMPTION;
+       u64 event_id;
+       int old_poison, ret;
 
        if (!p)
                return;
@@ -191,10 +194,16 @@ static void event_interrupt_poison_consumption_v9(struct kfd_node *dev,
                return;
        }
 
+       ret = amdgpu_ras_mark_ras_event(dev->adev, type);
+       if (ret)
+               return;
+
        kfd_signal_poison_consumed_event(dev, pasid);
 
-       dev_warn(dev->adev->dev,
-                "poison is consumed by client %d, kick off gpu reset flow\n", client_id);
+       event_id = amdgpu_ras_acquire_event_id(dev->adev, type);
+
+       RAS_EVENT_LOG(dev->adev, event_id,
+                     "poison is consumed by client %d, kick off gpu
+reset flow\n", client_id);
 
        amdgpu_amdkfd_ras_pasid_poison_consumption_handler(dev->adev,
                block, pasid, NULL, NULL, reset);

--
2.34.1

author
#5 lore raw

PATCH v4 4/4 drm/amdgpu: add ras event state device attribute support

In reply to Yang Wang

add amdgpu ras 'event_state' sysfs device attribute support

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 56 +++++++++++++++++++++++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h |  7 +++-
 2 files changed, 58 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +52 -4
index ca09316fbb6a..be053e168b64 100644
@@ -1731,6 +1731,39 @@ static ssize_t amdgpu_ras_sysfs_schema_show(struct device *dev,
 	return sysfs_emit(buf, "schema: 0x%x\n", con->schema);
 }
 
+static struct {
+	enum ras_event_type type;
+	const char *name;
+} dump_event[] = {
+	{RAS_EVENT_TYPE_FATAL, "Fatal Error"},
+	{RAS_EVENT_TYPE_POISON_CREATION, "Poison Creation"},
+	{RAS_EVENT_TYPE_POISON_CONSUMPTION, "Poison Consumption"},
+};
+
+static ssize_t amdgpu_ras_sysfs_event_state_show(struct device *dev,
+						 struct device_attribute *attr, char *buf)
+{
+	struct amdgpu_ras *con =
+		container_of(attr, struct amdgpu_ras, event_state_attr);
+	struct ras_event_manager *event_mgr = con->event_mgr;
+	struct ras_event_state *event_state;
+	int i, size = 0;
+
+	if (!event_mgr)
+		return -EINVAL;
+
+	size += sysfs_emit_at(buf, size, "current seqno: %llu\n", atomic64_read(&event_mgr->seqno));
+	for (i = 0; i < ARRAY_SIZE(dump_event); i++) {
+		event_state = &event_mgr->event_state[dump_event[i].type];
+		size += sysfs_emit_at(buf, size, "%s: count:%llu, last_seqno:%llu\n",
+				      dump_event[i].name,
+				      atomic64_read(&event_state->count),
+				      event_state->last_seqno);
+	}
+
+	return (ssize_t)size;
+}
+
 static void amdgpu_ras_sysfs_remove_bad_page_node(struct amdgpu_device *adev)
 {
 	struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
@@ -1748,6 +1781,7 @@ static int amdgpu_ras_sysfs_remove_dev_attr_node(struct amdgpu_device *adev)
 		&con->features_attr.attr,
 		&con->version_attr.attr,
 		&con->schema_attr.attr,
+		&con->event_state_attr.attr,
 		NULL
 	};
 	struct attribute_group group = {
@@ -1980,6 +2014,8 @@ static DEVICE_ATTR(version, 0444,
 		amdgpu_ras_sysfs_version_show, NULL);
 static DEVICE_ATTR(schema, 0444,
 		amdgpu_ras_sysfs_schema_show, NULL);
+static DEVICE_ATTR(event_state, 0444,
+		   amdgpu_ras_sysfs_event_state_show, NULL);
 static int amdgpu_ras_fs_init(struct amdgpu_device *adev)
 {
 	struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
@@ -1990,6 +2026,7 @@ static int amdgpu_ras_fs_init(struct amdgpu_device *adev)
 		&con->features_attr.attr,
 		&con->version_attr.attr,
 		&con->schema_attr.attr,
+		&con->event_state_attr.attr,
 		NULL
 	};
 	struct bin_attribute *bin_attrs[] = {
@@ -2012,6 +2049,10 @@ static int amdgpu_ras_fs_init(struct amdgpu_device *adev)
 	con->schema_attr = dev_attr_schema;
 	sysfs_attr_init(attrs[2]);
 
+	/* add event_state entry */
+	con->event_state_attr = dev_attr_event_state;
+	sysfs_attr_init(attrs[3]);
+
 	if (amdgpu_bad_page_threshold != 0) {
 		/* add bad_page_features entry */
 		bin_attr_gpu_vram_bad_pages.private = NULL;
@@ -3440,13 +3481,17 @@ static int amdgpu_get_ras_schema(struct amdgpu_device *adev)
 
 static void ras_event_mgr_init(struct ras_event_manager *mgr)
 {
+	struct ras_event_state *event_state;
 	int i;
 
 	memset(mgr, 0, sizeof(*mgr));
 	atomic64_set(&mgr->seqno, 0);
 
-	for (i = 0; i < ARRAY_SIZE(mgr->last_seqno); i++)
-		mgr->last_seqno[i] = RAS_EVENT_INVALID_ID;
+	for (i = 0; i < ARRAY_SIZE(mgr->event_state); i++) {
+		event_state = &mgr->event_state[i];
+		event_state->last_seqno = RAS_EVENT_INVALID_ID;
+		atomic64_set(&event_state->count, 0);
+	}
 }
 
 static void amdgpu_ras_event_mgr_init(struct amdgpu_device *adev)
@@ -3960,6 +4005,7 @@ static struct ras_event_manager* __get_ras_event_mgr(struct amdgpu_device *adev)
 int amdgpu_ras_mark_ras_event_caller(struct amdgpu_device *adev, enum ras_event_type type, const void *caller)
 {
 	struct ras_event_manager *event_mgr;
+	struct ras_event_state *event_state;
 	int ret = 0;
 
 	if (type >= RAS_EVENT_TYPE_COUNT) {
@@ -3973,7 +4019,9 @@ int amdgpu_ras_mark_ras_event_caller(struct amdgpu_device *adev, enum ras_event_
 		goto out;
 	}
 
-	event_mgr->last_seqno[type] = atomic64_inc_return(&event_mgr->seqno);
+	event_state = &event_mgr->event_state[type];
+	event_state->last_seqno = atomic64_inc_return(&event_mgr->seqno);
+	atomic64_inc(&event_state->count);
 
 out:
 	if (ret && caller)
@@ -3999,7 +4047,7 @@ u64 amdgpu_ras_acquire_event_id(struct amdgpu_device *adev, enum ras_event_type
 		if (!event_mgr)
 			return RAS_EVENT_INVALID_ID;
 
-		id = event_mgr->last_seqno[type];
+		id = event_mgr->event_state[type].last_seqno;
 		break;
 	case RAS_EVENT_TYPE_INVALID:
 	default:
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h +6 -1
index 49ec8edcbe39..88a427a1c8cb 100644
@@ -439,10 +439,14 @@ enum ras_event_type {
 	RAS_EVENT_TYPE_POISON_CONSUMPTION,
 	RAS_EVENT_TYPE_COUNT,
 };
+struct ras_event_state {
+	u64 last_seqno;
+	atomic64_t count;
+};
 
 struct ras_event_manager {
 	atomic64_t seqno;
-	u64 last_seqno[RAS_EVENT_TYPE_COUNT];
+	struct ras_event_state event_state[RAS_EVENT_TYPE_COUNT];
 };
 
 struct ras_event_id {
@@ -496,6 +500,7 @@ struct amdgpu_ras {
 	struct device_attribute features_attr;
 	struct device_attribute version_attr;
 	struct device_attribute schema_attr;
+	struct device_attribute event_state_attr;
 	struct bin_attribute badpages_attr;
 	struct dentry *de_ras_eeprom_table;
 	/* block array */
Signature · 1 line
2.34.1