Skip to contentSkip to conversation

drm/amdgpu: Implement instance ID remapping for harvested SDMA engines

PATCH In review Jesse Zhang 2 participants 4 messages Jun 11, 2025

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

PATCH 1/2 drm/amdgpu: Implement instance ID remapping for harvested SDMA engines

Adds logic to handle instance ID conversion during SDMA engine reset when harvest_config is active. This ensures correct physical engine addressing when some SDMA instances are harvested.

Changes include:
1. Added instance ID remapping using GET_INST macro when harvest_config is non-zero
2. Conversion happens before engine reset procedure begins
3. Maintains existing reset flow for non-harvested configurations

This fixes hardware initialization issues on devices with harvested SDMA instances where the logical instance IDs don't match physical hardware mapping.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c      | 3 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h      | 1 +
 3 files changed, 5 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +1 -0
index a0e9bf9b2710..4282f60a0cef 100644
@@ -759,6 +759,7 @@ static void amdgpu_discovery_read_from_harvest_table(struct amdgpu_device *adev,
 				~(1U << harvest_info->list[i].number_instance);
 			break;
 		case SDMA0_HWID:
+			adev->sdma.harvest_config |= (1U << harvest_info->list[i].number_instance);
 			adev->sdma.sdma_mask &=
 				~(1U << harvest_info->list[i].number_instance);
 			break;
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +3 -0
index 6716ac281c49..0bfd2c138d24 100644
@@ -581,6 +581,9 @@ int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id)
 	bool gfx_sched_stopped = false, page_sched_stopped = false;
 
 	mutex_lock(&sdma_instance->engine_reset_mutex);
