[PATCH 03/10] x86: jailhouse: Enable APIC and SMP support
From: Jan Kiszka
Date: Thu Nov 16 2017 - 02:47:58 EST
From: Jan Kiszka <jan.kiszka@xxxxxxxxxxx>
Register the APIC which Jailhouse always exposes at 0xfee00000 if in
xAPIC mode or via MSRs as x2APIC. The latter is only available if it was
already activated because there is no virtualization to switch its mode
during runtime.
Jailhouse requires the APIC to be operated in phys-flat mode. Ensure
that this mode is selected by Linux.
The available CPUs are taken from the setup data structure that the
loader filled and registered with the kernel.
Signed-off-by: Jan Kiszka <jan.kiszka@xxxxxxxxxxx>
---
arch/x86/kernel/apic/apic_flat_64.c | 4 +++-
arch/x86/kernel/jailhouse.c | 34 ++++++++++++++++++++++++++++++++++
2 files changed, 37 insertions(+), 1 deletion(-)
diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
index 34bfdfe29a04..56d22b4f9ffd 100644
--- a/arch/x86/kernel/apic/apic_flat_64.c
+++ b/arch/x86/kernel/apic/apic_flat_64.c
@@ -19,6 +19,7 @@
#include <asm/smp.h>
#include <asm/apic.h>
#include <asm/ipi.h>
+#include <asm/jailhouse_para.h>
#include <linux/acpi.h>
@@ -235,7 +236,8 @@ static void physflat_send_IPI_all(int vector)
static int physflat_probe(void)
{
- if (apic == &apic_physflat || num_possible_cpus() > 8)
+ if (apic == &apic_physflat || num_possible_cpus() > 8 ||
+ jailhouse_paravirt())
return 1;
return 0;
diff --git a/arch/x86/kernel/jailhouse.c b/arch/x86/kernel/jailhouse.c
index bc0f49a6172d..ce9416c70656 100644
--- a/arch/x86/kernel/jailhouse.c
+++ b/arch/x86/kernel/jailhouse.c
@@ -11,6 +11,7 @@
*/
#include <linux/kernel.h>
+#include <asm/apic.h>
#include <asm/cpu.h>
#include <asm/hypervisor.h>
#include <asm/setup.h>
@@ -48,10 +49,16 @@ static uint32_t __init jailhouse_detect(void)
return jailhouse_cpuid_base();
}
+static unsigned int x2apic_get_apic_id(unsigned long id)
+{
+ return id;
+}
+
static void __init jailhouse_init_platform(void)
{
u64 pa_data = boot_params.hdr.setup_data;
struct jailhouse_setup_data *data;
+ unsigned int cpu;
data = early_memremap(pa_data, sizeof(*data));
@@ -59,6 +66,23 @@ static void __init jailhouse_init_platform(void)
data->compatible_version > SETUP_REQUIRED_VERSION)
panic("Jailhouse: Unsupported setup data structure");
+#ifdef CONFIG_X86_X2APIC
+ /*
+ * Register x2APIC handlers early. We need them when running
+ * register_lapic_address.
+ */
+ if (x2apic_enabled()) {
+ apic->read = native_apic_msr_read;
+ apic->write = native_apic_msr_write;
+ apic->get_apic_id = x2apic_get_apic_id;
+ }
+#endif
+ register_lapic_address(0xfee00000);
+ for (cpu = 0; cpu < data->num_cpus; cpu++)
+ generic_processor_info(data->cpu_ids[cpu],
+ boot_cpu_apic_version);
+ smp_found_config = 1;
+
early_memunmap(data, sizeof(*data));
}
@@ -67,10 +91,20 @@ bool jailhouse_paravirt(void)
return jailhouse_cpuid_base() != 0;
}
+static bool jailhouse_x2apic_available(void)
+{
+ /*
+ * The x2APIC is only available if the root cell enabled it. Jailhouse
+ * does not support switching between xAPIC and x2APIC.
+ */
+ return x2apic_enabled();
+}
+
const struct hypervisor_x86 x86_hyper_jailhouse __refconst = {
.name = "Jailhouse",
.detect = jailhouse_detect,
.init = {
.init_platform = jailhouse_init_platform,
+ .x2apic_available = jailhouse_x2apic_available,
},
};
--
2.12.3