Skip to contentSkip to conversation

] drm/amdgpu: gate VM CPU HDP flush on reset lock; force-complete KIQ before VF reset

PATCH Superseded Chenglei Xie 2 participants 5 messages Apr 7 – Apr 8

Subsystems (2)

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v6 1/1 ] drm/amdgpu: gate VM CPU HDP flush on reset lock; force-complete KIQ before VF reset

During GPU reset, the application could still run CPU page table updates. Each commit called amdgpu_device_flush_hdp(), which on SR-IOV sends work through the KIQ ring. That can advance sync_seq while the GPU is being reset,
leaving fence writeback out of sync and causing amdgpu_fence_emit_polling() to time out on later KIQ use.

Fix:
amdgpu_vm_cpu_commit():
Take reset_domain->sem with down_read_trylock() before amdgpu_device_flush_hdp(). If the reset path holds the write lock, skip the HDP flush so no HDP-related HW access (including KIQ) runs during reset; state is re-established after reset.

amdgpu_virt_pre_reset():
After stopping the data exchange thread and setting MP1 FLR state, call amdgpu_fence_driver_force_completion() on each initialized KIQ ring so pending fences are signalled and writeback is aligned before reset proceeds.

Change-Id I938bce0cab93a794dbdb02fe3ca9e041f9ac1424
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c   | 11 +++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c | 16 +++++++++++++++-
 2 files changed, 26 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +11 -0
index 6974b1c5b56c2..0127b0d6c7277 100644
@@ -1188,9 +1188,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 +15 -1
index 22e2e5b473415..a9e33b7e87406 100644
@@ -21,6 +21,8 @@
  */
 
 #include "amdgpu_vm.h"
+#include "amdgpu.h"
+#include "amdgpu_reset.h"
 #include "amdgpu_object.h"
 #include "amdgpu_trace.h"
 
@@ -108,11 +110,23 @@ static int amdgpu_vm_cpu_update(struct amdgpu_vm_update_params *p,
 static int amdgpu_vm_cpu_commit(struct amdgpu_vm_update_params *p,
 				struct dma_fence **fence)
 {
+	struct amdgpu_device *adev = p->adev;
+
 	if (p->needs_flush)
 		atomic64_inc(&p->vm->tlb_seq);
 
 	mb();
-	amdgpu_device_flush_hdp(p->adev, NULL);
+	/*
+	 * While GPU reset holds reset_domain write lock, skip HDP flush entirely so
+	 * no HDP-related HW access runs during reset;
+	 * reset re-establishes consistent state afterward.
+	 */
+	if (!down_read_trylock(&adev->reset_domain->sem))
+		return 0;
+
+	amdgpu_device_flush_hdp(adev, NULL);
+	up_read(&adev->reset_domain->sem);
+
 	return 0;
 }
 
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 35 lines · Chenglei Xie

During GPU reset, the application could still run CPU page table updates. Each commit called amdgpu_device_flush_hdp(), which on SR-IOV sends work through the KIQ ring. That can advance sync_seq while the GPU is being reset,
leaving fence writeback out of sync and causing amdgpu_fence_emit_polling() to time out on later KIQ use.

Fix:
amdgpu_vm_cpu_commit():
Take reset_domain->sem with down_read_trylock() before amdgpu_device_flush_hdp(). If the reset path holds the write lock, skip the HDP flush so no HDP-related HW access (including KIQ) runs during reset; state is re-established after reset.

amdgpu_virt_pre_reset():
After stopping the data exchange thread and setting MP1 FLR state, call amdgpu_fence_driver_force_completion() on each initialized KIQ ring so pending fences are signalled and writeback is aligned before reset proceeds.

Change-Id I938bce0cab93a794dbdb02fe3ca9e041f9ac1424
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c   | 11 +++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c | 16 +++++++++++++++-
 2 files changed, 26 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +2 -0
index 6974b1c5b56c2..0127b0d6c7277 100644
@@ -1188,9 +1188,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 */

drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c enum amdgpu_sriov_vf_mode amdgpu_virt_get_sriov_vf_mode(struct amdgpu_device *ad · line 1203

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +8 -0
 	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);

Well that is unrelated and clearly incorrect. The KIQ is re-initialized through a reset and should *NEVER* be force signaled.

Quoted 23 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +1 -0
+	}
 }
 
 void amdgpu_virt_post_reset(struct amdgpu_device *adev)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c +4 -0
