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

[PATCH] xen/arm: fix sparse cpu_possible_map calculation on SMP boot


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Hirokazu Takahashi <taka@xxxxxxxxxxxxx>
  • Date: Thu, 25 Jun 2026 17:21:08 +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=vnst5qMEJYXshN47KHhoF22K42utP7xw3us1g8T906U=; b=KGqPkn1JCEZJmqY54K9wDdOzKuHBYX2LftW7P2Wr9vpS1Nl6J7DUA7eU4xi1YFTMKcDa4wzyoyDD+J3xbpn4Ncxhe2o1WWLnEBh6BXXNiM4M5ifSkkL3UUcXLjuLwEECnwbBU7s8ouFZwcJf5UdAs9Mp8Or6OFyC7hNuqfxEW73+kgs5tYXZz2zDin4Bpmp9yOeNkt/riPFtsnHfblktlD/KgxURn8p/hQ8pegv0zAkoNh6pQ3AmhgNaB/RUlgIYTV4reG9daDWXbrIqSw3cKfaPmN751LGfWvWfZkvAO9KZoTleLJQt4Ufugdd5/mqulsYTYKaGm58ASf6Q4VuzSQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=lWN7EK/IeY0UCPI565jl57+0qk8+rEP3odd26C9rItPABioAtdM3ZZEbOlRCz8XFkDL/nBwNMCoWZk9y9f/oenuHTPrd3IRxSUCdQ5mJ1u8ggc2eJD2JSFPXDikrLwq9pWmRYMoT66YoiDKDlkyKOGY+n+XMO98YxY6evID9yKkz+O6YBTLD0ArxQkqfpb92Q1FMgUKLYoveqLFSjPeMmqlH90lpPI1ShZidacbpTAa+GhzF91IjJ3TYKmUjcrS6QQP8oXqVoesGJW6kmigI5/Hyr/FTCQrcRuk8d3WpUZqw7xifQvreX0c0KGV+7sPc5eYLwcqZBP9DxzCtevpI9Q==
  • 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: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=valinux.co.jp;
  • Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Hirokazu Takahashi <taka@xxxxxxxxxxxxx>
  • Delivery-date: Thu, 25 Jun 2026 08:21:47 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Currently, during ARM Xen's SMP initialization, if there is
a Device Tree error (such as an invalid 'enable-method'),
cpu_possible_map can end up being sparse.

The issue here is that nr_cpu_ids is calculated in a way that
doesn't properly account for the maximum CPU ID when the map is
sparse, causing a mismatch. For example, if cpu_possible_map is
0xff0f, nr_cpu_ids becomes 12, but the actual maximum CPU ID
is 15. Xen's common code is built on the assumption that
'CPU ID < nr_cpu_ids', so this mismatch can break things.

To fix this, modify dt_smp_init_cpus() so that if the
arch_cpu_init() call fails, we don't consume the CPU ID slot.

Signed-off-by: Hirokazu Takahashi <taka@xxxxxxxxxxxxx>
---
 xen/arch/arm/smpboot.c | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/xen/arch/arm/smpboot.c b/xen/arch/arm/smpboot.c
index 7f3cfa812e..aba3c24373 100644
--- a/xen/arch/arm/smpboot.c
+++ b/xen/arch/arm/smpboot.c
@@ -191,6 +191,14 @@ static void __init dt_smp_init_cpus(void)
             continue;
         }
 
+        if ( hwid != mpidr && cpuidx >= NR_CPUS )
+        {
+            printk(XENLOG_WARNING
+                   "DT /cpu %u node exceeds the max cores %u, capping them\n",
+                   cpuidx, NR_CPUS);
+            break;
+        }
+
         /*
          * Duplicate MPIDRs are a recipe for disaster. Scan all initialized
          * entries and check for duplicates. If any found just skip the node.
@@ -224,24 +232,19 @@ static void __init dt_smp_init_cpus(void)
             bootcpu_valid = true;
         }
         else
-            i = cpuidx++;
-
-        if ( cpuidx > NR_CPUS )
-        {
-            printk(XENLOG_WARNING
-                   "DT /cpu %u node greater than max cores %u, capping them\n",
-                   cpuidx, NR_CPUS);
-            cpuidx = NR_CPUS;
-            break;
-        }
+            i = cpuidx;
 
         if ( (rc = arch_cpu_init(i, cpu)) < 0 )
         {
             printk("cpu%d init failed (hwid %"PRIregister"): %d\n", i, hwid, 
rc);
-            tmp_map[i] = MPIDR_INVALID;
         }
         else
+        {
             tmp_map[i] = hwid;
+
+            if ( i != 0 )
+                cpuidx++;
+        }
     }
 
     if ( !bootcpu_valid )
@@ -253,8 +256,6 @@ static void __init dt_smp_init_cpus(void)
 
     for ( i = 0; i < cpuidx; i++ )
     {
-        if ( tmp_map[i] == MPIDR_INVALID )
-            continue;
         cpumask_set_cpu(i, &cpu_possible_map);
         cpu_logical_map(i) = tmp_map[i];
     }
-- 
2.43.0




 


Rackspace

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