* [PATCH v2] drm/amdgpu: fix task hang from failed job submission during process kill
@ 2025-08-12 8:31 Liu01 Tong
2025-08-12 8:47 ` Christian König
2025-08-12 20:05 ` Matthew Schwartz
0 siblings, 2 replies; 3+ messages in thread
From: Liu01 Tong @ 2025-08-12 8:31 UTC (permalink / raw)
To: amd-gfx; +Cc: christian.koenig, gang.ba, Liu01 Tong, Lin . Cao
During process kill, drm_sched_entity_flush() will kill the vm
entities. The following job submissions of this process will fail, and
the resources of these jobs have not been released, nor have the fences
been signalled, causing tasks to hang and timeout.
Fix by check entity status in amdgpu_vm_ready() and avoid submit jobs to
stopped entity.
v2: add amdgpu_vm_ready() check before amdgpu_vm_clear_freed() in
function amdgpu_cs_vm_handling().
Signed-off-by: Liu01 Tong <Tong.Liu01@amd.com>
Signed-off-by: Lin.Cao <lincao12@amd.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 3 +++
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 15 +++++++++++----
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index e1e48e6f1f35..cdc02860011c 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -1138,6 +1138,9 @@ static int amdgpu_cs_vm_handling(struct amdgpu_cs_parser *p)
}
}
+ if (!amdgpu_vm_ready(vm))
+ return -EINVAL;
+
r = amdgpu_vm_clear_freed(adev, vm, NULL);
if (r)
return r;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 283dd44f04b0..bf42246a3db2 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -654,11 +654,10 @@ int amdgpu_vm_validate(struct amdgpu_device *adev, struct amdgpu_vm *vm,
* Check if all VM PDs/PTs are ready for updates
*
* Returns:
- * True if VM is not evicting.
+ * True if VM is not evicting and all VM entities are not stopped
*/
bool amdgpu_vm_ready(struct amdgpu_vm *vm)
{
- bool empty;
bool ret;
amdgpu_vm_eviction_lock(vm);
@@ -666,10 +665,18 @@ bool amdgpu_vm_ready(struct amdgpu_vm *vm)
amdgpu_vm_eviction_unlock(vm);
spin_lock(&vm->status_lock);
- empty = list_empty(&vm->evicted);
+ ret &= list_empty(&vm->evicted);
spin_unlock(&vm->status_lock);
- return ret && empty;
+ spin_lock(&vm->immediate.lock);
+ ret &= !vm->immediate.stopped;
+ spin_unlock(&vm->immediate.lock);
+
+ spin_lock(&vm->delayed.lock);
+ ret &= !vm->delayed.stopped;
+ spin_unlock(&vm->delayed.lock);
+
+ return ret;
}
/**
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] drm/amdgpu: fix task hang from failed job submission during process kill
2025-08-12 8:31 [PATCH v2] drm/amdgpu: fix task hang from failed job submission during process kill Liu01 Tong
@ 2025-08-12 8:47 ` Christian König
2025-08-12 20:05 ` Matthew Schwartz
1 sibling, 0 replies; 3+ messages in thread
From: Christian König @ 2025-08-12 8:47 UTC (permalink / raw)
To: Liu01 Tong, amd-gfx; +Cc: gang.ba, Lin . Cao
On 12.08.25 10:31, Liu01 Tong wrote:
> During process kill, drm_sched_entity_flush() will kill the vm
> entities. The following job submissions of this process will fail, and
> the resources of these jobs have not been released, nor have the fences
> been signalled, causing tasks to hang and timeout.
>
> Fix by check entity status in amdgpu_vm_ready() and avoid submit jobs to
> stopped entity.
>
> v2: add amdgpu_vm_ready() check before amdgpu_vm_clear_freed() in
> function amdgpu_cs_vm_handling().
>
> Signed-off-by: Liu01 Tong <Tong.Liu01@amd.com>
> Signed-off-by: Lin.Cao <lincao12@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 3 +++
> drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 15 +++++++++++----
> 2 files changed, 14 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> index e1e48e6f1f35..cdc02860011c 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> @@ -1138,6 +1138,9 @@ static int amdgpu_cs_vm_handling(struct amdgpu_cs_parser *p)
> }
> }
>
> + if (!amdgpu_vm_ready(vm))
> + return -EINVAL;
> +
> r = amdgpu_vm_clear_freed(adev, vm, NULL);
> if (r)
> return r;
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> index 283dd44f04b0..bf42246a3db2 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> @@ -654,11 +654,10 @@ int amdgpu_vm_validate(struct amdgpu_device *adev, struct amdgpu_vm *vm,
> * Check if all VM PDs/PTs are ready for updates
> *
> * Returns:
> - * True if VM is not evicting.
> + * True if VM is not evicting and all VM entities are not stopped
> */
> bool amdgpu_vm_ready(struct amdgpu_vm *vm)
> {
> - bool empty;
> bool ret;
>
> amdgpu_vm_eviction_lock(vm);
> @@ -666,10 +665,18 @@ bool amdgpu_vm_ready(struct amdgpu_vm *vm)
> amdgpu_vm_eviction_unlock(vm);
>
> spin_lock(&vm->status_lock);
> - empty = list_empty(&vm->evicted);
> + ret &= list_empty(&vm->evicted);
> spin_unlock(&vm->status_lock);
>
> - return ret && empty;
> + spin_lock(&vm->immediate.lock);
> + ret &= !vm->immediate.stopped;
> + spin_unlock(&vm->immediate.lock);
> +
> + spin_lock(&vm->delayed.lock);
> + ret &= !vm->delayed.stopped;
> + spin_unlock(&vm->delayed.lock);
> +
> + return ret;
> }
>
> /**
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] drm/amdgpu: fix task hang from failed job submission during process kill
2025-08-12 8:31 [PATCH v2] drm/amdgpu: fix task hang from failed job submission during process kill Liu01 Tong
2025-08-12 8:47 ` Christian König
@ 2025-08-12 20:05 ` Matthew Schwartz
1 sibling, 0 replies; 3+ messages in thread
From: Matthew Schwartz @ 2025-08-12 20:05 UTC (permalink / raw)
To: Liu01 Tong, amd-gfx; +Cc: christian.koenig, gang.ba, Lin . Cao
On 8/12/25 1:31 AM, Liu01 Tong wrote:
> During process kill, drm_sched_entity_flush() will kill the vm
> entities. The following job submissions of this process will fail, and
> the resources of these jobs have not been released, nor have the fences
> been signalled, causing tasks to hang and timeout.
>
> Fix by check entity status in amdgpu_vm_ready() and avoid submit jobs to
> stopped entity.
>
> v2: add amdgpu_vm_ready() check before amdgpu_vm_clear_freed() in
> function amdgpu_cs_vm_handling().
>
> Signed-off-by: Liu01 Tong <Tong.Liu01@amd.com>
> Signed-off-by: Lin.Cao <lincao12@amd.com>
Closes: https://lore.kernel.org/regressions/f2b70e6e-bff6-42f3-82a2-81eed892cc30@linux.dev/
Tested-by: Matthew Schwartz <matthew.schwartz@linux.dev>
Thanks,
Matt
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 3 +++
> drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 15 +++++++++++----
> 2 files changed, 14 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> index e1e48e6f1f35..cdc02860011c 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> @@ -1138,6 +1138,9 @@ static int amdgpu_cs_vm_handling(struct amdgpu_cs_parser *p)
> }
> }
>
> + if (!amdgpu_vm_ready(vm))
> + return -EINVAL;
> +
> r = amdgpu_vm_clear_freed(adev, vm, NULL);
> if (r)
> return r;
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> index 283dd44f04b0..bf42246a3db2 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> @@ -654,11 +654,10 @@ int amdgpu_vm_validate(struct amdgpu_device *adev, struct amdgpu_vm *vm,
> * Check if all VM PDs/PTs are ready for updates
> *
> * Returns:
> - * True if VM is not evicting.
> + * True if VM is not evicting and all VM entities are not stopped
> */
> bool amdgpu_vm_ready(struct amdgpu_vm *vm)
> {
> - bool empty;
> bool ret;
>
> amdgpu_vm_eviction_lock(vm);
> @@ -666,10 +665,18 @@ bool amdgpu_vm_ready(struct amdgpu_vm *vm)
> amdgpu_vm_eviction_unlock(vm);
>
> spin_lock(&vm->status_lock);
> - empty = list_empty(&vm->evicted);
> + ret &= list_empty(&vm->evicted);
> spin_unlock(&vm->status_lock);
>
> - return ret && empty;
> + spin_lock(&vm->immediate.lock);
> + ret &= !vm->immediate.stopped;
> + spin_unlock(&vm->immediate.lock);
> +
> + spin_lock(&vm->delayed.lock);
> + ret &= !vm->delayed.stopped;
> + spin_unlock(&vm->delayed.lock);
> +
> + return ret;
> }
>
> /**
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-08-13 10:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-12 8:31 [PATCH v2] drm/amdgpu: fix task hang from failed job submission during process kill Liu01 Tong
2025-08-12 8:47 ` Christian König
2025-08-12 20:05 ` Matthew Schwartz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).