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

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


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Hirokazu Takahashi <taka@xxxxxxxxxxxxx>
  • Date: Mon, 29 Jun 2026 07:51:15 +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=F/BPrknx8bZKBuNEgIZ8AT8lWBSgwhZWCT+D+P2y8Pw=; b=ohZexVH5vOBFJkCqTNjWI3YPhQaF5BhdLgOfo4DVOF03BfooGSEG8Y8lfyhAYkESX6UQMlYcwJODa03U+XUCsPP1vcd9hiRn45H4FNfClI2SRydd4jn1fkSuu4Wjz0x30efr94RpGtYPOLS3oycLQN7jebGDH5ibbRUnD6E86QlLK7/Lx8tCcW+FDSxcnp8AmtJnNnX/TbHQiqcNEUGuZWTucjvT4dCQozQh+1kh1goVDl3ImZlkHd56/upELl/kwNtkujXE811I1ZLb6Haw0o5Fdb6tcN6QcwzYsCYYFeQUXmGx3ANnJwWmrU5xuKF9SdIDSRqlt55fO/dvcvfYgw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=azUxOqPjcF5oQl5Ucsg5iWg1T1D00QmsS6rVG5E5vf4fpxL12junA3GGWYUY9J+i7DcsGPZ9aQjWt0BrCskBQim6UqEl6zvuSrJ213JJicLhZjsFK9CB8HAF8uLJBjqmRY8cILuZj7aPP6efSPz8DmfOJePHufRdCPCk0N4KJHti6lnRSEBbo0oT1ZNeD31EA2bflpsKbEVwEdSmbbvhWZeUXRNKZek8A98IrrYkc145dj7LWW8DgGaY2LUE3IDpOMOHFSONaRU0RlaJGvxWY2lZQjxhKOcx9dWv6cNd8wDIGYtk6/bAreEY/wTcVavPqt3Z7k5phc/5zNIXTQ9vzA==
  • 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: Sun, 28 Jun 2026 22:51:37 +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.

Changes in v2:
Fix an issue where cpu_logical_map(0) is cleared when boot CPU
initialization fails.

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

diff --git a/xen/arch/arm/smpboot.c b/xen/arch/arm/smpboot.c
index 7f3cfa812e..0ab9619398 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 )
@@ -251,10 +254,8 @@ static void __init dt_smp_init_cpus(void)
         return;
     }
 
-    for ( i = 0; i < cpuidx; i++ )
+    for ( i = 1; 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®.