xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RFC 00/16] Save/Restore Support for mini-OS PVH
@ 2017-12-19 23:41 Bruno Alvisio
  2017-12-19 23:41 ` [PATCH RFC 01/16] Save/Restore Support: Refactor HYPERVISOR_suspend hypercall Bruno Alvisio
                   ` (19 more replies)
  0 siblings, 20 replies; 34+ messages in thread
From: Bruno Alvisio @ 2017-12-19 23:41 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: jgross, samuel.thibault, wei.liu2

Hi all,

I have been working on supporting save/restore for mini-os PVH. Some parts of
the implementation were taken from the sysml/mini-os repository. The branch can
be found at:

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

Any feedback would be greatly appreciated.

Cheers,

Bruno

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 34+ messages in thread

* [PATCH RFC 01/16] Save/Restore Support: Refactor HYPERVISOR_suspend hypercall
  2017-12-19 23:41 [PATCH RFC 00/16] Save/Restore Support for mini-OS PVH Bruno Alvisio
@ 2017-12-19 23:41 ` Bruno Alvisio
  2017-12-19 23:51   ` [Minios-devel] " Samuel Thibault
  2017-12-19 23:41 ` [PATCH RFC 02/16] Save/Restore Support: Refactor trap_init() and setup vector callbacks Bruno Alvisio
                   ` (18 subsequent siblings)
  19 siblings, 1 reply; 34+ messages in thread
From: Bruno Alvisio @ 2017-12-19 23:41 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: jgross, samuel.thibault, wei.liu2, Bruno Alvisio

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.

Signed-off-by: Bruno Alvisio <bruno.alvisio@gmail.com>
---
 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(-)

diff --git a/include/x86/x86_32/hypercall-x86_32.h b/include/x86/x86_32/hypercall-x86_32.h
index 5c93464..70505a4 100644
--- a/include/x86/x86_32/hypercall-x86_32.h
+++ b/include/x86/x86_32/hypercall-x86_32.h
@@ -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
diff --git a/include/x86/x86_64/hypercall-x86_64.h b/include/x86/x86_64/hypercall-x86_64.h
index 6171812..95f8ade 100644
--- a/include/x86/x86_64/hypercall-x86_64.h
+++ b/include/x86/x86_64/hypercall-x86_64.h
@@ -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
-- 
2.3.2 (Apple Git-55)


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH RFC 02/16] Save/Restore Support: Refactor trap_init() and setup vector callbacks
  2017-12-19 23:41 [PATCH RFC 00/16] Save/Restore Support for mini-OS PVH Bruno Alvisio
  2017-12-19 23:41 ` [PATCH RFC 01/16] Save/Restore Support: Refactor HYPERVISOR_suspend hypercall Bruno Alvisio
@ 2017-12-19 23:41 ` Bruno Alvisio
  2017-12-19 23:51   ` [Minios-devel] " Samuel Thibault
  2017-12-19 23:41 ` [PATCH RFC 03/16] Save/Restore Support: Declare kernel and arch pre/post suspend functions Bruno Alvisio
                   ` (17 subsequent siblings)
  19 siblings, 1 reply; 34+ messages in thread
From: Bruno Alvisio @ 2017-12-19 23:41 UTC (permalink / raw)
  To: minios-devel, xen-devel
  Cc: jgross, samuel.thibault, Bruno Alvisio, wei.liu2, 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.

Signed-off-by: Bruno Alvisio <bruno.alvisio@oracle.com>
---
 arch/x86/traps.c | 17 +++++++++++------
 include/x86/os.h |  3 +++
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/arch/x86/traps.c b/arch/x86/traps.c
index aa17da3..a7388a5 100644
--- a/arch/x86/traps.c
+++ b/arch/x86/traps.c
@@ -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)
diff --git a/include/x86/os.h b/include/x86/os.h
index fbc2eeb..d155914 100644
--- a/include/x86/os.h
+++ b/include/x86/os.h
@@ -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);
 
-- 
2.3.2 (Apple Git-55)


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH RFC 03/16] Save/Restore Support: Declare kernel and arch pre/post suspend functions
  2017-12-19 23:41 [PATCH RFC 00/16] Save/Restore Support for mini-OS PVH Bruno Alvisio
  2017-12-19 23:41 ` [PATCH RFC 01/16] Save/Restore Support: Refactor HYPERVISOR_suspend hypercall Bruno Alvisio
  2017-12-19 23:41 ` [PATCH RFC 02/16] Save/Restore Support: Refactor trap_init() and setup vector callbacks Bruno Alvisio
@ 2017-12-19 23:41 ` Bruno Alvisio
  2017-12-19 23:52   ` [Minios-devel] " Samuel Thibault
  2017-12-19 23:41 ` [PATCH RFC 04/16] Save/Restore Support: Add xenbus_release_wait_for_watch Bruno Alvisio
                   ` (16 subsequent siblings)
  19 siblings, 1 reply; 34+ messages in thread
From: Bruno Alvisio @ 2017-12-19 23:41 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: jgross, samuel.thibault, wei.liu2, 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.

Signed-off-by: Bruno Alvisio <bruno.alvisio@gmail.com>
---
 arch/x86/setup.c | 10 ++++++++++
 include/kernel.h |  2 ++
 include/x86/os.h |  4 ++--
 kernel.c         | 10 ++++++++++
 4 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/arch/x86/setup.c b/arch/x86/setup.c
index 5278227..3dd86f9 100644
--- a/arch/x86/setup.c
+++ b/arch/x86/setup.c
@@ -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)
 {
diff --git a/include/kernel.h b/include/kernel.h
index d37ddda..161d757 100644
--- a/include/kernel.h
+++ b/include/kernel.h
@@ -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);
diff --git a/include/x86/os.h b/include/x86/os.h
index d155914..a73b63e 100644
--- a/include/x86/os.h
+++ b/include/x86/os.h
@@ -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
 
 /* 
diff --git a/kernel.c b/kernel.c
index 0d84a9b..90c865a 100644
--- a/kernel.c
+++ b/kernel.c
@@ -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 */
-- 
2.3.2 (Apple Git-55)


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH RFC 04/16] Save/Restore Support: Add xenbus_release_wait_for_watch
  2017-12-19 23:41 [PATCH RFC 00/16] Save/Restore Support for mini-OS PVH Bruno Alvisio
                   ` (2 preceding siblings ...)
  2017-12-19 23:41 ` [PATCH RFC 03/16] Save/Restore Support: Declare kernel and arch pre/post suspend functions Bruno Alvisio
@ 2017-12-19 23:41 ` Bruno Alvisio
  2017-12-20  0:14   ` [Minios-devel] " Samuel Thibault
  2017-12-19 23:42 ` [PATCH RFC 05/16] Save/Restore Support: Add kernel shutdown logic to shutdown.c Bruno Alvisio
                   ` (15 subsequent siblings)
  19 siblings, 1 reply; 34+ messages in thread
From: Bruno Alvisio @ 2017-12-19 23:41 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: jgross, samuel.thibault, wei.liu2, 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.

Signed-off-by: Bruno Alvisio <bruno.alvisio@gmail.com>
---
 include/xenbus.h |  1 +
 xenbus/xenbus.c  | 10 +++++++++-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/include/xenbus.h b/include/xenbus.h
index 12391b9..b2d5072 100644
--- a/include/xenbus.h
+++ b/include/xenbus.h
@@ -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);
diff --git a/xenbus/xenbus.c b/xenbus/xenbus.c
index 636786c..c2d2bd1 100644
--- a/xenbus/xenbus.c
+++ b/xenbus/xenbus.c
@@ -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);
 }
-- 
2.3.2 (Apple Git-55)


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH RFC 05/16] Save/Restore Support: Add kernel shutdown logic to shutdown.c
  2017-12-19 23:41 [PATCH RFC 00/16] Save/Restore Support for mini-OS PVH Bruno Alvisio
                   ` (3 preceding siblings ...)
  2017-12-19 23:41 ` [PATCH RFC 04/16] Save/Restore Support: Add xenbus_release_wait_for_watch Bruno Alvisio
@ 2017-12-19 23:42 ` Bruno Alvisio
  2017-12-20  0:16   ` [Minios-devel] " Samuel Thibault
  2017-12-21 22:49   ` Konrad Rzeszutek Wilk
  2017-12-19 23:42 ` [PATCH RFC 06/16] Save/Restore Support: Moved shutdown thread " Bruno Alvisio
                   ` (14 subsequent siblings)
  19 siblings, 2 replies; 34+ messages in thread
From: Bruno Alvisio @ 2017-12-19 23:42 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: jgross, samuel.thibault, wei.liu2, Bruno Alvisio

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=y, Size: 6655 bytes --]

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

Signed-off-by: Bruno Alvisio <bruno.alvisio@gmail.com>
---
 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

diff --git a/Makefile b/Makefile
index 88315c4..6a05de6 100644
--- a/Makefile
+++ b/Makefile
@@ -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
 
diff --git a/include/shutdown.h b/include/shutdown.h
new file mode 100644
index 0000000..a5ec019
--- /dev/null
+++ b/include/shutdown.h
@@ -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
diff --git a/shutdown.c b/shutdown.c
new file mode 100644
index 0000000..b3cea6d
--- /dev/null
+++ b/shutdown.c
@@ -0,0 +1,188 @@
+/*
+ *          MiniOS
+ *
+ *   file: fromdevice.cc
+ *
+ *          NEC Europe Ltd. PROPRIETARY INFORMATION
+ *
+ * This software is supplied under the terms of a license agreement
+ * or nondisclosure agreement with NEC Europe Ltd. and may not be
+ * copied or disclosed except in accordance with the terms of that
+ * agreement. The software and its source code contain valuable trade
+ * secrets and confidential information which have to be maintained in
+ * confidence.
+ * Any unauthorized publication, transfer to third parties or duplication
+ * of the object or source code - either totally or in part – is
+ * prohibited.
+ *
+ *      Copyright (c) 2014 NEC Europe Ltd. All Rights Reserved.
+ *
+ * Authors: Filipe Manco <filipe.manco@neclab.eu>
+ *
+ * NEC Europe Ltd. DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED,
+ * INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE AND THE WARRANTY AGAINST LATENT
+ * DEFECTS, WITH RESPECT TO THE PROGRAM AND THE ACCOMPANYING
+ * DOCUMENTATION.
+ *
+ * No Liability For Consequential Damages IN NO EVENT SHALL NEC Europe
+ * Ltd., NEC Corporation OR ANY OF ITS SUBSIDIARIES BE LIABLE FOR ANY
+ * DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS
+ * OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF INFORMATION, OR
+ * OTHER PECUNIARY LOSS AND INDIRECT, CONSEQUENTIAL, INCIDENTAL,
+ * ECONOMIC OR PUNITIVE DAMAGES) ARISING OUT OF THE USE OF OR INABILITY
+ * TO USE THIS PROGRAM, EVEN IF NEC Europe Ltd. HAS BEEN ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
+ *
+ *     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))) {
+            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 */
+            free(shutdown);
+            continue;
+        } else if (!strcmp(shutdown, "poweroff")) {
+            shutdown_reason = SHUTDOWN_poweroff;
+        } else if (!strcmp(shutdown, "reboot")) {
+            shutdown_reason = SHUTDOWN_reboot;
+        } else if (!strcmp(shutdown, "suspend")) {
+            shutdown_reason = SHUTDOWN_suspend;
+        } else {
+            shutdown_reason = SHUTDOWN_crash;
+        }
+        free(shutdown);
+
+        /* Acknowledge shutdown request */
+        if ((err = xenbus_write(XBT_NIL, path, ""))) {
+            free(err);
+            do_exit();
+        }
+
+        app_shutdown(shutdown_reason);
+    }
+}
+#endif
+
+static void fini_shutdown(void)
+{
+    char *err;
+
+    end_shutdown_thread = 1;
+    xenbus_release_wait_for_watch(&events);
+    err = xenbus_unwatch_path_token(XBT_NIL, path, token);
+    if (err) {
+        free(err);
+        do_exit();
+    }
+}
+
+void init_shutdown(start_info_t *si)
+{
+    start_info_ptr = si;
+
+    end_shutdown_thread = 0;
+    create_thread("shutdown", shutdown_thread, NULL);
+}
+
+void kernel_shutdown(int reason)
+{
+    char* reason_str = NULL;
+
+    switch(reason) {
+        case SHUTDOWN_poweroff:
+            reason_str = "poweroff";
+            break;
+        case SHUTDOWN_reboot:
+            reason_str = "reboot";
+            break;
+        case SHUTDOWN_crash:
+            reason_str = "crash";
+            break;
+        default:
+            do_exit();
+            break;
+    }
+
+    printk("MiniOS will shutdown (reason = %s) ...\n", reason_str);
+
+    fini_shutdown();
+
+    stop_kernel();
+
+    for ( ;; ) {
+        struct sched_shutdown sched_shutdown = { .reason = reason };
+        HYPERVISOR_sched_op(SCHEDOP_shutdown, &sched_shutdown);
+    }
+}
+
+void kernel_suspend(void)
+{
+    int rc;
+
+    printk("MiniOS will suspend ...\n");
+
+    pre_suspend();
+    arch_pre_suspend();
+
+    /*
+     * This hypercall returns 1 if the suspend
+     * was cancelled and 0 if resuming in a new domain
+     */
+    rc = HYPERVISOR_suspend(virt_to_mfn(start_info_ptr));
+
+    arch_post_suspend(rc);
+    post_suspend(rc);
+
+    if (rc) {
+        printk("MiniOS suspend canceled!");
+    } else {
+        printk("MiniOS resumed from suspend!\n");
+    }
+}
-- 
2.3.2 (Apple Git-55)



