On 18/11/2026 12:00, Philipp Stanner wrote:
Why do you call "single scheduler" a special case? That seems to be
quite a common case.

Special case a) in the code:

drm_sched_entity_init
{
...
        entity->sched_list = num_sched_list > 1 ? sched_list : NULL;


drm_sched_entity_select_rq
{
...
        if (entity->num_sched_list == 1)
                entity->sched_list = NULL;

And b) in the API contract, where when:

1)
drm_sched_entity_init num_sched_list == 1

Caller can pass in a stack sched_list container (as many if not all current callers do) ie. does not have to keep it valid for the lifetime of the entity;

and 2)
drm_sched_entity_init num_sched_list > 1

Caller MUST ensure the sched_list containers remains valid for the lifetime of the entity.

On Tue, 2026-11-17 at 10:06 +0000, Tvrtko Ursulin wrote:
In order to untangle all this lets make this area behave consistently and
store the single scheduler case directly in the entity. We can do that
easily by creating an union between the current pointer to a list of
schedulers, and a new pointer to the single scheduler.

This allows removal of the special cases which artificially cleared
entity->sched_list for a single scheduler case and fixes the amdgpu
dynamic priority changes for the single IP instances.

Signed-off-by: Tvrtko Ursulin <[email protected]>
Fixes: b3ac17667f11 ("drm/scheduler: rework entity creation")

Can you describe what the actual bug is?

It's explained in the commit message, but in short:

1)
drm_sched_entity_init calling convention (sched_list ownership rules) is dangerous and undocumented.

2)
drm_sched_entity_set_priority is broken when num_sched_list == 1 due above listed special casing.

Furthermore, the special casing, from the analysis presented in the commit message, appears to be a kludge to work around the UAF due unclear sched_list ownership/lifetime rules.

References: 8c23056bdc7a ("drm/scheduler: do not keep a copy of sched list")
References: 977f7e1068be ("drm/amdgpu: allocate entities on demand")
References: 2316a86bde49 ("drm/amdgpu: change hw sched list on ctx priority 
override")
References: ac4eb83ab255 ("drm/sched: select new rq even if there is only one 
v3")
References: 981b04d96856 ("drm/sched: improve docs around drm_sched_entity")
References: 77a6809f1dc3 ("drm/sched: Remove FIFO and RR and simplify to a single 
run queue")

This commit has been reverted.

It is stil a valid reference since with that commit the broken drm_sched_entity_set_priority() was fixed in a different way.

Recently, I often end up a confused by your series'. Is this here
another RFC?

No, it's a fix.

I appreciate one needs to devote sufficient time to stay on top of them. Recently you kindly reviewed a series where all patches were about drm_sched_init. This series is all about drm_sched_entity_init.

Is it a preparational patch for your CFS work?

Nope, it is a fix and clarification for drm_sched_entity_init().

   *
- * Note that the &sched_list must have at least one element to schedule the 
entity.
+ * Note that the &sched_list must have exactly one element to schedule the
+ * entity. Callers which pass more than one scheduler on the @sched_list must
+ * ensure the list remains valid for the lifetime of the entity.

What does that even mean, "valid"? Like, not deallocated?

Yes.

How does drm_sched_entity_modify_sched() play into that?

Same issue as drm_sched_entity_init because first job arm will clear the sched_list when num_sched_list == 1, which means run-queue cannot be change ever after.
-       sched = drm_sched_pick_best(entity->sched_list, entity->num_sched_list);
+       if (entity->num_sched_list == 1)
+               sched = entity->sched;
+       else
+               sched = drm_sched_pick_best(entity->sched_list,
+                                           entity->num_sched_list);

So what you want to achieve is that sched_list can never be NULL? How's
that a bug?

Null sched_list prevent run-queue changes with FIFO and RR.

-       struct drm_gpu_scheduler        **sched_list;
+       union {
+               /**
+                * @sched_list:
+                *
+                * A list of schedulers (struct drm_gpu_scheduler).  Jobs from
+                * this entity can be scheduled on any scheduler on this list.
+                *
+                * This can be modified by calling
+                * drm_sched_entity_modify_sched(). Locking is entirely up to
+                * the driver, see the above function for more details.
+                */
+               struct drm_gpu_scheduler        **sched_list;
+
+               /**
+                * @sched:
+                *
+                * A single struct drm_gpu_scheduler jobs from this entity will
+                * be scheduled on.
+                *
+                * This can be modified by calling
+                * drm_sched_entity_modify_sched(). Locking is entirely up to
+                * the driver, see the above function for more details.
+                */
+               struct drm_gpu_scheduler        *sched;
+       };

So you now would have some mode where there is sometimes a list and
sometimes a pointer, and what it is can change dynamically through
drm_sched_entity_modify_sched()??

How would that untangle anything?

I hope it is clearer after this reply? Commit message is complicated for a reason - because the history of the num_sched_list == 1 special case is equally complicated and confused.

Tvrtko

Reply via email to