grub-xen: support booting huge pv-domains
Juergen Gross
maintainerv5 cover grub-xen: support booting huge pv-domains
The Xen hypervisor supports starting a dom0 with large memory (up to the TB range) by not including the initrd and p2m list in the initial kernel mapping. Especially the p2m list can grow larger than the available virtual space in the initial mapping.
The started kernel is indicating the support of each feature via elf notes.
This series enables grub-xen to do the same as the hypervisor.
Tested with:
- 32 bit domU (kernel not supporting unmapped initrd)
- 32 bit domU (kernel supporting unmapped initrd)
- 1 GB 64 bit domU (kernel supporting unmapped initrd, not p2m)
- 1 GB 64 bit domU (kernel supporting unmapped initrd and p2m)
- 900GB 64 bit domU (kernel supporting unmapped initrd and p2m)
Changes in V5:
- patch 2: set grub_errno to GRUB_ERR_NONE to avoid false error reports as requested by Daniel Kiper
- patch 9: let call grub_xen_alloc_final() all subfunctions unconditionally and let them decide whether they need to do anything as suggested by Daniel Kiper
Changes in V4:
- split patch 1 into two patches as requested by Daniel Kiper
- patch 9 (was 8): rename grub_xen_alloc_end() as requested by Daniel Kiper
- patch 10 (was 9): align variables in assembly sources,
use separate structure define as requested by Daniel Kiper
Changes in V3:
- added new patch 1 (free memory in case of error) as requested by Daniel Kiper
- added new patch 2 (avoid global variables) as requested by Daniel Kiper
- added new patch 3 (use constants for elf notes) as requested by Daniel Kiper
- added new patch 4 (sync with new Xen headers) in order to use constants in assembly code
- modified patch 9 (was patch 5) to use constants instead of numbers as requested by Daniel Kiper
Changes in V2:
- rebased patch 5 to current master
Juergen Gross (11):
xen: make xen loader callable multiple times
xen: avoid memleaks on error
xen: reduce number of global variables in xen loader
xen: add elfnote.h to avoid using numbers instead of constants
xen: synchronize xen header
xen: factor out p2m list allocation into separate function
xen: factor out allocation of special pages into separate function
xen: factor out allocation of page tables into separate function
xen: add capability to load initrd outside of initial mapping
xen: modify page table construction
xen: add capability to load p2m list outside of kernel mapping
grub-core/lib/i386/xen/relocator.S | 88 ++-- grub-core/lib/x86_64/xen/relocator.S | 135 +++--- grub-core/lib/xen/relocator.c | 28 +- grub-core/loader/i386/xen.c | 781 +++++++++++++++++++++++------------ grub-core/loader/i386/xen_fileXX.c | 45 +- include/grub/i386/memory.h | 7 + include/grub/xen/relocator.h | 6 +- include/grub/xen_file.h | 3 + include/xen/arch-x86/xen-x86_32.h | 22 +- include/xen/arch-x86/xen-x86_64.h | 8 +- include/xen/elfnote.h | 281 +++++++++++++ include/xen/xen.h | 125 ++++-- 12 files changed, 1080 insertions(+), 449 deletions(-) create mode 100644 include/xen/elfnote.h
Signature · 1 line
2.6.2
Juergen Gross
maintainerPATCH v5 1/11 xen: make xen loader callable multiple times
The loader for xen paravirtualized environment isn't callable multiple times as it won't free any memory in case of failure.
Call grub_relocator_unload() as other modules do it before allocating a new relocator or when unloading the module.
---
V4: split patch into two patches
add comment
--- grub-core/loader/i386/xen.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-)
grub-core/loader/i386/xen.c +19 -8
@@ -316,11 +316,23 @@ grub_xen_boot (void) xen_inf.virt_base); } +static void +grub_xen_reset (void ) +{ +grub_memset (&next_start,0 ,sizeof (next_start)); + xen_module_info_page =NULL ; + n_modules =0 ; + +grub_relocator_unload (relocator); + relocator =NULL ; + loaded =0 ; +} +static grub_err_t grub_xen_unload (void ) { +grub_xen_reset ();grub_dl_unref (my_mod); - loaded =0 ;return GRUB_ERR_NONE ; }
@@ -403,10 +415,7 @@ grub_cmd_xen (grub_command_t cmd __attribute__ ((unused)),grub_loader_unset (); -grub_memset (&next_start,0 ,sizeof (next_start)); - - xen_module_info_page =NULL ; - n_modules =0 ; +grub_xen_reset (); grub_create_loader_cmdline (argc - 1, argv + 1, (char *) next_start.cmd_line,
@@ -503,16 +512,18 @@ grub_cmd_xen (grub_command_t cmd __attribute__ ((unused)), goto fail; fail: +/* grub_errno might be clobbered by further calls, save the error reason. */ + err = grub_errno;if (elf)grub_elf_close (elf);else if (file)grub_file_close (file); -if (grub_errno !=GRUB_ERR_NONE ) - loaded =0 ; +if (err !=GRUB_ERR_NONE ) +grub_xen_reset (); -return grub_errno; +return err; } static grub_err_t
Signature · 7 lines
2.6.2 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Juergen Gross
maintainerPATCH v5 2/11 xen: avoid memleaks on error
In reply to Juergen GrossWhen loading a Xen pv-kernel avoid memory leaks in case of errors.
---
V5: set grub_errno to GRUB_ERR_NONE to avoid false error reports as requested
by Daniel Kiper
--- grub-core/loader/i386/xen.c | 2 +- grub-core/loader/i386/xen_fileXX.c | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-)
grub-core/loader/i386/xen.c +1 -1
@@ -563,7 +563,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), { err =grub_relocator_alloc_chunk_addr (relocator, &ch, max_addr, size);if (err) -return err; + goto fail;if (grub_initrd_load (&initrd_ctx, argv,get_virtual_current_address (ch)))
grub-core/loader/i386/xen_fileXX.c +13 -6
@@ -26,6 +26,8 @@ parse_xen_guest (grub_elf_t elf, struct grub_xen_file_info *xi,char *buf;char *ptr;int has_paddr =0 ; + + grub_errno =GRUB_ERR_NONE ;if (grub_file_seek (elf->file, off) == (grub_off_t) -1 )return grub_errno; buf =grub_malloc (sz);
@@ -35,7 +37,8 @@ parse_xen_guest (grub_elf_t elf, struct grub_xen_file_info *xi,if (grub_file_read (elf->file, buf, sz) != (grub_ssize_t ) sz) {if (grub_errno) -return grub_errno; + goto out; +grub_free (buf);return grub_error (GRUB_ERR_BAD_OS ,N_ ("premature end of file %s" ), elf->file->name); }
@@ -123,14 +126,14 @@ parse_xen_guest (grub_elf_t elf, struct grub_xen_file_info *xi, { xi->virt_base =grub_strtoull (ptr +sizeof ("VIRT_BASE=" ) -1 , &ptr,16 );if (grub_errno) -return grub_errno; + goto out;continue ; }if (grub_strncmp (ptr,"VIRT_ENTRY=" ,sizeof ("VIRT_ENTRY=" ) -1 ) ==0 ) { xi->entry_point =grub_strtoull (ptr +sizeof ("VIRT_ENTRY=" ) -1 , &ptr,16 );if (grub_errno) -return grub_errno; + goto out;continue ; }if (grub_strncmp (ptr,"HYPERCALL_PAGE=" ,sizeof ("HYPERCALL_PAGE=" ) -1 ) ==0 )
@@ -138,7 +141,7 @@ parse_xen_guest (grub_elf_t elf, struct grub_xen_file_info *xi, xi->hypercall_page =grub_strtoull (ptr +sizeof ("HYPERCALL_PAGE=" ) -1 , &ptr,16 ); xi->has_hypercall_page =1 ;if (grub_errno) -return grub_errno; + goto out;continue ; }if (grub_strncmp (ptr,"ELF_PADDR_OFFSET=" ,sizeof ("ELF_PADDR_OFFSET=" ) -1 ) ==0 )
@@ -146,7 +149,7 @@ parse_xen_guest (grub_elf_t elf, struct grub_xen_file_info *xi, xi->paddr_offset =grub_strtoull (ptr +sizeof ("ELF_PADDR_OFFSET=" ) -1 , &ptr,16 ); has_paddr =1 ;if (grub_errno) -return grub_errno; + goto out;continue ; } }
@@ -154,7 +157,11 @@ parse_xen_guest (grub_elf_t elf, struct grub_xen_file_info *xi, xi->hypercall_page = (xi->hypercall_page <<12 ) + xi->virt_base;if (!has_paddr) xi->paddr_offset = xi->virt_base; -return GRUB_ERR_NONE ; + +out: +grub_free (buf); + +return grub_errno; }#pragma GCC diagnostic ignored "-Wcast-align"
Signature · 7 lines
2.6.2 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v5 02/11] xen: avoid memleaks on error
Quoted 3 lines · Juergen Gross
When loading a Xen pv-kernel avoid memory leaks in case of errors.
Signed-off-by Juergen Gross <[email protected]>
Daniel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v5 02/11] xen: avoid memleaks on error
In reply to Juergen GrossQuoted 3 lines · Juergen Gross
When loading a Xen pv-kernel avoid memory leaks in case of errors.
Signed-off-by Juergen Gross <[email protected]>
Daniel
Juergen Gross
maintainerPATCH v5 3/11 xen: reduce number of global variables in xen loader
In reply to Juergen GrossThe loader for xen paravirtualized environment is using lots of global variables. Reduce the number by making them either local or by putting them into a single state structure.
--- grub-core/loader/i386/xen.c | 259 +++++++++++++++++++++++--------------------- 1 file changed, 138 insertions(+), 121 deletions(-)
grub-core/loader/i386/xen.c +138 -121
@@ -42,16 +42,20 @@GRUB_MOD_LICENSE ("GPLv3+" ); -static struct grub_relocator *relocator =NULL ; -static grub_uint64_t max_addr; +struct xen_loader_state { +struct grub_relocator *relocator; +struct start_info next_start; +struct grub_xen_file_info xen_inf; +grub_uint64_t max_addr; +struct xen_multiboot_mod_list *module_info_page; +grub_uint64_t modules_target_start; +grub_size_t n_modules; +int loaded; +}; + +static struct xen_loader_state xen_state; +static grub_dl_t my_mod; -static int loaded =0 ; -static struct start_info next_start; -static void *kern_chunk_src; -static struct grub_xen_file_info xen_inf; -static struct xen_multiboot_mod_list *xen_module_info_page; -static grub_uint64_t modules_target_start; -static grub_size_t n_modules;#define PAGE_SIZE 4096#define MAX_MODULES (PAGE_SIZE / sizeof (struct xen_multiboot_mod_list))
@@ -225,50 +229,55 @@ grub_xen_boot (void)if (grub_xen_n_allocated_shared_pages)return grub_error (GRUB_ERR_BUG ,"active grants" ); - state.mfn_list = max_addr; - next_start.mfn_list = max_addr + xen_inf.virt_base; - next_start.first_p2m_pfn = max_addr >>PAGE_SHIFT ;/* Is this right? */ + state.mfn_list = xen_state.max_addr; + xen_state.next_start.mfn_list = + xen_state.max_addr + xen_state.xen_inf.virt_base; + xen_state.next_start.first_p2m_pfn = xen_state.max_addr >>PAGE_SHIFT ; pgtsize =sizeof (grub_xen_mfn_t) * grub_xen_start_page_addr->nr_pages; - err =grub_relocator_alloc_chunk_addr (relocator, &ch, max_addr, pgtsize); - next_start.nr_p2m_frames = (pgtsize +PAGE_SIZE -1 ) >>PAGE_SHIFT ; + err =grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, + xen_state.max_addr, pgtsize); + xen_state.next_start.nr_p2m_frames = (pgtsize +PAGE_SIZE -1 ) >>PAGE_SHIFT ;if (err)return err; new_mfn_list =get_virtual_current_address (ch);grub_memcpy (new_mfn_list, (void *) grub_xen_start_page_addr->mfn_list, pgtsize); - max_addr =ALIGN_UP (max_addr + pgtsize,PAGE_SIZE ); + xen_state.max_addr =ALIGN_UP (xen_state.max_addr + pgtsize,PAGE_SIZE ); - err =grub_relocator_alloc_chunk_addr (relocator, &ch, - max_addr,sizeof (next_start)); + err =grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, + xen_state.max_addr, +sizeof (xen_state.next_start));if (err)return err; - state.start_info = max_addr + xen_inf.virt_base; + state.start_info = xen_state.max_addr + xen_state.xen_inf.virt_base; nst =get_virtual_current_address (ch); - max_addr =ALIGN_UP (max_addr +sizeof (next_start),PAGE_SIZE ); + xen_state.max_addr = +ALIGN_UP (xen_state.max_addr +sizeof (xen_state.next_start),PAGE_SIZE ); - next_start.nr_pages = grub_xen_start_page_addr->nr_pages; -grub_memcpy (next_start.magic, grub_xen_start_page_addr->magic, -sizeof (next_start.magic)); - next_start.store_mfn = grub_xen_start_page_addr->store_mfn; - next_start.store_evtchn = grub_xen_start_page_addr->store_evtchn; - next_start.console.domU = grub_xen_start_page_addr->console.domU; - next_start.shared_info = grub_xen_start_page_addr->shared_info; + xen_state.next_start.nr_pages = grub_xen_start_page_addr->nr_pages; +grub_memcpy (xen_state.next_start.magic, grub_xen_start_page_addr->magic, +sizeof (xen_state.next_start.magic)); + xen_state.next_start.store_mfn = grub_xen_start_page_addr->store_mfn; + xen_state.next_start.store_evtchn = grub_xen_start_page_addr->store_evtchn; + xen_state.next_start.console.domU = grub_xen_start_page_addr->console.domU; + xen_state.next_start.shared_info = grub_xen_start_page_addr->shared_info; - err =set_mfns (new_mfn_list, max_addr >>PAGE_SHIFT ); + err =set_mfns (new_mfn_list, xen_state.max_addr >>PAGE_SHIFT );if (err)return err; - max_addr +=2 *PAGE_SIZE ; + xen_state.max_addr +=2 *PAGE_SIZE ; - next_start.pt_base = max_addr + xen_inf.virt_base; - state.paging_start = max_addr >>PAGE_SHIFT ; + xen_state.next_start.pt_base = + xen_state.max_addr + xen_state.xen_inf.virt_base; + state.paging_start = xen_state.max_addr >>PAGE_SHIFT ; - nr_info_pages = max_addr >>PAGE_SHIFT ; + nr_info_pages = xen_state.max_addr >>PAGE_SHIFT ; nr_pages = nr_info_pages;while (1 ) { nr_pages =ALIGN_UP (nr_pages, (ALIGN_SIZE >>PAGE_SHIFT )); - nr_pt_pages =get_pgtable_size (nr_pages, xen_inf.virt_base); + nr_pt_pages =get_pgtable_size (nr_pages, xen_state.xen_inf.virt_base); nr_need_pages = nr_info_pages + nr_pt_pages + ((ADDITIONAL_SIZE +STACK_SIZE ) >>PAGE_SHIFT );
@@ -278,27 +287,28 @@ grub_xen_boot (void) }grub_dprintf ("xen" ,"bootstrap domain %llx+%llx\n" , - (unsigned long long ) xen_inf.virt_base, + (unsigned long long ) xen_state.xen_inf.virt_base, (unsigned long long )page2offset (nr_pages)); - err =grub_relocator_alloc_chunk_addr (relocator, &ch, - max_addr,page2offset (nr_pt_pages)); + err =grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, + xen_state.max_addr, +page2offset (nr_pt_pages));if (err)return err;generate_page_table (get_virtual_current_address (ch), - max_addr >>PAGE_SHIFT , nr_pages, - xen_inf.virt_base, new_mfn_list); + xen_state.max_addr >>PAGE_SHIFT , nr_pages, + xen_state.xen_inf.virt_base, new_mfn_list); - max_addr +=page2offset (nr_pt_pages); - state.stack = max_addr +STACK_SIZE + xen_inf.virt_base; - state.entry_point = xen_inf.entry_point; + xen_state.max_addr +=page2offset (nr_pt_pages); + state.stack = xen_state.max_addr +STACK_SIZE + xen_state.xen_inf.virt_base; + state.entry_point = xen_state.xen_inf.entry_point; - next_start.nr_p2m_frames += nr_pt_pages; - next_start.nr_pt_frames = nr_pt_pages; + xen_state.next_start.nr_p2m_frames += nr_pt_pages; + xen_state.next_start.nr_pt_frames = nr_pt_pages; state.paging_size = nr_pt_pages; - *nst = next_start; + *nst = xen_state.next_start;grub_memset (&gnttab_setver,0 ,sizeof (gnttab_setver));
@@ -308,24 +318,20 @@ grub_xen_boot (void)for (i =0 ; i <ARRAY_SIZE (grub_xen_shared_info->evtchn_pending); i++) grub_xen_shared_info->evtchn_pending[i] =0 ; -return grub_relocator_xen_boot (relocator, state, nr_pages, - xen_inf.virt_base < +return grub_relocator_xen_boot (xen_state.relocator, state, nr_pages, + xen_state.xen_inf.virt_base <PAGE_SIZE ?page2offset (nr_pages) :0 , nr_pages -1 ,page2offset (nr_pages -1 ) + - xen_inf.virt_base); + xen_state.xen_inf.virt_base); }static void grub_xen_reset (void ) { -grub_memset (&next_start,0 ,sizeof (next_start)); - xen_module_info_page =NULL ; - n_modules =0 ; +grub_relocator_unload (xen_state.relocator); -grub_relocator_unload (relocator); - relocator =NULL ; - loaded =0 ; +grub_memset (&xen_state,0 ,sizeof (xen_state)); } static grub_err_t
@@ -409,17 +415,22 @@ grub_cmd_xen (grub_command_t cmd __attribute__ ((unused)),grub_file_t file;grub_elf_t elf;grub_err_t err; +void *kern_chunk_src; +grub_relocator_chunk_t ch; +grub_addr_t kern_start; +grub_addr_t kern_end;if (argc ==0 )return grub_error (GRUB_ERR_BAD_ARGUMENT ,N_ ("filename expected" )); +/* Call grub_loader_unset early to avoid it being called by grub_loader_set */ grub_loader_unset ();grub_xen_reset ();grub_create_loader_cmdline (argc -1 , argv +1 , - (char *) next_start.cmd_line, -sizeof (next_start.cmd_line) -1 ); + (char *) xen_state.next_start.cmd_line, +sizeof (xen_state.next_start.cmd_line) -1 ); file =grub_file_open (argv[0 ]);if (!file)
@@ -429,85 +440,82 @@ grub_cmd_xen (grub_command_t cmd __attribute__ ((unused)),if (!elf) goto fail; - err =grub_xen_get_info (elf, &xen_inf); + err =grub_xen_get_info (elf, &xen_state.xen_inf);if (err) goto fail;#ifdef __x86_64__ -if (xen_inf.arch !=GRUB_XEN_FILE_X86_64 ) +if (xen_state.xen_inf.arch !=GRUB_XEN_FILE_X86_64 ) #else -if (xen_inf.arch !=GRUB_XEN_FILE_I386_PAE - && xen_inf.arch !=GRUB_XEN_FILE_I386_PAE_BIMODE ) +if (xen_state.xen_inf.arch !=GRUB_XEN_FILE_I386_PAE + && xen_state.xen_inf.arch !=GRUB_XEN_FILE_I386_PAE_BIMODE ) #endif {grub_error (GRUB_ERR_BAD_OS ,"incompatible architecture: %d" , - xen_inf.arch); + xen_state.xen_inf.arch); goto fail; } -if (xen_inf.virt_base & (PAGE_SIZE -1 )) +if (xen_state.xen_inf.virt_base & (PAGE_SIZE -1 )) {grub_error (GRUB_ERR_BAD_OS ,"unaligned virt_base" ); goto fail; }grub_dprintf ("xen" ,"virt_base = %llx, entry = %llx\n" , - (unsigned long long ) xen_inf.virt_base, - (unsigned long long ) xen_inf.entry_point); + (unsigned long long ) xen_state.xen_inf.virt_base, + (unsigned long long ) xen_state.xen_inf.entry_point); - relocator =grub_relocator_new (); -if (!relocator) + xen_state.relocator =grub_relocator_new (); +if (!xen_state.relocator) goto fail; -grub_relocator_chunk_t ch; -grub_addr_t kern_start = xen_inf.kern_start - xen_inf.paddr_offset; -grub_addr_t kern_end = xen_inf.kern_end - xen_inf.paddr_offset; + kern_start = xen_state.xen_inf.kern_start - xen_state.xen_inf.paddr_offset; + kern_end = xen_state.xen_inf.kern_end - xen_state.xen_inf.paddr_offset; -if (xen_inf.has_hypercall_page) +if (xen_state.xen_inf.has_hypercall_page) {grub_dprintf ("xen" ,"hypercall page at 0x%llx\n" , - (unsigned long long ) xen_inf.hypercall_page); -if (xen_inf.hypercall_page - xen_inf.virt_base < kern_start) - kern_start = xen_inf.hypercall_page - xen_inf.virt_base; - -if (xen_inf.hypercall_page - xen_inf.virt_base +PAGE_SIZE > kern_end) - kern_end = xen_inf.hypercall_page - xen_inf.virt_base +PAGE_SIZE ; + (unsigned long long ) xen_state.xen_inf.hypercall_page); + kern_start =grub_min (kern_start, xen_state.xen_inf.hypercall_page - + xen_state.xen_inf.virt_base); + kern_end =grub_max (kern_end, xen_state.xen_inf.hypercall_page - + xen_state.xen_inf.virt_base +PAGE_SIZE ); } - max_addr =ALIGN_UP (kern_end,PAGE_SIZE ); + xen_state.max_addr =ALIGN_UP (kern_end,PAGE_SIZE ); - err =grub_relocator_alloc_chunk_addr (relocator, &ch, kern_start, + err =grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, kern_start, kern_end - kern_start);if (err) goto fail; kern_chunk_src =get_virtual_current_address (ch);grub_dprintf ("xen" ,"paddr_offset = 0x%llx\n" , - (unsigned long long ) xen_inf.paddr_offset); + (unsigned long long ) xen_state.xen_inf.paddr_offset);grub_dprintf ("xen" ,"kern_start = 0x%llx, kern_end = 0x%llx\n" , - (unsigned long long ) xen_inf.kern_start, - (unsigned long long ) xen_inf.kern_end); + (unsigned long long ) xen_state.xen_inf.kern_start, + (unsigned long long ) xen_state.xen_inf.kern_end); err =grub_elfXX_load (elf, argv[0 ], (grub_uint8_t *) kern_chunk_src - kern_start - - xen_inf.paddr_offset,0 ,0 ,0 ); + - xen_state.xen_inf.paddr_offset,0 ,0 ,0 ); -if (xen_inf.has_hypercall_page) +if (xen_state.xen_inf.has_hypercall_page) {unsigned i;for (i =0 ; i <PAGE_SIZE /HYPERCALL_INTERFACE_SIZE ; i++)set_hypercall_interface ((grub_uint8_t *) kern_chunk_src + i *HYPERCALL_INTERFACE_SIZE + - xen_inf.hypercall_page - xen_inf.virt_base - - kern_start, i); + xen_state.xen_inf.hypercall_page - + xen_state.xen_inf.virt_base - kern_start, i); }if (err) goto fail;grub_dl_ref (my_mod); - loaded =1 ; + xen_state.loaded =1 ;grub_loader_set (grub_xen_boot, grub_xen_unload,0 ); - loaded =1 ; goto fail;
@@ -541,14 +549,14 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), goto fail; } -if (!loaded) +if (!xen_state.loaded) {grub_error (GRUB_ERR_BAD_ARGUMENT ,N_ ("you need to load the kernel first" )); goto fail; } -if (next_start.mod_start || next_start.mod_len) +if (xen_state.next_start.mod_start || xen_state.next_start.mod_len) {grub_error (GRUB_ERR_BAD_ARGUMENT ,N_ ("initrd already loaded" )); goto fail;
@@ -561,7 +569,8 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),if (size) { - err =grub_relocator_alloc_chunk_addr (relocator, &ch, max_addr, size); + err =grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, + xen_state.max_addr, size);if (err) goto fail;
@@ -570,13 +579,14 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), goto fail; } - next_start.mod_start = max_addr + xen_inf.virt_base; - next_start.mod_len = size; + xen_state.next_start.mod_start = + xen_state.max_addr + xen_state.xen_inf.virt_base; + xen_state.next_start.mod_len = size; - max_addr =ALIGN_UP (max_addr + size,PAGE_SIZE ); + xen_state.max_addr =ALIGN_UP (xen_state.max_addr + size,PAGE_SIZE );grub_dprintf ("xen" ,"Initrd, addr=0x%x, size=0x%x\n" , - (unsigned ) next_start.mod_start, (unsigned ) size); + (unsigned ) xen_state.next_start.mod_start, (unsigned ) size); fail:grub_initrd_close (&initrd_ctx);
@@ -608,45 +618,48 @@ grub_cmd_module (grub_command_t cmd __attribute__ ((unused)),if (argc ==0 )return grub_error (GRUB_ERR_BAD_ARGUMENT ,N_ ("filename expected" )); -if (!loaded) +if (!xen_state.loaded) {return grub_error (GRUB_ERR_BAD_ARGUMENT ,N_ ("you need to load the kernel first" )); } -if ((next_start.mod_start || next_start.mod_len) && !xen_module_info_page) +if ((xen_state.next_start.mod_start || xen_state.next_start.mod_len) && + !xen_state.module_info_page) {return grub_error (GRUB_ERR_BAD_ARGUMENT ,N_ ("initrd already loaded" )); }/* Leave one space for terminator. */ -if (n_modules >=MAX_MODULES -1 ) +if (xen_state.n_modules >=MAX_MODULES -1 ) {return grub_error (GRUB_ERR_BAD_ARGUMENT ,"too many modules" ); } -if (!xen_module_info_page) +if (!xen_state.module_info_page) { - n_modules =0 ; - max_addr =ALIGN_UP (max_addr,PAGE_SIZE ); - modules_target_start = max_addr; - next_start.mod_start = max_addr + xen_inf.virt_base; - next_start.flags |=SIF_MULTIBOOT_MOD ; + xen_state.n_modules =0 ; + xen_state.max_addr =ALIGN_UP (xen_state.max_addr,PAGE_SIZE ); + xen_state.modules_target_start = xen_state.max_addr; + xen_state.next_start.mod_start = + xen_state.max_addr + xen_state.xen_inf.virt_base; + xen_state.next_start.flags |=SIF_MULTIBOOT_MOD ; - err =grub_relocator_alloc_chunk_addr (relocator, &ch, - max_addr,MAX_MODULES + err =grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, + xen_state.max_addr,MAX_MODULES * -sizeof (xen_module_info_page +sizeof (xen_state.module_info_page [0 ]));if (err)return err; - xen_module_info_page =get_virtual_current_address (ch); -grub_memset (xen_module_info_page,0 ,MAX_MODULES - *sizeof (xen_module_info_page[0 ])); - max_addr +=MAX_MODULES *sizeof (xen_module_info_page[0 ]); + xen_state.module_info_page =get_virtual_current_address (ch); +grub_memset (xen_state.module_info_page,0 ,MAX_MODULES + *sizeof (xen_state.module_info_page[0 ])); + xen_state.max_addr += +MAX_MODULES *sizeof (xen_state.module_info_page[0 ]); } - max_addr =ALIGN_UP (max_addr,PAGE_SIZE ); + xen_state.max_addr =ALIGN_UP (xen_state.max_addr,PAGE_SIZE );if (nounzip)grub_file_filter_disable_compression ();
@@ -657,20 +670,22 @@ grub_cmd_module (grub_command_t cmd __attribute__ ((unused)), cmdline_len =grub_loader_cmdline_size (argc -1 , argv +1 ); - err =grub_relocator_alloc_chunk_addr (relocator, &ch, - max_addr, cmdline_len); + err =grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, + xen_state.max_addr, cmdline_len);if (err) goto fail;grub_create_loader_cmdline (argc -1 , argv +1 ,get_virtual_current_address (ch), cmdline_len); - xen_module_info_page[n_modules].cmdline = max_addr - modules_target_start; - max_addr =ALIGN_UP (max_addr + cmdline_len,PAGE_SIZE ); + xen_state.module_info_page[xen_state.n_modules].cmdline = + xen_state.max_addr - xen_state.modules_target_start; + xen_state.max_addr =ALIGN_UP (xen_state.max_addr + cmdline_len,PAGE_SIZE );if (size) { - err =grub_relocator_alloc_chunk_addr (relocator, &ch, max_addr, size); + err =grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, + xen_state.max_addr, size);if (err) goto fail; if (grub_file_read (file, get_virtual_current_address (ch), size)
@@ -682,15 +697,17 @@ grub_cmd_module (grub_command_t cmd __attribute__ ((unused)), goto fail; } } - next_start.mod_len = max_addr + size - modules_target_start; - xen_module_info_page[n_modules].mod_start = max_addr - modules_target_start; - xen_module_info_page[n_modules].mod_end = - max_addr + size - modules_target_start; + xen_state.next_start.mod_len = + xen_state.max_addr + size - xen_state.modules_target_start; + xen_state.module_info_page[xen_state.n_modules].mod_start = + xen_state.max_addr - xen_state.modules_target_start; + xen_state.module_info_page[xen_state.n_modules].mod_end = + xen_state.max_addr + size - xen_state.modules_target_start; - n_modules++; + xen_state.n_modules++;grub_dprintf ("xen" ,"module, addr=0x%x, size=0x%x\n" , - (unsigned ) max_addr, (unsigned ) size); - max_addr =ALIGN_UP (max_addr + size,PAGE_SIZE ); + (unsigned ) xen_state.max_addr, (unsigned ) size); + xen_state.max_addr =ALIGN_UP (xen_state.max_addr + size,PAGE_SIZE ); fail:
Signature · 7 lines
2.6.2 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Juergen Gross
maintainerPATCH v5 3/11 xen: reduce number of global variables in xen loader
In reply to Juergen GrossThe loader for xen paravirtualized environment is using lots of global variables. Reduce the number by making them either local or by putting them into a single state structure.
--- grub-core/loader/i386/xen.c | 259 +++++++++++++++++++++++--------------------- 1 file changed, 138 insertions(+), 121 deletions(-)
grub-core/loader/i386/xen.c +138 -121
@@ -42,16 +42,20 @@GRUB_MOD_LICENSE ("GPLv3+" ); -static struct grub_relocator *relocator =NULL ; -static grub_uint64_t max_addr; +struct xen_loader_state { +struct grub_relocator *relocator; +struct start_info next_start; +struct grub_xen_file_info xen_inf; +grub_uint64_t max_addr; +struct xen_multiboot_mod_list *module_info_page; +grub_uint64_t modules_target_start; +grub_size_t n_modules; +int loaded; +}; + +static struct xen_loader_state xen_state; +static grub_dl_t my_mod; -static int loaded =0 ; -static struct start_info next_start; -static void *kern_chunk_src; -static struct grub_xen_file_info xen_inf; -static struct xen_multiboot_mod_list *xen_module_info_page; -static grub_uint64_t modules_target_start; -static grub_size_t n_modules;#define PAGE_SIZE 4096#define MAX_MODULES (PAGE_SIZE / sizeof (struct xen_multiboot_mod_list))
@@ -225,50 +229,55 @@ grub_xen_boot (void)if (grub_xen_n_allocated_shared_pages)return grub_error (GRUB_ERR_BUG ,"active grants" ); - state.mfn_list = max_addr; - next_start.mfn_list = max_addr + xen_inf.virt_base; - next_start.first_p2m_pfn = max_addr >>PAGE_SHIFT ;/* Is this right? */ + state.mfn_list = xen_state.max_addr; + xen_state.next_start.mfn_list = + xen_state.max_addr + xen_state.xen_inf.virt_base; + xen_state.next_start.first_p2m_pfn = xen_state.max_addr >>PAGE_SHIFT ; pgtsize =sizeof (grub_xen_mfn_t) * grub_xen_start_page_addr->nr_pages; - err =grub_relocator_alloc_chunk_addr (relocator, &ch, max_addr, pgtsize); - next_start.nr_p2m_frames = (pgtsize +PAGE_SIZE -1 ) >>PAGE_SHIFT ; + err =grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, + xen_state.max_addr, pgtsize); + xen_state.next_start.nr_p2m_frames = (pgtsize +PAGE_SIZE -1 ) >>PAGE_SHIFT ;if (err)return err; new_mfn_list =get_virtual_current_address (ch);grub_memcpy (new_mfn_list, (void *) grub_xen_start_page_addr->mfn_list, pgtsize); - max_addr =ALIGN_UP (max_addr + pgtsize,PAGE_SIZE ); + xen_state.max_addr =ALIGN_UP (xen_state.max_addr + pgtsize,PAGE_SIZE ); - err =grub_relocator_alloc_chunk_addr (relocator, &ch, - max_addr,sizeof (next_start)); + err =grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, + xen_state.max_addr, +sizeof (xen_state.next_start));if (err)return err; - state.start_info = max_addr + xen_inf.virt_base; + state.start_info = xen_state.max_addr + xen_state.xen_inf.virt_base; nst =get_virtual_current_address (ch); - max_addr =ALIGN_UP (max_addr +sizeof (next_start),PAGE_SIZE ); + xen_state.max_addr = +ALIGN_UP (xen_state.max_addr +sizeof (xen_state.next_start),PAGE_SIZE ); - next_start.nr_pages = grub_xen_start_page_addr->nr_pages; -grub_memcpy (next_start.magic, grub_xen_start_page_addr->magic, -sizeof (next_start.magic)); - next_start.store_mfn = grub_xen_start_page_addr->store_mfn; - next_start.store_evtchn = grub_xen_start_page_addr->store_evtchn; - next_start.console.domU = grub_xen_start_page_addr->console.domU; - next_start.shared_info = grub_xen_start_page_addr->shared_info; + xen_state.next_start.nr_pages = grub_xen_start_page_addr->nr_pages; +grub_memcpy (xen_state.next_start.magic, grub_xen_start_page_addr->magic, +sizeof (xen_state.next_start.magic)); + xen_state.next_start.store_mfn = grub_xen_start_page_addr->store_mfn; + xen_state.next_start.store_evtchn = grub_xen_start_page_addr->store_evtchn; + xen_state.next_start.console.domU = grub_xen_start_page_addr->console.domU; + xen_state.next_start.shared_info = grub_xen_start_page_addr->shared_info; - err =set_mfns (new_mfn_list, max_addr >>PAGE_SHIFT ); + err =set_mfns (new_mfn_list, xen_state.max_addr >>PAGE_SHIFT );if (err)return err; - max_addr +=2 *PAGE_SIZE ; + xen_state.max_addr +=2 *PAGE_SIZE ; - next_start.pt_base = max_addr + xen_inf.virt_base; - state.paging_start = max_addr >>PAGE_SHIFT ; + xen_state.next_start.pt_base = + xen_state.max_addr + xen_state.xen_inf.virt_base; + state.paging_start = xen_state.max_addr >>PAGE_SHIFT ; - nr_info_pages = max_addr >>PAGE_SHIFT ; + nr_info_pages = xen_state.max_addr >>PAGE_SHIFT ; nr_pages = nr_info_pages;while (1 ) { nr_pages =ALIGN_UP (nr_pages, (ALIGN_SIZE >>PAGE_SHIFT )); - nr_pt_pages =get_pgtable_size (nr_pages, xen_inf.virt_base); + nr_pt_pages =get_pgtable_size (nr_pages, xen_state.xen_inf.virt_base); nr_need_pages = nr_info_pages + nr_pt_pages + ((ADDITIONAL_SIZE +STACK_SIZE ) >>PAGE_SHIFT );
@@ -278,27 +287,28 @@ grub_xen_boot (void) }grub_dprintf ("xen" ,"bootstrap domain %llx+%llx\n" , - (unsigned long long ) xen_inf.virt_base, + (unsigned long long ) xen_state.xen_inf.virt_base, (unsigned long long )page2offset (nr_pages)); - err =grub_relocator_alloc_chunk_addr (relocator, &ch, - max_addr,page2offset (nr_pt_pages)); + err =grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, + xen_state.max_addr, +page2offset (nr_pt_pages));if (err)return err;generate_page_table (get_virtual_current_address (ch), - max_addr >>PAGE_SHIFT , nr_pages, - xen_inf.virt_base, new_mfn_list); + xen_state.max_addr >>PAGE_SHIFT , nr_pages, + xen_state.xen_inf.virt_base, new_mfn_list); - max_addr +=page2offset (nr_pt_pages); - state.stack = max_addr +STACK_SIZE + xen_inf.virt_base; - state.entry_point = xen_inf.entry_point; + xen_state.max_addr +=page2offset (nr_pt_pages); + state.stack = xen_state.max_addr +STACK_SIZE + xen_state.xen_inf.virt_base; + state.entry_point = xen_state.xen_inf.entry_point; - next_start.nr_p2m_frames += nr_pt_pages; - next_start.nr_pt_frames = nr_pt_pages; + xen_state.next_start.nr_p2m_frames += nr_pt_pages; + xen_state.next_start.nr_pt_frames = nr_pt_pages; state.paging_size = nr_pt_pages; - *nst = next_start; + *nst = xen_state.next_start;grub_memset (&gnttab_setver,0 ,sizeof (gnttab_setver));
@@ -308,24 +318,20 @@ grub_xen_boot (void)for (i =0 ; i <ARRAY_SIZE (grub_xen_shared_info->evtchn_pending); i++) grub_xen_shared_info->evtchn_pending[i] =0 ; -return grub_relocator_xen_boot (relocator, state, nr_pages, - xen_inf.virt_base < +return grub_relocator_xen_boot (xen_state.relocator, state, nr_pages, + xen_state.xen_inf.virt_base <PAGE_SIZE ?page2offset (nr_pages) :0 , nr_pages -1 ,page2offset (nr_pages -1 ) + - xen_inf.virt_base); + xen_state.xen_inf.virt_base); }static void grub_xen_reset (void ) { -grub_memset (&next_start,0 ,sizeof (next_start)); - xen_module_info_page =NULL ; - n_modules =0 ; +grub_relocator_unload (xen_state.relocator); -grub_relocator_unload (relocator); - relocator =NULL ; - loaded =0 ; +grub_memset (&xen_state,0 ,sizeof (xen_state)); } static grub_err_t
@@ -409,17 +415,22 @@ grub_cmd_xen (grub_command_t cmd __attribute__ ((unused)),grub_file_t file;grub_elf_t elf;grub_err_t err; +void *kern_chunk_src; +grub_relocator_chunk_t ch; +grub_addr_t kern_start; +grub_addr_t kern_end;if (argc ==0 )return grub_error (GRUB_ERR_BAD_ARGUMENT ,N_ ("filename expected" )); +/* Call grub_loader_unset early to avoid it being called by grub_loader_set */ grub_loader_unset ();grub_xen_reset ();grub_create_loader_cmdline (argc -1 , argv +1 , - (char *) next_start.cmd_line, -sizeof (next_start.cmd_line) -1 ); + (char *) xen_state.next_start.cmd_line, +sizeof (xen_state.next_start.cmd_line) -1 ); file =grub_file_open (argv[0 ]);if (!file)
@@ -429,85 +440,82 @@ grub_cmd_xen (grub_command_t cmd __attribute__ ((unused)),if (!elf) goto fail; - err =grub_xen_get_info (elf, &xen_inf); + err =grub_xen_get_info (elf, &xen_state.xen_inf);if (err) goto fail;#ifdef __x86_64__ -if (xen_inf.arch !=GRUB_XEN_FILE_X86_64 ) +if (xen_state.xen_inf.arch !=GRUB_XEN_FILE_X86_64 ) #else -if (xen_inf.arch !=GRUB_XEN_FILE_I386_PAE - && xen_inf.arch !=GRUB_XEN_FILE_I386_PAE_BIMODE ) +if (xen_state.xen_inf.arch !=GRUB_XEN_FILE_I386_PAE + && xen_state.xen_inf.arch !=GRUB_XEN_FILE_I386_PAE_BIMODE ) #endif {grub_error (GRUB_ERR_BAD_OS ,"incompatible architecture: %d" , - xen_inf.arch); + xen_state.xen_inf.arch); goto fail; } -if (xen_inf.virt_base & (PAGE_SIZE -1 )) +if (xen_state.xen_inf.virt_base & (PAGE_SIZE -1 )) {grub_error (GRUB_ERR_BAD_OS ,"unaligned virt_base" ); goto fail; }grub_dprintf ("xen" ,"virt_base = %llx, entry = %llx\n" , - (unsigned long long ) xen_inf.virt_base, - (unsigned long long ) xen_inf.entry_point); + (unsigned long long ) xen_state.xen_inf.virt_base, + (unsigned long long ) xen_state.xen_inf.entry_point); - relocator =grub_relocator_new (); -if (!relocator) + xen_state.relocator =grub_relocator_new (); +if (!xen_state.relocator) goto fail; -grub_relocator_chunk_t ch; -grub_addr_t kern_start = xen_inf.kern_start - xen_inf.paddr_offset; -grub_addr_t kern_end = xen_inf.kern_end - xen_inf.paddr_offset; + kern_start = xen_state.xen_inf.kern_start - xen_state.xen_inf.paddr_offset; + kern_end = xen_state.xen_inf.kern_end - xen_state.xen_inf.paddr_offset; -if (xen_inf.has_hypercall_page) +if (xen_state.xen_inf.has_hypercall_page) {grub_dprintf ("xen" ,"hypercall page at 0x%llx\n" , - (unsigned long long ) xen_inf.hypercall_page); -if (xen_inf.hypercall_page - xen_inf.virt_base < kern_start) - kern_start = xen_inf.hypercall_page - xen_inf.virt_base; - -if (xen_inf.hypercall_page - xen_inf.virt_base +PAGE_SIZE > kern_end) - kern_end = xen_inf.hypercall_page - xen_inf.virt_base +PAGE_SIZE ; + (unsigned long long ) xen_state.xen_inf.hypercall_page); + kern_start =grub_min (kern_start, xen_state.xen_inf.hypercall_page - + xen_state.xen_inf.virt_base); + kern_end =grub_max (kern_end, xen_state.xen_inf.hypercall_page - + xen_state.xen_inf.virt_base +PAGE_SIZE ); } - max_addr =ALIGN_UP (kern_end,PAGE_SIZE ); + xen_state.max_addr =ALIGN_UP (kern_end,PAGE_SIZE ); - err =grub_relocator_alloc_chunk_addr (relocator, &ch, kern_start, + err =grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, kern_start, kern_end - kern_start);if (err) goto fail; kern_chunk_src =get_virtual_current_address (ch);grub_dprintf ("xen" ,"paddr_offset = 0x%llx\n" , - (unsigned long long ) xen_inf.paddr_offset); + (unsigned long long ) xen_state.xen_inf.paddr_offset);grub_dprintf ("xen" ,"kern_start = 0x%llx, kern_end = 0x%llx\n" , - (unsigned long long ) xen_inf.kern_start, - (unsigned long long ) xen_inf.kern_end); + (unsigned long long ) xen_state.xen_inf.kern_start, + (unsigned long long ) xen_state.xen_inf.kern_end); err =grub_elfXX_load (elf, argv[0 ], (grub_uint8_t *) kern_chunk_src - kern_start - - xen_inf.paddr_offset,0 ,0 ,0 ); + - xen_state.xen_inf.paddr_offset,0 ,0 ,0 ); -if (xen_inf.has_hypercall_page) +if (xen_state.xen_inf.has_hypercall_page) {unsigned i;for (i =0 ; i <PAGE_SIZE /HYPERCALL_INTERFACE_SIZE ; i++)set_hypercall_interface ((grub_uint8_t *) kern_chunk_src + i *HYPERCALL_INTERFACE_SIZE + - xen_inf.hypercall_page - xen_inf.virt_base - - kern_start, i); + xen_state.xen_inf.hypercall_page - + xen_state.xen_inf.virt_base - kern_start, i); }if (err) goto fail;grub_dl_ref (my_mod); - loaded =1 ; + xen_state.loaded =1 ;grub_loader_set (grub_xen_boot, grub_xen_unload,0 ); - loaded =1 ; goto fail;
@@ -541,14 +549,14 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), goto fail; } -if (!loaded) +if (!xen_state.loaded) {grub_error (GRUB_ERR_BAD_ARGUMENT ,N_ ("you need to load the kernel first" )); goto fail; } -if (next_start.mod_start || next_start.mod_len) +if (xen_state.next_start.mod_start || xen_state.next_start.mod_len) {grub_error (GRUB_ERR_BAD_ARGUMENT ,N_ ("initrd already loaded" )); goto fail;
@@ -561,7 +569,8 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),if (size) { - err =grub_relocator_alloc_chunk_addr (relocator, &ch, max_addr, size); + err =grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, + xen_state.max_addr, size);if (err) goto fail;
@@ -570,13 +579,14 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), goto fail; } - next_start.mod_start = max_addr + xen_inf.virt_base; - next_start.mod_len = size; + xen_state.next_start.mod_start = + xen_state.max_addr + xen_state.xen_inf.virt_base; + xen_state.next_start.mod_len = size; - max_addr =ALIGN_UP (max_addr + size,PAGE_SIZE ); + xen_state.max_addr =ALIGN_UP (xen_state.max_addr + size,PAGE_SIZE );grub_dprintf ("xen" ,"Initrd, addr=0x%x, size=0x%x\n" , - (unsigned ) next_start.mod_start, (unsigned ) size); + (unsigned ) xen_state.next_start.mod_start, (unsigned ) size); fail:grub_initrd_close (&initrd_ctx);
@@ -608,45 +618,48 @@ grub_cmd_module (grub_command_t cmd __attribute__ ((unused)),if (argc ==0 )return grub_error (GRUB_ERR_BAD_ARGUMENT ,N_ ("filename expected" )); -if (!loaded) +if (!xen_state.loaded) {return grub_error (GRUB_ERR_BAD_ARGUMENT ,N_ ("you need to load the kernel first" )); } -if ((next_start.mod_start || next_start.mod_len) && !xen_module_info_page) +if ((xen_state.next_start.mod_start || xen_state.next_start.mod_len) && + !xen_state.module_info_page) {return grub_error (GRUB_ERR_BAD_ARGUMENT ,N_ ("initrd already loaded" )); }/* Leave one space for terminator. */ -if (n_modules >=MAX_MODULES -1 ) +if (xen_state.n_modules >=MAX_MODULES -1 ) {return grub_error (GRUB_ERR_BAD_ARGUMENT ,"too many modules" ); } -if (!xen_module_info_page) +if (!xen_state.module_info_page) { - n_modules =0 ; - max_addr =ALIGN_UP (max_addr,PAGE_SIZE ); - modules_target_start = max_addr; - next_start.mod_start = max_addr + xen_inf.virt_base; - next_start.flags |=SIF_MULTIBOOT_MOD ; + xen_state.n_modules =0 ; + xen_state.max_addr =ALIGN_UP (xen_state.max_addr,PAGE_SIZE ); + xen_state.modules_target_start = xen_state.max_addr; + xen_state.next_start.mod_start = + xen_state.max_addr + xen_state.xen_inf.virt_base; + xen_state.next_start.flags |=SIF_MULTIBOOT_MOD ; - err =grub_relocator_alloc_chunk_addr (relocator, &ch, - max_addr,MAX_MODULES + err =grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, + xen_state.max_addr,MAX_MODULES * -sizeof (xen_module_info_page +sizeof (xen_state.module_info_page [0 ]));if (err)return err; - xen_module_info_page =get_virtual_current_address (ch); -grub_memset (xen_module_info_page,0 ,MAX_MODULES - *sizeof (xen_module_info_page[0 ])); - max_addr +=MAX_MODULES *sizeof (xen_module_info_page[0 ]); + xen_state.module_info_page =get_virtual_current_address (ch); +grub_memset (xen_state.module_info_page,0 ,MAX_MODULES + *sizeof (xen_state.module_info_page[0 ])); + xen_state.max_addr += +MAX_MODULES *sizeof (xen_state.module_info_page[0 ]); } - max_addr =ALIGN_UP (max_addr,PAGE_SIZE ); + xen_state.max_addr =ALIGN_UP (xen_state.max_addr,PAGE_SIZE );if (nounzip)grub_file_filter_disable_compression ();
@@ -657,20 +670,22 @@ grub_cmd_module (grub_command_t cmd __attribute__ ((unused)), cmdline_len =grub_loader_cmdline_size (argc -1 , argv +1 ); - err =grub_relocator_alloc_chunk_addr (relocator, &ch, - max_addr, cmdline_len); + err =grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, + xen_state.max_addr, cmdline_len);if (err) goto fail;grub_create_loader_cmdline (argc -1 , argv +1 ,get_virtual_current_address (ch), cmdline_len); - xen_module_info_page[n_modules].cmdline = max_addr - modules_target_start; - max_addr =ALIGN_UP (max_addr + cmdline_len,PAGE_SIZE ); + xen_state.module_info_page[xen_state.n_modules].cmdline = + xen_state.max_addr - xen_state.modules_target_start; + xen_state.max_addr =ALIGN_UP (xen_state.max_addr + cmdline_len,PAGE_SIZE );if (size) { - err =grub_relocator_alloc_chunk_addr (relocator, &ch, max_addr, size); + err =grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, + xen_state.max_addr, size);if (err) goto fail; if (grub_file_read (file, get_virtual_current_address (ch), size)
@@ -682,15 +697,17 @@ grub_cmd_module (grub_command_t cmd __attribute__ ((unused)), goto fail; } } - next_start.mod_len = max_addr + size - modules_target_start; - xen_module_info_page[n_modules].mod_start = max_addr - modules_target_start; - xen_module_info_page[n_modules].mod_end = - max_addr + size - modules_target_start; + xen_state.next_start.mod_len = + xen_state.max_addr + size - xen_state.modules_target_start; + xen_state.module_info_page[xen_state.n_modules].mod_start = + xen_state.max_addr - xen_state.modules_target_start; + xen_state.module_info_page[xen_state.n_modules].mod_end = + xen_state.max_addr + size - xen_state.modules_target_start; - n_modules++; + xen_state.n_modules++;grub_dprintf ("xen" ,"module, addr=0x%x, size=0x%x\n" , - (unsigned ) max_addr, (unsigned ) size); - max_addr =ALIGN_UP (max_addr + size,PAGE_SIZE ); + (unsigned ) xen_state.max_addr, (unsigned ) size); + xen_state.max_addr =ALIGN_UP (xen_state.max_addr + size,PAGE_SIZE ); fail:
Signature · 1 line
2.6.2
Juergen Gross
maintainerPATCH v5 4/11 xen: add elfnote.h to avoid using numbers instead of constants
In reply to Juergen GrossVarious features and parameters of a pv-kernel are specified via elf notes in the kernel image. Those notes are part of the interface between the Xen hypervisor and the kernel.
Instead of using num,bers in the code when interpreting the elf notes make use of the header supplied by Xen for that purpose.
--- grub-core/loader/i386/xen_fileXX.c | 19 +-- include/xen/elfnote.h | 281 +++++++++++++++++++++++++++++++++++++ 2 files changed, 291 insertions(+), 9 deletions(-) create mode 100644 include/xen/elfnote.h
grub-core/loader/i386/xen_fileXX.c +10 -9
@@ -18,6 +18,7 @@#include <grub/xen_file.h> #include <grub/misc.h> +#include <xen/elfnote.h> static grub_err_t parse_xen_guest (grub_elf_t elf, struct grub_xen_file_info *xi,
@@ -203,35 +204,35 @@ parse_note (grub_elf_t elf, struct grub_xen_file_info *xi, xi->has_note =1 ;switch (nh->n_type) { -case 1 : +case XEN_ELFNOTE_ENTRY : xi->entry_point =grub_le_to_cpu_addr (*(Elf_Addr *) desc);break ; -case 2 : +case XEN_ELFNOTE_HYPERCALL_PAGE : xi->hypercall_page =grub_le_to_cpu_addr (*(Elf_Addr *) desc); xi->has_hypercall_page =1 ;break ; -case 3 : +case XEN_ELFNOTE_VIRT_BASE : xi->virt_base =grub_le_to_cpu_addr (*(Elf_Addr *) desc);break ; -case 4 : +case XEN_ELFNOTE_PADDR_OFFSET : xi->paddr_offset =grub_le_to_cpu_addr (*(Elf_Addr *) desc);break ; -case 5 : +case XEN_ELFNOTE_XEN_VERSION :grub_dprintf ("xen" ,"xenversion = `%s'\n" , (char *) desc);break ; -case 6 : +case XEN_ELFNOTE_GUEST_OS :grub_dprintf ("xen" ,"name = `%s'\n" , (char *) desc);break ; -case 7 : +case XEN_ELFNOTE_GUEST_VERSION :grub_dprintf ("xen" ,"version = `%s'\n" , (char *) desc);break ; -case 8 : +case XEN_ELFNOTE_LOADER :if (descsz <7 ||grub_memcmp (desc,"generic" , descsz ==7 ?7 :8 ) !=0 )return grub_error (GRUB_ERR_BAD_OS ,"invalid loader" );break ;/* PAE */ -case 9 : +case XEN_ELFNOTE_PAE_MODE :grub_dprintf ("xen" ,"pae = `%s', %d, %d\n" , (char *) desc, xi->arch, descsz); if (xi->arch != GRUB_XEN_FILE_I386
include/xen/elfnote.h new file +281 -0
281 lines not on this page · raw message
Signature · 7 lines
2.6.2 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Juergen Gross
maintainerPATCH v5 5/11 xen: synchronize xen header
In reply to Juergen GrossGet actual version of include/xen/xen.h from the Xen repository in order to be able to use constants defined there.
--- include/xen/arch-x86/xen-x86_32.h | 22 +++---- include/xen/arch-x86/xen-x86_64.h | 8 +-- include/xen/xen.h | 125 +++++++++++++++++++++++++++----------- 3 files changed, 105 insertions(+), 50 deletions(-)
include/xen/arch-x86/xen-x86_32.h +10 -12
@@ -58,34 +58,31 @@#define __HYPERVISOR_VIRT_START_PAE 0xF5800000#define __MACH2PHYS_VIRT_START_PAE 0xF5800000#define __MACH2PHYS_VIRT_END_PAE 0xF6800000 -#define HYPERVISOR_VIRT_START_PAE \ - mk_unsigned_long(__HYPERVISOR_VIRT_START_PAE) -#define MACH2PHYS_VIRT_START_PAE \ - mk_unsigned_long(__MACH2PHYS_VIRT_START_PAE) -#define MACH2PHYS_VIRT_END_PAE \ - mk_unsigned_long(__MACH2PHYS_VIRT_END_PAE) +#define HYPERVISOR_VIRT_START_PAE xen_mk_ulong(__HYPERVISOR_VIRT_START_PAE) +#define MACH2PHYS_VIRT_START_PAE xen_mk_ulong(__MACH2PHYS_VIRT_START_PAE) +#define MACH2PHYS_VIRT_END_PAE xen_mk_ulong(__MACH2PHYS_VIRT_END_PAE)/* Non-PAE bounds are obsolete. */ #define __HYPERVISOR_VIRT_START_NONPAE 0xFC000000#define __MACH2PHYS_VIRT_START_NONPAE 0xFC000000#define __MACH2PHYS_VIRT_END_NONPAE 0xFC400000#define HYPERVISOR_VIRT_START_NONPAE \ - mk_unsigned_long(__HYPERVISOR_VIRT_START_NONPAE) + xen_mk_ulong(__HYPERVISOR_VIRT_START_NONPAE)#define MACH2PHYS_VIRT_START_NONPAE \ - mk_unsigned_long(__MACH2PHYS_VIRT_START_NONPAE) + xen_mk_ulong(__MACH2PHYS_VIRT_START_NONPAE)#define MACH2PHYS_VIRT_END_NONPAE \ - mk_unsigned_long(__MACH2PHYS_VIRT_END_NONPAE) + xen_mk_ulong(__MACH2PHYS_VIRT_END_NONPAE)#define __HYPERVISOR_VIRT_START __HYPERVISOR_VIRT_START_PAE#define __MACH2PHYS_VIRT_START __MACH2PHYS_VIRT_START_PAE#define __MACH2PHYS_VIRT_END __MACH2PHYS_VIRT_END_PAE#ifndef HYPERVISOR_VIRT_START -#define HYPERVISOR_VIRT_START mk_unsigned_long(__HYPERVISOR_VIRT_START) +#define HYPERVISOR_VIRT_START xen_mk_ulong(__HYPERVISOR_VIRT_START)#endif -#define MACH2PHYS_VIRT_START mk_unsigned_long(__MACH2PHYS_VIRT_START) -#define MACH2PHYS_VIRT_END mk_unsigned_long(__MACH2PHYS_VIRT_END) +#define MACH2PHYS_VIRT_START xen_mk_ulong(__MACH2PHYS_VIRT_START) +#define MACH2PHYS_VIRT_END xen_mk_ulong(__MACH2PHYS_VIRT_END)#define MACH2PHYS_NR_ENTRIES ((MACH2PHYS_VIRT_END-MACH2PHYS_VIRT_START)>>2)#ifndef machine_to_phys_mapping#define machine_to_phys_mapping ((unsigned long *)MACH2PHYS_VIRT_START)
@@ -104,6 +101,7 @@do {if (sizeof (hnd) ==8 ) *(uint64_t *)&(hnd) =0 ; \ (hnd).p = val; \ } while ( 0 ) +#define int64_aligned_t int64_t __attribute__((aligned(8)))#define uint64_aligned_t uint64_t __attribute__((aligned(8)))#define __XEN_GUEST_HANDLE_64 (name) __guest_handle_64_ ## name#define XEN_GUEST_HANDLE_64 (name) __XEN_GUEST_HANDLE_64(name)
include/xen/arch-x86/xen-x86_64.h +4 -4
@@ -76,12 +76,12 @@#define __MACH2PHYS_VIRT_END 0xFFFF804000000000#ifndef HYPERVISOR_VIRT_START -#define HYPERVISOR_VIRT_START mk_unsigned_long(__HYPERVISOR_VIRT_START) -#define HYPERVISOR_VIRT_END mk_unsigned_long(__HYPERVISOR_VIRT_END) +#define HYPERVISOR_VIRT_START xen_mk_ulong(__HYPERVISOR_VIRT_START) +#define HYPERVISOR_VIRT_END xen_mk_ulong(__HYPERVISOR_VIRT_END)#endif -#define MACH2PHYS_VIRT_START mk_unsigned_long(__MACH2PHYS_VIRT_START) -#define MACH2PHYS_VIRT_END mk_unsigned_long(__MACH2PHYS_VIRT_END) +#define MACH2PHYS_VIRT_START xen_mk_ulong(__MACH2PHYS_VIRT_START) +#define MACH2PHYS_VIRT_END xen_mk_ulong(__MACH2PHYS_VIRT_END)#define MACH2PHYS_NR_ENTRIES ((MACH2PHYS_VIRT_END-MACH2PHYS_VIRT_START)>>3)#ifndef machine_to_phys_mapping#define machine_to_phys_mapping ((unsigned long *)HYPERVISOR_VIRT_START)
include/xen/xen.h +91 -34
230 lines not on this page · raw message
Signature · 7 lines
2.6.2 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Juergen Gross
maintainerPATCH v5 5/11 xen: synchronize xen header
In reply to Juergen GrossGet actual version of include/xen/xen.h from the Xen repository in order to be able to use constants defined there.
--- include/xen/arch-x86/xen-x86_32.h | 22 +++---- include/xen/arch-x86/xen-x86_64.h | 8 +-- include/xen/xen.h | 125 +++++++++++++++++++++++++++----------- 3 files changed, 105 insertions(+), 50 deletions(-)
include/xen/arch-x86/xen-x86_32.h +10 -12
@@ -58,34 +58,31 @@#define __HYPERVISOR_VIRT_START_PAE 0xF5800000#define __MACH2PHYS_VIRT_START_PAE 0xF5800000#define __MACH2PHYS_VIRT_END_PAE 0xF6800000 -#define HYPERVISOR_VIRT_START_PAE \ - mk_unsigned_long(__HYPERVISOR_VIRT_START_PAE) -#define MACH2PHYS_VIRT_START_PAE \ - mk_unsigned_long(__MACH2PHYS_VIRT_START_PAE) -#define MACH2PHYS_VIRT_END_PAE \ - mk_unsigned_long(__MACH2PHYS_VIRT_END_PAE) +#define HYPERVISOR_VIRT_START_PAE xen_mk_ulong(__HYPERVISOR_VIRT_START_PAE) +#define MACH2PHYS_VIRT_START_PAE xen_mk_ulong(__MACH2PHYS_VIRT_START_PAE) +#define MACH2PHYS_VIRT_END_PAE xen_mk_ulong(__MACH2PHYS_VIRT_END_PAE)/* Non-PAE bounds are obsolete. */ #define __HYPERVISOR_VIRT_START_NONPAE 0xFC000000#define __MACH2PHYS_VIRT_START_NONPAE 0xFC000000#define __MACH2PHYS_VIRT_END_NONPAE 0xFC400000#define HYPERVISOR_VIRT_START_NONPAE \ - mk_unsigned_long(__HYPERVISOR_VIRT_START_NONPAE) + xen_mk_ulong(__HYPERVISOR_VIRT_START_NONPAE)#define MACH2PHYS_VIRT_START_NONPAE \ - mk_unsigned_long(__MACH2PHYS_VIRT_START_NONPAE) + xen_mk_ulong(__MACH2PHYS_VIRT_START_NONPAE)#define MACH2PHYS_VIRT_END_NONPAE \ - mk_unsigned_long(__MACH2PHYS_VIRT_END_NONPAE) + xen_mk_ulong(__MACH2PHYS_VIRT_END_NONPAE)#define __HYPERVISOR_VIRT_START __HYPERVISOR_VIRT_START_PAE#define __MACH2PHYS_VIRT_START __MACH2PHYS_VIRT_START_PAE#define __MACH2PHYS_VIRT_END __MACH2PHYS_VIRT_END_PAE#ifndef HYPERVISOR_VIRT_START -#define HYPERVISOR_VIRT_START mk_unsigned_long(__HYPERVISOR_VIRT_START) +#define HYPERVISOR_VIRT_START xen_mk_ulong(__HYPERVISOR_VIRT_START)#endif -#define MACH2PHYS_VIRT_START mk_unsigned_long(__MACH2PHYS_VIRT_START) -#define MACH2PHYS_VIRT_END mk_unsigned_long(__MACH2PHYS_VIRT_END) +#define MACH2PHYS_VIRT_START xen_mk_ulong(__MACH2PHYS_VIRT_START) +#define MACH2PHYS_VIRT_END xen_mk_ulong(__MACH2PHYS_VIRT_END)#define MACH2PHYS_NR_ENTRIES ((MACH2PHYS_VIRT_END-MACH2PHYS_VIRT_START)>>2)#ifndef machine_to_phys_mapping#define machine_to_phys_mapping ((unsigned long *)MACH2PHYS_VIRT_START)
@@ -104,6 +101,7 @@do {if (sizeof (hnd) ==8 ) *(uint64_t *)&(hnd) =0 ; \ (hnd).p = val; \ } while ( 0 ) +#define int64_aligned_t int64_t __attribute__((aligned(8)))#define uint64_aligned_t uint64_t __attribute__((aligned(8)))#define __XEN_GUEST_HANDLE_64 (name) __guest_handle_64_ ## name#define XEN_GUEST_HANDLE_64 (name) __XEN_GUEST_HANDLE_64(name)
include/xen/arch-x86/xen-x86_64.h +4 -4
@@ -76,12 +76,12 @@#define __MACH2PHYS_VIRT_END 0xFFFF804000000000#ifndef HYPERVISOR_VIRT_START -#define HYPERVISOR_VIRT_START mk_unsigned_long(__HYPERVISOR_VIRT_START) -#define HYPERVISOR_VIRT_END mk_unsigned_long(__HYPERVISOR_VIRT_END) +#define HYPERVISOR_VIRT_START xen_mk_ulong(__HYPERVISOR_VIRT_START) +#define HYPERVISOR_VIRT_END xen_mk_ulong(__HYPERVISOR_VIRT_END)#endif -#define MACH2PHYS_VIRT_START mk_unsigned_long(__MACH2PHYS_VIRT_START) -#define MACH2PHYS_VIRT_END mk_unsigned_long(__MACH2PHYS_VIRT_END) +#define MACH2PHYS_VIRT_START xen_mk_ulong(__MACH2PHYS_VIRT_START) +#define MACH2PHYS_VIRT_END xen_mk_ulong(__MACH2PHYS_VIRT_END)#define MACH2PHYS_NR_ENTRIES ((MACH2PHYS_VIRT_END-MACH2PHYS_VIRT_START)>>3)#ifndef machine_to_phys_mapping#define machine_to_phys_mapping ((unsigned long *)HYPERVISOR_VIRT_START)
include/xen/xen.h +91 -34
230 lines not on this page · raw message
Signature · 1 line
2.6.2
Juergen Gross
maintainerPATCH v5 6/11 xen: factor out p2m list allocation into separate function
In reply to Juergen GrossDo the p2m list allocation of the to be loaded kernel in a separate function. This will allow doing the p2m list allocation at different times of the boot preparations depending on the features the kernel is supporting.
While at this remove superfluous setting of first_p2m_pfn and nr_p2m_frames as those are needed only in case of the p2m list not being mapped by the initial kernel mapping.
--- grub-core/loader/i386/xen.c | 87 ++++++++++++++++++++++++++------------------- 1 file changed, 50 insertions(+), 37 deletions(-)
grub-core/loader/i386/xen.c +50 -37
@@ -44,8 +44,10 @@ GRUB_MOD_LICENSE ("GPLv3+");struct xen_loader_state {struct grub_relocator *relocator; +struct grub_relocator_xen_state state;struct start_info next_start;struct grub_xen_file_info xen_inf; +grub_xen_mfn_t *virt_mfn_list;grub_uint64_t max_addr;struct xen_multiboot_mod_list *module_info_page;grub_uint64_t modules_target_start;
@@ -170,7 +172,7 @@ generate_page_table (grub_uint64_t *where, grub_uint64_t paging_start, }static grub_err_t -set_mfns (grub_xen_mfn_t * new_mfn_list,grub_xen_mfn_t pfn) +set_mfns (grub_xen_mfn_t pfn) {grub_xen_mfn_t i, t;grub_xen_mfn_t cn_pfn =-1 , st_pfn =-1 ;
@@ -179,32 +181,34 @@ set_mfns (grub_xen_mfn_t * new_mfn_list, grub_xen_mfn_t pfn)for (i =0 ; i < grub_xen_start_page_addr->nr_pages; i++) { -if (new_mfn_list[i] == grub_xen_start_page_addr->console.domU.mfn) +if (xen_state.virt_mfn_list[i] == + grub_xen_start_page_addr->console.domU.mfn) cn_pfn = i; -if (new_mfn_list[i] == grub_xen_start_page_addr->store_mfn) +if (xen_state.virt_mfn_list[i] == grub_xen_start_page_addr->store_mfn) st_pfn = i; }if (cn_pfn == (grub_xen_mfn_t)-1 )return grub_error (GRUB_ERR_BUG ,"no console" );if (st_pfn == (grub_xen_mfn_t)-1 )return grub_error (GRUB_ERR_BUG ,"no store" ); - t = new_mfn_list[pfn]; - new_mfn_list[pfn] = new_mfn_list[cn_pfn]; - new_mfn_list[cn_pfn] = t; - t = new_mfn_list[pfn +1 ]; - new_mfn_list[pfn +1 ] = new_mfn_list[st_pfn]; - new_mfn_list[st_pfn] = t; + t = xen_state.virt_mfn_list[pfn]; + xen_state.virt_mfn_list[pfn] = xen_state.virt_mfn_list[cn_pfn]; + xen_state.virt_mfn_list[cn_pfn] = t; + t = xen_state.virt_mfn_list[pfn +1 ]; + xen_state.virt_mfn_list[pfn +1 ] = xen_state.virt_mfn_list[st_pfn]; + xen_state.virt_mfn_list[st_pfn] = t; - m2p_updates[0 ].ptr =page2offset (new_mfn_list[pfn]) |MMU_MACHPHYS_UPDATE ; + m2p_updates[0 ].ptr = +page2offset (xen_state.virt_mfn_list[pfn]) |MMU_MACHPHYS_UPDATE ; m2p_updates[0 ].val = pfn; m2p_updates[1 ].ptr = -page2offset (new_mfn_list[pfn +1 ]) |MMU_MACHPHYS_UPDATE ; +page2offset (xen_state.virt_mfn_list[pfn +1 ]) |MMU_MACHPHYS_UPDATE ; m2p_updates[1 ].val = pfn +1 ; m2p_updates[2 ].ptr = -page2offset (new_mfn_list[cn_pfn]) |MMU_MACHPHYS_UPDATE ; +page2offset (xen_state.virt_mfn_list[cn_pfn]) |MMU_MACHPHYS_UPDATE ; m2p_updates[2 ].val = cn_pfn; m2p_updates[3 ].ptr = -page2offset (new_mfn_list[st_pfn]) |MMU_MACHPHYS_UPDATE ; +page2offset (xen_state.virt_mfn_list[st_pfn]) |MMU_MACHPHYS_UPDATE ; m2p_updates[3 ].val = st_pfn;grub_xen_mmu_update (m2p_updates,4 ,NULL ,DOMID_SELF );
@@ -213,43 +217,52 @@ set_mfns (grub_xen_mfn_t * new_mfn_list, grub_xen_mfn_t pfn) }static grub_err_t +grub_xen_p2m_alloc (void ) +{ +grub_relocator_chunk_t ch; +grub_size_t p2msize; +grub_err_t err; + + xen_state.state.mfn_list = xen_state.max_addr; + xen_state.next_start.mfn_list = + xen_state.max_addr + xen_state.xen_inf.virt_base; + p2msize =sizeof (grub_xen_mfn_t) * grub_xen_start_page_addr->nr_pages; + err =grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, + xen_state.max_addr, p2msize); +if (err) +return err; + xen_state.virt_mfn_list =get_virtual_current_address (ch); +grub_memcpy (xen_state.virt_mfn_list, + (void *) grub_xen_start_page_addr->mfn_list, p2msize); + xen_state.max_addr =ALIGN_UP (xen_state.max_addr + p2msize,PAGE_SIZE ); + +return GRUB_ERR_NONE ; +} + +static grub_err_t grub_xen_boot (void ) { -struct grub_relocator_xen_state state;grub_relocator_chunk_t ch;grub_err_t err; -grub_size_t pgtsize;struct start_info *nst;grub_uint64_t nr_info_pages;grub_uint64_t nr_pages, nr_pt_pages, nr_need_pages;struct gnttab_set_version gnttab_setver; -grub_xen_mfn_t *new_mfn_list;grub_size_t i;if (grub_xen_n_allocated_shared_pages)return grub_error (GRUB_ERR_BUG ,"active grants" ); - state.mfn_list = xen_state.max_addr; - xen_state.next_start.mfn_list = - xen_state.max_addr + xen_state.xen_inf.virt_base; - xen_state.next_start.first_p2m_pfn = xen_state.max_addr >>PAGE_SHIFT ; - pgtsize =sizeof (grub_xen_mfn_t) * grub_xen_start_page_addr->nr_pages; - err =grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, - xen_state.max_addr, pgtsize); - xen_state.next_start.nr_p2m_frames = (pgtsize +PAGE_SIZE -1 ) >>PAGE_SHIFT ; + err =grub_xen_p2m_alloc ();if (err)return err; - new_mfn_list =get_virtual_current_address (ch); -grub_memcpy (new_mfn_list, - (void *) grub_xen_start_page_addr->mfn_list, pgtsize); - xen_state.max_addr =ALIGN_UP (xen_state.max_addr + pgtsize,PAGE_SIZE ); err =grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, xen_state.max_addr,sizeof (xen_state.next_start));if (err)return err; - state.start_info = xen_state.max_addr + xen_state.xen_inf.virt_base; + xen_state.state.start_info = xen_state.max_addr + xen_state.xen_inf.virt_base; nst =get_virtual_current_address (ch); xen_state.max_addr =ALIGN_UP (xen_state.max_addr +sizeof (xen_state.next_start),PAGE_SIZE );
@@ -262,14 +275,14 @@ grub_xen_boot (void) xen_state.next_start.console.domU = grub_xen_start_page_addr->console.domU; xen_state.next_start.shared_info = grub_xen_start_page_addr->shared_info; - err =set_mfns (new_mfn_list, xen_state.max_addr >>PAGE_SHIFT ); + err =set_mfns (xen_state.max_addr >>PAGE_SHIFT );if (err)return err; xen_state.max_addr +=2 *PAGE_SIZE ; xen_state.next_start.pt_base = xen_state.max_addr + xen_state.xen_inf.virt_base; - state.paging_start = xen_state.max_addr >>PAGE_SHIFT ; + xen_state.state.paging_start = xen_state.max_addr >>PAGE_SHIFT ; nr_info_pages = xen_state.max_addr >>PAGE_SHIFT ; nr_pages = nr_info_pages;
@@ -298,15 +311,15 @@ grub_xen_boot (void)generate_page_table (get_virtual_current_address (ch), xen_state.max_addr >>PAGE_SHIFT , nr_pages, - xen_state.xen_inf.virt_base, new_mfn_list); + xen_state.xen_inf.virt_base, xen_state.virt_mfn_list); xen_state.max_addr +=page2offset (nr_pt_pages); - state.stack = xen_state.max_addr +STACK_SIZE + xen_state.xen_inf.virt_base; - state.entry_point = xen_state.xen_inf.entry_point; + xen_state.state.stack = + xen_state.max_addr +STACK_SIZE + xen_state.xen_inf.virt_base; + xen_state.state.entry_point = xen_state.xen_inf.entry_point; - xen_state.next_start.nr_p2m_frames += nr_pt_pages; xen_state.next_start.nr_pt_frames = nr_pt_pages; - state.paging_size = nr_pt_pages; + xen_state.state.paging_size = nr_pt_pages; *nst = xen_state.next_start;
@@ -318,7 +331,7 @@ grub_xen_boot (void)for (i =0 ; i <ARRAY_SIZE (grub_xen_shared_info->evtchn_pending); i++) grub_xen_shared_info->evtchn_pending[i] =0 ; - return grub_relocator_xen_boot (xen_state.relocator, state, nr_pages, + return grub_relocator_xen_boot (xen_state.relocator, xen_state.state, nr_pages, xen_state.xen_inf.virt_base < PAGE_SIZE ? page2offset (nr_pages) : 0, nr_pages - 1,
Signature · 7 lines
2.6.2 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Juergen Gross
maintainerPATCH v5 7/11 xen: factor out allocation of special pages into separate function
In reply to Juergen GrossDo the allocation of special pages (start info, console and xenbus ring buffers) in a separate function. This will allow to do the allocation at different times of the boot preparations depending on the features the kernel is supporting.
--- grub-core/loader/i386/xen.c | 48 +++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 17 deletions(-)
grub-core/loader/i386/xen.c +31 -17
@@ -48,6 +48,8 @@ struct xen_loader_state {struct start_info next_start;struct grub_xen_file_info xen_inf;grub_xen_mfn_t *virt_mfn_list; +struct start_info *virt_start_info; +grub_xen_mfn_t console_pfn;grub_uint64_t max_addr;struct xen_multiboot_mod_list *module_info_page;grub_uint64_t modules_target_start;
@@ -240,22 +242,10 @@ grub_xen_p2m_alloc (void) }static grub_err_t -grub_xen_boot (void ) +grub_xen_special_alloc (void ) {grub_relocator_chunk_t ch;grub_err_t err; -struct start_info *nst; -grub_uint64_t nr_info_pages; -grub_uint64_t nr_pages, nr_pt_pages, nr_need_pages; -struct gnttab_set_version gnttab_setver; -grub_size_t i; - -if (grub_xen_n_allocated_shared_pages) -return grub_error (GRUB_ERR_BUG ,"active grants" ); - - err =grub_xen_p2m_alloc (); -if (err) -return err; err = grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, xen_state.max_addr,
@@ -263,9 +253,11 @@ grub_xen_boot (void)if (err)return err; xen_state.state.start_info = xen_state.max_addr + xen_state.xen_inf.virt_base; - nst =get_virtual_current_address (ch); + xen_state.virt_start_info =get_virtual_current_address (ch); xen_state.max_addr =ALIGN_UP (xen_state.max_addr +sizeof (xen_state.next_start),PAGE_SIZE ); + xen_state.console_pfn = xen_state.max_addr >>PAGE_SHIFT ; + xen_state.max_addr +=2 *PAGE_SIZE ; xen_state.next_start.nr_pages = grub_xen_start_page_addr->nr_pages; grub_memcpy (xen_state.next_start.magic, grub_xen_start_page_addr->magic,
@@ -275,10 +267,28 @@ grub_xen_boot (void) xen_state.next_start.console.domU = grub_xen_start_page_addr->console.domU; xen_state.next_start.shared_info = grub_xen_start_page_addr->shared_info; - err =set_mfns (xen_state.max_addr >>PAGE_SHIFT ); +return GRUB_ERR_NONE ; +} + +static grub_err_t +grub_xen_boot (void ) +{ +grub_relocator_chunk_t ch; +grub_err_t err; +grub_uint64_t nr_info_pages; +grub_uint64_t nr_pages, nr_pt_pages, nr_need_pages; +struct gnttab_set_version gnttab_setver; +grub_size_t i; + +if (grub_xen_n_allocated_shared_pages) +return grub_error (GRUB_ERR_BUG ,"active grants" ); + + err =grub_xen_p2m_alloc (); +if (err) +return err; + err =grub_xen_special_alloc ();if (err)return err; - xen_state.max_addr +=2 *PAGE_SIZE ; xen_state.next_start.pt_base = xen_state.max_addr + xen_state.xen_inf.virt_base;
@@ -309,6 +319,10 @@ grub_xen_boot (void)if (err)return err; + err =set_mfns (xen_state.console_pfn); +if (err) +return err; +generate_page_table (get_virtual_current_address (ch), xen_state.max_addr >>PAGE_SHIFT , nr_pages, xen_state.xen_inf.virt_base, xen_state.virt_mfn_list);
@@ -321,7 +335,7 @@ grub_xen_boot (void) xen_state.next_start.nr_pt_frames = nr_pt_pages; xen_state.state.paging_size = nr_pt_pages; - *nst = xen_state.next_start; + *xen_state.virt_start_info = xen_state.next_start;grub_memset (&gnttab_setver,0 ,sizeof (gnttab_setver));
Signature · 7 lines
2.6.2 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Juergen Gross
maintainerPATCH v5 8/11 xen: factor out allocation of page tables into separate function
In reply to Juergen GrossDo the allocation of page tables in a separate function. This will allow to do the allocation at different times of the boot preparations depending on the features the kernel is supporting.
--- grub-core/loader/i386/xen.c | 91 ++++++++++++++++++++++++++++----------------- 1 file changed, 56 insertions(+), 35 deletions(-)
grub-core/loader/i386/xen.c +56 -35
@@ -51,6 +51,9 @@ struct xen_loader_state {struct start_info *virt_start_info;grub_xen_mfn_t console_pfn;grub_uint64_t max_addr; +grub_uint64_t *virt_pgtable; +grub_uint64_t pgtbl_start; +grub_uint64_t pgtbl_end;struct xen_multiboot_mod_list *module_info_page;grub_uint64_t modules_target_start;grub_size_t n_modules;
@@ -110,17 +113,17 @@ get_pgtable_size (grub_uint64_t total_pages, grub_uint64_t virt_base)static void generate_page_table (grub_uint64_t *where,grub_uint64_t paging_start, -grub_uint64_t total_pages,grub_uint64_t virt_base, -grub_xen_mfn_t *mfn_list) +grub_uint64_t paging_end,grub_uint64_t total_pages, +grub_uint64_t virt_base,grub_xen_mfn_t *mfn_list) {if (!virt_base) - total_pages++; + paging_end++;grub_uint64_t lx[NUMBER_OF_LEVELS ], lxs[NUMBER_OF_LEVELS ];grub_uint64_t nlx, nls, sz =0 ;int l; - nlx = total_pages; + nlx = paging_end; nls = virt_base >>PAGE_SHIFT ;for (l =0 ; l <NUMBER_OF_LEVELS ; l++) {
@@ -164,7 +167,7 @@ generate_page_table (grub_uint64_t *where, grub_uint64_t paging_start,if (pr) pg +=POINTERS_PER_PAGE ; -for (j =0 ; j < total_pages; j++) +for (j =0 ; j < paging_end; j++) {if (j >= paging_start && j < lp) pg[j + lxs[0 ]] =page2offset (mfn_list[j]) |5 ;
@@ -271,24 +274,12 @@ grub_xen_special_alloc (void) }static grub_err_t -grub_xen_boot (void ) +grub_xen_pt_alloc (void ) {grub_relocator_chunk_t ch;grub_err_t err;grub_uint64_t nr_info_pages;grub_uint64_t nr_pages, nr_pt_pages, nr_need_pages; -struct gnttab_set_version gnttab_setver; -grub_size_t i; - -if (grub_xen_n_allocated_shared_pages) -return grub_error (GRUB_ERR_BUG ,"active grants" ); - - err =grub_xen_p2m_alloc (); -if (err) -return err; - err =grub_xen_special_alloc (); -if (err) -return err; xen_state.next_start.pt_base = xen_state.max_addr + xen_state.xen_inf.virt_base;
@@ -309,31 +300,61 @@ grub_xen_boot (void) nr_pages = nr_need_pages; } -grub_dprintf ("xen" ,"bootstrap domain %llx+%llx\n" , - (unsigned long long ) xen_state.xen_inf.virt_base, - (unsigned long long )page2offset (nr_pages)); - err =grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, xen_state.max_addr,page2offset (nr_pt_pages));if (err)return err; - err =set_mfns (xen_state.console_pfn); -if (err) -return err; - -generate_page_table (get_virtual_current_address (ch), - xen_state.max_addr >>PAGE_SHIFT , nr_pages, - xen_state.xen_inf.virt_base, xen_state.virt_mfn_list); - + xen_state.virt_pgtable =get_virtual_current_address (ch); + xen_state.pgtbl_start = xen_state.max_addr >>PAGE_SHIFT ; xen_state.max_addr +=page2offset (nr_pt_pages); xen_state.state.stack = xen_state.max_addr +STACK_SIZE + xen_state.xen_inf.virt_base; - xen_state.state.entry_point = xen_state.xen_inf.entry_point; - - xen_state.next_start.nr_pt_frames = nr_pt_pages; xen_state.state.paging_size = nr_pt_pages; + xen_state.next_start.nr_pt_frames = nr_pt_pages; + xen_state.max_addr =page2offset (nr_pages); + xen_state.pgtbl_end = nr_pages; + +return GRUB_ERR_NONE ; +} + +static grub_err_t +grub_xen_boot (void ) +{ +grub_err_t err; +grub_uint64_t nr_pages; +struct gnttab_set_version gnttab_setver; +grub_size_t i; + +if (grub_xen_n_allocated_shared_pages) +return grub_error (GRUB_ERR_BUG ,"active grants" ); + + err =grub_xen_p2m_alloc (); +if (err) +return err; + err =grub_xen_special_alloc (); +if (err) +return err; + err =grub_xen_pt_alloc (); +if (err) +return err; + + err =set_mfns (xen_state.console_pfn); +if (err) +return err; + + nr_pages = xen_state.max_addr >>PAGE_SHIFT ; + +grub_dprintf ("xen" ,"bootstrap domain %llx+%llx\n" , + (unsigned long long ) xen_state.xen_inf.virt_base, + (unsigned long long )page2offset (nr_pages)); + +generate_page_table (xen_state.virt_pgtable, xen_state.pgtbl_start, + xen_state.pgtbl_end, nr_pages, + xen_state.xen_inf.virt_base, xen_state.virt_mfn_list); + + xen_state.state.entry_point = xen_state.xen_inf.entry_point; *xen_state.virt_start_info = xen_state.next_start;
@@ -348,8 +369,8 @@ grub_xen_boot (void)return grub_relocator_xen_boot (xen_state.relocator, xen_state.state, nr_pages, xen_state.xen_inf.virt_base <PAGE_SIZE ?page2offset (nr_pages) :0 , - nr_pages -1 , -page2offset (nr_pages -1 ) + + xen_state.pgtbl_end -1 , +page2offset (xen_state.pgtbl_end -1 ) + xen_state.xen_inf.virt_base); }
Signature · 7 lines
2.6.2 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Juergen Gross
maintainerPATCH v5 9/11 xen: add capability to load initrd outside of initial mapping
In reply to Juergen GrossModern pvops linux kernels support an initrd not covered by the initial mapping. This capability is flagged by an elf-note.
In case the elf-note is set by the kernel don't place the initrd into the initial mapping. This will allow to load larger initrds and/or support domains with larger memory, as the initial mapping is limited to 2GB and it is containing the p2m list.
---
V5: let call grub_xen_alloc_final() all subfunctions unconditionally
and let them decide whether they need to do anything
V4: rename grub_xen_alloc_end() to grub_xen_alloc_final()
--- grub-core/loader/i386/xen.c | 65 ++++++++++++++++++++++++++++++-------- grub-core/loader/i386/xen_fileXX.c | 3 ++ include/grub/xen_file.h | 1 + 3 files changed, 56 insertions(+), 13 deletions(-)
grub-core/loader/i386/xen.c +52 -13
@@ -228,6 +228,9 @@ grub_xen_p2m_alloc (void)grub_size_t p2msize;grub_err_t err; +if (xen_state.virt_mfn_list) +return GRUB_ERR_NONE ; + xen_state.state.mfn_list = xen_state.max_addr; xen_state.next_start.mfn_list = xen_state.max_addr + xen_state.xen_inf.virt_base;
@@ -250,6 +253,9 @@ grub_xen_special_alloc (void)grub_relocator_chunk_t ch;grub_err_t err; +if (xen_state.virt_start_info) +return GRUB_ERR_NONE ; + err =grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, xen_state.max_addr,sizeof (xen_state.next_start));
@@ -281,6 +287,9 @@ grub_xen_pt_alloc (void)grub_uint64_t nr_info_pages;grub_uint64_t nr_pages, nr_pt_pages, nr_need_pages; +if (xen_state.virt_pgtable) +return GRUB_ERR_NONE ; + xen_state.next_start.pt_base = xen_state.max_addr + xen_state.xen_inf.virt_base; xen_state.state.paging_start = xen_state.max_addr >>PAGE_SHIFT ;
@@ -320,6 +329,24 @@ grub_xen_pt_alloc (void) }static grub_err_t +grub_xen_alloc_final (void ) +{ +grub_err_t err; + + err =grub_xen_p2m_alloc (); +if (err) +return err; + err =grub_xen_special_alloc (); +if (err) +return err; + err =grub_xen_pt_alloc (); +if (err) +return err; + +return GRUB_ERR_NONE ; +} + +static grub_err_t grub_xen_boot (void ) {grub_err_t err;
@@ -330,13 +357,7 @@ grub_xen_boot (void)if (grub_xen_n_allocated_shared_pages)return grub_error (GRUB_ERR_BUG ,"active grants" ); - err =grub_xen_p2m_alloc (); -if (err) -return err; - err =grub_xen_special_alloc (); -if (err) -return err; - err =grub_xen_pt_alloc (); + err =grub_xen_alloc_final ();if (err)return err;
@@ -610,6 +631,13 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), goto fail; } +if (xen_state.xen_inf.unmapped_initrd) + { + err =grub_xen_alloc_final (); +if (err) + goto fail; + } +if (grub_initrd_init (argc, argv, &initrd_ctx)) goto fail;
@@ -627,14 +655,24 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), goto fail; } - xen_state.next_start.mod_start = - xen_state.max_addr + xen_state.xen_inf.virt_base; - xen_state.next_start.mod_len = size; - - xen_state.max_addr =ALIGN_UP (xen_state.max_addr + size,PAGE_SIZE ); +if (xen_state.xen_inf.unmapped_initrd) + { + xen_state.next_start.flags |=SIF_MOD_START_PFN ; + xen_state.next_start.mod_start = xen_state.max_addr >>PAGE_SHIFT ; + xen_state.next_start.mod_len = size; + } +else + { + xen_state.next_start.mod_start = + xen_state.max_addr + xen_state.xen_inf.virt_base; + xen_state.next_start.mod_len = size; + }grub_dprintf ("xen" ,"Initrd, addr=0x%x, size=0x%x\n" , - (unsigned ) xen_state.next_start.mod_start, (unsigned ) size); + (unsigned ) (xen_state.max_addr + xen_state.xen_inf.virt_base), + (unsigned ) size); + + xen_state.max_addr =ALIGN_UP (xen_state.max_addr + size,PAGE_SIZE ); fail:grub_initrd_close (&initrd_ctx);
@@ -686,6 +724,7 @@ grub_cmd_module (grub_command_t cmd __attribute__ ((unused)),if (!xen_state.module_info_page) { + xen_state.xen_inf.unmapped_initrd =0 ; xen_state.n_modules =0 ; xen_state.max_addr =ALIGN_UP (xen_state.max_addr,PAGE_SIZE ); xen_state.modules_target_start = xen_state.max_addr;
grub-core/loader/i386/xen_fileXX.c +3 -0
@@ -261,6 +261,9 @@ parse_note (grub_elf_t elf, struct grub_xen_file_info *xi, descsz == 2 ? 2 : 3) == 0) xi->arch =GRUB_XEN_FILE_I386 ;break ; +case XEN_ELFNOTE_MOD_START_PFN : + xi->unmapped_initrd = !!grub_le_to_cpu32 (*(grub_uint32_t *) desc); +break ;default :grub_dprintf ("xen" ,"unknown note type %d\n" , nh->n_type);break ;
include/grub/xen_file.h +1 -0
@@ -36,6 +36,7 @@ struct grub_xen_file_infoint has_note;int has_xen_guest;int extended_cr3; +int unmapped_initrd;enum {GRUB_XEN_FILE_I386 =1 ,
Signature · 7 lines
2.6.2 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v5 09/11] xen: add capability to load initrd outside of initial mapping
Quoted 60 lines · Juergen Gross
Modern pvops linux kernels support an initrd not covered by the initial mapping. This capability is flagged by an elf-note.
In case the elf-note is set by the kernel don't place the initrd into the initial mapping. This will allow to load larger initrds and/or support domains with larger memory, as the initial mapping is limited to 2GB and it is containing the p2m list.
Signed-off-by Juergen Gross <[email protected]>---
V5: let callgrub_xen_alloc_final()all subfunctions unconditionally
and let them decide whether they need to do anything
V4: renamegrub_xen_alloc_end()togrub_xen_alloc_final()--- grub-core/loader/i386/xen.c | 65 ++++++++++++++++++++++++++++++-------- grub-core/loader/i386/xen_fileXX.c | 3 ++ include/grub/xen_file.h | 1 + 3 files changed, 56 insertions(+), 13 deletions(-)grub-core/loader/i386/xen.c +12
-0@@ -228,6 +228,9 @@ grub_xen_p2m_alloc (void)grub_size_t p2msize;grub_err_t err; +if (xen_state.virt_mfn_list) +return GRUB_ERR_NONE ; + xen_state.state.mfn_list = xen_state.max_addr; xen_state.next_start.mfn_list = xen_state.max_addr + xen_state.xen_inf.virt_base;@@ -250,6 +253,9 @@ grub_xen_special_alloc (void)grub_relocator_chunk_t ch;grub_err_t err; +if (xen_state.virt_start_info) +return GRUB_ERR_NONE ; + err =grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, xen_state.max_addr,sizeof (xen_state.next_start));@@ -281,6 +287,9 @@ grub_xen_pt_alloc (void)grub_uint64_t nr_info_pages;grub_uint64_t nr_pages, nr_pt_pages, nr_need_pages; +if (xen_state.virt_pgtable) +return GRUB_ERR_NONE ; + xen_state.next_start.pt_base = xen_state.max_addr + xen_state.xen_inf.virt_base; xen_state.state.paging_start = xen_state.max_addr >>PAGE_SHIFT ;@@ -320,6 +329,24 @@ grub_xen_pt_alloc (void) }static grub_err_t +grub_xen_alloc_final (void ) +{ +grub_err_t err;
grub-core/loader/i386/xen.c grub_xen_pt_alloc (void) · line 344
Quoted 10 lines
grub-core/loader/i386/xen.c +10
-0+ + err =grub_xen_p2m_alloc (); +if (err) +return err; + err =grub_xen_special_alloc (); +if (err) +return err; + err =grub_xen_pt_alloc (); +if (err) +return err;
Could you move grub_xen_p2m_alloc() here? This way grub_xen_alloc_final() will be real final in patch 11 and you do not need an extra condition around grub_xen_p2m_alloc().
Quoted 10 lines
grub-core/loader/i386/xen.c +5
-0+ +return GRUB_ERR_NONE ; +} + +static grub_err_t grub_xen_boot (void ) {grub_err_t err;@@ -330,13 +357,7 @@ grub_xen_boot (void)if (grub_xen_n_allocated_shared_pages)
grub-core/loader/i386/xen.c grub_xen_boot (void) · line 360
Quoted 10 lines
grub-core/loader/i386/xen.c +1
-7return grub_error (GRUB_ERR_BUG ,"active grants" ); - err =grub_xen_p2m_alloc (); -if (err) -return err; - err =grub_xen_special_alloc (); -if (err) -return err; - err =grub_xen_pt_alloc (); + err =grub_xen_alloc_final ();
if (!xen_state.xen_inf.unmapped_initrd)
{
err = grub_xen_alloc_final ();
if (err)
goto fail;}
This way you avoid checks in grub_xen_p2m_alloc(), grub_xen_special_alloc() and grub_xen_pt_alloc().
Quoted 18 lines
grub-core/loader/i386/xen.c +7
-0if (err)return err;@@ -610,6 +631,13 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), goto fail; } +if (xen_state.xen_inf.unmapped_initrd) + { + err =grub_xen_alloc_final (); +if (err) + goto fail; + } +if (grub_initrd_init (argc, argv, &initrd_ctx)) goto fail;
grub-core/loader/i386/xen.c grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), · line 632
Quoted 6 lines
grub-core/loader/i386/xen.c +0
-3@@ -627,14 +655,24 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), goto fail; } - xen_state.next_start.mod_start = - xen_state.max_addr + xen_state.xen_inf.virt_base; - xen_state.next_start.mod_len = size;
Leave "xen_state.next_start.mod_len = size;" as is here and...
grub-core/loader/i386/xen.c grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), · line 662
Quoted 7 lines
grub-core/loader/i386/xen.c +5
-2- - xen_state.max_addr =ALIGN_UP (xen_state.max_addr + size,PAGE_SIZE ); +if (xen_state.xen_inf.unmapped_initrd) + { + xen_state.next_start.flags |=SIF_MOD_START_PFN ; + xen_state.next_start.mod_start = xen_state.max_addr >>PAGE_SHIFT ; + xen_state.next_start.mod_len = size;
... do not add it here...
grub-core/loader/i386/xen.c grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), · line 668
Quoted 6 lines
grub-core/loader/i386/xen.c +6
-0+ } +else + { + xen_state.next_start.mod_start = + xen_state.max_addr + xen_state.xen_inf.virt_base; + xen_state.next_start.mod_len = size;
... and here...
grub-core/loader/i386/xen.c grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), · line 669
Quoted 1 line
grub-core/loader/i386/xen.c +1
-0+ }
... and you do not need curly brackets then.
grub-core/loader/i386/xen.c grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), · line 673
Quoted 4 lines
grub-core/loader/i386/xen.c +2
-1grub_dprintf ("xen" ,"Initrd, addr=0x%x, size=0x%x\n" , - (unsigned ) xen_state.next_start.mod_start, (unsigned ) size); + (unsigned ) (xen_state.max_addr + xen_state.xen_inf.virt_base), + (unsigned ) size);
This should be printed only if !xen_state.xen_inf.unmapped_initrd. Why do not use xen_state.next_start.mod_start here?
Daniel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v5 09/11] xen: add capability to load initrd outside of initial mapping
In reply to Juergen GrossQuoted 60 lines · Juergen Gross
Modern pvops linux kernels support an initrd not covered by the initial mapping. This capability is flagged by an elf-note.
In case the elf-note is set by the kernel don't place the initrd into the initial mapping. This will allow to load larger initrds and/or support domains with larger memory, as the initial mapping is limited to 2GB and it is containing the p2m list.
Signed-off-by Juergen Gross <[email protected]>---
V5: let callgrub_xen_alloc_final()all subfunctions unconditionally
and let them decide whether they need to do anything
V4: renamegrub_xen_alloc_end()togrub_xen_alloc_final()--- grub-core/loader/i386/xen.c | 65 ++++++++++++++++++++++++++++++-------- grub-core/loader/i386/xen_fileXX.c | 3 ++ include/grub/xen_file.h | 1 + 3 files changed, 56 insertions(+), 13 deletions(-)grub-core/loader/i386/xen.c +12
-0@@ -228,6 +228,9 @@ grub_xen_p2m_alloc (void)grub_size_t p2msize;grub_err_t err; +if (xen_state.virt_mfn_list) +return GRUB_ERR_NONE ; + xen_state.state.mfn_list = xen_state.max_addr; xen_state.next_start.mfn_list = xen_state.max_addr + xen_state.xen_inf.virt_base;@@ -250,6 +253,9 @@ grub_xen_special_alloc (void)grub_relocator_chunk_t ch;grub_err_t err; +if (xen_state.virt_start_info) +return GRUB_ERR_NONE ; + err =grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, xen_state.max_addr,sizeof (xen_state.next_start));@@ -281,6 +287,9 @@ grub_xen_pt_alloc (void)grub_uint64_t nr_info_pages;grub_uint64_t nr_pages, nr_pt_pages, nr_need_pages; +if (xen_state.virt_pgtable) +return GRUB_ERR_NONE ; + xen_state.next_start.pt_base = xen_state.max_addr + xen_state.xen_inf.virt_base; xen_state.state.paging_start = xen_state.max_addr >>PAGE_SHIFT ;@@ -320,6 +329,24 @@ grub_xen_pt_alloc (void) }static grub_err_t +grub_xen_alloc_final (void ) +{ +grub_err_t err;
grub-core/loader/i386/xen.c grub_xen_pt_alloc (void) · line 344
Quoted 10 lines
grub-core/loader/i386/xen.c +10
-0+ + err =grub_xen_p2m_alloc (); +if (err) +return err; + err =grub_xen_special_alloc (); +if (err) +return err; + err =grub_xen_pt_alloc (); +if (err) +return err;
Could you move grub_xen_p2m_alloc() here? This way grub_xen_alloc_final() will be real final in patch 11 and you do not need an extra condition around grub_xen_p2m_alloc().
Quoted 10 lines
grub-core/loader/i386/xen.c +5
-0+ +return GRUB_ERR_NONE ; +} + +static grub_err_t grub_xen_boot (void ) {grub_err_t err;@@ -330,13 +357,7 @@ grub_xen_boot (void)if (grub_xen_n_allocated_shared_pages)
grub-core/loader/i386/xen.c grub_xen_boot (void) · line 360
Quoted 10 lines
grub-core/loader/i386/xen.c +1
-7return grub_error (GRUB_ERR_BUG ,"active grants" ); - err =grub_xen_p2m_alloc (); -if (err) -return err; - err =grub_xen_special_alloc (); -if (err) -return err; - err =grub_xen_pt_alloc (); + err =grub_xen_alloc_final ();
if (!xen_state.xen_inf.unmapped_initrd)
{
err = grub_xen_alloc_final ();
if (err)
goto fail;}
This way you avoid checks in grub_xen_p2m_alloc(), grub_xen_special_alloc() and grub_xen_pt_alloc().
Quoted 18 lines
grub-core/loader/i386/xen.c +7
-0if (err)return err;@@ -610,6 +631,13 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), goto fail; } +if (xen_state.xen_inf.unmapped_initrd) + { + err =grub_xen_alloc_final (); +if (err) + goto fail; + } +if (grub_initrd_init (argc, argv, &initrd_ctx)) goto fail;
grub-core/loader/i386/xen.c grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), · line 632
Quoted 6 lines
grub-core/loader/i386/xen.c +0
-3@@ -627,14 +655,24 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), goto fail; } - xen_state.next_start.mod_start = - xen_state.max_addr + xen_state.xen_inf.virt_base; - xen_state.next_start.mod_len = size;
Leave "xen_state.next_start.mod_len = size;" as is here and...
grub-core/loader/i386/xen.c grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), · line 662
Quoted 7 lines
grub-core/loader/i386/xen.c +5
-2- - xen_state.max_addr =ALIGN_UP (xen_state.max_addr + size,PAGE_SIZE ); +if (xen_state.xen_inf.unmapped_initrd) + { + xen_state.next_start.flags |=SIF_MOD_START_PFN ; + xen_state.next_start.mod_start = xen_state.max_addr >>PAGE_SHIFT ; + xen_state.next_start.mod_len = size;
... do not add it here...
grub-core/loader/i386/xen.c grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), · line 668
Quoted 6 lines
grub-core/loader/i386/xen.c +6
-0+ } +else + { + xen_state.next_start.mod_start = + xen_state.max_addr + xen_state.xen_inf.virt_base; + xen_state.next_start.mod_len = size;
... and here...
grub-core/loader/i386/xen.c grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), · line 669
Quoted 1 line
grub-core/loader/i386/xen.c +1
-0+ }
... and you do not need curly brackets then.
grub-core/loader/i386/xen.c grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), · line 673
Quoted 4 lines
grub-core/loader/i386/xen.c +2
-1grub_dprintf ("xen" ,"Initrd, addr=0x%x, size=0x%x\n" , - (unsigned ) xen_state.next_start.mod_start, (unsigned ) size); + (unsigned ) (xen_state.max_addr + xen_state.xen_inf.virt_base), + (unsigned ) size);
This should be printed only if !xen_state.xen_inf.unmapped_initrd. Why do not use xen_state.next_start.mod_start here?
Daniel
Juergen Gross
maintainerRe: [PATCH v5 09/11] xen: add capability to load initrd outside of initial mapping
Quoted 67 lines · Daniel Kiper
Quoted 66 lines · Juergen Gross
Modern pvops linux kernels support an initrd not covered by the initial mapping. This capability is flagged by an elf-note.
In case the elf-note is set by the kernel don't place the initrd into the initial mapping. This will allow to load larger initrds and/or support domains with larger memory, as the initial mapping is limited to 2GB and it is containing the p2m list.
Signed-off-by Juergen Gross <[email protected]>---
V5: let callgrub_xen_alloc_final()all subfunctions unconditionally
and let them decide whether they need to do anything
V4: renamegrub_xen_alloc_end()togrub_xen_alloc_final()--- grub-core/loader/i386/xen.c | 65 ++++++++++++++++++++++++++++++-------- grub-core/loader/i386/xen_fileXX.c | 3 ++ include/grub/xen_file.h | 1 + 3 files changed, 56 insertions(+), 13 deletions(-)grub-core/loader/i386/xen.c +18
-0@@ -228,6 +228,9 @@ grub_xen_p2m_alloc (void)grub_size_t p2msize;grub_err_t err; +if (xen_state.virt_mfn_list) +return GRUB_ERR_NONE ; + xen_state.state.mfn_list = xen_state.max_addr; xen_state.next_start.mfn_list = xen_state.max_addr + xen_state.xen_inf.virt_base;@@ -250,6 +253,9 @@ grub_xen_special_alloc (void)grub_relocator_chunk_t ch;grub_err_t err; +if (xen_state.virt_start_info) +return GRUB_ERR_NONE ; + err =grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, xen_state.max_addr,sizeof (xen_state.next_start));@@ -281,6 +287,9 @@ grub_xen_pt_alloc (void)grub_uint64_t nr_info_pages;grub_uint64_t nr_pages, nr_pt_pages, nr_need_pages; +if (xen_state.virt_pgtable) +return GRUB_ERR_NONE ; + xen_state.next_start.pt_base = xen_state.max_addr + xen_state.xen_inf.virt_base; xen_state.state.paging_start = xen_state.max_addr >>PAGE_SHIFT ;@@ -320,6 +329,24 @@ grub_xen_pt_alloc (void) }static grub_err_t +grub_xen_alloc_final (void ) +{ +grub_err_t err; + + err =grub_xen_p2m_alloc (); +if (err) +return err; + err =grub_xen_special_alloc (); +if (err)
Quoted 8 lines
grub-core/loader/i386/xen.c grub_xen_pt_alloc (void) · line 344
Quoted 4 lines
grub-core/loader/i386/xen.c +4
-0+return err; + err =grub_xen_pt_alloc (); +if (err) +return err;Could you move
grub_xen_p2m_alloc()here? This waygrub_xen_alloc_final()will be real final in patch 11 and you do not need an extra condition aroundgrub_xen_p2m_alloc().
No. Page tables must be allocated after p2m unless p2m is outside of initial kernel mapping (patch 11).
Quoted 23 lines
Quoted 11 lines
grub-core/loader/i386/xen.c +5
-0+ +return GRUB_ERR_NONE ; +} + +static grub_err_t grub_xen_boot (void ) {grub_err_t err;@@ -330,13 +357,7 @@ grub_xen_boot (void)if (grub_xen_n_allocated_shared_pages)grub-core/loader/i386/xen.c grub_xen_boot (void) · line 360
Quoted 10 lines
grub-core/loader/i386/xen.c +1
-7return grub_error (GRUB_ERR_BUG ,"active grants" ); - err =grub_xen_p2m_alloc (); -if (err) -return err; - err =grub_xen_special_alloc (); -if (err) -return err; - err =grub_xen_pt_alloc (); + err =grub_xen_alloc_final ();if (!xen_state.xen_inf.unmapped_initrd)
Quoted 8 lines
{ err = grub_xen_alloc_final (); if (err) goto fail;}
This way you avoid checks in
grub_xen_p2m_alloc(),grub_xen_special_alloc()andgrub_xen_pt_alloc().
No. In case there is no initrd, but the kernel does support an unmapped initrd, I would omit allocating special pages, p2m and page tables.
Quoted 47 lines
Quoted 19 lines
grub-core/loader/i386/xen.c +7
-0if (err)return err;@@ -610,6 +631,13 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), goto fail; } +if (xen_state.xen_inf.unmapped_initrd) + { + err =grub_xen_alloc_final (); +if (err) + goto fail; + } +if (grub_initrd_init (argc, argv, &initrd_ctx)) goto fail;grub-core/loader/i386/xen.c grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), · line 632
Quoted 6 lines
grub-core/loader/i386/xen.c +0
-3@@ -627,14 +655,24 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), goto fail; } - xen_state.next_start.mod_start = - xen_state.max_addr + xen_state.xen_inf.virt_base; - xen_state.next_start.mod_len = size;Leave "xen_state.next_start.mod_len = size;" as is here and...
grub-core/loader/i386/xen.c grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), · line 662
Quoted 7 lines
grub-core/loader/i386/xen.c +5
-2- - xen_state.max_addr =ALIGN_UP (xen_state.max_addr + size,PAGE_SIZE ); +if (xen_state.xen_inf.unmapped_initrd) + { + xen_state.next_start.flags |=SIF_MOD_START_PFN ; + xen_state.next_start.mod_start = xen_state.max_addr >>PAGE_SHIFT ; + xen_state.next_start.mod_len = size;... do not add it here...
grub-core/loader/i386/xen.c grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), · line 668
Quoted 6 lines
grub-core/loader/i386/xen.c +6
-0+ } +else + { + xen_state.next_start.mod_start = + xen_state.max_addr + xen_state.xen_inf.virt_base; + xen_state.next_start.mod_len = size;... and here...
Quoted 3 lines
grub-core/loader/i386/xen.c grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), · line 669
Quoted 1 line
grub-core/loader/i386/xen.c +1
-0+ }... and you do not need curly brackets then.
I still do, as in the "if" part I still have two statements.
Quoted 7 lines
grub-core/loader/i386/xen.c grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), · line 673
Quoted 5 lines
grub-core/loader/i386/xen.c +2
-1grub_dprintf ("xen" ,"Initrd, addr=0x%x, size=0x%x\n" , - (unsigned ) xen_state.next_start.mod_start, (unsigned ) size); + (unsigned ) (xen_state.max_addr + xen_state.xen_inf.virt_base), + (unsigned ) size);This should be printed only if !xen_state.xen_inf.unmapped_initrd.
Really? Why? We still have an initrd.
Quoted 1 line
Why do not use xen_state.next_start.mod_start here?
It is the pfn in case of unmapped_initrd.
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Juergen Gross
maintainerRe: [PATCH v5 09/11] xen: add capability to load initrd outside of initial mapping
In reply to Daniel KiperQuoted 67 lines · Daniel Kiper
Quoted 66 lines · Juergen Gross
Modern pvops linux kernels support an initrd not covered by the initial mapping. This capability is flagged by an elf-note.
In case the elf-note is set by the kernel don't place the initrd into the initial mapping. This will allow to load larger initrds and/or support domains with larger memory, as the initial mapping is limited to 2GB and it is containing the p2m list.
Signed-off-by Juergen Gross <[email protected]>---
V5: let callgrub_xen_alloc_final()all subfunctions unconditionally
and let them decide whether they need to do anything
V4: renamegrub_xen_alloc_end()togrub_xen_alloc_final()--- grub-core/loader/i386/xen.c | 65 ++++++++++++++++++++++++++++++-------- grub-core/loader/i386/xen_fileXX.c | 3 ++ include/grub/xen_file.h | 1 + 3 files changed, 56 insertions(+), 13 deletions(-)grub-core/loader/i386/xen.c +18
-0@@ -228,6 +228,9 @@ grub_xen_p2m_alloc (void)grub_size_t p2msize;grub_err_t err; +if (xen_state.virt_mfn_list) +return GRUB_ERR_NONE ; + xen_state.state.mfn_list = xen_state.max_addr; xen_state.next_start.mfn_list = xen_state.max_addr + xen_state.xen_inf.virt_base;@@ -250,6 +253,9 @@ grub_xen_special_alloc (void)grub_relocator_chunk_t ch;grub_err_t err; +if (xen_state.virt_start_info) +return GRUB_ERR_NONE ; + err =grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, xen_state.max_addr,sizeof (xen_state.next_start));@@ -281,6 +287,9 @@ grub_xen_pt_alloc (void)grub_uint64_t nr_info_pages;grub_uint64_t nr_pages, nr_pt_pages, nr_need_pages; +if (xen_state.virt_pgtable) +return GRUB_ERR_NONE ; + xen_state.next_start.pt_base = xen_state.max_addr + xen_state.xen_inf.virt_base; xen_state.state.paging_start = xen_state.max_addr >>PAGE_SHIFT ;@@ -320,6 +329,24 @@ grub_xen_pt_alloc (void) }static grub_err_t +grub_xen_alloc_final (void ) +{ +grub_err_t err; + + err =grub_xen_p2m_alloc (); +if (err) +return err; + err =grub_xen_special_alloc (); +if (err)
Quoted 8 lines
grub-core/loader/i386/xen.c grub_xen_pt_alloc (void) · line 344
Quoted 4 lines
grub-core/loader/i386/xen.c +4
-0+return err; + err =grub_xen_pt_alloc (); +if (err) +return err;Could you move
grub_xen_p2m_alloc()here? This waygrub_xen_alloc_final()will be real final in patch 11 and you do not need an extra condition aroundgrub_xen_p2m_alloc().
No. Page tables must be allocated after p2m unless p2m is outside of initial kernel mapping (patch 11).
Quoted 23 lines
Quoted 11 lines
grub-core/loader/i386/xen.c +5
-0+ +return GRUB_ERR_NONE ; +} + +static grub_err_t grub_xen_boot (void ) {grub_err_t err;@@ -330,13 +357,7 @@ grub_xen_boot (void)if (grub_xen_n_allocated_shared_pages)grub-core/loader/i386/xen.c grub_xen_boot (void) · line 360
Quoted 10 lines
grub-core/loader/i386/xen.c +1
-7return grub_error (GRUB_ERR_BUG ,"active grants" ); - err =grub_xen_p2m_alloc (); -if (err) -return err; - err =grub_xen_special_alloc (); -if (err) -return err; - err =grub_xen_pt_alloc (); + err =grub_xen_alloc_final ();if (!xen_state.xen_inf.unmapped_initrd)
Quoted 8 lines
{ err = grub_xen_alloc_final (); if (err) goto fail;}
This way you avoid checks in
grub_xen_p2m_alloc(),grub_xen_special_alloc()andgrub_xen_pt_alloc().
No. In case there is no initrd, but the kernel does support an unmapped initrd, I would omit allocating special pages, p2m and page tables.
Quoted 47 lines
Quoted 19 lines
grub-core/loader/i386/xen.c +7
-0if (err)return err;@@ -610,6 +631,13 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), goto fail; } +if (xen_state.xen_inf.unmapped_initrd) + { + err =grub_xen_alloc_final (); +if (err) + goto fail; + } +if (grub_initrd_init (argc, argv, &initrd_ctx)) goto fail;grub-core/loader/i386/xen.c grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), · line 632
Quoted 6 lines
grub-core/loader/i386/xen.c +0
-3@@ -627,14 +655,24 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), goto fail; } - xen_state.next_start.mod_start = - xen_state.max_addr + xen_state.xen_inf.virt_base; - xen_state.next_start.mod_len = size;Leave "xen_state.next_start.mod_len = size;" as is here and...
grub-core/loader/i386/xen.c grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), · line 662
Quoted 7 lines
grub-core/loader/i386/xen.c +5
-2- - xen_state.max_addr =ALIGN_UP (xen_state.max_addr + size,PAGE_SIZE ); +if (xen_state.xen_inf.unmapped_initrd) + { + xen_state.next_start.flags |=SIF_MOD_START_PFN ; + xen_state.next_start.mod_start = xen_state.max_addr >>PAGE_SHIFT ; + xen_state.next_start.mod_len = size;... do not add it here...
grub-core/loader/i386/xen.c grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), · line 668
Quoted 6 lines
grub-core/loader/i386/xen.c +6
-0+ } +else + { + xen_state.next_start.mod_start = + xen_state.max_addr + xen_state.xen_inf.virt_base; + xen_state.next_start.mod_len = size;... and here...
Quoted 3 lines
grub-core/loader/i386/xen.c grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), · line 669
Quoted 1 line
grub-core/loader/i386/xen.c +1
-0+ }... and you do not need curly brackets then.
I still do, as in the "if" part I still have two statements.
Quoted 7 lines
grub-core/loader/i386/xen.c grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), · line 673
Quoted 5 lines
grub-core/loader/i386/xen.c +2
-1grub_dprintf ("xen" ,"Initrd, addr=0x%x, size=0x%x\n" , - (unsigned ) xen_state.next_start.mod_start, (unsigned ) size); + (unsigned ) (xen_state.max_addr + xen_state.xen_inf.virt_base), + (unsigned ) size);This should be printed only if !xen_state.xen_inf.unmapped_initrd.
Really? Why? We still have an initrd.
Quoted 1 line
Why do not use xen_state.next_start.mod_start here?
It is the pfn in case of unmapped_initrd.
Juergen
Re: [PATCH v5 09/11] xen: add capability to load initrd outside of initial mapping
Quoted 77 lines · Juergen Gross
Quoted 67 lines · Daniel Kiper
Quoted 66 lines · Juergen Gross
Modern pvops linux kernels support an initrd not covered by the initial mapping. This capability is flagged by an elf-note.
In case the elf-note is set by the kernel don't place the initrd into the initial mapping. This will allow to load larger initrds and/or support domains with larger memory, as the initial mapping is limited to 2GB and it is containing the p2m list.
Signed-off-by Juergen Gross <[email protected]>---
V5: let callgrub_xen_alloc_final()all subfunctions unconditionally
and let them decide whether they need to do anything
V4: renamegrub_xen_alloc_end()togrub_xen_alloc_final()--- grub-core/loader/i386/xen.c | 65 ++++++++++++++++++++++++++++++-------- grub-core/loader/i386/xen_fileXX.c | 3 ++ include/grub/xen_file.h | 1 + 3 files changed, 56 insertions(+), 13 deletions(-)grub-core/loader/i386/xen.c +18
-0@@ -228,6 +228,9 @@ grub_xen_p2m_alloc (void)grub_size_t p2msize;grub_err_t err; +if (xen_state.virt_mfn_list) +return GRUB_ERR_NONE ; + xen_state.state.mfn_list = xen_state.max_addr; xen_state.next_start.mfn_list = xen_state.max_addr + xen_state.xen_inf.virt_base;@@ -250,6 +253,9 @@ grub_xen_special_alloc (void)grub_relocator_chunk_t ch;grub_err_t err; +if (xen_state.virt_start_info) +return GRUB_ERR_NONE ; + err =grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, xen_state.max_addr,sizeof (xen_state.next_start));@@ -281,6 +287,9 @@ grub_xen_pt_alloc (void)grub_uint64_t nr_info_pages;grub_uint64_t nr_pages, nr_pt_pages, nr_need_pages; +if (xen_state.virt_pgtable) +return GRUB_ERR_NONE ; + xen_state.next_start.pt_base = xen_state.max_addr + xen_state.xen_inf.virt_base; xen_state.state.paging_start = xen_state.max_addr >>PAGE_SHIFT ;@@ -320,6 +329,24 @@ grub_xen_pt_alloc (void) }static grub_err_t +grub_xen_alloc_final (void ) +{ +grub_err_t err; + + err =grub_xen_p2m_alloc (); +if (err) +return err; + err =grub_xen_special_alloc (); +if (err)Quoted 8 lines
grub-core/loader/i386/xen.c grub_xen_pt_alloc (void) · line 344
Quoted 4 lines
grub-core/loader/i386/xen.c +4
-0+return err; + err =grub_xen_pt_alloc (); +if (err) +return err;Could you move
grub_xen_p2m_alloc()here? This waygrub_xen_alloc_final()will be real final in patch 11 and you do not need an extra condition aroundgrub_xen_p2m_alloc().
Quoted 2 lines
No. Page tables must be allocated after p2m unless p2m is outside of initial kernel mapping (patch 11).
OK, I was afraid of that. However, then grub_xen_alloc_final() is not final. So, maybe it should be called grub_xen_alloc_boot_data() or something like that.
Quoted 27 lines
Quoted 27 lines
Quoted 9 lines
grub-core/loader/i386/xen.c +4
-0+return GRUB_ERR_NONE ; +} + +static grub_err_t grub_xen_boot (void ) {grub_err_t err;@@ -330,13 +357,7 @@ grub_xen_boot (void)if (grub_xen_n_allocated_shared_pages)grub-core/loader/i386/xen.c grub_xen_boot (void) · line 360
Quoted 10 lines
grub-core/loader/i386/xen.c +1
-7return grub_error (GRUB_ERR_BUG ,"active grants" ); - err =grub_xen_p2m_alloc (); -if (err) -return err; - err =grub_xen_special_alloc (); -if (err) -return err; - err =grub_xen_pt_alloc (); + err =grub_xen_alloc_final ();if (!xen_state.xen_inf.unmapped_initrd)
{ err = grub_xen_alloc_final (); if (err) goto fail;}
Quoted 5 lines
Quoted 2 lines
This way you avoid checks in
grub_xen_p2m_alloc(),grub_xen_special_alloc()andgrub_xen_pt_alloc().No. In case there is no initrd, but the kernel does support an unmapped initrd, I would omit allocating special pages, p2m and page tables.
Ups... I have missed that.
Quoted 46 lines
Quoted 46 lines
Quoted 18 lines
grub-core/loader/i386/xen.c +7
-0if (err)return err;@@ -610,6 +631,13 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), goto fail; } +if (xen_state.xen_inf.unmapped_initrd) + { + err =grub_xen_alloc_final (); +if (err) + goto fail; + } +if (grub_initrd_init (argc, argv, &initrd_ctx)) goto fail;grub-core/loader/i386/xen.c grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), · line 632
Quoted 6 lines
grub-core/loader/i386/xen.c +0
-3@@ -627,14 +655,24 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), goto fail; } - xen_state.next_start.mod_start = - xen_state.max_addr + xen_state.xen_inf.virt_base; - xen_state.next_start.mod_len = size;Leave "xen_state.next_start.mod_len = size;" as is here and...
grub-core/loader/i386/xen.c grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), · line 662
Quoted 7 lines
grub-core/loader/i386/xen.c +5
-2- - xen_state.max_addr =ALIGN_UP (xen_state.max_addr + size,PAGE_SIZE ); +if (xen_state.xen_inf.unmapped_initrd) + { + xen_state.next_start.flags |=SIF_MOD_START_PFN ; + xen_state.next_start.mod_start = xen_state.max_addr >>PAGE_SHIFT ; + xen_state.next_start.mod_len = size;... do not add it here...
grub-core/loader/i386/xen.c grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), · line 668
Quoted 6 lines
grub-core/loader/i386/xen.c +6
-0+ } +else + { + xen_state.next_start.mod_start = + xen_state.max_addr + xen_state.xen_inf.virt_base; + xen_state.next_start.mod_len = size;... and here...
Quoted 5 lines
Quoted 3 lines
grub-core/loader/i386/xen.c grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), · line 669
Quoted 1 line
grub-core/loader/i386/xen.c +1
-0+ }... and you do not need curly brackets then.
I still do, as in the "if" part I still have two statements.
Yep, but else stuff does not need one.
Quoted 7 lines
Quoted 6 lines
grub-core/loader/i386/xen.c grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), · line 673
Quoted 4 lines
grub-core/loader/i386/xen.c +2
-1grub_dprintf ("xen" ,"Initrd, addr=0x%x, size=0x%x\n" , - (unsigned ) xen_state.next_start.mod_start, (unsigned ) size); + (unsigned ) (xen_state.max_addr + xen_state.xen_inf.virt_base), + (unsigned ) size);This should be printed only if !xen_state.xen_inf.unmapped_initrd.
Quoted 5 lines
Really? Why? We still have an initrd.
Quoted 1 line
Why do not use xen_state.next_start.mod_start here?
It is the pfn in case of
unmapped_initrd.
Errr... I have looked at wrong line. Sorry about that.
Daniel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Juergen Gross
maintainerRe: [PATCH v5 09/11] xen: add capability to load initrd outside of initial mapping
Quoted 78 lines · Daniel Kiper
Quoted 77 lines · Juergen Gross
Quoted 75 lines · Daniel Kiper
Quoted 60 lines · Juergen Gross
Modern pvops linux kernels support an initrd not covered by the initial mapping. This capability is flagged by an elf-note.
In case the elf-note is set by the kernel don't place the initrd into the initial mapping. This will allow to load larger initrds and/or support domains with larger memory, as the initial mapping is limited to 2GB and it is containing the p2m list.
Signed-off-by Juergen Gross <[email protected]>---
V5: let callgrub_xen_alloc_final()all subfunctions unconditionally
and let them decide whether they need to do anything
V4: renamegrub_xen_alloc_end()togrub_xen_alloc_final()--- grub-core/loader/i386/xen.c | 65 ++++++++++++++++++++++++++++++-------- grub-core/loader/i386/xen_fileXX.c | 3 ++ include/grub/xen_file.h | 1 + 3 files changed, 56 insertions(+), 13 deletions(-)grub-core/loader/i386/xen.c +12
-0@@ -228,6 +228,9 @@ grub_xen_p2m_alloc (void)grub_size_t p2msize;grub_err_t err; +if (xen_state.virt_mfn_list) +return GRUB_ERR_NONE ; + xen_state.state.mfn_list = xen_state.max_addr; xen_state.next_start.mfn_list = xen_state.max_addr + xen_state.xen_inf.virt_base;@@ -250,6 +253,9 @@ grub_xen_special_alloc (void)grub_relocator_chunk_t ch;grub_err_t err; +if (xen_state.virt_start_info) +return GRUB_ERR_NONE ; + err =grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, xen_state.max_addr,sizeof (xen_state.next_start));@@ -281,6 +287,9 @@ grub_xen_pt_alloc (void)grub_uint64_t nr_info_pages;grub_uint64_t nr_pages, nr_pt_pages, nr_need_pages; +if (xen_state.virt_pgtable) +return GRUB_ERR_NONE ; + xen_state.next_start.pt_base = xen_state.max_addr + xen_state.xen_inf.virt_base; xen_state.state.paging_start = xen_state.max_addr >>PAGE_SHIFT ;@@ -320,6 +329,24 @@ grub_xen_pt_alloc (void) }static grub_err_t +grub_xen_alloc_final (void ) +{ +grub_err_t err;grub-core/loader/i386/xen.c grub_xen_pt_alloc (void) · line 344
Quoted 10 lines
grub-core/loader/i386/xen.c +10
-0+ + err =grub_xen_p2m_alloc (); +if (err) +return err; + err =grub_xen_special_alloc (); +if (err) +return err; + err =grub_xen_pt_alloc (); +if (err) +return err;Could you move
grub_xen_p2m_alloc()here? This waygrub_xen_alloc_final()will be real final in patch 11 and you do not need an extra condition aroundgrub_xen_p2m_alloc().
Quoted 4 lines
Quoted 2 lines
No. Page tables must be allocated after p2m unless p2m is outside of initial kernel mapping (patch 11).
OK, I was afraid of that. However, then
grub_xen_alloc_final()is not final.
Sure it is. Patch 11 just adds allocation to grub_xen_alloc_final(), not after it.
Quoted 83 lines
So, maybe it should be called
grub_xen_alloc_boot_data()or something like that.Quoted 27 lines
Quoted 27 lines
Quoted 9 lines
grub-core/loader/i386/xen.c +4
-0+return GRUB_ERR_NONE ; +} + +static grub_err_t grub_xen_boot (void ) {grub_err_t err;@@ -330,13 +357,7 @@ grub_xen_boot (void)if (grub_xen_n_allocated_shared_pages)grub-core/loader/i386/xen.c grub_xen_boot (void) · line 360
Quoted 10 lines
grub-core/loader/i386/xen.c +1
-7return grub_error (GRUB_ERR_BUG ,"active grants" ); - err =grub_xen_p2m_alloc (); -if (err) -return err; - err =grub_xen_special_alloc (); -if (err) -return err; - err =grub_xen_pt_alloc (); + err =grub_xen_alloc_final ();if (!xen_state.xen_inf.unmapped_initrd)
{ err = grub_xen_alloc_final (); if (err) goto fail;}
Quoted 5 lines
Quoted 2 lines
This way you avoid checks in
grub_xen_p2m_alloc(),grub_xen_special_alloc()andgrub_xen_pt_alloc().No. In case there is no initrd, but the kernel does support an unmapped initrd, I would omit allocating special pages, p2m and page tables.
Ups... I have missed that.
Quoted 46 lines
Quoted 46 lines
Quoted 18 lines
grub-core/loader/i386/xen.c +7
-0if (err)return err;@@ -610,6 +631,13 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), goto fail; } +if (xen_state.xen_inf.unmapped_initrd) + { + err =grub_xen_alloc_final (); +if (err) + goto fail; + } +if (grub_initrd_init (argc, argv, &initrd_ctx)) goto fail;grub-core/loader/i386/xen.c grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), · line 632
Quoted 6 lines
grub-core/loader/i386/xen.c +0
-3@@ -627,14 +655,24 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), goto fail; } - xen_state.next_start.mod_start = - xen_state.max_addr + xen_state.xen_inf.virt_base; - xen_state.next_start.mod_len = size;Leave "xen_state.next_start.mod_len = size;" as is here and...
grub-core/loader/i386/xen.c grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), · line 662
Quoted 7 lines
grub-core/loader/i386/xen.c +5
-2- - xen_state.max_addr =ALIGN_UP (xen_state.max_addr + size,PAGE_SIZE ); +if (xen_state.xen_inf.unmapped_initrd) + { + xen_state.next_start.flags |=SIF_MOD_START_PFN ; + xen_state.next_start.mod_start = xen_state.max_addr >>PAGE_SHIFT ; + xen_state.next_start.mod_len = size;... do not add it here...
grub-core/loader/i386/xen.c grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), · line 668
Quoted 6 lines
grub-core/loader/i386/xen.c +6
-0+ } +else + { + xen_state.next_start.mod_start = + xen_state.max_addr + xen_state.xen_inf.virt_base; + xen_state.next_start.mod_len = size;... and here...
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
grub-core/loader/i386/xen.c grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), · line 669
Quoted 1 line
grub-core/loader/i386/xen.c +1
-0+ }... and you do not need curly brackets then.
I still do, as in the "if" part I still have two statements.
Yep, but else stuff does not need one.
Ah, okay. Too many different coding styles. Linux kernel would keep the braces.
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
grub-core/loader/i386/xen.c grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), · line 673
Quoted 5 lines
grub-core/loader/i386/xen.c +2
-1grub_dprintf ("xen" ,"Initrd, addr=0x%x, size=0x%x\n" , - (unsigned ) xen_state.next_start.mod_start, (unsigned ) size); + (unsigned ) (xen_state.max_addr + xen_state.xen_inf.virt_base), + (unsigned ) size);This should be printed only if !xen_state.xen_inf.unmapped_initrd.
Quoted 7 lines
Quoted 5 lines
Really? Why? We still have an initrd.
Quoted 1 line
Why do not use xen_state.next_start.mod_start here?
It is the pfn in case of
unmapped_initrd.Errr... I have looked at wrong line. Sorry about that.
NP.
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Juergen Gross
maintainerRe: [PATCH v5 09/11] xen: add capability to load initrd outside of initial mapping
In reply to Daniel KiperQuoted 78 lines · Daniel Kiper
Quoted 77 lines · Juergen Gross
Quoted 75 lines · Daniel Kiper
Quoted 60 lines · Juergen Gross
Modern pvops linux kernels support an initrd not covered by the initial mapping. This capability is flagged by an elf-note.
In case the elf-note is set by the kernel don't place the initrd into the initial mapping. This will allow to load larger initrds and/or support domains with larger memory, as the initial mapping is limited to 2GB and it is containing the p2m list.
Signed-off-by Juergen Gross <[email protected]>---
V5: let callgrub_xen_alloc_final()all subfunctions unconditionally
and let them decide whether they need to do anything
V4: renamegrub_xen_alloc_end()togrub_xen_alloc_final()--- grub-core/loader/i386/xen.c | 65 ++++++++++++++++++++++++++++++-------- grub-core/loader/i386/xen_fileXX.c | 3 ++ include/grub/xen_file.h | 1 + 3 files changed, 56 insertions(+), 13 deletions(-)grub-core/loader/i386/xen.c +12
-0@@ -228,6 +228,9 @@ grub_xen_p2m_alloc (void)grub_size_t p2msize;grub_err_t err; +if (xen_state.virt_mfn_list) +return GRUB_ERR_NONE ; + xen_state.state.mfn_list = xen_state.max_addr; xen_state.next_start.mfn_list = xen_state.max_addr + xen_state.xen_inf.virt_base;@@ -250,6 +253,9 @@ grub_xen_special_alloc (void)grub_relocator_chunk_t ch;grub_err_t err; +if (xen_state.virt_start_info) +return GRUB_ERR_NONE ; + err =grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, xen_state.max_addr,sizeof (xen_state.next_start));@@ -281,6 +287,9 @@ grub_xen_pt_alloc (void)grub_uint64_t nr_info_pages;grub_uint64_t nr_pages, nr_pt_pages, nr_need_pages; +if (xen_state.virt_pgtable) +return GRUB_ERR_NONE ; + xen_state.next_start.pt_base = xen_state.max_addr + xen_state.xen_inf.virt_base; xen_state.state.paging_start = xen_state.max_addr >>PAGE_SHIFT ;@@ -320,6 +329,24 @@ grub_xen_pt_alloc (void) }static grub_err_t +grub_xen_alloc_final (void ) +{ +grub_err_t err;grub-core/loader/i386/xen.c grub_xen_pt_alloc (void) · line 344
Quoted 10 lines
grub-core/loader/i386/xen.c +10
-0+ + err =grub_xen_p2m_alloc (); +if (err) +return err; + err =grub_xen_special_alloc (); +if (err) +return err; + err =grub_xen_pt_alloc (); +if (err) +return err;Could you move
grub_xen_p2m_alloc()here? This waygrub_xen_alloc_final()will be real final in patch 11 and you do not need an extra condition aroundgrub_xen_p2m_alloc().
Quoted 4 lines
Quoted 2 lines
No. Page tables must be allocated after p2m unless p2m is outside of initial kernel mapping (patch 11).
OK, I was afraid of that. However, then
grub_xen_alloc_final()is not final.
Sure it is. Patch 11 just adds allocation to grub_xen_alloc_final(), not after it.
Quoted 83 lines
So, maybe it should be called
grub_xen_alloc_boot_data()or something like that.Quoted 27 lines
Quoted 27 lines
Quoted 9 lines
grub-core/loader/i386/xen.c +4
-0+return GRUB_ERR_NONE ; +} + +static grub_err_t grub_xen_boot (void ) {grub_err_t err;@@ -330,13 +357,7 @@ grub_xen_boot (void)if (grub_xen_n_allocated_shared_pages)grub-core/loader/i386/xen.c grub_xen_boot (void) · line 360
Quoted 10 lines
grub-core/loader/i386/xen.c +1
-7return grub_error (GRUB_ERR_BUG ,"active grants" ); - err =grub_xen_p2m_alloc (); -if (err) -return err; - err =grub_xen_special_alloc (); -if (err) -return err; - err =grub_xen_pt_alloc (); + err =grub_xen_alloc_final ();if (!xen_state.xen_inf.unmapped_initrd)
{ err = grub_xen_alloc_final (); if (err) goto fail;}
Quoted 5 lines
Quoted 2 lines
This way you avoid checks in
grub_xen_p2m_alloc(),grub_xen_special_alloc()andgrub_xen_pt_alloc().No. In case there is no initrd, but the kernel does support an unmapped initrd, I would omit allocating special pages, p2m and page tables.
Ups... I have missed that.
Quoted 46 lines
Quoted 46 lines
Quoted 18 lines
grub-core/loader/i386/xen.c +7
-0if (err)return err;@@ -610,6 +631,13 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), goto fail; } +if (xen_state.xen_inf.unmapped_initrd) + { + err =grub_xen_alloc_final (); +if (err) + goto fail; + } +if (grub_initrd_init (argc, argv, &initrd_ctx)) goto fail;grub-core/loader/i386/xen.c grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), · line 632
Quoted 6 lines
grub-core/loader/i386/xen.c +0
-3@@ -627,14 +655,24 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), goto fail; } - xen_state.next_start.mod_start = - xen_state.max_addr + xen_state.xen_inf.virt_base; - xen_state.next_start.mod_len = size;Leave "xen_state.next_start.mod_len = size;" as is here and...
grub-core/loader/i386/xen.c grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), · line 662
Quoted 7 lines
grub-core/loader/i386/xen.c +5
-2- - xen_state.max_addr =ALIGN_UP (xen_state.max_addr + size,PAGE_SIZE ); +if (xen_state.xen_inf.unmapped_initrd) + { + xen_state.next_start.flags |=SIF_MOD_START_PFN ; + xen_state.next_start.mod_start = xen_state.max_addr >>PAGE_SHIFT ; + xen_state.next_start.mod_len = size;... do not add it here...
grub-core/loader/i386/xen.c grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), · line 668
Quoted 6 lines
grub-core/loader/i386/xen.c +6
-0+ } +else + { + xen_state.next_start.mod_start = + xen_state.max_addr + xen_state.xen_inf.virt_base; + xen_state.next_start.mod_len = size;... and here...
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
grub-core/loader/i386/xen.c grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), · line 669
Quoted 1 line
grub-core/loader/i386/xen.c +1
-0+ }... and you do not need curly brackets then.
I still do, as in the "if" part I still have two statements.
Yep, but else stuff does not need one.
Ah, okay. Too many different coding styles. Linux kernel would keep the braces.
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
grub-core/loader/i386/xen.c grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), · line 673
Quoted 5 lines
grub-core/loader/i386/xen.c +2
-1grub_dprintf ("xen" ,"Initrd, addr=0x%x, size=0x%x\n" , - (unsigned ) xen_state.next_start.mod_start, (unsigned ) size); + (unsigned ) (xen_state.max_addr + xen_state.xen_inf.virt_base), + (unsigned ) size);This should be printed only if !xen_state.xen_inf.unmapped_initrd.
Quoted 7 lines
Quoted 5 lines
Really? Why? We still have an initrd.
Quoted 1 line
Why do not use xen_state.next_start.mod_start here?
It is the pfn in case of
unmapped_initrd.Errr... I have looked at wrong line. Sorry about that.
NP.
Juergen
Re: [PATCH v5 09/11] xen: add capability to load initrd outside of initial mapping
Quoted 79 lines · Juergen Gross
Quoted 78 lines · Daniel Kiper
Quoted 77 lines · Juergen Gross
Quoted 75 lines · Daniel Kiper
Quoted 60 lines · Juergen Gross
Modern pvops linux kernels support an initrd not covered by the initial mapping. This capability is flagged by an elf-note.
In case the elf-note is set by the kernel don't place the initrd into the initial mapping. This will allow to load larger initrds and/or support domains with larger memory, as the initial mapping is limited to 2GB and it is containing the p2m list.
Signed-off-by Juergen Gross <[email protected]>---
V5: let callgrub_xen_alloc_final()all subfunctions unconditionally
and let them decide whether they need to do anything
V4: renamegrub_xen_alloc_end()togrub_xen_alloc_final()--- grub-core/loader/i386/xen.c | 65 ++++++++++++++++++++++++++++++-------- grub-core/loader/i386/xen_fileXX.c | 3 ++ include/grub/xen_file.h | 1 + 3 files changed, 56 insertions(+), 13 deletions(-)grub-core/loader/i386/xen.c +12
-0@@ -228,6 +228,9 @@ grub_xen_p2m_alloc (void)grub_size_t p2msize;grub_err_t err; +if (xen_state.virt_mfn_list) +return GRUB_ERR_NONE ; + xen_state.state.mfn_list = xen_state.max_addr; xen_state.next_start.mfn_list = xen_state.max_addr + xen_state.xen_inf.virt_base;@@ -250,6 +253,9 @@ grub_xen_special_alloc (void)grub_relocator_chunk_t ch;grub_err_t err; +if (xen_state.virt_start_info) +return GRUB_ERR_NONE ; + err =grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, xen_state.max_addr,sizeof (xen_state.next_start));@@ -281,6 +287,9 @@ grub_xen_pt_alloc (void)grub_uint64_t nr_info_pages;grub_uint64_t nr_pages, nr_pt_pages, nr_need_pages; +if (xen_state.virt_pgtable) +return GRUB_ERR_NONE ; + xen_state.next_start.pt_base = xen_state.max_addr + xen_state.xen_inf.virt_base; xen_state.state.paging_start = xen_state.max_addr >>PAGE_SHIFT ;@@ -320,6 +329,24 @@ grub_xen_pt_alloc (void) }static grub_err_t +grub_xen_alloc_final (void ) +{ +grub_err_t err;grub-core/loader/i386/xen.c grub_xen_pt_alloc (void) · line 344
Quoted 10 lines
grub-core/loader/i386/xen.c +10
-0+ + err =grub_xen_p2m_alloc (); +if (err) +return err; + err =grub_xen_special_alloc (); +if (err) +return err; + err =grub_xen_pt_alloc (); +if (err) +return err;Could you move
grub_xen_p2m_alloc()here? This waygrub_xen_alloc_final()will be real final in patch 11 and you do not need an extra condition aroundgrub_xen_p2m_alloc().
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
No. Page tables must be allocated after p2m unless p2m is outside of initial kernel mapping (patch 11).
OK, I was afraid of that. However, then
grub_xen_alloc_final()is not final.Sure it is. Patch 11 just adds allocation to
grub_xen_alloc_final(), not after it.
Excerpt from patch 11:
@@ -474,6 +503,12 @@ grub_xen_boot (void)
err = grub_xen_alloc_final ();
if (err)
return err;
+ if (xen_state.xen_inf.has_p2m_base)
+ {
+ err = grub_xen_p2m_alloc ();
+ if (err)
+ return err;
+ }
Quoted 1 line
Quoted 1 line
So, maybe it should be called
grub_xen_alloc_boot_data()or something like that.
Then my previous comment is still valid.
Daniel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Juergen Gross
maintainerRe: [PATCH v5 09/11] xen: add capability to load initrd outside of initial mapping
Quoted 91 lines · Daniel Kiper
Quoted 79 lines · Juergen Gross
Quoted 78 lines · Daniel Kiper
Quoted 77 lines · Juergen Gross
Quoted 75 lines · Daniel Kiper
Quoted 60 lines · Juergen Gross
Modern pvops linux kernels support an initrd not covered by the initial mapping. This capability is flagged by an elf-note.
In case the elf-note is set by the kernel don't place the initrd into the initial mapping. This will allow to load larger initrds and/or support domains with larger memory, as the initial mapping is limited to 2GB and it is containing the p2m list.
Signed-off-by Juergen Gross <[email protected]>---
V5: let callgrub_xen_alloc_final()all subfunctions unconditionally
and let them decide whether they need to do anything
V4: renamegrub_xen_alloc_end()togrub_xen_alloc_final()--- grub-core/loader/i386/xen.c | 65 ++++++++++++++++++++++++++++++-------- grub-core/loader/i386/xen_fileXX.c | 3 ++ include/grub/xen_file.h | 1 + 3 files changed, 56 insertions(+), 13 deletions(-)grub-core/loader/i386/xen.c +12
-0@@ -228,6 +228,9 @@ grub_xen_p2m_alloc (void)grub_size_t p2msize;grub_err_t err; +if (xen_state.virt_mfn_list) +return GRUB_ERR_NONE ; + xen_state.state.mfn_list = xen_state.max_addr; xen_state.next_start.mfn_list = xen_state.max_addr + xen_state.xen_inf.virt_base;@@ -250,6 +253,9 @@ grub_xen_special_alloc (void)grub_relocator_chunk_t ch;grub_err_t err; +if (xen_state.virt_start_info) +return GRUB_ERR_NONE ; + err =grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, xen_state.max_addr,sizeof (xen_state.next_start));@@ -281,6 +287,9 @@ grub_xen_pt_alloc (void)grub_uint64_t nr_info_pages;grub_uint64_t nr_pages, nr_pt_pages, nr_need_pages; +if (xen_state.virt_pgtable) +return GRUB_ERR_NONE ; + xen_state.next_start.pt_base = xen_state.max_addr + xen_state.xen_inf.virt_base; xen_state.state.paging_start = xen_state.max_addr >>PAGE_SHIFT ;@@ -320,6 +329,24 @@ grub_xen_pt_alloc (void) }static grub_err_t +grub_xen_alloc_final (void ) +{ +grub_err_t err;grub-core/loader/i386/xen.c grub_xen_pt_alloc (void) · line 344
Quoted 10 lines
grub-core/loader/i386/xen.c +10
-0+ + err =grub_xen_p2m_alloc (); +if (err) +return err; + err =grub_xen_special_alloc (); +if (err) +return err; + err =grub_xen_pt_alloc (); +if (err) +return err;Could you move
grub_xen_p2m_alloc()here? This waygrub_xen_alloc_final()will be real final in patch 11 and you do not need an extra condition aroundgrub_xen_p2m_alloc().Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
No. Page tables must be allocated after p2m unless p2m is outside of initial kernel mapping (patch 11).
OK, I was afraid of that. However, then
grub_xen_alloc_final()is not final.Sure it is. Patch 11 just adds allocation to
grub_xen_alloc_final(), not after it.Excerpt from patch 11:
grub-core/loader/i386/xen.c grub_xen_boot (void) · line 512
Quoted 10 lines
grub-core/loader/i386/xen.c +6
-0@@ -474,6 +503,12 @@ grub_xen_boot (void) err =grub_xen_alloc_final ();if (err)return err; +if (xen_state.xen_inf.has_p2m_base) + { + err =grub_xen_p2m_alloc (); +if (err) +return err; + }
Hmph. No idea what I looked at when writing my previous reply.
Quoted 3 lines
Quoted 1 line
Quoted 1 line
So, maybe it should be called
grub_xen_alloc_boot_data()or something like that.Then my previous comment is still valid.
What about naming it grub_xen_alloc_kernel_mapping() ? This is what it really does: It is allocating all not yet allocated areas which are to be included in the initial kernel mapping.
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Juergen Gross
maintainerRe: [PATCH v5 09/11] xen: add capability to load initrd outside of initial mapping
In reply to Daniel KiperQuoted 91 lines · Daniel Kiper
Quoted 79 lines · Juergen Gross
Quoted 78 lines · Daniel Kiper
Quoted 77 lines · Juergen Gross
Quoted 75 lines · Daniel Kiper
Quoted 60 lines · Juergen Gross
Modern pvops linux kernels support an initrd not covered by the initial mapping. This capability is flagged by an elf-note.
In case the elf-note is set by the kernel don't place the initrd into the initial mapping. This will allow to load larger initrds and/or support domains with larger memory, as the initial mapping is limited to 2GB and it is containing the p2m list.
Signed-off-by Juergen Gross <[email protected]>---
V5: let callgrub_xen_alloc_final()all subfunctions unconditionally
and let them decide whether they need to do anything
V4: renamegrub_xen_alloc_end()togrub_xen_alloc_final()--- grub-core/loader/i386/xen.c | 65 ++++++++++++++++++++++++++++++-------- grub-core/loader/i386/xen_fileXX.c | 3 ++ include/grub/xen_file.h | 1 + 3 files changed, 56 insertions(+), 13 deletions(-)grub-core/loader/i386/xen.c +12
-0@@ -228,6 +228,9 @@ grub_xen_p2m_alloc (void)grub_size_t p2msize;grub_err_t err; +if (xen_state.virt_mfn_list) +return GRUB_ERR_NONE ; + xen_state.state.mfn_list = xen_state.max_addr; xen_state.next_start.mfn_list = xen_state.max_addr + xen_state.xen_inf.virt_base;@@ -250,6 +253,9 @@ grub_xen_special_alloc (void)grub_relocator_chunk_t ch;grub_err_t err; +if (xen_state.virt_start_info) +return GRUB_ERR_NONE ; + err =grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, xen_state.max_addr,sizeof (xen_state.next_start));@@ -281,6 +287,9 @@ grub_xen_pt_alloc (void)grub_uint64_t nr_info_pages;grub_uint64_t nr_pages, nr_pt_pages, nr_need_pages; +if (xen_state.virt_pgtable) +return GRUB_ERR_NONE ; + xen_state.next_start.pt_base = xen_state.max_addr + xen_state.xen_inf.virt_base; xen_state.state.paging_start = xen_state.max_addr >>PAGE_SHIFT ;@@ -320,6 +329,24 @@ grub_xen_pt_alloc (void) }static grub_err_t +grub_xen_alloc_final (void ) +{ +grub_err_t err;grub-core/loader/i386/xen.c grub_xen_pt_alloc (void) · line 344
Quoted 10 lines
grub-core/loader/i386/xen.c +10
-0+ + err =grub_xen_p2m_alloc (); +if (err) +return err; + err =grub_xen_special_alloc (); +if (err) +return err; + err =grub_xen_pt_alloc (); +if (err) +return err;Could you move
grub_xen_p2m_alloc()here? This waygrub_xen_alloc_final()will be real final in patch 11 and you do not need an extra condition aroundgrub_xen_p2m_alloc().Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
No. Page tables must be allocated after p2m unless p2m is outside of initial kernel mapping (patch 11).
OK, I was afraid of that. However, then
grub_xen_alloc_final()is not final.Sure it is. Patch 11 just adds allocation to
grub_xen_alloc_final(), not after it.Excerpt from patch 11:
grub-core/loader/i386/xen.c grub_xen_boot (void) · line 512
Quoted 10 lines
grub-core/loader/i386/xen.c +6
-0@@ -474,6 +503,12 @@ grub_xen_boot (void) err =grub_xen_alloc_final ();if (err)return err; +if (xen_state.xen_inf.has_p2m_base) + { + err =grub_xen_p2m_alloc (); +if (err) +return err; + }
Hmph. No idea what I looked at when writing my previous reply.
Quoted 3 lines
Quoted 1 line
Quoted 1 line
So, maybe it should be called
grub_xen_alloc_boot_data()or something like that.Then my previous comment is still valid.
What about naming it grub_xen_alloc_kernel_mapping() ? This is what it really does: It is allocating all not yet allocated areas which are to be included in the initial kernel mapping.
Juergen
Re: [PATCH v5 09/11] xen: add capability to load initrd outside of initial mapping
Quoted 105 lines · Juergen Gross
Quoted 91 lines · Daniel Kiper
Quoted 79 lines · Juergen Gross
Quoted 78 lines · Daniel Kiper
Quoted 77 lines · Juergen Gross
Quoted 75 lines · Daniel Kiper
Quoted 60 lines · Juergen Gross
Modern pvops linux kernels support an initrd not covered by the initial mapping. This capability is flagged by an elf-note.
In case the elf-note is set by the kernel don't place the initrd into the initial mapping. This will allow to load larger initrds and/or support domains with larger memory, as the initial mapping is limited to 2GB and it is containing the p2m list.
Signed-off-by Juergen Gross <[email protected]>---
V5: let callgrub_xen_alloc_final()all subfunctions unconditionally
and let them decide whether they need to do anything
V4: renamegrub_xen_alloc_end()togrub_xen_alloc_final()--- grub-core/loader/i386/xen.c | 65 ++++++++++++++++++++++++++++++-------- grub-core/loader/i386/xen_fileXX.c | 3 ++ include/grub/xen_file.h | 1 + 3 files changed, 56 insertions(+), 13 deletions(-)grub-core/loader/i386/xen.c +12
-0@@ -228,6 +228,9 @@ grub_xen_p2m_alloc (void)grub_size_t p2msize;grub_err_t err; +if (xen_state.virt_mfn_list) +return GRUB_ERR_NONE ; + xen_state.state.mfn_list = xen_state.max_addr; xen_state.next_start.mfn_list = xen_state.max_addr + xen_state.xen_inf.virt_base;@@ -250,6 +253,9 @@ grub_xen_special_alloc (void)grub_relocator_chunk_t ch;grub_err_t err; +if (xen_state.virt_start_info) +return GRUB_ERR_NONE ; + err =grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, xen_state.max_addr,sizeof (xen_state.next_start));@@ -281,6 +287,9 @@ grub_xen_pt_alloc (void)grub_uint64_t nr_info_pages;grub_uint64_t nr_pages, nr_pt_pages, nr_need_pages; +if (xen_state.virt_pgtable) +return GRUB_ERR_NONE ; + xen_state.next_start.pt_base = xen_state.max_addr + xen_state.xen_inf.virt_base; xen_state.state.paging_start = xen_state.max_addr >>PAGE_SHIFT ;@@ -320,6 +329,24 @@ grub_xen_pt_alloc (void) }static grub_err_t +grub_xen_alloc_final (void ) +{ +grub_err_t err;grub-core/loader/i386/xen.c grub_xen_pt_alloc (void) · line 344
Quoted 10 lines
grub-core/loader/i386/xen.c +10
-0+ + err =grub_xen_p2m_alloc (); +if (err) +return err; + err =grub_xen_special_alloc (); +if (err) +return err; + err =grub_xen_pt_alloc (); +if (err) +return err;Could you move
grub_xen_p2m_alloc()here? This waygrub_xen_alloc_final()will be real final in patch 11 and you do not need an extra condition aroundgrub_xen_p2m_alloc().Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
No. Page tables must be allocated after p2m unless p2m is outside of initial kernel mapping (patch 11).
OK, I was afraid of that. However, then
grub_xen_alloc_final()is not final.Sure it is. Patch 11 just adds allocation to
grub_xen_alloc_final(), not after it.Excerpt from patch 11:
Review grub_xen_boot (void) · line 512
Quoted 10 lines
(quoted diff) +6
-0@@ -474,6 +503,12 @@ grub_xen_boot (void) err = grub_xen_alloc_final (); if (err) return err; + if (xen_state.xen_inf.has_p2m_base) + { + err = grub_xen_p2m_alloc (); + if (err) + return err; + }Hmph. No idea what I looked at when writing my previous reply.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
So, maybe it should be called
grub_xen_alloc_boot_data()or something like that.Then my previous comment is still valid.
What about naming it
grub_xen_alloc_kernel_mapping()? This is what it really does: It is allocating all not yet allocated areas which are to be included in the initial kernel mapping.
This function does three things:
- allocate memory for p2m array,
- allocate special pages (e.g. console),
- allocate memory for page tables.
Three of them are part of boot data described by struct start_info. Well, there are also other required stuff to properly boot PV guest. So, I can agree that grub_xen_alloc_boot_data() is not perfect but I cannot find anything better. Additionally, IMO grub_xen_alloc_kernel_mapping() is not right choice too. It suggests that this functions does anything with kernel mapping. Yep, it does, however, this is only one third of this function. So, I tend to use my proposal or anything better which is short and quite well describes what is going in this function as whole.
Daniel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v5 09/11] xen: add capability to load initrd outside of initial mapping
In reply to Juergen GrossQuoted 105 lines · Juergen Gross
Quoted 91 lines · Daniel Kiper
Quoted 79 lines · Juergen Gross
Quoted 78 lines · Daniel Kiper
Quoted 77 lines · Juergen Gross
Quoted 75 lines · Daniel Kiper
Quoted 60 lines · Juergen Gross
Modern pvops linux kernels support an initrd not covered by the initial mapping. This capability is flagged by an elf-note.
In case the elf-note is set by the kernel don't place the initrd into the initial mapping. This will allow to load larger initrds and/or support domains with larger memory, as the initial mapping is limited to 2GB and it is containing the p2m list.
Signed-off-by Juergen Gross <[email protected]>---
V5: let callgrub_xen_alloc_final()all subfunctions unconditionally
and let them decide whether they need to do anything
V4: renamegrub_xen_alloc_end()togrub_xen_alloc_final()--- grub-core/loader/i386/xen.c | 65 ++++++++++++++++++++++++++++++-------- grub-core/loader/i386/xen_fileXX.c | 3 ++ include/grub/xen_file.h | 1 + 3 files changed, 56 insertions(+), 13 deletions(-)grub-core/loader/i386/xen.c +12
-0@@ -228,6 +228,9 @@ grub_xen_p2m_alloc (void)grub_size_t p2msize;grub_err_t err; +if (xen_state.virt_mfn_list) +return GRUB_ERR_NONE ; + xen_state.state.mfn_list = xen_state.max_addr; xen_state.next_start.mfn_list = xen_state.max_addr + xen_state.xen_inf.virt_base;@@ -250,6 +253,9 @@ grub_xen_special_alloc (void)grub_relocator_chunk_t ch;grub_err_t err; +if (xen_state.virt_start_info) +return GRUB_ERR_NONE ; + err =grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, xen_state.max_addr,sizeof (xen_state.next_start));@@ -281,6 +287,9 @@ grub_xen_pt_alloc (void)grub_uint64_t nr_info_pages;grub_uint64_t nr_pages, nr_pt_pages, nr_need_pages; +if (xen_state.virt_pgtable) +return GRUB_ERR_NONE ; + xen_state.next_start.pt_base = xen_state.max_addr + xen_state.xen_inf.virt_base; xen_state.state.paging_start = xen_state.max_addr >>PAGE_SHIFT ;@@ -320,6 +329,24 @@ grub_xen_pt_alloc (void) }static grub_err_t +grub_xen_alloc_final (void ) +{ +grub_err_t err;grub-core/loader/i386/xen.c grub_xen_pt_alloc (void) · line 344
Quoted 10 lines
grub-core/loader/i386/xen.c +10
-0+ + err =grub_xen_p2m_alloc (); +if (err) +return err; + err =grub_xen_special_alloc (); +if (err) +return err; + err =grub_xen_pt_alloc (); +if (err) +return err;Could you move
grub_xen_p2m_alloc()here? This waygrub_xen_alloc_final()will be real final in patch 11 and you do not need an extra condition aroundgrub_xen_p2m_alloc().Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
No. Page tables must be allocated after p2m unless p2m is outside of initial kernel mapping (patch 11).
OK, I was afraid of that. However, then
grub_xen_alloc_final()is not final.Sure it is. Patch 11 just adds allocation to
grub_xen_alloc_final(), not after it.Excerpt from patch 11:
Review grub_xen_boot (void) · line 512
Quoted 10 lines
(quoted diff) +6
-0@@ -474,6 +503,12 @@ grub_xen_boot (void) err = grub_xen_alloc_final (); if (err) return err; + if (xen_state.xen_inf.has_p2m_base) + { + err = grub_xen_p2m_alloc (); + if (err) + return err; + }Hmph. No idea what I looked at when writing my previous reply.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
So, maybe it should be called
grub_xen_alloc_boot_data()or something like that.Then my previous comment is still valid.
What about naming it
grub_xen_alloc_kernel_mapping()? This is what it really does: It is allocating all not yet allocated areas which are to be included in the initial kernel mapping.
This function does three things:
- allocate memory for p2m array,
- allocate special pages (e.g. console),
- allocate memory for page tables.
Three of them are part of boot data described by struct start_info. Well, there are also other required stuff to properly boot PV guest. So, I can agree that grub_xen_alloc_boot_data() is not perfect but I cannot find anything better. Additionally, IMO grub_xen_alloc_kernel_mapping() is not right choice too. It suggests that this functions does anything with kernel mapping. Yep, it does, however, this is only one third of this function. So, I tend to use my proposal or anything better which is short and quite well describes what is going in this function as whole.
Daniel
Juergen Gross
maintainerRe: [PATCH v5 09/11] xen: add capability to load initrd outside of initial mapping
Quoted 119 lines · Daniel Kiper
Quoted 105 lines · Juergen Gross
Quoted 91 lines · Daniel Kiper
Quoted 79 lines · Juergen Gross
Quoted 78 lines · Daniel Kiper
Quoted 77 lines · Juergen Gross
Quoted 75 lines · Daniel Kiper
Quoted 60 lines · Juergen Gross
Modern pvops linux kernels support an initrd not covered by the initial mapping. This capability is flagged by an elf-note.
In case the elf-note is set by the kernel don't place the initrd into the initial mapping. This will allow to load larger initrds and/or support domains with larger memory, as the initial mapping is limited to 2GB and it is containing the p2m list.
Signed-off-by Juergen Gross <[email protected]>---
V5: let callgrub_xen_alloc_final()all subfunctions unconditionally
and let them decide whether they need to do anything
V4: renamegrub_xen_alloc_end()togrub_xen_alloc_final()--- grub-core/loader/i386/xen.c | 65 ++++++++++++++++++++++++++++++-------- grub-core/loader/i386/xen_fileXX.c | 3 ++ include/grub/xen_file.h | 1 + 3 files changed, 56 insertions(+), 13 deletions(-)grub-core/loader/i386/xen.c +12
-0@@ -228,6 +228,9 @@ grub_xen_p2m_alloc (void)grub_size_t p2msize;grub_err_t err; +if (xen_state.virt_mfn_list) +return GRUB_ERR_NONE ; + xen_state.state.mfn_list = xen_state.max_addr; xen_state.next_start.mfn_list = xen_state.max_addr + xen_state.xen_inf.virt_base;@@ -250,6 +253,9 @@ grub_xen_special_alloc (void)grub_relocator_chunk_t ch;grub_err_t err; +if (xen_state.virt_start_info) +return GRUB_ERR_NONE ; + err =grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, xen_state.max_addr,sizeof (xen_state.next_start));@@ -281,6 +287,9 @@ grub_xen_pt_alloc (void)grub_uint64_t nr_info_pages;grub_uint64_t nr_pages, nr_pt_pages, nr_need_pages; +if (xen_state.virt_pgtable) +return GRUB_ERR_NONE ; + xen_state.next_start.pt_base = xen_state.max_addr + xen_state.xen_inf.virt_base; xen_state.state.paging_start = xen_state.max_addr >>PAGE_SHIFT ;@@ -320,6 +329,24 @@ grub_xen_pt_alloc (void) }static grub_err_t +grub_xen_alloc_final (void ) +{ +grub_err_t err;grub-core/loader/i386/xen.c grub_xen_pt_alloc (void) · line 344
Quoted 10 lines
grub-core/loader/i386/xen.c +10
-0+ + err =grub_xen_p2m_alloc (); +if (err) +return err; + err =grub_xen_special_alloc (); +if (err) +return err; + err =grub_xen_pt_alloc (); +if (err) +return err;Could you move
grub_xen_p2m_alloc()here? This waygrub_xen_alloc_final()will be real final in patch 11 and you do not need an extra condition aroundgrub_xen_p2m_alloc().Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
No. Page tables must be allocated after p2m unless p2m is outside of initial kernel mapping (patch 11).
OK, I was afraid of that. However, then
grub_xen_alloc_final()is not final.Sure it is. Patch 11 just adds allocation to
grub_xen_alloc_final(), not after it.Excerpt from patch 11:
Review grub_xen_boot (void) · line 512
Quoted 10 lines
(quoted diff) +6
-0@@ -474,6 +503,12 @@ grub_xen_boot (void) err = grub_xen_alloc_final (); if (err) return err; + if (xen_state.xen_inf.has_p2m_base) + { + err = grub_xen_p2m_alloc (); + if (err) + return err; + }Hmph. No idea what I looked at when writing my previous reply.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
So, maybe it should be called
grub_xen_alloc_boot_data()or something like that.Then my previous comment is still valid.
What about naming it
grub_xen_alloc_kernel_mapping()? This is what it really does: It is allocating all not yet allocated areas which are to be included in the initial kernel mapping.This function does three things:
- allocate memory for p2m array,
- allocate special pages (e.g. console),
- allocate memory for page tables.
Quoted 9 lines
Three of them are part of boot data described by struct
start_info. Well, there are also other required stuff to properly boot PV guest. So, I can agree thatgrub_xen_alloc_boot_data()is not perfect but I cannot find anything better. Additionally, IMOgrub_xen_alloc_kernel_mapping()is not right choice too. It suggests that this functions does anything with kernel mapping. Yep, it does, however, this is only one third of this function. So, I tend to use my proposal or anything better which is short and quite well describes what is going in this function as whole.
Yeah. grub_xen_alloc_stuff() with a nice comment. ;-)
Okay, lets stick with grub_xen_alloc_boot_data() and add a comment explaining that the function will allocate everything not yet allocated and covered by the initial page tables.
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Juergen Gross
maintainerRe: [PATCH v5 09/11] xen: add capability to load initrd outside of initial mapping
In reply to Daniel KiperQuoted 119 lines · Daniel Kiper
Quoted 105 lines · Juergen Gross
Quoted 91 lines · Daniel Kiper
Quoted 79 lines · Juergen Gross
Quoted 78 lines · Daniel Kiper
Quoted 77 lines · Juergen Gross
Quoted 75 lines · Daniel Kiper
Quoted 60 lines · Juergen Gross
Modern pvops linux kernels support an initrd not covered by the initial mapping. This capability is flagged by an elf-note.
In case the elf-note is set by the kernel don't place the initrd into the initial mapping. This will allow to load larger initrds and/or support domains with larger memory, as the initial mapping is limited to 2GB and it is containing the p2m list.
Signed-off-by Juergen Gross <[email protected]>---
V5: let callgrub_xen_alloc_final()all subfunctions unconditionally
and let them decide whether they need to do anything
V4: renamegrub_xen_alloc_end()togrub_xen_alloc_final()--- grub-core/loader/i386/xen.c | 65 ++++++++++++++++++++++++++++++-------- grub-core/loader/i386/xen_fileXX.c | 3 ++ include/grub/xen_file.h | 1 + 3 files changed, 56 insertions(+), 13 deletions(-)grub-core/loader/i386/xen.c +12
-0@@ -228,6 +228,9 @@ grub_xen_p2m_alloc (void)grub_size_t p2msize;grub_err_t err; +if (xen_state.virt_mfn_list) +return GRUB_ERR_NONE ; + xen_state.state.mfn_list = xen_state.max_addr; xen_state.next_start.mfn_list = xen_state.max_addr + xen_state.xen_inf.virt_base;@@ -250,6 +253,9 @@ grub_xen_special_alloc (void)grub_relocator_chunk_t ch;grub_err_t err; +if (xen_state.virt_start_info) +return GRUB_ERR_NONE ; + err =grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, xen_state.max_addr,sizeof (xen_state.next_start));@@ -281,6 +287,9 @@ grub_xen_pt_alloc (void)grub_uint64_t nr_info_pages;grub_uint64_t nr_pages, nr_pt_pages, nr_need_pages; +if (xen_state.virt_pgtable) +return GRUB_ERR_NONE ; + xen_state.next_start.pt_base = xen_state.max_addr + xen_state.xen_inf.virt_base; xen_state.state.paging_start = xen_state.max_addr >>PAGE_SHIFT ;@@ -320,6 +329,24 @@ grub_xen_pt_alloc (void) }static grub_err_t +grub_xen_alloc_final (void ) +{ +grub_err_t err;grub-core/loader/i386/xen.c grub_xen_pt_alloc (void) · line 344
Quoted 10 lines
grub-core/loader/i386/xen.c +10
-0+ + err =grub_xen_p2m_alloc (); +if (err) +return err; + err =grub_xen_special_alloc (); +if (err) +return err; + err =grub_xen_pt_alloc (); +if (err) +return err;Could you move
grub_xen_p2m_alloc()here? This waygrub_xen_alloc_final()will be real final in patch 11 and you do not need an extra condition aroundgrub_xen_p2m_alloc().Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
No. Page tables must be allocated after p2m unless p2m is outside of initial kernel mapping (patch 11).
OK, I was afraid of that. However, then
grub_xen_alloc_final()is not final.Sure it is. Patch 11 just adds allocation to
grub_xen_alloc_final(), not after it.Excerpt from patch 11:
Review grub_xen_boot (void) · line 512
Quoted 10 lines
(quoted diff) +6
-0@@ -474,6 +503,12 @@ grub_xen_boot (void) err = grub_xen_alloc_final (); if (err) return err; + if (xen_state.xen_inf.has_p2m_base) + { + err = grub_xen_p2m_alloc (); + if (err) + return err; + }Hmph. No idea what I looked at when writing my previous reply.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
So, maybe it should be called
grub_xen_alloc_boot_data()or something like that.Then my previous comment is still valid.
What about naming it
grub_xen_alloc_kernel_mapping()? This is what it really does: It is allocating all not yet allocated areas which are to be included in the initial kernel mapping.This function does three things:
- allocate memory for p2m array,
- allocate special pages (e.g. console),
- allocate memory for page tables.
Quoted 9 lines
Three of them are part of boot data described by struct
start_info. Well, there are also other required stuff to properly boot PV guest. So, I can agree thatgrub_xen_alloc_boot_data()is not perfect but I cannot find anything better. Additionally, IMOgrub_xen_alloc_kernel_mapping()is not right choice too. It suggests that this functions does anything with kernel mapping. Yep, it does, however, this is only one third of this function. So, I tend to use my proposal or anything better which is short and quite well describes what is going in this function as whole.
Yeah. grub_xen_alloc_stuff() with a nice comment. ;-)
Okay, lets stick with grub_xen_alloc_boot_data() and add a comment explaining that the function will allocate everything not yet allocated and covered by the initial page tables.
Juergen
Re: [PATCH v5 09/11] xen: add capability to load initrd outside of initial mapping
Quoted 130 lines · Juergen Gross
Quoted 119 lines · Daniel Kiper
Quoted 105 lines · Juergen Gross
Quoted 91 lines · Daniel Kiper
Quoted 79 lines · Juergen Gross
Quoted 78 lines · Daniel Kiper
Quoted 77 lines · Juergen Gross
Quoted 75 lines · Daniel Kiper
Quoted 60 lines · Juergen Gross
Modern pvops linux kernels support an initrd not covered by the initial mapping. This capability is flagged by an elf-note.
In case the elf-note is set by the kernel don't place the initrd into the initial mapping. This will allow to load larger initrds and/or support domains with larger memory, as the initial mapping is limited to 2GB and it is containing the p2m list.
Signed-off-by Juergen Gross <[email protected]>---
V5: let callgrub_xen_alloc_final()all subfunctions unconditionally
and let them decide whether they need to do anything
V4: renamegrub_xen_alloc_end()togrub_xen_alloc_final()--- grub-core/loader/i386/xen.c | 65 ++++++++++++++++++++++++++++++-------- grub-core/loader/i386/xen_fileXX.c | 3 ++ include/grub/xen_file.h | 1 + 3 files changed, 56 insertions(+), 13 deletions(-)grub-core/loader/i386/xen.c +12
-0@@ -228,6 +228,9 @@ grub_xen_p2m_alloc (void)grub_size_t p2msize;grub_err_t err; +if (xen_state.virt_mfn_list) +return GRUB_ERR_NONE ; + xen_state.state.mfn_list = xen_state.max_addr; xen_state.next_start.mfn_list = xen_state.max_addr + xen_state.xen_inf.virt_base;@@ -250,6 +253,9 @@ grub_xen_special_alloc (void)grub_relocator_chunk_t ch;grub_err_t err; +if (xen_state.virt_start_info) +return GRUB_ERR_NONE ; + err =grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, xen_state.max_addr,sizeof (xen_state.next_start));@@ -281,6 +287,9 @@ grub_xen_pt_alloc (void)grub_uint64_t nr_info_pages;grub_uint64_t nr_pages, nr_pt_pages, nr_need_pages; +if (xen_state.virt_pgtable) +return GRUB_ERR_NONE ; + xen_state.next_start.pt_base = xen_state.max_addr + xen_state.xen_inf.virt_base; xen_state.state.paging_start = xen_state.max_addr >>PAGE_SHIFT ;@@ -320,6 +329,24 @@ grub_xen_pt_alloc (void) }static grub_err_t +grub_xen_alloc_final (void ) +{ +grub_err_t err;grub-core/loader/i386/xen.c grub_xen_pt_alloc (void) · line 344
Quoted 10 lines
grub-core/loader/i386/xen.c +10
-0+ + err =grub_xen_p2m_alloc (); +if (err) +return err; + err =grub_xen_special_alloc (); +if (err) +return err; + err =grub_xen_pt_alloc (); +if (err) +return err;Could you move
grub_xen_p2m_alloc()here? This waygrub_xen_alloc_final()will be real final in patch 11 and you do not need an extra condition aroundgrub_xen_p2m_alloc().Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
No. Page tables must be allocated after p2m unless p2m is outside of initial kernel mapping (patch 11).
OK, I was afraid of that. However, then
grub_xen_alloc_final()is not final.Sure it is. Patch 11 just adds allocation to
grub_xen_alloc_final(), not after it.Excerpt from patch 11:
Review grub_xen_boot (void) · line 512
Quoted 10 lines
(quoted diff) +6
-0@@ -474,6 +503,12 @@ grub_xen_boot (void) err = grub_xen_alloc_final (); if (err) return err; + if (xen_state.xen_inf.has_p2m_base) + { + err = grub_xen_p2m_alloc (); + if (err) + return err; + }Hmph. No idea what I looked at when writing my previous reply.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
So, maybe it should be called
grub_xen_alloc_boot_data()or something like that.Then my previous comment is still valid.
What about naming it
grub_xen_alloc_kernel_mapping()? This is what it really does: It is allocating all not yet allocated areas which are to be included in the initial kernel mapping.This function does three things:
- allocate memory for p2m array,
- allocate special pages (e.g. console),
- allocate memory for page tables.Quoted 9 lines
Three of them are part of boot data described by struct
start_info. Well, there are also other required stuff to properly boot PV guest. So, I can agree thatgrub_xen_alloc_boot_data()is not perfect but I cannot find anything better. Additionally, IMOgrub_xen_alloc_kernel_mapping()is not right choice too. It suggests that this functions does anything with kernel mapping. Yep, it does, however, this is only one third of this function. So, I tend to use my proposal or anything better which is short and quite well describes what is going in this function as whole.
Quoted 1 line
Yeah.
grub_xen_alloc_stuff()with a nice comment. ;-)
:-))) I thought about that one too!
Quoted 3 lines
Okay, lets stick with
grub_xen_alloc_boot_data()and add a comment explaining that the function will allocate everything not yet allocated and covered by the initial page tables.
LGTM. Granted!
Daniel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v5 09/11] xen: add capability to load initrd outside of initial mapping
In reply to Juergen GrossQuoted 130 lines · Juergen Gross
Quoted 119 lines · Daniel Kiper
Quoted 105 lines · Juergen Gross
Quoted 91 lines · Daniel Kiper
Quoted 79 lines · Juergen Gross
Quoted 78 lines · Daniel Kiper
Quoted 77 lines · Juergen Gross
Quoted 75 lines · Daniel Kiper
Quoted 60 lines · Juergen Gross
Modern pvops linux kernels support an initrd not covered by the initial mapping. This capability is flagged by an elf-note.
In case the elf-note is set by the kernel don't place the initrd into the initial mapping. This will allow to load larger initrds and/or support domains with larger memory, as the initial mapping is limited to 2GB and it is containing the p2m list.
Signed-off-by Juergen Gross <[email protected]>---
V5: let callgrub_xen_alloc_final()all subfunctions unconditionally
and let them decide whether they need to do anything
V4: renamegrub_xen_alloc_end()togrub_xen_alloc_final()--- grub-core/loader/i386/xen.c | 65 ++++++++++++++++++++++++++++++-------- grub-core/loader/i386/xen_fileXX.c | 3 ++ include/grub/xen_file.h | 1 + 3 files changed, 56 insertions(+), 13 deletions(-)grub-core/loader/i386/xen.c +12
-0@@ -228,6 +228,9 @@ grub_xen_p2m_alloc (void)grub_size_t p2msize;grub_err_t err; +if (xen_state.virt_mfn_list) +return GRUB_ERR_NONE ; + xen_state.state.mfn_list = xen_state.max_addr; xen_state.next_start.mfn_list = xen_state.max_addr + xen_state.xen_inf.virt_base;@@ -250,6 +253,9 @@ grub_xen_special_alloc (void)grub_relocator_chunk_t ch;grub_err_t err; +if (xen_state.virt_start_info) +return GRUB_ERR_NONE ; + err =grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, xen_state.max_addr,sizeof (xen_state.next_start));@@ -281,6 +287,9 @@ grub_xen_pt_alloc (void)grub_uint64_t nr_info_pages;grub_uint64_t nr_pages, nr_pt_pages, nr_need_pages; +if (xen_state.virt_pgtable) +return GRUB_ERR_NONE ; + xen_state.next_start.pt_base = xen_state.max_addr + xen_state.xen_inf.virt_base; xen_state.state.paging_start = xen_state.max_addr >>PAGE_SHIFT ;@@ -320,6 +329,24 @@ grub_xen_pt_alloc (void) }static grub_err_t +grub_xen_alloc_final (void ) +{ +grub_err_t err;grub-core/loader/i386/xen.c grub_xen_pt_alloc (void) · line 344
Quoted 10 lines
grub-core/loader/i386/xen.c +10
-0+ + err =grub_xen_p2m_alloc (); +if (err) +return err; + err =grub_xen_special_alloc (); +if (err) +return err; + err =grub_xen_pt_alloc (); +if (err) +return err;Could you move
grub_xen_p2m_alloc()here? This waygrub_xen_alloc_final()will be real final in patch 11 and you do not need an extra condition aroundgrub_xen_p2m_alloc().Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
No. Page tables must be allocated after p2m unless p2m is outside of initial kernel mapping (patch 11).
OK, I was afraid of that. However, then
grub_xen_alloc_final()is not final.Sure it is. Patch 11 just adds allocation to
grub_xen_alloc_final(), not after it.Excerpt from patch 11:
Review grub_xen_boot (void) · line 512
Quoted 10 lines
(quoted diff) +6
-0@@ -474,6 +503,12 @@ grub_xen_boot (void) err = grub_xen_alloc_final (); if (err) return err; + if (xen_state.xen_inf.has_p2m_base) + { + err = grub_xen_p2m_alloc (); + if (err) + return err; + }Hmph. No idea what I looked at when writing my previous reply.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
So, maybe it should be called
grub_xen_alloc_boot_data()or something like that.Then my previous comment is still valid.
What about naming it
grub_xen_alloc_kernel_mapping()? This is what it really does: It is allocating all not yet allocated areas which are to be included in the initial kernel mapping.This function does three things:
- allocate memory for p2m array,
- allocate special pages (e.g. console),
- allocate memory for page tables.Quoted 9 lines
Three of them are part of boot data described by struct
start_info. Well, there are also other required stuff to properly boot PV guest. So, I can agree thatgrub_xen_alloc_boot_data()is not perfect but I cannot find anything better. Additionally, IMOgrub_xen_alloc_kernel_mapping()is not right choice too. It suggests that this functions does anything with kernel mapping. Yep, it does, however, this is only one third of this function. So, I tend to use my proposal or anything better which is short and quite well describes what is going in this function as whole.
Quoted 1 line
Yeah.
grub_xen_alloc_stuff()with a nice comment. ;-)
:-))) I thought about that one too!
Quoted 3 lines
Okay, lets stick with
grub_xen_alloc_boot_data()and add a comment explaining that the function will allocate everything not yet allocated and covered by the initial page tables.
LGTM. Granted!
Daniel
Juergen Gross
maintainerPATCH v5 10/11 xen: modify page table construction
In reply to Juergen GrossModify the page table construction to allow multiple virtual regions to be mapped. This is done as preparation for removing the p2m list from the initial kernel mapping in order to support huge pv domains.
This allows a cleaner approach for mapping the relocator page by using this capability.
The interface to the assembler level of the relocator has to be changed in order to be able to process multiple page table areas.
---
V4: align variables in assembly sources
use separate structure define as requested by Daniel Kiper
V3: use constants instead of numbers as requested by Daniel Kiper
add lots of comments to assembly code as requested by Daniel Kiper
--- grub-core/lib/i386/xen/relocator.S | 88 ++++++---- grub-core/lib/x86_64/xen/relocator.S | 135 ++++++-------- grub-core/lib/xen/relocator.c | 28 ++- grub-core/loader/i386/xen.c | 329 +++++++++++++++++++++++------------ include/grub/i386/memory.h | 7 + include/grub/xen/relocator.h | 6 +- 6 files changed, 360 insertions(+), 233 deletions(-)
grub-core/lib/i386/xen/relocator.S +52 -36
@@ -16,6 +16,8 @@ * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ +#include <grub/i386/memory.h> +#include <grub/i386/types.h> #include <grub/symbol.h> #include <grub/xen.h>
@@ -23,78 +25,86 @@ VARIABLE(grub_relocator_xen_remap_start) LOCAL(base): - /* mov imm32, %ebx */ + /* Remap the remapper to it's new address. */ + /* mov imm32, %ebx - %ebx: new virtual address of remapper */ .byte 0xbb VARIABLE(grub_relocator_xen_remapper_virt) .long 0 - /* mov imm32, %ecx */ + /* mov imm32, %ecx - %ecx: low part of page table entry */ .byte 0xb9 VARIABLE(grub_relocator_xen_remapper_map) .long 0 - /* mov imm32, %edx */ + /* mov imm32, %edx - %edx: high part of page table entry */ .byte 0xba VARIABLE(grub_relocator_xen_remapper_map_high) .long 0 - movl %ebx, %ebp + movl %ebx, %ebp /* %ebx is clobbered by hypercall */ - movl $2, %esi + movl $UVMF_INVLPG, %esi /* esi: flags (inv. single entry) */ movl $__HYPERVISOR_update_va_mapping, %eax int $0x82 movl %ebp, %ebx addl $(LOCAL(cont) - LOCAL(base)), %ebx - jmp *%ebx + jmp *%ebx /* Continue with new virtual address */ LOCAL(cont): - xorl %eax, %eax - movl %eax, %ebp + /* Modify mappings of new page tables to be read-only. */ + /* mov imm32, %eax */ + .byte 0xb8 +VARIABLE(grub_relocator_xen_paging_areas_addr) + .long 0 + movl %eax, %ebx 1: + movl 0(%ebx), %ebp /* Get start pfn of the current area */ + movl GRUB_TARGET_SIZEOF_LONG(%ebx), %ecx /* Get # of pg tables */ + testl %ecx, %ecx /* 0 -> last area reached */ + jz 3f + addl $(2 * GRUB_TARGET_SIZEOF_LONG), %ebx + movl %ebx, %esp /* Save current area pointer */ +2: + movl %ecx, %edi /* mov imm32, %eax */ .byte 0xb8 VARIABLE(grub_relocator_xen_mfn_list) .long 0 - movl %eax, %edi - movl %ebp, %eax - movl 0(%edi, %eax, 4), %ecx - - /* mov imm32, %ebx */ - .byte 0xbb -VARIABLE(grub_relocator_xen_paging_start) - .long 0 - shll $12, %eax - addl %eax, %ebx + movl 0(%eax, %ebp, 4), %ecx /* mfn */ + movl %ebp, %ebx + shll $PAGE_SHIFT, %ebx /* virtual address (1:1 mapping) */ movl %ecx, %edx - shll $12, %ecx - shrl $20, %edx - orl $5, %ecx - movl $2, %esi + shll $PAGE_SHIFT, %ecx /* prepare pte low part */ + shrl $(32 - PAGE_SHIFT), %edx /* pte high part */ + orl $(GRUB_PAGE_PRESENT | GRUB_PAGE_USER), %ecx /* pte low */ + movl $UVMF_INVLPG, %esi movl $__HYPERVISOR_update_va_mapping, %eax - int $0x82 + int $0x82 /* parameters: eax, ebx, ecx, edx, esi */ - incl %ebp - /* mov imm32, %ecx */ - .byte 0xb9 -VARIABLE(grub_relocator_xen_paging_size) - .long 0 - cmpl %ebp, %ecx + incl %ebp /* next pfn */ + movl %edi, %ecx - ja 1b + loop 2b + mov %esp, %ebx /* restore area poniter */ + jmp 1b + +3: + /* Switch page tables: pin new L3 pt, load cr3, unpin old L3. */ /* mov imm32, %ebx */ .byte 0xbb VARIABLE(grub_relocator_xen_mmu_op_addr) .long 0 - movl $3, %ecx - movl $0, %edx - movl $0x7FF0, %esi + movl $3, %ecx /* 3 mmu ops */ + movl $0, %edx /* pdone (not used) */ + movl $DOMID_SELF, %esi movl $__HYPERVISOR_mmuext_op, %eax int $0x82 + /* Continue in virtual kernel mapping. */ /* mov imm32, %eax */ .byte 0xb8 VARIABLE(grub_relocator_xen_remap_continue)
@@ -102,6 +112,10 @@ VARIABLE(grub_relocator_xen_remap_continue) jmp *%eax + .p2align 2 +VARIABLE(grub_relocator_xen_paging_areas) + .long 0, 0, 0, 0, 0, 0, 0, 0 + VARIABLE(grub_relocator_xen_mmu_op) .space 256
@@ -109,6 +123,7 @@ VARIABLE(grub_relocator_xen_remap_end) VARIABLE(grub_relocator_xen_start) + /* Unmap old remapper area. */ /* mov imm32, %eax */ .byte 0xb8 VARIABLE(grub_relocator_xen_remapper_virt2)
@@ -116,14 +131,14 @@ VARIABLE(grub_relocator_xen_remapper_virt2) movl %eax, %edi - xorl %ecx, %ecx + xorl %ecx, %ecx /* Invalid pte */ xorl %edx, %edx - movl $2, %esi + movl $UVMF_INVLPG, %esi movl $__HYPERVISOR_update_va_mapping, %eax int $0x82 - + /* Prepare registers for starting kernel. */ /* mov imm32, %eax */ .byte 0xb8 VARIABLE(grub_relocator_xen_stack)
@@ -145,6 +160,7 @@ VARIABLE(grub_relocator_xen_start_info) VARIABLE(grub_relocator_xen_entry_point) .long 0 + /* Now start the new kernel. */ jmp *%eax VARIABLE(grub_relocator_xen_end)
grub-core/lib/x86_64/xen/relocator.S +56 -79
197 lines not on this page · raw message
grub-core/lib/xen/relocator.c +20 -8
@@ -29,6 +29,11 @@typedef grub_addr_t grub_xen_reg_t ; +struct grub_relocator_xen_paging_area { +grub_xen_reg_t start; +grub_xen_reg_t size; +}; +extern grub_uint8_t grub_relocator_xen_start;extern grub_uint8_t grub_relocator_xen_end;extern grub_uint8_t grub_relocator_xen_remap_start;
@@ -36,15 +41,16 @@ extern grub_uint8_t grub_relocator_xen_remap_end;extern grub_xen_reg_t grub_relocator_xen_stack;extern grub_xen_reg_t grub_relocator_xen_start_info;extern grub_xen_reg_t grub_relocator_xen_entry_point; -extern grub_xen_reg_t grub_relocator_xen_paging_start; -extern grub_xen_reg_t grub_relocator_xen_paging_size;extern grub_xen_reg_t grub_relocator_xen_remapper_virt;extern grub_xen_reg_t grub_relocator_xen_remapper_virt2;extern grub_xen_reg_t grub_relocator_xen_remapper_map;extern grub_xen_reg_t grub_relocator_xen_mfn_list; +extern struct grub_relocator_xen_paging_area + grub_relocator_xen_paging_areas[XEN_MAX_MAPPINGS ];extern grub_xen_reg_t grub_relocator_xen_remap_continue;#ifdef __i386__extern grub_xen_reg_t grub_relocator_xen_mmu_op_addr; +extern grub_xen_reg_t grub_relocator_xen_paging_areas_addr;extern grub_xen_reg_t grub_relocator_xen_remapper_map_high;#endif extern mmuext_op_t grub_relocator_xen_mmu_op[3 ];
@@ -61,6 +67,7 @@ grub_relocator_xen_boot (struct grub_relocator *rel, {grub_err_t err;void *relst; +int i;grub_relocator_chunk_t ch, ch_tramp;grub_xen_mfn_t *mfn_list = (grub_xen_mfn_t *) grub_xen_start_page_addr->mfn_list;
@@ -77,8 +84,11 @@ grub_relocator_xen_boot (struct grub_relocator *rel, grub_relocator_xen_stack = state.stack; grub_relocator_xen_start_info = state.start_info; grub_relocator_xen_entry_point = state.entry_point; - grub_relocator_xen_paging_start = state.paging_start <<12 ; - grub_relocator_xen_paging_size = state.paging_size; +for (i =0 ; i <XEN_MAX_MAPPINGS ; i++) + { + grub_relocator_xen_paging_areas[i].start = state.paging_start[i]; + grub_relocator_xen_paging_areas[i].size = state.paging_size[i]; + } grub_relocator_xen_remapper_virt = remapper_virt; grub_relocator_xen_remapper_virt2 = remapper_virt; grub_relocator_xen_remap_continue = trampoline_virt;
@@ -88,10 +98,12 @@ grub_relocator_xen_boot (struct grub_relocator *rel, grub_relocator_xen_remapper_map_high = (mfn_list[remapper_pfn] >>20 ); grub_relocator_xen_mmu_op_addr = (char *) &grub_relocator_xen_mmu_op - (char *) &grub_relocator_xen_remap_start + remapper_virt; + grub_relocator_xen_paging_areas_addr = + (char *) &grub_relocator_xen_paging_areas + - (char *) &grub_relocator_xen_remap_start + remapper_virt;#endif - grub_relocator_xen_mfn_list = state.mfn_list - + state.paging_start *sizeof (grub_addr_t); + grub_relocator_xen_mfn_list = state.mfn_list;grub_memset (grub_relocator_xen_mmu_op,0 ,sizeof (grub_relocator_xen_mmu_op));
@@ -100,9 +112,9 @@ grub_relocator_xen_boot (struct grub_relocator *rel,#else grub_relocator_xen_mmu_op[0 ].cmd =MMUEXT_PIN_L4_TABLE ;#endif - grub_relocator_xen_mmu_op[0 ].arg1.mfn = mfn_list[state.paging_start]; + grub_relocator_xen_mmu_op[0 ].arg1.mfn = mfn_list[state.paging_start[0 ]]; grub_relocator_xen_mmu_op[1 ].cmd =MMUEXT_NEW_BASEPTR ; - grub_relocator_xen_mmu_op[1 ].arg1.mfn = mfn_list[state.paging_start]; + grub_relocator_xen_mmu_op[1 ].arg1.mfn = mfn_list[state.paging_start[0 ]]; grub_relocator_xen_mmu_op[2 ].cmd =MMUEXT_UNPIN_TABLE ; grub_relocator_xen_mmu_op[2 ].arg1.mfn = mfn_list[grub_xen_start_page_addr->pt_base >>12 ];
grub-core/loader/i386/xen.c +221 -108
405 lines not on this page · raw message
include/grub/i386/memory.h +7 -0
@@ -20,6 +20,8 @@#ifndef GRUB_MEMORY_CPU_HEADER #define GRUB_MEMORY_CPU_HEADER 1 +#define PAGE_SHIFT 12 +/* The flag for protected mode. */ #define GRUB_MEMORY_CPU_CR0_PE_ON 0x1#define GRUB_MEMORY_CPU_CR4_PAE_ON 0x00000020
@@ -31,6 +33,11 @@#define GRUB_MEMORY_MACHINE_UPPER_START 0x100000/* 1 MiB */ #define GRUB_MEMORY_MACHINE_LOWER_SIZE GRUB_MEMORY_MACHINE_UPPER_START +/* Some PTE definitions. */ +#define GRUB_PAGE_PRESENT 0x00000001 +#define GRUB_PAGE_RW 0x00000002 +#define GRUB_PAGE_USER 0x00000004 +#ifndef ASM_FILE #define GRUB_MMAP_MALLOC_LOW 1
include/grub/xen/relocator.h +4 -2
@@ -23,11 +23,13 @@#include <grub/err.h> #include <grub/relocator.h> +#define XEN_MAX_MAPPINGS 3 +struct grub_relocator_xen_state {grub_addr_t start_info; -grub_addr_t paging_start; -grub_addr_t paging_size; +grub_addr_t paging_start[XEN_MAX_MAPPINGS ]; +grub_addr_t paging_size[XEN_MAX_MAPPINGS ];grub_addr_t mfn_list;grub_addr_t stack;grub_addr_t entry_point;
Signature · 7 lines
2.6.2 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v5 10/11] xen: modify page table construction
Quoted 11 lines · Juergen Gross
Modify the page table construction to allow multiple virtual regions to be mapped. This is done as preparation for removing the p2m list from the initial kernel mapping in order to support huge pv domains.
This allows a cleaner approach for mapping the relocator page by using this capability.
The interface to the assembler level of the relocator has to be changed in order to be able to process multiple page table areas.
Signed-off-by Juergen Gross <[email protected]>
Daniel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v5 10/11] xen: modify page table construction
In reply to Juergen GrossQuoted 11 lines · Juergen Gross
Modify the page table construction to allow multiple virtual regions to be mapped. This is done as preparation for removing the p2m list from the initial kernel mapping in order to support huge pv domains.
This allows a cleaner approach for mapping the relocator page by using this capability.
The interface to the assembler level of the relocator has to be changed in order to be able to process multiple page table areas.
Signed-off-by Juergen Gross <[email protected]>
Daniel
Juergen Gross
maintainerPATCH v5 11/11 xen: add capability to load p2m list outside of kernel mapping
In reply to Juergen GrossModern pvops linux kernels support a p2m list not covered by the kernel mapping. This capability is flagged by an elf-note specifying the virtual address the kernel is expecting the p2m list to be mapped to.
In case the elf-note is set by the kernel don't place the p2m list into the kernel mapping, but map it to the given address. This will allow to support domains with larger memory, as the kernel mapping is limited to 2GB and a domain with huge memory in the TB range will have a p2m list larger than this.
--- grub-core/loader/i386/xen.c | 53 +++++++++++++++++++++++++++++++------- grub-core/loader/i386/xen_fileXX.c | 4 +++ include/grub/xen_file.h | 2 ++ 3 files changed, 50 insertions(+), 9 deletions(-)
grub-core/loader/i386/xen.c +44 -9
@@ -313,24 +313,50 @@ static grub_err_tgrub_xen_p2m_alloc (void) {grub_relocator_chunk_t ch; -grub_size_t p2msize; +grub_size_t p2msize, p2malloc;grub_err_t err; +struct grub_xen_mapping *map;if (xen_state.virt_mfn_list)return GRUB_ERR_NONE ; + map = xen_state.mappings + xen_state.n_mappings; + p2msize =ALIGN_UP (sizeof (grub_xen_mfn_t) * + grub_xen_start_page_addr->nr_pages,PAGE_SIZE ); +if (xen_state.xen_inf.has_p2m_base) + { + err =get_pgtable_size (xen_state.xen_inf.p2m_base, + xen_state.xen_inf.p2m_base + p2msize, + (xen_state.max_addr + p2msize) >>PAGE_SHIFT ); +if (err) +return err; + + map->area.pfn_start = xen_state.max_addr >>PAGE_SHIFT ; + p2malloc = p2msize +page2offset (map->area.n_pt_pages); + xen_state.n_mappings++; + xen_state.next_start.mfn_list = xen_state.xen_inf.p2m_base; + xen_state.next_start.first_p2m_pfn = map->area.pfn_start; + xen_state.next_start.nr_p2m_frames = p2malloc >>PAGE_SHIFT ; + } +else + { + xen_state.next_start.mfn_list = + xen_state.max_addr + xen_state.xen_inf.virt_base; + p2malloc = p2msize; + } + xen_state.state.mfn_list = xen_state.max_addr; - xen_state.next_start.mfn_list = - xen_state.max_addr + xen_state.xen_inf.virt_base; - p2msize =sizeof (grub_xen_mfn_t) * grub_xen_start_page_addr->nr_pages; err =grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, - xen_state.max_addr, p2msize); + xen_state.max_addr, p2malloc);if (err)return err; xen_state.virt_mfn_list =get_virtual_current_address (ch); +if (xen_state.xen_inf.has_p2m_base) + map->where = (grub_uint64_t *) xen_state.virt_mfn_list + + p2msize /sizeof (grub_uint64_t);grub_memcpy (xen_state.virt_mfn_list, (void *) grub_xen_start_page_addr->mfn_list, p2msize); - xen_state.max_addr =ALIGN_UP (xen_state.max_addr + p2msize,PAGE_SIZE ); + xen_state.max_addr += p2malloc;return GRUB_ERR_NONE ; }
@@ -447,9 +473,12 @@ grub_xen_alloc_final (void) {grub_err_t err; - err =grub_xen_p2m_alloc (); -if (err) -return err; +if (!xen_state.xen_inf.has_p2m_base) + { + err =grub_xen_p2m_alloc (); +if (err) +return err; + } err =grub_xen_special_alloc ();if (err)return err;
@@ -474,6 +503,12 @@ grub_xen_boot (void) err =grub_xen_alloc_final ();if (err)return err; +if (xen_state.xen_inf.has_p2m_base) + { + err =grub_xen_p2m_alloc (); +if (err) +return err; + } err =set_mfns (xen_state.console_pfn);if (err)
grub-core/loader/i386/xen_fileXX.c +4 -0
@@ -261,6 +261,10 @@ parse_note (grub_elf_t elf, struct grub_xen_file_info *xi, descsz == 2 ? 2 : 3) == 0) xi->arch =GRUB_XEN_FILE_I386 ;break ; +case XEN_ELFNOTE_INIT_P2M : + xi->p2m_base =grub_le_to_cpu_addr (*(Elf_Addr *) desc); + xi->has_p2m_base =1 ; +break ;case XEN_ELFNOTE_MOD_START_PFN : xi->unmapped_initrd = !!grub_le_to_cpu32 (*(grub_uint32_t *) desc);break ;
include/grub/xen_file.h +2 -0
@@ -32,9 +32,11 @@ struct grub_xen_file_infogrub_uint64_t entry_point;grub_uint64_t hypercall_page;grub_uint64_t paddr_offset; +grub_uint64_t p2m_base;int has_hypercall_page;int has_note;int has_xen_guest; +int has_p2m_base;int extended_cr3;int unmapped_initrd; enum
Signature · 7 lines
2.6.2 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel