Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Stefano Stabellini and committed by
Jeremy Fitzhardinge
016b6f5f 183d03cc

+90 -11
+18 -6
arch/x86/xen/enlighten.c
··· 1262 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 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 - extend_brk(PAGE_SIZE, PAGE_SIZE); 1271 + if (!shared_info_page) 1272 + shared_info_page = (struct shared_info *) 1273 + extend_brk(PAGE_SIZE, PAGE_SIZE); 1272 1274 xatp.domid = DOMID_SELF; 1273 1275 xatp.idx = 0; 1274 1276 xatp.space = XENMAPSPACE_shared_info; ··· 1280 1278 1281 1279 HYPERVISOR_shared_info = (struct shared_info *)shared_info_page; 1282 1280 1283 - per_cpu(xen_vcpu, 0) = &HYPERVISOR_shared_info->vcpu_info[0]; 1281 + /* xen_vcpu is a pointer to the vcpu_info struct in the shared_info 1282 + * page, we use it in the event channel upcall and in some pvclock 1283 + * related functions. We don't need the vcpu_info placement 1284 + * optimizations because we don't use any pv_mmu or pv_irq op on 1285 + * HVM. 1286 + * When xen_hvm_init_shared_info is run at boot time only vcpu 0 is 1287 + * online but xen_hvm_init_shared_info is run at resume time too and 1288 + * in that case multiple vcpus might be online. */ 1289 + for_each_online_cpu(cpu) { 1290 + per_cpu(xen_vcpu, cpu) = &HYPERVISOR_shared_info->vcpu_info[cpu]; 1291 + } 1284 1292 } 1285 1293 1286 1294 static int __cpuinit xen_hvm_cpu_notify(struct notifier_block *self, ··· 1320 1308 if (r < 0) 1321 1309 return; 1322 1310 1323 - init_shared_info(); 1311 + xen_hvm_init_shared_info(); 1324 1312 1325 1313 if (xen_feature(XENFEAT_hvm_callback_vector)) 1326 1314 xen_have_vector_callback = 1;
+6
arch/x86/xen/suspend.c
··· 26 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 35 void xen_post_suspend(int suspend_cancelled) 30 36 { 31 37 xen_build_mfn_list_list();
+1
arch/x86/xen/xen-ops.h
··· 39 39 void xen_vcpu_restore(void); 40 40 41 41 void xen_callback_vector(void); 42 + void xen_hvm_init_shared_info(void); 42 43 43 44 void __init xen_build_dynamic_phys_to_machine(void); 44 45
+41 -4
drivers/xen/manage.c
··· 9 9 #include <linux/stop_machine.h> 10 10 #include <linux/freezer.h> 11 11 12 + #include <xen/xen.h> 12 13 #include <xen/xenbus.h> 13 14 #include <xen/grant_table.h> 14 15 #include <xen/events.h> ··· 18 17 19 18 #include <asm/xen/hypercall.h> 20 19 #include <asm/xen/page.h> 20 + #include <asm/xen/hypervisor.h> 21 21 22 22 enum shutdown_state { 23 23 SHUTDOWN_INVALID = -1, ··· 35 33 static enum shutdown_state shutting_down = SHUTDOWN_INVALID; 36 34 37 35 #ifdef CONFIG_PM_SLEEP 36 + static int xen_hvm_suspend(void *data) 37 + { 38 + struct sched_shutdown r = { .reason = SHUTDOWN_suspend }; 39 + int *cancelled = data; 40 + 41 + BUG_ON(!irqs_disabled()); 42 + 43 + *cancelled = HYPERVISOR_sched_op(SCHEDOP_shutdown, &r); 44 + 45 + xen_hvm_post_suspend(*cancelled); 46 + gnttab_resume(); 47 + 48 + if (!*cancelled) { 49 + xen_irq_resume(); 50 + xen_timer_resume(); 51 + } 52 + 53 + return 0; 54 + } 55 + 38 56 static int xen_suspend(void *data) 39 57 { 40 - int *cancelled = data; 41 58 int err; 59 + int *cancelled = data; 42 60 43 61 BUG_ON(!irqs_disabled()); 44 62 ··· 128 106 goto out_resume; 129 107 } 130 108 131 - err = stop_machine(xen_suspend, &cancelled, cpumask_of(0)); 109 + if (xen_hvm_domain()) 110 + err = stop_machine(xen_hvm_suspend, &cancelled, cpumask_of(0)); 111 + else 112 + err = stop_machine(xen_suspend, &cancelled, cpumask_of(0)); 132 113 133 114 dpm_resume_noirq(PMSG_RESUME); 134 115 ··· 280 255 return NOTIFY_DONE; 281 256 } 282 257 283 - static int __init setup_shutdown_event(void) 258 + static int __init __setup_shutdown_event(void) 259 + { 260 + /* Delay initialization in the PV on HVM case */ 261 + if (xen_hvm_domain()) 262 + return 0; 263 + 264 + if (!xen_pv_domain()) 265 + return -ENODEV; 266 + 267 + return xen_setup_shutdown_event(); 268 + } 269 + 270 + int xen_setup_shutdown_event(void) 284 271 { 285 272 static struct notifier_block xenstore_notifier = { 286 273 .notifier_call = shutdown_event ··· 303 266 } 304 267 EXPORT_SYMBOL_GPL(xen_setup_shutdown_event); 305 268 306 - subsys_initcall(setup_shutdown_event); 269 + subsys_initcall(__setup_shutdown_event);
+21 -1
drivers/xen/platform-pci.c
··· 31 31 #include <xen/xenbus.h> 32 32 #include <xen/events.h> 33 33 #include <xen/hvm.h> 34 + #include <xen/xen-ops.h> 34 35 35 36 #define DRV_NAME "xen-platform-pci" 36 37 ··· 42 41 static unsigned long platform_mmio; 43 42 static unsigned long platform_mmio_alloc; 44 43 static unsigned long platform_mmiolen; 44 + static uint64_t callback_via; 45 45 46 46 unsigned long alloc_xen_mmio(unsigned long len) 47 47 { ··· 87 85 "xen-platform-pci", pdev); 88 86 } 89 87 88 + static int platform_pci_resume(struct pci_dev *pdev) 89 + { 90 + int err; 91 + if (xen_have_vector_callback) 92 + return 0; 93 + err = xen_set_callback_via(callback_via); 94 + if (err) { 95 + dev_err(&pdev->dev, "platform_pci_resume failure!\n"); 96 + return err; 97 + } 98 + return 0; 99 + } 100 + 90 101 static int __devinit platform_pci_init(struct pci_dev *pdev, 91 102 const struct pci_device_id *ent) 92 103 { 93 104 int i, ret; 94 105 long ioaddr, iolen; 95 106 long mmio_addr, mmio_len; 96 - uint64_t callback_via; 97 107 unsigned int max_nr_gframes; 98 108 99 109 i = pci_enable_device(pdev); ··· 162 148 if (ret) 163 149 goto out; 164 150 xenbus_probe(NULL); 151 + ret = xen_setup_shutdown_event(); 152 + if (ret) 153 + goto out; 165 154 return 0; 166 155 167 156 out: ··· 188 171 .name = DRV_NAME, 189 172 .probe = platform_pci_init, 190 173 .id_table = platform_pci_tbl, 174 + #ifdef CONFIG_PM 175 + .resume_early = platform_pci_resume, 176 + #endif 191 177 }; 192 178 193 179 static int __init platform_pci_module_init(void)
+3
include/xen/xen-ops.h
··· 7 7 8 8 void xen_pre_suspend(void); 9 9 void xen_post_suspend(int suspend_cancelled); 10 + void xen_hvm_post_suspend(int suspend_cancelled); 10 11 11 12 void xen_mm_pin_all(void); 12 13 void xen_mm_unpin_all(void); 13 14 14 15 void xen_timer_resume(void); 15 16 void xen_arch_resume(void); 17 + 18 + int xen_setup_shutdown_event(void); 16 19 17 20 #endif /* INCLUDE_XEN_OPS_H */