Skip to contentSkip to conversation

Save/Restore Support for mini-OS PVH

PATCH In review Bruno Alvisio 2 participants 20 messages Feb 14, 2018

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

v2 cover Save/Restore Support for mini-OS PVH

Hi all,

I am sending the second revision for supporting save/restore in Mini-OS PVH. The branch can be found at:

https://github.com/balvisio/mini-os/tree/feature/mini-os-suspend-support-submission-2

Feedback would be greatly appreciated.

Cheers,

Bruno

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#1 lore raw

PATCH v2 1/16 Save/Restore Support: Refactor HYPERVISOR_suspend hypercall

Directly using the SHUTDOWN_suspend macro as a parameter for the schedop hypercall causes an error in the Xen hypercall handler. Also for consistency, the SHUTDOWN_suspend param is wrapped in the sched_shutdown struct.

---
 include/x86/x86_32/hypercall-x86_32.h | 4 ++--
 include/x86/x86_64/hypercall-x86_64.h | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
include/x86/x86_32/hypercall-x86_32.h +2 -2
index 5c93464..70505a4 100644
@@ -298,8 +298,8 @@ static inline int
 HYPERVISOR_suspend(
 	unsigned long srec)
 {
-	return _hypercall3(int, sched_op, SCHEDOP_shutdown,
-			   SHUTDOWN_suspend, srec);
+	struct sched_shutdown shutdown = { .reason = SHUTDOWN_suspend };
+	return _hypercall3(int, sched_op, SCHEDOP_shutdown, &shutdown, srec);
 }
 
 static inline int
include/x86/x86_64/hypercall-x86_64.h +2 -2
index 6171812..95f8ade 100644
@@ -305,8 +305,8 @@ static inline int
 HYPERVISOR_suspend(
 	unsigned long srec)
 {
-	return _hypercall3(int, sched_op, SCHEDOP_shutdown,
-			   SHUTDOWN_suspend, srec);
+	struct sched_shutdown shutdown = { .reason = SHUTDOWN_suspend };
+	return _hypercall3(int, sched_op, SCHEDOP_shutdown, &shutdown, srec);
 }
 
 static inline int
Signature · 7 lines
2.3.2 (Apple Git-55)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#2 lore raw

PATCH v2 2/16 Save/Restore Support: Refactor trap_init() and setup vector callbacks

In reply to Bruno Alvisio

Currently the setup of the IDT and the request to set the HVM vector callbacks are performed both in the trap_init function.

As part of the post-suspend operation, the HVM vector callback needs to be setup again while the IDT does not. Thus, the trap_init function is split into two separate functions: trap_init (sets up IDT) and xen_callback_vector (sets the HVM vector callback). During the post-suspend operations the xen_callback_vector function will be invoked.

---
 arch/x86/traps.c | 17 +++++++++++------
 include/x86/os.h |  3 +++
 2 files changed, 14 insertions(+), 6 deletions(-)
arch/x86/traps.c +11 -6
index aa17da3..a7388a5 100644
@@ -389,6 +389,16 @@ static void setup_gate(unsigned int entry, void *addr, unsigned int dpl)
 #endif
 }
 
+void xen_callback_vector(void)
+{
+    if (hvm_set_parameter(HVM_PARAM_CALLBACK_IRQ,
+                         (2ULL << 56) | TRAP_xen_callback))
+    {
+        xprintk("Request for Xen HVM callback vector failed\n");
+        do_exit();
+    }
+}
+
 void trap_init(void)
 {
     setup_gate(TRAP_divide_error, &divide_error, 0);
@@ -415,12 +425,7 @@ void trap_init(void)
     gdt[GDTE_TSS] = (typeof(*gdt))INIT_GDTE((unsigned long)&tss, 0x67, 0x89);
     asm volatile ("ltr %w0" :: "rm" (GDTE_TSS * 8));
 
-    if ( hvm_set_parameter(HVM_PARAM_CALLBACK_IRQ,
-                           (2ULL << 56) | TRAP_xen_callback) )
-    {
-        xprintk("Request for Xen HVM callback vector failed\n");
-        do_exit();
-    }
+    xen_callback_vector();
 }
 
 void trap_fini(void)
include/x86/os.h +3 -0
index fbc2eeb..d155914 100644
@@ -67,6 +67,9 @@ extern shared_info_t *HYPERVISOR_shared_info;
 
 void trap_init(void);
 void trap_fini(void);
+#ifndef CONFIG_PARAVIRT
+void xen_callback_vector(void);
+#endif
 
 void arch_fini(void);
 
Signature · 7 lines
2.3.2 (Apple Git-55)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#3 lore raw

PATCH v2 3/16 Save/Restore Support: Declare kernel and arch pre/post suspend functions

In reply to Bruno Alvisio

For mini-OS to support suspend and restore, the kernel will have to suspend different modules such as xenbus, console, irq, etc. During save/restore the kernel and arch pre_suspend and post_suspend functions will be invoked to suspend/resume each of the modules.

---
 arch/x86/setup.c | 10 ++++++++++
 include/kernel.h |  2 ++
 include/x86/os.h |  4 ++--
 kernel.c         | 10 ++++++++++
 4 files changed, 24 insertions(+), 2 deletions(-)
arch/x86/setup.c +10 -0
index 5278227..3dd86f9 100644
@@ -204,6 +204,16 @@ arch_init(void *par)
 	start_kernel();
 }
 
+void arch_pre_suspend(void)
+{
+
+}
+
+void arch_post_suspend(int canceled)
+{
+
+}
+
 void
 arch_fini(void)
 {
include/kernel.h +2 -0
index d37ddda..161d757 100644
@@ -5,6 +5,8 @@
 extern char cmdline[MAX_CMDLINE_SIZE];
 
 void start_kernel(void);
+void pre_suspend(void);
+void post_suspend(int canceled);
 void do_exit(void) __attribute__((noreturn));
 void arch_do_exit(void);
 void stop_kernel(void);
include/x86/os.h +2 -2
index d155914..a73b63e 100644
@@ -71,10 +71,10 @@ void trap_fini(void);
 void xen_callback_vector(void);
 #endif
 
+void arch_pre_suspend(void);
+void arch_post_suspend(int canceled);
 void arch_fini(void);
 
-
-
 #ifdef CONFIG_PARAVIRT
 
 /* 
kernel.c +10 -0
index 0d84a9b..90c865a 100644
@@ -155,6 +155,16 @@ void start_kernel(void)
     run_idle_thread();
 }
 
+void pre_suspend(void)
+{
+
+}
+
+void post_suspend(int canceled)
+{
+
+}
+
 void stop_kernel(void)
 {
     /* TODO: fs import */
Signature · 7 lines
2.3.2 (Apple Git-55)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#4 lore raw

PATCH v2 4/16 Save/Restore Support: Add xenbus_release_wait_for_watch

In reply to Bruno Alvisio

xenbus_release_wait_for_watch generates a fake event to trigger make xenbus_wait_for_watch return. This is necessary to wake up waiting threads.

release_xenbus_id additionally checks if the number of requests == 0 to wake up the 'waiting' suspend xenbus thread.

---
Changed since v1:
* Added doc for change in release_xenbus_id

---
 include/xenbus.h |  1 +
 xenbus/xenbus.c  | 10 +++++++++-
 2 files changed, 10 insertions(+), 1 deletion(-)
include/xenbus.h +1 -0
index 12391b9..b2d5072 100644
@@ -42,6 +42,7 @@ char *xenbus_unwatch_path_token(xenbus_transaction_t xbt, const char *path, cons
 extern struct wait_queue_head xenbus_watch_queue;
 void xenbus_wait_for_watch(xenbus_event_queue *queue);
 char **xenbus_wait_for_watch_return(xenbus_event_queue *queue);
+void xenbus_release_wait_for_watch(xenbus_event_queue *queue);
 char* xenbus_wait_for_value(const char *path, const char *value, xenbus_event_queue *queue);
 char *xenbus_wait_for_state_change(const char* path, XenbusState *state, xenbus_event_queue *queue);
 char *xenbus_switch_state(xenbus_transaction_t xbt, const char* path, XenbusState state);
xenbus/xenbus.c +9 -1
index 636786c..c2d2bd1 100644
@@ -129,6 +129,14 @@ void xenbus_wait_for_watch(xenbus_event_queue *queue)
         printk("unexpected path returned by watch\n");
 }
 
+void xenbus_release_wait_for_watch(xenbus_event_queue *queue)
+{
+    struct xenbus_event *event = malloc(sizeof(*event));
+    event->next = *queue;
+    *queue = event;
+    wake_up(&xenbus_watch_queue);
+}
+
 char* xenbus_wait_for_value(const char* path, const char* value, xenbus_event_queue *queue)
 {
     if (!queue)
@@ -318,7 +326,7 @@ static void release_xenbus_id(int id)
     req_info[id].in_use = 0;
     nr_live_reqs--;
     req_info[id].in_use = 0;
-    if (nr_live_reqs == NR_REQS - 1)
+    if (nr_live_reqs == 0 || nr_live_reqs == NR_REQS - 1)
         wake_up(&req_wq);
     spin_unlock(&req_lock);
 }
Signature · 7 lines
2.3.2 (Apple Git-55)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#5 lore raw

PATCH v2 5/16 Save/Restore Support: Add kernel shutdown logic to shutdown.c

In reply to Bruno Alvisio

Created shutdown.c for the shutdown thread and all the shutdown related functions.

---
Changesd since v1:
* Updated license to a BSD 3-clause. This license was taken
from the updated original file. (Repo: sysml/mini-os)

---
 Makefile           |   1 +
 include/shutdown.h |  11 ++++
 shutdown.c         | 188 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 200 insertions(+)
 create mode 100644 include/shutdown.h
 create mode 100644 shutdown.c
Makefile +1 -0
index 88315c4..6a05de6 100644
@@ -53,6 +53,7 @@ src-y += mm.c
 src-$(CONFIG_NETFRONT) += netfront.c
 src-$(CONFIG_PCIFRONT) += pcifront.c
 src-y += sched.c
+src-y += shutdown.c
 src-$(CONFIG_TEST) += test.c
 src-$(CONFIG_BALLOON) += balloon.c
 
include/shutdown.h new file +11 -0
new file mode 100644
index 0000000..a5ec019
@@ -0,0 +1,11 @@
+#ifndef _SHUTDOWN_H_
+#define _SHUTDOWN_H_
+
+#include <mini-os/hypervisor.h>
+
+void init_shutdown(start_info_t *si);
+
+void kernel_shutdown(int reason) __attribute__((noreturn));
+void kernel_suspend(void);
+
+#endif
shutdown.c new file +188 -0

188 lines not on this page · raw message

Signature · 7 lines
2.3.2 (Apple Git-55)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v2 5/16
#6 lore raw

Re: [PATCH v2 05/16] Save/Restore Support: Add kernel shutdown logic to shutdown.c

Quoted 51 lines · Bruno Alvisio

Created shutdown.c for the shutdown thread and all the shutdown related functions.

---
Changesd since v1:
* Updated license to a BSD 3-clause. This license was taken
from the updated original file. (Repo: sysml/mini-os)

---
 Makefile           |   1 +
 include/shutdown.h |  11 ++++
 shutdown.c         | 188 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 200 insertions(+)
 create mode 100644 include/shutdown.h
 create mode 100644 shutdown.c
Makefile +1 -0
index 88315c4..6a05de6 100644
@@ -53,6 +53,7 @@ src-y += mm.c
 src-$(CONFIG_NETFRONT) += netfront.c
 src-$(CONFIG_PCIFRONT) += pcifront.c
 src-y += sched.c
+src-y += shutdown.c
 src-$(CONFIG_TEST) += test.c
 src-$(CONFIG_BALLOON) += balloon.c
 
include/shutdown.h new file +11 -0
new file mode 100644
index 0000000..a5ec019
@@ -0,0 +1,11 @@
+#ifndef _SHUTDOWN_H_
+#define _SHUTDOWN_H_
+
+#include <mini-os/hypervisor.h>
+
+void init_shutdown(start_info_t *si);
+
+void kernel_shutdown(int reason) __attribute__((noreturn));
+void kernel_suspend(void);
+
+#endif
shutdown.c new file +0 -0
new file mode 100644
index 0000000..aba146e

shutdown.c line 4

Quoted 4 lines
shutdown.c new file +4 -0
@@ -0,0 +1,188 @@
+/*
+ *          MiniOS
+ *
+ *   file: fromdevice.cc

shutdown.c?

Quoted 74 lines
shutdown.c new file +74 -0
+ *
+ * Authors: Joao Martins <[email protected]>
+ *
+ *
+ * Copyright (c) 2014, NEC Europe Ltd., NEC Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
+ */
+
+#include <mini-os/os.h>
+#include <mini-os/events.h>
+#include <mini-os/kernel.h>
+#include <mini-os/sched.h>
+#include <mini-os/shutdown.h>
+#include <mini-os/lib.h>
+#include <mini-os/xenbus.h>
+#include <mini-os/xmalloc.h>
+
+
+static start_info_t *start_info_ptr;
+
+static const char *path = "control/shutdown";
+static const char *token = "control/shutdown";
+static xenbus_event_queue events = NULL;
+static int end_shutdown_thread = 0;
+
+#ifdef CONFIG_XENBUS
+/* This should be overridden by the application we are linked against. */
+__attribute__((weak)) void app_shutdown(unsigned reason)
+{
+    printk("Shutdown requested: %d\n", reason);
+    if (reason == SHUTDOWN_suspend) {
+        kernel_suspend();
+    } else {
+        struct sched_shutdown sched_shutdown = { .reason = reason };
+        HYPERVISOR_sched_op(SCHEDOP_shutdown, &sched_shutdown);
+    }
+}
+
+static void shutdown_thread(void *p)
+{
+    char *shutdown, *err;
+    unsigned int shutdown_reason;
+
+    xenbus_watch_path_token(XBT_NIL, path, token, &events);
+
+    for ( ;; ) {
+        xenbus_wait_for_watch(&events);
+        if ((err = xenbus_read(XBT_NIL, path, &shutdown))) {

shutdown.c line 88

Quoted 10 lines
shutdown.c new file +10 -0
+            free(err);
+            do_exit();
+        }
+
+        if (end_shutdown_thread)
+            break;
+
+        if (!strcmp(shutdown, "")) {
+            /* Avoid spurious event on xenbus */
+            /* FIXME: investigate the reason of the spurious event */

Remove the FIXME, please.

Watches will fire e.g. directly after setting them up once.

With above issues fixed you can add my:

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#7 lore raw

PATCH v2 6/16 Save/Restore Support: Moved shutdown thread to shutdown.c

In reply to Bruno Alvisio

The shutdown thread present in kernel.c was removed and now the thread in shutdown.c is created instead.

---
 arch/x86/setup.c |  2 +-
 include/kernel.h |  2 +-
 kernel.c         | 50 ++++++--------------------------------------------
 3 files changed, 8 insertions(+), 46 deletions(-)
arch/x86/setup.c +1 -1
index 3dd86f9..31fa2c6 100644
@@ -201,7 +201,7 @@ arch_init(void *par)
 	memcpy(&start_info, par, sizeof(start_info));
 #endif
 
-	start_kernel();
+	start_kernel((start_info_t *)par);
 }
 
 void arch_pre_suspend(void)
include/kernel.h +1 -1
index 161d757..742abf5 100644
@@ -4,7 +4,7 @@
 #define MAX_CMDLINE_SIZE 1024
 extern char cmdline[MAX_CMDLINE_SIZE];
 
-void start_kernel(void);
+void start_kernel(void* par);
 void pre_suspend(void);
 void post_suspend(int canceled);
 void do_exit(void) __attribute__((noreturn));
kernel.c +6 -44

74 lines not on this page · raw message

Signature · 7 lines
2.3.2 (Apple Git-55)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#8 lore raw

PATCH v2 7/16 Save/Restore Support: Add unmap_shared_info

In reply to Bruno Alvisio

This function is necessary as part of the pre-suspend operation.

---
Changed since v1:
* Changed HYPERVISOR_shared_info for shared_info

---
 arch/x86/setup.c     | 12 ++++++++++++
 hypervisor.c         | 12 ++++++++++++
 include/hypervisor.h |  1 +
 3 files changed, 25 insertions(+)
arch/x86/setup.c +12 -0
index 31fa2c6..b6e0541 100644
@@ -93,6 +93,18 @@ shared_info_t *map_shared_info(void *p)
     return (shared_info_t *)shared_info;
 }
 
+void unmap_shared_info(void)
+{
+    int rc;
+
+    if ( (rc = HYPERVISOR_update_va_mapping((unsigned long)shared_info,
+            __pte((virt_to_mfn(shared_info)<<L1_PAGETABLE_SHIFT)| L1_PROT), UVMF_INVLPG)) )
+    {
+        printk("Failed to unmap shared_info page!! rc=%d\n", rc);
+        do_exit();
+    }
+}
+
 static void get_cmdline(void *p)
 {
     start_info_t *si = p;
hypervisor.c +12 -0
index 1647121..d3857e7 100644
@@ -78,6 +78,18 @@ shared_info_t *map_shared_info(void *p)
 
     return &shared_info;
 }
+
+void unmap_shared_info(void)
+{
+    struct xen_remove_from_physmap xrtp;
+
+    xrtp.domid = DOMID_SELF;
+    xrtp.gpfn = virt_to_pfn(&shared_info);
+    if ( HYPERVISOR_memory_op(XENMEM_remove_from_physmap, &xrtp) != 0 )
+        BUG();
+
+    return;
+}
 #endif
 
 void do_hypervisor_callback(struct pt_regs *regs)
include/hypervisor.h +1 -0
index f3b1f3c..1d09271 100644
@@ -43,6 +43,7 @@ int hvm_get_parameter(int idx, uint64_t *value);
 int hvm_set_parameter(int idx, uint64_t value);
 #endif
 shared_info_t *map_shared_info(void *p);
+void unmap_shared_info(void);
 void force_evtchn_callback(void);
 void do_hypervisor_callback(struct pt_regs *regs);
 void mask_evtchn(uint32_t port);
Signature · 7 lines
2.3.2 (Apple Git-55)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#9 lore raw

PATCH v2 8/16 Save/Restore Support: Add arch_mm_pre|post_suspend

In reply to Bruno Alvisio

For PV guests the pagetables reference the real MFNs rather than PFNs, so when the guest is resumed into a different area of a hosts memory, these will need to be rewritten. Thus for PV guests the MFNs need to be replaced with PFNs:
canonicalization.

PVH guests are auto-translated so no memory operation is needed.

---
 arch/x86/mm.c         | 14 ++++++++++++++
 include/x86/arch_mm.h |  3 +++
 2 files changed, 17 insertions(+)
arch/x86/mm.c +14 -0
index 05ad029..1b163ac 100644
@@ -848,6 +848,20 @@ void arch_init_p2m(unsigned long max_pfn)
 
     arch_remap_p2m(max_pfn);
 }
+
+void arch_mm_pre_suspend(void)
+{
+    //TODO: Canonicalize pagetables
+}
+
+void arch_mm_post_suspend(int canceled)
+{
+    //TODO: Locate pagetables and 'uncanonicalize' them
+}
+#else
+void arch_mm_pre_suspend(void){ }
+
+void arch_mm_post_suspend(int canceled){ }
 #endif
 
 void arch_init_mm(unsigned long* start_pfn_p, unsigned long* max_pfn_p)
include/x86/arch_mm.h +3 -0
index ab8a53e..cbbeb21 100644
@@ -279,6 +279,9 @@ pgentry_t *need_pgt(unsigned long addr);
 void arch_mm_preinit(void *p);
 unsigned long alloc_virt_kernel(unsigned n_pages);
 
+void arch_mm_pre_suspend(void);
+void arch_mm_post_suspend(int canceled);
+
 #ifndef CONFIG_PARAVIRT
 void arch_print_memmap(void);
 #endif
Signature · 7 lines
2.3.2 (Apple Git-55)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#10 lore raw

PATCH v2 9/16 Save/Restore Support: Disable/enable IRQs during suspend/restore

In reply to Bruno Alvisio
---
 kernel.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel.c +2 -2
index 1cd40e8..782eb79 100644
@@ -119,12 +119,12 @@ void start_kernel(void* par)
 
 void pre_suspend(void)
 {
-
+    local_irq_disable();
 }
 
 void post_suspend(int canceled)
 {
-
+    local_irq_enable();
 }
 
 void stop_kernel(void)
Signature · 7 lines
2.3.2 (Apple Git-55)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#11 lore raw

PATCH v2 10/16 Save/Restore Support: Add suspend/resume support for timers

In reply to Bruno Alvisio

---
Changed since v1:
* Removed resume/suspend_time() and used init/fini_time() instead

---
 arch/x86/time.c | 1 -
 kernel.c        | 4 ++++
 2 files changed, 4 insertions(+), 1 deletion(-)
arch/x86/time.c +0 -1
index 3658142..8077c80 100644
@@ -233,7 +233,6 @@ static void timer_handler(evtchn_port_t ev, struct pt_regs *regs, void *ign)
 static evtchn_port_t port;
 void init_time(void)
 {
-    printk("Initialising timer interface\n");
     port = bind_virq(VIRQ_TIMER, &timer_handler, NULL);
     unmask_evtchn(port);
 }
kernel.c +4 -0
index 782eb79..3564af3 100644
@@ -120,10 +120,14 @@ void start_kernel(void* par)
 void pre_suspend(void)
 {
     local_irq_disable();
+
+    fini_time();
 }
 
 void post_suspend(int canceled)
 {
+    init_time();
+
     local_irq_enable();
 }
 
Signature · 7 lines
2.3.2 (Apple Git-55)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#13 lore raw

PATCH v2 11/16 Save/Restore Support: Add suspend/restore support for console

In reply to Bruno Alvisio
---
 console/console.c      | 15 ++++++++-
 console/xenbus.c       |  3 +-
 console/xencons_ring.c | 83 +++++++++++++++++++++++++++++++-------------------
 include/console.h      |  6 +++-
 kernel.c               |  4 +++
 lib/sys.c              |  2 +-
 6 files changed, 77 insertions(+), 36 deletions(-)
console/console.c +14 -1
index 2e04552..9814506 100644
@@ -52,6 +52,7 @@
 
 /* If console not initialised the printk will be sent to xen serial line 
    NOTE: you need to enable verbose in xen/Rules.mk for it to work. */
+static struct consfront_dev* xen_console = NULL;
 static int console_initialised = 0;
 
 __attribute__((weak)) void console_input(char * buf, unsigned len)
@@ -162,8 +163,20 @@ void xprintk(const char *fmt, ...)
 void init_console(void)
 {   
     printk("Initialising console ... ");
-    xencons_ring_init();    
+    xen_console = xencons_ring_init();
     console_initialised = 1;
     /* This is also required to notify the daemon */
     printk("done.\n");
 }
+
+void suspend_console(void)
+{
+    console_initialised = 0;
+    xencons_ring_fini(xen_console);
+}
+
+void resume_console(void)
+{
+    xencons_ring_resume(xen_console);
+    console_initialised = 1;
+}
\ No newline at end of file
console/xenbus.c +1 -2
index 1c9a590..654b469 100644
@@ -188,8 +188,7 @@ error:
     return NULL;
 }
 
