diff options
| author | Stefano Stabellini <stefano.stabellini@eu.citrix.com> | 2010-05-14 07:45:07 -0400 |
|---|---|---|
| committer | Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com> | 2010-07-22 19:46:21 -0400 |
| commit | 016b6f5fe8398b0291cece60b749d7c930a2e09c (patch) | |
| tree | 430e9aad74f223dc5d144b60f4b78a0c3fb9cdfd | |
| parent | 183d03cc4ff39e0f0d952c09aa96d0abfd6e0c3c (diff) | |
xen: Add suspend/resume support for PV on HVM guests.
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>
| -rw-r--r-- | arch/x86/xen/enlighten.c | 24 | ||||
| -rw-r--r-- | arch/x86/xen/suspend.c | 6 | ||||
| -rw-r--r-- | arch/x86/xen/xen-ops.h | 1 | ||||
| -rw-r--r-- | drivers/xen/manage.c | 45 | ||||
| -rw-r--r-- | drivers/xen/platform-pci.c | 22 | ||||
| -rw-r--r-- | include/xen/xen-ops.h | 3 |
6 files changed, 90 insertions, 11 deletions
diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c index b211a04c4b2c..127c95c8d15e 100644 --- a/arch/x86/xen/enlighten.c +++ b/arch/x86/xen/enlighten.c | |||
| @@ -1262,13 +1262,15 @@ static int init_hvm_pv_info(int *major, int *minor) | |||
| 1262 | return 0; | 1262 | return 0; |
| 1263 | } | 1263 | } |
| 1264 | 1264 | ||
| 1265 | static void __init init_shared_info(void) | 1265 | void xen_hvm_init_shared_info(void) |
| 1266 | { | 1266 | { |
| 1267 | int cpu; | ||
| 1267 | struct xen_add_to_physmap xatp; | 1268 | struct xen_add_to_physmap xatp; |
| 1268 | struct shared_info *shared_info_page; | 1269 | static struct shared_info *shared_info_page = 0; |
| 1269 | 1270 | ||
| 1270 | shared_info_page = (struct shared_info *) | 1271 | if (!shared_info_page) |
| 1271 | extend_brk(PAGE_SIZE, PAGE_SIZE); | 1272 | shared_info_page = (struct shared_info *) |
| 1273 | extend_brk(PAGE_SIZE, PAGE_SIZE); | ||
| 1272 | xatp.domid = DOMID_SELF; | 1274 | xatp.domid = DOMID_SELF; |
| 1273 | xatp.idx = 0; | 1275 | xatp.idx = 0; |
| 1274 | xatp.space = XENMAPSPACE_shared_info; | 1276 | xatp.space = XENMAPSPACE_shared_info; |
| @@ -1278,7 +1280,17 @@ static void __init init_shared_info(void) | |||
| 1278 | 1280 | ||
| 1279 | HYPERVISOR_shared_info = (struct shared_info *)shared_info_page; | 1281 | HYPERVISOR_shared_info = (struct shared_info *)shared_info_page; |
| 1280 | 1282 | ||
| 1281 | per_cpu(xen_vcpu, 0) = &HYPERVISOR_shared_info->vcpu_info[0]; | 1283 | /* xen_vcpu is a pointer to the vcpu_info struct in the shared_info |
| 1284 | * page, we use it in the event channel upcall and in some pvclock | ||
| 1285 | * related functions. We don't need the vcpu_info placement | ||
| 1286 | * optimizations because we don't use any pv_mmu or pv_irq op on | ||
| 1287 | * HVM. | ||
| 1288 | * When xen_hvm_init_shared_info is run at boot time only vcpu 0 is | ||
| 1289 | * online but xen_hvm_init_shared_info is run at resume time too and | ||
| 1290 | * in that case multiple vcpus might be online. */ | ||
| 1291 | for_each_online_cpu(cpu) { | ||
| 1292 | per_cpu(xen_vcpu, cpu) = &HYPERVISOR_shared_info->vcpu_info[cpu]; | ||
| 1293 | } | ||
| 1282 | } | 1294 | } |
| 1283 | 1295 | ||
| 1284 | static int __cpuinit xen_hvm_cpu_notify(struct notifier_block *self, | 1296 | static int __cpuinit xen_hvm_cpu_notify(struct notifier_block *self, |
| @@ -1308,7 +1320,7 @@ static void __init xen_hvm_guest_init(void) | |||
| 1308 | if (r < 0) | 1320 | if (r < 0) |
| 1309 | return; | 1321 | return; |
| 1310 | 1322 | ||
| 1311 | init_shared_info(); | 1323 | xen_hvm_init_shared_info(); |
| 1312 | 1324 | ||
| 1313 | if (xen_feature(XENFEAT_hvm_callback_vector)) | 1325 | if (xen_feature(XENFEAT_hvm_callback_vector)) |
| 1314 | xen_have_vector_callback = 1; | 1326 | xen_have_vector_callback = 1; |
diff --git a/arch/x86/xen/suspend.c b/arch/x86/xen/suspend.c index a9c661108034..d07479c340f5 100644 --- a/arch/x86/xen/suspend.c +++ b/arch/x86/xen/suspend.c | |||
| @@ -26,6 +26,12 @@ void xen_pre_suspend(void) | |||
| 26 | BUG(); | 26 | BUG(); |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | void xen_hvm_post_suspend(int suspend_cancelled) | ||
| 30 | { | ||
| 31 | xen_hvm_init_shared_info(); | ||
| 32 | xen_callback_vector(); | ||
| 33 | } | ||
| 34 | |||
| 29 | void xen_post_suspend(int suspend_cancelled) | 35 | void xen_post_suspend(int suspend_cancelled) |
| 30 | { | 36 | { |
| 31 | xen_build_mfn_list_list(); | 37 | xen_build_mfn_list_list(); |
diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h index 0d0e0e6a7479..01c9dd386522 100644 --- a/arch/x86/xen/xen-ops.h +++ b/arch/x86/xen/xen-ops.h | |||
| @@ -39,6 +39,7 @@ void xen_enable_syscall(void); | |||
| 39 | void xen_vcpu_restore(void); | 39 | void xen_vcpu_restore(void); |
| 40 | 40 | ||
| 41 | void xen_callback_vector(void); | 41 | void xen_callback_vector(void); |
| 42 | void xen_hvm_init_shared_info(void); | ||
| 42 | 43 | ||
| 43 | void __init xen_build_dynamic_phys_to_machine(void); | 44 | void __init xen_build_dynamic_phys_to_machine(void); |
| 44 | 45 | ||
diff --git a/drivers/xen/manage.c b/drivers/xen/manage.c index af9c5594d315..1799bd890315 100644 --- a/drivers/xen/manage.c +++ b/drivers/xen/manage.c | |||
| @@ -9,6 +9,7 @@ | |||
| 9 | #include <linux/stop_machine.h> | 9 | #include <linux/stop_machine.h> |
| 10 | #include <linux/freezer.h> | 10 | #include <linux/freezer.h> |
| 11 | 11 | ||
| 12 | #include <xen/xen.h> | ||
| 12 | #include <xen/xenbus.h> | 13 | #include <xen/xenbus.h> |
| 13 | #include <xen/grant_table.h> | 14 | #include <xen/grant_table.h> |
| 14 | #include <xen/events.h> | 15 | #include <xen/events.h> |
| @@ -17,6 +18,7 @@ | |||
| 17 | 18 | ||
| 18 | #include <asm/xen/hypercall.h> | 19 | #include <asm/xen/hypercall.h> |
| 19 | #include <asm/xen/page.h> | 20 | #include <asm/xen/page.h> |
| 21 | #include <asm/xen/hypervisor.h> | ||
| 20 | 22 | ||
| 21 | enum shutdown_state { | 23 | enum shutdown_state { |
| 22 | SHUTDOWN_INVALID = -1, | 24 | SHUTDOWN_INVALID = -1, |
| @@ -33,10 +35,30 @@ enum shutdown_state { | |||
| 33 | static enum shutdown_state shutting_down = SHUTDOWN_INVALID; | 35 | static enum shutdown_state shutting_down = SHUTDOWN_INVALID; |
| 34 | 36 | ||
| 35 | #ifdef CONFIG_PM_SLEEP | 37 | #ifdef CONFIG_PM_SLEEP |
| 36 | static int xen_suspend(void *data) | 38 | static int xen_hvm_suspend(void *data) |
| 37 | { | 39 | { |
| 40 | struct sched_shutdown r = { .reason = SHUTDOWN_suspend }; | ||
| 38 | int *cancelled = data; | 41 | int *cancelled = data; |
| 42 | |||
| 43 | BUG_ON(!irqs_disabled()); | ||
| 44 | |||
| 45 | *cancelled = HYPERVISOR_sched_op(SCHEDOP_shutdown, &r); | ||
| 46 | |||
| 47 | xen_hvm_post_suspend(*cancelled); | ||
| 48 | gnttab_resume(); | ||
| 49 | |||
| 50 | if (!*cancelled) { | ||
| 51 | xen_irq_resume(); | ||
| 52 | xen_timer_resume(); | ||
| 53 | } | ||
| 54 | |||
| 55 | return 0; | ||
| 56 | } | ||
| 57 | |||
| 58 | static int xen_suspend(void *data) | ||
| 59 | { | ||
| 39 | int err; | 60 | int err; |
| 61 | int *cancelled = data; | ||
| 40 | 62 | ||
| 41 | BUG_ON(!irqs_disabled()); | 63 | BUG_ON(!irqs_disabled()); |
| 42 | 64 | ||
| @@ -106,7 +128,10 @@ static void do_suspend(void) | |||
| 106 | goto out_resume; | 128 | goto out_resume; |
| 107 | } | 129 | } |
| 108 | 130 | ||
| 109 | err = stop_machine(xen_suspend, &cancelled, cpumask_of(0)); | 131 | if (xen_hvm_domain()) |
| 132 | err = stop_machine(xen_hvm_suspend, &cancelled, cpumask_of(0)); | ||
| 133 | else | ||
| 134 | err = stop_machine(xen_suspend, &cancelled, cpumask_of(0)); | ||
| 110 | 135 | ||
| 111 | dpm_resume_noirq(PMSG_RESUME); | 136 | dpm_resume_noirq(PMSG_RESUME); |
| 112 | 137 | ||
| @@ -255,7 +280,19 @@ static int shutdown_event(struct notifier_block *notifier, | |||
| 255 | return NOTIFY_DONE; | 280 | return NOTIFY_DONE; |
| 256 | } | 281 | } |
| 257 | 282 | ||
| 258 | static int __init setup_shutdown_event(void) | 283 | static int __init __setup_shutdown_event(void) |
| 284 | { | ||
| 285 | /* Delay initialization in the PV on HVM case */ | ||
| 286 | if (xen_hvm_domain()) | ||
| 287 | return 0; | ||
| 288 | |||
| 289 | if (!xen_pv_domain()) | ||
| 290 | return -ENODEV; | ||
| 291 | |||
| 292 | return xen_setup_shutdown_event(); | ||
| 293 | } | ||
| 294 | |||
| 295 | int xen_setup_shutdown_event(void) | ||
| 259 | { | 296 | { |
| 260 | static struct notifier_block xenstore_notifier = { | 297 | static struct notifier_block xenstore_notifier = { |
| 261 | .notifier_call = shutdown_event | 298 | .notifier_call = shutdown_event |
| @@ -266,4 +303,4 @@ static int __init setup_shutdown_event(void) | |||
| 266 | } | 303 | } |
| 267 | EXPORT_SYMBOL_GPL(xen_setup_shutdown_event); | 304 | EXPORT_SYMBOL_GPL(xen_setup_shutdown_event); |
| 268 | 305 | ||
| 269 | subsys_initcall(setup_shutdown_event); | 306 | subsys_initcall(__setup_shutdown_event); |
diff --git a/drivers/xen/platform-pci.c b/drivers/xen/platform-pci.c index a0ee5d06f715..bdb44f2473e8 100644 --- a/drivers/xen/platform-pci.c +++ b/drivers/xen/platform-pci.c | |||
| @@ -31,6 +31,7 @@ | |||
| 31 | #include <xen/xenbus.h> | 31 | #include <xen/xenbus.h> |
| 32 | #include <xen/events.h> | 32 | #include <xen/events.h> |
| 33 | #include <xen/hvm.h> | 33 | #include <xen/hvm.h> |
| 34 | #include <xen/xen-ops.h> | ||
| 34 | 35 | ||
| 35 | #define DRV_NAME "xen-platform-pci" | 36 | #define DRV_NAME "xen-platform-pci" |
| 36 | 37 | ||
| @@ -41,6 +42,7 @@ MODULE_LICENSE("GPL"); | |||
| 41 | static unsigned long platform_mmio; | 42 | static unsigned long platform_mmio; |
| 42 | static unsigned long platform_mmio_alloc; | 43 | static unsigned long platform_mmio_alloc; |
| 43 | static unsigned long platform_mmiolen; | 44 | static unsigned long platform_mmiolen; |
| 45 | static uint64_t callback_via; | ||
| 44 | 46 | ||
| 45 | unsigned long alloc_xen_mmio(unsigned long len) | 47 | unsigned long alloc_xen_mmio(unsigned long len) |
| 46 | { | 48 | { |
| @@ -85,13 +87,25 @@ static int xen_allocate_irq(struct pci_dev *pdev) | |||
| 85 | "xen-platform-pci", pdev); | 87 | "xen-platform-pci", pdev); |
| 86 | } | 88 | } |
| 87 | 89 | ||
| 90 | static int platform_pci_resume(struct pci_dev *pdev) | ||
| 91 | { | ||
| 92 | int err; | ||
| 93 | if (xen_have_vector_callback) | ||
| 94 | return 0; | ||
| 95 | err = xen_set_callback_via(callback_via); | ||
| 96 | if (err) { | ||
| 97 | dev_err(&pdev->dev, "platform_pci_resume failure!\n"); | ||
| 98 | return err; | ||
| 99 | } | ||
| 100 | return 0; | ||
| 101 | } | ||
| 102 | |||
| 88 | static int __devinit platform_pci_init(struct pci_dev *pdev, | 103 | static int __devinit platform_pci_init(struct pci_dev *pdev, |
| 89 | const struct pci_device_id *ent) | 104 | const struct pci_device_id *ent) |
| 90 | { | 105 | { |
| 91 | int i, ret; | 106 | int i, ret; |
| 92 | long ioaddr, iolen; | 107 | long ioaddr, iolen; |
| 93 | long mmio_addr, mmio_len; | 108 | long mmio_addr, mmio_len; |
| 94 | uint64_t callback_via; | ||
| 95 | unsigned int max_nr_gframes; | 109 | unsigned int max_nr_gframes; |
| 96 | 110 | ||
| 97 | i = pci_enable_device(pdev); | 111 | i = pci_enable_device(pdev); |
| @@ -148,6 +162,9 @@ static int __devinit platform_pci_init(struct pci_dev *pdev, | |||
| 148 | if (ret) | 162 | if (ret) |
| 149 | goto out; | 163 | goto out; |
| 150 | xenbus_probe(NULL); | 164 | xenbus_probe(NULL); |
| 165 | ret = xen_setup_shutdown_event(); | ||
| 166 | if (ret) | ||
| 167 | goto out; | ||
| 151 | return 0; | 168 | return 0; |
| 152 | 169 | ||
| 153 | out: | 170 | out: |
| @@ -171,6 +188,9 @@ static struct pci_driver platform_driver = { | |||
| 171 | .name = DRV_NAME, | 188 | .name = DRV_NAME, |
| 172 | .probe = platform_pci_init, | 189 | .probe = platform_pci_init, |
| 173 | .id_table = platform_pci_tbl, | 190 | .id_table = platform_pci_tbl, |
| 191 | #ifdef CONFIG_PM | ||
| 192 | .resume_early = platform_pci_resume, | ||
| 193 | #endif | ||
| 174 | }; | 194 | }; |
| 175 | 195 | ||
| 176 | static int __init platform_pci_module_init(void) | 196 | static int __init platform_pci_module_init(void) |
diff --git a/include/xen/xen-ops.h b/include/xen/xen-ops.h index 883a21bba24b..46bc81ef74c6 100644 --- a/include/xen/xen-ops.h +++ b/include/xen/xen-ops.h | |||
| @@ -7,6 +7,7 @@ DECLARE_PER_CPU(struct vcpu_info *, xen_vcpu); | |||
| 7 | 7 | ||
| 8 | void xen_pre_suspend(void); | 8 | void xen_pre_suspend(void); |
| 9 | void xen_post_suspend(int suspend_cancelled); | 9 | void xen_post_suspend(int suspend_cancelled); |
| 10 | void xen_hvm_post_suspend(int suspend_cancelled); | ||
| 10 | 11 | ||
| 11 | void xen_mm_pin_all(void); | 12 | void xen_mm_pin_all(void); |
| 12 | void xen_mm_unpin_all(void); | 13 | void xen_mm_unpin_all(void); |
| @@ -14,4 +15,6 @@ void xen_mm_unpin_all(void); | |||
| 14 | void xen_timer_resume(void); | 15 | void xen_timer_resume(void); |
| 15 | void xen_arch_resume(void); | 16 | void xen_arch_resume(void); |
| 16 | 17 | ||
| 18 | int xen_setup_shutdown_event(void); | ||
| 19 | |||
| 17 | #endif /* INCLUDE_XEN_OPS_H */ | 20 | #endif /* INCLUDE_XEN_OPS_H */ |
