Skip to contentSkip to conversation

Boot modules for Hyperlaunch

PATCH Superseded Daniel P. Smith 4 participants 76 messages Oct 17, 2024 – Oct 19, 2024

v6 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v6 cover Boot modules for Hyperlaunch

The Boot Modules for Hyperlaunch series is an effort to split out preliminary changes necessary for the introduction of the Hyperlaunch domain builder logic. These preliminary changes revolve around introducing the struct boot_module and struct boot_domain structures. This includes converting the dom0 construction path to use these structures. These abstractions lay the groundwork to transform and extend the dom0 construction logic into a limited, but general domain builder.

The splitting of Hyperlaunch into a set of series are twofold, to reduce the effort in reviewing a much larger series, and to reduce the effort in handling the knock-on effects to the construction logic from requested review changes.

Much thanks to AMD for supporting this work.

Documentation on Hyperlaunch:
https://wiki.xenproject.org/wiki/Hyperlaunch

Original Hyperlaunch v1 patch series:
https://lists.xenproject.org/archives/html/xen-devel/2022-07/msg00345.html

V/r,
Daniel P. Smith

Changes since v5:
- switched to per patch change logs
- incorporated review requests

Changes since v4:
- added requested inline code comments
- moved instance of struct boot_info to unit level and extern'ed
- array of struct boot_module moved into struct boot_info
- renamed function to multiboot_fill_bootinfo, now returns *struct boot_info
- multiboot_fill_bootinfo changed to take multiboot_info_t addr as param
- added missing guard that checked there were multiboot1/2 modules passed
- renmaed struct elements per the review
- fixed errant commit messages per the review
- corrected coding style per review
- attempted to repalce all open codings of page/addr translations touched
- unified use of bi as var name for pointer ref to struct boot_info
- when appropriate, ensure variables where typed, eg size_t, paddr_t, etc.
- dropped all uses of "a = b = c"

Changes since v3:
- reduced scope to x86 only
- broke changes into a smaller chunks with a linear progression
- concerns about deconflicting with Arm deferred
- conversion from mb1 to boot modules no longer attempted at entry points
- the temporary conversion function is now the permenant means to convert
- incorporated suggestion from Andy Cooper for handling bootstrap_map

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.

Andrew Cooper (1):
x86/boot: split bootstrap_map_addr() out of bootstrap_map()

Christopher Clark (1):
x86/boot: move x86 boot module counting into a new boot_info struct

Daniel P. Smith (42):
x86/boot: move boot loader name to boot info
x86/boot: move cmdline to boot info
x86/boot: move mmap info to boot info
x86/boot: introduce struct boot_module
x86/boot: convert consider_modules to struct boot_module x86/boot: move headroom to boot modules
x86/boot: convert mod refs to boot_module mod
x86/boot: introduce boot module types
x86/boot: introduce boot module flags
x86/boot: add start and size fields to struct boot_module x86/boot: update struct boot_module on module relocation x86/boot: transition relocation calculations to struct boot_module x86/boot: introduce boot module interator
x86/boot: introduce consumed flag for struct boot_module x86/boot: convert microcode loading to consume struct boot_info x86/boot: convert late microcode loading to struct boot_module x86/boot: use consumed boot module flag for microcode x86/boot: convert xsm policy loading to struct boot_module x86/boot: convert ramdisk locating to struct boot_module x86/boot: remove module_map usage from microcode loading x86/boot: remove module_map usage from xsm policy loading x86/boot: remove module_map usage by ramdisk loading x86/boot: convert create_dom0 to use boot info
x86/boot: convert construct_dom0 to use struct boot_module x86/boot: relocate kextra into boot info
x86/boot: add cmdline to struct boot_module
x86/boot: convert dom0_construct_pv image param to struct boot_module x86/boot: convert dom0_construct_pv initrd param to struct boot_module x86/boot: convert dom0_construct_pvh to struct boot_module x86/boot: convert pvh_load_kernel to struct boot_module x86/boot: convert initial_images to struct boot_module x86/boot: drop the use of initial_images unit global x86/boot: remove usage of mod_end by discard_initial_images x86/boot: remove remaining module_t references
x86/boot: remove mod from struct boot_module
x86/boot: introduce boot domain
x86/boot: introduce domid field to struct boot_domain x86/boot: add cmdline to struct boot_domain
x86/boot: add struct domain to struct boot_domain x86/boot: convert construct_dom0 to struct boot_domain x86/boot: convert dom0_construct_pv to struct boot_domain x86/boot: convert dom0_construct_pvh to struct boot_domain

 xen/arch/x86/cpu/microcode/core.c     |  78 +++----
 xen/arch/x86/dom0_build.c             |  10 +-
 xen/arch/x86/efi/efi-boot.h           |   4 +-
 xen/arch/x86/hvm/dom0_build.c         |  32 ++-
 xen/arch/x86/include/asm/bootdomain.h |  37 ++++
 xen/arch/x86/include/asm/bootinfo.h   | 110 +++++++++
 xen/arch/x86/include/asm/dom0_build.h |  11 +-
 xen/arch/x86/include/asm/microcode.h  |  12 +-
 xen/arch/x86/include/asm/setup.h      |  11 +-
 xen/arch/x86/pv/dom0_build.c          |  54 +++--
 xen/arch/x86/setup.c                  | 308 ++++++++++++++++----------
 xen/include/xsm/xsm.h                 |  14 +-
 xen/xsm/xsm_core.c                    |  19 +-
 xen/xsm/xsm_policy.c                  |  22 +-
 14 files changed, 459 insertions(+), 263 deletions(-)
 create mode 100644 xen/arch/x86/include/asm/bootdomain.h
 create mode 100644 xen/arch/x86/include/asm/bootinfo.h
Signature · 1 line
2.30.2
#1 lore raw

PATCH v6 1/44 x86/boot: move x86 boot module counting into a new boot_info struct

From: Christopher Clark <[email protected]>

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, <asm/bootinfo.h>, and populate it with a new boot_info structure initially containing a count of the number of boot modules.

No functional change intended.

---
Changes since v5:
- moved __init from being in middle of type declaration

---
 xen/arch/x86/include/asm/bootinfo.h | 29 +++++++++++++
 xen/arch/x86/include/asm/setup.h    |  2 +
 xen/arch/x86/setup.c                | 64 ++++++++++++++++++-----------
 3 files changed, 71 insertions(+), 24 deletions(-)
 create mode 100644 xen/arch/x86/include/asm/bootinfo.h
xen/arch/x86/include/asm/bootinfo.h new file +29 -0
new file mode 100644
index 000000000000..a649500ee3a2
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (c) 2024 Christopher Clark <[email protected]>
+ * Copyright (c) 2024 Apertus Solutions, LLC
+ * Author: Daniel P. Smith <[email protected]>
+ */
+
+#ifndef __XEN_X86_BOOTINFO_H__
+#define __XEN_X86_BOOTINFO_H__
+
+/*
+ * Xen internal representation of information provided by the
+ * bootloader/environment, or derived from the information.
+ */
+struct boot_info {
+    unsigned int nr_modules;
+};
+
+#endif /* __XEN_X86_BOOTINFO_H__ */
+
+/*
+ * 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 -0
index d75589178b91..3d189521189d 100644
@@ -32,6 +32,8 @@ int construct_dom0(
     const char *cmdline);
 void setup_io_bitmap(struct domain *d);
 
+extern struct boot_info xen_boot_info;
+
 unsigned long initial_images_nrpages(nodeid_t node);
 void discard_initial_images(void);
 void *bootstrap_map(const module_t *mod);
xen/arch/x86/setup.c +40 -24

189 lines not on this page · raw message

Signature · 1 line
2.30.2
#2 lore raw

Re: [PATCH v6 01/44] x86/boot: move x86 boot module counting into a new boot_info struct

Quoted 8 lines · Daniel P. Smith
xen/arch/x86/setup.c +0 -0
index a6e77c9ed9fc..6201ca0fad19 100644
@@ -274,16 +275,28 @@ static int __init cf_check parse_acpi_param(const char *s)
 custom_param("acpi", parse_acpi_param);
 
 static const module_t *__initdata initial_images;

xen/arch/x86/setup.c static int __init cf_check parse_acpi_param(const char *s) · line 286

Quoted 10 lines
xen/arch/x86/setup.c +9 -1
-static unsigned int __initdata nr_initial_images;
+
+struct boot_info __initdata xen_boot_info;
+
+static struct boot_info *__init multiboot_fill_boot_info(unsigned long mbi_p)
+{
+    struct boot_info *bi = &xen_boot_info;
+    const multiboot_info_t *mbi = __va(mbi_p);
+
+    bi->nr_modules = (mbi->flags & MBI_MODULES) ? mbi->mods_count : 0;

Having looked to end of the series, this and a few other expressions are still awkward.

The nicer way looks like:

struct boot_info __initdata xen_boot_info = {
    .loader = "unknown",
    .cmdline = "",
};

static struct boot_info *__init multiboot_fill_boot_info(unsigned long mbi_p)
{
    struct boot_info *bi = &xen_boot_info;
    const multiboot_info_t *mbi = __va(mbi_p);
    module_t *mods = __va(mbi->mods_addr);
    unsigned int i;

    if ( mbi->flags & MBI_MODULES )
        bi->nr_modules = mbi->mods_count;

    if ( mbi->flags & MBI_LOADERNAME )
        bi->loader = __va(mbi->boot_loader_name);

    if ( mbi->flags & MBI_CMDLINE )
        bi->cmdline = cmdline_cook(__va(mbi->cmdline), bi->loader);

    if ( mbi->flags & MBI_MEMMAP )
    {
        bi->memmap_addr = mbi->mmap_addr;
        bi->memmap_length = mbi->mmap_length;
    }

which is easier to read and follow.  Thoughts?

~Andrew

#3 lore raw

Re: [PATCH v6 01/44] x86/boot: move x86 boot module counting into a new boot_info struct

Quoted 47 lines · Andrew Cooper
Quoted 8 lines · Daniel P. Smith
xen/arch/x86/setup.c +0 -0
index a6e77c9ed9fc..6201ca0fad19 100644
@@ -274,16 +275,28 @@ static int __init cf_check parse_acpi_param(const char *s)
  custom_param("acpi", parse_acpi_param);
 
  static const module_t *__initdata initial_images;

xen/arch/x86/setup.c static int __init cf_check parse_acpi_param(const char *s) · line 286

Quoted 10 lines
xen/arch/x86/setup.c +9 -1
-static unsigned int __initdata nr_initial_images;
+
+struct boot_info __initdata xen_boot_info;
+
+static struct boot_info *__init multiboot_fill_boot_info(unsigned long mbi_p)
+{
+    struct boot_info *bi = &xen_boot_info;
+    const multiboot_info_t *mbi = __va(mbi_p);
+
+    bi->nr_modules = (mbi->flags & MBI_MODULES) ? mbi->mods_count : 0;

Having looked to end of the series, this and a few other expressions are still awkward.

The nicer way looks like:

struct boot_info __initdata xen_boot_info = {
    .loader = "unknown",
    .cmdline = "",
};

static struct boot_info *__init multiboot_fill_boot_info(unsigned long mbi_p)
{
    struct boot_info *bi = &xen_boot_info;
    const multiboot_info_t *mbi = __va(mbi_p);
    module_t *mods = __va(mbi->mods_addr);
    unsigned int i;

    if ( mbi->flags & MBI_MODULES )
        bi->nr_modules = mbi->mods_count;

    if ( mbi->flags & MBI_LOADERNAME ) bi->loader = __va(mbi->boot_loader_name);

    if ( mbi->flags & MBI_CMDLINE )
        bi->cmdline = cmdline_cook(__va(mbi->cmdline), bi->loader);

Quoted 8 lines

    if ( mbi->flags & MBI_MEMMAP )
    {
        bi->memmap_addr = mbi->mmap_addr;
        bi->memmap_length = mbi->mmap_length;
    }

which is easier to read and follow.  Thoughts?

You are right, that is much cleaner. I'm good with it.

v/r,
dps

#4 lore raw

PATCH v6 2/44 x86/boot: move boot loader name to boot info

In reply to Daniel P. Smith

Transition the incoming boot loader name to be held in struct boot_info.

No functional change intended.

---
Changes since v5:
- reorder struct boot_module fields
- code style changes

---
 xen/arch/x86/include/asm/bootinfo.h |  2 ++
 xen/arch/x86/setup.c                | 16 ++++++++--------
 2 files changed, 10 insertions(+), 8 deletions(-)
xen/arch/x86/include/asm/bootinfo.h +2 -0
index a649500ee3a2..bec35e7c2f23 100644
@@ -13,6 +13,8 @@
  * bootloader/environment, or derived from the information.
  */
 struct boot_info {
+    const char *loader;
+
     unsigned int nr_modules;
 };
 
xen/arch/x86/setup.c +8 -8
index 6201ca0fad19..eac0954f42b8 100644
@@ -285,6 +285,9 @@ static struct boot_info *__init multiboot_fill_boot_info(unsigned long mbi_p)
 
     bi->nr_modules = (mbi->flags & MBI_MODULES) ? mbi->mods_count : 0;
 
+    bi->loader = (mbi->flags & MBI_LOADERNAME) ? __va(mbi->boot_loader_name)
+                                               : "unknown";
+
     return bi;
 }
 
@@ -978,7 +981,7 @@ static struct domain *__init create_dom0(const module_t *image,
 
 void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
 {
-    const char *memmap_type = NULL, *loader, *cmdline = "";
+    const char *memmap_type = NULL, *cmdline = "";
     char *kextra;
     void *bsp_stack;
     struct cpu_info *info = get_cpu_info(), *bsp_info;
@@ -1032,12 +1035,9 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
 
     bi = multiboot_fill_boot_info(mbi_p);
 
-    loader = (mbi->flags & MBI_LOADERNAME) ? __va(mbi->boot_loader_name)
-                                           : "unknown";
-
     /* Parse the command-line options. */
     if ( mbi->flags & MBI_CMDLINE )
-        cmdline = cmdline_cook(__va(mbi->cmdline), loader);
+        cmdline = cmdline_cook(__va(mbi->cmdline), bi->loader);
 
     if ( (kextra = strstr(cmdline, " -- ")) != NULL )
     {
@@ -1078,7 +1078,7 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
     if ( pvh_boot )
         pvh_print_info();
 
-    printk("Bootloader: %s\n", loader);
+    printk("Bootloader: %s\n", bi->loader);
 
     printk("Command line: %s\n", cmdline);
 
@@ -1171,7 +1171,7 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
         l3_bootmap[l3_table_offset(BOOTSTRAP_MAP_BASE)] =
             l3e_from_paddr(__pa(l2_bootmap), __PAGE_HYPERVISOR);
 
-        memmap_type = loader;
+        memmap_type = bi->loader;
     }
     else if ( efi_enabled(EFI_BOOT) )
         memmap_type = "EFI";
@@ -2039,7 +2039,7 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
      */
     dom0 = create_dom0(mod, modules_headroom,
                        initrdidx < bi->nr_modules ? mod + initrdidx : NULL,
-                       kextra, loader);
+                       kextra, bi->loader);
     if ( !dom0 )
         panic("Could not set up DOM0 guest OS\n");
 
Signature · 1 line
2.30.2
#6 lore raw

PATCH v6 3/44 x86/boot: move cmdline to boot info

In reply to Daniel P. Smith

Transition Xen's command line to being held in struct boot_info.

No functional change intended.

---

Changes since v5:
- reorder struct boot_module fields

---
 xen/arch/x86/include/asm/bootinfo.h |  1 +
 xen/arch/x86/setup.c                | 20 ++++++++++++--------
 2 files changed, 13 insertions(+), 8 deletions(-)
xen/arch/x86/include/asm/bootinfo.h +1 -0
index bec35e7c2f23..efbbd30cc514 100644
@@ -14,6 +14,7 @@
  */
 struct boot_info {
     const char *loader;
+    const char *cmdline;
 
     unsigned int nr_modules;
 };
xen/arch/x86/setup.c +12 -8
index eac0954f42b8..037cdd17386c 100644
@@ -274,6 +274,8 @@ static int __init cf_check parse_acpi_param(const char *s)
 }
 custom_param("acpi", parse_acpi_param);
 
+static const char *cmdline_cook(const char *p, const char *loader_name);
+
 static const module_t *__initdata initial_images;
 
 struct boot_info __initdata xen_boot_info;
@@ -288,6 +290,12 @@ static struct boot_info *__init multiboot_fill_boot_info(unsigned long mbi_p)
     bi->loader = (mbi->flags & MBI_LOADERNAME) ? __va(mbi->boot_loader_name)
                                                : "unknown";
 
+    /* Parse the command-line options. */
+    if ( mbi->flags & MBI_CMDLINE )
+        bi->cmdline = cmdline_cook(__va(mbi->cmdline), bi->loader);
+    else
+        bi->cmdline = "";
+
     return bi;
 }
 
@@ -981,7 +989,7 @@ static struct domain *__init create_dom0(const module_t *image,
 
 void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
 {
-    const char *memmap_type = NULL, *cmdline = "";
+    const char *memmap_type = NULL;
     char *kextra;
     void *bsp_stack;
     struct cpu_info *info = get_cpu_info(), *bsp_info;
@@ -1035,11 +1043,7 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
 
     bi = multiboot_fill_boot_info(mbi_p);
 
-    /* Parse the command-line options. */
-    if ( mbi->flags & MBI_CMDLINE )
-        cmdline = cmdline_cook(__va(mbi->cmdline), bi->loader);
-
-    if ( (kextra = strstr(cmdline, " -- ")) != NULL )
+    if ( (kextra = strstr(bi->cmdline, " -- ")) != NULL )
     {
         /*
          * Options after ' -- ' separator belong to dom0.
@@ -1050,7 +1054,7 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
         kextra += 3;
         while ( kextra[1] == ' ' ) kextra++;
     }
-    cmdline_parse(cmdline);
+    cmdline_parse(bi->cmdline);
 
     /* Must be after command line argument parsing and before
      * allocing any xenheap structures wanted in lower memory. */
@@ -1080,7 +1084,7 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
 
     printk("Bootloader: %s\n", bi->loader);
 
-    printk("Command line: %s\n", cmdline);
+    printk("Command line: %s\n", bi->cmdline);
 
     printk("Xen image load base address: %#lx\n", xen_phys_start);
     if ( hypervisor_name )
Signature · 1 line
2.30.2
#7 lore raw

Re: [PATCH v6 03/44] x86/boot: move cmdline to boot info

Quoted 5 lines · Daniel P. Smith
xen/arch/x86/setup.c +0 -0
index eac0954f42b8..037cdd17386c 100644

xen/arch/x86/setup.c void asmlinkage __init noreturn __start_xen(unsigned long mbi_p) · line 1046

Quoted 9 lines
xen/arch/x86/setup.c +1 -5
@@ -1035,11 +1043,7 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
 
     bi = multiboot_fill_boot_info(mbi_p);
 
-    /* Parse the command-line options. */
-    if ( mbi->flags & MBI_CMDLINE )
-        cmdline = cmdline_cook(__va(mbi->cmdline), bi->loader);
-
-    if ( (kextra = strstr(cmdline, " -- ")) != NULL )
+    if ( (kextra = strstr(bi->cmdline, " -- ")) != NULL )

The /* Parse the command-line options. */ comment refers mostly to ...

xen/arch/x86/setup.c void asmlinkage __init noreturn __start_xen(unsigned long mbi_p) · line 1057

Quoted 9 lines
xen/arch/x86/setup.c +1 -1
     {
         /*
          * Options after ' -- ' separator belong to dom0.
@@ -1050,7 +1054,7 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
         kextra += 3;
         while ( kextra[1] == ' ' ) kextra++;
     }
-    cmdline_parse(cmdline);
+    cmdline_parse(bi->cmdline);

..., so should stay in place rather than moving into multiboot_fill_boot_info().

~Andrew

#8 lore raw

Re: [PATCH v6 03/44] x86/boot: move cmdline to boot info

Quoted 18 lines · Andrew Cooper
Quoted 5 lines · Daniel P. Smith
xen/arch/x86/setup.c +0 -0
index eac0954f42b8..037cdd17386c 100644

xen/arch/x86/setup.c void asmlinkage __init noreturn __start_xen(unsigned long mbi_p) · line 1046

Quoted 9 lines
xen/arch/x86/setup.c +1 -5
@@ -1035,11 +1043,7 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
 
      bi = multiboot_fill_boot_info(mbi_p);
 
-    /* Parse the command-line options. */
-    if ( mbi->flags & MBI_CMDLINE )
-        cmdline = cmdline_cook(__va(mbi->cmdline), bi->loader);
-
-    if ( (kextra = strstr(cmdline, " -- ")) != NULL )
+    if ( (kextra = strstr(bi->cmdline, " -- ")) != NULL )

The /* Parse the command-line options. */ comment refers mostly to ...

Quoted 12 lines

xen/arch/x86/setup.c void asmlinkage __init noreturn __start_xen(unsigned long mbi_p) · line 1057

Quoted 9 lines
xen/arch/x86/setup.c +1 -1
      {
          /*
           * Options after ' -- ' separator belong to dom0.
@@ -1050,7 +1054,7 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
          kextra += 3;
          while ( kextra[1] == ' ' ) kextra++;
      }
-    cmdline_parse(cmdline);
+    cmdline_parse(bi->cmdline);

..., so should stay in place rather than moving into multiboot_fill_boot_info().

Ack.

v/r,
dps

#9 lore raw

PATCH v6 4/44 x86/boot: move mmap info to boot info

In reply to Daniel P. Smith

Transition the memory map info to be held in struct boot_info.

No functional change intended.

---
Changes since v5:
- reorder of struct boot_module fields
- changed to memmap_length check for memmap detection

---
 xen/arch/x86/include/asm/bootinfo.h |  5 +++++
 xen/arch/x86/setup.c                | 12 +++++++++---
 2 files changed, 14 insertions(+), 3 deletions(-)
xen/arch/x86/include/asm/bootinfo.h +5 -0
index efbbd30cc514..f75a7e72a700 100644
@@ -8,6 +8,8 @@
 #ifndef __XEN_X86_BOOTINFO_H__
 #define __XEN_X86_BOOTINFO_H__
 
+#include <xen/types.h>
+
 /*
  * Xen internal representation of information provided by the
  * bootloader/environment, or derived from the information.
@@ -16,6 +18,9 @@ struct boot_info {
     const char *loader;
     const char *cmdline;
 
+    paddr_t memmap_addr;
+    size_t memmap_length;
+
     unsigned int nr_modules;
 };
 
xen/arch/x86/setup.c +9 -3
index 037cdd17386c..f7ea482920ef 100644
@@ -296,6 +296,12 @@ static struct boot_info *__init multiboot_fill_boot_info(unsigned long mbi_p)
     else
         bi->cmdline = "";
 
+    if ( mbi->flags & MBI_MEMMAP )
+    {
+        bi->memmap_addr = mbi->mmap_addr;
+        bi->memmap_length = mbi->mmap_length;
+    }
+
     return bi;
 }
 
@@ -1185,13 +1191,13 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
     {
         memmap_type = "Xen-e820";
     }
-    else if ( mbi->flags & MBI_MEMMAP )
+    else if ( bi->memmap_length )
     {
         memmap_type = "Multiboot-e820";
-        while ( bytes < mbi->mmap_length &&
+        while ( bytes < bi->memmap_length &&
                 e820_raw.nr_map < ARRAY_SIZE(e820_raw.map) )
         {
-            memory_map_t *map = __va(mbi->mmap_addr + bytes);
+            memory_map_t *map = __va(bi->memmap_addr + bytes);
 
             /*
              * This is a gross workaround for a BIOS bug. Some bootloaders do
Signature · 1 line
2.30.2
#10 lore raw

PATCH v6 5/44 x86/boot: introduce struct boot_module

In reply to Daniel P. Smith

This will introduce a new struct boot_module to provide a rich state representation around modules provided by the boot loader. Support is for 64 boot modules, one held in reserve for Xen, and up to 63 can be provided by the boot loader. The array of struct boot_modules will be accessible via a reference held in struct boot_info.

A temporary mod parameter is included in struct boot_module to ease the transition from using Multiboot v1 structures over to struct boot_module. Once the transition is complete, the parameter will be dropped from the structure.

---
Changes since v5:
- reword comment

---
 xen/arch/x86/include/asm/bootinfo.h | 10 ++++++++++
 xen/arch/x86/setup.c                |  9 +++++++++
 2 files changed, 19 insertions(+)
xen/arch/x86/include/asm/bootinfo.h +10 -0
index f75a7e72a700..d19473d8941e 100644
@@ -8,8 +8,17 @@
 #ifndef __XEN_X86_BOOTINFO_H__
 #define __XEN_X86_BOOTINFO_H__
 
+#include <xen/multiboot.h>
 #include <xen/types.h>
 
+/* Max number of boot modules a bootloader can provide in addition to Xen */
+#define MAX_NR_BOOTMODS 63
+
+struct boot_module {
+    /* Transitionary only */
+    module_t *mod;
+};
+
 /*
  * Xen internal representation of information provided by the
  * bootloader/environment, or derived from the information.
@@ -22,6 +31,7 @@ struct boot_info {
     size_t memmap_length;
 
     unsigned int nr_modules;
+    struct boot_module mods[MAX_NR_BOOTMODS + 1];
 };
 
 #endif /* __XEN_X86_BOOTINFO_H__ */
xen/arch/x86/setup.c +9 -0
index f7ea482920ef..d8ee5741740a 100644
@@ -284,6 +284,8 @@ static struct boot_info *__init multiboot_fill_boot_info(unsigned long mbi_p)
 {
     struct boot_info *bi = &xen_boot_info;
     const multiboot_info_t *mbi = __va(mbi_p);
+    module_t *mods = __va(mbi->mods_addr);
+    unsigned int i;
 
     bi->nr_modules = (mbi->flags & MBI_MODULES) ? mbi->mods_count : 0;
 
@@ -302,6 +304,13 @@ static struct boot_info *__init multiboot_fill_boot_info(unsigned long mbi_p)
         bi->memmap_length = mbi->mmap_length;
     }
 
+    /*
+     * Iterate over all modules, including the extra one which should have been
+     * reserved for Xen itself
+     */
+    for ( i = 0; i <= bi->nr_modules; i++ )
+        bi->mods[i].mod = &mods[i];
+
     return bi;
 }
 
Signature · 1 line
2.30.2
#11 lore raw

Re: [PATCH v6 05/44] x86/boot: introduce struct boot_module

Quoted 14 lines · Daniel P. Smith
xen/arch/x86/setup.c +2 -0
index f7ea482920ef..d8ee5741740a 100644
@@ -284,6 +284,8 @@ static struct boot_info *__init multiboot_fill_boot_info(unsigned long mbi_p)
 {
     struct boot_info *bi = &xen_boot_info;
     const multiboot_info_t *mbi = __va(mbi_p);
+    module_t *mods = __va(mbi->mods_addr);
+    unsigned int i;
 
     bi->nr_modules = (mbi->flags & MBI_MODULES) ? mbi->mods_count : 0;
 

xen/arch/x86/setup.c static struct boot_info *__init multiboot_fill_boot_info(unsigned long mbi_p) · line 312

Quoted 9 lines
xen/arch/x86/setup.c +6 -0
@@ -302,6 +304,13 @@ static struct boot_info *__init multiboot_fill_boot_info(unsigned long mbi_p)
         bi->memmap_length = mbi->mmap_length;
     }
 
+    /*
+     * Iterate over all modules, including the extra one which should have been
+     * reserved for Xen itself
+     */
+    for ( i = 0; i <= bi->nr_modules; i++ )
+        bi->mods[i].mod = &mods[i];

I'm afraid you've got a bug here.  bi->nr_modules is unsanitised from firmware at this point.

It's checked/clamped later in __start_xen(), but not before you've potentially scribbled past the end of bi->mod[] in this loop.

I think we want to retain the warning from clamping (which needs to be after printk() is set up, so after parsing the cmdline), so to compensate I think you want:

    i < ARRAY_SIZE(bi->mods) && i <= bi->nr_modules

as the loop condition here, and a note to this effect.  I'm not sure what I think about passing exactly 64 modules, and this interacting with the Xen slot.

However, you also want to move part of "x86/boot: convert create_dom0 to use boot info" into this patch.

Specifically, the conversion from sizeof(module_map)*8 to MAX_NR_BOOTMODS, or there's also a latent bug that depends Xen being compiled as 64bit (unsigned long vs MAX_NR_BOOTMODS).

~Andrew

#12 lore raw

Re: [PATCH v6 05/44] x86/boot: introduce struct boot_module

Quoted 35 lines · Andrew Cooper
Quoted 14 lines · Daniel P. Smith
xen/arch/x86/setup.c +2 -0
index f7ea482920ef..d8ee5741740a 100644
@@ -284,6 +284,8 @@ static struct boot_info *__init multiboot_fill_boot_info(unsigned long mbi_p)
  {
      struct boot_info *bi = &xen_boot_info;
      const multiboot_info_t *mbi = __va(mbi_p);
+    module_t *mods = __va(mbi->mods_addr);
+    unsigned int i;
 
      bi->nr_modules = (mbi->flags & MBI_MODULES) ? mbi->mods_count : 0;
 

xen/arch/x86/setup.c static struct boot_info *__init multiboot_fill_boot_info(unsigned long mbi_p) · line 312

Quoted 9 lines
xen/arch/x86/setup.c +6 -0
@@ -302,6 +304,13 @@ static struct boot_info *__init multiboot_fill_boot_info(unsigned long mbi_p)
          bi->memmap_length = mbi->mmap_length;
      }
 
+    /*
+     * Iterate over all modules, including the extra one which should have been
+     * reserved for Xen itself
+     */
+    for ( i = 0; i <= bi->nr_modules; i++ )
+        bi->mods[i].mod = &mods[i];

I'm afraid you've got a bug here.  bi->nr_modules is unsanitised from firmware at this point.

It's checked/clamped later in __start_xen(), but not before you've potentially scribbled past the end of bi->mod[] in this loop.

I think we want to retain the warning from clamping (which needs to be after printk() is set up, so after parsing the cmdline), so to compensate I think you want:

Quoted 5 lines

    i < ARRAY_SIZE(bi->mods) && i <= bi->nr_modules

as the loop condition here, and a note to this effect.  I'm not sure what I think about passing exactly 64 modules, and this interacting with the Xen slot.

Completely agree. I think Alejandro was trying to call that out and I missed his point. Will fix.

Quoted 6 lines

However, you also want to move part of "x86/boot: convert create_dom0 to use boot info" into this patch.

Specifically, the conversion from sizeof(module_map)*8 to MAX_NR_BOOTMODS, or there's also a latent bug that depends Xen being compiled as 64bit (unsigned long vs MAX_NR_BOOTMODS).

You are right, we should truncate to MAX_NR_BOOTMODS at this point and not later.

v/r,
dps

#13 lore raw

PATCH v6 6/44 x86/boot: convert consider_modules to struct boot_module

In reply to Daniel P. Smith

To start transitioning consider_modules() over to struct boot_module, begin with taking the array of struct boot_modules but use the temporary struct element mod.

No functional change intended.

---
Changes since v5:
- drop unnecessary type cast

---
 xen/arch/x86/setup.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
xen/arch/x86/setup.c +8 -8
index d8ee5741740a..10934bf31d7f 100644
@@ -629,7 +629,7 @@ static void __init noinline move_xen(void)
 #undef BOOTSTRAP_MAP_LIMIT
 
 static uint64_t __init consider_modules(
-    uint64_t s, uint64_t e, uint32_t size, const module_t *mod,
+    uint64_t s, uint64_t e, uint32_t size, const struct boot_module mods[],
     unsigned int nr_mods, unsigned int this_mod)
 {
     unsigned int i;
@@ -639,20 +639,20 @@ static uint64_t __init consider_modules(
 
     for ( i = 0; i < nr_mods ; ++i )
     {
-        uint64_t start = (uint64_t)mod[i].mod_start << PAGE_SHIFT;
-        uint64_t end = start + PAGE_ALIGN(mod[i].mod_end);
+        uint64_t start = pfn_to_paddr(mods[i].mod->mod_start);
+        uint64_t end = start + PAGE_ALIGN(mods[i].mod->mod_end);
 
         if ( i == this_mod )
             continue;
 
         if ( s < end && start < e )
         {
-            end = consider_modules(end, e, size, mod + i + 1,
+            end = consider_modules(end, e, size, &mods[i + 1],
                                    nr_mods - i - 1, this_mod - i - 1);
             if ( end )
                 return end;
 
-            return consider_modules(s, start, size, mod + i + 1,
+            return consider_modules(s, start, size, &mods[i + 1],
                                     nr_mods - i - 1, this_mod - i - 1);
         }
     }
@@ -1428,7 +1428,7 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
         {
             /* Don't overlap with modules. */
             end = consider_modules(s, e, reloc_size + mask,
-                                   mod, bi->nr_modules, -1);
+                                   bi->mods, bi->nr_modules, -1);
             end &= ~mask;
         }
         else
@@ -1463,7 +1463,7 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
                 continue;
 
             /* Don't overlap with other modules (or Xen itself). */
-            end = consider_modules(s, e, size, mod,
+            end = consider_modules(s, e, size, bi->mods,
                                    bi->nr_modules + relocated, j);
 
             if ( highmem_start && end > highmem_start )
@@ -1490,7 +1490,7 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
         while ( !kexec_crash_area.start )
         {
             /* Don't overlap with modules (or Xen itself). */
-            e = consider_modules(s, e, PAGE_ALIGN(kexec_crash_area.size), mod,
+            e = consider_modules(s, e, PAGE_ALIGN(kexec_crash_area.size), bi->mods,
                                  bi->nr_modules + relocated, -1);
             if ( s >= e )
                 break;
Signature · 1 line
2.30.2
#14 lore raw

PATCH v6 7/44 x86/boot: move headroom to boot modules

In reply to Daniel P. Smith

The purpose of struct boot_module is to encapsulate the state of boot module as it is processed by Xen. Locating boot module state struct boot_module reduces the number of global variables as well as the number of state variables that must be passed around. It also lays the groundwork for hyperlaunch mult-domain construction, where multiple instances of state variables like headroom will be needed.

---
Changes since v5:
- reword and expand comment on headroom
- consolidated declaration and assignment

---
 xen/arch/x86/include/asm/bootinfo.h | 13 +++++++++++++
 xen/arch/x86/setup.c                | 21 ++++++++++++---------
 2 files changed, 25 insertions(+), 9 deletions(-)
xen/arch/x86/include/asm/bootinfo.h +13 -0
index d19473d8941e..5fe4f1387d03 100644
@@ -17,6 +17,19 @@
 struct boot_module {
     /* Transitionary only */
     module_t *mod;
+    /*
+     * A boot module may contain a compressed kernel that will require
+     * additional space, before the module data, into which the kernel will be
+     * decompressed.
+     *
+     * Memory layout at boot:
+     *     [ compressed kernel ]
+     * After boot module relocation:
+     *     [ estimated headroom + PAGE_SIZE rounding ][ compressed kernel ]
+     * After kernel decompression:
+     *     [ decompressed kernel ][ unused rounding ]
+     */
+    unsigned long headroom;
 };
 
 /*
xen/arch/x86/setup.c +12 -9
index 10934bf31d7f..11e1027d72dd 100644
@@ -1012,7 +1012,7 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
     struct boot_info *bi;
     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;
@@ -1371,7 +1371,10 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
         mod[bi->nr_modules].mod_end = __2M_rwdata_end - _stext;
     }
 
-    modules_headroom = bzimage_headroom(bootstrap_map(mod), mod->mod_end);
+    bi->mods[0].headroom =
+        bzimage_headroom(bootstrap_map(bi->mods[0].mod),
+                         bi->mods[0].mod->mod_end);
+
     bootstrap_map(NULL);
 
 #ifndef highmem_start
@@ -1456,8 +1459,8 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
              * decompressor overheads of mod[0] (the dom0 kernel).  When we
              * move mod[0], we incorporate this as extra space at the start.
              */
-            unsigned long headroom = j ? 0 : modules_headroom;
-            unsigned long size = PAGE_ALIGN(headroom + mod[j].mod_end);
+            struct boot_module *bm = &bi->mods[j];
+            unsigned long size = PAGE_ALIGN(bm->headroom + mod[j].mod_end);
 
             if ( mod[j].reserved )
                 continue;
@@ -1470,14 +1473,14 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
                 continue;
 
             if ( s < end &&
-                 (headroom ||
+                 (bm->headroom ||
                   ((end - size) >> PAGE_SHIFT) > mod[j].mod_start) )
             {
-                move_memory(end - size + headroom,
+                move_memory(end - size + bm->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].mod_end += bm->headroom;
                 mod[j].reserved = 1;
             }
         }
@@ -1504,7 +1507,7 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
 #endif
     }
 
-    if ( modules_headroom && !mod->reserved )
+    if ( bi->mods[0].headroom && !mod->reserved )
         panic("Not enough memory to relocate the dom0 kernel image\n");
     for ( i = 0; i < bi->nr_modules; ++i )
     {
@@ -2056,7 +2059,7 @@ void asmlinkage __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, bi->mods[0].headroom,
                        initrdidx < bi->nr_modules ? mod + initrdidx : NULL,
                        kextra, bi->loader);
     if ( !dom0 )
Signature · 1 line
2.30.2
Reviewed-by on v6 7/44
#15 lore raw

Re: [PATCH v6 07/44] x86/boot: move headroom to boot modules

Quoted 8 lines · Daniel P. Smith

The purpose of struct boot_module is to encapsulate the state of boot module as it is processed by Xen. Locating boot module state struct boot_module reduces the number of global variables as well as the number of state variables that must be passed around. It also lays the groundwork for hyperlaunch mult-domain construction, where multiple instances of state variables like headroom will be needed.

#16 lore raw

Re: [PATCH v6 07/44] x86/boot: move headroom to boot modules

In reply to Daniel P. Smith

xen/arch/x86/include/asm/bootinfo.h line 19

Quoted 8 lines · Daniel P. Smith
xen/arch/x86/include/asm/bootinfo.h +0 -0
index d19473d8941e..5fe4f1387d03 100644
@@ -17,6 +17,19 @@
 struct boot_module {
     /* Transitionary only */
     module_t *mod;

Blank line here.

I know it falls back out later, but it's very important for legibility to be able to tell at a glance which comment belongs to which item.

~Andrew

Quoted 17 lines
xen/arch/x86/include/asm/bootinfo.h +13 -0
+    /*
+     * A boot module may contain a compressed kernel that will require
+     * additional space, before the module data, into which the kernel will be
+     * decompressed.
+     *
+     * Memory layout at boot:
+     *     [ compressed kernel ]
+     * After boot module relocation:
+     *     [ estimated headroom + PAGE_SIZE rounding ][ compressed kernel ]
+     * After kernel decompression:
+     *     [ decompressed kernel ][ unused rounding ]
+     */
+    unsigned long headroom;
 };
 
 /*
#17 lore raw

Re: [PATCH v6 07/44] x86/boot: move headroom to boot modules

Quoted 12 lines · Andrew Cooper

xen/arch/x86/include/asm/bootinfo.h line 19

Quoted 8 lines · Daniel P. Smith
xen/arch/x86/include/asm/bootinfo.h +0 -0
index d19473d8941e..5fe4f1387d03 100644
@@ -17,6 +17,19 @@
  struct boot_module {
      /* Transitionary only */
      module_t *mod;

Blank line here.

Quoted 2 lines

I know it falls back out later, but it's very important for legibility to be able to tell at a glance which comment belongs to which item.

Ack.

v/r,
dps

#18 lore raw

PATCH v6 8/44 x86/boot: convert mod refs to boot_module mod

In reply to Daniel P. Smith

To allow a slow conversion of x86 over to struct boot_module, start with replacing all references to module_t mod, only in setup.c, to the mod element of struct boot_module. These serves twofold, first to allow the incremental transition from module_t fields to struct boot_module fields. The second is to allow the conversion of function definitions from taking module_t parameters to accepting struct boot_module as needed when a transitioned field will be accessed.

---
Changes since v5:
- rewrote commit message
- coding style changes
- added comment for initial_images assignment

---
 xen/arch/x86/setup.c | 64 +++++++++++++++++++++++++-------------------
 1 file changed, 37 insertions(+), 27 deletions(-)
xen/arch/x86/setup.c +37 -27
index 11e1027d72dd..1b56eaf26efe 100644
@@ -1341,15 +1341,19 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
     set_kexec_crash_area_size((u64)nr_pages << PAGE_SHIFT);
     kexec_reserve_area();
 
-    initial_images = mod;
+    /*
+     * The field bi->mods[0].mod points to the first element of the module_t
+     * array.
+     */
+    initial_images = bi->mods[0].mod;
 
     for ( i = 0; !efi_enabled(EFI_LOADER) && i < bi->nr_modules; i++ )
     {
-        if ( mod[i].mod_start & (PAGE_SIZE - 1) )
+        if ( bi->mods[i].mod->mod_start & (PAGE_SIZE - 1) )
             panic("Bootloader didn't honor module alignment request\n");
-        mod[i].mod_end -= mod[i].mod_start;
-        mod[i].mod_start >>= PAGE_SHIFT;
-        mod[i].reserved = 0;
+        bi->mods[i].mod->mod_end -= bi->mods[i].mod->mod_start;
+        bi->mods[i].mod->mod_start >>= PAGE_SHIFT;
+        bi->mods[i].mod->reserved = 0;
     }
 
     /*
@@ -1360,6 +1364,7 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
 
     if ( xen_phys_start )
     {
+        unsigned int xen = bi->nr_modules;
         relocated = true;
 
         /*
@@ -1367,8 +1372,8 @@ void asmlinkage __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[bi->nr_modules].mod_start = virt_to_mfn(_stext);
-        mod[bi->nr_modules].mod_end = __2M_rwdata_end - _stext;
+        bi->mods[xen].mod->mod_start = virt_to_mfn(_stext);
+        bi->mods[xen].mod->mod_end = __2M_rwdata_end - _stext;
     }
 
     bi->mods[0].headroom =
@@ -1460,9 +1465,9 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
              * move mod[0], we incorporate this as extra space at the start.
              */
             struct boot_module *bm = &bi->mods[j];
-            unsigned long size = PAGE_ALIGN(bm->headroom + mod[j].mod_end);
+            unsigned long size = PAGE_ALIGN(bm->headroom + bm->mod->mod_end);
 
-            if ( mod[j].reserved )
+            if ( bi->mods[j].mod->reserved )
                 continue;
 
             /* Don't overlap with other modules (or Xen itself). */
@@ -1474,14 +1479,14 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
 
             if ( s < end &&
                  (bm->headroom ||
-                  ((end - size) >> PAGE_SHIFT) > mod[j].mod_start) )
+                  ((end - size) >> PAGE_SHIFT) > bm->mod->mod_start) )
             {
                 move_memory(end - size + bm->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 += bm->headroom;
-                mod[j].reserved = 1;
+                            (uint64_t)bm->mod->mod_start << PAGE_SHIFT,
+                            bm->mod->mod_end);
+                bm->mod->mod_start = (end - size) >> PAGE_SHIFT;
+                bm->mod->mod_end += bm->headroom;
+                bm->mod->reserved = 1;
             }
         }
 
@@ -1507,13 +1512,15 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
 #endif
     }
 
-    if ( bi->mods[0].headroom && !mod->reserved )
+    if ( bi->mods[0].headroom && !bi->mods[0].mod->reserved )
         panic("Not enough memory to relocate the dom0 kernel image\n");
     for ( i = 0; i < bi->nr_modules; ++i )
     {
-        uint64_t s = (uint64_t)mod[i].mod_start << PAGE_SHIFT;
+        uint64_t s = (uint64_t)bi->mods[i].mod->mod_start
+                        << PAGE_SHIFT;
 
-        reserve_e820_ram(&boot_e820, s, s + PAGE_ALIGN(mod[i].mod_end));
+        reserve_e820_ram(&boot_e820, s,
+                         s + PAGE_ALIGN(bi->mods[i].mod->mod_end));
     }
 
     if ( !xen_phys_start )
@@ -1591,8 +1598,9 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
                 map_e = boot_e820.map[j].addr + boot_e820.map[j].size;
                 for ( j = 0; j < bi->nr_modules; ++j )
                 {
-                    uint64_t end = pfn_to_paddr(mod[j].mod_start) +
-                                   mod[j].mod_end;
+                    uint64_t end = pfn_to_paddr(
+                                   bi->mods[j].mod->mod_start) +
+                                   bi->mods[j].mod->mod_end;
 
                     if ( map_e < end )
                         map_e = end;
@@ -1666,11 +1674,12 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
 
     for ( i = 0; i < bi->nr_modules; ++i )
     {
-        set_pdx_range(mod[i].mod_start,
-                      mod[i].mod_start + PFN_UP(mod[i].mod_end));
-        map_pages_to_xen((unsigned long)mfn_to_virt(mod[i].mod_start),
-                         _mfn(mod[i].mod_start),
-                         PFN_UP(mod[i].mod_end), PAGE_HYPERVISOR);
+        set_pdx_range(bi->mods[i].mod->mod_start,
+                      bi->mods[i].mod->mod_start +
+                      PFN_UP(bi->mods[i].mod->mod_end));
+        map_pages_to_xen((unsigned long)mfn_to_virt(bi->mods[i].mod->mod_start),
+            _mfn(bi->mods[i].mod->mod_start),
+            PFN_UP(bi->mods[i].mod->mod_end), PAGE_HYPERVISOR);
     }
 
 #ifdef CONFIG_KEXEC
@@ -2059,8 +2068,9 @@ void asmlinkage __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, bi->mods[0].headroom,
-                       initrdidx < bi->nr_modules ? mod + initrdidx : NULL,
+    dom0 = create_dom0(bi->mods[0].mod, bi->mods[0].headroom,
+                       initrdidx < bi->nr_modules ? bi->mods[initrdidx].mod
+                                                  : NULL,
                        kextra, bi->loader);
     if ( !dom0 )
         panic("Could not set up DOM0 guest OS\n");
Signature · 1 line
2.30.2
#19 lore raw

Re: [PATCH v6 08/44] x86/boot: convert mod refs to boot_module mod

Quoted 24 lines · Daniel P. Smith

To allow a slow conversion of x86 over to struct boot_module, start with replacing all references to module_t mod, only in setup.c, to the mod element of struct boot_module. These serves twofold, first to allow the incremental transition from module_t fields to struct boot_module fields. The second is to allow the conversion of function definitions from taking module_t parameters to accepting struct boot_module as needed when a transitioned field will be accessed.

---
Changes since v5:
- rewrote commit message
- coding style changes
- added comment for initial_images assignment

---
  xen/arch/x86/setup.c | 64 +++++++++++++++++++++++++-------------------
  1 file changed, 37 insertions(+), 27 deletions(-)
xen/arch/x86/setup.c +0 -0
index 11e1027d72dd..1b56eaf26efe 100644

xen/arch/x86/setup.c void asmlinkage __init noreturn __start_xen(unsigned long mbi_p) · line 1470

Quoted 8 lines
xen/arch/x86/setup.c +2 -2
@@ -1460,9 +1465,9 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
               * move mod[0], we incorporate this as extra space at the start.
               */
              struct boot_module *bm = &bi->mods[j];
-            unsigned long size = PAGE_ALIGN(bm->headroom + mod[j].mod_end);
+            unsigned long size = PAGE_ALIGN(bm->headroom + bm->mod->mod_end);
 
-            if ( mod[j].reserved )
+            if ( bi->mods[j].mod->reserved )

Use bm->mod->reserved here?

xen/arch/x86/setup.c void asmlinkage __init noreturn __start_xen(unsigned long mbi_p) · line 1602

Quoted 12 lines
xen/arch/x86/setup.c +2 -2
                  continue;
 
              /* Don't overlap with other modules (or Xen itself). */
@@ -1591,8 +1598,9 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
                  map_e = boot_e820.map[j].addr + boot_e820.map[j].size;
                  for ( j = 0; j < bi->nr_modules; ++j )
                  {
-                    uint64_t end = pfn_to_paddr(mod[j].mod_start) +
-                                   mod[j].mod_end;
+                    uint64_t end = pfn_to_paddr(
+                                   bi->mods[j].mod->mod_start) +

pfn_to_paddr and mod_start can fit on one line

Quoted 6 lines
xen/arch/x86/setup.c +1 -0
+                                   bi->mods[j].mod->mod_end;
 
                      if ( map_e < end )
                          map_e = end;
@@ -1666,11 +1674,12 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
 

xen/arch/x86/setup.c void asmlinkage __init noreturn __start_xen(unsigned long mbi_p) · line 1679

Quoted 10 lines
xen/arch/x86/setup.c +3 -5
      for ( i = 0; i < bi->nr_modules; ++i )
      {
-        set_pdx_range(mod[i].mod_start,
-                      mod[i].mod_start + PFN_UP(mod[i].mod_end));
-        map_pages_to_xen((unsigned long)mfn_to_virt(mod[i].mod_start),
-                         _mfn(mod[i].mod_start),
-                         PFN_UP(mod[i].mod_end), PAGE_HYPERVISOR);
+        set_pdx_range(bi->mods[i].mod->mod_start,
+                      bi->mods[i].mod->mod_start +
+                      PFN_UP(bi->mods[i].mod->mod_end));

Indent PFN_UP since it's a continuation of the previous argument?

xen/arch/x86/setup.c void asmlinkage __init noreturn __start_xen(unsigned long mbi_p) · line 1685

Quoted 6 lines
xen/arch/x86/setup.c +3 -0
+        map_pages_to_xen((unsigned long)mfn_to_virt(bi->mods[i].mod->mod_start),
+            _mfn(bi->mods[i].mod->mod_start),
+            PFN_UP(bi->mods[i].mod->mod_end), PAGE_HYPERVISOR);
      }
 
  #ifdef CONFIG_KEXEC

Regards,
Jason

#20 lore raw

Re: [PATCH v6 08/44] x86/boot: convert mod refs to boot_module mod

Quoted 24 lines · Jason Andryuk
Quoted 22 lines · Daniel P. Smith

To allow a slow conversion of x86 over to struct boot_module, start with replacing all references to module_t mod, only in setup.c, to the mod element of struct boot_module. These serves twofold, first to allow the incremental transition from module_t fields to struct boot_module fields. The second is to allow the conversion of function definitions from taking module_t parameters to accepting struct boot_module as needed when a transitioned field will be accessed.

---
Changes since v5:
- rewrote commit message
- coding style changes
- added comment for initial_images assignment
---
  xen/arch/x86/setup.c | 64 +++++++++++++++++++++++++-------------------

  1 file changed, 37 insertions(+), 27 deletions(-)
xen/arch/x86/setup.c +0 -0
index 11e1027d72dd..1b56eaf26efe 100644
Quoted 13 lines

xen/arch/x86/setup.c void asmlinkage __init noreturn · line 1472

Quoted 11 lines
xen/arch/x86/setup.c +2 -2
@@ -1460,9 +1465,9 @@ void asmlinkage __init noreturn 
 __start_xen(unsigned long mbi_p)
                * move mod[0], we incorporate this as extra space at the start.
                */
               struct boot_module *bm = &bi->mods[j];
-            unsigned long size = PAGE_ALIGN(bm->headroom + 
 mod[j].mod_end);
+            unsigned long size = PAGE_ALIGN(bm->headroom + 
 bm->mod->mod_end);
-            if ( mod[j].reserved )
+            if ( bi->mods[j].mod->reserved )

Use bm->mod->reserved here?

Yah, that would be better.

Quoted 14 lines

xen/arch/x86/setup.c void asmlinkage __init noreturn · line 1603

Quoted 12 lines
xen/arch/x86/setup.c +0 -0
                   continue;

              /* Don't overlap with other modules (or Xen itself). */

xen/arch/x86/setup.c +2 -2
@@ -1591,8 +1598,9 @@ void asmlinkage __init noreturn 
 __start_xen(unsigned long mbi_p)
                   map_e = boot_e820.map[j].addr + boot_e820.map[j].size;
                   for ( j = 0; j < bi->nr_modules; ++j )
                   {
-                    uint64_t end = pfn_to_paddr(mod[j].mod_start) +
-                                   mod[j].mod_end;
+                    uint64_t end = pfn_to_paddr(
+                                   bi->mods[j].mod->mod_start) +

pfn_to_paddr and mod_start can fit on one line

I will check but you have to also account for the '+' as generally it should stay with the LHS.

Quoted 9 lines
Quoted 9 lines
xen/arch/x86/setup.c +1 -2
+                                   bi->mods[j].mod->mod_end;
                       if ( map_e < end )
                           map_e = end;
@@ -1666,11 +1674,12 @@ void asmlinkage __init noreturn 
 __start_xen(unsigned long mbi_p)
       for ( i = 0; i < bi->nr_modules; ++i )
       {
-        set_pdx_range(mod[i].mod_start,
-                      mod[i].mod_start + PFN_UP(mod[i].mod_end));
Quoted 8 lines

xen/arch/x86/setup.c void asmlinkage __init noreturn __start_xen(unsigned long mbi_p) · line 1679

Quoted 6 lines
xen/arch/x86/setup.c +3 -3
-        map_pages_to_xen((unsigned long)mfn_to_virt(mod[i].mod_start),
-                         _mfn(mod[i].mod_start),
-                         PFN_UP(mod[i].mod_end), PAGE_HYPERVISOR);
+        set_pdx_range(bi->mods[i].mod->mod_start,
+                      bi->mods[i].mod->mod_start +
+                      PFN_UP(bi->mods[i].mod->mod_end));

Indent PFN_UP since it's a continuation of the previous argument?

Ack.

v/r,
dps

#21 lore raw

PATCH v6 9/44 x86/boot: introduce boot module types

In reply to Daniel P. Smith

This commit introduces module types of xen, kernel, and ramdisk to allow boot module detect code to tag the purpose of a boot module. This reduces the need for hard coded order assumptions and global variables to be used by consumers of boot modules, such as domain construction.

---
Changes since v5:
- added guard around initrd type assignment
- removed a missed rebase artifact

---
 xen/arch/x86/include/asm/bootinfo.h | 9 +++++++++
 xen/arch/x86/setup.c                | 6 ++++++
 2 files changed, 15 insertions(+)
xen/arch/x86/include/asm/bootinfo.h +9 -0
index 5fe4f1387d03..18281d80fa97 100644
@@ -14,6 +14,14 @@
 /* Max number of boot modules a bootloader can provide in addition to Xen */
 #define MAX_NR_BOOTMODS 63
 
+/* Boot module binary type / purpose */
+enum bootmod_type {
+    BOOTMOD_UNKNOWN,
+    BOOTMOD_XEN,
+    BOOTMOD_KERNEL,
+    BOOTMOD_RAMDISK,
+};
+
 struct boot_module {
     /* Transitionary only */
     module_t *mod;
@@ -30,6 +38,7 @@ struct boot_module {
      *     [ decompressed kernel ][ unused rounding ]
      */
     unsigned long headroom;
+    enum bootmod_type type;
 };
 
 /*
xen/arch/x86/setup.c +6 -0
index 1b56eaf26efe..fed9bef16305 100644
@@ -311,6 +311,9 @@ static struct boot_info *__init multiboot_fill_boot_info(unsigned long mbi_p)
     for ( i = 0; i <= bi->nr_modules; i++ )
         bi->mods[i].mod = &mods[i];
 
+    /* map the last mb module for xen entry */
+    bi->mods[bi->nr_modules].type = BOOTMOD_XEN;
+
     return bi;
 }
 
@@ -1171,6 +1174,7 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
 
     bitmap_fill(module_map, bi->nr_modules);
     __clear_bit(0, module_map); /* Dom0 kernel is always first */
+    bi->mods[0].type = BOOTMOD_KERNEL;
 
     if ( pvh_boot )
     {
@@ -2059,6 +2063,8 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
            cpu_has_nx ? "" : "not ");
 
     initrdidx = find_first_bit(module_map, bi->nr_modules);
+    if ( initrdidx < bi->nr_modules )
+        bi->mods[initrdidx].type = BOOTMOD_RAMDISK;
     if ( bitmap_weight(module_map, bi->nr_modules) > 1 )
         printk(XENLOG_WARNING
                "Multiple initrd candidates, picking module #%u\n",
Signature · 1 line
2.30.2
Reviewed-by on v6 9/44
#22 lore raw

Re: [PATCH v6 09/44] x86/boot: introduce boot module types

Quoted 6 lines · Daniel P. Smith

This commit introduces module types of xen, kernel, and ramdisk to allow boot module detect code to tag the purpose of a boot module. This reduces the need for hard coded order assumptions and global variables to be used by consumers of boot modules, such as domain construction.

#23 lore raw

PATCH v6 10/44 x86/boot: introduce boot module flags

In reply to Daniel P. Smith

The existing startup code employs various ad-hoc state tracking about certain boot module types by each area of the code. A boot module flags is added to enable tracking these different states. The first state to be transition by this commit is module relocation.

---
Changes since v5:
- removed trailing blank line.

---
 xen/arch/x86/include/asm/bootinfo.h | 3 +++
 xen/arch/x86/setup.c                | 8 ++++----
 2 files changed, 7 insertions(+), 4 deletions(-)
xen/arch/x86/include/asm/bootinfo.h +3 -0
index 18281d80fa97..e8ba9390a51f 100644
@@ -39,6 +39,9 @@ struct boot_module {
      */
     unsigned long headroom;
     enum bootmod_type type;
+
+    uint32_t flags;
+#define BOOTMOD_FLAG_X86_RELOCATED     (1U << 0)
 };
 
 /*
xen/arch/x86/setup.c +4 -4
index fed9bef16305..f87faa31a2cf 100644
@@ -1357,7 +1357,6 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
             panic("Bootloader didn't honor module alignment request\n");
         bi->mods[i].mod->mod_end -= bi->mods[i].mod->mod_start;
         bi->mods[i].mod->mod_start >>= PAGE_SHIFT;
-        bi->mods[i].mod->reserved = 0;
     }
 
     /*
@@ -1471,7 +1470,7 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
             struct boot_module *bm = &bi->mods[j];
             unsigned long size = PAGE_ALIGN(bm->headroom + bm->mod->mod_end);
 
-            if ( bi->mods[j].mod->reserved )
+            if ( bi->mods[j].flags & BOOTMOD_FLAG_X86_RELOCATED )
                 continue;
 
             /* Don't overlap with other modules (or Xen itself). */
@@ -1490,7 +1489,7 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
                             bm->mod->mod_end);
                 bm->mod->mod_start = (end - size) >> PAGE_SHIFT;
                 bm->mod->mod_end += bm->headroom;
-                bm->mod->reserved = 1;
+                bm->flags |= BOOTMOD_FLAG_X86_RELOCATED;
             }
         }
 
@@ -1516,7 +1515,8 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
 #endif
     }
 
-    if ( bi->mods[0].headroom && !bi->mods[0].mod->reserved )
+    if ( bi->mods[0].headroom &&
+         !(bi->mods[0].flags & BOOTMOD_FLAG_X86_RELOCATED) )
         panic("Not enough memory to relocate the dom0 kernel image\n");
     for ( i = 0; i < bi->nr_modules; ++i )
     {
Signature · 1 line
2.30.2
#24 lore raw

Re: [PATCH v6 10/44] x86/boot: introduce boot module flags

xen/arch/x86/include/asm/bootinfo.h struct boot_module { · line 44

Quoted 11 lines · Daniel P. Smith
xen/arch/x86/include/asm/bootinfo.h +3 -0
index 18281d80fa97..e8ba9390a51f 100644
@@ -39,6 +39,9 @@ struct boot_module {
      */
     unsigned long headroom;
     enum bootmod_type type;
+
+    uint32_t flags;
+#define BOOTMOD_FLAG_X86_RELOCATED     (1U << 0)

There are two parts to this request.  First, there's nothing X86 specific about any of the flags added (in this series at least), and the FLAG infix doesn't feel as if it adds much.

But, looking over the code, I get the feeling it would be better as simply:

    /*
     * Misc flags  XXX docs
     */
    bool relocated:1;
    bool consumed:1;

(Possibly with an enclosing struct { ... } flags; but I don't think that's necessary either.)

because flags is never operated on as a unit of multiple things, or passed around separately from a bm-> pointer.  For misc independent flags like this, bitfields lead to far more legible code because you're not having to express everything as binary operators in the logic.

I know this will be a moderately invasive change, but I suspect the improvement will speak for itself.  (Assuming there isn't a need to keep it as a plain flags field later.)

~Andrew

#25 lore raw

Re: [PATCH v6 10/44] x86/boot: introduce boot module flags

Quoted 19 lines · Andrew Cooper

xen/arch/x86/include/asm/bootinfo.h struct boot_module { · line 44

Quoted 11 lines · Daniel P. Smith
xen/arch/x86/include/asm/bootinfo.h +3 -0
index 18281d80fa97..e8ba9390a51f 100644
@@ -39,6 +39,9 @@ struct boot_module {
       */
      unsigned long headroom;
      enum bootmod_type type;
+
+    uint32_t flags;
+#define BOOTMOD_FLAG_X86_RELOCATED     (1U << 0)

There are two parts to this request.  First, there's nothing X86 specific about any of the flags added (in this series at least), and the FLAG infix doesn't feel as if it adds much.

But, looking over the code, I get the feeling it would be better as simply:

Quoted 8 lines

    /*
     * Misc flags  XXX docs
     */
    bool relocated:1;
    bool consumed:1;

(Possibly with an enclosing struct { ... } flags; but I don't think that's necessary either.)

I see no reason why not a bitfield, and as you state, will make code simpler (and possibly shorter) elsewhere.

Quoted 8 lines

because flags is never operated on as a unit of multiple things, or passed around separately from a bm-> pointer.  For misc independent flags like this, bitfields lead to far more legible code because you're not having to express everything as binary operators in the logic.

I know this will be a moderately invasive change, but I suspect the improvement will speak for itself.  (Assuming there isn't a need to keep it as a plain flags field later.)

Yah it will be a bit painful, but I would rather have cleaner and easier to read code.

v/r,
dps

#26 lore raw

PATCH v6 11/44 x86/boot: add start and size fields to struct boot_module

In reply to Daniel P. Smith

This commit introduces the start and size fields to struct boot_module and assigns their value during boot_info construction.

The EFI entry point special cased itself, and pre-converted mod_start and mod_end to mfn and size respectively. This required an additional test in the coversion loop to not convert mod_start and mod_end when the conversion was done for both the multiboot and PVH boot entry points. To simplify the logic populating the start and size fields, the EFI module population logic was coverted to using start and end addresses.

---
Changes since v5:
- switched EFI population of mod_start/mod_end to addresses

---
 xen/arch/x86/efi/efi-boot.h         | 4 ++--
 xen/arch/x86/include/asm/bootinfo.h | 3 +++
 xen/arch/x86/setup.c                | 7 ++++++-
 3 files changed, 11 insertions(+), 3 deletions(-)
xen/arch/x86/efi/efi-boot.h +2 -2
index 94f34433640f..779f101c3de7 100644
@@ -732,8 +732,8 @@ static void __init efi_arch_handle_module(const struct file *file,
     if ( options )
         place_string(&mb_modules[mbi.mods_count].string, options);
     place_string(&mb_modules[mbi.mods_count].string, local_name.s);
-    mb_modules[mbi.mods_count].mod_start = file->addr >> PAGE_SHIFT;
-    mb_modules[mbi.mods_count].mod_end = file->size;
+    mb_modules[mbi.mods_count].mod_start = file->addr;
+    mb_modules[mbi.mods_count].mod_end = file->addr + file->size;
     ++mbi.mods_count;
     efi_bs->FreePool(ptr);
 }
xen/arch/x86/include/asm/bootinfo.h +3 -0
index e8ba9390a51f..5862054b8cef 100644
@@ -42,6 +42,9 @@ struct boot_module {
 
     uint32_t flags;
 #define BOOTMOD_FLAG_X86_RELOCATED     (1U << 0)
+
+    paddr_t start;
+    size_t size;
 };
 
 /*
xen/arch/x86/setup.c +6 -1
index f87faa31a2cf..6ee352fc0cde 100644
@@ -309,8 +309,13 @@ static struct boot_info *__init multiboot_fill_boot_info(unsigned long mbi_p)
      * reserved for Xen itself
      */
     for ( i = 0; i <= bi->nr_modules; i++ )
+    {
         bi->mods[i].mod = &mods[i];
 
+        bi->mods[i].start = (paddr_t)mods[i].mod_start;
+        bi->mods[i].size = mods[i].mod_end - mods[i].mod_start;
+    }
+
     /* map the last mb module for xen entry */
     bi->mods[bi->nr_modules].type = BOOTMOD_XEN;
 
@@ -1351,7 +1356,7 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
      */
     initial_images = bi->mods[0].mod;
 
-    for ( i = 0; !efi_enabled(EFI_LOADER) && i < bi->nr_modules; i++ )
+    for ( i = 0; i < bi->nr_modules; i++ )
     {
         if ( bi->mods[i].mod->mod_start & (PAGE_SIZE - 1) )
             panic("Bootloader didn't honor module alignment request\n");
Signature · 1 line
2.30.2
Reviewed-by on v6 11/44
#27 lore raw

Re: [PATCH v6 11/44] x86/boot: add start and size fields to struct boot_module

Quoted 6 lines · Daniel P. Smith

This commit introduces the start and size fields to struct boot_module and assigns their value during boot_info construction.

The EFI entry point special cased itself, and pre-converted mod_start and mod_end to mfn and size respectively. This required an additional test in the coversion loop to not convert mod_start and mod_end when the conversion

conversion

Quoted 3 lines

was done for both the multiboot and PVH boot entry points. To simplify the logic populating the start and size fields, the EFI module population logic was coverted to using start and end addresses.

converted

Quoted 2 lines

with that

EFI now gains the alignment check, but beforehand it was just silently truncating. Seems better to check :)

Regards,
Jason

#28 lore raw

Re: [PATCH v6 11/44] x86/boot: add start and size fields to struct boot_module

Quoted 9 lines · Jason Andryuk
Quoted 6 lines · Daniel P. Smith

This commit introduces the start and size fields to struct boot_module and assigns their value during boot_info construction.

The EFI entry point special cased itself, and pre-converted mod_start and mod_end to mfn and size respectively. This required an additional test in the coversion loop to not convert mod_start and mod_end when the conversion

conversion

Ack.

Quoted 5 lines
Quoted 3 lines

was done for both the multiboot and PVH boot entry points. To simplify the logic populating the start and size fields, the EFI module population logic was coverted to using start and end addresses.

converted

Ack.

Quoted 5 lines
Quoted 2 lines

with that

Thank you but will hold off since Andy has asked this be split and changed.

Quoted 1 line

EFI now gains the alignment check, but beforehand it was just silently truncating.  Seems better to check :)

My thinking as well.

v/r,
dps

#29 lore raw

Re: [PATCH v6 11/44] x86/boot: add start and size fields to struct boot_module

In reply to Daniel P. Smith
Quoted 11 lines · Daniel P. Smith

This commit introduces the start and size fields to struct boot_module and assigns their value during boot_info construction.

The EFI entry point special cased itself, and pre-converted mod_start and mod_end to mfn and size respectively. This required an additional test in the coversion loop to not convert mod_start and mod_end when the conversion was done for both the multiboot and PVH boot entry points. To simplify the logic populating the start and size fields, the EFI module population logic was coverted to using start and end addresses.

Quoted 8 lines

---
Changes since v5:
- switched EFI population of mod_start/mod_end to addresses

---
 xen/arch/x86/efi/efi-boot.h         | 4 ++--
 xen/arch/x86/include/asm/bootinfo.h | 3 +++
 xen/arch/x86/setup.c                | 7 ++++++-
 3 files changed, 11 insertions(+), 3 deletions(-)

Despite being small already, I'd still prefer to split this into two patches.

One changing the EFI path, and a separate one adding in the new (real) start/size fields.

Sods law would says that if we don't, bisection is going to end up here, except it doesn't need to...

xen/arch/x86/efi/efi-boot.h static void __init efi_arch_handle_module(const struct file *file, · line 736

Quoted 12 lines
xen/arch/x86/efi/efi-boot.h +2 -2
index 94f34433640f..779f101c3de7 100644
@@ -732,8 +732,8 @@ static void __init efi_arch_handle_module(const struct file *file,
     if ( options )
         place_string(&mb_modules[mbi.mods_count].string, options);
     place_string(&mb_modules[mbi.mods_count].string, local_name.s);
-    mb_modules[mbi.mods_count].mod_start = file->addr >> PAGE_SHIFT;
-    mb_modules[mbi.mods_count].mod_end = file->size;
+    mb_modules[mbi.mods_count].mod_start = file->addr;
+    mb_modules[mbi.mods_count].mod_end = file->addr + file->size;

... because you can't drop this shift until you have a full-width start field to use.   file->addr might exceed 4G, and truncate with this patch in place.

You're going to need to keep the old semantics here, fill in all 4 fields, and keep the EFI special case in the final hunk until you can remove the ->mod_{start,end} narrow fields.

xen/arch/x86/setup.c static struct boot_info *__init multiboot_fill_boot_info(unsigned long mbi_p) · line 315

Quoted 12 lines
xen/arch/x86/setup.c +2 -0
index f87faa31a2cf..6ee352fc0cde 100644
@@ -309,8 +309,13 @@ static struct boot_info *__init multiboot_fill_boot_info(unsigned long mbi_p)
      * reserved for Xen itself
      */
     for ( i = 0; i <= bi->nr_modules; i++ )
+    {
         bi->mods[i].mod = &mods[i];
 
+        bi->mods[i].start = (paddr_t)mods[i].mod_start;

This cast isn't needed, but don't we need a shift in here?

~Andrew

#30 lore raw

Re: [PATCH v6 11/44] x86/boot: add start and size fields to struct boot_module

Quoted 21 lines · Andrew Cooper
Quoted 11 lines · Daniel P. Smith

This commit introduces the start and size fields to struct boot_module and assigns their value during boot_info construction.

The EFI entry point special cased itself, and pre-converted mod_start and mod_end to mfn and size respectively. This required an additional test in the coversion loop to not convert mod_start and mod_end when the conversion was done for both the multiboot and PVH boot entry points. To simplify the logic populating the start and size fields, the EFI module population logic was coverted to using start and end addresses.

Quoted 8 lines

---
Changes since v5:
- switched EFI population of mod_start/mod_end to addresses

---
  xen/arch/x86/efi/efi-boot.h         | 4 ++--
  xen/arch/x86/include/asm/bootinfo.h | 3 +++
  xen/arch/x86/setup.c                | 7 ++++++-
  3 files changed, 11 insertions(+), 3 deletions(-)
Quoted 2 lines

Despite being small already, I'd still prefer to split this into two patches.

I was going to agree with you but thinking about your point that in EFI the addr could legitimately be >4G and thus the conversion to pfn and size will need to stay. Therefore this will cause the efi changes to drop back out and require the introduction of EFI test and alternative path for setting start/size by converting back. If I were to break up it up, what will result is there will be a patch that introduces straight assignment for MB and PVH boot. The second commit would introduce the EFI test and alternate branch to assign start using the shift conversion. I think this all probably should stay in a single patch, but if you still would like to see it separate than I will do so.

Quoted 23 lines

One changing the EFI path, and a separate one adding in the new (real) start/size fields.

Sods law would says that if we don't, bisection is going to end up here, except it doesn't need to...

xen/arch/x86/efi/efi-boot.h static void __init efi_arch_handle_module(const struct file *file, · line 736

Quoted 12 lines
xen/arch/x86/efi/efi-boot.h +2 -2
index 94f34433640f..779f101c3de7 100644
@@ -732,8 +732,8 @@ static void __init efi_arch_handle_module(const struct file *file,
      if ( options )
          place_string(&mb_modules[mbi.mods_count].string, options);
      place_string(&mb_modules[mbi.mods_count].string, local_name.s);
-    mb_modules[mbi.mods_count].mod_start = file->addr >> PAGE_SHIFT;
-    mb_modules[mbi.mods_count].mod_end = file->size;
+    mb_modules[mbi.mods_count].mod_start = file->addr;
+    mb_modules[mbi.mods_count].mod_end = file->addr + file->size;

... because you can't drop this shift until you have a full-width start field to use.   file->addr might exceed 4G, and truncate with this patch in place.

Quoted 3 lines

You're going to need to keep the old semantics here, fill in all 4 fields, and keep the EFI special case in the final hunk until you can remove the ->mod_{start,end} narrow fields.

While in testing I did not see it occur, you are correct that it is possible that the EFI allocator may choose to do so. I will drop the change in the efi code and handle with a condition in the multiboot_fill_boot_info() funciton for the time being.

Quoted 11 lines
Quoted 11 lines
xen/arch/x86/setup.c +1 -0
index f87faa31a2cf..6ee352fc0cde 100644
@@ -309,8 +309,13 @@ static struct boot_info *__init multiboot_fill_boot_info(unsigned long mbi_p)
       * reserved for Xen itself
       */
      for ( i = 0; i <= bi->nr_modules; i++ )
+    {
          bi->mods[i].mod = &mods[i];
 
Quoted 3 lines

xen/arch/x86/setup.c static struct boot_info *__init multiboot_fill_boot_info(unsigned long mbi_p) · line 315

Quoted 1 line
xen/arch/x86/setup.c +1 -0
+        bi->mods[i].start = (paddr_t)mods[i].mod_start;

This cast isn't needed, but don't we need a shift in here?

Only for EFI.

v/r,
dps

#31 lore raw

PATCH v6 12/44 x86/boot: update struct boot_module on module relocation

In reply to Daniel P. Smith

When a boot module is relocated, ensure struct boot_module start and size fields are updated along with early_mod.

---
Changes since v5:
- corrected conversion function for a missed switch from mfn to maddr/paddr

---
 xen/arch/x86/setup.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
xen/arch/x86/setup.c +5 -2
index 6ee352fc0cde..d51b0b03bc97 100644
@@ -1380,8 +1380,11 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
          * respective reserve_e820_ram() invocation below. No need to
          * query efi_boot_mem_unused() here, though.
          */
-        bi->mods[xen].mod->mod_start = virt_to_mfn(_stext);
-        bi->mods[xen].mod->mod_end = __2M_rwdata_end - _stext;
+        bi->mods[xen].start = virt_to_maddr(_stext);
+        bi->mods[xen].size = __2M_rwdata_end - _stext;
+
+        bi->mods[xen].mod->mod_start = bi->mods[xen].start;
+        bi->mods[xen].mod->mod_end = bi->mods[xen].size;
     }
 
     bi->mods[0].headroom =
Signature · 1 line
2.30.2
#32 lore raw

Re: [PATCH v6 12/44] x86/boot: update struct boot_module on module relocation

Quoted 16 lines · Daniel P. Smith

When a boot module is relocated, ensure struct boot_module start and size fields are updated along with early_mod.

---
Changes since v5:
- corrected conversion function for a missed switch from mfn to maddr/paddr

---
  xen/arch/x86/setup.c | 7 +++++--
  1 file changed, 5 insertions(+), 2 deletions(-)
xen/arch/x86/setup.c +0 -0
index 6ee352fc0cde..d51b0b03bc97 100644

xen/arch/x86/setup.c void asmlinkage __init noreturn __start_xen(unsigned long mbi_p) · line 1386

Quoted 9 lines
xen/arch/x86/setup.c +4 -2
@@ -1380,8 +1380,11 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
           * respective reserve_e820_ram() invocation below. No need to
           * query efi_boot_mem_unused() here, though.
           */
-        bi->mods[xen].mod->mod_start = virt_to_mfn(_stext);
-        bi->mods[xen].mod->mod_end = __2M_rwdata_end - _stext;
+        bi->mods[xen].start = virt_to_maddr(_stext);
+        bi->mods[xen].size = __2M_rwdata_end - _stext;
+
+        bi->mods[xen].mod->mod_start = bi->mods[xen].start;

But now this line needs to be converted to an mfn?

Regards,
Jason

Quoted 4 lines
xen/arch/x86/setup.c +1 -0
+        bi->mods[xen].mod->mod_end = bi->mods[xen].size;
      }
 
      bi->mods[0].headroom =
#33 lore raw

Re: [PATCH v6 12/44] x86/boot: update struct boot_module on module relocation

Quoted 22 lines · Jason Andryuk
Quoted 21 lines · Daniel P. Smith

When a boot module is relocated, ensure struct boot_module start and size fields are updated along with early_mod.

---
Changes since v5:
- corrected conversion function for a missed switch from mfn to maddr/paddr
---
  xen/arch/x86/setup.c | 7 +++++--

  1 file changed, 5 insertions(+), 2 deletions(-)
xen/arch/x86/setup.c +0 -0
index 6ee352fc0cde..d51b0b03bc97 100644
@@ -1380,8 +1380,11 @@ void asmlinkage __init noreturn 
 __start_xen(unsigned long mbi_p)
            * respective reserve_e820_ram() invocation below. No need to
            * query efi_boot_mem_unused() here, though.
            */
Quoted 8 lines

xen/arch/x86/setup.c void asmlinkage __init noreturn __start_xen(unsigned long mbi_p) · line 1386

Quoted 6 lines
xen/arch/x86/setup.c +4 -2
-        bi->mods[xen].mod->mod_start = virt_to_mfn(_stext);
-        bi->mods[xen].mod->mod_end = __2M_rwdata_end - _stext;
+        bi->mods[xen].start = virt_to_maddr(_stext);
+        bi->mods[xen].size = __2M_rwdata_end - _stext;
+
+        bi->mods[xen].mod->mod_start = bi->mods[xen].start;

But now this line needs to be converted to an mfn?

Correct.

v/r,
dps

#34 lore raw

PATCH v6 13/44 x86/boot: transition relocation calculations to struct boot_module

In reply to Daniel P. Smith

Use struct boot_module fields, start and size, when calculating the relocation address and size. It also ensures that early_mod references are kept in sync.

---
Changes since v5:
- removed unnecessary paddr_to_pfn, allowing condition to collapse to one line
- correct a missed conversion from .mod->mod_start to .start

---
 xen/arch/x86/setup.c | 38 +++++++++++++++++---------------------
 1 file changed, 17 insertions(+), 21 deletions(-)
xen/arch/x86/setup.c +17 -21
index d51b0b03bc97..44cec48fc877 100644
@@ -1476,7 +1476,7 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
              * move mod[0], we incorporate this as extra space at the start.
              */
             struct boot_module *bm = &bi->mods[j];
-            unsigned long size = PAGE_ALIGN(bm->headroom + bm->mod->mod_end);
+            unsigned long size = PAGE_ALIGN(bm->headroom + bm->size);
 
             if ( bi->mods[j].flags & BOOTMOD_FLAG_X86_RELOCATED )
                 continue;
@@ -1488,15 +1488,13 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
             if ( highmem_start && end > highmem_start )
                 continue;
 
-            if ( s < end &&
-                 (bm->headroom ||
-                  ((end - size) >> PAGE_SHIFT) > bm->mod->mod_start) )
+            if ( s < end && (bm->headroom || (end - size) > bm->start) )
             {
-                move_memory(end - size + bm->headroom,
-                            (uint64_t)bm->mod->mod_start << PAGE_SHIFT,
-                            bm->mod->mod_end);
-                bm->mod->mod_start = (end - size) >> PAGE_SHIFT;
-                bm->mod->mod_end += bm->headroom;
+                move_memory(end - size + bm->headroom, bm->start, bm->size);
+                bm->start = (end - size);
+                bm->mod->mod_start = paddr_to_pfn(bm->start);
+                bm->size += bm->headroom;
+                bm->mod->mod_end = bm->size;
                 bm->flags |= BOOTMOD_FLAG_X86_RELOCATED;
             }
         }
@@ -1528,11 +1526,10 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
         panic("Not enough memory to relocate the dom0 kernel image\n");
     for ( i = 0; i < bi->nr_modules; ++i )
     {
-        uint64_t s = (uint64_t)bi->mods[i].mod->mod_start
-                        << PAGE_SHIFT;
+        uint64_t s = (uint64_t)bi->mods[i].start;
 
         reserve_e820_ram(&boot_e820, s,
-                         s + PAGE_ALIGN(bi->mods[i].mod->mod_end));
+                         s + PAGE_ALIGN(bi->mods[i].size));
     }
 
     if ( !xen_phys_start )
@@ -1610,9 +1607,8 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
                 map_e = boot_e820.map[j].addr + boot_e820.map[j].size;
                 for ( j = 0; j < bi->nr_modules; ++j )
                 {
-                    uint64_t end = pfn_to_paddr(
-                                   bi->mods[j].mod->mod_start) +
-                                   bi->mods[j].mod->mod_end;
+                    uint64_t end = bi->mods[j].start +
+                                   bi->mods[j].size;
 
                     if ( map_e < end )
                         map_e = end;
@@ -1686,12 +1682,12 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
 
     for ( i = 0; i < bi->nr_modules; ++i )
     {
-        set_pdx_range(bi->mods[i].mod->mod_start,
-                      bi->mods[i].mod->mod_start +
-                      PFN_UP(bi->mods[i].mod->mod_end));
-        map_pages_to_xen((unsigned long)mfn_to_virt(bi->mods[i].mod->mod_start),
-            _mfn(bi->mods[i].mod->mod_start),
-            PFN_UP(bi->mods[i].mod->mod_end), PAGE_HYPERVISOR);
+        set_pdx_range(paddr_to_pfn(bi->mods[i].start),
+                      paddr_to_pfn(bi->mods[i].start) +
+                      PFN_UP(bi->mods[i].size));
+        map_pages_to_xen((unsigned long)maddr_to_virt(bi->mods[i].start),
+            maddr_to_mfn(bi->mods[i].start),
+            PFN_UP(bi->mods[i].size), PAGE_HYPERVISOR);
     }
 
 #ifdef CONFIG_KEXEC
Signature · 1 line
2.30.2
Reviewed-by on v6 13/44
#35 lore raw

Re: [PATCH v6 13/44] x86/boot: transition relocation calculations to struct boot_module

Quoted 18 lines · Daniel P. Smith

Use struct boot_module fields, start and size, when calculating the relocation address and size. It also ensures that early_mod references are kept in sync.

---
Changes since v5:
- removed unnecessary paddr_to_pfn, allowing condition to collapse to one line
- correct a missed conversion from .mod->mod_start to .start

---
  xen/arch/x86/setup.c | 38 +++++++++++++++++---------------------
  1 file changed, 17 insertions(+), 21 deletions(-)
xen/arch/x86/setup.c +0 -0
index d51b0b03bc97..44cec48fc877 100644

xen/arch/x86/setup.c void asmlinkage __init noreturn __start_xen(unsigned long mbi_p) · line 1529

Quoted 6 lines
xen/arch/x86/setup.c +1 -2
@@ -1528,11 +1526,10 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
          panic("Not enough memory to relocate the dom0 kernel image\n");
      for ( i = 0; i < bi->nr_modules; ++i )
      {
-        uint64_t s = (uint64_t)bi->mods[i].mod->mod_start
-                        << PAGE_SHIFT;
+        uint64_t s = (uint64_t)bi->mods[i].start;

I don't think this cast is necessary.

Quoted 14 lines
xen/arch/x86/setup.c +1 -3
          reserve_e820_ram(&boot_e820, s,
-                         s + PAGE_ALIGN(bi->mods[i].mod->mod_end));
+                         s + PAGE_ALIGN(bi->mods[i].size));
      }
 
      if ( !xen_phys_start )
 
@@ -1686,12 +1682,12 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
 
      for ( i = 0; i < bi->nr_modules; ++i )
      {
-        set_pdx_range(bi->mods[i].mod->mod_start,
-                      bi->mods[i].mod->mod_start +

xen/arch/x86/setup.c void asmlinkage __init noreturn __start_xen(unsigned long mbi_p) · line 1690

Quoted 10 lines
xen/arch/x86/setup.c +6 -4
-                      PFN_UP(bi->mods[i].mod->mod_end));
-        map_pages_to_xen((unsigned long)mfn_to_virt(bi->mods[i].mod->mod_start),
-            _mfn(bi->mods[i].mod->mod_start),
-            PFN_UP(bi->mods[i].mod->mod_end), PAGE_HYPERVISOR);
+        set_pdx_range(paddr_to_pfn(bi->mods[i].start),
+                      paddr_to_pfn(bi->mods[i].start) +
+                      PFN_UP(bi->mods[i].size));
+        map_pages_to_xen((unsigned long)maddr_to_virt(bi->mods[i].start),
+            maddr_to_mfn(bi->mods[i].start),
+            PFN_UP(bi->mods[i].size), PAGE_HYPERVISOR);

I would vertically align all the parameters inside the (.

xen/arch/x86/setup.c void asmlinkage __init noreturn __start_xen(unsigned long mbi_p) · line 1693

Quoted 3 lines
xen/arch/x86/setup.c +0 -0
      }
 
  #ifdef CONFIG_KEXEC

With those:

Regards,
Jason

#36 lore raw

Re: [PATCH v6 13/44] x86/boot: transition relocation calculations to struct boot_module

Quoted 19 lines · Jason Andryuk
Quoted 6 lines · Daniel P. Smith
xen/arch/x86/setup.c +0 -2
@@ -1686,12 +1682,12 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
 
      for ( i = 0; i < bi->nr_modules; ++i )
      {
-        set_pdx_range(bi->mods[i].mod->mod_start,
-                      bi->mods[i].mod->mod_start +

xen/arch/x86/setup.c void asmlinkage __init noreturn __start_xen(unsigned long mbi_p) · line 1690

Quoted 10 lines
xen/arch/x86/setup.c +6 -4
-                      PFN_UP(bi->mods[i].mod->mod_end));
-        map_pages_to_xen((unsigned long)mfn_to_virt(bi->mods[i].mod->mod_start),
-            _mfn(bi->mods[i].mod->mod_start),
-            PFN_UP(bi->mods[i].mod->mod_end), PAGE_HYPERVISOR);
+        set_pdx_range(paddr_to_pfn(bi->mods[i].start),
+                      paddr_to_pfn(bi->mods[i].start) +
+                      PFN_UP(bi->mods[i].size));
+        map_pages_to_xen((unsigned long)maddr_to_virt(bi->mods[i].start),
+            maddr_to_mfn(bi->mods[i].start),
+            PFN_UP(bi->mods[i].size), PAGE_HYPERVISOR);

I would vertically align all the parameters inside the (.

At the very least the two successive calls want formatting the same way. Plus imo the presented formatting of map_pages_to_xen() isn't "legal" anyway, it ought to be

        map_pages_to_xen(
            (unsigned long)maddr_to_virt(bi->mods[i].start),
            maddr_to_mfn(bi->mods[i].start),
            PFN_UP(bi->mods[i].size), PAGE_HYPERVISOR);

(if not doing it the way Jason asked for).

Jan

#37 lore raw

Re: [PATCH v6 13/44] x86/boot: transition relocation calculations to struct boot_module

Quoted 21 lines · Jan Beulich
Quoted 19 lines · Jason Andryuk
Quoted 6 lines · Daniel P. Smith
xen/arch/x86/setup.c +0 -2
@@ -1686,12 +1682,12 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
 
       for ( i = 0; i < bi->nr_modules; ++i )
       {
-        set_pdx_range(bi->mods[i].mod->mod_start,
-                      bi->mods[i].mod->mod_start +

xen/arch/x86/setup.c void asmlinkage __init noreturn __start_xen(unsigned long mbi_p) · line 1690

Quoted 10 lines
xen/arch/x86/setup.c +6 -4
-                      PFN_UP(bi->mods[i].mod->mod_end));
-        map_pages_to_xen((unsigned long)mfn_to_virt(bi->mods[i].mod->mod_start),
-            _mfn(bi->mods[i].mod->mod_start),
-            PFN_UP(bi->mods[i].mod->mod_end), PAGE_HYPERVISOR);
+        set_pdx_range(paddr_to_pfn(bi->mods[i].start),
+                      paddr_to_pfn(bi->mods[i].start) +
+                      PFN_UP(bi->mods[i].size));
+        map_pages_to_xen((unsigned long)maddr_to_virt(bi->mods[i].start),
+            maddr_to_mfn(bi->mods[i].start),
+            PFN_UP(bi->mods[i].size), PAGE_HYPERVISOR);

I would vertically align all the parameters inside the (.

Quoted 8 lines

At the very least the two successive calls want formatting the same way. Plus imo the presented formatting of map_pages_to_xen() isn't "legal" anyway, it ought to be

         map_pages_to_xen(
             (unsigned long)maddr_to_virt(bi->mods[i].start),
             maddr_to_mfn(bi->mods[i].start),
             PFN_UP(bi->mods[i].size), PAGE_HYPERVISOR);

Agreed, will change to the above.

v/r,
dps

#38 lore raw

Re: [PATCH v6 13/44] x86/boot: transition relocation calculations to struct boot_module

In reply to Jason Andryuk
Quoted 19 lines · Jason Andryuk
Quoted 17 lines · Daniel P. Smith

Use struct boot_module fields, start and size, when calculating the relocation address and size. It also ensures that early_mod references are kept in sync.

---
Changes since v5:
- removed unnecessary paddr_to_pfn, allowing condition to collapse to one line
- correct a missed conversion from .mod->mod_start to .start
---
  xen/arch/x86/setup.c | 38 +++++++++++++++++---------------------

  1 file changed, 17 insertions(+), 21 deletions(-)
xen/arch/x86/setup.c +0 -0
index d51b0b03bc97..44cec48fc877 100644
Quoted 10 lines

xen/arch/x86/setup.c void asmlinkage __init noreturn · line 1530

Quoted 8 lines
xen/arch/x86/setup.c +1 -2
@@ -1528,11 +1526,10 @@ void asmlinkage __init noreturn 
 __start_xen(unsigned long mbi_p)
           panic("Not enough memory to relocate the dom0 kernel image\n");
       for ( i = 0; i < bi->nr_modules; ++i )
       {
-        uint64_t s = (uint64_t)bi->mods[i].mod->mod_start
-                        << PAGE_SHIFT;
+        uint64_t s = (uint64_t)bi->mods[i].start;

I don't think this cast is necessary.

Ack.

Quoted 18 lines
Quoted 18 lines
xen/arch/x86/setup.c +2 -7
           reserve_e820_ram(&boot_e820, s,
-                         s + PAGE_ALIGN(bi->mods[i].mod->mod_end));
+                         s + PAGE_ALIGN(bi->mods[i].size));
       }
       if ( !xen_phys_start )
 
@@ -1686,12 +1682,12 @@ void asmlinkage __init noreturn 
 __start_xen(unsigned long mbi_p)
       for ( i = 0; i < bi->nr_modules; ++i )
       {
-        set_pdx_range(bi->mods[i].mod->mod_start,
-                      bi->mods[i].mod->mod_start +
-                      PFN_UP(bi->mods[i].mod->mod_end));
-        map_pages_to_xen((unsigned 
 long)mfn_to_virt(bi->mods[i].mod->mod_start),
-            _mfn(bi->mods[i].mod->mod_start),
-            PFN_UP(bi->mods[i].mod->mod_end), PAGE_HYPERVISOR);
+        set_pdx_range(paddr_to_pfn(bi->mods[i].start),
Quoted 8 lines

xen/arch/x86/setup.c void asmlinkage __init noreturn __start_xen(unsigned long mbi_p) · line 1690

Quoted 6 lines
xen/arch/x86/setup.c +5 -0
+                      paddr_to_pfn(bi->mods[i].start) +
+                      PFN_UP(bi->mods[i].size));
+        map_pages_to_xen((unsigned 
 long)maddr_to_virt(bi->mods[i].start),
+            maddr_to_mfn(bi->mods[i].start),
+            PFN_UP(bi->mods[i].size), PAGE_HYPERVISOR);

I would vertically align all the parameters inside the (.

Ack, though I will be applying the format requested by Jan.

Quoted 2 lines

With those:

Thanks!

v/r,
dps

#39 lore raw

PATCH v6 14/44 x86/boot: introduce boot module interator

In reply to Daniel P. Smith

Provide an iterator to go through boot module array searching based on type.

---
Changes since v5:
- documented help next_boot_module_index
- switch to unsigned int for next_boot_module_index
- changes identified that BOOTMOD_XEN was not supported, so added support

---
 xen/arch/x86/include/asm/bootinfo.h | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)
xen/arch/x86/include/asm/bootinfo.h +28 -1
index 5862054b8cef..3010e6f4af9c 100644
@@ -62,8 +62,35 @@ struct boot_info {
     struct boot_module mods[MAX_NR_BOOTMODS + 1];
 };
 
-#endif /* __XEN_X86_BOOTINFO_H__ */
+/*
+ * next_boot_module_index:
+ *     Finds the next boot module of type t, starting at array index start.
+ *
+ * Returns:
+ *      Success - index in boot_module array
+ *      Failure - a value greater than MAX_NR_BOOTMODS
+ */
+static inline unsigned int __init next_boot_module_index(
+    const struct boot_info *bi, enum bootmod_type t, unsigned int start)
+{
+    unsigned int i;
+
+    if ( t == BOOTMOD_XEN )
+        return MAX_NR_BOOTMODS;
 
+    for ( i = start; i < bi->nr_modules; i++ )
+    {
+        if ( bi->mods[i].type == t )
+            return i;
+    }
+
+    return MAX_NR_BOOTMODS + 1;
+}
+
+#define first_boot_module_index(bi, t)              \
+    next_boot_module_index(bi, t, 0)
+
+#endif /* __XEN_X86_BOOTINFO_H__ */
 /*
  * Local variables:
  * mode: C
Signature · 1 line
2.30.2
#40 lore raw

Re: [PATCH v6 14/44] x86/boot: introduce boot module interator

Quoted 26 lines · Daniel P. Smith

Provide an iterator to go through boot module array searching based on type.

---
Changes since v5:
- documented help next_boot_module_index
- switch to unsigned int for next_boot_module_index
- changes identified that BOOTMOD_XEN was not supported, so added support

---
  xen/arch/x86/include/asm/bootinfo.h | 29 ++++++++++++++++++++++++++++-
  1 file changed, 28 insertions(+), 1 deletion(-)
xen/arch/x86/include/asm/bootinfo.h +5 -1
index 5862054b8cef..3010e6f4af9c 100644
@@ -62,8 +62,35 @@ struct boot_info {
      struct boot_module mods[MAX_NR_BOOTMODS + 1];
  };
 
-#endif /* __XEN_X86_BOOTINFO_H__ */
+/*
+ * next_boot_module_index:
+ *     Finds the next boot module of type t, starting at array index start.
+ *
+ * Returns:

xen/arch/x86/include/asm/bootinfo.h struct boot_info { · line 79

Quoted 10 lines
xen/arch/x86/include/asm/bootinfo.h +10 -0
+ *      Success - index in boot_module array
+ *      Failure - a value greater than MAX_NR_BOOTMODS
+ */
+static inline unsigned int __init next_boot_module_index(
+    const struct boot_info *bi, enum bootmod_type t, unsigned int start)
+{
+    unsigned int i;
+
+    if ( t == BOOTMOD_XEN )
+        return MAX_NR_BOOTMODS;

Your earlier patch "x86/boot: convert mod refs to boot_module mod" put xen at bi->nr_modules. You'll want these to match.

Regards,
Jason

Quoted 17 lines
xen/arch/x86/include/asm/bootinfo.h +13 -0
+    for ( i = start; i < bi->nr_modules; i++ )
+    {
+        if ( bi->mods[i].type == t )
+            return i;
+    }
+
+    return MAX_NR_BOOTMODS + 1;
+}
+
+#define first_boot_module_index(bi, t)              \
+    next_boot_module_index(bi, t, 0)
+
+#endif /* __XEN_X86_BOOTINFO_H__ */
  /*
   * Local variables:
   * mode: C
#41 lore raw

Re: [PATCH v6 14/44] x86/boot: introduce boot module interator

Quoted 31 lines · Jason Andryuk
Quoted 30 lines · Daniel P. Smith

Provide an iterator to go through boot module array searching based on type.

---
Changes since v5:
- documented help next_boot_module_index
- switch to unsigned int for next_boot_module_index
- changes identified that BOOTMOD_XEN was not supported, so added support
---
  xen/arch/x86/include/asm/bootinfo.h | 29 ++++++++++++++++++++++++++++-

  1 file changed, 28 insertions(+), 1 deletion(-)
xen/arch/x86/include/asm/bootinfo.h +3 -1
index 5862054b8cef..3010e6f4af9c 100644
@@ -62,8 +62,35 @@ struct boot_info {
       struct boot_module mods[MAX_NR_BOOTMODS + 1];
   };
-#endif /* __XEN_X86_BOOTINFO_H__ */
+/*
+ * next_boot_module_index:
+ *     Finds the next boot module of type t, starting at array index 

start.
+ *
+ * Returns:
+ *      Success - index in boot_module array
+ *      Failure - a value greater than MAX_NR_BOOTMODS
+ */
+static inline unsigned int __init next_boot_module_index(

Quoted 8 lines

xen/arch/x86/include/asm/bootinfo.h struct boot_info { · line 79

Quoted 6 lines

+    const struct boot_info *bi, enum bootmod_type t, unsigned int start)

xen/arch/x86/include/asm/bootinfo.h +5 -0
+{
+    unsigned int i;
+
+    if ( t == BOOTMOD_XEN )
+        return MAX_NR_BOOTMODS;

Your earlier patch "x86/boot: convert mod refs to boot_module mod" put xen at bi->nr_modules.  You'll want these to match.

Yep.

v/r,
dps

#42 lore raw

PATCH v6 15/44 x86/boot: introduce consumed flag for struct boot_module

In reply to Daniel P. Smith

Allow the tracking of when a boot module has been consumed by a handler in the hypervisor independent of when it is claimed. The instances where the hypervisor does nothing beyond claiming, the dom0 kernel, dom0 ramdisk, and a placeholder for itself, are updated as being consumed at the time of being claimed.

---
Changes since v5:
- first flag assignment can be = instead of |=

---
 xen/arch/x86/include/asm/bootinfo.h | 1 +
 xen/arch/x86/setup.c                | 5 +++++
 2 files changed, 6 insertions(+)
xen/arch/x86/include/asm/bootinfo.h +1 -0
index 3010e6f4af9c..6903ab00ec90 100644
@@ -42,6 +42,7 @@ struct boot_module {
 
     uint32_t flags;
 #define BOOTMOD_FLAG_X86_RELOCATED     (1U << 0)
+#define BOOTMOD_FLAG_X86_CONSUMED      (1U << 1)
 
     paddr_t start;
     size_t size;
xen/arch/x86/setup.c +5 -0
index 44cec48fc877..8261a87d9fb4 100644
@@ -318,6 +318,7 @@ static struct boot_info *__init multiboot_fill_boot_info(unsigned long mbi_p)
 
     /* map the last mb module for xen entry */
     bi->mods[bi->nr_modules].type = BOOTMOD_XEN;
+    bi->mods[bi->nr_modules].flags = BOOTMOD_FLAG_X86_CONSUMED;
 
     return bi;
 }
@@ -1180,6 +1181,7 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
     bitmap_fill(module_map, bi->nr_modules);
     __clear_bit(0, module_map); /* Dom0 kernel is always first */
     bi->mods[0].type = BOOTMOD_KERNEL;
+    bi->mods[0].flags = BOOTMOD_FLAG_X86_CONSUMED;
 
     if ( pvh_boot )
     {
@@ -2068,7 +2070,10 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
 
     initrdidx = find_first_bit(module_map, bi->nr_modules);
     if ( initrdidx < bi->nr_modules )
+    {
         bi->mods[initrdidx].type = BOOTMOD_RAMDISK;
+        bi->mods[initrdidx].flags |= BOOTMOD_FLAG_X86_CONSUMED;
+    }
     if ( bitmap_weight(module_map, bi->nr_modules) > 1 )
         printk(XENLOG_WARNING
                "Multiple initrd candidates, picking module #%u\n",
Signature · 1 line
2.30.2
#43 lore raw

PATCH v6 16/44 x86/boot: split bootstrap_map_addr() out of bootstrap_map()

In reply to Daniel P. Smith

From: Andrew Cooper <[email protected]>

Using an interface based on addresses directly, not modules.

No functional change.

---
Changes since v5:
- moved bootstrap_map_addr() to being static to setup.c

---
 xen/arch/x86/setup.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)
xen/arch/x86/setup.c +13 -6
index 8261a87d9fb4..852454c161ee 100644
@@ -442,24 +442,22 @@ 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)
+static void *__init bootstrap_map_addr(paddr_t start, paddr_t end)
 {
     static unsigned long __initdata map_cur = BOOTSTRAP_MAP_BASE;
-    uint64_t start, end, mask = (1L << L2_PAGETABLE_SHIFT) - 1;
+    uint64_t 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 end ? maddr_to_virt(start) : NULL;
 
-    if ( !mod )
+    if ( !end )
     {
         destroy_xen_mappings(BOOTSTRAP_MAP_BASE, BOOTSTRAP_MAP_LIMIT);
         map_cur = BOOTSTRAP_MAP_BASE;
         return NULL;
     }
 
-    start = (uint64_t)mod->mod_start << PAGE_SHIFT;
-    end = start + mod->mod_end;
     if ( start >= end )
         return NULL;
 
@@ -475,6 +473,15 @@ void *__init bootstrap_map(const module_t *mod)
     return ret;
 }
 
+void *__init bootstrap_map(const module_t *mod)
+{
+    if ( !mod )
+        return bootstrap_map_addr(0, 0);
+
+    return bootstrap_map_addr(pfn_to_paddr(mod->mod_start),
+                              pfn_to_paddr(mod->mod_start) + mod->mod_end);
+}
+
 static void __init move_memory(
     uint64_t dst, uint64_t src, unsigned int size)
 {
Signature · 1 line
2.30.2
#44 lore raw

PATCH v6 17/44 x86/boot: convert microcode loading to consume struct boot_info

In reply to Daniel P. Smith

Convert the microcode loading functions to take struct boot_info, and then using struct boot_module to map and check for microcode. To keep the changes focused, continue using the struct mod to hold the reference to the microcode that is used by the late microcode logic.

To support loading the microcode boot module in to the bootstrap map, introduce bootstrap_map_bm() for mapping struct boot_module.

---
Changes since v5:
- moved bootstrap_map_bm definition to this commit

---
 xen/arch/x86/cpu/microcode/core.c    | 37 +++++++++++++---------------
 xen/arch/x86/include/asm/bootinfo.h  |  1 +
 xen/arch/x86/include/asm/microcode.h | 14 ++++++-----
 xen/arch/x86/include/asm/setup.h     |  2 ++
 xen/arch/x86/setup.c                 | 12 +++++++--
 5 files changed, 38 insertions(+), 28 deletions(-)
xen/arch/x86/cpu/microcode/core.c +17 -20
index 8564e4d2c94c..22fea80bc97e 100644
@@ -35,6 +35,7 @@
 #include <xen/watchdog.h>
 
 #include <asm/apic.h>
+#include <asm/bootinfo.h>
 #include <asm/cpu-policy.h>
 #include <asm/nmi.h>
 #include <asm/processor.h>
@@ -153,10 +154,8 @@ static int __init cf_check parse_ucode(const char *s)
 custom_param("ucode", parse_ucode);
 
 static void __init microcode_scan_module(
-    unsigned long *module_map,
-    const multiboot_info_t *mbi)
+    unsigned long *module_map, const struct boot_info *bi)
 {
-    module_t *mod = (module_t *)__va(mbi->mods_addr);
     uint64_t *_blob_start;
     unsigned long _blob_size;
     struct cpio_data cd;
@@ -178,16 +177,16 @@ static void __init microcode_scan_module(
     /*
      * Try all modules and see whichever could be the microcode blob.
      */
-    for ( i = 1 /* Ignore dom0 kernel */; i < mbi->mods_count; i++ )
+    for ( i = 1 /* Ignore dom0 kernel */; i < bi->nr_modules; i++ )
     {
         if ( !test_bit(i, module_map) )
             continue;
 
-        _blob_start = bootstrap_map(&mod[i]);
-        _blob_size = mod[i].mod_end;
+        _blob_start = bootstrap_map_bm(&bi->mods[i]);
+        _blob_size = bi->mods[i].size;
         if ( !_blob_start )
         {
-            printk("Could not map multiboot module #%d (size: %ld)\n",
+            printk("Could not map boot module #%d (size: %ld)\n",
                    i, _blob_size);
             continue;
         }
@@ -205,20 +204,18 @@ static void __init microcode_scan_module(
 }
 
 static void __init microcode_grab_module(
-    unsigned long *module_map,
-    const multiboot_info_t *mbi)
+    unsigned long *module_map, struct boot_info *bi)
 {
-    module_t *mod = (module_t *)__va(mbi->mods_addr);
-
     if ( ucode_mod_idx < 0 )
-        ucode_mod_idx += mbi->mods_count;
-    if ( ucode_mod_idx <= 0 || ucode_mod_idx >= mbi->mods_count ||
+        ucode_mod_idx += bi->nr_modules;
+    if ( ucode_mod_idx <= 0 || ucode_mod_idx >= bi->nr_modules ||
          !__test_and_clear_bit(ucode_mod_idx, module_map) )
         goto scan;
-    ucode_mod = mod[ucode_mod_idx];
+    bi->mods[ucode_mod_idx].type = BOOTMOD_MICROCODE;
+    ucode_mod = *bi->mods[ucode_mod_idx].mod;
 scan:
     if ( ucode_scan )
-        microcode_scan_module(module_map, mbi);
+        microcode_scan_module(module_map, bi);
 }
 
 static struct microcode_ops __ro_after_init ucode_ops;
@@ -822,8 +819,8 @@ 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(
+    unsigned long *module_map, const struct boot_info *bi)
 {
     int rc = 0;
 
@@ -832,7 +829,7 @@ 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(module_map, bi);
 
     if ( ucode_mod.mod_end )
         rc = early_update_cache(bootstrap_map(&ucode_mod),
@@ -879,7 +876,7 @@ static int __init early_microcode_update_cpu(void)
 }
 
 int __init early_microcode_init(unsigned long *module_map,
-                                const struct multiboot_info *mbi)
+                                struct boot_info *bi)
 {
     const struct cpuinfo_x86 *c = &boot_cpu_data;
     int rc = 0;
@@ -922,7 +919,7 @@ int __init early_microcode_init(unsigned long *module_map,
         return -ENODEV;
     }
 
-    microcode_grab_module(module_map, mbi);
+    microcode_grab_module(module_map, bi);
 
     if ( ucode_mod.mod_end || ucode_blob.size )
         rc = early_microcode_update_cpu();
xen/arch/x86/include/asm/bootinfo.h +1 -0
index 6903ab00ec90..19a0ed16ab27 100644
@@ -20,6 +20,7 @@ enum bootmod_type {
     BOOTMOD_XEN,
     BOOTMOD_KERNEL,
     BOOTMOD_RAMDISK,
+    BOOTMOD_MICROCODE,
 };
 
 struct boot_module {
xen/arch/x86/include/asm/microcode.h +8 -6
index 57c08205d475..495c8f7a7cc5 100644
@@ -4,6 +4,8 @@
 #include <xen/types.h>
 #include <xen/percpu.h>
 
+#include <asm/bootinfo.h>
+
 #include <public/xen.h>
 
 struct multiboot_info;
@@ -22,12 +24,12 @@ struct cpu_signature {
 DECLARE_PER_CPU(struct cpu_signature, cpu_sig);
 
 void microcode_set_module(unsigned int idx);
-int microcode_update(XEN_GUEST_HANDLE(const_void) buf,
-                     unsigned long len, unsigned int flags);
-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 microcode_update(
+    XEN_GUEST_HANDLE(const_void) buf, unsigned long len, unsigned int flags);
+int early_microcode_init(
+    unsigned long *module_map, struct boot_info *bi);
+int microcode_init_cache(
+    unsigned long *module_map, const struct boot_info *bi);
 int microcode_update_one(void);
 
 #endif /* ASM_X86__MICROCODE_H */
xen/arch/x86/include/asm/setup.h +2 -0
index 3d189521189d..729f68ca23b8 100644
@@ -2,6 +2,7 @@
 #define __X86_SETUP_H_
 
 #include <xen/multiboot.h>
+#include <asm/bootinfo.h>
 #include <asm/numa.h>
 
 extern const char __2M_text_start[], __2M_text_end[];
@@ -37,6 +38,7 @@ extern struct boot_info xen_boot_info;
 unsigned long initial_images_nrpages(nodeid_t node);
 void discard_initial_images(void);
 void *bootstrap_map(const module_t *mod);
+void *bootstrap_map_bm(const struct boot_module *bm);
 
 int remove_xen_ranges(struct rangeset *r);
 
xen/arch/x86/setup.c +10 -2
index 852454c161ee..04de06ba1400 100644
@@ -482,6 +482,14 @@ void *__init bootstrap_map(const module_t *mod)
                               pfn_to_paddr(mod->mod_start) + mod->mod_end);
 }
 
+void *__init bootstrap_map_bm(const struct boot_module *bm)
+{
+    if ( !bm )
+        return bootstrap_map_addr(0, 0);
+
+    return bootstrap_map_addr(bm->start, bm->start + bm->size);
+}
+
 static void __init move_memory(
     uint64_t dst, uint64_t src, unsigned int size)
 {
@@ -1377,7 +1385,7 @@ void asmlinkage __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(module_map, bi);
 
     if ( xen_phys_start )
     {
@@ -1929,7 +1937,7 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
 
     timer_init();
 
-    microcode_init_cache(module_map, mbi); /* Needs xmalloc() */
+    microcode_init_cache(module_map, bi); /* Needs xmalloc() */
 
     tsx_init(); /* Needs microcode.  May change HLE/RTM feature bits. */
 
Signature · 1 line
2.30.2
#45 lore raw

Re: [PATCH v6 17/44] x86/boot: convert microcode loading to consume struct boot_info

Quoted 5 lines · Daniel P. Smith
xen/arch/x86/cpu/microcode/core.c +0 -0
index 8564e4d2c94c..22fea80bc97e 100644

xen/arch/x86/cpu/microcode/core.c static void __init microcode_scan_module( · line 184

Quoted 9 lines
xen/arch/x86/cpu/microcode/core.c +1 -1
@@ -178,16 +177,16 @@ static void __init microcode_scan_module(
     /*
      * Try all modules and see whichever could be the microcode blob.
      */
-    for ( i = 1 /* Ignore dom0 kernel */; i < mbi->mods_count; i++ )
+    for ( i = 1 /* Ignore dom0 kernel */; i < bi->nr_modules; i++ )
     {
         if ( !test_bit(i, module_map) )
             continue;
 

Somewhere in this series, it would be nice to purge the these "module 0 is dom0" special cases.  I'm not sure where best in the series to do it, and it may not be here.

Later, in "x86/boot: remove module_map usage from microcode loading" you convert this test_bit() into a type != UNKNOWN check, but the pattern is used elsewhere too.

How about a for_each_unknown_module(bi, bm) helper?  (which at this point can even use module_map in scope).

If you introduce it at this point, then I think the churn later in the series reduces marginally, and I think it removes all the "careful not to look at dom0" special cases.

~Andrew

#46 lore raw

Re: [PATCH v6 17/44] x86/boot: convert microcode loading to consume struct boot_info

Quoted 20 lines · Andrew Cooper
Quoted 5 lines · Daniel P. Smith
xen/arch/x86/cpu/microcode/core.c +0 -0
index 8564e4d2c94c..22fea80bc97e 100644

xen/arch/x86/cpu/microcode/core.c static void __init microcode_scan_module( · line 184

Quoted 9 lines
xen/arch/x86/cpu/microcode/core.c +1 -1
@@ -178,16 +177,16 @@ static void __init microcode_scan_module(
      /*
       * Try all modules and see whichever could be the microcode blob.
       */
-    for ( i = 1 /* Ignore dom0 kernel */; i < mbi->mods_count; i++ )
+    for ( i = 1 /* Ignore dom0 kernel */; i < bi->nr_modules; i++ )
      {
          if ( !test_bit(i, module_map) )
              continue;
 

Somewhere in this series, it would be nice to purge the these "module 0 is dom0" special cases.  I'm not sure where best in the series to do it, and it may not be here.

Quoted 6 lines

Later, in "x86/boot: remove module_map usage from microcode loading" you convert this test_bit() into a type != UNKNOWN check, but the pattern is used elsewhere too.

How about a for_each_unknown_module(bi, bm) helper?  (which at this point can even use module_map in scope).

So I do have the first_boot_module_index() iterator which I am using to effectively open-code your suggested for_each_unknown_module() in one or two places. I can introduce that helper when I first do the open coding, though I would like to make it a little more generic. I would prefer to do it as for_each_bootmodule(bi, bm, type). There is a scenario/enhancement that I would like to get to that may require doing an iteration on a type other than BOOTMOD_UNKNOWN.

Would you be okay with leaving the module_map usage at this point and changing over to the for_each_bootmodule() when it is dropped? As I see it, otherwise I would have to make the helper initially work with module_map only to turn around and drop it when module_map goes away. At least to me, seems like unnecessary churn unless you see a way without causing the churn in the helper.

Quoted 3 lines

If you introduce it at this point, then I think the churn later in the series reduces marginally, and I think it removes all the "careful not to look at dom0" special cases.

In the end, yes I want to get a way from that, once domain builder is introduced, it will be possible to provide the boot modules in any order.

v/r,
dps

#47 lore raw

Re: [PATCH v6 17/44] x86/boot: convert microcode loading to consume struct boot_info

Quoted 38 lines · Daniel P. Smith
Quoted 21 lines · Andrew Cooper
Quoted 14 lines · Daniel P. Smith
xen/arch/x86/cpu/microcode/core.c +1 -1
index 8564e4d2c94c..22fea80bc97e 100644
@@ -178,16 +177,16 @@ static void __init microcode_scan_module(
       /*
        * Try all modules and see whichever could be the microcode blob.
        */
-    for ( i = 1 /* Ignore dom0 kernel */; i < mbi->mods_count; i++ )
+    for ( i = 1 /* Ignore dom0 kernel */; i < bi->nr_modules; i++ )
       {
           if ( !test_bit(i, module_map) )
               continue;
Quoted 1 line

Somewhere in this series, it would be nice to purge the these "module 0 is dom0" special cases.  I'm not sure where best in the series to do it, and it may not be here.

Quoted 6 lines

Later, in "x86/boot: remove module_map usage from microcode loading" you convert this test_bit() into a type != UNKNOWN check, but the pattern is used elsewhere too.

How about a for_each_unknown_module(bi, bm) helper?  (which at this point can even use module_map in scope).

So I do have the first_boot_module_index() iterator which I am using to effectively open-code your suggested for_each_unknown_module() in one or two places. I can introduce that helper when I first do the open coding,
though I would like to make it a little more generic. I would prefer to do it as for_each_bootmodule(bi, bm, type). There is a scenario/enhancement that I would like to get to that may require doing an iteration on a type other than BOOTMOD_UNKNOWN.

Quoted 6 lines

Would you be okay with leaving the module_map usage at this point and changing over to the for_each_bootmodule() when it is dropped? As I see it, otherwise I would have to make the helper initially work with module_map only to turn around and drop it when module_map goes away. At least to me, seems like unnecessary churn unless you see a way without causing the churn in the helper.

I'll leave it to your judgement about when is best to introduce the helper.  You know the series better than I do.

~Andrew

#48 lore raw

PATCH v6 18/44 x86/boot: convert late microcode loading to struct boot_module

In reply to Daniel P. Smith

Remove the use of struct mod to hold the reference for the microcode, converting the code to work with a struct boot_module.

---
 xen/arch/x86/cpu/microcode/core.c | 31 +++++++++++++++----------------
 1 file changed, 15 insertions(+), 16 deletions(-)
xen/arch/x86/cpu/microcode/core.c +15 -16
index 22fea80bc97e..7bcc17e0ab2f 100644
@@ -28,7 +28,6 @@
 #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>
@@ -59,7 +58,7 @@
  */
 #define MICROCODE_UPDATE_TIMEOUT_US 1000000
 
-static module_t __initdata ucode_mod;
+static struct boot_module __initdata ucode_mod;
 static signed int __initdata ucode_mod_idx;
 static bool __initdata ucode_mod_forced;
 static unsigned int nr_cores;
@@ -98,7 +97,7 @@ struct patch_with_flags {
 
 static struct ucode_mod_blob __initdata ucode_blob;
 /*
- * By default we will NOT parse the multiboot modules to see if there is
+ * By default we will NOT parse the boot modules to see if there is
  * cpio image with the microcode images.
  */
 static bool __initdata ucode_scan;
@@ -199,7 +198,7 @@ static void __init microcode_scan_module(
             ucode_blob.data = cd.data;
             break;
         }
-        bootstrap_map(NULL);
+        bootstrap_map_bm(NULL);
     }
 }
 
@@ -212,7 +211,7 @@ static void __init microcode_grab_module(
          !__test_and_clear_bit(ucode_mod_idx, module_map) )
         goto scan;
     bi->mods[ucode_mod_idx].type = BOOTMOD_MICROCODE;
-    ucode_mod = *bi->mods[ucode_mod_idx].mod;
+    ucode_mod = bi->mods[ucode_mod_idx];
 scan:
     if ( ucode_scan )
         microcode_scan_module(module_map, bi);
@@ -766,14 +765,14 @@ static int __init cf_check microcode_init(void)
      */
     if ( ucode_blob.size )
     {
-        bootstrap_map(NULL);
+        bootstrap_map_bm(NULL);
         ucode_blob.size = 0;
         ucode_blob.data = NULL;
     }
-    else if ( ucode_mod.mod_end )
+    else if ( ucode_mod.size )
     {
-        bootstrap_map(NULL);
-        ucode_mod.mod_end = 0;
+        bootstrap_map_bm(NULL);
+        ucode_mod.size = 0;
     }
 
     return 0;
@@ -831,9 +830,9 @@ int __init microcode_init_cache(
         /* Need to rescan the modules because they might have been relocated */
         microcode_scan_module(module_map, bi);
 
-    if ( ucode_mod.mod_end )
-        rc = early_update_cache(bootstrap_map(&ucode_mod),
-                                ucode_mod.mod_end);
+    if ( ucode_mod.size )
+        rc = early_update_cache(bootstrap_map_bm(&ucode_mod),
+                                ucode_mod.size);
     else if ( ucode_blob.size )
         rc = early_update_cache(ucode_blob.data, ucode_blob.size);
 
@@ -852,10 +851,10 @@ static int __init early_microcode_update_cpu(void)
         len = ucode_blob.size;
         data = ucode_blob.data;
     }
-    else if ( ucode_mod.mod_end )
+    else if ( ucode_mod.size )
     {
-        len = ucode_mod.mod_end;
-        data = bootstrap_map(&ucode_mod);
+        len = ucode_mod.size;
+        data = bootstrap_map_bm(&ucode_mod);
     }
 
     if ( !data )
@@ -921,7 +920,7 @@ int __init early_microcode_init(unsigned long *module_map,
 
     microcode_grab_module(module_map, bi);
 
-    if ( ucode_mod.mod_end || ucode_blob.size )
+    if ( ucode_mod.size || ucode_blob.size )
         rc = early_microcode_update_cpu();
 
     /*
Signature · 1 line
2.30.2
#49 lore raw

PATCH v6 19/44 x86/boot: use consumed boot module flag for microcode

In reply to Daniel P. Smith

To track if the microcode boot module was loaded, a copy of the boot module is kept. The size element of this copy is set to zero as the indicator that the microcode was loaded. A side effect is that the modules have to be rescanned to find the boot module post-relocation, so the cache copy can be created.

Use the consumed boot module flag to track the loading of the microcode boot module. This removes the need to manipulate the boot module size element, no longer requiring the copy, thus allowing it to be replaced by a reference. As a result it is no longer necessary to rescan the boot modules after relocation has occurred.

---
 xen/arch/x86/cpu/microcode/core.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
xen/arch/x86/cpu/microcode/core.c +14 -14
index 7bcc17e0ab2f..5b42aad2fdd0 100644
@@ -58,7 +58,7 @@
  */
 #define MICROCODE_UPDATE_TIMEOUT_US 1000000
 
-static struct boot_module __initdata ucode_mod;
+static struct boot_module __initdata *ucode_mod;
 static signed int __initdata ucode_mod_idx;
 static bool __initdata ucode_mod_forced;
 static unsigned int nr_cores;
@@ -211,7 +211,7 @@ static void __init microcode_grab_module(
          !__test_and_clear_bit(ucode_mod_idx, module_map) )
         goto scan;
     bi->mods[ucode_mod_idx].type = BOOTMOD_MICROCODE;
-    ucode_mod = bi->mods[ucode_mod_idx];
+    ucode_mod = &bi->mods[ucode_mod_idx];
 scan:
     if ( ucode_scan )
         microcode_scan_module(module_map, bi);
@@ -769,10 +769,10 @@ static int __init cf_check microcode_init(void)
         ucode_blob.size = 0;
         ucode_blob.data = NULL;
     }
-    else if ( ucode_mod.size )
+    else if ( ucode_mod && !(ucode_mod->flags & BOOTMOD_FLAG_X86_CONSUMED) )
     {
         bootstrap_map_bm(NULL);
-        ucode_mod.size = 0;
+        ucode_mod->flags |= BOOTMOD_FLAG_X86_CONSUMED;
     }
 
     return 0;
@@ -826,14 +826,14 @@ int __init microcode_init_cache(
     if ( !ucode_ops.apply_microcode )
         return -ENODEV;
 
-    if ( ucode_scan )
-        /* Need to rescan the modules because they might have been relocated */
+    /* Scan if microcode was not detected earlier */
+    if ( !ucode_mod )
         microcode_scan_module(module_map, bi);
 
-    if ( ucode_mod.size )
-        rc = early_update_cache(bootstrap_map_bm(&ucode_mod),
-                                ucode_mod.size);
-    else if ( ucode_blob.size )
+    if ( ucode_mod && !(ucode_mod->flags & BOOTMOD_FLAG_X86_CONSUMED) )
+        rc = early_update_cache(bootstrap_map_bm(ucode_mod),
+                                ucode_mod->size);
+    else if ( ucode_mod && ucode_blob.size )
         rc = early_update_cache(ucode_blob.data, ucode_blob.size);
 
     return rc;
@@ -851,10 +851,10 @@ static int __init early_microcode_update_cpu(void)
         len = ucode_blob.size;
         data = ucode_blob.data;
     }
-    else if ( ucode_mod.size )
+    else if ( ucode_mod && !(ucode_mod->flags & BOOTMOD_FLAG_X86_CONSUMED) )
     {
-        len = ucode_mod.size;
-        data = bootstrap_map_bm(&ucode_mod);
+        len = ucode_mod->size;
+        data = bootstrap_map_bm(ucode_mod);
     }
 
     if ( !data )
@@ -920,7 +920,7 @@ int __init early_microcode_init(unsigned long *module_map,
 
     microcode_grab_module(module_map, bi);
 
-    if ( ucode_mod.size || ucode_blob.size )
+    if ( ucode_mod || ucode_blob.size )
         rc = early_microcode_update_cpu();
 
     /*
Signature · 1 line
2.30.2
#50 lore raw

PATCH v6 20/44 x86/boot: convert xsm policy loading to struct boot_module

In reply to Daniel P. Smith

Iterate through the unclaimed struct boot_module to see if any are an XSM FLASK policy. If one is located, mark it as an xsm policy.

---
Changes since v5:
- replaced bootstrap_map with bootstrap_map_bm
- make init function definitions consistent in dropping const on *bi

---
 xen/arch/x86/include/asm/bootinfo.h |  1 +
 xen/arch/x86/setup.c                |  2 +-
 xen/include/xsm/xsm.h               | 11 +++++++----
 xen/xsm/xsm_core.c                  | 17 +++++++++++++----
 xen/xsm/xsm_policy.c                | 15 ++++++++-------
 5 files changed, 30 insertions(+), 16 deletions(-)
xen/arch/x86/include/asm/bootinfo.h +1 -0
index 19a0ed16ab27..8b63eb27d6dd 100644
@@ -21,6 +21,7 @@ enum bootmod_type {
     BOOTMOD_KERNEL,
     BOOTMOD_RAMDISK,
     BOOTMOD_MICROCODE,
+    BOOTMOD_XSM_POLICY,
 };
 
 struct boot_module {
xen/arch/x86/setup.c +1 -1
index 04de06ba1400..a4ddcb908626 100644
@@ -1863,7 +1863,7 @@ void asmlinkage __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_multiboot_init(module_map, bi);
 
     /*
      * IOMMU-related ACPI table parsing may require some of the system domains
xen/include/xsm/xsm.h +7 -4
index 627c0d2731af..f155d10e718c 100644
@@ -17,7 +17,10 @@
 
 #include <xen/alternative-call.h>
 #include <xen/sched.h>
-#include <xen/multiboot.h>
+
+#ifdef CONFIG_MULTIBOOT
+#include <asm/bootinfo.h>
+#endif
 
 /* policy magic number (defined by XSM_MAGIC) */
 typedef uint32_t xsm_magic_t;
@@ -779,9 +782,9 @@ static inline int xsm_argo_send(const struct domain *d, const struct domain *t)
 
 #ifdef CONFIG_MULTIBOOT
 int xsm_multiboot_init(
-    unsigned long *module_map, const multiboot_info_t *mbi);
+    unsigned long *module_map, struct boot_info *bi);
 int xsm_multiboot_policy_init(
-    unsigned long *module_map, const multiboot_info_t *mbi,
+    unsigned long *module_map, struct boot_info *bi,
     void **policy_buffer, size_t *policy_size);
 #endif
 
@@ -829,7 +832,7 @@ static const inline struct xsm_ops *silo_init(void)
 
 #ifdef CONFIG_MULTIBOOT
 static inline int xsm_multiboot_init (
-    unsigned long *module_map, const multiboot_info_t *mbi)
+    unsigned long *module_map, struct boot_info *bi)
 {
     return 0;
 }
xen/xsm/xsm_core.c +13 -4
index eaa028109bde..6f034f70428d 100644
@@ -21,6 +21,7 @@
 #ifdef CONFIG_XSM
 
 #ifdef CONFIG_MULTIBOOT
+#include <asm/bootinfo.h>
 #include <asm/setup.h>
 #endif
 
@@ -140,7 +141,7 @@ static int __init xsm_core_init(const void *policy_buffer, size_t policy_size)
 
 #ifdef CONFIG_MULTIBOOT
 int __init xsm_multiboot_init(
-    unsigned long *module_map, const multiboot_info_t *mbi)
+    unsigned long *module_map, struct boot_info *bi)
 {
     int ret = 0;
     void *policy_buffer = NULL;
@@ -150,18 +151,26 @@ int __init xsm_multiboot_init(
 
     if ( XSM_MAGIC )
     {
-        ret = xsm_multiboot_policy_init(module_map, mbi, &policy_buffer,
+        ret = xsm_multiboot_policy_init(module_map, bi, &policy_buffer,
                                         &policy_size);
         if ( ret )
         {
-            bootstrap_map(NULL);
+            bootstrap_map_bm(NULL);
             printk(XENLOG_ERR "Error %d initializing XSM policy\n", ret);
             return -EINVAL;
         }
     }
 
     ret = xsm_core_init(policy_buffer, policy_size);
-    bootstrap_map(NULL);
+    if ( ret == 0 )
+    {
+        int idx = first_boot_module_index(bi, BOOTMOD_XSM_POLICY);
+
+        /* If the policy was loaded from a boot module, mark it consumed */
+        if ( idx >= 0 )
+            bi->mods[idx].flags |= BOOTMOD_FLAG_X86_CONSUMED;
+    }
+    bootstrap_map_bm(NULL);
 
     return 0;
 }
xen/xsm/xsm_policy.c +8 -7
index 8dafbc93810f..921bb254b9d1 100644
@@ -21,6 +21,7 @@
 #include <xsm/xsm.h>
 #ifdef CONFIG_MULTIBOOT
 #include <xen/multiboot.h>
+#include <asm/bootinfo.h>
 #include <asm/setup.h>
 #endif
 #include <xen/bitops.h>
@@ -31,11 +32,10 @@
 
 #ifdef CONFIG_MULTIBOOT
 int __init xsm_multiboot_policy_init(
-    unsigned long *module_map, const multiboot_info_t *mbi,
+    unsigned long *module_map, struct boot_info *bi,
     void **policy_buffer, size_t *policy_size)
 {
     int i;
-    module_t *mod = (module_t *)__va(mbi->mods_addr);
     int rc = 0;
     u32 *_policy_start;
     unsigned long _policy_len;
@@ -44,13 +44,13 @@ int __init xsm_multiboot_policy_init(
      * 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-- )
+    for ( i = bi->nr_modules-1; i >= 1; i-- )
     {
-        if ( !test_bit(i, module_map) )
+        if ( bi->mods[i].type != BOOTMOD_UNKNOWN )
             continue;
 
-        _policy_start = bootstrap_map(mod + i);
-        _policy_len   = mod[i].mod_end;
+        _policy_start = bootstrap_map_bm(&bi->mods[i]);
+        _policy_len   = bi->mods[i].size;
 
         if ( (xsm_magic_t)(*_policy_start) == XSM_MAGIC )
         {
@@ -61,11 +61,12 @@ int __init xsm_multiboot_policy_init(
                    _policy_len,_policy_start);
 
             __clear_bit(i, module_map);
+            bi->mods[i].type = BOOTMOD_XSM_POLICY;
             break;
 
         }
 
-        bootstrap_map(NULL);
+        bootstrap_map_bm(NULL);
     }
 
     return rc;
Signature · 1 line
2.30.2
#51 lore raw

PATCH v6 21/44 x86/boot: convert ramdisk locating to struct boot_module

In reply to Daniel P. Smith

Locate the first unclaimed struct boot_module and mark it as ramdisk. If there are any remaining unclaimed struct boot_module instances, report to the console. In the change, the new boot module iterator is used to find the initrd index, which returns a signed int. Switch initrdidx from unsigned to signed.

---
Changes since v5:
- adjusted initrdidx check for prior changes to boot module search function

---
 xen/arch/x86/setup.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)
xen/arch/x86/setup.c +13 -6
index a4ddcb908626..6ba8a893daf0 100644
@@ -2083,16 +2083,23 @@ void asmlinkage __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, bi->nr_modules);
-    if ( initrdidx < bi->nr_modules )
+    /*
+     * At this point all capabilities that consume boot modules should have
+     * claimed their boot modules. Find the first unclaimed boot module and
+     * claim it as the initrd ramdisk. Do a second search to see if there are
+     * any remaining unclaimed boot modules, and report them as unusued initrd
+     * candidates.
+     */
+    initrdidx = first_boot_module_index(bi, BOOTMOD_UNKNOWN);
+    if ( initrdidx < MAX_NR_BOOTMODS )
     {
         bi->mods[initrdidx].type = BOOTMOD_RAMDISK;
         bi->mods[initrdidx].flags |= BOOTMOD_FLAG_X86_CONSUMED;
+        if ( first_boot_module_index(bi, BOOTMOD_UNKNOWN) < MAX_NR_BOOTMODS )
+            printk(XENLOG_WARNING
+                   "Multiple initrd candidates, picking module #%u\n",
+                   initrdidx);
     }
-    if ( bitmap_weight(module_map, bi->nr_modules) > 1 )
-        printk(XENLOG_WARNING
-               "Multiple initrd candidates, picking module #%u\n",
-               initrdidx);
 
     /*
      * We're going to setup domain0 using the module(s) that we stashed safely
Signature · 1 line
2.30.2
#52 lore raw

PATCH v6 22/44 x86/boot: remove module_map usage from microcode loading

In reply to Daniel P. Smith

With all consumers of module_map converted, remove usage of it by the microcode loading logic.

---
Changes since v5:
- dropped unnecessary parens

---
 xen/arch/x86/cpu/microcode/core.c    | 22 +++++++++-------------
 xen/arch/x86/include/asm/microcode.h |  6 ++----
 xen/arch/x86/setup.c                 |  4 ++--
 3 files changed, 13 insertions(+), 19 deletions(-)
xen/arch/x86/cpu/microcode/core.c +9 -13
index 5b42aad2fdd0..23984c69bce7 100644
@@ -152,8 +152,7 @@ static int __init cf_check parse_ucode(const char *s)
 }
 custom_param("ucode", parse_ucode);
 
-static void __init microcode_scan_module(
-    unsigned long *module_map, const struct boot_info *bi)
+static void __init microcode_scan_module(const struct boot_info *bi)
 {
     uint64_t *_blob_start;
     unsigned long _blob_size;
@@ -178,7 +177,7 @@ static void __init microcode_scan_module(
      */
     for ( i = 1 /* Ignore dom0 kernel */; i < bi->nr_modules; i++ )
     {
-        if ( !test_bit(i, module_map) )
+        if ( bi->mods[i].type != BOOTMOD_UNKNOWN )
             continue;
 
         _blob_start = bootstrap_map_bm(&bi->mods[i]);
@@ -202,19 +201,18 @@ static void __init microcode_scan_module(
     }
 }
 
-static void __init microcode_grab_module(
-    unsigned long *module_map, struct boot_info *bi)
+static void __init microcode_grab_module(struct boot_info *bi)
 {
     if ( ucode_mod_idx < 0 )
         ucode_mod_idx += bi->nr_modules;
     if ( ucode_mod_idx <= 0 || ucode_mod_idx >= bi->nr_modules ||
-         !__test_and_clear_bit(ucode_mod_idx, module_map) )
+         bi->mods[ucode_mod_idx].type != BOOTMOD_UNKNOWN )
         goto scan;
     bi->mods[ucode_mod_idx].type = BOOTMOD_MICROCODE;
     ucode_mod = &bi->mods[ucode_mod_idx];
 scan:
     if ( ucode_scan )
-        microcode_scan_module(module_map, bi);
+        microcode_scan_module(bi);
 }
 
 static struct microcode_ops __ro_after_init ucode_ops;
@@ -818,8 +816,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 boot_info *bi)
+int __init microcode_init_cache(const struct boot_info *bi)
 {
     int rc = 0;
 
@@ -828,7 +825,7 @@ int __init microcode_init_cache(
 
     /* Scan if microcode was not detected earlier */
     if ( !ucode_mod )
-        microcode_scan_module(module_map, bi);
+        microcode_scan_module(bi);
 
     if ( ucode_mod && !(ucode_mod->flags & BOOTMOD_FLAG_X86_CONSUMED) )
         rc = early_update_cache(bootstrap_map_bm(ucode_mod),
@@ -874,8 +871,7 @@ static int __init early_microcode_update_cpu(void)
     return microcode_update_cpu(patch, 0);
 }
 
-int __init early_microcode_init(unsigned long *module_map,
-                                struct boot_info *bi)
+int __init early_microcode_init(struct boot_info *bi)
 {
     const struct cpuinfo_x86 *c = &boot_cpu_data;
     int rc = 0;
@@ -918,7 +914,7 @@ int __init early_microcode_init(unsigned long *module_map,
         return -ENODEV;
     }
 
-    microcode_grab_module(module_map, bi);
+    microcode_grab_module(bi);
 
     if ( ucode_mod || ucode_blob.size )
         rc = early_microcode_update_cpu();
xen/arch/x86/include/asm/microcode.h +2 -4
index 495c8f7a7cc5..84e0eb487244 100644
@@ -26,10 +26,8 @@ DECLARE_PER_CPU(struct cpu_signature, cpu_sig);
 void microcode_set_module(unsigned int idx);
 int microcode_update(
     XEN_GUEST_HANDLE(const_void) buf, unsigned long len, unsigned int flags);
-int early_microcode_init(
-    unsigned long *module_map, struct boot_info *bi);
-int microcode_init_cache(
-    unsigned long *module_map, const struct boot_info *bi);
+int early_microcode_init(struct boot_info *bi);
+int microcode_init_cache(const struct boot_info *bi);
 int microcode_update_one(void);
 
 #endif /* ASM_X86__MICROCODE_H */
xen/arch/x86/setup.c +2 -2
index 6ba8a893daf0..e1763d7e6548 100644
@@ -1385,7 +1385,7 @@ void asmlinkage __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, bi);
+    early_microcode_init(bi);
 
     if ( xen_phys_start )
     {
@@ -1937,7 +1937,7 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
 
     timer_init();
 
-    microcode_init_cache(module_map, bi); /* Needs xmalloc() */
+    microcode_init_cache(bi); /* Needs xmalloc() */
 
     tsx_init(); /* Needs microcode.  May change HLE/RTM feature bits. */
 
Signature · 1 line
2.30.2
#53 lore raw

PATCH v6 23/44 x86/boot: remove module_map usage from xsm policy loading

In reply to Daniel P. Smith

---
Changes since v5:
- adjust comment to coding style

---
 xen/arch/x86/setup.c  | 2 +-
 xen/include/xsm/xsm.h | 9 +++------
 xen/xsm/xsm_core.c    | 6 ++----
 xen/xsm/xsm_policy.c  | 9 ++-------
 4 files changed, 8 insertions(+), 18 deletions(-)
xen/arch/x86/setup.c +1 -1
index e1763d7e6548..91110ba96f73 100644
@@ -1863,7 +1863,7 @@ void asmlinkage __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, bi);
+    xsm_multiboot_init(bi);
 
     /*
      * IOMMU-related ACPI table parsing may require some of the system domains
xen/include/xsm/xsm.h +3 -6
index f155d10e718c..791936e5285b 100644
@@ -781,11 +781,9 @@ 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, struct boot_info *bi);
+int xsm_multiboot_init(struct boot_info *bi);
 int xsm_multiboot_policy_init(
-    unsigned long *module_map, struct boot_info *bi,
-    void **policy_buffer, size_t *policy_size);
+    struct boot_info *bi, void **policy_buffer, size_t *policy_size);
 #endif
 
 #ifdef CONFIG_HAS_DEVICE_TREE
@@ -831,8 +829,7 @@ 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, struct boot_info *bi)
+static inline int xsm_multiboot_init(struct boot_info *bi)
 {
     return 0;
 }
xen/xsm/xsm_core.c +2 -4
index 6f034f70428d..50b665759aad 100644
@@ -140,8 +140,7 @@ static int __init xsm_core_init(const void *policy_buffer, size_t policy_size)
 }
 
 #ifdef CONFIG_MULTIBOOT
-int __init xsm_multiboot_init(
-    unsigned long *module_map, struct boot_info *bi)
+int __init xsm_multiboot_init(struct boot_info *bi)
 {
     int ret = 0;
     void *policy_buffer = NULL;
@@ -151,8 +150,7 @@ int __init xsm_multiboot_init(
 
     if ( XSM_MAGIC )
     {
-        ret = xsm_multiboot_policy_init(module_map, bi, &policy_buffer,
-                                        &policy_size);
+        ret = xsm_multiboot_policy_init(bi, &policy_buffer, &policy_size);
         if ( ret )
         {
             bootstrap_map_bm(NULL);
xen/xsm/xsm_policy.c +2 -7
index 921bb254b9d1..453c81df4a2d 100644
@@ -32,18 +32,14 @@
 
 #ifdef CONFIG_MULTIBOOT
 int __init xsm_multiboot_policy_init(
-    unsigned long *module_map, struct boot_info *bi,
-    void **policy_buffer, size_t *policy_size)
+    struct boot_info *bi, void **policy_buffer, size_t *policy_size)
 {
     int i;
     int rc = 0;
     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.
-     */
+    /* Try all modules and see whichever could be the binary policy. */
     for ( i = bi->nr_modules-1; i >= 1; i-- )
     {
         if ( bi->mods[i].type != BOOTMOD_UNKNOWN )
@@ -60,7 +56,6 @@ int __init xsm_multiboot_policy_init(
             printk("Policy len %#lx, start at %p.\n",
                    _policy_len,_policy_start);
 
-            __clear_bit(i, module_map);
             bi->mods[i].type = BOOTMOD_XSM_POLICY;
             break;
 
Signature · 1 line
2.30.2
#54 lore raw

PATCH v6 24/44 x86/boot: remove module_map usage by ramdisk loading

In reply to Daniel P. Smith

The ramdisk loading is the last user of module_map, remove its usage and any remaining remnants of module_map.

---
Changes since v5:
- set excessive module check down to MAX_NR_BOOTMODS

---
 xen/arch/x86/setup.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
xen/arch/x86/setup.c +5 -6
index 91110ba96f73..08319f871a5d 100644
@@ -1036,7 +1036,7 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
     struct boot_info *bi;
     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;
@@ -1186,15 +1186,14 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
         panic("dom0 kernel not specified. Check bootloader configuration\n");
 
     /* Check that we don't have a silly number of modules. */
-    if ( bi->nr_modules > sizeof(module_map) * 8 )
+    if ( bi->nr_modules > MAX_NR_BOOTMODS )
     {
-        bi->nr_modules = sizeof(module_map) * 8;
-        printk("Excessive boot modules - using the first %u only\n",
+        bi->nr_modules = MAX_NR_BOOTMODS;
+        printk("Excessive multiboot modules - using the first %u only\n",
                bi->nr_modules);
     }
 
-    bitmap_fill(module_map, bi->nr_modules);
-    __clear_bit(0, module_map); /* Dom0 kernel is always first */
+    /* Dom0 kernel is always first */
     bi->mods[0].type = BOOTMOD_KERNEL;
     bi->mods[0].flags = BOOTMOD_FLAG_X86_CONSUMED;
 
Signature · 1 line
2.30.2
#55 lore raw

PATCH v6 25/44 x86/boot: convert create_dom0 to use boot info

In reply to Daniel P. Smith

This commit changes create_dom0 to no longer take the individual components and take struct boot_info instead. Internally, it is changed to locate the kernel and ramdisk details from struct boot_info.

---
Changes since v5:
- change headroom back to unsigned long
- make mod_idx unsigned int

---
 xen/arch/x86/setup.c | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)
xen/arch/x86/setup.c +17 -9
index 08319f871a5d..5bc667b8b4d4 100644
@@ -945,10 +945,8 @@ static unsigned int __init copy_bios_e820(struct e820entry *map, unsigned int li
     return n;
 }
 
-static struct domain *__init create_dom0(const module_t *image,
-                                         unsigned long headroom,
-                                         module_t *initrd, const char *kextra,
-                                         const char *loader)
+static struct domain *__init create_dom0(const struct boot_info *bi,
+                                         const char *kextra)
 {
     static char __initdata cmdline[MAX_GUEST_CMDLINE];
 
@@ -963,9 +961,22 @@ static struct domain *__init create_dom0(const module_t *image,
             .misc_flags = opt_dom0_msr_relaxed ? XEN_X86_MSR_RELAXED : 0,
         },
     };
+    unsigned long headroom;
+    unsigned int mod_idx = first_boot_module_index(bi, BOOTMOD_RAMDISK);
+    module_t *image, *initrd;
     struct domain *d;
     domid_t domid;
 
+    /* Map boot_module to mb1 module for dom0 */
+    image = bi->mods[0].mod;
+    headroom = bi->mods[0].headroom;
+
+    /* Map boot_module to mb1 module for initrd */
+    if ( mod_idx < 0 )
+        initrd = NULL;
+    else
+        initrd = bi->mods[mod_idx].mod;
+
     if ( opt_dom0_pvh )
     {
         dom0_cfg.flags |= (XEN_DOMCTL_CDF_hvm |
@@ -994,7 +1005,7 @@ static struct domain *__init create_dom0(const module_t *image,
     if ( image->string || kextra )
     {
         if ( image->string )
-            safe_strcpy(cmdline, cmdline_cook(__va(image->string), loader));
+            safe_strcpy(cmdline, cmdline_cook(__va(image->string), bi->loader));
 
         if ( kextra )
             /* kextra always includes exactly one leading space. */
@@ -2104,10 +2115,7 @@ void asmlinkage __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(bi->mods[0].mod, bi->mods[0].headroom,
-                       initrdidx < bi->nr_modules ? bi->mods[initrdidx].mod
-                                                  : NULL,
-                       kextra, bi->loader);
+    dom0 = create_dom0(bi, kextra);
     if ( !dom0 )
         panic("Could not set up DOM0 guest OS\n");
 
Signature · 1 line
2.30.2
#56 lore raw

PATCH v6 26/44 x86/boot: convert construct_dom0 to use struct boot_module

In reply to Daniel P. Smith

The construct_dom0 function is converted to consume struct boot_module instances for the kernel and ramdisk. With this change, it is no longer necessary for the internal use of struct mod by create_dom0, so they are changed to struct boot_module.

---
 xen/arch/x86/dom0_build.c        | 12 +++++++-----
 xen/arch/x86/include/asm/setup.h |  6 ++----
 xen/arch/x86/setup.c             | 19 +++++++++----------
 3 files changed, 18 insertions(+), 19 deletions(-)
xen/arch/x86/dom0_build.c +7 -5
index 8d56705a0861..1eff3192f72d 100644
@@ -13,6 +13,7 @@
 #include <xen/softirq.h>
 
 #include <asm/amd.h>
+#include <asm/bootinfo.h>
 #include <asm/dom0_build.h>
 #include <asm/guest.h>
 #include <asm/hpet.h>
@@ -596,9 +597,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,
-                          const char *cmdline)
+int __init construct_dom0(struct domain *d, const struct boot_module *image,
+                          struct boot_module *initrd, const char *cmdline)
 {
     int rc;
 
@@ -610,9 +610,11 @@ 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->mod, image->headroom, initrd->mod,
+                                cmdline);
     else if ( is_pv_domain(d) )
-        rc = dom0_construct_pv(d, image, image_headroom, initrd, cmdline);
+        rc = dom0_construct_pv(d, image->mod, image->headroom, initrd->mod,
+                               cmdline);
     else
         panic("Cannot construct Dom0. No guest interface available\n");
 
xen/arch/x86/include/asm/setup.h +2 -4
index 729f68ca23b8..72d183e8a4de 100644
@@ -27,10 +27,8 @@ void subarch_init_memory(void);
 void init_IRQ(void);
 
 int construct_dom0(
-    struct domain *d,
-    const module_t *image, unsigned long image_headroom,
-    module_t *initrd,
-    const char *cmdline);
+    struct domain *d, const struct boot_module *image,
+    struct boot_module *initrd, const char *cmdline);
 void setup_io_bitmap(struct domain *d);
 
 extern struct boot_info xen_boot_info;
xen/arch/x86/setup.c +9 -10
index 5bc667b8b4d4..e7573bc3f40b 100644
@@ -945,7 +945,7 @@ static unsigned int __init copy_bios_e820(struct e820entry *map, unsigned int li
     return n;
 }
 
-static struct domain *__init create_dom0(const struct boot_info *bi,
+static struct domain *__init create_dom0(struct boot_info *bi,
                                          const char *kextra)
 {
     static char __initdata cmdline[MAX_GUEST_CMDLINE];
@@ -961,21 +961,19 @@ static struct domain *__init create_dom0(const struct boot_info *bi,
             .misc_flags = opt_dom0_msr_relaxed ? XEN_X86_MSR_RELAXED : 0,
         },
     };
-    unsigned long headroom;
     unsigned int mod_idx = first_boot_module_index(bi, BOOTMOD_RAMDISK);
-    module_t *image, *initrd;
+    struct boot_module *image, *initrd;
     struct domain *d;
     domid_t domid;
 
     /* Map boot_module to mb1 module for dom0 */
-    image = bi->mods[0].mod;
-    headroom = bi->mods[0].headroom;
+    image = &bi->mods[0];
 
     /* Map boot_module to mb1 module for initrd */
     if ( mod_idx < 0 )
         initrd = NULL;
     else
-        initrd = bi->mods[mod_idx].mod;
+        initrd = &bi->mods[mod_idx];
 
     if ( opt_dom0_pvh )
     {
@@ -1002,10 +1000,11 @@ static struct domain *__init create_dom0(const struct boot_info *bi,
         panic("Error creating d%uv0\n", domid);
 
     /* Grab the DOM0 command line. */
-    if ( image->string || kextra )
+    if ( image->mod->string || kextra )
     {
-        if ( image->string )
-            safe_strcpy(cmdline, cmdline_cook(__va(image->string), bi->loader));
+        if ( image->mod->string )
+            safe_strcpy(cmdline, cmdline_cook(__va(image->mod->string),
+                        bi->loader));
 
         if ( kextra )
             /* kextra always includes exactly one leading space. */
@@ -1028,7 +1027,7 @@ static struct domain *__init create_dom0(const struct boot_info *bi,
         }
     }
 
-    if ( construct_dom0(d, image, headroom, initrd, cmdline) != 0 )
+    if ( construct_dom0(d, image, initrd, cmdline) != 0 )
         panic("Could not construct domain 0\n");
 
     return d;
Signature · 1 line
2.30.2
#57 lore raw

PATCH v6 27/44 x86/boot: relocate kextra into boot info

In reply to Daniel P. Smith

Move kextra into struct boot_info, thus no longer needed to be passed as a parameter to create_dom0.

---
 xen/arch/x86/include/asm/bootinfo.h |  1 +
 xen/arch/x86/setup.c                | 12 ++++++------
 2 files changed, 7 insertions(+), 6 deletions(-)
xen/arch/x86/include/asm/bootinfo.h +1 -0
index 8b63eb27d6dd..8dcda42b3400 100644
@@ -57,6 +57,7 @@ struct boot_module {
 struct boot_info {
     const char *loader;
     const char *cmdline;
+    const char *kextra;
 
     paddr_t memmap_addr;
     size_t memmap_length;
xen/arch/x86/setup.c +6 -6
index e7573bc3f40b..2574d2f1fdb4 100644
@@ -945,8 +945,7 @@ static unsigned int __init copy_bios_e820(struct e820entry *map, unsigned int li
     return n;
 }
 
-static struct domain *__init create_dom0(struct boot_info *bi,
-                                         const char *kextra)
+static struct domain *__init create_dom0(struct boot_info *bi)
 {
     static char __initdata cmdline[MAX_GUEST_CMDLINE];
 
@@ -1000,15 +999,15 @@ static struct domain *__init create_dom0(struct boot_info *bi,
         panic("Error creating d%uv0\n", domid);
 
     /* Grab the DOM0 command line. */
-    if ( image->mod->string || kextra )
+    if ( image->mod->string || bi->kextra )
     {
         if ( image->mod->string )
             safe_strcpy(cmdline, cmdline_cook(__va(image->mod->string),
                         bi->loader));
 
-        if ( kextra )
+        if ( bi->kextra )
             /* kextra always includes exactly one leading space. */
-            safe_strcat(cmdline, kextra);
+            safe_strcat(cmdline, bi->kextra);
 
         /* Append any extra parameters. */
         if ( skip_ioapic_setup && !strstr(cmdline, "noapic") )
@@ -1102,6 +1101,7 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
         *kextra = '\0';
         kextra += 3;
         while ( kextra[1] == ' ' ) kextra++;
+        bi->kextra = kextra;
     }
     cmdline_parse(bi->cmdline);
 
@@ -2114,7 +2114,7 @@ void asmlinkage __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(bi, kextra);
+    dom0 = create_dom0(bi);
     if ( !dom0 )
         panic("Could not set up DOM0 guest OS\n");
 
Signature · 1 line
2.30.2
#58 lore raw

PATCH v6 28/44 x86/boot: add cmdline to struct boot_module

In reply to Daniel P. Smith

Add a char pointer field, cmdline, to struct boot_module to hold the address pointed to by the string field of struct mod. This removes the need to use the early_mod field to get to the dom0 kernel command line.

---
Changes since v5:
- changed boot_module element cmdline to paddr_t

---
 xen/arch/x86/include/asm/bootinfo.h | 2 ++
 xen/arch/x86/setup.c                | 9 ++++++---
 2 files changed, 8 insertions(+), 3 deletions(-)
xen/arch/x86/include/asm/bootinfo.h +2 -0
index 8dcda42b3400..24c2f37c7b11 100644
@@ -46,6 +46,8 @@ struct boot_module {
 #define BOOTMOD_FLAG_X86_RELOCATED     (1U << 0)
 #define BOOTMOD_FLAG_X86_CONSUMED      (1U << 1)
 
+    paddr_t cmdline;
+
     paddr_t start;
     size_t size;
 };
xen/arch/x86/setup.c +6 -3
index 2574d2f1fdb4..e6f1208d5807 100644
@@ -312,6 +312,8 @@ static struct boot_info *__init multiboot_fill_boot_info(unsigned long mbi_p)
     {
         bi->mods[i].mod = &mods[i];
 
+        bi->mods[i].cmdline = (paddr_t)mods[i].string;
+
         bi->mods[i].start = (paddr_t)mods[i].mod_start;
         bi->mods[i].size = mods[i].mod_end - mods[i].mod_start;
     }
@@ -999,10 +1001,11 @@ static struct domain *__init create_dom0(struct boot_info *bi)
         panic("Error creating d%uv0\n", domid);
 
     /* Grab the DOM0 command line. */
-    if ( image->mod->string || bi->kextra )
+    if ( image->cmdline || bi->kextra )
     {
-        if ( image->mod->string )
-            safe_strcpy(cmdline, cmdline_cook(__va(image->mod->string),
+        if ( image->cmdline )
+            safe_strcpy(cmdline,
+                        cmdline_cook(__va(image->cmdline),
                         bi->loader));
 
         if ( bi->kextra )
Signature · 1 line
2.30.2
#59 lore raw

PATCH v6 29/44 x86/boot: convert dom0_construct_pv image param to struct boot_module

In reply to Daniel P. Smith

This changes the type for the image parameter of dom0_construct_pv to be struct boot_module. Removing the usage of early_mod field for kernel module.

---
Changes since v5:
- replaced bootstrap_map(NULL) with bootstrap_map_bm

---
 xen/arch/x86/dom0_build.c             |  3 +--
 xen/arch/x86/include/asm/dom0_build.h |  7 +++----
 xen/arch/x86/pv/dom0_build.c          | 16 +++++++---------
 3 files changed, 11 insertions(+), 15 deletions(-)
xen/arch/x86/dom0_build.c +1 -2
index 1eff3192f72d..54db578dd29f 100644
@@ -613,8 +613,7 @@ int __init construct_dom0(struct domain *d, const struct boot_module *image,
         rc = dom0_construct_pvh(d, image->mod, image->headroom, initrd->mod,
                                 cmdline);
     else if ( is_pv_domain(d) )
-        rc = dom0_construct_pv(d, image->mod, image->headroom, initrd->mod,
-                               cmdline);
+        rc = dom0_construct_pv(d, image, initrd->mod, cmdline);
     else
         panic("Cannot construct Dom0. No guest interface available\n");
 
xen/arch/x86/include/asm/dom0_build.h +3 -4
index 107c1ff98367..a1f36f7d360d 100644
@@ -13,10 +13,9 @@ 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,
-                      const char *cmdline);
+int dom0_construct_pv(
+    struct domain *d, const struct boot_module *image,
+    module_t *initrd, const char *cmdline);
 
 int dom0_construct_pvh(struct domain *d, const module_t *image,
                        unsigned long image_headroom,
xen/arch/x86/pv/dom0_build.c +7 -9
index 262edb6bf2f0..f59597e50a11 100644
@@ -355,8 +355,7 @@ static struct page_info * __init alloc_chunk(struct domain *d,
 }
 
 static int __init dom0_construct(struct domain *d,
-                                 const module_t *image,
-                                 unsigned long image_headroom,
+                                 const struct boot_module *image,
                                  module_t *initrd,
                                  const char *cmdline)
 {
@@ -374,9 +373,9 @@ static int __init dom0_construct(struct domain *d,
     unsigned int flush_flags = 0;
     start_info_t *si;
     struct vcpu *v = d->vcpu[0];
-    void *image_base = bootstrap_map(image);
-    unsigned long image_len = image->mod_end;
-    void *image_start = image_base + image_headroom;
+    void *image_base = bootstrap_map_bm(image);
+    unsigned long image_len = image->size;
+    void *image_start = image_base + image->headroom;
     unsigned long initrd_len = initrd ? initrd->mod_end : 0;
     l4_pgentry_t *l4tab = NULL, *l4start = NULL;
     l3_pgentry_t *l3tab = NULL, *l3start = NULL;
@@ -830,7 +829,7 @@ static int __init dom0_construct(struct domain *d,
         printk("Failed to load the kernel binary\n");
         goto out;
     }
-    bootstrap_map(NULL);
+    bootstrap_map_bm(NULL);
 
     if ( UNSET_ADDR != parms.virt_hypercall )
     {
@@ -1052,8 +1051,7 @@ out:
 }
 
 int __init dom0_construct_pv(struct domain *d,
-                             const module_t *image,
-                             unsigned long image_headroom,
+                             const struct boot_module *image,
                              module_t *initrd,
                              const char *cmdline)
 {
@@ -1072,7 +1070,7 @@ int __init dom0_construct_pv(struct domain *d,
         write_cr4(read_cr4() & ~X86_CR4_SMAP);
     }
 
-    rc = dom0_construct(d, image, image_headroom, initrd, cmdline);
+    rc = dom0_construct(d, image, initrd, cmdline);
 
     if ( boot_cpu_has(X86_FEATURE_XEN_SMAP) )
     {
Signature · 1 line
2.30.2
#60 lore raw

PATCH v6 30/44 x86/boot: convert dom0_construct_pv initrd param to struct boot_module

In reply to Daniel P. Smith

This changes the type for the initrd parameter of dom0_construct_pv to be struct boot_module. This conversion requires several adjustments throughout dom0_construct_pv to account for the type change. Removes the usage of early_mod field for ramdisk module.

---
Changes since v5:
- changed initrd_mfn initialization to _mfn(0)

---
 xen/arch/x86/dom0_build.c             |  2 +-
 xen/arch/x86/include/asm/dom0_build.h |  2 +-
 xen/arch/x86/pv/dom0_build.c          | 29 +++++++++++++++------------
 3 files changed, 18 insertions(+), 15 deletions(-)
xen/arch/x86/dom0_build.c +1 -1
index 54db578dd29f..1d05ee53a6d8 100644
@@ -613,7 +613,7 @@ int __init construct_dom0(struct domain *d, const struct boot_module *image,
         rc = dom0_construct_pvh(d, image->mod, image->headroom, initrd->mod,
                                 cmdline);
     else if ( is_pv_domain(d) )
-        rc = dom0_construct_pv(d, image, initrd->mod, cmdline);
+        rc = dom0_construct_pv(d, image, initrd, cmdline);
     else
         panic("Cannot construct Dom0. No guest interface available\n");
 
xen/arch/x86/include/asm/dom0_build.h +1 -1
index a1f36f7d360d..2ce5ea3851af 100644
@@ -15,7 +15,7 @@ int dom0_setup_permissions(struct domain *d);
 
 int dom0_construct_pv(
     struct domain *d, const struct boot_module *image,
-    module_t *initrd, const char *cmdline);
+    struct boot_module *initrd, const char *cmdline);
 
 int dom0_construct_pvh(struct domain *d, const module_t *image,
                        unsigned long image_headroom,
xen/arch/x86/pv/dom0_build.c +16 -13
index f59597e50a11..5e7b543d0cbe 100644
@@ -356,7 +356,7 @@ static struct page_info * __init alloc_chunk(struct domain *d,
 
 static int __init dom0_construct(struct domain *d,
                                  const struct boot_module *image,
-                                 module_t *initrd,
+                                 struct boot_module *initrd,
                                  const char *cmdline)
 {
     int i, rc, order, machine;
@@ -367,7 +367,8 @@ static int __init dom0_construct(struct domain *d,
     unsigned long nr_pt_pages;
     unsigned long alloc_spfn;
     unsigned long alloc_epfn;
-    unsigned long initrd_pfn = -1, initrd_mfn = 0;
+    unsigned long initrd_pfn = -1;
+    mfn_t  initrd_mfn = _mfn(0);
     unsigned long count;
     struct page_info *page = NULL;
     unsigned int flush_flags = 0;
@@ -376,7 +377,7 @@ static int __init dom0_construct(struct domain *d,
     void *image_base = bootstrap_map_bm(image);
     unsigned long image_len = image->size;
     void *image_start = image_base + image->headroom;
-    unsigned long initrd_len = initrd ? initrd->mod_end : 0;
+    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;
@@ -612,7 +613,8 @@ static int __init dom0_construct(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 = maddr_to_mfn(initrd->start);
+        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 +629,13 @@ static int __init dom0_construct(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 = initrd->start;
             init_domheap_pages(mpt_alloc,
                                mpt_alloc + PAGE_ALIGN(initrd_len));
-            initrd->mod_start = initrd_mfn = mfn_x(page_to_mfn(page));
+            initrd_mfn = page_to_mfn(page);
+            initrd->start = mfn_to_maddr(initrd_mfn);
         }
         else
         {
@@ -640,9 +643,9 @@ static int __init dom0_construct(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)),
+        iommu_memory_setup(d, "initrd", mfn_to_page(initrd_mfn),
                            PFN_UP(initrd_len), &flush_flags);
     }
 
@@ -654,7 +657,7 @@ static int __init dom0_construct(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);
     }
@@ -763,7 +766,7 @@ static int __init dom0_construct(struct domain *d,
         if ( count < initrd_pfn || count >= initrd_pfn + PFN_UP(initrd_len) )
             mfn = pfn++;
         else
-            mfn = initrd_mfn++;
+            mfn = mfn_x(initrd_mfn) + 1;
         *l1tab = l1e_from_pfn(mfn, compat ? COMPAT_L1_PROT : L1_PROT);
         l1tab++;
 
@@ -882,7 +885,7 @@ static int __init dom0_construct(struct domain *d,
         if ( pfn >= initrd_pfn )
         {
             if ( pfn < initrd_pfn + PFN_UP(initrd_len) )
-                mfn = initrd->mod_start + (pfn - initrd_pfn);
+                mfn = paddr_to_pfn(initrd->start) + (pfn - initrd_pfn);
             else
                 mfn -= PFN_UP(initrd_len);
         }
@@ -1052,7 +1055,7 @@ out:
 
 int __init dom0_construct_pv(struct domain *d,
                              const struct boot_module *image,
-                             module_t *initrd,
+                             struct boot_module *initrd,
                              const char *cmdline)
 {
     int rc;
Signature · 1 line
2.30.2
#61 lore raw

PATCH v6 31/44 x86/boot: convert dom0_construct_pvh to struct boot_module

In reply to Daniel P. Smith

This changes both the kernel and ramdisk parameters over to struct boot_module.

---
 xen/arch/x86/dom0_build.c             |  3 +--
 xen/arch/x86/hvm/dom0_build.c         | 11 +++++------
 xen/arch/x86/include/asm/dom0_build.h |  7 +++----
 3 files changed, 9 insertions(+), 12 deletions(-)
xen/arch/x86/dom0_build.c +1 -2
index 1d05ee53a6d8..71b2e3afc1a1 100644
@@ -610,8 +610,7 @@ int __init construct_dom0(struct domain *d, const struct boot_module *image,
     process_pending_softirqs();
 
     if ( is_hvm_domain(d) )
-        rc = dom0_construct_pvh(d, image->mod, image->headroom, initrd->mod,
-                                cmdline);
+        rc = dom0_construct_pvh(d, image, initrd, cmdline);
     else if ( is_pv_domain(d) )
         rc = dom0_construct_pv(d, image, initrd, cmdline);
     else
xen/arch/x86/hvm/dom0_build.c +5 -6
index 3dd913bdb029..beaa1d492077 100644
@@ -1300,10 +1300,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,
-                              const char *cmdline)
+int __init dom0_construct_pvh(
+    struct domain *d, const struct boot_module *image,
+    struct boot_module *initrd, const char *cmdline)
 {
     paddr_t entry, start_info;
     int rc;
@@ -1347,8 +1346,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),
-                         cmdline, &entry, &start_info);
+    rc = pvh_load_kernel(d, image->mod, image->headroom, initrd->mod,
+                         bootstrap_map_bm(image), cmdline, &entry, &start_info);
     if ( rc )
     {
         printk("Failed to load Dom0 kernel\n");
xen/arch/x86/include/asm/dom0_build.h +3 -4
index 2ce5ea3851af..8f7b37f3d308 100644
@@ -17,10 +17,9 @@ int dom0_construct_pv(
     struct domain *d, const struct boot_module *image,
     struct boot_module *initrd, const char *cmdline);
 
-int dom0_construct_pvh(struct domain *d, const module_t *image,
-                       unsigned long image_headroom,
-                       module_t *initrd,
-                       const char *cmdline);
+int dom0_construct_pvh(
+    struct domain *d, const struct boot_module *image,
+    struct boot_module *initrd, const char *cmdline);
 
 unsigned long dom0_paging_pages(const struct domain *d,
                                 unsigned long nr_pages);
Signature · 1 line
2.30.2
#62 lore raw

PATCH v6 32/44 x86/boot: convert pvh_load_kernel to struct boot_module

In reply to Daniel P. Smith

This changes both the kernel and ramdisk parameters over to struct boot_module.

---
 xen/arch/x86/hvm/dom0_build.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)
xen/arch/x86/hvm/dom0_build.c +12 -13
index beaa1d492077..a3fd5e762dc4 100644
@@ -642,15 +642,14 @@ static bool __init check_and_adjust_load_address(
     return true;
 }
 
-static int __init pvh_load_kernel(struct domain *d, const module_t *image,
-                                  unsigned long image_headroom,
-                                  module_t *initrd, void *image_base,
-                                  const 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,
+    const char *cmdline, paddr_t *entry, paddr_t *start_info_addr)
 {
-    void *image_start = image_base + image_headroom;
-    unsigned long image_len = image->mod_end;
-    unsigned long initrd_len = initrd ? initrd->mod_end : 0;
+    void *image_start = image_base + image->headroom;
+    unsigned long image_len = image->size;
+    unsigned long initrd_len = initrd ? initrd->size : 0;
     struct elf_binary elf;
     struct elf_dom_parms parms;
     paddr_t last_addr;
@@ -725,7 +724,7 @@ 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),
+        rc = hvm_copy_to_guest_phys(last_addr, maddr_to_virt(initrd->start),
                                     initrd_len, v);
         if ( rc )
         {
@@ -736,9 +735,9 @@ static int __init pvh_load_kernel(struct domain *d, const module_t *image,
         mod.paddr = last_addr;
         mod.size = initrd_len;
         last_addr += ROUNDUP(initrd_len, elf_64bit(&elf) ? 8 : 4);
-        if ( initrd->string )
+        if ( initrd->cmdline )
         {
-            char *str = __va(initrd->string);
+            char *str = __va((unsigned long)initrd->cmdline);
             size_t len = strlen(str) + 1;
 
             rc = hvm_copy_to_guest_phys(last_addr, str, len, v);
@@ -1346,8 +1345,8 @@ int __init dom0_construct_pvh(
         return rc;
     }
 
-    rc = pvh_load_kernel(d, image->mod, image->headroom, initrd->mod,
-                         bootstrap_map_bm(image), cmdline, &entry, &start_info);
+    rc = pvh_load_kernel(d, image, initrd, bootstrap_map_bm(image), cmdline,
+                         &entry, &start_info);
     if ( rc )
     {
         printk("Failed to load Dom0 kernel\n");
Signature · 1 line
2.30.2
#63 lore raw

PATCH v6 33/44 x86/boot: convert initial_images to struct boot_module

In reply to Daniel P. Smith

The variable initial_images is used for tracking the boot modules passed in by the boot loader. Convert to a struct boot_module and adjust the code that uses it accordingly.

---
Changes since v5:
- coding style changes

---
 xen/arch/x86/setup.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
xen/arch/x86/setup.c +7 -10
index e6f1208d5807..f5cd7eeb157c 100644
@@ -276,7 +276,7 @@ custom_param("acpi", parse_acpi_param);
 
 static const char *cmdline_cook(const char *p, const char *loader_name);
 
-static const module_t *__initdata initial_images;
+static const struct boot_module *__initdata initial_images;
 
 struct boot_info __initdata xen_boot_info;
 
@@ -335,8 +335,8 @@ unsigned long __init initial_images_nrpages(nodeid_t node)
 
     for ( nr = i = 0; i < bi->nr_modules; ++i )
     {
-        unsigned long start = initial_images[i].mod_start;
-        unsigned long end = start + PFN_UP(initial_images[i].mod_end);
+        unsigned long start = initial_images[i].mod->mod_start;
+        unsigned long end = start + PFN_UP(initial_images[i].mod->mod_end);
 
         if ( end > node_start && node_end > start )
             nr += min(node_end, end) - max(node_start, start);
@@ -352,10 +352,11 @@ void __init discard_initial_images(void)
 
     for ( i = 0; i < bi->nr_modules; ++i )
     {
-        uint64_t start = (uint64_t)initial_images[i].mod_start << PAGE_SHIFT;
+        uint64_t start =
+            (uint64_t)initial_images[i].mod->mod_start << PAGE_SHIFT;
 
         init_domheap_pages(start,
-                           start + PAGE_ALIGN(initial_images[i].mod_end));
+                           start + PAGE_ALIGN(initial_images[i].mod->mod_end));
     }
 
     bi->nr_modules = 0;
@@ -1379,11 +1380,7 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
     set_kexec_crash_area_size((u64)nr_pages << PAGE_SHIFT);
     kexec_reserve_area();
 
-    /*
-     * The field bi->mods[0].mod points to the first element of the module_t
-     * array.
-     */
-    initial_images = bi->mods[0].mod;
+    initial_images = bi->mods;
 
     for ( i = 0; i < bi->nr_modules; i++ )
     {
Signature · 1 line
2.30.2
#64 lore raw

PATCH v6 34/44 x86/boot: drop the use of initial_images unit global

In reply to Daniel P. Smith

---

Changes since v5:
- coding style changes

---
 xen/arch/x86/setup.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)
xen/arch/x86/setup.c +4 -10
index f5cd7eeb157c..f8b9c164c1cb 100644
@@ -276,8 +276,6 @@ custom_param("acpi", parse_acpi_param);
 
 static const char *cmdline_cook(const char *p, const char *loader_name);
 
-static const struct boot_module *__initdata initial_images;
-
 struct boot_info __initdata xen_boot_info;
 
 static struct boot_info *__init multiboot_fill_boot_info(unsigned long mbi_p)
@@ -335,8 +333,8 @@ unsigned long __init initial_images_nrpages(nodeid_t node)
 
     for ( nr = i = 0; i < bi->nr_modules; ++i )
     {
-        unsigned long start = initial_images[i].mod->mod_start;
-        unsigned long end = start + PFN_UP(initial_images[i].mod->mod_end);
+        unsigned long start = bi->mods[i].mod->mod_start;
+        unsigned long end = start + PFN_UP(bi->mods[i].mod->mod_end);
 
         if ( end > node_start && node_end > start )
             nr += min(node_end, end) - max(node_start, start);
@@ -353,14 +351,12 @@ void __init discard_initial_images(void)
     for ( i = 0; i < bi->nr_modules; ++i )
     {
         uint64_t start =
-            (uint64_t)initial_images[i].mod->mod_start << PAGE_SHIFT;
+            (uint64_t)bi->mods[i].mod->mod_start << PAGE_SHIFT;
 
-        init_domheap_pages(start,
-                           start + PAGE_ALIGN(initial_images[i].mod->mod_end));
+        init_domheap_pages(start, start + PAGE_ALIGN(bi->mods[i].mod->mod_end));
     }
 
     bi->nr_modules = 0;
-    initial_images = NULL;
 }
 
 static void __init init_idle_domain(void)
@@ -1380,8 +1376,6 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
     set_kexec_crash_area_size((u64)nr_pages << PAGE_SHIFT);
     kexec_reserve_area();
 
-    initial_images = bi->mods;
-
     for ( i = 0; i < bi->nr_modules; i++ )
     {
         if ( bi->mods[i].mod->mod_start & (PAGE_SIZE - 1) )
Signature · 1 line
2.30.2
#65 lore raw

PATCH v6 35/44 x86/boot: remove usage of mod_end by discard_initial_images

In reply to Daniel P. Smith

This eliminates usage of early_mod by discard_initial_images

---
 xen/arch/x86/setup.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
xen/arch/x86/setup.c +2 -3
index f8b9c164c1cb..4d53292aa444 100644
@@ -350,10 +350,9 @@ void __init discard_initial_images(void)
 
     for ( i = 0; i < bi->nr_modules; ++i )
     {
-        uint64_t start =
-            (uint64_t)bi->mods[i].mod->mod_start << PAGE_SHIFT;
+        uint64_t start = bi->mods[i].start;
 
-        init_domheap_pages(start, start + PAGE_ALIGN(bi->mods[i].mod->mod_end));
+        init_domheap_pages(start, start + PAGE_ALIGN(bi->mods[i].size));
     }
 
     bi->nr_modules = 0;
Signature · 1 line
2.30.2
#66 lore raw

PATCH v6 36/44 x86/boot: remove remaining module_t references

In reply to Daniel P. Smith

Any direct usages of module_t have been transitioned, remove the remaining references to the mod field. This also removes any external use of bootstrap_map(), dropping from setup.h and making it static.

---
Changes since v5:
- commit message rewrite
- coding style change
- remove export of bootstrap_map()

---
 xen/arch/x86/include/asm/setup.h |  1 -
 xen/arch/x86/setup.c             | 27 +++++++++------------------
 2 files changed, 9 insertions(+), 19 deletions(-)
xen/arch/x86/include/asm/setup.h +0 -1
index 72d183e8a4de..f7958b56eab6 100644
@@ -35,7 +35,6 @@ extern struct boot_info xen_boot_info;
 
 unsigned long initial_images_nrpages(nodeid_t node);
 void discard_initial_images(void);
-void *bootstrap_map(const module_t *mod);
 void *bootstrap_map_bm(const struct boot_module *bm);
 
 int remove_xen_ranges(struct rangeset *r);
xen/arch/x86/setup.c +9 -18
index 4d53292aa444..5ae82f3abcb5 100644
@@ -333,8 +333,8 @@ unsigned long __init initial_images_nrpages(nodeid_t node)
 
     for ( nr = i = 0; i < bi->nr_modules; ++i )
     {
-        unsigned long start = bi->mods[i].mod->mod_start;
-        unsigned long end = start + PFN_UP(bi->mods[i].mod->mod_end);
+        unsigned long start = bi->mods[i].start;
+        unsigned long end = start + PFN_UP(bi->mods[i].size);
 
         if ( end > node_start && node_end > start )
             nr += min(node_end, end) - max(node_start, start);
@@ -471,7 +471,7 @@ static void *__init bootstrap_map_addr(paddr_t start, paddr_t end)
     return ret;
 }
 
-void *__init bootstrap_map(const module_t *mod)
+static void *__init bootstrap_map(const module_t *mod)
 {
     if ( !mod )
         return bootstrap_map_addr(0, 0);
@@ -661,8 +661,8 @@ static uint64_t __init consider_modules(
 
     for ( i = 0; i < nr_mods ; ++i )
     {
-        uint64_t start = pfn_to_paddr(mods[i].mod->mod_start);
-        uint64_t end = start + PAGE_ALIGN(mods[i].mod->mod_end);
+        uint64_t start = (uint64_t)mods[i].start;
+        uint64_t end = start + PAGE_ALIGN(mods[i].size);
 
         if ( i == this_mod )
             continue;
@@ -1377,10 +1377,8 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
 
     for ( i = 0; i < bi->nr_modules; i++ )
     {
-        if ( bi->mods[i].mod->mod_start & (PAGE_SIZE - 1) )
+        if ( bi->mods[i].start & (PAGE_SIZE - 1) )
             panic("Bootloader didn't honor module alignment request\n");
-        bi->mods[i].mod->mod_end -= bi->mods[i].mod->mod_start;
-        bi->mods[i].mod->mod_start >>= PAGE_SHIFT;
     }
 
     /*
@@ -1401,16 +1399,11 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
          */
         bi->mods[xen].start = virt_to_maddr(_stext);
         bi->mods[xen].size = __2M_rwdata_end - _stext;
-
-        bi->mods[xen].mod->mod_start = bi->mods[xen].start;
-        bi->mods[xen].mod->mod_end = bi->mods[xen].size;
     }
 
-    bi->mods[0].headroom =
-        bzimage_headroom(bootstrap_map(bi->mods[0].mod),
-                         bi->mods[0].mod->mod_end);
-
-    bootstrap_map(NULL);
+    bi->mods[0].headroom = bzimage_headroom(
+        bootstrap_map_bm(&bi->mods[0]), bi->mods[0].size);
+    bootstrap_map_bm(NULL);
 
 #ifndef highmem_start
     /* Don't allow split below 4Gb. */
@@ -1511,9 +1504,7 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
             {
                 move_memory(end - size + bm->headroom, bm->start, bm->size);
                 bm->start = (end - size);
-                bm->mod->mod_start = paddr_to_pfn(bm->start);
                 bm->size += bm->headroom;
-                bm->mod->mod_end = bm->size;
                 bm->flags |= BOOTMOD_FLAG_X86_RELOCATED;
             }
         }
Signature · 1 line
2.30.2
#67 lore raw

PATCH v6 37/44 x86/boot: remove mod from struct boot_module

In reply to Daniel P. Smith

With all references to mod field removed, remove the mod field from struct boot_module.

---
 xen/arch/x86/include/asm/bootinfo.h | 3 ---
 xen/arch/x86/setup.c                | 2 --
 2 files changed, 5 deletions(-)
xen/arch/x86/include/asm/bootinfo.h +0 -3
index 24c2f37c7b11..b65b55c0a2c2 100644
@@ -8,7 +8,6 @@
 #ifndef __XEN_X86_BOOTINFO_H__
 #define __XEN_X86_BOOTINFO_H__
 
-#include <xen/multiboot.h>
 #include <xen/types.h>
 
 /* Max number of boot modules a bootloader can provide in addition to Xen */
@@ -25,8 +24,6 @@ enum bootmod_type {
 };
 
 struct boot_module {
-    /* Transitionary only */
-    module_t *mod;
     /*
      * A boot module may contain a compressed kernel that will require
      * additional space, before the module data, into which the kernel will be
xen/arch/x86/setup.c +0 -2
index 5ae82f3abcb5..ae027667eb82 100644
@@ -308,8 +308,6 @@ static struct boot_info *__init multiboot_fill_boot_info(unsigned long mbi_p)
      */
     for ( i = 0; i <= bi->nr_modules; i++ )
     {
-        bi->mods[i].mod = &mods[i];
-
         bi->mods[i].cmdline = (paddr_t)mods[i].string;
 
         bi->mods[i].start = (paddr_t)mods[i].mod_start;
Signature · 1 line
2.30.2
#68 lore raw

PATCH v6 38/44 x86/boot: introduce boot domain

In reply to Daniel P. Smith

To begin moving toward allowing the hypervisor to construct more than one domain at boot, a container is needed for a domain's build information.

Introduce a new header, <xen/asm/bootdomain.h>, that contains the initial struct boot_domain that encapsulate the build information for a domain.

No functional change intended.

---
 xen/arch/x86/include/asm/bootdomain.h | 28 +++++++++++++++++++++++++++
 xen/arch/x86/include/asm/bootinfo.h   |  5 +++++
 xen/arch/x86/setup.c                  | 23 +++++++---------------
 3 files changed, 40 insertions(+), 16 deletions(-)
 create mode 100644 xen/arch/x86/include/asm/bootdomain.h
xen/arch/x86/include/asm/bootdomain.h new file +28 -0
new file mode 100644
index 000000000000..4285223ac5ab
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (c) 2024 Apertus Solutions, LLC
+ * Author: Daniel P. Smith <[email protected]>
+ * Copyright (c) 2024 Christopher Clark <[email protected]>
+ */
+
+#ifndef __XEN_X86_BOOTDOMAIN_H__
+#define __XEN_X86_BOOTDOMAIN_H__
+
+struct boot_module;
+
+struct boot_domain {
+    struct boot_module *kernel;
+    struct boot_module *ramdisk;
+};
+
+#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/bootinfo.h +5 -0
index b65b55c0a2c2..476f71a7633b 100644
@@ -9,10 +9,14 @@
 #define __XEN_X86_BOOTINFO_H__
 
 #include <xen/types.h>
+#include <asm/bootdomain.h>
 
 /* Max number of boot modules a bootloader can provide in addition to Xen */
 #define MAX_NR_BOOTMODS 63
 
+/* Max number of boot domains that Xen can construct */
+#define MAX_NR_BOOTDOMS 1
+
 /* Boot module binary type / purpose */
 enum bootmod_type {
     BOOTMOD_UNKNOWN,
@@ -63,6 +67,7 @@ struct boot_info {
 
     unsigned int nr_modules;
     struct boot_module mods[MAX_NR_BOOTMODS + 1];
+    struct boot_domain domains[MAX_NR_BOOTDOMS];
 };
 
 /*
xen/arch/x86/setup.c +7 -16
index ae027667eb82..ccb5052e18be 100644
@@ -956,20 +956,10 @@ static struct domain *__init create_dom0(struct boot_info *bi)
             .misc_flags = opt_dom0_msr_relaxed ? XEN_X86_MSR_RELAXED : 0,
         },
     };
-    unsigned int mod_idx = first_boot_module_index(bi, BOOTMOD_RAMDISK);
-    struct boot_module *image, *initrd;
+    struct boot_domain *bd = &bi->domains[0];
     struct domain *d;
     domid_t domid;
 
-    /* Map boot_module to mb1 module for dom0 */
-    image = &bi->mods[0];
-
-    /* Map boot_module to mb1 module for initrd */
-    if ( mod_idx < 0 )
-        initrd = NULL;
-    else
-        initrd = &bi->mods[mod_idx];
-
     if ( opt_dom0_pvh )
     {
         dom0_cfg.flags |= (XEN_DOMCTL_CDF_hvm |
@@ -995,11 +985,10 @@ static struct domain *__init create_dom0(struct boot_info *bi)
         panic("Error creating d%uv0\n", domid);
 
     /* Grab the DOM0 command line. */
-    if ( image->cmdline || bi->kextra )
+    if ( bd->kernel->cmdline || bi->kextra )
     {
-        if ( image->cmdline )
-            safe_strcpy(cmdline,
-                        cmdline_cook(__va(image->cmdline),
+        if ( bd->kernel->cmdline )
+            safe_strcpy(cmdline, cmdline_cook(__va(bd->kernel->cmdline),
                         bi->loader));
 
         if ( bi->kextra )
@@ -1023,7 +1012,7 @@ static struct domain *__init create_dom0(struct boot_info *bi)
         }
     }
 
-    if ( construct_dom0(d, image, initrd, cmdline) != 0 )
+    if ( construct_dom0(d, bd->kernel, bd->ramdisk, cmdline) != 0 )
         panic("Could not construct domain 0\n");
 
     return d;
@@ -1203,6 +1192,7 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
     /* Dom0 kernel is always first */
     bi->mods[0].type = BOOTMOD_KERNEL;
     bi->mods[0].flags = BOOTMOD_FLAG_X86_CONSUMED;
+    bi->domains[0].kernel = &bi->mods[0];
 
     if ( pvh_boot )
     {
@@ -2086,6 +2076,7 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
     {
         bi->mods[initrdidx].type = BOOTMOD_RAMDISK;
         bi->mods[initrdidx].flags |= BOOTMOD_FLAG_X86_CONSUMED;
+        bi->domains[0].ramdisk = &bi->mods[initrdidx];
         if ( first_boot_module_index(bi, BOOTMOD_UNKNOWN) < MAX_NR_BOOTMODS )
             printk(XENLOG_WARNING
                    "Multiple initrd candidates, picking module #%u\n",
Signature · 1 line
2.30.2
#69 lore raw

PATCH v6 39/44 x86/boot: introduce domid field to struct boot_domain

In reply to Daniel P. Smith

Add a domid field to struct boot_domain to hold the assigned domain id for the domain. During initialization, ensure all instances of struct boot_domain have the invalid domid to ensure that the domid must be set either by convention or configuration.

---
 xen/arch/x86/include/asm/bootdomain.h |  2 ++
 xen/arch/x86/setup.c                  | 12 +++++++-----
 2 files changed, 9 insertions(+), 5 deletions(-)
xen/arch/x86/include/asm/bootdomain.h +2 -0
index 4285223ac5ab..d6264d554dba 100644
@@ -11,6 +11,8 @@
 struct boot_module;
 
 struct boot_domain {
+    domid_t domid;
+
     struct boot_module *kernel;
     struct boot_module *ramdisk;
 };
xen/arch/x86/setup.c +7 -5
index ccb5052e18be..e74526e20b5b 100644
@@ -318,6 +318,9 @@ static struct boot_info *__init multiboot_fill_boot_info(unsigned long mbi_p)
     bi->mods[bi->nr_modules].type = BOOTMOD_XEN;
     bi->mods[bi->nr_modules].flags = BOOTMOD_FLAG_X86_CONSUMED;
 
+    for ( i = 0; i < MAX_NR_BOOTDOMS; i++ )
+        bi->domains[i].domid = DOMID_INVALID;
+
     return bi;
 }
 
@@ -958,7 +961,6 @@ static struct domain *__init create_dom0(struct boot_info *bi)
     };
     struct boot_domain *bd = &bi->domains[0];
     struct domain *d;
-    domid_t domid;
 
     if ( opt_dom0_pvh )
     {
@@ -974,15 +976,15 @@ static struct domain *__init create_dom0(struct boot_info *bi)
         dom0_cfg.flags |= XEN_DOMCTL_CDF_iommu;
 
     /* Create initial domain.  Not d0 for pvshim. */
-    domid = get_initial_domain_id();
-    d = domain_create(domid, &dom0_cfg, pv_shim ? 0 : CDF_privileged);
+    bd->domid = get_initial_domain_id();
+    d = domain_create(bd->domid, &dom0_cfg, pv_shim ? 0 : CDF_privileged);
     if ( IS_ERR(d) )
-        panic("Error creating d%u: %ld\n", domid, PTR_ERR(d));
+        panic("Error creating d%u: %ld\n", bd->domid, PTR_ERR(d));
 
     init_dom0_cpuid_policy(d);
 
     if ( alloc_dom0_vcpu0(d) == NULL )
-        panic("Error creating d%uv0\n", domid);
+        panic("Error creating d%uv0\n", bd->domid);
 
     /* Grab the DOM0 command line. */
     if ( bd->kernel->cmdline || bi->kextra )
Signature · 1 line
2.30.2
#70 lore raw

PATCH v6 40/44 x86/boot: add cmdline to struct boot_domain

In reply to Daniel P. Smith

Add a container for the "cooked" command line for a domain.

---
 xen/arch/x86/include/asm/bootdomain.h |  4 ++++
 xen/arch/x86/setup.c                  | 18 ++++++++----------
 2 files changed, 12 insertions(+), 10 deletions(-)
xen/arch/x86/include/asm/bootdomain.h +4 -0
index d6264d554dba..00f7d9267965 100644
@@ -8,9 +8,13 @@
 #ifndef __XEN_X86_BOOTDOMAIN_H__
 #define __XEN_X86_BOOTDOMAIN_H__
 
+#include <public/xen.h>
+
 struct boot_module;
 
 struct boot_domain {
+    char cmdline[MAX_GUEST_CMDLINE];
+
     domid_t domid;
 
     struct boot_module *kernel;
xen/arch/x86/setup.c +8 -10
index e74526e20b5b..1aa063facfce 100644
@@ -946,8 +946,6 @@ static unsigned int __init copy_bios_e820(struct e820entry *map, unsigned int li
 
 static struct domain *__init create_dom0(struct boot_info *bi)
 {
-    static char __initdata cmdline[MAX_GUEST_CMDLINE];
-
     struct xen_domctl_createdomain dom0_cfg = {
         .flags = IS_ENABLED(CONFIG_TBOOT) ? XEN_DOMCTL_CDF_s3_integrity : 0,
         .max_evtchn_port = -1,
@@ -990,16 +988,16 @@ static struct domain *__init create_dom0(struct boot_info *bi)
     if ( bd->kernel->cmdline || bi->kextra )
     {
         if ( bd->kernel->cmdline )
-            safe_strcpy(cmdline, cmdline_cook(__va(bd->kernel->cmdline),
+            safe_strcpy(bd->cmdline, cmdline_cook(__va(bd->kernel->cmdline),
                         bi->loader));
 
         if ( bi->kextra )
             /* kextra always includes exactly one leading space. */
-            safe_strcat(cmdline, bi->kextra);
+            safe_strcat(bd->cmdline, bi->kextra);
 
         /* Append any extra parameters. */
-        if ( skip_ioapic_setup && !strstr(cmdline, "noapic") )
-            safe_strcat(cmdline, " noapic");
+        if ( skip_ioapic_setup && !strstr(bd->cmdline, "noapic") )
+            safe_strcat(bd->cmdline, " noapic");
 
         if ( (strlen(acpi_param) == 0) && acpi_disabled )
         {
@@ -1007,14 +1005,14 @@ static struct domain *__init create_dom0(struct boot_info *bi)
             safe_strcpy(acpi_param, "off");
         }
 
-        if ( (strlen(acpi_param) != 0) && !strstr(cmdline, "acpi=") )
+        if ( (strlen(acpi_param) != 0) && !strstr(bd->cmdline, "acpi=") )
         {
-            safe_strcat(cmdline, " acpi=");
-            safe_strcat(cmdline, acpi_param);
+            safe_strcat(bd->cmdline, " acpi=");
+            safe_strcat(bd->cmdline, acpi_param);
         }
     }
 
-    if ( construct_dom0(d, bd->kernel, bd->ramdisk, cmdline) != 0 )
+    if ( construct_dom0(d, bd->kernel, bd->ramdisk, bd->cmdline) != 0 )
         panic("Could not construct domain 0\n");
 
     return d;
Signature · 1 line
2.30.2
#71 lore raw

PATCH v6 41/44 x86/boot: add struct domain to struct boot_domain

In reply to Daniel P. Smith

Store a reference to the created domain in struct boot_domain.

---
Changes since v5:
- moved back to using variable *d to hold domain reference locally

---
 xen/arch/x86/include/asm/bootdomain.h | 3 +++
 xen/arch/x86/setup.c                  | 4 +++-
 2 files changed, 6 insertions(+), 1 deletion(-)
xen/arch/x86/include/asm/bootdomain.h +3 -0
index 00f7d9267965..2322c459e36a 100644
@@ -10,6 +10,7 @@
 
 #include <public/xen.h>
 
+struct domain;
 struct boot_module;
 
 struct boot_domain {
@@ -19,6 +20,8 @@ struct boot_domain {
 
     struct boot_module *kernel;
     struct boot_module *ramdisk;
+
+    struct domain *d;
 };
 
 #endif
xen/arch/x86/setup.c +3 -1
index 1aa063facfce..494e48a7c836 100644
@@ -1012,10 +1012,12 @@ static struct domain *__init create_dom0(struct boot_info *bi)
         }
     }
 
+    bd->d = d;
+
     if ( construct_dom0(d, bd->kernel, bd->ramdisk, bd->cmdline) != 0 )
         panic("Could not construct domain 0\n");
 
-    return d;
+    return bd->d;
 }
 
 /* How much of the directmap is prebuilt at compile time. */
Signature · 1 line
2.30.2
#72 lore raw

PATCH v6 42/44 x86/boot: convert construct_dom0 to struct boot_domain

In reply to Daniel P. Smith

A struct boot_domain now encapsulates the domain reference, kernel, ramdisk, and command line for the domain being constructed. As a result of this encapsulation, construct_dom0 can now take a single struct boot_domain instead of these four parameters.

---
Changes since v5:
- moved back to using variable *d to hold domain reference locally

---
 xen/arch/x86/dom0_build.c        | 8 ++++----
 xen/arch/x86/include/asm/setup.h | 4 +---
 xen/arch/x86/setup.c             | 2 +-
 3 files changed, 6 insertions(+), 8 deletions(-)
xen/arch/x86/dom0_build.c +4 -4
index 71b2e3afc1a1..34b4943de3b1 100644
@@ -597,10 +597,10 @@ int __init dom0_setup_permissions(struct domain *d)
     return rc;
 }
 
-int __init construct_dom0(struct domain *d, const struct boot_module *image,
-                          struct boot_module *initrd, const char *cmdline)
+int __init construct_dom0(struct boot_domain *bd)
 {
     int rc;
+    struct domain *d = bd->d;
 
     /* Sanity! */
     BUG_ON(!pv_shim && d->domain_id != 0);
@@ -610,9 +610,9 @@ int __init construct_dom0(struct domain *d, const struct boot_module *image,
     process_pending_softirqs();
 
     if ( is_hvm_domain(d) )
-        rc = dom0_construct_pvh(d, image, initrd, cmdline);
+        rc = dom0_construct_pvh(bd->d, bd->kernel, bd->ramdisk, bd->cmdline);
     else if ( is_pv_domain(d) )
-        rc = dom0_construct_pv(d, image, initrd, cmdline);
+        rc = dom0_construct_pv(bd->d, bd->kernel, bd->ramdisk, bd->cmdline);
     else
         panic("Cannot construct Dom0. No guest interface available\n");
 
xen/arch/x86/include/asm/setup.h +1 -3
index f7958b56eab6..b049dc5ee17e 100644
@@ -26,9 +26,7 @@ void subarch_init_memory(void);
 
 void init_IRQ(void);
 
-int construct_dom0(
-    struct domain *d, const struct boot_module *image,
-    struct boot_module *initrd, const char *cmdline);
+int construct_dom0(struct boot_domain *d);
 void setup_io_bitmap(struct domain *d);
 
 extern struct boot_info xen_boot_info;
xen/arch/x86/setup.c +1 -1
index 494e48a7c836..d9ad27093611 100644
@@ -1014,7 +1014,7 @@ static struct domain *__init create_dom0(struct boot_info *bi)
 
     bd->d = d;
 
-    if ( construct_dom0(d, bd->kernel, bd->ramdisk, bd->cmdline) != 0 )
+    if ( construct_dom0(bd) != 0 )
         panic("Could not construct domain 0\n");
 
     return bd->d;
Signature · 1 line
2.30.2
#73 lore raw

PATCH v6 43/44 x86/boot: convert dom0_construct_pv to struct boot_domain

In reply to Daniel P. Smith

With construct_dom0 consuming struct boot_domain, continue passing the structure down to dom0_construct_pv.

---
Changes since v5:
- reverted back *v d->vcpu[0]

---
 xen/arch/x86/dom0_build.c             |  2 +-
 xen/arch/x86/include/asm/dom0_build.h |  5 ++--
 xen/arch/x86/pv/dom0_build.c          | 41 ++++++++++++---------------
 3 files changed, 21 insertions(+), 27 deletions(-)
xen/arch/x86/dom0_build.c +1 -1
index 34b4943de3b1..96cd1154b037 100644
@@ -612,7 +612,7 @@ int __init construct_dom0(struct boot_domain *bd)
     if ( is_hvm_domain(d) )
         rc = dom0_construct_pvh(bd->d, bd->kernel, bd->ramdisk, bd->cmdline);
     else if ( is_pv_domain(d) )
-        rc = dom0_construct_pv(bd->d, bd->kernel, bd->ramdisk, bd->cmdline);
+        rc = dom0_construct_pv(bd);
     else
         panic("Cannot construct Dom0. No guest interface available\n");
 
xen/arch/x86/include/asm/dom0_build.h +2 -3
index 8f7b37f3d308..60e9cb21f14d 100644
@@ -4,6 +4,7 @@
 #include <xen/libelf.h>
 #include <xen/sched.h>
 
+#include <asm/bootinfo.h>
 #include <asm/setup.h>
 
 extern unsigned int dom0_memflags;
@@ -13,9 +14,7 @@ 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 struct boot_module *image,
-    struct boot_module *initrd, const char *cmdline);
+int dom0_construct_pv(struct boot_domain *bd);
 
 int dom0_construct_pvh(
     struct domain *d, const struct boot_module *image,
xen/arch/x86/pv/dom0_build.c +18 -23

107 lines not on this page · raw message

Signature · 1 line
2.30.2
#74 lore raw

PATCH v6 44/44 x86/boot: convert dom0_construct_pvh to struct boot_domain

In reply to Daniel P. Smith

With construct_dom0 consuming struct boot_domain, continue passing the structure down to dom0_construct_pvh.

---
Changes since v5:
- revert back to using *d as local reference for struct domain

---
 xen/arch/x86/dom0_build.c             | 2 +-
 xen/arch/x86/hvm/dom0_build.c         | 8 ++++----
 xen/arch/x86/include/asm/dom0_build.h | 4 +---
 3 files changed, 6 insertions(+), 8 deletions(-)
xen/arch/x86/dom0_build.c +1 -1
index 96cd1154b037..f0d2c349095b 100644
@@ -610,7 +610,7 @@ int __init construct_dom0(struct boot_domain *bd)
     process_pending_softirqs();
 
     if ( is_hvm_domain(d) )
-        rc = dom0_construct_pvh(bd->d, bd->kernel, bd->ramdisk, bd->cmdline);
+        rc = dom0_construct_pvh(bd);
     else if ( is_pv_domain(d) )
         rc = dom0_construct_pv(bd);
     else
xen/arch/x86/hvm/dom0_build.c +4 -4
index a3fd5e762dc4..720e08f9346f 100644
@@ -1299,10 +1299,9 @@ static void __hwdom_init pvh_setup_mmcfg(struct domain *d)
     }
 }
 
-int __init dom0_construct_pvh(
-    struct domain *d, const struct boot_module *image,
-    struct boot_module *initrd, const char *cmdline)
+int __init dom0_construct_pvh(const struct boot_domain *bd)
 {
+    struct domain *d = bd->d;
     paddr_t entry, start_info;
     int rc;
 
@@ -1345,7 +1344,8 @@ int __init dom0_construct_pvh(
         return rc;
     }
 
-    rc = pvh_load_kernel(d, image, initrd, bootstrap_map_bm(image), cmdline,
+    rc = pvh_load_kernel(d, bd->kernel, bd->ramdisk,
+                         bootstrap_map_bm(bd->kernel), bd->cmdline,
                          &entry, &start_info);
     if ( rc )
     {
xen/arch/x86/include/asm/dom0_build.h +1 -3
index 60e9cb21f14d..adbe90bfd034 100644
@@ -16,9 +16,7 @@ int dom0_setup_permissions(struct domain *d);
 
 int dom0_construct_pv(struct boot_domain *bd);
 
-int dom0_construct_pvh(
-    struct domain *d, const struct boot_module *image,
-    struct boot_module *initrd, const char *cmdline);
+int dom0_construct_pvh(const struct boot_domain *bd);
 
 unsigned long dom0_paging_pages(const struct domain *d,
                                 unsigned long nr_pages);
Signature · 1 line
2.30.2
#75 lore raw
In reply to Daniel P. Smith
Quoted 7 lines · Daniel P. Smith

Christopher Clark (1):
x86/boot: move x86 boot module counting into a new boot_info struct

Daniel P. Smith (42):
x86/boot: move boot loader name to boot info
x86/boot: move cmdline to boot info
x86/boot: move mmap info to boot info

I've committed these 4, with the noted minor adjustments.

Unfortunately patch 5 needs some more complicated rework.

~Andrew