index 22e2e5b473415..a9e33b7e87406 100644
@@ -21,6 +21,8 @@
  */
 
 #include "amdgpu_vm.h"
+#include "amdgpu.h"
+#include "amdgpu_reset.h"
 #include "amdgpu_object.h"
 #include "amdgpu_trace.h"
 
@@ -108,11 +110,23 @@ static int amdgpu_vm_cpu_update(struct amdgpu_vm_update_params *p,
 static int amdgpu_vm_cpu_commit(struct amdgpu_vm_update_params *p,
 				struct dma_fence **fence)
 {
+	struct amdgpu_device *adev = p->adev;
+

drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c static int amdgpu_vm_cpu_update(struct amdgpu_vm_update_params *p, · line 123

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c +5 -1
 	if (p->needs_flush)
 		atomic64_inc(&p->vm->tlb_seq);
 
 	mb();
-	amdgpu_device_flush_hdp(p->adev, NULL);
+	/*
+	 * While GPU reset holds reset_domain write lock, skip HDP flush entirely so
+	 * no HDP-related HW access runs during reset;
+	 * reset re-establishes consistent state afterward.
+	 */

That comment explains what is done but not why.

Rather use something like this:

/* A reset flushed the HDP anyway, so that here can be skipped when a reset is ongoing */

Regards,
Christian.

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c +6 -0
+	if (!down_read_trylock(&adev->reset_domain->sem))
+		return 0;
+
+	amdgpu_device_flush_hdp(adev, NULL);
+	up_read(&adev->reset_domain->sem);
+
 	return 0;
 }
 
#2 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

Hi @Koenig, Christian,

Quoted 15 lines

void amdgpu_virt_pre_reset(struct amdgpu_device *adev) {

drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +10 -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);
Quoted 1 line
Quoted 1 line

Well that is unrelated and clearly incorrect. The KIQ is re-initialized through a reset and should *NEVER* be force signaled.

HW KIQ is re-inited after reset, but that path does not reinitialize or reset ring->fence_drv.
amdgpu_fence_driver_force_completion() is SW-only: pending dma_fences get -ECANCELED, writeback is set to sync_seq, and fences are signaled so bookkeeping and waiters reflect that the queue’s prior work will not complete on HW. Without that, seq/writeback can stay wrong and amdgpu_fence_emit_polling() can time out on later KIQ use.

The generic loop in amdgpu_device_pre_asic_reset() only force-completes scheduler-ready rings, so it skips KIQ. This VF path covers KIQ unless we add equivalent logic elsewhere. So we still need this SW cleanup to avoid KIQ fence state mismatch after reset.

Thanks,
Chenglei

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Tuesday, April 7, 2026 1:07 PM
To: Xie, Chenglei <[email protected]>; [email protected]
Cc: Lazar, Lijo <[email protected]>; Kuehling, Felix <[email protected]>; Deucher, Alexander <[email protected]>; Chan, Hing Pong <[email protected]>; Luo, Zhigang <[email protected]>; Kasiviswanathan, Harish <[email protected]>; Zhao, Victor <[email protected]>; Yat Sin, David <[email protected]>; Dhinakararam, Lokesh <[email protected]>
Subject: Re: [[PATCH v6]] drm/amdgpu: gate VM CPU HDP flush on reset lock; force-complete KIQ before VF reset

Quoted 36 lines · Chenglei Xie

During GPU reset, the application could still run CPU page table
updates. Each commit called amdgpu_device_flush_hdp(), which on SR-IOV sends work through the KIQ ring. That can advance sync_seq while the GPU is being reset, leaving fence
writeback out of sync and causing amdgpu_fence_emit_polling() to time
out on later KIQ use.

Fix:
amdgpu_vm_cpu_commit():
Take reset_domain->sem with down_read_trylock() before amdgpu_device_flush_hdp(). If the reset path holds the write lock, skip the HDP flush so no HDP-related HW access (including KIQ) runs during reset; state is re-established after reset.

amdgpu_virt_pre_reset():
After stopping the data exchange thread and setting MP1 FLR state, call amdgpu_fence_driver_force_completion() on each initialized KIQ ring so pending fences are signalled and writeback is aligned before reset proceeds.

Change-Id I938bce0cab93a794dbdb02fe3ca9e041f9ac1424
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c   | 11 +++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c | 16 +++++++++++++++-
 2 files changed, 26 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +0 -0
index 6974b1c5b56c2..0127b0d6c7277 100644
@@ -1188,9 +1188,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 +2 -0
+     int i;
+
      /* stop the data exchange thread */

drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c enum amdgpu_sriov_vf_mode amdgpu_virt_get_sriov_vf_mode(struct amdgpu_device *ad · line 1203

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +8 -0
      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);

Well that is unrelated and clearly incorrect. The KIQ is re-initialized through a reset and should *NEVER* be force signaled.

Quoted 24 lines

+ }
}

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..a9e33b7e87406 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c +4 -0
@@ -21,6 +21,8 @@
  */
 
 #include "amdgpu_vm.h"
