* [PATCH v3] drm/sched: Preserve entity->rq when no schedulers are ready
@ 2026-12-06 14:03 Li Sheng
0 siblings, 0 replies; only message in thread
From: Li Sheng @ 2026-12-06 14:03 UTC (permalink / raw)
To: dri-devel
Cc: Philipp Stanner, Tvrtko Ursulin, Matthew Brost, Danilo Krummrich,
Christian König, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, linux-kernel
Commit 6d602e031103 ("drm/sched: move calling
drm_sched_entity_select_rq") moved drm_sched_entity_select_rq() into
drm_sched_job_arm() immediately before dereferencing entity->rq->sched.
Later, commit 2df5efb45425 ("drm/sched: Remove redundant entity->rq
initialization and checks") also removed the !entity->rq checks from
drm_sched_entity_kill(), drm_sched_entity_flush(), and
drm_sched_job_init() under the assumption that entity->rq can never be
NULL once an entity is initialized.
However, when drm_sched_entity_select_rq() is called and all
schedulers in entity->sched_list have !sched->ready (for example when
amdgpu marks rings not ready during reset or teardown),
drm_sched_pick_best() returns NULL and drm_sched_entity_select_rq()
overwrites entity->rq with NULL. Immediately afterwards,
drm_sched_job_arm() dereferences entity->rq->sched unconditionally, and
drm_sched_entity_push_job(), drm_sched_entity_kill(),
drm_sched_entity_flush(), and drm_sched_entity_wakeup() likewise assume
entity->rq is non-NULL.
When drm_sched_pick_best() returns NULL, select entity->rq->sched if it
is still in entity->sched_list with a valid sched_rq, or otherwise fall
back to the first entry in entity->sched_list with a non-NULL sched_rq
(handling drm_sched_entity_modify_sched()). Passing that scheduler
through the normal run-queue update path preserves entity->rq != NULL
while also handling priority changes and num_sched_list == 1 cleanup
consistently.
Fixes: 6d602e031103 ("drm/sched: move calling drm_sched_entity_select_rq")
Fixes: 2df5efb45425 ("drm/sched: Remove redundant entity->rq initialization and checks")
Cc: stable@vger.kernel.org
Signed-off-by: Li Sheng <wirsbf@gmail.com>
---
Changes in v3:
- Assign sched = entity->rq->sched when the current scheduler is still
in entity->sched_list (with non-NULL sched_rq) so FIFO/RR priority
run-queue updates and num_sched_list == 1 sched_list cleanup still run.
- Fall back to the first entry in entity->sched_list with a non-NULL
sched_rq (rather than only sched_list[0]), and guard entity->rq before
drm_sched_rq_remove_entity().
Changes in v2:
- Handle the case where entity->rq->sched is no longer in
entity->sched_list after drm_sched_entity_modify_sched().
- Add Fixes: 6d602e031103 ("drm/sched: move calling
drm_sched_entity_select_rq") for older stable trees.
- Drop the drm_sched_job_init() kernel-doc removal so the fix
backports cleanly to stable kernels that still return -ENOENT.
drivers/gpu/drm/scheduler/sched_entity.c | 36 ++++++++++++++++++++----
1 file changed, 30 insertions(+), 6 deletions(-)
diff --git a/drivers/gpu/drm/scheduler/sched_entity.c b/drivers/gpu/drm/scheduler/sched_entity.c
index 03e68b410..f3e1d01f9 100644
--- a/drivers/gpu/drm/scheduler/sched_entity.c
+++ b/drivers/gpu/drm/scheduler/sched_entity.c
@@ -595,14 +595,38 @@ void drm_sched_entity_select_rq(struct drm_sched_entity *entity)
}
sched = drm_sched_pick_best(entity->sched_list, entity->num_sched_list);
- rq = sched ? sched->sched_rq[entity->rq_priority] : NULL;
- if (rq != entity->rq) {
- drm_sched_rq_remove_entity(entity->rq, entity);
- entity->rq = rq;
+ if (!sched) {
+ struct drm_gpu_scheduler *fallback = NULL;
+ unsigned int i;
+
+ for (i = 0; i < entity->num_sched_list; ++i) {
+ struct drm_gpu_scheduler *s = entity->sched_list[i];
+
+ if (!s || !s->sched_rq)
+ continue;
+ if (entity->rq && s == entity->rq->sched) {
+ sched = s;
+ break;
+ }
+ if (!fallback)
+ fallback = s;
+ }
+
+ if (!sched)
+ sched = fallback;
}
- if (entity->num_sched_list == 1)
- entity->sched_list = NULL;
+ if (sched) {
+ rq = sched->sched_rq[entity->rq_priority];
+ if (rq != entity->rq) {
+ if (entity->rq)
+ drm_sched_rq_remove_entity(entity->rq, entity);
+ entity->rq = rq;
+ }
+
+ if (entity->num_sched_list == 1)
+ entity->sched_list = NULL;
+ }
spin_unlock(&entity->lock);
}
--
2.56.1
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-12-06 14:03 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-06 14:03 [PATCH v3] drm/sched: Preserve entity->rq when no schedulers are ready Li Sheng
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®