Skip to contentSkip to conversation

arm, arm64/xen: preliminary suspend support

PATCH In review David Vrabel 3 participants 6 messages May 8, 2014 – May 12, 2014

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

cover arm, arm64/xen: preliminary suspend support

Introduce the necessary infrastructure to allow the suspend to build for the arm and arm64 architectures.

The first patch refactors Xen's suspend code to allow support for new architectures to be added. The second adds HYPERVISOR_suspend and empty stubs for the arch specific calls.

David

#1 lore raw

PATCH 1/2 xen: refactor suspend pre/post hooks

New architectures currently have to provide implementations of 5 different
functions: xen_arch_pre_suspend(), xen_arch_post_suspend(), xen_arch_hvm_post_suspend(), xen_mm_pin_all(), and xen_mm_unpin_all().

Refactor the suspend code to only require xen_arch_pre_suspend() and xen_arch_post_suspend().

---
 arch/x86/xen/suspend.c |   23 ++++++++++++++++++++---
 arch/x86/xen/xen-ops.h |    2 ++
 drivers/xen/manage.c   |   45 +++++++--------------------------------------
 include/xen/xen-ops.h  |    4 ----
 4 files changed, 29 insertions(+), 45 deletions(-)
arch/x86/xen/suspend.c +20 -3
index 45329c8..c4df9db 100644
@@ -12,8 +12,10 @@
 #include "xen-ops.h"
 #include "mmu.h"
 
-void xen_arch_pre_suspend(void)
+static void xen_pv_pre_suspend(void)
 {
+	xen_mm_pin_all();
+
 	xen_start_info->store_mfn = mfn_to_pfn(xen_start_info->store_mfn);
 	xen_start_info->console.domU.mfn =
 		mfn_to_pfn(xen_start_info->console.domU.mfn);
@@ -26,7 +28,7 @@ void xen_arch_pre_suspend(void)
 		BUG();
 }
 
-void xen_arch_hvm_post_suspend(int suspend_cancelled)
+static void xen_hvm_post_suspend(int suspend_cancelled)
 {
 #ifdef CONFIG_XEN_PVHVM
 	int cpu;
@@ -41,7 +43,7 @@ void xen_arch_hvm_post_suspend(int suspend_cancelled)
 #endif
 }
 
-void xen_arch_post_suspend(int suspend_cancelled)
+static void xen_pv_post_suspend(int suspend_cancelled)
 {
 	xen_build_mfn_list_list();
 
@@ -60,6 +62,21 @@ void xen_arch_post_suspend(int suspend_cancelled)
 		xen_vcpu_restore();
 	}
 
+	xen_mm_unpin_all();
+}
+
+void xen_arch_pre_suspend(void)
+{
+    if (xen_pv_domain())
+        xen_pv_pre_suspend();
+}
+
+void xen_arch_post_suspend(int cancelled)
+{
+    if (xen_pv_domain())
+        xen_pv_post_suspend(cancelled);
+    else
+        xen_hvm_post_suspend(cancelled);
 }
 
 static void xen_vcpu_notify_restore(void *data)
arch/x86/xen/xen-ops.h +2 -0
index 1cb6f4c..c834d4b 100644
@@ -31,6 +31,8 @@ void xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn);
 void xen_reserve_top(void);
 extern unsigned long xen_max_p2m_pfn;
 
+void xen_mm_pin_all(void);
+void xen_mm_unpin_all(void);
 void xen_set_pat(u64);
 
 char * __init xen_memory_setup(void);
drivers/xen/manage.c +7 -38

76 lines not on this page · raw message

include/xen/xen-ops.h +0 -4
index 2cf4717..0b3149e 100644
@@ -9,10 +9,6 @@ DECLARE_PER_CPU(struct vcpu_info *, xen_vcpu);
 
 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);
 
 void xen_timer_resume(void);
 void xen_arch_resume(void);
Signature · 1 line
1.7.10.4
#3 lore raw

PATCH 2/2 arm, arm64/xen: introduce HYPERVISOR_suspend

In reply to David Vrabel

