Skip to contentSkip to conversation

drm/amdgpu/sdma6: don't do MMIO in MQD init

PATCH In review Alex Deucher 3 participants 10 messages Jul 7 – Jul 8

Subsystems (3)
lore
Share & tools
lore

Alex Deucher

author maintainer
#0 lore raw

PATCH 1/6 drm/amdgpu/sdma6: don't do MMIO in MQD init

There's no need to read the register, just use the default value.

Assisted-by Claude:claude-opus-4.6
---
 drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c +1 -2
index 96c350d5fef24..8d3bde9fbb426 100644
@@ -860,8 +860,7 @@ static int sdma_v6_0_mqd_init(struct amdgpu_device *adev, void *mqd,
 	m->sdmax_rlcx_rb_rptr_addr_lo = lower_32_bits(wb_gpu_addr);
 	m->sdmax_rlcx_rb_rptr_addr_hi = upper_32_bits(wb_gpu_addr);
 
-	m->sdmax_rlcx_ib_cntl = RREG32_SOC15_IP(GC, sdma_v6_0_get_reg_offset(adev, 0,
-							regSDMA0_QUEUE0_IB_CNTL));
+	m->sdmax_rlcx_ib_cntl = regSDMA0_QUEUE0_IB_CNTL_DEFAULT;
 
 	m->sdmax_rlcx_doorbell_offset =
 		prop->doorbell_index << SDMA0_QUEUE0_DOORBELL_OFFSET__OFFSET__SHIFT;
Signature · 1 line
2.55.0
author maintainer
#1 lore raw

PATCH 2/6 drm/amdgpu/sdma7: don't do MMIO in MQD init

There's no need to read the register, just use the default value.

Assisted-by Claude:claude-opus-4.6
---
 drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c +1 -2
index aee370b2725af..eb27fba285c1a 100644
@@ -886,8 +886,7 @@ static int sdma_v7_0_mqd_init(struct amdgpu_device *adev, void *mqd,
 	m->sdmax_rlcx_rb_rptr_addr_lo = lower_32_bits(wb_gpu_addr);
 	m->sdmax_rlcx_rb_rptr_addr_hi = upper_32_bits(wb_gpu_addr);
 
-	m->sdmax_rlcx_ib_cntl = RREG32_SOC15_IP(GC, sdma_v7_0_get_reg_offset(adev, 0,
-							regSDMA0_QUEUE0_IB_CNTL));
+	m->sdmax_rlcx_ib_cntl = 0x00000100; //regSDMA0_QUEUE0_IB_CNTL_DEFAULT
 
 	m->sdmax_rlcx_doorbell_offset =
 		prop->doorbell_index << SDMA0_QUEUE0_DOORBELL_OFFSET__OFFSET__SHIFT;
Signature · 1 line
2.55.0
author maintainer
#2 lore raw

PATCH 3/6 drm/amdgpu/sdma7.1: don't do MMIO in MQD init

In reply to Alex Deucher

There's no need to read the register, just use the default value.

Assisted-by Claude:claude-opus-4.6
---
 drivers/gpu/drm/amd/amdgpu/sdma_v7_1.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v7_1.c +1 -2
index 3a358a54f7c57..3fb73fd1a568d 100644
@@ -879,8 +879,7 @@ static int sdma_v7_1_mqd_init(struct amdgpu_device *adev, void *mqd,
 	m->sdmax_rlcx_rb_rptr_addr_lo = lower_32_bits(wb_gpu_addr);
 	m->sdmax_rlcx_rb_rptr_addr_hi = upper_32_bits(wb_gpu_addr);
 
-	m->sdmax_rlcx_ib_cntl = RREG32_SOC15_IP(GC, sdma_v7_1_get_reg_offset(adev, 0,
-							regSDMA0_SDMA_QUEUE0_IB_CNTL));
+	m->sdmax_rlcx_ib_cntl = 0x00000100; //regSDMA0_QUEUE0_IB_CNTL_DEFAULT
 
 	m->sdmax_rlcx_doorbell_offset =
 		prop->doorbell_index << SDMA0_SDMA_QUEUE0_DOORBELL_OFFSET__OFFSET__SHIFT;
Signature · 1 line
2.55.0
author maintainer
#3 lore raw

PATCH 4/6 drm/amdgpu: disallow gfxoff around gfx/compute/sdma KQ reset

In reply to Alex Deucher

If the engine is hung, we shouldn't need this since it won't be powered down, but we could potentially have a case where a queue can be preempted, but due to logic errors in the commands, the fence never signals. The engine could potentially go into the off state. Protect against that.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +8 -0
index b5c2d1d4d8839..c8a1aa88a9de0 100644
@@ -137,7 +137,15 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job)
 			s_job->sched->name);
 		/* Stop the scheduler to prevent anybody else from touching the ring buffer. */
 		drm_sched_wqueue_stop(&ring->sched);
+		if (ring->funcs->type == AMDGPU_RING_TYPE_GFX ||
+		    ring->funcs->type == AMDGPU_RING_TYPE_COMPUTE ||
+		    ring->funcs->type == AMDGPU_RING_TYPE_SDMA)
+			amdgpu_gfx_off_ctrl(adev, false);
 		r = amdgpu_ring_reset(ring, job->vmid, job->hw_fence);
+		if (ring->funcs->type == AMDGPU_RING_TYPE_GFX ||
+		    ring->funcs->type == AMDGPU_RING_TYPE_COMPUTE ||
+		    ring->funcs->type == AMDGPU_RING_TYPE_SDMA)
+			amdgpu_gfx_off_ctrl(adev, true);
 		if (!r) {
 			/* Start the scheduler again */
 			drm_sched_wqueue_start(&ring->sched);
Signature · 1 line
2.55.0
#4 lore raw

Re: [PATCH 4/6] drm/amdgpu: disallow gfxoff around gfx/compute/sdma KQ reset

Quoted 5 lines · Alex Deucher

If the engine is hung, we shouldn't need this since it won't be powered down, but we could potentially have a case where a queue can be preempted, but due to logic errors in the commands, the fence never signals. The engine could potentially go into the off state. Protect against that.

On a second thought, is this a real case? If engine already goes to off state, wouldn't everything be reset by default once it comes back?

Thanks,
Lijo

Quoted 26 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 8 ++++++++
  1 file changed, 8 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +8 -0
index b5c2d1d4d8839..c8a1aa88a9de0 100644
@@ -137,7 +137,15 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job)
  			s_job->sched->name);
  		/* Stop the scheduler to prevent anybody else from touching the ring buffer. */
  		drm_sched_wqueue_stop(&ring->sched);
