Skip to contentSkip to conversation

x86/Documentation: Update algo in init_size description of boot protocol

PATCH Superseded Andy Shevchenko 4 participants 7 messages Nov 25, 2024

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/Documentation: Update algo in init_size description of boot protocol

The init_size description of boot protocol has an example of the runtime start address for the compressed bzImage. For non-relocatable kernel it relies on the pref_address value (if not 0), but for relocatable case only pays respect to the load_addres and kernel_alignment, and it is inaccurate for the latter. Boot loader must consider the pref_address as the Linux kernel relocates to it before being decompressed as nicely described in the commit 43b1d3e68ee7 message.

Due to this inaccuracy some of the bootloaders (*) made a mistake in the calculations and if kernel image is big enough, this may lead to unbootable configurations.

*)
In particular, kexec-tools missed that and resently got a couple of changes which will be part of v2.0.30 release. For the record, the 43b1d3e68ee7 fixed only kernel kexec implementation and also missed to update the init_size description.

While at it, make an example C-like looking as it's done elsewhere in the document and fix indentation, so the syntax highliting will work properly in some editors (vim).

Fixes 43b1d3e68ee7 ("kexec: Allocate kernel above bzImage's pref_address")
Fixes d297366ba692 ("x86: document new bzImage fields")
---
 Documentation/arch/x86/boot.rst | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
Documentation/arch/x86/boot.rst +13 -4
index 4fd492cb4970..01f08d94e8df 100644
@@ -896,10 +896,19 @@ Offset/size:	0x260/4
 
   The kernel runtime start address is determined by the following algorithm::
 
-	if (relocatable_kernel)
-	runtime_start = align_up(load_address, kernel_alignment)
-	else
-	runtime_start = pref_address
+    if ( relocatable_kernel ) {
+      if ( load_address < pref_address )
+        load_address = pref_address;
+      runtime_start = align_up(load_address, kernel_alignment);
+    } else {
+      runtime_start = pref_address;
+    }
+
+Hence the necessary memory window location and size can be estimated by
+a boot loader as::
+
+    memory_window_start = runtime_start;
+    memory_window_size = init_size;
 
 ============	===============
 Field name:	handover_offset
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
reviewer
#1 lore raw

Hi Andy,

Quoted 34 lines · Andy Shevchenko

The init_size description of boot protocol has an example of the runtime start address for the compressed bzImage. For non-relocatable kernel it relies on the pref_address value (if not 0), but for relocatable case only pays respect to the load_addres and kernel_alignment, and it is inaccurate for the latter. Boot loader must consider the pref_address as the Linux kernel relocates to it before being decompressed as nicely described in the commit 43b1d3e68ee7 message.

Due to this inaccuracy some of the bootloaders (*) made a mistake in the calculations and if kernel image is big enough, this may lead to unbootable configurations.

*)
In particular, kexec-tools missed that and resently got a couple of changes which will be part of v2.0.30 release. For the record, the 43b1d3e68ee7 fixed only kernel kexec implementation and also missed to update the init_size description.

While at it, make an example C-like looking as it's done elsewhere in the document and fix indentation, so the syntax highliting will work properly in some editors (vim).

Fixes 43b1d3e68ee7 ("kexec: Allocate kernel above bzImage's pref_address")
Fixes d297366ba692 ("x86: document new bzImage fields")
---
 Documentation/arch/x86/boot.rst | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
Documentation/arch/x86/boot.rst +0 -0
index 4fd492cb4970..01f08d94e8df 100644

Documentation/arch/x86/boot.rst Offset/size: 0x260/4 · line 900

Quoted 9 lines
Documentation/arch/x86/boot.rst +2 -4
@@ -896,10 +896,19 @@ Offset/size:	0x260/4
 
   The kernel runtime start address is determined by the following algorithm::
 
-	if (relocatable_kernel)
-	runtime_start = align_up(load_address, kernel_alignment)
-	else
-	runtime_start = pref_address
+    if ( relocatable_kernel ) {
+      if ( load_address < pref_address )

What's up with the extra spaces around ( and ) ... and inconsistent with the lines below?

Quoted 14 lines
Documentation/arch/x86/boot.rst +11 -0
+        load_address = pref_address;
+      runtime_start = align_up(load_address, kernel_alignment);
+    } else {
+      runtime_start = pref_address;
+    }
+
+Hence the necessary memory window location and size can be estimated by
+a boot loader as::
+
+    memory_window_start = runtime_start;
+    memory_window_size = init_size;
 
 ============	===============
 Field name:	handover_offset
Signature · 1 line
~Randy
#2 lore raw
Quoted 40 lines · Randy Dunlap

Hi Andy,

Quoted 37 lines · Andy Shevchenko

The init_size description of boot protocol has an example of the runtime start address for the compressed bzImage. For non-relocatable kernel it relies on the pref_address value (if not 0), but for relocatable case only pays respect to the load_addres and kernel_alignment, and it is inaccurate for the latter. Boot loader must consider the pref_address as the Linux kernel relocates to it before being decompressed as nicely described in the commit 43b1d3e68ee7 message.

Due to this inaccuracy some of the bootloaders (*) made a mistake in the calculations and if kernel image is big enough, this may lead to unbootable configurations.

*)
In particular, kexec-tools missed that and resently got a couple of changes which will be part of v2.0.30 release. For the record, the 43b1d3e68ee7 fixed only kernel kexec implementation and also missed to update the init_size description.

While at it, make an example C-like looking as it's done elsewhere in the document and fix indentation, so the syntax highliting will work properly in some editors (vim).

Fixes 43b1d3e68ee7 ("kexec: Allocate kernel above bzImage's pref_address")
Fixes d297366ba692 ("x86: document new bzImage fields")
---
 Documentation/arch/x86/boot.rst | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
Documentation/arch/x86/boot.rst +0 -0
index 4fd492cb4970..01f08d94e8df 100644
@@ -896,10 +896,19 @@ Offset/size:	0x260/4
 
   The kernel runtime start address is determined by the following algorithm::
 
Quoted 9 lines

Documentation/arch/x86/boot.rst Offset/size: 0x260/4 · line 900