[-- Attachment #2: Type: text/plain, Size: 157 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH RFC 06/16] Save/Restore Support: Moved shutdown thread to shutdown.c
  2017-12-19 23:41 [PATCH RFC 00/16] Save/Restore Support for mini-OS PVH Bruno Alvisio
                   ` (4 preceding siblings ...)
  2017-12-19 23:42 ` [PATCH RFC 05/16] Save/Restore Support: Add kernel shutdown logic to shutdown.c Bruno Alvisio
@ 2017-12-19 23:42 ` Bruno Alvisio
  2017-12-19 23:42 ` [PATCH RFC 07/16] Save/Restore Support: Add unmap_shared_info Bruno Alvisio
                   ` (13 subsequent siblings)
  19 siblings, 0 replies; 34+ messages in thread
From: Bruno Alvisio @ 2017-12-19 23:42 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: jgross, samuel.thibault, wei.liu2, Bruno Alvisio

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

Signed-off-by: Bruno Alvisio <bruno.alvisio@gmail.com>
---
 arch/x86/setup.c |  2 +-
 include/kernel.h |  2 +-
 kernel.c         | 50 ++++++--------------------------------------------
 3 files changed, 8 insertions(+), 46 deletions(-)

diff --git a/arch/x86/setup.c b/arch/x86/setup.c
index 3dd86f9..31fa2c6 100644
--- a/arch/x86/setup.c
+++ b/arch/x86/setup.c
@@ -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)
diff --git a/include/kernel.h b/include/kernel.h
index 161d757..742abf5 100644
--- a/include/kernel.h
+++ b/include/kernel.h
@@ -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));
diff --git a/kernel.c b/kernel.c
index 90c865a..1cd40e8 100644
--- a/kernel.c
+++ b/kernel.c
@@ -42,6 +42,9 @@
 #include <mini-os/blkfront.h>
 #include <mini-os/fbfront.h>
 #include <mini-os/pcifront.h>
+#ifdef CONFIG_XENBUS
+#include <mini-os/shutdown.h>
+#endif
 #include <mini-os/xmalloc.h>
 #include <fcntl.h>
 #include <xen/features.h>
@@ -66,48 +69,6 @@ void setup_xen_features(void)
     }
 }
 
-#ifdef CONFIG_XENBUS
-/* This should be overridden by the application we are linked against. */
-__attribute__((weak)) void app_shutdown(unsigned reason)
-{
-    struct sched_shutdown sched_shutdown = { .reason = reason };
-    printk("Shutdown requested: %d\n", reason);
-    HYPERVISOR_sched_op(SCHEDOP_shutdown, &sched_shutdown);
-}
-
-static void shutdown_thread(void *p)
-{
-    const char *path = "control/shutdown";
-    const char *token = path;
-    xenbus_event_queue events = NULL;
-    char *shutdown = NULL, *err;
-    unsigned int shutdown_reason;
-    xenbus_watch_path_token(XBT_NIL, path, token, &events);
-    while ((err = xenbus_read(XBT_NIL, path, &shutdown)) != NULL || !strcmp(shutdown, ""))
-    {
-        free(err);
-        free(shutdown);
-        shutdown = NULL;
-        xenbus_wait_for_watch(&events);
-    }
-    err = xenbus_unwatch_path_token(XBT_NIL, path, token);
-    free(err);
-    err = xenbus_write(XBT_NIL, path, "");
-    free(err);
-    printk("Shutting down (%s)\n", shutdown);
-
-    if (!strcmp(shutdown, "poweroff"))
-        shutdown_reason = SHUTDOWN_poweroff;
-    else if (!strcmp(shutdown, "reboot"))
-        shutdown_reason = SHUTDOWN_reboot;
-    else
-        /* Unknown */
-        shutdown_reason = SHUTDOWN_crash;
-    app_shutdown(shutdown_reason);
-    free(shutdown);
-}
-#endif
-
 
 /* This should be overridden by the application we are linked against. */
 __attribute__((weak)) int app_main(void *p)
@@ -116,7 +77,7 @@ __attribute__((weak)) int app_main(void *p)
     return 0;
 }
 
-void start_kernel(void)
+void start_kernel(void* par)
 {
     /* Set up events. */
     init_events();
@@ -145,7 +106,8 @@ void start_kernel(void)
     init_xenbus();
 
 #ifdef CONFIG_XENBUS
-    create_thread("shutdown", shutdown_thread, NULL);
+    /* Init shutdown thread */
+    init_shutdown((start_info_t *)par);
 #endif
 
     /* Call (possibly overridden) app_main() */
-- 
2.3.2 (Apple Git-55)


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH RFC 07/16] Save/Restore Support: Add unmap_shared_info
  2017-12-19 23:41 [PATCH RFC 00/16] Save/Restore Support for mini-OS PVH Bruno Alvisio
                   ` (5 preceding siblings ...)
  2017-12-19 23:42 ` [PATCH RFC 06/16] Save/Restore Support: Moved shutdown thread " Bruno Alvisio
@ 2017-12-19 23:42 ` Bruno Alvisio
  2017-12-20  0:23   ` [Minios-devel] " Samuel Thibault
  2017-12-19 23:42 ` [PATCH RFC 08/16] Save/Restore Support: Add arch_mm_pre|post_suspend Bruno Alvisio
                   ` (12 subsequent siblings)
  19 siblings, 1 reply; 34+ messages in thread
From: Bruno Alvisio @ 2017-12-19 23:42 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: jgross, samuel.thibault, wei.liu2, Bruno Alvisio

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

Signed-off-by: Bruno Alvisio <bruno.alvisio@gmail.com>
---
 arch/x86/setup.c     | 12 ++++++++++++
 hypervisor.c         | 12 ++++++++++++
 include/hypervisor.h |  1 +
 3 files changed, 25 insertions(+)

diff --git a/arch/x86/setup.c b/arch/x86/setup.c
index 31fa2c6..3eabce4 100644
--- a/arch/x86/setup.c
+++ b/arch/x86/setup.c
@@ -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)HYPERVISOR_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;
diff --git a/hypervisor.c b/hypervisor.c
index 1647121..d3857e7 100644
--- a/hypervisor.c
+++ b/hypervisor.c
@@ -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)
diff --git a/include/hypervisor.h b/include/hypervisor.h
index f3b1f3c..1d09271 100644
--- a/include/hypervisor.h
+++ b/include/hypervisor.h
@@ -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);
-- 
2.3.2 (Apple Git-55)


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH RFC 08/16] Save/Restore Support: Add arch_mm_pre|post_suspend
  2017-12-19 23:41 [PATCH RFC 00/16] Save/Restore Support for mini-OS PVH Bruno Alvisio
                   ` (6 preceding siblings ...)
  2017-12-19 23:42 ` [PATCH RFC 07/16] Save/Restore Support: Add unmap_shared_info Bruno Alvisio
@ 2017-12-19 23:42 ` Bruno Alvisio
  2017-12-20  0:24   ` [Minios-devel] " Samuel Thibault
  2017-12-19 23:42 ` [PATCH RFC 09/16] Save/Restore Support: Disable/enable IRQs during suspend/restore Bruno Alvisio
                   ` (11 subsequent siblings)
  19 siblings, 1 reply; 34+ messages in thread
From: Bruno Alvisio @ 2017-12-19 23:42 UTC (permalink / raw)
  To: minios-devel, xen-devel
  Cc: jgross, samuel.thibault, Bruno Alvisio, wei.liu2, 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.

Signed-off-by: Bruno Alvisio <bruno.alvisio@oracle.com>
---
 arch/x86/mm.c         | 14 ++++++++++++++
 include/x86/arch_mm.h |  3 +++
 2 files changed, 17 insertions(+)

diff --git a/arch/x86/mm.c b/arch/x86/mm.c
index 05ad029..1b163ac 100644
--- a/arch/x86/mm.c
+++ b/arch/x86/mm.c
@@ -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)
diff --git a/include/x86/arch_mm.h b/include/x86/arch_mm.h
index ab8a53e..cbbeb21 100644
--- a/include/x86/arch_mm.h
+++ b/include/x86/arch_mm.h
@@ -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
-- 
2.3.2 (Apple Git-55)


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH RFC 09/16] Save/Restore Support: Disable/enable IRQs during suspend/restore
  2017-12-19 23:41 [PATCH RFC 00/16] Save/Restore Support for mini-OS PVH Bruno Alvisio
                   ` (7 preceding siblings ...)
  2017-12-19 23:42 ` [PATCH RFC 08/16] Save/Restore Support: Add arch_mm_pre|post_suspend Bruno Alvisio
@ 2017-12-19 23:42 ` Bruno Alvisio
  2017-12-20  0:25   ` [Minios-devel] " Samuel Thibault
  2017-12-19 23:42 ` [PATCH RFC 10/16] Save/Restore Support: Add suspend/resume support for timers Bruno Alvisio
                   ` (10 subsequent siblings)
  19 siblings, 1 reply; 34+ messages in thread
From: Bruno Alvisio @ 2017-12-19 23:42 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: jgross, samuel.thibault, wei.liu2, Bruno Alvisio

Signed-off-by: Bruno Alvisio <bruno.alvisio@gmail.com>
---
 kernel.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel.c b/kernel.c
index 1cd40e8..782eb79 100644
--- a/kernel.c
+++ b/kernel.c
@@ -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)
-- 
2.3.2 (Apple Git-55)


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH RFC 10/16] Save/Restore Support: Add suspend/resume support for timers
  2017-12-19 23:41 [PATCH RFC 00/16] Save/Restore Support for mini-OS PVH Bruno Alvisio
                   ` (8 preceding siblings ...)
  2017-12-19 23:42 ` [PATCH RFC 09/16] Save/Restore Support: Disable/enable IRQs during suspend/restore Bruno Alvisio
@ 2017-12-19 23:42 ` Bruno Alvisio
  2017-12-20  0:26   ` [Minios-devel] " Samuel Thibault
  2017-12-19 23:42 ` [PATCH RFC 11/16] Save/Restore Support: Add suspend/restore support for console Bruno Alvisio
                   ` (9 subsequent siblings)
  19 siblings, 1 reply; 34+ messages in thread
From: Bruno Alvisio @ 2017-12-19 23:42 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: jgross, samuel.thibault, wei.liu2, Bruno Alvisio

Signed-off-by: Bruno Alvisio <bruno.alvisio@gmail.com>
---
 arch/x86/time.c | 13 +++++++++++++
 include/time.h  |  2 ++
 kernel.c        |  4 ++++
 3 files changed, 19 insertions(+)

diff --git a/arch/x86/time.c b/arch/x86/time.c
index 3658142..8f79d69 100644
--- a/arch/x86/time.c
+++ b/arch/x86/time.c
@@ -244,3 +244,16 @@ void fini_time(void)
     HYPERVISOR_set_timer_op(0);
     unbind_evtchn(port);
 }
+
+void suspend_time(void)
+{
+    /* Clear any pending timer */
+    HYPERVISOR_set_timer_op(0);
+    unbind_evtchn(port);
+}
+
+void resume_time(void)
+{
+    port = bind_virq(VIRQ_TIMER, &timer_handler, NULL);
+    unmask_evtchn(port);
+}
diff --git a/include/time.h b/include/time.h
index 5d6ed67..2e06d58 100644
--- a/include/time.h
+++ b/include/time.h
@@ -55,6 +55,8 @@ typedef long suseconds_t;
 /* prototypes */
 void     init_time(void);
 void     fini_time(void);
+void     suspend_time(void);
+void     resume_time(void);
 s_time_t get_s_time(void);
 s_time_t get_v_time(void);
 uint64_t monotonic_clock(void);
diff --git a/kernel.c b/kernel.c
index 782eb79..a16b1ba 100644
--- a/kernel.c
+++ b/kernel.c
@@ -120,10 +120,14 @@ void start_kernel(void* par)
 void pre_suspend(void)
 {
     local_irq_disable();
+
+    suspend_time();
 }
 
 void post_suspend(int canceled)
 {
+    resume_time();
+
     local_irq_enable();
 }
 
-- 
2.3.2 (Apple Git-55)


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH RFC 11/16] Save/Restore Support: Add suspend/restore support for console
  2017-12-19 23:41 [PATCH RFC 00/16] Save/Restore Support for mini-OS PVH Bruno Alvisio
                   ` (9 preceding siblings ...)
  2017-12-19 23:42 ` [PATCH RFC 10/16] Save/Restore Support: Add suspend/resume support for timers Bruno Alvisio
@ 2017-12-19 23:42 ` Bruno Alvisio
  2017-12-19 23:42 ` [PATCH RFC 12/16] Save/Restore Support: Add support for suspend/restore events Bruno Alvisio
                   ` (8 subsequent siblings)
  19 siblings, 0 replies; 34+ messages in thread
From: Bruno Alvisio @ 2017-12-19 23:42 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: jgross, samuel.thibault, wei.liu2, Bruno Alvisio

Signed-off-by: Bruno Alvisio <bruno.alvisio@gmail.com>
---
 console/console.c      | 15 ++++++++++++++-
 console/xenbus.c       |  3 +--
 console/xencons_ring.c | 41 +++++++++++++++++++++++++++++++----------
 include/console.h      |  6 +++++-
 kernel.c               |  4 ++++
 lib/sys.c              |  2 +-
 6 files changed, 56 insertions(+), 15 deletions(-)

diff --git a/console/console.c b/console/console.c
index 2e04552..9814506 100644
--- a/console/console.c
+++ b/console/console.c
@@ -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
diff --git a/console/xenbus.c b/console/xenbus.c
index 1c9a590..654b469 100644
--- a/console/xenbus.c
+++ b/console/xenbus.c
@@ -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);
 }
