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

[xen master] xen/arm: smpboot: Allocate the CPU sibling/core maps while preparing the CPU



commit 65f684b728f779e170335e9e0cbbf82f7e1c7e5b
Author:     Julien Grall <jgrall@xxxxxxxxxx>
AuthorDate: Wed Jun 22 18:51:17 2022 +0100
Commit:     Julien Grall <jgrall@xxxxxxxxxx>
CommitDate: Wed Jun 22 18:52:24 2022 +0100

    xen/arm: smpboot: Allocate the CPU sibling/core maps while preparing the CPU
    
    Commit 5047cd1d5dea "xen/common: Use enhanced ASSERT_ALLOC_CONTEXT in
    xmalloc()" extended the checks in _xmalloc() to catch any use of the
    helpers from context with interrupts disabled.
    
    Unfortunately, the rule is not followed when allocating the CPU
    sibling/core maps.
    
    (XEN) Xen call trace:
    (XEN)    [<00238a5c>] _xmalloc+0xfc/0x314 (PC)
    (XEN)    [<00000000>] 00000000 (LR)
    (XEN)    [<00238c8c>] _xzalloc+0x18/0x4c
    (XEN)    [<00288cb4>] smpboot.c#setup_cpu_sibling_map+0x38/0x138
    (XEN)    [<00289024>] start_secondary+0x1b4/0x270
    (XEN)    [<40010170>] 40010170
    (XEN)
    (XEN)
    (XEN) ****************************************
    (XEN) Panic on CPU 2:
    (XEN) Assertion '!in_irq() && (local_irq_is_enabled() || num_online_cpus() 
<= 1)' failed at common/xmalloc_tlsf.c:601
    (XEN) ****************************************
    
    This is happening because zalloc_cpumask_var() may allocate memory
    if NR_CPUS is > 2 * sizeof(unsigned long).
    
    Avoid the problem by allocating the CPU sibling/core maps while
    preparing the CPU.
    
    This also has the benefit to remove a panic() in the secondary CPU
    code.
    
    Signed-off-by: Julien Grall <jgrall@xxxxxxxxxx>
    Reviewed-by: Michal Orzel <michal.orzel@xxxxxxx>
    Acked-by: Stefano Stabellini <sstabellini@xxxxxxxxxx>
---
 xen/arch/arm/smpboot.c | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/xen/arch/arm/smpboot.c b/xen/arch/arm/smpboot.c
index 3f62f3a44f..9e92279563 100644
--- a/xen/arch/arm/smpboot.c
+++ b/xen/arch/arm/smpboot.c
@@ -83,15 +83,17 @@ DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_mask);
 static bool __read_mostly opt_hmp_unsafe = false;
 boolean_param("hmp-unsafe", opt_hmp_unsafe);
 
-static void setup_cpu_sibling_map(int cpu)
+static int setup_cpu_sibling_map(int cpu)
 {
     if ( !zalloc_cpumask_var(&per_cpu(cpu_sibling_mask, cpu)) ||
          !zalloc_cpumask_var(&per_cpu(cpu_core_mask, cpu)) )
-        panic("No memory for CPU sibling/core maps\n");
+        return -ENOMEM;
 
     /* A CPU is a sibling with itself and is always on its own core. */
     cpumask_set_cpu(cpu, per_cpu(cpu_sibling_mask, cpu));
     cpumask_set_cpu(cpu, per_cpu(cpu_core_mask, cpu));
+
+    return 0;
 }
 
 static void remove_cpu_sibling_map(int cpu)
@@ -298,9 +300,14 @@ unsigned int __init smp_get_max_cpus(void)
 void __init
 smp_prepare_cpus(void)
 {
+    int rc;
+
     cpumask_copy(&cpu_present_map, &cpu_possible_map);
 
-    setup_cpu_sibling_map(0);
+    rc = setup_cpu_sibling_map(0);
+    if ( rc )
+        panic("Unable to allocate CPU sibling/core maps\n");
+
 }
 
 /* Boot the current CPU */
@@ -369,8 +376,6 @@ void start_secondary(void)
 
     set_current(idle_vcpu[cpuid]);
 
-    setup_cpu_sibling_map(cpuid);
-
     /* Run local notifiers */
     notify_cpu_starting(cpuid);
     /*
@@ -539,9 +544,19 @@ static int cpu_smpboot_callback(struct notifier_block *nfb,
                                 void *hcpu)
 {
     unsigned int cpu = (unsigned long)hcpu;
+    unsigned int rc = 0;
 
     switch ( action )
     {
+    case CPU_UP_PREPARE:
+        rc = setup_cpu_sibling_map(cpu);
+        if ( rc )
+            printk(XENLOG_ERR
+                   "Unable to allocate CPU sibling/core map  for CPU%u\n",
+                   cpu);
+
+        break;
+
     case CPU_DEAD:
         remove_cpu_sibling_map(cpu);
         break;
@@ -549,7 +564,7 @@ static int cpu_smpboot_callback(struct notifier_block *nfb,
         break;
     }
 
-    return NOTIFY_DONE;
+    return !rc ? NOTIFY_DONE : notifier_from_errno(rc);
 }
 
 static struct notifier_block cpu_smpboot_nfb = {
--
generated by git-patchbot for /home/xen/git/xen.git#master



 


Rackspace

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