-void fini_console(struct consfront_dev *dev)
+void fini_consfront(struct consfront_dev *dev)
 {
     if (dev) free_consfront(dev);
 }
-
console/xencons_ring.c +52 -31

118 lines not on this page · raw message

include/console.h +5 -1
index 539cccd..0d7bf07 100644
@@ -78,11 +78,15 @@ void xencons_tx(void);
 void get_console(void *p);
 void init_console(void);
 void console_print(struct consfront_dev *dev, char *data, int length);
-void fini_console(struct consfront_dev *dev);
+void fini_consfront(struct consfront_dev *dev);
+void suspend_console(void);
+void resume_console(void);
 
 /* Low level functions defined in xencons_ring.c */
 extern struct wait_queue_head console_queue;
 struct consfront_dev *xencons_ring_init(void);
+void xencons_ring_fini(struct consfront_dev* dev);
+void xencons_ring_resume(struct consfront_dev* dev);
 struct consfront_dev *init_consfront(char *_nodename);
 int xencons_ring_send(struct consfront_dev *dev, const char *data, unsigned len);
 int xencons_ring_send_no_notify(struct consfront_dev *dev, const char *data, unsigned len);
kernel.c +4 -0
index 3564af3..2fb69bf 100644
@@ -122,10 +122,14 @@ void pre_suspend(void)
     local_irq_disable();
 
     fini_time();
