Skip to contentSkip to conversation

xen/arm: Set correct per-cpu cpu_core_mask

PATCH In review Henry Wang 3 participants 6 messages Mar 21, 2024 – May 24, 2024

lore
Share & tools
lore

Henry Wang

author
#0 lore raw

PATCH v3 1/1 xen/arm: Set correct per-cpu cpu_core_mask

In the common sysctl command XEN_SYSCTL_physinfo, the value of cores_per_socket is calculated based on the cpu_core_mask of CPU0. Currently on Arm this is a fixed value 1 (can be checked via xl info), which is not correct. This is because during the Arm CPU online process at boot time, setup_cpu_sibling_map() only sets the per-cpu cpu_core_mask for itself.

cores_per_socket refers to the number of cores that belong to the same socket (NUMA node). Currently Xen on Arm does not support physical CPU hotplug and NUMA, also we assume there is no multithread. Therefore cores_per_socket means all possible CPUs detected from the device tree. Setting the per-cpu cpu_core_mask in setup_cpu_sibling_map() accordingly. Modify the in-code comment which seems to be outdated. Add a warning to users if Xen is running on processors with multithread support.

---
v3:
- Use cpumask_copy() to set cpu_core_mask and drop the unnecessary cpumask_set_cpu(cpu, per_cpu(cpu_core_mask, cpu)).
- In-code comment adjustments.
- Add a warning for multithread.
v2:
- Do not do the multithread check.

---
 xen/arch/arm/smpboot.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
xen/arch/arm/smpboot.c +15 -3
index a84e706d77..b6268be27a 100644
@@ -66,7 +66,11 @@ static bool cpu_is_dead;
 
 /* ID of the PCPU we're running on */
 DEFINE_PER_CPU(unsigned int, cpu_id);
-/* XXX these seem awfully x86ish... */
+/*
+ * Although multithread is part of the Arm spec, there are not many
+ * processors support multithread and current Xen on Arm assumes there
+ * is no multithread.
+ */
 /* representing HT siblings of each logical CPU */
 DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_sibling_mask);
 /* representing HT and core siblings of each logical CPU */
@@ -85,9 +89,13 @@ static int setup_cpu_sibling_map(int cpu)
          !zalloc_cpumask_var(&per_cpu(cpu_core_mask, cpu)) )
         return -ENOMEM;
 
-    /* A CPU is a sibling with itself and is always on its own core. */
+    /*
+     * Currently we assume there is no multithread and NUMA, so
+     * a CPU is a sibling with itself, and the all possible CPUs
+     * are supposed to belong to the same socket (NUMA node).
+     */
     cpumask_set_cpu(cpu, per_cpu(cpu_sibling_mask, cpu));
-    cpumask_set_cpu(cpu, per_cpu(cpu_core_mask, cpu));
+    cpumask_copy(per_cpu(cpu_core_mask, cpu), &cpu_possible_map);
 
     return 0;
 }
@@ -277,6 +285,10 @@ void __init smp_init_cpus(void)
         warning_add("WARNING: HMP COMPUTING HAS BEEN ENABLED.\n"
                     "It has implications on the security and stability of the system,\n"
                     "unless the cpu affinity of all domains is specified.\n");
+
+    if ( system_cpuinfo.mpidr.mt == 1 )
+        warning_add("WARNING: MULTITHREADING HAS BEEN DETECTED ON THE PROCESSOR.\n"
+                    "It might impact the security of the system.\n");
 }
 
 unsigned int __init smp_get_max_cpus(void)
Signature · 1 line
2.34.1
author
#1 lore raw

Hi All,

Gentle ping since it has been a couple of months, any comments on this updated patch? Thanks!

Kind regards,
Henry

Quoted 74 lines · Henry Wang

In the common sysctl command XEN_SYSCTL_physinfo, the value of cores_per_socket is calculated based on the cpu_core_mask of CPU0. Currently on Arm this is a fixed value 1 (can be checked via xl info), which is not correct. This is because during the Arm CPU online process at boot time, setup_cpu_sibling_map() only sets the per-cpu cpu_core_mask for itself.

