[PATCH 6/6] pre states for x86

From: David Woodhouse
Date: Mon Feb 01 2021 - 05:42:11 EST


Utterly broken because the bringup uses global initial_stack and initial_gs
variables, and the TSC sync is similarly hosed (I should probably do one
at a time).

The bringup is going to be the most fun to fix, because the AP coming up
doesn't actually have a lot that it *can* use to disambiguate itself from
the others. Starting them at different locations is mostly a non-starter
as we can only specify a page address under 1MiB and there are only 256
of those even if we could allocate them *all* to start different CPUs.
I think we need to get them to find their own logical CPU# from their
APICID, perhaps by trawling the per_cpu x86_cpu_to_apicid or some other
means, then find their initial stack / %gs from that.

We also need to work out if we can eliminate the real-mode stack for the
trampoline, or do some locking if we really must share it perhaps.
---
arch/x86/kernel/smpboot.c | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index 649b8236309b..03f63027fdad 100644
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -57,6 +57,7 @@
#include <linux/pgtable.h>
#include <linux/overflow.h>
#include <linux/syscore_ops.h>
+#include <linux/smpboot.h>

#include <asm/acpi.h>
#include <asm/desc.h>
@@ -1217,14 +1218,6 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
{
int ret;

- ret = do_cpu_up(cpu, tidle);
- if (ret)
- return ret;
-
- ret = do_wait_cpu_initialized(cpu);
- if (ret)
- return ret;
-
ret = do_wait_cpu_callin(cpu);
if (ret)
return ret;
@@ -1241,6 +1234,16 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
return ret;
}

+int native_cpu_kick(unsigned int cpu)
+{
+ return do_cpu_up(cpu, idle_thread_get(cpu));
+}
+
+int native_cpu_wait_init(unsigned int cpu)
+{
+ return do_wait_cpu_initialized(cpu);
+}
+
/**
* arch_disable_smp_support() - disables SMP support for x86 at runtime
*/
@@ -1412,6 +1415,11 @@ void __init native_smp_prepare_cpus(unsigned int max_cpus)
smp_quirk_init_udelay();

speculative_store_bypass_ht_init();
+
+ cpuhp_setup_state_nocalls(CPUHP_BP_PARALLEL_DYN, "x86/cpu:kick",
+ native_cpu_kick, NULL);
+ cpuhp_setup_state_nocalls(CPUHP_BP_PARALLEL_DYN, "x86/cpu:wait-init",
+ native_cpu_wait_init, NULL);
}

void arch_thaw_secondary_cpus_begin(void)
--
2.29.2