Skip to contentSkip to conversation

drm/sched: Fix bounds limiting when given a malformed entity

PATCH New Luben Tuikov 1 participant 1 message Nov 23, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/sched: Fix bounds limiting when given a malformed entity

If we're given a malformed entity in drm_sched_entity_init()--shouldn't happen, but we verify--with out-of-bounds priority value, we set it to an allowed value. Fix the expression which sets this limit.

Fixes 56e449603f0ac5 ("drm/sched: Convert the GPU scheduler to variable number of run-queues")
---
 drivers/gpu/drm/scheduler/sched_entity.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/gpu/drm/scheduler/sched_entity.c +6 -3
index 4d42b1e4daa67f..20c9c561843ce1 100644
@@ -84,9 +84,12 @@ int drm_sched_entity_init(struct drm_sched_entity *entity,
 		/* The "priority" of an entity cannot exceed the number
 		 * of run-queues of a scheduler.
 		 */
-		if (entity->priority >= sched_list[0]->num_rqs)
-			entity->priority = max_t(u32, sched_list[0]->num_rqs,
-						 DRM_SCHED_PRIORITY_MIN);
+		if (entity->priority >= sched_list[0]->num_rqs) {
+			drm_err(sched_list[0], "entity with out-of-bounds priority:%u num_rqs:%u\n",
+				entity->priority, sched_list[0]->num_rqs);
+			entity->priority = max_t(s32, (s32) sched_list[0]->num_rqs - 1,
+						 (s32) DRM_SCHED_PRIORITY_MIN);
+		}
 		entity->rq = sched_list[0]->sched_rq[entity->priority];
 	}
 

base-commit: b3c5a7de9aeb51cb19160f3f61343ed87487abde

Signature · 1 line
2.43.0