From: Stefano Stabellini <[email protected]>

Introduce HYPERVISOR_suspend: it is a call to sched_op with an additional argument that is always 0 on arm and arm64.

Introduce a few additional empty stubs for Xen arch specific functions called by drivers/xen/manage.c.

---
 arch/arm/include/asm/xen/hypercall.h |   10 ++++++++++
 arch/arm/xen/enlighten.c             |    9 +++++++++
 arch/arm/xen/hypercall.S             |    6 ++++++
 arch/arm64/xen/hypercall.S           |    6 ++++++
 4 files changed, 31 insertions(+)
arch/arm/include/asm/xen/hypercall.h +10 -0
index 7704e28..24135be 100644
@@ -48,6 +48,16 @@ int HYPERVISOR_memory_op(unsigned int cmd, void *arg);
 int HYPERVISOR_physdev_op(int cmd, void *arg);
 int HYPERVISOR_vcpu_op(int cmd, int vcpuid, void *extra_args);
 int HYPERVISOR_tmem_op(void *arg);
+int HYPERVISOR_sched_op_shutdown(int cmd, void *arg, unsigned long unused);
+
+static inline int
+HYPERVISOR_suspend(unsigned long start_info_mfn)
+{
+	struct sched_shutdown r = { .reason = SHUTDOWN_suspend };
+
+	/* start_info_mfn is unused on ARM, pass 0 instead */
+	return HYPERVISOR_sched_op_shutdown(SCHEDOP_shutdown, &r, 0);
+}
 
 static inline void
 MULTI_update_va_mapping(struct multicall_entry *mcl, unsigned long va,
arch/arm/xen/enlighten.c +9 -0
index b96723e..7f01565 100644
@@ -339,6 +339,14 @@ static int __init xen_pm_init(void)
 }
 late_initcall(xen_pm_init);
 
+
+/* empty stubs */
+void xen_arch_pre_suspend(void) { }
+void xen_arch_post_suspend(int suspend_cancelled) { }
+void xen_timer_resume(void) { }
+void xen_arch_resume(void) { }
+
+
 /* In the hypervisor.S file. */
 EXPORT_SYMBOL_GPL(HYPERVISOR_event_channel_op);
 EXPORT_SYMBOL_GPL(HYPERVISOR_grant_table_op);
@@ -351,3 +359,4 @@ EXPORT_SYMBOL_GPL(HYPERVISOR_physdev_op);
 EXPORT_SYMBOL_GPL(HYPERVISOR_vcpu_op);
 EXPORT_SYMBOL_GPL(HYPERVISOR_tmem_op);
 EXPORT_SYMBOL_GPL(privcmd_call);
+EXPORT_SYMBOL_GPL(HYPERVISOR_sched_op_shutdown);
arch/arm/xen/hypercall.S +6 -0
index d1cf7b7..7da8837 100644
@@ -102,3 +102,9 @@ ENTRY(privcmd_call)
 	ldm sp!, {r4}
 	mov pc, lr
 ENDPROC(privcmd_call);
+
+ENTRY(HYPERVISOR_sched_op_shutdown)
+	mov r12, #__HYPERVISOR_sched_op
+	__HVC(XEN_IMM)
+	mov pc, lr
+ENDPROC(HYPERVISOR_sched_op_shutdown)
arch/arm64/xen/hypercall.S +6 -0
index 531342e..aa51678 100644
@@ -91,3 +91,9 @@ ENTRY(privcmd_call)
 	hvc XEN_IMM
 	ret
 ENDPROC(privcmd_call);
+
+ENTRY(HYPERVISOR_sched_op_shutdown)
+	mov x16, #__HYPERVISOR_sched_op
+	hvc XEN_IMM
+	ret
+ENDPROC(HYPERVISOR_sched_op_shutdown)
Signature · 1 line
1.7.10.4
reviewer Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] xen: refactor suspend pre/post hooks

In reply to David Vrabel
Quoted 8 lines · David Vrabel

New architectures currently have to provide implementations of 5 different
functions: xen_arch_pre_suspend(), xen_arch_post_suspend(), xen_arch_hvm_post_suspend(), xen_mm_pin_all(), and xen_mm_unpin_all().

