Skip to contentSkip to conversation

x86/cpu: maintain a parked CPU bitmap

PATCH In review Chao Gao 4 participants 11 messages Nov 21, 2019

lore
Share & tools
lore

Chao Gao

author
#0 lore raw

PATCH 1/2 x86/cpu: maintain a parked CPU bitmap

It helps to distinguish parked CPUs from those are really offlined or hot-added. We need to know the parked CPUs in order to do a special check against them to ensure that all CPUs, except those are really offlined or hot-added, have the same ucode version.

---
Note that changes on ARM side are untested.

---
 xen/arch/arm/smpboot.c    | 1 +
 xen/arch/x86/cpu/common.c | 4 ++++
 xen/arch/x86/smpboot.c    | 1 +
 xen/common/cpu.c          | 4 ++++
 xen/include/asm-arm/smp.h | 1 +
 xen/include/asm-x86/smp.h | 1 +
 xen/include/xen/cpumask.h | 1 +
 7 files changed, 13 insertions(+)
xen/arch/arm/smpboot.c +1 -0
index 00b64c3..1b57ba4 100644
@@ -39,6 +39,7 @@
 cpumask_t cpu_online_map;
 cpumask_t cpu_present_map;
 cpumask_t cpu_possible_map;
+cpumask_var_t cpu_parked_map;
 
 struct cpuinfo_arm cpu_data[NR_CPUS];
 
xen/arch/x86/cpu/common.c +4 -0
index 6c6bd63..fbb961d 100644
@@ -337,7 +337,11 @@ void __init early_cpu_init(void)
 	}
 
 	if (!(c->x86_vendor & (X86_VENDOR_AMD | X86_VENDOR_HYGON)))
+	{
 		park_offline_cpus = opt_mce;
+		if (park_offline_cpus && !zalloc_cpumask_var(&cpu_parked_map))
+			panic("No memory for CPU parked map\n");
+	}
 
 	initialize_cpu_data(0);
 }
xen/arch/x86/smpboot.c +1 -0
index fa691b6..f66de8d 100644
@@ -60,6 +60,7 @@ cpumask_t cpu_online_map __read_mostly;
 EXPORT_SYMBOL(cpu_online_map);
 
 bool __read_mostly park_offline_cpus;
+cpumask_var_t cpu_parked_map;
 
 unsigned int __read_mostly nr_sockets;
 cpumask_t **__read_mostly socket_cpumask;
xen/common/cpu.c +4 -0
index 66c855c..0090a19 100644
@@ -117,6 +117,8 @@ int cpu_down(unsigned int cpu)
     cpu_notifier_call_chain(cpu, CPU_DEAD, NULL, true);
 
     send_global_virq(VIRQ_PCPU_STATE);
+    if ( park_offline_cpus )
+        cpumask_set_cpu(cpu, cpu_parked_map);
     cpu_hotplug_done();
     return 0;
 
@@ -154,6 +156,8 @@ int cpu_up(unsigned int cpu)
     cpu_notifier_call_chain(cpu, CPU_ONLINE, NULL, true);
 
     send_global_virq(VIRQ_PCPU_STATE);
+    if ( park_offline_cpus )
+        cpumask_clear_cpu(cpu, cpu_parked_map);
 
     cpu_hotplug_done();
     return 0;
xen/include/asm-arm/smp.h +1 -0
index fdbcefa..4b392fa 100644
@@ -19,6 +19,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_mask);
  * would otherwise prefer them to be off?
  */
 #define park_offline_cpus false
+extern cpumask_var_t cpu_parked_map;
 
 extern void noreturn stop_cpu(void);
 
xen/include/asm-x86/smp.h +1 -0
index dbeed2f..886737d 100644
@@ -31,6 +31,7 @@ DECLARE_PER_CPU(cpumask_var_t, scratch_cpumask);
  * would otherwise prefer them to be off?
  */
 extern bool park_offline_cpus;
+extern cpumask_var_t cpu_parked_map;
 
 void smp_send_nmi_allbutself(void);
 
xen/include/xen/cpumask.h +1 -0
index 256b60b..543cec5 100644
@@ -457,6 +457,7 @@ extern cpumask_t cpu_present_map;
 #define for_each_possible_cpu(cpu) for_each_cpu(cpu, &cpu_possible_map)
 #define for_each_online_cpu(cpu)   for_each_cpu(cpu, &cpu_online_map)
 #define for_each_present_cpu(cpu)  for_each_cpu(cpu, &cpu_present_map)