+
+    suspend_console();
 }
 
 void post_suspend(int canceled)
 {
+    resume_console();
+
     init_time();
 
     local_irq_enable();
lib/sys.c +1 -1
index 23dc2a5..da434fc 100644
@@ -487,7 +487,7 @@ int close(int fd)
 #ifdef CONFIG_CONSFRONT
         case FTYPE_SAVEFILE:
         case FTYPE_CONSOLE:
-            fini_console(files[fd].cons.dev);
+            fini_consfront(files[fd].cons.dev);
             files[fd].type = FTYPE_NONE;
             return 0;
 #endif
Signature · 7 lines
2.3.2 (Apple Git-55)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#14 lore raw

PATCH v2 12/16 Save/Restore Support: Add support for suspend/restore events.

In reply to Bruno Alvisio
---
 events.c         | 5 +++++
 include/events.h | 1 +
 kernel.c         | 2 ++
 3 files changed, 8 insertions(+)
events.c +5 -0
index e8ef8aa..342aead 100644
@@ -183,6 +183,11 @@ void fini_events(void)
     arch_fini_events();
 }
 
+void suspend_events(void)
+{
+    unbind_all_ports();
+}
+
 void default_handler(evtchn_port_t port, struct pt_regs *regs, void *ignore)
 {
     printk("[Port %d] - event received\n", port);
include/events.h +1 -0
index 89b5997..705ad93 100644
@@ -55,5 +55,6 @@ static inline int notify_remote_via_evtchn(evtchn_port_t port)
 }
 
 void fini_events(void);
