diff mbox series

[v5,09/44] x86/boot: introduce boot module types

Message ID 20241006214956.24339-10-dpsmith@apertussolutions.com (mailing list archive)
State Superseded
Headers show
Series Boot modules for Hyperlaunch | expand

Commit Message

Daniel P. Smith Oct. 6, 2024, 9:49 p.m. UTC
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.

Signed-off-by: Daniel P. Smith <dpsmith@apertussolutions.com>
---
 xen/arch/x86/include/asm/bootinfo.h | 9 +++++++++
 xen/arch/x86/setup.c                | 6 ++++++
 2 files changed, 15 insertions(+)

Comments

Jason Andryuk Oct. 7, 2024, 7:50 p.m. UTC | #1
On 2024-10-06 17:49, Daniel P. Smith wrote:
> 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.
> 
> Signed-off-by: Daniel P. Smith <dpsmith@apertussolutions.com>
> ---

> @@ -2058,6 +2063,7 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
>              cpu_has_nx ? "" : "not ");
>   
>       initrdidx = find_first_bit(module_map, bi->nr_modules);
> +    bi->mods[initrdidx].type = BOOTMOD_RAMDISK;

This is incorrect if an initrd isn't present.

>       if ( bitmap_weight(module_map, bi->nr_modules) > 1 )
>           printk(XENLOG_WARNING
>                  "Multiple initrd candidates, picking module #%u\n",
Daniel P. Smith Oct. 9, 2024, 2:25 p.m. UTC | #2
On 10/7/24 15:50, Jason Andryuk wrote:
> On 2024-10-06 17:49, Daniel P. Smith wrote:
>> 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.
>>
>> Signed-off-by: Daniel P. Smith <dpsmith@apertussolutions.com>
>> ---
> 
>> @@ -2058,6 +2063,7 @@ void asmlinkage __init noreturn 
>> __start_xen(unsigned long mbi_p)
>>              cpu_has_nx ? "" : "not ");
>>       initrdidx = find_first_bit(module_map, bi->nr_modules);
>> +    bi->mods[initrdidx].type = BOOTMOD_RAMDISK;
> 
> This is incorrect if an initrd isn't present.

Correct, will put behind guard.

v/r,
dps
Jan Beulich Oct. 9, 2024, 3:30 p.m. UTC | #3
On 06.10.2024 23:49, Daniel P. Smith wrote:
> --- a/xen/arch/x86/setup.c
> +++ b/xen/arch/x86/setup.c
> @@ -311,6 +311,10 @@ static struct boot_info __init *multiboot_fill_boot_info(unsigned long mbi_p)
>      for ( i = 0; i <= bi->nr_modules; i++ )
>          bi->mods[i].mod = &mods[i];

This loop, on its last iteration, has done ...

> +    /* map the last mb module for xen entry */
> +    bi->mods[bi->nr_modules].type = BOOTMOD_XEN;
> +    bi->mods[bi->nr_modules].mod = &mods[bi->nr_modules];

... this assignment already, hasn't it?

Jan
Daniel P. Smith Oct. 10, 2024, 1:11 a.m. UTC | #4
On 10/9/24 11:30, Jan Beulich wrote:
> On 06.10.2024 23:49, Daniel P. Smith wrote:
>> --- a/xen/arch/x86/setup.c
>> +++ b/xen/arch/x86/setup.c
>> @@ -311,6 +311,10 @@ static struct boot_info __init *multiboot_fill_boot_info(unsigned long mbi_p)
>>       for ( i = 0; i <= bi->nr_modules; i++ )
>>           bi->mods[i].mod = &mods[i];
> 
> This loop, on its last iteration, has done ...
> 
>> +    /* map the last mb module for xen entry */
>> +    bi->mods[bi->nr_modules].type = BOOTMOD_XEN;
>> +    bi->mods[bi->nr_modules].mod = &mods[bi->nr_modules];
> 
> ... this assignment already, hasn't it?

Yep, looks like I missed that the rebase of this commit put the 
assignment back in. Will make sure it's not re-inserted.

v/r,
dps
diff mbox series

Patch

diff --git a/xen/arch/x86/include/asm/bootinfo.h b/xen/arch/x86/include/asm/bootinfo.h
index c7e6b4ebf0da..6941a8975ea6 100644
--- a/xen/arch/x86/include/asm/bootinfo.h
+++ b/xen/arch/x86/include/asm/bootinfo.h
@@ -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;
@@ -22,6 +30,7 @@  struct boot_module {
      * reserved, into which it will be decompressed.
      */
     unsigned long headroom;
+    enum bootmod_type type;
 };
 
 /*
diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
index ba4bee6b93af..69c45f115523 100644
--- a/xen/arch/x86/setup.c
+++ b/xen/arch/x86/setup.c
@@ -311,6 +311,10 @@  static struct boot_info __init *multiboot_fill_boot_info(unsigned long mbi_p)
     for ( i = 0; i <= bi->nr_modules; i++ )
         bi->mods[i].mod = &mods[i];
 
+    /* map the last mb module for xen entry */
+    bi->mods[bi->nr_modules].type = BOOTMOD_XEN;
+    bi->mods[bi->nr_modules].mod = &mods[bi->nr_modules];
+
     return bi;
 }
 
@@ -1171,6 +1175,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 )
     {
@@ -2058,6 +2063,7 @@  void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
            cpu_has_nx ? "" : "not ");
 
     initrdidx = find_first_bit(module_map, 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",