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

tip-bot2 for Boris Ostrovsky posted 1 patch 4 years ago
arch/x86/xen/smp_pv.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
[tip: smp/core] x86/xen: Allow to retry if cpu_initialize_context() failed.
Posted by tip-bot2 for Boris Ostrovsky 4 years ago
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 <boris.ostrovsky@oracle.com>
AuthorDate:    Wed, 09 Feb 2022 09:02:13 +01:00
Committer:     Thomas Gleixner <tglx@linutronix.de>
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. ]

Signed-off-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20220209080214.1439408-2-bigeasy@linutronix.de

---
 arch/x86/xen/smp_pv.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/x86/xen/smp_pv.c b/arch/x86/xen/smp_pv.c
index 688aa8b..ba7af2e 100644
--- a/arch/x86/xen/smp_pv.c
+++ b/arch/x86/xen/smp_pv.c
@@ -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);