Skip to contentSkip to conversation

Boot modules for Hyperlaunch

PATCH Superseded Daniel P. Smith 2 participants 45 messages Oct 21, 2024 – Oct 22, 2024

v7 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v7 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 v6:
- Dropped patches that were merged from v5
- patch 8 title and commit message rewritten
- boot module interator patch merged with xsm patch, its first use
- incorporated review requests
- made additional style optimizations as a result of review requests

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.

Daniel P. Smith (38):
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: populate boot module for xen entry
x86/boot: transition relocation calculations to struct boot_module 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     |  83 ++++------
 xen/arch/x86/dom0_build.c             |  10 +-
 xen/arch/x86/hvm/dom0_build.c         |  32 ++--
 xen/arch/x86/include/asm/bootdomain.h |  37 +++++
 xen/arch/x86/include/asm/bootinfo.h   | 104 +++++++++++-
 xen/arch/x86/include/asm/dom0_build.h |  11 +-
 xen/arch/x86/include/asm/microcode.h  |  12 +-
 xen/arch/x86/include/asm/setup.h      |   9 +-
 xen/arch/x86/pv/dom0_build.c          |  54 +++---
 xen/arch/x86/setup.c                  | 226 ++++++++++++++++----------
 xen/include/xsm/xsm.h                 |  14 +-
 xen/xsm/xsm_core.c                    |  19 ++-
 xen/xsm/xsm_policy.c                  |  20 +--
 13 files changed, 398 insertions(+), 233 deletions(-)
 create mode 100644 xen/arch/x86/include/asm/bootdomain.h
Signature · 1 line
2.30.2
#1 lore raw

PATCH v7 1/38 x86/boot: introduce struct boot_module

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 v6:
- add guard to prevent OOB access of the boot module array
- pulled the setting of the Xen entry back out as independently set
- updated comment to understand why Xen entry has to be explicitly set

Changes since v5:
- reword comment

---
 xen/arch/x86/include/asm/bootinfo.h | 10 ++++++++++
 xen/arch/x86/setup.c                | 26 ++++++++++++++++++++++++--
 2 files changed, 34 insertions(+), 2 deletions(-)
xen/arch/x86/include/asm/bootinfo.h +10 -0
index e7821e0603f8..ffa443406747 100644
@@ -8,8 +8,17 @@
 #ifndef X86_BOOTINFO_H
 #define 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 /* X86_BOOTINFO_H */
xen/arch/x86/setup.c +24 -2
index bfede5064e8c..db670258d650 100644
@@ -287,6 +287,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;
 
     if ( mbi->flags & MBI_MODULES )
         bi->nr_modules = mbi->mods_count;
@@ -303,6 +305,21 @@ static struct boot_info *__init multiboot_fill_boot_info(unsigned long mbi_p)
         bi->memmap_length = mbi->mmap_length;
     }
 
+    /*
+     * The multiboot entry point will reserve mods_count + 1 instances of
+     * module_t, with the last one being for Xen. First iterate over nr_modules
+     * module_t entries, or MAX_NR_BOOTMODS if more than the max was passed.
+     *
+     * As the Xen entry may be beyond MAX_NR_BOOTMODS, explicitly set the last
+     * entry in mods to point at the last module_t entry which the entry point
+     * reserved for Xen.
+     */
+    for ( i = 0; i < MAX_NR_BOOTMODS && i < bi->nr_modules; i++ )
+        bi->mods[i].mod = &mods[i];
+
+    /* Variable 'i' should be one entry past the last module. */
+    bi->mods[i].mod = &mods[bi->nr_modules];
+
     return bi;
 }
 
@@ -1163,9 +1180,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;
+        /*
+         * Only MAX_NR_BOOTMODS were populated in bootinfo, truncate nr_modules
+         * now that it can be report that an excess number of modules were
+         * passed.
+         */
+        bi->nr_modules = MAX_NR_BOOTMODS;
         printk("Excessive boot modules - using the first %u only\n",
                bi->nr_modules);
     }
Signature · 1 line
2.30.2
#2 lore raw

PATCH v7 2/38 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 db670258d650..1eafa0a61e0e 100644
@@ -645,7 +645,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;
@@ -655,20 +655,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);
         }
     }
@@ -1451,7 +1451,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
@@ -1486,7 +1486,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 )
@@ -1513,7 +1513,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
#3 lore raw

Re: [PATCH v7 02/38] x86/boot: convert consider_modules to struct boot_module

Quoted 8 lines · 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.

I've taken patch 1 (currently in testing to push).

However, this change breaks PV Shim (same test case that I debugged the OSSTest failure with on Saturday).

(XEN) PVH start info: (pa 0000ffc0)
(XEN)   version:    1
(XEN)   flags:      0
(XEN)   nr_modules: 2
(XEN)   modlist_pa: 000000000000ff60
(XEN)   cmdline_pa: 000000000000ffa0
(XEN)   cmdline:    'pv-shim console=xen,pv'
(XEN)   rsdp_pa:    00000000fc008000
(XEN)     mod[0].pa:         0000000001042000
(XEN)     mod[0].size:       0000000006907440
(XEN)     mod[0].cmdline_pa: 0000000000000000
(XEN)     mod[1].pa:         00000000016d9000
(XEN)     mod[1].size:       0000000019870751
(XEN)     mod[1].cmdline_pa: 0000000000000000
(XEN) Bootloader: PVH Directboot
(XEN) Command line: pv-shim console=xen,pv
(XEN) Xen image load base address: 0
...
(XEN) ----[ Xen-4.20-unstable  x86_64  debug=y ubsan=y  Not tainted ]---- (XEN) CPU:    0
(XEN) RIP:    e008:[<ffff82d040a51d38>] arch/x86/pv/dom0_build.c#dom0_construct+0x2020/0x24eb
...
(XEN) Xen call trace:
(XEN)    [<ffff82d040a51d38>] R arch/x86/pv/dom0_build.c#dom0_construct+0x2020/0x24eb
(XEN)    [<ffff82d040a52222>] F dom0_construct_pv+0x1f/0xcd (XEN)    [<ffff82d040a7bb27>] F construct_dom0+0xad/0xc0 (XEN)    [<ffff82d040a6eb3f>] F __start_xen+0x50f2/0x53aa (XEN)    [<ffff82d040206184>] F __high_start+0x94/0xa0
...
(XEN) Pagetable walk from ffff8287fffffff8:
(XEN)  L4[0x105] = 000000001fa17063 ffffffffffffffff
(XEN)  L3[0x01f] = 0000000000000000 ffffffffffffffff
(XEN)
(XEN) ****************************************
(XEN) Panic on CPU 0:
(XEN) FATAL PAGE FAULT
(XEN) [error_code=0000]
(XEN) Faulting linear address: ffff8287fffffff8
(XEN) ****************************************