+		if (ring->funcs->type == AMDGPU_RING_TYPE_GFX ||
+		    ring->funcs->type == AMDGPU_RING_TYPE_COMPUTE ||
+		    ring->funcs->type == AMDGPU_RING_TYPE_SDMA)
+			amdgpu_gfx_off_ctrl(adev, false);
  		r = amdgpu_ring_reset(ring, job->vmid, job->hw_fence);
+		if (ring->funcs->type == AMDGPU_RING_TYPE_GFX ||
+		    ring->funcs->type == AMDGPU_RING_TYPE_COMPUTE ||
+		    ring->funcs->type == AMDGPU_RING_TYPE_SDMA)
+			amdgpu_gfx_off_ctrl(adev, true);
  		if (!r) {
  			/* Start the scheduler again */
  			drm_sched_wqueue_start(&ring->sched);
author maintainer
#5 lore raw

RE: [PATCH 4/6] drm/amdgpu: disallow gfxoff around gfx/compute/sdma KQ reset

AMD General

Quoted 11 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Tuesday, July 7, 2026 11:34 AM
To: Deucher, Alexander <[email protected]>; amd- [email protected]
Subject: Re: [PATCH 4/6] drm/amdgpu: disallow gfxoff around gfx/compute/sdma KQ reset

On 07-Jul-26 8:04 PM, Alex Deucher wrote:

Quoted 8 lines
Quoted 5 lines

If the engine is hung, we shouldn't need this since it won't be powered down, but we could potentially have a case where a queue can be preempted, but due to logic errors in the commands, the fence never signals. The engine could potentially go into the off state. Protect against that.

On a second thought, is this a real case? If engine already goes to off state, wouldn't everything be reset by default once it comes back?

I'm not sure if gfxoff will actually enter or not, but consider the case of an IB which is waiting for some memory location. It's just waiting so the queue can be preempted, but when it's resumed, it just goes back to waiting so it needs to be reset even though it's not hung per se because it's fence will never signal. For compute queues at least, we peempt all the queues in the reset handler and then reset the bad queues. In theory there could be a window there where gfxoff entry could happen and then we may access a GC register via MMIO when we reset one of the bad queues.

Alex

Quoted 33 lines

Thanks,
Lijo

drivers/gpu/drm/amd/amdgpu/amdgpu_job.c static enum drm_gpu_sched_stat

Quoted 12 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 8 ++++++++
  1 file changed, 8 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0 -0
index b5c2d1d4d8839..c8a1aa88a9de0 100644
@@ -137,7 +137,15 @@ static enum drm_gpu_sched_stat

amdgpu_job_timedout(struct drm_sched_job *s_job)

drivers/gpu/drm/amd/amdgpu/amdgpu_job.c static enum drm_gpu_sched_stat · line 138

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0 -0
                    s_job->sched->name);
            /* Stop the scheduler to prevent anybody else from touching

the ring buffer. */

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +8 -0
            drm_sched_wqueue_stop(&ring->sched);