+#include "amdgpu.h"
+#include "amdgpu_reset.h"
 #include "amdgpu_object.h"
 #include "amdgpu_trace.h"
 
@@ -108,11 +110,23 @@ static int amdgpu_vm_cpu_update(struct
 amdgpu_vm_update_params *p,  static int amdgpu_vm_cpu_commit(struct amdgpu_vm_update_params *p,
                              struct dma_fence **fence)
 {
+     struct amdgpu_device *adev = p->adev;
+

drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c static int amdgpu_vm_cpu_update(struct · line 123

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c +5 -1
      if (p->needs_flush)
              atomic64_inc(&p->vm->tlb_seq);
 
      mb();
-     amdgpu_device_flush_hdp(p->adev, NULL);
+     /*
+      * While GPU reset holds reset_domain write lock, skip HDP flush entirely so
+      * no HDP-related HW access runs during reset;
+      * reset re-establishes consistent state afterward.
+      */

That comment explains what is done but not why.

Rather use something like this:

/* A reset flushed the HDP anyway, so that here can be skipped when a reset is ongoing */

Regards,
Christian.

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c +6 -0
+     if (!down_read_trylock(&adev->reset_domain->sem))
+             return 0;
+
+     amdgpu_device_flush_hdp(adev, NULL);
+     up_read(&adev->reset_domain->sem);
+
      return 0;
 }
 
maintainer
#3 lore raw
Quoted 19 lines · Chenglei

[AMD Official Use Only - AMD Internal Distribution Only]

Hi @Koenig, Christian,

Quoted 14 lines

void amdgpu_virt_pre_reset(struct amdgpu_device *adev) {

drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +10 -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);
Quoted 6 lines
Quoted 1 line
Quoted 1 line

Well that is unrelated and clearly incorrect. The KIQ is re-initialized through a reset and should *NEVER* be force signaled.

HW KIQ is re-inited after reset, but that path does not reinitialize or reset ring->fence_drv.
amdgpu_fence_driver_force_completion() is SW-only: pending dma_fences get -ECANCELED, writeback is set to sync_seq, and fences are signaled so bookkeeping and waiters reflect that the queue’s prior work will not complete on HW. Without that, seq/writeback can stay wrong and amdgpu_fence_emit_polling() can time out on later KIQ use.

The generic loop in amdgpu_device_pre_asic_reset() only force-completes scheduler-ready rings, so it skips KIQ. This VF path covers KIQ unless we add equivalent logic elsewhere. So we still need this SW cleanup to avoid KIQ fence state mismatch after reset.

Well you just explained it.

The KIQ is skipped in amdgpu_device_pre_asic_reset() because it doesn't use dma_fences and so calling amdgpu_fence_driver_force_completion() on it is absolutely nonsense.

I mean when there is an intentional skipping of calling a function why in the world do you think that you need to do that manually?

Regards,
Christian.

Quoted 115 lines

Thanks,
Chenglei

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Tuesday, April 7, 2026 1:07 PM
To: Xie, Chenglei <[email protected]>; [email protected]
Cc: Lazar, Lijo <[email protected]>; Kuehling, Felix <[email protected]>; Deucher, Alexander <[email protected]>; Chan, Hing Pong <[email protected]>; Luo, Zhigang <[email protected]>; Kasiviswanathan, Harish <[email protected]>; Zhao, Victor <[email protected]>; Yat Sin, David <[email protected]>; Dhinakararam, Lokesh <[email protected]>
Subject: Re: [[PATCH v6]] drm/amdgpu: gate VM CPU HDP flush on reset lock; force-complete KIQ before VF reset

Quoted 36 lines · Chenglei Xie

During GPU reset, the application could still run CPU page table
updates. Each commit called amdgpu_device_flush_hdp(), which on SR-IOV sends work through the KIQ ring. That can advance sync_seq while the GPU is being reset, leaving fence
writeback out of sync and causing amdgpu_fence_emit_polling() to time
out on later KIQ use.

Fix:
amdgpu_vm_cpu_commit():
Take reset_domain->sem with down_read_trylock() before amdgpu_device_flush_hdp(). If the reset path holds the write lock, skip the HDP flush so no HDP-related HW access (including KIQ) runs during reset; state is re-established after reset.

amdgpu_virt_pre_reset():
After stopping the data exchange thread and setting MP1 FLR state, call amdgpu_fence_driver_force_completion() on each initialized KIQ ring so pending fences are signalled and writeback is aligned before reset proceeds.

Change-Id I938bce0cab93a794dbdb02fe3ca9e041f9ac1424
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c   | 11 +++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c | 16 +++++++++++++++-
 2 files changed, 26 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +0 -0
index 6974b1c5b56c2..0127b0d6c7277 100644
@@ -1188,9 +1188,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 +2 -0
+     int i;
+
      /* stop the data exchange thread */

drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c enum amdgpu_sriov_vf_mode amdgpu_virt_get_sriov_vf_mode(struct amdgpu_device *ad · line 1203

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +8 -0
      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);

Well that is unrelated and clearly incorrect. The KIQ is re-initialized through a reset and should *NEVER* be force signaled.

Quoted 24 lines

+ }
}

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..a9e33b7e87406 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c +4 -0
@@ -21,6 +21,8 @@
  */
 
 #include "amdgpu_vm.h"