+void suspend_events(void);
 
 #endif /* _EVENTS_H_ */
kernel.c +2 -0
index 2fb69bf..d078e0a 100644
@@ -124,6 +124,8 @@ void pre_suspend(void)
     fini_time();
 
     suspend_console();
+
+    suspend_events();
 }
 
 void post_suspend(int canceled)
Signature · 7 lines
2.3.2 (Apple Git-55)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#15 lore raw

PATCH v2 13/16 Save/Restore Support: Add suspend/restore support for Grant Tables.

In reply to Bruno Alvisio

---
Changed since v1:
- Moved suspend/resume _gnttab to arch specific files

---
 arch/x86/mm.c    | 34 ++++++++++++++++++++++++++++++++++
 gnttab.c         | 10 ++++++++++
 include/gnttab.h |  4 ++++
 kernel.c         |  4 ++++
 4 files changed, 52 insertions(+)
arch/x86/mm.c +34 -0
index 1b163ac..2597c5b 100644
@@ -917,6 +917,40 @@ grant_entry_v1_t *arch_init_gnttab(int nr_grant_frames)
     return map_frames(frames, nr_grant_frames);
 }
 
+void arch_suspend_gnttab(grant_entry_v1_t *gnttab_table, int nr_grant_frames)
+{
+#ifdef CONFIG_PARAVIRT
+    int i;
+
+    for (i = 0; i < nr_grant_frames; i++) {
+        HYPERVISOR_update_va_mapping((unsigned long)(((char *)gnttab_table) + PAGE_SIZE*i),
+                (pte_t){0x0<<PAGE_SHIFT}, UVMF_INVLPG);
+    }
+#endif
+    return;
+}
+
+void arch_resume_gnttab(grant_entry_v1_t *gnttab_table, int nr_grant_frames)
+{
+    struct gnttab_setup_table setup;
+    unsigned long frames[nr_grant_frames];
+#ifdef CONFIG_PARAVIRT
+    int i;
+#endif
+    setup.dom = DOMID_SELF;
+    setup.nr_frames = nr_grant_frames;
+    set_xen_guest_handle(setup.frame_list, frames);
+
+    HYPERVISOR_grant_table_op(GNTTABOP_setup_table, &setup, 1);
+
+#ifdef CONFIG_PARAVIRT
+    for (i = 0; i < nr_grant_frames; i++) {
+        HYPERVISOR_update_va_mapping((unsigned long)(((char *)gnttab_table) + PAGE_SIZE*i),
+                (pte_t){(frames[i] << PAGE_SHIFT) | L1_PROT}, UVMF_INVLPG);
+    }
+#endif
+}
+
 unsigned long alloc_virt_kernel(unsigned n_pages)
 {
     unsigned long addr;
gnttab.c +10 -0
index 3f0e35f..6978a9b 100644
@@ -194,3 +194,13 @@ fini_gnttab(void)
 
     HYPERVISOR_grant_table_op(GNTTABOP_setup_table, &setup, 1);
 }