+           if (ring->funcs->type == AMDGPU_RING_TYPE_GFX ||
+               ring->funcs->type == AMDGPU_RING_TYPE_COMPUTE ||
+               ring->funcs->type == AMDGPU_RING_TYPE_SDMA)
+                   amdgpu_gfx_off_ctrl(adev, false);
            r = amdgpu_ring_reset(ring, job->vmid, job->hw_fence);
+           if (ring->funcs->type == AMDGPU_RING_TYPE_GFX ||
+               ring->funcs->type == AMDGPU_RING_TYPE_COMPUTE ||
+               ring->funcs->type == AMDGPU_RING_TYPE_SDMA)
+                   amdgpu_gfx_off_ctrl(adev, true);
            if (!r) {
                    /* Start the scheduler again */
                    drm_sched_wqueue_start(&ring->sched);
#6 lore raw

Re: [PATCH 4/6] drm/amdgpu: disallow gfxoff around gfx/compute/sdma KQ reset

Quoted 19 lines · Alexander

AMD General

Quoted 17 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Tuesday, July 7, 2026 11:34 AM
To: Deucher, Alexander <[email protected]>; amd- [email protected]
Subject: Re: [PATCH 4/6] drm/amdgpu: disallow gfxoff around gfx/compute/sdma KQ reset

Quoted 5 lines · Alex Deucher

If the engine is hung, we shouldn't need this since it won't be powered down, but we could potentially have a case where a queue can be preempted, but due to logic errors in the commands, the fence never signals. The engine could potentially go into the off state. Protect against that.

Quoted 5 lines
Quoted 2 lines

On a second thought, is this a real case? If engine already goes to off state, wouldn't everything be reset by default once it comes back?

I'm not sure if gfxoff will actually enter or not, but consider the case of an IB which is waiting for some memory location. It's just waiting so the queue can be preempted, but when it's resumed, it just goes back to waiting so it needs to be reset even though it's not hung per se because it's fence will never signal. For compute queues at least, we peempt all the queues in the reset handler and then reset the bad queues. In theory there could be a window there where gfxoff entry could happen and then we may access a GC register via MMIO when we reset one of the bad queues.

I'm assuming IB execution will be considered as some part of GFX being active. A wakeup from gfxoff requires external intervention, so it's unlikely that it enters gfxoff during the wait. As far as I know, only doorbells could trigger external wakeup.

Thanks,
Lijo

Quoted 36 lines

Alex

Quoted 33 lines

Thanks,
Lijo

drivers/gpu/drm/amd/amdgpu/amdgpu_job.c static enum drm_gpu_sched_stat

Quoted 12 lines
---
   drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 8 ++++++++
   1 file changed, 8 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0 -0
index b5c2d1d4d8839..c8a1aa88a9de0 100644
@@ -137,7 +137,15 @@ static enum drm_gpu_sched_stat

amdgpu_job_timedout(struct drm_sched_job *s_job)

drivers/gpu/drm/amd/amdgpu/amdgpu_job.c static enum drm_gpu_sched_stat · line 138

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0 -0
                     s_job->sched->name);
             /* Stop the scheduler to prevent anybody else from touching

the ring buffer. */

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +8 -0
             drm_sched_wqueue_stop(&ring->sched);
