Skip to contentSkip to conversation

multiboot2: Add module load and preference tag

PATCH Superseded Zide Chen 2 participants 4 messages May 7, 2020 – May 13, 2020

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Zide Chen

author
#0 lore raw

PATCH v2 1/1 multiboot2: Add module load and preference tag

In the cases of users have preferences over Multiboot2 module load addresses, currently GRUB has no way to achieve it.

Similar to the relocatable header tag, this new tag allows users to specify the minimum and maximum load addresses, and other load preferences on Multiboot2 modules.

---
 doc/multiboot.texi | 41 +++++++++++++++++++++++++++++++++++++++++
 doc/multiboot2.h   | 11 +++++++++++
 2 files changed, 52 insertions(+)
doc/multiboot.texi +41 -0
index df8a0d056e76..758ef7fd1e2d 100644
@@ -356,6 +356,7 @@ executable header.
 * Module alignment tag::
 * EFI boot services tag::
 * Relocatable header tag::
+* Module load preferences tag::
 
 @end menu
 
@@ -730,6 +731,46 @@ Boot loader should follow it. @samp{0} means none, @samp{1} means
 load image at lowest possible address but not lower than min_addr
 and @samp{2} means load image at highest possible address but not
 higher than max_addr.
+
+@node Module load preferences tag
+@subsection Module load preferences tag
+
+@example
+@group
+        +-------------------+
+u16     | type = 11         |
+u16     | flags             |
+u32     | size = 20         |
+u32     | min_addr          |
+u32     | max_addr          |
+u32     | preference        |
+        +-------------------+
+@end group
+@end example
+
+This tag is independent to the relocatable header tag. All of the
+address fields in this tag are physical addresses.
+
+The meaning of each field is as follows:
+
+@table @code
+@item min_addr
+Lowest possible physical address at which any modules should be
+loaded. The bootloader cannot load any part of any modules below
+this address.
+
+@item max_addr
+Highest possible physical address at which any loaded modules should
+end. The bootloader cannot load any part of any modules above this
+address.
+
+@item preference
+It contains load address placement suggestion for boot loader.
+Boot loader should follow it. @samp{0} means load modules not lower
+than min_addr and not higher than max_addr, but no preference on either
+lower or higher address. @samp{1} means load modules at lowest possible
+address but not lower than min_addr. @samp{2} means load modules at
+highest possible address but not higher than max_addr.
 @end table
 
 @node Machine state
doc/multiboot2.h +11 -0
index b181607075b2..a68013ad932f 100644
@@ -75,6 +75,7 @@
 #define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI32  8
 #define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64  9
 #define MULTIBOOT_HEADER_TAG_RELOCATABLE  10
+#define MULTIBOOT_HEADER_TAG_MODULE_LOAD_PREFERENCES  11
 
 #define MULTIBOOT_ARCHITECTURE_I386  0
 #define MULTIBOOT_ARCHITECTURE_MIPS32  4
@@ -179,6 +180,16 @@ struct multiboot_header_tag_relocatable
   multiboot_uint32_t preference;
 };
 
+struct multiboot_header_tag_module_load_preferences
+{
+  multiboot_uint16_t type;
+  multiboot_uint16_t flags;
+  multiboot_uint32_t size;
+  multiboot_uint32_t min_addr;
+  multiboot_uint32_t max_addr;
+  multiboot_uint32_t preference;
+};
+
 struct multiboot_color
 {
   multiboot_uint8_t red;
Signature · 1 line
2.17.1
#1 lore raw
Quoted 18 lines · Zide Chen

In the cases of users have preferences over Multiboot2 module load addresses, currently GRUB has no way to achieve it.

Similar to the relocatable header tag, this new tag allows users to specify the minimum and maximum load addresses, and other load preferences on Multiboot2 modules.

---
 doc/multiboot.texi | 41 +++++++++++++++++++++++++++++++++++++++++
 doc/multiboot2.h   | 11 +++++++++++
 2 files changed, 52 insertions(+)
doc/multiboot.texi +0 -0
index df8a0d056e76..758ef7fd1e2d 100644

doc/multiboot.texi executable header. · line 359

Quoted 4 lines
doc/multiboot.texi +1 -0
@@ -356,6 +356,7 @@ executable header.
 * Module alignment tag::
 * EFI boot services tag::
 * Relocatable header tag::
+* Module load preferences tag::

Please bump spec version to 2.1.

Quoted 8 lines
doc/multiboot.texi +2 -0
 @end menu
 
@@ -730,6 +731,46 @@ Boot loader should follow it. @samp{0} means none, @samp{1} means
 load image at lowest possible address but not lower than min_addr
 and @samp{2} means load image at highest possible address but not
 higher than max_addr.
+
+@node Module load preferences tag

doc/multiboot.texi Boot loader should follow it. @samp{0} means none, @samp{1} means · line 745

Quoted 10 lines
doc/multiboot.texi +10 -0
+@subsection Module load preferences tag
+
+@example
+@group
+        +-------------------+
+u16     | type = 11         |
+u16     | flags             |
+u32     | size = 20         |
+u32     | min_addr          |
+u32     | max_addr          |

I have an itching to add "align" member here like in the relocatable header tag. I can imagine that some kernels may want aligned modules. If you do that then we have to resolve conflict with the module alignment tag. I think if both tags are in the image header then the bootloader should use max(align, PAGE_SIZE). This behavior should be described in one way or another next to both tags.

doc/multiboot.texi Boot loader should follow it. @samp{0} means none, @samp{1} means · line 750

Quoted 5 lines
doc/multiboot.texi +5 -0
+u32     | preference        |
+        +-------------------+
+@end group
+@end example
+

Please describe shortly what this tag does. You can find good example in relocatable header tag.

doc/multiboot.texi Boot loader should follow it. @samp{0} means none, @samp{1} means · line 751

Quoted 1 line
doc/multiboot.texi +1 -0
+This tag is independent to the relocatable header tag. All of the

This sentence should go to the end of the tag description.

Quoted 12 lines
doc/multiboot.texi +12 -0
+address fields in this tag are physical addresses.
+
+The meaning of each field is as follows:
+
+@table @code
+@item min_addr
+Lowest possible physical address at which any modules should be
+loaded. The bootloader cannot load any part of any modules below
+this address.
+
+@item max_addr
+Highest possible physical address at which any loaded modules should

doc/multiboot.texi Boot loader should follow it. @samp{0} means none, @samp{1} means · line 773

Quoted 10 lines
doc/multiboot.texi +10 -0
+end. The bootloader cannot load any part of any modules above this
+address.
+
+@item preference
+It contains load address placement suggestion for boot loader.
+Boot loader should follow it. @samp{0} means load modules not lower
+than min_addr and not higher than max_addr, but no preference on either
+lower or higher address. @samp{1} means load modules at lowest possible
+address but not lower than min_addr. @samp{2} means load modules at
+highest possible address but not higher than max_addr.

Please copy preference description from relocatable header tag and replace "image" with "module".

Daniel

author
#2 lore raw

Hi Daniel,

Quoted 7 lines

-----Original Message-----
From: Daniel Kiper <[email protected]>
Sent: Wednesday, May 13, 2020 8:54 AM
To: Chen, Zide <[email protected]>
Cc: [email protected]
Subject: Re: [MULTIBOOT2 SPEC PATCH V2] multiboot2: Add module load and preference tag

Quoted 11 lines

doc/multiboot.texi executable header. · line 359

Quoted 9 lines
doc/multiboot.texi +1 -0
index df8a0d056e76..758ef7fd1e2d 100644
@@ -356,6 +356,7 @@ executable header.
 * Module alignment tag::
 * EFI boot services tag::
 * Relocatable header tag::
+* Module load preferences tag::

Please bump spec version to 2.1.

OK, will do it, also will add 2020 to the copyright in configure.ac.

Quoted 17 lines
Quoted 17 lines
doc/multiboot.texi +11 -0
 @end menu
 
@@ -730,6 +731,46 @@ Boot loader should follow it. @samp{0} means none, @samp{1} means
 load image at lowest possible address but not lower than min_addr
 and @samp{2} means load image at highest possible address but not
 higher than max_addr.
+
+@node Module load preferences tag
+@subsection Module load preferences tag
+
+@example
+@group
+        +-------------------+
+u16     | type = 11         |
+u16     | flags             |
+u32     | size = 20         |
+u32     | min_addr          |
Quoted 8 lines

doc/multiboot.texi Boot loader should follow it. @samp{0} means none, @samp{1} means · line 745

Quoted 1 line
doc/multiboot.texi +1 -0
+u32     | max_addr          |

I have an itching to add "align" member here like in the relocatable header tag. I can imagine that some kernels may want aligned modules. If you do that then we have to resolve conflict with the module alignment tag. I think if both tags are in the image header then the bootloader should use max(align, PAGE_SIZE). This behavior should be described in one way or another next to both tags.

Yes, I thought about the align member.
Sure, I can add the it to the spec. Since we give user the flexibility to specify alignment, why we would overwrite user's choice to force it to minimum PAGE_SIZE aligned? How about pick the maximum alignment of the two tags?

But in GRUB's implementation, since GRUB ignores the module alignment tag, the behavior Could be these:

If align is zero in this tag: module alignment is PAGE_SIZE (

If align is none-zero, Grub will use whatever value it is to load modules.

Quoted 8 lines

doc/multiboot.texi Boot loader should follow it. @samp{0} means none, @samp{1} means · line 750

Quoted 5 lines
doc/multiboot.texi +5 -0
+u32     | preference        |
+        +-------------------+
+@end group
+@end example
+

Please describe shortly what this tag does. You can find good example in relocatable header tag.

OK.

Quoted 3 lines

doc/multiboot.texi Boot loader should follow it. @samp{0} means none, @samp{1} means · line 751

Quoted 1 line
doc/multiboot.texi +1 -0
+This tag is independent to the relocatable header tag. All of the

This sentence should go to the end of the tag description.

OK.

Quoted 17 lines
Quoted 17 lines
doc/multiboot.texi +17 -0
+address fields in this tag are physical addresses.
+
+The meaning of each field is as follows:
+
+@table @code
+@item min_addr
+Lowest possible physical address at which any modules should be
+loaded. The bootloader cannot load any part of any modules below
+this address.
+
+@item max_addr
+Highest possible physical address at which any loaded modules should
+end. The bootloader cannot load any part of any modules above this
+address.
+
+@item preference
+It contains load address placement suggestion for boot loader.
Quoted 8 lines

doc/multiboot.texi Boot loader should follow it. @samp{0} means none, @samp{1} means · line 773

Quoted 5 lines
doc/multiboot.texi +5 -0
+Boot loader should follow it. @samp{0} means load modules not lower
+than min_addr and not higher than max_addr, but no preference on either
+lower or higher address. @samp{1} means load modules at lowest possible
+address but not lower than min_addr. @samp{2} means load modules at
+highest possible address but not higher than max_addr.

Please copy preference description from relocatable header tag and replace "image" with "module".

Will do.

Best Regards,
Zide

Quoted 1 line

Daniel

author
#3 lore raw

Hi Daniel,

Quoted 36 lines

-----Original Message-----
From: Chen, Zide
Sent: Wednesday, May 13, 2020 3:39 PM
To: 'Daniel Kiper' <[email protected]>
Cc: [email protected]
Subject: RE: [MULTIBOOT2 SPEC PATCH V2] multiboot2: Add module load and preference tag

Quoted 16 lines
Quoted 16 lines
doc/multiboot.texi +11 -0
@@ -730,6 +731,46 @@ Boot loader should follow it. @samp{0} means none, @samp{1} means
 load image at lowest possible address but not lower than min_addr
 and @samp{2} means load image at highest possible address but not
 higher than max_addr.
+
+@node Module load preferences tag
+@subsection Module load preferences tag
+
+@example
+@group
+        +-------------------+
+u16     | type = 11         |
+u16     | flags             |
+u32     | size = 20         |
+u32     | min_addr          |
Quoted 8 lines

doc/multiboot.texi Boot loader should follow it. @samp{0} means none, @samp{1} means · line 745

Quoted 1 line
doc/multiboot.texi +1 -0
+u32     | max_addr          |

I have an itching to add "align" member here like in the relocatable header tag. I can imagine that some kernels may want aligned modules. If you do that then we have to resolve conflict with the module alignment tag. I think if both tags are in the image header then the bootloader should use max(align, PAGE_SIZE). This behavior should be described in one way or another next to both tags.

Yes, I thought about the align member.
Sure, I can add the it to the spec. Since we give user the flexibility to specify alignment, why we would overwrite user's choice to force it to minimum PAGE_SIZE aligned? How about pick the maximum alignment of the two tags?

Quoted 6 lines

But in GRUB's implementation, since GRUB ignores the module alignment tag, the behavior Could be these:

If align is zero in this tag: module alignment is PAGE_SIZE (

If align is none-zero, Grub will use whatever value it is to load modules.

You are right. Please ignore my previous comments. I have sent out the updated patch for review.

-Zide