Skip to contentSkip to conversation

Make Xenstore-stubdom live update possible

PATCH Superseded Juergen Gross 3 participants 47 messages Jul 2, 2025 – Jul 15, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Make Xenstore-stubdom live update possible

With this series applied I was able to perform Live Update of Xenstore running in a PVH stubdom.

The main problem to solve was to keep the 9pfs device used to store and later retrieve the Xenstore state usable across kexec(). This has been achieved by using a module containing the shared pages of the device and the related config data. This module is then passed to the new kernel via linking it to the struct hvm_start_info.

The rest of the series are some missing bits and pieces to have a sane state when activating the new kernel, and some minor fixes and cleanups.

In order to be able to perform a Xenstore live update an associated patch series for Xen is needed. The Xen series is depending on this Mini-OS patch series.

Juergen Gross (19):
setup: add global pointer for struct hvm_start_info
mini-os: kexec: add O_CLOEXEC support
mini-os: grants: support populated grant table at boot
time: unbind VIRQ_TIMER across kexec
mm: refactor init_page_allocator()
mm: don't add module pages to free memory
kexec: fix physical addresses in start info data
e820: don't count lapic page as initially reserved
kexec: restructure building the start info data
e820: use special type for software reserved memory
mini-os: config: add support for config items with numerical values
mini-os: kexec: add support for handing over some memory across kexec
kexec: add support for allocating pages from kexec module memory 9pfs: store bepath in struct struct dev_9pfs
9pfs: refactor init_9pfront()
gnttab: remove gnttab_alloc_and_grant() function
gnttab: add function to obtain memory address from grantref 9pfs: add support to keep device opened across kexec
events: export bind_evtchn()

 9pfront.c             | 267 +++++++++++++++++++++++++++++++-----------
 Config.mk             |   6 +
 arch/x86/kexec.c      | 113 ++++++++++++++++--
 arch/x86/mm.c         |  98 ++++++++++++++++
 arch/x86/setup.c      |  48 +++++++-
 arch/x86/time.c       |  14 +++
 e820.c                |  11 +-
 events.c              |   1 +
 gnttab.c              |  21 ++--
 include/9pfront.h     |   9 ++
 include/e820.h        |   2 +
 include/fcntl.h       |   6 +
 include/gnttab.h      |   2 +-
 include/hypervisor.h  |   3 +
 include/kernel.h      |   1 +
 include/kexec.h       |  98 ++++++++++++++++
 include/lib.h         |   1 +
 include/mm.h          |   4 +
 include/x86/arch_mm.h |   1 +
 kexec.c               | 118 +++++++++++++++++++
 lib/sys.c             |  44 ++++++-
 mm.c                  | 134 +++++++++++++--------
 22 files changed, 858 insertions(+), 144 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/19 setup: add global pointer for struct hvm_start_info

Similar to start_info_ptr for PV provide hvm_start_info_ptr for PVH.

Add a generic function to set the pointer.

---
 arch/x86/setup.c     | 20 +++++++++++++++++---
 include/hypervisor.h |  3 +++
 2 files changed, 20 insertions(+), 3 deletions(-)
arch/x86/setup.c +17 -3
index ed28d940..2085ee5c 100644
@@ -69,6 +69,11 @@ static inline void sse_init(void) {
 start_info_t *start_info_ptr;
 EXPORT_SYMBOL(start_info_ptr);
 
+static void set_info_ptr(start_info_t *ptr)
+{
+    start_info_ptr = ptr;
+}
+
 #define hpc_init()
 
 shared_info_t *map_shared_info(void)
@@ -123,6 +128,17 @@ static void print_start_of_day(void *p)
     printk("       stack: %p-%p\n", stack, stack + sizeof(stack));
 }
 #else
+
+/*
+ * This pointer holds a reference to the hvm_start_info struct.
+ */
+struct hvm_start_info *hvm_start_info_ptr;
+
+static void set_info_ptr(struct hvm_start_info *ptr)
+{
+    hvm_start_info_ptr = ptr;
+}
+
 static void hpc_init(void)
 {
     uint32_t eax, ebx, ecx, edx, base;
@@ -176,9 +192,7 @@ arch_init(void *par)
 {
 	static char hello[] = "Bootstrapping...\n";
 
-#ifdef CONFIG_PARAVIRT
-	start_info_ptr = par;
-#endif
+	set_info_ptr(par);
 
 	hpc_init();
 	(void)HYPERVISOR_console_io(CONSOLEIO_write, strlen(hello), hello);
include/hypervisor.h +3 -0
index d199f039..93f1247f 100644
@@ -33,6 +33,9 @@ extern start_info_t *start_info_ptr;
 
 #define start_info (*start_info_ptr)
 #else
+#include <xen/arch-x86/hvm/start_info.h>
+
+extern struct hvm_start_info *hvm_start_info_ptr;
 int hvm_get_parameter(int idx, uint64_t *value);
 int hvm_set_parameter(int idx, uint64_t value);
 #endif
Signature · 1 line
2.43.0
#3 lore raw

PATCH 2/19 mini-os: kexec: add O_CLOEXEC support

In reply to Juergen Gross

Define O_CLOEXEC as a non-zero value and add a kexec callback to cycle over all open files to close them in case O_CLOEXEC was specified when opening the file.

This requires the addition of a cloexec boolean in struct file.

---
 include/fcntl.h |  6 ++++++
 include/lib.h   |  1 +
 lib/sys.c       | 44 +++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 50 insertions(+), 1 deletion(-)
include/fcntl.h +6 -0
index cc59b3ca..3205daed 100644
@@ -3,6 +3,9 @@
 
 #ifdef HAVE_LIBC
 #include_next <fcntl.h>
+#ifndef O_CLOEXEC
+#define O_CLOEXEC	0x40000	/* Use newlib's value for WIN32 and CYGWIN. */
+#endif
 #else
 
 /* open/fcntl - O_SYNC is only implemented on blocks devices and on files
@@ -25,6 +28,9 @@
 #define O_DIRECTORY	0200000	/* must be a directory */
 #define O_NOFOLLOW	0400000 /* don't follow links */
 #define O_NOATIME	01000000
+#ifndef O_CLOEXEC
+#define O_CLOEXEC	02000000
+#endif
 
 #define F_DUPFD		0	/* dup */
 #define F_GETFD		1	/* get close_on_exec */
include/lib.h +1 -0
index de67bab0..ea146496 100644
@@ -174,6 +174,7 @@ extern struct wait_queue_head event_queue;
 struct file {
     unsigned int type;
     bool read;	/* maybe available for read */
+    bool cloexec;
     off_t offset;
     union {
         int fd; /* Any fd from an upper layer. */
lib/sys.c +43 -1

74 lines not on this page · raw message

Signature · 1 line
2.43.0
Reviewed-by on v1 2/19
#4 lore raw

Re: [MINI-OS PATCH 02/19] mini-os: kexec: add O_CLOEXEC support

Quoted 7 lines · Juergen Gross

Define O_CLOEXEC as a non-zero value and add a kexec callback to cycle over all open files to close them in case O_CLOEXEC was specified when opening the file.

This requires the addition of a cloexec boolean in struct file.

#5 lore raw

PATCH 3/19 mini-os: grants: support populated grant table at boot

In reply to Juergen Gross

When kexec-ing into a new kernel, the grant table might still have active grants. Support that by not adding populated grant entries to the list of free grant entries.

---
 gnttab.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
gnttab.c +4 -2
index 8168ed5d..5b04ab01 100644
@@ -183,11 +183,13 @@ init_gnttab(void)
 #ifdef GNT_DEBUG
     memset(inuse, 1, sizeof(inuse));
 #endif
-    for (i = NR_RESERVED_ENTRIES; i < NR_GRANT_ENTRIES; i++)
-        put_free_entry(i);
 
     gnttab_table = arch_init_gnttab(NR_GRANT_FRAMES);
     printk("gnttab_table mapped at %p.\n", gnttab_table);
+
+    for (i = NR_RESERVED_ENTRIES; i < NR_GRANT_ENTRIES; i++)
+        if (gnttab_table[i].flags == 0)
+            put_free_entry(i);
 }
 
 void
Signature · 1 line
2.43.0
#7 lore raw

PATCH 4/19 time: unbind VIRQ_TIMER across kexec

In reply to Juergen Gross

Deactivate the VIRQ_TIMER event when doing kexec() in order to be able to set it up again in the new kernel.

---
 arch/x86/time.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
arch/x86/time.c +14 -0
index 52916e15..3a2a1d29 100644
@@ -36,6 +36,7 @@
 #include <mini-os/types.h>
 #include <mini-os/hypervisor.h>
 #include <mini-os/events.h>
+#include <mini-os/kexec.h>
 #include <mini-os/time.h>
 #include <mini-os/lib.h>
 
@@ -193,3 +194,16 @@ void fini_time(void)
     HYPERVISOR_set_timer_op(0);
     unbind_evtchn(port);
 }
+
+#ifdef CONFIG_KEXEC
+static int unbind_virq_timer(bool undo)
+{
+    if ( undo )
+        init_time();
+    else
+        fini_time();
+
+    return 0;
+}
+kexec_call(unbind_virq_timer);
+#endif
Signature · 1 line
2.43.0
#9 lore raw

PATCH 5/19 mm: refactor init_page_allocator()

In reply to Juergen Gross

Split init_page_allocator() into three functions in order to prepare for sparing some memory from being added to the buddy allocator.

Use a function pointer for selecting the function used for handling a memory range, as this will be needed by a future patch. For the same reason make iterate_memory_range() globally visible.

---
 include/mm.h |   3 ++
 mm.c         | 111 +++++++++++++++++++++++++++++----------------------
 2 files changed, 66 insertions(+), 48 deletions(-)
include/mm.h +3 -0
index 0a16d56c..1dc89ddb 100644
@@ -95,4 +95,7 @@ void fini_mm(void);
 
 void change_readonly(bool readonly);
 
+void iterate_memory_range(unsigned long min, unsigned long max,
+                          void (*func)(unsigned long, unsigned long));
+
 #endif /* _MM_H_ */
mm.c +63 -48

129 lines not on this page · raw message

Signature · 1 line
2.43.0
Reviewed-by on v1 5/19
#10 lore raw

Re: [MINI-OS PATCH 05/19] mm: refactor init_page_allocator()

Quoted 8 lines · Juergen Gross

Split init_page_allocator() into three functions in order to prepare for sparing some memory from being added to the buddy allocator.

Use a function pointer for selecting the function used for handling a memory range, as this will be needed by a future patch. For the same reason make iterate_memory_range() globally visible.

#11 lore raw

PATCH 6/19 mm: don't add module pages to free memory

In reply to Juergen Gross

When initializing the memory allocator, don't add memory pages of modules and the initial boot info structure to the free memory.

This is relevant only when running in PVH mode, as in PV mode only memory above the initial page tables is added to free memory, and the module and start_info pages are below the page tables.

---
 arch/x86/mm.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++
 include/mm.h  |  1 +
 mm.c          | 21 +++++++++++++-
 3 files changed, 101 insertions(+), 1 deletion(-)
arch/x86/mm.c +80 -0
index 26ede6f4..7c3c83be 100644
@@ -78,6 +78,10 @@ void arch_mm_preinit(void *p)
     last_free_pfn = si->nr_pages;
     balloon_set_nr_pages(last_free_pfn, last_free_pfn);
 }
+
+void check_memory_range(unsigned long *from, unsigned long *to)
+{
+}
 #else
 #include <mini-os/desc.h>
 user_desc gdt[NR_GDT_ENTRIES] =
@@ -125,6 +129,78 @@ void arch_mm_preinit(void *p)
     last_free_pfn = e820_get_maxpfn(pages);
     balloon_set_nr_pages(pages, last_free_pfn);
 }
+
+static void check_memory_range_conflict(unsigned long *from, unsigned long *to,
+                                        unsigned long chk, unsigned long sz)
+{
+    unsigned long chk_end = chk + sz;
+
+    if ( *to <= chk || *from >= chk_end )
+        return;
+
+    if ( chk <= *from )
+        *from = (chk_end >= *to) ? *to : chk_end;
+    else
+        *to = chk;
+}
+
+/* Reserved memory ranges not added to free memory. */
+#define MAX_RSV_RANGES  1
+static struct {
+    unsigned long start;
+    unsigned long size;
+} reserved_range[MAX_RSV_RANGES];
+
+void check_memory_range(unsigned long *from, unsigned long *to)
+{
+    unsigned int m;
+    struct hvm_modlist_entry *mod;
+
+    for ( m = 0; m < MAX_RSV_RANGES && reserved_range[m].size; m++ )
+        check_memory_range_conflict(from, to, reserved_range[m].start,
+                                    reserved_range[m].size);
+
+    mod = (struct hvm_modlist_entry *)(unsigned long)
+          hvm_start_info_ptr->modlist_paddr;
+    for ( m = 0; m < hvm_start_info_ptr->nr_modules; m++ )
+        check_memory_range_conflict(from, to, mod[m].paddr, mod[m].size);
+}
+
+#define max(a, b) ((a) < (b) ? (b) : (a))
+
+static void pvh_reserve_start_info(unsigned long *start_pfn)
+{
+    unsigned long end = 0;
+    unsigned long start = (unsigned long)hvm_start_info_ptr;
+    unsigned long end_pfn;
+    unsigned int m;
+    struct hvm_modlist_entry *mod;
+    char *cmdline;
+
+    mod = (void *)(unsigned long)hvm_start_info_ptr->modlist_paddr;
+
+    end = max(end, start + sizeof(struct hvm_start_info));
+    end = max(end, hvm_start_info_ptr->modlist_paddr +
+              hvm_start_info_ptr->nr_modules *
+              sizeof(struct hvm_modlist_entry));
+    for ( m = 0; m < hvm_start_info_ptr->nr_modules; m++ )
+    {
+        cmdline = (char *)(unsigned long)mod[m].cmdline_paddr;
+        if ( cmdline )
+            end = max(end, (unsigned long)cmdline + strlen(cmdline) + 1);
+    }
+    cmdline = (char *)(unsigned long)hvm_start_info_ptr->cmdline_paddr;
+    if ( cmdline )
+        end = max(end, (unsigned long)cmdline + strlen(cmdline) + 1);
+    if ( hvm_start_info_ptr->version >= 1 )
+        end = max(end, hvm_start_info_ptr->memmap_paddr +
+                  hvm_start_info_ptr->memmap_entries *
+                  sizeof(struct hvm_memmap_table_entry));
+
+    end_pfn = PFN_UP(end);
+    if ( end_pfn > *start_pfn )
+        *start_pfn = end_pfn;
+}
 #endif
 
 static const struct {
@@ -888,6 +964,10 @@ void arch_init_mm(unsigned long* start_pfn_p, unsigned long* max_pfn_p)
     if ( max_pfn >= MAX_MEM_SIZE / PAGE_SIZE )
         max_pfn = MAX_MEM_SIZE / PAGE_SIZE - 1;
 
+#ifndef CONFIG_PARAVIRT
+    pvh_reserve_start_info(&start_pfn);
+#endif
+
     printk("  start_pfn: %lx\n", start_pfn);
     printk("    max_pfn: %lx\n", max_pfn);
 
include/mm.h +1 -0
index 1dc89ddb..995e9862 100644
@@ -74,6 +74,7 @@ static __inline__ int get_order(unsigned long size)
 
 void arch_init_demand_mapping_area(void);
 void arch_init_mm(unsigned long* start_pfn_p, unsigned long* max_pfn_p);
+void check_memory_range(unsigned long *from, unsigned long *to);
 
 unsigned long allocate_ondemand(unsigned long n, unsigned long alignment);
 /* map f[i*stride]+i*increment for i in 0..n-1, aligned on alignment pages */
mm.c +20 -1
index 858dc108..8c41d2f2 100644
@@ -185,6 +185,25 @@ static void add_memory_range(unsigned long r_min, unsigned long r_max)
     }
 }
 
+static void consider_memory_range(unsigned long r_min, unsigned long r_max,
+                                  void (*func)(unsigned long, unsigned long))
+{
+    unsigned long from = r_min;
+    unsigned long to = r_max;
+
+    while ( true )
+    {
+        check_memory_range(&from, &to);
+        if ( from == to )
+            return;
+
+        func(from, to);
+
+        from = to;
+        to = r_max;
+    }
+}
+
 void iterate_memory_range(unsigned long min, unsigned long max,
                           void (*func)(unsigned long, unsigned long))
 {
@@ -207,7 +226,7 @@ void iterate_memory_range(unsigned long min, unsigned long max,
         if ( r_max > max )
             r_max = max;
 
-        func(r_min, r_max);
+        consider_memory_range(r_min, r_max, func);
     }
 }
 
Signature · 1 line
2.43.0
#12 lore raw

Re: [MINI-OS PATCH 06/19] mm: don't add module pages to free memory

Quoted 170 lines · Juergen Gross

When initializing the memory allocator, don't add memory pages of modules and the initial boot info structure to the free memory.

This is relevant only when running in PVH mode, as in PV mode only memory above the initial page tables is added to free memory, and the module and start_info pages are below the page tables.

---
  arch/x86/mm.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++
  include/mm.h  |  1 +
  mm.c          | 21 +++++++++++++-
  3 files changed, 101 insertions(+), 1 deletion(-)
arch/x86/mm.c +80 -0
index 26ede6f4..7c3c83be 100644
@@ -78,6 +78,10 @@ void arch_mm_preinit(void *p)
      last_free_pfn = si->nr_pages;
      balloon_set_nr_pages(last_free_pfn, last_free_pfn);
  }
+
+void check_memory_range(unsigned long *from, unsigned long *to)
+{
+}
  #else
  #include <mini-os/desc.h>
  user_desc gdt[NR_GDT_ENTRIES] =
@@ -125,6 +129,78 @@ void arch_mm_preinit(void *p)
      last_free_pfn = e820_get_maxpfn(pages);
      balloon_set_nr_pages(pages, last_free_pfn);
  }
+
+static void check_memory_range_conflict(unsigned long *from, unsigned long *to,
+                                        unsigned long chk, unsigned long sz)
+{
+    unsigned long chk_end = chk + sz;
+
+    if ( *to <= chk || *from >= chk_end )
+        return;
+
+    if ( chk <= *from )
+        *from = (chk_end >= *to) ? *to : chk_end;
+    else
+        *to = chk;
+}
+
+/* Reserved memory ranges not added to free memory. */
+#define MAX_RSV_RANGES  1
+static struct {
+    unsigned long start;
+    unsigned long size;
+} reserved_range[MAX_RSV_RANGES];
+
+void check_memory_range(unsigned long *from, unsigned long *to)
+{
+    unsigned int m;
+    struct hvm_modlist_entry *mod;
+
+    for ( m = 0; m < MAX_RSV_RANGES && reserved_range[m].size; m++ )
+        check_memory_range_conflict(from, to, reserved_range[m].start,
+                                    reserved_range[m].size);
+
+    mod = (struct hvm_modlist_entry *)(unsigned long)
+          hvm_start_info_ptr->modlist_paddr;
+    for ( m = 0; m < hvm_start_info_ptr->nr_modules; m++ )
+        check_memory_range_conflict(from, to, mod[m].paddr, mod[m].size);
+}
+
+#define max(a, b) ((a) < (b) ? (b) : (a))
+
+static void pvh_reserve_start_info(unsigned long *start_pfn)
+{
+    unsigned long end = 0;
+    unsigned long start = (unsigned long)hvm_start_info_ptr;
+    unsigned long end_pfn;
+    unsigned int m;
+    struct hvm_modlist_entry *mod;
+    char *cmdline;
+
+    mod = (void *)(unsigned long)hvm_start_info_ptr->modlist_paddr;
+
+    end = max(end, start + sizeof(struct hvm_start_info));
+    end = max(end, hvm_start_info_ptr->modlist_paddr +
+              hvm_start_info_ptr->nr_modules *
+              sizeof(struct hvm_modlist_entry));
+    for ( m = 0; m < hvm_start_info_ptr->nr_modules; m++ )
+    {
+        cmdline = (char *)(unsigned long)mod[m].cmdline_paddr;
+        if ( cmdline )
+            end = max(end, (unsigned long)cmdline + strlen(cmdline) + 1);
+    }
+    cmdline = (char *)(unsigned long)hvm_start_info_ptr->cmdline_paddr;
+    if ( cmdline )
+        end = max(end, (unsigned long)cmdline + strlen(cmdline) + 1);
+    if ( hvm_start_info_ptr->version >= 1 )
+        end = max(end, hvm_start_info_ptr->memmap_paddr +
+                  hvm_start_info_ptr->memmap_entries *
+                  sizeof(struct hvm_memmap_table_entry));
+
+    end_pfn = PFN_UP(end);
+    if ( end_pfn > *start_pfn )
+        *start_pfn = end_pfn;
+}
  #endif
 
  static const struct {
@@ -888,6 +964,10 @@ void arch_init_mm(unsigned long* start_pfn_p, unsigned long* max_pfn_p)
      if ( max_pfn >= MAX_MEM_SIZE / PAGE_SIZE )
          max_pfn = MAX_MEM_SIZE / PAGE_SIZE - 1;
 
+#ifndef CONFIG_PARAVIRT
+    pvh_reserve_start_info(&start_pfn);
+#endif
+
      printk("  start_pfn: %lx\n", start_pfn);
      printk("    max_pfn: %lx\n", max_pfn);
 
include/mm.h +1 -0
index 1dc89ddb..995e9862 100644
@@ -74,6 +74,7 @@ static __inline__ int get_order(unsigned long size)
 
  void arch_init_demand_mapping_area(void);
  void arch_init_mm(unsigned long* start_pfn_p, unsigned long* max_pfn_p);
+void check_memory_range(unsigned long *from, unsigned long *to);
 
  unsigned long allocate_ondemand(unsigned long n, unsigned long alignment);
  /* map f[i*stride]+i*increment for i in 0..n-1, aligned on alignment pages */
mm.c +20 -1
index 858dc108..8c41d2f2 100644
@@ -185,6 +185,25 @@ static void add_memory_range(unsigned long r_min, unsigned long r_max)
      }
  }
 
+static void consider_memory_range(unsigned long r_min, unsigned long r_max,
+                                  void (*func)(unsigned long, unsigned long))
+{
+    unsigned long from = r_min;
+    unsigned long to = r_max;
+
+    while ( true )
+    {
+        check_memory_range(&from, &to);
+        if ( from == to )
+            return;
+
+        func(from, to);
+
+        from = to;
+        to = r_max;
+    }
+}
+
  void iterate_memory_range(unsigned long min, unsigned long max,
                            void (*func)(unsigned long, unsigned long))
  {
@@ -207,7 +226,7 @@ void iterate_memory_range(unsigned long min, unsigned long max,
          if ( r_max > max )
              r_max = max;
 
-        func(r_min, r_max);
+        consider_memory_range(r_min, r_max, func);
      }
  }
 
#13 lore raw

Re: [MINI-OS PATCH 06/19] mm: don't add module pages to free memory

In reply to Juergen Gross
Quoted 14 lines · Juergen Gross

When initializing the memory allocator, don't add memory pages of modules and the initial boot info structure to the free memory.

This is relevant only when running in PVH mode, as in PV mode only memory above the initial page tables is added to free memory, and the module and start_info pages are below the page tables.

arch/x86/mm.c +5 -0
+/* Reserved memory ranges not added to free memory. */
+#define MAX_RSV_RANGES  1
+static struct {
+    unsigned long start;
+    unsigned long size;

arch/x86/mm.c void arch_mm_preinit(void *p) · line 161

Quoted 10 lines
arch/x86/mm.c +10 -0
+} reserved_range[MAX_RSV_RANGES];
+
+void check_memory_range(unsigned long *from, unsigned long *to)
+{
+    unsigned int m;
+    struct hvm_modlist_entry *mod;
+
+    for ( m = 0; m < MAX_RSV_RANGES && reserved_range[m].size; m++ )
+        check_memory_range_conflict(from, to, reserved_range[m].start,
+                                    reserved_range[m].size);

reserved_range[] isn't updated, so this is dead code. I guess that is fine for now.

Quoted 11 lines
arch/x86/mm.c +7 -0
+
+    mod = (struct hvm_modlist_entry *)(unsigned long)
+          hvm_start_info_ptr->modlist_paddr;
+    for ( m = 0; m < hvm_start_info_ptr->nr_modules; m++ )
+        check_memory_range_conflict(from, to, mod[m].paddr, mod[m].size);
+}
+
 
 
  static const struct {

arch/x86/mm.c void arch_init_mm(unsigned long* start_pfn_p, unsigned long* max_pfn_p) · line 969

Quoted 6 lines
arch/x86/mm.c +3 -0
@@ -888,6 +964,10 @@ void arch_init_mm(unsigned long* start_pfn_p, unsigned long* max_pfn_p)
      if ( max_pfn >= MAX_MEM_SIZE / PAGE_SIZE )
          max_pfn = MAX_MEM_SIZE / PAGE_SIZE - 1;
 
+#ifndef CONFIG_PARAVIRT
+    pvh_reserve_start_info(&start_pfn);
+#endif

Maybe this ifdef can be removed and arch_mm_preinit() can call pvh_reserve_start_info() and update first_free_pfn (which is assigned to start_pfn)?

Regards,
Jason

#14 lore raw

Re: [MINI-OS PATCH 06/19] mm: don't add module pages to free memory

Quoted 19 lines · Jason Andryuk
Quoted 18 lines · Juergen Gross

When initializing the memory allocator, don't add memory pages of modules and the initial boot info structure to the free memory.

This is relevant only when running in PVH mode, as in PV mode only memory above the initial page tables is added to free memory, and the module and start_info pages are below the page tables.

arch/x86/mm.c +9 -0
+/* Reserved memory ranges not added to free memory. */
+#define MAX_RSV_RANGES  1
+static struct {
+    unsigned long start;
+    unsigned long size;
+} reserved_range[MAX_RSV_RANGES];
+
+void check_memory_range(unsigned long *from, unsigned long *to)
+{
Quoted 8 lines
Quoted 6 lines

+    unsigned int m;
+    struct hvm_modlist_entry *mod;
+
+    for ( m = 0; m < MAX_RSV_RANGES && reserved_range[m].size; m++ ) +        check_memory_range_conflict(from, to, reserved_range[m].start, +                                    reserved_range[m].size);

reserved_range[] isn't updated, so this is dead code.  I guess that is fine for now.

I thought so, yes. It felt more natural to add it in this patch.

Quoted 8 lines
Quoted 7 lines
arch/x86/mm.c +7 -0
+
+    mod = (struct hvm_modlist_entry *)(unsigned long)
+          hvm_start_info_ptr->modlist_paddr;
+    for ( m = 0; m < hvm_start_info_ptr->nr_modules; m++ )
+        check_memory_range_conflict(from, to, mod[m].paddr, mod[m].size);
+}
+
Quoted 10 lines

arch/x86/mm.c void arch_init_mm(unsigned long* start_pfn_p, unsigned · line 969

Quoted 8 lines

  static const struct {

arch/x86/mm.c +3 -0
@@ -888,6 +964,10 @@ void arch_init_mm(unsigned long* start_pfn_p, unsigned 
 long* max_pfn_p)
       if ( max_pfn >= MAX_MEM_SIZE / PAGE_SIZE )
           max_pfn = MAX_MEM_SIZE / PAGE_SIZE - 1;
+#ifndef CONFIG_PARAVIRT
+    pvh_reserve_start_info(&start_pfn);
+#endif

Maybe this ifdef can be removed and arch_mm_preinit() can call pvh_reserve_start_info() and update first_free_pfn (which is assigned to start_pfn)?

Yes, that should be possible.

Thanks for the idea, I'll modify the patch.

Juergen

#15 lore raw

PATCH 7/19 kexec: fix physical addresses in start info data

In reply to Juergen Gross

The physical addresses in struct hvm_start_info are pointing to the memory where the data is being built instead of the location where it will finally be moved to.

Fix that.

Fixes b7994b6409a4 ("mini-os: kexec: build parameters for new kernel")
---
 arch/x86/kexec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kexec.c +2 -2
index fc58473e..d84df42c 100644
@@ -233,9 +233,9 @@ int kexec_get_entry(const char *cmdline)
     memset(info, 0, sizeof(*info));
     info->magic = XEN_HVM_START_MAGIC_VALUE;
     info->version = 1;
-    info->cmdline_paddr = kexec_param_mem + sizeof(*info) +
+    info->cmdline_paddr = kexec_param_loc + sizeof(*info) +
                           e820_entries * sizeof(struct hvm_memmap_table_entry);
-    info->memmap_paddr = kexec_param_mem + sizeof(*info);
+    info->memmap_paddr = kexec_param_loc + sizeof(*info);
     info->memmap_entries = e820_entries;
 
     mmap = (struct hvm_memmap_table_entry *)(info + 1);
Signature · 1 line
2.43.0
Reviewed-by on v1 7/19
#16 lore raw

Re: [MINI-OS PATCH 07/19] kexec: fix physical addresses in start info data

Quoted 8 lines · Juergen Gross

The physical addresses in struct hvm_start_info are pointing to the memory where the data is being built instead of the location where it will finally be moved to.

Fix that.

Fixes b7994b6409a4 ("mini-os: kexec: build parameters for new kernel")
#17 lore raw

PATCH 8/19 e820: don't count lapic page as initially reserved

In reply to Juergen Gross

The number of pages marked initially as reserved in the memory map are counted to be allocated, as they are normally populated by Xen tools for e.g. xenbus and console ring pages.

This is wrong in case the lapic page is marked as reserved in the memory map, as there is never memory allocated for a lapic.

So when finding the lapic page to be marked as reserved, don't add it to the number of reserved pages.

Fixes 9b87429d2864 ("mini-os: fix number of pages for PVH")
---
 e820.c | 3 +++
 1 file changed, 3 insertions(+)
e820.c +3 -0
index 49b16878..876d55b1 100644
@@ -275,7 +275,10 @@ static void e820_sanitize(void)
             e820_initial_reserved_pfns += e820_map[i].size / PAGE_SIZE;
             if ( e820_map[i].addr <= LAPIC_ADDRESS &&
                  e820_map[i].addr + e820_map[i].size > LAPIC_ADDRESS )
+            {
                 found_lapic = true;
+                e820_initial_reserved_pfns--;
+            }
         }
     }
 
Signature · 1 line
2.43.0
Reviewed-by on v1 8/19
#18 lore raw

Re: [MINI-OS PATCH 08/19] e820: don't count lapic page as initially reserved

Quoted 4 lines · Juergen Gross

The number of pages marked initially as reserved in the memory map are counted to be allocated, as they are normally populated by Xen tools for e.g. xenbus and console ring pages.

Quoted 8 lines

This is wrong in case the lapic page is marked as reserved in the memory map, as there is never memory allocated for a lapic.

So when finding the lapic page to be marked as reserved, don't add it to the number of reserved pages.

Fixes 9b87429d2864 ("mini-os: fix number of pages for PVH")
#19 lore raw

PATCH 9/19 kexec: restructure building the start info data

In reply to Juergen Gross

Instead of setting most of the struct hvm_start_info fields first and then building the leaf data, restructure kexec_get_entry() by using an opaque "next" pointer where the next leaf data will be stored and handle that leaf data together with the associated hvm_start_info fields.

This will make it easier to add new data items without having to rewrite large portions of the function.

---
 arch/x86/kexec.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
arch/x86/kexec.c +11 -7
index d84df42c..3e3b64e2 100644
@@ -215,6 +215,7 @@ void kexec_set_param_loc(const char *cmdline)
 
 int kexec_get_entry(const char *cmdline)
 {
+    void *next;
     struct hvm_start_info *info;
     struct hvm_memmap_table_entry *mmap;
     unsigned int order;
@@ -229,16 +230,17 @@ int kexec_get_entry(const char *cmdline)
     if ( !kexec_param_mem )
         return ENOMEM;
 
-    info = (struct hvm_start_info *)kexec_param_mem;
+    next = (void *)kexec_param_mem;
+
+    info = next;
     memset(info, 0, sizeof(*info));
     info->magic = XEN_HVM_START_MAGIC_VALUE;
     info->version = 1;
-    info->cmdline_paddr = kexec_param_loc + sizeof(*info) +
-                          e820_entries * sizeof(struct hvm_memmap_table_entry);
-    info->memmap_paddr = kexec_param_loc + sizeof(*info);
-    info->memmap_entries = e820_entries;
+    next = info + 1;
 
-    mmap = (struct hvm_memmap_table_entry *)(info + 1);
+    mmap = next;
+    info->memmap_paddr = kexec_param_loc + (unsigned long)next - kexec_param_mem;
+    info->memmap_entries = e820_entries;
     for ( i = 0; i < e820_entries; i++ )
     {
         mmap->addr = e820_map[i].addr;
@@ -246,8 +248,10 @@ int kexec_get_entry(const char *cmdline)
         mmap->type = e820_map[i].type;
         mmap++;
     }
+    next = mmap;
 
-    strcpy((char *)mmap, cmdline);
+    info->cmdline_paddr = kexec_param_loc + (unsigned long)next - kexec_param_mem;
+    strcpy(next, cmdline);
 
     if ( kexec_add_action(KEXEC_COPY, to_virt(kexec_param_loc), info,
                           kexec_param_size) )
Signature · 1 line
2.43.0
Reviewed-by on v1 9/19
#20 lore raw

Re: [MINI-OS PATCH 09/19] kexec: restructure building the start info data

Quoted 10 lines · Juergen Gross

Instead of setting most of the struct hvm_start_info fields first and then building the leaf data, restructure kexec_get_entry() by using an opaque "next" pointer where the next leaf data will be stored and handle that leaf data together with the associated hvm_start_info fields.

This will make it easier to add new data items without having to rewrite large portions of the function.

#21 lore raw

PATCH 10/19 e820: use special type for software reserved memory

In reply to Juergen Gross

For memory areas used to map foreign domain memory Mini-OS is using the type E820_RESERVED in the memory map today. This is causing problems with kexec, as the new kernel should not see those areas in the memory map. Unfortunately the sequence of actions for calculating the size of the memory map and the removal of those reserved areas can't easily be adjusted to do the removal first, so another way must be used to avoid passing those reserved areas to the new kernel.

Instead of using the type E820_RESERVED, which might be used for other pages as well, just use a new type. Areas with that new type can easily be filtered out when building the memory map for the new kernel.

Introduce the type E820_TYPE_SOFT_RESERVED with the same value as the Linux kernel is using for the same purpose.

---
 arch/x86/kexec.c | 4 +++-
 e820.c           | 8 ++++----
 include/e820.h   | 2 ++
 3 files changed, 9 insertions(+), 5 deletions(-)
arch/x86/kexec.c +3 -1
index 3e3b64e2..804e7b6d 100644
@@ -240,14 +240,16 @@ int kexec_get_entry(const char *cmdline)
 
     mmap = next;
     info->memmap_paddr = kexec_param_loc + (unsigned long)next - kexec_param_mem;
-    info->memmap_entries = e820_entries;
     for ( i = 0; i < e820_entries; i++ )
     {
+        if ( e820_map[i].type == E820_TYPE_SOFT_RESERVED )
+            continue;
         mmap->addr = e820_map[i].addr;
         mmap->size = e820_map[i].size;
         mmap->type = e820_map[i].type;
         mmap++;
     }
+    info->memmap_entries = mmap - (struct hvm_memmap_table_entry *)next;
     next = mmap;
 
     info->cmdline_paddr = kexec_param_loc + (unsigned long)next - kexec_param_mem;
e820.c +4 -4
index 876d55b1..d8cfb1f4 100644
@@ -367,8 +367,8 @@ unsigned long e820_get_reserved_pfns(int pages)
     for ( i = 0; i < e820_entries && e820_map[i].addr < last + needed; i++ )
         last = e820_map[i].addr + e820_map[i].size;
 
-    if ( i == 0 || e820_map[i - 1].type != E820_RESERVED )
-        e820_insert_entry_at(i, last, needed, E820_RESERVED);
+    if ( i == 0 || e820_map[i - 1].type != E820_TYPE_SOFT_RESERVED )
+        e820_insert_entry_at(i, last, needed, E820_TYPE_SOFT_RESERVED);
     else
         e820_map[i - 1].size += needed;
 
@@ -385,7 +385,7 @@ void e820_put_reserved_pfns(unsigned long start_pfn, int pages)
           i < e820_entries && addr >= e820_map[i].addr + e820_map[i].size;
           i++ );
 
-    BUG_ON(i == e820_entries || e820_map[i].type != E820_RESERVED ||
+    BUG_ON(i == e820_entries || e820_map[i].type != E820_TYPE_SOFT_RESERVED ||
            addr + size > e820_map[i].addr + e820_map[i].size);
 
     if ( addr == e820_map[i].addr )
@@ -405,7 +405,7 @@ void e820_put_reserved_pfns(unsigned long start_pfn, int pages)
 
     e820_insert_entry_at(i + 1, addr + size,
                          e820_map[i].addr + e820_map[i].size - addr - size,
-                         E820_RESERVED);
+                         E820_TYPE_SOFT_RESERVED);
     e820_map[i].size = addr - e820_map[i].addr;
 }
 #endif
