Re: [Xen-devel] [PATCH v3 09/10] xen/arm: Free memory allocated for sibling/core maps on CPU hot-unplug

2018-04-30 Thread Julien Grall

Hi Mirela,

On 27/04/18 18:12, Mirela Simonovic wrote:

The memory allocated in setup_cpu_sibling_map() when a CPU is hotplugged
has to be freed when the CPU is hot-unplugged. This is done in
remove_cpu_sibling_map() and called when the CPU dies. The call to
remove_cpu_sibling_map() is made from a notifier callback when
CPU_DEAD event is received.

Signed-off-by: Mirela Simonovic 

---
CC: Stefano Stabellini 
CC: Julien Grall 
---
Changes in v3:
-Use notifier to trigger remove_cpu_sibling_map() when the CPU dies.
---
  xen/arch/arm/smpboot.c | 34 ++
  1 file changed, 34 insertions(+)

diff --git a/xen/arch/arm/smpboot.c b/xen/arch/arm/smpboot.c
index ad1f6b751b..b833e3a754 100644
--- a/xen/arch/arm/smpboot.c
+++ b/xen/arch/arm/smpboot.c
@@ -89,6 +89,12 @@ static void setup_cpu_sibling_map(int cpu)
  cpumask_set_cpu(cpu, per_cpu(cpu_core_mask, cpu));
  }
  
+static void remove_cpu_sibling_map(int cpu)

+{
+free_cpumask_var(per_cpu(cpu_sibling_mask, cpu));
+free_cpumask_var(per_cpu(cpu_core_mask, cpu));
+}
+
  void __init
  smp_clear_cpu_maps (void)
  {
@@ -499,6 +505,34 @@ void __cpu_die(unsigned int cpu)
  smp_mb();
  }
  
+static int cpu_smpboot_callback(

+struct notifier_block *nfb, unsigned long action, void *hcpu)
+{
+unsigned int cpu = (unsigned long)hcpu;
+
+switch ( action )
+{
+case CPU_DEAD:
+remove_cpu_sibling_map(cpu);
+break;
+default:
+break;
+}
+
+return NOTIFY_DONE;
+}
+
+static struct notifier_block cpu_smpboot_nfb = {
+.notifier_call = cpu_smpboot_callback,
+};
+
+static int __init cpu_smpboot_notifier_init(void)
+{
+register_cpu_notifier(_smpboot_nfb);
+return 0;
+}
+__initcall(cpu_smpboot_notifier_init);


I think this notifiers should go in preinit smp to cover the case where 
a secondary CPU dies beforehand the initcall.


Cheers,

--
Julien Grall

___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

[Xen-devel] [PATCH v3 09/10] xen/arm: Free memory allocated for sibling/core maps on CPU hot-unplug

2018-04-27 Thread Mirela Simonovic
The memory allocated in setup_cpu_sibling_map() when a CPU is hotplugged
has to be freed when the CPU is hot-unplugged. This is done in
remove_cpu_sibling_map() and called when the CPU dies. The call to
remove_cpu_sibling_map() is made from a notifier callback when
CPU_DEAD event is received.

Signed-off-by: Mirela Simonovic 

---
CC: Stefano Stabellini 
CC: Julien Grall 
---
Changes in v3:
-Use notifier to trigger remove_cpu_sibling_map() when the CPU dies.
---
 xen/arch/arm/smpboot.c | 34 ++
 1 file changed, 34 insertions(+)

diff --git a/xen/arch/arm/smpboot.c b/xen/arch/arm/smpboot.c
index ad1f6b751b..b833e3a754 100644
--- a/xen/arch/arm/smpboot.c
+++ b/xen/arch/arm/smpboot.c
@@ -89,6 +89,12 @@ static void setup_cpu_sibling_map(int cpu)
 cpumask_set_cpu(cpu, per_cpu(cpu_core_mask, cpu));
 }
 
+static void remove_cpu_sibling_map(int cpu)
+{
+free_cpumask_var(per_cpu(cpu_sibling_mask, cpu));
+free_cpumask_var(per_cpu(cpu_core_mask, cpu));
+}
+
 void __init
 smp_clear_cpu_maps (void)
 {
@@ -499,6 +505,34 @@ void __cpu_die(unsigned int cpu)
 smp_mb();
 }
 
+static int cpu_smpboot_callback(
+struct notifier_block *nfb, unsigned long action, void *hcpu)
+{
+unsigned int cpu = (unsigned long)hcpu;
+
+switch ( action )
+{
+case CPU_DEAD:
+remove_cpu_sibling_map(cpu);
+break;
+default:
+break;
+}
+
+return NOTIFY_DONE;
+}
+
+static struct notifier_block cpu_smpboot_nfb = {
+.notifier_call = cpu_smpboot_callback,
+};
+
+static int __init cpu_smpboot_notifier_init(void)
+{
+register_cpu_notifier(_smpboot_nfb);
+return 0;
+}
+__initcall(cpu_smpboot_notifier_init);
+
 /*
  * Local variables:
  * mode: C
-- 
2.13.0


___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel