Skip to contentSkip to conversation

v2: Boot modules for Hyperlaunch

PATCH New Christopher Clark 1 participant 12 messages Jul 1, 2023 RISC-V

lore
Share & tools
lore
#0 lore raw

cover v2: Boot modules for Hyperlaunch

This is a v2 series of work for Hyperlaunch for the Xen hypervisor, implementing a subset of the v1 series and functionality, with changes made to address the community feedback provided on the patches in v1.

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

Christopher Clark (11):
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 types, x86 boot: define DEFINE_PTR_TYPE and char_ptr_t x86, arm, riscv: add per-arch bootinfo headers to allow x86 boot
include
arm setup: include <xen/bootinfo> for bootmod defns, replacing enum x86 setup: refactor 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
#1 lore raw

PATCH 1/11 x86 setup: move x86 boot module counting into a new boot_info struct

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.

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 derived from 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 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
index 74e3915a4d..708639b236 100644
@@ -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
new file mode 100644
index 0000000000..6a7d55d20e
@@ -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
#2 lore raw

PATCH 2/11 x86 setup: per-arch bootmodule structure, headroom field

In reply to 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.

changes since v1:
- patch is a subset of v1 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
index ac4fd428be..dac2399b89 100644
@@ -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
index fd2cbf68bc..bf08998862 100644
@@ -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
new file mode 100644
index 0000000000..a25054f372
@@ -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
index 7ed69d3910..dd784f32ef 100644
@@ -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
index c99135a552..6ed9f8bbed 100644
@@ -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
index 708639b236..c0e8fc6ab7 100644
@@ -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
index 6a7d55d20e..b72ae31a66 100644
@@ -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
#3 lore raw

PATCH 3/11 x86 setup: change bootstrap map to accept new boot module structures

In reply to 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/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.

changes since v1:
- new patch so v1 patch 3 can be implemented via incremental series

---
 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
index cd456c476f..e720a89167 100644
@@ -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 )
         {
@@ -794,7 +795,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);
@@ -817,7 +818,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
index bf08998862..56fe89632b 100644
@@ -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
new file mode 100644
index 0000000000..10b17f12b2
@@ -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
index ae0dd3915a..80d0bb2a21 100644
@@ -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
index 6ed9f8bbed..4fe806b60d 100644
@@ -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
index c0e8fc6ab7..3b623a4149 100644
@@ -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
index b72ae31a66..eb93cc3439 100644
@@ -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
index 8dafbc9381..c6df8c6e06 100644
@@ -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
#4 lore raw

PATCH 4/11 x86 setup: porting dom0 construction logic to boot module structures

In reply to 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_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: a subset of patch 3
- retains module_map for now as still used functions outside setup
- move the static inline functions to a separate dedicated header
- include mm-frame.h and compiler.h as simpler dependencies than mm.h

---
 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
index 79234f18ff..b38cd1550e 100644
@@ -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>
@@ -574,9 +575,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;
 
@@ -588,9 +588,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
index 10b17f12b2..bcf4f2e2e3 100644
@@ -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
index a25054f372..30c27980e0 100644
@@ -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
index a5f8c9e67f..ca502269f2 100644
@@ -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
index 80d0bb2a21..2d620d04c7 100644
@@ -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
index 4fe806b60d..bc0af7cf27 100644
@@ -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
index eb93cc3439..2f4284a91f 100644
@@ -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
#5 lore raw

PATCH 5/11 xsm: switch XSM init to boot info structures

In reply to 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 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:
- derived from patches 2 and 3
- added pvh-boot.c multiboot header inclusion
- conditional inclusion of bootinfo.h to avoid breaking Arm

---
 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
index 9cbe87b61b..1ed04d035c 100644
@@ -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
index f9b04daebd..a616ccc0a8 100644
@@ -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
index 8dad03fd3d..d409c30be6 100644
@@ -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
#6 lore raw

PATCH 6/11 x86 setup, microcode: switch to the new bootinfo structures

In reply to 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_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:
- an incremental subset of patch 3
- added the drop of the temporary bootstrap map

---
 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
index e720a89167..c674ccf88c 100644
@@ -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);
@@ -737,11 +770,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;
 }
@@ -785,19 +813,15 @@ 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;
 
     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;
@@ -815,11 +839,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;
@@ -838,8 +857,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;
@@ -863,11 +881,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
index bcf4f2e2e3..e51fd32280 100644
@@ -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
index 62ce3418f7..803fbbb270 100644
@@ -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
index a616ccc0a8..50a1a124b0 100644
@@ -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
#7 lore raw

PATCH 7/11 x86 boot: define paddr_t and add macros for typedefing struct pointers

In reply to 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.

Introduces DEFINE_STRUCT_PTR_TYPE which will generate typedefs with a _ptr_t suffix for pointers to the specified struct. This is then used in <xen/bootinfo.h>

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.

New in v2 of series