cores_per_socket refers to the number of cores that belong to the same socket (NUMA node). Currently Xen on Arm does not support physical CPU hotplug and NUMA, also we assume there is no multithread. Therefore cores_per_socket means all possible CPUs detected from the device tree. Setting the per-cpu cpu_core_mask in setup_cpu_sibling_map() accordingly. Modify the in-code comment which seems to be outdated. Add a warning to users if Xen is running on processors with multithread support.

---
v3:
- Use cpumask_copy() to set cpu_core_mask and drop the unnecessary cpumask_set_cpu(cpu, per_cpu(cpu_core_mask, cpu)).
- In-code comment adjustments.
- Add a warning for multithread.
v2:
- Do not do the multithread check.

---
  xen/arch/arm/smpboot.c | 18 +++++++++++++++---
  1 file changed, 15 insertions(+), 3 deletions(-)
xen/arch/arm/smpboot.c +15 -3
index a84e706d77..b6268be27a 100644
@@ -66,7 +66,11 @@ static bool cpu_is_dead;
 
  /* ID of the PCPU we're running on */
  DEFINE_PER_CPU(unsigned int, cpu_id);
-/* XXX these seem awfully x86ish... */
+/*
+ * Although multithread is part of the Arm spec, there are not many
+ * processors support multithread and current Xen on Arm assumes there
+ * is no multithread.
+ */
  /* representing HT siblings of each logical CPU */
  DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_sibling_mask);
  /* representing HT and core siblings of each logical CPU */
@@ -85,9 +89,13 @@ static int setup_cpu_sibling_map(int cpu)
           !zalloc_cpumask_var(&per_cpu(cpu_core_mask, cpu)) )
          return -ENOMEM;
 
-    /* A CPU is a sibling with itself and is always on its own core. */
+    /*
+     * Currently we assume there is no multithread and NUMA, so
+     * a CPU is a sibling with itself, and the all possible CPUs
+     * are supposed to belong to the same socket (NUMA node).
+     */
      cpumask_set_cpu(cpu, per_cpu(cpu_sibling_mask, cpu));
-    cpumask_set_cpu(cpu, per_cpu(cpu_core_mask, cpu));
+    cpumask_copy(per_cpu(cpu_core_mask, cpu), &cpu_possible_map);
 
      return 0;
  }
@@ -277,6 +285,10 @@ void __init smp_init_cpus(void)
          warning_add("WARNING: HMP COMPUTING HAS BEEN ENABLED.\n"
                      "It has implications on the security and stability of the system,\n"
                      "unless the cpu affinity of all domains is specified.\n");
+
+    if ( system_cpuinfo.mpidr.mt == 1 )
+        warning_add("WARNING: MULTITHREADING HAS BEEN DETECTED ON THE PROCESSOR.\n"
+                    "It might impact the security of the system.\n");
  }
 
  unsigned int __init smp_get_max_cpus(void)
Reviewed-by
#2 lore raw

Hi Henry.

Quoted 4 lines · Henry Wang

Hi All,

Gentle ping since it has been a couple of months, any comments on this updated patch? Thanks!

Sorry for the late reply.

Quoted 23 lines

Kind regards,
Henry

Quoted 18 lines · Henry Wang

In the common sysctl command XEN_SYSCTL_physinfo, the value of cores_per_socket is calculated based on the cpu_core_mask of CPU0. Currently on Arm this is a fixed value 1 (can be checked via xl info), which is not correct. This is because during the Arm CPU online process at boot time, setup_cpu_sibling_map() only sets the per-cpu cpu_core_mask for itself.

cores_per_socket refers to the number of cores that belong to the same socket (NUMA node). Currently Xen on Arm does not support physical CPU hotplug and NUMA, also we assume there is no multithread. Therefore cores_per_socket means all possible CPUs detected from the device tree. Setting the per-cpu cpu_core_mask in setup_cpu_sibling_map() accordingly. Modify the in-code comment which seems to be outdated. Add a warning to users if Xen is running on processors with multithread support.

Quoted 18 lines
Quoted 18 lines

---
v3:
- Use cpumask_copy() to set cpu_core_mask and drop the unnecessary cpumask_set_cpu(cpu, per_cpu(cpu_core_mask, cpu)).
- In-code comment adjustments.
- Add a warning for multithread.
v2:
- Do not do the multithread check.