+#define for_each_parked_cpu(cpu)   for_each_cpu(cpu, cpu_parked_map)
 
 /* Copy to/from cpumap provided by control tools. */
 struct xenctl_bitmap;
Signature · 7 lines
1.8.3.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
author
#1 lore raw

PATCH 2/2 microcode: reject late ucode loading if any core is parked

If a core with all of its thread being parked, late ucode loading which currently only loads ucode on online threads would lead to differing ucode revisions in the system. In general, keeping ucode revision consistent would be less error-prone. To this end, if there is a parked thread doesn't have an online sibling thread, late ucode loading is rejected.

Two threads are on the same core or computing unit iff they have the same phys_proc_id and cpu_core_id/compute_unit_id. Based on phys_proc_id and cpu_core_id/compute_unit_id, an unique core id is generated for each thread. And use a bitmap to reduce the number of comparison.

---
Changes:
- traverse the new parked cpu bitmap to find a parked core. It avoids access uninitialized cpu_data of a hot-added CPU.
- use bitmap_empty() rather than find_first_bit() to check whether a bitmap is empty.

---
 xen/arch/x86/microcode.c        | 63 +++++++++++++++++++++++++++++++++++++++++
 xen/include/asm-x86/processor.h |  1 +
 2 files changed, 64 insertions(+)
xen/arch/x86/microcode.c +63 -0
index 65d1f41..dcc8e4b 100644
@@ -584,6 +584,51 @@ static int do_microcode_update(void *patch)
     return ret;
 }
 
+static unsigned int unique_core_id(unsigned int cpu, unsigned int socket_shift)
+{
+    unsigned int core_id = cpu_to_cu(cpu);
+
+    if ( core_id == INVALID_CUID )
+        core_id = cpu_to_core(cpu);
+
+    return (cpu_to_socket(cpu) << socket_shift) + core_id;
+}
+
+static int has_parked_core(void)
+{
+    int ret;
+    unsigned int cpu, max_bits, core_width;
+    unsigned int max_sockets = 1, max_cores = 1;
+    unsigned long *bitmap;
+
+    if ( !park_offline_cpus )
+        return 0;
+
+    for_each_parked_cpu(cpu)
+    {
+        /* Note that cpu_to_socket() get an ID starting from 0. */
+        max_sockets = max(max_sockets, cpu_to_socket(cpu) + 1);
+        max_cores = max(max_cores, cpu_data[cpu].x86_max_cores);
+    }
+
+    core_width = fls(max_cores);
+    max_bits = max_sockets << core_width;
+    bitmap = xzalloc_array(unsigned long, BITS_TO_LONGS(max_bits));
+    if ( !bitmap )
+        return -ENOMEM;
+
+    for_each_parked_cpu(cpu)
+        __set_bit(unique_core_id(cpu, core_width), bitmap);
+
+    for_each_online_cpu(cpu)
+        __clear_bit(unique_core_id(cpu, core_width), bitmap);
+
+    ret = !bitmap_empty(bitmap, max_bits);
+    xfree(bitmap);
+
+    return ret;
+}
+
 int microcode_update(XEN_GUEST_HANDLE_PARAM(const_void) buf, unsigned long len)
 {
     int ret;
@@ -629,6 +674,24 @@ int microcode_update(XEN_GUEST_HANDLE_PARAM(const_void) buf, unsigned long len)
         return -EPERM;
     }
 
+    /*
+     * If there is a core with all of its threads parked, late loading may
+     * cause differing ucode revisions in the system. Refuse this operation.
+     */
+    ret = has_parked_core();
+    if ( ret )
+    {
+        if ( ret > 0 )
+        {
+            printk(XENLOG_WARNING
+                   "Aborted: found a parked core (parked CPU bitmap: %*pbl)\n",
+                   CPUMASK_PR(cpu_parked_map));
+            ret = -EPERM;
+        }
+        xfree(buffer);
+        goto put;
+    }
+
     patch = parse_blob(buffer, len);
     xfree(buffer);
     if ( IS_ERR(patch) )
xen/include/asm-x86/processor.h +1 -0
index 557f9b6..f8a9e93 100644
@@ -171,6 +171,7 @@ extern unsigned int init_intel_cacheinfo(struct cpuinfo_x86 *c);
 
 #define cpu_to_core(_cpu)   (cpu_data[_cpu].cpu_core_id)
 #define cpu_to_socket(_cpu) (cpu_data[_cpu].phys_proc_id)