We've got a wild access, but it's not clear exactly what's going on here.

addr2line says it's line 904 which is in the middle of the page_list_for_each() loop setting up the physmap.

My gut feeling is that the pointer -> array conversion in consider_modules() isn't correct, because that's literally the only non-trivial change, but I can't spot anything concretely wrong...

~Andrew

#4 lore raw

Re: [PATCH v7 02/38] x86/boot: convert consider_modules to struct boot_module

Quoted 56 lines · Andrew Cooper
Quoted 8 lines · 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.

I've taken patch 1 (currently in testing to push).

However, this change breaks PV Shim (same test case that I debugged the OSSTest failure with on Saturday).

(XEN) PVH start info: (pa 0000ffc0)
(XEN)   version:    1
(XEN)   flags:      0
(XEN)   nr_modules: 2
(XEN)   modlist_pa: 000000000000ff60
(XEN)   cmdline_pa: 000000000000ffa0
(XEN)   cmdline:    'pv-shim console=xen,pv'
(XEN)   rsdp_pa:    00000000fc008000
(XEN)     mod[0].pa:         0000000001042000
(XEN)     mod[0].size:       0000000006907440
(XEN)     mod[0].cmdline_pa: 0000000000000000
(XEN)     mod[1].pa:         00000000016d9000
(XEN)     mod[1].size:       0000000019870751
(XEN)     mod[1].cmdline_pa: 0000000000000000
(XEN) Bootloader: PVH Directboot
(XEN) Command line: pv-shim console=xen,pv
(XEN) Xen image load base address: 0
...
(XEN) ----[ Xen-4.20-unstable  x86_64  debug=y ubsan=y  Not tainted ]---- (XEN) CPU:    0
(XEN) RIP:    e008:[<ffff82d040a51d38>] arch/x86/pv/dom0_build.c#dom0_construct+0x2020/0x24eb
...
(XEN) Xen call trace:
(XEN)    [<ffff82d040a51d38>] R arch/x86/pv/dom0_build.c#dom0_construct+0x2020/0x24eb
(XEN)    [<ffff82d040a52222>] F dom0_construct_pv+0x1f/0xcd (XEN)    [<ffff82d040a7bb27>] F construct_dom0+0xad/0xc0 (XEN)    [<ffff82d040a6eb3f>] F __start_xen+0x50f2/0x53aa (XEN)    [<ffff82d040206184>] F __high_start+0x94/0xa0
...
(XEN) Pagetable walk from ffff8287fffffff8:
(XEN)  L4[0x105] = 000000001fa17063 ffffffffffffffff
(XEN)  L3[0x01f] = 0000000000000000 ffffffffffffffff
(XEN)
(XEN) ****************************************
(XEN) Panic on CPU 0:
(XEN) FATAL PAGE FAULT
(XEN) [error_code=0000]
(XEN) Faulting linear address: ffff8287fffffff8
(XEN) ****************************************

Quoted 8 lines

We've got a wild access, but it's not clear exactly what's going on here.

addr2line says it's line 904 which is in the middle of the page_list_for_each() loop setting up the physmap.

My gut feeling is that the pointer -> array conversion in consider_modules() isn't correct, because that's literally the only non-trivial change, but I can't spot anything concretely wrong...

To follow up, this isn't really the fault of this patch.

It's a hindenbug left by prior patches.  Fix at
https://lore.kernel.org/xen-devel/[email protected]/T/#u

~Andrew

#5 lore raw

PATCH v7 3/38 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 v6:
- add blank line to separate comment from line above it

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

---
 xen/arch/x86/include/asm/bootinfo.h | 14 ++++++++++++++
 xen/arch/x86/setup.c                | 21 ++++++++++++---------
 2 files changed, 26 insertions(+), 9 deletions(-)
xen/arch/x86/include/asm/bootinfo.h +14 -0
index ffa443406747..59e6696f9671 100644
@@ -17,6 +17,20 @@
 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 1eafa0a61e0e..48809aa94451 100644
@@ -1028,7 +1028,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;
@@ -1394,7 +1394,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
@@ -1479,8 +1482,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;
@@ -1493,14 +1496,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;
             }
         }