include/e820.h +2 -0
index ffa15aa9..ad5657ff 100644
@@ -39,6 +39,8 @@
 #define E820_DISABLED     6
 #define E820_PMEM         7
 #define E820_TYPES        8
+/* Memory reserved for Mini-OS internal purpose. */
+#define E820_TYPE_SOFT_RESERVED   0xefffffff
 
 struct __packed e820entry {
     uint64_t addr;
Signature · 1 line
2.43.0
Reviewed-by on v1 10/19
#22 lore raw

Re: [MINI-OS PATCH 10/19] e820: use special type for software reserved memory

Quoted 13 lines · Juergen Gross

For memory areas used to map foreign domain memory Mini-OS is using the type E820_RESERVED in the memory map today. This is causing problems with kexec, as the new kernel should not see those areas in the memory map. Unfortunately the sequence of actions for calculating the size of the memory map and the removal of those reserved areas can't easily be adjusted to do the removal first, so another way must be used to avoid passing those reserved areas to the new kernel.

Instead of using the type E820_RESERVED, which might be used for other pages as well, just use a new type. Areas with that new type can easily be filtered out when building the memory map for the new kernel.

Quoted 4 lines

Introduce the type E820_TYPE_SOFT_RESERVED with the same value as the Linux kernel is using for the same purpose.

#23 lore raw

PATCH 11/19 mini-os: config: add support for config items with numerical values

In reply to Juergen Gross

Add support for a Mini-OS config file containing config items with numerical values, e.g. CONFIG_FOO=7.

---
 Config.mk | 4 ++++
 1 file changed, 4 insertions(+)
Config.mk +4 -0
index e2afb1b4..b9675e61 100644
@@ -178,6 +178,7 @@ endif
 # CONFIG-y contains all items defaulting to "y"
 # CONFIG-n contains all items defaulting to "n"
 # CONFIG-x contains all items being calculated if not set explicitly
+# CONFIG-val-y contains all items with numerical values, defaulting to 0
 CONFIG-y += CONFIG_START_NETWORK
 CONFIG-y += CONFIG_SPARSE_BSS
 CONFIG-y += CONFIG_BLKFRONT
@@ -219,6 +220,8 @@ CONFIG-$(lwip) += CONFIG_LWIP
 $(foreach i,$(CONFIG-y),$(eval $(i) ?= y))
 $(foreach i,$(CONFIG-n),$(eval $(i) ?= n))
 
+$(foreach i,$(CONFIG-val-y),$(eval $(i) ?= 0))
+
 CONFIG-x += CONFIG_LIBXS
 CONFIG_LIBXS ?= $(CONFIG_XENBUS)
 
@@ -226,6 +229,7 @@ CONFIG-all := $(CONFIG-y) $(CONFIG-n) $(CONFIG-x)
 
 # Export config items as compiler directives
 $(foreach i,$(CONFIG-all),$(eval DEFINES-$($(i)) += -D$(i)))
+$(foreach i,$(CONFIG-val-y),$(eval DEFINES-y += -D$(i)=$($(i))))
 
 DEFINES-y += -D__XEN_INTERFACE_VERSION__=$(XEN_INTERFACE_VERSION)
 
Signature · 1 line
2.43.0
Reviewed-by on v1 11/19
#24 lore raw

Re: [MINI-OS PATCH 11/19] mini-os: config: add support for config items with numerical values

Quoted 4 lines · Juergen Gross

Add support for a Mini-OS config file containing config items with numerical values, e.g. CONFIG_FOO=7.

Albeit I'm puzzled by the use in the next patch. Besides me perhaps simply not knowing where the new CONFIG_* would actually have its value set, I wonder why, ...

Quoted 11 lines
Config.mk +1 -0
@@ -178,6 +178,7 @@ endif
 # CONFIG-y contains all items defaulting to "y"
 # CONFIG-n contains all items defaulting to "n"
 # CONFIG-x contains all items being calculated if not set explicitly
+# CONFIG-val-y contains all items with numerical values, defaulting to 0
 CONFIG-y += CONFIG_START_NETWORK
 CONFIG-y += CONFIG_SPARSE_BSS
 CONFIG-y += CONFIG_BLKFRONT

Config.mk CONFIG-$(lwip) += CONFIG_LWIP · line 223

Quoted 4 lines
Config.mk +1 -0
@@ -219,6 +220,8 @@ CONFIG-$(lwip) += CONFIG_LWIP
 $(foreach i,$(CONFIG-y),$(eval $(i) ?= y))
 $(foreach i,$(CONFIG-n),$(eval $(i) ?= n))
 
+$(foreach i,$(CONFIG-val-y),$(eval $(i) ?= 0))

... with this and ...

Config.mk CONFIG-all := $(CONFIG-y) $(CONFIG-n) $(CONFIG-x) · line 232

Quoted 5 lines
Config.mk +1 -0
@@ -226,6 +229,7 @@ CONFIG-all := $(CONFIG-y) $(CONFIG-n) $(CONFIG-x)
 
 # Export config items as compiler directives
 $(foreach i,$(CONFIG-all),$(eval DEFINES-$($(i)) += -D$(i)))
+$(foreach i,$(CONFIG-val-y),$(eval DEFINES-y += -D$(i)=$($(i))))

... this, kexec.h still needs to have a fallback #define there.

Jan

#25 lore raw

Re: [MINI-OS PATCH 11/19] mini-os: config: add support for config items with numerical values

Quoted 30 lines · Jan Beulich
Quoted 4 lines · Juergen Gross

Add support for a Mini-OS config file containing config items with numerical values, e.g. CONFIG_FOO=7.

Albeit I'm puzzled by the use in the next patch. Besides me perhaps simply not knowing where the new CONFIG_* would actually have its value set, I wonder why, ...

Quoted 11 lines
Config.mk +1 -0
@@ -178,6 +178,7 @@ endif
  # CONFIG-y contains all items defaulting to "y"
  # CONFIG-n contains all items defaulting to "n"
  # CONFIG-x contains all items being calculated if not set explicitly
+# CONFIG-val-y contains all items with numerical values, defaulting to 0
  CONFIG-y += CONFIG_START_NETWORK
  CONFIG-y += CONFIG_SPARSE_BSS
  CONFIG-y += CONFIG_BLKFRONT

Config.mk CONFIG-$(lwip) += CONFIG_LWIP · line 223

Quoted 4 lines
Config.mk +1 -0
@@ -219,6 +220,8 @@ CONFIG-$(lwip) += CONFIG_LWIP
  $(foreach i,$(CONFIG-y),$(eval $(i) ?= y))
  $(foreach i,$(CONFIG-n),$(eval $(i) ?= n))
 
+$(foreach i,$(CONFIG-val-y),$(eval $(i) ?= 0))

... with this and ...

Quoted 7 lines

Config.mk CONFIG-all := $(CONFIG-y) $(CONFIG-n) $(CONFIG-x) · line 232

Quoted 5 lines
Config.mk +1 -0
@@ -226,6 +229,7 @@ CONFIG-all := $(CONFIG-y) $(CONFIG-n) $(CONFIG-x)
 
  # Export config items as compiler directives
  $(foreach i,$(CONFIG-all),$(eval DEFINES-$($(i)) += -D$(i)))
+$(foreach i,$(CONFIG-val-y),$(eval DEFINES-y += -D$(i)=$($(i))))

... this, kexec.h still needs to have a fallback #define there.

Thanks for catching.

I had an intermediate version using CONFIG_KEXEC_MODULE_PAGES outside kexec.c, but moved the related code later.

I'll remove the fallback.

Juergen

#26 lore raw

PATCH 12/19 mini-os: kexec: add support for handing over some memory across kexec

In reply to Juergen Gross

Especially for support of Xenstore-stubdom live update some memory must be handed over to the new kernel without moving it around: as the 9pfs device used for storing and retrieving the state of Xenstore needs to be kept operational across kexec (it can't be reopened due to Xenstore not being available without access to the device), the ring pages need to be accessible via active grants by the backend all the time.

Add the basic support for that by reserving a pre-defined number of memory pages at the top of the memory. This memory area will be handed over to the new kernel via specifying it as a module in struct hvm_start_info.

The contents of the memory area are described via a generic table of contents in the last page of the memory.

---
 Config.mk             |  2 ++
 arch/x86/kexec.c      | 77 +++++++++++++++++++++++++++++++++++++++++++
 arch/x86/mm.c         | 18 ++++++++++
 arch/x86/setup.c      | 28 ++++++++++++++++
 include/kernel.h      |  1 +
 include/kexec.h       | 45 +++++++++++++++++++++++++
 include/x86/arch_mm.h |  1 +
 kexec.c               |  3 ++
 mm.c                  |  6 ++++
 9 files changed, 181 insertions(+)
Config.mk +2 -0
index b9675e61..0e4e86d8 100644
@@ -220,6 +220,8 @@ CONFIG-$(lwip) += CONFIG_LWIP
 $(foreach i,$(CONFIG-y),$(eval $(i) ?= y))
 $(foreach i,$(CONFIG-n),$(eval $(i) ?= n))
 
+CONFIG-val-$(CONFIG_KEXEC) += CONFIG_KEXEC_MODULE_PAGES
+
 $(foreach i,$(CONFIG-val-y),$(eval $(i) ?= 0))
 
 CONFIG-x += CONFIG_LIBXS
arch/x86/kexec.c +77 -0

99 lines not on this page · raw message

arch/x86/mm.c +18 -0
index 7c3c83be..bdff38fd 100644
@@ -151,6 +151,24 @@ static struct {
     unsigned long size;
 } reserved_range[MAX_RSV_RANGES];
 
+void set_reserved_range(unsigned long start, unsigned long end)
+{
+    unsigned int i;
+
+    for ( i = 0; i < MAX_RSV_RANGES; i++ )
+    {
+        if ( reserved_range[i].size )
+            continue;
+
+        reserved_range[i].start = start;
+        reserved_range[i].size = end - start;
+
+        return;
+    }
+
+    BUG();
+}
+
 void check_memory_range(unsigned long *from, unsigned long *to)
 {
     unsigned int m;
arch/x86/setup.c +28 -0
index 2085ee5c..299ff8c7 100644
@@ -127,6 +127,13 @@ static void print_start_of_day(void *p)
     printk("    cmd_line: %s\n", cmdline);
     printk("       stack: %p-%p\n", stack, stack + sizeof(stack));
 }
+
+unsigned long get_module(unsigned long *size)
+{
+    *size = start_info_ptr->mod_len;
+
+    return start_info_ptr->mod_start;
+}
 #else
 
 /*
@@ -182,6 +189,27 @@ static void print_start_of_day(void *p)
     printk("       stack: %p-%p\n", stack, stack + sizeof(stack));
     arch_print_memmap();
 }
+
+unsigned long get_module(unsigned long *size)
+{
+    struct hvm_modlist_entry *mod;
+
+    if ( !hvm_start_info_ptr->nr_modules )
+        return 0;
+
+    if ( hvm_start_info_ptr->nr_modules > 1 )
+    {
+        printk("get_module() called with more than 1 module present\n");
+        printk("First module data returned\n");
+    }
+
+    mod = (struct hvm_modlist_entry *)(unsigned long)
+          hvm_start_info_ptr->modlist_paddr;
+
+    *size = mod->size;
+
+    return mod->paddr;
+}
 #endif
 
 /*
include/kernel.h +1 -0
index 161d7571..e11b04cf 100644
@@ -10,5 +10,6 @@ void post_suspend(int canceled);
 void do_exit(void) __attribute__((noreturn));
 void arch_do_exit(void);
 void stop_kernel(void);
+unsigned long get_module(unsigned long *size);
 
 #endif /* _KERNEL_H_ */
include/kexec.h +45 -0

55 lines not on this page · raw message

include/x86/arch_mm.h +1 -0
index a1b975dc..ae56781e 100644
@@ -289,6 +289,7 @@ unsigned long alloc_virt_kernel(unsigned n_pages);
 
 void arch_mm_pre_suspend(void);
 void arch_mm_post_suspend(int canceled);
+void set_reserved_range(unsigned long start, unsigned long end);
 
 #ifndef CONFIG_PARAVIRT
 void arch_print_memmap(void);
kexec.c +3 -0
index 2607c819..ded29882 100644
@@ -250,3 +250,6 @@ int kexec_add_action(int action, void *dest, void *src, unsigned int len)
 
     return 0;
 }
+
+unsigned long kexec_mod_start;
+struct kexec_module *mod_ptr;
mm.c +6 -0
index 8c41d2f2..b5e8d801 100644
@@ -44,6 +44,7 @@
 #include <mini-os/lib.h>
 #include <mini-os/xmalloc.h>
 #include <mini-os/e820.h>
+#include <mini-os/kexec.h>
 
 /*
  * ALLOCATION BITMAP
@@ -503,6 +504,11 @@ void init_mm(void)
     arch_init_mm(&start_pfn, &max_pfn);
     get_max_pages();
 
+#ifdef CONFIG_KEXEC
+    /* To be called after arch_init_mm() and before init_page_allocator(). */
+    kexec_module(start_pfn, max_pfn);
+#endif
+
     /* Now we can initialise the page allocator. */
     init_page_allocator(PFN_PHYS(start_pfn), PFN_PHYS(max_pfn));
     printk("MM: done\n");
Signature · 1 line
2.43.0
#27 lore raw

Re: [MINI-OS PATCH 12/19] mini-os: kexec: add support for handing over some memory across kexec

Quoted 62 lines · Juergen Gross

Especially for support of Xenstore-stubdom live update some memory must be handed over to the new kernel without moving it around: as the 9pfs device used for storing and retrieving the state of Xenstore needs to be kept operational across kexec (it can't be reopened due to Xenstore not being available without access to the device), the ring pages need to be accessible via active grants by the backend all the time.

Add the basic support for that by reserving a pre-defined number of memory pages at the top of the memory. This memory area will be handed over to the new kernel via specifying it as a module in struct hvm_start_info.

The contents of the memory area are described via a generic table of contents in the last page of the memory.

---
  Config.mk             |  2 ++
  arch/x86/kexec.c      | 77 +++++++++++++++++++++++++++++++++++++++++++
  arch/x86/mm.c         | 18 ++++++++++
  arch/x86/setup.c      | 28 ++++++++++++++++
  include/kernel.h      |  1 +
  include/kexec.h       | 45 +++++++++++++++++++++++++
  include/x86/arch_mm.h |  1 +
  kexec.c               |  3 ++
  mm.c                  |  6 ++++
  9 files changed, 181 insertions(+)
Config.mk +2 -0
index b9675e61..0e4e86d8 100644
@@ -220,6 +220,8 @@ CONFIG-$(lwip) += CONFIG_LWIP
  $(foreach i,$(CONFIG-y),$(eval $(i) ?= y))
  $(foreach i,$(CONFIG-n),$(eval $(i) ?= n))
 
+CONFIG-val-$(CONFIG_KEXEC) += CONFIG_KEXEC_MODULE_PAGES
+
  $(foreach i,$(CONFIG-val-y),$(eval $(i) ?= 0))
 
  CONFIG-x += CONFIG_LIBXS
arch/x86/kexec.c +12 -0
index 804e7b6d..7fb98473 100644
@@ -201,10 +201,73 @@ static unsigned long kexec_param_loc;
  static unsigned int kexec_param_size;
  static unsigned long kexec_param_mem;
 
+static struct kexec_module *kexec_check_module(void)
+{
+    unsigned long mod_size;
+    unsigned long mod;
+    struct kexec_module *module_ptr;
+
+    mod = get_module(&mod_size);
+    if ( !mod )
+        return NULL;
+    /* Size must be a multiple of PAGE_SIZE. */
+    if ( mod_size & ~PAGE_MASK )
+        return NULL;

arch/x86/kexec.c static unsigned long kexec_param_loc; · line 225

Quoted 10 lines
arch/x86/kexec.c +10 -0
+
+    /* Kxec module description is at start of the last page of the module. */
+    module_ptr = (void *)(mod + mod_size - (unsigned long)PAGE_SIZE);
+
+    /* Check eye catcher. */
+    if ( memcmp(module_ptr->eye_catcher, KEXECMOD_EYECATCHER,
+                sizeof(module_ptr->eye_catcher)) )
+        return NULL;
+    if ( module_ptr->n_pages != (mod_size >> PAGE_SHIFT) - 1 )
+        return NULL;

There is missing:

+ kexec_mod_start = mod;

Otherwise a second live update won't work.

I'll wait for more feedback before sending out V2.

Juergen

#28 lore raw

Re: [MINI-OS PATCH 12/19] mini-os: kexec: add support for handing over some memory across kexec

In reply to Juergen Gross
Quoted 34 lines · Juergen Gross

Especially for support of Xenstore-stubdom live update some memory must be handed over to the new kernel without moving it around: as the 9pfs device used for storing and retrieving the state of Xenstore needs to be kept operational across kexec (it can't be reopened due to Xenstore not being available without access to the device), the ring pages need to be accessible via active grants by the backend all the time.

Add the basic support for that by reserving a pre-defined number of memory pages at the top of the memory. This memory area will be handed over to the new kernel via specifying it as a module in struct hvm_start_info.

The contents of the memory area are described via a generic table of contents in the last page of the memory.

---
  Config.mk             |  2 ++
  arch/x86/kexec.c      | 77 +++++++++++++++++++++++++++++++++++++++++++
  arch/x86/mm.c         | 18 ++++++++++
  arch/x86/setup.c      | 28 ++++++++++++++++
  include/kernel.h      |  1 +
  include/kexec.h       | 45 +++++++++++++++++++++++++
  include/x86/arch_mm.h |  1 +
  kexec.c               |  3 ++
  mm.c                  |  6 ++++
  9 files changed, 181 insertions(+)
Config.mk +0 -0
index b9675e61..0e4e86d8 100644

Config.mk CONFIG-$(lwip) += CONFIG_LWIP · line 224

Quoted 5 lines
Config.mk +2 -0
@@ -220,6 +220,8 @@ CONFIG-$(lwip) += CONFIG_LWIP
  $(foreach i,$(CONFIG-y),$(eval $(i) ?= y))
  $(foreach i,$(CONFIG-n),$(eval $(i) ?= n))
 
+CONFIG-val-$(CONFIG_KEXEC) += CONFIG_KEXEC_MODULE_PAGES
+

I don't know Makefiles well enough to review the preceding patch. This doesn't seem to be used?

Quoted 15 lines
Config.mk +0 -0
  $(foreach i,$(CONFIG-val-y),$(eval $(i) ?= 0))
 
  CONFIG-x += CONFIG_LIBXS
arch/x86/kexec.c +4 -0
index 804e7b6d..7fb98473 100644
@@ -201,10 +201,73 @@ static unsigned long kexec_param_loc;
  static unsigned int kexec_param_size;
  static unsigned long kexec_param_mem;
 
+static struct kexec_module *kexec_check_module(void)
+{
+    unsigned long mod_size;
+    unsigned long mod;

arch/x86/kexec.c static unsigned long kexec_param_loc; · line 217

Quoted 10 lines
arch/x86/kexec.c +10 -0
+    struct kexec_module *module_ptr;
+
+    mod = get_module(&mod_size);
+    if ( !mod )
+        return NULL;
+    /* Size must be a multiple of PAGE_SIZE. */
+    if ( mod_size & ~PAGE_MASK )
+        return NULL;
+
+    /* Kxec module description is at start of the last page of the module. */

Kexec

Quoted 8 lines
arch/x86/kexec.c +8 -0
+    module_ptr = (void *)(mod + mod_size - (unsigned long)PAGE_SIZE);
+
+    /* Check eye catcher. */
+    if ( memcmp(module_ptr->eye_catcher, KEXECMOD_EYECATCHER,
+                sizeof(module_ptr->eye_catcher)) )
+        return NULL;
+    if ( module_ptr->n_pages != (mod_size >> PAGE_SHIFT) - 1 )
+        return NULL;

arch/x86/kexec.c static unsigned long kexec_param_loc;

Quoted 10 lines
arch/x86/kexec.c +9 -0
+
+    return module_ptr;
+}
 
+#define min(a, b) ((a) < (b) ? (a) : (b))
+void kexec_module(unsigned long start_pfn, unsigned long max_pfn)
+{
+    /* Reuse already existing kexec module. */
+    mod_ptr = kexec_check_module();
+    if ( !mod_ptr && CONFIG_KEXEC_MODULE_PAGES )

What if CONFIG_KEXEC_MODULE_PAGES changes between the old and the new stubdom?

Quoted 4 lines
arch/x86/kexec.c +4 -0
+    {
+        max_pfn = min(max_pfn, PHYS_PFN(0xffffffff));
+
+        iterate_memory_range(PFN_PHYS(start_pfn), PFN_PHYS(max_pfn),

arch/x86/kexec.c static unsigned long kexec_param_loc; · line 257

Quoted 10 lines
arch/x86/kexec.c +10 -0
+                             get_mod_addr);
+        BUG_ON(!kexec_mod_start);
+
+        mod_ptr = (void *)(kexec_mod_start +
+                           ((CONFIG_KEXEC_MODULE_PAGES - 1) << PAGE_SHIFT));
+        memset(mod_ptr, 0, PAGE_SIZE);
+        memcpy(mod_ptr->eye_catcher, KEXECMOD_EYECATCHER,
+               sizeof(mod_ptr->eye_catcher));
+        mod_ptr->n_pages = CONFIG_KEXEC_MODULE_PAGES - 1;
+        memset(mod_ptr->pg2rec, KEXECMOD_PG_FREE, mod_ptr->n_pages);

I was wondering about a BUILD_BUG_ON for CONFIG_KEXEC_MODULE_PAGES versus some limit but I can't think of one.

arch/x86/kexec.c static unsigned long kexec_param_loc; · line 259

Quoted 2 lines
arch/x86/kexec.c +2 -0
+        mod_ptr->recs_off = sizeof(struct kexec_module) +
+                            CONFIG_KEXEC_MODULE_PAGES + (mod_ptr->n_pages & 1);

mod_ptr->n_pages & 1 is to ensure 16bit alignment?

mod_ptr->n_pages = CONFIG_KEXEC_MODULE_PAGES - 1, and pg2rec is n_pages, so using CONFIG_KEXEC_MODULE_PAGES makes this off by 1?

Quoted 7 lines
arch/x86/kexec.c +5 -0
+
+        set_reserved_range(kexec_mod_start, (unsigned long)mod_ptr + PAGE_SIZE);
+    }
+}
+
 

arch/x86/kexec.c int kexec_get_entry(const char *cmdline) · line 324

Quoted 9 lines
arch/x86/kexec.c +6 -0
@@ -252,6 +316,19 @@ int kexec_get_entry(const char *cmdline)
      info->memmap_entries = mmap - (struct hvm_memmap_table_entry *)next;
      next = mmap;
 
+    if ( mod_ptr )
+    {
+        mod = next;
+        memset(mod, 0, sizeof(*mod));
+        info->nr_modules = 1;
+        info->modlist_paddr = kexec_param_loc +

Looking at this again, I wonder if kexec_param_loc would be better named _pa or _paddr.

Quoted 17 lines
arch/x86/kexec.c +7 -0
+                              (unsigned long)next - kexec_param_mem;
+        mod->paddr = kexec_mod_start;
+        mod->size = PFN_PHYS(mod_ptr->n_pages + 1);
+        mod->cmdline_paddr = 0;
+        next = mod + 1;
+    }
+
      info->cmdline_paddr = kexec_param_loc + (unsigned long)next - kexec_param_mem;
      strcpy(next, cmdline);
 
include/kexec.h +0 -0
index b89c3000..0200005f 100644

include/kexec.h line 9

Quoted 8 lines
include/kexec.h +5 -0
@@ -2,6 +2,48 @@
  #define _KEXEC_H
  #include <mini-os/elf.h>
 
+/*
+ * Kexec module used to hand over memory across kexec().
+ *
+ * This is an ABI which should be modified only in a compatible way.
+ * struct kexec_module is located at the start of the last page of the module.

Why is kexec_module, which seems like a header, placed in the last page?

Quoted 10 lines
include/kexec.h +10 -0
+ *
+ * The module can contain data/pages of multiple users. Each user has an own
+ * record which layout is depending on the user. Records are linked via a table
+ * of record offsets.
+ *
+ * All admin data (struct kexec_module, record offset table and records) must
+ * fit into the last page of the module.
+ */
+struct kexec_module {
+    uint8_t eye_catcher[8];

include/kexec.h line 29

Quoted 10 lines
include/kexec.h +10 -0
+#define KEXECMOD_EYECATCHER "KexecMem"
+    uint16_t n_pages;       /* Number of allocatable pages in the module.    */
+    uint16_t n_records;     /* Size of record table (max. 255).              */
+#define KEXECMOD_REC_MAX    255
+    uint16_t recs_off;      /* Offset to record table from start of page.    */
+                            /* The record table is an array of               */
+                            /* struct kexec_module_rec.                      */
+    uint8_t pg2rec[];       /* One entry per allocatable module page, value  */
+                            /* is record number (starting from 0) associated */
+                            /* with it. Free pages have value 255.           */

This reads like it is 1 page per record...

include/kexec.h line 34

Quoted 5 lines
include/kexec.h +5 -0
+#define KEXECMOD_PG_FREE    255
+};
+
+struct kexec_module_rec {
+    uint16_t offset;        /* Offset to record from start of page.          */

... but then why would you need an offset? How do you identify which "page" or do you mean from the start of the module?

Quoted 21 lines
include/kexec.h +12 -0
+    uint8_t type;           /* Type of record.                               */
+#define KEXECMOD_REC_NONE   0
+    uint8_t size;           /* Size of record.                               */
+};
+
+#ifndef CONFIG_KEXEC_MODULE_PAGES
+#define CONFIG_KEXEC_MODULE_PAGES 0
+#endif
+
+extern unsigned long kexec_mod_start;
+extern struct kexec_module *mod_ptr;
+
  /* One element of kexec actions (last element must have action KEXEC_CALL): */
  struct kexec_action {
      enum {
kexec.c +0 -0
index 2607c819..ded29882 100644

kexec.c int kexec_add_action(int action, void *dest, void *src, unsigned int len) · line 255

Quoted 6 lines
kexec.c +3 -0
@@ -250,3 +250,6 @@ int kexec_add_action(int action, void *dest, void *src, unsigned int len)
 
      return 0;
  }
+
+unsigned long kexec_mod_start;
+struct kexec_module *mod_ptr;

Personally, I find it a little unusual to add variables at the end of the file. But it's fine and you don't have to change it.

Regards,
Jason

#29 lore raw

Re: [MINI-OS PATCH 12/19] mini-os: kexec: add support for handing over some memory across kexec

Quoted 30 lines · Jason Andryuk
Quoted 29 lines · Juergen Gross

Especially for support of Xenstore-stubdom live update some memory must be handed over to the new kernel without moving it around: as the 9pfs device used for storing and retrieving the state of Xenstore needs to be kept operational across kexec (it can't be reopened due to Xenstore not being available without access to the device), the ring pages need to be accessible via active grants by the backend all the time.

Add the basic support for that by reserving a pre-defined number of memory pages at the top of the memory. This memory area will be handed over to the new kernel via specifying it as a module in struct hvm_start_info.

The contents of the memory area are described via a generic table of contents in the last page of the memory.

---
  Config.mk             |  2 ++
  arch/x86/kexec.c      | 77 +++++++++++++++++++++++++++++++++++++++++++ arch/x86/mm.c         | 18 ++++++++++
  arch/x86/setup.c      | 28 ++++++++++++++++ include/kernel.h      |  1 +
  include/kexec.h       | 45 +++++++++++++++++++++++++ include/x86/arch_mm.h |  1 +
  kexec.c               |  3 ++
  mm.c                  |  6 ++++

  9 files changed, 181 insertions(+)
Quoted 11 lines

Config.mk CONFIG-$(lwip) += CONFIG_LWIP · line 223

Quoted 9 lines
Config.mk +2 -0
index b9675e61..0e4e86d8 100644
@@ -220,6 +220,8 @@ CONFIG-$(lwip) += CONFIG_LWIP
   $(foreach i,$(CONFIG-y),$(eval $(i) ?= y))
   $(foreach i,$(CONFIG-n),$(eval $(i) ?= n))
+CONFIG-val-$(CONFIG_KEXEC) += CONFIG_KEXEC_MODULE_PAGES
+

I don't know Makefiles well enough to review the preceding patch.  This doesn't seem to be used?

It is.

Quoted 18 lines
Quoted 18 lines
Config.mk +0 -0
   $(foreach i,$(CONFIG-val-y),$(eval $(i) ?= 0))

  CONFIG-x += CONFIG_LIBXS

arch/x86/kexec.c +8 -0
index 804e7b6d..7fb98473 100644
@@ -201,10 +201,73 @@ static unsigned long kexec_param_loc;
   static unsigned int kexec_param_size;
   static unsigned long kexec_param_mem;
+static struct kexec_module *kexec_check_module(void)
+{
+    unsigned long mod_size;
+    unsigned long mod;
+    struct kexec_module *module_ptr;
+
+    mod = get_module(&mod_size);
+    if ( !mod )
Quoted 8 lines

arch/x86/kexec.c static unsigned long kexec_param_loc; · line 217

Quoted 6 lines
arch/x86/kexec.c +6 -0
+        return NULL;
+    /* Size must be a multiple of PAGE_SIZE. */
+    if ( mod_size & ~PAGE_MASK )
+        return NULL;
+
+    /* Kxec module description is at start of the last page of the module. */

Kexec

Yes. Seen it already.

Quoted 13 lines
Quoted 12 lines
arch/x86/kexec.c +11 -0
+    module_ptr = (void *)(mod + mod_size - (unsigned long)PAGE_SIZE);
+
+    /* Check eye catcher. */
+    if ( memcmp(module_ptr->eye_catcher, KEXECMOD_EYECATCHER,
+                sizeof(module_ptr->eye_catcher)) )
+        return NULL;
+    if ( module_ptr->n_pages != (mod_size >> PAGE_SHIFT) - 1 )
+        return NULL;
+
+    return module_ptr;
+}
Quoted 8 lines

arch/x86/kexec.c static unsigned long kexec_param_loc; · line 243

Quoted 6 lines
arch/x86/kexec.c +6 -0
+#define min(a, b) ((a) < (b) ? (a) : (b))
+void kexec_module(unsigned long start_pfn, unsigned long max_pfn)
+{
+    /* Reuse already existing kexec module. */
+    mod_ptr = kexec_check_module();
+    if ( !mod_ptr && CONFIG_KEXEC_MODULE_PAGES )

What if CONFIG_KEXEC_MODULE_PAGES changes between the old and the new stubdom?

Right now this wouldn't really matter. The CONFIG value is used only for sizing the module if we are not started via kexec().

Quoted 17 lines
Quoted 5 lines
arch/x86/kexec.c +4 -0
+    {
+        max_pfn = min(max_pfn, PHYS_PFN(0xffffffff));
+
+        iterate_memory_range(PFN_PHYS(start_pfn), PFN_PHYS(max_pfn),

arch/x86/kexec.c static unsigned long kexec_param_loc; · line 257

Quoted 10 lines
arch/x86/kexec.c +10 -0
+                             get_mod_addr);
+        BUG_ON(!kexec_mod_start);
+
+        mod_ptr = (void *)(kexec_mod_start +
+                           ((CONFIG_KEXEC_MODULE_PAGES - 1) << PAGE_SHIFT));
+        memset(mod_ptr, 0, PAGE_SIZE);
+        memcpy(mod_ptr->eye_catcher, KEXECMOD_EYECATCHER,
+               sizeof(mod_ptr->eye_catcher));
+        mod_ptr->n_pages = CONFIG_KEXEC_MODULE_PAGES - 1;
+        memset(mod_ptr->pg2rec, KEXECMOD_PG_FREE, mod_ptr->n_pages);

I was wondering about a BUILD_BUG_ON for CONFIG_KEXEC_MODULE_PAGES versus some limit but I can't think of one.

I don't think we need that. If the value is too high, it will be just a bug.

Quoted 6 lines

arch/x86/kexec.c static unsigned long kexec_param_loc; · line 259

Quoted 2 lines
arch/x86/kexec.c +2 -0
+        mod_ptr->recs_off = sizeof(struct kexec_module) +
+                            CONFIG_KEXEC_MODULE_PAGES + (mod_ptr->n_pages & 1);

mod_ptr->n_pages & 1 is to ensure 16bit alignment?

mod_ptr->n_pages = CONFIG_KEXEC_MODULE_PAGES - 1, and pg2rec is n_pages, so using CONFIG_KEXEC_MODULE_PAGES makes this off by 1?

Thanks for catching this. I failed to fix that when switching to "mod_ptr->n_pages = CONFIG_KEXEC_MODULE_PAGES - 1" (initially I didn't have the "- 1", but this required too many corrections by 1 at other places).

Quoted 7 lines
Quoted 6 lines
arch/x86/kexec.c +5 -0
+
+        set_reserved_range(kexec_mod_start, (unsigned long)mod_ptr + PAGE_SIZE);
+    }
+}
+
Quoted 11 lines

arch/x86/kexec.c int kexec_get_entry(const char *cmdline) · line 323

Quoted 9 lines
arch/x86/kexec.c +6 -0
@@ -252,6 +316,19 @@ int kexec_get_entry(const char *cmdline)
       info->memmap_entries = mmap - (struct hvm_memmap_table_entry *)next;
       next = mmap;
+    if ( mod_ptr )
+    {
+        mod = next;
+        memset(mod, 0, sizeof(*mod));
+        info->nr_modules = 1;
+        info->modlist_paddr = kexec_param_loc +

Looking at this again, I wonder if kexec_param_loc would be better named _pa or _paddr.

Yes, good idea.

Quoted 12 lines
Quoted 10 lines
arch/x86/kexec.c +7 -0
+                              (unsigned long)next - kexec_param_mem;
+        mod->paddr = kexec_mod_start;
+        mod->size = PFN_PHYS(mod_ptr->n_pages + 1);
+        mod->cmdline_paddr = 0;
+        next = mod + 1;
+    }
+
       info->cmdline_paddr = kexec_param_loc + (unsigned long)next - kexec_param_mem;
       strcpy(next, cmdline);
Quoted 14 lines

include/kexec.h line 8

Quoted 12 lines
include/kexec.h +5 -0
index b89c3000..0200005f 100644
@@ -2,6 +2,48 @@
   #define _KEXEC_H
   #include <mini-os/elf.h>
+/*
+ * Kexec module used to hand over memory across kexec().
+ *
+ * This is an ABI which should be modified only in a compatible way.
+ * struct kexec_module is located at the start of the last page of the module.

Why is kexec_module, which seems like a header, placed in the last page?

In case we ever need to grow the module (e.g. when adding new data to it and with that having to handle different CONFIG_KEXEC_MODULE_PAGES values between old and new build), it will be easier, as the module will normally be located at the end of the usable memory, so we wouldn't have to move the struct kexec_module around.

Quoted 15 lines
Quoted 15 lines
include/kexec.h +14 -0
+ *
+ * The module can contain data/pages of multiple users. Each user has an own
+ * record which layout is depending on the user. Records are linked via a table
+ * of record offsets.
+ *
+ * All admin data (struct kexec_module, record offset table and records) must
+ * fit into the last page of the module.
+ */
+struct kexec_module {
+    uint8_t eye_catcher[8];
+#define KEXECMOD_EYECATCHER "KexecMem"
+    uint16_t n_pages;       /* Number of allocatable pages in the module.    */
+    uint16_t n_records;     /* Size of record table (max. 255).              */
+#define KEXECMOD_REC_MAX    255
Quoted 8 lines

include/kexec.h line 29

Quoted 6 lines
include/kexec.h +6 -0
+    uint16_t recs_off;      /* Offset to record table from start of page.    */
+                            /* The record table is an array of               */
+                            /* struct kexec_module_rec.                      */
+    uint8_t pg2rec[];       /* One entry per allocatable module page, value  */
+                            /* is record number (starting from 0) associated */
+                            /* with it. Free pages have value 255.           */

This reads like it is 1 page per record...

No, this means that each used page is associated with a record, but there can be [0 ... n_pages] associated with each record.

Quoted 8 lines

include/kexec.h line 34

Quoted 6 lines
include/kexec.h +5 -0
+#define KEXECMOD_PG_FREE    255
+};
+
+struct kexec_module_rec {
+    uint16_t offset;        /* Offset to record from start of page.          */

... but then why would you need an offset?  How do you identify which "page" or do you mean from the start of the module?

The record itself needs to contain the data for finding the pages associated with it. See patch 18 for the details of the 9pfs record added there.

It will use all 17 allocatable pages from the module (1 for the main 9pfs shared interface page plus 16 for the shared rings), while the record itself will hold the grant reference of the 9pfs interface page, which serves as the key for locating the page itself and the ring pages.

Quoted 17 lines
Quoted 16 lines
include/kexec.h +12 -0
+    uint8_t type;           /* Type of record.                               */
+#define KEXECMOD_REC_NONE   0
+    uint8_t size;           /* Size of record.                               */
+};
+
+#ifndef CONFIG_KEXEC_MODULE_PAGES
+#define CONFIG_KEXEC_MODULE_PAGES 0
+#endif
+
+extern unsigned long kexec_mod_start;
+extern struct kexec_module *mod_ptr;
+
   /* One element of kexec actions (last element must have action KEXEC_CALL): */
   struct kexec_action {
       enum {
Quoted 13 lines

kexec.c int kexec_add_action(int action, void *dest, void *src, · line 255

Quoted 11 lines
kexec.c +3 -0
index 2607c819..ded29882 100644
@@ -250,3 +250,6 @@ int kexec_add_action(int action, void *dest, void *src, 
 unsigned int len)
       return 0;
   }
+
+unsigned long kexec_mod_start;
+struct kexec_module *mod_ptr;

Personally, I find it a little unusual to add variables at the end of the file. But it's fine and you don't have to change it.

Patch 13 will add the common code below those additions. :-)

Juergen

#30 lore raw

Re: [MINI-OS PATCH 12/19] mini-os: kexec: add support for handing over some memory across kexec

Quoted 32 lines · Jürgen Groß
Quoted 19 lines · Jason Andryuk
Quoted 17 lines · Juergen Gross

Especially for support of Xenstore-stubdom live update some memory must be handed over to the new kernel without moving it around: as the 9pfs device used for storing and retrieving the state of Xenstore needs to be kept operational across kexec (it can't be reopened due to Xenstore not being available without access to the device), the ring pages need to be accessible via active grants by the backend all the time.

Add the basic support for that by reserving a pre-defined number of memory pages at the top of the memory. This memory area will be handed over to the new kernel via specifying it as a module in struct hvm_start_info.

The contents of the memory area are described via a generic table of contents in the last page of the memory.

Quoted 11 lines

Config.mk CONFIG-$(lwip) += CONFIG_LWIP · line 223

Quoted 9 lines
Config.mk +2 -0
index b9675e61..0e4e86d8 100644
@@ -220,6 +220,8 @@ CONFIG-$(lwip) += CONFIG_LWIP
   $(foreach i,$(CONFIG-y),$(eval $(i) ?= y))
   $(foreach i,$(CONFIG-n),$(eval $(i) ?= n))
+CONFIG-val-$(CONFIG_KEXEC) += CONFIG_KEXEC_MODULE_PAGES
+

I don't know Makefiles well enough to review the preceding patch. This doesn't seem to be used?

Quoted 1 line

It is.

Oh, so setting CONFIG-val-y, through the Makefile magic, creates -DCONFIG_KEXEC_MODULE_PAGES=$n

I said I didn't know Makefiles well :)

Quoted 25 lines
Quoted 16 lines
Quoted 15 lines
Config.mk +0 -0
   $(foreach i,$(CONFIG-val-y),$(eval $(i) ?= 0))

  CONFIG-x += CONFIG_LIBXS

+    module_ptr = (void *)(mod + mod_size - (unsigned long)PAGE_SIZE);

Config.mk +10 -0
+
+    /* Check eye catcher. */
+    if ( memcmp(module_ptr->eye_catcher, KEXECMOD_EYECATCHER,
+                sizeof(module_ptr->eye_catcher)) )
+        return NULL;
+    if ( module_ptr->n_pages != (mod_size >> PAGE_SHIFT) - 1 )
+        return NULL;
+
+    return module_ptr;
+}
Quoted 8 lines

Config.mk

Quoted 6 lines
Config.mk +6 -0
+#define min(a, b) ((a) < (b) ? (a) : (b))
+void kexec_module(unsigned long start_pfn, unsigned long max_pfn)
+{
+    /* Reuse already existing kexec module. */
+    mod_ptr = kexec_check_module();
+    if ( !mod_ptr && CONFIG_KEXEC_MODULE_PAGES )

What if CONFIG_KEXEC_MODULE_PAGES changes between the old and the new stubdom?

Quoted 2 lines

Right now this wouldn't really matter. The CONFIG value is used only for sizing the module if we are not started via kexec().

When I wrote this I was thinking of:
A -- kexec --> B -- kexec --> C

A: CONFIG_KEXEC_MODULE_PAGES=4
B: CONFIG_KEXEC_MODULE_PAGES=6

When B is running, it has the 4 pages from A, but it expects 6 available for its use....

Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
include/kexec.h +0 -0
index b89c3000..0200005f 100644
@@ -2,6 +2,48 @@
   #define _KEXEC_H
   #include <mini-os/elf.h>
Quoted 8 lines
Quoted 6 lines
include/kexec.h +5 -0
+/*
+ * Kexec module used to hand over memory across kexec().
+ *
+ * This is an ABI which should be modified only in a compatible way.
+ * struct kexec_module is located at the start of the last page of 

the module.

Why is kexec_module, which seems like a header, placed in the last page?

Quoted 5 lines

In case we ever need to grow the module (e.g. when adding new data to it and with that having to handle different CONFIG_KEXEC_MODULE_PAGES values between old and new build), it will be easier, as the module will normally be located at the end of the usable memory, so we wouldn't have to move the struct kexec_module around.

.. and this avoids that issue since the extra pages can be grabbed without moving struct kexec_module.

Quoted 35 lines
Quoted 26 lines
Quoted 26 lines

+ *
+ * The module can contain data/pages of multiple users. Each user has an own
+ * record which layout is depending on the user. Records are linked via a table
+ * of record offsets.
+ *
+ * All admin data (struct kexec_module, record offset table and records) must
+ * fit into the last page of the module.
+ */

include/kexec.h +4 -0
+struct kexec_module {
+    uint8_t eye_catcher[8];
+#define KEXECMOD_EYECATCHER "KexecMem"
+    uint16_t n_pages;       /* Number of allocatable pages in the 

module.    */
+    uint16_t n_records;     /* Size of record table (max. 255).              */
+#define KEXECMOD_REC_MAX    255
+    uint16_t recs_off;      /* Offset to record table from start of page.    */
+                            /* The record table is an array of               */
+                            /* struct
kexec_module_rec.                      */

Quoted 8 lines
Quoted 6 lines

+    uint8_t pg2rec[];       /* One entry per allocatable module page, value  */
+                            /* is record number (starting from 0) associated */
+                            /* with it. Free pages have value 255.           */

This reads like it is 1 page per record...

Quoted 2 lines

No, this means that each used page is associated with a record, but there can be [0 ... n_pages] associated with each record.

Maybe:
"Mapping of module pages to associated module record. Allocated pages are indicated by their record number (starting from 0). Free pages have value 255."?

Quoted 14 lines
Quoted 9 lines
Quoted 7 lines
include/kexec.h +5 -0
+#define KEXECMOD_PG_FREE    255
+};
+
+struct kexec_module_rec {
+    uint16_t offset;        /* Offset to record from start of 

page.          */

... but then why would you need an offset?  How do you identify which "page" or do you mean from the start of the module?

The record itself needs to contain the data for finding the pages associated with it. See patch 18 for the details of the 9pfs record added there.

Quoted 5 lines

It will use all 17 allocatable pages from the module (1 for the main 9pfs shared interface page plus 16 for the shared rings), while the record itself will hold the grant reference of the 9pfs interface page, which serves as the key for locating the page itself and the ring pages.

I was missing the overall view. I think I have it now from reading patch 13.

From kexec_mod_start, we have:
(CONFIG_KEXEC_MODULE_PAGES - 1) pages (allocated as pages - referenced by pg2rec) struct kexec_module *mod_ptr is the start of the final page. pg2rec[n_pages]
struct kexec_module_rec mod_recs[n_records]
< extra data for each mod_recs found by .offset and .size >

I didn't realize the mod_recs were separate from their "extra data", and extra data took up the end of the. If that's correct, I think it would be helpful to describe the overall layout.

Thanks,
Jason

Quoted 19 lines
Quoted 19 lines
Quoted 18 lines

+    uint8_t type;           /* Type of
record.                               */
+#define KEXECMOD_REC_NONE   0
+    uint8_t size;           /* Size of
record.                               */

include/kexec.h +9 -0
+};
+
+#ifndef CONFIG_KEXEC_MODULE_PAGES
+#define CONFIG_KEXEC_MODULE_PAGES 0
+#endif
+
+extern unsigned long kexec_mod_start;
+extern struct kexec_module *mod_ptr;
+

  /* One element of kexec actions (last element must have action KEXEC_CALL): */ struct kexec_action {
      enum {

#31 lore raw

Re: [MINI-OS PATCH 12/19] mini-os: kexec: add support for handing over some memory across kexec

Quoted 68 lines · Jason Andryuk
Quoted 32 lines · Jürgen Groß
Quoted 19 lines · Jason Andryuk
Quoted 17 lines · Juergen Gross

Especially for support of Xenstore-stubdom live update some memory must be handed over to the new kernel without moving it around: as the 9pfs device used for storing and retrieving the state of Xenstore needs to be kept operational across kexec (it can't be reopened due to Xenstore not being available without access to the device), the ring pages need to be accessible via active grants by the backend all the time.

Add the basic support for that by reserving a pre-defined number of memory pages at the top of the memory. This memory area will be handed over to the new kernel via specifying it as a module in struct hvm_start_info.

The contents of the memory area are described via a generic table of contents in the last page of the memory.

Quoted 11 lines

Config.mk CONFIG-$(lwip) += CONFIG_LWIP · line 223

Quoted 9 lines
Config.mk +2 -0
index b9675e61..0e4e86d8 100644
@@ -220,6 +220,8 @@ CONFIG-$(lwip) += CONFIG_LWIP
   $(foreach i,$(CONFIG-y),$(eval $(i) ?= y))
   $(foreach i,$(CONFIG-n),$(eval $(i) ?= n))
+CONFIG-val-$(CONFIG_KEXEC) += CONFIG_KEXEC_MODULE_PAGES
+

I don't know Makefiles well enough to review the preceding patch. This doesn't seem to be used?

Quoted 1 line

It is.

Oh, so setting CONFIG-val-y, through the Makefile magic, creates -DCONFIG_KEXEC_MODULE_PAGES=$n

I said I didn't know Makefiles well :)

Quoted 25 lines
Quoted 16 lines
Quoted 15 lines
Config.mk +0 -0
   $(foreach i,$(CONFIG-val-y),$(eval $(i) ?= 0))

  CONFIG-x += CONFIG_LIBXS

+    module_ptr = (void *)(mod + mod_size - (unsigned long)PAGE_SIZE);

Config.mk +10 -0
+
+    /* Check eye catcher. */
+    if ( memcmp(module_ptr->eye_catcher, KEXECMOD_EYECATCHER,
+                sizeof(module_ptr->eye_catcher)) )
+        return NULL;
+    if ( module_ptr->n_pages != (mod_size >> PAGE_SHIFT) - 1 )
+        return NULL;
+
+    return module_ptr;
+}
Quoted 8 lines

Config.mk

Quoted 6 lines
Config.mk +6 -0
+#define min(a, b) ((a) < (b) ? (a) : (b))
+void kexec_module(unsigned long start_pfn, unsigned long max_pfn)
+{
+    /* Reuse already existing kexec module. */
+    mod_ptr = kexec_check_module();
+    if ( !mod_ptr && CONFIG_KEXEC_MODULE_PAGES )

What if CONFIG_KEXEC_MODULE_PAGES changes between the old and the new stubdom?

Quoted 2 lines

Right now this wouldn't really matter. The CONFIG value is used only for sizing the module if we are not started via kexec().

Quoted 7 lines

When I wrote this I was thinking of:
A -- kexec --> B -- kexec --> C

A: CONFIG_KEXEC_MODULE_PAGES=4
B: CONFIG_KEXEC_MODULE_PAGES=6

When B is running, it has the 4 pages from A, but it expects 6 available for its use....

Depends...

Looking at the first user (xenstore-stubdom), things are a little bit more complicated.

All the allocated pages (so everything apart from the last page containing the records) are used for the 9pfs device shared pages. This number will only change, if the ring buffer size is changed (lets skip the case where another use case of a kexec module page is coming up). As the device is being kept open across kexec(), the size of the ring buffer will be kept, so there is no reason to use more kexec module pages. This is working fine, as all the relevant parameters of the 9pfs device are taken from the kexec 9pfs record or the shared pages themselves after kexec(), instead of using the builtin defaults.

This could change only, if we'd add support to reconnect the 9pfs device after kexec() using a different ring buffer size (and/or maybe multiple rings). In this case we'd need to implement the capability to resize the kexec module, which is possible with the current design, but not needed yet.

Quoted 16 lines
Quoted 16 lines
Quoted 15 lines

include/kexec.h line 8

Quoted 13 lines
include/kexec.h +5 -0
index b89c3000..0200005f 100644
@@ -2,6 +2,48 @@
   #define _KEXEC_H
   #include <mini-os/elf.h>
+/*
+ * Kexec module used to hand over memory across kexec().
+ *
+ * This is an ABI which should be modified only in a compatible way.
+ * struct kexec_module is located at the start of the last page of the module.

Why is kexec_module, which seems like a header, placed in the last page?

Quoted 7 lines
Quoted 5 lines

In case we ever need to grow the module (e.g. when adding new data to it and with that having to handle different CONFIG_KEXEC_MODULE_PAGES values between old and new build), it will be easier, as the module will normally be located at the end of the usable memory, so we wouldn't have to move the struct kexec_module around.

.. and this avoids that issue since the extra pages can be grabbed without moving struct kexec_module.

Right.

Quoted 34 lines
Quoted 34 lines
Quoted 33 lines
Quoted 23 lines
include/kexec.h +3 -0
+ *
+ * The module can contain data/pages of multiple users. Each user has an own
+ * record which layout is depending on the user. Records are linked via a 

table
+ * of record offsets.
+ *
+ * All admin data (struct kexec_module, record offset table and records) must
+ * fit into the last page of the module.
+ */

include/kexec.h +4 -0
+struct kexec_module {
+    uint8_t eye_catcher[8];
+#define KEXECMOD_EYECATCHER "KexecMem"
+    uint16_t n_pages;       /* Number of allocatable pages in the 

module.    */
+    uint16_t n_records;     /* Size of record table (max. 255).              */
+#define KEXECMOD_REC_MAX    255
+    uint16_t recs_off;      /* Offset to record table from start of page.    */
+                            /* The record table is an array of               */

Quoted 8 lines

+                            /* struct
kexec_module_rec.                      */
+    uint8_t pg2rec[];       /* One entry per allocatable module page, value  */
+                            /* is record number (starting from 0) associated */
+                            /* with it. Free pages have value 255.           */

This reads like it is 1 page per record...

Quoted 5 lines
Quoted 2 lines

No, this means that each used page is associated with a record, but there can be [0 ... n_pages] associated with each record.

Maybe:
"Mapping of module pages to associated module record.  Allocated pages are indicated by their record number (starting from 0).  Free pages have value 255."?

Fine with me.

Quoted 23 lines
Quoted 15 lines
Quoted 10 lines
Quoted 8 lines
include/kexec.h +5 -0
+#define KEXECMOD_PG_FREE    255
+};
+
+struct kexec_module_rec {
+    uint16_t offset;        /* Offset to record from start of 

page.          */

... but then why would you need an offset?  How do you identify which "page" or do you mean from the start of the module?

The record itself needs to contain the data for finding the pages associated with it. See patch 18 for the details of the 9pfs record added there.

Quoted 5 lines

It will use all 17 allocatable pages from the module (1 for the main 9pfs shared interface page plus 16 for the shared rings), while the record itself will hold the grant reference of the 9pfs interface page, which serves as the key for locating the page itself and the ring pages.

I was missing the overall view.  I think I have it now from reading patch 13.

Quoted 8 lines

From kexec_mod_start, we have:
(CONFIG_KEXEC_MODULE_PAGES - 1) pages (allocated as pages - referenced by pg2rec) struct kexec_module *mod_ptr is the start of the final page. pg2rec[n_pages]
struct kexec_module_rec mod_recs[n_records]
< extra data for each mod_recs found by .offset and .size >

I didn't realize the mod_recs were separate from their "extra data", and extra data took up the end of the.  If that's correct, I think it would be helpful to describe the overall layout.

I'll change the kexec module description comment.

Juergen

#32 lore raw

PATCH 13/19 kexec: add support for allocating pages from kexec module memory

In reply to Juergen Gross

Add the needed functions for allocating and freeing memory pages of the kexec module.

As the pages are always related to a kexec module record, add the related utility functions, too. For now only support adding records and retrieving them.

---
 arch/x86/kexec.c |  16 +++++++
 include/kexec.h  |  52 +++++++++++++++++++++
 kexec.c          | 115 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 183 insertions(+)
arch/x86/kexec.c +16 -0
index 7fb98473..8b3e841a 100644
@@ -238,6 +238,9 @@ static void get_mod_addr(unsigned long from, unsigned long to)
 #define min(a, b) ((a) < (b) ? (a) : (b))
 void kexec_module(unsigned long start_pfn, unsigned long max_pfn)
 {
+    unsigned int i;
+    char *rec_end;
+
     /* Reuse already existing kexec module. */
     mod_ptr = kexec_check_module();
     if ( !mod_ptr && CONFIG_KEXEC_MODULE_PAGES )
@@ -255,11 +258,24 @@ void kexec_module(unsigned long start_pfn, unsigned long max_pfn)
                sizeof(mod_ptr->eye_catcher));
         mod_ptr->n_pages = CONFIG_KEXEC_MODULE_PAGES - 1;
         memset(mod_ptr->pg2rec, KEXECMOD_PG_FREE, mod_ptr->n_pages);
+        mod_ptr->n_records = 16;
         mod_ptr->recs_off = sizeof(struct kexec_module) +
                             CONFIG_KEXEC_MODULE_PAGES + (mod_ptr->n_pages & 1);
 
         set_reserved_range(kexec_mod_start, (unsigned long)mod_ptr + PAGE_SIZE);
     }
+
+    mod_recs = (void *)((unsigned long)mod_ptr + mod_ptr->recs_off);
+    mod_rec_start = (char *)(mod_recs + mod_ptr->n_records);
+    mod_rec_end = mod_rec_start;
+    for ( i = 0; i < mod_ptr->n_records; i++ )
+    {
+        if ( mod_recs[i].type == KEXECMOD_REC_NONE )
+            continue;
+        rec_end = (char *)mod_ptr + mod_recs[i].offset + mod_recs[i].size;
+        if ( mod_rec_end < rec_end )
+            mod_rec_end = rec_end;
+    }
 }
 
 void kexec_set_param_loc(const char *cmdline)
include/kexec.h +52 -0

68 lines not on this page · raw message

kexec.c +115 -0

118 lines not on this page · raw message

Signature · 1 line
2.43.0
Reviewed-by on v1 13/19
#33 lore raw

Re: [MINI-OS PATCH 13/19] kexec: add support for allocating pages from kexec module memory

Quoted 8 lines · Juergen Gross

Add the needed functions for allocating and freeing memory pages of the kexec module.

As the pages are always related to a kexec module record, add the related utility functions, too. For now only support adding records and retrieving them.

#34 lore raw

PATCH 14/19 9pfs: store bepath in struct struct dev_9pfs

In reply to Juergen Gross

Use struct dev_9pfs for storing the backend path of the device state in order to avoid code duplication in init_9pfront() and shutdown_9pfront().

---
 9pfront.c | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)
9pfront.c +10 -13
index 895426d1..2bfc49b1 100644
@@ -25,6 +25,7 @@ struct dev_9pfs {
     char nodename[20];
     unsigned int dom;
     char *backend;
+    char bepath[64];
 
     char *tag;
     const char *mnt;
@@ -1103,7 +1104,6 @@ void *init_9pfront(unsigned int id, const char *mnt)
     char *reason = "";
     xenbus_transaction_t xbt;
     int retry = 1;
-    char bepath[64] = { 0 };
     XenbusState state;
     unsigned int i;
     void *addr;
@@ -1137,11 +1137,12 @@ void *init_9pfront(unsigned int id, const char *mnt)
     if ( msg )
         goto err;
 
-    snprintf(bepath, sizeof(bepath), "%s/state", dev->backend);
-    free(xenbus_watch_path_token(XBT_NIL, bepath, bepath, &dev->events));
-    state = xenbus_read_integer(bepath);
+    snprintf(dev->bepath, sizeof(dev->bepath), "%s/state", dev->backend);
+    free(xenbus_watch_path_token(XBT_NIL, dev->bepath, dev->bepath,
+                                 &dev->events));
+    state = xenbus_read_integer(dev->bepath);
     while ( msg == NULL && state < XenbusStateInitWait )
-        msg = xenbus_wait_for_state_change(bepath, &state, &dev->events);
+        msg = xenbus_wait_for_state_change(dev->bepath, &state, &dev->events);
     if ( msg || state != XenbusStateInitWait )
     {
         reason = "illegal backend state";
@@ -1228,9 +1229,9 @@ void *init_9pfront(unsigned int id, const char *mnt)
         free(xenbus_transaction_end(xbt, 0, &retry));
     }
 
-    state = xenbus_read_integer(bepath);
+    state = xenbus_read_integer(dev->bepath);
     while ( msg == NULL && state < XenbusStateConnected )
-        msg = xenbus_wait_for_state_change(bepath, &state, &dev->events);
+        msg = xenbus_wait_for_state_change(dev->bepath, &state, &dev->events);
     if ( msg || state != XenbusStateConnected )
     {
         reason = "illegal backend state";
@@ -1263,8 +1264,6 @@ void *init_9pfront(unsigned int id, const char *mnt)
     free(xenbus_transaction_end(xbt, 1, &retry));
 
  err:
-    if ( bepath[0] )
-        free(xenbus_unwatch_path_token(XBT_NIL, bepath, bepath));
     if ( msg )
         printk("9pfsfront add %u failed, error %s accessing Xenstore\n",
                id, msg);
@@ -1279,22 +1278,20 @@ EXPORT_SYMBOL(init_9pfront);
 void shutdown_9pfront(void *dev)
 {
     struct dev_9pfs *dev9p = dev;
-    char bepath[64];
     XenbusState state;
     char *msg;
     char *reason = "";
 
     umount(dev9p->mnt);
-    snprintf(bepath, sizeof(bepath), "%s/state", dev9p->backend);
 
     msg = xenbus_printf(XBT_NIL, dev9p->nodename, "state", "%u",
                         XenbusStateClosing);
     if ( msg )
         goto err;
 
-    state = xenbus_read_integer(bepath);
+    state = xenbus_read_integer(dev9p->bepath);
     while ( msg == NULL && state < XenbusStateClosing)
-        msg = xenbus_wait_for_state_change(bepath, &state, &dev9p->events);
+        msg = xenbus_wait_for_state_change(dev9p->bepath, &state, &dev9p->events);
     if ( msg || state != XenbusStateClosing )
     {
         reason = "illegal backend state";
Signature · 1 line
2.43.0
#36 lore raw

PATCH 15/19 9pfs: refactor init_9pfront()

In reply to Juergen Gross

Move the Xenstore and backend interface related handling into a sub-function in order to prepare supporting reconnecting to an active 9pfs device after kexec.

---
 9pfront.c | 136 ++++++++++++++++++++++++++++++++++--------------------
 1 file changed, 86 insertions(+), 50 deletions(-)
9pfront.c +86 -50
index 2bfc49b1..8da2f726 100644
@@ -1097,68 +1097,65 @@ static void free_9pfront(struct dev_9pfs *dev)
     free(dev);
 }
 
-void *init_9pfront(unsigned int id, const char *mnt)
+static bool issue_err(struct dev_9pfs *dev, char *msg, char *reason)
+{
+    if ( msg )
+    {
+        printk("9pfsfront add %u failed, error %s accessing Xenstore\n",
+               dev->id, msg);
+        free(msg);
+    }
+    else
+        printk("9pfsfront add %u failed, %s\n", dev->id, reason);
+
+    return false;
+}
+
+static bool read_config_xs(struct dev_9pfs *dev)
 {
-    struct dev_9pfs *dev;
     char *msg;
     char *reason = "";
-    xenbus_transaction_t xbt;
-    int retry = 1;
     XenbusState state;
-    unsigned int i;
-    void *addr;
+    xenbus_transaction_t xbt;
     char *version;
     char *v;
-
-    printk("9pfsfront add %u, for mount at %s\n", id, mnt);
-    dev = malloc(sizeof(*dev));
-    memset(dev, 0, sizeof(*dev));
-    snprintf(dev->nodename, sizeof(dev->nodename), "device/9pfs/%u", id);
-    dev->id = id;
-    init_waitqueue_head(&dev->waitq);
-    init_SEMAPHORE(&dev->ring_out_sem, 1);
-    init_SEMAPHORE(&dev->ring_in_sem, 1);
-    dev->fid_mask = ~0ULL;
-
-    for ( i = 0; i < N_REQS; i++ )
-    {
-        dev->req[i].id = i;
-        dev->req[i].next_free = i + 1;
-    }
-    dev->free_reqs = 0;
+    void *addr;
+    unsigned int i;
+    int retry = 1;
 
     msg = xenbus_read_unsigned(XBT_NIL, dev->nodename, "backend-id", &dev->dom);
     if ( msg )
-        goto err;
+        return issue_err(dev, msg, reason);
     msg = xenbus_read_string(XBT_NIL, dev->nodename, "backend", &dev->backend);
     if ( msg )
-        goto err;
+        return issue_err(dev, msg, reason);
     msg = xenbus_read_string(XBT_NIL, dev->nodename, "tag", &dev->tag);
     if ( msg )
-        goto err;
+        return issue_err(dev, msg, reason);
 
     snprintf(dev->bepath, sizeof(dev->bepath), "%s/state", dev->backend);
     free(xenbus_watch_path_token(XBT_NIL, dev->bepath, dev->bepath,
                                  &dev->events));
+
     state = xenbus_read_integer(dev->bepath);
     while ( msg == NULL && state < XenbusStateInitWait )
         msg = xenbus_wait_for_state_change(dev->bepath, &state, &dev->events);
     if ( msg || state != XenbusStateInitWait )
     {
         reason = "illegal backend state";
-        goto err;
+        return issue_err(dev, msg, reason);
     }
 
     msg = xenbus_read_unsigned(XBT_NIL, dev->backend, "max-ring-page-order",
                                &dev->ring_order);
     if ( msg )
-        goto err;
+        return issue_err(dev, msg, reason);
     if ( dev->ring_order > DEFAULT_9PFS_RING_ORDER )
         dev->ring_order = DEFAULT_9PFS_RING_ORDER;
 
     msg = xenbus_read_string(XBT_NIL, dev->backend, "versions", &version);
     if ( msg )
-        goto err;
+        return issue_err(dev, msg, reason);
     for ( v = version; *v; v++ )
     {
         if ( strtoul(v, &v, 10) == 1 && (*v == ',' || *v == 0) )
@@ -1170,25 +1167,36 @@ void *init_9pfront(unsigned int id, const char *mnt)
         {
             reason = "backend published illegal version string";
             free(version);
-            goto err;
+            return issue_err(dev, msg, reason);
         }
     }
     free(version);
     if ( v )
     {
         reason = "backend doesn't support version 1";
-        goto err;
+        return issue_err(dev, msg, reason);
     }
 
-    dev->ring_ref = gnttab_alloc_and_grant((void **)&dev->intf);
+    dev->intf = (void *)alloc_page();
+    if ( !dev->intf )
+    {
+        reason = "couldn't allocate shared interface page";
+        return issue_err(dev, msg, reason);
+    }
     memset(dev->intf, 0, PAGE_SIZE);
+    dev->ring_ref = gnttab_grant_access(dev->dom, virt_to_mfn(dev->intf), 0);
     if ( evtchn_alloc_unbound(dev->dom, intr_9pfs, dev, &dev->evtchn) )
     {
         reason = "no event channel";
-        goto err;
+        return issue_err(dev, msg, reason);
     }
     dev->intf->ring_order = dev->ring_order;
     dev->data.in = (void *)alloc_pages(dev->ring_order);
+    if ( !dev->data.in )
+    {
+        reason = "couldn't allocate ring pages";
+        return issue_err(dev, msg, reason);
+    }
     dev->data.out = dev->data.in + XEN_FLEX_RING_SIZE(dev->ring_order);
     for ( i = 0; i < (1 << dev->ring_order); i++ )
     {
@@ -1204,30 +1212,35 @@ void *init_9pfront(unsigned int id, const char *mnt)
             free(msg);
             msg = NULL;
             reason = "starting transaction";
-            goto err;
+            return issue_err(dev, msg, reason);
         }
 
         msg = xenbus_printf(xbt, dev->nodename, "version", "%u", 1);
         if ( msg )
-            goto err_tr;
+            break;
         msg = xenbus_printf(xbt, dev->nodename, "num-rings", "%u", 1);
         if ( msg )
-            goto err_tr;
+            break;
         msg = xenbus_printf(xbt, dev->nodename, "ring-ref0", "%u",
                             dev->ring_ref);
         if ( msg )
-            goto err_tr;
+            break;
         msg = xenbus_printf(xbt, dev->nodename, "event-channel-0", "%u",
                             dev->evtchn);
         if ( msg )
-            goto err_tr;
+            break;
         msg = xenbus_printf(xbt, dev->nodename, "state", "%u",
                             XenbusStateInitialised);
         if ( msg )
-            goto err_tr;
+            break;
 
         free(xenbus_transaction_end(xbt, 0, &retry));
     }
+    if ( msg )
+    {
+        free(xenbus_transaction_end(xbt, 1, &retry));
+        return issue_err(dev, msg, reason);
+    }
 
     state = xenbus_read_integer(dev->bepath);
     while ( msg == NULL && state < XenbusStateConnected )
@@ -1235,13 +1248,42 @@ void *init_9pfront(unsigned int id, const char *mnt)
     if ( msg || state != XenbusStateConnected )
     {
         reason = "illegal backend state";
-        goto err;
+        return issue_err(dev, msg, reason);
     }
 
     msg = xenbus_printf(XBT_NIL, dev->nodename, "state", "%u",
                         XenbusStateConnected);
     if ( msg )
-        goto err;
+        return issue_err(dev, msg, reason);
+
+    return true;
+}
+
+void *init_9pfront(unsigned int id, const char *mnt)
+{
+    struct dev_9pfs *dev;
+    char *reason = "";
+    unsigned int i;
+
+    printk("9pfsfront add %u, for mount at %s\n", id, mnt);
+    dev = malloc(sizeof(*dev));
+    memset(dev, 0, sizeof(*dev));
+    snprintf(dev->nodename, sizeof(dev->nodename), "device/9pfs/%u", id);
+    dev->id = id;
+    init_waitqueue_head(&dev->waitq);
+    init_SEMAPHORE(&dev->ring_out_sem, 1);
+    init_SEMAPHORE(&dev->ring_in_sem, 1);
+    dev->fid_mask = ~0ULL;
+
+    for ( i = 0; i < N_REQS; i++ )
+    {
+        dev->req[i].id = i;
+        dev->req[i].next_free = i + 1;
+    }
+    dev->free_reqs = 0;
+
+    if ( !read_config_xs(dev) )
+        goto err_out;
 
     unmask_evtchn(dev->evtchn);
 
@@ -1260,17 +1302,11 @@ void *init_9pfront(unsigned int id, const char *mnt)
 
     return dev;
 
- err_tr:
-    free(xenbus_transaction_end(xbt, 1, &retry));
-
  err:
-    if ( msg )
-        printk("9pfsfront add %u failed, error %s accessing Xenstore\n",
-               id, msg);
-    else
-        printk("9pfsfront add %u failed, %s\n", id, reason);
+    printk("9pfsfront add %u failed, %s\n", id, reason);
+
+ err_out:
     free_9pfront(dev);
-    free(msg);
     return NULL;
 }
 EXPORT_SYMBOL(init_9pfront);
Signature · 1 line
2.43.0
Reviewed-by on v1 15/19
#37 lore raw

Re: [MINI-OS PATCH 15/19] 9pfs: refactor init_9pfront()

Quoted 5 lines · Juergen Gross

Move the Xenstore and backend interface related handling into a sub-function in order to prepare supporting reconnecting to an active 9pfs device after kexec.

This includes the replacement of gnttab_alloc_and_grant() which should at least be mentioned in the commit message. With that:

#38 lore raw

PATCH 16/19 gnttab: remove gnttab_alloc_and_grant() function

In reply to Juergen Gross

The last user of gnttab_alloc_and_grant() is gone.

Remove gnttab_alloc_and_grant() as it is doing more harm than good. It is hard coded to only grant access for dom0, which is not really clear from looking at the function name. It would be possible to add a domid parameter, but given its now 0 users, there doesn't seem to be a real demand for that function.

---
 gnttab.c         | 13 -------------
 include/gnttab.h |  1 -
 2 files changed, 14 deletions(-)
gnttab.c +0 -13
index 5b04ab01..6bac0905 100644
@@ -149,19 +149,6 @@ gnttab_end_transfer(grant_ref_t ref)
 }
 EXPORT_SYMBOL(gnttab_end_transfer);
 
-grant_ref_t
-gnttab_alloc_and_grant(void **map)
-{
-    unsigned long mfn;
-    grant_ref_t gref;
-
-    *map = (void *)alloc_page();
-    mfn = virt_to_mfn(*map);
-    gref = gnttab_grant_access(0, mfn, 0);
-    return gref;
-}
-EXPORT_SYMBOL(gnttab_alloc_and_grant);
-
 static const char * const gnttabop_error_msgs[] = GNTTABOP_error_msgs;
 
 const char *
include/gnttab.h +0 -1
index 974cb89d..108c4425 100644
@@ -4,7 +4,6 @@
 #include <xen/grant_table.h>
 
 void init_gnttab(void);
-grant_ref_t gnttab_alloc_and_grant(void **map);
 grant_ref_t gnttab_grant_access(domid_t domid, unsigned long frame,
 				int readonly);
 grant_ref_t gnttab_grant_transfer(domid_t domid, unsigned long pfn);
Signature · 1 line
2.43.0
Reviewed-by on v1 16/19
#39 lore raw

Re: [MINI-OS PATCH 16/19] gnttab: remove gnttab_alloc_and_grant() function

Quoted 9 lines · Juergen Gross

The last user of gnttab_alloc_and_grant() is gone.

Remove gnttab_alloc_and_grant() as it is doing more harm than good. It is hard coded to only grant access for dom0, which is not really clear from looking at the function name. It would be possible to add a domid parameter, but given its now 0 users, there doesn't seem to be a real demand for that function.

#40 lore raw

PATCH 17/19 gnttab: add function to obtain memory address from grantref

In reply to Juergen Gross

Add a new function gnttab_get_addr() to obtain a memory pointer for a given grant reference.

---
 gnttab.c         | 10 ++++++++++
 include/gnttab.h |  1 +
 2 files changed, 11 insertions(+)
gnttab.c +10 -0
index 6bac0905..52d6792a 100644
@@ -149,6 +149,16 @@ gnttab_end_transfer(grant_ref_t ref)
 }
 EXPORT_SYMBOL(gnttab_end_transfer);
 
+void *gnttab_get_addr(grant_ref_t ref)
+{
+    BUG_ON(ref >= NR_GRANT_ENTRIES || ref < NR_RESERVED_ENTRIES);
+
+    if ( !gnttab_table[ref].flags )
+        return NULL;
+
+    return mfn_to_virt(gnttab_table[ref].frame);
+}
+
 static const char * const gnttabop_error_msgs[] = GNTTABOP_error_msgs;
 
 const char *
include/gnttab.h +1 -0
index 108c4425..46e72a36 100644
@@ -9,6 +9,7 @@ grant_ref_t gnttab_grant_access(domid_t domid, unsigned long frame,
 grant_ref_t gnttab_grant_transfer(domid_t domid, unsigned long pfn);
 unsigned long gnttab_end_transfer(grant_ref_t gref);
 int gnttab_end_access(grant_ref_t ref);
+void *gnttab_get_addr(grant_ref_t ref);
 const char *gnttabop_error(int16_t status);
 void fini_gnttab(void);
 void suspend_gnttab(void);
Signature · 1 line
2.43.0
Reviewed-by on v1 17/19
#41 lore raw

Re: [MINI-OS PATCH 17/19] gnttab: add function to obtain memory address from grantref

Quoted 4 lines · Juergen Gross

Add a new function gnttab_get_addr() to obtain a memory pointer for a given grant reference.

Maybe you want to name it gnttab_get_vaddr() to be a little more explicit in its return value? Either way:

#42 lore raw

Re: [MINI-OS PATCH 17/19] gnttab: add function to obtain memory address from grantref

Quoted 7 lines · Jason Andryuk
Quoted 4 lines · Juergen Gross

Add a new function gnttab_get_addr() to obtain a memory pointer for a given grant reference.

Maybe you want to name it gnttab_get_vaddr() to be a little more explicit in its return value?

I think this isn't necessary. In case a physical address would be handed back I'd agree to add 'p' for qualifying the address, but I don't think we need to qualify virtual addresses as such.

Juergen

#43 lore raw

PATCH 18/19 9pfs: add support to keep device opened across kexec

In reply to Juergen Gross

In order to support Xenstore-stubdom live update, the 9pfs device used to save and restore the Xenstore state needs to be kept open across kexec, as otherwise re-opening of the device using the new kernel would not work (this would require Xenstore to be active, which is obviously not possible before having read the saved state).

Add an alternative init function for a 9pfs device supporting to take the configuration from the kexec module instead of Xenstore. Add support for creating the device using the kexec module, too.

---
 9pfront.c         | 120 +++++++++++++++++++++++++++++++++++++++++-----
 include/9pfront.h |   9 ++++
 include/kexec.h   |   1 +
 3 files changed, 117 insertions(+), 13 deletions(-)
9pfront.c +107 -13
index 8da2f726..b3106d13 100644
@@ -8,6 +8,7 @@
 #include <mini-os/events.h>
 #include <mini-os/fcntl.h>
 #include <mini-os/gnttab.h>
+#include <mini-os/kexec.h>
 #include <mini-os/semaphore.h>
 #include <mini-os/wait.h>
 #include <mini-os/xenbus.h>
@@ -26,6 +27,7 @@ struct dev_9pfs {
     unsigned int dom;
     char *backend;
     char bepath[64];
+    bool kexecmem;
 
     char *tag;
     const char *mnt;
@@ -58,6 +60,13 @@ struct dev_9pfs {
     unsigned long long fid_mask;              /* Bit mask for free fids. */
 };
 
+struct kexec_9pfs_rec {
+    grant_ref_t ring_ref;
+    evtchn_port_t evtchn;
+    RING_IDX prod_pvt_out;
+    RING_IDX cons_pvt_in;
+};
+
 struct file_9pfs {
     uint32_t fid;
     struct dev_9pfs *dev;
@@ -898,7 +907,7 @@ static bool path_canonical(const char *pathname)
     return true;
 }
 
-static int connect_9pfs(struct dev_9pfs *dev)
+static int connect_9pfs(struct dev_9pfs *dev, bool do_attach)
 {
     int ret;
 
@@ -906,7 +915,7 @@ static int connect_9pfs(struct dev_9pfs *dev)
     if ( ret )
         return ret;
 
-    return p9_attach(dev);
+    return do_attach ? p9_attach(dev) : 0;
 }
 
 static void intr_9pfs(evtchn_port_t port, struct pt_regs *regs, void *data)
@@ -1079,6 +1088,9 @@ static int open_9pfs(struct mount_point *mnt, const char *pathname, int flags,
     return -1;
 }
 
+static int kexec_recid = -1;
+static struct dev_9pfs *kexec_dev;
+
 static void free_9pfront(struct dev_9pfs *dev)
 {
     unsigned int i;
@@ -1087,13 +1099,22 @@ static void free_9pfront(struct dev_9pfs *dev)
     {
         for ( i = 0; i < (1 << dev->ring_order); i++ )
             gnttab_end_access(dev->intf->ref[i]);
-        free_pages(dev->data.in, dev->ring_order);
+        if ( dev->kexecmem )
+            kexec_free_mod_pages(kexec_recid, (unsigned long)dev->data.in,
+                                 1 << dev->ring_order);
+        else
+            free_pages(dev->data.in, dev->ring_order);
     }
     unbind_evtchn(dev->evtchn);
     gnttab_end_access(dev->ring_ref);
-    free_page(dev->intf);
+    if ( dev->kexecmem )
+        kexec_free_mod_pages(kexec_recid, (unsigned long)dev->intf, 1);
+    else
+        free_page(dev->intf);
     free(dev->backend);
     free(dev->tag);
+    if ( dev == kexec_dev )
+        kexec_dev = NULL;
     free(dev);
 }
 
@@ -1111,7 +1132,7 @@ static bool issue_err(struct dev_9pfs *dev, char *msg, char *reason)
     return false;
 }
 
-static bool read_config_xs(struct dev_9pfs *dev)
+static bool read_config_xs(struct dev_9pfs *dev, struct kexec_9pfs_rec *rec)
 {
     char *msg;
     char *reason = "";
@@ -1121,7 +1142,9 @@ static bool read_config_xs(struct dev_9pfs *dev)
     char *v;
     void *addr;
     unsigned int i;
+    unsigned int n_pages;
     int retry = 1;
+    int err;
 
     msg = xenbus_read_unsigned(XBT_NIL, dev->nodename, "backend-id", &dev->dom);
     if ( msg )
@@ -1177,7 +1200,9 @@ static bool read_config_xs(struct dev_9pfs *dev)
         return issue_err(dev, msg, reason);
     }
 
-    dev->intf = (void *)alloc_page();
+    dev->intf = (void *)(dev->kexecmem
+                         ? kexec_alloc_mod_pages(kexec_recid, 1)
+                         : alloc_page());
     if ( !dev->intf )
     {
         reason = "couldn't allocate shared interface page";
@@ -1191,14 +1216,17 @@ static bool read_config_xs(struct dev_9pfs *dev)
         return issue_err(dev, msg, reason);
     }
     dev->intf->ring_order = dev->ring_order;
-    dev->data.in = (void *)alloc_pages(dev->ring_order);
+    n_pages = 1 << dev->ring_order;
+    dev->data.in = (void *)(dev->kexecmem
+                            ? kexec_alloc_mod_pages(kexec_recid, n_pages)
+                            : alloc_pages(dev->ring_order));
     if ( !dev->data.in )
     {
         reason = "couldn't allocate ring pages";
         return issue_err(dev, msg, reason);
     }
     dev->data.out = dev->data.in + XEN_FLEX_RING_SIZE(dev->ring_order);
-    for ( i = 0; i < (1 << dev->ring_order); i++ )
+    for ( i = 0; i < n_pages; i++ )
     {
         addr = dev->data.in + i * PAGE_SIZE;
         dev->intf->ref[i] = gnttab_grant_access(dev->dom, virt_to_mfn(addr), 0);
@@ -1256,18 +1284,65 @@ static bool read_config_xs(struct dev_9pfs *dev)
     if ( msg )
         return issue_err(dev, msg, reason);
 
+    if ( dev->kexecmem )
+    {
+        rec->ring_ref = dev->ring_ref;
+        rec->evtchn = dev->evtchn;
+        err = kexec_upd_mod_record(kexec_recid, KEXECMOD_REC_9PFS, rec,
+                                   sizeof(*rec));
+        BUG_ON(err);
+    }
+
     return true;
 }
 
-void *init_9pfront(unsigned int id, const char *mnt)
+#ifdef CONFIG_KEXEC
+static int kexec_9pfront(bool undo)
+{
+    struct kexec_9pfs_rec rec;
+
+    if ( kexec_recid < 0 || !kexec_dev || undo )
+        return 0;
+
+    kexec_read_mod_record(kexec_recid, &rec, sizeof(rec));
+    rec.prod_pvt_out = kexec_dev->prod_pvt_out;
+    rec.cons_pvt_in = kexec_dev->cons_pvt_in;
+    kexec_upd_mod_record(kexec_recid, KEXECMOD_REC_9PFS, &rec, sizeof(rec));
+
+    return 0;
+}
+kexec_call(kexec_9pfront);
+#endif
+
+static void read_config_kexec(struct dev_9pfs *dev, struct kexec_9pfs_rec *rec)
+{
+    dev->ring_ref = rec->ring_ref;
+    dev->evtchn = rec->evtchn;
+    dev->prod_pvt_out = rec->prod_pvt_out;
+    dev->cons_pvt_in = rec->cons_pvt_in;
+
+    dev->intf = gnttab_get_addr(dev->ring_ref);
+    dev->ring_order = dev->intf->ring_order;
+    dev->data.in = gnttab_get_addr(dev->intf->ref[0]);
+    dev->data.out = dev->data.in + XEN_FLEX_RING_SIZE(dev->ring_order);
+
+    bind_evtchn(dev->evtchn, intr_9pfs, dev);
+}
+
+void *init_9pfront2(unsigned int id, const char *mnt, unsigned int flags)
 {
     struct dev_9pfs *dev;
     char *reason = "";
     unsigned int i;
+    struct kexec_9pfs_rec record = { };
+    unsigned int rec_size;
 
-    printk("9pfsfront add %u, for mount at %s\n", id, mnt);
+    printk("9pfsfront add %u, for mount at %s, flags %x\n", id, mnt, flags);
     dev = malloc(sizeof(*dev));
     memset(dev, 0, sizeof(*dev));
+    dev->kexecmem = flags & (INIT9P_FLAG_KEXEC | INIT9P_FLAG_REINIT);
+    if ( dev->kexecmem )
+        kexec_dev = dev;
     snprintf(dev->nodename, sizeof(dev->nodename), "device/9pfs/%u", id);
     dev->id = id;
     init_waitqueue_head(&dev->waitq);
@@ -1282,12 +1357,25 @@ void *init_9pfront(unsigned int id, const char *mnt)
     }
     dev->free_reqs = 0;
 
-    if ( !read_config_xs(dev) )
-        goto err_out;
+    if ( !(flags & INIT9P_FLAG_REINIT) )
+    {
+        if ( dev->kexecmem )
+            kexec_recid = kexec_add_mod_record(KEXECMOD_REC_9PFS, &record,
+                                               sizeof(record));
+        if ( !read_config_xs(dev, &record) )
+            goto err_out;
+    }
+    else
+    {
+        kexec_recid = kexec_find_mod_record(0, KEXECMOD_REC_9PFS, &rec_size);
+        BUG_ON(kexec_recid < 0 || rec_size != sizeof(record));
+        kexec_read_mod_record(kexec_recid, &record, rec_size);
+        read_config_kexec(dev, &record);
+    }
 
     unmask_evtchn(dev->evtchn);
 
-    if ( connect_9pfs(dev) )
+    if ( connect_9pfs(dev, !(flags & INIT9P_FLAG_REINIT)) )
     {
         reason = "9pfs connect failed";
         goto err;
@@ -1309,6 +1397,12 @@ void *init_9pfront(unsigned int id, const char *mnt)
     free_9pfront(dev);
     return NULL;
 }
+EXPORT_SYMBOL(init_9pfront2);
+
+void *init_9pfront(unsigned int id, const char *mnt)
+{
+    return init_9pfront2(id, mnt, 0);
+}
 EXPORT_SYMBOL(init_9pfront);
 
 void shutdown_9pfront(void *dev)
include/9pfront.h +9 -0
index 722ec564..a0cb5487 100644
@@ -2,6 +2,15 @@
 #define __9PFRONT_H__
 
 void *init_9pfront(unsigned int id, const char *mnt);
+void *init_9pfront2(unsigned int id, const char *mnt, unsigned int flags);
+#ifdef CONFIG_KEXEC
+#define INIT9P_FLAG_REINIT 0x01      /* Reinit with data from kexec module. */
+#define INIT9P_FLAG_KEXEC  0x02      /* Use kexec module for interface. */
+#else
+#define INIT9P_FLAG_REINIT 0
+#define INIT9P_FLAG_KEXEC  0
+#endif
+
 void shutdown_9pfront(void *dev);
 
 #endif /* __9PFRONT_H__ */
include/kexec.h +1 -0
index 1e753ee1..b358b202 100644
@@ -34,6 +34,7 @@ struct kexec_module_rec {
     uint16_t offset;        /* Offset to record from start of page.          */
     uint8_t type;           /* Type of record.                               */
 #define KEXECMOD_REC_NONE   0
+#define KEXECMOD_REC_9PFS   1
     uint8_t size;           /* Size of record.                               */
 };
 
Signature · 1 line
2.43.0
Reviewed-by on v1 18/19
#44 lore raw

Re: [MINI-OS PATCH 18/19] 9pfs: add support to keep device opened across kexec

Quoted 11 lines · Juergen Gross

In order to support Xenstore-stubdom live update, the 9pfs device used to save and restore the Xenstore state needs to be kept open across kexec, as otherwise re-opening of the device using the new kernel would not work (this would require Xenstore to be active, which is obviously not possible before having read the saved state).

Add an alternative init function for a 9pfs device supporting to take the configuration from the kexec module instead of Xenstore. Add support for creating the device using the kexec module, too.

#45 lore raw

PATCH 19/19 events: export bind_evtchn()

In reply to Juergen Gross

Export the bind_evtchn() function, as it will be needed for reactivating events after kexec().

---
 events.c | 1 +
 1 file changed, 1 insertion(+)
events.c +1 -0
index 9f3dbf05..a9c1ccac 100644
@@ -98,6 +98,7 @@ evtchn_port_t bind_evtchn(evtchn_port_t port, evtchn_handler_t handler,
 
 	return port;
 }
+EXPORT_SYMBOL(bind_evtchn);
 
 void unbind_evtchn(evtchn_port_t port )
 {
Signature · 1 line
2.43.0