-
diff --git a/console/xencons_ring.c b/console/xencons_ring.c
index dd64a41..1df8304 100644
--- a/console/xencons_ring.c
+++ b/console/xencons_ring.c
@@ -19,6 +19,8 @@ DECLARE_WAIT_QUEUE_HEAD(console_queue);
 static struct xencons_interface *console_ring;
 uint32_t console_evtchn;
 
+static struct consfront_dev* resume_xen_console(struct consfront_dev* dev);
+
 #ifdef CONFIG_PARAVIRT
 void get_console(void *p)
 {
@@ -32,10 +34,12 @@ void get_console(void *p)
 {
     uint64_t v = -1;
 
-    hvm_get_parameter(HVM_PARAM_CONSOLE_EVTCHN, &v);
+    if (hvm_get_parameter(HVM_PARAM_CONSOLE_EVTCHN, &v))
+    	BUG();
     console_evtchn = v;
 
-    hvm_get_parameter(HVM_PARAM_CONSOLE_PFN, &v);
+    if (hvm_get_parameter(HVM_PARAM_CONSOLE_PFN, &v))
+    	BUG();
     console_ring = (struct xencons_interface *)map_frame_virt(v);
 }
 #endif
@@ -89,9 +93,7 @@ int xencons_ring_send(struct consfront_dev *dev, const char *data, unsigned len)
     notify_daemon(dev);
 
     return sent;
-}	
-
-
+}
 
 void console_handle_input(evtchn_port_t port, struct pt_regs *regs, void *data)
 {
@@ -177,7 +179,6 @@ int xencons_ring_recv(struct consfront_dev *dev, char *data, unsigned len)
 
 struct consfront_dev *xencons_ring_init(void)
 {
-	int err;
 	struct consfront_dev *dev;
 
 	if (!console_evtchn)
@@ -193,16 +194,24 @@ struct consfront_dev *xencons_ring_init(void)
 #ifdef HAVE_LIBC
 	dev->fd = -1;
 #endif
+
+	return resume_xen_console(dev);
+}
+
+static struct consfront_dev* resume_xen_console(struct consfront_dev* dev)
+{
+	int err;
+
 	dev->evtchn = console_evtchn;
 	dev->ring = xencons_interface();
 
 	err = bind_evtchn(dev->evtchn, console_handle_input, dev);
 	if (err <= 0) {
 		printk("XEN console request chn bind failed %i\n", err);
-                free(dev);
+        free(dev);
 		return NULL;
 	}
-        unmask_evtchn(dev->evtchn);
+    unmask_evtchn(dev->evtchn);
 
 	/* In case we have in-flight data after save/restore... */
 	notify_daemon(dev);
@@ -210,8 +219,20 @@ struct consfront_dev *xencons_ring_init(void)
 	return dev;
 }
 
-void xencons_resume(void)
+void xencons_ring_fini(struct consfront_dev* dev)
 {
-	(void)xencons_ring_init();
+	if (dev)
+    	mask_evtchn(dev->evtchn);
 }
 
+void xencons_ring_resume(struct consfront_dev* dev)
+{
+	if (dev) {
+#if CONFIG_PARAVIRT
+		get_console(&start_info);
+#else
+		get_console(0);
+#endif
+		resume_xen_console(dev);
+	}
+}
diff --git a/include/console.h b/include/console.h
index 539cccd..0d7bf07 100644
--- a/include/console.h
+++ b/include/console.h
@@ -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);
diff --git a/kernel.c b/kernel.c
index a16b1ba..fd1c4c5 100644
--- a/kernel.c
+++ b/kernel.c
@@ -122,10 +122,14 @@ void pre_suspend(void)
     local_irq_disable();
 
     suspend_time();
+
+    suspend_console();
 }
 
 void post_suspend(int canceled)
 {
+    resume_console();
+
     resume_time();
 
     local_irq_enable();
diff --git a/lib/sys.c b/lib/sys.c
index 23dc2a5..da434fc 100644
--- a/lib/sys.c
+++ b/lib/sys.c
@@ -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
-- 
2.3.2 (Apple Git-55)


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH RFC 12/16] Save/Restore Support: Add support for suspend/restore events.
  2017-12-19 23:41 [PATCH RFC 00/16] Save/Restore Support for mini-OS PVH Bruno Alvisio
                   ` (10 preceding siblings ...)
  2017-12-19 23:42 ` [PATCH RFC 11/16] Save/Restore Support: Add suspend/restore support for console Bruno Alvisio
@ 2017-12-19 23:42 ` Bruno Alvisio
  2017-12-20  0:37   ` [Minios-devel] " Samuel Thibault
  2017-12-19 23:42 ` [PATCH RFC 13/16] Save/Restore Support: Add suspend/restore support for Grant Tables Bruno Alvisio
                   ` (7 subsequent siblings)
  19 siblings, 1 reply; 34+ messages in thread
From: Bruno Alvisio @ 2017-12-19 23:42 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: jgross, samuel.thibault, wei.liu2, Bruno Alvisio

Signed-off-by: Bruno Alvisio <bruno.alvisio@gmail.com>
---
 events.c         | 5 +++++
 include/events.h | 1 +
 kernel.c         | 2 ++
 3 files changed, 8 insertions(+)

diff --git a/events.c b/events.c
index e8ef8aa..342aead 100644
--- a/events.c
+++ b/events.c
@@ -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);
diff --git a/include/events.h b/include/events.h
index 89b5997..705ad93 100644
--- a/include/events.h
+++ b/include/events.h
@@ -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_ */
diff --git a/kernel.c b/kernel.c
index fd1c4c5..c6ff9f3 100644
--- a/kernel.c
+++ b/kernel.c
@@ -124,6 +124,8 @@ void pre_suspend(void)
     suspend_time();
 
     suspend_console();
+
+    suspend_events();
 }
 
 void post_suspend(int canceled)
-- 
2.3.2 (Apple Git-55)


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH RFC 13/16] Save/Restore Support: Add suspend/restore support for Grant Tables.
  2017-12-19 23:41 [PATCH RFC 00/16] Save/Restore Support for mini-OS PVH Bruno Alvisio
                   ` (11 preceding siblings ...)
  2017-12-19 23:42 ` [PATCH RFC 12/16] Save/Restore Support: Add support for suspend/restore events Bruno Alvisio
@ 2017-12-19 23:42 ` Bruno Alvisio
  2017-12-20  0:40   ` [Minios-devel] " Samuel Thibault
  2017-12-19 23:42 ` [PATCH RFC 14/16] Save/Restore Support: Add suspend/restore support for xenbus Bruno Alvisio
                   ` (6 subsequent siblings)
  19 siblings, 1 reply; 34+ messages in thread
From: Bruno Alvisio @ 2017-12-19 23:42 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: jgross, samuel.thibault, wei.liu2, Bruno Alvisio

Signed-off-by: Bruno Alvisio <bruno.alvisio@gmail.com>
---
 gnttab.c         | 33 +++++++++++++++++++++++++++++++++
 include/gnttab.h |  2 ++
 kernel.c         |  4 ++++
 3 files changed, 39 insertions(+)

diff --git a/gnttab.c b/gnttab.c
index 3f0e35f..a91c2e1 100644
--- a/gnttab.c
+++ b/gnttab.c
@@ -194,3 +194,36 @@ fini_gnttab(void)
 
     HYPERVISOR_grant_table_op(GNTTABOP_setup_table, &setup, 1);
 }
+
+void suspend_gnttab(void)
+{
+#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 resume_gnttab(void)
+{
+    struct gnttab_setup_table setup;
+    unsigned long frames[NR_GRANT_FRAMES];
+
+    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
+    int i;
+    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
+}
\ No newline at end of file
diff --git a/include/gnttab.h b/include/gnttab.h
index a9d8e09..56f5159 100644
--- a/include/gnttab.h
+++ b/include/gnttab.h
@@ -12,6 +12,8 @@ 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);
 
 #endif /* !__GNTTAB_H__ */
diff --git a/kernel.c b/kernel.c
index c6ff9f3..a563f60 100644
--- a/kernel.c
+++ b/kernel.c
@@ -121,6 +121,8 @@ void pre_suspend(void)
 {
     local_irq_disable();
 
+    suspend_gnttab();
+
     suspend_time();
 
     suspend_console();
@@ -134,6 +136,8 @@ void post_suspend(int canceled)
 
     resume_time();
 
+    resume_gnttab();
+
     local_irq_enable();
 }
 
-- 
2.3.2 (Apple Git-55)


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH RFC 14/16] Save/Restore Support: Add suspend/restore support for xenbus
  2017-12-19 23:41 [PATCH RFC 00/16] Save/Restore Support for mini-OS PVH Bruno Alvisio
                   ` (12 preceding siblings ...)
  2017-12-19 23:42 ` [PATCH RFC 13/16] Save/Restore Support: Add suspend/restore support for Grant Tables Bruno Alvisio
@ 2017-12-19 23:42 ` Bruno Alvisio
  2017-12-20  0:43   ` [Minios-devel] " Samuel Thibault
  2017-12-19 23:42 ` [PATCH RFC 15/16] Save/Restore Support: Add suspend/restore support for netfront Bruno Alvisio
                   ` (5 subsequent siblings)
  19 siblings, 1 reply; 34+ messages in thread
From: Bruno Alvisio @ 2017-12-19 23:42 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: jgross, samuel.thibault, wei.liu2, 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.

Signed-off-by: Bruno Alvisio <bruno.alvisio@gmail.com>
---
 include/xenbus.h |   2 ++
 kernel.c         |   8 +++++
 xenbus/xenbus.c  | 106 +++++++++++++++++++++++++++++++++++++++----------------
 3 files changed, 85 insertions(+), 31 deletions(-)

diff --git a/include/xenbus.h b/include/xenbus.h
index b2d5072..3871f35 100644
--- a/include/xenbus.h
+++ b/include/xenbus.h
@@ -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)
 {
diff --git a/kernel.c b/kernel.c
index a563f60..bc2394f 100644
--- a/kernel.c
+++ b/kernel.c
@@ -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)
diff --git a/xenbus/xenbus.c b/xenbus/xenbus.c
index c2d2bd1..4c626fb 100644
--- a/xenbus/xenbus.c
+++ b/xenbus/xenbus.c
@@ -50,6 +50,7 @@ DECLARE_WAIT_QUEUE_HEAD(xenbus_watch_queue);
 xenbus_event_queue xenbus_events;
 static struct watch {
     char *token;
+    char *path;
     xenbus_event_queue *events;
     struct watch *next;
 } *watches;
@@ -63,6 +64,8 @@ struct xenbus_req_info
 #define NR_REQS 32
 static struct xenbus_req_info req_info[NR_REQS];
 
