Skip to contentSkip to conversation

xen: suspend and resume system devices when running PVHVM

PATCH In review Ian Campbell 6 participants 24 messages Feb 14, 2011 – Feb 17, 2011

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

PATCH 1/1 xen: suspend and resume system devices when running PVHVM

Otherwise we fail to properly suspend/resume all of the emulated devices.

Something between 2.6.38-rc2 and rc3 appears to have exposed this issue, but it's always been wrong not to do this.

Cc Stefano Stabellini <[email protected]>
Cc Jeremy Fitzhardinge <[email protected]>
---
 drivers/xen/manage.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
drivers/xen/manage.c +10 -0
index db8c4c4..2417727 100644
@@ -37,11 +37,19 @@ static enum shutdown_state shutting_down = SHUTDOWN_INVALID;
 #ifdef CONFIG_PM_SLEEP
 static int xen_hvm_suspend(void *data)
 {
+	int err;
 	struct sched_shutdown r = { .reason = SHUTDOWN_suspend };
 	int *cancelled = data;
 
 	BUG_ON(!irqs_disabled());
 
+	err = sysdev_suspend(PMSG_SUSPEND);
+	if (err) {
+		printk(KERN_ERR "xen_hvm_suspend: sysdev_suspend failed: %d\n",
+		       err);
+		return err;
+	}
+
 	*cancelled = HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
 
 	xen_hvm_post_suspend(*cancelled);
@@ -53,6 +61,8 @@ static int xen_hvm_suspend(void *data)
 		xen_timer_resume();
 	}
 
+	sysdev_resume();
+
 	return 0;
 }
 
Signature · 1 line
1.5.6.5
#1 lore raw
Quoted 8 lines · Ian Campbell

Otherwise we fail to properly suspend/resume all of the emulated devices.

Something between 2.6.38-rc2 and rc3 appears to have exposed this issue, but it's always been wrong not to do this.

Cc Stefano Stabellini <[email protected]>
Cc Jeremy Fitzhardinge <[email protected]>

I can confirm that this patch fixes a sporadic save/restore issue with upstream PVHVM kernels.
I am going to import it in the pvhvm branch I am preparing for the next merge window.

#2 lore raw
Quoted 6 lines · Stefano Stabellini
Quoted 5 lines · Ian Campbell

Otherwise we fail to properly suspend/resume all of the emulated devices.

Something between 2.6.38-rc2 and rc3 appears to have exposed this issue, but it's always been wrong not to do this.

Quoted 8 lines
Quoted 3 lines
Cc Stefano Stabellini <[email protected]>
Cc Jeremy Fitzhardinge <[email protected]>

I can confirm that this patch fixes a sporadic save/restore issue with upstream PVHVM kernels.
I am going to import it in the pvhvm branch I am preparing for the next merge window.

I was intending to send this one to Linus for the next rc, since it appears to be currently broken.

Ian.

#3 lore raw
Quoted 11 lines · Ian Campbell
Quoted 10 lines · Stefano Stabellini
Quoted 8 lines · Ian Campbell

Otherwise we fail to properly suspend/resume all of the emulated devices.

Something between 2.6.38-rc2 and rc3 appears to have exposed this issue, but it's always been wrong not to do this.

Cc Stefano Stabellini <[email protected]>
Cc Jeremy Fitzhardinge <[email protected]>
Quoted 7 lines
Quoted 4 lines

I can confirm that this patch fixes a sporadic save/restore issue with upstream PVHVM kernels.
I am going to import it in the pvhvm branch I am preparing for the next merge window.

I was intending to send this one to Linus for the next rc, since it appears to be currently broken.

great, even better

#4 lore raw
In reply to Ian Campbell
Quoted 10 lines · Ian Campbell
Quoted 9 lines · Stefano Stabellini
Quoted 8 lines · Ian Campbell

Otherwise we fail to properly suspend/resume all of the emulated devices.

Something between 2.6.38-rc2 and rc3 appears to have exposed this issue, but it's always been wrong not to do this.

Cc Stefano Stabellini <[email protected]>
Cc Jeremy Fitzhardinge <[email protected]>
Quoted 6 lines
Quoted 4 lines

I can confirm that this patch fixes a sporadic save/restore issue with upstream PVHVM kernels.
I am going to import it in the pvhvm branch I am preparing for the next merge window.

I was intending to send this one to Linus for the next rc, since it appears to be currently broken.

Fine by me.

J

#5 lore raw
Quoted 11 lines · Jeremy Fitzhardinge
Quoted 10 lines · Ian Campbell
Quoted 9 lines · Stefano Stabellini
Quoted 8 lines · Ian Campbell

Otherwise we fail to properly suspend/resume all of the emulated devices.

Something between 2.6.38-rc2 and rc3 appears to have exposed this issue, but it's always been wrong not to do this.

Cc Stefano Stabellini <[email protected]>
Cc Jeremy Fitzhardinge <[email protected]>
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

I can confirm that this patch fixes a sporadic save/restore issue with upstream PVHVM kernels.
I am going to import it in the pvhvm branch I am preparing for the next merge window.

