Skip to contentSkip to conversation

drm/amdgpu: Fix KIQ fence timeout after GPU reset on GFX v9.4.3

PATCH In review Chenglei Xie 5 participants 18 messages Mar 3 – Mar 16

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

PATCH 1/1 drm/amdgpu: Fix KIQ fence timeout after GPU reset on GFX v9.4.3

After GPU reset, the hardware queue is cleared and all pending fences are lost. However, the fence writeback memory remains stale from before reset, while software continues emitting fences and sync_seq keeps incrementing. This causes amdgpu_fence_emit_polling() to wait for fences that were lost during reset, resulting in -ETIMEDOUT errors.

Fix this by updating the fence writeback memory to match sync_seq after GPU reset in gfx_v9_4_3_xcc_kiq_init_queue(). This aligns the hardware's view of completed fences with software's view of emitted fences, preventing timeouts when waiting for fences that no longer exist.

Change-Id I717df52ed0ef0bb51a6901f218191d9837a77f6f
---
 drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +9 -0
index ad4d442e7345e..6b5fcdd987693 100644
@@ -2135,6 +2135,15 @@ static int gfx_v9_4_3_xcc_kiq_init_queue(struct amdgpu_ring *ring, int xcc_id)
 		gfx_v9_4_3_xcc_kiq_init_register(ring, xcc_id);
 		soc15_grbm_select(adev, 0, 0, 0, 0, GET_INST(GC, xcc_id));
 		mutex_unlock(&adev->srbm_mutex);