+static char *errmsg(struct xsd_sockmsg *rep);
+
 uint32_t xenbus_evtchn;
 
 #ifdef CONFIG_PARAVIRT
@@ -231,45 +234,39 @@ static void xenbus_thread_func(void *ign)
     struct xsd_sockmsg msg;
     unsigned prod = xenstore_buf->rsp_prod;
 
-    for (;;) 
-    {
+    for (;;) {
         wait_event(xb_waitq, prod != xenstore_buf->rsp_prod);
-        while (1) 
-        {
+        while (1) {
             prod = xenstore_buf->rsp_prod;
             DEBUG("Rsp_cons %d, rsp_prod %d.\n", xenstore_buf->rsp_cons,
-                    xenstore_buf->rsp_prod);
+                  xenstore_buf->rsp_prod);
             if (xenstore_buf->rsp_prod - xenstore_buf->rsp_cons < sizeof(msg))
                 break;
             rmb();
-            memcpy_from_ring(xenstore_buf->rsp,
-                    &msg,
-                    MASK_XENSTORE_IDX(xenstore_buf->rsp_cons),
-                    sizeof(msg));
-            DEBUG("Msg len %d, %d avail, id %d.\n",
-                    msg.len + sizeof(msg),
-                    xenstore_buf->rsp_prod - xenstore_buf->rsp_cons,
-                    msg.req_id);
+            memcpy_from_ring(xenstore_buf->rsp, &msg,
+                             MASK_XENSTORE_IDX(xenstore_buf->rsp_cons),
+                             sizeof(msg));
+            DEBUG("Msg len %d, %d avail, id %d.\n", msg.len + sizeof(msg),
+                  xenstore_buf->rsp_prod - xenstore_buf->rsp_cons, msg.req_id);
+
             if (xenstore_buf->rsp_prod - xenstore_buf->rsp_cons <
-                    sizeof(msg) + msg.len)
+                sizeof(msg) + msg.len)
                 break;
 
             DEBUG("Message is good.\n");
 
-            if(msg.type == XS_WATCH_EVENT)
-            {
-		struct xenbus_event *event = malloc(sizeof(*event) + msg.len);
+            if (msg.type == XS_WATCH_EVENT) {
+		        struct xenbus_event *event = malloc(sizeof(*event) + msg.len);
                 xenbus_event_queue *events = NULL;
-		char *data = (char*)event + sizeof(*event);
+		        char *data = (char*)event + sizeof(*event);
                 struct watch *watch;
 
-                memcpy_from_ring(xenstore_buf->rsp,
-		    data,
+                memcpy_from_ring(xenstore_buf->rsp, data,
                     MASK_XENSTORE_IDX(xenstore_buf->rsp_cons + sizeof(msg)),
                     msg.len);
 
-		event->path = data;
-		event->token = event->path + strlen(event->path) + 1;
+		        event->path = data;
+		        event->token = event->path + strlen(event->path) + 1;
 
                 mb();
                 xenstore_buf->rsp_cons += msg.len + sizeof(msg);
@@ -288,15 +285,11 @@ static void xenbus_thread_func(void *ign)
                     printk("unexpected watch token %s\n", event->token);
                     free(event);
                 }
-            }
-
-            else
-            {
+            } else {
                 req_info[msg.req_id].reply = malloc(sizeof(msg) + msg.len);
-                memcpy_from_ring(xenstore_buf->rsp,
-                    req_info[msg.req_id].reply,
-                    MASK_XENSTORE_IDX(xenstore_buf->rsp_cons),
-                    msg.len + sizeof(msg));
+                memcpy_from_ring(xenstore_buf->rsp, req_info[msg.req_id].reply,
+                                 MASK_XENSTORE_IDX(xenstore_buf->rsp_cons),
+                                 msg.len + sizeof(msg));
                 mb();
                 xenstore_buf->rsp_cons += msg.len + sizeof(msg);
                 wake_up(&req_info[msg.req_id].waitq);
@@ -380,6 +373,55 @@ void fini_xenbus(void)
 {
 }
 
+void suspend_xenbus(void)
+{
+  /* Check for live requests and wait until they finish */
+    while (1)
+    {
+        spin_lock(&req_lock);
+        if (nr_live_reqs == 0)
+            break;
+        spin_unlock(&req_lock);
+        wait_event(req_wq, (nr_live_reqs == 0));
+    }
+
+    mask_evtchn(xenbus_evtchn);
+    xenstore_buf = NULL;
+    spin_unlock(&req_lock);
+}
+
+void resume_xenbus(int canceled)
+{
+    char *msg;
+    struct watch *watch;
+    struct write_req req[2];
+    struct xsd_sockmsg *rep;
+
+#ifdef CONFIG_PARAVIRT
+    get_xenbus(&start_info);
+#else
+    get_xenbus(0);
+#endif
+    unmask_evtchn(xenbus_evtchn);
+
+    if (!canceled) {
+        for (watch = watches; watch; watch = watch->next) {
+            req[0].data = watch->path;
+            req[0].len = strlen(watch->path) + 1;
+            req[1].data = watch->token;
+            req[1].len = strlen(watch->token) + 1;
+
+            rep = xenbus_msg_reply(XS_WATCH, XBT_NIL, req, ARRAY_SIZE(req));
+            msg = errmsg(rep);
+            if (msg)
+                xprintk("error on XS_WATCH: %s\n", msg);
+            free(rep);
+        }
+    }
+
+    notify_remote_via_evtchn(xenbus_evtchn);
+}
+
 /* Send data to xenbus.  This can block.  All of the requests are seen
    by xenbus as if sent atomically.  The header is added
    automatically, using type %type, req_id %req_id, and trans_id
@@ -501,7 +543,7 @@ static char *errmsg(struct xsd_sockmsg *rep)
     res[rep->len] = 0;
     free(rep);
     return res;
-}	
+}
 
 /* Send a debug message to xenbus.  Can block. */
 static void xenbus_debug_msg(const char *msg)
@@ -601,6 +643,7 @@ char* xenbus_watch_path_token( xenbus_transaction_t xbt, const char *path, const
         events = &xenbus_events;
 
     watch->token = strdup(token);
+    watch->path = strdup(path);
     watch->events = events;
     watch->next = watches;
     watches = watch;
@@ -636,6 +679,7 @@ char* xenbus_unwatch_path_token( xenbus_transaction_t xbt, const char *path, con
     for (prev = &watches, watch = *prev; watch; prev = &watch->next, watch = *prev)
         if (!strcmp(watch->token, token)) {
             free(watch->token);
+            free(watch->path);
             *prev = watch->next;
             free(watch);
             break;
-- 
2.3.2 (Apple Git-55)


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH RFC 15/16] Save/Restore Support: Add suspend/restore support for netfront
  2017-12-19 23:41 [PATCH RFC 00/16] Save/Restore Support for mini-OS PVH Bruno Alvisio
                   ` (13 preceding siblings ...)
  2017-12-19 23:42 ` [PATCH RFC 14/16] Save/Restore Support: Add suspend/restore support for xenbus Bruno Alvisio
@ 2017-12-19 23:42 ` Bruno Alvisio
  2017-12-19 23:42 ` [PATCH RFC 16/16] Save/Restore Support: Implement code for arch suspend/resume Bruno Alvisio
                   ` (4 subsequent siblings)
  19 siblings, 0 replies; 34+ messages in thread
From: Bruno Alvisio @ 2017-12-19 23:42 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: jgross, samuel.thibault, wei.liu2, Bruno Alvisio

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

Signed-off-by: Bruno Alvisio <bruno.alvisio@gmail.com>
---
 include/netfront.h |   8 +-
 kernel.c           |   8 ++
 netfront.c         | 242 +++++++++++++++++++++++++++++++++++++++++------------
 3 files changed, 204 insertions(+), 54 deletions(-)

diff --git a/include/netfront.h b/include/netfront.h
index 2b95da9..1164d50 100644
--- a/include/netfront.h
+++ b/include/netfront.h
@@ -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);
diff --git a/kernel.c b/kernel.c
index bc2394f..805539e 100644
--- a/kernel.c
+++ b/kernel.c
@@ -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)
diff --git a/netfront.c b/netfront.c
index b8fac62..9aef42b 100644
--- a/netfront.c
+++ b/netfront.c
@@ -63,10 +63,29 @@ struct netfront_dev {
     size_t rlen;
 #endif
 
-    void (*netif_rx)(unsigned char* data, int len);
+    void (*netif_rx)(unsigned char* data, int len, void* arg);
+    void *netif_rx_arg;
 };
 
+struct netfront_dev_list {
+	struct netfront_dev *dev;
+	unsigned char rawmac[6];
+	char *ip;
+
+	int refcount;
+
+	struct netfront_dev_list *next;
+};
+
+static struct netfront_dev_list *dev_list = NULL;
+
 void init_rx_buffers(struct netfront_dev *dev);
+static struct netfront_dev *_init_netfront(struct netfront_dev *dev,
+					   unsigned char rawmac[6], char **ip);
+static void _shutdown_netfront(struct netfront_dev *dev);
+void netfront_set_rx_handler(struct netfront_dev *dev,
+			                 void (*thenetif_rx)(unsigned char *data, int len,
+			                 void *arg), void *arg);
 
 static inline void add_id_to_freelist(unsigned int id,unsigned short* freelist)
 {
@@ -81,7 +100,7 @@ static inline unsigned short get_id_from_freelist(unsigned short* freelist)
     return id;
 }
 
-__attribute__((weak)) void netif_rx(unsigned char* data,int len)
+__attribute__((weak)) void netif_rx(unsigned char* data, int len, void *arg)
 {
     printk("%d bytes incoming at %p\n",len,data);
 }
@@ -134,7 +153,7 @@ moretodo:
 		dobreak = 1;
 	    } else
 #endif
-		dev->netif_rx(page+rx->offset,rx->status);
+		dev->netif_rx(page+rx->offset, rx->status, dev->netif_rx_arg);
         }
     }
     dev->rx.rsp_cons=cons;
@@ -282,19 +301,16 @@ static void free_netfront(struct netfront_dev *dev)
     free(dev);
 }
 
-struct netfront_dev *init_netfront(char *_nodename, void (*thenetif_rx)(unsigned char* data, int len), unsigned char rawmac[6], char **ip)
+struct netfront_dev *init_netfront(char *_nodename,
+                                   void (*thenetif_rx)(unsigned char* data,
+                                                       int len, void* arg),
+                                   unsigned char rawmac[6],
+                                   char **ip)
 {
-    xenbus_transaction_t xbt;
-    char* err;
-    char* message=NULL;
-    struct netif_tx_sring *txs;
-    struct netif_rx_sring *rxs;
-    int retry=0;
-    int i;
-    char* msg = NULL;
     char nodename[256];
-    char path[256];
     struct netfront_dev *dev;
+    struct netfront_dev_list *ldev = NULL;
+    struct netfront_dev_list *list = NULL;
     static int netfrontends = 0;
 
     if (!_nodename)
@@ -303,10 +319,20 @@ struct netfront_dev *init_netfront(char *_nodename, void (*thenetif_rx)(unsigned
         strncpy(nodename, _nodename, sizeof(nodename) - 1);
         nodename[sizeof(nodename) - 1] = 0;
     }
-    netfrontends++;
+
+    /* Check if the device is already initialized */
+    for (list = dev_list; list != NULL; list = list->next) {
+        if (strcmp(nodename, list->dev->nodename) == 0) {
+            list->refcount++;
+            dev = list->dev;
+            if (thenetif_rx)
+                netfront_set_rx_handler(dev, thenetif_rx, NULL);
+            goto out;
+        }
+    }
 
     if (!thenetif_rx)
-	thenetif_rx = netif_rx;
+        thenetif_rx = netif_rx;
 
     printk("************************ NETFRONT for %s **********\n\n\n", nodename);
 
@@ -316,23 +342,77 @@ struct netfront_dev *init_netfront(char *_nodename, void (*thenetif_rx)(unsigned
 #ifdef HAVE_LIBC
     dev->fd = -1;
 #endif
+    dev->netif_rx = thenetif_rx;
+
+    ldev = malloc(sizeof(struct netfront_dev_list));
+    memset(ldev, 0, sizeof(struct netfront_dev_list));
+
+    if (_init_netfront(dev, ldev->rawmac, &(ldev->ip))) {
+	    ldev->dev = dev;
+		ldev->refcount = 1;
+		ldev->next = NULL;
+
+		if (!dev_list) {
+            dev_list = ldev;
+		} else {
+            for (list = dev_list; list->next != NULL; list = list->next);
+            list->next = ldev;
+		}
+        netfrontends++;
+	} else {
+        free(dev->nodename);
+        free(dev);
+        free(ldev);
+        dev = NULL;
+        goto err;
+    }
+
+out:
+    if (rawmac) {
+        rawmac[0] = ldev->rawmac[0];
+        rawmac[1] = ldev->rawmac[1];
+        rawmac[2] = ldev->rawmac[2];
+        rawmac[3] = ldev->rawmac[3];
+        rawmac[4] = ldev->rawmac[4];
+        rawmac[5] = ldev->rawmac[5];
+	}
+    if (ip) {
+	    *ip = malloc(strlen(ldev->ip) + 1);
+	    strncpy(*ip, ldev->ip, strlen(ldev->ip) + 1);
+    }
+
+err:
+    return dev;
+}
+
+static struct netfront_dev *_init_netfront(struct netfront_dev *dev,
+					   unsigned char rawmac[6],
+					   char **ip)
+{
+    xenbus_transaction_t xbt;
+    char* err = NULL;
+    char* message=NULL;
+    struct netif_tx_sring *txs;
+    struct netif_rx_sring *rxs;
+    char* msg = NULL;
+    int retry=0;
+    int i;
+    char path[256];
 
     printk("net TX ring size %lu\n", (unsigned long) NET_TX_RING_SIZE);
     printk("net RX ring size %lu\n", (unsigned long) NET_RX_RING_SIZE);
     init_SEMAPHORE(&dev->tx_sem, NET_TX_RING_SIZE);
-    for(i=0;i<NET_TX_RING_SIZE;i++)
-    {
-	add_id_to_freelist(i,dev->tx_freelist);
+    for (i = 0; i < NET_TX_RING_SIZE; i++) {
+	    add_id_to_freelist(i,dev->tx_freelist);
         dev->tx_buffers[i].page = NULL;
     }
 
-    for(i=0;i<NET_RX_RING_SIZE;i++)
-    {
-	/* TODO: that's a lot of memory */
+    for (i = 0; i < NET_RX_RING_SIZE; i++) {
+	    /* TODO: that's a lot of memory */
         dev->rx_buffers[i].page = (char*)alloc_page();
     }
 
-    snprintf(path, sizeof(path), "%s/backend-id", nodename);
+    snprintf(path, sizeof(path), "%s/backend-id", dev->nodename);
     dev->dom = xenbus_read_integer(path);
 #ifdef HAVE_LIBC
     if (thenetif_rx == NETIF_SELECT_RX)
@@ -343,22 +423,19 @@ struct netfront_dev *init_netfront(char *_nodename, void (*thenetif_rx)(unsigned
 
     txs = (struct netif_tx_sring *) alloc_page();
     rxs = (struct netif_rx_sring *) alloc_page();
-    memset(txs,0,PAGE_SIZE);
-    memset(rxs,0,PAGE_SIZE);
-
+    memset(txs, 0, PAGE_SIZE);
+    memset(rxs, 0, PAGE_SIZE);
 
     SHARED_RING_INIT(txs);
     SHARED_RING_INIT(rxs);
     FRONT_RING_INIT(&dev->tx, txs, PAGE_SIZE);
     FRONT_RING_INIT(&dev->rx, rxs, PAGE_SIZE);
 
-    dev->tx_ring_ref = gnttab_grant_access(dev->dom,virt_to_mfn(txs),0);
-    dev->rx_ring_ref = gnttab_grant_access(dev->dom,virt_to_mfn(rxs),0);
+    dev->tx_ring_ref = gnttab_grant_access(dev->dom, virt_to_mfn(txs), 0);
+    dev->rx_ring_ref = gnttab_grant_access(dev->dom, virt_to_mfn(rxs), 0);
 
     init_rx_buffers(dev);
 
-    dev->netif_rx = thenetif_rx;
-
     dev->events = NULL;
 
 again:
@@ -368,33 +445,31 @@ again:
         free(err);
     }
 
-    err = xenbus_printf(xbt, nodename, "tx-ring-ref","%u",
-                dev->tx_ring_ref);
+    err = xenbus_printf(xbt, dev->nodename, "tx-ring-ref","%u",
+                        dev->tx_ring_ref);
     if (err) {
         message = "writing tx ring-ref";
         goto abort_transaction;
     }
-    err = xenbus_printf(xbt, nodename, "rx-ring-ref","%u",
-                dev->rx_ring_ref);
+    err = xenbus_printf(xbt, dev->nodename, "rx-ring-ref","%u",
+                        dev->rx_ring_ref);
     if (err) {
         message = "writing rx ring-ref";
         goto abort_transaction;
     }
-    err = xenbus_printf(xbt, nodename,
-                "event-channel", "%u", dev->evtchn);
+    err = xenbus_printf(xbt, dev->nodename, "event-channel", "%u", dev->evtchn);
     if (err) {
         message = "writing event-channel";
         goto abort_transaction;
     }
 
-    err = xenbus_printf(xbt, nodename, "request-rx-copy", "%u", 1);
-
+    err = xenbus_printf(xbt, dev->nodename, "request-rx-copy", "%u", 1);
     if (err) {
         message = "writing request-rx-copy";
         goto abort_transaction;
     }
 
-    snprintf(path, sizeof(path), "%s/state", nodename);
+    snprintf(path, sizeof(path), "%s/state", dev->nodename);
     err = xenbus_switch_state(xbt, path, XenbusStateConnected);
     if (err) {
         message = "switching state";
@@ -404,7 +479,7 @@ again:
     err = xenbus_transaction_end(xbt, 0, &retry);
     free(err);
     if (retry) {
-            goto again;
+        goto again;
         printk("completing transaction\n");
     }
 
@@ -417,10 +492,9 @@ abort_transaction:
     goto error;
 
 done:
-
-    snprintf(path, sizeof(path), "%s/backend", nodename);
+    snprintf(path, sizeof(path), "%s/backend", dev->nodename);
     msg = xenbus_read(XBT_NIL, path, &dev->backend);
-    snprintf(path, sizeof(path), "%s/mac", nodename);
+    snprintf(path, sizeof(path), "%s/mac", dev->nodename);
     msg = xenbus_read(XBT_NIL, path, &dev->mac);
 
     if ((dev->backend == NULL) || (dev->mac == NULL)) {
@@ -428,8 +502,8 @@ done:
         goto error;
     }
 
-    printk("backend at %s\n",dev->backend);
-    printk("mac is %s\n",dev->mac);
+    printk("backend at %s\n", dev->backend);
+    printk("mac is %s\n", dev->mac);
 
     {
         XenbusState state;
@@ -458,18 +532,20 @@ done:
 
     unmask_evtchn(dev->evtchn);
 
-        /* Special conversion specifier 'hh' needed for __ia64__. Without
-           this mini-os panics with 'Unaligned reference'. */
+    /* Special conversion specifier 'hh' needed for __ia64__. Without
+     * this mini-os panics with 'Unaligned reference'.
+     */
     if (rawmac)
-	sscanf(dev->mac,"%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
-            &rawmac[0],
-            &rawmac[1],
-            &rawmac[2],
-            &rawmac[3],
-            &rawmac[4],
-            &rawmac[5]);
+	    sscanf(dev->mac,"%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
+               &rawmac[0],
+               &rawmac[1],
+               &rawmac[2],
+               &rawmac[3],
+               &rawmac[4],
+               &rawmac[5]);
 
     return dev;
+
 error:
     free(msg);
     free(err);
@@ -496,6 +572,40 @@ int netfront_tap_open(char *nodename) {
 
 void shutdown_netfront(struct netfront_dev *dev)
 {
+    struct netfront_dev_list *list = NULL;
+    struct netfront_dev_list *to_del = NULL;
+
+    /* Check this is a valid device */
+    for (list = dev_list; list != NULL; list = list->next) {
+	    if (list->dev == dev)
+		    break;
+    }
+
+    if (!list) {
+	    printk("Trying to shutdown an invalid netfront device (%p)\n", dev);
+        return;
+    }
+
+    list->refcount--;
+    if (list->refcount == 0) {
+	    _shutdown_netfront(dev);
+	    free(dev->nodename);
+	    free(dev);
+
+	    to_del = list;
+        if (to_del == dev_list) {
+            free(to_del);
+			dev_list = NULL;
+        } else {
+	        for (list = dev_list; list->next != to_del; list = list->next);
+	        list->next = to_del->next;
+            free(to_del);
+        }
+    }
+}
+
+static void _shutdown_netfront(struct netfront_dev *dev)
+{
     char* err = NULL, *err2;
     XenbusState state;
 
@@ -559,6 +669,21 @@ close:
         free_netfront(dev);
 }
 
+void suspend_netfront(void)
+{
+    struct netfront_dev_list *list;
+
+    for (list = dev_list; list != NULL; list = list->next)
+        _shutdown_netfront(list->dev);
+}
+
+void resume_netfront(void)
+{
+    struct netfront_dev_list *list;
+
+    for (list = dev_list; list != NULL; list = list->next)
+        _init_netfront(list->dev, NULL, NULL);
+}
 
 void init_rx_buffers(struct netfront_dev *dev)
 {
@@ -665,3 +790,14 @@ ssize_t netfront_receive(struct netfront_dev *dev, unsigned char *data, size_t l
     return dev->rlen;
 }
 #endif
+
+void netfront_set_rx_handler(struct netfront_dev *dev,
+			                 void (*thenetif_rx)(unsigned char *data, int len,
+			                 void *arg), void *arg)
+{
+    if (dev->netif_rx && dev->netif_rx != netif_rx)
+        printk("Replacing netif_rx handler for dev %s\n", dev->nodename);
+
+    dev->netif_rx = thenetif_rx;
+    dev->netif_rx_arg = arg;
+}
-- 
2.3.2 (Apple Git-55)


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH RFC 16/16] Save/Restore Support: Implement code for arch suspend/resume
  2017-12-19 23:41 [PATCH RFC 00/16] Save/Restore Support for mini-OS PVH Bruno Alvisio
                   ` (14 preceding siblings ...)
  2017-12-19 23:42 ` [PATCH RFC 15/16] Save/Restore Support: Add suspend/restore support for netfront Bruno Alvisio
@ 2017-12-19 23:42 ` Bruno Alvisio
  2017-12-20  0:19 ` [Minios-devel] [PATCH RFC 00/16] Save/Restore Support for mini-OS PVH Samuel Thibault
                   ` (3 subsequent siblings)
  19 siblings, 0 replies; 34+ messages in thread
From: Bruno Alvisio @ 2017-12-19 23:42 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: jgross, samuel.thibault, wei.liu2, 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.

Signed-off-by: Bruno Alvisio <bruno.alvisio@gmail.com>
---
 arch/x86/setup.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)

diff --git a/arch/x86/setup.c b/arch/x86/setup.c
index 3eabce4..a525e73 100644
--- a/arch/x86/setup.c
+++ b/arch/x86/setup.c
@@ -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 pfns with the correspondent mfns */
+    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
-- 
2.3.2 (Apple Git-55)


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* Re: [Minios-devel] [PATCH RFC 01/16] Save/Restore Support: Refactor HYPERVISOR_suspend hypercall
  2017-12-19 23:41 ` [PATCH RFC 01/16] Save/Restore Support: Refactor HYPERVISOR_suspend hypercall Bruno Alvisio
@ 2017-12-19 23:51   ` Samuel Thibault
  0 siblings, 0 replies; 34+ messages in thread
From: Samuel Thibault @ 2017-12-19 23:51 UTC (permalink / raw)
  To: Bruno Alvisio; +Cc: minios-devel, xen-devel, wei.liu2, jgross

Bruno Alvisio, on mar. 19 déc. 2017 15:41:56 -0800, wrote:
> 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.
> 
> Signed-off-by: Bruno Alvisio <bruno.alvisio@gmail.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  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(-)
> 
> diff --git a/include/x86/x86_32/hypercall-x86_32.h b/include/x86/x86_32/hypercall-x86_32.h
> index 5c93464..70505a4 100644
> --- a/include/x86/x86_32/hypercall-x86_32.h
> +++ b/include/x86/x86_32/hypercall-x86_32.h
> @@ -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
> diff --git a/include/x86/x86_64/hypercall-x86_64.h b/include/x86/x86_64/hypercall-x86_64.h
> index 6171812..95f8ade 100644
> --- a/include/x86/x86_64/hypercall-x86_64.h
> +++ b/include/x86/x86_64/hypercall-x86_64.h
> @@ -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
> -- 
> 2.3.2 (Apple Git-55)
> 
> 
> _______________________________________________
> Minios-devel mailing list
> Minios-devel@lists.xenproject.org
> https://lists.xenproject.org/mailman/listinfo/minios-devel

-- 
Samuel
<T> csp.tar.gz:     ascii text
 -+- #ens-mim - vive les browsers qui prennent des initiatives à la con -+-

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [Minios-devel] [PATCH RFC 02/16] Save/Restore Support: Refactor trap_init() and setup vector callbacks
  2017-12-19 23:41 ` [PATCH RFC 02/16] Save/Restore Support: Refactor trap_init() and setup vector callbacks Bruno Alvisio
@ 2017-12-19 23:51   ` Samuel Thibault
  0 siblings, 0 replies; 34+ messages in thread
From: Samuel Thibault @ 2017-12-19 23:51 UTC (permalink / raw)
  To: Bruno Alvisio; +Cc: minios-devel, xen-devel, Bruno Alvisio, wei.liu2, jgross

Bruno Alvisio, on mar. 19 déc. 2017 15:41:57 -0800, wrote:
> 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.
> 
> Signed-off-by: Bruno Alvisio <bruno.alvisio@oracle.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  arch/x86/traps.c | 17 +++++++++++------
>  include/x86/os.h |  3 +++
>  2 files changed, 14 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/x86/traps.c b/arch/x86/traps.c
> index aa17da3..a7388a5 100644
> --- a/arch/x86/traps.c
> +++ b/arch/x86/traps.c
> @@ -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)
> diff --git a/include/x86/os.h b/include/x86/os.h
> index fbc2eeb..d155914 100644
> --- a/include/x86/os.h
> +++ b/include/x86/os.h
> @@ -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);
>  
> -- 
> 2.3.2 (Apple Git-55)
> 
> 
> _______________________________________________
> Minios-devel mailing list
> Minios-devel@lists.xenproject.org
> https://lists.xenproject.org/mailman/listinfo/minios-devel

-- 
Samuel
<O> Ça peut être une madeleine à sous munitions (avec des composants,
par exemple)
 -+- #runtime -+-

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [Minios-devel] [PATCH RFC 03/16] Save/Restore Support: Declare kernel and arch pre/post suspend functions
  2017-12-19 23:41 ` [PATCH RFC 03/16] Save/Restore Support: Declare kernel and arch pre/post suspend functions Bruno Alvisio
@ 2017-12-19 23:52   ` Samuel Thibault
  0 siblings, 0 replies; 34+ messages in thread
From: Samuel Thibault @ 2017-12-19 23:52 UTC (permalink / raw)
  To: Bruno Alvisio; +Cc: minios-devel, xen-devel, wei.liu2, jgross

Bruno Alvisio, on mar. 19 déc. 2017 15:41:58 -0800, wrote:
> 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.
> 
> Signed-off-by: Bruno Alvisio <bruno.alvisio@gmail.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  arch/x86/setup.c | 10 ++++++++++
>  include/kernel.h |  2 ++
>  include/x86/os.h |  4 ++--
>  kernel.c         | 10 ++++++++++
>  4 files changed, 24 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/x86/setup.c b/arch/x86/setup.c
> index 5278227..3dd86f9 100644
> --- a/arch/x86/setup.c
> +++ b/arch/x86/setup.c
> @@ -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)
>  {
> diff --git a/include/kernel.h b/include/kernel.h
> index d37ddda..161d757 100644
> --- a/include/kernel.h
> +++ b/include/kernel.h
> @@ -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);
> diff --git a/include/x86/os.h b/include/x86/os.h
> index d155914..a73b63e 100644
> --- a/include/x86/os.h
> +++ b/include/x86/os.h
> @@ -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
>  
>  /* 
> diff --git a/kernel.c b/kernel.c
> index 0d84a9b..90c865a 100644
> --- a/kernel.c
> +++ b/kernel.c
> @@ -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 */
> -- 
> 2.3.2 (Apple Git-55)
> 
> 
> _______________________________________________
> Minios-devel mailing list
> Minios-devel@lists.xenproject.org
> https://lists.xenproject.org/mailman/listinfo/minios-devel

-- 
Samuel
<g> r: et la marmotte, elle écrit un papier IPDPS

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [Minios-devel] [PATCH RFC 04/16] Save/Restore Support: Add xenbus_release_wait_for_watch
  2017-12-19 23:41 ` [PATCH RFC 04/16] Save/Restore Support: Add xenbus_release_wait_for_watch Bruno Alvisio
@ 2017-12-20  0:14   ` Samuel Thibault
  0 siblings, 0 replies; 34+ messages in thread
From: Samuel Thibault @ 2017-12-20  0:14 UTC (permalink / raw)
  To: Bruno Alvisio; +Cc: minios-devel, xen-devel, wei.liu2, jgross

Bruno Alvisio, on mar. 19 déc. 2017 15:41:59 -0800, wrote:
> 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.

Please also document the release_xenbus_id change.

> Signed-off-by: Bruno Alvisio <bruno.alvisio@gmail.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  include/xenbus.h |  1 +
>  xenbus/xenbus.c  | 10 +++++++++-
>  2 files changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/include/xenbus.h b/include/xenbus.h
> index 12391b9..b2d5072 100644
> --- a/include/xenbus.h
> +++ b/include/xenbus.h
> @@ -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);
> diff --git a/xenbus/xenbus.c b/xenbus/xenbus.c
> index 636786c..c2d2bd1 100644
> --- a/xenbus/xenbus.c
> +++ b/xenbus/xenbus.c
> @@ -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);
>  }
> -- 
> 2.3.2 (Apple Git-55)
> 
> 
> _______________________________________________
> Minios-devel mailing list
> Minios-devel@lists.xenproject.org
> https://lists.xenproject.org/mailman/listinfo/minios-devel

