drm/amdgpu: Fix race condition in amdgpu_vm_wait_idle during process kill
Subsystems (2)
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
@@ -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
Christian König
maintainerQuoted 7 lines · On 07.08.25 10:46, Liu01 Tong wrote:
The early commit
b8adc31cc0ca("drm/amdgpu: Avoid extra evict-restore process.") changedamdgpu_vm_wait_idleto usedrm_sched_entity_flushinstead ofdma_resv_wait_timeoutto 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.
Signed-off-by Liu01 Tong <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +7
-0@@ -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;