Quoted 6 lines
Documentation/arch/x86/boot.rst +2 -4
-	if (relocatable_kernel)
-	runtime_start = align_up(load_address, kernel_alignment)
-	else
-	runtime_start = pref_address
+    if ( relocatable_kernel ) {
+      if ( load_address < pref_address )

What's up with the extra spaces around ( and ) ... and inconsistent with the lines below?

Also, even pseudocode should follow the kernel's coding style and use tabs in particular - which it already does in (some...) other places of this document, such as the 'Sample Boot Configuration' chapter.

Thanks,

Ingo

#3 lore raw
Quoted 2 lines · Ingo Molnar
Quoted 1 line · Randy Dunlap

On 11/25/24 12:31 AM, Andy Shevchenko wrote:

...

Quoted 9 lines
Quoted 9 lines

Documentation/arch/x86/boot.rst Offset/size: 0x260/4 · line 900

Quoted 6 lines
Documentation/arch/x86/boot.rst +2 -4
-	if (relocatable_kernel)
-	runtime_start = align_up(load_address, kernel_alignment)
-	else
-	runtime_start = pref_address
+    if ( relocatable_kernel ) {
+      if ( load_address < pref_address )

What's up with the extra spaces around ( and ) ... and inconsistent with the lines below?

I can remove them. This file has a lot of inconsistencies it seems...

Quoted 3 lines

Also, even pseudocode should follow the kernel's coding style and use tabs in particular - which it already does in (some...) other places of this document, such as the 'Sample Boot Configuration' chapter.

The problem is that reStructuredText syntax requires that indentation. I may follow the rules after the rST requirements, though.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Ingo Molnar
Quoted 1 line · Randy Dunlap

On 11/25/24 12:31 AM, Andy Shevchenko wrote:

...

Quoted 10 lines
Quoted 9 lines
Quoted 9 lines

Documentation/arch/x86/boot.rst Offset/size: 0x260/4 · line 900

Quoted 6 lines
Documentation/arch/x86/boot.rst +2 -4
-	if (relocatable_kernel)
-	runtime_start = align_up(load_address, kernel_alignment)
-	else
-	runtime_start = pref_address
+    if ( relocatable_kernel ) {
+      if ( load_address < pref_address )

What's up with the extra spaces around ( and ) ... and inconsistent with the lines below?

Quoted 8 lines

I can remove them. This file has a lot of inconsistencies it seems...

Quoted 3 lines

Also, even pseudocode should follow the kernel's coding style and use tabs in particular - which it already does in (some...) other places of this document, such as the 'Sample Boot Configuration' chapter.

The problem is that reStructuredText syntax requires that indentation. I may follow the rules after the rST requirements, though.

v2 has just been sent:
https://lore.kernel.org/r/[email protected]

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw
In reply to Andy Shevchenko
Quoted 16 lines · Andy Shevchenko
Quoted 2 lines · Ingo Molnar
Quoted 1 line · Randy Dunlap

On 11/25/24 12:31 AM, Andy Shevchenko wrote:

...

Quoted 9 lines
Quoted 9 lines

Documentation/arch/x86/boot.rst Offset/size: 0x260/4 · line 900

Quoted 6 lines
Documentation/arch/x86/boot.rst +2 -4
-	if (relocatable_kernel)
-	runtime_start = align_up(load_address, kernel_alignment)
-	else
-	runtime_start = pref_address
+    if ( relocatable_kernel ) {
+      if ( load_address < pref_address )

What's up with the extra spaces around ( and ) ... and inconsistent with the lines below?

Quoted 1 line

I can remove them. This file has a lot of inconsistencies it seems...

Feel free to send a followup patch that fixes up all of those other details and harmonizes the style. Quality of the boot protocol documentation demonstrably matters quite a bit in functional terms as well ...

Quoted 7 lines
Quoted 4 lines

Also, even pseudocode should follow the kernel's coding style and use tabs in particular - which it already does in (some...) other places of this document, such as the 'Sample Boot Configuration' chapter.

The problem is that reStructuredText syntax requires that indentation. I may follow the rules after the rST requirements, though.

That's a good solution - thank you!

Ingo

#6 lore raw
Quoted 31 lines · Ingo Molnar
Quoted 16 lines · Andy Shevchenko
Quoted 2 lines · Ingo Molnar
Quoted 1 line · Randy Dunlap

On 11/25/24 12:31 AM, Andy Shevchenko wrote:

...

Quoted 9 lines
Quoted 9 lines

Documentation/arch/x86/boot.rst Offset/size: 0x260/4 · line 900

Quoted 6 lines
Documentation/arch/x86/boot.rst +2 -4
-	if (relocatable_kernel)
-	runtime_start = align_up(load_address, kernel_alignment)
-	else
-	runtime_start = pref_address
+    if ( relocatable_kernel ) {
+      if ( load_address < pref_address )

What's up with the extra spaces around ( and ) ... and inconsistent with the lines below?

Quoted 1 line

I can remove them. This file has a lot of inconsistencies it seems...

Feel free to send a followup patch that fixes up all of those other details and harmonizes the style. Quality of the boot protocol documentation demonstrably matters quite a bit in functional terms as well ...

Quoted 5 lines
Quoted 4 lines

Also, even pseudocode should follow the kernel's coding style and use tabs in particular - which it already does in (some...) other places of this document, such as the 'Sample Boot Configuration' chapter.

Quoted 6 lines
Quoted 2 lines

The problem is that reStructuredText syntax requires that indentation. I may follow the rules after the rST requirements, though.

That's a good solution - thank you!

Ingo

I, too, would really appreciate help in cleaning up the document and yes, the number of inconsistencies that have crept in over the years is quite frankly embarrassing. In a few places I will admit to thinking "did I actually write this?"

And as Ingo says, it matters, because experience shows that boot loader authors don't ask for clarification, they make their own interpretation and now we are stuck with a legacy.

One part of the problem is that reviewing documentation changes in patch form hides inconsistencies because you only get a few lines of context.

On top of that, it would be great if the markup language could be used to insert rationale and commentary into the document. In some cases I think it would really help getting better compliance with the spec as intended, explain why we make certain recommendations as opposed to "well it seems to work", and help catch inconsistencies.