kexec: Clean up shutdown logic. Reinstate ACPI DMAR during kexec.
authorKeir Fraser <keir.fraser@citrix.com>
Thu, 29 Jul 2010 09:31:21 +0000 (10:31 +0100)
committerKeir Fraser <keir.fraser@citrix.com>
Thu, 29 Jul 2010 09:31:21 +0000 (10:31 +0100)
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
xen/arch/x86/crash.c
xen/arch/x86/machine_kexec.c
xen/arch/x86/smp.c
xen/arch/x86/tboot.c
xen/common/kexec.c
xen/drivers/acpi/tables.c
xen/drivers/passthrough/vtd/dmar.c
xen/include/asm-x86/smp.h

index a95154771e0f10d3b5e910c9edb798a9d0ab640d..1564a01b12934bf609cfea5bd08862b53fb0e5cb 100644 (file)
@@ -25,7 +25,6 @@
 #include <public/xen.h>
 #include <asm/shared.h>
 #include <asm/hvm/support.h>
-#include <asm/hpet.h>
 #include <asm/apic.h>
 #include <asm/io_apic.h>
 
@@ -43,9 +42,10 @@ static int crash_nmi_callback(struct cpu_user_regs *regs, int cpu)
     local_irq_disable();
 
     kexec_crash_save_cpu();
-    disable_local_APIC();
+
+    __stop_this_cpu();
+
     atomic_dec(&waiting_for_crash_ipi);
-    hvm_cpu_down();
 
     for ( ; ; )
         halt();
@@ -57,7 +57,10 @@ static void nmi_shootdown_cpus(void)
 {
     unsigned long msecs;
 
+    local_irq_disable();
+
     crashing_cpu = smp_processor_id();
+    local_irq_count(crashing_cpu) = 0;
 
     atomic_set(&waiting_for_crash_ipi, num_online_cpus() - 1);
     /* Would it be better to replace the trap vector here? */
@@ -74,25 +77,18 @@ static void nmi_shootdown_cpus(void)
         msecs--;
     }
 
-    /* Leave the nmi callback set */
-    disable_local_APIC();
+    __stop_this_cpu();
+    disable_IO_APIC();
+
+    local_irq_enable();
 }
 
 void machine_crash_shutdown(void)
 {
     crash_xen_info_t *info;
 
-    local_irq_disable();
-
     nmi_shootdown_cpus();
 
-    if ( hpet_broadcast_is_available() )
-        hpet_disable_legacy_broadcast();
-
-    disable_IO_APIC();
-
-    hvm_cpu_down();
-
     info = kexec_crash_save_info();
     info->xen_phys_start = xen_phys_start;
     info->dom0_pfn_to_mfn_frame_list_list =
index f44aba2b5b6d8d7707db55c0faa197b8716307ef..d3f146854fab113207473573a850e79708871d16 100644 (file)
@@ -18,6 +18,7 @@
 #include <xen/domain_page.h>
 #include <asm/fixmap.h>
 #include <asm/hvm/hvm.h>
+#include <asm/hpet.h>
 
 typedef void (*relocate_new_kernel_t)(
                 unsigned long indirection_page,
@@ -76,38 +77,11 @@ void machine_kexec_unload(int type, int slot, xen_kexec_image_t *image)
 {
 }
 
-static void __machine_reboot_kexec(void *data)
+void machine_reboot_kexec(xen_kexec_image_t *image)
 {
-    xen_kexec_image_t *image = (xen_kexec_image_t *)data;
-
-    watchdog_disable();
-    console_start_sync();
-
+    BUG_ON(smp_processor_id() != 0);
     smp_send_stop();
-
     machine_kexec(image);
-}
-
-void machine_reboot_kexec(xen_kexec_image_t *image)
-{
-    int reboot_cpu_id;
-
-    reboot_cpu_id = 0;
-
-    if ( !cpu_isset(reboot_cpu_id, cpu_online_map) )
-        reboot_cpu_id = smp_processor_id();
-
-    if ( reboot_cpu_id != smp_processor_id() )
-    {
-        on_selected_cpus(cpumask_of(reboot_cpu_id), __machine_reboot_kexec,
-                         image, 0);
-        for (;;)
-                ; /* nothing */
-    }
-    else
-    {
-        __machine_reboot_kexec(image);
-    }
     BUG();
 }
 
@@ -118,6 +92,9 @@ void machine_kexec(xen_kexec_image_t *image)
         .limit = LAST_RESERVED_GDT_BYTE
     };
 
+    if ( hpet_broadcast_is_available() )
+        hpet_disable_legacy_broadcast();
+
     /*
      * compat_machine_kexec() returns to idle pagetables, which requires us
      * to be running on a static GDT mapping (idle pagetables have no GDT
index 1c231b00b165994213c36865f577ca0666e7fb2c..f97a9e491dbc56f2ae845f15bb3a26fe53c71950 100644 (file)
@@ -336,7 +336,7 @@ void on_selected_cpus(
     spin_unlock(&call_lock);
 }
 
-static void __stop_this_cpu(void)
+void __stop_this_cpu(void)
 {
     ASSERT(!local_irq_is_enabled());
 
index 91f97ce43810defa3607e174fa202877e0b9129e..7a9421e7c675e52c5adcfec788fd94cc85618156 100644 (file)
@@ -478,7 +478,10 @@ int __init tboot_parse_dmar_table(acpi_table_handler dmar_handler)
     dmar_table = NULL;
     acpi_get_table(ACPI_SIG_DMAR, 0, &dmar_table);
     if ( dmar_table != NULL )
-        ((struct acpi_table_dmar *)dmar_table)->header.signature[0] = '\0';
+    {
+        dmar_table->signature[0] = 'X';
+        dmar_table->checksum -= 'X'-'D';
+    }
 
     return rc;
 }
index 263faebcf556accc1940468cd49bcca404963870..f6ce3b16a24c3949b0576ca42caa8bc638e80edc 100644 (file)
@@ -6,7 +6,9 @@
  * - Magnus Damm <magnus@valinux.co.jp>
  */
 
+#include <xen/init.h>
 #include <xen/lib.h>
+#include <xen/acpi.h>
 #include <xen/ctype.h>
 #include <xen/errno.h>
 #include <xen/guest_access.h>
@@ -201,6 +203,22 @@ crash_xen_info_t *kexec_crash_save_info(void)
     return out;
 }
 