@@ -1527,7 +1530,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 )
     {
@@ -2079,7 +2082,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
#6 lore raw

Re: [PATCH v7 03/38] x86/boot: move headroom to boot modules

Quoted 26 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.

---
Changes since v6:
- add blank line to separate comment from line above it

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

---
 xen/arch/x86/include/asm/bootinfo.h | 14 ++++++++++++++
 xen/arch/x86/setup.c                | 21 ++++++++++++---------
 2 files changed, 26 insertions(+), 9 deletions(-)
xen/arch/x86/include/asm/bootinfo.h +0 -0
index ffa443406747..59e6696f9671 100644

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

Quoted 8 lines
xen/arch/x86/include/asm/bootinfo.h +5 -0
@@ -17,6 +17,20 @@
 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.

The grammar is a bit awkward.  Space beforehand is an implementation choice of Xen, not a requirement.

Can I suggest:

---%<---
A boot module may need decompressing by Xen.  Headroom is an estimate of the additional space required to decompress the module.

Headroom is accounted for at the start of the module.  Decompressing is done in-place with input=start, output=start-headroom, expecting the pointers to become equal (give or take some rounding) when decompression is complete.
---%<---

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

Quoted 8 lines
xen/arch/x86/include/asm/bootinfo.h +8 -0
+     *
+     * Memory layout at boot:
+     *     [ compressed kernel ]
+     * After boot module relocation:
+     *     [ estimated headroom + PAGE_SIZE rounding ][ compressed kernel ]
+     * After kernel decompression:
+     *     [ decompressed kernel ][ unused rounding ]
+     */

I'm not sure how helpful this is.  If anything, I'd say it ought to be:

                       start + size --+
          start --+                   |
                  v                   v

                  +-------------------+
                  | Compressed Module |
 +----------------+-------------------+
 |         Decompressed Module        |
 +----------------+-------------------+

 ^
 +-- start - headroom

~Andrew

#7 lore raw

Re: [PATCH v7 03/38] x86/boot: move headroom to boot modules

In reply to Daniel P. Smith
Quoted 9 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.

Actually, based on the observation in the subsequent patch about pulling the initial_image deletion earlier in the series, I'm going to recommend something else here.

You should fully remove the mod pointer in __start_xen() (i.e. convert mod[] references to bi->mods[]) before starting to remove other variables such as module_headroom here.

This is largely doable because microcode and xsm both take the mbi pointer and map mbi->module_addr themselves, rather than take __start_xen()'s pointer.

Again, this reduces churn in the series, and minimises the extent to which we're operating on multiple representations of the same data.

~Andrew

#8 lore raw

PATCH v7 4/38 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 v6:
- code style
- switched to a local ref

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

---
 xen/arch/x86/setup.c | 62 +++++++++++++++++++++++++-------------------
 1 file changed, 35 insertions(+), 27 deletions(-)
xen/arch/x86/setup.c +35 -27
index 48809aa94451..b6d688f8fe5e 100644
@@ -1364,15 +1364,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;
     }
 
     /*
@@ -1383,6 +1387,7 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
 
     if ( xen_phys_start )
     {
+        unsigned int xen = bi->nr_modules;
         relocated = true;
 
         /*
@@ -1390,8 +1395,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 =
@@ -1483,9 +1488,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 ( bm->mod->reserved )
                 continue;
 
             /* Don't overlap with other modules (or Xen itself). */
@@ -1497,14 +1502,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;
             }
         }
 
@@ -1530,13 +1535,14 @@ 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 )
@@ -1614,8 +1620,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(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;
@@ -1689,11 +1695,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
@@ -2082,8 +2089,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
#9 lore raw

Re: [PATCH v7 04/38] x86/boot: convert mod refs to boot_module mod

Quoted 27 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 v6:
- code style
- switched to a local ref

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

---
 xen/arch/x86/setup.c | 62 +++++++++++++++++++++++++-------------------
 1 file changed, 35 insertions(+), 27 deletions(-)
xen/arch/x86/setup.c +0 -0
index 48809aa94451..b6d688f8fe5e 100644

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

Quoted 9 lines
xen/arch/x86/setup.c +5 -1
@@ -1364,15 +1364,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;

This looks actively-dodgy.  It might be correct, but its also not necessary.

bi->mods[] is populated and both initial_images_nrpages() and discard_initial_images() have a local bi-> pointer which they already consume nr_module from, so you really can drop initial_images here in the series.

i.e. you want to pull patch 28 forward to ahead of of this one, and it will reduce the churn through the series.

But mostly, it removes a transient-WTF construct from the series, making it easier to review.

~Andrew

#10 lore raw

Re: [PATCH v7 04/38] x86/boot: convert mod refs to boot_module mod

Quoted 44 lines · Andrew Cooper
Quoted 27 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 v6:
- code style
- switched to a local ref

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

---
 xen/arch/x86/setup.c | 62 +++++++++++++++++++++++++-------------------
 1 file changed, 35 insertions(+), 27 deletions(-)
xen/arch/x86/setup.c +0 -0
index 48809aa94451..b6d688f8fe5e 100644

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

Quoted 9 lines
xen/arch/x86/setup.c +5 -1
@@ -1364,15 +1364,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;

This looks actively-dodgy.  It might be correct, but its also not necessary.

bi->mods[] is populated and both initial_images_nrpages() and discard_initial_images() have a local bi-> pointer which they already consume nr_module from, so you really can drop initial_images here in the series.

Quoted 5 lines

i.e. you want to pull patch 28 forward to ahead of of this one, and it will reduce the churn through the series.

But mostly, it removes a transient-WTF construct from the series, making it easier to review.

In fact, having done this locally, both patches 27 and 28 disappear. Patches 29 and 30 are the ones which swap these two functions away from using the mod-> pointer, and they're basically the same.

So yes, far less churn.

~Andrew

#11 lore raw

PATCH v7 5/38 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                | 4 ++++
 2 files changed, 13 insertions(+)
xen/arch/x86/include/asm/bootinfo.h +9 -0
index 59e6696f9671..ec005a97d6d5 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;
@@ -31,6 +39,7 @@ struct boot_module {
      *     [ decompressed kernel ][ unused rounding ]
      */
     unsigned long headroom;
+    enum bootmod_type type;
 };
 
 /*
xen/arch/x86/setup.c +4 -0
index b6d688f8fe5e..496f0900890d 100644
@@ -319,6 +319,7 @@ static struct boot_info *__init multiboot_fill_boot_info(unsigned long mbi_p)
 
     /* Variable 'i' should be one entry past the last module. */
     bi->mods[i].mod = &mods[bi->nr_modules];
+    bi->mods[i].type = BOOTMOD_XEN;
 
     return bi;
 }