Refactor the suspend code to only require xen_arch_pre_suspend() and xen_arch_post_suspend().

Quoted 175 lines
---
  arch/x86/xen/suspend.c |   23 ++++++++++++++++++++---
  arch/x86/xen/xen-ops.h |    2 ++
  drivers/xen/manage.c   |   45 +++++++--------------------------------------
  include/xen/xen-ops.h  |    4 ----
  4 files changed, 29 insertions(+), 45 deletions(-)
arch/x86/xen/suspend.c +20 -3
index 45329c8..c4df9db 100644
@@ -12,8 +12,10 @@
  #include "xen-ops.h"
  #include "mmu.h"
 
-void xen_arch_pre_suspend(void)
+static void xen_pv_pre_suspend(void)
  {
+	xen_mm_pin_all();
+
  	xen_start_info->store_mfn = mfn_to_pfn(xen_start_info->store_mfn);
  	xen_start_info->console.domU.mfn =
  		mfn_to_pfn(xen_start_info->console.domU.mfn);
@@ -26,7 +28,7 @@ void xen_arch_pre_suspend(void)
  		BUG();
  }
 
-void xen_arch_hvm_post_suspend(int suspend_cancelled)
+static void xen_hvm_post_suspend(int suspend_cancelled)
  {
  #ifdef CONFIG_XEN_PVHVM
  	int cpu;
@@ -41,7 +43,7 @@ void xen_arch_hvm_post_suspend(int suspend_cancelled)
  #endif
  }
 
-void xen_arch_post_suspend(int suspend_cancelled)
+static void xen_pv_post_suspend(int suspend_cancelled)
  {
  	xen_build_mfn_list_list();
 
@@ -60,6 +62,21 @@ void xen_arch_post_suspend(int suspend_cancelled)
  		xen_vcpu_restore();
  	}
 
+	xen_mm_unpin_all();
+}
+
+void xen_arch_pre_suspend(void)
+{
+    if (xen_pv_domain())
+        xen_pv_pre_suspend();
+}
+
+void xen_arch_post_suspend(int cancelled)
+{
+    if (xen_pv_domain())
+        xen_pv_post_suspend(cancelled);
+    else
+        xen_hvm_post_suspend(cancelled);
  }
 
  static void xen_vcpu_notify_restore(void *data)
arch/x86/xen/xen-ops.h +2 -0
index 1cb6f4c..c834d4b 100644
@@ -31,6 +31,8 @@ void xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn);
  void xen_reserve_top(void);
  extern unsigned long xen_max_p2m_pfn;
 
+void xen_mm_pin_all(void);
+void xen_mm_unpin_all(void);
  void xen_set_pat(u64);
 
  char * __init xen_memory_setup(void);
drivers/xen/manage.c +7 -38
index 32f9236..c3667b2 100644
@@ -41,9 +41,6 @@ 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 RAW_NOTIFIER_HEAD(xen_resume_notifier);
@@ -61,26 +58,6 @@ void xen_resume_notifier_unregister(struct notifier_block *nb)
  EXPORT_SYMBOL_GPL(xen_resume_notifier_unregister);
 
  #ifdef CONFIG_HIBERNATE_CALLBACKS
-static void xen_hvm_post_suspend(int cancelled)
-{
-	xen_arch_hvm_post_suspend(cancelled);
-	gnttab_resume();
-}
-
-static void xen_pre_suspend(void)
-{
-	xen_mm_pin_all();
-	gnttab_suspend();
-	xen_arch_pre_suspend();
-}
-
-static void xen_post_suspend(int cancelled)
-{
-	xen_arch_post_suspend(cancelled);
-	gnttab_resume();
-	xen_mm_unpin_all();
-}
-
  static int xen_suspend(void *data)
  {
  	struct suspend_info *si = data;
@@ -94,18 +71,20 @@ static int xen_suspend(void *data)
  		return err;
  	}
 