-- 
Samuel
"c'est pas nous qui sommes à la rue, c'est la rue qui est à nous"

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [Minios-devel] [PATCH RFC 05/16] Save/Restore Support: Add kernel shutdown logic to shutdown.c
  2017-12-19 23:42 ` [PATCH RFC 05/16] Save/Restore Support: Add kernel shutdown logic to shutdown.c Bruno Alvisio
@ 2017-12-20  0:16   ` Samuel Thibault
  2017-12-21 22:49   ` Konrad Rzeszutek Wilk
  1 sibling, 0 replies; 34+ messages in thread
From: Samuel Thibault @ 2017-12-20  0:16 UTC (permalink / raw)
  To: Bruno Alvisio; +Cc: minios-devel, xen-devel, wei.liu2, jgross

Bruno Alvisio, on mar. 19 déc. 2017 15:42:00 -0800, wrote:
> + *          NEC Europe Ltd. PROPRIETARY INFORMATION
> + *
> + * This software is supplied under the terms of a license agreement
> + * or nondisclosure agreement with NEC Europe Ltd. and may not be
> + * copied or disclosed except in accordance with the terms of that
> + * agreement. The software and its source code contain valuable trade
> + * secrets and confidential information which have to be maintained in
> + * confidence.
> + * Any unauthorized publication, transfer to third parties or duplication
> + * of the object or source code - either totally or in part – is
> + * prohibited.
> + *
> + *      Copyright (c) 2014 NEC Europe Ltd. All Rights Reserved.
> + *
> + * Authors: Filipe Manco <filipe.manco@neclab.eu>
> + *
> + * NEC Europe Ltd. DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED,
> + * INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY
> + * AND FITNESS FOR A PARTICULAR PURPOSE AND THE WARRANTY AGAINST LATENT
> + * DEFECTS, WITH RESPECT TO THE PROGRAM AND THE ACCOMPANYING
> + * DOCUMENTATION.
> + *
> + * No Liability For Consequential Damages IN NO EVENT SHALL NEC Europe
> + * Ltd., NEC Corporation OR ANY OF ITS SUBSIDIARIES BE LIABLE FOR ANY
> + * DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS
> + * OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF INFORMATION, OR
> + * OTHER PECUNIARY LOSS AND INDIRECT, CONSEQUENTIAL, INCIDENTAL,
> + * ECONOMIC OR PUNITIVE DAMAGES) ARISING OUT OF THE USE OF OR INABILITY
> + * TO USE THIS PROGRAM, EVEN IF NEC Europe Ltd. HAS BEEN ADVISED OF THE
> + * POSSIBILITY OF SUCH DAMAGES.
> + *
> + *     THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.

Err, AIUI, this makes it unusable for mini-os (or whatever free
software).

Samuel

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [Minios-devel] [PATCH RFC 00/16] Save/Restore Support for mini-OS PVH
  2017-12-19 23:41 [PATCH RFC 00/16] Save/Restore Support for mini-OS PVH Bruno Alvisio
                   ` (15 preceding siblings ...)
  2017-12-19 23:42 ` [PATCH RFC 16/16] Save/Restore Support: Implement code for arch suspend/resume Bruno Alvisio
@ 2017-12-20  0:19 ` Samuel Thibault
  2017-12-20  0:37 ` Samuel Thibault
                   ` (2 subsequent siblings)
  19 siblings, 0 replies; 34+ messages in thread