---
  xen/arch/arm/smpboot.c | 18 +++++++++++++++---
  1 file changed, 15 insertions(+), 3 deletions(-)
xen/arch/arm/smpboot.c +0 -0
index a84e706d77..b6268be27a 100644
@@ -66,7 +66,11 @@ static bool cpu_is_dead;
 
Quoted 6 lines

xen/arch/arm/smpboot.c static bool cpu_is_dead; · line 71

Quoted 6 lines
xen/arch/arm/smpboot.c +3 -1
  /* ID of the PCPU we're running on */
  DEFINE_PER_CPU(unsigned int, cpu_id);
-/* XXX these seem awfully x86ish... */
+/*
+ * Although multithread is part of the Arm spec, there are not many
+ * processors support multithread and current Xen on Arm assumes there

NIT: s/support/supporting

Quoted 31 lines
Quoted 31 lines
xen/arch/arm/smpboot.c +12 -2
+ * is no multithread.
+ */
  /* representing HT siblings of each logical CPU */
  DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_sibling_mask);
  /* representing HT and core siblings of each logical CPU */
@@ -85,9 +89,13 @@ static int setup_cpu_sibling_map(int cpu)
           !zalloc_cpumask_var(&per_cpu(cpu_core_mask, cpu)) )
          return -ENOMEM;
 
-    /* A CPU is a sibling with itself and is always on its own core. */
+    /*
+     * Currently we assume there is no multithread and NUMA, so
+     * a CPU is a sibling with itself, and the all possible CPUs
+     * are supposed to belong to the same socket (NUMA node).
+     */
      cpumask_set_cpu(cpu, per_cpu(cpu_sibling_mask, cpu));
-    cpumask_set_cpu(cpu, per_cpu(cpu_core_mask, cpu));
+    cpumask_copy(per_cpu(cpu_core_mask, cpu), &cpu_possible_map);
 
      return 0;
  }
@@ -277,6 +285,10 @@ void __init smp_init_cpus(void)
          warning_add("WARNING: HMP COMPUTING HAS BEEN ENABLED.\n"
                      "It has implications on the security and stability of the system,\n"
                      "unless the cpu affinity of all domains is specified.\n");
+
+    if ( system_cpuinfo.mpidr.mt == 1 )
+        warning_add("WARNING: MULTITHREADING HAS BEEN DETECTED ON THE PROCESSOR.\n"
+                    "It might impact the security of the system.\n");
  }
 
Quoted 2 lines

xen/arch/arm/smpboot.c void __init smp_init_cpus(void) · line 294

Quoted 1 line
xen/arch/arm/smpboot.c +0 -0
  unsigned int __init smp_get_max_cpus(void)

~Michal

author
#3 lore raw

Hi Michal,

Quoted 19 lines · Michal Orzel

Hi Henry.

Quoted 16 lines · Henry Wang
Quoted 16 lines

In the common sysctl command XEN_SYSCTL_physinfo, the value of cores_per_socket is calculated based on the cpu_core_mask of CPU0. Currently on Arm this is a fixed value 1 (can be checked via xl info), which is not correct. This is because during the Arm CPU online process at boot time, setup_cpu_sibling_map() only sets the per-cpu cpu_core_mask for itself.

cores_per_socket refers to the number of cores that belong to the same socket (NUMA node). Currently Xen on Arm does not support physical CPU hotplug and NUMA, also we assume there is no multithread. Therefore cores_per_socket means all possible CPUs detected from the device tree. Setting the per-cpu cpu_core_mask in setup_cpu_sibling_map() accordingly. Modify the in-code comment which seems to be outdated. Add a warning to users if Xen is running on processors with multithread support.

Quoted 3 lines
Quoted 2 lines
Quoted 2 lines

Thanks.

Quoted 7 lines
Quoted 6 lines

xen/arch/arm/smpboot.c static bool cpu_is_dead; · line 71

Quoted 6 lines
   /* ID of the PCPU we're running on */
   DEFINE_PER_CPU(unsigned int, cpu_id);
