Skip to contentSkip to conversation

xen/sched: fix cpu hotplug

PATCH Superseded Juergen Gross 2 participants 10 messages Aug 16, 2022 – Sep 1, 2022

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover xen/sched: fix cpu hotplug

A recent change in the hypervisor memory allocation framework led to crashes when unplugging host cpus.

This was due to the (correct) assertion that allocating and freeing memory is allowed with enabled interrupts only. As the main cpu unplug operation is done in stop-machine context, this assertion triggers in debug builds.

Correct that by pre-allocating all needed memory while interrupts are still on, and free memory after interrupts are enabled again.

Changes in V3:
- addressed all comments

Changes in V2:
- addressed all comments

Juergen Gross (3):
xen/sched: introduce cpupool_update_node_affinity() xen/sched: carve out memory allocation and freeing from
schedule_cpu_rm()
xen/sched: fix cpu hotplug

 xen/common/sched/core.c    | 214 ++++++++++++++++++++++++-------------
 xen/common/sched/cpupool.c |  91 +++++++++++-----
 xen/common/sched/private.h |  21 +++-
 xen/include/xen/sched.h    |   9 +-
 4 files changed, 235 insertions(+), 100 deletions(-)
Signature · 1 line
2.35.3
#1 lore raw

PATCH v3 1/3 xen/sched: introduce cpupool_update_node_affinity()

For updating the node affinities of all domains in a cpupool add a new function cpupool_update_node_affinity().

In order to avoid multiple allocations of cpumasks carve out memory allocation and freeing from domain_update_node_affinity() into new helpers, which can be used by cpupool_update_node_affinity().

Modify domain_update_node_affinity() to take an additional parameter for passing the allocated memory in and to allocate and free the memory via the new helpers in case NULL was passed.

This will help later to pre-allocate the cpumasks in order to avoid allocations in stop-machine context.

---
V2:
- move helpers to core.c (Jan Beulich)
- allocate/free memory in domain_update_node_aff() if NULL was passed in (Jan Beulich)
V3:
- remove pointless initializer (Jan Beulich)

---
 xen/common/sched/core.c    | 54 ++++++++++++++++++++++++++------------
 xen/common/sched/cpupool.c | 39 +++++++++++++++------------
 xen/common/sched/private.h |  7 +++++
 xen/include/xen/sched.h    |  9 ++++++-
 4 files changed, 74 insertions(+), 35 deletions(-)
xen/common/sched/core.c +37 -17
index ff1ddc7624..f6eed88930 100644
@@ -1824,9 +1824,28 @@ int vcpu_affinity_domctl(struct domain *d, uint32_t cmd,
     return ret;
 }
 
-void domain_update_node_affinity(struct domain *d)
+bool update_node_aff_alloc(struct affinity_masks *affinity)
 {
-    cpumask_var_t dom_cpumask, dom_cpumask_soft;
+    if ( !alloc_cpumask_var(&affinity->hard) )
+        return false;
+    if ( !alloc_cpumask_var(&affinity->soft) )
+    {
+        free_cpumask_var(affinity->hard);
+        return false;
+    }
+
+    return true;
+}
+
+void update_node_aff_free(struct affinity_masks *affinity)
+{
+    free_cpumask_var(affinity->soft);
+    free_cpumask_var(affinity->hard);
+}
+
+void domain_update_node_aff(struct domain *d, struct affinity_masks *affinity)
+{
+    struct affinity_masks masks;
     cpumask_t *dom_affinity;
     const cpumask_t *online;
     struct sched_unit *unit;
@@ -1836,14 +1855,16 @@ void domain_update_node_affinity(struct domain *d)
     if ( !d->vcpu || !d->vcpu[0] )
         return;
 
-    if ( !zalloc_cpumask_var(&dom_cpumask) )
-        return;
-    if ( !zalloc_cpumask_var(&dom_cpumask_soft) )
+    if ( !affinity )
     {
-        free_cpumask_var(dom_cpumask);
-        return;
+        affinity = &masks;
+        if ( !update_node_aff_alloc(affinity) )
+            return;
     }
 
+    cpumask_clear(affinity->hard);
+    cpumask_clear(affinity->soft);
+
     online = cpupool_domain_master_cpumask(d);
 
     spin_lock(&d->node_affinity_lock);
@@ -1864,22 +1885,21 @@ void domain_update_node_affinity(struct domain *d)
          */
         for_each_sched_unit ( d, unit )
         {
-            cpumask_or(dom_cpumask, dom_cpumask, unit->cpu_hard_affinity);
-            cpumask_or(dom_cpumask_soft, dom_cpumask_soft,
-                       unit->cpu_soft_affinity);
+            cpumask_or(affinity->hard, affinity->hard, unit->cpu_hard_affinity);
+            cpumask_or(affinity->soft, affinity->soft, unit->cpu_soft_affinity);
         }
         /* Filter out non-online cpus */
-        cpumask_and(dom_cpumask, dom_cpumask, online);
-        ASSERT(!cpumask_empty(dom_cpumask));
+        cpumask_and(affinity->hard, affinity->hard, online);
+        ASSERT(!cpumask_empty(affinity->hard));
         /* And compute the intersection between hard, online and soft */
-        cpumask_and(dom_cpumask_soft, dom_cpumask_soft, dom_cpumask);
+        cpumask_and(affinity->soft, affinity->soft, affinity->hard);
 
         /*
          * If not empty, the intersection of hard, soft and online is the
          * narrowest set we want. If empty, we fall back to hard&online.
          */
-        dom_affinity = cpumask_empty(dom_cpumask_soft) ?
-                           dom_cpumask : dom_cpumask_soft;
+        dom_affinity = cpumask_empty(affinity->soft) ? affinity->hard
+                                                     : affinity->soft;
 
         nodes_clear(d->node_affinity);
         for_each_cpu ( cpu, dom_affinity )
@@ -1888,8 +1908,8 @@ void domain_update_node_affinity(struct domain *d)
 
     spin_unlock(&d->node_affinity_lock);
 
-    free_cpumask_var(dom_cpumask_soft);
-    free_cpumask_var(dom_cpumask);
+    if ( affinity == &masks )
+        update_node_aff_free(affinity);
 }
 
 typedef long ret_t;
xen/common/sched/cpupool.c +22 -17
index 2afe54f54d..58e082eb4c 100644
@@ -410,6 +410,25 @@ int cpupool_move_domain(struct domain *d, struct cpupool *c)
     return ret;
 }
 
