]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
xen: Add suspend/resume support for PV on HVM guests.
authorStefano Stabellini <stefano.stabellini@eu.citrix.com>
Fri, 14 May 2010 11:45:07 +0000 (12:45 +0100)
committerJeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
Thu, 22 Jul 2010 23:46:21 +0000 (16:46 -0700)
Suspend/resume requires few different things on HVM: the suspend
hypercall is different; we don't need to save/restore memory related
settings; except the shared info page and the callback mechanism.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
arch/x86/xen/enlighten.c
arch/x86/xen/suspend.c
arch/x86/xen/xen-ops.h
drivers/xen/manage.c
drivers/xen/platform-pci.c
include/xen/xen-ops.h

index b211a04c4b2ccbb6f1ad2c4b2388592532dff2f0..127c95c8d15e9f7e5f777e53022303ddf49d893e 100644 (file)
@@ -1262,13 +1262,15 @@ static int init_hvm_pv_info(int *major, int *minor)
        return 0;
 }
 
-static void __init init_shared_info(void)
+void xen_hvm_init_shared_info(void)
 {
+       int cpu;
        struct xen_add_to_physmap xatp;
-       struct shared_info *shared_info_page;
+       static struct shared_info *shared_info_page = 0;
 
-       shared_info_page = (struct shared_info *)
-               extend_brk(PAGE_SIZE, PAGE_SIZE);
+       if (!shared_info_page)
+               shared_info_page = (struct shared_info *)
+                       extend_brk(PAGE_SIZE, PAGE_SIZE);
        xatp.domid = DOMID_SELF;
        xatp.idx = 0;
        xatp.space = XENMAPSPACE_shared_info;
@@ -1278,7 +1280,17 @@ static void __init init_shared_info(void)
 
        HYPERVISOR_shared_info = (struct shared_info *)shared_info_page;
 
-       per_cpu(xen_vcpu, 0) = &HYPERVISOR_shared_info->vcpu_info[0];
+       /* xen_vcpu is a pointer to the vcpu_info struct in the shared_info
+        * page, we use it in the event channel upcall and in some pvclock
+        * related functions. We don't need the vcpu_info placement
+        * optimizations because we don't use any pv_mmu or pv_irq op on
+        * HVM.
+        * When xen_hvm_init_shared_info is run at boot time only vcpu 0 is
+        * online but xen_hvm_init_shared_info is run at resume time too and
+        * in that case multiple vcpus might be online. */
+       for_each_online_cpu(cpu) {
+               per_cpu(xen_vcpu, cpu) = &HYPERVISOR_shared_info->vcpu_info[cpu];
+       }
 }
 
 static int __cpuinit xen_hvm_cpu_notify(struct notifier_block *self,
@@ -1308,7 +1320,7 @@ static void __init xen_hvm_guest_init(void)
        if (r < 0)
                return;
 
-       init_shared_info();
+       xen_hvm_init_shared_info();
 
        if (xen_feature(XENFEAT_hvm_callback_vector))
                xen_have_vector_callback = 1;
index a9c6611080347bd4368beff2ab582d07347fa256..d07479c340f551e1ea118e5a16a16dd10a5eb413 100644 (file)
@@ -26,6 +26,12 @@ void xen_pre_suspend(void)
                BUG();
 }
 
