Skip to contentSkip to conversation

drm/amdgpu: Disable gfx IB preemption with gang submit

PATCH In review Yifan Zha 2 participants 2 messages Aug 27, 2025

Subsystems (2)
lore
Share & tools
lore

Yifan Zha

author
#0 lore raw

PATCH 1/1 drm/amdgpu: Disable gfx IB preemption with gang submit

[Why]
Gang submit has conflict with IB preemption which will break the synchronization between enginees. Specifically, MCBP is enabled default under SRIOV. It will causes gang submit use case failure.

[How]
Disable gfx IB preemption when it is gang submit.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 4 +++-
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 8 +++++---
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c  | 4 +++-
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c  | 3 ++-
 4 files changed, 13 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +3 -1
index 264183ab24ec..c4506be4d723 100644
@@ -8653,7 +8653,9 @@ static void gfx_v10_0_ring_emit_ib_gfx(struct amdgpu_ring *ring,
 
 	control |= ib->length_dw | (vmid << 24);
 
-	if (ring->adev->gfx.mcbp && (ib->flags & AMDGPU_IB_FLAG_PREEMPT)) {
+	if (ring->adev->gfx.mcbp &&
+		(ib->flags & AMDGPU_IB_FLAG_PREEMPT) &&
+		(job->gang_submit != &job->base.s_fence->scheduled)) {
 		control |= INDIRECT_BUFFER_PRE_ENB(1);
 
 		if (flags & AMDGPU_IB_PREEMPTED)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +5 -3
index 456ba758fa94..725b0e4d9bf8 100644
@@ -2424,7 +2424,7 @@ static int gfx_v11_0_rlc_load_microcode(struct amdgpu_device *adev)
 			if (version_minor == 3)
 				gfx_v11_0_load_rlcp_rlcv_microcode(adev);
 		}
-		
+
 		return 0;
 	}
 
@@ -3872,7 +3872,7 @@ static int gfx_v11_0_cp_compute_load_microcode(struct amdgpu_device *adev)
 	}
 
 	memcpy(fw, fw_data, fw_size);
-	
+
 	amdgpu_bo_kunmap(adev->gfx.mec.mec_fw_obj);
 	amdgpu_bo_unreserve(adev->gfx.mec.mec_fw_obj);
 