I was intending to send this one to Linus for the next rc, since it appears to be currently broken.

Fine by me.

Thanks, I'll take your and Stefano's responses as Acked-by's and send upstream today.

Ian.

#6 lore raw

cover suspend cleanups, refactoring and fixes (Was: Re: [PATCH] xen: suspend and resume system devices when running PVHVM)

In reply to Stefano Stabellini
Quoted 2 lines · Stefano Stabellini

I am going to import it in the pvhvm branch I am preparing for the next merge window.

Is there any conflict with the following series (which builds on this patch)? It's not all pvhvm related but the bulk is the removal of the separate xen_hvm_suspend function.

Do you want to carry these in your branch for the next merge window or shall I create a separate branch?

Ian.

#7 lore raw

PATCH 1/11 xen: do not respond to unknown xenstore control requests

The PV xenbus control/shutdown node is written by the toolstack as a request to the guest to perform a particular action (shutdown, reboot, suspend etc). The guest is expected to acknowledge that it will complete a request by clearing the control node.

Previously it would acknowledge any request, even if it did not know what to do with it. Specifically in the case where CONFIG_PM_SLEEP is not enabled the kernel would acknowledge a suspend request even though it was not actually going to do anything.

Instead make the kernel only acknowledge requests if it is actually going to do something with it. This will improve the toolstack's ability to diagnose and deal with failures.

---
 drivers/xen/manage.c |   49 +++++++++++++++++++++++++++++++++++++------------
 1 files changed, 37 insertions(+), 12 deletions(-)
drivers/xen/manage.c +37 -12
index 2417727..6f866e2 100644
@@ -172,12 +172,39 @@ out:
 }
 #endif	/* CONFIG_PM_SLEEP */
 