---
 xen/arch/x86/boot/defs.h            | 5 +++++
 xen/arch/x86/include/asm/bootinfo.h | 2 ++
 xen/include/xen/bootinfo.h          | 7 ++++---
 xen/include/xen/types.h             | 5 +++++
 4 files changed, 16 insertions(+), 3 deletions(-)
xen/arch/x86/boot/defs.h +5 -0
index f9840044ec..867df6d18d 100644
@@ -60,4 +60,9 @@ 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;
+
 #endif /* __BOOT_DEFS_H__ */
xen/arch/x86/include/asm/bootinfo.h +2 -0
index 30c27980e0..8d1261503d 100644
@@ -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;
@@ -19,6 +20,7 @@ struct arch_boot_info {
     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 +4 -3
index 2f4284a91f..8ee3ee36e9 100644
@@ -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;
 
     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 +5 -0
index 6aba80500a..78a2079619 100644
@@ -71,4 +71,9 @@ 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
+
 #endif /* __TYPES_H__ */
Signature · 1 line
2.25.1
#8 lore raw

PATCH 8/11 types, x86 boot: define DEFINE_PTR_TYPE and char_ptr_t

In reply to 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 enables the 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.

Add a macro for defining pointer types for fields and use this macro for pointers to chars in <xen/bootinfo.h> and <asm/bootinfo.h> 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.

New in v2

---
 xen/arch/x86/boot/defs.h            | 4 ++++
 xen/arch/x86/include/asm/bootinfo.h | 2 +-
 xen/include/xen/bootinfo.h          | 2 +-
 xen/include/xen/types.h             | 6 ++++++
 4 files changed, 12 insertions(+), 2 deletions(-)
xen/arch/x86/boot/defs.h +4 -0
index 867df6d18d..bc0f1b5cf8 100644
@@ -65,4 +65,8 @@ 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 +1 -1
index 8d1261503d..989fb7a1da 100644
@@ -15,7 +15,7 @@ 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;
xen/include/xen/bootinfo.h +1 -1
index 8ee3ee36e9..8389da4f72 100644
@@ -41,7 +41,7 @@ struct boot_module {
 DEFINE_STRUCT_PTR_TYPE(boot_module);
 
 struct boot_info {
-    char *cmdline;
+    char_ptr_t cmdline;
 
     unsigned int nr_mods;
     boot_module_ptr_t mods;
xen/include/xen/types.h +6 -0
index 78a2079619..e807ffe255 100644
@@ -76,4 +76,10 @@ typedef bool bool_t;
     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
#9 lore raw

PATCH 9/11 x86, arm, riscv: add per-arch bootinfo headers to allow x86 boot include

In reply to Christopher Clark

The <xen/bootinfo.h> header contains structures that will be used in efi logic prior to the main start of Xen, so will soon be included in Arm builds. This same header will also used in early x86 boot, where asm/* headers are not reachable and yet it contains a needed include of <asm/bootinfo.h>, so...

Add initial per-arch <asm/bootinfo.h> headers to Arm and RISC-V so that inclusion of <asm/bootinfo.h> succeeds in each main arch build and then gate that inclusion from <xen/bootinfo.h> on CONFIG variables so that it does not take effect in the early x86 boot build where CONFIG_X86 is not defined to prevent build failure there. The early x86 boot logic can then directly include asm/bootinfo.h via a specified directory path to bring in the necessary definitions.

Is this fantastic? No. Does it help? Yep.

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
new file mode 100644
index 0000000000..5316c87a3d
@@ -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
new file mode 100644
index 0000000000..5316c87a3d
@@ -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
index 8389da4f72..bf5586a76b 100644
@@ -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 defined CONFIG_X86 || CONFIG_ARM || CONFIG_RISCV
+# include <asm/bootinfo.h>
 #endif
 
 /* Boot module binary type / purpose */
Signature · 1 line
2.25.1
#10 lore raw

PATCH 10/11 arm setup: include <xen/bootinfo> for bootmod defns, replacing enum

In reply to Christopher Clark

This change enables and begins introducion of <xen/bootinfo.h> into Arm builds: it replace the enum definition of bootmodule_kind with bootmod_type_t which is a fixed size type as needed for packed structs, to be used in the 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
index 38e2ce255f..ce3882ca67 100644
@@ -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
#11 lore raw

PATCH 11/11 x86 setup: refactor entrypoints to new boot info

In reply to Christopher Clark

Previous 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.

changes since v1:
- 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 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
index bb64925d70..d931fe06ed 100644
@@ -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
index bc0f1b5cf8..519ca4dae6 100644
@@ -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
index 989fb7a1da..c1ed76fd3e 100644
@@ -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 << 0
     uint32_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
index 247ba6899e..c820b0bf88 100644
@@ -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
index c5850c26af..09b38b497c 100644
@@ -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
index bf5586a76b..6e09be6899 100644
@@ -20,13 +20,16 @@
 #define BOOTMOD_GUEST_DTB   7
 typedef 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