Make Xenstore-stubdom live update possible
v2 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.
Changes in V2:
- patches 1-5 of V1 have been applied already
- addressed the (minor) comments to V1
Juergen Gross (14):
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 | 123 +++++++++++++++++-- arch/x86/mm.c | 95 +++++++++++++++ arch/x86/setup.c | 28 +++++ e820.c | 11 +- events.c | 1 + gnttab.c | 15 +-- include/9pfront.h | 9 ++ include/e820.h | 2 + include/gnttab.h | 2 +- include/kernel.h | 1 + include/kexec.h | 122 +++++++++++++++++++ include/mm.h | 1 + include/x86/arch_mm.h | 1 + kexec.c | 118 +++++++++++++++++++ mm.c | 27 ++++- 17 files changed, 733 insertions(+), 96 deletions(-)
Signature · 1 line
2.43.0
PATCH v2 1/14 mm: don't add module pages to free memory
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.
---
V2:
- call pvh_reserve_start_info() from arch_mm_preinit() (Jason Andryuk)
--- arch/x86/mm.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/mm.h | 1 + mm.c | 21 +++++++++++++- 3 files changed, 98 insertions(+), 1 deletion(-)
arch/x86/mm.c +77 -0
@@ -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] =
@@ -108,6 +112,42 @@ desc_ptr idt_ptr = .base = (unsigned long)&idt, }; +#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; +} +void arch_mm_preinit (void *p) {unsigned int pages;
@@ -124,6 +164,43 @@ void arch_mm_preinit(void *p) pages =e820_get_current_pages (); last_free_pfn =e820_get_maxpfn (pages);balloon_set_nr_pages (pages, last_free_pfn); +pvh_reserve_start_info (&first_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); }#endif
include/mm.h +1 -0
@@ -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
@@ -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
Re: [MINI-OS PATCH v2 01/14] mm: don't add module pages to free memory
Quoted 8 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_infopages are below the page tables.Signed-off-by Juergen Gross <[email protected]>
PATCH v2 2/14 kexec: fix physical addresses in start info data
In reply to Juergen GrossThe 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. Additionally rename kexec_param_loc to kexec_param_pa to better reflect the semantics of the variable.
---
V2:
- rename kexec_param_loc to kexec_param_pa (Jason Andryuk)
--- arch/x86/kexec.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
arch/x86/kexec.c +6 -6
@@ -197,7 +197,7 @@ bool kexec_arch_need_analyze_shdrs(void)return kernel_phys_entry == ~0UL ; } -static unsigned long kexec_param_loc; +static unsigned long kexec_param_pa;static unsigned int kexec_param_size;static unsigned long kexec_param_mem;
@@ -208,7 +208,7 @@ void kexec_set_param_loc(const char *cmdline) kexec_param_size +=strlen (cmdline) +1 ; kexec_last_addr = (kexec_last_addr +7 ) & ~7UL ; - kexec_param_loc = kexec_last_addr; + kexec_param_pa = kexec_last_addr; kexec_last_addr += kexec_param_size; kexec_last_addr =round_pgup (kexec_last_addr); }
@@ -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_pa +sizeof (*info) + e820_entries *sizeof (struct hvm_memmap_table_entry ); - info->memmap_paddr = kexec_param_mem +sizeof (*info); + info->memmap_paddr = kexec_param_pa +sizeof (*info); info->memmap_entries = e820_entries; mmap = (struct hvm_memmap_table_entry *)(info +1 );
@@ -249,13 +249,13 @@ int kexec_get_entry(const char *cmdline)strcpy ((char *)mmap, cmdline); -if (kexec_add_action (KEXEC_COPY ,to_virt (kexec_param_loc), info, +if (kexec_add_action (KEXEC_COPY ,to_virt (kexec_param_pa), info, kexec_param_size) )return ENOSPC ;/* The call of the new kernel happens via the physical address! */ if (kexec_add_action (KEXEC_CALL , (void *)kernel_phys_entry, - (void *)kexec_param_loc,0 ) ) + (void *)kexec_param_pa,0 ) )return ENOSPC ;return 0 ;
Signature · 1 line
2.43.0
PATCH v2 3/14 e820: don't count lapic page as initially reserved
In reply to Juergen GrossThe 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.
--- e820.c | 3 +++ 1 file changed, 3 insertions(+)
e820.c +3 -0
@@ -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
PATCH v2 4/14 kexec: restructure building the start info data
In reply to Juergen GrossInstead 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
@@ -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_pa +sizeof (*info) + - e820_entries *sizeof (struct hvm_memmap_table_entry ); - info->memmap_paddr = kexec_param_pa +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_pa + (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_pa + (unsigned long )next - kexec_param_mem; +strcpy (next, cmdline);if (kexec_add_action (KEXEC_COPY ,to_virt (kexec_param_pa), info, kexec_param_size) )
Signature · 1 line
2.43.0
PATCH v2 5/14 e820: use special type for software reserved memory
In reply to Juergen GrossFor 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
@@ -240,14 +240,16 @@ int kexec_get_entry(const char *cmdline) mmap = next; info->memmap_paddr = kexec_param_pa + (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_pa + (unsigned long )next - kexec_param_mem;
e820.c +4 -4
@@ -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 =round_pgup (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
@@ -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 0xefffffffstruct __packed e820entry {uint64_t addr;
Signature · 1 line
2.43.0
PATCH v2 6/14 mini-os: config: add support for config items with numerical values
In reply to Juergen GrossAdd 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
@@ -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
PATCH v2 7/14 mini-os: kexec: add support for handing over some memory across kexec
In reply to Juergen GrossEspecially 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.
---
V2:
- set kexec_mod_start in kexec_check_module()
- remove fallback definition of CONFIG_KEXEC_MODULE_PAGES (Jan Beulich)
- fix mod_ptr->recs_off alignment (Jason Andryuk)
- expand comment at start of kexec.h (Jason Andryuk)
--- Config.mk | 2 ++ arch/x86/kexec.c | 79 +++++++++++++++++++++++++++++++++++++++++++ arch/x86/mm.c | 18 ++++++++++ arch/x86/setup.c | 28 +++++++++++++++ include/kernel.h | 1 + include/kexec.h | 69 +++++++++++++++++++++++++++++++++++++ include/x86/arch_mm.h | 1 + kexec.c | 3 ++ mm.c | 6 ++++ 9 files changed, 207 insertions(+)
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 + $(foreach i,$(CONFIG-val-y),$(eval $(i) ?= 0)) CONFIG-x += CONFIG_LIBXS
arch/x86/kexec.c +79 -0
101 lines not on this page · raw message
arch/x86/mm.c +18 -0
@@ -188,6 +188,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
@@ -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
@@ -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 +69 -0
79 lines not on this page · raw message
include/x86/arch_mm.h +1 -0
@@ -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
@@ -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
@@ -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
Re: [MINI-OS PATCH v2 07/14] mini-os: kexec: add support for handing over some memory across kexec
Quoted 13 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.
Quoted 4 lines
The contents of the memory area are described via a generic table of contents in the last page of the memory.
Signed-off-by Juergen Gross <[email protected]>
Thanks for the expanded comment.
Regards,
Jason
PATCH v2 8/14 kexec: add support for allocating pages from kexec module memory
In reply to Juergen GrossAdd 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
@@ -240,6 +240,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 )
@@ -257,11 +260,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 ) + mod_ptr->n_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
PATCH v2 9/14 9pfs: store bepath in struct struct dev_9pfs
In reply to Juergen GrossUse 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
@@ -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
PATCH v2 10/14 9pfs: refactor init_9pfront()
In reply to Juergen GrossMove the Xenstore and backend interface related handling into a sub-function in order to prepare supporting reconnecting to an active 9pfs device after kexec.
Don't use gnttab_alloc_and_grant(), as this will hard code to use dom0 as backend.
--- 9pfront.c | 136 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 86 insertions(+), 50 deletions(-)
9pfront.c +86 -50
@@ -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
PATCH v2 11/14 gnttab: remove gnttab_alloc_and_grant() function
In reply to Juergen GrossThe 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
@@ -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
@@ -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
PATCH v2 12/14 gnttab: add function to obtain memory address from grantref
In reply to Juergen GrossAdd 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
@@ -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
@@ -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
PATCH v2 13/14 9pfs: add support to keep device opened across kexec
In reply to Juergen GrossIn 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
@@ -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
@@ -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
@@ -62,6 +62,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 1uint8_t size;/* Size of record. */ };
Signature · 1 line
2.43.0
PATCH v2 14/14 events: export bind_evtchn()
In reply to Juergen GrossExport 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
@@ -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