Skip to contentSkip to conversation

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

PATCH Applied Sebastian Andrzej Siewior 2 participants 5 messages Feb 9, 2022 – Apr 12, 2022

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 4a6019238ee7d..57c3f9332ec94 100644
@@ -260,8 +260,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

[tip: smp/core] x86/xen: Allow to retry if cpu_initialize_context() failed.

The following commit has been merged into the smp/core branch of tip:

The following commit has been merged into the smp/core branch of tip:

Commit-ID:     e8a69f12f01f487c6a0e704eb14ccf2dd015277d
Gitweb:        https://git.kernel.org/tip/e8a69f12f01f487c6a0e704eb14ccf2dd015277d
Author:        Boris Ostrovsky <[email protected]>
AuthorDate:    Wed, 09 Feb 2022 09:02:13 +01:00
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Tue, 12 Apr 2022 14:13:01 +02:00

x86/xen: Allow to retry if cpu_initialize_context() failed.

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 688aa8b..ba7af2e 100644
@@ -260,8 +260,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);
 
#3 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
merge bot Applied
#4 lore raw
The following commit has been merged into the smp/core branch of tip:

The following commit has been merged into the smp/core branch of tip:

Commit-ID:     c7dfb2591b23856182e2c9da6b1d526ef7fd6b2e
Gitweb:        https://git.kernel.org/tip/c7dfb2591b23856182e2c9da6b1d526ef7fd6b2e
Author:        Longpeng(Mike) <[email protected]>
AuthorDate:    Wed, 09 Feb 2022 09:02:14 +01:00
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Tue, 12 Apr 2022 14:13:01 +02:00

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

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 f6bc0bc..b9f5454 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. */