From: Samuel Thibault @ 2017-12-20  0:19 UTC (permalink / raw)
  To: Bruno Alvisio; +Cc: minios-devel, xen-devel, wei.liu2, jgross

I can't find patch 06 in my mbox, but

Bruno Alvisio, on mar. 19 déc. 2017 15:41:55 -0800, wrote:
> I have been working on supporting save/restore for mini-os PVH. Some parts of
> the implementation were taken from the sysml/mini-os repository. The branch can
> be found at:
> 
> https://github.com/balvisio/mini-os/tree/feature/mini-os-suspend-support

I got commit 3869ff5bf4e88d708fb62c16fbe8eb9c0eee9d45 from there, and
you can consider it

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

Samuel

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [Minios-devel] [PATCH RFC 07/16] Save/Restore Support: Add unmap_shared_info
  2017-12-19 23:42 ` [PATCH RFC 07/16] Save/Restore Support: Add unmap_shared_info Bruno Alvisio
@ 2017-12-20  0:23   ` Samuel Thibault
  0 siblings, 0 replies; 34+ messages in thread
From: Samuel Thibault @ 2017-12-20  0:23 UTC (permalink / raw)
  To: Bruno Alvisio; +Cc: minios-devel, xen-devel, wei.liu2, jgross

Bruno Alvisio, on mar. 19 déc. 2017 15:42:02 -0800, wrote:
> This function is necessary as part of the pre-suspend operation.
> 
> Signed-off-by: Bruno Alvisio <bruno.alvisio@gmail.com>
> ---

> +void unmap_shared_info(void)
> +{
> +    int rc;
> +
> +    if ( (rc = HYPERVISOR_update_va_mapping((unsigned long)HYPERVISOR_shared_info,

For coherency, I'd say use shared_info there too.
Apart from that,

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> +            __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;
> diff --git a/hypervisor.c b/hypervisor.c
> index 1647121..d3857e7 100644
> --- a/hypervisor.c
> +++ b/hypervisor.c
> @@ -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)
> diff --git a/include/hypervisor.h b/include/hypervisor.h
> index f3b1f3c..1d09271 100644
> --- a/include/hypervisor.h
> +++ b/include/hypervisor.h
> @@ -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);
> -- 
> 2.3.2 (Apple Git-55)
> 
> 
> _______________________________________________
> Minios-devel mailing list
> Minios-devel@lists.xenproject.org
> https://lists.xenproject.org/mailman/listinfo/minios-devel

-- 
Samuel
<y> la vraie vie, c'est quand le prompt passe de $ à #

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [Minios-devel] [PATCH RFC 08/16] Save/Restore Support: Add arch_mm_pre|post_suspend
  2017-12-19 23:42 ` [PATCH RFC 08/16] Save/Restore Support: Add arch_mm_pre|post_suspend Bruno Alvisio
@ 2017-12-20  0:24   ` Samuel Thibault
  0 siblings, 0 replies; 34+ messages in thread
From: Samuel Thibault @ 2017-12-20  0:24 UTC (permalink / raw)
  To: Bruno Alvisio; +Cc: minios-devel, xen-devel, Bruno Alvisio, wei.liu2, jgross

Bruno Alvisio, on mar. 19 déc. 2017 15:42:03 -0800, wrote:
> 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.
> 
> Signed-off-by: Bruno Alvisio <bruno.alvisio@oracle.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  arch/x86/mm.c         | 14 ++++++++++++++
>  include/x86/arch_mm.h |  3 +++
>  2 files changed, 17 insertions(+)
> 
> diff --git a/arch/x86/mm.c b/arch/x86/mm.c
> index 05ad029..1b163ac 100644
> --- a/arch/x86/mm.c
> +++ b/arch/x86/mm.c
> @@ -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)
> diff --git a/include/x86/arch_mm.h b/include/x86/arch_mm.h
> index ab8a53e..cbbeb21 100644
> --- a/include/x86/arch_mm.h
> +++ b/include/x86/arch_mm.h
> @@ -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
> -- 
> 2.3.2 (Apple Git-55)
> 
> 
> _______________________________________________
> Minios-devel mailing list
> Minios-devel@lists.xenproject.org
> https://lists.xenproject.org/mailman/listinfo/minios-devel

-- 
Samuel
 J'ai un gros problème: j'ai cet exercice à rendre demain lundi, mais ma
 TI 89 ne sait pas le faire...
 Est-ce que quelqu'un pourrait m'aider??
 -+- OD In Guide du Neuneu Usenet : Comment ça ! Il faut réfléchir ?-+-

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [Minios-devel] [PATCH RFC 09/16] Save/Restore Support: Disable/enable IRQs during suspend/restore
  2017-12-19 23:42 ` [PATCH RFC 09/16] Save/Restore Support: Disable/enable IRQs during suspend/restore Bruno Alvisio
@ 2017-12-20  0:25   ` Samuel Thibault
  0 siblings, 0 replies; 34+ messages in thread
From: Samuel Thibault @ 2017-12-20  0:25 UTC (permalink / raw)
  To: Bruno Alvisio; +Cc: minios-devel, xen-devel, wei.liu2, jgross

Bruno Alvisio, on mar. 19 déc. 2017 15:42:04 -0800, wrote:
> Signed-off-by: Bruno Alvisio <bruno.alvisio@gmail.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  kernel.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel.c b/kernel.c
> index 1cd40e8..782eb79 100644
> --- a/kernel.c
> +++ b/kernel.c
> @@ -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)
> -- 
> 2.3.2 (Apple Git-55)
> 
> 
> _______________________________________________
> Minios-devel mailing list
> Minios-devel@lists.xenproject.org
> https://lists.xenproject.org/mailman/listinfo/minios-devel