@@ -5855,7 +5855,9 @@ static void gfx_v11_0_ring_emit_ib_gfx(struct amdgpu_ring *ring,
 
 	control |= ib->length_dw | (vmid << 24);
 
-	if (ring->adev->gfx.mcbp && (ib->flags & AMDGPU_IB_FLAG_PREEMPT)) {
+	if (ring->adev->gfx.mcbp &&
+		(ib->flags & AMDGPU_IB_FLAG_PREEMPT) &&
+		(job->gang_submit != &job->base.s_fence->scheduled)) {
 		control |= INDIRECT_BUFFER_PRE_ENB(1);
 
 		if (flags & AMDGPU_IB_PREEMPTED)
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +3 -1
index 367449d8061b..843761947b73 100644
@@ -6051,7 +6051,9 @@ static void gfx_v8_0_ring_emit_ib_gfx(struct amdgpu_ring *ring,
 
 	control |= ib->length_dw | (vmid << 24);
 
-	if (amdgpu_sriov_vf(ring->adev) && (ib->flags & AMDGPU_IB_FLAG_PREEMPT)) {
+	if (ring->adev->gfx.mcbp &&
+		(ib->flags & AMDGPU_IB_FLAG_PREEMPT) &&
+		(job->gang_submit != &job->base.s_fence->scheduled)) {
 		control |= INDIRECT_BUFFER_PRE_ENB(1);
 
 		if (!(ib->flags & AMDGPU_IB_FLAG_CE) && vmid)
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +2 -1
index a6ff9a137a83..47b10528e07b 100644
@@ -5420,7 +5420,8 @@ static void gfx_v9_0_ring_emit_ib_gfx(struct amdgpu_ring *ring,
 
 	control |= ib->length_dw | (vmid << 24);
 
-	if (ib->flags & AMDGPU_IB_FLAG_PREEMPT) {
+	if ((ib->flags & AMDGPU_IB_FLAG_PREEMPT) &&
+		(job->gang_submit != &job->base.s_fence->scheduled)) {
 		control |= INDIRECT_BUFFER_PRE_ENB(1);
 
 		if (flags & AMDGPU_IB_PREEMPTED)
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 5 lines · Yifan Zha

[Why]
Gang submit has conflict with IB preemption which will break the synchronization between enginees. Specifically, MCBP is enabled default under SRIOV. It will causes gang submit use case failure.

Gang submit is broken by design on SRIOV.

As long as nobody comes up with an idea to fix this generally I will systematically reject all patches trying to mitigate the situation.

What we could do is to return an error on gang submit under SRIOV.

Quoted 17 lines

[How]
Disable gfx IB preemption when it is gang submit.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 4 +++-
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 8 +++++---
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c  | 4 +++-
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c  | 3 ++-
 4 files changed, 13 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +0 -0
index 264183ab24ec..c4506be4d723 100644

drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c static void gfx_v10_0_ring_emit_ib_gfx(struct amdgpu_ring *ring, · line 8658

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +3 -1
@@ -8653,7 +8653,9 @@ static void gfx_v10_0_ring_emit_ib_gfx(struct amdgpu_ring *ring,
 
 	control |= ib->length_dw | (vmid << 24);
 
-	if (ring->adev->gfx.mcbp && (ib->flags & AMDGPU_IB_FLAG_PREEMPT)) {
+	if (ring->adev->gfx.mcbp &&
+		(ib->flags & AMDGPU_IB_FLAG_PREEMPT) &&
+		(job->gang_submit != &job->base.s_fence->scheduled)) {

That needs to be handled at the higher level.

drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c static int gfx_v11_0_rlc_load_microcode(struct amdgpu_device *adev) · line 2427

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +0 -0
 		control |= INDIRECT_BUFFER_PRE_ENB(1);
 
 		if (flags & AMDGPU_IB_PREEMPTED)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1 -1
index 456ba758fa94..725b0e4d9bf8 100644
@@ -2424,7 +2424,7 @@ static int gfx_v11_0_rlc_load_microcode(struct amdgpu_device *adev)
 			if (version_minor == 3)
 				gfx_v11_0_load_rlcp_rlcv_microcode(adev);
 		}
-		
+

Unrelated white space change.

drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c static int gfx_v11_0_cp_compute_load_microcode(struct amdgpu_device *adev) · line 3875

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1 -1
 		return 0;
 	}
 
@@ -3872,7 +3872,7 @@ static int gfx_v11_0_cp_compute_load_microcode(struct amdgpu_device *adev)
 	}
 
 	memcpy(fw, fw_data, fw_size);
-	
+

Dito.

Regards,
Christian.

Quoted 43 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +3 -1
 	amdgpu_bo_kunmap(adev->gfx.mec.mec_fw_obj);
 	amdgpu_bo_unreserve(adev->gfx.mec.mec_fw_obj);
 
@@ -5855,7 +5855,9 @@ static void gfx_v11_0_ring_emit_ib_gfx(struct amdgpu_ring *ring,
 
 	control |= ib->length_dw | (vmid << 24);
 
-	if (ring->adev->gfx.mcbp && (ib->flags & AMDGPU_IB_FLAG_PREEMPT)) {
+	if (ring->adev->gfx.mcbp &&
+		(ib->flags & AMDGPU_IB_FLAG_PREEMPT) &&
+		(job->gang_submit != &job->base.s_fence->scheduled)) {
 		control |= INDIRECT_BUFFER_PRE_ENB(1);
 
 		if (flags & AMDGPU_IB_PREEMPTED)
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +3 -1
index 367449d8061b..843761947b73 100644
@@ -6051,7 +6051,9 @@ static void gfx_v8_0_ring_emit_ib_gfx(struct amdgpu_ring *ring,
 
 	control |= ib->length_dw | (vmid << 24);
 
-	if (amdgpu_sriov_vf(ring->adev) && (ib->flags & AMDGPU_IB_FLAG_PREEMPT)) {
+	if (ring->adev->gfx.mcbp &&
+		(ib->flags & AMDGPU_IB_FLAG_PREEMPT) &&
+		(job->gang_submit != &job->base.s_fence->scheduled)) {
 		control |= INDIRECT_BUFFER_PRE_ENB(1);
 
 		if (!(ib->flags & AMDGPU_IB_FLAG_CE) && vmid)
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +2 -1
index a6ff9a137a83..47b10528e07b 100644
@@ -5420,7 +5420,8 @@ static void gfx_v9_0_ring_emit_ib_gfx(struct amdgpu_ring *ring,
 
 	control |= ib->length_dw | (vmid << 24);
 
-	if (ib->flags & AMDGPU_IB_FLAG_PREEMPT) {
+	if ((ib->flags & AMDGPU_IB_FLAG_PREEMPT) &&
+		(job->gang_submit != &job->base.s_fence->scheduled)) {
 		control |= INDIRECT_BUFFER_PRE_ENB(1);
 
 		if (flags & AMDGPU_IB_PREEMPTED)