xen/arch/arm/smpboot.c +3 -1
-/* XXX these seem awfully x86ish... */
+/*
+ * Although multithread is part of the Arm spec, there are not many
+ * processors support multithread and current Xen on Arm assumes there

NIT: s/support/supporting

Sorry, it should have been spotted locally before sending. Anyway, I will correct this in v4 with your Reviewed-by tag taken. Thanks for pointing this out.

Kind regards,
Henry

Quoted 2 lines
Quoted 1 line
Quoted 1 line

__init smp_get_max_cpus(void)

~Michal

#4 lore raw
Quoted 36 lines · Henry Wang

Hi Michal,

Quoted 19 lines · Michal Orzel

Hi Henry.

Quoted 16 lines · Henry Wang
Quoted 16 lines

In the common sysctl command XEN_SYSCTL_physinfo, the value of cores_per_socket is calculated based on the cpu_core_mask of CPU0. Currently on Arm this is a fixed value 1 (can be checked via xl info), which is not correct. This is because during the Arm CPU online process at boot time, setup_cpu_sibling_map() only sets the per-cpu cpu_core_mask for itself.

cores_per_socket refers to the number of cores that belong to the same socket (NUMA node). Currently Xen on Arm does not support physical CPU hotplug and NUMA, also we assume there is no multithread. Therefore cores_per_socket means all possible CPUs detected from the device tree. Setting the per-cpu cpu_core_mask in setup_cpu_sibling_map() accordingly. Modify the in-code comment which seems to be outdated. Add a warning to users if Xen is running on processors with multithread support.

Quoted 3 lines
Quoted 2 lines
Quoted 2 lines

Thanks.

Quoted 7 lines
Quoted 6 lines

xen/arch/arm/smpboot.c static bool cpu_is_dead; · line 71

Quoted 6 lines
   /* ID of the PCPU we're running on */
   DEFINE_PER_CPU(unsigned int, cpu_id);
xen/arch/arm/smpboot.c +3 -1
-/* XXX these seem awfully x86ish... */
+/*
+ * Although multithread is part of the Arm spec, there are not many
+ * processors support multithread and current Xen on Arm assumes there

NIT: s/support/supporting

Quoted 3 lines

Sorry, it should have been spotted locally before sending. Anyway, I will correct this in v4 with your Reviewed-by tag taken. Thanks for pointing this out.

I don't think there is a need to resend a patch just for fixing this typo. It can be done on commit.

~Michal

#5 lore raw

Hi,

Quoted 39 lines · Michal Orzel
Quoted 36 lines · Henry Wang

Hi Michal,

Quoted 19 lines · Michal Orzel

Hi Henry.

Quoted 16 lines · Henry Wang
Quoted 16 lines

In the common sysctl command XEN_SYSCTL_physinfo, the value of cores_per_socket is calculated based on the cpu_core_mask of CPU0. Currently on Arm this is a fixed value 1 (can be checked via xl info), which is not correct. This is because during the Arm CPU online process at boot time, setup_cpu_sibling_map() only sets the per-cpu cpu_core_mask for itself.

cores_per_socket refers to the number of cores that belong to the same socket (NUMA node). Currently Xen on Arm does not support physical CPU hotplug and NUMA, also we assume there is no multithread. Therefore cores_per_socket means all possible CPUs detected from the device tree. Setting the per-cpu cpu_core_mask in setup_cpu_sibling_map() accordingly. Modify the in-code comment which seems to be outdated. Add a warning to users if Xen is running on processors with multithread support.

Quoted 3 lines
Quoted 2 lines
Quoted 2 lines

Thanks.

Quoted 7 lines
Quoted 6 lines

xen/arch/arm/smpboot.c static bool cpu_is_dead; · line 71

Quoted 6 lines
    /* ID of the PCPU we're running on */
    DEFINE_PER_CPU(unsigned int, cpu_id);
xen/arch/arm/smpboot.c +3 -1
-/* XXX these seem awfully x86ish... */
+/*
+ * Although multithread is part of the Arm spec, there are not many
+ * processors support multithread and current Xen on Arm assumes there

NIT: s/support/supporting

Quoted 4 lines
Quoted 3 lines

Sorry, it should have been spotted locally before sending. Anyway, I will correct this in v4 with your Reviewed-by tag taken. Thanks for pointing this out.

I don't think there is a need to resend a patch just for fixing this typo. It can be done on commit.

Fixed and committed.

Cheers,

Quoted 3 lines

~Michal

Signature · 1 line
Julien Grall