[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[xen staging-4.22] xen/sched: Fix the sorted insertion in sched_domain_insert_unit()



commit 20d30dc07d9963b014d1f55581696aa0f5167d14
Author:     Stefano Stabellini <stefano.stabellini@xxxxxxx>
AuthorDate: Thu Oct 29 13:19:11 2026 +0100
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Thu Oct 29 13:19:11 2026 +0100

    xen/sched: Fix the sorted insertion in sched_domain_insert_unit()
    
    The loop links the new unit in front of the unit whose successor has a
    higher unit_id, rather than after it: inserting 1 into {0, 2} gives
    {1, 0, 2}. Stop at the first unit with a higher unit_id instead.
    
    This goes unnoticed as long as units are inserted in unit_id order, as
    guest vCPUs typically are.
    
    Also rename prev_unit to next_unit: the new unit is linked in front of
    *next_unit, not after it.
    
    Fixes: 141db7fd4d2d ("xen/sched: build a linked list of struct sched_unit")
    Signed-off-by: Stefano Stabellini <stefano.stabellini@xxxxxxx>
    Reviewed-by: Juergen Gross <jgross@xxxxxxxx>
    master commit: 999c22e4818a838724c2a89cbd856ae0e4e8b15c
    master date: 2026-10-27 13:41:46 -0700
---
 xen/common/sched/core.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/xen/common/sched/core.c b/xen/common/sched/core.c
index a4678ceafb..fbbe3bb853 100644
--- a/xen/common/sched/core.c
+++ b/xen/common/sched/core.c
@@ -478,18 +478,17 @@ static struct sched_unit *sched_alloc_unit_mem(void)
 
 static void sched_domain_insert_unit(struct sched_unit *unit, struct domain *d)
 {
-    struct sched_unit **prev_unit;
+    struct sched_unit **next_unit;
 
     unit->domain = d;
 
-    for ( prev_unit = &d->sched_unit_list; *prev_unit;
-          prev_unit = &(*prev_unit)->next_in_list )
-        if ( (*prev_unit)->next_in_list &&
-             (*prev_unit)->next_in_list->unit_id > unit->unit_id )
+    for ( next_unit = &d->sched_unit_list; *next_unit;
+          next_unit = &(*next_unit)->next_in_list )
+        if ( (*next_unit)->unit_id > unit->unit_id )
             break;
 
-    unit->next_in_list = *prev_unit;
-    *prev_unit = unit;
+    unit->next_in_list = *next_unit;
+    *next_unit = unit;
 }
 
 static struct sched_unit *sched_alloc_unit(struct vcpu *v)
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.22



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.