[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 05/12] x86/boot: move headroom to boot modules


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: "Daniel P. Smith" <dpsmith@xxxxxxxxxxxxxxxxxxxx>
  • Date: Sat, 2 Nov 2024 13:25:44 -0400
  • Arc-authentication-results: i=1; mx.zohomail.com; dkim=pass header.i=apertussolutions.com; spf=pass smtp.mailfrom=dpsmith@xxxxxxxxxxxxxxxxxxxx; dmarc=pass header.from=<dpsmith@xxxxxxxxxxxxxxxxxxxx>
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730568379; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=IkU4V9zheGmMbE9F1wh08/Ap7m7WOTpvdQ1/oa+ZpD8=; b=NYUw0b5xZJxFu0ddjhlUI0/2WD7p6PD+ndizVHfUaKOUjDxTg6o37hSHMrVklqUupX1pb8ndpRoyshKCX3LozvxiX9tuIkFeW98JQlrstT6VeeOjEWD3E05Ze6bKbb1OvZ1oVbclB4EBK45mjibU9ChedPKOPJc7+66XjfI9NVY=
  • Arc-seal: i=1; a=rsa-sha256; t=1730568379; cv=none; d=zohomail.com; s=zohoarc; b=MDs4UQlt+6cs2MV/bWPoLf5yewGv93jWyeHDuTpMW6SgVw2/JVod3CnrXWklN+pLDNKziIrJb9KVATzKRFkUxkZuokVak1GIfmKZI8C6K8lL4qVUVKMQvzDVcxyKnTcW8d8bizs3lctc4ihG6PjNksGe4w3eCDaSWz0e9tKJjfA=
  • Cc: "Daniel P. Smith" <dpsmith@xxxxxxxxxxxxxxxxxxxx>, jason.andryuk@xxxxxxx, christopher.w.clark@xxxxxxxxx, stefano.stabellini@xxxxxxx, Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Delivery-date: Sat, 02 Nov 2024 17:27:03 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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.

Signed-off-by: Daniel P. Smith <dpsmith@xxxxxxxxxxxxxxxxxxxx>
Reviewed-by: Jason Andryuk <jason.andryuk@xxxxxxx>
---
Changes since v7:
- adopted headroom comment from Andy Cooper

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 | 22 ++++++++++++++++++++++
 xen/arch/x86/setup.c                | 23 ++++++++---------------
 2 files changed, 30 insertions(+), 15 deletions(-)

diff --git a/xen/arch/x86/include/asm/bootinfo.h 
b/xen/arch/x86/include/asm/bootinfo.h
index b1549d8c8f93..e337baa905f0 100644
--- a/xen/arch/x86/include/asm/bootinfo.h
+++ b/xen/arch/x86/include/asm/bootinfo.h
@@ -30,6 +30,28 @@ struct boot_module {
 
     enum bootmod_type type;
 
+    /*
+     * 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.
+     *
+     * Memory layout at boot:
+     *
+     *               start ----+
+     *                         v
+     *   |<-----headroom------>|<------size------->|
+     *                         +-------------------+
+     *                         | Compressed Module |
+     *   +---------------------+-------------------+
+     *   |           Decompressed Module           |
+     *   +-----------------------------------------+
+     */
+    unsigned long headroom;
+
     /*
      * Module State Flags:
      *   relocated: indicates module has been relocated in memory.
diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
index e6d2d25fd038..633319d39d80 100644
--- a/xen/arch/x86/setup.c
+++ b/xen/arch/x86/setup.c
@@ -1062,7 +1062,7 @@ void asmlinkage __init noreturn __start_xen(void)
     struct cpu_info *info = get_cpu_info(), *bsp_info;
     unsigned int initrdidx, num_parked = 0;
     struct boot_info *bi;
-    unsigned long nr_pages, raw_max_page, modules_headroom;
+    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;
@@ -1443,7 +1443,7 @@ void asmlinkage __init noreturn __start_xen(void)
         xen->mod->mod_end   = __2M_rwdata_end - _stext;
     }
 
-    modules_headroom =
+    bi->mods[0].headroom =
         bzimage_headroom(bootstrap_map_bm(&bi->mods[0]),
                          bi->mods[0].mod->mod_end);
     bootstrap_unmap();
@@ -1526,14 +1526,7 @@ void asmlinkage __init noreturn __start_xen(void)
         for ( j = bi->nr_modules - 1; j >= 0; j-- )
         {
             struct boot_module *bm = &bi->mods[j];
-
-            /*
-             * 'headroom' is a guess for the decompressed size and
-             * 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 + bm->mod->mod_end);
+            unsigned long size = PAGE_ALIGN(bm->headroom + bm->mod->mod_end);
 
             if ( bm->relocated )
                 continue;
@@ -1546,13 +1539,13 @@ void asmlinkage __init noreturn __start_xen(void)
                 continue;
 
             if ( s < end &&
-                 (headroom ||
+                 (bm->headroom ||
                   ((end - size) >> PAGE_SHIFT) > bm->mod->mod_start) )
             {
-                move_memory(end - size + headroom,
+                move_memory(end - size + bm->headroom,
                             pfn_to_paddr(bm->mod->mod_start), 
bm->mod->mod_end);
                 bm->mod->mod_start = (end - size) >> PAGE_SHIFT;
-                bm->mod->mod_end += headroom;
+                bm->mod->mod_end += bm->headroom;
                 bm->relocated = true;
             }
         }
@@ -1579,7 +1572,7 @@ void asmlinkage __init noreturn __start_xen(void)
 #endif
     }
 
-    if ( modules_headroom && !bi->mods[0].relocated )
+    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 )
     {
@@ -2145,7 +2138,7 @@ void asmlinkage __init noreturn __start_xen(void)
      * 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, modules_headroom,
+    dom0 = create_dom0(bi->mods[0].mod, bi->mods[0].headroom,
                        initrdidx < bi->nr_modules ? bi->mods[initrdidx].mod
                                                   : NULL,
                        kextra, bi->loader);
-- 
2.30.2




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.