-	if (si->pre)
-		si->pre();
+	gnttab_suspend();
+	xen_arch_pre_suspend();
 
  	/*
  	 * 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);
+	si->cancelled = HYPERVISOR_suspend(xen_pv_domain()
+                                           ? virt_to_mfn(xen_start_info)
+                                           : 0);
 
-	if (si->post)
-		si->post(si->cancelled);
+	xen_arch_post_suspend(si->cancelled);
+	gnttab_resume();
 
  	if (!si->cancelled) {
  		xen_irq_resume();
@@ -154,16 +133,6 @@ static void do_suspend(void)
 
  	si.cancelled = 1;
 
-	if (xen_hvm_domain()) {
-		si.arg = 0UL;
-		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;
-	}
-
  	err = stop_machine(xen_suspend, &si, cpumask_of(0));
 
  	raw_notifier_call_chain(&xen_resume_notifier, 0, NULL);
include/xen/xen-ops.h +0 -4
index 2cf4717..0b3149e 100644
@@ -9,10 +9,6 @@ DECLARE_PER_CPU(struct vcpu_info *, xen_vcpu);
 
  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);
 
  void xen_timer_resume(void);
  void xen_arch_resume(void);
#4 lore raw

Re: [PATCH 2/2] arm, arm64/xen: introduce HYPERVISOR_suspend

In reply to David Vrabel
Quoted 4 lines · David Vrabel

From: Stefano Stabellini <[email protected]>

Introduce HYPERVISOR_suspend: it is a call to sched_op with an additional argument that is always 0 on arm and arm64.

Given that the third argument is not actually mandatory, we can have a simpler arm side patch:

---

arm,arm64/xen: introduce HYPERVISOR_suspend

Introduce HYPERVISOR_suspend.
Also introduce a few additional empty stubs for Xen arch specific functions called by drivers/xen/manage.c.

arch/arm/include/asm/xen/hypercall.h +10 -0
index 7658150..712b50e 100644
@@ -34,6 +34,7 @@
 #define _ASM_ARM_XEN_HYPERCALL_H
 
 #include <xen/interface/xen.h>
+#include <xen/interface/sched.h>
 
 long privcmd_call(unsigned call, unsigned long a1,
 		unsigned long a2, unsigned long a3,
@@ -50,6 +51,15 @@ int HYPERVISOR_vcpu_op(int cmd, int vcpuid, void *extra_args);
 int HYPERVISOR_tmem_op(void *arg);
 int HYPERVISOR_multicall(struct multicall_entry *calls, uint32_t nr);
 
+static inline int
+HYPERVISOR_suspend(unsigned long start_info_mfn)
+{
+	struct sched_shutdown r = { .reason = SHUTDOWN_suspend };
+
+	/* start_info_mfn is unused on ARM */
+	return HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
+}
+
 static inline void
 MULTI_update_va_mapping(struct multicall_entry *mcl, unsigned long va,
 			unsigned int new_val, unsigned long flags)
arch/arm/xen/enlighten.c +8 -0
index b96723e..1a7087b 100644
@@ -339,6 +339,14 @@ static int __init xen_pm_init(void)
 }
 late_initcall(xen_pm_init);
 
+
+/* empty stubs */
+void xen_arch_pre_suspend(void) { }
+void xen_arch_post_suspend(int suspend_cancelled) { }
+void xen_timer_resume(void) { }
+void xen_arch_resume(void) { }
+
+
 /* In the hypervisor.S file. */
 EXPORT_SYMBOL_GPL(HYPERVISOR_event_channel_op);
 EXPORT_SYMBOL_GPL(HYPERVISOR_grant_table_op);
author Applied
#5 lore raw

Re: [PATCH 2/2] arm, arm64/xen: introduce HYPERVISOR_suspend

Quoted 8 lines · Stefano Stabellini
Quoted 4 lines · David Vrabel

From: Stefano Stabellini <[email protected]>

Introduce HYPERVISOR_suspend: it is a call to sched_op with an additional argument that is always 0 on arm and arm64.

Given that the third argument is not actually mandatory, we can have a simpler arm side patch:

Thanks.

Applied to devel/for-linus-3.16

David