Skip to contentSkip to conversation

cpu/hotplug: Allow the CPU in CPU_UP_PREPARE state to be brought up again.

PATCH Superseded Sebastian Andrzej Siewior 1 participant 4 messages Dec 6, 2021 – Dec 14, 2021

Subsystems (3)
lore
Share & tools
lore
#1 lore raw

PATCH v2 1/2 x86/xen: Allow to retry if cpu_initialize_context() failed.

From: Boris Ostrovsky <[email protected]>

If memory allocation in cpu_initialize_context() fails then it will bring up the VCPU and leave with the corresponding CPU bit set in xen_cpu_initialized_map.
The following (presumably successful) CPU bring up will BUG in xen_pv_cpu_up() because nothing for that VCPU would be initialized.

Clear the CPU bits, that were set in cpu_initialize_context() in case the memory allocation fails.

[ bigeasy: Creating a patch from Boris' email. ]

---
 arch/x86/xen/smp_pv.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/x86/xen/smp_pv.c +4 -1
index 6a8f3b53ab834..86368fcef4667 100644
@@ -277,8 +277,11 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
 		return 0;
 
 	ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
-	if (ctxt == NULL)
+	if (ctxt == NULL) {
+		cpumask_clear_cpu(cpu, xen_cpu_initialized_map);
+		cpumask_clear_cpu(cpu, cpu_callout_mask);
 		return -ENOMEM;
+	}
 
 	gdt = get_cpu_gdt_rw(cpu);
 
Signature · 1 line
2.34.1
#2 lore raw

PATCH v2 2/2 cpu/hotplug: Allow the CPU in CPU_UP_PREPARE state to be brought up again.

In reply to Sebastian Andrzej Siewior

From: "Longpeng(Mike)" <[email protected]>

A CPU will not show up in virtualized environment which includes an Enclave. The VM splits its resources into a primary VM and a Enclave VM. While the Enclave is active, the hypervisor will ignore all requests to bring up a CPU and this CPU will remain in CPU_UP_PREPARE state. The kernel will wait up to ten seconds for CPU to show up (do_boot_cpu()) and then rollback the hotplug state back to CPUHP_OFFLINE leaving the CPU state in CPU_UP_PREPARE. The CPU state is set back to CPUHP_TEARDOWN_CPU during the CPU_POST_DEAD stage.

After the Enclave VM terminates, the primary VM can bring up the CPU again.

Allow to bring up the CPU if it is in the CPU_UP_PREPARE state.

[bigeasy: Rewrite commit description.]

---
 kernel/smpboot.c | 7 +++++++
 1 file changed, 7 insertions(+)
kernel/smpboot.c +7 -0
index f6bc0bc8a2aab..b9f54544e7499 100644
@@ -392,6 +392,13 @@ int cpu_check_up_prepare(int cpu)
 		 */
 		return -EAGAIN;
 
+	case CPU_UP_PREPARE:
+		/*
+		 * Timeout while waiting for the CPU to show up. Allow to try
+		 * again later.
+		 */
+		return 0;
+
 	default:
 
 		/* Should not happen.  Famous last words. */
Signature · 1 line
2.34.1