+static int acpi_dmar_reinstate(struct acpi_table_header *table)
+{
+    table->signature[0] = 'D';
+    table->checksum += 'X'-'D';
+    return 0;
+}
+
+static void kexec_common_shutdown(void)
+{
+    watchdog_disable();
+    console_start_sync();
+    spin_debug_disable();
+    one_cpu_only();
+    acpi_table_parse(ACPI_SIG_DMAR, acpi_dmar_reinstate);
+}
+
 void kexec_crash(void)
 {
     int pos;
@@ -209,17 +227,25 @@ void kexec_crash(void)
     if ( !test_bit(KEXEC_IMAGE_CRASH_BASE + pos, &kexec_flags) )
         return;
 
-    console_start_sync();
-
-    one_cpu_only();
+    kexec_common_shutdown();
     kexec_crash_save_cpu();
     machine_crash_shutdown();
-
     machine_kexec(&kexec_image[KEXEC_IMAGE_CRASH_BASE + pos]);
 
     BUG();
 }
 
+static long kexec_reboot(void *_image)
+{
+    xen_kexec_image_t *image = _image;
+
+    kexec_common_shutdown();
+    machine_reboot_kexec(image);
+
+    BUG();
+    return 0;
+}
+
 static void do_crashdump_trigger(unsigned char key)
 {
     printk("'%c' pressed -> triggering crashdump\n", key);
@@ -540,7 +566,7 @@ static int kexec_exec(XEN_GUEST_HANDLE(void) uarg)
 {
     xen_kexec_exec_t exec;
     xen_kexec_image_t *image;
-    int base, bit, pos;
+    int base, bit, pos, ret = -EINVAL;
 
     if ( unlikely(copy_from_guest(&exec, uarg, 1)) )
         return -EFAULT;
@@ -558,8 +584,7 @@ static int kexec_exec(XEN_GUEST_HANDLE(void) uarg)
     {
     case KEXEC_TYPE_DEFAULT:
         image = &kexec_image[base + pos];
-        one_cpu_only();
-        machine_reboot_kexec(image); /* Does not return */
+        ret = continue_hypercall_on_cpu(0, kexec_reboot, image);
         break;
     case KEXEC_TYPE_CRASH:
         kexec_crash(); /* Does not return */
index e4f402e7c1105be4d47c6c9295a9fab58985254d..60df53aab27de365499d7995d5ca6063859343b9 100644 (file)
@@ -41,7 +41,7 @@ mps_inti_flags_polarity[] = { "dfl", "high", "res", "low" };
 static const char *__initdata
 mps_inti_flags_trigger[] = { "dfl", "edge", "res", "level" };
 
-static struct acpi_table_desc initial_tables[ACPI_MAX_TABLES] __initdata;
+static struct acpi_table_desc initial_tables[ACPI_MAX_TABLES];
 
 static int acpi_apic_instance __initdata;
 
@@ -269,7 +269,7 @@ acpi_table_parse_madt(enum acpi_madt_type id,
  * Scan the ACPI System Descriptor Table (STD) for a table matching @id,
  * run @handler on it.  Return 0 if table found, return on if not.
  */
-int __init acpi_table_parse(char *id, acpi_table_handler handler)
+int acpi_table_parse(char *id, acpi_table_handler handler)
 {
        struct acpi_table_header *table = NULL;
 
index 55c911cfe06226955f8d3e9a264b80bcb23e7ecb..f4078ff44b2647420562ea74d4d5f82162305922 100644 (file)
@@ -738,7 +738,8 @@ static int __init acpi_parse_dmar(struct acpi_table_header *table)
 
 out:
     /* Zap ACPI DMAR signature to prevent dom0 using vt-d HW. */
-    dmar->header.signature[0] = '\0';
+    dmar->header.signature[0] = 'X';
+    dmar->header.checksum -= 'X'-'D';
     return ret;
 }
 
index 76413e70b954e9271a4c4de9d8d1df9527396e47..ba8fa8aeab446b923602003ebe730bd1ec1b6da8 100644 (file)
@@ -61,6 +61,8 @@ int cpu_add(uint32_t apic_id, uint32_t acpi_id, uint32_t pxm);
 int hard_smp_processor_id(void);
 int logical_smp_processor_id(void);
 
+void __stop_this_cpu(void);
+
 #endif /* !__ASSEMBLY__ */
 
 #else /* CONFIG_SMP */