+           if (ring->funcs->type == AMDGPU_RING_TYPE_GFX ||
+               ring->funcs->type == AMDGPU_RING_TYPE_COMPUTE ||
+               ring->funcs->type == AMDGPU_RING_TYPE_SDMA)
+                   amdgpu_gfx_off_ctrl(adev, false);
             r = amdgpu_ring_reset(ring, job->vmid, job->hw_fence);
+           if (ring->funcs->type == AMDGPU_RING_TYPE_GFX ||
+               ring->funcs->type == AMDGPU_RING_TYPE_COMPUTE ||
+               ring->funcs->type == AMDGPU_RING_TYPE_SDMA)
+                   amdgpu_gfx_off_ctrl(adev, true);
             if (!r) {
                     /* Start the scheduler again */
                     drm_sched_wqueue_start(&ring->sched);
#7 lore raw

Re: [PATCH 4/6] drm/amdgpu: disallow gfxoff around gfx/compute/sdma KQ reset

Quoted 26 lines · Lijo
Quoted 22 lines · Alexander

AMD General

Quoted 19 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Tuesday, July 7, 2026 11:34 AM
To: Deucher, Alexander <[email protected]>; amd- [email protected]
Subject: Re: [PATCH 4/6] drm/amdgpu: disallow gfxoff around gfx/compute/sdma KQ reset

Quoted 5 lines · Alex Deucher

If the engine is hung, we shouldn't need this since it won't be powered down, but we could potentially have a case where a queue can be preempted, but due to logic errors in the commands, the fence never signals. The engine could potentially go into the off state. Protect against that.

On a second thought, is this a real case? If engine already goes to off state, wouldn't everything be reset by default once it comes back?

Quoted 7 lines
Quoted 2 lines

I'm not sure if gfxoff will actually enter or not, but consider the case of an IB which is waiting for some memory location. It's just waiting so the queue can be preempted, but when it's resumed, it just goes back to waiting so it needs to be reset even though it's not hung per se because it's fence will never signal. For compute queues at least, we peempt all the queues in the reset handler and then reset the bad queues. In theory there could be a window there where gfxoff entry could happen and then we may access a GC register via MMIO when we reset one of the bad queues.

I'm assuming IB execution will be considered as some part of GFX being active. A wakeup from gfxoff requires external intervention, so it's unlikely that it enters gfxoff during the wait. As far as I know, only doorbells could trigger external wakeup.

Couldn't gfxoff entry happen after MES preempts queues? if we ring the MES doorbell subsequently it should cause gfxoff entry, but in some cases, we do the reset via MMIO.

Alex

Quoted 40 lines

Thanks,
Lijo

Quoted 36 lines

Alex

Quoted 33 lines

Thanks,
Lijo

drivers/gpu/drm/amd/amdgpu/amdgpu_job.c static enum drm_gpu_sched_stat

Quoted 12 lines
---
   drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 8 ++++++++
   1 file changed, 8 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0 -0
index b5c2d1d4d8839..c8a1aa88a9de0 100644
@@ -137,7 +137,15 @@ static enum drm_gpu_sched_stat

amdgpu_job_timedout(struct drm_sched_job *s_job)

drivers/gpu/drm/amd/amdgpu/amdgpu_job.c static enum drm_gpu_sched_stat · line 138

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0 -0
                     s_job->sched->name);
             /* Stop the scheduler to prevent anybody else from touching

the ring buffer. */

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +8 -0
             drm_sched_wqueue_stop(&ring->sched);
+           if (ring->funcs->type == AMDGPU_RING_TYPE_GFX ||
+               ring->funcs->type == AMDGPU_RING_TYPE_COMPUTE ||
+               ring->funcs->type == AMDGPU_RING_TYPE_SDMA)
+                   amdgpu_gfx_off_ctrl(adev, false);
             r = amdgpu_ring_reset(ring, job->vmid, job->hw_fence);
+           if (ring->funcs->type == AMDGPU_RING_TYPE_GFX ||
+               ring->funcs->type == AMDGPU_RING_TYPE_COMPUTE ||
+               ring->funcs->type == AMDGPU_RING_TYPE_SDMA)
+                   amdgpu_gfx_off_ctrl(adev, true);
             if (!r) {
                     /* Start the scheduler again */
                     drm_sched_wqueue_start(&ring->sched);
author maintainer
#8 lore raw

PATCH 5/6 drm/amdgpu: disallow gfxoff around gfx/compute/sdma UQ reset

In reply to Alex Deucher

If the engine is hung, we shouldn't need this since it won't be powered down, but we could potentially have a case where a queue can be preempted, but due to logic errors in the commands, the fence never signals. The engine could potentially go into the off state. Protect against that.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +8 -0
index aa5cc5642e87b..cfdee25a152b5 100644
@@ -141,11 +141,19 @@ static void amdgpu_userq_hang_detect_work(struct work_struct *work)
 						 AMDGPU_RESET_TYPE_PER_QUEUE)) {
 		int r;
 
+		if (queue->queue_type == AMDGPU_HW_IP_GFX ||
+		    queue->queue_type == AMDGPU_HW_IP_COMPUTE ||
+		    queue->queue_type == AMDGPU_HW_IP_DMA)
+			amdgpu_gfx_off_ctrl(adev, false);
 		if (queue->queue_type == AMDGPU_HW_IP_COMPUTE)
 			r = amdgpu_gfx_reset_mes_compute(adev, NULL, NULL,
 							 queue, NULL, NULL);
 		else
 			r = userq_funcs->reset(queue);
+		if (queue->queue_type == AMDGPU_HW_IP_GFX ||
+		    queue->queue_type == AMDGPU_HW_IP_COMPUTE ||
+		    queue->queue_type == AMDGPU_HW_IP_DMA)
+			amdgpu_gfx_off_ctrl(adev, true);
 		if (r)
 			gpu_reset = true;
 	} else {
Signature · 1 line
2.55.0
author maintainer
#9 lore raw

PATCH 6/6 drm/amdkfd: disallow gfxoff around compute/sdma queue reset

In reply to Alex Deucher

If the engine is hung, we shouldn't need this since it won't be powered down, but we could potentially have a case where a queue can be preempted, but due to logic errors in the commands, the fence never signals. The engine could potentially go into the off state. Protect against that.

---
 drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +6 -1
index f6a749fbdd8ee..7edae15adb16e 100644
@@ -473,7 +473,9 @@ static int reset_queues_mes(struct device_queue_manager *dqm, struct queue *q)
 	queue_input.remove_queue_after_reset = false;
 	queue_input.xcc_id = ffs(dqm->dev->xcc_mask) - 1;
 	/* pass the known bad queue info to the reset function */
+	amdgpu_gfx_off_ctrl(adev, false);
 	r = amdgpu_gfx_reset_mes_compute(adev, NULL, NULL, NULL, &num_hung, &queue_input);
+	amdgpu_gfx_off_ctrl(adev, true);
 	if (r)
 		goto fail;
 
@@ -2454,7 +2456,10 @@ static int reset_hung_queues_sdma(struct device_queue_manager *dqm)
 				continue;
 
 			/* Reset engine and check. */
-			if (amdgpu_sdma_reset_engine(dqm->dev->adev, i, false) ||
+			amdgpu_gfx_off_ctrl(dqm->dev->adev, false);
+			r = amdgpu_sdma_reset_engine(dqm->dev->adev, i, false);
+			amdgpu_gfx_off_ctrl(dqm->dev->adev, true);
+			if (r ||
 			    dqm->dev->kfd2kgd->hqd_sdma_get_doorbell(dqm->dev->adev, i, j) ||
 			    !set_sdma_queue_as_reset(dqm, doorbell_off)) {
 				r = -ENOTRECOVERABLE;
Signature · 1 line
2.55.0