]> git.karo-electronics.de Git - linux-beck.git/commitdiff
x86/apic: Enable x2APIC without interrupt remapping under KVM
authorGleb Natapov <gleb@redhat.com>
Mon, 20 Jul 2009 12:24:17 +0000 (15:24 +0300)
committerIngo Molnar <mingo@elte.hu>
Wed, 5 Aug 2009 12:28:50 +0000 (14:28 +0200)
KVM would like to provide x2APIC interface to a guest without emulating
interrupt remapping device. The reason KVM prefers guest to use x2APIC
is that x2APIC interface is better virtualizable and provides better
performance than mmio xAPIC interface:

 - msr exits are faster than mmio (no page table walk, emulation)
 - no need to read back ICR to look at the busy bit
 - one 64 bit ICR write instead of two 32 bit writes
 - shared code with the Hyper-V paravirt interface

Included patch changes x2APIC enabling logic to enable it even if IR
initialization failed, but kernel runs under KVM and no apic id is
greater than 255 (if there is one spec requires BIOS to move to x2apic
mode before starting an OS).

-v2: fix build
-v3: fix bug causing compiler warning

Signed-off-by: Gleb Natapov <gleb@redhat.com>
Acked-by: Suresh Siddha <suresh.b.siddha@intel.com>
Cc: Sheng Yang <sheng@linux.intel.com>
Cc: "avi@redhat.com" <avi@redhat.com>
LKML-Reference: <20090720122417.GR5638@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
arch/x86/include/asm/apic.h
arch/x86/kernel/apic/apic.c
arch/x86/kernel/apic/probe_64.c

index bb7d47925847c585ee7e9e66f6f2e8652b5ab753..586b7adb8e53b33799b5c21926cfa0a8810a9987 100644 (file)
@@ -183,6 +183,10 @@ static inline int x2apic_enabled(void)
 }
 
 #define x2apic_supported()     (cpu_has_x2apic)
+static inline void x2apic_force_phys(void)
+{
+       x2apic_phys = 1;
+}
 #else
 static inline void check_x2apic(void)
 {
@@ -194,6 +198,9 @@ static inline int x2apic_enabled(void)
 {
        return 0;
 }
+static inline void x2apic_force_phys(void)
+{
+}
 
 #define        x2apic_preenabled 0
 #define        x2apic_supported()      0
index 0b021c56e822cbe4d0413770ef5d6662c4e8294f..de039fcdd0530f6c00bb0a7947b5ca3a8f450105 100644 (file)
@@ -49,6 +49,7 @@
 #include <asm/mtrr.h>
 #include <asm/smp.h>
 #include <asm/mce.h>
+#include <asm/kvm_para.h>
 
 unsigned int num_processors;
 
@@ -1361,52 +1362,76 @@ void enable_x2apic(void)
 }
 #endif /* CONFIG_X86_X2APIC */
 
-void __init enable_IR_x2apic(void)
+int __init enable_IR(void)
 {
 #ifdef CONFIG_INTR_REMAP
        int ret;
-       unsigned long flags;
-       struct IO_APIC_route_entry **ioapic_entries = NULL;
 
        ret = dmar_table_init();
        if (ret) {
                pr_debug("dmar_table_init() failed with %d:\n", ret);
-               goto ir_failed;
+               return 0;
        }
 
        if (!intr_remapping_supported()) {
                pr_debug("intr-remapping not supported\n");
-               goto ir_failed;
+               return 0;
        }
 
-
        if (!x2apic_preenabled && skip_ioapic_setup) {
                pr_info("Skipped enabling intr-remap because of skipping "
                        "io-apic setup\n");
-               return;
+               return 0;
        }
 
+       if (enable_intr_remapping(x2apic_supported()))
+               return 0;
+
+       pr_info("Enabled Interrupt-remapping\n");
+
+       return 1;
+
+#endif
+       return 0;
+}
+
+void __init enable_IR_x2apic(void)
+{
+       unsigned long flags;
+       struct IO_APIC_route_entry **ioapic_entries = NULL;
+       int ret, x2apic_enabled = 0;
+
        ioapic_entries = alloc_ioapic_entries();
        if (!ioapic_entries) {
-               pr_info("Allocate ioapic_entries failed: %d\n", ret);
-               goto end;
+               pr_err("Allocate ioapic_entries failed\n");
+               goto out;
        }
 
        ret = save_IO_APIC_setup(ioapic_entries);
        if (ret) {
                pr_info("Saving IO-APIC state failed: %d\n", ret);
-               goto end;
+               goto out;
        }
 
        local_irq_save(flags);
-       mask_IO_APIC_setup(ioapic_entries);
        mask_8259A();
+       mask_IO_APIC_setup(ioapic_entries);
 
-       ret = enable_intr_remapping(x2apic_supported());
-       if (ret)
-               goto end_restore;
+       ret = enable_IR();
+       if (!ret) {
+               /* IR is required if there is APIC ID > 255 even when running
+                * under KVM
+                */
+               if (max_physical_apicid > 255 || !kvm_para_available())
+                       goto nox2apic;
+               /*
+                * without IR all CPUs can be addressed by IOAPIC/MSI
+                * only in physical mode
+                */
+               x2apic_force_phys();
+       }
 
-       pr_info("Enabled Interrupt-remapping\n");
+       x2apic_enabled = 1;
 
        if (x2apic_supported() && !x2apic_mode) {
                x2apic_mode = 1;
@@ -1414,41 +1439,25 @@ void __init enable_IR_x2apic(void)
                pr_info("Enabled x2apic\n");
        }
 
-end_restore:
-       if (ret)
-               /*
-                * IR enabling failed
-                */
+nox2apic:
+       if (!ret) /* IR enabling failed */
                restore_IO_APIC_setup(ioapic_entries);
-
        unmask_8259A();
        local_irq_restore(flags);
 
-end:
+out:
        if (ioapic_entries)
                free_ioapic_entries(ioapic_entries);
 
-       if (!ret)
+       if (x2apic_enabled)
                return;
 
-ir_failed:
        if (x2apic_preenabled)
-               panic("x2apic enabled by bios. But IR enabling failed");
+               panic("x2apic: enabled by BIOS but kernel init failed.");
        else if (cpu_has_x2apic)
-               pr_info("Not enabling x2apic,Intr-remapping\n");
-#else
-       if (!cpu_has_x2apic)
-               return;
-
-       if (x2apic_preenabled)
-               panic("x2apic enabled prior OS handover,"
-                     " enable CONFIG_X86_X2APIC, CONFIG_INTR_REMAP");
-#endif
-
-       return;
+               pr_info("Not enabling x2apic, Intr-remapping init failed.\n");
 }
 
-
 #ifdef CONFIG_X86_64
 /*
  * Detect and enable local APICs on non-SMP boards.
index bc3e880f9b82e76902b305d10920b70b05c440ac..f3b1037076e48c180caaf893d08b6990fb35dfd1 100644 (file)
@@ -50,11 +50,11 @@ static struct apic *apic_probe[] __initdata = {
 void __init default_setup_apic_routing(void)
 {
 #ifdef CONFIG_X86_X2APIC
-       if (x2apic_mode && (apic != &apic_x2apic_phys &&
+       if (x2apic_mode
 #ifdef CONFIG_X86_UV
-                      apic != &apic_x2apic_uv_x &&
+                      && apic != &apic_x2apic_uv_x
 #endif
-                      apic != &apic_x2apic_cluster)) {
+                      ) {
                if (x2apic_phys)
                        apic = &apic_x2apic_phys;
                else