-- 
Samuel
Q:	How do you play religious roulette?
A:	You stand around in a circle and blaspheme and see who gets struck by lightning first.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [Minios-devel] [PATCH RFC 10/16] Save/Restore Support: Add suspend/resume support for timers
  2017-12-19 23:42 ` [PATCH RFC 10/16] Save/Restore Support: Add suspend/resume support for timers Bruno Alvisio
@ 2017-12-20  0:26   ` Samuel Thibault
  0 siblings, 0 replies; 34+ messages in thread
From: Samuel Thibault @ 2017-12-20  0:26 UTC (permalink / raw)
  To: Bruno Alvisio; +Cc: minios-devel, xen-devel, wei.liu2, jgross

Bruno Alvisio, on mar. 19 déc. 2017 15:42:05 -0800, wrote:
> Signed-off-by: Bruno Alvisio <bruno.alvisio@gmail.com>

> +void resume_time(void)
> +{
> +    port = bind_virq(VIRQ_TIMER, &timer_handler, NULL);
> +    unmask_evtchn(port);
> +}

I'd say rather factorize it with init_time.
(you could even just remove the printf there to avoid having to write
yet another function)

> diff --git a/include/time.h b/include/time.h
> index 5d6ed67..2e06d58 100644
> --- a/include/time.h
> +++ b/include/time.h
> @@ -55,6 +55,8 @@ typedef long suseconds_t;
>  /* prototypes */
>  void     init_time(void);
>  void     fini_time(void);
> +void     suspend_time(void);
> +void     resume_time(void);
>  s_time_t get_s_time(void);
>  s_time_t get_v_time(void);
>  uint64_t monotonic_clock(void);
> diff --git a/kernel.c b/kernel.c
> index 782eb79..a16b1ba 100644
> --- a/kernel.c
> +++ b/kernel.c
> @@ -120,10 +120,14 @@ void start_kernel(void* par)
>  void pre_suspend(void)
>  {
>      local_irq_disable();
> +
> +    suspend_time();
>  }
>  
>  void post_suspend(int canceled)
>  {
> +    resume_time();
> +
>      local_irq_enable();
>  }
>  
> -- 
> 2.3.2 (Apple Git-55)
> 
> 
> _______________________________________________
> Minios-devel mailing list
> Minios-devel@lists.xenproject.org
> https://lists.xenproject.org/mailman/listinfo/minios-devel

-- 
Samuel
<y> ça gaze ?
<l> prout
 -+- #ens-mim - ouvrez les fenêtres ! -+-

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [Minios-devel] [PATCH RFC 00/16] Save/Restore Support for mini-OS PVH
  2017-12-19 23:41 [PATCH RFC 00/16] Save/Restore Support for mini-OS PVH Bruno Alvisio
                   ` (16 preceding siblings ...)
  2017-12-20  0:19 ` [Minios-devel] [PATCH RFC 00/16] Save/Restore Support for mini-OS PVH Samuel Thibault
@ 2017-12-20  0:37 ` Samuel Thibault
  2017-12-20  0:57 ` Samuel Thibault
  2017-12-20  1:01 ` Samuel Thibault
  19 siblings, 0 replies; 34+ messages in thread
From: Samuel Thibault @ 2017-12-20  0:37 UTC (permalink / raw)
  To: Bruno Alvisio; +Cc: minios-devel, xen-devel, wei.liu2, jgross

Again, I didn't find patch 11, so I got it from here

Bruno Alvisio, on mar. 19 déc. 2017 15:41:55 -0800, wrote:
> https://github.com/balvisio/mini-os/tree/feature/mini-os-suspend-support

There are indentation oddities bringing spurious hunks. Apart from that,

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

Samuel

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [Minios-devel] [PATCH RFC 12/16] Save/Restore Support: Add support for suspend/restore events.
  2017-12-19 23:42 ` [PATCH RFC 12/16] Save/Restore Support: Add support for suspend/restore events Bruno Alvisio
@ 2017-12-20  0:37   ` Samuel Thibault
  0 siblings, 0 replies; 34+ messages in thread
From: Samuel Thibault @ 2017-12-20  0:37 UTC (permalink / raw)
  To: Bruno Alvisio; +Cc: minios-devel, xen-devel, wei.liu2, jgross

Bruno Alvisio, on mar. 19 déc. 2017 15:42:07 -0800, wrote:
> Signed-off-by: Bruno Alvisio <bruno.alvisio@gmail.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  events.c         | 5 +++++
>  include/events.h | 1 +
>  kernel.c         | 2 ++
>  3 files changed, 8 insertions(+)
> 
> diff --git a/events.c b/events.c
> index e8ef8aa..342aead 100644
> --- a/events.c
> +++ b/events.c
> @@ -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);
> diff --git a/include/events.h b/include/events.h
> index 89b5997..705ad93 100644
> --- a/include/events.h
> +++ b/include/events.h
> @@ -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_ */
> diff --git a/kernel.c b/kernel.c
> index fd1c4c5..c6ff9f3 100644
> --- a/kernel.c
> +++ b/kernel.c
> @@ -124,6 +124,8 @@ void pre_suspend(void)
>      suspend_time();
>  
>      suspend_console();
> +
> +    suspend_events();
>  }
>  
>  void post_suspend(int canceled)
> -- 
> 2.3.2 (Apple Git-55)
> 
> 
> _______________________________________________
> Minios-devel mailing list
> Minios-devel@lists.xenproject.org
> https://lists.xenproject.org/mailman/listinfo/minios-devel

-- 
Samuel
X-Favorit-Cartoon: Calvin and Hobbes
 -+- Mail header of Wim van Dorst -+-

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [Minios-devel] [PATCH RFC 13/16] Save/Restore Support: Add suspend/restore support for Grant Tables.
  2017-12-19 23:42 ` [PATCH RFC 13/16] Save/Restore Support: Add suspend/restore support for Grant Tables Bruno Alvisio
@ 2017-12-20  0:40   ` Samuel Thibault
  0 siblings, 0 replies; 34+ messages in thread
From: Samuel Thibault @ 2017-12-20  0:40 UTC (permalink / raw)
  To: Bruno Alvisio; +Cc: minios-devel, xen-devel, wei.liu2, jgross

Bruno Alvisio, on mar. 19 déc. 2017 15:42:08 -0800, wrote:

> +void suspend_gnttab(void)
> +{
> +#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 resume_gnttab(void)
> +{...

The initialization in arch_init_gnttab is different for arm, so I'd say
this should be arch-specific.

Samuel

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [Minios-devel] [PATCH RFC 14/16] Save/Restore Support: Add suspend/restore support for xenbus
  2017-12-19 23:42 ` [PATCH RFC 14/16] Save/Restore Support: Add suspend/restore support for xenbus Bruno Alvisio