+#include "amdgpu.h"
+#include "amdgpu_reset.h"
 #include "amdgpu_object.h"
 #include "amdgpu_trace.h"
 
@@ -108,11 +110,23 @@ static int amdgpu_vm_cpu_update(struct
 amdgpu_vm_update_params *p,  static int amdgpu_vm_cpu_commit(struct amdgpu_vm_update_params *p,
                              struct dma_fence **fence)
 {
+     struct amdgpu_device *adev = p->adev;
+

drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c static int amdgpu_vm_cpu_update(struct · line 123

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c +5 -1
      if (p->needs_flush)
              atomic64_inc(&p->vm->tlb_seq);
 
      mb();
-     amdgpu_device_flush_hdp(p->adev, NULL);
+     /*
+      * While GPU reset holds reset_domain write lock, skip HDP flush entirely so
+      * no HDP-related HW access runs during reset;
+      * reset re-establishes consistent state afterward.
+      */

That comment explains what is done but not why.

Rather use something like this:

/* A reset flushed the HDP anyway, so that here can be skipped when a reset is ongoing */

Regards,
Christian.

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c +6 -0
+     if (!down_read_trylock(&adev->reset_domain->sem))
+             return 0;
+
+     amdgpu_device_flush_hdp(adev, NULL);
+     up_read(&adev->reset_domain->sem);
+
      return 0;
 }
 
#4 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

I see, I will create new patch for review. I tried a few loops of sanity test and the results looks positive.

Thanks,
Chenglei

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Wednesday, April 8, 2026 4:09 AM
To: Xie, Chenglei <[email protected]>; [email protected]
Cc: Lazar, Lijo <[email protected]>; Kuehling, Felix <[email protected]>; Deucher, Alexander <[email protected]>; Chan, Hing Pong <[email protected]>; Luo, Zhigang <[email protected]>; Zhao, Victor <[email protected]>; Yat Sin, David <[email protected]>; Dhinakararam, Lokesh <[email protected]>
Subject: Re: [[PATCH v6]] drm/amdgpu: gate VM CPU HDP flush on reset lock; force-complete KIQ before VF reset

Quoted 19 lines · Chenglei

[AMD Official Use Only - AMD Internal Distribution Only]

Hi @Koenig, Christian,

Quoted 14 lines

void amdgpu_virt_pre_reset(struct amdgpu_device *adev) {

drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +10 -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);
Quoted 6 lines
Quoted 1 line
Quoted 1 line

Well that is unrelated and clearly incorrect. The KIQ is re-initialized through a reset and should *NEVER* be force signaled.

HW KIQ is re-inited after reset, but that path does not reinitialize or reset ring->fence_drv.
amdgpu_fence_driver_force_completion() is SW-only: pending dma_fences get -ECANCELED, writeback is set to sync_seq, and fences are signaled so bookkeeping and waiters reflect that the queue’s prior work will not complete on HW. Without that, seq/writeback can stay wrong and amdgpu_fence_emit_polling() can time out on later KIQ use.

The generic loop in amdgpu_device_pre_asic_reset() only force-completes scheduler-ready rings, so it skips KIQ. This VF path covers KIQ unless we add equivalent logic elsewhere. So we still need this SW cleanup to avoid KIQ fence state mismatch after reset.

Well you just explained it.

The KIQ is skipped in amdgpu_device_pre_asic_reset() because it doesn't use dma_fences and so calling amdgpu_fence_driver_force_completion() on it is absolutely nonsense.

I mean when there is an intentional skipping of calling a function why in the world do you think that you need to do that manually?

Regards,
Christian.

Quoted 123 lines

Thanks,
Chenglei

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Tuesday, April 7, 2026 1:07 PM
To: Xie, Chenglei <[email protected]>; [email protected]
Cc: Lazar, Lijo <[email protected]>; Kuehling, Felix <[email protected]>; Deucher, Alexander <[email protected]>; Chan, Hing Pong <[email protected]>; Luo, Zhigang <[email protected]>; Kasiviswanathan, Harish <[email protected]>; Zhao, Victor <[email protected]>; Yat Sin, David <[email protected]>; Dhinakararam, Lokesh <[email protected]>
Subject: Re: [[PATCH v6]] drm/amdgpu: gate VM CPU HDP flush on reset lock; force-complete KIQ before VF reset

Quoted 36 lines · Chenglei Xie

During GPU reset, the application could still run CPU page table
updates. Each commit called amdgpu_device_flush_hdp(), which on SR-IOV sends work through the KIQ ring. That can advance sync_seq while the GPU is being reset, leaving fence
writeback out of sync and causing amdgpu_fence_emit_polling() to time
out on later KIQ use.

Fix:
amdgpu_vm_cpu_commit():
Take reset_domain->sem with down_read_trylock() before amdgpu_device_flush_hdp(). If the reset path holds the write lock, skip the HDP flush so no HDP-related HW access (including KIQ) runs during reset; state is re-established after reset.

amdgpu_virt_pre_reset():
After stopping the data exchange thread and setting MP1 FLR state, call amdgpu_fence_driver_force_completion() on each initialized KIQ ring so pending fences are signalled and writeback is aligned before reset proceeds.

Change-Id I938bce0cab93a794dbdb02fe3ca9e041f9ac1424
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c   | 11 +++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c | 16 +++++++++++++++-
 2 files changed, 26 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +0 -0
index 6974b1c5b56c2..0127b0d6c7277 100644
@@ -1188,9 +1188,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 +2 -0
+     int i;
+
      /* stop the data exchange thread */

drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c enum amdgpu_sriov_vf_mode amdgpu_virt_get_sriov_vf_mode(struct amdgpu_device *ad · line 1203

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +8 -0
      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);

Well that is unrelated and clearly incorrect. The KIQ is re-initialized through a reset and should *NEVER* be force signaled.

Quoted 23 lines

+ }
}

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..a9e33b7e87406 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c +4 -0
@@ -21,6 +21,8 @@
  */
 
 #include "amdgpu_vm.h"
