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

[PATCH v2] xen/sched: Fix the sorted insertion in sched_domain_insert_unit()


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Stefano Stabellini <stefano.stabellini@xxxxxxx>
  • Date: Mon, 26 Oct 2026 16:39:36 -0700
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ahjVg/6HXjNeC9J3Powm8bLZ+kSAojsaF2JTC35Yw3o=; b=erVn3ZqjSODOGnyom7m6vQpMBf4ArGInUEFWZ5NM3xoL91e7z6FYhg9U10pIZqIVVHm51ArTpFXMuERjyamtir2NBaKo6h7y9fpq1rWfIsChJeelo/kPxje17rCX6fLOY7QTRCmDVeSY+dzRayxT2zYftH2KSq2xD6CE74jMMJ3osyALGZtXPk7ed+NWzBe+kqjxAw99CBETH8JvpfsJgilL+iN08f5DbFX14zE68X41cRv3LC5VArhSM2ZDqieskLe9Pk4hZ8VqDVPQoYOdeNd4tHBwRp2cq9E1/yOXbsuR4YXjl9K5clR9TQNYcOPlHeGu5D/OsZf+7rwYrC9O4w==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=L2jNLnWBXlUH4tfKsHhu7NA8BxxgBPZ6jLYXMgU1BQoArO6GzvsQ2Sb8sacP1sClb8pubJkwYh//mZNWlH4EImcbQcn0FqF0Jv+YqZo9FS3/WEkIrCCd/oUVkIZe4gmMpY51LtQlRyMqHKTglY/fS3sHVQZzoFHkWR4y4YpOHSzppnySjNA8Vk/L5qFfJ5wh8n4Vz2dH4Cu+WtGqRy5me8qx7puwDsvY6R1pvQxEH8zyOOIZ/c0aQW+6V0XRcgj8mkV8/u7tqC139a+rUld/dmhVz3V2EtmqJY+IyAOPQ1+a3E0N1b5A+UsBTrlNDo3yszaSGuNKeXUvUxbxBoDRuA==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=amd.com header.i="@amd.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Cc: Stefano Stabellini <stefano.stabellini@xxxxxxx>, <dfaggioli@xxxxxxxx>, <jgross@xxxxxxxx>, <gwd@xxxxxxxxxxxxxx>, <jbeulich@xxxxxxxx>
  • Delivery-date: Mon, 26 Oct 2026 23:40:21 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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>
---
Changes in v2:
- rename prev_unit to next_unit
- add a Fixes tag
- reword the second paragraph of the commit message

 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 0b072bdee6..88ae40f954 100644
--- a/xen/common/sched/core.c
+++ b/xen/common/sched/core.c
@@ -483,18 +483,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)
-- 
2.47.3




 


Rackspace

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