v3: Boot modules for Hyperlaunch
PATCH 3/10 x86 setup: change bootstrap map to accept new boot module structures
In reply to Christopher ClarkTo convert the x86 boot logic from multiboot to boot module structures, change the bootstrap map function to accept a boot module parameter.
To allow incremental change from multiboot to boot modules across all x86 setup logic, provide a temporary inline wrapper that still accepts a multiboot module parameter and use it where necessary. The wrapper is placed in a new arch/x86 header <asm/boot.h> to avoid putting a static inline function into an existing header that has no such functions already. This new header will be expanded with additional functions in subsequent patches in this series.
No functional change intended.
---
A new patch so v1 series patch 3 can be implemented incrementally instead.
xen/arch/x86/cpu/microcode/core.c | 7 ++++--- xen/arch/x86/hvm/dom0_build.c | 4 +++- xen/arch/x86/include/asm/boot.h | 32 +++++++++++++++++++++++++++++++ xen/arch/x86/include/asm/setup.h | 3 ++- xen/arch/x86/pv/dom0_build.c | 3 ++- xen/arch/x86/setup.c | 18 +++++++++-------- xen/include/xen/bootinfo.h | 3 +++ xen/xsm/xsm_policy.c | 3 ++- 8 files changed, 58 insertions(+), 15 deletions(-) create mode 100644 xen/arch/x86/include/asm/boot.h
xen/arch/x86/cpu/microcode/core.c +4 -3
@@ -34,6 +34,7 @@#include <xen/watchdog.h> #include <asm/apic.h> +#include <asm/boot.h> #include <asm/cpu-policy.h> #include <asm/delay.h> #include <asm/nmi.h>
@@ -180,7 +181,7 @@ void __init microcode_scan_module(if ( !test_bit (i, module_map) )continue ; - _blob_start =bootstrap_map (&mod[i]); + _blob_start =bootstrap_map_multiboot (&mod[i]); _blob_size = mod[i].mod_end;if ( !_blob_start ) {
@@ -798,7 +799,7 @@ int __init microcode_init_cache(unsigned long *module_map,microcode_scan_module (module_map, mbi);if ( ucode_mod.mod_end ) - rc =early_update_cache (bootstrap_map (&ucode_mod), + rc =early_update_cache (bootstrap_map_multiboot (&ucode_mod), ucode_mod.mod_end);else if ( ucode_blob.size ) rc =early_update_cache (ucode_blob.data, ucode_blob.size);
@@ -821,7 +822,7 @@ static int __init early_microcode_update_cpu(void)else if ( ucode_mod.mod_end ) { len = ucode_mod.mod_end; - data =bootstrap_map (&ucode_mod); + data =bootstrap_map_multiboot (&ucode_mod); }if ( !data )
xen/arch/x86/hvm/dom0_build.c +3 -1
@@ -16,6 +16,7 @@#include <acpi/actables.h> +#include <asm/boot.h> #include <asm/bzimage.h> #include <asm/dom0_build.h> #include <asm/hvm/support.h>
@@ -1208,7 +1209,8 @@ int __init dom0_construct_pvh(struct domain *d, const module_t *image,return rc; } - rc =pvh_load_kernel (d, image, image_headroom, initrd,bootstrap_map (image), + rc =pvh_load_kernel (d, image, image_headroom, initrd, +bootstrap_map_multiboot (image), cmdline, &entry, &start_info);if ( rc ) {
xen/arch/x86/include/asm/boot.h new file +32 -0
@@ -0,0 +1,32 @@ +#ifndef __ASM_X86_BOOT_H__ +#define __ASM_X86_BOOT_H__ + +#include <xen/bootinfo.h> +#include <xen/multiboot.h> + +#include <asm/setup.h> + +static inline void *bootstrap_map_multiboot (const module_t *mod) +{ +struct boot_module bm; + +if ( !mod ) +return bootstrap_map (NULL ); + + bm.start = mod->mod_start <<PAGE_SHIFT ; + bm.size = mod->mod_end; + +return bootstrap_map (&bm); +} + +#endif + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
xen/arch/x86/include/asm/setup.h +2 -1
@@ -1,6 +1,7 @@#ifndef __X86_SETUP_H_#define __X86_SETUP_H_ +#include <xen/bootinfo.h> #include <xen/multiboot.h> #include <asm/numa.h>
@@ -40,7 +41,7 @@ void setup_io_bitmap(struct domain *d);unsigned long initial_images_nrpages (nodeid_t node);void discard_initial_images (void ); -void *bootstrap_map (const module_t *mod); +void *bootstrap_map (const struct boot_module *mod);int xen_in_range (unsigned long mfn);
xen/arch/x86/pv/dom0_build.c +2 -1
@@ -14,6 +14,7 @@#include <xen/sched.h> #include <xen/softirq.h> +#include <asm/boot.h> #include <asm/bzimage.h> #include <asm/dom0_build.h> #include <asm/guest.h>
@@ -374,7 +375,7 @@ int __init dom0_construct_pv(struct domain *d,unsigned int flush_flags =0 ;start_info_t *si;struct vcpu *v = d->vcpu[0 ]; -void *image_base =bootstrap_map (image); +void *image_base =bootstrap_map_multiboot (image);unsigned long image_len = image->mod_end;void *image_start = image_base + image_headroom;unsigned long initrd_len = initrd ? initrd->mod_end :0 ;
xen/arch/x86/setup.c +10 -8
@@ -32,6 +32,7 @@#include <compat/xen.h> #endif #include <xen/bitops.h> +#include <asm/boot.h> #include <asm/smp.h> #include <asm/processor.h> #include <asm/mpspec.h>
@@ -405,14 +406,14 @@ static void __init normalise_cpu_order(void)* Ensure a given physical memory range is present in the bootstrap mappings. * Use superpage mappings to ensure that pagetable memory needn't be allocated. */ -void *__init bootstrap_map (const module_t *mod) +void *__init bootstrap_map (const struct boot_module *mod) {static unsigned long __initdata map_cur =BOOTSTRAP_MAP_BASE ;uint64_t start, end, mask = (1L <<L2_PAGETABLE_SHIFT ) -1 ;void *ret;if ( system_state != SYS_STATE_early_boot ) -return mod ?mfn_to_virt (mod->mod_start) :NULL ; +return mod ?maddr_to_virt (mod->start) :NULL ;if ( !mod ) {
@@ -421,8 +422,8 @@ void *__init bootstrap_map(const module_t *mod)return NULL ; } - start = (uint64_t )mod->mod_start <<PAGE_SHIFT ; - end = start + mod->mod_end; + start = (uint64_t )mod->start; + end = start + mod->size;if ( start >= end )return NULL ;
@@ -460,7 +461,7 @@ static void __init move_memory(if ( mod.mod_end > blksz ) mod.mod_end = blksz; sz = mod.mod_end - soffs; - s =bootstrap_map (&mod); + s =bootstrap_map_multiboot (&mod); mod.mod_start = (dst - doffs) >>PAGE_SHIFT ; mod.mod_end = doffs + size;
@@ -468,7 +469,7 @@ static void __init move_memory( mod.mod_end = blksz;if ( sz > mod.mod_end - doffs ) sz = mod.mod_end - doffs; - d =bootstrap_map (&mod); + d =bootstrap_map_multiboot (&mod);memmove (d + doffs, s + soffs, sz);
@@ -1360,8 +1361,9 @@ void __init noreturn __start_xen(unsigned long mbi_p) mod[boot_info->nr_mods].mod_end = __2M_rwdata_end - _stext; } - boot_info->mods[0 ].arch->headroom =bzimage_headroom (bootstrap_map (mod), - mod->mod_end); + boot_info->mods[0 ].arch->headroom = +bzimage_headroom (bootstrap_map_multiboot (mod), mod->mod_end); +bootstrap_map (NULL );#ifndef highmem_start
xen/include/xen/bootinfo.h +3 -0
@@ -10,6 +10,9 @@#endif struct boot_module { +paddr_t start; +size_t size; +struct arch_bootmodule *arch; };
xen/xsm/xsm_policy.c +2 -1
@@ -20,6 +20,7 @@#include <xsm/xsm.h> #ifdef CONFIG_MULTIBOOT +#include <asm/boot.h> #include <xen/multiboot.h> #include <asm/setup.h> #endif
@@ -49,7 +50,7 @@ int __init xsm_multiboot_policy_init(if ( !test_bit (i, module_map) )continue ; - _policy_start =bootstrap_map (mod + i); + _policy_start =bootstrap_map_multiboot (mod + i); _policy_len = mod[i].mod_end;if ( (xsm_magic_t)(*_policy_start) ==XSM_MAGIC )
Signature · 1 line
2.25.1
PATCH 1/10 x86 setup: move x86 boot module counting into a new boot_info struct
In reply to Christopher ClarkAn initial step towards a non-multiboot internal representation of boot modules for common code, starting with x86 setup and converting the fields that are accessed for the startup calculations.
Introduce a new header, <xen/bootinfo.h>, and populate it with a new boot_info structure initially containing a count of the number of boot modules.
The naming of the header, structure and fields is intended to respect the boot structures on Arm -- see arm/include/asm/setup.h -- as part of work towards aligning common architecture-neutral boot logic and structures.
No functional change intended.
---
Changes since v1: patch is a subset of v1 series patches 2 and 3.
xen/arch/x86/setup.c | 58 +++++++++++++++++++++++--------------- xen/include/xen/bootinfo.h | 20 +++++++++++++ 2 files changed, 55 insertions(+), 23 deletions(-) create mode 100644 xen/include/xen/bootinfo.h
xen/arch/x86/setup.c +35 -23
@@ -1,3 +1,4 @@ +#include <xen/bootinfo.h> #include <xen/init.h> #include <xen/lib.h> #include <xen/err.h>
@@ -268,7 +269,16 @@ static int __init cf_check parse_acpi_param(const char *s)custom_param ("acpi" , parse_acpi_param);static const module_t *__initdata initial_images; -static unsigned int __initdata nr_initial_images; +static struct boot_info __initdata *boot_info; + +static void __init multiboot_to_bootinfo (multiboot_info_t *mbi) +{ +static struct boot_info __initdata info; + + info.nr_mods = mbi->mods_count; + + boot_info = &info; +}unsigned long __init initial_images_nrpages (nodeid_t node) {
@@ -277,7 +287,7 @@ unsigned long __init initial_images_nrpages(nodeid_t node)unsigned long nr;unsigned int i; -for ( nr = i =0 ; i < nr_initial_images; ++i ) +for ( nr = i =0 ; i < boot_info->nr_mods; ++i ) {unsigned long start = initial_images[i].mod_start;unsigned long end = start +PFN_UP (initial_images[i].mod_end);
@@ -293,7 +303,7 @@ void __init discard_initial_images(void) {unsigned int i; -for ( i =0 ; i < nr_initial_images; ++i ) +for ( i =0 ; i < boot_info->nr_mods; ++i ) {uint64_t start = (uint64_t )initial_images[i].mod_start <<PAGE_SHIFT ;
@@ -301,7 +311,7 @@ void __init discard_initial_images(void) start + PAGE_ALIGN(initial_images[i].mod_end)); } - nr_initial_images =0 ; + boot_info->nr_mods =0 ; initial_images =NULL ; }
@@ -1020,6 +1030,8 @@ void __init noreturn __start_xen(unsigned long mbi_p) mod =__va (mbi->mods_addr); } +multiboot_to_bootinfo (mbi); + loader = (mbi->flags &MBI_LOADERNAME ) ? (char *)__va (mbi->boot_loader_name) :"unknown" ;
@@ -1127,18 +1139,18 @@ void __init noreturn __start_xen(unsigned long mbi_p) bootsym(boot_edd_info_nr));/* Check that we have at least one Multiboot module. */ -if ( !(mbi->flags &MBI_MODULES ) || (mbi->mods_count ==0 ) ) +if ( !(mbi->flags &MBI_MODULES ) || (boot_info->nr_mods ==0 ) )panic ("dom0 kernel not specified. Check bootloader configuration\n" );/* Check that we don't have a silly number of modules. */ -if ( mbi->mods_count >sizeof (module_map) *8 ) +if ( boot_info->nr_mods >sizeof (module_map) *8 ) { - mbi->mods_count =sizeof (module_map) *8 ; + boot_info->nr_mods =sizeof (module_map) *8 ;printk ("Excessive multiboot modules - using the first %u only\n" , - mbi->mods_count); + boot_info->nr_mods); } -bitmap_fill (module_map, mbi->mods_count); +bitmap_fill (module_map, boot_info->nr_mods);__clear_bit (0 , module_map);/* Dom0 kernel is always first */ if ( pvh_boot )
@@ -1311,9 +1323,9 @@ void __init noreturn __start_xen(unsigned long mbi_p)kexec_reserve_area (&boot_e820); initial_images = mod; - nr_initial_images = mbi->mods_count; + boot_info->nr_mods = boot_info->nr_mods; -for ( i =0 ; !efi_enabled (EFI_LOADER ) && i < mbi->mods_count; i++ ) +for ( i =0 ; !efi_enabled (EFI_LOADER ) && i < boot_info->nr_mods; i++ ) {if ( mod[i].mod_start & (PAGE_SIZE -1 ) )panic ("Bootloader didn't honor module alignment request\n" );
@@ -1337,8 +1349,8 @@ void __init noreturn __start_xen(unsigned long mbi_p)* respective reserve_e820_ram() invocation below. No need to * query efi_boot_mem_unused() here, though. */ - mod[mbi->mods_count].mod_start =virt_to_mfn (_stext); - mod[mbi->mods_count].mod_end = __2M_rwdata_end - _stext; + mod[boot_info->nr_mods].mod_start =virt_to_mfn (_stext); + mod[boot_info->nr_mods].mod_end = __2M_rwdata_end - _stext; } modules_headroom =bzimage_headroom (bootstrap_map (mod), mod->mod_end);
@@ -1398,7 +1410,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) {/* Don't overlap with modules. */ end =consider_modules (s, e, reloc_size + mask, - mod, mbi->mods_count,-1 ); + mod, boot_info->nr_mods,-1 ); end &= ~mask; } else
@@ -1419,7 +1431,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) }/* Is the region suitable for relocating the multiboot modules? */ -for ( j = mbi->mods_count -1 ; j >=0 ; j-- ) +for ( j = boot_info->nr_mods -1 ; j >=0 ; j-- ) {unsigned long headroom = j ?0 : modules_headroom;unsigned long size =PAGE_ALIGN (headroom + mod[j].mod_end);
@@ -1429,7 +1441,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)/* Don't overlap with other modules (or Xen itself). */ end =consider_modules (s, e, size, mod, - mbi->mods_count + relocated, j); + boot_info->nr_mods + relocated, j);if ( highmem_start && end > highmem_start )continue ;
@@ -1456,7 +1468,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) {/* Don't overlap with modules (or Xen itself). */ e =consider_modules (s, e,PAGE_ALIGN (kexec_crash_area.size), mod, - mbi->mods_count + relocated,-1 ); + boot_info->nr_mods + relocated,-1 );if ( s >= e )break ;if ( e > kexec_crash_area_limit )
@@ -1471,7 +1483,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)if ( modules_headroom && !mod->reserved )panic ("Not enough memory to relocate the dom0 kernel image\n" ); -for ( i =0 ; i < mbi->mods_count; ++i ) +for ( i =0 ; i < boot_info->nr_mods; ++i ) {uint64_t s = (uint64_t )mod[i].mod_start <<PAGE_SHIFT ;
@@ -1540,7 +1552,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)ASSERT (j); } map_e = boot_e820.map[j].addr + boot_e820.map[j].size; -for ( j =0 ; j < mbi->mods_count; ++j ) +for ( j =0 ; j < boot_info->nr_mods; ++j ) {uint64_t end =pfn_to_paddr (mod[j].mod_start) + mod[j].mod_end;
@@ -1616,7 +1628,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) } } -for ( i =0 ; i < mbi->mods_count; ++i ) +for ( i =0 ; i < boot_info->nr_mods; ++i ) {set_pdx_range (mod[i].mod_start, mod[i].mod_start +PFN_UP (mod[i].mod_end));
@@ -1999,8 +2011,8 @@ void __init noreturn __start_xen(unsigned long mbi_p) cpu_has_nx ?XENLOG_INFO :XENLOG_WARNING "Warning: " , cpu_has_nx ? "" : "not "); - initrdidx =find_first_bit (module_map, mbi->mods_count); -if (bitmap_weight (module_map, mbi->mods_count) >1 ) + initrdidx =find_first_bit (module_map, boot_info->nr_mods); +if (bitmap_weight (module_map, boot_info->nr_mods) >1 )printk (XENLOG_WARNING "Multiple initrd candidates, picking module #%u\n" , initrdidx);
@@ -2010,7 +2022,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)* above our heap. The second module, if present, is an initrd ramdisk. */ dom0 =create_dom0 (mod, modules_headroom, - initrdidx < mbi->mods_count ? mod + initrdidx :NULL , + initrdidx < boot_info->nr_mods ? mod + initrdidx :NULL , kextra, loader);if ( !dom0 )panic ("Could not set up DOM0 guest OS\n" );
xen/include/xen/bootinfo.h new file +20 -0
@@ -0,0 +1,20 @@ +#ifndef __XEN_BOOTINFO_H__ +#define __XEN_BOOTINFO_H__ + +#include <xen/types.h> + +struct boot_info { +unsigned int nr_mods; +}; + +#endif + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
Signature · 1 line
2.25.1
PATCH 5/10 xsm: switch XSM init to boot info structures
In reply to Christopher ClarkChange the XSM implementation to use the boot info structure instead of the multiboot module_map.
Drops a dependency on CONFIG_MULTIBOOT, so boot module logic is now used whenever the DEVICE_TREE specific logic (for Arm) is not, with the bootinfo header conditionally included to ensure no change on Arm.
Adds a multiboot header inclusion into guest/xen/pvh-boot.c since it is no longer provided via transitive inclusion and the source in that file uses multiboot structures.
---
Changes since v1: patch is a subset of v1 series patches 2 and 3.
- Added the <xen/multiboot.h> inclusion to pvh-boot.c
- Use conditional inclusion for <xen/bootinfo.h>
xen/arch/x86/guest/xen/pvh-boot.c | 1 + xen/arch/x86/setup.c | 2 +- xen/include/xsm/xsm.h | 28 +++++++-------- xen/xsm/xsm_core.c | 47 +++++++++++++++--------- xen/xsm/xsm_policy.c | 59 ++++++++++++++++--------------- 5 files changed, 77 insertions(+), 60 deletions(-)
xen/arch/x86/guest/xen/pvh-boot.c +1 -0
@@ -9,6 +9,7 @@#include <xen/init.h> #include <xen/lib.h> #include <xen/mm.h> +#include <xen/multiboot.h> #include <asm/e820.h> #include <asm/guest.h>
xen/arch/x86/setup.c +1 -1
@@ -1835,7 +1835,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) mmio_ro_ranges =rangeset_new (NULL ,"r/o mmio ranges" , RANGESETF_prettyprint_hex); -xsm_multiboot_init (module_map, mbi); +xsm_bootmodule_init (boot_info);/* * IOMMU-related ACPI table parsing may require some of the system domains
xen/include/xsm/xsm.h +14 -14
@@ -16,8 +16,10 @@#define __XSM_H__#include <xen/alternative-call.h> +#ifndef CONFIG_HAS_DEVICE_TREE +# include <xen/bootinfo.h> +#endif #include <xen/sched.h> -#include <xen/multiboot.h> /* policy magic number (defined by XSM_MAGIC) */ typedef uint32_t xsm_magic_t ;
@@ -776,15 +778,14 @@ static inline int xsm_argo_send(const struct domain *d, const struct domain *t)#endif /* XSM_NO_WRAPPERS */ -#ifdef CONFIG_MULTIBOOT -int xsm_multiboot_init ( -unsigned long *module_map,const multiboot_info_t *mbi); -int xsm_multiboot_policy_init ( -unsigned long *module_map,const multiboot_info_t *mbi, -void **policy_buffer,size_t *policy_size); -#endif +#ifndef CONFIG_HAS_DEVICE_TREE +int xsm_bootmodule_init (const struct boot_info *info); +int xsm_bootmodule_policy_init ( +const struct boot_info *info,const unsigned char **policy_buffer, +size_t *policy_size); + +#else -#ifdef CONFIG_HAS_DEVICE_TREE /* * Initialize XSM *
@@ -826,15 +827,14 @@ static const inline struct xsm_ops *silo_init(void)#include <xsm/dummy.h> -#ifdef CONFIG_MULTIBOOT -static inline int xsm_multiboot_init ( -unsigned long *module_map,const multiboot_info_t *mbi) +#ifndef CONFIG_HAS_DEVICE_TREE +static inline int xsm_bootmodule_init (const struct boot_info *info) {return 0 ; } -#endif -#ifdef CONFIG_HAS_DEVICE_TREE +#else +static inline int xsm_dt_init (void ) {return 0 ;
xen/xsm/xsm_core.c +30 -17
82 lines not on this page · raw message
xen/xsm/xsm_policy.c +31 -28
93 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH 7/10 x86 boot: define paddr_t and add macros for typedefing struct pointers
In reply to Christopher ClarkPointer fields within structs need to be defined as fixed size types in the x86 boot build environment. Using a typedef for the field type rather than a struct pointer type enables the type definition to be changed in the 32-bit boot build and the main hypervisor build, allowing for a single common structure definition and a common header file.
Introduces DEFINE_STRUCT_PTR_TYPE and DEFINE_PTR_TYPE which will generate typedefs with a _ptr_t suffix for pointers to the specified type. This is then used in <xen/bootinfo.h> for pointers within structs as preparation for using these headers in the x86 boot build.
The 32-bit behaviour is obtained by inclusion of "defs.h" first with a check for such an existing definition on the <xen/types.h> version.
paddr_t is used in <xen/bootinfo.h> so a definition is added here to the x86 boot environment defs.h header.
---
Changes since v2: This is two v2 patches merged into one for v3. Changes since v1: New in v2 of series.
xen/arch/x86/boot/defs.h | 9 +++++++++ xen/arch/x86/include/asm/bootinfo.h | 4 +++- xen/include/xen/bootinfo.h | 9 +++++---- xen/include/xen/types.h | 11 +++++++++++ 4 files changed, 28 insertions(+), 5 deletions(-)
xen/arch/x86/boot/defs.h +9 -0
@@ -60,4 +60,13 @@ typedef u64 uint64_t;#define U16_MAX ((u16)(~0U))#define UINT_MAX (~0U) +typedef unsigned long long paddr_t ; + +#define DEFINE_STRUCT_PTR_TYPE (struct_name) \ + typedef uint64_t struct_name ## _ptr_t; + +#define DEFINE_PTR_TYPE (type) \ + typedef uint64_t type ## _ptr_t; +DEFINE_PTR_TYPE (char); +#endif /* __BOOT_DEFS_H__ */
xen/arch/x86/include/asm/bootinfo.h +3 -1
@@ -6,6 +6,7 @@ struct arch_bootmodule {uint32_t flags;unsigned headroom; }; +DEFINE_STRUCT_PTR_TYPE (arch_bootmodule);struct arch_boot_info {uint32_t flags;
@@ -14,11 +15,12 @@ struct arch_boot_info {#define BOOTINFO_FLAG_X86_MEMMAP 1U << 6#define BOOTINFO_FLAG_X86_LOADERNAME 1U << 9 -char *boot_loader_name; +char_ptr_t boot_loader_name;uint32_t mmap_length;paddr_t mmap_addr; }; +DEFINE_STRUCT_PTR_TYPE (arch_boot_info);struct __packed mb_memmap {uint32_t size;
xen/include/xen/bootinfo.h +5 -4
@@ -35,17 +35,18 @@ struct boot_module {mfn_t mfn;size_t size; -struct arch_bootmodule *arch; +arch_bootmodule_ptr_t arch; struct boot_string string; }; +DEFINE_STRUCT_PTR_TYPE (boot_module);struct boot_info { -char *cmdline; +char_ptr_t cmdline;unsigned int nr_mods; -struct boot_module *mods; +boot_module_ptr_t mods; -struct arch_boot_info *arch; +arch_boot_info_ptr_t arch; };#endif
xen/include/xen/types.h +11 -0
@@ -71,4 +71,15 @@ typedef bool bool_t;#define test_and_set_bool (b) xchg(&(b), true)#define test_and_clear_bool (b) xchg(&(b), false) +#ifndef DEFINE_STRUCT_PTR_TYPE +#define DEFINE_STRUCT_PTR_TYPE (struct_name) \ + typedef struct struct_name * struct_name ## _ptr_t; +#endif + +#ifndef DEFINE_PTR_TYPE +#define DEFINE_PTR_TYPE (type) \ + typedef type * type ## _ptr_t; +DEFINE_PTR_TYPE (char); +#endif +#endif /* __TYPES_H__ */
Signature · 1 line
2.25.1
PATCH 8/10 x86, arm, riscv: add per-arch bootinfo headers
In reply to Christopher ClarkChanges to ensure that inclusion of <xen/bootinfo.h> succeeds in each of the main archtecture builds and in the 32-bit early x86 boot build.
The <xen/bootinfo.h> header contains structures that will be used in efi logic prior to the main start of Xen, so it needs to be suitable for inclusion in Arm source files.
The same header will also be included in early x86 boot logic, where asm/* headers are not reachable, and so they cannot be transitively included, so a ifdef condition is needed to prevent an attempt to include <asm/bootinfo.h> from within <xen/bootinfo.h> in that case.
The early x86 boot logic can then directly include <asm/bootinfo.h> via a specified directory path where it can be included successfully.
---
New for v2 series.
xen/arch/arm/include/asm/bootinfo.h | 20 ++++++++++++++++++++ xen/arch/riscv/include/asm/bootinfo.h | 20 ++++++++++++++++++++ xen/include/xen/bootinfo.h | 7 ++----- 3 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 xen/arch/arm/include/asm/bootinfo.h create mode 100644 xen/arch/riscv/include/asm/bootinfo.h
xen/arch/arm/include/asm/bootinfo.h new file +20 -0
@@ -0,0 +1,20 @@ +#ifndef __ARCH_ARM_BOOTINFO_H__ +#define __ARCH_ARM_BOOTINFO_H__ + +struct __packed arch_bootmodule { }; +DEFINE_STRUCT_PTR_TYPE (arch_bootmodule); + +struct __packed arch_boot_info { }; +DEFINE_STRUCT_PTR_TYPE (arch_boot_info); + +#endif + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
xen/arch/riscv/include/asm/bootinfo.h new file +20 -0
@@ -0,0 +1,20 @@ +#ifndef __ARCH_ARM_BOOTINFO_H__ +#define __ARCH_ARM_BOOTINFO_H__ + +struct __packed arch_bootmodule { }; +DEFINE_STRUCT_PTR_TYPE (arch_bootmodule); + +struct __packed arch_boot_info { }; +DEFINE_STRUCT_PTR_TYPE (arch_boot_info); + +#endif + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
xen/include/xen/bootinfo.h +2 -5
@@ -5,11 +5,8 @@#include <xen/compiler.h> #include <xen/mm-frame.h> -#ifdef CONFIG_X86 -#include <asm/bootinfo.h> -#else -struct arch_bootmodule { }; -struct arch_boot_info { }; +#if definedCONFIG_X86 ||CONFIG_ARM ||CONFIG_RISCV +# include <asm/bootinfo.h> #endif /* Boot module binary type / purpose */
Signature · 1 line
2.25.1
cover v3: Boot modules for Hyperlaunch
This is a v3 series of work for Hyperlaunch for the Xen hypervisor, an update to v2 and implementing a subset of the v1 series and functionality, with changes made to address the community feedback provided on the patches. Changes since the earlier versions of the series are described below.
The patches in this series are primarily derived from patches 2-4 of the v1 full series, in a series of smaller patches for ease of review.
Thanks to AMD for supporting this work.
Documentation on Hyperlaunch:
https://wiki.xenproject.org/wiki/Hyperlaunch
v1 Hyperlaunch patch series:
https://lists.xenproject.org/archives/html/xen-devel/2022-07/msg00345.html
thanks
Christopher
Changes since v2:
- combined v2 patches 7 and 8 for common review
- rebased the v2 series onto the current tip of staging (sorry)
- fixed the placement of the patch changelogs
- provided the changes description in the cover letter
Changes since v1:
- the v2 and v3 series implement functionality from v1 patches 2-4
- v2 series objective is to enable efficient patch review in support of merging the functionality into the hypervisor. It implements a subset of the v1 series, incorporating changes from community feedback.
- the bootstrap map is made accessible early in the v2 series via both multiboot and boot module arguments until later in the series where multiboot use is retired. This allows for incremental conversion across several patches from multiboot to boot modules.
- the 32-bit x86 boot environment header is removed, and changes are made to allow the new common bootinfo headers to be used instead.
- Arm and RISC-V architecture bootinfo headers are added to ensure that builds on those architectures can complete correctly.
- The KConfig patch to set the maximum number of boot modules allowed is not included in this series, replaced with a static maximum define.
Christopher Clark (10):
x86 setup: move x86 boot module counting into a new boot_info struct x86 setup: per-arch bootmodule structure, headroom field x86 setup: change bootstrap map to accept new boot module structures x86 setup: porting dom0 construction logic to boot module structures
xsm: switch XSM init to boot info structures
x86 setup, microcode: switch to the new bootinfo structures x86 boot: define paddr_t and add macros for typedefing struct pointers x86, arm, riscv: add per-arch bootinfo headers
arm setup: use common integer-typed bootmod definition
x86 setup: refactor efi, pvh and multiboot entrypoints to new boot
info
xen/arch/arm/efi/efi-boot.h | 6 + xen/arch/arm/include/asm/bootinfo.h | 20 ++ xen/arch/arm/include/asm/setup.h | 11 +- xen/arch/riscv/include/asm/bootinfo.h | 20 ++ xen/arch/x86/boot/defs.h | 10 + xen/arch/x86/boot/reloc.c | 192 ++++++++++++------ xen/arch/x86/bzimage.c | 10 +- xen/arch/x86/cpu/microcode/core.c | 149 ++++++++------ xen/arch/x86/dom0_build.c | 10 +- xen/arch/x86/efi/efi-boot.h | 95 +++++---- xen/arch/x86/guest/xen/pvh-boot.c | 65 ++++-- xen/arch/x86/hvm/dom0_build.c | 44 ++-- xen/arch/x86/include/asm/boot.h | 55 +++++ xen/arch/x86/include/asm/bootinfo.h | 47 +++++ xen/arch/x86/include/asm/bzimage.h | 2 +- xen/arch/x86/include/asm/dom0_build.h | 13 +- xen/arch/x86/include/asm/guest/pvh-boot.h | 6 +- xen/arch/x86/include/asm/microcode.h | 7 +- xen/arch/x86/include/asm/setup.h | 7 +- xen/arch/x86/pv/dom0_build.c | 32 +-- xen/arch/x86/setup.c | 232 ++++++++++++---------- xen/common/efi/boot.c | 4 +- xen/include/xen/bootinfo.h | 62 ++++++ xen/include/xen/types.h | 11 + xen/include/xsm/xsm.h | 28 +-- xen/xsm/xsm_core.c | 47 +++-- xen/xsm/xsm_policy.c | 58 +++--- 27 files changed, 821 insertions(+), 422 deletions(-) create mode 100644 xen/arch/arm/include/asm/bootinfo.h create mode 100644 xen/arch/riscv/include/asm/bootinfo.h create mode 100644 xen/arch/x86/include/asm/boot.h create mode 100644 xen/arch/x86/include/asm/bootinfo.h create mode 100644 xen/include/xen/bootinfo.h
Signature · 1 line
2.25.1
PATCH 2/10 x86 setup: per-arch bootmodule structure, headroom field
Next step in incremental work towards adding a non-multiboot internal representation of boot modules, converting the fields being accessed for the startup calculations.
Add a new array of structs for per-boot-module state, though only allocate space for a single array entry in this change since that is all that is required for functionality modified in this patch: moving the headroom field for the image decompression calculation into a new per-arch boot module struct and then using it in x86 dom0 construction.
Introduces a per-arch header for x86 for arch-specific boot module structures, and add a member to the common boot module structure for access to it.
No functional change intended.
---
Changes since v1: patch is a subset of v1 series patches 2 and 3.
xen/arch/x86/bzimage.c | 10 +++++----- xen/arch/x86/hvm/dom0_build.c | 3 ++- xen/arch/x86/include/asm/bootinfo.h | 18 ++++++++++++++++++ xen/arch/x86/include/asm/bzimage.h | 2 +- xen/arch/x86/pv/dom0_build.c | 3 ++- xen/arch/x86/setup.c | 23 ++++++++++++++++------- xen/include/xen/bootinfo.h | 11 +++++++++++ 7 files changed, 55 insertions(+), 15 deletions(-) create mode 100644 xen/arch/x86/include/asm/bootinfo.h
xen/arch/x86/bzimage.c +5 -5
@@ -69,8 +69,6 @@ static __init int bzimage_check(struct setup_header *hdr, unsigned long len)return 1 ; } -static unsigned long __initdata orig_image_len; -unsigned long __init bzimage_headroom (void *image_start,unsigned long image_length) {
@@ -91,7 +89,6 @@ unsigned long __init bzimage_headroom(void *image_start,if (elf_is_elfbinary (image_start, image_length) )return 0 ; - orig_image_len = image_length; headroom =output_length (image_start, image_length);if (gzip_check (image_start, image_length)) {
@@ -105,11 +102,14 @@ unsigned long __init bzimage_headroom(void *image_start, }int __init bzimage_parse (void *image_base,void **image_start, +unsigned int headroom,unsigned long *image_len) {struct setup_header *hdr = (struct setup_header *)(*image_start);int err =bzimage_check (hdr, *image_len); -unsigned long output_len; +unsigned long output_len, orig_image_len; + + orig_image_len = *image_len - headroom;if ( err <0 )return err;
@@ -125,7 +125,7 @@ int __init bzimage_parse(void *image_base, void **image_start,BUG_ON (!(image_base < *image_start)); - output_len =output_length (*image_start, orig_image_len); + output_len =output_length (*image_start, *image_len);if ( (err =perform_gunzip (image_base, *image_start, orig_image_len)) >0 ) err =decompress (*image_start, orig_image_len, image_base);
xen/arch/x86/hvm/dom0_build.c +2 -1
@@ -545,7 +545,8 @@ static int __init pvh_load_kernel(struct domain *d, const module_t *image,struct vcpu *v = d->vcpu[0 ];int rc; -if ( (rc =bzimage_parse (image_base, &image_start, &image_len)) !=0 ) +if ( (rc =bzimage_parse (image_base, &image_start, image_headroom, + &image_len)) !=0 ) {printk ("Error trying to detect bz compressed kernel\n" );return rc;
xen/arch/x86/include/asm/bootinfo.h new file +18 -0
@@ -0,0 +1,18 @@ +#ifndef __ARCH_X86_BOOTINFO_H__ +#define __ARCH_X86_BOOTINFO_H__ + +struct arch_bootmodule { +unsigned headroom; +}; + +#endif + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
xen/arch/x86/include/asm/bzimage.h +1 -1
@@ -5,7 +5,7 @@unsigned long bzimage_headroom (void *image_start,unsigned long image_length); -int bzimage_parse (void *image_base,void **image_start, +int bzimage_parse (void *image_base,void **image_start,unsigned int headroom,unsigned long *image_len);#endif /* __X86_BZIMAGE_H__ */
xen/arch/x86/pv/dom0_build.c +2 -1
@@ -416,7 +416,8 @@ int __init dom0_construct_pv(struct domain *d, d->max_pages = ~0U ; -if ( (rc =bzimage_parse (image_base, &image_start, &image_len)) !=0 ) +if ( (rc =bzimage_parse (image_base, &image_start, image_headroom, + &image_len)) !=0 )return rc;if ( (rc =elf_init (&elf, image_start, image_len)) !=0 )
xen/arch/x86/setup.c +16 -7
@@ -273,10 +273,16 @@ static struct boot_info __initdata *boot_info;static void __init multiboot_to_bootinfo (multiboot_info_t *mbi) { -static struct boot_info __initdata info; +static struct boot_info __initdata info; +static struct boot_module __initdata boot_mods[1 ]; +static struct arch_bootmodule __initdata arch_boot_mods[1 ]; + + info.mods = boot_mods; info.nr_mods = mbi->mods_count; + boot_mods[0 ].arch = &arch_boot_mods[0 ]; + boot_info = &info; }
@@ -961,7 +967,8 @@ static struct domain *__init create_dom0(const module_t *image,write_cr4 (read_cr4 () & ~X86_CR4_SMAP ); } -if (construct_dom0 (d, image, headroom, initrd, cmdline) !=0 ) +if (construct_dom0 (d, image, boot_info->mods[0 ].arch->headroom, initrd, + cmdline) !=0 )panic ("Could not construct domain 0\n" );if ( cpu_has_smap )
@@ -985,7 +992,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)unsigned int initrdidx, num_parked =0 ;multiboot_info_t *mbi;module_t *mod; -unsigned long nr_pages, raw_max_page, modules_headroom, module_map[1 ]; +unsigned long nr_pages, raw_max_page, module_map[1 ];int i, j, e820_warn =0 , bytes =0 ;unsigned long eb_start, eb_end;bool acpi_boot_table_init_done = false, relocated = false;
@@ -1353,7 +1360,8 @@ void __init noreturn __start_xen(unsigned long mbi_p) mod[boot_info->nr_mods].mod_end = __2M_rwdata_end - _stext; } - modules_headroom =bzimage_headroom (bootstrap_map (mod), mod->mod_end); + boot_info->mods[0 ].arch->headroom =bzimage_headroom (bootstrap_map (mod), + mod->mod_end);bootstrap_map (NULL );#ifndef highmem_start
@@ -1433,7 +1441,8 @@ void __init noreturn __start_xen(unsigned long mbi_p)/* Is the region suitable for relocating the multiboot modules? */ for ( j = boot_info->nr_mods -1 ; j >=0 ; j-- ) { -unsigned long headroom = j ?0 : modules_headroom; +struct boot_module *boot_mods = boot_info->mods; +unsigned long headroom = j ?0 : boot_mods[0 ].arch->headroom;unsigned long size =PAGE_ALIGN (headroom + mod[j].mod_end);if ( mod[j].reserved )
@@ -1481,7 +1490,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)#endif } -if ( modules_headroom && !mod->reserved ) +if ( boot_info->mods[0 ].arch->headroom && !mod->reserved )panic ("Not enough memory to relocate the dom0 kernel image\n" );for ( i =0 ; i < boot_info->nr_mods; ++i ) {
@@ -2021,7 +2030,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)* We're going to setup domain0 using the module(s) that we stashed safely * above our heap. The second module, if present, is an initrd ramdisk. */ - dom0 =create_dom0 (mod, modules_headroom, + dom0 =create_dom0 (mod, boot_info->mods[0 ].arch->headroom, initrdidx < boot_info->nr_mods ? mod + initrdidx :NULL , kextra, loader);if ( !dom0 )
xen/include/xen/bootinfo.h +11 -0
@@ -3,8 +3,19 @@#include <xen/types.h> +#ifdef CONFIG_X86 +#include <asm/bootinfo.h> +#else +struct arch_bootmodule { }; +#endif + +struct boot_module { +struct arch_bootmodule *arch; +}; +struct boot_info {unsigned int nr_mods; +struct boot_module *mods; };#endif
Signature · 1 line
2.25.1
PATCH 9/10 arm setup: use common integer-typed bootmod definition
In reply to Christopher ClarkThis change enables inclusion of <xen/bootinfo.h> in Arm builds, required for subsequent patches in this series.
It replaces the enum definition of bootmodule_kind with bootmod_type_t as enums are not fixed size as needed for packed structs which are needed for boot structures in subsequent changes.
---
New for v2 series.
xen/arch/arm/include/asm/setup.h | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
xen/arch/arm/include/asm/setup.h +2 -9
@@ -3,6 +3,7 @@#include <public/version.h> #include <asm/p2m.h> +#include <xen/bootinfo.h> #include <xen/device_tree.h> #define MIN_FDT_ALIGN 8
@@ -12,15 +13,7 @@#define MAX_MODULES 32/* Current maximum useful modules */ -typedef enum { -BOOTMOD_XEN , -BOOTMOD_FDT , -BOOTMOD_KERNEL , -BOOTMOD_RAMDISK , -BOOTMOD_XSM , -BOOTMOD_GUEST_DTB , -BOOTMOD_UNKNOWN -}bootmodule_kind ; +typedef bootmod_type_t bootmodule_kind ;enum membank_type {/*
Signature · 1 line
2.25.1
PATCH 4/10 x86 setup: porting dom0 construction logic to boot module structures
In reply to Christopher ClarkAdjust the PV and PVH dom0 construction entry points to take boot module structures as parameters, and add further fields to the boot module structures to plumb the data needed to support this use. Populate these from the multiboot module data.
This change removes multiboot from the PV and PVH dom0 construction logic.
Introduce and use new inline accessor functions for navigating the boot module structures.
The per-boot-module arrays are expanded from singletons to accommodate all modules, up to a static maximum of 64 modules including Xen that can be accepted from a bootloader to match the previous value from the module map check.
The field that identifies the type of a boot module (kernel, ramdisk, etc) is introduced to the common boot module structure and declared as a non-enum integer type to allow the field to be of a known-size and so structure can be packed in a subsequent patch in the series, and it will then be reconciled with the equivalent Arm boot field type.
The command line provided by multiboot for each boot module is added directly to the boot_module structure, which is appropriate for this logic just replacing multiboot.
The maximum number of boot modules that a bootloader can provide in addition to the Xen hypervisor is preserved from prior logic with the module_map at 63.
---
Changes since v1: patch is a subset of v1 series patches 2 and 3.
- The module_map is kept for now since still in use.
- Move the static inline functions into a separate dedicated header.
- <mm-frame.h> and <compiler.h> replace prior inclusion of <mm.h> for simpler dependencies.
xen/arch/x86/dom0_build.c | 10 +- xen/arch/x86/hvm/dom0_build.c | 43 +++--- xen/arch/x86/include/asm/boot.h | 36 +++++ xen/arch/x86/include/asm/bootinfo.h | 24 +++ xen/arch/x86/include/asm/dom0_build.h | 13 +- xen/arch/x86/include/asm/setup.h | 4 +- xen/arch/x86/pv/dom0_build.c | 32 ++-- xen/arch/x86/setup.c | 206 +++++++++++++++----------- xen/include/xen/bootinfo.h | 27 ++++ 9 files changed, 254 insertions(+), 141 deletions(-)
xen/arch/x86/dom0_build.c +5 -5
@@ -4,6 +4,7 @@* Copyright (c) 2002-2005, K A Fraser */ +#include <xen/bootinfo.h> #include <xen/init.h> #include <xen/iocap.h> #include <xen/libelf.h>
@@ -562,9 +563,8 @@ int __init dom0_setup_permissions(struct domain *d)return rc; } -int __init construct_dom0 (struct domain *d,const module_t *image, -unsigned long image_headroom,module_t *initrd, -char *cmdline) +int __init construct_dom0 (struct domain *d,const struct boot_module *image, +struct boot_module *initrd,char *cmdline) {int rc;
@@ -576,9 +576,9 @@ int __init construct_dom0(struct domain *d, const module_t *image,process_pending_softirqs ();if (is_hvm_domain (d) ) - rc =dom0_construct_pvh (d, image, image_headroom, initrd, cmdline); + rc =dom0_construct_pvh (d, image, initrd, cmdline);else if (is_pv_domain (d) ) - rc =dom0_construct_pv (d, image, image_headroom, initrd, cmdline); + rc =dom0_construct_pv (d, image, initrd, cmdline);else panic ("Cannot construct Dom0. No guest interface available\n" );
xen/arch/x86/hvm/dom0_build.c +20 -23
95 lines not on this page · raw message
xen/arch/x86/include/asm/boot.h +36 -0
@@ -19,6 +19,42 @@ static inline void *bootstrap_map_multiboot(const module_t *mod)return bootstrap_map (&bm); } +static inline unsigned long bootmodule_index ( +const struct boot_info *info,bootmod_type_t bootmod_type, +unsigned long start) +{ +for ( ; start < info->nr_mods; start++ ) +if ( info->mods[start].bootmod_type == bootmod_type ) +return start; + +return info->nr_mods +1 ; +} + +static inline struct boot_module *bootmodule_next ( +const struct boot_info *info,bootmod_type_t bootmod_type) +{ +unsigned long i; + +for ( i =0 ; i < info->nr_mods; i++ ) +if ( info->mods[i].bootmod_type == bootmod_type ) +return &info->mods[i]; + +return NULL ; +} + +static inline void bootmodule_update_start (struct boot_module *bm, +paddr_t new_start) +{ + bm->start = new_start; + bm->mfn =maddr_to_mfn (new_start); +} + +static inline void bootmodule_update_mfn (struct boot_module *bm,mfn_t new_mfn) +{ + bm->mfn = new_mfn; + bm->start =mfn_to_maddr (new_mfn); +} +#endif /*
xen/arch/x86/include/asm/bootinfo.h +24 -0
@@ -2,9 +2,33 @@#define __ARCH_X86_BOOTINFO_H__struct arch_bootmodule { +#define BOOTMOD_FLAG_X86_RELOCATED 1U << 0 +uint32_t flags;unsigned headroom; }; +struct arch_boot_info { +uint32_t flags; +#define BOOTINFO_FLAG_X86_CMDLINE 1U << 2 +#define BOOTINFO_FLAG_X86_MODULES 1U << 3 +#define BOOTINFO_FLAG_X86_MEMMAP 1U << 6 +#define BOOTINFO_FLAG_X86_LOADERNAME 1U << 9 + +char *boot_loader_name; + +uint32_t mmap_length; +paddr_t mmap_addr; +}; + +struct __packed mb_memmap { +uint32_t size; +uint32_t base_addr_low; +uint32_t base_addr_high; +uint32_t length_low; +uint32_t length_high; +uint32_t type; +}; +#endif /*
xen/arch/x86/include/asm/dom0_build.h +5 -8
@@ -1,6 +1,7 @@#ifndef _DOM0_BUILD_H_#define _DOM0_BUILD_H_ +#include <xen/bootinfo.h> #include <xen/libelf.h> #include <xen/sched.h>
@@ -13,15 +14,11 @@ unsigned long dom0_compute_nr_pages(struct domain *d, unsigned long initrd_len);int dom0_setup_permissions (struct domain *d); -int dom0_construct_pv (struct domain *d,const module_t *image, -unsigned long image_headroom, -module_t *initrd, -char *cmdline); +int dom0_construct_pv (struct domain *d,const struct boot_module *image, +struct boot_module *initrd,char *cmdline); -int dom0_construct_pvh (struct domain *d,const module_t *image, -unsigned long image_headroom, -module_t *initrd, -char *cmdline); +int dom0_construct_pvh (struct domain *d,const struct boot_module *image, +struct boot_module *initrd,char *cmdline);unsigned long dom0_paging_pages (const struct domain *d,unsigned long nr_pages);
xen/arch/x86/include/asm/setup.h +2 -2
@@ -34,8 +34,8 @@ static inline void vesa_init(void) {};int construct_dom0 (struct domain *d, -const module_t *kernel,unsigned long kernel_headroom, -module_t *initrd, +const struct boot_module *kernel, +struct boot_module *initrd,char *cmdline);void setup_io_bitmap (struct domain *d);
xen/arch/x86/pv/dom0_build.c +16 -16
@@ -4,12 +4,12 @@* Copyright (c) 2002-2005, K A Fraser */ +#include <xen/bootinfo.h> #include <xen/console.h> #include <xen/domain.h> #include <xen/domain_page.h> #include <xen/init.h> #include <xen/libelf.h> -#include <xen/multiboot.h> #include <xen/pfn.h> #include <xen/sched.h> #include <xen/softirq.h>
@@ -356,9 +356,8 @@ static struct page_info * __init alloc_chunk(struct domain *d, }int __init dom0_construct_pv (struct domain *d, -const module_t *image, -unsigned long image_headroom, -module_t *initrd, +const struct boot_module *image, +struct boot_module *initrd,char *cmdline) {int i, rc, order, machine;
@@ -375,10 +374,10 @@ int __init dom0_construct_pv(struct domain *d,unsigned int flush_flags =0 ;start_info_t *si;struct vcpu *v = d->vcpu[0 ]; -void *image_base =bootstrap_map_multiboot (image); -unsigned long image_len = image->mod_end; -void *image_start = image_base + image_headroom; -unsigned long initrd_len = initrd ? initrd->mod_end :0 ; +void *image_base =bootstrap_map (image); +unsigned long image_len = image->size; +void *image_start = image_base + image->arch->headroom; +unsigned long initrd_len = initrd ? initrd->size :0 ;l4_pgentry_t *l4tab =NULL , *l4start =NULL ;l3_pgentry_t *l3tab =NULL , *l3start =NULL ;l2_pgentry_t *l2tab =NULL , *l2start =NULL ;
@@ -417,7 +416,7 @@ int __init dom0_construct_pv(struct domain *d, d->max_pages = ~0U ; -if ( (rc =bzimage_parse (image_base, &image_start, image_headroom, +if ( (rc =bzimage_parse (image_base, &image_start, image->arch->headroom, &image_len)) !=0 )return rc;
@@ -612,7 +611,7 @@ int __init dom0_construct_pv(struct domain *d, initrd_pfn = vinitrd_start ? (vinitrd_start - v_start) >>PAGE_SHIFT :domain_tot_pages (d); - initrd_mfn = mfn = initrd->mod_start; + initrd_mfn = mfn =mfn_x (initrd->mfn); count =PFN_UP (initrd_len);if ( d->arch.physaddr_bitsize && ((mfn + count -1 ) >> (d->arch.physaddr_bitsize -PAGE_SHIFT )) )
@@ -627,12 +626,13 @@ int __init dom0_construct_pv(struct domain *d,free_domheap_pages (page, order); page +=1UL << order; } -memcpy (page_to_virt (page),mfn_to_virt (initrd->mod_start), +memcpy (page_to_virt (page),maddr_to_virt (initrd->start), initrd_len); - mpt_alloc = (paddr_t )initrd->mod_start <<PAGE_SHIFT ; + mpt_alloc = (paddr_t )initrd->start;init_domheap_pages (mpt_alloc, mpt_alloc +PAGE_ALIGN (initrd_len)); - initrd->mod_start = initrd_mfn =mfn_x (page_to_mfn (page)); +bootmodule_update_mfn (initrd,page_to_mfn (page)); + initrd_mfn =mfn_x (initrd->mfn); }else {
@@ -640,7 +640,7 @@ int __init dom0_construct_pv(struct domain *d,if (assign_pages (mfn_to_page (_mfn (mfn++)),1 , d,0 ) )BUG (); } - initrd->mod_end =0 ; + initrd->size =0 ;iommu_memory_setup (d,"initrd" ,mfn_to_page (_mfn (initrd_mfn)),PFN_UP (initrd_len), &flush_flags);
@@ -654,7 +654,7 @@ int __init dom0_construct_pv(struct domain *d, nr_pages - domain_tot_pages(d));if ( initrd ) { - mpt_alloc = (paddr_t )initrd->mod_start <<PAGE_SHIFT ; + mpt_alloc = initrd->start;printk ("\n Init. ramdisk: %" PRIpaddr"->%" PRIpaddr, mpt_alloc, mpt_alloc + initrd_len); }
@@ -880,7 +880,7 @@ int __init dom0_construct_pv(struct domain *d,if ( pfn >= initrd_pfn ) {if ( pfn < initrd_pfn +PFN_UP (initrd_len) ) - mfn = initrd->mod_start + (pfn - initrd_pfn); + mfn =mfn_x (initrd->mfn) + (pfn - initrd_pfn);else mfn -=PFN_UP (initrd_len); }
xen/arch/x86/setup.c +119 -87
414 lines not on this page · raw message
xen/include/xen/bootinfo.h +27 -0
@@ -2,23 +2,50 @@#define __XEN_BOOTINFO_H__#include <xen/types.h> +#include <xen/compiler.h> +#include <xen/mm-frame.h> #ifdef CONFIG_X86 #include <asm/bootinfo.h> #else struct arch_bootmodule { }; +struct arch_boot_info { };#endif +/* Boot module binary type / purpose */ +#define BOOTMOD_UNKNOWN 0 +#define BOOTMOD_XEN 1 +#define BOOTMOD_FDT 2 +#define BOOTMOD_KERNEL 3 +#define BOOTMOD_RAMDISK 4 +#define BOOTMOD_XSM 5 +#define BOOTMOD_UCODE 6 +#define BOOTMOD_GUEST_DTB 7 +typedef unsigned int bootmod_type_t ; + +#define BOOTMOD_STRING_MAX_LEN 1024 +struct boot_string { +char bytes[BOOTMOD_STRING_MAX_LEN ]; +size_t len; +}; +struct boot_module { +bootmod_type_t bootmod_type;paddr_t start; +mfn_t mfn;size_t size;struct arch_bootmodule *arch; +struct boot_string string; };struct boot_info { +char *cmdline; +unsigned int nr_mods;struct boot_module *mods; + +struct arch_boot_info *arch; };#endif
Signature · 1 line
2.25.1
PATCH 6/10 x86 setup, microcode: switch to the new bootinfo structures
In reply to Christopher ClarkNext step in incremental work towards adding a non-multiboot internal representation of boot modules, converting the fields being accessed for the startup calculations.
Move the per-module scan logic into a dedicated function from the iteration loop and set the BOOTMOD_UCODE module type when microcode is found.
Completes the conversion from the module_map bitmap in x86 setup so it can be removed, along with the temporary bootstrap_map multiboot wrapper since the last code that uses it is removed in this change.
---
Changes since v1: patch is a subset of v1 series patches 2 and 3.
- Added the removal of the temporary bootstrap map function
xen/arch/x86/cpu/microcode/core.c | 148 +++++++++++++++------------ xen/arch/x86/include/asm/boot.h | 13 --- xen/arch/x86/include/asm/microcode.h | 7 +- xen/arch/x86/setup.c | 8 +- 4 files changed, 89 insertions(+), 87 deletions(-)
xen/arch/x86/cpu/microcode/core.c +83 -65
@@ -22,12 +22,12 @@*/ #include <xen/alternative-call.h> +#include <xen/bootinfo.h> #include <xen/cpu.h> #include <xen/earlycpio.h> #include <xen/err.h> #include <xen/guest_access.h> #include <xen/init.h> -#include <xen/multiboot.h> #include <xen/param.h> #include <xen/spinlock.h> #include <xen/stop_machine.h>
@@ -57,7 +57,6 @@*/ #define MICROCODE_UPDATE_TIMEOUT_US 1000000 -static module_t __initdata ucode_mod;static signed int __initdata ucode_mod_idx;static bool_t __initdata ucode_mod_forced;static unsigned int nr_cores;
@@ -150,75 +149,109 @@ static int __init cf_check parse_ucode(const char *s) }custom_param ("ucode" , parse_ucode); -void __init microcode_scan_module ( -unsigned long *module_map, -const multiboot_info_t *mbi) +#define MICROCODE_MODULE_MATCH 1 +#define MICROCODE_MODULE_NONMATCH 0 + +static int __init microcode_check_module (struct boot_module *mod) { -module_t *mod = (module_t *)__va (mbi->mods_addr);uint64_t *_blob_start;unsigned long _blob_size; -struct cpio_data cd; +struct cpio_data cd = {NULL ,0 };long offset;const char *p =NULL ; -int i; - - ucode_blob.size =0 ; -if ( !ucode_scan ) -return ;if ( boot_cpu_data.x86_vendor ==X86_VENDOR_AMD ) p ="kernel/x86/microcode/AuthenticAMD.bin" ;else if ( boot_cpu_data.x86_vendor ==X86_VENDOR_INTEL ) p ="kernel/x86/microcode/GenuineIntel.bin" ;else +return -EFAULT ; + + _blob_start =bootstrap_map (mod); + _blob_size = mod->size; +if ( !_blob_start ) + { +printk ("Could not map multiboot module (0x%lx) (size: %ld)\n" , + mod->start, _blob_size); +/* Non-fatal error, so just say no match */ +return MICROCODE_MODULE_NONMATCH ; + } + + cd =find_cpio_data (p, _blob_start, _blob_size, &offset/* ignore */ ); + +if ( cd.data ) + { + ucode_blob.size = cd.size; + ucode_blob.data = cd.data; + + mod->bootmod_type =BOOTMOD_UCODE ; +return MICROCODE_MODULE_MATCH ; + } + +bootstrap_map (NULL ); + +return MICROCODE_MODULE_NONMATCH ; +} + +void __init microcode_scan_module (struct boot_info *bootinfo) +{ +int i; + +if ( !ucode_scan )return ; -/* -* Try all modules and see whichever could be the microcode blob. -*/ -for ( i =1 /* Ignore dom0 kernel */ ; i < mbi->mods_count; i++ ) + i =bootmodule_index (bootinfo,BOOTMOD_UNKNOWN ,0 ); +while ( i < bootinfo->nr_mods ) { -if ( !test_bit (i, module_map) ) -continue ; +int ret =microcode_check_module (&bootinfo->mods[i]); - _blob_start =bootstrap_map_multiboot (&mod[i]); - _blob_size = mod[i].mod_end; -if ( !_blob_start ) +switch ( ret ) { -printk ("Could not map multiboot module #%d (size: %ld)\n" , - i, _blob_size); +case MICROCODE_MODULE_MATCH : +return ; +case MICROCODE_MODULE_NONMATCH : + i =bootmodule_index (bootinfo,BOOTMOD_UNKNOWN , ++i);continue ; +default : +printk ("%s: (err: %d) unable to check microcode\n" , + __func__, ret); +return ; } - cd.data =NULL ; - cd.size =0 ; - cd =find_cpio_data (p, _blob_start, _blob_size, &offset/* ignore */ ); -if ( cd.data ) - { - ucode_blob.size = cd.size; - ucode_blob.data = cd.data; -break ; - } -bootstrap_map (NULL ); } } -static void __init microcode_grab_module ( -unsigned long *module_map, -const multiboot_info_t *mbi) +static void __init microcode_grab_module (struct boot_info *bootinfo) { -module_t *mod = (module_t *)__va (mbi->mods_addr); + ucode_blob.size =0 ;if ( ucode_mod_idx <0 ) - ucode_mod_idx += mbi->mods_count; -if ( ucode_mod_idx <=0 || ucode_mod_idx >= mbi->mods_count || - !__test_and_clear_bit (ucode_mod_idx, module_map) ) - goto scan; - ucode_mod = mod[ucode_mod_idx]; -scan: + ucode_mod_idx += bootinfo->nr_mods; +if ( ucode_mod_idx >=0 && ucode_mod_idx <= bootinfo->nr_mods && + bootinfo->mods[ucode_mod_idx].bootmod_type ==BOOTMOD_UNKNOWN ) + { +int ret =microcode_check_module (&bootinfo->mods[ucode_mod_idx]); + +switch ( ret ) + { +case MICROCODE_MODULE_MATCH : +return ; +case MICROCODE_MODULE_NONMATCH : +break ; +default : +printk ("%s: (err: %d) unable to check microcode\n" , + __func__, ret); +return ; + } + } +if ( ucode_scan ) -microcode_scan_module (module_map, mbi); +microcode_scan_module (bootinfo); } +/* Undefining as they are not needed anymore */ +#undef MICROCODE_MODULE_MATCH +#undef MICROCODE_MODULE_NONMATCH +static struct microcode_ops __ro_after_init ucode_ops;static DEFINE_SPINLOCK (microcode_mutex);
@@ -738,11 +771,6 @@ static int __init cf_check microcode_init(void) ucode_blob.size =0 ; ucode_blob.data =NULL ; } -else if ( ucode_mod.mod_end ) - { -bootstrap_map (NULL ); - ucode_mod.mod_end =0 ; - }return 0 ; }
@@ -786,8 +814,7 @@ static int __init early_update_cache(const void *data, size_t len)return rc; } -int __init microcode_init_cache (unsigned long *module_map, -const struct multiboot_info *mbi) +int __init microcode_init_cache (struct boot_info *bootinfo) {int rc =0 ;
@@ -796,12 +823,9 @@ int __init microcode_init_cache(unsigned long *module_map,if ( ucode_scan )/* Need to rescan the modules because they might have been relocated */ -microcode_scan_module (module_map, mbi); +microcode_scan_module (bootinfo); -if ( ucode_mod.mod_end ) - rc =early_update_cache (bootstrap_map_multiboot (&ucode_mod), - ucode_mod.mod_end); -else if ( ucode_blob.size ) +if ( ucode_blob.size ) rc =early_update_cache (ucode_blob.data, ucode_blob.size);return rc;
@@ -819,11 +843,6 @@ static int __init early_microcode_update_cpu(void) len = ucode_blob.size; data = ucode_blob.data; } -else if ( ucode_mod.mod_end ) - { - len = ucode_mod.mod_end; - data =bootstrap_map_multiboot (&ucode_mod); - }if ( !data )return -ENOMEM ;
@@ -842,8 +861,7 @@ static int __init early_microcode_update_cpu(void)return microcode_update_cpu (patch); } -int __init early_microcode_init (unsigned long *module_map, -const struct multiboot_info *mbi) +int __init early_microcode_init (struct boot_info *bootinfo) {const struct cpuinfo_x86 *c = &boot_cpu_data;int rc =0 ;
@@ -867,11 +885,11 @@ int __init early_microcode_init(unsigned long *module_map,return -ENODEV ; } -microcode_grab_module (module_map, mbi); +microcode_grab_module (bootinfo); ucode_ops.collect_cpu_info (); -if ( ucode_mod.mod_end || ucode_blob.size ) +if ( ucode_blob.size ) rc =early_microcode_update_cpu ();return rc;
xen/arch/x86/include/asm/boot.h +0 -13
@@ -6,19 +6,6 @@#include <asm/setup.h> -static inline void *bootstrap_map_multiboot (const module_t *mod) -{ -struct boot_module bm; - -if ( !mod ) -return bootstrap_map (NULL ); - - bm.start = mod->mod_start <<PAGE_SHIFT ; - bm.size = mod->mod_end; - -return bootstrap_map (&bm); -} -static inline unsigned long bootmodule_index (const struct boot_info *info,bootmod_type_t bootmod_type,unsigned long start)
xen/arch/x86/include/asm/microcode.h +3 -4
@@ -1,6 +1,7 @@#ifndef ASM_X86__MICROCODE_H #define ASM_X86__MICROCODE_H +#include <xen/bootinfo.h> #include <xen/types.h> #include <xen/percpu.h>
@@ -23,10 +24,8 @@ DECLARE_PER_CPU(struct cpu_signature, cpu_sig);void microcode_set_module (unsigned int idx);int microcode_update (XEN_GUEST_HANDLE (const_void ),unsigned long len); -int early_microcode_init (unsigned long *module_map, -const struct multiboot_info *mbi); -int microcode_init_cache (unsigned long *module_map, -const struct multiboot_info *mbi); +int early_microcode_init (struct boot_info *bootinfo); +int microcode_init_cache (struct boot_info *bootinfo);int microcode_update_one (void );#endif /* ASM_X86__MICROCODE_H */
xen/arch/x86/setup.c +3 -5
@@ -1023,7 +1023,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)unsigned int initrdidx, num_parked =0 ;multiboot_info_t *mbi;module_t *mod; -unsigned long nr_pages, raw_max_page, module_map[1 ]; +unsigned long nr_pages, raw_max_page;int i, j, e820_warn =0 , bytes =0 ;unsigned long eb_start, eb_end;bool acpi_boot_table_init_done = false, relocated = false;
@@ -1190,8 +1190,6 @@ void __init noreturn __start_xen(unsigned long mbi_p) }/* Dom0 kernel is the first boot module */ -bitmap_fill (module_map, mbi->mods_count); -__clear_bit (0 , module_map);/* Dom0 kernel is always first */ boot_info->mods[0 ].bootmod_type =BOOTMOD_KERNEL ;if ( pvh_boot )
@@ -1371,7 +1369,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)* TODO: load ucode earlier once multiboot modules become accessible * at an earlier stage. */ -early_microcode_init (module_map, mbi); +early_microcode_init (boot_info);if ( xen_phys_start ) {
@@ -1906,7 +1904,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)timer_init (); -microcode_init_cache (module_map, mbi);/* Needs xmalloc() */ +microcode_init_cache (boot_info);/* Needs xmalloc() */ tsx_init ();/* Needs microcode. May change HLE/RTM feature bits. */
Signature · 1 line
2.25.1
PATCH 10/10 x86 setup: refactor efi, pvh and multiboot entrypoints to new boot info
In reply to Christopher ClarkPrevious commits added a transition point from multiboot v1 structures to the new boot info structures at the earliest common point for all the x86 entrypoints. The result is that each of the entrypoints would construct a multiboot v1 structure from the structures used by each entrypoint. This meant that multiboot2, EFI, and PVH all converted their structures over to mutliboot v1 to only be converted again upon entering __start_xen().
This commit drops the translation function and moves the population of the new boot info structures down into the various entrypoints.
This change increases the maximum number of boot modules accepted on the EFI entry path and the PVH entry path to the same fixed maximum number accepted via multiboot, making it common across all x86 entry points.
---
Changes since v1: patch is based on v1 series patch 4.
- use main bootinfo headers in boot logic instead of adding a 32-bit version
- apply packing to boot structures here rather than in earlier changes
- use a defined maximum number of boot modules rather than Kconfig'd variable
xen/arch/arm/efi/efi-boot.h | 6 + xen/arch/x86/boot/defs.h | 1 + xen/arch/x86/boot/reloc.c | 192 +++++++++++++++------- xen/arch/x86/efi/efi-boot.h | 95 ++++++----- xen/arch/x86/guest/xen/pvh-boot.c | 64 +++++--- xen/arch/x86/include/asm/bootinfo.h | 7 +- xen/arch/x86/include/asm/guest/pvh-boot.h | 6 +- xen/arch/x86/setup.c | 73 +++----- xen/common/efi/boot.c | 4 +- xen/include/xen/bootinfo.h | 9 +- 10 files changed, 278 insertions(+), 179 deletions(-)
xen/arch/arm/efi/efi-boot.h +6 -0
@@ -1003,6 +1003,12 @@ static void __init efi_arch_flush_dcache_area(const void *vaddr, UINTN size)__flush_dcache_area (vaddr, size); } +static struct boot_info __init *efi_arch_bootinfo_init (void ) +{ +/* boot modules not currently in use on Arm so no init required here */ +return NULL ; +} +/* * Local variables: * mode: C
xen/arch/x86/boot/defs.h +1 -0
@@ -44,6 +44,7 @@ _x > _y ? _x : _y; })#define _p (val) ((void *)(unsigned long)(val)) +#define _addr (val) ((unsigned long)(void *)(val))#define tolower (c) ((c) | 0x20)
xen/arch/x86/boot/reloc.c +134 -58
290 lines not on this page · raw message
xen/arch/x86/efi/efi-boot.h +57 -38
159 lines not on this page · raw message
xen/arch/x86/guest/xen/pvh-boot.c +43 -21
112 lines not on this page · raw message
xen/arch/x86/include/asm/bootinfo.h +5 -2
@@ -1,14 +1,14 @@#ifndef __ARCH_X86_BOOTINFO_H__#define __ARCH_X86_BOOTINFO_H__ -struct arch_bootmodule { +struct __packed arch_bootmodule {#define BOOTMOD_FLAG_X86_RELOCATED 1U << 0uint32_t flags;unsigned headroom; };DEFINE_STRUCT_PTR_TYPE (arch_bootmodule); -struct arch_boot_info { +struct __packed arch_boot_info {uint32_t flags;#define BOOTINFO_FLAG_X86_CMDLINE 1U << 2#define BOOTINFO_FLAG_X86_MODULES 1U << 3
@@ -17,6 +17,9 @@ struct arch_boot_info {char_ptr_t boot_loader_name; +uint32_t mem_lower; +uint32_t mem_upper; +uint32_t mmap_length;paddr_t mmap_addr; };
xen/arch/x86/include/asm/guest/pvh-boot.h +3 -3
@@ -8,13 +8,13 @@#ifndef __X86_PVH_BOOT_H__#define __X86_PVH_BOOT_H__ -#include <xen/multiboot.h> +#include <xen/bootinfo.h> #ifdef CONFIG_PVH_GUEST extern bool pvh_boot; -void pvh_init (multiboot_info_t **mbi,module_t **mod); +void __init pvh_init (struct boot_info **bi);void pvh_print_info (void );#else
@@ -23,7 +23,7 @@ void pvh_print_info(void);#define pvh_boot 0 -static inline void pvh_init (multiboot_info_t **mbi,module_t **mod) +static inline void __init pvh_init (struct boot_info **bi) {ASSERT_UNREACHABLE (); }
xen/arch/x86/setup.c +20 -53
113 lines not on this page · raw message
xen/common/efi/boot.c +3 -1
@@ -3,6 +3,7 @@#include <efi/efipciio.h> #include <public/xen.h> #include <xen/bitops.h> +#include <xen/bootinfo.h> #include <xen/compile.h> #include <xen/ctype.h> #include <xen/dmi.h>
@@ -11,7 +12,6 @@#include <xen/keyhandler.h> #include <xen/lib.h> #include <xen/mm.h> -#include <xen/multiboot.h> #include <xen/param.h> #include <xen/pci_regs.h> #include <xen/pfn.h>
@@ -1359,6 +1359,8 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)efi_arch_relocate_image (0 ); +efi_arch_bootinfo_init (); +if ( use_cfg_file ) {EFI_FILE_HANDLE dir_handle;
xen/include/xen/bootinfo.h +6 -3
@@ -20,13 +20,16 @@#define BOOTMOD_GUEST_DTB 7typedef unsigned int bootmod_type_t ; +/* Max number of boot modules a bootloader can provide in addition to Xen */ +#define MAX_NR_BOOTMODS 63 +#define BOOTMOD_STRING_MAX_LEN 1024 -struct boot_string { +struct __packed boot_string {char bytes[BOOTMOD_STRING_MAX_LEN ];size_t len; }; -struct boot_module { +struct __packed boot_module {bootmod_type_t bootmod_type;paddr_t start;mfn_t mfn;
@@ -37,7 +40,7 @@ struct boot_module { };DEFINE_STRUCT_PTR_TYPE (boot_module); -struct boot_info { +struct __packed boot_info {char_ptr_t cmdline;unsigned int nr_mods;
Signature · 1 line
2.25.1
Re: [PATCH 10/10] x86 setup: refactor efi, pvh and multiboot entrypoints to new boot info
I was trying a test build with these patches and got the following error
In function 'mbi2_reloc',
inlined from 'reloc' at arch/x86/boot/reloc.c:437:16:
arch/x86/boot/reloc.c:349:20: error: 'bi_mods' may be used uninitialized [-Werror=maybe-uninitialized]
349 | bi_mods[mod_idx].start = get_mb2_data(tag, module,mod_start);
| ^arch/x86/boot/reloc.c: In function 'reloc':arch/x86/boot/reloc.c:237:25: note: 'bi_mods' was declared here
237 | struct boot_module *bi_mods;
| ^~~~~~~
In file included from arch/x86/boot/reloc.c:29:
In function 'mbi2_reloc',
inlined from 'reloc' at arch/x86/boot/reloc.c:437:16:
arch/x86/boot/reloc.c:365:43: error: 'arch_bi_mods' may be used uninitialized [-Werror=maybe-uninitialized]
365 | bi_mods[mod_idx].arch = _addr(&arch_bi_mods[mod_idx]);arch/x86/boot/defs.h:47:46: note: in definition of macro '_addr'
47 | #define _addr(val) ((unsigned long)(void *)(val))
| ^~~arch/x86/boot/reloc.c: In function 'reloc':arch/x86/boot/reloc.c:238:29: note: 'arch_bi_mods' was declared here
238 | struct arch_bootmodule *arch_bi_mods;
| ^~~~~~~~~~~~cc1: all warnings being treated as errors
Is there a problem in the code?
Michael Young
Re: [PATCH 01/10] x86 setup: move x86 boot module counting into a new boot_info struct
In reply to Christopher ClarkQuoted 4 lines · Christopher Clark
An initial step towards a non-multiboot internal representation of boot modules for common code, starting with x86 setup and converting the fields that are accessed for the startup calculations.
Quoted 8 lines
Introduce a new header, <
xen/bootinfo.h>, and populate it with a newboot_infostructure initially containing a count of the number of boot modules.The naming of the header, structure and fields is intended to respect the boot structures on Arm -- see
arm/include/asm/setup.h-- as part of work towards aligning common architecture-neutral boot logic and structures.
Thanks for aligning the two archs. At some point we should also have ARM use the common headers.
Quoted 23 lines
No functional change intended.
Signed-off-by Christopher Clark <[email protected]>Signed-off-by Daniel P. Smith <[email protected]>---
Changes since v1: patch is a subset of v1 series patches 2 and 3.xen/arch/x86/setup.c | 58 +++++++++++++++++++++++--------------- xen/include/xen/bootinfo.h | 20 +++++++++++++ 2 files changed, 55 insertions(+), 23 deletions(-) create mode 100644 xen/include/xen/bootinfo.hxen/arch/x86/setup.c +1
-0@@ -1,3 +1,4 @@ +#include <xen/bootinfo.h> #include <xen/init.h> #include <xen/lib.h> #include <xen/err.h>
xen/arch/x86/setup.c static int __init cf_check parse_acpi_param(const char *s) · line 272
Quoted 5 lines
xen/arch/x86/setup.c +1
-1@@ -268,7 +269,16 @@ static int __init cf_check parse_acpi_param(const char *s)custom_param ("acpi" , parse_acpi_param);static const module_t *__initdata initial_images; -static unsigned int __initdata nr_initial_images; +static struct boot_info __initdata *boot_info;
Why can't this be not a pointer?
xen/arch/x86/setup.c static int __init cf_check parse_acpi_param(const char *s) · line 276
Quoted 3 lines
xen/arch/x86/setup.c +3
-0+static void __init multiboot_to_bootinfo (multiboot_info_t *mbi) +{ +static struct boot_info __initdata info;
Then we don't need this
xen/arch/x86/setup.c static int __init cf_check parse_acpi_param(const char *s) · line 280
Quoted 3 lines
xen/arch/x86/setup.c +3
-0+ info.nr_mods = mbi->mods_count; + + boot_info = &info;
And we could just do:
boot_info.nr_mods = mbi->mods_count;
?
Quoted 176 lines
xen/arch/x86/setup.c +25
-22+}unsigned long __init initial_images_nrpages (nodeid_t node) {@@ -277,7 +287,7 @@ unsigned long __init initial_images_nrpages(nodeid_t node)unsigned long nr;unsigned int i; -for ( nr = i =0 ; i < nr_initial_images; ++i ) +for ( nr = i =0 ; i < boot_info->nr_mods; ++i ) {unsigned long start = initial_images[i].mod_start;unsigned long end = start +PFN_UP (initial_images[i].mod_end);@@ -293,7 +303,7 @@ void __init discard_initial_images(void) {unsigned int i; -for ( i =0 ; i < nr_initial_images; ++i ) +for ( i =0 ; i < boot_info->nr_mods; ++i ) {uint64_t start = (uint64_t )initial_images[i].mod_start <<PAGE_SHIFT ;@@ -301,7 +311,7 @@ void __init discard_initial_images(void) start + PAGE_ALIGN(initial_images[i].mod_end)); } - nr_initial_images =0 ; + boot_info->nr_mods =0 ; initial_images =NULL ; }@@ -1020,6 +1030,8 @@ void __init noreturn __start_xen(unsigned long mbi_p) mod =__va (mbi->mods_addr); } +multiboot_to_bootinfo (mbi); + loader = (mbi->flags &MBI_LOADERNAME ) ? (char *)__va (mbi->boot_loader_name) :"unknown" ;@@ -1127,18 +1139,18 @@ void __init noreturn __start_xen(unsigned long mbi_p) bootsym(boot_edd_info_nr));/* Check that we have at least one Multiboot module. */ -if ( !(mbi->flags &MBI_MODULES ) || (mbi->mods_count ==0 ) ) +if ( !(mbi->flags &MBI_MODULES ) || (boot_info->nr_mods ==0 ) )panic ("dom0 kernel not specified. Check bootloader configuration\n" );/* Check that we don't have a silly number of modules. */ -if ( mbi->mods_count >sizeof (module_map) *8 ) +if ( boot_info->nr_mods >sizeof (module_map) *8 ) { - mbi->mods_count =sizeof (module_map) *8 ; + boot_info->nr_mods =sizeof (module_map) *8 ;printk ("Excessive multiboot modules - using the first %u only\n" , - mbi->mods_count); + boot_info->nr_mods); } -bitmap_fill (module_map, mbi->mods_count); +bitmap_fill (module_map, boot_info->nr_mods);__clear_bit (0 , module_map);/* Dom0 kernel is always first */ if ( pvh_boot )@@ -1311,9 +1323,9 @@ void __init noreturn __start_xen(unsigned long mbi_p)kexec_reserve_area (&boot_e820); initial_images = mod; - nr_initial_images = mbi->mods_count; + boot_info->nr_mods = boot_info->nr_mods; -for ( i =0 ; !efi_enabled (EFI_LOADER ) && i < mbi->mods_count; i++ ) +for ( i =0 ; !efi_enabled (EFI_LOADER ) && i < boot_info->nr_mods; i++ ) {if ( mod[i].mod_start & (PAGE_SIZE -1 ) )panic ("Bootloader didn't honor module alignment request\n" );@@ -1337,8 +1349,8 @@ void __init noreturn __start_xen(unsigned long mbi_p)* respective reserve_e820_ram() invocation below. No need to * query efi_boot_mem_unused() here, though. */ - mod[mbi->mods_count].mod_start =virt_to_mfn (_stext); - mod[mbi->mods_count].mod_end = __2M_rwdata_end - _stext; + mod[boot_info->nr_mods].mod_start =virt_to_mfn (_stext); + mod[boot_info->nr_mods].mod_end = __2M_rwdata_end - _stext; } modules_headroom =bzimage_headroom (bootstrap_map (mod), mod->mod_end);@@ -1398,7 +1410,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) {/* Don't overlap with modules. */ end =consider_modules (s, e, reloc_size + mask, - mod, mbi->mods_count,-1 ); + mod, boot_info->nr_mods,-1 ); end &= ~mask; } else@@ -1419,7 +1431,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) }/* Is the region suitable for relocating the multiboot modules? */ -for ( j = mbi->mods_count -1 ; j >=0 ; j-- ) +for ( j = boot_info->nr_mods -1 ; j >=0 ; j-- ) {unsigned long headroom = j ?0 : modules_headroom;unsigned long size =PAGE_ALIGN (headroom + mod[j].mod_end);@@ -1429,7 +1441,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)/* Don't overlap with other modules (or Xen itself). */ end =consider_modules (s, e, size, mod, - mbi->mods_count + relocated, j); + boot_info->nr_mods + relocated, j);if ( highmem_start && end > highmem_start )continue ;@@ -1456,7 +1468,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) {/* Don't overlap with modules (or Xen itself). */ e =consider_modules (s, e,PAGE_ALIGN (kexec_crash_area.size), mod, - mbi->mods_count + relocated,-1 ); + boot_info->nr_mods + relocated,-1 );if ( s >= e )break ;if ( e > kexec_crash_area_limit )@@ -1471,7 +1483,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)if ( modules_headroom && !mod->reserved )panic ("Not enough memory to relocate the dom0 kernel image\n" ); -for ( i =0 ; i < mbi->mods_count; ++i ) +for ( i =0 ; i < boot_info->nr_mods; ++i ) {uint64_t s = (uint64_t )mod[i].mod_start <<PAGE_SHIFT ;@@ -1540,7 +1552,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)ASSERT (j); } map_e = boot_e820.map[j].addr + boot_e820.map[j].size; -for ( j =0 ; j < mbi->mods_count; ++j ) +for ( j =0 ; j < boot_info->nr_mods; ++j ) {uint64_t end =pfn_to_paddr (mod[j].mod_start) + mod[j].mod_end;@@ -1616,7 +1628,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) } } -for ( i =0 ; i < mbi->mods_count; ++i ) +for ( i =0 ; i < boot_info->nr_mods; ++i ) {set_pdx_range (mod[i].mod_start, mod[i].mod_start +PFN_UP (mod[i].mod_end));@@ -1999,8 +2011,8 @@ void __init noreturn __start_xen(unsigned long mbi_p) cpu_has_nx ?XENLOG_INFO :XENLOG_WARNING "Warning: " , cpu_has_nx ? "" : "not "); - initrdidx =find_first_bit (module_map, mbi->mods_count); -if (bitmap_weight (module_map, mbi->mods_count) >1 ) + initrdidx =find_first_bit (module_map, boot_info->nr_mods); +if (bitmap_weight (module_map, boot_info->nr_mods) >1 )printk (XENLOG_WARNING "Multiple initrd candidates, picking module #%u\n" , initrdidx);@@ -2010,7 +2022,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)* above our heap. The second module, if present, is an initrd ramdisk. */ dom0 =create_dom0 (mod, modules_headroom, - initrdidx < mbi->mods_count ? mod + initrdidx :NULL , + initrdidx < boot_info->nr_mods ? mod + initrdidx :NULL , kextra, loader);if ( !dom0 )panic ("Could not set up DOM0 guest OS\n" );xen/include/xen/bootinfo.h new file +0
-0
xen/include/xen/bootinfo.h line 4
Quoted 4 lines
xen/include/xen/bootinfo.h new file +4
-0@@ -0,0 +1,20 @@ +#ifndef __XEN_BOOTINFO_H__ +#define __XEN_BOOTINFO_H__ + +#include <xen/types.h>
I don't think you need types.h right now
xen/include/xen/bootinfo.h line 6
Quoted 1 line
xen/include/xen/bootinfo.h new file +1
-0+struct boot_info {
This is what we call struct bootmodules on ARM right? Would it help if we used the same name?
I am not asking to make the ARM code common because I think that would probably be a lot more work.
Quoted 18 lines
xen/include/xen/bootinfo.h new file +14
-0+ unsigned int nr_mods; +}; + +#endif + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/ Signature · 1 line
2.25.1
Re: [PATCH 03/10] x86 setup: change bootstrap map to accept new boot module structures
In reply to Christopher ClarkQuoted 16 lines · Christopher Clark
To convert the x86 boot logic from multiboot to boot module structures, change the bootstrap map function to accept a boot module parameter.
To allow incremental change from multiboot to boot modules across all x86 setup logic, provide a temporary inline wrapper that still accepts a multiboot module parameter and use it where necessary. The wrapper is placed in a new
arch/x86header <asm/boot.h> to avoid putting a static inline function into an existing header that has no such functions already. This new header will be expanded with additional functions in subsequent patches in this series.No functional change intended.
Signed-off-by Christopher Clark <[email protected]>Signed-off-by Daniel P. Smith <[email protected]>
[...]
xen/include/xen/bootinfo.h line 14
Quoted 10 lines
xen/include/xen/bootinfo.h +2
-0@@ -10,6 +10,9 @@#endif struct boot_module { +paddr_t start; +size_t size;
I think size should be paddr_t (instead of size_t) to make sure it is the right size on both 64-bit and 32-bit architectures that support 64-bit addresses.
Quoted 2 lines
xen/include/xen/bootinfo.h +0
-0struct arch_bootmodule *arch; };
Re: [PATCH 04/10] x86 setup: porting dom0 construction logic to boot module structures
In reply to Christopher ClarkQuoted 246 lines · Christopher Clark
Adjust the PV and PVH dom0 construction entry points to take boot module structures as parameters, and add further fields to the boot module structures to plumb the data needed to support this use. Populate these from the multiboot module data.
This change removes multiboot from the PV and PVH dom0 construction logic.
Introduce and use new inline accessor functions for navigating the boot module structures.
The per-boot-module arrays are expanded from singletons to accommodate all modules, up to a static maximum of 64 modules including Xen that can be accepted from a bootloader to match the previous value from the module map check.
The field that identifies the type of a boot module (kernel, ramdisk, etc) is introduced to the common boot module structure and declared as a non-enum integer type to allow the field to be of a known-size and so structure can be packed in a subsequent patch in the series, and it will then be reconciled with the equivalent Arm boot field type.
The command line provided by multiboot for each boot module is added directly to the
boot_modulestructure, which is appropriate for this logic just replacing multiboot.The maximum number of boot modules that a bootloader can provide in addition to the Xen hypervisor is preserved from prior logic with the
module_mapat 63.Signed-off-by Christopher Clark <[email protected]>Signed-off-by Daniel P. Smith <[email protected]>---
Changes since v1: patch is a subset of v1 series patches 2 and 3.
- Themodule_mapis kept for now since still in use.
- Move the static inline functions into a separate dedicated header.
- <mm-frame.h> and <compiler.h> replace prior inclusion of <mm.h> for simpler dependencies.xen/arch/x86/dom0_build.c | 10 +- xen/arch/x86/hvm/dom0_build.c | 43 +++--- xen/arch/x86/include/asm/boot.h | 36 +++++ xen/arch/x86/include/asm/bootinfo.h | 24 +++ xen/arch/x86/include/asm/dom0_build.h | 13 +- xen/arch/x86/include/asm/setup.h | 4 +- xen/arch/x86/pv/dom0_build.c | 32 ++-- xen/arch/x86/setup.c | 206 +++++++++++++++----------- xen/include/xen/bootinfo.h | 27 ++++ 9 files changed, 254 insertions(+), 141 deletions(-)xen/arch/x86/dom0_build.c +5
-5@@ -4,6 +4,7 @@* Copyright (c) 2002-2005, K A Fraser */ +#include <xen/bootinfo.h> #include <xen/init.h> #include <xen/iocap.h> #include <xen/libelf.h> @@ -562,9 +563,8 @@ int __init dom0_setup_permissions(struct domain *d)return rc; } -int __init construct_dom0 (struct domain *d,const module_t *image, -unsigned long image_headroom,module_t *initrd, -char *cmdline) +int __init construct_dom0 (struct domain *d,const struct boot_module *image, +struct boot_module *initrd,char *cmdline) {int rc;@@ -576,9 +576,9 @@ int __init construct_dom0(struct domain *d, const module_t *image,process_pending_softirqs ();if (is_hvm_domain (d) ) - rc =dom0_construct_pvh (d, image, image_headroom, initrd, cmdline); + rc =dom0_construct_pvh (d, image, initrd, cmdline);else if (is_pv_domain (d) ) - rc =dom0_construct_pv (d, image, image_headroom, initrd, cmdline); + rc =dom0_construct_pv (d, image, initrd, cmdline);else panic ("Cannot construct Dom0. No guest interface available\n" );xen/arch/x86/hvm/dom0_build.c +20
-23@@ -8,9 +8,9 @@*/ #include <xen/acpi.h> +#include <xen/bootinfo.h> #include <xen/init.h> #include <xen/libelf.h> -#include <xen/multiboot.h> #include <xen/pci.h> #include <xen/softirq.h> @@ -530,14 +530,13 @@ static paddr_t __init find_memory(return INVALID_PADDR ; } -static int __init pvh_load_kernel (struct domain *d,const module_t *image, -unsigned long image_headroom, -module_t *initrd,void *image_base, -char *cmdline,paddr_t *entry, -paddr_t *start_info_addr) +static int __init pvh_load_kernel ( +struct domain *d,const struct boot_module *image, +struct boot_module *initrd,void *image_base,char *cmdline,paddr_t *entry, +paddr_t *start_info_addr) { -void *image_start = image_base + image_headroom; -unsigned long image_len = image->mod_end; +void *image_start = image_base + image->arch->headroom; +unsigned long image_len = image->size;struct elf_binary elf;struct elf_dom_parms parms;paddr_t last_addr;@@ -546,7 +545,7 @@ static int __init pvh_load_kernel(struct domain *d, const module_t *image,struct vcpu *v = d->vcpu[0 ];int rc; -if ( (rc =bzimage_parse (image_base, &image_start, image_headroom, +if ( (rc =bzimage_parse (image_base, &image_start, image->arch->headroom, &image_len)) !=0 ) {printk ("Error trying to detect bz compressed kernel\n" );@@ -594,7 +593,7 @@ static int __init pvh_load_kernel(struct domain *d, const module_t *image,* simplify it. */ last_addr = find_memory(d, &elf, sizeof(start_info) + - (initrd ? ROUNDUP(initrd->mod_end, PAGE_SIZE) + + (initrd ? ROUNDUP(initrd->size, PAGE_SIZE) + sizeof(mod) : 0) + (cmdline ? ROUNDUP(strlen(cmdline) + 1,@@ -608,8 +607,8 @@ static int __init pvh_load_kernel(struct domain *d, const module_t *image,if ( initrd !=NULL ) { - rc =hvm_copy_to_guest_phys (last_addr,mfn_to_virt (initrd->mod_start), - initrd->mod_end, v); + rc =hvm_copy_to_guest_phys (last_addr,maddr_to_virt (initrd->start), + initrd->size, v);if ( rc ) {printk ("Unable to copy initrd to guest\n" );@@ -617,11 +616,11 @@ static int __init pvh_load_kernel(struct domain *d, const module_t *image, } mod.paddr = last_addr; - mod.size = initrd->mod_end; - last_addr +=ROUNDUP (initrd->mod_end,elf_64bit (&elf) ?8 :4 ); -if ( initrd->string ) + mod.size = initrd->size; + last_addr +=ROUNDUP (initrd->size,elf_64bit (&elf) ?8 :4 ); +if ( initrd->string.len ) { -char *str =__va (initrd->string); +char *str = initrd->string.bytes;size_t len =strlen (str) +1 ; rc =hvm_copy_to_guest_phys (last_addr, str, len, v);@@ -1176,10 +1175,9 @@ static void __hwdom_init pvh_setup_mmcfg(struct domain *d) } } -int __init dom0_construct_pvh (struct domain *d,const module_t *image, -unsigned long image_headroom, -module_t *initrd, -char *cmdline) +int __init dom0_construct_pvh ( +struct domain *d,const struct boot_module *image, +struct boot_module *initrd,char *cmdline) {paddr_t entry, start_info;int rc;@@ -1209,9 +1207,8 @@ int __init dom0_construct_pvh(struct domain *d, const module_t *image,return rc; } - rc =pvh_load_kernel (d, image, image_headroom, initrd, -bootstrap_map_multiboot (image), - cmdline, &entry, &start_info); + rc =pvh_load_kernel (d, image, initrd,bootstrap_map (image), cmdline, + &entry, &start_info);if ( rc ) {printk ("Failed to load Dom0 kernel\n" );xen/arch/x86/include/asm/boot.h +36
-0@@ -19,6 +19,42 @@ static inline void *bootstrap_map_multiboot(const module_t *mod)return bootstrap_map (&bm); } +static inline unsigned long bootmodule_index ( +const struct boot_info *info,bootmod_type_t bootmod_type, +unsigned long start) +{ +for ( ; start < info->nr_mods; start++ ) +if ( info->mods[start].bootmod_type == bootmod_type ) +return start; + +return info->nr_mods +1 ; +} + +static inline struct boot_module *bootmodule_next ( +const struct boot_info *info,bootmod_type_t bootmod_type) +{ +unsigned long i; + +for ( i =0 ; i < info->nr_mods; i++ ) +if ( info->mods[i].bootmod_type == bootmod_type ) +return &info->mods[i]; + +return NULL ; +} + +static inline void bootmodule_update_start (struct boot_module *bm, +paddr_t new_start) +{ + bm->start = new_start; + bm->mfn =maddr_to_mfn (new_start); +} + +static inline void bootmodule_update_mfn (struct boot_module *bm,mfn_t new_mfn) +{ + bm->mfn = new_mfn; + bm->start =mfn_to_maddr (new_mfn); +} +#endif /* xen/arch/x86/include/asm/bootinfo.h +0
-0@@ -2,9 +2,33 @@#define __ARCH_X86_BOOTINFO_H__
xen/arch/x86/include/asm/bootinfo.h line 12
Quoted 10 lines
xen/arch/x86/include/asm/bootinfo.h +5
-0struct arch_bootmodule { +#define BOOTMOD_FLAG_X86_RELOCATED 1U << 0 +uint32_t flags;unsigned headroom; }; +struct arch_boot_info { +uint32_t flags; +#define BOOTINFO_FLAG_X86_CMDLINE 1U << 2
Is this to indicate the presence of the Xen cmdline?
Quoted 35 lines
xen/arch/x86/include/asm/bootinfo.h +19
-0+#define BOOTINFO_FLAG_X86_MODULES 1U << 3 +#define BOOTINFO_FLAG_X86_MEMMAP 1U << 6 +#define BOOTINFO_FLAG_X86_LOADERNAME 1U << 9 + +char *boot_loader_name; + +uint32_t mmap_length; + paddr_t mmap_addr; +}; + +struct __packed mb_memmap { +uint32_t size; +uint32_t base_addr_low; +uint32_t base_addr_high; +uint32_t length_low; +uint32_t length_high; +uint32_t type; +}; +#endif /* xen/arch/x86/setup.c +1
-0@@ -37,6 +37,7 @@#include <asm/processor.h> #include <asm/mpspec.h> #include <asm/apic.h> +#include <asm/boot.h> #include <asm/msi.h> #include <asm/desc.h> #include <asm/paging.h>
xen/arch/x86/setup.c line 64
Quoted 5 lines
xen/arch/x86/setup.c +2
-0@@ -59,6 +60,9 @@#include <asm/prot-key.h> #include <asm/pv/domain.h> +/* Max number of boot modules a bootloader can provide in addition to Xen */ +#define MAX_NR_BOOTMODS 63
Call it MAX_MODULES ?
Like I wrote in the past, you already did the hard work of aligning the interfaces, we might as well also use the same names.
[...]
xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long mbi_p) · line 1388
Quoted 10 lines
xen/arch/x86/setup.c +3
-2@@ -1357,12 +1382,14 @@ void __init noreturn __start_xen(unsigned long mbi_p)* respective reserve_e820_ram() invocation below. No need to * query efi_boot_mem_unused() here, though. */ - mod[boot_info->nr_mods].mod_start =virt_to_mfn (_stext); - mod[boot_info->nr_mods].mod_end = __2M_rwdata_end - _stext; +bootmodule_update_start (&boot_info->mods[boot_info->nr_mods], +virt_to_maddr (_stext)); + boot_info->mods[boot_info->nr_mods].size = __2M_rwdata_end - _stext; }
The original code had the end address as "__2M_rwdata_end - _stext" while now we have the size as "__2M_rwdata_end - _stext" which is not the same?
Quoted 7 lines
xen/arch/x86/setup.c +2
-1boot_info->mods[0 ].arch->headroom = -bzimage_headroom (bootstrap_map_multiboot (mod), mod->mod_end); +bzimage_headroom (bootstrap_map (&boot_info->mods[0 ]), + boot_info->mods[0 ].size);bootstrap_map (NULL );
[...]
Quoted 20 lines
xen/include/xen/bootinfo.h +5
-0@@ -2,23 +2,50 @@#define __XEN_BOOTINFO_H__#include <xen/types.h> +#include <xen/compiler.h> +#include <xen/mm-frame.h> #ifdef CONFIG_X86 #include <asm/bootinfo.h> #else struct arch_bootmodule { }; +struct arch_boot_info { };#endif +/* Boot module binary type / purpose */ +#define BOOTMOD_UNKNOWN 0
xen/include/xen/bootinfo.h line 26
Quoted 10 lines
xen/include/xen/bootinfo.h +10
-0+#define BOOTMOD_XEN 1 +#define BOOTMOD_FDT 2 +#define BOOTMOD_KERNEL 3 +#define BOOTMOD_RAMDISK 4 +#define BOOTMOD_XSM 5 +#define BOOTMOD_UCODE 6 +#define BOOTMOD_GUEST_DTB 7 +typedef unsigned int bootmod_type_t ; + +#define BOOTMOD_STRING_MAX_LEN 1024
BOOTMOD_MAX_CMDLINE ?
xen/include/xen/bootinfo.h line 27
Quoted 1 line
xen/include/xen/bootinfo.h +1
-0+struct boot_string {
struct bootcmdline ?
xen/include/xen/bootinfo.h line 28
Quoted 1 line
xen/include/xen/bootinfo.h +1
-0+char bytes[BOOTMOD_STRING_MAX_LEN ];
cmdline?
If the string is \0 terminated we don't need len?
xen/include/xen/bootinfo.h line 33
Quoted 5 lines
xen/include/xen/bootinfo.h +4
-0+size_t len; +}; +struct boot_module { +bootmod_type_t bootmod_type;
Why not use a good old enum?
xen/include/xen/bootinfo.h line 35
Quoted 2 lines
xen/include/xen/bootinfo.h +1
-0paddr_t start; +mfn_t mfn;
I think mfn should be in arch_bootmodule
xen/include/xen/bootinfo.h line 43
Quoted 8 lines
xen/include/xen/bootinfo.h +2
-0size_t size;struct arch_bootmodule *arch; +struct boot_string string; };struct boot_info { +char *cmdline;
Is this for Xen cmdline? While all the other cmdline are in the various struct boot_string? Is there any benefit in using the BOOTMOD_XEN for it? BOOTMOD_XEN is not used so far, so if you don't end up using it, probably not, otherwise it could be considered.
Quoted 11 lines
xen/include/xen/bootinfo.h +2
-0unsigned int nr_mods;struct boot_module *mods; + + struct arch_boot_info *arch; };#endif Signature · 1 line
2.25.1
Re: [PATCH 02/10] x86 setup: per-arch bootmodule structure, headroom field
In reply to Christopher ClarkQuoted 18 lines · Christopher Clark
Next step in incremental work towards adding a non-multiboot internal representation of boot modules, converting the fields being accessed for the startup calculations.
Add a new array of structs for per-boot-module state, though only allocate space for a single array entry in this change since that is all that is required for functionality modified in this patch: moving the headroom field for the image decompression calculation into a new per-arch boot module struct and then using it in x86 dom0 construction.
Introduces a per-arch header for x86 for arch-specific boot module structures, and add a member to the common boot module structure for access to it.
No functional change intended.
Signed-off-by Christopher Clark <[email protected]>Signed-off-by Daniel P. Smith <[email protected]>
[...]
Quoted 24 lines
xen/arch/x86/include/asm/bootinfo.h new file +18
-0@@ -0,0 +1,18 @@ +#ifndef __ARCH_X86_BOOTINFO_H__ +#define __ARCH_X86_BOOTINFO_H__ + +struct arch_bootmodule { +unsigned headroom; +}; + +#endif + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
[...]
Quoted 11 lines
xen/include/xen/bootinfo.h +3
-0@@ -3,8 +3,19 @@#include <xen/types.h> +#ifdef CONFIG_X86 +#include <asm/bootinfo.h> +#else
xen/include/xen/bootinfo.h line 18
Quoted 10 lines
xen/include/xen/bootinfo.h +8
-0+struct arch_bootmodule { }; +#endif + +struct boot_module { +struct arch_bootmodule *arch; +}; +struct boot_info {unsigned int nr_mods; +struct boot_module *mods;
Also here you already made the effort of using the same data structures we use on ARM, you might as well use the same names too. Otherwise when we try to use them on ARM it will require a rename somewhere.
Quoted 7 lines
xen/include/xen/bootinfo.h +0
-0};#endif Signature · 1 line
2.25.1
Re: [PATCH 05/10] xsm: switch XSM init to boot info structures
In reply to Christopher ClarkQuoted 6 lines · Christopher Clark
Change the XSM implementation to use the boot info structure instead of the multiboot
module_map.Drops a dependency on
CONFIG_MULTIBOOT, so boot module logic is now used whenever theDEVICE_TREEspecific logic (for Arm) is not, with the bootinfo header conditionally included to ensure no change on Arm.
Given that device tree is used for ARM but also for the Hyperlaunch configuration, I think this is very confusing.
Ideally I think we should use struct bootinfo (ideally the same version currently under xen/arch/arm/include/asm/setup.h) for both ARM and x86, getting rid of any need of any #ifdefs. We should be able to get xsm_dt_policy_init to work with Hyperlaunch x86 pretty easily?
If that is too much work, then please use #ifdef CONFIG_ARM so at least it is clear what the difference is.
Quoted 295 lines
Adds a multiboot header inclusion into
guest/xen/pvh-boot.csince it is no longer provided via transitive inclusion and the source in that file uses multiboot structures.Signed-off-by Christopher Clark <[email protected]>Signed-off-by Daniel P. Smith <[email protected]>---
Changes since v1: patch is a subset of v1 series patches 2 and 3.
- Added the <xen/multiboot.h> inclusion topvh-boot.c
- Use conditional inclusion for <xen/bootinfo.h>xen/arch/x86/guest/xen/pvh-boot.c | 1 + xen/arch/x86/setup.c | 2 +- xen/include/xsm/xsm.h | 28 +++++++-------- xen/xsm/xsm_core.c | 47 +++++++++++++++--------- xen/xsm/xsm_policy.c | 59 ++++++++++++++++--------------- 5 files changed, 77 insertions(+), 60 deletions(-)xen/arch/x86/guest/xen/pvh-boot.c +1
-0@@ -9,6 +9,7 @@#include <xen/init.h> #include <xen/lib.h> #include <xen/mm.h> +#include <xen/multiboot.h> #include <asm/e820.h> #include <asm/guest.h> xen/arch/x86/setup.c +1
-1@@ -1835,7 +1835,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) mmio_ro_ranges =rangeset_new (NULL ,"r/o mmio ranges" , RANGESETF_prettyprint_hex); -xsm_multiboot_init (module_map, mbi); +xsm_bootmodule_init (boot_info);/* * IOMMU-related ACPI table parsing may require some of the system domains xen/include/xsm/xsm.h +14
-14@@ -16,8 +16,10 @@#define __XSM_H__#include <xen/alternative-call.h> +#ifndef CONFIG_HAS_DEVICE_TREE +# include <xen/bootinfo.h> +#endif #include <xen/sched.h> -#include <xen/multiboot.h> /* policy magic number (defined by XSM_MAGIC) */ typedef uint32_t xsm_magic_t ;@@ -776,15 +778,14 @@ static inline int xsm_argo_send(const struct domain *d, const struct domain *t)#endif /* XSM_NO_WRAPPERS */ -#ifdef CONFIG_MULTIBOOT -int xsm_multiboot_init ( -unsigned long *module_map,const multiboot_info_t *mbi); -int xsm_multiboot_policy_init ( -unsigned long *module_map,const multiboot_info_t *mbi, -void **policy_buffer,size_t *policy_size); -#endif +#ifndef CONFIG_HAS_DEVICE_TREE +int xsm_bootmodule_init (const struct boot_info *info); +int xsm_bootmodule_policy_init ( +const struct boot_info *info,const unsigned char **policy_buffer, +size_t *policy_size); + +#else -#ifdef CONFIG_HAS_DEVICE_TREE /* * Initialize XSM * @@ -826,15 +827,14 @@ static const inline struct xsm_ops *silo_init(void)#include <xsm/dummy.h> -#ifdef CONFIG_MULTIBOOT -static inline int xsm_multiboot_init ( -unsigned long *module_map,const multiboot_info_t *mbi) +#ifndef CONFIG_HAS_DEVICE_TREE +static inline int xsm_bootmodule_init (const struct boot_info *info) {return 0 ; } -#endif -#ifdef CONFIG_HAS_DEVICE_TREE +#else +static inline int xsm_dt_init (void ) {return 0 ;xen/xsm/xsm_core.c +30
-17@@ -10,8 +10,12 @@* as published by the Free Software Foundation. */ -#include <xen/init.h> +#ifndef CONFIG_HAS_DEVICE_TREE +# include <xen/bootinfo.h> +#endif #include <xen/errno.h> +#include <xen/hypercall.h> +#include <xen/init.h> #include <xen/lib.h> #include <xen/param.h> @@ -138,26 +142,35 @@ static int __init xsm_core_init(const void *policy_buffer, size_t policy_size)return 0 ; } -#ifdef CONFIG_MULTIBOOT -int __init xsm_multiboot_init ( -unsigned long *module_map,const multiboot_info_t *mbi) +/* +* ifdef'ing this against multiboot is no longer valid as the boot module +* is agnostic and it will be possible to dropped the ifndef should Arm +* adopt boot info +*/ +#ifndef CONFIG_HAS_DEVICE_TREE +int __init xsm_bootmodule_init (const struct boot_info *bootinfo) {int ret =0 ; -void *policy_buffer =NULL ; +const unsigned char *policy_buffer =NULL ;size_t policy_size =0 ;printk ("XSM Framework v" XSM_FRAMEWORK_VERSION " initialized\n" );if (XSM_MAGIC ) { - ret =xsm_multiboot_policy_init (module_map, mbi, &policy_buffer, - &policy_size); -if ( ret ) - { -bootstrap_map (NULL ); -printk (XENLOG_ERR "Error %d initializing XSM policy\n" , ret); -return -EINVAL ; - } +int ret =xsm_bootmodule_policy_init (bootinfo, &policy_buffer, + &policy_size); +bootstrap_map (NULL ); + +if ( ret == -ENOENT ) +/* +* The XSM module needs a policy file but one was not located. +* Report as a warning and continue as the XSM module may late +* load a policy file. +*/ +printk (XENLOG_WARNING "xsm: starting without a policy loaded!\n" ); +else if ( ret ) +panic ("Error %d initializing XSM policy\n" , ret); } ret =xsm_core_init (policy_buffer, policy_size);@@ -165,9 +178,9 @@ int __init xsm_multiboot_init( return 0; } -#endif -#ifdef CONFIG_HAS_DEVICE_TREE +#else +int __init xsm_dt_init (void ) {int ret =0 ;@@ -215,9 +228,9 @@ bool __init has_xsm_magic(paddr_t start)return false; } -#endif +#endif /* CONFIG_HAS_DEVICE_TREE */ -#endif +#endif /* CONFIG_XSM */ long do_xsm_op (XEN_GUEST_HANDLE_PARAM (void ) op) {xen/xsm/xsm_policy.c +31
-28@@ -18,62 +18,65 @@* */ -#include <xsm/xsm.h> -#ifdef CONFIG_MULTIBOOT -#include <asm/boot.h> -#include <xen/multiboot.h> -#include <asm/setup.h> -#endif #include <xen/bitops.h> +#ifndef CONFIG_HAS_DEVICE_TREE +# include <xen/bootinfo.h> +#endif +#include <xsm/xsm.h> #ifdef CONFIG_HAS_DEVICE_TREE -# include <asm/setup.h> # include <xen/device_tree.h> +#else +#include <asm/boot.h> #endif -#ifdef CONFIG_MULTIBOOT -int __init xsm_multiboot_policy_init ( -unsigned long *module_map,const multiboot_info_t *mbi, -void **policy_buffer,size_t *policy_size) +#include <asm/setup.h> + +#ifndef CONFIG_HAS_DEVICE_TREE +int __init xsm_bootmodule_policy_init ( +const struct boot_info *bootinfo,const unsigned char **policy_buffer, +size_t *policy_size) { -int i; -module_t *mod = (module_t *)__va (mbi->mods_addr); -int rc =0 ; +unsigned long i; +int rc = -ENOENT ;u32 *_policy_start;unsigned long _policy_len; -/* -* Try all modules and see whichever could be the binary policy. -* Adjust module_map for the module that is the binary policy. -*/ -for ( i = mbi->mods_count-1 ; i >=1 ; i-- ) - { -if ( !test_bit (i, module_map) ) -continue ; +#ifdef CONFIG_XSM_FLASK_POLICY +/* Initially set to builtin policy, overriden if boot module is found. */ + *policy_buffer = xsm_flask_init_policy; + *policy_size = xsm_flask_init_policy_size; + rc =0 ; +#endif - _policy_start =bootstrap_map_multiboot (mod + i); - _policy_len = mod[i].mod_end; + i =bootmodule_index (bootinfo,BOOTMOD_UNKNOWN ,0 ); +while ( i < bootinfo->nr_mods ) + { + _policy_start =bootstrap_map (&bootinfo->mods[i]); + _policy_len = bootinfo->mods[i].size;if ( (xsm_magic_t)(*_policy_start) ==XSM_MAGIC ) { - *policy_buffer = _policy_start; + *policy_buffer = (unsigned char *)_policy_start; *policy_size = _policy_len;printk ("Policy len %#lx, start at %p.\n" , _policy_len,_policy_start); -__clear_bit (i, module_map); + bootinfo->mods[i].bootmod_type =BOOTMOD_XSM ; + rc =0 ;break ; }bootstrap_map (NULL ); + i =bootmodule_index (bootinfo,BOOTMOD_UNKNOWN , ++i); }return rc; } -#endif -#ifdef CONFIG_HAS_DEVICE_TREE +#else +int __init xsm_dt_policy_init (void **policy_buffer,size_t *policy_size) {struct bootmodule *mod =boot_module_find_by_kind (BOOTMOD_XSM );Signature · 1 line
2.25.1
Re: [PATCH 05/10] xsm: switch XSM init to boot info structures
Quoted 11 lines · Stefano Stabellini
Quoted 6 lines · Christopher Clark
Change the XSM implementation to use the boot info structure instead of the multiboot
module_map.Drops a dependency on
CONFIG_MULTIBOOT, so boot module logic is now used whenever theDEVICE_TREEspecific logic (for Arm) is not, with the bootinfo header conditionally included to ensure no change on Arm.Given that device tree is used for ARM but also for the Hyperlaunch configuration, I think this is very confusing.
Quoted 7 lines
Ideally I think we should use struct bootinfo (ideally the same version currently under
xen/arch/arm/include/asm/setup.h) for both ARM and x86, getting rid of any need of any #ifdefs. We should be able to getxsm_dt_policy_initto work with Hyperlaunch x86 pretty easily?If that is too much work, then please use #ifdef
CONFIG_ARMso at least it is clear what the difference is.
Wait, is it the case that xsm_bootmodule_init is for the old grub multiboot protocol? And xsm_dt_init will be used by both Dom0less ARM and Hyperlaunch x86?
Wouldn't it be better to have a "detect" or "pre-init" function per module-type (one for xsm, one for microcode, etc.) that configure the bootinfo and bootmodules correctly and then we can reuse a single xsm init function in all cases:
- dom0less arm
- hyperlaunch x86
- legacy grub multiboot x86
Quoted 296 lines
Quoted 295 lines
Adds a multiboot header inclusion into
guest/xen/pvh-boot.csince it is no longer provided via transitive inclusion and the source in that file uses multiboot structures.Signed-off-by Christopher Clark <[email protected]>Signed-off-by Daniel P. Smith <[email protected]>---
Changes since v1: patch is a subset of v1 series patches 2 and 3.
- Added the <xen/multiboot.h> inclusion topvh-boot.c
- Use conditional inclusion for <xen/bootinfo.h>xen/arch/x86/guest/xen/pvh-boot.c | 1 + xen/arch/x86/setup.c | 2 +- xen/include/xsm/xsm.h | 28 +++++++-------- xen/xsm/xsm_core.c | 47 +++++++++++++++--------- xen/xsm/xsm_policy.c | 59 ++++++++++++++++--------------- 5 files changed, 77 insertions(+), 60 deletions(-)xen/arch/x86/guest/xen/pvh-boot.c +1
-0@@ -9,6 +9,7 @@#include <xen/init.h> #include <xen/lib.h> #include <xen/mm.h> +#include <xen/multiboot.h> #include <asm/e820.h> #include <asm/guest.h> xen/arch/x86/setup.c +1
-1@@ -1835,7 +1835,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) mmio_ro_ranges =rangeset_new (NULL ,"r/o mmio ranges" , RANGESETF_prettyprint_hex); -xsm_multiboot_init (module_map, mbi); +xsm_bootmodule_init (boot_info);/* * IOMMU-related ACPI table parsing may require some of the system domains xen/include/xsm/xsm.h +14
-14@@ -16,8 +16,10 @@#define __XSM_H__#include <xen/alternative-call.h> +#ifndef CONFIG_HAS_DEVICE_TREE +# include <xen/bootinfo.h> +#endif #include <xen/sched.h> -#include <xen/multiboot.h> /* policy magic number (defined by XSM_MAGIC) */ typedef uint32_t xsm_magic_t ;@@ -776,15 +778,14 @@ static inline int xsm_argo_send(const struct domain *d, const struct domain *t)#endif /* XSM_NO_WRAPPERS */ -#ifdef CONFIG_MULTIBOOT -int xsm_multiboot_init ( -unsigned long *module_map,const multiboot_info_t *mbi); -int xsm_multiboot_policy_init ( -unsigned long *module_map,const multiboot_info_t *mbi, -void **policy_buffer,size_t *policy_size); -#endif +#ifndef CONFIG_HAS_DEVICE_TREE +int xsm_bootmodule_init (const struct boot_info *info); +int xsm_bootmodule_policy_init ( +const struct boot_info *info,const unsigned char **policy_buffer, +size_t *policy_size); + +#else -#ifdef CONFIG_HAS_DEVICE_TREE /* * Initialize XSM * @@ -826,15 +827,14 @@ static const inline struct xsm_ops *silo_init(void)#include <xsm/dummy.h> -#ifdef CONFIG_MULTIBOOT -static inline int xsm_multiboot_init ( -unsigned long *module_map,const multiboot_info_t *mbi) +#ifndef CONFIG_HAS_DEVICE_TREE +static inline int xsm_bootmodule_init (const struct boot_info *info) {return 0 ; } -#endif -#ifdef CONFIG_HAS_DEVICE_TREE +#else +static inline int xsm_dt_init (void ) {return 0 ;xen/xsm/xsm_core.c +30
-17@@ -10,8 +10,12 @@* as published by the Free Software Foundation. */ -#include <xen/init.h> +#ifndef CONFIG_HAS_DEVICE_TREE +# include <xen/bootinfo.h> +#endif #include <xen/errno.h> +#include <xen/hypercall.h> +#include <xen/init.h> #include <xen/lib.h> #include <xen/param.h> @@ -138,26 +142,35 @@ static int __init xsm_core_init(const void *policy_buffer, size_t policy_size)return 0 ; } -#ifdef CONFIG_MULTIBOOT -int __init xsm_multiboot_init ( -unsigned long *module_map,const multiboot_info_t *mbi) +/* +* ifdef'ing this against multiboot is no longer valid as the boot module +* is agnostic and it will be possible to dropped the ifndef should Arm +* adopt boot info +*/ +#ifndef CONFIG_HAS_DEVICE_TREE +int __init xsm_bootmodule_init (const struct boot_info *bootinfo) {int ret =0 ; -void *policy_buffer =NULL ; +const unsigned char *policy_buffer =NULL ;size_t policy_size =0 ;printk ("XSM Framework v" XSM_FRAMEWORK_VERSION " initialized\n" );if (XSM_MAGIC ) { - ret =xsm_multiboot_policy_init (module_map, mbi, &policy_buffer, - &policy_size); -if ( ret ) - { -bootstrap_map (NULL ); -printk (XENLOG_ERR "Error %d initializing XSM policy\n" , ret); -return -EINVAL ; - } +int ret =xsm_bootmodule_policy_init (bootinfo, &policy_buffer, + &policy_size); +bootstrap_map (NULL ); + +if ( ret == -ENOENT ) +/* +* The XSM module needs a policy file but one was not located. +* Report as a warning and continue as the XSM module may late +* load a policy file. +*/ +printk (XENLOG_WARNING "xsm: starting without a policy loaded!\n" ); +else if ( ret ) +panic ("Error %d initializing XSM policy\n" , ret); } ret =xsm_core_init (policy_buffer, policy_size);@@ -165,9 +178,9 @@ int __init xsm_multiboot_init( return 0; } -#endif -#ifdef CONFIG_HAS_DEVICE_TREE +#else +int __init xsm_dt_init (void ) {int ret =0 ;@@ -215,9 +228,9 @@ bool __init has_xsm_magic(paddr_t start)return false; } -#endif +#endif /* CONFIG_HAS_DEVICE_TREE */ -#endif +#endif /* CONFIG_XSM */ long do_xsm_op (XEN_GUEST_HANDLE_PARAM (void ) op) {xen/xsm/xsm_policy.c +31
-28@@ -18,62 +18,65 @@* */ -#include <xsm/xsm.h> -#ifdef CONFIG_MULTIBOOT -#include <asm/boot.h> -#include <xen/multiboot.h> -#include <asm/setup.h> -#endif #include <xen/bitops.h> +#ifndef CONFIG_HAS_DEVICE_TREE +# include <xen/bootinfo.h> +#endif +#include <xsm/xsm.h> #ifdef CONFIG_HAS_DEVICE_TREE -# include <asm/setup.h> # include <xen/device_tree.h> +#else +#include <asm/boot.h> #endif -#ifdef CONFIG_MULTIBOOT -int __init xsm_multiboot_policy_init ( -unsigned long *module_map,const multiboot_info_t *mbi, -void **policy_buffer,size_t *policy_size) +#include <asm/setup.h> + +#ifndef CONFIG_HAS_DEVICE_TREE +int __init xsm_bootmodule_policy_init ( +const struct boot_info *bootinfo,const unsigned char **policy_buffer, +size_t *policy_size) { -int i; -module_t *mod = (module_t *)__va (mbi->mods_addr); -int rc =0 ; +unsigned long i; +int rc = -ENOENT ;u32 *_policy_start;unsigned long _policy_len; -/* -* Try all modules and see whichever could be the binary policy. -* Adjust module_map for the module that is the binary policy. -*/ -for ( i = mbi->mods_count-1 ; i >=1 ; i-- ) - { -if ( !test_bit (i, module_map) ) -continue ; +#ifdef CONFIG_XSM_FLASK_POLICY +/* Initially set to builtin policy, overriden if boot module is found. */ + *policy_buffer = xsm_flask_init_policy; + *policy_size = xsm_flask_init_policy_size; + rc =0 ; +#endif - _policy_start =bootstrap_map_multiboot (mod + i); - _policy_len = mod[i].mod_end; + i =bootmodule_index (bootinfo,BOOTMOD_UNKNOWN ,0 ); +while ( i < bootinfo->nr_mods ) + { + _policy_start =bootstrap_map (&bootinfo->mods[i]); + _policy_len = bootinfo->mods[i].size;if ( (xsm_magic_t)(*_policy_start) ==XSM_MAGIC ) { - *policy_buffer = _policy_start; + *policy_buffer = (unsigned char *)_policy_start; *policy_size = _policy_len;printk ("Policy len %#lx, start at %p.\n" , _policy_len,_policy_start); -__clear_bit (i, module_map); + bootinfo->mods[i].bootmod_type =BOOTMOD_XSM ; + rc =0 ;break ; }bootstrap_map (NULL ); + i =bootmodule_index (bootinfo,BOOTMOD_UNKNOWN , ++i); }return rc; } -#endif -#ifdef CONFIG_HAS_DEVICE_TREE +#else +int __init xsm_dt_policy_init (void **policy_buffer,size_t *policy_size) {struct bootmodule *mod =boot_module_find_by_kind (BOOTMOD_XSM );Signature · 1 line
2.25.1
Re: [PATCH 06/10] x86 setup, microcode: switch to the new bootinfo structures
In reply to Christopher ClarkQuoted 7 lines · Christopher Clark
Next step in incremental work towards adding a non-multiboot internal representation of boot modules, converting the fields being accessed for the startup calculations.
Move the per-module scan logic into a dedicated function from the iteration loop and set the
BOOTMOD_UCODEmodule type when microcode is found.
Quoted 6 lines
Completes the conversion from the
module_mapbitmap in x86 setup so it can be removed, along with the temporarybootstrap_mapmultiboot wrapper since the last code that uses it is removed in this change.Signed-off-by Christopher Clark <[email protected]>Signed-off-by Daniel P. Smith <[email protected]>
Quoted 354 lines
---
Changes since v1: patch is a subset of v1 series patches 2 and 3.
- Added the removal of the temporary bootstrap map functionxen/arch/x86/cpu/microcode/core.c | 148 +++++++++++++++------------ xen/arch/x86/include/asm/boot.h | 13 --- xen/arch/x86/include/asm/microcode.h | 7 +- xen/arch/x86/setup.c | 8 +- 4 files changed, 89 insertions(+), 87 deletions(-)xen/arch/x86/cpu/microcode/core.c +83
-65@@ -22,12 +22,12 @@*/ #include <xen/alternative-call.h> +#include <xen/bootinfo.h> #include <xen/cpu.h> #include <xen/earlycpio.h> #include <xen/err.h> #include <xen/guest_access.h> #include <xen/init.h> -#include <xen/multiboot.h> #include <xen/param.h> #include <xen/spinlock.h> #include <xen/stop_machine.h> @@ -57,7 +57,6 @@*/ #define MICROCODE_UPDATE_TIMEOUT_US 1000000 -static module_t __initdata ucode_mod;static signed int __initdata ucode_mod_idx;static bool_t __initdata ucode_mod_forced;static unsigned int nr_cores;@@ -150,75 +149,109 @@ static int __init cf_check parse_ucode(const char *s) }custom_param ("ucode" , parse_ucode); -void __init microcode_scan_module ( -unsigned long *module_map, -const multiboot_info_t *mbi) +#define MICROCODE_MODULE_MATCH 1 +#define MICROCODE_MODULE_NONMATCH 0 + +static int __init microcode_check_module (struct boot_module *mod) { -module_t *mod = (module_t *)__va (mbi->mods_addr);uint64_t *_blob_start;unsigned long _blob_size; -struct cpio_data cd; +struct cpio_data cd = {NULL ,0 };long offset;const char *p =NULL ; -int i; - - ucode_blob.size =0 ; -if ( !ucode_scan ) -return ;if ( boot_cpu_data.x86_vendor ==X86_VENDOR_AMD ) p ="kernel/x86/microcode/AuthenticAMD.bin" ;else if ( boot_cpu_data.x86_vendor ==X86_VENDOR_INTEL ) p ="kernel/x86/microcode/GenuineIntel.bin" ;else +return -EFAULT ; + + _blob_start =bootstrap_map (mod); + _blob_size = mod->size; +if ( !_blob_start ) + { +printk ("Could not map multiboot module (0x%lx) (size: %ld)\n" , + mod->start, _blob_size); +/* Non-fatal error, so just say no match */ +return MICROCODE_MODULE_NONMATCH ; + } + + cd =find_cpio_data (p, _blob_start, _blob_size, &offset/* ignore */ ); + +if ( cd.data ) + { + ucode_blob.size = cd.size; + ucode_blob.data = cd.data; + + mod->bootmod_type =BOOTMOD_UCODE ; +return MICROCODE_MODULE_MATCH ; + } + +bootstrap_map (NULL ); + +return MICROCODE_MODULE_NONMATCH ; +} + +void __init microcode_scan_module (struct boot_info *bootinfo) +{ +int i; + +if ( !ucode_scan )return ; -/* -* Try all modules and see whichever could be the microcode blob. -*/ -for ( i =1 /* Ignore dom0 kernel */ ; i < mbi->mods_count; i++ ) + i =bootmodule_index (bootinfo,BOOTMOD_UNKNOWN ,0 ); +while ( i < bootinfo->nr_mods ) { -if ( !test_bit (i, module_map) ) -continue ; +int ret =microcode_check_module (&bootinfo->mods[i]); - _blob_start =bootstrap_map_multiboot (&mod[i]); - _blob_size = mod[i].mod_end; -if ( !_blob_start ) +switch ( ret ) { -printk ("Could not map multiboot module #%d (size: %ld)\n" , - i, _blob_size); +case MICROCODE_MODULE_MATCH : +return ; +case MICROCODE_MODULE_NONMATCH : + i =bootmodule_index (bootinfo,BOOTMOD_UNKNOWN , ++i);continue ; +default : +printk ("%s: (err: %d) unable to check microcode\n" , + __func__, ret); +return ; } - cd.data =NULL ; - cd.size =0 ; - cd =find_cpio_data (p, _blob_start, _blob_size, &offset/* ignore */ ); -if ( cd.data ) - { - ucode_blob.size = cd.size; - ucode_blob.data = cd.data; -break ; - } -bootstrap_map (NULL ); } } -static void __init microcode_grab_module ( -unsigned long *module_map, -const multiboot_info_t *mbi) +static void __init microcode_grab_module (struct boot_info *bootinfo) { -module_t *mod = (module_t *)__va (mbi->mods_addr); + ucode_blob.size =0 ;if ( ucode_mod_idx <0 ) - ucode_mod_idx += mbi->mods_count; -if ( ucode_mod_idx <=0 || ucode_mod_idx >= mbi->mods_count || - !__test_and_clear_bit (ucode_mod_idx, module_map) ) - goto scan; - ucode_mod = mod[ucode_mod_idx]; -scan: + ucode_mod_idx += bootinfo->nr_mods; +if ( ucode_mod_idx >=0 && ucode_mod_idx <= bootinfo->nr_mods && + bootinfo->mods[ucode_mod_idx].bootmod_type ==BOOTMOD_UNKNOWN ) + { +int ret =microcode_check_module (&bootinfo->mods[ucode_mod_idx]); + +switch ( ret ) + { +case MICROCODE_MODULE_MATCH : +return ; +case MICROCODE_MODULE_NONMATCH : +break ; +default : +printk ("%s: (err: %d) unable to check microcode\n" , + __func__, ret); +return ; + } + } +if ( ucode_scan ) -microcode_scan_module (module_map, mbi); +microcode_scan_module (bootinfo); } +/* Undefining as they are not needed anymore */ +#undef MICROCODE_MODULE_MATCH +#undef MICROCODE_MODULE_NONMATCH +static struct microcode_ops __ro_after_init ucode_ops;static DEFINE_SPINLOCK (microcode_mutex);@@ -738,11 +771,6 @@ static int __init cf_check microcode_init(void) ucode_blob.size =0 ; ucode_blob.data =NULL ; } -else if ( ucode_mod.mod_end ) - { -bootstrap_map (NULL ); - ucode_mod.mod_end =0 ; - }return 0 ; }@@ -786,8 +814,7 @@ static int __init early_update_cache(const void *data, size_t len)return rc; } -int __init microcode_init_cache (unsigned long *module_map, -const struct multiboot_info *mbi) +int __init microcode_init_cache (struct boot_info *bootinfo) {int rc =0 ;@@ -796,12 +823,9 @@ int __init microcode_init_cache(unsigned long *module_map,if ( ucode_scan )/* Need to rescan the modules because they might have been relocated */ -microcode_scan_module (module_map, mbi); +microcode_scan_module (bootinfo); -if ( ucode_mod.mod_end ) - rc =early_update_cache (bootstrap_map_multiboot (&ucode_mod), - ucode_mod.mod_end); -else if ( ucode_blob.size ) +if ( ucode_blob.size ) rc =early_update_cache (ucode_blob.data, ucode_blob.size);return rc;@@ -819,11 +843,6 @@ static int __init early_microcode_update_cpu(void) len = ucode_blob.size; data = ucode_blob.data; } -else if ( ucode_mod.mod_end ) - { - len = ucode_mod.mod_end; - data =bootstrap_map_multiboot (&ucode_mod); - }if ( !data )return -ENOMEM ;@@ -842,8 +861,7 @@ static int __init early_microcode_update_cpu(void)return microcode_update_cpu (patch); } -int __init early_microcode_init (unsigned long *module_map, -const struct multiboot_info *mbi) +int __init early_microcode_init (struct boot_info *bootinfo) {const struct cpuinfo_x86 *c = &boot_cpu_data;int rc =0 ;@@ -867,11 +885,11 @@ int __init early_microcode_init(unsigned long *module_map,return -ENODEV ; } -microcode_grab_module (module_map, mbi); +microcode_grab_module (bootinfo); ucode_ops.collect_cpu_info (); -if ( ucode_mod.mod_end || ucode_blob.size ) +if ( ucode_blob.size ) rc =early_microcode_update_cpu ();return rc;xen/arch/x86/include/asm/boot.h +0
-13@@ -6,19 +6,6 @@#include <asm/setup.h> -static inline void *bootstrap_map_multiboot (const module_t *mod) -{ -struct boot_module bm; - -if ( !mod ) -return bootstrap_map (NULL ); - - bm.start = mod->mod_start <<PAGE_SHIFT ; - bm.size = mod->mod_end; - -return bootstrap_map (&bm); -} -static inline unsigned long bootmodule_index (const struct boot_info *info,bootmod_type_t bootmod_type,unsigned long start)xen/arch/x86/include/asm/microcode.h +3
-4@@ -1,6 +1,7 @@#ifndef ASM_X86__MICROCODE_H #define ASM_X86__MICROCODE_H +#include <xen/bootinfo.h> #include <xen/types.h> #include <xen/percpu.h> @@ -23,10 +24,8 @@ DECLARE_PER_CPU(struct cpu_signature, cpu_sig);void microcode_set_module (unsigned int idx);int microcode_update (XEN_GUEST_HANDLE (const_void ),unsigned long len); -int early_microcode_init (unsigned long *module_map, -const struct multiboot_info *mbi); -int microcode_init_cache (unsigned long *module_map, -const struct multiboot_info *mbi); +int early_microcode_init (struct boot_info *bootinfo); +int microcode_init_cache (struct boot_info *bootinfo);int microcode_update_one (void );#endif /* ASM_X86__MICROCODE_H */ xen/arch/x86/setup.c +3
-5@@ -1023,7 +1023,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)unsigned int initrdidx, num_parked =0 ;multiboot_info_t *mbi;module_t *mod; -unsigned long nr_pages, raw_max_page, module_map[1 ]; +unsigned long nr_pages, raw_max_page;int i, j, e820_warn =0 , bytes =0 ;unsigned long eb_start, eb_end;bool acpi_boot_table_init_done = false, relocated = false;@@ -1190,8 +1190,6 @@ void __init noreturn __start_xen(unsigned long mbi_p) }/* Dom0 kernel is the first boot module */ -bitmap_fill (module_map, mbi->mods_count); -__clear_bit (0 , module_map);/* Dom0 kernel is always first */ boot_info->mods[0 ].bootmod_type =BOOTMOD_KERNEL ;if ( pvh_boot )@@ -1371,7 +1369,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)* TODO: load ucode earlier once multiboot modules become accessible * at an earlier stage. */ -early_microcode_init (module_map, mbi); +early_microcode_init (boot_info);if ( xen_phys_start ) {@@ -1906,7 +1904,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)timer_init (); -microcode_init_cache (module_map, mbi);/* Needs xmalloc() */ +microcode_init_cache (boot_info);/* Needs xmalloc() */ tsx_init ();/* Needs microcode. May change HLE/RTM feature bits. */ Signature · 1 line
2.25.1
Re: [PATCH 09/10] arm setup: use common integer-typed bootmod definition
In reply to Christopher ClarkQuoted 21 lines · Christopher Clark
This change enables inclusion of <
xen/bootinfo.h> in Arm builds, required for subsequent patches in this series.It replaces the enum definition of
bootmodule_kindwithbootmod_type_tas enums are not fixed size as needed for packed structs which are needed for boot structures in subsequent changes.Signed-off-by Christopher Clark <[email protected]>Signed-off-by Daniel P. Smith <[email protected]>---
New for v2 series.xen/arch/arm/include/asm/setup.h | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)xen/arch/arm/include/asm/setup.h +0
-0
xen/arch/arm/include/asm/setup.h line 6
Quoted 4 lines
xen/arch/arm/include/asm/setup.h +1
-0@@ -3,6 +3,7 @@#include <public/version.h> #include <asm/p2m.h> +#include <xen/bootinfo.h>
I see this as very positive, but then I do think we should use a single definition of struct bootmodule, struct bootinfo and struct bootcmdline.
I don't think it is a good idea to have struct bootinfo here and struct boot_info in xen/include/xen/bootinfo.h with a similar definition and purpose.
I think we should have a single definition of struct bootinfo and struct bootmodule that works everywhere.
Quoted 7 lines
xen/arch/arm/include/asm/setup.h +0
-0#include <xen/device_tree.h> #define MIN_FDT_ALIGN 8@@ -12,15 +13,7 @@#define MAX_MODULES 32/* Current maximum useful modules */
xen/arch/arm/include/asm/setup.h line 16
Quoted 10 lines
xen/arch/arm/include/asm/setup.h +1
-9-typedef enum { -BOOTMOD_XEN , -BOOTMOD_FDT , -BOOTMOD_KERNEL , -BOOTMOD_RAMDISK , -BOOTMOD_XSM , -BOOTMOD_GUEST_DTB , -BOOTMOD_UNKNOWN -}bootmodule_kind ; +typedef bootmod_type_t bootmodule_kind ;
Why can't we use an enum for it?
Re: [PATCH 08/10] x86, arm, riscv: add per-arch bootinfo headers
In reply to Christopher ClarkQuoted 12 lines · Christopher Clark
Changes to ensure that inclusion of <
xen/bootinfo.h> succeeds in each of the main archtecture builds and in the 32-bit early x86 boot build.The <
xen/bootinfo.h> header contains structures that will be used in efi logic prior to the main start of Xen, so it needs to be suitable for inclusion in Arm source files.The same header will also be included in early x86 boot logic, where asm/* headers are not reachable, and so they cannot be transitively included, so a ifdef condition is needed to prevent an attempt to include <
asm/bootinfo.h> from within <xen/bootinfo.h> in that case.
Quoted 5 lines
The early x86 boot logic can then directly include <
asm/bootinfo.h> via a specified directory path where it can be included successfully.Signed-off-by Christopher Clark <[email protected]>Signed-off-by Daniel P. Smith <[email protected]>
I think this is fine.
Quoted 84 lines
---
New for v2 series.xen/arch/arm/include/asm/bootinfo.h | 20 ++++++++++++++++++++ xen/arch/riscv/include/asm/bootinfo.h | 20 ++++++++++++++++++++ xen/include/xen/bootinfo.h | 7 ++----- 3 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 xen/arch/arm/include/asm/bootinfo.h create mode 100644 xen/arch/riscv/include/asm/bootinfo.hxen/arch/arm/include/asm/bootinfo.h new file +20
-0@@ -0,0 +1,20 @@ +#ifndef __ARCH_ARM_BOOTINFO_H__ +#define __ARCH_ARM_BOOTINFO_H__ + +struct __packed arch_bootmodule { }; +DEFINE_STRUCT_PTR_TYPE (arch_bootmodule); + +struct __packed arch_boot_info { }; +DEFINE_STRUCT_PTR_TYPE (arch_boot_info); + +#endif + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/ xen/arch/riscv/include/asm/bootinfo.h new file +20
-0@@ -0,0 +1,20 @@ +#ifndef __ARCH_ARM_BOOTINFO_H__ +#define __ARCH_ARM_BOOTINFO_H__ + +struct __packed arch_bootmodule { }; +DEFINE_STRUCT_PTR_TYPE (arch_bootmodule); + +struct __packed arch_boot_info { }; +DEFINE_STRUCT_PTR_TYPE (arch_boot_info); + +#endif + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/ xen/include/xen/bootinfo.h +2
-5@@ -5,11 +5,8 @@#include <xen/compiler.h> #include <xen/mm-frame.h> -#ifdef CONFIG_X86 -#include <asm/bootinfo.h> -#else -struct arch_bootmodule { }; -struct arch_boot_info { }; +#if definedCONFIG_X86 ||CONFIG_ARM ||CONFIG_RISCV +# include <asm/bootinfo.h> #endif /* Boot module binary type / purpose */ Signature · 1 line
2.25.1
Re: [PATCH 07/10] x86 boot: define paddr_t and add macros for typedefing struct pointers
In reply to Christopher ClarkQuoted 5 lines · Christopher Clark
Pointer fields within structs need to be defined as fixed size types in the x86 boot build environment. Using a typedef for the field type rather than a struct pointer type enables the type definition to be changed in the 32-bit boot build and the main hypervisor build, allowing for a single common structure definition and a common header file.
Sorry for my ignorance, but why?
struct boot_module is not used as part of any ABI, right? It is populated by Xen at boot by hand. Why do we need a specific memory layout for it?
Quoted 120 lines
Introduces
DEFINE_STRUCT_PTR_TYPEandDEFINE_PTR_TYPEwhich will generate typedefs with a_ptr_tsuffix for pointers to the specified type. This is then used in <xen/bootinfo.h> for pointers within structs as preparation for using these headers in the x86 boot build.The 32-bit behaviour is obtained by inclusion of "
defs.h" first with a check for such an existing definition on the <xen/types.h> version.
paddr_tis used in <xen/bootinfo.h> so a definition is added here to the x86 boot environmentdefs.hheader.Signed-off-by Christopher Clark <[email protected]>Signed-off-by Daniel P. Smith <[email protected]>---
Changes since v2: This is two v2 patches merged into one for v3. Changes since v1: New in v2 of series.xen/arch/x86/boot/defs.h | 9 +++++++++ xen/arch/x86/include/asm/bootinfo.h | 4 +++- xen/include/xen/bootinfo.h | 9 +++++---- xen/include/xen/types.h | 11 +++++++++++ 4 files changed, 28 insertions(+), 5 deletions(-)xen/arch/x86/boot/defs.h +9
-0@@ -60,4 +60,13 @@ typedef u64 uint64_t;#define U16_MAX ((u16)(~0U))#define UINT_MAX (~0U) +typedef unsigned long long paddr_t ; + +#define DEFINE_STRUCT_PTR_TYPE (struct_name) \ + typedef uint64_t struct_name ## _ptr_t; + +#define DEFINE_PTR_TYPE (type) \ + typedef uint64_t type ## _ptr_t; +DEFINE_PTR_TYPE (char); +#endif /* __BOOT_DEFS_H__ */ xen/arch/x86/include/asm/bootinfo.h +3
-1@@ -6,6 +6,7 @@ struct arch_bootmodule {uint32_t flags;unsigned headroom; }; +DEFINE_STRUCT_PTR_TYPE (arch_bootmodule);struct arch_boot_info {uint32_t flags;@@ -14,11 +15,12 @@ struct arch_boot_info {#define BOOTINFO_FLAG_X86_MEMMAP 1U << 6#define BOOTINFO_FLAG_X86_LOADERNAME 1U << 9 -char *boot_loader_name; +char_ptr_t boot_loader_name;uint32_t mmap_length;paddr_t mmap_addr; }; +DEFINE_STRUCT_PTR_TYPE (arch_boot_info);struct __packed mb_memmap {uint32_t size;xen/include/xen/bootinfo.h +5
-4@@ -35,17 +35,18 @@ struct boot_module {mfn_t mfn;size_t size; -struct arch_bootmodule *arch; +arch_bootmodule_ptr_t arch; struct boot_string string; }; +DEFINE_STRUCT_PTR_TYPE (boot_module);struct boot_info { -char *cmdline; +char_ptr_t cmdline;unsigned int nr_mods; -struct boot_module *mods; +boot_module_ptr_t mods; -struct arch_boot_info *arch; +arch_boot_info_ptr_t arch; };#endif xen/include/xen/types.h +11
-0@@ -71,4 +71,15 @@ typedef bool bool_t;#define test_and_set_bool (b) xchg(&(b), true)#define test_and_clear_bool (b) xchg(&(b), false) +#ifndef DEFINE_STRUCT_PTR_TYPE +#define DEFINE_STRUCT_PTR_TYPE (struct_name) \ + typedef struct struct_name * struct_name ## _ptr_t; +#endif + +#ifndef DEFINE_PTR_TYPE +#define DEFINE_PTR_TYPE (type) \ + typedef type * type ## _ptr_t; +DEFINE_PTR_TYPE (char); +#endif +#endif /* __TYPES_H__ */ Signature · 1 line
2.25.1
Re: [PATCH 04/10] x86 setup: porting dom0 construction logic to boot module structures
In reply to Stefano StabelliniQuoted 15 lines · Stefano Stabellini
xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long mbi_p) · line 1388
Quoted 10 lines · Christopher Clark
xen/arch/x86/setup.c +3
-2@@ -1357,12 +1382,14 @@ void __init noreturn __start_xen(unsigned long mbi_p)* respective reserve_e820_ram() invocation below. No need to * query efi_boot_mem_unused() here, though. */ - mod[boot_info->nr_mods].mod_start =virt_to_mfn (_stext); - mod[boot_info->nr_mods].mod_end = __2M_rwdata_end - _stext; +bootmodule_update_start (&boot_info->mods[boot_info->nr_mods], +virt_to_maddr (_stext)); + boot_info->mods[boot_info->nr_mods].size = __2M_rwdata_end - _stext; }The original code had the end address as "
__2M_rwdata_end-_stext" while now we have the size as "__2M_rwdata_end-_stext" which is not the same?
A few lines up from here you'll find code adjusting what .mod_end holds:
We use it as a size field in most places (along with using page-granular .mod_start; page-granular .mod_end wouldn't work as an address, as modules may be any number of bytes).
Jan
Re: [PATCH 03/10] x86 setup: change bootstrap map to accept new boot module structures
In reply to Stefano StabelliniQuoted 27 lines · Stefano Stabellini
Quoted 16 lines · Christopher Clark
To convert the x86 boot logic from multiboot to boot module structures, change the bootstrap map function to accept a boot module parameter.
To allow incremental change from multiboot to boot modules across all x86 setup logic, provide a temporary inline wrapper that still accepts a multiboot module parameter and use it where necessary. The wrapper is placed in a new
arch/x86header <asm/boot.h> to avoid putting a static inline function into an existing header that has no such functions already. This new header will be expanded with additional functions in subsequent patches in this series.No functional change intended.
Signed-off-by Christopher Clark <[email protected]>Signed-off-by Daniel P. Smith <[email protected]>[...]
Quoted 7 lines
xen/include/xen/bootinfo.h +0
-0@@ -10,6 +10,9 @@#endif
Quoted 8 lines
xen/include/xen/bootinfo.h line 14
Quoted 3 lines
xen/include/xen/bootinfo.h +2
-0struct boot_module { +paddr_t start; +size_t size;I think size should be
paddr_t(instead ofsize_t) to make sure it is the right size on both 64-bit and 32-bit architectures that support 64-bit addresses.
Thanks, that explanation does make sense - ack.
Christopher
Quoted 5 lines
Quoted 4 lines
xen/include/xen/bootinfo.h +0
-0struct arch_bootmodule *arch; };
Re: [PATCH 01/10] x86 setup: move x86 boot module counting into a new boot_info struct
In reply to Stefano StabelliniQuoted 42 lines · Stefano Stabellini
Quoted 4 lines · Christopher Clark
An initial step towards a non-multiboot internal representation of boot modules for common code, starting with x86 setup and converting the fields that are accessed for the startup calculations.
Quoted 8 lines
Introduce a new header, <
xen/bootinfo.h>, and populate it with a newboot_infostructure initially containing a count of the number of boot modules.The naming of the header, structure and fields is intended to respect the boot structures on Arm -- see
arm/include/asm/setup.h-- as part of work towards aligning common architecture-neutral boot logic and structures.Thanks for aligning the two archs. At some point we should also have ARM use the common headers.
xen/arch/x86/setup.c static int __init cf_check parse_acpi_param(const
Quoted 23 lines
No functional change intended.
Signed-off-by Christopher Clark <[email protected]>Signed-off-by Daniel P. Smith <[email protected]>---
Changes since v1: patch is a subset of v1 series patches 2 and 3.xen/arch/x86/setup.c | 58 +++++++++++++++++++++++--------------- xen/include/xen/bootinfo.h | 20 +++++++++++++ 2 files changed, 55 insertions(+), 23 deletions(-) create mode 100644 xen/include/xen/bootinfo.hxen/arch/x86/setup.c +1
-0@@ -1,3 +1,4 @@ +#include <xen/bootinfo.h> #include <xen/init.h> #include <xen/lib.h> #include <xen/err.h> @@ -268,7 +269,16 @@ static int __init cf_check parse_acpi_param(constchar *s)
Quoted 8 lines
xen/arch/x86/setup.c static int __init cf_check parse_acpi_param(const char *s) · line 272
Quoted 5 lines
xen/arch/x86/setup.c +1
-1custom_param ("acpi" , parse_acpi_param);static const module_t *__initdata initial_images; -static unsigned int __initdata nr_initial_images; +static struct boot_info __initdata *boot_info;Why can't this be not a pointer?
In a later patch (10/10 in the same series posted), the boot_info pointer is passed as an argument to start_xen. On x86 there are currently three different entry points to this that have different environments which must all be made to behave the same, and passing the argument as a pointer is a lowest-common-denominater due to the 32bit x86 multiboot entry point. Additionally another entry point will be coming soon for TrenchBoot.
Defining it as a pointer now where this logic is introduced saves having to do a conversion of all accesses when the later change is made.
I can add a note about this to the commit message.
Quoted 8 lines
xen/arch/x86/setup.c static int __init cf_check parse_acpi_param(const char *s) · line 276
Quoted 5 lines
xen/arch/x86/setup.c +3
-0+static void __init multiboot_to_bootinfo (multiboot_info_t *mbi) +{ +static struct boot_info __initdata info;Then we don't need this
(see above)
Quoted 6 lines
xen/arch/x86/setup.c static int __init cf_check parse_acpi_param(const char *s) · line 280
Quoted 5 lines
xen/arch/x86/setup.c +3
-0+ info.nr_mods = mbi->mods_count; + + boot_info = &info;
Quoted 6 lines
And we could just do:
boot_info.nr_mods = mbi->mods_count;?
(see above)
Quoted 194 lines
xen/arch/x86/setup.c unsigned long __init initial_images_nrpages(nodeid_t
Quoted 7 lines
xen/arch/x86/setup.c +1
-0+}unsigned long __init initial_images_nrpages (nodeid_t node) {@@ -277,7 +287,7 @@ unsigned long __init initial_images_nrpages(nodeid_tnode)
Quoted 9 lines
xen/arch/x86/setup.c +1
-1unsigned long nr;unsigned int i; -for ( nr = i =0 ; i < nr_initial_images; ++i ) +for ( nr = i =0 ; i < boot_info->nr_mods; ++i ) {unsigned long start = initial_images[i].mod_start;unsigned long end = start +PFN_UP (initial_images[i].mod_end);xen/arch/x86/setup.c void __init discard_initial_images(void) · line 308
Quoted 7 lines
xen/arch/x86/setup.c +1
-1@@ -293,7 +303,7 @@ void __init discard_initial_images(void) {unsigned int i; -for ( i =0 ; i < nr_initial_images; ++i ) +for ( i =0 ; i < boot_info->nr_mods; ++i ) { uint64_t start = (uint64_t)initial_images[i].mod_start <<
PAGE_SHIFT;xen/arch/x86/setup.c void __init discard_initial_images(void) · line 311
Quoted 3 lines
xen/arch/x86/setup.c +0
-0@@ -301,7 +311,7 @@ void __init discard_initial_images(void) start +
PAGE_ALIGN(initial_images[i].mod_end));xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long
Quoted 8 lines
xen/arch/x86/setup.c +1
-1} - nr_initial_images =0 ; + boot_info->nr_mods =0 ; initial_images =NULL ; }@@ -1020,6 +1030,8 @@ void __init noreturn __start_xen(unsigned long
mbi_p)xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long
Quoted 9 lines
xen/arch/x86/setup.c +2
-0mod =__va (mbi->mods_addr); } +multiboot_to_bootinfo (mbi); + loader = (mbi->flags &MBI_LOADERNAME ) ? (char *)__va (mbi->boot_loader_name) :"unknown" ;@@ -1127,18 +1139,18 @@ void __init noreturn __start_xen(unsigned long
mbi_p)xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long mbi_p)
Quoted 6 lines
xen/arch/x86/setup.c +1
-1bootsym(boot_edd_info_nr));/* Check that we have at least one Multiboot module. */ -if ( !(mbi->flags &MBI_MODULES ) || (mbi->mods_count ==0 ) ) +if ( !(mbi->flags &MBI_MODULES ) || (boot_info->nr_mods ==0 ) ) panic("dom0 kernel not specified. Check bootloaderconfiguration\n");
xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long mbi_p)
Quoted 8 lines
xen/arch/x86/setup.c +2
-2/* Check that we don't have a silly number of modules. */ -if ( mbi->mods_count >sizeof (module_map) *8 ) +if ( boot_info->nr_mods >sizeof (module_map) *8 ) { - mbi->mods_count =sizeof (module_map) *8 ; + boot_info->nr_mods =sizeof (module_map) *8 ; printk("Excessive multiboot modules - using the first %uonly\n",
xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long
Quoted 10 lines
xen/arch/x86/setup.c +2
-2- mbi->mods_count); + boot_info->nr_mods); } -bitmap_fill (module_map, mbi->mods_count); +bitmap_fill (module_map, boot_info->nr_mods);__clear_bit (0 , module_map);/* Dom0 kernel is always first */ if ( pvh_boot )@@ -1311,9 +1323,9 @@ void __init noreturn __start_xen(unsigned long
mbi_p)xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long mbi_p)
Quoted 8 lines
xen/arch/x86/setup.c +2
-2kexec_reserve_area (&boot_e820); initial_images = mod; - nr_initial_images = mbi->mods_count; + boot_info->nr_mods = boot_info->nr_mods; -for ( i =0 ; !efi_enabled (EFI_LOADER ) && i < mbi->mods_count; i++ ) + for ( i = 0; !efi_enabled(EFI_LOADER) && i < boot_info->nr_mods;i++ )
xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long
Quoted 4 lines
xen/arch/x86/setup.c +0
-0{if ( mod[i].mod_start & (PAGE_SIZE -1 ) )panic ("Bootloader didn't honor module alignment request\n" );@@ -1337,8 +1349,8 @@ void __init noreturn __start_xen(unsigned long
mbi_p)xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long mbi_p)
Quoted 10 lines
xen/arch/x86/setup.c +2
-2* respective reserve_e820_ram() invocation below. No need to * query efi_boot_mem_unused() here, though. */ - mod[mbi->mods_count].mod_start =virt_to_mfn (_stext); - mod[mbi->mods_count].mod_end = __2M_rwdata_end - _stext; + mod[boot_info->nr_mods].mod_start =virt_to_mfn (_stext); + mod[boot_info->nr_mods].mod_end = __2M_rwdata_end - _stext; } modules_headroom = bzimage_headroom(bootstrap_map(mod),
mod->mod_end);xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long
Quoted 1 line
xen/arch/x86/setup.c +0
-0@@ -1398,7 +1410,7 @@ void __init noreturn __start_xen(unsigned long
mbi_p)xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long
Quoted 9 lines
xen/arch/x86/setup.c +1
-1{/* Don't overlap with modules. */ end =consider_modules (s, e, reloc_size + mask, - mod, mbi->mods_count,-1 ); + mod, boot_info->nr_mods,-1 ); end &= ~mask; } else@@ -1419,7 +1431,7 @@ void __init noreturn __start_xen(unsigned long
mbi_p)xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long · line 1433
Quoted 3 lines
xen/arch/x86/setup.c +0
-0}/* Is the region suitable for relocating the multiboot modules? */
xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long
Quoted 6 lines
xen/arch/x86/setup.c +1
-1-for ( j = mbi->mods_count -1 ; j >=0 ; j-- ) +for ( j = boot_info->nr_mods -1 ; j >=0 ; j-- ) {unsigned long headroom = j ?0 : modules_headroom;unsigned long size =PAGE_ALIGN (headroom + mod[j].mod_end);@@ -1429,7 +1441,7 @@ void __init noreturn __start_xen(unsigned long
mbi_p)xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long
Quoted 9 lines
xen/arch/x86/setup.c +1
-1/* Don't overlap with other modules (or Xen itself). */ end =consider_modules (s, e, size, mod, - mbi->mods_count + relocated, j); + boot_info->nr_mods + relocated, j);if ( highmem_start && end > highmem_start )continue ;@@ -1456,7 +1468,7 @@ void __init noreturn __start_xen(unsigned long
mbi_p)xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long mbi_p)
Quoted 3 lines
xen/arch/x86/setup.c +0
-0{/* Don't overlap with modules (or Xen itself). */ e = consider_modules(s, e,
PAGE_ALIGN(kexec_crash_area.size), mod,xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long
Quoted 6 lines
xen/arch/x86/setup.c +1
-1- mbi->mods_count + relocated, -1); + boot_info->nr_mods + relocated, -1);if ( s >= e )break ;if ( e > kexec_crash_area_limit )@@ -1471,7 +1483,7 @@ void __init noreturn __start_xen(unsigned long
mbi_p)xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long
Quoted 9 lines
xen/arch/x86/setup.c +1
-1if ( modules_headroom && !mod->reserved )panic ("Not enough memory to relocate the dom0 kernel image\n" ); -for ( i =0 ; i < mbi->mods_count; ++i ) +for ( i =0 ; i < boot_info->nr_mods; ++i ) {uint64_t s = (uint64_t )mod[i].mod_start <<PAGE_SHIFT ;@@ -1540,7 +1552,7 @@ void __init noreturn __start_xen(unsigned long
mbi_p)xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long
Quoted 9 lines
xen/arch/x86/setup.c +1
-1ASSERT (j); } map_e = boot_e820.map[j].addr + boot_e820.map[j].size; -for ( j =0 ; j < mbi->mods_count; ++j ) +for ( j =0 ; j < boot_info->nr_mods; ++j ) {uint64_t end =pfn_to_paddr (mod[j].mod_start) + mod[j].mod_end;@@ -1616,7 +1628,7 @@ void __init noreturn __start_xen(unsigned long
mbi_p)xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long
Quoted 9 lines
xen/arch/x86/setup.c +1
-1} } -for ( i =0 ; i < mbi->mods_count; ++i ) +for ( i =0 ; i < boot_info->nr_mods; ++i ) {set_pdx_range (mod[i].mod_start, mod[i].mod_start +PFN_UP (mod[i].mod_end));@@ -1999,8 +2011,8 @@ void __init noreturn __start_xen(unsigned long
mbi_p)xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long
Quoted 11 lines
xen/arch/x86/setup.c +2
-2cpu_has_nx ?XENLOG_INFO :XENLOG_WARNING "Warning: " , cpu_has_nx ? "" : "not "); - initrdidx =find_first_bit (module_map, mbi->mods_count); -if (bitmap_weight (module_map, mbi->mods_count) >1 ) + initrdidx =find_first_bit (module_map, boot_info->nr_mods); +if (bitmap_weight (module_map, boot_info->nr_mods) >1 )printk (XENLOG_WARNING "Multiple initrd candidates, picking module #%u\n" , initrdidx);@@ -2010,7 +2022,7 @@ void __init noreturn __start_xen(unsigned long
mbi_p)xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long · line 2022
Quoted 1 line
xen/arch/x86/setup.c +0
-0* above our heap. The second module, if present, is an initrd ramdisk.
xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long mbi_p)
Quoted 3 lines
xen/arch/x86/setup.c +0
-1*/ dom0 = create_dom0(mod, modules_headroom, - initrdidx < mbi->mods_count ? mod + initrdidx :NULL,
xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long · line 2025
Quoted 1 line
xen/arch/x86/setup.c +1
-0+ initrdidx < boot_info->nr_mods ? mod + initrdidx: NULL,
Quoted 16 lines
xen/include/xen/bootinfo.h line 4
Quoted 13 lines
xen/arch/x86/setup.c +0
-0kextra, loader);if ( !dom0 )panic ("Could not set up DOM0 guest OS\n" );xen/include/xen/bootinfo.h new file +4
-0@@ -0,0 +1,20 @@ +#ifndef __XEN_BOOTINFO_H__ +#define __XEN_BOOTINFO_H__ + +#include <xen/types.h> I don't think you need
types.hright now
Ack - thanks
Quoted 10 lines
xen/include/xen/bootinfo.h line 6
Quoted 3 lines
xen/include/xen/bootinfo.h new file +1
-0+struct boot_info {This is what we call struct bootmodules on ARM right? Would it help if we used the same name?
I am not asking to make the ARM code common because I think that would probably be a lot more work.
It becomes clearer to see by the end of the full hyperlaunch v1 series with the domain builder implemented, but it is also evident by the end of this
series: the core/common boot info for Xen is more than just a set of bootmodules. This first patch is part of adding functionality to common incrementally, as a starting point, and reducing this boot info to just a bootmodules structure is going to be limiting it in this context.
Christopher
Quoted 21 lines
Quoted 20 lines
xen/include/xen/bootinfo.h new file +14
-1+ unsigned int nr_mods; +}; + +#endif + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/ --2.25.1
Re: [PATCH 02/10] x86 setup: per-arch bootmodule structure, headroom field
In reply to Stefano StabelliniQuoted 68 lines · Stefano Stabellini
Quoted 18 lines · Christopher Clark
Next step in incremental work towards adding a non-multiboot internal representation of boot modules, converting the fields being accessed for the startup calculations.
Add a new array of structs for per-boot-module state, though only allocate space for a single array entry in this change since that is all that is required for functionality modified in this patch: moving the headroom field for the image decompression calculation into a new per-arch boot module struct and then using it in x86 dom0 construction.
Introduces a per-arch header for x86 for arch-specific boot module structures, and add a member to the common boot module structure for access to it.
No functional change intended.
Signed-off-by Christopher Clark <[email protected]>Signed-off-by Daniel P. Smith <[email protected]>[...]
Review
Quoted 1 line
(quoted diff) +0
-0
b/xen/arch/x86/include/asm/bootinfo.hQuoted 23 lines
new file mode 100644
index 0000000000..a25054f372xen/arch/x86/include/asm/bootinfo.h new file +18
-0@@ -0,0 +1,18 @@ +#ifndef __ARCH_X86_BOOTINFO_H__ +#define __ARCH_X86_BOOTINFO_H__ + +struct arch_bootmodule { +unsigned headroom; +}; + +#endif + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/ [...]
Quoted 17 lines
xen/include/xen/bootinfo.h +9
-0@@ -3,8 +3,19 @@#include <xen/types.h> +#ifdef CONFIG_X86 +#include <asm/bootinfo.h> +#else +struct arch_bootmodule { }; +#endif + +struct boot_module { +struct arch_bootmodule *arch; +};
Quoted 9 lines
xen/include/xen/bootinfo.h line 18
Quoted 4 lines
xen/include/xen/bootinfo.h +2
-0+struct boot_info {unsigned int nr_mods; +struct boot_module *mods;Also here you already made the effort of using the same data structures we use on ARM, you might as well use the same names too. Otherwise when we try to use them on ARM it will require a rename somewhere.
Thanks for the review. We consciously made an effort to derive from the Arm data structures to ensure that we're able to support the logic that Arm needs. Arm's bootmodules were a
good start as a means for abstraction, and the design for hyperlaunch was striving to abstract even further to incorporate x86-ism and hopefully enough foresight for PPC and Risc-V.
Christopher
Quoted 9 lines
Quoted 8 lines
xen/include/xen/bootinfo.h +0
-1};#endif --2.25.1
Re: [PATCH 03/10] x86 setup: change bootstrap map to accept new boot module structures
In reply to Christopher ClarkQuoted 41 lines · Christopher Clark
Quoted 27 lines · Stefano Stabellini
Quoted 16 lines · Christopher Clark
To convert the x86 boot logic from multiboot to boot module structures, change the bootstrap map function to accept a boot module parameter.
To allow incremental change from multiboot to boot modules across all x86 setup logic, provide a temporary inline wrapper that still accepts a multiboot module parameter and use it where necessary. The wrapper is placed in a new
arch/x86header <asm/boot.h> to avoid putting a static inline function into an existing header that has no such functions already. This new header will be expanded with additional functions in subsequent patches in this series.No functional change intended.
Signed-off-by Christopher Clark <[email protected]>Signed-off-by Daniel P. Smith <[email protected]>[...]
Quoted 7 lines
xen/include/xen/bootinfo.h +0
-0@@ -10,6 +10,9 @@#endif Quoted 8 lines
xen/include/xen/bootinfo.h line 14
Quoted 3 lines
xen/include/xen/bootinfo.h +2
-0struct boot_module { +paddr_t start; +size_t size;I think size should be
paddr_t(instead ofsize_t) to make sure it is the right size on both 64-bit and 32-bit architectures that support 64-bit addresses.
Quoted 2 lines
Thanks, that explanation does make sense - ack.
I've come back to reconsider this as it doesn't seem right to me to store a non-address value (which this will always be) in a type explicitly defined to hold an address: addresses may have architectural alignment requirements whereas a size value is just a number of bytes so will not. The point of a size_t value is that size_t is defined to be large enough to hold the size of any valid object in memory, so I think this was right as-is.
Christopher
Quoted 10 lines
Christopher
Quoted 5 lines
Quoted 4 lines
xen/include/xen/bootinfo.h +0
-0struct arch_bootmodule *arch; };
Re: [PATCH 04/10] x86 setup: porting dom0 construction logic to boot module structures
In reply to Stefano StabelliniQuoted 278 lines · Stefano Stabellini
Quoted 6 lines · Christopher Clark
Adjust the PV and PVH dom0 construction entry points to take boot module structures as parameters, and add further fields to the boot module structures to plumb the data needed to support this use. Populate these from the multiboot module data.
This change removes multiboot from the PV and PVH dom0 construction
logic.
Quoted 57 lines
Introduce and use new inline accessor functions for navigating the boot module structures.
The per-boot-module arrays are expanded from singletons to accommodate all modules, up to a static maximum of 64 modules including Xen that can be accepted from a bootloader to match the previous value from the module map check.
The field that identifies the type of a boot module (kernel, ramdisk, etc) is introduced to the common boot module structure and declared as a non-enum integer type to allow the field to be of a known-size and so structure can be packed in a subsequent patch in the series, and it will then be reconciled with the equivalent Arm boot field type.
The command line provided by multiboot for each boot module is added directly to the
boot_modulestructure, which is appropriate for this logic just replacing multiboot.The maximum number of boot modules that a bootloader can provide in addition to the Xen hypervisor is preserved from prior logic with the
module_mapat 63.Signed-off-by Christopher Clark <[email protected]>Signed-off-by Daniel P. Smith <[email protected]>---
Changes since v1: patch is a subset of v1 series patches 2 and 3.
- Themodule_mapis kept for now since still in use.
- Move the static inline functions into a separate dedicated header.
- <mm-frame.h> and <compiler.h> replace prior inclusion of <mm.h> for simpler dependencies.xen/arch/x86/dom0_build.c | 10 +- xen/arch/x86/hvm/dom0_build.c | 43 +++--- xen/arch/x86/include/asm/boot.h | 36 +++++ xen/arch/x86/include/asm/bootinfo.h | 24 +++ xen/arch/x86/include/asm/dom0_build.h | 13 +- xen/arch/x86/include/asm/setup.h | 4 +- xen/arch/x86/pv/dom0_build.c | 32 ++-- xen/arch/x86/setup.c | 206 +++++++++++++++----------- xen/include/xen/bootinfo.h | 27 ++++ 9 files changed, 254 insertions(+), 141 deletions(-)xen/arch/x86/dom0_build.c +1
-0@@ -4,6 +4,7 @@* Copyright (c) 2002-2005, K A Fraser */ +#include <xen/bootinfo.h> #include <xen/init.h> #include <xen/iocap.h> #include <xen/libelf.h> xen/arch/x86/dom0_build.c int __init dom0_setup_permissions(struct domain *d) · line 566
Quoted 5 lines
xen/arch/x86/dom0_build.c +0
-2@@ -562,9 +563,8 @@ int __init dom0_setup_permissions(struct domain *d)return rc; } -int __init construct_dom0 (struct domain *d,const module_t *image, - unsigned long image_headroom, module_t*initrd,
xen/arch/x86/dom0_build.c int __init dom0_setup_permissions(struct domain *d) · line 566
Quoted 2 lines
xen/arch/x86/dom0_build.c +1
-1- char *cmdline) +int __init construct_dom0(struct domain *d, const struct boot_module*image,
xen/arch/x86/dom0_build.c int __init construct_dom0(struct domain *d, const
Quoted 5 lines
xen/arch/x86/dom0_build.c +1
-0+ struct boot_module *initrd, char *cmdline) { int rc;@@ -576,9 +576,9 @@ int __init construct_dom0(struct domain *d, const
module_t*image,xen/arch/x86/dom0_build.c int __init construct_dom0(struct domain *d, const module_t *image,
Quoted 4 lines
xen/arch/x86/dom0_build.c +0
-1process_pending_softirqs ();if (is_hvm_domain (d) ) - rc = dom0_construct_pvh(d, image, image_headroom, initrd,cmdline);
xen/arch/x86/dom0_build.c int __init construct_dom0(struct domain *d, const module_t *image,
Quoted 3 lines
xen/arch/x86/dom0_build.c +1
-1+ rc =dom0_construct_pvh (d, image, initrd, cmdline); else if ( is_pv_domain(d) ) - rc = dom0_construct_pv(d, image, image_headroom, initrd,cmdline);
Review
Quoted 5 lines
xen/arch/x86/dom0_build.c +1
-0+ rc =dom0_construct_pv (d, image, initrd, cmdline); else panic("Cannot construct Dom0. No guest interface available\n");(quoted diff) +0
-0
b/xen/arch/x86/hvm/dom0_build.cQuoted 15 lines
index
56fe89632b..c094863bb8100644xen/arch/x86/hvm/dom0_build.c +1
-1@@ -8,9 +8,9 @@*/ #include <xen/acpi.h> +#include <xen/bootinfo.h> #include <xen/init.h> #include <xen/libelf.h> -#include <xen/multiboot.h> #include <xen/pci.h> #include <xen/softirq.h> xen/arch/x86/hvm/dom0_build.c static paddr_t __init find_memory( · line 533
Quoted 4 lines
xen/arch/x86/hvm/dom0_build.c +0
-1@@ -530,14 +530,13 @@ static paddr_t __init find_memory(return INVALID_PADDR ; } -static int __init pvh_load_kernel(struct domain *d, const module_t*image,
xen/arch/x86/hvm/dom0_build.c static paddr_t __init find_memory(
Quoted 7 lines
xen/arch/x86/hvm/dom0_build.c +3
-4-unsigned long image_headroom, - module_t *initrd, void *image_base, - char *cmdline, paddr_t *entry, - paddr_t *start_info_addr) +static int __init pvh_load_kernel( + struct domain *d, const struct boot_module *image, + struct boot_module *initrd, void *image_base, char *cmdline,
paddr_t*entry,xen/arch/x86/hvm/dom0_build.c static int __init pvh_load_kernel(struct domain *d,
Quoted 10 lines
xen/arch/x86/hvm/dom0_build.c +3
-2+ paddr_t *start_info_addr) { -void *image_start = image_base + image_headroom; -unsigned long image_len = image->mod_end; +void *image_start = image_base + image->arch->headroom; +unsigned long image_len = image->size;struct elf_binary elf;struct elf_dom_parms parms;paddr_t last_addr;@@ -546,7 +545,7 @@ static int __init pvh_load_kernel(struct domain *d,const
module_t*image,xen/arch/x86/hvm/dom0_build.c static int __init pvh_load_kernel(struct domain *d, const module_t *image,
Quoted 5 lines
xen/arch/x86/hvm/dom0_build.c +1
-1struct vcpu *v = d->vcpu[0 ];int rc; - if ( (rc = bzimage_parse(image_base, &image_start, image_headroom, + if ( (rc = bzimage_parse(image_base, &image_start,
image->arch->headroom,xen/arch/x86/hvm/dom0_build.c static int __init pvh_load_kernel(struct domain *d,
Quoted 4 lines
xen/arch/x86/hvm/dom0_build.c +0
-0&image_len)) != 0 ) {printk ("Error trying to detect bz compressed kernel\n" );@@ -594,7 +593,7 @@ static int __init pvh_load_kernel(struct domain *d,const
module_t*image,xen/arch/x86/hvm/dom0_build.c static int __init pvh_load_kernel(struct domain *d, const module_t *image,
Quoted 4 lines
xen/arch/x86/hvm/dom0_build.c +0
-1* simplify it. */ last_addr = find_memory(d, &elf, sizeof(start_info) + - (initrd ? ROUNDUP(initrd->mod_end,
PAGE_SIZE) +xen/arch/x86/hvm/dom0_build.c static int __init pvh_load_kernel(struct domain *d,
Quoted 5 lines
xen/arch/x86/hvm/dom0_build.c +1
-0+ (initrd ?ROUNDUP (initrd->size,PAGE_SIZE ) +sizeof (mod) : 0) + (cmdline ? ROUNDUP(strlen(cmdline) + 1,@@ -608,8 +607,8 @@ static int __init pvh_load_kernel(struct domain *d,const
module_t*image,xen/arch/x86/hvm/dom0_build.c static int __init pvh_load_kernel(struct domain *d, const module_t *image,
Quoted 4 lines
xen/arch/x86/hvm/dom0_build.c +0
-1if ( initrd !=NULL ) { - rc = hvm_copy_to_guest_phys(last_addr,
mfn_to_virt(initrd->mod_start),xen/arch/x86/hvm/dom0_build.c static int __init pvh_load_kernel(struct domain *d, · line 609
Quoted 2 lines
xen/arch/x86/hvm/dom0_build.c +1
-1- initrd->mod_end, v); + rc = hvm_copy_to_guest_phys(last_addr,
maddr_to_virt(initrd->start),xen/arch/x86/hvm/dom0_build.c static int __init pvh_load_kernel(struct domain
Quoted 5 lines
xen/arch/x86/hvm/dom0_build.c +1
-0+ initrd->size, v);if ( rc ) {printk ("Unable to copy initrd to guest\n" );@@ -617,11 +616,11 @@ static int __init pvh_load_kernel(struct domain*d, const
module_t*image,xen/arch/x86/hvm/dom0_build.c static void __hwdom_init pvh_setup_mmcfg(struct
Quoted 16 lines
xen/arch/x86/hvm/dom0_build.c +4
-4} mod.paddr = last_addr; - mod.size = initrd->mod_end; - last_addr +=ROUNDUP (initrd->mod_end,elf_64bit (&elf) ?8 :4 ); -if ( initrd->string ) + mod.size = initrd->size; + last_addr +=ROUNDUP (initrd->size,elf_64bit (&elf) ?8 :4 ); +if ( initrd->string.len ) { -char *str =__va (initrd->string); +char *str = initrd->string.bytes;size_t len =strlen (str) +1 ; rc =hvm_copy_to_guest_phys (last_addr, str, len, v);@@ -1176,10 +1175,9 @@ static void __hwdom_init pvh_setup_mmcfg(structdomain *d)
xen/arch/x86/hvm/dom0_build.c int __init dom0_construct_pvh(struct domain *d,
Quoted 14 lines
xen/arch/x86/hvm/dom0_build.c +3
-4} } -int __init dom0_construct_pvh (struct domain *d,const module_t *image, -unsigned long image_headroom, -module_t *initrd, -char *cmdline) +int __init dom0_construct_pvh ( +struct domain *d,const struct boot_module *image, +struct boot_module *initrd,char *cmdline) {paddr_t entry, start_info;int rc;@@ -1209,9 +1207,8 @@ int __init dom0_construct_pvh(struct domain *d,const
module_t*image,xen/arch/x86/hvm/dom0_build.c int __init dom0_construct_pvh(struct domain *d, const module_t *image,
Quoted 7 lines
xen/arch/x86/hvm/dom0_build.c +1
-3return rc; } - rc =pvh_load_kernel (d, image, image_headroom, initrd, -bootstrap_map_multiboot (image), - cmdline, &entry, &start_info); + rc = pvh_load_kernel(d, image, initrd, bootstrap_map(image),cmdline,
Review
Quoted 5 lines
xen/arch/x86/hvm/dom0_build.c +1
-0+ &entry, &start_info);if ( rc ) {printk ("Failed to load Dom0 kernel\n" );(quoted diff) +0
-0
b/xen/arch/x86/include/asm/boot.hxen/arch/x86/include/asm/boot.h static inline void *bootstrap_map_multiboot(const
Quoted 4 lines
index
10b17f12b2..bcf4f2e2e3100644xen/arch/x86/include/asm/boot.h +0
-0@@ -19,6 +19,42 @@ static inline void *bootstrap_map_multiboot(const
module_t*mod)Quoted 24 lines
xen/arch/x86/include/asm/boot.h +21
-0return bootstrap_map (&bm); } +static inline unsigned long bootmodule_index ( +const struct boot_info *info,bootmod_type_t bootmod_type, +unsigned long start) +{ +for ( ; start < info->nr_mods; start++ ) +if ( info->mods[start].bootmod_type == bootmod_type ) +return start; + +return info->nr_mods +1 ; +} + +static inline struct boot_module *bootmodule_next ( +const struct boot_info *info,bootmod_type_t bootmod_type) +{ +unsigned long i; + +for ( i =0 ; i < info->nr_mods; i++ ) +if ( info->mods[i].bootmod_type == bootmod_type ) +return &info->mods[i]; + +return NULL ;xen/arch/x86/include/asm/boot.h static inline void *bootstrap_map_multiboot(const module_t *mod)
Quoted 10 lines
xen/arch/x86/include/asm/boot.h +10
-0+} + +static inline void bootmodule_update_start (struct boot_module *bm, +paddr_t new_start) +{ + bm->start = new_start; + bm->mfn =maddr_to_mfn (new_start); +} + +static inline void bootmodule_update_mfn(struct boot_module *bm, mfn_t
new_mfn)Review
Quoted 9 lines
xen/arch/x86/include/asm/boot.h +5
-0+{ + bm->mfn = new_mfn; + bm->start =mfn_to_maddr (new_mfn); +} +#endif /* (quoted diff) +0
-0
b/xen/arch/x86/include/asm/bootinfo.hQuoted 12 lines
index
a25054f372..30c27980e0100644xen/arch/x86/include/asm/bootinfo.h +2
-0@@ -2,9 +2,33 @@#define __ARCH_X86_BOOTINFO_H__struct arch_bootmodule { +#define BOOTMOD_FLAG_X86_RELOCATED 1U << 0 +uint32_t flags;unsigned headroom; };
Quoted 6 lines
xen/arch/x86/include/asm/bootinfo.h line 12
Quoted 3 lines
xen/arch/x86/include/asm/bootinfo.h +3
-0+struct arch_boot_info { +uint32_t flags; +#define BOOTINFO_FLAG_X86_CMDLINE 1U << 2Is this to indicate the presence of the Xen cmdline?
Yes; it replaces the previous use of the MBI_CMDLINE flag and is set whenever MBI_CMDLINE is set when passed from multiboot. This indicates that a command line has been passed via multiboot.
A comment in the conversion function confirms the intended use of the flag field:
/* The BOOTINFO_FLAG_X86_* flags are a 1-1 map to MBI_* */
Quoted 40 lines
Quoted 40 lines
xen/arch/x86/include/asm/bootinfo.h +19
-0+#define BOOTINFO_FLAG_X86_MODULES 1U << 3 +#define BOOTINFO_FLAG_X86_MEMMAP 1U << 6 +#define BOOTINFO_FLAG_X86_LOADERNAME 1U << 9 + +char *boot_loader_name; + +uint32_t mmap_length; + paddr_t mmap_addr; +}; + +struct __packed mb_memmap { +uint32_t size; +uint32_t base_addr_low; +uint32_t base_addr_high; +uint32_t length_low; +uint32_t length_high; +uint32_t type; +}; +#endif /* xen/arch/x86/setup.c +1
-0@@ -37,6 +37,7 @@#include <asm/processor.h> #include <asm/mpspec.h> #include <asm/apic.h> +#include <asm/boot.h> #include <asm/msi.h> #include <asm/desc.h> #include <asm/paging.h> @@ -59,6 +60,9 @@#include <asm/prot-key.h> #include <asm/pv/domain.h>
Quoted 8 lines
xen/arch/x86/setup.c line 63
Quoted 1 line
xen/arch/x86/setup.c +1
-0+/* Max number of boot modules a bootloader can provide in addition to Xen */
xen/arch/x86/setup.c line 64
Quoted 1 line
xen/arch/x86/setup.c +1
-0+#define MAX_NR_BOOTMODS 63Call it
MAX_MODULES?
Like I wrote in the past, you already did the hard work of aligning the interfaces, we might as well also use the same names.
On the general naming: BOOTMODS is more descriptive in that it indicates an association between the module and the context it is from: ie. boot, and is a module handed to the hypervisor by a bootloader (as opposed to say, a late-loaded module). The term BOOTMOD is also already used within the Arm source, see: BOOTMOD_MAX_CMDLINE.
On using the same name: following the feedback in the previous round of reviews this value doesn't include a count of the hypervisor itself; so it isn't the same thing and so I wouldn't use the same name for it.
Quoted 13 lines
[...]
xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long
Quoted 1 line
xen/arch/x86/setup.c +0
-0@@ -1357,12 +1382,14 @@ void __init noreturn __start_xen(unsigned long
mbi_p)xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long mbi_p)
Quoted 8 lines
xen/arch/x86/setup.c +3
-2* respective reserve_e820_ram() invocation below. No need to * query efi_boot_mem_unused() here, though. */ - mod[boot_info->nr_mods].mod_start =virt_to_mfn (_stext); - mod[boot_info->nr_mods].mod_end = __2M_rwdata_end - _stext; +bootmodule_update_start (&boot_info->mods[boot_info->nr_mods], +virt_to_maddr (_stext)); + boot_info->mods[boot_info->nr_mods].size = __2M_rwdata_end -
Quoted 7 lines
_stext;xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long · line 1388
Quoted 1 line
xen/arch/x86/setup.c +0
-0}The original code had the end address as "
__2M_rwdata_end-_stext" while now we have the size as "__2M_rwdata_end-_stext" which is not the same?
(this was answered by Jan in a previous reply)
Quoted 32 lines
Quoted 10 lines
xen/arch/x86/setup.c +2
-1boot_info->mods[0 ].arch->headroom = -bzimage_headroom (bootstrap_map_multiboot (mod), mod->mod_end); +bzimage_headroom (bootstrap_map (&boot_info->mods[0 ]), + boot_info->mods[0 ].size);bootstrap_map (NULL );[...]
Quoted 18 lines
xen/include/xen/bootinfo.h +3
-0@@ -2,23 +2,50 @@#define __XEN_BOOTINFO_H__#include <xen/types.h> +#include <xen/compiler.h> +#include <xen/mm-frame.h> #ifdef CONFIG_X86 #include <asm/bootinfo.h> #else struct arch_bootmodule { }; +struct arch_boot_info { };#endif
Quoted 15 lines
xen/include/xen/bootinfo.h line 26
Quoted 12 lines
xen/include/xen/bootinfo.h +12
-0+/* Boot module binary type / purpose */ +#define BOOTMOD_UNKNOWN 0 +#define BOOTMOD_XEN 1 +#define BOOTMOD_FDT 2 +#define BOOTMOD_KERNEL 3 +#define BOOTMOD_RAMDISK 4 +#define BOOTMOD_XSM 5 +#define BOOTMOD_UCODE 6 +#define BOOTMOD_GUEST_DTB 7 +typedef unsigned int bootmod_type_t ; + +#define BOOTMOD_STRING_MAX_LEN 1024
BOOTMOD_MAX_CMDLINE?
The string associated with a boot module may not be a command line; it depends on the type of the module, hence BOOTMOD_MAX_STRING was what it was called in v1 of the hyperlaunch series, and I revised it to this since I think it's clearer.
ie. There's a purpose to the rename.
Quoted 6 lines
xen/include/xen/bootinfo.h line 27
Quoted 3 lines
xen/include/xen/bootinfo.h +1
-0+struct boot_string {struct bootcmdline ?
It is similar to bootcmdline in that it stores the contents of the string provided by the bootloader to associate with a boot module, but the struct contents differ and the way that it is accessed is different too.
I think it replaces bootcmdline once the new structures are fully in use on Arm.
Quoted 6 lines
xen/include/xen/bootinfo.h line 28
Quoted 3 lines
xen/include/xen/bootinfo.h +1
-0+char bytes[BOOTMOD_STRING_MAX_LEN ];cmdline?
It may not be command line, depending on the module type, hence the interest in using a different term for it.
Quoted 3 lines
If the string is \0 terminated we don't need len?
This is for generalized strings associated with boot modules supplied by the bootloader, not just command lines, so additional consideration may be wanted. This is a defensive mechanism, attackers don't follow specifications and sometimes people cause bugs.
Quoted 10 lines
xen/include/xen/bootinfo.h line 33
Quoted 7 lines
xen/include/xen/bootinfo.h +4
-0+size_t len; +}; +struct boot_module { +bootmod_type_t bootmod_type;Why not use a good old enum?
The early x86 boot logic that runs in 32-bit mode populates the structures which are then accessed in the main hypervisor initialization logic in 64-bit mode, and we would like to have a single common definition for the structures in a header that is useable in both places, so that requires preparing for fixed-size types in packed structures; an enum isn't guaranteed to compile to
the same size in those two cases, so doesn't pack. To make transition for the Arm code easier I can make these definitions closer to the old enum though.
Quoted 7 lines
xen/include/xen/bootinfo.h line 35
Quoted 4 lines
xen/include/xen/bootinfo.h +1
-0paddr_t start; +mfn_t mfn;I think mfn should be in
arch_bootmodule
I think that's ok if it's not needed in non-x86 logic.
Quoted 4 lines
Quoted 4 lines
xen/include/xen/bootinfo.h +0
-0size_t size;
Quoted 8 lines
xen/include/xen/bootinfo.h line 43
Quoted 6 lines
xen/include/xen/bootinfo.h +2
-0struct arch_bootmodule *arch; +struct boot_string string; };struct boot_info { +char *cmdline;Is this for Xen cmdline?
Yes
Quoted 5 lines
While all the other cmdline are in the various
structboot_string? Is there any benefit in using theBOOTMOD_XENfor it?BOOTMOD_XENis not used so far, so if you don't end up using it, probably not, otherwise it could be considered.
ok - I agree that we haven't dropped any use of BOOTMOD_XEN so far but will keep it in mind.
thanks,
Christopher
Quoted 16 lines
Quoted 15 lines
xen/include/xen/bootinfo.h +2
-1unsigned int nr_mods;struct boot_module *mods; + + struct arch_boot_info *arch; };#endif --2.25.1
Re: [PATCH 07/10] x86 boot: define paddr_t and add macros for typedefing struct pointers
In reply to Stefano StabelliniQuoted 6 lines · Stefano Stabellini
Quoted 5 lines · Christopher Clark
Pointer fields within structs need to be defined as fixed size types in the x86 boot build environment. Using a typedef for the field type rather than a struct pointer type enables the type definition to be changed in the 32-bit boot build and the main hypervisor build, allowing for a single common structure definition and a common header
Quoted 8 lines
file.
Sorry for my ignorance, but why?
struct
boot_moduleis not used as part of any ABI, right? It is populated by Xen at boot by hand. Why do we need a specific memory layout for it?
Fair question! In the early x86 boot logic, which runs in 32-bit CPU mode, struct boot_module is allocated and populated, so the structure needs to be defined and available to code that is compiled in 32-bit to do that. The same structures are also accessed later in 64-bit hypervisor logic, and the memory layout of the structure needs to be the same in both cases, so we want all the fields to be fixed-width types, and that includes pointers.
These macros help with declaring pointers as always-64-bit-sized struct fields in a single definition of the struct. They're not strictly necessary though - providing alternative definitions for typedefs can be used instead, and I've been looking at doing that since posting this patch.
Christopher
Quoted 125 lines
Review
Quoted 47 lines
Introduces
DEFINE_STRUCT_PTR_TYPEandDEFINE_PTR_TYPEwhich will generate typedefs with a_ptr_tsuffix for pointers to the specified type. This is then used in <xen/bootinfo.h> for pointers within structs as preparation for using these headers in the x86 boot build.The 32-bit behaviour is obtained by inclusion of "
defs.h" first with a check for such an existing definition on the <xen/types.h> version.
paddr_tis used in <xen/bootinfo.h> so a definition is added here to the x86 boot environmentdefs.hheader.Signed-off-by Christopher Clark <[email protected]>Signed-off-by Daniel P. Smith <[email protected]>---
Changes since v2: This is two v2 patches merged into one for v3. Changes since v1: New in v2 of series.xen/arch/x86/boot/defs.h | 9 +++++++++ xen/arch/x86/include/asm/bootinfo.h | 4 +++- xen/include/xen/bootinfo.h | 9 +++++---- xen/include/xen/types.h | 11 +++++++++++ 4 files changed, 28 insertions(+), 5 deletions(-)xen/arch/x86/boot/defs.h +9
-0@@ -60,4 +60,13 @@ typedef u64 uint64_t;#define U16_MAX ((u16)(~0U))#define UINT_MAX (~0U) +typedef unsigned long long paddr_t ; + +#define DEFINE_STRUCT_PTR_TYPE (struct_name) \ + typedef uint64_t struct_name ## _ptr_t; + +#define DEFINE_PTR_TYPE (type) \ + typedef uint64_t type ## _ptr_t; +DEFINE_PTR_TYPE (char); +#endif /* __BOOT_DEFS_H__ */ (quoted diff) +0
-0
b/xen/arch/x86/include/asm/bootinfo.hQuoted 76 lines
index
30c27980e0..989fb7a1da100644xen/arch/x86/include/asm/bootinfo.h +3
-1@@ -6,6 +6,7 @@ struct arch_bootmodule {uint32_t flags;unsigned headroom; }; +DEFINE_STRUCT_PTR_TYPE (arch_bootmodule);struct arch_boot_info {uint32_t flags;@@ -14,11 +15,12 @@ struct arch_boot_info {#define BOOTINFO_FLAG_X86_MEMMAP 1U << 6#define BOOTINFO_FLAG_X86_LOADERNAME 1U << 9 -char *boot_loader_name; +char_ptr_t boot_loader_name;uint32_t mmap_length;paddr_t mmap_addr; }; +DEFINE_STRUCT_PTR_TYPE (arch_boot_info);struct __packed mb_memmap {uint32_t size;xen/include/xen/bootinfo.h +5
-4@@ -35,17 +35,18 @@ struct boot_module {mfn_t mfn;size_t size; -struct arch_bootmodule *arch; +arch_bootmodule_ptr_t arch; struct boot_string string; }; +DEFINE_STRUCT_PTR_TYPE (boot_module);struct boot_info { -char *cmdline; +char_ptr_t cmdline;unsigned int nr_mods; -struct boot_module *mods; +boot_module_ptr_t mods; -struct arch_boot_info *arch; +arch_boot_info_ptr_t arch; };#endif xen/include/xen/types.h +11
-1@@ -71,4 +71,15 @@ typedef bool bool_t;#define test_and_set_bool (b) xchg(&(b), true)#define test_and_clear_bool (b) xchg(&(b), false) +#ifndef DEFINE_STRUCT_PTR_TYPE +#define DEFINE_STRUCT_PTR_TYPE (struct_name) \ + typedef struct struct_name * struct_name ## _ptr_t; +#endif + +#ifndef DEFINE_PTR_TYPE +#define DEFINE_PTR_TYPE (type) \ + typedef type * type ## _ptr_t; +DEFINE_PTR_TYPE (char); +#endif +#endif /* __TYPES_H__ */ --2.25.1
Re: [PATCH 03/10] x86 setup: change bootstrap map to accept new boot module structures
In reply to Christopher ClarkQuoted 47 lines · Christopher Clark
Quoted 41 lines · Christopher Clark
Quoted 27 lines · Stefano Stabellini
Quoted 16 lines · Christopher Clark
To convert the x86 boot logic from multiboot to boot module structures, change the bootstrap map function to accept a boot module parameter.
To allow incremental change from multiboot to boot modules across all x86 setup logic, provide a temporary inline wrapper that still accepts a multiboot module parameter and use it where necessary. The wrapper is placed in a new
arch/x86header <asm/boot.h> to avoid putting a static inline function into an existing header that has no such functions already. This new header will be expanded with additional functions in subsequent patches in this series.No functional change intended.
Signed-off-by Christopher Clark <[email protected]>Signed-off-by Daniel P. Smith <[email protected]>[...]
Quoted 7 lines
xen/include/xen/bootinfo.h +0
-0@@ -10,6 +10,9 @@#endif Quoted 8 lines
xen/include/xen/bootinfo.h line 14
Quoted 3 lines
xen/include/xen/bootinfo.h +2
-0struct boot_module { +paddr_t start; +size_t size;I think size should be
paddr_t(instead ofsize_t) to make sure it is the right size on both 64-bit and 32-bit architectures that support 64-bit addresses.Quoted 2 lines
Thanks, that explanation does make sense - ack.
Quoted 6 lines
I've come back to reconsider this as it doesn't seem right to me to store a non-address value (which this will always be) in a type explicitly defined to hold an address: addresses may have architectural alignment requirements whereas a size value is just a number of bytes so will not. The point of a
size_tvalue is thatsize_tis defined to be large enough to hold the size of any valid object in memory, so I think this was right as-is.
"Any object in memory" implies virtual addresses (or more generally addresses which can be used for accessing objects). This isn't the case when considering physical addresses - there may be far more memory in a system than can be made accessible all in one go.
Jan
Re: [PATCH 03/10] x86 setup: change bootstrap map to accept new boot module structures
Quoted 55 lines · Jan Beulich
Quoted 47 lines · Christopher Clark
Quoted 41 lines · Christopher Clark
Quoted 27 lines · Stefano Stabellini
Quoted 16 lines · Christopher Clark
To convert the x86 boot logic from multiboot to boot module structures, change the bootstrap map function to accept a boot module parameter.
To allow incremental change from multiboot to boot modules across all x86 setup logic, provide a temporary inline wrapper that still accepts a multiboot module parameter and use it where necessary. The wrapper is placed in a new
arch/x86header <asm/boot.h> to avoid putting a static inline function into an existing header that has no such functions already. This new header will be expanded with additional functions in subsequent patches in this series.No functional change intended.
Signed-off-by Christopher Clark <[email protected]>Signed-off-by Daniel P. Smith <[email protected]>[...]
Quoted 7 lines
xen/include/xen/bootinfo.h +0
-0@@ -10,6 +10,9 @@#endif Quoted 8 lines
xen/include/xen/bootinfo.h line 14
Quoted 3 lines
xen/include/xen/bootinfo.h +2
-0struct boot_module { +paddr_t start; +size_t size;I think size should be
paddr_t(instead ofsize_t) to make sure it is the right size on both 64-bit and 32-bit architectures that support 64-bit addresses.Quoted 2 lines
Thanks, that explanation does make sense - ack.
Quoted 6 lines
I've come back to reconsider this as it doesn't seem right to me to store a non-address value (which this will always be) in a type explicitly defined to hold an address: addresses may have architectural alignment requirements whereas a size value is just a number of bytes so will not. The point of a
size_tvalue is thatsize_tis defined to be large enough to hold the size of any valid object in memory, so I think this was right as-is.
Quoted 4 lines
"Any object in memory" implies virtual addresses (or more generally addresses which can be used for accessing objects). This isn't the case when considering physical addresses - there may be far more memory in a system than can be made accessible all in one go.
Right. And I think size_t is defined as 32-bit in Xen which is a problem.
Re: [PATCH 01/10] x86 setup: move x86 boot module counting into a new boot_info struct
In reply to Christopher Clark(You might want to check your email settings because it looks like you sent an html email)
Quoted 7 lines · Christopher Clark
> +struct
boot_info{This is what we call struct bootmodules on ARM right? Would it help if we used the same name?
I am not asking to make the ARM code common because I think that would probably be a lot more work.
This comment was wrong
Quoted 4 lines
It becomes clearer to see by the end of the full hyperlaunch v1 series with the domain builder implemented, but it is also evident by the end of this series: the core/common boot info for Xen is more than just a set of bootmodules. This first patch is part of adding functionality to common incrementally, as a starting point, and reducing this boot info to just a bootmodules structure is going to be limiting it in this context.
After having read the whole series, it is clear that you made such a fantastic progress toward unifying all the interfaces, both ARM and x86. You managed to introduce interfaces so similar to the existing ARM interfaces, that they are almost the same already. This is way better than I expected when I wrote that comment to the first patch.
I think we should go the extra mile and move the ARM interfaces to common, and make any changes needed by x86 there in common and reflecting the changes back to ARM.
This will also allow us to move more dom0less init code from ARM to common with fewer changes later on.
Re: [PATCH 03/10] x86 setup: change bootstrap map to accept new boot module structures
In reply to Jan BeulichQuoted 55 lines · Jan Beulich
Quoted 47 lines · Christopher Clark
Quoted 41 lines · Christopher Clark
Quoted 27 lines · Stefano Stabellini
Quoted 16 lines · Christopher Clark
To convert the x86 boot logic from multiboot to boot module structures, change the bootstrap map function to accept a boot module parameter.
To allow incremental change from multiboot to boot modules across all x86 setup logic, provide a temporary inline wrapper that still accepts a multiboot module parameter and use it where necessary. The wrapper is placed in a new
arch/x86header <asm/boot.h> to avoid putting a static inline function into an existing header that has no such functions already. This new header will be expanded with additional functions in subsequent patches in this series.No functional change intended.
Signed-off-by Christopher Clark <[email protected]>Signed-off-by Daniel P. Smith <[email protected]>[...]
Quoted 7 lines
xen/include/xen/bootinfo.h +0
-0@@ -10,6 +10,9 @@#endif Quoted 8 lines
xen/include/xen/bootinfo.h line 14
Quoted 3 lines
xen/include/xen/bootinfo.h +2
-0struct boot_module { +paddr_t start; +size_t size;I think size should be
paddr_t(instead ofsize_t) to make sure it is the right size on both 64-bit and 32-bit architectures that support 64-bit addresses.Quoted 2 lines
Thanks, that explanation does make sense - ack.
Quoted 6 lines
I've come back to reconsider this as it doesn't seem right to me to store a non-address value (which this will always be) in a type explicitly defined to hold an address: addresses may have architectural alignment requirements whereas a size value is just a number of bytes so will not. The point of a
size_tvalue is thatsize_tis defined to be large enough to hold the size of any valid object in memory, so I think this was right as-is.
Quoted 4 lines
"Any object in memory" implies virtual addresses (or more generally addresses which can be used for accessing objects). This isn't the case when considering physical addresses - there may be far more memory in a system than can be made accessible all in one go.
That is not my understanding of it, but I could be wrong. My understanding based on all the debates I have read online around this topic is that the intent in the spec is that size_t has to be able to hold a value that represents the largest object the CPU can manipulate with general purpose operations. From which I understand to mean as large as the largest register a CPU instruction may use for a size argument to a general purpose instruction. On x86_64, that is a 64bit register, as I don't believe the SSE/AVX registers are counted even though the are used by compiler/libc implementations to optimize some memory operations.
From what I have seen for Xen, this is currently reflected in the x86 code base, as size_t is 32bits for the early 32bit code and 64bits for Xen proper.
That aside, another objection I have to the use of paddr_t is that it is type abuse. Types are meant to convey context to the intended use of the variable and enable the ability to enforce proper usage of the variable, otherwise we might as well just use u64/uint64_t and be done. The field's purpose is to convey a size of an object, and labeling it a type that is intended for physical address objects violates both intents behind declaring a type, it asserts an invalid context and enables violations of type checking.
V/r,
Daniel P. Smith
Re: [PATCH 03/10] x86 setup: change bootstrap map to accept new boot module structures
In reply to Stefano StabelliniQuoted 56 lines · Stefano Stabellini
Quoted 55 lines · Jan Beulich
Quoted 53 lines · Christopher Clark
Quoted 41 lines · Christopher Clark
Quoted 27 lines · Stefano Stabellini
Quoted 16 lines · Christopher Clark
To convert the x86 boot logic from multiboot to boot module structures, change the bootstrap map function to accept a boot module parameter.
To allow incremental change from multiboot to boot modules across all x86 setup logic, provide a temporary inline wrapper that still accepts a multiboot module parameter and use it where necessary. The wrapper is placed in a new
arch/x86header <asm/boot.h> to avoid putting a static inline function into an existing header that has no such functions already. This new header will be expanded with additional functions in subsequent patches in this series.No functional change intended.
Signed-off-by Christopher Clark <[email protected]>Signed-off-by Daniel P. Smith <[email protected]>[...]
Quoted 7 lines
xen/include/xen/bootinfo.h +0
-0@@ -10,6 +10,9 @@#endif Quoted 8 lines
xen/include/xen/bootinfo.h line 14
Quoted 3 lines
xen/include/xen/bootinfo.h +2
-0struct boot_module { +paddr_t start; +size_t size;I think size should be
paddr_t(instead ofsize_t) to make sure it is the right size on both 64-bit and 32-bit architectures that support 64-bit addresses.Quoted 2 lines
Thanks, that explanation does make sense - ack.
I've come back to reconsider this as it doesn't seem right to me to store a non-address value (which this will always be) in a type explicitly defined to hold an address: addresses may have architectural alignment requirements whereas a size value is just a number of bytes so will not. The point of a
size_tvalue is thatsize_tis defined to be large enough to hold the size of any valid object in memory, so I think this was right as-is.
Quoted 7 lines
Quoted 4 lines
"Any object in memory" implies virtual addresses (or more generally addresses which can be used for accessing objects). This isn't the case when considering physical addresses - there may be far more memory in a system than can be made accessible all in one go.
Right. And I think
size_tis defined as 32-bit in Xen which is a problem.
In x86 32bit early boot code it is 32bits, but in Xen proper it is 64bits. That is why in the 32bit HL code, a second set of structures was used with macros to ensure the structures used 64bit values for field types that are not 64bits in 32bit mode code.
v/r,
dps
Re: [PATCH 03/10] x86 setup: change bootstrap map to accept new boot module structures
In reply to Daniel P. SmithQuoted 63 lines · Daniel P. Smith
Quoted 55 lines · Jan Beulich
Quoted 47 lines · Christopher Clark
Quoted 41 lines · Christopher Clark
Quoted 27 lines · Stefano Stabellini
Quoted 16 lines · Christopher Clark
To convert the x86 boot logic from multiboot to boot module structures, change the bootstrap map function to accept a boot module parameter.
To allow incremental change from multiboot to boot modules across all x86 setup logic, provide a temporary inline wrapper that still accepts a multiboot module parameter and use it where necessary. The wrapper is placed in a new
arch/x86header <asm/boot.h> to avoid putting a static inline function into an existing header that has no such functions already. This new header will be expanded with additional functions in subsequent patches in this series.No functional change intended.
Signed-off-by Christopher Clark <[email protected]>Signed-off-by Daniel P. Smith <[email protected]>[...]
Quoted 7 lines
xen/include/xen/bootinfo.h +0
-0@@ -10,6 +10,9 @@#endif Quoted 8 lines
xen/include/xen/bootinfo.h line 14
Quoted 3 lines
xen/include/xen/bootinfo.h +2
-0struct boot_module { +paddr_t start; +size_t size;I think size should be
paddr_t(instead ofsize_t) to make sure it is the right size on both 64-bit and 32-bit architectures that support 64-bit addresses.Quoted 2 lines
Thanks, that explanation does make sense - ack.
Quoted 6 lines
I've come back to reconsider this as it doesn't seem right to me to store a non-address value (which this will always be) in a type explicitly defined to hold an address: addresses may have architectural alignment requirements whereas a size value is just a number of bytes so will not. The point of a
size_tvalue is thatsize_tis defined to be large enough to hold the size of any valid object in memory, so I think this was right as-is.Quoted 4 lines
"Any object in memory" implies virtual addresses (or more generally addresses which can be used for accessing objects). This isn't the case when considering physical addresses - there may be far more memory in a system than can be made accessible all in one go.
Quoted 10 lines
That is not my understanding of it, but I could be wrong. My understanding based on all the debates I have read online around this topic is that the intent in the spec is that
size_thas to be able to hold a value that represents the largest object the CPU can manipulate with general purpose operations. From which I understand to mean as large as the largest register a CPU instruction may use for a size argument to a general purpose instruction. Onx86_64, that is a 64bit register, as I don't believe the SSE/AVX registers are counted even though the are used by compiler/libc implementations to optimize some memory operations.
I can't see how this relates to my earlier remark.
Quoted 9 lines
From what I have seen for Xen, this is currently reflected in the x86
code base, assize_tis 32bits for the early 32bit code and 64bits for Xen proper.That aside, another objection I have to the use of
paddr_tis that it is type abuse. Types are meant to convey context to the intended use of the variable and enable the ability to enforce proper usage of the variable, otherwise we might as well just use u64/uint64_t and be done. The field's purpose is to convey a size of an object,
You use "object" here again, when in physical address space (with paging enabled) this isn't an appropriate term.
Quoted 4 lines
and labeling it a type
that is intended for physical address objects violates both intents behind declaring a type, it asserts an invalid context and enables violations of type checking.
It is type abuse to a certain extent, yes, but what do you do? We could invent psize_t, but that would (afaics) always match paddr_t. uint64_t otoh may be too larger for 32-bit platforms which only know a 32-bit wide physical address space.
Jan
Re: [PATCH 03/10] x86 setup: change bootstrap map to accept new boot module structures
Quoted 75 lines · Jan Beulich
Quoted 63 lines · Daniel P. Smith
Quoted 55 lines · Jan Beulich
Quoted 47 lines · Christopher Clark
Quoted 41 lines · Christopher Clark
Quoted 27 lines · Stefano Stabellini
Quoted 16 lines · Christopher Clark
To convert the x86 boot logic from multiboot to boot module structures, change the bootstrap map function to accept a boot module parameter.
To allow incremental change from multiboot to boot modules across all x86 setup logic, provide a temporary inline wrapper that still accepts a multiboot module parameter and use it where necessary. The wrapper is placed in a new
arch/x86header <asm/boot.h> to avoid putting a static inline function into an existing header that has no such functions already. This new header will be expanded with additional functions in subsequent patches in this series.No functional change intended.
Signed-off-by Christopher Clark <[email protected]>Signed-off-by Daniel P. Smith <[email protected]>[...]
Quoted 7 lines
xen/include/xen/bootinfo.h +0
-0@@ -10,6 +10,9 @@#endif Quoted 8 lines
xen/include/xen/bootinfo.h line 14
Quoted 3 lines
xen/include/xen/bootinfo.h +2
-0struct boot_module { +paddr_t start; +size_t size;I think size should be
paddr_t(instead ofsize_t) to make sure it is the right size on both 64-bit and 32-bit architectures that support 64-bit addresses.Quoted 2 lines
Thanks, that explanation does make sense - ack.
Quoted 6 lines
I've come back to reconsider this as it doesn't seem right to me to store a non-address value (which this will always be) in a type explicitly defined to hold an address: addresses may have architectural alignment requirements whereas a size value is just a number of bytes so will not. The point of a
size_tvalue is thatsize_tis defined to be large enough to hold the size of any valid object in memory, so I think this was right as-is.Quoted 4 lines
"Any object in memory" implies virtual addresses (or more generally addresses which can be used for accessing objects). This isn't the case when considering physical addresses - there may be far more memory in a system than can be made accessible all in one go.
Quoted 10 lines
That is not my understanding of it, but I could be wrong. My understanding based on all the debates I have read online around this topic is that the intent in the spec is that
size_thas to be able to hold a value that represents the largest object the CPU can manipulate with general purpose operations. From which I understand to mean as large as the largest register a CPU instruction may use for a size argument to a general purpose instruction. Onx86_64, that is a 64bit register, as I don't believe the SSE/AVX registers are counted even though the are used by compiler/libc implementations to optimize some memory operations.
Quoted 1 line
I can't see how this relates to my earlier remark.
Perhaps I misunderstood what your point was then. I thought you were taking the position that size_t could not be used to represent the largest object in memory addressable by a single CPU operation.
Quoted 4 lines
Quoted 4 lines
From what I have seen for Xen, this is currently reflected in the x86
code base, assize_tis 32bits for the early 32bit code and 64bits for Xen proper.
Quoted 8 lines
Quoted 5 lines
That aside, another objection I have to the use of
paddr_tis that it is type abuse. Types are meant to convey context to the intended use of the variable and enable the ability to enforce proper usage of the variable, otherwise we might as well just use u64/uint64_t and be done. The field's purpose is to convey a size of an object,You use "object" here again, when in physical address space (with paging enabled) this isn't an appropriate term.
Because that is the language used in the C spec to refer to instances in memory,
"Object: region of data storage in the execution environment, the contents of which can represent values"
ISO/IEC 9899:1999(E) - 3.14: https://www.dii.uchile.cl/~daespino/files/Iso_C_1999_definition.pdf
With the following two interpretations of the spec for size_t to mean (any emphasis being mine),
"size_t is an unsigned integer type used to represent the size of any **object** (including arrays) in the particular implementation."
Wikipedia - size_t: https://en.wikipedia.org/wiki/C_data_types#stddef.h
"size_t can store the maximum size of a theoretically possible **object** of any type (including array)."
CPP Ref - size_t: (https://en.cppreference.com/w/c/types/size_t)
Quoted 9 lines
Quoted 4 lines
and labeling it a type
that is intended for physical address objects violates both intents behind declaring a type, it asserts an invalid context and enables violations of type checking.It is type abuse to a certain extent, yes, but what do you do? We could invent
psize_t, but that would (afaics) always matchpaddr_t.uint64_totoh may be too larger for 32-bit platforms which only know a 32-bit wide physical address space.
Why invent a new type? That is the purpose of size_t, and it should be of the correct size, otherwise Xen's implementation is incorrect (which it is not).
dps
Re: [PATCH 03/10] x86 setup: change bootstrap map to accept new boot module structures
Quoted 70 lines · Daniel P. Smith
Quoted 69 lines · Jan Beulich
Quoted 67 lines · Daniel P. Smith
Quoted 51 lines · Jan Beulich
Quoted 43 lines · Christopher Clark
Quoted 38 lines · Christopher Clark
Quoted 27 lines · Stefano Stabellini
Quoted 16 lines · Christopher Clark
To convert the x86 boot logic from multiboot to boot module structures, change the bootstrap map function to accept a boot module parameter.
To allow incremental change from multiboot to boot modules across all x86 setup logic, provide a temporary inline wrapper that still accepts a multiboot module parameter and use it where necessary. The wrapper is placed in a new
arch/x86header <asm/boot.h> to avoid putting a static inline function into an existing header that has no such functions already. This new header will be expanded with additional functions in subsequent patches in this series.No functional change intended.
Signed-off-by Christopher Clark <[email protected]>Signed-off-by Daniel P. Smith <[email protected]>[...]
Quoted 7 lines
xen/include/xen/bootinfo.h +0
-0@@ -10,6 +10,9 @@#endif Quoted 8 lines
xen/include/xen/bootinfo.h line 14
Quoted 3 lines
xen/include/xen/bootinfo.h +2
-0struct boot_module { +paddr_t start; +size_t size;I think size should be
paddr_t(instead ofsize_t) to make sure it is the right size on both 64-bit and 32-bit architectures that support 64-bit addresses.Quoted 2 lines
Thanks, that explanation does make sense - ack.
Quoted 6 lines
I've come back to reconsider this as it doesn't seem right to me to store a non-address value (which this will always be) in a type explicitly defined to hold an address: addresses may have architectural alignment requirements whereas a size value is just a number of bytes so will not. The point of a
size_tvalue is thatsize_tis defined to be large enough to hold the size of any valid object in memory, so I think this was right as-is.Quoted 4 lines
"Any object in memory" implies virtual addresses (or more generally addresses which can be used for accessing objects). This isn't the case when considering physical addresses - there may be far more memory in a system than can be made accessible all in one go.
That is not my understanding of it, but I could be wrong. My understanding based on all the debates I have read online around this topic is that the intent in the spec is that
size_thas to be able to hold a value that represents the largest object the CPU can manipulate with general purpose operations. From which I understand to mean as large as the largest register a CPU instruction may use for a size argument to a general purpose instruction. Onx86_64, that is a 64bit register, as I don't believe the SSE/AVX registers are counted even though the are used by compiler/libc implementations to optimize some memory operations.
Quoted 5 lines
Quoted 1 line
I can't see how this relates to my earlier remark.
Perhaps I misunderstood what your point was then. I thought you were taking the position that
size_tcould not be used to represent the largest object in memory addressable by a single CPU operation.
No. I was trying to clarify that we're talking about physical addresses here. Which you still seem to have trouble with, ...
Quoted 31 lines
Quoted 4 lines
Quoted 4 lines
From what I have seen for Xen, this is currently reflected in the x86
code base, assize_tis 32bits for the early 32bit code and 64bits for Xen proper.Quoted 8 lines
Quoted 5 lines
That aside, another objection I have to the use of
paddr_tis that it is type abuse. Types are meant to convey context to the intended use of the variable and enable the ability to enforce proper usage of the variable, otherwise we might as well just use u64/uint64_t and be done. The field's purpose is to convey a size of an object,You use "object" here again, when in physical address space (with paging enabled) this isn't an appropriate term.
Because that is the language used in the C spec to refer to instances in memory,
"Object: region of data storage in the execution environment, the contents of which can represent values"
ISO/IEC 9899:1999(E) - 3.14:
https://www.dii.uchile.cl/~daespino/files/Iso_C_1999_definition.pdfWith the following two interpretations of the spec for
size_tto mean (any emphasis being mine),"
size_tis an unsigned integer type used to represent the size of any **object** (including arrays) in the particular implementation."
Quoted 7 lines
Wikipedia -
size_t: https://en.wikipedia.org/wiki/C_data_types#stddef.h"
size_tcan store the maximum size of a theoretically possible **object** of any type (including array)."CPP Ref -
size_t: (https://en.cppreference.com/w/c/types/size_t)
... according to all of this and ...
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
and labeling it a type
that is intended for physical address objects violates both intents behind declaring a type, it asserts an invalid context and enables violations of type checking.
Quoted 8 lines
Quoted 4 lines
It is type abuse to a certain extent, yes, but what do you do? We could invent
psize_t, but that would (afaics) always matchpaddr_t.uint64_totoh may be too larger for 32-bit platforms which only know a 32-bit wide physical address space.Why invent a new type? That is the purpose of
size_t, and it should be of the correct size, otherwise Xen's implementation is incorrect (which it is not).
... this. What C talks about is what the CPU can address (within a single address space, i.e. normally virtual addresses). With 32-bit addresses you can address at most 4G, when the system you're running on may have much more memory. Yet in an OS or hypervisor you need to deal with this larger amount of memory, no matter that you can't address all of it in one go.
Jan
Re: [PATCH 03/10] x86 setup: change bootstrap map to accept new boot module structures
Quoted 71 lines · Jan Beulich
Quoted 70 lines · Daniel P. Smith
Quoted 69 lines · Jan Beulich
Quoted 67 lines · Daniel P. Smith
Quoted 51 lines · Jan Beulich
Quoted 43 lines · Christopher Clark
Quoted 38 lines · Christopher Clark
Quoted 27 lines · Stefano Stabellini
Quoted 16 lines · Christopher Clark
To convert the x86 boot logic from multiboot to boot module structures, change the bootstrap map function to accept a boot module parameter.
To allow incremental change from multiboot to boot modules across all x86 setup logic, provide a temporary inline wrapper that still accepts a multiboot module parameter and use it where necessary. The wrapper is placed in a new
arch/x86header <asm/boot.h> to avoid putting a static inline function into an existing header that has no such functions already. This new header will be expanded with additional functions in subsequent patches in this series.No functional change intended.
Signed-off-by Christopher Clark <[email protected]>Signed-off-by Daniel P. Smith <[email protected]>[...]
Quoted 7 lines
xen/include/xen/bootinfo.h +0
-0@@ -10,6 +10,9 @@#endif Quoted 8 lines
xen/include/xen/bootinfo.h line 14
Quoted 3 lines
xen/include/xen/bootinfo.h +2
-0struct boot_module { +paddr_t start; +size_t size;I think size should be
paddr_t(instead ofsize_t) to make sure it is the right size on both 64-bit and 32-bit architectures that support 64-bit addresses.Quoted 2 lines
Thanks, that explanation does make sense - ack.
Quoted 6 lines
I've come back to reconsider this as it doesn't seem right to me to store a non-address value (which this will always be) in a type explicitly defined to hold an address: addresses may have architectural alignment requirements whereas a size value is just a number of bytes so will not. The point of a
size_tvalue is thatsize_tis defined to be large enough to hold the size of any valid object in memory, so I think this was right as-is.Quoted 4 lines
"Any object in memory" implies virtual addresses (or more generally addresses which can be used for accessing objects). This isn't the case when considering physical addresses - there may be far more memory in a system than can be made accessible all in one go.
That is not my understanding of it, but I could be wrong. My understanding based on all the debates I have read online around this topic is that the intent in the spec is that
size_thas to be able to hold a value that represents the largest object the CPU can manipulate with general purpose operations. From which I understand to mean as large as the largest register a CPU instruction may use for a size argument to a general purpose instruction. Onx86_64, that is a 64bit register, as I don't believe the SSE/AVX registers are counted even though the are used by compiler/libc implementations to optimize some memory operations.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
I can't see how this relates to my earlier remark.
Perhaps I misunderstood what your point was then. I thought you were taking the position that
size_tcould not be used to represent the largest object in memory addressable by a single CPU operation.No. I was trying to clarify that we're talking about physical addresses here. Which you still seem to have trouble with, ...
No, I perfectly understand what you are saying and am not having difficulties with.
Quoted 55 lines
Quoted 31 lines
Quoted 4 lines
Quoted 4 lines
From what I have seen for Xen, this is currently reflected in the x86
code base, assize_tis 32bits for the early 32bit code and 64bits for Xen proper.Quoted 8 lines
Quoted 5 lines
That aside, another objection I have to the use of
paddr_tis that it is type abuse. Types are meant to convey context to the intended use of the variable and enable the ability to enforce proper usage of the variable, otherwise we might as well just use u64/uint64_t and be done. The field's purpose is to convey a size of an object,You use "object" here again, when in physical address space (with paging enabled) this isn't an appropriate term.
Because that is the language used in the C spec to refer to instances in memory,
"Object: region of data storage in the execution environment, the contents of which can represent values"
ISO/IEC 9899:1999(E) - 3.14:
https://www.dii.uchile.cl/~daespino/files/Iso_C_1999_definition.pdfWith the following two interpretations of the spec for
size_tto mean (any emphasis being mine),"
size_tis an unsigned integer type used to represent the size of any **object** (including arrays) in the particular implementation."Quoted 7 lines
Wikipedia -
size_t: https://en.wikipedia.org/wiki/C_data_types#stddef.h"
size_tcan store the maximum size of a theoretically possible **object** of any type (including array)."CPP Ref -
size_t: (https://en.cppreference.com/w/c/types/size_t)... according to all of this and ...
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
and labeling it a type
that is intended for physical address objects violates both intents behind declaring a type, it asserts an invalid context and enables violations of type checking.Quoted 8 lines
Quoted 4 lines
It is type abuse to a certain extent, yes, but what do you do? We could invent
psize_t, but that would (afaics) always matchpaddr_t.uint64_totoh may be too larger for 32-bit platforms which only know a 32-bit wide physical address space.Why invent a new type? That is the purpose of
size_t, and it should be of the correct size, otherwise Xen's implementation is incorrect (which it is not).
Quoted 6 lines
... this. What C talks about is what the CPU can address (within a single address space, i.e. normally virtual addresses). With 32-bit addresses you can address at most 4G, when the system you're running on may have much more memory. Yet in an OS or hypervisor you need to deal with this larger amount of memory, no matter that you can't address all of it in one go.
Nothing I said disagrees with your statement.
Let's bring this back to the actual implementation instead of the theoretical. Your position is that Xen's paddr_t is desired because it can store larger values than that of size_t. Now if you look in Xen proper (main 64bit code on x86), paddr_t is a typedef for a 64bit unsigned integer. And if you look at size_t, it is also a typedef to a 64bit unsigned integer, they are literally a couple of lines apart in types.h. Thus they are the same size and can only represent the same maximum size. The only area of issue for x86 is during the short bit of code that runs in 32bit mode during startup. In this series, we address this by using a set of macros in the 32bit code to provide 64bit clean definition of the structures. This approach is acceptable because as far as I am aware, x86 is the only platform where the hypervisor has to transition from one bit size to another, e.g. Arm just starts in 64bit mode when on a 64bit device.
At the end of the day, size_t is the same size as paddr_t for the end execution environments and I would levy a guess that should x86 suddenly find itself having a 128bit mode which would likely drive paddr_t to 128bits, so would follow size_t.
v/r,
dps
Re: [PATCH 03/10] x86 setup: change bootstrap map to accept new boot module structures
Quoted 8 lines · Daniel P. Smith
Let's bring this back to the actual implementation instead of the theoretical. Your position is that Xen's
paddr_tis desired because it can store larger values than that ofsize_t. Now if you look in Xen proper (main 64bit code on x86),paddr_tis a typedef for a 64bit unsigned integer. And if you look atsize_t, it is also a typedef to a 64bit unsigned integer, they are literally a couple of lines apart intypes.h. Thus they are the same size and can only represent the same maximum size.
What about 32-bit Arm, or any other 32-bit architecture that we might see Xen ported to, with wider than 32-bit physical address space?
Quoted 8 lines
The only area of issue for x86 is during the short bit of code that runs in 32bit mode during startup. In this series, we address this by using a set of macros in the 32bit code to provide 64bit clean definition of the structures. This approach is acceptable because as far as I am aware, x86 is the only platform where the hypervisor has to transition from one bit size to another, e.g. Arm just starts in 64bit mode when on a 64bit device.
Quoted 4 lines
At the end of the day,
size_tis the same size aspaddr_tfor the end execution environments and I would levy a guess that should x86 suddenly find itself having a 128bit mode which would likely drivepaddr_tto 128bits, so would followsize_t.
Likely. Yet when we still had ix86 (x86-32) support, paddr_t also wasn't the same as size_t. Even on x86-64 it's possible we'd see physical address width go beyond 64 bits before virtual address width would, just like had happened for ix86 (which initially only allowed for 32-bit physical addresses, until PSE36 arrived).
In your implementation you want to cover the general case, not a subset of special ones.
Jan
Re: [PATCH 03/10] x86 setup: change bootstrap map to accept new boot module structures
Quoted 10 lines · Jan Beulich
Quoted 8 lines · Daniel P. Smith
Let's bring this back to the actual implementation instead of the theoretical. Your position is that Xen's
paddr_tis desired because it can store larger values than that ofsize_t. Now if you look in Xen proper (main 64bit code on x86),paddr_tis a typedef for a 64bit unsigned integer. And if you look atsize_t, it is also a typedef to a 64bit unsigned integer, they are literally a couple of lines apart intypes.h. Thus they are the same size and can only represent the same maximum size.
Quoted 3 lines
What about 32-bit Arm, or any other 32-bit architecture that we might see Xen ported to, with wider than 32-bit physical address space?
To be more concrete here:
Suppose that you had a machine with 32-bit virtual address spaces (i.e., going up to 4GiB), and 36-bit physical address spaces (i.e., going up to 64GiB). And suppose you had a system with 16GiB of physical ram. And you wanted to use Hyperlaunch to create VMs using some sort of memory image that was 5GiB (presumably of some kind of static data, not, say, a kernel or initramfs). You wouldn't be able to do it if the "size" parameter of the boot modules was limited to 4GiB (without some kind of hack where you string multiple boot modules together).
I guess part of the question is whether we think that's an important use case; on the whole if you're populating 5GiB of RAM, it seems like it would be better to have the VM load it itself from disk.
I do see the logic behind wanting to avoid "paddr_t" for a size; I'm sure Jan that you would nack any patch that used "size_t" as a memory address (instead of, say, uintptr_t). In that case, "psize_t" is the obvious solution.
-George
Re: [PATCH 03/10] x86 setup: change bootstrap map to accept new boot module structures
Quoted 15 lines · George Dunlap
On Thu, Jul 27, 2023 at 3:42 PM Jan Beulich <[email protected]> wrote:
On 27.07.2023 15:26, Daniel P. Smith wrote:
> Let's bring this back to the actual implementation instead of the > theoretical. Your position is that Xen'spaddr_tis desired because it > can store larger values than that ofsize_t. Now if you look in Xen > proper (main 64bit code on x86),paddr_tis a typedef for a 64bit > unsigned integer. And if you look atsize_t, it is also a typedef to a > 64bit unsigned integer, they are literally a couple of lines apart in >types.h. Thus they are the same size and can only represent the same > maximum size.What about 32-bit Arm, or any other 32-bit architecture that we might see Xen ported to, with wider than 32-bit physical address space?
Quoted 6 lines
To be more concrete here:
Suppose that you had a machine with 32-bit virtual address spaces (i.e., going up to 4GiB), and 36-bit physical address spaces (i.e., going up to 64GiB). And suppose you had a system with 16GiB of physical ram. And you wanted to use Hyperlaunch to create VMs using some sort of memory image that was 5GiB (presumably of some kind of static data, not, say, a kernel or initramfs). You wouldn't be able to do it if the "size" parameter of the boot modules was limited to 4GiB (without some kind of hack where you string multiple boot modules together).
Yes exactly.
I would like this code to be common across ARM and x86. On arm32 size_t wouldn't work, with size_t as it is defined today. One option is to use paddr_t on all arches, or at least on arm32. Another option is to change the definition of size_t on arm32.
My suggestion it to move the existing equivalent dom0less interface defined here:
xen/arch/arm/include/asm/setup.c:struct bootmodule
to common code and base this work on top of it. struct bootmodule uses paddr_t for both start and size to solve the arm32 issue today.
Re: [PATCH 03/10] x86 setup: change bootstrap map to accept new boot module structures
In reply to George DunlapQuoted 17 lines · George Dunlap
On Thu, Jul 27, 2023 at 3:42 PM Jan Beulich <[email protected] <mailto:[email protected]>> wrote:
On 27.07.2023 15:26, Daniel P. Smith wrote:
> Let's bring this back to the actual implementation instead of the > theoretical. Your position is that Xen'spaddr_tis desired
because it
> can store larger values than that ofsize_t. Now if you look in Xen > proper (main 64bit code on x86),paddr_tis a typedef for a 64bit > unsigned integer. And if you look atsize_t, it is also a typedef
to a
> 64bit unsigned integer, they are literally a couple of lines
apart in
>types.h. Thus they are the same size and can only represent the same > maximum size.
Quoted 7 lines
What about 32-bit Arm, or any other 32-bit architecture that we might see Xen ported to, with wider than 32-bit physical address space?
To be more concrete here:
Suppose that you had a machine with 32-bit virtual address spaces (i.e., going up to 4GiB), and 36-bit physical address spaces (i.e., going up to 64GiB). And suppose you had a system with 16GiB of physical ram. And you wanted to use Hyperlaunch to create VMs using some sort of memory image that was 5GiB (presumably of some kind of static data, not, say, a kernel or initramfs). You wouldn't be able to do it if the "size" parameter of the boot modules was limited to 4GiB (without some kind of hack where you string multiple boot modules together).
The reality to your scenario here is that it would never work on x86. Regardless of which entry point you come in through, 32bit BIOS entry, UEFI, or PVH, all of these expect the boot material to be passed in using the MB1 or MB2 protocol. Under those protocols, a module definition has a start and end addresses which are u32. While the start address could be okay, the end address will be well beyond 4GiB which at best would overflow the address, but more likely be rejected by the bootloader.
Quoted 1 line
I guess part of the question is whether we think that's an important use case; on the whole if you're populating 5GiB of RAM, it seems like it would be better to have the VM load it itself from disk.
The point of hyperlaunch is to enable advanced use-cases and domain resume on boot is one I think someone might find useful.
Quoted 1 line
I do see the logic behind wanting to avoid "
paddr_t" for a size; I'm sure Jan that you would nack any patch that used "size_t" as a memory address (instead of, say, uintptr_t). In that case, "psize_t" is the obvious solution.
I would be amenable with declaring a psize_t that lived in all the same places paddr_t are defined to signal them as a pair, of sorts. I would have to see if adding paddr_t and this new psize_t addresses to the 32bit defs.h would result in making the structures 64bit clean in the x86 32bit code. If so, then it would remove the need for a separate declaration of the structures there.
v/r,
dps
Re: [PATCH 03/10] x86 setup: change bootstrap map to accept new boot module structures
In reply to Stefano StabelliniQuoted 23 lines · Stefano Stabellini
Quoted 15 lines · George Dunlap
On Thu, Jul 27, 2023 at 3:42 PM Jan Beulich <[email protected]> wrote:
On 27.07.2023 15:26, Daniel P. Smith wrote:
> Let's bring this back to the actual implementation instead of the > theoretical. Your position is that Xen'spaddr_tis desired because it > can store larger values than that ofsize_t. Now if you look in Xen > proper (main 64bit code on x86),paddr_tis a typedef for a 64bit > unsigned integer. And if you look atsize_t, it is also a typedef to a > 64bit unsigned integer, they are literally a couple of lines apart in >types.h. Thus they are the same size and can only represent the same > maximum size.What about 32-bit Arm, or any other 32-bit architecture that we might see Xen ported to, with wider than 32-bit physical address space?
Quoted 6 lines
To be more concrete here:
Suppose that you had a machine with 32-bit virtual address spaces (i.e., going up to 4GiB), and 36-bit physical address spaces (i.e., going up to 64GiB). And suppose you had a system with 16GiB of physical ram. And you wanted to use Hyperlaunch to create VMs using some sort of memory image that was 5GiB (presumably of some kind of static data, not, say, a kernel or initramfs). You wouldn't be able to do it if the "size" parameter of the boot modules was limited to 4GiB (without some kind of hack where you string multiple boot modules together).
Quoted 6 lines
Yes exactly.
I would like this code to be common across ARM and x86. On arm32
size_twouldn't work, withsize_tas it is defined today. One option is to usepaddr_ton all arches, or at least on arm32. Another option is to change the definition ofsize_ton arm32.
How can changing size_t be an option? This is determined by the psABI, and going out of sync with what the compiler assumes size_t is will bring you all sorts of trouble.
Jan
Re: [PATCH 01/10] x86 setup: move x86 boot module counting into a new boot_info struct
In reply to Christopher ClarkQuoted 4 lines · Christopher Clark
xen/arch/x86/setup.c +0
-0@@ -1127,18 +1139,18 @@ void __init noreturn __start_xen(unsigned long mbi_p) bootsym(boot_edd_info_nr));/* Check that we have at least one Multiboot module. */
xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long mbi_p) · line 1148
Quoted 10 lines
xen/arch/x86/setup.c +3
-3-if ( !(mbi->flags &MBI_MODULES ) || (mbi->mods_count ==0 ) ) +if ( !(mbi->flags &MBI_MODULES ) || (boot_info->nr_mods ==0 ) )panic ("dom0 kernel not specified. Check bootloader configuration\n" );/* Check that we don't have a silly number of modules. */ -if ( mbi->mods_count >sizeof (module_map) *8 ) +if ( boot_info->nr_mods >sizeof (module_map) *8 ) { - mbi->mods_count =sizeof (module_map) *8 ; + boot_info->nr_mods =sizeof (module_map) *8 ;
As long as you don't replace all consumers of mbi->mods_count (see in particular the call trees down from early_microcode_init() and down from xsm_multiboot_init()), I don't think you can drop the original assignment.
Quoted 11 lines
xen/arch/x86/setup.c +2
-2printk ("Excessive multiboot modules - using the first %u only\n" , - mbi->mods_count); + boot_info->nr_mods); } -bitmap_fill (module_map, mbi->mods_count); +bitmap_fill (module_map, boot_info->nr_mods);__clear_bit (0 , module_map);/* Dom0 kernel is always first */ if ( pvh_boot )
xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long mbi_p) · line 1326
Quoted 5 lines
xen/arch/x86/setup.c +1
-1@@ -1311,9 +1323,9 @@ void __init noreturn __start_xen(unsigned long mbi_p)kexec_reserve_area (&boot_e820); initial_images = mod; - nr_initial_images = mbi->mods_count; + boot_info->nr_mods = boot_info->nr_mods;
Overly mechanical change? To prevent such going unnoticed, maybe boot_info should be pointer-to-const? Would of course require the bounding to occur earlier, so you truly don't need to write the struct after filling it in multiboot_to_bootinfo(). Or you move the call to that function down a little. Yet other options also exist.
xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long mbi_p) · line 1328
Quoted 2 lines
xen/arch/x86/setup.c +1
-1-for ( i =0 ; !efi_enabled (EFI_LOADER ) && i < mbi->mods_count; i++ ) +for ( i =0 ; !efi_enabled (EFI_LOADER ) && i < boot_info->nr_mods; i++ )
Seeing all sorts of changes of this kind - did you consider naming the pointer variable (which will become a function parameter as to what I understood from your reply to Stefano) just "bi"? (I wouldn't suggest this if the variable was to remain file-scope.)
Jan
Re: [PATCH 02/10] x86 setup: per-arch bootmodule structure, headroom field
In reply to Christopher ClarkQuoted 17 lines · Christopher Clark
xen/arch/x86/bzimage.c +4
-1@@ -105,11 +102,14 @@ unsigned long __init bzimage_headroom(void *image_start, }int __init bzimage_parse (void *image_base,void **image_start, +unsigned int headroom,unsigned long *image_len) {struct setup_header *hdr = (struct setup_header *)(*image_start);int err =bzimage_check (hdr, *image_len); -unsigned long output_len; +unsigned long output_len, orig_image_len; + + orig_image_len = *image_len - headroom;if ( err <0 )return err;
xen/arch/x86/bzimage.c int __init bzimage_parse(void *image_base, void **image_start, · line 128
Quoted 5 lines
xen/arch/x86/bzimage.c +1
-1@@ -125,7 +125,7 @@ int __init bzimage_parse(void *image_base, void **image_start,BUG_ON (!(image_base < *image_start)); - output_len =output_length (*image_start, orig_image_len); + output_len =output_length (*image_start, *image_len);
If this is correct, then I would imply that so far we passed too large a value (a too small one pretty certainly wouldn't have worked). But I wonder whether you aren't passing too large a value now. In any event ideally such a functional change would be split out; otherwise it very clearly needs mentioning (justifying) in the description.
xen/arch/x86/include/asm/bootinfo.h line 6
Quoted 9 lines
xen/arch/x86/include/asm/bootinfo.h new file +6
-0@@ -0,0 +1,18 @@ +#ifndef __ARCH_X86_BOOTINFO_H__ +#define __ARCH_X86_BOOTINFO_H__ + +struct arch_bootmodule { +unsigned headroom; +};
But this isn't a per-module property, is it?
xen/arch/x86/include/asm/bootinfo.h static struct domain *__init create_dom0(const module_t *image, · line 972
Quoted 8 lines
xen/arch/x86/include/asm/bootinfo.h new file +2
-1@@ -961,7 +967,8 @@ static struct domain *__init create_dom0(const module_t *image,write_cr4 (read_cr4 () & ~X86_CR4_SMAP ); } -if (construct_dom0 (d, image, headroom, initrd, cmdline) !=0 ) +if (construct_dom0 (d, image, boot_info->mods[0 ].arch->headroom, initrd, + cmdline) !=0 )panic ("Could not construct domain 0\n" );
This looks to render the function's "headroom" parameter unused.
xen/include/xen/bootinfo.h line 10
Quoted 11 lines
xen/include/xen/bootinfo.h +5
-0@@ -3,8 +3,19 @@#include <xen/types.h> +#ifdef CONFIG_X86 +#include <asm/bootinfo.h> +#else +struct arch_bootmodule { }; +#endif
This wants making use of include/asm-generic/ now, provided the non-x86 header are going to remain empty. Otherwise arch headers will want introducing right away; there shouldn't be a CONFIG_X86 use here.
xen/include/xen/bootinfo.h line 14
Quoted 3 lines
xen/include/xen/bootinfo.h +3
-0+struct boot_module { +struct arch_bootmodule *arch; +};
Why a pointer? By the names it's a 1:1 relationship, so ...
xen/include/xen/bootinfo.h line 18
Quoted 3 lines
xen/include/xen/bootinfo.h +1
-0struct boot_info {unsigned int nr_mods; +struct boot_module *mods;
... only the pointer here is what takes care of there being multiple instances (likely as before represented as an array).
Jan
Re: [PATCH 03/10] x86 setup: change bootstrap map to accept new boot module structures
In reply to Christopher ClarkQuoted 6 lines · Christopher Clark
To convert the x86 boot logic from multiboot to boot module structures, change the bootstrap map function to accept a boot module parameter.
To allow incremental change from multiboot to boot modules across all x86 setup logic, provide a temporary inline wrapper that still accepts a multiboot module parameter and use it where necessary.
And all uses of the original function are converted to the new wrapper, except when passing NULL - am I getting this right? Plus down the road you'll change all of them back? Too much code churn for my taste, to be honest, not the least because this undermines easy use of "git blame".
If the above observation is right, and since passing NULL to the wrapper is fine too, why don't you deal with this by using a macro wrapper instead, without needing to touch all the call sites:
#define bootstrap_map(m) bootstrap_map_multiboot(m)
Misra won't like that, but as you say it's temporary.
Jan
Re: [PATCH 06/10] x86 setup, microcode: switch to the new bootinfo structures
In reply to Christopher ClarkQuoted 6 lines · Christopher Clark
Next step in incremental work towards adding a non-multiboot internal representation of boot modules, converting the fields being accessed for the startup calculations.
Move the per-module scan logic into a dedicated function from the iteration loop and set the
BOOTMOD_UCODEmodule type when microcode is found.
It's not really clear to me why the split (and the associated code churn) is needed.
Quoted 7 lines
xen/arch/x86/cpu/microcode/core.c +0
-3@@ -150,75 +149,109 @@ static int __init cf_check parse_ucode(const char *s) }custom_param ("ucode" , parse_ucode); -void __init microcode_scan_module ( -unsigned long *module_map, -const multiboot_info_t *mbi)
xen/arch/x86/cpu/microcode/core.c static int __init cf_check parse_ucode(const char *s) · line 159
Quoted 10 lines
xen/arch/x86/cpu/microcode/core.c +5
-2+#define MICROCODE_MODULE_MATCH 1 +#define MICROCODE_MODULE_NONMATCH 0 + +static int __init microcode_check_module (struct boot_module *mod) { -module_t *mod = (module_t *)__va (mbi->mods_addr);uint64_t *_blob_start;unsigned long _blob_size; -struct cpio_data cd; +struct cpio_data cd = {NULL ,0 };
Why? You don't ...
Quoted 16 lines
xen/arch/x86/cpu/microcode/core.c +3
-5long offset;const char *p =NULL ; -int i; - - ucode_blob.size =0 ; -if ( !ucode_scan ) -return ;if ( boot_cpu_data.x86_vendor ==X86_VENDOR_AMD ) p ="kernel/x86/microcode/AuthenticAMD.bin" ;else if ( boot_cpu_data.x86_vendor ==X86_VENDOR_INTEL ) p ="kernel/x86/microcode/GenuineIntel.bin" ;else +return -EFAULT ; + + _blob_start =bootstrap_map (mod);
xen/arch/x86/cpu/microcode/core.c static int __init cf_check parse_ucode(const char *s) · line 180
Quoted 10 lines
xen/arch/x86/cpu/microcode/core.c +10
-0+ _blob_size = mod->size; +if ( !_blob_start ) + { +printk ("Could not map multiboot module (0x%lx) (size: %ld)\n" , + mod->start, _blob_size); +/* Non-fatal error, so just say no match */ +return MICROCODE_MODULE_NONMATCH ; + } + + cd =find_cpio_data (p, _blob_start, _blob_size, &offset/* ignore */ );
... use the variable ahead of this assignment.
Quoted 7 lines
xen/arch/x86/cpu/microcode/core.c +7
-0+if ( cd.data ) + { + ucode_blob.size = cd.size; + ucode_blob.data = cd.data; + + mod->bootmod_type =BOOTMOD_UCODE ; +return MICROCODE_MODULE_MATCH ;
xen/arch/x86/cpu/microcode/core.c static int __init cf_check parse_ucode(const char *s) · line 198
Quoted 10 lines
xen/arch/x86/cpu/microcode/core.c +10
-0+ } + +bootstrap_map (NULL ); + +return MICROCODE_MODULE_NONMATCH ; +} + +void __init microcode_scan_module (struct boot_info *bootinfo) +{ +int i;
No plain int please for variables holding only non-negative values.
xen/arch/x86/cpu/microcode/core.c static int __init cf_check parse_ucode(const char *s) · line 204
Quoted 9 lines
xen/arch/x86/cpu/microcode/core.c +3
-4+if ( !ucode_scan )return ; -/* -* Try all modules and see whichever could be the microcode blob. -*/ -for ( i =1 /* Ignore dom0 kernel */ ; i < mbi->mods_count; i++ ) + i =bootmodule_index (bootinfo,BOOTMOD_UNKNOWN ,0 ); +while ( i < bootinfo->nr_mods )
Why is the comment going away?
Quoted 67 lines
xen/arch/x86/cpu/microcode/core.c +29
-27{ -if ( !test_bit (i, module_map) ) -continue ; +int ret =microcode_check_module (&bootinfo->mods[i]); - _blob_start =bootstrap_map_multiboot (&mod[i]); - _blob_size = mod[i].mod_end; -if ( !_blob_start ) +switch ( ret ) { -printk ("Could not map multiboot module #%d (size: %ld)\n" , - i, _blob_size); +case MICROCODE_MODULE_MATCH : +return ; +case MICROCODE_MODULE_NONMATCH : + i =bootmodule_index (bootinfo,BOOTMOD_UNKNOWN , ++i);continue ; +default : +printk ("%s: (err: %d) unable to check microcode\n" , + __func__, ret); +return ; } - cd.data =NULL ; - cd.size =0 ; - cd =find_cpio_data (p, _blob_start, _blob_size, &offset/* ignore */ ); -if ( cd.data ) - { - ucode_blob.size = cd.size; - ucode_blob.data = cd.data; -break ; - } -bootstrap_map (NULL ); } } -static void __init microcode_grab_module ( -unsigned long *module_map, -const multiboot_info_t *mbi) +static void __init microcode_grab_module (struct boot_info *bootinfo) { -module_t *mod = (module_t *)__va (mbi->mods_addr); + ucode_blob.size =0 ;if ( ucode_mod_idx <0 ) - ucode_mod_idx += mbi->mods_count; -if ( ucode_mod_idx <=0 || ucode_mod_idx >= mbi->mods_count || - !__test_and_clear_bit (ucode_mod_idx, module_map) ) - goto scan; - ucode_mod = mod[ucode_mod_idx]; -scan: + ucode_mod_idx += bootinfo->nr_mods; +if ( ucode_mod_idx >=0 && ucode_mod_idx <= bootinfo->nr_mods && + bootinfo->mods[ucode_mod_idx].bootmod_type ==BOOTMOD_UNKNOWN ) + { +int ret =microcode_check_module (&bootinfo->mods[ucode_mod_idx]); + +switch ( ret ) + { +case MICROCODE_MODULE_MATCH : +return ; +case MICROCODE_MODULE_NONMATCH : +break ; +default : +printk ("%s: (err: %d) unable to check microcode\n" , + __func__, ret); +return ; + }
xen/arch/x86/cpu/microcode/core.c static int __init cf_check parse_ucode(const char *s) · line 253
Quoted 10 lines
xen/arch/x86/cpu/microcode/core.c +6
-1+ } +if ( ucode_scan ) -microcode_scan_module (module_map, mbi); +microcode_scan_module (bootinfo); } +/* Undefining as they are not needed anymore */ +#undef MICROCODE_MODULE_MATCH +#undef MICROCODE_MODULE_NONMATCH
No need to comment this; we do so elsewhere as well.
xen/arch/x86/cpu/microcode/core.c static int __init cf_check microcode_init(void) · line 745
Quoted 9 lines
xen/arch/x86/cpu/microcode/core.c +0
-5@@ -738,11 +771,6 @@ static int __init cf_check microcode_init(void) ucode_blob.size =0 ; ucode_blob.data =NULL ; } -else if ( ucode_mod.mod_end ) - { -bootstrap_map (NULL ); - ucode_mod.mod_end =0 ; - }
I can spot why this and ...
Quoted 26 lines
xen/arch/x86/cpu/microcode/core.c +3
-7@@ -786,8 +814,7 @@ static int __init early_update_cache(const void *data, size_t len)return rc; } -int __init microcode_init_cache (unsigned long *module_map, -const struct multiboot_info *mbi) +int __init microcode_init_cache (struct boot_info *bootinfo) {int rc =0 ;@@ -796,12 +823,9 @@ int __init microcode_init_cache(unsigned long *module_map,if ( ucode_scan )/* Need to rescan the modules because they might have been relocated */ -microcode_scan_module (module_map, mbi); +microcode_scan_module (bootinfo); -if ( ucode_mod.mod_end ) - rc =early_update_cache (bootstrap_map_multiboot (&ucode_mod), - ucode_mod.mod_end); -else if ( ucode_blob.size ) +if ( ucode_blob.size ) rc =early_update_cache (ucode_blob.data, ucode_blob.size);return rc;
xen/arch/x86/cpu/microcode/core.c static int __init early_microcode_update_cpu(void) · line 826
Quoted 8 lines
xen/arch/x86/cpu/microcode/core.c +0
-5@@ -819,11 +843,6 @@ static int __init early_microcode_update_cpu(void) len = ucode_blob.size; data = ucode_blob.data; } -else if ( ucode_mod.mod_end ) - { - len = ucode_mod.mod_end; - data =bootstrap_map_multiboot (&ucode_mod); - }
... this isn't needed anymore. The code doesn't appear to move elsewhere.
Jan
Re: [PATCH 04/10] x86 setup: porting dom0 construction logic to boot module structures
In reply to Christopher Clarkxen/arch/x86/include/asm/boot.h static inline void *bootstrap_map_multiboot(const module_t *mod) · line 24
Quoted 9 lines · Christopher Clark
xen/arch/x86/include/asm/boot.h +3
-0@@ -19,6 +19,42 @@ static inline void *bootstrap_map_multiboot(const module_t *mod)return bootstrap_map (&bm); } +static inline unsigned long bootmodule_index ( +const struct boot_info *info,bootmod_type_t bootmod_type, +unsigned long start)
unsigned int?
xen/arch/x86/include/asm/boot.h static inline void *bootstrap_map_multiboot(const module_t *mod) · line 36
Quoted 12 lines
xen/arch/x86/include/asm/boot.h +12
-0+{ +for ( ; start < info->nr_mods; start++ ) +if ( info->mods[start].bootmod_type == bootmod_type ) +return start; + +return info->nr_mods +1 ; +} + +static inline struct boot_module *bootmodule_next ( +const struct boot_info *info,bootmod_type_t bootmod_type) +{ +unsigned long i;
Again.
xen/arch/x86/include/asm/boot.h static inline void *bootstrap_map_multiboot(const module_t *mod) · line 43
Quoted 6 lines
xen/arch/x86/include/asm/boot.h +6
-0+for ( i =0 ; i < info->nr_mods; i++ ) +if ( info->mods[i].bootmod_type == bootmod_type ) +return &info->mods[i]; + +return NULL ; +}
What is "next" meant to express here? You always return the first module of the requested type.
xen/arch/x86/include/asm/boot.h static inline void *bootstrap_map_multiboot(const module_t *mod) · line 56
Quoted 12 lines
xen/arch/x86/include/asm/boot.h +12
-0+static inline void bootmodule_update_start (struct boot_module *bm, +paddr_t new_start) +{ + bm->start = new_start; + bm->mfn =maddr_to_mfn (new_start); +} + +static inline void bootmodule_update_mfn (struct boot_module *bm,mfn_t new_mfn) +{ + bm->mfn = new_mfn; + bm->start =mfn_to_maddr (new_mfn); +}
Why two functions setting the same data and overriding each other?
Quoted 7 lines
xen/arch/x86/include/asm/bootinfo.h +1
-0@@ -2,9 +2,33 @@#define __ARCH_X86_BOOTINFO_H__struct arch_bootmodule { +#define BOOTMOD_FLAG_X86_RELOCATED 1U << 0
xen/arch/x86/include/asm/bootinfo.h line 15
Quoted 10 lines
xen/arch/x86/include/asm/bootinfo.h +7
-0+uint32_t flags;unsigned headroom; }; +struct arch_boot_info { +uint32_t flags; +#define BOOTINFO_FLAG_X86_CMDLINE 1U << 2 +#define BOOTINFO_FLAG_X86_MODULES 1U << 3 +#define BOOTINFO_FLAG_X86_MEMMAP 1U << 6 +#define BOOTINFO_FLAG_X86_LOADERNAME 1U << 9
In how far are all of these x86-specific? And are they needed at all? Can't you internally use respective fields being NULL as good enough indicator (looking at e.g. the places where LOADERNAME and CMDLINE are inspected).
Also the values are all missing parentheses.
xen/arch/x86/include/asm/bootinfo.h line 17
Quoted 1 line
xen/arch/x86/include/asm/bootinfo.h +1
-0+char *boot_loader_name;
const char * ?
xen/arch/x86/include/asm/bootinfo.h line 30
Quoted 12 lines
xen/arch/x86/include/asm/bootinfo.h +12
-0+uint32_t mmap_length; +paddr_t mmap_addr; +}; + +struct __packed mb_memmap { +uint32_t size; +uint32_t base_addr_low; +uint32_t base_addr_high; +uint32_t length_low; +uint32_t length_high; +uint32_t type; +};
This looks to duplicate an existing structure, without removing the original, and without annotating both places to mention that they need to remain in sync. Question of course is why you need a 2nd struct definition in the first place.
Quoted 16 lines
xen/arch/x86/include/asm/bootinfo.h +4
-4@@ -269,20 +273,44 @@ static int __init cf_check parse_acpi_param(const char *s) }custom_param ("acpi" , parse_acpi_param); -static const module_t *__initdata initial_images;static struct boot_info __initdata *boot_info; -static void __init multiboot_to_bootinfo (multiboot_info_t *mbi) +static void __init multiboot_to_bootinfo (multiboot_info_t *mbi,module_t *mods) {static struct boot_info __initdata info; -static struct boot_module __initdata boot_mods[1 ]; -static struct arch_bootmodule __initdata arch_boot_mods[1 ]; +static struct arch_boot_info __initdata arch_info; +static struct boot_module __initdata boot_mods[MAX_NR_BOOTMODS +1 ]; + static struct arch_bootmodule __initdata arch_boot_mods[
xen/arch/x86/include/asm/bootinfo.h static int __init cf_check parse_acpi_param(const char *s) · line 293
Quoted 10 lines
xen/arch/x86/include/asm/bootinfo.h +7
-0+ MAX_NR_BOOTMODS + 1]; +int i; + + info.arch = &arch_info; info.mods = boot_mods; + info.cmdline =__va (mbi->cmdline); + +/* The BOOTINFO_FLAG_X86_* flags are a 1-1 map to MBI_* */
I would say the comment should go in the header and here you want to check the property via a set of BUILD_BUG_ON().
Quoted 5 lines
xen/arch/x86/include/asm/bootinfo.h +0
-1@@ -1147,19 +1177,22 @@ void __init noreturn __start_xen(unsigned long mbi_p) bootsym(boot_edd_info_nr));/* Check that we have at least one Multiboot module. */ -if ( !(mbi->flags &MBI_MODULES ) || (boot_info->nr_mods ==0 ) )
xen/arch/x86/include/asm/bootinfo.h void __init noreturn __start_xen(unsigned long mbi_p) · line 1187
Quoted 10 lines
xen/arch/x86/include/asm/bootinfo.h +4
-2+if ( !(boot_info->arch->flags &BOOTINFO_FLAG_X86_MODULES ) || + (boot_info->nr_mods ==0 ) )panic ("dom0 kernel not specified. Check bootloader configuration\n" );/* Check that we don't have a silly number of modules. */ -if ( boot_info->nr_mods >sizeof (module_map) *8 ) +if ( boot_info->nr_mods >MAX_NR_BOOTMODS +1 ) { - boot_info->nr_mods =sizeof (module_map) *8 ; + boot_info->nr_mods =MAX_NR_BOOTMODS +1 ;
This makes for a transient disconnect between module_map's size and MAX_NR_BOOTMODS (which only so happens to be 63; it could well be another value).
Quoted 4 lines
xen/arch/x86/include/asm/bootinfo.h +0
-0@@ -1459,14 +1486,14 @@ void __init noreturn __start_xen(unsigned long mbi_p) if ( s < end && (headroom ||
xen/arch/x86/include/asm/bootinfo.h void __init noreturn __start_xen(unsigned long mbi_p) · line 1492
Quoted 10 lines
xen/arch/x86/include/asm/bootinfo.h +2
-6- ((end - size) >> PAGE_SHIFT) > mod[j].mod_start) ) + ((end - size) >> PAGE_SHIFT) > mfn_x(boot_mod[j].mfn)) ) { move_memory(end - size + headroom, - (uint64_t )mod[j].mod_start <<PAGE_SHIFT , - mod[j].mod_end); - mod[j].mod_start = (end - size) >>PAGE_SHIFT ; - mod[j].mod_end += headroom; - mod[j].reserved =1 ; + (uint64_t)boot_mod[j].start,
Another case where you no longer need a cast afaict.
xen/arch/x86/include/asm/bootinfo.h void __init noreturn __start_xen(unsigned long mbi_p) · line 1528
Quoted 12 lines
xen/arch/x86/include/asm/bootinfo.h +3
-2@@ -1492,13 +1520,14 @@ void __init noreturn __start_xen(unsigned long mbi_p)#endif } -if ( boot_info->mods[0 ].arch->headroom && !mod->reserved ) +if ( boot_info->mods[0 ].arch->headroom && + !(boot_info->mods[0 ].arch->flags &BOOTMOD_FLAG_X86_RELOCATED ) )panic ("Not enough memory to relocate the dom0 kernel image\n" );for ( i =0 ; i < boot_info->nr_mods; ++i ) { -uint64_t s = (uint64_t )mod[i].mod_start <<PAGE_SHIFT ; +uint64_t s = (uint64_t )boot_info->mods[i].start;
Yet one more.
Quoted 15 lines
xen/include/xen/bootinfo.h +3
-0@@ -2,23 +2,50 @@#define __XEN_BOOTINFO_H__#include <xen/types.h> +#include <xen/compiler.h> +#include <xen/mm-frame.h> #ifdef CONFIG_X86 #include <asm/bootinfo.h> #else struct arch_bootmodule { }; +struct arch_boot_info { };#endif
xen/include/xen/bootinfo.h line 23
Quoted 10 lines
xen/include/xen/bootinfo.h +9
-0+/* Boot module binary type / purpose */ +#define BOOTMOD_UNKNOWN 0 +#define BOOTMOD_XEN 1 +#define BOOTMOD_FDT 2 +#define BOOTMOD_KERNEL 3 +#define BOOTMOD_RAMDISK 4 +#define BOOTMOD_XSM 5 +#define BOOTMOD_UCODE 6 +#define BOOTMOD_GUEST_DTB 7
Not all of the constants are used here (and I don't mean Arm-only ones), so I wonder how they're reliably assigned. Without assignment ahead of use (via e.g. bootmodule_next()) it's not entirely clear what the purpose is.
xen/include/xen/bootinfo.h line 26
Quoted 3 lines
xen/include/xen/bootinfo.h +3
-0+typedef unsigned int bootmod_type_t ; + +#define BOOTMOD_STRING_MAX_LEN 1024
Is there any chance of getting away with a hard-coded upper bound? You have
...
xen/include/xen/bootinfo.h line 29
Quoted 3 lines
xen/include/xen/bootinfo.h +3
-0+struct boot_string { +char bytes[BOOTMOD_STRING_MAX_LEN ]; +size_t len;
... a size field, after all.
Quoted 9 lines
xen/include/xen/bootinfo.h +4
-0+}; +struct boot_module { +bootmod_type_t bootmod_type;paddr_t start; +mfn_t mfn;size_t size;struct arch_bootmodule *arch;
xen/include/xen/bootinfo.h line 48
Quoted 10 lines
xen/include/xen/bootinfo.h +5
-0+struct boot_string string; };struct boot_info { +char *cmdline; +unsigned int nr_mods;struct boot_module *mods; + +struct arch_boot_info *arch;
Along the lines of the question on the earlier patch: Why a pointer?
Jan
Quoted 43 lines · Christopher Clark
This is a v3 series of work for Hyperlaunch for the Xen hypervisor, an update to v2 and implementing a subset of the v1 series and functionality, with changes made to address the community feedback provided on the patches. Changes since the earlier versions of the series are described below.
The patches in this series are primarily derived from patches 2-4 of the v1 full series, in a series of smaller patches for ease of review.
Thanks to AMD for supporting this work.
Documentation on Hyperlaunch:
https://wiki.xenproject.org/wiki/Hyperlaunchv1 Hyperlaunch patch series:
https://lists.xenproject.org/archives/html/xen-devel/2022-07/msg00345.htmlthanks
Christopher
Changes since v2:
- combined v2 patches 7 and 8 for common review
- rebased the v2 series onto the current tip of staging (sorry)
- fixed the placement of the patch changelogs
- provided the changes description in the cover letterChanges since v1:
- the v2 and v3 series implement functionality from v1 patches 2-4
- v2 series objective is to enable efficient patch review in support of merging the functionality into the hypervisor. It implements a subset of the v1 series, incorporating changes from community feedback.
- the bootstrap map is made accessible early in the v2 series via both multiboot and boot module arguments until later in the series where multiboot use is retired. This allows for incremental conversion across several patches from multiboot to boot modules.
- the 32-bit x86 boot environment header is removed, and changes are made to allow the new common bootinfo headers to be used instead.
- Arm and RISC-V architecture bootinfo headers are added to ensure that builds on those architectures can complete correctly.
- The KConfig patch to set the maximum number of boot modules allowed is not included in this series, replaced with a static maximum define.
Quoted 7 lines
Christopher Clark (10):
x86 setup: move x86 boot module counting into a newboot_infostruct x86 setup: per-arch bootmodule structure, headroom field x86 setup: change bootstrap map to accept new boot module structures x86 setup: porting dom0 construction logic to boot module structures
xsm: switch XSM init to boot info structures
x86 setup, microcode: switch to the new bootinfo structures
While up to here things are an integral part of your hyperlaunch work, ...
Quoted 5 lines
x86 boot: define
paddr_tand add macros for typedefing struct pointers x86, arm, riscv: add per-arch bootinfo headers
arm setup: use common integer-typed bootmod definition
x86 setup: refactor efi, pvh and multiboot entrypoints to new boot
info
... I'm getting the impression that the rest is unrelated tidying. I wonder if we really want to take that churn right now; besides this needlessly bloating the series and pulling away attention from the functionally important parts, I could also see there being a need for changes later in the course of your hyperlaunch work, which might then have a knock-on effect on what's being carried through here to very early boot code. Early boot code, tending to be fragile, would perhaps best not be altered more than necessary. I wonder what the other x86 maintainers think ...
Jan