drm_sched_job_init() is just racing when checking an entity's runqueue, without
taking the proper spinlock.

Add the lock.

Cc: [email protected] # 6.7+
Fixes: 56e449603f0a ("drm/sched: Convert the GPU scheduler to variable number 
of run-queues")
Signed-off-by: Philipp Stanner <[email protected]>
---
 drivers/gpu/drm/scheduler/sched_main.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/scheduler/sched_main.c 
b/drivers/gpu/drm/scheduler/sched_main.c
index 7f938f491b6f..30028054385f 100644
--- a/drivers/gpu/drm/scheduler/sched_main.c
+++ b/drivers/gpu/drm/scheduler/sched_main.c
@@ -799,7 +799,12 @@ int drm_sched_job_init(struct drm_sched_job *job,
                       u32 credits, void *owner,
                       uint64_t drm_client_id)
 {
-       if (!entity->rq) {
+       struct drm_sched_rq *rq;
+
+       spin_lock(&entity->lock);
+       rq = entity->rq;
+       spin_unlock(&entity->lock);
+       if (!rq) {
                /* This will most likely be followed by missing frames
                 * or worse--a blank screen--leave a trail in the
                 * logs, so this can be debugged easier.
-- 
2.49.0

Reply via email to