+
+	if (adev->sdma.harvest_config)
+		instance_id = GET_INST(SDMA0, instance_id);
 	/* Stop the scheduler's work queue for the GFX and page rings if they are running.
 	* This ensures that no new tasks are submitted to the queues while
 	* the reset is in progress.
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +1 -0
index e5f8951bbb6f..fed00854a1a2 100644
@@ -123,6 +123,7 @@ struct amdgpu_sdma {
 
 	int			num_instances;
 	uint32_t 		sdma_mask;
+	uint32_t		harvest_config;
 	int			num_inst_per_aid;
 	uint32_t                    srbm_soft_reset;
 	bool			has_page_queue;
Signature · 1 line
2.34.1
#1 lore raw

PATCH 2/2 drm/amdgpu: Fix SDMA queue reset array out-of-bounds access

The current SDMA v4.4.2 queue reset logic incorrectly uses GET_INST macro for queue operations, leading to array index out-of-bounds errors when harvesting is enabled. This manifests as UBSAN warnings when stopping queues during reset operations.

[  306.871518] UBSAN: array-index-out-of-bounds in drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c:118:38
[  306.871538] index 4294967295 is out of range for type 'uint32_t *[44]'
[  306.871929]  amdgpu_sdma_reset_engine+0xe4/0x320 [amdgpu]
[  306.872115]  reset_queues_on_hws_hang+0x2dc/0x4d0 [amdgpu]

The fix ensures we use physical instance IDs consistently for queue operations while maintaining harvest-aware mapping for register access.

---
 drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +2 -2
index 9c169112a5e7..3de125062ee3 100644
@@ -1670,7 +1670,7 @@ static bool sdma_v4_4_2_page_ring_is_guilty(struct amdgpu_ring *ring)
 static int sdma_v4_4_2_reset_queue(struct amdgpu_ring *ring, unsigned int vmid)
 {
 	struct amdgpu_device *adev = ring->adev;
-	u32 id = GET_INST(SDMA0, ring->me);
+	u32 id = ring->me;
 	int r;
 
 	if (!(adev->sdma.supported_reset & AMDGPU_RESET_TYPE_PER_QUEUE))
@@ -1686,7 +1686,7 @@ static int sdma_v4_4_2_reset_queue(struct amdgpu_ring *ring, unsigned int vmid)
 static int sdma_v4_4_2_stop_queue(struct amdgpu_ring *ring)
 {
 	struct amdgpu_device *adev = ring->adev;
-	u32 instance_id = GET_INST(SDMA0, ring->me);
+	u32 instance_id = ring->me;
 	u32 inst_mask;
 	uint64_t rptr;
 
Signature · 1 line
2.34.1
#2 lore raw
In reply to Jesse Zhang
Quoted 10 lines · Jesse Zhang

Adds logic to handle instance ID conversion during SDMA engine reset when harvest_config is active. This ensures correct physical engine addressing when some SDMA instances are harvested.

Changes include:
1. Added instance ID remapping using GET_INST macro when harvest_config is non-zero
2. Conversion happens before engine reset procedure begins
3. Maintains existing reset flow for non-harvested configurations

Quoted 4 lines

This fixes hardware initialization issues on devices with harvested SDMA instances where the logical instance IDs don't match physical hardware mapping.

This shouldn't be required. Without harvest-awareness, driver won't load properly on MI308.

Thanks,
Lijo

Quoted 46 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c      | 3 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h      | 1 +
 3 files changed, 5 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +1 -0
index a0e9bf9b2710..4282f60a0cef 100644
@@ -759,6 +759,7 @@ static void amdgpu_discovery_read_from_harvest_table(struct amdgpu_device *adev,
 				~(1U << harvest_info->list[i].number_instance);
 			break;
 		case SDMA0_HWID:
+			adev->sdma.harvest_config |= (1U << harvest_info->list[i].number_instance);
 			adev->sdma.sdma_mask &=
 				~(1U << harvest_info->list[i].number_instance);
 			break;
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +3 -0
index 6716ac281c49..0bfd2c138d24 100644
@@ -581,6 +581,9 @@ int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id)
 	bool gfx_sched_stopped = false, page_sched_stopped = false;
 
 	mutex_lock(&sdma_instance->engine_reset_mutex);
+
+	if (adev->sdma.harvest_config)
+		instance_id = GET_INST(SDMA0, instance_id);
 	/* Stop the scheduler's work queue for the GFX and page rings if they are running.
 	* This ensures that no new tasks are submitted to the queues while
 	* the reset is in progress.
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +1 -0
index e5f8951bbb6f..fed00854a1a2 100644
@@ -123,6 +123,7 @@ struct amdgpu_sdma {
 
 	int			num_instances;
 	uint32_t 		sdma_mask;
+	uint32_t		harvest_config;
 	int			num_inst_per_aid;
 	uint32_t                    srbm_soft_reset;
 	bool			has_page_queue;
#3 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

Thanks Lijo
As we discussed offline, we will remove the harvest_config check.

Regards
Jesse

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Wednesday, June 11, 2025 2:15 PM
To: Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Kim, Jonathan <[email protected]>; Zhu, Jiadong <[email protected]>
Subject: Re: [PATCH 1/2] drm/amdgpu: Implement instance ID remapping for harvested SDMA engines

Quoted 10 lines · Jesse Zhang

Adds logic to handle instance ID conversion during SDMA engine reset when harvest_config is active. This ensures correct physical engine addressing when some SDMA instances are harvested.

Changes include:
1. Added instance ID remapping using GET_INST macro when harvest_config is non-zero
2. Conversion happens before engine reset procedure begins 3. Maintains existing reset flow for non-harvested configurations

Quoted 4 lines

This fixes hardware initialization issues on devices with harvested SDMA instances where the logical instance IDs don't match physical hardware mapping.

This shouldn't be required. Without harvest-awareness, driver won't load properly on MI308.

Thanks,
Lijo

Quoted 50 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c      | 3 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h      | 1 +
 3 files changed, 5 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +2 -0
index a0e9bf9b2710..4282f60a0cef 100644
@@ -759,6 +759,7 @@ static void amdgpu_discovery_read_from_harvest_table(struct amdgpu_device *adev,
                              ~(1U << harvest_info->list[i].number_instance);
                      break;
              case SDMA0_HWID:
+                     adev->sdma.harvest_config |= (1U <<
+harvest_info->list[i].number_instance);
                      adev->sdma.sdma_mask &=
                              ~(1U << harvest_info->list[i].number_instance);
                      break;
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +3 -0
index 6716ac281c49..0bfd2c138d24 100644
@@ -581,6 +581,9 @@ int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id)
      bool gfx_sched_stopped = false, page_sched_stopped = false;
 
      mutex_lock(&sdma_instance->engine_reset_mutex);
+
+     if (adev->sdma.harvest_config)
+             instance_id = GET_INST(SDMA0, instance_id);
      /* Stop the scheduler's work queue for the GFX and page rings if they are running.
      * This ensures that no new tasks are submitted to the queues while
      * the reset is in progress.
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +1 -0
index e5f8951bbb6f..fed00854a1a2 100644
@@ -123,6 +123,7 @@ struct amdgpu_sdma {
 
      int                     num_instances;
      uint32_t                sdma_mask;
+     uint32_t                harvest_config;
      int                     num_inst_per_aid;
      uint32_t                    srbm_soft_reset;
      bool                    has_page_queue;