+#define cpu_to_cu(_cpu)     (cpu_data[_cpu].compute_unit_id)
 
 unsigned int apicid_to_socket(unsigned int);
 
Signature · 7 lines
1.8.3.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#2 lore raw

Re: [Xen-devel] [PATCH v1 2/2] microcode: reject late ucode loading if any core is parked

Quoted 6 lines · Chao Gao

If a core with all of its thread being parked, late ucode loading which currently only loads ucode on online threads would lead to differing ucode revisions in the system. In general, keeping ucode revision consistent would be less error-prone. To this end, if there is a parked thread doesn't have an online sibling thread, late ucode loading is rejected.

I'm confused. I thought we had agreed that the long term solution would be to briefly bring online a thread of cores with all their threads parked. What you do here was meant to be a temporary step only for 4.13, for which it is too late now (unless Jürgen indicates otherwise).

Quoted 25 lines
xen/arch/x86/microcode.c +19 -0
@@ -584,6 +584,51 @@ static int do_microcode_update(void *patch)
     return ret;
 }
 
+static unsigned int unique_core_id(unsigned int cpu, unsigned int socket_shift)
+{
+    unsigned int core_id = cpu_to_cu(cpu);
+
+    if ( core_id == INVALID_CUID )
+        core_id = cpu_to_core(cpu);
+
+    return (cpu_to_socket(cpu) << socket_shift) + core_id;
+}
+
+static int has_parked_core(void)
+{
+    int ret;
+    unsigned int cpu, max_bits, core_width;
+    unsigned int max_sockets = 1, max_cores = 1;
+    unsigned long *bitmap;
+
+    if ( !park_offline_cpus )
+        return 0;

xen/arch/x86/microcode.c static int do_microcode_update(void *patch) · line 615

Quoted 10 lines
xen/arch/x86/microcode.c +10 -0
+
+    for_each_parked_cpu(cpu)
+    {
+        /* Note that cpu_to_socket() get an ID starting from 0. */
+        max_sockets = max(max_sockets, cpu_to_socket(cpu) + 1);
+        max_cores = max(max_cores, cpu_data[cpu].x86_max_cores);
+    }
+
+    core_width = fls(max_cores);
+    max_bits = max_sockets << core_width;

Isn't this off by one? If max_cores is 1, you don't need to shift max_sockets (or the cpu_to_socket() value in unique_core_id()) at all, for example.

With this in mind, instead of the park_offline_cpus check at the top of the function, wouldn't it make sense to check here whether max_sockets and max_cores are both still 1, in which case at least one thread of the only core of the only socket in the system is obviously still online (the one we're running on)?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#3 lore raw

Re: [Xen-devel] [PATCH v1 2/2] microcode: reject late ucode loading if any core is parked

Quoted 11 lines · Jan Beulich
Quoted 6 lines · Chao Gao

If a core with all of its thread being parked, late ucode loading which currently only loads ucode on online threads would lead to differing ucode revisions in the system. In general, keeping ucode revision consistent would be less error-prone. To this end, if there is a parked thread doesn't have an online sibling thread, late ucode loading is rejected.

I'm confused. I thought we had agreed that the long term solution would be to briefly bring online a thread of cores with all their threads parked.

I don't remeber that we reached such an aggrement. But if it happened, I am really sorry for forgeting it.

Actually, I think Dom0 has the information (cpu topology and each cpu's offline/online status) to decide if there is a parked core or not. IMO, rejecting late loading in this case is just a defense check. Dom0 is able to correct the situation by bringing up some cpus.

Quoted 44 lines

What you do here was meant to be a temporary step only for 4.13, for which it is too late now (unless Jürgen indicates otherwise).

Quoted 25 lines
xen/arch/x86/microcode.c +19 -0
@@ -584,6 +584,51 @@ static int do_microcode_update(void *patch)
     return ret;
 }
 
+static unsigned int unique_core_id(unsigned int cpu, unsigned int socket_shift)
+{
+    unsigned int core_id = cpu_to_cu(cpu);
+
+    if ( core_id == INVALID_CUID )
+        core_id = cpu_to_core(cpu);
+
+    return (cpu_to_socket(cpu) << socket_shift) + core_id;
+}
+
+static int has_parked_core(void)
+{
+    int ret;
+    unsigned int cpu, max_bits, core_width;
+    unsigned int max_sockets = 1, max_cores = 1;
+    unsigned long *bitmap;
+
+    if ( !park_offline_cpus )
+        return 0;

xen/arch/x86/microcode.c static int do_microcode_update(void *patch) · line 615

Quoted 10 lines
xen/arch/x86/microcode.c +10 -0
+
+    for_each_parked_cpu(cpu)
+    {
+        /* Note that cpu_to_socket() get an ID starting from 0. */
+        max_sockets = max(max_sockets, cpu_to_socket(cpu) + 1);
+        max_cores = max(max_cores, cpu_data[cpu].x86_max_cores);
+    }
+
+    core_width = fls(max_cores);
+    max_bits = max_sockets << core_width;

Isn't this off by one? If max_cores is 1, you don't need to shift max_sockets (or the cpu_to_socket() value in unique_core_id()) at all, for example.

Quoted 5 lines

With this in mind, instead of the park_offline_cpus check at the top of the function, wouldn't it make sense to check here whether max_sockets and max_cores are both still 1, in which case at least one thread of the only core of the only socket in the system is obviously still online (the one we're running on)?

Agree. Will follow your suggestion.

Thanks
Chao

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#4 lore raw

Re: [Xen-devel] [PATCH v1 2/2] microcode: reject late ucode loading if any core is parked

Quoted 13 lines · Chao Gao
Quoted 11 lines · Jan Beulich
Quoted 6 lines · Chao Gao

If a core with all of its thread being parked, late ucode loading which currently only loads ucode on online threads would lead to differing ucode revisions in the system. In general, keeping ucode revision consistent would be less error-prone. To this end, if there is a parked thread doesn't have an online sibling thread, late ucode loading is rejected.

I'm confused. I thought we had agreed that the long term solution would be to briefly bring online a thread of cores with all their threads parked.

Quoted 7 lines

I don't remeber that we reached such an aggrement. But if it happened, I am really sorry for forgeting it.

Actually, I think Dom0 has the information (cpu topology and each cpu's offline/online status) to decide if there is a parked core or not. IMO, rejecting late loading in this case is just a defense check. Dom0 is able to correct the situation by bringing up some cpus.

Dom0 can _fully_ bring up CPUs, but not with the intent of _just_ getting their ucode updated.

Quoted 44 lines
Quoted 44 lines

What you do here was meant to be a temporary step only for 4.13, for which it is too late now (unless Jürgen indicates otherwise).

Quoted 25 lines
xen/arch/x86/microcode.c +19 -0
@@ -584,6 +584,51 @@ static int do_microcode_update(void *patch)
     return ret;
 }
 
+static unsigned int unique_core_id(unsigned int cpu, unsigned int socket_shift)
+{
+    unsigned int core_id = cpu_to_cu(cpu);
+
+    if ( core_id == INVALID_CUID )
+        core_id = cpu_to_core(cpu);
+
+    return (cpu_to_socket(cpu) << socket_shift) + core_id;
+}
+
+static int has_parked_core(void)
+{
+    int ret;
+    unsigned int cpu, max_bits, core_width;
+    unsigned int max_sockets = 1, max_cores = 1;
+    unsigned long *bitmap;
+
+    if ( !park_offline_cpus )
+        return 0;

xen/arch/x86/microcode.c static int do_microcode_update(void *patch) · line 615

Quoted 10 lines
xen/arch/x86/microcode.c +10 -0
+
+    for_each_parked_cpu(cpu)
+    {
+        /* Note that cpu_to_socket() get an ID starting from 0. */
+        max_sockets = max(max_sockets, cpu_to_socket(cpu) + 1);
+        max_cores = max(max_cores, cpu_data[cpu].x86_max_cores);
+    }
+
+    core_width = fls(max_cores);
+    max_bits = max_sockets << core_width;

Isn't this off by one? If max_cores is 1, you don't need to shift max_sockets (or the cpu_to_socket() value in unique_core_id()) at all, for example.

Quoted 7 lines
Quoted 5 lines

With this in mind, instead of the park_offline_cpus check at the top of the function, wouldn't it make sense to check here whether max_sockets and max_cores are both still 1, in which case at least one thread of the only core of the only socket in the system is obviously still online (the one we're running on)?

Agree. Will follow your suggestion.

Aiui it'll be correct again only if the parked map gets allocated unconditionally.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#5 lore raw

Re: [Xen-devel] [PATCH v1 2/2] microcode: reject late ucode loading if any core is parked

In reply to Jan Beulich
Quoted 8 lines · Jan Beulich
Quoted 6 lines · Chao Gao

If a core with all of its thread being parked, late ucode loading which currently only loads ucode on online threads would lead to differing ucode revisions in the system. In general, keeping ucode revision consistent would be less error-prone. To this end, if there is a parked thread doesn't have an online sibling thread, late ucode loading is rejected.

Quoted 5 lines

I'm confused. I thought we had agreed that the long term solution would be to briefly bring online a thread of cores with all their threads parked. What you do here was meant to be a temporary step only for 4.13, for which it is too late now (unless Jürgen indicates otherwise).

Which I don't intend to do.

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#6 lore raw
In reply to Chao Gao

Hi,

Quoted 23 lines · Chao Gao

It helps to distinguish parked CPUs from those are really offlined or hot-added. We need to know the parked CPUs in order to do a special check against them to ensure that all CPUs, except those are really offlined or hot-added, have the same ucode version.

---
Note that changes on ARM side are untested.

---
  xen/arch/arm/smpboot.c    | 1 +
  xen/arch/x86/cpu/common.c | 4 ++++
  xen/arch/x86/smpboot.c    | 1 +
  xen/common/cpu.c          | 4 ++++
  xen/include/asm-arm/smp.h | 1 +
  xen/include/asm-x86/smp.h | 1 +
  xen/include/xen/cpumask.h | 1 +
  7 files changed, 13 insertions(+)
xen/arch/arm/smpboot.c +0 -0
index 00b64c3..1b57ba4 100644

xen/arch/arm/smpboot.c line 42

Quoted 4 lines
xen/arch/arm/smpboot.c +1 -0
@@ -39,6 +39,7 @@
  cpumask_t cpu_online_map;
  cpumask_t cpu_present_map;
  cpumask_t cpu_possible_map;
+cpumask_var_t cpu_parked_map;

You define cpu_parked_map but AFAIK it will never get allocated. The risk here is any access to that variable will result to a fault.

Looking at the changes below, it looks like access in common code will be protected by park_offline_cpus. This is always false on Arm, so the compiler should remove any access to cpu_parked_map.

With that in mind, I think it would be best to only provide a prototype for cpu_parked_map and so the linker can warn if someone used it.

xen/include/asm-arm/smp.h DECLARE_PER_CPU(cpumask_var_t, cpu_core_mask); · line 22

Quoted 9 lines
xen/include/asm-arm/smp.h +1 -0
index fdbcefa..4b392fa 100644
@@ -19,6 +19,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_mask);
   * would otherwise prefer them to be off?
   */
  #define park_offline_cpus false
+extern cpumask_var_t cpu_parked_map;

The prototype should be the same for all architectures. So is there any reason to duplicate it?

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#7 lore raw
Quoted 12 lines · Julien Grall

xen/arch/arm/smpboot.c line 42

Quoted 7 lines · Chao Gao
xen/arch/arm/smpboot.c +1 -0
@@ -39,6 +39,7 @@
  cpumask_t cpu_online_map;
  cpumask_t cpu_present_map;
  cpumask_t cpu_possible_map;
+cpumask_var_t cpu_parked_map;

You define cpu_parked_map but AFAIK it will never get allocated. The risk here is any access to that variable will result to a fault.

Quoted 6 lines

Looking at the changes below, it looks like access in common code will be protected by park_offline_cpus. This is always false on Arm, so the compiler should remove any access to cpu_parked_map.

With that in mind, I think it would be best to only provide a prototype for cpu_parked_map and so the linker can warn if someone used it.

+1

In fact I wonder whether the maintenance of the map should live in common code in the first place. While clearing the respective bit in cpu_up() looks correct (and could be done without any if()), I'm not convinced the setting of the bit in cpu_down() is going to be correct in all cases. I'd rather leave this to the relevant callers of cpu_down(). To deal with cpu_add_remove_lock not being held perhaps it would be best to set the flag _before_ calling cpu_down(); consumers of the map then would need to double check that a CPU is not _also_ (still) online.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#8 lore raw
Quoted 13 lines · Jan Beulich
Quoted 12 lines · Julien Grall

xen/arch/arm/smpboot.c line 42