@ 2017-12-20  0:43   ` Samuel Thibault
  0 siblings, 0 replies; 34+ messages in thread
From: Samuel Thibault @ 2017-12-20  0:43 UTC (permalink / raw)
  To: Bruno Alvisio; +Cc: minios-devel, xen-devel, wei.liu2, jgross

Bruno Alvisio, on mar. 19 déc. 2017 15:42:09 -0800, wrote:
> 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.
> 
> Signed-off-by: Bruno Alvisio <bruno.alvisio@gmail.com>

Again, there are spurious hunks in this patch due to oddities in
indentation, please remove them. Apart from that,

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  include/xenbus.h |   2 ++
>  kernel.c         |   8 +++++
>  xenbus/xenbus.c  | 106 +++++++++++++++++++++++++++++++++++++++----------------
>  3 files changed, 85 insertions(+), 31 deletions(-)
> 
> diff --git a/include/xenbus.h b/include/xenbus.h
> index b2d5072..3871f35 100644
> --- a/include/xenbus.h
> +++ b/include/xenbus.h
> @@ -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)
>  {
> diff --git a/kernel.c b/kernel.c
> index a563f60..bc2394f 100644
> --- a/kernel.c
> +++ b/kernel.c
> @@ -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)
> diff --git a/xenbus/xenbus.c b/xenbus/xenbus.c
> index c2d2bd1..4c626fb 100644
> --- a/xenbus/xenbus.c
> +++ b/xenbus/xenbus.c
> @@ -50,6 +50,7 @@ DECLARE_WAIT_QUEUE_HEAD(xenbus_watch_queue);
>  xenbus_event_queue xenbus_events;
>  static struct watch {
>      char *token;
> +    char *path;
>      xenbus_event_queue *events;
>      struct watch *next;
>  } *watches;
> @@ -63,6 +64,8 @@ struct xenbus_req_info
>  #define NR_REQS 32
>  static struct xenbus_req_info req_info[NR_REQS];
>  
> +static char *errmsg(struct xsd_sockmsg *rep);
> +
>  uint32_t xenbus_evtchn;
>  
>  #ifdef CONFIG_PARAVIRT
> @@ -231,45 +234,39 @@ static void xenbus_thread_func(void *ign)
>      struct xsd_sockmsg msg;
>      unsigned prod = xenstore_buf->rsp_prod;
>  
> -    for (;;) 
> -    {
> +    for (;;) {
>          wait_event(xb_waitq, prod != xenstore_buf->rsp_prod);
> -        while (1) 
> -        {
> +        while (1) {
>              prod = xenstore_buf->rsp_prod;
>              DEBUG("Rsp_cons %d, rsp_prod %d.\n", xenstore_buf->rsp_cons,
> -                    xenstore_buf->rsp_prod);
> +                  xenstore_buf->rsp_prod);
>              if (xenstore_buf->rsp_prod - xenstore_buf->rsp_cons < sizeof(msg))
>                  break;
>              rmb();
> -            memcpy_from_ring(xenstore_buf->rsp,
> -                    &msg,
> -                    MASK_XENSTORE_IDX(xenstore_buf->rsp_cons),
> -                    sizeof(msg));
> -            DEBUG("Msg len %d, %d avail, id %d.\n",
> -                    msg.len + sizeof(msg),
> -                    xenstore_buf->rsp_prod - xenstore_buf->rsp_cons,
> -                    msg.req_id);
> +            memcpy_from_ring(xenstore_buf->rsp, &msg,
> +                             MASK_XENSTORE_IDX(xenstore_buf->rsp_cons),
> +                             sizeof(msg));
> +            DEBUG("Msg len %d, %d avail, id %d.\n", msg.len + sizeof(msg),
> +                  xenstore_buf->rsp_prod - xenstore_buf->rsp_cons, msg.req_id);
> +
>              if (xenstore_buf->rsp_prod - xenstore_buf->rsp_cons <
> -                    sizeof(msg) + msg.len)
> +                sizeof(msg) + msg.len)
>                  break;
>  
>              DEBUG("Message is good.\n");
>  
> -            if(msg.type == XS_WATCH_EVENT)
> -            {
> -		struct xenbus_event *event = malloc(sizeof(*event) + msg.len);
> +            if (msg.type == XS_WATCH_EVENT) {
> +		        struct xenbus_event *event = malloc(sizeof(*event) + msg.len);
>                  xenbus_event_queue *events = NULL;
> -		char *data = (char*)event + sizeof(*event);
> +		        char *data = (char*)event + sizeof(*event);
>                  struct watch *watch;
>  
> -                memcpy_from_ring(xenstore_buf->rsp,
> -		    data,
> +                memcpy_from_ring(xenstore_buf->rsp, data,
>                      MASK_XENSTORE_IDX(xenstore_buf->rsp_cons + sizeof(msg)),
>                      msg.len);
>  
> -		event->path = data;
> -		event->token = event->path + strlen(event->path) + 1;
> +		        event->path = data;
> +		        event->token = event->path + strlen(event->path) + 1;
>  
>                  mb();
>                  xenstore_buf->rsp_cons += msg.len + sizeof(msg);
> @@ -288,15 +285,11 @@ static void xenbus_thread_func(void *ign)
>                      printk("unexpected watch token %s\n", event->token);
>                      free(event);
>                  }
> -            }
> -
> -            else
> -            {
> +            } else {
>                  req_info[msg.req_id].reply = malloc(sizeof(msg) + msg.len);
> -                memcpy_from_ring(xenstore_buf->rsp,
> -                    req_info[msg.req_id].reply,
> -                    MASK_XENSTORE_IDX(xenstore_buf->rsp_cons),
> -                    msg.len + sizeof(msg));
> +                memcpy_from_ring(xenstore_buf->rsp, req_info[msg.req_id].reply,
> +                                 MASK_XENSTORE_IDX(xenstore_buf->rsp_cons),
> +                                 msg.len + sizeof(msg));
>                  mb();
>                  xenstore_buf->rsp_cons += msg.len + sizeof(msg);
>                  wake_up(&req_info[msg.req_id].waitq);
> @@ -380,6 +373,55 @@ void fini_xenbus(void)
>  {
>  }
>  
> +void suspend_xenbus(void)
> +{
> +  /* Check for live requests and wait until they finish */
> +    while (1)
> +    {
> +        spin_lock(&req_lock);
> +        if (nr_live_reqs == 0)
> +            break;
> +        spin_unlock(&req_lock);
> +        wait_event(req_wq, (nr_live_reqs == 0));
> +    }
> +
> +    mask_evtchn(xenbus_evtchn);
> +    xenstore_buf = NULL;
> +    spin_unlock(&req_lock);
> +}
> +
> +void resume_xenbus(int canceled)
> +{
> +    char *msg;
> +    struct watch *watch;
> +    struct write_req req[2];
> +    struct xsd_sockmsg *rep;
> +
> +#ifdef CONFIG_PARAVIRT
> +    get_xenbus(&start_info);
> +#else
> +    get_xenbus(0);
> +#endif
> +    unmask_evtchn(xenbus_evtchn);
> +
> +    if (!canceled) {
> +        for (watch = watches; watch; watch = watch->next) {
> +            req[0].data = watch->path;
> +            req[0].len = strlen(watch->path) + 1;
> +            req[1].data = watch->token;
> +            req[1].len = strlen(watch->token) + 1;
> +
> +            rep = xenbus_msg_reply(XS_WATCH, XBT_NIL, req, ARRAY_SIZE(req));
> +            msg = errmsg(rep);
> +            if (msg)
> +                xprintk("error on XS_WATCH: %s\n", msg);
> +            free(rep);
> +        }
> +    }
> +
> +    notify_remote_via_evtchn(xenbus_evtchn);
> +}
> +
>  /* Send data to xenbus.  This can block.  All of the requests are seen
>     by xenbus as if sent atomically.  The header is added
>     automatically, using type %type, req_id %req_id, and trans_id
> @@ -501,7 +543,7 @@ static char *errmsg(struct xsd_sockmsg *rep)
>      res[rep->len] = 0;
>      free(rep);
>      return res;
> -}	
> +}
>  
>  /* Send a debug message to xenbus.  Can block. */
>  static void xenbus_debug_msg(const char *msg)
> @@ -601,6 +643,7 @@ char* xenbus_watch_path_token( xenbus_transaction_t xbt, const char *path, const
>          events = &xenbus_events;
>  
>      watch->token = strdup(token);
> +    watch->path = strdup(path);
>      watch->events = events;
>      watch->next = watches;
>      watches = watch;
> @@ -636,6 +679,7 @@ char* xenbus_unwatch_path_token( xenbus_transaction_t xbt, const char *path, con
>      for (prev = &watches, watch = *prev; watch; prev = &watch->next, watch = *prev)
>          if (!strcmp(watch->token, token)) {
>              free(watch->token);
> +            free(watch->path);
>              *prev = watch->next;
>              free(watch);
>              break;
> -- 
> 2.3.2 (Apple Git-55)
> 
> 
> _______________________________________________
> Minios-devel mailing list
> Minios-devel@lists.xenproject.org
> https://lists.xenproject.org/mailman/listinfo/minios-devel

-- 
Samuel
quit   When the quit statement is read, the  bc  processor
       is  terminated, regardless of where the quit state-
       ment is found.  For example, "if  (0  ==  1)  quit"
       will cause bc to terminate.
(Seen in the manpage for "bc". Note the "if" statement's logic)

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [Minios-devel] [PATCH RFC 00/16] Save/Restore Support for mini-OS PVH
  2017-12-19 23:41 [PATCH RFC 00/16] Save/Restore Support for mini-OS PVH Bruno Alvisio
                   ` (17 preceding siblings ...)
  2017-12-20  0:37 ` Samuel Thibault
@ 2017-12-20  0:57 ` Samuel Thibault
  2017-12-20  1:01 ` Samuel Thibault
  19 siblings, 0 replies; 34+ messages in thread
From: Samuel Thibault @ 2017-12-20  0:57 UTC (permalink / raw)
  To: Bruno Alvisio; +Cc: minios-devel, xen-devel, wei.liu2, jgross

About patch 15, it seems your terminal is set to see tabs as 4 spaces.
Where tabs are used, the mini-os source code assumes 8 spaces. Avoid
using tabs, just use spaces :)

And, avoid

for (list = dev_list; list->next != NULL; list = list->next);

better write

for (list = dev_list; list->next != NULL; list = list->next)
	;

to make it explicit that the loop is empty.

Also, 

     *ip = malloc(strlen(ldev->ip) + 1);
     strncpy(*ip, ldev->ip, strlen(ldev->ip) + 1);

can be a mere *ip = strdup(ldev->ip), can't it?

Apart from that,

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

Samuel

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [Minios-devel] [PATCH RFC 00/16] Save/Restore Support for mini-OS PVH
  2017-12-19 23:41 [PATCH RFC 00/16] Save/Restore Support for mini-OS PVH Bruno Alvisio
                   ` (18 preceding siblings ...)
  2017-12-20  0:57 ` Samuel Thibault
@ 2017-12-20  1:01 ` Samuel Thibault
  19 siblings, 0 replies; 34+ messages in thread
From: Samuel Thibault @ 2017-12-20  1:01 UTC (permalink / raw)
  To: Bruno Alvisio; +Cc: minios-devel, xen-devel, wei.liu2, jgross

About patch 16, 
"Replace xenstore and console pfns with the correspondent mfns"
seems exactly contrary to what the code does.
Apart from that,

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

Samuel

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH RFC 05/16] Save/Restore Support: Add kernel shutdown logic to shutdown.c
  2017-12-19 23:42 ` [PATCH RFC 05/16] Save/Restore Support: Add kernel shutdown logic to shutdown.c Bruno Alvisio
  2017-12-20  0:16   ` [Minios-devel] " Samuel Thibault
@ 2017-12-21 22:49   ` Konrad Rzeszutek Wilk
  1 sibling, 0 replies; 34+ messages in thread
From: Konrad Rzeszutek Wilk @ 2017-12-21 22:49 UTC (permalink / raw)
  To: Bruno Alvisio; +Cc: minios-devel, xen-devel, wei.liu2, jgross, samuel.thibault

.snip..
> diff --git a/shutdown.c b/shutdown.c
> new file mode 100644
> index 0000000..b3cea6d
> --- /dev/null
> +++ b/shutdown.c
> @@ -0,0 +1,188 @@
> +/*
> + *          MiniOS
> + *
> + *   file: fromdevice.cc
> + *
> + *          NEC Europe Ltd. PROPRIETARY INFORMATION
> + *
> + * This software is supplied under the terms of a license agreement
> + * or nondisclosure agreement with NEC Europe Ltd. and may not be
> + * copied or disclosed except in accordance with the terms of that
> + * agreement. The software and its source code contain valuable trade

Um?!?

> + * secrets and confidential information which have to be maintained in
> + * confidence.
> + * Any unauthorized publication, transfer to third parties or duplication
> + * of the object or source code - either totally or in part – is
> + * prohibited.

So ... this needs to be a different license I think.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 34+ messages in thread

end of thread, other threads:[~2017-12-21 22:50 UTC | newest]

Thread overview: 34+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-19 23:41 [PATCH RFC 00/16] Save/Restore Support for mini-OS PVH Bruno Alvisio
2017-12-19 23:41 ` [PATCH RFC 01/16] Save/Restore Support: Refactor HYPERVISOR_suspend hypercall Bruno Alvisio
2017-12-19 23:51   ` [Minios-devel] " Samuel Thibault
2017-12-19 23:41 ` [PATCH RFC 02/16] Save/Restore Support: Refactor trap_init() and setup vector callbacks Bruno Alvisio
2017-12-19 23:51   ` [Minios-devel] " Samuel Thibault
2017-12-19 23:41 ` [PATCH RFC 03/16] Save/Restore Support: Declare kernel and arch pre/post suspend functions Bruno Alvisio
2017-12-19 23:52   ` [Minios-devel] " Samuel Thibault
2017-12-19 23:41 ` [PATCH RFC 04/16] Save/Restore Support: Add xenbus_release_wait_for_watch Bruno Alvisio
2017-12-20  0:14   ` [Minios-devel] " Samuel Thibault
2017-12-19 23:42 ` [PATCH RFC 05/16] Save/Restore Support: Add kernel shutdown logic to shutdown.c Bruno Alvisio
2017-12-20  0:16   ` [Minios-devel] " Samuel Thibault
2017-12-21 22:49   ` Konrad Rzeszutek Wilk
2017-12-19 23:42 ` [PATCH RFC 06/16] Save/Restore Support: Moved shutdown thread " Bruno Alvisio
2017-12-19 23:42 ` [PATCH RFC 07/16] Save/Restore Support: Add unmap_shared_info Bruno Alvisio
2017-12-20  0:23   ` [Minios-devel] " Samuel Thibault
2017-12-19 23:42 ` [PATCH RFC 08/16] Save/Restore Support: Add arch_mm_pre|post_suspend Bruno Alvisio
2017-12-20  0:24   ` [Minios-devel] " Samuel Thibault
2017-12-19 23:42 ` [PATCH RFC 09/16] Save/Restore Support: Disable/enable IRQs during suspend/restore Bruno Alvisio
2017-12-20  0:25   ` [Minios-devel] " Samuel Thibault
2017-12-19 23:42 ` [PATCH RFC 10/16] Save/Restore Support: Add suspend/resume support for timers Bruno Alvisio
2017-12-20  0:26   ` [Minios-devel] " Samuel Thibault
2017-12-19 23:42 ` [PATCH RFC 11/16] Save/Restore Support: Add suspend/restore support for console Bruno Alvisio
2017-12-19 23:42 ` [PATCH RFC 12/16] Save/Restore Support: Add support for suspend/restore events Bruno Alvisio
2017-12-20  0:37   ` [Minios-devel] " Samuel Thibault
2017-12-19 23:42 ` [PATCH RFC 13/16] Save/Restore Support: Add suspend/restore support for Grant Tables Bruno Alvisio
2017-12-20  0:40   ` [Minios-devel] " Samuel Thibault
2017-12-19 23:42 ` [PATCH RFC 14/16] Save/Restore Support: Add suspend/restore support for xenbus Bruno Alvisio
2017-12-20  0:43   ` [Minios-devel] " Samuel Thibault
2017-12-19 23:42 ` [PATCH RFC 15/16] Save/Restore Support: Add suspend/restore support for netfront Bruno Alvisio
2017-12-19 23:42 ` [PATCH RFC 16/16] Save/Restore Support: Implement code for arch suspend/resume Bruno Alvisio
2017-12-20  0:19 ` [Minios-devel] [PATCH RFC 00/16] Save/Restore Support for mini-OS PVH Samuel Thibault
2017-12-20  0:37 ` Samuel Thibault
2017-12-20  0:57 ` Samuel Thibault
2017-12-20  1:01 ` Samuel Thibault

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).