Skip to contentSkip to conversation

PV on HVM suspend\resume

PATCH In review Stefano Stabellini 4 participants 9 messages Apr 22, 2010 – May 3, 2010

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PV on HVM suspend\resume

Hi all,
this patch adds suspend\resume support for PV on HVM guests.

---
 arch/x86/xen/enlighten.c                   |    9 ++-
 drivers/xen/features.c                     |    2 +-
 drivers/xen/manage.c                       |   99 ++++++++++++++++++++++++++-
 drivers/xen/platform-pci.c                 |   28 ++++++++-
 drivers/xen/xenbus/xenbus_probe_frontend.c |   29 ++++++++
 include/xen/platform_pci.h                 |    6 ++
 include/xen/xen-ops.h                      |    2 +
 7 files changed, 165 insertions(+), 10 deletions(-)
arch/x86/xen/enlighten.c +5 -4
index 7acb130..98ad573 100644
@@ -1335,12 +1335,13 @@ static int init_hvm_pv_info(int *major, int *minor)
 	return 0;
 }
 
-static void __init init_shared_info(void)
+static void init_shared_info(void)
 {
 	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 *) alloc_bootmem_pages(PAGE_SIZE);
+	if (!shared_info_page)
+		shared_info_page = (struct shared_info *) alloc_bootmem_pages(PAGE_SIZE);
 	xatp.domid = DOMID_SELF;
 	xatp.idx = 0;
 	xatp.space = XENMAPSPACE_shared_info;
@@ -1370,7 +1371,7 @@ void do_hvm_pv_evtchn_intr(void)
 	xen_hvm_evtchn_do_upcall(get_irq_regs());
 }
 