+
+void suspend_gnttab(void)
+{
+    arch_suspend_gnttab(gnttab_table, NR_GRANT_FRAMES);
+}
+
+void resume_gnttab(void)
+{
+    arch_resume_gnttab(gnttab_table, NR_GRANT_FRAMES);
+}
include/gnttab.h +4 -0
index a9d8e09..974cb89 100644
@@ -12,6 +12,10 @@ unsigned long gnttab_end_transfer(grant_ref_t gref);
 int gnttab_end_access(grant_ref_t ref);
 const char *gnttabop_error(int16_t status);
 void fini_gnttab(void);
+void suspend_gnttab(void);
+void resume_gnttab(void);
 grant_entry_v1_t *arch_init_gnttab(int nr_grant_frames);
+void arch_suspend_gnttab(grant_entry_v1_t *gnttab_table, int nr_grant_frames);
+void arch_resume_gnttab(grant_entry_v1_t *gnttab_table, int nr_grant_frames);
 
 #endif /* !__GNTTAB_H__ */
kernel.c +4 -0
index d078e0a..933cbcd 100644
@@ -121,6 +121,8 @@ void pre_suspend(void)
 {
     local_irq_disable();
 
+    suspend_gnttab();
+
     fini_time();
 
     suspend_console();
@@ -134,6 +136,8 @@ void post_suspend(int canceled)
 
     init_time();
 
+    resume_gnttab();
+
     local_irq_enable();
 }
 
