Skip to contentSkip to conversation

drm/amdkfd: update parameter for event_interrupt_poison_consumption

PATCH In review Tao Zhou 4 participants 16 messages Mar 14, 2022 – Mar 15, 2022

Subsystems (3)
lore
Share & tools
lore

Tao Zhou

author
#0 lore raw

PATCH 1/3 drm/amdkfd: update parameter for event_interrupt_poison_consumption

Other parameters can be gotten from ih_ring_entry, so only inputting ih_ring_entry is enough.

---
 drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +9 -4
index 7eedbcd14828..f7def0bf0730 100644
@@ -91,11 +91,16 @@ enum SQ_INTERRUPT_ERROR_TYPE {
 #define KFD_SQ_INT_DATA__ERR_TYPE__SHIFT 20
 
 static void event_interrupt_poison_consumption(struct kfd_dev *dev,
-				uint16_t pasid, uint16_t source_id)
+				const uint32_t *ih_ring_entry)
 {
+	uint16_t source_id, pasid;
 	int ret = -EINVAL;
-	struct kfd_process *p = kfd_lookup_process_by_pasid(pasid);
+	struct kfd_process *p;
 
+	source_id = SOC15_SOURCE_ID_FROM_IH_ENTRY(ih_ring_entry);
+	pasid = SOC15_PASID_FROM_IH_ENTRY(ih_ring_entry);
+
+	p = kfd_lookup_process_by_pasid(pasid);
 	if (!p)
 		return;
 
@@ -270,7 +275,7 @@ static void event_interrupt_wq_v9(struct kfd_dev *dev,
 					sq_intr_err);
 				if (sq_intr_err != SQ_INTERRUPT_ERROR_TYPE_ILLEGAL_INST &&
 					sq_intr_err != SQ_INTERRUPT_ERROR_TYPE_MEMVIOL) {
-					event_interrupt_poison_consumption(dev, pasid, source_id);
+					event_interrupt_poison_consumption(dev, ih_ring_entry);
 					return;
 				}
 				break;
@@ -291,7 +296,7 @@ static void event_interrupt_wq_v9(struct kfd_dev *dev,
 		if (source_id == SOC15_INTSRC_SDMA_TRAP) {
 			kfd_signal_event_interrupt(pasid, context_id0 & 0xfffffff, 28);
 		} else if (source_id == SOC15_INTSRC_SDMA_ECC) {
-			event_interrupt_poison_consumption(dev, pasid, source_id);
+			event_interrupt_poison_consumption(dev, ih_ring_entry);
 			return;
 		}
 	} else if (client_id == SOC15_IH_CLIENTID_VMC ||
Signature · 1 line
2.35.1
author
#1 lore raw

PATCH 2/3 drm/amdgpu: add utcl2 RAS poison functions for Aldebaran

Add help functions to check and clear RAS utcl2 poison status.

---
 .../drm/amd/amdgpu/amdgpu_amdkfd_aldebaran.c  | 28 ++++++++++++++++++-
 .../gpu/drm/amd/include/kgd_kfd_interface.h   |  3 ++
 2 files changed, 30 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_aldebaran.c +27 -1
index c8935d718207..ebd7d36d099b 100644
@@ -23,6 +23,30 @@
 #include "amdgpu_amdkfd.h"
 #include "amdgpu_amdkfd_arcturus.h"
 #include "amdgpu_amdkfd_gfx_v9.h"
+#include "soc15.h"
+#include "gc/gc_9_4_2_sh_mask.h"
+
+static bool kgd_aldebaran_is_ras_utcl2_poison(struct amdgpu_device *adev,
+			uint16_t client_id)
+{
+	uint32_t status = 0;
+	struct amdgpu_vmhub *hub;
+
+	if (client_id != SOC15_IH_CLIENTID_UTCL2)
+		return false;
+
+	hub = &adev->vmhub[AMDGPU_GFXHUB_0];
+	status = RREG32(hub->vm_l2_pro_fault_status);
+	return REG_GET_FIELD(status, VM_L2_PROTECTION_FAULT_STATUS, FED);
+}
+
+static void kgd_aldebaran_utcl2_fault_clear(struct amdgpu_device *adev)
+{
+	struct amdgpu_vmhub *hub = &adev->vmhub[AMDGPU_GFXHUB_0];
+
+	hub = &adev->vmhub[AMDGPU_GFXHUB_0];
+	WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);
+}
 
 const struct kfd2kgd_calls aldebaran_kfd2kgd = {
 	.program_sh_mem_settings = kgd_gfx_v9_program_sh_mem_settings,
@@ -41,5 +65,7 @@ const struct kfd2kgd_calls aldebaran_kfd2kgd = {
 	.get_atc_vmid_pasid_mapping_info =
 				kgd_gfx_v9_get_atc_vmid_pasid_mapping_info,
 	.set_vm_context_page_table_base = kgd_gfx_v9_set_vm_context_page_table_base,
-	.program_trap_handler_settings = kgd_gfx_v9_program_trap_handler_settings
+	.program_trap_handler_settings = kgd_gfx_v9_program_trap_handler_settings,
+	.is_ras_utcl2_poison = kgd_aldebaran_is_ras_utcl2_poison,
+	.utcl2_fault_clear = kgd_aldebaran_utcl2_fault_clear
 };
drivers/gpu/drm/amd/include/kgd_kfd_interface.h +3 -0
index 2f60cf35a444..78400479193e 100644
@@ -291,6 +291,9 @@ struct kfd2kgd_calls {
 			int *wave_cnt, int *max_waves_per_cu);
 	void (*program_trap_handler_settings)(struct amdgpu_device *adev,
 			uint32_t vmid, uint64_t tba_addr, uint64_t tma_addr);
+	bool (*is_ras_utcl2_poison)(struct amdgpu_device *adev,
+			uint16_t client_id);
+	void (*utcl2_fault_clear)(struct amdgpu_device *adev);
 };
 
 #endif	/* KGD_KFD_INTERFACE_H_INCLUDED */
Signature · 1 line
2.35.1
#2 lore raw

Re: [PATCH 2/3] drm/amdgpu: add utcl2 RAS poison functions for Aldebaran

Quoted 18 lines · Tao Zhou

Add help functions to check and clear RAS utcl2 poison status.

---
  .../drm/amd/amdgpu/amdgpu_amdkfd_aldebaran.c  | 28 ++++++++++++++++++-
  .../gpu/drm/amd/include/kgd_kfd_interface.h   |  3 ++
  2 files changed, 30 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_aldebaran.c +2 -0
index c8935d718207..ebd7d36d099b 100644
@@ -23,6 +23,30 @@
  #include "amdgpu_amdkfd.h"
  #include "amdgpu_amdkfd_arcturus.h"
  #include "amdgpu_amdkfd_gfx_v9.h"
+#include "soc15.h"
+#include "gc/gc_9_4_2_sh_mask.h"

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_aldebaran.c line 37

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_aldebaran.c +10 -0
+
+static bool kgd_aldebaran_is_ras_utcl2_poison(struct amdgpu_device *adev,
+			uint16_t client_id)
+{
+	uint32_t status = 0;
+	struct amdgpu_vmhub *hub;
+
+	if (client_id != SOC15_IH_CLIENTID_UTCL2)
+		return false;
+

Status check is not related to interrupt. Is IH client id needed here?

Thanks,
Lijo

Quoted 39 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_aldebaran.c +15 -1
+	hub = &adev->vmhub[AMDGPU_GFXHUB_0];
+	status = RREG32(hub->vm_l2_pro_fault_status);
+	return REG_GET_FIELD(status, VM_L2_PROTECTION_FAULT_STATUS, FED);
+}
+
+static void kgd_aldebaran_utcl2_fault_clear(struct amdgpu_device *adev)
+{
+	struct amdgpu_vmhub *hub = &adev->vmhub[AMDGPU_GFXHUB_0];
+
+	hub = &adev->vmhub[AMDGPU_GFXHUB_0];
+	WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);
+}
 
  const struct kfd2kgd_calls aldebaran_kfd2kgd = {
  	.program_sh_mem_settings = kgd_gfx_v9_program_sh_mem_settings,
@@ -41,5 +65,7 @@ const struct kfd2kgd_calls aldebaran_kfd2kgd = {
  	.get_atc_vmid_pasid_mapping_info =
  				kgd_gfx_v9_get_atc_vmid_pasid_mapping_info,
  	.set_vm_context_page_table_base = kgd_gfx_v9_set_vm_context_page_table_base,
-	.program_trap_handler_settings = kgd_gfx_v9_program_trap_handler_settings
+	.program_trap_handler_settings = kgd_gfx_v9_program_trap_handler_settings,
+	.is_ras_utcl2_poison = kgd_aldebaran_is_ras_utcl2_poison,
+	.utcl2_fault_clear = kgd_aldebaran_utcl2_fault_clear
  };
drivers/gpu/drm/amd/include/kgd_kfd_interface.h +3 -0
index 2f60cf35a444..78400479193e 100644
@@ -291,6 +291,9 @@ struct kfd2kgd_calls {
  			int *wave_cnt, int *max_waves_per_cu);
  	void (*program_trap_handler_settings)(struct amdgpu_device *adev,
  			uint32_t vmid, uint64_t tba_addr, uint64_t tma_addr);
+	bool (*is_ras_utcl2_poison)(struct amdgpu_device *adev,
+			uint16_t client_id);
+	void (*utcl2_fault_clear)(struct amdgpu_device *adev);
  };
 
  #endif	/* KGD_KFD_INTERFACE_H_INCLUDED */
author
#3 lore raw

RE: [PATCH 2/3] drm/amdgpu: add utcl2 RAS poison functions for Aldebaran

[AMD Official Use Only]

Quoted 36 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Monday, March 14, 2022 5:44 PM
To: Zhou1, Tao <[email protected]>; [email protected]; Zhang, Hawking <[email protected]>; Yang, Stanley <[email protected]>; Chai, Thomas <[email protected]>
Subject: Re: [PATCH 2/3] drm/amdgpu: add utcl2 RAS poison functions for Aldebaran

Quoted 5 lines · Tao Zhou

Add help functions to check and clear RAS utcl2 poison status.

---
  .../drm/amd/amdgpu/amdgpu_amdkfd_aldebaran.c  | 28

++++++++++++++++++-

Quoted 18 lines
  .../gpu/drm/amd/include/kgd_kfd_interface.h   |  3 ++
  2 files changed, 30 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_aldebaran.c +6 -0
index c8935d718207..ebd7d36d099b 100644
@@ -23,6 +23,30 @@
  #include "amdgpu_amdkfd.h"
  #include "amdgpu_amdkfd_arcturus.h"
  #include "amdgpu_amdkfd_gfx_v9.h"
+#include "soc15.h"
+#include "gc/gc_9_4_2_sh_mask.h"
+
+static bool kgd_aldebaran_is_ras_utcl2_poison(struct amdgpu_device *adev,
+			uint16_t client_id)
+{
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_aldebaran.c line 37

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_aldebaran.c +6 -0
+	uint32_t status = 0;
+	struct amdgpu_vmhub *hub;
+
+	if (client_id != SOC15_IH_CLIENTID_UTCL2)
+		return false;
+

Status check is not related to interrupt. Is IH client id needed here?

[Tao] I'll remove the check for client_id since it has been checked in vm fault handler.

Quoted 47 lines

Thanks,
Lijo

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_aldebaran.c

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_aldebaran.c +3 -0
+	hub = &adev->vmhub[AMDGPU_GFXHUB_0];
+	status = RREG32(hub->vm_l2_pro_fault_status);
+	return REG_GET_FIELD(status, VM_L2_PROTECTION_FAULT_STATUS,

FED); }

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_aldebaran.c const struct kfd2kgd_calls aldebaran_kfd2kgd = { · line 66

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_aldebaran.c +7 -0
+
+static void kgd_aldebaran_utcl2_fault_clear(struct amdgpu_device
+*adev) {
+	struct amdgpu_vmhub *hub = &adev->vmhub[AMDGPU_GFXHUB_0];
+
+	hub = &adev->vmhub[AMDGPU_GFXHUB_0];
+	WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1); }
 
  const struct kfd2kgd_calls aldebaran_kfd2kgd = {
  	.program_sh_mem_settings = kgd_gfx_v9_program_sh_mem_settings,
@@ -41,5 +65,7 @@ const struct kfd2kgd_calls aldebaran_kfd2kgd = {
  	.get_atc_vmid_pasid_mapping_info =
 

kgd_gfx_v9_get_atc_vmid_pasid_mapping_info,

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_aldebaran.c const struct kfd2kgd_calls aldebaran_kfd2kgd = { · line 67

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_aldebaran.c +0 -0
  	.set_vm_context_page_table_base =

kgd_gfx_v9_set_vm_context_page_table_base,

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_aldebaran.c const struct kfd2kgd_calls aldebaran_kfd2kgd = { · line 44

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_aldebaran.c +0 -1
-	.program_trap_handler_settings =

kgd_gfx_v9_program_trap_handler_settings

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_aldebaran.c const struct kfd2kgd_calls aldebaran_kfd2kgd = { · line 68

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_aldebaran.c +1 -0
+	.program_trap_handler_settings =

kgd_gfx_v9_program_trap_handler_settings,

Quoted 19 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_aldebaran.c +2 -0
+	.is_ras_utcl2_poison = kgd_aldebaran_is_ras_utcl2_poison,
+	.utcl2_fault_clear = kgd_aldebaran_utcl2_fault_clear
  };
drivers/gpu/drm/amd/include/kgd_kfd_interface.h +3 -0
index 2f60cf35a444..78400479193e 100644
@@ -291,6 +291,9 @@ struct kfd2kgd_calls {
  			int *wave_cnt, int *max_waves_per_cu);
  	void (*program_trap_handler_settings)(struct amdgpu_device *adev,
  			uint32_t vmid, uint64_t tba_addr, uint64_t tma_addr);
+	bool (*is_ras_utcl2_poison)(struct amdgpu_device *adev,
+			uint16_t client_id);
+	void (*utcl2_fault_clear)(struct amdgpu_device *adev);
  };
 
  #endif	/* KGD_KFD_INTERFACE_H_INCLUDED */
author
#4 lore raw

PATCH 3/3 drm/amdkfd: add RAS poison consumption support for utcl2

In reply to Tao Zhou

Do RAS page retirement and use gpu reset as fallback in utcl2 fault handler.

---
 .../gpu/drm/amd/amdkfd/kfd_int_process_v9.c   | 23 ++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +20 -3
index f7def0bf0730..3991f71d865b 100644
@@ -93,11 +93,12 @@ enum SQ_INTERRUPT_ERROR_TYPE {
 static void event_interrupt_poison_consumption(struct kfd_dev *dev,
 				const uint32_t *ih_ring_entry)
 {
-	uint16_t source_id, pasid;
+	uint16_t source_id, client_id, pasid;
 	int ret = -EINVAL;
 	struct kfd_process *p;
 
 	source_id = SOC15_SOURCE_ID_FROM_IH_ENTRY(ih_ring_entry);
+	client_id = SOC15_CLIENT_ID_FROM_IH_ENTRY(ih_ring_entry);
 	pasid = SOC15_PASID_FROM_IH_ENTRY(ih_ring_entry);
 
 	p = kfd_lookup_process_by_pasid(pasid);
@@ -110,6 +111,7 @@ static void event_interrupt_poison_consumption(struct kfd_dev *dev,
 		return;
 	}
 
+	pr_debug("RAS poison consumption handling\n");
 	atomic_set(&p->poison, 1);
 	kfd_unref_process(p);
 
@@ -119,10 +121,14 @@ static void event_interrupt_poison_consumption(struct kfd_dev *dev,
 		break;
 	case SOC15_INTSRC_SDMA_ECC:
 	default:
+		if (client_id == SOC15_IH_CLIENTID_UTCL2)
+			ret = kfd_dqm_evict_pasid(dev->dqm, pasid);
 		break;
 	}
 
-	kfd_signal_poison_consumed_event(dev, pasid);
+	/* utcl2 page fault has its own vm fault event */
+	if (client_id != SOC15_IH_CLIENTID_UTCL2)
+		kfd_signal_poison_consumed_event(dev, pasid);
 
 	/* resetting queue passes, do page retirement without gpu reset
 	 * resetting queue fails, fallback to gpu reset solution
@@ -314,7 +320,18 @@ static void event_interrupt_wq_v9(struct kfd_dev *dev,
 		info.prot_write = ring_id & 0x20;
 
 		kfd_smi_event_update_vmfault(dev, pasid);
-		kfd_dqm_evict_pasid(dev->dqm, pasid);
+
+		if (client_id == SOC15_IH_CLIENTID_UTCL2 &&
+		    dev->kfd2kgd->is_ras_utcl2_poison &&
+		    dev->kfd2kgd->is_ras_utcl2_poison(dev->adev, client_id)) {
+			event_interrupt_poison_consumption(dev, ih_ring_entry);
+
+			if (dev->kfd2kgd->utcl2_fault_clear)
+				dev->kfd2kgd->utcl2_fault_clear(dev->adev);
+		}
+		else
+			kfd_dqm_evict_pasid(dev->dqm, pasid);
+
 		kfd_signal_vm_fault_event(dev, pasid, &info);
 	}
 }
Signature · 1 line
2.35.1
#5 lore raw

Re: [PATCH 3/3] drm/amdkfd: add RAS poison consumption support for utcl2

Quoted 27 lines · Tao Zhou

Do RAS page retirement and use gpu reset as fallback in utcl2 fault handler.

---
  .../gpu/drm/amd/amdkfd/kfd_int_process_v9.c   | 23 ++++++++++++++++---
  1 file changed, 20 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +2 -1
index f7def0bf0730..3991f71d865b 100644
@@ -93,11 +93,12 @@ enum SQ_INTERRUPT_ERROR_TYPE {
  static void event_interrupt_poison_consumption(struct kfd_dev *dev,
  				const uint32_t *ih_ring_entry)
  {
-	uint16_t source_id, pasid;
+	uint16_t source_id, client_id, pasid;
  	int ret = -EINVAL;
  	struct kfd_process *p;
 
  	source_id = SOC15_SOURCE_ID_FROM_IH_ENTRY(ih_ring_entry);
+	client_id = SOC15_CLIENT_ID_FROM_IH_ENTRY(ih_ring_entry);
  	pasid = SOC15_PASID_FROM_IH_ENTRY(ih_ring_entry);
 
  	p = kfd_lookup_process_by_pasid(pasid);

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c static void event_interrupt_poison_consumption(struct kfd_dev *dev, · line 114

Quoted 4 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +1 -0
@@ -110,6 +111,7 @@ static void event_interrupt_poison_consumption(struct kfd_dev *dev,
  		return;
  	}
 
+	pr_debug("RAS poison consumption handling\n");

dev is available through kfd_dev.

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c static void event_interrupt_poison_consumption(struct kfd_dev *dev, · line 125

Quoted 9 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +2 -0
  	atomic_set(&p->poison, 1);
  	kfd_unref_process(p);
 
@@ -119,10 +121,14 @@ static void event_interrupt_poison_consumption(struct kfd_dev *dev,
  		break;
  	case SOC15_INTSRC_SDMA_ECC:
  	default:
+		if (client_id == SOC15_IH_CLIENTID_UTCL2)
+			ret = kfd_dqm_evict_pasid(dev->dqm, pasid);

Since this doesn't logically belong to the switch condition, better to keep it outside of switch.

Quoted 11 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +3 -1
  		break;
  	}
 
-	kfd_signal_poison_consumed_event(dev, pasid);
+	/* utcl2 page fault has its own vm fault event */
+	if (client_id != SOC15_IH_CLIENTID_UTCL2)
+		kfd_signal_poison_consumed_event(dev, pasid);
 
  	/* resetting queue passes, do page retirement without gpu reset
  	 * resetting queue fails, fallback to gpu reset solution

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c static void event_interrupt_wq_v9(struct kfd_dev *dev, · line 328

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +6 -1
@@ -314,7 +320,18 @@ static void event_interrupt_wq_v9(struct kfd_dev *dev,
  		info.prot_write = ring_id & 0x20;
 
  		kfd_smi_event_update_vmfault(dev, pasid);
-		kfd_dqm_evict_pasid(dev->dqm, pasid);
+
+		if (client_id == SOC15_IH_CLIENTID_UTCL2 &&
+		    dev->kfd2kgd->is_ras_utcl2_poison &&
+		    dev->kfd2kgd->is_ras_utcl2_poison(dev->adev, client_id)) {
+			event_interrupt_poison_consumption(dev, ih_ring_entry);
+

Is it expected that no other interrupt would come until this FED error is cleared? Otherwise subsequent ones could also be treated as poison.

Basically, whether to do this or not?
1) Clear FED
2) Handle poison consumption

Thanks,
Lijo

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +6 -0
+			if (dev->kfd2kgd->utcl2_fault_clear)
+				dev->kfd2kgd->utcl2_fault_clear(dev->adev);
+		}
+		else
+			kfd_dqm_evict_pasid(dev->dqm, pasid);
+
  		kfd_signal_vm_fault_event(dev, pasid, &info);
  	}
  }
author
#6 lore raw

RE: [PATCH 3/3] drm/amdkfd: add RAS poison consumption support for utcl2

[AMD Official Use Only]

Quoted 41 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Monday, March 14, 2022 5:52 PM
To: Zhou1, Tao <[email protected]>; [email protected]; Zhang, Hawking <[email protected]>; Yang, Stanley <[email protected]>; Chai, Thomas <[email protected]>
Subject: Re: [PATCH 3/3] drm/amdkfd: add RAS poison consumption support for utcl2

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c static void

Quoted 28 lines · Tao Zhou

Do RAS page retirement and use gpu reset as fallback in utcl2 fault handler.

---
  .../gpu/drm/amd/amdkfd/kfd_int_process_v9.c   | 23 ++++++++++++++++---
  1 file changed, 20 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +2 -1
index f7def0bf0730..3991f71d865b 100644
@@ -93,11 +93,12 @@ enum SQ_INTERRUPT_ERROR_TYPE {
  static void event_interrupt_poison_consumption(struct kfd_dev *dev,
  				const uint32_t *ih_ring_entry)
  {
-	uint16_t source_id, pasid;
+	uint16_t source_id, client_id, pasid;
  	int ret = -EINVAL;
  	struct kfd_process *p;
 
  	source_id = SOC15_SOURCE_ID_FROM_IH_ENTRY(ih_ring_entry);
+	client_id = SOC15_CLIENT_ID_FROM_IH_ENTRY(ih_ring_entry);
  	pasid = SOC15_PASID_FROM_IH_ENTRY(ih_ring_entry);
 
  	p = kfd_lookup_process_by_pasid(pasid);
@@ -110,6 +111,7 @@ static void

event_interrupt_poison_consumption(struct kfd_dev *dev,

Quoted 6 lines

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c static void event_interrupt_poison_consumption(struct kfd_dev *dev, · line 114

Quoted 4 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +1 -0
  		return;
  	}
 
+	pr_debug("RAS poison consumption handling\n");

dev is available through kfd_dev.

[Tao] not sure of your meaning here.

Quoted 6 lines

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c static void

Quoted 5 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +0 -0
  	atomic_set(&p->poison, 1);
  	kfd_unref_process(p);
 
@@ -119,10 +121,14 @@ static void

event_interrupt_poison_consumption(struct kfd_dev *dev,

Quoted 8 lines

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c static void event_interrupt_poison_consumption(struct kfd_dev *dev, · line 125

Quoted 5 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +2 -0
  		break;
  	case SOC15_INTSRC_SDMA_ECC:
  	default:
+		if (client_id == SOC15_IH_CLIENTID_UTCL2)
+			ret = kfd_dqm_evict_pasid(dev->dqm, pasid);

Since this doesn't logically belong to the switch condition, better to keep it outside of switch.

[Tao] will add source id definition for it.

Quoted 22 lines
Quoted 11 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +3 -1
  		break;
  	}
 
-	kfd_signal_poison_consumed_event(dev, pasid);
+	/* utcl2 page fault has its own vm fault event */
+	if (client_id != SOC15_IH_CLIENTID_UTCL2)
+		kfd_signal_poison_consumed_event(dev, pasid);
 
  	/* resetting queue passes, do page retirement without gpu reset
  	 * resetting queue fails, fallback to gpu reset solution @@ -314,7

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c static void

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +6 -1
+320,18 @@ static void event_interrupt_wq_v9(struct kfd_dev *dev,
  		info.prot_write = ring_id & 0x20;
 
  		kfd_smi_event_update_vmfault(dev, pasid);
-		kfd_dqm_evict_pasid(dev->dqm, pasid);
+
+		if (client_id == SOC15_IH_CLIENTID_UTCL2 &&
+		    dev->kfd2kgd->is_ras_utcl2_poison &&
+		    dev->kfd2kgd->is_ras_utcl2_poison(dev->adev, client_id)) {
+			event_interrupt_poison_consumption(dev,

ih_ring_entry);

Quoted 3 lines
Quoted 1 line

+

Is it expected that no other interrupt would come until this FED error is cleared? Otherwise subsequent ones could also be treated as poison.

[Tao] OK, I'll clear it after checking FED status.

Quoted 4 lines

Basically, whether to do this or not?
1) Clear FED
2) Handle poison consumption

[Tao] I think we need to clear status register, otherwise the error status is always there.

Quoted 15 lines

Thanks,
Lijo

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +6 -0
+			if (dev->kfd2kgd->utcl2_fault_clear)
+				dev->kfd2kgd->utcl2_fault_clear(dev->adev);
+		}
+		else
+			kfd_dqm_evict_pasid(dev->dqm, pasid);
+
  		kfd_signal_vm_fault_event(dev, pasid, &info);
  	}
  }
#7 lore raw

Re: [PATCH 3/3] drm/amdkfd: add RAS poison consumption support for utcl2

Quoted 45 lines · Tao

[AMD Official Use Only]

Quoted 41 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Monday, March 14, 2022 5:52 PM
To: Zhou1, Tao <[email protected]>; [email protected]; Zhang, Hawking <[email protected]>; Yang, Stanley <[email protected]>; Chai, Thomas <[email protected]>
Subject: Re: [PATCH 3/3] drm/amdkfd: add RAS poison consumption support for utcl2

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c static void

Quoted 28 lines · Tao Zhou

Do RAS page retirement and use gpu reset as fallback in utcl2 fault handler.

---
   .../gpu/drm/amd/amdkfd/kfd_int_process_v9.c   | 23 ++++++++++++++++---
   1 file changed, 20 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +2 -1
index f7def0bf0730..3991f71d865b 100644
@@ -93,11 +93,12 @@ enum SQ_INTERRUPT_ERROR_TYPE {
   static void event_interrupt_poison_consumption(struct kfd_dev *dev,
   				const uint32_t *ih_ring_entry)
   {
-	uint16_t source_id, pasid;
+	uint16_t source_id, client_id, pasid;
   	int ret = -EINVAL;
   	struct kfd_process *p;
 
   	source_id = SOC15_SOURCE_ID_FROM_IH_ENTRY(ih_ring_entry);
+	client_id = SOC15_CLIENT_ID_FROM_IH_ENTRY(ih_ring_entry);
   	pasid = SOC15_PASID_FROM_IH_ENTRY(ih_ring_entry);
 
   	p = kfd_lookup_process_by_pasid(pasid);
@@ -110,6 +111,7 @@ static void

event_interrupt_poison_consumption(struct kfd_dev *dev,

Quoted 8 lines
Quoted 6 lines

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c static void event_interrupt_poison_consumption(struct kfd_dev *dev, · line 114

Quoted 4 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +1 -0
   		return;
   	}
 
+	pr_debug("RAS poison consumption handling\n");

dev is available through kfd_dev.

[Tao] not sure of your meaning here.

I meant use dev_dbg here after fetching dev pointer through kfd_dev.

Quoted 44 lines
Quoted 7 lines

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c static void

Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +0 -0
   	atomic_set(&p->poison, 1);
   	kfd_unref_process(p);
 
@@ -119,10 +121,14 @@ static void

event_interrupt_poison_consumption(struct kfd_dev *dev,

Quoted 8 lines

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c static void event_interrupt_poison_consumption(struct kfd_dev *dev, · line 125

Quoted 5 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +2 -0
   		break;
   	case SOC15_INTSRC_SDMA_ECC:
   	default:
+		if (client_id == SOC15_IH_CLIENTID_UTCL2)
+			ret = kfd_dqm_evict_pasid(dev->dqm, pasid);

Since this doesn't logically belong to the switch condition, better to keep it outside of switch.

[Tao] will add source id definition for it.

Quoted 22 lines
Quoted 11 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +3 -1
   		break;
   	}
 
-	kfd_signal_poison_consumed_event(dev, pasid);
+	/* utcl2 page fault has its own vm fault event */
+	if (client_id != SOC15_IH_CLIENTID_UTCL2)
+		kfd_signal_poison_consumed_event(dev, pasid);
 
   	/* resetting queue passes, do page retirement without gpu reset
   	 * resetting queue fails, fallback to gpu reset solution @@ -314,7

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c static void

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +6 -1
+320,18 @@ static void event_interrupt_wq_v9(struct kfd_dev *dev,
   		info.prot_write = ring_id & 0x20;
 
   		kfd_smi_event_update_vmfault(dev, pasid);
-		kfd_dqm_evict_pasid(dev->dqm, pasid);
+
+		if (client_id == SOC15_IH_CLIENTID_UTCL2 &&
+		    dev->kfd2kgd->is_ras_utcl2_poison &&
+		    dev->kfd2kgd->is_ras_utcl2_poison(dev->adev, client_id)) {
+			event_interrupt_poison_consumption(dev,

ih_ring_entry);

Quoted 3 lines
Quoted 1 line

+

Is it expected that no other interrupt would come until this FED error is cleared? Otherwise subsequent ones could also be treated as poison.

Quoted 9 lines

[Tao] OK, I'll clear it after checking FED status.

Quoted 4 lines

Basically, whether to do this or not?
1) Clear FED
2) Handle poison consumption

[Tao] I think we need to clear status register, otherwise the error status is always there.

Patch sequence is
1) Handle poison consumption
2) Clear FED.

I was asking whether to reverse it. You already clarified it above.

Thanks,
Lijo

Quoted 15 lines
Quoted 15 lines

Thanks,
Lijo

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +6 -0
+			if (dev->kfd2kgd->utcl2_fault_clear)
+				dev->kfd2kgd->utcl2_fault_clear(dev->adev);
+		}
+		else
+			kfd_dqm_evict_pasid(dev->dqm, pasid);
+
   		kfd_signal_vm_fault_event(dev, pasid, &info);
   	}
   }
author
#8 lore raw

RE: [PATCH 3/3] drm/amdkfd: add RAS poison consumption support for utcl2

[AMD Official Use Only]

Quoted 62 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Tuesday, March 15, 2022 4:43 PM
To: Zhou1, Tao <[email protected]>; [email protected]; Zhang, Hawking <[email protected]>; Yang, Stanley <[email protected]>; Chai, Thomas <[email protected]>
Subject: Re: [PATCH 3/3] drm/amdkfd: add RAS poison consumption support for utcl2

Quoted 23 lines · Tao

[AMD Official Use Only]

Quoted 19 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Monday, March 14, 2022 5:52 PM
To: Zhou1, Tao <[email protected]>; [email protected]; Zhang, Hawking <[email protected]>; Yang, Stanley <[email protected]>; Chai, Thomas <[email protected]>
Subject: Re: [PATCH 3/3] drm/amdkfd: add RAS poison consumption support for
utcl2

Quoted 6 lines · Tao Zhou

Do RAS page retirement and use gpu reset as fallback in utcl2 fault handler.

---
   .../gpu/drm/amd/amdkfd/kfd_int_process_v9.c   | 23 ++++++++++++++++-

--

Quoted 26 lines
Quoted 26 lines

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c static void

Quoted 22 lines
   1 file changed, 20 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +2 -1
index f7def0bf0730..3991f71d865b 100644
@@ -93,11 +93,12 @@ enum SQ_INTERRUPT_ERROR_TYPE {
   static void event_interrupt_poison_consumption(struct kfd_dev *dev,
   				const uint32_t *ih_ring_entry)
   {
-	uint16_t source_id, pasid;
+	uint16_t source_id, client_id, pasid;
   	int ret = -EINVAL;
   	struct kfd_process *p;
 
   	source_id = SOC15_SOURCE_ID_FROM_IH_ENTRY(ih_ring_entry);
+	client_id = SOC15_CLIENT_ID_FROM_IH_ENTRY(ih_ring_entry);
   	pasid = SOC15_PASID_FROM_IH_ENTRY(ih_ring_entry);
 
   	p = kfd_lookup_process_by_pasid(pasid);
@@ -110,6 +111,7 @@ static void

event_interrupt_poison_consumption(struct kfd_dev *dev,

Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +0 -0
   		return;
   	}
 
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c static void event_interrupt_poison_consumption(struct kfd_dev *dev, · line 114

Quoted 1 line
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +1 -0
+	pr_debug("RAS poison consumption handling\n");

dev is available through kfd_dev.

[Tao] not sure of your meaning here.

I meant use dev_dbg here after fetching dev pointer through kfd_dev.

[Tao] only pr_debug is used in this file, I think another refinement is needed if we want to convert pr_debug to dev_dbg.

Quoted 82 lines
Quoted 17 lines
Quoted 8 lines

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c static void

Quoted 7 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +0 -0
   	atomic_set(&p->poison, 1);
   	kfd_unref_process(p);
 
@@ -119,10 +121,14 @@ static void

event_interrupt_poison_consumption(struct kfd_dev *dev,

Quoted 8 lines

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c static void event_interrupt_poison_consumption(struct kfd_dev *dev, · line 125

Quoted 5 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +2 -0
   		break;
   	case SOC15_INTSRC_SDMA_ECC:
   	default:
+		if (client_id == SOC15_IH_CLIENTID_UTCL2)
+			ret = kfd_dqm_evict_pasid(dev->dqm, pasid);

Since this doesn't logically belong to the switch condition, better to keep it outside of switch.

Quoted 27 lines

[Tao] will add source id definition for it.

Quoted 25 lines
Quoted 12 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +3 -2
   		break;
   	}
 
-	kfd_signal_poison_consumed_event(dev, pasid);
+	/* utcl2 page fault has its own vm fault event */
+	if (client_id != SOC15_IH_CLIENTID_UTCL2)
+		kfd_signal_poison_consumed_event(dev, pasid);
 
   	/* resetting queue passes, do page retirement without gpu reset
   	 * resetting queue fails, fallback to gpu reset solution @@
-314,7

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c static void

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +6 -1
+320,18 @@ static void event_interrupt_wq_v9(struct kfd_dev *dev,
   		info.prot_write = ring_id & 0x20;
 
   		kfd_smi_event_update_vmfault(dev, pasid);
-		kfd_dqm_evict_pasid(dev->dqm, pasid);
+
+		if (client_id == SOC15_IH_CLIENTID_UTCL2 &&
+		    dev->kfd2kgd->is_ras_utcl2_poison &&
+		    dev->kfd2kgd->is_ras_utcl2_poison(dev->adev, client_id)) {
+			event_interrupt_poison_consumption(dev,

ih_ring_entry);

Quoted 1 line

+

Is it expected that no other interrupt would come until this FED error is

cleared?

Quoted 10 lines
Quoted 1 line

Otherwise subsequent ones could also be treated as poison.

[Tao] OK, I'll clear it after checking FED status.

Quoted 4 lines

Basically, whether to do this or not?
1) Clear FED
2) Handle poison consumption

[Tao] I think we need to clear status register, otherwise the error status is

always there.

Quoted 1 line

Patch sequence is
1) Handle poison consumption
2) Clear FED.

I was asking whether to reverse it. You already clarified it above.

Thanks,
Lijo

Quoted 15 lines
Quoted 15 lines

Thanks,
Lijo

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +6 -0
+			if (dev->kfd2kgd->utcl2_fault_clear)
+				dev->kfd2kgd->utcl2_fault_clear(dev->adev);
+		}
+		else
+			kfd_dqm_evict_pasid(dev->dqm, pasid);
+
   		kfd_signal_vm_fault_event(dev, pasid, &info);
   	}
   }
#9 lore raw

RE: [PATCH 3/3] drm/amdkfd: add RAS poison consumption support for utcl2

In reply to Tao Zhou

[AMD Official Use Only]

Copy Felix

@@ -119,10 +121,14 @@ static void event_interrupt_poison_consumption(struct kfd_dev *dev,
break;
case SOC15_INTSRC_SDMA_ECC:
default:
+ if (client_id == SOC15_IH_CLIENTID_UTCL2)
+ ret = kfd_dqm_evict_pasid(dev->dqm, pasid);
break;
}

This will break SDMA - We haven't enabled optimized poison consumption handling for sdma yet.

I'd suggest we explicitly call out the interrupt source id UTCL2_FAULT as a case, even it is the same as VM_FAULT. And it should be fine to start evict_queue directly after that because in ISR it already guarantee this is from UTCL2 client, right?

+ if (client_id == SOC15_IH_CLIENTID_UTCL2 &&
+ dev->kfd2kgd->is_ras_utcl2_poison &&
+ dev->kfd2kgd->is_ras_utcl2_poison(dev->adev, client_id)) {
+ event_interrupt_poison_consumption(dev, ih_ring_entry);

In addition, is_ras_utcl2_poison can be renamed to query_utcl2_ras_status or poison_status, while utcl2_fault_clear to reset_utlc2_poison_status to align with naming style of ras hw op.

Thinking about this more, it's better we add this in gfx ras op, and expose to KFD. Thoughts?

Regards,
Hawking

-----Original Message-----
From: Zhou1, Tao <[email protected]>
Sent: Monday, March 14, 2022 15:03
To: [email protected]; Zhang, Hawking <[email protected]>; Yang, Stanley <[email protected]>; Chai, Thomas <[email protected]>
Cc: Zhou1, Tao <[email protected]>
Subject: [PATCH 3/3] drm/amdkfd: add RAS poison consumption support for utcl2

Do RAS page retirement and use gpu reset as fallback in utcl2 fault handler.

---
 .../gpu/drm/amd/amdkfd/kfd_int_process_v9.c   | 23 ++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +8 -2
index f7def0bf0730..3991f71d865b 100644
@@ -93,11 +93,12 @@ enum SQ_INTERRUPT_ERROR_TYPE {  static void event_interrupt_poison_consumption(struct kfd_dev *dev,
 				const uint32_t *ih_ring_entry)
 {
-	uint16_t source_id, pasid;
+	uint16_t source_id, client_id, pasid;
 	int ret = -EINVAL;
 	struct kfd_process *p;
 
 	source_id = SOC15_SOURCE_ID_FROM_IH_ENTRY(ih_ring_entry);
+	client_id = SOC15_CLIENT_ID_FROM_IH_ENTRY(ih_ring_entry);
 	pasid = SOC15_PASID_FROM_IH_ENTRY(ih_ring_entry);
 
 	p = kfd_lookup_process_by_pasid(pasid);
@@ -110,6 +111,7 @@ static void event_interrupt_poison_consumption(struct kfd_dev *dev,
 		return;
 	}
 
+	pr_debug("RAS poison consumption handling\n");
 	atomic_set(&p->poison, 1);
 	kfd_unref_process(p);
 
@@ -119,10 +121,14 @@ static void event_interrupt_poison_consumption(struct kfd_dev *dev,
 		break;
 	case SOC15_INTSRC_SDMA_ECC:
 	default:
+		if (client_id == SOC15_IH_CLIENTID_UTCL2)
+			ret = kfd_dqm_evict_pasid(dev->dqm, pasid);
 		break;
 	}
 
-	kfd_signal_poison_consumed_event(dev, pasid);
+	/* utcl2 page fault has its own vm fault event */
+	if (client_id != SOC15_IH_CLIENTID_UTCL2)
+		kfd_signal_poison_consumed_event(dev, pasid);
 
 	/* resetting queue passes, do page retirement without gpu reset
 	 * resetting queue fails, fallback to gpu reset solution @@ -314,7 +320,18 @@ static void event_interrupt_wq_v9(struct kfd_dev *dev,

info.prot_write = ring_id & 0x20;

kfd_smi_event_update_vmfault(dev, pasid);
- kfd_dqm_evict_pasid(dev->dqm, pasid);
+
+ if (client_id == SOC15_IH_CLIENTID_UTCL2 &&
+ dev->kfd2kgd->is_ras_utcl2_poison &&
+ dev->kfd2kgd->is_ras_utcl2_poison(dev->adev, client_id)) {
+ event_interrupt_poison_consumption(dev, ih_ring_entry);
+
+ if (dev->kfd2kgd->utcl2_fault_clear)
+ dev->kfd2kgd->utcl2_fault_clear(dev->adev);
+ }
+ else
+ kfd_dqm_evict_pasid(dev->dqm, pasid);
+
kfd_signal_vm_fault_event(dev, pasid, &info);
}
}
--
2.35.1

#10 lore raw

RE: [PATCH 3/3] drm/amdkfd: add RAS poison consumption support for utcl2

Never mind Tao. I guess you just want to leverage client_id to differentiate sdma int source from the default, right? Then might consider to explicitly call out the UTCL2_FAULT source.

Regards,
Hawking

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Zhang, Hawking
Sent: Monday, March 14, 2022 18:40
To: Zhou1, Tao <[email protected]>; [email protected]; Yang, Stanley <[email protected]>; Chai, Thomas <[email protected]>; Kuehling, Felix <[email protected]>
Subject: RE: [PATCH 3/3] drm/amdkfd: add RAS poison consumption support for utcl2

[AMD Official Use Only]

Copy Felix

@@ -119,10 +121,14 @@ static void event_interrupt_poison_consumption(struct kfd_dev *dev,
break;
case SOC15_INTSRC_SDMA_ECC:
default:
+ if (client_id == SOC15_IH_CLIENTID_UTCL2)
+ ret = kfd_dqm_evict_pasid(dev->dqm, pasid);
break;
}

This will break SDMA - We haven't enabled optimized poison consumption handling for sdma yet.

I'd suggest we explicitly call out the interrupt source id UTCL2_FAULT as a case, even it is the same as VM_FAULT. And it should be fine to start evict_queue directly after that because in ISR it already guarantee this is from UTCL2 client, right?

+ if (client_id == SOC15_IH_CLIENTID_UTCL2 &&
+ dev->kfd2kgd->is_ras_utcl2_poison &&
+ dev->kfd2kgd->is_ras_utcl2_poison(dev->adev, client_id)) {
+ event_interrupt_poison_consumption(dev, ih_ring_entry);

In addition, is_ras_utcl2_poison can be renamed to query_utcl2_ras_status or poison_status, while utcl2_fault_clear to reset_utlc2_poison_status to align with naming style of ras hw op.

Thinking about this more, it's better we add this in gfx ras op, and expose to KFD. Thoughts?

Regards,
Hawking

-----Original Message-----
From: Zhou1, Tao <[email protected]>
Sent: Monday, March 14, 2022 15:03
To: [email protected]; Zhang, Hawking <[email protected]>; Yang, Stanley <[email protected]>; Chai, Thomas <[email protected]>
Cc: Zhou1, Tao <[email protected]>
Subject: [PATCH 3/3] drm/amdkfd: add RAS poison consumption support for utcl2

Do RAS page retirement and use gpu reset as fallback in utcl2 fault handler.

---
 .../gpu/drm/amd/amdkfd/kfd_int_process_v9.c   | 23 ++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +8 -2
index f7def0bf0730..3991f71d865b 100644
@@ -93,11 +93,12 @@ enum SQ_INTERRUPT_ERROR_TYPE {  static void event_interrupt_poison_consumption(struct kfd_dev *dev,
 				const uint32_t *ih_ring_entry)
 {
-	uint16_t source_id, pasid;
+	uint16_t source_id, client_id, pasid;
 	int ret = -EINVAL;
 	struct kfd_process *p;
 
 	source_id = SOC15_SOURCE_ID_FROM_IH_ENTRY(ih_ring_entry);
+	client_id = SOC15_CLIENT_ID_FROM_IH_ENTRY(ih_ring_entry);
 	pasid = SOC15_PASID_FROM_IH_ENTRY(ih_ring_entry);
 
 	p = kfd_lookup_process_by_pasid(pasid);
@@ -110,6 +111,7 @@ static void event_interrupt_poison_consumption(struct kfd_dev *dev,
 		return;
 	}
 
+	pr_debug("RAS poison consumption handling\n");
 	atomic_set(&p->poison, 1);
 	kfd_unref_process(p);
 
@@ -119,10 +121,14 @@ static void event_interrupt_poison_consumption(struct kfd_dev *dev,
 		break;
 	case SOC15_INTSRC_SDMA_ECC:
 	default:
+		if (client_id == SOC15_IH_CLIENTID_UTCL2)
+			ret = kfd_dqm_evict_pasid(dev->dqm, pasid);
 		break;
 	}
 
-	kfd_signal_poison_consumed_event(dev, pasid);
+	/* utcl2 page fault has its own vm fault event */
+	if (client_id != SOC15_IH_CLIENTID_UTCL2)
+		kfd_signal_poison_consumed_event(dev, pasid);
 
 	/* resetting queue passes, do page retirement without gpu reset
 	 * resetting queue fails, fallback to gpu reset solution @@ -314,7 +320,18 @@ static void event_interrupt_wq_v9(struct kfd_dev *dev,

info.prot_write = ring_id & 0x20;

kfd_smi_event_update_vmfault(dev, pasid);
- kfd_dqm_evict_pasid(dev->dqm, pasid);
+
+ if (client_id == SOC15_IH_CLIENTID_UTCL2 &&
+ dev->kfd2kgd->is_ras_utcl2_poison &&
+ dev->kfd2kgd->is_ras_utcl2_poison(dev->adev, client_id)) {
+ event_interrupt_poison_consumption(dev, ih_ring_entry);
+
+ if (dev->kfd2kgd->utcl2_fault_clear)
+ dev->kfd2kgd->utcl2_fault_clear(dev->adev);
+ }
+ else
+ kfd_dqm_evict_pasid(dev->dqm, pasid);
+
kfd_signal_vm_fault_event(dev, pasid, &info);
}
}
--
2.35.1

author
#11 lore raw

RE: [PATCH 3/3] drm/amdkfd: add RAS poison consumption support for utcl2

[AMD Official Use Only]

Quoted 10 lines

-----Original Message-----
From: Zhang, Hawking <[email protected]>
Sent: Monday, March 14, 2022 7:14 PM
To: Zhang, Hawking <[email protected]>; Zhou1, Tao <[email protected]>; [email protected]; Yang, Stanley <[email protected]>; Chai, Thomas <[email protected]>; Kuehling, Felix <[email protected]>
Subject: RE: [PATCH 3/3] drm/amdkfd: add RAS poison consumption support for utcl2

Quoted 6 lines

Never mind Tao. I guess you just want to leverage client_id to differentiate sdma int source from the default, right? Then might consider to explicitly call out the UTCL2_FAULT source.

Regards,
Hawking

[Tao] we only define client id for UTCL2, no related source id definition in our code (the id number is 1 per my experiment), I'll add the definition.

Quoted 40 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Zhang, Hawking
Sent: Monday, March 14, 2022 18:40
To: Zhou1, Tao <[email protected]>; [email protected]; Yang, Stanley <[email protected]>; Chai, Thomas <[email protected]>; Kuehling, Felix <[email protected]>
Subject: RE: [PATCH 3/3] drm/amdkfd: add RAS poison consumption support for utcl2

[AMD Official Use Only]

Copy Felix

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +2 -0
@@ -119,10 +121,14 @@ static void
 event_interrupt_poison_consumption(struct kfd_dev *dev,
 		break;
 	case SOC15_INTSRC_SDMA_ECC:
 	default:
+		if (client_id == SOC15_IH_CLIENTID_UTCL2)
+			ret = kfd_dqm_evict_pasid(dev->dqm, pasid);
 		break;
 	}
 

This will break SDMA - We haven't enabled optimized poison consumption handling for sdma yet.

I'd suggest we explicitly call out the interrupt source id UTCL2_FAULT as a case, even it is the same as VM_FAULT. And it should be fine to start evict_queue directly after that because in ISR it already guarantee this is from UTCL2 client, right?

(quoted diff) +4 -0
+		if (client_id == SOC15_IH_CLIENTID_UTCL2 &&
+		    dev->kfd2kgd->is_ras_utcl2_poison &&
+		    dev->kfd2kgd->is_ras_utcl2_poison(dev->adev, client_id)) {
+			event_interrupt_poison_consumption(dev,

ih_ring_entry);

Quoted 6 lines

In addition, is_ras_utcl2_poison can be renamed to query_utcl2_ras_status or poison_status, while utcl2_fault_clear to reset_utlc2_poison_status to align with naming style of ras hw op.

Thinking about this more, it's better we add this in gfx ras op, and expose to KFD. Thoughts?

[Tao] accepted

Quoted 89 lines

Regards,
Hawking

-----Original Message-----
From: Zhou1, Tao <[email protected]>
Sent: Monday, March 14, 2022 15:03
To: [email protected]; Zhang, Hawking <[email protected]>; Yang, Stanley <[email protected]>; Chai, Thomas <[email protected]>
Cc: Zhou1, Tao <[email protected]>
Subject: [PATCH 3/3] drm/amdkfd: add RAS poison consumption support for utcl2

Do RAS page retirement and use gpu reset as fallback in utcl2 fault handler.

---
 .../gpu/drm/amd/amdkfd/kfd_int_process_v9.c   | 23 ++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +8 -2
index f7def0bf0730..3991f71d865b 100644
@@ -93,11 +93,12 @@ enum SQ_INTERRUPT_ERROR_TYPE {  static void
 event_interrupt_poison_consumption(struct kfd_dev *dev,
 				const uint32_t *ih_ring_entry)
 {
-	uint16_t source_id, pasid;
+	uint16_t source_id, client_id, pasid;
 	int ret = -EINVAL;
 	struct kfd_process *p;
 
 	source_id = SOC15_SOURCE_ID_FROM_IH_ENTRY(ih_ring_entry);
+	client_id = SOC15_CLIENT_ID_FROM_IH_ENTRY(ih_ring_entry);
 	pasid = SOC15_PASID_FROM_IH_ENTRY(ih_ring_entry);
 
 	p = kfd_lookup_process_by_pasid(pasid);
@@ -110,6 +111,7 @@ static void event_interrupt_poison_consumption(struct
 kfd_dev *dev,
 		return;
 	}
 
+	pr_debug("RAS poison consumption handling\n");
 	atomic_set(&p->poison, 1);
 	kfd_unref_process(p);
@@ -119,10 +121,14 @@ static void
 event_interrupt_poison_consumption(struct kfd_dev *dev,
 		break;
 	case SOC15_INTSRC_SDMA_ECC:
 	default:
+		if (client_id == SOC15_IH_CLIENTID_UTCL2)
+			ret = kfd_dqm_evict_pasid(dev->dqm, pasid);
 		break;
 	}
 
-	kfd_signal_poison_consumed_event(dev, pasid);
+	/* utcl2 page fault has its own vm fault event */
+	if (client_id != SOC15_IH_CLIENTID_UTCL2)
+		kfd_signal_poison_consumed_event(dev, pasid);
 
 	/* resetting queue passes, do page retirement without gpu reset
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +6 -1
 	 * resetting queue fails, fallback to gpu reset solution @@ -314,7
+320,18 @@ static void event_interrupt_wq_v9(struct kfd_dev *dev,
 		info.prot_write = ring_id & 0x20;
 
 		kfd_smi_event_update_vmfault(dev, pasid);
-		kfd_dqm_evict_pasid(dev->dqm, pasid);
+
+		if (client_id == SOC15_IH_CLIENTID_UTCL2 &&
+		    dev->kfd2kgd->is_ras_utcl2_poison &&
+		    dev->kfd2kgd->is_ras_utcl2_poison(dev->adev, client_id)) {
+			event_interrupt_poison_consumption(dev,

ih_ring_entry);

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +7 -1
+
+			if (dev->kfd2kgd->utcl2_fault_clear)
+				dev->kfd2kgd->utcl2_fault_clear(dev->adev);
+		}
+		else
+			kfd_dqm_evict_pasid(dev->dqm, pasid);
+
 		kfd_signal_vm_fault_event(dev, pasid, &info);
 	}
 }
--

2.35.1

maintainer
#12 lore raw

Re: [PATCH 3/3] drm/amdkfd: add RAS poison consumption support for utcl2

In reply to Tao Zhou

I'm not sure I understand this change. It looks like you will check the RAS poison status on every UTCL2 VM fault? Is that because there is no dedicated interrupt source or client ID to distinguish UTCL2 poison consumption from VM faults?

Why is kfd_signal_poison_consumed_event not done for UTCL2 poison consumption? The comment says, because it's signaled to user mode as a VM fault. But a VM fault and a poison consumption event are different. You're basically sending the wrong event to user mode. Maybe it doesn't make a big difference in practice at the moment. But that could change in the future.

Two more comments inline ...

Am 2022-03-14 um 03:03 schrieb Tao Zhou:

Quoted 55 lines

Do RAS page retirement and use gpu reset as fallback in utcl2 fault handler.

---
  .../gpu/drm/amd/amdkfd/kfd_int_process_v9.c   | 23 ++++++++++++++++---
  1 file changed, 20 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +8 -3
index f7def0bf0730..3991f71d865b 100644
@@ -93,11 +93,12 @@ enum SQ_INTERRUPT_ERROR_TYPE {
  static void event_interrupt_poison_consumption(struct kfd_dev *dev,
  				const uint32_t *ih_ring_entry)
  {
-	uint16_t source_id, pasid;
+	uint16_t source_id, client_id, pasid;
  	int ret = -EINVAL;
  	struct kfd_process *p;
 
  	source_id = SOC15_SOURCE_ID_FROM_IH_ENTRY(ih_ring_entry);
+	client_id = SOC15_CLIENT_ID_FROM_IH_ENTRY(ih_ring_entry);
  	pasid = SOC15_PASID_FROM_IH_ENTRY(ih_ring_entry);
 
  	p = kfd_lookup_process_by_pasid(pasid);
@@ -110,6 +111,7 @@ static void event_interrupt_poison_consumption(struct kfd_dev *dev,
  		return;
  	}
 
+	pr_debug("RAS poison consumption handling\n");
  	atomic_set(&p->poison, 1);
  	kfd_unref_process(p);
 
@@ -119,10 +121,14 @@ static void event_interrupt_poison_consumption(struct kfd_dev *dev,
  		break;
  	case SOC15_INTSRC_SDMA_ECC:
  	default:
+		if (client_id == SOC15_IH_CLIENTID_UTCL2)
+			ret = kfd_dqm_evict_pasid(dev->dqm, pasid);
  		break;
  	}
 
-	kfd_signal_poison_consumed_event(dev, pasid);
+	/* utcl2 page fault has its own vm fault event */
+	if (client_id != SOC15_IH_CLIENTID_UTCL2)
+		kfd_signal_poison_consumed_event(dev, pasid);
 
  	/* resetting queue passes, do page retirement without gpu reset
  	 * resetting queue fails, fallback to gpu reset solution
@@ -314,7 +320,18 @@ static void event_interrupt_wq_v9(struct kfd_dev *dev,
  		info.prot_write = ring_id & 0x20;
 
  		kfd_smi_event_update_vmfault(dev, pasid);
-		kfd_dqm_evict_pasid(dev->dqm, pasid);

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c static void event_interrupt_wq_v9(struct kfd_dev *dev, · line 332

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +10 -0
+
+		if (client_id == SOC15_IH_CLIENTID_UTCL2 &&
+		    dev->kfd2kgd->is_ras_utcl2_poison &&
+		    dev->kfd2kgd->is_ras_utcl2_poison(dev->adev, client_id)) {
+			event_interrupt_poison_consumption(dev, ih_ring_entry);
+
+			if (dev->kfd2kgd->utcl2_fault_clear)
+				dev->kfd2kgd->utcl2_fault_clear(dev->adev);
+		}
+		else

Else should be on the same line as }. Please run checkpatch.pl, it would catch this. It's also good practice to use {}-braces around the else-branch if you have braces around the if-branch.

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c static void event_interrupt_wq_v9(struct kfd_dev *dev, · line 335

Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +2 -0
+			kfd_dqm_evict_pasid(dev->dqm, pasid);
+
  		kfd_signal_vm_fault_event(dev, pasid, &info);

If you move kfd_signal_vm_fault_event into the else-branch, you can unconditionally send the correct poison consumption event to user mode in event_interrupt_poison_consumption.

Regards,
  Felix

Quoted 2 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +0 -0
  	}
  }
author
#13 lore raw

RE: [PATCH 3/3] drm/amdkfd: add RAS poison consumption support for utcl2

[AMD Official Use Only]

Quoted 13 lines

-----Original Message-----
From: Kuehling, Felix <[email protected]>
Sent: Tuesday, March 15, 2022 2:41 AM
To: Zhou1, Tao <[email protected]>; [email protected]; Zhang, Hawking <[email protected]>; Yang, Stanley <[email protected]>; Chai, Thomas <[email protected]>
Subject: Re: [PATCH 3/3] drm/amdkfd: add RAS poison consumption support for utcl2

I'm not sure I understand this change. It looks like you will check the RAS poison status on every UTCL2 VM fault? Is that because there is no dedicated interrupt source or client ID to distinguish UTCL2 poison consumption from VM faults?

Quoted 5 lines

Why is kfd_signal_poison_consumed_event not done for UTCL2 poison consumption? The comment says, because it's signaled to user mode as a VM fault. But a VM fault and a poison consumption event are different. You're basically sending the wrong event to user mode. Maybe it doesn't make a big difference in practice at the moment. But that could change in the future.

[Tao] yes, no dedicated interrupt source, so I need to check FED bit in VM_L2_PROTECTION_FAULT_STATUS to distinguish it from general VM fault.

I inject error to PDE1 to trigger UTCL2 poison consumption, both kfd_signal_poison_consumed_event and kfd_signal_vm_fault_event can be handled by ROCr in my experiment (bus error vs. coredump and APP can be killed). I think we can take UTCL2 consumption as a special VM fault, so I select kfd_signal_vm_fault_event. Anyway, this can be discussed furtherly.

Quoted 69 lines

Two more comments inline ...

Am 2022-03-14 um 03:03 schrieb Tao Zhou:

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c static void

Quoted 28 lines

Do RAS page retirement and use gpu reset as fallback in utcl2 fault handler.

---
  .../gpu/drm/amd/amdkfd/kfd_int_process_v9.c   | 23 ++++++++++++++++---
  1 file changed, 20 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +2 -1
index f7def0bf0730..3991f71d865b 100644
@@ -93,11 +93,12 @@ enum SQ_INTERRUPT_ERROR_TYPE {
  static void event_interrupt_poison_consumption(struct kfd_dev *dev,
  				const uint32_t *ih_ring_entry)
  {
-	uint16_t source_id, pasid;
+	uint16_t source_id, client_id, pasid;
  	int ret = -EINVAL;
  	struct kfd_process *p;
 
  	source_id = SOC15_SOURCE_ID_FROM_IH_ENTRY(ih_ring_entry);
+	client_id = SOC15_CLIENT_ID_FROM_IH_ENTRY(ih_ring_entry);
  	pasid = SOC15_PASID_FROM_IH_ENTRY(ih_ring_entry);
 
  	p = kfd_lookup_process_by_pasid(pasid);
@@ -110,6 +111,7 @@ static void

event_interrupt_poison_consumption(struct kfd_dev *dev,

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c static void

Quoted 8 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +1 -0
  		return;
  	}
 
+	pr_debug("RAS poison consumption handling\n");
  	atomic_set(&p->poison, 1);
  	kfd_unref_process(p);
 
@@ -119,10 +121,14 @@ static void

event_interrupt_poison_consumption(struct kfd_dev *dev,

Quoted 15 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +5 -1
  		break;
  	case SOC15_INTSRC_SDMA_ECC:
  	default:
+		if (client_id == SOC15_IH_CLIENTID_UTCL2)
+			ret = kfd_dqm_evict_pasid(dev->dqm, pasid);
  		break;
  	}
 
-	kfd_signal_poison_consumed_event(dev, pasid);
+	/* utcl2 page fault has its own vm fault event */
+	if (client_id != SOC15_IH_CLIENTID_UTCL2)
+		kfd_signal_poison_consumed_event(dev, pasid);
 
  	/* resetting queue passes, do page retirement without gpu reset
  	 * resetting queue fails, fallback to gpu reset solution @@ -314,7

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c static void event_interrupt_poison_consumption(struct kfd_dev *dev,

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +6 -1
+320,18 @@ static void event_interrupt_wq_v9(struct kfd_dev *dev,
  		info.prot_write = ring_id & 0x20;
 
  		kfd_smi_event_update_vmfault(dev, pasid);
-		kfd_dqm_evict_pasid(dev->dqm, pasid);
+
+		if (client_id == SOC15_IH_CLIENTID_UTCL2 &&
+		    dev->kfd2kgd->is_ras_utcl2_poison &&
+		    dev->kfd2kgd->is_ras_utcl2_poison(dev->adev, client_id)) {
+			event_interrupt_poison_consumption(dev,

ih_ring_entry);

Quoted 9 lines

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c static void event_interrupt_wq_v9(struct kfd_dev *dev, · line 332

Quoted 5 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +5 -0
+
+			if (dev->kfd2kgd->utcl2_fault_clear)
+				dev->kfd2kgd->utcl2_fault_clear(dev->adev);
+		}
+		else

Else should be on the same line as }. Please run checkpatch.pl, it would catch this. It's also good practice to use {}-braces around the else-branch if you have braces around the if-branch.

[Tao] accepted

Quoted 16 lines

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c static void event_interrupt_wq_v9(struct kfd_dev *dev, · line 335

Quoted 5 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +2 -0
+			kfd_dqm_evict_pasid(dev->dqm, pasid);
+
  		kfd_signal_vm_fault_event(dev, pasid, &info);

If you move kfd_signal_vm_fault_event into the else-branch, you can unconditionally send the correct poison consumption event to user mode in event_interrupt_poison_consumption.

Regards,
  Felix

Quoted 2 lines
  	}
  }
maintainer
#14 lore raw
In reply to Tao Zhou

Am 2022-03-14 um 03:03 schrieb Tao Zhou:

Quoted 2 lines

Other parameters can be gotten from ih_ring_entry, so only inputting ih_ring_entry is enough.

I'm not sure what's the reason for this change. You remove one parameter, but end up duplicating the SOC15_..._FROM_IH_RING_ENTRY translations. It doesn't look like a net improvement to me.

Looking at this function a bit more, this code looks problematic:

        if (atomic_read(&p->poison)) {
                kfd_unref_process(p);
                return;
        }

        atomic_set(&p->poison, 1);
        kfd_unref_process(p);

Doing the read and set as two separate operations is not atomic. You should use atomic_cmpxchg here to make sure the poison-consumption is handled only once:

	old_poison = atomic_cmpxchg(&p->poison, 0, 1);
	kfd_unref_process(p);
	if (old_poison)
		return;
	/* handle poison consumption */

Alternatively you could use atomic_inc_return and do the poison handling only if that returns exactly 1.

Regards,
  Felix

Quoted 47 lines
---
  drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c | 13 +++++++++----
  1 file changed, 9 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +9 -4
index 7eedbcd14828..f7def0bf0730 100644
@@ -91,11 +91,16 @@ enum SQ_INTERRUPT_ERROR_TYPE {
  #define KFD_SQ_INT_DATA__ERR_TYPE__SHIFT 20
 
  static void event_interrupt_poison_consumption(struct kfd_dev *dev,
-				uint16_t pasid, uint16_t source_id)
+				const uint32_t *ih_ring_entry)
  {
+	uint16_t source_id, pasid;
  	int ret = -EINVAL;
-	struct kfd_process *p = kfd_lookup_process_by_pasid(pasid);
+	struct kfd_process *p;
 
+	source_id = SOC15_SOURCE_ID_FROM_IH_ENTRY(ih_ring_entry);
+	pasid = SOC15_PASID_FROM_IH_ENTRY(ih_ring_entry);
+
+	p = kfd_lookup_process_by_pasid(pasid);
  	if (!p)
  		return;
 
@@ -270,7 +275,7 @@ static void event_interrupt_wq_v9(struct kfd_dev *dev,
  					sq_intr_err);
  				if (sq_intr_err != SQ_INTERRUPT_ERROR_TYPE_ILLEGAL_INST &&
  					sq_intr_err != SQ_INTERRUPT_ERROR_TYPE_MEMVIOL) {
-					event_interrupt_poison_consumption(dev, pasid, source_id);
+					event_interrupt_poison_consumption(dev, ih_ring_entry);
  					return;
  				}
  				break;
@@ -291,7 +296,7 @@ static void event_interrupt_wq_v9(struct kfd_dev *dev,
  		if (source_id == SOC15_INTSRC_SDMA_TRAP) {
  			kfd_signal_event_interrupt(pasid, context_id0 & 0xfffffff, 28);
  		} else if (source_id == SOC15_INTSRC_SDMA_ECC) {
-			event_interrupt_poison_consumption(dev, pasid, source_id);
+			event_interrupt_poison_consumption(dev, ih_ring_entry);
  			return;
  		}
  	} else if (client_id == SOC15_IH_CLIENTID_VMC ||
author
#15 lore raw

[AMD Official Use Only]

Quoted 9 lines

-----Original Message-----
From: Kuehling, Felix <[email protected]>
Sent: Tuesday, March 15, 2022 2:25 AM
To: Zhou1, Tao <[email protected]>; [email protected]; Zhang, Hawking <[email protected]>; Yang, Stanley <[email protected]>; Chai, Thomas <[email protected]>
Subject: Re: [PATCH 1/3] drm/amdkfd: update parameter for event_interrupt_poison_consumption

Quoted 7 lines

Am 2022-03-14 um 03:03 schrieb Tao Zhou:

Quoted 2 lines

Other parameters can be gotten from ih_ring_entry, so only inputting ih_ring_entry is enough.

I'm not sure what's the reason for this change. You remove one parameter, but end up duplicating the SOC15_..._FROM_IH_RING_ENTRY translations. It doesn't look like a net improvement to me.

[Tao] source_id/pasid/client_id will be transferred and I'd like to reduce the number of parameters, I'll drop the change.

Quoted 15 lines

Looking at this function a bit more, this code looks problematic:

        if (atomic_read(&p->poison)) {
                kfd_unref_process(p);
                return;
        }

        atomic_set(&p->poison, 1);
        kfd_unref_process(p);

Doing the read and set as two separate operations is not atomic. You should use atomic_cmpxchg here to make sure the poison-consumption is handled only once:

Quoted 8 lines
	old_poison = atomic_cmpxchg(&p->poison, 0, 1);
	kfd_unref_process(p);
	if (old_poison)
		return;
	/* handle poison consumption */

Alternatively you could use atomic_inc_return and do the poison handling only if that returns exactly 1.

[Tao] thanks, accepted.

Quoted 60 lines

Regards,
  Felix

Quoted 31 lines
---
  drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c | 13 +++++++++----
  1 file changed, 9 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +7 -2
index 7eedbcd14828..f7def0bf0730 100644
@@ -91,11 +91,16 @@ enum SQ_INTERRUPT_ERROR_TYPE {
  #define KFD_SQ_INT_DATA__ERR_TYPE__SHIFT 20
 
  static void event_interrupt_poison_consumption(struct kfd_dev *dev,
-				uint16_t pasid, uint16_t source_id)
+				const uint32_t *ih_ring_entry)
  {
+	uint16_t source_id, pasid;
  	int ret = -EINVAL;
-	struct kfd_process *p = kfd_lookup_process_by_pasid(pasid);
+	struct kfd_process *p;
 
+	source_id = SOC15_SOURCE_ID_FROM_IH_ENTRY(ih_ring_entry);
+	pasid = SOC15_PASID_FROM_IH_ENTRY(ih_ring_entry);
+
+	p = kfd_lookup_process_by_pasid(pasid);
  	if (!p)
  		return;
 

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c static void event_interrupt_wq_v9(struct kfd_dev *dev, · line 276

Quoted 2 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +0 -0
@@ -270,7 +275,7 @@ static void event_interrupt_wq_v9(struct kfd_dev *dev,
  					sq_intr_err);
  				if (sq_intr_err !=

SQ_INTERRUPT_ERROR_TYPE_ILLEGAL_INST &&

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c static void event_interrupt_wq_v9(struct kfd_dev *dev, · line 277

Quoted 1 line
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +0 -0
  					sq_intr_err !=

SQ_INTERRUPT_ERROR_TYPE_MEMVIOL) {

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c static void event_interrupt_wq_v9(struct kfd_dev *dev, · line 273

Quoted 1 line
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +0 -1
-
	event_interrupt_poison_consumption(dev, pasid, source_id);

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c enum SQ_INTERRUPT_ERROR_TYPE { · line 102

Quoted 1 line
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +1 -0
+
	event_interrupt_poison_consumption(dev, ih_ring_entry);

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c static void event_interrupt_wq_v9(struct kfd_dev *dev, · line 297

Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +0 -0
  					return;
  				}
  				break;
@@ -291,7 +296,7 @@ static void event_interrupt_wq_v9(struct kfd_dev *dev,
  		if (source_id == SOC15_INTSRC_SDMA_TRAP) {
  			kfd_signal_event_interrupt(pasid, context_id0 &

0xfffffff, 28);

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c static void event_interrupt_wq_v9(struct kfd_dev *dev, · line 294

Quoted 2 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +0 -1
  		} else if (source_id == SOC15_INTSRC_SDMA_ECC) {
-			event_interrupt_poison_consumption(dev, pasid,

source_id);

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c static void event_interrupt_wq_v9(struct kfd_dev *dev, · line 299

Quoted 1 line
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +1 -0
+			event_interrupt_poison_consumption(dev,

ih_ring_entry);

Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +0 -0
  			return;
  		}
  	} else if (client_id == SOC15_IH_CLIENTID_VMC ||