@@ -1194,6 +1195,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 )
     {
@@ -2080,6 +2082,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
#12 lore raw

PATCH v7 6/38 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 bitfield is added to enable tracking these different states. The first state to be transition by this commit is module relocation.

---
Changes since v6:
- replaced bitmask flags field with the bitfield, relocated
- slight update to commit message to mention bitfield
- dropped Rb and Ab due to approach change

Changes since v5:
- removed trailing blank line.

---
 xen/arch/x86/include/asm/bootinfo.h | 6 ++++++
 xen/arch/x86/setup.c                | 7 +++----
 2 files changed, 9 insertions(+), 4 deletions(-)
xen/arch/x86/include/asm/bootinfo.h +6 -0
index ec005a97d6d5..e8fba66eedc5 100644
@@ -40,6 +40,12 @@ struct boot_module {
      */
     unsigned long headroom;
     enum bootmod_type type;
+
+    /*
+     * Module State Flags:
+     *   relocated: indicates module has been relocated in memory.
+     */
+    bool relocated:1;
 };
 
 /*
xen/arch/x86/setup.c +3 -4
index 496f0900890d..17f74384b5c1 100644
@@ -1378,7 +1378,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;
     }
 
     /*
@@ -1492,7 +1491,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 ( bm->mod->reserved )
+            if ( bm->relocated )
                 continue;
 
             /* Don't overlap with other modules (or Xen itself). */
@@ -1511,7 +1510,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->relocated = true;
             }
         }
 
@@ -1537,7 +1536,7 @@ 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].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
#13 lore raw

PATCH v7 7/38 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 is a special case, as the EFI file loading boot service may load a file beyond the 4G barrier. As a result, to make the address fit in the 32bit integer used by the MB1 module_t structure, the frame number is stored in mod_start and size in mod_end. Until the EFI entry point is enlightened to work with boot_info and boot_module, multiboot_fill_boot_info will handle the alternate values in mod_start and mod_end when EFI is detected.

---
Changes since v6:
- put the efi conversion for mod_start and mod_end back along with check
- dropped unnecessary cast
- updated the population of start and size fields to take into account efi

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

---
 xen/arch/x86/include/asm/bootinfo.h |  3 +++
 xen/arch/x86/setup.c                | 15 +++++++++++++++
 2 files changed, 18 insertions(+)
xen/arch/x86/include/asm/bootinfo.h +3 -0
index e8fba66eedc5..dbd22db3d063 100644
@@ -46,6 +46,9 @@ struct boot_module {
      *   relocated: indicates module has been relocated in memory.
      */
     bool relocated:1;
+
+    paddr_t start;
+    size_t size;
 };
 
 /*
xen/arch/x86/setup.c +15 -0
index 17f74384b5c1..2e87aa314389 100644
@@ -315,10 +315,25 @@ static struct boot_info *__init multiboot_fill_boot_info(unsigned long mbi_p)
      * reserved for Xen.
      */
     for ( i = 0; i < MAX_NR_BOOTMODS && i < bi->nr_modules; i++ )
+    {
         bi->mods[i].mod = &mods[i];
 
+        if ( !efi_enabled(EFI_LOADER) )
+        {
+            bi->mods[i].start = mods[i].mod_start;
+            bi->mods[i].size = mods[i].mod_end - mods[i].mod_start;
+        }
+        else
+        {
+            bi->mods[i].start = pfn_to_paddr(mods[i].mod_start);
+            bi->mods[i].size = mods[i].mod_end;
+        }
+    }
+
     /* Variable 'i' should be one entry past the last module. */
     bi->mods[i].mod = &mods[bi->nr_modules];
+    bi->mods[i].start = mods[i].mod_start;
+    bi->mods[i].size = mods[i].mod_end - mods[i].mod_start;
     bi->mods[i].type = BOOTMOD_XEN;
 
     return bi;
Signature · 1 line
2.30.2
#14 lore raw

PATCH v7 8/38 x86/boot: populate boot module for xen entry

In reply to Daniel P. Smith

Populate the start and size fields for the Xen entry when populating them in the reserved module_t entry.

---
Changes since v6:
- apply correct conversion of assignment to mod_start
- rewrite commit message to reflect code change

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 2e87aa314389..4e5d4055e7dd 100644
@@ -1411,8 +1411,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 = paddr_to_pfn(bi->mods[xen].start);
+        bi->mods[xen].mod->mod_end = bi->mods[xen].size;
     }
 
     bi->mods[0].headroom =
Signature · 1 line
2.30.2
#15 lore raw

PATCH v7 9/38 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 v6:
- introduce local s and l refs for start and size, shortening the lines while correcting the indentation style

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 | 34 ++++++++++++++--------------------
 1 file changed, 14 insertions(+), 20 deletions(-)
xen/arch/x86/setup.c +14 -20
index 4e5d4055e7dd..b02391b887b1 100644
@@ -1507,7 +1507,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 ( bm->relocated )
                 continue;
@@ -1519,15 +1519,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->relocated = true;
             }
         }
@@ -1558,10 +1556,9 @@ 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 = bi->mods[i].start;
 
-        reserve_e820_ram(&boot_e820, s,
-                         s + PAGE_ALIGN(bi->mods[i].mod->mod_end));
+        reserve_e820_ram(&boot_e820, s, s + PAGE_ALIGN(bi->mods[i].size));
     }
 
     if ( !xen_phys_start )