Signature · 7 lines
2.3.2 (Apple Git-55)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v2 13/16
#16 lore raw

Re: [PATCH v2 13/16] Save/Restore Support: Add suspend/restore support for Grant Tables.

Quoted 17 lines · Bruno Alvisio

---
Changed since v1:
- Moved suspend/resume _gnttab to arch specific files

---
 arch/x86/mm.c    | 34 ++++++++++++++++++++++++++++++++++
 gnttab.c         | 10 ++++++++++
 include/gnttab.h |  4 ++++
 kernel.c         |  4 ++++
 4 files changed, 52 insertions(+)
arch/x86/mm.c +0 -0
index 1b163ac..2597c5b 100644
@@ -917,6 +917,40 @@ grant_entry_v1_t *arch_init_gnttab(int nr_grant_frames)
     return map_frames(frames, nr_grant_frames);

arch/x86/mm.c grant_entry_v1_t *arch_init_gnttab(int nr_grant_frames) · line 927

Quoted 10 lines
arch/x86/mm.c +8 -0
 }
 
+void arch_suspend_gnttab(grant_entry_v1_t *gnttab_table, int nr_grant_frames)
+{
+#ifdef CONFIG_PARAVIRT
+    int i;
+
+    for (i = 0; i < nr_grant_frames; i++) {
+        HYPERVISOR_update_va_mapping((unsigned long)(((char *)gnttab_table) + PAGE_SIZE*i),
+                (pte_t){0x0<<PAGE_SHIFT}, UVMF_INVLPG);

Coding style (blanks around operators, once again below).

Other than that:

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#17 lore raw

PATCH v2 14/16 Save/Restore Support: Add suspend/restore support for xenbus

In reply to Bruno Alvisio

Currently the watch path is not saved in the watch struct when it is registered. During xenbus resume the path is needed so that the watches can be registered again. Thus, 'path' field is added to struct watch so that watches can be re-registered during xenbus resume.

---
 include/xenbus.h |   2 ++
 kernel.c         |   8 +++++
 xenbus/xenbus.c  | 106 +++++++++++++++++++++++++++++++++++++++----------------
 3 files changed, 85 insertions(+), 31 deletions(-)
include/xenbus.h +2 -0
index b2d5072..3871f35 100644
@@ -120,6 +120,8 @@ domid_t xenbus_get_self_id(void);
 #ifdef CONFIG_XENBUS
 /* Reset the XenBus system. */
 void fini_xenbus(void);
+void suspend_xenbus(void);
+void resume_xenbus(int canceled);
 #else
 static inline void fini_xenbus(void)
 {
kernel.c +8 -0
index 933cbcd..1393d15 100644
@@ -119,6 +119,10 @@ void start_kernel(void* par)
 
 void pre_suspend(void)
 {
+#ifdef CONFIG_XENBUS
+    suspend_xenbus();
+#endif
+
     local_irq_disable();
 
     suspend_gnttab();
@@ -139,6 +143,10 @@ void post_suspend(int canceled)
     resume_gnttab();
 
     local_irq_enable();
+
+#ifdef CONFIG_XENBUS
+    resume_xenbus(canceled);
+#endif
 }
 
 void stop_kernel(void)
xenbus/xenbus.c +75 -31

172 lines not on this page · raw message

Signature · 7 lines
2.3.2 (Apple Git-55)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#18 lore raw

PATCH v2 15/16 Save/Restore Support: Add suspend/restore support for netfront

In reply to Bruno Alvisio

Performed an additional cleanup to make the file more syntactically consistent.

---
 include/netfront.h |   8 +-
 kernel.c           |   8 ++
 netfront.c         | 309 ++++++++++++++++++++++++++++++++++++++---------------
 3 files changed, 236 insertions(+), 89 deletions(-)
include/netfront.h +7 -1
index 2b95da9..1164d50 100644
@@ -3,9 +3,15 @@
 #include <lwip/netif.h>
 #endif
 struct netfront_dev;
-struct netfront_dev *init_netfront(char *nodename, void (*netif_rx)(unsigned char *data, int len), unsigned char rawmac[6], char **ip);
+struct netfront_dev *init_netfront(char *nodename,
+                                   void (*netif_rx)(unsigned char *data,
+                                                    int len, void* arg),
+                                   unsigned char rawmac[6],
+                                   char **ip);
 void netfront_xmit(struct netfront_dev *dev, unsigned char* data,int len);
 void shutdown_netfront(struct netfront_dev *dev);
+void suspend_netfront(void);
+void resume_netfront(void);
 #ifdef HAVE_LIBC
 int netfront_tap_open(char *nodename);
 ssize_t netfront_receive(struct netfront_dev *dev, unsigned char *data, size_t len);
kernel.c +8 -0
index 1393d15..301273d 100644
@@ -119,6 +119,10 @@ void start_kernel(void* par)
 
 void pre_suspend(void)
 {
+#ifdef CONFIG_NETFRONT
+    suspend_netfront();
+#endif
+
 #ifdef CONFIG_XENBUS
     suspend_xenbus();
 #endif
@@ -147,6 +151,10 @@ void post_suspend(int canceled)
 #ifdef CONFIG_XENBUS
     resume_xenbus(canceled);
 #endif
+
+#ifdef CONFIG_NETFRONT
+    resume_netfront();
+#endif
 }
 
 void stop_kernel(void)
netfront.c +221 -88

502 lines not on this page · raw message

Signature · 7 lines
2.3.2 (Apple Git-55)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#19 lore raw

PATCH v2 16/16 Save/Restore Support: Implement code for arch suspend/resume

In reply to Bruno Alvisio

Before suspending the domain the shared_info_page is unmapped and for PVs the pagetables should be canonicalized. After resume the shared_info_page should be mapped again.

---
Changed since v1:
* Fixed comment

---
 arch/x86/setup.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
arch/x86/setup.c +51 -0
index b6e0541..b5ed1c8 100644
@@ -32,6 +32,7 @@
 #include <xen/xen.h>
 #include <xen/arch-x86/cpuid.h>
 #include <xen/arch-x86/hvm/start_info.h>
+#include <xen/hvm/params.h>
 
 #ifdef CONFIG_PARAVIRT
 /*
@@ -42,6 +43,11 @@ union start_info_union start_info_union;
 #endif
 
 /*
+ * This pointer holds a reference to the copy of the start_info struct.
+ */
+static start_info_t *start_info_ptr;
+
+/*
  * Shared page for communicating with the hypervisor.
  * Events flags go here, for example.
  */
@@ -212,18 +218,63 @@ arch_init(void *par)
 #ifdef CONFIG_PARAVIRT
 	memcpy(&start_info, par, sizeof(start_info));
 #endif
+	start_info_ptr = (start_info_t *)par;
 
 	start_kernel((start_info_t *)par);
 }
 
 void arch_pre_suspend(void)
 {
+#ifdef CONFIG_PARAVIRT
+   /* Replace xenstore and console mfns with the correspondent pfns */
+    start_info_ptr->store_mfn =
+        virt_to_pfn(mfn_to_virt(start_info_ptr->store_mfn));
+    start_info_ptr->console.domU.mfn =
+        virt_to_pfn(mfn_to_virt(start_info_ptr->console.domU.mfn));
+#else
+    uint64_t store_v;
+    uint64_t console_v;
+
+    if( hvm_get_parameter(HVM_PARAM_STORE_PFN, &store_v) )
+        BUG();
+    start_info_ptr->store_mfn = store_v;
+
+    if( hvm_get_parameter(HVM_PARAM_CONSOLE_PFN, &console_v) )
+        BUG();
+    start_info_ptr->console.domU.mfn = console_v;
+#endif
+    unmap_shared_info();
 
+    arch_mm_pre_suspend();
 }
 
 void arch_post_suspend(int canceled)
 {
+#if CONFIG_PARAVIRT
+    if (canceled) {
+        start_info_ptr->store_mfn = pfn_to_mfn(start_info_ptr->store_mfn);
+        start_info_ptr->console.domU.mfn = pfn_to_mfn(start_info_ptr->console.domU.mfn);
+    } else {
+        memcpy(&start_info, start_info_ptr, sizeof(start_info_t));
+    }
+#else
+    uint64_t store_v;
+    uint64_t console_v;
+
+    if (hvm_get_parameter(HVM_PARAM_STORE_PFN, &store_v))
+        BUG();
+    start_info_ptr->store_mfn = pfn_to_mfn(store_v);
 
+    if (hvm_get_parameter(HVM_PARAM_CONSOLE_PFN, &console_v))
+        BUG();
+    start_info_ptr->console.domU.mfn = pfn_to_mfn(console_v);
+#endif
+
+    HYPERVISOR_shared_info = map_shared_info((void*) start_info_ptr->shared_info);
+#ifndef CONFIG_PARAVIRT
+    xen_callback_vector();
+#endif
+    arch_mm_post_suspend(canceled);
 }
 
 void
Signature · 7 lines
2.3.2 (Apple Git-55)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel