Skip to content

Commit 016b6f5

Browse files
Stefano StabelliniJeremy Fitzhardinge
authored andcommitted
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>
1 parent 183d03c commit 016b6f5

6 files changed

Lines changed: 90 additions & 11 deletions

File tree

‎arch/x86/xen/enlighten.c‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,13 +1262,15 @@ static int init_hvm_pv_info(int *major, int *minor)
12621262
return 0;
12631263
}
12641264

1265-
static void __init init_shared_info(void)
1265+
void xen_hvm_init_shared_info(void)
12661266
{
1267+
int cpu;
12671268
struct xen_add_to_physmap xatp;
1268-
struct shared_info *shared_info_page;
1269+
static struct shared_info *shared_info_page = 0;
12691270

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);
12721274
xatp.domid = DOMID_SELF;
12731275
xatp.idx = 0;
12741276
xatp.space = XENMAPSPACE_shared_info;
@@ -1278,7 +1280,17 @@ static void __init init_shared_info(void)
12781280

12791281
HYPERVISOR_shared_info = (struct shared_info *)shared_info_page;
12801282

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+
}
12821294
}
12831295

12841296
static int __cpuinit xen_hvm_cpu_notify(struct notifier_block *self,
@@ -1308,7 +1320,7 @@ static void __init xen_hvm_guest_init(void)
13081320
if (r < 0)
13091321
return;
13101322

1311-
init_shared_info();
1323+
xen_hvm_init_shared_info();
13121324

13131325
if (xen_feature(XENFEAT_hvm_callback_vector))
13141326
xen_have_vector_callback = 1;

‎arch/x86/xen/suspend.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ void xen_pre_suspend(void)
2626
BUG();
2727
}
2828

29+
void xen_hvm_post_suspend(int suspend_cancelled)
30+
{
31+
xen_hvm_init_shared_info();
32+
xen_callback_vector();
33+
}
34+
2935
void xen_post_suspend(int suspend_cancelled)
3036
{
3137
xen_build_mfn_list_list();

‎arch/x86/xen/xen-ops.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ void xen_enable_syscall(void);
3939
void xen_vcpu_restore(void);
4040

4141
void xen_callback_vector(void);
42+
void xen_hvm_init_shared_info(void);
4243

4344
void __init xen_build_dynamic_phys_to_machine(void);
4445

‎drivers/xen/manage.c‎

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <linux/stop_machine.h>
1010
#include <linux/freezer.h>
1111

12+
#include <xen/xen.h>
1213
#include <xen/xenbus.h>
1314
#include <xen/grant_table.h>
1415
#include <xen/events.h>
@@ -17,6 +18,7 @@
1718

1819
#include <asm/xen/hypercall.h>
1920
#include <asm/xen/page.h>
21+
#include <asm/xen/hypervisor.h>
2022

2123
enum shutdown_state {
2224
SHUTDOWN_INVALID = -1,
@@ -33,10 +35,30 @@ enum shutdown_state {
3335
static enum shutdown_state shutting_down = SHUTDOWN_INVALID;
3436

3537
#ifdef CONFIG_PM_SLEEP
36-
static int xen_suspend(void *data)
38+
static int xen_hvm_suspend(void *data)
3739
{
40+
struct sched_shutdown r = { .reason = SHUTDOWN_suspend };
3841
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+
{
3960
int err;
61+
int *cancelled = data;
4062

4163
BUG_ON(!irqs_disabled());
4264

@@ -106,7 +128,10 @@ static void do_suspend(void)
106128
goto out_resume;
107129
}
108130

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));
110135

111136
dpm_resume_noirq(PMSG_RESUME);
112137

@@ -255,7 +280,19 @@ static int shutdown_event(struct notifier_block *notifier,
255280
return NOTIFY_DONE;
256281
}
257282

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)
259296
{
260297
static struct notifier_block xenstore_notifier = {
261298
.notifier_call = shutdown_event
@@ -266,4 +303,4 @@ static int __init setup_shutdown_event(void)
266303
}
267304
EXPORT_SYMBOL_GPL(xen_setup_shutdown_event);
268305

269-
subsys_initcall(setup_shutdown_event);
306+
subsys_initcall(__setup_shutdown_event);

‎drivers/xen/platform-pci.c‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <xen/xenbus.h>
3232
#include <xen/events.h>
3333
#include <xen/hvm.h>
34+
#include <xen/xen-ops.h>
3435

3536
#define DRV_NAME "xen-platform-pci"
3637

@@ -41,6 +42,7 @@ MODULE_LICENSE("GPL");
4142
static unsigned long platform_mmio;
4243
static unsigned long platform_mmio_alloc;
4344
static unsigned long platform_mmiolen;
45+
static uint64_t callback_via;
4446

4547
unsigned long alloc_xen_mmio(unsigned long len)
4648
{
@@ -85,13 +87,25 @@ static int xen_allocate_irq(struct pci_dev *pdev)
8587
"xen-platform-pci", pdev);
8688
}
8789

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+
88103
static int __devinit platform_pci_init(struct pci_dev *pdev,
89104
const struct pci_device_id *ent)
90105
{
91106
int i, ret;
92107
long ioaddr, iolen;
93108
long mmio_addr, mmio_len;
94-
uint64_t callback_via;
95109
unsigned int max_nr_gframes;
96110

97111
i = pci_enable_device(pdev);
@@ -148,6 +162,9 @@ static int __devinit platform_pci_init(struct pci_dev *pdev,
148162
if (ret)
149163
goto out;
150164
xenbus_probe(NULL);
165+
ret = xen_setup_shutdown_event();
166+
if (ret)
167+
goto out;
151168
return 0;
152169

153170
out:
@@ -171,6 +188,9 @@ static struct pci_driver platform_driver = {
171188
.name = DRV_NAME,
172189
.probe = platform_pci_init,
173190
.id_table = platform_pci_tbl,
191+
#ifdef CONFIG_PM
192+
.resume_early = platform_pci_resume,
193+
#endif
174194
};
175195

176196
static int __init platform_pci_module_init(void)

‎include/xen/xen-ops.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ DECLARE_PER_CPU(struct vcpu_info *, xen_vcpu);
77

88
void xen_pre_suspend(void);
99
void xen_post_suspend(int suspend_cancelled);
10+
void xen_hvm_post_suspend(int suspend_cancelled);
1011

1112
void xen_mm_pin_all(void);
1213
void xen_mm_unpin_all(void);
1314

1415
void xen_timer_resume(void);
1516
void xen_arch_resume(void);
1617

18+
int xen_setup_shutdown_event(void);
19+
1720
#endif /* INCLUDE_XEN_OPS_H */

0 commit comments

Comments
 (0)