+/* Update affinities of all domains in a cpupool. */
+static void cpupool_update_node_affinity(const struct cpupool *c)
+{
+    struct affinity_masks masks;
+    struct domain *d;
+
+    if ( !update_node_aff_alloc(&masks) )
+        return;
+
+    rcu_read_lock(&domlist_read_lock);
+
+    for_each_domain_in_cpupool(d, c)
+        domain_update_node_aff(d, &masks);
+
+    rcu_read_unlock(&domlist_read_lock);
+
+    update_node_aff_free(&masks);
+}
+
 /*
  * assign a specific cpu to a cpupool
  * cpupool_lock must be held
@@ -417,7 +436,6 @@ int cpupool_move_domain(struct domain *d, struct cpupool *c)
 static int cpupool_assign_cpu_locked(struct cpupool *c, unsigned int cpu)
 {
     int ret;
-    struct domain *d;
     const cpumask_t *cpus;
 
     cpus = sched_get_opt_cpumask(c->gran, cpu);
@@ -442,12 +460,7 @@ static int cpupool_assign_cpu_locked(struct cpupool *c, unsigned int cpu)
 
     rcu_read_unlock(&sched_res_rculock);
 
-    rcu_read_lock(&domlist_read_lock);
-    for_each_domain_in_cpupool(d, c)
-    {
-        domain_update_node_affinity(d);
-    }
-    rcu_read_unlock(&domlist_read_lock);
+    cpupool_update_node_affinity(c);
 
     return 0;
 }
@@ -456,18 +469,14 @@ static int cpupool_unassign_cpu_finish(struct cpupool *c)
 {
     int cpu = cpupool_moving_cpu;
     const cpumask_t *cpus;
-    struct domain *d;
     int ret;
 
     if ( c != cpupool_cpu_moving )
         return -EADDRNOTAVAIL;
 
-    /*
-     * We need this for scanning the domain list, both in
-     * cpu_disable_scheduler(), and at the bottom of this function.
-     */
     rcu_read_lock(&domlist_read_lock);
     ret = cpu_disable_scheduler(cpu);
+    rcu_read_unlock(&domlist_read_lock);
 
     rcu_read_lock(&sched_res_rculock);
     cpus = get_sched_res(cpu)->cpus;
@@ -494,11 +503,7 @@ static int cpupool_unassign_cpu_finish(struct cpupool *c)
     }
     rcu_read_unlock(&sched_res_rculock);
 
-    for_each_domain_in_cpupool(d, c)
-    {
-        domain_update_node_affinity(d);
-    }
-    rcu_read_unlock(&domlist_read_lock);
+    cpupool_update_node_affinity(c);
 
     return ret;
 }
xen/common/sched/private.h +7 -0
index a870320146..38251b1f7b 100644
@@ -593,6 +593,13 @@ affinity_balance_cpumask(const struct sched_unit *unit, int step,
         cpumask_copy(mask, unit->cpu_hard_affinity);
 }
 
+struct affinity_masks {
+    cpumask_var_t hard;
+    cpumask_var_t soft;
+};
+
+bool update_node_aff_alloc(struct affinity_masks *affinity);
+void update_node_aff_free(struct affinity_masks *affinity);
 void sched_rm_cpu(unsigned int cpu);
 const cpumask_t *sched_get_opt_cpumask(enum sched_gran opt, unsigned int cpu);
 void schedule_dump(struct cpupool *c);
xen/include/xen/sched.h +8 -1
index e2b3b6daa3..666264b8c3 100644
@@ -663,8 +663,15 @@ static inline void get_knownalive_domain(struct domain *d)
     ASSERT(!(atomic_read(&d->refcnt) & DOMAIN_DESTROYED));
 }
 
+struct affinity_masks;
+
 int domain_set_node_affinity(struct domain *d, const nodemask_t *affinity);