+
+		/* Update fence writeback memory to align with software state after reset.
+		 * After GPU reset, the hardware queue is cleared and all pending fences
+		 * are lost. The fence writeback memory may be stale from before reset. To prevent
+		 * waiting for lost fences, update writeback memory to match sync_seq.
+		 * This avoids waiting for lost fences and prevents timeouts.
+		 */
+		 if (ring->fence_drv.cpu_addr)
+			*ring->fence_drv.cpu_addr = cpu_to_le32(ring->fence_drv.sync_seq);
 	} else {
 		memset((void *)mqd, 0, sizeof(struct v9_mqd_allocation));
 		((struct v9_mqd_allocation *)mqd)->dynamic_cu_mask = 0xFFFFFFFF;
Signature · 1 line
2.34.1
#1 lore raw

RE: [PATCH] drm/amdgpu: Fix KIQ fence timeout after GPU reset on GFX v9.4.3 ping for review

[AMD Official Use Only - AMD Internal Distribution Only]

Hi all,

Just a friendly ping on this patch that fixes PLAT-192105 , I'd appreciate a review when you have a chance.

Best regards,
Chenglei

-----Original Message-----
From: Xie, Chenglei <[email protected]>
Sent: Tuesday, March 3, 2026 11:19 AM
To: [email protected]
Cc: Chan, Hing Pong <[email protected]>; Luo, Zhigang <[email protected]>; Zhang, Hawking <[email protected]>; Xie, Chenglei <[email protected]>
Subject: [PATCH] drm/amdgpu: Fix KIQ fence timeout after GPU reset on GFX v9.4.3

After GPU reset, the hardware queue is cleared and all pending fences are lost. However, the fence writeback memory remains stale from before reset, while software continues emitting fences and sync_seq keeps incrementing. This causes amdgpu_fence_emit_polling() to wait for fences that were lost during reset, resulting in -ETIMEDOUT errors.

Fix this by updating the fence writeback memory to match sync_seq after GPU reset in gfx_v9_4_3_xcc_kiq_init_queue(). This aligns the hardware's view of completed fences with software's view of emitted fences, preventing timeouts when waiting for fences that no longer exist.

Change-Id I717df52ed0ef0bb51a6901f218191d9837a77f6f
---
 drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +9 -0
index ad4d442e7345e..6b5fcdd987693 100644
@@ -2135,6 +2135,15 @@ static int gfx_v9_4_3_xcc_kiq_init_queue(struct amdgpu_ring *ring, int xcc_id)
                gfx_v9_4_3_xcc_kiq_init_register(ring, xcc_id);
                soc15_grbm_select(adev, 0, 0, 0, 0, GET_INST(GC, xcc_id));
                mutex_unlock(&adev->srbm_mutex);
+
+               /* Update fence writeback memory to align with software state after reset.
+                * After GPU reset, the hardware queue is cleared and all pending fences
+                * are lost. The fence writeback memory may be stale from before reset. To prevent
+                * waiting for lost fences, update writeback memory to match sync_seq.
+                * This avoids waiting for lost fences and prevents timeouts.
+                */
+                if (ring->fence_drv.cpu_addr)
+                       *ring->fence_drv.cpu_addr = cpu_to_le32(ring->fence_drv.sync_seq);
        } else {
                memset((void *)mqd, 0, sizeof(struct v9_mqd_allocation));
                ((struct v9_mqd_allocation *)mqd)->dynamic_cu_mask = 0xFFFFFFFF;

--
2.34.1

#2 lore raw
In reply to Chenglei Xie
Quoted 23 lines · Chenglei Xie

After GPU reset, the hardware queue is cleared and all pending fences are lost. However, the fence writeback memory remains stale from before reset, while software continues emitting fences and sync_seq keeps incrementing. This causes amdgpu_fence_emit_polling() to wait for fences that were lost during reset, resulting in -ETIMEDOUT errors.

Fix this by updating the fence writeback memory to match sync_seq after GPU reset in gfx_v9_4_3_xcc_kiq_init_queue(). This aligns the hardware's view of completed fences with software's view of emitted fences, preventing timeouts when waiting for fences that no longer exist.

Change-Id I717df52ed0ef0bb51a6901f218191d9837a77f6f
---
 drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +0 -0
index ad4d442e7345e..6b5fcdd987693 100644

drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c static int gfx_v9_4_3_xcc_kiq_init_queue(struct amdgpu_ring *ring, int xcc_id) · line 2144

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +7 -0
@@ -2135,6 +2135,15 @@ static int gfx_v9_4_3_xcc_kiq_init_queue(struct amdgpu_ring *ring, int xcc_id)
                gfx_v9_4_3_xcc_kiq_init_register(ring, xcc_id);
                soc15_grbm_select(adev, 0, 0, 0, 0, GET_INST(GC, xcc_id));
                mutex_unlock(&adev->srbm_mutex);
+
+               /* Update fence writeback memory to align with software state after reset.
+                * After GPU reset, the hardware queue is cleared and all pending fences
+                * are lost. The fence writeback memory may be stale from before reset. To prevent
+                * waiting for lost fences, update writeback memory to match sync_seq.
+                * This avoids waiting for lost fences and prevents timeouts.
+                */

This doesn't make sense. No other kiq_init_queue() function does this. When the GPU is reset, amdgpu_fence_driver_force_completion() should get called for each ring. That will set an error on the fence and update the fence sequence. Why is that not working?

Alex

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +2 -1
+                if (ring->fence_drv.cpu_addr)
+                       *ring->fence_drv.cpu_addr = cpu_to_le32(ring->fence_drv.sync_seq);
        } else {
                memset((void *)mqd, 0, sizeof(struct v9_mqd_allocation));
                ((struct v9_mqd_allocation *)mqd)->dynamic_cu_mask = 0xFFFFFFFF;
--

2.34.1

#3 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

Hi Alex,

amdgpu_fence_driver_force_completion() is working but it was called prior to GPU reset.

However, in this failing case, during a GPU reset, the KIQ ring is still used (e.g. for HDP flush in amdgpu_kiq_hdp_flush()). Each of those submissions emits a fence and increments sync_seq. The hardware queue is later cleared by the reset and never runs those commands, so it never updates the fence writeback location. After reset, the writeback memory still holds the last value written before reset while sync_seq has moved far ahead.

Before emitting a new fence, amdgpu_fence_emit_polling() waits until the oldest in-flight fence is done: it calls amdgpu_fence_wait_polling(ring, seq - ring->fence_drv.num_fences_mask, timeout), which busy waits until the writeback value is at least that sequence. Because the writeback value is still near the pre-reset value and sync_seq has grown, the required sequence (sync_seq - num_fences_mask) is much larger than the writeback value. The driver therefore waits for completion of fences that were lost in the reset and will never complete, the wait hits the timeout, and amdgpu_fence_emit_polling() returns -ETIMEDOUT. The driver then refuses to emit new KIQ fences, assuming the ring is full, and KIQ submissions effectively stall.

To fix this, when re-initializing the KIQ after a reset, the code now sets the fence writeback memory to sync_seq. So it no longer waits for those lost fences. amdgpu_fence_emit_polling() can then emit new fences without timing out, and KIQ usage resumes after reset.

Regards,
Chenglei
-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Friday, March 6, 2026 11:18 AM
To: Xie, Chenglei <[email protected]>
Cc: [email protected]; Chan, Hing Pong <[email protected]>; Luo, Zhigang <[email protected]>; Zhang, Hawking <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: Fix KIQ fence timeout after GPU reset on GFX v9.4.3

[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

Quoted 24 lines · Chenglei Xie

After GPU reset, the hardware queue is cleared and all pending fences are lost. However, the fence writeback memory remains stale from before reset, while software continues emitting fences and sync_seq keeps incrementing. This causes amdgpu_fence_emit_polling() to wait for fences that were lost during reset, resulting in -ETIMEDOUT errors.

Fix this by updating the fence writeback memory to match sync_seq after GPU reset in gfx_v9_4_3_xcc_kiq_init_queue(). This aligns the hardware's view of completed fences with software's view of emitted fences, preventing timeouts when waiting for fences that no longer exist.

Change-Id I717df52ed0ef0bb51a6901f218191d9837a77f6f
---
 drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +0 -0
index ad4d442e7345e..6b5fcdd987693 100644

drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c static int gfx_v9_4_3_xcc_kiq_init_queue(struct amdgpu_ring *ring, int xcc_id) · line 2144

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +7 -0
@@ -2135,6 +2135,15 @@ static int gfx_v9_4_3_xcc_kiq_init_queue(struct amdgpu_ring *ring, int xcc_id)
                gfx_v9_4_3_xcc_kiq_init_register(ring, xcc_id);
                soc15_grbm_select(adev, 0, 0, 0, 0, GET_INST(GC, xcc_id));
                mutex_unlock(&adev->srbm_mutex);
+
+               /* Update fence writeback memory to align with software state after reset.
+                * After GPU reset, the hardware queue is cleared and all pending fences
+                * are lost. The fence writeback memory may be stale from before reset. To prevent
+                * waiting for lost fences, update writeback memory to match sync_seq.
+                * This avoids waiting for lost fences and prevents timeouts.
+                */

This doesn't make sense. No other kiq_init_queue() function does this. When the GPU is reset, amdgpu_fence_driver_force_completion() should get called for each ring. That will set an error on the fence and update the fence sequence. Why is that not working?

Alex

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +3 -0
+                if (ring->fence_drv.cpu_addr)
+                       *ring->fence_drv.cpu_addr =
+ cpu_to_le32(ring->fence_drv.sync_seq);
        } else {
                memset((void *)mqd, 0, sizeof(struct v9_mqd_allocation));
                ((struct v9_mqd_allocation *)mqd)->dynamic_cu_mask =

0xFFFFFFFF;
--
2.34.1

#4 lore raw
Quoted 8 lines · Chenglei

[AMD Official Use Only - AMD Internal Distribution Only]

Hi Alex,

amdgpu_fence_driver_force_completion() is working but it was called prior to GPU reset.

However, in this failing case, during a GPU reset, the KIQ ring is still used (e.g. for HDP flush in amdgpu_kiq_hdp_flush()). Each of those submissions emits a fence and increments sync_seq. The hardware queue is later cleared by the reset and never runs those commands, so it never updates the fence writeback location. After reset, the writeback memory still holds the last value written before reset while sync_seq has moved far ahead.

Sounds like a bug in the reset sequence. We should fix that so that we don't use KIQ during the reset.

Alex

Quoted 67 lines

Before emitting a new fence, amdgpu_fence_emit_polling() waits until the oldest in-flight fence is done: it calls amdgpu_fence_wait_polling(ring, seq - ring->fence_drv.num_fences_mask, timeout), which busy waits until the writeback value is at least that sequence. Because the writeback value is still near the pre-reset value and sync_seq has grown, the required sequence (sync_seq - num_fences_mask) is much larger than the writeback value. The driver therefore waits for completion of fences that were lost in the reset and will never complete, the wait hits the timeout, and amdgpu_fence_emit_polling() returns -ETIMEDOUT. The driver then refuses to emit new KIQ fences, assuming the ring is full, and KIQ submissions effectively stall.

To fix this, when re-initializing the KIQ after a reset, the code now sets the fence writeback memory to sync_seq. So it no longer waits for those lost fences. amdgpu_fence_emit_polling() can then emit new fences without timing out, and KIQ usage resumes after reset.

Regards,
Chenglei
-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Friday, March 6, 2026 11:18 AM
To: Xie, Chenglei <[email protected]>
Cc: [email protected]; Chan, Hing Pong <[email protected]>; Luo, Zhigang <[email protected]>; Zhang, Hawking <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: Fix KIQ fence timeout after GPU reset on GFX v9.4.3

[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

Quoted 24 lines · Chenglei Xie

After GPU reset, the hardware queue is cleared and all pending fences are lost. However, the fence writeback memory remains stale from before reset, while software continues emitting fences and sync_seq keeps incrementing. This causes amdgpu_fence_emit_polling() to wait for fences that were lost during reset, resulting in -ETIMEDOUT errors.

Fix this by updating the fence writeback memory to match sync_seq after GPU reset in gfx_v9_4_3_xcc_kiq_init_queue(). This aligns the hardware's view of completed fences with software's view of emitted fences, preventing timeouts when waiting for fences that no longer exist.

Change-Id I717df52ed0ef0bb51a6901f218191d9837a77f6f
---
 drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +0 -0
index ad4d442e7345e..6b5fcdd987693 100644

drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c static int gfx_v9_4_3_xcc_kiq_init_queue(struct amdgpu_ring *ring, int xcc_id) · line 2144

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +7 -0
@@ -2135,6 +2135,15 @@ static int gfx_v9_4_3_xcc_kiq_init_queue(struct amdgpu_ring *ring, int xcc_id)
                gfx_v9_4_3_xcc_kiq_init_register(ring, xcc_id);
                soc15_grbm_select(adev, 0, 0, 0, 0, GET_INST(GC, xcc_id));
                mutex_unlock(&adev->srbm_mutex);
+
+               /* Update fence writeback memory to align with software state after reset.
+                * After GPU reset, the hardware queue is cleared and all pending fences
+                * are lost. The fence writeback memory may be stale from before reset. To prevent
+                * waiting for lost fences, update writeback memory to match sync_seq.
+                * This avoids waiting for lost fences and prevents timeouts.
+                */

This doesn't make sense. No other kiq_init_queue() function does this. When the GPU is reset, amdgpu_fence_driver_force_completion() should get called for each ring. That will set an error on the fence and update the fence sequence. Why is that not working?

Alex

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +3 -0
+                if (ring->fence_drv.cpu_addr)
+                       *ring->fence_drv.cpu_addr =
+ cpu_to_le32(ring->fence_drv.sync_seq);
        } else {
                memset((void *)mqd, 0, sizeof(struct v9_mqd_allocation));
                ((struct v9_mqd_allocation *)mqd)->dynamic_cu_mask =

0xFFFFFFFF;
--
2.34.1

#5 lore raw

PATCH v2 1/1 drm/amdgpu: Avoid KIQ ring access during GPU reset to fix fence timeout

In reply to Alex Deucher

After GPU reset, the hardware queue is cleared and all pending fences are lost, but the fence writeback memory stays stale. If the driver keeps submitting to the KIQ ring during reset (e.g. HDP flush), sync_seq advances while writeback does not, so amdgpu_fence_emit_polling() waits for lost fences and hits -ETIMEDOUT, blocking further KIQ use.

Fix this by skipping KIQ ring use when in reset.

Change-Id I717df52ed0ef0bb51a6901f218191d9837a77f6f
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 10 ++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c |  3 +++
 2 files changed, 13 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +10 -0
index cab3196a87fb1..0021e763b753a 100644
@@ -1124,6 +1124,9 @@ uint32_t amdgpu_kiq_rreg(struct amdgpu_device *adev, uint32_t reg, uint32_t xcc_
 	if (adev->mes.ring[0].sched.ready)
 		return amdgpu_mes_rreg(adev, reg, xcc_id);
 
+	if (amdgpu_in_reset(adev))
+		return ~0;
+
 	BUG_ON(!ring->funcs->emit_rreg);
 
 	spin_lock_irqsave(&kiq->ring_lock, flags);
@@ -1202,6 +1205,9 @@ void amdgpu_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v, uint3
 		return;
 	}
 
+	if (amdgpu_in_reset(adev))
+		return;
+
 	spin_lock_irqsave(&kiq->ring_lock, flags);
 	r = amdgpu_ring_alloc(ring, 32);
 	if (r)
@@ -1298,6 +1304,10 @@ int amdgpu_kiq_hdp_flush(struct amdgpu_device *adev)
 	if (adev->enable_mes_kiq && adev->mes.ring[0].sched.ready)
 		return amdgpu_mes_hdp_flush(adev);
 
+	/* Avoid KIQ ring access during reset; caller will use amdgpu_hdp_flush fallback */
+	if (amdgpu_in_reset(adev))
+		return -EBUSY;
+
 	if (!ring->funcs->emit_hdp_flush) {
 		return -EOPNOTSUPP;
 	}
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +3 -0
index 20e1395b39882..f9db2b17105b7 100644
@@ -876,6 +876,9 @@ void amdgpu_gmc_fw_reg_write_reg_wait(struct amdgpu_device *adev,
 		return;
 	}
 
+	if (amdgpu_in_reset(adev))
+		return;
+
 	spin_lock_irqsave(&kiq->ring_lock, flags);
 	amdgpu_ring_alloc(ring, 32);
 	amdgpu_ring_emit_reg_write_reg_wait(ring, reg0, reg1,
Signature · 1 line
2.34.1
#6 lore raw

RE: [PATCH v2] drm/amdgpu: Avoid KIQ ring access during GPU reset to fix fence timeout

[AMD Official Use Only - AMD Internal Distribution Only]

Hi Alex,

I updated the patch that skips KIQ ring access during reset to fix the issue. Please help review, thanks!

Regards,
Chenglei

-----Original Message-----
From: Xie, Chenglei <[email protected]>
Sent: Monday, March 9, 2026 1:10 PM
To: Deucher, Alexander <[email protected]>
Cc: Chan, Hing Pong <[email protected]>; Luo, Zhigang <[email protected]>; [email protected]; Xie, Chenglei <[email protected]>
Subject: [PATCH v2] drm/amdgpu: Avoid KIQ ring access during GPU reset to fix fence timeout

After GPU reset, the hardware queue is cleared and all pending fences are lost, but the fence writeback memory stays stale. If the driver keeps submitting to the KIQ ring during reset (e.g. HDP flush), sync_seq advances while writeback does not, so amdgpu_fence_emit_polling() waits for lost fences and hits -ETIMEDOUT, blocking further KIQ use.

Fix this by skipping KIQ ring use when in reset.

Change-Id I717df52ed0ef0bb51a6901f218191d9837a77f6f
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 10 ++++++++++  drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c |  3 +++
 2 files changed, 13 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +3 -0
index cab3196a87fb1..0021e763b753a 100644
@@ -1124,6 +1124,9 @@ uint32_t amdgpu_kiq_rreg(struct amdgpu_device *adev, uint32_t reg, uint32_t xcc_
        if (adev->mes.ring[0].sched.ready)
                return amdgpu_mes_rreg(adev, reg, xcc_id);
 
+       if (amdgpu_in_reset(adev))
+               return ~0;
+
        BUG_ON(!ring->funcs->emit_rreg);
 
        spin_lock_irqsave(&kiq->ring_lock, flags); @@ -1202,6 +1205,9 @@ void amdgpu_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v, uint3
                return;
        }

+ if (amdgpu_in_reset(adev))
+ return;
+

        spin_lock_irqsave(&kiq->ring_lock, flags);
        r = amdgpu_ring_alloc(ring, 32);
        if (r)
@@ -1298,6 +1304,10 @@ int amdgpu_kiq_hdp_flush(struct amdgpu_device *adev)
        if (adev->enable_mes_kiq && adev->mes.ring[0].sched.ready)
                return amdgpu_mes_hdp_flush(adev);

+ /* Avoid KIQ ring access during reset; caller will use amdgpu_hdp_flush fallback */
+ if (amdgpu_in_reset(adev))
+ return -EBUSY;
+

        if (!ring->funcs->emit_hdp_flush) {
                return -EOPNOTSUPP;
        }
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +3 -0
index 20e1395b39882..f9db2b17105b7 100644
@@ -876,6 +876,9 @@ void amdgpu_gmc_fw_reg_write_reg_wait(struct amdgpu_device *adev,
                return;
        }
 
+       if (amdgpu_in_reset(adev))
+               return;
+
        spin_lock_irqsave(&kiq->ring_lock, flags);
        amdgpu_ring_alloc(ring, 32);
        amdgpu_ring_emit_reg_write_reg_wait(ring, reg0, reg1,

--
2.34.1

maintainer Acked-by on v2 1/1
#7 lore raw

RE: [PATCH v2] drm/amdgpu: Avoid KIQ ring access during GPU reset to fix fence timeout

In reply to Chenglei Xie

[Public]

Quoted 16 lines

-----Original Message-----
From: Xie, Chenglei <[email protected]>
Sent: Monday, March 9, 2026 1:10 PM
To: Deucher, Alexander <[email protected]>
Cc: Chan, Hing Pong <[email protected]>; Luo, Zhigang <[email protected]>; [email protected]; Xie, Chenglei <[email protected]>
Subject: [PATCH v2] drm/amdgpu: Avoid KIQ ring access during GPU reset to fix fence timeout

After GPU reset, the hardware queue is cleared and all pending fences are lost, but the fence writeback memory stays stale. If the driver keeps submitting to the KIQ ring during reset (e.g. HDP flush), sync_seq advances while writeback does not, so amdgpu_fence_emit_polling() waits for lost fences and hits - ETIMEDOUT, blocking further KIQ use.

Quoted 3 lines

Fix this by skipping KIQ ring use when in reset.

Quoted 64 lines

Change-Id: I717df52ed0ef0bb51a6901f218191d9837a77f6f

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 10 ++++++++++
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c |  3 +++
 2 files changed, 13 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +3 -0
index cab3196a87fb1..0021e763b753a 100644
@@ -1124,6 +1124,9 @@ uint32_t amdgpu_kiq_rreg(struct amdgpu_device
 *adev, uint32_t reg, uint32_t xcc_
      if (adev->mes.ring[0].sched.ready)
              return amdgpu_mes_rreg(adev, reg, xcc_id);
 
+     if (amdgpu_in_reset(adev))
+             return ~0;
+
      BUG_ON(!ring->funcs->emit_rreg);
 
      spin_lock_irqsave(&kiq->ring_lock, flags); @@ -1202,6 +1205,9 @@
void amdgpu_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v,
uint3
              return;
      }
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +4 -0
+     if (amdgpu_in_reset(adev))
+             return;
+
      spin_lock_irqsave(&kiq->ring_lock, flags);
      r = amdgpu_ring_alloc(ring, 32);
      if (r)
@@ -1298,6 +1304,10 @@ int amdgpu_kiq_hdp_flush(struct
 amdgpu_device *adev)
      if (adev->enable_mes_kiq && adev->mes.ring[0].sched.ready)
              return amdgpu_mes_hdp_flush(adev);
 
+     /* Avoid KIQ ring access during reset; caller will use

amdgpu_hdp_flush fallback */

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +3 -0
+     if (amdgpu_in_reset(adev))
+             return -EBUSY;
+
      if (!ring->funcs->emit_hdp_flush) {
              return -EOPNOTSUPP;
      }
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +3 -0
index 20e1395b39882..f9db2b17105b7 100644
@@ -876,6 +876,9 @@ void amdgpu_gmc_fw_reg_write_reg_wait(struct
 amdgpu_device *adev,
              return;
      }
 
+     if (amdgpu_in_reset(adev))
+             return;
+
      spin_lock_irqsave(&kiq->ring_lock, flags);
      amdgpu_ring_alloc(ring, 32);

amdgpu_ring_emit_reg_write_reg_wait(ring, reg0, reg1,
--
2.34.1

#8 lore raw

Re: [PATCH v2] drm/amdgpu: Avoid KIQ ring access during GPU reset to fix fence timeout

In reply to Chenglei Xie
Quoted 22 lines · Chenglei Xie

[Some people who received this message don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

After GPU reset, the hardware queue is cleared and all pending fences are lost, but the fence writeback memory stays stale. If the driver keeps submitting to the KIQ ring during reset (e.g. HDP flush), sync_seq advances while writeback does not, so amdgpu_fence_emit_polling() waits for lost fences and hits -ETIMEDOUT, blocking further KIQ use.

Fix this by skipping KIQ ring use when in reset.

Change-Id I717df52ed0ef0bb51a6901f218191d9837a77f6f
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 10 ++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c |  3 +++
  2 files changed, 13 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +0 -0
index cab3196a87fb1..0021e763b753a 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c uint32_t amdgpu_kiq_rreg(struct amdgpu_device *adev, uint32_t reg, uint32_t xcc_ · line 1129

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +3 -0
@@ -1124,6 +1124,9 @@ uint32_t amdgpu_kiq_rreg(struct amdgpu_device *adev, uint32_t reg, uint32_t xcc_
         if (adev->mes.ring[0].sched.ready)
                 return amdgpu_mes_rreg(adev, reg, xcc_id);
 
+       if (amdgpu_in_reset(adev))
+               return ~0;
+

Please note that the existing logic assumes that kiq access will work fine even during reset and only could fail under certain reset situations (not all) -

https://github.com/torvalds/linux/blob/master/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c#L1107

Also, there are additional things done after full access is released -

https://github.com/torvalds/linux/blob/master/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c#L5610

May be it needs a force completion at the right place somewhere in amdgpu_device_reset_sriov() as Alex suggested and not to simply block all KIQ based reg accesses during reset. In baremetal case, it is done during pre-reset as we don't expect any more packet submission/indirect register accesses through kernel rings afterwards.

Thanks,
Lijo

Quoted 41 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +7 -0
         BUG_ON(!ring->funcs->emit_rreg);
 
         spin_lock_irqsave(&kiq->ring_lock, flags);
@@ -1202,6 +1205,9 @@ void amdgpu_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v, uint3
                 return;
         }
 
+       if (amdgpu_in_reset(adev))
+               return;
+
         spin_lock_irqsave(&kiq->ring_lock, flags);
         r = amdgpu_ring_alloc(ring, 32);
         if (r)
@@ -1298,6 +1304,10 @@ int amdgpu_kiq_hdp_flush(struct amdgpu_device *adev)
         if (adev->enable_mes_kiq && adev->mes.ring[0].sched.ready)
                 return amdgpu_mes_hdp_flush(adev);
 
+       /* Avoid KIQ ring access during reset; caller will use amdgpu_hdp_flush fallback */
+       if (amdgpu_in_reset(adev))
+               return -EBUSY;
+
         if (!ring->funcs->emit_hdp_flush) {
                 return -EOPNOTSUPP;
         }
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +3 -1
index 20e1395b39882..f9db2b17105b7 100644
@@ -876,6 +876,9 @@ void amdgpu_gmc_fw_reg_write_reg_wait(struct amdgpu_device *adev,
                 return;
         }
 
+       if (amdgpu_in_reset(adev))
+               return;
+
         spin_lock_irqsave(&kiq->ring_lock, flags);
         amdgpu_ring_alloc(ring, 32);
         amdgpu_ring_emit_reg_write_reg_wait(ring, reg0, reg1,
--

2.34.1

#9 lore raw

RE: [PATCH v2] drm/amdgpu: Avoid KIQ ring access during GPU reset to fix fence timeout

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 24 lines
  drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 10 ++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c |  3 +++
  2 files changed, 13 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +3 -0
index cab3196a87fb1..0021e763b753a 100644
@@ -1124,6 +1124,9 @@ uint32_t amdgpu_kiq_rreg(struct amdgpu_device *adev, uint32_t reg, uint32_t xcc_
         if (adev->mes.ring[0].sched.ready)
                 return amdgpu_mes_rreg(adev, reg, xcc_id);
 
+       if (amdgpu_in_reset(adev))
+               return ~0;
+
 

Please note that the existing logic assumes that kiq access will work fine even during reset and only could fail under certain reset situations (not all) -

https://github.com/torvalds/linux/blob/master/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c#L1107

Also, there are additional things done after full access is released -

Quoted 7 lines

https://github.com/torvalds/linux/blob/master/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c#L5610

May be it needs a force completion at the right place somewhere in
amdgpu_device_reset_sriov() as Alex suggested and not to simply block all KIQ based reg accesses during reset. In baremetal case, it is done during pre-reset as we don't expect any more packet submission/indirect register accesses through kernel rings afterwards.

Thanks,
Lijo

Chenglei: After the in_gpu_reset flag is set in the KIQ paths, the current logic allows a short window of time when HW and KIQ can still run to process packets before the HW actually start reset. But once the HW reset stared, HW would stop processing and new jobs in the KIQ ring would fail because of that.

If we want to avoid blocking all kiq access during reset, we can have amdgpu_fence_driver_force_completion() called in amdgpu_device_reset_sriov() after -
https://github.com/torvalds/linux/blob/master/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c#L5586
where the rings are re-inited.

Also, the current logic in amdgpu_device_pre_asic_reset() skips rings without gpu scheduler -
https://github.com/torvalds/linux/blob/master/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c#L5810
https://github.com/torvalds/linux/blob/master/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c#L862
So that KIQ rings are skipped and never got force_completion before reset.

Issue should be fixed if we force completion on all possible rings on both pre reset(both SRIOV and BM) and post rest(SRIOV only). I will send out new patch based on this.

Thanks,
Chenglei

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Tuesday, March 10, 2026 2:40 AM
To: Xie, Chenglei <[email protected]>; Deucher, Alexander <[email protected]>
Cc: Chan, Hing Pong <[email protected]>; Luo, Zhigang <[email protected]>; [email protected]
Subject: Re: [PATCH v2] drm/amdgpu: Avoid KIQ ring access during GPU reset to fix fence timeout

Quoted 25 lines · Chenglei Xie

[Some people who received this message don't often get email from [email protected]. Learn why this is important at
https://aka.ms/LearnAboutSenderIdentification ]

After GPU reset, the hardware queue is cleared and all pending fences
are lost, but the fence writeback memory stays stale. If the driver
keeps submitting to the KIQ ring during reset (e.g. HDP flush),
sync_seq advances while writeback does not, so
amdgpu_fence_emit_polling() waits for lost fences and hits -ETIMEDOUT, blocking further KIQ use.

Fix this by skipping KIQ ring use when in reset.

Change-Id I717df52ed0ef0bb51a6901f218191d9837a77f6f
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 10 ++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c |  3 +++
  2 files changed, 13 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +0 -0
index cab3196a87fb1..0021e763b753a 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c uint32_t amdgpu_kiq_rreg(struct amdgpu_device *adev, uint32_t reg, uint32_t xcc_ · line 1129

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +3 -0
@@ -1124,6 +1124,9 @@ uint32_t amdgpu_kiq_rreg(struct amdgpu_device *adev, uint32_t reg, uint32_t xcc_
         if (adev->mes.ring[0].sched.ready)
                 return amdgpu_mes_rreg(adev, reg, xcc_id);
 
+       if (amdgpu_in_reset(adev))
+               return ~0;
+

Please note that the existing logic assumes that kiq access will work fine even during reset and only could fail under certain reset situations (not all) -

https://github.com/torvalds/linux/blob/master/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c#L1107

Also, there are additional things done after full access is released -

https://github.com/torvalds/linux/blob/master/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c#L5610

May be it needs a force completion at the right place somewhere in
amdgpu_device_reset_sriov() as Alex suggested and not to simply block all KIQ based reg accesses during reset. In baremetal case, it is done during pre-reset as we don't expect any more packet submission/indirect register accesses through kernel rings afterwards.

Thanks,
Lijo

Quoted 42 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +0 -0
         BUG_ON(!ring->funcs->emit_rreg);
 
         spin_lock_irqsave(&kiq->ring_lock, flags); @@ -1202,6 +1205,9

@@ void amdgpu_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v, uint3

                 return;
         }
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +7 -0
+       if (amdgpu_in_reset(adev))
+               return;
+
         spin_lock_irqsave(&kiq->ring_lock, flags);
         r = amdgpu_ring_alloc(ring, 32);
         if (r)
@@ -1298,6 +1304,10 @@ int amdgpu_kiq_hdp_flush(struct amdgpu_device *adev)
         if (adev->enable_mes_kiq && adev->mes.ring[0].sched.ready)
                 return amdgpu_mes_hdp_flush(adev);
 
+       /* Avoid KIQ ring access during reset; caller will use amdgpu_hdp_flush fallback */
+       if (amdgpu_in_reset(adev))
+               return -EBUSY;
+
         if (!ring->funcs->emit_hdp_flush) {
                 return -EOPNOTSUPP;
         }
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +3 -1
index 20e1395b39882..f9db2b17105b7 100644
@@ -876,6 +876,9 @@ void amdgpu_gmc_fw_reg_write_reg_wait(struct amdgpu_device *adev,
                 return;
         }
 
+       if (amdgpu_in_reset(adev))
+               return;
+
         spin_lock_irqsave(&kiq->ring_lock, flags);
         amdgpu_ring_alloc(ring, 32);
         amdgpu_ring_emit_reg_write_reg_wait(ring, reg0, reg1,
--

2.34.1

#10 lore raw

Re: [PATCH v2] drm/amdgpu: Avoid KIQ ring access during GPU reset to fix fence timeout

Quoted 28 lines · Chenglei

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 26 lines
   drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 10 ++++++++++
   drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c |  3 +++
   2 files changed, 13 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +3 -0
index cab3196a87fb1..0021e763b753a 100644
@@ -1124,6 +1124,9 @@ uint32_t amdgpu_kiq_rreg(struct amdgpu_device *adev, uint32_t reg, uint32_t xcc_
          if (adev->mes.ring[0].sched.ready)
                  return amdgpu_mes_rreg(adev, reg, xcc_id);
 
+       if (amdgpu_in_reset(adev))
+               return ~0;
+
 

Please note that the existing logic assumes that kiq access will work fine even during reset and only could fail under certain reset situations (not all) -

https://github.com/torvalds/linux/blob/master/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c#L1107

Also, there are additional things done after full access is released -

https://github.com/torvalds/linux/blob/master/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c#L5610

Quoted 8 lines
Quoted 5 lines

May be it needs a force completion at the right place somewhere in
amdgpu_device_reset_sriov() as Alex suggested and not to simply block all KIQ based reg accesses during reset. In baremetal case, it is done during pre-reset as we don't expect any more packet submission/indirect register accesses through kernel rings afterwards.

Thanks,
Lijo

Chenglei: After the in_gpu_reset flag is set in the KIQ paths, the current logic allows a short window of time when HW and KIQ can still run to process packets before the HW actually start reset. But once the HW reset stared, HW would stop processing and new jobs in the KIQ ring would fail because of that.

Do you know the source for those ring submissions? I think it's not expected to happen once host driver driver is notified.

Quoted 4 lines

If we want to avoid blocking all kiq access during reset, we can have amdgpu_fence_driver_force_completion() called in amdgpu_device_reset_sriov() after -
https://github.com/torvalds/linux/blob/master/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c#L5586
where the rings are re-inited.

I was thinking more like forcing kiq fence completion right after host driver is notified. Ideally, no submission is expected after that. You may also return from KIQ reg read/write paths if runtime service is disabled. I'm assuming they are supposed to be used only at that time.

Quoted 6 lines

Also, the current logic in amdgpu_device_pre_asic_reset() skips rings without gpu scheduler -
https://github.com/torvalds/linux/blob/master/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c#L5810
https://github.com/torvalds/linux/blob/master/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c#L862
So that KIQ rings are skipped and never got force_completion before reset.

Issue should be fixed if we force completion on all possible rings on both pre reset(both SRIOV and BM) and post rest(SRIOV only). I will send out new patch based on this.

I think you should trace the source of submission while HW reset is ongoing. Ideally force completion should be done before reset even in SRIOV case.

Thanks,
Lijo

Quoted 103 lines

Thanks,
Chenglei

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Tuesday, March 10, 2026 2:40 AM
To: Xie, Chenglei <[email protected]>; Deucher, Alexander <[email protected]>
Cc: Chan, Hing Pong <[email protected]>; Luo, Zhigang <[email protected]>; [email protected]
Subject: Re: [PATCH v2] drm/amdgpu: Avoid KIQ ring access during GPU reset to fix fence timeout

Quoted 25 lines · Chenglei Xie

[Some people who received this message don't often get email from [email protected]. Learn why this is important at
https://aka.ms/LearnAboutSenderIdentification ]

After GPU reset, the hardware queue is cleared and all pending fences
are lost, but the fence writeback memory stays stale. If the driver
keeps submitting to the KIQ ring during reset (e.g. HDP flush),
sync_seq advances while writeback does not, so
amdgpu_fence_emit_polling() waits for lost fences and hits -ETIMEDOUT, blocking further KIQ use.

Fix this by skipping KIQ ring use when in reset.

Change-Id I717df52ed0ef0bb51a6901f218191d9837a77f6f
---
   drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 10 ++++++++++
   drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c |  3 +++
   2 files changed, 13 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +0 -0
index cab3196a87fb1..0021e763b753a 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c uint32_t amdgpu_kiq_rreg(struct amdgpu_device *adev, uint32_t reg, uint32_t xcc_ · line 1129

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +3 -0
@@ -1124,6 +1124,9 @@ uint32_t amdgpu_kiq_rreg(struct amdgpu_device *adev, uint32_t reg, uint32_t xcc_
          if (adev->mes.ring[0].sched.ready)
                  return amdgpu_mes_rreg(adev, reg, xcc_id);
 
+       if (amdgpu_in_reset(adev))
+               return ~0;
+

Please note that the existing logic assumes that kiq access will work fine even during reset and only could fail under certain reset situations (not all) -

https://github.com/torvalds/linux/blob/master/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c#L1107

Also, there are additional things done after full access is released -

https://github.com/torvalds/linux/blob/master/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c#L5610

May be it needs a force completion at the right place somewhere in
amdgpu_device_reset_sriov() as Alex suggested and not to simply block all KIQ based reg accesses during reset. In baremetal case, it is done during pre-reset as we don't expect any more packet submission/indirect register accesses through kernel rings afterwards.

Thanks,
Lijo

Quoted 42 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +0 -0
          BUG_ON(!ring->funcs->emit_rreg);
 
          spin_lock_irqsave(&kiq->ring_lock, flags); @@ -1202,6 +1205,9

@@ void amdgpu_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v, uint3

                  return;
          }
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +7 -0
+       if (amdgpu_in_reset(adev))
+               return;
+
          spin_lock_irqsave(&kiq->ring_lock, flags);
          r = amdgpu_ring_alloc(ring, 32);
          if (r)
@@ -1298,6 +1304,10 @@ int amdgpu_kiq_hdp_flush(struct amdgpu_device *adev)
          if (adev->enable_mes_kiq && adev->mes.ring[0].sched.ready)
                  return amdgpu_mes_hdp_flush(adev);
 
+       /* Avoid KIQ ring access during reset; caller will use amdgpu_hdp_flush fallback */
+       if (amdgpu_in_reset(adev))
+               return -EBUSY;
+
          if (!ring->funcs->emit_hdp_flush) {
                  return -EOPNOTSUPP;
          }
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +3 -1
index 20e1395b39882..f9db2b17105b7 100644
@@ -876,6 +876,9 @@ void amdgpu_gmc_fw_reg_write_reg_wait(struct amdgpu_device *adev,
                  return;
          }
 
+       if (amdgpu_in_reset(adev))
+               return;
+
          spin_lock_irqsave(&kiq->ring_lock, flags);
          amdgpu_ring_alloc(ring, 32);
          amdgpu_ring_emit_reg_write_reg_wait(ring, reg0, reg1,
--

2.34.1

#11 lore raw

PATCH v3 1/1 drm/amdgpu: force fence completion for all rings before and after reset

In reply to Lazar, Lijo

After GPU reset, the hardware queue is cleared and all pending fences are lost, but the fence writeback memory stays stale. If the driver keeps submitting to the KIQ ring during reset (e.g. HDP flush), sync_seq advances while writeback does not, so amdgpu_fence_emit_polling() waits for lost fences and hits -ETIMEDOUT, blocking further KIQ use.

Also, current logic on amdgpu_device_pre_asic_reset() skips force completion on rings without GPU scheduler(e.g KIQ)

v3: Use ring->fence_drv.initialized instead of amdgpu_ring_sched_ready()
so that every ring with a fence driver(including KIQ) gets force_completion before reset in amdgpu_device_pre_asic_reset(), and after reinit in amdgpu_device_reset_sriov(). That syncs writeback with sync_seq and avoids the timeout.

Change-Id I717df52ed0ef0bb51a6901f218191d9837a77f6f
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +13 -4
index 1e1e9c824598f..2a8ff85ddb771 100644
@@ -4985,7 +4985,7 @@ static int amdgpu_device_ip_post_soft_reset(struct amdgpu_device *adev)
 static int amdgpu_device_reset_sriov(struct amdgpu_device *adev,
 				     struct amdgpu_reset_context *reset_context)
 {
-	int r;
+	int i, r;
 	struct amdgpu_hive_info *hive = NULL;
 
 	if (test_bit(AMDGPU_HOST_FLR, &reset_context->flags)) {
@@ -5022,6 +5022,16 @@ static int amdgpu_device_reset_sriov(struct amdgpu_device *adev,
 	if (r)
 		return r;
 
+	/* After reset and reinitialization, force completion on all rings to discard any lost fences sent during reset. */
+	for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
+		struct amdgpu_ring *ring = adev->rings[i];
+
+		if (!ring || !ring->fence_drv.initialized)
+			continue;
+
+		amdgpu_fence_driver_force_completion(ring);
+	}
+
 	hive = amdgpu_get_xgmi_hive(adev);
 	/* Update PSP FW topology after reset */
 	if (hive && adev->gmc.xgmi.num_physical_nodes > 1)
@@ -5238,14 +5248,13 @@ int amdgpu_device_pre_asic_reset(struct amdgpu_device *adev,
 
 	amdgpu_fence_driver_isr_toggle(adev, true);
 
-	/* block all schedulers and reset given job's ring */
+	/* Force completion on all rings with fence driver so pending fences are signalled and writeback is synced before reset. */
 	for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
 		struct amdgpu_ring *ring = adev->rings[i];
 
-		if (!amdgpu_ring_sched_ready(ring))
+		if (!ring || !ring->fence_drv.initialized)
 			continue;
 
-		/* after all hw jobs are reset, hw fence is meaningless, so force_completion */
 		amdgpu_fence_driver_force_completion(ring);
 	}
 
Signature · 1 line
2.34.1
#12 lore raw

Re: [PATCH v3] drm/amdgpu: force fence completion for all rings before and after reset

Quoted 36 lines · Chenglei Xie

After GPU reset, the hardware queue is cleared and all pending fences are lost, but the fence writeback memory stays stale. If the driver keeps submitting to the KIQ ring during reset (e.g. HDP flush), sync_seq advances while writeback does not, so amdgpu_fence_emit_polling() waits for lost fences and hits -ETIMEDOUT, blocking further KIQ use.

Also, current logic on amdgpu_device_pre_asic_reset() skips force completion on rings without GPU scheduler(e.g KIQ)

v3: Use ring->fence_drv.initialized instead of amdgpu_ring_sched_ready()
so that every ring with a fence driver(including KIQ) gets force_completion before reset in amdgpu_device_pre_asic_reset(), and after reinit in amdgpu_device_reset_sriov(). That syncs writeback with sync_seq and avoids the timeout.

Change-Id I717df52ed0ef0bb51a6901f218191d9837a77f6f
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 17 +++++++++++++----
  1 file changed, 13 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
index 1e1e9c824598f..2a8ff85ddb771 100644
@@ -4985,7 +4985,7 @@ static int amdgpu_device_ip_post_soft_reset(struct amdgpu_device *adev)
  static int amdgpu_device_reset_sriov(struct amdgpu_device *adev,
  				     struct amdgpu_reset_context *reset_context)
  {
-	int r;
+	int i, r;
  	struct amdgpu_hive_info *hive = NULL;
 
  	if (test_bit(AMDGPU_HOST_FLR, &reset_context->flags)) {
@@ -5022,6 +5022,16 @@ static int amdgpu_device_reset_sriov(struct amdgpu_device *adev,
  	if (r)
  		return r;

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_device_reset_sriov(struct amdgpu_device *adev, · line 5033

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +9 -0
 
+	/* After reset and reinitialization, force completion on all rings to discard any lost fences sent during reset. */
+	for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
+		struct amdgpu_ring *ring = adev->rings[i];
+
+		if (!ring || !ring->fence_drv.initialized)
+			continue;
+
+		amdgpu_fence_driver_force_completion(ring);
+	}

As mentioned in the other comment, this should be done before reset. You need to trace why any submission request could happen afterwards when actual device reset is ongoing.

Also, you may wrap this around amdgpu_virt_* such that only kiq ring fences are forced to completion. The others should be covered with pre-reset.

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -0
+
  	hive = amdgpu_get_xgmi_hive(adev);
  	/* Update PSP FW topology after reset */
  	if (hive && adev->gmc.xgmi.num_physical_nodes > 1)
@@ -5238,14 +5248,13 @@ int amdgpu_device_pre_asic_reset(struct amdgpu_device *adev,
 

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_pre_asic_reset(struct amdgpu_device *adev, · line 5256

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2 -2
  	amdgpu_fence_driver_isr_toggle(adev, true);
 
-	/* block all schedulers and reset given job's ring */
+	/* Force completion on all rings with fence driver so pending fences are signalled and writeback is synced before reset. */
  	for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
  		struct amdgpu_ring *ring = adev->rings[i];
 
-		if (!amdgpu_ring_sched_ready(ring))
+		if (!ring || !ring->fence_drv.initialized)
  			continue;

Not expecting any change in this sequence.

Thanks,
Lijo

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -1
-		/* after all hw jobs are reset, hw fence is meaningless, so force_completion */
  		amdgpu_fence_driver_force_completion(ring);
  	}
 
#13 lore raw

PATCH v4 1/1 drm/amdgpu: avoid KIQ HDP flush from VM CPU commit during reset

During GPU reset (SR-IOV), amdgpu_vm_cpu_commit() is called repeatedly for VM page table updates. Each call uses amdgpu_device_flush_hdp(adev, NULL), which on SRIOV runtime takes the KIQ path and submits a fence to the KIQ ring. That floods the KIQ ring while the GPU is resetting. After reset, hardware has cleared the queue and those fences are lost, but fence writeback memory and sync_seq are out of sync, so amdgpu_fence_emit_polling() can hit -ETIMEDOUT and block further KIQ use.

Fix:
- In amdgpu_vm_cpu_commit(), when the device is in reset,
use the non-KIQ HDP flush path (amdgpu_hdp_flush) instead of
amdgpu_device_flush_hdp so VM updates during reset do not submit to the
KIQ ring.
- In amdgpu_virt_pre_reset(), force completion on all KIQ ring fences so any
pending fences are signalled before reset. The other rings were handled in amdgpu_device_pre_asic_reset()

Change-Id I95404ce348ad546ddff1ea3b95a3f790299eb7aa
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c   | 11 +++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c |  7 ++++++-
 2 files changed, 17 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +11 -0
index f01f385091083..5998e0a04d760 100644
@@ -1191,9 +1191,20 @@ enum amdgpu_sriov_vf_mode amdgpu_virt_get_sriov_vf_mode(struct amdgpu_device *ad
 
 void amdgpu_virt_pre_reset(struct amdgpu_device *adev)
 {
+	int i;
+
 	/* stop the data exchange thread */
 	amdgpu_virt_fini_data_exchange(adev);
 	amdgpu_dpm_set_mp1_state(adev, PP_MP1_STATE_FLR);
+
+	/* Force completion on KIQ ring fences so pending fences are signalled. */
+	for (i = 0; i < AMDGPU_MAX_GC_INSTANCES; i++) {
+		struct amdgpu_ring *ring = &adev->gfx.kiq[i].ring;
+
+		if (!ring->fence_drv.initialized)
+			continue;
+		amdgpu_fence_driver_force_completion(ring);
+	}
 }
 
 void amdgpu_virt_post_reset(struct amdgpu_device *adev)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c +6 -1
index 22e2e5b473415..50ab9f9604834 100644
@@ -21,6 +21,7 @@
  */
 
 #include "amdgpu_vm.h"
+#include "amdgpu.h"
 #include "amdgpu_object.h"
 #include "amdgpu_trace.h"
 
@@ -112,7 +113,11 @@ static int amdgpu_vm_cpu_commit(struct amdgpu_vm_update_params *p,
 		atomic64_inc(&p->vm->tlb_seq);
 
 	mb();
-	amdgpu_device_flush_hdp(p->adev, NULL);
+	/* Avoid KIQ during reset; use non-KIQ HDP flush */
+	if (amdgpu_in_reset(p->adev))
+		amdgpu_hdp_flush(p->adev, NULL);
+	else
+		amdgpu_device_flush_hdp(p->adev, NULL);
 	return 0;
 }
 
Signature · 1 line
2.34.1
#14 lore raw

RE: [PATCH v4] drm/amdgpu: avoid KIQ HDP flush from VM CPU commit during reset

[AMD Official Use Only - AMD Internal Distribution Only]

Hi Lijo,

Please help review the latest patch version. The faulty source is the amdgpu_vm_cpu_commit() requests too many HDP flush commands to KIQ due to VM page table updates during reset. The new change fix this by using non-KIQ HDP flush path when in reset, and added extra fence force completion on KIQ rings during SRIOV pre_reset.

Thanks,
Chenglei

-----Original Message-----
From: Xie, Chenglei <[email protected]>
Sent: Wednesday, March 11, 2026 3:31 PM
To: Lazar, Lijo <[email protected]>
Cc: Chan, Hing Pong <[email protected]>; Luo, Zhigang <[email protected]>; [email protected]; Xie, Chenglei <[email protected]>; Deucher, Alexander <[email protected]>
Subject: [PATCH v4] drm/amdgpu: avoid KIQ HDP flush from VM CPU commit during reset

During GPU reset (SR-IOV), amdgpu_vm_cpu_commit() is called repeatedly for VM page table updates. Each call uses amdgpu_device_flush_hdp(adev, NULL), which on SRIOV runtime takes the KIQ path and submits a fence to the KIQ ring. That floods the KIQ ring while the GPU is resetting. After reset, hardware has cleared the queue and those fences are lost, but fence writeback memory and sync_seq are out of sync, so amdgpu_fence_emit_polling() can hit -ETIMEDOUT and block further KIQ use.

Fix:
- In amdgpu_vm_cpu_commit(), when the device is in reset,
use the non-KIQ HDP flush path (amdgpu_hdp_flush) instead of
amdgpu_device_flush_hdp so VM updates during reset do not submit to the
KIQ ring.
- In amdgpu_virt_pre_reset(), force completion on all KIQ ring fences so any
pending fences are signalled before reset. The other rings were handled in amdgpu_device_pre_asic_reset()

Change-Id I95404ce348ad546ddff1ea3b95a3f790299eb7aa
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c   | 11 +++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c |  7 ++++++-
 2 files changed, 17 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +11 -0
index f01f385091083..5998e0a04d760 100644
@@ -1191,9 +1191,20 @@ enum amdgpu_sriov_vf_mode amdgpu_virt_get_sriov_vf_mode(struct amdgpu_device *ad
 
 void amdgpu_virt_pre_reset(struct amdgpu_device *adev)  {
+       int i;
+
        /* stop the data exchange thread */
        amdgpu_virt_fini_data_exchange(adev);
        amdgpu_dpm_set_mp1_state(adev, PP_MP1_STATE_FLR);
+
+       /* Force completion on KIQ ring fences so pending fences are signalled. */
+       for (i = 0; i < AMDGPU_MAX_GC_INSTANCES; i++) {
+               struct amdgpu_ring *ring = &adev->gfx.kiq[i].ring;
+
+               if (!ring->fence_drv.initialized)
+                       continue;
+               amdgpu_fence_driver_force_completion(ring);
+       }
 }
 
 void amdgpu_virt_post_reset(struct amdgpu_device *adev) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c

index 22e2e5b473415..50ab9f9604834 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c +6 -1
@@ -21,6 +21,7 @@
  */
 
 #include "amdgpu_vm.h"
+#include "amdgpu.h"
 #include "amdgpu_object.h"
 #include "amdgpu_trace.h"
 
@@ -112,7 +113,11 @@ static int amdgpu_vm_cpu_commit(struct amdgpu_vm_update_params *p,
                atomic64_inc(&p->vm->tlb_seq);
 
        mb();
-       amdgpu_device_flush_hdp(p->adev, NULL);
+       /* Avoid KIQ during reset; use non-KIQ HDP flush */
+       if (amdgpu_in_reset(p->adev))
+               amdgpu_hdp_flush(p->adev, NULL);
+       else
+               amdgpu_device_flush_hdp(p->adev, NULL);
        return 0;
 }
 

--
2.34.1

#15 lore raw

Re: [PATCH v4] drm/amdgpu: avoid KIQ HDP flush from VM CPU commit during reset

Quoted 5 lines · Chenglei

[AMD Official Use Only - AMD Internal Distribution Only]

Hi Lijo,

Please help review the latest patch version. The faulty source is the amdgpu_vm_cpu_commit() requests too many HDP flush commands to KIQ due to VM page table updates during reset.

Do you have a dmesg log for this trace? If this is happening after hardware reset is initiated, it needs a closer look. We don't expect page table commits while hardware reset is ongoing. Copying Philip.

Quoted 1 line

The new change fix this by using non-KIQ HDP flush path when in reset, and added extra fence force completion on KIQ rings during SRIOV pre_reset.

If I remember correctly, the reason to introduce KIQ based HDP flush was that the direct ones don't work for multi-VF cases. I think you cannot replace one with the other just for flush happening in reset scenarios.

Thanks,
Lijo

Quoted 79 lines

Thanks,
Chenglei

-----Original Message-----
From: Xie, Chenglei <[email protected]>
Sent: Wednesday, March 11, 2026 3:31 PM
To: Lazar, Lijo <[email protected]>
Cc: Chan, Hing Pong <[email protected]>; Luo, Zhigang <[email protected]>; [email protected]; Xie, Chenglei <[email protected]>; Deucher, Alexander <[email protected]>
Subject: [PATCH v4] drm/amdgpu: avoid KIQ HDP flush from VM CPU commit during reset

During GPU reset (SR-IOV), amdgpu_vm_cpu_commit() is called repeatedly for VM page table updates. Each call uses amdgpu_device_flush_hdp(adev, NULL), which on SRIOV runtime takes the KIQ path and submits a fence to the KIQ ring. That floods the KIQ ring while the GPU is resetting. After reset, hardware has cleared the queue and those fences are lost, but fence writeback memory and sync_seq are out of sync, so amdgpu_fence_emit_polling() can hit -ETIMEDOUT and block further KIQ use.

Fix:
- In amdgpu_vm_cpu_commit(), when the device is in reset,
use the non-KIQ HDP flush path (amdgpu_hdp_flush) instead of
amdgpu_device_flush_hdp so VM updates during reset do not submit to the
KIQ ring.
- In amdgpu_virt_pre_reset(), force completion on all KIQ ring fences so any
pending fences are signalled before reset. The other rings were handled in amdgpu_device_pre_asic_reset()

Change-Id I95404ce348ad546ddff1ea3b95a3f790299eb7aa
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c   | 11 +++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c |  7 ++++++-
  2 files changed, 17 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +11 -0
index f01f385091083..5998e0a04d760 100644
@@ -1191,9 +1191,20 @@ enum amdgpu_sriov_vf_mode amdgpu_virt_get_sriov_vf_mode(struct amdgpu_device *ad
 
  void amdgpu_virt_pre_reset(struct amdgpu_device *adev)  {
+       int i;
+
         /* stop the data exchange thread */
         amdgpu_virt_fini_data_exchange(adev);
         amdgpu_dpm_set_mp1_state(adev, PP_MP1_STATE_FLR);
+
+       /* Force completion on KIQ ring fences so pending fences are signalled. */
+       for (i = 0; i < AMDGPU_MAX_GC_INSTANCES; i++) {
+               struct amdgpu_ring *ring = &adev->gfx.kiq[i].ring;
+
+               if (!ring->fence_drv.initialized)
+                       continue;
+               amdgpu_fence_driver_force_completion(ring);
+       }
  }
 
  void amdgpu_virt_post_reset(struct amdgpu_device *adev) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c

index 22e2e5b473415..50ab9f9604834 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c +6 -2
@@ -21,6 +21,7 @@
   */
 
  #include "amdgpu_vm.h"
+#include "amdgpu.h"
  #include "amdgpu_object.h"
  #include "amdgpu_trace.h"
 
@@ -112,7 +113,11 @@ static int amdgpu_vm_cpu_commit(struct amdgpu_vm_update_params *p,
                 atomic64_inc(&p->vm->tlb_seq);
 
         mb();
-       amdgpu_device_flush_hdp(p->adev, NULL);
+       /* Avoid KIQ during reset; use non-KIQ HDP flush */
+       if (amdgpu_in_reset(p->adev))
+               amdgpu_hdp_flush(p->adev, NULL);
+       else
+               amdgpu_device_flush_hdp(p->adev, NULL);
         return 0;
  }
 
--

2.34.1

#16 lore raw

RE: [PATCH v4] drm/amdgpu: avoid KIQ HDP flush from VM CPU commit during reset

[AMD Official Use Only - AMD Internal Distribution Only]

How about do force completion after amdgpu_virt_post_reset to avoid any possible fence corruption during reset? For amdgpu_device_flush_hdp we already have amdgpu_in_reset check in amdgpu_kiq_hdp_flush so calling it should not cause trouble.

Thanks,
Victor

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Lazar, Lijo
Sent: Thursday, March 12, 2026 1:45 PM
To: Xie, Chenglei <[email protected]>
Cc: Chan, Hing Pong <[email protected]>; Luo, Zhigang <[email protected]>; [email protected]; Deucher, Alexander <[email protected]>; Yang, Philip <[email protected]>
Subject: Re: [PATCH v4] drm/amdgpu: avoid KIQ HDP flush from VM CPU commit during reset

Quoted 5 lines · Chenglei

[AMD Official Use Only - AMD Internal Distribution Only]

Hi Lijo,

Please help review the latest patch version. The faulty source is the amdgpu_vm_cpu_commit() requests too many HDP flush commands to KIQ due to VM page table updates during reset.

Do you have a dmesg log for this trace? If this is happening after hardware reset is initiated, it needs a closer look. We don't expect page table commits while hardware reset is ongoing. Copying Philip.

Quoted 1 line

The new change fix this by using non-KIQ HDP flush path when in reset, and added extra fence force completion on KIQ rings during SRIOV pre_reset.

If I remember correctly, the reason to introduce KIQ based HDP flush was that the direct ones don't work for multi-VF cases. I think you cannot replace one with the other just for flush happening in reset scenarios.

Thanks,
Lijo

Quoted 87 lines

Thanks,
Chenglei

-----Original Message-----
From: Xie, Chenglei <[email protected]>
Sent: Wednesday, March 11, 2026 3:31 PM
To: Lazar, Lijo <[email protected]>
Cc: Chan, Hing Pong <[email protected]>; Luo, Zhigang <[email protected]>; [email protected]; Xie, Chenglei <[email protected]>; Deucher, Alexander <[email protected]>
Subject: [PATCH v4] drm/amdgpu: avoid KIQ HDP flush from VM CPU commit during reset

During GPU reset (SR-IOV), amdgpu_vm_cpu_commit() is called repeatedly for VM page table updates. Each call uses amdgpu_device_flush_hdp(adev, NULL), which on SRIOV runtime takes the KIQ path and submits a fence to the KIQ ring. That floods the KIQ ring while the GPU is resetting. After reset, hardware has cleared the queue and those fences are lost, but fence writeback memory and sync_seq are out of sync, so amdgpu_fence_emit_polling() can hit -ETIMEDOUT and block further KIQ use.

Fix:
- In amdgpu_vm_cpu_commit(), when the device is in reset,
use the non-KIQ HDP flush path (amdgpu_hdp_flush) instead of amdgpu_device_flush_hdp so VM updates during reset do not submit to the KIQ ring.
- In amdgpu_virt_pre_reset(), force completion on all KIQ ring fences so any pending fences are signalled before reset. The other rings were
handled in amdgpu_device_pre_asic_reset()

Change-Id I95404ce348ad546ddff1ea3b95a3f790299eb7aa
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c   | 11 +++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c |  7 ++++++-
  2 files changed, 17 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +0 -0
index f01f385091083..5998e0a04d760 100644
@@ -1191,9 +1191,20 @@ enum amdgpu_sriov_vf_mode

amdgpu_virt_get_sriov_vf_mode(struct amdgpu_device *ad

  void amdgpu_virt_pre_reset(struct amdgpu_device *adev)  {
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +11 -0
+       int i;
+
         /* stop the data exchange thread */
         amdgpu_virt_fini_data_exchange(adev);
         amdgpu_dpm_set_mp1_state(adev, PP_MP1_STATE_FLR);
+
+       /* Force completion on KIQ ring fences so pending fences are signalled. */
+       for (i = 0; i < AMDGPU_MAX_GC_INSTANCES; i++) {
+               struct amdgpu_ring *ring = &adev->gfx.kiq[i].ring;
+
+               if (!ring->fence_drv.initialized)
+                       continue;
+               amdgpu_fence_driver_force_completion(ring);
+       }
  }
 
  void amdgpu_virt_post_reset(struct amdgpu_device *adev) diff --git

a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c index 22e2e5b473415..50ab9f9604834 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c +6 -2
@@ -21,6 +21,7 @@
   */
 
  #include "amdgpu_vm.h"
+#include "amdgpu.h"
  #include "amdgpu_object.h"
  #include "amdgpu_trace.h"
 
@@ -112,7 +113,11 @@ static int amdgpu_vm_cpu_commit(struct amdgpu_vm_update_params *p,
                 atomic64_inc(&p->vm->tlb_seq);
 
         mb();
-       amdgpu_device_flush_hdp(p->adev, NULL);
+       /* Avoid KIQ during reset; use non-KIQ HDP flush */
+       if (amdgpu_in_reset(p->adev))
+               amdgpu_hdp_flush(p->adev, NULL);
+       else
+               amdgpu_device_flush_hdp(p->adev, NULL);
         return 0;
  }
 
--

2.34.1

#17 lore raw

Re: [PATCH v4] drm/amdgpu: avoid KIQ HDP flush from VM CPU commit during reset

Quoted 4 lines · Victor

[AMD Official Use Only - AMD Internal Distribution Only]

How about do force completion after amdgpu_virt_post_reset to avoid any possible fence corruption during reset? For amdgpu_device_flush_hdp we already have amdgpu_in_reset check in amdgpu_kiq_hdp_flush so calling it should not cause trouble.

Clearing before actual hardware reset should be sufficient ideally.

The current in_reset() check in kiq flush is when packet submission times out. in_reset() is a software condition. Flush could be required for unwind operations before actual hardware reset is initiated. That way, it cannot be blocked with a blanket in_reset() check.

There is also a higher level logic issue seen now. There is a sidethread on this, will add you there.

Thanks,
Lijo

Quoted 116 lines

Thanks,
Victor

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Lazar, Lijo
Sent: Thursday, March 12, 2026 1:45 PM
To: Xie, Chenglei <[email protected]>
Cc: Chan, Hing Pong <[email protected]>; Luo, Zhigang <[email protected]>; [email protected]; Deucher, Alexander <[email protected]>; Yang, Philip <[email protected]>
Subject: Re: [PATCH v4] drm/amdgpu: avoid KIQ HDP flush from VM CPU commit during reset

Quoted 5 lines · Chenglei

[AMD Official Use Only - AMD Internal Distribution Only]

Hi Lijo,

Please help review the latest patch version. The faulty source is the amdgpu_vm_cpu_commit() requests too many HDP flush commands to KIQ due to VM page table updates during reset.

Do you have a dmesg log for this trace? If this is happening after hardware reset is initiated, it needs a closer look. We don't expect page table commits while hardware reset is ongoing. Copying Philip.

Quoted 1 line

The new change fix this by using non-KIQ HDP flush path when in reset, and added extra fence force completion on KIQ rings during SRIOV pre_reset.

If I remember correctly, the reason to introduce KIQ based HDP flush was that the direct ones don't work for multi-VF cases. I think you cannot replace one with the other just for flush happening in reset scenarios.

Thanks,
Lijo

Quoted 87 lines

Thanks,
Chenglei

-----Original Message-----
From: Xie, Chenglei <[email protected]>
Sent: Wednesday, March 11, 2026 3:31 PM
To: Lazar, Lijo <[email protected]>
Cc: Chan, Hing Pong <[email protected]>; Luo, Zhigang <[email protected]>; [email protected]; Xie, Chenglei <[email protected]>; Deucher, Alexander <[email protected]>
Subject: [PATCH v4] drm/amdgpu: avoid KIQ HDP flush from VM CPU commit during reset

During GPU reset (SR-IOV), amdgpu_vm_cpu_commit() is called repeatedly for VM page table updates. Each call uses amdgpu_device_flush_hdp(adev, NULL), which on SRIOV runtime takes the KIQ path and submits a fence to the KIQ ring. That floods the KIQ ring while the GPU is resetting. After reset, hardware has cleared the queue and those fences are lost, but fence writeback memory and sync_seq are out of sync, so amdgpu_fence_emit_polling() can hit -ETIMEDOUT and block further KIQ use.

Fix:
- In amdgpu_vm_cpu_commit(), when the device is in reset,
use the non-KIQ HDP flush path (amdgpu_hdp_flush) instead of amdgpu_device_flush_hdp so VM updates during reset do not submit to the KIQ ring.
- In amdgpu_virt_pre_reset(), force completion on all KIQ ring fences so any pending fences are signalled before reset. The other rings were
handled in amdgpu_device_pre_asic_reset()

Change-Id I95404ce348ad546ddff1ea3b95a3f790299eb7aa
---
   drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c   | 11 +++++++++++
   drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c |  7 ++++++-
   2 files changed, 17 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +0 -0
index f01f385091083..5998e0a04d760 100644
@@ -1191,9 +1191,20 @@ enum amdgpu_sriov_vf_mode

amdgpu_virt_get_sriov_vf_mode(struct amdgpu_device *ad

   void amdgpu_virt_pre_reset(struct amdgpu_device *adev)  {
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +11 -0
+       int i;
+
          /* stop the data exchange thread */
          amdgpu_virt_fini_data_exchange(adev);
          amdgpu_dpm_set_mp1_state(adev, PP_MP1_STATE_FLR);
+
+       /* Force completion on KIQ ring fences so pending fences are signalled. */
+       for (i = 0; i < AMDGPU_MAX_GC_INSTANCES; i++) {
+               struct amdgpu_ring *ring = &adev->gfx.kiq[i].ring;
+
+               if (!ring->fence_drv.initialized)
+                       continue;
+               amdgpu_fence_driver_force_completion(ring);
+       }
   }
 
   void amdgpu_virt_post_reset(struct amdgpu_device *adev) diff --git

a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c index 22e2e5b473415..50ab9f9604834 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c +6 -2
@@ -21,6 +21,7 @@
    */
 
   #include "amdgpu_vm.h"
+#include "amdgpu.h"
   #include "amdgpu_object.h"
   #include "amdgpu_trace.h"
 
@@ -112,7 +113,11 @@ static int amdgpu_vm_cpu_commit(struct amdgpu_vm_update_params *p,
                  atomic64_inc(&p->vm->tlb_seq);
 
          mb();
-       amdgpu_device_flush_hdp(p->adev, NULL);
+       /* Avoid KIQ during reset; use non-KIQ HDP flush */
+       if (amdgpu_in_reset(p->adev))
+               amdgpu_hdp_flush(p->adev, NULL);
+       else
+               amdgpu_device_flush_hdp(p->adev, NULL);
          return 0;
   }
 
--

2.34.1