All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/scheduler: signal fences of jobs pushed to a stopped entity
@ 2026-10-22 10:54 Olivier Kaloudoff
  2026-10-22 11:12 ` sashiko-bot
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Olivier Kaloudoff @ 2026-10-22 10:54 UTC (permalink / raw)
  To: dri-devel
  Cc: amd-gfx, christian.koenig, alexander.deucher, tvrtko.ursulin,
	phasta, Olivier Kaloudoff

drm_sched_entity_push_job() queues the job on entity->job_queue first,
then drm_sched_rq_add_entity() notices entity->stopped under
entity->lock, prints "Trying to push to a killed entity" and returns
NULL. The scheduler is never woken, the job strands on the spsc queue
forever, and its fences never signal, hanging any task that waits on
them.

One way to hit this is process kill racing a late submission from the
same address space: an amdkfd SVM migration job submitted from the
fault path of a dying process (SIGBUS on device unplug -> coredump ->
get_dump_page -> svm_migrate_to_ram) lands on the process's already
killed entity and is never completed, which then wedges the entire
PCIe hot-unplug removal thread.

Check entity->stopped under entity->lock before queueing; since
drm_sched_entity_kill() only sets ->stopped while holding that same
lock, this cannot race. A job pushed to a stopped entity is never
queued; instead it is run through the normal kill-jobs work so its
finished fence completes with -ESRCH, exactly like the jobs drained by
drm_sched_entity_kill() itself. The sched->score increment is balanced
explicitly since drm_sched_job_done() only decrements it for jobs that
actually run.

An earlier attempt [1] checked ->stopped without holding entity->lock
and was rejected as racy; this performs the check under the lock where
->stopped is written.

Note: Tvrtko Ursulin's entity run-queue consolidation series [2]
moves this code around, making drm_sched_entity_push_job() lockless
and taking entity->lock inside drm_sched_rq_add_entity() instead.
The orphan survives that series unchanged -- the job is queued before
the NULL return and nothing completes it -- so this fix stays needed
whichever lands first; the loser's side just needs a context rebase.

[1] https://lore.kernel.org/dri-devel/20250811072050.3838241-1-Tong.Liu01@amd.com/
[2] https://lists.freedesktop.org/archives/amd-gfx/2026-April/142980.html

Fixes: 62347a33001c ("drm/scheduler: Add stopped flag to drm_sched_entity")
Signed-off-by: Olivier Kaloudoff <olivier.kaloudoff@gmail.com>
Cc: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Cc: Philipp Stanner <phasta@kernel.org>
Cc: "Christian König" <christian.koenig@amd.com>
---
 drivers/gpu/drm/scheduler/sched_entity.c | 21 ++
 1 file changed, 21 insertions(+), 0 deletions(-)

diff --git a/drivers/gpu/drm/scheduler/sched_entity.c b/drivers/gpu/drm/scheduler/sched_entity.c
index 673ca9cbf..22ecc9bfd 100644
--- a/drivers/gpu/drm/scheduler/sched_entity.c
+++ b/drivers/gpu/drm/scheduler/sched_entity.c
@@ -651,6 +651,27 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job)
 
 	spin_lock(&entity->lock);
 
+	/*
+	 * A stopped entity is never put back on a run queue, so a job
+	 * queued on it would be stranded forever and its fences would
+	 * never signal, hanging any task waiting on them. Don't queue
+	 * the job at all; run the normal kill-jobs work on it so its
+	 * finished fence completes with -ESRCH.
+	 */
+	if (unlikely(entity->stopped)) {
+		spin_unlock(&entity->lock);
+		/*
+		 * Balance the atomic_inc(&sched->score) above; the
+		 * decrement in drm_sched_job_done() only happens when
+		 * the job actually runs on a scheduler.
+		 */
+		atomic_dec(entity->rq->sched->score);
+		DRM_ERROR("Trying to push to a killed entity\n");
+		INIT_WORK(&sched_job->work, drm_sched_entity_kill_jobs_work);
+		schedule_work(&sched_job->work);
+		return;
+	}
+
 	first = spsc_queue_push(&entity->job_queue, &sched_job->queue_node);
 
 	/* first job wakes up scheduler */
-- 
2.39.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-10-22 15:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-22 10:54 [PATCH] drm/scheduler: signal fences of jobs pushed to a stopped entity Olivier Kaloudoff
2026-10-22 11:12 ` sashiko-bot
2026-10-22 11:42 ` Philipp Stanner
2026-10-22 15:06 ` Christian König

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.