@@ -1639,8 +1636,7 @@ 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;
@@ -1714,12 +1710,10 @@ 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);
+        unsigned long s = bi->mods[i].start, l = bi->mods[i].size;
+        set_pdx_range(paddr_to_pfn(s), paddr_to_pfn(s) + PFN_UP(l));
+        map_pages_to_xen((unsigned long)maddr_to_virt(s), maddr_to_mfn(s),
+                         PFN_UP(l), PAGE_HYPERVISOR);
     }
 
 #ifdef CONFIG_KEXEC
Signature · 1 line
2.30.2
#16 lore raw

PATCH v7 10/38 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 v6:
- changed flag from bitmap to bitfield.

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

---
 xen/arch/x86/include/asm/bootinfo.h | 3 +++
 xen/arch/x86/setup.c                | 5 +++++
 2 files changed, 8 insertions(+)
xen/arch/x86/include/asm/bootinfo.h +3 -0
index dbd22db3d063..3eb9930904c0 100644
@@ -44,8 +44,11 @@ struct boot_module {
     /*
      * Module State Flags:
      *   relocated: indicates module has been relocated in memory.
+     *   consumed:  indicates that the subystem that claimed the module has
+     *              finished with it.
      */
     bool relocated:1;
+    bool consumed:1;
 
     paddr_t start;
     size_t size;
xen/arch/x86/setup.c +5 -0
index b02391b887b1..a623f9cd9df9 100644
@@ -335,6 +335,7 @@ static struct boot_info *__init multiboot_fill_boot_info(unsigned long mbi_p)
     bi->mods[i].start = mods[i].mod_start;
     bi->mods[i].size = mods[i].mod_end - mods[i].mod_start;
     bi->mods[i].type = BOOTMOD_XEN;
+    bi->mods[i].consumed = true;
 
     return bi;
 }
@@ -1211,6 +1212,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].consumed = true;
 
     if ( pvh_boot )
     {
@@ -2094,7 +2096,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].consumed = true;
+    }
     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
#17 lore raw

PATCH v7 11/38 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 v6:
- introduce helpers for_each_boot_module and boot_module_index
- drop const due to object use changes done by helpers
- converted boot module search to use for each helper
- make bootstrap unmap call match bootstrap map

Changes since v5:
- moved bootstrap_map_bm definition to this commit

---
 xen/arch/x86/cpu/microcode/core.c    | 46 ++++++++++++----------------
 xen/arch/x86/include/asm/bootinfo.h  | 25 +++++++++++++++
 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, 65 insertions(+), 34 deletions(-)
xen/arch/x86/cpu/microcode/core.c +20 -26
index 8564e4d2c94c..11a0ba978a33 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,16 +154,14 @@ 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, 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;
     long offset;
     const char *p = NULL;
-    int i;
+    struct boot_module *bm;
 
     ucode_blob.size = 0;
     if ( !ucode_scan )