+#include "amdgpu.h"
+#include "amdgpu_reset.h"
 #include "amdgpu_object.h"
 #include "amdgpu_trace.h"
 
@@ -108,11 +110,23 @@ static int amdgpu_vm_cpu_update(struct
 amdgpu_vm_update_params *p,  static int amdgpu_vm_cpu_commit(struct amdgpu_vm_update_params *p,
                              struct dma_fence **fence)  {
+     struct amdgpu_device *adev = p->adev;
+

drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c static int amdgpu_vm_cpu_update(struct · line 122

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c +5 -1
      if (p->needs_flush)
              atomic64_inc(&p->vm->tlb_seq);
 
      mb();
-     amdgpu_device_flush_hdp(p->adev, NULL);
+     /*
+      * While GPU reset holds reset_domain write lock, skip HDP flush entirely so
+      * no HDP-related HW access runs during reset;
+      * reset re-establishes consistent state afterward.
+      */

That comment explains what is done but not why.

Rather use something like this:

/* A reset flushed the HDP anyway, so that here can be skipped when a reset is ongoing */

Regards,
Christian.

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c +6 -0
+     if (!down_read_trylock(&adev->reset_domain->sem))
+             return 0;
+
+     amdgpu_device_flush_hdp(adev, NULL);
+     up_read(&adev->reset_domain->sem);
+
      return 0;
 }