Quoted 7 lines · Chao Gao
xen/arch/arm/smpboot.c +1 -0
@@ -39,6 +39,7 @@
  cpumask_t cpu_online_map;
  cpumask_t cpu_present_map;
  cpumask_t cpu_possible_map;
+cpumask_var_t cpu_parked_map;

You define cpu_parked_map but AFAIK it will never get allocated. The risk here is any access to that variable will result to a fault.

Quoted 8 lines
Quoted 6 lines

Looking at the changes below, it looks like access in common code will be protected by park_offline_cpus. This is always false on Arm, so the compiler should remove any access to cpu_parked_map.

With that in mind, I think it would be best to only provide a prototype for cpu_parked_map and so the linker can warn if someone used it.

+1

Will do. I added this because I am not sure all compilers would omit such access.

Quoted 4 lines

In fact I wonder whether the maintenance of the map should live in common code in the first place. While clearing the respective bit in cpu_up() looks correct (and could be done without any if()),

But when park_offline_cpus() is false, the map isn't allocated. I don't think it is safe to access the map in this case.

Quoted 2 lines

I'm not convinced the setting of the bit in cpu_down() is going to be correct in all cases.

Do you mean in some cases, cpu_down() is to really offline a CPU even park_offline_cpus is set? And in this case, setting the bit isn't correct.

If yes, one thing confuses me is that cpu_down() would call cpu_notifier_call_chain() several times unconditionally. And registered callbacks take actions depending on the value of park_offline_cpus. I expected that callbacks would do more check to avoid parking a CPU in some cases.

Thanks
Chao

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#9 lore raw
Quoted 27 lines · Chao Gao
Quoted 13 lines · Jan Beulich
Quoted 12 lines · Julien Grall

xen/arch/arm/smpboot.c line 42

Quoted 7 lines · Chao Gao
xen/arch/arm/smpboot.c +1 -0
@@ -39,6 +39,7 @@
  cpumask_t cpu_online_map;
  cpumask_t cpu_present_map;
  cpumask_t cpu_possible_map;
+cpumask_var_t cpu_parked_map;

You define cpu_parked_map but AFAIK it will never get allocated. The risk here is any access to that variable will result to a fault.

Quoted 8 lines
Quoted 6 lines

Looking at the changes below, it looks like access in common code will be protected by park_offline_cpus. This is always false on Arm, so the compiler should remove any access to cpu_parked_map.

With that in mind, I think it would be best to only provide a prototype for cpu_parked_map and so the linker can warn if someone used it.

+1

Will do. I added this because I am not sure all compilers would omit such access.

Quoted 1 line
Quoted 6 lines
Quoted 3 lines

In fact I wonder whether the maintenance of the map should live in common code in the first place. While clearing the respective bit in cpu_up() looks correct (and could be done without any if()),

But when park_offline_cpus() is false, the map isn't allocated. I don't think it is safe to access the map in this case.

Oh, you're right of course. Unless the map was allocated unconditionally ...

Quoted 6 lines
Quoted 2 lines

I'm not convinced the setting of the bit in cpu_down() is going to be correct in all cases.

Do you mean in some cases, cpu_down() is to really offline a CPU even park_offline_cpus is set? And in this case, setting the bit isn't correct.

The purposes of cpu_down() calls _may_ be different. Plus whether there's parking wanted/necessary for an architecture should remain
- as much as possible - an architecture thing to deal with. I.e. despite park_offline_cpus being used in common code, I think we should strive to avoid adding more there when it can be avoided.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#10 lore raw
In reply to Chao Gao

xen/arch/x86/cpu/common.c void __init early_cpu_init(void) · line 344

Quoted 11 lines · Chao Gao
xen/arch/x86/cpu/common.c +4 -0
@@ -337,7 +337,11 @@ void __init early_cpu_init(void)
 	}
 
 	if (!(c->x86_vendor & (X86_VENDOR_AMD | X86_VENDOR_HYGON)))
+	{
 		park_offline_cpus = opt_mce;
+		if (park_offline_cpus && !zalloc_cpumask_var(&cpu_parked_map))
+			panic("No memory for CPU parked map\n");
+	}

Maybe shorter as

	if (!(c->x86_vendor & (X86_VENDOR_AMD | X86_VENDOR_HYGON)) && opt_mce)
	{
		if (!zalloc_cpumask_var(&cpu_parked_map))
			panic("No memory for CPU parked map\n");
		park_offline_cpus = true;
	}

?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel