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

[PATCH v3] xen/arm: Fix sibling mask setup to only include online CPUs


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Hirokazu Takahashi <taka@xxxxxxxxxxxxx>
  • Date: Thu, 26 Nov 2026 13:43:40 +0900
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=valinux.co.jp; dmarc=pass action=none header.from=valinux.co.jp; dkim=pass header.d=valinux.co.jp; arc=none
  • 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=6EY/xPu9BHTFirjCN8BQ/7xXpDdD575oLiFsMJTyZdw=; b=SqB9JcxKV8lpr5NZbX6q3a1AQQLj8/eozgmtokBJ0UZS10zhbqOJEezlt9NRm0lKEg6M+hSSBxUcixtZ5nI/t+f6f/sOcA/gIowUCKBB8JGACycccU7gxDgtMrf4t3IZovqRPoc5AwbPBX7KZr/fu+Vrsri2MSJcWpGXxf4Nt4AHd1B+DzK6WoHl0kZLb7dyTTbIxg7t0znonR8Z8vrB5a6CxsjOr0jS+CzbcL2r9UKWF25yrUx0/DZ98IM1B1ASI4vj5HuN0QzbX1RCWoPbdiLjNY85J2b3dwFiQIZBRT0Rc/jRvbJ0Fe2ZFO2GZIWmx0/GrQiadApPD4CJT57EdA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=LS5H2RVudEJ5Ga2Q3sIaZF4VFbAHd1u1ENiic6XezMgm6BXNXNloosZUQDU+lqHvfL5s4ODrhu7F+j5TOyzxoHHauxk4hWpmmAXnq9liwrkeGwWsr0CtU02g4C8IDg+A12mSlTQe/DWwCimn2JgMfaHRlrTRuWHmdRU9bXbIuq3nkULvzB2wnIDHJR62lSawBVhyKeZey75CUbDh1dpUtAxIukubN2G55XxxXJ4sv71hPx1WOBLC11l1Y+AN4xSM7lq1E6Lbs6L14Dk5tBJAarDRBlDaFkWNpGQ2bpMlnhkyM2Y4G5gGrJIGE9ilYG54dJOTDyPBDE+1abgk6uNS/A==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=valinux.co.jp header.i="@valinux.co.jp" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Authentication-results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=valinux.co.jp;
  • Cc: michal.orzel@xxxxxxx, jbeulich@xxxxxxxx, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Hirokazu Takahashi <taka@xxxxxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>
  • Delivery-date: Thu, 26 Nov 2026 04:45:01 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Populate the CPU sibling map only with CPUs that are brought
online. Currently, all CPUs in cpu_possible_map are added,
which leaves CPUs that failed to boot in the sibling masks and
may lead the scheduler to make incorrect decisions.

Fixes: 701190abb3d5 ("xen/arm: Set correct per-cpu cpu_core_mask")
Signed-off-by: Hirokazu Takahashi <taka@xxxxxxxxxxxxx>
---
Changes in v3:
- Remove the CPU from sibling maps when it goes down, introducing
  remove_siblinginfo() to match x86 Xen.
- Change the cpu parameter type of set_cpu_sibling_map() to
  'unsigned int' to align with x86 Xen. Also use 'unsigned int'
  for the cpu parameters of remove_siblinginfo() and
  remove_cpu_sibling_map().
- Minor code cleanups.

Changes in v2:
- Rename init_cpu_sibling_map() to set_cpu_sibling_map() to align
  with x86.
- Use BUG_ON() in set_cpu_sibling_map() to verify that per-cpu
  cpu_sibling_mask and cpu_core_mask are allocated.

 xen/arch/arm/smpboot.c | 39 +++++++++++++++++++++++++++++++++++----
 1 file changed, 35 insertions(+), 4 deletions(-)

diff --git a/xen/arch/arm/smpboot.c b/xen/arch/arm/smpboot.c
index 8c9072f3c1..c4c9f535e3 100644
--- a/xen/arch/arm/smpboot.c
+++ b/xen/arch/arm/smpboot.c
@@ -91,18 +91,44 @@ static int setup_cpu_sibling_map(int cpu)
          !zalloc_cpumask_var(&per_cpu(cpu_core_mask, cpu)) )
         return -ENOMEM;
 
+    return 0;
+}
+
+static void set_cpu_sibling_map(unsigned int cpu)
+{
+    unsigned int sibling;
+
+    BUG_ON(!per_cpu(cpu_sibling_mask, cpu));
+    BUG_ON(!per_cpu(cpu_core_mask, cpu));
+
     /*
      * Currently we assume there is no multithread and NUMA, so
-     * a CPU is a sibling with itself, and the all possible CPUs
+     * a CPU is a sibling with itself, and the all online CPUs
      * are supposed to belong to the same socket (NUMA node).
      */
     cpumask_set_cpu(cpu, per_cpu(cpu_sibling_mask, cpu));
-    cpumask_copy(per_cpu(cpu_core_mask, cpu), &cpu_possible_map);
+    cpumask_copy(per_cpu(cpu_core_mask, cpu), &cpu_online_map);
+    cpumask_set_cpu(cpu, per_cpu(cpu_core_mask, cpu));
 
-    return 0;
+    for_each_online_cpu(sibling)
+        cpumask_set_cpu(cpu, per_cpu(cpu_core_mask, sibling));
 }
 
-static void remove_cpu_sibling_map(int cpu)
+static void remove_siblinginfo(unsigned int cpu)
+{
+    unsigned int sibling;
+
+    for_each_cpu(sibling, per_cpu(cpu_core_mask, cpu))
+        cpumask_clear_cpu(cpu, per_cpu(cpu_core_mask, sibling));
+
+    for_each_cpu(sibling, per_cpu(cpu_sibling_mask, cpu))
+        cpumask_clear_cpu(cpu, per_cpu(cpu_sibling_mask, sibling));
+
+    cpumask_clear(per_cpu(cpu_sibling_mask, cpu));
+    cpumask_clear(per_cpu(cpu_core_mask, cpu));
+}
+
+static void remove_cpu_sibling_map(unsigned int cpu)
 {
     free_cpumask_var(per_cpu(cpu_sibling_mask, cpu));
     free_cpumask_var(per_cpu(cpu_core_mask, cpu));
@@ -314,6 +340,7 @@ smp_prepare_cpus(void)
     if ( rc )
         panic("Unable to allocate CPU sibling/core maps\n");
 
+    set_cpu_sibling_map(0);
 }
 
 /* Boot the current CPU */
@@ -385,6 +412,8 @@ void asmlinkage noreturn start_secondary(void)
 
     set_current(idle_vcpu[cpuid]);
 
+    set_cpu_sibling_map(cpuid);
+
     /* Run local notifiers */
     notify_cpu_starting(cpuid);
     /*
@@ -431,6 +460,8 @@ void __cpu_disable(void)
     mdelay(1);
     local_irq_disable();
 
+    remove_siblinginfo(cpu);
+
     /* It's now safe to remove this processor from the online map */
     cpumask_clear_cpu(cpu, &cpu_online_map);
 
-- 
2.43.0




 


Rackspace

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