-void __init xen_guest_init(void)
+void xen_guest_init(void)
 {
 	int r;
 	int major, minor;
drivers/xen/features.c +1 -1
index 9e2b64f..99eda16 100644
@@ -18,7 +18,7 @@
 u8 xen_features[XENFEAT_NR_SUBMAPS * 32] __read_mostly;
 EXPORT_SYMBOL_GPL(xen_features);
 
-void __init xen_setup_features(void)
+void xen_setup_features(void)
 {
 	struct xen_feature_info fi;
 	int i, j;
drivers/xen/manage.c +95 -4

141 lines not on this page · raw message

drivers/xen/platform-pci.c +27 -1
index cf91d7e..63a2eac 100644
@@ -32,6 +32,7 @@
 #include <xen/xenbus.h>
 #include <xen/events.h>
 #include <xen/hvm.h>
+#include <xen/xen-ops.h>
 
 #define DRV_NAME    "xen-platform-pci"
 
@@ -42,6 +43,8 @@ MODULE_LICENSE("GPL");
 static unsigned long platform_mmio;
 static unsigned long platform_mmio_alloc;
 static unsigned long platform_mmiolen;
+static uint64_t callback_via;
+struct pci_dev *xen_platform_pdev;
 
 unsigned long alloc_xen_mmio(unsigned long len)
 {
@@ -93,13 +96,33 @@ int xen_irq_init(struct pci_dev *pdev)
 			IRQF_TRIGGER_RISING, "xen-platform-pci", pdev);
 }
 
+void platform_pci_disable_irq(void)
+{
+	printk(KERN_DEBUG "platform_pci_disable_irq\n");
+	disable_irq(xen_platform_pdev->irq);
+}
+
+void platform_pci_enable_irq(void)
+{
+	printk(KERN_DEBUG "platform_pci_enable_irq\n");
+	enable_irq(xen_platform_pdev->irq);
+}
+
+void platform_pci_resume(void)
+{
+	if (xen_set_callback_via(callback_via)) {
+		printk("platform_pci_resume failure!\n");
+		return;
+	}
+}
+
 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;
+	xen_platform_pdev = pdev;
 
 	i = pci_enable_device(pdev);
 	if (i)
@@ -144,6 +167,9 @@ static int __devinit platform_pci_init(struct pci_dev *pdev,
 	if ((ret = xenbus_probe_init()))
 		goto out;
 
+	if ((ret = xen_setup_shutdown_event()))
+		goto out;
+
  out:
 	if (ret) {
 		release_mem_region(mmio_addr, mmio_len);
drivers/xen/xenbus/xenbus_probe_frontend.c +29 -0
index 77af5c3..0ef64a6 100644
@@ -101,6 +101,35 @@ static struct xen_bus_type xenbus_frontend = {
 	},
 };
 
+static int dev_suspend(struct device *dev, void *data)
+{
+	return xenbus_dev_suspend(dev, PMSG_SUSPEND);
+}
+
+void xenbus_suspend(void)
+{
+	DPRINTK("");
+
+	bus_for_each_dev(&xenbus_frontend.bus, NULL, NULL, dev_suspend);
+	xs_suspend();
+}
+EXPORT_SYMBOL_GPL(xenbus_suspend);
+
+static int dev_resume(struct device *dev, void *data)
+{
+	return xenbus_dev_resume(dev);
+}
+
+void xenbus_resume(void)
+{
+	DPRINTK("");
+
+	xs_resume();
+	bus_for_each_dev(&xenbus_frontend.bus, NULL, NULL, dev_resume);
+}
+EXPORT_SYMBOL_GPL(xenbus_resume);
+
+
 static void frontend_changed(struct xenbus_watch *watch,
 			     const char **vec, unsigned int len)
 {
include/xen/platform_pci.h +6 -0
index 870e7a4..4e2afa3 100644
@@ -30,11 +30,17 @@
 
 #ifdef CONFIG_XEN_PLATFORM_PCI
 unsigned long alloc_xen_mmio(unsigned long len);
+void platform_pci_resume(void);
+void platform_pci_disable_irq(void);
+void platform_pci_enable_irq(void);
 #else
 static inline unsigned long alloc_xen_mmio(unsigned long len)
 {
 	return ~0UL;
 }
+static inline void platform_pci_resume(void) {}
+static inline void platform_pci_disable_irq(void) {}
+static inline void platform_pci_enable_irq(void) {}
 #endif
 
 #endif /* _XEN_PLATFORM_PCI_H */
include/xen/xen-ops.h +2 -0
index c7b3ce9..09ba229 100644
@@ -25,4 +25,6 @@ int xen_create_contiguous_region(unsigned long vstart, unsigned int order,
 
 void xen_destroy_contiguous_region(unsigned long vstart, unsigned int order);
 
+int xen_setup_shutdown_event(void);
+
 #endif /* INCLUDE_XEN_OPS_H */
Signature · 1 line
1.5.4.3
#1 lore raw
Quoted 12 lines · Stefano Stabellini
drivers/xen/manage.c +11 -0
+static void do_hvm_suspend(void)
+{
+	int err;
+	int cancelled = 1;
+
+	shutting_down = SHUTDOWN_SUSPEND;
+
+	err = stop_machine_create();
+	if (err) {
+		printk(KERN_ERR "xen suspend: failed to setup stop_machine %d\n", err);
+		goto out;

drivers/xen/manage.c static int xen_suspend(void *data) · line 119

Quoted 10 lines
drivers/xen/manage.c +10 -0
+	}
+
+#ifdef CONFIG_PREEMPT
+	/* If the kernel is preemptible, we need to freeze all the processes
+	   to prevent them from being in the middle of a pagetable update
+	   during suspend. */
+	err = freeze_processes();
+	if (err) {
+		printk(KERN_ERR "xen suspend: freeze failed %d\n", err);
+		goto out_destroy_sm;

This won't compile with CONFIG_PREEMPT enabled, because out_destroy_sm is missing below.

J

#2 lore raw
Quoted 18 lines · Jeremy Fitzhardinge
Quoted 17 lines · Stefano Stabellini
drivers/xen/manage.c +17 -0
+static void do_hvm_suspend(void)
+{
+	int err;
+	int cancelled = 1;
+
+	shutting_down = SHUTDOWN_SUSPEND;
+
+	err = stop_machine_create();
+	if (err) {
+		printk(KERN_ERR "xen suspend: failed to setup stop_machine %d\n", err);
+		goto out;
+	}
+
+#ifdef CONFIG_PREEMPT
+	/* If the kernel is preemptible, we need to freeze all the processes
+	   to prevent them from being in the middle of a pagetable update
+	   during suspend. */
Quoted 9 lines

drivers/xen/manage.c static int xen_suspend(void *data) · line 119

Quoted 5 lines
drivers/xen/manage.c +4 -0
+	err = freeze_processes();
+	if (err) {
+		printk(KERN_ERR "xen suspend: freeze failed %d\n", err);
+		goto out_destroy_sm;

This won't compile with CONFIG_PREEMPT enabled, because out_destroy_sm is missing below.

Now it is fixed, however I tried suspend/resume with CONFIG_PREEMPT enabled and the kernel seems to hang at resume time; I wonder if it works for pv guests since the suspend/resume code is similiar...

#3 lore raw
Quoted 6 lines · Stefano Stabellini
Quoted 4 lines

This won't compile with CONFIG_PREEMPT enabled, because out_destroy_sm is missing below.

Now it is fixed,

Did you push out the fix (ideally as a new delta changeset on top of the previous ones, rather than rebaseing them).

Quoted 4 lines

however I tried suspend/resume with CONFIG_PREEMPT
enabled and the kernel seems to hang at resume time; I wonder if it works for pv guests since the suspend/resume code is similiar...

I think Pasi and IanC tested it quite a bit not too long ago, but its possible they didn't test preempt kernels (and it wouldn't surprise me at all if preempt breaks things).

Thanks,
J

#4 lore raw
Quoted 11 lines · Jeremy Fitzhardinge
Quoted 6 lines · Stefano Stabellini
Quoted 4 lines

This won't compile with CONFIG_PREEMPT enabled, because out_destroy_sm is missing below.

Now it is fixed,

Did you push out the fix (ideally as a new delta changeset on top of the previous ones, rather than rebaseing them).

Yes but this time I rebased them; next time I'll keep the fix separated.

Quoted 10 lines
Quoted 5 lines

however I tried suspend/resume with CONFIG_PREEMPT
enabled and the kernel seems to hang at resume time; I wonder if it works for pv guests since the suspend/resume code is similiar...

I think Pasi and IanC tested it quite a bit not too long ago, but its possible they didn't test preempt kernels (and it wouldn't surprise me at all if preempt breaks things).

all right, more debugging required here...

#5 lore raw
Quoted 21 lines · Stefano Stabellini
Quoted 11 lines · Jeremy Fitzhardinge
Quoted 6 lines · Stefano Stabellini
Quoted 4 lines

This won't compile with CONFIG_PREEMPT enabled, because out_destroy_sm is missing below.

Now it is fixed,

Did you push out the fix (ideally as a new delta changeset on top of the previous ones, rather than rebaseing them).

Yes but this time I rebased them; next time I'll keep the fix separated.

Quoted 6 lines
Quoted 5 lines

however I tried suspend/resume with CONFIG_PREEMPT
enabled and the kernel seems to hang at resume time; I wonder if it works for pv guests since the suspend/resume code is similiar...

Quoted 7 lines
Quoted 4 lines

I think Pasi and IanC tested it quite a bit not too long ago, but its possible they didn't test preempt kernels (and it wouldn't surprise me at all if preempt breaks things).

all right, more debugging required here...

I was testing a lot with normal PV guests.. kernel .config was based on standard Fedora kernels:

$ grep -i empt config-2.6.32.11-99.fc12.x86_64
# CONFIG_TREE_PREEMPT_RCU is not set
CONFIG_PREEMPT_NOTIFIERS=y
# CONFIG_PREEMPT_NONE is not set
CONFIG_PREEMPT_VOLUNTARY=y
# CONFIG_PREEMPT is not set
$ grep -i empt config-2.6.32.9-70.fc12.i686.PAE
# CONFIG_TREE_PREEMPT_RCU is not set
CONFIG_PREEMPT_NOTIFIERS=y
# CONFIG_PREEMPT_NONE is not set
CONFIG_PREEMPT_VOLUNTARY=y
# CONFIG_PREEMPT is not set

-- Pasi

#6 lore raw
In reply to Stefano Stabellini
Quoted 21 lines · Stefano Stabellini
Quoted 11 lines · Jeremy Fitzhardinge
Quoted 6 lines · Stefano Stabellini
Quoted 4 lines

This won't compile with CONFIG_PREEMPT enabled, because out_destroy_sm is missing below.

Now it is fixed,

Did you push out the fix (ideally as a new delta changeset on top of the previous ones, rather than rebaseing them).

Yes but this time I rebased them; next time I'll keep the fix separated.

Quoted 6 lines
Quoted 5 lines

however I tried suspend/resume with CONFIG_PREEMPT
enabled and the kernel seems to hang at resume time; I wonder if it works for pv guests since the suspend/resume code is similiar...

Quoted 6 lines
Quoted 4 lines

I think Pasi and IanC tested it quite a bit not too long ago, but its possible they didn't test preempt kernels (and it wouldn't surprise me at all if preempt breaks things).

all right, more debugging required here...

FYI. The Documents/SubmitChecklist mentions:

12: Has been tested with CONFIG_PREEMPT, CONFIG_DEBUG_PREEMPT,
CONFIG_DEBUG_SLAB, CONFIG_DEBUG_PAGEALLOC, CONFIG_DEBUG_MUTEXES, CONFIG_DEBUG_SPINLOCK, CONFIG_DEBUG_SPINLOCK_SLEEP all simultaneously enabled.

amongs other things..

#7 lore raw
In reply to Stefano Stabellini
Quoted 6 lines · Stefano Stabellini
Quoted 4 lines

Did you push out the fix (ideally as a new delta changeset on top of the previous ones, rather than rebaseing them).

Yes but this time I rebased them; next time I'll keep the fix separated.

That's awkward because I've already merged the original one. The merge was non-trivial because some of the affected code was moved around, so I'd prefer not to do it again. Since it looks like the fix is a one-liner, I'm just going to add it to your original branch.

J

#8 lore raw
In reply to Stefano Stabellini
Quoted 3 lines · Stefano Stabellini

all right, more debugging required here...

I found the issue: I simply forgot to restart the processes at resume time :)
I pushed the update to

git://xenbits.xen.org/people/sstabellini/linux-pvhvm.git