-void domain_update_node_affinity(struct domain *d);
+void domain_update_node_aff(struct domain *d, struct affinity_masks *affinity);
+
+static inline void domain_update_node_affinity(struct domain *d)
+{
+    domain_update_node_aff(d, NULL);
+}
 
 /*
  * To be implemented by each architecture, sanity checking the configuration
Signature · 1 line
2.35.3
#2 lore raw

PATCH v3 2/3 xen/sched: carve out memory allocation and freeing from schedule_cpu_rm()

In reply to Juergen Gross

In order to prepare not allocating or freeing memory from schedule_cpu_rm(), move this functionality to dedicated functions.

For now call those functions from schedule_cpu_rm().

No change of behavior expected.

---
V2:
- add const (Jan Beulich)
- use "unsigned int" for loop index (Jan Beulich)
- use xmalloc_flex_struct() (Jan Beulich)
- use XFREE() (Jan Beulich)
- hold rcu lock longer (Jan Beulich)
- add ASSERT() (Jan Beulich)
V3:
- added comment for schedule_cpu_rm_alloc() (Jan Beulich)

---
 xen/common/sched/core.c    | 143 ++++++++++++++++++++++---------------
 xen/common/sched/private.h |   9 +++
 2 files changed, 96 insertions(+), 56 deletions(-)
xen/common/sched/core.c +87 -56
index f6eed88930..228470ac41 100644
@@ -3237,6 +3237,75 @@ out:
     return ret;
 }
 
+/*
+ * Allocate all memory needed for schedule_cpu_rm_free(), which can't do that
+ * due to be called in stop_machine() context with interrupts disabled.
+ *
+ * Between schedule_cpu_rm_alloc() and the real cpu removal action the relevant
+ * contents of struct sched_resource can't change, as the cpu in question is
+ * locked against any other movement to or from cpupools, and the data copied
+ * by schedule_cpu_rm_alloc() is modified only in case the cpu in question is
+ * being moved from or to a cpupool.
+ */
+static struct cpu_rm_data *schedule_cpu_rm_alloc(unsigned int cpu)
+{
+    struct cpu_rm_data *data;
+    const struct sched_resource *sr;
+    unsigned int idx;
+
+    rcu_read_lock(&sched_res_rculock);
+
+    sr = get_sched_res(cpu);
+    data = xmalloc_flex_struct(struct cpu_rm_data, sr, sr->granularity - 1);
+    if ( !data )
+        goto out;
+
+    data->old_ops = sr->scheduler;
+    data->vpriv_old = idle_vcpu[cpu]->sched_unit->priv;
+    data->ppriv_old = sr->sched_priv;
+
+    for ( idx = 0; idx < sr->granularity - 1; idx++ )
+    {
+        data->sr[idx] = sched_alloc_res();
+        if ( data->sr[idx] )
+        {
+            data->sr[idx]->sched_unit_idle = sched_alloc_unit_mem();
+            if ( !data->sr[idx]->sched_unit_idle )
+            {
+                sched_res_free(&data->sr[idx]->rcu);
+                data->sr[idx] = NULL;
+            }
+        }
+        if ( !data->sr[idx] )
+        {
+            while ( idx > 0 )
+                sched_res_free(&data->sr[--idx]->rcu);
+            XFREE(data);
+            goto out;
+        }
+
+        data->sr[idx]->curr = data->sr[idx]->sched_unit_idle;
+        data->sr[idx]->scheduler = &sched_idle_ops;
+        data->sr[idx]->granularity = 1;
+
+        /* We want the lock not to change when replacing the resource. */
+        data->sr[idx]->schedule_lock = sr->schedule_lock;
+    }
+
+ out:
+    rcu_read_unlock(&sched_res_rculock);
+
+    return data;
+}
+
+static void schedule_cpu_rm_free(struct cpu_rm_data *mem, unsigned int cpu)
+{
+    sched_free_udata(mem->old_ops, mem->vpriv_old);
+    sched_free_pdata(mem->old_ops, mem->ppriv_old, cpu);
+
+    xfree(mem);
+}
+
 /*
  * Remove a pCPU from its cpupool. Its scheduler becomes &sched_idle_ops
  * (the idle scheduler).
@@ -3245,53 +3314,23 @@ out:
  */
 int schedule_cpu_rm(unsigned int cpu)
 {
-    void *ppriv_old, *vpriv_old;
-    struct sched_resource *sr, **sr_new = NULL;
+    struct sched_resource *sr;
+    struct cpu_rm_data *data;
     struct sched_unit *unit;
-    struct scheduler *old_ops;
     spinlock_t *old_lock;
     unsigned long flags;
-    int idx, ret = -ENOMEM;
+    int idx = 0;
     unsigned int cpu_iter;
 
+    data = schedule_cpu_rm_alloc(cpu);
+    if ( !data )
+        return -ENOMEM;
+
     rcu_read_lock(&sched_res_rculock);
 
     sr = get_sched_res(cpu);
-    old_ops = sr->scheduler;
-
-    if ( sr->granularity > 1 )
-    {
-        sr_new = xmalloc_array(struct sched_resource *, sr->granularity - 1);
-        if ( !sr_new )
-            goto out;
-        for ( idx = 0; idx < sr->granularity - 1; idx++ )
-        {
-            sr_new[idx] = sched_alloc_res();
-            if ( sr_new[idx] )
-            {
-                sr_new[idx]->sched_unit_idle = sched_alloc_unit_mem();
-                if ( !sr_new[idx]->sched_unit_idle )
-                {
-                    sched_res_free(&sr_new[idx]->rcu);
-                    sr_new[idx] = NULL;
-                }
-            }
-            if ( !sr_new[idx] )
-            {
-                for ( idx--; idx >= 0; idx-- )
-                    sched_res_free(&sr_new[idx]->rcu);
-                goto out;
-            }
-            sr_new[idx]->curr = sr_new[idx]->sched_unit_idle;
-            sr_new[idx]->scheduler = &sched_idle_ops;
-            sr_new[idx]->granularity = 1;
 
-            /* We want the lock not to change when replacing the resource. */
-            sr_new[idx]->schedule_lock = sr->schedule_lock;
-        }
-    }
-
-    ret = 0;
+    ASSERT(sr->granularity);
     ASSERT(sr->cpupool != NULL);
     ASSERT(cpumask_test_cpu(cpu, &cpupool_free_cpus));
     ASSERT(!cpumask_test_cpu(cpu, sr->cpupool->cpu_valid));
@@ -3299,10 +3338,6 @@ int schedule_cpu_rm(unsigned int cpu)
     /* See comment in schedule_cpu_add() regarding lock switching. */
     old_lock = pcpu_schedule_lock_irqsave(cpu, &flags);
 
-    vpriv_old = idle_vcpu[cpu]->sched_unit->priv;
-    ppriv_old = sr->sched_priv;
-
-    idx = 0;
     for_each_cpu ( cpu_iter, sr->cpus )
     {
         per_cpu(sched_res_idx, cpu_iter) = 0;
@@ -3316,27 +3351,27 @@ int schedule_cpu_rm(unsigned int cpu)
         else
         {
             /* Initialize unit. */
-            unit = sr_new[idx]->sched_unit_idle;
-            unit->res = sr_new[idx];
+            unit = data->sr[idx]->sched_unit_idle;
+            unit->res = data->sr[idx];
             unit->is_running = true;
             sched_unit_add_vcpu(unit, idle_vcpu[cpu_iter]);
             sched_domain_insert_unit(unit, idle_vcpu[cpu_iter]->domain);
 
             /* Adjust cpu masks of resources (old and new). */
             cpumask_clear_cpu(cpu_iter, sr->cpus);
-            cpumask_set_cpu(cpu_iter, sr_new[idx]->cpus);
+            cpumask_set_cpu(cpu_iter, data->sr[idx]->cpus);
             cpumask_set_cpu(cpu_iter, &sched_res_mask);
 
             /* Init timer. */
-            init_timer(&sr_new[idx]->s_timer, s_timer_fn, NULL, cpu_iter);
+            init_timer(&data->sr[idx]->s_timer, s_timer_fn, NULL, cpu_iter);
 
             /* Last resource initializations and insert resource pointer. */
-            sr_new[idx]->master_cpu = cpu_iter;
-            set_sched_res(cpu_iter, sr_new[idx]);
+            data->sr[idx]->master_cpu = cpu_iter;
+            set_sched_res(cpu_iter, data->sr[idx]);
 
             /* Last action: set the new lock pointer. */
             smp_mb();
-            sr_new[idx]->schedule_lock = &sched_free_cpu_lock;
+            data->sr[idx]->schedule_lock = &sched_free_cpu_lock;
 
             idx++;
         }
@@ -3352,16 +3387,12 @@ int schedule_cpu_rm(unsigned int cpu)
     /* _Not_ pcpu_schedule_unlock(): schedule_lock may have changed! */
     spin_unlock_irqrestore(old_lock, flags);
 
-    sched_deinit_pdata(old_ops, ppriv_old, cpu);
-
-    sched_free_udata(old_ops, vpriv_old);
-    sched_free_pdata(old_ops, ppriv_old, cpu);
+    sched_deinit_pdata(data->old_ops, data->ppriv_old, cpu);
 
-out:
     rcu_read_unlock(&sched_res_rculock);
-    xfree(sr_new);
+    schedule_cpu_rm_free(data, cpu);
 
-    return ret;
+    return 0;
 }
 
 struct scheduler *scheduler_get_default(void)
xen/common/sched/private.h +9 -0
index 38251b1f7b..601d639699 100644
@@ -600,6 +600,15 @@ struct affinity_masks {
 
 bool update_node_aff_alloc(struct affinity_masks *affinity);
 void update_node_aff_free(struct affinity_masks *affinity);
+
+/* Memory allocation related data for schedule_cpu_rm(). */
+struct cpu_rm_data {
+    const struct scheduler *old_ops;
+    void *ppriv_old;
+    void *vpriv_old;
+    struct sched_resource *sr[];
+};
+
 void sched_rm_cpu(unsigned int cpu);
 const cpumask_t *sched_get_opt_cpumask(enum sched_gran opt, unsigned int cpu);
 void schedule_dump(struct cpupool *c);
Signature · 1 line
2.35.3
#3 lore raw

Re: [PATCH v3 2/3] xen/sched: carve out memory allocation and freeing from schedule_cpu_rm()

xen/common/sched/core.c out: · line 3242

Quoted 11 lines · Juergen Gross
xen/common/sched/core.c +3 -0
index f6eed88930..228470ac41 100644
@@ -3237,6 +3237,75 @@ out:
     return ret;
 }
 
+/*
+ * Allocate all memory needed for schedule_cpu_rm_free(), which can't do that
+ * due to be called in stop_machine() context with interrupts disabled.

As a minor observation, this is awkward grammar.  I'd suggest "... needed for free_cpu_rm_data(), as allocations cannot be made in stop_machine() context".

~Andrew

#4 lore raw

Re: [PATCH v3 2/3] xen/sched: carve out memory allocation and freeing from schedule_cpu_rm()

Quoted 9 lines · Andrew Cooper
Quoted 8 lines · Juergen Gross
xen/common/sched/core.c +0 -0
index f6eed88930..228470ac41 100644
@@ -3237,6 +3237,75 @@ out:
      return ret;
  }
 
Quoted 7 lines

xen/common/sched/core.c out: · line 3242

Quoted 3 lines
xen/common/sched/core.c +3 -0
+/*
+ * Allocate all memory needed for schedule_cpu_rm_free(), which can't do that
+ * due to be called in stop_machine() context with interrupts disabled.

As a minor observation, this is awkward grammar.  I'd suggest "... needed for free_cpu_rm_data(), as allocations cannot be made in stop_machine() context".

Okay, will change it.

Juergen

#5 lore raw

PATCH v3 3/3 xen/sched: fix cpu hotplug

In reply to Juergen Gross

Cpu cpu unplugging is calling schedule_cpu_rm() via stop_machine_run() with interrupts disabled, thus any memory allocation or freeing must be avoided.

Since commit 5047cd1d5dea ("xen/common: Use enhanced ASSERT_ALLOC_CONTEXT in xmalloc()") this restriction is being enforced via an assertion, which will now fail.

Before that commit cpu unplugging in normal configurations was working just by chance as only the cpu performing schedule_cpu_rm() was doing active work. With core scheduling enabled, however, failures could result from memory allocations not being properly propagated to other cpus' TLBs.

Fix this mess by allocating needed memory before entering stop_machine_run() and freeing any memory only after having finished stop_machine_run().

Fixes 1ec410112cdd ("xen/sched: support differing granularity in schedule_cpu_[add/rm]()")

---
V2:
- move affinity mask allocation into schedule_cpu_rm_alloc() (Jan Beulich)

---
 xen/common/sched/core.c    | 27 +++++++++++----
 xen/common/sched/cpupool.c | 68 +++++++++++++++++++++++++++++---------
 xen/common/sched/private.h |  5 ++-
 3 files changed, 78 insertions(+), 22 deletions(-)
xen/common/sched/core.c +21 -6
index 228470ac41..ffb2d6202b 100644
@@ -3247,7 +3247,7 @@ out:
  * by schedule_cpu_rm_alloc() is modified only in case the cpu in question is
  * being moved from or to a cpupool.
  */
-static struct cpu_rm_data *schedule_cpu_rm_alloc(unsigned int cpu)
+struct cpu_rm_data *schedule_cpu_rm_alloc(unsigned int cpu, bool aff_alloc)
 {
     struct cpu_rm_data *data;
     const struct sched_resource *sr;
@@ -3260,6 +3260,17 @@ static struct cpu_rm_data *schedule_cpu_rm_alloc(unsigned int cpu)
     if ( !data )
         goto out;
 
+    if ( aff_alloc )
+    {
+        if ( !update_node_aff_alloc(&data->affinity) )
+        {
+            XFREE(data);
+            goto out;
+        }
+    }
+    else
+        memset(&data->affinity, 0, sizeof(data->affinity));
+
     data->old_ops = sr->scheduler;
     data->vpriv_old = idle_vcpu[cpu]->sched_unit->priv;
     data->ppriv_old = sr->sched_priv;
@@ -3280,6 +3291,7 @@ static struct cpu_rm_data *schedule_cpu_rm_alloc(unsigned int cpu)
         {
             while ( idx > 0 )
                 sched_res_free(&data->sr[--idx]->rcu);
+            update_node_aff_free(&data->affinity);
             XFREE(data);
             goto out;
         }
@@ -3298,10 +3310,11 @@ static struct cpu_rm_data *schedule_cpu_rm_alloc(unsigned int cpu)
     return data;
 }
 
-static void schedule_cpu_rm_free(struct cpu_rm_data *mem, unsigned int cpu)
+void schedule_cpu_rm_free(struct cpu_rm_data *mem, unsigned int cpu)
 {
     sched_free_udata(mem->old_ops, mem->vpriv_old);
     sched_free_pdata(mem->old_ops, mem->ppriv_old, cpu);
+    update_node_aff_free(&mem->affinity);
 
     xfree(mem);
 }
@@ -3312,17 +3325,18 @@ static void schedule_cpu_rm_free(struct cpu_rm_data *mem, unsigned int cpu)
  * The cpu is already marked as "free" and not valid any longer for its
  * cpupool.
  */
-int schedule_cpu_rm(unsigned int cpu)
+int schedule_cpu_rm(unsigned int cpu, struct cpu_rm_data *data)
 {
     struct sched_resource *sr;
-    struct cpu_rm_data *data;
     struct sched_unit *unit;
     spinlock_t *old_lock;
     unsigned long flags;
     int idx = 0;
     unsigned int cpu_iter;
+    bool freemem = !data;
 
-    data = schedule_cpu_rm_alloc(cpu);
+    if ( !data )
+        data = schedule_cpu_rm_alloc(cpu, false);
     if ( !data )
         return -ENOMEM;
 
@@ -3390,7 +3404,8 @@ int schedule_cpu_rm(unsigned int cpu)
     sched_deinit_pdata(data->old_ops, data->ppriv_old, cpu);
 
     rcu_read_unlock(&sched_res_rculock);
-    schedule_cpu_rm_free(data, cpu);
+    if ( freemem )
+        schedule_cpu_rm_free(data, cpu);
 
     return 0;
 }
xen/common/sched/cpupool.c +53 -15

154 lines not on this page · raw message

xen/common/sched/private.h +4 -1
index 601d639699..cc7a6cb571 100644
@@ -603,6 +603,7 @@ void update_node_aff_free(struct affinity_masks *affinity);
 
 /* Memory allocation related data for schedule_cpu_rm(). */
 struct cpu_rm_data {
+    struct affinity_masks affinity;
     const struct scheduler *old_ops;
     void *ppriv_old;
     void *vpriv_old;
@@ -617,7 +618,9 @@ struct scheduler *scheduler_alloc(unsigned int sched_id);
 void scheduler_free(struct scheduler *sched);
 int cpu_disable_scheduler(unsigned int cpu);
 int schedule_cpu_add(unsigned int cpu, struct cpupool *c);
-int schedule_cpu_rm(unsigned int cpu);
+struct cpu_rm_data *schedule_cpu_rm_alloc(unsigned int cpu, bool aff_alloc);
+void schedule_cpu_rm_free(struct cpu_rm_data *mem, unsigned int cpu);
+int schedule_cpu_rm(unsigned int cpu, struct cpu_rm_data *mem);
 int sched_move_domain(struct domain *d, struct cpupool *c);
 struct cpupool *cpupool_get_by_id(unsigned int poolid);
 void cpupool_put(struct cpupool *pool);
Signature · 1 line
2.35.3
#6 lore raw
Quoted 1 line · Juergen Gross

Cpu cpu unplugging is calling schedule_cpu_rm() via stop_machine_run()

Cpu cpu.

Quoted 7 lines

with interrupts disabled, thus any memory allocation or freeing must be avoided.

Since commit 5047cd1d5dea ("xen/common: Use enhanced ASSERT_ALLOC_CONTEXT in xmalloc()") this restriction is being enforced via an assertion, which will now fail.

Quoted 5 lines

Before that commit cpu unplugging in normal configurations was working just by chance as only the cpu performing schedule_cpu_rm() was doing active work. With core scheduling enabled, however, failures could result from memory allocations not being properly propagated to other cpus' TLBs.

This isn't accurate, is it?  The problem with initiating a TLB flush with IRQs disabled is that you can deadlock against a remote CPU which is waiting for you to enable IRQs first to take a TLB flush IPI.

How does a memory allocation out of the xenheap result in a TLB flush? Even with split heaps, you're only potentially allocating into a new slot which was unused...

xen/common/sched/core.c static struct cpu_rm_data *schedule_cpu_rm_alloc(unsigned int cpu) · line 3265

Quoted 11 lines
xen/common/sched/core.c +3 -0
index 228470ac41..ffb2d6202b 100644
@@ -3260,6 +3260,17 @@ static struct cpu_rm_data *schedule_cpu_rm_alloc(unsigned int cpu)
     if ( !data )
         goto out;
 
+    if ( aff_alloc )
+    {
+        if ( !update_node_aff_alloc(&data->affinity) )

I spent ages trying to figure out what this was doing, before realising the problem is the function name.

alloc (as with free) is the critical piece of information and needs to come first.  The fact we typically pass the result to update_node_aff(inity) isn't relevant, and becomes actively wrong here when we're nowhere near.

Patch 1 needs to name these helpers:

bool alloc_affinity_masks(struct affinity_masks *affinity); void free_affinity_masks(struct affinity_masks *affinity);

and then patches 2 and 3 become far easier to follow.

Similarly in patch 2, the new helpers need to be {alloc,free}_cpu_rm_data() to make sense.  These have nothing to do with scheduling.

Also, you shouldn't introduce the helpers static in patch 2 and then turn them non-static in patch 3.  That just adds unnecessary churn to the complicated patch.

xen/common/sched/core.c static struct cpu_rm_data *schedule_cpu_rm_alloc(unsigned int cpu) · line 3272

Quoted 7 lines
xen/common/sched/core.c +7 -0
+        {
+            XFREE(data);
+            goto out;
+        }
+    }
+    else
+        memset(&data->affinity, 0, sizeof(data->affinity));

I honestly don't think it is worth optimising xzalloc() -> xmalloc() for the cognitive complexity of having this logic here.

Quoted 29 lines
xen/common/sched/cpupool.c +9 -5
index 58e082eb4c..2506861e4f 100644
@@ -411,22 +411,28 @@ int cpupool_move_domain(struct domain *d, struct cpupool *c)
 }
 
 /* Update affinities of all domains in a cpupool. */
-static void cpupool_update_node_affinity(const struct cpupool *c)
+static void cpupool_update_node_affinity(const struct cpupool *c,
+                                         struct affinity_masks *masks)
 {
-    struct affinity_masks masks;
+    struct affinity_masks local_masks;
     struct domain *d;
 
-    if ( !update_node_aff_alloc(&masks) )
-        return;
+    if ( !masks )
+    {
+        if ( !update_node_aff_alloc(&local_masks) )
+            return;
+        masks = &local_masks;
+    }
 
     rcu_read_lock(&domlist_read_lock);
 
     for_each_domain_in_cpupool(d, c)
-        domain_update_node_aff(d, &masks);

xen/common/sched/cpupool.c int cpupool_move_domain(struct domain *d, struct cpupool *c) · line 438

Quoted 10 lines
xen/common/sched/cpupool.c +3 -1
+        domain_update_node_aff(d, masks);
 
     rcu_read_unlock(&domlist_read_lock);
 
-    update_node_aff_free(&masks);
+    if ( masks == &local_masks )
+        update_node_aff_free(masks);
 }
 
 /*

Why do we need this at all?  domain_update_node_aff() already knows what to do when passed NULL, so this seems like an awfully complicated no-op.

xen/common/sched/cpupool.c static int cf_check cpu_callback( · line 1027

Quoted 13 lines
xen/common/sched/cpupool.c +5 -0
@@ -1008,10 +1016,21 @@ static int cf_check cpu_callback(
 {
     unsigned int cpu = (unsigned long)hcpu;
     int rc = 0;
+    static struct cpu_rm_data *mem;
 
     switch ( action )
     {
     case CPU_DOWN_FAILED:
+        if ( system_state <= SYS_STATE_active )
+        {
+            if ( mem )
+            {

So, this does compile (and indeed I've tested the result), but I can't see how it should.

mem is guaranteed to be uninitialised at this point, and ...

Quoted 10 lines
xen/common/sched/cpupool.c +6 -0
+                schedule_cpu_rm_free(mem, cpu);
+                mem = NULL;
+            }
+            rc = cpupool_cpu_add(cpu);
+        }
+        break;
     case CPU_ONLINE:
         if ( system_state <= SYS_STATE_active )
             rc = cpupool_cpu_add(cpu);

xen/common/sched/cpupool.c static int cf_check cpu_callback( · line 1045

Quoted 8 lines
xen/common/sched/cpupool.c +4 -0
@@ -1019,12 +1038,31 @@ static int cf_check cpu_callback(
     case CPU_DOWN_PREPARE:
         /* Suspend/Resume don't change assignments of cpus to cpupools. */
         if ( system_state <= SYS_STATE_active )
+        {
             rc = cpupool_cpu_remove_prologue(cpu);
+            if ( !rc )
+            {
+                ASSERT(!mem);

... here, and each subsequent assertion too.

Given that I tested the patch and it does fix the IRQ assertion, I can only imagine that it works by deterministically finding stack rubble which happens to be 0.

~Andrew

#7 lore raw
Quoted 18 lines · Andrew Cooper
Quoted 1 line · Juergen Gross

Cpu cpu unplugging is calling schedule_cpu_rm() via stop_machine_run()

Cpu cpu.

Quoted 7 lines

with interrupts disabled, thus any memory allocation or freeing must be avoided.

Since commit 5047cd1d5dea ("xen/common: Use enhanced ASSERT_ALLOC_CONTEXT in xmalloc()") this restriction is being enforced via an assertion, which will now fail.

Quoted 5 lines

Before that commit cpu unplugging in normal configurations was working just by chance as only the cpu performing schedule_cpu_rm() was doing active work. With core scheduling enabled, however, failures could result from memory allocations not being properly propagated to other cpus' TLBs.

Quoted 3 lines

This isn't accurate, is it?  The problem with initiating a TLB flush with IRQs disabled is that you can deadlock against a remote CPU which is waiting for you to enable IRQs first to take a TLB flush IPI.

As long as only one cpu is trying to allocate/free memory during the stop_machine_run() action the deadlock won't happen.

Quoted 3 lines

How does a memory allocation out of the xenheap result in a TLB flush? Even with split heaps, you're only potentially allocating into a new slot which was unused...

Yeah, you are right. The main problem would occur only when a virtual address is changed to point at another physical address, which should be quite unlikely.

I can drop that paragraph, as it doesn't really help.

Quoted 28 lines

xen/common/sched/core.c static struct cpu_rm_data *schedule_cpu_rm_alloc(unsigned int cpu) · line 3265

Quoted 12 lines
xen/common/sched/core.c +3 -0
index 228470ac41..ffb2d6202b 100644
@@ -3260,6 +3260,17 @@ static struct cpu_rm_data *schedule_cpu_rm_alloc(unsigned int cpu)
      if ( !data )
          goto out;
 
+    if ( aff_alloc )
+    {
+        if ( !update_node_aff_alloc(&data->affinity) )

I spent ages trying to figure out what this was doing, before realising the problem is the function name.

alloc (as with free) is the critical piece of information and needs to come first.  The fact we typically pass the result to update_node_aff(inity) isn't relevant, and becomes actively wrong here when we're nowhere near.

Patch 1 needs to name these helpers:

bool alloc_affinity_masks(struct affinity_masks *affinity); void free_affinity_masks(struct affinity_masks *affinity);

and then patches 2 and 3 become far easier to follow.

Quoted 7 lines

Similarly in patch 2, the new helpers need to be {alloc,free}_cpu_rm_data() to make sense.  These have nothing to do with scheduling.

Also, you shouldn't introduce the helpers static in patch 2 and then turn them non-static in patch 3.  That just adds unnecessary churn to the complicated patch.

Okay to all of above.

Quoted 11 lines

xen/common/sched/core.c static struct cpu_rm_data *schedule_cpu_rm_alloc(unsigned int cpu) · line 3272

Quoted 8 lines
xen/common/sched/core.c +7 -0
+        {
+            XFREE(data);
+            goto out;
+        }
+    }
+    else
+        memset(&data->affinity, 0, sizeof(data->affinity));

I honestly don't think it is worth optimising xzalloc() -> xmalloc() for the cognitive complexity of having this logic here.

I don't mind either way. This logic is the result of one of Jan's comments.

Quoted 39 lines
Quoted 39 lines
xen/common/sched/cpupool.c +12 -6
index 58e082eb4c..2506861e4f 100644
@@ -411,22 +411,28 @@ int cpupool_move_domain(struct domain *d, struct cpupool *c)
  }
 
  /* Update affinities of all domains in a cpupool. */
-static void cpupool_update_node_affinity(const struct cpupool *c)
+static void cpupool_update_node_affinity(const struct cpupool *c,
+                                         struct affinity_masks *masks)
  {
-    struct affinity_masks masks;
+    struct affinity_masks local_masks;
      struct domain *d;
 
-    if ( !update_node_aff_alloc(&masks) )
-        return;
+    if ( !masks )
+    {
+        if ( !update_node_aff_alloc(&local_masks) )
+            return;
+        masks = &local_masks;
+    }
 
      rcu_read_lock(&domlist_read_lock);
 
      for_each_domain_in_cpupool(d, c)
-        domain_update_node_aff(d, &masks);
+        domain_update_node_aff(d, masks);
 
      rcu_read_unlock(&domlist_read_lock);
 
-    update_node_aff_free(&masks);
+    if ( masks == &local_masks )
+        update_node_aff_free(masks);
  }
 
Quoted 4 lines

xen/common/sched/cpupool.c int cpupool_move_domain(struct domain *d, struct cpupool *c) · line 438

Quoted 1 line
xen/common/sched/cpupool.c +0 -0
  /*

Why do we need this at all?  domain_update_node_aff() already knows what to do when passed NULL, so this seems like an awfully complicated no-op.

You do realize that update_node_aff_free() will do something in case masks was initially NULL?

Quoted 18 lines
Quoted 4 lines
xen/common/sched/cpupool.c +0 -0
@@ -1008,10 +1016,21 @@ static int cf_check cpu_callback(
  {
      unsigned int cpu = (unsigned long)hcpu;

xen/common/sched/cpupool.c static int cf_check cpu_callback( · line 1027

Quoted 10 lines
xen/common/sched/cpupool.c +5 -0
      int rc = 0;
+    static struct cpu_rm_data *mem;
 
      switch ( action )
      {
      case CPU_DOWN_FAILED:
+        if ( system_state <= SYS_STATE_active )
+        {
+            if ( mem )
+            {

So, this does compile (and indeed I've tested the result), but I can't see how it should.

Quoted 1 line

mem is guaranteed to be uninitialised at this point, and ...

... it is defined as "static", so it is clearly NULL initially.

Quoted 22 lines
Quoted 11 lines
xen/common/sched/cpupool.c +6 -0
+                schedule_cpu_rm_free(mem, cpu);
+                mem = NULL;
+            }
+            rc = cpupool_cpu_add(cpu);
+        }
+        break;
      case CPU_ONLINE:
          if ( system_state <= SYS_STATE_active )
              rc = cpupool_cpu_add(cpu);

xen/common/sched/cpupool.c static int cf_check cpu_callback( · line 1045

Quoted 8 lines
xen/common/sched/cpupool.c +4 -0
@@ -1019,12 +1038,31 @@ static int cf_check cpu_callback(
      case CPU_DOWN_PREPARE:
          /* Suspend/Resume don't change assignments of cpus to cpupools. */
          if ( system_state <= SYS_STATE_active )
+        {
              rc = cpupool_cpu_remove_prologue(cpu);
+            if ( !rc )
+            {
+                ASSERT(!mem);

... here, and each subsequent assertion too.

Quoted 3 lines

Given that I tested the patch and it does fix the IRQ assertion, I can only imagine that it works by deterministically finding stack rubble which happens to be 0.

Not really, as mem isn't on the stack. :-)

Juergen

#8 lore raw
Quoted 30 lines · Juergen Gross
Quoted 18 lines · Andrew Cooper
Quoted 1 line · Juergen Gross

Cpu cpu unplugging is calling schedule_cpu_rm() via stop_machine_run()

Cpu cpu.

Quoted 7 lines

with interrupts disabled, thus any memory allocation or freeing must be avoided.

Since commit 5047cd1d5dea ("xen/common: Use enhanced ASSERT_ALLOC_CONTEXT in xmalloc()") this restriction is being enforced via an assertion, which will now fail.

Quoted 5 lines

Before that commit cpu unplugging in normal configurations was working just by chance as only the cpu performing schedule_cpu_rm() was doing active work. With core scheduling enabled, however, failures could result from memory allocations not being properly propagated to other cpus' TLBs.

Quoted 3 lines

This isn't accurate, is it?  The problem with initiating a TLB flush with IRQs disabled is that you can deadlock against a remote CPU which is waiting for you to enable IRQs first to take a TLB flush IPI.

As long as only one cpu is trying to allocate/free memory during the stop_machine_run() action the deadlock won't happen.

Quoted 3 lines

How does a memory allocation out of the xenheap result in a TLB flush? Even with split heaps, you're only potentially allocating into a new slot which was unused...

Quoted 5 lines

Yeah, you are right. The main problem would occur only when a virtual address is changed to point at another physical address, which should be quite unlikely.

I can drop that paragraph, as it doesn't really help.

Yeah, I think that would be best.

Quoted 38 lines
Quoted 29 lines
Quoted 29 lines
xen/common/sched/cpupool.c +10 -4
index 58e082eb4c..2506861e4f 100644
@@ -411,22 +411,28 @@ int cpupool_move_domain(struct domain *d,
 struct cpupool *c)
   }
     /* Update affinities of all domains in a cpupool. */
-static void cpupool_update_node_affinity(const struct cpupool *c)
+static void cpupool_update_node_affinity(const struct cpupool *c,
+                                         struct affinity_masks *masks)
   {
-    struct affinity_masks masks;
+    struct affinity_masks local_masks;
       struct domain *d;
   -    if ( !update_node_aff_alloc(&masks) )
-        return;
+    if ( !masks )
+    {
+        if ( !update_node_aff_alloc(&local_masks) )
+            return;
+        masks = &local_masks;
+    }
         rcu_read_lock(&domlist_read_lock);
         for_each_domain_in_cpupool(d, c)
-        domain_update_node_aff(d, &masks);
+        domain_update_node_aff(d, masks);
         rcu_read_unlock(&domlist_read_lock);
Quoted 8 lines

xen/common/sched/cpupool.c int cpupool_move_domain(struct domain *d, struct cpupool *c) · line 438

Quoted 5 lines
xen/common/sched/cpupool.c +2 -0
   -    update_node_aff_free(&masks);
+    if ( masks == &local_masks )
+        update_node_aff_free(masks);
   }
     /*

Why do we need this at all?  domain_update_node_aff() already knows what to do when passed NULL, so this seems like an awfully complicated no-op.

Quoted 3 lines

You do realize that update_node_aff_free() will do something in case masks
was initially NULL?

By "this", I meant the entire hunk, not just the final if().

What is wrong with passing the (possibly NULL) masks pointer straight down into domain_update_node_aff() and removing all the memory allocation in this function?

But I've also answered that by looking more clearly.  It's about not repeating the memory allocations/freeing for each domain in the pool. Which does make sense as this is a slow path already, but the complexity here of having conditionally allocated masks is far from simple.

Quoted 18 lines
Quoted 18 lines
Quoted 9 lines
xen/common/sched/cpupool.c +1 -0
@@ -1008,10 +1016,21 @@ static int cf_check cpu_callback(
   {
       unsigned int cpu = (unsigned long)hcpu;
       int rc = 0;
+    static struct cpu_rm_data *mem;
         switch ( action )
       {
Quoted 5 lines

      case CPU_DOWN_FAILED:
+        if ( system_state <= SYS_STATE_active )
+        {
+            if ( mem )
+            {

So, this does compile (and indeed I've tested the result), but I can't see how it should.

Quoted 3 lines
Quoted 1 line

mem is guaranteed to be uninitialised at this point, and ...

... it is defined as "static", so it is clearly NULL initially.

Oh, so it is.  That is hiding particularly well in plain sight.

Can it please be this:

@@ -1014,9 +1014,10 @@ void cf_check dump_runq(unsigned char key) static int cf_check cpu_callback(
     struct notifier_block *nfb, unsigned long action, void *hcpu) {
+    static struct cpu_rm_data *mem; /* Protected by cpu_add_remove_lock */ +
     unsigned int cpu = (unsigned long)hcpu;
     int rc = 0;
-    static struct cpu_rm_data *mem;

     switch ( action )
     {

We already split static and non-static variable like this elsewhere for clarity, and identifying the lock which protects the data is useful for anyone coming to this in the future.

~Andrew

P.S. as an observation, this isn't safe for parallel AP booting, but I guarantee that this isn't the only example which would want fixing if we wanted to get parallel booting working.

#9 lore raw
Quoted 81 lines · Andrew Cooper
Quoted 30 lines · Juergen Gross
Quoted 18 lines · Andrew Cooper
Quoted 1 line · Juergen Gross

Cpu cpu unplugging is calling schedule_cpu_rm() via stop_machine_run()

Cpu cpu.

Quoted 7 lines

with interrupts disabled, thus any memory allocation or freeing must be avoided.

Since commit 5047cd1d5dea ("xen/common: Use enhanced ASSERT_ALLOC_CONTEXT in xmalloc()") this restriction is being enforced via an assertion, which will now fail.

Quoted 5 lines

Before that commit cpu unplugging in normal configurations was working just by chance as only the cpu performing schedule_cpu_rm() was doing active work. With core scheduling enabled, however, failures could result from memory allocations not being properly propagated to other cpus' TLBs.

Quoted 3 lines

This isn't accurate, is it?  The problem with initiating a TLB flush with IRQs disabled is that you can deadlock against a remote CPU which is waiting for you to enable IRQs first to take a TLB flush IPI.

As long as only one cpu is trying to allocate/free memory during the stop_machine_run() action the deadlock won't happen.

Quoted 3 lines

How does a memory allocation out of the xenheap result in a TLB flush? Even with split heaps, you're only potentially allocating into a new slot which was unused...

Quoted 5 lines

Yeah, you are right. The main problem would occur only when a virtual address is changed to point at another physical address, which should be quite unlikely.

I can drop that paragraph, as it doesn't really help.

Yeah, I think that would be best.

Quoted 38 lines
Quoted 29 lines
Quoted 29 lines
xen/common/sched/cpupool.c +10 -4
index 58e082eb4c..2506861e4f 100644
@@ -411,22 +411,28 @@ int cpupool_move_domain(struct domain *d,
 struct cpupool *c)
   }
     /* Update affinities of all domains in a cpupool. */
-static void cpupool_update_node_affinity(const struct cpupool *c)
+static void cpupool_update_node_affinity(const struct cpupool *c,
+                                         struct affinity_masks *masks)
   {
-    struct affinity_masks masks;
+    struct affinity_masks local_masks;
       struct domain *d;
   -    if ( !update_node_aff_alloc(&masks) )
-        return;
+    if ( !masks )
+    {
+        if ( !update_node_aff_alloc(&local_masks) )
+            return;
+        masks = &local_masks;
+    }
         rcu_read_lock(&domlist_read_lock);
         for_each_domain_in_cpupool(d, c)
-        domain_update_node_aff(d, &masks);
+        domain_update_node_aff(d, masks);
         rcu_read_unlock(&domlist_read_lock);
Quoted 8 lines

xen/common/sched/cpupool.c int cpupool_move_domain(struct domain *d, struct cpupool *c) · line 438

Quoted 5 lines
xen/common/sched/cpupool.c +2 -0
   -    update_node_aff_free(&masks);
+    if ( masks == &local_masks )
+        update_node_aff_free(masks);
   }
     /*

Why do we need this at all?  domain_update_node_aff() already knows what to do when passed NULL, so this seems like an awfully complicated no-op.

Quoted 3 lines

You do realize that update_node_aff_free() will do something in case masks
was initially NULL?

Quoted 8 lines

By "this", I meant the entire hunk, not just the final if().

What is wrong with passing the (possibly NULL) masks pointer straight down into domain_update_node_aff() and removing all the memory allocation in this function?

But I've also answered that by looking more clearly.  It's about not repeating the memory allocations/freeing for each domain in the pool.

Correct.

Quoted 42 lines

Which does make sense as this is a slow path already, but the complexity here of having conditionally allocated masks is far from simple.

Quoted 18 lines
Quoted 18 lines
Quoted 4 lines
xen/common/sched/cpupool.c +0 -0
@@ -1008,10 +1016,21 @@ static int cf_check cpu_callback(
   {

xen/common/sched/cpupool.c static int cf_check cpu_callback( · line 1026

Quoted 10 lines
xen/common/sched/cpupool.c +5 -0
       unsigned int cpu = (unsigned long)hcpu;
       int rc = 0;
+    static struct cpu_rm_data *mem;
         switch ( action )
       {
       case CPU_DOWN_FAILED:
+        if ( system_state <= SYS_STATE_active )
+        {
+            if ( mem )
+            {

So, this does compile (and indeed I've tested the result), but I can't see how it should.

Quoted 3 lines
Quoted 1 line

mem is guaranteed to be uninitialised at this point, and ...

... it is defined as "static", so it is clearly NULL initially.

Oh, so it is.  That is hiding particularly well in plain sight.

Can it please be this:

xen/common/sched/cpupool.c +2 -1
@@ -1014,9 +1014,10 @@ void cf_check dump_runq(unsigned char key)
  static int cf_check cpu_callback(
      struct notifier_block *nfb, unsigned long action, void *hcpu)
  {
+    static struct cpu_rm_data *mem; /* Protected by cpu_add_remove_lock */
+
      unsigned int cpu = (unsigned long)hcpu;
      int rc = 0;
-    static struct cpu_rm_data *mem;
 
      switch ( action )
      {
Quoted 3 lines

We already split static and non-static variable like this elsewhere for clarity, and identifying the lock which protects the data is useful for anyone coming to this in the future.

Fine with me.

Quoted 6 lines

~Andrew

P.S. as an observation, this isn't safe for parallel AP booting, but I guarantee that this isn't the only example which would want fixing if we wanted to get parallel booting working.

You are aware that mem is used only when removing cpus?

Juergen