+void xen_hvm_post_suspend(int suspend_cancelled)
+{
+       xen_hvm_init_shared_info();
+       xen_callback_vector();
+}
+
 void xen_post_suspend(int suspend_cancelled)
 {
        xen_build_mfn_list_list();
index 0d0e0e6a747991f9904d78dc3b3fb91ec26992b1..01c9dd386522112e91c7041751e8fb0b312779b1 100644 (file)
@@ -39,6 +39,7 @@ void xen_enable_syscall(void);
 void xen_vcpu_restore(void);
 
 void xen_callback_vector(void);
+void xen_hvm_init_shared_info(void);
 
 void __init xen_build_dynamic_phys_to_machine(void);
 
index af9c5594d31557bdbb28a019466efa6e78ae0705..1799bd8903151db422bd28cf1173564f0d6872d4 100644 (file)
@@ -9,6 +9,7 @@
 #include <linux/stop_machine.h>
 #include <linux/freezer.h>
 
+#include <xen/xen.h>
 #include <xen/xenbus.h>
 #include <xen/grant_table.h>
 #include <xen/events.h>
@@ -17,6 +18,7 @@
 
 #include <asm/xen/hypercall.h>
 #include <asm/xen/page.h>
+#include <asm/xen/hypervisor.h>
 
 enum shutdown_state {
        SHUTDOWN_INVALID = -1,
@@ -33,10 +35,30 @@ enum shutdown_state {
 static enum shutdown_state shutting_down = SHUTDOWN_INVALID;
 
 #ifdef CONFIG_PM_SLEEP
-static int xen_suspend(void *data)
+static int xen_hvm_suspend(void *data)
 {
+       struct sched_shutdown r = { .reason = SHUTDOWN_suspend };
        int *cancelled = data;
+
+       BUG_ON(!irqs_disabled());
+
+       *cancelled = HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
+
+       xen_hvm_post_suspend(*cancelled);
+       gnttab_resume();
+
+       if (!*cancelled) {
+               xen_irq_resume();
+               xen_timer_resume();
+       }
+
+       return 0;
+}
+
+static int xen_suspend(void *data)
+{
        int err;
+       int *cancelled = data;
 
        BUG_ON(!irqs_disabled());
 
@@ -106,7 +128,10 @@ static void do_suspend(void)
                goto out_resume;
        }
 
-       err = stop_machine(xen_suspend, &cancelled, cpumask_of(0));
+       if (xen_hvm_domain())
+               err = stop_machine(xen_hvm_suspend, &cancelled, cpumask_of(0));
+       else
+               err = stop_machine(xen_suspend, &cancelled, cpumask_of(0));
 
        dpm_resume_noirq(PMSG_RESUME);
 
@@ -255,7 +280,19 @@ static int shutdown_event(struct notifier_block *notifier,
        return NOTIFY_DONE;
 }
 
-static int __init setup_shutdown_event(void)
+static int __init __setup_shutdown_event(void)
+{
+       /* Delay initialization in the PV on HVM case */
+       if (xen_hvm_domain())
+               return 0;
+
+       if (!xen_pv_domain())
+               return -ENODEV;
+
+       return xen_setup_shutdown_event();
+}
+
+int xen_setup_shutdown_event(void)
 {
        static struct notifier_block xenstore_notifier = {
                .notifier_call = shutdown_event
@@ -266,4 +303,4 @@ static int __init setup_shutdown_event(void)
 }
 EXPORT_SYMBOL_GPL(xen_setup_shutdown_event);
 
-subsys_initcall(setup_shutdown_event);
+subsys_initcall(__setup_shutdown_event);
index a0ee5d06f7153d2feda09b67fb3bb1da7ed8c48b..bdb44f2473e872006d19e2edeedd2b895a5d376f 100644 (file)
@@ -31,6 +31,7 @@
 #include <xen/xenbus.h>
 #include <xen/events.h>
 #include <xen/hvm.h>
+#include <xen/xen-ops.h>
 
 #define DRV_NAME    "xen-platform-pci"
 
@@ -41,6 +42,7 @@ MODULE_LICENSE("GPL");
 static unsigned long platform_mmio;
 static unsigned long platform_mmio_alloc;
 static unsigned long platform_mmiolen;
+static uint64_t callback_via;
 
 unsigned long alloc_xen_mmio(unsigned long len)
 {
@@ -85,13 +87,25 @@ static int xen_allocate_irq(struct pci_dev *pdev)
                        "xen-platform-pci", pdev);
 }
 
+static int platform_pci_resume(struct pci_dev *pdev)
+{
+       int err;
+       if (xen_have_vector_callback)
+               return 0;
+       err = xen_set_callback_via(callback_via);
+       if (err) {
+               dev_err(&pdev->dev, "platform_pci_resume failure!\n");
+               return err;
+       }
+       return 0;
+}
+
 static int __devinit platform_pci_init(struct pci_dev *pdev,
                                       const struct pci_device_id *ent)
 {
        int i, ret;
        long ioaddr, iolen;
        long mmio_addr, mmio_len;
-       uint64_t callback_via;
        unsigned int max_nr_gframes;
 
        i = pci_enable_device(pdev);
@@ -148,6 +162,9 @@ static int __devinit platform_pci_init(struct pci_dev *pdev,
        if (ret)
                goto out;
        xenbus_probe(NULL);
+       ret = xen_setup_shutdown_event();
+       if (ret)
+               goto out;
        return 0;
 
 out:
@@ -171,6 +188,9 @@ static struct pci_driver platform_driver = {
        .name =           DRV_NAME,
        .probe =          platform_pci_init,
        .id_table =       platform_pci_tbl,
+#ifdef CONFIG_PM
+       .resume_early =   platform_pci_resume,
+#endif
 };
 
 static int __init platform_pci_module_init(void)
index 883a21bba24bac3991e79533f586679de6926a4a..46bc81ef74c67468a667e6f5d06026be1cc43f4c 100644 (file)
@@ -7,6 +7,7 @@ DECLARE_PER_CPU(struct vcpu_info *, xen_vcpu);
 
 void xen_pre_suspend(void);
 void xen_post_suspend(int suspend_cancelled);
+void xen_hvm_post_suspend(int suspend_cancelled);
 
 void xen_mm_pin_all(void);
 void xen_mm_unpin_all(void);
@@ -14,4 +15,6 @@ void xen_mm_unpin_all(void);
 void xen_timer_resume(void);
 void xen_arch_resume(void);
 
+int xen_setup_shutdown_event(void);
+
 #endif /* INCLUDE_XEN_OPS_H */