From: Li Sheng <wirsbf@gmail.com>
To: dri-devel@lists.freedesktop.org
Cc: "Philipp Stanner" <phasta@kernel.org>,
"Tvrtko Ursulin" <tvrtko.ursulin@igalia.com>,
"Matthew Brost" <matthew.brost@intel.com>,
"Danilo Krummrich" <dakr@kernel.org>,
"Christian König" <ckoenig.leichtzumerken@gmail.com>,
"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
"Maxime Ripard" <mripard@kernel.org>,
"Thomas Zimmermann" <tzimmermann@suse.de>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
linux-kernel@vger.kernel.org
Subject: [PATCH v2] drm/sched: Preserve entity->rq when no schedulers are ready
Date: Sun, 6 Dec 2026 19:29:58 +0800 [thread overview]
Message-ID: <20261206112958.929358-1-wirsbf@gmail.com> (raw)
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, preserve the existing
entity->rq if entity->rq->sched is still in entity->sched_list.
Otherwise (for example after drm_sched_entity_modify_sched() replaces
entity->sched_list to restrict jobs to a subset of engines), fall back
to entity->sched_list[0]->sched_rq[entity->rq_priority] when sched_rq
is non-NULL, matching drm_sched_entity_init().
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 v2:
- Handle the case where entity->rq->sched is no longer in
entity->sched_list after drm_sched_entity_modify_sched() by falling
back to entity->sched_list[0]->sched_rq[entity->rq_priority].
- 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 | 31 +++++++++++++++++++-----
1 file changed, 25 insertions(+), 6 deletions(-)
diff --git a/drivers/gpu/drm/scheduler/sched_entity.c b/drivers/gpu/drm/scheduler/sched_entity.c
index 03e68b410..de9e1e75f 100644
--- a/drivers/gpu/drm/scheduler/sched_entity.c
+++ b/drivers/gpu/drm/scheduler/sched_entity.c
@@ -595,14 +595,33 @@ 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) {
+ bool in_list = false;
+ unsigned int i;
+
+ for (i = 0; i < entity->num_sched_list; ++i) {
+ if (entity->rq &&
+ entity->sched_list[i] == entity->rq->sched) {
+ in_list = true;
+ break;
+ }
+ }
+
+ if (!in_list && entity->num_sched_list &&
+ entity->sched_list[0] && entity->sched_list[0]->sched_rq)
+ sched = entity->sched_list[0];
}
- if (entity->num_sched_list == 1)
- entity->sched_list = NULL;
+ if (sched) {
+ rq = sched->sched_rq[entity->rq_priority];
+ if (rq != 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
reply other threads:[~2026-12-06 11:30 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261206112958.929358-1-wirsbf@gmail.com \
--to=wirsbf@gmail.com \
--cc=airlied@gmail.com \
--cc=ckoenig.leichtzumerken@gmail.com \
--cc=dakr@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=matthew.brost@intel.com \
--cc=mripard@kernel.org \
--cc=phasta@kernel.org \
--cc=simona@ffwll.ch \
--cc=tvrtko.ursulin@igalia.com \
--cc=tzimmermann@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®