Skip to contentSkip to conversation

drm/amdgpu: Fix race condition in amdgpu_vm_wait_idle during process kill

PATCH In review Liu01 Tong 2 participants 2 messages Aug 7, 2025

Subsystems (2)
lore
Share & tools
lore

Liu01 Tong

author
#0 lore raw

PATCH 1/1 drm/amdgpu: Fix race condition in amdgpu_vm_wait_idle during process kill

The early commit b8adc31cc0ca ("drm/amdgpu: Avoid extra evict-restore process.") changed amdgpu_vm_wait_idle to use drm_sched_entity_flush instead of dma_resv_wait_timeout to avoid KFD eviction fence signaling. But this introduce a race condition when processes are killed.

During process kill, drm_sched_entity_flush() will kill the vm entities. Concurrent job submissions of this process will fail.

Fix by skipping vm entity flushing when the process is being killed.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +7 -0
index 283dd44f04b0..ae43a378f866 100644
@@ -2415,6 +2415,13 @@ void amdgpu_vm_adjust_size(struct amdgpu_device *adev, uint32_t min_vm_size,
  */
 long amdgpu_vm_wait_idle(struct amdgpu_vm *vm, long timeout)
 {
+	/* If the process is being killed, skip flush VM entities
+	 * as entities of concurrent job submission of this process
+	 * might be in an inconsistent state
+	 */
+	if (current->flags & PF_EXITING)
+		return timeout;
+
 	timeout = drm_sched_entity_flush(&vm->immediate, timeout);
 	if (timeout <= 0)
 		return timeout;
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 7 lines · On 07.08.25 10:46, Liu01 Tong wrote:

The early commit b8adc31cc0ca ("drm/amdgpu: Avoid extra evict-restore process.") changed amdgpu_vm_wait_idle to use drm_sched_entity_flush instead of dma_resv_wait_timeout to avoid KFD eviction fence signaling. But this introduce a race condition when processes are killed.

During process kill, drm_sched_entity_flush() will kill the vm entities. Concurrent job submissions of this process will fail.

Clear NAK to that. This is essentially why we call drm_sched_entity_flush() here in the first place.

Regards,
Christian.

Quoted 26 lines

Fix by skipping vm entity flushing when the process is being killed.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +7 -0
index 283dd44f04b0..ae43a378f866 100644
@@ -2415,6 +2415,13 @@ void amdgpu_vm_adjust_size(struct amdgpu_device *adev, uint32_t min_vm_size,
  */
 long amdgpu_vm_wait_idle(struct amdgpu_vm *vm, long timeout)
 {
+	/* If the process is being killed, skip flush VM entities
+	 * as entities of concurrent job submission of this process
+	 * might be in an inconsistent state
+	 */
+	if (current->flags & PF_EXITING)
+		return timeout;
+
 	timeout = drm_sched_entity_flush(&vm->immediate, timeout);
 	if (timeout <= 0)
 		return timeout;