Skip to contentSkip to conversation

drm/amdgpu: refine amdgpu ras event id core code

PATCH Superseded Yang Wang 3 participants 8 messages Jul 3, 2024 – Jul 8, 2024

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Yang Wang

author
#0 lore raw

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

- 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.

---
 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 | 89 ++++++++++++++++++++-----
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h | 18 +++--
 drivers/gpu/drm/amd/amdgpu_ras.c        |  0
 5 files changed, 88 insertions(+), 25 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 +72 -17

188 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h +13 -5
index 0fa1148e6642..88df4be5d122 100644
@@ -68,6 +68,9 @@ 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__);
 
@@ -427,20 +430,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_ISR,
 	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 +955,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(struct amdgpu_device *adev, enum ras_event_type type);
 
 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 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 45ac82a34d49..8a98611d2353 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;
 
@@ -3964,6 +3974,7 @@ u64 amdgpu_ras_acquire_event_id(struct amdgpu_device *adev, enum ras_event_type
 
 	switch (type) {
 	case RAS_EVENT_TYPE_ISR:
+	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 88df4be5d122..1343cfbc913b 100644
@@ -432,6 +432,7 @@ struct umc_ecc_info {
 enum ras_event_type {
 	RAS_EVENT_TYPE_INVALID = 0,
 	RAS_EVENT_TYPE_ISR,
+	RAS_EVENT_TYPE_POISON_CREATION,
 	RAS_EVENT_TYPE_COUNT,
 };
 
Signature · 1 line
2.34.1
#2 lore raw

RE: [PATCH 2/4] drm/amdgpu: add ras POSION_CREATION event id support

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 27 lines

-----Original Message-----
From: Wang, Yang(Kevin) <[email protected]>
Sent: Wednesday, July 3, 2024 1:52 PM
To: [email protected]
Cc: Zhang, Hawking <[email protected]>; Zhou1, Tao <[email protected]>
Subject: [PATCH 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 +0 -0
index 45ac82a34d49..8a98611d2353 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)
{

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c static void amdgpu_ras_interrupt_poison_consumption_handler(struct ras_manager * · line 2125

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +7 -2
-     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)

[Tao] do we need to add warning message here?

Quoted 51 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +4 -0
+             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);
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +1 -0
@@ -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 {
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +1 -1
-             ret = amdgpu_ras_query_error_status(adev, &info);
+             ret = amdgpu_ras_query_error_status_with_event(adev, &info,
type);
              if (ret)
                      return ret;
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +0 -0
@@ -3964,6 +3974,7 @@ u64 amdgpu_ras_acquire_event_id(struct

amdgpu_device *adev, enum ras_event_type

      switch (type) {
      case RAS_EVENT_TYPE_ISR:
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +1 -0
+     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 -1
index 88df4be5d122..1343cfbc913b 100644
@@ -432,6 +432,7 @@ struct umc_ecc_info {  enum ras_event_type {
      RAS_EVENT_TYPE_INVALID = 0,
      RAS_EVENT_TYPE_ISR,
+     RAS_EVENT_TYPE_POISON_CREATION,
      RAS_EVENT_TYPE_COUNT,
 };
 
--

2.34.1

author
#3 lore raw

PATCH 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 8a98611d2353..11f8c37a97ef 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_recovery_event(struct amdgpu_device *a
 	if (amdgpu_ras_intr_triggered())
 		return RAS_EVENT_TYPE_ISR;
 	else
-		return RAS_EVENT_TYPE_INVALID;
+		return RAS_EVENT_TYPE_POISON_CONSUMPTION;
 }
 
 static void amdgpu_ras_do_recovery(struct work_struct *work)
@@ -3975,6 +3984,7 @@ u64 amdgpu_ras_acquire_event_id(struct amdgpu_device *adev, enum ras_event_type
 	switch (type) {
 	case RAS_EVENT_TYPE_ISR:
 	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 1343cfbc913b..6086da67fa4e 100644
@@ -433,6 +433,7 @@ enum ras_event_type {
 	RAS_EVENT_TYPE_INVALID = 0,
 	RAS_EVENT_TYPE_ISR,
 	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
#4 lore raw

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

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 30 lines

-----Original Message-----
From: Wang, Yang(Kevin) <[email protected]>
Sent: Wednesday, July 3, 2024 1:52 PM
To: [email protected]
Cc: Zhang, Hawking <[email protected]>; Zhou1, Tao <[email protected]>
Subject: [PATCH 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 +0 -0
index 8a98611d2353..11f8c37a97ef 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;

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c static void amdgpu_ras_interrupt_poison_consumption_handler(struct ras_manager * · line 2087

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +4 -0
+     u64 event_id;
+     int ret;
 
      if (!block_obj || !con)
              return;
 
+     ret = amdgpu_ras_mark_ras_event(adev, type);
+     if (ret)

[Tao] add warning? Or you can add it in amdgpu_ras_mark_ras_event.

Quoted 82 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +2 -0
+             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

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +0 -0
@@ -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",

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +3 -1
-                             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",

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +1 -0
+                           block_obj->ras_comm.name);
              amdgpu_ras_reset_gpu(adev);
      }
@@ -2498,7 +2507,7 @@ static enum ras_event_type

amdgpu_ras_get_recovery_event(struct amdgpu_device *a

      if (amdgpu_ras_intr_triggered())
              return RAS_EVENT_TYPE_ISR;
      else
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +2 -1
-             return RAS_EVENT_TYPE_INVALID;
+             return RAS_EVENT_TYPE_POISON_CONSUMPTION;
 }
 
 static void amdgpu_ras_do_recovery(struct work_struct *work) @@ -3975,6
+3984,7 @@ u64 amdgpu_ras_acquire_event_id(struct amdgpu_device *adev,

enum ras_event_type

      switch (type) {
      case RAS_EVENT_TYPE_ISR:
      case RAS_EVENT_TYPE_POISON_CREATION:
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +1 -0
+     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 1343cfbc913b..6086da67fa4e 100644
@@ -433,6 +433,7 @@ enum ras_event_type {
      RAS_EVENT_TYPE_INVALID = 0,
      RAS_EVENT_TYPE_ISR,
      RAS_EVENT_TYPE_POISON_CREATION,
+     RAS_EVENT_TYPE_POISON_CONSUMPTION,
      RAS_EVENT_TYPE_COUNT,
 };
 
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +4 -1
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;

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c static void · line 198

Quoted 5 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +1 -0
@@ -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);

[Tao] I don't think it's necessary to mark it both in amdgpu_ras_interrupt_poison_consumption_handler and here. Another question is, event_interrupt_poison_consumption_v9 is used by several ASICs, are you sure the event id code doesn't affect old ASICs?

Quoted 18 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +8 -3
+     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

#5 lore raw

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

[AMD Official Use Only - AMD Internal Distribution Only]

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

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 30 lines

-----Original Message-----
From: Wang, Yang(Kevin) <[email protected]>
Sent: Wednesday, July 3, 2024 1:52 PM
To: [email protected]
Cc: Zhang, Hawking <[email protected]>; Zhou1, Tao <[email protected]>
Subject: [PATCH 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 +0 -0
index 8a98611d2353..11f8c37a97ef 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;

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c static void amdgpu_ras_interrupt_poison_consumption_handler(struct ras_manager * · line 2087

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +4 -0
+     u64 event_id;
+     int ret;
 
      if (!block_obj || !con)
              return;
 
+     ret = amdgpu_ras_mark_ras_event(adev, type);
+     if (ret)

[Tao] add warning? Or you can add it in amdgpu_ras_mark_ras_event. [Kevin]:

Thanks suggestion, I will update v2 and add a warn log in function internal.

Best Regards,
Kevin

Quoted 84 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +2 -0
+             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

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +0 -0
@@ -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",

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +4 -1
-                             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",

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +1 -0
+                           block_obj->ras_comm.name);
              amdgpu_ras_reset_gpu(adev);
      }
@@ -2498,7 +2507,7 @@ static enum ras_event_type

amdgpu_ras_get_recovery_event(struct amdgpu_device *a

      if (amdgpu_ras_intr_triggered())
              return RAS_EVENT_TYPE_ISR;
      else
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +2 -2
-             return RAS_EVENT_TYPE_INVALID;
+             return RAS_EVENT_TYPE_POISON_CONSUMPTION;
 }
 
 static void amdgpu_ras_do_recovery(struct work_struct *work) @@
-3975,6
+3984,7 @@ u64 amdgpu_ras_acquire_event_id(struct amdgpu_device *adev,

enum ras_event_type

      switch (type) {
      case RAS_EVENT_TYPE_ISR:
      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 1343cfbc913b..6086da67fa4e 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h +1 -0
@@ -433,6 +433,7 @@ enum ras_event_type {
      RAS_EVENT_TYPE_INVALID = 0,
      RAS_EVENT_TYPE_ISR,
      RAS_EVENT_TYPE_POISON_CREATION,
+     RAS_EVENT_TYPE_POISON_CONSUMPTION,
      RAS_EVENT_TYPE_COUNT,
 };
 
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +4 -1
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;

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c static void · line 198

Quoted 5 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +1 -0
@@ -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);

[Tao] I don't think it's necessary to mark it both in amdgpu_ras_interrupt_poison_consumption_handler and here. Another question is, event_interrupt_poison_consumption_v9 is used by several ASICs, are you sure the event id code doesn't affect old ASICs?

[Kevin]:
The event id is only used for format the RAS event log, and it won't affect the code logic for old Asics.

Best Regards,
Kevin

Quoted 18 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +8 -3
+     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
#6 lore raw

PATCH 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 11f8c37a97ef..d84e4f841ecc 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_ISR, "Fault 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(struct amdgpu_device *adev, enum ras_event_type type)
 {
 	struct ras_event_manager *event_mgr;
+	struct ras_event_state *event_state;
 
 	if (type >= RAS_EVENT_TYPE_COUNT)
 		return -EINVAL;
@@ -3968,7 +4014,9 @@ int amdgpu_ras_mark_ras_event(struct amdgpu_device *adev, enum ras_event_type ty
 	if (!event_mgr)
 		return -EINVAL;
 
-	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);
 
 	return 0;
 }
@@ -3989,7 +4037,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 6086da67fa4e..189e2bf53a44 100644
@@ -436,10 +436,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 {
@@ -493,6 +497,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
#7 lore raw
In reply to Yang Wang

[AMD Official Use Only - AMD Internal Distribution Only]

We will need to change RAS_EVENT_TYPE_ISR to RAS_EVENT_TYPE_FATAL to differentiate the upcoming correctable error ISR event.

And please also align the terminology in code to change recovery_event to fatal_error_event, i.e., amdgpu_ras_get_recovery_event -> amdgpu_ras_get_fatal_error_event.

Regards,
Hawking

-----Original Message-----
From: Wang, Yang(Kevin) <[email protected]>
Sent: Wednesday, July 3, 2024 13:52
To: [email protected]
Cc: Zhang, Hawking <[email protected]>; Zhou1, Tao <[email protected]>
Subject: [PATCH 1/4] drm/amdgpu: refine amdgpu ras event id core code

- 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.

---
 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 | 89 ++++++++++++++++++++-----  drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h | 18 +++--
 drivers/gpu/drm/amd/amdgpu_ras.c        |  0
 5 files changed, 88 insertions(+), 25 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"); diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c

index 9d3a3c778504..2542bd7aa7c7 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c +1 -1
@@ -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 +1 -1
index 53b5ac2d7bed..45ac82a34d49 100644
@@ -1055,7 +1055,7 @@ static void amdgpu_ras_error_print_error_data(struct amdgpu_device *adev,
        struct amdgpu_smuio_mcm_config_info *mcm_info;
        struct ras_err_node *err_node;
        struct ras_err_info *err_info;
-       u64 event_id = qctx->event_id;
+       u64 event_id = qctx->evid.event_id;
 
        if (is_ue) {
                for_each_ras_error(err_node, err_data) { @@ -1140,7 +1140,7 @@ static void amdgpu_ras_error_generate_report(struct amdgpu_device *adev,  {
        struct ras_manager *ras_mgr = amdgpu_ras_find_obj(adev, &query_if->head);
        const char *blk_name = get_ras_block_str(&query_if->head);

- u64 event_id = qctx->event_id;
+ u64 event_id = qctx->evid.event_id;

        if (err_data->ce_count) {
                if (err_data_has_source_info(err_data)) { @@ -1366,7 +1366,9 @@ static int amdgpu_ras_query_error_status_helper(struct amdgpu_device *adev,  }

/* query/inject/cure begin */
-int amdgpu_ras_query_error_status(struct amdgpu_device *adev, struct ras_query_if *info) +static int amdgpu_ras_query_error_status_with_event(struct amdgpu_device *adev,
+ struct ras_query_if *info,
+ enum ras_event_type type)

 {
        struct ras_manager *obj = amdgpu_ras_find_obj(adev, &info->head);
        struct ras_err_data err_data;
@@ -1385,8 +1387,8 @@ int amdgpu_ras_query_error_status(struct amdgpu_device *adev, struct ras_query_i
                return -EINVAL;

        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);
+ qctx.evid.type = type;
+ qctx.evid.event_id = amdgpu_ras_acquire_event_id(adev, type);

        if (!down_read_trylock(&adev->reset_domain->sem)) {
                ret = -EIO;
@@ -1415,6 +1417,11 @@ int amdgpu_ras_query_error_status(struct amdgpu_device *adev, struct ras_query_i
        return ret;

}

+int amdgpu_ras_query_error_status(struct amdgpu_device *adev, struct +ras_query_if *info) {
+ return amdgpu_ras_query_error_status_with_event(adev, info,
+RAS_EVENT_TYPE_INVALID); }
+
int amdgpu_ras_reset_error_count(struct amdgpu_device *adev,
enum amdgpu_ras_block block)
{
@@ -2305,7 +2312,7 @@ static int amdgpu_ras_interrupt_remove_all(struct amdgpu_device *adev)
/* ih end */

/* traversal all IPs except NBIO to query error counter */ -static void amdgpu_ras_log_on_err_counter(struct amdgpu_device *adev)
+static void amdgpu_ras_log_on_err_counter(struct amdgpu_device *adev,
+enum ras_event_type type)

 {
        struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
        struct ras_manager *obj;
@@ -2338,7 +2345,7 @@ static void amdgpu_ras_log_on_err_counter(struct amdgpu_device *adev)
                     IP_VERSION(13, 0, 2)))
                        continue;

- amdgpu_ras_query_error_status(adev, &info);
+ amdgpu_ras_query_error_status_with_event(adev, &info, type);

                if (amdgpu_ip_version(adev, MP0_HWIP, 0) !=
                            IP_VERSION(11, 0, 2) &&
@@ -2477,6 +2484,14 @@ bool amdgpu_ras_in_recovery(struct amdgpu_device *adev)
        return false;

}

+static enum ras_event_type amdgpu_ras_get_recovery_event(struct +amdgpu_device *adev) {
+ if (amdgpu_ras_intr_triggered())
+ return RAS_EVENT_TYPE_ISR;
+ else
+ return RAS_EVENT_TYPE_INVALID;
+}
+
static void amdgpu_ras_do_recovery(struct work_struct *work) {
struct amdgpu_ras *ras =
@@ -2485,6 +2500,7 @@ static void amdgpu_ras_do_recovery(struct work_struct *work)

        struct amdgpu_device *adev = ras->adev;
        struct list_head device_list, *device_list_handle =  NULL;
        struct amdgpu_hive_info *hive = amdgpu_get_xgmi_hive(adev);

+ enum ras_event_type type;

        if (hive) {
                atomic_set(&hive->ras_recovery, 1);
@@ -2512,10 +2528,11 @@ static void amdgpu_ras_do_recovery(struct work_struct *work)
                        device_list_handle = &device_list;
                }
+               type = amdgpu_ras_get_recovery_event(adev);
                list_for_each_entry(remote_adev,
                                device_list_handle, gmc.xgmi.head) {
                        amdgpu_ras_query_err_status(remote_adev);
-                       amdgpu_ras_log_on_err_counter(remote_adev);
+                       amdgpu_ras_log_on_err_counter(remote_adev, type);
                }

        }
@@ -3406,8 +3423,11 @@ static void ras_event_mgr_init(struct ras_event_manager *mgr)  {
        int i;

- for (i = 0; i < ARRAY_SIZE(mgr->seqnos); i++)
- atomic64_set(&mgr->seqnos[i], 0);
+ 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;
}

static void amdgpu_ras_event_mgr_init(struct amdgpu_device *adev) @@ -3907,23 +3927,52 @@ void amdgpu_ras_set_fed(struct amdgpu_device *adev, bool status)

                atomic_set(&ras->fed, !!status);

}

-bool amdgpu_ras_event_id_is_valid(struct amdgpu_device *adev, u64 id) +static struct ras_event_manager* __get_ras_event_mgr(struct +amdgpu_device *adev) {
+ struct amdgpu_ras *ras;
+
+ ras = amdgpu_ras_get_context(adev);
+ if (!ras)
+ return NULL;
+
+ return ras->event_mgr;
+}
+
+int amdgpu_ras_mark_ras_event(struct amdgpu_device *adev, enum +ras_event_type type)
{
- return !(id & BIT_ULL(63));
+ struct ras_event_manager *event_mgr;
+
+ if (type >= RAS_EVENT_TYPE_COUNT)
+ return -EINVAL;
+
+ event_mgr = __get_ras_event_mgr(adev);
+ if (!event_mgr)
+ return -EINVAL;
+
+ event_mgr->last_seqno[type] = atomic64_inc_return(&event_mgr->seqno);
+
+ return 0;
}

u64 amdgpu_ras_acquire_event_id(struct amdgpu_device *adev, enum ras_event_type type) {
- struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);

+       struct ras_event_manager *event_mgr;
        u64 id;

+ if (type >= RAS_EVENT_TYPE_COUNT)
+ return RAS_EVENT_INVALID_ID;
+

        switch (type) {
        case RAS_EVENT_TYPE_ISR:
-               id = (u64)atomic64_read(&ras->event_mgr->seqnos[type]);
+               event_mgr = __get_ras_event_mgr(adev);
+               if (!event_mgr)
+                       return RAS_EVENT_INVALID_ID;
+
+               id = event_mgr->last_seqno[type];
                break;
        case RAS_EVENT_TYPE_INVALID:
        default:
-               id = BIT_ULL(63) | 0ULL;
+               id = RAS_EVENT_INVALID_ID;
                break;
        }
@@ -3934,7 +3983,13 @@ void amdgpu_ras_global_ras_isr(struct amdgpu_device *adev)  {
        if (atomic_cmpxchg(&amdgpu_ras_in_intr, 0, 1) == 0) {
                struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
-               u64 event_id = (u64)atomic64_inc_return(&ras->event_mgr->seqnos[RAS_EVENT_TYPE_ISR]);
+               enum ras_event_type type = RAS_EVENT_TYPE_ISR;
+               u64 event_id;

+
+ if (amdgpu_ras_mark_ras_event(adev, type))
+ return;
+
+ event_id = amdgpu_ras_acquire_event_id(adev, type);

                RAS_EVENT_LOG(adev, event_id, "uncorrectable hardware error"
                              "(ERREVENT_ATHUB_INTERRUPT) detected!\n"); @@ -4668,7 +4723,7 @@ void amdgpu_ras_event_log_print(struct amdgpu_device *adev, u64 event_id,
        vaf.fmt = fmt;
        vaf.va = &args;

- if (amdgpu_ras_event_id_is_valid(adev, event_id))
+ if (RAS_EVENT_ID_IS_VALID(event_id))

                dev_printk(KERN_INFO, adev->dev, "{%llu}%pV", event_id, &vaf);
        else
                dev_printk(KERN_INFO, adev->dev, "%pV", &vaf); diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h

index 0fa1148e6642..88df4be5d122 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h +14 -5
@@ -68,6 +68,9 @@ 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__);
 
@@ -427,20 +430,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_ISR,
        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 +955,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(struct amdgpu_device *adev, enum
+ras_event_type type);
 
 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

--
2.34.1