@@ -178,17 +177,14 @@ 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_each_boot_module(bi, bm, BOOTMOD_UNKNOWN)
     {
-        if ( !test_bit(i, module_map) )
-            continue;
-
-        _blob_start = bootstrap_map(&mod[i]);
-        _blob_size = mod[i].mod_end;
+        _blob_start = bootstrap_map_bm(bm);
+        _blob_size = bm->size;
         if ( !_blob_start )
         {
-            printk("Could not map multiboot module #%d (size: %ld)\n",
-                   i, _blob_size);
+            printk("Could not map boot module #%d (size: %ld)\n",
+                   boot_module_index(bi, bm), _blob_size);
             continue;
         }
         cd.data = NULL;
@@ -200,25 +196,23 @@ static void __init microcode_scan_module(
             ucode_blob.data = cd.data;
             break;
         }
-        bootstrap_map(NULL);
+        bootstrap_map_bm(NULL);
     }
 }
 
 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 +816,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, struct boot_info *bi)
 {
     int rc = 0;
 
@@ -832,7 +826,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 +873,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 +916,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 +25 -0
index 3eb9930904c0..e470df48700d 100644
@@ -20,6 +20,7 @@ enum bootmod_type {
     BOOTMOD_XEN,
     BOOTMOD_KERNEL,
     BOOTMOD_RAMDISK,
+    BOOTMOD_MICROCODE,
 };
 
 struct boot_module {
@@ -69,6 +70,30 @@ struct boot_info {
     struct boot_module mods[MAX_NR_BOOTMODS + 1];
 };
 
+static inline struct boot_module *__init next_boot_module_by_type(
+    struct boot_info *bi, struct boot_module *bm, enum bootmod_type t)
+{
+    if ( bm == NULL )
+        bm = &bi->mods[0];
+    else
+        bm++;
+
+    for ( ; bm <= &bi->mods[bi->nr_modules]; bm++ )
+    {
+        if ( bm->type == t )
+            return bm;
+    }
+
+    return NULL;
+}
+
+#define for_each_boot_module(bi, bm, t)                                     \
+    for ( bm = &bi->mods[0]; bm != NULL && bm <= &bi->mods[bi->nr_modules]; \
+          bm = next_boot_module_by_type(bi, bm, t) )
+
+#define boot_module_index(bi, bm)                   \
+    (unsigned int)(bm - &bi->mods[0])
+
 #endif /* X86_BOOTINFO_H */
 
 /*
xen/arch/x86/include/asm/microcode.h +8 -6
index 57c08205d475..9e7c7ab004ed 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, 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 a623f9cd9df9..272d5a725c54 100644
@@ -499,6 +499,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)
 {
@@ -1401,7 +1409,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 )
     {
@@ -1948,7 +1956,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
#18 lore raw

PATCH v7 12/38 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 | 29 ++++++++++++++---------------
 1 file changed, 14 insertions(+), 15 deletions(-)
xen/arch/x86/cpu/microcode/core.c +14 -15
index 11a0ba978a33..b6badd9afdb2 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;
@@ -209,7 +208,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);
@@ -763,14 +762,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;
@@ -828,9 +827,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);
 
@@ -849,10 +848,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 )
@@ -918,7 +917,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
#19 lore raw

PATCH v7 13/38 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.

---
Changes since v6:
- adjust logic to the change of consumed flag to being a bitfield

---
 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 b6badd9afdb2..8ea789dceec2 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;
@@ -208,7 +208,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);
@@ -766,10 +766,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->consumed )
     {
         bootstrap_map_bm(NULL);
-        ucode_mod.size = 0;
+        ucode_mod->consumed = true;
     }
 
     return 0;
@@ -823,14 +823,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->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;
@@ -848,10 +848,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->consumed )
     {
-        len = ucode_mod.size;
-        data = bootstrap_map_bm(&ucode_mod);
+        len = ucode_mod->size;
+        data = bootstrap_map_bm(ucode_mod);
     }
 
     if ( !data )
@@ -917,7 +917,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
#20 lore raw

PATCH v7 14/38 x86/boot: convert xsm policy loading to struct boot_module

In reply to Daniel P. Smith

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

To assist with looking up the index of the xsm policy in the boot module array, an iterator is provided.

---
Changes since v6:
- converted boot module walk over to for each helper
- slight reword of commit message
- merged the interator patch with its first usage by XSM
- corrected the short-circuit return value for Xen in the interator
- dropped R-b due to merging with patch not approved.

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 | 30 ++++++++++++++++++++++++++++-
 xen/arch/x86/setup.c                |  2 +-
 xen/include/xsm/xsm.h               | 11 +++++++----
 xen/xsm/xsm_core.c                  | 17 ++++++++++++----
 xen/xsm/xsm_policy.c                | 20 +++++++++----------
 5 files changed, 59 insertions(+), 21 deletions(-)
xen/arch/x86/include/asm/bootinfo.h +29 -1
index e470df48700d..3ca56454c4d7 100644
@@ -21,6 +21,7 @@ enum bootmod_type {
     BOOTMOD_KERNEL,
     BOOTMOD_RAMDISK,
     BOOTMOD_MICROCODE,
+    BOOTMOD_XSM_POLICY,
 };
 
 struct boot_module {
@@ -94,8 +95,35 @@ static inline struct boot_module *__init next_boot_module_by_type(
 #define boot_module_index(bi, bm)                   \
     (unsigned int)(bm - &bi->mods[0])
 
-#endif /* 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 bi->nr_modules;
+
+    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 /* X86_BOOTINFO_H */
 /*
  * Local variables:
  * mode: C
xen/arch/x86/setup.c +1 -1
index 272d5a725c54..ed1d89ad4bb4 100644
@@ -1882,7 +1882,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..234b39de7a1d 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].consumed = true;
+    }
+    bootstrap_map_bm(NULL);
 
     return 0;
 }
xen/xsm/xsm_policy.c +9 -11
index 8dafbc93810f..9fb8563eb571 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,26 +32,22 @@
 
 #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;
+    struct boot_module *bm;
 
     /*
      * 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_each_boot_module(bi, bm, BOOTMOD_UNKNOWN)
     {
-        if ( !test_bit(i, module_map) )
-            continue;
-
-        _policy_start = bootstrap_map(mod + i);
-        _policy_len   = mod[i].mod_end;
+        _policy_start = bootstrap_map_bm(bm);
+        _policy_len   = bm->size;
 
         if ( (xsm_magic_t)(*_policy_start) == XSM_MAGIC )
         {
@@ -60,12 +57,13 @@ int __init xsm_multiboot_policy_init(
             printk("Policy len %#lx, start at %p.\n",
                    _policy_len,_policy_start);
 
-            __clear_bit(i, module_map);
+            __clear_bit(boot_module_index(bi, bm), module_map);
+            bm->type = BOOTMOD_XSM_POLICY;
             break;
 
         }
 
-        bootstrap_map(NULL);
+        bootstrap_map_bm(NULL);
     }
 
     return rc;
Signature · 1 line
2.30.2
#21 lore raw

PATCH v7 15/38 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 ed1d89ad4bb4..153d361793c1 100644
@@ -2102,16 +2102,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].consumed = true;
+        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
#22 lore raw

PATCH v7 16/38 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    | 20 ++++++++------------
 xen/arch/x86/include/asm/microcode.h |  6 ++----
 xen/arch/x86/setup.c                 |  4 ++--
 3 files changed, 12 insertions(+), 18 deletions(-)
xen/arch/x86/cpu/microcode/core.c +8 -12
index 8ea789dceec2..938dfd74a9f1 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, struct boot_info *bi)
+static void __init microcode_scan_module(struct boot_info *bi)
 {
     uint64_t *_blob_start;
     unsigned long _blob_size;
@@ -199,19 +198,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;
@@ -815,8 +813,7 @@ static int __init early_update_cache(const void *data, size_t len)
     return rc;
 }
 
-int __init microcode_init_cache(
-    unsigned long *module_map, struct boot_info *bi)
+int __init microcode_init_cache(struct boot_info *bi)
 {
     int rc = 0;
 
@@ -825,7 +822,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->consumed )
         rc = early_update_cache(bootstrap_map_bm(ucode_mod),
@@ -871,8 +868,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;
@@ -915,7 +911,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 9e7c7ab004ed..917a861fd8f7 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, struct boot_info *bi);
+int early_microcode_init(struct boot_info *bi);
+int microcode_init_cache(struct boot_info *bi);
 int microcode_update_one(void);
 
 #endif /* ASM_X86__MICROCODE_H */
xen/arch/x86/setup.c +2 -2
index 153d361793c1..7fdbe57ca1c3 100644
@@ -1409,7 +1409,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 )
     {
@@ -1956,7 +1956,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
#23 lore raw

PATCH v7 17/38 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  | 4 +---
 4 files changed, 7 insertions(+), 14 deletions(-)
xen/arch/x86/setup.c +1 -1
index 7fdbe57ca1c3..84d6981f4e77 100644
@@ -1882,7 +1882,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 234b39de7a1d..d58042a1fa4a 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 +1 -3
index 9fb8563eb571..f1c94702f6e0 100644
@@ -32,8 +32,7 @@
 
 #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 rc = 0;
     u32 *_policy_start;
@@ -57,7 +56,6 @@ int __init xsm_multiboot_policy_init(
             printk("Policy len %#lx, start at %p.\n",
                    _policy_len,_policy_start);
 
-            __clear_bit(boot_module_index(bi, bm), module_map);
             bm->type = BOOTMOD_XSM_POLICY;
             break;
 
Signature · 1 line
2.30.2
#24 lore raw

PATCH v7 18/38 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 | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
xen/arch/x86/setup.c +2 -3
index 84d6981f4e77..4a482c8aefa4 100644
@@ -1053,7 +1053,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;
@@ -1217,8 +1217,7 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
                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].consumed = true;
 
Signature · 1 line
2.30.2
#25 lore raw

PATCH v7 19/38 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 4a482c8aefa4..347b27ad7c6c 100644
@@ -962,10 +962,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];
 
@@ -980,9 +978,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 |
@@ -1011,7 +1022,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. */
@@ -2123,10 +2134,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
#26 lore raw

PATCH v7 20/38 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 347b27ad7c6c..d7f03225bd5a 100644
@@ -962,7 +962,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];
@@ -978,21 +978,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 )
     {
@@ -1019,10 +1017,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. */
@@ -1045,7 +1044,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
#27 lore raw

PATCH v7 21/38 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 3ca56454c4d7..9bd0e6336b4a 100644
@@ -63,6 +63,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 d7f03225bd5a..6f953edd7521 100644
@@ -962,8 +962,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];
 
@@ -1017,15 +1016,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") )
@@ -1121,6 +1120,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);
 
@@ -2133,7 +2133,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
#28 lore raw

PATCH v7 22/38 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 9bd0e6336b4a..941363601db7 100644
@@ -52,6 +52,8 @@ struct boot_module {
     bool relocated:1;
     bool consumed:1;
 
+    paddr_t cmdline;
+
     paddr_t start;
     size_t size;
 };
xen/arch/x86/setup.c +6 -3
index 6f953edd7521..254aeb0c5e1b 100644
@@ -318,6 +318,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;
+
         if ( !efi_enabled(EFI_LOADER) )
         {
             bi->mods[i].start = mods[i].mod_start;
@@ -1016,10 +1018,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
#29 lore raw

PATCH v7 23/38 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 v6:
- removed unnecessary indentation changes

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 |  3 +--
 xen/arch/x86/pv/dom0_build.c          | 16 +++++++---------
 3 files changed, 9 insertions(+), 13 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 +1 -2
index 107c1ff98367..66ea70869c49 100644
@@ -13,8 +13,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 module_t *image,
-                      unsigned long image_headroom,
+int dom0_construct_pv(struct domain *d, const struct boot_module *image,
                       module_t *initrd,
                       const char *cmdline);
 
xen/arch/x86/pv/dom0_build.c +7 -9
index ee9ecdc2abbf..db4c066e626b 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)
 {
@@ -1073,7 +1071,7 @@ int __init dom0_construct_pv(struct domain *d,
         write_cr4(cr4 & ~X86_CR4_SMAP);
     }
 
-    rc = dom0_construct(d, image, image_headroom, initrd, cmdline);
+    rc = dom0_construct(d, image, initrd, cmdline);
 
     if ( cr4 & X86_CR4_SMAP )
     {
Signature · 1 line
2.30.2
#30 lore raw

PATCH v7 24/38 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 v6:
- removed unnecessary indentation changes

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 66ea70869c49..3ddd22fad2ba 100644
@@ -14,7 +14,7 @@ unsigned long dom0_compute_nr_pages(struct domain *d,
 int dom0_setup_permissions(struct domain *d);
 
 int dom0_construct_pv(struct domain *d, const struct boot_module *image,
-                      module_t *initrd,
+                      struct boot_module *initrd,
                       const char *cmdline);
 
 int dom0_construct_pvh(struct domain *d, const module_t *image,
xen/arch/x86/pv/dom0_build.c +16 -13
index db4c066e626b..45a386aa81f0 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)
 {
     unsigned long cr4 = read_cr4();
Signature · 1 line
2.30.2
#31 lore raw

PATCH v7 25/38 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.

---
Changes since v6:
- removed unnecessary indentation changes

---
 xen/arch/x86/dom0_build.c             | 3 +--
 xen/arch/x86/hvm/dom0_build.c         | 9 ++++-----
 xen/arch/x86/include/asm/dom0_build.h | 5 ++---
 3 files changed, 7 insertions(+), 10 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 +4 -5
index 3dd913bdb029..0fe63f040936 100644
@@ -1300,9 +1300,8 @@ 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,
+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;
@@ -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 +2 -3
index 3ddd22fad2ba..5d0c4fd2639a 100644
@@ -17,9 +17,8 @@ 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,
+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,
Signature · 1 line
2.30.2
#32 lore raw

PATCH v7 26/38 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 0fe63f040936..211f4e3e772e 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(struct domain *d, const struct boot_module *image,
         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
#33 lore raw

PATCH v7 27/38 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 254aeb0c5e1b..0f8fb3c572c6 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 = {
     .loader = "unknown",
@@ -352,8 +352,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);
@@ -369,10 +369,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;
@@ -1403,11 +1404,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; !efi_enabled(EFI_LOADER) && i < bi->nr_modules; i++ )
     {
Signature · 1 line
2.30.2
#34 lore raw

PATCH v7 28/38 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 0f8fb3c572c6..87b118cdcf1e 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 = {
     .loader = "unknown",
     .cmdline = "",
@@ -352,8 +350,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);
@@ -370,14 +368,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)
@@ -1404,8 +1400,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; !efi_enabled(EFI_LOADER) && i < bi->nr_modules; i++ )
     {
         if ( bi->mods[i].mod->mod_start & (PAGE_SIZE - 1) )
Signature · 1 line
2.30.2
#35 lore raw

PATCH v7 29/38 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 87b118cdcf1e..67e72459170a 100644
@@ -367,10 +367,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
#36 lore raw

PATCH v7 30/38 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 v6:
- drop efi exclusion check for module memory alignment validation

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             | 29 ++++++++++-------------------
 2 files changed, 10 insertions(+), 20 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 +10 -19
index 67e72459170a..2102923cd510 100644
@@ -350,8 +350,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);
@@ -488,7 +488,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);
@@ -678,8 +678,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;
@@ -1399,12 +1399,10 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
     set_kexec_crash_area_size((u64)nr_pages << PAGE_SHIFT);
     kexec_reserve_area();
 
-    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) )
+        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;
     }
 
     /*
@@ -1425,16 +1423,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 = paddr_to_pfn(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. */
@@ -1535,9 +1528,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->relocated = true;
             }
         }
Signature · 1 line
2.30.2
#37 lore raw

PATCH v7 31/38 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 | 4 ----
 xen/arch/x86/setup.c                | 3 ---
 2 files changed, 7 deletions(-)
xen/arch/x86/include/asm/bootinfo.h +0 -4
index 941363601db7..eaed99b64e57 100644
@@ -8,7 +8,6 @@
 #ifndef X86_BOOTINFO_H
 #define 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,9 +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 -3
index 2102923cd510..1fda462ba1d0 100644
@@ -314,8 +314,6 @@ static struct boot_info *__init multiboot_fill_boot_info(unsigned long mbi_p)
      */
     for ( i = 0; i < MAX_NR_BOOTMODS && i < bi->nr_modules; i++ )
     {
-        bi->mods[i].mod = &mods[i];
-
         bi->mods[i].cmdline = (paddr_t)mods[i].string;
 
         if ( !efi_enabled(EFI_LOADER) )
@@ -331,7 +329,6 @@ static struct boot_info *__init multiboot_fill_boot_info(unsigned long mbi_p)
     }
 
     /* Variable 'i' should be one entry past the last module. */
-    bi->mods[i].mod = &mods[bi->nr_modules];
     bi->mods[i].start = mods[i].mod_start;
     bi->mods[i].size = mods[i].mod_end - mods[i].mod_start;
     bi->mods[i].type = BOOTMOD_XEN;
Signature · 1 line
2.30.2
#38 lore raw

PATCH v7 32/38 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 eaed99b64e57..3fb23e90d712 100644
@@ -9,10 +9,14 @@
 #define 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,
@@ -68,6 +72,7 @@ struct boot_info {
 
     unsigned int nr_modules;
     struct boot_module mods[MAX_NR_BOOTMODS + 1];
+    struct boot_domain domains[MAX_NR_BOOTDOMS];
 };
 
 static inline struct boot_module *__init next_boot_module_by_type(
xen/arch/x86/setup.c +7 -16
index 1fda462ba1d0..9b2a16863eae 100644
@@ -972,20 +972,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 |
@@ -1011,11 +1001,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 )
@@ -1039,7 +1028,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;
@@ -1226,6 +1215,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].consumed = true;
+    bi->domains[0].kernel = &bi->mods[0];
 
     if ( pvh_boot )
     {
@@ -2104,6 +2094,7 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
     {
         bi->mods[initrdidx].type = BOOTMOD_RAMDISK;
         bi->mods[initrdidx].consumed = true;
+        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
#39 lore raw

PATCH v7 33/38 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 9b2a16863eae..e6756d0ad18d 100644
@@ -334,6 +334,9 @@ static struct boot_info *__init multiboot_fill_boot_info(unsigned long mbi_p)
     bi->mods[i].type = BOOTMOD_XEN;
     bi->mods[i].consumed = true;
 
+    for ( i = 0; i < MAX_NR_BOOTDOMS; i++ )
+        bi->domains[i].domid = DOMID_INVALID;
+
     return bi;
 }
 
@@ -974,7 +977,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 )
     {
@@ -990,15 +992,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
#40 lore raw

PATCH v7 34/38 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 e6756d0ad18d..47b705097dd3 100644
@@ -962,8 +962,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,
@@ -1006,16 +1004,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 )
         {
@@ -1023,14 +1021,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
#41 lore raw

PATCH v7 35/38 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 47b705097dd3..9423e999990a 100644
@@ -1028,10 +1028,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
#42 lore raw

PATCH v7 36/38 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 9423e999990a..ed4bf3d2b62b 100644
@@ -1030,7 +1030,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
#43 lore raw

PATCH v7 37/38 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 5d0c4fd2639a..eafa741db16f 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,
                        struct boot_module *initrd,
xen/arch/x86/pv/dom0_build.c +18 -23

107 lines not on this page · raw message

Signature · 1 line
2.30.2
#44 lore raw

PATCH v7 38/38 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 211f4e3e772e..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(struct domain *d, const struct boot_module *image,
         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 eafa741db16f..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