+struct shutdown_handler {
+	const char *command;
+	void (*cb)(void);
+};
+
+static void do_poweroff(void)
+{
+	shutting_down = SHUTDOWN_POWEROFF;
+	orderly_poweroff(false);
+}
+
+static void do_reboot(void)
+{
+	shutting_down = SHUTDOWN_POWEROFF; /* ? */
+	ctrl_alt_del();
+}
+
 static void shutdown_handler(struct xenbus_watch *watch,
 			     const char **vec, unsigned int len)
 {
 	char *str;
 	struct xenbus_transaction xbt;
 	int err;
+	static struct shutdown_handler handlers[] = {
+		{ "poweroff",	do_poweroff },
+		{ "halt",	do_poweroff },
+		{ "reboot",	do_reboot   },
+#ifdef CONFIG_PM_SLEEP
+		{ "suspend",	do_suspend  },
+#endif
+		{NULL, NULL},
+	};
+	static struct shutdown_handler *handler;
 
 	if (shutting_down != SHUTDOWN_INVALID)
 		return;
@@ -194,7 +221,14 @@ static void shutdown_handler(struct xenbus_watch *watch,
 		return;
 	}
 
-	xenbus_write(xbt, "control", "shutdown", "");
+	for (handler = &handlers[0]; handler->command; handler++) {
+		if (strcmp(str, handler->command) == 0)
+			break;
+	}
+
+	/* Only acknowledge commands which we are prepared to handle. */
+	if (handler->cb)
+		xenbus_write(xbt, "control", "shutdown", "");
 
 	err = xenbus_transaction_end(xbt, 0);
 	if (err == -EAGAIN) {
@@ -202,17 +236,8 @@ static void shutdown_handler(struct xenbus_watch *watch,
 		goto again;
 	}
 
-	if (strcmp(str, "poweroff") == 0 ||
-	    strcmp(str, "halt") == 0) {
-		shutting_down = SHUTDOWN_POWEROFF;
-		orderly_poweroff(false);
-	} else if (strcmp(str, "reboot") == 0) {
-		shutting_down = SHUTDOWN_POWEROFF; /* ? */
-		ctrl_alt_del();
-#ifdef CONFIG_PM_SLEEP
-	} else if (strcmp(str, "suspend") == 0) {
-		do_suspend();
-#endif
+	if (handler->cb) {
+		handler->cb();
 	} else {
 		printk(KERN_INFO "Ignoring shutdown request: %s\n", str);
 		shutting_down = SHUTDOWN_INVALID;
Signature · 1 line
1.5.6.5
#8 lore raw

PATCH 2/11 xen: use new schedop interface for suspend

In reply to Ian Campbell

Take the opportunity to comment on the semantics of the PV guest suspend hypercall arguments.

---
 arch/x86/include/asm/xen/hypercall.h |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)
arch/x86/include/asm/xen/hypercall.h +10 -3
index a3c28ae..a7d5823 100644
@@ -422,10 +422,17 @@ HYPERVISOR_set_segment_base(int reg, unsigned long value)
 #endif
 
 static inline int
-HYPERVISOR_suspend(unsigned long srec)
+HYPERVISOR_suspend(unsigned long start_info_mfn)
 {
-	return _hypercall3(int, sched_op, SCHEDOP_shutdown,
-			   SHUTDOWN_suspend, srec);
+	struct sched_shutdown r = { .reason = SHUTDOWN_suspend };
+
+	/*
+	 * For a PV guest the tools require that the start_info mfn be
+	 * present in rdx/edx when the hypercall is made. Per the
+	 * hypercall calling convention this is the third hypercall
+	 * argument, which is start_info_mfn here.
+	 */
+	return _hypercall3(int, sched_op_new, SCHEDOP_shutdown, &r, start_info_mfn);
 }
 
 static inline int
Signature · 1 line
1.5.6.5
#9 lore raw

PATCH 3/11 xen: switch to new schedop hypercall by default.

In reply to Ian Campbell

Rename old interface to sched_op_compat and rename sched_op_new to simply sched_op.

---
 arch/x86/include/asm/xen/hypercall.h |    4 ++--
 include/xen/interface/xen.h          |    4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
arch/x86/include/asm/xen/hypercall.h +2 -2
index a7d5823..8508bfe 100644
@@ -287,7 +287,7 @@ HYPERVISOR_fpu_taskswitch(int set)
 static inline int
 HYPERVISOR_sched_op(int cmd, void *arg)
 {
-	return _hypercall2(int, sched_op_new, cmd, arg);
+	return _hypercall2(int, sched_op, cmd, arg);
 }
 
 static inline long
@@ -432,7 +432,7 @@ HYPERVISOR_suspend(unsigned long start_info_mfn)
 	 * hypercall calling convention this is the third hypercall
 	 * argument, which is start_info_mfn here.
 	 */
-	return _hypercall3(int, sched_op_new, SCHEDOP_shutdown, &r, start_info_mfn);
+	return _hypercall3(int, sched_op, SCHEDOP_shutdown, &r, start_info_mfn);
 }
 
 static inline int
include/xen/interface/xen.h +2 -2
index 2befa3e..b33257b 100644
@@ -30,7 +30,7 @@
 #define __HYPERVISOR_stack_switch          3
 #define __HYPERVISOR_set_callbacks         4
 #define __HYPERVISOR_fpu_taskswitch        5
-#define __HYPERVISOR_sched_op              6
+#define __HYPERVISOR_sched_op_compat       6
 #define __HYPERVISOR_dom0_op               7
 #define __HYPERVISOR_set_debugreg          8
 #define __HYPERVISOR_get_debugreg          9
@@ -52,7 +52,7 @@
 #define __HYPERVISOR_mmuext_op            26
 #define __HYPERVISOR_acm_op               27
 #define __HYPERVISOR_nmi_op               28
-#define __HYPERVISOR_sched_op_new         29
+#define __HYPERVISOR_sched_op             29
 #define __HYPERVISOR_callback_op          30
 #define __HYPERVISOR_xenoprof_op          31
 #define __HYPERVISOR_event_channel_op     32
Signature · 1 line
1.5.6.5
#10 lore raw

PATCH 4/11 xen: suspend: use HYPERVISOR_suspend for PVHVM case instead of open coding

In reply to Ian Campbell
---
 drivers/xen/manage.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
drivers/xen/manage.c +6 -2
index 6f866e2..ba7caa3 100644
@@ -38,7 +38,6 @@ static enum shutdown_state shutting_down = SHUTDOWN_INVALID;
 static int xen_hvm_suspend(void *data)
 {
 	int err;
-	struct sched_shutdown r = { .reason = SHUTDOWN_suspend };
 	int *cancelled = data;
 
 	BUG_ON(!irqs_disabled());
@@ -50,7 +49,12 @@ static int xen_hvm_suspend(void *data)
 		return err;
 	}
 
-	*cancelled = HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
+	/*
+	 * This hypercall returns 1 if suspend was cancelled
+	 * or the domain was merely checkpointed, and 0 if it
+	 * is resuming in a new domain.
+	 */
+	*cancelled = HYPERVISOR_suspend(0UL);
 
 	xen_hvm_post_suspend(*cancelled);
 	gnttab_resume();
Signature · 1 line
1.5.6.5
#11 lore raw

PATCH 5/11 xen: suspend: refactor cancellation flag into a structure

In reply to Ian Campbell

Will add extra fields in subsequent patches.

---
 drivers/xen/manage.c |   32 +++++++++++++++++++-------------
 1 files changed, 19 insertions(+), 13 deletions(-)
drivers/xen/manage.c +19 -13
index ba7caa3..22af876 100644
@@ -34,11 +34,15 @@ enum shutdown_state {
 /* Ignore multiple shutdown requests. */
 static enum shutdown_state shutting_down = SHUTDOWN_INVALID;
 
+struct suspend_info {
+	int cancelled;
+};
+
 #ifdef CONFIG_PM_SLEEP
 static int xen_hvm_suspend(void *data)
 {
+	struct suspend_info *si = data;
 	int err;
-	int *cancelled = data;
 
 	BUG_ON(!irqs_disabled());
 
@@ -54,12 +58,12 @@ static int xen_hvm_suspend(void *data)
 	 * or the domain was merely checkpointed, and 0 if it
 	 * is resuming in a new domain.
 	 */
-	*cancelled = HYPERVISOR_suspend(0UL);
+	si->cancelled = HYPERVISOR_suspend(0UL);
 
-	xen_hvm_post_suspend(*cancelled);
+	xen_hvm_post_suspend(si->cancelled);
 	gnttab_resume();
 
-	if (!*cancelled) {
+	if (!si->cancelled) {
 		xen_irq_resume();
 		xen_console_resume();
 		xen_timer_resume();
@@ -72,8 +76,8 @@ static int xen_hvm_suspend(void *data)
 
 static int xen_suspend(void *data)
 {
+	struct suspend_info *si = data;
 	int err;
-	int *cancelled = data;
 
 	BUG_ON(!irqs_disabled());
 
@@ -93,13 +97,13 @@ static int xen_suspend(void *data)
 	 * or the domain was merely checkpointed, and 0 if it
 	 * is resuming in a new domain.
 	 */
-	*cancelled = HYPERVISOR_suspend(virt_to_mfn(xen_start_info));
+	si->cancelled = HYPERVISOR_suspend(virt_to_mfn(xen_start_info));
 
-	xen_post_suspend(*cancelled);
+	xen_post_suspend(si->cancelled);
 	gnttab_resume();
 	xen_mm_unpin_all();
 
-	if (!*cancelled) {
+	if (!si->cancelled) {
 		xen_irq_resume();
 		xen_console_resume();
 		xen_timer_resume();
@@ -113,7 +117,7 @@ static int xen_suspend(void *data)
 static void do_suspend(void)
 {
 	int err;
-	int cancelled = 1;
+	struct suspend_info si;
 
 	shutting_down = SHUTDOWN_SUSPEND;
 
@@ -143,20 +147,22 @@ static void do_suspend(void)
 		goto out_resume;
 	}
 
+	si.cancelled = 1;
+
 	if (xen_hvm_domain())
-		err = stop_machine(xen_hvm_suspend, &cancelled, cpumask_of(0));
+		err = stop_machine(xen_hvm_suspend, &si, cpumask_of(0));
 	else
-		err = stop_machine(xen_suspend, &cancelled, cpumask_of(0));
+		err = stop_machine(xen_suspend, &si, cpumask_of(0));
 
 	dpm_resume_noirq(PMSG_RESUME);
 
 	if (err) {
 		printk(KERN_ERR "failed to start xen_suspend: %d\n", err);
-		cancelled = 1;
+		si.cancelled = 1;
 	}
 
 out_resume:
-	if (!cancelled) {
+	if (!si.cancelled) {
 		xen_arch_resume();
 		xs_resume();
 	} else
Signature · 1 line
1.5.6.5
#12 lore raw

PATCH 6/11 xen: suspend: pass extra hypercall argument via suspend_info struct

In reply to Ian Campbell
---
 drivers/xen/manage.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
drivers/xen/manage.c +8 -2
index 22af876..0647918 100644
@@ -36,6 +36,7 @@ static enum shutdown_state shutting_down = SHUTDOWN_INVALID;
 
 struct suspend_info {
 	int cancelled;
+	unsigned long arg; /* extra hypercall argument */
 };
 
 #ifdef CONFIG_PM_SLEEP
@@ -58,7 +59,7 @@ static int xen_hvm_suspend(void *data)
 	 * or the domain was merely checkpointed, and 0 if it
 	 * is resuming in a new domain.
 	 */
-	si->cancelled = HYPERVISOR_suspend(0UL);
+	si->cancelled = HYPERVISOR_suspend(si->arg);
 
 	xen_hvm_post_suspend(si->cancelled);
 	gnttab_resume();
@@ -97,7 +98,7 @@ static int xen_suspend(void *data)
 	 * or the domain was merely checkpointed, and 0 if it
 	 * is resuming in a new domain.
 	 */
-	si->cancelled = HYPERVISOR_suspend(virt_to_mfn(xen_start_info));
+	si->cancelled = HYPERVISOR_suspend(si->arg);
 
 	xen_post_suspend(si->cancelled);
 	gnttab_resume();
@@ -150,6 +151,11 @@ static void do_suspend(void)
 	si.cancelled = 1;
 
 	if (xen_hvm_domain())
+		si.arg = 0UL;
+	else
+		si.arg = virt_to_mfn(xen_start_info);
+
+	if (xen_hvm_domain())
 		err = stop_machine(xen_hvm_suspend, &si, cpumask_of(0));
 	else
 		err = stop_machine(xen_suspend, &si, cpumask_of(0));
Signature · 1 line
1.5.6.5
#13 lore raw

PATCH 7/11 xen: suspend: add "arch" to pre/post suspend hooks

In reply to Ian Campbell

xen_pre_device_suspend is unused on ia64.

---
 arch/ia64/xen/suspend.c |    9 ++-------
 arch/x86/xen/suspend.c  |    6 +++---
 drivers/xen/manage.c    |    6 +++---
 include/xen/xen-ops.h   |    6 +++---
 4 files changed, 11 insertions(+), 16 deletions(-)
arch/ia64/xen/suspend.c +2 -7
index fd66b04..419c862 100644
@@ -37,19 +37,14 @@ xen_mm_unpin_all(void)
 	/* nothing */
 }
 
-void xen_pre_device_suspend(void)
-{
-	/* nothing */
-}
-
 void
-xen_pre_suspend()
+xen_arch_pre_suspend()
 {
 	/* nothing */
 }
 
 void
-xen_post_suspend(int suspend_cancelled)
+xen_arch_post_suspend(int suspend_cancelled)
 {
 	if (suspend_cancelled)
 		return;
arch/x86/xen/suspend.c +3 -3
index 9bbd63a..96b1be2 100644
@@ -12,7 +12,7 @@
 #include "xen-ops.h"
 #include "mmu.h"
 
-void xen_pre_suspend(void)
+void xen_arch_pre_suspend(void)
 {
 	xen_start_info->store_mfn = mfn_to_pfn(xen_start_info->store_mfn);
 	xen_start_info->console.domU.mfn =
@@ -26,7 +26,7 @@ void xen_pre_suspend(void)
 		BUG();
 }
 
-void xen_hvm_post_suspend(int suspend_cancelled)
+void xen_arch_hvm_post_suspend(int suspend_cancelled)
 {
 	int cpu;
 	xen_hvm_init_shared_info();
@@ -39,7 +39,7 @@ void xen_hvm_post_suspend(int suspend_cancelled)
 	}
 }
 
-void xen_post_suspend(int suspend_cancelled)
+void xen_arch_post_suspend(int suspend_cancelled)
 {
 	xen_build_mfn_list_list();
 
drivers/xen/manage.c +3 -3
index 0647918..7783722 100644
@@ -61,7 +61,7 @@ static int xen_hvm_suspend(void *data)
 	 */
 	si->cancelled = HYPERVISOR_suspend(si->arg);
 
-	xen_hvm_post_suspend(si->cancelled);
+	xen_arch_hvm_post_suspend(si->cancelled);
 	gnttab_resume();
 
 	if (!si->cancelled) {
@@ -91,7 +91,7 @@ static int xen_suspend(void *data)
 
 	xen_mm_pin_all();
 	gnttab_suspend();
-	xen_pre_suspend();
+	xen_arch_pre_suspend();
 
 	/*
 	 * This hypercall returns 1 if suspend was cancelled
@@ -100,7 +100,7 @@ static int xen_suspend(void *data)
 	 */
 	si->cancelled = HYPERVISOR_suspend(si->arg);
 
-	xen_post_suspend(si->cancelled);
+	xen_arch_post_suspend(si->cancelled);
 	gnttab_resume();
 	xen_mm_unpin_all();
 
include/xen/xen-ops.h +3 -3
index 98b9215..03c85d7 100644
@@ -5,9 +5,9 @@
 
 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_arch_pre_suspend(void);
+void xen_arch_post_suspend(int suspend_cancelled);
+void xen_arch_hvm_post_suspend(int suspend_cancelled);
 
 void xen_mm_pin_all(void);
 void xen_mm_unpin_all(void);
Signature · 1 line
1.5.6.5
#14 lore raw

PATCH 8/11 xen: suspend: refactor non-arch specific pre/post suspend hooks

In reply to Ian Campbell
---
 drivers/xen/manage.c |   25 ++++++++++++++++++++-----
 1 files changed, 20 insertions(+), 5 deletions(-)
drivers/xen/manage.c +20 -5
index 7783722..f61c155 100644
@@ -39,6 +39,23 @@ struct suspend_info {
 	unsigned long arg; /* extra hypercall argument */
 };
 
+static void xen_hvm_post_suspend(void)
+{
+	gnttab_resume();
+}
+
+static void xen_pre_suspend(void)
+{
+	xen_mm_pin_all();
+	gnttab_suspend();
+}
+
+static void xen_post_suspend(void)
+{
+	gnttab_resume();
+	xen_mm_unpin_all();
+}
+
 #ifdef CONFIG_PM_SLEEP
 static int xen_hvm_suspend(void *data)
 {
@@ -62,7 +79,7 @@ static int xen_hvm_suspend(void *data)
 	si->cancelled = HYPERVISOR_suspend(si->arg);
 
 	xen_arch_hvm_post_suspend(si->cancelled);
-	gnttab_resume();
+	xen_hvm_post_suspend();
 
 	if (!si->cancelled) {
 		xen_irq_resume();
@@ -89,8 +106,7 @@ static int xen_suspend(void *data)
 		return err;
 	}
 
-	xen_mm_pin_all();
-	gnttab_suspend();
+	xen_pre_suspend();
 	xen_arch_pre_suspend();
 
 	/*
@@ -101,8 +117,7 @@ static int xen_suspend(void *data)
 	si->cancelled = HYPERVISOR_suspend(si->arg);
 
 	xen_arch_post_suspend(si->cancelled);
-	gnttab_resume();
-	xen_mm_unpin_all();
+	xen_post_suspend();
 
 	if (!si->cancelled) {
 		xen_irq_resume();
Signature · 1 line
1.5.6.5
#15 lore raw

PATCH 9/11 xen: suspend: move arch specific pre/post suspend hooks into generic hooks

In reply to Ian Campbell
---
 drivers/xen/manage.c |   14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)
drivers/xen/manage.c +7 -7
index f61c155..49a7458 100644
@@ -39,8 +39,9 @@ struct suspend_info {
 	unsigned long arg; /* extra hypercall argument */
 };
 
-static void xen_hvm_post_suspend(void)
+static void xen_hvm_post_suspend(int cancelled)
 {
+	xen_arch_hvm_post_suspend(cancelled);
 	gnttab_resume();
 }
 
@@ -48,10 +49,12 @@ static void xen_pre_suspend(void)
 {
 	xen_mm_pin_all();
 	gnttab_suspend();
+	xen_arch_pre_suspend();
 }
 
-static void xen_post_suspend(void)
+static void xen_post_suspend(int cancelled)
 {
+	xen_arch_post_suspend(cancelled);
 	gnttab_resume();
 	xen_mm_unpin_all();
 }
@@ -78,8 +81,7 @@ static int xen_hvm_suspend(void *data)
 	 */
 	si->cancelled = HYPERVISOR_suspend(si->arg);
 
-	xen_arch_hvm_post_suspend(si->cancelled);
-	xen_hvm_post_suspend();
+	xen_hvm_post_suspend(si->cancelled);
 
 	if (!si->cancelled) {
 		xen_irq_resume();
@@ -107,7 +109,6 @@ static int xen_suspend(void *data)
 	}
 
 	xen_pre_suspend();
-	xen_arch_pre_suspend();
 
 	/*
 	 * This hypercall returns 1 if suspend was cancelled
@@ -116,8 +117,7 @@ static int xen_suspend(void *data)
 	 */
 	si->cancelled = HYPERVISOR_suspend(si->arg);
 
-	xen_arch_post_suspend(si->cancelled);
-	xen_post_suspend();
+	xen_post_suspend(si->cancelled);
 
 	if (!si->cancelled) {
 		xen_irq_resume();
Signature · 1 line
1.5.6.5
#16 lore raw

PATCH 10/11 xen: suspend: pull pre/post suspend hooks out into suspend_info

In reply to Ian Campbell
---
 drivers/xen/manage.c |   23 ++++++++++++++++++-----
 1 files changed, 18 insertions(+), 5 deletions(-)
drivers/xen/manage.c +18 -5
index 49a7458..5ccddab 100644
@@ -37,6 +37,8 @@ static enum shutdown_state shutting_down = SHUTDOWN_INVALID;
 struct suspend_info {
 	int cancelled;
 	unsigned long arg; /* extra hypercall argument */
+	void (*pre)(void);
+	void (*post)(int cancelled);
 };
 
 static void xen_hvm_post_suspend(int cancelled)
@@ -74,6 +76,9 @@ static int xen_hvm_suspend(void *data)
 		return err;
 	}
 
+	if (si->pre)
+		si->pre();
+
 	/*
 	 * This hypercall returns 1 if suspend was cancelled
 	 * or the domain was merely checkpointed, and 0 if it
@@ -81,7 +86,8 @@ static int xen_hvm_suspend(void *data)
 	 */
 	si->cancelled = HYPERVISOR_suspend(si->arg);
 
-	xen_hvm_post_suspend(si->cancelled);
+	if (si->post)
+		si->post(si->cancelled);
 
 	if (!si->cancelled) {
 		xen_irq_resume();
@@ -108,7 +114,8 @@ static int xen_suspend(void *data)
 		return err;
 	}
 
-	xen_pre_suspend();
+	if (si->pre)
+		si->pre();
 
 	/*
 	 * This hypercall returns 1 if suspend was cancelled
@@ -117,7 +124,8 @@ static int xen_suspend(void *data)
 	 */
 	si->cancelled = HYPERVISOR_suspend(si->arg);
 
-	xen_post_suspend(si->cancelled);
+	if (si->post)
+		si->post(si->cancelled);
 
 	if (!si->cancelled) {
 		xen_irq_resume();
@@ -165,10 +173,15 @@ static void do_suspend(void)
 
 	si.cancelled = 1;
 
-	if (xen_hvm_domain())
+	if (xen_hvm_domain()) {
 		si.arg = 0UL;
-	else
+		si.pre = NULL;
+		si.post = &xen_hvm_post_suspend;
+	} else {
 		si.arg = virt_to_mfn(xen_start_info);
+		si.pre = &xen_pre_suspend;
+		si.post = &xen_post_suspend;
+	}
 
 	if (xen_hvm_domain())
 		err = stop_machine(xen_hvm_suspend, &si, cpumask_of(0));
Signature · 1 line
1.5.6.5
#17 lore raw

PATCH 11/11 xen: suspend: remove xen_hvm_suspend

In reply to Ian Campbell

It is now identical to xen_suspend, the differences are encapsulated in the suspend_info struct.

---
 drivers/xen/manage.c |   43 +------------------------------------------
 1 files changed, 1 insertions(+), 42 deletions(-)
drivers/xen/manage.c +1 -42
index 5ccddab..c255ed4 100644
@@ -62,44 +62,6 @@ static void xen_post_suspend(int cancelled)
 }
 
 #ifdef CONFIG_PM_SLEEP
-static int xen_hvm_suspend(void *data)
-{
-	struct suspend_info *si = data;
-	int err;
-
-	BUG_ON(!irqs_disabled());
-
-	err = sysdev_suspend(PMSG_SUSPEND);
-	if (err) {
-		printk(KERN_ERR "xen_hvm_suspend: sysdev_suspend failed: %d\n",
-		       err);
-		return err;
-	}
-
-	if (si->pre)
-		si->pre();
-
-	/*
-	 * This hypercall returns 1 if suspend was cancelled
-	 * or the domain was merely checkpointed, and 0 if it
-	 * is resuming in a new domain.
-	 */
-	si->cancelled = HYPERVISOR_suspend(si->arg);
-
-	if (si->post)
-		si->post(si->cancelled);
-
-	if (!si->cancelled) {
-		xen_irq_resume();
-		xen_console_resume();
-		xen_timer_resume();
-	}
-
-	sysdev_resume();
-
-	return 0;
-}
-
 static int xen_suspend(void *data)
 {
 	struct suspend_info *si = data;
@@ -183,10 +145,7 @@ static void do_suspend(void)
 		si.post = &xen_post_suspend;
 	}
 
-	if (xen_hvm_domain())
-		err = stop_machine(xen_hvm_suspend, &si, cpumask_of(0));
-	else
-		err = stop_machine(xen_suspend, &si, cpumask_of(0));
+	err = stop_machine(xen_suspend, &si, cpumask_of(0));
 
 	dpm_resume_noirq(PMSG_RESUME);
 
Signature · 1 line
1.5.6.5
#18 lore raw

Re: [PATCH 0/11] suspend cleanups, refactoring and fixes (Was: Re: [PATCH] xen: suspend and resume system devices when running PVHVM)

In reply to Ian Campbell
Quoted 10 lines · Ian Campbell
Quoted 2 lines · Stefano Stabellini

I am going to import it in the pvhvm branch I am preparing for the next merge window.

Is there any conflict with the following series (which builds on this patch)? It's not all pvhvm related but the bulk is the removal of the separate xen_hvm_suspend function.

Do you want to carry these in your branch for the next merge window or shall I create a separate branch?

They all seem very reasonable, I don't mind having them in my branch.

#19 lore raw

Re: [PATCH 0/11] suspend cleanups, refactoring and fixes (Was: Re: [PATCH] xen: suspend and resume system devices when running PVHVM)

Quoted 5 lines · Stefano Stabellini
Quoted 4 lines · Ian Campbell
Quoted 2 lines · Stefano Stabellini

I am going to import it in the pvhvm branch I am preparing for the next merge window.

Quoted 8 lines
Quoted 6 lines

Is there any conflict with the following series (which builds on this patch)? It's not all pvhvm related but the bulk is the removal of the separate xen_hvm_suspend function.

Do you want to carry these in your branch for the next merge window or shall I create a separate branch?

They all seem very reasonable, I don't mind having them in my branch.

Thanks.

I resent the precursor patch to Linus as a git pull request. The following includes that one commit followed by this series.

The following changes since commit 100b33c8bd8a3235fd0b7948338d6cbb3db3c63d:
Linus Torvalds (1):

        Linux 2.6.38-rc4

are available in the git repository at:

git://xenbits.xen.org/people/ianc/linux-2.6.git for-stefano/pvhvm

Ian Campbell (12):
xen: suspend and resume system devices when running PVHVM
xen: do not respond to unknown xenstore control requests
xen: use new schedop interface for suspend
xen: switch to new schedop hypercall by default.
xen: suspend: use HYPERVISOR_suspend for PVHVM case instead of open coding
xen: suspend: refactor cancellation flag into a structure
xen: suspend: pass extra hypercall argument via suspend_info struct
xen: suspend: add "arch" to pre/post suspend hooks
xen: suspend: refactor non-arch specific pre/post suspend hooks
xen: suspend: move arch specific pre/post suspend hooks into generic hooks
xen: suspend: pull pre/post suspend hooks out into suspend_info
xen: suspend: remove xen_hvm_suspend

 arch/ia64/xen/suspend.c              |    9 +--
 arch/x86/include/asm/xen/hypercall.h |   15 +++-
 arch/x86/xen/suspend.c               |    6 +-
 drivers/xen/manage.c                 |  126 ++++++++++++++++++++++------------
 include/xen/interface/xen.h          |    4 +-
 include/xen/xen-ops.h                |    6 +-
 6 files changed, 103 insertions(+), 63 deletions(-)
#20 lore raw

Re: [PATCH 0/11] suspend cleanups, refactoring and fixes (Was: Re: [PATCH] xen: suspend and resume system devices when running PVHVM)

Quoted 13 lines · Ian Campbell
Quoted 12 lines · Stefano Stabellini
Quoted 10 lines · Ian Campbell
Quoted 2 lines · Stefano Stabellini

I am going to import it in the pvhvm branch I am preparing for the next merge window.

Is there any conflict with the following series (which builds on this patch)? It's not all pvhvm related but the bulk is the removal of the separate xen_hvm_suspend function.

Do you want to carry these in your branch for the next merge window or shall I create a separate branch?

Quoted 7 lines
Quoted 1 line

They all seem very reasonable, I don't mind having them in my branch.

Thanks.

I resent the precursor patch to Linus as a git pull request. The following includes that one commit followed by this series.

I merged it into the branch 2.6.38-rc5-pvhvm

Reviewed-by on the v1 series
#21 lore raw

Re: [PATCH 0/11] suspend cleanups, refactoring and fixes (Was: Re: [PATCH] xen: suspend and resume system devices when running PVHVM)

In reply to Ian Campbell
Quoted 10 lines · Ian Campbell
Quoted 2 lines · Stefano Stabellini

I am going to import it in the pvhvm branch I am preparing for the next merge window.

Is there any conflict with the following series (which builds on this patch)? It's not all pvhvm related but the bulk is the removal of the separate xen_hvm_suspend function.

Do you want to carry these in your branch for the next merge window or shall I create a separate branch?

#22 lore raw
In reply to Ian Campbell
Quoted 17 lines · Ian Campbell

Otherwise we fail to properly suspend/resume all of the emulated devices.

Something between 2.6.38-rc2 and rc3 appears to have exposed this issue, but it's always been wrong not to do this.

Cc Stefano Stabellini <[email protected]>
Cc Jeremy Fitzhardinge <[email protected]>

---
 drivers/xen/manage.c |   10 ++++++++++

 1 files changed, 10 insertions(+), 0 deletions(-)
drivers/xen/manage.c +0 -0
index db8c4c4..2417727 100644

drivers/xen/manage.c static enum shutdown_state shutting_down = SHUTDOWN_INVALID; · line 46

Quoted 10 lines
drivers/xen/manage.c +2 -0
@@ -37,11 +37,19 @@ static enum shutdown_state shutting_down = SHUTDOWN_INVALID;
  #ifdef CONFIG_PM_SLEEP
  static int xen_hvm_suspend(void *data)
  {
+       int err;
        struct sched_shutdown r = { .reason = SHUTDOWN_suspend };
        int *cancelled = data;
 
        BUG_ON(!irqs_disabled());
 
+       err = sysdev_suspend(PMSG_SUSPEND);

Shouldnt this be PMSG_FREEZE ? based on the recent discussion with linux-pm folks and the issue of xm save -c resulting in guest hangup.

Quoted 27 lines
drivers/xen/manage.c +8 -1
+       if (err) {
+               printk(KERN_ERR "xen_hvm_suspend: sysdev_suspend failed: %d\n",
+                      err);
+               return err;
+       }
+
        *cancelled = HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
 
        xen_hvm_post_suspend(*cancelled);
@@ -53,6 +61,8 @@ static int xen_hvm_suspend(void *data)
                xen_timer_resume();
        }
 
+       sysdev_resume();
+
        return 0;
  }
 
--

1.5.6.5

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#23 lore raw
Quoted 25 lines · Shriram Rajagopalan
Quoted 24 lines · Ian Campbell

Otherwise we fail to properly suspend/resume all of the emulated devices.

Something between 2.6.38-rc2 and rc3 appears to have exposed this issue, but it's always been wrong not to do this.

Cc Stefano Stabellini <[email protected]>
Cc Jeremy Fitzhardinge <[email protected]>
---
 drivers/xen/manage.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
drivers/xen/manage.c +1 -0
index db8c4c4..2417727 100644
@@ -37,11 +37,19 @@ static enum shutdown_state shutting_down = SHUTDOWN_INVALID;
 #ifdef CONFIG_PM_SLEEP
 static int xen_hvm_suspend(void *data)
 {
+       int err;
       struct sched_shutdown r = { .reason = SHUTDOWN_suspend };
       int *cancelled = data;
 
Quoted 6 lines

drivers/xen/manage.c static enum shutdown_state shutting_down = SHUTDOWN_INVALID; · line 46

Quoted 3 lines
drivers/xen/manage.c +1 -0
       BUG_ON(!irqs_disabled());
 
+       err = sysdev_suspend(PMSG_SUSPEND);

Shouldnt this be PMSG_FREEZE ? based on the recent discussion with linux-pm folks and the issue of xm save -c resulting in guest hangup.

After your patch goes upstream, yes I think it should be, however until then PMSG_SUSPEND is consistent with the rest of the code.

Ian.

Quoted 27 lines
Quoted 27 lines
drivers/xen/manage.c +8 -1
+       if (err) {
+               printk(KERN_ERR "xen_hvm_suspend: sysdev_suspend failed: %d\n",
+                      err);
+               return err;
+       }
+
       *cancelled = HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
 
       xen_hvm_post_suspend(*cancelled);
@@ -53,6 +61,8 @@ static int xen_hvm_suspend(void *data)
               xen_timer_resume();
       }
 
+       sysdev_resume();
+
       return 0;
 }
 
--

1.5.6.5

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel