Skip to contentSkip to conversation

drm/amdgpu: get sdma instance from irq id

PATCH In review Tao Zhou 1 participant 5 messages Jun 11, 2025 – Jun 13, 2025

Subsystems (3)
lore
Share & tools
lore

Tao Zhou

author
#0 lore raw

PATCH 1/4 drm/amdgpu: get sdma instance from irq id

And the interface can be accessed globally.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h |  2 +
 drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 51 ++++++++++++++++--------
 2 files changed, 36 insertions(+), 17 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +2 -0
index e5f8951bbb6f..262321a0aa4f 100644
@@ -54,6 +54,8 @@ struct amdgpu_sdma_funcs {
 	int (*stop_kernel_queue)(struct amdgpu_ring *ring);
 	int (*start_kernel_queue)(struct amdgpu_ring *ring);
 	int (*soft_reset_kernel_queue)(struct amdgpu_device *adev, u32 instance_id);
+	int (*sdma_irq_id_to_seq)(struct amdgpu_device *adev,
+			uint16_t client_id, uint16_t node_id);
 };
 
 struct amdgpu_sdma_instance {
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +34 -17

73 lines not on this page · raw message

Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 2/4 drm/amdgpu: Add SDMA RAS poison consumption handling

Perform queue reset for SDMA poison consumption.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c |  8 ++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h |  3 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c    | 30 ++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h    |  4 +++
 4 files changed, 45 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +8 -0
index 6c47f7d9adcd..085bff11319a 100644
@@ -741,6 +741,14 @@ void amdgpu_amdkfd_ras_poison_consumption_handler(struct amdgpu_device *adev,
 	amdgpu_umc_pasid_poison_handler(adev, block, 0, NULL, NULL, reset);
 }
 
+int amdgpu_amdkfd_ras_poison_queue_reset(struct amdgpu_device *adev,
+	enum amdgpu_ras_block block, uint16_t client_id, uint16_t vmid,
+	uint16_t node_id)
+{
+	return amdgpu_ras_poison_queue_reset(adev, block, client_id, vmid,
+			node_id);
+}
+
 int amdgpu_amdkfd_send_close_event_drain_irq(struct amdgpu_device *adev,
 					uint32_t *payload)
 {
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +3 -0
index 3fa951ede37c..f1680027399e 100644
@@ -404,6 +404,9 @@ void amdgpu_amdkfd_ras_poison_consumption_handler(struct amdgpu_device *adev,
 void amdgpu_amdkfd_ras_pasid_poison_consumption_handler(struct amdgpu_device *adev,
 			enum amdgpu_ras_block block, uint16_t pasid,
 			pasid_notify pasid_fn, void *data, uint32_t reset);
+int amdgpu_amdkfd_ras_poison_queue_reset(struct amdgpu_device *adev,
+			enum amdgpu_ras_block block, uint16_t client_id,
+			uint16_t vmid, uint16_t node_id);
 
 bool amdgpu_amdkfd_is_fed(struct amdgpu_device *adev);
 bool amdgpu_amdkfd_bo_mapped_to_dev(void *drm_priv, struct kgd_mem *mem);
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +30 -0
index 6565dc7ff9cd..7e63c2fc1a62 100644
@@ -5311,3 +5311,33 @@ bool amdgpu_ras_is_rma(struct amdgpu_device *adev)
 
 	return con->is_rma;
 }
+
+int amdgpu_ras_poison_queue_reset(struct amdgpu_device *adev,
+	enum amdgpu_ras_block block, uint16_t client_id, uint16_t vmid,
+	uint16_t node_id)
+{
+	struct amdgpu_ring *ring = NULL;
+	int sdma_inst, ret;
+
+	if (block == AMDGPU_RAS_BLOCK__SDMA &&
+	    adev->sdma.instance[0].funcs->sdma_irq_id_to_seq) {
+		sdma_inst = adev->sdma.instance[0].funcs->sdma_irq_id_to_seq(adev,
+					client_id, node_id);
+		if (sdma_inst < 0)
+			return sdma_inst;
+
+		ring = &(adev->sdma.instance[sdma_inst].ring);
+	}
+
+	if (ring && ring->funcs->reset) {
+		ret = amdgpu_ring_reset(ring, vmid);
+		if (ret)
+			dev_warn(adev->dev,
+				"queue reset failed in block%d (ret %d), fallback to gpu reset\n",
+				block, ret);
+	} else {
+		return -EINVAL;
+	}
+
+	return ret;
+}
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h +4 -0
index 927d6bff734a..debc07767b5c 100644
@@ -984,4 +984,8 @@ void amdgpu_ras_event_log_print(struct amdgpu_device *adev, u64 event_id,
 				const char *fmt, ...);
 
 bool amdgpu_ras_is_rma(struct amdgpu_device *adev);
+
+int amdgpu_ras_poison_queue_reset(struct amdgpu_device *adev,
+	enum amdgpu_ras_block block, uint16_t client_id, uint16_t vmid,
+	uint16_t node_id);
 #endif
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH 3/4 drm/amdkfd: add vmid/nodeid input for RAS poison consumption handler

In reply to Tao Zhou

Prepare for the support of specific queue reset.

v2: also input node_id to the handler.

---
 drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +10 -5
index 4ceb251312a6..0018d04f4b33 100644
@@ -142,7 +142,8 @@ enum SQ_INTERRUPT_ERROR_TYPE {
 				>> KFD_DEBUG_CP_BAD_OP_ECODE_SHIFT)
 
 static void event_interrupt_poison_consumption_v9(struct kfd_node *dev,
-				uint16_t pasid, uint16_t client_id)
+				uint16_t pasid, uint16_t client_id,
+				uint16_t vmid, uint16_t node_id)
 {
 	enum amdgpu_ras_block block = 0;
 	uint32_t reset = 0;
@@ -357,7 +358,7 @@ static bool event_interrupt_isr_v9(struct kfd_node *dev,
 static void event_interrupt_wq_v9(struct kfd_node *dev,
 					const uint32_t *ih_ring_entry)
 {
-	uint16_t source_id, client_id, pasid, vmid;
+	uint16_t source_id, client_id, pasid, vmid, node_id;
 	uint32_t context_id0, context_id1;
 	uint32_t sq_intr_err, sq_int_data, encoding;
 
@@ -367,6 +368,7 @@ static void event_interrupt_wq_v9(struct kfd_node *dev,
 	vmid = SOC15_VMID_FROM_IH_ENTRY(ih_ring_entry);
 	context_id0 = SOC15_CONTEXT_ID0_FROM_IH_ENTRY(ih_ring_entry);
 	context_id1 = SOC15_CONTEXT_ID1_FROM_IH_ENTRY(ih_ring_entry);
+	node_id = SOC15_NODEID_FROM_IH_ENTRY(ih_ring_entry);
 
 	if (client_id == SOC15_IH_CLIENTID_GRBM_CP ||
 	    client_id == SOC15_IH_CLIENTID_SE0SH ||
@@ -501,7 +503,8 @@ static void event_interrupt_wq_v9(struct kfd_node *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_v9(dev, pasid, client_id);
+					event_interrupt_poison_consumption_v9(dev,
+						pasid, client_id, vmid, node_id);
 					return;
 				}
 				break;
@@ -527,7 +530,8 @@ static void event_interrupt_wq_v9(struct kfd_node *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_v9(dev, pasid, client_id);
+			event_interrupt_poison_consumption_v9(dev, pasid,
+				client_id, vmid, node_id);
 			return;
 		}
 	} else if (client_id == SOC15_IH_CLIENTID_VMC ||
@@ -538,7 +542,8 @@ static void event_interrupt_wq_v9(struct kfd_node *dev,
 		struct kfd_hsa_memory_exception_data exception_data;
 
 		if (source_id == SOC15_INTSRC_VMC_UTCL2_POISON) {
-			event_interrupt_poison_consumption_v9(dev, pasid, client_id);
+			event_interrupt_poison_consumption_v9(dev,
+				pasid, client_id, vmid, node_id);
 			return;
 		}
 
Signature · 1 line
2.34.1
author
#3 lore raw

PATCH 4/4 drm/amdkfd: use queue reset for SDMA RAS poison consumption

In reply to Tao Zhou

Replace mode2 reset with queue reset to improve system performance.

v2: fallback to mode1 reset if queue reset fails.
move the queue reset handling from KFD to KGD.

---
 drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +12 -1
index 0018d04f4b33..b9429774a006 100644
@@ -197,6 +197,9 @@ static void event_interrupt_poison_consumption_v9(struct kfd_node *dev,
 	case SOC15_IH_CLIENTID_SDMA2:
 	case SOC15_IH_CLIENTID_SDMA3:
 	case SOC15_IH_CLIENTID_SDMA4:
+	case SOC15_IH_CLIENTID_SDMA5:
+	case SOC15_IH_CLIENTID_SDMA6:
+	case SOC15_IH_CLIENTID_SDMA7:
 		block = AMDGPU_RAS_BLOCK__SDMA;
 		if (amdgpu_ip_version(dev->adev, SDMA0_HWIP, 0) == IP_VERSION(4, 4, 2)) {
 			/* driver mode-2 for gfx poison is only supported by
@@ -204,7 +207,7 @@ static void event_interrupt_poison_consumption_v9(struct kfd_node *dev,
 			if (dev->adev->pm.fw_version < 0x00557300)
 				reset = AMDGPU_RAS_GPU_RESET_MODE1_RESET;
 			else
-				reset = AMDGPU_RAS_GPU_RESET_MODE2_RESET;
+				reset = 0;
 		} else if (amdgpu_ip_version(dev->adev, SDMA0_HWIP, 0) == IP_VERSION(4, 4, 5)) {
 			/* driver mode-2 for gfx poison is only supported by
 			 * pmfw 0x05550C00 and onwards */
@@ -223,6 +226,14 @@ static void event_interrupt_poison_consumption_v9(struct kfd_node *dev,
 		return;
 	}
 
+	if (!reset) {
+		ret = amdgpu_amdkfd_ras_poison_queue_reset(dev->adev, block,
+				 client_id, vmid, node_id);
+		/* fallback to mode1 reset */
+		if (ret)
+			reset = AMDGPU_RAS_GPU_RESET_MODE1_RESET;
+	}
+
 	ret = amdgpu_ras_mark_ras_event(dev->adev, type);
 	if (ret)
 		return;
Signature · 1 line
2.34.1
author
#4 lore raw
In reply to Tao Zhou

[AMD Official Use Only - AMD Internal Distribution Only]

Ping for the series.

Quoted 115 lines

-----Original Message-----
From: Zhou1, Tao <[email protected]>
Sent: Wednesday, June 11, 2025 11:35 AM
To: [email protected]
Cc: Zhou1, Tao <[email protected]>
Subject: [PATCH 1/4] drm/amdgpu: get sdma instance from irq id

And the interface can be accessed globally.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h |  2 +
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 51 ++++++++++++++++--------
 2 files changed, 36 insertions(+), 17 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +2 -0
index e5f8951bbb6f..262321a0aa4f 100644
@@ -54,6 +54,8 @@ struct amdgpu_sdma_funcs {
      int (*stop_kernel_queue)(struct amdgpu_ring *ring);
      int (*start_kernel_queue)(struct amdgpu_ring *ring);
      int (*soft_reset_kernel_queue)(struct amdgpu_device *adev, u32
 instance_id);
+     int (*sdma_irq_id_to_seq)(struct amdgpu_device *adev,
+                     uint16_t client_id, uint16_t node_id);
 };
 

struct amdgpu_sdma_instance {

drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0 -0
index 9c169112a5e7..96ea9a0f952c 100644
@@ -156,6 +156,35 @@ static int sdma_v4_4_2_irq_id_to_seq(struct

amdgpu_device *adev, unsigned client

      }

}

drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +28 -0
+static int sdma_v4_4_2_irq_id_to_seq_global(struct amdgpu_device *adev,
+             uint16_t client_id, uint16_t node_id) {
+     uint32_t instance, i;
+
+     instance = sdma_v4_4_2_irq_id_to_seq(adev, client_id);
+
+     /* Client id gives the SDMA instance in AID. To know the exact SDMA
+      * instance, interrupt entry gives the node id which corresponds to
+      * the AID instance. Match node id with the AID id associated with
+      * the SDMA instance.
+      */
+     for (i = instance; i < adev->sdma.num_instances;
+              i += adev->sdma.num_inst_per_aid) {
+             if (adev->sdma.instance[i].aid_id ==
+                     node_id_to_phys_map[node_id])
+                     break;
+     }
+
+     if (i >= adev->sdma.num_instances) {
+             dev_WARN_ONCE(
+                     adev->dev, 1,
+                     "Couldn't find the right sdma instance in trap handler");
+             return -EINVAL;
+     }
+
+     return i;
+}
+
 static void sdma_v4_4_2_inst_init_golden_registers(struct amdgpu_device *adev,
                                                 uint32_t inst_mask)
 {
@@ -1337,6 +1366,7 @@ static bool

sdma_v4_4_2_fw_support_paging_queue(struct amdgpu_device *adev) static const

struct amdgpu_sdma_funcs sdma_v4_4_2_sdma_funcs = {
      .stop_kernel_queue = &sdma_v4_4_2_stop_queue,
      .start_kernel_queue = &sdma_v4_4_2_restore_queue,

+ .sdma_irq_id_to_seq = &sdma_v4_4_2_irq_id_to_seq_global,
};

static int sdma_v4_4_2_early_init(struct amdgpu_ip_block *ip_block) @@ -1764,27
+1794,14 @@ static int sdma_v4_4_2_process_trap_irq(struct amdgpu_device *adev,
struct amdgpu_irq_src *source, struct amdgpu_iv_entry *entry) {

drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1 -4
-     uint32_t instance, i;
+     int i;
 
      DRM_DEBUG("IH: SDMA trap\n");
-     instance = sdma_v4_4_2_irq_id_to_seq(adev, entry->client_id);
 
-     /* Client id gives the SDMA instance in AID. To know the exact SDMA
-      * instance, interrupt entry gives the node id which corresponds to the AID

instance.

drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +3 -14
-      * Match node id with the AID id associated with the SDMA instance. */
-     for (i = instance; i < adev->sdma.num_instances;
-          i += adev->sdma.num_inst_per_aid) {
-             if (adev->sdma.instance[i].aid_id ==
-                 node_id_to_phys_map[entry->node_id])
-                     break;
-     }
-
-     if (i >= adev->sdma.num_instances) {
-             dev_WARN_ONCE(
-                     adev->dev, 1,
-                     "Couldn't find the right sdma instance in trap handler");
+     i = sdma_v4_4_2_irq_id_to_seq_global(adev, entry->client_id,
+                             entry->node_id);
+     if (i < 0)
              return 0;
-     }
 
      switch (entry->ring_id) {
      case 0:
--

2.34.1